@atolljs/core 0.1.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.
Files changed (44) hide show
  1. package/README.md +110 -0
  2. package/dist/index.js +19 -0
  3. package/dist/index10.js +186 -0
  4. package/dist/index11.js +52 -0
  5. package/dist/index12.js +66 -0
  6. package/dist/index13.js +27 -0
  7. package/dist/index14.js +63 -0
  8. package/dist/index15.js +50 -0
  9. package/dist/index16.js +46 -0
  10. package/dist/index17.js +42 -0
  11. package/dist/index18.js +61 -0
  12. package/dist/index19.js +56 -0
  13. package/dist/index2.js +10 -0
  14. package/dist/index20.js +59 -0
  15. package/dist/index3.js +120 -0
  16. package/dist/index4.js +40 -0
  17. package/dist/index5.js +481 -0
  18. package/dist/index6.js +23 -0
  19. package/dist/index7.js +10 -0
  20. package/dist/index8.js +37 -0
  21. package/dist/index9.js +22 -0
  22. package/package.json +68 -0
  23. package/src/contract/listSchema.ts +211 -0
  24. package/src/contract/msgpackCodec.ts +9 -0
  25. package/src/contract/msgpackrCodec.ts +16 -0
  26. package/src/contract/mz.ts +48 -0
  27. package/src/contract/sharedMemory.ts +909 -0
  28. package/src/contract/types.ts +123 -0
  29. package/src/index.ts +114 -0
  30. package/src/log.ts +69 -0
  31. package/src/observable.ts +151 -0
  32. package/src/pool/errors.ts +31 -0
  33. package/src/pool/memory.ts +68 -0
  34. package/src/pool/workerClient.ts +181 -0
  35. package/src/pool/workerPool.ts +438 -0
  36. package/src/reactive.ts +161 -0
  37. package/src/service.ts +283 -0
  38. package/src/shared/sharedWorkerClient.ts +142 -0
  39. package/src/shared/sharedWorkerHost.ts +104 -0
  40. package/src/task.ts +99 -0
  41. package/src/testing/inProcessWorker.ts +127 -0
  42. package/src/worker/defineWorker.ts +135 -0
  43. package/src/worker/registry.ts +42 -0
  44. package/src/worker/workerBootstrap.ts +56 -0
