@harperfast/rocksdb-js 2.2.0 → 2.4.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
@@ -9,6 +9,10 @@ import { ExtendedIterable } from "@harperfast/extended-iterable";
9
9
  * not scoped to an individual `Store`.
10
10
  */
11
11
  interface BackupOptions {
12
+ /**
13
+ * Include write-ahead log files in the backup. Defaults to `true`.
14
+ */
15
+ backupLogFiles?: boolean;
12
16
  /**
13
17
  * Flush the memtable before backing up. Defaults to `true` when the database
14
18
  * was opened with `disableWAL` (otherwise unflushed data would be lost from
@@ -16,32 +20,47 @@ interface BackupOptions {
16
20
  */
17
21
  flushBeforeBackup?: boolean;
18
22
  /**
23
+ * Number of background threads used to copy files. Defaults to `1`.
24
+ */
25
+ maxBackgroundOperations?: number;
26
+ /**
19
27
  * Arbitrary application metadata stored with the backup and returned by
20
28
  * `backups.list()`.
21
29
  */
22
30
  metadata?: string;
23
31
  /**
24
- * Share table/blob files between backups in the same directory to enable
25
- * incremental backups. Defaults to `true`.
26
- */
27
- shareTableFiles?: boolean;
28
- /**
29
32
  * Distinguish shared files by checksum to avoid collisions across databases.
30
33
  * Defaults to `true`. Only relevant when `shareTableFiles` is enabled.
31
34
  */
32
35
  shareFilesWithChecksum?: boolean;
33
36
  /**
34
- * Include write-ahead log files in the backup. Defaults to `true`.
37
+ * Share table/blob files between backups in the same directory to enable
38
+ * incremental backups. Defaults to `true`.
35
39
  */
36
- backupLogFiles?: boolean;
40
+ shareTableFiles?: boolean;
37
41
  /**
38
- * `fsync` backup files for crash consistency. Defaults to `true`.
42
+ * `fsync` backup files — including the transaction log snapshot when
43
+ * `transactionLogs` is enabled — for crash consistency. Defaults to `true`.
39
44
  */
40
45
  sync?: boolean;
41
46
  /**
42
- * Number of background threads used to copy files. Defaults to `1`.
47
+ * Snapshot the transaction log store into
48
+ * `<backupDir>/transaction_logs/<backupId>/`. Defaults to `false`. This is an
49
+ * all-or-nothing snapshot per backup (not incremental); `backups.delete()` and
50
+ * `backups.purge()` remove the corresponding log snapshots, and
51
+ * `backups.restore()` restores them into the database directory.
52
+ *
53
+ * The snapshot is staged and atomically renamed into place after every file
54
+ * is copied (and fsynced, per `sync`), so a crash mid-backup can never leave
55
+ * a partial snapshot: a backup id either has its complete log snapshot or
56
+ * none at all.
57
+ *
58
+ * The log snapshot is captured just after the RocksDB engine snapshot, so it
59
+ * may include entries committed between the two — the restored logs can run
60
+ * slightly ahead of the restored key-value data, never behind it. That bias
61
+ * is safe for redo-style logs that are replayed against the restored data.
43
62
  */
44
- maxBackgroundOperations?: number;
63
+ transactionLogs?: boolean;
45
64
  }
