@affiant/core 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +354 -0
  3. package/dist/context.d.ts +136 -0
  4. package/dist/context.d.ts.map +1 -0
  5. package/dist/context.js +30 -0
  6. package/dist/context.js.map +1 -0
  7. package/dist/docket/entry.d.ts +421 -0
  8. package/dist/docket/entry.d.ts.map +1 -0
  9. package/dist/docket/entry.js +155 -0
  10. package/dist/docket/entry.js.map +1 -0
  11. package/dist/docket/expiry.d.ts +82 -0
  12. package/dist/docket/expiry.d.ts.map +1 -0
  13. package/dist/docket/expiry.js +106 -0
  14. package/dist/docket/expiry.js.map +1 -0
  15. package/dist/docket/memory.d.ts +163 -0
  16. package/dist/docket/memory.d.ts.map +1 -0
  17. package/dist/docket/memory.js +528 -0
  18. package/dist/docket/memory.js.map +1 -0
  19. package/dist/docket/store.d.ts +387 -0
  20. package/dist/docket/store.d.ts.map +1 -0
  21. package/dist/docket/store.js +51 -0
  22. package/dist/docket/store.js.map +1 -0
  23. package/dist/errors.d.ts +153 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/errors.js +164 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/gate/coverage.d.ts +152 -0
  28. package/dist/gate/coverage.d.ts.map +1 -0
  29. package/dist/gate/coverage.js +114 -0
  30. package/dist/gate/coverage.js.map +1 -0
  31. package/dist/gate/decide.d.ts +207 -0
  32. package/dist/gate/decide.d.ts.map +1 -0
  33. package/dist/gate/decide.js +559 -0
  34. package/dist/gate/decide.js.map +1 -0
  35. package/dist/gate/gate.d.ts +212 -0
  36. package/dist/gate/gate.d.ts.map +1 -0
  37. package/dist/gate/gate.js +175 -0
  38. package/dist/gate/gate.js.map +1 -0
  39. package/dist/gate/pipeline.d.ts +285 -0
  40. package/dist/gate/pipeline.d.ts.map +1 -0
  41. package/dist/gate/pipeline.js +515 -0
  42. package/dist/gate/pipeline.js.map +1 -0
  43. package/dist/gate/policy.d.ts +272 -0
  44. package/dist/gate/policy.d.ts.map +1 -0
  45. package/dist/gate/policy.js +396 -0
  46. package/dist/gate/policy.js.map +1 -0
  47. package/dist/gate/wrap.d.ts +107 -0
  48. package/dist/gate/wrap.d.ts.map +1 -0
  49. package/dist/gate/wrap.js +164 -0
  50. package/dist/gate/wrap.js.map +1 -0
  51. package/dist/index.d.ts +95 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +111 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/model/affidavit.d.ts +354 -0
  56. package/dist/model/affidavit.d.ts.map +1 -0
  57. package/dist/model/affidavit.js +417 -0
  58. package/dist/model/affidavit.js.map +1 -0
  59. package/dist/model/amendments.d.ts +160 -0
  60. package/dist/model/amendments.d.ts.map +1 -0
  61. package/dist/model/amendments.js +183 -0
  62. package/dist/model/amendments.js.map +1 -0
  63. package/dist/model/canonical.d.ts +311 -0
  64. package/dist/model/canonical.d.ts.map +1 -0
  65. package/dist/model/canonical.js +665 -0
  66. package/dist/model/canonical.js.map +1 -0
  67. package/dist/model/money.d.ts +127 -0
  68. package/dist/model/money.d.ts.map +1 -0
  69. package/dist/model/money.js +177 -0
  70. package/dist/model/money.js.map +1 -0
  71. package/dist/model/provenance.d.ts +315 -0
  72. package/dist/model/provenance.d.ts.map +1 -0
  73. package/dist/model/provenance.js +223 -0
  74. package/dist/model/provenance.js.map +1 -0
  75. package/dist/ports.d.ts +269 -0
  76. package/dist/ports.d.ts.map +1 -0
  77. package/dist/ports.js +34 -0
  78. package/dist/ports.js.map +1 -0
  79. package/dist/store-memory.d.ts +21 -0
  80. package/dist/store-memory.d.ts.map +1 -0
  81. package/dist/store-memory.js +20 -0
  82. package/dist/store-memory.js.map +1 -0
  83. package/dist/telemetry-keys.d.ts +65 -0
  84. package/dist/telemetry-keys.d.ts.map +1 -0
  85. package/dist/telemetry-keys.js +72 -0
  86. package/dist/telemetry-keys.js.map +1 -0
  87. package/dist/telemetry.d.ts +77 -0
  88. package/dist/telemetry.d.ts.map +1 -0
  89. package/dist/telemetry.js +43 -0
  90. package/dist/telemetry.js.map +1 -0
  91. package/dist/testing.d.ts +574 -0
  92. package/dist/testing.d.ts.map +1 -0
  93. package/dist/testing.js +1291 -0
  94. package/dist/testing.js.map +1 -0
  95. package/package.json +75 -0
  96. package/telemetry-keys.json +92 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/model/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AAQH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAgE1E,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,2BAA2B,CACzC,SAAyB,EACzB,UAAwB,EACxB,GAAgB;IAEhB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAE5C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC/E,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACpD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,CAAC,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AC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED,0EAA0E;AAC1E,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC;QACrE,OAAO,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9C,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACzF,OAAO,GAAG,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,eAAe,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;IACvE,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Money on the wire: a decimal string plus an ISO 4217 currency code.
