@anonaddy/omni-worker 0.0.1 → 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.
- package/README.md +92 -28
- package/dist/cjs/{builder/helpers.js → helpers/builder.js} +2 -2
- package/dist/cjs/{builder/helpers.js.map → helpers/builder.js.map} +1 -1
- package/dist/cjs/helpers/pool.js +9 -0
- package/dist/cjs/helpers/pool.js.map +1 -0
- package/dist/cjs/node/builder/constants.js +19 -0
- package/dist/cjs/node/builder/constants.js.map +1 -0
- package/dist/cjs/node/builder/helpers.js +144 -0
- package/dist/cjs/node/builder/helpers.js.map +1 -0
- package/dist/cjs/node/builder/index.js +26 -0
- package/dist/cjs/node/builder/index.js.map +1 -0
- package/dist/cjs/node/index.js +125 -0
- package/dist/cjs/node/index.js.map +1 -0
- package/dist/cjs/node/pool.js +144 -0
- package/dist/cjs/node/pool.js.map +1 -0
- package/dist/cjs/node.js +6 -0
- package/dist/cjs/node.js.map +1 -0
- package/dist/cjs/types/helpers.js +11 -0
- package/dist/cjs/types/helpers.js.map +1 -0
- package/dist/cjs/types/node-omni-worker.js +3 -0
- package/dist/cjs/types/node-omni-worker.js.map +1 -0
- package/dist/cjs/types/web-omni-worker.js +3 -0
- package/dist/cjs/types/web-omni-worker.js.map +1 -0
- package/dist/cjs/web/builder/helpers.js +9 -0
- package/dist/cjs/web/builder/helpers.js.map +1 -0
- package/dist/cjs/web/builder/index.js +47 -0
- package/dist/cjs/web/builder/index.js.map +1 -0
- package/dist/cjs/{types/omni-worker.js → web/builder/model.js} +1 -1
- package/dist/cjs/web/builder/model.js.map +1 -0
- package/dist/cjs/web/index.js +156 -0
- package/dist/cjs/web/index.js.map +1 -0
- package/dist/cjs/web/pool.js +143 -0
- package/dist/cjs/web/pool.js.map +1 -0
- package/dist/cjs/web/provider/helpers.js +9 -0
- package/dist/cjs/web/provider/helpers.js.map +1 -0
- package/dist/cjs/web/provider/index.js +69 -0
- package/dist/cjs/web/provider/index.js.map +1 -0
- package/dist/cjs/web/provider/model.js +3 -0
- package/dist/cjs/web/provider/model.js.map +1 -0
- package/dist/cjs/web.js +8 -0
- package/dist/cjs/web.js.map +1 -0
- package/dist/mjs/{builder/helpers.js → helpers/builder.js} +2 -2
- package/dist/mjs/{builder/helpers.js.map → helpers/builder.js.map} +1 -1
- package/dist/mjs/helpers/pool.js +6 -0
- package/dist/mjs/helpers/pool.js.map +1 -0
- package/dist/mjs/node/builder/constants.js +13 -0
- package/dist/mjs/node/builder/constants.js.map +1 -0
- package/dist/mjs/node/builder/helpers.js +138 -0
- package/dist/mjs/node/builder/helpers.js.map +1 -0
- package/dist/mjs/node/builder/index.js +18 -0
- package/dist/mjs/node/builder/index.js.map +1 -0
- package/dist/mjs/node/index.js +119 -0
- package/dist/mjs/node/index.js.map +1 -0
- package/dist/mjs/node/pool.js +141 -0
- package/dist/mjs/node/pool.js.map +1 -0
- package/dist/mjs/node.js +2 -0
- package/dist/mjs/node.js.map +1 -0
- package/dist/mjs/types/helpers.js +8 -0
- package/dist/mjs/types/helpers.js.map +1 -0
- package/dist/mjs/types/node-omni-worker.js +2 -0
- package/dist/mjs/types/node-omni-worker.js.map +1 -0
- package/dist/mjs/types/web-omni-worker.js +2 -0
- package/dist/mjs/types/web-omni-worker.js.map +1 -0
- package/dist/mjs/web/builder/helpers.js +6 -0
- package/dist/mjs/web/builder/helpers.js.map +1 -0
- package/dist/mjs/web/builder/index.js +10 -0
- package/dist/mjs/web/builder/index.js.map +1 -0
- package/dist/mjs/web/builder/model.js +2 -0
- package/dist/mjs/web/builder/model.js.map +1 -0
- package/dist/mjs/web/index.js +120 -0
- package/dist/mjs/web/index.js.map +1 -0
- package/dist/mjs/web/pool.js +140 -0
- package/dist/mjs/web/pool.js.map +1 -0
- package/dist/mjs/web/provider/helpers.js +6 -0
- package/dist/mjs/web/provider/helpers.js.map +1 -0
- package/dist/mjs/web/provider/index.js +32 -0
- package/dist/mjs/web/provider/index.js.map +1 -0
- package/dist/mjs/web/provider/model.js +2 -0
- package/dist/mjs/web/provider/model.js.map +1 -0
- package/dist/mjs/web.js +3 -0
- package/dist/mjs/web.js.map +1 -0
- package/dist/types/{builder/helpers.d.ts → helpers/builder.d.ts} +1 -1
- package/dist/types/helpers/builder.d.ts.map +1 -0
- package/dist/types/helpers/pool.d.ts +2 -0
- package/dist/types/helpers/pool.d.ts.map +1 -0
- package/dist/types/node/builder/constants.d.ts +5 -0
- package/dist/types/node/builder/constants.d.ts.map +1 -0
- package/dist/types/node/builder/helpers.d.ts +2 -0
- package/dist/types/node/builder/helpers.d.ts.map +1 -0
- package/dist/types/node/builder/index.d.ts +8 -0
- package/dist/types/node/builder/index.d.ts.map +1 -0
- package/dist/types/node/index.d.ts +32 -0
- package/dist/types/node/index.d.ts.map +1 -0
- package/dist/types/node/pool.d.ts +31 -0
- package/dist/types/node/pool.d.ts.map +1 -0
- package/dist/types/node.d.ts +3 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/types/types/helpers.d.ts +6 -0
- package/dist/types/types/helpers.d.ts.map +1 -0
- package/dist/types/types/node-omni-worker.d.ts +90 -0
- package/dist/types/types/node-omni-worker.d.ts.map +1 -0
- package/dist/types/types/web-omni-worker.d.ts +103 -0
- package/dist/types/types/web-omni-worker.d.ts.map +1 -0
- package/dist/types/web/builder/helpers.d.ts +3 -0
- package/dist/types/web/builder/helpers.d.ts.map +1 -0
- package/dist/types/web/builder/index.d.ts +8 -0
- package/dist/types/web/builder/index.d.ts.map +1 -0
- package/dist/types/web/builder/model.d.ts +11 -0
- package/dist/types/web/builder/model.d.ts.map +1 -0
- package/dist/types/web/index.d.ts +35 -0
- package/dist/types/web/index.d.ts.map +1 -0
- package/dist/types/web/pool.d.ts +31 -0
- package/dist/types/web/pool.d.ts.map +1 -0
- package/dist/types/web/provider/helpers.d.ts +2 -0
- package/dist/types/web/provider/helpers.d.ts.map +1 -0
- package/dist/types/web/provider/index.d.ts +16 -0
- package/dist/types/web/provider/index.d.ts.map +1 -0
- package/dist/types/web/provider/model.d.ts +7 -0
- package/dist/types/web/provider/model.d.ts.map +1 -0
- package/dist/types/web.d.ts +4 -0
- package/dist/types/web.d.ts.map +1 -0
- package/package.json +37 -16
- package/dist/cjs/builder/node.js +0 -80
- package/dist/cjs/builder/node.js.map +0 -1
- package/dist/cjs/builder/plugins/external-imports.js +0 -44
- package/dist/cjs/builder/plugins/external-imports.js.map +0 -1
- package/dist/cjs/builder/plugins/native-module.js +0 -18
- package/dist/cjs/builder/plugins/native-module.js.map +0 -1
- package/dist/cjs/index.js +0 -84
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/types/omni-worker.js.map +0 -1
- package/dist/mjs/builder/node.js +0 -40
- package/dist/mjs/builder/node.js.map +0 -1
- package/dist/mjs/builder/plugins/external-imports.js +0 -39
- package/dist/mjs/builder/plugins/external-imports.js.map +0 -1
- package/dist/mjs/builder/plugins/native-module.js +0 -15
- package/dist/mjs/builder/plugins/native-module.js.map +0 -1
- package/dist/mjs/index.js +0 -44
- package/dist/mjs/index.js.map +0 -1
- package/dist/mjs/types/omni-worker.js +0 -2
- package/dist/mjs/types/omni-worker.js.map +0 -1
- package/dist/types/builder/helpers.d.ts.map +0 -1
- package/dist/types/builder/node.d.ts +0 -3
- package/dist/types/builder/node.d.ts.map +0 -1
- package/dist/types/builder/plugins/external-imports.d.ts +0 -4
- package/dist/types/builder/plugins/external-imports.d.ts.map +0 -1
- package/dist/types/builder/plugins/native-module.d.ts +0 -3
- package/dist/types/builder/plugins/native-module.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -26
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/types/omni-worker.d.ts +0 -21
- package/dist/types/types/omni-worker.d.ts.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAAU,EACV,OAAqC,EACyB,EAAE;IAEhE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC7C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAE/C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAI,MAAM,CAAC,CAAC;IAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAChC,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../src/web/builder/model.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
6
|
+
var _, done = false;
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
8
|
+
var context = {};
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
13
|
+
if (kind === "accessor") {
|
14
|
+
if (result === void 0) continue;
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
19
|
+
}
|
20
|
+
else if (_ = accept(result)) {
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
22
|
+
else descriptor[key] = _;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
26
|
+
done = true;
|
27
|
+
};
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
29
|
+
var useValue = arguments.length > 2;
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
32
|
+
}
|
33
|
+
return useValue ? value : void 0;
|
34
|
+
};
|
35
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
36
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
37
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
38
|
+
};
|
39
|
+
import * as Comlink from 'comlink/dist/esm/comlink';
|
40
|
+
import { staticImplements } from "../types/helpers";
|
41
|
+
import { buildWebApiAndWorker } from "./builder";
|
42
|
+
/**
|
43
|
+
* OmniWorker for the web
|
44
|
+
*/
|
45
|
+
let WebOmniWorker = (() => {
|
46
|
+
let _classDecorators = [staticImplements(), staticImplements()];
|
47
|
+
let _classDescriptor;
|
48
|
+
let _classExtraInitializers = [];
|
49
|
+
let _classThis;
|
50
|
+
var WebOmniWorker = _classThis = class {
|
51
|
+
constructor(url, options, worker, api) {
|
52
|
+
this.isInitialized = () => this._api !== undefined;
|
53
|
+
this.use = () => {
|
54
|
+
const isInitialized = this.isInitialized();
|
55
|
+
if (isInitialized) {
|
56
|
+
return this._api;
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
throw Error(`worker is not yet initialized. make sure to call the build() function, first`);
|
60
|
+
}
|
61
|
+
};
|
62
|
+
this.destroy = async () => {
|
63
|
+
var _a;
|
64
|
+
(_a = this._worker) === null || _a === void 0 ? void 0 : _a.terminate();
|
65
|
+
};
|
66
|
+
this.clone = (numOfTimes) => {
|
67
|
+
const workers = [];
|
68
|
+
const url = this._url;
|
69
|
+
const options = this._options;
|
70
|
+
for (let i = 0; i <= numOfTimes; i++) {
|
71
|
+
const { worker, api } = buildWebApiAndWorker(url, options);
|
72
|
+
workers.push(new WebOmniWorker(url, options, worker, api));
|
73
|
+
}
|
74
|
+
return workers;
|
75
|
+
};
|
76
|
+
this._url = url;
|
77
|
+
this._options = options;
|
78
|
+
this._worker = worker;
|
79
|
+
this._api = api;
|
80
|
+
return this;
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* Handles the building of the necessary resources for an OmniWorker to function.
|
84
|
+
* This usually means, building from the consumer's code, creating the comlink
|
85
|
+
* interface between the worker and the main thread as well as the worker itself.
|
86
|
+
*
|
87
|
+
* @param tsUrl A URL object linking to the worker .ts file
|
88
|
+
* @param options Builder options
|
89
|
+
* @returns A WebOmniWorker
|
90
|
+
*/
|
91
|
+
static async build(tsUrl, options = {
|
92
|
+
extension: '.js'
|
93
|
+
}) {
|
94
|
+
const { jsUrl, worker, api } = buildWebApiAndWorker(tsUrl, options);
|
95
|
+
return new WebOmniWorker(jsUrl, options, worker, api);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
__setFunctionName(_classThis, "WebOmniWorker");
|
99
|
+
(() => {
|
100
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
101
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
102
|
+
WebOmniWorker = _classThis = _classDescriptor.value;
|
103
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
104
|
+
})();
|
105
|
+
/**
|
106
|
+
* Expose the functions inside the worker to the rest of the application.
|
107
|
+
* After having exposed the functions, the build step can be initiated.
|
108
|
+
* @param exposable A class, object with functions or a single function to be
|
109
|
+
* exposed to the main thread.
|
110
|
+
*/
|
111
|
+
_classThis.expose = (exposable) => {
|
112
|
+
Comlink.expose(exposable);
|
113
|
+
};
|
114
|
+
(() => {
|
115
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
116
|
+
})();
|
117
|
+
return WebOmniWorker = _classThis;
|
118
|
+
})();
|
119
|
+
export { WebOmniWorker };
|
120
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAGjD;;GAEG;IAGU,aAAa;4BAFzB,gBAAgB,EAAc,EAC9B,gBAAgB,EAAc;;;;;QAO7B,YACE,GAAQ,EACR,OAAqC,EACrC,MAAc,EACd,GAA4B;YAsC9B,kBAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;YAE9C,QAAG,GAAG,GAAG,EAAE;gBACT,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;gBAC3C,IAAI,aAAa,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,IAAK,CAAC;gBACpB,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC,8EAA8E,CAAC,CAAC;gBAC9F,CAAC;Y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GAAG,CAAI,SAAY,EAAQ,EAAE;QAC/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,AAFmB,CAEnB;;QA3BU,uDAAa;;;;SAAb,aAAa"}
|
@@ -0,0 +1,140 @@
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
6
|
+
var _, done = false;
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
8
|
+
var context = {};
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
13
|
+
if (kind === "accessor") {
|
14
|
+
if (result === void 0) continue;
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
19
|
+
}
|
20
|
+
else if (_ = accept(result)) {
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
22
|
+
else descriptor[key] = _;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
26
|
+
done = true;
|
27
|
+
};
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
29
|
+
var useValue = arguments.length > 2;
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
32
|
+
}
|
33
|
+
return useValue ? value : void 0;
|
34
|
+
};
|
35
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
36
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
37
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
38
|
+
};
|
39
|
+
import { WebOmniWorker } from ".";
|
40
|
+
import { staticImplements } from "../types/helpers";
|
41
|
+
let WebOmniWorkerPool = (() => {
|
42
|
+
let _classDecorators = [staticImplements()];
|
43
|
+
let _classDescriptor;
|
44
|
+
let _classExtraInitializers = [];
|
45
|
+
let _classThis;
|
46
|
+
var WebOmniWorkerPool = _classThis = class {
|
47
|
+
constructor(from, options) {
|
48
|
+
this._pool = [];
|
49
|
+
this._count = 0;
|
50
|
+
this._lastUseIdx = -1;
|
51
|
+
this.isInitialized = () => this._count > 0;
|
52
|
+
this.getNumOfWorkers = () => this._count;
|
53
|
+
this.use = () => {
|
54
|
+
if (!this.isInitialized()) {
|
55
|
+
return this._from.use();
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
const lastIdx = this._lastUseIdx;
|
59
|
+
// first run or maxed out
|
60
|
+
if (lastIdx === this._count - 1 ||
|
61
|
+
lastIdx === -1) {
|
62
|
+
this._lastUseIdx = 0;
|
63
|
+
return this._pool[0].use();
|
64
|
+
// any other run
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
this._lastUseIdx = lastIdx + 1;
|
68
|
+
return this._pool[lastIdx + 1].use();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
};
|
72
|
+
this.destroy = async () => {
|
73
|
+
const fns = [];
|
74
|
+
this._pool.forEach(w => {
|
75
|
+
const fn = async () => {
|
76
|
+
await w.destroy();
|
77
|
+
};
|
78
|
+
fns.push(fn);
|
79
|
+
});
|
80
|
+
await Promise.all(fns.map(fn => fn()));
|
81
|
+
};
|
82
|
+
this._from = from;
|
83
|
+
this._options = options || { numOfWorkers: 1 };
|
84
|
+
this.applyOptions();
|
85
|
+
}
|
86
|
+
/**
|
87
|
+
* First builds the OmniWorkers and then launches a new WebOmniWorker pool
|
88
|
+
* @param url A URL with the relative file path to the worker .ts file
|
89
|
+
* @param options (Optional) Options object for launching the pool
|
90
|
+
*/
|
91
|
+
static async buildAndLaunch(url, options = {
|
92
|
+
extension: '.js',
|
93
|
+
numOfWorkers: (navigator === null || navigator === void 0 ? void 0 : navigator.hardwareConcurrency) || 1
|
94
|
+
}) {
|
95
|
+
const worker = await WebOmniWorker.build(url, options);
|
96
|
+
const pool = WebOmniWorkerPool.launch(worker, options);
|
97
|
+
return pool;
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* Launches a new WebOmniWorker pool according to the options provided
|
101
|
+
* @param worker An already built WebOmniWorker
|
102
|
+
* @returns A newly created pool
|
103
|
+
*/
|
104
|
+
static launch(worker, options) {
|
105
|
+
const pool = new WebOmniWorkerPool(worker, options);
|
106
|
+
return pool;
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* Applies the options provided
|
110
|
+
*/
|
111
|
+
applyOptions() {
|
112
|
+
const { numOfWorkers } = this._options;
|
113
|
+
let count = 0;
|
114
|
+
if (numOfWorkers === undefined) {
|
115
|
+
count = 1;
|
116
|
+
}
|
117
|
+
else {
|
118
|
+
count = numOfWorkers;
|
119
|
+
}
|
120
|
+
if (count < 1) {
|
121
|
+
throw Error(`number of workers must be at least 1`);
|
122
|
+
}
|
123
|
+
this._count = count;
|
124
|
+
for (let i = 0; i <= count; i++) {
|
125
|
+
this._pool = this._from.clone(count);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
};
|
129
|
+
__setFunctionName(_classThis, "WebOmniWorkerPool");
|
130
|
+
(() => {
|
131
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
132
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
133
|
+
WebOmniWorkerPool = _classThis = _classDescriptor.value;
|
134
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
135
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
136
|
+
})();
|
137
|
+
return WebOmniWorkerPool = _classThis;
|
138
|
+
})();
|
139
|
+
export { WebOmniWorkerPool };
|
140
|
+
//# sourceMappingURL=pool.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/web/pool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;IAIvC,iBAAiB;4BAD7B,gBAAgB,EAAe;;;;;QAS9B,YACE,IAAsB,EACtB,OAAgC;YAR1B,UAAK,GAAuB,EAAE,CAAC;YAG/B,WAAM,GAAW,CAAC,CAAC;YACnB,gBAAW,GAAW,CAAC,CAAC,CAAC;YA+D1B,kBAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAEtC,oBAAe,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;YAEpC,QAAG,GAAG,GAAG,EAAE;gBAChB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;oBAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;gBAC1B,CAAC;qBAAM,CAAC;oBACN,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC;oBAEjC,yBAAyB;oBACzB,IACE,O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AK,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { convertToJsUrl } from "./helpers";
|
2
|
+
/**
|
3
|
+
* This provider is needed, since most bundlers will "tree shake"
|
4
|
+
* out worker files that are not imported. The reason for that,
|
5
|
+
* is that worker files aren't supposed to be imported.
|
6
|
+
* This wrapper function quickly imports the worker, before building
|
7
|
+
* it.
|
8
|
+
*
|
9
|
+
* @param tsUrl A URL object linking a worker .ts file, created using
|
10
|
+
* new URL('/path/to/your/file.ts', import.meta.url)
|
11
|
+
* @param options Optional options for the provisioning
|
12
|
+
* @returns A callback function, returning the the .js URL for building
|
13
|
+
* the worker
|
14
|
+
*/
|
15
|
+
export const provideWorker = (tsUrl, options = {
|
16
|
+
extension: '.js'
|
17
|
+
}) => {
|
18
|
+
const jsUrl = convertToJsUrl(tsUrl, options.extension);
|
19
|
+
return () => {
|
20
|
+
const loadModule = (async () => {
|
21
|
+
try {
|
22
|
+
import(jsUrl.href);
|
23
|
+
}
|
24
|
+
catch (e) {
|
25
|
+
console.warn(e);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
loadModule();
|
29
|
+
return jsUrl;
|
30
|
+
};
|
31
|
+
};
|
32
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAU,EACV,UAAiC;IAC/B,SAAS,EAAE,KAAK;CACjB,EACD,EAAE;IAEF,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAEvD,OAAO,GAAQ,EAAE;QACf,MAAM,UAAU,GAAG,CAAC,KAAK,IAAI,EAAE;YAC7B,IAAI,CAAC;gBACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;YAAC,OAAM,CAAC,EAAE,CAAC;gBACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,UAAU,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC,CAAA;AACH,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../../src/web/provider/model.ts"],"names":[],"mappings":""}
|
package/dist/mjs/web.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,aAAa,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EAClB,MAAM,YAAY,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
1
|
export declare function getCallerDir(): string;
|
2
|
-
//# sourceMappingURL=
|
2
|
+
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/helpers/builder.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,WAa3B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/helpers/pool.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,qBAItB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/node/builder/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,MAAO,YAAY,CAAC;AAE7B,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,eAGlC,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,eAMnC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/node/builder/helpers.ts"],"names":[],"mappings":"AAWA,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,mBAoChD"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import Comlink from 'comlink';
|
2
|
+
import { Worker as ThreadWorker } from 'worker_threads';
|
3
|
+
export declare const genWorkerCodeFromFile: (workerPath: string) => Promise<string>;
|
4
|
+
export declare const buildNodeApiAndWorkerFromCode: <T>(code: string) => {
|
5
|
+
worker: ThreadWorker;
|
6
|
+
api: Comlink.RemoteObject<T>;
|
7
|
+
};
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/node/builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAMxD,eAAO,MAAM,qBAAqB,eACpB,MAAM,KACjB,OAAO,CAAC,MAAM,CAKhB,CAAA;AAED,eAAO,MAAM,6BAA6B,GAAI,CAAC,QACvC,MAAM,KACX;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;CAMtD,CAAA"}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { IOmniWorker, IPoolable } from '../types/node-omni-worker';
|
2
|
+
import Comlink from 'comlink';
|
3
|
+
/**
|
4
|
+
* OmniWorker for NodeJS
|
5
|
+
*/
|
6
|
+
export declare class NodeOmniWorker<T> implements IOmniWorker<T>, IPoolable<T> {
|
7
|
+
private _code;
|
8
|
+
private _worker;
|
9
|
+
private _api;
|
10
|
+
private constructor();
|
11
|
+
/**
|
12
|
+
* Expose the functions inside the worker to the rest of the application.
|
13
|
+
* After having exposed the functions, the build step can be initiated.
|
14
|
+
* @param exposable A class, object with functions or a single function to be
|
15
|
+
* exposed to the main thread.
|
16
|
+
*/
|
17
|
+
static expose: <T_1>(exposable: T_1) => void;
|
18
|
+
/**
|
19
|
+
* Handles the building of the necessary resources for an OmniWorker to function.
|
20
|
+
* This usually means, building from the consumer's code, creating the comlink
|
21
|
+
* interface between the worker and the main thread as well as the worker itself.
|
22
|
+
*
|
23
|
+
* @param path Relative path FROM YOUR PROJECT's ROOT to the file to be the worker
|
24
|
+
* @returns An OmniWorker
|
25
|
+
*/
|
26
|
+
static build<T>(path: string): Promise<NodeOmniWorker<T>>;
|
27
|
+
isInitialized: () => boolean;
|
28
|
+
use: () => Comlink.RemoteObject<T>;
|
29
|
+
clone: (numOfTimes: number) => NodeOmniWorker<T>[];
|
30
|
+
destroy: () => Promise<void>;
|
31
|
+
}
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,WAAW,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3F,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B;;GAEG;AACH,qBAEa,cAAc,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAEpE,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,IAAI,CAA0B;IAEtC,OAAO;IAWP;;;;;OAKG;IACH,OAAc,MAAM,mBAAkB,GAAC,UAItC;IAED;;;;;;;OAOG;WACiB,KAAK,CAAC,CAAC,EACzB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAMtB,aAAa,QAAO,OAAO,CAEhC;IAEK,GAAG,gCAOT;IAEM,KAAK,eAAgB,MAAM,yBAQjC;IAEM,OAAO,sBAEb;CACF"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { NodeOmniWorker } from ".";
|
2
|
+
import { IOmniWorkerPool, IOmniWorkerPoolOptions } from "../types/node-omni-worker";
|
3
|
+
export declare class NodeOmniWorkerPool<T> implements IOmniWorkerPool<T> {
|
4
|
+
private _pool;
|
5
|
+
private _from;
|
6
|
+
private _options;
|
7
|
+
private _count;
|
8
|
+
private _lastUseIdx;
|
9
|
+
private constructor();
|
10
|
+
/**
|
11
|
+
* First builds the OmniWorkers and then launches a new NodeOmniWorker pool
|
12
|
+
* @param from The (relative) file path from your project's root to the worker .ts file
|
13
|
+
* @param options (Optional) Options object for launching the pool
|
14
|
+
*/
|
15
|
+
static buildAndLaunch<T>(from: string, options?: IOmniWorkerPoolOptions): Promise<NodeOmniWorkerPool<T>>;
|
16
|
+
/**
|
17
|
+
* Launches a new NodeOmniWorker pool according to the options provided
|
18
|
+
* @param worker An already built NodeOmniWorker
|
19
|
+
* @returns A newly created pool
|
20
|
+
*/
|
21
|
+
static launch<T>(worker: NodeOmniWorker<T>, options?: IOmniWorkerPoolOptions): NodeOmniWorkerPool<T>;
|
22
|
+
/**
|
23
|
+
* Applies the options provided
|
24
|
+
*/
|
25
|
+
private applyOptions;
|
26
|
+
isInitialized: () => boolean;
|
27
|
+
getNumOfWorkers: () => number;
|
28
|
+
use: () => import("comlink").RemoteObject<T>;
|
29
|
+
destroy: () => Promise<void>;
|
30
|
+
}
|
31
|
+
//# sourceMappingURL=pool.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/node/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAe,MAAM,2BAA2B,CAAC;AAEjG,qBACa,kBAAkB,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAE9D,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAc;IAEjC,OAAO;IASP;;;;OAIG;WACiB,cAAc,CAAC,CAAC,EAClC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,sBAER,GACA,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAMjC;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EACb,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,OAAO,GAAE,sBAER,GACA,kBAAkB,CAAC,CAAC,CAAC;IAKxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBb,aAAa,gBAAyB;IAEtC,eAAe,eAAqB;IAEpC,GAAG,0CAoBT;IAEM,OAAO,sBASb;CACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,cAAc,EACf,MAAM,cAAc,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,MACtB,CAAC,SAAS,CAAC,eAAe,CAAC,UACtC"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { RemoteObject } from 'comlink/dist/umd/comlink';
|
2
|
+
/**
|
3
|
+
* The base Interface for all workers
|
4
|
+
*/
|
5
|
+
export interface IOmniWorker<T> {
|
6
|
+
/**
|
7
|
+
* Use this function to see if the worker(pool) was successfully initialized
|
8
|
+
*
|
9
|
+
* @returns A boolean on whether or not the OmniWorker was successfully initialized
|
10
|
+
*/
|
11
|
+
isInitialized: () => boolean;
|
12
|
+
/**
|
13
|
+
* Will let you use the worker functions that were exposed from inside the worker(pool).
|
14
|
+
* Please not that since using the worker, all your functions will now return
|
15
|
+
* asynchronously (Promise<T>).
|
16
|
+
*
|
17
|
+
* @returns An object with the worker functions that were exposed from the worker
|
18
|
+
*/
|
19
|
+
use: () => RemoteObject<T>;
|
20
|
+
/**
|
21
|
+
* Terminates the underlying worker(s)
|
22
|
+
*/
|
23
|
+
destroy: () => Promise<void>;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Defines whether the class is buildable, meaning that class can be made into
|
27
|
+
* a NodeOmniWorker type.
|
28
|
+
*/
|
29
|
+
export interface IBuildable {
|
30
|
+
build: <T>(path: string) => Promise<IOmniWorker<T>>;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Defines whether the class can expose code from the module user to the main thread.
|
34
|
+
*/
|
35
|
+
export interface IExposable {
|
36
|
+
expose: <T>(exposable: T) => void;
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* A pool with multiple OmniWorkers
|
40
|
+
*/
|
41
|
+
export interface IOmniWorkerPool<T> extends IOmniWorker<T> {
|
42
|
+
/**
|
43
|
+
* Retrieves the number of workers that were initialized for the pool
|
44
|
+
*/
|
45
|
+
getNumOfWorkers: () => number;
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Determines whether an OmniWorker pool is able to build and launch
|
49
|
+
* OmniWorkers
|
50
|
+
*/
|
51
|
+
export interface ILaunchable {
|
52
|
+
/**
|
53
|
+
* First builds the OmniWorkers and then launches a new OmniWorker pool
|
54
|
+
* @param from The (relative) file path from your project's root to the worker .ts file
|
55
|
+
* @param options (Optional) Options object for launching the pool
|
56
|
+
*/
|
57
|
+
buildAndLaunch<T>(from: string, options?: IOmniWorkerPoolOptions): Promise<IOmniWorkerPool<T>>;
|
58
|
+
/**
|
59
|
+
* Launches a new OmniWorker pool according to the options provided
|
60
|
+
* @param worker An already built OmniWorker
|
61
|
+
* @returns A newly created pool
|
62
|
+
*/
|
63
|
+
launch<T extends object>(worker: IOmniWorker<T>, options?: IOmniWorkerPoolOptions): IOmniWorkerPool<T>;
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* Whether an IOmniWorker is able to be pooled
|
67
|
+
*/
|
68
|
+
export interface IPoolable<T> {
|
69
|
+
/**
|
70
|
+
* Clone an OmniWorker as many times as specified
|
71
|
+
* @param numOfTimes how many times the item should be cloned
|
72
|
+
* @returns a collection of OmniWorkers
|
73
|
+
*/
|
74
|
+
clone: (numOfTimes: number) => IOmniWorker<T>[];
|
75
|
+
}
|
76
|
+
/**
|
77
|
+
* Options for instantiation of a OmniWorkerPool
|
78
|
+
*/
|
79
|
+
export interface IPoolOptions {
|
80
|
+
/**
|
81
|
+
* The desired number of workers to be launched
|
82
|
+
*/
|
83
|
+
numOfWorkers?: number;
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* The options for instantiating an OmniWorker pool
|
87
|
+
*/
|
88
|
+
export interface IOmniWorkerPoolOptions extends IPoolOptions {
|
89
|
+
}
|
90
|
+
//# sourceMappingURL=node-omni-worker.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"node-omni-worker.d.ts","sourceRoot":"","sources":["../../../src/types/node-omni-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;EAEE;AACF,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B;;;;OAIG;IACH,aAAa,EAAE,MAAM,OAAO,CAAA;IAE5B;;;;;;OAMG;IACH,GAAG,EAAE,MAAM,YAAY,CAAC,CAAC,CAAC,CAAA;IAE1B;;OAEG;IACH,OAAO,EAAE,MAA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