@atolljs/core 0.1.7 → 0.1.8

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 (59) hide show
  1. package/README.md +1 -1
  2. package/dist/contract/memoryDevtools.d.ts +30 -0
  3. package/dist/contract/sharedMemory.d.ts +4 -2
  4. package/dist/contract/types.d.ts +11 -0
  5. package/dist/devtools.d.ts +127 -4
  6. package/dist/index.d.ts +8 -4
  7. package/dist/index.js +19 -17
  8. package/dist/index10.js +29 -14
  9. package/dist/index11.js +14 -307
  10. package/dist/index12.js +29 -50
  11. package/dist/index13.js +46 -60
  12. package/dist/index14.js +56 -22
  13. package/dist/index15.js +332 -55
  14. package/dist/index16.js +246 -45
  15. package/dist/index17.js +56 -51
  16. package/dist/index18.js +9 -39
  17. package/dist/index19.js +56 -80
  18. package/dist/index20.js +24 -53
  19. package/dist/index21.js +56 -52
  20. package/dist/index22.js +48 -0
  21. package/dist/index23.js +68 -0
  22. package/dist/index24.js +41 -0
  23. package/dist/index25.js +46 -0
  24. package/dist/index26.js +113 -0
  25. package/dist/index27.js +60 -0
  26. package/dist/index28.js +57 -0
  27. package/dist/index5.js +135 -64
  28. package/dist/index6.js +160 -35
  29. package/dist/index7.js +45 -503
  30. package/dist/index8.js +513 -19
  31. package/dist/index9.js +19 -33
  32. package/dist/pool/dedicatedWorker.d.ts +63 -0
  33. package/dist/pool/devtoolsCommands.d.ts +54 -0
  34. package/dist/pool/subWorkerClient.d.ts +50 -0
  35. package/dist/pool/workerChannel.d.ts +44 -0
  36. package/dist/pool/workerClient.d.ts +36 -8
  37. package/dist/pool/workerPool.d.ts +10 -1
  38. package/dist/reactive.d.ts +15 -0
  39. package/dist/reactiveGraph.d.ts +9 -0
  40. package/dist/userTiming.d.ts +27 -0
  41. package/package.json +2 -1
  42. package/src/contract/memoryDevtools.ts +249 -0
  43. package/src/contract/sharedMemory.ts +20 -6
  44. package/src/contract/types.ts +11 -0
  45. package/src/devtools.ts +251 -6
  46. package/src/index.ts +13 -1
  47. package/src/log.ts +22 -0
  48. package/src/observable.ts +16 -3
  49. package/src/pool/dedicatedWorker.ts +332 -0
  50. package/src/pool/devtoolsCommands.ts +165 -0
  51. package/src/pool/subWorkerClient.ts +70 -0
  52. package/src/pool/workerChannel.ts +99 -0
  53. package/src/pool/workerClient.ts +61 -15
  54. package/src/pool/workerPool.ts +75 -45
  55. package/src/reactive.ts +87 -12
  56. package/src/reactiveGraph.ts +91 -0
  57. package/src/testing/inProcessWorker.ts +4 -3
  58. package/src/userTiming.ts +71 -0
  59. package/src/worker/workerBootstrap.ts +27 -4
package/dist/index6.js CHANGED
@@ -1,38 +1,163 @@
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 { emitDevtools as e, previewValue as t, registerDevtoolsCommand as n } from "./index5.js";
2
+ //#region src/contract/memoryDevtools.ts
3
+ var r = /* @__PURE__ */ new Map(), i = () => [], a = !1, o = 5, s = 16, c = (e) => {
4
+ let n = e;
5
+ if (typeof n.readAt == "function" && typeof n.recordCount == "number") {
6
+ let e = Array.from({ length: Math.min(o, n.recordCount) }, (e, t) => n.readAt(t));
7
+ return t({
8
+ records: n.recordCount,
9
+ head: e
10
+ }, 1024);
11
+ }
12
+ let r = e.read();
13
+ if (ArrayBuffer.isView(r) && !(r instanceof DataView)) {
14
+ let e = r, t = Array.from({ length: Math.min(s, e.length) }, (t, n) => typeof e[n] == "bigint" ? `${e[n]}n` : e[n]);
15
+ return `${r.constructor.name}(${e.length}) ${JSON.stringify(t)}${e.length > s ? "…" : ""}`;
16
+ }
17
+ return t(r, 1024);
18
+ }, l = (e, t) => e.connector(t), u = (e) => e._version ? Atomics.load(e._version.view, e._version.index) : 0, d = (e) => {
19
+ try {
20
+ return JSON.parse(e);
21
+ } catch {
22
+ return e;
23
+ }
24
+ }, f = (e) => typeof e == "number" ? e : typeof e == "bigint" ? Number(e) : null, p = (e) => {
25
+ let n = e.trim();
26
+ if (n === "change") return {
27
+ text: n,
28
+ test: () => !0
29
+ };
30
+ let r = /^(>=|<=|==|!=|>|<)\s*(.+)$/.exec(n);
31
+ if (!r) throw Error(`memory.watch: bad rule '${e}' — use change, > n, < n, >= n, <= n, == v, != v`);
32
+ let [, i, a] = r;
33
+ if (i === "==" || i === "!=") {
34
+ let e = d(a), r = (n) => typeof n == "object" && n ? t(n) === t(e) : Object.is(n, e) || typeof n == "bigint" && Number(n) === e;
35
+ return {
36
+ text: n,
37
+ test: i === "==" ? r : (e) => !r(e)
38
+ };
39
+ }
40
+ let o = Number(a);
41
+ if (!Number.isFinite(o)) throw Error(`memory.watch: '${a}' is not a number`);
42
+ let s = {
43
+ ">": (e) => e > o,
44
+ "<": (e) => e < o,
45
+ ">=": (e) => e >= o,
46
+ "<=": (e) => e <= o
47
+ };
28
48
  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)
