@harperfast/rocksdb-js 1.0.1 → 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 +55 -8
- package/dist/index.cjs +44 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -23
- package/dist/index.d.mts +48 -23
- package/dist/index.mjs +44 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -20
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;
|
|
@@ -75,6 +76,11 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transaction
|
|
|
75
76
|
* If `true`, the encoder will use a random access structure.
|
|
76
77
|
*/
|
|
77
78
|
randomAccessStructure?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* When `true`, the database is opened in read-only mode. Write operations
|
|
81
|
+
* will throw an error with code `ERR_DATABASE_READONLY`.
|
|
82
|
+
*/
|
|
83
|
+
readOnly?: boolean;
|
|
78
84
|
sharedStructuresKey?: symbol;
|
|
79
85
|
/**
|
|
80
86
|
* A string containing the amount of time or the number of milliseconds to
|
|
@@ -180,6 +186,11 @@ declare class Store {
|
|
|
180
186
|
*/
|
|
181
187
|
pessimistic: boolean;
|
|
182
188
|
/**
|
|
189
|
+
* Whether the database is open in readonly mode. When `true`, write
|
|
190
|
+
* operations will throw an error with code `ERR_DATABASE_READONLY`.
|
|
191
|
+
*/
|
|
192
|
+
readOnly: boolean;
|
|
193
|
+
/**
|
|
183
194
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
184
195
|
* access structure.
|
|
185
196
|
*/
|
|
@@ -362,29 +373,17 @@ interface PutOptions {
|
|
|
362
373
|
}
|
|
363
374
|
//#endregion
|
|
364
375
|
//#region src/load-binding.d.ts
|
|
365
|
-
type
|
|
376
|
+
type NativeTransactionOptions = {
|
|
366
377
|
/**
|
|
367
378
|
* Whether to disable snapshots.
|
|
368
379
|
*
|
|
369
380
|
* @default false
|
|
370
381
|
*/
|
|
371
382
|
disableSnapshot?: boolean;
|
|
372
|
-
/**
|
|
373
|
-
* The maximum number of times to retry the transaction.
|
|
374
|
-
*
|
|
375
|
-
* @default 3
|
|
376
|
-
*/
|
|
377
|
-
maxRetries?: number;
|
|
378
|
-
/**
|
|
379
|
-
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
380
|
-
*
|
|
381
|
-
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
382
|
-
*/
|
|
383
|
-
retryOnBusy?: boolean;
|
|
384
383
|
};
|
|
385
384
|
type NativeTransaction = {
|
|
386
385
|
id: number;
|
|
387
|
-
new (context: NativeDatabase, options?:
|
|
386
|
+
new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
|
|
388
387
|
abort(): void;
|
|
389
388
|
commit(resolve: () => void, reject: (err: Error) => void): void;
|
|
390
389
|
commitSync(): void;
|
|
@@ -416,7 +415,7 @@ type TransactionEntry = {
|
|
|
416
415
|
endTxn: boolean;
|
|
417
416
|
};
|
|
418
417
|
type TransactionLog = {
|
|
419
|
-
new (name: string): TransactionLog;
|
|
418
|
+
new (db: NativeDatabase, name: string): TransactionLog;
|
|
420
419
|
addEntry(data: Buffer | Uint8Array, txnId?: number): void;
|
|
421
420
|
getLogFileSize(sequenceId?: number): number;
|
|
422
421
|
name: string;
|
|
@@ -438,6 +437,7 @@ type NativeDatabaseOptions = {
|
|
|
438
437
|
name?: string;
|
|
439
438
|
noBlockCache?: boolean;
|
|
440
439
|
parallelismThreads?: number;
|
|
440
|
+
readOnly?: boolean;
|
|
441
441
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
442
442
|
transactionLogMaxAgeThreshold?: number;
|
|
443
443
|
transactionLogMaxSize?: number;
|
|
@@ -469,6 +469,7 @@ type NativeDatabase = {
|
|
|
469
469
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
470
470
|
clearSync(): void;
|
|
471
471
|
close(): void;
|
|
472
|
+
columns: string[];
|
|
472
473
|
destroy(): void;
|
|
473
474
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
474
475
|
dropSync(): void;
|
|
@@ -477,8 +478,8 @@ type NativeDatabase = {
|
|
|
477
478
|
notify(event: string | BufferWithDataView, args?: any[]): boolean;
|
|
478
479
|
get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer>, reject: RejectCallback, txnId?: number): number;
|
|
479
480
|
getCount(options?: RangeOptions, txnId?: number): number;
|
|
480
|
-
getDBIntProperty(propertyName: string): number;
|
|
481
|
-
getDBProperty(propertyName: string): string;
|
|
481
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
482
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
482
483
|
getMonotonicTimestamp(): number;
|
|
483
484
|
getOldestSnapshotTimestamp(): number;
|
|
484
485
|
getStat(statName: string): number | StatsHistogramData;
|
|
@@ -555,7 +556,7 @@ declare class Transaction extends DBI {
|
|
|
555
556
|
* @param store - The base store interface for this transaction.
|
|
556
557
|
* @param options - The options for the transaction.
|
|
557
558
|
*/
|
|
558
|
-
constructor(store: Store, options?:
|
|
559
|
+
constructor(store: Store, options?: NativeTransactionOptions);
|
|
559
560
|
/**
|
|
560
561
|
* Abort the transaction.
|
|
561
562
|
*/
|
|
@@ -911,6 +912,22 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
911
912
|
*/
|
|
912
913
|
name?: string;
|
|
913
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
|
+
}
|
|
929
|
+
type RocksDBStat = number | StatsHistogramData;
|
|
930
|
+
type RocksDBStats = Record<string, RocksDBStat>;
|
|
914
931
|
/**
|
|
915
932
|
* The main class for interacting with a RocksDB database.
|
|
916
933
|
*
|
|
@@ -958,6 +975,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
958
975
|
*/
|
|
959
976
|
close(): void;
|
|
960
977
|
/**
|
|
978
|
+
* Returns the list of column families in the RocksDB database.
|
|
979
|
+
*/
|
|
980
|
+
get columns(): string[];
|
|
981
|
+
/**
|
|
961
982
|
* Set global database settings.
|
|
962
983
|
*
|
|
963
984
|
* @param options - The options for the database.
|
|
@@ -997,7 +1018,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
997
1018
|
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
998
1019
|
* ```
|
|
999
1020
|
*/
|
|
1000
|
-
getDBIntProperty(propertyName: string): number;
|
|
1021
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
1001
1022
|
/**
|
|
1002
1023
|
* Gets a RocksDB database property as a string.
|
|
1003
1024
|
*
|
|
@@ -1011,7 +1032,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1011
1032
|
* const stats = db.getDBProperty('rocksdb.stats');
|
|
1012
1033
|
* ```
|
|
1013
1034
|
*/
|
|
1014
|
-
getDBProperty(propertyName: string): string;
|
|
1035
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
1015
1036
|
/**
|
|
1016
1037
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1017
1038
|
* milliseconds represented as a decimal number.
|
|
@@ -1032,7 +1053,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1032
1053
|
* @param statName - The name of the statistic to retrieve.
|
|
1033
1054
|
* @returns The statistic value.
|
|
1034
1055
|
*/
|
|
1035
|
-
getStat(statName: string):
|
|
1056
|
+
getStat(statName: string): RocksDBStat;
|
|
1036
1057
|
/**
|
|
1037
1058
|
* Gets the RocksDB statistics. Requires statistics to be enabled.
|
|
1038
1059
|
*
|
|
@@ -1042,7 +1063,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1042
1063
|
* const stats = db.getStats();
|
|
1043
1064
|
* ```
|
|
1044
1065
|
*/
|
|
1045
|
-
getStats(all?: boolean):
|
|
1066
|
+
getStats(all?: boolean): RocksDBStats;
|
|
1046
1067
|
/**
|
|
1047
1068
|
* Gets or creates a buffer that can be shared across worker threads.
|
|
1048
1069
|
*
|
|
@@ -1096,6 +1117,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1096
1117
|
*/
|
|
1097
1118
|
get name(): string;
|
|
1098
1119
|
/**
|
|
1120
|
+
* Whether the database is open in readonly mode.
|
|
1121
|
+
*/
|
|
1122
|
+
get readOnly(): boolean;
|
|
1123
|
+
/**
|
|
1099
1124
|
* Sugar method for opening a database.
|
|
1100
1125
|
*
|
|
1101
1126
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1246,5 +1271,5 @@ declare const versions: {
|
|
|
1246
1271
|
"rocksdb-js": string;
|
|
1247
1272
|
};
|
|
1248
1273
|
//#endregion
|
|
1249
|
-
export { DBI, DBIterator, type IteratorOptions, type Key, RocksDatabase, type RocksDatabaseOptions, type StatsHistogramData, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, constants, currentThreadId, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1274
|
+
export { DBI, DBIterator, type IteratorOptions, type Key, type RocksDBStat, type RocksDBStats, RocksDatabase, type RocksDatabaseOptions, type StatsHistogramData, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, constants, currentThreadId, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1250
1275
|
//# sourceMappingURL=index.d.cts.map
|
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;
|
|
@@ -75,6 +76,11 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transaction
|
|
|
75
76
|
* If `true`, the encoder will use a random access structure.
|
|
76
77
|
*/
|
|
77
78
|
randomAccessStructure?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* When `true`, the database is opened in read-only mode. Write operations
|
|
81
|
+
* will throw an error with code `ERR_DATABASE_READONLY`.
|
|
82
|
+
*/
|
|
83
|
+
readOnly?: boolean;
|
|
78
84
|
sharedStructuresKey?: symbol;
|
|
79
85
|
/**
|
|
80
86
|
* A string containing the amount of time or the number of milliseconds to
|
|
@@ -180,6 +186,11 @@ declare class Store {
|
|
|
180
186
|
*/
|
|
181
187
|
pessimistic: boolean;
|
|
182
188
|
/**
|
|
189
|
+
* Whether the database is open in readonly mode. When `true`, write
|
|
190
|
+
* operations will throw an error with code `ERR_DATABASE_READONLY`.
|
|
191
|
+
*/
|
|
192
|
+
readOnly: boolean;
|
|
193
|
+
/**
|
|
183
194
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
184
195
|
* access structure.
|
|
185
196
|
*/
|
|
@@ -362,29 +373,17 @@ interface PutOptions {
|
|
|
362
373
|
}
|
|
363
374
|
//#endregion
|
|
364
375
|
//#region src/load-binding.d.ts
|
|
365
|
-
type
|
|
376
|
+
type NativeTransactionOptions = {
|
|
366
377
|
/**
|
|
367
378
|
* Whether to disable snapshots.
|
|
368
379
|
*
|
|
369
380
|
* @default false
|
|
370
381
|
*/
|
|
371
382
|
disableSnapshot?: boolean;
|
|
372
|
-
/**
|
|
373
|
-
* The maximum number of times to retry the transaction.
|
|
374
|
-
*
|
|
375
|
-
* @default 3
|
|
376
|
-
*/
|
|
377
|
-
maxRetries?: number;
|
|
378
|
-
/**
|
|
379
|
-
* Whether to retry the transaction if it fails with `IsBusy`.
|
|
380
|
-
*
|
|
381
|
-
* @default `true` when the transaction is bound to a transaction log, otherwise `false`
|
|
382
|
-
*/
|
|
383
|
-
retryOnBusy?: boolean;
|
|
384
383
|
};
|
|
385
384
|
type NativeTransaction = {
|
|
386
385
|
id: number;
|
|
387
|
-
new (context: NativeDatabase, options?:
|
|
386
|
+
new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
|
|
388
387
|
abort(): void;
|
|
389
388
|
commit(resolve: () => void, reject: (err: Error) => void): void;
|
|
390
389
|
commitSync(): void;
|
|
@@ -416,7 +415,7 @@ type TransactionEntry = {
|
|
|
416
415
|
endTxn: boolean;
|
|
417
416
|
};
|
|
418
417
|
type TransactionLog = {
|
|
419
|
-
new (name: string): TransactionLog;
|
|
418
|
+
new (db: NativeDatabase, name: string): TransactionLog;
|
|
420
419
|
addEntry(data: Buffer | Uint8Array, txnId?: number): void;
|
|
421
420
|
getLogFileSize(sequenceId?: number): number;
|
|
422
421
|
name: string;
|
|
@@ -438,6 +437,7 @@ type NativeDatabaseOptions = {
|
|
|
438
437
|
name?: string;
|
|
439
438
|
noBlockCache?: boolean;
|
|
440
439
|
parallelismThreads?: number;
|
|
440
|
+
readOnly?: boolean;
|
|
441
441
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
442
442
|
transactionLogMaxAgeThreshold?: number;
|
|
443
443
|
transactionLogMaxSize?: number;
|
|
@@ -469,6 +469,7 @@ type NativeDatabase = {
|
|
|
469
469
|
clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
470
470
|
clearSync(): void;
|
|
471
471
|
close(): void;
|
|
472
|
+
columns: string[];
|
|
472
473
|
destroy(): void;
|
|
473
474
|
drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
|
|
474
475
|
dropSync(): void;
|
|
@@ -477,8 +478,8 @@ type NativeDatabase = {
|
|
|
477
478
|
notify(event: string | BufferWithDataView, args?: any[]): boolean;
|
|
478
479
|
get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer>, reject: RejectCallback, txnId?: number): number;
|
|
479
480
|
getCount(options?: RangeOptions, txnId?: number): number;
|
|
480
|
-
getDBIntProperty(propertyName: string): number;
|
|
481
|
-
getDBProperty(propertyName: string): string;
|
|
481
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
482
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
482
483
|
getMonotonicTimestamp(): number;
|
|
483
484
|
getOldestSnapshotTimestamp(): number;
|
|
484
485
|
getStat(statName: string): number | StatsHistogramData;
|
|
@@ -555,7 +556,7 @@ declare class Transaction extends DBI {
|
|
|
555
556
|
* @param store - The base store interface for this transaction.
|
|
556
557
|
* @param options - The options for the transaction.
|
|
557
558
|
*/
|
|
558
|
-
constructor(store: Store, options?:
|
|
559
|
+
constructor(store: Store, options?: NativeTransactionOptions);
|
|
559
560
|
/**
|
|
560
561
|
* Abort the transaction.
|
|
561
562
|
*/
|
|
@@ -911,6 +912,22 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
911
912
|
*/
|
|
912
913
|
name?: string;
|
|
913
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
|
+
}
|
|
929
|
+
type RocksDBStat = number | StatsHistogramData;
|
|
930
|
+
type RocksDBStats = Record<string, RocksDBStat>;
|
|
914
931
|
/**
|
|
915
932
|
* The main class for interacting with a RocksDB database.
|
|
916
933
|
*
|
|
@@ -958,6 +975,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
958
975
|
*/
|
|
959
976
|
close(): void;
|
|
960
977
|
/**
|
|
978
|
+
* Returns the list of column families in the RocksDB database.
|
|
979
|
+
*/
|
|
980
|
+
get columns(): string[];
|
|
981
|
+
/**
|
|
961
982
|
* Set global database settings.
|
|
962
983
|
*
|
|
963
984
|
* @param options - The options for the database.
|
|
@@ -997,7 +1018,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
997
1018
|
* const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
|
|
998
1019
|
* ```
|
|
999
1020
|
*/
|
|
1000
|
-
getDBIntProperty(propertyName: string): number;
|
|
1021
|
+
getDBIntProperty(propertyName: string): number | undefined;
|
|
1001
1022
|
/**
|
|
1002
1023
|
* Gets a RocksDB database property as a string.
|
|
1003
1024
|
*
|
|
@@ -1011,7 +1032,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1011
1032
|
* const stats = db.getDBProperty('rocksdb.stats');
|
|
1012
1033
|
* ```
|
|
1013
1034
|
*/
|
|
1014
|
-
getDBProperty(propertyName: string): string;
|
|
1035
|
+
getDBProperty(propertyName: string): string | undefined;
|
|
1015
1036
|
/**
|
|
1016
1037
|
* Returns the current timestamp as a monotonically increasing timestamp in
|
|
1017
1038
|
* milliseconds represented as a decimal number.
|
|
@@ -1032,7 +1053,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1032
1053
|
* @param statName - The name of the statistic to retrieve.
|
|
1033
1054
|
* @returns The statistic value.
|
|
1034
1055
|
*/
|
|
1035
|
-
getStat(statName: string):
|
|
1056
|
+
getStat(statName: string): RocksDBStat;
|
|
1036
1057
|
/**
|
|
1037
1058
|
* Gets the RocksDB statistics. Requires statistics to be enabled.
|
|
1038
1059
|
*
|
|
@@ -1042,7 +1063,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1042
1063
|
* const stats = db.getStats();
|
|
1043
1064
|
* ```
|
|
1044
1065
|
*/
|
|
1045
|
-
getStats(all?: boolean):
|
|
1066
|
+
getStats(all?: boolean): RocksDBStats;
|
|
1046
1067
|
/**
|
|
1047
1068
|
* Gets or creates a buffer that can be shared across worker threads.
|
|
1048
1069
|
*
|
|
@@ -1096,6 +1117,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1096
1117
|
*/
|
|
1097
1118
|
get name(): string;
|
|
1098
1119
|
/**
|
|
1120
|
+
* Whether the database is open in readonly mode.
|
|
1121
|
+
*/
|
|
1122
|
+
get readOnly(): boolean;
|
|
1123
|
+
/**
|
|
1099
1124
|
* Sugar method for opening a database.
|
|
1100
1125
|
*
|
|
1101
1126
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1246,5 +1271,5 @@ declare const versions: {
|
|
|
1246
1271
|
"rocksdb-js": string;
|
|
1247
1272
|
};
|
|
1248
1273
|
//#endregion
|
|
1249
|
-
export { DBI, DBIterator, type IteratorOptions, type Key, RocksDatabase, type RocksDatabaseOptions, type StatsHistogramData, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, constants, currentThreadId, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1274
|
+
export { DBI, DBIterator, type IteratorOptions, type Key, type RocksDBStat, type RocksDBStats, RocksDatabase, type RocksDatabaseOptions, type StatsHistogramData, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, constants, currentThreadId, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1250
1275
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -629,6 +629,11 @@ var Store = class {
|
|
|
629
629
|
*/
|
|
630
630
|
pessimistic;
|
|
631
631
|
/**
|
|
632
|
+
* Whether the database is open in readonly mode. When `true`, write
|
|
633
|
+
* operations will throw an error with code `ERR_DATABASE_READONLY`.
|
|
634
|
+
*/
|
|
635
|
+
readOnly;
|
|
636
|
+
/**
|
|
632
637
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
633
638
|
* access structure.
|
|
634
639
|
*/
|
|
@@ -697,6 +702,7 @@ var Store = class {
|
|
|
697
702
|
this.parallelismThreads = options?.parallelismThreads ?? 1;
|
|
698
703
|
this.path = path;
|
|
699
704
|
this.pessimistic = options?.pessimistic ?? false;
|
|
705
|
+
this.readOnly = options?.readOnly ?? false;
|
|
700
706
|
this.randomAccessStructure = options?.randomAccessStructure ?? false;
|
|
701
707
|
this.readKey = readKey;
|
|
702
708
|
this.sharedStructuresKey = options?.sharedStructuresKey;
|
|
@@ -767,6 +773,7 @@ var Store = class {
|
|
|
767
773
|
const keyParam = getKeyParam(this.encodeKey(key));
|
|
768
774
|
let flags = 0;
|
|
769
775
|
if (alwaysCreateNewBuffer) flags |= ALWAYS_CREATE_NEW_BUFFER_FLAG;
|
|
776
|
+
if (this.readOnly) txnId = void 0;
|
|
770
777
|
const result = context.getSync(keyParam, flags | ONLY_IF_IN_MEMORY_CACHE_FLAG, txnId);
|
|
771
778
|
if (typeof result === "number") {
|
|
772
779
|
if (result === NOT_IN_MEMORY_CACHE_FLAG) return new Promise((resolve, reject) => {
|
|
@@ -839,7 +846,7 @@ var Store = class {
|
|
|
839
846
|
*/
|
|
840
847
|
getTxnId(options) {
|
|
841
848
|
let txnId;
|
|
842
|
-
if (options?.transaction) {
|
|
849
|
+
if (!this.readOnly && options?.transaction) {
|
|
843
850
|
txnId = options.transaction.id;
|
|
844
851
|
if (txnId === void 0) throw new TypeError("Invalid transaction");
|
|
845
852
|
}
|
|
@@ -907,6 +914,7 @@ var Store = class {
|
|
|
907
914
|
name: this.name,
|
|
908
915
|
noBlockCache: this.noBlockCache,
|
|
909
916
|
parallelismThreads: this.parallelismThreads,
|
|
917
|
+
readOnly: this.readOnly,
|
|
910
918
|
statsLevel: this.statsLevel,
|
|
911
919
|
transactionLogMaxAgeThreshold: this.transactionLogMaxAgeThreshold,
|
|
912
920
|
transactionLogMaxSize: this.transactionLogMaxSize,
|
|
@@ -1022,9 +1030,17 @@ var Transaction = class extends DBI {
|
|
|
1022
1030
|
* @param options - The options for the transaction.
|
|
1023
1031
|
*/
|
|
1024
1032
|
constructor(store, options) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1033
|
+
if (store.readOnly) {
|
|
1034
|
+
super(store);
|
|
1035
|
+
this.#txn = { id: 0 };
|
|
1036
|
+
this.abort = this.commitSync = this.setTimestamp = () => {};
|
|
1037
|
+
this.commit = async () => {};
|
|
1038
|
+
this.getTimestamp = () => 0;
|
|
1039
|
+
} else {
|
|
1040
|
+
const txn = new NativeTransaction(store.db, options);
|
|
1041
|
+
super(store, txn);
|
|
1042
|
+
this.#txn = txn;
|
|
1043
|
+
}
|
|
1028
1044
|
}
|
|
1029
1045
|
/**
|
|
1030
1046
|
* Abort the transaction.
|
|
@@ -1178,6 +1194,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1178
1194
|
this.store.close();
|
|
1179
1195
|
}
|
|
1180
1196
|
/**
|
|
1197
|
+
* Returns the list of column families in the RocksDB database.
|
|
1198
|
+
*/
|
|
1199
|
+
get columns() {
|
|
1200
|
+
return this.store.db.columns;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1181
1203
|
* Set global database settings.
|
|
1182
1204
|
*
|
|
1183
1205
|
* @param options - The options for the database.
|
|
@@ -1354,6 +1376,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1354
1376
|
return this.#name;
|
|
1355
1377
|
}
|
|
1356
1378
|
/**
|
|
1379
|
+
* Whether the database is open in readonly mode.
|
|
1380
|
+
*/
|
|
1381
|
+
get readOnly() {
|
|
1382
|
+
return this.store.readOnly;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1357
1385
|
* Sugar method for opening a database.
|
|
1358
1386
|
*
|
|
1359
1387
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1415,14 +1443,14 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1415
1443
|
return buffer && store.decoder?.decode ? store.decoder.decode(buffer) : void 0;
|
|
1416
1444
|
};
|
|
1417
1445
|
opts.saveStructures = (structures, isCompatible) => {
|
|
1418
|
-
return this.transactionSync((txn) => {
|
|
1446
|
+
return this.transactionSync((txn, _attempt) => {
|
|
1419
1447
|
const existingStructuresBuffer = this.getBinarySync(sharedStructuresKey);
|
|
1420
1448
|
const existingStructures = existingStructuresBuffer && store.decoder?.decode ? store.decoder.decode(existingStructuresBuffer) : void 0;
|
|
1421
1449
|
if (typeof isCompatible == "function") {
|
|
1422
1450
|
if (!isCompatible(existingStructures)) return false;
|
|
1423
1451
|
} else if (existingStructures && existingStructures.length !== isCompatible) return false;
|
|
1424
1452
|
txn.putSync(sharedStructuresKey, structures);
|
|
1425
|
-
});
|
|
1453
|
+
}, { retryOnBusy: true });
|
|
1426
1454
|
};
|
|
1427
1455
|
}
|
|
1428
1456
|
store.encoder = new EncoderClass({
|
|
@@ -1439,16 +1467,15 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1439
1467
|
};
|
|
1440
1468
|
store.decoder = store.encoder;
|
|
1441
1469
|
}
|
|
1442
|
-
if (typeof store.encoder?.writeKey === "function" && !store.encoder?.encode) {
|
|
1443
|
-
store.encoder
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
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;
|
|
1452
1479
|
if (store.decoder && store.decoder.needsStableBuffer !== true) store.decoderCopies = true;
|
|
1453
1480
|
if (store.decoder?.readKey && !store.decoder.decode) {
|
|
1454
1481
|
store.decoder.decode = (buffer) => {
|
|
@@ -1884,7 +1911,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
1884
1911
|
//#region src/index.ts
|
|
1885
1912
|
const versions = {
|
|
1886
1913
|
rocksdb: version,
|
|
1887
|
-
"rocksdb-js": "1.
|
|
1914
|
+
"rocksdb-js": "1.1.1"
|
|
1888
1915
|
};
|
|
1889
1916
|
|
|
1890
1917
|
//#endregion
|