@harperfast/rocksdb-js 0.1.3 → 0.1.4

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/dist/index.d.cts CHANGED
@@ -50,7 +50,12 @@ declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
50
50
  }
51
51
  //#endregion
52
52
  //#region src/store.d.ts
53
- type Context = NativeDatabase | NativeTransaction;
53
+ type StoreContext = NativeDatabase | NativeTransaction;
54
+ type StoreGetOptions = GetOptions & DBITransactional;
55
+ type StoreIteratorOptions = IteratorOptions & DBITransactional;
56
+ type StorePutOptions = PutOptions & DBITransactional;
57
+ type StoreRangeOptions = RangeOptions & DBITransactional;
58
+ type StoreRemoveOptions = DBITransactional | unknown;
54
59
  /**
55
60
  * Options for the `Store` class.
56
61
  */
@@ -248,10 +253,12 @@ declare class Store {
248
253
  * @returns The encoded value.
249
254
  */
250
255
  encodeValue(value: any): BufferWithDataView | Uint8Array;
251
- get(context: NativeDatabase | NativeTransaction, key: Key, alwaysCreateNewBuffer?: boolean, txnId?: number): any | undefined;
252
- getCount(context: NativeDatabase | NativeTransaction, options?: RangeOptions): number;
253
- getRange(context: NativeDatabase | NativeTransaction, options?: IteratorOptions & DBITransactional): ExtendedIterable<DBIteratorValue<any>>;
254
- getSync(context: NativeDatabase | NativeTransaction, key: Key, alwaysCreateNewBuffer?: boolean, options?: GetOptions & DBITransactional): any | undefined;
256
+ get(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, txnId?: number): any | undefined;
257
+ getCount(context: StoreContext, options?: StoreRangeOptions): number;
258
+ getKeys(context: StoreContext, options?: StoreIteratorOptions): any | undefined;
259
+ getKeysCount(context: StoreContext, options?: StoreRangeOptions): number;
260
+ getRange(context: StoreContext, options?: StoreIteratorOptions): ExtendedIterable<DBIteratorValue<any>>;
261
+ getSync(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
255
262
  /**
256
263
  * Checks if the data method options object contains a transaction ID and
257
264
  * returns it.
@@ -294,8 +301,8 @@ declare class Store {
294
301
  * are performed.
295
302
  */
296
303
  open(): boolean;
297
- putSync(context: NativeDatabase | NativeTransaction, key: Key, value: any, options?: PutOptions & DBITransactional): void;
298
- removeSync(context: NativeDatabase | NativeTransaction, key: Key, options?: DBITransactional | undefined): void;
304
+ putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
305
+ removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
299
306
  /**
300
307
  * Attempts to acquire a lock for a given key. If the lock is available,
301
308
  * the function returns `true` and the optional callback is never called.
@@ -321,7 +328,7 @@ declare class Store {
321
328
  * @param name - The name of the transaction log.
322
329
  * @returns The transaction log.
323
330
  */
324
- useLog(context: NativeDatabase | NativeTransaction, name: string | number): TransactionLog;
331
+ useLog(context: StoreContext, name: string | number): TransactionLog;
325
332
  /**
326
333
  * Acquires a lock on the given key and calls the callback.
327
334
  *
@@ -639,7 +646,10 @@ interface DBITransactional {
639
646
  * This class is not meant to be used directly.
640
647
  */
641
648
  declare class DBI<T extends DBITransactional | unknown = unknown> {
642
- #private;
649
+ /**
650
+ * The RocksDB context for `get()`, `put()`, and `remove()`.
651
+ */
652
+ _context: StoreContext;
643
653
  /**
644
654
  * The database store instance. The store instance is tied to the database
645
655
  * instance and shared with transaction instances.
@@ -1171,5 +1181,5 @@ declare const versions: {
1171
1181
  "rocksdb-js": string;
1172
1182
  };
1173
1183
  //#endregion
1174
- export { type Context, DBIterator, type IteratorOptions, type Key, RocksDatabase, type RocksDatabaseOptions, Store, Transaction, type TransactionEntry, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, versions };
1184
+ export { DBI, DBIterator, type IteratorOptions, type Key, RocksDatabase, type RocksDatabaseOptions, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, versions };
1175
1185
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -50,7 +50,12 @@ declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
50
50
  }
51
51
  //#endregion
52
52
  //#region src/store.d.ts
53
- type Context = NativeDatabase | NativeTransaction;
53
+ type StoreContext = NativeDatabase | NativeTransaction;
54
+ type StoreGetOptions = GetOptions & DBITransactional;
55
+ type StoreIteratorOptions = IteratorOptions & DBITransactional;
56
+ type StorePutOptions = PutOptions & DBITransactional;
57
+ type StoreRangeOptions = RangeOptions & DBITransactional;
58
+ type StoreRemoveOptions = DBITransactional | unknown;
54
59
  /**
55
60
  * Options for the `Store` class.
56
61
  */
@@ -248,10 +253,12 @@ declare class Store {
248
253
  * @returns The encoded value.
249
254
  */
250
255
  encodeValue(value: any): BufferWithDataView | Uint8Array;
251
- get(context: NativeDatabase | NativeTransaction, key: Key, alwaysCreateNewBuffer?: boolean, txnId?: number): any | undefined;
252
- getCount(context: NativeDatabase | NativeTransaction, options?: RangeOptions): number;
253
- getRange(context: NativeDatabase | NativeTransaction, options?: IteratorOptions & DBITransactional): ExtendedIterable<DBIteratorValue<any>>;
254
- getSync(context: NativeDatabase | NativeTransaction, key: Key, alwaysCreateNewBuffer?: boolean, options?: GetOptions & DBITransactional): any | undefined;
256
+ get(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, txnId?: number): any | undefined;
257
+ getCount(context: StoreContext, options?: StoreRangeOptions): number;
258
+ getKeys(context: StoreContext, options?: StoreIteratorOptions): any | undefined;
259
+ getKeysCount(context: StoreContext, options?: StoreRangeOptions): number;
260
+ getRange(context: StoreContext, options?: StoreIteratorOptions): ExtendedIterable<DBIteratorValue<any>>;
261
+ getSync(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
255
262
  /**
256
263
  * Checks if the data method options object contains a transaction ID and
257
264
  * returns it.
@@ -294,8 +301,8 @@ declare class Store {
294
301
  * are performed.
295
302
  */
296
303
  open(): boolean;
297
- putSync(context: NativeDatabase | NativeTransaction, key: Key, value: any, options?: PutOptions & DBITransactional): void;
298
- removeSync(context: NativeDatabase | NativeTransaction, key: Key, options?: DBITransactional | undefined): void;
304
+ putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
305
+ removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
299
306
  /**
300
307
  * Attempts to acquire a lock for a given key. If the lock is available,
301
308
  * the function returns `true` and the optional callback is never called.
@@ -321,7 +328,7 @@ declare class Store {
321
328
  * @param name - The name of the transaction log.
322
329
  * @returns The transaction log.
323
330
  */
324
- useLog(context: NativeDatabase | NativeTransaction, name: string | number): TransactionLog;
331
+ useLog(context: StoreContext, name: string | number): TransactionLog;
325
332
  /**
326
333
  * Acquires a lock on the given key and calls the callback.
327
334
  *
@@ -639,7 +646,10 @@ interface DBITransactional {
639
646
  * This class is not meant to be used directly.
640
647
  */
641
648
  declare class DBI<T extends DBITransactional | unknown = unknown> {
642
- #private;
649
+ /**
650
+ * The RocksDB context for `get()`, `put()`, and `remove()`.
651
+ */
652
+ _context: StoreContext;
643
653
  /**
644
654
  * The database store instance. The store instance is tied to the database
645
655
  * instance and shared with transaction instances.
@@ -1171,5 +1181,5 @@ declare const versions: {
1171
1181
  "rocksdb-js": string;
1172
1182
  };
1173
1183
  //#endregion
1174
- export { type Context, DBIterator, type IteratorOptions, type Key, RocksDatabase, type RocksDatabaseOptions, Store, Transaction, type TransactionEntry, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, versions };
1184
+ export { DBI, DBIterator, type IteratorOptions, type Key, RocksDatabase, type RocksDatabaseOptions, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, versions };
1175
1185
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -145,7 +145,7 @@ var DBI = class DBI {
145
145
  /**
146
146
  * The RocksDB context for `get()`, `put()`, and `remove()`.
147
147
  */
148
- #context;
148
+ _context;
149
149
  /**
150
150
  * The database store instance. The store instance is tied to the database
151
151
  * instance and shared with transaction instances.
@@ -160,7 +160,7 @@ var DBI = class DBI {
160
160
  constructor(store, transaction) {
161
161
  if (new.target === DBI) throw new Error("DBI is an abstract class and cannot be instantiated directly");
162
162
  this.store = store;
163
- this.#context = transaction || store.db;
163
+ this._context = transaction || store.db;
164
164
  }
165
165
  /**
166
166
  * Adds a listener for the given key.
@@ -191,14 +191,14 @@ var DBI = class DBI {
191
191
  */
192
192
  getBinary(key, options) {
193
193
  if (!this.store.isOpen()) return Promise.reject(/* @__PURE__ */ new Error("Database not open"));
194
- return this.store.get(this.#context, key, true, this.store.getTxnId(options));
194
+ return this.store.get(this._context, key, true, this.store.getTxnId(options));
195
195
  }
196
196
  /**
197
197
  * Synchronously retrieves the binary data for the given key.
198
198
  */
199
199
  getBinarySync(key, options) {
200
200
  if (!this.store.isOpen()) throw new Error("Database not open");
201
- return this.store.getSync(this.#context, key, true, options);
201
+ return this.store.getSync(this._context, key, true, options);
202
202
  }
203
203
  /**
204
204
  * Retrieves the binary data for the given key using a preallocated,
@@ -212,7 +212,7 @@ var DBI = class DBI {
212
212
  */
213
213
  getBinaryFast(key, options) {
214
214
  if (!this.store.isOpen()) return Promise.reject(/* @__PURE__ */ new Error("Database not open"));
215
- return this.store.get(this.#context, key, false, this.store.getTxnId(options));
215
+ return this.store.get(this._context, key, false, this.store.getTxnId(options));
216
216
  }
217
217
  /**
218
218
  * Synchronously retrieves the binary data for the given key using a
@@ -221,16 +221,13 @@ var DBI = class DBI {
221
221
  */
222
222
  getBinaryFastSync(key, options) {
223
223
  if (!this.store.isOpen()) throw new Error("Database not open");
224
- return this.store.getSync(this.#context, key, false, options);
224
+ return this.store.getSync(this._context, key, false, options);
225
225
  }
226
226
  /**
227
227
  * Retrieves all keys within a range.
228
228
  */
229
229
  getKeys(options) {
230
- return this.store.getRange(this.#context, {
231
- ...options,
232
- values: false
233
- }).map((item) => item.key);
230
+ return this.store.getKeys(this._context, options);
234
231
  }
235
232
  /**
236
233
  * Retrieves the number of keys within a range.
@@ -245,7 +242,7 @@ var DBI = class DBI {
245
242
  * ```
246
243
  */
247
244
  getKeysCount(options) {
248
- return this.store.getCount(this.#context, options);
245
+ return this.store.getKeysCount(this._context, options);
249
246
  }
250
247
  /**
251
248
  * Retrieves a range of keys and their values.
@@ -265,7 +262,7 @@ var DBI = class DBI {
265
262
  * ```
266
263
  */
267
264
  getRange(options) {
268
- return this.store.getRange(this.#context, options);
265
+ return this.store.getRange(this._context, options);
269
266
  }
270
267
  /**
271
268
  * Synchronously retrieves the value for the given key, then returns the
@@ -282,7 +279,7 @@ var DBI = class DBI {
282
279
  return result ? this.store.decodeValue(result) : void 0;
283
280
  }
284
281
  if (!this.store.isOpen()) throw new Error("Database not open");
285
- return this.store.decodeValue(this.store.getSync(this.#context, key, true, options));
282
+ return this.store.decodeValue(this.store.getSync(this._context, key, true, options));
286
283
  }
287
284
  /**
288
285
  * Gets the number of listeners for the given key.
@@ -351,7 +348,7 @@ var DBI = class DBI {
351
348
  * ```
352
349
  */
353
350
  async put(key, value, options) {
354
- return this.store.putSync(this.#context, key, value, options);
351
+ return this.store.putSync(this._context, key, value, options);
355
352
  }
356
353
  /**
357
354
  * Synchronously stores a value for the given key.
@@ -367,7 +364,7 @@ var DBI = class DBI {
367
364
  * ```
368
365
  */
369
366
  putSync(key, value, options) {
370
- return this.store.putSync(this.#context, key, value, options);
367
+ return this.store.putSync(this._context, key, value, options);
371
368
  }
372
369
  /**
373
370
  * Removes a value for the given key. If the key does not exist, it will
@@ -383,7 +380,7 @@ var DBI = class DBI {
383
380
  * ```
384
381
  */
385
382
  async remove(key, options) {
386
- return this.store.removeSync(this.#context, key, options);
383
+ return this.store.removeSync(this._context, key, options);
387
384
  }
388
385
  /**
389
386
  * Removes a value for the given key. If the key does not exist, it will
@@ -399,7 +396,7 @@ var DBI = class DBI {
399
396
  * ```
400
397
  */
401
398
  removeSync(key, options) {
402
- return this.store.removeSync(this.#context, key, options);
399
+ return this.store.removeSync(this._context, key, options);
403
400
  }
404
401
  /**
405
402
  * Removes an event listener. You must specify the exact same callback that was
@@ -418,7 +415,7 @@ var DBI = class DBI {
418
415
  * @returns The transaction log.
419
416
  */
420
417
  useLog(name) {
421
- return this.store.useLog(this.#context, name);
418
+ return this.store.useLog(this._context, name);
422
419
  }
423
420
  };
424
421
 
@@ -775,6 +772,15 @@ var Store = class {
775
772
  }
776
773
  return context.getCount(options, this.getTxnId(options));
777
774
  }
775
+ getKeys(context, options) {
776
+ return this.getRange(context, {
777
+ ...options,
778
+ values: false
779
+ }).map((item) => item.key);
780
+ }
781
+ getKeysCount(context, options) {
782
+ return this.getCount(context, options);
783
+ }
778
784
  getRange(context, options) {
779
785
  if (!this.db.opened) throw new Error("Database not open");
780
786
  options = { ...options };
@@ -1780,9 +1786,9 @@ function loadLastPosition(transactionLog, readUncommitted) {
1780
1786
  //#region src/index.ts
1781
1787
  const versions = {
1782
1788
  rocksdb: version,
1783
- "rocksdb-js": "0.1.3"
1789
+ "rocksdb-js": "0.1.4"
1784
1790
  };
1785
1791
 
1786
1792
  //#endregion
1787
- export { DBIterator, RocksDatabase, Store, Transaction, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, versions };
1793
+ export { DBI, DBIterator, RocksDatabase, Store, Transaction, TransactionLog, constants, parseTransactionLog, registryStatus, shutdown, versions };
1788
1794
  //# sourceMappingURL=index.mjs.map