nedb-engine 20.21.22 → 20.22.23

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 CHANGED
@@ -129,9 +129,13 @@ traversable — and the same hash chain that keeps it honest also protects it.
129
129
 
130
130
  ## Boot hydration
131
131
 
132
- Set `NITRO_NEDB_HYDRATION=true` in the process that opens the database. On an exclusive durable Rust open, the engine loads current document IDs and live records into RAM before open returns. Embedded clients and the HTTP daemon use this same open path. Writes refresh the resident state and deletes remove the live entry. The DAG retains the version history on disk.
132
+ Set `NITRO_NEDB_HYDRATION=true` in the process that opens the database. On the first exclusive open of a durable native store, the engine loads the live records and current IDs into memory, then writes `checkpoints/native-live-v1.bin` beside the database's `MANIFEST`. Allow time for this first pass and size RAM for the live dataset.
133
133
 
134
- In the Python engine, ordinary replay already builds resident state. A portal open with hydration enabled loads the sealed checkpoint into the in-memory version store before replaying the tail. Size memory for the live dataset and allow time at startup to read it. The flag defaults to off.
134
+ On subsequent opens, the native Python binding and HTTP daemon read the checkpoint and start serving while a background worker warms the current ID index. Current ID pointers still determine which version is visible. This includes writes and deletions made since the checkpoint. A query that needs an index the worker is still warming can incur disk reads.
135
+
136
+ After hydration the engine replaces the same checkpoint atomically. Each store retains one completed checkpoint. With a managed native Python handle, call `core.request_hydration_checkpoint()` to queue a fresh checkpoint at closing time. A true return value means the worker accepted the request. The engine logs completion after replacing the file. Encrypted stores encrypt the checkpoint with the store key. An unreadable or damaged checkpoint triggers a rebuild from the store. Keep the database files when backing up or moving the store, including the DAG and its indexes.
137
+
138
+ The flag defaults to off. The separate pure-Python engine uses its existing AOF and portal checkpoint formats. With hydration enabled, a portal open loads its sealed checkpoint into the in-memory version store before replaying the tail.
135
139
 
136
140
  ## Portals — data stays on disk, access is immediate · *new*
137
141
 
