@harperfast/rocksdb-js 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -23
- package/bin/rocksdb-js.mjs +568 -0
- package/dist/index.cjs +179 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +138 -24
- package/dist/index.d.mts +138 -24
- package/dist/index.mjs +179 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -16
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,7 @@ interface Encoder {
|
|
|
16
16
|
encode?: (value: any, mode?: number) => Buffer;
|
|
17
17
|
Encoder?: EncoderFunction;
|
|
18
18
|
freezeData?: boolean;
|
|
19
|
+
name?: string;
|
|
19
20
|
needsStableBuffer?: boolean;
|
|
20
21
|
randomAccessStructure?: boolean;
|
|
21
22
|
readKey?: (buffer: Buffer, start: number, end: number, inSequence?: boolean) => any;
|
|
@@ -35,16 +36,21 @@ interface DBIteratorValue<T> {
|
|
|
35
36
|
value: T;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* Wraps
|
|
39
|
-
*
|
|
39
|
+
* Wraps the `NativeIterator` C++ binding, decoding keys and values from the
|
|
40
|
+
* shared key/value buffers (fast path) or from per-iteration buffers (slow
|
|
41
|
+
* fallback path used for oversized data or stable-buffer decoders).
|
|
42
|
+
*
|
|
43
|
+
* The native `next()` returns a primitive signal (and writes lengths to the
|
|
44
|
+
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
45
|
+
* so this class is responsible for building the `IteratorResult`.
|
|
40
46
|
*/
|
|
41
47
|
declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
42
48
|
#private;
|
|
43
|
-
iterator:
|
|
49
|
+
iterator: InstanceType<typeof NativeIteratorCls>;
|
|
44
50
|
store: Store;
|
|
45
|
-
constructor(iterator:
|
|
51
|
+
constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean);
|
|
46
52
|
[Symbol.iterator](): Iterator<DBIteratorValue<T>>;
|
|
47
|
-
next(
|
|
53
|
+
next(): IteratorResult<DBIteratorValue<T>>;
|
|
48
54
|
return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
|
|
49
55
|
throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
|
|
50
56
|
}
|
|
@@ -56,6 +62,10 @@ type StoreIteratorOptions = IteratorOptions & DBITransactional;
|
|
|
56
62
|
type StorePutOptions = PutOptions & DBITransactional;
|
|
57
63
|
type StoreRangeOptions = RangeOptions & DBITransactional;
|
|
58
64
|
type StoreRemoveOptions = DBITransactional | unknown;
|
|
65
|
+
type CompactOptions = {
|
|
66
|
+
start?: Key;
|
|
67
|
+
end?: Key;
|
|
68
|
+
};
|
|
59
69
|
/**
|
|
60
70
|
* Options for the `Store` class.
|
|
61
71
|
*/
|
|
@@ -244,6 +254,28 @@ declare class Store {
|
|
|
244
254
|
*/
|
|
245
255
|
close(): void;
|
|
246
256
|
/**
|
|
257
|
+
* Compacts the entire key range of the database asynchronously.
|
|
258
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
263
|
+
* await db.compact();
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Compacts the entire key range of the database synchronously.
|
|
269
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
274
|
+
* db.compactSync();
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
compactSync(options?: CompactOptions): void;
|
|
278
|
+
/**
|
|
247
279
|
* Decodes a key from the database.
|
|
248
280
|
*
|
|
249
281
|
* @param key - The key to decode.
|
|
@@ -372,29 +404,17 @@ interface PutOptions {
|
|
|
372
404
|
}
|
|
373
405
|
//#endregion
|
|
374
406
|
//#region src/load-binding.d.ts
|
|
375
|
-
type
|
|
407
|
+
type NativeTransactionOptions = {
|
|
376
408
|
/**
|
|
377
409
|
* Whether to disable snapshots.
|
|
378
410
|
*
|
|
379
411
|
* @default false
|
|
380
412
|
*/
|
|
381
413
|
disableSnapshot?: boolean;
|
|
382
|
-
/**
|
|
383
|
-
* The maximum number of times to retry the transaction.
|
|
384
|
-
*
|
|
385
|
-
* @default 3
|
|
386
|
-
*/
|
|
387
|
-
maxRetries?: number;
|
|
388
|
-
/**
|
|
389
|
-
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
390
|
-
*
|
|
391
|
-
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
392
|
-
*/
|
|
393
|
-
retryOnBusy?: boolean;
|
|
394
414
|
};
|
|
395
415
|
type NativeTransaction = {
|
|
396
416
|
id: number;
|
|
397
|
-
new (context: NativeDatabase, options?:
|
|
417
|
+
new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
|
|
398
418
|
abort(): void;
|
|
399
419
|
commit(resolve: () => void, reject: (err: Error) => void): void;
|
|
400
420
|
commitSync(): void;
|
|
@@ -440,6 +460,36 @@ type TransactionLog = {
|
|
|
440
460
|
_lastCommittedPosition: Float64Array;
|
|
441
461
|
_logBuffers: Map<number, WeakRef<LogBuffer>>;
|
|
442
462
|
};
|
|
463
|
+
/**
|
|
464
|
+
* Shape of options that can be passed to the native iterator constructor for
|
|
465
|
+
* the rare case of advanced RocksDB ReadOptions overrides. Common iterator
|
|
466
|
+
* options are passed via the bitmask `flags` argument instead.
|
|
467
|
+
*/
|
|
468
|
+
type NativeIteratorAdvancedOptions = {
|
|
469
|
+
adaptiveReadahead?: boolean;
|
|
470
|
+
asyncIO?: boolean;
|
|
471
|
+
autoReadaheadSize?: boolean;
|
|
472
|
+
backgroundPurgeOnIteratorCleanup?: boolean;
|
|
473
|
+
fillCache?: boolean;
|
|
474
|
+
readaheadSize?: number;
|
|
475
|
+
tailing?: boolean;
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* The result of a single native iterator step. A number value matches one of
|
|
479
|
+
* the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
|
|
480
|
+
* the data does not fit in the shared key/value buffers, or when the decoder
|
|
481
|
+
* needs a stable value buffer.
|
|
482
|
+
*/
|
|
483
|
+
type NativeIteratorResult = number | {
|
|
484
|
+
key: Buffer;
|
|
485
|
+
value?: Buffer;
|
|
486
|
+
};
|
|
487
|
+
declare class NativeIteratorCls {
|
|
488
|
+
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
|
|
489
|
+
next(): NativeIteratorResult;
|
|
490
|
+
return(): void;
|
|
491
|
+
throw(err?: unknown): void;
|
|
492
|
+
}
|
|
443
493
|
type NativeDatabaseMode = "optimistic" | "pessimistic";
|
|
444
494
|
type NativeDatabaseOptions = {
|
|
445
495
|
disableWAL?: boolean;
|
|
@@ -480,6 +530,9 @@ type NativeDatabase = {
|
|
|
480
530
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
481
531
|
clearSync(): void;
|
|
482
532
|
close(): void;
|
|
533
|
+
compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
|
|
534
|
+
compactSync(start?: Key, end?: Key): void;
|
|
535
|
+
columns: string[];
|
|
483
536
|
destroy(): void;
|
|
484
537
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
485
538
|
dropSync(): void;
|
|
@@ -488,8 +541,8 @@ type NativeDatabase = {
|
|
|
488
541
|
notify(event: string | BufferWithDataView, args?: any[]): boolean;
|
|
489
542
|
get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer>, reject: RejectCallback, txnId?: number): number;
|
|
490
543
|
getCount(options?: RangeOptions, txnId?: number): number;
|
|
491
|
-
getDBIntProperty(propertyName: string): number;
|
|
492
|
-
getDBProperty(propertyName: string): string;
|
|
544
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
545
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
493
546
|
getMonotonicTimestamp(): number;
|
|
494
547
|
getOldestSnapshotTimestamp(): number;
|
|
495
548
|
getStat(statName: string): number | StatsHistogramData;
|
|
@@ -507,6 +560,7 @@ type NativeDatabase = {
|
|
|
507
560
|
removeSync(key: BufferWithDataView, txnId?: number): void;
|
|
508
561
|
setDefaultKeyBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
509
562
|
setDefaultValueBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
563
|
+
setIteratorState(buffer: Buffer | Uint8Array): void;
|
|
510
564
|
tryLock(key: BufferWithDataView, callback?: () => void): boolean;
|
|
511
565
|
unlock(key: BufferWithDataView): void;
|
|
512
566
|
useLog(name: string): TransactionLog;
|
|
@@ -514,6 +568,7 @@ type NativeDatabase = {
|
|
|
514
568
|
};
|
|
515
569
|
type RocksDatabaseConfig = {
|
|
516
570
|
blockCacheSize?: number;
|
|
571
|
+
compactOnClose?: boolean;
|
|
517
572
|
};
|
|
518
573
|
type RegistryStatusDB = {
|
|
519
574
|
path: string;
|
|
@@ -533,6 +588,14 @@ declare const constants: {
|
|
|
533
588
|
TRANSACTION_LOG_TOKEN: number;
|
|
534
589
|
TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
|
|
535
590
|
TRANSACTION_LOG_FILE_HEADER_SIZE: number;
|
|
591
|
+
ITERATOR_REVERSE_FLAG: number;
|
|
592
|
+
ITERATOR_INCLUSIVE_END_FLAG: number;
|
|
593
|
+
ITERATOR_EXCLUSIVE_START_FLAG: number;
|
|
594
|
+
ITERATOR_INCLUDE_VALUES_FLAG: number;
|
|
595
|
+
ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
|
|
596
|
+
ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
|
|
597
|
+
ITERATOR_RESULT_DONE: number;
|
|
598
|
+
ITERATOR_RESULT_FAST: number;
|
|
536
599
|
};
|
|
537
600
|
declare const NativeDatabase: NativeDatabase;
|
|
538
601
|
declare const NativeTransaction: NativeTransaction;
|
|
@@ -566,7 +629,7 @@ declare class Transaction extends DBI {
|
|
|
566
629
|
* @param store - The base store interface for this transaction.
|
|
567
630
|
* @param options - The options for the transaction.
|
|
568
631
|
*/
|
|
569
|
-
constructor(store: Store, options?:
|
|
632
|
+
constructor(store: Store, options?: NativeTransactionOptions);
|
|
570
633
|
/**
|
|
571
634
|
* Abort the transaction.
|
|
572
635
|
*/
|
|
@@ -922,6 +985,20 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
922
985
|
*/
|
|
923
986
|
name?: string;
|
|
924
987
|
}
|
|
988
|
+
interface TransactionOptions extends NativeTransactionOptions {
|
|
989
|
+
/**
|
|
990
|
+
* The maximum number of times to retry the transaction.
|
|
991
|
+
*
|
|
992
|
+
* @default 3
|
|
993
|
+
*/
|
|
994
|
+
maxRetries?: number;
|
|
995
|
+
/**
|
|
996
|
+
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
997
|
+
*
|
|
998
|
+
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
999
|
+
*/
|
|
1000
|
+
retryOnBusy?: boolean;
|
|
1001
|
+
}
|
|
925
1002
|
type RocksDBStat = number | StatsHistogramData;
|
|
926
1003
|
type RocksDBStats = Record<string, RocksDBStat>;
|
|
927
1004
|
/**
|
|
@@ -971,6 +1048,32 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
971
1048
|
*/
|
|
972
1049
|
close(): void;
|
|
973
1050
|
/**
|
|
1051
|
+
* Compacts the entire key range of the database asynchronously.
|
|
1052
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```typescript
|
|
1056
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1057
|
+
* await db.compact();
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
1061
|
+
/**
|
|
1062
|
+
* Compacts the entire key range of the database synchronously.
|
|
1063
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```typescript
|
|
1067
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1068
|
+
* db.compactSync();
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
1071
|
+
compactSync(options?: CompactOptions): void;
|
|
1072
|
+
/**
|
|
1073
|
+
* Returns the list of column families in the RocksDB database.
|
|
1074
|
+
*/
|
|
1075
|
+
get columns(): string[];
|
|
1076
|
+
/**
|
|
974
1077
|
* Set global database settings.
|
|
975
1078
|
*
|
|
976
1079
|
* @param options - The options for the database.
|
|
@@ -1010,7 +1113,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1010
1113
|
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
1011
1114
|
* ```
|
|
1012
1115
|
*/
|
|
1013
|
-
getDBIntProperty(propertyName: string): number;
|
|
1116
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
1014
1117
|
/**
|
|
1015
1118
|
* Gets a RocksDB database property as a string.
|
|
1016
1119
|
*
|
|
@@ -1024,7 +1127,18 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1024
1127
|
* const stats = db.getDBProperty('rocksdb.stats');
|
|
1025
1128
|
* ```
|
|
1026
1129
|
*/
|
|
1027
|
-
getDBProperty(propertyName: string): string;
|
|
1130
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
1131
|
+
/**
|
|
1132
|
+
* Retrieves the estimated number of keys in the database.
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```typescript
|
|
1136
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1137
|
+
* const estimated = db.getEstimatedKeyCount();
|
|
1138
|
+
* console.log(estimated);
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
getEstimatedKeyCount(): number;
|
|
1028
1142
|
/**
|
|
1029
1143
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1030
1144
|
* milliseconds represented as a decimal number.
|
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,7 @@ interface Encoder {
|
|
|
16
16
|
encode?: (value: any, mode?: number) => Buffer;
|
|
17
17
|
Encoder?: EncoderFunction;
|
|
18
18
|
freezeData?: boolean;
|
|
19
|
+
name?: string;
|
|
19
20
|
needsStableBuffer?: boolean;
|
|
20
21
|
randomAccessStructure?: boolean;
|
|
21
22
|
readKey?: (buffer: Buffer, start: number, end: number, inSequence?: boolean) => any;
|
|
@@ -35,16 +36,21 @@ interface DBIteratorValue<T> {
|
|
|
35
36
|
value: T;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* Wraps
|
|
39
|
-
*
|
|
39
|
+
* Wraps the `NativeIterator` C++ binding, decoding keys and values from the
|
|
40
|
+
* shared key/value buffers (fast path) or from per-iteration buffers (slow
|
|
41
|
+
* fallback path used for oversized data or stable-buffer decoders).
|
|
42
|
+
*
|
|
43
|
+
* The native `next()` returns a primitive signal (and writes lengths to the
|
|
44
|
+
* shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
|
|
45
|
+
* so this class is responsible for building the `IteratorResult`.
|
|
40
46
|
*/
|
|
41
47
|
declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
|
|
42
48
|
#private;
|
|
43
|
-
iterator:
|
|
49
|
+
iterator: InstanceType<typeof NativeIteratorCls>;
|
|
44
50
|
store: Store;
|
|
45
|
-
constructor(iterator:
|
|
51
|
+
constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean);
|
|
46
52
|
[Symbol.iterator](): Iterator<DBIteratorValue<T>>;
|
|
47
|
-
next(
|
|
53
|
+
next(): IteratorResult<DBIteratorValue<T>>;
|
|
48
54
|
return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
|
|
49
55
|
throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
|
|
50
56
|
}
|
|
@@ -56,6 +62,10 @@ type StoreIteratorOptions = IteratorOptions & DBITransactional;
|
|
|
56
62
|
type StorePutOptions = PutOptions & DBITransactional;
|
|
57
63
|
type StoreRangeOptions = RangeOptions & DBITransactional;
|
|
58
64
|
type StoreRemoveOptions = DBITransactional | unknown;
|
|
65
|
+
type CompactOptions = {
|
|
66
|
+
start?: Key;
|
|
67
|
+
end?: Key;
|
|
68
|
+
};
|
|
59
69
|
/**
|
|
60
70
|
* Options for the `Store` class.
|
|
61
71
|
*/
|
|
@@ -244,6 +254,28 @@ declare class Store {
|
|
|
244
254
|
*/
|
|
245
255
|
close(): void;
|
|
246
256
|
/**
|
|
257
|
+
* Compacts the entire key range of the database asynchronously.
|
|
258
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
263
|
+
* await db.compact();
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Compacts the entire key range of the database synchronously.
|
|
269
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
274
|
+
* db.compactSync();
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
compactSync(options?: CompactOptions): void;
|
|
278
|
+
/**
|
|
247
279
|
* Decodes a key from the database.
|
|
248
280
|
*
|
|
249
281
|
* @param key - The key to decode.
|
|
@@ -372,29 +404,17 @@ interface PutOptions {
|
|
|
372
404
|
}
|
|
373
405
|
//#endregion
|
|
374
406
|
//#region src/load-binding.d.ts
|
|
375
|
-
type
|
|
407
|
+
type NativeTransactionOptions = {
|
|
376
408
|
/**
|
|
377
409
|
* Whether to disable snapshots.
|
|
378
410
|
*
|
|
379
411
|
* @default false
|
|
380
412
|
*/
|
|
381
413
|
disableSnapshot?: boolean;
|
|
382
|
-
/**
|
|
383
|
-
* The maximum number of times to retry the transaction.
|
|
384
|
-
*
|
|
385
|
-
* @default 3
|
|
386
|
-
*/
|
|
387
|
-
maxRetries?: number;
|
|
388
|
-
/**
|
|
389
|
-
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
390
|
-
*
|
|
391
|
-
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
392
|
-
*/
|
|
393
|
-
retryOnBusy?: boolean;
|
|
394
414
|
};
|
|
395
415
|
type NativeTransaction = {
|
|
396
416
|
id: number;
|
|
397
|
-
new (context: NativeDatabase, options?:
|
|
417
|
+
new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
|
|
398
418
|
abort(): void;
|
|
399
419
|
commit(resolve: () => void, reject: (err: Error) => void): void;
|
|
400
420
|
commitSync(): void;
|
|
@@ -440,6 +460,36 @@ type TransactionLog = {
|
|
|
440
460
|
_lastCommittedPosition: Float64Array;
|
|
441
461
|
_logBuffers: Map<number, WeakRef<LogBuffer>>;
|
|
442
462
|
};
|
|
463
|
+
/**
|
|
464
|
+
* Shape of options that can be passed to the native iterator constructor for
|
|
465
|
+
* the rare case of advanced RocksDB ReadOptions overrides. Common iterator
|
|
466
|
+
* options are passed via the bitmask `flags` argument instead.
|
|
467
|
+
*/
|
|
468
|
+
type NativeIteratorAdvancedOptions = {
|
|
469
|
+
adaptiveReadahead?: boolean;
|
|
470
|
+
asyncIO?: boolean;
|
|
471
|
+
autoReadaheadSize?: boolean;
|
|
472
|
+
backgroundPurgeOnIteratorCleanup?: boolean;
|
|
473
|
+
fillCache?: boolean;
|
|
474
|
+
readaheadSize?: number;
|
|
475
|
+
tailing?: boolean;
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* The result of a single native iterator step. A number value matches one of
|
|
479
|
+
* the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
|
|
480
|
+
* the data does not fit in the shared key/value buffers, or when the decoder
|
|
481
|
+
* needs a stable value buffer.
|
|
482
|
+
*/
|
|
483
|
+
type NativeIteratorResult = number | {
|
|
484
|
+
key: Buffer;
|
|
485
|
+
value?: Buffer;
|
|
486
|
+
};
|
|
487
|
+
declare class NativeIteratorCls {
|
|
488
|
+
constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
|
|
489
|
+
next(): NativeIteratorResult;
|
|
490
|
+
return(): void;
|
|
491
|
+
throw(err?: unknown): void;
|
|
492
|
+
}
|
|
443
493
|
type NativeDatabaseMode = "optimistic" | "pessimistic";
|
|
444
494
|
type NativeDatabaseOptions = {
|
|
445
495
|
disableWAL?: boolean;
|
|
@@ -480,6 +530,9 @@ type NativeDatabase = {
|
|
|
480
530
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
481
531
|
clearSync(): void;
|
|
482
532
|
close(): void;
|
|
533
|
+
compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
|
|
534
|
+
compactSync(start?: Key, end?: Key): void;
|
|
535
|
+
columns: string[];
|
|
483
536
|
destroy(): void;
|
|
484
537
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
485
538
|
dropSync(): void;
|
|
@@ -488,8 +541,8 @@ type NativeDatabase = {
|
|
|
488
541
|
notify(event: string | BufferWithDataView, args?: any[]): boolean;
|
|
489
542
|
get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer>, reject: RejectCallback, txnId?: number): number;
|
|
490
543
|
getCount(options?: RangeOptions, txnId?: number): number;
|
|
491
|
-
getDBIntProperty(propertyName: string): number;
|
|
492
|
-
getDBProperty(propertyName: string): string;
|
|
544
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
545
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
493
546
|
getMonotonicTimestamp(): number;
|
|
494
547
|
getOldestSnapshotTimestamp(): number;
|
|
495
548
|
getStat(statName: string): number | StatsHistogramData;
|
|
@@ -507,6 +560,7 @@ type NativeDatabase = {
|
|
|
507
560
|
removeSync(key: BufferWithDataView, txnId?: number): void;
|
|
508
561
|
setDefaultKeyBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
509
562
|
setDefaultValueBuffer(buffer: Buffer | Uint8Array | null): void;
|
|
563
|
+
setIteratorState(buffer: Buffer | Uint8Array): void;
|
|
510
564
|
tryLock(key: BufferWithDataView, callback?: () => void): boolean;
|
|
511
565
|
unlock(key: BufferWithDataView): void;
|
|
512
566
|
useLog(name: string): TransactionLog;
|
|
@@ -514,6 +568,7 @@ type NativeDatabase = {
|
|
|
514
568
|
};
|
|
515
569
|
type RocksDatabaseConfig = {
|
|
516
570
|
blockCacheSize?: number;
|
|
571
|
+
compactOnClose?: boolean;
|
|
517
572
|
};
|
|
518
573
|
type RegistryStatusDB = {
|
|
519
574
|
path: string;
|
|
@@ -533,6 +588,14 @@ declare const constants: {
|
|
|
533
588
|
TRANSACTION_LOG_TOKEN: number;
|
|
534
589
|
TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
|
|
535
590
|
TRANSACTION_LOG_FILE_HEADER_SIZE: number;
|
|
591
|
+
ITERATOR_REVERSE_FLAG: number;
|
|
592
|
+
ITERATOR_INCLUSIVE_END_FLAG: number;
|
|
593
|
+
ITERATOR_EXCLUSIVE_START_FLAG: number;
|
|
594
|
+
ITERATOR_INCLUDE_VALUES_FLAG: number;
|
|
595
|
+
ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
|
|
596
|
+
ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
|
|
597
|
+
ITERATOR_RESULT_DONE: number;
|
|
598
|
+
ITERATOR_RESULT_FAST: number;
|
|
536
599
|
};
|
|
537
600
|
declare const NativeDatabase: NativeDatabase;
|
|
538
601
|
declare const NativeTransaction: NativeTransaction;
|
|
@@ -566,7 +629,7 @@ declare class Transaction extends DBI {
|
|
|
566
629
|
* @param store - The base store interface for this transaction.
|
|
567
630
|
* @param options - The options for the transaction.
|
|
568
631
|
*/
|
|
569
|
-
constructor(store: Store, options?:
|
|
632
|
+
constructor(store: Store, options?: NativeTransactionOptions);
|
|
570
633
|
/**
|
|
571
634
|
* Abort the transaction.
|
|
572
635
|
*/
|
|
@@ -922,6 +985,20 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
922
985
|
*/
|
|
923
986
|
name?: string;
|
|
924
987
|
}
|
|
988
|
+
interface TransactionOptions extends NativeTransactionOptions {
|
|
989
|
+
/**
|
|
990
|
+
* The maximum number of times to retry the transaction.
|
|
991
|
+
*
|
|
992
|
+
* @default 3
|
|
993
|
+
*/
|
|
994
|
+
maxRetries?: number;
|
|
995
|
+
/**
|
|
996
|
+
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
997
|
+
*
|
|
998
|
+
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
999
|
+
*/
|
|
1000
|
+
retryOnBusy?: boolean;
|
|
1001
|
+
}
|
|
925
1002
|
type RocksDBStat = number | StatsHistogramData;
|
|
926
1003
|
type RocksDBStats = Record<string, RocksDBStat>;
|
|
927
1004
|
/**
|
|
@@ -971,6 +1048,32 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
971
1048
|
*/
|
|
972
1049
|
close(): void;
|
|
973
1050
|
/**
|
|
1051
|
+
* Compacts the entire key range of the database asynchronously.
|
|
1052
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```typescript
|
|
1056
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1057
|
+
* await db.compact();
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
compact(options?: CompactOptions): Promise<void>;
|
|
1061
|
+
/**
|
|
1062
|
+
* Compacts the entire key range of the database synchronously.
|
|
1063
|
+
* This triggers manual compaction which removes tombstones and reclaims space.
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```typescript
|
|
1067
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1068
|
+
* db.compactSync();
|
|
1069
|
+
* ```
|
|
1070
|
+
*/
|
|
1071
|
+
compactSync(options?: CompactOptions): void;
|
|
1072
|
+
/**
|
|
1073
|
+
* Returns the list of column families in the RocksDB database.
|
|
1074
|
+
*/
|
|
1075
|
+
get columns(): string[];
|
|
1076
|
+
/**
|
|
974
1077
|
* Set global database settings.
|
|
975
1078
|
*
|
|
976
1079
|
* @param options - The options for the database.
|
|
@@ -1010,7 +1113,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1010
1113
|
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
1011
1114
|
* ```
|
|
1012
1115
|
*/
|
|
1013
|
-
getDBIntProperty(propertyName: string): number;
|
|
1116
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
1014
1117
|
/**
|
|
1015
1118
|
* Gets a RocksDB database property as a string.
|
|
1016
1119
|
*
|
|
@@ -1024,7 +1127,18 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1024
1127
|
* const stats = db.getDBProperty('rocksdb.stats');
|
|
1025
1128
|
* ```
|
|
1026
1129
|
*/
|
|
1027
|
-
getDBProperty(propertyName: string): string;
|
|
1130
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
1131
|
+
/**
|
|
1132
|
+
* Retrieves the estimated number of keys in the database.
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```typescript
|
|
1136
|
+
* const db = RocksDatabase.open('/path/to/database');
|
|
1137
|
+
* const estimated = db.getEstimatedKeyCount();
|
|
1138
|
+
* console.log(estimated);
|
|
1139
|
+
* ```
|
|
1140
|
+
*/
|
|
1141
|
+
getEstimatedKeyCount(): number;
|
|
1028
1142
|
/**
|
|
1029
1143
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1030
1144
|
* milliseconds represented as a decimal number.
|