@invinite-org/chartlang-compiler 1.0.1 → 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.
Files changed (82) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +3 -0
  3. package/dist/analysis/extractCapabilities.d.ts +5 -1
  4. package/dist/analysis/extractCapabilities.d.ts.map +1 -1
  5. package/dist/analysis/extractCapabilities.js +6 -2
  6. package/dist/analysis/extractCapabilities.js.map +1 -1
  7. package/dist/analysis/extractDependencyGraph.d.ts +160 -0
  8. package/dist/analysis/extractDependencyGraph.d.ts.map +1 -0
  9. package/dist/analysis/extractDependencyGraph.js +690 -0
  10. package/dist/analysis/extractDependencyGraph.js.map +1 -0
  11. package/dist/analysis/extractInputs.d.ts +5 -1
  12. package/dist/analysis/extractInputs.d.ts.map +1 -1
  13. package/dist/analysis/extractInputs.js +6 -2
  14. package/dist/analysis/extractInputs.js.map +1 -1
  15. package/dist/analysis/extractMaxLookback.d.ts +6 -1
  16. package/dist/analysis/extractMaxLookback.d.ts.map +1 -1
  17. package/dist/analysis/extractMaxLookback.js +10 -5
  18. package/dist/analysis/extractMaxLookback.js.map +1 -1
  19. package/dist/analysis/forbiddenConstructs.d.ts +1 -2
  20. package/dist/analysis/forbiddenConstructs.d.ts.map +1 -1
  21. package/dist/analysis/forbiddenConstructs.js +4 -2
  22. package/dist/analysis/forbiddenConstructs.js.map +1 -1
  23. package/dist/analysis/index.d.ts +3 -1
  24. package/dist/analysis/index.d.ts.map +1 -1
  25. package/dist/analysis/index.js +1 -0
  26. package/dist/analysis/index.js.map +1 -1
  27. package/dist/analysis/structuralChecks.d.ts +65 -9
  28. package/dist/analysis/structuralChecks.d.ts.map +1 -1
  29. package/dist/analysis/structuralChecks.js +111 -22
  30. package/dist/analysis/structuralChecks.js.map +1 -1
  31. package/dist/api.d.ts +52 -0
  32. package/dist/api.d.ts.map +1 -1
  33. package/dist/api.js +485 -35
  34. package/dist/api.js.map +1 -1
  35. package/dist/bundle.d.ts +91 -3
  36. package/dist/bundle.d.ts.map +1 -1
  37. package/dist/bundle.js +88 -5
  38. package/dist/bundle.js.map +1 -1
  39. package/dist/dependency/index.d.ts +3 -0
  40. package/dist/dependency/index.d.ts.map +1 -0
  41. package/dist/dependency/index.js +4 -0
  42. package/dist/dependency/index.js.map +1 -0
  43. package/dist/dependency/resolveProducer.d.ts +183 -0
  44. package/dist/dependency/resolveProducer.d.ts.map +1 -0
  45. package/dist/dependency/resolveProducer.js +256 -0
  46. package/dist/dependency/resolveProducer.js.map +1 -0
  47. package/dist/diagnostics.d.ts +6 -2
  48. package/dist/diagnostics.d.ts.map +1 -1
  49. package/dist/diagnostics.js.map +1 -1
  50. package/dist/index.d.ts +3 -1
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +1 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/manifest.d.ts +8 -1
  55. package/dist/manifest.d.ts.map +1 -1
  56. package/dist/manifest.js +27 -0
  57. package/dist/manifest.js.map +1 -1
  58. package/dist/program.d.ts +1 -0
  59. package/dist/program.d.ts.map +1 -1
  60. package/dist/program.js +80 -4
  61. package/dist/program.js.map +1 -1
  62. package/dist/transformers/callsiteIdInjection.d.ts +3 -2
  63. package/dist/transformers/callsiteIdInjection.d.ts.map +1 -1
  64. package/dist/transformers/callsiteIdInjection.js +16 -1
  65. package/dist/transformers/callsiteIdInjection.js.map +1 -1
  66. package/dist/transformers/index.d.ts +2 -0
  67. package/dist/transformers/index.d.ts.map +1 -1
  68. package/dist/transformers/index.js +1 -0
  69. package/dist/transformers/index.js.map +1 -1
  70. package/dist/transformers/plotKindFromCallsite.d.ts +43 -0
  71. package/dist/transformers/plotKindFromCallsite.d.ts.map +1 -0
  72. package/dist/transformers/plotKindFromCallsite.js +103 -0
  73. package/dist/transformers/plotKindFromCallsite.js.map +1 -0
  74. package/dist/transformers/rewriteDependencyAccessors.d.ts +65 -0
  75. package/dist/transformers/rewriteDependencyAccessors.d.ts.map +1 -0
  76. package/dist/transformers/rewriteDependencyAccessors.js +204 -0
  77. package/dist/transformers/rewriteDependencyAccessors.js.map +1 -0
  78. package/dist/typesEmit.d.ts +14 -11
  79. package/dist/typesEmit.d.ts.map +1 -1
  80. package/dist/typesEmit.js +91 -7
  81. package/dist/typesEmit.js.map +1 -1
  82. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,112 @@
