@invinite-org/chartlang-host-worker 1.1.0 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # @invinite-org/chartlang-host-worker
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 073f41b: Add the higher-timeframe expression/callback overload to `request.security`.
8
+ Alongside the existing data form `request.security({ interval })` →
9
+ `SecurityBar`, scripts can now write `request.security({ interval }, (bar) =>
10
+ …)` → `Series<number>`, where the callback runs on the **higher-timeframe
11
+ clock** — `request.security({ interval: "1W" }, (bar) => ta.ema(bar.close, 20))`
12
+ is a true weekly EMA(20) (20 weekly bars), not 20 main bars of a weekly-stepped
13
+ series. The result is aligned no-lookahead down to the main timeline.
14
+
15
+ - **core** — the `SecurityExpr` callback type (re-exported from the package
16
+ root), the second `security` overload, and the shared `statefulPrimitives`
17
+ entry annotated as covering both arities.
18
+ - **compiler** — records one `SecurityExpressionDescriptor { slotId, interval,
19
+ paramName }` per expression callsite in `manifest.securityExpressions`
20
+ (sorted by `slotId`, omitted for the data-only form), and validates each
21
+ callback against the allowed subset — its `bar` parameter and body locals,
22
+ the ambient `ta` / `inputs`, safe `Math.*` globals, and literals — rejecting
23
+ any captured outer binding with the new
24
+ `request-security-expr-captures-local` diagnostic.
25
+ - **runtime** — mounts one `SecurityExprRunner` per manifest entry: the
26
+ callback is captured lazily on the first main compute, driven once per HTF bar
27
+ close through a dedicated fold `StreamState` so `ta.*` accumulate on the HTF
28
+ clock, and one sampled value per HTF bar feeds a per-slot output buffer that
29
+ `request.security(opts, expr)` returns aligned no-lookahead to the main
30
+ timeline. Capability / interval / stream fallbacks return an all-NaN series
31
+ with a deduped diagnostic.
32
+ - **host-worker / host-quickjs** — boot the expression form unchanged; the
33
+ `__manifest` sidecar already carries `securityExpressions`.
34
+ - **pine-converter** — Pine's `request.security(sym, "D", ta.ema(close, 9))`
35
+ now lowers to the chartlang callback form
36
+ `request.security({ interval: "1d" }, (bar) => ta.ema(bar.close, 9))` (a bare
37
+ OHLCV third arg keeps lowering to the data form).
38
+ - **conformance** — new scenarios prove the weekly expression value differs
39
+ from a same-length main-timeframe EMA, plus the `multiTimeframe: false` NaN
40
+ fallback.
41
+
42
+ ### Patch Changes
43
+
44
+ - 850ae21: Fix single-script multi-timeframe loads dropping their secondary streams.
45
+ Both host boots now adopt the compiler's object-form `__manifest` sidecar
46
+ as the authoritative manifest for a single-script module
47
+ (`buildBundleFromModule` in host-worker, the bundle builder in
48
+ host-quickjs's `dispatcherCore`). The runtime `defineIndicator` stub zeroes
49
+ compiler-derived fields (`requestedIntervals`, `outputs`, `plots`,
50
+ `maxLookback`), so using `mod.default.manifest` left `requestedIntervals`
51
+ empty — a `request.security` script never registered its secondary streams
52
+ and every secondary candle was dropped with an `unknown-secondary-stream`
53
+ warning. Single-object detection goes through a dedicated `isSingleManifest`
54
+ guard (TS #17002: `Array.isArray` does not subtract a `ReadonlyArray` union
55
+ member). Cross-host parity is preserved.
56
+ - Updated dependencies [850ae21]
57
+ - Updated dependencies [ca19e20]
58
+ - Updated dependencies [6235ad7]
59
+ - Updated dependencies [3bf391a]
60
+ - Updated dependencies [8086003]
61
+ - Updated dependencies [850ae21]
62
+ - Updated dependencies [850ae21]
63
+ - Updated dependencies [073f41b]
64
+ - Updated dependencies [5a9c24d]
65
+ - Updated dependencies [08c536c]
66
+ - @invinite-org/chartlang-core@1.2.0
67
+ - @invinite-org/chartlang-runtime@1.2.0
68
+ - @invinite-org/chartlang-adapter-kit@1.3.0
69
+
70
+ ## 1.1.1
71
+
72
+ ### Patch Changes
73
+
74
+ - 71ea0a5: Inline original TypeScript sources into emitted `.js.map` files (`inlineSources: true`). Published sourcemaps no longer reference missing `../src/*.ts` files, fixing "points to missing source files" warnings in downstream bundlers (e.g. Vite).
75
+ - Updated dependencies [71ea0a5]
76
+ - @invinite-org/chartlang-adapter-kit@1.2.1
77
+ - @invinite-org/chartlang-core@1.1.1
78
+ - @invinite-org/chartlang-runtime@1.1.1
79
+
3
80
  ## 1.1.0
4
81
 
5
82
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"createWorkerBoot.d.ts","sourceRoot":"","sources":["../src/createWorkerBoot.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGhE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IAC5F,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAAC;CACxC,CAAC;AA2EF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CA6F7D"}
1
+ {"version":3,"file":"createWorkerBoot.d.ts","sourceRoot":"","sources":["../src/createWorkerBoot.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGhE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IAC5F,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAAC;CACxC,CAAC;AA+FF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CA6F7D"}
@@ -17,6 +17,12 @@ function isFrame(value) {
17
17
  const k = value.kind;
18
18
  return typeof k === "string";
19
19
  }
20
+ // `Array.isArray` narrows to `any[]`, which does not subtract a
21
+ // `ReadonlyArray<T>` member from a union (TS #17002), so the single-object
22
+ // `__manifest` form needs this dedicated guard.
23
+ function isSingleManifest(manifest) {
24
+ return manifest !== undefined && !Array.isArray(manifest);
25
+ }
20
26
  function isCompiledScriptObject(v) {
21
27
  if (v === null || typeof v !== "object")
22
28
  return false;
@@ -43,6 +49,17 @@ function buildBundleFromModule(mod) {
43
49
  const dependencies = mod.__dependencies ?? [];
44
50
  const isBundle = Array.isArray(manifest) || dependencies.length > 0;
45
51
  if (!isBundle) {
52
+ // Single-script form: the compiler's `__manifest` sidecar is the
53
+ // authoritative manifest (it carries compiler-derived fields the
54
+ // runtime `defineIndicator` cannot know — `requestedIntervals`,
55
+ // `outputs`, `plots`, `maxLookback`). `mod.default.manifest` is the
56
+ // runtime stub with those fields zeroed, so an MTF script would
57
+ // never register its secondary streams if we used it directly.
58
+ // `isBundle` is false here, so `manifest` (when present) is the
59
+ // single-object form.
60
+ if (isSingleManifest(manifest)) {
61
+ return Object.freeze({ ...mod.default, manifest });
62
+ }
46
63
  return mod.default;
47
64
  }
48
65
  const siblings = [];
@@ -1 +1 @@
1
- {"version":3,"file":"createWorkerBoot.js","sourceRoot":"","sources":["../src/createWorkerBoot.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAG/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAuBxC,KAAK,UAAU,oBAAoB,CAAC,YAAoB;IACpD,sEAAsE;IACtE,oEAAoE;IACpE,oEAAoE;IACpE,gBAAgB;IAChB,MAAM,GAAG,GAAG,sCAAsC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;IACrF,OAAO,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAyB,CAAC;A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CAAC,CAAC;oBAChD,KAAK,CAAC,WAAW,CAAC;wBACd,IAAI,EAAE,WAAW;wBACjB,KAAK,EAAE,GAAG,CAAC,KAAK;wBAChB,SAAS,EAAE,OAAO;qBACrB,CAAC,CAAC;oBACH,MAAM;gBACV,CAAC;gBACD,KAAK,SAAS,CAAC,CAAC,CAAC;oBACb,MAAM,MAAM,EAAE,OAAO,EAAE,CAAC;oBACxB,MAAM,GAAG,IAAI,CAAC;oBACd,MAAM,GAAG,IAAI,CAAC;oBACd,MAAM;gBACV,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACN,MAAM,IAAI,KAAK,CACX,uBAAwB,GAAiC,CAAC,IAAI,EAAE,CACnE,CAAC;gBACN,CAAC;YACL,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,KAAK,CAAC,WAAW,CAAC;gBACd,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC5D,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type {\n CompiledScriptBundle,\n CompiledScriptObject,\n ScriptManifest,\n} from \"@invinite-org/chartlang-core\";\nimport { createScriptRunner } from \"@invinite-org/chartlang-runtime\";\n\nimport { filterEmissions } from \"./filterEmissions.js\";\nimport { watchStep } from \"./limits.js\";\nimport type { HostToWorker, WorkerToHost } from \"./protocol.js\";\nimport type { CompiledModuleExport, HostLimits, ScriptRunnerHandle } from \"./types.js\";\n\n/**\n * Duck-typed slice of the worker global scope the boot factory needs. Lets\n * tests drive `createWorkerBoot` against a `MessageChannel` port without\n * faking the full `WorkerGlobalScope`.\n *\n * @since 0.1\n * @stable\n * @example\n * const scope: WorkerBootScope = {\n * addEventListener: () => {},\n * postMessage: () => {},\n * };\n * void scope;\n */\nexport type WorkerBootScope = {\n addEventListener(type: \"message\", listener: (ev: MessageEvent<HostToWorker>) => void): void;\n postMessage(msg: WorkerToHost): void;\n};\n\nasync function importCompiledModule(moduleSource: string): Promise<CompiledModuleExport> {\n // `encodeURIComponent` preserves multi-byte UTF-8 across the data URL\n // without the Annex-B `unescape` round-trip. ESM `import(\"data:…\")`\n // accepts percent-encoded text/javascript directly in both browsers\n // and Node 20+.\n const url = `data:text/javascript;charset=utf-8,${encodeURIComponent(moduleSource)}`;\n return (await import(/* @vite-ignore */ url)) as CompiledModuleExport;\n}\n\nfunction isFrame(value: unknown): value is HostToWorker {\n if (value === null || typeof value !== \"object\") return false;\n const k = (value as { readonly kind?: unknown }).kind;\n return typeof k === \"string\";\n}\n\n// `Array.isArray` narrows to `any[]`, which does not subtract a\n// `ReadonlyArray<T>` member from a union (TS #17002), so the single-object\n// `__manifest` form needs this dedicated guard.\nfunction isSingleManifest(\n manifest: ScriptManifest | ReadonlyArray<ScriptManifest> | undefined,\n): manifest is ScriptManifest {\n return manifest !== undefined && !Array.isArray(manifest);\n}\n\nfunction isCompiledScriptObject(v: unknown): v is CompiledScriptObject {\n if (v === null || typeof v !== \"object\") return false;\n const o = v as { readonly compute?: unknown; readonly manifest?: unknown };\n return typeof o.compute === \"function\" && typeof o.manifest === \"object\" && o.manifest !== null;\n}\n\n/**\n * Bridge a dynamically-imported compiled module into the runtime's\n * single-or-bundle compiled-script shape. Detects the §22.10\n * indicator-composition bundle by either (a) the array form of\n * `__manifest` or (b) a non-empty `__dependencies` export — both are\n * additive over the Phase-1 single-script wire format. Single-script\n * callers see the same `mod.default` `CompiledScriptObject` they did\n * before, byte-identical.\n *\n * Sibling exports are recovered by reading each non-`default` manifest\n * entry's `exportName` off the array sidecar and pulling the matching\n * named export off the module namespace object. Entries the local\n * `isCompiledScriptObject` guard rejects are skipped silently so a\n * malformed bundle still loads its primary script.\n */\nfunction buildBundleFromModule(\n mod: CompiledModuleExport,\n): CompiledScriptObject | CompiledScriptBundle {\n const manifest = mod.__manifest;\n const dependencies = mod.__dependencies ?? [];\n const isBundle = Array.isArray(manifest) || dependencies.length > 0;\n if (!isBundle) {\n // Single-script form: the compiler's `__manifest` sidecar is the\n // authoritative manifest (it carries compiler-derived fields the\n // runtime `defineIndicator` cannot know — `requestedIntervals`,\n // `outputs`, `plots`, `maxLookback`). `mod.default.manifest` is the\n // runtime stub with those fields zeroed, so an MTF script would\n // never register its secondary streams if we used it directly.\n // `isBundle` is false here, so `manifest` (when present) is the\n // single-object form.\n if (isSingleManifest(manifest)) {\n return Object.freeze({ ...mod.default, manifest });\n }\n return mod.default;\n }\n const siblings: Array<{\n readonly exportName: string;\n readonly compiled: CompiledScriptObject;\n }> = [];\n if (Array.isArray(manifest)) {\n for (let i = 1; i < manifest.length; i += 1) {\n const entry = manifest[i];\n const exportName = entry.exportName;\n if (exportName === undefined || exportName === \"default\") continue;\n const compiled = mod[exportName];\n if (!isCompiledScriptObject(compiled)) continue;\n siblings.push(Object.freeze({ exportName, compiled }));\n }\n }\n const frozenDeps = dependencies.map((d) =>\n Object.freeze({\n localId: d.localId,\n compiled: d.compiled,\n ...(d.inputOverrides === undefined ? {} : { inputOverrides: d.inputOverrides }),\n }),\n );\n return Object.freeze({\n primary: mod.default,\n siblings: Object.freeze(siblings),\n dependencies: Object.freeze(frozenDeps),\n });\n}\n\n/**\n * Wire `scope` to the host-worker postMessage protocol. Lazily imports the\n * compiled module via a `data:` URL so the same code path runs inside a real\n * browser `Worker` and inside Node tests (`MessageChannel`-backed).\n *\n * Lifecycle:\n *\n * - `load` → dynamic import → `createScriptRunner(...)` → cache `limits`.\n * Posts `loaded` on success or `loadError` on failure.\n * - `candleEvent` → wrap dispatch in `watchStep(...)`; post `step-overshoot`\n * when over budget. Errors map to `fatal`.\n * - `drain` → validate every plot / alert emission; sink malformed ones into\n * the diagnostics array; post `emissions` with the original nonce.\n * - `dispose` → release the runner; subsequent messages map to `fatal`.\n *\n * @since 0.1\n * @stable\n * @example\n * // import { createWorkerBoot } from \"@invinite-org/chartlang-host-worker\";\n * // const scope = self;\n * // createWorkerBoot(scope);\n * const fn: typeof createWorkerBoot = createWorkerBoot;\n * void fn;\n */\nexport function createWorkerBoot(scope: WorkerBootScope): void {\n let runner: ScriptRunnerHandle | null = null;\n let limits: HostLimits | null = null;\n\n scope.addEventListener(\"message\", async (ev: MessageEvent<HostToWorker>) => {\n const msg = ev.data;\n if (!isFrame(msg)) {\n scope.postMessage({\n kind: \"fatal\",\n message: \"malformed host frame: not a plain object with a string 'kind'\",\n });\n return;\n }\n if (msg.kind === \"load\") {\n try {\n const mod = await importCompiledModule(msg.compiled.moduleSource);\n const compiled = buildBundleFromModule(mod);\n runner = createScriptRunner({\n compiled,\n capabilities: msg.capabilities,\n ...(msg.symInfo !== undefined ? { symInfo: msg.symInfo } : {}),\n ...(msg.inputOverrides !== undefined\n ? { inputOverrides: msg.inputOverrides }\n : {}),\n ...(msg.plotOverrides !== undefined\n ? { plotOverrides: msg.plotOverrides }\n : {}),\n });\n limits = msg.limits;\n scope.postMessage({ kind: \"loaded\" });\n } catch (err) {\n scope.postMessage({\n kind: \"loadError\",\n message: err instanceof Error ? err.message : String(err),\n });\n }\n return;\n }\n\n try {\n switch (msg.kind) {\n case \"candleEvent\": {\n if (runner === null || limits === null) {\n throw new Error(\"candleEvent before load\");\n }\n const r = runner;\n const { overshoot } = await watchStep(\n () => r.push(msg.event),\n limits.maxCpuMsPerStep,\n );\n if (overshoot > 0) {\n scope.postMessage({ kind: \"step-overshoot\", observedMs: overshoot });\n }\n break;\n }\n case \"setPlotOverrides\": {\n if (runner === null) {\n throw new Error(\"setPlotOverrides before load\");\n }\n runner.setPlotOverrides(msg.overrides);\n break;\n }\n case \"drain\": {\n if (runner === null) {\n throw new Error(\"drain before load\");\n }\n const cleaned = filterEmissions(runner.drain());\n scope.postMessage({\n kind: \"emissions\",\n nonce: msg.nonce,\n emissions: cleaned,\n });\n break;\n }\n case \"dispose\": {\n await runner?.dispose();\n runner = null;\n limits = null;\n break;\n }\n default: {\n throw new Error(\n `unknown frame kind: ${(msg as { readonly kind: string }).kind}`,\n );\n }\n }\n } catch (err) {\n scope.postMessage({\n kind: \"fatal\",\n message: err instanceof Error ? err.message : String(err),\n });\n }\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createWorkerHost.js","sourceRoot":"","sources":["../src/createWorkerHost.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAS/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAyC7C,SAAS,YAAY,CAAC,CAAa;IAC/B,OAAO,OAAO,CAAC,CAAC,SAAS,KAAK,UAAU,CAAC;AAC7C,CAAC;AAED,SAAS,mBAAmB,CAAC,EAAoB;IAC7C,IAAI,OAAO,EAAE,CAAC,OAAO,KAAK,QAAQ,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC,OAAO,CAAC;IAC/E,IAAI,EAAE,CAAC,KAAK,YAAY,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;IACtF,IAAI,OAAO,EAAE,CAAC,KAAK,KAAK,QAAQ,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC;IACzE,OAAO,sBAAsB,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAA0B;IACvD,MAAM,MAAM,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAChF,0EAA0E;IAC1E,mE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GAAiB,EAAE,IAAI,EAAE,kBAAkB,EAAE,SAAS,EAAE,CAAC;YACpE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,KAAK;YACD,MAAM,CAAC,GAAG,YAAY,CAAC;YACvB,YAAY,IAAI,CAAC,CAAC;YAClB,OAAO,IAAI,OAAO,CAAkB,CAAC,OAAO,EAAE,EAAE;gBAC5C,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;gBAC9B,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;gBACxD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO;YACH,MAAM,KAAK,GAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;YAChD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;gBACvB,MAAM,CAAC,SAAS,EAAE,CAAC;YACvB,CAAC;YACD,gBAAgB,EAAE,CAAC;YACnB,aAAa,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,MAAM;KACT,CAAC,CAAC;AACP,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type {\n AdapterSymInfo,\n Capabilities,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\n\nimport { defaultWorkerFactory } from \"./defaultWorkerFactory.js\";\nimport { DEFAULT_LIMITS } from \"./limits.js\";\nimport type { HostToWorker, WorkerToHost } from \"./protocol.js\";\nimport type { HostLimits, ScriptHost, WorkerErrorEvent, WorkerLike } from \"./types.js\";\n\n/**\n * Constructor options for {@link createWorkerHost}.\n *\n * - `capabilities` — the adapter's declared capability bag. Bolted onto every\n * `load` postMessage; the worker boot never falls back to a default.\n * - `symInfo` — optional adapter-supplied metadata for runtime `syminfo.*`.\n * - `resolveInputs` — optional adapter callback. The host resolves it during\n * `load()` and sends the plain override record to the worker.\n * - `resolvePlotOverrides` — optional adapter callback for the initial per-slot\n * presentation overrides. Resolved during `load()`; the plain record is sent\n * to the worker beside `inputOverrides`.\n * - `workerLike` — injection seam for tests. Production callers omit it; the\n * host then constructs a real `Worker` via {@link defaultWorkerFactory}.\n * - `limits` — partial `HostLimits` overrides; missing fields fall through to\n * {@link DEFAULT_LIMITS}.\n * - `onWorkerError` — called when the worker posts `step-overshoot` or\n * `fatal`. The host does not synthesize diagnostics into the next\n * `drain()` — Phase 1 keeps overshoot surfacing on the adapter.\n *\n * @since 0.1\n * @stable\n * @example\n * const opts: CreateWorkerHostOpts = {\n * capabilities: {} as Capabilities,\n * };\n * void opts;\n */\nexport type CreateWorkerHostOpts = {\n readonly capabilities: Capabilities;\n readonly symInfo?: AdapterSymInfo;\n readonly resolveInputs?: (scriptId: string) => Readonly<Record<string, unknown>>;\n readonly resolvePlotOverrides?: (scriptId: string) => Readonly<Record<string, PlotOverride>>;\n readonly workerLike?: WorkerLike;\n readonly limits?: Partial<HostLimits>;\n readonly onWorkerError?: (message: string) => void;\n};\n\nfunction hasTerminate(w: WorkerLike): w is WorkerLike & { terminate: () => void } {\n return typeof w.terminate === \"function\";\n}\n\nfunction describeWorkerError(ev: WorkerErrorEvent): string {\n if (typeof ev.message === \"string\" && ev.message.length > 0) return ev.message;\n if (ev.error instanceof Error && ev.error.message.length > 0) return ev.error.message;\n if (typeof ev.error === \"string\" && ev.error.length > 0) return ev.error;\n return \"unknown worker error\";\n}\n\n/**\n * Build a browser-default `ScriptHost` around a Web Worker. The host\n * round-trips `load` / `push` / `drain` / `dispose` calls across the worker\n * boundary via structured-clone-safe postMessage frames defined in\n * {@link HostToWorker} / {@link WorkerToHost}.\n *\n * The host owns the `nonce` counter for `drain` correlation, the in-flight\n * `load` promise, and the in-flight drain registry. `dispose` posts the\n * tear-down message, calls `terminate()` when the underlying `WorkerLike`\n * supports it, and clears the pending-drain map.\n *\n * @since 0.1\n * @stable\n * @example\n * import { createWorkerHost } from \"@invinite-org/chartlang-host-worker\";\n * // const host = createWorkerHost({ capabilities });\n * const fn: typeof createWorkerHost = createWorkerHost;\n * void fn;\n */\nexport function createWorkerHost(opts: CreateWorkerHostOpts): ScriptHost {\n const limits: HostLimits = Object.freeze({ ...DEFAULT_LIMITS, ...opts.limits });\n // The `defaultWorkerFactory` branch is browser-only — tests always inject\n // `workerLike`. Excluded from coverage to keep the production-only\n // `new Worker(...)` path uncounted, consistent with the file-level\n // exclusion of `defaultWorkerFactory.ts` itself.\n /* v8 ignore next */\n const worker: WorkerLike = opts.workerLike ?? defaultWorkerFactory();\n\n let nonceCounter = 0;\n const pendingDrains = new Map<number, (e: RunnerEmissions) => void>();\n let loadedResolve: (() => void) | null = null;\n let loadedReject: ((err: Error) => void) | null = null;\n let loadTimeoutHandle: ReturnType<typeof setTimeout> | null = null;\n // Latches the first worker-level error so a subsequent `load()` call\n // refuses to wait on a dead worker (no `loaded` reply will ever arrive).\n let fatalError: string | null = null;\n\n function clearLoadTimeout(): void {\n if (loadTimeoutHandle !== null) {\n clearTimeout(loadTimeoutHandle);\n loadTimeoutHandle = null;\n }\n }\n\n function failLoad(err: Error): void {\n clearLoadTimeout();\n loadedReject?.(err);\n loadedResolve = null;\n loadedReject = null;\n }\n\n worker.addEventListener(\"message\", (ev: MessageEvent<unknown>) => {\n const msg = ev.data as WorkerToHost;\n switch (msg.kind) {\n case \"loaded\": {\n clearLoadTimeout();\n loadedResolve?.();\n loadedResolve = null;\n loadedReject = null;\n break;\n }\n case \"loadError\": {\n failLoad(new Error(msg.message));\n break;\n }\n case \"emissions\": {\n const resolve = pendingDrains.get(msg.nonce);\n if (resolve !== undefined) {\n pendingDrains.delete(msg.nonce);\n resolve(msg.emissions);\n }\n break;\n }\n case \"step-overshoot\": {\n opts.onWorkerError?.(`step overshoot ${msg.observedMs.toFixed(2)}ms`);\n break;\n }\n case \"fatal\": {\n opts.onWorkerError?.(msg.message);\n break;\n }\n }\n });\n\n // The error channel is fed by browser `Worker`'s `onerror` event.\n // `MessagePort`-backed fakes accept the subscription silently and never\n // fire it, which is the right behaviour: a port doesn't have its own\n // boot/error channel. The cast narrows `addEventListener`'s overload\n // signature to the error variant.\n const addErrorListener = worker.addEventListener as (\n type: \"error\",\n listener: (ev: WorkerErrorEvent) => void,\n ) => void;\n addErrorListener(\"error\", (ev) => {\n const description = describeWorkerError(ev);\n fatalError = description;\n const message = `worker failed to boot: ${description}`;\n failLoad(new Error(message));\n opts.onWorkerError?.(message);\n });\n\n return Object.freeze<ScriptHost>({\n load(compiled) {\n return new Promise<void>((resolve, reject) => {\n if (fatalError !== null) {\n reject(new Error(`worker failed to boot: ${fatalError}`));\n return;\n }\n if (loadedResolve !== null) {\n reject(new Error(\"load() already in flight\"));\n return;\n }\n loadedResolve = resolve;\n loadedReject = reject;\n loadTimeoutHandle = setTimeout(() => {\n failLoad(\n new Error(\n `worker load() timed out after ${limits.maxLoadTimeoutMs}ms — worker never replied with 'loaded'`,\n ),\n );\n }, limits.maxLoadTimeoutMs);\n const frame: HostToWorker = {\n kind: \"load\",\n compiled: {\n moduleSource: compiled.moduleSource,\n manifest: compiled.manifest,\n },\n capabilities: opts.capabilities,\n ...(opts.symInfo !== undefined ? { symInfo: opts.symInfo } : {}),\n ...(opts.resolveInputs !== undefined\n ? { inputOverrides: opts.resolveInputs(compiled.manifest.name) }\n : {}),\n ...(opts.resolvePlotOverrides !== undefined\n ? { plotOverrides: opts.resolvePlotOverrides(compiled.manifest.name) }\n : {}),\n limits,\n };\n worker.postMessage(frame);\n });\n },\n push(event) {\n const frame: HostToWorker = { kind: \"candleEvent\", event };\n worker.postMessage(frame);\n return Promise.resolve();\n },\n setPlotOverrides(overrides) {\n const frame: HostToWorker = { kind: \"setPlotOverrides\", overrides };\n worker.postMessage(frame);\n },\n drain() {\n const n = nonceCounter;\n nonceCounter += 1;\n return new Promise<RunnerEmissions>((resolve) => {\n pendingDrains.set(n, resolve);\n const frame: HostToWorker = { kind: \"drain\", nonce: n };\n worker.postMessage(frame);\n });\n },\n dispose() {\n const frame: HostToWorker = { kind: \"dispose\" };\n worker.postMessage(frame);\n if (hasTerminate(worker)) {\n worker.terminate();\n }\n clearLoadTimeout();\n pendingDrains.clear();\n },\n limits,\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"defaultWorkerFactory.js","sourceRoot":"","sources":["../src/defaultWorkerFactory.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAI/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB;IAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC/C,CAAC"}
1
+ {"version":3,"file":"defaultWorkerFactory.js","sourceRoot":"","sources":["../src/defaultWorkerFactory.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAI/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB;IAChC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { WorkerLike } from \"./types.js\";\n\n/**\n * Browser-only fallback when `createWorkerHost` is called without an\n * explicit `workerLike`. Constructs a real `Worker` against the bundled\n * `dist/worker-boot.js` sibling. In a real Node test runner `Worker` is not\n * a global so calling this throws a `ReferenceError`; tests always inject a\n * `MessageChannel`-backed `WorkerLike` instead, and the coverage test in\n * `defaultWorkerFactory.test.ts` stubs `globalThis.Worker` to exercise the\n * construction path.\n *\n * @since 0.1\n * @stable\n * @example\n * // const worker = defaultWorkerFactory(); // browser only\n * const fn: typeof defaultWorkerFactory = defaultWorkerFactory;\n * void fn;\n */\nexport function defaultWorkerFactory(): WorkerLike {\n const url = new URL(\"./worker-boot.js\", import.meta.url);\n return new Worker(url, { type: \"module\" });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"filterEmissions.js","sourceRoot":"","sources":["../src/filterEmissions.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAQH,gBAAgB,GACnB,MAAM,qCAAqC,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,GAAoB;IAChD,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAyB,EAAE,CAAC;IACxC,MAAM,eAAe,GAAkC,EAAE,CAAC;IAC1D,MAAM,IAAI,GAAuB,EAAE,CAAC;IACpC,MAAM,WAAW,GAA6B,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IAEnE,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;YACP,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACJ,WAAW,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,MAAM,EAAE,CAA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OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,MAAM,EAAE,IAAI;gBACZ,GAAG,EAAE,SAAS,CAAC,GAAG;aACrB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;aAAM,CAAC;YACJ,WAAW,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,MAAM,EAAE,IAAI;gBACZ,GAAG,EAAE,GAAG,CAAC,GAAG;aACf,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC3B,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IACD,OAAO;QACH,KAAK;QACL,QAAQ;QACR,MAAM;QACN,eAAe;QACf,IAAI;QACJ,WAAW;QACX,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;KACnB,CAAC;AACN,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport {\n type AlertEmission,\n type AlertConditionEmission,\n type DrawingEmission,\n type LogEmission,\n type PlotEmission,\n type RunnerEmissions,\n type RuntimeDiagnostic,\n validateEmission,\n} from \"@invinite-org/chartlang-adapter-kit\";\n\n/**\n * Walk a `RunnerEmissions` snapshot and replace any plot / alert that fails\n * adapter-kit's `validateEmission` with a `malformed-emission` diagnostic.\n * Drawings pass through unchanged in Phase 1 (no `draw.*` primitives ship\n * yet); diagnostics are appended to (never validated against — recursive\n * validation would loop).\n *\n * The boot calls this on every `drain()` before posting `emissions` back to\n * the host; the trust boundary for the postMessage wire format is here.\n *\n * @since 0.1\n * @stable\n * @example\n * // const out = filterEmissions(runner.drain());\n * // postMessage({ kind: \"emissions\", nonce, emissions: out });\n * const fn: typeof filterEmissions = filterEmissions;\n * void fn;\n */\nexport function filterEmissions(raw: RunnerEmissions): RunnerEmissions {\n const plots: Array<PlotEmission> = [];\n const drawings: Array<DrawingEmission> = [];\n const alerts: Array<AlertEmission> = [];\n const alertConditions: Array<AlertConditionEmission> = [];\n const logs: Array<LogEmission> = [];\n const diagnostics: Array<RuntimeDiagnostic> = [...raw.diagnostics];\n\n for (const p of raw.plots) {\n const r = validateEmission(p);\n if (r.ok) {\n plots.push(p);\n } else {\n diagnostics.push({\n kind: \"diagnostic\",\n severity: \"warning\",\n code: r.code,\n message: r.message,\n slotId: p.slotId,\n bar: p.bar,\n });\n }\n }\n for (const a of raw.alerts) {\n const r = validateEmission(a);\n if (r.ok) {\n alerts.push(a);\n } else {\n diagnostics.push({\n kind: \"diagnostic\",\n severity: \"warning\",\n code: r.code,\n message: r.message,\n slotId: a.slotId,\n bar: a.bar,\n });\n }\n }\n for (const condition of raw.alertConditions) {\n const r = validateEmission(condition);\n if (r.ok) {\n alertConditions.push(condition);\n } else {\n diagnostics.push({\n kind: \"diagnostic\",\n severity: \"warning\",\n code: r.code,\n message: r.message,\n slotId: null,\n bar: condition.bar,\n });\n }\n }\n for (const log of raw.logs) {\n const r = validateEmission(log);\n if (r.ok) {\n logs.push(log);\n } else {\n diagnostics.push({\n kind: \"diagnostic\",\n severity: \"warning\",\n code: r.code,\n message: r.message,\n slotId: null,\n bar: log.bar,\n });\n }\n }\n for (const d of raw.drawings) {\n drawings.push(d);\n }\n return {\n plots,\n drawings,\n alerts,\n alertConditions,\n logs,\n diagnostics,\n fromBar: raw.fromBar,\n toBar: raw.toBar,\n };\n}\n"]}
package/dist/idb.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"idb.js","sourceRoot":"","sources":["../src/idb.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"idb.js","sourceRoot":"","sources":["../src/idb.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nexport { idbStateStore } from \"./idbStateStore.js\";\n"]}
@@ -59,7 +59,7 @@ export function idbStateStore(opts) {
59
59
  });
60
60
  }
61
61
  /**
62
- * Stable cache-key serialisation for PLAN.md §6.9 `StateStoreKey`.
62
+ * Stable cache-key serialisation for the `StateStoreKey`.
63
63
  *
64
64
  * @internal
65
65
  */
@@ -1 +1 @@
1
- {"version":3,"file":"idbStateStore.js","sourceRoot":"","sources":["../src/idbStateStore.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAK/D,MAAM,eAAe,GAAG,WAAW,CAAC;AACpC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAC1C,MAAM,cAAc,GAAG,SAAS,CAAC;AASjC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAgC,CAAC;AAE3D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CACzB,IAIE;IAEF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,eAAe,CAAC;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,iBAAiB,CAAC;IACpD,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEzC,OAAO,MAA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,aAAa,CAAC;IAClC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,QAAuB;IAClD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,KAAc;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACjF,IAAI,CAAC,CAAC,eAAe,IAAI,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,aAAa,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACzF,IAAI,CAAC,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC7E,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAS,OAAO,CAAC,KAAc,EAAE,QAAgB;IAC7C,IAAI,KAAK,YAAY,YAAY;QAAE,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACnE,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { StateSnapshot, StateStoreKey } from \"@invinite-org/chartlang-core\";\nimport type { PersistentStateStore } from \"@invinite-org/chartlang-runtime\";\n\nconst DEFAULT_DB_NAME = \"chartlang\";\nconst DEFAULT_CAP_BYTES = 50 * 1024 * 1024;\nconst OBJECT_STORE = \"chartlangSnapshots\";\nconst SAVED_AT_INDEX = \"savedAt\";\n\ntype StoredRecord = Readonly<{\n keyString: string;\n snapshot: StateSnapshot;\n bytesEstimate: number;\n savedAt: number;\n}>;\n\nconst dbPromises = new Map<string, Promise<IDBDatabase>>();\n\n/**\n * IDB-backed {@link PersistentStateStore}. One record per `StateStoreKey`,\n * capped at `capBytes` total with oldest-first eviction by `snapshot.savedAt`.\n * Reads on mount, writes on dispose + 60s cadence; the cadence is enforced by\n * the runtime, not the store. Identity-safe: `load()` returns `null` for any\n * non-matching key, and `clear()` deletes only this key's record.\n *\n * @since 0.5\n * @stable\n * @example\n * // import { idbStateStore } from \"@invinite-org/chartlang-host-worker/idb\";\n * // const store = idbStateStore({ dbName: \"chartlang\", key });\n * // await store.save(snapshot);\n */\nexport function idbStateStore(\n opts: Readonly<{\n key: StateStoreKey;\n dbName?: string;\n capBytes?: number;\n }>,\n): PersistentStateStore {\n const dbName = opts.dbName ?? DEFAULT_DB_NAME;\n const capBytes = opts.capBytes ?? DEFAULT_CAP_BYTES;\n const keyString = stringifyKey(opts.key);\n\n return Object.freeze({\n key: opts.key,\n async load(): Promise<StateSnapshot | null> {\n const db = await openDb(dbName);\n const tx = db.transaction(OBJECT_STORE, \"readonly\");\n const done = transactionDone(tx);\n const value = await requestToPromise<unknown>(\n tx.objectStore(OBJECT_STORE).get(keyString),\n );\n await done;\n return isStoredRecord(value) ? value.snapshot : null;\n },\n async save(snapshot: StateSnapshot): Promise<void> {\n const db = await openDb(dbName);\n const tx = db.transaction(OBJECT_STORE, \"readwrite\");\n const done = transactionDone(tx);\n const store = tx.objectStore(OBJECT_STORE);\n const records = await readAllRecords(store);\n const nextBytes = estimateSnapshotBytes(snapshot);\n await evictUntilUnderCap(store, records, keyString, nextBytes, capBytes);\n await requestToPromise(\n store.put({\n keyString,\n snapshot,\n bytesEstimate: nextBytes,\n savedAt: snapshot.savedAt,\n }),\n );\n await done;\n },\n async clear(): Promise<void> {\n const db = await openDb(dbName);\n const tx = db.transaction(OBJECT_STORE, \"readwrite\");\n const done = transactionDone(tx);\n await requestToPromise(tx.objectStore(OBJECT_STORE).delete(keyString));\n await done;\n },\n });\n}\n\n/**\n * Stable cache-key serialisation for the `StateStoreKey`.\n *\n * @internal\n */\nfunction stringifyKey(key: StateStoreKey): string {\n return JSON.stringify({\n scriptHash: key.scriptHash,\n compilerVersion: key.compilerVersion,\n apiVersion: key.apiVersion,\n capabilitiesHash: key.capabilitiesHash,\n symbol: key.symbol,\n mainInterval: key.mainInterval,\n requestedIntervals: key.requestedIntervals.join(\",\"),\n });\n}\n\n/**\n * Lazy singleton IDB connection per database name.\n *\n * @internal\n */\nfunction openDb(dbName: string): Promise<IDBDatabase> {\n const existing = dbPromises.get(dbName);\n if (existing !== undefined) return existing;\n\n const promise = new Promise<IDBDatabase>((resolve, reject) => {\n if (globalThis.indexedDB === undefined) {\n reject(new Error(\"indexedDB is not available\"));\n return;\n }\n\n let request: IDBOpenDBRequest;\n try {\n request = globalThis.indexedDB.open(dbName, 1);\n } catch (error) {\n reject(toError(error, \"indexedDB.open failed\"));\n return;\n }\n\n request.onupgradeneeded = () => {\n const db = request.result;\n if (!db.objectStoreNames.contains(OBJECT_STORE)) {\n const store = db.createObjectStore(OBJECT_STORE, { keyPath: \"keyString\" });\n store.createIndex(SAVED_AT_INDEX, \"savedAt\");\n }\n };\n request.onerror = () => {\n reject(toError(request.error, \"indexedDB.open failed\"));\n };\n request.onblocked = () => {\n reject(new Error(`indexedDB.open blocked for database \"${dbName}\"`));\n };\n request.onsuccess = () => {\n const db = request.result;\n // Drop the cached promise if the connection is closed or another\n // tab requests a version upgrade, so the next openDb() reopens a\n // valid connection instead of reusing a dead IDBDatabase.\n const evict = (): void => {\n if (dbPromises.get(dbName) === promise) dbPromises.delete(dbName);\n };\n db.onclose = evict;\n db.onversionchange = () => {\n db.close();\n evict();\n };\n resolve(db);\n };\n });\n\n promise.catch(() => {\n if (dbPromises.get(dbName) === promise) dbPromises.delete(dbName);\n });\n dbPromises.set(dbName, promise);\n return promise;\n}\n\n/**\n * Promise wrapper for one IDB request.\n *\n * @internal\n */\nfunction requestToPromise<T>(request: IDBRequest<T>): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n request.onerror = () => {\n reject(toError(request.error, \"IndexedDB request failed\"));\n };\n request.onsuccess = () => {\n resolve(request.result);\n };\n });\n}\n\n/**\n * Resolves only when the whole IDB transaction completes.\n *\n * @internal\n */\nfunction transactionDone(tx: IDBTransaction): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n tx.onabort = () => {\n reject(toError(tx.error, \"IndexedDB transaction aborted\"));\n };\n tx.onerror = () => {\n reject(toError(tx.error, \"IndexedDB transaction failed\"));\n };\n tx.oncomplete = () => {\n resolve();\n };\n });\n}\n\n/**\n * Reads all well-formed snapshot records from the store.\n *\n * @internal\n */\nfunction readAllRecords(store: IDBObjectStore): Promise<ReadonlyArray<StoredRecord>> {\n return new Promise<ReadonlyArray<StoredRecord>>((resolve, reject) => {\n const records: StoredRecord[] = [];\n const request = store.index(SAVED_AT_INDEX).openCursor();\n request.onerror = () => {\n reject(toError(request.error, \"IndexedDB cursor failed\"));\n };\n request.onsuccess = () => {\n const cursor = request.result;\n if (cursor === null) {\n resolve(records);\n return;\n }\n if (isStoredRecord(cursor.value)) records.push(cursor.value);\n cursor.continue();\n };\n });\n}\n\n/**\n * Evicts savedAt-ascending records until the pending write fits the cap.\n *\n * @internal\n */\nasync function evictUntilUnderCap(\n store: IDBObjectStore,\n records: ReadonlyArray<StoredRecord>,\n keyString: string,\n nextBytes: number,\n capBytes: number,\n): Promise<void> {\n let total = 0;\n const candidates: StoredRecord[] = [];\n for (const record of records) {\n if (record.keyString === keyString) continue;\n total += record.bytesEstimate;\n candidates.push(record);\n }\n candidates.sort((a, b) => a.savedAt - b.savedAt);\n\n for (const record of candidates) {\n if (total + nextBytes <= capBytes) return;\n await requestToPromise(store.delete(record.keyString));\n total -= record.bytesEstimate;\n }\n}\n\n/**\n * UTF-16 byte estimate used for best-effort cap accounting.\n *\n * @internal\n */\nfunction estimateSnapshotBytes(snapshot: StateSnapshot): number {\n return JSON.stringify(snapshot).length * 2;\n}\n\n/**\n * Narrows records read from IDB's untyped structured-clone surface.\n *\n * @internal\n */\nfunction isStoredRecord(value: unknown): value is StoredRecord {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"keyString\" in value) || typeof value.keyString !== \"string\") return false;\n if (!(\"bytesEstimate\" in value) || typeof value.bytesEstimate !== \"number\") return false;\n if (!(\"savedAt\" in value) || typeof value.savedAt !== \"number\") return false;\n if (!(\"snapshot\" in value)) return false;\n return true;\n}\n\n/**\n * Preserves underlying IDB messages on rejection paths.\n *\n * @internal\n */\nfunction toError(value: unknown, fallback: string): Error {\n if (value instanceof DOMException) return new Error(value.message);\n if (value instanceof Error) return value;\n if (typeof value === \"string\") return new Error(value);\n return new Error(fallback);\n}\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nexport { createWorkerHost } from \"./createWorkerHost.js\";\nexport type { CreateWorkerHostOpts } from \"./createWorkerHost.js\";\nexport { createWorkerBoot } from \"./createWorkerBoot.js\";\nexport type { WorkerBootScope } from \"./createWorkerBoot.js\";\nexport { DEFAULT_LIMITS } from \"./limits.js\";\nexport type {\n HostCompiledScript,\n HostLimits,\n ScriptHost,\n WorkerLike,\n} from \"./types.js\";\nexport type { HostToWorker, WorkerToHost } from \"./protocol.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAI/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,cAAc,GAAe,MAAM,CAAC,MAAM,CAAC;IACpD,YAAY,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IAC9B,eAAe,EAAE,EAAE;IACnB,iBAAiB,EAAE,KAAK;IACxB,gBAAgB,EAAE,MAAM;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC3B,EAAoB,EACpB,KAAa;IAEb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC1C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAChE,CAAC"}
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAI/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,cAAc,GAAe,MAAM,CAAC,MAAM,CAAC;IACpD,YAAY,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IAC9B,eAAe,EAAE,EAAE;IACnB,iBAAiB,EAAE,KAAK;IACxB,gBAAgB,EAAE,MAAM;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC3B,EAAoB,EACpB,KAAa;IAEb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC1C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAChE,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { HostLimits } from \"./types.js\";\n\n/**\n * Phase-1 default `HostLimits`. `maxCpuMsPerStep` is the only enforced cap;\n * `maxHeapBytes` is advisory (no per-worker heap API exists in browsers\n * today) and `maxRingBufferBars` is forwarded for runtime sizing decisions.\n * `maxLoadTimeoutMs` bounds `host.load()` so a silently-dead worker can't\n * hang a consumer indefinitely; 30s is generous for module fetch + parse\n * on a slow network and still bounded enough to recover.\n * Frozen so consumers cannot mutate the singleton.\n *\n * @since 0.1\n * @stable\n * @example\n * import { DEFAULT_LIMITS } from \"@invinite-org/chartlang-host-worker\";\n * const cpu = DEFAULT_LIMITS.maxCpuMsPerStep; // 50\n * void cpu;\n */\nexport const DEFAULT_LIMITS: HostLimits = Object.freeze({\n maxHeapBytes: 64 * 1024 * 1024,\n maxCpuMsPerStep: 50,\n maxRingBufferBars: 5_000,\n maxLoadTimeoutMs: 30_000,\n});\n\n/**\n * Wall-clock measurement around `fn`. Returns `result` (always — Phase-1\n * enforcement is measurement, not preemption) and `overshoot` (the observed\n * elapsed ms when over budget, `0` otherwise). The worker boot uses this to\n * post `step-overshoot` to the host; Phase 5's QuickJS host swaps this seam\n * for real `setInterruptHandler`-based preemption.\n *\n * Re-throws if `fn` rejects — overshoot detection does not swallow errors.\n *\n * @since 0.1\n * @stable\n * @example\n * // const { result, overshoot } = await watchStep(async () => 42, 100);\n * // result === 42; overshoot === 0;\n * const fn: typeof watchStep = watchStep;\n * void fn;\n */\nexport async function watchStep<T>(\n fn: () => Promise<T>,\n maxMs: number,\n): Promise<{ readonly result: T; readonly overshoot: number }> {\n const start = performance.now();\n const result = await fn();\n const elapsed = performance.now() - start;\n return { result, overshoot: elapsed > maxMs ? elapsed : 0 };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D"}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type {\n AdapterSymInfo,\n CandleEvent,\n Capabilities,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\n\nimport type { HostCompiledScript, HostLimits } from \"./types.js\";\n\n/**\n * Messages the main thread posts into the worker. JSON-clean by construction\n * — every payload survives `structuredClone` without bespoke transferables.\n *\n * - `load` carries the compiled bundle, the adapter's `Capabilities`, and the\n * host's `HostLimits`. Optional `inputOverrides` / `plotOverrides` are\n * already resolved on the host side because callbacks cannot cross the\n * worker boundary.\n * - `candleEvent` is fire-and-forget — the worker only replies on overshoot\n * or fatal.\n * - `setPlotOverrides` swaps the live presentation-override map; fire-and-forget\n * like `candleEvent` — the next `drain` reflects it without a recompute.\n * - `drain` carries a host-issued `nonce`; the matching reply echoes it.\n * - `dispose` has no reply.\n *\n * @since 0.1\n * @stable\n * @example\n * const m: HostToWorker = { kind: \"dispose\" };\n * void m;\n */\nexport type HostToWorker =\n | {\n readonly kind: \"load\";\n readonly compiled: HostCompiledScript;\n readonly capabilities: Capabilities;\n readonly symInfo?: AdapterSymInfo;\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n readonly plotOverrides?: Readonly<Record<string, PlotOverride>>;\n readonly limits: HostLimits;\n }\n | { readonly kind: \"candleEvent\"; readonly event: CandleEvent }\n | {\n readonly kind: \"setPlotOverrides\";\n readonly overrides: Readonly<Record<string, PlotOverride>>;\n }\n | { readonly kind: \"drain\"; readonly nonce: number }\n | { readonly kind: \"dispose\" };\n\n/**\n * Messages the worker posts back to the main thread.\n *\n * - `loaded` / `loadError` close the `load` round-trip.\n * - `emissions` carries the matching `nonce` from the `drain` request.\n * - `step-overshoot` is fire-and-forget — Phase-1 enforcement is\n * measurement, not preemption. The host surfaces overshoots via\n * `onWorkerError`; Phase 5's QuickJS host adds real interrupt-based\n * preemption.\n * - `fatal` reports any uncaught error inside the boot's message handler.\n *\n * @since 0.1\n * @stable\n * @example\n * const m: WorkerToHost = { kind: \"loaded\" };\n * void m;\n */\nexport type WorkerToHost =\n | { readonly kind: \"loaded\" }\n | { readonly kind: \"loadError\"; readonly message: string }\n | {\n readonly kind: \"emissions\";\n readonly nonce: number;\n readonly emissions: RunnerEmissions;\n }\n | { readonly kind: \"step-overshoot\"; readonly observedMs: number }\n | { readonly kind: \"fatal\"; readonly message: string };\n"]}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type {\n CandleEvent,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\nimport type { Bar, CompiledScriptObject, ScriptManifest } from \"@invinite-org/chartlang-core\";\n\n/**\n * Resource caps a `ScriptHost` reports to its consumer. Phase-1 `host-worker`\n * enforces `maxCpuMsPerStep` via measurement-only watchdog inside the worker\n * boot; `maxHeapBytes` is advisory (no browser API exists for reliable\n * per-worker heap caps — Phase 5's QuickJS host adds real limits).\n * `maxRingBufferBars` is forwarded for runtime sizing decisions.\n *\n * `maxLoadTimeoutMs` bounds how long `host.load()` is allowed to wait for the\n * worker's `loaded` reply before rejecting with a descriptive timeout error.\n * A silently-dead worker (failed module fetch, exception during boot, OS-level\n * crash) would otherwise leave `load()` pending forever.\n *\n * @since 0.1\n * @stable\n * @example\n * const limits: HostLimits = {\n * maxHeapBytes: 64 * 1024 * 1024,\n * maxCpuMsPerStep: 50,\n * maxRingBufferBars: 5_000,\n * maxLoadTimeoutMs: 30_000,\n * };\n */\nexport type HostLimits = {\n readonly maxHeapBytes: number;\n readonly maxCpuMsPerStep: number;\n readonly maxRingBufferBars: number;\n readonly maxLoadTimeoutMs: number;\n};\n\n/**\n * The minimal compiled-script shape the host streams across the postMessage\n * boundary. Mirrors `@invinite-org/chartlang-compiler`'s `CompiledScript`\n * without naming it — keeps `host-worker` free of a compiler dependency while\n * still pinning the wire contract (Phase 1 walking skeleton).\n *\n * @since 0.1\n * @stable\n * @example\n * const cs: HostCompiledScript = {\n * moduleSource: \"export default { manifest: {...}, compute: () => {} };\",\n * manifest: {\n * apiVersion: 1,\n * kind: \"indicator\",\n * name: \"demo\",\n * inputs: {},\n * capabilities: [\"indicators\"],\n * requestedIntervals: [],\n * userPickableInterval: false,\n * seriesCapacities: {},\n * maxLookback: 0,\n * },\n * };\n */\nexport type HostCompiledScript = {\n readonly moduleSource: string;\n readonly manifest: ScriptManifest;\n};\n\n/**\n * Host-side lifecycle handle the worker host returns. Mirrors PLAN §8.1 — the\n * Phase-1 Web Worker host owns the only declaration; Phase-5's QuickJS host\n * re-uses the same shape. Methods cross the worker boundary via structured\n * clones; `dispose` terminates the worker.\n *\n * @since 0.1\n * @stable\n * @example\n * declare const host: ScriptHost;\n * await host.load({\n * moduleSource: \"export default { manifest: m, compute: () => {} };\",\n * manifest: m,\n * });\n * await host.push({ kind: \"history\", bars: [] });\n * const emissions = await host.drain();\n * host.dispose();\n * void emissions;\n */\nexport type ScriptHost = {\n load(compiled: HostCompiledScript): Promise<void>;\n push(event: CandleEvent): Promise<void>;\n /**\n * Live-swap the per-slot presentation overrides keyed by\n * `PlotEmission.slotId`. Presentation-only — no recompute; the next\n * `drain` reflects the new map. @since 0.8\n */\n setPlotOverrides(overrides: Readonly<Record<string, PlotOverride>>): void;\n drain(): Promise<RunnerEmissions>;\n dispose(): void;\n readonly limits: HostLimits;\n};\n\n/**\n * Duck-typed slice of the browser `Worker` / `MessagePort` surface the host\n * needs. Tests supply a `MessageChannel` port; production supplies a real\n * `Worker`. `terminate` is optional because `MessagePort` doesn't expose it —\n * the host feature-detects before calling.\n *\n * The `addEventListener(\"error\", ...)` overload models the browser `Worker`'s\n * boot/runtime failure channel. `MessagePort`-backed fakes accept the\n * subscription but never fire it; the host unconditionally subscribes and\n * relies on the boundary's natural no-op.\n *\n * @since 0.1\n * @stable\n * @example\n * const ch = new MessageChannel();\n * const worker: WorkerLike = ch.port1;\n * void worker;\n */\nexport type WorkerLike = {\n addEventListener(type: \"message\", listener: (ev: MessageEvent<unknown>) => void): void;\n addEventListener(type: \"error\", listener: (ev: WorkerErrorEvent) => void): void;\n postMessage(msg: unknown): void;\n terminate?(): void;\n};\n\n/**\n * The minimum subset of `ErrorEvent` the host reads when a real `Worker`\n * fails to boot or crashes. Defined locally because `MessagePort` doesn't\n * dispatch `ErrorEvent` and we don't want to drag a DOM-typed alias through\n * the worker boundary.\n *\n * @since 0.1\n * @stable\n * @example\n * const ev: WorkerErrorEvent = { message: \"boot failed\" };\n * void ev;\n */\nexport type WorkerErrorEvent = {\n readonly message?: string;\n readonly filename?: string;\n readonly error?: unknown;\n};\n\n/**\n * The runtime-level surface a worker boot stands up around a compiled script.\n * Re-declared here so the boot module doesn't pull `createScriptRunner`'s\n * typings through `@invinite-org/chartlang-runtime`'s barrel during dynamic\n * import resolution.\n *\n * @since 0.1\n * @stable\n * @example\n * // declare const r: ScriptRunnerHandle;\n * // await r.onBarClose({ time: 0, open: 1, high: 1, low: 1, close: 1, volume: 0, symbol: \"\", interval: \"\" });\n * declare const r: ScriptRunnerHandle;\n * void r;\n */\nexport type ScriptRunnerHandle = {\n onHistory(bars: ReadonlyArray<Bar>): Promise<void>;\n onBarClose(bar: Bar): Promise<void>;\n onBarTick(bar: Bar): Promise<void>;\n push(event: CandleEvent): Promise<void>;\n drain(): RunnerEmissions;\n setPlotOverrides(overrides: Readonly<Record<string, PlotOverride>>): void;\n dispose(): Promise<void>;\n};\n\n/**\n * The default ESM-export shape the worker boot expects from a dynamically\n * imported compiled module. Matches `@invinite-org/chartlang-compiler`'s\n * bundled output:\n *\n * - **Single-script** files export `default` + `__manifest:\n * ScriptManifest` (and may omit `__manifest`).\n * - **Multi-export / composition** files (§22.10) additionally export\n * one named const per drawn sibling (`mod[exportName]`), an array\n * `__manifest: ReadonlyArray<ScriptManifest>`, and (when the default\n * manifest carries `dependencies`) `__dependencies` carrying every\n * private-dep compiled object.\n *\n * The `[exportName: string]: unknown` index signature keeps sibling\n * reads narrow without forcing every host caller to assert types — the\n * host walks `mod[exportName]` with the local\n * `isCompiledScriptObject` guard before forwarding.\n *\n * @since 0.1 — widened in 0.7 for indicator-composition bundles.\n * @stable\n * @example\n * const m: CompiledModuleExport = {\n * default: { manifest: {} as ScriptManifest, compute: () => {} },\n * };\n * void m;\n */\nexport type CompiledModuleExport = {\n readonly default: CompiledScriptObject;\n /**\n * Sidecar manifest. Single object for back-compat single-script\n * bundles; array of `ScriptManifest` (default first) for\n * multi-export composition bundles.\n *\n * @since 0.7\n */\n readonly __manifest?: ScriptManifest | ReadonlyArray<ScriptManifest>;\n /**\n * Inlined private deps a multi-export bundle exposes for host\n * mounting. Each entry's `compiled` is the `defineIndicator(...)`\n * return value bound to a module-local `const <localId>` in the\n * consumer's source.\n *\n * @since 0.7\n */\n readonly __dependencies?: ReadonlyArray<{\n readonly localId: string;\n readonly compiled: CompiledScriptObject;\n /**\n * Merged `.withInputs({...})` overrides the consumer applied\n * to its alias binding. Forwarded to the runtime so the\n * `DepRunner` evaluates the producer's `compute` with the\n * consumer-supplied inputs instead of the producer's\n * manifest defaults. Omitted for direct\n * `defineIndicator(...)` private deps that don't apply\n * overrides.\n *\n * @since 0.7\n */\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n }>;\n readonly [exportName: string]: unknown;\n};\n"]}