@harperfast/rocksdb-js 2.3.0 → 2.5.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/dist/index.d.mts CHANGED
@@ -1,85 +1,121 @@
1
1
  import { ExtendedIterable } from "@harperfast/extended-iterable";
2
-
3
2
  //#region src/backup.d.ts
4
3
  /**
5
- * Options for creating a backup via `db.backup()`.
6
- *
7
- * Backups are whole-database: every column family, the manifest, and (unless
8
- * `backupLogFiles` is disabled) the write-ahead log are captured. A backup is
9
- * not scoped to an individual `Store`.
10
- */
4
+ * Options for creating a backup via `db.backup()`.
5
+ *
6
+ * Backups are whole-database: every column family, the manifest, and (unless
7
+ * `backupLogFiles` is disabled) the write-ahead log are captured. A backup is
8
+ * not scoped to an individual `Store`.
9
+ */
11
10
  interface BackupOptions {
12
11
  /**
13
- * Flush the memtable before backing up. Defaults to `true` when the database
14
- * was opened with `disableWAL` (otherwise unflushed data would be lost from
15
- * the backup), and `false` otherwise.
16
- */
12
+ * Include write-ahead log files in the backup. Defaults to `true`.
13
+ */
14
+ backupLogFiles?: boolean;
15
+ /**
16
+ * Preflight the destination volume and reject the backup when it lacks room.
17
+ * Defaults to `true`. The rejection is an I/O error whose message reports the
18
+ * available and required bytes (it is not distinguishable by an `err.code`).
19
+ *
20
+ * The required size is estimated conservatively as a *full* copy of the
21
+ * database's live files, plus the transaction-log snapshot when
22
+ * `transactionLogs` is enabled (a backup only ever copies files, so this can
23
+ * never under-estimate the bytes written). For incremental backups to a
24
+ * right-sized volume this may over-reject — set `false` to skip the check in
25
+ * that case. The check also self-disables when free space is unknowable (e.g.
26
+ * some network filesystems report 0), so it never blocks a backup on an
27
+ * untrustworthy number.
28
+ *
29
+ * Only applies to directory-target backups; the streaming backup path is
30
+ * unaffected.
31
+ */
32
+ checkDiskSpace?: boolean;
33
+ /**
34
+ * Flush the memtable before backing up. Defaults to `true` when the database
35
+ * was opened with `disableWAL` (otherwise unflushed data would be lost from
36
+ * the backup), and `false` otherwise.
37
+ */
17
38
  flushBeforeBackup?: boolean;
18
39
  /**
19
- * Arbitrary application metadata stored with the backup and returned by
20
- * `backups.list()`.
21
- */
22
- metadata?: string;
40
+ * Number of background threads used to copy files. Defaults to `1`.
41
+ */
42
+ maxBackgroundOperations?: number;
23
43
  /**
24
- * Share table/blob files between backups in the same directory to enable
25
- * incremental backups. Defaults to `true`.
26
- */
27
- shareTableFiles?: boolean;
44
+ * Arbitrary application metadata stored with the backup and returned by
45
+ * `backups.list()`.
46
+ */
47
+ metadata?: string;
28
48
  /**
29
- * Distinguish shared files by checksum to avoid collisions across databases.
30
- * Defaults to `true`. Only relevant when `shareTableFiles` is enabled.
31
- */
49
+ * Distinguish shared files by checksum to avoid collisions across databases.
50
+ * Defaults to `true`. Only relevant when `shareTableFiles` is enabled.
51
+ */
32
52
  shareFilesWithChecksum?: boolean;
33
53
  /**
34
- * Include write-ahead log files in the backup. Defaults to `true`.
35
- */
36
- backupLogFiles?: boolean;
54
+ * Share table/blob files between backups in the same directory to enable
55
+ * incremental backups. Defaults to `true`.
56
+ */
57
+ shareTableFiles?: boolean;
37
58
  /**
38
- * `fsync` backup files for crash consistency. Defaults to `true`.
39
- */
59
+ * `fsync` backup files — including the transaction log snapshot when
60
+ * `transactionLogs` is enabled — for crash consistency. Defaults to `true`.
61
+ */
40
62
  sync?: boolean;
41
63
  /**
42
- * Number of background threads used to copy files. Defaults to `1`.
43
- */
44
- maxBackgroundOperations?: number;
64
+ * Snapshot the transaction log store into
65
+ * `<backupDir>/transaction_logs/<backupId>/`. Defaults to `false`. This is an
66
+ * all-or-nothing snapshot per backup (not incremental); `backups.delete()` and
67
+ * `backups.purge()` remove the corresponding log snapshots, and
68
+ * `backups.restore()` restores them into the database directory.
69
+ *
70
+ * The snapshot is staged and atomically renamed into place after every file
71
+ * is copied (and fsynced, per `sync`), so a crash mid-backup can never leave
72
+ * a partial snapshot: a backup id either has its complete log snapshot or
73
+ * none at all.
74
+ *
75
+ * The log snapshot is captured just after the RocksDB engine snapshot, so it
76
+ * may include entries committed between the two — the restored logs can run
77
+ * slightly ahead of the restored key-value data, never behind it. That bias
78
+ * is safe for redo-style logs that are replayed against the restored data.
79
+ */
80
+ transactionLogs?: boolean;
45
81
  }
46
82
  /**
47
- * The level of incremental restore to perform.
48
- *
49
- * - `purgeAllFiles` (default): purge the destination directory and restore all
50
- * files from the backup. Destructive but always correct.
51
- * - `keepLatestDbSessionIdFiles`: efficiently restore a healthy database,
52
- * reusing existing files that match the backup.
53
- * - `verifyChecksum`: reuse existing destination files whose checksums match the
54
- * backup, replacing only mismatched/corrupt files.
55
- */
83
+ * The level of incremental restore to perform.
84
+ *
85
+ * - `purgeAllFiles` (default): purge the destination directory and restore all
86
+ * files from the backup. Destructive but always correct.
87
+ * - `keepLatestDbSessionIdFiles`: efficiently restore a healthy database,
88
+ * reusing existing files that match the backup.
89
+ * - `verifyChecksum`: reuse existing destination files whose checksums match the
90
+ * backup, replacing only mismatched/corrupt files.
91
+ */
56
92
  type RestoreMode = "purgeAllFiles" | "keepLatestDbSessionIdFiles" | "verifyChecksum";
57
93
  /**
58
- * Options for restoring a backup via `backups.restore()`.
59
- */
94
+ * Options for restoring a backup via `backups.restore()`.
95
+ */
60
96
  interface RestoreOptions {
61
97
  /**
62
- * The backup id to restore. Defaults to the latest non-corrupt backup.
63
- */
98
+ * The backup id to restore. Defaults to the latest non-corrupt backup.
99
+ */
64
100
  backupId?: number;
65
101
  /**
66
- * Directory to restore write-ahead log files into. Defaults to the database
67
- * directory.
68
- */
102
+ * Directory to restore write-ahead log files into. Defaults to the database
103
+ * directory.
104
+ */
69
105
  walDir?: string;
70
106
  /**
71
- * Keep existing log files in `walDir` rather than overwriting them. Defaults
72
- * to `false`.
73
- */
107
+ * Keep existing log files in `walDir` rather than overwriting them. Defaults
108
+ * to `false`.
109
+ */
74
110
  keepLogFiles?: boolean;
75
111
  /**
76
- * The restore strategy. Defaults to `purgeAllFiles`, which is destructive.
77
- */
112
+ * The restore strategy. Defaults to `purgeAllFiles`, which is destructive.
113
+ */
78
114
  mode?: RestoreMode;
79
115
  }
