@harperfast/rocksdb-js 1.0.0 → 1.1.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 +45 -5
- package/dist/index.cjs +29 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -4
- package/dist/index.d.mts +22 -4
- package/dist/index.mjs +29 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -19
package/dist/index.d.cts
CHANGED
|
@@ -75,6 +75,11 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transaction
|
|
|
75
75
|
* If `true`, the encoder will use a random access structure.
|
|
76
76
|
*/
|
|
77
77
|
randomAccessStructure?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* When `true`, the database is opened in read-only mode. Write operations
|
|
80
|
+
* will throw an error with code `ERR_DATABASE_READONLY`.
|
|
81
|
+
*/
|
|
82
|
+
readOnly?: boolean;
|
|
78
83
|
sharedStructuresKey?: symbol;
|
|
79
84
|
/**
|
|
80
85
|
* A string containing the amount of time or the number of milliseconds to
|
|
@@ -180,6 +185,11 @@ declare class Store {
|
|
|
180
185
|
*/
|
|
181
186
|
pessimistic: boolean;
|
|
182
187
|
/**
|
|
188
|
+
* Whether the database is open in readonly mode. When `true`, write
|
|
189
|
+
* operations will throw an error with code `ERR_DATABASE_READONLY`.
|
|
190
|
+
*/
|
|
191
|
+
readOnly: boolean;
|
|
192
|
+
/**
|
|
183
193
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
184
194
|
* access structure.
|
|
185
195
|
*/
|
|
@@ -416,7 +426,7 @@ type TransactionEntry = {
|
|
|
416
426
|
endTxn: boolean;
|
|
417
427
|
};
|
|
418
428
|
type TransactionLog = {
|
|
419
|
-
new (name: string): TransactionLog;
|
|
429
|
+
new (db: NativeDatabase, name: string): TransactionLog;
|
|
420
430
|
addEntry(data: Buffer | Uint8Array, txnId?: number): void;
|
|
421
431
|
getLogFileSize(sequenceId?: number): number;
|
|
422
432
|
name: string;
|
|
@@ -438,6 +448,7 @@ type NativeDatabaseOptions = {
|
|
|
438
448
|
name?: string;
|
|
439
449
|
noBlockCache?: boolean;
|
|
440
450
|
parallelismThreads?: number;
|
|
451
|
+
readOnly?: boolean;
|
|
441
452
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
442
453
|
transactionLogMaxAgeThreshold?: number;
|
|
443
454
|
transactionLogMaxSize?: number;
|
|
@@ -528,6 +539,7 @@ declare const NativeTransaction: NativeTransaction;
|
|
|
528
539
|
declare const TransactionLog: TransactionLog;
|
|
529
540
|
declare const registryStatus: () => RegistryStatus;
|
|
530
541
|
declare const shutdown: () => void;
|
|
542
|
+
declare const currentThreadId: () => number;
|
|
531
543
|
declare const stats: {
|
|
532
544
|
histograms: string[];
|
|
533
545
|
tickers: string[];
|
|
@@ -910,6 +922,8 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
910
922
|
*/
|
|
911
923
|
name?: string;
|
|
912
924
|
}
|
|
925
|
+
type RocksDBStat = number | StatsHistogramData;
|
|
926
|
+
type RocksDBStats = Record<string, RocksDBStat>;
|
|
913
927
|
/**
|
|
914
928
|
* The main class for interacting with a RocksDB database.
|
|
915
929
|
*
|
|
@@ -1031,7 +1045,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1031
1045
|
* @param statName - The name of the statistic to retrieve.
|
|
1032
1046
|
* @returns The statistic value.
|
|
1033
1047
|
*/
|
|
1034
|
-
getStat(statName: string):
|
|
1048
|
+
getStat(statName: string): RocksDBStat;
|
|
1035
1049
|
/**
|
|
1036
1050
|
* Gets the RocksDB statistics. Requires statistics to be enabled.
|
|
1037
1051
|
*
|
|
@@ -1041,7 +1055,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1041
1055
|
* const stats = db.getStats();
|
|
1042
1056
|
* ```
|
|
1043
1057
|
*/
|
|
1044
|
-
getStats(all?: boolean):
|
|
1058
|
+
getStats(all?: boolean): RocksDBStats;
|
|
1045
1059
|
/**
|
|
1046
1060
|
* Gets or creates a buffer that can be shared across worker threads.
|
|
1047
1061
|
*
|
|
@@ -1095,6 +1109,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1095
1109
|
*/
|
|
1096
1110
|
get name(): string;
|
|
1097
1111
|
/**
|
|
1112
|
+
* Whether the database is open in readonly mode.
|
|
1113
|
+
*/
|
|
1114
|
+
get readOnly(): boolean;
|
|
1115
|
+
/**
|
|
1098
1116
|
* Sugar method for opening a database.
|
|
1099
1117
|
*
|
|
1100
1118
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1245,5 +1263,5 @@ declare const versions: {
|
|
|
1245
1263
|
"rocksdb-js": string;
|
|
1246
1264
|
};
|
|
1247
1265
|
//#endregion
|
|
1248
|
-
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, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1266
|
+
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 };
|
|
1249
1267
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -75,6 +75,11 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transaction
|
|
|
75
75
|
* If `true`, the encoder will use a random access structure.
|
|
76
76
|
*/
|
|
77
77
|
randomAccessStructure?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* When `true`, the database is opened in read-only mode. Write operations
|
|
80
|
+
* will throw an error with code `ERR_DATABASE_READONLY`.
|
|
81
|
+
*/
|
|
82
|
+
readOnly?: boolean;
|
|
78
83
|
sharedStructuresKey?: symbol;
|
|
79
84
|
/**
|
|
80
85
|
* A string containing the amount of time or the number of milliseconds to
|
|
@@ -180,6 +185,11 @@ declare class Store {
|
|
|
180
185
|
*/
|
|
181
186
|
pessimistic: boolean;
|
|
182
187
|
/**
|
|
188
|
+
* Whether the database is open in readonly mode. When `true`, write
|
|
189
|
+
* operations will throw an error with code `ERR_DATABASE_READONLY`.
|
|
190
|
+
*/
|
|
191
|
+
readOnly: boolean;
|
|
192
|
+
/**
|
|
183
193
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
184
194
|
* access structure.
|
|
185
195
|
*/
|
|
@@ -416,7 +426,7 @@ type TransactionEntry = {
|
|
|
416
426
|
endTxn: boolean;
|
|
417
427
|
};
|
|
418
428
|
type TransactionLog = {
|
|
419
|
-
new (name: string): TransactionLog;
|
|
429
|
+
new (db: NativeDatabase, name: string): TransactionLog;
|
|
420
430
|
addEntry(data: Buffer | Uint8Array, txnId?: number): void;
|
|
421
431
|
getLogFileSize(sequenceId?: number): number;
|
|
422
432
|
name: string;
|
|
@@ -438,6 +448,7 @@ type NativeDatabaseOptions = {
|
|
|
438
448
|
name?: string;
|
|
439
449
|
noBlockCache?: boolean;
|
|
440
450
|
parallelismThreads?: number;
|
|
451
|
+
readOnly?: boolean;
|
|
441
452
|
statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
|
|
442
453
|
transactionLogMaxAgeThreshold?: number;
|
|
443
454
|
transactionLogMaxSize?: number;
|
|
@@ -528,6 +539,7 @@ declare const NativeTransaction: NativeTransaction;
|
|
|
528
539
|
declare const TransactionLog: TransactionLog;
|
|
529
540
|
declare const registryStatus: () => RegistryStatus;
|
|
530
541
|
declare const shutdown: () => void;
|
|
542
|
+
declare const currentThreadId: () => number;
|
|
531
543
|
declare const stats: {
|
|
532
544
|
histograms: string[];
|
|
533
545
|
tickers: string[];
|
|
@@ -910,6 +922,8 @@ interface RocksDatabaseOptions extends StoreOptions {
|
|
|
910
922
|
*/
|
|
911
923
|
name?: string;
|
|
912
924
|
}
|
|
925
|
+
type RocksDBStat = number | StatsHistogramData;
|
|
926
|
+
type RocksDBStats = Record<string, RocksDBStat>;
|
|
913
927
|
/**
|
|
914
928
|
* The main class for interacting with a RocksDB database.
|
|
915
929
|
*
|
|
@@ -1031,7 +1045,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1031
1045
|
* @param statName - The name of the statistic to retrieve.
|
|
1032
1046
|
* @returns The statistic value.
|
|
1033
1047
|
*/
|
|
1034
|
-
getStat(statName: string):
|
|
1048
|
+
getStat(statName: string): RocksDBStat;
|
|
1035
1049
|
/**
|
|
1036
1050
|
* Gets the RocksDB statistics. Requires statistics to be enabled.
|
|
1037
1051
|
*
|
|
@@ -1041,7 +1055,7 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1041
1055
|
* const stats = db.getStats();
|
|
1042
1056
|
* ```
|
|
1043
1057
|
*/
|
|
1044
|
-
getStats(all?: boolean):
|
|
1058
|
+
getStats(all?: boolean): RocksDBStats;
|
|
1045
1059
|
/**
|
|
1046
1060
|
* Gets or creates a buffer that can be shared across worker threads.
|
|
1047
1061
|
*
|
|
@@ -1095,6 +1109,10 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1095
1109
|
*/
|
|
1096
1110
|
get name(): string;
|
|
1097
1111
|
/**
|
|
1112
|
+
* Whether the database is open in readonly mode.
|
|
1113
|
+
*/
|
|
1114
|
+
get readOnly(): boolean;
|
|
1115
|
+
/**
|
|
1098
1116
|
* Sugar method for opening a database.
|
|
1099
1117
|
*
|
|
1100
1118
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1245,5 +1263,5 @@ declare const versions: {
|
|
|
1245
1263
|
"rocksdb-js": string;
|
|
1246
1264
|
};
|
|
1247
1265
|
//#endregion
|
|
1248
|
-
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, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1266
|
+
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 };
|
|
1249
1267
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,7 @@ const NativeTransaction = binding.Transaction;
|
|
|
62
62
|
const TransactionLog = binding.TransactionLog;
|
|
63
63
|
const registryStatus = binding.registryStatus;
|
|
64
64
|
const shutdown = binding.shutdown;
|
|
65
|
+
const currentThreadId = binding.currentThreadId;
|
|
65
66
|
const stats = binding.stats;
|
|
66
67
|
const version = binding.version;
|
|
67
68
|
|
|
@@ -628,6 +629,11 @@ var Store = class {
|
|
|
628
629
|
*/
|
|
629
630
|
pessimistic;
|
|
630
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
|
+
/**
|
|
631
637
|
* Encoder specific flag used to signal that the encoder should use a random
|
|
632
638
|
* access structure.
|
|
633
639
|
*/
|
|
@@ -696,6 +702,7 @@ var Store = class {
|
|
|
696
702
|
this.parallelismThreads = options?.parallelismThreads ?? 1;
|
|
697
703
|
this.path = path;
|
|
698
704
|
this.pessimistic = options?.pessimistic ?? false;
|
|
705
|
+
this.readOnly = options?.readOnly ?? false;
|
|
699
706
|
this.randomAccessStructure = options?.randomAccessStructure ?? false;
|
|
700
707
|
this.readKey = readKey;
|
|
701
708
|
this.sharedStructuresKey = options?.sharedStructuresKey;
|
|
@@ -766,6 +773,7 @@ var Store = class {
|
|
|
766
773
|
const keyParam = getKeyParam(this.encodeKey(key));
|
|
767
774
|
let flags = 0;
|
|
768
775
|
if (alwaysCreateNewBuffer) flags |= ALWAYS_CREATE_NEW_BUFFER_FLAG;
|
|
776
|
+
if (this.readOnly) txnId = void 0;
|
|
769
777
|
const result = context.getSync(keyParam, flags | ONLY_IF_IN_MEMORY_CACHE_FLAG, txnId);
|
|
770
778
|
if (typeof result === "number") {
|
|
771
779
|
if (result === NOT_IN_MEMORY_CACHE_FLAG) return new Promise((resolve, reject) => {
|
|
@@ -838,7 +846,7 @@ var Store = class {
|
|
|
838
846
|
*/
|
|
839
847
|
getTxnId(options) {
|
|
840
848
|
let txnId;
|
|
841
|
-
if (options?.transaction) {
|
|
849
|
+
if (!this.readOnly && options?.transaction) {
|
|
842
850
|
txnId = options.transaction.id;
|
|
843
851
|
if (txnId === void 0) throw new TypeError("Invalid transaction");
|
|
844
852
|
}
|
|
@@ -906,6 +914,7 @@ var Store = class {
|
|
|
906
914
|
name: this.name,
|
|
907
915
|
noBlockCache: this.noBlockCache,
|
|
908
916
|
parallelismThreads: this.parallelismThreads,
|
|
917
|
+
readOnly: this.readOnly,
|
|
909
918
|
statsLevel: this.statsLevel,
|
|
910
919
|
transactionLogMaxAgeThreshold: this.transactionLogMaxAgeThreshold,
|
|
911
920
|
transactionLogMaxSize: this.transactionLogMaxSize,
|
|
@@ -1021,9 +1030,17 @@ var Transaction = class extends DBI {
|
|
|
1021
1030
|
* @param options - The options for the transaction.
|
|
1022
1031
|
*/
|
|
1023
1032
|
constructor(store, options) {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
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
|
+
}
|
|
1027
1044
|
}
|
|
1028
1045
|
/**
|
|
1029
1046
|
* Abort the transaction.
|
|
@@ -1353,6 +1370,12 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1353
1370
|
return this.#name;
|
|
1354
1371
|
}
|
|
1355
1372
|
/**
|
|
1373
|
+
* Whether the database is open in readonly mode.
|
|
1374
|
+
*/
|
|
1375
|
+
get readOnly() {
|
|
1376
|
+
return this.store.readOnly;
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1356
1379
|
* Sugar method for opening a database.
|
|
1357
1380
|
*
|
|
1358
1381
|
* @param pathOrStore - The filesystem path to the database or a custom store.
|
|
@@ -1883,9 +1906,9 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
1883
1906
|
//#region src/index.ts
|
|
1884
1907
|
const versions = {
|
|
1885
1908
|
rocksdb: version,
|
|
1886
|
-
"rocksdb-js": "1.
|
|
1909
|
+
"rocksdb-js": "1.1.0"
|
|
1887
1910
|
};
|
|
1888
1911
|
|
|
1889
1912
|
//#endregion
|
|
1890
|
-
export { DBI, DBIterator, RocksDatabase, Store, Transaction, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1913
|
+
export { DBI, DBIterator, RocksDatabase, Store, Transaction, TransactionLog, constants, currentThreadId, parseTransactionLog, registryStatus, shutdown, stats, versions };
|
|
1891
1914
|
//# sourceMappingURL=index.mjs.map
|