@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
package/dist/index5.js ADDED
@@ -0,0 +1,481 @@
1
+ import { msgpackrCodec as e } from "./index2.js";
2
+ import { memberToSpec as t, zodArrayInfo as n, zodObjectShape as r, zodStringBytes as i } from "./index3.js";
3
+ import { fmtBytes as a, scoped as o } from "./index4.js";
4
+ import { z as s } from "zod";
5
+ //#region src/contract/sharedMemory.ts
6
+ var c = o("memory"), l = 8, u = (e, t) => e + t - 1 & ~(t - 1), d = (e) => u(e, l), f = (e) => typeof e == "object" && !!e && typeof e.kind == "string" && typeof e.byteLength == "number";
7
+ function p(e) {
8
+ let t = [];
9
+ for (let [n, r] of Object.entries(e)) if (f(r)) t.push({
10
+ path: n,
11
+ descriptor: r
12
+ });
13
+ else for (let [e, i] of Object.entries(r)) {
14
+ if (!f(i)) throw TypeError(`shared memory "${n}.${e}" is not a field descriptor — intent groups nest one level only`);
15
+ t.push({
16
+ path: `${n}.${e}`,
17
+ descriptor: i
18
+ });
19
+ }
20
+ return t;
21
+ }
22
+ var m = new TextEncoder(), h = new TextDecoder(), g = {
23
+ encode: (e) => m.encode(JSON.stringify(e)),
24
+ decode: (e) => JSON.parse(h.decode(e))
25
+ }, _ = /* @__PURE__ */ new Map();
26
+ function v(e, t) {
27
+ _.set(e, t);
28
+ }
29
+ var y = {
30
+ i8: 1,
31
+ u8: 1,
32
+ i16: 2,
33
+ u16: 2,
34
+ i32: 4,
35
+ u32: 4,
36
+ f32: 4,
37
+ f64: 8,
38
+ i64: 8,
39
+ u64: 8
40
+ }, b = (e) => typeof e == "string" ? y[e] : "string" in e ? e.string : 1, x = (e) => typeof e == "string" ? y[e] : 1;
41
+ function S(e) {
42
+ let n = {}, r = {}, i = 0;
43
+ for (let a of Object.keys(e)) {
44
+ let o = t(e[a], String(a));
45
+ r[a] = o, i = u(i, x(o)), n[a] = i, i += b(o);
46
+ }
47
+ return {
48
+ layout: r,
49
+ offsets: n,
50
+ recordSize: d(i)
51
+ };
52
+ }
53
+ var C = {
54
+ number: () => ({
55
+ kind: "number",
56
+ byteLength: 8
57
+ }),
58
+ boolean: () => ({
59
+ kind: "boolean",
60
+ byteLength: 8
61
+ }),
62
+ string: (e) => {
63
+ let { schema: t, maxBytes: n } = e;
64
+ if (n !== void 0) return {
65
+ kind: "string",
66
+ byteLength: 4 + n,
67
+ schema: t
68
+ };
69
+ let r = t ? i(t) : null;
70
+ if (r !== null) return {
71
+ kind: "string",
72
+ byteLength: 4 + r,
73
+ schema: t
74
+ };
75
+ throw TypeError("field.string: pass { maxBytes } or a schema carrying a byte budget — mz.string(n) / z.string().meta({ bytes: n })");
76
+ },
77
+ object: (e) => {
78
+ let { schema: t, maxBytes: n } = e;
79
+ if (n === void 0 && t) {
80
+ let e = r(t);
81
+ if (e) {
82
+ let { layout: n, offsets: r, recordSize: i } = S(e);
83
+ return {
84
+ kind: "object",
85
+ byteLength: 8 + i,
86
+ schema: t,
87
+ layout: n,
88
+ offsets: r,
89
+ recordSize: i
90
+ };
91
+ }
92
+ throw TypeError("field.object: schema can't derive a fixed byte width (not a zod object of fixed-width members) — pass { maxBytes } for codec-encoded storage");
93
+ }
94
+ if (n === void 0) throw TypeError("field.object: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
95
+ return {
96
+ kind: "object",
97
+ byteLength: 4 + n,
98
+ schema: t
99
+ };
100
+ },
101
+ array: (e) => {
102
+ let { schema: r, maxBytes: i } = e;
103
+ if (i === void 0 && r) {
104
+ let e = n(r);
105
+ if (e) {
106
+ if (e.capacity === null) throw TypeError("field.array: z.array() needs .max(n) or .length(n) — bounded arrays are fixed-width");
107
+ let n;
108
+ try {
109
+ n = t(e.element, "array element");
110
+ } catch (e) {
111
+ throw TypeError(`field.array: element isn't a fixed-width member — use field.list for arrays of records (${e.message})`);
112
+ }
113
+ let i = u(b(n), x(n));
114
+ return {
115
+ kind: "array",
116
+ byteLength: 8 + e.capacity * i,
117
+ schema: r,
118
+ element: n,
119
+ elementStride: i,
120
+ capacity: e.capacity
121
+ };
122
+ }
123
+ throw TypeError("field.array: schema can't derive a fixed byte width (not a bounded zod array) — pass { maxBytes } for codec-encoded storage");
124
+ }
125
+ if (i === void 0) throw TypeError("field.array: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
126
+ return {
127
+ kind: "array",
128
+ byteLength: 4 + i,
129
+ schema: r
130
+ };
131
+ },
132
+ int32Array: ({ length: e }) => ({
133
+ kind: "Int32",
134
+ byteLength: e * 4
135
+ }),
136
+ float64Array: ({ length: e }) => ({
137
+ kind: "Float64",
138
+ byteLength: e * 8
139
+ }),
140
+ bigInt64Array: ({ length: e }) => ({
141
+ kind: "BigInt64",
142
+ byteLength: e * 8
143
+ }),
144
+ uint8Array: ({ length: e }) => ({
145
+ kind: "Uint8",
146
+ byteLength: e
147
+ }),
148
+ list: ({ schema: e, count: t }) => {
149
+ let n = r(e);
150
+ if (!n) throw TypeError("field.list: schema must be an mz.object() of fixed-width members");
151
+ let { layout: i, offsets: a, recordSize: o } = S(n);
152
+ return {
153
+ kind: "list",
154
+ byteLength: o * t,
155
+ schema: e,
156
+ layout: i,
157
+ offsets: a,
158
+ recordSize: o,
159
+ count: t
160
+ };
161
+ }
162
+ }, w = {
163
+ Int32: Int32Array,
164
+ Float64: Float64Array,
165
+ BigInt64: BigInt64Array,
166
+ Uint8: Uint8Array
167
+ };
168
+ v("number", (e, t, n) => {
169
+ let r = new Float64Array(t.buffer, n, 1);
170
+ return {
171
+ byteOffset: n,
172
+ byteLength: e.byteLength,
173
+ read: () => r[0],
174
+ write: (e) => {
175
+ r[0] = e;
176
+ }
177
+ };
178
+ }), v("boolean", (e, t, n) => {
179
+ let r = new Uint8Array(t.buffer, n, 1);
180
+ return {
181
+ byteOffset: n,
182
+ byteLength: e.byteLength,
183
+ read: () => r[0] === 1,
184
+ write: (e) => {
185
+ r[0] = +!!e;
186
+ }
187
+ };
188
+ });
189
+ for (let e of Object.keys(w)) v(e, (t, n, r) => {
190
+ let i = w[e], a = new i(n.buffer, r, t.byteLength / i.BYTES_PER_ELEMENT);
191
+ return {
192
+ byteOffset: r,
193
+ byteLength: t.byteLength,
194
+ read: () => a,
195
+ write: (e) => a.set(e)
196
+ };
197
+ });
198
+ v("string", (e, t, n) => {
199
+ let r = new TextEncoder(), i = new TextDecoder(), a = e.byteLength - 4, o = new Uint32Array(t.buffer, n, 1), s = (e) => {
200
+ if (e.byteLength > a) throw Error(`Encoded value of ${e.byteLength} bytes exceeds field capacity of ${a} bytes at offset ${n}`);
201
+ o[0] = e.byteLength, new Uint8Array(t.buffer, n + 4, e.byteLength).set(e);
202
+ }, c = () => new Uint8Array(t.buffer, n + 4, o[0]).slice();
203
+ return {
204
+ byteOffset: n,
205
+ byteLength: e.byteLength,
206
+ read: () => i.decode(c()),
207
+ write: (t) => s(r.encode(e.schema ? e.schema.parse(t) : t))
208
+ };
209
+ });
210
+ function T(e) {
211
+ let t = new DataView(e.buffer), n = new Uint8Array(e.buffer), r = new TextEncoder(), i = new TextDecoder(), a = {
212
+ i8: {
213
+ get: (e) => t.getInt8(e),
214
+ set: (e, n) => t.setInt8(e, n)
215
+ },
216
+ u8: {
217
+ get: (e) => t.getUint8(e),
218
+ set: (e, n) => t.setUint8(e, n)
219
+ },
220
+ i16: {
221
+ get: (e) => t.getInt16(e),
222
+ set: (e, n) => t.setInt16(e, n)
223
+ },
224
+ u16: {
225
+ get: (e) => t.getUint16(e),
226
+ set: (e, n) => t.setUint16(e, n)
227
+ },
228
+ i32: {
229
+ get: (e) => t.getInt32(e),
230
+ set: (e, n) => t.setInt32(e, n)
231
+ },
232
+ u32: {
233
+ get: (e) => t.getUint32(e),
234
+ set: (e, n) => t.setUint32(e, n)
235
+ },
236
+ f32: {
237
+ get: (e) => t.getFloat32(e),
238
+ set: (e, n) => t.setFloat32(e, n)
239
+ },
240
+ f64: {
241
+ get: (e) => t.getFloat64(e),
242
+ set: (e, n) => t.setFloat64(e, n)
243
+ },
244
+ i64: {
245
+ get: (e) => t.getBigInt64(e),
246
+ set: (e, n) => t.setBigInt64(e, n)
247
+ },
248
+ u64: {
249
+ get: (e) => t.getBigUint64(e),
250
+ set: (e, n) => t.setBigUint64(e, n)
251
+ }
252
+ }, o = (e, t) => {
253
+ let r = n.indexOf(0, e), a = r === -1 || r - e >= t ? t : r - e;
254
+ return i.decode(n.slice(e, e + a));
255
+ }, s = /* @__PURE__ */ new Uint8Array(64), c = (e, t, i) => {
256
+ s.length < t && (s = new Uint8Array(t));
257
+ let { read: a, written: o } = r.encodeInto(i, s);
258
+ if (a < i.length || o > t) throw Error(`String exceeds inline field capacity of ${t} bytes`);
259
+ n.set(s.subarray(0, o), e), o < t && n.fill(0, e + o, e + t);
260
+ }, l = (e) => {
261
+ if (typeof e == "string") {
262
+ let t = a[e];
263
+ return {
264
+ get: (e) => t.get(e),
265
+ set: (e, n) => t.set(e, n)
266
+ };
267
+ }
268
+ return "bool" in e ? {
269
+ get: (e) => !!t.getUint8(e),
270
+ set: (e, n) => t.setUint8(e, +!!n)
271
+ } : {
272
+ get: (t) => o(t, e.string),
273
+ set: (t, n) => c(t, e.string, n)
274
+ };
275
+ };
276
+ return {
277
+ ops: l,
278
+ compile: (e, t) => {
279
+ let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
280
+ for (let i of Object.keys(e)) {
281
+ let { get: a, set: o } = l(e[i]), s = t[i];
282
+ n.set(i, (e, t) => {
283
+ t[i] = a(e + s);
284
+ }), r.set(i, (e, t) => o(e + s, t[i]));
285
+ }
286
+ let i = [...n.values()], a = [...r.values()];
287
+ return {
288
+ read(e, t = {}, r) {
289
+ if (r) for (let i of r) n.get(i)(e, t);
290
+ else for (let n of i) n(e, t);
291
+ return t;
292
+ },
293
+ write(e, t, n) {
294
+ if (n) for (let i of n) r.get(i)(e, t);
295
+ else for (let n of a) n(e, t);
296
+ }
297
+ };
298
+ }
299
+ };
300
+ }
301
+ var E = (e, t, n) => {
302
+ let { schema: r, byteLength: i, kind: a } = e, o = e;
303
+ if (o.layout && o.offsets && o.recordSize !== void 0) {
304
+ let e = new Uint32Array(t.buffer, n, 2), a = n + 8, s = T(t).compile(o.layout, o.offsets);
305
+ return {
306
+ byteOffset: n,
307
+ byteLength: i,
308
+ read: () => e[0] ? s.read(a, {}) : void 0,
309
+ write: (t) => {
310
+ s.write(a, r ? r.parse(t) : t), e[0] = 1;
311
+ }
312
+ };
313
+ }
314
+ if (o.element !== void 0 && o.elementStride !== void 0 && o.capacity !== void 0) {
315
+ let e = new Uint32Array(t.buffer, n, 1), a = new Uint32Array(t.buffer, n + 4, 1), s = T(t).ops(o.element), c = o.elementStride, l = o.capacity, u = n + 8;
316
+ return {
317
+ byteOffset: n,
318
+ byteLength: i,
319
+ read: () => {
320
+ if (!e[0]) return;
321
+ let t = a[0];
322
+ return Array.from({ length: t }, (e, t) => s.get(u + t * c));
323
+ },
324
+ write: (t) => {
325
+ let n = r ? r.parse(t) : t;
326
+ if (n.length > l) throw Error(`${n.length} elements exceeds array capacity of ${l}`);
327
+ n.forEach((e, t) => s.set(u + t * c, e)), a[0] = n.length, e[0] = 1;
328
+ }
329
+ };
330
+ }
331
+ let s = i - 4, c = new Uint32Array(t.buffer, n, 1), l = (e) => {
332
+ if (e.byteLength > s) throw Error(`Encoded value of ${e.byteLength} bytes exceeds field capacity of ${s} bytes at offset ${n}`);
333
+ c[0] = e.byteLength, new Uint8Array(t.buffer, n + 4, e.byteLength).set(e);
334
+ }, u = () => new Uint8Array(t.buffer, n + 4, c[0]).slice();
335
+ return {
336
+ byteOffset: n,
337
+ byteLength: i,
338
+ read: () => {
339
+ let e = u();
340
+ if (e.byteLength === 0) return;
341
+ let n = t.codec.decode(e);
342
+ return r ? r.parse(n) : n;
343
+ },
344
+ write: (e) => l(t.codec.encode(r ? r.parse(e) : e))
345
+ };
346
+ };
347
+ v("object", E), v("array", E);
348
+ function D(e, t, n) {
349
+ let r = e, { offsets: i, recordSize: a, count: o } = r, s = T(t).compile(r.layout, i), c = (e) => {
350
+ if (e < 0 || e >= o) throw RangeError(`Record index ${e} out of bounds (0..${o - 1})`);
351
+ }, l = (e, t = {}, r) => (c(e), s.read(n + e * a, t, r)), u = (e, t, r) => {
352
+ c(e), s.write(n + e * a, t, r);
353
+ };
354
+ return {
355
+ byteOffset: n,
356
+ byteLength: e.byteLength,
357
+ recordCount: o,
358
+ recordSize: a,
359
+ readAt: l,
360
+ writeAt: u,
361
+ commit: () => {
362
+ t.version && (Atomics.add(t.version.view, t.version.index, 1), Atomics.notify(t.version.view, t.version.index));
363
+ },
364
+ read: () => Array.from({ length: o }, (e, t) => l(t)),
365
+ write: (e) => {
366
+ if (e.length > o) throw Error(`${e.length} records exceeds list array capacity of ${o}`);
367
+ e.forEach((e, t) => u(t, e));
368
+ }
369
+ };
370
+ }
371
+ v("list", D);
372
+ var O = [];
373
+ function k(e) {
374
+ let t = {};
375
+ for (let [n, r] of Object.entries(e)) t[n] = f(r) ? A(r) : Object.fromEntries(Object.entries(r).map(([e, t]) => [e, A(t)]));
376
+ return t;
377
+ }
378
+ function A(e) {
379
+ if (e.schema) return e.schema;
380
+ switch (e.kind) {
381
+ case "number": return s.number();
382
+ case "boolean": return s.boolean();
383
+ case "string": return s.string();
384
+ case "Int32": return s.instanceof(Int32Array);
385
+ case "Float64": return s.instanceof(Float64Array);
386
+ case "BigInt64": return s.instanceof(BigInt64Array);
387
+ case "Uint8": return s.instanceof(Uint8Array);
388
+ default: return s.unknown();
389
+ }
390
+ }
391
+ var j = class {
392
+ totalBytes;
393
+ spec;
394
+ schemas;
395
+ codec;
396
+ plugins;
397
+ entries;
398
+ offsets = /* @__PURE__ */ new Map();
399
+ versionOffset;
400
+ connectors = /* @__PURE__ */ new Map();
401
+ boundListeners = /* @__PURE__ */ new Set();
402
+ isBound = !1;
403
+ constructor(t, n = {}) {
404
+ this.spec = t, this.codec = n.codec ?? e, this.plugins = n.plugins, this.entries = p(t), this.schemas = k(t);
405
+ let r = 0;
406
+ for (let { path: e, descriptor: t } of this.entries) r = d(r), this.offsets.set(e, r), r += t.byteLength;
407
+ this.versionOffset = d(r), this.totalBytes = this.versionOffset + d(this.entries.length * 4), O.push(this), c.info(`contract defined: ${this.entries.length} field(s), ${a(this.totalBytes)}`, {
408
+ fields: Object.fromEntries(this.entries.map((e) => [e.path, `${e.descriptor.kind}@${this.offsets.get(e.path)?.toLocaleString()}+${a(e.descriptor.byteLength)}`])),
409
+ pluginOverrides: Object.keys(this.plugins ?? {})
410
+ });
411
+ }
412
+ bind(e) {
413
+ this.connectors.clear();
414
+ let t = new Int32Array(e, this.versionOffset, this.entries.length);
415
+ this.entries.forEach(({ path: n, descriptor: r }, i) => {
416
+ let o = this.plugins?.[r.kind] ?? _.get(r.kind);
417
+ if (!o) throw Error(`Unknown shared memory field kind: ${r.kind}`);
418
+ c.debug(`bind "${n}" (${r.kind}, ${a(r.byteLength)}) via ${this.plugins?.[r.kind] ? "plugin" : "built-in"} factory`);
419
+ let s = o(r, {
420
+ buffer: e,
421
+ codec: this.codec,
422
+ version: {
423
+ view: t,
424
+ index: i
425
+ }
426
+ }, this.offsets.get(n));
427
+ this.connectors.set(n, {
428
+ ...s,
429
+ write: (e) => {
430
+ s.write(e), Atomics.add(t, i, 1), Atomics.notify(t, i);
431
+ },
432
+ _version: {
433
+ view: t,
434
+ index: i
435
+ }
436
+ });
437
+ }), this.isBound = !0;
438
+ for (let e of [...this.boundListeners]) e();
439
+ }
440
+ get bound() {
441
+ return this.isBound;
442
+ }
443
+ onBound(e) {
444
+ return this.isBound ? (e(), () => {}) : (this.boundListeners.add(e), () => this.boundListeners.delete(e));
445
+ }
446
+ connector(e) {
447
+ let t = String(e), n = this.connectors.get(t);
448
+ if (!n) throw Error(`Shared memory field "${t}" was accessed before the buffer was bound on this thread.`);
449
+ return n;
450
+ }
451
+ };
452
+ function M(e, t = {}) {
453
+ let n = new j(e, t);
454
+ for (let [t, r] of Object.entries(e)) if (f(r)) Object.defineProperty(n, t, {
455
+ enumerable: !0,
456
+ get: () => n.connector(t)
457
+ });
458
+ else {
459
+ let e = {};
460
+ for (let i of Object.keys(r)) Object.defineProperty(e, i, {
461
+ enumerable: !0,
462
+ get: () => n.connector(`${t}.${i}`)
463
+ });
464
+ Object.defineProperty(n, t, {
465
+ enumerable: !0,
466
+ get: () => e
467
+ });
468
+ }
469
+ return n;
470
+ }
471
+ function N(e) {
472
+ for (let t of O) t.bind(e);
473
+ c.info(`bound ${O.length} contract(s) — ${a(e.byteLength)} buffer`);
474
+ }
475
+ function P() {
476
+ return O.length;
477
+ }
478
+ //#endregion
479
+ export { j as SharedMemory, N as bindSharedMemories, M as defineSharedMemory, C as field, P as getDefinedSharedMemoryCount, g as jsonCodec, v as registerConnectorFactory };
480
+
481
+ //# sourceMappingURL=index5.js.map
package/dist/index6.js ADDED
@@ -0,0 +1,23 @@
1
+ import { z as e } from "zod";
2
+ //#region src/contract/mz.ts
3
+ var t = {
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.int32(),
9
+ u32: () => e.uint32(),
10
+ f32: () => e.float32(),
11
+ f64: () => e.float64(),
12
+ i64: () => e.int64(),
13
+ u64: () => e.uint64(),
14
+ int: (t, n) => e.number().int().min(t).max(n),
15
+ boolean: () => e.boolean(),
16
+ string: (t) => e.string().refine((e) => new TextEncoder().encode(e).byteLength <= t, `exceeds ${t} UTF-8 bytes`).meta({ bytes: t }),
17
+ object: (t) => e.object(t),
18
+ array: (t) => e.array(t)
19
+ };
20
+ //#endregion
21
+ export { t as mz };
22
+
23
+ //# sourceMappingURL=index6.js.map
package/dist/index7.js ADDED
@@ -0,0 +1,10 @@
1
+ import { decode as e, encode as t } from "@msgpack/msgpack";
2
+ //#region src/contract/msgpackCodec.ts
3
+ var n = {
4
+ encode: t,
5
+ decode: e
6
+ };
7
+ //#endregion
8
+ export { n as msgpackCodec };
9
+
10
+ //# sourceMappingURL=index7.js.map
package/dist/index8.js ADDED
@@ -0,0 +1,37 @@
1
+ //#region src/pool/memory.ts
2
+ var e = class {
3
+ memory;
4
+ maxPages;
5
+ constructor(e = {}) {
6
+ let t = e.initialPages ?? 16;
7
+ this.maxPages = e.maximumPages ?? 16384, this.memory = new WebAssembly.Memory({
8
+ initial: t,
9
+ maximum: this.maxPages,
10
+ shared: !0
11
+ });
12
+ }
13
+ ensureCapacity(e) {
14
+ let t = this.memory.buffer.byteLength;
15
+ if (t >= e) return;
16
+ let n = e - t, r = Math.ceil(n / 65536);
17
+ if (this.memory.buffer.byteLength / 65536 + r > this.maxPages) throw Error(`Cannot grow memory: exceeds maximum page limit of ${this.maxPages}`);
18
+ this.memory.grow(r);
19
+ }
20
+ getView(e, t = 0, n) {
21
+ let r = this.memory.buffer;
22
+ switch (e) {
23
+ case "Int32": return new Int32Array(r, t, n);
24
+ case "Float64": return new Float64Array(r, t, n);
25
+ case "BigInt64": return new BigInt64Array(r, t, n);
26
+ case "Uint8": return new Uint8Array(r, t, n);
27
+ default: throw Error(`Unsupported view type: ${e}`);
28
+ }
29
+ }
30
+ getBuffer() {
31
+ return this.memory.buffer;
32
+ }
33
+ };
34
+ //#endregion
35
+ export { e as MemoryManager };
36
+
37
+ //# sourceMappingURL=index8.js.map
package/dist/index9.js ADDED
@@ -0,0 +1,22 @@
1
+ //#region src/pool/errors.ts
2
+ var e = class extends Error {
3
+ constructor(e = "WorkerPool task queue is full") {
4
+ super(e), this.name = "PoolQueueFullError";
5
+ }
6
+ }, t = class extends Error {
7
+ constructor(e = "task aborted") {
8
+ super(e), this.name = "AbortError";
9
+ }
10
+ }, n = class extends Error {
11
+ constructor(e = "task timed out") {
12
+ super(e), this.name = "TaskTimeoutError";
13
+ }
14
+ }, r = class extends Error {
15
+ constructor(e = "worker crashed") {
16
+ super(e), this.name = "WorkerCrashedError";
17
+ }
18
+ };
19
+ //#endregion
20
+ export { e as PoolQueueFullError, t as TaskAbortedError, n as TaskTimeoutError, r as WorkerCrashedError };
21
+
22
+ //# sourceMappingURL=index9.js.map
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@atolljs/core",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json",
13
+ "./*": "./src/*"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "!src/**/*.test.ts",
19
+ "!dist/**/*.map"
20
+ ],
21
+ "sideEffects": [
22
+ "**/workerBootstrap.ts",
23
+ "**/workerBootstrap.js"
24
+ ],
25
+ "scripts": {
26
+ "dev:all": "node scripts/dev-all.mjs",
27
+ "kill:all": "node scripts/kill-all.mjs",
28
+ "serve:all": "node scripts/serve-all.mjs",
29
+ "build": "tsc --noEmit && vite build",
30
+ "test": "vitest run",
31
+ "build:pages": "node scripts/build-pages.mjs",
32
+ "assemble:pages": "node scripts/assemble-pages.mjs"
33
+ },
34
+ "devDependencies": {
35
+ "@angular/core": "^22.2.0",
36
+ "@angular/platform-browser": "^22.2.0",
37
+ "@angular/platform-browser-dynamic": "^22.2.0",
38
+ "@nestjs/common": "^11.2.6",
39
+ "@nestjs/core": "^11.2.6",
40
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
41
+ "@types/react": "^19.3.0",
42
+ "@types/react-dom": "^19.3.0",
43
+ "@vitest/coverage-v8": "^4.1.11",
44
+ "fast-json-stringify": "^7.0.1",
45
+ "happy-dom": "^20.14.5",
46
+ "htmlparser2": "^12.0.0",
47
+ "react": "^19.3.0",
48
+ "react-dom": "^19.3.0",
49
+ "react-reconciler": "^0.34.0",
50
+ "reflect-metadata": "^0.2.2",
51
+ "rxjs": "^7.8.2",
52
+ "svelte": "^5.57.1",
53
+ "typescript": "^7.0.2",
54
+ "vite": "^8.3.1",
55
+ "vitest": "^4.1.11",
56
+ "vue": "^3.5.43"
57
+ },
58
+ "dependencies": {
59
+ "@msgpack/msgpack": "^3.1.3",
60
+ "msgpackr": "^2.1.0",
61
+ "solid-js": "^1.9.15",
62
+ "zod": "^4.6.5"
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "https://github.com/jwhenry3/atolljs"
67
+ }
68
+ }