@harperfast/rocksdb-js 2.6.0 → 2.7.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.cts CHANGED
@@ -255,6 +255,18 @@ type StoreRemoveOptions = DBITransactional | unknown;
255
255
  type CompactOptions = {
256
256
  start?: Key;
257
257
  end?: Key;
258
+ /**
259
+ * Compact the bottommost level as well, rewriting every file in range.
260
+ *
261
+ * RocksDB skips the bottommost level by default when no compaction filter is installed, and
262
+ * that is where most of the data sits — so an ordinary `compact()` leaves it untouched. Since a
263
+ * changed `compression` algorithm only governs newly written files, rewriting that level is the
264
+ * only way to re-encode data that already exists.
265
+ *
266
+ * This rewrites the whole range regardless of whether RocksDB considers it worth doing, so it
267
+ * is as expensive as the data is large. Defaults to `false`.
268
+ */
269
+ bottommost?: boolean;
258
270
  };
259
271
  /**
260
272
  * A RocksDB block/blob compression algorithm. Which algorithms are actually
@@ -302,6 +314,27 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "compression" | "comp
302
314
  * @default 'lz4'
303
315
  */
304
316
  compression?: CompressionOption;
317
+ /**
318
+ * Apply `compression` to every column family in the database, not only the one being opened.
319
+ *
320
+ * RocksDB opens all of a database's column families in a single native call, and by default
321
+ * each of the ones you did not name keeps its persisted algorithm. That is right when codecs
322
+ * are chosen per table, but it leaves a caller that wants one codec for the whole database
323
+ * unable to say so: those families are already open at their old algorithm before it gets a
324
+ * chance to ask, and a column family's compression cannot be changed while it is open.
325
+ *
326
+ * Setting this applies the requested algorithm to all of them instead — including families
327
+ * that were persisted with a different one, which is the point when adopting a codec on a
328
+ * database that predates it.
329
+ *
330
+ * Only meaningful with an explicit `compression` (it throws otherwise), and only on the open
331
+ * that actually creates the database handle; later opens of the same path reuse that handle
332
+ * and cannot revisit the decision. As always, the algorithm governs newly written files —
333
+ * existing SST/blob files keep theirs until rewritten (see `compact({ bottommost: true })`).
334
+ *
335
+ * @default false
336
+ */
337
+ compressionForAllColumnFamilies?: boolean;
305
338
  decoder?: Encoder | null;
306
339
  encoder?: Encoder | null;
307
340
  encoding?: Encoding;
