Skip to content

Commit 15823a3

Browse files
committed
WIP
1 parent 5f85b79 commit 15823a3

File tree

3 files changed

+87
-32
lines changed

3 files changed

+87
-32
lines changed

src/DB.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,11 @@ class DB {
157157
public transaction(): ResourceAcquire<DBTransaction> {
158158
return async () => {
159159
const transactionId = this.transactionCounter++;
160-
const tran = new DBTransaction({
160+
const tran = await DBTransaction.createTransaction({
161161
db: this,
162162
transactionId,
163163
logger: this.logger,
164164
});
165-
// const tran = await DBTransaction.createTransaction({
166-
// db: this,
167-
// transactionId,
168-
// logger: this.logger,
169-
// });
170165
return [
171166
async (e?: Error) => {
172167
try {
@@ -389,10 +384,6 @@ class DB {
389384
options: DBIteratorOptions & { keys: false },
390385
levelPath?: LevelPath,
391386
): DBIterator<undefined, Buffer>;
392-
public iterator<V>(
393-
options: DBIteratorOptions & { keys: false; valueAsBuffer: false },
394-
levelPath?: LevelPath,
395-
): DBIterator<undefined, V>;
396387
public iterator(
397388
options: DBIteratorOptions & { values: false },
398389
levelPath?: LevelPath,
@@ -436,13 +427,6 @@ class DB {
436427
options: DBIteratorOptions & { keys: false },
437428
levelPath?: LevelPath,
438429
): DBIterator<undefined, Buffer>;
439-
/**
440-
* @internal
441-
*/
442-
public _iterator<V>(
443-
options: DBIteratorOptions & { keys: false; valueAsBuffer: false },
444-
levelPath?: LevelPath,
445-
): DBIterator<undefined, V>;
446430
/**
447431
* @internal
448432
*/
@@ -762,7 +746,7 @@ class DB {
762746
throw e;
763747
}
764748
}
765-
}
749+
g
766750
}
767751

768752
export default DB;

src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ function keyPathToKey(keyPath: KeyPath): Buffer {
4343
return Buffer.concat([
4444
levelPathToKey(levelPath),
4545
escapePart(
46-
typeof keyPart === 'string'
47-
? Buffer.from(keyPart, 'utf-8')
48-
: keyPart),
46+
typeof keyPart === 'string' ? Buffer.from(keyPart, 'utf-8') : keyPart,
47+
),
4948
]);
5049
}
5150

tests/utils.test.ts

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,109 @@ describe('utils', () => {
2121
[Buffer.concat([utils.sep, Buffer.from('foobar')])],
2222
[Buffer.concat([Buffer.from('foobar'), utils.sep])],
2323
[Buffer.concat([utils.sep, Buffer.from('foobar'), utils.sep])],
24-
[Buffer.concat([utils.sep, Buffer.from('foobar'), utils.sep, Buffer.from('foobar')])],
25-
[Buffer.concat([Buffer.from('foobar'), utils.sep, Buffer.from('foobar'), utils.sep])],
26-
['', Buffer.concat([Buffer.from('foobar'), utils.sep, Buffer.from('foobar'), utils.sep]), ''],
24+
[
25+
Buffer.concat([
26+
utils.sep,
27+
Buffer.from('foobar'),
28+
utils.sep,
29+
Buffer.from('foobar'),
30+
]),
31+
],
32+
[
33+
Buffer.concat([
34+
Buffer.from('foobar'),
35+
utils.sep,
36+
Buffer.from('foobar'),
37+
utils.sep,
38+
]),
39+
],
40+
[
41+
'',
42+
Buffer.concat([
43+
Buffer.from('foobar'),
44+
utils.sep,
45+
Buffer.from('foobar'),
46+
utils.sep,
47+
]),
48+
'',
49+
],
2750
// Escape can be used in key part
2851
[utils.esc],
2952
[Buffer.concat([utils.esc, Buffer.from('foobar')])],
3053
[Buffer.concat([Buffer.from('foobar'), utils.esc])],
3154
[Buffer.concat([utils.esc, Buffer.from('foobar'), utils.esc])],
32-
[Buffer.concat([utils.esc, Buffer.from('foobar'), utils.esc, Buffer.from('foobar')])],
33-
[Buffer.concat([Buffer.from('foobar'), utils.esc, Buffer.from('foobar'), utils.esc])],
34-
['', Buffer.concat([Buffer.from('foobar'), utils.esc, Buffer.from('foobar'), utils.esc]), ''],
55+
[
56+
Buffer.concat([
57+
utils.esc,
58+
Buffer.from('foobar'),
59+
utils.esc,
60+
Buffer.from('foobar'),
61+
]),
62+
],
63+
[
64+
Buffer.concat([
65+
Buffer.from('foobar'),
66+
utils.esc,
67+
Buffer.from('foobar'),
68+
utils.esc,
69+
]),
70+
],
71+
[
72+
'',
73+
Buffer.concat([
74+
Buffer.from('foobar'),
75+
utils.esc,
76+
Buffer.from('foobar'),
77+
utils.esc,
78+
]),
79+
'',
80+
],
3581
// Separator can be used in level parts
3682
[Buffer.concat([utils.sep, Buffer.from('foobar')]), 'key'],
3783
[Buffer.concat([Buffer.from('foobar'), utils.sep]), 'key'],
3884
[Buffer.concat([utils.sep, Buffer.from('foobar'), utils.sep]), 'key'],
39-
[Buffer.concat([utils.sep, Buffer.from('foobar'), utils.sep, Buffer.from('foobar')]), 'key'],
40-
[Buffer.concat([Buffer.from('foobar'), utils.sep, Buffer.from('foobar'), utils.sep]), 'key'],
41-
['', Buffer.concat([Buffer.from('foobar'), utils.sep, Buffer.from('foobar'), utils.sep]), 'key', ''],
85+
[
86+
Buffer.concat([
87+
utils.sep,
88+
Buffer.from('foobar'),
89+
utils.sep,
90+
Buffer.from('foobar'),
91+
]),
92+
'key',
93+
],
94+
[
95+
Buffer.concat([
96+
Buffer.from('foobar'),
97+
utils.sep,
98+
Buffer.from('foobar'),
99+
utils.sep,
100+
]),
101+
'key',
102+
],
103+
[
104+
'',
105+
Buffer.concat([
106+
Buffer.from('foobar'),
107+
utils.sep,
108+
Buffer.from('foobar'),
109+
utils.sep,
110+
]),
111+
'key',
112+
'',
113+
],
42114
// Escape can be used in level parts
43115
[Buffer.concat([utils.sep, utils.esc, utils.sep]), 'key'],
44116
[Buffer.concat([utils.esc, utils.esc, utils.esc]), 'key'],
45117
['', Buffer.concat([utils.esc, utils.esc, utils.esc]), 'key', ''],
46118
];
47-
test.each(keyPaths.map(kP => [kP]))(
119+
test.each(keyPaths.map((kP) => [kP]))(
48120
'parse key paths %s',
49121
(keyPath: KeyPath) => {
50122
const key = utils.keyPathToKey(keyPath);
51123
const keyPath_ = utils.parseKey(key);
52124
expect(keyPath.map((b) => b.toString())).toStrictEqual(
53125
keyPath_.map((b) => b.toString()),
54126
);
55-
}
127+
},
56128
);
57129
});

0 commit comments

Comments
 (0)