@toiroakr/chisel 0.0.0-stage → 0.2.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.
- package/README.md +693 -2
- package/dist/absence.d.ts +27 -0
- package/dist/absence.js +228 -0
- package/dist/absence.js.map +1 -0
- package/dist/behavior.d.ts +193 -0
- package/dist/behavior.js +589 -0
- package/dist/behavior.js.map +1 -0
- package/dist/beside.d.ts +27 -0
- package/dist/beside.js +88 -0
- package/dist/beside.js.map +1 -0
- package/dist/border.d.ts +61 -0
- package/dist/border.js +434 -0
- package/dist/border.js.map +1 -0
- package/dist/bounds.d.ts +1 -0
- package/dist/bounds.js +26 -0
- package/dist/bounds.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +835 -0
- package/dist/cli.js.map +1 -0
- package/dist/codec.d.ts +6 -0
- package/dist/codec.js +86 -0
- package/dist/codec.js.map +1 -0
- package/dist/codegen.d.ts +2 -0
- package/dist/codegen.js +61 -0
- package/dist/codegen.js.map +1 -0
- package/dist/composition.d.ts +38 -0
- package/dist/composition.js +242 -0
- package/dist/composition.js.map +1 -0
- package/dist/data.d.ts +17 -0
- package/dist/data.js +51 -0
- package/dist/data.js.map +1 -0
- package/dist/dependency.d.ts +101 -0
- package/dist/dependency.js +161 -0
- package/dist/dependency.js.map +1 -0
- package/dist/domain.d.ts +12 -0
- package/dist/domain.js +217 -0
- package/dist/domain.js.map +1 -0
- package/dist/ensures.d.ts +15 -0
- package/dist/ensures.js +88 -0
- package/dist/ensures.js.map +1 -0
- package/dist/equal.d.ts +1 -0
- package/dist/equal.js +135 -0
- package/dist/equal.js.map +1 -0
- package/dist/exact.d.ts +21 -0
- package/dist/exact.js +80 -0
- package/dist/exact.js.map +1 -0
- package/dist/feasibility.d.ts +63 -0
- package/dist/feasibility.js +1053 -0
- package/dist/feasibility.js.map +1 -0
- package/dist/guard-borders.d.ts +57 -0
- package/dist/guard-borders.js +760 -0
- package/dist/guard-borders.js.map +1 -0
- package/dist/guard-scope.d.ts +61 -0
- package/dist/guard-scope.js +364 -0
- package/dist/guard-scope.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/interleave.d.ts +31 -0
- package/dist/interleave.js +202 -0
- package/dist/interleave.js.map +1 -0
- package/dist/interval.d.ts +10 -0
- package/dist/interval.js +311 -0
- package/dist/interval.js.map +1 -0
- package/dist/isolated.d.ts +9 -0
- package/dist/isolated.js +41 -0
- package/dist/isolated.js.map +1 -0
- package/dist/machine-check.d.ts +73 -0
- package/dist/machine-check.js +215 -0
- package/dist/machine-check.js.map +1 -0
- package/dist/machine.d.ts +97 -0
- package/dist/machine.js +200 -0
- package/dist/machine.js.map +1 -0
- package/dist/model.d.ts +160 -0
- package/dist/model.js +778 -0
- package/dist/model.js.map +1 -0
- package/dist/outcomes.d.ts +7 -0
- package/dist/outcomes.js +38 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/pairs.d.ts +26 -0
- package/dist/pairs.js +115 -0
- package/dist/pairs.js.map +1 -0
- package/dist/partition.d.ts +45 -0
- package/dist/partition.js +354 -0
- package/dist/partition.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +556 -0
- package/dist/proof.js.map +1 -0
- package/dist/replay.d.ts +45 -0
- package/dist/replay.js +157 -0
- package/dist/replay.js.map +1 -0
- package/dist/report-json.d.ts +11 -0
- package/dist/report-json.js +94 -0
- package/dist/report-json.js.map +1 -0
- package/dist/rule.d.ts +186 -0
- package/dist/rule.js +866 -0
- package/dist/rule.js.map +1 -0
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +163 -0
- package/dist/schema.js +528 -0
- package/dist/schema.js.map +1 -0
- package/dist/specification.d.ts +266 -0
- package/dist/specification.js +2123 -0
- package/dist/specification.js.map +1 -0
- package/dist/temporal-global.d.ts +4 -0
- package/dist/temporal-global.js +11 -0
- package/dist/temporal-global.js.map +1 -0
- package/dist/temporal.d.ts +22 -0
- package/dist/temporal.js +113 -0
- package/dist/temporal.js.map +1 -0
- package/dist/text.d.ts +1 -0
- package/dist/text.js +11 -0
- package/dist/text.js.map +1 -0
- package/dist/tla.d.ts +54 -0
- package/dist/tla.js +579 -0
- package/dist/tla.js.map +1 -0
- package/dist/verification.d.ts +7 -0
- package/dist/verification.js +5 -0
- package/dist/verification.js.map +1 -0
- package/dist/ways.d.ts +28 -0
- package/dist/ways.js +86 -0
- package/dist/ways.js.map +1 -0
- package/dist/world.d.ts +98 -0
- package/dist/world.js +467 -0
- package/dist/world.js.map +1 -0
- package/package.json +76 -4
- package/schema/report.schema.json +1062 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ElementLabels, Rule } from "./rule.js";
|
|
2
|
+
import type { AnySchema, VariantTable } from "./schema.js";
|
|
3
|
+
export interface Fact {
|
|
4
|
+
readonly rule: Rule;
|
|
5
|
+
readonly outcome: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface Roots {
|
|
8
|
+
readonly scope: AnySchema;
|
|
9
|
+
readonly locals?: ReadonlyMap<string, AnySchema>;
|
|
10
|
+
readonly labels?: ElementLabels;
|
|
11
|
+
readonly declared?: ReadonlySet<string>;
|
|
12
|
+
readonly input?: {
|
|
13
|
+
readonly sum: {
|
|
14
|
+
readonly discriminant: string;
|
|
15
|
+
readonly variants: VariantTable;
|
|
16
|
+
};
|
|
17
|
+
readonly tag: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare function factsOf(rule: Rule, outcome: boolean): readonly Fact[];
|
|
21
|
+
export declare function leftOutReadIn(rule: Rule, roots: Roots, facts?: readonly Fact[], label?: string): string | undefined;
|
|
22
|
+
export declare function choiceFacts(template: unknown): ReadonlyMap<unknown, readonly Fact[]>;
|
|
23
|
+
export declare function casesLeft(sum: {
|
|
24
|
+
readonly discriminant: string;
|
|
25
|
+
readonly variants: VariantTable;
|
|
26
|
+
}, at: readonly string[], facts: readonly Fact[]): readonly string[];
|
|
27
|
+
export declare function leftOutReadInModel(template: unknown, roots: Roots, facts?: readonly Fact[]): string | undefined;
|
package/dist/absence.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { childrenOf, nodeOf } from "./model.js";
|
|
2
|
+
import { describeTerm, isTerm, localLabel, termData } from "./rule.js";
|
|
3
|
+
// What a rule settled with the outcome tells of the comparisons in it.
|
|
4
|
+
export function factsOf(rule, outcome) {
|
|
5
|
+
switch (rule.kind) {
|
|
6
|
+
case "compare":
|
|
7
|
+
return [{ rule, outcome }];
|
|
8
|
+
case "and":
|
|
9
|
+
return outcome ? rule.rules.flatMap(part => factsOf(part, true)) : [];
|
|
10
|
+
case "or":
|
|
11
|
+
return outcome ? [] : rule.rules.flatMap(part => factsOf(part, false));
|
|
12
|
+
case "not":
|
|
13
|
+
return factsOf(rule.rule, !outcome);
|
|
14
|
+
default:
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// The first read of the rule that may be left out, described, or undefined.
|
|
19
|
+
export function leftOutReadIn(rule, roots, facts = [], label = "$") {
|
|
20
|
+
switch (rule.kind) {
|
|
21
|
+
case "and":
|
|
22
|
+
case "or": {
|
|
23
|
+
const known = [...facts];
|
|
24
|
+
for (const part of rule.rules) {
|
|
25
|
+
const found = leftOutReadIn(part, roots, known, label);
|
|
26
|
+
if (found !== undefined)
|
|
27
|
+
return found;
|
|
28
|
+
known.push(...factsOf(part, rule.kind === "and"));
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
case "not":
|
|
33
|
+
return leftOutReadIn(rule.rule, roots, facts, label);
|
|
34
|
+
case "all":
|
|
35
|
+
case "any": {
|
|
36
|
+
const found = leftOutOperand(rule.of, roots, facts, label);
|
|
37
|
+
if (found !== undefined)
|
|
38
|
+
return found;
|
|
39
|
+
const of = termData(rule.of);
|
|
40
|
+
const arrays = of.kind === "position" ? resolve(of.path, roots, facts) : [];
|
|
41
|
+
for (const array of arrays) {
|
|
42
|
+
if (array.kind !== "array")
|
|
43
|
+
continue;
|
|
44
|
+
const locals = new Map(roots.locals ?? []);
|
|
45
|
+
locals.set(rule.element, array.element);
|
|
46
|
+
const labels = { ...roots.labels, [rule.element]: `${describeTerm(rule.of, label, roots.labels)}[]` };
|
|
47
|
+
const inner = leftOutReadIn(rule.each, { ...roots, locals, labels }, facts, label);
|
|
48
|
+
if (inner !== undefined)
|
|
49
|
+
return inner;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
case "compare":
|
|
54
|
+
if (!isTerm(rule.left) && !isTerm(rule.right))
|
|
55
|
+
return undefined;
|
|
56
|
+
for (const side of [rule.left, rule.right]) {
|
|
57
|
+
if (side === undefined)
|
|
58
|
+
return "compares with undefined, which no value is: write the absence as a case of a sum";
|
|
59
|
+
const found = leftOutOperand(side, roots, facts, label);
|
|
60
|
+
if (found !== undefined)
|
|
61
|
+
return found;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function leftOutOperand(operand, roots, facts, label) {
|
|
67
|
+
if (!isTerm(operand))
|
|
68
|
+
return undefined;
|
|
69
|
+
const data = termData(operand);
|
|
70
|
+
const paths = data.kind === "position" ? [data.path] : data.parts.map(part => part.path);
|
|
71
|
+
for (const path of paths) {
|
|
72
|
+
const at = leftOutAt(path, roots, facts);
|
|
73
|
+
if (at !== undefined) {
|
|
74
|
+
const read = render(path, label, roots);
|
|
75
|
+
const where = render(path.slice(0, at), label, roots);
|
|
76
|
+
return read === where || at === 0
|
|
77
|
+
? `reads ${read}, which may be left out: write its absence as a case of a sum`
|
|
78
|
+
: `reads ${read}, which may be left out at ${where}: write its absence as a case of a sum`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
function render(path, label, roots) {
|
|
84
|
+
const [first, ...rest] = path;
|
|
85
|
+
if (first === undefined)
|
|
86
|
+
return label;
|
|
87
|
+
const named = (roots.labels !== undefined && Object.hasOwn(roots.labels, first) ? roots.labels[first] : undefined) ?? (first.startsWith("#local:") ? localLabel(first) : undefined);
|
|
88
|
+
if (named !== undefined)
|
|
89
|
+
return [named, ...rest].join(".");
|
|
90
|
+
return first.startsWith("#") || label === "" ? path.join(".") : [label, ...path].join(".");
|
|
91
|
+
}
|
|
92
|
+
// How many keys of the path lead to where it may be left out, or undefined
|
|
93
|
+
// where the value it reads is always there.
|
|
94
|
+
function leftOutAt(path, roots, facts) {
|
|
95
|
+
if (roots.input !== undefined && !casesLeft(roots.input.sum, [], facts).includes(roots.input.tag))
|
|
96
|
+
return undefined;
|
|
97
|
+
// The input's discriminant is restored by parse whatever a case declares of it.
|
|
98
|
+
if (roots.input !== undefined && roots.locals?.get(path[0] ?? "") === undefined && path[0] === roots.input.sum.discriminant)
|
|
99
|
+
return undefined;
|
|
100
|
+
const local = path.length > 0 ? roots.locals?.get(path[0]) : undefined;
|
|
101
|
+
// Every case a sum may still hold is walked, so a field one of them leaves
|
|
102
|
+
// out is found whichever case is declared first.
|
|
103
|
+
const from = (current, index) => {
|
|
104
|
+
if (current === undefined)
|
|
105
|
+
return undefined;
|
|
106
|
+
if (current.kind === "optional")
|
|
107
|
+
return index;
|
|
108
|
+
if (index === path.length)
|
|
109
|
+
return undefined;
|
|
110
|
+
const key = path[index];
|
|
111
|
+
// An entry of a record, or an element of an array, read by its key may be missing.
|
|
112
|
+
if (current.kind === "record" || current.kind === "array")
|
|
113
|
+
return index + 1;
|
|
114
|
+
if (current.kind === "object") {
|
|
115
|
+
const { shape } = current;
|
|
116
|
+
// Below the root a field the object does not declare is one left out; at the root the name may be a local or a dependency the scope does not list.
|
|
117
|
+
if (!Object.hasOwn(shape, key))
|
|
118
|
+
return index > (local === undefined ? 0 : 1) || (local === undefined && roots.declared?.has(key)) ? index : undefined;
|
|
119
|
+
return from(shape[key], index + 1);
|
|
120
|
+
}
|
|
121
|
+
if (current.kind === "variants") {
|
|
122
|
+
const sum = current;
|
|
123
|
+
if (key === sum.discriminant)
|
|
124
|
+
return undefined;
|
|
125
|
+
const cases = casesLeft(sum, path.slice(0, index), facts).map(tag => sum.variants[tag].shape);
|
|
126
|
+
if (cases.some(shape => !Object.hasOwn(shape, key)))
|
|
127
|
+
return index;
|
|
128
|
+
const found = cases.map(shape => from(shape[key], index + 1)).filter((at) => at !== undefined);
|
|
129
|
+
return found.length === 0 ? undefined : Math.min(...found);
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
};
|
|
133
|
+
return from(local ?? roots.scope, local === undefined ? 0 : 1);
|
|
134
|
+
}
|
|
135
|
+
// What the choices around each choose settle when it is read: the condition of
|
|
136
|
+
// each enclosing choose, held in its yes and failed in its no. A choose reached
|
|
137
|
+
// under different facts keeps none, since neither holds of every read of it.
|
|
138
|
+
export function choiceFacts(template) {
|
|
139
|
+
const found = new Map();
|
|
140
|
+
function visit(value, facts) {
|
|
141
|
+
const node = nodeOf(value);
|
|
142
|
+
if (node?.kind === "choose") {
|
|
143
|
+
const known = found.get(node);
|
|
144
|
+
const same = known !== undefined && known.length === facts.length && known.every((fact, index) => fact.rule === facts[index].rule && fact.outcome === facts[index].outcome);
|
|
145
|
+
found.set(node, found.has(node) && !same ? undefined : facts);
|
|
146
|
+
visit(node.yes, [...facts, ...factsOf(node.condition, true)]);
|
|
147
|
+
visit(node.no, [...facts, ...factsOf(node.condition, false)]);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
childrenOf(value).forEach(child => visit(child, facts));
|
|
151
|
+
}
|
|
152
|
+
visit(template, []);
|
|
153
|
+
return new Map([...found].map(([node, facts]) => [node, facts ?? []]));
|
|
154
|
+
}
|
|
155
|
+
export function casesLeft(sum, at, facts) {
|
|
156
|
+
let tags = Object.keys(sum.variants);
|
|
157
|
+
for (const { rule, outcome } of facts) {
|
|
158
|
+
if (rule.kind !== "compare" || (rule.operator !== "==" && rule.operator !== "!="))
|
|
159
|
+
continue;
|
|
160
|
+
for (const [term, bound] of [[rule.left, rule.right], [rule.right, rule.left]]) {
|
|
161
|
+
if (!isTerm(term) || typeof bound !== "string")
|
|
162
|
+
continue;
|
|
163
|
+
const data = termData(term);
|
|
164
|
+
if (data.kind !== "position" || data.measure !== "value" || data.path.length !== at.length + 1)
|
|
165
|
+
continue;
|
|
166
|
+
if (!at.every((key, index) => data.path[index] === key) || data.path[at.length] !== sum.discriminant)
|
|
167
|
+
continue;
|
|
168
|
+
const equal = (rule.operator === "==") === outcome;
|
|
169
|
+
tags = tags.filter(tag => (tag === bound) === equal);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return tags;
|
|
173
|
+
}
|
|
174
|
+
// Every schema a path may reach: through each case of a sum still possible
|
|
175
|
+
// that declares the next key.
|
|
176
|
+
function resolve(path, roots, facts) {
|
|
177
|
+
const local = path.length > 0 ? roots.locals?.get(path[0]) : undefined;
|
|
178
|
+
const from = (current, index) => {
|
|
179
|
+
if (current?.kind === "optional")
|
|
180
|
+
current = current.schema;
|
|
181
|
+
if (current === undefined)
|
|
182
|
+
return [];
|
|
183
|
+
if (index === path.length)
|
|
184
|
+
return [current];
|
|
185
|
+
const key = path[index];
|
|
186
|
+
if (current.kind === "object") {
|
|
187
|
+
const { shape } = current;
|
|
188
|
+
return Object.hasOwn(shape, key) ? from(shape[key], index + 1) : [];
|
|
189
|
+
}
|
|
190
|
+
if (current.kind === "variants") {
|
|
191
|
+
const sum = current;
|
|
192
|
+
return casesLeft(sum, path.slice(0, index), facts)
|
|
193
|
+
.filter(tag => Object.hasOwn(sum.variants[tag].shape, key))
|
|
194
|
+
.flatMap(tag => from(sum.variants[tag].shape[key], index + 1));
|
|
195
|
+
}
|
|
196
|
+
return [];
|
|
197
|
+
};
|
|
198
|
+
return from(local ?? roots.scope, local === undefined ? 0 : 1);
|
|
199
|
+
}
|
|
200
|
+
// The same over a model: each choice is read under what the choices around it
|
|
201
|
+
// settled, and a local is read as the schema it was bound under.
|
|
202
|
+
export function leftOutReadInModel(template, roots, facts = []) {
|
|
203
|
+
const node = nodeOf(template);
|
|
204
|
+
const within = (name, schema) => ({ ...roots, locals: new Map([...(roots.locals ?? []), [name, schema]]) });
|
|
205
|
+
switch (node?.kind) {
|
|
206
|
+
case "choose":
|
|
207
|
+
return leftOutReadIn(node.condition, roots, facts)
|
|
208
|
+
?? leftOutReadInModel(node.yes, roots, [...facts, ...factsOf(node.condition, true)])
|
|
209
|
+
?? leftOutReadInModel(node.no, roots, [...facts, ...factsOf(node.condition, false)]);
|
|
210
|
+
case "bind":
|
|
211
|
+
return leftOutReadInModel(node.value, roots, facts) ?? leftOutReadInModel(node.body, within(node.name, node.schema), facts);
|
|
212
|
+
case "map":
|
|
213
|
+
return leftOutReadInModel(node.values, roots, facts) ?? leftOutReadInModel(node.body, within(node.name, node.element), facts);
|
|
214
|
+
case "fold": {
|
|
215
|
+
const body = { ...within(node.name, node.element) };
|
|
216
|
+
return leftOutReadInModel(node.values, roots, facts) ?? leftOutReadInModel(node.initial, roots, facts)
|
|
217
|
+
?? leftOutReadInModel(node.body, { ...body, locals: new Map([...(body.locals ?? []), [node.accumulator, node.output]]) }, facts);
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
for (const child of childrenOf(template)) {
|
|
221
|
+
const found = leftOutReadInModel(child, roots, facts);
|
|
222
|
+
if (found !== undefined)
|
|
223
|
+
return found;
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=absence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"absence.js","sourceRoot":"","sources":["../src/absence.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,U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CAAC,CAAC;YACZ,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAoB,CAAC,EAAE,CAAC;YACjE,OAAO,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC;mBACjG,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAmB,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAClJ,CAAC;QACD;YACE,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzC,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBACtD,IAAI,KAAK,KAAK,SAAS;oBAAE,OAAO,KAAK,CAAC;YACxC,CAAC;YACD,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { Translation } from "./model.js";
|
|
2
|
+
import type { DeclaredDependencies, Resolved, Supplied } from "./dependency.js";
|
|
3
|
+
import type { AnyVariantsSchema, Infer, Schema, Tags, VariantOf } from "./schema.js";
|
|
4
|
+
import type { CompareRule, Distinction, Rule, Term, TermOf } from "./rule.js";
|
|
5
|
+
export interface Execution<Result, Effect> {
|
|
6
|
+
readonly result: Result;
|
|
7
|
+
readonly effects: readonly Effect[];
|
|
8
|
+
}
|
|
9
|
+
export interface Todo {
|
|
10
|
+
readonly kind: "todo";
|
|
11
|
+
readonly reason: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Decision<Input, Result, Effect, Deps = unknown> {
|
|
14
|
+
readonly kind: "decision";
|
|
15
|
+
readonly id: string;
|
|
16
|
+
run(input: Input, deps: Deps): Execution<Result, Effect> | Promise<Execution<Result, Effect>>;
|
|
17
|
+
}
|
|
18
|
+
export interface Guard<Input, Result, Effect, Deps = unknown> {
|
|
19
|
+
readonly kind: "guard";
|
|
20
|
+
readonly condition: Rule;
|
|
21
|
+
orElse(input: Input, deps: Deps): Execution<Result, Effect>;
|
|
22
|
+
}
|
|
23
|
+
export type Handler<Input, Result, Effect, Deps = unknown> = {
|
|
24
|
+
bivariant(input: Input, deps: Deps): Execution<Result, Effect>;
|
|
25
|
+
}["bivariant"];
|
|
26
|
+
export interface Match<Input, Result, Effect, Deps = unknown> {
|
|
27
|
+
readonly kind: "match";
|
|
28
|
+
readonly on: Term<string>;
|
|
29
|
+
readonly cases: Readonly<Record<string, Handler<Input, Result, Effect, Deps>>>;
|
|
30
|
+
}
|
|
31
|
+
export type Otherwise<Input, Result, Effect, Deps = unknown> = Handler<Input, Result, Effect, Deps> | Match<Input, Result, Effect, Deps>;
|
|
32
|
+
export interface RulesDecision<Input, Result, Effect, Deps = unknown> {
|
|
33
|
+
readonly expression?: unknown;
|
|
34
|
+
readonly runs?: unknown;
|
|
35
|
+
readonly translate?: Translation;
|
|
36
|
+
readonly kind: "rules";
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly guards: readonly Guard<Input, Result, Effect, Deps>[];
|
|
39
|
+
readonly otherwise: Otherwise<Input, Result, Effect, Deps>;
|
|
40
|
+
}
|
|
41
|
+
export type Branch = Distinction | Match<unknown, unknown, unknown>;
|
|
42
|
+
export interface ControlPolicy {
|
|
43
|
+
readonly execution: "direct" | "outbox" | "queue";
|
|
44
|
+
readonly idempotency: "required" | "not-required";
|
|
45
|
+
readonly compensation: "automatic" | "manual" | "none";
|
|
46
|
+
readonly exposure?: "normal" | "shadow" | "canary";
|
|
47
|
+
}
|
|
48
|
+
export type ControlTable<Effects extends AnyVariantsSchema> = Readonly<Partial<Record<Tags<Effects>, ControlPolicy | Todo>>>;
|
|
49
|
+
export interface EnsuresClause {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly cases: readonly string[] | undefined;
|
|
52
|
+
readonly rule: Rule;
|
|
53
|
+
}
|
|
54
|
+
export interface EnsuresBuilder<Input, ResultSchema extends Schema<unknown>> {
|
|
55
|
+
when<Tag extends Tags<ResultSchema>>(name: string, cases: readonly Tag[], rule: (input: TermOf<Input>, value: TermOf<VariantOf<ResultSchema, Tag>>) => Rule): EnsuresClause;
|
|
56
|
+
always(name: string, rule: (input: TermOf<Input>, value: TermOf<Infer<ResultSchema>>) => Rule): EnsuresClause;
|
|
57
|
+
}
|
|
58
|
+
export interface Behavior<InputSchema extends AnyVariantsSchema, ResultSchema extends Schema<unknown>, EffectSchema extends AnyVariantsSchema, Requires extends DeclaredDependencies = {}> {
|
|
59
|
+
readonly kind: "behavior";
|
|
60
|
+
readonly name: string;
|
|
61
|
+
readonly description?: string;
|
|
62
|
+
readonly input: InputSchema;
|
|
63
|
+
readonly result: ResultSchema;
|
|
64
|
+
readonly effects: EffectSchema;
|
|
65
|
+
readonly dependencies: Requires;
|
|
66
|
+
readonly ensures: readonly EnsuresClause[];
|
|
67
|
+
readonly disregards: Readonly<Record<string, readonly (readonly string[])[]>>;
|
|
68
|
+
}
|
|
69
|
+
type KeysOfEvery<T> = T extends unknown ? keyof T : never;
|
|
70
|
+
type ValueAt<T, K> = T extends unknown ? (K extends keyof T ? T[K] : never) : never;
|
|
71
|
+
type Merged<T, Keys extends PropertyKey> = {
|
|
72
|
+
readonly [K in Keys]: ValueAt<T, K>;
|
|
73
|
+
};
|
|
74
|
+
type Fielded<T> = Merged<T, KeysOfEvery<T>>;
|
|
75
|
+
type Disregarded<T> = (input: TermOf<T>) => readonly Term<unknown>[];
|
|
76
|
+
export type Disregards<InputSchema extends AnyVariantsSchema> = {
|
|
77
|
+
readonly [Key in Tags<InputSchema> | "$default"]?: Key extends Tags<InputSchema> ? Disregarded<VariantOf<InputSchema, Key>> : Disregarded<Fielded<Infer<InputSchema>>>;
|
|
78
|
+
};
|
|
79
|
+
export type AnyBehavior = Behavior<AnyVariantsSchema, Schema<unknown>, AnyVariantsSchema, DeclaredDependencies>;
|
|
80
|
+
export type BehaviorInput<B> = B extends {
|
|
81
|
+
readonly input: infer Input;
|
|
82
|
+
} ? Infer<Input> : never;
|
|
83
|
+
export type BehaviorResult<B> = B extends {
|
|
84
|
+
readonly result: infer Result;
|
|
85
|
+
} ? Infer<Result> : never;
|
|
86
|
+
export type BehaviorEffect<B> = B extends {
|
|
87
|
+
readonly effects: infer Effect;
|
|
88
|
+
} ? Infer<Effect> : never;
|
|
89
|
+
export type BehaviorDeps<B> = B extends {
|
|
90
|
+
readonly dependencies: infer Requires;
|
|
91
|
+
} ? Resolved<Requires> : never;
|
|
92
|
+
export type SuppliedDeps<B> = B extends {
|
|
93
|
+
readonly dependencies: infer Requires;
|
|
94
|
+
} ? Supplied<Requires> : never;
|
|
95
|
+
export type ImplementationCases<B extends AnyBehavior> = {
|
|
96
|
+
readonly [Tag in Tags<B["input"]>]: Decision<VariantOf<B["input"], Tag>, BehaviorResult<B>, BehaviorEffect<B>, BehaviorDeps<B>> | RulesDecision<VariantOf<B["input"], Tag>, BehaviorResult<B>, BehaviorEffect<B>, BehaviorDeps<B>> | Todo;
|
|
97
|
+
};
|
|
98
|
+
export interface Implementation<B extends AnyBehavior> {
|
|
99
|
+
readonly kind: "implementation";
|
|
100
|
+
readonly behavior: B;
|
|
101
|
+
readonly cases: ImplementationCases<B>;
|
|
102
|
+
readonly controls: ControlTable<B["effects"]>;
|
|
103
|
+
readonly pipeline?: readonly [Implementation<AnyBehavior>, Implementation<AnyBehavior>];
|
|
104
|
+
readonly external?: {
|
|
105
|
+
readonly reason: string;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export type AnyImplementation = Implementation<AnyBehavior>;
|
|
109
|
+
export declare class SpecificationError extends Error {
|
|
110
|
+
constructor(message: string);
|
|
111
|
+
}
|
|
112
|
+
export declare class TodoDecision extends SpecificationError {
|
|
113
|
+
readonly behavior: string;
|
|
114
|
+
readonly variant: string;
|
|
115
|
+
readonly reason: string;
|
|
116
|
+
constructor(behavior: string, variant: string, reason: string);
|
|
117
|
+
}
|
|
118
|
+
export declare function match<Input, Result, Effect, Deps = unknown, Tag extends string = string>(select: (input: TermOf<Input>) => Term<Tag>, cases: {
|
|
119
|
+
readonly [Case in Tag]: (input: Input, deps: Deps) => Execution<Result, Effect>;
|
|
120
|
+
}): Match<Input, Result, Effect, Deps>;
|
|
121
|
+
export type ValueDepsOf<Deps> = {
|
|
122
|
+
readonly [K in keyof Deps as Deps[K] extends (...args: never[]) => unknown ? never : K]: Deps[K];
|
|
123
|
+
};
|
|
124
|
+
export declare function action<Input, Result, Effect, Deps = unknown>(id: string, body: {
|
|
125
|
+
readonly guards?: (input: TermOf<NoInfer<Input>>, deps: TermOf<ValueDepsOf<NoInfer<Deps>>>) => readonly Guard<NoInfer<Input>, NoInfer<Result>, NoInfer<Effect>, NoInfer<Deps>>[];
|
|
126
|
+
readonly run: Otherwise<NoInfer<Input>, NoInfer<Result>, NoInfer<Effect>, NoInfer<Deps>>;
|
|
127
|
+
}): RulesDecision<Input, Result, Effect, Deps>;
|
|
128
|
+
export declare function todo(reason?: string): Todo;
|
|
129
|
+
declare const caseOnlyBrand: unique symbol;
|
|
130
|
+
export interface CaseOnly<Tag extends string = string> {
|
|
131
|
+
readonly kind: "case";
|
|
132
|
+
readonly case: Tag;
|
|
133
|
+
readonly [caseOnlyBrand]: true;
|
|
134
|
+
}
|
|
135
|
+
export declare function caseOf<const Tag extends string>(tag: Tag): CaseOnly<Tag>;
|
|
136
|
+
export declare function isCaseOnly(value: unknown): value is CaseOnly;
|
|
137
|
+
export declare function isTodo(value: unknown): value is Todo;
|
|
138
|
+
export declare function behavior<const InputSchema extends AnyVariantsSchema, const ResultSchema extends Schema<unknown>, const EffectSchema extends AnyVariantsSchema, const Requires extends DeclaredDependencies = {}>(name: string, options: {
|
|
139
|
+
readonly description?: string;
|
|
140
|
+
readonly input: InputSchema;
|
|
141
|
+
readonly result: ResultSchema;
|
|
142
|
+
readonly effects: EffectSchema;
|
|
143
|
+
readonly dependencies?: Requires;
|
|
144
|
+
readonly ensures?: (clause: EnsuresBuilder<Infer<InputSchema>, ResultSchema>) => readonly EnsuresClause[];
|
|
145
|
+
readonly disregards?: Disregards<NoInfer<InputSchema>>;
|
|
146
|
+
}): Behavior<InputSchema, ResultSchema, EffectSchema, Requires>;
|
|
147
|
+
export declare function brokenEnsures(definition: AnyBehavior, input: unknown, result: unknown): EnsuresClause | undefined;
|
|
148
|
+
type CaseDecision<B extends AnyBehavior, Input> = Decision<Input, BehaviorResult<B>, BehaviorEffect<B>, BehaviorDeps<B>> | RulesDecision<Input, BehaviorResult<B>, BehaviorEffect<B>, BehaviorDeps<B>> | Todo;
|
|
149
|
+
export type CasesWithDefault<B extends AnyBehavior> = ImplementationCases<B> | (Partial<ImplementationCases<B>> & {
|
|
150
|
+
readonly $default: CaseDecision<B, BehaviorInput<B>>;
|
|
151
|
+
});
|
|
152
|
+
export declare function implement<B extends AnyBehavior>(definition: B, options: NoInfer<{
|
|
153
|
+
readonly cases: CasesWithDefault<B>;
|
|
154
|
+
readonly controls?: ControlTable<B["effects"]>;
|
|
155
|
+
readonly constructs?: readonly Schema<unknown>[];
|
|
156
|
+
}>): Implementation<NoInfer<B>>;
|
|
157
|
+
export declare function external<B extends AnyBehavior>(definition: B, reason: string): Implementation<B>;
|
|
158
|
+
export declare function isBehavior(value: unknown): value is AnyBehavior;
|
|
159
|
+
export interface ComparisonReached {
|
|
160
|
+
readonly rule: CompareRule;
|
|
161
|
+
readonly scope: unknown;
|
|
162
|
+
}
|
|
163
|
+
export interface WayTaken {
|
|
164
|
+
readonly decision: string;
|
|
165
|
+
readonly steps: readonly {
|
|
166
|
+
readonly distinction: Branch;
|
|
167
|
+
readonly outcome: boolean | string;
|
|
168
|
+
}[];
|
|
169
|
+
readonly within?: unknown;
|
|
170
|
+
}
|
|
171
|
+
export interface ArmTaken {
|
|
172
|
+
readonly decision: string;
|
|
173
|
+
readonly guard: number;
|
|
174
|
+
readonly arm: string;
|
|
175
|
+
}
|
|
176
|
+
export declare function perform<B extends AnyBehavior>(implementation: Implementation<B>, input: BehaviorInput<B>, deps?: SuppliedDeps<B>): Promise<Execution<BehaviorResult<B>, BehaviorEffect<B>>>;
|
|
177
|
+
export declare function runTraced<B extends AnyBehavior>(implementation: Implementation<B>, input: BehaviorInput<B>, deps?: SuppliedDeps<B>): Promise<{
|
|
178
|
+
readonly execution: Execution<BehaviorResult<B>, BehaviorEffect<B>>;
|
|
179
|
+
readonly arms: readonly ArmTaken[];
|
|
180
|
+
readonly comparisons: readonly ComparisonReached[];
|
|
181
|
+
readonly way: WayTaken | undefined;
|
|
182
|
+
readonly iterations: readonly WayTaken[];
|
|
183
|
+
}>;
|
|
184
|
+
export declare function performSync<B extends AnyBehavior>(implementation: Implementation<B>, input: BehaviorInput<B>, deps?: BehaviorDeps<B>): Execution<BehaviorResult<B>, BehaviorEffect<B>>;
|
|
185
|
+
export declare function traceSync(implementation: AnyImplementation, input: unknown, deps?: unknown): {
|
|
186
|
+
readonly comparisons: readonly ComparisonReached[];
|
|
187
|
+
readonly way: WayTaken | undefined;
|
|
188
|
+
readonly iterations: readonly WayTaken[];
|
|
189
|
+
readonly ended?: true;
|
|
190
|
+
readonly error?: unknown;
|
|
191
|
+
};
|
|
192
|
+
export declare function comparisonsReached(implementation: AnyImplementation, input: unknown, deps?: unknown): readonly ComparisonReached[];
|
|
193
|
+
export {};
|