3
+ *
4
+ * **Rule served: SR-2** — *a monetary field value is `{ amount: "<decimal
5
+ * string>", currency: "<ISO 4217>" }` — the amount as a decimal string with no
6
+ * exponent, no thousands separators, at most the currency's minor-unit scale
7
+ * unless the host declares otherwise; never a binary float.*
8
+ *
9
+ * The reason is not fussiness about types. An Affidavit is a record a person swears
10
+ * to and an auditor reads back years later; a binary float cannot represent `0.10`,
11
+ * so a card that showed "£4,000.10" and a store that holds `4000.099999999999`
12
+ * disagree about what was approved, and nothing in the record says which one the
13
+ * reviewer saw. A decimal string is the value the reviewer read, byte for byte,
14
+ * and it survives every JSON parser in every language unchanged.
15
+ *
16
+ * SR-2 is a **wire** rule. A host stores what it likes — integer minor units, a
17
+ * database `decimal`, a `Money` class — and converts at the edge; the store
18
+ * persists the wire value without reinterpreting it.
19
+ *
20
+ * `./affidavit.ts` re-exports {@link Money} and {@link isMoney} from here, so an
21
+ * Affidavit and its money have one definition between them and a caller can reach
22
+ * either through `@affiant/core`.
23
+ *
24
+ * This module deliberately embeds **no currency list**. ISO 4217 changes (currencies
25
+ * are added, redenominated and withdrawn), and a hard-coded table inside a
26
+ * serialization package would be wrong within a year and unfixable without a
27
+ * release. What is checked here is the *shape* — three uppercase ASCII letters —
28
+ * and the host checks membership against whatever list it keeps current.
29
+ *
30
+ * @packageDocumentation
31
+ */
32
+ /**
33
+ * A monetary value as it appears on the wire and inside an Affidavit.
34
+ *
35
+ * Both properties are strings on purpose: see the module header, and SR-2.
36
+ */
37
+ export interface Money {
38
+ /**
39
+ * The amount as a decimal string: an optional `-`, an integer part with no
40
+ * leading zeros, and an optional fractional part. No exponent, no thousands
41
+ * separators, no leading `+`, no currency symbol.
42
+ *
43
+ * Examples: `"0"`, `"10.00"`, `"-1250.75"`, `"12345678901234567890.01"`.
44
+ */
45
+ readonly amount: string;
46
+ /**
47
+ * The ISO 4217 alphabetic code, three uppercase ASCII letters: `"GBP"`, `"LKR"`,
48
+ * `"USD"`. Not case-folded anywhere — SR-3 fixes enum spellings as they stand.
49
+ */
50
+ readonly currency: string;
51
+ }
52
+ /**
53
+ * The shape {@link Money.amount} must match.
54
+ *
55
+ * Read it left to right: an optional minus; then either a bare `0` or a digit
56
+ * sequence that does not start with `0`; then, optionally, a decimal point and at
57
+ * least one digit. That excludes exactly the forms that lose or hide information —
58
+ * `1e3` (an exponent a reader has to evaluate), `1,000` (a separator that means a
59
+ * decimal point in half the world), `+10` (a sign JSON numbers do not carry),
60
+ * `010` (an integer part whose leading zero could be a truncation), `10.` (a point
61
+ * with nothing after it) and `.5` (a point with nothing before it).
62
+ *
63
+ * Not anchored to a scale: SR-2's minor-unit clause is the host's to declare, and
64
+ * {@link moneyScaleOk} is how it declares one.
65
+ */
66
+ export declare const MONEY_AMOUNT_PATTERN: RegExp;
67
+ /**
68
+ * The shape {@link Money.currency} must match: the ISO 4217 alphabetic-code shape,
69
+ * three uppercase ASCII letters. Membership in the standard's current list is the
70
+ * host's check, not this package's — see the module header.
71
+ */
72
+ export declare const MONEY_CURRENCY_PATTERN: RegExp;
73
+ /**
74
+ * Whether `value` is a valid {@link Money}: both properties present, both strings,
75
+ * both matching their patterns.
76
+ *
77
+ * A predicate, not a refusal — {@link assertMoney} is the refusing form and carries
78
+ * the diagnosis. Use this one where a value may legitimately not be money.
79
+ */
80
+ export declare function isMoney(value: unknown): value is Money;
81
+ /**
82
+ * Refuse anything that is not a valid {@link Money}, naming SR-2 and saying which
83
+ * part is wrong.
84
+ *
85
+ * The message names the rule because the caller who hits this is usually a host
86
+ * author who reached for the obvious thing — a JSON number — and the useful reply
87
+ * is not "invalid money" but "here is the rule, and here is why a float is not
88
+ * allowed to represent a price".
89
+ *
90
+ * @param value The value that should be money.
91
+ * @param where What the value is, for the message: a field name, a JSON pointer.
92
+ * @throws TypeError when `value` is not a valid {@link Money}.
93
+ */
94
+ export declare function assertMoney(value: unknown, where?: string): asserts value is Money;
95
+ /**
96
+ * Validate `value` as money and return it as a {@link Money}.
97
+ *
98
+ * The returned object carries exactly the two properties, so a value that arrived
99
+ * with extra keys does not smuggle them onward. The strings are returned unchanged
100
+ * — this parses, it does not normalise: `"10.00"` stays `"10.00"` and never becomes
101
+ * `"10"`, because the trailing zeros are what the reviewer saw and dropping them
102
+ * would change the canonical bytes (SR-1) for a value nobody amended.
103
+ *
104
+ * @param value The value that should be money.
105
+ * @param where What the value is, for the message.
106
+ * @throws TypeError when `value` is not a valid {@link Money} — including the
107
+ * common case of a JSON number, which names SR-2 and says why.
108
+ */
109
+ export declare function parseMoney(value: unknown, where?: string): Money;
110
+ /**
111
+ * Whether `money` fits a scale the host declares, in minor units.
112
+ *
113
+ * SR-2 caps a money amount at "the currency's minor-unit scale unless the host
114
+ * declares otherwise", and this package holds no currency table, so the scale is a
115
+ * number the caller passes: `2` for sterling and the euro, `0` for the yen, `3` for
116
+ * the dinar, and whatever a host declares for an internal unit that needs more.
117
+ *
118
+ * The check is on the digits *written*, not on the value: `"10.00"` has scale 2 and
119
+ * fails `moneyScaleOk(money, 1)` even though the amount is representable in one
120
+ * decimal place. That is deliberate — the record is what was written.
121
+ *
122
+ * @param money A valid {@link Money}.
123
+ * @param minorUnits The number of fractional digits the host allows. A non-negative integer.
124
+ * @throws TypeError when `minorUnits` is not a non-negative integer, or `money` is not money.
125
+ */
126
+ export declare function moneyScaleOk(money: Money, minorUnits: number): boolean;
127
+ //# sourceMappingURL=money.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/model/money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,QAA6B,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAe,CAAC;AAanD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAQtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAU,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAmCnF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAU,GAAG,KAAK,CAGjE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAWtE"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Money on the wire: a decimal string plus an ISO 4217 currency code.
3
+ *
4
+ * **Rule served: SR-2** — *a monetary field value is `{ amount: "<decimal
5
+ * string>", currency: "<ISO 4217>" }` — the amount as a decimal string with no
6
+ * exponent, no thousands separators, at most the currency's minor-unit scale
7
+ * unless the host declares otherwise; never a binary float.*
8
+ *
9
+ * The reason is not fussiness about types. An Affidavit is a record a person swears
10
+ * to and an auditor reads back years later; a binary float cannot represent `0.10`,
11
+ * so a card that showed "£4,000.10" and a store that holds `4000.099999999999`
12
+ * disagree about what was approved, and nothing in the record says which one the
13
+ * reviewer saw. A decimal string is the value the reviewer read, byte for byte,
14
+ * and it survives every JSON parser in every language unchanged.
15
+ *
16
+ * SR-2 is a **wire** rule. A host stores what it likes — integer minor units, a
17
+ * database `decimal`, a `Money` class — and converts at the edge; the store
18
+ * persists the wire value without reinterpreting it.
19
+ *
20
+ * `./affidavit.ts` re-exports {@link Money} and {@link isMoney} from here, so an
21
+ * Affidavit and its money have one definition between them and a caller can reach
22
+ * either through `@affiant/core`.
23
+ *
24
+ * This module deliberately embeds **no currency list**. ISO 4217 changes (currencies
25
+ * are added, redenominated and withdrawn), and a hard-coded table inside a
26
+ * serialization package would be wrong within a year and unfixable without a
27
+ * release. What is checked here is the *shape* — three uppercase ASCII letters —
28
+ * and the host checks membership against whatever list it keeps current.
29
+ *
30
+ * @packageDocumentation
31
+ */
32
+ /**
33
+ * The shape {@link Money.amount} must match.
34
+ *
35
+ * Read it left to right: an optional minus; then either a bare `0` or a digit
36
+ * sequence that does not start with `0`; then, optionally, a decimal point and at
37
+ * least one digit. That excludes exactly the forms that lose or hide information —
38
+ * `1e3` (an exponent a reader has to evaluate), `1,000` (a separator that means a
39
+ * decimal point in half the world), `+10` (a sign JSON numbers do not carry),
40
+ * `010` (an integer part whose leading zero could be a truncation), `10.` (a point
41
+ * with nothing after it) and `.5` (a point with nothing before it).
42
+ *
43
+ * Not anchored to a scale: SR-2's minor-unit clause is the host's to declare, and
44
+ * {@link moneyScaleOk} is how it declares one.
45
+ */
46
+ export const MONEY_AMOUNT_PATTERN = /^-?(0|[1-9]\d*)(\.\d+)?$/;
47
+ /**
48
+ * The shape {@link Money.currency} must match: the ISO 4217 alphabetic-code shape,
49
+ * three uppercase ASCII letters. Membership in the standard's current list is the
50
+ * host's check, not this package's — see the module header.
51
+ */
52
+ export const MONEY_CURRENCY_PATTERN = /^[A-Z]{3}$/;
53
+ /** Whether `value` is a plain object carrying an own `amount` and an own `currency`. */
54
+ function isMoneyShaped(value) {
55
+ if (typeof value !== "object" || value === null)
56
+ return false;
57
+ return (Object.prototype.hasOwnProperty.call(value, "amount") &&
58
+ Object.prototype.hasOwnProperty.call(value, "currency"));
59
+ }
60
+ /**
61
+ * Whether `value` is a valid {@link Money}: both properties present, both strings,
62
+ * both matching their patterns.
63
+ *
64
+ * A predicate, not a refusal — {@link assertMoney} is the refusing form and carries
65
+ * the diagnosis. Use this one where a value may legitimately not be money.
66
+ */
67
+ export function isMoney(value) {
68
+ if (!isMoneyShaped(value))
69
+ return false;
70
+ return (typeof value.amount === "string" &&
71
+ typeof value.currency === "string" &&
72
+ MONEY_AMOUNT_PATTERN.test(value.amount) &&
73
+ MONEY_CURRENCY_PATTERN.test(value.currency));
74
+ }
75
+ /**
76
+ * Refuse anything that is not a valid {@link Money}, naming SR-2 and saying which
77
+ * part is wrong.
78
+ *
79
+ * The message names the rule because the caller who hits this is usually a host
80
+ * author who reached for the obvious thing — a JSON number — and the useful reply
81
+ * is not "invalid money" but "here is the rule, and here is why a float is not
82
+ * allowed to represent a price".
83
+ *
84
+ * @param value The value that should be money.
85
+ * @param where What the value is, for the message: a field name, a JSON pointer.
86
+ * @throws TypeError when `value` is not a valid {@link Money}.
87
+ */
88
+ export function assertMoney(value, where = "value") {
89
+ if (typeof value === "number") {
90
+ throw new TypeError(`SR-2: ${where} is a JSON number (${String(value)}) where money was expected. ` +
91
+ `Money on the wire is { amount: "<decimal string>", currency: "<ISO 4217>" }, never a ` +
92
+ `binary float: 0.1 has no exact double, so the amount a reviewer approved and the amount ` +
93
+ `a store holds would differ with nothing on the record to say which was sworn to.`);
94
+ }
95
+ if (!isMoneyShaped(value)) {
96
+ throw new TypeError(`SR-2: ${where} is not money. Expected an object with an "amount" (decimal string) and a ` +
97
+ `"currency" (ISO 4217 code); received ${describe(value)}.`);
98
+ }
99
+ if (typeof value.amount === "number") {
100
+ throw new TypeError(`SR-2: ${where}.amount is a JSON number (${String(value.amount)}). The amount is a decimal ` +
101
+ `string — write ${JSON.stringify(String(value.amount))} — because a binary float cannot ` +
102
+ `hold the value a reviewer read.`);
103
+ }
104
+ if (typeof value.amount !== "string" || !MONEY_AMOUNT_PATTERN.test(value.amount)) {
105
+ throw new TypeError(`SR-2: ${where}.amount is not a decimal string. Expected ${String(MONEY_AMOUNT_PATTERN)} — ` +
106
+ `an optional "-", an integer part with no leading zeros, and an optional fractional part; ` +
107
+ `no exponent, no thousands separators, no leading "+". Received ${describe(value.amount)}.`);
108
+ }
109
+ if (typeof value.currency !== "string" || !MONEY_CURRENCY_PATTERN.test(value.currency)) {
110
+ throw new TypeError(`SR-2: ${where}.currency is not an ISO 4217 code. Expected three uppercase ASCII letters ` +
111
+ `(the code is never case-folded on the wire); received ${describe(value.currency)}.`);
112
+ }
113
+ }
114
+ /**
115
+ * Validate `value` as money and return it as a {@link Money}.
116
+ *
117
+ * The returned object carries exactly the two properties, so a value that arrived
118
+ * with extra keys does not smuggle them onward. The strings are returned unchanged
119
+ * — this parses, it does not normalise: `"10.00"` stays `"10.00"` and never becomes
120
+ * `"10"`, because the trailing zeros are what the reviewer saw and dropping them
121
+ * would change the canonical bytes (SR-1) for a value nobody amended.
122
+ *
123
+ * @param value The value that should be money.
124
+ * @param where What the value is, for the message.
125
+ * @throws TypeError when `value` is not a valid {@link Money} — including the
126
+ * common case of a JSON number, which names SR-2 and says why.
127
+ */
128
+ export function parseMoney(value, where = "value") {
129
+ assertMoney(value, where);
130
+ return { amount: value.amount, currency: value.currency };
131
+ }
132
+ /**
133
+ * Whether `money` fits a scale the host declares, in minor units.
134
+ *
135
+ * SR-2 caps a money amount at "the currency's minor-unit scale unless the host
136
+ * declares otherwise", and this package holds no currency table, so the scale is a
137
+ * number the caller passes: `2` for sterling and the euro, `0` for the yen, `3` for
138
+ * the dinar, and whatever a host declares for an internal unit that needs more.
139
+ *
140
+ * The check is on the digits *written*, not on the value: `"10.00"` has scale 2 and
141
+ * fails `moneyScaleOk(money, 1)` even though the amount is representable in one
142
+ * decimal place. That is deliberate — the record is what was written.
143
+ *
144
+ * @param money A valid {@link Money}.
145
+ * @param minorUnits The number of fractional digits the host allows. A non-negative integer.
146
+ * @throws TypeError when `minorUnits` is not a non-negative integer, or `money` is not money.
147
+ */
148
+ export function moneyScaleOk(money, minorUnits) {
149
+ if (!Number.isInteger(minorUnits) || minorUnits < 0) {
150
+ throw new TypeError(`SR-2: minorUnits must be a non-negative integer (2 for GBP, 0 for JPY, 3 for KWD); ` +
151
+ `received ${describe(minorUnits)}.`);
152
+ }
153
+ assertMoney(money, "money");
154
+ const point = money.amount.indexOf(".");
155
+ const scale = point === -1 ? 0 : money.amount.length - point - 1;
156
+ return scale <= minorUnits;
157
+ }
158
+ /** A short, safe rendering of an arbitrary value for an error message. */
159
+ function describe(value) {
160
+ if (value === null)
161
+ return "null";
162
+ if (value === undefined)
163
+ return "undefined";
164
+ if (typeof value === "string")
165
+ return `the string ${JSON.stringify(truncate(value))}`;
166
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
167
+ return `${typeof value} ${String(value)}`;
168
+ }
169
+ if (Array.isArray(value))
170
+ return `an array of ${String(value.length)}`;
171
+ return `${typeof value} ${truncate(Object.prototype.toString.call(value))}`;
172
+ }
173
+ /** Error messages quote values; values can be long. */
174
+ function truncate(text) {
175
+ return text.length <= 60 ? text : `${text.slice(0, 57)}...`;
176
+ }
177
+ //# sourceMappingURL=money.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/model/money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAuBH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAEnD,wFAAwF;AACxF,SAAS,aAAa,CACpB,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC;QACrD,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CACxD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,CACL,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;QAChC,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ;QAClC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QACvC,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAC5C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc,EAA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AK,KAAK,QAAQ,EAAE,CAAC;QACzF,OAAO,GAAG,OAAO,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC5C,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,eAAe,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;IACvE,OAAO,GAAG,OAAO,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED,uDAAuD;AACvD,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Provenance: the seven-source ladder, the tag, the binding that makes a tag
3
+ * checkable, the chain that keeps every superseded tag, and the merge rule.
4
+ *
5
+ * **Rules served: PV-1** (the ladder, the chain, confidence-first /
6
+ * determinism-second merge, confidence clamped into `[0, 1]`), **PV-2** (a tag
7
+ * above `Conversation` carries a binding, and the binding kinds are a fixed set),
8
+ * **PV-3** (an implementation's own inference never mints `UserStated`), **PV-5**
9
+ * (no wire type raises a grade: an asserted grade above `Conversation` with no
10
+ * binding is carried on the record but is not honourable).
11
+ *
12
+ * The idea in one paragraph: a value on an Affidavit is worth exactly what its
13
+ * evidence is worth. A provenance tag says where the value came from
14
+ * ({@link ProvenanceSource}), how confident its producer was, and — for the grades
15
+ * that claim more than "a model read it in the conversation" — a {@link Binding}:
16
+ * a pointer at something an auditor can go and check years later. A tag with no
17
+ * binding is not a lie, it is a weaker claim, and the framework's job is to keep
18
+ * the difference visible rather than to average it away.
19
+ *
20
+ * Nothing here reads a clock. Every function that stamps a time takes the instant
21
+ * as a parameter, so a fixture can pin it (RT-1, and the same reason the clock is
22
+ * a port rather than a call to `Date.now()`).
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ import type { ProvenanceSource } from "@affiant/contract";
27
+ /** Where a value came from. Re-exported so a host can name it without a second import. */
28
+ export type { ProvenanceSource };
29
+ /**
30
+ * The seven provenance sources, **most deterministic first**.
31
+ *
32
+ * This order is not a preference, it is the tie-breaker: when two tags carry equal
33
+ * confidence the one nearer the front of this list wins the merge (PV-1). Read it
34
+ * as a claim about who could re-derive the value — the person said it; a system of
35
+ * record holds it; a named rule computes it; it was literally present in the
36
+ * conversation; a model reasoned to it; a default filled it in; nobody knows.
37
+ *
38
+ * Spelled out here rather than re-exported from `@affiant/contract` so the gate's
39
+ * ordering is a fact of the gate. `test/provenance.test.ts` asserts the two lists
40
+ * are identical, which is what keeps them from drifting apart.
41
+ */
42
+ export declare const PROVENANCE_LADDER: readonly ["UserStated", "External", "Computed", "Conversation", "Inferred", "Default", "Empty"];
43
+ /**
44
+ * How deterministic `source` is: `0` for `UserStated`, `6` for `Empty`.
45
+ *
46
+ * **Lower is more deterministic.** The number is an index into
47
+ * {@link PROVENANCE_LADDER}, so it is a comparison key and nothing else — never a
48
+ * score, never a weight, never something to multiply a confidence by.
49
+ */
50
+ export declare function determinismRank(source: ProvenanceSource): number;
51
+ /**
52
+ * Whether a tag with this source must carry a {@link Binding} to be worth its grade
53
+ * (PV-2): the three sources **above** `Conversation` — `UserStated`, `External`,
54
+ * `Computed`.
55
+ *
56
+ * At or below `Conversation` the grade already says "this came from the turn, or
57
+ * from a model reading the turn", and the turn is itself the artifact. Above it,
58
+ * the tag claims an artifact outside the conversation, and a claim with no pointer
59
+ * at that artifact is not checkable — see {@link isBound} and PV-4, where the pair
60
+ * decides whether a person-free approval may rest on the tag.
61
+ */
62
+ export declare function requiresBinding(source: ProvenanceSource): boolean;
63
+ /**
64
+ * Where in the unmodified utterance a value was found.
65
+ *
66
+ * Offset and length rather than a start/end pair, and a `hash` of the substring:
67
+ * offsets alone rot the moment anything re-wraps or re-encodes the transcript, so
68
+ * the hash is what lets an auditor prove the span still says what it said. The
69
+ * digest algorithm and encoding are fixed by the canonical-form rules (SR-1, pull
70
+ * request C3); this type carries the string.
71
+ */
72
+ export interface UtteranceSpanRef {
73
+ /** Character offset into the utterance, from 0. */
74
+ readonly offset: number;
75
+ /** Length of the span in characters. */
76
+ readonly length: number;
77
+ /** Digest of the spanned substring, so the span can be checked after the fact. */
78
+ readonly hash: string;
79
+ }
80
+ /** The Docket decision that amended the field. */
81
+ export interface ReviewerActRef {
82
+ /** The Docket entry the decision was made on. */
83
+ readonly entryId: string;
84
+ /** When the decision was made, as an ISO 8601 instant. */
85
+ readonly decisionAt: string;
86
+ }
87
+ /** The form control a person typed into. */
88
+ export interface FormInputRef {
89
+ /** The form field's name, as the host's own surface names it. */
90
+ readonly field: string;
91
+ }
92
+ /**
93
+ * A relay that asserted a person's identity rather than authenticating them — the
94
+ * channel the capture arrived on and the message it arrived in (Sequence C).
95
+ */
96
+ export interface RelayRef {
97
+ /** The relay's own principal id. */
98
+ readonly principal: string;
99
+ /** How the person is addressed on that channel. */
100
+ readonly channelIdentity: string;
101
+ /** The message the capture arrived in. */
102
+ readonly messageId: string;
103
+ }
104
+ /**
105
+ * The system of record an `External` value was read from.
106
+ *
107
+ * `fetchedAt` and `contentHash` are what a value read from a page with no API binds
108
+ * instead of a record id: when it was read, and what it said when it was read. A
109
+ * binding whose source cannot be re-fetched or re-verified is not a binding (PV-2).
110
+ */
111
+ export interface ExternalRef {
112
+ /** The source system, named the way the host names it. */
113
+ readonly system: string;
114
+ /** The record within that system. A canonical URL where the system is a page. */
115
+ readonly recordId: string;
116
+ /** When the value was read, as an ISO 8601 instant. */
117
+ readonly fetchedAt?: string;
118
+ /** Digest of what the source said when it was read. */
119
+ readonly contentHash?: string;
120
+ /** Present when the value arrived over a trusted relay. */
121
+ readonly relay?: RelayRef;
122
+ }
123
+ /**
124
+ * An externally published constant a computation consumed, and the date it was
125
+ * last verified.
126
+ *
127
+ * *When a value was checked is a different fact from when the tag was written*
128
+ * (PV-2): a rate table verified in March and used in September is a September tag
129
+ * resting on a March fact, and a reviewer is entitled to see both.
130
+ */
131
+ export interface ComputationConstantRef {
132
+ /** Where the constant is published. */
133
+ readonly source: string;
134
+ /** The date the constant was last verified, as an ISO 8601 date or instant. */
135
+ readonly verifiedOn: string;
136
+ }
137
+ /** The deterministic rule a `Computed` value came out of, and what it consumed. */
138
+ export interface ComputationRef {
139
+ /** The rule's name — re-runnable, not a description. */
140
+ readonly rule: string;
141
+ /** The field names the rule consumed, in the order it consumed them. */
142
+ readonly inputs: readonly string[];
143
+ /** An externally published constant the rule depends on. */
144
+ readonly constant?: ComputationConstantRef;
145
+ }
146
+ /**
147
+ * What to look at to check a value. The five kinds are a **fixed set** (PV-2): a
148
+ * binding kind nobody can enumerate is a binding nobody can audit.
149
+ */
150
+ export type Binding = {
151
+ readonly kind: "utterance-span";
152
+ readonly ref: UtteranceSpanRef;
153
+ } | {
154
+ readonly kind: "reviewer-act";
155
+ readonly ref: ReviewerActRef;
156
+ } | {
157
+ readonly kind: "form-input";
158
+ readonly ref: FormInputRef;
159
+ } | {
160
+ readonly kind: "external-ref";
161
+ readonly ref: ExternalRef;
162
+ } | {
163
+ readonly kind: "computation-ref";
164
+ readonly ref: ComputationRef;
165
+ };
166
+ /** Every {@link Binding} kind, as data. */
167
+ export declare const BINDING_KINDS: readonly ["utterance-span", "reviewer-act", "form-input", "external-ref", "computation-ref"];
168
+ /** The kind discriminator of a {@link Binding}. */
169
+ export type BindingKind = Binding["kind"];
170
+ /**
171
+ * The bindings a deterministic interceptor may mint.
172
+ *
173
+ * The restriction is PV-3 in the type system: an interceptor resolves `External`
174
+ * and `Computed` values, so it can only ever point at a record or a computation. A
175
+ * machine does not get to bind a value to a person's act.
176
+ */
177
+ export type InterceptorBinding = Extract<Binding, {
178
+ kind: "external-ref" | "computation-ref";
179
+ }>;
180
+ /**
181
+ * One provenance record for one field value.
182
+ *
183
+ * `binding` is written on every minted tag — `null` when the producer had nothing
184
+ * to point at — so a reader never has to distinguish "unbound" from "the property
185
+ * was left off". The property is declared optional only because a wire-derived tag
186
+ * at protocol tag `0.0.1-seed` carries no binding field at all.
187
+ */
188
+ export interface ProvenanceTag {
189
+ /** Where the value came from. */
190
+ readonly source: ProvenanceSource;
191
+ /** Confidence in the value, in `[0, 1]`. Always clamped at mint time (PV-1). */
192
+ readonly confidence: number;
193
+ /** A human-readable line for the reviewer, or `null` when there is nothing to say. */
194
+ readonly note: string | null;
195
+ /** When the tag was minted, as an ISO 8601 instant. */
196
+ readonly at: string;
197
+ /** Index of the conversation turn the value came from, or `null`. */
198
+ readonly conversationTurn: number | null;
199
+ /** What to look at to check the value (PV-2), or `null` when the producer had nothing. */
200
+ readonly binding?: Binding | null;
201
+ }
202
+ /**
203
+ * The ordered provenance history of one field: the tag in force, and every tag it
204
+ * displaced.
205
+ *
206
+ * `prior` is newest first, which is the order a card reads it in ("was `Inferred`
207
+ * at 0.4, before that `Default`"). Nothing is ever dropped from a chain — a merge
208
+ * that discarded the loser would erase the fact that two producers disagreed,
209
+ * which is the fact a reviewer most wants.
210
+ */
211
+ export interface ProvenanceChain {
212
+ /** The tag in force for the field's current value. */
213
+ readonly current: ProvenanceTag;
214
+ /** Superseded tags, newest first. Empty on a chain that has never been merged. */
215
+ readonly prior: readonly ProvenanceTag[];
216
+ }
217
+ /** What every mint call needs. */
218
+ interface MintCommon {
219
+ /** Confidence as the producer reports it. Clamped into `[0, 1]` (PV-1). */
220
+ readonly confidence: number;
221
+ /** When the tag is minted, as an ISO 8601 instant. Passed in; nothing here reads a clock. */
222
+ readonly at: string;
223
+ /** A human-readable line for the reviewer. Defaults to `null`. */
224
+ readonly note?: string | null;
225
+ /** The conversation turn the value came from. Defaults to `null`. */
226
+ readonly conversationTurn?: number | null;
227
+ /** What to look at to check the value. Defaults to `null`. */
228
+ readonly binding?: Binding | null;
229
+ }
230
+ /** What {@link mintTag} needs: {@link MintCommon} plus the source being claimed. */
231
+ export interface MintTagOptions extends MintCommon {
232
+ /** The grade being claimed. */
233
+ readonly source: ProvenanceSource;
234
+ }
235
+ /** What {@link mintInference}, {@link mintConversation} and {@link mintInferred} need. */
236
+ export type MintInferenceOptions = MintCommon;
237
+ /**
238
+ * Mint a tag for any source, clamping the confidence into `[0, 1]` (PV-1).
239
+ *
240
+ * A tag whose source is `Empty` is forced to confidence `0`: "nobody knows where
241
+ * this came from" cannot also be a confident claim, and AF-2 counts every `Empty`
242
+ * field as `0` in the aggregate anyway — forcing it here means the two can never
243
+ * disagree.
244
+ *
245
+ * This is the general minting surface, used by deterministic interceptors, by the
246
+ * projection step and by a reviewer's amendment. **It is not the surface the
247
+ * inference step gets:** PV-3 forbids an implementation's own inference from
248
+ * minting `UserStated`, so the inference step is handed {@link mintInference},
249
+ * whose source parameter is typed {@link InferenceSource} and cannot name it.
250
+ */
251
+ export declare function mintTag(options: MintTagOptions): ProvenanceTag;
252
+ /**
253
+ * The only two sources an implementation's own inference may mint (PV-3).
254
+ *
255
+ * `Conversation` when the value is literally present in the unmodified utterance;
256
+ * `Inferred` when the model reasoned to it. `UserStated` is an observation of a
257
+ * person's act — an utterance span, a form input, a reviewer's amendment — never
258
+ * the host vouching for a value it produced itself.
259
+ */
260
+ export type InferenceSource = "Conversation" | "Inferred";
261
+ /**
262
+ * Mint a tag from the inference step. The source parameter is
263
+ * {@link InferenceSource}, so `UserStated` is a compile error here (PV-3).
264
+ *
265
+ * The runtime guard exists for callers with no type-checker — a JavaScript host, a
266
+ * value cast at the boundary — because PV-3 is a rule about what the record may
267
+ * say, not about what TypeScript can see.
268
+ *
269
+ * @throws RangeError if `source` is anything but `Conversation` or `Inferred`.
270
+ */
271
+ export declare function mintInference(source: InferenceSource, options: MintInferenceOptions): ProvenanceTag;
272
+ /** {@link mintInference} with source `Conversation`: the value was literally in the turn. */
273
+ export declare function mintConversation(options: MintInferenceOptions): ProvenanceTag;
274
+ /** {@link mintInference} with source `Inferred`: the model reasoned to the value. */
275
+ export declare function mintInferred(options: MintInferenceOptions): ProvenanceTag;
276
+ /**
277
+ * The tag a field carries when nobody knows where its value came from: source
278
+ * `Empty`, confidence `0` (AF-1 — present and tagged, never omitted).
279
+ */
280
+ export declare function emptyTag(at: string, note?: string | null): ProvenanceTag;
281
+ /** Whether `tag` points at something an auditor can check (PV-2). */
282
+ export declare function isBound(tag: ProvenanceTag): boolean;
283
+ /**
284
+ * Whether `tag`'s grade is one a person-free verdict may rest on: either the grade
285
+ * needs no binding, or it has one (PV-4, PV-5).
286
+ *
287
+ * The unhonourable case is exactly the one PV-5 names: a caller asserts
288
+ * `UserStated` on the wire and points at nothing. The tag is still recorded — the
289
+ * record says what the caller claimed — but a Standing Order that predicates on it
290
+ * falls back to asking a person.
291
+ */
292
+ export declare function isHonourable(tag: ProvenanceTag): boolean;
293
+ /** A fresh chain holding one tag and no history. */
294
+ export declare function chainOf(tag: ProvenanceTag): ProvenanceChain;
295
+ /**
296
+ * Merge `incoming` into `chain` (PV-1): the higher confidence wins, ties break
297
+ * toward the more deterministic source, **and the loser is preserved** at the head
298
+ * of `prior`.
299
+ *
300
+ * This is the step where a deterministic interceptor's `External` value displaces
301
+ * a model's guess, or fails to. Either way both tags survive, so a card can show a
302
+ * reviewer that the model said one thing and the system of record said another.
303
+ */
304
+ export declare function merge(chain: ProvenanceChain, incoming: ProvenanceTag): ProvenanceChain;
305
+ /**
306
+ * Put `tag` in force unconditionally, pushing the tag it displaces onto `prior`.
307
+ *
308
+ * Not a merge: a reviewer's amendment is not a confidence contest it might lose
309
+ * (AF-4, PV-2). When a person corrects a field, their act is the provenance of the
310
+ * new value even if the machine was more sure of the old one.
311
+ */
312
+ export declare function supersede(chain: ProvenanceChain, tag: ProvenanceTag): ProvenanceChain;
313
+ /** Every tag in `chain`, in force first and then oldest-displaced last. */
314
+ export declare function tagsOf(chain: ProvenanceChain): readonly ProvenanceTag[];
315
+ //# sourceMappingURL=provenance.d.ts.map