@endge/computation-sandbox 0.1.19 → 0.2.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.
|
@@ -3,7 +3,7 @@ export interface QuickJSComputationSandboxOptions {
|
|
|
3
3
|
workerCount?: number;
|
|
4
4
|
watchdogMs?: number;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/** Адаптер пакетного пула Worker для runtime вычислений ядра. */
|
|
7
7
|
export declare class QuickJSComputationSandbox implements ComputationSandboxAdapter {
|
|
8
8
|
private readonly _workers;
|
|
9
9
|
private readonly _queue;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var a = Object.defineProperty;
|
|
2
|
-
var h = (
|
|
3
|
-
var s = (
|
|
4
|
-
import {
|
|
2
|
+
var h = (i, e, t) => e in i ? a(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var s = (i, e, t) => h(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { EndgeModule as d, Endge as n } from "@endge/core";
|
|
5
5
|
class _ {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
s(this, "_worker", this._createWorker());
|
|
@@ -41,10 +41,10 @@ class _ {
|
|
|
41
41
|
this._active = null, this._timer = null, this._busy = !1, this._pump();
|
|
42
42
|
}, this._watchdogMs), this._worker.onmessage = (t) => {
|
|
43
43
|
this._timer && clearTimeout(this._timer), this._timer = null;
|
|
44
|
-
const r = new Map(t.data.results.map((
|
|
45
|
-
for (const
|
|
46
|
-
const u = r.get(
|
|
47
|
-
u ? u.ok ?
|
|
44
|
+
const r = new Map(t.data.results.map((o) => [o.id, o]));
|
|
45
|
+
for (const o of e) {
|
|
46
|
+
const u = r.get(o.id);
|
|
47
|
+
u ? u.ok ? o.resolve(u.value) : o.reject(new Error(u.message)) : o.reject(new Error("Computation Worker returned no result."));
|
|
48
48
|
}
|
|
49
49
|
this._active = null, this._busy = !1, this._pump();
|
|
50
50
|
}, this._worker.onerror = (t) => {
|
|
@@ -72,8 +72,8 @@ class c {
|
|
|
72
72
|
s(this, "_nextId", 1);
|
|
73
73
|
s(this, "_scheduled", !1);
|
|
74
74
|
s(this, "_disposed", !1);
|
|
75
|
-
const t = typeof navigator > "u" ? 2 : navigator.hardwareConcurrency || 2, r = e.workerCount ?? Math.min(4, Math.max(1, t - 1)),
|
|
76
|
-
this._workers = Array.from({ length: r }, () => new _(
|
|
75
|
+
const t = typeof navigator > "u" ? 2 : navigator.hardwareConcurrency || 2, r = e.workerCount ?? Math.min(4, Math.max(1, t - 1)), o = e.watchdogMs ?? 500;
|
|
76
|
+
this._workers = Array.from({ length: r }, () => new _(o));
|
|
77
77
|
}
|
|
78
78
|
execute(e) {
|
|
79
79
|
return this._disposed ? Promise.reject(new Error("Computation sandbox is disposed.")) : new Promise((t, r) => {
|
|
@@ -95,24 +95,32 @@ class c {
|
|
|
95
95
|
let t = 0;
|
|
96
96
|
for (; this._queue.length; )
|
|
97
97
|
e[t++ % e.length].push(this._queue.shift());
|
|
98
|
-
e.forEach((r,
|
|
99
|
-
r.length && this._workers[
|
|
98
|
+
e.forEach((r, o) => {
|
|
99
|
+
r.length && this._workers[o].execute(r);
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
function l(
|
|
104
|
-
return new c(
|
|
103
|
+
function l(i) {
|
|
104
|
+
return new c(i);
|
|
105
105
|
}
|
|
106
106
|
class m extends d {
|
|
107
107
|
constructor() {
|
|
108
108
|
super(...arguments);
|
|
109
|
+
/** Активный sandbox adapter текущего lifecycle. */
|
|
109
110
|
s(this, "_adapter", null);
|
|
110
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* ----------------------------------------
|
|
114
|
+
* PUBLIC
|
|
115
|
+
* ----------------------------------------
|
|
116
|
+
*/
|
|
117
|
+
/** Создаёт и подключает sandbox adapter перед запуском runtime. */
|
|
111
118
|
setup() {
|
|
112
|
-
this._adapter = l(), n.
|
|
119
|
+
this._adapter = l(), n.computations.setSandboxAdapter(this._adapter);
|
|
113
120
|
}
|
|
121
|
+
/** Отключает adapter и освобождает ссылку текущего lifecycle. */
|
|
114
122
|
reset() {
|
|
115
|
-
n.
|
|
123
|
+
n.computations.setSandboxAdapter(null), this._adapter = null;
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
const w = {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EndgeModule } from '@endge/core';
|
|
2
|
+
/** Подключает изолированный QuickJS adapter к computation runtime на время lifecycle Endge. */
|
|
3
|
+
export declare class EndgeComputationSandbox_Module extends EndgeModule {
|
|
4
|
+
/** Активный sandbox adapter текущего lifecycle. */
|
|
5
|
+
private _adapter;
|
|
6
|
+
/**
|
|
7
|
+
* ----------------------------------------
|
|
8
|
+
* PUBLIC
|
|
9
|
+
* ----------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
/** Создаёт и подключает sandbox adapter перед запуском runtime. */
|
|
12
|
+
setup(): void;
|
|
13
|
+
/** Отключает adapter и освобождает ссылку текущего lifecycle. */
|
|
14
|
+
reset(): void;
|
|
15
|
+
}
|
|
@@ -4,7 +4,7 @@ export interface QuickJSComputationVMOptions {
|
|
|
4
4
|
memoryLimitBytes?: number;
|
|
5
5
|
stackLimitBytes?: number;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/** Единая изолированная фабрика QuickJS VM, используемая внутри Worker. */
|
|
8
8
|
export declare class QuickJSComputationVM {
|
|
9
9
|
private readonly _quickJs;
|
|
10
10
|
private readonly _moduleSources;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@endge/computation-sandbox",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"exports": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint-fix": "eslint . --fix --cache"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@endge/core": "^
|
|
28
|
+
"@endge/core": "^6.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@antfu/eslint-config": "9.3.0",
|
|
37
|
-
"@endge/core": "^
|
|
38
|
-
"@endge/raph": "^3.0
|
|
39
|
-
"@endge/utils": "^0.
|
|
37
|
+
"@endge/core": "^6.0.0",
|
|
38
|
+
"@endge/raph": "^3.1.0",
|
|
39
|
+
"@endge/utils": "^0.26.0",
|
|
40
40
|
"eslint": "10.9.1",
|
|
41
41
|
"rimraf": "^6.0.1",
|
|
42
42
|
"unplugin-dts": "^1.0.3",
|