@surrealdb/node 1.0.0-beta.3 → 2.3.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/dist/surrealdb-node.d.ts +50 -0
- package/dist/surrealdb-node.darwin-arm64.node +0 -0
- package/dist/surrealdb-node.darwin-x64.node +0 -0
- package/dist/surrealdb-node.linux-arm64-gnu.node +0 -0
- package/{npm/darwin-arm64/surrealdb.node.darwin-arm64.node → dist/surrealdb-node.linux-arm64-musl.node} +0 -0
- package/{npm/linux-arm64-gnu/surrealdb.node.linux-arm64-gnu.node → dist/surrealdb-node.linux-x64-gnu.node} +0 -0
- package/{npm/android-arm64/surrealdb.node.android-arm64.node → dist/surrealdb-node.linux-x64-musl.node} +0 -0
- package/dist/surrealdb-node.mjs +495 -0
- package/dist/surrealdb-node.win32-arm64-msvc.node +0 -0
- package/{npm/darwin-x64/surrealdb.node.darwin-x64.node → dist/surrealdb-node.win32-x64-msvc.node} +0 -0
- package/package.json +43 -88
- package/LICENSE +0 -201
- package/README.md +0 -56
- package/index.d.ts +0 -13
- package/index.js +0 -315
- package/lib/embedded.d.ts +0 -16
- package/lib/embedded.js +0 -103
- package/lib/embedded.js.map +0 -1
- package/npm/android-arm-eabi/README.md +0 -3
- package/npm/android-arm-eabi/package.json +0 -27
- package/npm/android-arm64/README.md +0 -3
- package/npm/android-arm64/package.json +0 -27
- package/npm/darwin-arm64/README.md +0 -3
- package/npm/darwin-arm64/package.json +0 -27
- package/npm/darwin-universal/README.md +0 -3
- package/npm/darwin-universal/package.json +0 -24
- package/npm/darwin-universal/surrealdb.node.darwin-universal.node +0 -0
- package/npm/darwin-x64/README.md +0 -3
- package/npm/darwin-x64/package.json +0 -27
- package/npm/freebsd-x64/README.md +0 -3
- package/npm/freebsd-x64/package.json +0 -27
- package/npm/linux-arm-gnueabihf/README.md +0 -3
- package/npm/linux-arm-gnueabihf/package.json +0 -27
- package/npm/linux-arm64-gnu/README.md +0 -3
- package/npm/linux-arm64-gnu/package.json +0 -30
- package/npm/linux-arm64-musl/README.md +0 -3
- package/npm/linux-arm64-musl/package.json +0 -30
- package/npm/linux-x64-gnu/README.md +0 -3
- package/npm/linux-x64-gnu/package.json +0 -30
- package/npm/linux-x64-gnu/surrealdb.node.linux-x64-gnu.node +0 -0
- package/npm/linux-x64-musl/README.md +0 -3
- package/npm/linux-x64-musl/package.json +0 -30
- package/npm/linux-x64-musl/surrealdb.node.linux-x64-musl.node +0 -0
- package/npm/win32-arm64-msvc/README.md +0 -3
- package/npm/win32-arm64-msvc/package.json +0 -27
- package/npm/win32-ia32-msvc/README.md +0 -3
- package/npm/win32-ia32-msvc/package.json +0 -27
- package/npm/win32-x64-msvc/README.md +0 -3
- package/npm/win32-x64-msvc/package.json +0 -27
- package/npm/win32-x64-msvc/surrealdb.node.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { ConnectionState, DriverContext, EngineEvents, Engines, JsonEngine, LiveMessage, RpcRequest, SurrealEngine, Uuid } from 'surrealdb';
|
|
4
|
+
|
|
5
|
+
type CapabilitiesAllowDenyList = {
|
|
6
|
+
allow?: boolean | string[];
|
|
7
|
+
deny?: boolean | string[];
|
|
8
|
+
};
|
|
9
|
+
type ConnectionOptions = {
|
|
10
|
+
strict?: boolean;
|
|
11
|
+
query_timeout?: number;
|
|
12
|
+
transaction_timeout?: number;
|
|
13
|
+
capabilities?: boolean | {
|
|
14
|
+
scripting?: boolean;
|
|
15
|
+
guest_access?: boolean;
|
|
16
|
+
live_query_notifications?: boolean;
|
|
17
|
+
functions?: boolean | string[] | CapabilitiesAllowDenyList;
|
|
18
|
+
network_targets?: boolean | string[] | CapabilitiesAllowDenyList;
|
|
19
|
+
experimental?: boolean | string[] | CapabilitiesAllowDenyList;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The engine implementation responsible for communicating with an embedded
|
|
24
|
+
* WebAssembly build of SurrealDB.
|
|
25
|
+
*/
|
|
26
|
+
export declare class NodeEngine extends JsonEngine implements SurrealEngine {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(context: DriverContext, options?: ConnectionOptions);
|
|
29
|
+
open(state: ConnectionState): void;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
subscribe<K extends keyof EngineEvents>(event: K, listener: (...payload: EngineEvents[K]) => void): () => void;
|
|
32
|
+
liveQuery(id: Uuid): AsyncIterable<LiveMessage>;
|
|
33
|
+
send<Method extends string, Params extends unknown[] | undefined, Result>(request: RpcRequest<Method, Params>): Promise<Result>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Configure the `mem`, `rocksdb`, `surrealkv`, and `surrealkv+versioned` Nodejs engines for the JavaScript SDK.
|
|
37
|
+
*
|
|
38
|
+
* While this package is called `@surrealdb/node`, it is also compatible with Bun and Deno.
|
|
39
|
+
*
|
|
40
|
+
* @param options Optional connection options to configure the Nodejs engines.
|
|
41
|
+
* @example ```ts
|
|
42
|
+
* import { createNodeEngines } from "@surrealdb/node";
|
|
43
|
+
* import { Surreal } from "surrealdb";
|
|
44
|
+
*
|
|
45
|
+
* const db = new Surreal(createNodeEngines());
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const createNodeEngines: (options?: ConnectionOptions) => Engines;
|
|
49
|
+
|
|
50
|
+
export {};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { ChannelIterator, ConnectionUnavailable, JsonEngine, Publisher, UnexpectedConnectionError } from "surrealdb";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
|
|
4
|
+
//#region napi/index.js
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
new URL(".", import.meta.url).pathname;
|
|
7
|
+
const { readFileSync } = require("node:fs");
|
|
8
|
+
let nativeBinding = null;
|
|
9
|
+
const loadErrors = [];
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
let musl = false;
|
|
12
|
+
if (process.platform === "linux") {
|
|
13
|
+
musl = isMuslFromFilesystem();
|
|
14
|
+
if (musl === null) musl = isMuslFromReport();
|
|
15
|
+
if (musl === null) musl = isMuslFromChildProcess();
|
|
16
|
+
}
|
|
17
|
+
return musl;
|
|
18
|
+
};
|
|
19
|
+
const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
|
20
|
+
const isMuslFromFilesystem = () => {
|
|
21
|
+
try {
|
|
22
|
+
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const isMuslFromReport = () => {
|
|
28
|
+
let report = null;
|
|
29
|
+
if (typeof process.report?.getReport === "function") {
|
|
30
|
+
process.report.excludeNetwork = true;
|
|
31
|
+
report = process.report.getReport();
|
|
32
|
+
}
|
|
33
|
+
if (!report) return null;
|
|
34
|
+
if (report.header && report.header.glibcVersionRuntime) return false;
|
|
35
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
36
|
+
if (report.sharedObjects.some(isFileMusl)) return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
const isMuslFromChildProcess = () => {
|
|
41
|
+
try {
|
|
42
|
+
return require("child_process").execSync("ldd --version", { encoding: "utf8" }).includes("musl");
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function requireNative() {
|
|
48
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) try {
|
|
49
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
loadErrors.push(err);
|
|
52
|
+
}
|
|
53
|
+
else if (process.platform === "android") if (process.arch === "arm64") {
|
|
54
|
+
try {
|
|
55
|
+
return require("./surrealdb-node.android-arm64.node");
|
|
56
|
+
} catch (e) {
|
|
57
|
+
loadErrors.push(e);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const binding = require("@surrealdb/node-android-arm64");
|
|
61
|
+
const bindingPackageVersion = require("@surrealdb/node-android-arm64/package.json").version;
|
|
62
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
63
|
+
return binding;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
loadErrors.push(e);
|
|
66
|
+
}
|
|
67
|
+
} else if (process.arch === "arm") {
|
|
68
|
+
try {
|
|
69
|
+
return require("./surrealdb-node.android-arm-eabi.node");
|
|
70
|
+
} catch (e) {
|
|
71
|
+
loadErrors.push(e);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const binding = require("@surrealdb/node-android-arm-eabi");
|
|
75
|
+
const bindingPackageVersion = require("@surrealdb/node-android-arm-eabi/package.json").version;
|
|
76
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
77
|
+
return binding;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
loadErrors.push(e);
|
|
80
|
+
}
|
|
81
|
+
} else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported architecture on Android ${process.arch}`));
|
|
82
|
+
else if (process.platform === "win32") if (process.arch === "x64") {
|
|
83
|
+
try {
|
|
84
|
+
return require("./surrealdb-node.win32-x64-msvc.node");
|
|
85
|
+
} catch (e) {
|
|
86
|
+
loadErrors.push(e);
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const binding = require("@surrealdb/node-win32-x64-msvc");
|
|
90
|
+
const bindingPackageVersion = require("@surrealdb/node-win32-x64-msvc/package.json").version;
|
|
91
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
92
|
+
return binding;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
loadErrors.push(e);
|
|
95
|
+
}
|
|
96
|
+
} else if (process.arch === "ia32") {
|
|
97
|
+
try {
|
|
98
|
+
return require("./surrealdb-node.win32-ia32-msvc.node");
|
|
99
|
+
} catch (e) {
|
|
100
|
+
loadErrors.push(e);
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const binding = require("@surrealdb/node-win32-ia32-msvc");
|
|
104
|
+
const bindingPackageVersion = require("@surrealdb/node-win32-ia32-msvc/package.json").version;
|
|
105
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
106
|
+
return binding;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
loadErrors.push(e);
|
|
109
|
+
}
|
|
110
|
+
} else if (process.arch === "arm64") {
|
|
111
|
+
try {
|
|
112
|
+
return require("./surrealdb-node.win32-arm64-msvc.node");
|
|
113
|
+
} catch (e) {
|
|
114
|
+
loadErrors.push(e);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const binding = require("@surrealdb/node-win32-arm64-msvc");
|
|
118
|
+
const bindingPackageVersion = require("@surrealdb/node-win32-arm64-msvc/package.json").version;
|
|
119
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
120
|
+
return binding;
|
|
121
|
+
} catch (e) {
|
|
122
|
+
loadErrors.push(e);
|
|
123
|
+
}
|
|
124
|
+
} else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported architecture on Windows: ${process.arch}`));
|
|
125
|
+
else if (process.platform === "darwin") {
|
|
126
|
+
try {
|
|
127
|
+
return require("./surrealdb-node.darwin-universal.node");
|
|
128
|
+
} catch (e) {
|
|
129
|
+
loadErrors.push(e);
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const binding = require("@surrealdb/node-darwin-universal");
|
|
133
|
+
const bindingPackageVersion = require("@surrealdb/node-darwin-universal/package.json").version;
|
|
134
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
135
|
+
return binding;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
loadErrors.push(e);
|
|
138
|
+
}
|
|
139
|
+
if (process.arch === "x64") {
|
|
140
|
+
try {
|
|
141
|
+
return require("./surrealdb-node.darwin-x64.node");
|
|
142
|
+
} catch (e) {
|
|
143
|
+
loadErrors.push(e);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const binding = require("@surrealdb/node-darwin-x64");
|
|
147
|
+
const bindingPackageVersion = require("@surrealdb/node-darwin-x64/package.json").version;
|
|
148
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
149
|
+
return binding;
|
|
150
|
+
} catch (e) {
|
|
151
|
+
loadErrors.push(e);
|
|
152
|
+
}
|
|
153
|
+
} else if (process.arch === "arm64") {
|
|
154
|
+
try {
|
|
155
|
+
return require("./surrealdb-node.darwin-arm64.node");
|
|
156
|
+
} catch (e) {
|
|
157
|
+
loadErrors.push(e);
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const binding = require("@surrealdb/node-darwin-arm64");
|
|
161
|
+
const bindingPackageVersion = require("@surrealdb/node-darwin-arm64/package.json").version;
|
|
162
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
163
|
+
return binding;
|
|
164
|
+
} catch (e) {
|
|
165
|
+
loadErrors.push(e);
|
|
166
|
+
}
|
|
167
|
+
} else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported architecture on macOS: ${process.arch}`));
|
|
168
|
+
} else if (process.platform === "freebsd") if (process.arch === "x64") {
|
|
169
|
+
try {
|
|
170
|
+
return require("./surrealdb-node.freebsd-x64.node");
|
|
171
|
+
} catch (e) {
|
|
172
|
+
loadErrors.push(e);
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const binding = require("@surrealdb/node-freebsd-x64");
|
|
176
|
+
const bindingPackageVersion = require("@surrealdb/node-freebsd-x64/package.json").version;
|
|
177
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
178
|
+
return binding;
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadErrors.push(e);
|
|
181
|
+
}
|
|
182
|
+
} else if (process.arch === "arm64") {
|
|
183
|
+
try {
|
|
184
|
+
return require("./surrealdb-node.freebsd-arm64.node");
|
|
185
|
+
} catch (e) {
|
|
186
|
+
loadErrors.push(e);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const binding = require("@surrealdb/node-freebsd-arm64");
|
|
190
|
+
const bindingPackageVersion = require("@surrealdb/node-freebsd-arm64/package.json").version;
|
|
191
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
192
|
+
return binding;
|
|
193
|
+
} catch (e) {
|
|
194
|
+
loadErrors.push(e);
|
|
195
|
+
}
|
|
196
|
+
} else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
|
|
197
|
+
else if (process.platform === "linux") if (process.arch === "x64") if (isMusl()) {
|
|
198
|
+
try {
|
|
199
|
+
return require("./surrealdb-node.linux-x64-musl.node");
|
|
200
|
+
} catch (e) {
|
|
201
|
+
loadErrors.push(e);
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const binding = require("@surrealdb/node-linux-x64-musl");
|
|
205
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-x64-musl/package.json").version;
|
|
206
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
207
|
+
return binding;
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadErrors.push(e);
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
try {
|
|
213
|
+
return require("./surrealdb-node.linux-x64-gnu.node");
|
|
214
|
+
} catch (e) {
|
|
215
|
+
loadErrors.push(e);
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const binding = require("@surrealdb/node-linux-x64-gnu");
|
|
219
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-x64-gnu/package.json").version;
|
|
220
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
221
|
+
return binding;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
loadErrors.push(e);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (process.arch === "arm64") if (isMusl()) {
|
|
227
|
+
try {
|
|
228
|
+
return require("./surrealdb-node.linux-arm64-musl.node");
|
|
229
|
+
} catch (e) {
|
|
230
|
+
loadErrors.push(e);
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
const binding = require("@surrealdb/node-linux-arm64-musl");
|
|
234
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-arm64-musl/package.json").version;
|
|
235
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
236
|
+
return binding;
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadErrors.push(e);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
try {
|
|
242
|
+
return require("./surrealdb-node.linux-arm64-gnu.node");
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadErrors.push(e);
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const binding = require("@surrealdb/node-linux-arm64-gnu");
|
|
248
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-arm64-gnu/package.json").version;
|
|
249
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
250
|
+
return binding;
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadErrors.push(e);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (process.arch === "arm") if (isMusl()) {
|
|
256
|
+
try {
|
|
257
|
+
return require("./surrealdb-node.linux-arm-musleabihf.node");
|
|
258
|
+
} catch (e) {
|
|
259
|
+
loadErrors.push(e);
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
const binding = require("@surrealdb/node-linux-arm-musleabihf");
|
|
263
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-arm-musleabihf/package.json").version;
|
|
264
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
265
|
+
return binding;
|
|
266
|
+
} catch (e) {
|
|
267
|
+
loadErrors.push(e);
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
try {
|
|
271
|
+
return require("./surrealdb-node.linux-arm-gnueabihf.node");
|
|
272
|
+
} catch (e) {
|
|
273
|
+
loadErrors.push(e);
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
const binding = require("@surrealdb/node-linux-arm-gnueabihf");
|
|
277
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-arm-gnueabihf/package.json").version;
|
|
278
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
279
|
+
return binding;
|
|
280
|
+
} catch (e) {
|
|
281
|
+
loadErrors.push(e);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (process.arch === "riscv64") if (isMusl()) {
|
|
285
|
+
try {
|
|
286
|
+
return require("./surrealdb-node.linux-riscv64-musl.node");
|
|
287
|
+
} catch (e) {
|
|
288
|
+
loadErrors.push(e);
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const binding = require("@surrealdb/node-linux-riscv64-musl");
|
|
292
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-riscv64-musl/package.json").version;
|
|
293
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
294
|
+
return binding;
|
|
295
|
+
} catch (e) {
|
|
296
|
+
loadErrors.push(e);
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
try {
|
|
300
|
+
return require("./surrealdb-node.linux-riscv64-gnu.node");
|
|
301
|
+
} catch (e) {
|
|
302
|
+
loadErrors.push(e);
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
const binding = require("@surrealdb/node-linux-riscv64-gnu");
|
|
306
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-riscv64-gnu/package.json").version;
|
|
307
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
308
|
+
return binding;
|
|
309
|
+
} catch (e) {
|
|
310
|
+
loadErrors.push(e);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (process.arch === "ppc64") {
|
|
314
|
+
try {
|
|
315
|
+
return require("./surrealdb-node.linux-ppc64-gnu.node");
|
|
316
|
+
} catch (e) {
|
|
317
|
+
loadErrors.push(e);
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const binding = require("@surrealdb/node-linux-ppc64-gnu");
|
|
321
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-ppc64-gnu/package.json").version;
|
|
322
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
323
|
+
return binding;
|
|
324
|
+
} catch (e) {
|
|
325
|
+
loadErrors.push(e);
|
|
326
|
+
}
|
|
327
|
+
} else if (process.arch === "s390x") {
|
|
328
|
+
try {
|
|
329
|
+
return require("./surrealdb-node.linux-s390x-gnu.node");
|
|
330
|
+
} catch (e) {
|
|
331
|
+
loadErrors.push(e);
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
const binding = require("@surrealdb/node-linux-s390x-gnu");
|
|
335
|
+
const bindingPackageVersion = require("@surrealdb/node-linux-s390x-gnu/package.json").version;
|
|
336
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
337
|
+
return binding;
|
|
338
|
+
} catch (e) {
|
|
339
|
+
loadErrors.push(e);
|
|
340
|
+
}
|
|
341
|
+
} else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported architecture on Linux: ${process.arch}`));
|
|
342
|
+
else if (process.platform === "openharmony") if (process.arch === "arm64") {
|
|
343
|
+
try {
|
|
344
|
+
return require("./surrealdb-node.openharmony-arm64.node");
|
|
345
|
+
} catch (e) {
|
|
346
|
+
loadErrors.push(e);
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const binding = require("@surrealdb/node-openharmony-arm64");
|
|
350
|
+
const bindingPackageVersion = require("@surrealdb/node-openharmony-arm64/package.json").version;
|
|
351
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
352
|
+
return binding;
|
|
353
|
+
} catch (e) {
|
|
354
|
+
loadErrors.push(e);
|
|
355
|
+
}
|
|
356
|
+
} else if (process.arch === "x64") {
|
|
357
|
+
try {
|
|
358
|
+
return require("./surrealdb-node.openharmony-x64.node");
|
|
359
|
+
} catch (e) {
|
|
360
|
+
loadErrors.push(e);
|
|
361
|
+
}
|
|
362
|
+
try {
|
|
363
|
+
const binding = require("@surrealdb/node-openharmony-x64");
|
|
364
|
+
const bindingPackageVersion = require("@surrealdb/node-openharmony-x64/package.json").version;
|
|
365
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
366
|
+
return binding;
|
|
367
|
+
} catch (e) {
|
|
368
|
+
loadErrors.push(e);
|
|
369
|
+
}
|
|
370
|
+
} else if (process.arch === "arm") {
|
|
371
|
+
try {
|
|
372
|
+
return require("./surrealdb-node.openharmony-arm.node");
|
|
373
|
+
} catch (e) {
|
|
374
|
+
loadErrors.push(e);
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
const binding = require("@surrealdb/node-openharmony-arm");
|
|
378
|
+
const bindingPackageVersion = require("@surrealdb/node-openharmony-arm/package.json").version;
|
|
379
|
+
if (bindingPackageVersion !== "2.3.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 2.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
380
|
+
return binding;
|
|
381
|
+
} catch (e) {
|
|
382
|
+
loadErrors.push(e);
|
|
383
|
+
}
|
|
384
|
+
} else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));
|
|
385
|
+
else loadErrors.push(/* @__PURE__ */ new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
|
|
386
|
+
}
|
|
387
|
+
nativeBinding = requireNative();
|
|
388
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
389
|
+
try {
|
|
390
|
+
nativeBinding = require("./surrealdb-node.wasi.cjs");
|
|
391
|
+
} catch (err) {
|
|
392
|
+
if (process.env.NAPI_RS_FORCE_WASI) loadErrors.push(err);
|
|
393
|
+
}
|
|
394
|
+
if (!nativeBinding) try {
|
|
395
|
+
nativeBinding = require("@surrealdb/node-wasm32-wasi");
|
|
396
|
+
} catch (err) {
|
|
397
|
+
if (process.env.NAPI_RS_FORCE_WASI) loadErrors.push(err);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (!nativeBinding) {
|
|
401
|
+
if (loadErrors.length > 0) throw new Error("Cannot find native binding. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.", { cause: loadErrors });
|
|
402
|
+
throw new Error(`Failed to load native binding`);
|
|
403
|
+
}
|
|
404
|
+
const { SurrealNodeEngine } = nativeBinding;
|
|
405
|
+
|
|
406
|
+
//#endregion
|
|
407
|
+
//#region src-ts/engine.ts
|
|
408
|
+
/**
|
|
409
|
+
* The engine implementation responsible for communicating with an embedded
|
|
410
|
+
* WebAssembly build of SurrealDB.
|
|
411
|
+
*/
|
|
412
|
+
var NodeEngine = class extends JsonEngine {
|
|
413
|
+
#engine;
|
|
414
|
+
#publisher = new Publisher();
|
|
415
|
+
#subscriptions = new Publisher();
|
|
416
|
+
#active = false;
|
|
417
|
+
#options;
|
|
418
|
+
constructor(context, options) {
|
|
419
|
+
super(context);
|
|
420
|
+
this.#options = options;
|
|
421
|
+
}
|
|
422
|
+
open(state) {
|
|
423
|
+
this.#publisher.publish("connecting");
|
|
424
|
+
this.#active = true;
|
|
425
|
+
this._state = state;
|
|
426
|
+
this.#initialize(state);
|
|
427
|
+
}
|
|
428
|
+
async close() {
|
|
429
|
+
this._state = void 0;
|
|
430
|
+
this.#active = false;
|
|
431
|
+
this.#engine?.free();
|
|
432
|
+
this.#engine = void 0;
|
|
433
|
+
this.#publisher.publish("disconnected");
|
|
434
|
+
}
|
|
435
|
+
subscribe(event, listener) {
|
|
436
|
+
return this.#publisher.subscribe(event, listener);
|
|
437
|
+
}
|
|
438
|
+
liveQuery(id) {
|
|
439
|
+
const channel = new ChannelIterator(() => {
|
|
440
|
+
unsub1();
|
|
441
|
+
unsub2();
|
|
442
|
+
});
|
|
443
|
+
const unsub1 = this.#subscriptions.subscribe(id.toString(), (msg) => {
|
|
444
|
+
channel.submit(msg);
|
|
445
|
+
});
|
|
446
|
+
const unsub2 = this.#publisher.subscribe("disconnected", () => {
|
|
447
|
+
channel.cancel();
|
|
448
|
+
});
|
|
449
|
+
return channel;
|
|
450
|
+
}
|
|
451
|
+
async send(request) {
|
|
452
|
+
if (!this.#active || !this.#engine) throw new ConnectionUnavailable();
|
|
453
|
+
const id = this._context.uniqueId();
|
|
454
|
+
const payload = this._context.cborEncode({
|
|
455
|
+
id,
|
|
456
|
+
...request
|
|
457
|
+
});
|
|
458
|
+
const response = await this.#engine.execute(payload);
|
|
459
|
+
const result = this._context.cborDecode(response);
|
|
460
|
+
return result;
|
|
461
|
+
}
|
|
462
|
+
async #initialize(state) {
|
|
463
|
+
try {
|
|
464
|
+
this.#engine = await SurrealNodeEngine.connect(state.url.toString(), this.#options);
|
|
465
|
+
this.#publisher.publish("connected");
|
|
466
|
+
} catch (err) {
|
|
467
|
+
this.#publisher.publish("error", new UnexpectedConnectionError(err));
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src-ts/index.ts
|
|
474
|
+
/**
|
|
475
|
+
* Configure the `mem`, `rocksdb`, `surrealkv`, and `surrealkv+versioned` Nodejs engines for the JavaScript SDK.
|
|
476
|
+
*
|
|
477
|
+
* While this package is called `@surrealdb/node`, it is also compatible with Bun and Deno.
|
|
478
|
+
*
|
|
479
|
+
* @param options Optional connection options to configure the Nodejs engines.
|
|
480
|
+
* @example ```ts
|
|
481
|
+
* import { createNodeEngines } from "@surrealdb/node";
|
|
482
|
+
* import { Surreal } from "surrealdb";
|
|
483
|
+
*
|
|
484
|
+
* const db = new Surreal(createNodeEngines());
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
const createNodeEngines = (options) => ({
|
|
488
|
+
mem: (ctx) => new NodeEngine(ctx, options),
|
|
489
|
+
rocksdb: (ctx) => new NodeEngine(ctx, options),
|
|
490
|
+
surrealkv: (ctx) => new NodeEngine(ctx, options),
|
|
491
|
+
"surrealkv+versioned": (ctx) => new NodeEngine(ctx, options)
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
//#endregion
|
|
495
|
+
export { NodeEngine, createNodeEngines };
|
|
Binary file
|