@net-mesh/core 0.21.0 → 0.23.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/meshdb.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Result of {@link parseMeshDbErrorKind}: extracted structured
3
+ * discriminator + the human-readable message stripped of the
4
+ * `<<meshdb-kind:...>>` prefix.
5
+ */
6
+ export interface ParsedMeshDbError {
7
+ kind: string;
8
+ message: string;
9
+ }
10
+ /**
11
+ * Pull the structured error kind out of a MeshDB error message.
12
+ *
13
+ * The Rust binding embeds the kind discriminator (one of the
14
+ * `MeshError` variant tags such as `planner_error`,
15
+ * `executor_error`, `query_cancelled`, `historical_range_unavailable`,
16
+ * `ambiguous_discovery`, etc.) at the start of the error message
17
+ * as `<<meshdb-kind:KIND>>MSG`. This helper parses it back.
18
+ *
19
+ * Returns `null` for errors that don't carry a kind prefix
20
+ * (SDK-side validation failures, factory rejections) — those
21
+ * surface with the plain message intact.
22
+ */
23
+ export declare function parseMeshDbErrorKind(err: unknown): ParsedMeshDbError | null;
package/meshdb.js ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ // MeshDB AsyncIterable shim.
3
+ //
4
+ // Augments the napi-rs–generated `MeshQueryStream` class with
5
+ // `[Symbol.asyncIterator]` so callers can write `for await (const row
6
+ // of await runner.execute(query)) { ... }`. The locked Node SDK
7
+ // decision is `Promise<AsyncIterable<Row>>`; importing this module
8
+ // once at startup makes the shape land.
9
+ //
10
+ // Usage:
11
+ //
12
+ // import "@net-mesh/core/meshdb"; // augments MeshQueryStream
13
+ // import { MeshQuery, MeshQueryRunner } from "@net-mesh/core";
14
+ //
15
+ // const runner = new MeshQueryRunner(reader);
16
+ // const stream = await runner.execute(MeshQuery.latest(0xABn));
17
+ // for await (const row of stream) {
18
+ // console.log(row.seq, row.payload);
19
+ // }
20
+ //
21
+ // The shim is idempotent — re-imports are no-ops. It detaches
22
+ // cleanly under tree-shaking too (no top-level side effects beyond
23
+ // the prototype attach, which only fires when `MeshQueryStream` is
24
+ // part of the loaded native binding).
25
+ //
26
+ // Phase-F note: this shim is a wire-shape ergonomics layer; it
27
+ // doesn't change semantics. The underlying `next()` / `toArray()`
28
+ // methods stay available for callers that prefer manual iteration
29
+ // or batch drain.
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.parseMeshDbErrorKind = parseMeshDbErrorKind;
32
+ // The napi-generated MeshQueryStream is a constructor function with a
33
+ // prototype, but the original cast typed it as a plain object — the
34
+ // later `typeof === "function"` narrowing then collapsed it to `never`
35
+ // and reading `.prototype` errored under `-D warnings`. Cast as a
36
+ // Function with a prototype so both type-guards line up.
37
+ const native = require("./index");
38
+ if (native.MeshQueryStream &&
39
+ typeof native.MeshQueryStream === "function" &&
40
+ !(Symbol.asyncIterator in native.MeshQueryStream.prototype)) {
41
+ Object.defineProperty(native.MeshQueryStream.prototype, Symbol.asyncIterator, {
42
+ value() {
43
+ const stream = this;
44
+ return {
45
+ async next() {
46
+ const row = await stream.next();
47
+ if (row === null || row === undefined) {
48
+ return { value: undefined, done: true };
49
+ }
50
+ return { value: row, done: false };
51
+ },
52
+ // `return(value)` is invoked when a `for await (...)` loop
53
+ // `break`s, `return`s from the enclosing function, or an
54
+ // exception unwinds out of the loop body. Without this,
55
+ // the backing row Vec stays pinned on the AsyncMutex
56
+ // until JS GC eventually drops the stream — for a 10k+
57
+ // row result that's a sizeable memory pin.
58
+ async return(value) {
59
+ if (typeof stream.release === "function") {
60
+ await stream.release();
61
+ }
62
+ return { value, done: true };
63
+ },
64
+ // `throw(err)` is the iteration-protocol's error path.
65
+ // Symmetric to `return()`: free the buffer, then
66
+ // re-surface the error to the caller.
67
+ async throw(err) {
68
+ if (typeof stream.release === "function") {
69
+ await stream.release();
70
+ }
71
+ throw err;
72
+ },
73
+ };
74
+ },
75
+ enumerable: false,
76
+ configurable: true,
77
+ writable: true,
78
+ });
79
+ }
80
+ /**
81
+ * Pull the structured error kind out of a MeshDB error message.
82
+ *
83
+ * The Rust binding embeds the kind discriminator (one of the
84
+ * `MeshError` variant tags such as `planner_error`,
85
+ * `executor_error`, `query_cancelled`, `historical_range_unavailable`,
86
+ * `ambiguous_discovery`, etc.) at the start of the error message
87
+ * as `<<meshdb-kind:KIND>>MSG`. This helper parses it back.
88
+ *
89
+ * Returns `null` for errors that don't carry a kind prefix
90
+ * (SDK-side validation failures, factory rejections) — those
91
+ * surface with the plain message intact.
92
+ */
93
+ function parseMeshDbErrorKind(err) {
94
+ if (!(err instanceof Error))
95
+ return null;
96
+ // Accept digits too (`protocol_v2_mismatch`-style future kinds).
97
+ const m = err.message.match(/^<<meshdb-kind:([a-z0-9_]+)>>(.*)$/s);
98
+ if (!m)
99
+ return null;
100
+ return { kind: m[1], message: m[2] };
101
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@net-mesh/core",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "High-performance, schema-agnostic event bus for AI runtime workloads",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,6 +20,10 @@
20
20
  "./meshdb": {
21
21
  "types": "./meshdb.d.ts",
22
22
  "default": "./meshdb.js"
23
+ },
24
+ "./aggregator": {
25
+ "types": "./aggregator.d.ts",
26
+ "default": "./aggregator.js"
23
27
  }
24
28
  },
