@harperfast/rocksdb-js 1.3.0 → 1.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/bin/rocksdb-js.mjs +81 -19
- package/dist/index.cjs +23 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.mts +7 -2
- package/dist/index.mjs +23 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -19
package/dist/index.d.cts
CHANGED
|
@@ -1415,13 +1415,16 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1415
1415
|
//#endregion
|
|
1416
1416
|
//#region src/parse-transaction-log.d.ts
|
|
1417
1417
|
interface LogEntry {
|
|
1418
|
-
|
|
1418
|
+
anomalies?: string[];
|
|
1419
|
+
data?: Buffer;
|
|
1419
1420
|
flags: number;
|
|
1420
1421
|
length: number;
|
|
1421
1422
|
timestamp?: number;
|
|
1422
1423
|
}
|
|
1423
1424
|
interface TransactionLog$1 {
|
|
1425
|
+
anomalies: string[];
|
|
1424
1426
|
entries: LogEntry[];
|
|
1427
|
+
entryAnomalyCount: number;
|
|
1425
1428
|
timestamp: number;
|
|
1426
1429
|
size: number;
|
|
1427
1430
|
version: number;
|
|
@@ -1431,7 +1434,9 @@ interface TransactionLog$1 {
|
|
|
1431
1434
|
* @param path - The path to the transaction log file.
|
|
1432
1435
|
* @returns The transaction log.
|
|
1433
1436
|
*/
|
|
1434
|
-
declare function parseTransactionLog(path: string
|
|
1437
|
+
declare function parseTransactionLog(path: string, options?: {
|
|
1438
|
+
skipData?: boolean;
|
|
1439
|
+
}): TransactionLog$1;
|
|
1435
1440
|
//#endregion
|
|
1436
1441
|
//#region src/index.d.ts
|
|
1437
1442
|
declare const versions: {
|
package/dist/index.d.mts
CHANGED
|
@@ -1415,13 +1415,16 @@ declare class RocksDatabase extends DBI<DBITransactional> {
|
|
|
1415
1415
|
//#endregion
|
|
1416
1416
|
//#region src/parse-transaction-log.d.ts
|
|
1417
1417
|
interface LogEntry {
|
|
1418
|
-
|
|
1418
|
+
anomalies?: string[];
|
|
1419
|
+
data?: Buffer;
|
|
1419
1420
|
flags: number;
|
|
1420
1421
|
length: number;
|
|
1421
1422
|
timestamp?: number;
|
|
1422
1423
|
}
|
|
1423
1424
|
interface TransactionLog$1 {
|
|
1425
|
+
anomalies: string[];
|
|
1424
1426
|
entries: LogEntry[];
|
|
1427
|
+
entryAnomalyCount: number;
|
|
1425
1428
|
timestamp: number;
|
|
1426
1429
|
size: number;
|
|
1427
1430
|
version: number;
|
|
@@ -1431,7 +1434,9 @@ interface TransactionLog$1 {
|
|
|
1431
1434
|
* @param path - The path to the transaction log file.
|
|
1432
1435
|
* @returns The transaction log.
|
|
1433
1436
|
*/
|
|
1434
|
-
declare function parseTransactionLog(path: string
|
|
1437
|
+
declare function parseTransactionLog(path: string, options?: {
|
|
1438
|
+
skipData?: boolean;
|
|
1439
|
+
}): TransactionLog$1;
|
|
1435
1440
|
//#endregion
|
|
1436
1441
|
//#region src/index.d.ts
|
|
1437
1442
|
declare const versions: {
|
package/dist/index.mjs
CHANGED
|
@@ -570,6 +570,8 @@ const VALUE_BUFFER = createFixedBuffer(64 * 1024);
|
|
|
570
570
|
const ITERATOR_STATE_BUFFER = Buffer.allocUnsafeSlow(8);
|
|
571
571
|
const ITERATOR_STATE = new Uint32Array(ITERATOR_STATE_BUFFER.buffer, ITERATOR_STATE_BUFFER.byteOffset, 2);
|
|
572
572
|
const MAX_KEY_SIZE = 1024 * 1024;
|
|
573
|
+
const RESET_BUFFER_MODE = 1024;
|
|
574
|
+
const REUSE_BUFFER_MODE = 512;
|
|
573
575
|
const SAVE_BUFFER_SIZE = 8192;
|
|
574
576
|
/**
|
|
575
577
|
* A store wraps the `NativeDatabase` binding and database settings so that a
|
|
@@ -859,7 +861,7 @@ var Store = class {
|
|
|
859
861
|
encodeValue(value) {
|
|
860
862
|
if (value && value["binary-data"]) return value["binary-data"];
|
|
861
863
|
if (typeof this.encoder?.encode === "function") {
|
|
862
|
-
if (this.encoder.copyBuffers) return this.encoder.encode(value,
|
|
864
|
+
if (this.encoder.copyBuffers) return this.encoder.encode(value, REUSE_BUFFER_MODE | RESET_BUFFER_MODE);
|
|
863
865
|
const valueBuffer = this.encoder.encode(value);
|
|
864
866
|
if (typeof valueBuffer === "string") return Buffer.from(valueBuffer);
|
|
865
867
|
return valueBuffer;
|
|
@@ -1833,12 +1835,14 @@ var RocksDatabase = class RocksDatabase extends DBI {
|
|
|
1833
1835
|
//#endregion
|
|
1834
1836
|
//#region src/parse-transaction-log.ts
|
|
1835
1837
|
const { TRANSACTION_LOG_TOKEN } = constants;
|
|
1838
|
+
const MIN_VALID_TIMESTAMP = Date.UTC(2026, 0, 27);
|
|
1839
|
+
const VALID_FLAGS_MASK = 1;
|
|
1836
1840
|
/**
|
|
1837
1841
|
* Loads an entire transaction log file into memory.
|
|
1838
1842
|
* @param path - The path to the transaction log file.
|
|
1839
1843
|
* @returns The transaction log.
|
|
1840
1844
|
*/
|
|
1841
|
-
function parseTransactionLog(path) {
|
|
1845
|
+
function parseTransactionLog(path, options = {}) {
|
|
1842
1846
|
let stats;
|
|
1843
1847
|
try {
|
|
1844
1848
|
stats = statSync(path);
|
|
@@ -1862,7 +1866,10 @@ function parseTransactionLog(path) {
|
|
|
1862
1866
|
const version = read(1).readUInt8(0);
|
|
1863
1867
|
if (version !== 1) throw new Error(`Unsupported transaction log file version: ${version}`);
|
|
1864
1868
|
const timestamp = read(8).readDoubleBE(0);
|
|
1869
|
+
const anomalies = [];
|
|
1870
|
+
if (!Number.isFinite(timestamp) || timestamp < MIN_VALID_TIMESTAMP) anomalies.push(`Header timestamp ${timestamp} predates 2026-01-27 (possible corruption)`);
|
|
1865
1871
|
const entries = [];
|
|
1872
|
+
let entryAnomalyCount = 0;
|
|
1866
1873
|
while (fileOffset < size) {
|
|
1867
1874
|
const timestamp = read(8).readDoubleBE(0);
|
|
1868
1875
|
if (timestamp === 0) {
|
|
@@ -1872,15 +1879,25 @@ function parseTransactionLog(path) {
|
|
|
1872
1879
|
const length = read(4).readUInt32BE(0);
|
|
1873
1880
|
const flags = read(1).readUInt8(0);
|
|
1874
1881
|
const data = read(length);
|
|
1875
|
-
|
|
1882
|
+
const entryAnomalies = [];
|
|
1883
|
+
if (!Number.isFinite(timestamp) || timestamp < MIN_VALID_TIMESTAMP) entryAnomalies.push(`timestamp ${timestamp} predates 2026-01-27 (possible corruption)`);
|
|
1884
|
+
if ((flags & ~VALID_FLAGS_MASK) !== 0) entryAnomalies.push(`flags 0x${flags.toString(16).padStart(2, "0")} contains undefined bits (expected 0x00 or 0x01)`);
|
|
1885
|
+
const entry = {
|
|
1876
1886
|
timestamp,
|
|
1877
1887
|
length,
|
|
1878
1888
|
flags,
|
|
1879
|
-
data
|
|
1880
|
-
}
|
|
1889
|
+
data: options.skipData ? void 0 : Buffer.from(data)
|
|
1890
|
+
};
|
|
1891
|
+
if (entryAnomalies.length > 0) {
|
|
1892
|
+
entry.anomalies = entryAnomalies;
|
|
1893
|
+
entryAnomalyCount += entryAnomalies.length;
|
|
1894
|
+
}
|
|
1895
|
+
entries.push(entry);
|
|
1881
1896
|
}
|
|
1882
1897
|
return {
|
|
1898
|
+
anomalies,
|
|
1883
1899
|
entries,
|
|
1900
|
+
entryAnomalyCount,
|
|
1884
1901
|
timestamp,
|
|
1885
1902
|
size,
|
|
1886
1903
|
version
|
|
@@ -2073,7 +2090,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
|
|
|
2073
2090
|
//#region src/index.ts
|
|
2074
2091
|
const versions = {
|
|
2075
2092
|
rocksdb: version,
|
|
2076
|
-
"rocksdb-js": "1.
|
|
2093
|
+
"rocksdb-js": "1.4.0"
|
|
2077
2094
|
};
|
|
2078
2095
|
|
|
2079
2096
|
//#endregion
|