@hyperscale0/hsx 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AUTHORS +8 -0
  2. package/CHANGELOG.md +59 -0
  3. package/LICENSE +661 -0
  4. package/LICENSING.md +52 -0
  5. package/README.md +170 -0
  6. package/SECURITY.md +47 -0
  7. package/TRADEMARKS.md +35 -0
  8. package/bin/hsx.ts +15 -0
  9. package/dist/bin/hsx.d.ts +7 -0
  10. package/dist/bin/hsx.d.ts.map +1 -0
  11. package/dist/bin/hsx.js +14 -0
  12. package/dist/bin/hsx.js.map +1 -0
  13. package/dist/src/ast.d.ts +172 -0
  14. package/dist/src/ast.d.ts.map +1 -0
  15. package/dist/src/ast.js +22 -0
  16. package/dist/src/ast.js.map +1 -0
  17. package/dist/src/check.d.ts +11 -0
  18. package/dist/src/check.d.ts.map +1 -0
  19. package/dist/src/check.js +1214 -0
  20. package/dist/src/check.js.map +1 -0
  21. package/dist/src/cli.d.ts +20 -0
  22. package/dist/src/cli.d.ts.map +1 -0
  23. package/dist/src/cli.js +137 -0
  24. package/dist/src/cli.js.map +1 -0
  25. package/dist/src/compile.d.ts +39 -0
  26. package/dist/src/compile.d.ts.map +1 -0
  27. package/dist/src/compile.js +59 -0
  28. package/dist/src/compile.js.map +1 -0
  29. package/dist/src/index.d.ts +9 -0
  30. package/dist/src/index.d.ts.map +1 -0
  31. package/dist/src/index.js +7 -0
  32. package/dist/src/index.js.map +1 -0
  33. package/dist/src/lex.d.ts +23 -0
  34. package/dist/src/lex.d.ts.map +1 -0
  35. package/dist/src/lex.js +125 -0
  36. package/dist/src/lex.js.map +1 -0
  37. package/dist/src/lower.d.ts +93 -0
  38. package/dist/src/lower.d.ts.map +1 -0
  39. package/dist/src/lower.js +2081 -0
  40. package/dist/src/lower.js.map +1 -0
  41. package/dist/src/model.d.ts +307 -0
  42. package/dist/src/model.d.ts.map +1 -0
  43. package/dist/src/model.js +15 -0
  44. package/dist/src/model.js.map +1 -0
  45. package/dist/src/parse.d.ts +19 -0
  46. package/dist/src/parse.d.ts.map +1 -0
  47. package/dist/src/parse.js +484 -0
  48. package/dist/src/parse.js.map +1 -0
  49. package/dist/src/version.d.ts +16 -0
  50. package/dist/src/version.d.ts.map +1 -0
  51. package/dist/src/version.js +16 -0
  52. package/dist/src/version.js.map +1 -0
  53. package/package.json +79 -0
  54. package/spec/hsx-ir.schema.json +522 -0
  55. package/src/ast.ts +231 -0
  56. package/src/check.ts +1699 -0
  57. package/src/cli.ts +173 -0
  58. package/src/compile.ts +98 -0
  59. package/src/index.ts +16 -0
  60. package/src/lex.ts +161 -0
  61. package/src/lower.ts +2619 -0
  62. package/src/model.ts +340 -0
  63. package/src/parse.ts +580 -0
  64. package/src/version.ts +17 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The lowering: checked program model -> HSX-JSON IR + congruent Business