1
1
  # @invinite-org/chartlang-compiler
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6aeeb02: Add an `inMemoryModules` option to `compile` (and `bundleModule`): a `{ [bareSpecifier]: selfContainedEsmSource }` map the esbuild bundling step resolves in-memory instead of from disk. This lets a host run the compiler where the workspace `@invinite-org/chartlang-*` packages are not installed as resolvable `node_modules` — e.g. a bundled serverless function, where the packages are inlined into the host bundle rather than shipped to the function filesystem. Each value must be pre-bundled (no remaining bare imports). When omitted, resolution stays on disk exactly as before.
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - f0c8eb8: Add `CompiledScriptObject.output` / `.withInputs` sentinels, `DependencyDeclaration` + `OutputDeclaration` types, optional `dependencies` / `outputs` / `exportName` / `siblings` / `isDrawn` fields on `ScriptManifest`, `CompiledScriptBundle` + `isCompiledScriptBundle` narrowing helper, and six new `dep-*` `DiagnosticCode` entries (`dep-error`, `dep-cycle`, `dep-unknown-output`, `dep-invalid-input-override`, `dep-dynamic`, `dep-output-not-titled`). The compiler ambient shim is widened in lockstep so script source resolves the new surface. Additive within `apiVersion: 1`.
14
+ - f0c8eb8: Add `extractDependencyGraph` analysis pass and `rewriteDependencyAccessors`
15
+ transformer for indicator composition. Six new `dep-*` compile diagnostics
16
+ plus three structural diagnostics (`multiple-default-exports`,
17
+ `non-const-define-binding`, `duplicate-output-title`). Multi-binding
18
+ `defineIndicator` per file now accepted; single-file behaviour unchanged.
19
+ Existing `.chart.ts` files compile through with byte-identical output.
20
+ - 2123181: Bundle multi-export `.chart.ts` files into one ESM module, inline cross-file
21
+ `.chart.ts` deps recursively via the new `createProducerResolver` walker, emit
22
+ a union-shape manifest sidecar (single object or array depending on
23
+ drawn-export count), and emit per-export `.d.ts` declarations carrying the
24
+ typed `output<K>` / `withInputs` accessors. Single-script files remain
25
+ byte-identical.
26
+ - 2123181: Indicator composition (Phase 7 closeout): one chartlang indicator can
27
+ read another indicator's titled plot output as a typed `Series<number>`.
28
+
29
+ - Compose via local `const` binding plus `<binding>.output("title")` —
30
+ no new public API beyond the chainable `.output` / `.withInputs`
31
+ accessors on `CompiledScriptObject`.
32
+ - A single `.chart.ts` MAY declare a default export plus any number of
33
+ named exports plus any number of private `const` deps. Export form
34
+ determines render policy: drawn exports render with the
35
+ `export:<exportName>/` slot-id prefix; private `const` deps are data
36
+ feeds only and their visuals are dropped.
37
+ - Cross-file `import baseTrend from "./base-trend.chart"` resolves
38
+ recursively; shared producers inline exactly once per consumer.
39
+ - Additive within `apiVersion: 1.x`. The 172-entry
40
+ `STATEFUL_PRIMITIVES` set is unchanged. `DiagnosticCode` widens to 32
41
+ with the new `dep-*` codes (`dep-error`, `dep-cycle`,
42
+ `dep-unknown-output`, `dep-invalid-input-override`, `dep-dynamic`,
43
+ `dep-output-not-titled`).
44
+ - Five conformance scenarios in `@invinite-org/chartlang-conformance`
45
+ pin the runtime contract end-to-end (`dep-private-single-file`,
46
+ `dep-multi-export`, `dep-cross-file`, `dep-diamond`,
47
+ `dep-error-halts-parent`). `Scenario.additionalSources` lets
48
+ cross-file scenarios ship producer + consumer side-by-side.
49
+ - Two new example scripts in `examples/scripts/`:
50
+ `base-trend.chart.ts` (producer) + `trend-confirmation.chart.ts`
51
+ (multi-export consumer). React-demo gains a fifth catalogue entry
52
+ exercising the feature end-to-end in the browser.
53
+ - Docs: `docs/language/indicator-composition.md` narrative guide,
54
+ `docs/spec/manifest.md` + `docs/spec/semantics.md` +
55
+ `docs/spec/versioning.md` updates, five new glossary entries.
56
+
57
+ - 2123181: Light up the end-to-end cross-file dep path for indicator composition. The
58
+ compiler's `rewriteDependencyAccessors` transformer now collapses
59
+ `const <alias> = <root>.withInputs({...})...` chains to the bare root
60
+ identifier so the runtime sentinel never fires at module load; the merged
61
+ effective inputs flow through the `__dependencies[i].inputOverrides` slot
62
+ into the runtime's `DepRunner`. Cross-file producers' `@invinite-org/chartlang-core`
63
+ imports are hoisted above the inlined IIFE so esbuild dedupes them against
64
+ the consumer's imports and pulls in every symbol the producer uses
65
+ (`input.int`, `ta.ema`, …). The `__dependencies` export is now prepended
66
+ pre-bundle so esbuild's tree-shaker keeps each alias binding alive. The
67
+ `dep-cross-file` conformance scenario joins `ALL_SCENARIOS` and the suite
68
+ runs 225 scenarios green.
69
+ - 4d77f4d: Emit `ScriptManifest.plots` — one `PlotSlotDescriptor` per `plot()` /
70
+ `hline()` callsite, in source order, carrying the compiler-issued
71
+ `slotId`, the statically-known plot `kind` (derived from the opts
72
+ `style.kind` literal; bare `plot` ⇒ `line`, `hline` ⇒ `horizontal-line`;
73
+ dynamic styles fall back to `line` best-effort), and a literal `title`
74
+ when present. Additive: the field is omitted for scripts with no
75
+ plot/hline callsites, so existing manifests are byte-identical.
76
+ - 0427459: Persist `defineIndicator({ overlay })` onto `ScriptManifest.overlay?:
77
+ boolean` so the runtime has a script-level default-pane signal. Add
78
+ `HLineOpts.pane?: "overlay" | "new" | string` mirroring `PlotOpts.pane`
79
+ so hlines opt into the same pane router. The compiler's `buildManifest`
80
+ extracts the literal-boolean `overlay` from the `defineIndicator`
81
+ object literal via `extractOverrides` and emits it on the bundled
82
+ `__manifest`; the ambient core shim now carries `ScriptManifest.overlay?`
83
+ and `HLineOpts.pane?` to keep downstream packages type-aligned.
84
+
85
+ Step 1 of the `subpane-rendering` feature. Pure additive contract
86
+ change — every new field is optional and absence keeps existing
87
+ manifests / emissions byte-identical. The runtime, adapter, and demos
88
+ land in tasks 2-5.
89
+
90
+ ### Patch Changes
91
+
92
+ - d6d1a1f: Fix Phase-7 indicator composition where a producer's titled `plot(...)` outputs were never wired to consumers. The compiler computed each binding's `outputs` statically but only wrote them into the manifest sidecar, never onto the producer object's own `manifest.outputs` — so the runtime allocated no dep-output ring buffer and every `<binding>.output("title")` read returned NaN past warmup.
93
+
94
+ `defineIndicator` now copies an optional `outputs` opts field into the manifest (omitted ⇒ manifest byte-identical to a script with no titled plots), and the compiler bakes each producer binding's titled `outputs` into its `defineIndicator({...})` opts literal so private deps, named-export siblings, and cross-file producer defaults are self-describing at runtime. Output-free scripts are untouched. Additive within `apiVersion: 1`.
95
+
96
+ - 3b4952d: Remove the redundant `bars` plot kind. It was never reachable from the script-author API (`PlotOptsStyle` had no `bars` arm and the runtime `buildStyle` had no `case`), no `ta.*` primitive or example emitted it, and the canvas2d reference adapter declared it as a capability but never rendered it. It carried the same `{ baseline: number }` shape as `histogram`, so it was a dead arm of the `PlotKind` / wire-level `PlotStyle` unions.
97
+
98
+ `PlotKind`, the adapter-kit `PlotStyle` union, `validateEmission`, the `capabilities.bars()` / `PHASE_5_PLOT_KINDS` surfaces, and the canvas2d adapter's dead `bars.ts` renderer are all dropped. chartlang has no users yet, so this is a hard reset with no deprecation path. Authors who want columns use `histogram`.
99
+
100
+ - Updated dependencies [d6d1a1f]
101
+ - Updated dependencies [f0c8eb8]
102
+ - Updated dependencies [2123181]
103
+ - Updated dependencies [2123181]
104
+ - Updated dependencies [2123181]
105
+ - Updated dependencies [4d77f4d]
106
+ - Updated dependencies [3b4952d]
107
+ - Updated dependencies [0427459]
108
+ - @invinite-org/chartlang-core@1.1.0
109
+
3
110
  ## 1.0.1
