jazz-napi 2.0.0-alpha.2
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/index.d.ts +51 -0
- package/index.js +292 -0
- package/package.json +39 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
export declare function generateId(): string;
|
|
7
|
+
export declare function currentTimestamp(): number;
|
|
8
|
+
export declare function parseSchema(json: string): any;
|
|
9
|
+
export declare class NapiRuntime {
|
|
10
|
+
/** Create a new NapiRuntime with SurrealKV-backed persistent storage. */
|
|
11
|
+
constructor(
|
|
12
|
+
schemaJson: string,
|
|
13
|
+
appId: string,
|
|
14
|
+
jazzEnv: string,
|
|
15
|
+
userBranch: string,
|
|
16
|
+
dataPath: string,
|
|
17
|
+
tier?: string | undefined | null,
|
|
18
|
+
);
|
|
19
|
+
insert(table: string, values: any): string;
|
|
20
|
+
update(objectId: string, values: any): void;
|
|
21
|
+
delete(objectId: string): void;
|
|
22
|
+
query(
|
|
23
|
+
queryJson: string,
|
|
24
|
+
sessionJson?: string | undefined | null,
|
|
25
|
+
settledTier?: string | undefined | null,
|
|
26
|
+
): Promise<any>;
|
|
27
|
+
subscribe(
|
|
28
|
+
queryJson: string,
|
|
29
|
+
onUpdate: (...args: any[]) => any,
|
|
30
|
+
sessionJson?: string | undefined | null,
|
|
31
|
+
settledTier?: string | undefined | null,
|
|
32
|
+
): number;
|
|
33
|
+
unsubscribe(handle: number): void;
|
|
34
|
+
insertWithAck(table: string, values: any, tier: string): Promise<string>;
|
|
35
|
+
updateWithAck(objectId: string, values: any, tier: string): Promise<void>;
|
|
36
|
+
deleteWithAck(objectId: string, tier: string): Promise<void>;
|
|
37
|
+
onSyncMessageReceived(messageJson: string): void;
|
|
38
|
+
/** Called by JS when a sync message arrives from a client (not a server). */
|
|
39
|
+
onSyncMessageReceivedFromClient(clientId: string, messageJson: string): void;
|
|
40
|
+
onSyncMessageToSend(callback: (...args: any[]) => any): void;
|
|
41
|
+
addServer(): void;
|
|
42
|
+
removeServer(): void;
|
|
43
|
+
addClient(): string;
|
|
44
|
+
/** Set a client's role ("user", "admin", or "peer"). */
|
|
45
|
+
setClientRole(clientId: string, role: string): void;
|
|
46
|
+
getSchema(): any;
|
|
47
|
+
getSchemaHash(): string;
|
|
48
|
+
flush(): void;
|
|
49
|
+
/** Flush and close the underlying storage, releasing filesystem locks. */
|
|
50
|
+
close(): void;
|
|
51
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* prettier-ignore */
|
|
4
|
+
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
|
|
7
|
+
const { existsSync, readFileSync } = require('fs')
|
|
8
|
+
const { join } = require("path");
|
|
9
|
+
|
|
10
|
+
const { platform, arch } = process;
|
|
11
|
+
|
|
12
|
+
let nativeBinding = null;
|
|
13
|
+
let localFileExisted = false;
|
|
14
|
+
let loadError = null;
|
|
15
|
+
|
|
16
|
+
function isMusl() {
|
|
17
|
+
// For Node 10
|
|
18
|
+
if (!process.report || typeof process.report.getReport !== "function") {
|
|
19
|
+
try {
|
|
20
|
+
const lddPath = require("child_process").execSync("which ldd").toString().trim();
|
|
21
|
+
return readFileSync(lddPath, "utf8").includes("musl");
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
27
|
+
return !glibcVersionRuntime;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case "android":
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case "arm64":
|
|
35
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.android-arm64.node"));
|
|
36
|
+
try {
|
|
37
|
+
if (localFileExisted) {
|
|
38
|
+
nativeBinding = require("./jazz-napi.android-arm64.node");
|
|
39
|
+
} else {
|
|
40
|
+
nativeBinding = require("jazz-napi-android-arm64");
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
loadError = e;
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case "arm":
|
|
47
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.android-arm-eabi.node"));
|
|
48
|
+
try {
|
|
49
|
+
if (localFileExisted) {
|
|
50
|
+
nativeBinding = require("./jazz-napi.android-arm-eabi.node");
|
|
51
|
+
} else {
|
|
52
|
+
nativeBinding = require("jazz-napi-android-arm-eabi");
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
loadError = e;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported architecture on Android ${arch}`);
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case "win32":
|
|
63
|
+
switch (arch) {
|
|
64
|
+
case "x64":
|
|
65
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.win32-x64-msvc.node"));
|
|
66
|
+
try {
|
|
67
|
+
if (localFileExisted) {
|
|
68
|
+
nativeBinding = require("./jazz-napi.win32-x64-msvc.node");
|
|
69
|
+
} else {
|
|
70
|
+
nativeBinding = require("jazz-napi-win32-x64-msvc");
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
loadError = e;
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case "ia32":
|
|
77
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.win32-ia32-msvc.node"));
|
|
78
|
+
try {
|
|
79
|
+
if (localFileExisted) {
|
|
80
|
+
nativeBinding = require("./jazz-napi.win32-ia32-msvc.node");
|
|
81
|
+
} else {
|
|
82
|
+
nativeBinding = require("jazz-napi-win32-ia32-msvc");
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
loadError = e;
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "arm64":
|
|
89
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.win32-arm64-msvc.node"));
|
|
90
|
+
try {
|
|
91
|
+
if (localFileExisted) {
|
|
92
|
+
nativeBinding = require("./jazz-napi.win32-arm64-msvc.node");
|
|
93
|
+
} else {
|
|
94
|
+
nativeBinding = require("jazz-napi-win32-arm64-msvc");
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
loadError = e;
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "darwin":
|
|
105
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.darwin-universal.node"));
|
|
106
|
+
try {
|
|
107
|
+
if (localFileExisted) {
|
|
108
|
+
nativeBinding = require("./jazz-napi.darwin-universal.node");
|
|
109
|
+
} else {
|
|
110
|
+
nativeBinding = require("jazz-napi-darwin-universal");
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
} catch {}
|
|
114
|
+
switch (arch) {
|
|
115
|
+
case "x64":
|
|
116
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.darwin-x64.node"));
|
|
117
|
+
try {
|
|
118
|
+
if (localFileExisted) {
|
|
119
|
+
nativeBinding = require("./jazz-napi.darwin-x64.node");
|
|
120
|
+
} else {
|
|
121
|
+
nativeBinding = require("jazz-napi-darwin-x64");
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
loadError = e;
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
case "arm64":
|
|
128
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.darwin-arm64.node"));
|
|
129
|
+
try {
|
|
130
|
+
if (localFileExisted) {
|
|
131
|
+
nativeBinding = require("./jazz-napi.darwin-arm64.node");
|
|
132
|
+
} else {
|
|
133
|
+
nativeBinding = require("jazz-napi-darwin-arm64");
|
|
134
|
+
}
|
|
135
|
+
} catch (e) {
|
|
136
|
+
loadError = e;
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
case "freebsd":
|
|
144
|
+
if (arch !== "x64") {
|
|
145
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
|
|
146
|
+
}
|
|
147
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.freebsd-x64.node"));
|
|
148
|
+
try {
|
|
149
|
+
if (localFileExisted) {
|
|
150
|
+
nativeBinding = require("./jazz-napi.freebsd-x64.node");
|
|
151
|
+
} else {
|
|
152
|
+
nativeBinding = require("jazz-napi-freebsd-x64");
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
loadError = e;
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case "linux":
|
|
159
|
+
switch (arch) {
|
|
160
|
+
case "x64":
|
|
161
|
+
if (isMusl()) {
|
|
162
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-x64-musl.node"));
|
|
163
|
+
try {
|
|
164
|
+
if (localFileExisted) {
|
|
165
|
+
nativeBinding = require("./jazz-napi.linux-x64-musl.node");
|
|
166
|
+
} else {
|
|
167
|
+
nativeBinding = require("jazz-napi-linux-x64-musl");
|
|
168
|
+
}
|
|
169
|
+
} catch (e) {
|
|
170
|
+
loadError = e;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-x64-gnu.node"));
|
|
174
|
+
try {
|
|
175
|
+
if (localFileExisted) {
|
|
176
|
+
nativeBinding = require("./jazz-napi.linux-x64-gnu.node");
|
|
177
|
+
} else {
|
|
178
|
+
nativeBinding = require("jazz-napi-linux-x64-gnu");
|
|
179
|
+
}
|
|
180
|
+
} catch (e) {
|
|
181
|
+
loadError = e;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
case "arm64":
|
|
186
|
+
if (isMusl()) {
|
|
187
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-arm64-musl.node"));
|
|
188
|
+
try {
|
|
189
|
+
if (localFileExisted) {
|
|
190
|
+
nativeBinding = require("./jazz-napi.linux-arm64-musl.node");
|
|
191
|
+
} else {
|
|
192
|
+
nativeBinding = require("jazz-napi-linux-arm64-musl");
|
|
193
|
+
}
|
|
194
|
+
} catch (e) {
|
|
195
|
+
loadError = e;
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-arm64-gnu.node"));
|
|
199
|
+
try {
|
|
200
|
+
if (localFileExisted) {
|
|
201
|
+
nativeBinding = require("./jazz-napi.linux-arm64-gnu.node");
|
|
202
|
+
} else {
|
|
203
|
+
nativeBinding = require("jazz-napi-linux-arm64-gnu");
|
|
204
|
+
}
|
|
205
|
+
} catch (e) {
|
|
206
|
+
loadError = e;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
case "arm":
|
|
211
|
+
if (isMusl()) {
|
|
212
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-arm-musleabihf.node"));
|
|
213
|
+
try {
|
|
214
|
+
if (localFileExisted) {
|
|
215
|
+
nativeBinding = require("./jazz-napi.linux-arm-musleabihf.node");
|
|
216
|
+
} else {
|
|
217
|
+
nativeBinding = require("jazz-napi-linux-arm-musleabihf");
|
|
218
|
+
}
|
|
219
|
+
} catch (e) {
|
|
220
|
+
loadError = e;
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-arm-gnueabihf.node"));
|
|
224
|
+
try {
|
|
225
|
+
if (localFileExisted) {
|
|
226
|
+
nativeBinding = require("./jazz-napi.linux-arm-gnueabihf.node");
|
|
227
|
+
} else {
|
|
228
|
+
nativeBinding = require("jazz-napi-linux-arm-gnueabihf");
|
|
229
|
+
}
|
|
230
|
+
} catch (e) {
|
|
231
|
+
loadError = e;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case "riscv64":
|
|
236
|
+
if (isMusl()) {
|
|
237
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-riscv64-musl.node"));
|
|
238
|
+
try {
|
|
239
|
+
if (localFileExisted) {
|
|
240
|
+
nativeBinding = require("./jazz-napi.linux-riscv64-musl.node");
|
|
241
|
+
} else {
|
|
242
|
+
nativeBinding = require("jazz-napi-linux-riscv64-musl");
|
|
243
|
+
}
|
|
244
|
+
} catch (e) {
|
|
245
|
+
loadError = e;
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-riscv64-gnu.node"));
|
|
249
|
+
try {
|
|
250
|
+
if (localFileExisted) {
|
|
251
|
+
nativeBinding = require("./jazz-napi.linux-riscv64-gnu.node");
|
|
252
|
+
} else {
|
|
253
|
+
nativeBinding = require("jazz-napi-linux-riscv64-gnu");
|
|
254
|
+
}
|
|
255
|
+
} catch (e) {
|
|
256
|
+
loadError = e;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
case "s390x":
|
|
261
|
+
localFileExisted = existsSync(join(__dirname, "jazz-napi.linux-s390x-gnu.node"));
|
|
262
|
+
try {
|
|
263
|
+
if (localFileExisted) {
|
|
264
|
+
nativeBinding = require("./jazz-napi.linux-s390x-gnu.node");
|
|
265
|
+
} else {
|
|
266
|
+
nativeBinding = require("jazz-napi-linux-s390x-gnu");
|
|
267
|
+
}
|
|
268
|
+
} catch (e) {
|
|
269
|
+
loadError = e;
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (!nativeBinding) {
|
|
281
|
+
if (loadError) {
|
|
282
|
+
throw loadError;
|
|
283
|
+
}
|
|
284
|
+
throw new Error(`Failed to load native binding`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const { NapiRuntime, generateId, currentTimestamp, parseSchema } = nativeBinding;
|
|
288
|
+
|
|
289
|
+
module.exports.NapiRuntime = NapiRuntime;
|
|
290
|
+
module.exports.generateId = generateId;
|
|
291
|
+
module.exports.currentTimestamp = currentTimestamp;
|
|
292
|
+
module.exports.parseSchema = parseSchema;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jazz-napi",
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
4
|
+
"description": "Native Node.js bindings for Jazz runtime",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/garden-co/jazz2"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"index.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"types": "index.d.ts",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"tag": "alpha"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "node scripts/build.js",
|
|
22
|
+
"build:debug": "napi build --platform"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@napi-rs/cli": "^2"
|
|
26
|
+
},
|
|
27
|
+
"napi": {
|
|
28
|
+
"name": "jazz-napi",
|
|
29
|
+
"triples": {
|
|
30
|
+
"defaults": false,
|
|
31
|
+
"additional": [
|
|
32
|
+
"x86_64-unknown-linux-gnu",
|
|
33
|
+
"x86_64-pc-windows-msvc",
|
|
34
|
+
"x86_64-apple-darwin",
|
|
35
|
+
"aarch64-apple-darwin"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|