@hyperscale0/hsx 1.0.0-beta.1 → 1.0.0-rc.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.
- package/CHANGELOG.md +41 -9
- package/LICENSING.md +3 -3
- package/README.md +37 -149
- package/TRADEMARKS.md +4 -4
- package/dist/src/ast.d.ts +129 -10
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +148 -12
- package/dist/src/cli.js.map +1 -1
- package/dist/src/compile.d.ts +41 -4
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +82 -15
- package/dist/src/compile.js.map +1 -1
- package/dist/src/cost.d.ts +78 -0
- package/dist/src/cost.d.ts.map +1 -0
- package/dist/src/cost.js +369 -0
- package/dist/src/cost.js.map +1 -0
- package/dist/src/diagnostics.d.ts +11 -0
- package/dist/src/diagnostics.d.ts.map +1 -0
- package/dist/src/diagnostics.js +420 -0
- package/dist/src/diagnostics.js.map +1 -0
- package/dist/src/emit.d.ts +35 -0
- package/dist/src/emit.d.ts.map +1 -0
- package/dist/src/emit.js +359 -0
- package/dist/src/emit.js.map +1 -0
- package/dist/src/entry-overrides.d.ts +17 -3
- package/dist/src/entry-overrides.d.ts.map +1 -1
- package/dist/src/entry-overrides.js +180 -35
- package/dist/src/entry-overrides.js.map +1 -1
- package/dist/src/format.d.ts +10 -0
- package/dist/src/format.d.ts.map +1 -0
- package/dist/src/format.js +183 -0
- package/dist/src/format.js.map +1 -0
- package/dist/src/index.d.ts +10 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/ir.d.ts +66 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +15 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/lex.d.ts +9 -1
- package/dist/src/lex.d.ts.map +1 -1
- package/dist/src/lex.js +50 -4
- package/dist/src/lex.js.map +1 -1
- package/dist/src/limits.d.ts +2 -3
- package/dist/src/limits.d.ts.map +1 -1
- package/dist/src/limits.js +2 -3
- package/dist/src/limits.js.map +1 -1
- package/dist/src/modules.d.ts +36 -0
- package/dist/src/modules.d.ts.map +1 -0
- package/dist/src/modules.js +372 -0
- package/dist/src/modules.js.map +1 -0
- package/dist/src/parse.d.ts.map +1 -1
- package/dist/src/parse.js +590 -17
- package/dist/src/parse.js.map +1 -1
- package/dist/src/typecheck.d.ts +8 -0
- package/dist/src/typecheck.d.ts.map +1 -0
- package/dist/src/typecheck.js +2958 -0
- package/dist/src/typecheck.js.map +1 -0
- package/dist/src/version.d.ts +4 -15
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +4 -15
- package/dist/src/version.js.map +1 -1
- package/docs/README.md +23 -0
- package/docs/guide/01-first-program.md +24 -0
- package/docs/guide/02-money.md +25 -0
- package/docs/guide/03-instruments.md +22 -0
- package/docs/guide/04-lifecycles.md +25 -0
- package/docs/guide/05-fees-and-splits.md +45 -0
- package/docs/guide/06-schedules.md +22 -0
- package/docs/guide/07-composition.md +46 -0
- package/docs/guide/08-writing-a-module.md +26 -0
- package/docs/guide/09-cost.md +24 -0
- package/docs/guide/10-diagnostics.md +27 -0
- package/docs/llms-full.txt +1738 -0
- package/docs/llms.txt +45 -0
- package/docs/reference/cli.md +33 -0
- package/docs/reference/diagnostics.md +619 -0
- package/docs/reference/grammar.md +39 -0
- package/docs/reference/std/advance.md +35 -0
- package/docs/reference/std/cancellable_booking.md +35 -0
- package/docs/reference/std/captured_payment.md +43 -0
- package/docs/reference/std/conditional_disbursement.md +33 -0
- package/docs/reference/std/credit_facility.md +35 -0
- package/docs/reference/std/held_payment.md +64 -0
- package/docs/reference/std/instant_transfer.md +30 -0
- package/docs/reference/std/metered.md +27 -0
- package/docs/reference/std/pooled_split.md +26 -0
- package/docs/reference/std/premium_forward.md +39 -0
- package/docs/reference/std/reconciled_payout.md +33 -0
- package/docs/reference/std/recurring_collection.md +25 -0
- package/docs/reference/std/rotating_pool.md +42 -0
- package/docs/reference/std/scheduled.md +51 -0
- package/docs/reference/std/security_deposit.md +46 -0
- package/docs/reference/std/settlement_batch.md +42 -0
- package/docs/reference/std/swap.md +46 -0
- package/docs/reference/std/threshold_pool.md +47 -0
- package/docs/reference/std/weighted_distribution.md +39 -0
- package/docs/reference/types.md +20 -0
- package/docs/reference/udl-output.md +14 -0
- package/docs/sessions/2026-09-02-two-instruments.hsx +21 -0
- package/docs/sessions/2026-09-02-two-instruments.md +41 -0
- package/examples/01-first-program/README.md +45 -0
- package/examples/01-first-program/tip-jar.hsx +17 -0
- package/examples/02-imports-and-archetypes/README.md +99 -0
- package/examples/02-imports-and-archetypes/photo-booth.hsx +37 -0
- package/examples/03-diagnostics/README.md +68 -0
- package/examples/03-diagnostics/corner-shop-fixed.hsx +22 -0
- package/examples/03-diagnostics/corner-shop.hsx +19 -0
- package/examples/04-complete-product/README.md +87 -0
- package/examples/04-complete-product/study-hall.hsx +67 -0
- package/examples/05-watch-club/README.md +9 -0
- package/examples/05-watch-club/watch-club.hsx +124 -0
- package/examples/README.md +18 -0
- package/examples/advance/README.md +3 -0
- package/examples/advance/advance.hsx +13 -0
- package/examples/advance/advance.udl +339 -0
- package/examples/cancellable_booking/README.md +3 -0
- package/examples/cancellable_booking/cancellable_booking.hsx +14 -0
- package/examples/cancellable_booking/cancellable_booking.udl +391 -0
- package/examples/captured_payment/README.md +3 -0
- package/examples/captured_payment/captured_payment.hsx +21 -0
- package/examples/captured_payment/captured_payment.udl +677 -0
- package/examples/conditional_disbursement/README.md +3 -0
- package/examples/conditional_disbursement/conditional_disbursement.hsx +17 -0
- package/examples/conditional_disbursement/conditional_disbursement.udl +412 -0
- package/examples/cost-table.json +386 -0
- package/examples/credit_facility/README.md +3 -0
- package/examples/credit_facility/credit_facility.hsx +27 -0
- package/examples/credit_facility/credit_facility.udl +1373 -0
- package/examples/held_payment/README.md +3 -0
- package/examples/held_payment/held_payment.hsx +13 -0
- package/examples/held_payment/held_payment.udl +507 -0
- package/examples/instant_transfer/README.md +3 -0
- package/examples/instant_transfer/instant_transfer.hsx +16 -0
- package/examples/instant_transfer/instant_transfer.udl +364 -0
- package/examples/metered/README.md +3 -0
- package/examples/metered/metered.hsx +13 -0
- package/examples/metered/metered.udl +247 -0
- package/examples/pooled_split/README.md +3 -0
- package/examples/pooled_split/pooled_split.hsx +15 -0
- package/examples/pooled_split/pooled_split.udl +425 -0
- package/examples/premium_forward/README.md +3 -0
- package/examples/premium_forward/premium_forward.hsx +19 -0
- package/examples/premium_forward/premium_forward.udl +594 -0
- package/examples/reconciled_payout/README.md +3 -0
- package/examples/reconciled_payout/reconciled_payout.hsx +13 -0
- package/examples/reconciled_payout/reconciled_payout.udl +303 -0
- package/examples/recurring_collection/README.md +3 -0
- package/examples/recurring_collection/recurring_collection.hsx +21 -0
- package/examples/recurring_collection/recurring_collection.udl +1130 -0
- package/examples/rotating_pool/README.md +3 -0
- package/examples/rotating_pool/rotating_pool.hsx +18 -0
- package/examples/rotating_pool/rotating_pool.udl +4352 -0
- package/examples/scheduled/README.md +3 -0
- package/examples/scheduled/scheduled.hsx +12 -0
- package/examples/scheduled/scheduled.udl +335 -0
- package/examples/security_deposit/README.md +3 -0
- package/examples/security_deposit/security_deposit.hsx +21 -0
- package/examples/security_deposit/security_deposit.udl +293 -0
- package/examples/settlement_batch/README.md +3 -0
- package/examples/settlement_batch/settlement_batch.hsx +19 -0
- package/examples/settlement_batch/settlement_batch.udl +753 -0
- package/examples/swap/README.md +3 -0
- package/examples/swap/swap.hsx +19 -0
- package/examples/swap/swap.udl +876 -0
- package/examples/threshold_pool/README.md +3 -0
- package/examples/threshold_pool/threshold_pool.hsx +16 -0
- package/examples/threshold_pool/threshold_pool.udl +667 -0
- package/examples/weighted_distribution/README.md +3 -0
- package/examples/weighted_distribution/weighted_distribution.hsx +20 -0
- package/examples/weighted_distribution/weighted_distribution.udl +337 -0
- package/package.json +19 -6
- package/skills/hsx/SKILL.md +483 -0
- package/src/ast.ts +163 -9
- package/src/cli.ts +164 -12
- package/src/compile.ts +160 -20
- package/src/cost.ts +579 -0
- package/src/diagnostics.ts +442 -0
- package/src/emit.ts +447 -0
- package/src/entry-overrides.ts +263 -48
- package/src/format.ts +261 -0
- package/src/index.ts +32 -4
- package/src/ir.ts +99 -0
- package/src/lex.ts +59 -4
- package/src/limits.ts +2 -3
- package/src/modules.ts +444 -0
- package/src/parse.ts +655 -21
- package/src/typecheck.ts +3876 -0
- package/src/version.ts +4 -16
- package/std/SEMANTICS.md +130 -0
- package/std/settlements/advance.hsx +177 -0
- package/std/settlements/cancellable_booking.hsx +87 -0
- package/std/settlements/captured_payment.hsx +144 -0
- package/std/settlements/conditional_disbursement.hsx +185 -0
- package/std/settlements/credit_facility.hsx +167 -0
- package/std/settlements/held_payment.hsx +578 -0
- package/std/settlements/index.hsx +3 -0
- package/std/settlements/instant_transfer.hsx +190 -0
- package/std/settlements/metered.hsx +67 -0
- package/std/settlements/pooled_split.hsx +68 -0
- package/std/settlements/premium_forward.hsx +257 -0
- package/std/settlements/reconciled_payout.hsx +77 -0
- package/std/settlements/recurring_collection.hsx +27 -0
- package/std/settlements/rotating_pool.hsx +252 -0
- package/std/settlements/scheduled.hsx +641 -0
- package/std/settlements/security_deposit.hsx +166 -0
- package/std/settlements/settlement_batch.hsx +122 -0
- package/std/settlements/swap.hsx +1114 -0
- package/std/settlements/threshold_pool.hsx +221 -0
- package/std/settlements/weighted_distribution.hsx +141 -0
- package/dist/src/archetypes.d.ts +0 -17
- package/dist/src/archetypes.d.ts.map +0 -1
- package/dist/src/archetypes.js +0 -327
- package/dist/src/archetypes.js.map +0 -1
- package/dist/src/check.d.ts +0 -12
- package/dist/src/check.d.ts.map +0 -1
- package/dist/src/check.js +0 -1910
- package/dist/src/check.js.map +0 -1
- package/dist/src/lower.d.ts +0 -146
- package/dist/src/lower.d.ts.map +0 -1
- package/dist/src/lower.js +0 -4570
- package/dist/src/lower.js.map +0 -1
- package/dist/src/model.d.ts +0 -467
- package/dist/src/model.d.ts.map +0 -1
- package/dist/src/model.js +0 -15
- package/dist/src/model.js.map +0 -1
- package/spec/hsx-ir.schema.json +0 -920
- package/src/archetypes.ts +0 -340
- package/src/check.ts +0 -2938
- package/src/lower.ts +0 -5416
- package/src/model.ts +0 -519
package/dist/src/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `hsx` command line
|
|
2
|
+
* The `hsx` command line over the one compiler entry point and catalog.
|
|
3
3
|
*
|
|
4
4
|
* `check` prints diagnostics and says nothing else; `build` writes the
|
|
5
5
|
* compiled artifacts as JSON. Neither reads the environment, neither touches
|
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
* spec drives the real code paths with an in-memory filesystem instead of
|
|
10
10
|
* asserting on a subprocess's scrollback.
|
|
11
11
|
*/
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
12
13
|
import { compile } from "./compile.js";
|
|
13
|
-
import {
|
|
14
|
+
import { hsxDiagnostics } from "./diagnostics.js";
|
|
15
|
+
import { format } from "./format.js";
|
|
16
|
+
import { HSX_TARGET_UDL_VERSION, HSX_VERSION } from "./version.js";
|
|
14
17
|
/**
|
|
15
18
|
* Exit codes. `warning` exits 0 because a lint note is not a failure; pass
|
|
16
19
|
* `--strict` to make it one.
|
|
@@ -18,20 +21,27 @@ import { HSX_IR_VERSION, HSX_VERSION } from "./version.js";
|
|
|
18
21
|
const OK = 0;
|
|
19
22
|
const REFUSED = 1;
|
|
20
23
|
const USAGE = 2;
|
|
21
|
-
const USAGE_TEXT = `hsx ${HSX_VERSION}, the HSX compiler
|
|
24
|
+
export const USAGE_TEXT = `hsx ${HSX_VERSION}, the HSX compiler
|
|
22
25
|
|
|
23
26
|
Usage:
|
|
24
27
|
hsx check <file.hsx> [--strict]
|
|
25
28
|
hsx build <file.hsx> [--out <file.json>] [--strict]
|
|
29
|
+
hsx cost <file.hsx> [--json] [--out <file.json>] [--strict]
|
|
30
|
+
hsx explain <HSX####>
|
|
31
|
+
hsx format <file.hsx>
|
|
26
32
|
hsx --version
|
|
27
33
|
hsx --help
|
|
28
34
|
|
|
29
35
|
Commands:
|
|
30
36
|
check Compile and report diagnostics. Prints nothing when the program is clean.
|
|
31
|
-
build Compile and write
|
|
37
|
+
build Compile and write canonical UDL and its Business Frame as JSON.
|
|
38
|
+
cost Compile and print the version-pinned cost manifest as a table or JSON.
|
|
39
|
+
explain Print one diagnostic title, fix, and source example.
|
|
40
|
+
format Print the source in the one canonical HSX style.
|
|
32
41
|
|
|
33
42
|
Options:
|
|
34
|
-
--
|
|
43
|
+
--json Print the cost manifest as JSON instead of a table.
|
|
44
|
+
--out <file> Write build or cost JSON to this path instead of stdout.
|
|
35
45
|
--strict Treat warning-severity diagnostics as failures.
|
|
36
46
|
|
|
37
47
|
Exit codes:
|
|
@@ -45,10 +55,15 @@ export async function runCli(argv, io) {
|
|
|
45
55
|
return command === undefined ? USAGE : OK;
|
|
46
56
|
}
|
|
47
57
|
if (command === "--version" || command === "-v") {
|
|
48
|
-
io.out(`${HSX_VERSION} (
|
|
58
|
+
io.out(`${HSX_VERSION} (UDL version ${HSX_TARGET_UDL_VERSION})`);
|
|
49
59
|
return OK;
|
|
50
60
|
}
|
|
51
|
-
if (command
|
|
61
|
+
if (command === "explain")
|
|
62
|
+
return explainDiagnostic(rest, io);
|
|
63
|
+
if (command !== "check" &&
|
|
64
|
+
command !== "build" &&
|
|
65
|
+
command !== "cost" &&
|
|
66
|
+
command !== "format") {
|
|
52
67
|
io.err(`hsx: unknown command "${command}"`);
|
|
53
68
|
io.err(USAGE_TEXT);
|
|
54
69
|
return USAGE;
|
|
@@ -66,7 +81,26 @@ export async function runCli(argv, io) {
|
|
|
66
81
|
io.err(`hsx: cannot read ${parsed.file}: ${messageOf(cause)}`);
|
|
67
82
|
return USAGE;
|
|
68
83
|
}
|
|
69
|
-
|
|
84
|
+
if (command === "format") {
|
|
85
|
+
const result = format(source);
|
|
86
|
+
if (!result.ok) {
|
|
87
|
+
for (const diagnostic of result.diagnostics) {
|
|
88
|
+
io.err(`${parsed.file}:1:1: error [parse] ${diagnostic.message}`);
|
|
89
|
+
}
|
|
90
|
+
return REFUSED;
|
|
91
|
+
}
|
|
92
|
+
io.out(result.formatted.trimEnd());
|
|
93
|
+
return OK;
|
|
94
|
+
}
|
|
95
|
+
let costTable;
|
|
96
|
+
try {
|
|
97
|
+
costTable = await readDefaultCostTable(io);
|
|
98
|
+
}
|
|
99
|
+
catch (cause) {
|
|
100
|
+
io.err(`hsx: cannot read the packaged cost table: ${messageOf(cause)}`);
|
|
101
|
+
return USAGE;
|
|
102
|
+
}
|
|
103
|
+
const result = compile(source, { costTable });
|
|
70
104
|
for (const line of diagnosticLines(parsed.file, result))
|
|
71
105
|
io.err(line);
|
|
72
106
|
const refused = result.verdict === "invalid" ||
|
|
@@ -76,6 +110,17 @@ export async function runCli(argv, io) {
|
|
|
76
110
|
}
|
|
77
111
|
if (!result.artifacts)
|
|
78
112
|
return REFUSED;
|
|
113
|
+
if (command === "cost") {
|
|
114
|
+
const json = `${JSON.stringify(result.artifacts.costManifest, null, 2)}\n`;
|
|
115
|
+
if (parsed.out !== undefined) {
|
|
116
|
+
const writeCode = await writeOutput(parsed.out, json, io);
|
|
117
|
+
return writeCode === OK && refused ? REFUSED : writeCode;
|
|
118
|
+
}
|
|
119
|
+
io.out(parsed.json
|
|
120
|
+
? json.trimEnd()
|
|
121
|
+
: renderCostTable(result.artifacts.costManifest));
|
|
122
|
+
return refused ? REFUSED : OK;
|
|
123
|
+
}
|
|
79
124
|
const json = `${JSON.stringify({
|
|
80
125
|
document: result.artifacts.document,
|
|
81
126
|
frame: result.artifacts.frame,
|
|
@@ -96,17 +141,28 @@ export async function runCli(argv, io) {
|
|
|
96
141
|
}
|
|
97
142
|
function parseOptions(args, command) {
|
|
98
143
|
let file;
|
|
144
|
+
let json = false;
|
|
99
145
|
let out;
|
|
100
146
|
let strict = false;
|
|
101
147
|
for (let index = 0; index < args.length; index += 1) {
|
|
102
148
|
const argument = args[index];
|
|
103
149
|
if (argument === "--strict") {
|
|
150
|
+
if (command === "format") {
|
|
151
|
+
return { error: "hsx format has no style options" };
|
|
152
|
+
}
|
|
104
153
|
strict = true;
|
|
105
154
|
continue;
|
|
106
155
|
}
|
|
156
|
+
if (argument === "--json") {
|
|
157
|
+
if (command !== "cost")
|
|
158
|
+
return { error: "--json belongs to hsx cost" };
|
|
159
|
+
json = true;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
107
162
|
if (argument === "--out") {
|
|
108
|
-
if (command !== "build")
|
|
109
|
-
return { error: "--out belongs to hsx build" };
|
|
163
|
+
if (command !== "build" && command !== "cost") {
|
|
164
|
+
return { error: "--out belongs to hsx build or hsx cost" };
|
|
165
|
+
}
|
|
110
166
|
const value = args[index + 1];
|
|
111
167
|
if (value === undefined || value.startsWith("--")) {
|
|
112
168
|
return { error: "--out needs a file path" };
|
|
@@ -125,11 +181,91 @@ function parseOptions(args, command) {
|
|
|
125
181
|
}
|
|
126
182
|
if (file === undefined)
|
|
127
183
|
return { error: `hsx ${command} needs a file` };
|
|
128
|
-
return { file, ...(out === undefined ? {} : { out }), strict };
|
|
184
|
+
return { file, json, ...(out === undefined ? {} : { out }), strict };
|
|
185
|
+
}
|
|
186
|
+
function explainDiagnostic(args, io) {
|
|
187
|
+
if (args.length !== 1 || args[0]?.startsWith("-")) {
|
|
188
|
+
io.err("hsx: explain needs one diagnostic code");
|
|
189
|
+
return USAGE;
|
|
190
|
+
}
|
|
191
|
+
const diagnostic = hsxDiagnostics.find(({ code }) => code === args[0]);
|
|
192
|
+
if (!diagnostic) {
|
|
193
|
+
io.err(`hsx: unknown diagnostic code ${args[0]}`);
|
|
194
|
+
return USAGE;
|
|
195
|
+
}
|
|
196
|
+
io.out([
|
|
197
|
+
`${diagnostic.code} ${diagnostic.title}`,
|
|
198
|
+
`Stage: ${diagnostic.stage}`,
|
|
199
|
+
`Fix: ${diagnostic.fix}`,
|
|
200
|
+
diagnostic.example === null
|
|
201
|
+
? "Example: unavailable from source alone"
|
|
202
|
+
: `Example:\n${diagnostic.example}`,
|
|
203
|
+
].join("\n"));
|
|
204
|
+
return OK;
|
|
205
|
+
}
|
|
206
|
+
function renderCostTable(manifest) {
|
|
207
|
+
const rows = [
|
|
208
|
+
`costTableVersion\t${manifest.costTableVersion}`,
|
|
209
|
+
"instrument.action\teffect\tunit\tcount\ttotal\tpayer",
|
|
210
|
+
];
|
|
211
|
+
for (const action of manifest.actions) {
|
|
212
|
+
for (const component of action.components) {
|
|
213
|
+
const fixed = BigInt(component.perEventMinor) * BigInt(component.count);
|
|
214
|
+
const unit = [
|
|
215
|
+
`${component.perEventMinor} ${manifest.currency} minor`,
|
|
216
|
+
component.bps > 0 ? `${component.bps} bps` : undefined,
|
|
217
|
+
]
|
|
218
|
+
.filter((part) => part !== undefined)
|
|
219
|
+
.join(" + ");
|
|
220
|
+
const total = component.bps === 0
|
|
221
|
+
? `${fixed} ${manifest.currency} minor`
|
|
222
|
+
: [
|
|
223
|
+
fixed === 0n ? undefined : `${fixed} ${manifest.currency} minor`,
|
|
224
|
+
`amount-dependent (${component.bps} bps)`,
|
|
225
|
+
]
|
|
226
|
+
.filter((part) => part !== undefined)
|
|
227
|
+
.join(" + ");
|
|
228
|
+
rows.push([
|
|
229
|
+
`${action.instrument}.${action.action}`,
|
|
230
|
+
component.signature,
|
|
231
|
+
unit,
|
|
232
|
+
component.count,
|
|
233
|
+
total,
|
|
234
|
+
component.payer,
|
|
235
|
+
].join("\t"));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return rows.join("\n");
|
|
239
|
+
}
|
|
240
|
+
async function writeOutput(path, contents, io) {
|
|
241
|
+
try {
|
|
242
|
+
await io.writeFile(path, contents);
|
|
243
|
+
}
|
|
244
|
+
catch (cause) {
|
|
245
|
+
io.err(`hsx: cannot write ${path}: ${messageOf(cause)}`);
|
|
246
|
+
return USAGE;
|
|
247
|
+
}
|
|
248
|
+
return OK;
|
|
249
|
+
}
|
|
250
|
+
async function readDefaultCostTable(io) {
|
|
251
|
+
const candidates = [
|
|
252
|
+
fileURLToPath(new URL("../examples/cost-table.json", import.meta.url)),
|
|
253
|
+
fileURLToPath(new URL("../../examples/cost-table.json", import.meta.url)),
|
|
254
|
+
];
|
|
255
|
+
let lastError;
|
|
256
|
+
for (const path of candidates) {
|
|
257
|
+
try {
|
|
258
|
+
return JSON.parse(await io.readFile(path));
|
|
259
|
+
}
|
|
260
|
+
catch (cause) {
|
|
261
|
+
lastError = cause;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
throw lastError;
|
|
129
265
|
}
|
|
130
266
|
/** `file:line:col: severity [stage] message`, the shape editors already parse. */
|
|
131
267
|
function diagnosticLines(file, result) {
|
|
132
|
-
return result.diagnostics.map((diagnostic) => `${file}:${diagnostic.line}:${diagnostic.column}: ${diagnostic.severity} [${diagnostic.stage}] ${diagnostic.message}`);
|
|
268
|
+
return result.diagnostics.map((diagnostic) => `${diagnostic.file ?? file}:${diagnostic.line}:${diagnostic.column}: ${diagnostic.severity} [${diagnostic.stage}] ${diagnostic.message}`);
|
|
133
269
|
}
|
|
134
270
|
function messageOf(cause) {
|
|
135
271
|
return cause instanceof Error ? cause.message : String(cause);
|
package/dist/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAsB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAsB,MAAM,cAAc,CAAC;AAE3D,OAAO,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AAC"}
|
package/dist/src/compile.d.ts
CHANGED
|
@@ -10,23 +10,60 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Every diagnostic points at SOURCE coordinates, never at lowered IR paths.
|
|
12
12
|
*/
|
|
13
|
+
import type { UdlIssueCode } from "@hyperscale0/udl";
|
|
14
|
+
import { type UdlCostManifest, type UdlCostTable } from "./cost.ts";
|
|
15
|
+
import { type HsxCompilerHost } from "./modules.ts";
|
|
13
16
|
type Json = Record<string, unknown>;
|
|
14
17
|
type CompileVerdict = "invalid" | "valid" | "warning";
|
|
15
|
-
interface CompileDiagnostic {
|
|
18
|
+
export interface CompileDiagnostic {
|
|
16
19
|
/** 1-indexed source column. */
|
|
17
20
|
readonly column: number;
|
|
21
|
+
/** Imported module file when the diagnostic belongs to module source. */
|
|
22
|
+
readonly file?: string;
|
|
18
23
|
/** 1-indexed source line. */
|
|
19
24
|
readonly line: number;
|
|
20
25
|
readonly message: string;
|
|
26
|
+
/** Source offsets in UTF-16 code units, matching parser and checker spans. */
|
|
27
|
+
readonly span: {
|
|
28
|
+
readonly end: number;
|
|
29
|
+
readonly start: number;
|
|
30
|
+
};
|
|
31
|
+
readonly code?: string;
|
|
32
|
+
readonly fix?: string;
|
|
33
|
+
/** Canonical UDL path when lowering rejected an emitted clause. */
|
|
34
|
+
readonly path?: string;
|
|
35
|
+
/** UDL validator category when the emitter rejected its candidate document. */
|
|
36
|
+
readonly udlCode?: UdlIssueCode;
|
|
21
37
|
readonly severity: "error" | "warning";
|
|
22
38
|
/** The stage that raised it: parse, check, or lower. */
|
|
23
|
-
readonly stage: "check" | "lower" | "parse";
|
|
39
|
+
readonly stage: "bind" | "check" | "lower" | "parse" | "typecheck";
|
|
24
40
|
}
|
|
25
41
|
interface CompileArtifacts {
|
|
26
|
-
/** The
|
|
42
|
+
/** The canonical UDL document. */
|
|
27
43
|
readonly document: Json;
|
|
28
44
|
/** The congruent Business Frame. */
|
|
29
45
|
readonly frame: Json;
|
|
46
|
+
/** Canonical UDL paths bound to their narrowest authored source terms. */
|
|
47
|
+
readonly originMap: readonly CompileOriginMapEntry[];
|
|
48
|
+
/** Deterministic compile-time cost, pinned to one versioned table. */
|
|
49
|
+
readonly costManifest: UdlCostManifest;
|
|
50
|
+
}
|
|
51
|
+
export interface CompileOptions extends HsxCompilerHost {
|
|
52
|
+
readonly composesCatalogBlueprint?: boolean;
|
|
53
|
+
readonly costTable?: UdlCostTable;
|
|
54
|
+
}
|
|
55
|
+
export interface CompileOriginMapEntry {
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly span: {
|
|
58
|
+
/** Exclusive UTF-8 byte offset. */
|
|
59
|
+
readonly end: number;
|
|
60
|
+
/** 1-indexed source column. */
|
|
61
|
+
readonly column: number;
|
|
62
|
+
/** 1-indexed source line. */
|
|
63
|
+
readonly line: number;
|
|
64
|
+
/** Inclusive UTF-8 byte offset. */
|
|
65
|
+
readonly start: number;
|
|
66
|
+
};
|
|
30
67
|
}
|
|
31
68
|
export interface CompileResult {
|
|
32
69
|
/** Present exactly when the verdict is not `invalid`. */
|
|
@@ -34,6 +71,6 @@ export interface CompileResult {
|
|
|
34
71
|
readonly diagnostics: readonly CompileDiagnostic[];
|
|
35
72
|
readonly verdict: CompileVerdict;
|
|
36
73
|
}
|
|
37
|
-
export declare function compile(source: string): CompileResult;
|
|
74
|
+
export declare function compile(source: string, options?: CompileOptions): CompileResult;
|
|
38
75
|
export {};
|
|
39
76
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAEL,KAAK,eAAe,EACpB,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AsE;IACtE,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;CACxC;AAED,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,QAAQ,CAAC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAC5C,QAAQ,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE;QACb,mCAAmC;QACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,+BAA+B;QAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,6BAA6B;QAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,mCAAmC;QACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CAClC;AAED,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAmB,GAC3B,aAAa,CAiIf"}
|
package/dist/src/compile.js
CHANGED
|
@@ -11,53 +11,120 @@
|
|
|
11
11
|
* Every diagnostic points at SOURCE coordinates, never at lowered IR paths.
|
|
12
12
|
*/
|
|
13
13
|
import { lineColIn, lineIndex } from "./ast.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { buildCostManifest, } from "./cost.js";
|
|
15
|
+
import { lowerGeneralProgram } from "./emit.js";
|
|
16
|
+
import { resolveProgramModules, } from "./modules.js";
|
|
16
17
|
import { parseProgram } from "./parse.js";
|
|
17
|
-
|
|
18
|
+
import { checkGeneralProgram } from "./typecheck.js";
|
|
19
|
+
export function compile(source, options = {}) {
|
|
18
20
|
const diagnostics = [];
|
|
19
21
|
// Scanned once here rather than per diagnostic: a source can carry one
|
|
20
22
|
// diagnostic per two bytes, and rescanning from offset zero for each one
|
|
21
23
|
// made a 128 KB file cost 2.4 seconds of coordinate arithmetic.
|
|
22
24
|
const lines = lineIndex(source);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
+
const byteOffsets = utf8OffsetIndex(source);
|
|
26
|
+
const at = (stage, severity, message, span, details, origin) => {
|
|
27
|
+
const position = origin ?? lineColIn(lines, span.start);
|
|
25
28
|
diagnostics.push({
|
|
26
29
|
column: position.column,
|
|
30
|
+
...(origin ? { file: origin.moduleName } : {}),
|
|
27
31
|
line: position.line,
|
|
28
32
|
message,
|
|
33
|
+
span: { ...span },
|
|
34
|
+
...(details ? details : {}),
|
|
29
35
|
severity,
|
|
30
36
|
stage,
|
|
31
37
|
});
|
|
32
38
|
};
|
|
33
39
|
const parsed = parseProgram(source);
|
|
34
40
|
for (const diagnostic of parsed.diagnostics) {
|
|
35
|
-
at("parse", "error", diagnostic.message, diagnostic.span.
|
|
41
|
+
at("parse", "error", diagnostic.message, diagnostic.span, diagnostic.code && diagnostic.fix
|
|
42
|
+
? { code: diagnostic.code, fix: diagnostic.fix }
|
|
43
|
+
: undefined);
|
|
36
44
|
}
|
|
37
45
|
if (parsed.diagnostics.length > 0) {
|
|
38
46
|
return { diagnostics, verdict: "invalid" };
|
|
39
47
|
}
|
|
40
|
-
const
|
|
48
|
+
const resolved = resolveProgramModules(parsed.program, options);
|
|
49
|
+
if (!resolved.ok) {
|
|
50
|
+
for (const issue of resolved.issues) {
|
|
51
|
+
at("bind", "error", issue.message, issue.span, {
|
|
52
|
+
code: issue.code,
|
|
53
|
+
fix: issue.fix,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return { diagnostics, verdict: "invalid" };
|
|
57
|
+
}
|
|
58
|
+
const checked = checkGeneralProgram(resolved.program, options.publishedCatalog
|
|
59
|
+
? { publishedCatalog: options.publishedCatalog }
|
|
60
|
+
: {});
|
|
41
61
|
for (const diagnostic of checked.diagnostics) {
|
|
42
|
-
|
|
62
|
+
const moduleOrigin = resolved.origins.get(diagnostic.span);
|
|
63
|
+
at(diagnostic.code === "HSX1001" ? "bind" : "typecheck", diagnostic.severity, diagnostic.message, diagnostic.span, { code: diagnostic.code, fix: diagnostic.fix }, moduleOrigin);
|
|
43
64
|
}
|
|
44
|
-
if (!checked.program)
|
|
65
|
+
if (!checked.program)
|
|
66
|
+
return { diagnostics, verdict: "invalid" };
|
|
67
|
+
const cost = buildCostManifest(checked.program, options.costTable, options.composesCatalogBlueprint ?? false);
|
|
68
|
+
if (!cost.ok) {
|
|
69
|
+
for (const diagnostic of cost.diagnostics) {
|
|
70
|
+
at("typecheck", diagnostic.severity, diagnostic.message, diagnostic.span, { code: diagnostic.code, fix: diagnostic.fix });
|
|
71
|
+
}
|
|
45
72
|
return { diagnostics, verdict: "invalid" };
|
|
46
73
|
}
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
49
|
-
for (const issue of
|
|
50
|
-
at("lower", "error", issue.message, issue.span
|
|
74
|
+
const lowered = lowerGeneralProgram(checked.program);
|
|
75
|
+
if (!lowered.ok) {
|
|
76
|
+
for (const issue of lowered.issues) {
|
|
77
|
+
at("lower", "error", issue.message, issue.span, {
|
|
78
|
+
code: issue.code,
|
|
79
|
+
fix: issue.fix,
|
|
80
|
+
path: issue.path,
|
|
81
|
+
...(issue.udlCode ? { udlCode: issue.udlCode } : {}),
|
|
82
|
+
});
|
|
51
83
|
}
|
|
52
84
|
return { diagnostics, verdict: "invalid" };
|
|
53
85
|
}
|
|
86
|
+
const compileOrigin = (entry) => {
|
|
87
|
+
const position = lineColIn(lines, entry.span.start);
|
|
88
|
+
return {
|
|
89
|
+
path: entry.path,
|
|
90
|
+
span: {
|
|
91
|
+
column: position.column,
|
|
92
|
+
end: byteOffsets[entry.span.end] ?? byteOffsets[byteOffsets.length - 1],
|
|
93
|
+
line: position.line,
|
|
94
|
+
start: byteOffsets[entry.span.start] ?? 0,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
54
98
|
return {
|
|
55
99
|
artifacts: {
|
|
56
|
-
document:
|
|
57
|
-
|
|
100
|
+
document: lowered.value.document,
|
|
101
|
+
costManifest: cost.manifest,
|
|
102
|
+
frame: lowered.value.frame,
|
|
103
|
+
originMap: lowered.value.originMap.map(compileOrigin),
|
|
58
104
|
},
|
|
59
105
|
diagnostics,
|
|
60
106
|
verdict: diagnostics.length > 0 ? "warning" : "valid",
|
|
61
107
|
};
|
|
62
108
|
}
|
|
109
|
+
function utf8OffsetIndex(source) {
|
|
110
|
+
const offsets = new Uint32Array(source.length + 1);
|
|
111
|
+
let bytes = 0;
|
|
112
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
113
|
+
offsets[index] = bytes;
|
|
114
|
+
const codePoint = source.codePointAt(index);
|
|
115
|
+
if (codePoint > 0xffff) {
|
|
116
|
+
offsets[index + 1] = bytes;
|
|
117
|
+
bytes += 4;
|
|
118
|
+
index += 1;
|
|
119
|
+
}
|
|
120
|
+
else if (codePoint > 0x7ff)
|
|
121
|
+
bytes += 3;
|
|
122
|
+
else if (codePoint > 0x7f)
|
|
123
|
+
bytes += 2;
|
|
124
|
+
else
|
|
125
|
+
bytes += 1;
|
|
126
|
+
}
|
|
127
|
+
offsets[source.length] = bytes;
|
|
128
|
+
return offsets;
|
|
129
|
+
}
|
|
63
130
|
//# sourceMappingURL=compile.js.map
|
package/dist/src/compile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU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AAG,CAAC,CAAC,CAAC;IACnD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;QACvB,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAW,CAAC;QACtD,IAAI,SAAS,GAAG,MAAM,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAC3B,KAAK,IAAI,CAAC,CAAC;YACX,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;aAAM,IAAI,SAAS,GAAG,KAAK;YAAE,KAAK,IAAI,CAAC,CAAC;aACpC,IAAI,SAAS,GAAG,IAAI;YAAE,KAAK,IAAI,CAAC,CAAC;;YACjC,KAAK,IAAI,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;IAC/B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type UdlDocument, type UdlEffectKind } from "@hyperscale0/udl";
|
|
2
|
+
import type { GeneralDiagnostic, TypedProgram } from "./ir.ts";
|
|
3
|
+
export type HsxEffectKind = UdlEffectKind;
|
|
4
|
+
export interface UdlCostTable {
|
|
5
|
+
readonly version: string;
|
|
6
|
+
/** Digest of the effective prices and fixed anchors after overrides. */
|
|
7
|
+
readonly effectiveTableDigest: string;
|
|
8
|
+
readonly currency: string;
|
|
9
|
+
/** Billable runtime meters the platform's operation contract can emit. */
|
|
10
|
+
readonly declaredMeters: readonly string[];
|
|
11
|
+
readonly rows: readonly {
|
|
12
|
+
readonly signature: string;
|
|
13
|
+
readonly perEventMinor: string;
|
|
14
|
+
readonly bps: number;
|
|
15
|
+
readonly payer: "product" | "end_customer";
|
|
16
|
+
/** Collection policy. Runtime resolves movement rows to execution or invoice. */
|
|
17
|
+
readonly settlement: "per_event" | "invoice";
|
|
18
|
+
readonly meter: string;
|
|
19
|
+
readonly volumeMeter?: string;
|
|
20
|
+
}[];
|
|
21
|
+
readonly fixed: {
|
|
22
|
+
readonly weights: Readonly<Record<string, number>>;
|
|
23
|
+
readonly monthlyBaseMinor: string;
|
|
24
|
+
readonly monthlyPerPointMinor: string;
|
|
25
|
+
readonly activationBaseMinor: string;
|
|
26
|
+
readonly activationPerPointMinor: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface UdlCostManifest {
|
|
30
|
+
readonly costTableVersion: string;
|
|
31
|
+
readonly effectiveTableDigest: string;
|
|
32
|
+
readonly currency: string;
|
|
33
|
+
/** Complete runtime meter allowlist, independent of clause effects and payer. */
|
|
34
|
+
readonly declaredMeters: readonly string[];
|
|
35
|
+
readonly fixed: {
|
|
36
|
+
readonly complexityScore: number;
|
|
37
|
+
readonly monthlyMinor: string;
|
|
38
|
+
readonly activationMinor: string;
|
|
39
|
+
readonly components: readonly {
|
|
40
|
+
readonly weight: string;
|
|
41
|
+
readonly count: number;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
readonly actions: readonly {
|
|
45
|
+
readonly instrument: string;
|
|
46
|
+
readonly action: string;
|
|
47
|
+
readonly components: readonly {
|
|
48
|
+
readonly signature: string;
|
|
49
|
+
readonly count: number;
|
|
50
|
+
readonly perEventMinor: string;
|
|
51
|
+
readonly bps: number;
|
|
52
|
+
readonly payer: "product" | "end_customer";
|
|
53
|
+
readonly settlement: "per_event" | "invoice";
|
|
54
|
+
readonly meter: string;
|
|
55
|
+
readonly volumeMeter?: string;
|
|
56
|
+
}[];
|
|
57
|
+
readonly perEventMinor: string;
|
|
58
|
+
readonly endCustomerPerEventMinor: string;
|
|
59
|
+
}[];
|
|
60
|
+
/** Frozen list prices for every declared runtime meter. */
|
|
61
|
+
readonly meterPrices: readonly UdlCostTable["rows"][number][];
|
|
62
|
+
readonly monthlyEstimate: {
|
|
63
|
+
readonly expression: string;
|
|
64
|
+
readonly variables: readonly string[];
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export type CostManifestResult = {
|
|
68
|
+
readonly diagnostics: readonly GeneralDiagnostic[];
|
|
69
|
+
readonly ok: false;
|
|
70
|
+
} | {
|
|
71
|
+
readonly manifest: UdlCostManifest;
|
|
72
|
+
readonly ok: true;
|
|
73
|
+
};
|
|
74
|
+
export declare function buildCostManifest(program: TypedProgram, table: UdlCostTable | undefined, composesCatalogBlueprint: boolean): CostManifestResult;
|
|
75
|
+
export declare function computeUdlFixedCost(document: UdlDocument, table: UdlCostTable, composesCatalogBlueprint: boolean): UdlCostManifest["fixed"];
|
|
76
|
+
export declare function buildUdlCostManifest(document: UdlDocument, table: UdlCostTable, composesCatalogBlueprint: boolean): UdlCostManifest;
|
|
77
|
+
export declare function evaluateUdlCostManifest(costManifest: UdlCostManifest, readings: Readonly<Record<string, string>>): string;
|
|
78
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/cost.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAa,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1E,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC;AAE1C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,0EAA0E;IAC1E,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,IAAI,E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