@coherentglobal/wasm-runner 0.0.22

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/error.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable no-useless-constructor */
4
+ /* eslint-disable max-classes-per-file */
5
+ class WasmError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ }
9
+ get v3() {
10
+ return {
11
+ error_category: this.name,
12
+ error_type: this.type,
13
+ message: this.message,
14
+ severity: this.severity,
15
+ };
16
+ }
17
+ get modelInfo() {
18
+ return {
19
+ uuid: this.uuid,
20
+ input: this.input
21
+ };
22
+ }
23
+ }
24
+ // Model Errors
25
+ class ModelError extends WasmError {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = "model_error";
29
+ this.type = "error.MODEL_ERROR";
30
+ this.severity = "low";
31
+ }
32
+ }
33
+ class MissingModelError extends ModelError {
34
+ constructor(uuid) {
35
+ super(`Model ${uuid} cannot be found`);
36
+ this.name = "missing_model_error";
37
+ this.uuid = uuid;
38
+ this.type = "error.MISSING_MODEL_ERROR";
39
+ this.severity = "low";
40
+ }
41
+ }
42
+ class ModelInitializationError extends ModelError {
43
+ constructor(uuid) {
44
+ super(`Model ${uuid} was not initialized`);
45
+ this.name = "model_not_initialized_error";
46
+ this.uuid = uuid;
47
+ this.type = "error.MODEL_NOT_INITIALIZED_ERROR";
48
+ this.severity = "low";
49
+ }
50
+ }
51
+ class ParameterRequiredError extends WasmError {
52
+ constructor(parameter, inputs = "") {
53
+ super(`WasmRunner failed to find ${parameter} parameter`);
54
+ this.name = "missing_parameter";
55
+ this.parameter = parameter;
56
+ this.type = "error.MISSING_PARAMETER";
57
+ this.severity = "low";
58
+ this.input = inputs;
59
+ }
60
+ }
61
+ // Browser Errors
62
+ class BrowserError extends WasmError {
63
+ constructor(message) {
64
+ super(message);
65
+ this.name = "browser_error";
66
+ this.type = "error.BROWSER_ERROR";
67
+ this.severity = "low";
68
+ }
69
+ }
70
+ class NotSupportedError extends BrowserError {
71
+ constructor(support, uuid = "", input = {}) {
72
+ super(`${support} support is required`);
73
+ this.name = "not_supported_error";
74
+ this.type = "error.NOT_SUPPORTED";
75
+ this.severity = "high";
76
+ this.uuid = uuid;
77
+ this.input = input;
78
+ }
79
+ }
80
+ class ModelValidationError extends ModelError {
81
+ constructor(errors, uuid, results) {
82
+ super("Model validation error");
83
+ this.name = "validation_error";
84
+ this.type = "error.VALIDATION";
85
+ this.severity = "low";
86
+ this.errors = errors;
87
+ this.rawResult = results;
88
+ this.uuid = uuid;
89
+ }
90
+ }
91
+ class ModelExecuteError extends ModelError {
92
+ constructor(errors, uuid, input) {
93
+ super("Model execution error");
94
+ this.name = "execution_error";
95
+ this.type = "error.EXECUTION";
96
+ this.severity = "low";
97
+ this.errors = errors;
98
+ this.input = input;
99
+ this.uuid = uuid;
100
+ }
101
+ }
102
+ exports.default = {
103
+ ModelError,
104
+ ModelExecuteError,
105
+ MissingModelError,
106
+ ModelValidationError,
107
+ ModelInitializationError,
108
+ ParameterRequiredError,
109
+ BrowserError,
110
+ NotSupportedError,
111
+ };
112
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;AAAA,2CAA2C;AAC3C,yCAAyC;AACzC,MAAM,SAAU,SAAQ,KAAK;IAK3B,YAAY,OAAO;QACjB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,IAAI;YACzB,UAAU,EAAE,IAAI,CAAC,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;IAED,IAAI,SAAS;QACX,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,I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AI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,kBAAe;IACb,UAAU;IACV,iBAAiB;IACjB,iBAAiB;IACjB,oBAAoB;IACpB,wBAAwB;IACxB,sBAAsB;IACtB,YAAY;IACZ,iBAAiB;CAClB,CAAC"}
@@ -0,0 +1,70 @@
1
+ const { parentPort, workerData } = require('worker_threads');
2
+ var model = require('<%= runtime %>')
3
+
4
+ let wasm;
5
+ let wb;
6
+ let modelName = '<%= modelName %>';
7
+ let isReady = false;
8
+
9
+ let execute = function (req) { return false }
10
+
11
+ try {
12
+ model().then(instance => {
13
+ try {
14
+ execute = function (req) {
15
+ try {
16
+ if(req === "isReady") {
17
+ return isReady
18
+ }
19
+
20
+ const enc = new TextEncoder();
21
+ const encoded = enc.encode(req)
22
+
23
+ var inBuffer = instance._malloc(encoded.length);
24
+
25
+ var bytes_per_element = encoded.BYTES_PER_ELEMENT;
26
+ instance.HEAP8.set(encoded, inBuffer / bytes_per_element);
27
+
28
+ const outBuffer = instance._malloc(8);
29
+
30
+ const outPtr = instance._node_calc_v3(wb, inBuffer, encoded.length, outBuffer);
31
+
32
+ var offset = instance.getValue(outBuffer, "i64");
33
+
34
+ var dnc = new TextDecoder("utf-8");
35
+
36
+ const resultData = new Uint8Array(instance.HEAPU8.subarray(outPtr, outPtr + offset));
37
+
38
+ const result = dnc.decode(resultData).slice()
39
+
40
+ instance._free(inBuffer);
41
+ instance._free(outBuffer);
42
+ instance._free(outPtr);
43
+
44
+ return result
45
+ } catch(err) {
46
+ throw err
47
+ }
48
+ }
49
+
50
+ wb = instance._construct();
51
+ console.log(`Worker ${modelName} initiated`);
52
+ isReady = true;
53
+ return Promise.resolve()
54
+ } catch (err) {
55
+ instance = undefined
56
+ console.log(`Worker ${modelName} failed to initiate`);
57
+ return Promise.reject(err)
58
+ }
59
+ }).catch(err => console.error(err))
60
+ } catch(err) {}
61
+
62
+
63
+
64
+ parentPort.on('message', (param) => {
65
+ if (typeof param !== 'string' && param !== "isReady") {
66
+ throw new Error('Param must be a json string.');
67
+ }
68
+ const result = execute(param);
69
+ parentPort.postMessage(result);
70
+ });
package/dist/node.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import tmp from "tmp";
2
+ import { NodeModel, RunnerConfig } from "./types";
3
+ /**
4
+ * WASM runner config
5
+ * @typedef {Object} RunnerConfig
6
+ * @property {string} id - Model id or version_uuid
7
+ * @property {string} url - Model url
8
+ */
9
+ /**
10
+ * Input object
11
+ * @typedef {Object} InputObject
12
+ * @property {Object} request_data - Request input date
13
+ * @property {Object} request_meta - Request input meta
14
+ */
15
+ /**
16
+ * WasmRunner class, responsible for managing model and it's lifecycle
17
+ *
18
+ * @class
19
+ * @classdesc WasmRunner class, responsible for managing model and it's lifecycle
20
+ */
21
+ export declare class WasmRunner {
22
+ _tempWorkerFolder: tmp.DirSyncObject;
23
+ _tempModelFolder: tmp.DirSyncObject;
24
+ license: string;
25
+ models: any[];
26
+ /**
27
+ * Create new Wasm Runner instance
28
+ *
29
+ * @param {RunnerConfig} wasmRunnerConfig
30
+ */
31
+ constructor(wasmRunnerConfig: RunnerConfig, license?: string);
32
+ /**
33
+ * Initialize wasm runner fetching model from remote server
34
+ *
35
+ * @async
36
+ * @function initialize
37
+ */
38
+ initialize(license?: string): Promise<void>;
39
+ _initializeModelInstance(m: NodeModel): Promise<void>;
40
+ /**
41
+ * Append and initialized new model to runner
42
+ * @param {RunnerConfig} modelConfig
43
+ * @returns Promise
44
+ */
45
+ append(modelConfig: RunnerConfig): Promise<void>;
46
+ /**
47
+ * Remove model from runner
48
+ * @param {string} id Model id
49
+ */
50
+ remove(id: string): void;
51
+ _parseError(rawResponse: any): Object;
52
+ _getModel(id: string): NodeModel;
53
+ /**
54
+ * Check if model existed
55
+ * @param {string} id Model id
56
+ * @returns boolean
57
+ */
58
+ isExist(id: string): boolean;
59
+ /**
60
+ * Perform calculation. The runner will use request_meta.version_uuid of input argument to locate model
61
+ * @async
62
+ * @param {InputObject} input - Input data for calculation
63
+ * @returns {Promise<Object>} - Response model data
64
+ */
65
+ execute(input: any, id?: string): Promise<Object>;
66
+ }
package/dist/node.js ADDED
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.WasmRunner = void 0;
35
+ /* eslint-disable consistent-return */
36
+ /* eslint-disable no-shadow */
37
+ /* eslint-disable camelcase */
38
+ /* eslint-disable no-param-reassign */
39
+ /* eslint-disable no-underscore-dangle */
40
+ const tmp_1 = __importDefault(require("tmp"));
41
+ const unzipper_1 = require("unzipper");
42
+ const ejs_1 = __importDefault(require("ejs"));
43
+ const stream_1 = __importDefault(require("stream"));
44
+ const fs_1 = __importStar(require("fs"));
45
+ const path_1 = __importDefault(require("path"));
46
+ const util_1 = require("util");
47
+ const got_1 = __importDefault(require("got"));
48
+ const node_worker_threads_pool_1 = require("node-worker-threads-pool");
49
+ const utils = __importStar(require("./utils"));
50
+ const error_1 = __importDefault(require("./error"));
51
+ const pipeline = (0, util_1.promisify)(stream_1.default.pipeline);
52
+ function replaceRegexInFile(file, search, replace) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ let contents = yield fs_1.default.promises.readFile(file, "utf8");
55
+ let replaced_contents = contents.replace(search, replace);
56
+ let tmpfile = `${file}.jstmpreplace`;
57
+ yield fs_1.default.promises.writeFile(tmpfile, replaced_contents, "utf8");
58
+ yield fs_1.default.promises.rename(tmpfile, file);
59
+ return true;
60
+ });
61
+ }
62
+ const unzipFiles = (id, url, workerFolder) => {
63
+ let js;
64
+ let wasm;
65
+ // @ts-ignore
66
+ const stream = fs_1.default.createReadStream(url).pipe((0, unzipper_1.Parse)());
67
+ return new Promise((resolve, reject) => {
68
+ stream.on("entry", (entry) => {
69
+ const type = entry.type;
70
+ if (type === "File" && entry.path.indexOf("__MACOSX") === -1) {
71
+ const fileName = tmp_1.default.fileSync({
72
+ dir: workerFolder,
73
+ name: entry.path,
74
+ // @ts-ignore
75
+ mode: 0o750,
76
+ });
77
+ const writeStream = fs_1.default.createWriteStream(fileName.name);
78
+ if (path_1.default.extname(entry.path) === ".js") {
79
+ js = fileName.name;
80
+ }
81
+ if (path_1.default.extname(entry.path) === ".wasm") {
82
+ wasm = fileName.name;
83
+ }
84
+ return entry.pipe(writeStream);
85
+ }
86
+ return entry.autodrain();
87
+ });
88
+ stream.on("finish", () => {
89
+ if (!js)
90
+ return reject(new Error("Missing runtime file"));
91
+ if (!wasm)
92
+ return reject(new Error("Missing engine file"));
93
+ if (js && wasm)
94
+ return resolve({
95
+ js,
96
+ wasm,
97
+ });
98
+ });
99
+ stream.on("error", (error) => reject(error));
100
+ });
101
+ };
102
+ const template = ejs_1.default.compile(fs_1.default.readFileSync(path_1.default.join(__dirname, "node/template/main.template.ejs"), {
103
+ encoding: "utf8",
104
+ flag: "r",
105
+ }), { async: false });
106
+ const createModelInstance = (id, url, workerFolder) => __awaiter(void 0, void 0, void 0, function* () {
107
+ const tempFolder = tmp_1.default.dirSync({
108
+ dir: workerFolder,
109
+ name: `${id}-${Date.now()}`,
110
+ // @ts-ignore
111
+ mode: 0o750,
112
+ });
113
+ const modelPack = yield unzipFiles(id, url, tempFolder.name);
114
+ const modelName = id;
115
+ yield replaceRegexInFile(modelPack.js, `wasmBinaryFile="${path_1.default.basename(modelPack.wasm)}"`,
116
+ // `scriptDirectory="";wasmBinaryFile="data:application/octet-stream;base64,${content}"`
117
+ `scriptDirectory="";wasmBinaryFile="${modelPack.wasm}"`);
118
+ const fileContent = template({
119
+ runtime: modelPack.js.replace(".js", ""),
120
+ model: modelPack.wasm,
121
+ modelName,
122
+ });
123
+ const workerPath = tmp_1.default.fileSync({
124
+ dir: tempFolder.name,
125
+ name: `worker-${id}.js`,
126
+ // @ts-ignore
127
+ mode: 0o750,
128
+ }).name;
129
+ yield fs_1.default.promises.writeFile(workerPath, fileContent);
130
+ const instancePool = new node_worker_threads_pool_1.StaticPool({
131
+ size: 1,
132
+ task: workerPath,
133
+ });
134
+ return new Promise((resolve, reject) => {
135
+ let limit = 0;
136
+ const checkModelStatus = () => __awaiter(void 0, void 0, void 0, function* () {
137
+ const isReady = yield instancePool.exec("isReady");
138
+ if (isReady) {
139
+ resolve(instancePool);
140
+ }
141
+ else if (limit >= 2000) { // 1 second
142
+ reject(new Error("Model initialize issue"));
143
+ }
144
+ else {
145
+ setTimeout(checkModelStatus, 5);
146
+ // eslint-disable-next-line no-plusplus
147
+ limit++;
148
+ }
149
+ });
150
+ setTimeout(checkModelStatus, 5);
151
+ });
152
+ // return {};
153
+ });
154
+ const createModelInstanceFromURL = (id, url, workerFolder, modelFolder) => __awaiter(void 0, void 0, void 0, function* () {
155
+ try {
156
+ const modelPath = path_1.default.join(modelFolder, `${id}.zip`);
157
+ const downloadStream = got_1.default.stream(url);
158
+ const fileWriterStream = (0, fs_1.createWriteStream)(modelPath);
159
+ yield pipeline(downloadStream, fileWriterStream);
160
+ const instance = yield createModelInstance(id, modelPath, workerFolder);
161
+ return instance;
162
+ }
163
+ catch (err) {
164
+ throw new error_1.default.ModelError(`Error createModelInstanceFromURL: id:${id}, url:${url}, error:${err.message}`);
165
+ }
166
+ });
167
+ /**
168
+ * WASM runner config
169
+ * @typedef {Object} RunnerConfig
170
+ * @property {string} id - Model id or version_uuid
171
+ * @property {string} url - Model url
172
+ */
173
+ /**
174
+ * Input object
175
+ * @typedef {Object} InputObject
176
+ * @property {Object} request_data - Request input date
177
+ * @property {Object} request_meta - Request input meta
178
+ */
179
+ /**
180
+ * WasmRunner class, responsible for managing model and it's lifecycle
181
+ *
182
+ * @class
183
+ * @classdesc WasmRunner class, responsible for managing model and it's lifecycle
184
+ */
185
+ // eslint-disable-next-line import/prefer-default-export
186
+ class WasmRunner {
187
+ /**
188
+ * Create new Wasm Runner instance
189
+ *
190
+ * @param {RunnerConfig} wasmRunnerConfig
191
+ */
192
+ constructor(wasmRunnerConfig, license = "") {
193
+ this._tempWorkerFolder = tmp_1.default.dirSync({
194
+ prefix: "wasmserver_worker",
195
+ // @ts-ignore
196
+ mode: 0o750,
197
+ });
198
+ this._tempModelFolder = tmp_1.default.dirSync({
199
+ prefix: "wasmserver_model",
200
+ // @ts-ignore
201
+ mode: 0o750,
202
+ });
203
+ this.license = license;
204
+ this.models = [];
205
+ if (!utils.isEmpty(wasmRunnerConfig)) {
206
+ if (Array.isArray(wasmRunnerConfig)) {
207
+ this.models = wasmRunnerConfig.map((wsconfig) => ({
208
+ id: wsconfig.id,
209
+ url: wsconfig.url,
210
+ }));
211
+ }
212
+ else if (typeof wasmRunnerConfig === "object") {
213
+ this.models = [
214
+ {
215
+ id: wasmRunnerConfig.id,
216
+ url: wasmRunnerConfig.url,
217
+ },
218
+ ];
219
+ }
220
+ }
221
+ }
222
+ /**
223
+ * Initialize wasm runner fetching model from remote server
224
+ *
225
+ * @async
226
+ * @function initialize
227
+ */
228
+ initialize(license = "") {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ yield Promise.all(this.models.map((m) => __awaiter(this, void 0, void 0, function* () {
231
+ yield this._initializeModelInstance(m);
232
+ })));
233
+ });
234
+ }
235
+ _initializeModelInstance(m) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ if (utils.isHttpURL(m.url)) {
238
+ const instance = yield createModelInstanceFromURL(m.id, m.url, this._tempWorkerFolder.name, this._tempModelFolder.name);
239
+ m.ready = true;
240
+ m.worker = instance;
241
+ return Promise.resolve();
242
+ }
243
+ if (yield utils.isPath(m.url)) {
244
+ const instance = yield createModelInstance(m.id, m.url, this._tempWorkerFolder.name);
245
+ m.ready = true;
246
+ m.worker = instance;
247
+ return Promise.resolve();
248
+ }
249
+ });
250
+ }
251
+ /**
252
+ * Append and initialized new model to runner
253
+ * @param {RunnerConfig} modelConfig
254
+ * @returns Promise
255
+ */
256
+ append(modelConfig) {
257
+ return __awaiter(this, void 0, void 0, function* () {
258
+ if (this.isExist(modelConfig.id)) {
259
+ return;
260
+ }
261
+ const model = {
262
+ id: modelConfig.id,
263
+ url: modelConfig.url,
264
+ };
265
+ yield this._initializeModelInstance(model);
266
+ this.models.push(model);
267
+ });
268
+ }
269
+ /**
270
+ * Remove model from runner
271
+ * @param {string} id Model id
272
+ */
273
+ remove(id) {
274
+ if (this.isExist(id)) {
275
+ this.models.filter((m) => m.id !== id);
276
+ }
277
+ }
278
+ _parseError(rawResponse) {
279
+ var _a;
280
+ let errors = (_a = rawResponse.response_data) === null || _a === void 0 ? void 0 : _a.errors.reduce((prev, curr) => {
281
+ const { source_path } = curr;
282
+ if (!source_path) {
283
+ return prev;
284
+ }
285
+ const keys = source_path.split(".");
286
+ let errProp;
287
+ const maxIndex = keys.length - 1;
288
+ keys.forEach((k, index) => {
289
+ if (index === 0) {
290
+ if (!prev[k]) {
291
+ prev[k] = {};
292
+ }
293
+ errProp = prev[k];
294
+ }
295
+ else {
296
+ if (!errProp[k]) {
297
+ if (index === maxIndex) {
298
+ errProp[k] = [];
299
+ }
300
+ else {
301
+ errProp[k] = {};
302
+ }
303
+ }
304
+ errProp = errProp[k];
305
+ }
306
+ if (index === maxIndex) {
307
+ if (!Array.isArray(errProp)) {
308
+ const error = new error_1.default.BrowserError(`Parsing response error at errors ${source_path}`);
309
+ throw error;
310
+ }
311
+ else {
312
+ errProp.push({
313
+ message: curr.message,
314
+ });
315
+ }
316
+ }
317
+ });
318
+ return prev;
319
+ }, {});
320
+ errors = { request_data: errors };
321
+ return errors;
322
+ }
323
+ _getModel(id) {
324
+ const model = this.models.find((m) => m.id === id);
325
+ if (!model)
326
+ throw new error_1.default.MissingModelError(id);
327
+ if (!model.ready)
328
+ throw new error_1.default.ModelInitializationError(id);
329
+ return model;
330
+ }
331
+ /**
332
+ * Check if model existed
333
+ * @param {string} id Model id
334
+ * @returns boolean
335
+ */
336
+ isExist(id) {
337
+ try {
338
+ return !!this._getModel(id);
339
+ }
340
+ catch (err) {
341
+ return false;
342
+ }
343
+ }
344
+ /**
345
+ * Perform calculation. The runner will use request_meta.version_uuid of input argument to locate model
346
+ * @async
347
+ * @param {InputObject} input - Input data for calculation
348
+ * @returns {Promise<Object>} - Response model data
349
+ */
350
+ execute(input, id = undefined) {
351
+ var _a;
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ console.log(`EXECUTING: ${id}, input: ${JSON.stringify(input)}`);
354
+ const version_uuid = id || ((_a = input.request_meta) === null || _a === void 0 ? void 0 : _a.version_uuid);
355
+ if (input) {
356
+ console.log(`EXECUTING: ${id}, input: ${JSON.stringify(input)}`);
357
+ const model = this._getModel(version_uuid);
358
+ try {
359
+ const result = yield model.worker.exec(JSON.stringify(input));
360
+ return JSON.parse(result);
361
+ }
362
+ catch (err) {
363
+ console.log('ERROR---------');
364
+ console.log(err);
365
+ throw new error_1.default.ModelExecuteError(err.message, version_uuid, input);
366
+ }
367
+ }
368
+ else {
369
+ throw new error_1.default.ParameterRequiredError("request_meta.version_uuid", input);
370
+ }
371
+ });
372
+ }
373
+ }
374
+ exports.WasmRunner = WasmRunner;
375
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAsC;AACtC,8BAA8B;AAC9B,8BAA8B;AAC9B,sCAAsC;AACtC,yCAAyC;AACzC,8CAAsB;AACtB,uCAAiC;AACjC,8CAAsB;AACtB,oDAA4B;AAC5B,yCAA2C;AAC3C,gDAAwB;AACxB,+BAAiC;AACjC,8CAAsB;AACtB,uEAAsD;AACtD,+CAAiC;AAGjC,oDAAuC;AAEvC,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,gBAAM,CAAC,QAAQ,CAAC,CAAC;AAE5C,SAAe,kBAAkB,CAAC,IAAY,EAAE,MAAc,EAAE,OAAe;;QAC7E,IAAI,QAAQ,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,iBAAiB,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1D,IAAI,OAAO,GAAG,GAAG,IAAI,eAAe,CAAC;QACrC,MAAM,YAAE,CAA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GAAG,EAAE;oBACZ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;oBAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;oBAChB,MAAM,IAAI,eAAgB,CAAC,iBAAiB,CAC1C,GAAG,CAAC,OAAO,EACX,YAAY,EACZ,KAAK,CACN,CAAC;iBACH;aACF;iBAAM;gBACL,MAAM,IAAI,eAAgB,CAAC,sBAAsB,CAC/C,2BAA2B,EAC3B,KAAK,CACN,CAAC;aACH;;KACF;CACF;AA3ND,gCA2NC"}
@@ -0,0 +1,32 @@
1
+ import { StaticPool } from "node-worker-threads-pool";
2
+ export interface Files {
3
+ js: string;
4
+ wasm: string;
5
+ }
6
+ export interface RunnerConfig {
7
+ id: string;
8
+ url: string;
9
+ }
10
+ interface ZipContent {
11
+ path: string;
12
+ url: string;
13
+ }
14
+ export interface UnzippedFiles {
15
+ js: ZipContent;
16
+ wasm: ZipContent;
17
+ }
18
+ export interface NodeModel {
19
+ id: any;
20
+ url: any;
21
+ ready?: boolean;
22
+ worker?: StaticPool<any, any>;
23
+ results?: any;
24
+ }
25
+ export interface Model {
26
+ id: any;
27
+ url: any;
28
+ ready?: boolean;
29
+ worker?: Worker;
30
+ results?: any;
31
+ }
32
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}