@cascode/cascode-js 0.5.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/README.md +98 -0
- package/binding.gyp +26 -0
- package/lib/std/Bundles.cas +6 -0
- package/lib/std/InverterLike.cas +11 -0
- package/lib/std/amp/Common.cas +16 -0
- package/lib/std/amp/FullyDifferentialOpAmp.cas +61 -0
- package/lib/std/amp/SingleEndedAmp.cas +48 -0
- package/lib/std/amp/SingleEndedOpAmp.cas +48 -0
- package/lib/std/bench/DCBiasBenches.cas +41 -0
- package/lib/std/bench/NoiseBenches.cas +167 -0
- package/lib/std/bench/PowerBenches.cas +202 -0
- package/lib/std/bench/TranBenches.cas +164 -0
- package/lib/std/bench/TransferBenches.cas +329 -0
- package/lib/std/composites/PadDriver.cas +10 -0
- package/lib/std/prim/Devices.cas +20 -0
- package/lib/std/prim/Passives.cas +23 -0
- package/lib/std/refs/ConstantGm.cas +25 -0
- package/lib/std/refs/CurrentReference.cas +7 -0
- package/lib/std/refs/ReferenceCircuit.cas +6 -0
- package/lib/std/refs/VoltageReference.cas +7 -0
- package/native/cascode_native_addon.c +788 -0
- package/native/osx-arm64/Cascode.Native.dylib +0 -0
- package/native/osx-arm64/google-ortools-native.dylib +0 -0
- package/native/osx-arm64/libortools.9.dylib +0 -0
- package/package.json +48 -0
- package/platform-packages/cascode-js-darwin-arm64/README.md +4 -0
- package/platform-packages/cascode-js-darwin-arm64/index.js +10 -0
- package/platform-packages/cascode-js-darwin-arm64/package.json +28 -0
- package/platform-packages/cascode-js-darwin-x64/README.md +4 -0
- package/platform-packages/cascode-js-darwin-x64/index.js +10 -0
- package/platform-packages/cascode-js-darwin-x64/package.json +28 -0
- package/platform-packages/cascode-js-linux-x64/README.md +4 -0
- package/platform-packages/cascode-js-linux-x64/index.js +10 -0
- package/platform-packages/cascode-js-linux-x64/package.json +28 -0
- package/platform-packages/cascode-js-win32-x64/README.md +4 -0
- package/platform-packages/cascode-js-win32-x64/index.js +10 -0
- package/platform-packages/cascode-js-win32-x64/package.json +28 -0
- package/scripts/stage-platform-package.mjs +128 -0
- package/scripts/sync-stdlib.mjs +35 -0
- package/src/index.d.ts +38 -0
- package/src/index.js +453 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const PLATFORM_PACKAGES = {
|
|
7
|
+
"darwin-arm64": "@cascode/cascode-js-darwin-arm64",
|
|
8
|
+
"darwin-x64": "@cascode/cascode-js-darwin-x64",
|
|
9
|
+
"linux-x64": "@cascode/cascode-js-linux-x64",
|
|
10
|
+
"win32-x64": "@cascode/cascode-js-win32-x64",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a platform-architecture key for the current process.
|
|
15
|
+
* @returns {string} A string in the form `platform-arch` (for example, `linux-x64`, `win32-arm64`).
|
|
16
|
+
*/
|
|
17
|
+
function getPlatformKey() {
|
|
18
|
+
return `${process.platform}-${process.arch}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the runtime identifier (RID) for the current platform and architecture (e.g., "win-x64", "linux-arm64").
|
|
23
|
+
*
|
|
24
|
+
* @returns {string|null} The RID string for supported platform/architecture combinations, or `null` if unsupported.
|
|
25
|
+
*/
|
|
26
|
+
function getRuntimeRid() {
|
|
27
|
+
if (process.platform === "win32") {
|
|
28
|
+
return process.arch === "arm64" ? "win-arm64" : "win-x64";
|
|
29
|
+
}
|
|
30
|
+
if (process.platform === "darwin") {
|
|
31
|
+
return process.arch === "arm64" ? "darwin-arm64" : "darwin-x64";
|
|
32
|
+
}
|
|
33
|
+
if (process.platform === "linux") {
|
|
34
|
+
return process.arch === "arm64" ? "linux-arm64" : "linux-x64";
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Return the list of native library filenames that may be present for the current platform.
|
|
41
|
+
*
|
|
42
|
+
* @returns {string[]} An array of candidate native library filenames for the current process platform; returns an empty array if the platform is not recognized.
|
|
43
|
+
*/
|
|
44
|
+
function getNativeLibraryFileNames() {
|
|
45
|
+
if (process.platform === "win32") {
|
|
46
|
+
return ["Cascode.Native.dll", "libcascode.dll"];
|
|
47
|
+
}
|
|
48
|
+
if (process.platform === "darwin") {
|
|
49
|
+
return ["libCascode.Native.dylib", "libcascode.dylib", "Cascode.Native.dylib"];
|
|
50
|
+
}
|
|
51
|
+
if (process.platform === "linux") {
|
|
52
|
+
return ["libCascode.Native.so", "libcascode.so", "Cascode.Native.so"];
|
|
53
|
+
}
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Prepend a directory to the native library search path for the current platform.
|
|
59
|
+
*
|
|
60
|
+
* On Windows this prepends to PATH, on macOS to DYLD_LIBRARY_PATH, and on other platforms to LD_LIBRARY_PATH.
|
|
61
|
+
* If the provided `directory` is falsy, the function is a no-op. Existing environment values are preserved.
|
|
62
|
+
* @param {string} directory - Directory to add to the front of the platform-specific library search path.
|
|
63
|
+
*/
|
|
64
|
+
function prependLibrarySearchPath(directory) {
|
|
65
|
+
if (!directory) return;
|
|
66
|
+
if (process.platform === "win32") {
|
|
67
|
+
const existingPath = process.env.PATH ?? "";
|
|
68
|
+
process.env.PATH = `${directory}${path.delimiter}${existingPath}`;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const key = process.platform === "darwin" ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH";
|
|
73
|
+
const existingPath = process.env[key] ?? "";
|
|
74
|
+
process.env[key] = `${directory}${path.delimiter}${existingPath}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Load a Node native addon module from a filesystem path if the file exists.
|
|
79
|
+
* @param {string} addonPath - Filesystem path to the addon (.node) or module file.
|
|
80
|
+
* @returns {any|null} The required addon module when the path exists, `null` otherwise.
|
|
81
|
+
*/
|
|
82
|
+
function tryLoadAddonFromPath(addonPath) {
|
|
83
|
+
if (!addonPath || !fs.existsSync(addonPath)) return null;
|
|
84
|
+
return require(addonPath);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Attempts to load a platform-specific prebuilt native addon package and prepare its native library search path.
|
|
89
|
+
*
|
|
90
|
+
* If a mapped prebuilt package is found, this function requires the package, validates that it exports
|
|
91
|
+
* `addonPath`, `libraryPath`, and `libraryDir`, sets `process.env.CASCODE_NATIVE_LIB` (if not already set),
|
|
92
|
+
* and prepends `libraryDir` to the platform's library search path before loading the addon.
|
|
93
|
+
*
|
|
94
|
+
* @param {string[]} errors - Array to append human-readable error messages describing why loading failed.
|
|
95
|
+
* @returns {object|null} The loaded native addon module on success, or `null` if no suitable package exists or loading failed.
|
|
96
|
+
*/
|
|
97
|
+
function tryLoadFromPrebuiltPackage(errors) {
|
|
98
|
+
const packageName = PLATFORM_PACKAGES[getPlatformKey()];
|
|
99
|
+
if (!packageName) {
|
|
100
|
+
errors.push(`No prebuilt package mapping for platform '${getPlatformKey()}'.`);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let bundle;
|
|
105
|
+
try {
|
|
106
|
+
bundle = require(packageName);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
109
|
+
errors.push(`Failed to require '${packageName}': ${message}`);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const addonPath = typeof bundle?.addonPath === "string" ? bundle.addonPath : "";
|
|
114
|
+
const libraryPath = typeof bundle?.libraryPath === "string" ? bundle.libraryPath : "";
|
|
115
|
+
const libraryDir = typeof bundle?.libraryDir === "string" ? bundle.libraryDir : "";
|
|
116
|
+
|
|
117
|
+
if (!addonPath || !libraryPath || !libraryDir) {
|
|
118
|
+
errors.push(`Package '${packageName}' did not export addon/library paths.`);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!process.env.CASCODE_NATIVE_LIB) {
|
|
123
|
+
process.env.CASCODE_NATIVE_LIB = libraryPath;
|
|
124
|
+
}
|
|
125
|
+
prependLibrarySearchPath(libraryDir);
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
return tryLoadAddonFromPath(addonPath);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
131
|
+
errors.push(`Failed loading prebuilt addon from '${addonPath}': ${message}`);
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Searches common installation and build locations for the platform-native library and, if found,
|
|
138
|
+
* sets process.env.CASCODE_NATIVE_LIB to the discovered path and prepends that directory to the
|
|
139
|
+
* process dynamic library search path.
|
|
140
|
+
*
|
|
141
|
+
* The function does nothing if CASCODE_NATIVE_LIB is already set or if the current platform/architecture
|
|
142
|
+
* is unsupported. If no matching library is found, the environment is left unchanged.
|
|
143
|
+
*/
|
|
144
|
+
function maybeResolveNativeLibraryPath() {
|
|
145
|
+
if (process.env.CASCODE_NATIVE_LIB) return;
|
|
146
|
+
const rid = getRuntimeRid();
|
|
147
|
+
if (!rid) return;
|
|
148
|
+
|
|
149
|
+
const roots = [
|
|
150
|
+
// Packaged/prepared module layout: editors/node/native/<rid>/<lib>
|
|
151
|
+
path.join(__dirname, "..", "native", rid),
|
|
152
|
+
// Cascode repo layout: <repo>/build/native/<rid>/<lib>
|
|
153
|
+
path.join(__dirname, "..", "..", "..", "build", "native", rid),
|
|
154
|
+
// Alternate nested layout used by some local installs.
|
|
155
|
+
path.join(__dirname, "..", "..", "build", "native", rid),
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
const names = getNativeLibraryFileNames();
|
|
159
|
+
for (const root of roots) {
|
|
160
|
+
for (const name of names) {
|
|
161
|
+
const candidate = path.join(root, name);
|
|
162
|
+
if (fs.existsSync(candidate)) {
|
|
163
|
+
process.env.CASCODE_NATIVE_LIB = candidate;
|
|
164
|
+
prependLibrarySearchPath(root);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Attempt to load a locally built native addon for the current platform.
|
|
173
|
+
* @param {string[]} errors - Array that will receive error messages for each failed load attempt; messages are appended in-place.
|
|
174
|
+
* @returns {Object|null} The loaded native addon module if found, or `null` if no local addon could be loaded.
|
|
175
|
+
*/
|
|
176
|
+
function tryLoadFromLocalBuild(errors) {
|
|
177
|
+
maybeResolveNativeLibraryPath();
|
|
178
|
+
const localCandidates = [
|
|
179
|
+
path.join(__dirname, "..", "build", "Release", "cascode_native_addon.node"),
|
|
180
|
+
path.join(__dirname, "..", "prebuilds", "cascode_native_addon.node"),
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
for (const candidate of localCandidates) {
|
|
184
|
+
try {
|
|
185
|
+
const addon = tryLoadAddonFromPath(candidate);
|
|
186
|
+
if (addon) return addon;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
189
|
+
errors.push(`Failed loading local addon from '${candidate}': ${message}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
errors.push("No local addon found in expected build/prebuild paths.");
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Load the native Cascode addon from a prebuilt package or a local build.
|
|
199
|
+
*
|
|
200
|
+
* Attempts to load a prebuilt platform package first, then falls back to local build artifacts.
|
|
201
|
+
* @returns {object} The loaded native addon module.
|
|
202
|
+
* @throws {Error} If no addon could be loaded; the error message lists attempted sources and failures.
|
|
203
|
+
*/
|
|
204
|
+
function loadAddonOrThrow() {
|
|
205
|
+
const errors = [];
|
|
206
|
+
const prebuiltAddon = tryLoadFromPrebuiltPackage(errors);
|
|
207
|
+
if (prebuiltAddon) return prebuiltAddon;
|
|
208
|
+
|
|
209
|
+
const localAddon = tryLoadFromLocalBuild(errors);
|
|
210
|
+
if (localAddon) return localAddon;
|
|
211
|
+
|
|
212
|
+
throw new Error(
|
|
213
|
+
"[cascode-native] Failed to load native addon.\n" +
|
|
214
|
+
"Checked prebuilt platform package and local build paths.\n" +
|
|
215
|
+
`Errors:\n- ${errors.join("\n- ")}`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const addon = loadAddonOrThrow();
|
|
220
|
+
|
|
221
|
+
// Bundled stdlib path — try package-local first, then repo-relative.
|
|
222
|
+
const _bundledStdlib = path.join(__dirname, "..", "lib", "std");
|
|
223
|
+
const _repoStdlib = path.join(__dirname, "..", "..", "..", "lib", "std");
|
|
224
|
+
let stdlibPath = null;
|
|
225
|
+
if (fs.existsSync(_bundledStdlib)) {
|
|
226
|
+
stdlibPath = _bundledStdlib;
|
|
227
|
+
} else if (fs.existsSync(_repoStdlib)) {
|
|
228
|
+
stdlibPath = _repoStdlib;
|
|
229
|
+
} else {
|
|
230
|
+
throw new Error(
|
|
231
|
+
"[cascode-native] Standard library not found.\n" +
|
|
232
|
+
`Expected either:\n- ${_bundledStdlib}\n- ${_repoStdlib}\n` +
|
|
233
|
+
"If you are developing locally, ensure you are inside a cascode-lynx checkout.\n" +
|
|
234
|
+
"If you installed from npm, the package may be missing bundled lib/std."
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Create a new Cascode session using the provided JSON options.
|
|
240
|
+
* @param {string} optionsJson - JSON string containing session options (e.g., "{}", configuration fields).
|
|
241
|
+
* @returns {any} The created session handle to pass to other native functions.
|
|
242
|
+
*/
|
|
243
|
+
function createSession(optionsJson = "{}") {
|
|
244
|
+
return addon.createSession(optionsJson);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Terminates and frees a native session created by createSession.
|
|
249
|
+
* @param {*} session - The native session handle returned by createSession.
|
|
250
|
+
*/
|
|
251
|
+
function destroySession(session) {
|
|
252
|
+
addon.destroySession(session);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Invoke a native addon method for an existing session.
|
|
257
|
+
* @param {any} session - Opaque session handle returned by createSession.
|
|
258
|
+
* @param {string} method - Method name to invoke (e.g., "document.open").
|
|
259
|
+
* @param {string} requestJson - JSON-serialized request payload.
|
|
260
|
+
* @returns {string} The JSON-serialized response from the native addon.
|
|
261
|
+
*/
|
|
262
|
+
function call(session, method, requestJson) {
|
|
263
|
+
return addon.call(session, method, requestJson);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Retrieve the last error for a session as a JSON string.
|
|
268
|
+
* @param {*} session - Session handle returned by createSession.
|
|
269
|
+
* @returns {string} The JSON-encoded error details for the session.
|
|
270
|
+
*/
|
|
271
|
+
function lastErrorJson(session) {
|
|
272
|
+
return addon.lastErrorJson(session);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Get the native addon's API version.
|
|
277
|
+
* @returns {number} The API version number.
|
|
278
|
+
*/
|
|
279
|
+
function apiVersion() {
|
|
280
|
+
return addon.apiVersion();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Retrieve the schema version exposed by the native addon.
|
|
285
|
+
* @returns {number} The schema version number.
|
|
286
|
+
*/
|
|
287
|
+
function schemaVersion() {
|
|
288
|
+
return addon.schemaVersion();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Invoke the native addon's `call` method with the given request and parse its JSON response.
|
|
293
|
+
* @param {{call: function}} native - Native addon exposing a `call(session, method, json)` function.
|
|
294
|
+
* @param {*} session - Session handle previously returned by `createSession`.
|
|
295
|
+
* @param {string} method - Method name to invoke on the native addon.
|
|
296
|
+
* @param {*} request - Request payload to be serialized to JSON and sent to the native addon.
|
|
297
|
+
* @returns {*} The parsed response object returned by the native addon.
|
|
298
|
+
*/
|
|
299
|
+
function parseCall(native, session, method, request) {
|
|
300
|
+
return JSON.parse(native.call(session, method, JSON.stringify(request)));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Invoke the native "document.open" method and parse its JSON response.
|
|
305
|
+
* @param {*} native - The loaded native addon module.
|
|
306
|
+
* @param {*} session - The native session handle.
|
|
307
|
+
* @param {*} req - The request payload (object or JSON string) to send to the native call.
|
|
308
|
+
* @returns {object} The parsed JSON response from the native call.
|
|
309
|
+
*/
|
|
310
|
+
function open(native, session, req) {
|
|
311
|
+
return parseCall(native, session, "document.open", req);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Invoke the native addon's "document.updateText" method for a session and return the parsed response.
|
|
316
|
+
* @param {Object} native - The loaded native addon module.
|
|
317
|
+
* @param {*} session - The session handle returned by the native addon.
|
|
318
|
+
* @param {Object|string} req - The request payload for the updateText call (object or JSON string).
|
|
319
|
+
* @returns {Object} The parsed JSON response from the native method.
|
|
320
|
+
*/
|
|
321
|
+
function updateText(native, session, req) {
|
|
322
|
+
return parseCall(native, session, "document.updateText", req);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Close a document in the given session using the native addon.
|
|
327
|
+
* @param {Object} native - The loaded native addon module.
|
|
328
|
+
* @param {*} session - The session handle returned by createSession.
|
|
329
|
+
* @param {Object} req - Request payload for the "document.close" call.
|
|
330
|
+
* @returns {Object} The parsed JSON response returned by the native call.
|
|
331
|
+
*/
|
|
332
|
+
function close(native, session, req) {
|
|
333
|
+
return parseCall(native, session, "document.close", req);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Request a schematic render from the native addon and return its parsed response.
|
|
338
|
+
* @param {object} native - The native addon module to invoke.
|
|
339
|
+
* @param {*} session - The session handle previously returned by createSession.
|
|
340
|
+
* @param {object|string} req - The render request (object or JSON string) to send to the native addon.
|
|
341
|
+
* @returns {object} The parsed response object returned by the native render operation.
|
|
342
|
+
*/
|
|
343
|
+
function render(native, session, req) {
|
|
344
|
+
return parseCall(native, session, "render.schematic", req);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Invoke the native "schematic.applyOperations" method and return its parsed result.
|
|
349
|
+
* @param {object} native - The native addon object exposing call bindings.
|
|
350
|
+
* @param {*} session - The native session handle.
|
|
351
|
+
* @param {*} req - The request payload to send; typically an object or JSON string.
|
|
352
|
+
* @returns {object} The parsed response object from the native "schematic.applyOperations" call.
|
|
353
|
+
*/
|
|
354
|
+
function applyOps(native, session, req) {
|
|
355
|
+
return parseCall(native, session, "schematic.applyOperations", req);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Run electrical rule check for the given session and request.
|
|
360
|
+
* @param {object} native - Loaded native addon exposing RPC methods.
|
|
361
|
+
* @param {any} session - Session identifier returned by `createSession`.
|
|
362
|
+
* @param {object|string} req - Request payload for the ERC operation.
|
|
363
|
+
* @returns {object} The parsed response from the native `erc.run` call.
|
|
364
|
+
*/
|
|
365
|
+
function erc(native, session, req) {
|
|
366
|
+
return parseCall(native, session, "erc.run", req);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Invoke the native "emit.run" operation for the given session.
|
|
371
|
+
* @param {object} native - The loaded native addon module.
|
|
372
|
+
* @param {*} session - The session handle returned by createSession.
|
|
373
|
+
* @param {object|string} req - The request payload (object or JSON string) for the emit operation.
|
|
374
|
+
* @returns {object} The parsed response object from the "emit.run" operation.
|
|
375
|
+
*/
|
|
376
|
+
function emit(native, session, req) {
|
|
377
|
+
return parseCall(native, session, "emit.run", req);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Invoke the native "verify.run" method for the given session and request.
|
|
382
|
+
* @param {*} native - The native addon module used to perform the call.
|
|
383
|
+
* @param {*} session - The native session handle.
|
|
384
|
+
* @param {string|Object} req - The request payload (JSON string or object) to send.
|
|
385
|
+
* @returns {Object} The parsed response object returned by the native verify.run call.
|
|
386
|
+
*/
|
|
387
|
+
function verify(native, session, req) {
|
|
388
|
+
return parseCall(native, session, "verify.run", req);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Invoke the native "job.start" method for a session and return its parsed response.
|
|
393
|
+
* @param {object} native - The loaded native addon exposing call APIs.
|
|
394
|
+
* @param {*} session - The session handle returned by createSession.
|
|
395
|
+
* @param {object} req - The request payload to send to the native method.
|
|
396
|
+
* @returns {object} The parsed response object returned by the native addon.
|
|
397
|
+
*/
|
|
398
|
+
function jobStart(native, session, req) {
|
|
399
|
+
return parseCall(native, session, "job.start", req);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Polls the status of a background job.
|
|
404
|
+
* @param {*} native - The native addon module to invoke.
|
|
405
|
+
* @param {*} session - The session handle returned by createSession.
|
|
406
|
+
* @param {Object} req - The request payload for the job poll.
|
|
407
|
+
* @returns {*} The parsed response from the native `job.poll` call.
|
|
408
|
+
*/
|
|
409
|
+
function jobPoll(native, session, req) {
|
|
410
|
+
return parseCall(native, session, "job.poll", req);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Invoke the native "job.cancel" method and return its parsed JSON response.
|
|
415
|
+
* @param {any} native - The loaded native addon module exposing the `call` entrypoint.
|
|
416
|
+
* @param {number|string|object} session - Session identifier returned by `createSession`.
|
|
417
|
+
* @param {object} req - Request payload for the cancel operation.
|
|
418
|
+
* @returns {object} Parsed JSON response from the native `job.cancel` call.
|
|
419
|
+
*/
|
|
420
|
+
function jobCancel(native, session, req) {
|
|
421
|
+
return parseCall(native, session, "job.cancel", req);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const native = {
|
|
425
|
+
createSession,
|
|
426
|
+
destroySession,
|
|
427
|
+
call,
|
|
428
|
+
lastErrorJson,
|
|
429
|
+
apiVersion,
|
|
430
|
+
schemaVersion
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
module.exports = {
|
|
434
|
+
native,
|
|
435
|
+
stdlibPath,
|
|
436
|
+
createSession,
|
|
437
|
+
destroySession,
|
|
438
|
+
call,
|
|
439
|
+
lastErrorJson,
|
|
440
|
+
apiVersion,
|
|
441
|
+
schemaVersion,
|
|
442
|
+
open,
|
|
443
|
+
updateText,
|
|
444
|
+
close,
|
|
445
|
+
render,
|
|
446
|
+
applyOps,
|
|
447
|
+
erc,
|
|
448
|
+
emit,
|
|
449
|
+
verify,
|
|
450
|
+
jobStart,
|
|
451
|
+
jobPoll,
|
|
452
|
+
jobCancel
|
|
453
|
+
};
|