@harperfast/rocksdb-js 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/index.cjs +80 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -0
- package/dist/index.d.mts +42 -0
- package/dist/index.mjs +80 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
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;
|
|
@@ -1361,6 +1365,60 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1361
1365
|
static config(options) {
|
|
1362
1366
|
config(options);
|
|
1363
1367
|
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Registers a process-wide event listener. Internal events emitted by the
|
|
1370
|
+
* native binding use namespaced keys (e.g. `'transactionLog:warning'`).
|
|
1371
|
+
*
|
|
1372
|
+
* Listeners are not tied to any specific database — they fire for every
|
|
1373
|
+
* matching event emitted in this process.
|
|
1374
|
+
*
|
|
1375
|
+
* @example
|
|
1376
|
+
* ```typescript
|
|
1377
|
+
* RocksDatabase.on('transactionLog:warning', (warning) => {
|
|
1378
|
+
* console.warn(warning);
|
|
1379
|
+
* });
|
|
1380
|
+
* ```
|
|
1381
|
+
*/
|
|
1382
|
+
static on(event, callback) {
|
|
1383
|
+
addGlobalListener(event, callback);
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Alias for {@link RocksDatabase.on}, mirroring the Node `EventEmitter` API.
|
|
1387
|
+
*/
|
|
1388
|
+
static addListener(event, callback) {
|
|
1389
|
+
addGlobalListener(event, callback);
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Removes a previously-registered process-wide event listener. The
|
|
1393
|
+
* callback identity must match the one passed to {@link RocksDatabase.on}.
|
|
1394
|
+
*
|
|
1395
|
+
* @returns `true` if a matching listener was removed.
|
|
1396
|
+
*/
|
|
1397
|
+
static off(event, callback) {
|
|
1398
|
+
return removeGlobalListener(event, callback);
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Alias for {@link RocksDatabase.off}, mirroring the Node `EventEmitter` API.
|
|
1402
|
+
*/
|
|
1403
|
+
static removeListener(event, callback) {
|
|
1404
|
+
return removeGlobalListener(event, callback);
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Returns the number of process-wide listeners registered for the given event.
|
|
1408
|
+
*/
|
|
1409
|
+
static listenerCount(event) {
|
|
1410
|
+
return globalListenerCount(event);
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Emits a process-wide event. Mostly intended for tests and as a peer to
|
|
1414
|
+
* {@link RocksDatabase.on} — native code should call `emitGlobalEvent` in
|
|
1415
|
+
* `napi/global_events.h` directly rather than round-tripping through JS.
|
|
1416
|
+
*
|
|
1417
|
+
* @returns `true` if there was at least one listener.
|
|
1418
|
+
*/
|
|
1419
|
+
static notify(event, ...args) {
|
|
1420
|
+
return globalNotify(event, args);
|
|
1421
|
+
}
|
|
1364
1422
|
destroy() {
|
|
1365
1423
|
this.store.db.destroy();
|
|
1366
1424
|
}
|
|
@@ -1834,7 +1892,7 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1834
1892
|
|
|
1835
1893
|
//#endregion
|
|
1836
1894
|
//#region src/parse-transaction-log.ts
|
|
1837
|
-
const { TRANSACTION_LOG_TOKEN } = constants;
|
|
1895
|
+
const { TRANSACTION_LOG_TOKEN, TRANSACTION_LOG_ENTRY_HEADER_SIZE: TRANSACTION_LOG_ENTRY_HEADER_SIZE$1 } = constants;
|
|
1838
1896
|
const MIN_VALID_TIMESTAMP = Date.UTC(2026, 0, 27);
|
|
1839
1897
|
const VALID_FLAGS_MASK = 1;
|
|
1840
1898
|
/**
|
|
@@ -1858,7 +1916,11 @@ function parseTransactionLog(path, options = {}) {
|
|
|
1858
1916
|
const buffer = Buffer.allocUnsafe(numBytes);
|
|
1859
1917
|
const bytesRead = readSync(fileHandle, buffer, 0, numBytes, fileOffset);
|
|
1860
1918
|
fileOffset += bytesRead;
|
|
1861
|
-
if (bytesRead !== numBytes)
|
|
1919
|
+
if (bytesRead !== numBytes) {
|
|
1920
|
+
const previewBytes = Math.min(bytesRead, 64);
|
|
1921
|
+
const preview = buffer.subarray(0, previewBytes).toString("hex");
|
|
1922
|
+
throw new Error(`Expected to read ${numBytes} bytes but only read ${bytesRead}, file offset: ${fileOffset.toString(16)}, file size: ${size}, file path: ${path}, buffer (first ${previewBytes} bytes): ${preview}`);
|
|
1923
|
+
}
|
|
1862
1924
|
return buffer;
|
|
1863
1925
|
};
|
|
1864
1926
|
try {
|
|
@@ -1878,6 +1940,11 @@ function parseTransactionLog(path, options = {}) {
|
|
|
1878
1940
|
}
|
|
1879
1941
|
const length = read(4).readUInt32BE(0);
|
|
1880
1942
|
const flags = read(1).readUInt8(0);
|
|
1943
|
+
const remaining = size - fileOffset;
|
|
1944
|
+
if (length > remaining) {
|
|
1945
|
+
const entryOffset = fileOffset - TRANSACTION_LOG_ENTRY_HEADER_SIZE$1;
|
|
1946
|
+
throw new Error(`Corrupt entry at offset ${entryOffset.toString(16)}: declared length ${length} exceeds ${remaining} bytes remaining (file size: ${size})`);
|
|
1947
|
+
}
|
|
1881
1948
|
const data = read(length);
|
|
1882
1949
|
const entryAnomalies = [];
|
|
1883
1950
|
if (!Number.isFinite(timestamp) || timestamp < MIN_VALID_TIMESTAMP) entryAnomalies.push(`timestamp ${timestamp} predates 2026-01-27 (possible corruption)`);
|
|
@@ -1997,14 +2064,17 @@ Object.defineProperty(TransactionLog.prototype, "query", { value({ start, end, e
|
|
|
1997
2064
|
try {
|
|
1998
2065
|
timestamp = dataView.getFloat64(position);
|
|
1999
2066
|
} catch (error) {
|
|
2000
|
-
error.message += ` at position ${position} of log ${logBuffer.logId} (size=${size}, log buffer length=${logBuffer.length})`;
|
|
2067
|
+
error.message += ` at position ${position.toString(16)} of log ${logBuffer.logId} (size=${size}, log buffer length=${logBuffer.length})`;
|
|
2001
2068
|
throw error;
|
|
2002
2069
|
}
|
|
2003
2070
|
if (!timestamp) return {
|
|
2004
2071
|
done: true,
|
|
2005
2072
|
value: void 0
|
|
2006
2073
|
};
|
|
2074
|
+
const limit = readUncommitted ? logBuffer.length : size;
|
|
2075
|
+
if (position + TRANSACTION_LOG_ENTRY_HEADER_SIZE > limit) throw new RangeError(`Corrupt transaction log: truncated entry header at position ${position.toString(16)} of log ${logBuffer.logId} (available=${limit - position})`);
|
|
2007
2076
|
const length = dataView.getUint32(position + 8);
|
|
2077
|
+
if (position + TRANSACTION_LOG_ENTRY_HEADER_SIZE + length > limit) throw new RangeError(`Corrupt transaction log entry at position ${position.toString(16)} of log ${logBuffer.logId}: declared length ${length} overruns the log (limit=${limit})`);
|
|
2008
2078
|
position += TRANSACTION_LOG_ENTRY_HEADER_SIZE;
|
|
2009
2079
|
let matchesRange;
|
|
2010
2080
|
if (foundExactStart) matchesRange = (!exclusiveStart || timestamp !== start) && timestamp < end;
|
|
@@ -2027,7 +2097,12 @@ Object.defineProperty(TransactionLog.prototype, "query", { value({ start, end, e
|
|
|
2027
2097
|
const { logId: latestLogId, size: latestSize } = loadLastPosition(transactionLog, !!readUncommitted);
|
|
2028
2098
|
size = latestSize;
|
|
2029
2099
|
if (latestLogId > logBuffer.logId) {
|
|
2030
|
-
|
|
2100
|
+
const nextLogBuffer = getLogMemoryMap(transactionLog, logBuffer.logId + 1);
|
|
2101
|
+
if (!nextLogBuffer) return {
|
|
2102
|
+
done: true,
|
|
2103
|
+
value: void 0
|
|
2104
|
+
};
|
|
2105
|
+
logBuffer = nextLogBuffer;
|
|
2031
2106
|
dataView = logBuffer.dataView;
|
|
2032
2107
|
size = logBuffer.size;
|
|
2033
2108
|
if (size == void 0) {
|
|
@@ -2090,7 +2165,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
2090
2165
|
//#region src/index.ts
|
|
2091
2166
|
const versions = {
|
|
2092
2167
|
rocksdb: version,
|
|
2093
|
-
"rocksdb-js": "1.
|
|
2168
|
+
"rocksdb-js": "1.5.0"
|
|
2094
2169
|
};
|
|
2095
2170
|
|
|
2096
2171
|
//#endregion
|