@atolljs/core 0.1.12 → 0.1.14

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 (32) hide show
  1. package/README.md +4 -0
  2. package/dist/{index4.js → contract/listSchema.js} +1 -1
  3. package/dist/{index6.js → contract/memoryDevtools.js} +1 -1
  4. package/dist/{index9.js → contract/reef.js} +1 -1
  5. package/dist/{index8.js → contract/sharedMemory.js} +55 -55
  6. package/dist/contract/types.js +0 -0
  7. package/dist/index.js +22 -22
  8. package/dist/{index7.js → log.js} +1 -1
  9. package/dist/{index27.js → observable.js} +3 -3
  10. package/dist/{index16.js → pool/dedicatedWorker.js} +6 -6
  11. package/dist/{index14.js → pool/devtoolsCommands.js} +1 -1
  12. package/dist/{index18.js → pool/subWorkerClient.js} +1 -1
  13. package/dist/{index13.js → pool/workerChannel.js} +2 -2
  14. package/dist/{index17.js → pool/workerClient.js} +2 -2
  15. package/dist/{index15.js → pool/workerPool.js} +6 -6
  16. package/dist/{index26.js → reactive.js} +2 -2
  17. package/dist/{index25.js → reactiveGraph.js} +1 -1
  18. package/dist/{index22.js → service.js} +2 -2
  19. package/dist/{index19.js → shared/sharedWorkerClient.js} +1 -1
  20. package/dist/{index21.js → shared/sharedWorkerHost.js} +4 -4
  21. package/dist/{index28.js → task.js} +1 -1
  22. package/dist/testing/inProcessWorker.js +110 -0
  23. package/dist/{index24.js → worker/defineWorker.js} +3 -3
  24. package/dist/{index20.js → worker/registry.js} +1 -1
  25. package/dist/{index23.js → worker/workerBootstrap.js} +5 -5
  26. package/package.json +11 -3
  27. /package/dist/{index2.js → contract/msgpackrCodec.js} +0 -0
  28. /package/dist/{index3.js → contract/zod.js} +0 -0
  29. /package/dist/{index5.js → devtools.js} +0 -0
  30. /package/dist/{index11.js → pool/errors.js} +0 -0
  31. /package/dist/{index10.js → pool/memory.js} +0 -0
  32. /package/dist/{index12.js → userTiming.js} +0 -0
package/README.md CHANGED
@@ -16,6 +16,10 @@ fabric, so work is offloaded as typed method calls while large state stays put
16
16
 
