nedb-engine-client 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/README.md +192 -0
  2. package/package.json +2 -1
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # nedb-engine-client
2
+
3
+ > TypeScript/JavaScript client for [nedbd](https://github.com/Eth-Interchained/nedb) — the NEDB server daemon.
4
+
5
+ [![npm](https://img.shields.io/npm/v/nedb-engine-client?color=00d4ff)](https://www.npmjs.com/package/nedb-engine-client)
6
+ [![License](https://img.shields.io/badge/license-GPL--3.0--or--later-818cf8)](https://github.com/Eth-Interchained/nedb/blob/master/LICENSE)
7
+
8
+ Connect to any running `nedbd` instance from Node.js or the browser. No engine embedded, no native dependencies. Just fetch.
9
+
10
+ ---
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install nedb-engine-client
16
+ ```
17
+
18
+ Requires Node.js ≥ 18 (uses native `fetch`). Works in modern browsers too.
19
+
20
+ ---
21
+
22
+ ## Quick start
23
+
24
+ ```typescript
25
+ import { NedbClient } from "nedb-engine-client";
26
+
27
+ const db = new NedbClient({ url: "http://127.0.0.1:7070", db: "mydb" });
28
+
29
+ // Write a document
30
+ await db.put("blocks", "618000", {
31
+ height: 618000,
32
+ hash: "000000000000000000024bead8df69990852c202db0e0097c1a12ea637d7e96d",
33
+ txCount: 2734,
34
+ });
35
+
36
+ // Query with NQL
37
+ const rows = await db.query("FROM blocks ORDER BY height DESC LIMIT 10");
38
+
39
+ // Time-travel: what did the DB look like at seq 100?
40
+ const old = await db.query("FROM blocks AS OF 100 WHERE height > 600000");
41
+
42
+ // Bi-temporal: what was true on 2024-06-15?
43
+ const valid = await db.query('FROM policy VALID AS OF "2024-06-15"');
44
+
45
+ // BLAKE2b Merkle head — changes on every write, anchorable
46
+ const head = await db.head();
47
+
48
+ // Tamper-evidence check across all objects
49
+ const report = await db.verify();
50
+ console.assert(report.ok, "tamper detected!");
51
+ ```
52
+
53
+ ---
54
+
55
+ ## nedbd — start the server
56
+
57
+ ```bash
58
+ npm install nedb-engine # or: pip install nedb-engine
59
+
60
+ # v2 DAG engine (recommended — instant cold start, tamper-evident)
61
+ NEDBD_DAG=1 nedbd --data ./data
62
+
63
+ # Check health
64
+ curl http://127.0.0.1:7070/health
65
+ # {"ok":true,"version":"2.0.8","service":"nedbd","encrypted":true}
66
+ ```
67
+
68
+ ---
69
+
70
+ ## API reference
71
+
72
+ ### Constructor
73
+
74
+ ```typescript
75
+ const db = new NedbClient({
76
+ url: "http://127.0.0.1:7070", // nedbd base URL
77
+ db: "mydb", // database name
78
+ token: "secret", // bearer auth (optional)
79
+ autoCreate: true, // create DB on first write
80
+ readTimeoutMs: 3_000, // query timeout
81
+ writeTimeoutMs: 30_000, // write timeout
82
+ });
83
+ ```
84
+
85
+ ### Writes
86
+
87
+ | Method | Description |
88
+ |--------|-------------|
89
+ | `db.put(coll, id, doc, opts?)` | Write a document |
90
+ | `db.delete(coll, id)` | Tombstone delete (history preserved in DAG) |
91
+ | `db.batch(ops)` | Batch put/del in one HTTP round-trip |
92
+ | `db.createIndex(coll, field)` | Create sorted index for ORDER BY |
93
+
94
+ **Put options:**
95
+
96
+ ```typescript
97
+ await db.put("claims", "c1", { fact: "..." }, {
98
+ causedBy: ["abc123hash"], // DAG causal provenance
99
+ validFrom: "2024-01-01", // bi-temporal valid window
100
+ validTo: "2024-12-31",
101
+ evidence: "sensor-42", // human-readable provenance note
102
+ confidence: 0.95, // confidence score 0–1
103
+ idem: "dedup-key", // idempotency key
104
+ });
105
+ ```
106
+
107
+ ### Reads
108
+
109
+ | Method | Description |
110
+ |--------|-------------|
111
+ | `db.get(coll, id)` | Fetch current version of a document |
112
+ | `db.query(nql)` | NQL query → array of objects |
113
+ | `db.queryFull(nql)` | NQL query → full response (rows + seq + head) |
114
+
115
+ ### NQL — NEDB Query Language
116
+
117
+ ```
118
+ FROM <collection>
119
+ [AS OF <seq>] transaction time (when was it written?)
120
+ [VALID AS OF "<date>"] valid time (when was it true in the world?)
121
+ [WHERE field = value [AND ...]] op: = != < <= > >=
122
+ [ORDER BY field [DESC]]
123
+ [LIMIT n]
124
+ [GROUP BY field COUNT|SUM|AVG|MIN|MAX]
125
+ [TRACE caused_by [REVERSE]] causal graph traversal
126
+ [SEARCH "text"] full-text search
127
+ ```
128
+
129
+ ### Integrity
130
+
131
+ | Method | Description |
132
+ |--------|-------------|
133
+ | `db.verify()` | BLAKE2b tamper-evidence check across all objects |
134
+ | `db.head()` | Current Merkle root — changes on every write |
135
+ | `db.seq()` | Current global sequence number |
136
+ | `db.log(limit?)` | Recent write log |
137
+ | `db.checkpoint()` | Explicit checkpoint (no-op on v2 DAG) |
138
+
139
+ ### Server management
140
+
141
+ | Method | Description |
142
+ |--------|-------------|
143
+ | `db.health()` | Server health — version, databases, encryption |
144
+ | `db.ping()` | Boolean reachability check |
145
+ | `db.listDatabases()` | All databases on this server |
146
+ | `db.createDatabase()` | Create this database explicitly |
147
+ | `db.dropDatabase()` | Drop this database (irreversible) |
148
+
149
+ ---
150
+
151
+ ## Error handling
152
+
153
+ ```typescript
154
+ import { NedbClient, NedbError } from "nedb-engine-client";
155
+
156
+ try {
157
+ await db.put("coll", "id", { data: "value" });
158
+ } catch (e) {
159
+ if (e instanceof NedbError) {
160
+ console.error(`HTTP ${e.status}: ${e.message}`);
161
+ }
162
+ }
163
+ ```
164
+
165
+ Queries on missing collections return `[]` rather than throwing — resilient by default.
166
+
167
+ ---
168
+
169
+ ## Batch writes
170
+
171
+ ```typescript
172
+ await db.batch([
173
+ { op: "put", coll: "blocks", id: "618001", doc: { height: 618001 } },
174
+ { op: "put", coll: "blocks", id: "618002", doc: { height: 618002 } },
175
+ { op: "del", coll: "blocks", id: "617999" },
176
+ ]);
177
+ ```
178
+
179
+ One HTTP request, multiple ops — best throughput for bulk ingestion.
180
+
181
+ ---
182
+
183
+ ## Links
184
+
185
+ - **Engine:** [pip install nedb-engine](https://pypi.org/project/nedb-engine/) · [npm install nedb-engine](https://www.npmjs.com/package/nedb-engine)
186
+ - **Python client:** [pip install nedb-engine-client](https://pypi.org/project/nedb-engine-client/)
187
+ - **Source:** [github.com/Eth-Interchained/nedb](https://github.com/Eth-Interchained/nedb)
188
+ - **Studio:** [studio.interchained.org](https://studio.interchained.org)
189
+
190
+ ---
191
+
192
+ © [INTERCHAINED, LLC](https://interchained.org) · GPL-3.0-or-later · Built with [Hyperagent](https://hyperagent.com/refer/J2G6TCD7)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nedb-engine-client",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "TypeScript/JavaScript client for the nedbd HTTP API (nedb-engine)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -12,6 +12,7 @@
12
12
  "types": "./dist/index.d.ts"
13
13
  }
14
14
  },
15
+ "readme": "README.md",
15
16
  "files": ["dist", "README.md", "LICENSE"],
16
17
  "scripts": {
17
18
  "build": "tsc && node scripts/esm-shim.mjs",