@harperfast/rocksdb-js 1.1.0 → 1.1.1
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 +19 -3
- package/dist/index.cjs +18 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -19
- package/dist/index.d.mts +27 -19
- package/dist/index.mjs +18 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
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;
|
|
@@ -372,29 +373,17 @@ interface PutOptions {
|
|
|
372
373
|
}
|
|
373
374
|
//#endregion
|
|
374
375
|
//#region src/load-binding.d.ts
|
|
375
|
-
type
|
|
376
|
+
type NativeTransactionOptions = {
|
|
376
377
|
/**
|
|
377
378
|
* Whether to disable snapshots.
|
|
378
379
|
*
|
|
379
380
|
* @default false
|
|
380
381
|
*/
|
|
381
382
|
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
383
|
};
|
|
395
384
|
type NativeTransaction = {
|
|
396
385
|
id: number;
|
|
397
|
-
new (context: NativeDatabase, options?:
|
|
386
|
+
new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
|
|
398
387
|
abort(): void;
|
|
399
388
|
commit(resolve: () => void, reject: (err: Error) => void): void;
|
|
400
389
|
commitSync(): void;
|
|
@@ -480,6 +469,7 @@ type NativeDatabase = {
|
|
|
480
469
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
481
470
|
clearSync(): void;
|
|
482
471
|
close(): void;
|
|
472
|
+
columns: string[];
|
|
483
473
|
destroy(): void;
|
|
484
474
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
485
475
|
dropSync(): void;
|
|
@@ -488,8 +478,8 @@ type NativeDatabase = {
|
|
|
488
478
|
notify(event: string | BufferWithDataView, args?: any[]): boolean;
|
|
489
479
|
get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer>, reject: RejectCallback, txnId?: number): number;
|
|
490
480
|
getCount(options?: RangeOptions, txnId?: number): number;
|
|
491
|
-
getDBIntProperty(propertyName: string): number;
|
|
492
|
-
getDBProperty(propertyName: string): string;
|
|
481
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
482
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
493
483
|
getMonotonicTimestamp(): number;
|
|
494
484
|
getOldestSnapshotTimestamp(): number;
|
|
495
485
|
getStat(statName: string): number | StatsHistogramData;
|
|
@@ -566,7 +556,7 @@ declare class Transaction extends DBI {
|
|
|
566
556
|
* @param store - The base store interface for this transaction.
|
|
567
557
|
* @param options - The options for the transaction.
|
|
568
558
|
*/
|
|
569
|
-
constructor(store: Store, options?:
|
|
559
|
+
constructor(store: Store, options?: NativeTransactionOptions);
|
|
570
560
|
/**
|
|
571
561
|
* Abort the transaction.
|
|
572
562
|
*/
|
|
@@ -922,6 +912,20 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
922
912
|
*/
|
|
923
913
|
name?: string;
|
|
924
914
|
}
|
|
915
|
+
interface TransactionOptions extends NativeTransactionOptions {
|
|
916
|
+
/**
|
|
917
|
+
* The maximum number of times to retry the transaction.
|
|
918
|
+
*
|
|
919
|
+
* @default 3
|
|
920
|
+
*/
|
|
921
|
+
maxRetries?: number;
|
|
922
|
+
/**
|
|
923
|
+
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
924
|
+
*
|
|
925
|
+
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
926
|
+
*/
|
|
927
|
+
retryOnBusy?: boolean;
|
|
928
|
+
}
|
|
925
929
|
type RocksDBStat = number | StatsHistogramData;
|
|
926
930
|
type RocksDBStats = Record<string, RocksDBStat>;
|
|
927
931
|
/**
|
|
@@ -971,6 +975,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
971
975
|
*/
|
|
972
976
|
close(): void;
|
|
973
977
|
/**
|
|
978
|
+
* Returns the list of column families in the RocksDB database.
|
|
979
|
+
*/
|
|
980
|
+
get columns(): string[];
|
|
981
|
+
/**
|
|
974
982
|
* Set global database settings.
|
|
975
983
|
*
|
|
976
984
|
* @param options - The options for the database.
|
|
@@ -1010,7 +1018,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1010
1018
|
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
1011
1019
|
* ```
|
|
1012
1020
|
*/
|
|
1013
|
-
getDBIntProperty(propertyName: string): number;
|
|
1021
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
1014
1022
|
/**
|
|
1015
1023
|
* Gets a RocksDB database property as a string.
|
|
1016
1024
|
*
|
|
@@ -1024,7 +1032,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1024
1032
|
* const stats = db.getDBProperty('rocksdb.stats');
|
|
1025
1033
|
* ```
|
|
1026
1034
|
*/
|
|
1027
|
-
getDBProperty(propertyName: string): string;
|
|
1035
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
1028
1036
|
/**
|
|
1029
1037
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1030
1038
|
* 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;
|
|
@@ -372,29 +373,17 @@ interface PutOptions {
|
|
|
372
373
|
}
|
|
373
374
|
//#endregion
|
|
374
375
|
//#region src/load-binding.d.ts
|
|
375
|
-
type
|
|
376
|
+
type NativeTransactionOptions = {
|
|
376
377
|
/**
|
|
377
378
|
* Whether to disable snapshots.
|
|
378
379
|
*
|
|
379
380
|
* @default false
|
|
380
381
|
*/
|
|
381
382
|
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
383
|
};
|
|
395
384
|
type NativeTransaction = {
|
|
396
385
|
id: number;
|
|
397
|
-
new (context: NativeDatabase, options?:
|
|
386
|
+
new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
|
|
398
387
|
abort(): void;
|
|
399
388
|
commit(resolve: () => void, reject: (err: Error) => void): void;
|
|
400
389
|
commitSync(): void;
|
|
@@ -480,6 +469,7 @@ type NativeDatabase = {
|
|
|
480
469
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
481
470
|
clearSync(): void;
|
|
482
471
|
close(): void;
|
|
472
|
+
columns: string[];
|
|
483
473
|
destroy(): void;
|
|
484
474
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
485
475
|
dropSync(): void;
|
|
@@ -488,8 +478,8 @@ type NativeDatabase = {
|
|
|
488
478
|
notify(event: string | BufferWithDataView, args?: any[]): boolean;
|
|
489
479
|
get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer>, reject: RejectCallback, txnId?: number): number;
|
|
490
480
|
getCount(options?: RangeOptions, txnId?: number): number;
|
|
491
|
-
getDBIntProperty(propertyName: string): number;
|
|
492
|
-
getDBProperty(propertyName: string): string;
|
|
481
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
482
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
493
483
|
getMonotonicTimestamp(): number;
|
|
494
484
|
getOldestSnapshotTimestamp(): number;
|
|
495
485
|
getStat(statName: string): number | StatsHistogramData;
|
|
@@ -566,7 +556,7 @@ declare class Transaction extends DBI {
|
|
|
566
556
|
* @param store - The base store interface for this transaction.
|
|
567
557
|
* @param options - The options for the transaction.
|
|
568
558
|
*/
|
|
569
|
-
constructor(store: Store, options?:
|
|
559
|
+
constructor(store: Store, options?: NativeTransactionOptions);
|
|
570
560
|
/**
|
|
571
561
|
* Abort the transaction.
|
|
572
562
|
*/
|
|
@@ -922,6 +912,20 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
922
912
|
*/
|
|
923
913
|
name?: string;
|
|
924
914
|
}
|
|
915
|
+
interface TransactionOptions extends NativeTransactionOptions {
|
|
916
|
+
/**
|
|
917
|
+
* The maximum number of times to retry the transaction.
|
|
918
|
+
*
|
|
919
|
+
* @default 3
|
|
920
|
+
*/
|
|
921
|
+
maxRetries?: number;
|
|
922
|
+
/**
|
|
923
|
+
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
924
|
+
*
|
|
925
|
+
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
926
|
+
*/
|
|
927
|
+
retryOnBusy?: boolean;
|
|
928
|
+
}
|
|
925
929
|
type RocksDBStat = number | StatsHistogramData;
|
|
926
930
|
type RocksDBStats = Record<string, RocksDBStat>;
|
|
927
931
|
/**
|
|
@@ -971,6 +975,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
971
975
|
*/
|
|
972
976
|
close(): void;
|
|
973
977
|
/**
|
|
978
|
+
* Returns the list of column families in the RocksDB database.
|
|
979
|
+
*/
|
|
980
|
+
get columns(): string[];
|
|
981
|
+
/**
|
|
974
982
|
* Set global database settings.
|
|
975
983
|
*
|
|
976
984
|
* @param options - The options for the database.
|
|
@@ -1010,7 +1018,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1010
1018
|
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
1011
1019
|
* ```
|
|
1012
1020
|
*/
|
|
1013
|
-
getDBIntProperty(propertyName: string): number;
|
|
1021
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
1014
1022
|
/**
|
|
1015
1023
|
* Gets a RocksDB database property as a string.
|
|
1016
1024
|
*
|
|
@@ -1024,7 +1032,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1024
1032
|
* const stats = db.getDBProperty('rocksdb.stats');
|
|
1025
1033
|
* ```
|
|
1026
1034
|
*/
|
|
1027
|
-
getDBProperty(propertyName: string): string;
|
|
1035
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
1028
1036
|
/**
|
|
1029
1037
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1030
1038
|
* milliseconds represented as a decimal number.
|
package/dist/index.mjs
CHANGED
|
@@ -1194,6 +1194,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1194
1194
|
this.store.close();
|
|
1195
1195
|
}
|
|
1196
1196
|
/**
|
|
1197
|
+
* Returns the list of column families in the RocksDB database.
|
|
1198
|
+
*/
|
|
1199
|
+
get columns() {
|
|
1200
|
+
return this.store.db.columns;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1197
1203
|
* Set global database settings.
|
|
1198
1204
|
*
|
|
1199
1205
|
* @param options - The options for the database.
|
|
@@ -1437,14 +1443,14 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1437
1443
|
return buffer && store.decoder?.decode ? store.decoder.decode(buffer) : void 0;
|
|
1438
1444
|
};
|
|
1439
1445
|
opts.saveStructures = (structures, isCompatible) => {
|
|
1440
|
-
return this.transactionSync((txn) => {
|
|
1446
|
+
return this.transactionSync((txn, _attempt) => {
|
|
1441
1447
|
const existingStructuresBuffer = this.getBinarySync(sharedStructuresKey);
|
|
1442
1448
|
const existingStructures = existingStructuresBuffer && store.decoder?.decode ? store.decoder.decode(existingStructuresBuffer) : void 0;
|
|
1443
1449
|
if (typeof isCompatible == "function") {
|
|
1444
1450
|
if (!isCompatible(existingStructures)) return false;
|
|
1445
1451
|
} else if (existingStructures && existingStructures.length !== isCompatible) return false;
|
|
1446
1452
|
txn.putSync(sharedStructuresKey, structures);
|
|
1447
|
-
});
|
|
1453
|
+
}, { retryOnBusy: true });
|
|
1448
1454
|
};
|
|
1449
1455
|
}
|
|
1450
1456
|
store.encoder = new EncoderClass({
|
|
@@ -1461,16 +1467,15 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1461
1467
|
};
|
|
1462
1468
|
store.decoder = store.encoder;
|
|
1463
1469
|
}
|
|
1464
|
-
if (typeof store.encoder?.writeKey === "function" && !store.encoder?.encode) {
|
|
1465
|
-
store.encoder
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
}
|
|
1470
|
+
if (typeof store.encoder?.writeKey === "function" && !store.encoder?.encode) store.encoder = {
|
|
1471
|
+
...store.encoder,
|
|
1472
|
+
encode: (value, _mode) => {
|
|
1473
|
+
const bytesWritten = store.writeKey(value, store.encodeBuffer, 0);
|
|
1474
|
+
return store.encodeBuffer.subarray(0, bytesWritten);
|
|
1475
|
+
},
|
|
1476
|
+
copyBuffers: true
|
|
1477
|
+
};
|
|
1478
|
+
if (store.encoder) store.encoder.name = this.#name;
|
|
1474
1479
|
if (store.decoder && store.decoder.needsStableBuffer !== true) store.decoderCopies = true;
|
|
1475
1480
|
if (store.decoder?.readKey && !store.decoder.decode) {
|
|
1476
1481
|
store.decoder.decode = (buffer) => {
|
|
@@ -1906,7 +1911,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
1906
1911
|
//#region src/index.ts
|
|
1907
1912
|
const versions = {
|
|
1908
1913
|
rocksdb: version,
|
|
1909
|
-
"rocksdb-js": "1.1.
|
|
1914
|
+
"rocksdb-js": "1.1.1"
|
|
1910
1915
|
};
|
|
1911
1916
|
|
|
1912
1917
|
//#endregion
|