@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.
Files changed (51) hide show
  1. package/README.md +167 -61
  2. package/dist/contract/listSchema.d.ts +47 -0
  3. package/dist/contract/msgpackCodec.d.ts +7 -0
  4. package/dist/contract/msgpackrCodec.d.ts +2 -0
  5. package/dist/contract/mz.d.ts +43 -0
  6. package/dist/contract/sharedMemory.d.ts +350 -0
  7. package/dist/contract/types.d.ts +131 -0
  8. package/dist/contract/zod.d.ts +53 -0
  9. package/dist/index.d.ts +30 -0
  10. package/dist/index.js +18 -18
  11. package/dist/index10.js +14 -178
  12. package/dist/index11.js +188 -47
  13. package/dist/index12.js +45 -59
  14. package/dist/index13.js +59 -20
  15. package/dist/index14.js +24 -60
  16. package/dist/index15.js +56 -43
  17. package/dist/index16.js +45 -41
  18. package/dist/index17.js +42 -38
  19. package/dist/index18.js +36 -55
  20. package/dist/index19.js +52 -47
  21. package/dist/index20.js +48 -51
  22. package/dist/index21.js +59 -0
  23. package/dist/index3.js +24 -117
  24. package/dist/index4.js +116 -34
  25. package/dist/index5.js +32 -473
  26. package/dist/index6.js +489 -19
  27. package/dist/index7.js +19 -6
  28. package/dist/index8.js +6 -33
  29. package/dist/index9.js +29 -14
  30. package/dist/log.d.ts +35 -0
  31. package/dist/observable.d.ts +30 -0
  32. package/dist/pool/errors.d.ts +16 -0
  33. package/dist/pool/memory.d.ts +19 -0
  34. package/dist/pool/workerClient.d.ts +80 -0
  35. package/dist/pool/workerPool.d.ts +115 -0
  36. package/dist/reactive.d.ts +46 -0
  37. package/dist/service.d.ts +181 -0
  38. package/dist/shared/sharedWorkerClient.d.ts +35 -0
  39. package/dist/shared/sharedWorkerHost.d.ts +21 -0
  40. package/dist/task.d.ts +40 -0
  41. package/dist/worker/defineWorker.d.ts +63 -0
  42. package/dist/worker/registry.d.ts +8 -0
  43. package/dist/worker/workerBootstrap.d.ts +1 -0
  44. package/package.json +17 -2
  45. package/src/contract/listSchema.ts +13 -8
  46. package/src/contract/mz.ts +1 -1
  47. package/src/contract/sharedMemory.ts +28 -1
  48. package/src/contract/types.ts +21 -0
  49. package/src/contract/zod.ts +44 -0
  50. package/src/index.ts +2 -1
  51. package/src/pool/workerPool.ts +27 -1
package/dist/index20.js CHANGED
@@ -1,59 +1,56 @@
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);
1
+ import { scoped as e } from "./index5.js";
2
+ import { watch as t } from "./index19.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();
42
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;
43
45
  },
44
- runOnce(e) {
45
- r.pending || r.settled || o.run(e);
46
+ subscribe(e) {
47
+ return m.add(e), h(), () => {
48
+ m.delete(e), m.size === 0 && g();
49
+ };
46
50
  }
47
51
  };
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
52
  }
56
53
  //#endregion
57
- export { n as defineTask, r as isAsyncTask, i as toTask };
54
+ export { r as observe };
58
55
 
59
56
  //# sourceMappingURL=index20.js.map
@@ -0,0 +1,59 @@
1
+ import { scoped as e } from "./index5.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=index21.js.map
package/dist/index3.js CHANGED
@@ -1,120 +1,27 @@
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
- }
1
+ import { array as e, bigint as t, boolean as n, float32 as r, float64 as i, instanceof as a, int32 as o, int64 as s, number as c, object as l, string as u, uint32 as d, uint64 as f, unknown as p } from "zod";
2
+ import { $ZodArray as m, $ZodObject as h, $ZodString as g, $ZodType as _ } from "zod/v4/core";
3
+ //#region src/contract/zod.ts
4
+ var v = {
5
+ number: c,
6
+ string: u,
7
+ boolean: n,
8
+ bigint: t,
9
+ object: l,
10
+ array: e,
11
+ instanceof: a,
12
+ unknown: p,
13
+ int32: o,
14
+ uint32: d,
15
+ float32: r,
16
+ float64: i,
17
+ int64: s,
18
+ uint64: f,
19
+ ZodType: _,
20
+ ZodObject: h,
21
+ ZodArray: m,
22
+ ZodString: g
23
+ };
117
24
  //#endregion
118
- export { i as listSchema, d as memberToSpec, p as zodArrayInfo, f as zodObjectShape, m as zodStringBytes };
25
+ export { v as z };
119
26
 
120
27
  //# sourceMappingURL=index3.js.map
package/dist/index4.js CHANGED
@@ -1,40 +1,122 @@
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) {
1
+ import { z as e } from "./index3.js";
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._zod.def?.type === "string" ? m(i) : 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._zod.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 = m(t);
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._zod.def.shape : null;
99
+ }
100
+ function p(t) {
101
+ if (!(t instanceof e.ZodArray)) return null;
102
+ let n = t._zod.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
+ }
28
107
  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)
108
+ element: n.element,
109
+ capacity: r
34
110
  };
35
111
  }
36
- var u = (e) => e >= 1 << 20 ? `${(e / (1 << 20)).toFixed(1)}MB` : e >= 1024 ? `${(e / 1024).toFixed(1)}KB` : `${e}B`;
112
+ function m(e) {
113
+ let t = e.meta?.();
114
+ return typeof t?.bytes == "number" ? t.bytes : null;
115
+ }
116
+ function h(t) {
117
+ return t instanceof e.ZodString ? m(t) : null;
118
+ }
37
119
  //#endregion
38
- export { u as fmtBytes, o as getLogLevel, c as log, l as scoped, a as setLogLevel, s as setLogSink };
120
+ export { i as listSchema, d as memberToSpec, p as zodArrayInfo, f as zodObjectShape, h as zodStringBytes };
39
121
 
40
122
  //# sourceMappingURL=index4.js.map