@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
package/dist/machine.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// A single executable expression describes both production transitions and
|
|
2
|
+
// the graph checked by exhaustive exploration. No second model can drift from
|
|
3
|
+
// the code that runs. Completeness requires a finite command domain.
|
|
4
|
+
import { SpecificationError } from "./behavior.js";
|
|
5
|
+
import { EvaluationLimit } from "./exact.js";
|
|
6
|
+
import { childrenOf, interpret, nodeOf } from "./model.js";
|
|
7
|
+
import { rootTerm } from "./rule.js";
|
|
8
|
+
export function effect(name, state, options = {}) {
|
|
9
|
+
return { kind: "effect", name, state,
|
|
10
|
+
...(Object.hasOwn(options, "failure") ? { failure: options.failure } : {}),
|
|
11
|
+
...(options.ifUnchanged === undefined ? {} : { ifUnchanged: options.ifUnchanged }),
|
|
12
|
+
...(options.writes === undefined ? {} : { writes: options.writes }) };
|
|
13
|
+
}
|
|
14
|
+
export function machine(name, definition) {
|
|
15
|
+
if (Object.hasOwn(definition, "invariants") || Object.hasOwn(definition, "transitions")) {
|
|
16
|
+
throw new SpecificationError(`Machine ${name} verification properties belong in a separate specifyMachine declaration`);
|
|
17
|
+
}
|
|
18
|
+
if (definition.initial.length === 0)
|
|
19
|
+
throw new SpecificationError(`Machine ${name} starts from no state`);
|
|
20
|
+
const initial = definition.initial.map((value, index) => parse(definition.state, value, `Initial state ${index + 1}`));
|
|
21
|
+
const update = definition.update(rootTerm("state"), rootTerm("command"));
|
|
22
|
+
if (!update || (!nodeOf(update) && !Object.hasOwn(update, "state") && !Object.hasOwn(update, "effects")))
|
|
23
|
+
throw new SpecificationError(`Machine ${name} must return a state`);
|
|
24
|
+
if (hasCall(update))
|
|
25
|
+
throw new SpecificationError(`Machine ${name} cannot call external dependencies in a transition`);
|
|
26
|
+
return { kind: "machine", name, state: definition.state, command: definition.command, initial, update };
|
|
27
|
+
}
|
|
28
|
+
export function isMachine(value) {
|
|
29
|
+
if (typeof value !== "object" || value === null)
|
|
30
|
+
return false;
|
|
31
|
+
const candidate = value;
|
|
32
|
+
return candidate.kind === "machine" && typeof candidate.name === "string" &&
|
|
33
|
+
typeof candidate.state?.parse === "function" && typeof candidate.command?.parse === "function" &&
|
|
34
|
+
Array.isArray(candidate.initial) && candidate.update !== undefined;
|
|
35
|
+
}
|
|
36
|
+
function hasCall(value) {
|
|
37
|
+
if (nodeOf(value)?.kind === "call")
|
|
38
|
+
return true;
|
|
39
|
+
return childrenOf(value).some(hasCall);
|
|
40
|
+
}
|
|
41
|
+
function parse(schema, value, context) {
|
|
42
|
+
const result = schema.parse(value);
|
|
43
|
+
if (!result.success)
|
|
44
|
+
throw new SpecificationError(`${context}: ${result.issues.map(issue => `${issue.path}: ${issue.message}`).join("; ")}`);
|
|
45
|
+
return result.value;
|
|
46
|
+
}
|
|
47
|
+
export class MachineFailure extends SpecificationError {
|
|
48
|
+
steps;
|
|
49
|
+
constructor(message, steps) {
|
|
50
|
+
super(message);
|
|
51
|
+
this.steps = steps;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export class MachineLimitError extends SpecificationError {
|
|
55
|
+
steps;
|
|
56
|
+
constructor(message, steps = []) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.steps = steps;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Evaluates the same expression used by the verification tools. Emissions are internal
|
|
62
|
+
// commands, not I/O. The caller decides when and where to persist the result.
|
|
63
|
+
// `fails` says whether an effect fails and `dies` whether the process dies at a point of a
|
|
64
|
+
// command with effects (before the first, and after each); by default neither happens, since
|
|
65
|
+
// an effect is something the caller performs and this function only follows the machine.
|
|
66
|
+
export function runMachine(definition, state, command, options = {}) {
|
|
67
|
+
const maxCommands = positiveLimit(options.maxCommands, 1000, "maxCommands");
|
|
68
|
+
let current = parse(definition.state, state, "Current state");
|
|
69
|
+
const pending = [command];
|
|
70
|
+
const steps = [];
|
|
71
|
+
while (pending.length > 0) {
|
|
72
|
+
if (steps.length === maxCommands)
|
|
73
|
+
throw new MachineLimitError(`Machine ${definition.name} exceeded ${maxCommands} commands`, [...steps]);
|
|
74
|
+
try {
|
|
75
|
+
const input = parse(definition.command, pending.shift(), "Command");
|
|
76
|
+
const output = interpret(definition.update, { state: current, command: input });
|
|
77
|
+
if (output === null || typeof output !== "object" || (!Object.hasOwn(output, "state") && !Object.hasOwn(output, "effects"))) {
|
|
78
|
+
throw new SpecificationError("A machine transition must return a state");
|
|
79
|
+
}
|
|
80
|
+
let next;
|
|
81
|
+
let performed;
|
|
82
|
+
let stopped = false;
|
|
83
|
+
let died;
|
|
84
|
+
if (Object.hasOwn(output, "effects")) {
|
|
85
|
+
if (!Array.isArray(output.effects))
|
|
86
|
+
throw new SpecificationError("Effects must be an array");
|
|
87
|
+
next = current;
|
|
88
|
+
performed = [];
|
|
89
|
+
const declaredEffects = output.effects;
|
|
90
|
+
for (const [index, item] of declaredEffects.entries()) {
|
|
91
|
+
if (options.dies?.({ completed: index, command: input })) {
|
|
92
|
+
died = { after: index };
|
|
93
|
+
stopped = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
const declared = item;
|
|
97
|
+
if (declared === null || typeof declared !== "object" || typeof declared.name !== "string")
|
|
98
|
+
throw new SpecificationError("An effect must name itself");
|
|
99
|
+
if (options.fails?.({ name: declared.name, index, command: input })) {
|
|
100
|
+
performed.push({ name: declared.name, outcome: "failed" });
|
|
101
|
+
if (Object.hasOwn(declared, "failure"))
|
|
102
|
+
next = parse(definition.state, declared.failure, `Effect ${declared.name} failure state`);
|
|
103
|
+
stopped = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
next = parse(definition.state, declared.state, `Effect ${declared.name} state`);
|
|
107
|
+
performed.push({ name: declared.name, outcome: "succeeded" });
|
|
108
|
+
}
|
|
109
|
+
if (!stopped && declaredEffects.length > 0 && options.dies?.({ completed: declaredEffects.length, command: input })) {
|
|
110
|
+
died = { after: declaredEffects.length };
|
|
111
|
+
stopped = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
next = parse(definition.state, output.state, `Command ${steps.length + 1} next state`);
|
|
116
|
+
steps.push({ command: input, before: current, after: next, ...(performed === undefined ? {} : { performed }), ...(died === undefined ? {} : { died }) });
|
|
117
|
+
if (died !== undefined)
|
|
118
|
+
pending.length = 0;
|
|
119
|
+
const emitted = output.commands === undefined || stopped ? [] : output.commands;
|
|
120
|
+
if (!Array.isArray(emitted))
|
|
121
|
+
throw new SpecificationError("Emitted commands must be an array");
|
|
122
|
+
const validated = emitted.map((value) => parse(definition.command, value, "Emitted command"));
|
|
123
|
+
current = next;
|
|
124
|
+
pending.push(...validated);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
if (error instanceof EvaluationLimit)
|
|
128
|
+
throw new MachineLimitError(error.message, [...steps]);
|
|
129
|
+
throw new MachineFailure(error instanceof Error ? error.message : String(error), steps);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { state: current, steps };
|
|
133
|
+
}
|
|
134
|
+
// What a command does in a state, read once and checked against the schemas.
|
|
135
|
+
export function evaluateCommand(definition, state, command) {
|
|
136
|
+
const output = interpret(definition.update, { state, command });
|
|
137
|
+
if (output === null || typeof output !== "object" || (!Object.hasOwn(output, "state") && !Object.hasOwn(output, "effects"))) {
|
|
138
|
+
throw new SpecificationError("A machine transition must return a state");
|
|
139
|
+
}
|
|
140
|
+
const emitted = output.commands === undefined ? [] : output.commands;
|
|
141
|
+
if (!Array.isArray(emitted))
|
|
142
|
+
throw new SpecificationError("Emitted commands must be an array");
|
|
143
|
+
const commands = emitted.map((value) => parse(definition.command, value, "Emitted command"));
|
|
144
|
+
if (!Object.hasOwn(output, "effects"))
|
|
145
|
+
return { state: parse(definition.state, output.state, "Next state"), commands };
|
|
146
|
+
if (!Array.isArray(output.effects))
|
|
147
|
+
throw new SpecificationError("Effects must be an array");
|
|
148
|
+
const effects = output.effects.map(item => {
|
|
149
|
+
const declared = item;
|
|
150
|
+
if (declared === null || typeof declared !== "object" || typeof declared.name !== "string")
|
|
151
|
+
throw new SpecificationError("An effect must name itself");
|
|
152
|
+
if (declared.ifUnchanged !== undefined && typeof declared.ifUnchanged !== "boolean")
|
|
153
|
+
throw new SpecificationError(`Effect ${declared.name}: ifUnchanged must be a boolean`);
|
|
154
|
+
if (declared.writes !== undefined && (!Array.isArray(declared.writes) || declared.writes.some(item => typeof item !== "string"))) {
|
|
155
|
+
throw new SpecificationError(`Effect ${declared.name}: writes must be a list of field names`);
|
|
156
|
+
}
|
|
157
|
+
return { name: declared.name, state: parse(definition.state, declared.state, `Effect ${declared.name} state`), ifUnchanged: declared.ifUnchanged === true,
|
|
158
|
+
...(declared.writes === undefined ? {} : { writes: declared.writes }) };
|
|
159
|
+
});
|
|
160
|
+
return { effects, commands };
|
|
161
|
+
}
|
|
162
|
+
// Every way a command can end when each effect it runs may succeed or fail (and, with `crashes`,
|
|
163
|
+
// the process may die before the first effect and after each one), found by replaying the run
|
|
164
|
+
// with each choice taken the other way once.
|
|
165
|
+
export function runMachineOutcomes(definition, state, command, options = {}) {
|
|
166
|
+
const maxOutcomes = positiveLimit(options.maxOutcomes, 1000, "maxOutcomes");
|
|
167
|
+
const outcomes = [];
|
|
168
|
+
const tapes = [[]];
|
|
169
|
+
for (let next = 0; next < tapes.length; next++) {
|
|
170
|
+
const tape = tapes[next];
|
|
171
|
+
if (outcomes.length === maxOutcomes) {
|
|
172
|
+
outcomes.push({ error: new MachineLimitError(`Machine ${definition.name} exceeded ${maxOutcomes} outcomes for one command`) });
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
const decided = tape;
|
|
176
|
+
let evaluated = 0;
|
|
177
|
+
const choose = () => {
|
|
178
|
+
const choice = evaluated++;
|
|
179
|
+
if (choice < decided.length)
|
|
180
|
+
return decided[choice];
|
|
181
|
+
tapes.push([...decided, ...Array.from({ length: choice - decided.length }, () => false), true]);
|
|
182
|
+
return false;
|
|
183
|
+
};
|
|
184
|
+
const { crashes, ...limits } = options;
|
|
185
|
+
try {
|
|
186
|
+
outcomes.push({ result: runMachine(definition, state, command, { ...limits, fails: choose, ...(crashes ? { dies: choose } : {}) }) });
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
outcomes.push({ error });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return outcomes;
|
|
193
|
+
}
|
|
194
|
+
export function positiveLimit(value, fallback, name) {
|
|
195
|
+
const result = value ?? fallback;
|
|
196
|
+
if (!Number.isSafeInteger(result) || result < 1)
|
|
197
|
+
throw new SpecificationError(`${name} must be a positive safe integer`);
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine.js","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,qEAAqE;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC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{ AnyBehavior, Execution, RulesDecision, Branch } from "./behavior.js";
|
|
4
|
+
import type { Rule, Term, TermOf, ComparisonObserver } from "./rule.js";
|
|
5
|
+
import type { Schema, AnyVariantsSchema, Infer, Tags, VariantOf } from "./schema.js";
|
|
6
|
+
import type { Step } from "./ways.js";
|
|
7
|
+
import type { Temporal as TemporalTypes } from "temporal-spec";
|
|
8
|
+
import type { CalendarUnit, ClockUnit, Overflow } from "./temporal.js";
|
|
9
|
+
declare const EXPRESSION: unique symbol;
|
|
10
|
+
export interface Expression<T> {
|
|
11
|
+
readonly [EXPRESSION]: Node;
|
|
12
|
+
readonly output?: T;
|
|
13
|
+
}
|
|
14
|
+
export type Template<T> = Term<T> | Expression<T> | (T extends readonly (infer E)[] ? readonly Template<E>[] : T extends object ? {
|
|
15
|
+
readonly [K in keyof T]: Template<T[K]>;
|
|
16
|
+
} : T);
|
|
17
|
+
export type Node = {
|
|
18
|
+
readonly kind: "bind";
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly schema: Schema<unknown>;
|
|
21
|
+
readonly value: unknown;
|
|
22
|
+
readonly body: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "map";
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly element: Schema<unknown>;
|
|
27
|
+
readonly output: Schema<unknown>;
|
|
28
|
+
readonly values: unknown;
|
|
29
|
+
readonly body: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: "fold";
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly accumulator: string;
|
|
34
|
+
readonly element: Schema<unknown>;
|
|
35
|
+
readonly output: Schema<unknown>;
|
|
36
|
+
readonly values: unknown;
|
|
37
|
+
readonly initial: unknown;
|
|
38
|
+
readonly body: unknown;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "call";
|
|
41
|
+
readonly dependency: Term<unknown>;
|
|
42
|
+
readonly input: unknown;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "choose";
|
|
45
|
+
readonly condition: Rule;
|
|
46
|
+
readonly yes: unknown;
|
|
47
|
+
readonly no: unknown;
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: "construct";
|
|
50
|
+
readonly schema: Schema<unknown>;
|
|
51
|
+
readonly value: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
readonly kind: "operation";
|
|
54
|
+
readonly operator: "add" | "subtract" | "multiply" | "divide" | "quotient" | "concat";
|
|
55
|
+
readonly left: unknown;
|
|
56
|
+
readonly right: unknown;
|
|
57
|
+
} | {
|
|
58
|
+
readonly kind: "temporal";
|
|
59
|
+
readonly operator: "plus" | "minus" | "between";
|
|
60
|
+
readonly left: unknown;
|
|
61
|
+
readonly right: unknown;
|
|
62
|
+
readonly unit: string;
|
|
63
|
+
readonly overflow: Overflow;
|
|
64
|
+
};
|
|
65
|
+
export declare function bind<Value, Result>(schema: Schema<Value>, value: NoInfer<Template<Value>>, build: (value: TermOf<Value>) => Template<Result>): Expression<Result>;
|
|
66
|
+
export declare function matchValue<S extends AnyVariantsSchema, Result>(schema: S, value: NoInfer<Template<Infer<S>>>, cases: {
|
|
67
|
+
readonly [Tag in Tags<S>]: (value: TermOf<VariantOf<S, Tag>>) => Template<Result>;
|
|
68
|
+
}): Expression<Result>;
|
|
69
|
+
export declare function map<Element, Result>(element: Schema<Element>, output: Schema<Result>, values: Template<readonly NoInfer<Element>[]>, build: (value: TermOf<Element>) => NoInfer<Template<Result>>): Expression<readonly Result[]>;
|
|
70
|
+
export declare function fold<Element, Accumulator>(element: Schema<Element>, output: Schema<Accumulator>, values: Template<readonly NoInfer<Element>[]>, initial: NoInfer<Template<Accumulator>>, build: (accumulator: TermOf<Accumulator>, value: TermOf<Element>) => NoInfer<Template<Accumulator>>): Expression<Accumulator>;
|
|
71
|
+
export declare function isAnswer(local: string): boolean;
|
|
72
|
+
export declare function bindingsOf(template: unknown): readonly (readonly [string, Schema<unknown>])[];
|
|
73
|
+
export declare function answersOf(template: unknown): readonly {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly schema: Schema<unknown>;
|
|
76
|
+
readonly dependency: string;
|
|
77
|
+
readonly input: unknown;
|
|
78
|
+
}[];
|
|
79
|
+
export declare function localRoots(value: unknown): readonly string[];
|
|
80
|
+
export declare function choose<Yes, No = Yes>(condition: Rule, yes: Template<Yes>, no: Template<No>): Expression<Yes | No>;
|
|
81
|
+
export declare function construct<T>(schema: Schema<T>, value: NoInfer<Template<T extends object ? Pick<T, Extract<keyof T, string | number>> : T>>): Expression<T>;
|
|
82
|
+
export declare function call<Input, Output>(dependency: Term<(input: Input) => Output>, input: NoInfer<Template<Input>>): Expression<Output>;
|
|
83
|
+
export declare function dependencyName(dependency: Term<unknown>): string;
|
|
84
|
+
export declare function concat(left: Template<string>, right: Template<string>): Expression<string>;
|
|
85
|
+
export declare function arithmetic<T extends number | bigint | Rational | Decimal>(operator: "add" | "subtract" | "multiply" | "divide", left: Template<T>, right: NoInfer<Template<T>>): Expression<T>;
|
|
86
|
+
type PlainDate = TemporalTypes.PlainDate;
|
|
87
|
+
type PlainTime = TemporalTypes.PlainTime;
|
|
88
|
+
type PlainDateTime = TemporalTypes.PlainDateTime;
|
|
89
|
+
type Instant = TemporalTypes.Instant;
|
|
90
|
+
interface MoveOptions {
|
|
91
|
+
readonly overflow?: Overflow;
|
|
92
|
+
}
|
|
93
|
+
export declare function plus(value: Template<PlainDate>, amount: Template<number>, unit: CalendarUnit, options?: MoveOptions): Expression<PlainDate>;
|
|
94
|
+
export declare function plus(value: Template<PlainTime>, amount: Template<number>, unit: ClockUnit): Expression<PlainTime>;
|
|
95
|
+
export declare function plus(value: Template<PlainDateTime>, amount: Template<number>, unit: CalendarUnit | ClockUnit, options?: MoveOptions): Expression<PlainDateTime>;
|
|
96
|
+
export declare function plus(value: Template<Instant>, amount: Template<number>, unit: ClockUnit): Expression<Instant>;
|
|
97
|
+
export declare function minus(value: Template<PlainDate>, amount: Template<number>, unit: CalendarUnit, options?: MoveOptions): Expression<PlainDate>;
|
|
98
|
+
export declare function minus(value: Template<PlainTime>, amount: Template<number>, unit: ClockUnit): Expression<PlainTime>;
|
|
99
|
+
export declare function minus(value: Template<PlainDateTime>, amount: Template<number>, unit: CalendarUnit | ClockUnit, options?: MoveOptions): Expression<PlainDateTime>;
|
|
100
|
+
export declare function minus(value: Template<Instant>, amount: Template<number>, unit: ClockUnit): Expression<Instant>;
|
|
101
|
+
export declare function between(start: Template<PlainDate>, end: Template<PlainDate>, unit: CalendarUnit): Expression<number>;
|
|
102
|
+
export declare function between(start: Template<PlainTime>, end: Template<PlainTime>, unit: ClockUnit): Expression<number>;
|
|
103
|
+
export declare function between(start: Template<PlainDateTime>, end: Template<PlainDateTime>, unit: CalendarUnit | ClockUnit): Expression<number>;
|
|
104
|
+
export declare function between(start: Template<Instant>, end: Template<Instant>, unit: ClockUnit): Expression<number>;
|
|
105
|
+
export declare function quotient(left: Template<number | bigint | Decimal | Rational>, right: Template<number | bigint | Decimal | Rational>): Expression<Rational>;
|
|
106
|
+
export declare function nodeOf(value: unknown): Node | undefined;
|
|
107
|
+
export declare function childrenOf(value: unknown): readonly unknown[];
|
|
108
|
+
export declare function modelDependencyIssue(template: unknown, definition: AnyBehavior, tags: readonly string[]): string | undefined;
|
|
109
|
+
export declare function choicesOf(template: unknown): readonly Extract<Node, {
|
|
110
|
+
kind: "choose";
|
|
111
|
+
}>[];
|
|
112
|
+
export declare function model<Input, Result, Effect, Deps = unknown>(id: string, build: (input: TermOf<NoInfer<Input>>, deps: TermOf<NoInfer<Deps>>) => Template<Execution<NoInfer<Result>, NoInfer<Effect>>>): RulesDecision<Input, Result, Effect, Deps>;
|
|
113
|
+
export declare function interpret(template: unknown, scope: unknown, options?: {
|
|
114
|
+
readonly steps?: number;
|
|
115
|
+
readonly invoke?: (name: string, input: unknown) => unknown;
|
|
116
|
+
readonly observe?: ComparisonObserver;
|
|
117
|
+
readonly distinguish?: (distinction: Branch, outcome: boolean | string) => void;
|
|
118
|
+
readonly arm?: (index: number, outcome: boolean) => void;
|
|
119
|
+
readonly iterate?: (iteration: Node, steps: readonly Step[]) => void;
|
|
120
|
+
readonly onPending?: (pending: PromiseLike<unknown>) => never;
|
|
121
|
+
}): unknown;
|
|
122
|
+
export interface ModelPath {
|
|
123
|
+
readonly value: unknown;
|
|
124
|
+
readonly steps: readonly Step[];
|
|
125
|
+
readonly choices: readonly {
|
|
126
|
+
readonly condition: Rule;
|
|
127
|
+
readonly outcome: boolean;
|
|
128
|
+
}[];
|
|
129
|
+
}
|
|
130
|
+
export declare function modelPaths(template: unknown): Generator<ModelPath>;
|
|
131
|
+
export declare function replaceChildren(template: unknown, values: readonly unknown[]): unknown;
|
|
132
|
+
export declare function inlineInputBindings(template: unknown, schemaAt: (path: readonly string[]) => Schema<unknown> | undefined): unknown;
|
|
133
|
+
export declare function guardsOf(template: unknown): RulesDecision<unknown, unknown, unknown>["guards"];
|
|
134
|
+
export declare function callsIn(template: unknown): readonly {
|
|
135
|
+
readonly dependency: string;
|
|
136
|
+
readonly input: unknown;
|
|
137
|
+
}[];
|
|
138
|
+
export declare function writtenArgument(input: unknown, argument: unknown, value: unknown): unknown;
|
|
139
|
+
export interface IterationEntry {
|
|
140
|
+
readonly node: Extract<Node, {
|
|
141
|
+
kind: "map" | "fold";
|
|
142
|
+
}>;
|
|
143
|
+
readonly steps: readonly Step[];
|
|
144
|
+
}
|
|
145
|
+
export declare function iterationEntries(template: unknown, steps?: readonly Step[]): Generator<IterationEntry>;
|
|
146
|
+
export declare function iterationsOf(template: unknown): readonly Extract<Node, {
|
|
147
|
+
kind: "map" | "fold";
|
|
148
|
+
}>[];
|
|
149
|
+
export declare function localsOf(template: unknown, opaque?: ReadonlySet<string>): readonly {
|
|
150
|
+
readonly name: string;
|
|
151
|
+
readonly schema: Schema<unknown>;
|
|
152
|
+
readonly opaque: boolean;
|
|
153
|
+
}[];
|
|
154
|
+
export declare function fieldsTurnedOn(template: unknown, matters?: (dependency: string, argument: unknown) => boolean): ReadonlySet<string> | undefined;
|
|
155
|
+
export interface Translation {
|
|
156
|
+
readonly rules: ReadonlyMap<object, object>;
|
|
157
|
+
readonly nodes: ReadonlyMap<object, object>;
|
|
158
|
+
}
|
|
159
|
+
export declare function translationOf(written: unknown, rewritten: unknown): Translation;
|
|
160
|
+
export {};
|