@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/README.md CHANGED
@@ -68,7 +68,7 @@ export const counter = connectWorker<CounterWorker>({
68
68
  // Inline new Worker(new URL(..., import.meta.url)) — every bundler's
69
69
  // worker transform can see the entry point this way.
70
70
  worker: () => new Worker(new URL('./counter.worker.ts', import.meta.url), { type: 'module' }),
71
- poolSize: 'auto', // navigator.hardwareConcurrency, or pass a number
71
+ workers: 'auto', // navigator.hardwareConcurrency; default 1 (one worker, no pool)
72
72
  });
73
73
  // counter.increment(1) → Promise<number>. The pool spawns on first call
74
74
  // (SSR-safe to import); counter.terminate() tears it down.
@@ -0,0 +1,30 @@
1
+ import type { Connector, SharedMemory } from './sharedMemory.js';
2
+ export type WatchRule = {
3
+ text: string;
4
+ test: (value: unknown) => boolean;
5
+ };
6
+ interface WatchState {
7
+ rule: WatchRule;
8
+ /** Per contract: last version checked and last value preview ('change'). */
9
+ seen: WeakMap<SharedMemory<any>, {
10
+ version: number;
11
+ preview: string;
12
+ }>;
13
+ stop: () => void;
14
+ hits: number;
15
+ }
16
+ /** path → watch. Read by the write path — keep `.size` the only hot check. */
17
+ export declare const memoryWatches: Map<string, WatchState>;
18
+ /** Bounded preview of a field's current value — lists/typed arrays read only a head. */
19
+ export declare const fieldPreview: (connector: Connector<any>) => string;
20
+ /**
21
+ * Parse a watch rule: 'change' | '> n' | '< n' | '>= n' | '<= n' | '== v' |
22
+ * '!= v'. `v` is JSON when it parses ('"down"', 'true', '3'), else a bare
23
+ * string. Numeric comparisons only match number/bigint fields.
24
+ */
25
+ export declare const parseWatchRule: (raw: string) => WatchRule;
26
+ /** Write-path hook — only called when `memoryWatches.size > 0`. */
27
+ export declare const checkWatchOnWrite: (memory: SharedMemory<any>, path: string, version: number) => void;
28
+ /** Register the `memory.*` commands once; `contracts` lists every defined contract. */
29
+ export declare const ensureMemoryCommands: (contracts: () => readonly SharedMemory<any>[]) => void;
30
+ export {};
@@ -81,6 +81,8 @@ export interface Connector<T> {
81
81
  view: Int32Array;
82
82
  index: number;
83
83
  };
84
+ /** Internal: the field's contract path — devtools node labels. */
85
+ readonly _path?: string;
84
86
  }
85
87
  export type ScalarKind = 'i8' | 'u8' | 'i16' | 'u16' | 'i32' | 'u32' | 'f32' | 'f64' | 'i64' | 'u64';
86
88
  /** A fixed-layout member spec: a scalar kind, `{ string: n }` for an inline UTF-8 field of n bytes, or `{ bool: true }` for a flag byte. */
@@ -318,8 +320,8 @@ export declare class SharedMemory<S extends SharedSpec = SharedSpec> {
318
320
  byteLength: number;
319
321
  }[];
320
322
  /**
321
- * Fires when the contract is bound on this thread — immediately if already
322
- * bound. Returns an unsubscribe function.
323
+ * Fires when the contract is bound on this thread — on every bind, and
324
+ * immediately if already bound. Returns an unsubscribe function.
323
325
  */
324
326
  onBound(cb: () => void): () => void;
325
327
  /** Typed lookup for flat (ungrouped) field keys. */
@@ -52,6 +52,17 @@ export interface WorkerPoolConfig<S extends SharedSpec = SharedSpec, T extends T
52
52
  * skipped and workers receive a plain `{ type: 'INIT' }` handshake.
53
53
  */
54
54
  sharedMemory?: SharedMemory<S> & Prettify<SharedAccess<S>>;