25
29
  "napi": {
@@ -56,6 +60,10 @@
56
60
  "errors.d.ts",
57
61
  "mesh_rpc.js",
58
62
  "mesh_rpc.d.ts",
63
+ "meshdb.js",
64
+ "meshdb.d.ts",
65
+ "aggregator.js",
66
+ "aggregator.d.ts",
59
67
  "*.node"
60
68
  ],
61
69
  "devDependencies": {
@@ -66,9 +74,9 @@
66
74
  },
67
75
  "scripts": {
68
76
  "artifacts": "napi artifacts",
69
- "build": "napi build --platform --release --features redis,net,cortex,compute,groups,meshos,deck,meshdb",
70
- "build:debug": "napi build --platform --features redis,net,cortex,compute,groups,meshos,deck,meshdb",
71
- "build:test": "napi build --platform --features redis,net,cortex,compute,groups,meshos,deck,meshdb,test-helpers",
77
+ "build": "napi build --platform --release --features redis,net,cortex,compute,groups,meshos,deck,meshdb,aggregator",
78
+ "build:debug": "napi build --platform --features redis,net,cortex,compute,groups,meshos,deck,meshdb,aggregator",
79
+ "build:test": "napi build --platform --features redis,net,cortex,compute,groups,meshos,deck,meshdb,aggregator,test-helpers",
72
80
  "build:ts": "tsc -p tsconfig.build.json",
73
81
  "prepublishOnly": "npm run build:ts && napi prepublish -t npm",
74
82
  "test": "vitest run",
@@ -83,13 +91,13 @@
83
91
  "node": ">=20"
84
92
  },
85
93
  "optionalDependencies": {
86
- "@net-mesh/core-win32-x64-msvc": "0.21.0",
87
- "@net-mesh/core-win32-arm64-msvc": "0.21.0",
88
- "@net-mesh/core-darwin-x64": "0.21.0",
89
- "@net-mesh/core-darwin-arm64": "0.21.0",
90
- "@net-mesh/core-linux-x64-gnu": "0.21.0",
91
- "@net-mesh/core-linux-x64-musl": "0.21.0",
92
- "@net-mesh/core-linux-arm64-gnu": "0.21.0",
93
- "@net-mesh/core-linux-arm64-musl": "0.21.0"
94
+ "@net-mesh/core-win32-x64-msvc": "0.23.0",
95
+ "@net-mesh/core-win32-arm64-msvc": "0.23.0",
96
+ "@net-mesh/core-darwin-x64": "0.23.0",
97
+ "@net-mesh/core-darwin-arm64": "0.23.0",
98
+ "@net-mesh/core-linux-x64-gnu": "0.23.0",
99
+ "@net-mesh/core-linux-x64-musl": "0.23.0",
100
+ "@net-mesh/core-linux-arm64-gnu": "0.23.0",
101
+ "@net-mesh/core-linux-arm64-musl": "0.23.0"
94
102
  }
95
103
  }