@@ -375,6 +408,11 @@ declare class Store {
375
408
  * store's column family. Normalized and applied when the database opens.
376
409
  */
377
410
  compression?: CompressionOption;
411
+ /**
412
+ * Whether `compression` applies to every column family in the database rather than just this
413
+ * store's. See `RocksDatabaseOptions.compressionForAllColumnFamilies`.
414
+ */
415
+ compressionForAllColumnFamilies: boolean;
378
416
  /**
379
417
  * Whether to disable the write ahead log.
380
418
  */
@@ -750,6 +788,15 @@ declare class Transaction extends DBI {
750
788
  * @param options - The options for the transaction.
751
789
  */
752
790
  constructor(store: Store, options?: NativeTransactionOptions);
791
+ /**
792
+ * Release the staged writes' verification-table write intents without
793
+ * closing the transaction, barring any later commit or write. For a
794
+ * transaction kept open only for its outstanding read iterators after the
795
+ * writes were replayed onto another transaction: otherwise other writers'
796
+ * coordinated-retry commits park on those intents until it is aborted.
797
+ * Reads keep working, including read-your-own-writes.
798
+ */
799
+ abandonWrites(): void;
753
800
  /**
754
801
  * Abort the transaction.
755
802
  */
@@ -1605,6 +1652,7 @@ type NativeTransactionOptions = {
1605
1652
  type NativeTransaction = {
1606
1653
  id: number;
1607
1654
  new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
1655
+ abandonWrites(): void;
1608
1656
  abort(): void;
1609
1657
  commit(resolve: (retrySignal?: number) => void, reject: (err: Error) => void): void;
1610
1658
  commitSync(): void;
@@ -1755,6 +1803,11 @@ type NativeDatabaseOptions = {
1755
1803
  * is algorithm-specific; omit to use the algorithm's default.
1756
1804
  */
1757
1805
  compressionLevel?: number;
1806
+ /**
1807
+ * Apply `compression` to every column family the underlying `DB::Open` opens, rather than
1808
+ * only the one named by `name`. Requires an explicit `compression`.
1809
+ */
1810
+ compressionForAllColumnFamilies?: boolean;
1758
1811
  dbWriteBufferSize?: number;
1759
1812
  disableWAL?: boolean;
1760
1813
  enableStats?: boolean;
@@ -1812,8 +1865,8 @@ type NativeDatabase = {
1812
1865
  clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1813
1866
  clearSync(): void;
1814
1867
  close(): void;
1815
- compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
1816
- compactSync(start?: Key, end?: Key): void;
1868
+ compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key, bottommost?: boolean): void;
1869
+ compactSync(start?: Key, end?: Key, bottommost?: boolean): void;
1817
1870
  columns: string[];
1818
1871
  createCheckpoint(resolve: ResolveCallback<void>, reject: RejectCallback, targetPath: string): void;
1819
1872
  destroy(): void;
package/dist/index.d.mts CHANGED
@@ -255,6 +255,18 @@ type StoreRemoveOptions = DBITransactional | unknown;
255
255
  type CompactOptions = {
256
256
  start?: Key;
257
257
  end?: Key;
258
+ /**
259
+ * Compact the bottommost level as well, rewriting every file in range.
260
+ *
261
+ * RocksDB skips the bottommost level by default when no compaction filter is installed, and
262
+ * that is where most of the data sits — so an ordinary `compact()` leaves it untouched. Since a
263
+ * changed `compression` algorithm only governs newly written files, rewriting that level is the
264
+ * only way to re-encode data that already exists.
265
+ *
266
+ * This rewrites the whole range regardless of whether RocksDB considers it worth doing, so it
267
+ * is as expensive as the data is large. Defaults to `false`.
268
+ */
269
+ bottommost?: boolean;
258
270
  };
259
271
  /**
260
272
  * A RocksDB block/blob compression algorithm. Which algorithms are actually
@@ -302,6 +314,27 @@ interface StoreOptions extends Omit<NativeDatabaseOptions, "compression" | "comp
302
314
  * @default 'lz4'
303
315
  */
304
316
  compression?: CompressionOption;
317
+ /**
318
+ * Apply `compression` to every column family in the database, not only the one being opened.
319
+ *
320
+ * RocksDB opens all of a database's column families in a single native call, and by default
321
+ * each of the ones you did not name keeps its persisted algorithm. That is right when codecs
322
+ * are chosen per table, but it leaves a caller that wants one codec for the whole database
323
+ * unable to say so: those families are already open at their old algorithm before it gets a
324
+ * chance to ask, and a column family's compression cannot be changed while it is open.
325
+ *
326
+ * Setting this applies the requested algorithm to all of them instead — including families
327
+ * that were persisted with a different one, which is the point when adopting a codec on a
328
+ * database that predates it.
329
+ *
330
+ * Only meaningful with an explicit `compression` (it throws otherwise), and only on the open
331
+ * that actually creates the database handle; later opens of the same path reuse that handle
332
+ * and cannot revisit the decision. As always, the algorithm governs newly written files —
333
+ * existing SST/blob files keep theirs until rewritten (see `compact({ bottommost: true })`).
334
+ *
335
+ * @default false
336
+ */
337
+ compressionForAllColumnFamilies?: boolean;
305
338
  decoder?: Encoder | null;
306
339
  encoder?: Encoder | null;
307
340
  encoding?: Encoding;
@@ -375,6 +408,11 @@ declare class Store {
375
408
  * store's column family. Normalized and applied when the database opens.
376
409
  */
377
410
  compression?: CompressionOption;
411
+ /**
412
+ * Whether `compression` applies to every column family in the database rather than just this
413
+ * store's. See `RocksDatabaseOptions.compressionForAllColumnFamilies`.
414
+ */
415
+ compressionForAllColumnFamilies: boolean;
378
416
  /**
379
417
  * Whether to disable the write ahead log.
380
418
  */
@@ -750,6 +788,15 @@ declare class Transaction extends DBI {
750
788
  * @param options - The options for the transaction.
751
789
  */
752
790
  constructor(store: Store, options?: NativeTransactionOptions);
791
+ /**
792
+ * Release the staged writes' verification-table write intents without
793
+ * closing the transaction, barring any later commit or write. For a
794
+ * transaction kept open only for its outstanding read iterators after the
795
+ * writes were replayed onto another transaction: otherwise other writers'
796
+ * coordinated-retry commits park on those intents until it is aborted.
797
+ * Reads keep working, including read-your-own-writes.
798
+ */
799
+ abandonWrites(): void;
753
800
  /**
754
801
  * Abort the transaction.
755
802
  */
@@ -1605,6 +1652,7 @@ type NativeTransactionOptions = {
1605
1652
  type NativeTransaction = {
1606
1653
  id: number;
1607
1654
  new (context: NativeDatabase, options?: NativeTransactionOptions): NativeTransaction;
1655
+ abandonWrites(): void;
1608
1656
  abort(): void;
1609
1657
  commit(resolve: (retrySignal?: number) => void, reject: (err: Error) => void): void;
1610
1658
  commitSync(): void;
@@ -1755,6 +1803,11 @@ type NativeDatabaseOptions = {
1755
1803
  * is algorithm-specific; omit to use the algorithm's default.
1756
1804
  */
1757
1805
  compressionLevel?: number;
1806
+ /**
1807
+ * Apply `compression` to every column family the underlying `DB::Open` opens, rather than
1808
+ * only the one named by `name`. Requires an explicit `compression`.
1809
+ */
1810
+ compressionForAllColumnFamilies?: boolean;
1758
1811
  dbWriteBufferSize?: number;
1759
1812
  disableWAL?: boolean;
1760
1813
  enableStats?: boolean;
@@ -1812,8 +1865,8 @@ type NativeDatabase = {
1812
1865
  clear(resolve: ResolveCallback<void>, reject: RejectCallback): void;
1813
1866
  clearSync(): void;
1814
1867
  close(): void;
1815
- compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key): void;
1816
- compactSync(start?: Key, end?: Key): void;
1868
+ compact(resolve: ResolveCallback<void>, reject: RejectCallback, start?: Key, end?: Key, bottommost?: boolean): void;
1869
+ compactSync(start?: Key, end?: Key, bottommost?: boolean): void;
1817
1870
  columns: string[];
1818
1871
  createCheckpoint(resolve: ResolveCallback<void>, reject: RejectCallback, targetPath: string): void;
1819
1872
  destroy(): void;
package/dist/index.mjs CHANGED
@@ -1213,9 +1213,10 @@ const MAX_KEY_SIZE = 1024 * 1024;
1213
1213
  const SAVE_BUFFER_SIZE = 8192;
1214
1214
  /**
1215
1215
  * Normalizes the public `compression` option into the primitive fields the
1216
- * native layer expects. When `option` is omitted, returns an empty object and
1217
- * lets the native layer apply the default (LZ4 when the build supports it, else
1218
- * RocksDB's own default). Throws a `TypeError` for a malformed option and an
1216
+ * native layer expects. When `option` is omitted, or is an object without an
1217
+ * `algorithm`, returns an empty object and lets the native layer apply the
1218
+ * default (LZ4 when the build supports it, else RocksDB's own default).
1219
+ * Throws a `TypeError` for a malformed option and an
1219
1220
  * `Error` for an algorithm that isn't supported by this build.
1220
1221
  */
1221
1222
  function normalizeCompression(option) {
@@ -1223,7 +1224,11 @@ function normalizeCompression(option) {
1223
1224
  let algorithm;
1224
1225
  let level;
1225
1226
  if (typeof option === "string") algorithm = option;
1226
- else if (typeof option === "object" && option.algorithm !== void 0) {
1227
+ else if (typeof option === "object" && !Array.isArray(option)) {
1228
+ if (option.algorithm === void 0 || option.algorithm === null) {
1229
+ if (option.level !== void 0 && option.level !== null) throw new TypeError("Compression level cannot be specified without an algorithm");
1230
+ return {};
1231
+ }
1227
1232
  algorithm = option.algorithm;
1228
1233
  if (option.level !== void 0 && option.level !== null) {
1229
1234
  const raw = option.level;
@@ -1275,6 +1280,11 @@ var Store = class {
1275
1280
  */
1276
1281
  compression;
1277
1282
  /**
1283
+ * Whether `compression` applies to every column family in the database rather than just this
1284
+ * store's. See `RocksDatabaseOptions.compressionForAllColumnFamilies`.
1285
+ */
1286
+ compressionForAllColumnFamilies = false;
1287
+ /**
1278
1288
  * Whether to disable the write ahead log.
1279
1289
  */
1280
1290
  disableWAL;
@@ -1433,6 +1443,7 @@ var Store = class {
1433
1443
  const { keyEncoding, readKey, writeKey } = initKeyEncoder(options?.keyEncoding, options?.keyEncoder);
1434
1444
  this.db = new NativeDatabase();
1435
1445
  this.compression = options?.compression;
1446
+ this.compressionForAllColumnFamilies = options?.compressionForAllColumnFamilies === true;
1436
1447
  this.dbWriteBufferSize = options?.dbWriteBufferSize;
1437
1448
  this.decoder = options?.decoder ?? null;
1438
1449
  this.disableWAL = options?.disableWAL ?? false;
@@ -1502,7 +1513,7 @@ var Store = class {
1502
1513
  const end = this.encodeKey(options.end);
1503
1514
  endBuffer = Buffer.from(end.subarray(end.start, end.end));
1504
1515
  }
1505
- return new Promise((resolve, reject) => this.db.compact(resolve, reject, startBuffer, endBuffer));
1516
+ return new Promise((resolve, reject) => this.db.compact(resolve, reject, startBuffer, endBuffer, options?.bottommost === true));
1506
1517
  }
1507
1518
  async backup(target, options) {
1508
1519
  if (typeof target !== "string" && typeof target?.getWriter === "function") return backupToStream(this.db, target, options);
@@ -1530,7 +1541,7 @@ var Store = class {
1530
1541
  const end = this.encodeKey(options.end);
1531
1542
  endBuffer = Buffer.from(end.subarray(end.start, end.end));
1532
1543
  }
1533
- this.db.compactSync(startBuffer, endBuffer);
1544
+ this.db.compactSync(startBuffer, endBuffer, options?.bottommost === true);
1534
1545
  }
1535
1546
  /**
1536
1547
  * Decodes a key from the database.
@@ -1747,6 +1758,7 @@ var Store = class {
1747
1758
  this.db.open(this.path, {
1748
1759
  compression,
1749
1760
  compressionLevel,
1761
+ compressionForAllColumnFamilies: this.compressionForAllColumnFamilies,
1750
1762
  dbWriteBufferSize: this.dbWriteBufferSize,
1751
1763
  disableWAL: this.disableWAL,
1752
1764
  enableStats: this.enableStats,
@@ -1929,7 +1941,7 @@ var Transaction = class extends DBI {
1929
1941
  if (store.readOnly) {
1930
1942
  super(store);
1931
1943
  this.#txn = { id: 0 };
1932
- this.abort = this.commitSync = this.setTimestamp = () => {};
1944
+ this.abandonWrites = this.abort = this.commitSync = this.setTimestamp = () => {};
1933
1945
  this.commit = async () => {};
1934
1946
  this.getTimestamp = () => 0;
1935
1947
  } else {
@@ -1939,6 +1951,17 @@ var Transaction = class extends DBI {
1939
1951
  }
1940
1952
  }
1941
1953
  /**
1954
+ * Release the staged writes' verification-table write intents without
1955
+ * closing the transaction, barring any later commit or write. For a
1956
+ * transaction kept open only for its outstanding read iterators after the
1957
+ * writes were replayed onto another transaction: otherwise other writers'
1958
+ * coordinated-retry commits park on those intents until it is aborted.
1959
+ * Reads keep working, including read-your-own-writes.
1960
+ */
1961
+ abandonWrites() {
1962
+ this.#txn.abandonWrites();
1963
+ }
1964
+ /**
1942
1965
  * Abort the transaction.
1943
1966
  */
1944
1967
  abort() {
@@ -3012,7 +3035,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
3012
3035
  //#region src/index.ts
3013
3036
  const versions = {
3014
3037
  rocksdb: version,
3015
- "rocksdb-js": "2.6.0"
3038
+ "rocksdb-js": "2.7.0"
3016
3039
  };
3017
3040
 
3018
3041
  //#endregion