package/index.d.ts CHANGED
@@ -1,64 +1,64 @@
1
- // nedb-engine — public type surface.
2
- //
3
- // Runtime behavior (durable-mode auto-flush-on-exit) is added by the wrapper in
4
- // index.js; the type surface is exactly the generated native binding's.
5
- export * from './native';
6
-
7
- // ── wrap adapter family (wrap/*.js) ─────────────────────────────────────────
8
-
9
- /** Options accepted by every wrap_* constructor. */
10
- export interface WrapOptions {
11
- /** Logical database name (default "default"). */
12
- dbName?: string;
13
- /** HTTP nedbd server (v1 AOF, `--dag` v2, `--dag-v3` v3). Overrides embedded DAG. */
14
- nedbdUrl?: string;
15
- /** Bearer token for nedbd (NEDBD_TOKEN on the server). */
16
- nedbdToken?: string;
17
- /** Durable DAG store directory (embedded mode). */
18
- dagPath?: string;
19
- /** 64-hex TMK → AES-256-GCM at-rest encryption (embedded DAG mode). */
20
- dagTmk?: string;
21
- /** Explicit NedbCore class (testing / custom builds). */
22
- native?: unknown;
23
- }
24
-
25
- /** The `.nedb` attribute — full NEDB layer-2 API. */
26
- export interface NedbSurface {
27
- register(pattern: string, collection: string, opts?: {
28
- idExtractor?: (key: string) => string;
29
- valueParser?: (raw: unknown) => Record<string, unknown>;
30
- valueType?: 'string' | 'hash' | 'json';
31
- }): NedbSurface;
32
- backfill(opts?: { pattern?: string; collection?: string; batchSize?: number }): number;
33
- shadowWrites: boolean;
34
- readonly engineKind: 'dag-embedded' | 'nedbd-http' | 'aof-embedded';
35
-
36
- put(coll: string, id: string, doc: Record<string, unknown>): Record<string, unknown>;
37
- get(coll: string, id: string, asOf?: number): Record<string, unknown> | null;
38
- query(nql: string): Array<Record<string, unknown>>;
39
- createIndex(coll: string, field: string, kind?: string): void;
40
- delete(coll: string, id: string): void;
41
- link(frm: string, rel: string, to: string): void;
42
- unlink(frm: string, rel: string, to: string): void;
43
- neighbors(frm: string, rel: string, asOf?: number): string[];
44
- inbound(to: string, rel: string, asOf?: number): string[];
45
- verify(): boolean;
46
- readonly head: string;
47
- readonly seq: number;
48
- checkpoint(): string;
49
- /** DAG-native: latest node (null on non-DAG backends). */
50
- tip(): Record<string, unknown> | null;
51
- /** DAG-native: changefeed page, after_seq exclusive. */
52
- since(afterSeq: number | bigint, limit?: number): {
53
- nodes: Array<Record<string, unknown>>; from_seq: number; to_seq: number;
54
- head_seq: number; has_more: boolean;
55
- };
56
- /** DAG-native: replication readiness. */
57
- scanStatus(): { scan_complete: boolean; tip_seq: number; indexed_count: number; [k: string]: unknown };
58
- }
59
-
60
- export declare function wrapRedis<T extends object = object>(client: T, opts?: WrapOptions): T & { nedb: NedbSurface };
61
- export declare function wrapSqlite<T extends object = object>(conn: T, opts?: WrapOptions): T & { nedb: NedbSurface };
62
- export declare function wrapMysql<T extends object = object>(conn: T, opts?: WrapOptions): T & { nedb: NedbSurface };
63
- export declare function wrapPg<T extends object = object>(conn: T, opts?: WrapOptions): T & { nedb: NedbSurface };
64
- export declare function wrapMongo<T extends object = object>(client: T, opts?: WrapOptions): T & { nedb: NedbSurface };
1
+ // nedb-engine — public type surface.
2
+ //
3
+ // Runtime behavior (durable-mode auto-flush-on-exit) is added by the wrapper in
4
+ // index.js; the type surface is exactly the generated native binding's.
5
+ export * from './native';
6
+
7
+ // ── wrap adapter family (wrap/*.js) ─────────────────────────────────────────
8
+
9
+ /** Options accepted by every wrap_* constructor. */
10
+ export interface WrapOptions {
11
+ /** Logical database name (default "default"). */
12
+ dbName?: string;
13
+ /** HTTP nedbd server (v1 AOF, `--dag` v2, `--dag-v3` v3). Overrides embedded DAG. */
14
+ nedbdUrl?: string;
15
+ /** Bearer token for nedbd (NEDBD_TOKEN on the server). */
16
+ nedbdToken?: string;
17
+ /** Durable DAG store directory (embedded mode). */
18
+ dagPath?: string;
19
+ /** 64-hex TMK → AES-256-GCM at-rest encryption (embedded DAG mode). */
20
+ dagTmk?: string;
21
+ /** Explicit NedbCore class (testing / custom builds). */
22
+ native?: unknown;
23
+ }
24
+
25
+ /** The `.nedb` attribute — full NEDB layer-2 API. */
26
+ export interface NedbSurface {
27
+ register(pattern: string, collection: string, opts?: {
28
+ idExtractor?: (key: string) => string;
29
+ valueParser?: (raw: unknown) => Record<string, unknown>;
30
+ valueType?: 'string' | 'hash' | 'json';
31
+ }): NedbSurface;
32
+ backfill(opts?: { pattern?: string; collection?: string; batchSize?: number }): number;
33
+ shadowWrites: boolean;
34
+ readonly engineKind: 'dag-embedded' | 'nedbd-http' | 'aof-embedded';
35
+
36
+ put(coll: string, id: string, doc: Record<string, unknown>): Record<string, unknown>;
37
+ get(coll: string, id: string, asOf?: number): Record<string, unknown> | null;
38
+ query(nql: string): Array<Record<string, unknown>>;
39
+ createIndex(coll: string, field: string, kind?: string): void;
40
+ delete(coll: string, id: string): void;
41
+ link(frm: string, rel: string, to: string): void;
42
+ unlink(frm: string, rel: string, to: string): void;
43
+ neighbors(frm: string, rel: string, asOf?: number): string[];
44
+ inbound(to: string, rel: string, asOf?: number): string[];
45
+ verify(): boolean;
46
+ readonly head: string;
47
+ readonly seq: number;
48
+ checkpoint(): string;
49
+ /** DAG-native: latest node (null on non-DAG backends). */
50
+ tip(): Record<string, unknown> | null;
51
+ /** DAG-native: changefeed page, after_seq exclusive. */
52
+ since(afterSeq: number | bigint, limit?: number): {
53
+ nodes: Array<Record<string, unknown>>; from_seq: number; to_seq: number;
54
+ head_seq: number; has_more: boolean;
55
+ };
56
+ /** DAG-native: replication readiness. */
57
+ scanStatus(): { scan_complete: boolean; tip_seq: number; indexed_count: number; [k: string]: unknown };
58
+ }
59
+
60
+ export declare function wrapRedis<T extends object = object>(client: T, opts?: WrapOptions): T & { nedb: NedbSurface };
61
+ export declare function wrapSqlite<T extends object = object>(conn: T, opts?: WrapOptions): T & { nedb: NedbSurface };
62
+ export declare function wrapMysql<T extends object = object>(conn: T, opts?: WrapOptions): T & { nedb: NedbSurface };
63
+ export declare function wrapPg<T extends object = object>(conn: T, opts?: WrapOptions): T & { nedb: NedbSurface };
64
+ export declare function wrapMongo<T extends object = object>(client: T, opts?: WrapOptions): T & { nedb: NedbSurface };
package/index.js CHANGED
@@ -1,84 +1,84 @@
1
- // SPDX-FileCopyrightText: 2026 INTERCHAINED LLC
2
- // SPDX-License-Identifier: BUSL-1.1
3
- // NEDB · © 2026 INTERCHAINED LLC × Eth-Interchained × Vex (Claude Opus 5)
4
-
5
- 'use strict';
6
- // nedb-engine — durable-mode auto-flush-on-exit wrapper.
7
- //
8
- // The native addon (generated napi binding in ./native.js) exposes `NedbCore`.
9
- // A durable `NedbCore.open(path)` buffers writes in the engine's id-index WAL and
10
- // only makes them durable on `flush()`; a hard exit (Ctrl+C, `SIGTERM` from an
11
- // orchestrator, `pm2 stop`) that never runs an explicit flush would lose writes
12
- // staged since the last flush.
13
- //
14
- // We close that gap the libuv-cooperative way — `process.on('SIGINT'|'SIGTERM'
15
- // |'exit', () => db.flush())` — NOT a C-level signal handler inside the addon,
16
- // which would clobber libuv's own signal machinery. In-memory databases
17
- // (`new NedbCore()`) are never armed; there is nothing to flush.
18
- //
19
- // Escape hatch: set NEDB_NO_EXIT_FLUSH=1 to leave signal handling entirely to
20
- // the host app (it can still call `db.flush()` itself).
21
- //
22
- // © INTERCHAINED LLC × Vex (Interchained AI fleet: GLM · Claude · Opus · Fable · GPT-6)
23
- const native = require('./native.js');
24
-
25
- const Native = native.NedbCore;
26
-
27
- // The napi class defines `open` as a NON-writable, NON-configurable static, so the
28
- // 2.5.x wrapper's `NedbCore.open = …` threw ("Cannot assign to read only property")
29
- // — and CI's `napi build` was overwriting this file with the generated loader
30
- // anyway, so the published package never carried the wrapper at all. Both fixed
31
- // in 2.8.5: wrap by SUBCLASS (an own static on the subclass shadows the parent's),
32
- // build with `--js native.js` so this file survives, and gate the publish on
33
- // `NedbCore.__exitFlushWrapped` (see test/durability.test.mjs).
34
- let NedbCore = Native;
35
- if (Native && typeof Native.open === 'function' && !Native.__exitFlushWrapped) {
36
- // Durable handles opened in this process. Strong refs: a durable DB is meant to
37
- // live for the process, and we must be able to flush it on the way out.
38
- const live = new Set();
39
- let armed = false;
40
-
41
- const flushAll = () => {
42
- for (const db of live) {
43
- try {
44
- db.flush();
45
- } catch (_) {
46
- // Best-effort on shutdown — never throw out of an exit handler.
47
- }
48
- }
49
- };
50
-
51
- const arm = () => {
52
- if (armed || process.env.NEDB_NO_EXIT_FLUSH) return;
53
- armed = true;
54
- // 'exit' fires on normal termination; handlers must be synchronous, and
55
- // db.flush() is a synchronous native call — so this is safe and sufficient
56
- // for clean exits and uncaught-exception exits.
57
- process.on('exit', flushAll);
58
- // Registering a SIGINT/SIGTERM listener SUPPRESSES Node's default
59
- // termination, so once we listen we own the exit: flush, then terminate with
60
- // the conventional 128+signum status.
61
- const onSignal = (signum) => () => {
62
- flushAll();
63
- process.exit(128 + signum);
64
- };
65
- process.on('SIGINT', onSignal(2));
66
- process.on('SIGTERM', onSignal(15));
67
- };
68
-
69
- NedbCore = class NedbCore extends Native {
70
- static open(path) {
71
- const db = Native.open(path);
72
- live.add(db);
73
- arm();
74
- return db;
75
- }
76
- };
77
- // Mark so a re-require (or a wrapped re-export) never double-wraps.
78
- Object.defineProperty(NedbCore, '__exitFlushWrapped', { value: true, enumerable: false });
79
- }
80
-
81
- module.exports = { ...native, NedbCore };
82
- // Explicit named re-export so ESM `import { NedbCore } from 'nedb-engine'` (used
83
- // by the test suite) resolves the class through cjs-module-lexer.
84
- module.exports.NedbCore = NedbCore;
1
+ // SPDX-FileCopyrightText: 2026 INTERCHAINED LLC
2
+ // SPDX-License-Identifier: BUSL-1.1
3
+ // NEDB · © 2026 INTERCHAINED LLC × Eth-Interchained × Vex (Claude Opus 5)
4
+
5
+ 'use strict';
6
+ // nedb-engine — durable-mode auto-flush-on-exit wrapper.
7
+ //
8
+ // The native addon (generated napi binding in ./native.js) exposes `NedbCore`.
9
+ // A durable `NedbCore.open(path)` buffers writes in the engine's id-index WAL and
10
+ // only makes them durable on `flush()`; a hard exit (Ctrl+C, `SIGTERM` from an
11
+ // orchestrator, `pm2 stop`) that never runs an explicit flush would lose writes
12
+ // staged since the last flush.
13
+ //
14
+ // We close that gap the libuv-cooperative way — `process.on('SIGINT'|'SIGTERM'
15
+ // |'exit', () => db.flush())` — NOT a C-level signal handler inside the addon,
16
+ // which would clobber libuv's own signal machinery. In-memory databases
17
+ // (`new NedbCore()`) are never armed; there is nothing to flush.
18
+ //
19
+ // Escape hatch: set NEDB_NO_EXIT_FLUSH=1 to leave signal handling entirely to
20
+ // the host app (it can still call `db.flush()` itself).
21
+ //
22
+ // © INTERCHAINED LLC × Vex (Interchained AI fleet: GLM · Claude · Opus · Fable · GPT-6)
23
+ const native = require('./native.js');
24
+
25
+ const Native = native.NedbCore;
26
+
27
+ // The napi class defines `open` as a NON-writable, NON-configurable static, so the
28
+ // 2.5.x wrapper's `NedbCore.open = …` threw ("Cannot assign to read only property")
29
+ // — and CI's `napi build` was overwriting this file with the generated loader
30
+ // anyway, so the published package never carried the wrapper at all. Both fixed
31
+ // in 2.8.5: wrap by SUBCLASS (an own static on the subclass shadows the parent's),
32
+ // build with `--js native.js` so this file survives, and gate the publish on
33
+ // `NedbCore.__exitFlushWrapped` (see test/durability.test.mjs).
34
+ let NedbCore = Native;
35
+ if (Native && typeof Native.open === 'function' && !Native.__exitFlushWrapped) {
36
+ // Durable handles opened in this process. Strong refs: a durable DB is meant to
37
+ // live for the process, and we must be able to flush it on the way out.
38
+ const live = new Set();
39
+ let armed = false;
40
+
41
+ const flushAll = () => {
42
+ for (const db of live) {
43
+ try {
44
+ db.flush();
45
+ } catch (_) {
46
+ // Best-effort on shutdown — never throw out of an exit handler.
47
+ }
48
+ }
49
+ };
50
+
51
+ const arm = () => {
52
+ if (armed || process.env.NEDB_NO_EXIT_FLUSH) return;
53
+ armed = true;
54
+ // 'exit' fires on normal termination; handlers must be synchronous, and
55
+ // db.flush() is a synchronous native call — so this is safe and sufficient
56
+ // for clean exits and uncaught-exception exits.
57
+ process.on('exit', flushAll);
58
+ // Registering a SIGINT/SIGTERM listener SUPPRESSES Node's default
59
+ // termination, so once we listen we own the exit: flush, then terminate with
60
+ // the conventional 128+signum status.
61
+ const onSignal = (signum) => () => {
62
+ flushAll();
63
+ process.exit(128 + signum);
64
+ };
65
+ process.on('SIGINT', onSignal(2));
66
+ process.on('SIGTERM', onSignal(15));
67
+ };
68
+
69
+ NedbCore = class NedbCore extends Native {
70
+ static open(path) {
71
+ const db = Native.open(path);
72
+ live.add(db);
73
+ arm();
74
+ return db;
75
+ }
76
+ };
77
+ // Mark so a re-require (or a wrapped re-export) never double-wraps.
78
+ Object.defineProperty(NedbCore, '__exitFlushWrapped', { value: true, enumerable: false });
79
+ }
80
+
81
+ module.exports = { ...native, NedbCore };
82
+ // Explicit named re-export so ESM `import { NedbCore } from 'nedb-engine'` (used
83
+ // by the test suite) resolves the class through cjs-module-lexer.
84
+ module.exports.NedbCore = NedbCore;
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/nesql-linux-arm64 CHANGED
Binary file
Binary file
package/nesql-linux-x64 CHANGED
Binary file
Binary file
package/nesql-win-x64.exe CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nedb-engine",
3
- "version": "20.21.22",
3
+ "version": "20.22.23",
4
4
  "description": "NEDB — hash-chained, time-traveling, bi-temporal embedded database with Rust native core. SQL, Redis, MongoDB adapters. Causal Write Provenance. RESP2 wire protocol. Opt-in boot hydration (NITRO_NEDB_HYDRATION=true) loads the live dataset into RAM at open for millisecond reads.",
5
5
  "main": "index.js",
6
6
  "exports": {