@hyperscale0/hsx 1.0.337 → 1.0.339
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/dist/src/ast.d.ts +1 -0
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast.js.map +1 -1
- package/dist/src/attachment-economics.d.ts +37 -0
- package/dist/src/attachment-economics.d.ts.map +1 -1
- package/dist/src/attachment-economics.js +183 -3
- package/dist/src/attachment-economics.js.map +1 -1
- package/dist/src/binding-contract.d.ts.map +1 -1
- package/dist/src/binding-contract.js +10 -4
- package/dist/src/binding-contract.js.map +1 -1
- package/dist/src/catalog-program.d.ts +1 -1
- package/dist/src/catalog-program.d.ts.map +1 -1
- package/dist/src/catalog-program.js +1 -1
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +133 -41
- package/dist/src/compile.js.map +1 -1
- package/dist/src/examples-bundle.js +1 -1
- package/dist/src/examples-bundle.js.map +1 -1
- package/dist/src/headers.d.ts.map +1 -1
- package/dist/src/headers.js +3 -1
- package/dist/src/headers.js.map +1 -1
- package/dist/src/language.d.ts.map +1 -1
- package/dist/src/language.js +1 -0
- package/dist/src/language.js.map +1 -1
- package/dist/src/parse.js +13 -1
- package/dist/src/parse.js.map +1 -1
- package/dist/src/std-bundle.js +6 -6
- package/dist/src/std-bundle.js.map +1 -1
- package/dist/src/template-guide.d.ts.map +1 -1
- package/dist/src/template-guide.js +49 -18
- package/dist/src/template-guide.js.map +1 -1
- package/docs/README.md +5 -2
- package/examples/camera-rental.hsx +6 -1
- package/package.json +4 -4
- package/src/ast.ts +7 -1
- package/src/attachment-economics.ts +230 -2
- package/src/binding-contract.ts +13 -6
- package/src/catalog-program.ts +1 -1
- package/src/compile.ts +185 -58
- package/src/examples-bundle.ts +1 -1
- package/src/headers.ts +6 -1
- package/src/language.ts +1 -0
- package/src/parse.ts +16 -1
- package/src/std-bundle.ts +6 -6
- package/src/template-guide.ts +74 -22
- package/std/collections.hsx +4 -4
- package/std/financing.hsx +461 -266
- package/std/insurance.hsx +21 -5
- package/std/lending.hsx +13 -9
- package/std/money.hsx +148 -38
- package/std/reporting.hsx +6 -6
package/src/catalog-program.ts
CHANGED
|
@@ -24,7 +24,7 @@ object item "Item" {
|
|
|
24
24
|
attach transfer = money.transfer { payer: actor, payee: owner, amount: 750 SAR }
|
|
25
25
|
attach hold = money.hold { payer: actor, payee: owner, amount: 750 SAR }
|
|
26
26
|
attach split = money.split { payer: actor, amount: 750 SAR }
|
|
27
|
-
attach schedule = money.schedule { payer:
|
|
27
|
+
attach schedule = money.schedule { payer: owner, payee: operator, amount: 250 SAR, every: 1 month }
|
|
28
28
|
attach pool = money.pool { payer: actor, payee: owner, target: 1000 SAR, closes: 2027-01-01 }
|
|
29
29
|
attach swap = money.swap { first: actor, second: owner, first_amount: 100 SAR, second_amount: 200 SAR, expires: 2027-01-01 }
|
|
30
30
|
attach payout = money.payout { payer: actor, payee: owner, adapter: "conformance_boundary" }
|
package/src/compile.ts
CHANGED
|
@@ -43,6 +43,8 @@ import { parseProgram } from "./parse.ts";
|
|
|
43
43
|
import {
|
|
44
44
|
applyAttachmentEconomics,
|
|
45
45
|
purposeWarnings,
|
|
46
|
+
samePartyMoves,
|
|
47
|
+
unboundEconomicSources,
|
|
46
48
|
} from "./attachment-economics.ts";
|
|
47
49
|
import { parseHeader } from "./header-source.ts";
|
|
48
50
|
import {
|
|
@@ -331,6 +333,24 @@ function decimal(raw: string, scale: number, expr: Expr): string {
|
|
|
331
333
|
BigInt(fraction.padEnd(scale, "0") || "0")
|
|
332
334
|
).toString();
|
|
333
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* A calendar period as ISO-8601 text: `1 month`, `2 weeks`, `7d` or `P1M`.
|
|
338
|
+
* Days, weeks, months and years only, the units Stripe and Shopify bill in.
|
|
339
|
+
*/
|
|
340
|
+
function periodText(expr: Expr): string | undefined {
|
|
341
|
+
if (!["duration", "text", "name"].includes(expr.kind)) return undefined;
|
|
342
|
+
const value = (expr as { value: string }).value.trim();
|
|
343
|
+
const units: Record<string, string> = { d: "D", w: "W", m: "M", y: "Y" };
|
|
344
|
+
const words = /^([1-9]\d{0,3}) ?(day|week|month|year)s?$/.exec(value);
|
|
345
|
+
const short = /^([1-9]\d{0,3})(d|w)$/.exec(value);
|
|
346
|
+
const iso =
|
|
347
|
+
/^P(?!$)(?:[1-9]\d{0,3}Y)?(?:[1-9]\d{0,3}M)?(?:[1-9]\d{0,3}W)?(?:[1-9]\d{0,3}D)?$/.exec(
|
|
348
|
+
value,
|
|
349
|
+
);
|
|
350
|
+
if (words) return `P${words[1]}${units[words[2]![0]!]}`;
|
|
351
|
+
if (short) return `P${short[1]}${units[short[2]!]}`;
|
|
352
|
+
return iso ? value : undefined;
|
|
353
|
+
}
|
|
334
354
|
function literal(expr: Expr, expectedType?: string): string | number | boolean {
|
|
335
355
|
if (expr.kind === "text" && expectedType === "duration")
|
|
336
356
|
return literal({ ...expr, kind: "duration" });
|
|
@@ -778,6 +798,8 @@ export function compile(
|
|
|
778
798
|
revision?: number | undefined;
|
|
779
799
|
},
|
|
780
800
|
standardOrigin?: NonNullable<CompileOriginMapEntry["standardBlock"]>,
|
|
801
|
+
/** Declared tunables, true where the author bound them. */
|
|
802
|
+
inheritedTunables = new Map<string, boolean>(),
|
|
781
803
|
) => {
|
|
782
804
|
const resolveFamilyInstruments = (
|
|
783
805
|
family: UdlFamily,
|
|
@@ -970,6 +992,9 @@ export function compile(
|
|
|
970
992
|
suppliedEntries.set(entry.key, entry);
|
|
971
993
|
}
|
|
972
994
|
const environment = new Map<string, Expr>(inherited);
|
|
995
|
+
// `when every is set` asks whether the author bound a tunable; a
|
|
996
|
+
// default leaves it unset.
|
|
997
|
+
const tunables = new Map(inheritedTunables);
|
|
973
998
|
const parameterErrors: Diagnostic[] = [];
|
|
974
999
|
for (const param of decl.parameters) {
|
|
975
1000
|
const type =
|
|
@@ -979,7 +1004,8 @@ export function compile(
|
|
|
979
1004
|
const typeName =
|
|
980
1005
|
type.kind === "type" || type.kind === "call" ? type.name : text(type);
|
|
981
1006
|
const partyParameter = attachmentInfo && typeName === "party";
|
|
982
|
-
const optional =
|
|
1007
|
+
const optional =
|
|
1008
|
+
(type.kind === "type" || type.kind === "call") && !!type.optional;
|
|
983
1009
|
// An optional party stays unset unless the attachment binds it, so a
|
|
984
1010
|
// program party that shares its name does not switch it on.
|
|
985
1011
|
const byName: Expr | undefined =
|
|
@@ -989,6 +1015,7 @@ export function compile(
|
|
|
989
1015
|
document.parties[param.key])
|
|
990
1016
|
? { kind: "name", value: param.key, span: origin }
|
|
991
1017
|
: undefined;
|
|
1018
|
+
tunables.set(param.key, supplied.has(param.key) || !!byName);
|
|
992
1019
|
const actual =
|
|
993
1020
|
supplied.get(param.key) ??
|
|
994
1021
|
byName ??
|
|
@@ -1036,11 +1063,10 @@ export function compile(
|
|
|
1036
1063
|
}
|
|
1037
1064
|
for (const dependency of dependencies) {
|
|
1038
1065
|
const selected = environment.get(dependency.when);
|
|
1039
|
-
|
|
1040
|
-
selected?.kind === "name" &&
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
) {
|
|
1066
|
+
const holds = enums.has(dependency.when)
|
|
1067
|
+
? selected?.kind === "name" && selected.value === dependency.is
|
|
1068
|
+
: tunables.get(dependency.when) === (dependency.is === "set");
|
|
1069
|
+
if (holds && !environment.has(dependency.binding)) {
|
|
1044
1070
|
throw new CompileFailure({
|
|
1045
1071
|
code: "HSX1001",
|
|
1046
1072
|
message: dependency.message.replaceAll(
|
|
@@ -1221,7 +1247,10 @@ export function compile(
|
|
|
1221
1247
|
.filter(
|
|
1222
1248
|
(p) =>
|
|
1223
1249
|
p.value.kind !== "default" &&
|
|
1224
|
-
!(
|
|
1250
|
+
!(
|
|
1251
|
+
(p.value.kind === "type" || p.value.kind === "call") &&
|
|
1252
|
+
p.value.optional
|
|
1253
|
+
),
|
|
1225
1254
|
)
|
|
1226
1255
|
.map((p) => p.key) ?? [];
|
|
1227
1256
|
fail(
|
|
@@ -1331,6 +1360,9 @@ export function compile(
|
|
|
1331
1360
|
/^P/.test(v.value)
|
|
1332
1361
|
)
|
|
1333
1362
|
v = { ...v, kind: "duration" };
|
|
1363
|
+
// A period lowers as ISO text, so `after` steps calendar months.
|
|
1364
|
+
const period = type === "period" ? periodText(v) : undefined;
|
|
1365
|
+
if (period) v = { kind: "text", value: period, span: v.span };
|
|
1334
1366
|
environment.set(param.key, v);
|
|
1335
1367
|
if (type === "enum" && t.kind === "call") {
|
|
1336
1368
|
if (v.kind !== "name" || !t.args.some((a) => text(a) === v.value))
|
|
@@ -1453,6 +1485,13 @@ export function compile(
|
|
|
1453
1485
|
items: [v],
|
|
1454
1486
|
span: v.span,
|
|
1455
1487
|
});
|
|
1488
|
+
} else if (type === "period") {
|
|
1489
|
+
if (!period)
|
|
1490
|
+
fail(
|
|
1491
|
+
v,
|
|
1492
|
+
`${param.key} needs a calendar period`,
|
|
1493
|
+
`write ${param.key}: 1 month, 2 weeks, 1 year or 7 days`,
|
|
1494
|
+
);
|
|
1456
1495
|
} else if (type === "fee" || type === "split" || type === "policy") {
|
|
1457
1496
|
if (v.kind !== "block")
|
|
1458
1497
|
fail(
|
|
@@ -1571,6 +1610,41 @@ export function compile(
|
|
|
1571
1610
|
throw new CompileFailure(parameterErrors[0]!);
|
|
1572
1611
|
}
|
|
1573
1612
|
const body = entries(decl.body);
|
|
1613
|
+
// A ceiling caps a tunable by the value of an enum tunable, such as the
|
|
1614
|
+
// longest term per loan kind. An unset tunable takes the ceiling; a
|
|
1615
|
+
// supplied one may lower it, never raise it.
|
|
1616
|
+
for (const ceiling of asBlock(body.get("ceilings")).entries) {
|
|
1617
|
+
const table = entries(asBlock(ceiling.value));
|
|
1618
|
+
const by = table.get("by");
|
|
1619
|
+
const selected = by && environment.get(text(by));
|
|
1620
|
+
if (!by || selected?.kind !== "name")
|
|
1621
|
+
fail(
|
|
1622
|
+
ceiling,
|
|
1623
|
+
`ceiling ${ceiling.key} needs by: an enum tunable`,
|
|
1624
|
+
"write by: kind and one maximum per enum value",
|
|
1625
|
+
);
|
|
1626
|
+
const maximum = table.get(selected.value);
|
|
1627
|
+
if (maximum?.kind !== "number")
|
|
1628
|
+
fail(
|
|
1629
|
+
ceiling,
|
|
1630
|
+
`ceiling ${ceiling.key} has no maximum for ${selected.value}`,
|
|
1631
|
+
`add ${selected.value}: number to the ceiling`,
|
|
1632
|
+
);
|
|
1633
|
+
if (!tunables.get(ceiling.key)) {
|
|
1634
|
+
environment.set(ceiling.key, { ...maximum, span: origin });
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
const supplied = environment.get(ceiling.key)!;
|
|
1638
|
+
if (
|
|
1639
|
+
supplied.kind !== "number" ||
|
|
1640
|
+
BigInt(supplied.value) > BigInt(maximum.value)
|
|
1641
|
+
)
|
|
1642
|
+
fail(
|
|
1643
|
+
supplied,
|
|
1644
|
+
`${ceiling.key} for ${selected.value} is at most ${maximum.value}`,
|
|
1645
|
+
`choose ${ceiling.key} of ${maximum.value} or less, or omit it`,
|
|
1646
|
+
);
|
|
1647
|
+
}
|
|
1574
1648
|
for (const constraint of asBlock(body.get("constraints")).entries) {
|
|
1575
1649
|
const rule = constraint.value;
|
|
1576
1650
|
if (
|
|
@@ -1591,6 +1665,13 @@ export function compile(
|
|
|
1591
1665
|
"constraint needs two declared tunables",
|
|
1592
1666
|
"name the compared tunables",
|
|
1593
1667
|
);
|
|
1668
|
+
// A runtime value is checked when the agreement is created.
|
|
1669
|
+
if (
|
|
1670
|
+
[left, right].some(
|
|
1671
|
+
(expr) => expr.kind === "name" && expr.value === "runtime",
|
|
1672
|
+
)
|
|
1673
|
+
)
|
|
1674
|
+
continue;
|
|
1594
1675
|
const numericKind = (expr: Expr) =>
|
|
1595
1676
|
expr.kind === "name" && /^P(?:\d|T)/.test(expr.value)
|
|
1596
1677
|
? "duration"
|
|
@@ -1631,6 +1712,7 @@ export function compile(
|
|
|
1631
1712
|
"summary",
|
|
1632
1713
|
"invariants",
|
|
1633
1714
|
"constraints",
|
|
1715
|
+
"ceilings",
|
|
1634
1716
|
"dependencies",
|
|
1635
1717
|
"parameterDiagnostics",
|
|
1636
1718
|
"reports",
|
|
@@ -1873,9 +1955,71 @@ export function compile(
|
|
|
1873
1955
|
: value.value;
|
|
1874
1956
|
return literal(value);
|
|
1875
1957
|
};
|
|
1958
|
+
const branchMatches = (entry: Entry): boolean => {
|
|
1959
|
+
const [, tunable, relation, choice] = entry.key.split(" ");
|
|
1960
|
+
// `when every is set` holds when the author bound the tunable, so an
|
|
1961
|
+
// optional tunable and a defaulted one both read as unset.
|
|
1962
|
+
if (
|
|
1963
|
+
relation === "is" &&
|
|
1964
|
+
(choice === "set" || choice === "unset") &&
|
|
1965
|
+
tunables.has(tunable!) &&
|
|
1966
|
+
!enums.has(tunable!)
|
|
1967
|
+
)
|
|
1968
|
+
return tunables.get(tunable!) === (choice === "set");
|
|
1969
|
+
const binding = environment.get(tunable!);
|
|
1970
|
+
if (!binding)
|
|
1971
|
+
fail(
|
|
1972
|
+
entry,
|
|
1973
|
+
`unknown branch tunable ${tunable}`,
|
|
1974
|
+
"name an enum, reference or optional tunable declared by this header",
|
|
1975
|
+
);
|
|
1976
|
+
if (relation === "has") {
|
|
1977
|
+
// Inspect declarations, not lowering order: a bound object may
|
|
1978
|
+
// appear after the instrument that asks about its fields.
|
|
1979
|
+
const bound = resolve(binding!);
|
|
1980
|
+
const [root, ...children] = text(bound).split(".");
|
|
1981
|
+
const assignment = assignments.get(root!);
|
|
1982
|
+
let target = assignment
|
|
1983
|
+
? templates.get(assignment.target)?.body
|
|
1984
|
+
: program.decls
|
|
1985
|
+
.filter(
|
|
1986
|
+
(decl): decl is InstrumentDecl => decl.kind === "instrument",
|
|
1987
|
+
)
|
|
1988
|
+
.find((decl) => decl.name === root)?.body;
|
|
1989
|
+
for (const child of children) {
|
|
1990
|
+
const record = target
|
|
1991
|
+
? entries(asBlock(entries(target).get("records"))).get(child)
|
|
1992
|
+
: undefined;
|
|
1993
|
+
target = record ? asBlock(record) : undefined;
|
|
1994
|
+
}
|
|
1995
|
+
if (!target)
|
|
1996
|
+
fail(
|
|
1997
|
+
entry,
|
|
1998
|
+
"field branch needs a declared object",
|
|
1999
|
+
"bind a reference to a declared object",
|
|
2000
|
+
);
|
|
2001
|
+
return entries(asBlock(entries(target!).get("fields"))).has(choice!);
|
|
2002
|
+
}
|
|
2003
|
+
if (!enums.get(tunable!)?.includes(choice!))
|
|
2004
|
+
fail(
|
|
2005
|
+
entry,
|
|
2006
|
+
`unknown enum branch ${choice}`,
|
|
2007
|
+
"use a declared enum value, or set or unset",
|
|
2008
|
+
);
|
|
2009
|
+
return text(binding!) === choice;
|
|
2010
|
+
};
|
|
2011
|
+
// Fields and inputs take `when` branches too; a branch holds field rows.
|
|
2012
|
+
const branchRows = (block: BlockExpr): Entry[] =>
|
|
2013
|
+
block.entries.flatMap((row) =>
|
|
2014
|
+
row.key.startsWith("when ")
|
|
2015
|
+
? branchMatches(row)
|
|
2016
|
+
? branchRows(asBlock(row.value))
|
|
2017
|
+
: []
|
|
2018
|
+
: [row],
|
|
2019
|
+
);
|
|
1876
2020
|
const lowerFields = (block: BlockExpr): UdlField[] => {
|
|
1877
2021
|
const result: UdlField[] = [];
|
|
1878
|
-
for (const row of block
|
|
2022
|
+
for (const row of branchRows(block)) {
|
|
1879
2023
|
const { type: t } = fieldType(row);
|
|
1880
2024
|
const constant =
|
|
1881
2025
|
row.value.kind === "default" ? resolve(row.value.value) : undefined;
|
|
@@ -2086,6 +2230,15 @@ export function compile(
|
|
|
2086
2230
|
milliseconds: args[1]!,
|
|
2087
2231
|
direction: constant.name as "before" | "after",
|
|
2088
2232
|
});
|
|
2233
|
+
// after(start, 1 month, 3) steps calendar periods from start.
|
|
2234
|
+
else if (constant.name === "after" && args.length === 3)
|
|
2235
|
+
calculations.push({
|
|
2236
|
+
target,
|
|
2237
|
+
op: "step",
|
|
2238
|
+
date: args[0]!,
|
|
2239
|
+
period: args[1]!,
|
|
2240
|
+
times: args[2]!,
|
|
2241
|
+
});
|
|
2089
2242
|
else
|
|
2090
2243
|
fail(
|
|
2091
2244
|
constant,
|
|
@@ -2179,53 +2332,7 @@ export function compile(
|
|
|
2179
2332
|
...block,
|
|
2180
2333
|
entries: block.entries.flatMap((entry) => {
|
|
2181
2334
|
if (!entry.key.startsWith("when ")) return [entry];
|
|
2182
|
-
const
|
|
2183
|
-
const binding = environment.get(tunable!);
|
|
2184
|
-
if (!binding)
|
|
2185
|
-
fail(
|
|
2186
|
-
entry,
|
|
2187
|
-
`unknown branch tunable ${tunable}`,
|
|
2188
|
-
"name an enum or reference tunable declared by this header",
|
|
2189
|
-
);
|
|
2190
|
-
let matches: boolean;
|
|
2191
|
-
if (relation === "has") {
|
|
2192
|
-
// Inspect declarations, not lowering order: a bound object may
|
|
2193
|
-
// appear after the instrument that asks about its fields.
|
|
2194
|
-
const bound = resolve(binding!);
|
|
2195
|
-
const [root, ...children] = text(bound).split(".");
|
|
2196
|
-
const assignment = assignments.get(root!);
|
|
2197
|
-
let target = assignment
|
|
2198
|
-
? templates.get(assignment.target)?.body
|
|
2199
|
-
: program.decls
|
|
2200
|
-
.filter(
|
|
2201
|
-
(decl): decl is InstrumentDecl =>
|
|
2202
|
-
decl.kind === "instrument",
|
|
2203
|
-
)
|
|
2204
|
-
.find((decl) => decl.name === root)?.body;
|
|
2205
|
-
for (const child of children) {
|
|
2206
|
-
const record = target
|
|
2207
|
-
? entries(asBlock(entries(target).get("records"))).get(child)
|
|
2208
|
-
: undefined;
|
|
2209
|
-
target = record ? asBlock(record) : undefined;
|
|
2210
|
-
}
|
|
2211
|
-
if (!target)
|
|
2212
|
-
fail(
|
|
2213
|
-
entry,
|
|
2214
|
-
"field branch needs a declared object",
|
|
2215
|
-
"bind a reference to a declared object",
|
|
2216
|
-
);
|
|
2217
|
-
matches = entries(asBlock(entries(target!).get("fields"))).has(
|
|
2218
|
-
choice!,
|
|
2219
|
-
);
|
|
2220
|
-
} else {
|
|
2221
|
-
if (!enums.get(tunable!)?.includes(choice!))
|
|
2222
|
-
fail(
|
|
2223
|
-
entry,
|
|
2224
|
-
`unknown enum branch ${choice}`,
|
|
2225
|
-
"use a declared enum value",
|
|
2226
|
-
);
|
|
2227
|
-
matches = text(binding!) === choice;
|
|
2228
|
-
}
|
|
2335
|
+
const matches = branchMatches(entry);
|
|
2229
2336
|
const body = asBlock(entry.value);
|
|
2230
2337
|
for (const clause of body.entries)
|
|
2231
2338
|
if (
|
|
@@ -3397,6 +3504,7 @@ export function compile(
|
|
|
3397
3504
|
.join("."),
|
|
3398
3505
|
}
|
|
3399
3506
|
: undefined,
|
|
3507
|
+
tunables,
|
|
3400
3508
|
);
|
|
3401
3509
|
}
|
|
3402
3510
|
};
|
|
@@ -4710,12 +4818,31 @@ export function compile(
|
|
|
4710
4818
|
);
|
|
4711
4819
|
}),
|
|
4712
4820
|
};
|
|
4821
|
+
const sameParty = samePartyMoves(
|
|
4822
|
+
document,
|
|
4823
|
+
attachedSelectors,
|
|
4824
|
+
attachEntries,
|
|
4825
|
+
);
|
|
4826
|
+
const unbound = unboundEconomicSources(
|
|
4827
|
+
document,
|
|
4828
|
+
attachedSelectors,
|
|
4829
|
+
attachEntries,
|
|
4830
|
+
);
|
|
4831
|
+
if (sameParty.errors.length || unbound.length)
|
|
4832
|
+
return {
|
|
4833
|
+
verdict: "invalid",
|
|
4834
|
+
warnings: [],
|
|
4835
|
+
diagnostics: [...sameParty.errors, ...unbound].map((d) =>
|
|
4836
|
+
diagnostic(d, "check"),
|
|
4837
|
+
),
|
|
4838
|
+
};
|
|
4713
4839
|
return {
|
|
4714
4840
|
verdict: "valid",
|
|
4715
4841
|
diagnostics: [],
|
|
4716
|
-
warnings:
|
|
4717
|
-
|
|
4718
|
-
|
|
4842
|
+
warnings: [
|
|
4843
|
+
...sameParty.warnings,
|
|
4844
|
+
...purposeWarnings(document, attachedSelectors, attachEntries),
|
|
4845
|
+
].map((d) => ({ ...diagnostic(d, "check"), severity: "warning" })),
|
|
4719
4846
|
artifacts: {
|
|
4720
4847
|
document: validated.value,
|
|
4721
4848
|
costManifest: buildUdlCostManifest(validated.value),
|
package/src/examples-bundle.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by open/hsx/scripts/bundle-examples.ts. Do not edit by hand.
|
|
2
2
|
import type { HsxExample } from "./examples.ts";
|
|
3
3
|
export const examples: HsxExample[] = [
|
|
4
|
-
{"id":"camera-rental","title":"Camera rentals","summary":"Riyadh camera shop holds a 1,000 SAR deposit on each rental and charges 50 SAR for each day a camera comes back late, after one day of grace, up to 300 SAR.","headers":["money"],"source":"// Riyadh camera shop holds a 1,000 SAR deposit on each rental and charges 50 SAR\n// for each day a camera comes back late, after one day of grace, up to 300 SAR.\nprogram camera_rentals \"Camera rentals\"\nuse money\n\n// The customer owns the rental and pays both the deposit and any late fee.\n// The shop is payee, so its own session keeps a damaged camera's deposit with\n// keep_deposit; released_by stays on the default payee. Late fees are earnings.\nobject rental \"Camera rental\" {\n fields { camera: text, returnBy: date }\n columns: [camera, returnBy]\n attach deposit = money.hold {\n payer: owner, payee: operator, amount: 1000 SAR\n expose create as agree_deposit\n expose fund as pay_deposit\n expose release as keep_deposit\n expose refund as return_deposit\n }\n attach late = money.late_fee {\n payer: owner, payee: operator, amount: 50 SAR, cap: 300 SAR, period: 1d, grace: 1d\n rename { dueAt: returnBy }\n expose create as
|
|
4
|
+
{"id":"camera-rental","title":"Camera rentals","summary":"Riyadh camera shop holds a 1,000 SAR deposit on each rental and charges 50 SAR for each day a camera comes back late, after one day of grace, up to 300 SAR.","headers":["money"],"source":"// Riyadh camera shop holds a 1,000 SAR deposit on each rental and charges 50 SAR\n// for each day a camera comes back late, after one day of grace, up to 300 SAR.\nprogram camera_rentals \"Camera rentals\"\nuse money\n\n// The customer owns the rental and pays both the deposit and any late fee.\n// The shop is payee, so its own session keeps a damaged camera's deposit with\n// keep_deposit; released_by stays on the default payee. Late fees are earnings.\n// A return keeps the fees owed so far; waive_late_fees forgives the ones a\n// customer never funds. The shop starts the fees, and change_return moves the\n// unpaid ones to a later returnBy.\nobject rental \"Camera rental\" {\n fields { camera: text, returnBy: date }\n columns: [camera, returnBy]\n attach deposit = money.hold {\n payer: owner, payee: operator, amount: 1000 SAR\n expose create as agree_deposit\n expose fund as pay_deposit\n expose release as keep_deposit\n expose refund as return_deposit\n }\n attach late = money.late_fee {\n payer: owner, payee: operator, amount: 50 SAR, cap: 300 SAR, period: 1d, grace: 1d\n rename { dueAt: returnBy }\n expose create as start_late_fees\n expose stop as record_return\n expose waive as waive_late_fees\n expose reschedule as change_return\n }\n}\n"},
|
|
5
5
|
{"id":"cards","title":"Boston catering cards","summary":"Boston catering cards lets staff reserve supplier purchases up to 5,000 SAR each. Supplier cancellation releases the reservation; captured purchases support a full refund or a reviewed dispute.","headers":["cards"],"source":"// Boston catering cards lets staff reserve supplier purchases up to 5,000 SAR each.\n// Supplier cancellation releases the reservation; captured purchases support a full refund or a reviewed dispute.\nprogram team_expense_cards \"Boston catering cards\"\nuse cards\nparty supplier: business\n\n// Bind supplier to the food wholesaler. Staff customers own their card records.\n// Card fee: 0%, tax: 0% on card access because the caterer charges staff nothing.\n// A supplier invoice might be 2,000 SAR plus 15% VAT, paid as one 2,300 SAR\n// authorization. cards does not calculate or remit the supplier's invoice VAT.\nobject employee \"Catering expense card\" {\n fields { employeeName: text, department: text }\n columns: [employeeName, department]\n attach holder = cards.cardholder {\n holder: owner\n expose create as enrol_employee\n expose activate as activate_employee\n expose suspend as suspend_employee\n expose resume as restore_employee\n expose close as close_employee_access\n expose operator_close as remove_employee_access\n }\n attach card = cards.card {\n holder: holder, person: owner, issuer: operator, spend_limit: 5000 SAR\n expose create as issue_card\n expose activate as activate_card\n expose freeze as freeze_lost_card\n expose unfreeze as restore_found_card\n expose issuer_freeze as block_card\n expose issuer_unfreeze as unblock_card\n expose cancel as cancel_card\n expose issuer_cancel as retire_employee_card\n }\n // Supply the gross invoice amount and expiresAt, such as 24 hours after\n // ordering. Pending and approved authorizations expire without capture.\n attach payment = cards.authorization {\n card: card, merchant: supplier, issuer: operator\n expose create as request_supplier_payment\n expose approve as approve_payment\n expose decline as decline_payment\n expose capture as capture_delivered_order\n expose reverse as cancel_supplier_reservation\n }\n attach receipt = cards.transaction {\n authorization: payment\n expose create as record_captured_purchase\n expose refund as refund_supplier_purchase\n }\n attach complaint = cards.dispute {\n transaction: receipt, issuer: operator, within: 30d\n expose create as dispute_supplier_purchase\n expose review as review_purchase_dispute\n expose win as uphold_dispute_and_refund\n }\n // A dispute unresolved after 30 days becomes lost. A refund always needs\n // the supplier's funds; the card header does not prove card-network settlement.\n}\n"},
|
|
6
6
|
{"id":"collections","title":"Portland cafe equipment finance","summary":"Portland cafe equipment finance lends 24,000 SAR over 12 months and refers debt seven days overdue. Its agency earns 10% of each recovery from the lender, with at most four contacts per 30 days.","headers":["collections","financing"],"source":"// Portland cafe equipment finance lends 24,000 SAR over 12 months and refers debt seven days overdue.\n// Its agency earns 10% of each recovery from the lender, with at most four contacts per 30 days.\nprogram business_collections \"Portland cafe equipment finance\"\nuse collections\nuse financing\nparty agency: business\n\n// Bind agency to the collector. The cafe owns the facility. Set price to\n// 24,000 SAR: 6% flat profit is 1,440 SAR, repaid in twelve 2,120 SAR payments.\n// Loan fee: 0%, tax: 0% on principal. The agency invoices 15% VAT on its\n// recovery service outside collections.case, which posts only the 10% fee.\nobject facility \"Cafe equipment facility\" {\n fields { businessName: text, purpose: text, price: money }\n columns: [businessName, purpose, price]\n attach allowance = financing.limits {\n borrower: owner, per_borrower: 100000 SAR\n expose create as request_borrower_limit\n expose approve as approve_borrower\n }\n attach budget = financing.portfolio_limit {\n limit: 2000000 SAR\n expose create as create_lending_budget\n expose approve as approve_budget\n }\n // Approve both limits and provide twelve future due dates before disbursement.\n attach loan = financing.installments {\n borrower: owner, capital: operator, share: 0%\n months: 12, pricing: flat_total, profit_rate: 6%, disburse_to: borrower\n payoff_rebate: 100%, refund_within: 30d, write_off_after: 90d\n limits: allowance, portfolio: budget\n expose create as quote_equipment_loan\n expose sign as sign_loan\n expose disburse as release_loan\n expose cancel as decline_loan_quote\n expose void as cancel_unfunded_loan\n expose payoff as repay_early\n expose complete as close_repaid_loan\n }\n // Select matching plan, overdue slice and pending payment when opening.\n // Recovery pays that payment, not necessarily the whole remaining debt.\n attach recovery = collections.case {\n on: loan, agency: agency, capital: operator, overdue: 7d, fee: 10%\n expose create as refer_overdue_instalment\n expose assign as assign_agency\n expose recover as collect_referred_payment\n expose recall as recall_collection_case\n expose return_uncollected as return_uncollected_case\n }\n attach contact = collections.contact {\n case: recovery, agency: agency\n max_contacts: 4, window: 30d, contact_from: 9, contact_until: 18\n timezone: \"Asia/Riyadh\"\n expose create as record_collection_contact\n }\n}\n\nexpose facility.contact.outcome.create as record_contact_outcome\nexpose facility.loan.payment.create as record_repayment\nexpose facility.loan.payment.pay as pay_instalment\nexpose facility.loan.payment.refund as refund_mistaken_repayment\nexpose facility.loan.payoff_quote.create as request_payoff_quote\n// A disputed contact can be recorded, then capital can recall the case.\n// Uncollectible principal needs a separate capital decision after 90 days.\nexpose facility.loan.write_off_request.create as request_overdue_write_off\nexpose facility.loan.write_off_request.apply as approve_overdue_write_off\nexpose facility.loan.write_off_request.cancel as cancel_write_off_request\n"},
|
|
7
7
|
{"id":"escrow","title":"Seattle used laptops","summary":"Seattle used laptops holds a buyer's 2,300 SAR until the laptop arrives and passes inspection. Delivery has seven days; the buyer has 48 hours to accept or dispute before the operator reviews the sale.","headers":["escrow"],"source":"// Seattle used laptops holds a buyer's 2,300 SAR until the laptop arrives and passes inspection.\n// Delivery has seven days; the buyer has 48 hours to accept or dispute before the operator reviews the sale.\nprogram used_device_sales \"Seattle used laptops\"\nuse escrow\nparty seller: business\n\n// Bind seller to the refurbisher. Set price to the agreed gross invoice, for\n// example 2,300 SAR. The company keeps 5%, 115 SAR, plus 15% VAT on that fee.\n// Seller receives 2,167.75 SAR. Any VAT on the laptop is on the seller's invoice.\nobject device \"Laptop purchase\" {\n fields { model: text, condition: text, serialNumber: text, price: money }\n columns: [model, condition, serialNumber, price]\n attach sale = escrow.hold {\n payer: owner, payee: seller\n fee: { seller: 5%, tax: 15% }\n deliver_within: 7d, accept_within: 48h\n dispute: { refund_after: return_verified }\n expose create as agree_purchase\n expose fund as pay_for_laptop\n expose deliver as confirm_delivery\n expose accept as accept_laptop\n expose dispute as report_problem\n expose verify_return as verify_returned_laptop\n expose refund as refund_buyer\n expose refund_undelivered as refund_missing_delivery\n expose settle_release as resolve_in_seller_favour\n expose settle_return as resolve_in_buyer_favour\n expose settle_refund as finish_buyer_refund\n expose cancel as cancel_unpaid_purchase\n }\n}\n"},
|
package/src/headers.ts
CHANGED
|
@@ -83,7 +83,12 @@ export function headerManifest(
|
|
|
83
83
|
? { values: type.args.map(spelling) }
|
|
84
84
|
: {}),
|
|
85
85
|
...tunableBounds(type),
|
|
86
|
-
required:
|
|
86
|
+
required:
|
|
87
|
+
!fallback &&
|
|
88
|
+
!(
|
|
89
|
+
(type.kind === "type" || type.kind === "call") &&
|
|
90
|
+
type.optional
|
|
91
|
+
),
|
|
87
92
|
...(fallback ? { default: spelling(fallback) } : {}),
|
|
88
93
|
};
|
|
89
94
|
});
|
package/src/language.ts
CHANGED
package/src/parse.ts
CHANGED
|
@@ -255,6 +255,13 @@ class Parser {
|
|
|
255
255
|
}
|
|
256
256
|
if (this.eat("expose")) {
|
|
257
257
|
const action = this.identifier();
|
|
258
|
+
// r340: the Architect wrote expose occurrence.pay seven times against
|
|
259
|
+
// a bare "expected a name" and never found the program-level form.
|
|
260
|
+
if (this.at("."))
|
|
261
|
+
this.fail(
|
|
262
|
+
`expose inside an attachment takes one of its own actions, not ${action}.<action>`,
|
|
263
|
+
`delete this line, or expose a caller action of ${action} at program level: expose <object>.<attachment>.${action}.<action> as <name>`,
|
|
264
|
+
);
|
|
258
265
|
let publicName = action;
|
|
259
266
|
if (this.eat("as")) {
|
|
260
267
|
publicName = this.identifier();
|
|
@@ -557,7 +564,15 @@ class Parser {
|
|
|
557
564
|
args.push(this.expression());
|
|
558
565
|
this.separators();
|
|
559
566
|
}
|
|
560
|
-
|
|
567
|
+
// `integer(1, 366)?` keeps its bounds and may stay unset.
|
|
568
|
+
const optional = this.eat("?");
|
|
569
|
+
return {
|
|
570
|
+
kind: "call",
|
|
571
|
+
name,
|
|
572
|
+
args,
|
|
573
|
+
...(optional ? { optional } : {}),
|
|
574
|
+
span: this.span(start),
|
|
575
|
+
};
|
|
561
576
|
}
|
|
562
577
|
let target: string | undefined;
|
|
563
578
|
let owner: string | undefined;
|