@hyperscale0/hsx 1.0.128 → 1.0.130
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/cli.js +1 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +96 -10
- package/dist/src/compile.js.map +1 -1
- package/dist/src/examples-bundle.js +3 -3
- package/dist/src/examples-bundle.js.map +1 -1
- package/dist/src/parse.js +4 -1
- package/dist/src/parse.js.map +1 -1
- package/dist/src/std-bundle.js +5 -5
- package/dist/src/std-bundle.js.map +1 -1
- package/docs/README.md +45 -20
- package/examples/cards.hsx +4 -0
- package/examples/collections.hsx +4 -0
- package/examples/cost-table.json +80 -56
- package/examples/insurance.hsx +2 -1
- package/package.json +4 -4
- package/src/cli.ts +1 -1
- package/src/compile.ts +146 -10
- package/src/examples-bundle.ts +3 -3
- package/src/parse.ts +4 -1
- package/src/std-bundle.ts +5 -5
- package/std/booking.hsx +1 -1
- package/std/cards.hsx +5 -3
- package/std/escrow.hsx +18 -9
- package/std/financing.hsx +81 -16
- package/std/wallet.hsx +3 -3
package/src/compile.ts
CHANGED
|
@@ -1039,6 +1039,29 @@ export function compile(
|
|
|
1039
1039
|
(!!attachmentInfo &&
|
|
1040
1040
|
subjectPartyRoles.includes(name as SubjectPartyRole));
|
|
1041
1041
|
const resolvedParties = new Set<string>();
|
|
1042
|
+
// A party of a sibling attachment this one references, such as the
|
|
1043
|
+
// borrower of `self.plan`, binds here the way it binds there.
|
|
1044
|
+
const reachedParty = (
|
|
1045
|
+
name: string,
|
|
1046
|
+
): AttachmentPartyBinding | undefined => {
|
|
1047
|
+
if (!attachmentInfo) return;
|
|
1048
|
+
const targets = fields.flatMap((field) =>
|
|
1049
|
+
field.type === "ref" && field.targetKind === "instrument"
|
|
1050
|
+
? [field.target].flat()
|
|
1051
|
+
: [],
|
|
1052
|
+
);
|
|
1053
|
+
const bindings = attachmentInfo.attachments.flatMap((attachment) =>
|
|
1054
|
+
targets.some(
|
|
1055
|
+
(target) =>
|
|
1056
|
+
target === attachment.instrument ||
|
|
1057
|
+
target.startsWith(`${attachment.instrument}_`),
|
|
1058
|
+
) && attachment.parties[name]
|
|
1059
|
+
? [attachment.parties[name]]
|
|
1060
|
+
: [],
|
|
1061
|
+
);
|
|
1062
|
+
const distinct = new Set(bindings.map((item) => JSON.stringify(item)));
|
|
1063
|
+
return distinct.size === 1 ? bindings[0] : undefined;
|
|
1064
|
+
};
|
|
1042
1065
|
const resolve = (
|
|
1043
1066
|
expr: Expr,
|
|
1044
1067
|
seen = new Set<string>(),
|
|
@@ -1098,6 +1121,18 @@ export function compile(
|
|
|
1098
1121
|
attachmentSubjects.has(name)
|
|
1099
1122
|
? name.slice(attachmentInfo.subjectKindId.length + 1)
|
|
1100
1123
|
: `${name} (program)`;
|
|
1124
|
+
const elsewhere = [...assignments.values()]
|
|
1125
|
+
.filter(
|
|
1126
|
+
(assignment) =>
|
|
1127
|
+
assignment.target === type &&
|
|
1128
|
+
attachmentSubjects.has(assignment.name) &&
|
|
1129
|
+
attachmentSubjects.get(assignment.name) !==
|
|
1130
|
+
attachmentInfo.subjectKindId,
|
|
1131
|
+
)
|
|
1132
|
+
.map((assignment) => {
|
|
1133
|
+
const subject = attachmentSubjects.get(assignment.name)!;
|
|
1134
|
+
return `\`${subject}.${assignment.name.slice(subject.length + 1)}\``;
|
|
1135
|
+
});
|
|
1101
1136
|
const target = templates.get(type);
|
|
1102
1137
|
const required =
|
|
1103
1138
|
target?.parameters
|
|
@@ -1116,7 +1151,7 @@ export function compile(
|
|
|
1116
1151
|
}`,
|
|
1117
1152
|
matches.length
|
|
1118
1153
|
? `Bind \`${parameter}\` explicitly to one of: ${matches.map(local).join(", ")}.`
|
|
1119
|
-
: `
|
|
1154
|
+
: `Attach \`${type}\` to \`${attachmentInfo.subjectKindId}\` and bind \`${parameter}\` to that attachment's name. Choose ${required.map((name) => (name.startsWith("per_") ? `its ${name.slice(4).replaceAll("_", " ")} limit` : `\`${name}\``)).join(", ") || "its required bindings"} explicitly.${elsewhere.length ? ` ${elsewhere.join(", ")} ${elsewhere.length === 1 ? "is" : "are"} on another object, which this binding cannot reach.` : ""}`,
|
|
1120
1155
|
);
|
|
1121
1156
|
}
|
|
1122
1157
|
if (expr.name !== "all" && matches.length !== 1)
|
|
@@ -1555,6 +1590,28 @@ export function compile(
|
|
|
1555
1590
|
value: `${id}_${key}`,
|
|
1556
1591
|
span: origin,
|
|
1557
1592
|
});
|
|
1593
|
+
// A subject role only has money here when this attachment binds it.
|
|
1594
|
+
const moneyPath = (expr: Expr): string => {
|
|
1595
|
+
const lowered = path(expr);
|
|
1596
|
+
const role = lowered.slice("party.".length) as SubjectPartyRole;
|
|
1597
|
+
if (
|
|
1598
|
+
attachmentInfo &&
|
|
1599
|
+
lowered.startsWith("party.") &&
|
|
1600
|
+
subjectPartyRoles.includes(role) &&
|
|
1601
|
+
!Object.values(attachmentInfo.parties).some(
|
|
1602
|
+
(binding) => "role" in binding && binding.role === role,
|
|
1603
|
+
)
|
|
1604
|
+
)
|
|
1605
|
+
failWithCode(
|
|
1606
|
+
expr,
|
|
1607
|
+
"subject_party_unbound",
|
|
1608
|
+
`\`${role}\` has no money account in \`${decl.name}\``,
|
|
1609
|
+
role === "operator"
|
|
1610
|
+
? "Use `programOperator` for the company's own account."
|
|
1611
|
+
: `Add a party parameter to \`${decl.name}\` and bind it to \`${role}\` where you attach it.`,
|
|
1612
|
+
);
|
|
1613
|
+
return lowered;
|
|
1614
|
+
};
|
|
1558
1615
|
const fields: UdlField[] = [];
|
|
1559
1616
|
const calculations: UdlCalculation[] = [];
|
|
1560
1617
|
let currentAction: UdlAction | undefined;
|
|
@@ -2472,9 +2529,18 @@ export function compile(
|
|
|
2472
2529
|
`unknown economic purpose ${purposeName}`,
|
|
2473
2530
|
"choose a declared economic purpose",
|
|
2474
2531
|
);
|
|
2475
|
-
|
|
2532
|
+
let sourcePartyName = sourceParty
|
|
2476
2533
|
? String(data(sourceParty))
|
|
2477
2534
|
: undefined;
|
|
2535
|
+
const reached =
|
|
2536
|
+
sourcePartyName && !isParty(sourcePartyName)
|
|
2537
|
+
? reachedParty(sourcePartyName)
|
|
2538
|
+
: undefined;
|
|
2539
|
+
if (reached) {
|
|
2540
|
+
attachmentInfo!.parties[sourcePartyName!] = reached;
|
|
2541
|
+
sourcePartyName =
|
|
2542
|
+
"role" in reached ? reached.role : reached.party;
|
|
2543
|
+
}
|
|
2478
2544
|
if (sourcePartyName && !isParty(sourcePartyName))
|
|
2479
2545
|
fail(
|
|
2480
2546
|
sourceParty!,
|
|
@@ -2608,7 +2674,7 @@ export function compile(
|
|
|
2608
2674
|
operation: "internal_transfer.create",
|
|
2609
2675
|
...(economics ? { economics } : {}),
|
|
2610
2676
|
amount: piece,
|
|
2611
|
-
from:
|
|
2677
|
+
from: moneyPath(from),
|
|
2612
2678
|
to: `party.${recipient.value}`,
|
|
2613
2679
|
});
|
|
2614
2680
|
}
|
|
@@ -2636,8 +2702,8 @@ export function compile(
|
|
|
2636
2702
|
? { capture: String(data(parts.get("capture")!)) }
|
|
2637
2703
|
: {}),
|
|
2638
2704
|
amount: val(amount!),
|
|
2639
|
-
from:
|
|
2640
|
-
to:
|
|
2705
|
+
from: moneyPath(from!),
|
|
2706
|
+
to: moneyPath(to!),
|
|
2641
2707
|
};
|
|
2642
2708
|
const fee = parts.get("fee");
|
|
2643
2709
|
if (!fee)
|
|
@@ -2909,6 +2975,26 @@ export function compile(
|
|
|
2909
2975
|
message: `${id}.${name}.subject.${requirement.field.name}`,
|
|
2910
2976
|
});
|
|
2911
2977
|
}
|
|
2978
|
+
// A parent actor over an empty all() names no instrument that could
|
|
2979
|
+
// invoke the action. A std action then does not exist in this program;
|
|
2980
|
+
// in user code the all() is a mistake.
|
|
2981
|
+
if (
|
|
2982
|
+
typeof a.actor === "object" &&
|
|
2983
|
+
"parent" in a.actor &&
|
|
2984
|
+
Array.isArray(a.actor.parent) &&
|
|
2985
|
+
!a.actor.parent.length
|
|
2986
|
+
) {
|
|
2987
|
+
if ((declarationSources.get(decl) ?? "program") === "program") {
|
|
2988
|
+
const parent = entries(asBlock(slots.get("actor"))).get("parent");
|
|
2989
|
+
fail(
|
|
2990
|
+
parent ?? row,
|
|
2991
|
+
`${parent?.kind === "call" ? `${parent.name}(${text(parent.args[0]!)})` : `the parent actor of ${name}`} matches no instrument`,
|
|
2992
|
+
"name an instrument this program declares or attaches",
|
|
2993
|
+
);
|
|
2994
|
+
}
|
|
2995
|
+
delete lifecycle.transitions[name];
|
|
2996
|
+
continue;
|
|
2997
|
+
}
|
|
2912
2998
|
inst.actions[name] = a;
|
|
2913
2999
|
inst.actionOrder.push(name);
|
|
2914
3000
|
}
|
|
@@ -3746,7 +3832,7 @@ export function compile(
|
|
|
3746
3832
|
// A family member drops an optional reference field its binding left
|
|
3747
3833
|
// unset (a borrower-funded plan has no `funds`), so it cannot match and
|
|
3748
3834
|
// leaves the selection. The header must still declare the field.
|
|
3749
|
-
const
|
|
3835
|
+
const declaredMembers = (selection: UdlSelection) => {
|
|
3750
3836
|
const members = [selection.instrument].flat();
|
|
3751
3837
|
const header = selection.family
|
|
3752
3838
|
? templates.get(
|
|
@@ -3764,13 +3850,52 @@ export function compile(
|
|
|
3764
3850
|
resolveField(document, byId.get(id)!, `self.${selection.reference}`),
|
|
3765
3851
|
);
|
|
3766
3852
|
};
|
|
3853
|
+
// A member whose reference points at another attachment of the anchor's
|
|
3854
|
+
// own template (the plan funding another object's escrow) cannot match
|
|
3855
|
+
// either, so each object only selects what can reference it.
|
|
3856
|
+
const kin = (a: string, b: string) => {
|
|
3857
|
+
const left = byId.get(a);
|
|
3858
|
+
const right = byId.get(b);
|
|
3859
|
+
return (
|
|
3860
|
+
!!left && !!right && declarations.get(left) === declarations.get(right)
|
|
3861
|
+
);
|
|
3862
|
+
};
|
|
3863
|
+
const matchable = (
|
|
3864
|
+
selection: UdlSelection,
|
|
3865
|
+
inst: UdlInstrument,
|
|
3866
|
+
action?: UdlAction,
|
|
3867
|
+
) =>
|
|
3868
|
+
declaredMembers(selection).filter((id) => {
|
|
3869
|
+
const member = byId.get(id);
|
|
3870
|
+
if (!member) return true;
|
|
3871
|
+
const anchor = resolveField(
|
|
3872
|
+
document,
|
|
3873
|
+
inst,
|
|
3874
|
+
selection.anchor,
|
|
3875
|
+
action?.input,
|
|
3876
|
+
action,
|
|
3877
|
+
);
|
|
3878
|
+
const reference = resolveField(
|
|
3879
|
+
document,
|
|
3880
|
+
member,
|
|
3881
|
+
`self.${selection.reference}`,
|
|
3882
|
+
);
|
|
3883
|
+
if (anchor?.type !== "ref" || reference?.type !== "ref") return true;
|
|
3884
|
+
const targets = [anchor.target].flat();
|
|
3885
|
+
const candidates = [reference.target].flat();
|
|
3886
|
+
return !candidates.every(
|
|
3887
|
+
(candidate) =>
|
|
3888
|
+
!targets.includes(candidate) &&
|
|
3889
|
+
targets.some((target) => kin(target, candidate)),
|
|
3890
|
+
);
|
|
3891
|
+
});
|
|
3767
3892
|
// A count over no matchable member is zero.
|
|
3768
3893
|
for (const inst of document.instruments)
|
|
3769
3894
|
for (const action of Object.values(inst.actions))
|
|
3770
3895
|
action.requires = action.requires.map((requirement) =>
|
|
3771
3896
|
requirement.kind === "aggregate" &&
|
|
3772
3897
|
requirement.measure === "count" &&
|
|
3773
|
-
!matchable(requirement.selection).length
|
|
3898
|
+
!matchable(requirement.selection, inst, action).length
|
|
3774
3899
|
? {
|
|
3775
3900
|
kind: "compare",
|
|
3776
3901
|
left: { literal: 0 },
|
|
@@ -3784,9 +3909,15 @@ export function compile(
|
|
|
3784
3909
|
at: Located,
|
|
3785
3910
|
scope: Scope,
|
|
3786
3911
|
) => {
|
|
3912
|
+
walk(
|
|
3913
|
+
selection.overlaps,
|
|
3914
|
+
"overlaps",
|
|
3915
|
+
site(selection, "overlaps", at),
|
|
3916
|
+
scope,
|
|
3917
|
+
);
|
|
3787
3918
|
walk(selection.anchor, "anchor", site(selection, "anchor", at), scope);
|
|
3788
3919
|
walk(selection.where, "where", site(selection, "where", at), scope);
|
|
3789
|
-
const members = matchable(selection);
|
|
3920
|
+
const members = matchable(selection, scope.inst, scope.action);
|
|
3790
3921
|
if (
|
|
3791
3922
|
members.length &&
|
|
3792
3923
|
members.length < [selection.instrument].flat().length
|
|
@@ -3807,6 +3938,9 @@ export function compile(
|
|
|
3807
3938
|
selection.order?.forEach((key, index) =>
|
|
3808
3939
|
member(key, site(selection.order!, index, at)),
|
|
3809
3940
|
);
|
|
3941
|
+
if (selection.overlaps)
|
|
3942
|
+
for (const key of ["start", "end"] as const)
|
|
3943
|
+
member(selection.overlaps[key], site(selection.overlaps, key, at));
|
|
3810
3944
|
if (selection.window)
|
|
3811
3945
|
member(selection.window.field, site(selection.window, "field", at));
|
|
3812
3946
|
}
|
|
@@ -4112,13 +4246,15 @@ export function compile(
|
|
|
4112
4246
|
),
|
|
4113
4247
|
),
|
|
4114
4248
|
);
|
|
4249
|
+
const reaching = stranded.actions.at(-1);
|
|
4250
|
+
const drain = `move ${stranded.accounts.map((account) => `\`self.${account}.balance\``).join(" and ")} out in ${reaching ? `\`${reaching}\`` : "the action that reaches it"}, or add an action from \`${stranded.state}\` that does`;
|
|
4115
4251
|
return diagnostic(
|
|
4116
4252
|
{
|
|
4117
4253
|
code: i.code,
|
|
4118
4254
|
message: `\`${attachment?.name ?? instrument.id}\` can reach \`${stranded.state}\` with money in ${stranded.accounts.map((account) => `\`${account}\``).join(", ")}, but no action leaves that state and disposes of the balance.`,
|
|
4119
4255
|
fix: binding
|
|
4120
|
-
? `Restore \`${binding.parameter}: ${stranded.state}\`, or
|
|
4121
|
-
:
|
|
4256
|
+
? `Restore \`${binding.parameter}: ${stranded.state}\`, or ${drain}.`
|
|
4257
|
+
: `${drain[0]!.toUpperCase()}${drain.slice(1)}.`,
|
|
4122
4258
|
span: binding?.span ?? origin?.span ?? program.span,
|
|
4123
4259
|
related: stranded.accounts.map((account) => ({
|
|
4124
4260
|
source: "program",
|
package/src/examples-bundle.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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":"cards","title":"Team expense cards","summary":"A company issues expense cards to employees and reserves each supplier payment before capture.","headers":["cards"],"source":"// A company issues expense cards to employees and reserves each supplier payment before capture.\nprogram team_expense_cards \"Team expense cards\"\nuse cards\nparty supplier: business\n\nobject employee \"Employee card\" {\n fields { employeeName: text, department: text }\n columns: [employeeName, department]\n attach holder = cards.cardholder {\n expose create as create_holder\n holder: owner\n expose activate as activate_employee\n expose suspend as suspend_employee\n }\n attach card = cards.card {\n expose create as create_card\n holder: holder, spend_limit: 5000 SAR\n expose activate as activate_card\n expose freeze as freeze_card\n expose unfreeze as unfreeze_card\n }\n attach payment = cards.authorization {\n expose create as create_payment\n card: card, merchant: supplier\n expose approve as approve_payment\n expose capture as capture_payment\n expose reverse as reverse_payment\n }\n attach receipt = cards.transaction {\n expose create as create_receipt\n authorization: payment\n expose refund as refund_payment\n }\n}\n"},
|
|
5
|
-
{"id":"collections","title":"Small business collections","summary":"A business lender refers overdue instalments to an agency with limits on collection contacts.","headers":["collections","financing"],"source":"// A business lender refers overdue instalments to an agency with limits on collection contacts.\nprogram business_collections \"Small business collections\"\nuse collections\nuse financing\nparty agency: business\n\nobject facility \"Business loan\" {\n fields { businessName: text, purpose: text, price: money }\n columns: [businessName, purpose, price]\n attach allowance = financing.limits { expose create as create_allowance, expose approve as approve_borrower, borrower: owner, per_borrower: 100000 SAR }\n attach budget = financing.portfolio_limit { expose create as create_budget, expose approve as approve_budget, limit: 2000000 SAR }\n attach loan = financing.installments {\n expose create as create_loan\n borrower: owner, capital: operator\n months: 12, pricing: amortizing, profit_rate: 6%, disburse_to: borrower\n limits: allowance, portfolio: budget\n expose sign as sign_loan\n expose disburse as release_loan\n expose payoff as repay_early\n }\n attach recovery = collections.case {\n expose create as create_recovery\n on: loan, agency: agency\n expose assign as assign_case\n expose recover as recover_payment\n expose recall as recall_case\n }\n attach contact = collections.contact {\n expose create as create_contact\n case: recovery, agency: agency\n }\n}\n\nexpose facility.loan.payment.create as create_payment\nexpose facility.loan.payment.pay as pay_instalment\nexpose facility.loan.payment.refund as refund_payment\nexpose facility.loan.payoff_quote.create as request_payoff_quote\n"},
|
|
4
|
+
{"id":"cards","title":"Team expense cards","summary":"A company issues expense cards to employees and reserves each supplier payment before capture.","headers":["cards"],"source":"// A company issues expense cards to employees and reserves each supplier payment before capture.\nprogram team_expense_cards \"Team expense cards\"\nuse cards\n// supplier is a business this program declares, so plan needs {\"partyBindings\":{\"supplier\":\"<partyId>\"}}.\n// That partyId is an organization customer's: create the Product from this source without the payment\n// and receipt attachments, add the customer with customer.create, activate its access, open its\n// customer_balance account, then compose this source with the binding.\nparty supplier: business\n\nobject employee \"Employee card\" {\n fields { employeeName: text, department: text }\n columns: [employeeName, department]\n attach holder = cards.cardholder {\n expose create as create_holder\n holder: owner\n expose activate as activate_employee\n expose suspend as suspend_employee\n }\n attach card = cards.card {\n expose create as create_card\n holder: holder, spend_limit: 5000 SAR\n expose activate as activate_card\n expose freeze as freeze_card\n expose unfreeze as unfreeze_card\n }\n attach payment = cards.authorization {\n expose create as create_payment\n card: card, merchant: supplier\n expose approve as approve_payment\n expose capture as capture_payment\n expose reverse as reverse_payment\n }\n attach receipt = cards.transaction {\n expose create as create_receipt\n authorization: payment\n expose refund as refund_payment\n }\n}\n"},
|
|
5
|
+
{"id":"collections","title":"Small business collections","summary":"A business lender refers overdue instalments to an agency with limits on collection contacts.","headers":["collections","financing"],"source":"// A business lender refers overdue instalments to an agency with limits on collection contacts.\nprogram business_collections \"Small business collections\"\nuse collections\nuse financing\n// agency is a business this program declares, so plan needs {\"partyBindings\":{\"agency\":\"<partyId>\"}}.\n// That partyId is an organization customer's: create the Product from this source without the recovery\n// and contact attachments, add the customer with customer.create, activate its access, open its\n// customer_balance account, then compose this source with the binding.\nparty agency: business\n\nobject facility \"Business loan\" {\n fields { businessName: text, purpose: text, price: money }\n columns: [businessName, purpose, price]\n attach allowance = financing.limits { expose create as create_allowance, expose approve as approve_borrower, borrower: owner, per_borrower: 100000 SAR }\n attach budget = financing.portfolio_limit { expose create as create_budget, expose approve as approve_budget, limit: 2000000 SAR }\n attach loan = financing.installments {\n expose create as create_loan\n borrower: owner, capital: operator\n months: 12, pricing: amortizing, profit_rate: 6%, disburse_to: borrower\n limits: allowance, portfolio: budget\n expose sign as sign_loan\n expose disburse as release_loan\n expose payoff as repay_early\n }\n attach recovery = collections.case {\n expose create as create_recovery\n on: loan, agency: agency\n expose assign as assign_case\n expose recover as recover_payment\n expose recall as recall_case\n }\n attach contact = collections.contact {\n expose create as create_contact\n case: recovery, agency: agency\n }\n}\n\nexpose facility.loan.payment.create as create_payment\nexpose facility.loan.payment.pay as pay_instalment\nexpose facility.loan.payment.refund as refund_payment\nexpose facility.loan.payoff_quote.create as request_payoff_quote\n"},
|
|
6
6
|
{"id":"escrow","title":"Used device sales","summary":"Buyers fund a used device purchase, then accept delivery or raise a dispute before release.","headers":["escrow"],"source":"// Buyers fund a used device purchase, then accept delivery or raise a dispute before release.\nprogram used_device_sales \"Used device sales\"\nuse escrow\n\nobject device \"Device\" {\n fields {\n model: text\n condition: text\n serialNumber: text\n price: money\n }\n columns: [model, condition, price]\n attach sale = escrow.hold {\n expose create as create_sale\n payer: actor, payee: owner\n expose fund as pay_for_device\n expose deliver as confirm_delivery\n expose accept as accept_device\n expose dispute as report_problem\n expose verify_return as verify_return\n expose refund as refund_buyer\n expose cancel as cancel_sale\n }\n}\n"},
|
|
7
7
|
{"id":"financing","title":"Tuition instalments","summary":"A tuition lender funds a student's fees over three interest-free instalments with borrowing limits.","headers":["financing"],"source":"// A tuition lender funds a student's fees over three interest-free instalments with borrowing limits.\nprogram tuition_instalments \"Tuition instalments\"\nuse financing\n\nobject enrolment \"Enrolment\" {\n fields { student: text, course: text, price: money }\n columns: [student, course, price]\n attach allowance = financing.limits {\n expose create as create_allowance\n borrower: owner, per_borrower: 12000 SAR\n expose approve as approve_student\n }\n attach budget = financing.portfolio_limit {\n expose create as create_budget\n limit: 500000 SAR\n expose approve as approve_budget\n }\n attach tuition = financing.installments {\n expose create as create_tuition\n borrower: owner, capital: operator\n months: 3, pricing: flat_total, profit_rate: 0%, disburse_to: borrower\n limits: allowance, portfolio: budget\n expose sign as sign_tuition_plan\n expose disburse as fund_tuition\n expose payoff as repay_early\n }\n}\n\nexpose enrolment.tuition.payment.create as create_payment\nexpose enrolment.tuition.payment.pay as pay_instalment\nexpose enrolment.tuition.payment.refund as refund_payment\nexpose enrolment.tuition.payoff_quote.create as request_payoff_quote\n"},
|
|
8
|
-
{"id":"insurance","title":"Device insurance","summary":"A device retailer collects the purchase price and attaches cover with a claim review process.","headers":["insurance","money"],"source":"// A device retailer collects the purchase price and attaches cover with a claim review process.\nprogram device_insurance \"Device insurance\"\nuse insurance\nuse money\n\nobject device \"Insured device\" {\n fields { model: text, serialNumber: text, purchaseDate: date }\n columns: [model, serialNumber, purchaseDate]\n attach purchase = money.transfer {\n expose create as create_purchase\n payer: owner, payee: operator\n economics pay { purpose: earning, sourceParty: owner }\n expose pay as pay_for_device\n }\n // conformance_boundary is the sandbox insurer adapter; swap in the insurer's registered adapter to go live.\n // Premiums net of commission go to its account. claim_limit is the sum insured, set per cover at creation.\n attach protection = insurance.cover {\n expose create as create_protection\n holder: owner, adapter: \"conformance_boundary\", commission: 10%, covers: purchase\n expose activate as activate_cover\n expose cancel as cancel_cover\n }\n attach claim = insurance.claim {\n expose create as create_claim\n cover: protection, inspector: operator\n expose approve as approve_claim\n expose deny as deny_claim\n expose pay as pay_claim\n }\n}\n"},
|
|
8
|
+
{"id":"insurance","title":"Device insurance","summary":"A device retailer collects the purchase price and attaches cover with a claim review process.","headers":["insurance","money"],"source":"// A device retailer collects the purchase price and attaches cover with a claim review process.\nprogram device_insurance \"Device insurance\"\nuse insurance\nuse money\n\nobject device \"Insured device\" {\n fields { model: text, serialNumber: text, purchaseDate: date }\n columns: [model, serialNumber, purchaseDate]\n attach purchase = money.transfer {\n expose create as create_purchase\n payer: owner, payee: operator\n economics pay { purpose: earning, sourceParty: owner }\n expose pay as pay_for_device\n }\n // conformance_boundary is the sandbox insurer adapter; swap in the insurer's registered adapter to go live.\n // Premiums net of commission go to its account. The default broker is the retailer, which keeps the commission.\n // claim_limit is the sum insured, set per cover at creation.\n attach protection = insurance.cover {\n expose create as create_protection\n holder: owner, adapter: \"conformance_boundary\", commission: 10%, covers: purchase\n expose activate as activate_cover\n expose cancel as cancel_cover\n }\n attach claim = insurance.claim {\n expose create as create_claim\n cover: protection, inspector: operator\n expose approve as approve_claim\n expose deny as deny_claim\n expose pay as pay_claim\n }\n}\n"},
|
|
9
9
|
{"id":"lending","title":"Community business lending","summary":"A lending composition with limit approvals, wallet commitments and cash distribution transitions.","headers":["lending","financing","wallet"],"source":"// A lending composition with limit approvals, wallet commitments and cash distribution transitions.\nprogram community_business_lending \"Community business lending\"\nuse lending\nuse financing\nuse wallet\n\nobject business \"Business funding\" {\n fields { businessName: text, purpose: text, price: money }\n columns: [businessName, purpose, price]\n attach allowance = financing.limits {\n expose create as create_allowance\n borrower: owner, per_borrower: 100000 SAR\n expose approve as approve_borrower\n }\n attach budget = financing.portfolio_limit {\n expose create as create_budget\n limit: 2000000 SAR\n expose approve as approve_budget\n }\n attach loan = financing.installments {\n expose create as create_loan\n borrower: owner, capital: operator\n months: 12, pricing: amortizing, profit_rate: 6%, disburse_to: borrower\n limits: allowance, portfolio: budget\n expose sign as sign_loan\n expose disburse as release_loan\n expose payoff as repay_early\n }\n attach investor_balance = wallet.balance {\n expose create as create_investor_balance\n holder: actor\n expose activate as open_wallet\n expose topup as add_funds\n }\n attach funding = lending.round {\n borrower: owner, plan: loan\n expose create as open_funding\n expose close as close_funding\n }\n attach investment = lending.commitment {\n round: funding, wallet: investor_balance, investor: actor\n expose create as invest\n expose withdraw as withdraw_investment\n }\n attach returns = lending.distribution {\n expose create as create_returns\n round: funding, receipt: loan.settlement\n expose prepare_cash as prepare_returns\n expose distribute_cash as distribute_returns\n }\n}\n\nexpose business.loan.payment.create as create_payment\nexpose business.loan.payment.pay as pay_instalment\nexpose business.loan.payment.refund as refund_payment\nexpose business.loan.payoff_quote.create as request_payoff_quote\nexpose business.returns.share.create as create_return_share\n"},
|
|
10
10
|
{"id":"library","title":"Financed car sales","summary":"A minimal financed car sale connects escrow to a three-instalment plan and lending limits.","headers":["escrow","financing"],"source":"// A minimal financed car sale connects escrow to a three-instalment plan and lending limits.\nprogram cars \"Financed car sales\"\nuse escrow\nuse financing\nobject car \"Cars\" {\n fields { make: text, model: text, year: integer }\n attach sale = escrow.hold { expose create as create_sale, payer: actor, payee: owner, expose fund as sell }\n attach limits = financing.limits { expose create as create_limits, borrower: actor, per_borrower: 60000 SAR }\n attach ceiling = financing.portfolio_limit { expose create as create_ceiling, limit: 1500000 SAR }\n attach plan = financing.installments {\n borrower: actor, capital: operator, share: 25%\n months: 3, pricing: flat_total, profit_rate: 2.5%, funds: sale, limits: limits, portfolio: ceiling\n expose create as finance\n }\n}\n"},
|
|
11
11
|
{"id":"marketplace","title":"Freelance marketplace","summary":"Freelancers publish offers and clients place orders with funds held until work is accepted.","headers":["marketplace","escrow"],"source":"// Freelancers publish offers and clients place orders with funds held until work is accepted.\nprogram freelance_marketplace \"Freelance marketplace\"\nuse marketplace\nuse escrow\n\nobject project \"Project\" {\n fields { brief: text, deliverable: text, price: money }\n columns: [brief, deliverable, price]\n attach offer = marketplace.listing {\n expose create as create_offer\n seller: owner\n expose publish as publish_offer\n expose withdraw as withdraw_offer\n }\n attach order = marketplace.order {\n expose create as create_order\n listing: offer, buyer: actor\n expose commit as place_order\n expose fulfill as finish_order\n }\n attach payment = escrow.hold {\n expose create as create_payment\n payer: actor, payee: owner\n expose fund as fund_project\n expose deliver as submit_work\n expose accept as accept_work\n expose dispute as dispute_work\n expose verify_return as verify_return\n expose refund as refund_client\n expose cancel as cancel_payment\n }\n}\n"},
|
package/src/parse.ts
CHANGED
|
@@ -471,13 +471,16 @@ class Parser {
|
|
|
471
471
|
this.fail("expression nesting exceeds 32", "reduce nested values");
|
|
472
472
|
const start = this.peek().span.start;
|
|
473
473
|
let value = this.atom();
|
|
474
|
-
|
|
474
|
+
// `cap:` starts the next entry, so a field may still be named cap.
|
|
475
|
+
if (this.at("cap") && this.tokens[this.index + 1]?.text !== ":") {
|
|
476
|
+
this.take();
|
|
475
477
|
value = {
|
|
476
478
|
kind: "capped",
|
|
477
479
|
rate: value,
|
|
478
480
|
cap: this.atom(),
|
|
479
481
|
span: this.span(start),
|
|
480
482
|
};
|
|
483
|
+
}
|
|
481
484
|
if (this.eat("="))
|
|
482
485
|
value = {
|
|
483
486
|
kind: "default",
|