46
65
  /**
47
66
  * The level of incremental restore to perform.
@@ -165,1560 +184,1612 @@ type KeyEncoding = "binary" | "ordered-binary" | "uint32";
165
184
  type ReadKeyFunction<T> = (source: BufferWithDataView, start: number, end?: number) => T;
166
185
  type WriteKeyFunction = (key: Key, target: BufferWithDataView, start: number) => number;
167
186
  //#endregion
168
- //#region src/stats.d.ts
169
- /** Database-level RocksDB statistics types for `db.getStats()` / `db.getStat()`. */
170
- type StatsHistogramData = {
171
- average: number;
172
- count: number;
173
- max: number;
174
- median: number;
175
- min: number;
176
- percentile95: number;
177
- percentile99: number;
178
- standardDeviation: number;
179
- sum: number;
187
+ //#region src/dbi-iterator.d.ts
188
+ interface DBIteratorValue<T> {
189
+ key: Key;
190
+ value: T;
191
+ }
192
+ /**
193
+ * Wraps the `NativeIterator` C++ binding, decoding keys and values from the
194
+ * shared key/value buffers (fast path) or from per-iteration buffers (slow
195
+ * fallback path used for oversized data or stable-buffer decoders).
196
+ *
197
+ * The native `next()` returns a primitive signal (and writes lengths to the
198
+ * shared `ITERATOR_STATE` buffer) instead of constructing a JS result object,
199
+ * so this class is responsible for building the `IteratorResult`.
200
+ */
201
+ declare class DBIterator<T> implements Iterator<DBIteratorValue<T>> {
202
+ #private;
203
+ iterator: InstanceType<typeof NativeIteratorCls>;
204
+ store: Store;
205
+ constructor(iterator: InstanceType<typeof NativeIteratorCls>, store: Store, includeValues: boolean, limit?: number);
206
+ [Symbol.iterator](): Iterator<DBIteratorValue<T>>;
207
+ next(): IteratorResult<DBIteratorValue<T>>;
208
+ return(value?: any): IteratorResult<DBIteratorValue<T>, any>;
209
+ throw(err: unknown): IteratorResult<DBIteratorValue<T>, any>;
210
+ }
211
+ //#endregion
212
+ //#region src/store.d.ts
213
+ type StoreContext = NativeDatabase | NativeTransaction;
214
+ type StoreGetOptions = GetOptions & DBITransactional;
215
+ type StoreIteratorOptions = IteratorOptions & DBITransactional;
216
+ type StorePutOptions = PutOptions & DBITransactional;
217
+ type StoreRangeOptions = RangeOptions & DBITransactional;
218
+ type StoreRemoveOptions = DBITransactional | unknown;
219
+ type CompactOptions = {
220
+ start?: Key;
221
+ end?: Key;
180
222
  };
181
- type StatsBasics = {
182
- "rocksdb.num-immutable-mem-table": number;
183
- "rocksdb.num-immutable-mem-table-flushed": number;
184
- "rocksdb.mem-table-flush-pending": number;
185
- "rocksdb.cur-size-active-mem-table": number;
186
- "rocksdb.cur-size-all-mem-tables": number;
187
- "rocksdb.size-all-mem-tables": number;
188
- "rocksdb.num-entries-active-mem-table": number;
189
- "rocksdb.num-deletes-active-mem-table": number;
190
- "rocksdb.compaction-pending": number;
191
- "rocksdb.estimate-pending-compaction-bytes": number;
192
- "rocksdb.num-running-compactions": number;
193
- "rocksdb.num-running-flushes": number;
194
- "rocksdb.total-sst-files-size": number;
195
- "rocksdb.live-sst-files-size": number;
196
- "rocksdb.estimate-live-data-size": number;
197
- "rocksdb.estimate-num-keys": number;
198
- "rocksdb.block-cache-capacity": number;
199
- "rocksdb.block-cache-usage": number;
200
- "rocksdb.block-cache-pinned-usage": number;
201
- "rocksdb.num-live-versions": number;
202
- "rocksdb.current-super-version-number": number;
203
- "rocksdb.oldest-snapshot-time": number;
204
- "rocksdb.num-blob-files": number;
205
- "rocksdb.total-blob-file-size": number;
206
- "rocksdb.live-blob-file-size": number;
207
- "txnlog.logCount": number;
208
- "txnlog.fileCount": number;
209
- "txnlog.totalSizeBytes": number;
210
- "txnlog.mappedBytes": number;
211
- "txnlog.overlayBytes": number;
212
- "txnlog.activeMaps": number;
213
- "txnlog.pendingTransactions": number;
214
- "txnlog.uncommittedTransactions": number;
215
- "txnlog.transactionsWritten": number;
216
- "txnlog.bytesWritten": number;
217
- "txnlog.replayGapBytes": number;
223
+ /**
224
+ * Options for the `Store` class.
225
+ */
226
+ interface StoreOptions extends Omit<NativeDatabaseOptions, "mode" | "transactionLogRetentionMs"> {
227
+ decoder?: Encoder | null;
228
+ encoder?: Encoder | null;
229
+ encoding?: Encoding;
230
+ freezeData?: boolean;
231
+ keyEncoder?: {
232
+ readKey?: ReadKeyFunction<Key>;
233
+ writeKey?: WriteKeyFunction;
234
+ };
235
+ keyEncoding?: KeyEncoding;
236
+ maxKeySize?: number;
237
+ pessimistic?: boolean;
238
+ /**
239
+ * If `true`, the encoder will use a random access structure.
240
+ */
241
+ randomAccessStructure?: boolean;
242
+ /**
243
+ * When `true`, the database is opened in read-only mode. Write operations
244
+ * will throw an error with code `ERR_DATABASE_READONLY`.
245
+ */
246
+ readOnly?: boolean;
247
+ sharedStructuresKey?: symbol;
248
+ /**
249
+ * A string containing the amount of time or the number of milliseconds to
250
+ * retain transaction logs before purging.
251
+ *
252
+ * @default '3d' (3 days)
253
+ */
254
+ transactionLogRetention?: number | string;
255
+ }
256
+ /**
257
+ * Options for the `getUserSharedBuffer()` method.
258
+ */
259
+ type UserSharedBufferOptions = {
260
+ callback?: UserSharedBufferCallback;
218
261
  };
219
- type StatsCuratedExtras = {
220
- "rocksdb.block.cache.hit": number;
221
- "rocksdb.block.cache.miss": number;
222
- "rocksdb.block.cache.data.hit": number;
223
- "rocksdb.block.cache.data.miss": number;
224
- "rocksdb.block.cache.index.hit": number;
225
- "rocksdb.block.cache.index.miss": number;
226
- "rocksdb.block.cache.filter.hit": number;
227
- "rocksdb.block.cache.filter.miss": number;
228
- "rocksdb.bloom.filter.useful": number;
229
- "rocksdb.bloom.filter.full.positive": number;
230
- "rocksdb.bloom.filter.full.true.positive": number;
231
- "rocksdb.db.iter.bytes.read": number;
232
- "rocksdb.number.reseeks.iteration": number;
233
- "rocksdb.number.keys.read": number;
234
- "rocksdb.number.keys.written": number;
235
- "rocksdb.bytes.read": number;
236
- "rocksdb.bytes.written": number;
237
- "rocksdb.memtable.hit": number;
238
- "rocksdb.memtable.miss": number;
239
- "rocksdb.txn.overhead.mutex.prepare": number;
240
- "rocksdb.txn.overhead.mutex.old.commit.map": number;
241
- "rocksdb.txn.overhead.mutex.snapshot": number;
242
- "rocksdb.compact.read.bytes": number;
243
- "rocksdb.compact.write.bytes": number;
244
- "rocksdb.compaction.cancelled": number;
245
- "rocksdb.stall.micros": number;
246
- "rocksdb.no.file.errors": number;
247
- "rocksdb.read.amp.estimate.useful.bytes": number;
248
- "rocksdb.read.amp.total.read.bytes": number;
249
- "rocksdb.db.get.micros": StatsHistogramData;
250
- "rocksdb.db.write.micros": StatsHistogramData;
251
- "rocksdb.db.seek.micros": StatsHistogramData;
252
- "rocksdb.db.flush.micros": StatsHistogramData;
253
- "rocksdb.db.write.stall": StatsHistogramData;
254
- "rocksdb.blobdb.value.size": StatsHistogramData;
255
- "rocksdb.sst.read.micros": StatsHistogramData;
256
- "rocksdb.compaction.times.micros": StatsHistogramData;
262
+ /**
263
+ * The return type of `getUserSharedBuffer()`.
264
+ */
265
+ type ArrayBufferWithNotify = ArrayBuffer & {
266
+ cancel: () => void;
267
+ notify: () => void;
257
268
  };
258
- type StatsAllExtras = {
259
- "rocksdb.block.cache.add": number;
260
- "rocksdb.block.cache.add.failures": number;
261
- "rocksdb.block.cache.index.add": number;
262
- "rocksdb.block.cache.index.bytes.insert": number;
263
- "rocksdb.block.cache.filter.add": number;
264
- "rocksdb.block.cache.filter.bytes.insert": number;
265
- "rocksdb.block.cache.data.add": number;
266
- "rocksdb.block.cache.data.bytes.insert": number;
267
- "rocksdb.block.cache.bytes.read": number;
268
- "rocksdb.block.cache.bytes.write": number;
269
- "rocksdb.block.cache.compression.dict.miss": number;
270
- "rocksdb.block.cache.compression.dict.hit": number;
271
- "rocksdb.block.cache.compression.dict.add": number;
272
- "rocksdb.block.cache.compression.dict.bytes.insert": number;
273
- "rocksdb.block.cache.add.redundant": number;
274
- "rocksdb.block.cache.index.add.redundant": number;
275
- "rocksdb.block.cache.filter.add.redundant": number;
276
- "rocksdb.block.cache.data.add.redundant": number;
277
- "rocksdb.block.cache.compression.dict.add.redundant": number;
278
- "rocksdb.secondary.cache.hits": number;
279
- "rocksdb.secondary.cache.filter.hits": number;
280
- "rocksdb.secondary.cache.index.hits": number;
281
- "rocksdb.secondary.cache.data.hits": number;
282
- "rocksdb.compressed.secondary.cache.dummy.hits": number;
283
- "rocksdb.compressed.secondary.cache.hits": number;
284
- "rocksdb.compressed.secondary.cache.promotions": number;
285
- "rocksdb.compressed.secondary.cache.promotion.skips": number;
286
- "rocksdb.bloom.filter.prefix.checked": number;
287
- "rocksdb.bloom.filter.prefix.useful": number;
288
- "rocksdb.bloom.filter.prefix.true.positive": number;
289
- "rocksdb.persistent.cache.hit": number;
290
- "rocksdb.persistent.cache.miss": number;
291
- "rocksdb.sim.block.cache.hit": number;
292
- "rocksdb.sim.block.cache.miss": number;
293
- "rocksdb.l0.hit": number;
294
- "rocksdb.l1.hit": number;
295
- "rocksdb.l2andup.hit": number;
296
- "rocksdb.compaction.key.drop.new": number;
297
- "rocksdb.compaction.key.drop.obsolete": number;
298
- "rocksdb.compaction.key.drop.range_del": number;
299
- "rocksdb.compaction.key.drop.user": number;
300
- "rocksdb.compaction.range_del.drop.obsolete": number;
301
- "rocksdb.compaction.optimized.del.drop.obsolete": number;
302
- "rocksdb.compaction.aborted": number;
303
- "rocksdb.number.keys.updated": number;
304
- "rocksdb.number.db.seek": number;
305
- "rocksdb.number.db.next": number;
306
- "rocksdb.number.db.prev": number;
307
- "rocksdb.number.db.seek.found": number;
308
- "rocksdb.number.db.next.found": number;
309
- "rocksdb.number.db.prev.found": number;
310
- "rocksdb.number.iter.skip": number;
311
- "rocksdb.num.iterator.created": number;
312
- "rocksdb.num.iterator.deleted": number;
313
- "rocksdb.no.file.opens": number;
314
- "rocksdb.db.mutex.wait.micros": number;
315
- "rocksdb.number.multiget.get": number;
316
- "rocksdb.number.multiget.keys.read": number;
317
- "rocksdb.number.multiget.bytes.read": number;
318
- "rocksdb.number.multiget.keys.found": number;
319
- "rocksdb.number.merge.failures": number;
320
- "rocksdb.getupdatessince.calls": number;
321
- "rocksdb.wal.synced": number;
322
- "rocksdb.wal.bytes": number;
323
- "rocksdb.write.self": number;
324
- "rocksdb.write.other": number;
325
- "rocksdb.write.wal": number;
326
- "rocksdb.flush.write.bytes": number;
327
- "rocksdb.compact.read.marked.bytes": number;
328
- "rocksdb.compact.read.periodic.bytes": number;
329
- "rocksdb.compact.read.ttl.bytes": number;
330
- "rocksdb.compact.write.marked.bytes": number;
331
- "rocksdb.compact.write.periodic.bytes": number;
332
- "rocksdb.compact.write.ttl.bytes": number;
333
- "rocksdb.number.direct.load.table.properties": number;
334
- "rocksdb.number.superversion_acquires": number;
335
- "rocksdb.number.superversion_releases": number;
336
- "rocksdb.number.superversion_cleanups": number;
337
- "rocksdb.number.block.compressed": number;
338
- "rocksdb.number.block.decompressed": number;
339
- "rocksdb.bytes.compressed.from": number;
340
- "rocksdb.bytes.compressed.to": number;
341
- "rocksdb.bytes.compression_bypassed": number;
342
- "rocksdb.bytes.compression.rejected": number;
343
- "rocksdb.number.block_compression_bypassed": number;
344
- "rocksdb.number.block_compression_rejected": number;
345
- "rocksdb.bytes.decompressed.from": number;
346
- "rocksdb.bytes.decompressed.to": number;
347
- "rocksdb.merge.operation.time.nanos": number;
348
- "rocksdb.filter.operation.time.nanos": number;
349
- "rocksdb.compaction.total.time.cpu_micros": number;
350
- "rocksdb.row.cache.hit": number;
351
- "rocksdb.row.cache.miss": number;
352
- "rocksdb.number.rate_limiter.drains": number;
353
- "rocksdb.blobdb.num.put": number;
354
- "rocksdb.blobdb.num.write": number;
355
- "rocksdb.blobdb.num.get": number;
356
- "rocksdb.blobdb.num.multiget": number;
357
- "rocksdb.blobdb.num.seek": number;
358
- "rocksdb.blobdb.num.next": number;
359
- "rocksdb.blobdb.num.prev": number;
360
- "rocksdb.blobdb.num.keys.written": number;
361
- "rocksdb.blobdb.num.keys.read": number;
362
- "rocksdb.blobdb.bytes.written": number;
363
- "rocksdb.blobdb.bytes.read": number;
364
- "rocksdb.blobdb.write.inlined": number;
365
- "rocksdb.blobdb.write.inlined.ttl": number;
366
- "rocksdb.blobdb.write.blob": number;
367
- "rocksdb.blobdb.write.blob.ttl": number;
368
- "rocksdb.blobdb.blob.file.bytes.written": number;
369
- "rocksdb.blobdb.blob.file.bytes.read": number;
370
- "rocksdb.blobdb.blob.file.synced": number;
371
- "rocksdb.blobdb.blob.index.expired.count": number;
372
- "rocksdb.blobdb.blob.index.expired.size": number;
373
- "rocksdb.blobdb.blob.index.evicted.count": number;
374
- "rocksdb.blobdb.blob.index.evicted.size": number;
375
- "rocksdb.blobdb.gc.num.files": number;
376
- "rocksdb.blobdb.gc.num.new.files": number;
377
- "rocksdb.blobdb.gc.failures": number;
378
- "rocksdb.blobdb.gc.num.keys.relocated": number;
379
- "rocksdb.blobdb.gc.bytes.relocated": number;
380
- "rocksdb.blobdb.fifo.num.files.evicted": number;
381
- "rocksdb.blobdb.fifo.num.keys.evicted": number;
382
- "rocksdb.blobdb.fifo.bytes.evicted": number;
383
- "rocksdb.blobdb.cache.miss": number;
384
- "rocksdb.blobdb.cache.hit": number;
385
- "rocksdb.blobdb.cache.add": number;
386
- "rocksdb.blobdb.cache.add.failures": number;
387
- "rocksdb.blobdb.cache.bytes.read": number;
388
- "rocksdb.blobdb.cache.bytes.write": number;
389
- "rocksdb.txn.overhead.duplicate.key": number;
390
- "rocksdb.txn.get.tryagain": number;
391
- "rocksdb.files.marked.trash": number;
392
- "rocksdb.files.marked.trash.deleted": number;
393
- "rocksdb.files.deleted.immediately": number;
394
- "rocksdb.error.handler.bg.error.count": number;
395
- "rocksdb.error.handler.bg.io.error.count": number;
396
- "rocksdb.error.handler.bg.retryable.io.error.count": number;
397
- "rocksdb.error.handler.autoresume.count": number;
398
- "rocksdb.error.handler.autoresume.retry.total.count": number;
399
- "rocksdb.error.handler.autoresume.success.count": number;
400
- "rocksdb.memtable.payload.bytes.at.flush": number;
401
- "rocksdb.memtable.garbage.bytes.at.flush": number;
402
- "rocksdb.verify_checksum.read.bytes": number;
403
- "rocksdb.backup.read.bytes": number;
404
- "rocksdb.backup.write.bytes": number;
405
- "rocksdb.remote.compact.read.bytes": number;
406
- "rocksdb.remote.compact.write.bytes": number;
407
- "rocksdb.remote.compact.resumed.bytes": number;
408
- "rocksdb.hot.file.read.bytes": number;
409
- "rocksdb.warm.file.read.bytes": number;
410
- "rocksdb.cool.file.read.bytes": number;
411
- "rocksdb.cold.file.read.bytes": number;
412
- "rocksdb.ice.file.read.bytes": number;
413
- "rocksdb.hot.file.read.count": number;
414
- "rocksdb.warm.file.read.count": number;
415
- "rocksdb.cool.file.read.count": number;
416
- "rocksdb.cold.file.read.count": number;
417
- "rocksdb.ice.file.read.count": number;
418
- "rocksdb.last.level.read.bytes": number;
419
- "rocksdb.last.level.read.count": number;
420
- "rocksdb.non.last.level.read.bytes": number;
421
- "rocksdb.non.last.level.read.count": number;
422
- "rocksdb.last.level.seek.filtered": number;
423
- "rocksdb.last.level.seek.filter.match": number;
424
- "rocksdb.last.level.seek.data": number;
425
- "rocksdb.last.level.seek.data.useful.no.filter": number;
426
- "rocksdb.last.level.seek.data.useful.filter.match": number;
427
- "rocksdb.non.last.level.seek.filtered": number;
428
- "rocksdb.non.last.level.seek.filter.match": number;
429
- "rocksdb.non.last.level.seek.data": number;
430
- "rocksdb.non.last.level.seek.data.useful.no.filter": number;
431
- "rocksdb.non.last.level.seek.data.useful.filter.match": number;
432
- "rocksdb.block.checksum.compute.count": number;
433
- "rocksdb.block.checksum.mismatch.count": number;
434
- "rocksdb.multiget.coroutine.count": number;
435
- "rocksdb.read.async.micros": number;
436
- "rocksdb.async.read.error.count": number;
437
- "rocksdb.table.open.prefetch.tail.miss": number;
438
- "rocksdb.table.open.prefetch.tail.hit": number;
439
- "rocksdb.timestamp.filter.table.checked": number;
440
- "rocksdb.timestamp.filter.table.filtered": number;
441
- "rocksdb.readahead.trimmed": number;
442
- "rocksdb.fifo.max.size.compactions": number;
443
- "rocksdb.fifo.ttl.compactions": number;
444
- "rocksdb.fifo.change_temperature.compactions": number;
445
- "rocksdb.prefetch.bytes": number;
446
- "rocksdb.prefetch.bytes.useful": number;
447
- "rocksdb.prefetch.hits": number;
448
- "rocksdb.footer.corruption.count": number;
449
- "rocksdb.file.read.corruption.retry.count": number;
450
- "rocksdb.file.read.corruption.retry.success.count": number;
451
- "rocksdb.number.wbwi.ingest": number;
452
- "rocksdb.sst.user.defined.index.load.fail.count": number;
453
- "rocksdb.multiscan.prepare.calls": number;
454
- "rocksdb.multiscan.prepare.errors": number;
455
- "rocksdb.multiscan.blocks.prefetched": number;
456
- "rocksdb.multiscan.blocks.from.cache": number;
457
- "rocksdb.multiscan.prefetch.bytes": number;
458
- "rocksdb.multiscan.prefetch.blocks.wasted": number;
459
- "rocksdb.multiscan.io.requests": number;
460
- "rocksdb.multiscan.io.coalesced.nonadjacent": number;
461
- "rocksdb.multiscan.seek.errors": number;
462
- "rocksdb.prefetch.memory.bytes.granted": number;
463
- "rocksdb.prefetch.memory.bytes.released": number;
464
- "rocksdb.prefetch.memory.requests.blocked": number;
465
- "rocksdb.compaction.times.cpu_micros": StatsHistogramData;
466
- "rocksdb.subcompaction.setup.times.micros": StatsHistogramData;
467
- "rocksdb.table.sync.micros": StatsHistogramData;
468
- "rocksdb.compaction.outfile.sync.micros": StatsHistogramData;
469
- "rocksdb.wal.file.sync.micros": StatsHistogramData;
470
- "rocksdb.manifest.file.sync.micros": StatsHistogramData;
471
- "rocksdb.table.open.io.micros": StatsHistogramData;
472
- "rocksdb.db.multiget.micros": StatsHistogramData;
473
- "rocksdb.read.block.compaction.micros": StatsHistogramData;
474
- "rocksdb.read.block.get.micros": StatsHistogramData;
475
- "rocksdb.write.raw.block.micros": StatsHistogramData;
476
- "rocksdb.numfiles.in.singlecompaction": StatsHistogramData;
477
- "rocksdb.file.read.flush.micros": StatsHistogramData;
478
- "rocksdb.file.read.compaction.micros": StatsHistogramData;
479
- "rocksdb.file.read.db.open.micros": StatsHistogramData;
480
- "rocksdb.file.read.get.micros": StatsHistogramData;
481
- "rocksdb.file.read.multiget.micros": StatsHistogramData;
482
- "rocksdb.file.read.db.iterator.micros": StatsHistogramData;
483
- "rocksdb.file.read.verify.db.checksum.micros": StatsHistogramData;
484
- "rocksdb.file.read.verify.file.checksums.micros": StatsHistogramData;
485
- "rocksdb.sst.write.micros": StatsHistogramData;
486
- "rocksdb.file.write.flush.micros": StatsHistogramData;
487
- "rocksdb.file.write.compaction.micros": StatsHistogramData;
488
- "rocksdb.file.write.db.open.micros": StatsHistogramData;
489
- "rocksdb.num.subcompactions.scheduled": StatsHistogramData;
490
- "rocksdb.bytes.per.read": StatsHistogramData;
491
- "rocksdb.bytes.per.write": StatsHistogramData;
492
- "rocksdb.bytes.per.multiget": StatsHistogramData;
493
- "rocksdb.compression.times.nanos": StatsHistogramData;
494
- "rocksdb.decompression.times.nanos": StatsHistogramData;
495
- "rocksdb.read.num.merge_operands": StatsHistogramData;
496
- "rocksdb.blobdb.key.size": StatsHistogramData;
497
- "rocksdb.blobdb.write.micros": StatsHistogramData;
498
- "rocksdb.blobdb.get.micros": StatsHistogramData;
499
- "rocksdb.blobdb.multiget.micros": StatsHistogramData;
500
- "rocksdb.blobdb.seek.micros": StatsHistogramData;
501
- "rocksdb.blobdb.next.micros": StatsHistogramData;
502
- "rocksdb.blobdb.prev.micros": StatsHistogramData;
503
- "rocksdb.blobdb.blob.file.write.micros": StatsHistogramData;
504
- "rocksdb.blobdb.blob.file.read.micros": StatsHistogramData;
505
- "rocksdb.blobdb.blob.file.sync.micros": StatsHistogramData;
506
- "rocksdb.blobdb.compression.micros": StatsHistogramData;
507
- "rocksdb.blobdb.decompression.micros": StatsHistogramData;
508
- "rocksdb.sst.batch.size": StatsHistogramData;
509
- "rocksdb.multiget.io.batch.size": StatsHistogramData;
510
- "rocksdb.num.index.and.filter.blocks.read.per.level": StatsHistogramData;
511
- "rocksdb.num.sst.read.per.level": StatsHistogramData;
512
- "rocksdb.num.level.read.per.multiget": StatsHistogramData;
513
- "rocksdb.error.handler.autoresume.retry.count": StatsHistogramData;
514
- "rocksdb.async.read.bytes": StatsHistogramData;
515
- "rocksdb.poll.wait.micros": StatsHistogramData;
516
- "rocksdb.compaction.prefetch.bytes": StatsHistogramData;
517
- "rocksdb.prefetched.bytes.discarded": StatsHistogramData;
518
- "rocksdb.async.prefetch.abort.micros": StatsHistogramData;
519
- "rocksdb.table.open.prefetch.tail.read.bytes": StatsHistogramData;
520
- "rocksdb.num.op.per.transaction": StatsHistogramData;
521
- "rocksdb.multiscan.op.prepare.iterators.micros": StatsHistogramData;
522
- "rocksdb.multiscan.prepare.micros": StatsHistogramData;
523
- "rocksdb.multiscan.blocks.per.prepare": StatsHistogramData;
524
- "rocksdb.block.key.distribution.cv": StatsHistogramData;
525
- };
526
- type StatsCurated = StatsBasics & StatsCuratedExtras;
527
- type StatsAll = StatsCurated & StatsAllExtras;
528
- type StatsValue = number | StatsHistogramData;
529
- /** Returned by `getStats()` when `all` is omitted or `false`. Curated keys require `enableStats: true`. */
530
- type StatsDefault = StatsBasics | StatsCurated;
531
- interface GetStatsMethod {
532
- getStats(all?: false): StatsDefault;
533
- getStats(all: true): StatsAll;
534
- }
535
- //#endregion
536
- //#region src/dbi-iterator.d.ts
537
- interface DBIteratorValue<T> {
538
- key: Key;
539
- value: T;
540
- }
541
269
  /**
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).
270
+ * A store wraps the `NativeDatabase` binding and database settings so that a
271
+ * single database instance can be shared between the main `RocksDatabase`
272
+ * instance and the `Transaction` instance.
545
273
  *
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.
274
+ * This store should not be shared between `RocksDatabase` instances.
574
275
  */
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;
276
+ declare class Store {
277
+ /**
278
+ * The database instance.
279
+ */
280
+ db: NativeDatabase;
281
+ /**
282
+ * The decoder instance. This is commonly the same as the `encoder`
283
+ * instance.
284
+ */
285
+ decoder: Encoder | null;
286
+ /**
287
+ * Whether the decoder copies the buffer when encoding values.
288
+ */
289
+ decoderCopies: boolean;
290
+ /**
291
+ * Whether to disable the write ahead log.
292
+ */
293
+ disableWAL: boolean;
294
+ /**
295
+ * Whether to enable RocksDB statistics.
296
+ */
297
+ enableStats: boolean;
298
+ /**
299
+ * Reusable buffer for encoding values using `writeKey()` when the custom
300
+ * encoder does not provide a `encode()` method.
301
+ */
302
+ encodeBuffer: BufferWithDataView;
303
+ /**
304
+ * The encoder instance.
305
+ */
306
+ encoder: Encoder | null;
307
+ /**
308
+ * The encoding used to encode values. Defaults to `'msgpack'` in
309
+ * `RocksDatabase.open()`.
310
+ */
311
+ encoding: Encoding | null;
312
+ /**
313
+ * Encoder specific option used to signal that the data should be frozen.
314
+ */
315
+ freezeData: boolean;
316
+ /**
317
+ * Reusable buffer for encoding keys.
318
+ */
319
+ keyBuffer: BufferWithDataView;
320
+ /**
321
+ * The key encoding to use for keys. Defaults to `'ordered-binary'`.
322
+ */
323
+ keyEncoding: KeyEncoding;
324
+ /**
325
+ * The maximum key size.
326
+ */
327
+ maxKeySize: number;
328
+ /**
329
+ * The maximum number of memtables that can be queued per column family
330
+ * before writes stall. Higher values absorb write bursts while flushes catch
331
+ * up, at the cost of memory.
332
+ */
333
+ maxWriteBufferNumber?: number;
334
+ /**
335
+ * The bytes of recent memtable history to retain in memory for transaction
336
+ * conflict checking. `-1` derives the value from
337
+ * `maxWriteBufferNumber * writeBufferSize`.
338
+ */
339
+ maxWriteBufferSizeToMaintain?: number;
340
+ /**
341
+ * The total memtable budget in bytes across all column families. When the
342
+ * sum of memtables reaches this size, RocksDB flushes the largest one. `0`
343
+ * disables the global trigger so per-CF `writeBufferSize` drives flushing.
344
+ */
345
+ dbWriteBufferSize?: number;
346
+ /**
347
+ * The name of the store (e.g. the column family). Defaults to `'default'`.
348
+ */
349
+ name: string;
350
+ /**
351
+ * Whether to disable the block cache.
352
+ */
353
+ noBlockCache?: boolean;
354
+ /**
355
+ * The number of threads to use for parallel operations. This is a RocksDB
356
+ * option. When undefined, the native layer picks
357
+ * `max(1, hardware_concurrency() / 2)`.
358
+ */
359
+ parallelismThreads?: number;
360
+ /**
361
+ * The path to the database.
362
+ */
363
+ path: string;
364
+ /**
365
+ * Whether to use pessimistic locking for transactions. When `true`,
366
+ * transactions will fail as soon as a conflict is detected. When `false`,
367
+ * transactions will only fail when `commit()` is called.
368
+ */
369
+ pessimistic: boolean;
370
+ /**
371
+ * Whether the database is open in readonly mode. When `true`, write
372
+ * operations will throw an error with code `ERR_DATABASE_READONLY`.
373
+ */
374
+ readOnly: boolean;
375
+ /**
376
+ * Encoder specific flag used to signal that the encoder should use a random
377
+ * access structure.
378
+ */
379
+ randomAccessStructure: boolean;
380
+ /**
381
+ * The function used to encode keys.
382
+ */
383
+ readKey: ReadKeyFunction<Key>;
384
+ /**
385
+ * The key used to store shared structures.
386
+ */
387
+ sharedStructuresKey?: symbol;
388
+ /**
389
+ * The level of statistics to capture.
390
+ */
391
+ statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
392
+ /**
393
+ * The threshold for the transaction log file's last modified time to be
394
+ * older than the retention period before it is rotated to the next sequence
395
+ * number. A threshold of 0 means ignore age check.
396
+ */
397
+ transactionLogMaxAgeThreshold?: number;
398
+ /**
399
+ * The maximum size of a transaction log before it is rotated to the next
400
+ * sequence number.
401
+ */
402
+ transactionLogMaxSize?: number;
403
+ /**
404
+ * A string containing the amount of time or the number of milliseconds to
405
+ * retain transaction logs before purging.
406
+ *
407
+ * @default '3d' (3 days)
408
+ */
409
+ transactionLogRetention?: number | string;
410
+ /**
411
+ * The path to the transaction logs directory.
412
+ */
413
+ transactionLogsPath?: string;
414
+ /**
415
+ * Whether this store's column family participates in the VerificationTable.
416
+ */
417
+ verificationTable?: boolean;
418
+ /**
419
+ * The per-column-family memtable size in bytes at which the memtable is
420
+ * sealed and flushed.
421
+ */
422
+ writeBufferSize?: number;
423
+ /**
424
+ * The function used to encode keys using the shared `keyBuffer`.
425
+ */
426
+ writeKey: WriteKeyFunction;
427
+ /**
428
+ * Initializes the store with a new `NativeDatabase` instance.
429
+ *
430
+ * @param path - The path to the database.
431
+ * @param options - The options for the store.
432
+ */
433
+ constructor(path: string, options?: StoreOptions);
434
+ /**
435
+ * Closes the database.
436
+ */
437
+ close(): void;
438
+ /**
439
+ * Compacts the entire key range of the database asynchronously.
440
+ * This triggers manual compaction which removes tombstones and reclaims space.
441
+ *
442
+ * @example
443
+ * ```typescript
444
+ * const db = RocksDatabase.open('/path/to/database');
445
+ * await db.compact();
446
+ * ```
447
+ */
448
+ compact(options?: CompactOptions): Promise<void>;
449
+ /**
450
+ * Creates a backup of the entire database (all column families) into the
451
+ * given directory and resolves with the new backup id. Parent directories
452
+ * are created as needed. See `backups` for restore and management.
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * const id = await db.backup('/path/to/backups');
457
+ * ```
458
+ */
459
+ backup(backupDir: string, options?: BackupOptions): Promise<number>;
460
+ backup(stream: WritableStream<Uint8Array>, options?: BackupStreamOptions): Promise<void>;
461
+ /**
462
+ * Compacts the entire key range of the database synchronously.
463
+ * This triggers manual compaction which removes tombstones and reclaims space.
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const db = RocksDatabase.open('/path/to/database');
468
+ * db.compactSync();
469
+ * ```
470
+ */
471
+ compactSync(options?: CompactOptions): void;
472
+ /**
473
+ * Decodes a key from the database.
474
+ *
475
+ * @param key - The key to decode.
476
+ * @returns The decoded key.
477
+ */
478
+ decodeKey(key: Buffer): Key;
587
479
  /**
588
- * If `true`, the encoder will use a random access structure.
480
+ * Decodes a value from the database.
481
+ *
482
+ * @param value - The value to decode.
483
+ * @returns The decoded value.
589
484
  */
590
- randomAccessStructure?: boolean;
485
+ decodeValue(value: BufferWithDataView): any;
591
486
  /**
592
- * When `true`, the database is opened in read-only mode. Write operations
593
- * will throw an error with code `ERR_DATABASE_READONLY`.
487
+ * Encodes a key for the database.
488
+ *
489
+ * @param key - The key to encode.
490
+ * @returns The encoded key.
594
491
  */
595
- readOnly?: boolean;
596
- sharedStructuresKey?: symbol;
492
+ encodeKey(key: Key): BufferWithDataView;
597
493
  /**
598
- * A string containing the amount of time or the number of milliseconds to
599
- * retain transaction logs before purging.
494
+ * Encodes a value for the database.
600
495
  *
601
- * @default '3d' (3 days)
496
+ * @param value - The value to encode.
497
+ * @returns The encoded value.
602
498
  */
603
- transactionLogRetention?: number | string;
604
- }
605
- /**
606
- * Options for the `getUserSharedBuffer()` method.
607
- */
608
- type UserSharedBufferOptions = {
609
- callback?: UserSharedBufferCallback;
610
- };
611
- /**
612
- * The return type of `getUserSharedBuffer()`.
613
- */
614
- type ArrayBufferWithNotify = ArrayBuffer & {
615
- cancel: () => void;
616
- notify: () => void;
617
- };
618
- /**
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 {
499
+ encodeValue(value: any): BufferWithDataView | Uint8Array;
500
+ get(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
501
+ getCount(context: StoreContext, options?: StoreRangeOptions): number;
502
+ getKeys(context: StoreContext, options?: StoreIteratorOptions): any | undefined;
503
+ getKeysCount(context: StoreContext, options?: StoreRangeOptions): number;
504
+ getRange(context: StoreContext, options?: StoreIteratorOptions): ExtendedIterable<DBIteratorValue<any>>;
505
+ getSync(context: StoreContext, key: Key, alwaysCreateNewBuffer?: boolean, options?: StoreGetOptions): any | undefined;
626
506
  /**
627
- * The database instance.
507
+ * Checks if the data method options object contains a transaction ID and
508
+ * returns it.
628
509
  */
629
- db: NativeDatabase;
510
+ getTxnId(options?: DBITransactional | unknown): number | undefined;
630
511
  /**
631
- * The decoder instance. This is commonly the same as the `encoder`
632
- * instance.
512
+ * Gets or creates a buffer that can be shared across worker threads.
513
+ *
514
+ * @param key - The key to get or create the buffer for.
515
+ * @param defaultBuffer - The default buffer to copy and use if the buffer
516
+ * does not exist.
517
+ * @param [options] - The options for the buffer.
518
+ * @param [options.callback] - A optional callback is called when `notify()`
519
+ * on the returned buffer is called.
520
+ * @returns An `ArrayBuffer` that is internally backed by a rocksdb-js
521
+ * managed buffer. The buffer also has `notify()` and `cancel()` methods
522
+ * that can be used to notify the specified `options.callback`.
633
523
  */
634
- decoder: Encoder | null;
524
+ getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
635
525
  /**
636
- * Whether the decoder copies the buffer when encoding values.
526
+ * Checks if a lock exists.
527
+ * @param key The lock key.
528
+ * @returns `true` if the lock exists, `false` otherwise
637
529
  */
638
- decoderCopies: boolean;
530
+ hasLock(key: Key): boolean;
639
531
  /**
640
- * Whether to disable the write ahead log.
532
+ * Checks if the database is open.
533
+ *
534
+ * @returns `true` if the database is open, `false` otherwise.
641
535
  */
642
- disableWAL: boolean;
536
+ isOpen(): boolean;
643
537
  /**
644
- * Whether to enable RocksDB statistics.
538
+ * Lists all transaction log names.
539
+ *
540
+ * @returns an array of transaction log names.
645
541
  */
646
- enableStats: boolean;
542
+ listLogs(): string[];
647
543
  /**
648
- * Reusable buffer for encoding values using `writeKey()` when the custom
649
- * encoder does not provide a `encode()` method.
544
+ * Opens the database. This must be called before any database operations
545
+ * are performed.
650
546
  */
651
- encodeBuffer: BufferWithDataView;
547
+ open(): boolean;
548
+ putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
549
+ removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
652
550
  /**
653
- * The encoder instance.
551
+ * Attempts to acquire a lock for a given key. If the lock is available,
552
+ * the function returns `true` and the optional callback is never called.
553
+ * If the lock is not available, the function returns `false` and the
554
+ * callback is queued until the lock is released.
555
+ *
556
+ * @param key - The key to lock.
557
+ * @param onUnlocked - A callback to call when the lock is released.
558
+ * @returns `true` if the lock was acquired, `false` otherwise.
654
559
  */
655
- encoder: Encoder | null;
560
+ tryLock(key: Key, onUnlocked?: () => void): boolean;
656
561
  /**
657
- * The encoding used to encode values. Defaults to `'msgpack'` in
658
- * `RocksDatabase.open()`.
562
+ * Releases the lock on the given key and calls any queued `onUnlocked`
563
+ * callback handlers.
564
+ *
565
+ * @param key - The key to unlock.
659
566
  */
660
- encoding: Encoding | null;
567
+ unlock(key: Key): void;
661
568
  /**
662
- * Encoder specific option used to signal that the data should be frozen.
569
+ * Gets or creates a transaction log instance.
570
+ *
571
+ * @param context - The context to use for the transaction log.
572
+ * @param name - The name of the transaction log.
573
+ * @returns The transaction log.
663
574
  */
664
- freezeData: boolean;
575
+ useLog(context: StoreContext, name: string | number): TransactionLog;
665
576
  /**
666
- * Reusable buffer for encoding keys.
577
+ * Checks the process-global verification table for a fresh version match
578
+ * on `key`. Returns `true` when the table currently records `version` for
579
+ * this database+column-family. Provides a fast cache-freshness check
580
+ * before falling back to a full read.
667
581
  */
668
- keyBuffer: BufferWithDataView;
582
+ verifyVersion(key: Key, version: number): boolean;
669
583
  /**
670
- * The key encoding to use for keys. Defaults to `'ordered-binary'`.
584
+ * Seeds the verification-table slot for `key` with `version`. Has no
585
+ * effect if the slot is currently lock-tagged or the table is disabled.
586
+ * Useful after a full read where the caller already knows the version.
671
587
  */
672
- keyEncoding: KeyEncoding;
588
+ populateVersion(key: Key, version: number): void;
673
589
  /**
674
- * The maximum key size.
590
+ * Acquires a lock on the given key and calls the callback.
591
+ *
592
+ * @param key - The key to lock.
593
+ * @param callback - The callback to call when the lock is acquired.
594
+ * @returns A promise that resolves when the lock is acquired.
675
595
  */
676
- maxKeySize: number;
596
+ withLock(key: Key, callback: () => void | Promise<void>): Promise<void>;
597
+ }
598
+ interface GetOptions {
677
599
  /**
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.
600
+ * When set, the native layer checks the verification table before reading.
601
+ * If the slot holds this version, returns `FRESH_VERSION_FLAG` immediately
602
+ * (the cached value is still valid). After a DB read, also seeds the slot
603
+ * with the version extracted from the value.
681
604
  */
682
- maxWriteBufferNumber?: number;
605
+ expectedVersion?: number;
683
606
  /**
684
- * The bytes of recent memtable history to retain in memory for transaction
685
- * conflict checking. `-1` derives the value from
686
- * `maxWriteBufferNumber * writeBufferSize`.
607
+ * When `true`, after a DB read the native layer automatically seeds the
608
+ * verification-table slot with the version extracted from the value.
609
+ * Eliminates the need for a separate `populateVersion` call on cold reads.
610
+ *
611
+ * @default false
687
612
  */
688
- maxWriteBufferSizeToMaintain?: number;
613
+ populateVersion?: boolean;
689
614
  /**
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.
615
+ * Whether to skip decoding the value.
616
+ *
617
+ * @default false
693
618
  */
694
- dbWriteBufferSize?: number;
619
+ skipDecode?: boolean;
620
+ }
621
+ interface PutOptions {
622
+ append?: boolean;
623
+ instructedWrite?: boolean;
624
+ noDupData?: boolean;
625
+ noOverwrite?: boolean;
626
+ }
627
+ //#endregion
628
+ //#region src/transaction.d.ts
629
+ /**
630
+ * Sentinel value returned by `commit()` when `coordinatedRetry: true` and the
631
+ * transaction encountered an IsBusy conflict. The native layer parks on VT
632
+ * slots and resolves only after the conflicting transaction releases its write
633
+ * intent, so callers should retry immediately without any backoff delay.
634
+ */
635
+ declare const RETRY_NOW: number;
636
+ /**
637
+ * Provides transaction level operations to a transaction callback.
638
+ */
639
+ declare class Transaction extends DBI {
640
+ #private;
695
641
  /**
696
- * The name of the store (e.g. the column family). Defaults to `'default'`.
642
+ * Create a new transaction.
643
+ *
644
+ * @param store - The base store interface for this transaction.
645
+ * @param options - The options for the transaction.
697
646
  */
698
- name: string;
647
+ constructor(store: Store, options?: NativeTransactionOptions);
699
648
  /**
700
- * Whether to disable the block cache.
649
+ * Abort the transaction.
701
650
  */
702
- noBlockCache?: boolean;
651
+ abort(): void;
703
652
  /**
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)`.
653
+ * Commit the transaction.
654
+ *
655
+ * Returns `RETRY_NOW` when `coordinatedRetry: true` and an IsBusy conflict
656
+ * was detected. The caller should retry the transaction body immediately.
707
657
  */
708
- parallelismThreads?: number;
658
+ commit(): Promise<typeof RETRY_NOW | void>;
709
659
  /**
710
- * The path to the database.
660
+ * Commit the transaction synchronously.
711
661
  */
712
- path: string;
662
+ commitSync(): void;
713
663
  /**
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.
664
+ * Returns the transaction start timestamp in seconds. Defaults to the time at which
665
+ * the transaction was created.
666
+ *
667
+ * @returns The transaction start timestamp in seconds.
717
668
  */
718
- pessimistic: boolean;
669
+ getTimestamp(): number;
719
670
  /**
720
- * Whether the database is open in readonly mode. When `true`, write
721
- * operations will throw an error with code `ERR_DATABASE_READONLY`.
671
+ * Get the transaction id.
722
672
  */
723
- readOnly: boolean;
673
+ get id(): number;
724
674
  /**
725
- * Encoder specific flag used to signal that the encoder should use a random
726
- * access structure.
675
+ * Set the transaction start timestamp in seconds.
676
+ *
677
+ * @param timestamp - The timestamp to set in seconds.
678
+ */
679
+ setTimestamp(timestamp?: number): void;
680
+ }
681
+ //#endregion
682
+ //#region src/util.d.ts
683
+ type MaybePromise<T> = T | Promise<T>;
684
+ //#endregion
685
+ //#region src/dbi.d.ts
686
+ interface RocksDBOptions {
687
+ /**
688
+ * When `true`, RocksDB will do some enhancements for prefetching the data.
689
+ * Defaults to `true`. Note that RocksDB defaults this to `false`.
690
+ */
691
+ adaptiveReadahead?: boolean;
692
+ /**
693
+ * When `true`, RocksDB will prefetch some data async and apply it if reads
694
+ * are sequential and its internal automatic prefetching. Defaults to
695
+ * `true`. Note that RocksDB defaults this to `false`.
727
696
  */
728
- randomAccessStructure: boolean;
697
+ asyncIO?: boolean;
729
698
  /**
730
- * The function used to encode keys.
699
+ * When `true`, RocksDB will auto-tune the readahead size during scans
700
+ * internally based on the block cache data when block caching is enabled,
701
+ * an end key (e.g. upper bound) is set, and prefix is the same as the start
702
+ * key. Defaults to `true`.
731
703
  */
732
- readKey: ReadKeyFunction<Key>;
704
+ autoReadaheadSize?: boolean;
733
705
  /**
734
- * The key used to store shared structures.
706
+ * When `true`, after the iterator is closed, a background job is scheduled
707
+ * to flush the job queue and delete obsolete files. Defaults to `true`.
708
+ * Note that RocksDB defaults this to `false`.
735
709
  */
736
- sharedStructuresKey?: symbol;
710
+ backgroundPurgeOnIteratorCleanup?: boolean;
737
711
  /**
738
- * The level of statistics to capture.
712
+ * When `true`, the iterator will fill the block cache. Filling the block
713
+ * cache is not desirable for bulk scans and could impact eviction order.
714
+ * Defaults to `false`. Note that RocksDB defaults this to `true`.
739
715
  */
740
- statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
716
+ fillCache?: boolean;
741
717
  /**
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.
718
+ * The RocksDB readahead size. RocksDB does auto-readahead for iterators
719
+ * when there is more than two reads for a table file. The readahead
720
+ * starts at 8KB and doubles on every additional read up to 256KB. This
721
+ * option can help if most of the range scans are large and if a larger
722
+ * readahead than that enabled by auto-readahead is needed. Using a large
723
+ * readahead size (> 2MB) can typically improve the performance of forward
724
+ * iteration on spinning disks. Defaults to `0`.
745
725
  */
746
- transactionLogMaxAgeThreshold?: number;
726
+ readaheadSize?: number;
747
727
  /**
748
- * The maximum size of a transaction log before it is rotated to the next
749
- * sequence number.
728
+ * When `true`, creates a "tailing iterator" which is a special iterator
729
+ * that has a view of the complete database including newly added data and
730
+ * is optimized for sequential reads. This will return records that were
731
+ * inserted into the database after the creation of the iterator. Defaults
732
+ * to `false`.
750
733
  */
751
- transactionLogMaxSize?: number;
734
+ tailing?: boolean;
735
+ }
736
+ interface RangeOptions extends RocksDBOptions {
752
737
  /**
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)
738
+ * The range end key, otherwise known as the "upper bound". Defaults to
739
+ * the last key in the database.
757
740
  */
758
- transactionLogRetention?: number | string;
741
+ end?: Key | Uint8Array;
759
742
  /**
760
- * The path to the transaction logs directory.
743
+ * When `true`, the iterator will exclude the first key if it matches the start key.
744
+ * Defaults to `false`.
761
745
  */
762
- transactionLogsPath?: string;
746
+ exclusiveStart?: boolean;
763
747
  /**
764
- * Whether this store's column family participates in the VerificationTable.
748
+ * When `true`, the iterator will include the last key if it matches the end
749
+ * key. Defaults to `false`.
765
750
  */
766
- verificationTable?: boolean;
751
+ inclusiveEnd?: boolean;
767
752
  /**
768
- * The per-column-family memtable size in bytes at which the memtable is
769
- * sealed and flushed.
753
+ * The range start key, otherwise known as the "lower bound". Defaults to
754
+ * the first key in the database.
770
755
  */
771
- writeBufferSize?: number;
756
+ start?: Key | Uint8Array;
757
+ }
758
+ interface IteratorOptions extends RangeOptions {
772
759
  /**
773
- * The function used to encode keys using the shared `keyBuffer`.
760
+ * The maximum number of entries to yield. When set, iteration stops after
761
+ * `limit` entries regardless of the range bounds. Values <= 0 yield nothing.
762
+ * Unset means no limit.
774
763
  */
775
- writeKey: WriteKeyFunction;
764
+ limit?: number;
776
765
  /**
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.
766
+ * A specific key to match which may result in zero, one, or many values.
781
767
  */
782
- constructor(path: string, options?: StoreOptions);
768
+ key?: Key;
783
769
  /**
784
- * Closes the database.
770
+ * When `true`, only returns the number of values for the given query.
785
771
  */
786
- close(): void;
772
+ onlyCount?: boolean;
787
773
  /**
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
- * ```
774
+ * When `true`, the iterator will iterate in reverse order. Defaults to
775
+ * `false`.
796
776
  */
797
- compact(options?: CompactOptions): Promise<void>;
777
+ reverse?: boolean;
798
778
  /**
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
- * ```
779
+ * When `true`, decodes and returns the value. When `false`, the value is
780
+ * omitted. Defaults to `true`.
807
781
  */
808
- backup(backupDir: string, options?: BackupOptions): Promise<number>;
782
+ values?: boolean;
809
783
  /**
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
- * ```
784
+ * When `true`, the iterator will only return the values.
818
785
  */
819
- compactSync(options?: CompactOptions): void;
786
+ valuesOnly?: boolean;
787
+ }
788
+ interface DBITransactional {
789
+ transaction?: Transaction;
790
+ }
791
+ /**
792
+ * The base class for all database operations. This base class is shared by
793
+ * `RocksDatabase` and `Transaction`.
794
+ *
795
+ * This class is not meant to be used directly.
796
+ */
797
+ declare class DBI<T extends DBITransactional | unknown = unknown> {
820
798
  /**
821
- * Decodes a key from the database.
822
- *
823
- * @param key - The key to decode.
824
- * @returns The decoded key.
799
+ * The RocksDB context for `get()`, `put()`, and `remove()`.
825
800
  */
826
- decodeKey(key: Buffer): Key;
801
+ _context: StoreContext;
827
802
  /**
828
- * Decodes a value from the database.
829
- *
830
- * @param value - The value to decode.
831
- * @returns The decoded value.
803
+ * The database store instance. The store instance is tied to the database
804
+ * instance and shared with transaction instances.
832
805
  */
833
- decodeValue(value: BufferWithDataView): any;
806
+ store: Store;
834
807
  /**
835
- * Encodes a key for the database.
808
+ * Initializes the DBI context.
836
809
  *
837
- * @param key - The key to encode.
838
- * @returns The encoded key.
810
+ * @param store - The store instance.
811
+ * @param transaction - The transaction instance.
839
812
  */
840
- encodeKey(key: Key): BufferWithDataView;
813
+ constructor(store: Store, transaction?: NativeTransaction);
841
814
  /**
842
- * Encodes a value for the database.
815
+ * Adds a listener for the given key.
843
816
  *
844
- * @param value - The value to encode.
845
- * @returns The encoded value.
817
+ * @param event - The event name to add the listener for.
818
+ * @param callback - The callback to add.
846
819
  */
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;
820
+ addListener(event: string, callback: (...args: any[]) => void): this;
854
821
  /**
855
- * Checks if the data method options object contains a transaction ID and
856
- * returns it.
822
+ * Retrieves the value for the given key, then returns the decoded value.
857
823
  */
858
- getTxnId(options?: DBITransactional | unknown): number | undefined;
824
+ get(key: Key, options?: GetOptions & T): MaybePromise<any | undefined>;
859
825
  /**
860
- * Gets or creates a buffer that can be shared across worker threads.
826
+ * Retrieves the binary data for the given key. This is just like `get()`,
827
+ * but bypasses the decoder.
861
828
  *
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`.
829
+ * Note: Used by HDBreplication.
871
830
  */
872
- getUserSharedBuffer(key: Key, defaultBuffer: ArrayBuffer, options?: UserSharedBufferOptions): ArrayBufferWithNotify;
831
+ getBinary(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
873
832
  /**
874
- * Checks if a lock exists.
875
- * @param key The lock key.
876
- * @returns `true` if the lock exists, `false` otherwise
833
+ * Synchronously retrieves the binary data for the given key.
877
834
  */
878
- hasLock(key: Key): boolean;
835
+ getBinarySync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
879
836
  /**
880
- * Checks if the database is open.
837
+ * Retrieves the binary data for the given key using a preallocated,
838
+ * reusable buffer. Data in the buffer is only valid until the next get
839
+ * operation (including cursor operations).
881
840
  *
882
- * @returns `true` if the database is open, `false` otherwise.
841
+ * Note: The reusable buffer slightly differs from a typical buffer:
842
+ * - `.length` is set to the size of the value
843
+ * - `.byteLength` is set to the size of the full allocated memory area for
844
+ * the buffer (usually much larger).
883
845
  */
884
- isOpen(): boolean;
846
+ getBinaryFast(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
885
847
  /**
886
- * Lists all transaction log names.
887
- *
888
- * @returns an array of transaction log names.
848
+ * Synchronously retrieves the binary data for the given key using a
849
+ * preallocated, reusable buffer. Data in the buffer is only valid until the
850
+ * next get operation (including cursor operations).
889
851
  */
890
- listLogs(): string[];
852
+ getBinaryFastSync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
891
853
  /**
892
- * Opens the database. This must be called before any database operations
893
- * are performed.
854
+ * Retrieves all keys within a range.
894
855
  */
895
- open(): boolean;
896
- putSync(context: StoreContext, key: Key, value: any, options?: StorePutOptions): void;
897
- removeSync(context: StoreContext, key: Key, options?: StoreRemoveOptions): void;
856
+ getKeys(options?: IteratorOptions & T): any | undefined;
898
857
  /**
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.
858
+ * Retrieves the number of keys within a range.
903
859
  *
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.
860
+ * @param options - The range options.
861
+ * @returns The number of keys within the range.
912
862
  *
913
- * @param key - The key to unlock.
863
+ * @example
864
+ * ```typescript
865
+ * const total = db.getKeysCount();
866
+ * const range = db.getKeysCount({ start: 'a', end: 'z' });
867
+ * ```
914
868
  */
915
- unlock(key: Key): void;
869
+ getKeysCount(options?: RangeOptions & T): number;
916
870
  /**
917
- * Gets or creates a transaction log instance.
871
+ * Retrieves a range of keys and their values.
872
+ *
873
+ * @param options - The iterator options.
874
+ * @returns A range iterable.
875
+ *
876
+ * @example
877
+ * ```typescript
878
+ * for (const { key, value } of db.getRange()) {
879
+ * console.log({ key, value });
880
+ * }
918
881
  *
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.
882
+ * for (const { key, value } of db.getRange({ start: 'a', end: 'z' })) {
883
+ * console.log({ key, value });
884
+ * }
885
+ * ```
929
886
  */
930
- verifyVersion(key: Key, version: number): boolean;
887
+ getRange(options?: IteratorOptions & T): any | undefined;
931
888
  /**
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.
889
+ * Synchronously retrieves the value for the given key, then returns the
890
+ * decoded value.
935
891
  */
936
- populateVersion(key: Key, version: number): void;
892
+ getSync(key: Key, options?: GetOptions & T): any | undefined;
937
893
  /**
938
- * Acquires a lock on the given key and calls the callback.
894
+ * Gets the number of listeners for the given key.
939
895
  *
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.
896
+ * @param event - The event name to get the listeners for.
897
+ * @returns The number of listeners for the given key.
943
898
  */
944
- withLock(key: Key, callback: () => void | Promise<void>): Promise<void>;
945
- }
946
- interface GetOptions {
899
+ listeners(event: string | BufferWithDataView): number;
947
900
  /**
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.
901
+ * Notifies an event for the given key.
902
+ *
903
+ * @param event - The event name to emit the event for.
904
+ * @param args - The arguments to emit.
905
+ * @returns `true` if there were listeners, `false` otherwise.
952
906
  */
953
- expectedVersion?: number;
907
+ notify(event: string, ...args: any[]): boolean;
954
908
  /**
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.
909
+ * Alias for `removeListener()`.
958
910
  *
959
- * @default false
911
+ * @param event - The event name to remove the listener for.
912
+ * @param callback - The callback to remove.
960
913
  */
961
- populateVersion?: boolean;
914
+ off(event: string, callback: (...args: any[]) => void): this;
962
915
  /**
963
- * Whether to skip decoding the value.
916
+ * Alias for `addListener()`.
964
917
  *
965
- * @default false
918
+ * @param event - The event name to add the listener for.
919
+ * @param callback - The callback to add.
966
920
  */
967
- skipDecode?: boolean;
968
- }
969
- interface PutOptions {
970
- append?: boolean;
971
- instructedWrite?: boolean;
972
- noDupData?: boolean;
973
- noOverwrite?: boolean;
974
- }
975
- //#endregion
976
- //#region src/load-binding.d.ts
977
- type NativeTransactionOptions = {
921
+ on(event: string, callback: (...args: any[]) => void): this;
978
922
  /**
979
- * Whether to disable snapshots.
923
+ * Adds a one-time listener, then automatically removes it.
980
924
  *
981
- * @default false
925
+ * @param event - The event name to add the listener for.
926
+ * @param callback - The callback to add.
982
927
  */
983
- disableSnapshot?: boolean;
928
+ once(event: string, callback: (...args: any[]) => void): this;
984
929
  /**
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.
930
+ * Stores a value for the given key.
989
931
  *
990
- * Use together with `verificationTable: true` on the database.
932
+ * @param key - The key to store the value for.
933
+ * @param value - The value to store.
934
+ * @param options - The put options.
935
+ * @returns The key and value.
991
936
  *
992
- * @default false
937
+ * @example
938
+ * ```typescript
939
+ * await db.put('a', 'b');
940
+ * ```
993
941
  */
994
- coordinatedRetry?: boolean;
995
- };
996
- type NativeTransaction = {
997
- id: number;
998
- new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
999
- abort(): void;
1000
- commit(resolve: (retrySignal?: number) => void, reject: (err: Error) => void): void;
1001
- commitSync(): void;
1002
- get(keyLengthOrKeyBuffer: number | Buffer, resolve: (value: Buffer | number) => void, reject: (err: Error) => void, txnIdIgnored?: number, expectedVersion?: number): number;
1003
- getCount(options?: RangeOptions): number;
1004
- getSync(keyLengthOrKeyBuffer: number | Buffer): Buffer | number | undefined;
1005
- getTimestamp(): number;
1006
- putSync(key: Key, value: Buffer | Uint8Array, txnId?: number): void;
1007
- removeSync(key: Key): void;
1008
- setTimestamp(timestamp?: number): void;
1009
- useLog(name: string | number): TransactionLog;
1010
- };
1011
- type LogBuffer = Buffer & {
1012
- dataView: DataView;
1013
- logId: number;
1014
- size: number;
1015
- };
1016
- type TransactionLogQueryOptions = {
1017
- start?: number;
1018
- end?: number;
1019
- exactStart?: boolean;
1020
- startFromLastFlushed?: boolean;
1021
- readUncommitted?: boolean;
1022
- exclusiveStart?: boolean;
1023
- };
1024
- type TransactionEntry = {
1025
- timestamp: number;
1026
- data: Buffer;
1027
- endTxn: boolean;
1028
- };
1029
- /**
1030
- * A position within a transaction log, identifying a log file by its sequence
1031
- * number and a byte `offset` within that file.
1032
- */
1033
- type TransactionLogPosition = {
1034
- sequence: number;
1035
- offset: number;
1036
- };
1037
- /**
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
- */
1047
- type TransactionLogStats = {
1048
- name: string;
1049
- path: string;
1050
- fileCount: number;
1051
- currentSequenceNumber: number;
1052
- oldestSequenceNumber: number;
1053
- totalSizeBytes: number;
1054
- currentFileSize: number;
1055
- pendingTransactions: number;
1056
- uncommittedTransactions: number;
1057
- replayGapBytes: number;
1058
- memory: {
1059
- mappedBytes: number;
1060
- overlayBytes: number;
1061
- activeMaps: number;
1062
- };
1063
- nextLogPosition: TransactionLogPosition;
1064
- lastFlushedPosition: TransactionLogPosition;
1065
- lastCommittedPosition: TransactionLogPosition | null;
1066
- purge: {
1067
- oldestFileAgeMs: number;
1068
- purgeableFiles: number;
1069
- retainedUnflushedFiles: number;
1070
- lastPurgeMs: number;
1071
- };
1072
- totals: {
1073
- transactionsWritten: number;
1074
- entriesWritten: number;
1075
- bytesWritten: number;
1076
- rotations: number;
1077
- filesPurged: number;
1078
- bytesPurged: number;
1079
- purgeRuns: number;
1080
- databaseFlushes: number;
1081
- writeFailures: number;
1082
- };
1083
- config: {
1084
- maxFileSize: number;
1085
- retentionMs: number;
1086
- maxAgeThreshold: number;
1087
- };
1088
- };
1089
- type TransactionLog = {
1090
- new (db: NativeDatabase, name: string): TransactionLog;
1091
- addEntry(data: Buffer | Uint8Array, txnId?: number): void;
1092
- getLogFileSize(sequenceId?: number): number;
1093
- getStats(): TransactionLogStats;
1094
- name: string;
1095
- path: string;
1096
- query(options?: TransactionLogQueryOptions): IterableIterator<TransactionEntry>;
1097
- _currentLogBuffer: LogBuffer;
1098
- _findPosition(timestamp: number): number;
1099
- _getLastCommittedPosition(): Buffer;
1100
- _getLastFlushed(): number;
1101
- _getMemoryMapOfFile(sequenceId: number): LogBuffer | undefined;
1102
- _lastCommittedPosition: Float64Array;
1103
- _logBuffers: Map<number, WeakRef<LogBuffer>>;
1104
- };
1105
- /**
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
- */
1110
- type NativeIteratorAdvancedOptions = {
1111
- adaptiveReadahead?: boolean;
1112
- asyncIO?: boolean;
1113
- autoReadaheadSize?: boolean;
1114
- backgroundPurgeOnIteratorCleanup?: boolean;
1115
- fillCache?: boolean;
1116
- readaheadSize?: number;
1117
- tailing?: boolean;
1118
- };
1119
- /**
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
- */
1125
- type NativeIteratorResult = number | {
1126
- key: Buffer;
1127
- value?: Buffer;
1128
- };
1129
- declare class NativeIteratorCls {
1130
- constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
1131
- next(): NativeIteratorResult;
1132
- return(): void;
1133
- throw(err?: unknown): void;
1134
- }
1135
- type NativeDatabaseMode = "optimistic" | "pessimistic";
1136
- type NativeDatabaseOptions = {
1137
- dbWriteBufferSize?: number;
1138
- disableWAL?: boolean;
1139
- enableStats?: boolean;
1140
- maxWriteBufferNumber?: number;
1141
- maxWriteBufferSizeToMaintain?: number;
1142
- mode?: NativeDatabaseMode;
1143
- name?: string;
1144
- noBlockCache?: boolean;
1145
- parallelismThreads?: number;
1146
- readOnly?: boolean;
1147
- statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
1148
- transactionLogMaxAgeThreshold?: number;
1149
- transactionLogMaxSize?: number;
1150
- transactionLogRetentionMs?: number;
1151
- transactionLogsPath?: string;
942
+ put(key: Key, value: any, options?: PutOptions & T): Promise<void>;
943
+ /**
944
+ * Synchronously stores a value for the given key.
945
+ *
946
+ * @param key - The key to store the value for.
947
+ * @param value - The value to store.
948
+ * @param options - The put options.
949
+ * @returns The key and value.
950
+ *
951
+ * @example
952
+ * ```typescript
953
+ * db.putSync('a', 'b');
954
+ * ```
955
+ */
956
+ putSync(key: Key, value: any, options?: PutOptions & T): void;
1152
957
  /**
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.
958
+ * Removes a value for the given key. If the key does not exist, it will
959
+ * not error.
960
+ *
961
+ * @param key - The key to remove the value for.
962
+ * @param options - The remove options.
963
+ * @returns The key and value.
964
+ *
965
+ * @example
966
+ * ```typescript
967
+ * await db.remove('a');
968
+ * ```
1157
969
  */
1158
- verificationTable?: boolean;
1159
- writeBufferSize?: number;
1160
- };
1161
- type ResolveCallback<T> = (value: T) => void;
1162
- type RejectCallback = (err: Error) => void;
1163
- type UserSharedBufferCallback = () => void;
1164
- type PurgeLogsOptions = {
1165
- before?: number;
1166
- destroy?: boolean;
970
+ remove(key: Key, options?: T): Promise<void>;
1167
971
  /**
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.
972
+ * Removes a value for the given key. If the key does not exist, it will
973
+ * not error.
974
+ *
975
+ * @param key - The key to remove the value for.
976
+ * @param options - The remove options.
977
+ * @returns The key and value.
978
+ *
979
+ * @example
980
+ * ```typescript
981
+ * db.removeSync('a');
982
+ * ```
1170
983
  */
1171
- includeEntryCounts?: boolean;
1172
- name?: string;
984
+ removeSync(key: Key, options?: T): void;
985
+ /**
986
+ * Removes an event listener. You must specify the exact same callback that was
987
+ * used in `addListener()`.
988
+ *
989
+ * @param event - The event name to remove the listener for.
990
+ * @param callback - The callback to remove.
991
+ */
992
+ removeListener(event: string, callback: (value?: any) => void): boolean;
993
+ /**
994
+ * Get or create a transaction log instance.
995
+ *
996
+ * @param name - The name of the transaction log.
997
+ * @returns The transaction log.
998
+ */
999
+ useLog(name: string | number): TransactionLog;
1000
+ }
1001
+ //#endregion
1002
+ //#region src/stats.d.ts
1003
+ /** Database-level RocksDB statistics types for `db.getStats()` / `db.getStat()`. */
1004
+ type StatsHistogramData = {
1005
+ average: number;
1006
+ count: number;
1007
+ max: number;
1008
+ median: number;
1009
+ min: number;
1010
+ percentile95: number;
1011
+ percentile99: number;
1012
+ standardDeviation: number;
1013
+ sum: number;
1173
1014
  };
1174
- /**
1175
- * A purged transaction log file and the number of entries it held, returned by
1176
- * `purgeLogs()` when `includeEntryCounts` is `true`.
1177
- */
1178
- type PurgedLog = {
1179
- path: string;
1180
- entries: number;
1015
+ type StatsBasics = {
1016
+ "rocksdb.num-immutable-mem-table": number;
1017
+ "rocksdb.num-immutable-mem-table-flushed": number;
1018
+ "rocksdb.mem-table-flush-pending": number;
1019
+ "rocksdb.cur-size-active-mem-table": number;
1020
+ "rocksdb.cur-size-all-mem-tables": number;
1021
+ "rocksdb.size-all-mem-tables": number;
1022
+ "rocksdb.num-entries-active-mem-table": number;
1023
+ "rocksdb.num-deletes-active-mem-table": number;
1024
+ "rocksdb.compaction-pending": number;
1025
+ "rocksdb.estimate-pending-compaction-bytes": number;
1026
+ "rocksdb.num-running-compactions": number;
1027
+ "rocksdb.num-running-flushes": number;
1028
+ "rocksdb.total-sst-files-size": number;
1029
+ "rocksdb.live-sst-files-size": number;
1030
+ "rocksdb.estimate-live-data-size": number;
1031
+ "rocksdb.estimate-num-keys": number;
1032
+ "rocksdb.block-cache-capacity": number;
1033
+ "rocksdb.block-cache-usage": number;
1034
+ "rocksdb.block-cache-pinned-usage": number;
1035
+ "rocksdb.num-live-versions": number;
1036
+ "rocksdb.current-super-version-number": number;
1037
+ "rocksdb.oldest-snapshot-time": number;
1038
+ "rocksdb.num-blob-files": number;
1039
+ "rocksdb.total-blob-file-size": number;
1040
+ "rocksdb.live-blob-file-size": number;
1041
+ "txnlog.logCount": number;
1042
+ "txnlog.fileCount": number;
1043
+ "txnlog.totalSizeBytes": number;
1044
+ "txnlog.mappedBytes": number;
1045
+ "txnlog.overlayBytes": number;
1046
+ "txnlog.activeMaps": number;
1047
+ "txnlog.pendingTransactions": number;
1048
+ "txnlog.uncommittedTransactions": number;
1049
+ "txnlog.transactionsWritten": number;
1050
+ "txnlog.bytesWritten": number;
1051
+ "txnlog.replayGapBytes": number;
1052
+ };
1053
+ type StatsCuratedExtras = {
1054
+ "rocksdb.block.cache.hit": number;
1055
+ "rocksdb.block.cache.miss": number;
1056
+ "rocksdb.block.cache.data.hit": number;
1057
+ "rocksdb.block.cache.data.miss": number;
1058
+ "rocksdb.block.cache.index.hit": number;
1059
+ "rocksdb.block.cache.index.miss": number;
1060
+ "rocksdb.block.cache.filter.hit": number;
1061
+ "rocksdb.block.cache.filter.miss": number;
1062
+ "rocksdb.bloom.filter.useful": number;
1063
+ "rocksdb.bloom.filter.full.positive": number;
1064
+ "rocksdb.bloom.filter.full.true.positive": number;
1065
+ "rocksdb.db.iter.bytes.read": number;
1066
+ "rocksdb.number.reseeks.iteration": number;
1067
+ "rocksdb.number.keys.read": number;
1068
+ "rocksdb.number.keys.written": number;
1069
+ "rocksdb.bytes.read": number;
1070
+ "rocksdb.bytes.written": number;
1071
+ "rocksdb.memtable.hit": number;
1072
+ "rocksdb.memtable.miss": number;
1073
+ "rocksdb.txn.overhead.mutex.prepare": number;
1074
+ "rocksdb.txn.overhead.mutex.old.commit.map": number;
1075
+ "rocksdb.txn.overhead.mutex.snapshot": number;
1076
+ "rocksdb.compact.read.bytes": number;
1077
+ "rocksdb.compact.write.bytes": number;
1078
+ "rocksdb.compaction.cancelled": number;
1079
+ "rocksdb.stall.micros": number;
1080
+ "rocksdb.no.file.errors": number;
1081
+ "rocksdb.read.amp.estimate.useful.bytes": number;
1082
+ "rocksdb.read.amp.total.read.bytes": number;
1083
+ "rocksdb.db.get.micros": StatsHistogramData;
1084
+ "rocksdb.db.write.micros": StatsHistogramData;
1085
+ "rocksdb.db.seek.micros": StatsHistogramData;
1086
+ "rocksdb.db.flush.micros": StatsHistogramData;
1087
+ "rocksdb.db.write.stall": StatsHistogramData;
1088
+ "rocksdb.blobdb.value.size": StatsHistogramData;
1089
+ "rocksdb.sst.read.micros": StatsHistogramData;
1090
+ "rocksdb.compaction.times.micros": StatsHistogramData;
1091
+ };
1092
+ type StatsAllExtras = {
1093
+ "rocksdb.block.cache.add": number;
1094
+ "rocksdb.block.cache.add.failures": number;
1095
+ "rocksdb.block.cache.index.add": number;
1096
+ "rocksdb.block.cache.index.bytes.insert": number;
1097
+ "rocksdb.block.cache.filter.add": number;
1098
+ "rocksdb.block.cache.filter.bytes.insert": number;
1099
+ "rocksdb.block.cache.data.add": number;
1100
+ "rocksdb.block.cache.data.bytes.insert": number;
1101
+ "rocksdb.block.cache.bytes.read": number;
1102
+ "rocksdb.block.cache.bytes.write": number;
1103
+ "rocksdb.block.cache.compression.dict.miss": number;
1104
+ "rocksdb.block.cache.compression.dict.hit": number;
1105
+ "rocksdb.block.cache.compression.dict.add": number;
1106
+ "rocksdb.block.cache.compression.dict.bytes.insert": number;
1107
+ "rocksdb.block.cache.add.redundant": number;
1108
+ "rocksdb.block.cache.index.add.redundant": number;
1109
+ "rocksdb.block.cache.filter.add.redundant": number;
1110
+ "rocksdb.block.cache.data.add.redundant": number;
1111
+ "rocksdb.block.cache.compression.dict.add.redundant": number;
1112
+ "rocksdb.secondary.cache.hits": number;
1113
+ "rocksdb.secondary.cache.filter.hits": number;
1114
+ "rocksdb.secondary.cache.index.hits": number;
1115
+ "rocksdb.secondary.cache.data.hits": number;
1116
+ "rocksdb.compressed.secondary.cache.dummy.hits": number;
1117
+ "rocksdb.compressed.secondary.cache.hits": number;
1118
+ "rocksdb.compressed.secondary.cache.promotions": number;
1119
+ "rocksdb.compressed.secondary.cache.promotion.skips": number;
1120
+ "rocksdb.bloom.filter.prefix.checked": number;
1121
+ "rocksdb.bloom.filter.prefix.useful": number;
1122
+ "rocksdb.bloom.filter.prefix.true.positive": number;
1123
+ "rocksdb.persistent.cache.hit": number;
1124
+ "rocksdb.persistent.cache.miss": number;
1125
+ "rocksdb.sim.block.cache.hit": number;
1126
+ "rocksdb.sim.block.cache.miss": number;
1127
+ "rocksdb.l0.hit": number;
1128
+ "rocksdb.l1.hit": number;
1129
+ "rocksdb.l2andup.hit": number;
1130
+ "rocksdb.compaction.key.drop.new": number;
1131
+ "rocksdb.compaction.key.drop.obsolete": number;
1132
+ "rocksdb.compaction.key.drop.range_del": number;
1133
+ "rocksdb.compaction.key.drop.user": number;
1134
+ "rocksdb.compaction.range_del.drop.obsolete": number;
1135
+ "rocksdb.compaction.optimized.del.drop.obsolete": number;
1136
+ "rocksdb.compaction.aborted": number;
1137
+ "rocksdb.number.keys.updated": number;
1138
+ "rocksdb.number.db.seek": number;
1139
+ "rocksdb.number.db.next": number;
1140
+ "rocksdb.number.db.prev": number;
1141
+ "rocksdb.number.db.seek.found": number;
1142
+ "rocksdb.number.db.next.found": number;
1143
+ "rocksdb.number.db.prev.found": number;
1144
+ "rocksdb.number.iter.skip": number;
1145
+ "rocksdb.num.iterator.created": number;
1146
+ "rocksdb.num.iterator.deleted": number;
1147
+ "rocksdb.no.file.opens": number;
1148
+ "rocksdb.db.mutex.wait.micros": number;
1149
+ "rocksdb.number.multiget.get": number;
1150
+ "rocksdb.number.multiget.keys.read": number;
1151
+ "rocksdb.number.multiget.bytes.read": number;
1152
+ "rocksdb.number.multiget.keys.found": number;
1153
+ "rocksdb.number.merge.failures": number;
1154
+ "rocksdb.getupdatessince.calls": number;
1155
+ "rocksdb.wal.synced": number;
1156
+ "rocksdb.wal.bytes": number;
1157
+ "rocksdb.write.self": number;
1158
+ "rocksdb.write.other": number;
1159
+ "rocksdb.write.wal": number;
1160
+ "rocksdb.flush.write.bytes": number;
1161
+ "rocksdb.compact.read.marked.bytes": number;
1162
+ "rocksdb.compact.read.periodic.bytes": number;
1163
+ "rocksdb.compact.read.ttl.bytes": number;
1164
+ "rocksdb.compact.write.marked.bytes": number;
1165
+ "rocksdb.compact.write.periodic.bytes": number;
1166
+ "rocksdb.compact.write.ttl.bytes": number;
1167
+ "rocksdb.number.direct.load.table.properties": number;
1168
+ "rocksdb.number.superversion_acquires": number;
1169
+ "rocksdb.number.superversion_releases": number;
1170
+ "rocksdb.number.superversion_cleanups": number;
1171
+ "rocksdb.number.block.compressed": number;
1172
+ "rocksdb.number.block.decompressed": number;
1173
+ "rocksdb.bytes.compressed.from": number;
1174
+ "rocksdb.bytes.compressed.to": number;
1175
+ "rocksdb.bytes.compression_bypassed": number;
1176
+ "rocksdb.bytes.compression.rejected": number;
1177
+ "rocksdb.number.block_compression_bypassed": number;
1178
+ "rocksdb.number.block_compression_rejected": number;
1179
+ "rocksdb.bytes.decompressed.from": number;
1180
+ "rocksdb.bytes.decompressed.to": number;
1181
+ "rocksdb.merge.operation.time.nanos": number;
1182
+ "rocksdb.filter.operation.time.nanos": number;
1183
+ "rocksdb.compaction.total.time.cpu_micros": number;
1184
+ "rocksdb.row.cache.hit": number;
1185
+ "rocksdb.row.cache.miss": number;
1186
+ "rocksdb.number.rate_limiter.drains": number;
1187
+ "rocksdb.blobdb.num.put": number;
1188
+ "rocksdb.blobdb.num.write": number;
1189
+ "rocksdb.blobdb.num.get": number;
1190
+ "rocksdb.blobdb.num.multiget": number;
1191
+ "rocksdb.blobdb.num.seek": number;
1192
+ "rocksdb.blobdb.num.next": number;
1193
+ "rocksdb.blobdb.num.prev": number;
1194
+ "rocksdb.blobdb.num.keys.written": number;
1195
+ "rocksdb.blobdb.num.keys.read": number;
1196
+ "rocksdb.blobdb.bytes.written": number;
1197
+ "rocksdb.blobdb.bytes.read": number;
1198
+ "rocksdb.blobdb.write.inlined": number;
1199
+ "rocksdb.blobdb.write.inlined.ttl": number;
1200
+ "rocksdb.blobdb.write.blob": number;
1201
+ "rocksdb.blobdb.write.blob.ttl": number;
1202
+ "rocksdb.blobdb.blob.file.bytes.written": number;
1203
+ "rocksdb.blobdb.blob.file.bytes.read": number;
1204
+ "rocksdb.blobdb.blob.file.synced": number;
1205
+ "rocksdb.blobdb.blob.index.expired.count": number;
1206
+ "rocksdb.blobdb.blob.index.expired.size": number;
1207
+ "rocksdb.blobdb.blob.index.evicted.count": number;
1208
+ "rocksdb.blobdb.blob.index.evicted.size": number;
1209
+ "rocksdb.blobdb.gc.num.files": number;
1210
+ "rocksdb.blobdb.gc.num.new.files": number;
1211
+ "rocksdb.blobdb.gc.failures": number;
1212
+ "rocksdb.blobdb.gc.num.keys.relocated": number;
1213
+ "rocksdb.blobdb.gc.bytes.relocated": number;
1214
+ "rocksdb.blobdb.fifo.num.files.evicted": number;
1215
+ "rocksdb.blobdb.fifo.num.keys.evicted": number;
1216
+ "rocksdb.blobdb.fifo.bytes.evicted": number;
1217
+ "rocksdb.blobdb.cache.miss": number;
1218
+ "rocksdb.blobdb.cache.hit": number;
1219
+ "rocksdb.blobdb.cache.add": number;
1220
+ "rocksdb.blobdb.cache.add.failures": number;
1221
+ "rocksdb.blobdb.cache.bytes.read": number;
1222
+ "rocksdb.blobdb.cache.bytes.write": number;
1223
+ "rocksdb.txn.overhead.duplicate.key": number;
1224
+ "rocksdb.txn.get.tryagain": number;
1225
+ "rocksdb.files.marked.trash": number;
1226
+ "rocksdb.files.marked.trash.deleted": number;
1227
+ "rocksdb.files.deleted.immediately": number;
1228
+ "rocksdb.error.handler.bg.error.count": number;
1229
+ "rocksdb.error.handler.bg.io.error.count": number;
1230
+ "rocksdb.error.handler.bg.retryable.io.error.count": number;
1231
+ "rocksdb.error.handler.autoresume.count": number;
1232
+ "rocksdb.error.handler.autoresume.retry.total.count": number;
1233
+ "rocksdb.error.handler.autoresume.success.count": number;
1234
+ "rocksdb.memtable.payload.bytes.at.flush": number;
1235
+ "rocksdb.memtable.garbage.bytes.at.flush": number;
1236
+ "rocksdb.verify_checksum.read.bytes": number;
1237
+ "rocksdb.backup.read.bytes": number;
1238
+ "rocksdb.backup.write.bytes": number;
1239
+ "rocksdb.remote.compact.read.bytes": number;
1240
+ "rocksdb.remote.compact.write.bytes": number;
1241
+ "rocksdb.remote.compact.resumed.bytes": number;
1242
+ "rocksdb.hot.file.read.bytes": number;
1243
+ "rocksdb.warm.file.read.bytes": number;
1244
+ "rocksdb.cool.file.read.bytes": number;
1245
+ "rocksdb.cold.file.read.bytes": number;
1246
+ "rocksdb.ice.file.read.bytes": number;
1247
+ "rocksdb.hot.file.read.count": number;
1248
+ "rocksdb.warm.file.read.count": number;
1249
+ "rocksdb.cool.file.read.count": number;
1250
+ "rocksdb.cold.file.read.count": number;
1251
+ "rocksdb.ice.file.read.count": number;
1252
+ "rocksdb.last.level.read.bytes": number;
1253
+ "rocksdb.last.level.read.count": number;
1254
+ "rocksdb.non.last.level.read.bytes": number;
1255
+ "rocksdb.non.last.level.read.count": number;
1256
+ "rocksdb.last.level.seek.filtered": number;
1257
+ "rocksdb.last.level.seek.filter.match": number;
1258
+ "rocksdb.last.level.seek.data": number;
1259
+ "rocksdb.last.level.seek.data.useful.no.filter": number;
1260
+ "rocksdb.last.level.seek.data.useful.filter.match": number;
1261
+ "rocksdb.non.last.level.seek.filtered": number;
1262
+ "rocksdb.non.last.level.seek.filter.match": number;
1263
+ "rocksdb.non.last.level.seek.data": number;
1264
+ "rocksdb.non.last.level.seek.data.useful.no.filter": number;
1265
+ "rocksdb.non.last.level.seek.data.useful.filter.match": number;
1266
+ "rocksdb.block.checksum.compute.count": number;
1267
+ "rocksdb.block.checksum.mismatch.count": number;
1268
+ "rocksdb.multiget.coroutine.count": number;
1269
+ "rocksdb.read.async.micros": number;
1270
+ "rocksdb.async.read.error.count": number;
1271
+ "rocksdb.table.open.prefetch.tail.miss": number;
1272
+ "rocksdb.table.open.prefetch.tail.hit": number;
1273
+ "rocksdb.timestamp.filter.table.checked": number;
1274
+ "rocksdb.timestamp.filter.table.filtered": number;
1275
+ "rocksdb.readahead.trimmed": number;
1276
+ "rocksdb.fifo.max.size.compactions": number;
1277
+ "rocksdb.fifo.ttl.compactions": number;
1278
+ "rocksdb.fifo.change_temperature.compactions": number;
1279
+ "rocksdb.prefetch.bytes": number;
1280
+ "rocksdb.prefetch.bytes.useful": number;
1281
+ "rocksdb.prefetch.hits": number;
1282
+ "rocksdb.footer.corruption.count": number;
1283
+ "rocksdb.file.read.corruption.retry.count": number;
1284
+ "rocksdb.file.read.corruption.retry.success.count": number;
1285
+ "rocksdb.number.wbwi.ingest": number;
1286
+ "rocksdb.sst.user.defined.index.load.fail.count": number;
1287
+ "rocksdb.multiscan.prepare.calls": number;
1288
+ "rocksdb.multiscan.prepare.errors": number;
1289
+ "rocksdb.multiscan.blocks.prefetched": number;
1290
+ "rocksdb.multiscan.blocks.from.cache": number;
1291
+ "rocksdb.multiscan.prefetch.bytes": number;
1292
+ "rocksdb.multiscan.prefetch.blocks.wasted": number;
1293
+ "rocksdb.multiscan.io.requests": number;
1294
+ "rocksdb.multiscan.io.coalesced.nonadjacent": number;
1295
+ "rocksdb.multiscan.seek.errors": number;
1296
+ "rocksdb.prefetch.memory.bytes.granted": number;
1297
+ "rocksdb.prefetch.memory.bytes.released": number;
1298
+ "rocksdb.prefetch.memory.requests.blocked": number;
1299
+ "rocksdb.compaction.times.cpu_micros": StatsHistogramData;
1300
+ "rocksdb.subcompaction.setup.times.micros": StatsHistogramData;
1301
+ "rocksdb.table.sync.micros": StatsHistogramData;
1302
+ "rocksdb.compaction.outfile.sync.micros": StatsHistogramData;
1303
+ "rocksdb.wal.file.sync.micros": StatsHistogramData;
1304
+ "rocksdb.manifest.file.sync.micros": StatsHistogramData;
1305
+ "rocksdb.table.open.io.micros": StatsHistogramData;
1306
+ "rocksdb.db.multiget.micros": StatsHistogramData;
1307
+ "rocksdb.read.block.compaction.micros": StatsHistogramData;
1308
+ "rocksdb.read.block.get.micros": StatsHistogramData;
1309
+ "rocksdb.write.raw.block.micros": StatsHistogramData;
1310
+ "rocksdb.numfiles.in.singlecompaction": StatsHistogramData;
1311
+ "rocksdb.file.read.flush.micros": StatsHistogramData;
1312
+ "rocksdb.file.read.compaction.micros": StatsHistogramData;
1313
+ "rocksdb.file.read.db.open.micros": StatsHistogramData;
1314
+ "rocksdb.file.read.get.micros": StatsHistogramData;
1315
+ "rocksdb.file.read.multiget.micros": StatsHistogramData;
1316
+ "rocksdb.file.read.db.iterator.micros": StatsHistogramData;
1317
+ "rocksdb.file.read.verify.db.checksum.micros": StatsHistogramData;
1318
+ "rocksdb.file.read.verify.file.checksums.micros": StatsHistogramData;
1319
+ "rocksdb.sst.write.micros": StatsHistogramData;
1320
+ "rocksdb.file.write.flush.micros": StatsHistogramData;
1321
+ "rocksdb.file.write.compaction.micros": StatsHistogramData;
1322
+ "rocksdb.file.write.db.open.micros": StatsHistogramData;
1323
+ "rocksdb.num.subcompactions.scheduled": StatsHistogramData;
1324
+ "rocksdb.bytes.per.read": StatsHistogramData;
1325
+ "rocksdb.bytes.per.write": StatsHistogramData;
1326
+ "rocksdb.bytes.per.multiget": StatsHistogramData;
1327
+ "rocksdb.compression.times.nanos": StatsHistogramData;
1328
+ "rocksdb.decompression.times.nanos": StatsHistogramData;
1329
+ "rocksdb.read.num.merge_operands": StatsHistogramData;
1330
+ "rocksdb.blobdb.key.size": StatsHistogramData;
1331
+ "rocksdb.blobdb.write.micros": StatsHistogramData;
1332
+ "rocksdb.blobdb.get.micros": StatsHistogramData;
1333
+ "rocksdb.blobdb.multiget.micros": StatsHistogramData;
1334
+ "rocksdb.blobdb.seek.micros": StatsHistogramData;
1335
+ "rocksdb.blobdb.next.micros": StatsHistogramData;
1336
+ "rocksdb.blobdb.prev.micros": StatsHistogramData;
1337
+ "rocksdb.blobdb.blob.file.write.micros": StatsHistogramData;
1338
+ "rocksdb.blobdb.blob.file.read.micros": StatsHistogramData;
1339
+ "rocksdb.blobdb.blob.file.sync.micros": StatsHistogramData;
1340
+ "rocksdb.blobdb.compression.micros": StatsHistogramData;
1341
+ "rocksdb.blobdb.decompression.micros": StatsHistogramData;
1342
+ "rocksdb.sst.batch.size": StatsHistogramData;
1343
+ "rocksdb.multiget.io.batch.size": StatsHistogramData;
1344
+ "rocksdb.num.index.and.filter.blocks.read.per.level": StatsHistogramData;
1345
+ "rocksdb.num.sst.read.per.level": StatsHistogramData;
1346
+ "rocksdb.num.level.read.per.multiget": StatsHistogramData;
1347
+ "rocksdb.error.handler.autoresume.retry.count": StatsHistogramData;
1348
+ "rocksdb.async.read.bytes": StatsHistogramData;
1349
+ "rocksdb.poll.wait.micros": StatsHistogramData;
1350
+ "rocksdb.compaction.prefetch.bytes": StatsHistogramData;
1351
+ "rocksdb.prefetched.bytes.discarded": StatsHistogramData;
1352
+ "rocksdb.async.prefetch.abort.micros": StatsHistogramData;
1353
+ "rocksdb.table.open.prefetch.tail.read.bytes": StatsHistogramData;
1354
+ "rocksdb.num.op.per.transaction": StatsHistogramData;
1355
+ "rocksdb.multiscan.op.prepare.iterators.micros": StatsHistogramData;
1356
+ "rocksdb.multiscan.prepare.micros": StatsHistogramData;
1357
+ "rocksdb.multiscan.blocks.per.prepare": StatsHistogramData;
1358
+ "rocksdb.block.key.distribution.cv": StatsHistogramData;
1181
1359
  };
1182
- type NativeDatabase = {
1183
- new (): NativeDatabase;
1184
- addListener(event: string, callback: (...args: any[]) => void): void;
1185
- backup(resolve: ResolveCallback<number>, reject: RejectCallback, backupDir: string, options?: BackupOptions): void;
1186
- clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1187
- clearSync(): void;
1188
- close(): void;
1189
- compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
1190
- compactSync(start?: Key, end?: Key): void;
1191
- columns: string[];
1192
- destroy(): void;
1193
- drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1194
- dropSync(): void;
1195
- flush(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1196
- flushSync(): void;
1197
- notify(event: string | BufferWithDataView, args?: any[]): boolean;
1198
- get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer | number>, reject: RejectCallback, txnId?: number, expectedVersion?: number): number;
1199
- getCount(options?: RangeOptions, txnId?: number): number;
1200
- getDBIntProperty(propertyName: string): number | undefined;
1201
- getDBProperty(propertyName: string): string | undefined;
1202
- getMonotonicTimestamp(): number;
1203
- getOldestSnapshotTimestamp(): number;
1204
- getStat(statName: string): number | StatsHistogramData;
1360
+ type StatsCurated = StatsBasics & StatsCuratedExtras;
1361
+ type StatsAll = StatsCurated & StatsAllExtras;
1362
+ type StatsValue = number | StatsHistogramData;
1363
+ /** Returned by `getStats()` when `all` is omitted or `false`. Curated keys require `enableStats: true`. */
1364
+ type StatsDefault = StatsBasics | StatsCurated;
1365
+ interface GetStatsMethod {
1205
1366
  getStats(all?: false): StatsDefault;
1206
1367
  getStats(all: true): StatsAll;
1207
- getSync(keyLengthOrKeyBuffer: number | Buffer, flags: number, txnId?: number, expectedVersion?: number): Buffer;
1208
- getUserSharedBuffer(key: BufferWithDataView, defaultBuffer: ArrayBuffer, callback?: UserSharedBufferCallback): ArrayBuffer;
1209
- hasLock(key: BufferWithDataView): boolean;
1210
- listeners(event: string | BufferWithDataView): number;
1211
- listLogs(): string[];
1212
- opened: boolean;
1213
- open(path: string, options?: NativeDatabaseOptions): void;
1214
- populateVersion(keyLengthOrKeyBuffer: number | Buffer, version: number): void;
1215
- purgeLogs(options: PurgeLogsOptions & {
1216
- includeEntryCounts: true;
1217
- }): PurgedLog[];
1218
- purgeLogs(options?: PurgeLogsOptions & {
1219
- includeEntryCounts?: false;
1220
- }): string[];
1221
- purgeLogs(options?: PurgeLogsOptions): string[] | PurgedLog[];
1222
- putSync(key: BufferWithDataView, value: any, txnId?: number): void;
1223
- removeListener(event: string | BufferWithDataView, callback: () => void): boolean;
1224
- removeSync(key: BufferWithDataView, txnId?: number): void;
1225
- setDefaultKeyBuffer(buffer: Buffer | Uint8Array | null): void;
1226
- setDefaultValueBuffer(buffer: Buffer | Uint8Array | null): void;
1227
- setIteratorState(buffer: Buffer | Uint8Array): void;
1228
- tryLock(key: BufferWithDataView, callback?: () => void): boolean;
1229
- unlock(key: BufferWithDataView): void;
1230
- useLog(name: string): TransactionLog;
1231
- verifyVersion(keyLengthOrKeyBuffer: number | Buffer, version: number): boolean;
1232
- withLock(key: BufferWithDataView, callback: () => void | Promise<void>): Promise<void>;
1233
- };
1234
- type RocksDatabaseConfig = {
1235
- blockCacheSize?: number;
1236
- /**
1237
- * Number of slots in the process-global verification table. Each slot is
1238
- * 8 bytes; the default of 128K slots is 1 MB. Set to 0 to disable.
1239
- *
1240
- * Must be configured before the first database is opened. Once the table
1241
- * is materialized, attempts to change this value will throw.
1242
- */
1243
- verificationTableEntries?: number;
1244
- compactOnClose?: boolean;
1245
- /**
1246
- * Total memtable memory limit (bytes) shared across every database opened
1247
- * in this process. When set, RocksDB uses a single `WriteBufferManager` so
1248
- * write buffers are bounded process-wide rather than per database. 0 (the
1249
- * default) disables the manager.
1250
- *
1251
- * Can be updated at runtime; the new size takes effect on the existing
1252
- * manager via `SetBufferSize`.
1253
- */
1254
- writeBufferManagerSize?: number;
1368
+ }
1369
+ //#endregion
1370
+ //#region src/load-binding.d.ts
1371
+ type NativeTransactionOptions = {
1255
1372
  /**
1256
- * When `true`, memtable memory is "charged" against the shared block cache
1257
- * so the block cache and write buffers draw from a single pool. During
1258
- * write bursts the cache shrinks to make room for memtables; once
1259
- * memtables flush, the cache can grow back into the reclaimed space.
1260
- *
1261
- * Has no effect when the block cache is disabled (size 0) or
1262
- * `writeBufferManagerSize` is 0. Must be set on the same `config()` call
1263
- * that first enables the manager — changing it after the manager has been
1264
- * created has no effect on the running instance.
1373
+ * Whether to disable snapshots.
1265
1374
  *
1266
1375
  * @default false
1267
1376
  */
1268
- writeBufferManagerCostToCache?: boolean;
1377
+ disableSnapshot?: boolean;
1269
1378
  /**
1270
- * When `true`, writes are stalled once the manager's `buffer_size` is
1271
- * exceeded, providing a hard cap on memtable memory. When `false`,
1272
- * memtables are allowed to grow past the limit and flushes are simply
1273
- * scheduled more aggressively. Off by default to favor write throughput
1274
- * over hard memory bounding.
1379
+ * When `true`, an `IsBusy` conflict at commit time is resolved with the
1380
+ * `RETRY_NOW` sentinel value instead of being rejected. The native layer
1381
+ * may park on a VT slot before resolving, so the JS retry fires only after
1382
+ * the conflicting transaction has committed and released its write intent.
1383
+ *
1384
+ * Use together with `verificationTable: true` on the database.
1275
1385
  *
1276
1386
  * @default false
1277
1387
  */
1278
- writeBufferManagerAllowStall?: boolean;
1388
+ coordinatedRetry?: boolean;
1279
1389
  };
1280
- type RegistryStatusDB = {
1281
- path: string;
1282
- refCount: number;
1283
- columnFamilies: string[];
1284
- transactions: number;
1285
- closables: number;
1286
- locks: number;
1287
- userSharedBuffers: number;
1288
- listenerCallbacks: number;
1390
+ type NativeTransaction = {
1391
+ id: number;
1392
+ new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
1393
+ abort(): void;
1394
+ commit(resolve: (retrySignal?: number) => void, reject: (err: Error) => void): void;
1395
+ commitSync(): void;
1396
+ get(keyLengthOrKeyBuffer: number | Buffer, resolve: (value: Buffer | number) => void, reject: (err: Error) => void, txnIdIgnored?: number, expectedVersion?: number): number;
1397
+ getCount(options?: RangeOptions): number;
1398
+ getSync(keyLengthOrKeyBuffer: number | Buffer): Buffer | number | undefined;
1399
+ getTimestamp(): number;
1400
+ putSync(key: Key, value: Buffer | Uint8Array, txnId?: number): void;
1401
+ removeSync(key: Key): void;
1402
+ setTimestamp(timestamp?: number): void;
1403
+ useLog(name: string | number): TransactionLog;
1289
1404
  };
1290
- type RegistryStatus = RegistryStatusDB[];
1291
- declare const constants: {
1292
- ALWAYS_CREATE_NEW_BUFFER_FLAG: number;
1293
- NOT_IN_MEMORY_CACHE_FLAG: number;
1294
- ONLY_IF_IN_MEMORY_CACHE_FLAG: number;
1295
- POPULATE_VERSION_FLAG: number;
1296
- FRESH_VERSION_FLAG: number;
1297
- /**
1298
- * Sentinel value resolved (not rejected) by `commit()` when
1299
- * `coordinatedRetry: true` and the transaction encountered an IsBusy
1300
- * conflict. JS should retry the transaction body immediately.
1301
- */
1302
- RETRY_NOW_VALUE: number;
1303
- TRANSACTION_LOG_TOKEN: number;
1304
- TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
1305
- TRANSACTION_LOG_FILE_HEADER_SIZE: number;
1306
- ITERATOR_REVERSE_FLAG: number;
1307
- ITERATOR_INCLUSIVE_END_FLAG: number;
1308
- ITERATOR_EXCLUSIVE_START_FLAG: number;
1309
- ITERATOR_INCLUDE_VALUES_FLAG: number;
1310
- ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
1311
- ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
1312
- ITERATOR_RESULT_DONE: number;
1313
- ITERATOR_RESULT_FAST: number;
1405
+ type LogBuffer = Buffer & {
1406
+ dataView: DataView;
1407
+ logId: number;
1408
+ size: number;
1314
1409
  };
1315
- declare const NativeDatabase: NativeDatabase;
1316
- declare const NativeTransaction: NativeTransaction;
1317
- declare const TransactionLog: TransactionLog;
1318
- declare const registryStatus: () => RegistryStatus;
1319
- declare const shutdown: () => void;
1320
- declare const currentThreadId: () => number;
1321
- /**
1322
- * Advises the kernel that the file-backed pages of every mapped transaction log
1323
- * are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
1324
- * without being freed — useful during replication catch-up, where a full read of
1325
- * the logs would otherwise inflate the container's reclaimable cache toward its
1326
- * cgroup limit. No-op on kernels < 5.4, macOS, and Windows.
1327
- *
1328
- * The transaction log registry is a process-global singleton shared across all
1329
- * worker threads, so a single call cools every worker's maps. Call it on an
1330
- * interval from one thread (e.g. an `unref()`ed timer on the main thread).
1331
- *
1332
- * @returns the number of maps cooled and total file-backed bytes advised.
1333
- */
1334
- declare const coolTransactionLogs: () => {
1335
- maps: number;
1336
- bytes: number;
1410
+ type TransactionLogQueryOptions = {
1411
+ start?: number;
1412
+ end?: number;
1413
+ exactStart?: boolean;
1414
+ startFromLastFlushed?: boolean;
1415
+ readUncommitted?: boolean;
1416
+ exclusiveStart?: boolean;
1337
1417
  };
1338
- declare const stats: {
1339
- StatsLevel: {
1340
- DisableAll: number;
1341
- ExceptTickers: number;
1342
- ExceptHistogramOrTimers: number;
1343
- ExceptTimers: number;
1344
- ExceptDetailedTimers: number;
1345
- ExceptTimeForMutex: number;
1346
- All: number;
1347
- };
1418
+ type TransactionEntry = {
1419
+ timestamp: number;
1420
+ data: Buffer;
1421
+ endTxn: boolean;
1348
1422
  };
1349
- //#endregion
1350
- //#region src/transaction.d.ts
1351
1423
  /**
1352
- * Sentinel value returned by `commit()` when `coordinatedRetry: true` and the
1353
- * transaction encountered an IsBusy conflict. The native layer parks on VT
1354
- * slots and resolves only after the conflicting transaction releases its write
1355
- * intent, so callers should retry immediately without any backoff delay.
1424
+ * A position within a transaction log, identifying a log file by its sequence
1425
+ * number and a byte `offset` within that file.
1356
1426
  */
1357
- declare const RETRY_NOW: number;
1427
+ type TransactionLogPosition = {
1428
+ sequence: number;
1429
+ offset: number;
1430
+ };
1358
1431
  /**
1359
- * Provides transaction level operations to a transaction callback.
1432
+ * A detailed statistics snapshot for a single transaction log store, returned
1433
+ * by {@link TransactionLog.getStats}. All sizes are in bytes; timestamps are
1434
+ * milliseconds since the Unix epoch.
1435
+ *
1436
+ * Memory note: `memory.mappedBytes` is virtual address space — the active write
1437
+ * file is mapped at the full configured `maxFileSize` on POSIX, so it does not
1438
+ * reflect resident memory. `memory.overlayBytes` (POSIX only; 0 on Windows) is
1439
+ * the file-backed portion and is the closer proxy for real consumption.
1360
1440
  */
1361
- declare class Transaction extends DBI {
1362
- #private;
1363
- /**
1364
- * Create a new transaction.
1365
- *
1366
- * @param store - The base store interface for this transaction.
1367
- * @param options - The options for the transaction.
1368
- */
1369
- constructor(store: Store, options?: NativeTransactionOptions);
1370
- /**
1371
- * Abort the transaction.
1372
- */
1373
- abort(): void;
1374
- /**
1375
- * Commit the transaction.
1376
- *
1377
- * Returns `RETRY_NOW` when `coordinatedRetry: true` and an IsBusy conflict
1378
- * was detected. The caller should retry the transaction body immediately.
1379
- */
1380
- commit(): Promise<typeof RETRY_NOW | void>;
1381
- /**
1382
- * Commit the transaction synchronously.
1383
- */
1384
- commitSync(): void;
1385
- /**
1386
- * Returns the transaction start timestamp in seconds. Defaults to the time at which
1387
- * the transaction was created.
1388
- *
1389
- * @returns The transaction start timestamp in seconds.
1390
- */
1391
- getTimestamp(): number;
1392
- /**
1393
- * Get the transaction id.
1394
- */
1395
- get id(): number;
1396
- /**
1397
- * Set the transaction start timestamp in seconds.
1398
- *
1399
- * @param timestamp - The timestamp to set in seconds.
1400
- */
1401
- setTimestamp(timestamp?: number): void;
1402
- }
1403
- //#endregion
1404
- //#region src/util.d.ts
1405
- type MaybePromise<T> = T | Promise<T>;
1406
- //#endregion
1407
- //#region src/dbi.d.ts
1408
- interface RocksDBOptions {
1409
- /**
1410
- * When `true`, RocksDB will do some enhancements for prefetching the data.
1411
- * Defaults to `true`. Note that RocksDB defaults this to `false`.
1412
- */
1441
+ type TransactionLogStats = {
1442
+ name: string;
1443
+ path: string;
1444
+ fileCount: number;
1445
+ currentSequenceNumber: number;
1446
+ oldestSequenceNumber: number;
1447
+ totalSizeBytes: number;
1448
+ currentFileSize: number;
1449
+ pendingTransactions: number;
1450
+ uncommittedTransactions: number;
1451
+ replayGapBytes: number;
1452
+ memory: {
1453
+ mappedBytes: number;
1454
+ overlayBytes: number;
1455
+ activeMaps: number;
1456
+ };
1457
+ nextLogPosition: TransactionLogPosition;
1458
+ lastFlushedPosition: TransactionLogPosition;
1459
+ lastCommittedPosition: TransactionLogPosition | null;
1460
+ purge: {
1461
+ oldestFileAgeMs: number;
1462
+ purgeableFiles: number;
1463
+ retainedUnflushedFiles: number;
1464
+ lastPurgeMs: number;
1465
+ };
1466
+ totals: {
1467
+ transactionsWritten: number;
1468
+ entriesWritten: number;
1469
+ bytesWritten: number;
1470
+ rotations: number;
1471
+ filesPurged: number;
1472
+ bytesPurged: number;
1473
+ purgeRuns: number;
1474
+ databaseFlushes: number;
1475
+ writeFailures: number;
1476
+ };
1477
+ config: {
1478
+ maxFileSize: number;
1479
+ retentionMs: number;
1480
+ maxAgeThreshold: number;
1481
+ };
1482
+ };
1483
+ type TransactionLog = {
1484
+ new (db: NativeDatabase, name: string): TransactionLog;
1485
+ addEntry(data: Buffer | Uint8Array, txnId?: number): void;
1486
+ getLogFileSize(sequenceId?: number): number;
1487
+ getStats(): TransactionLogStats;
1488
+ name: string;
1489
+ path: string;
1490
+ query(options?: TransactionLogQueryOptions): IterableIterator<TransactionEntry>;
1491
+ _currentLogBuffer: LogBuffer;
1492
+ _findPosition(timestamp: number): number;
1493
+ _getLastCommittedPosition(): Buffer;
1494
+ _getLastFlushed(): number;
1495
+ _getMemoryMapOfFile(sequenceId: number): LogBuffer | undefined;
1496
+ _lastCommittedPosition: Float64Array;
1497
+ _logBuffers: Map<number, WeakRef<LogBuffer>>;
1498
+ };
1499
+ /**
1500
+ * Shape of options that can be passed to the native iterator constructor for
1501
+ * the rare case of advanced RocksDB ReadOptions overrides. Common iterator
1502
+ * options are passed via the bitmask `flags` argument instead.
1503
+ */
1504
+ type NativeIteratorAdvancedOptions = {
1413
1505
  adaptiveReadahead?: boolean;
1414
- /**
1415
- * When `true`, RocksDB will prefetch some data async and apply it if reads
1416
- * are sequential and its internal automatic prefetching. Defaults to
1417
- * `true`. Note that RocksDB defaults this to `false`.
1418
- */
1419
1506
  asyncIO?: boolean;
1420
- /**
1421
- * When `true`, RocksDB will auto-tune the readahead size during scans
1422
- * internally based on the block cache data when block caching is enabled,
1423
- * an end key (e.g. upper bound) is set, and prefix is the same as the start
1424
- * key. Defaults to `true`.
1425
- */
1426
1507
  autoReadaheadSize?: boolean;
1427
- /**
1428
- * When `true`, after the iterator is closed, a background job is scheduled
1429
- * to flush the job queue and delete obsolete files. Defaults to `true`.
1430
- * Note that RocksDB defaults this to `false`.
1431
- */
1432
1508
  backgroundPurgeOnIteratorCleanup?: boolean;
1433
- /**
1434
- * When `true`, the iterator will fill the block cache. Filling the block
1435
- * cache is not desirable for bulk scans and could impact eviction order.
1436
- * Defaults to `false`. Note that RocksDB defaults this to `true`.
1437
- */
1438
1509
  fillCache?: boolean;
1439
- /**
1440
- * The RocksDB readahead size. RocksDB does auto-readahead for iterators
1441
- * when there is more than two reads for a table file. The readahead
1442
- * starts at 8KB and doubles on every additional read up to 256KB. This
1443
- * option can help if most of the range scans are large and if a larger
1444
- * readahead than that enabled by auto-readahead is needed. Using a large
1445
- * readahead size (> 2MB) can typically improve the performance of forward
1446
- * iteration on spinning disks. Defaults to `0`.
1447
- */
1448
1510
  readaheadSize?: number;
1449
- /**
1450
- * When `true`, creates a "tailing iterator" which is a special iterator
1451
- * that has a view of the complete database including newly added data and
1452
- * is optimized for sequential reads. This will return records that were
1453
- * inserted into the database after the creation of the iterator. Defaults
1454
- * to `false`.
1455
- */
1456
1511
  tailing?: boolean;
1457
- }
1458
- interface RangeOptions extends RocksDBOptions {
1459
- /**
1460
- * The range end key, otherwise known as the "upper bound". Defaults to
1461
- * the last key in the database.
1462
- */
1463
- end?: Key | Uint8Array;
1464
- /**
1465
- * When `true`, the iterator will exclude the first key if it matches the start key.
1466
- * Defaults to `false`.
1467
- */
1468
- exclusiveStart?: boolean;
1469
- /**
1470
- * When `true`, the iterator will include the last key if it matches the end
1471
- * key. Defaults to `false`.
1472
- */
1473
- inclusiveEnd?: boolean;
1474
- /**
1475
- * The range start key, otherwise known as the "lower bound". Defaults to
1476
- * the first key in the database.
1477
- */
1478
- start?: Key | Uint8Array;
1479
- }
1480
- interface IteratorOptions extends RangeOptions {
1481
- /**
1482
- * The maximum number of entries to yield. When set, iteration stops after
1483
- * `limit` entries regardless of the range bounds. Values <= 0 yield nothing.
1484
- * Unset means no limit.
1485
- */
1486
- limit?: number;
1487
- /**
1488
- * A specific key to match which may result in zero, one, or many values.
1489
- */
1490
- key?: Key;
1491
- /**
1492
- * When `true`, only returns the number of values for the given query.
1493
- */
1494
- onlyCount?: boolean;
1495
- /**
1496
- * When `true`, the iterator will iterate in reverse order. Defaults to
1497
- * `false`.
1498
- */
1499
- reverse?: boolean;
1500
- /**
1501
- * When `true`, decodes and returns the value. When `false`, the value is
1502
- * omitted. Defaults to `true`.
1503
- */
1504
- values?: boolean;
1505
- /**
1506
- * When `true`, the iterator will only return the values.
1507
- */
1508
- valuesOnly?: boolean;
1509
- }
1510
- interface DBITransactional {
1511
- transaction?: Transaction;
1512
- }
1512
+ };
1513
1513
  /**
1514
- * The base class for all database operations. This base class is shared by
1515
- * `RocksDatabase` and `Transaction`.
1516
- *
1517
- * This class is not meant to be used directly.
1514
+ * The result of a single native iterator step. A number value matches one of
1515
+ * the `ITERATOR_RESULT_*` constants. The slow-path object is returned when
1516
+ * the data does not fit in the shared key/value buffers, or when the decoder
1517
+ * needs a stable value buffer.
1518
1518
  */
1519
- declare class DBI<T extends DBITransactional | unknown = unknown> {
1520
- /**
1521
- * The RocksDB context for `get()`, `put()`, and `remove()`.
1522
- */
1523
- _context: StoreContext;
1524
- /**
1525
- * The database store instance. The store instance is tied to the database
1526
- * instance and shared with transaction instances.
1527
- */
1528
- store: Store;
1529
- /**
1530
- * Initializes the DBI context.
1531
- *
1532
- * @param store - The store instance.
1533
- * @param transaction - The transaction instance.
1534
- */
1535
- constructor(store: Store, transaction?: NativeTransaction);
1536
- /**
1537
- * Adds a listener for the given key.
1538
- *
1539
- * @param event - The event name to add the listener for.
1540
- * @param callback - The callback to add.
1541
- */
1542
- addListener(event: string, callback: (...args: any[]) => void): this;
1543
- /**
1544
- * Retrieves the value for the given key, then returns the decoded value.
1545
- */
1546
- get(key: Key, options?: GetOptions & T): MaybePromise<any | undefined>;
1547
- /**
1548
- * Retrieves the binary data for the given key. This is just like `get()`,
1549
- * but bypasses the decoder.
1550
- *
1551
- * Note: Used by HDBreplication.
1552
- */
1553
- getBinary(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
1554
- /**
1555
- * Synchronously retrieves the binary data for the given key.
1556
- */
1557
- getBinarySync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
1558
- /**
1559
- * Retrieves the binary data for the given key using a preallocated,
1560
- * reusable buffer. Data in the buffer is only valid until the next get
1561
- * operation (including cursor operations).
1562
- *
1563
- * Note: The reusable buffer slightly differs from a typical buffer:
1564
- * - `.length` is set to the size of the value
1565
- * - `.byteLength` is set to the size of the full allocated memory area for
1566
- * the buffer (usually much larger).
1567
- */
1568
- getBinaryFast(key: Key, options?: GetOptions & T): MaybePromise<Buffer | number | undefined>;
1569
- /**
1570
- * Synchronously retrieves the binary data for the given key using a
1571
- * preallocated, reusable buffer. Data in the buffer is only valid until the
1572
- * next get operation (including cursor operations).
1573
- */
1574
- getBinaryFastSync(key: Key, options?: GetOptions & T): Buffer | number | undefined;
1575
- /**
1576
- * Retrieves all keys within a range.
1577
- */
1578
- getKeys(options?: IteratorOptions & T): any | undefined;
1579
- /**
1580
- * Retrieves the number of keys within a range.
1581
- *
1582
- * @param options - The range options.
1583
- * @returns The number of keys within the range.
1584
- *
1585
- * @example
1586
- * ```typescript
1587
- * const total = db.getKeysCount();
1588
- * const range = db.getKeysCount({ start: 'a', end: 'z' });
1589
- * ```
1590
- */
1591
- getKeysCount(options?: RangeOptions & T): number;
1592
- /**
1593
- * Retrieves a range of keys and their values.
1594
- *
1595
- * @param options - The iterator options.
1596
- * @returns A range iterable.
1597
- *
1598
- * @example
1599
- * ```typescript
1600
- * for (const { key, value } of db.getRange()) {
1601
- * console.log({ key, value });
1602
- * }
1603
- *
1604
- * for (const { key, value } of db.getRange({ start: 'a', end: 'z' })) {
1605
- * console.log({ key, value });
1606
- * }
1607
- * ```
1608
- */
1609
- getRange(options?: IteratorOptions & T): any | undefined;
1610
- /**
1611
- * Synchronously retrieves the value for the given key, then returns the
1612
- * decoded value.
1613
- */
1614
- getSync(key: Key, options?: GetOptions & T): any | undefined;
1615
- /**
1616
- * Gets the number of listeners for the given key.
1617
- *
1618
- * @param event - The event name to get the listeners for.
1619
- * @returns The number of listeners for the given key.
1620
- */
1621
- listeners(event: string | BufferWithDataView): number;
1519
+ type NativeIteratorResult = number | {
1520
+ key: Buffer;
1521
+ value?: Buffer;
1522
+ };
1523
+ declare class NativeIteratorCls {
1524
+ constructor(context: StoreContext, flags: number, startKeyEnd: number, endKeyStart: number, endKeyEnd: number, options?: NativeIteratorAdvancedOptions);
1525
+ next(): NativeIteratorResult;
1526
+ return(): void;
1527
+ throw(err?: unknown): void;
1528
+ }
1529
+ type NativeDatabaseMode = "optimistic" | "pessimistic";
1530
+ type NativeDatabaseOptions = {
1531
+ dbWriteBufferSize?: number;
1532
+ disableWAL?: boolean;
1533
+ enableStats?: boolean;
1534
+ maxWriteBufferNumber?: number;
1535
+ maxWriteBufferSizeToMaintain?: number;
1536
+ mode?: NativeDatabaseMode;
1537
+ name?: string;
1538
+ noBlockCache?: boolean;
1539
+ parallelismThreads?: number;
1540
+ readOnly?: boolean;
1541
+ statsLevel?: (typeof stats.StatsLevel)[keyof typeof stats.StatsLevel];
1542
+ transactionLogMaxAgeThreshold?: number;
1543
+ transactionLogMaxSize?: number;
1544
+ transactionLogRetentionMs?: number;
1545
+ transactionLogsPath?: string;
1622
1546
  /**
1623
- * Notifies an event for the given key.
1624
- *
1625
- * @param event - The event name to emit the event for.
1626
- * @param args - The arguments to emit.
1627
- * @returns `true` if there were listeners, `false` otherwise.
1547
+ * When true, transaction writes to this column family invalidate the
1548
+ * VerificationTable slot for each written key at write time (not at
1549
+ * commit time). Enable only for column families whose records are
1550
+ * cached (e.g. the primary CF of a table). Default: false.
1628
1551
  */
1629
- notify(event: string, ...args: any[]): boolean;
1630
- /**
1631
- * Alias for `removeListener()`.
1632
- *
1633
- * @param event - The event name to remove the listener for.
1634
- * @param callback - The callback to remove.
1552
+ verificationTable?: boolean;
1553
+ writeBufferSize?: number;
1554
+ };
1555
+ type ResolveCallback<T> = (value: T) => void;
1556
+ type RejectCallback = (err: Error) => void;
1557
+ type UserSharedBufferCallback = () => void;
1558
+ type PurgeLogsOptions = {
1559
+ before?: number;
1560
+ destroy?: boolean;
1561
+ /**
1562
+ * When `true`, count the entries in each purged log file (extra work) and
1563
+ * return `PurgedLog[]` instead of the default `string[]` of file paths.
1635
1564
  */
1636
- off(event: string, callback: (...args: any[]) => void): this;
1565
+ includeEntryCounts?: boolean;
1566
+ name?: string;
1567
+ };
1568
+ /**
1569
+ * A purged transaction log file and the number of entries it held, returned by
1570
+ * `purgeLogs()` when `includeEntryCounts` is `true`.
1571
+ */
1572
+ type PurgedLog = {
1573
+ path: string;
1574
+ entries: number;
1575
+ };
1576
+ type NativeDatabase = {
1577
+ new (): NativeDatabase;
1578
+ addListener(event: string, callback: (...args: any[]) => void): void;
1579
+ backup(resolve: ResolveCallback<number>, reject: RejectCallback, backupDir: string, options?: BackupOptions): void;
1580
+ backupStream(resolve: ResolveCallback<void>, reject: RejectCallback, emit: (kind: number, data: string | Uint8Array, size: number, mtime: number) => Promise<void>, options?: {
1581
+ flushBeforeBackup?: boolean;
1582
+ transactionLogs?: boolean;
1583
+ }): void;
1584
+ clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1585
+ clearSync(): void;
1586
+ close(): void;
1587
+ compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
1588
+ compactSync(start?: Key, end?: Key): void;
1589
+ columns: string[];
1590
+ createCheckpoint(resolve: ResolveCallback<void>, reject: RejectCallback, targetPath: string): void;
1591
+ destroy(): void;
1592
+ drop(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1593
+ dropSync(): void;
1594
+ flush(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1595
+ flushSync(): void;
1596
+ notify(event: string | BufferWithDataView, args?: any[]): boolean;
1597
+ get(keyLengthOrKeyBuffer: number | Buffer, resolve: ResolveCallback<Buffer | number>, reject: RejectCallback, txnId?: number, expectedVersion?: number): number;
1598
+ getCount(options?: RangeOptions, txnId?: number): number;
1599
+ getDBIntProperty(propertyName: string): number | undefined;
1600
+ getDBProperty(propertyName: string): string | undefined;
1601
+ getMonotonicTimestamp(): number;
1602
+ getOldestSnapshotTimestamp(): number;
1603
+ getStat(statName: string): number | StatsHistogramData;
1604
+ getStats(all?: false): StatsDefault;
1605
+ getStats(all: true): StatsAll;
1606
+ getSync(keyLengthOrKeyBuffer: number | Buffer, flags: number, txnId?: number, expectedVersion?: number): Buffer;
1607
+ getUserSharedBuffer(key: BufferWithDataView, defaultBuffer: ArrayBuffer, callback?: UserSharedBufferCallback): ArrayBuffer;
1608
+ hasLock(key: BufferWithDataView): boolean;
1609
+ listeners(event: string | BufferWithDataView): number;
1610
+ listLogs(): string[];
1611
+ opened: boolean;
1612
+ open(path: string, options?: NativeDatabaseOptions): void;
1613
+ populateVersion(keyLengthOrKeyBuffer: number | Buffer, version: number): void;
1614
+ purgeLogs(options: PurgeLogsOptions & {
1615
+ includeEntryCounts: true;
1616
+ }): PurgedLog[];
1617
+ purgeLogs(options?: PurgeLogsOptions & {
1618
+ includeEntryCounts?: false;
1619
+ }): string[];
1620
+ purgeLogs(options?: PurgeLogsOptions): string[] | PurgedLog[];
1621
+ putSync(key: BufferWithDataView, value: any, txnId?: number): void;
1622
+ removeListener(event: string | BufferWithDataView, callback: () => void): boolean;
1623
+ removeSync(key: BufferWithDataView, txnId?: number): void;
1624
+ setDefaultKeyBuffer(buffer: Buffer | Uint8Array | null): void;
1625
+ setDefaultValueBuffer(buffer: Buffer | Uint8Array | null): void;
1626
+ setIteratorState(buffer: Buffer | Uint8Array): void;
1627
+ tryLock(key: BufferWithDataView, callback?: () => void): boolean;
1628
+ unlock(key: BufferWithDataView): void;
1629
+ useLog(name: string): TransactionLog;
1630
+ verifyVersion(keyLengthOrKeyBuffer: number | Buffer, version: number): boolean;
1631
+ withLock(key: BufferWithDataView, callback: () => void | Promise<void>): Promise<void>;
1632
+ };
1633
+ type RocksDatabaseConfig = {
1634
+ blockCacheSize?: number;
1637
1635
  /**
1638
- * Alias for `addListener()`.
1636
+ * Number of slots in the process-global verification table. Each slot is
1637
+ * 8 bytes; the default of 128K slots is 1 MB. Set to 0 to disable.
1639
1638
  *
1640
- * @param event - The event name to add the listener for.
1641
- * @param callback - The callback to add.
1639
+ * Must be configured before the first database is opened. Once the table
1640
+ * is materialized, attempts to change this value will throw.
1642
1641
  */
1643
- on(event: string, callback: (...args: any[]) => void): this;
1642
+ verificationTableEntries?: number;
1643
+ compactOnClose?: boolean;
1644
1644
  /**
1645
- * Adds a one-time listener, then automatically removes it.
1645
+ * Total memtable memory limit (bytes) shared across every database opened
1646
+ * in this process. When set, RocksDB uses a single `WriteBufferManager` so
1647
+ * write buffers are bounded process-wide rather than per database. 0 (the
1648
+ * default) disables the manager.
1646
1649
  *
1647
- * @param event - The event name to add the listener for.
1648
- * @param callback - The callback to add.
1650
+ * Can be updated at runtime; the new size takes effect on the existing
1651
+ * manager via `SetBufferSize`.
1649
1652
  */
1650
- once(event: string, callback: (...args: any[]) => void): this;
1653
+ writeBufferManagerSize?: number;
1651
1654
  /**
1652
- * Stores a value for the given key.
1655
+ * When `true`, memtable memory is "charged" against the shared block cache
1656
+ * so the block cache and write buffers draw from a single pool. During
1657
+ * write bursts the cache shrinks to make room for memtables; once
1658
+ * memtables flush, the cache can grow back into the reclaimed space.
1653
1659
  *
1654
- * @param key - The key to store the value for.
1655
- * @param value - The value to store.
1656
- * @param options - The put options.
1657
- * @returns The key and value.
1660
+ * Has no effect when the block cache is disabled (size 0) or
1661
+ * `writeBufferManagerSize` is 0. Must be set on the same `config()` call
1662
+ * that first enables the manager — changing it after the manager has been
1663
+ * created has no effect on the running instance.
1658
1664
  *
1659
- * @example
1660
- * ```typescript
1661
- * await db.put('a', 'b');
1662
- * ```
1665
+ * @default false
1663
1666
  */
1664
- put(key: Key, value: any, options?: PutOptions & T): Promise<void>;
1667
+ writeBufferManagerCostToCache?: boolean;
1665
1668
  /**
1666
- * Synchronously stores a value for the given key.
1667
- *
1668
- * @param key - The key to store the value for.
1669
- * @param value - The value to store.
1670
- * @param options - The put options.
1671
- * @returns The key and value.
1669
+ * When `true`, writes are stalled once the manager's `buffer_size` is
1670
+ * exceeded, providing a hard cap on memtable memory. When `false`,
1671
+ * memtables are allowed to grow past the limit and flushes are simply
1672
+ * scheduled more aggressively. Off by default to favor write throughput
1673
+ * over hard memory bounding.
1672
1674
  *
1673
- * @example
1674
- * ```typescript
1675
- * db.putSync('a', 'b');
1676
- * ```
1675
+ * @default false
1677
1676
  */
1678
- putSync(key: Key, value: any, options?: PutOptions & T): void;
1677
+ writeBufferManagerAllowStall?: boolean;
1678
+ };
1679
+ type RegistryStatusDB = {
1680
+ path: string;
1681
+ refCount: number;
1682
+ columnFamilies: string[];
1683
+ transactions: number;
1684
+ closables: number;
1685
+ locks: number;
1686
+ userSharedBuffers: number;
1687
+ listenerCallbacks: number;
1688
+ };
1689
+ type RegistryStatus = RegistryStatusDB[];
1690
+ declare const constants: {
1691
+ ALWAYS_CREATE_NEW_BUFFER_FLAG: number;
1692
+ NOT_IN_MEMORY_CACHE_FLAG: number;
1693
+ ONLY_IF_IN_MEMORY_CACHE_FLAG: number;
1694
+ POPULATE_VERSION_FLAG: number;
1695
+ FRESH_VERSION_FLAG: number;
1679
1696
  /**
1680
- * Removes a value for the given key. If the key does not exist, it will
1681
- * not error.
1682
- *
1683
- * @param key - The key to remove the value for.
1684
- * @param options - The remove options.
1685
- * @returns The key and value.
1686
- *
1687
- * @example
1688
- * ```typescript
1689
- * await db.remove('a');
1690
- * ```
1697
+ * Sentinel value resolved (not rejected) by `commit()` when
1698
+ * `coordinatedRetry: true` and the transaction encountered an IsBusy
1699
+ * conflict. JS should retry the transaction body immediately.
1691
1700
  */
1692
- remove(key: Key, options?: T): Promise<void>;
1701
+ RETRY_NOW_VALUE: number;
1702
+ TRANSACTION_LOG_TOKEN: number;
1703
+ TRANSACTION_LOG_ENTRY_HEADER_SIZE: number;
1704
+ TRANSACTION_LOG_FILE_HEADER_SIZE: number;
1705
+ ITERATOR_REVERSE_FLAG: number;
1706
+ ITERATOR_INCLUSIVE_END_FLAG: number;
1707
+ ITERATOR_EXCLUSIVE_START_FLAG: number;
1708
+ ITERATOR_INCLUDE_VALUES_FLAG: number;
1709
+ ITERATOR_NEEDS_STABLE_VALUE_BUFFER_FLAG: number;
1710
+ ITERATOR_CONTEXT_IS_TRANSACTION_FLAG: number;
1711
+ ITERATOR_RESULT_DONE: number;
1712
+ ITERATOR_RESULT_FAST: number;
1713
+ };
1714
+ declare const NativeDatabase: NativeDatabase;
1715
+ declare const NativeTransaction: NativeTransaction;
1716
+ declare const TransactionLog: TransactionLog;
1717
+ declare const registryStatus: () => RegistryStatus;
1718
+ declare const shutdown: () => void;
1719
+ declare const currentThreadId: () => number;
1720
+ /**
1721
+ * Advises the kernel that the file-backed pages of every mapped transaction log
1722
+ * are cold (Linux MADV_COLD), so they are reclaimed first under memory pressure
1723
+ * without being freed — useful during replication catch-up, where a full read of
1724
+ * the logs would otherwise inflate the container's reclaimable cache toward its
1725
+ * cgroup limit. No-op on kernels < 5.4, macOS, and Windows.
1726
+ *
1727
+ * The transaction log registry is a process-global singleton shared across all
1728
+ * worker threads, so a single call cools every worker's maps. Call it on an
1729
+ * interval from one thread (e.g. an `unref()`ed timer on the main thread).
1730
+ *
1731
+ * @returns the number of maps cooled and total file-backed bytes advised.
1732
+ */
1733
+ declare const coolTransactionLogs: () => {
1734
+ maps: number;
1735
+ bytes: number;
1736
+ };
1737
+ /**
1738
+ * Creates a native file lock using the specified file path (`flock` on POSIX,
1739
+ * `LockFileEx` on Windows). Returns an opaque non-zero token to pass to
1740
+ * `fileLockRelease`, or `0` if another holder — in any process, container, or
1741
+ * worker thread — currently has it. Throws if `file` is missing or on a hard
1742
+ * error. The OS handle is owned entirely in native code (no fd crosses into
1743
+ * JS), and the kernel releases the lock when the handle closes, including on
1744
+ * process death.
1745
+ */
1746
+ declare const tryFileLock: (file: string) => number;
1747
+ /**
1748
+ * Releases a file lock acquired via `tryFileLock`. A no-op for
1749
+ * token `0` or an unknown token.
1750
+ */
1751
+ declare const fileLockRelease: (token: number) => void;
1752
+ declare const stats: {
1753
+ StatsLevel: {
1754
+ DisableAll: number;
1755
+ ExceptTickers: number;
1756
+ ExceptHistogramOrTimers: number;
1757
+ ExceptTimers: number;
1758
+ ExceptDetailedTimers: number;
1759
+ ExceptTimeForMutex: number;
1760
+ All: number;
1761
+ };
1762
+ };
1763
+ //#endregion
1764
+ //#region src/backup-stream.d.ts
1765
+ /**
1766
+ * Options for streaming a backup via `db.backup(stream)`.
1767
+ */
1768
+ interface BackupStreamOptions {
1693
1769
  /**
1694
- * Removes a value for the given key. If the key does not exist, it will
1695
- * not error.
1696
- *
1697
- * @param key - The key to remove the value for.
1698
- * @param options - The remove options.
1699
- * @returns The key and value.
1700
- *
1701
- * @example
1702
- * ```typescript
1703
- * db.removeSync('a');
1704
- * ```
1770
+ * Flush the memtable before streaming. Defaults to `true` when the database
1771
+ * was opened with `disableWAL` (otherwise unflushed data would be missing
1772
+ * from the stream), and `false` otherwise — matching `db.backup(dir)`.
1705
1773
  */
1706
- removeSync(key: Key, options?: T): void;
1774
+ flushBeforeBackup?: boolean;
1707
1775
  /**
1708
- * Removes an event listener. You must specify the exact same callback that was
1709
- * used in `addListener()`.
1776
+ * Gzip-compress the archive before writing it to the stream, producing a
1777
+ * `.tar.gz` stream instead of a plain `.tar`. Defaults to `false`.
1710
1778
  *
1711
- * @param event - The event name to remove the listener for.
1712
- * @param callback - The callback to remove.
1779
+ * Compression runs in the runtime's `CompressionStream`, downstream of the tar
1780
+ * encoder, so end-to-end backpressure is preserved. RocksDB SST files are
1781
+ * usually already block-compressed, so the additional savings vary with the
1782
+ * data and the configured compression.
1713
1783
  */
1714
- removeListener(event: string, callback: (value?: any) => void): boolean;
1784
+ gzip?: boolean;
1715
1785
  /**
1716
- * Get or create a transaction log instance.
1717
- *
1718
- * @param name - The name of the transaction log.
1719
- * @returns The transaction log.
1786
+ * Also stream the transaction log store as `transaction_logs/<store>/…`
1787
+ * entries (each `*.txnlog` and `txn.state` file) after the database files.
1788
+ * Defaults to `false`. Extraction reconstructs them next to the database, and
1789
+ * their mtimes are preserved so the store's age-based rotation/retention stays
1790
+ * correct.
1720
1791
  */
1721
- useLog(name: string | number): TransactionLog;
1792
+ transactionLogs?: boolean;
1722
1793
  }
1723
1794
  //#endregion
1724
1795
  //#region src/database.d.ts
@@ -1823,6 +1894,47 @@ declare class RocksDatabase extends DBI<DBITransactional> {
1823
1894
  */
1824
1895
  backup(backupDir: string, options?: BackupOptions): Promise<number>;
1825
1896
  /**
1897
+ * Streams a consistent snapshot of the entire database to a `WritableStream`
1898
+ * as a tar archive, with no intermediate copy written to disk. Resolves once
1899
+ * the stream has been fully written and closed.
1900
+ *
1901
+ * Backpressure is honored end to end, so a slow consumer (e.g. a network or
1902
+ * S3 upload) paces the backup rather than buffering it in memory. The archive
1903
+ * unpacks with any tar tool into a directory that opens as a RocksDB database.
1904
+ *
1905
+ * @example
1906
+ * ```typescript
1907
+ * const file = await fetch(uploadUrl, { method: 'PUT', body: stream });
1908
+ * await db.backup(stream); // `stream` is the request's WritableStream
1909
+ * ```
1910
+ */
1911
+ backup(stream: WritableStream<Uint8Array>, options?: BackupStreamOptions): Promise<void>;
1912
+ /**
1913
+ * Creates a hardlinked, point-in-time, fully independent copy of the entire
1914
+ * database (all column families) at `targetPath` and resolves once written.
1915
+ *
1916
+ * Unlike a backup, a checkpoint is a normal, writable sibling database: open
1917
+ * it with {@link RocksDatabase.open} and it diverges independently from the
1918
+ * source. SST and blob files are hardlinked when `targetPath` is on the same
1919
+ * filesystem as the database and copied otherwise (other files such as the
1920
+ * MANIFEST are always copied), so the operation is near-instant on the same
1921
+ * filesystem. The memtable is flushed so the checkpoint includes the latest
1922
+ * writes even when the WAL is disabled.
1923
+ *
1924
+ * Parent directories are created as needed. `targetPath` itself must not
1925
+ * already exist (RocksDB creates the checkpoint directory) and rejects with
1926
+ * `Create checkpoint failed: target path exists` if it does. The caller is
1927
+ * responsible for eventual cleanup of the directory.
1928
+ *
1929
+ * @example
1930
+ * ```typescript
1931
+ * const db = RocksDatabase.open('/path/to/database');
1932
+ * await db.createCheckpoint('/path/to/checkpoint');
1933
+ * const branch = RocksDatabase.open('/path/to/checkpoint');
1934
+ * ```
1935
+ */
1936
+ createCheckpoint(targetPath: string): Promise<void>;
1937
+ /**
1826
1938
  * Compacts the entire key range of the database synchronously.
1827
1939
  * This triggers manual compaction which removes tombstones and reclaims space.
1828
1940
  *
@@ -2225,5 +2337,5 @@ declare const versions: {
2225
2337
  "rocksdb-js": string;
2226
2338
  };
2227
2339
  //#endregion
2228
- 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 };
2340
+ 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 TransactionLogPosition, type TransactionLogStats, backups, constants, coolTransactionLogs, currentThreadId, fileLockRelease, parseTransactionLog, registryStatus, shutdown, stats, tryFileLock, versions };
2229
2341
  //# sourceMappingURL=index.d.mts.map