17
17
  **[Atoll — package documentation](https://jwhenry3.github.io/atolljs/consumer/quickstart/)**
18
18
 
19
+ <p align="center">
20
+ <img alt="AtollJS bridges main-thread UI and web workers" src="assets/atoll-convergence.png" width="1100">
21
+ </p>
22
+
19
23
  ## Install
20
24
 
21
25
  ```bash
@@ -1,4 +1,4 @@
1
- import { fluent as e, z as t } from "./index3.js";
1
+ import { fluent as e, z as t } from "./zod.js";
2
2
  //#region src/contract/listSchema.ts
3
3
  var n = new TextEncoder(), r = (n, r) => e(t.number().check(t.int(), t.gte(n), t.lte(r))), i = {
4
4
  i8: r(-128, 127),
@@ -1,4 +1,4 @@
1
- import { emitDevtools as e, previewValue as t, registerDevtoolsCommand as n } from "./index5.js";
1
+ import { emitDevtools as e, previewValue as t, registerDevtoolsCommand as n } from "../devtools.js";
2
2
  //#region src/contract/memoryDevtools.ts
3
3
  var r = /* @__PURE__ */ new Map(), i = () => [], a = !1, o = 5, s = 16, c = (e) => {
4
4
  let n = e;
@@ -1,4 +1,4 @@
1
- import { fluent as e, z as t } from "./index3.js";
1
+ import { fluent as e, z as t } from "./zod.js";
2
2
  //#region src/contract/reef.ts
3
3
  var n = new TextEncoder(), r = {
4
4
  i8: () => e(t.number().check(t.int(), t.gte(-128), t.lte(127))),
@@ -1,9 +1,9 @@
1
- import { msgpackrCodec as e } from "./index2.js";
2
- import { fluent as t, z as n } from "./index3.js";
3
- import { memberToSpec as r, zodArrayInfo as i, zodObjectShape as a, zodStringBytes as o } from "./index4.js";
4
- import { devtoolsEnabled as s, emitDevtools as c } from "./index5.js";
5
- import { checkWatchOnWrite as l, ensureMemoryCommands as u, memoryWatches as d } from "./index6.js";
6
- import { fmtBytes as f, scoped as p } from "./index7.js";
1
+ import { fluent as e, z as t } from "./zod.js";
2
+ import { memberToSpec as n, zodArrayInfo as r, zodObjectShape as i, zodStringBytes as a } from "./listSchema.js";
3
+ import { devtoolsEnabled as o, emitDevtools as s } from "../devtools.js";
4
+ import { checkWatchOnWrite as c, ensureMemoryCommands as l, memoryWatches as u } from "./memoryDevtools.js";
5
+ import { msgpackrCodec as d } from "./msgpackrCodec.js";
6
+ import { fmtBytes as f, scoped as p } from "../log.js";
7
7
  //#region src/contract/sharedMemory.ts
8
8
  var m = p("memory"), h = 8, g = (e, t) => e + t - 1 & ~(t - 1), _ = (e) => g(e, h), v = (e) => typeof e == "object" && !!e && typeof e.kind == "string" && typeof e.byteLength == "number";
9
9
  function y(e) {
@@ -41,13 +41,13 @@ var T = {
41
41
  u64: 8
42
42
  }, E = (e) => typeof e == "string" ? T[e] : "string" in e ? e.string : 1, D = (e) => typeof e == "string" ? T[e] : 1;
43
43
  function O(e) {
44
- let t = {}, n = {}, i = 0;
44
+ let t = {}, r = {}, i = 0;
45
45
  for (let a of Object.keys(e)) {
46
- let o = r(e[a], String(a));
47
- n[a] = o, i = g(i, D(o)), t[a] = i, i += E(o);
46
+ let o = n(e[a], String(a));
47
+ r[a] = o, i = g(i, D(o)), t[a] = i, i += E(o);
48
48
  }
49
49
  return {
50
- layout: n,
50
+ layout: r,
51
51
  offsets: t,
52
52
  recordSize: _(i)
53
53
  };
@@ -68,7 +68,7 @@ var k = {
68
68
  byteLength: 4 + n,
69
69
  schema: t
70
70
  };
71
- let r = t ? o(t) : null;
71
+ let r = t ? a(t) : null;
72
72
  if (r !== null) return {
73
73
  kind: "string",
74
74
  byteLength: 4 + r,
@@ -79,7 +79,7 @@ var k = {
79
79
  object: (e) => {
80
80
  let { schema: t, maxBytes: n } = e;
81
81
  if (n === void 0 && t) {
82
- let e = a(t);
82
+ let e = i(t);
83
83
  if (e) {
84
84
  let { layout: n, offsets: r, recordSize: i } = O(e);
85
85
  return {
@@ -101,33 +101,33 @@ var k = {
101
101
  };
102
102
  },
103
103
  array: (e) => {
104
- let { schema: t, maxBytes: n } = e;
105
- if (n === void 0 && t) {
106
- let e = i(t);
104
+ let { schema: t, maxBytes: i } = e;
105
+ if (i === void 0 && t) {
106
+ let e = r(t);
107
107
  if (e) {
108
108
  if (e.capacity === null) throw TypeError("field.array: z.array() needs .max(n) or .length(n) — bounded arrays are fixed-width");
109
- let n;
109
+ let r;
110
110
  try {
111
- n = r(e.element, "array element");
111
+ r = n(e.element, "array element");
112
112
  } catch (e) {
113
113
  throw TypeError(`field.array: element isn't a fixed-width member — use field.list for arrays of records (${e.message})`);
114
114
  }
115
- let i = g(E(n), D(n));
115
+ let i = g(E(r), D(r));
116
116
  return {
117
117
  kind: "array",
118
118
  byteLength: 8 + e.capacity * i,
119
119
  schema: t,
120
- element: n,
120
+ element: r,
121
121
  elementStride: i,
122
122
  capacity: e.capacity
123
123
  };
124
124
  }
125
125
  throw TypeError("field.array: schema can't derive a fixed byte width (not a bounded zod array) — pass { maxBytes } for codec-encoded storage");
126
126
  }
127
- if (n === void 0) throw TypeError("field.array: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
127
+ if (i === void 0) throw TypeError("field.array: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
128
128
  return {
129
129
  kind: "array",
130
- byteLength: 4 + n,
130
+ byteLength: 4 + i,
131
131
  schema: t
132
132
  };
133
133
  },
@@ -148,15 +148,15 @@ var k = {
148
148
  byteLength: e
149
149
  }),
