@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
- /** Batched Worker pool adapter for the core computation runtime. */
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 = (o, e, t) => e in o ? a(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var s = (o, e, t) => h(o, typeof e != "symbol" ? e + "" : e, t);
4
- import { Endge as n, EndgeModule as d } from "@endge/core";
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((i) => [i.id, i]));
45
- for (const i of e) {
46
- const u = r.get(i.id);
47
- u ? u.ok ? i.resolve(u.value) : i.reject(new Error(u.message)) : i.reject(new Error("Computation Worker returned no result."));
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)), i = e.watchdogMs ?? 500;
76
- this._workers = Array.from({ length: r }, () => new _(i));
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, i) => {
99
- r.length && this._workers[i].execute(r);
98
+ e.forEach((r, o) => {
99
+ r.length && this._workers[o].execute(r);
100
100
  });
101
101
  }
102
102
  }
103
- function l(o) {
104
- return new c(o);
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.runtime.computation.setSandboxAdapter(this._adapter);
119
+ this._adapter = l(), n.computations.setSandboxAdapter(this._adapter);
113
120
  }
121
+ /** Отключает adapter и освобождает ссылку текущего lifecycle. */
114
122
  reset() {
115
- n.runtime.computation.setSandboxAdapter(null), this._adapter = null;
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
- /** One isolated QuickJS VM factory used inside a Worker. */
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.1.19",
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": "^3.0.1 || ^4.0.0 || ^5.0.0"
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": "^5.0.0",
38
- "@endge/raph": "^3.0.11",
39
- "@endge/utils": "^0.25.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",