1
- import type { AbstractBatch , AbstractIteratorOptions } from 'abstract-leveldown' ;
1
+ import type {
2
+ AbstractBatch ,
3
+ AbstractIteratorOptions ,
4
+ } from 'abstract-leveldown' ;
2
5
import type { LevelDB } from 'level' ;
3
6
import type { ResourceAcquire } from '@matrixai/resources' ;
4
7
import type {
@@ -209,14 +212,8 @@ class DB {
209
212
* Get from root level
210
213
* @internal
211
214
*/
212
- public async _get < T > (
213
- keyPath : KeyPath ,
214
- raw ?: false ,
215
- ) : Promise < T | undefined > ;
216
- public async _get (
217
- keyPath : KeyPath ,
218
- raw : true ,
219
- ) : Promise < Buffer | undefined > ;
215
+ public async _get < T > ( keyPath : KeyPath , raw ?: false ) : Promise < T | undefined > ;
216
+ public async _get ( keyPath : KeyPath , raw : true ) : Promise < Buffer | undefined > ;
220
217
public async _get < T > (
221
218
keyPath : KeyPath ,
222
219
raw : boolean = false ,
@@ -268,16 +265,8 @@ class DB {
268
265
* Put from root level
269
266
* @internal
270
267
*/
271
- public async _put (
272
- keyPath : KeyPath ,
273
- value : any ,
274
- raw ?: false ,
275
- ) : Promise < void > ;
276
- public async _put (
277
- keyPath : KeyPath ,
278
- value : Buffer ,
279
- raw : true ,
280
- ) : Promise < void > ;
268
+ public async _put ( keyPath : KeyPath , value : any , raw ?: false ) : Promise < void > ;
269
+ public async _put ( keyPath : KeyPath , value : Buffer , raw : true ) : Promise < void > ;
281
270
public async _put (
282
271
keyPath : KeyPath ,
283
272
value : any ,
@@ -443,13 +432,15 @@ class DB {
443
432
if ( options . gt != null ) {
444
433
options . gt = Buffer . concat ( [
445
434
levelKeyStart ,
446
- ( typeof options . gt === 'string' ) ? Buffer . from ( options . gt ) : options . gt
435
+ typeof options . gt === 'string' ? Buffer . from ( options . gt ) : options . gt ,
447
436
] ) ;
448
437
}
449
438
if ( options . gte != null ) {
450
439
options . gte = Buffer . concat ( [
451
440
levelKeyStart ,
452
- ( typeof options . gte === 'string' ) ? Buffer . from ( options . gte ) : options . gte
441
+ typeof options . gte === 'string'
442
+ ? Buffer . from ( options . gte )
443
+ : options . gte ,
453
444
] ) ;
454
445
}
455
446
if ( options . gt == null && options . gte == null ) {
@@ -458,13 +449,15 @@ class DB {
458
449
if ( options ?. lt != null ) {
459
450
options . lt = Buffer . concat ( [
460
451
levelKeyStart ,
461
- ( typeof options . lt === 'string' ) ? Buffer . from ( options . lt ) : options . lt
452
+ typeof options . lt === 'string' ? Buffer . from ( options . lt ) : options . lt ,
462
453
] ) ;
463
454
}
464
455
if ( options ?. lte != null ) {
465
456
options . lte = Buffer . concat ( [
466
457
levelKeyStart ,
467
- ( typeof options . lte === 'string' ) ? Buffer . from ( options . lte ) : options . lte
458
+ typeof options . lte === 'string'
459
+ ? Buffer . from ( options . lte )
460
+ : options . lte ,
468
461
] ) ;
469
462
}
470
463
if ( options . lt == null && options . lte == null ) {
@@ -477,11 +470,7 @@ class DB {
477
470
const next = iterator . next . bind ( iterator ) ;
478
471
// @ts -ignore AbstractIterator type is outdated
479
472
iterator . seek = ( k : Buffer | string ) : void => {
480
- seek (
481
- utils . keyPathToKey (
482
- [ ...levelPath , k ] as unknown as KeyPath
483
- )
484
- ) ;
473
+ seek ( utils . keyPathToKey ( [ ...levelPath , k ] as unknown as KeyPath ) ) ;
485
474
} ;
486
475
// @ts -ignore AbstractIterator type is outdated
487
476
iterator . next = async ( ) => {
@@ -492,9 +481,7 @@ class DB {
492
481
if ( kv [ 0 ] != null ) {
493
482
// Truncate level path so the returned key is relative to the level path
494
483
const keyPath = utils . parseKey ( kv [ 0 ] ) . slice ( levelPath . length ) ;
495
- kv [ 0 ] = utils . keyPathToKey (
496
- keyPath as unknown as KeyPath
497
- ) ;
484
+ kv [ 0 ] = utils . keyPathToKey ( keyPath as unknown as KeyPath ) ;
498
485
}
499
486
// Handle values: false
500
487
if ( kv [ 1 ] != null ) {
@@ -511,9 +498,7 @@ class DB {
511
498
* This is not atomic, it will iterate over a snapshot of the DB
512
499
*/
513
500
@ready ( new errors . ErrorDBNotRunning ( ) )
514
- public async clear (
515
- levelPath : LevelPath = [ ] ,
516
- ) : Promise < void > {
501
+ public async clear ( levelPath : LevelPath = [ ] ) : Promise < void > {
517
502
levelPath = [ 'data' , ...levelPath ] ;
518
503
if ( utils . checkSepLevelPath ( levelPath ) ) {
519
504
throw new errors . ErrorDBLevelSep ( ) ;
@@ -525,10 +510,7 @@ class DB {
525
510
* Clear from root level
526
511
* @internal
527
512
*/
528
- public async _clear (
529
- db : LevelDB ,
530
- levelPath : LevelPath = [ ] ,
531
- ) : Promise < void > {
513
+ public async _clear ( db : LevelDB , levelPath : LevelPath = [ ] ) : Promise < void > {
532
514
for await ( const [ k ] of this . _iterator ( db , { values : false } , levelPath ) ) {
533
515
await db . del ( utils . keyPathToKey ( [ ...levelPath , k ] as unknown as KeyPath ) ) ;
534
516
}
@@ -547,10 +529,19 @@ class DB {
547
529
* Dump from root level
548
530
* It is intended for diagnostics
549
531
*/
550
- public async dump ( levelPath ?: LevelPath , raw ?: false ) : Promise < Array < [ string , any ] > > ;
551
- public async dump ( levelPath : LevelPath | undefined , raw : true ) : Promise < Array < [ Buffer , Buffer ] > > ;
532
+ public async dump (
533
+ levelPath ?: LevelPath ,
534
+ raw ?: false ,
535
+ ) : Promise < Array < [ string , any ] > > ;
536
+ public async dump (
537
+ levelPath : LevelPath | undefined ,
538
+ raw : true ,
539
+ ) : Promise < Array < [ Buffer , Buffer ] > > ;
552
540
@ready ( new errors . ErrorDBNotRunning ( ) )
553
- public async dump ( levelPath : LevelPath = [ ] , raw : boolean = false ) : Promise < Array < [ string | Buffer , any ] > > {
541
+ public async dump (
542
+ levelPath : LevelPath = [ ] ,
543
+ raw : boolean = false ,
544
+ ) : Promise < Array < [ string | Buffer , any ] > > {
554
545
if ( utils . checkSepLevelPath ( levelPath ) ) {
555
546
throw new errors . ErrorDBLevelSep ( ) ;
556
547
}
0 commit comments