@harperfast/rocksdb-js 1.4.2 → 2.0.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
@@ -1146,6 +1146,48 @@ declare class RocksDatabase extends DBI<DBITransactional> {
1146
1146
  * ```
1147
1147
  */
1148
1148
  static config(options: RocksDatabaseConfig): void;
1149
+ /**
1150
+ * Registers a process-wide event listener. Internal events emitted by the
1151
+ * native binding use namespaced keys (e.g. `'transactionLog:warning'`).
1152
+ *
1153
+ * Listeners are not tied to any specific database — they fire for every
1154
+ * matching event emitted in this process.
1155
+ *
1156
+ * @example
1157
+ * ```typescript
1158
+ * RocksDatabase.on('transactionLog:warning', (warning) => {
1159
+ * console.warn(warning);
1160
+ * });
1161
+ * ```
1162
+ */
1163
+ static on(event: string, callback: (...args: any[]) => void): void;
1164
+ /**
1165
+ * Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
1166
+ */
1167
+ static addListener(event: string, callback: (...args: any[]) => void): void;
1168
+ /**
1169
+ * Removes a previously-registered process-wide event listener. The
1170
+ * callback identity must match the one passed to {@link RocksDatabase.on}.
1171
+ *
1172
+ * @returns `true` if a matching listener was removed.
1173
+ */
1174
+ static off(event: string, callback: (...args: any[]) => void): boolean;
1175
+ /**
1176
+ * Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
1177
+ */
1178
+ static removeListener(event: string, callback: (...args: any[]) => void): boolean;
1179
+ /**
1180
+ * Returns the number of process-wide listeners registered for the given event.
1181
+ */
1182
+ static listenerCount(event: string): number;
1183
+ /**
1184
+ * Emits a process-wide event. Mostly intended for tests and as a peer to
1185
+ * {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
1186
+ * `napi/global_events.h` directly rather than round-tripping through JS.
1187
+ *
1188
+ * @returns `true` if there was at least one listener.
1189
+ */
1190
+ static notify(event: string, ...args: any[]): boolean;
1149
1191
  destroy(): void;
1150
1192
  drop(): Promise<void>;
1151
1193
  dropSync(): void;
package/dist/index.d.mts CHANGED
@@ -1146,6 +1146,48 @@ declare class RocksDatabase extends DBI<DBITransactional> {
1146
1146
  * ```
1147
1147
  */
1148
1148
  static config(options: RocksDatabaseConfig): void;
1149
+ /**
1150
+ * Registers a process-wide event listener. Internal events emitted by the
1151
+ * native binding use namespaced keys (e.g. `'transactionLog:warning'`).
1152
+ *
1153
+ * Listeners are not tied to any specific database — they fire for every
1154
+ * matching event emitted in this process.
1155
+ *
1156
+ * @example
1157
+ * ```typescript
1158
+ * RocksDatabase.on('transactionLog:warning', (warning) => {
1159
+ * console.warn(warning);
1160
+ * });
1161
+ * ```
1162
+ */
1163
+ static on(event: string, callback: (...args: any[]) => void): void;
1164
+ /**
1165
+ * Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
1166
+ */
1167
+ static addListener(event: string, callback: (...args: any[]) => void): void;
1168
+ /**
1169
+ * Removes a previously-registered process-wide event listener. The
1170
+ * callback identity must match the one passed to {@link RocksDatabase.on}.
1171
+ *
1172
+ * @returns `true` if a matching listener was removed.
1173
+ */
1174
+ static off(event: string, callback: (...args: any[]) => void): boolean;
1175
+ /**
1176
+ * Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
1177
+ */
1178
+ static removeListener(event: string, callback: (...args: any[]) => void): boolean;
1179
+ /**
1180
+ * Returns the number of process-wide listeners registered for the given event.
1181
+ */
1182
+ static listenerCount(event: string): number;
1183
+ /**
1184
+ * Emits a process-wide event. Mostly intended for tests and as a peer to
1185
+ * {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
1186
+ * `napi/global_events.h` directly rather than round-tripping through JS.
1187
+ *
1188
+ * @returns `true` if there was at least one listener.
1189
+ */
1190
+ static notify(event: string, ...args: any[]): boolean;
1149
1191
  destroy(): void;
1150
1192
  drop(): Promise<void>;
1151
1193
  dropSync(): void;
package/dist/index.mjs CHANGED
@@ -55,6 +55,10 @@ function locateBinding() {
55
55
  }
56
56
  const binding = req(locateBinding());
57
57
  const config = binding.config;
58
+ const addGlobalListener = binding.addListener;
59
+ const removeGlobalListener = binding.removeListener;
60
+ const globalListenerCount = binding.listenerCount;
61
+ const globalNotify = binding.notify;
58
62
  const constants = binding.constants;
59
63
  const NativeDatabase = binding.Database;
60
64
  const NativeIterator = binding.Iterator;
@@ -570,8 +574,6 @@ const VALUE_BUFFER = createFixedBuffer(64 * 1024);
570
574
  const ITERATOR_STATE_BUFFER = Buffer.allocUnsafeSlow(8);
571
575
  const ITERATOR_STATE = new Uint32Array(ITERATOR_STATE_BUFFER.buffer, ITERATOR_STATE_BUFFER.byteOffset, 2);
572
576
  const MAX_KEY_SIZE = 1024 * 1024;
573
- const RESET_BUFFER_MODE = 1024;
574
- const REUSE_BUFFER_MODE = 512;
575
577
  const SAVE_BUFFER_SIZE = 8192;
576
578
  /**
577
579
  * A store wraps the `NativeDatabase` binding and database settings so that a
@@ -861,7 +863,7 @@ var Store = class {
861
863
  encodeValue(value) {
862
864
  if (value && value["binary-data"]) return value["binary-data"];
863
865
  if (typeof this.encoder?.encode === "function") {
864
- if (this.encoder.copyBuffers) return this.encoder.encode(value, REUSE_BUFFER_MODE | RESET_BUFFER_MODE);
866
+ if (this.encoder.copyBuffers) return this.encoder.encode(value, 1536);
865
867
  const valueBuffer = this.encoder.encode(value);
866
868
  if (typeof valueBuffer === "string") return Buffer.from(valueBuffer);
867
869
  return valueBuffer;
@@ -1361,6 +1363,60 @@ var RocksDatabase = class RocksDatabase extends DBI {
1361
1363
  static config(options) {
1362
1364
  config(options);
1363
1365
  }
1366
+ /**
1367
+ * Registers a process-wide event listener. Internal events emitted by the
1368
+ * native binding use namespaced keys (e.g. `'transactionLog:warning'`).
1369
+ *
1370
+ * Listeners are not tied to any specific database — they fire for every
1371
+ * matching event emitted in this process.
1372
+ *
1373
+ * @example
1374
+ * ```typescript
1375
+ * RocksDatabase.on('transactionLog:warning', (warning) => {
1376
+ * console.warn(warning);
1377
+ * });
1378
+ * ```
1379
+ */
1380
+ static on(event, callback) {
1381
+ addGlobalListener(event, callback);
1382
+ }
1383
+ /**
1384
+ * Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
1385
+ */
1386
+ static addListener(event, callback) {
1387
+ addGlobalListener(event, callback);
1388
+ }
1389
+ /**
1390
+ * Removes a previously-registered process-wide event listener. The
1391
+ * callback identity must match the one passed to {@link RocksDatabase.on}.
1392
+ *
1393
+ * @returns `true` if a matching listener was removed.
1394
+ */
1395
+ static off(event, callback) {
1396
+ return removeGlobalListener(event, callback);
1397
+ }
1398
+ /**
1399
+ * Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
1400
+ */
1401
+ static removeListener(event, callback) {
1402
+ return removeGlobalListener(event, callback);
1403
+ }
1404
+ /**
1405
+ * Returns the number of process-wide listeners registered for the given event.
1406
+ */
1407
+ static listenerCount(event) {
1408
+ return globalListenerCount(event);
1409
+ }
1410
+ /**
1411
+ * Emits a process-wide event. Mostly intended for tests and as a peer to
1412
+ * {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
1413
+ * `napi/global_events.h` directly rather than round-tripping through JS.
1414
+ *
1415
+ * @returns `true` if there was at least one listener.
1416
+ */
1417
+ static notify(event, ...args) {
1418
+ return globalNotify(event, args);
1419
+ }
1364
1420
  destroy() {
1365
1421
  this.store.db.destroy();
1366
1422
  }
@@ -1836,7 +1892,6 @@ var RocksDatabase = class RocksDatabase extends DBI {
1836
1892
  //#region src/parse-transaction-log.ts
1837
1893
  const { TRANSACTION_LOG_TOKEN, TRANSACTION_LOG_ENTRY_HEADER_SIZE: TRANSACTION_LOG_ENTRY_HEADER_SIZE$1 } = constants;
1838
1894
  const MIN_VALID_TIMESTAMP = Date.UTC(2026, 0, 27);
1839
- const VALID_FLAGS_MASK = 1;
1840
1895
  /**
1841
1896
  * Loads an entire transaction log file into memory.
1842
1897
  * @param path - The path to the transaction log file.
@@ -1890,7 +1945,7 @@ function parseTransactionLog(path, options = {}) {
1890
1945
  const data = read(length);
1891
1946
  const entryAnomalies = [];
1892
1947
  if (!Number.isFinite(timestamp) || timestamp < MIN_VALID_TIMESTAMP) entryAnomalies.push(`timestamp ${timestamp} predates 2026-01-27 (possible corruption)`);
1893
- if ((flags & ~VALID_FLAGS_MASK) !== 0) entryAnomalies.push(`flags 0x${flags.toString(16).padStart(2, "0")} contains undefined bits (expected 0x00 or 0x01)`);
1948
+ if ((flags & -2) !== 0) entryAnomalies.push(`flags 0x${flags.toString(16).padStart(2, "0")} contains undefined bits (expected 0x00 or 0x01)`);
1894
1949
  const entry = {
1895
1950
  timestamp,
1896
1951
  length,
@@ -2107,7 +2162,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
2107
2162
  //#region src/index.ts
2108
2163
  const versions = {
2109
2164
  rocksdb: version,
2110
- "rocksdb-js": "1.4.2"
2165
+ "rocksdb-js": "2.0.0"
2111
2166
  };
2112
2167
 
2113
2168
  //#endregion