3
+ * Frame. This is where the piece choreography the Architect used to hand-author
4
+ * is EMITTED deterministically instead.
5
+ *
6
+ * Semantics fixed here, once, for every archetype:
7
+ *
8
+ * - Fees: a payer-side fee is a service charge ON TOP of the amount, moving
9
+ * payer -> platform directly and never entering custody; a payee-side fee
10
+ * (or a premium commission) is CARVED FROM the amount at release.
11
+ * - Partitions: whenever an amount splits, it is partitioned into the finest
12
+ * common refinement of every exit, each piece its own required money field
13
+ * funded and debited under that exact name, the shape the independent
14
+ * checker's terminal-escrow analysis can prove conserving. Every partition
15
+ * is also declared on the noun, so create admission refuses pieces that do
16
+ * not sum to their total.
17
+ * - Integer minor-unit arithmetic: each piece is floor(amount * bps / 10000);
18
+ * the division remainder goes to the FIRST piece unless a split names its
19
+ * `remainder_to` recipient.
20
+ * - Schedules are finite by construction: a literal anchor count unrolls into
21
+ * one due-driven verb per anchor, each its own idempotent lifecycle step.
22
+ * - Metered usage never accrues custody: each usage charge IS the ledger
23
+ * transfer, so emission and ledger cannot diverge; the period close makes
24
+ * further charges unreachable.
25
+ * - Deposits are reservations: placed as a hold, then posted to the holder
26
+ * (claim) or voided back to the payer (return); the hold pairing law
27
+ * accounts for the full amount on both exits.
28
+ *
29
+ * The lowering never shares code with the checker that verifies its output;
30
+ * that independence is the safety argument of the whole compiler.
31
+ */
32
+ import type { Span } from "./ast.ts";
33
+ import type { CheckedProgram } from "./model.ts";
34
+ type Json = Record<string, unknown>;
35
+ /**
36
+ * The most money events one program may mint. The Business Frame contract caps
37
+ * its moneyEvents array at the same number, and a runtime spec pins the two
38
+ * against each other, so neither can drift alone. Every installment anchor,
39
+ * fee leg, cancellation leg, abandonment refund, and forward counts one.
40
+ */
41
+ export declare const MONEY_EVENT_BUDGET = 14;
42
+ interface LoweredPiece {
43
+ /** Exact width of this piece in basis points of the held amount. */
44
+ readonly bps: number;
45
+ /** Party receiving this piece when the settlement cancels; absent without a cancel policy. */
46
+ readonly cancelTo?: string;
47
+ /** The required money field carrying this piece's minor-unit amount. */
48
+ readonly field: string;
49
+ /** Source span of the term this piece derives from (fee or split share). */
50
+ readonly origin: Span;
51
+ /** Party receiving this piece when the settlement releases. */
52
+ readonly releaseTo: string;
53
+ }
54
+ interface LoweredSettlement {
55
+ readonly name: string;
56
+ readonly pieces: readonly LoweredPiece[];
57
+ /** Payer-side service fee charged on top at funding, if any. */
58
+ readonly serviceFee?: {
59
+ readonly bps: number;
60
+ readonly field: string;
61
+ };
62
+ }
63
+ interface LoweringIssue {
64
+ readonly message: string;
65
+ readonly span: Span;
66
+ }
67
+ interface LoweredProgram {
68
+ /** The HSX-JSON IR document the independent checker verifies. */
69
+ readonly document: Json;
70
+ /** The congruent Business Frame: one money event per settlement behavior
71
+ * (funding stream, per-recipient release, per-party cancel, abandonment
72
+ * refund), each covering its piece movements. */
73
+ readonly frame: Json;
74
+ readonly settlements: readonly LoweredSettlement[];
75
+ }
76
+ export type LowerResult = {
77
+ readonly issues: readonly LoweringIssue[];
78
+ readonly ok: false;
79
+ } | {
80
+ readonly ok: true;
81
+ readonly value: LoweredProgram;
82
+ };
83
+ /**
84
+ * Split a minor-unit amount across pieces by exact basis points. Floors every
85
+ * piece and gives the division remainder to the piece at `remainderIndex`
86
+ * (the first by default), so the piece amounts always sum exactly.
87
+ */
88
+ export declare function pieceAmounts(pieces: readonly {
89
+ readonly bps: number;
90
+ }[], amountMinor: bigint, remainderIndex?: number): bigint[];
91
+ export declare function lowerProgram(program: CheckedProgram): LowerResult;
92
+ export {};
93
+ //# sourceMappingURL=lower.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lower.d.ts","sourceRoot":"","sources":["../../src/lower.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,EAUV,cAAc,EAMf,MAAM,YAAY,CAAC;AAGpB,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAIrC,UAAU,YAAY;IACpB,oEAAoE;IACpE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8FAA8F;IAC9F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,UAAU,iBAAiB;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;IACzC,gEAAgE;IAChE,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAA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