80
116
  /**
81
- * Information about a single backup, as returned by `backups.list()`.
82
- */
117
+ * Information about a single backup, as returned by `backups.list()`.
118
+ */
83
119
  interface BackupInfo {
84
120
  /** The backup id (monotonically increasing integer). */
85
121
  backupId: number;
@@ -93,45 +129,64 @@ interface BackupInfo {
93
129
  appMetadata: string;
94
130
  }
95
131
  /**
96
- * Backup management operations that act on a backup directory and do not
97
- * require an open database. To create a backup, use the `db.backup()` instance
98
- * method instead (it needs a live database for a consistent snapshot).
99
- *
100
- * @example
101
- * ```typescript
102
- * import { backups } from '@harperfast/rocksdb-js';
103
- *
104
- * const id = await db.backup('/path/to/backups');
105
- * db.close();
106
- * await backups.restore('/path/to/backups', '/path/to/restored-db');
107
- * ```
108
- */
132
+ * Backup management operations that act on a backup directory and do not
133
+ * require an open database. To create a backup, use the `db.backup()` instance
134
+ * method instead (it needs a live database for a consistent snapshot).
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * import { backups } from '@harperfast/rocksdb-js';
139
+ *
140
+ * const id = await db.backup('/path/to/backups');
141
+ * db.close();
142
+ * await backups.restore('/path/to/backups', '/path/to/restored-db');
143
+ * ```
144
+ */
109
145
  declare const backups: {
110
146
  /**
111
- * Restores a database from a backup directory into a (closed) database
112
- * directory. The default mode purges the destination directory, so it must
113
- * not point at a live database.
114
- */
147
+ * Restores a database from a backup directory into a (closed) database
148
+ * directory. The default mode purges the destination directory, so it must
149
+ * not point at a live database.
150
+ *
151
+ * Holds the backup directory lock in shared mode for the duration: multiple
152
+ * restores can read concurrently, but a writer (`db.backup()`, `delete`,
153
+ * `purge`) rejects while a restore is in flight rather than deleting files
154
+ * out from under it — and a restore rejects while a writer holds the lock.
155
+ *
156
+ * The shared lock needs no write access to `backupDir`, so restoring from a
157
+ * read-only backup directory (immutable/WORM store, read-only-mounted volume)
158
+ * works: the lock is taken on an existing `.backup.lock` read-only, degrading
159
+ * to a no-op only when the media is read-only for every process (`EROFS`). A
160
+ * mere permission denial hard-fails instead — it doesn't prove a privileged
161
+ * writer isn't running.
162
+ */
115
163
  restore(backupDir: string, dbDir: string, options?: RestoreOptions): Promise<void>;
116
164
  /**
117
- * Lists the non-corrupt backups in a backup directory, ordered by id.
118
- */
165
+ * Lists the non-corrupt backups in a backup directory, ordered by id.
166
+ */
119
167
  list(backupDir: string): Promise<BackupInfo[]>;
120
168
  /**
121
- * Deletes a specific backup. Shared files are reference-counted and only
122
- * removed once no remaining backup references them.
123
- */
169
+ * Deletes a specific backup. Shared files are reference-counted and only
170
+ * removed once no remaining backup references them.
171
+ */
124
172
  delete(backupDir: string, backupId: number): Promise<void>;
125
173
  /**
126
- * Deletes all but the newest `keepCount` backups.
127
- */
174
+ * Deletes all but the newest `keepCount` backups.
175
+ */
128
176
  purge(backupDir: string, keepCount: number): Promise<void>;
129
177
  /**
130
- * Verifies a backup's file sizes, and optionally their checksums (which
131
- * requires reading all backed-up data).
132
- */
178
+ * Verifies a backup's file sizes, and optionally their checksums (which
179
+ * requires reading all backed-up data).
180
+ *
181
+ * When the backup was created with `transactionLogs: true`, the backup's
182
+ * transaction log snapshot (`<backupDir>/transaction_logs/<backupId>/`) is
183
+ * also validated — every log file's header and entry framing must be intact
184
+ * (snapshots are copied on committed entry boundaries, so even a torn tail
185
+ * is a verification failure). Set `verifyTransactionLogs: false` to skip.
186
+ */
133
187
  verify(backupDir: string, backupId: number, options?: {
134
188
  verifyWithChecksum?: boolean;
189
+ verifyTransactionLogs?: boolean;
135
190
  }): Promise<void>;
136
191
  };
137
192
  //#endregion
@@ -165,6 +220,831 @@ type KeyEncoding = "binary" | "ordered-binary" | "uint32";
165
220
  type ReadKeyFunction<T> = (source: BufferWithDataView, start: number, end?: number) => T;
166
221
  type WriteKeyFunction = (key: Key, target: BufferWithDataView, start: number) => number;
167
222
  //#endregion
223
+ //#region src/dbi-iterator.d.ts
224
+ interface DBIteratorValue<T> {
225
+ key: Key;
226
+ value: T;
227
+ }
228
+ /**
229
+ * Wraps the `NativeIterator` C++ binding, decoding keys and values from the
230
+ * shared key/value buffers (fast path) or from per-iteration buffers (slow
231
+ * fallback path used for oversized data or stable-buffer decoders).
232
+ *
233
+ * The native `next()` returns a primitive signal (and writes lengths to the
234
+ * shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
235
+ * so this class is responsible for building the `IteratorResult`.
236
+ */
237
+ declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
238
+ #private;
239
+ iterator: InstanceType<typeof NativeIteratorCls>;
240
+ store: Store;
241
+ constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean, limit?: number);
242
+ [Symbol.iterator](): Iterator<DBIteratorValue<T>>;
243
+ next(): IteratorResult<DBIteratorValue<T>>;
244
+ return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
245
+ throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
246
+ }
247
+ //#endregion
248
+ //#region src/store.d.ts
249
+ type StoreContext = NativeDatabase | NativeTransaction;
250
+ type StoreGetOptions = GetOptions & DBITransactional;
251
+ type StoreIteratorOptions = IteratorOptions & DBITransactional;
252
+ type StorePutOptions = PutOptions & DBITransactional;
253
+ type StoreRangeOptions = RangeOptions & DBITransactional;
254
+ type StoreRemoveOptions = DBITransactional | unknown;
255
+ type CompactOptions = {
256
+ start?: Key;
257
+ end?: Key;
258
+ };
259
+ /**
260
+ * Options for the `Store` class.
261
+ */
262
+ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transactionLogRetentionMs"> {
263
+ decoder?: Encoder | null;
264
+ encoder?: Encoder | null;
265
+ encoding?: Encoding;
266
+ freezeData?: boolean;
267
+ keyEncoder?: {
268
+ readKey?: ReadKeyFunction<Key>;
269
+ writeKey?: WriteKeyFunction;
270
+ };
271
+ keyEncoding?: KeyEncoding;
272
+ maxKeySize?: number;
273
+ pessimistic?: boolean;
274
+ /**
275
+ * If `true`, the encoder will use a random access structure.
276
+ */
277
+ randomAccessStructure?: boolean;
278
+ /**
279
+ * When `true`, the database is opened in read-only mode. Write operations
280
+ * will throw an error with code `ERR_DATABASE_READONLY`.
281
+ */
282
+ readOnly?: boolean;
283
+ sharedStructuresKey?: symbol;
284
+ /**
285
+ * A string containing the amount of time or the number of milliseconds to
286
+ * retain transaction logs before purging.
287
+ *
288
+ * @default '3d' (3 days)
289
+ */
290
+ transactionLogRetention?: number | string;
291
+ }
292
+ /**
293
+ * Options for the `getUserSharedBuffer()` method.
294
+ */
295
+ type UserSharedBufferOptions = {
296
+ callback?: UserSharedBufferCallback;
297
+ };
298
+ /**
299
+ * The return type of `getUserSharedBuffer()`.
300
+ */
301
+ type ArrayBufferWithNotify = ArrayBuffer & {
302
+ cancel: () => void;
303
+ notify: () => void;
304
+ };
305
+ /**
306
+ * A store wraps the `NativeDatabase` binding and database settings so that a
307
+ * single database instance can be shared between the main `RocksDatabase`
308
+ * instance and the `Transaction` instance.
309
+ *
310
+ * This store should not be shared between `RocksDatabase` instances.
311
+ */
312
+ declare class Store {
313
+ /**
314
+ * The database instance.
315
+ */
316
+ db: NativeDatabase;
317
+ /**
318
+ * The decoder instance. This is commonly the same as the `encoder`
319
+ * instance.
320
+ */
321
+ decoder: Encoder | null;
322
+ /**
323
+ * Whether the decoder copies the buffer when encoding values.
324
+ */
325
+ decoderCopies: boolean;
326
+ /**
327
+ * Whether to disable the write ahead log.
328
+ */
329
+ disableWAL: boolean;
330
+ /**
331
+ * Whether to enable RocksDB statistics.
332
+ */
333
+ enableStats: boolean;
334
+ /**
335
+ * Reusable buffer for encoding values using `writeKey()` when the custom
336
+ * encoder does not provide a `encode()` method.
337
+ */
338
+ encodeBuffer: BufferWithDataView;
339
+ /**
340
+ * The encoder instance.
341
+ */
342
+ encoder: Encoder | null;
343
+ /**
344
+ * The encoding used to encode values. Defaults to `'msgpack'` in
345
+ * `RocksDatabase.open()`.
346
+ */
347
+ encoding: Encoding | null;
348
+ /**
349
+ * Encoder specific option used to signal that the data should be frozen.
350
+ */
351
+ freezeData: boolean;
352
+ /**
353
+ * Reusable buffer for encoding keys.
354
+ */
355
+ keyBuffer: BufferWithDataView;
356
+ /**
357
+ * The key encoding to use for keys. Defaults to `'ordered-binary'`.
358
+ */
359
+ keyEncoding: KeyEncoding;
360
+ /**
361
+ * The maximum key size.
362
+ */
363
+ maxKeySize: number;
364
+ /**
365
+ * The maximum number of table files RocksDB keeps open. `0` (the default)
366
+ * derives a budget from the effective per-process open-file limit (an
367
+ * eighth of the limit — several databases can share one process — clamped
368
+ * to `[1024, 262144]`); `-1` holds every table file open (the RocksDB
369
+ * default, which can exhaust the process file-descriptor limit when
370
+ * compaction falls behind under sustained ingest); a positive `int32` is
371
+ * an explicit cap.
372
+ */
373
+ maxOpenFiles?: number;
374
+ /**
375
+ * The maximum number of memtables that can be queued per column family
376
+ * before writes stall. Higher values absorb write bursts while flushes catch
377
+ * up, at the cost of memory.
378
+ */
379
+ maxWriteBufferNumber?: number;
380
+ /**
381
+ * The bytes of recent memtable history to retain in memory for transaction
382
+ * conflict checking. `-1` derives the value from
383
+ * `maxWriteBufferNumber * writeBufferSize`.
384
+ */
385
+ maxWriteBufferSizeToMaintain?: number;
386
+ /**
387
+ * The total memtable budget in bytes across all column families. When the
388
+ * sum of memtables reaches this size, RocksDB flushes the largest one. `0`
389
+ * disables the global trigger so per-CF `writeBufferSize` drives flushing.
390
+ */
391
+ dbWriteBufferSize?: number;
392
+ /**
393
+ * The name of the store (e.g. the column family). Defaults to `'default'`.
394
+ */
395
+ name: string;
396
+ /**
397
+ * Whether to disable the block cache.
398
+ */
399
+ noBlockCache?: boolean;
400
+ /**
401
+ * The number of threads to use for parallel operations. This is a RocksDB
402
+ * option. When undefined, the native layer picks
403
+ * `max(1, hardware_concurrency() / 2)`.
404
+ */
405
+ parallelismThreads?: number;
406
+ /**
407
+ * The path to the database.
408
+ */
409
+ path: string;
410
+ /**
411
+ * Whether to use pessimistic locking for transactions. When `true`,
412
+ * transactions will fail as soon as a conflict is detected. When `false`,
413
+ * transactions will only fail when `commit()` is called.
414
+ */
415
+ pessimistic: boolean;
416
+ /**
417
+ * Whether the database is open in readonly mode. When `true`, write
418
+ * operations will throw an error with code `ERR_DATABASE_READONLY`.
419
+ */
420
+ readOnly: boolean;
421
+ /**
422
+ * Encoder specific flag used to signal that the encoder should use a random
423
+ * access structure.
424
+ */
425
+ randomAccessStructure: boolean;
426
+ /**
427
+ * The function used to encode keys.
428
+ */
429
+ readKey: ReadKeyFunction<Key>;
430
+ /**
431
+ * The key used to store shared structures.
432
+ */
433
+ sharedStructuresKey?: symbol;
434
+ /**
435
+ * The level of statistics to capture.
436
+ */
437
+ statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
438
+ /**
439
+ * The threshold for the transaction log file's last modified time to be
440
+ * older than the retention period before it is rotated to the next sequence
441
+ * number. A threshold of 0 means ignore age check.
442
+ */
443
+ transactionLogMaxAgeThreshold?: number;
444
+ /**
445
+ * The maximum size of a transaction log before it is rotated to the next
446
+ * sequence number.
447
+ */
448
+ transactionLogMaxSize?: number;
449
+ /**
450
+ * A string containing the amount of time or the number of milliseconds to
451
+ * retain transaction logs before purging.
452
+ *
453
+ * @default '3d' (3 days)
454
+ */
455
+ transactionLogRetention?: number | string;
456
+ /**
457
+ * The path to the transaction logs directory.
458
+ */
459
+ transactionLogsPath?: string;
460
+ /**
461
+ * Whether this store's column family participates in the VerificationTable.
462
+ */
463
+ verificationTable?: boolean;
464
+ /**
465
+ * The per-column-family memtable size in bytes at which the memtable is
466
+ * sealed and flushed.
467
+ */
468
+ writeBufferSize?: number;
469
+ /**
470
+ * The function used to encode keys using the shared `keyBuffer`.
471
+ */
472
+ writeKey: WriteKeyFunction;
473
+ /**
474
+ * Initializes the store with a new `NativeDatabase` instance.
475
+ *
476
+ * @param path - The path to the database.
477
+ * @param options - The options for the store.
478
+ */
479
+ constructor(path: string, options?: StoreOptions);
480
+ /**
481
+ * Closes the database.
482
+ */
483
+ close(): void;
484
+ /**
485
+ * Compacts the entire key range of the database asynchronously.
486
+ * This triggers manual compaction which removes tombstones and reclaims space.
487
+ *
488
+ * @example
489
+ * ```typescript
490
+ * const db = RocksDatabase.open('/path/to/database');
491
+ * await db.compact();
492
+ * ```
493
+ */
494
+ compact(options?: CompactOptions): Promise<void>;
495
+ /**
496
+ * Creates a backup of the entire database (all column families) into the
497
+ * given directory and resolves with the new backup id. Parent directories
498
+ * are created as needed. See `backups` for restore and management.
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * const id = await db.backup('/path/to/backups');
503
+ * ```
504
+ */
505
+ backup(backupDir: string, options?: BackupOptions): Promise<number>;
506
+ backup(stream: WritableStream<Uint8Array>, options?: BackupStreamOptions): Promise<void>;
507
+ /**
508
+ * Compacts the entire key range of the database synchronously.
509
+ * This triggers manual compaction which removes tombstones and reclaims space.
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const db = RocksDatabase.open('/path/to/database');
514
+ * db.compactSync();
515
+ * ```
516
+ */
517
+ compactSync(options?: CompactOptions): void;
518
+ /**
519
+ * Decodes a key from the database.
520
+ *
521
+ * @param key - The key to decode.
522
+ * @returns The decoded key.
523
+ */
524
+ decodeKey(key: Buffer): Key;
525
+ /**
526
+ * Decodes a value from the database.
527
+ *
528
+ * @param value - The value to decode.
529
+ * @returns The decoded value.
530
+ */
531
+ decodeValue(value: BufferWithDataView): any;
532
+ /**
533
+ * Encodes a key for the database.
534
+ *
535
+ * @param key - The key to encode.
536
+ * @returns The encoded key.
537
+ */
538
+ encodeKey(key: Key): BufferWithDataView;
539
+ /**
540
+ * Encodes a value for the database.
541
+ *
542
+ * @param value - The value to encode.
543
+ * @returns The encoded value.
544
+ */
545
+ encodeValue(value: any): BufferWithDataView | Uint8Array;
546
+ get(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
547
+ getCount(context: StoreContext, options?: StoreRangeOptions): number;
548
+ getKeys(context: StoreContext, options?: StoreIteratorOptions): any | undefined;
549
+ getKeysCount(context: StoreContext, options?: StoreRangeOptions): number;
550
+ getRange(context: StoreContext, options?: StoreIteratorOptions): ExtendedIterable<DBIteratorValue<any>>;
551
+ getSync(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
552
+ /**
553
+ * Checks if the data method options object contains a transaction ID and
554
+ * returns it.
555
+ */
556
+ getTxnId(options?: DBITransactional | unknown): number | undefined;
557
+ /**
558
+ * Gets or creates a buffer that can be shared across worker threads.
559
+ *
560
+ * @param key - The key to get or create the buffer for.
561
+ * @param defaultBuffer - The default buffer to copy and use if the buffer
562
+ * does not exist.
563
+ * @param [options] - The options for the buffer.
564
+ * @param [options.callback] - A optional callback is called when `notify()`
565
+ * on the returned buffer is called.
566
+ * @returns An `ArrayBuffer` that is internally backed by a rocksdb-js
567
+ * managed buffer. The buffer also has `notify()` and `cancel()` methods
568
+ * that can be used to notify the specified `options.callback`.
569
+ */
570
+ getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
571
+ /**
572
+ * Checks if a lock exists.
573
+ * @param key The lock key.
574
+ * @returns `true` if the lock exists, `false` otherwise
575
+ */
576
+ hasLock(key: Key): boolean;
577
+ /**
578
+ * Checks if the database is open.
579
+ *
580
+ * @returns `true` if the database is open, `false` otherwise.
581
+ */
582
+ isOpen(): boolean;
583
+ /**
584
+ * Lists all transaction log names.
585
+ *
586
+ * @returns an array of transaction log names.
587
+ */
588
+ listLogs(): string[];
589
+ /**
590
+ * Opens the database. This must be called before any database operations
591
+ * are performed.
592
+ */
593
+ open(): boolean;
594
+ putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
595
+ removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
596
+ /**
597
+ * Attempts to acquire a lock for a given key. If the lock is available,
598
+ * the function returns `true` and the optional callback is never called.
599
+ * If the lock is not available, the function returns `false` and the
600
+ * callback is queued until the lock is released.
601
+ *
602
+ * @param key - The key to lock.
603
+ * @param onUnlocked - A callback to call when the lock is released.
604
+ * @returns `true` if the lock was acquired, `false` otherwise.
605
+ */
606
+ tryLock(key: Key, onUnlocked?: () => void): boolean;
607
+ /**
608
+ * Releases the lock on the given key and calls any queued `onUnlocked`
609
+ * callback handlers.
610
+ *
611
+ * @param key - The key to unlock.
612
+ */
613
+ unlock(key: Key): void;
614
+ /**
615
+ * Gets or creates a transaction log instance.
616
+ *
617
+ * @param context - The context to use for the transaction log.
618
+ * @param name - The name of the transaction log.
619
+ * @returns The transaction log.
620
+ */
621
+ useLog(context: StoreContext, name: string | number): TransactionLog;
622
+ /**
623
+ * Checks the process-global verification table for a fresh version match
624
+ * on `key`. Returns `true` when the table currently records `version` for
625
+ * this database+column-family. Provides a fast cache-freshness check
626
+ * before falling back to a full read.
627
+ */
628
+ verifyVersion(key: Key, version: number): boolean;
629
+ /**
630
+ * Seeds the verification-table slot for `key` with `version`. Has no
631
+ * effect if the slot is currently lock-tagged or the table is disabled.
632
+ * Useful after a full read where the caller already knows the version.
633
+ */
634
+ populateVersion(key: Key, version: number): void;
635
+ /**
636
+ * Acquires a lock on the given key and calls the callback.
637
+ *
638
+ * @param key - The key to lock.
639
+ * @param callback - The callback to call when the lock is acquired.
640
+ * @returns A promise that resolves when the lock is acquired.
641
+ */
642
+ withLock(key: Key, callback: () => void | Promise<void>): Promise<void>;
643
+ }
644
+ interface GetOptions {
645
+ /**
646
+ * When set, the native layer checks the verification table before reading.
647
+ * If the slot holds this version, returns `FRESH_VERSION_FLAG` immediately
648
+ * (the cached value is still valid). After a DB read, also seeds the slot
649
+ * with the version extracted from the value.
650
+ */
651
+ expectedVersion?: number;
652
+ /**
653
+ * When `true`, after a DB read the native layer automatically seeds the
654
+ * verification-table slot with the version extracted from the value.
655
+ * Eliminates the need for a separate `populateVersion` call on cold reads.
656
+ *
657
+ * @default false
658
+ */
659
+ populateVersion?: boolean;
660
+ /**
661
+ * Whether to skip decoding the value.
662
+ *
663
+ * @default false
664
+ */
665
+ skipDecode?: boolean;
666
+ }
667
+ interface PutOptions {
668
+ append?: boolean;
669
+ instructedWrite?: boolean;
670
+ noDupData?: boolean;
671
+ noOverwrite?: boolean;
672
+ }
673
+ //#endregion
674
+ //#region src/transaction.d.ts
675
+ /**
676
+ * Sentinel value returned by `commit()` when `coordinatedRetry: true` and the
677
+ * transaction encountered an IsBusy conflict. The native layer parks on VT
678
+ * slots and resolves only after the conflicting transaction releases its write
679
+ * intent, so callers should retry immediately without any backoff delay.
680
+ */
681
+ declare const RETRY_NOW: number;
682
+ /**
683
+ * Provides transaction level operations to a transaction callback.
684
+ */
685
+ declare class Transaction extends DBI {
686
+ #private;
687
+ /**
688
+ * Create a new transaction.
689
+ *
690
+ * @param store - The base store interface for this transaction.
691
+ * @param options - The options for the transaction.
692
+ */
693
+ constructor(store: Store, options?: NativeTransactionOptions);
694
+ /**
695
+ * Abort the transaction.
696
+ */
697
+ abort(): void;
698
+ /**
699
+ * Commit the transaction.
700
+ *
701
+ * Returns `RETRY_NOW` when `coordinatedRetry: true` and an IsBusy conflict
702
+ * was detected. The caller should retry the transaction body immediately.
703
+ */
704
+ commit(): Promise<typeof RETRY_NOW | void>;
705
+ /**
706
+ * Commit the transaction synchronously.
707
+ */
708
+ commitSync(): void;
709
+ /**
710
+ * Returns the transaction start timestamp in seconds. Defaults to the time at which
711
+ * the transaction was created.
712
+ *
713
+ * @returns The transaction start timestamp in seconds.
714
+ */
715
+ getTimestamp(): number;
716
+ /**
717
+ * Get the transaction id.
718
+ */
719
+ get id(): number;
720
+ /**
721
+ * Set the transaction start timestamp in seconds.
722
+ *
723
+ * @param timestamp - The timestamp to set in seconds.
724
+ */
725
+ setTimestamp(timestamp?: number): void;
726
+ }
727
+ //#endregion
728
+ //#region src/util.d.ts
729
+ type MaybePromise<T> = T | Promise<T>;
730
+ //#endregion
731
+ //#region src/dbi.d.ts
732
+ interface RocksDBOptions {
733
+ /**
734
+ * When `true`, RocksDB will do some enhancements for prefetching the data.
735
+ * Defaults to `true`. Note that RocksDB defaults this to `false`.
736
+ */
737
+ adaptiveReadahead?: boolean;
738
+ /**
739
+ * When `true`, RocksDB will prefetch some data async and apply it if reads
740
+ * are sequential and its internal automatic prefetching. Defaults to
741
+ * `true`. Note that RocksDB defaults this to `false`.
742
+ */
743
+ asyncIO?: boolean;
744
+ /**
745
+ * When `true`, RocksDB will auto-tune the readahead size during scans
746
+ * internally based on the block cache data when block caching is enabled,
747
+ * an end key (e.g. upper bound) is set, and prefix is the same as the start
748
+ * key. Defaults to `true`.
749
+ */
750
+ autoReadaheadSize?: boolean;
751
+ /**
752
+ * When `true`, after the iterator is closed, a background job is scheduled
753
+ * to flush the job queue and delete obsolete files. Defaults to `true`.
754
+ * Note that RocksDB defaults this to `false`.
755
+ */
756
+ backgroundPurgeOnIteratorCleanup?: boolean;
757
+ /**
758
+ * When `true`, the iterator will fill the block cache. Filling the block
759
+ * cache is not desirable for bulk scans and could impact eviction order.
760
+ * Defaults to `false`. Note that RocksDB defaults this to `true`.
761
+ */
762
+ fillCache?: boolean;
763
+ /**
764
+ * The RocksDB readahead size. RocksDB does auto-readahead for iterators
765
+ * when there is more than two reads for a table file. The readahead
766
+ * starts at 8KB and doubles on every additional read up to 256KB. This
767
+ * option can help if most of the range scans are large and if a larger
768
+ * readahead than that enabled by auto-readahead is needed. Using a large
769
+ * readahead size (> 2MB) can typically improve the performance of forward
770
+ * iteration on spinning disks. Defaults to `0`.
771
+ */
772
+ readaheadSize?: number;
773
+ /**
774
+ * When `true`, creates a "tailing iterator" which is a special iterator
775
+ * that has a view of the complete database including newly added data and
776
+ * is optimized for sequential reads. This will return records that were
777
+ * inserted into the database after the creation of the iterator. Defaults
778
+ * to `false`.
779
+ */
780
+ tailing?: boolean;
781
+ }
782
+ interface RangeOptions extends RocksDBOptions {
783
+ /**
784
+ * The range end key, otherwise known as the "upper bound". Defaults to
785
+ * the last key in the database.
786
+ */
787
+ end?: Key | Uint8Array;
788
+ /**
789
+ * When `true`, the iterator will exclude the first key if it matches the start key.
790
+ * Defaults to `false`.
791
+ */
792
+ exclusiveStart?: boolean;
793
+ /**
794
+ * When `true`, the iterator will include the last key if it matches the end
795
+ * key. Defaults to `false`.
796
+ */
797
+ inclusiveEnd?: boolean;
798
+ /**
799
+ * The range start key, otherwise known as the "lower bound". Defaults to
800
+ * the first key in the database.
801
+ */
802
+ start?: Key | Uint8Array;
803
+ }
804
+ interface IteratorOptions extends RangeOptions {
805
+ /**
806
+ * The maximum number of entries to yield. When set, iteration stops after
807
+ * `limit` entries regardless of the range bounds. Values <= 0 yield nothing.
808
+ * Unset means no limit.
809
+ */
810
+ limit?: number;
811
+ /**
812
+ * A specific key to match which may result in zero, one, or many values.
813
+ */
814
+ key?: Key;
815
+ /**
816
+ * When `true`, only returns the number of values for the given query.
817
+ */
818
+ onlyCount?: boolean;
819
+ /**
820
+ * When `true`, the iterator will iterate in reverse order. Defaults to
821
+ * `false`.
822
+ */
823
+ reverse?: boolean;
824
+ /**
825
+ * When `true`, decodes and returns the value. When `false`, the value is
826
+ * omitted. Defaults to `true`.
827
+ */
828
+ values?: boolean;
829
+ /**
830
+ * When `true`, the iterator will only return the values.
831
+ */
832
+ valuesOnly?: boolean;
833
+ }
834
+ interface DBITransactional {
835
+ transaction?: Transaction;
836
+ }
837
+ /**
838
+ * The base class for all database operations. This base class is shared by
839
+ * `RocksDatabase` and `Transaction`.
840
+ *
841
+ * This class is not meant to be used directly.
842
+ */
843
+ declare class DBI<T extends DBITransactional | unknown = unknown> {
844
+ /**
845
+ * The RocksDB context for `get()`, `put()`, and `remove()`.
846
+ */
847
+ _context: StoreContext;
848
+ /**
849
+ * The database store instance. The store instance is tied to the database
850
+ * instance and shared with transaction instances.
851
+ */
852
+ store: Store;
853
+ /**
854
+ * Initializes the DBI context.
855
+ *
856
+ * @param store - The store instance.
857
+ * @param transaction - The transaction instance.
858
+ */
859
+ constructor(store: Store, transaction?: NativeTransaction);
860
+ /**
861
+ * Adds a listener for the given key.
862
+ *
863
+ * @param event - The event name to add the listener for.
864
+ * @param callback - The callback to add.
865
+ */
866
+ addListener(event: string, callback: (...args: any[]) => void): this;
867
+ /**
868
+ * Retrieves the value for the given key, then returns the decoded value.
869
+ */
870
+ get(key: Key, options?: GetOptions & T): MaybePromise<any | undefined>;
871
+ /**
872
+ * Retrieves the binary data for the given key. This is just like `get()`,
873
+ * but bypasses the decoder.
874
+ *
875
+ * Note: Used by HDBreplication.
876
+ */
877
+ getBinary(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
878
+ /**
879
+ * Synchronously retrieves the binary data for the given key.
880
+ */
881
+ getBinarySync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
882
+ /**
883
+ * Retrieves the binary data for the given key using a preallocated,
884
+ * reusable buffer. Data in the buffer is only valid until the next get
885
+ * operation (including cursor operations).
886
+ *
887
+ * Note: The reusable buffer slightly differs from a typical buffer:
888
+ * - `.length` is set to the size of the value
889
+ * - `.byteLength` is set to the size of the full allocated memory area for
890
+ * the buffer (usually much larger).
891
+ */
892
+ getBinaryFast(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
893
+ /**
894
+ * Synchronously retrieves the binary data for the given key using a
895
+ * preallocated, reusable buffer. Data in the buffer is only valid until the
896
+ * next get operation (including cursor operations).
897
+ */
898
+ getBinaryFastSync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
899
+ /**
900
+ * Retrieves all keys within a range.
901
+ */
902
+ getKeys(options?: IteratorOptions & T): any | undefined;
903
+ /**
904
+ * Retrieves the number of keys within a range.
905
+ *
906
+ * @param options - The range options.
907
+ * @returns The number of keys within the range.
908
+ *
909
+ * @example
910
+ * ```typescript
911
+ * const total = db.getKeysCount();
912
+ * const range = db.getKeysCount({ start: 'a', end: 'z' });
913
+ * ```
914
+ */
915
+ getKeysCount(options?: RangeOptions & T): number;
916
+ /**
917
+ * Retrieves a range of keys and their values.
918
+ *
919
+ * @param options - The iterator options.
920
+ * @returns A range iterable.
921
+ *
922
+ * @example
923
+ * ```typescript
924
+ * for (const { key, value } of db.getRange()) {
925
+ * console.log({ key, value });
926
+ * }
927
+ *
928
+ * for (const { key, value } of db.getRange({ start: 'a', end: 'z' })) {
929
+ * console.log({ key, value });
930
+ * }
931
+ * ```
932
+ */
933
+ getRange(options?: IteratorOptions & T): any | undefined;
934
+ /**
935
+ * Synchronously retrieves the value for the given key, then returns the
936
+ * decoded value.
937
+ */
938
+ getSync(key: Key, options?: GetOptions & T): any | undefined;
939
+ /**
940
+ * Gets the number of listeners for the given key.
941
+ *
942
+ * @param event - The event name to get the listeners for.
943
+ * @returns The number of listeners for the given key.
944
+ */
945
+ listeners(event: string | BufferWithDataView): number;
946
+ /**
947
+ * Notifies an event for the given key.
948
+ *
949
+ * @param event - The event name to emit the event for.
950
+ * @param args - The arguments to emit.
951
+ * @returns `true` if there were listeners, `false` otherwise.
952
+ */
953
+ notify(event: string, ...args: any[]): boolean;
954
+ /**
955
+ * Alias for `removeListener()`.
956
+ *
957
+ * @param event - The event name to remove the listener for.
958
+ * @param callback - The callback to remove.
959
+ */
960
+ off(event: string, callback: (...args: any[]) => void): this;
961
+ /**
962
+ * Alias for `addListener()`.
963
+ *
964
+ * @param event - The event name to add the listener for.
965
+ * @param callback - The callback to add.
966
+ */
967
+ on(event: string, callback: (...args: any[]) => void): this;
968
+ /**
969
+ * Adds a one-time listener, then automatically removes it.
970
+ *
971
+ * @param event - The event name to add the listener for.
972
+ * @param callback - The callback to add.
973
+ */
974
+ once(event: string, callback: (...args: any[]) => void): this;
975
+ /**
976
+ * Stores a value for the given key.
977
+ *
978
+ * @param key - The key to store the value for.
979
+ * @param value - The value to store.
980
+ * @param options - The put options.
981
+ * @returns The key and value.
982
+ *
983
+ * @example
984
+ * ```typescript
985
+ * await db.put('a', 'b');
986
+ * ```
987
+ */
988
+ put(key: Key, value: any, options?: PutOptions & T): Promise<void>;
989
+ /**
990
+ * Synchronously stores a value for the given key.
991
+ *
992
+ * @param key - The key to store the value for.
993
+ * @param value - The value to store.
994
+ * @param options - The put options.
995
+ * @returns The key and value.
996
+ *
997
+ * @example
998
+ * ```typescript
999
+ * db.putSync('a', 'b');
1000
+ * ```
1001
+ */
1002
+ putSync(key: Key, value: any, options?: PutOptions & T): void;
1003
+ /**
1004
+ * Removes a value for the given key. If the key does not exist, it will
1005
+ * not error.
1006
+ *
1007
+ * @param key - The key to remove the value for.
1008
+ * @param options - The remove options.
1009
+ * @returns The key and value.
1010
+ *
1011
+ * @example
1012
+ * ```typescript
1013
+ * await db.remove('a');
1014
+ * ```
1015
+ */
1016
+ remove(key: Key, options?: T): Promise<void>;
1017
+ /**
1018
+ * Removes a value for the given key. If the key does not exist, it will
1019
+ * not error.
1020
+ *
1021
+ * @param key - The key to remove the value for.
1022
+ * @param options - The remove options.
1023
+ * @returns The key and value.
1024
+ *
1025
+ * @example
1026
+ * ```typescript
1027
+ * db.removeSync('a');
1028
+ * ```
1029
+ */
1030
+ removeSync(key: Key, options?: T): void;
1031
+ /**
1032
+ * Removes an event listener. You must specify the exact same callback that was
1033
+ * used in `addListener()`.
1034
+ *
1035
+ * @param event - The event name to remove the listener for.
1036
+ * @param callback - The callback to remove.
1037
+ */
1038
+ removeListener(event: string, callback: (value?: any) => void): boolean;
1039
+ /**
1040
+ * Get or create a transaction log instance.
1041
+ *
1042
+ * @param name - The name of the transaction log.
1043
+ * @returns The transaction log.
1044
+ */
1045
+ useLog(name: string | number): TransactionLog;
1046
+ }
1047
+ //#endregion
168
1048
  //#region src/stats.d.ts
169
1049
  /** Database-level RocksDB statistics types for `db.getStats()` / `db.getStat()`. */
170
1050
  type StatsHistogramData = {
@@ -215,6 +1095,8 @@ type StatsBasics = {
215
1095
  "txnlog.transactionsWritten": number;
216
1096
  "txnlog.bytesWritten": number;
217
1097
  "txnlog.replayGapBytes": number;
1098
+ "commitPipeline.logQueueDepth": number;
1099
+ "commitPipeline.commitQueueDepth": number;
218
1100
  };
219
1101
  type StatsCuratedExtras = {
220
1102
  "rocksdb.block.cache.hit": number;
@@ -533,464 +1415,132 @@ interface GetStatsMethod {
533
1415
  getStats(all: true): StatsAll;
534
1416
  }
535
1417
  //#endregion
536
- //#region src/dbi-iterator.d.ts
537
- interface DBIteratorValue<T> {
538
- key: Key;
539
- value: T;
540
- }
541
- /**
542
- * Wraps the `NativeIterator` C++ binding, decoding keys and values from the
543
- * shared key/value buffers (fast path) or from per-iteration buffers (slow
544
- * fallback path used for oversized data or stable-buffer decoders).
545
- *
546
- * The native `next()` returns a primitive signal (and writes lengths to the
547
- * shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
548
- * so this class is responsible for building the `IteratorResult`.
549
- */
550
- declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
551
- #private;
552
- iterator: InstanceType<typeof NativeIteratorCls>;
553
- store: Store;
554
- constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean, limit?: number);
555
- [Symbol.iterator](): Iterator<DBIteratorValue<T>>;
556
- next(): IteratorResult<DBIteratorValue<T>>;
557
- return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
558
- throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
559
- }
560
- //#endregion
561
- //#region src/store.d.ts
562
- type StoreContext = NativeDatabase | NativeTransaction;
563
- type StoreGetOptions = GetOptions & DBITransactional;
564
- type StoreIteratorOptions = IteratorOptions & DBITransactional;
565
- type StorePutOptions = PutOptions & DBITransactional;
566
- type StoreRangeOptions = RangeOptions & DBITransactional;
567
- type StoreRemoveOptions = DBITransactional | unknown;
568
- type CompactOptions = {
569
- start?: Key;
570
- end?: Key;
571
- };
572
- /**
573
- * Options for the `Store` class.
574
- */
575
- interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transactionLogRetentionMs"> {
576
- decoder?: Encoder | null;
577
- encoder?: Encoder | null;
578
- encoding?: Encoding;
579
- freezeData?: boolean;
580
- keyEncoder?: {
581
- readKey?: ReadKeyFunction<Key>;
582
- writeKey?: WriteKeyFunction;
583
- };
584
- keyEncoding?: KeyEncoding;
585
- maxKeySize?: number;
586
- pessimistic?: boolean;
587
- /**
588
- * If `true`, the encoder will use a random access structure.
589
- */
590
- randomAccessStructure?: boolean;
591
- /**
592
- * When `true`, the database is opened in read-only mode. Write operations
593
- * will throw an error with code `ERR_DATABASE_READONLY`.
594
- */
595
- readOnly?: boolean;
596
- sharedStructuresKey?: symbol;
597
- /**
598
- * A string containing the amount of time or the number of milliseconds to
599
- * retain transaction logs before purging.
600
- *
601
- * @default '3d' (3 days)
602
- */
603
- transactionLogRetention?: number | string;
604
- }
605
- /**
606
- * Options for the `getUserSharedBuffer()` method.
607
- */
608
- type UserSharedBufferOptions = {
609
- callback?: UserSharedBufferCallback;
610
- };
1418
+ //#region src/validate-transaction-log.d.ts
611
1419
  /**
612
- * The return type of `getUserSharedBuffer()`.
613
- */
614
- type ArrayBufferWithNotify = ArrayBuffer & {
615
- cancel: () => void;
616
- notify: () => void;
617
- };
1420
+ * The validation result for a single transaction log file within a store, as
1421
+ * returned by {@link validateTransactionLogStore}.
1422
+ */
1423
+ interface TransactionLogFileValidation {
1424
+ /** File name relative to the store directory, e.g. `"3.txnlog"`. */
1425
+ file: string;
1426
+ /** Sequence number parsed from the file name. */
1427
+ sequence: number;
1428
+ /** On-disk file size in bytes. */
1429
+ size: number;
1430
+ /** Number of well-formed entry frames. */
1431
+ entries: number;
1432
+ /** End offset of the validly framed data (header + well-formed entries). */
1433
+ validBytes: number;
1434
+ /** `true` when `errors` is empty. */
1435
+ valid: boolean;
1436
+ /**
1437
+ * Conditions that make the file invalid: a bad/missing header, an
1438
+ * unsupported version, or a mid-file framing break. With `strict`, a torn
1439
+ * tail is also reported here.
1440
+ */
1441
+ errors: string[];
1442
+ /**
1443
+ * Conditions that do not invalidate the file: a torn tail (recoverable —
1444
+ * open-time recovery truncates it without losing committed entries) and
1445
+ * per-entry anomalies such as suspicious timestamps or undefined flag bits.
1446
+ */
1447
+ warnings: string[];
1448
+ }
618
1449
  /**
619
- * A store wraps the `NativeDatabase` binding and database settings so that a
620
- * single database instance can be shared between the main `RocksDatabase`
621
- * instance and the `Transaction` instance.
622
- *
623
- * This store should not be shared between `RocksDatabase` instances.
624
- */
625
- declare class Store {
626
- /**
627
- * The database instance.
628
- */
629
- db: NativeDatabase;
630
- /**
631
- * The decoder instance. This is commonly the same as the `encoder`
632
- * instance.
633
- */
634
- decoder: Encoder | null;
635
- /**
636
- * Whether the decoder copies the buffer when encoding values.
637
- */
638
- decoderCopies: boolean;
639
- /**
640
- * Whether to disable the write ahead log.
641
- */
642
- disableWAL: boolean;
643
- /**
644
- * Whether to enable RocksDB statistics.
645
- */
646
- enableStats: boolean;
647
- /**
648
- * Reusable buffer for encoding values using `writeKey()` when the custom
649
- * encoder does not provide a `encode()` method.
650
- */
651
- encodeBuffer: BufferWithDataView;
652
- /**
653
- * The encoder instance.
654
- */
655
- encoder: Encoder | null;
656
- /**
657
- * The encoding used to encode values. Defaults to `'msgpack'` in
658
- * `RocksDatabase.open()`.
659
- */
660
- encoding: Encoding | null;
661
- /**
662
- * Encoder specific option used to signal that the data should be frozen.
663
- */
664
- freezeData: boolean;
665
- /**
666
- * Reusable buffer for encoding keys.
667
- */
668
- keyBuffer: BufferWithDataView;
669
- /**
670
- * The key encoding to use for keys. Defaults to `'ordered-binary'`.
671
- */
672
- keyEncoding: KeyEncoding;
673
- /**
674
- * The maximum key size.
675
- */
676
- maxKeySize: number;
677
- /**
678
- * The maximum number of memtables that can be queued per column family
679
- * before writes stall. Higher values absorb write bursts while flushes catch
680
- * up, at the cost of memory.
681
- */
682
- maxWriteBufferNumber?: number;
683
- /**
684
- * The bytes of recent memtable history to retain in memory for transaction
685
- * conflict checking. `-1` derives the value from
686
- * `maxWriteBufferNumber * writeBufferSize`.
687
- */
688
- maxWriteBufferSizeToMaintain?: number;
689
- /**
690
- * The total memtable budget in bytes across all column families. When the
691
- * sum of memtables reaches this size, RocksDB flushes the largest one. `0`
692
- * disables the global trigger so per-CF `writeBufferSize` drives flushing.
693
- */
694
- dbWriteBufferSize?: number;
695
- /**
696
- * The name of the store (e.g. the column family). Defaults to `'default'`.
697
- */
698
- name: string;
699
- /**
700
- * Whether to disable the block cache.
701
- */
702
- noBlockCache?: boolean;
703
- /**
704
- * The number of threads to use for parallel operations. This is a RocksDB
705
- * option. When undefined, the native layer picks
706
- * `max(1, hardware_concurrency() / 2)`.
707
- */
708
- parallelismThreads?: number;
709
- /**
710
- * The path to the database.
711
- */
1450
+ * The result of validating a transaction log store directory, as returned by
1451
+ * {@link validateTransactionLogStore}.
1452
+ */
1453
+ interface TransactionLogStoreValidation {
1454
+ /** The validated store directory. */
712
1455
  path: string;
713
1456
  /**
714
- * Whether to use pessimistic locking for transactions. When `true`,
715
- * transactions will fail as soon as a conflict is detected. When `false`,
716
- * transactions will only fail when `commit()` is called.
717
- */
718
- pessimistic: boolean;
719
- /**
720
- * Whether the database is open in readonly mode. When `true`, write
721
- * operations will throw an error with code `ERR_DATABASE_READONLY`.
722
- */
723
- readOnly: boolean;
724
- /**
725
- * Encoder specific flag used to signal that the encoder should use a random
726
- * access structure.
727
- */
728
- randomAccessStructure: boolean;
729
- /**
730
- * The function used to encode keys.
731
- */
732
- readKey: ReadKeyFunction<Key>;
733
- /**
734
- * The key used to store shared structures.
735
- */
736
- sharedStructuresKey?: symbol;
737
- /**
738
- * The level of statistics to capture.
739
- */
740
- statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
741
- /**
742
- * The threshold for the transaction log file's last modified time to be
743
- * older than the retention period before it is rotated to the next sequence
744
- * number. A threshold of 0 means ignore age check.
745
- */
746
- transactionLogMaxAgeThreshold?: number;
747
- /**
748
- * The maximum size of a transaction log before it is rotated to the next
749
- * sequence number.
750
- */
751
- transactionLogMaxSize?: number;
752
- /**
753
- * A string containing the amount of time or the number of milliseconds to
754
- * retain transaction logs before purging.
755
- *
756
- * @default '3d' (3 days)
757
- */
758
- transactionLogRetention?: number | string;
759
- /**
760
- * The path to the transaction logs directory.
761
- */
762
- transactionLogsPath?: string;
763
- /**
764
- * Whether this store's column family participates in the VerificationTable.
765
- */
766
- verificationTable?: boolean;
767
- /**
768
- * The per-column-family memtable size in bytes at which the memtable is
769
- * sealed and flushed.
770
- */
771
- writeBufferSize?: number;
772
- /**
773
- * The function used to encode keys using the shared `keyBuffer`.
774
- */
775
- writeKey: WriteKeyFunction;
776
- /**
777
- * Initializes the store with a new `NativeDatabase` instance.
778
- *
779
- * @param path - The path to the database.
780
- * @param options - The options for the store.
781
- */
782
- constructor(path: string, options?: StoreOptions);
783
- /**
784
- * Closes the database.
785
- */
786
- close(): void;
787
- /**
788
- * Compacts the entire key range of the database asynchronously.
789
- * This triggers manual compaction which removes tombstones and reclaims space.
790
- *
791
- * @example
792
- * ```typescript
793
- * const db = RocksDatabase.open('/path/to/database');
794
- * await db.compact();
795
- * ```
796
- */
797
- compact(options?: CompactOptions): Promise<void>;
798
- /**
799
- * Creates a backup of the entire database (all column families) into the
800
- * given directory and resolves with the new backup id. Parent directories
801
- * are created as needed. See `backups` for restore and management.
802
- *
803
- * @example
804
- * ```typescript
805
- * const id = await db.backup('/path/to/backups');
806
- * ```
807
- */
808
- backup(backupDir: string, options?: BackupOptions): Promise<number>;
809
- /**
810
- * Compacts the entire key range of the database synchronously.
811
- * This triggers manual compaction which removes tombstones and reclaims space.
812
- *
813
- * @example
814
- * ```typescript
815
- * const db = RocksDatabase.open('/path/to/database');
816
- * db.compactSync();
817
- * ```
818
- */
819
- compactSync(options?: CompactOptions): void;
820
- /**
821
- * Decodes a key from the database.
822
- *
823
- * @param key - The key to decode.
824
- * @returns The decoded key.
825
- */
826
- decodeKey(key: Buffer): Key;
827
- /**
828
- * Decodes a value from the database.
829
- *
830
- * @param value - The value to decode.
831
- * @returns The decoded value.
832
- */
833
- decodeValue(value: BufferWithDataView): any;
834
- /**
835
- * Encodes a key for the database.
836
- *
837
- * @param key - The key to encode.
838
- * @returns The encoded key.
839
- */
840
- encodeKey(key: Key): BufferWithDataView;
841
- /**
842
- * Encodes a value for the database.
843
- *
844
- * @param value - The value to encode.
845
- * @returns The encoded value.
846
- */
847
- encodeValue(value: any): BufferWithDataView | Uint8Array;
848
- get(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
849
- getCount(context: StoreContext, options?: StoreRangeOptions): number;
850
- getKeys(context: StoreContext, options?: StoreIteratorOptions): any | undefined;
851
- getKeysCount(context: StoreContext, options?: StoreRangeOptions): number;
852
- getRange(context: StoreContext, options?: StoreIteratorOptions): ExtendedIterable<DBIteratorValue<any>>;
853
- getSync(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
854
- /**
855
- * Checks if the data method options object contains a transaction ID and
856
- * returns it.
857
- */
858
- getTxnId(options?: DBITransactional | unknown): number | undefined;
859
- /**
860
- * Gets or creates a buffer that can be shared across worker threads.
861
- *
862
- * @param key - The key to get or create the buffer for.
863
- * @param defaultBuffer - The default buffer to copy and use if the buffer
864
- * does not exist.
865
- * @param [options] - The options for the buffer.
866
- * @param [options.callback] - A optional callback is called when `notify()`
867
- * on the returned buffer is called.
868
- * @returns An `ArrayBuffer` that is internally backed by a rocksdb-js
869
- * managed buffer. The buffer also has `notify()` and `cancel()` methods
870
- * that can be used to notify the specified `options.callback`.
871
- */
872
- getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
873
- /**
874
- * Checks if a lock exists.
875
- * @param key The lock key.
876
- * @returns `true` if the lock exists, `false` otherwise
877
- */
878
- hasLock(key: Key): boolean;
879
- /**
880
- * Checks if the database is open.
881
- *
882
- * @returns `true` if the database is open, `false` otherwise.
883
- */
884
- isOpen(): boolean;
885
- /**
886
- * Lists all transaction log names.
887
- *
888
- * @returns an array of transaction log names.
889
- */
890
- listLogs(): string[];
891
- /**
892
- * Opens the database. This must be called before any database operations
893
- * are performed.
894
- */
895
- open(): boolean;
896
- putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
897
- removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
898
- /**
899
- * Attempts to acquire a lock for a given key. If the lock is available,
900
- * the function returns `true` and the optional callback is never called.
901
- * If the lock is not available, the function returns `false` and the
902
- * callback is queued until the lock is released.
903
- *
904
- * @param key - The key to lock.
905
- * @param onUnlocked - A callback to call when the lock is released.
906
- * @returns `true` if the lock was acquired, `false` otherwise.
907
- */
908
- tryLock(key: Key, onUnlocked?: () => void): boolean;
909
- /**
910
- * Releases the lock on the given key and calls any queued `onUnlocked`
911
- * callback handlers.
912
- *
913
- * @param key - The key to unlock.
914
- */
915
- unlock(key: Key): void;
916
- /**
917
- * Gets or creates a transaction log instance.
918
- *
919
- * @param context - The context to use for the transaction log.
920
- * @param name - The name of the transaction log.
921
- * @returns The transaction log.
922
- */
923
- useLog(context: StoreContext, name: string | number): TransactionLog;
924
- /**
925
- * Checks the process-global verification table for a fresh version match
926
- * on `key`. Returns `true` when the table currently records `version` for
927
- * this database+column-family. Provides a fast cache-freshness check
928
- * before falling back to a full read.
929
- */
930
- verifyVersion(key: Key, version: number): boolean;
931
- /**
932
- * Seeds the verification-table slot for `key` with `version`. Has no
933
- * effect if the slot is currently lock-tagged or the table is disabled.
934
- * Useful after a full read where the caller already knows the version.
935
- */
936
- populateVersion(key: Key, version: number): void;
937
- /**
938
- * Acquires a lock on the given key and calls the callback.
939
- *
940
- * @param key - The key to lock.
941
- * @param callback - The callback to call when the lock is acquired.
942
- * @returns A promise that resolves when the lock is acquired.
943
- */
944
- withLock(key: Key, callback: () => void | Promise<void>): Promise<void>;
945
- }
946
- interface GetOptions {
947
- /**
948
- * When set, the native layer checks the verification table before reading.
949
- * If the slot holds this version, returns `FRESH_VERSION_FLAG` immediately
950
- * (the cached value is still valid). After a DB read, also seeds the slot
951
- * with the version extracted from the value.
952
- */
953
- expectedVersion?: number;
954
- /**
955
- * When `true`, after a DB read the native layer automatically seeds the
956
- * verification-table slot with the version extracted from the value.
957
- * Eliminates the need for a separate `populateVersion` call on cold reads.
958
- *
959
- * @default false
960
- */
961
- populateVersion?: boolean;
962
- /**
963
- * Whether to skip decoding the value.
964
- *
965
- * @default false
966
- */
967
- skipDecode?: boolean;
1457
+ * `true` when there are no store-level errors and every log file is valid.
1458
+ */
1459
+ valid: boolean;
1460
+ /** Per-file validation results, ordered by sequence number. */
1461
+ files: TransactionLogFileValidation[];
1462
+ /**
1463
+ * Store-level errors: malformed file names, an unreadable file, or a
1464
+ * corrupt `txn.state`.
1465
+ */
1466
+ errors: string[];
1467
+ /**
1468
+ * Store-level warnings: sequence gaps, unexpected directory entries, or an
1469
+ * implausible `txn.state` flushed position.
1470
+ */
1471
+ warnings: string[];
968
1472
  }
969
- interface PutOptions {
970
- append?: boolean;
971
- instructedWrite?: boolean;
972
- noDupData?: boolean;
973
- noOverwrite?: boolean;
1473
+ /**
1474
+ * Options for {@link validateTransactionLogStore}.
1475
+ */
1476
+ interface ValidateTransactionLogStoreOptions {
1477
+ /**
1478
+ * Report conditions that indicate an incomplete snapshot — a torn tail, a
1479
+ * sequence gap, or a `txn.state` flushed position beyond the newest log
1480
+ * file or beyond its file's actual size — as errors instead of warnings. A
1481
+ * torn tail on a live store is a normal crash artifact that open-time
1482
+ * recovery truncates, but a backup snapshot captures every surviving file
1483
+ * on committed entry boundaries and must be clean end to end —
1484
+ * `backups.verify()` validates snapshots with `strict: true`. Defaults to
1485
+ * `false`.
1486
+ */
1487
+ strict?: boolean;
974
1488
  }
1489
+ /**
1490
+ * Validates a transaction log store directory: every `<sequence>.txnlog` file
1491
+ * is checked for a valid header (token, version) and intact v1 entry framing
1492
+ * (using the same scan as open-time crash recovery), file-name and sequence
1493
+ * continuity are checked, and the `txn.state` side file (when present) is
1494
+ * checked for shape and a plausible flushed position. The result reports
1495
+ * per-file entry counts, errors, and warnings; it does not throw when the
1496
+ * store is invalid — check `result.valid`.
1497
+ *
1498
+ * Runs entirely in native code on a worker thread and does not require (or
1499
+ * open) a database, so it works on the store of a closed database and on the
1500
+ * per-backup snapshots under `<backupDir>/transaction_logs/<backupId>/` alike.
1501
+ *
1502
+ * Validating a store that is being actively appended to can spuriously report
1503
+ * a torn tail for the current log file — the tail of an in-flight append is
1504
+ * indistinguishable from a crash artifact.
1505
+ *
1506
+ * Rejects if `path` does not exist or is not a directory (a bad argument, as
1507
+ * opposed to an invalid store).
1508
+ *
1509
+ * @param path The store directory, e.g. `<dbDir>/transaction_logs/<name>`.
1510
+ * @param options Validation options.
1511
+ *
1512
+ * @example
1513
+ * ```typescript
1514
+ * import { validateTransactionLogStore } from '@harperfast/rocksdb-js';
1515
+ *
1516
+ * const result = await validateTransactionLogStore('/path/to/db/transaction_logs/mylog');
1517
+ * if (!result.valid) {
1518
+ * for (const file of result.files) {
1519
+ * console.error(file.file, file.errors);
1520
+ * }
1521
+ * }
1522
+ * ```
1523
+ */
1524
+ declare function validateTransactionLogStore(path: string, options?: ValidateTransactionLogStoreOptions): Promise<TransactionLogStoreValidation>;
975
1525
  //#endregion
976
1526
  //#region src/load-binding.d.ts
977
1527
  type NativeTransactionOptions = {
978
1528
  /**
979
- * Whether to disable snapshots.
980
- *
981
- * @default false
982
- */
1529
+ * Whether to disable snapshots.
1530
+ *
1531
+ * @default false
1532
+ */
983
1533
  disableSnapshot?: boolean;
984
1534
  /**
985
- * When `true`, an `IsBusy` conflict at commit time is resolved with the
986
- * `RETRY_NOW` sentinel value instead of being rejected. The native layer
987
- * may park on a VT slot before resolving, so the JS retry fires only after
988
- * the conflicting transaction has committed and released its write intent.
989
- *
990
- * Use together with `verificationTable: true` on the database.
991
- *
992
- * @default false
993
- */
1535
+ * When `true`, an `IsBusy` conflict at commit time is resolved with the
1536
+ * `RETRY_NOW` sentinel value instead of being rejected. The native layer
1537
+ * may park on a VT slot before resolving, so the JS retry fires only after
1538
+ * the conflicting transaction has committed and released its write intent.
1539
+ *
1540
+ * Use together with `verificationTable: true` on the database.
1541
+ *
1542
+ * @default false
1543
+ */
994
1544
  coordinatedRetry?: boolean;
995
1545
  };
996
1546
  type NativeTransaction = {
@@ -1027,23 +1577,23 @@ type TransactionEntry = {
1027
1577
  endTxn: boolean;
1028
1578
  };
1029
1579
  /**
1030
- * A position within a transaction log, identifying a log file by its sequence
1031
- * number and a byte `offset` within that file.
1032
- */
1580
+ * A position within a transaction log, identifying a log file by its sequence
1581
+ * number and a byte `offset` within that file.
1582
+ */
1033
1583
  type TransactionLogPosition = {
1034
1584
  sequence: number;
1035
1585
  offset: number;
1036
1586
  };
1037
1587
  /**
1038
- * A detailed statistics snapshot for a single transaction log store, returned
1039
- * by {@link TransactionLog.getStats}. All sizes are in bytes; timestamps are
1040
- * milliseconds since the Unix epoch.
1041
- *
1042
- * Memory note: `memory.mappedBytes` is virtual address space — the active write
1043
- * file is mapped at the full configured `maxFileSize` on POSIX, so it does not
1044
- * reflect resident memory. `memory.overlayBytes` (POSIX only; 0 on Windows) is
1045
- * the file-backed portion and is the closer proxy for real consumption.
1046
- */
1588
+ * A detailed statistics snapshot for a single transaction log store, returned
1589
+ * by {@link TransactionLog.getStats}. All sizes are in bytes; timestamps are
1590
+ * milliseconds since the Unix epoch.
1591
+ *
1592
+ * Memory note: `memory.mappedBytes` is virtual address space — the active write
1593
+ * file is mapped at the full configured `maxFileSize` on POSIX, so it does not
1594
+ * reflect resident memory. `memory.overlayBytes` (POSIX only; 0 on Windows) is
1595
+ * the file-backed portion and is the closer proxy for real consumption.
1596
+ */
1047
1597
  type TransactionLogStats = {
1048
1598
  name: string;
1049
1599
  path: string;
@@ -1103,10 +1653,10 @@ type TransactionLog = {
1103
1653
  _logBuffers: Map<number, WeakRef<LogBuffer>>;
1104
1654
  };
1105
1655
  /**
1106
- * Shape of options that can be passed to the native iterator constructor for
1107
- * the rare case of advanced RocksDB ReadOptions overrides. Common iterator
1108
- * options are passed via the bitmask `flags` argument instead.
1109
- */
1656
+ * Shape of options that can be passed to the native iterator constructor for
1657
+ * the rare case of advanced RocksDB ReadOptions overrides. Common iterator
1658
+ * options are passed via the bitmask `flags` argument instead.
1659
+ */
1110
1660
  type NativeIteratorAdvancedOptions = {
1111
1661
  adaptiveReadahead?: boolean;
1112
1662
  asyncIO?: boolean;
@@ -1117,11 +1667,11 @@ type NativeIteratorAdvancedOptions = {
1117
1667
  tailing?: boolean;
1118
1668
  };
1119
1669
  /**
1120
- * The result of a single native iterator step. A number value matches one of
1121
- * the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
1122
- * the data does not fit in the shared key/value buffers, or when the decoder
1123
- * needs a stable value buffer.
1124
- */
1670
+ * The result of a single native iterator step. A number value matches one of
1671
+ * the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
1672
+ * the data does not fit in the shared key/value buffers, or when the decoder
1673
+ * needs a stable value buffer.
1674
+ */
1125
1675
  type NativeIteratorResult = number | {
1126
1676
  key: Buffer;
1127
1677
  value?: Buffer;
@@ -1137,6 +1687,7 @@ type NativeDatabaseOptions = {
1137
1687
  dbWriteBufferSize?: number;
1138
1688
  disableWAL?: boolean;
1139
1689
  enableStats?: boolean;
1690
+ maxOpenFiles?: number;
1140
1691
  maxWriteBufferNumber?: number;
1141
1692
  maxWriteBufferSizeToMaintain?: number;
1142
1693
  mode?: NativeDatabaseMode;
@@ -1150,11 +1701,11 @@ type NativeDatabaseOptions = {
1150
1701
  transactionLogRetentionMs?: number;
1151
1702
  transactionLogsPath?: string;
1152
1703
  /**
1153
- * When true, transaction writes to this column family invalidate the
1154
- * VerificationTable slot for each written key at write time (not at
1155
- * commit time). Enable only for column families whose records are
1156
- * cached (e.g. the primary CF of a table). Default: false.
1157
- */
1704
+ * When true, transaction writes to this column family invalidate the
1705
+ * VerificationTable slot for each written key at write time (not at
1706
+ * commit time). Enable only for column families whose records are
1707
+ * cached (e.g. the primary CF of a table). Default: false.
1708
+ */
1158
1709
  verificationTable?: boolean;
1159
1710
  writeBufferSize?: number;
1160
1711
  };
@@ -1165,16 +1716,16 @@ type PurgeLogsOptions = {
1165
1716
  before?: number;
1166
1717
  destroy?: boolean;
1167
1718
  /**
1168
- * When `true`, count the entries in each purged log file (extra work) and
1169
- * return `PurgedLog[]` instead of the default `string[]` of file paths.
1170
- */
1719
+ * When `true`, count the entries in each purged log file (extra work) and
1720
+ * return `PurgedLog[]` instead of the default `string[]` of file paths.
1721
+ */
1171
1722
  includeEntryCounts?: boolean;
1172
1723
  name?: string;
1173
1724
  };
1174
1725
  /**
1175
- * A purged transaction log file and the number of entries it held, returned by
1176
- * `purgeLogs()` when `includeEntryCounts` is `true`.
1177
- */
1726
+ * A purged transaction log file and the number of entries it held, returned by
1727
+ * `purgeLogs()` when `includeEntryCounts` is `true`.
1728
+ */
1178
1729
  type PurgedLog = {
1179
1730
  path: string;
1180
1731
  entries: number;
@@ -1183,6 +1734,10 @@ type NativeDatabase = {
1183
1734
  new (): NativeDatabase;
1184
1735
  addListener(event: string, callback: (...args: any[]) => void): void;
1185
1736
  backup(resolve: ResolveCallback<number>, reject: RejectCallback, backupDir: string, options?: BackupOptions): void;
1737
+ backupStream(resolve: ResolveCallback<void>, reject: RejectCallback, emit: (kind: number, data: string | Uint8Array, size: number, mtime: number) => Promise<void>, options?: {
1738
+ flushBeforeBackup?: boolean;
1739
+ transactionLogs?: boolean;
1740
+ }): void;
1186
1741
  clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1187
1742
  clearSync(): void;
1188
1743
  close(): void;
@@ -1235,47 +1790,47 @@ type NativeDatabase = {
1235
1790
  type RocksDatabaseConfig = {
1236
1791
  blockCacheSize?: number;
1237
1792
  /**
1238
- * Number of slots in the process-global verification table. Each slot is
1239
- * 8 bytes; the default of 128K slots is 1 MB. Set to 0 to disable.
1240
- *
1241
- * Must be configured before the first database is opened. Once the table
1242
- * is materialized, attempts to change this value will throw.
1243
- */
1793
+ * Number of slots in the process-global verification table. Each slot is
1794
+ * 8 bytes; the default of 128K slots is 1 MB. Set to 0 to disable.
1795
+ *
1796
+ * Must be configured before the first database is opened. Once the table
1797
+ * is materialized, attempts to change this value will throw.
1798
+ */
1244
1799
  verificationTableEntries?: number;
1245
1800
  compactOnClose?: boolean;
1246
1801
  /**
1247
- * Total memtable memory limit (bytes) shared across every database opened
1248
- * in this process. When set, RocksDB uses a single `WriteBufferManager` so
1249
- * write buffers are bounded process-wide rather than per database. 0 (the
1250
- * default) disables the manager.
1251
- *
1252
- * Can be updated at runtime; the new size takes effect on the existing
1253
- * manager via `SetBufferSize`.
1254
- */
1802
+ * Total memtable memory limit (bytes) shared across every database opened
1803
+ * in this process. When set, RocksDB uses a single `WriteBufferManager` so
1804
+ * write buffers are bounded process-wide rather than per database. 0 (the
1805
+ * default) disables the manager.
1806
+ *
1807
+ * Can be updated at runtime; the new size takes effect on the existing
1808
+ * manager via `SetBufferSize`.
1809
+ */
1255
1810
  writeBufferManagerSize?: number;
1256
1811
  /**
1257
- * When `true`, memtable memory is "charged" against the shared block cache
1258
- * so the block cache and write buffers draw from a single pool. During
1259
- * write bursts the cache shrinks to make room for memtables; once
1260
- * memtables flush, the cache can grow back into the reclaimed space.
1261
- *
1262
- * Has no effect when the block cache is disabled (size 0) or
1263
- * `writeBufferManagerSize` is 0. Must be set on the same `config()` call
1264
- * that first enables the manager — changing it after the manager has been
1265
- * created has no effect on the running instance.
1266
- *
1267
- * @default false
1268
- */
1812
+ * When `true`, memtable memory is "charged" against the shared block cache
1813
+ * so the block cache and write buffers draw from a single pool. During
1814
+ * write bursts the cache shrinks to make room for memtables; once
1815
+ * memtables flush, the cache can grow back into the reclaimed space.
1816
+ *
1817
+ * Has no effect when the block cache is disabled (size 0) or
1818
+ * `writeBufferManagerSize` is 0. Must be set on the same `config()` call
1819
+ * that first enables the manager — changing it after the manager has been
1820
+ * created has no effect on the running instance.
1821
+ *
1822
+ * @default false
1823
+ */
1269
1824
  writeBufferManagerCostToCache?: boolean;
1270
1825
  /**
1271
- * When `true`, writes are stalled once the manager's `buffer_size` is
1272
- * exceeded, providing a hard cap on memtable memory. When `false`,
1273
- * memtables are allowed to grow past the limit and flushes are simply
1274
- * scheduled more aggressively. Off by default to favor write throughput
1275
- * over hard memory bounding.
1276
- *
1277
- * @default false
1278
- */
1826
+ * When `true`, writes are stalled once the manager's `buffer_size` is
1827
+ * exceeded, providing a hard cap on memtable memory. When `false`,
1828
+ * memtables are allowed to grow past the limit and flushes are simply
1829
+ * scheduled more aggressively. Off by default to favor write throughput
1830
+ * over hard memory bounding.
1831
+ *
1832
+ * @default false
1833
+ */
1279
1834
  writeBufferManagerAllowStall?: boolean;
1280
1835
  };
1281
1836
  type RegistryStatusDB = {
@@ -1296,10 +1851,10 @@ declare const constants: {
1296
1851
  POPULATE_VERSION_FLAG: number;
1297
1852
  FRESH_VERSION_FLAG: number;
1298
1853
  /**
1299
- * Sentinel value resolved (not rejected) by `commit()` when
1300
- * `coordinatedRetry: true` and the transaction encountered an IsBusy
1301
- * conflict. JS should retry the transaction body immediately.
1302
- */
1854
+ * Sentinel value resolved (not rejected) by `commit()` when
1855
+ * `coordinatedRetry: true` and the transaction encountered an IsBusy
1856
+ * conflict. JS should retry the transaction body immediately.
1857
+ */
1303
1858
  RETRY_NOW_VALUE: number;
1304
1859
  TRANSACTION_LOG_TOKEN: number;
1305
1860
  TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
@@ -1320,22 +1875,39 @@ declare const registryStatus: () => RegistryStatus;
1320
1875
  declare const shutdown: () => void;
1321
1876
  declare const currentThreadId: () => number;
1322
1877
  /**
1323
- * Advises the kernel that the file-backed pages of every mapped transaction log
1324
- * are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
1325
- * without being freed — useful during replication catch-up, where a full read of
1326
- * the logs would otherwise inflate the container's reclaimable cache toward its
1327
- * cgroup limit. No-op on kernels < 5.4, macOS, and Windows.
1328
- *
1329
- * The transaction log registry is a process-global singleton shared across all
1330
- * worker threads, so a single call cools every worker's maps. Call it on an
1331
- * interval from one thread (e.g. an `unref()`ed timer on the main thread).
1332
- *
1333
- * @returns the number of maps cooled and total file-backed bytes advised.
1334
- */
1878
+ * Advises the kernel that the file-backed pages of every mapped transaction log
1879
+ * are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
1880
+ * without being freed — useful during replication catch-up, where a full read of
1881
+ * the logs would otherwise inflate the container's reclaimable cache toward its
1882
+ * cgroup limit. No-op on kernels < 5.4, macOS, and Windows.
1883
+ *
1884
+ * The transaction log registry is a process-global singleton shared across all
1885
+ * worker threads, so a single call cools every worker's maps. Call it on an
1886
+ * interval from one thread (e.g. an `unref()`ed timer on the main thread).
1887
+ *
1888
+ * @returns the number of maps cooled and total file-backed bytes advised.
1889
+ */
1335
1890
  declare const coolTransactionLogs: () => {
1336
1891
  maps: number;
1337
1892
  bytes: number;
1338
1893
  };
1894
+ /**
1895
+ * Creates a native file lock using the specified file path (`flock` on POSIX,
1896
+ * `LockFileEx` on Windows), creating the file and any missing parent
1897
+ * directories. Exclusive by default; pass `shared` for a shared (reader) lock
1898
+ * that coexists with other shared holders but conflicts with an exclusive
1899
+ * holder in either direction. Returns an opaque non-zero token to pass to
1900
+ * `fileLockRelease`, or `0` if a conflicting holder — in any process,
1901
+ * container, or worker thread — currently has it. Throws on a hard error. The
1902
+ * OS handle is owned entirely in native code (no fd crosses into JS), and the
1903
+ * kernel releases the lock when the handle closes, including on process death.
1904
+ */
1905
+ declare const tryFileLock: (file: string, shared?: boolean) => number;
1906
+ /**
1907
+ * Releases a file lock acquired via `tryFileLock`. A no-op for
1908
+ * token `0` or an unknown token.
1909
+ */
1910
+ declare const fileLockRelease: (token: number) => void;
1339
1911
  declare const stats: {
1340
1912
  StatsLevel: {
1341
1913
  DisableAll: number;
@@ -1348,780 +1920,453 @@ declare const stats: {
1348
1920
  };
1349
1921
  };
1350
1922
  //#endregion
1351
- //#region src/transaction.d.ts
1352
- /**
1353
- * Sentinel value returned by `commit()` when `coordinatedRetry: true` and the
1354
- * transaction encountered an IsBusy conflict. The native layer parks on VT
1355
- * slots and resolves only after the conflicting transaction releases its write
1356
- * intent, so callers should retry immediately without any backoff delay.
1357
- */
1358
- declare const RETRY_NOW: number;
1359
- /**
1360
- * Provides transaction level operations to a transaction callback.
1361
- */
1362
- declare class Transaction extends DBI {
1363
- #private;
1364
- /**
1365
- * Create a new transaction.
1366
- *
1367
- * @param store - The base store interface for this transaction.
1368
- * @param options - The options for the transaction.
1369
- */
1370
- constructor(store: Store, options?: NativeTransactionOptions);
1371
- /**
1372
- * Abort the transaction.
1373
- */
1374
- abort(): void;
1375
- /**
1376
- * Commit the transaction.
1377
- *
1378
- * Returns `RETRY_NOW` when `coordinatedRetry: true` and an IsBusy conflict
1379
- * was detected. The caller should retry the transaction body immediately.
1380
- */
1381
- commit(): Promise<typeof RETRY_NOW | void>;
1382
- /**
1383
- * Commit the transaction synchronously.
1384
- */
1385
- commitSync(): void;
1386
- /**
1387
- * Returns the transaction start timestamp in seconds. Defaults to the time at which
1388
- * the transaction was created.
1389
- *
1390
- * @returns The transaction start timestamp in seconds.
1391
- */
1392
- getTimestamp(): number;
1393
- /**
1394
- * Get the transaction id.
1395
- */
1396
- get id(): number;
1397
- /**
1398
- * Set the transaction start timestamp in seconds.
1399
- *
1400
- * @param timestamp - The timestamp to set in seconds.
1401
- */
1402
- setTimestamp(timestamp?: number): void;
1403
- }
1404
- //#endregion
1405
- //#region src/util.d.ts
1406
- type MaybePromise<T> = T | Promise<T>;
1407
- //#endregion
1408
- //#region src/dbi.d.ts
1409
- interface RocksDBOptions {
1410
- /**
1411
- * When `true`, RocksDB will do some enhancements for prefetching the data.
1412
- * Defaults to `true`. Note that RocksDB defaults this to `false`.
1413
- */
1414
- adaptiveReadahead?: boolean;
1415
- /**
1416
- * When `true`, RocksDB will prefetch some data async and apply it if reads
1417
- * are sequential and its internal automatic prefetching. Defaults to
1418
- * `true`. Note that RocksDB defaults this to `false`.
1419
- */
1420
- asyncIO?: boolean;
1421
- /**
1422
- * When `true`, RocksDB will auto-tune the readahead size during scans
1423
- * internally based on the block cache data when block caching is enabled,
1424
- * an end key (e.g. upper bound) is set, and prefix is the same as the start
1425
- * key. Defaults to `true`.
1426
- */
1427
- autoReadaheadSize?: boolean;
1428
- /**
1429
- * When `true`, after the iterator is closed, a background job is scheduled
1430
- * to flush the job queue and delete obsolete files. Defaults to `true`.
1431
- * Note that RocksDB defaults this to `false`.
1432
- */
1433
- backgroundPurgeOnIteratorCleanup?: boolean;
1434
- /**
1435
- * When `true`, the iterator will fill the block cache. Filling the block
1436
- * cache is not desirable for bulk scans and could impact eviction order.
1437
- * Defaults to `false`. Note that RocksDB defaults this to `true`.
1438
- */
1439
- fillCache?: boolean;
1440
- /**
1441
- * The RocksDB readahead size. RocksDB does auto-readahead for iterators
1442
- * when there is more than two reads for a table file. The readahead
1443
- * starts at 8KB and doubles on every additional read up to 256KB. This
1444
- * option can help if most of the range scans are large and if a larger
1445
- * readahead than that enabled by auto-readahead is needed. Using a large
1446
- * readahead size (> 2MB) can typically improve the performance of forward
1447
- * iteration on spinning disks. Defaults to `0`.
1448
- */
1449
- readaheadSize?: number;
1450
- /**
1451
- * When `true`, creates a "tailing iterator" which is a special iterator
1452
- * that has a view of the complete database including newly added data and
1453
- * is optimized for sequential reads. This will return records that were
1454
- * inserted into the database after the creation of the iterator. Defaults
1455
- * to `false`.
1456
- */
1457
- tailing?: boolean;
1458
- }
1459
- interface RangeOptions extends RocksDBOptions {
1460
- /**
1461
- * The range end key, otherwise known as the "upper bound". Defaults to
1462
- * the last key in the database.
1463
- */
1464
- end?: Key | Uint8Array;
1465
- /**
1466
- * When `true`, the iterator will exclude the first key if it matches the start key.
1467
- * Defaults to `false`.
1468
- */
1469
- exclusiveStart?: boolean;
1470
- /**
1471
- * When `true`, the iterator will include the last key if it matches the end
1472
- * key. Defaults to `false`.
1473
- */
1474
- inclusiveEnd?: boolean;
1475
- /**
1476
- * The range start key, otherwise known as the "lower bound". Defaults to
1477
- * the first key in the database.
1478
- */
1479
- start?: Key | Uint8Array;
1480
- }
1481
- interface IteratorOptions extends RangeOptions {
1482
- /**
1483
- * The maximum number of entries to yield. When set, iteration stops after
1484
- * `limit` entries regardless of the range bounds. Values <= 0 yield nothing.
1485
- * Unset means no limit.
1486
- */
1487
- limit?: number;
1488
- /**
1489
- * A specific key to match which may result in zero, one, or many values.
1490
- */
1491
- key?: Key;
1492
- /**
1493
- * When `true`, only returns the number of values for the given query.
1494
- */
1495
- onlyCount?: boolean;
1496
- /**
1497
- * When `true`, the iterator will iterate in reverse order. Defaults to
1498
- * `false`.
1499
- */
1500
- reverse?: boolean;
1501
- /**
1502
- * When `true`, decodes and returns the value. When `false`, the value is
1503
- * omitted. Defaults to `true`.
1504
- */
1505
- values?: boolean;
1506
- /**
1507
- * When `true`, the iterator will only return the values.
1508
- */
1509
- valuesOnly?: boolean;
1510
- }
1511
- interface DBITransactional {
1512
- transaction?: Transaction;
1513
- }
1923
+ //#region src/backup-stream.d.ts
1514
1924
  /**
1515
- * The base class for all database operations. This base class is shared by
1516
- * `RocksDatabase` and `Transaction`.
1517
- *
1518
- * This class is not meant to be used directly.
1519
- */
1520
- declare class DBI<T extends DBITransactional | unknown = unknown> {
1521
- /**
1522
- * The RocksDB context for `get()`, `put()`, and `remove()`.
1523
- */
1524
- _context: StoreContext;
1525
- /**
1526
- * The database store instance. The store instance is tied to the database
1527
- * instance and shared with transaction instances.
1528
- */
1529
- store: Store;
1530
- /**
1531
- * Initializes the DBI context.
1532
- *
1533
- * @param store - The store instance.
1534
- * @param transaction - The transaction instance.
1535
- */
1536
- constructor(store: Store, transaction?: NativeTransaction);
1537
- /**
1538
- * Adds a listener for the given key.
1539
- *
1540
- * @param event - The event name to add the listener for.
1541
- * @param callback - The callback to add.
1542
- */
1543
- addListener(event: string, callback: (...args: any[]) => void): this;
1544
- /**
1545
- * Retrieves the value for the given key, then returns the decoded value.
1546
- */
1547
- get(key: Key, options?: GetOptions & T): MaybePromise<any | undefined>;
1548
- /**
1549
- * Retrieves the binary data for the given key. This is just like `get()`,
1550
- * but bypasses the decoder.
1551
- *
1552
- * Note: Used by HDBreplication.
1553
- */
1554
- getBinary(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
1555
- /**
1556
- * Synchronously retrieves the binary data for the given key.
1557
- */
1558
- getBinarySync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
1559
- /**
1560
- * Retrieves the binary data for the given key using a preallocated,
1561
- * reusable buffer. Data in the buffer is only valid until the next get
1562
- * operation (including cursor operations).
1563
- *
1564
- * Note: The reusable buffer slightly differs from a typical buffer:
1565
- * - `.length` is set to the size of the value
1566
- * - `.byteLength` is set to the size of the full allocated memory area for
1567
- * the buffer (usually much larger).
1568
- */
1569
- getBinaryFast(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
1570
- /**
1571
- * Synchronously retrieves the binary data for the given key using a
1572
- * preallocated, reusable buffer. Data in the buffer is only valid until the
1573
- * next get operation (including cursor operations).
1574
- */
1575
- getBinaryFastSync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
1576
- /**
1577
- * Retrieves all keys within a range.
1578
- */
1579
- getKeys(options?: IteratorOptions & T): any | undefined;
1580
- /**
1581
- * Retrieves the number of keys within a range.
1582
- *
1583
- * @param options - The range options.
1584
- * @returns The number of keys within the range.
1585
- *
1586
- * @example
1587
- * ```typescript
1588
- * const total = db.getKeysCount();
1589
- * const range = db.getKeysCount({ start: 'a', end: 'z' });
1590
- * ```
1591
- */
1592
- getKeysCount(options?: RangeOptions & T): number;
1593
- /**
1594
- * Retrieves a range of keys and their values.
1595
- *
1596
- * @param options - The iterator options.
1597
- * @returns A range iterable.
1598
- *
1599
- * @example
1600
- * ```typescript
1601
- * for (const { key, value } of db.getRange()) {
1602
- * console.log({ key, value });
1603
- * }
1604
- *
1605
- * for (const { key, value } of db.getRange({ start: 'a', end: 'z' })) {
1606
- * console.log({ key, value });
1607
- * }
1608
- * ```
1609
- */
1610
- getRange(options?: IteratorOptions & T): any | undefined;
1611
- /**
1612
- * Synchronously retrieves the value for the given key, then returns the
1613
- * decoded value.
1614
- */
1615
- getSync(key: Key, options?: GetOptions & T): any | undefined;
1616
- /**
1617
- * Gets the number of listeners for the given key.
1618
- *
1619
- * @param event - The event name to get the listeners for.
1620
- * @returns The number of listeners for the given key.
1621
- */
1622
- listeners(event: string | BufferWithDataView): number;
1623
- /**
1624
- * Notifies an event for the given key.
1625
- *
1626
- * @param event - The event name to emit the event for.
1627
- * @param args - The arguments to emit.
1628
- * @returns `true` if there were listeners, `false` otherwise.
1629
- */
1630
- notify(event: string, ...args: any[]): boolean;
1631
- /**
1632
- * Alias for `removeListener()`.
1633
- *
1634
- * @param event - The event name to remove the listener for.
1635
- * @param callback - The callback to remove.
1636
- */
1637
- off(event: string, callback: (...args: any[]) => void): this;
1638
- /**
1639
- * Alias for `addListener()`.
1640
- *
1641
- * @param event - The event name to add the listener for.
1642
- * @param callback - The callback to add.
1643
- */
1644
- on(event: string, callback: (...args: any[]) => void): this;
1645
- /**
1646
- * Adds a one-time listener, then automatically removes it.
1647
- *
1648
- * @param event - The event name to add the listener for.
1649
- * @param callback - The callback to add.
1650
- */
1651
- once(event: string, callback: (...args: any[]) => void): this;
1652
- /**
1653
- * Stores a value for the given key.
1654
- *
1655
- * @param key - The key to store the value for.
1656
- * @param value - The value to store.
1657
- * @param options - The put options.
1658
- * @returns The key and value.
1659
- *
1660
- * @example
1661
- * ```typescript
1662
- * await db.put('a', 'b');
1663
- * ```
1664
- */
1665
- put(key: Key, value: any, options?: PutOptions & T): Promise<void>;
1666
- /**
1667
- * Synchronously stores a value for the given key.
1668
- *
1669
- * @param key - The key to store the value for.
1670
- * @param value - The value to store.
1671
- * @param options - The put options.
1672
- * @returns The key and value.
1673
- *
1674
- * @example
1675
- * ```typescript
1676
- * db.putSync('a', 'b');
1677
- * ```
1678
- */
1679
- putSync(key: Key, value: any, options?: PutOptions & T): void;
1680
- /**
1681
- * Removes a value for the given key. If the key does not exist, it will
1682
- * not error.
1683
- *
1684
- * @param key - The key to remove the value for.
1685
- * @param options - The remove options.
1686
- * @returns The key and value.
1687
- *
1688
- * @example
1689
- * ```typescript
1690
- * await db.remove('a');
1691
- * ```
1692
- */
1693
- remove(key: Key, options?: T): Promise<void>;
1694
- /**
1695
- * Removes a value for the given key. If the key does not exist, it will
1696
- * not error.
1697
- *
1698
- * @param key - The key to remove the value for.
1699
- * @param options - The remove options.
1700
- * @returns The key and value.
1701
- *
1702
- * @example
1703
- * ```typescript
1704
- * db.removeSync('a');
1705
- * ```
1706
- */
1707
- removeSync(key: Key, options?: T): void;
1708
- /**
1709
- * Removes an event listener. You must specify the exact same callback that was
1710
- * used in `addListener()`.
1711
- *
1712
- * @param event - The event name to remove the listener for.
1713
- * @param callback - The callback to remove.
1714
- */
1715
- removeListener(event: string, callback: (value?: any) => void): boolean;
1925
+ * Options for streaming a backup via `db.backup(stream)`.
1926
+ */
1927
+ interface BackupStreamOptions {
1928
+ /**
1929
+ * Flush the memtable before streaming. Defaults to `true` when the database
1930
+ * was opened with `disableWAL` (otherwise unflushed data would be missing
1931
+ * from the stream), and `false` otherwise — matching `db.backup(dir)`.
1932
+ */
1933
+ flushBeforeBackup?: boolean;
1716
1934
  /**
1717
- * Get or create a transaction log instance.
1718
- *
1719
- * @param name - The name of the transaction log.
1720
- * @returns The transaction log.
1721
- */
1722
- useLog(name: string | number): TransactionLog;
1935
+ * Gzip-compress the archive before writing it to the stream, producing a
1936
+ * `.tar.gz` stream instead of a plain `.tar`. Defaults to `false`.
1937
+ *
1938
+ * Compression runs in the runtime's `CompressionStream`, downstream of the tar
1939
+ * encoder, so end-to-end backpressure is preserved. RocksDB SST files are
1940
+ * usually already block-compressed, so the additional savings vary with the
1941
+ * data and the configured compression.
1942
+ */
1943
+ gzip?: boolean;
1944
+ /**
1945
+ * Also stream the transaction log store as `transaction_logs/<store>/…`
1946
+ * entries (each `*.txnlog` and `txn.state` file) after the database files.
1947
+ * Defaults to `false`. Extraction reconstructs them next to the database, and
1948
+ * their mtimes are preserved so the store's age-based rotation/retention stays
1949
+ * correct.
1950
+ */
1951
+ transactionLogs?: boolean;
1723
1952
  }
1724
1953
  //#endregion
1725
1954
  //#region src/database.d.ts
1726
1955
  type TransactionCallback<T> = (txn: Transaction, attempt: number) => T | PromiseLike<T>;
1727
1956
  interface RocksDatabaseOptions extends StoreOptions {
1728
1957
  /**
1729
- * The column family name.
1730
- *
1731
- * @default 'default'
1732
- */
1958
+ * The column family name.
1959
+ *
1960
+ * @default 'default'
1961
+ */
1733
1962
  name?: string;
1734
1963
  }
1735
1964
  interface TransactionOptions extends NativeTransactionOptions {
1736
1965
  /**
1737
- * The maximum number of times to retry the transaction.
1738
- *
1739
- * @default 3
1740
- */
1966
+ * The maximum number of times to retry the transaction.
1967
+ *
1968
+ * @default 3
1969
+ */
1741
1970
  maxRetries?: number;
1742
1971
  /**
1743
- * Whether to retry the transaction if it fails with `IsBusy`.
1744
- *
1745
- * @default `true` when the transaction is bound to a transaction log, otherwise `false`
1746
- */
1972
+ * Whether to retry the transaction if it fails with `IsBusy`.
1973
+ *
1974
+ * @default `true` when the transaction is bound to a transaction log, otherwise `false`
1975
+ */
1747
1976
  retryOnBusy?: boolean;
1748
1977
  }
1749
1978
  type RocksDBStat = StatsValue;
1750
1979
  type RocksDBStats = StatsDefault | StatsAll;
1751
1980
  /**
1752
- * The main class for interacting with a RocksDB database.
1753
- *
1754
- * Before using this class, you must open the database first.
1755
- *
1756
- * @example
1757
- * ```typescript
1758
- * const db = RocksDatabase.open('/path/to/database');
1759
- * await db.put('key', 'value');
1760
- * const value = await db.get('key');
1761
- * db.close();
1762
- * ```
1763
- */
1981
+ * The main class for interacting with a RocksDB database.
1982
+ *
1983
+ * Before using this class, you must open the database first.
1984
+ *
1985
+ * @example
1986
+ * ```typescript
1987
+ * const db = RocksDatabase.open('/path/to/database');
1988
+ * await db.put('key', 'value');
1989
+ * const value = await db.get('key');
1990
+ * db.close();
1991
+ * ```
1992
+ */
1764
1993
  declare class RocksDatabase extends DBI<DBITransactional> {
1765
1994
  #private;
1766
1995
  constructor(pathOrStore: string | Store, options?: RocksDatabaseOptions);
1767
1996
  /**
1768
- * Removes all data from the database asynchronously.
1769
- *
1770
- * @example
1771
- * ```typescript
1772
- * const db = RocksDatabase.open('/path/to/database');
1773
- * await db.clear();
1774
- * ```
1775
- */
1997
+ * Removes all data from the database asynchronously.
1998
+ *
1999
+ * @example
2000
+ * ```typescript
2001
+ * const db = RocksDatabase.open('/path/to/database');
2002
+ * await db.clear();
2003
+ * ```
2004
+ */
1776
2005
  clear(): Promise<void>;
1777
2006
  /**
1778
- * Removes all entries from the database synchronously.
1779
- *
1780
- * @example
1781
- * ```typescript
1782
- * const db = RocksDatabase.open('/path/to/database');
1783
- * db.clearSync();
1784
- * ```
1785
- */
2007
+ * Removes all entries from the database synchronously.
2008
+ *
2009
+ * @example
2010
+ * ```typescript
2011
+ * const db = RocksDatabase.open('/path/to/database');
2012
+ * db.clearSync();
2013
+ * ```
2014
+ */
1786
2015
  clearSync(): void;
1787
2016
  /**
1788
- * Closes the database.
1789
- *
1790
- * @example
1791
- * ```typescript
1792
- * const db = RocksDatabase.open('/path/to/database');
1793
- * db.close();
1794
- * ```
1795
- */
2017
+ * Closes the database.
2018
+ *
2019
+ * @example
2020
+ * ```typescript
2021
+ * const db = RocksDatabase.open('/path/to/database');
2022
+ * db.close();
2023
+ * ```
2024
+ */
1796
2025
  close(): void;
1797
2026
  /**
1798
- * Compacts the entire key range of the database asynchronously.
1799
- * This triggers manual compaction which removes tombstones and reclaims space.
1800
- *
1801
- * @example
1802
- * ```typescript
1803
- * const db = RocksDatabase.open('/path/to/database');
1804
- * await db.compact();
1805
- * ```
1806
- */
2027
+ * Compacts the entire key range of the database asynchronously.
2028
+ * This triggers manual compaction which removes tombstones and reclaims space.
2029
+ *
2030
+ * @example
2031
+ * ```typescript
2032
+ * const db = RocksDatabase.open('/path/to/database');
2033
+ * await db.compact();
2034
+ * ```
2035
+ */
1807
2036
  compact(options?: CompactOptions): Promise<void>;
1808
2037
  /**
1809
- * Creates a backup of the entire database (all column families) into the
1810
- * given directory, creating parent directories as needed, and resolves with
1811
- * the new backup id. Use the `backups` namespace to restore, list, delete,
1812
- * purge, or verify backups.
1813
- *
1814
- * When the database was opened with `disableWAL`, the memtable is flushed
1815
- * before the backup by default so unflushed data is not lost.
1816
- *
1817
- * @example
1818
- * ```typescript
1819
- * import { backups } from '@harperfast/rocksdb-js';
1820
- *
1821
- * const db = RocksDatabase.open('/path/to/database');
1822
- * const id = await db.backup('/path/to/backups');
1823
- * ```
1824
- */
2038
+ * Creates a backup of the entire database (all column families) into the
2039
+ * given directory, creating parent directories as needed, and resolves with
2040
+ * the new backup id. Use the `backups` namespace to restore, list, delete,
2041
+ * purge, or verify backups.
2042
+ *
2043
+ * When the database was opened with `disableWAL`, the memtable is flushed
2044
+ * before the backup by default so unflushed data is not lost.
2045
+ *
2046
+ * @example
2047
+ * ```typescript
2048
+ * import { backups } from '@harperfast/rocksdb-js';
2049
+ *
2050
+ * const db = RocksDatabase.open('/path/to/database');
2051
+ * const id = await db.backup('/path/to/backups');
2052
+ * ```
2053
+ */
1825
2054
  backup(backupDir: string, options?: BackupOptions): Promise<number>;
1826
2055
  /**
1827
- * Creates a hardlinked, point-in-time, fully independent copy of the entire
1828
- * database (all column families) at `targetPath` and resolves once written.
1829
- *
1830
- * Unlike a backup, a checkpoint is a normal, writable sibling database: open
1831
- * it with {@link RocksDatabase.open} and it diverges independently from the
1832
- * source. SST and blob files are hardlinked when `targetPath` is on the same
1833
- * filesystem as the database and copied otherwise (other files such as the
1834
- * MANIFEST are always copied), so the operation is near-instant on the same
1835
- * filesystem. The memtable is flushed so the checkpoint includes the latest
1836
- * writes even when the WAL is disabled.
1837
- *
1838
- * Parent directories are created as needed. `targetPath` itself must not
1839
- * already exist (RocksDB creates the checkpoint directory) and rejects with
1840
- * `Create checkpoint failed: target path exists` if it does. The caller is
1841
- * responsible for eventual cleanup of the directory.
1842
- *
1843
- * @example
1844
- * ```typescript
1845
- * const db = RocksDatabase.open('/path/to/database');
1846
- * await db.createCheckpoint('/path/to/checkpoint');
1847
- * const branch = RocksDatabase.open('/path/to/checkpoint');
1848
- * ```
1849
- */
2056
+ * Streams a consistent snapshot of the entire database to a `WritableStream`
2057
+ * as a tar archive, with no intermediate copy written to disk. Resolves once
2058
+ * the stream has been fully written and closed.
2059
+ *
2060
+ * Backpressure is honored end to end, so a slow consumer (e.g. a network or
2061
+ * S3 upload) paces the backup rather than buffering it in memory. The archive
2062
+ * unpacks with any tar tool into a directory that opens as a RocksDB database.
2063
+ *
2064
+ * @example
2065
+ * ```typescript
2066
+ * const file = await fetch(uploadUrl, { method: 'PUT', body: stream });
2067
+ * await db.backup(stream); // `stream` is the request's WritableStream
2068
+ * ```
2069
+ */
2070
+ backup(stream: WritableStream<Uint8Array>, options?: BackupStreamOptions): Promise<void>;
2071
+ /**
2072
+ * Creates a hardlinked, point-in-time, fully independent copy of the entire
2073
+ * database (all column families) at `targetPath` and resolves once written.
2074
+ *
2075
+ * Unlike a backup, a checkpoint is a normal, writable sibling database: open
2076
+ * it with {@link RocksDatabase.open} and it diverges independently from the
2077
+ * source. SST and blob files are hardlinked when `targetPath` is on the same
2078
+ * filesystem as the database and copied otherwise (other files such as the
2079
+ * MANIFEST are always copied), so the operation is near-instant on the same
2080
+ * filesystem. The memtable is flushed so the checkpoint includes the latest
2081
+ * writes even when the WAL is disabled.
2082
+ *
2083
+ * Parent directories are created as needed. `targetPath` itself must not
2084
+ * already exist (RocksDB creates the checkpoint directory) and rejects with
2085
+ * `Create checkpoint failed: target path exists` if it does. The caller is
2086
+ * responsible for eventual cleanup of the directory.
2087
+ *
2088
+ * @example
2089
+ * ```typescript
2090
+ * const db = RocksDatabase.open('/path/to/database');
2091
+ * await db.createCheckpoint('/path/to/checkpoint');
2092
+ * const branch = RocksDatabase.open('/path/to/checkpoint');
2093
+ * ```
2094
+ */
1850
2095
  createCheckpoint(targetPath: string): Promise<void>;
1851
2096
  /**
1852
- * Compacts the entire key range of the database synchronously.
1853
- * This triggers manual compaction which removes tombstones and reclaims space.
1854
- *
1855
- * @example
1856
- * ```typescript
1857
- * const db = RocksDatabase.open('/path/to/database');
1858
- * db.compactSync();
1859
- * ```
1860
- */
2097
+ * Compacts the entire key range of the database synchronously.
2098
+ * This triggers manual compaction which removes tombstones and reclaims space.
2099
+ *
2100
+ * @example
2101
+ * ```typescript
2102
+ * const db = RocksDatabase.open('/path/to/database');
2103
+ * db.compactSync();
2104
+ * ```
2105
+ */
1861
2106
  compactSync(options?: CompactOptions): void;
1862
2107
  /**
1863
- * Returns the list of column families in the RocksDB database.
1864
- */
2108
+ * Returns the list of column families in the RocksDB database.
2109
+ */
1865
2110
  get columns(): string[];
1866
2111
  /**
1867
- * Set global database settings.
1868
- *
1869
- * @param options - The options for the database.
1870
- *
1871
- * @example
1872
- * ```typescript
1873
- * RocksDatabase.config({ blockCacheSize: 1024 * 1024 });
1874
- * ```
1875
- */
2112
+ * Set global database settings.
2113
+ *
2114
+ * @param options - The options for the database.
2115
+ *
2116
+ * @example
2117
+ * ```typescript
2118
+ * RocksDatabase.config({ blockCacheSize: 1024 * 1024 });
2119
+ * ```
2120
+ */
1876
2121
  static config(options: RocksDatabaseConfig): void;
1877
2122
  /**
1878
- * Registers a process-wide event listener. Internal events emitted by the
1879
- * native binding use namespaced keys (e.g. `'transactionLog:warning'`).
1880
- *
1881
- * Listeners are not tied to any specific database — they fire for every
1882
- * matching event emitted in this process.
1883
- *
1884
- * @example
1885
- * ```typescript
1886
- * RocksDatabase.on('transactionLog:warning', (warning) => {
1887
- * console.warn(warning);
1888
- * });
1889
- * ```
1890
- */
2123
+ * Registers a process-wide event listener. Internal events emitted by the
2124
+ * native binding use namespaced keys (e.g. `'transactionLog:warning'`).
2125
+ *
2126
+ * Listeners are not tied to any specific database — they fire for every
2127
+ * matching event emitted in this process.
2128
+ *
2129
+ * @example
2130
+ * ```typescript
2131
+ * RocksDatabase.on('transactionLog:warning', (warning) => {
2132
+ * console.warn(warning);
2133
+ * });
2134
+ * ```
2135
+ */
1891
2136
  static on(event: string, callback: (...args: any[]) => void): void;
1892
2137
  /**
1893
- * Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
1894
- */
2138
+ * Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
2139
+ */
1895
2140
  static addListener(event: string, callback: (...args: any[]) => void): void;
1896
2141
  /**
1897
- * Removes a previously-registered process-wide event listener. The
1898
- * callback identity must match the one passed to {@link RocksDatabase.on}.
1899
- *
1900
- * @returns `true` if a matching listener was removed.
1901
- */
2142
+ * Removes a previously-registered process-wide event listener. The
2143
+ * callback identity must match the one passed to {@link RocksDatabase.on}.
2144
+ *
2145
+ * @returns `true` if a matching listener was removed.
2146
+ */
1902
2147
  static off(event: string, callback: (...args: any[]) => void): boolean;
1903
2148
  /**
1904
- * Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
1905
- */
2149
+ * Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
2150
+ */
1906
2151
  static removeListener(event: string, callback: (...args: any[]) => void): boolean;
1907
2152
  /**
1908
- * Returns the number of process-wide listeners registered for the given event.
1909
- */
2153
+ * Returns the number of process-wide listeners registered for the given event.
2154
+ */
1910
2155
  static listenerCount(event: string): number;
1911
2156
  /**
1912
- * Emits a process-wide event. Mostly intended for tests and as a peer to
1913
- * {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
1914
- * `napi/global_events.h` directly rather than round-tripping through JS.
1915
- *
1916
- * @returns `true` if there was at least one listener.
1917
- */
2157
+ * Emits a process-wide event. Mostly intended for tests and as a peer to
2158
+ * {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
2159
+ * `napi/global_events.h` directly rather than round-tripping through JS.
2160
+ *
2161
+ * @returns `true` if there was at least one listener.
2162
+ */
1918
2163
  static notify(event: string, ...args: any[]): boolean;
1919
2164
  destroy(): void;
1920
2165
  drop(): Promise<void>;
1921
2166
  dropSync(): void;
1922
2167
  get encoder(): Encoder | null;
1923
2168
  /**
1924
- * Flushes the underlying database by performing a commit or clearing any buffered operations.
1925
- *
1926
- * @return {void} Does not return a value.
1927
- */
2169
+ * Flushes the underlying database by performing a commit or clearing any buffered operations.
2170
+ *
2171
+ * @return {void} Does not return a value.
2172
+ */
1928
2173
  flush(): Promise<void>;
1929
2174
  /**
1930
- * Synchronously flushes the underlying database by performing a commit or clearing any buffered operations.
1931
- *
1932
- * @return {void} Does not return a value.
1933
- */
2175
+ * Synchronously flushes the underlying database by performing a commit or clearing any buffered operations.
2176
+ *
2177
+ * @return {void} Does not return a value.
2178
+ */
1934
2179
  flushSync(): void;
1935
2180
  /**
1936
- * Gets a RocksDB database property as an integer.
1937
- *
1938
- * @param propertyName - The name of the property to retrieve (e.g., 'rocksdb.num-blob-files').
1939
- * @returns The property value as a number.
1940
- *
1941
- * @example
1942
- * ```typescript
1943
- * const db = RocksDatabase.open('/path/to/database');
1944
- * const blobFiles = db.getDBIntProperty('rocksdb.num-blob-files');
1945
- * const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
1946
- * ```
1947
- */
2181
+ * Gets a RocksDB database property as an integer.
2182
+ *
2183
+ * @param propertyName - The name of the property to retrieve (e.g., 'rocksdb.num-blob-files').
2184
+ * @returns The property value as a number.
2185
+ *
2186
+ * @example
2187
+ * ```typescript
2188
+ * const db = RocksDatabase.open('/path/to/database');
2189
+ * const blobFiles = db.getDBIntProperty('rocksdb.num-blob-files');
2190
+ * const numKeys = db.getDBIntProperty('rocksdb.estimate-num-keys');
2191
+ * ```
2192
+ */
1948
2193
  getDBIntProperty(propertyName: string): number | undefined;
1949
2194
  /**
1950
- * Gets a RocksDB database property as a string.
1951
- *
1952
- * @param propertyName - The name of the property to retrieve (e.g., 'rocksdb.levelstats').
1953
- * @returns The property value as a string.
1954
- *
1955
- * @example
1956
- * ```typescript
1957
- * const db = RocksDatabase.open('/path/to/database');
1958
- * const levelStats = db.getDBProperty('rocksdb.levelstats');
1959
- * const stats = db.getDBProperty('rocksdb.stats');
1960
- * ```
1961
- */
2195
+ * Gets a RocksDB database property as a string.
2196
+ *
2197
+ * @param propertyName - The name of the property to retrieve (e.g., 'rocksdb.levelstats').
2198
+ * @returns The property value as a string.
2199
+ *
2200
+ * @example
2201
+ * ```typescript
2202
+ * const db = RocksDatabase.open('/path/to/database');
2203
+ * const levelStats = db.getDBProperty('rocksdb.levelstats');
2204
+ * const stats = db.getDBProperty('rocksdb.stats');
2205
+ * ```
2206
+ */
1962
2207
  getDBProperty(propertyName: string): string | undefined;
1963
2208
  /**
1964
- * Retrieves the estimated number of keys in the database.
1965
- *
1966
- * @example
1967
- * ```typescript
1968
- * const db = RocksDatabase.open('/path/to/database');
1969
- * const estimated = db.getEstimatedKeyCount();
1970
- * console.log(estimated);
1971
- * ```
1972
- */
2209
+ * Retrieves the estimated number of keys in the database.
2210
+ *
2211
+ * @example
2212
+ * ```typescript
2213
+ * const db = RocksDatabase.open('/path/to/database');
2214
+ * const estimated = db.getEstimatedKeyCount();
2215
+ * console.log(estimated);
2216
+ * ```
2217
+ */
1973
2218
  getEstimatedKeyCount(): number;
1974
2219
  /**
1975
- * Returns the current timestamp as a monotonically increasing timestamp in
1976
- * milliseconds represented as a decimal number.
1977
- *
1978
- * @returns The current monotonic timestamp in milliseconds.
1979
- */
2220
+ * Returns the current timestamp as a monotonically increasing timestamp in
2221
+ * milliseconds represented as a decimal number.
2222
+ *
2223
+ * @returns The current monotonic timestamp in milliseconds.
2224
+ */
1980
2225
  getMonotonicTimestamp(): number;
1981
2226
  /**
1982
- * Returns a number representing a unix timestamp of the oldest unreleased
1983
- * snapshot.
1984
- *
1985
- * @returns The oldest snapshot timestamp.
1986
- */
2227
+ * Returns a number representing a unix timestamp of the oldest unreleased
2228
+ * snapshot.
2229
+ *
2230
+ * @returns The oldest snapshot timestamp.
2231
+ */
1987
2232
  getOldestSnapshotTimestamp(): number;
1988
2233
  /**
1989
- * Gets a RocksDB statistic.
1990
- *
1991
- * @param statName - The name of the statistic to retrieve.
1992
- * @returns The statistic value.
1993
- */
2234
+ * Gets a RocksDB statistic.
2235
+ *
2236
+ * @param statName - The name of the statistic to retrieve.
2237
+ * @returns The statistic value.
2238
+ */
1994
2239
  getStat(statName: string): RocksDBStat;
1995
2240
  /**
1996
- * Gets the RocksDB statistics. The RocksDB ticker/histogram stats require
1997
- * statistics to be enabled, but the result always includes a summarized,
1998
- * aggregate set of `txnlog.*` keys (across all of this database's transaction
1999
- * logs), regardless of whether statistics are enabled. For detailed per-log
2000
- * statistics, including memory-map usage, use `log.getStats()` on the log
2001
- * returned by {@link RocksDatabase#useLog}.
2002
- *
2003
- * @example
2004
- * ```typescript
2005
- * const db = RocksDatabase.open('/path/to/database');
2006
- * const stats = db.getStats();
2007
- * stats['txnlog.totalSizeBytes']; // bytes across all transaction logs
2008
- * ```
2009
- */
2241
+ * Gets the RocksDB statistics. The RocksDB ticker/histogram stats require
2242
+ * statistics to be enabled, but the result always includes a summarized,
2243
+ * aggregate set of `txnlog.*` keys (across all of this database's transaction
2244
+ * logs), regardless of whether statistics are enabled. For detailed per-log
2245
+ * statistics, including memory-map usage, use `log.getStats()` on the log
2246
+ * returned by {@link RocksDatabase#useLog}.
2247
+ *
2248
+ * @example
2249
+ * ```typescript
2250
+ * const db = RocksDatabase.open('/path/to/database');
2251
+ * const stats = db.getStats();
2252
+ * stats['txnlog.totalSizeBytes']; // bytes across all transaction logs
2253
+ * ```
2254
+ */
2010
2255
  getStats(all?: false): StatsDefault;
2011
2256
  getStats(all: true): StatsAll;
2012
2257
  /**
2013
- * Gets or creates a buffer that can be shared across worker threads.
2014
- *
2015
- * @param key - The key to get or create the buffer for.
2016
- * @param defaultBuffer - The default buffer to copy and use if the buffer
2017
- * does not exist.
2018
- * @param [options] - The options for the buffer.
2019
- * @param [options.callback] - A optional callback that receives
2020
- * key-specific events.
2021
- * @returns An `ArrayBuffer` that is internally backed by a shared block of
2022
- * memory. The buffer also has `notify()` and `cancel()` methods that can be
2023
- * used to notify the specified `options.callback`.
2024
- *
2025
- * @example
2026
- * ```typescript
2027
- * const db = RocksDatabase.open('/path/to/database');
2028
- * const buffer = db.getUserSharedBuffer('foo', new ArrayBuffer(10));
2029
- */
2258
+ * Gets or creates a buffer that can be shared across worker threads.
2259
+ *
2260
+ * @param key - The key to get or create the buffer for.
2261
+ * @param defaultBuffer - The default buffer to copy and use if the buffer
2262
+ * does not exist.
2263
+ * @param [options] - The options for the buffer.
2264
+ * @param [options.callback] - A optional callback that receives
2265
+ * key-specific events.
2266
+ * @returns An `ArrayBuffer` that is internally backed by a shared block of
2267
+ * memory. The buffer also has `notify()` and `cancel()` methods that can be
2268
+ * used to notify the specified `options.callback`.
2269
+ *
2270
+ * @example
2271
+ * ```typescript
2272
+ * const db = RocksDatabase.open('/path/to/database');
2273
+ * const buffer = db.getUserSharedBuffer('foo', new ArrayBuffer(10));
2274
+ */
2030
2275
  getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
2031
2276
  /**
2032
- * Returns whether the database has a lock for the given key.
2033
- *
2034
- * @param key - The key to check.
2035
- * @returns `true` if the database has a lock for the given key, `false`
2036
- * otherwise.
2037
- *
2038
- * @example
2039
- * ```typescript
2040
- * const db = RocksDatabase.open('/path/to/database');
2041
- * db.hasLock('foo'); // false
2042
- * db.tryLock('foo', () => {});
2043
- * db.hasLock('foo'); // true
2044
- * ```
2045
- */
2277
+ * Returns whether the database has a lock for the given key.
2278
+ *
2279
+ * @param key - The key to check.
2280
+ * @returns `true` if the database has a lock for the given key, `false`
2281
+ * otherwise.
2282
+ *
2283
+ * @example
2284
+ * ```typescript
2285
+ * const db = RocksDatabase.open('/path/to/database');
2286
+ * db.hasLock('foo'); // false
2287
+ * db.tryLock('foo', () => {});
2288
+ * db.hasLock('foo'); // true
2289
+ * ```
2290
+ */
2046
2291
  hasLock(key: Key): boolean;
2047
2292
  ifNoExists(_key: Key): Promise<void>;
2048
2293
  /**
2049
- * Checks the process-global verification table for a fresh version match
2050
- * on `key`. Returns `true` when the table currently records `version`. Use
2051
- * this as a fast cache-freshness check before falling back to a full read:
2052
- *
2053
- * ```typescript
2054
- * if (db.verifyVersion(key, cachedEntry.version)) {
2055
- * return cachedEntry.value;
2056
- * }
2057
- * const value = db.getSync(key);
2058
- * db.populateVersion(key, extractVersion(value));
2059
- * ```
2060
- */
2294
+ * Checks the process-global verification table for a fresh version match
2295
+ * on `key`. Returns `true` when the table currently records `version`. Use
2296
+ * this as a fast cache-freshness check before falling back to a full read:
2297
+ *
2298
+ * ```typescript
2299
+ * if (db.verifyVersion(key, cachedEntry.version)) {
2300
+ * return cachedEntry.value;
2301
+ * }
2302
+ * const value = db.getSync(key);
2303
+ * db.populateVersion(key, extractVersion(value));
2304
+ * ```
2305
+ */
2061
2306
  verifyVersion(key: Key, version: number): boolean;
2062
2307
  /**
2063
- * Seeds the verification-table slot for `key` with `version`. Has no
2064
- * effect if the slot is currently lock-tagged or if the verification
2065
- * table is disabled.
2066
- */
2308
+ * Seeds the verification-table slot for `key` with `version`. Has no
2309
+ * effect if the slot is currently lock-tagged or if the verification
2310
+ * table is disabled.
2311
+ */
2067
2312
  populateVersion(key: Key, version: number): void;
2068
2313
  /**
2069
- * Returns whether the database is open.
2070
- *
2071
- * @returns `true` if the database is open, `false` otherwise.
2072
- */
2314
+ * Returns whether the database is open.
2315
+ *
2316
+ * @returns `true` if the database is open, `false` otherwise.
2317
+ */
2073
2318
  isOpen(): boolean;
2074
2319
  /**
2075
- * Lists all transaction log names.
2076
- *
2077
- * @returns an array of transaction log names.
2078
- */
2320
+ * Lists all transaction log names.
2321
+ *
2322
+ * @returns an array of transaction log names.
2323
+ */
2079
2324
  listLogs(): string[];
2080
2325
  /**
2081
- * The name of the database.
2082
- */
2326
+ * The name of the database.
2327
+ */
2083
2328
  get name(): string;
2084
2329
  /**
2085
- * Whether the database is open in readonly mode.
2086
- */
2330
+ * Whether the database is open in readonly mode.
2331
+ */
2087
2332
  get readOnly(): boolean;
2088
2333
  /**
2089
- * Sugar method for opening a database.
2090
- *
2091
- * @param pathOrStore - The filesystem path to the database or a custom store.
2092
- * @param options - The options for the database.
2093
- * @returns A new RocksDatabase instance.
2094
- *
2095
- * @example
2096
- * ```typescript
2097
- * const db = RocksDatabase.open('/path/to/database');
2098
- * ```
2099
- */
2334
+ * Sugar method for opening a database.
2335
+ *
2336
+ * @param pathOrStore - The filesystem path to the database or a custom store.
2337
+ * @param options - The options for the database.
2338
+ * @returns A new RocksDatabase instance.
2339
+ *
2340
+ * @example
2341
+ * ```typescript
2342
+ * const db = RocksDatabase.open('/path/to/database');
2343
+ * ```
2344
+ */
2100
2345
  static open(pathOrStore: string | Store, options?: RocksDatabaseOptions): RocksDatabase;
2101
2346
  /**
2102
- * Opens the database. This function returns immediately if the database is
2103
- * already open.
2104
- *
2105
- * @returns A new RocksDatabase instance.
2106
- *
2107
- * @example
2108
- * ```typescript
2109
- * const db = new RocksDatabase('/path/to/database');
2110
- * db.open();
2111
- * ```
2112
- */
2347
+ * Opens the database. This function returns immediately if the database is
2348
+ * already open.
2349
+ *
2350
+ * @returns A new RocksDatabase instance.
2351
+ *
2352
+ * @example
2353
+ * ```typescript
2354
+ * const db = new RocksDatabase('/path/to/database');
2355
+ * db.open();
2356
+ * ```
2357
+ */
2113
2358
  open(): RocksDatabase;
2114
2359
  /**
2115
- * Returns the path to the database.
2116
- */
2360
+ * Returns the path to the database.
2361
+ */
2117
2362
  get path(): string;
2118
2363
  /**
2119
- * Purges transaction logs.
2120
- *
2121
- * By default returns the paths of the deleted log files. Pass
2122
- * `includeEntryCounts: true` to instead return, for each deleted file, its
2123
- * path and the number of entries it held (`{ path, entries }`).
2124
- */
2364
+ * Purges transaction logs.
2365
+ *
2366
+ * By default returns the paths of the deleted log files. Pass
2367
+ * `includeEntryCounts: true` to instead return, for each deleted file, its
2368
+ * path and the number of entries it held (`{ path, entries }`).
2369
+ */
2125
2370
  purgeLogs(options: PurgeLogsOptions & {
2126
2371
  includeEntryCounts: true;
2127
2372
  }): PurgedLog[];
@@ -2130,93 +2375,93 @@ declare class RocksDatabase extends DBI<DBITransactional> {
2130
2375
  }): string[];
2131
2376
  purgeLogs(options?: PurgeLogsOptions): string[] | PurgedLog[];
2132
2377
  /**
2133
- * The status of the database.
2134
- */
2378
+ * The status of the database.
2379
+ */
2135
2380
  get status(): "open" | "closed";
2136
2381
  /**
2137
- * Executes all operations in the callback as a single transaction.
2138
- *
2139
- * @param callback - A async function that receives the transaction as an argument.
2140
- * @returns A promise that resolves the `callback` return value.
2141
- *
2142
- * @example
2143
- * ```typescript
2144
- * const db = RocksDatabase.open('/path/to/database');
2145
- * await db.transaction(async (txn) => {
2146
- * await txn.put('key', 'value');
2147
- * });
2148
- * ```
2149
- */
2382
+ * Executes all operations in the callback as a single transaction.
2383
+ *
2384
+ * @param callback - A async function that receives the transaction as an argument.
2385
+ * @returns A promise that resolves the `callback` return value.
2386
+ *
2387
+ * @example
2388
+ * ```typescript
2389
+ * const db = RocksDatabase.open('/path/to/database');
2390
+ * await db.transaction(async (txn) => {
2391
+ * await txn.put('key', 'value');
2392
+ * });
2393
+ * ```
2394
+ */
2150
2395
  transaction<T>(callback: TransactionCallback<T>, options?: TransactionOptions): Promise<T | void>;
2151
2396
  /**
2152
- * Executes all operations in the callback as a single transaction.
2153
- *
2154
- * @param callback - A function that receives the transaction as an
2155
- * argument. If the callback return promise-like value, it is awaited
2156
- * before committing the transaction. Otherwise, the callback is treated as
2157
- * synchronous.
2158
- * @returns The `callback` return value.
2159
- *
2160
- * @example
2161
- * ```typescript
2162
- * const db = RocksDatabase.open('/path/to/database');
2163
- * await db.transaction(async (txn) => {
2164
- * await txn.put('key', 'value');
2165
- * });
2166
- * ```
2167
- */
2397
+ * Executes all operations in the callback as a single transaction.
2398
+ *
2399
+ * @param callback - A function that receives the transaction as an
2400
+ * argument. If the callback return promise-like value, it is awaited
2401
+ * before committing the transaction. Otherwise, the callback is treated as
2402
+ * synchronous.
2403
+ * @returns The `callback` return value.
2404
+ *
2405
+ * @example
2406
+ * ```typescript
2407
+ * const db = RocksDatabase.open('/path/to/database');
2408
+ * await db.transaction(async (txn) => {
2409
+ * await txn.put('key', 'value');
2410
+ * });
2411
+ * ```
2412
+ */
2168
2413
  transactionSync<T>(callback: TransactionCallback<T>, options?: TransactionOptions): T | PromiseLike<T> | void;
2169
2414
  /**
2170
- * Attempts to acquire a lock for a given key. If the lock is available,
2171
- * the function returns `true` and the optional callback is never called.
2172
- * If the lock is not available, the function returns `false` and the
2173
- * callback is queued until the lock is released.
2174
- *
2175
- * @param key - The key to lock.
2176
- * @param onUnlocked - A callback to call when the lock is released.
2177
- *
2178
- * @example
2179
- * ```typescript
2180
- * const db = RocksDatabase.open('/path/to/database');
2181
- * db.tryLock('foo', () => {
2182
- * console.log('lock acquired');
2183
- * });
2184
- * ```
2185
- * @returns `true` if the lock was acquired, `false` otherwise.
2186
- */
2415
+ * Attempts to acquire a lock for a given key. If the lock is available,
2416
+ * the function returns `true` and the optional callback is never called.
2417
+ * If the lock is not available, the function returns `false` and the
2418
+ * callback is queued until the lock is released.
2419
+ *
2420
+ * @param key - The key to lock.
2421
+ * @param onUnlocked - A callback to call when the lock is released.
2422
+ *
2423
+ * @example
2424
+ * ```typescript
2425
+ * const db = RocksDatabase.open('/path/to/database');
2426
+ * db.tryLock('foo', () => {
2427
+ * console.log('lock acquired');
2428
+ * });
2429
+ * ```
2430
+ * @returns `true` if the lock was acquired, `false` otherwise.
2431
+ */
2187
2432
  tryLock(key: Key, onUnlocked?: () => void): boolean;
2188
2433
  /**
2189
- * Releases the lock on the given key and calls any queued `onUnlocked`
2190
- * callback handlers.
2191
- *
2192
- * @param key - The key to unlock.
2193
- * @returns `true` if the lock was released or `false` if the lock did not
2194
- * exist.
2195
- *
2196
- * @example
2197
- * ```typescript
2198
- * const db = RocksDatabase.open('/path/to/database');
2199
- * db.tryLock('foo', () => {});
2200
- * db.unlock('foo'); // returns `true`
2201
- * db.unlock('foo'); // already unlocked, returns `false`
2202
- * ```
2203
- */
2434
+ * Releases the lock on the given key and calls any queued `onUnlocked`
2435
+ * callback handlers.
2436
+ *
2437
+ * @param key - The key to unlock.
2438
+ * @returns `true` if the lock was released or `false` if the lock did not
2439
+ * exist.
2440
+ *
2441
+ * @example
2442
+ * ```typescript
2443
+ * const db = RocksDatabase.open('/path/to/database');
2444
+ * db.tryLock('foo', () => {});
2445
+ * db.unlock('foo'); // returns `true`
2446
+ * db.unlock('foo'); // already unlocked, returns `false`
2447
+ * ```
2448
+ */
2204
2449
  unlock(key: Key): void;
2205
2450
  /**
2206
- * Excecutes a function using a thread-safe lock to ensure mutual
2207
- * exclusion.
2208
- *
2209
- * @param callback - A callback to call when the lock is acquired.
2210
- * @returns A promise that resolves when the lock is acquired.
2211
- *
2212
- * @example
2213
- * ```typescript
2214
- * const db = RocksDatabase.open('/path/to/database');
2215
- * await db.withLock(async (waited) => {
2216
- * console.log('lock acquired', waited);
2217
- * });
2218
- * ```
2219
- */
2451
+ * Excecutes a function using a thread-safe lock to ensure mutual
2452
+ * exclusion.
2453
+ *
2454
+ * @param callback - A callback to call when the lock is acquired.
2455
+ * @returns A promise that resolves when the lock is acquired.
2456
+ *
2457
+ * @example
2458
+ * ```typescript
2459
+ * const db = RocksDatabase.open('/path/to/database');
2460
+ * await db.withLock(async (waited) => {
2461
+ * console.log('lock acquired', waited);
2462
+ * });
2463
+ * ```
2464
+ */
2220
2465
  withLock(key: Key, callback: () => void | Promise<void>): Promise<void> | undefined;
2221
2466
  }
2222
2467
  //#endregion
@@ -2237,10 +2482,10 @@ interface TransactionLog$1 {
2237
2482
  version: number;
2238
2483
  }
2239
2484
  /**
2240
- * Loads an entire transaction log file into memory.
2241
- * @param path - The path to the transaction log file.
2242
- * @returns The transaction log.
2243
- */
2485
+ * Loads an entire transaction log file into memory.
2486
+ * @param path - The path to the transaction log file.
2487
+ * @returns The transaction log.
2488
+ */
2244
2489
  declare function parseTransactionLog(path: string, options?: {
2245
2490
  skipData?: boolean;
2246
2491
  }): TransactionLog$1;
@@ -2251,5 +2496,5 @@ declare const versions: {
2251
2496
  "rocksdb-js": string;
2252
2497
  };
2253
2498
  //#endregion
2254
- export { type BackupInfo, type BackupOptions, DBI, DBIterator, type GetStatsMethod, type IteratorOptions, type Key, type RestoreMode, type RestoreOptions, type RocksDBStat, type RocksDBStats, RocksDatabase, type RocksDatabaseOptions, type StatsAll, type StatsAllExtras, type StatsBasics, type StatsCurated, type StatsCuratedExtras, type StatsDefault, type StatsHistogramData, type StatsValue, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, type TransactionLogPosition, type TransactionLogStats, backups, constants, coolTransactionLogs, currentThreadId, parseTransactionLog, registryStatus, shutdown, stats, versions };
2499
+ export { type BackupInfo, type BackupOptions, type BackupStreamOptions, DBI, DBIterator, type GetStatsMethod, type IteratorOptions, type Key, type RestoreMode, type RestoreOptions, type RocksDBStat, type RocksDBStats, RocksDatabase, type RocksDatabaseOptions, type StatsAll, type StatsAllExtras, type StatsBasics, type StatsCurated, type StatsCuratedExtras, type StatsDefault, type StatsHistogramData, type StatsValue, Store, type StoreContext, type StoreGetOptions, type StoreIteratorOptions, type StorePutOptions, type StoreRangeOptions, type StoreRemoveOptions, Transaction, type TransactionEntry, TransactionLog, type TransactionLogFileValidation, type TransactionLogPosition, type TransactionLogStats, type TransactionLogStoreValidation, type ValidateTransactionLogStoreOptions, backups, constants, coolTransactionLogs, currentThreadId, fileLockRelease, parseTransactionLog, registryStatus, shutdown, stats, tryFileLock, validateTransactionLogStore, versions };
2255
2500
  //# sourceMappingURL=index.d.mts.map