4
111
 
5
112
  ### Patch Changes
package/README.md CHANGED
@@ -29,6 +29,9 @@ pnpm add @invinite-org/chartlang-compiler
29
29
  - Phase 4 diagnostics include `input-call-not-literal`,
30
30
  `input-schema-not-literal`, `requires-intervals-not-literal`, and
31
31
  `request-security-interval-not-literal`.
32
+ - `createProducerResolver({ rootDir }, compileProducer)` — cross-file
33
+ `.chart.ts` resolver feeding indicator-composition (§22.10). Pass it
34
+ to `compile` / `compileFile` / `compileProject` as `resolveProducer`.
32
35
 
33
36
  ## Minimum-viable API call
34
37
 
@@ -10,6 +10,10 @@ type CapabilityId = "indicators" | "drawings" | "alerts" | "alertConditions";
10
10
  * `resolveCalleeName`. The result is deduplicated and sorted for
11
11
  * deterministic manifest output.
12
12
  *
13
+ * The optional `scope` parameter narrows the walk to a single AST subtree
14
+ * (typically one binding's `defineCall`) so multi-export files can derive
15
+ * per-binding capability sets. Defaults to the whole `sourceFile`.
16
+ *
13
17
  * @since 0.1
14
18
  * @example
15
19
  * // const caps = extractCapabilities(sourceFile, checker, "indicator");
@@ -17,6 +21,6 @@ type CapabilityId = "indicators" | "drawings" | "alerts" | "alertConditions";
17
21
  * const fn: typeof extractCapabilities = extractCapabilities;
18
22
  * void fn;
19
23
  */
20
- export declare function extractCapabilities(sourceFile: ts.SourceFile, checker: ts.TypeChecker, kind?: "indicator" | "drawing" | "alert" | "alertCondition"): ReadonlyArray<CapabilityId>;
24
+ export declare function extractCapabilities(sourceFile: ts.SourceFile, checker: ts.TypeChecker, kind?: "indicator" | "drawing" | "alert" | "alertCondition", scope?: ts.Node): ReadonlyArray<CapabilityId>;
21
25
  export {};
22
26
  //# sourceMappingURL=extractCapabilities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractCapabilities.d.ts","sourceRoot":"","sources":["../../src/analysis/extractCapabilities.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,KAAK,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,iBAAiB,CAAC;AAE7E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAC/B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,GAAE,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,gBAA8B,GACzE,aAAa,CAAC,YAAY,CAAC,CAyB7B"}
1
+ {"version":3,"file":"extractCapabilities.d.ts","sourceRoot":"","sources":["../../src/analysis/extractCapabilities.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,KAAK,YAAY,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,iBAAiB,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAC/B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,IAAI,GAAE,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,gBAA8B,EACxE,KAAK,GAAE,EAAE,CAAC,IAAiB,GAC5B,aAAa,CAAC,YAAY,CAAC,CAyB7B"}
@@ -12,6 +12,10 @@ import { resolveCalleeName } from "../transformers/resolveCallee.js";
12
12
  * `resolveCalleeName`. The result is deduplicated and sorted for
13
13
  * deterministic manifest output.
14
14
  *
15
+ * The optional `scope` parameter narrows the walk to a single AST subtree
16
+ * (typically one binding's `defineCall`) so multi-export files can derive
17
+ * per-binding capability sets. Defaults to the whole `sourceFile`.
18
+ *
15
19
  * @since 0.1
16
20
  * @example
17
21
  * // const caps = extractCapabilities(sourceFile, checker, "indicator");
@@ -19,7 +23,7 @@ import { resolveCalleeName } from "../transformers/resolveCallee.js";
19
23
  * const fn: typeof extractCapabilities = extractCapabilities;
20
24
  * void fn;
21
25
  */
22
- export function extractCapabilities(sourceFile, checker, kind = "indicator") {
26
+ export function extractCapabilities(sourceFile, checker, kind = "indicator", scope = sourceFile) {
23
27
  const SEED_BY_KIND = {
24
28
  indicator: "indicators",
25
29
  drawing: "drawings",
@@ -37,7 +41,7 @@ export function extractCapabilities(sourceFile, checker, kind = "indicator") {
37
41
  }
38
42
  ts.forEachChild(node, visit);
39
43
  };
40
- ts.forEachChild(sourceFile, visit);
44
+ visit(scope);
41
45
  const ordered = Array.from(found).sort();
42
46
  return Object.freeze(ordered);
43
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"extractCapabilities.js","sourceRoot":"","sources":["../../src/analysis/extractCapabilities.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAIrE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAC/B,UAAyB,EACzB,OAAuB,EACvB,OAA6D,WAAW;IAExE,MAAM,YAAY,GAEd;QACA,SAAS,EAAE,YAAY;QACvB,OAAO,EAAE,UAAU;QACnB,KAAK,EAAE,QAAQ;QACf,cAAc,EAAE,iBAAiB;KACpC,CAAC;IACF,MAAM,IAAI,GAAiB,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAe,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5C,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;QAClC,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;gBACzB,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,CAAC;QACL,CAAC;QACD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;IACF,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAEnC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"extractCapabilities.js","sourceRoot":"","sources":["../../src/analysis/extractCapabilities.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAIrE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,mBAAmB,CAC/B,UAAyB,EACzB,OAAuB,EACvB,OAA6D,WAAW,EACxE,QAAiB,UAAU;IAE3B,MAAM,YAAY,GAEd;QACA,SAAS,EAAE,YAAY;QACvB,OAAO,EAAE,UAAU;QACnB,KAAK,EAAE,QAAQ;QACf,cAAc,EAAE,iBAAiB;KACpC,CAAC;IACF,MAAM,IAAI,GAAiB,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAe,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5C,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;QAClC,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;gBACzB,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,CAAC;QACL,CAAC;QACD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;IACF,KAAK,CAAC,KAAK,CAAC,CAAC;IAEb,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,160 @@
1
+ import type { JsonValue, OutputDeclaration } from "@invinite-org/chartlang-core";
2
+ import ts from "typescript";
3
+ import { type CompileDiagnostic } from "../diagnostics.js";
4
+ import type { StructuralBindingInfo } from "./structuralChecks.js";
5
+ /**
6
+ * Producer reference recorded on a consumer-side `const` binding. The
7
+ * same-file variant carries the local binding name; the cross-file
8
+ * variant carries the resolved POSIX path + ES-module export name.
9
+ *
10
+ * @since 0.7
11
+ * @stable
12
+ * @example
13
+ * const r: ProducerRef = { kind: "same-file", bindingName: "baseTrend" };
14
+ * void r;
15
+ */
16
+ export type ProducerRef = Readonly<{
17
+ kind: "same-file";
18
+ bindingName: string;
19
+ }> | Readonly<{
20
+ kind: "cross-file";
21
+ sourcePath: string;
22
+ exportName: string;
23
+ }>;
24
+ /**
25
+ * One dep-graph edge — consumer binding → producer with the merged
26
+ * effective inputs the bundler needs to fold into the producer's
27
+ * compiled module at emit time.
28
+ *
29
+ * @since 0.7
30
+ * @stable
31
+ * @example
32
+ * declare const dummyOutputs: ReadonlyArray<OutputDeclaration>;
33
+ * const e: DepConsumesEntry = {
34
+ * localId: "fastTrend",
35
+ * producerRef: { kind: "same-file", bindingName: "baseTrend" },
36
+ * outputs: dummyOutputs,
37
+ * effectiveInputs: { length: 20 },
38
+ * };
39
+ * void e;
40
+ */
41
+ export type DepConsumesEntry = Readonly<{
42
+ readonly localId: string;
43
+ readonly producerRef: ProducerRef;
44
+ readonly outputs: ReadonlyArray<OutputDeclaration>;
45
+ readonly effectiveInputs: Readonly<Record<string, JsonValue>>;
46
+ }>;
47
+ /**
48
+ * One exported (drawn) indicator the file declares. `exportName` is
49
+ * `"default"` for `export default`, the identifier text otherwise.
50
+ *
51
+ * @since 0.7
52
+ * @stable
53
+ * @example
54
+ * // declare const callExpression: ts.CallExpression;
55
+ * const d: DrawnScript = {
56
+ * exportName: "default",
57
+ * bindingName: "default",
58
+ * defineCall: undefined as unknown as ts.CallExpression,
59
+ * outputs: [],
60
+ * consumes: [],
61
+ * };
62
+ * void d;
63
+ */
64
+ export type DrawnScript = Readonly<{
65
+ readonly exportName: string;
66
+ readonly bindingName: string;
67
+ readonly defineCall: ts.CallExpression;
68
+ readonly outputs: ReadonlyArray<OutputDeclaration>;
69
+ readonly consumes: ReadonlyArray<DepConsumesEntry>;
70
+ }>;
71
+ /**
72
+ * One private (data-only) dep binding the file declares. `defineCall`
73
+ * is `null` when the dep is a cross-file binding (the AST node lives
74
+ * in the producer's source file).
75
+ *
76
+ * @since 0.7
77
+ * @stable
78
+ * @example
79
+ * const d: PrivateDep = {
80
+ * localId: "fastTrend",
81
+ * producerRef: { kind: "same-file", bindingName: "baseTrend" },
82
+ * effectiveInputs: { length: 20 },
83
+ * defineCall: null,
84
+ * outputs: [],
85
+ * consumes: [],
86
+ * };
87
+ * void d;
88
+ */
89
+ export type PrivateDep = Readonly<{
90
+ readonly localId: string;
91
+ readonly producerRef: ProducerRef;
92
+ readonly effectiveInputs: Readonly<Record<string, JsonValue>>;
93
+ readonly defineCall: ts.CallExpression | null;
94
+ readonly outputs: ReadonlyArray<OutputDeclaration>;
95
+ readonly consumes: ReadonlyArray<DepConsumesEntry>;
96
+ }>;
97
+ /**
98
+ * Producer snapshot returned by `resolveProducer` for cross-file
99
+ * `import X from "./Y.chart"` consumer references.
100
+ *
101
+ * @since 0.7
102
+ * @stable
103
+ * @example
104
+ * const snap: ProducerSnapshot = { name: "trend", outputs: [], inputs: {} };
105
+ * void snap;
106
+ */
107
+ export type ProducerSnapshot = Readonly<{
108
+ readonly name: string;
109
+ readonly outputs: ReadonlyArray<OutputDeclaration>;
110
+ readonly inputs: Readonly<Record<string, unknown>>;
111
+ }>;
112
+ /**
113
+ * Callback the bundler supplies so the analysis pass can recursively
114
+ * compile sibling `.chart.ts` files. Returns `null` when the producer
115
+ * cannot be resolved (cycle, unknown path, no `defineIndicator(...)`).
116
+ *
117
+ * @since 0.7
118
+ * @stable
119
+ * @example
120
+ * const r: ResolveProducer = () => null;
121
+ * void r;
122
+ */
123
+ export type ResolveProducer = (sourcePath: string, exportName: string) => ProducerSnapshot | null;
124
+ /**
125
+ * The compiled dep-graph artefact returned by `extractDependencyGraph`.
126
+ * `drawn` + `privateDeps` are the indexed binding sets; `diagnostics`
127
+ * is the union of every per-binding diagnostic surfaced during
128
+ * walking + validation.
129
+ *
130
+ * @since 0.7
131
+ * @stable
132
+ * @example
133
+ * const g: DepGraph = { drawn: [], privateDeps: [], diagnostics: [] };
134
+ * void g;
135
+ */
136
+ export type DepGraph = Readonly<{
137
+ readonly drawn: ReadonlyArray<DrawnScript>;
138
+ readonly privateDeps: ReadonlyArray<PrivateDep>;
139
+ readonly diagnostics: ReadonlyArray<CompileDiagnostic>;
140
+ }>;
141
+ /**
142
+ * Run the dependency-graph analysis pass over a `.chart.ts` source
143
+ * file. Sweeps the AST four times — outputs, withInputs chains,
144
+ * consumer `.output(...)` calls, cycle detection — and returns a
145
+ * frozen `DepGraph` plus the diagnostics surfaced along the way.
146
+ *
147
+ * `resolveProducer` is a caller-supplied callback that the bundler
148
+ * (Task 3) wires to a recursive compile entry point. In Task 2 the
149
+ * pass works against `() => null` for cross-file edges; tests pass
150
+ * mocked snapshots instead.
151
+ *
152
+ * @since 0.7
153
+ * @stable
154
+ * @example
155
+ * // const graph = extractDependencyGraph(sf, checker, "demo.chart.ts", bindings, () => null);
156
+ * const fn: typeof extractDependencyGraph = extractDependencyGraph;
157
+ * void fn;
158
+ */
159
+ export declare function extractDependencyGraph(sourceFile: ts.SourceFile, checker: ts.TypeChecker, sourcePath: string, structuralBindings: ReadonlyArray<StructuralBindingInfo>, resolveProducer: ResolveProducer): DepGraph;
160
+ //# sourceMappingURL=extractDependencyGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractDependencyGraph.d.ts","sourceRoot":"","sources":["../../src/analysis/extractDependencyGraph.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,KAAK,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AAE7E,OAAO,KAAK,EAAE,qBAAqB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