150
150
  list: ({ schema: e, count: t }) => {
151
- let n = a(e);
151
+ let n = i(e);
152
152
  if (!n) throw TypeError("field.list: schema must be a reef.object() of fixed-width members");
153
- let { layout: r, offsets: i, recordSize: o } = O(n);
153
+ let { layout: r, offsets: a, recordSize: o } = O(n);
154
154
  return {
155
155
  kind: "list",
156
156
  byteLength: o * t,
157
157
  schema: e,
158
158
  layout: r,
159
- offsets: i,
159
+ offsets: a,
160
160
  recordSize: o,
161
161
  count: t
162
162
  };
@@ -348,31 +348,31 @@ var M = (e, t, n) => {
348
348
  };
349
349
  w("object", M), w("array", M);
350
350
  function N(e, t, n) {
351
- let r = e, { offsets: i, recordSize: a, count: o } = r, l = j(t).compile(r.layout, i), u = (e) => {
352
- if (e < 0 || e >= o) throw RangeError(`Record index ${e} out of bounds (0..${o - 1})`);
351
+ let r = e, { offsets: i, recordSize: a, count: c } = r, l = j(t).compile(r.layout, i), u = (e) => {
352
+ if (e < 0 || e >= c) throw RangeError(`Record index ${e} out of bounds (0..${c - 1})`);
353
353
  }, d = (e, t = {}, r) => (u(e), l.read(n + e * a, t, r)), f = (e, t, r) => {
354
354
  u(e), l.write(n + e * a, t, r);
355
355
  };
356
356
  return {
357
357
  byteOffset: n,
358
358
  byteLength: e.byteLength,
359
- recordCount: o,
359
+ recordCount: c,
360
360
  recordSize: a,
361
361
  readAt: d,
362
362
  writeAt: f,
363
363
  commit: () => {
364
364
  if (t.version) {
365
365
  let e = Atomics.add(t.version.view, t.version.index, 1);
366
- Atomics.notify(t.version.view, t.version.index), t.path && s() && c({
366
+ Atomics.notify(t.version.view, t.version.index), t.path && o() && s({
367
367
  type: "memory:write",
368
368
  path: t.path,
369
369
  version: e + 1
370
370
  });
371
371
  }
372
372
  },
373
- read: () => Array.from({ length: o }, (e, t) => d(t)),
373
+ read: () => Array.from({ length: c }, (e, t) => d(t)),
374
374
  write: (e) => {
375
- if (e.length > o) throw Error(`${e.length} records exceeds list array capacity of ${o}`);
375
+ if (e.length > c) throw Error(`${e.length} records exceeds list array capacity of ${c}`);
376
376
  e.forEach((e, t) => f(t, e));
377
377
  }
378
378
  };
@@ -384,17 +384,17 @@ function F(e) {
384
384
  for (let [n, r] of Object.entries(e)) t[n] = v(r) ? I(r) : Object.fromEntries(Object.entries(r).map(([e, t]) => [e, I(t)]));
385
385
  return t;
386
386
  }
387
- function I(e) {
388
- if (e.schema) return e.schema;
389
- switch (e.kind) {
390
- case "number": return t(n.number());
391
- case "boolean": return t(n.boolean());
392
- case "string": return t(n.string());
393
- case "Int32": return t(n.instanceof(Int32Array));
394
- case "Float64": return t(n.instanceof(Float64Array));
395
- case "BigInt64": return t(n.instanceof(BigInt64Array));
396
- case "Uint8": return t(n.instanceof(Uint8Array));
397
- default: return t(n.unknown());
387
+ function I(n) {
388
+ if (n.schema) return n.schema;
389
+ switch (n.kind) {
390
+ case "number": return e(t.number());
391
+ case "boolean": return e(t.boolean());
392
+ case "string": return e(t.string());
393
+ case "Int32": return e(t.instanceof(Int32Array));
394
+ case "Float64": return e(t.instanceof(Float64Array));
395
+ case "BigInt64": return e(t.instanceof(BigInt64Array));
396
+ case "Uint8": return e(t.instanceof(Uint8Array));
397
+ default: return e(t.unknown());
398
398
  }
399
399
  }
400
400
  var L = class {
@@ -410,11 +410,11 @@ var L = class {
410
410
  boundListeners = /* @__PURE__ */ new Set();
411
411
  isBound = !1;
412
412
  boundBuffer;
413
- constructor(t, n = {}) {
414
- this.spec = t, this.codec = n.codec ?? e, this.plugins = n.plugins, this.entries = y(t), this.schemas = F(t);
415
- let r = 0;
416
- for (let { path: e, descriptor: t } of this.entries) r = _(r), this.offsets.set(e, r), r += t.byteLength;
417
- this.versionOffset = _(r), this.totalBytes = this.versionOffset + _(this.entries.length * 4), P.push(this), m.info(`contract defined: ${this.entries.length} field(s), ${f(this.totalBytes)}`, {
413
+ constructor(e, t = {}) {
414
+ this.spec = e, this.codec = t.codec ?? d, this.plugins = t.plugins, this.entries = y(e), this.schemas = F(e);
415
+ let n = 0;
416
+ for (let { path: e, descriptor: t } of this.entries) n = _(n), this.offsets.set(e, n), n += t.byteLength;
417
+ this.versionOffset = _(n), this.totalBytes = this.versionOffset + _(this.entries.length * 4), P.push(this), m.info(`contract defined: ${this.entries.length} field(s), ${f(this.totalBytes)}`, {
418
418
  fields: Object.fromEntries(this.entries.map((e) => [e.path, `${e.descriptor.kind}@${this.offsets.get(e.path)?.toLocaleString()}+${f(e.descriptor.byteLength)}`])),
419
419
  pluginOverrides: Object.keys(this.plugins ?? {})
420
420
  });
@@ -426,7 +426,7 @@ var L = class {
426
426
  let a = this.plugins?.[r.kind] ?? C.get(r.kind);
427
427
  if (!a) throw Error(`Unknown shared memory field kind: ${r.kind}`);
428
428
  m.debug(`bind "${n}" (${r.kind}, ${f(r.byteLength)}) via ${this.plugins?.[r.kind] ? "plugin" : "built-in"} factory`);
429
- let o = a(r, {
429
+ let l = a(r, {
430
430
  buffer: e,
431
431
  codec: this.codec,
432
432
  version: {
@@ -434,20 +434,20 @@ var L = class {
434
434
  index: i
435
435
  },
436
436
  path: n
437
- }, this.offsets.get(n)), u = o.commit;
437
+ }, this.offsets.get(n)), d = l.commit;
438
438
  this.connectors.set(n, {
439
- ...o,
439
+ ...l,
440
440
  write: (e) => {
441
- o.write(e);
441
+ l.write(e);
442
442
  let r = Atomics.add(t, i, 1);
443
- Atomics.notify(t, i), s() && (c({
443
+ Atomics.notify(t, i), o() && (s({
444
444
  type: "memory:write",
445
445
  path: n,
446
446
  version: r + 1
447
- }), d.size && l(this, n, r + 1));
447
+ }), u.size && c(this, n, r + 1));
448
448
  },
449
- ...u && s() ? { commit: () => {
450
- u(), d.size && l(this, n, Atomics.load(t, i));
449
+ ...d && o() ? { commit: () => {
450
+ d(), u.size && c(this, n, Atomics.load(t, i));
451
451
  } } : {},
452
452
  _version: {
453
453
  view: t,
@@ -455,7 +455,7 @@ var L = class {
455
455
  },
456
456
  _path: n
457
457
  });
458
- }), s() && (u(() => P), c({
458
+ }), o() && (l(() => P), s({
459
459
  type: "memory:bind",
460
460
  fields: this.entries.map((e, t) => [t, e.path]),
461
461
  totalBytes: this.totalBytes
File without changes
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
- import { msgpackrCodec as e } from "./index2.js";
2
- import { SchemaError as t, z as n } from "./index3.js";
3
- import { listSchema as r } from "./index4.js";
4
- import { addDevtoolsSink as i, devtoolsEnabled as a, emitDevtools as o, estimateCloneBytes as s, installFetchProbe as c, installMemoryProbe as l, listDevtoolsCommands as u, previewValue as d, registerDevtoolsCommand as f, runDevtoolsCommand as p, setDevtoolsSink as m } from "./index5.js";
5
- import { getLogLevel as h, log as g, scoped as _, setLogLevel as v, setLogSink as y } from "./index7.js";
6
- import { bindSharedMemories as b, defineSharedMemory as x, field as S, getDefinedSharedMemoryCount as C, jsonCodec as w, registerConnectorFactory as T } from "./index8.js";
7
- import { reef as E } from "./index9.js";
8
- import { MemoryManager as D } from "./index10.js";
9
- import { PoolQueueFullError as O, TaskAbortedError as k, TaskTimeoutError as A, WorkerCrashedError as j } from "./index11.js";
10
- import { WorkerPool as M } from "./index15.js";
11
- import { DedicatedWorker as N } from "./index16.js";
12
- import { connectWorker as P, resolveWorkerCount as F, workerClient as I } from "./index17.js";
13
- import { connectSubWorker as L } from "./index18.js";
14
- import { connectSharedWorker as R } from "./index19.js";
15
- import { TaskRegistry as z } from "./index20.js";
16
- import { sharedWorkerHost as B } from "./index21.js";
17
- import { createClient as V, defineService as H, implementService as U, rpc as W, serviceMethod as G } from "./index22.js";
18
- import { RESERVED_CLIENT_KEYS as K, defineWorker as q } from "./index24.js";
19
- import { reactive as J, shallowEqual as Y, watch as X } from "./index26.js";
20
- import { observe as Z } from "./index27.js";
21
- import { defineTask as Q, isAsyncTask as $, toTask as ee } from "./index28.js";
22
- export { N as DedicatedWorker, D as MemoryManager, O as PoolQueueFullError, K as RESERVED_CLIENT_KEYS, t as SchemaError, k as TaskAbortedError, z as TaskRegistry, A as TaskTimeoutError, j as WorkerCrashedError, M as WorkerPool, i as addDevtoolsSink, b as bindSharedMemories, R as connectSharedWorker, L as connectSubWorker, P as connectWorker, V as createClient, H as defineService, x as defineSharedMemory, Q as defineTask, q as defineWorker, a as devtoolsEnabled, o as emitDevtools, s as estimateCloneBytes, S as field, C as getDefinedSharedMemoryCount, h as getLogLevel, U as implementService, c as installFetchProbe, l as installMemoryProbe, $ as isAsyncTask, w as jsonCodec, u as listDevtoolsCommands, r as listSchema, g as log, e as msgpackrCodec, Z as observe, d as previewValue, J as reactive, E as reef, T as registerConnectorFactory, f as registerDevtoolsCommand, F as resolveWorkerCount, W as rpc, p as runDevtoolsCommand, _ as scoped, G as serviceMethod, m as setDevtoolsSink, v as setLogLevel, y as setLogSink, Y as shallowEqual, B as sharedWorkerHost, ee as toTask, X as watch, I as workerClient, n as z };
1
+ import { SchemaError as e, z as t } from "./contract/zod.js";
2
+ import { listSchema as n } from "./contract/listSchema.js";
3
+ import { addDevtoolsSink as r, devtoolsEnabled as i, emitDevtools as a, estimateCloneBytes as o, installFetchProbe as s, installMemoryProbe as c, listDevtoolsCommands as l, previewValue as u, registerDevtoolsCommand as d, runDevtoolsCommand as f, setDevtoolsSink as p } from "./devtools.js";
4
+ import { msgpackrCodec as m } from "./contract/msgpackrCodec.js";
5
+ import { reef as h } from "./contract/reef.js";
6
+ import { getLogLevel as g, log as _, scoped as v, setLogLevel as y, setLogSink as b } from "./log.js";
7
+ import { bindSharedMemories as x, defineSharedMemory as S, field as C, getDefinedSharedMemoryCount as w, jsonCodec as T, registerConnectorFactory as E } from "./contract/sharedMemory.js";
8
+ import { MemoryManager as D } from "./pool/memory.js";
9
+ import { PoolQueueFullError as O, TaskAbortedError as k, TaskTimeoutError as A, WorkerCrashedError as j } from "./pool/errors.js";
10
+ import { WorkerPool as M } from "./pool/workerPool.js";
11
+ import { DedicatedWorker as N } from "./pool/dedicatedWorker.js";
12
+ import { connectWorker as P, resolveWorkerCount as F, workerClient as I } from "./pool/workerClient.js";
13
+ import { connectSubWorker as L } from "./pool/subWorkerClient.js";
14
+ import { connectSharedWorker as R } from "./shared/sharedWorkerClient.js";
15
+ import { TaskRegistry as z } from "./worker/registry.js";
16
+ import { sharedWorkerHost as B } from "./shared/sharedWorkerHost.js";
17
+ import { createClient as V, defineService as H, implementService as U, rpc as W, serviceMethod as G } from "./service.js";
18
+ import { RESERVED_CLIENT_KEYS as K, defineWorker as q } from "./worker/defineWorker.js";
19
+ import { reactive as J, shallowEqual as Y, watch as X } from "./reactive.js";
20
+ import { observe as Z } from "./observable.js";
21
+ import { defineTask as Q, isAsyncTask as $, toTask as ee } from "./task.js";
22
+ export { N as DedicatedWorker, D as MemoryManager, O as PoolQueueFullError, K as RESERVED_CLIENT_KEYS, e as SchemaError, k as TaskAbortedError, z as TaskRegistry, A as TaskTimeoutError, j as WorkerCrashedError, M as WorkerPool, r as addDevtoolsSink, x as bindSharedMemories, R as connectSharedWorker, L as connectSubWorker, P as connectWorker, V as createClient, H as defineService, S as defineSharedMemory, Q as defineTask, q as defineWorker, i as devtoolsEnabled, a as emitDevtools, o as estimateCloneBytes, C as field, w as getDefinedSharedMemoryCount, g as getLogLevel, U as implementService, s as installFetchProbe, c as installMemoryProbe, $ as isAsyncTask, T as jsonCodec, l as listDevtoolsCommands, n as listSchema, _ as log, m as msgpackrCodec, Z as observe, u as previewValue, J as reactive, h as reef, E as registerConnectorFactory, d as registerDevtoolsCommand, F as resolveWorkerCount, W as rpc, f as runDevtoolsCommand, v as scoped, G as serviceMethod, p as setDevtoolsSink, y as setLogLevel, b as setLogSink, Y as shallowEqual, B as sharedWorkerHost, ee as toTask, X as watch, I as workerClient, t as z };
@@ -1,4 +1,4 @@
1
- import { devtoolsEnabled as e, emitDevtools as t, previewValue as n } from "./index5.js";
1
+ import { devtoolsEnabled as e, emitDevtools as t, previewValue as n } from "./devtools.js";
2
2
  //#region src/log.ts
3
3
  var r = {
4
4
  trace: 0,
@@ -1,6 +1,6 @@
1
- import { scoped as e } from "./index7.js";
2
- import { relabelNode as t } from "./index25.js";
3
- import { watchNodes as n } from "./index26.js";
1
+ import { scoped as e } from "./log.js";
2
+ import { relabelNode as t } from "./reactiveGraph.js";
3
+ import { watchNodes as n } from "./reactive.js";
4
4
  //#region src/observable.ts
5
5
  var r = e("observe");
6
6
  function i(e, i, a, o) {
@@ -1,9 +1,9 @@
1
- import { devtoolsEnabled as e, emitDevtools as t, estimateCloneBytes as n, nextDevtoolsId as r } from "./index5.js";
2
- import { fmtBytes as i, scoped as a } from "./index7.js";
3
- import { TaskAbortedError as o, TaskTimeoutError as s, WorkerCrashedError as c } from "./index11.js";
4
- import { measureTaskCall as l } from "./index12.js";
5
- import { forwardWorkerDevtools as u, sendInit as d, setupChannelMemory as f } from "./index13.js";
6
- import { CHAOS_FAILURE as p, KILL_MESSAGE as m, applyChaos as h, registerDevtoolsRunner as g } from "./index14.js";
1
+ import { devtoolsEnabled as e, emitDevtools as t, estimateCloneBytes as n, nextDevtoolsId as r } from "../devtools.js";
2
+ import { fmtBytes as i, scoped as a } from "../log.js";
3
+ import { TaskAbortedError as o, TaskTimeoutError as s, WorkerCrashedError as c } from "./errors.js";
4
+ import { measureTaskCall as l } from "../userTiming.js";
5
+ import { forwardWorkerDevtools as u, sendInit as d, setupChannelMemory as f } from "./workerChannel.js";
6
+ import { CHAOS_FAILURE as p, KILL_MESSAGE as m, applyChaos as h, registerDevtoolsRunner as g } from "./devtoolsCommands.js";
7
7
  //#region src/pool/dedicatedWorker.ts
8
8
  var _ = a("worker"), v = a("task"), y = () => ({
9
9
  count: 0,
@@ -1,4 +1,4 @@
1
- import { registerDevtoolsCommand as e } from "./index5.js";
1
+ import { registerDevtoolsCommand as e } from "../devtools.js";
2
2
  //#region src/pool/devtoolsCommands.ts
3
3
  var t = "chaos: injected failure", n = "killed from devtools", r = /* @__PURE__ */ new Map(), i = null, a = (e) => {
4
4
  let t = e.poolId;
@@ -1,4 +1,4 @@
1
- import { connectWorker as e } from "./index17.js";
1
+ import { connectWorker as e } from "./workerClient.js";
2
2
  //#region src/pool/subWorkerClient.ts
3
3
  function t(t) {
4
4
  let n = { ...t };
@@ -1,5 +1,5 @@
1
- import { devtoolsEnabled as e, forwardDevtools as t } from "./index5.js";
2
- import { MemoryManager as n } from "./index10.js";
1
+ import { devtoolsEnabled as e, forwardDevtools as t } from "../devtools.js";
2
+ import { MemoryManager as n } from "./memory.js";
3
3
  //#region src/pool/workerChannel.ts
4
4
  function r(e, t) {
5
5
  if ((e.sharedMemory || e.sharedBuffer !== void 0) && (typeof SharedArrayBuffer > "u" || typeof crossOriginIsolated < "u" && !crossOriginIsolated)) throw Error(`${t} requires SharedArrayBuffer in a cross-origin isolated context — serve the page with COOP/COEP headers.`);
@@ -1,5 +1,5 @@
1
- import { WorkerPool as e } from "./index15.js";
2
- import { DedicatedWorker as t } from "./index16.js";
1
+ import { WorkerPool as e } from "./workerPool.js";
2
+ import { DedicatedWorker as t } from "./dedicatedWorker.js";
3
3
  //#region src/pool/workerClient.ts
4
4
  var n = (e, t, r, i) => {
5
5
  let a = /* @__PURE__ */ new Map();
@@ -1,9 +1,9 @@
1
- import { devtoolsEnabled as e, emitDevtools as t, estimateCloneBytes as n, nextDevtoolsId as r } from "./index5.js";
2
- import { fmtBytes as i, scoped as a } from "./index7.js";
3
- import { PoolQueueFullError as o, TaskAbortedError as s, TaskTimeoutError as c, WorkerCrashedError as l } from "./index11.js";
4
- import { measureTaskCall as u } from "./index12.js";
5
- import { forwardWorkerDevtools as d, sendInit as f, setupChannelMemory as p } from "./index13.js";
6
- import { CHAOS_FAILURE as m, KILL_MESSAGE as h, applyChaos as g, registerDevtoolsRunner as _ } from "./index14.js";
1
+ import { devtoolsEnabled as e, emitDevtools as t, estimateCloneBytes as n, nextDevtoolsId as r } from "../devtools.js";
2
+ import { fmtBytes as i, scoped as a } from "../log.js";
3
+ import { PoolQueueFullError as o, TaskAbortedError as s, TaskTimeoutError as c, WorkerCrashedError as l } from "./errors.js";
4
+ import { measureTaskCall as u } from "../userTiming.js";
5
+ import { forwardWorkerDevtools as d, sendInit as f, setupChannelMemory as p } from "./workerChannel.js";
6
+ import { CHAOS_FAILURE as m, KILL_MESSAGE as h, applyChaos as g, registerDevtoolsRunner as _ } from "./devtoolsCommands.js";
7
7
  //#region src/pool/workerPool.ts
8
8
  var v = a("pool"), y = a("task"), b = () => ({
9
9
  count: 0,
@@ -1,5 +1,5 @@
1
- import { scoped as e } from "./index7.js";
2
- import { disposeNodes as t, graphNode as n, graphSource as r } from "./index25.js";
1
+ import { scoped as e } from "./log.js";
2
+ import { disposeNodes as t, graphNode as n, graphSource as r } from "./reactiveGraph.js";
3
3
  import { createEffect as i, createMemo as a, createRenderEffect as o, createRoot as s, createSignal as c } from "solid-js";
4
4
  //#region src/reactive.ts
5
5
  var l = e("reactive");
@@ -1,4 +1,4 @@
1
- import { devtoolsEnabled as e, emitDevtools as t, registerDevtoolsCommand as n } from "./index5.js";
1
+ import { devtoolsEnabled as e, emitDevtools as t, registerDevtoolsCommand as n } from "./devtools.js";
2
2
  //#region src/reactiveGraph.ts
3
3
  var r = typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "worker" : "main", i = 0, a = /* @__PURE__ */ new Map(), o = !1, s = (e, n) => {
4
4
  t({
@@ -1,5 +1,5 @@
1
- import { scoped as e } from "./index7.js";
2
- import { TaskRegistry as t } from "./index20.js";
1
+ import { scoped as e } from "./log.js";
2
+ import { TaskRegistry as t } from "./worker/registry.js";
3
3
  //#region src/service.ts
4
4
  var n = e("service");
5
5
  function r(e = {}) {
@@ -1,4 +1,4 @@
1
- import { scoped as e } from "./index7.js";
1
+ import { scoped as e } from "../log.js";
2
2
  //#region src/shared/sharedWorkerClient.ts
3
3
  var t = e("shared-client"), n = e("task"), r = class {
4
4
  clientIndex;
@@ -1,7 +1,7 @@
1
- import { fmtBytes as e, scoped as t } from "./index7.js";
2
- import { bindSharedMemories as n } from "./index8.js";
3
- import { MemoryManager as r } from "./index10.js";
4
- import { TaskRegistry as i } from "./index20.js";
1
+ import { fmtBytes as e, scoped as t } from "../log.js";
2
+ import { bindSharedMemories as n } from "../contract/sharedMemory.js";
3
+ import { MemoryManager as r } from "../pool/memory.js";
4
+ import { TaskRegistry as i } from "../worker/registry.js";
5
5
  //#region src/shared/sharedWorkerHost.ts
6
6
  var a = t("shared-worker"), o = null, s = 0;
7
7
  function c(t, i) {
@@ -1,4 +1,4 @@
1
- import { scoped as e } from "./index7.js";
1
+ import { scoped as e } from "./log.js";
2
2
  //#region src/task.ts
3
3
  var t = e("task");
4
4
  function n(e) {
@@ -0,0 +1,110 @@
1
+ import { bindSharedMemories as e } from "../contract/sharedMemory.js";
2
+ import { TaskRegistry as t } from "../worker/registry.js";
3
+ //#region src/testing/inProcessWorker.ts
4
+ var n = class n {
5
+ url;
6
+ options;
7
+ static created = [];
8
+ static handlerModules = [];
9
+ executed = [];
10
+ terminated = !1;
11
+ listeners = {
12
+ message: /* @__PURE__ */ new Set(),
13
+ error: /* @__PURE__ */ new Set()
14
+ };
15
+ ready = null;
16
+ dead = !1;
17
+ constructor(e, t) {
18
+ this.url = e, this.options = t, n.created.push(this);
19
+ }
20
+ postMessage(e) {
21
+ queueMicrotask(() => void this.handle(e));
22
+ }
23
+ boot() {
24
+ return (async () => {
25
+ globalThis.self ??= {
26
+ postMessage() {},
27
+ onmessage: null
28
+ };
29
+ for (let e of n.handlerModules) await e();
30
+ })();
31
+ }
32
+ crashOnBoot(e) {
33
+ this.dead = !0;
34
+ let t = {
35
+ type: "error",
36
+ message: `worker entry failed to load: ${e?.message ?? String(e)}`,
37
+ error: e instanceof Error ? e : Error(String(e))
38
+ };
39
+ for (let e of this.listeners.error) e(t);
40
+ }
41
+ async handle(n) {
42
+ if (n.type === "INIT") {
43
+ this.ready ??= this.boot();
44
+ try {
45
+ await this.ready;
46
+ } catch (e) {
47
+ this.crashOnBoot(e);
48
+ }
49
+ return;
50
+ }
51
+ if (n.type === "INIT_MEMORY") {
52
+ let t = n.memory?.buffer ?? n.buffer;
53
+ this.ready ??= this.boot().then(() => {
54
+ t && e(t);
55
+ });
56
+ try {
57
+ await this.ready;
58
+ } catch (e) {
59
+ this.crashOnBoot(e);
60
+ }
61
+ return;
62
+ }
63
+ if (n.type === "EXECUTE_TASK") {
64
+ if (this.dead) return;
65
+ try {
66
+ await this.ready;
67
+ } catch {
68
+ return;
69
+ }
70
+ if (this.dead) return;
71
+ this.executed.push(n);
72
+ try {
73
+ let e = await t.execute(n.taskId, ...n.args || []);
74
+ this.emit({
75
+ messageId: n.messageId,
76
+ success: !0,
77
+ result: e
78
+ });
79
+ } catch (e) {
80
+ this.emit({
81
+ messageId: n.messageId,
82
+ success: !1,
83
+ error: e.message || String(e)
84
+ });
85
+ }
86
+ }
87
+ }
88
+ emit(e) {
89
+ for (let t of this.listeners.message) t({ data: e });
90
+ }
91
+ crash(e = "simulated crash") {
92
+ let t = {
93
+ type: "error",
94
+ message: e,
95
+ error: Error(e)
96
+ };
97
+ for (let e of this.listeners.error) e(t);
98
+ }
99
+ addEventListener(e, t) {
100
+ e === "error" ? this.listeners.error.add(t) : this.listeners.message.add(t);
101
+ }
102
+ removeEventListener(e, t) {
103
+ e === "error" ? this.listeners.error.delete(t) : this.listeners.message.delete(t);
104
+ }
105
+ terminate() {
106
+ this.terminated = !0;
107
+ }
108
+ }, r = () => new Promise((e) => setTimeout(e, 5));
109
+ //#endregion
110
+ export { n as InProcessWorker, r as flushObservers };
@@ -1,6 +1,6 @@
1
- import { scoped as e } from "./index7.js";
2
- import { TaskRegistry as t } from "./index20.js";
3
- import { installWorkerListener as n } from "./index23.js";
1
+ import { scoped as e } from "../log.js";
2
+ import { TaskRegistry as t } from "./registry.js";
3
+ import { installWorkerListener as n } from "./workerBootstrap.js";
4
4
  //#region src/worker/defineWorker.ts
5
5
  var r = e("worker"), i = [
6
6
  "start",
@@ -1,4 +1,4 @@
1
- import { scoped as e } from "./index7.js";
1
+ import { scoped as e } from "../log.js";
2
2
  //#region src/worker/registry.ts
3
3
  var t = e("registry"), n = class {
4
4
  static tasks = /* @__PURE__ */ new Map();
@@ -1,8 +1,8 @@
1
- import { devtoolsEnabled as e, enableWorkerDevtoolsForwarding as t } from "./index5.js";
2
- import { fmtBytes as n, scoped as r } from "./index7.js";
3
- import { bindSharedMemories as i, getDefinedSharedMemoryCount as a } from "./index8.js";
4
- import { measureAtoll as o } from "./index12.js";
5
- import { TaskRegistry as s } from "./index20.js";
1
+ import { devtoolsEnabled as e, enableWorkerDevtoolsForwarding as t } from "../devtools.js";
2
+ import { fmtBytes as n, scoped as r } from "../log.js";
3
+ import { bindSharedMemories as i, getDefinedSharedMemoryCount as a } from "../contract/sharedMemory.js";
4
+ import { measureAtoll as o } from "../userTiming.js";
5
+ import { TaskRegistry as s } from "./registry.js";
6
6
  //#region src/worker/workerBootstrap.ts
7
7
  var c = r("worker"), l = (e, t, n, r) => {
8
8
  let i = performance.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolljs/core",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Typed shared-memory worker pools — defineWorker/connectWorker, SharedArrayBuffer contracts, cross-thread reactivity",
5
5
  "homepage": "https://jwhenry3.github.io/atolljs/consumer/quickstart/",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  "./package.json": "./package.json",
15
15
  "./*": {
16
16
  "types": "./dist/*.d.ts",
17
- "default": "./src/*"
17
+ "default": "./dist/*.js"
18
18
  }
19
19
  },
20
20
  "files": [
@@ -41,7 +41,8 @@
41
41
  "build:extension": "node packages/devtools-extension/scripts/build.mjs",
42
42
  "assemble:pages": "node scripts/assemble-pages.mjs",
43
43
  "serve:pages": "node scripts/serve-pages.mjs",
44
- "serve:static": "node scripts/serve-static.mjs"
44
+ "serve:static": "node scripts/serve-static.mjs",
45
+ "approve:staged": "node scripts/approve-staged.mjs"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@angular/core": "^22.2.0",
@@ -49,6 +50,7 @@
49
50
  "@angular/platform-browser-dynamic": "^22.2.0",
50
51
  "@nestjs/common": "^12.1.2",
51
52
  "@nestjs/core": "^12.1.2",
53
+ "@nx/devkit": "23.3.0",
52
54
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
53
55
  "@types/react": "^19.3.0",
54
56
  "@types/react-dom": "^19.3.0",
@@ -58,6 +60,7 @@
58
60
  "fast-json-stringify": "^7.0.1",
59
61
  "happy-dom": "^20.14.5",
60
62
  "htmlparser2": "^12.0.0",
63
+ "nx": "23.3.0",
61
64
  "react": "^19.3.0",
62
65
  "react-dom": "^19.3.0",
63
66
  "react-reconciler": "^0.34.0",
@@ -74,6 +77,11 @@
74
77
  "msgpackr": "^2.1.0",
75
78
  "solid-js": "^1.9.15"
76
79
  },
80
+ "overrides": {
81
+ "nx": {
82
+ "undici": "7.29.1"
83
+ }
84
+ },
77
85
  "repository": {
78
86
  "type": "git",
79
87
  "url": "https://github.com/jwhenry3/atolljs"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes