@atolljs/core 0.1.0 → 0.1.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 +167 -61
- package/dist/contract/listSchema.d.ts +47 -0
- package/dist/contract/msgpackCodec.d.ts +7 -0
- package/dist/contract/msgpackrCodec.d.ts +2 -0
- package/dist/contract/mz.d.ts +43 -0
- package/dist/contract/sharedMemory.d.ts +350 -0
- package/dist/contract/types.d.ts +131 -0
- package/dist/contract/zod.d.ts +53 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +18 -18
- package/dist/index10.js +14 -178
- package/dist/index11.js +188 -47
- package/dist/index12.js +45 -59
- package/dist/index13.js +59 -20
- package/dist/index14.js +24 -60
- package/dist/index15.js +56 -43
- package/dist/index16.js +45 -41
- package/dist/index17.js +42 -38
- package/dist/index18.js +36 -55
- package/dist/index19.js +52 -47
- package/dist/index20.js +48 -51
- package/dist/index21.js +59 -0
- package/dist/index3.js +24 -117
- package/dist/index4.js +116 -34
- package/dist/index5.js +32 -473
- package/dist/index6.js +489 -19
- package/dist/index7.js +19 -6
- package/dist/index8.js +6 -33
- package/dist/index9.js +29 -14
- package/dist/log.d.ts +35 -0
- package/dist/observable.d.ts +30 -0
- package/dist/pool/errors.d.ts +16 -0
- package/dist/pool/memory.d.ts +19 -0
- package/dist/pool/workerClient.d.ts +80 -0
- package/dist/pool/workerPool.d.ts +115 -0
- package/dist/reactive.d.ts +46 -0
- package/dist/service.d.ts +181 -0
- package/dist/shared/sharedWorkerClient.d.ts +35 -0
- package/dist/shared/sharedWorkerHost.d.ts +21 -0
- package/dist/task.d.ts +40 -0
- package/dist/worker/defineWorker.d.ts +63 -0
- package/dist/worker/registry.d.ts +8 -0
- package/dist/worker/workerBootstrap.d.ts +1 -0
- package/package.json +17 -2
- package/src/contract/listSchema.ts +13 -8
- package/src/contract/mz.ts +1 -1
- package/src/contract/sharedMemory.ts +28 -1
- package/src/contract/types.ts +21 -0
- package/src/contract/zod.ts +44 -0
- package/src/index.ts +2 -1
- package/src/pool/workerPool.ts +27 -1
package/dist/index14.js
CHANGED
|
@@ -1,63 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
if (r?.type === "EXECUTE_TASK") {
|
|
26
|
-
let { messageId: n, taskId: s, args: c } = r;
|
|
27
|
-
if (!o) {
|
|
28
|
-
e.postMessage({
|
|
29
|
-
messageId: n,
|
|
30
|
-
success: !1,
|
|
31
|
-
error: "Shared memory not initialized in worker."
|
|
32
|
-
});
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
let l = performance.now();
|
|
36
|
-
try {
|
|
37
|
-
let r = await i.execute(s, ...c || []);
|
|
38
|
-
a.debug(`task ${s} → ${(performance.now() - l).toFixed(1)}ms (client #${t})`), e.postMessage({
|
|
39
|
-
messageId: n,
|
|
40
|
-
success: !0,
|
|
41
|
-
result: r
|
|
42
|
-
});
|
|
43
|
-
} catch (t) {
|
|
44
|
-
a.warn(`task ${s} failed: ${t.message || String(t)}`), e.postMessage({
|
|
45
|
-
messageId: n,
|
|
46
|
-
success: !1,
|
|
47
|
-
error: t.message || String(t)
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
r?.type === "SHARED_DISCONNECT" && (e.close(), a.info(`client #${t} disconnected`));
|
|
53
|
-
}, e.start();
|
|
54
|
-
}
|
|
55
|
-
function u() {
|
|
56
|
-
self.onconnect = (e) => {
|
|
57
|
-
l(e.ports[0]);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
1
|
+
import { scoped as e } from "./index5.js";
|
|
2
|
+
//#region src/worker/registry.ts
|
|
3
|
+
var t = e("registry"), n = class {
|
|
4
|
+
static tasks = /* @__PURE__ */ new Map();
|
|
5
|
+
static register(e, n) {
|
|
6
|
+
this.tasks.set(e.taskId, {
|
|
7
|
+
contract: e,
|
|
8
|
+
handler: n
|
|
9
|
+
}), t.debug(`registered "${e.taskId}"`, {
|
|
10
|
+
args: e.argsSchema ? "validated" : "unvalidated",
|
|
11
|
+
result: e.resultSchema ? "validated" : "unvalidated"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
static getContract(e) {
|
|
15
|
+
return this.tasks.get(e)?.contract;
|
|
16
|
+
}
|
|
17
|
+
static async execute(e, ...t) {
|
|
18
|
+
let n = this.tasks.get(e);
|
|
19
|
+
if (!n) throw Error(`Task handler not found for id: ${e}`);
|
|
20
|
+
let { contract: r, handler: i } = n, a = await i(...r.argsSchema ? r.argsSchema.parse(t) : t);
|
|
21
|
+
return r.resultSchema ? r.resultSchema.parse(a) : a;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
60
24
|
//#endregion
|
|
61
|
-
export {
|
|
25
|
+
export { n as TaskRegistry };
|
|
62
26
|
|
|
63
27
|
//# sourceMappingURL=index14.js.map
|
package/dist/index15.js
CHANGED
|
@@ -1,50 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { fmtBytes as e, scoped as t } from "./index5.js";
|
|
2
|
+
import { bindSharedMemories as n } from "./index6.js";
|
|
3
|
+
import { MemoryManager as r } from "./index9.js";
|
|
4
|
+
import { TaskRegistry as i } from "./index14.js";
|
|
5
|
+
//#region src/shared/sharedWorkerHost.ts
|
|
6
|
+
var a = t("shared-worker"), o = null, s = 0;
|
|
7
|
+
function c(t, i) {
|
|
8
|
+
if (o) return o.buffer.byteLength < t && a.warn(`client requested ${e(t)} but buffer is ${e(o.buffer.byteLength)} — first client's capacity wins`), o;
|
|
9
|
+
let s = new r(i);
|
|
10
|
+
return s.ensureCapacity(t), o = s.memory, n(s.getBuffer()), a.info(`shared buffer allocated (${e(o.buffer.byteLength)})`), o;
|
|
7
11
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
12
|
+
function l(e) {
|
|
13
|
+
let t = ++s;
|
|
14
|
+
a.info(`client #${t} connected`), e.onmessage = async (n) => {
|
|
15
|
+
let r = n.data;
|
|
16
|
+
if (r?.type === "SHARED_CONNECT") {
|
|
17
|
+
let n = c(r.memoryBytes ?? 0, r.memory);
|
|
18
|
+
e.postMessage({
|
|
19
|
+
type: "SHARED_MEMORY",
|
|
20
|
+
buffer: n.buffer,
|
|
21
|
+
clientIndex: t
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (r?.type === "EXECUTE_TASK") {
|
|
26
|
+
let { messageId: n, taskId: s, args: c } = r;
|
|
27
|
+
if (!o) {
|
|
28
|
+
e.postMessage({
|
|
29
|
+
messageId: n,
|
|
30
|
+
success: !1,
|
|
31
|
+
error: "Shared memory not initialized in worker."
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let l = performance.now();
|
|
36
|
+
try {
|
|
37
|
+
let r = await i.execute(s, ...c || []);
|
|
38
|
+
a.debug(`task ${s} → ${(performance.now() - l).toFixed(1)}ms (client #${t})`), e.postMessage({
|
|
39
|
+
messageId: n,
|
|
40
|
+
success: !0,
|
|
41
|
+
result: r
|
|
42
|
+
});
|
|
43
|
+
} catch (t) {
|
|
44
|
+
a.warn(`task ${s} failed: ${t.message || String(t)}`), e.postMessage({
|
|
45
|
+
messageId: n,
|
|
46
|
+
success: !1,
|
|
47
|
+
error: t.message || String(t)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
r?.type === "SHARED_DISCONNECT" && (e.close(), a.info(`client #${t} disconnected`));
|
|
53
|
+
}, e.start();
|
|
10
54
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let t = "def" in i ? i.def : i;
|
|
15
|
-
n[r] = {
|
|
16
|
-
taskId: t.taskId ?? `${e}.${r}`,
|
|
17
|
-
...t.dataType ? { dataType: t.dataType } : {},
|
|
18
|
-
...t.argsSchema ? { argsSchema: t.argsSchema } : {},
|
|
19
|
-
...t.resultSchema ? { resultSchema: t.resultSchema } : {}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
name: e,
|
|
24
|
-
tasks: n
|
|
55
|
+
function u() {
|
|
56
|
+
self.onconnect = (e) => {
|
|
57
|
+
l(e.ports[0]);
|
|
25
58
|
};
|
|
26
59
|
}
|
|
27
|
-
function o(e, r) {
|
|
28
|
-
let i = Object.keys(e.tasks).filter((e) => {
|
|
29
|
-
let t = r[e];
|
|
30
|
-
return typeof t != "function" && typeof t?.run != "function";
|
|
31
|
-
});
|
|
32
|
-
if (i.length > 0) throw Error(`implementService("${e.name}"): missing handlers for ${i.join(", ")}`);
|
|
33
|
-
for (let [n, i] of Object.entries(e.tasks)) {
|
|
34
|
-
let e = r[n];
|
|
35
|
-
t.register(i, typeof e == "function" ? e.bind(r) : e.run.bind(e));
|
|
36
|
-
}
|
|
37
|
-
return n.info(`service "${e.name}" implemented — ${Object.keys(e.tasks).join(", ")}`), {
|
|
38
|
-
service: e,
|
|
39
|
-
handlers: r
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function s(e, t) {
|
|
43
|
-
let n = {};
|
|
44
|
-
for (let [r, i] of Object.entries(e.tasks)) n[r] = (...e) => t.runTask(i, ...e);
|
|
45
|
-
return n;
|
|
46
|
-
}
|
|
47
60
|
//#endregion
|
|
48
|
-
export {
|
|
61
|
+
export { l as attachSharedPort, u as sharedWorkerHost };
|
|
49
62
|
|
|
50
63
|
//# sourceMappingURL=index15.js.map
|
package/dist/index16.js
CHANGED
|
@@ -1,46 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { scoped as e } from "./index5.js";
|
|
2
|
+
import { TaskRegistry as t } from "./index14.js";
|
|
3
|
+
//#region src/service.ts
|
|
4
|
+
var n = e("service");
|
|
5
|
+
function r(e = {}) {
|
|
6
|
+
return e;
|
|
7
|
+
}
|
|
8
|
+
function i(e) {
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function a(e, t) {
|
|
12
|
+
let n = {};
|
|
13
|
+
for (let [r, i] of Object.entries(t)) {
|
|
14
|
+
let t = "def" in i ? i.def : i;
|
|
15
|
+
n[r] = {
|
|
16
|
+
taskId: t.taskId ?? `${e}.${r}`,
|
|
17
|
+
...t.dataType ? { dataType: t.dataType } : {},
|
|
18
|
+
...t.argsSchema ? { argsSchema: t.argsSchema } : {},
|
|
19
|
+
...t.resultSchema ? { resultSchema: t.resultSchema } : {}
|
|
20
|
+
};
|
|
11
21
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
n
|
|
15
|
-
|
|
22
|
+
return {
|
|
23
|
+
name: e,
|
|
24
|
+
tasks: n
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function o(e, r) {
|
|
28
|
+
let i = Object.keys(e.tasks).filter((e) => {
|
|
29
|
+
let t = r[e];
|
|
30
|
+
return typeof t != "function" && typeof t?.run != "function";
|
|
31
|
+
});
|
|
32
|
+
if (i.length > 0) throw Error(`implementService("${e.name}"): missing handlers for ${i.join(", ")}`);
|
|
33
|
+
for (let [n, i] of Object.entries(e.tasks)) {
|
|
34
|
+
let e = r[n];
|
|
35
|
+
t.register(i, typeof e == "function" ? e.bind(r) : e.run.bind(e));
|
|
16
36
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let r = performance.now();
|
|
28
|
-
try {
|
|
29
|
-
let o = await i.execute(t, ...n || []);
|
|
30
|
-
a.debug(`task ${t} → ${(performance.now() - r).toFixed(1)}ms`), self.postMessage({
|
|
31
|
-
messageId: e,
|
|
32
|
-
success: !0,
|
|
33
|
-
result: o
|
|
34
|
-
});
|
|
35
|
-
} catch (n) {
|
|
36
|
-
a.warn(`task ${t} failed: ${n.message || String(n)}`), self.postMessage({
|
|
37
|
-
messageId: e,
|
|
38
|
-
success: !1,
|
|
39
|
-
error: n.message || String(n)
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
37
|
+
return n.info(`service "${e.name}" implemented — ${Object.keys(e.tasks).join(", ")}`), {
|
|
38
|
+
service: e,
|
|
39
|
+
handlers: r
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function s(e, t) {
|
|
43
|
+
let n = {};
|
|
44
|
+
for (let [r, i] of Object.entries(e.tasks)) n[r] = (...e) => t.runTask(i, ...e);
|
|
45
|
+
return n;
|
|
46
|
+
}
|
|
44
47
|
//#endregion
|
|
48
|
+
export { s as createClient, a as defineService, o as implementService, r as rpc, i as serviceMethod };
|
|
45
49
|
|
|
46
50
|
//# sourceMappingURL=index16.js.map
|
package/dist/index17.js
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import "./
|
|
4
|
-
//#region src/worker/
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"with"
|
|
12
|
-
], i = (e) => typeof e == "object" && !!e && "run" in e, a = new Set(r);
|
|
13
|
-
function o(e) {
|
|
14
|
-
let r = e.methods ?? {}, o = e.services ?? {}, s = 0, c = (e, n, r, o) => {
|
|
15
|
-
if (a.has(n)) throw Error(`defineWorker: "${n}" is reserved for the client API — rename the method`);
|
|
16
|
-
if (i(r)) {
|
|
17
|
-
let { def: n } = r;
|
|
18
|
-
t.register({
|
|
19
|
-
taskId: n.taskId ?? e,
|
|
20
|
-
...n.dataType ? { dataType: n.dataType } : {},
|
|
21
|
-
...n.argsSchema ? { argsSchema: n.argsSchema } : {},
|
|
22
|
-
...n.resultSchema ? { resultSchema: n.resultSchema } : {}
|
|
23
|
-
}, r.run.bind(r));
|
|
24
|
-
} else t.register({ taskId: e }, r.bind(o));
|
|
25
|
-
s++;
|
|
26
|
-
};
|
|
27
|
-
for (let [e, t] of Object.entries(r)) c(e, e, t, r);
|
|
28
|
-
for (let [e, t] of Object.entries(o)) {
|
|
29
|
-
if (a.has(e)) throw Error(`defineWorker: service name "${e}" is reserved for the client API — rename it`);
|
|
30
|
-
for (let [n, r] of Object.entries(t)) c(`${e}.${n}`, n, r, t);
|
|
1
|
+
import { fmtBytes as e, scoped as t } from "./index5.js";
|
|
2
|
+
import { bindSharedMemories as n, getDefinedSharedMemoryCount as r } from "./index6.js";
|
|
3
|
+
import { TaskRegistry as i } from "./index14.js";
|
|
4
|
+
//#region src/worker/workerBootstrap.ts
|
|
5
|
+
var a = t("worker"), o = !1;
|
|
6
|
+
typeof self > "u" ? a.warn("workerBootstrap: no worker global found — skipping message wiring") : self.onmessage = async (t) => {
|
|
7
|
+
let s = t.data;
|
|
8
|
+
if (s.type === "INIT") {
|
|
9
|
+
o = !0, r() > 0 && a.warn("pool sent INIT without memory, but shared-memory contracts are defined — field access will throw until bound"), a.info("initialized (message-only pool — no shared memory)");
|
|
10
|
+
return;
|
|
31
11
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
12
|
+
if (s.type === "INIT_MEMORY") {
|
|
13
|
+
let t = s.memory;
|
|
14
|
+
n(t.buffer), o = !0, a.info(`shared memory initialized (${e(t.buffer.byteLength)})`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (s.type === "EXECUTE_TASK") {
|
|
18
|
+
let { messageId: e, taskId: t, args: n } = s;
|
|
19
|
+
if (!o) {
|
|
20
|
+
a.warn(`rejected ${t} — shared memory not initialized`), self.postMessage({
|
|
21
|
+
messageId: e,
|
|
22
|
+
success: !1,
|
|
23
|
+
error: "Shared memory not initialized in worker."
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let r = performance.now();
|
|
28
|
+
try {
|
|
29
|
+
let o = await i.execute(t, ...n || []);
|
|
30
|
+
a.debug(`task ${t} → ${(performance.now() - r).toFixed(1)}ms`), self.postMessage({
|
|
31
|
+
messageId: e,
|
|
32
|
+
success: !0,
|
|
33
|
+
result: o
|
|
34
|
+
});
|
|
35
|
+
} catch (n) {
|
|
36
|
+
a.warn(`task ${t} failed: ${n.message || String(n)}`), self.postMessage({
|
|
37
|
+
messageId: e,
|
|
38
|
+
success: !1,
|
|
39
|
+
error: n.message || String(n)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
39
44
|
//#endregion
|
|
40
|
-
export { r as RESERVED_CLIENT_KEYS, o as defineWorker };
|
|
41
45
|
|
|
42
46
|
//# sourceMappingURL=index17.js.map
|
package/dist/index18.js
CHANGED
|
@@ -1,61 +1,42 @@
|
|
|
1
|
-
import { scoped as e } from "./
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
o.async && await o.value, i = Atomics.load(t.view, t.index), n || (a.trace(`remote write observed (offset ${e.byteOffset})`), r());
|
|
27
|
-
}
|
|
28
|
-
a.debug(`stopped observing (offset ${e.byteOffset})`);
|
|
29
|
-
})(), () => {
|
|
30
|
-
n = !0;
|
|
31
|
-
};
|
|
32
|
-
a.warn(`Atomics.waitAsync unavailable — observing via 50ms poll (offset ${e.byteOffset})`);
|
|
33
|
-
let o = setInterval(() => {
|
|
34
|
-
let e = Atomics.load(t.view, t.index);
|
|
35
|
-
e !== i && (i = e, r());
|
|
36
|
-
}, 50);
|
|
37
|
-
return () => {
|
|
38
|
-
n = !0, clearInterval(o);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
1
|
+
import { scoped as e } from "./index5.js";
|
|
2
|
+
import { TaskRegistry as t } from "./index14.js";
|
|
3
|
+
import "./index17.js";
|
|
4
|
+
//#region src/worker/defineWorker.ts
|
|
5
|
+
var n = e("worker"), r = [
|
|
6
|
+
"start",
|
|
7
|
+
"terminate",
|
|
8
|
+
"pool",
|
|
9
|
+
"sharedMemory",
|
|
10
|
+
"then",
|
|
11
|
+
"with"
|
|
12
|
+
], i = (e) => typeof e == "object" && !!e && "run" in e, a = new Set(r);
|
|
13
|
+
function o(e) {
|
|
14
|
+
let r = e.methods ?? {}, o = e.services ?? {}, s = 0, c = (e, n, r, o) => {
|
|
15
|
+
if (a.has(n)) throw Error(`defineWorker: "${n}" is reserved for the client API — rename the method`);
|
|
16
|
+
if (i(r)) {
|
|
17
|
+
let { def: n } = r;
|
|
18
|
+
t.register({
|
|
19
|
+
taskId: n.taskId ?? e,
|
|
20
|
+
...n.dataType ? { dataType: n.dataType } : {},
|
|
21
|
+
...n.argsSchema ? { argsSchema: n.argsSchema } : {},
|
|
22
|
+
...n.resultSchema ? { resultSchema: n.resultSchema } : {}
|
|
23
|
+
}, r.run.bind(r));
|
|
24
|
+
} else t.register({ taskId: e }, r.bind(o));
|
|
25
|
+
s++;
|
|
41
26
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let r
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return t !== void 0 && u(t, e), t;
|
|
52
|
-
}), e;
|
|
53
|
-
});
|
|
54
|
-
return a.debug(`watching connector at offset ${e.byteOffset}`), () => {
|
|
55
|
-
a.debug(`watch stopped (offset ${e.byteOffset})`), f(), p();
|
|
27
|
+
for (let [e, t] of Object.entries(r)) c(e, e, t, r);
|
|
28
|
+
for (let [e, t] of Object.entries(o)) {
|
|
29
|
+
if (a.has(e)) throw Error(`defineWorker: service name "${e}" is reserved for the client API — rename it`);
|
|
30
|
+
for (let [n, r] of Object.entries(t)) c(`${e}.${n}`, n, r, t);
|
|
31
|
+
}
|
|
32
|
+
n.info(`worker defined — ${s} method(s)`);
|
|
33
|
+
let l = {
|
|
34
|
+
methods: r,
|
|
35
|
+
services: o
|
|
56
36
|
};
|
|
37
|
+
return e.sharedMemory && (l.sharedMemory = e.sharedMemory), l;
|
|
57
38
|
}
|
|
58
39
|
//#endregion
|
|
59
|
-
export {
|
|
40
|
+
export { r as RESERVED_CLIENT_KEYS, o as defineWorker };
|
|
60
41
|
|
|
61
42
|
//# sourceMappingURL=index18.js.map
|
package/dist/index19.js
CHANGED
|
@@ -1,56 +1,61 @@
|
|
|
1
|
-
import { scoped as e } from "./
|
|
2
|
-
import {
|
|
3
|
-
//#region src/
|
|
4
|
-
var
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
d = null, h();
|
|
14
|
-
});
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
u = t(i, o, (e) => {
|
|
18
|
-
if (c === void 0 || !s(c, e)) {
|
|
19
|
-
c = e;
|
|
20
|
-
for (let t of m) t(e);
|
|
21
|
-
}
|
|
22
|
-
}, a), p = i, f ??= e.onBound(() => {
|
|
23
|
-
let t;
|
|
24
|
-
try {
|
|
25
|
-
t = e.connector(String(r));
|
|
26
|
-
} catch {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
t !== p && (u?.(), u = null, p = null, h());
|
|
30
|
-
}), n.debug(`observing "${String(r)}" (offset ${i.byteOffset})`);
|
|
31
|
-
}, g = () => {
|
|
32
|
-
u?.(), u = null, p = null, d?.(), d = null, f?.(), f = null;
|
|
33
|
-
};
|
|
1
|
+
import { scoped as e } from "./index5.js";
|
|
2
|
+
import { createEffect as t, createMemo as n, createRoot as r, createSignal as i } from "solid-js";
|
|
3
|
+
//#region src/reactive.ts
|
|
4
|
+
var a = e("reactive");
|
|
5
|
+
function o(e, t) {
|
|
6
|
+
if (e === t) return !0;
|
|
7
|
+
if (e == null || t == null) return !1;
|
|
8
|
+
let n = Object.keys(e), r = Object.keys(t);
|
|
9
|
+
return n.length === r.length && n.every((n) => Object.is(e[n], t[n]));
|
|
10
|
+
}
|
|
11
|
+
function s(e) {
|
|
12
|
+
let [t, n] = i(e.read(), { equals: !1 }), r = () => n(() => e.read());
|
|
34
13
|
return {
|
|
35
|
-
get
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
l = n;
|
|
40
|
-
let e = o(t.read());
|
|
41
|
-
(c === void 0 || !s(c, e)) && (c = e);
|
|
42
|
-
}
|
|
43
|
-
} catch {}
|
|
44
|
-
return c;
|
|
14
|
+
get: t,
|
|
15
|
+
peek: () => e.read(),
|
|
16
|
+
set: (t) => {
|
|
17
|
+
e.write(t), r();
|
|
45
18
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
observeRemote: () => {
|
|
20
|
+
let t = e._version;
|
|
21
|
+
if (!t) throw Error("This connector does not support remote observation.");
|
|
22
|
+
let n = !1, i = Atomics.load(t.view, t.index);
|
|
23
|
+
if (typeof Atomics.waitAsync == "function") return a.debug(`observing remote writes (offset ${e.byteOffset}, waitAsync)`), (async () => {
|
|
24
|
+
for (; !n;) {
|
|
25
|
+
let o = Atomics.waitAsync(t.view, t.index, i);
|
|
26
|
+
o.async && await o.value, i = Atomics.load(t.view, t.index), n || (a.trace(`remote write observed (offset ${e.byteOffset})`), r());
|
|
27
|
+
}
|
|
28
|
+
a.debug(`stopped observing (offset ${e.byteOffset})`);
|
|
29
|
+
})(), () => {
|
|
30
|
+
n = !0;
|
|
31
|
+
};
|
|
32
|
+
a.warn(`Atomics.waitAsync unavailable — observing via 50ms poll (offset ${e.byteOffset})`);
|
|
33
|
+
let o = setInterval(() => {
|
|
34
|
+
let e = Atomics.load(t.view, t.index);
|
|
35
|
+
e !== i && (i = e, r());
|
|
36
|
+
}, 50);
|
|
37
|
+
return () => {
|
|
38
|
+
n = !0, clearInterval(o);
|
|
49
39
|
};
|
|
50
40
|
}
|
|
51
41
|
};
|
|
52
42
|
}
|
|
43
|
+
function c(e, i, o, c) {
|
|
44
|
+
let l = o ? i : ((e) => e), u = o ?? i, d = s(e), f = d.observeRemote(), p = r((e) => {
|
|
45
|
+
let r = n(() => {
|
|
46
|
+
let e = d.get();
|
|
47
|
+
return e == null ? void 0 : l(e);
|
|
48
|
+
}, void 0, c?.equals ? { equals: (e, t) => e === void 0 || t === void 0 ? e === t : c.equals(e, t) } : void 0);
|
|
49
|
+
return t((e) => {
|
|
50
|
+
let t = r();
|
|
51
|
+
return t !== void 0 && u(t, e), t;
|
|
52
|
+
}), e;
|
|
53
|
+
});
|
|
54
|
+
return a.debug(`watching connector at offset ${e.byteOffset}`), () => {
|
|
55
|
+
a.debug(`watch stopped (offset ${e.byteOffset})`), f(), p();
|
|
56
|
+
};
|
|
57
|
+
}
|
|
53
58
|
//#endregion
|
|
54
|
-
export {
|
|
59
|
+
export { s as reactive, o as shallowEqual, c as watch };
|
|
55
60
|
|
|
56
61
|
//# sourceMappingURL=index19.js.map
|