@@ -451,24 +451,24 @@ export class WriteBatch {
451451 this . native = new native . NativeWriteBatch ( ) ;
452452 }
453453
454- put ( key : Binary , value : Binary ) : void {
455- this . native . put ( toBuffer ( key ) , toBuffer ( value ) ) ;
456- }
457-
458- putWithOptions ( key : Binary , value : Binary , options ?: PutOptions ) : void {
459- this . native . putWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ;
454+ put ( key : Binary , value : Binary , options ?: PutOptions ) : void {
455+ if ( options ) {
456+ this . native . putWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ;
457+ } else {
458+ this . native . put ( toBuffer ( key ) , toBuffer ( value ) ) ;
459+ }
460460 }
461461
462462 delete ( key : Binary ) : void {
463463 this . native . delete ( toBuffer ( key ) ) ;
464464 }
465465
466- merge ( key : Binary , value : Binary ) : void {
467- this . native . merge ( toBuffer ( key ) , toBuffer ( value ) ) ;
468- }
469-
470- mergeWithOptions ( key : Binary , value : Binary , options ?: MergeOptions ) : void {
471- this . native . mergeWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ;
466+ merge ( key : Binary , value : Binary , options ?: MergeOptions ) : void {
467+ if ( options ) {
468+ this . native . mergeWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ;
469+ } else {
470+ this . native . merge ( toBuffer ( key ) , toBuffer ( value ) ) ;
471+ }
472472 }
473473
474474 getNative ( ) : NativeWriteBatch {
@@ -483,34 +483,31 @@ export class SlateDBSnapshot {
483483 this . native = nativeSnapshot ;
484484 }
485485
486- async get ( key : Binary ) : Promise < Buffer | null > {
486+ async get ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
487+ if ( options ) {
488+ return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
489+ }
487490 return call ( ( ) => this . native . get ( toBuffer ( key ) ) ) ;
488491 }
489492
490- async getWithOptions ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
491- return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
492- }
493-
494- async scan ( start : Binary , end ?: Binary ) : Promise < SlateDBIterator > {
493+ async scan ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
494+ if ( options ) {
495+ const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
496+ return new SlateDBIterator ( iterator ) ;
497+ }
495498 const iterator = await call ( ( ) => this . native . scan ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) ) ) ;
496499 return new SlateDBIterator ( iterator ) ;
497500 }
498501
499- async scanWithOptions ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
500- const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
501- return new SlateDBIterator ( iterator ) ;
502- }
503-
504- async scanPrefix ( prefix : Binary ) : Promise < SlateDBIterator > {
502+ async scanPrefix ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
503+ if ( options ) {
504+ const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
505+ return new SlateDBIterator ( iterator ) ;
506+ }
505507 const iterator = await call ( ( ) => this . native . scanPrefix ( toBuffer ( prefix ) ) ) ;
506508 return new SlateDBIterator ( iterator ) ;
507509 }
508510
509- async scanPrefixWithOptions ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
510- const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
511- return new SlateDBIterator ( iterator ) ;
512- }
513-
514511 async close ( ) : Promise < void > {
515512 await call ( ( ) => this . native . close ( ) ) ;
516513 }
@@ -523,52 +520,49 @@ export class SlateDBTransaction {
523520 this . native = nativeTransaction ;
524521 }
525522
526- async get ( key : Binary ) : Promise < Buffer | null > {
523+ async get ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
524+ if ( options ) {
525+ return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
526+ }
527527 return call ( ( ) => this . native . get ( toBuffer ( key ) ) ) ;
528528 }
529529
530- async getWithOptions ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
531- return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
532- }
533-
534- async scan ( start : Binary , end ?: Binary ) : Promise < SlateDBIterator > {
530+ async scan ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
531+ if ( options ) {
532+ const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
533+ return new SlateDBIterator ( iterator ) ;
534+ }
535535 const iterator = await call ( ( ) => this . native . scan ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) ) ) ;
536536 return new SlateDBIterator ( iterator ) ;
537537 }
538538
539- async scanWithOptions ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
540- const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
541- return new SlateDBIterator ( iterator ) ;
542- }
543-
544- async scanPrefix ( prefix : Binary ) : Promise < SlateDBIterator > {
539+ async scanPrefix ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
540+ if ( options ) {
541+ const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
542+ return new SlateDBIterator ( iterator ) ;
543+ }
545544 const iterator = await call ( ( ) => this . native . scanPrefix ( toBuffer ( prefix ) ) ) ;
546545 return new SlateDBIterator ( iterator ) ;
547546 }
548547
549- async scanPrefixWithOptions ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
550- const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
551- return new SlateDBIterator ( iterator ) ;
552- }
553-
554- async put ( key : Binary , value : Binary ) : Promise < void > {
555- await call ( ( ) => this . native . put ( toBuffer ( key ) , toBuffer ( value ) ) ) ;
556- }
557-
558- async putWithOptions ( key : Binary , value : Binary , options ?: PutOptions ) : Promise < void > {
559- await call ( ( ) => this . native . putWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ) ;
548+ async put ( key : Binary , value : Binary , options ?: PutOptions ) : Promise < void > {
549+ if ( options ) {
550+ await call ( ( ) => this . native . putWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ) ;
551+ } else {
552+ await call ( ( ) => this . native . put ( toBuffer ( key ) , toBuffer ( value ) ) ) ;
553+ }
560554 }
561555
562556 async delete ( key : Binary ) : Promise < void > {
563557 await call ( ( ) => this . native . delete ( toBuffer ( key ) ) ) ;
564558 }
565559
566- async merge ( key : Binary , value : Binary ) : Promise < void > {
567- await call ( ( ) => this . native . merge ( toBuffer ( key ) , toBuffer ( value ) ) ) ;
568- }
569-
570- async mergeWithOptions ( key : Binary , value : Binary , options ?: MergeOptions ) : Promise < void > {
571- await call ( ( ) => this . native . mergeWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ) ;
560+ async merge ( key : Binary , value : Binary , options ?: MergeOptions ) : Promise < void > {
561+ if ( options ) {
562+ await call ( ( ) => this . native . mergeWithOptions ( toBuffer ( key ) , toBuffer ( value ) , options ) ) ;
563+ } else {
564+ await call ( ( ) => this . native . merge ( toBuffer ( key ) , toBuffer ( value ) ) ) ;
565+ }
572566 }
573567
574568 async markRead ( keys : Binary [ ] ) : Promise < void > {
@@ -600,34 +594,31 @@ export class SlateDBReader {
600594 this . native = nativeReader ;
601595 }
602596
603- async get ( key : Binary ) : Promise < Buffer | null > {
597+ async get ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
598+ if ( options ) {
599+ return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
600+ }
604601 return call ( ( ) => this . native . get ( toBuffer ( key ) ) ) ;
605602 }
606603
607- async getWithOptions ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
608- return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
609- }
610-
611- async scan ( start : Binary , end ?: Binary ) : Promise < SlateDBIterator > {
604+ async scan ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
605+ if ( options ) {
606+ const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
607+ return new SlateDBIterator ( iterator ) ;
608+ }
612609 const iterator = await call ( ( ) => this . native . scan ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) ) ) ;
613610 return new SlateDBIterator ( iterator ) ;
614611 }
615612
616- async scanWithOptions ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
617- const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
618- return new SlateDBIterator ( iterator ) ;
619- }
620-
621- async scanPrefix ( prefix : Binary ) : Promise < SlateDBIterator > {
613+ async scanPrefix ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
614+ if ( options ) {
615+ const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
616+ return new SlateDBIterator ( iterator ) ;
617+ }
622618 const iterator = await call ( ( ) => this . native . scanPrefix ( toBuffer ( prefix ) ) ) ;
623619 return new SlateDBIterator ( iterator ) ;
624620 }
625621
626- async scanPrefixWithOptions ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
627- const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
628- return new SlateDBIterator ( iterator ) ;
629- }
630-
631622 async close ( ) : Promise < void > {
632623 await call ( ( ) => this . native . close ( ) ) ;
633624 }
@@ -714,74 +705,67 @@ export class SlateDB {
714705 return open ( options ) ;
715706 }
716707
717- async get ( key : Binary ) : Promise < Buffer | null > {
708+ async get ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
709+ if ( options ) {
710+ return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
711+ }
718712 return call ( ( ) => this . native . get ( toBuffer ( key ) ) ) ;
719713 }
720714
721- async getWithOptions ( key : Binary , options ?: ReadOptions ) : Promise < Buffer | null > {
722- return call ( ( ) => this . native . getWithOptions ( toBuffer ( key ) , options ) ) ;
723- }
724-
725- async put ( key : Binary , value : Binary ) : Promise < WriteHandle > {
715+ async put ( key : Binary , value : Binary , putOptions ?: PutOptions , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
716+ if ( putOptions || writeOptions ) {
717+ const handle = await call ( ( ) => this . native . putWithOptions ( toBuffer ( key ) , toBuffer ( value ) , putOptions , writeOptions ) ) ;
718+ return mapWriteHandle ( handle ) ;
719+ }
726720 const handle = await call ( ( ) => this . native . put ( toBuffer ( key ) , toBuffer ( value ) ) ) ;
727721 return mapWriteHandle ( handle ) ;
728722 }
729723
730- async putWithOptions ( key : Binary , value : Binary , putOptions ?: PutOptions , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
731- const handle = await call ( ( ) => this . native . putWithOptions ( toBuffer ( key ) , toBuffer ( value ) , putOptions , writeOptions ) ) ;
732- return mapWriteHandle ( handle ) ;
733- }
734-
735- async delete ( key : Binary ) : Promise < WriteHandle > {
724+ async delete ( key : Binary , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
725+ if ( writeOptions ) {
726+ const handle = await call ( ( ) => this . native . deleteWithOptions ( toBuffer ( key ) , writeOptions ) ) ;
727+ return mapWriteHandle ( handle ) ;
728+ }
736729 const handle = await call ( ( ) => this . native . delete ( toBuffer ( key ) ) ) ;
737730 return mapWriteHandle ( handle ) ;
738731 }
739732
740- async deleteWithOptions ( key : Binary , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
741- const handle = await call ( ( ) => this . native . deleteWithOptions ( toBuffer ( key ) , writeOptions ) ) ;
742- return mapWriteHandle ( handle ) ;
743- }
744-
745- async merge ( key : Binary , value : Binary ) : Promise < WriteHandle > {
733+ async merge ( key : Binary , value : Binary , mergeOptions ?: MergeOptions , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
734+ if ( mergeOptions || writeOptions ) {
735+ const handle = await call ( ( ) => this . native . mergeWithOptions ( toBuffer ( key ) , toBuffer ( value ) , mergeOptions , writeOptions ) ) ;
736+ return mapWriteHandle ( handle ) ;
737+ }
746738 const handle = await call ( ( ) => this . native . merge ( toBuffer ( key ) , toBuffer ( value ) ) ) ;
747739 return mapWriteHandle ( handle ) ;
748740 }
749741
750- async mergeWithOptions ( key : Binary , value : Binary , mergeOptions ?: MergeOptions , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
751- const handle = await call ( ( ) => this . native . mergeWithOptions ( toBuffer ( key ) , toBuffer ( value ) , mergeOptions , writeOptions ) ) ;
752- return mapWriteHandle ( handle ) ;
753- }
754-
755- async write ( batch : WriteBatch ) : Promise < WriteHandle > {
742+ async write ( batch : WriteBatch , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
743+ if ( writeOptions ) {
744+ const handle = await call ( ( ) => this . native . writeWithOptions ( batch . getNative ( ) , writeOptions ) ) ;
745+ return mapWriteHandle ( handle ) ;
746+ }
756747 const handle = await call ( ( ) => this . native . write ( batch . getNative ( ) ) ) ;
757748 return mapWriteHandle ( handle ) ;
758749 }
759750
760- async writeWithOptions ( batch : WriteBatch , writeOptions ?: WriteOptions ) : Promise < WriteHandle > {
761- const handle = await call ( ( ) => this . native . writeWithOptions ( batch . getNative ( ) , writeOptions ) ) ;
762- return mapWriteHandle ( handle ) ;
763- }
764-
765- async scan ( start : Binary , end ?: Binary ) : Promise < SlateDBIterator > {
751+ async scan ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
752+ if ( options ) {
753+ const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
754+ return new SlateDBIterator ( iterator ) ;
755+ }
766756 const iterator = await call ( ( ) => this . native . scan ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) ) ) ;
767757 return new SlateDBIterator ( iterator ) ;
768758 }
769759
770- async scanWithOptions ( start : Binary , end ?: Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
771- const iterator = await call ( ( ) => this . native . scanWithOptions ( toBuffer ( start ) , end == null ? undefined : toBuffer ( end ) , options ) ) ;
772- return new SlateDBIterator ( iterator ) ;
773- }
774-
775- async scanPrefix ( prefix : Binary ) : Promise < SlateDBIterator > {
760+ async scanPrefix ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
761+ if ( options ) {
762+ const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
763+ return new SlateDBIterator ( iterator ) ;
764+ }
776765 const iterator = await call ( ( ) => this . native . scanPrefix ( toBuffer ( prefix ) ) ) ;
777766 return new SlateDBIterator ( iterator ) ;
778767 }
779768
780- async scanPrefixWithOptions ( prefix : Binary , options ?: ScanOptions ) : Promise < SlateDBIterator > {
781- const iterator = await call ( ( ) => this . native . scanPrefixWithOptions ( toBuffer ( prefix ) , options ) ) ;
782- return new SlateDBIterator ( iterator ) ;
783- }
784-
785769 async snapshot ( ) : Promise < SlateDBSnapshot > {
786770 const snapshot = await call ( ( ) => this . native . snapshot ( ) ) ;
787771 return new SlateDBSnapshot ( snapshot ) ;
@@ -792,12 +776,12 @@ export class SlateDB {
792776 return new SlateDBTransaction ( txn ) ;
793777 }
794778
795- async flush ( ) : Promise < void > {
796- await call ( ( ) => this . native . flush ( ) ) ;
797- }
798-
799- async flushWithOptions ( flushType ?: "wal" | "memtable" ) : Promise < void > {
800- await call ( ( ) => this . native . flushWithOptions ( flushType ) ) ;
779+ async flush ( flushType ?: "wal" | "memtable" ) : Promise < void > {
780+ if ( flushType ) {
781+ await call ( ( ) => this . native . flushWithOptions ( flushType ) ) ;
782+ } else {
783+ await call ( ( ) => this . native . flush ( ) ) ;
784+ }
801785 }
802786
803787 async metrics ( ) : Promise < Record < string , number > > {
0 commit comments