@tinta-lang/engine 0.0.0-stage → 0.1.0-dev.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.
@@ -0,0 +1,3 @@
1
+ import type { Program } from "@tinta-lang/types";
2
+ import type { Bound } from "./binding.js";
3
+ export declare const programs: WeakMap<Program, Bound>;
@@ -0,0 +1 @@
1
+ export const programs = new WeakMap();
@@ -0,0 +1,144 @@
1
+ export declare const registry: {
2
+ readonly contractRevision: "1.0-draft.3";
3
+ readonly sourceVersion: "1.0";
4
+ readonly workingName: "Tinta";
5
+ readonly sourceExtension: ".tinta";
6
+ readonly bundleExtension: ".tinta.zip";
7
+ readonly profiles: readonly ["markdown", "tinta"];
8
+ readonly directives: readonly ["meta", "let", "calc", "slider", "toggle", "choice", "when", "details", "data", "view", "table", "chart"];
9
+ readonly blockDirectives: readonly ["when", "details", "data"];
10
+ readonly blockDelimiter: "end";
11
+ readonly functions: readonly ["if", "min", "max", "round", "pow", "count", "sum", "mean", "fixed", "percent", "money"];
12
+ readonly chartTypes: readonly ["line", "area", "bar", "scatter", "pie", "donut", "histogram"];
13
+ readonly reservedIdentifiers: readonly ["true", "false", "and", "or", "not", "row", "__proto__", "prototype", "constructor", "if", "min", "max", "round", "pow", "count", "sum", "mean", "fixed", "percent", "money"];
14
+ readonly locales: readonly ["en-US", "en-GB", "es-ES", "fr-FR", "de-DE", "ja-JP", "zh-CN", "zh-TW"];
15
+ readonly currencies: readonly ["USD", "EUR", "GBP", "JPY", "CHF", "CAD", "AUD", "CNY"];
16
+ readonly defaults: {
17
+ readonly locale: "en-US";
18
+ readonly currency: "USD";
19
+ readonly version: "1.0";
20
+ readonly sliderMin: 0;
21
+ readonly sliderMax: 100;
22
+ readonly sliderStep: 1;
23
+ readonly histogramBins: 8;
24
+ };
25
+ readonly limits: {
26
+ readonly sourceBytes: 2097152;
27
+ readonly sourceLineUnits: 65536;
28
+ readonly expressionUnits: 8192;
29
+ readonly expressionDepth: 32;
30
+ readonly astNodes: 100000;
31
+ readonly tintaBlockDepth: 16;
32
+ readonly markdownDepth: 64;
33
+ readonly declarations: 512;
34
+ readonly controls: 128;
35
+ readonly identifierUnits: 64;
36
+ readonly textValueUnits: 65536;
37
+ readonly literalListItems: 1000;
38
+ readonly tableCount: 64;
39
+ readonly tableRows: 10000;
40
+ readonly tableColumns: 64;
41
+ readonly totalCells: 100000;
42
+ readonly chartRows: 2000;
43
+ readonly chartCategories: 200;
44
+ readonly chartSectors: 24;
45
+ readonly chartSeries: 6;
46
+ readonly chartMarks: 12000;
47
+ readonly documentChartMarks: 32000;
48
+ readonly chartCount: 32;
49
+ readonly histogramBinsMin: 2;
50
+ readonly histogramBinsMax: 30;
51
+ readonly histogramBinsDefault: 8;
52
+ readonly choiceOptions: 50;
53
+ readonly choiceOptionCodePoints: 120;
54
+ readonly labelCodePoints: 200;
55
+ readonly sliderTicks: 100000;
56
+ readonly sliderFractionalDigits: 6;
57
+ readonly sliderMagnitude: 1000000000;
58
+ readonly evaluationOperations: 2000000;
59
+ readonly compileOperations: 5000000;
60
+ readonly diagnostics: 100;
61
+ readonly importBytes: 5242880;
62
+ readonly assetCount: 100;
63
+ readonly assetBytes: 10485760;
64
+ readonly totalAssetBytes: 26214400;
65
+ readonly imagePixels: 20000000;
66
+ readonly bundleCompressedBytes: 31457280;
67
+ readonly bundleExpandedBytes: 31457280;
68
+ readonly bundleEntries: 102;
69
+ readonly htmlBytes: 41943040;
70
+ readonly workerWatchdogMs: 3000;
71
+ readonly editorDebounceMs: 200;
72
+ readonly recoveryDebounceMs: 1000;
73
+ readonly recoveryEntries: 10;
74
+ readonly recoveryTotalBytes: 31457280;
75
+ };
76
+ readonly errors: {
77
+ readonly E_ENCODING: "Invalid UTF-8 source or import encoding.";
78
+ readonly E_LIMIT: "A named resource limit was exceeded.";
79
+ readonly E_DIRECTIVE_UNKNOWN: "Unregistered column-1 directive.";
80
+ readonly E_DIRECTIVE_SYNTAX: "Malformed directive operands/options.";
81
+ readonly E_BLOCK_END: "Unexpected closing @end.";
82
+ readonly E_BLOCK_UNCLOSED: "Tinta block has no closing @end.";
83
+ readonly E_BLOCK_EMPTY: "Conditional/detail block contains no renderable content.";
84
+ readonly E_DECLARATION_SCOPE: "Root-only declaration used in a nested block.";
85
+ readonly E_PROPERTY_UNKNOWN: "Unsupported option key.";
86
+ readonly E_PROPERTY_DUPLICATE: "Option key repeated.";
87
+ readonly E_PROPERTY_REQUIRED: "Required option missing.";
88
+ readonly E_PROPERTY_DEPENDENCY: "Option depends on another missing option.";
89
+ readonly E_PROPERTY_VALUE: "Option has an invalid literal value.";
90
+ readonly E_VERSION: "Unsupported source format version.";
91
+ readonly E_META_POSITION: "Repeated or misplaced metadata.";
92
+ readonly E_META_VALUE: "Unsupported metadata setting.";
93
+ readonly E_EXPRESSION_SYNTAX: "Invalid/unfinished expression token sequence.";
94
+ readonly E_NAME_RESERVED: "Reserved or invalid identifier.";
95
+ readonly E_NAME_DUPLICATE: "Document name declared more than once.";
96
+ readonly E_NAME_UNKNOWN: "Unresolved global name.";
97
+ readonly E_ROW_SCOPE: "row.field used outside a supported row context.";
98
+ readonly E_COLUMN_UNKNOWN: "Referenced table column does not exist.";
99
+ readonly E_TYPE: "Types do not satisfy an operator/directive/function contract.";
100
+ readonly E_FUNCTION_ARITY: "Incorrect number of function arguments.";
101
+ readonly E_CONST_DEPENDENCY: "Constant depends on nonconstant state/data.";
102
+ readonly E_CYCLE: "Dependency cycle detected.";
103
+ readonly E_NUMBER_RANGE: "Numeric operation produced a non-finite/non-real result.";
104
+ readonly E_DIV_ZERO: "Division or remainder by zero.";
105
+ readonly E_DIGITS_RANGE: "Formatting/rounding digits are outside integer 0–10.";
106
+ readonly E_EMPTY_MEAN: "Mean requested for an empty table/view.";
107
+ readonly E_STATE_NAME: "Update names an unknown/non-control symbol.";
108
+ readonly E_STATE_DOMAIN: "Control update/default violates its allowed domain.";
109
+ readonly E_DATA_HEADER: "Invalid or duplicate typed table header.";
110
+ readonly E_DATA_ARITY: "Row cell count differs from the schema.";
111
+ readonly E_DATA_VALUE: "Cell is not a valid scalar for its declared type.";
112
+ readonly E_CHART_TYPE: "Unknown chart type.";
113
+ readonly E_CHART_SERIES: "Invalid series count/form for chart type.";
114
+ readonly E_CHART_DUPLICATE_X: "Chart requires unique x values.";
115
+ readonly E_CHART_VALUE: "Invalid chart datum, e.g. negative sector value.";
116
+ readonly E_CHART_DOMAIN: "Finite chart geometry cannot be constructed.";
117
+ readonly E_SELECTION_TARGET: "Invalid linked-control type/name.";
118
+ readonly E_SELECTION_DOMAIN: "Chart x cannot be represented by the linked control.";
119
+ readonly E_IMPORT_SCHEMA: "Unsupported import structure or conversion.";
120
+ readonly E_IMPORT_PRESERVATION: "Markdown enrichment changed unintended semantics.";
121
+ readonly E_ASSET_MISSING: "Referenced local image was not supplied.";
122
+ readonly E_ASSET_EXTERNAL: "Remote/nonlocal image is not permitted.";
123
+ readonly E_ASSET_TYPE: "Unsupported/mismatched raster image format.";
124
+ readonly E_ASSET_PATH: "Unsafe resource or ZIP entry path.";
125
+ readonly E_BUNDLE: "Malformed bundle, duplicate keys/entries, CRC or manifest mismatch.";
126
+ readonly E_HASH_MISMATCH: "Source/resource hash does not match its envelope.";
127
+ readonly E_SNAPSHOT: "State envelope does not match source/schema/controls.";
128
+ readonly E_EXPORT_INVALID: "Export requested for invalid/stale source or an invalid state.";
129
+ readonly E_OUTPUT_EXISTS: "Output already exists and replacement is not authorized.";
130
+ readonly E_IO: "Authorized filesystem operation failed.";
131
+ readonly E_WORKER_TIMEOUT: "Worker did not complete before the watchdog.";
132
+ readonly E_PROTOCOL: "Malformed or unauthorized host protocol message; stale valid results are ignored.";
133
+ readonly E_INTERNAL: "Unexpected engine fault; not a document syntax diagnosis.";
134
+ };
135
+ readonly warnings: {
136
+ readonly W_NUL_REPLACED: "NUL displayed as the replacement character.";
137
+ readonly W_HTML_INERT: "Raw author HTML displayed as text.";
138
+ readonly W_LINK_LOCAL_UNSUPPORTED: "Local document navigation is not implemented.";
139
+ readonly W_LINK_UNSAFE: "Unsafe/unsupported link disabled.";
140
+ readonly W_ASSET_UNAVAILABLE: "Preview image unavailable; export remains blocked.";
141
+ readonly W_RECOVERY_UNAVAILABLE: "Local browser recovery is unavailable.";
142
+ readonly W_MARKDOWN_COLLISION: "Enrichment proposes escapes for Tinta-looking literal text.";
143
+ };
144
+ };
@@ -0,0 +1,200 @@
1
+ // Generated from spec/registry.json; verified against the normative registry.
2
+ export const registry = {
3
+ contractRevision: "1.0-draft.3",
4
+ sourceVersion: "1.0",
5
+ workingName: "Tinta",
6
+ sourceExtension: ".tinta",
7
+ bundleExtension: ".tinta.zip",
8
+ profiles: ["markdown", "tinta"],
9
+ directives: [
10
+ "meta",
11
+ "let",
12
+ "calc",
13
+ "slider",
14
+ "toggle",
15
+ "choice",
16
+ "when",
17
+ "details",
18
+ "data",
19
+ "view",
20
+ "table",
21
+ "chart",
22
+ ],
23
+ blockDirectives: ["when", "details", "data"],
24
+ blockDelimiter: "end",
25
+ functions: [
26
+ "if",
27
+ "min",
28
+ "max",
29
+ "round",
30
+ "pow",
31
+ "count",
32
+ "sum",
33
+ "mean",
34
+ "fixed",
35
+ "percent",
36
+ "money",
37
+ ],
38
+ chartTypes: ["line", "area", "bar", "scatter", "pie", "donut", "histogram"],
39
+ reservedIdentifiers: [
40
+ "true",
41
+ "false",
42
+ "and",
43
+ "or",
44
+ "not",
45
+ "row",
46
+ "__proto__",
47
+ "prototype",
48
+ "constructor",
49
+ "if",
50
+ "min",
51
+ "max",
52
+ "round",
53
+ "pow",
54
+ "count",
55
+ "sum",
56
+ "mean",
57
+ "fixed",
58
+ "percent",
59
+ "money",
60
+ ],
61
+ locales: [
62
+ "en-US",
63
+ "en-GB",
64
+ "es-ES",
65
+ "fr-FR",
66
+ "de-DE",
67
+ "ja-JP",
68
+ "zh-CN",
69
+ "zh-TW",
70
+ ],
71
+ currencies: ["USD", "EUR", "GBP", "JPY", "CHF", "CAD", "AUD", "CNY"],
72
+ defaults: {
73
+ locale: "en-US",
74
+ currency: "USD",
75
+ version: "1.0",
76
+ sliderMin: 0,
77
+ sliderMax: 100,
78
+ sliderStep: 1,
79
+ histogramBins: 8,
80
+ },
81
+ limits: {
82
+ sourceBytes: 2097152,
83
+ sourceLineUnits: 65536,
84
+ expressionUnits: 8192,
85
+ expressionDepth: 32,
86
+ astNodes: 100000,
87
+ tintaBlockDepth: 16,
88
+ markdownDepth: 64,
89
+ declarations: 512,
90
+ controls: 128,
91
+ identifierUnits: 64,
92
+ textValueUnits: 65536,
93
+ literalListItems: 1000,
94
+ tableCount: 64,
95
+ tableRows: 10000,
96
+ tableColumns: 64,
97
+ totalCells: 100000,
98
+ chartRows: 2000,
99
+ chartCategories: 200,
100
+ chartSectors: 24,
101
+ chartSeries: 6,
102
+ chartMarks: 12000,
103
+ documentChartMarks: 32000,
104
+ chartCount: 32,
105
+ histogramBinsMin: 2,
106
+ histogramBinsMax: 30,
107
+ histogramBinsDefault: 8,
108
+ choiceOptions: 50,
109
+ choiceOptionCodePoints: 120,
110
+ labelCodePoints: 200,
111
+ sliderTicks: 100000,
112
+ sliderFractionalDigits: 6,
113
+ sliderMagnitude: 1000000000,
114
+ evaluationOperations: 2000000,
115
+ compileOperations: 5000000,
116
+ diagnostics: 100,
117
+ importBytes: 5242880,
118
+ assetCount: 100,
119
+ assetBytes: 10485760,
120
+ totalAssetBytes: 26214400,
121
+ imagePixels: 20000000,
122
+ bundleCompressedBytes: 31457280,
123
+ bundleExpandedBytes: 31457280,
124
+ bundleEntries: 102,
125
+ htmlBytes: 41943040,
126
+ workerWatchdogMs: 3000,
127
+ editorDebounceMs: 200,
128
+ recoveryDebounceMs: 1000,
129
+ recoveryEntries: 10,
130
+ recoveryTotalBytes: 31457280,
131
+ },
132
+ errors: {
133
+ E_ENCODING: "Invalid UTF-8 source or import encoding.",
134
+ E_LIMIT: "A named resource limit was exceeded.",
135
+ E_DIRECTIVE_UNKNOWN: "Unregistered column-1 directive.",
136
+ E_DIRECTIVE_SYNTAX: "Malformed directive operands/options.",
137
+ E_BLOCK_END: "Unexpected closing @end.",
138
+ E_BLOCK_UNCLOSED: "Tinta block has no closing @end.",
139
+ E_BLOCK_EMPTY: "Conditional/detail block contains no renderable content.",
140
+ E_DECLARATION_SCOPE: "Root-only declaration used in a nested block.",
141
+ E_PROPERTY_UNKNOWN: "Unsupported option key.",
142
+ E_PROPERTY_DUPLICATE: "Option key repeated.",
143
+ E_PROPERTY_REQUIRED: "Required option missing.",
144
+ E_PROPERTY_DEPENDENCY: "Option depends on another missing option.",
145
+ E_PROPERTY_VALUE: "Option has an invalid literal value.",
146
+ E_VERSION: "Unsupported source format version.",
147
+ E_META_POSITION: "Repeated or misplaced metadata.",
148
+ E_META_VALUE: "Unsupported metadata setting.",
149
+ E_EXPRESSION_SYNTAX: "Invalid/unfinished expression token sequence.",
150
+ E_NAME_RESERVED: "Reserved or invalid identifier.",
151
+ E_NAME_DUPLICATE: "Document name declared more than once.",
152
+ E_NAME_UNKNOWN: "Unresolved global name.",
153
+ E_ROW_SCOPE: "row.field used outside a supported row context.",
154
+ E_COLUMN_UNKNOWN: "Referenced table column does not exist.",
155
+ E_TYPE: "Types do not satisfy an operator/directive/function contract.",
156
+ E_FUNCTION_ARITY: "Incorrect number of function arguments.",
157
+ E_CONST_DEPENDENCY: "Constant depends on nonconstant state/data.",
158
+ E_CYCLE: "Dependency cycle detected.",
159
+ E_NUMBER_RANGE: "Numeric operation produced a non-finite/non-real result.",
160
+ E_DIV_ZERO: "Division or remainder by zero.",
161
+ E_DIGITS_RANGE: "Formatting/rounding digits are outside integer 0\u201310.",
162
+ E_EMPTY_MEAN: "Mean requested for an empty table/view.",
163
+ E_STATE_NAME: "Update names an unknown/non-control symbol.",
164
+ E_STATE_DOMAIN: "Control update/default violates its allowed domain.",
165
+ E_DATA_HEADER: "Invalid or duplicate typed table header.",
166
+ E_DATA_ARITY: "Row cell count differs from the schema.",
167
+ E_DATA_VALUE: "Cell is not a valid scalar for its declared type.",
168
+ E_CHART_TYPE: "Unknown chart type.",
169
+ E_CHART_SERIES: "Invalid series count/form for chart type.",
170
+ E_CHART_DUPLICATE_X: "Chart requires unique x values.",
171
+ E_CHART_VALUE: "Invalid chart datum, e.g. negative sector value.",
172
+ E_CHART_DOMAIN: "Finite chart geometry cannot be constructed.",
173
+ E_SELECTION_TARGET: "Invalid linked-control type/name.",
174
+ E_SELECTION_DOMAIN: "Chart x cannot be represented by the linked control.",
175
+ E_IMPORT_SCHEMA: "Unsupported import structure or conversion.",
176
+ E_IMPORT_PRESERVATION: "Markdown enrichment changed unintended semantics.",
177
+ E_ASSET_MISSING: "Referenced local image was not supplied.",
178
+ E_ASSET_EXTERNAL: "Remote/nonlocal image is not permitted.",
179
+ E_ASSET_TYPE: "Unsupported/mismatched raster image format.",
180
+ E_ASSET_PATH: "Unsafe resource or ZIP entry path.",
181
+ E_BUNDLE: "Malformed bundle, duplicate keys/entries, CRC or manifest mismatch.",
182
+ E_HASH_MISMATCH: "Source/resource hash does not match its envelope.",
183
+ E_SNAPSHOT: "State envelope does not match source/schema/controls.",
184
+ E_EXPORT_INVALID: "Export requested for invalid/stale source or an invalid state.",
185
+ E_OUTPUT_EXISTS: "Output already exists and replacement is not authorized.",
186
+ E_IO: "Authorized filesystem operation failed.",
187
+ E_WORKER_TIMEOUT: "Worker did not complete before the watchdog.",
188
+ E_PROTOCOL: "Malformed or unauthorized host protocol message; stale valid results are ignored.",
189
+ E_INTERNAL: "Unexpected engine fault; not a document syntax diagnosis.",
190
+ },
191
+ warnings: {
192
+ W_NUL_REPLACED: "NUL displayed as the replacement character.",
193
+ W_HTML_INERT: "Raw author HTML displayed as text.",
194
+ W_LINK_LOCAL_UNSUPPORTED: "Local document navigation is not implemented.",
195
+ W_LINK_UNSAFE: "Unsafe/unsupported link disabled.",
196
+ W_ASSET_UNAVAILABLE: "Preview image unavailable; export remains blocked.",
197
+ W_RECOVERY_UNAVAILABLE: "Local browser recovery is unavailable.",
198
+ W_MARKDOWN_COLLISION: "Enrichment proposes escapes for Tinta-looking literal text.",
199
+ },
200
+ };
@@ -0,0 +1,4 @@
1
+ import type { Program, Result } from "@tinta-lang/types";
2
+ export { createSession } from "./session.js";
3
+ /** Rehydrate exact export-time validated bytes, authenticated by the trusted shell. */
4
+ export declare function restoreExportProgram(payload: unknown, expectedHash: string): Result<Program>;
@@ -0,0 +1,32 @@
1
+ import { hash, encodeUtf8 } from "@tinta-lang/types/common";
2
+ import { attempt, Budget, fail, freeze } from "./common.js";
3
+ import { bind } from "./binding.js";
4
+ import { programs } from "./programs.js";
5
+ import { inspect } from "./inspect.js";
6
+ import validate from "./program-validator.js";
7
+ export { createSession } from "./session.js";
8
+ /** Rehydrate exact export-time validated bytes, authenticated by the trusted shell. */
9
+ export function restoreExportProgram(payload, expectedHash) {
10
+ const span = {
11
+ uri: "tinta:program",
12
+ start: { offset: 0, line: 1, column: 1 },
13
+ end: { offset: 0, line: 1, column: 1 },
14
+ };
15
+ return attempt(() => {
16
+ const budget = new Budget(span, "decode");
17
+ const serialized = JSON.stringify(payload);
18
+ if (serialized.length > 41943040 ||
19
+ hash(encodeUtf8(serialized)) !== expectedHash)
20
+ fail("E_HASH_MISMATCH", span, "decode");
21
+ inspect(payload, budget);
22
+ if (!validate(payload))
23
+ fail("E_PROTOCOL", span, "decode");
24
+ const ir = payload;
25
+ if (hash(encodeUtf8(ir.source)) !== ir.sourceSha256)
26
+ fail("E_HASH_MISMATCH", span, "decode");
27
+ const bound = bind(ir, budget, new Map());
28
+ const program = freeze(ir);
29
+ programs.set(program, bound);
30
+ return program;
31
+ });
32
+ }
@@ -0,0 +1,4 @@
1
+ import type { ControlState, Program, Result, Session } from "@tinta-lang/types";
2
+ export declare function createSession(program: Program, options?: {
3
+ readonly baseline?: ControlState;
4
+ }): Result<Session>;