55
+ /**
56
+ * Hand an existing SharedArrayBuffer to every spawned worker instead of
57
+ * allocating a fresh `WebAssembly.Memory` — the worker-shell case: a worker
58
+ * already bound to a contract spawns sub-workers on the SAME buffer
59
+ * (`sharedBuffer: contract.buffer`), or a second pool shares the first
60
+ * pool's `pool.sharedBuffer`. A thunk is resolved once, when the pool
61
+ * constructs. With `sharedMemory` the contract binds locally to this
62
+ * buffer; without it the buffer still ships via INIT_MEMORY and the
63
+ * workers bind their own defined contracts.
64
+ */
65
+ sharedBuffer?: SharedArrayBuffer | (() => SharedArrayBuffer | undefined);
55
66
  /**
56
67
  * Persistence adapter for `sharedMemory` — invoked with the contract right
57
68
  * after the pool binds it, and its `stop()` runs on `terminate()`.
@@ -16,8 +16,14 @@ export type DevtoolsEvent = {
16
16
  /** Config `name`, when supplied — a display label, not the id. */
17
17
  label?: string;
18
18
  poolSize: number;
19
+ /** Per-worker in-flight cap; 0 for a dedicated worker (no queue, uncapped). */
19
20
  concurrency: number;
20
21
  memoryBytes?: number;