49
+ text: n,
50
+ test: (e) => {
51
+ let t = f(e);
52
+ return t !== null && s[i](t);
53
+ }
54
+ };
55
+ }, m = (t, n, r, i, a) => {
56
+ let o = r.seen.get(t);
57
+ if (o && o.version >= a) return;
58
+ let s = r.rule.text === "change", l = typeof i.readAt == "function", u, d;
59
+ try {
60
+ d = c(i), u = s || l ? void 0 : i.read();
61
+ } catch {
62
+ return;
63
+ }
64
+ r.seen.set(t, {
65
+ version: a,
66
+ preview: d
67
+ }), (s ? d !== o?.preview : !l && r.rule.test(u)) && (r.hits++, e({
68
+ type: "memory:watch-hit",
69
+ path: n,
70
+ version: a,
71
+ value: d,
72
+ rule: r.rule.text
73
+ }));
74
+ }, h = (e, t, n) => {
75
+ let i = r.get(t);
76
+ i && m(e, t, i, l(e, t), n);
77
+ }, g = (e, t) => {
78
+ let n = !1, r = () => {
79
+ for (let n of i()) {
80
+ if (!n.bound) continue;
81
+ let r;
82
+ try {
83
+ r = l(n, e);
84
+ } catch {
85
+ continue;
86
+ }
87
+ m(n, e, t, r, u(r));
88
+ }
34
89
  };
35
- }
36
- var u = (e) => e >= 1 << 20 ? `${(e / (1 << 20)).toFixed(1)}MB` : e >= 1024 ? `${(e / 1024).toFixed(1)}KB` : `${e}B`;
90
+ if (typeof Atomics.waitAsync == "function") return (async () => {
91
+ for (; !n;) {
92
+ let t = i().find((t) => {
93
+ try {
94
+ return t.bound && l(t, e)._version !== void 0;
95
+ } catch {
96
+ return !1;
97
+ }
98
+ }), a = t ? l(t, e)._version : void 0;
99
+ if (a) {
100
+ let e = Atomics.waitAsync(a.view, a.index, Atomics.load(a.view, a.index), 250);
101
+ e.async && await e.value;
102
+ } else await new Promise((e) => setTimeout(e, 250));
103
+ n || r();
104
+ }
105
+ })(), () => {
106
+ n = !0;
107
+ };
108
+ let a = setInterval(r, 50);
109
+ return a.unref?.(), () => {
110
+ n = !0, clearInterval(a);
111
+ };
112
+ }, _ = () => [...r.entries()].map(([e, t]) => ({
113
+ path: e,
114
+ rule: t.rule.text,
115
+ hits: t.hits
116
+ })), v = (e) => {
117
+ i = e, !a && (a = !0, n("memory.read", () => {
118
+ let e = [];
119
+ return i().forEach((t, n) => {
120
+ if (t.bound) for (let { path: r } of t.fields()) try {
121
+ let i = l(t, r);
122
+ e.push({
123
+ path: r,
124
+ value: c(i),
125
+ version: u(i),
126
+ contract: n
127
+ });
128
+ } catch (t) {
129
+ e.push({
130
+ path: r,
131
+ value: `[unreadable: ${t.message}]`,
132
+ version: -1,
133
+ contract: n
134
+ });
135
+ }
136
+ }), e;
137
+ }), n("memory.watch", (e) => {
138
+ let t = String(e.path ?? "");
139
+ if (!t) throw Error("memory.watch: `path` is required");
140
+ if (!i().some((e) => e.fields().some((e) => e.path === t))) throw Error(`memory.watch: no contract defines a field '${t}'`);
141
+ let n = p(String(e.rule ?? "change"));
142
+ r.get(t)?.stop();
143
+ let a = {
144
+ rule: n,
145
+ seen: /* @__PURE__ */ new WeakMap(),
146
+ stop: () => {},
147
+ hits: 0
148
+ };
149
+ for (let e of i()) if (e.bound) try {
150
+ let n = l(e, t);
151
+ a.seen.set(e, {
152
+ version: u(n),
153
+ preview: c(n)
154
+ });
155
+ } catch {}
156
+ return r.set(t, a), a.stop = g(t, a), _();
157
+ }), n("memory.unwatch", (e) => {
158
+ let t = String(e.path ?? "");
159
+ return r.get(t)?.stop(), r.delete(t), _();
160
+ }), n("memory.watches", () => _()));
161
+ };
37
162
  //#endregion
38
- export { u as fmtBytes, o as getLogLevel, c as log, l as scoped, a as setLogLevel, s as setLogSink };
163
+ export { h as checkWatchOnWrite, v as ensureMemoryCommands, c as fieldPreview, r as memoryWatches, p as parseWatchRule };