@@ -0,0 +1,61 @@
1
+ import { scoped as e } from "./index4.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());
13
+ return {
14
+ get: t,
15
+ peek: () => e.read(),
16
+ set: (t) => {
17
+ e.write(t), r();
18
+ },
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);
39
+ };
40
+ }
41
+ };
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
+ }
58
+ //#endregion
59
+ export { s as reactive, o as shallowEqual, c as watch };
60
+
61
+ //# sourceMappingURL=index18.js.map
@@ -0,0 +1,56 @@
1
+ import { scoped as e } from "./index4.js";
2
+ import { watch as t } from "./index18.js";
3
+ //#region src/observable.ts
4
+ var n = e("observe");
5
+ function r(e, r, i, a) {
6
+ let o = i ?? ((e) => e), s = a?.equals ?? Object.is, c, l = -1, u = null, d = null, f = null, p = null, m = /* @__PURE__ */ new Set(), h = () => {
7
+ if (u || d) return;
8
+ let i;
9
+ try {
10
+ i = e.connector(String(r));
11
+ } catch {
12
+ d = e.onBound(() => {
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
+ };
34
+ return {
35
+ get() {
36
+ if (u || e.bound) try {
37
+ let t = e.connector(String(r)), n = t._version ? Atomics.load(t._version.view, t._version.index) : 0;
38
+ if (n !== l) {
39
+ l = n;
40
+ let e = o(t.read());
41
+ (c === void 0 || !s(c, e)) && (c = e);
42
+ }
43
+ } catch {}
44
+ return c;
45
+ },
46
+ subscribe(e) {
47
+ return m.add(e), h(), () => {
48
+ m.delete(e), m.size === 0 && g();
49
+ };
50
+ }
51
+ };
52
+ }
53
+ //#endregion
54
+ export { r as observe };
55
+
56
+ //# sourceMappingURL=index19.js.map
package/dist/index2.js ADDED
@@ -0,0 +1,10 @@
1
+ import { Packr as e } from "msgpackr";
2
+ //#region src/contract/msgpackrCodec.ts
3
+ var t = new e({ useRecords: !0 }), n = {
4
+ encode: (e) => t.pack(e),
5
+ decode: (e) => t.unpack(e)
6
+ };
7
+ //#endregion
8
+ export { n as msgpackrCodec };
9
+
10
+ //# sourceMappingURL=index2.js.map
@@ -0,0 +1,59 @@
1
+ import { scoped as e } from "./index4.js";
2
+ //#region src/task.ts
3
+ var t = e("task");
4
+ function n(e) {
5
+ let n = 0, r = {
6
+ data: null,
7
+ pending: !1,
8
+ settled: !1,
9
+ elapsedMs: null,
10
+ error: null
11
+ }, i = /* @__PURE__ */ new Set(), a = (e) => {
12
+ r = e;
13
+ for (let t of i) t(e);
14
+ }, o = {
15
+ get: () => r,
16
+ subscribe(e) {
17
+ return i.add(e), () => {
18
+ i.delete(e);
19
+ };
20
+ },
21
+ run(i) {
22
+ let o = ++n, s = performance.now();
23
+ a({
24
+ ...r,
25
+ pending: !0,
26
+ error: null
27
+ }), e(i).then((e) => {
28
+ o === n && a({
29
+ data: e,
30
+ pending: !1,
31
+ settled: !0,
32
+ elapsedMs: performance.now() - s,
33
+ error: null
34
+ });
35
+ }, (e) => {
36
+ o === n && a({
37
+ ...r,
38
+ pending: !1,
39
+ settled: !0,
40
+ error: e
41
+ }), t.error("task run failed", e);
42
+ });
43
+ },
44
+ runOnce(e) {
45
+ r.pending || r.settled || o.run(e);
46
+ }
47
+ };
48
+ return o;
49
+ }
50
+ function r(e) {
51
+ return typeof e == "object" && !!e && typeof e.run == "function" && typeof e.runOnce == "function" && typeof e.get == "function" && typeof e.subscribe == "function";
52
+ }
53
+ function i(e) {
54
+ return r(e) ? e : n(e);
55
+ }
56
+ //#endregion
57
+ export { n as defineTask, r as isAsyncTask, i as toTask };
58
+
59
+ //# sourceMappingURL=index20.js.map
package/dist/index3.js ADDED
@@ -0,0 +1,120 @@
1
+ import { z as e } from "zod";
2
+ //#region src/contract/listSchema.ts
3
+ var t = new TextEncoder(), n = {
4
+ i8: e.number().int().min(-128).max(127),
5
+ u8: e.number().int().min(0).max(255),
6
+ i16: e.number().int().min(-32768).max(32767),
7
+ u16: e.number().int().min(0).max(65535),
8
+ i32: e.number().int().min(-2147483648).max(2147483647),
9
+ u32: e.number().int().min(0).max(4294967295),
10
+ f32: e.number(),
11
+ f64: e.number(),
12
+ i64: e.bigint(),
13
+ u64: e.bigint().nonnegative()
14
+ }, r = (n) => e.string().refine((e) => t.encode(e).byteLength <= n, `exceeds ${n} UTF-8 bytes`);
15
+ function i(t) {
16
+ let n = {};
17
+ for (let e of Object.keys(t)) n[e] = a(t[e]);
18
+ return e.object(n);
19
+ }
20
+ function a(i) {
21
+ if (i instanceof e.ZodType) {
22
+ let e = i.def?.type === "string" ? i.meta()?.bytes : void 0;
23
+ return typeof e == "number" ? i.refine((n) => t.encode(n).byteLength <= e, `exceeds ${e} UTF-8 bytes`) : i;
24
+ }
25
+ return typeof i == "string" ? n[i] : "string" in i ? r(i.string) : e.boolean();
26
+ }
27
+ var o = {
28
+ int32: "i32",
29
+ uint32: "u32",
30
+ float32: "f32",
31
+ float64: "f64"
32
+ }, s = {
33
+ int64: "i64",
34
+ uint64: "u64"
35
+ }, c = [
36
+ {
37
+ kind: "u8",
38
+ min: 0,
39
+ max: 255
40
+ },
41
+ {
42
+ kind: "i8",
43
+ min: -128,
44
+ max: 127
45
+ },
46
+ {
47
+ kind: "u16",
48
+ min: 0,
49
+ max: 65535
50
+ },
51
+ {
52
+ kind: "i16",
53
+ min: -32768,
54
+ max: 32767
55
+ },
56
+ {
57
+ kind: "u32",
58
+ min: 0,
59
+ max: 4294967295
60
+ },
61
+ {
62
+ kind: "i32",
63
+ min: -2147483648,
64
+ max: 2147483647
65
+ }
66
+ ], l = (e) => e.def ?? e._zod?.def;
67
+ function u(e) {
68
+ let t = [e.format, ...(e.checks ?? []).map((e) => l(e)?.format)], n = t.find((e) => !!e && e in o);
69
+ if (n) return o[n];
70
+ if (t.includes("safeint")) {
71
+ let t = -Infinity, n = Infinity;
72
+ for (let r of e.checks ?? []) {
73
+ let e = l(r);
74
+ e?.check === "greater_than" && e.inclusive && (t = e.value ?? t), e?.check === "less_than" && e.inclusive && (n = e.value ?? n);
75
+ }
76
+ for (let e of c) if (t >= e.min && n <= e.max) return e.kind;
77
+ }
78
+ return "f64";
79
+ }
80
+ function d(t, n) {
81
+ if (typeof t == "string") return t;
82
+ if (!(t instanceof e.ZodType)) {
83
+ if (typeof t.string == "number" || t.bool === !0) return t;
84
+ throw TypeError(`member "${n}": expected a scalar token, { string: n }, { bool: true }, or a zod schema`);
85
+ }
86
+ let r = t.def;
87
+ if (r.type === "number") return u(r);
88
+ if (r.type === "bigint") return s[r.format ?? ""] ?? "i64";
89
+ if (r.type === "boolean") return { bool: !0 };
90
+ if (r.type === "string") {
91
+ let e = t.meta()?.bytes;
92
+ if (typeof e == "number") return { string: e };
93
+ throw TypeError(`member "${n}": z.string() needs .meta({ bytes: n }) — inline strings are fixed-width`);
94
+ }
95
+ throw TypeError(`member "${n}": zod "${r.type}" can't lay out as a fixed-width scalar — use number, bigint, boolean, or a bounded string`);
96
+ }
97
+ function f(t) {
98
+ return t instanceof e.ZodObject ? t.def.shape : null;
99
+ }
100
+ function p(t) {
101
+ if (!(t instanceof e.ZodArray)) return null;
102
+ let n = t.def, r = null;
103
+ for (let e of n.checks ?? []) {
104
+ let t = l(e);
105
+ t?.check === "max_length" && typeof t.maximum == "number" && (r = t.maximum), t?.check === "length_equals" && typeof t.length == "number" && (r = t.length);
106
+ }
107
+ return {
108
+ element: n.element,
109
+ capacity: r
110
+ };
111
+ }
112
+ function m(t) {
113
+ if (!(t instanceof e.ZodString)) return null;
114
+ let n = t.meta()?.bytes;
115
+ return typeof n == "number" ? n : null;
116
+ }
117
+ //#endregion
118
+ export { i as listSchema, d as memberToSpec, p as zodArrayInfo, f as zodObjectShape, m as zodStringBytes };
119
+
120
+ //# sourceMappingURL=index3.js.map
package/dist/index4.js ADDED
@@ -0,0 +1,40 @@
1
+ //#region src/log.ts
2
+ var e = {
3
+ trace: 0,
4
+ debug: 1,
5
+ info: 2,
6
+ warn: 3,
7
+ error: 4,
8
+ off: 5
9
+ }, t = typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "worker" : "main", n = ({ level: e, scope: t, message: n, data: r, thread: i, at: a }) => {
10
+ let o = `[${(a / 1e3).toFixed(2)}s ${i}:${t}]`, s = e === "error" ? console.error : e === "warn" ? console.warn : e === "info" ? console.info : console.debug;
11
+ r === void 0 ? s(`${o} ${n}`) : s(`${o} ${n}`, r);
12
+ }, r = "info", i = n, a = (e) => {
13
+ r = e;
14
+ }, o = () => r, s = (e) => {
15
+ i = e ?? n;
16
+ };
17
+ function c(n, a, o, s) {
18
+ e[n] < e[r] || i({
19
+ level: n,
20
+ scope: a,
21
+ message: o,
22
+ data: s,
23
+ thread: t,
24
+ at: performance.now()
25
+ });
26
+ }
27
+ function l(e) {
28
+ return {
29
+ trace: (t, n) => c("trace", e, t, n),
30
+ debug: (t, n) => c("debug", e, t, n),
31
+ info: (t, n) => c("info", e, t, n),
32
+ warn: (t, n) => c("warn", e, t, n),
33
+ error: (t, n) => c("error", e, t, n)
34
+ };
35
+ }
36
+ var u = (e) => e >= 1 << 20 ? `${(e / (1 << 20)).toFixed(1)}MB` : e >= 1024 ? `${(e / 1024).toFixed(1)}KB` : `${e}B`;
37
+ //#endregion
38
+ export { u as fmtBytes, o as getLogLevel, c as log, l as scoped, a as setLogLevel, s as setLogSink };
39
+
40
+ //# sourceMappingURL=index4.js.map