22
+ /**
23
+ * True for a single dedicated worker (`connectWorker({ workers: 1 })`,
24
+ * island clients): no pool, no queue. Same event vocabulary otherwise.
25
+ */
26
+ dedicated?: boolean;
21
27
  } | {
22
28
  type: 'pool:terminate';
23
29
  poolId: string;
@@ -46,6 +52,8 @@ export type DevtoolsEvent = {
46
52
  taskId: string;
47
53
  slot: number;
48
54
  waitMs: number;
55
+ /** Estimated structured-clone size of the task args (`estimateCloneBytes`). */
56
+ argBytes?: number;
49
57
  } | {
50
58
  type: 'task:settle';
51
59
  poolId: string;
@@ -55,6 +63,8 @@ export type DevtoolsEvent = {
55
63
  /** dispatch→reply; absent for calls that never ran. */
56
64
  runMs?: number;
57
65
  error?: string;
66
+ /** Estimated structured-clone size of the result (`estimateCloneBytes`). */
67
+ resultBytes?: number;
58
68
  } | {
59
69
  type: 'memory:bind';
60
70
  /** Version-counter index → field path, for pairing memory:write. */
@@ -64,6 +74,15 @@ export type DevtoolsEvent = {
64
74
  type: 'memory:write';
65
75
  path: string;
66
76
  version: number;
77
+ } | {
78
+ /** A dashboard-set watchpoint matched on write (`memory.watch` command). */
79
+ type: 'memory:watch-hit';
80
+ path: string;
81
+ version: number;
82
+ /** Preview of the written value (`previewValue`). */
83
+ value: string;
84
+ /** The watch rule as set, e.g. '> 100', 'change', '== "down"'. */
85
+ rule: string;
67
86
  } | {
68
87
  type: 'island:mount';
69
88
  instance: string;
@@ -80,6 +99,14 @@ export type DevtoolsEvent = {
80
99
  type: 'island:event';
81
100
  instance: string;
82
101
  name: string;
102
+ /** Preview of the emitted payload (`previewValue`). */
103
+ payload?: string;
104
+ } | {
105
+ /** The props an island currently holds: sent on mount and every updateProps. */
106
+ type: 'island:props';
107
+ instance: string;
108
+ /** Preview of the props object (`previewValue`); callbacks show as '[fn]'. */
109
+ props: string;
83
110
  } | {
84
111
  type: 'island:task';
85
112
  instance: string;
@@ -98,6 +125,8 @@ export type DevtoolsEvent = {
98
125
  count: number;
99
126
  /** Main-thread replay time; worker-side render time rides call timings. */
100
127
  replayMs?: number;
128
+ /** Estimated structured-clone size of the op batch (`estimateCloneBytes`). */
129
+ bytes?: number;
101
130
  } | {
102
131
  type: 'net:fetch';
103
132
  /** Per-context sequence — correlates the net:fetch-detail follow-up. */
@@ -164,6 +193,56 @@ export type DevtoolsEvent = {
164
193
  scope?: string;
165
194
  url?: string;
166
195
  }[];
196
+ } | {
197
+ /**
198
+ * A main-thread frame that blocked rendering: Long Animation Frame
199
+ * entries where supported, `longtask` entries as the fallback.
200
+ */
201
+ type: 'runtime:longframe';
202
+ /** Frame (or long task) duration. */
203
+ ms: number;
204
+ /** Time past the 50ms budget that blocked input/render. */
205
+ blockingMs: number;
206
+ /** LoAF script attribution, longest first (capped). */
207
+ scripts?: {
208
+ src?: string;
209
+ fn?: string;
210
+ ms: number;
211
+ }[];
212
+ /**
213
+ * Page was hidden: frame duration is throttling, not work, so only
214
+ * frames with substantial script time are reported. Excluded from
215
+ * foreground jank metrics.
216
+ */
217
+ hidden?: boolean;
218
+ } | {
219
+ /** Main-thread frame rate, sampled once a second via rAF while devtools is on. */
220
+ type: 'runtime:frames';
221
+ fps: number;
222
+ /** Frames over ~2× the display interval in that second. */
223
+ dropped: number;
224
+ } | {
225
+ /** A `src/log.ts` entry, mirrored into the stream (worker logs forward too). */
226
+ type: 'log';
227
+ level: 'trace' | 'debug' | 'info' | 'warn' | 'error';
228
+ scope: string;
229
+ message: string;
230
+ /** Preview of the structured data (`previewValue`). */
231
+ data?: string;
232
+ } | {
233
+ /**
234
+ * Cross-thread reactivity edge/node update for the dependency graph.
235
+ * `id` names a reactive source or subscriber; `deps` are the ids it reads.
236
+ */
237
+ type: 'reactive:node';
238
+ id: string;
239
+ kind: 'source' | 'derived' | 'effect' | 'bridge';
240
+ label?: string;
241
+ deps?: string[];
242
+ /** Thread-qualified owner, e.g. a pool id or island instance. */
243
+ owner?: string;
244
+ /** Set when the node is disposed. */
245
+ disposed?: boolean;
167
246
  };
168
247
  export type EmittedDevtoolsEvent = DevtoolsEvent & {
169
248
  /** performance.now() on the emitting thread. */
@@ -181,8 +260,17 @@ export type EmittedDevtoolsEvent = DevtoolsEvent & {
181
260
  };
182
261
  };
183
262
  export type DevtoolsSink = (event: EmittedDevtoolsEvent) => void;
184
- /** Install the event sink (devtools transports hook here); null disables. */
263
+ /**
264
+ * Install the transport sink (devtools transports hook here); null removes
265
+ * it. Additive sinks (`addDevtoolsSink`) are unaffected.
266
+ */
185
267
  export declare const setDevtoolsSink: (custom: DevtoolsSink | null) => void;
268
+ /**
269
+ * Add a listener alongside the transport sink (exporters like OTLP);
270
+ * returns its remover. Any installed listener turns `devtoolsEnabled()` on,
271
+ * so pools spawned afterwards enable worker forwarding the same way.
272
+ */
273
+ export declare const addDevtoolsSink: (listener: DevtoolsSink) => (() => void);
186
274
  /** Emit a structured event — one branch when no sink is installed. */
187
275
  export declare const emitDevtools: (event: DevtoolsEvent) => void;
188
276
  /**
@@ -190,8 +278,37 @@ export declare const emitDevtools: (event: DevtoolsEvent) => void;
190
278
  * arrived over postMessage without re-stamping their timing/thread.
191
279
  */
192
280
  export declare const forwardDevtools: (event: EmittedDevtoolsEvent) => void;
193
- /** True when a devtools sink is installed on this thread. */
281
+ /** True when a devtools sink (transport or additive listener) is installed on this thread. */
194
282
  export declare const devtoolsEnabled: () => boolean;
283
+ /**
284
+ * Compact, bounded preview of any value for event payloads: JSON-ish,
285
+ * functions as '[fn]', typed arrays/buffers described by size, cycles cut,
286
+ * capped at `max` chars. Call only behind `devtoolsEnabled()`.
287
+ */
288
+ export declare const previewValue: (value: unknown, max?: number) => string;
289
+ /**
290
+ * Rough structured-clone size in bytes: strings 2B/char, numbers 8B,
291
+ * typed arrays/buffers by byteLength, plus small per-key overhead. A cost
292
+ * signal for the dashboard ("is this message big?"), not an exact count.
293
+ * Walks at most `budget` nodes. Call only behind `devtoolsEnabled()`.
294
+ */
295
+ export declare const estimateCloneBytes: (value: unknown, budget?: number) => number;
296
+ /**
297
+ * A command the dashboard can invoke on this app (`control` frames on the
298
+ * devtools transport). Args and result must be structured-cloneable and
299
+ * JSON-safe (the WebSocket path stringifies them).
300
+ */
301
+ export type DevtoolsCommandHandler = (args: Record<string, unknown>) => unknown | Promise<unknown>;
302
+ /**
303
+ * Register a dashboard-invocable command; returns an unregister function.
304
+ * Names are dotted by area: 'island.tree', 'worker.kill', 'memory.read'.
305
+ * A later registration under the same name replaces the earlier one.
306
+ */
307
+ export declare const registerDevtoolsCommand: (name: string, handler: DevtoolsCommandHandler) => (() => void);
308
+ /** Names of the registered commands — the dashboard enables controls from this. */
309
+ export declare const listDevtoolsCommands: () => string[];
310
+ /** Run a registered command (transports call this for inbound `control` frames). */
311
+ export declare const runDevtoolsCommand: (name: string, args?: Record<string, unknown>) => Promise<unknown>;
195
312
  /**
196
313
  * Worker side: route emitted events to the main thread over the task
197
314
  * channel (`ATOLL_DEVTOOLS` messages — the pool re-emits them into its
@@ -219,5 +336,11 @@ export declare const installFetchProbe: (scope: {
219
336
  * inside worker_threads too). No-ops with none of the three.
220
337
  */
221
338
  export declare const installMemoryProbe: (scope: object, intervalMs?: number) => void;
222
- /** Process-unique ids for pools — 'pool-1', 'pool-2', … */
223
- export declare const nextDevtoolsId: (prefix: string) => string;
339
+ /**
340
+ * Process-unique ids for runners. Unnamed: 'pool-1', 'worker-2', … Named:
341
+ * the slugged name plus a kind suffix, '-p' for a pool and '-w' for a
342
+ * dedicated worker ('regions-p', 'ops-inline-w'); a repeated name gets a
343
+ * counter ('regions-w', 'regions-w2'). Slugs never contain '#', '~' or
344
+ * '|', which the dashboard uses to qualify forwarded ids.
345
+ */
346
+ export declare const nextDevtoolsId: (prefix: string, name?: string) => string;
package/dist/index.d.ts CHANGED
@@ -11,8 +11,12 @@ export { MemoryManager } from './pool/memory.js';
11
11
  export { WorkerPool } from './pool/workerPool.js';
12
12
  export type { PoolStats, RunOptions } from './pool/workerPool.js';
13
13
  export { PoolQueueFullError, TaskAbortedError, TaskTimeoutError, WorkerCrashedError, } from './pool/errors.js';
14
- export { connectWorker, workerClient } from './pool/workerClient.js';
15
- export type { ClientMethods, ConnectWorkerConfig, WorkerClient, WorkerMethods, } from './pool/workerClient.js';
14
+ export { DedicatedWorker } from './pool/dedicatedWorker.js';
15
+ export type { DedicatedWorkerConfig } from './pool/dedicatedWorker.js';
16
+ export { connectWorker, resolveWorkerCount, workerClient } from './pool/workerClient.js';
17
+ export type { ClientMethods, ConnectWorkerConfig, WorkerClient, WorkerMethods, WorkerRunner, } from './pool/workerClient.js';
18
+ export { connectSubWorker } from './pool/subWorkerClient.js';
19
+ export type { ConnectSubWorkerConfig } from './pool/subWorkerClient.js';
16
20
  export { connectSharedWorker } from './shared/sharedWorkerClient.js';
17
21
  export type { SharedWorkerClient } from './shared/sharedWorkerClient.js';
18
22
  export { sharedWorkerHost } from './shared/sharedWorkerHost.js';
@@ -29,5 +33,5 @@ export { defineTask, isAsyncTask, toTask } from './task.js';
29
33
  export type { AsyncTask, TaskSnapshot } from './task.js';
30
34
  export { getLogLevel, log, scoped, setLogLevel, setLogSink } from './log.js';
31
35
  export type { LogEntry, LogLevel, LogSink } from './log.js';
32
- export { devtoolsEnabled, emitDevtools, installFetchProbe, installMemoryProbe, setDevtoolsSink, } from './devtools.js';
33
- export type { DevtoolsEvent, DevtoolsSink, DevtoolsThread, EmittedDevtoolsEvent, TaskSettleOutcome, } from './devtools.js';
36
+ export { addDevtoolsSink, devtoolsEnabled, emitDevtools, estimateCloneBytes, installFetchProbe, installMemoryProbe, listDevtoolsCommands, previewValue, registerDevtoolsCommand, runDevtoolsCommand, setDevtoolsSink, } from './devtools.js';
37
+ export type { DevtoolsCommandHandler, DevtoolsEvent, DevtoolsSink, DevtoolsThread, EmittedDevtoolsEvent, TaskSettleOutcome, } from './devtools.js';
package/dist/index.js CHANGED
@@ -1,20 +1,22 @@
1
1
  import { msgpackrCodec as e } from "./index2.js";
2
2
  import { SchemaError as t, z as n } from "./index3.js";
3
3
  import { listSchema as r } from "./index4.js";
4
- import { devtoolsEnabled as i, emitDevtools as a, installFetchProbe as o, installMemoryProbe as s, setDevtoolsSink as c } from "./index5.js";
5
- import { getLogLevel as l, log as u, scoped as d, setLogLevel as f, setLogSink as p } from "./index6.js";
6
- import { bindSharedMemories as m, defineSharedMemory as h, field as g, getDefinedSharedMemoryCount as _, jsonCodec as v, registerConnectorFactory as y } from "./index7.js";
7
- import { reef as b } from "./index8.js";
8
- import { MemoryManager as x } from "./index9.js";
9
- import { PoolQueueFullError as S, TaskAbortedError as C, TaskTimeoutError as w, WorkerCrashedError as T } from "./index10.js";
10
- import { WorkerPool as E } from "./index11.js";
11
- import { connectWorker as D, workerClient as O } from "./index12.js";
12
- import { connectSharedWorker as k } from "./index13.js";
13
- import { TaskRegistry as A } from "./index14.js";
14
- import { sharedWorkerHost as j } from "./index15.js";
15
- import { createClient as M, defineService as N, implementService as P, rpc as F, serviceMethod as I } from "./index16.js";
16
- import { RESERVED_CLIENT_KEYS as L, defineWorker as R } from "./index18.js";
17
- import { reactive as z, shallowEqual as B, watch as V } from "./index19.js";
18
- import { observe as H } from "./index20.js";
19
- import { defineTask as U, isAsyncTask as W, toTask as G } from "./index21.js";
20
- export { x as MemoryManager, S as PoolQueueFullError, L as RESERVED_CLIENT_KEYS, t as SchemaError, C as TaskAbortedError, A as TaskRegistry, w as TaskTimeoutError, T as WorkerCrashedError, E as WorkerPool, m as bindSharedMemories, k as connectSharedWorker, D as connectWorker, M as createClient, N as defineService, h as defineSharedMemory, U as defineTask, R as defineWorker, i as devtoolsEnabled, a as emitDevtools, g as field, _ as getDefinedSharedMemoryCount, l as getLogLevel, P as implementService, o as installFetchProbe, s as installMemoryProbe, W as isAsyncTask, v as jsonCodec, r as listSchema, u as log, e as msgpackrCodec, H as observe, z as reactive, b as reef, y as registerConnectorFactory, F as rpc, d as scoped, I as serviceMethod, c as setDevtoolsSink, f as setLogLevel, p as setLogSink, B as shallowEqual, j as sharedWorkerHost, G as toTask, V as watch, O as workerClient, n as z };
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 };
package/dist/index10.js CHANGED
@@ -1,20 +1,35 @@
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";
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
+ });
5
12
  }
6
- }, t = class extends Error {
7
- constructor(e = "task aborted") {
8
- super(e), this.name = "AbortError";
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);
9
19
  }
10
- }, n = class extends Error {
11
- constructor(e = "task timed out") {
12
- super(e), this.name = "TaskTimeoutError";
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
+ }
13
29
  }
14
- }, r = class extends Error {
15
- constructor(e = "worker crashed") {
16
- super(e), this.name = "WorkerCrashedError";
30
+ getBuffer() {
31
+ return this.memory.buffer;
17
32
  }
18
33
  };
19
34
  //#endregion
20
- export { e as PoolQueueFullError, t as TaskAbortedError, n as TaskTimeoutError, r as WorkerCrashedError };
35
+ export { e as MemoryManager };