@invinite-org/chartlang-compiler 1.0.1

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 (88) hide show
  1. package/CHANGELOG.md +683 -0
  2. package/LICENSE +21 -0
  3. package/README.md +53 -0
  4. package/dist/analysis/extractAlertConditions.d.ts +33 -0
  5. package/dist/analysis/extractAlertConditions.d.ts.map +1 -0
  6. package/dist/analysis/extractAlertConditions.js +118 -0
  7. package/dist/analysis/extractAlertConditions.js.map +1 -0
  8. package/dist/analysis/extractCapabilities.d.ts +22 -0
  9. package/dist/analysis/extractCapabilities.d.ts.map +1 -0
  10. package/dist/analysis/extractCapabilities.js +44 -0
  11. package/dist/analysis/extractCapabilities.js.map +1 -0
  12. package/dist/analysis/extractInputs.d.ts +44 -0
  13. package/dist/analysis/extractInputs.d.ts.map +1 -0
  14. package/dist/analysis/extractInputs.js +306 -0
  15. package/dist/analysis/extractInputs.js.map +1 -0
  16. package/dist/analysis/extractMaxLookback.d.ts +37 -0
  17. package/dist/analysis/extractMaxLookback.d.ts.map +1 -0
  18. package/dist/analysis/extractMaxLookback.js +90 -0
  19. package/dist/analysis/extractMaxLookback.js.map +1 -0
  20. package/dist/analysis/extractRequestedIntervals.d.ts +19 -0
  21. package/dist/analysis/extractRequestedIntervals.d.ts.map +1 -0
  22. package/dist/analysis/extractRequestedIntervals.js +85 -0
  23. package/dist/analysis/extractRequestedIntervals.js.map +1 -0
  24. package/dist/analysis/extractRequiresIntervals.d.ts +16 -0
  25. package/dist/analysis/extractRequiresIntervals.d.ts.map +1 -0
  26. package/dist/analysis/extractRequiresIntervals.js +71 -0
  27. package/dist/analysis/extractRequiresIntervals.js.map +1 -0
  28. package/dist/analysis/forbiddenConstructs.d.ts +22 -0
  29. package/dist/analysis/forbiddenConstructs.d.ts.map +1 -0
  30. package/dist/analysis/forbiddenConstructs.js +214 -0
  31. package/dist/analysis/forbiddenConstructs.js.map +1 -0
  32. package/dist/analysis/index.d.ts +15 -0
  33. package/dist/analysis/index.d.ts.map +1 -0
  34. package/dist/analysis/index.js +13 -0
  35. package/dist/analysis/index.js.map +1 -0
  36. package/dist/analysis/statefulCallInLoop.d.ts +26 -0
  37. package/dist/analysis/statefulCallInLoop.d.ts.map +1 -0
  38. package/dist/analysis/statefulCallInLoop.js +64 -0
  39. package/dist/analysis/statefulCallInLoop.js.map +1 -0
  40. package/dist/analysis/structuralChecks.d.ts +73 -0
  41. package/dist/analysis/structuralChecks.d.ts.map +1 -0
  42. package/dist/analysis/structuralChecks.js +243 -0
  43. package/dist/analysis/structuralChecks.js.map +1 -0
  44. package/dist/analysis/validateLowerTfIntervals.d.ts +26 -0
  45. package/dist/analysis/validateLowerTfIntervals.d.ts.map +1 -0
  46. package/dist/analysis/validateLowerTfIntervals.js +91 -0
  47. package/dist/analysis/validateLowerTfIntervals.js.map +1 -0
  48. package/dist/api.d.ts +205 -0
  49. package/dist/api.d.ts.map +1 -0
  50. package/dist/api.js +354 -0
  51. package/dist/api.js.map +1 -0
  52. package/dist/bundle.d.ts +75 -0
  53. package/dist/bundle.d.ts.map +1 -0
  54. package/dist/bundle.js +90 -0
  55. package/dist/bundle.js.map +1 -0
  56. package/dist/diagnostics.d.ts +88 -0
  57. package/dist/diagnostics.d.ts.map +1 -0
  58. package/dist/diagnostics.js +95 -0
  59. package/dist/diagnostics.js.map +1 -0
  60. package/dist/index.d.ts +9 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +7 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/manifest.d.ts +40 -0
  65. package/dist/manifest.d.ts.map +1 -0
  66. package/dist/manifest.js +57 -0
  67. package/dist/manifest.js.map +1 -0
  68. package/dist/program.d.ts +68 -0
  69. package/dist/program.d.ts.map +1 -0
  70. package/dist/program.js +1391 -0
  71. package/dist/program.js.map +1 -0
  72. package/dist/transformers/callsiteIdInjection.d.ts +48 -0
  73. package/dist/transformers/callsiteIdInjection.d.ts.map +1 -0
  74. package/dist/transformers/callsiteIdInjection.js +91 -0
  75. package/dist/transformers/callsiteIdInjection.js.map +1 -0
  76. package/dist/transformers/index.d.ts +4 -0
  77. package/dist/transformers/index.d.ts.map +1 -0
  78. package/dist/transformers/index.js +5 -0
  79. package/dist/transformers/index.js.map +1 -0
  80. package/dist/transformers/resolveCallee.d.ts +39 -0
  81. package/dist/transformers/resolveCallee.d.ts.map +1 -0
  82. package/dist/transformers/resolveCallee.js +136 -0
  83. package/dist/transformers/resolveCallee.js.map +1 -0
  84. package/dist/typesEmit.d.ts +35 -0
  85. package/dist/typesEmit.d.ts.map +1 -0
  86. package/dist/typesEmit.js +27 -0
  87. package/dist/typesEmit.js.map +1 -0
  88. package/package.json +48 -0
