@loradb/lora-node 0.1.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/LICENSE ADDED
@@ -0,0 +1,87 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: LoraDB, Inc.
6
+ Licensed Work: LoraDB
7
+ Change Date: 2029-04-19
8
+ Change License: Apache License, Version 2.0
9
+
10
+ Additional Use Grant: You may use, copy, modify, create derivative works of,
11
+ distribute, and make production use of the Licensed Work
12
+ for internal business purposes and non-production
13
+ purposes, provided that you do not use the Licensed Work
14
+ to offer, operate, or make available a database-as-a-
15
+ service, hosted API, managed database platform, or any
16
+ substantially similar hosted service for third parties.
17
+
18
+ The Additional Use Grant does not permit using the
19
+ Licensed Work to provide a commercial or non-commercial
20
+ hosted service that allows third parties to access LoraDB
21
+ functionality, including as part of a competing managed
22
+ database platform, backend-as-a-service, application
23
+ platform, developer platform, or resale offering.
24
+
25
+ Business Source License
26
+
27
+ Terms
28
+
29
+ The Licensor hereby grants you the right to copy, modify, create derivative
30
+ works, redistribute, and make non-production use of the Licensed Work. The
31
+ Licensor may make an Additional Use Grant, above, permitting limited production
32
+ use.
33
+
34
+ Effective on the Change Date, or the fourth anniversary of the first publicly
35
+ available distribution of a specific version of the Licensed Work under this
36
+ License, whichever comes first, the Licensor hereby grants you rights under
37
+ the terms of the Change License, and the rights granted in the paragraph
38
+ above terminate.
39
+
40
+ If your use of the Licensed Work does not comply with the requirements
41
+ currently in effect as described in this License, you must purchase a
42
+ commercial license from the Licensor, its affiliated entities, or authorized
43
+ resellers, or you must refrain from using the Licensed Work.
44
+
45
+ All copies of the original and modified Licensed Work, and derivative works
46
+ of the Licensed Work, are subject to this License. This License applies
47
+ separately for each version of the Licensed Work and the Change Date may vary
48
+ for each version of the Licensed Work released by Licensor.
49
+
50
+ You must conspicuously display this License on each original or modified copy
51
+ of the Licensed Work. If you receive the Licensed Work in original or modified
52
+ form from a third party, the terms and conditions set forth in this License
53
+ apply to your use of that work.
54
+
55
+ Any use of the Licensed Work in violation of this License will automatically
56
+ terminate your rights under this License for the current and all other
57
+ versions of the Licensed Work.
58
+
59
+ This License does not grant you any right in any trademark or logo of Licensor
60
+ or its affiliates.
61
+
62
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
63
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
64
+ EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY,
65
+ FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
66
+
67
+ MariaDB hereby grants you permission to use this License's text to license
68
+ your works, and to refer to it using the trademark "Business Source License",
69
+ as long as you comply with the Covenants of Licensor below.
70
+
71
+ Covenants of Licensor
72
+
73
+ In consideration of the right to use this License's text and the "Business
74
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
75
+ other recipients of the licensed work to be provided by Licensor:
76
+
77
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
78
+ or a license that is compatible with GPL Version 2.0 or a later version,
79
+ where "compatible" means that software provided under the Change License can
80
+ be included in a program with software provided under GPL Version 2.0 or a
81
+ later version. Licensor may specify additional Change Licenses without
82
+ limitation.
83
+ 2. To either: (a) specify an additional grant of rights to use that does not
84
+ impose any additional restriction on the right granted in this License, as
85
+ the Additional Use Grant; or (b) insert the text "None".
86
+ 3. To specify a Change Date.
87
+ 4. Not to modify this License in any other way.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # lora-node
2
+
3
+ Node.js / TypeScript bindings for the [Lora](../../README.md) in-memory
4
+ graph engine. The package exposes a first-class typed API: query results are
5
+ modelled as discriminated unions, temporal values carry `kind` tags, and the
6
+ `Database` class is strongly typed in both directions (params and rows).
7
+
8
+ **Non-blocking:** `execute()` dispatches each query to the libuv threadpool via
9
+ [`napi::Task`](https://napi.rs/docs/compat-mode/async-task). The JS event loop
10
+ stays free for the full duration of a query — a 2 000-node MATCH happily
11
+ interleaves with `setImmediate` ticks on the main thread (proven by a
12
+ dedicated vitest).
13
+
14
+ > **Status:** prototype / feasibility check. Not published to npm.
15
+
16
+ ## Install (local dev)
17
+
18
+ ```bash
19
+ cd crates/lora-node
20
+ npm install
21
+ npm run build # builds the Rust cdylib + TypeScript declarations
22
+ npm test # runs the vitest suite
23
+ ```
24
+
25
+ The `npm run build:native` step uses [`@napi-rs/cli`](https://napi.rs/) and
26
+ produces a platform-specific `lora-node.<platform>-<arch>.node` artifact next
27
+ to `package.json`.
28
+
29
+ ## Usage
30
+
31
+ `lora-node` is **async-only** — the sole initialization pattern is
32
+ `createDatabase()`. There is no synchronous constructor and no
33
+ `Database.create()` static; `Database` is a type-only export.
34
+
35
+ ```ts
36
+ import { createDatabase, isNode, type LoraNode } from "lora-node";
37
+
38
+ const db = await createDatabase();
39
+ await db.execute("CREATE (:Person {name: $n, age: $a})", { n: "Alice", a: 30 });
40
+
41
+ const res = await db.execute<{ n: LoraNode }>("MATCH (n:Person) RETURN n");
42
+ for (const row of res.rows) {
43
+ if (isNode(row.n)) {
44
+ console.log(row.n.properties.name);
45
+ }
46
+ }
47
+ ```
48
+
49
+ The API matches `lora-wasm` verbatim — same shared types, same
50
+ `createDatabase()` entry point, same async method signatures — so
51
+ switching backends is a single import change.
52
+
53
+ ## Typed value model
54
+
55
+ | TS type | Runtime shape |
56
+ |-------------------------|-------------------------------------------------------------------------------|
57
+ | `null`/`boolean`/`number`/`string` | pass-through JS primitives |
58
+ | `LoraValue[]` / object | homogeneous arrays and nested records |
59
+ | `LoraNode` | `{ kind: "node", id, labels, properties }` |
60
+ | `LoraRelationship` | `{ kind: "relationship", id, startId, endId, type, properties }` |
61
+ | `LoraPath` | `{ kind: "path", nodes: number[], rels: number[] }` |
62
+ | `LoraDate`…`LoraDuration` | `{ kind: "date", iso: "YYYY-MM-DD" }` etc. |
63
+ | `LoraPoint` | Discriminated union on `srid`, see below |
64
+
65
+ `LoraPoint` is a discriminated union over the four supported CRSes:
66
+
67
+ | Shape | Meaning |
68
+ |--------------------------------------------------------------------------------------------------------------|----------------------|
69
+ | `{ kind: "point", srid: 7203, crs: "cartesian", x, y }` | Cartesian 2D |
70
+ | `{ kind: "point", srid: 9157, crs: "cartesian-3D", x, y, z }` | Cartesian 3D |
71
+ | `{ kind: "point", srid: 4326, crs: "WGS-84-2D", x, y, longitude, latitude }` | WGS-84 2D |
72
+ | `{ kind: "point", srid: 4979, crs: "WGS-84-3D", x, y, z, longitude, latitude, height }` | WGS-84 3D |
73
+
74
+ Helper constructors (`date("2025-01-15")`, `cartesian(1, 2)`, `cartesian3d(1, 2, 3)`,
75
+ `wgs84(lon, lat)`, `wgs84_3d(lon, lat, height)`, `duration("P1M")`, …) and
76
+ narrowing guards (`isNode`, `isRelationship`, `isPath`, `isPoint`, `isTemporal`)
77
+ are exported from `lora-node`.
78
+
79
+ > `distance()` on WGS-84-3D points ignores `height` — see
80
+ > [functions reference](../../apps/loradb.com/docs/functions/overview.md) for the full spatial
81
+ > reference and known limitations.
82
+
83
+ ## Architecture
84
+
85
+ ```
86
+ lora-database (Rust)
87
+ └── lora-node (crate, cdylib) <- napi-rs bindings, AsyncTask
88
+ └── ts/index.ts <- strongly-typed async wrapper
89
+ └── ../shared-ts/types.ts <- shared TS contract (with lora-wasm)
90
+ ```
91
+
92
+ Query execution path:
93
+
94
+ ```
95
+ JS main thread libuv threadpool Rust
96
+ ────────────── ─────────────────── ────────────────
97
+ db.execute(…) ──► ExecuteTask::compute() ──► parser → analyzer →
98
+ compiler → executor →
99
+ storage
100
+ ◄── resolve() wraps serde_json::Value
101
+ into JsUnknown and resolves the Promise
102
+ ```
103
+
104
+ The Rust crate is added to the workspace root (`Cargo.toml`). The Node side is
105
+ self-contained inside this directory. Only sub-millisecond operations
106
+ (`clear`, `nodeCount`, `relationshipCount`) stay synchronous inside napi; the
107
+ TS wrapper still exposes them as `Promise`-returning methods to keep the API
108
+ identical to `lora-wasm`.
109
+
110
+ ## Errors
111
+
112
+ `db.execute(...)` throws `LoraError` with a narrowed `code`:
113
+
114
+ - `LORA_ERROR` — parse / analyze / execute failure
115
+ - `INVALID_PARAMS` — a param value could not be mapped to a `LoraValue`
116
+
117
+ ## Known limitations
118
+
119
+ - **Concurrent writes.** Each `execute()` hops through the threadpool and
120
+ serialises on the store mutex inside Rust, so concurrent read/read and
121
+ read/write traffic works. Firing many concurrent write queries against
122
+ the same `Database` (e.g. 2 000 parallel `CREATE`s via `Promise.all`)
123
+ can expose races in the underlying engine — treat the mutex as
124
+ per-operation, not per-query. Prefer `await`-in-a-loop or a single
125
+ batched query for heavy write workloads.
126
+ - **I64 precision.** Integer values above `Number.MAX_SAFE_INTEGER`
127
+ (2^53) are returned as JS `number` and lose precision. A `bigint`-aware
128
+ path would require extending the value serializer.
129
+ - **Cancellation.** The napi `Task` abstraction does not support
130
+ cancellation once dispatched; a runaway query runs to completion.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * lora-node — typed Node.js binding for the Lora graph engine.
3
+ *
4
+ * Thin wrapper over the N-API module. Query execution is delegated to the
5
+ * native layer, which runs each query on the libuv threadpool so the JS
6
+ * event loop stays responsive. This file only narrows the `unknown`-valued
7
+ * native surface into the strongly-typed `QueryResult<T>` / `LoraParams`
8
+ * shapes defined in the shared TS contract (`crates/shared-ts/types.ts`).
9
+ *
10
+ * **Initialization is async-only.** The one canonical entry point is
11
+ * `createDatabase()`; there is no synchronous constructor. See the docs at
12
+ * https://loradb.com/docs/getting-started/node for the full rationale.
13
+ */
14
+ import type { LoraParams, LoraValue, QueryResult } from "./types.js";
15
+ declare const NativeDatabase: typeof import("./native.js").Database;
16
+ export * from "./types.js";
17
+ /**
18
+ * In-memory Lora graph database instance.
19
+ *
20
+ * Obtained exclusively via `createDatabase()`. There is no public constructor
21
+ * and no synchronous factory — the async entry point lets the binding
22
+ * extend initialization later (lazy native loading, warmup, schema
23
+ * preflight) without breaking callers.
24
+ *
25
+ * Instances are independent — each owns its own in-memory graph. Multiple
26
+ * concurrent `execute()` calls against one instance run one at a time
27
+ * (serialised on the store mutex) but none of them block the event loop.
28
+ */
29
+ declare class DatabaseImpl {
30
+ #private;
31
+ constructor(inner: InstanceType<typeof NativeDatabase>);
32
+ /**
33
+ * Execute a Lora query on the libuv threadpool. Returns a Promise that
34
+ * resolves with `{ columns, rows }`; errors surface as `LoraError`
35
+ * with a narrowed `code` (`LORA_ERROR` / `INVALID_PARAMS`).
36
+ */
37
+ execute<T extends Record<string, LoraValue> = Record<string, LoraValue>>(query: string, params?: LoraParams): Promise<QueryResult<T>>;
38
+ /** Drop every node and relationship. Constant-time under the hood. */
39
+ clear(): Promise<void>;
40
+ /** Number of nodes currently in the graph. */
41
+ nodeCount(): Promise<number>;
42
+ /** Number of relationships currently in the graph. */
43
+ relationshipCount(): Promise<number>;
44
+ }
45
+ /**
46
+ * Public type for a LoraDB instance.
47
+ *
48
+ * Exported as a type only — there is no runtime `Database` value. To obtain
49
+ * an instance, always use `createDatabase()`:
50
+ *
51
+ * ```ts
52
+ * import { createDatabase, type Database } from "lora-node";
53
+ *
54
+ * const db: Database = await createDatabase();
55
+ * ```
56
+ */
57
+ export type Database = DatabaseImpl;
58
+ /**
59
+ * Create and initialize a new in-memory LoraDB instance.
60
+ *
61
+ * **This is the only supported initialization pattern** for `lora-node`.
62
+ * Synchronous construction is not available — the async factory guarantees
63
+ * the native layer is ready before the first query dispatches and keeps
64
+ * the Node and WASM surfaces symmetric.
65
+ *
66
+ * ```ts
67
+ * import { createDatabase } from "lora-node";
68
+ *
69
+ * const db = await createDatabase();
70
+ * const res = await db.execute(
71
+ * "CREATE (n:Person {name: $name}) RETURN n",
72
+ * { name: "Alice" },
73
+ * );
74
+ * ```
75
+ *
76
+ * Each call returns an independent graph — no shared state between instances.
77
+ */
78
+ export declare function createDatabase(): Promise<Database>;
79
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACZ,MAAM,YAAY,CAAC;AAOpB,QAAA,MAAM,cAAc,EAAE,cAAc,aAAa,EAAE,QAA0B,CAAC;AAE9E,cAAc,YAAY,CAAC;AAE3B;;;;;;;;;;;GAWG;AACH,cAAM,YAAY;;gBAGJ,KAAK,EAAE,YAAY,CAAC,OAAO,cAAc,CAAC;IAItD;;;;OAIG;IACG,OAAO,CACX,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/D,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAS9D,sEAAsE;IAChE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,8CAA8C;IACxC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,sDAAsD;IAChD,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;CAG3C;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC,CAExD"}
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * lora-node — typed Node.js binding for the Lora graph engine.
4
+ *
5
+ * Thin wrapper over the N-API module. Query execution is delegated to the
6
+ * native layer, which runs each query on the libuv threadpool so the JS
7
+ * event loop stays responsive. This file only narrows the `unknown`-valued
8
+ * native surface into the strongly-typed `QueryResult<T>` / `LoraParams`
9
+ * shapes defined in the shared TS contract (`crates/shared-ts/types.ts`).
10
+ *
11
+ * **Initialization is async-only.** The one canonical entry point is
12
+ * `createDatabase()`; there is no synchronous constructor. See the docs at
13
+ * https://loradb.com/docs/getting-started/node for the full rationale.
14
+ */
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
+ };
29
+ var __importDefault = (this && this.__importDefault) || function (mod) {
30
+ return (mod && mod.__esModule) ? mod : { "default": mod };
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.createDatabase = createDatabase;
34
+ const types_js_1 = require("./types.js");
35
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36
+ // @ts-ignore - resolved at runtime via native.js loader
37
+ const native_js_1 = __importDefault(require("./native.js"));
38
+ const NativeDatabase = native_js_1.default.Database;
39
+ __exportStar(require("./types.js"), exports);
40
+ /**
41
+ * In-memory Lora graph database instance.
42
+ *
43
+ * Obtained exclusively via `createDatabase()`. There is no public constructor
44
+ * and no synchronous factory — the async entry point lets the binding
45
+ * extend initialization later (lazy native loading, warmup, schema
46
+ * preflight) without breaking callers.
47
+ *
48
+ * Instances are independent — each owns its own in-memory graph. Multiple
49
+ * concurrent `execute()` calls against one instance run one at a time
50
+ * (serialised on the store mutex) but none of them block the event loop.
51
+ */
52
+ class DatabaseImpl {
53
+ #inner;
54
+ constructor(inner) {
55
+ this.#inner = inner;
56
+ }
57
+ /**
58
+ * Execute a Lora query on the libuv threadpool. Returns a Promise that
59
+ * resolves with `{ columns, rows }`; errors surface as `LoraError`
60
+ * with a narrowed `code` (`LORA_ERROR` / `INVALID_PARAMS`).
61
+ */
62
+ async execute(query, params) {
63
+ try {
64
+ const raw = await this.#inner.execute(query, params ?? null);
65
+ return raw;
66
+ }
67
+ catch (err) {
68
+ throw (0, types_js_1.wrapError)(err);
69
+ }
70
+ }
71
+ /** Drop every node and relationship. Constant-time under the hood. */
72
+ async clear() {
73
+ this.#inner.clear();
74
+ }
75
+ /** Number of nodes currently in the graph. */
76
+ async nodeCount() {
77
+ return this.#inner.nodeCount();
78
+ }
79
+ /** Number of relationships currently in the graph. */
80
+ async relationshipCount() {
81
+ return this.#inner.relationshipCount();
82
+ }
83
+ }
84
+ /**
85
+ * Create and initialize a new in-memory LoraDB instance.
86
+ *
87
+ * **This is the only supported initialization pattern** for `lora-node`.
88
+ * Synchronous construction is not available — the async factory guarantees
89
+ * the native layer is ready before the first query dispatches and keeps
90
+ * the Node and WASM surfaces symmetric.
91
+ *
92
+ * ```ts
93
+ * import { createDatabase } from "lora-node";
94
+ *
95
+ * const db = await createDatabase();
96
+ * const res = await db.execute(
97
+ * "CREATE (n:Person {name: $name}) RETURN n",
98
+ * { name: "Alice" },
99
+ * );
100
+ * ```
101
+ *
102
+ * Each call returns an independent graph — no shared state between instances.
103
+ */
104
+ async function createDatabase() {
105
+ return new DatabaseImpl(new NativeDatabase());
106
+ }
107
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;AAsGH,wCAEC;AAjGD,yCAAuC;AAEvC,6DAA6D;AAC7D,wDAAwD;AACxD,4DAAiC;AAEjC,MAAM,cAAc,GAA0C,mBAAM,CAAC,QAAQ,CAAC;AAE9E,6CAA2B;AAE3B;;;;;;;;;;;GAWG;AACH,MAAM,YAAY;IACP,MAAM,CAAsC;IAErD,YAAY,KAA0C;QACpD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAEX,KAAa,EAAE,MAAmB;QAClC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC;YAC7D,OAAO,GAAqB,CAAC;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAA,oBAAS,EAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,8CAA8C;IAC9C,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IAED,sDAAsD;IACtD,KAAK,CAAC,iBAAiB;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;IACzC,CAAC;CACF;AAgBD;;;;;;;;;;;;;;;;;;;GAmBG;AACI,KAAK,UAAU,cAAc;IAClC,OAAO,IAAI,YAAY,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _exports: any;
2
+ export = _exports;
3
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../ts/native.js"],"names":[],"mappings":""}
package/dist/native.js ADDED
@@ -0,0 +1,85 @@
1
+ // Native module loader. Picks the right platform-specific prebuilt binary if
2
+ // present, otherwise falls back to the dev build produced by `napi build`.
3
+ //
4
+ // napi-rs appends an ABI suffix on some platforms:
5
+ // - Linux GNU: lora-node.linux-x64-gnu.node
6
+ // - Linux musl: lora-node.linux-x64-musl.node
7
+ // - Windows: lora-node.win32-x64-msvc.node
8
+ // - macOS: lora-node.darwin-arm64.node (no ABI suffix)
9
+ // - FreeBSD: lora-node.freebsd-x64.node
10
+ //
11
+ // Published installs resolve the binary through an optional platform
12
+ // subpackage named `@loradb/lora-node-<triple>`; local dev builds drop the
13
+ // `.node` at the crate root. We try both.
14
+ "use strict";
15
+ const { platform, arch } = process;
16
+ const { existsSync, readFileSync } = require("node:fs");
17
+ const { join } = require("node:path");
18
+ const { execSync } = require("node:child_process");
19
+ function isMuslLibc() {
20
+ // glibc `ldd --version` mentions GNU; musl's mentions "musl".
21
+ try {
22
+ const out = execSync("ldd --version", { stdio: ["ignore", "pipe", "pipe"] })
23
+ .toString()
24
+ .toLowerCase();
25
+ return out.includes("musl");
26
+ }
27
+ catch {
28
+ // When ldd can't be run, fall back to Node's process report which
29
+ // exposes `glibcVersionRuntime` only on glibc systems.
30
+ try {
31
+ const header = process.report?.getReport()?.header;
32
+ if (header && "glibcVersionRuntime" in header)
33
+ return false;
34
+ }
35
+ catch {
36
+ /* ignore */
37
+ }
38
+ // Default to glibc — the common case on CI Linux runners.
39
+ return false;
40
+ }
41
+ }
42
+ function candidateTriples() {
43
+ if (platform === "linux") {
44
+ const libc = isMuslLibc() ? "musl" : "gnu";
45
+ return [`${platform}-${arch}-${libc}`, `${platform}-${arch}`];
46
+ }
47
+ if (platform === "win32") {
48
+ return [`${platform}-${arch}-msvc`, `${platform}-${arch}`];
49
+ }
50
+ // darwin, freebsd, etc — napi doesn't add an ABI suffix.
51
+ return [`${platform}-${arch}`];
52
+ }
53
+ function loadNative() {
54
+ const triples = candidateTriples();
55
+ // 1. Local dev build at the crate root (produced by `napi build`).
56
+ const localCandidates = [
57
+ ...triples.map((t) => `lora-node.${t}.node`),
58
+ "lora.node",
59
+ "lora-node.node",
60
+ ];
61
+ for (const name of localCandidates) {
62
+ const candidate = join(__dirname, "..", name);
63
+ if (existsSync(candidate)) {
64
+ return require(candidate);
65
+ }
66
+ }
67
+ // 2. Platform-specific npm subpackage (@loradb/lora-node-<triple>).
68
+ const subpackageNames = triples.map((t) => `@loradb/lora-node-${t}`);
69
+ for (const name of subpackageNames) {
70
+ try {
71
+ return require(name);
72
+ }
73
+ catch (err) {
74
+ if (err && err.code !== "MODULE_NOT_FOUND")
75
+ throw err;
76
+ // fall through to the next triple / final error.
77
+ }
78
+ }
79
+ throw new Error(`lora-node: no native binary found for ${platform}-${arch}. ` +
80
+ `Tried local: ${localCandidates.join(", ")}. ` +
81
+ `Tried npm: ${subpackageNames.join(", ")}. ` +
82
+ "For local development, run `npm run build` in the crate directory.");
83
+ }
84
+ module.exports = loadNative();
85
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../ts/native.js"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2EAA2E;AAC3E,EAAE;AACF,mDAAmD;AACnD,gDAAgD;AAChD,iDAAiD;AACjD,iDAAiD;AACjD,gEAAgE;AAChE,8CAA8C;AAC9C,EAAE;AACF,qEAAqE;AACrE,2EAA2E;AAC3E,0CAA0C;AAE1C,YAAY,CAAC;AAEb,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;AACnC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACxD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACtC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnD,SAAS,UAAU;IACjB,8DAA8D;IAC9D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,QAAQ,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;aACzE,QAAQ,EAAE;aACV,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC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AAS,CAAC,EAAE,CAAC;YAC1B,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,oEAAoE;IACpE,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC;IACrE,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB;gBAAE,MAAM,GAAG,CAAC;YACtD,iDAAiD;QACnD,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,yCAAyC,QAAQ,IAAI,IAAI,IAAI;QAC3D,gBAAgB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAC9C,cAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAC5C,oEAAoE,CACvE,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,UAAU,EAAE,CAAC"}
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Canonical typed value model for the JS-facing Lora packages
3
+ * (`lora-node` and `lora-wasm`).
4
+ *
5
+ * Every structural value carries a `kind` discriminator. Temporal and
6
+ * spatial values are tagged so TypeScript can narrow safely after a
7
+ * query runs.
8
+ *
9
+ * Canonical source: `crates/shared-ts/types.ts`. Each JS-facing package
10
+ * (`lora-node`, `lora-wasm`) copies this file into its own `ts/` dir
11
+ * via its `sync:types` npm script. The `verify:types` script fails CI if
12
+ * the copies drift — do not edit the per-package copies directly.
13
+ */
14
+ /**
15
+ * Values accepted as Lora query parameters. Mirrors `LoraValue` but
16
+ * also allows plain JS scalars / arrays / objects. Temporal and spatial
17
+ * values must be passed as tagged objects so the bridge can parse them
18
+ * without ambiguity.
19
+ */
20
+ export type LoraParam = null | boolean | number | string | LoraParam[] | {
21
+ [key: string]: LoraParam;
22
+ } | LoraDate | LoraTime | LoraLocalTime | LoraDateTime | LoraLocalDateTime | LoraDuration | LoraPoint;
23
+ export type LoraParams = Record<string, LoraParam>;
24
+ export interface LoraNode {
25
+ kind: "node";
26
+ id: number;
27
+ labels: string[];
28
+ properties: Record<string, LoraValue>;
29
+ }
30
+ export interface LoraRelationship {
31
+ kind: "relationship";
32
+ id: number;
33
+ startId: number;
34
+ endId: number;
35
+ type: string;
36
+ properties: Record<string, LoraValue>;
37
+ }
38
+ export interface LoraPath {
39
+ kind: "path";
40
+ nodes: number[];
41
+ rels: number[];
42
+ }
43
+ export interface LoraDate {
44
+ kind: "date";
45
+ /** `YYYY-MM-DD` */
46
+ iso: string;
47
+ }
48
+ export interface LoraTime {
49
+ kind: "time";
50
+ /** `HH:MM:SS[.nnn][Z|±HH:MM]` */
51
+ iso: string;
52
+ }
53
+ export interface LoraLocalTime {
54
+ kind: "localtime";
55
+ /** `HH:MM:SS[.nnn]` */
56
+ iso: string;
57
+ }
58
+ export interface LoraDateTime {
59
+ kind: "datetime";
60
+ /** `YYYY-MM-DDTHH:MM:SS[.nnn][Z|±HH:MM]` */
61
+ iso: string;
62
+ }
63
+ export interface LoraLocalDateTime {
64
+ kind: "localdatetime";
65
+ /** `YYYY-MM-DDTHH:MM:SS[.nnn]` */
66
+ iso: string;
67
+ }
68
+ export interface LoraDuration {
69
+ kind: "duration";
70
+ /** ISO-8601 duration, e.g. `P1Y2M3DT4H5M6S` */
71
+ iso: string;
72
+ }
73
+ export type TemporalKind = "date" | "time" | "localtime" | "datetime" | "localdatetime" | "duration";
74
+ export type LoraTemporal = LoraDate | LoraTime | LoraLocalTime | LoraDateTime | LoraLocalDateTime | LoraDuration;
75
+ /**
76
+ * Supported spatial-reference identifiers.
77
+ *
78
+ * - `7203` — Cartesian 2D
79
+ * - `9157` — Cartesian 3D
80
+ * - `4326` — WGS-84 Geographic 2D
81
+ * - `4979` — WGS-84 Geographic 3D
82
+ */
83
+ export type LoraPointSrid = 7203 | 9157 | 4326 | 4979;
84
+ /**
85
+ * Canonical CRS name string. Mirrors `srid` 1:1 on the output side; on
86
+ * the input side, `point({…, crs: "…"})` accepts these plus the alias
87
+ * `"WGS-84"` (equivalent to `"WGS-84-2D"`) — see the engine README.
88
+ */
89
+ export type LoraPointCrs = "cartesian" | "cartesian-3D" | "WGS-84-2D" | "WGS-84-3D";
90
+ /** Cartesian 2D point. */
91
+ export interface LoraCartesianPoint {
92
+ kind: "point";
93
+ srid: 7203;
94
+ crs: "cartesian";
95
+ x: number;
96
+ y: number;
97
+ }
98
+ /** Cartesian 3D point. */
99
+ export interface LoraCartesianPoint3D {
100
+ kind: "point";
101
+ srid: 9157;
102
+ crs: "cartesian-3D";
103
+ x: number;
104
+ y: number;
105
+ z: number;
106
+ }
107
+ /**
108
+ * WGS-84 geographic 2D point.
109
+ *
110
+ * `x === longitude` and `y === latitude`. Both naming conventions are
111
+ * exposed so consumers can pick whichever is clearer at the call site.
112
+ */
113
+ export interface LoraWgs84Point {
114
+ kind: "point";
115
+ srid: 4326;
116
+ crs: "WGS-84-2D";
117
+ x: number;
118
+ y: number;
119
+ longitude: number;
120
+ latitude: number;
121
+ }
122
+ /**
123
+ * WGS-84 geographic 3D point.
124
+ *
125
+ * `x === longitude`, `y === latitude`, `z === height` (metres).
126
+ *
127
+ * **Caveat:** `distance()` on WGS-84-3D points currently ignores
128
+ * `height` and computes the great-circle surface distance only. A full
129
+ * 3D geodesic distance is not implemented.
130
+ */
131
+ export interface LoraWgs84Point3D {
132
+ kind: "point";
133
+ srid: 4979;
134
+ crs: "WGS-84-3D";
135
+ x: number;
136
+ y: number;
137
+ z: number;
138
+ longitude: number;
139
+ latitude: number;
140
+ height: number;
141
+ }
142
+ /**
143
+ * Any point value returned by the engine. Narrow via the `srid` or
144
+ * `crs` discriminator (or the `isPoint` guard plus `point.srid`).
145
+ */
146
+ export type LoraPoint = LoraCartesianPoint | LoraCartesianPoint3D | LoraWgs84Point | LoraWgs84Point3D;
147
+ export type LoraValue = null | boolean | number | string | LoraValue[] | {
148
+ [key: string]: LoraValue;
149
+ } | LoraNode | LoraRelationship | LoraPath | LoraDate | LoraTime | LoraLocalTime | LoraDateTime | LoraLocalDateTime | LoraDuration | LoraPoint;
150
+ export type QueryRow<T extends Record<string, LoraValue> = Record<string, LoraValue>> = T;
151
+ export interface QueryResult<T extends Record<string, LoraValue> = Record<string, LoraValue>> {
152
+ columns: string[];
153
+ rows: QueryRow<T>[];
154
+ }
155
+ export declare function isNode(v: LoraValue): v is LoraNode;
156
+ export declare function isRelationship(v: LoraValue): v is LoraRelationship;
157
+ export declare function isPath(v: LoraValue): v is LoraPath;
158
+ export declare function isPoint(v: LoraValue): v is LoraPoint;
159
+ export declare function isTemporal(v: LoraValue): v is LoraTemporal;
160
+ export declare const date: (iso: string) => LoraDate;
161
+ export declare const time: (iso: string) => LoraTime;
162
+ export declare const localtime: (iso: string) => LoraLocalTime;
163
+ export declare const datetime: (iso: string) => LoraDateTime;
164
+ export declare const localdatetime: (iso: string) => LoraLocalDateTime;
165
+ export declare const duration: (iso: string) => LoraDuration;
166
+ export declare const cartesian: (x: number, y: number) => LoraCartesianPoint;
167
+ export declare const cartesian3d: (x: number, y: number, z: number) => LoraCartesianPoint3D;
168
+ export declare const wgs84: (longitude: number, latitude: number) => LoraWgs84Point;
169
+ export declare const wgs84_3d: (longitude: number, latitude: number, height: number) => LoraWgs84Point3D;
170
+ /**
171
+ * Error codes emitted by the engine bridges.
172
+ *
173
+ * - `LORA_ERROR` — parse / analyze / execute failure
174
+ * - `INVALID_PARAMS` — a param value could not be mapped to a Lora value
175
+ * - `WORKER_ERROR` — worker transport / lifecycle failure (wasm worker only)
176
+ * - `UNKNOWN` — fall-through for unrecognised error shapes
177
+ */
178
+ export type LoraErrorCode = "LORA_ERROR" | "INVALID_PARAMS" | "WORKER_ERROR" | "UNKNOWN";
179
+ /**
180
+ * Error thrown by `Database.execute` when Lora parsing, analysis, or
181
+ * execution fails.
182
+ */
183
+ export declare class LoraError extends Error {
184
+ readonly code: LoraErrorCode;
185
+ constructor(message: string, code?: LoraErrorCode);
186
+ }
187
+ /**
188
+ * Normalise a thrown value into a `LoraError` with a narrowed `code`
189
+ * when the message carries a recognised prefix; otherwise returns the
190
+ * original `Error` unchanged.
191
+ */
192
+ export declare function wrapError(err: unknown): Error;
193
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GACjB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC5B,QAAQ,GACR,QAAQ,GACR,aAAa,GACb,YAAY,GACZ,iBAAiB,GACjB,YAAY,GACZ,SAAS,CAAC;AAEd,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAMnD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE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,CAAC;AAEH,eAAO,MAAM,KAAK,GAChB,WAAW,MAAM,EACjB,UAAU,MAAM,KACf,cAQD,CAAC;AAEH,eAAO,MAAM,QAAQ,GACnB,WAAW,MAAM,EACjB,UAAU,MAAM,EAChB,QAAQ,MAAM,KACb,gBAUD,CAAC;AAMH;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,gBAAgB,GAChB,cAAc,GACd,SAAS,CAAC;AAEd;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,IAAI,EAAE,aAAa,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,aAAyB;CAK7D;AAID;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAO7C"}
package/dist/types.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Canonical typed value model for the JS-facing Lora packages
4
+ * (`lora-node` and `lora-wasm`).
5
+ *
6
+ * Every structural value carries a `kind` discriminator. Temporal and
7
+ * spatial values are tagged so TypeScript can narrow safely after a
8
+ * query runs.
9
+ *
10
+ * Canonical source: `crates/shared-ts/types.ts`. Each JS-facing package
11
+ * (`lora-node`, `lora-wasm`) copies this file into its own `ts/` dir
12
+ * via its `sync:types` npm script. The `verify:types` script fails CI if
13
+ * the copies drift — do not edit the per-package copies directly.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.LoraError = exports.wgs84_3d = exports.wgs84 = exports.cartesian3d = exports.cartesian = exports.duration = exports.localdatetime = exports.datetime = exports.localtime = exports.time = exports.date = void 0;
17
+ exports.isNode = isNode;
18
+ exports.isRelationship = isRelationship;
19
+ exports.isPath = isPath;
20
+ exports.isPoint = isPoint;
21
+ exports.isTemporal = isTemporal;
22
+ exports.wrapError = wrapError;
23
+ // ---------------------------------------------------------------------------
24
+ // Guards
25
+ // ---------------------------------------------------------------------------
26
+ function isNode(v) {
27
+ return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "node";
28
+ }
29
+ function isRelationship(v) {
30
+ return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "relationship";
31
+ }
32
+ function isPath(v) {
33
+ return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "path";
34
+ }
35
+ function isPoint(v) {
36
+ return typeof v === "object" && v !== null && !Array.isArray(v) && v.kind === "point";
37
+ }
38
+ function isTemporal(v) {
39
+ if (typeof v !== "object" || v === null || Array.isArray(v))
40
+ return false;
41
+ const kind = v.kind;
42
+ return (kind === "date" ||
43
+ kind === "time" ||
44
+ kind === "localtime" ||
45
+ kind === "datetime" ||
46
+ kind === "localdatetime" ||
47
+ kind === "duration");
48
+ }
49
+ // ---------------------------------------------------------------------------
50
+ // Constructors
51
+ // ---------------------------------------------------------------------------
52
+ const date = (iso) => ({ kind: "date", iso });
53
+ exports.date = date;
54
+ const time = (iso) => ({ kind: "time", iso });
55
+ exports.time = time;
56
+ const localtime = (iso) => ({ kind: "localtime", iso });
57
+ exports.localtime = localtime;
58
+ const datetime = (iso) => ({ kind: "datetime", iso });
59
+ exports.datetime = datetime;
60
+ const localdatetime = (iso) => ({ kind: "localdatetime", iso });
61
+ exports.localdatetime = localdatetime;
62
+ const duration = (iso) => ({ kind: "duration", iso });
63
+ exports.duration = duration;
64
+ const cartesian = (x, y) => ({
65
+ kind: "point",
66
+ srid: 7203,
67
+ crs: "cartesian",
68
+ x,
69
+ y,
70
+ });
71
+ exports.cartesian = cartesian;
72
+ const cartesian3d = (x, y, z) => ({
73
+ kind: "point",
74
+ srid: 9157,
75
+ crs: "cartesian-3D",
76
+ x,
77
+ y,
78
+ z,
79
+ });
80
+ exports.cartesian3d = cartesian3d;
81
+ const wgs84 = (longitude, latitude) => ({
82
+ kind: "point",
83
+ srid: 4326,
84
+ crs: "WGS-84-2D",
85
+ x: longitude,
86
+ y: latitude,
87
+ longitude,
88
+ latitude,
89
+ });
90
+ exports.wgs84 = wgs84;
91
+ const wgs84_3d = (longitude, latitude, height) => ({
92
+ kind: "point",
93
+ srid: 4979,
94
+ crs: "WGS-84-3D",
95
+ x: longitude,
96
+ y: latitude,
97
+ z: height,
98
+ longitude,
99
+ latitude,
100
+ height,
101
+ });
102
+ exports.wgs84_3d = wgs84_3d;
103
+ /**
104
+ * Error thrown by `Database.execute` when Lora parsing, analysis, or
105
+ * execution fails.
106
+ */
107
+ class LoraError extends Error {
108
+ code;
109
+ constructor(message, code = "UNKNOWN") {
110
+ super(message);
111
+ this.name = "LoraError";
112
+ this.code = code;
113
+ }
114
+ }
115
+ exports.LoraError = LoraError;
116
+ const ERROR_PREFIX_RE = /^(LORA_ERROR|INVALID_PARAMS|WORKER_ERROR):\s*(.*)$/s;
117
+ /**
118
+ * Normalise a thrown value into a `LoraError` with a narrowed `code`
119
+ * when the message carries a recognised prefix; otherwise returns the
120
+ * original `Error` unchanged.
121
+ */
122
+ function wrapError(err) {
123
+ if (!(err instanceof Error))
124
+ return new LoraError(String(err), "UNKNOWN");
125
+ const match = ERROR_PREFIX_RE.exec(err.message);
126
+ if (match) {
127
+ return new LoraError(match[2], match[1]);
128
+ }
129
+ return err;
130
+ }
131
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AA6OH,wBAEC;AAED,wCAEC;AAED,wBAEC;AAED,0BAEC;AAED,gCAWC;AAsGD,8BAOC;AA5ID,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,SAAgB,MAAM,CAAC,CAAY;IACjC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAK,CAAwB,CAAC,IAAI,KAAK,MAAM,CAAC;AAC/G,CAAC;AAED,SAAgB,cAAc,CAAC,CAAY;IACzC,OAAO,OAAO,CAAC,K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;CACT,CAAC,CAAC;AAXU,QAAA,KAAK,SAWf;AAEI,MAAM,QAAQ,GAAG,CACtB,SAAiB,EACjB,QAAgB,EAChB,MAAc,EACI,EAAE,CAAC,CAAC;IACtB,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,WAAW;IAChB,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,MAAM;IACT,SAAS;IACT,QAAQ;IACR,MAAM;CACP,CAAC,CAAC;AAdU,QAAA,QAAQ,YAclB;AAoBH;;;GAGG;AACH,MAAa,SAAU,SAAQ,KAAK;IAClB,IAAI,CAAgB;IAEpC,YAAY,OAAe,EAAE,OAAsB,SAAS;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AARD,8BAQC;AAED,MAAM,eAAe,GAAG,qDAAqD,CAAC;AAE9E;;;;GAIG;AACH,SAAgB,SAAS,CAAC,GAAY;IACpC,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC;QAAE,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAChD,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,KAAK,CAAC,CAAC,CAAkB,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@loradb/lora-node",
3
+ "version": "0.1.0",
4
+ "description": "Node.js / TypeScript bindings for the Lora in-memory graph database",
5
+ "license": "BUSL-1.1",
6
+ "author": "LoraDB, Inc.",
7
+ "homepage": "https://github.com/lora-db/lora#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/lora-db/lora.git",
11
+ "directory": "crates/lora-node"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/lora-db/lora/issues"
15
+ },
16
+ "keywords": [
17
+ "lora",
18
+ "loradb",
19
+ "graph",
20
+ "cypher",
21
+ "database",
22
+ "napi",
23
+ "n-api",
24
+ "neo4j"
25
+ ],
26
+ "main": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js",
32
+ "require": "./dist/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist/",
37
+ "ts/native.js",
38
+ "ts/native.d.ts",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "provenance": true,
45
+ "registry": "https://registry.npmjs.org/"
46
+ },
47
+ "napi": {
48
+ "name": "lora-node",
49
+ "package": {
50
+ "name": "@loradb/lora-node"
51
+ },
52
+ "triples": {
53
+ "defaults": false,
54
+ "additional": [
55
+ "x86_64-unknown-linux-gnu",
56
+ "aarch64-unknown-linux-gnu",
57
+ "x86_64-apple-darwin",
58
+ "aarch64-apple-darwin",
59
+ "x86_64-pc-windows-msvc"
60
+ ]
61
+ }
62
+ },
63
+ "engines": {
64
+ "node": ">=18"
65
+ },
66
+ "scripts": {
67
+ "sync:types": "node -e \"require('fs').copyFileSync('../shared-ts/types.ts','ts/types.ts')\"",
68
+ "verify:types": "node -e \"const fs=require('fs'); const a=fs.readFileSync('../shared-ts/types.ts','utf8'); const b=fs.readFileSync('ts/types.ts','utf8'); if (a!==b) { console.error('ts/types.ts is out of sync with shared-ts/types.ts — run npm run sync:types'); process.exit(1);} \"",
69
+ "prebuild": "npm run sync:types",
70
+ "pretypecheck": "npm run sync:types",
71
+ "pretest": "npm run sync:types",
72
+ "build:native": "napi build --platform --release --js false",
73
+ "build:native:debug": "napi build --platform --js false",
74
+ "build:ts": "tsc -p tsconfig.json",
75
+ "build": "npm run build:native && npm run build:ts",
76
+ "typecheck": "tsc -p tsconfig.json --noEmit",
77
+ "test": "vitest run",
78
+ "test:watch": "vitest",
79
+ "artifacts": "napi artifacts",
80
+ "create-npm-dirs": "napi create-npm-dir -t .",
81
+ "copy-license": "node -e \"const fs=require('fs'); try { fs.copyFileSync('../../LICENSE','LICENSE'); } catch (e) { if (e.code !== 'ENOENT') throw e; }\"",
82
+ "prepack": "npm run sync:types && npm run copy-license && npm run build",
83
+ "pack:dry": "npm pack --dry-run"
84
+ },
85
+ "devDependencies": {
86
+ "@napi-rs/cli": "^2.18.4",
87
+ "@types/node": "^22.7.4",
88
+ "typescript": "^5.6.2",
89
+ "vitest": "^2.1.1"
90
+ },
91
+ "optionalDependencies": {
92
+ "@loradb/lora-node-linux-x64-gnu": "0.1.0",
93
+ "@loradb/lora-node-linux-arm64-gnu": "0.1.0",
94
+ "@loradb/lora-node-darwin-x64": "0.1.0",
95
+ "@loradb/lora-node-darwin-arm64": "0.1.0",
96
+ "@loradb/lora-node-win32-x64-msvc": "0.1.0"
97
+ }
98
+ }
package/ts/native.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Low-level typings for the native Rust N-API module (`cypher.node`).
3
+ *
4
+ * These mirror what napi-derive would generate. The high-level TS wrapper
5
+ * in `index.ts` narrows the return / param types to the strongly-typed
6
+ * `QueryResult<T>` / `LoraParams` surface.
7
+ */
8
+
9
+ export interface NativeQueryResult {
10
+ columns: string[];
11
+ rows: Array<Record<string, unknown>>;
12
+ }
13
+
14
+ export declare class Database {
15
+ constructor();
16
+ /** Non-blocking: runs on the libuv threadpool, returns a Promise. */
17
+ execute(
18
+ query: string,
19
+ params?: Record<string, unknown> | null,
20
+ ): Promise<NativeQueryResult>;
21
+ clear(): void;
22
+ nodeCount(): number;
23
+ relationshipCount(): number;
24
+ }
package/ts/native.js ADDED
@@ -0,0 +1,90 @@
1
+ // Native module loader. Picks the right platform-specific prebuilt binary if
2
+ // present, otherwise falls back to the dev build produced by `napi build`.
3
+ //
4
+ // napi-rs appends an ABI suffix on some platforms:
5
+ // - Linux GNU: lora-node.linux-x64-gnu.node
6
+ // - Linux musl: lora-node.linux-x64-musl.node
7
+ // - Windows: lora-node.win32-x64-msvc.node
8
+ // - macOS: lora-node.darwin-arm64.node (no ABI suffix)
9
+ // - FreeBSD: lora-node.freebsd-x64.node
10
+ //
11
+ // Published installs resolve the binary through an optional platform
12
+ // subpackage named `@loradb/lora-node-<triple>`; local dev builds drop the
13
+ // `.node` at the crate root. We try both.
14
+
15
+ "use strict";
16
+
17
+ const { platform, arch } = process;
18
+ const { existsSync, readFileSync } = require("node:fs");
19
+ const { join } = require("node:path");
20
+ const { execSync } = require("node:child_process");
21
+
22
+ function isMuslLibc() {
23
+ // glibc `ldd --version` mentions GNU; musl's mentions "musl".
24
+ try {
25
+ const out = execSync("ldd --version", { stdio: ["ignore", "pipe", "pipe"] })
26
+ .toString()
27
+ .toLowerCase();
28
+ return out.includes("musl");
29
+ } catch {
30
+ // When ldd can't be run, fall back to Node's process report which
31
+ // exposes `glibcVersionRuntime` only on glibc systems.
32
+ try {
33
+ const header = process.report?.getReport()?.header;
34
+ if (header && "glibcVersionRuntime" in header) return false;
35
+ } catch {
36
+ /* ignore */
37
+ }
38
+ // Default to glibc — the common case on CI Linux runners.
39
+ return false;
40
+ }
41
+ }
42
+
43
+ function candidateTriples() {
44
+ if (platform === "linux") {
45
+ const libc = isMuslLibc() ? "musl" : "gnu";
46
+ return [`${platform}-${arch}-${libc}`, `${platform}-${arch}`];
47
+ }
48
+ if (platform === "win32") {
49
+ return [`${platform}-${arch}-msvc`, `${platform}-${arch}`];
50
+ }
51
+ // darwin, freebsd, etc — napi doesn't add an ABI suffix.
52
+ return [`${platform}-${arch}`];
53
+ }
54
+
55
+ function loadNative() {
56
+ const triples = candidateTriples();
57
+
58
+ // 1. Local dev build at the crate root (produced by `napi build`).
59
+ const localCandidates = [
60
+ ...triples.map((t) => `lora-node.${t}.node`),
61
+ "lora.node",
62
+ "lora-node.node",
63
+ ];
64
+ for (const name of localCandidates) {
65
+ const candidate = join(__dirname, "..", name);
66
+ if (existsSync(candidate)) {
67
+ return require(candidate);
68
+ }
69
+ }
70
+
71
+ // 2. Platform-specific npm subpackage (@loradb/lora-node-<triple>).
72
+ const subpackageNames = triples.map((t) => `@loradb/lora-node-${t}`);
73
+ for (const name of subpackageNames) {
74
+ try {
75
+ return require(name);
76
+ } catch (err) {
77
+ if (err && err.code !== "MODULE_NOT_FOUND") throw err;
78
+ // fall through to the next triple / final error.
79
+ }
80
+ }
81
+
82
+ throw new Error(
83
+ `lora-node: no native binary found for ${platform}-${arch}. ` +
84
+ `Tried local: ${localCandidates.join(", ")}. ` +
85
+ `Tried npm: ${subpackageNames.join(", ")}. ` +
86
+ "For local development, run `npm run build` in the crate directory.",
87
+ );
88
+ }
89
+
90
+ module.exports = loadNative();