nedb-engine-client 1.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.
@@ -0,0 +1,201 @@
1
+ /**
2
+ * nedb-client — TypeScript/JavaScript client for the nedbd HTTP API.
3
+ *
4
+ * Works in Node.js (18+) and modern browsers.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { NedbClient } from "nedb-engine-client";
9
+ *
10
+ * const db = new NedbClient({ url: "http://127.0.0.1:7070", db: "mydb" });
11
+ *
12
+ * await db.put("blocks", "618000", { height: 618000, hash: "000abc" });
13
+ * const rows = await db.query("FROM blocks ORDER BY height DESC LIMIT 10");
14
+ * const head = await db.head();
15
+ * ```
16
+ */
17
+ export interface NedbClientOptions {
18
+ /** Base URL of the nedbd server. Default: "http://127.0.0.1:7070" */
19
+ url?: string;
20
+ /** Database name. All operations target this database. */
21
+ db: string;
22
+ /** Bearer token (matches NEDBD_TOKEN on the server). */
23
+ token?: string;
24
+ /**
25
+ * Auto-create the database on first write if it doesn't exist.
26
+ * Default: true
27
+ */
28
+ autoCreate?: boolean;
29
+ /**
30
+ * Read timeout in milliseconds (for queries).
31
+ * Default: 3000
32
+ */
33
+ readTimeoutMs?: number;
34
+ /**
35
+ * Write timeout in milliseconds (for puts, deletes, batch).
36
+ * Default: 30000
37
+ */
38
+ writeTimeoutMs?: number;
39
+ }
40
+ export interface PutOptions {
41
+ /** Object hashes that causally led to this write (DAG provenance). */
42
+ causedBy?: string[];
43
+ /** Bi-temporal valid-from date (ISO 8601). */
44
+ validFrom?: string;
45
+ /** Bi-temporal valid-to date (ISO 8601). */
46
+ validTo?: string;
47
+ /** Human-readable provenance note. */
48
+ evidence?: string;
49
+ /** Confidence score 0–1. */
50
+ confidence?: number;
51
+ /** Idempotency key — duplicate puts with the same key are no-ops. */
52
+ idem?: string;
53
+ /** Replay-protection nonce (monotonically increasing per clientId). */
54
+ nonce?: number;
55
+ /** Client identifier for replay protection. */
56
+ clientId?: string;
57
+ }
58
+ export interface PutResult {
59
+ ok: boolean;
60
+ doc: Record<string, unknown>;
61
+ seq: number;
62
+ head: string;
63
+ }
64
+ export interface QueryResult {
65
+ rows: Record<string, unknown>[];
66
+ count: number;
67
+ seq: number;
68
+ head: string;
69
+ }
70
+ export interface VerifyResult {
71
+ ok: boolean;
72
+ seq: number;
73
+ head: string;
74
+ tamper_evident: boolean;
75
+ objects_checked: number;
76
+ tampered: string[];
77
+ }
78
+ export interface HealthResult {
79
+ ok: boolean;
80
+ service: string;
81
+ version: string;
82
+ databases: string[];
83
+ encrypted: boolean;
84
+ }
85
+ export interface BatchOp {
86
+ op: "put" | "del";
87
+ coll: string;
88
+ id: string;
89
+ doc?: Record<string, unknown>;
90
+ caused_by?: string[];
91
+ }
92
+ export interface BatchResult {
93
+ results: Array<{
94
+ op: string;
95
+ id: string;
96
+ seq?: number;
97
+ error?: string;
98
+ }>;
99
+ count: number;
100
+ seq: number;
101
+ head: string;
102
+ }
103
+ /** Thrown when nedbd returns a non-2xx response (except auto-handled cases). */
104
+ export declare class NedbError extends Error {
105
+ readonly status: number;
106
+ readonly message: string;
107
+ constructor(status: number, message: string);
108
+ }
109
+ export declare class NedbClient {
110
+ private readonly base;
111
+ private readonly db;
112
+ private readonly headers;
113
+ private readonly autoCreate;
114
+ private readonly readMs;
115
+ private readonly writeMs;
116
+ constructor(opts: NedbClientOptions);
117
+ private fetch;
118
+ private raise;
119
+ private ensureDb;
120
+ /**
121
+ * Write a document.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * await db.put("blocks", "618000", { height: 618000 });
126
+ * await db.put("claims", "c1", { fact: "..." }, { causedBy: ["abc123"] });
127
+ * ```
128
+ */
129
+ put(coll: string, id: string, doc: Record<string, unknown>, opts?: PutOptions): Promise<PutResult>;
130
+ /**
131
+ * Fetch the current version of a document. Returns null if not found.
132
+ */
133
+ get(coll: string, id: string): Promise<Record<string, unknown> | null>;
134
+ /**
135
+ * Tombstone-delete a document.
136
+ * History is preserved in the DAG; returns true if the document existed.
137
+ */
138
+ delete(coll: string, id: string): Promise<boolean>;
139
+ /**
140
+ * Run a NQL query. Returns an array of document objects.
141
+ *
142
+ * ```
143
+ * NQL: FROM <coll>
144
+ * [AS OF <seq>]
145
+ * [VALID AS OF "<date>"]
146
+ * [WHERE field = value [AND ...]]
147
+ * [ORDER BY field [DESC]]
148
+ * [LIMIT n]
149
+ * [GROUP BY field COUNT|SUM|AVG|MIN|MAX]
150
+ * [TRACE caused_by [REVERSE]]
151
+ * [SEARCH "text"]
152
+ * ```
153
+ */
154
+ query(nql: string): Promise<Record<string, unknown>[]>;
155
+ /**
156
+ * Like {@link query} but returns the full response including `seq` and `head`.
157
+ */
158
+ queryFull(nql: string): Promise<QueryResult>;
159
+ /**
160
+ * Run a batch of put/del operations in a single HTTP round-trip.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * await db.batch([
165
+ * { op: "put", coll: "blocks", id: "1", doc: { height: 1 } },
166
+ * { op: "del", coll: "blocks", id: "0" },
167
+ * ]);
168
+ * ```
169
+ */
170
+ batch(ops: BatchOp[]): Promise<BatchResult>;
171
+ /** Create a sorted index on (coll, field) for fast ORDER BY queries. */
172
+ createIndex(coll: string, field: string, kind?: "sorted" | "eq"): Promise<{
173
+ ok: boolean;
174
+ }>;
175
+ /** Run a full BLAKE2b tamper-evidence check over all objects. */
176
+ verify(): Promise<VerifyResult>;
177
+ /** Return the current BLAKE2b Merkle head of the database. */
178
+ head(): Promise<string>;
179
+ /** Return the current global sequence number. */
180
+ seq(): Promise<number>;
181
+ /** Trigger an explicit checkpoint (no-op on v2 DAG — always snapshotted). */
182
+ checkpoint(): Promise<{
183
+ ok: boolean;
184
+ head: string;
185
+ seq: number;
186
+ }>;
187
+ /** Return the last `limit` write operations. */
188
+ log(limit?: number): Promise<Record<string, unknown>[]>;
189
+ /** Ping the server. Returns full health object. */
190
+ health(): Promise<HealthResult>;
191
+ /** Returns true if the server is reachable and healthy. */
192
+ ping(): Promise<boolean>;
193
+ /** List all database names on this server. */
194
+ listDatabases(): Promise<string[]>;
195
+ /** Explicitly create this database. Idempotent. */
196
+ createDatabase(): Promise<void>;
197
+ /** Drop this database and all its data. Irreversible. */
198
+ dropDatabase(): Promise<boolean>;
199
+ }
200
+ export default NedbClient;
201
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IAC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AAM,EACb,IAAI,GAAE,QAAQ,GAAG,IAAe,GAC/B,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,CAAC;IAa3B,iEAAiE;IAC3D,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;IAMrC,8DAA8D;IACxD,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAO7B,iDAAiD;IAC3C,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;IAO5B,6EAA6E;IACvE,UAAU,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAWvE,gDAAgD;IAC1C,GAAG,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAYzD,mDAAmD;IAC7C,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;IAMrC,2DAA2D;IACrD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAS9B,8CAA8C;IACxC,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAOxC,mDAAmD;IAC7C,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrC,yDAAyD;IACnD,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;CAWvC;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,272 @@
1
+
2
+ /**
3
+ * nedb-client — TypeScript/JavaScript client for the nedbd HTTP API.
4
+ *
5
+ * Works in Node.js (18+) and modern browsers.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { NedbClient } from "nedb-engine-client";
10
+ *
11
+ * const db = new NedbClient({ url: "http://127.0.0.1:7070", db: "mydb" });
12
+ *
13
+ * await db.put("blocks", "618000", { height: 618000, hash: "000abc" });
14
+ * const rows = await db.query("FROM blocks ORDER BY height DESC LIMIT 10");
15
+ * const head = await db.head();
16
+ * ```
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.NedbClient = exports.NedbError = void 0;
20
+ /** Thrown when nedbd returns a non-2xx response (except auto-handled cases). */
21
+ class NedbError extends Error {
22
+ constructor(status, message) {
23
+ super(`NedbError ${status}: ${message}`);
24
+ this.status = status;
25
+ this.message = message;
26
+ this.name = "NedbError";
27
+ }
28
+ }
29
+ exports.NedbError = NedbError;
30
+ // ── Client ────────────────────────────────────────────────────────────────
31
+ class NedbClient {
32
+ constructor(opts) {
33
+ this.base = (opts.url ?? "http://127.0.0.1:7070").replace(/\/$/, "");
34
+ this.db = opts.db;
35
+ this.autoCreate = opts.autoCreate ?? true;
36
+ this.readMs = opts.readTimeoutMs ?? 3000;
37
+ this.writeMs = opts.writeTimeoutMs ?? 30000;
38
+ this.headers = { "Content-Type": "application/json" };
39
+ if (opts.token)
40
+ this.headers["Authorization"] = `Bearer ${opts.token}`;
41
+ }
42
+ // ── Internal ──────────────────────────────────────────────────────────────
43
+ async fetch(method, path, body, timeoutMs) {
44
+ const controller = new AbortController();
45
+ const timer = setTimeout(() => controller.abort(), timeoutMs ?? this.readMs);
46
+ try {
47
+ return await fetch(`${this.base}${path}`, {
48
+ method,
49
+ headers: this.headers,
50
+ body: body !== undefined ? JSON.stringify(body) : undefined,
51
+ signal: controller.signal,
52
+ });
53
+ }
54
+ finally {
55
+ clearTimeout(timer);
56
+ }
57
+ }
58
+ async raise(resp) {
59
+ let msg = resp.statusText;
60
+ try {
61
+ const body = await resp.json();
62
+ if (body.error)
63
+ msg = body.error;
64
+ }
65
+ catch { /* ignore */ }
66
+ throw new NedbError(resp.status, msg);
67
+ }
68
+ async ensureDb() {
69
+ await this.fetch("POST", "/v1/databases", { name: this.db }, this.writeMs);
70
+ // 201 = created, 409 = already exists — both fine
71
+ }
72
+ // ── Core CRUD ─────────────────────────────────────────────────────────────
73
+ /**
74
+ * Write a document.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * await db.put("blocks", "618000", { height: 618000 });
79
+ * await db.put("claims", "c1", { fact: "..." }, { causedBy: ["abc123"] });
80
+ * ```
81
+ */
82
+ async put(coll, id, doc, opts = {}) {
83
+ const payload = { coll, id, doc };
84
+ if (opts.causedBy)
85
+ payload.caused_by = opts.causedBy;
86
+ if (opts.validFrom)
87
+ payload.valid_from = opts.validFrom;
88
+ if (opts.validTo)
89
+ payload.valid_to = opts.validTo;
90
+ if (opts.evidence)
91
+ payload.evidence = opts.evidence;
92
+ if (opts.confidence !== undefined)
93
+ payload.confidence = opts.confidence;
94
+ if (opts.idem)
95
+ payload.idem = opts.idem;
96
+ if (opts.nonce !== undefined)
97
+ payload.nonce = opts.nonce;
98
+ if (opts.clientId)
99
+ payload.client = opts.clientId;
100
+ let resp = await this.fetch("POST", `/v1/databases/${this.db}/put`, payload, this.writeMs);
101
+ if (resp.status === 404 && this.autoCreate) {
102
+ await this.ensureDb();
103
+ resp = await this.fetch("POST", `/v1/databases/${this.db}/put`, payload, this.writeMs);
104
+ }
105
+ if (!resp.ok)
106
+ await this.raise(resp);
107
+ return resp.json();
108
+ }
109
+ /**
110
+ * Fetch the current version of a document. Returns null if not found.
111
+ */
112
+ async get(coll, id) {
113
+ const rows = await this.query(`FROM ${coll} WHERE _id = "${id}" LIMIT 1`);
114
+ return rows[0] ?? null;
115
+ }
116
+ /**
117
+ * Tombstone-delete a document.
118
+ * History is preserved in the DAG; returns true if the document existed.
119
+ */
120
+ async delete(coll, id) {
121
+ const resp = await this.fetch("DELETE", `/v1/databases/${this.db}/rows/${coll}/${id}`, undefined, this.writeMs);
122
+ if (resp.status === 404)
123
+ return false;
124
+ if (!resp.ok)
125
+ await this.raise(resp);
126
+ const body = await resp.json();
127
+ return body.ok;
128
+ }
129
+ /**
130
+ * Run a NQL query. Returns an array of document objects.
131
+ *
132
+ * ```
133
+ * NQL: FROM <coll>
134
+ * [AS OF <seq>]
135
+ * [VALID AS OF "<date>"]
136
+ * [WHERE field = value [AND ...]]
137
+ * [ORDER BY field [DESC]]
138
+ * [LIMIT n]
139
+ * [GROUP BY field COUNT|SUM|AVG|MIN|MAX]
140
+ * [TRACE caused_by [REVERSE]]
141
+ * [SEARCH "text"]
142
+ * ```
143
+ */
144
+ async query(nql) {
145
+ const result = await this.queryFull(nql);
146
+ return result.rows;
147
+ }
148
+ /**
149
+ * Like {@link query} but returns the full response including `seq` and `head`.
150
+ */
151
+ async queryFull(nql) {
152
+ const resp = await this.fetch("POST", `/v1/databases/${this.db}/query`, { nql });
153
+ if (resp.status === 400 || resp.status === 404) {
154
+ return { rows: [], count: 0, seq: 0, head: "" };
155
+ }
156
+ if (!resp.ok)
157
+ await this.raise(resp);
158
+ return resp.json();
159
+ }
160
+ // ── Batch ─────────────────────────────────────────────────────────────────
161
+ /**
162
+ * Run a batch of put/del operations in a single HTTP round-trip.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * await db.batch([
167
+ * { op: "put", coll: "blocks", id: "1", doc: { height: 1 } },
168
+ * { op: "del", coll: "blocks", id: "0" },
169
+ * ]);
170
+ * ```
171
+ */
172
+ async batch(ops) {
173
+ let resp = await this.fetch("POST", `/v1/databases/${this.db}/batch`, { ops }, this.writeMs);
174
+ if (resp.status === 404 && this.autoCreate) {
175
+ await this.ensureDb();
176
+ resp = await this.fetch("POST", `/v1/databases/${this.db}/batch`, { ops }, this.writeMs);
177
+ }
178
+ if (!resp.ok)
179
+ await this.raise(resp);
180
+ return resp.json();
181
+ }
182
+ // ── Indexes ───────────────────────────────────────────────────────────────
183
+ /** Create a sorted index on (coll, field) for fast ORDER BY queries. */
184
+ async createIndex(coll, field, kind = "sorted") {
185
+ const resp = await this.fetch("POST", `/v1/databases/${this.db}/index`, { coll, field, kind }, this.writeMs);
186
+ if (!resp.ok)
187
+ await this.raise(resp);
188
+ return resp.json();
189
+ }
190
+ // ── Integrity ─────────────────────────────────────────────────────────────
191
+ /** Run a full BLAKE2b tamper-evidence check over all objects. */
192
+ async verify() {
193
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}/verify`);
194
+ if (!resp.ok)
195
+ await this.raise(resp);
196
+ return resp.json();
197
+ }
198
+ /** Return the current BLAKE2b Merkle head of the database. */
199
+ async head() {
200
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}`);
201
+ if (!resp.ok)
202
+ await this.raise(resp);
203
+ const body = await resp.json();
204
+ return body.head;
205
+ }
206
+ /** Return the current global sequence number. */
207
+ async seq() {
208
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}`);
209
+ if (!resp.ok)
210
+ await this.raise(resp);
211
+ const body = await resp.json();
212
+ return body.seq;
213
+ }
214
+ /** Trigger an explicit checkpoint (no-op on v2 DAG — always snapshotted). */
215
+ async checkpoint() {
216
+ const resp = await this.fetch("POST", `/v1/databases/${this.db}/checkpoint`, {}, this.writeMs);
217
+ if (!resp.ok)
218
+ await this.raise(resp);
219
+ return resp.json();
220
+ }
221
+ /** Return the last `limit` write operations. */
222
+ async log(limit = 50) {
223
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}/log?limit=${limit}`);
224
+ if (!resp.ok)
225
+ await this.raise(resp);
226
+ const body = await resp.json();
227
+ return body.log;
228
+ }
229
+ // ── Server ────────────────────────────────────────────────────────────────
230
+ /** Ping the server. Returns full health object. */
231
+ async health() {
232
+ const resp = await this.fetch("GET", "/health");
233
+ if (!resp.ok)
234
+ await this.raise(resp);
235
+ return resp.json();
236
+ }
237
+ /** Returns true if the server is reachable and healthy. */
238
+ async ping() {
239
+ try {
240
+ const h = await this.health();
241
+ return h.ok;
242
+ }
243
+ catch {
244
+ return false;
245
+ }
246
+ }
247
+ /** List all database names on this server. */
248
+ async listDatabases() {
249
+ const resp = await this.fetch("GET", "/v1/databases");
250
+ if (!resp.ok)
251
+ await this.raise(resp);
252
+ const body = await resp.json();
253
+ return body.databases.map((d) => d.name);
254
+ }
255
+ /** Explicitly create this database. Idempotent. */
256
+ async createDatabase() {
257
+ const resp = await this.fetch("POST", "/v1/databases", { name: this.db }, this.writeMs);
258
+ if (!resp.ok && resp.status !== 409)
259
+ await this.raise(resp);
260
+ }
261
+ /** Drop this database and all its data. Irreversible. */
262
+ async dropDatabase() {
263
+ const resp = await this.fetch("DELETE", `/v1/databases/${this.db}`, undefined, this.writeMs);
264
+ if (!resp.ok)
265
+ await this.raise(resp);
266
+ const body = await resp.json();
267
+ return body.dropped;
268
+ }
269
+ }
270
+ exports.NedbClient = NedbClient;
271
+ exports.default = NedbClient;
272
+ //# sourceMappingURL=index.js.map
package/dist/index.js ADDED
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ /**
3
+ * nedb-client — TypeScript/JavaScript client for the nedbd HTTP API.
4
+ *
5
+ * Works in Node.js (18+) and modern browsers.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { NedbClient } from "nedb-engine-client";
10
+ *
11
+ * const db = new NedbClient({ url: "http://127.0.0.1:7070", db: "mydb" });
12
+ *
13
+ * await db.put("blocks", "618000", { height: 618000, hash: "000abc" });
14
+ * const rows = await db.query("FROM blocks ORDER BY height DESC LIMIT 10");
15
+ * const head = await db.head();
16
+ * ```
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.NedbClient = exports.NedbError = void 0;
20
+ /** Thrown when nedbd returns a non-2xx response (except auto-handled cases). */
21
+ class NedbError extends Error {
22
+ constructor(status, message) {
23
+ super(`NedbError ${status}: ${message}`);
24
+ this.status = status;
25
+ this.message = message;
26
+ this.name = "NedbError";
27
+ }
28
+ }
29
+ exports.NedbError = NedbError;
30
+ // ── Client ────────────────────────────────────────────────────────────────
31
+ class NedbClient {
32
+ constructor(opts) {
33
+ this.base = (opts.url ?? "http://127.0.0.1:7070").replace(/\/$/, "");
34
+ this.db = opts.db;
35
+ this.autoCreate = opts.autoCreate ?? true;
36
+ this.readMs = opts.readTimeoutMs ?? 3000;
37
+ this.writeMs = opts.writeTimeoutMs ?? 30000;
38
+ this.headers = { "Content-Type": "application/json" };
39
+ if (opts.token)
40
+ this.headers["Authorization"] = `Bearer ${opts.token}`;
41
+ }
42
+ // ── Internal ──────────────────────────────────────────────────────────────
43
+ async fetch(method, path, body, timeoutMs) {
44
+ const controller = new AbortController();
45
+ const timer = setTimeout(() => controller.abort(), timeoutMs ?? this.readMs);
46
+ try {
47
+ return await fetch(`${this.base}${path}`, {
48
+ method,
49
+ headers: this.headers,
50
+ body: body !== undefined ? JSON.stringify(body) : undefined,
51
+ signal: controller.signal,
52
+ });
53
+ }
54
+ finally {
55
+ clearTimeout(timer);
56
+ }
57
+ }
58
+ async raise(resp) {
59
+ let msg = resp.statusText;
60
+ try {
61
+ const body = await resp.json();
62
+ if (body.error)
63
+ msg = body.error;
64
+ }
65
+ catch { /* ignore */ }
66
+ throw new NedbError(resp.status, msg);
67
+ }
68
+ async ensureDb() {
69
+ await this.fetch("POST", "/v1/databases", { name: this.db }, this.writeMs);
70
+ // 201 = created, 409 = already exists — both fine
71
+ }
72
+ // ── Core CRUD ─────────────────────────────────────────────────────────────
73
+ /**
74
+ * Write a document.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * await db.put("blocks", "618000", { height: 618000 });
79
+ * await db.put("claims", "c1", { fact: "..." }, { causedBy: ["abc123"] });
80
+ * ```
81
+ */
82
+ async put(coll, id, doc, opts = {}) {
83
+ const payload = { coll, id, doc };
84
+ if (opts.causedBy)
85
+ payload.caused_by = opts.causedBy;
86
+ if (opts.validFrom)
87
+ payload.valid_from = opts.validFrom;
88
+ if (opts.validTo)
89
+ payload.valid_to = opts.validTo;
90
+ if (opts.evidence)
91
+ payload.evidence = opts.evidence;
92
+ if (opts.confidence !== undefined)
93
+ payload.confidence = opts.confidence;
94
+ if (opts.idem)
95
+ payload.idem = opts.idem;
96
+ if (opts.nonce !== undefined)
97
+ payload.nonce = opts.nonce;
98
+ if (opts.clientId)
99
+ payload.client = opts.clientId;
100
+ let resp = await this.fetch("POST", `/v1/databases/${this.db}/put`, payload, this.writeMs);
101
+ if (resp.status === 404 && this.autoCreate) {
102
+ await this.ensureDb();
103
+ resp = await this.fetch("POST", `/v1/databases/${this.db}/put`, payload, this.writeMs);
104
+ }
105
+ if (!resp.ok)
106
+ await this.raise(resp);
107
+ return resp.json();
108
+ }
109
+ /**
110
+ * Fetch the current version of a document. Returns null if not found.
111
+ */
112
+ async get(coll, id) {
113
+ const rows = await this.query(`FROM ${coll} WHERE _id = "${id}" LIMIT 1`);
114
+ return rows[0] ?? null;
115
+ }
116
+ /**
117
+ * Tombstone-delete a document.
118
+ * History is preserved in the DAG; returns true if the document existed.
119
+ */
120
+ async delete(coll, id) {
121
+ const resp = await this.fetch("DELETE", `/v1/databases/${this.db}/rows/${coll}/${id}`, undefined, this.writeMs);
122
+ if (resp.status === 404)
123
+ return false;
124
+ if (!resp.ok)
125
+ await this.raise(resp);
126
+ const body = await resp.json();
127
+ return body.ok;
128
+ }
129
+ /**
130
+ * Run a NQL query. Returns an array of document objects.
131
+ *
132
+ * ```
133
+ * NQL: FROM <coll>
134
+ * [AS OF <seq>]
135
+ * [VALID AS OF "<date>"]
136
+ * [WHERE field = value [AND ...]]
137
+ * [ORDER BY field [DESC]]
138
+ * [LIMIT n]
139
+ * [GROUP BY field COUNT|SUM|AVG|MIN|MAX]
140
+ * [TRACE caused_by [REVERSE]]
141
+ * [SEARCH "text"]
142
+ * ```
143
+ */
144
+ async query(nql) {
145
+ const result = await this.queryFull(nql);
146
+ return result.rows;
147
+ }
148
+ /**
149
+ * Like {@link query} but returns the full response including `seq` and `head`.
150
+ */
151
+ async queryFull(nql) {
152
+ const resp = await this.fetch("POST", `/v1/databases/${this.db}/query`, { nql });
153
+ if (resp.status === 400 || resp.status === 404) {
154
+ return { rows: [], count: 0, seq: 0, head: "" };
155
+ }
156
+ if (!resp.ok)
157
+ await this.raise(resp);
158
+ return resp.json();
159
+ }
160
+ // ── Batch ─────────────────────────────────────────────────────────────────
161
+ /**
162
+ * Run a batch of put/del operations in a single HTTP round-trip.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * await db.batch([
167
+ * { op: "put", coll: "blocks", id: "1", doc: { height: 1 } },
168
+ * { op: "del", coll: "blocks", id: "0" },
169
+ * ]);
170
+ * ```
171
+ */
172
+ async batch(ops) {
173
+ let resp = await this.fetch("POST", `/v1/databases/${this.db}/batch`, { ops }, this.writeMs);
174
+ if (resp.status === 404 && this.autoCreate) {
175
+ await this.ensureDb();
176
+ resp = await this.fetch("POST", `/v1/databases/${this.db}/batch`, { ops }, this.writeMs);
177
+ }
178
+ if (!resp.ok)
179
+ await this.raise(resp);
180
+ return resp.json();
181
+ }
182
+ // ── Indexes ───────────────────────────────────────────────────────────────
183
+ /** Create a sorted index on (coll, field) for fast ORDER BY queries. */
184
+ async createIndex(coll, field, kind = "sorted") {
185
+ const resp = await this.fetch("POST", `/v1/databases/${this.db}/index`, { coll, field, kind }, this.writeMs);
186
+ if (!resp.ok)
187
+ await this.raise(resp);
188
+ return resp.json();
189
+ }
190
+ // ── Integrity ─────────────────────────────────────────────────────────────
191
+ /** Run a full BLAKE2b tamper-evidence check over all objects. */
192
+ async verify() {
193
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}/verify`);
194
+ if (!resp.ok)
195
+ await this.raise(resp);
196
+ return resp.json();
197
+ }
198
+ /** Return the current BLAKE2b Merkle head of the database. */
199
+ async head() {
200
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}`);
201
+ if (!resp.ok)
202
+ await this.raise(resp);
203
+ const body = await resp.json();
204
+ return body.head;
205
+ }
206
+ /** Return the current global sequence number. */
207
+ async seq() {
208
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}`);
209
+ if (!resp.ok)
210
+ await this.raise(resp);
211
+ const body = await resp.json();
212
+ return body.seq;
213
+ }
214
+ /** Trigger an explicit checkpoint (no-op on v2 DAG — always snapshotted). */
215
+ async checkpoint() {
216
+ const resp = await this.fetch("POST", `/v1/databases/${this.db}/checkpoint`, {}, this.writeMs);
217
+ if (!resp.ok)
218
+ await this.raise(resp);
219
+ return resp.json();
220
+ }
221
+ /** Return the last `limit` write operations. */
222
+ async log(limit = 50) {
223
+ const resp = await this.fetch("GET", `/v1/databases/${this.db}/log?limit=${limit}`);
224
+ if (!resp.ok)
225
+ await this.raise(resp);
226
+ const body = await resp.json();
227
+ return body.log;
228
+ }
229
+ // ── Server ────────────────────────────────────────────────────────────────
230
+ /** Ping the server. Returns full health object. */
231
+ async health() {
232
+ const resp = await this.fetch("GET", "/health");
233
+ if (!resp.ok)
234
+ await this.raise(resp);
235
+ return resp.json();
236
+ }
237
+ /** Returns true if the server is reachable and healthy. */
238
+ async ping() {
239
+ try {
240
+ const h = await this.health();
241
+ return h.ok;
242
+ }
243
+ catch {
244
+ return false;
245
+ }
246
+ }
247
+ /** List all database names on this server. */
248
+ async listDatabases() {
249
+ const resp = await this.fetch("GET", "/v1/databases");
250
+ if (!resp.ok)
251
+ await this.raise(resp);
252
+ const body = await resp.json();
253
+ return body.databases.map((d) => d.name);
254
+ }
255
+ /** Explicitly create this database. Idempotent. */
256
+ async createDatabase() {
257
+ const resp = await this.fetch("POST", "/v1/databases", { name: this.db }, this.writeMs);
258
+ if (!resp.ok && resp.status !== 409)
259
+ await this.raise(resp);
260
+ }
261
+ /** Drop this database and all its data. Irreversible. */
262
+ async dropDatabase() {
263
+ const resp = await this.fetch("DELETE", `/v1/databases/${this.db}`, undefined, this.writeMs);
264
+ if (!resp.ok)
265
+ await this.raise(resp);
266
+ const body = await resp.json();
267
+ return body.dropped;
268
+ }
269
+ }
270
+ exports.NedbClient = NedbClient;
271
+ exports.default = NedbClient;
272
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AA6FH,gFAAgF;AAChF,MAAa,SAAU,SAAQ,KAAK;IAClC,YACkB,MAAc,EACd,OAAe;QAE/B,KAAK,CAAC,aAAa,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;QAHzB,WAAM,GAAN,MAAM,CAAQ;QACd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AM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,MAAM,EACN,eAAe,EACf,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EACjB,IAAI,CAAC,OAAO,CACb,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,MAAM,KAAK,GAAG;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC;IAED,yDAAyD;IACzD,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAC3B,QAAQ,EACR,iBAAiB,IAAI,CAAC,EAAE,EAAE,EAC1B,SAAS,EACT,IAAI,CAAC,OAAO,CACb,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,EAAE;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAA0B,CAAC;QACvD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA3SD,gCA2SC;AAED,kBAAe,UAAU,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "nedb-engine-client",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript/JavaScript client for the nedbd HTTP API (nedb-engine)",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.esm.js",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": ["dist", "README.md", "LICENSE"],
16
+ "scripts": {
17
+ "build": "tsc && node scripts/esm-shim.mjs",
18
+ "test": "node --experimental-vm-modules node_modules/.bin/jest"
19
+ },
20
+ "keywords": ["nedb", "nedb-engine", "client", "database", "dag", "bi-temporal", "causal", "nedbd"],
21
+ "author": "Eth-Interchained",
22
+ "license": "GPL-3.0-or-later",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/Eth-Interchained/nedb.git"
26
+ },
27
+ "homepage": "https://github.com/Eth-Interchained/nedb/tree/master/client/node",
28
+ "devDependencies": {
29
+ "typescript": "^5.4.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=18"
33
+ }
34
+ }