package/dist/bundle.js ADDED
@@ -0,0 +1,90 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname } from "node:path";
5
+ import * as esbuild from "esbuild";
6
+ // The compiler package directory — esbuild's `resolveDir` so the workspace
7
+ // `@invinite-org/chartlang-core` bare specifier resolves through the compiler
8
+ // package's own `node_modules/` symlink. Computed once at module load.
9
+ const COMPILER_PACKAGE_DIR = dirname(dirname(fileURLToPath(import.meta.url)));
10
+ /**
11
+ * Drive esbuild's `build` API against an in-memory transformed TS source and
12
+ * emit a self-contained ESM bundle. Pinned flags: `bundle: true`,
13
+ * `loader: "ts"`, `format: "esm"`, `target: "es2022"`, `treeShaking: true`,
14
+ * `platform: "neutral"`. Bare specifiers like
15
+ * `@invinite-org/chartlang-core` resolve through the compiler package's own
16
+ * `node_modules/` (i.e. `resolveDir` is fixed to the compiler package dir),
17
+ * so the output has zero remaining `import` statements and can load from a
18
+ * `data:` URL inside any host (worker / QuickJS / Node) without a module
19
+ * resolver. Output is ~5–50 KB unminified per PLAN §5.2.
20
+ *
21
+ * @since 0.1
22
+ * @example
23
+ * // const { moduleSource } = await bundleModule({
24
+ * // transformedSource: "export default {};",
25
+ * // sourcePath: "demo.chart.ts",
26
+ * // sourcemap: false,
27
+ * // minify: false,
28
+ * // });
29
+ * const fn: typeof bundleModule = bundleModule;
30
+ * void fn;
31
+ */
32
+ export async function bundleModule(opts) {
33
+ const esbuildSourcemap = opts.sourcemap === false ? false : opts.sourcemap === "inline" ? "inline" : "external";
34
+ const wantsExternalMap = opts.sourcemap === true || opts.sourcemap === "external";
35
+ const buildOpts = {
36
+ stdin: {
37
+ contents: opts.transformedSource,
38
+ loader: "ts",
39
+ sourcefile: opts.sourcePath,
40
+ resolveDir: COMPILER_PACKAGE_DIR,
41
+ },
42
+ bundle: true,
43
+ format: "esm",
44
+ target: "es2022",
45
+ platform: "neutral",
46
+ sourcemap: esbuildSourcemap,
47
+ minify: opts.minify,
48
+ treeShaking: true,
49
+ write: false,
50
+ // `outfile` is required when `sourcemap: "external"`; the virtual path
51
+ // never touches disk because `write: false`.
52
+ ...(wantsExternalMap ? { outfile: `${opts.sourcePath}.js` } : {}),
53
+ };
54
+ const result = await esbuild.build(buildOpts);
55
+ // `outputFiles` is only `undefined` when `write !== false`; we pin
56
+ // `write: false` above so the runtime branch never fires. The defensive
57
+ // throws keep the type narrow without bloating the coverage gate.
58
+ const outputFiles = result.outputFiles ?? /* v8 ignore next */ [];
59
+ const jsFile = outputFiles.find((f) => !f.path.endsWith(".map"));
60
+ /* v8 ignore next 3 */
61
+ if (jsFile === undefined) {
62
+ throw new Error("esbuild produced no JS output file");
63
+ }
64
+ if (wantsExternalMap) {
65
+ const mapFile = outputFiles.find((f) => f.path.endsWith(".map"));
66
+ /* v8 ignore next 3 */
67
+ if (mapFile === undefined) {
68
+ throw new Error("esbuild produced no sourcemap file");
69
+ }
70
+ return Object.freeze({ moduleSource: jsFile.text, sourcemap: mapFile.text });
71
+ }
72
+ return Object.freeze({ moduleSource: jsFile.text });
73
+ }
74
+ /**
75
+ * Synthesise the bottom-of-bundle `export const __manifest = …;` assignment.
76
+ * The runtime reads this constant via dynamic `import(...)` to recover the
77
+ * frozen `ScriptManifest` that travels alongside the compiled JS. Serialised
78
+ * via `JSON.stringify` for determinism (insertion-order key emission).
79
+ *
80
+ * @since 0.1
81
+ * @example
82
+ * // const line = formatManifestAssignment(manifest);
83
+ * // line === 'export const __manifest = {"apiVersion":1,…};\n'
84
+ * const fn: typeof formatManifestAssignment = formatManifestAssignment;
85
+ * void fn;
86
+ */
87
+ export function formatManifestAssignment(manifest) {
88
+ return `export const __manifest = ${JSON.stringify(manifest)};\n`;
89
+ }
90
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAwCnC,2EAA2E;AAC3E,8EAA8E;AAC9E,uEAAuE;AACvE,MAAM,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAyB;IACxD,MAAM,gBAAgB,GAClB,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC;IAE3F,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC;IAElF,MAAM,SAAS,GAAyB;QACpC,KAAK,EAAE;YACH,QAAQ,EAAE,IAAI,CAAC,iBAAiB;YAChC,MAAM,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MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAwB;IAC7D,OAAO,6BAA6B,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;AACtE,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type ts from "typescript";
2
+ /**
3
+ * Stable identifier for every diagnostic the compiler can emit. New codes are
4
+ * added at the end; existing codes never change meaning so consumer-side
5
+ * filtering stays compatible across versions.
6
+ *
7
+ * Phase 1 ships eight emittable codes plus Phase 4's
8
+ * `request.security` and input-extraction codes.
9
+ *
10
+ * @since 0.1
11
+ * @example
12
+ * const code: CompileDiagnosticCode = "unbounded-loop";
13
+ */
14
+ export type CompileDiagnosticCode = "unbounded-loop" | "recursion-not-allowed" | "hostile-global" | "stateful-call-inside-loop" | "stateful-call-element-access" | "request-security-interval-not-literal" | "dynamic-series-index" | "callsite-id-conflict" | "missing-default-export" | "api-version-mismatch" | "input-default-not-literal" | "unknown-input-kind" | "multiple-input-interval" | "requires-intervals-not-literal" | "alert-condition-not-literal" | "alert-condition-field-not-literal" | "lower-tf-not-lower" | "request-lower-tf-interval-not-literal" | "type-error";
15
+ /**
16
+ * Single diagnostic the compiler emits while transforming or analysing a
17
+ * `.chart.ts` source. The shape is intentionally small — file/line/column and
18
+ * a stable code — so callers (CLI, editor, host) can format errors uniformly.
19
+ *
20
+ * `severity` distinguishes hard errors (abort `compile`) from warnings
21
+ * (surface to the user but still produce a manifest).
22
+ *
23
+ * @since 0.1
24
+ * @example
25
+ * const d: CompileDiagnostic = {
26
+ * severity: "error",
27
+ * code: "unbounded-loop",
28
+ * message: "while loops are not allowed",
29
+ * file: "demo.chart.ts",
30
+ * line: 5,
31
+ * column: 1,
32
+ * };
33
+ */
34
+ export type CompileDiagnostic = {
35
+ readonly severity: "error" | "warning";
36
+ readonly code: CompileDiagnosticCode;
37
+ readonly message: string;
38
+ readonly file: string;
39
+ readonly line: number;
40
+ readonly column: number;
41
+ readonly nodeText?: string;
42
+ };
43
+ /**
44
+ * Build a frozen `CompileDiagnostic` from a TypeScript node. Reads the node's
45
+ * starting position against the supplied source file, converts to 1-based
46
+ * line/column, and truncates the source snippet to a single line so terminal
47
+ * output stays compact.
48
+ *
49
+ * @since 0.1
50
+ * @example
51
+ * // Inside an analysis pass:
52
+ * // diagnostics.push(createDiagnostic({
53
+ * // severity: "error", code: "unbounded-loop",
54
+ * // message: "while loops are not allowed",
55
+ * // file: sourcePath, node, sourceFile,
56
+ * // }));
57
+ * const fake = { severity: "error" as const };
58
+ * void fake;
59
+ */
60
+ export declare function createDiagnostic(args: {
61
+ readonly severity: "error" | "warning";
62
+ readonly code: CompileDiagnosticCode;
63
+ readonly message: string;
64
+ readonly file: string;
65
+ readonly node: ts.Node;
66
+ readonly sourceFile: ts.SourceFile;
67
+ readonly includeSnippet?: boolean;
68
+ }): CompileDiagnostic;
69
+ /**
70
+ * Build a frozen `CompileDiagnostic` from a raw TypeScript `ts.Diagnostic`.
71
+ * Used by the `compile()` pipeline to surface semantic type-checker errors
72
+ * (TS2322, TS2345, …) under the `type-error` code. Carries the original
73
+ * `TS<code>` numeric prefix in the message so editor consumers can route
74
+ * to the TypeScript documentation if they want.
75
+ *
76
+ * Diagnostics without a `file` (global-scope, project-shape) are mapped to
77
+ * the script's `sourcePath` at line/column `1:1` so callers always get a
78
+ * stable location they can attribute to the user's source. The message is
79
+ * flattened across `DiagnosticMessageChain` nodes.
80
+ *
81
+ * @since 0.7
82
+ * @example
83
+ * // const compileDiagnostic = mapTsDiagnostic(tsDiagnostic, "demo.chart.ts");
84
+ * const fn: typeof mapTsDiagnostic = mapTsDiagnostic;
85
+ * void fn;
86
+ */
87
+ export declare function mapTsDiagnostic(diagnostic: ts.Diagnostic, sourcePath: string): CompileDiagnostic;
88
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,qBAAqB,GAC3B,gBAAgB,GAChB,uBAAuB,GACvB,gBAAgB,GAChB,2BAA2B,GAC3B,8BAA8B,GAC9B,uCAAuC,GACvC,sBAAsB,GACtB,sBAAsB,GACtB,wBAAwB,GACxB,sBAAsB,GACtB,2BAA2B,GAC3B,oBAAoB,GACpB,yBAAyB,GACzB,gCAAgC,GAChC,6BAA6B,GAC7B,mCAAmC,GACnC,oBAAoB,GACpB,uCAAuC,GACvC,YAAY,CAAC;AAEnB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACnC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IACnC,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CACrC,GAAG,iBAAiB,CAoBpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAsBhG"}
@@ -0,0 +1,95 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ /**
4
+ * Build a frozen `CompileDiagnostic` from a TypeScript node. Reads the node's
5
+ * starting position against the supplied source file, converts to 1-based
6
+ * line/column, and truncates the source snippet to a single line so terminal
7
+ * output stays compact.
8
+ *
9
+ * @since 0.1
10
+ * @example
11
+ * // Inside an analysis pass:
12
+ * // diagnostics.push(createDiagnostic({
13
+ * // severity: "error", code: "unbounded-loop",
14
+ * // message: "while loops are not allowed",
15
+ * // file: sourcePath, node, sourceFile,
16
+ * // }));
17
+ * const fake = { severity: "error" as const };
18
+ * void fake;
19
+ */
20
+ export function createDiagnostic(args) {
21
+ const { severity, code, message, file, node, sourceFile, includeSnippet } = args;
22
+ const start = node.getStart(sourceFile);
23
+ const { line, character } = sourceFile.getLineAndCharacterOfPosition(start);
24
+ const base = {
25
+ severity,
26
+ code,
27
+ message,
28
+ file,
29
+ line: line + 1,
30
+ column: character + 1,
31
+ };
32
+ if (includeSnippet) {
33
+ const text = node.getText(sourceFile);
34
+ const newlineIndex = text.indexOf("\n");
35
+ const firstLine = newlineIndex === -1 ? text : text.slice(0, newlineIndex);
36
+ const snippet = firstLine.length > 80 ? `${firstLine.slice(0, 77)}...` : firstLine;
37
+ return Object.freeze({ ...base, nodeText: snippet });
38
+ }
39
+ return Object.freeze(base);
40
+ }
41
+ /**
42
+ * Build a frozen `CompileDiagnostic` from a raw TypeScript `ts.Diagnostic`.
43
+ * Used by the `compile()` pipeline to surface semantic type-checker errors
44
+ * (TS2322, TS2345, …) under the `type-error` code. Carries the original
45
+ * `TS<code>` numeric prefix in the message so editor consumers can route
46
+ * to the TypeScript documentation if they want.
47
+ *
48
+ * Diagnostics without a `file` (global-scope, project-shape) are mapped to
49
+ * the script's `sourcePath` at line/column `1:1` so callers always get a
50
+ * stable location they can attribute to the user's source. The message is
51
+ * flattened across `DiagnosticMessageChain` nodes.
52
+ *
53
+ * @since 0.7
54
+ * @example
55
+ * // const compileDiagnostic = mapTsDiagnostic(tsDiagnostic, "demo.chart.ts");
56
+ * const fn: typeof mapTsDiagnostic = mapTsDiagnostic;
57
+ * void fn;
58
+ */
59
+ export function mapTsDiagnostic(diagnostic, sourcePath) {
60
+ const message = flattenDiagnosticMessage(diagnostic.messageText);
61
+ const file = diagnostic.file;
62
+ if (file === undefined || diagnostic.start === undefined) {
63
+ return Object.freeze({
64
+ severity: "error",
65
+ code: "type-error",
66
+ message: `TS${diagnostic.code}: ${message}`,
67
+ file: sourcePath,
68
+ line: 1,
69
+ column: 1,
70
+ });
71
+ }
72
+ const { line, character } = file.getLineAndCharacterOfPosition(diagnostic.start);
73
+ return Object.freeze({
74
+ severity: "error",
75
+ code: "type-error",
76
+ message: `TS${diagnostic.code}: ${message}`,
77
+ file: sourcePath,
78
+ line: line + 1,
79
+ column: character + 1,
80
+ });
81
+ }
82
+ function flattenDiagnosticMessage(message) {
83
+ if (typeof message === "string")
84
+ return message;
85
+ const parts = [message.messageText];
86
+ const next = message.next;
87
+ if (next === undefined)
88
+ return parts.join(" ");
89
+ const queue = next;
90
+ for (const chain of queue) {
91
+ parts.push(flattenDiagnosticMessage(chain));
92
+ }
93
+ return parts.join(" ");
94
+ }
95
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],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AAC;QACxB,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { CompileError, compile, compileFile, compileProject, transformAndAnalyse, walkChartFiles, writeAtomic, } from "./api.js";
2
+ export type { CompileFileOptions, CompileOptions, CompiledScript, TransformAndAnalyseOptions, TransformAndAnalyseResult, } from "./api.js";
3
+ export { bundleModule, formatManifestAssignment } from "./bundle.js";
4
+ export type { BundleModuleOptions, BundleModuleResult } from "./bundle.js";
5
+ export type { CompileDiagnostic, CompileDiagnosticCode } from "./diagnostics.js";
6
+ export { emitTypes } from "./typesEmit.js";
7
+ export type { EmitTypesOptions } from "./typesEmit.js";
8
+ export { resolveCalleeName } from "./transformers/resolveCallee.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,YAAY,EACZ,OAAO,EACP,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,WAAW,GACd,MAAM,UAAU,CAAC;AAClB,YAAY,EACR,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,GAC5B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACrE,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ export { CompileError, compile, compileFile, compileProject, transformAndAnalyse, walkChartFiles, writeAtomic, } from "./api.js";
4
+ export { bundleModule, formatManifestAssignment } from "./bundle.js";
5
+ export { emitTypes } from "./typesEmit.js";
6
+ export { resolveCalleeName } from "./transformers/resolveCallee.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EACH,YAAY,EACZ,OAAO,EACP,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,WAAW,GACd,MAAM,UAAU,CAAC;AAQlB,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAGrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { AlertConditionDefinition, CapabilityId, ScriptManifest } from "@invinite-org/chartlang-core";
2
+ type ValueFormat = "price" | "volume" | "percent" | "compact";
3
+ type ScaleAxis = "price" | "left" | "right" | "new";
4
+ type ManifestInputDescriptors = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
5
+ /**
6
+ * Build a recursively-frozen `ScriptManifest` from the compiler's
7
+ * extraction passes. Every array, every nested record, and the outer
8
+ * object itself are frozen so the runtime can structurally clone the
9
+ * manifest without worrying about post-build mutation.
10
+ *
11
+ * @since 0.1
12
+ * @example
13
+ * // const manifest = buildManifest({
14
+ * // name: "EMA(20)", kind: "indicator",
15
+ * // capabilities: ["alerts", "indicators"],
16
+ * // requestedIntervals: [], userPickableInterval: false,
17
+ * // seriesCapacities: {}, maxLookback: 0, inputs: {},
18
+ * // });
19
+ * const fn: typeof buildManifest = buildManifest;
20
+ * void fn;
21
+ */
22
+ export declare function buildManifest(args: {
23
+ readonly name: string;
24
+ readonly kind: "indicator" | "drawing" | "alert" | "alertCondition";
25
+ readonly capabilities: ReadonlyArray<CapabilityId>;
26
+ readonly requestedIntervals: ReadonlyArray<string>;
27
+ readonly userPickableInterval: boolean;
28
+ readonly seriesCapacities: Readonly<Record<string, number>>;
29
+ readonly maxLookback: number;
30
+ readonly inputs: ManifestInputDescriptors;
31
+ readonly maxBarsBack?: number;
32
+ readonly format?: ValueFormat;
33
+ readonly precision?: number;
34
+ readonly scale?: ScaleAxis;
35
+ readonly requiresIntervals?: ReadonlyArray<string>;
36
+ readonly shortName?: string;
37
+ readonly alertConditions?: ReadonlyArray<AlertConditionDefinition>;
38
+ }): ScriptManifest;
39
+ export {};
40
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACjB,MAAM,8BAA8B,CAAC;AAEtC,KAAK,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAC9D,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AACpD,KAAK,wBAAwB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5F;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,gBAAgB,CAAC;IACpE,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,kBAAkB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnD,QAAQ,CAAC,oBAAoB,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;CACtE,GAAG,cAAc,CA4CjB"}
@@ -0,0 +1,57 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ /**
4
+ * Build a recursively-frozen `ScriptManifest` from the compiler's
5
+ * extraction passes. Every array, every nested record, and the outer
6
+ * object itself are frozen so the runtime can structurally clone the
7
+ * manifest without worrying about post-build mutation.
8
+ *
9
+ * @since 0.1
10
+ * @example
11
+ * // const manifest = buildManifest({
12
+ * // name: "EMA(20)", kind: "indicator",
13
+ * // capabilities: ["alerts", "indicators"],
14
+ * // requestedIntervals: [], userPickableInterval: false,
15
+ * // seriesCapacities: {}, maxLookback: 0, inputs: {},
16
+ * // });
17
+ * const fn: typeof buildManifest = buildManifest;
18
+ * void fn;
19
+ */
20
+ export function buildManifest(args) {
21
+ const capabilities = Object.freeze(args.capabilities.slice());
22
+ const requestedIntervals = Object.freeze(args.requestedIntervals.slice());
23
+ const seriesCapacities = Object.freeze({ ...args.seriesCapacities });
24
+ const inputEntries = Object.entries(args.inputs).map(([key, value]) => [key, Object.freeze({ ...value })]);
25
+ const inputs = Object.freeze(Object.fromEntries(inputEntries));
26
+ const scriptInputs = inputs;
27
+ const requiresIntervals = args.requiresIntervals === undefined
28
+ ? undefined
29
+ : Object.freeze(args.requiresIntervals.slice());
30
+ const alertConditions = args.alertConditions === undefined
31
+ ? undefined
32
+ : Object.freeze(args.alertConditions.map((condition) => Object.freeze({
33
+ id: condition.id,
34
+ title: condition.title,
35
+ description: condition.description,
36
+ defaultMessage: condition.defaultMessage,
37
+ })));
38
+ return Object.freeze({
39
+ apiVersion: 1,
40
+ kind: args.kind,
41
+ name: args.name,
42
+ inputs: scriptInputs,
43
+ capabilities,
44
+ requestedIntervals,
45
+ userPickableInterval: args.userPickableInterval,
46
+ seriesCapacities,
47
+ maxLookback: args.maxLookback,
48
+ ...(args.maxBarsBack === undefined ? {} : { maxBarsBack: args.maxBarsBack }),
49
+ ...(args.format === undefined ? {} : { format: args.format }),
50
+ ...(args.precision === undefined ? {} : { precision: args.precision }),
51
+ ...(args.scale === undefined ? {} : { scale: args.scale }),
52
+ ...(requiresIntervals === undefined ? {} : { requiresIntervals }),
53
+ ...(args.shortName === undefined ? {} : { shortName: args.shortName }),
54
+ ...(alertConditions === undefined ? {} : { alertConditions }),
55
+ });
56
+ }
57
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAY/D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,aAAa,CAAC,IAgB7B;IACG,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAA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stable so the analysis passes can
5
+ * detect callee declarations coming from core (vs. user-shadowed names).
6
+ *
7
+ * @since 0.1
8
+ * @example
9
+ * import { CORE_MODULE_PATH } from "@invinite-org/chartlang-compiler/program";
10
+ * void CORE_MODULE_PATH;
11
+ */
12
+ export declare const CORE_MODULE_PATH = "/__chartlang__/core.d.ts";
13
+ /**
14
+ * The compiler options the compiler pins for every script. ES2022 target,
15
+ * Bundler module resolution, strict mode, no DOM. Scripts that depend on
16
+ * browser globals fail the `forbiddenConstructs` pass on the global access
17
+ * itself; the `lib` setting keeps the typechecker from accepting them in the
18
+ * first place.
19
+ *
20
+ * @since 0.1
21
+ * @example
22
+ * import { COMPILER_OPTIONS } from "@invinite-org/chartlang-compiler/program";
23
+ * void COMPILER_OPTIONS;
24
+ */
25
+ export declare const COMPILER_OPTIONS: ts.CompilerOptions;
26
+ /**
27
+ * The return shape of `createProgramForSource`. Callers use `sourceFile` for
28
+ * AST walks, `checker` for symbol resolution, and `program` as the root
29
+ * handle when they need diagnostics from `tsc` itself (not used in Phase 1,
30
+ * but kept on the type so Task 3 can plug in `program.getSemanticDiagnostics`
31
+ * without an API change).
32
+ *
33
+ * @since 0.1
34
+ * @example
35
+ * // const { sourceFile, checker } = createProgramForSource(src, opts);
36
+ * const shape: { sourceFile: unknown; checker: unknown; program: unknown } = {
37
+ * sourceFile: null,
38
+ * checker: null,
39
+ * program: null,
40
+ * };
41
+ * void shape;
42
+ */
43
+ export type ProgramForSource = Readonly<{
44
+ program: ts.Program;
45
+ sourceFile: ts.SourceFile;
46
+ checker: ts.TypeChecker;
47
+ }>;
48
+ /**
49
+ * Build a single-file TypeScript program for an in-memory `.chart.ts`
50
+ * source. The synthetic file lives at `sourcePath` (POSIX, as the user
51
+ * would write it); imports of `@invinite-org/chartlang-core` resolve
52
+ * against the in-memory ambient shim. Returns the source file and a
53
+ * configured type checker — the caller never sees the underlying compiler
54
+ * host plumbing.
55
+ *
56
+ * @since 0.1
57
+ * @example
58
+ * // const { sourceFile, checker } = createProgramForSource(
59
+ * // 'export default defineIndicator({ name: "x", apiVersion: 1, compute: () => {} });',
60
+ * // { sourcePath: "demo.chart.ts" },
61
+ * // );
62
+ * const fn: typeof createProgramForSource = createProgramForSource;
63
+ * void fn;
64
+ */
65
+ export declare function createProgramForSource(source: string, opts: {
66
+ readonly sourcePath: string;
67
+ }): ProgramForSource;
68
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,6BAA6B,CAAC;AAwxC3D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,eAYjC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC;IACpC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACpB,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IAC1B,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;CAC3B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACtC,gBAAgB,CAoDlB"}