@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.
Files changed (129) hide show
  1. package/README.md +693 -2
  2. package/dist/absence.d.ts +27 -0
  3. package/dist/absence.js +228 -0
  4. package/dist/absence.js.map +1 -0
  5. package/dist/behavior.d.ts +193 -0
  6. package/dist/behavior.js +589 -0
  7. package/dist/behavior.js.map +1 -0
  8. package/dist/beside.d.ts +27 -0
  9. package/dist/beside.js +88 -0
  10. package/dist/beside.js.map +1 -0
  11. package/dist/border.d.ts +61 -0
  12. package/dist/border.js +434 -0
  13. package/dist/border.js.map +1 -0
  14. package/dist/bounds.d.ts +1 -0
  15. package/dist/bounds.js +26 -0
  16. package/dist/bounds.js.map +1 -0
  17. package/dist/cli.d.ts +7 -0
  18. package/dist/cli.js +835 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/codec.d.ts +6 -0
  21. package/dist/codec.js +86 -0
  22. package/dist/codec.js.map +1 -0
  23. package/dist/codegen.d.ts +2 -0
  24. package/dist/codegen.js +61 -0
  25. package/dist/codegen.js.map +1 -0
  26. package/dist/composition.d.ts +38 -0
  27. package/dist/composition.js +242 -0
  28. package/dist/composition.js.map +1 -0
  29. package/dist/data.d.ts +17 -0
  30. package/dist/data.js +51 -0
  31. package/dist/data.js.map +1 -0
  32. package/dist/dependency.d.ts +101 -0
  33. package/dist/dependency.js +161 -0
  34. package/dist/dependency.js.map +1 -0
  35. package/dist/domain.d.ts +12 -0
  36. package/dist/domain.js +217 -0
  37. package/dist/domain.js.map +1 -0
  38. package/dist/ensures.d.ts +15 -0
  39. package/dist/ensures.js +88 -0
  40. package/dist/ensures.js.map +1 -0
  41. package/dist/equal.d.ts +1 -0
  42. package/dist/equal.js +135 -0
  43. package/dist/equal.js.map +1 -0
  44. package/dist/exact.d.ts +21 -0
  45. package/dist/exact.js +80 -0
  46. package/dist/exact.js.map +1 -0
  47. package/dist/feasibility.d.ts +63 -0
  48. package/dist/feasibility.js +1053 -0
  49. package/dist/feasibility.js.map +1 -0
  50. package/dist/guard-borders.d.ts +57 -0
  51. package/dist/guard-borders.js +760 -0
  52. package/dist/guard-borders.js.map +1 -0
  53. package/dist/guard-scope.d.ts +61 -0
  54. package/dist/guard-scope.js +364 -0
  55. package/dist/guard-scope.js.map +1 -0
  56. package/dist/index.d.ts +48 -0
  57. package/dist/index.js +24 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/interleave.d.ts +31 -0
  60. package/dist/interleave.js +202 -0
  61. package/dist/interleave.js.map +1 -0
  62. package/dist/interval.d.ts +10 -0
  63. package/dist/interval.js +311 -0
  64. package/dist/interval.js.map +1 -0
  65. package/dist/isolated.d.ts +9 -0
  66. package/dist/isolated.js +41 -0
  67. package/dist/isolated.js.map +1 -0
  68. package/dist/machine-check.d.ts +73 -0
  69. package/dist/machine-check.js +215 -0
  70. package/dist/machine-check.js.map +1 -0
  71. package/dist/machine.d.ts +97 -0
  72. package/dist/machine.js +200 -0
  73. package/dist/machine.js.map +1 -0
  74. package/dist/model.d.ts +160 -0
  75. package/dist/model.js +778 -0
  76. package/dist/model.js.map +1 -0
  77. package/dist/outcomes.d.ts +7 -0
  78. package/dist/outcomes.js +38 -0
  79. package/dist/outcomes.js.map +1 -0
  80. package/dist/pairs.d.ts +26 -0
  81. package/dist/pairs.js +115 -0
  82. package/dist/pairs.js.map +1 -0
  83. package/dist/partition.d.ts +45 -0
  84. package/dist/partition.js +354 -0
  85. package/dist/partition.js.map +1 -0
  86. package/dist/proof.d.ts +21 -0
  87. package/dist/proof.js +556 -0
  88. package/dist/proof.js.map +1 -0
  89. package/dist/replay.d.ts +45 -0
  90. package/dist/replay.js +157 -0
  91. package/dist/replay.js.map +1 -0
  92. package/dist/report-json.d.ts +11 -0
  93. package/dist/report-json.js +94 -0
  94. package/dist/report-json.js.map +1 -0
  95. package/dist/rule.d.ts +186 -0
  96. package/dist/rule.js +866 -0
  97. package/dist/rule.js.map +1 -0
  98. package/dist/runtime.d.ts +12 -0
  99. package/dist/runtime.js +8 -0
  100. package/dist/runtime.js.map +1 -0
  101. package/dist/schema.d.ts +163 -0
  102. package/dist/schema.js +528 -0
  103. package/dist/schema.js.map +1 -0
  104. package/dist/specification.d.ts +266 -0
  105. package/dist/specification.js +2123 -0
  106. package/dist/specification.js.map +1 -0
  107. package/dist/temporal-global.d.ts +4 -0
  108. package/dist/temporal-global.js +11 -0
  109. package/dist/temporal-global.js.map +1 -0
  110. package/dist/temporal.d.ts +22 -0
  111. package/dist/temporal.js +113 -0
  112. package/dist/temporal.js.map +1 -0
  113. package/dist/text.d.ts +1 -0
  114. package/dist/text.js +11 -0
  115. package/dist/text.js.map +1 -0
  116. package/dist/tla.d.ts +54 -0
  117. package/dist/tla.js +579 -0
  118. package/dist/tla.js.map +1 -0
  119. package/dist/verification.d.ts +7 -0
  120. package/dist/verification.js +5 -0
  121. package/dist/verification.js.map +1 -0
  122. package/dist/ways.d.ts +28 -0
  123. package/dist/ways.js +86 -0
  124. package/dist/ways.js.map +1 -0
  125. package/dist/world.d.ts +98 -0
  126. package/dist/world.js +467 -0
  127. package/dist/world.js.map +1 -0
  128. package/package.json +76 -4
  129. package/schema/report.schema.json +1062 -0
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ export { array, boolean, date, decimal, datetime, instant, int, enumOf as enum, literal, isVariantsSchema, number, object, record, string, time, variants, tagOf, } from "./schema.js";
2
+ export { formatTypeScriptValue } from "./codegen.js";
3
+ export { dependency, fake, FakeMiss } from "./dependency.js";
4
+ export { positionsOf } from "./partition.js";
5
+ export { action, behavior, caseOf, external, implement, isBehavior, match, isCaseOnly, isTodo, todo, perform, performSync, SpecificationError, TodoDecision, } from "./behavior.js";
6
+ export { spec, check, example, examples, evaluate, generate, isSpecification, test, } from "./specification.js";
7
+ export { FEASIBILITY_COMBINATION_LIMIT } from "./feasibility.js";
8
+ export { WAY_LIMIT } from "./ways.js";
9
+ export { reportDocument, reportSchemaVersion } from "./report-json.js";
10
+ export { compose, isComposition } from "./composition.js";
11
+ export { explore, invariant, transition, world } from "./world.js";
12
+ export { machine, effect, isMachine, runMachine } from "./machine.js";
13
+ export { specifyMachine, isMachineSpecification, checkMachine } from "./machine-check.js";
14
+ export { checkInterleavings } from "./interleave.js";
15
+ export { replayMachine } from "./replay.js";
16
+ export { toTla, checkMachineTla, checkInterleavingsTla, proveMachine } from "./tla.js";
17
+ export { decode, encode } from "./codec.js";
18
+ export { PAIR_LIMIT } from "./pairs.js";
19
+ export { model, bind, matchValue, map, fold, call, choose, construct, concat, arithmetic, quotient, plus, minus, between } from "./model.js";
20
+ export { verify } from "./proof.js";
21
+ export { Rational, INT64_MIN, INT64_MAX } from "./exact.js";
22
+ export { int64, rational } from "./schema.js";
23
+ export { data } from "./data.js";
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EACL,OAAO,EACP,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,OAAO,EACP,GAAG,EACH,MAAM,IAAI,IAAI,EACd,OAAO,EACP,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,KAAK,GACN,MAAM,aAAa,CAAC;AA6BrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAe7D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,OAAO,EACL,MAAM,EACN,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,MAAM,EACN,IAAI,EACJ,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,YAAY,GACb,MAAM,eAAe,CAAC;A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YAAY,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { MachineSpecification } from "./machine-check.js";
2
+ export interface InterleavingStep<State, Command> {
3
+ readonly copy: number;
4
+ readonly action: "read" | "run" | "write" | "refused";
5
+ readonly command: Command;
6
+ readonly effect?: string;
7
+ readonly before: State;
8
+ readonly after: State;
9
+ }
10
+ export interface InterleavingTrace<State, Command> {
11
+ readonly start: State;
12
+ readonly steps: readonly InterleavingStep<State, Command>[];
13
+ readonly reason: string;
14
+ }
15
+ export interface InterleavingReport<State, Command> {
16
+ readonly status: "held" | "broken" | "undetermined";
17
+ readonly states: number;
18
+ readonly reason?: string;
19
+ readonly counterexample?: InterleavingTrace<State, Command>;
20
+ readonly terminals: readonly {
21
+ readonly statuses: readonly ("finished" | "refused")[];
22
+ readonly state: State;
23
+ }[];
24
+ }
25
+ export declare function checkInterleavings<State, Command>(specification: MachineSpecification<State, Command>, options: {
26
+ readonly copies: readonly NoInfer<Command>[];
27
+ readonly starts?: readonly NoInfer<State>[];
28
+ readonly maxStates?: number;
29
+ readonly maxCopies?: number;
30
+ readonly maxCommands?: number;
31
+ }): InterleavingReport<State, Command>;
@@ -0,0 +1,202 @@
1
+ // Runs of one machine that share a single state. Each run reads the state when it starts a
2
+ // command and then performs that command's effects one step at a time, and every order in which
3
+ // the steps of the runs can interleave is explored.
4
+ import { SpecificationError } from "./behavior.js";
5
+ import { deepEqual } from "./equal.js";
6
+ import { EvaluationLimit } from "./exact.js";
7
+ import { evaluateCommand, positiveLimit } from "./machine.js";
8
+ import { checks, refusedBy } from "./world.js";
9
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
10
+ // What an effect writes onto the state as it is now: the fields it changed from what its run last saw
11
+ // (a field it left out is removed).
12
+ function written(seen, now, after, writes) {
13
+ if (isRecord(seen) && isRecord(now) && isRecord(after)) {
14
+ const fields = writes ?? [...new Set([...Object.keys(seen), ...Object.keys(after)])].filter(key => !deepEqual(seen[key], after[key]));
15
+ const next = { ...now };
16
+ for (const key of fields) {
17
+ if (Object.hasOwn(after, key))
18
+ next[key] = after[key];
19
+ else
20
+ delete next[key];
21
+ }
22
+ return { state: next, wrote: fields.length > 0 };
23
+ }
24
+ const wrote = writes !== undefined ? writes.length > 0 : !deepEqual(seen, after);
25
+ return { state: wrote ? after : now, wrote };
26
+ }
27
+ const keyOf = (value) => JSON.stringify(value, (_key, item) => typeof item === "bigint" ? `${item}n` : item) ?? "undefined";
28
+ export function checkInterleavings(specification, options) {
29
+ const maxStates = positiveLimit(options.maxStates, 10000, "maxStates");
30
+ const maxCopies = positiveLimit(options.maxCopies, 2, "maxCopies");
31
+ const maxCommands = positiveLimit(options.maxCommands, 1000, "maxCommands");
32
+ const machine = specification.machine;
33
+ if (options.copies.length === 0)
34
+ throw new SpecificationError(`Machine ${machine.name} has no copy to run`);
35
+ if (options.copies.length > maxCopies) {
36
+ return { status: "undetermined", states: 0, reason: `${options.copies.length} copies exceed maxCopies (${maxCopies})`, terminals: [] };
37
+ }
38
+ if (options.starts?.length === 0)
39
+ throw new SpecificationError(`Machine ${machine.name} has no state to start from`);
40
+ const shape = machine.state.shape;
41
+ const fieldNames = shape === undefined ? undefined : Object.keys(shape);
42
+ const commands = options.copies.map((command, index) => {
43
+ const parsed = machine.command.parse(command);
44
+ if (!parsed.success)
45
+ throw new SpecificationError(`Copy ${index}: ${parsed.issues.map(issue => `${issue.path}: ${issue.message}`).join("; ")}`);
46
+ return parsed.value;
47
+ });
48
+ const parseState = (value) => {
49
+ const parsed = machine.state.parse(value);
50
+ if (!parsed.success)
51
+ throw new SpecificationError(`${parsed.issues.map(issue => `${issue.path}: ${issue.message}`).join("; ")}`);
52
+ return parsed.value;
53
+ };
54
+ const nodes = [];
55
+ const seen = new Set();
56
+ const terminals = new Map();
57
+ let incomplete;
58
+ const trace = (index, extra, reason) => {
59
+ const steps = extra === undefined ? [] : [extra];
60
+ for (let current = index; current !== undefined; current = nodes[current].parent) {
61
+ const step = nodes[current].step;
62
+ if (step !== undefined)
63
+ steps.unshift(step);
64
+ }
65
+ return { start: nodes[index].start, steps, reason };
66
+ };
67
+ const violation = (before, after) => {
68
+ const broken = specification.invariants.find(invariant => !checks(invariant.holds, after));
69
+ if (broken)
70
+ return `Invariant ${broken.name} failed`;
71
+ for (const transition of specification.transitions) {
72
+ const reason = refusedBy(transition, specification.name, before, after);
73
+ if (reason !== undefined)
74
+ return reason;
75
+ }
76
+ return undefined;
77
+ };
78
+ const advance = (joint, index) => {
79
+ const copy = joint.copies[index];
80
+ const replace = (next, state, version) => ({ state, version, copies: joint.copies.map((item, position) => position === index ? next : item) });
81
+ const ended = (queue) => queue.length === 0 ? "finished" : "running";
82
+ const active = copy.active;
83
+ if (active === undefined) {
84
+ const command = copy.queue[0];
85
+ const rest = copy.queue.slice(1);
86
+ const evaluated = evaluateCommand(machine, joint.state, command);
87
+ const started = copy.started + 1;
88
+ if (evaluated.effects === undefined) {
89
+ const next = written(joint.state, joint.state, evaluated.state);
90
+ const queue = [...rest, ...evaluated.commands];
91
+ return { joint: replace({ queue, status: ended(queue), started }, parseState(next.state), joint.version + (next.wrote ? 1 : 0)),
92
+ step: { copy: index, action: "run", command, before: joint.state, after: next.state }, wrote: next.wrote };
93
+ }
94
+ for (const declared of evaluated.effects) {
95
+ const unknown = fieldNames === undefined ? undefined : declared.writes?.find(key => !fieldNames.includes(key));
96
+ if (unknown !== undefined)
97
+ throw new SpecificationError(`Effect ${declared.name} writes ${unknown}, which the state does not have`);
98
+ }
99
+ if (evaluated.effects.length === 0) {
100
+ const queue = [...rest, ...evaluated.commands];
101
+ return { joint: replace({ queue, status: ended(queue), started }, joint.state, joint.version),
102
+ step: { copy: index, action: "read", command, before: joint.state, after: joint.state }, wrote: false };
103
+ }
104
+ return { joint: replace({ queue: rest, status: "running", started,
105
+ active: { command, effects: evaluated.effects, index: 0, seen: joint.state, readVersion: joint.version, commands: evaluated.commands } }, joint.state, joint.version),
106
+ step: { copy: index, action: "read", command, before: joint.state, after: joint.state }, wrote: false };
107
+ }
108
+ const effect = active.effects[active.index];
109
+ const label = active.command;
110
+ if (effect.ifUnchanged && joint.version !== active.readVersion) {
111
+ return { joint: replace({ queue: [], status: "refused", started: copy.started }, joint.state, joint.version),
112
+ step: { copy: index, action: "refused", command: label, effect: effect.name, before: joint.state, after: joint.state }, wrote: false };
113
+ }
114
+ const next = written(active.seen, joint.state, effect.state, effect.writes);
115
+ const last = active.index === active.effects.length - 1;
116
+ const queue = last ? [...copy.queue, ...active.commands] : copy.queue;
117
+ const nextCopy = last
118
+ ? { queue, status: ended(queue), started: copy.started }
119
+ : { queue, status: "running", started: copy.started, active: { ...active, index: active.index + 1, seen: effect.state } };
120
+ return { joint: replace(nextCopy, parseState(next.state), joint.version + (next.wrote ? 1 : 0)),
121
+ step: { copy: index, action: "write", command: label, effect: effect.name, before: joint.state, after: next.state }, wrote: next.wrote };
122
+ };
123
+ const enqueue = (joint, start, parent, step) => {
124
+ const key = keyOf(joint);
125
+ if (seen.has(key))
126
+ return undefined;
127
+ if (nodes.length === maxStates) {
128
+ incomplete ??= `Reached maxStates (${maxStates}) before exploring every interleaving`;
129
+ return undefined;
130
+ }
131
+ seen.add(key);
132
+ nodes.push({ joint, start, ...(parent === undefined ? {} : { parent }), ...(step === undefined ? {} : { step }) });
133
+ return nodes.length - 1;
134
+ };
135
+ for (const initial of options.starts ?? machine.initial) {
136
+ const state = parseState(initial);
137
+ let broken;
138
+ try {
139
+ broken = specification.invariants.find(invariant => !checks(invariant.holds, state))?.name;
140
+ }
141
+ catch (error) {
142
+ if (!(error instanceof EvaluationLimit))
143
+ throw error;
144
+ incomplete ??= error.message;
145
+ continue;
146
+ }
147
+ if (broken !== undefined)
148
+ return { status: "broken", states: 0, terminals: [],
149
+ counterexample: { start: state, steps: [], reason: `Initial state violates ${broken}` } };
150
+ enqueue({ state, version: 0, copies: commands.map(command => ({ queue: [command], status: "running", started: 0 })) }, state, undefined, undefined);
151
+ }
152
+ for (let index = 0; index < nodes.length; index++) {
153
+ const node = nodes[index];
154
+ const running = node.joint.copies.flatMap((copy, position) => copy.status === "running" ? [position] : []);
155
+ if (running.length === 0) {
156
+ const statuses = node.joint.copies.map(copy => copy.status);
157
+ terminals.set(keyOf([statuses, node.joint.state]), { statuses, state: node.joint.state });
158
+ continue;
159
+ }
160
+ for (const position of running) {
161
+ if (node.joint.copies[position].started >= maxCommands && node.joint.copies[position].active === undefined) {
162
+ incomplete ??= `Copy ${position} exceeded ${maxCommands} commands`;
163
+ continue;
164
+ }
165
+ let result;
166
+ try {
167
+ result = advance(node.joint, position);
168
+ }
169
+ catch (error) {
170
+ if (error instanceof EvaluationLimit) {
171
+ incomplete ??= error.message;
172
+ continue;
173
+ }
174
+ if (!(error instanceof Error))
175
+ throw error;
176
+ return { status: "broken", states: nodes.length, terminals: [...terminals.values()],
177
+ counterexample: trace(index, undefined, error.message) };
178
+ }
179
+ if (result.wrote) {
180
+ let reason;
181
+ try {
182
+ reason = violation(node.joint.state, result.joint.state);
183
+ }
184
+ catch (error) {
185
+ if (!(error instanceof EvaluationLimit))
186
+ throw error;
187
+ incomplete ??= error.message;
188
+ continue;
189
+ }
190
+ if (reason !== undefined)
191
+ return { status: "broken", states: nodes.length, terminals: [...terminals.values()],
192
+ counterexample: trace(index, result.step, reason) };
193
+ }
194
+ enqueue(result.joint, node.start, index, result.step);
195
+ }
196
+ }
197
+ const all = [...terminals.values()];
198
+ return incomplete === undefined
199
+ ? { status: "held", states: nodes.length, terminals: all }
200
+ : { status: "undetermined", states: nodes.length, reason: incomplete, terminals: all };
201
+ }
202
+ //# sourceMappingURL=interleave.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interleave.js","sourceRoot":"","sources":["../src/interleave.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3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AAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE;QAC1D,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Rational } from "./exact.js";
2
+ import type { AnySchema } from "./schema.js";
3
+ import type { Step } from "./ways.js";
4
+ export { compatibleBound } from "./bounds.js";
5
+ export declare function provesTemporal(schema: AnySchema, value: unknown, scope: AnySchema, steps: readonly Step[]): boolean;
6
+ export declare function provesNumeric(schema: AnySchema, value: unknown, scope: AnySchema, steps: readonly Step[]): boolean;
7
+ export declare function rangeOf(value: unknown, scope: AnySchema, steps: readonly Step[]): {
8
+ readonly low: Rational;
9
+ readonly high: Rational;
10
+ } | undefined;
@@ -0,0 +1,311 @@
1
+ import { Decimal } from "decimal.js";
2
+ import { Rational, fractionOf, isRational, INT64_MIN, INT64_MAX } from "./exact.js";
3
+ import { nodeOf } from "./model.js";
4
+ import { isDecimal, isTerm, termData, positionTerm, conjuncts, positionData, counts } from "./rule.js";
5
+ import { schemaAtPath } from "./schema.js";
6
+ import { deepEqual } from "./equal.js";
7
+ import { compatibleBound } from "./bounds.js";
8
+ export { compatibleBound } from "./bounds.js";
9
+ import { DURATION_LIMIT, fixedLength, onTimeline, takesUnit, temporalKindOf, timelineOf, TIMELINE_RANGE } from "./temporal.js";
10
+ const zero = new Rational(0n);
11
+ // A bound a rule compares with, as a number or as a place on the timeline. A
12
+ // date, date-time or instant is read only against a range of its own kind, and
13
+ // a number only against a number: Temporal compares a date with a date-time by
14
+ // the date alone, and an instant with nothing else.
15
+ function boundOf(value, kind) {
16
+ if (!compatibleBound(value, kind))
17
+ return undefined;
18
+ const temporal = temporalKindOf(value);
19
+ if (onTimeline(kind) || temporal)
20
+ return temporal === kind ? timelineOf(value) : undefined;
21
+ try {
22
+ return fractionOf(value);
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ // Whether a date, time, date-time or instant meets its schema: a time of day
29
+ // moved by clock units always does, since it wraps at midnight; a date,
30
+ // date-time or instant does when its range on the timeline stays where Temporal
31
+ // holds it and within the schema's bounds.
32
+ export function provesTemporal(schema, value, scope, steps) {
33
+ if (!["date", "time", "datetime", "instant"].includes(schema.kind) || kindOf(value, scope) !== schema.kind)
34
+ return false;
35
+ if (schema.kind === "time") {
36
+ // Any time of day meets a time schema without bounds; one with bounds is not read here.
37
+ return schema.invariants.length === 0 && movesTime(value, scope, steps);
38
+ }
39
+ const range = interval(value, scope, steps);
40
+ if (!range || !onTimeline(range.kind))
41
+ return false;
42
+ const held = TIMELINE_RANGE[range.kind];
43
+ if (range.low.comparedTo(held.low) < 0 || range.high.comparedTo(held.high) > 0)
44
+ return false;
45
+ return schema.invariants.every(rule => satisfied(rule, range));
46
+ }
47
+ // Whether a time of day is moved only by whole clock units Temporal takes as a
48
+ // duration, so the move wraps rather than throws.
49
+ function movesTime(value, scope, steps) {
50
+ const node = nodeOf(value);
51
+ if (node?.kind !== "temporal")
52
+ return true;
53
+ if (node.operator === "between" || !takesUnit("time", node.unit) || !movesTime(node.left, scope, steps))
54
+ return false;
55
+ const amount = interval(node.right, scope, steps), unit = fixedLength(node.unit);
56
+ if (amount?.kind !== "number" || !amount.integral || !safeInteger(amount))
57
+ return false;
58
+ return max(amount.high, amount.low.times(new Rational(-1n))).times(unit).comparedTo(DURATION_LIMIT) < 0;
59
+ }
60
+ // moveTemporal takes an amount only as a safe integer.
61
+ function safeInteger(range) {
62
+ return range.low.comparedTo(fractionOf(Number.MIN_SAFE_INTEGER)) >= 0 && range.high.comparedTo(fractionOf(Number.MAX_SAFE_INTEGER)) <= 0;
63
+ }
64
+ function kindOf(value, scope) {
65
+ if (isTerm(value)) {
66
+ const term = termData(value);
67
+ // A value an optional around it may leave out is no value of its type.
68
+ return term.kind === "position" && term.measure === "value" && !optionalAlong(scope, term.path) ? schemaAtPath(scope, term.path)?.kind : undefined;
69
+ }
70
+ const node = nodeOf(value);
71
+ if (node?.kind === "construct")
72
+ return node.schema.kind;
73
+ if (node?.kind === "temporal")
74
+ return node.operator === "between" ? "integer" : kindOf(node.left, scope);
75
+ return temporalKindOf(value);
76
+ }
77
+ const inverse = { "<": ">=", "<=": ">", ">": "<=", ">=": "<", "==": "!=", "!=": "==" };
78
+ export function provesNumeric(schema, value, scope, steps) {
79
+ const range = interval(value, scope, steps);
80
+ if (!range)
81
+ return false;
82
+ if (schema.kind === "integer" && (range.kind !== "number" || !range.integral))
83
+ return false;
84
+ if (schema.kind === "number" && range.kind !== "number")
85
+ return false;
86
+ if (schema.kind === "int64" && (range.kind !== "bigint" || range.low.comparedTo(new Rational(INT64_MIN)) < 0 || range.high.comparedTo(new Rational(INT64_MAX)) > 0))
87
+ return false;
88
+ if (schema.kind === "rational" && range.kind !== "rational")
89
+ return false;
90
+ if (schema.kind === "decimal" && (range.kind !== "decimal" || range.scale === undefined || range.scale > schema.scale))
91
+ return false;
92
+ if (!["integer", "number", "int64", "rational", "decimal"].includes(schema.kind))
93
+ return false;
94
+ return schema.invariants.every(rule => satisfied(rule, range));
95
+ }
96
+ function satisfied(rule, range) {
97
+ if (rule.kind === "and")
98
+ return rule.rules.every(part => satisfied(part, range));
99
+ if (rule.kind === "or")
100
+ return rule.rules.some(part => satisfied(part, range));
101
+ if (rule.kind !== "compare" || !isTerm(rule.left))
102
+ return false;
103
+ const position = positionData(rule.left);
104
+ if (!position || position.path.length || position.measure !== "value" || isTerm(rule.right))
105
+ return false;
106
+ const bound = boundOf(rule.right, range.kind);
107
+ if (!bound)
108
+ return false;
109
+ const low = range.low.comparedTo(bound), high = range.high.comparedTo(bound);
110
+ switch (rule.operator) {
111
+ case ">": return low > 0;
112
+ case ">=": return low >= 0;
113
+ case "<": return high < 0;
114
+ case "<=": return high <= 0;
115
+ case "==": return low === 0 && high === 0;
116
+ case "!=": return low > 0 || high < 0;
117
+ }
118
+ }
119
+ function interval(value, scope, steps) {
120
+ if (isTerm(value)) {
121
+ const term = termData(value);
122
+ if (term.kind === "linear") {
123
+ let total = interval(term.constant, scope, steps);
124
+ for (const part of term.parts) {
125
+ const found = interval(positionTerm(part.path, part.measure), scope, steps);
126
+ if (!total || !found || onTimeline(found.kind) || total.kind !== found.kind && total.kind !== "number")
127
+ return undefined;
128
+ const coefficient = fractionOf(part.coefficient);
129
+ const a = found.low.times(coefficient), b = found.high.times(coefficient);
130
+ total = { kind: found.kind, scale: found.scale === undefined ? undefined : Math.max(total.scale ?? 0, found.scale), integral: total.integral && found.integral && Number.isInteger(part.coefficient), low: total.low.plus(min(a, b)), high: total.high.plus(max(a, b)) };
131
+ }
132
+ return exactNumber(total);
133
+ }
134
+ if (optionalAlong(scope, term.path))
135
+ return undefined;
136
+ const schema = schemaAtPath(scope, term.path);
137
+ if (!schema)
138
+ return undefined;
139
+ const timeline = term.measure === "value" && onTimeline(schema.kind) ? TIMELINE_RANGE[schema.kind] : undefined;
140
+ const kind = counts(term.measure) || schema.kind === "integer" ? "number" : schema.kind === "int64" ? "bigint" : schema.kind;
141
+ const integral = !!timeline || counts(term.measure) || schema.kind === "integer" || schema.kind === "int64";
142
+ let low = timeline ? timeline.low : counts(term.measure) ? zero : schema.kind === "int64" ? new Rational(INT64_MIN) : schema.kind === "integer" ? fractionOf(Number.MIN_SAFE_INTEGER) : undefined;
143
+ let high = timeline ? timeline.high : counts(term.measure) ? fractionOf(Number.MAX_SAFE_INTEGER) : schema.kind === "int64" ? new Rational(INT64_MAX) : schema.kind === "integer" ? fractionOf(Number.MAX_SAFE_INTEGER) : undefined;
144
+ const rules = [];
145
+ for (let size = 0; size <= term.path.length; size++) {
146
+ const at = schemaAtPath(scope, term.path.slice(0, size));
147
+ rules.push(...(at?.invariants.flatMap(conjuncts) ?? []).map(rule => ({ rule, prefix: term.path.slice(0, size), holds: true })));
148
+ }
149
+ rules.push(...steps.filter(step => step.distinction.kind !== "match").map(step => ({ rule: step.distinction, prefix: [], holds: step.outcome === true })));
150
+ for (const item of rules) {
151
+ if (item.rule.kind !== "compare" || !isTerm(item.rule.left) || isTerm(item.rule.right))
152
+ continue;
153
+ const left = positionData(item.rule.left);
154
+ if (!left || left.measure !== term.measure || !deepEqual([...item.prefix, ...left.path], term.path))
155
+ continue;
156
+ const bound = boundOf(item.rule.right, kind);
157
+ if (!bound)
158
+ continue;
159
+ const operator = item.holds ? item.rule.operator : inverse[item.rule.operator];
160
+ const next = integral && bound.denominator === 1n && (operator === "<" || operator === ">") ? bound.plus(new Rational(operator === "<" ? -1n : 1n)) : bound;
161
+ if ([">", ">=", "=="].includes(operator))
162
+ low = low ? max(low, next) : next;
163
+ if (["<", "<=", "=="].includes(operator))
164
+ high = high ? min(high, next) : next;
165
+ }
166
+ if (!low || !high || low.comparedTo(high) > 0)
167
+ return undefined;
168
+ if (timeline)
169
+ return { low, high, integral, kind: schema.kind };
170
+ return { low, high, integral, scale: schema.kind === "decimal" ? schema.scale : undefined, kind: schema.kind === "int64" ? "bigint" : schema.kind === "rational" ? "rational" : schema.kind === "decimal" ? "decimal" : "number" };
171
+ }
172
+ const node = nodeOf(value);
173
+ if (node?.kind === "construct")
174
+ return interval(node.value, scope, steps);
175
+ if (node?.kind === "temporal") {
176
+ // Only a unit of fixed length moves a value along the timeline by a fixed amount.
177
+ const unit = fixedLength(node.unit);
178
+ const left = interval(node.left, scope, steps), right = interval(node.right, scope, steps);
179
+ if (!unit || !left || !right || !onTimeline(left.kind) || !takesUnit(left.kind, node.unit))
180
+ return undefined;
181
+ if (node.operator === "between") {
182
+ if (right.kind !== left.kind)
183
+ return undefined;
184
+ // Temporal rounds a count of weeks by placing the start up to a week past
185
+ // the end, so the end must leave a week of room within the range held.
186
+ const held = TIMELINE_RANGE[left.kind];
187
+ if (node.unit === "weeks" && (right.low.comparedTo(held.low.plus(unit)) < 0 || right.high.comparedTo(held.high.minus(unit)) > 0))
188
+ return undefined;
189
+ // Whole units from start to end, the part of a unit dropped toward zero.
190
+ const whole = (span) => new Rational(span.numerator / (span.denominator * unit.numerator));
191
+ return exactNumber({ kind: "number", integral: true, low: whole(right.low.minus(left.high)), high: whole(right.high.minus(left.low)) });
192
+ }
193
+ if (right.kind !== "number" || !right.integral || !safeInteger(right))
194
+ return undefined;
195
+ const sign = new Rational(node.operator === "plus" ? 1n : -1n);
196
+ const a = right.low.times(unit).times(sign), b = right.high.times(unit).times(sign);
197
+ const low = left.low.plus(min(a, b)), high = left.high.plus(max(a, b));
198
+ // Temporal refuses a move that leaves the range it holds the type in, even
199
+ // one a later move brings back or a count only reads.
200
+ const held = TIMELINE_RANGE[left.kind];
201
+ if (low.comparedTo(held.low) < 0 || high.comparedTo(held.high) > 0)
202
+ return undefined;
203
+ return { kind: left.kind, integral: true, low, high };
204
+ }
205
+ if (node?.kind === "operation") {
206
+ if (node.operator === "concat")
207
+ return undefined;
208
+ const left = interval(node.left, scope, steps), right = interval(node.right, scope, steps);
209
+ if (!left || !right || onTimeline(left.kind) || onTimeline(right.kind) || node.operator !== "quotient" && left.kind !== right.kind)
210
+ return undefined;
211
+ let low, high;
212
+ if (node.operator === "add") {
213
+ low = left.low.plus(right.low);
214
+ high = left.high.plus(right.high);
215
+ }
216
+ else if (node.operator === "subtract") {
217
+ low = left.low.minus(right.high);
218
+ high = left.high.minus(right.low);
219
+ }
220
+ else {
221
+ if (node.operator !== "multiply" && right.low.comparedTo(zero) <= 0 && right.high.comparedTo(zero) >= 0)
222
+ return undefined;
223
+ if (node.operator === "divide" && left.kind !== "rational")
224
+ return undefined;
225
+ const values = [left.low, left.high].flatMap(a => [right.low, right.high].map(b => node.operator === "multiply" ? a.times(b) : a.dividedBy(b)));
226
+ low = values.reduce(min);
227
+ high = values.reduce(max);
228
+ }
229
+ const scale = left.scale === undefined || right.scale === undefined ? undefined : node.operator === "multiply" ? left.scale + right.scale : Math.max(left.scale, right.scale);
230
+ return exactNumber({ low, high, scale, kind: node.operator === "quotient" ? "rational" : left.kind, integral: node.operator !== "divide" && node.operator !== "quotient" && left.integral && right.integral });
231
+ }
232
+ const placed = timelineOf(value);
233
+ if (placed)
234
+ return { low: placed, high: placed, integral: true, kind: temporalKindOf(value) };
235
+ if (typeof value !== "number" && typeof value !== "bigint" && !isDecimal(value) && !isRational(value))
236
+ return undefined;
237
+ try {
238
+ const bound = fractionOf(value);
239
+ return { low: bound, high: bound, scale: isDecimal(value) ? value.decimalPlaces() : undefined, integral: bound.denominator === 1n, kind: typeof value === "number" ? "number" : typeof value === "bigint" ? "bigint" : isDecimal(value) ? "decimal" : "rational" };
240
+ }
241
+ catch {
242
+ return undefined;
243
+ }
244
+ }
245
+ function exactNumber(range) {
246
+ if (range?.kind !== "number")
247
+ return range;
248
+ return range.integral && range.low.comparedTo(fractionOf(Number.MIN_SAFE_INTEGER)) >= 0 && range.high.comparedTo(fractionOf(Number.MAX_SAFE_INTEGER)) <= 0 ? range : undefined;
249
+ }
250
+ function min(a, b) { return a.comparedTo(b) <= 0 ? a : b; }
251
+ function max(a, b) { return a.comparedTo(b) >= 0 ? a : b; }
252
+ function optionalAlong(schema, path) {
253
+ if (schema.kind === "optional")
254
+ return true;
255
+ if (!path.length)
256
+ return false;
257
+ if (schema.kind !== "object")
258
+ return true;
259
+ const child = schema.shape[path[0]];
260
+ return !child || optionalAlong(child, path.slice(1));
261
+ }
262
+ // The values a sum, difference or product of numbers may take, read from the
263
+ // bounds of the positions it reads and what the steps settle of them, as exact
264
+ // rationals with no limit of size, for telling a comparison it never meets. A
265
+ // `number` is added and multiplied in floating point at run time: one that is
266
+ // not a whole number is not read, and a result past the safe integers is widened
267
+ // by the relative error one rounding may make.
268
+ export function rangeOf(value, scope, steps) {
269
+ const range = measuredRange(value, scope, steps);
270
+ return range === undefined ? undefined : { low: range.low, high: range.high };
271
+ }
272
+ const rounding = new Rational(1n, 1n << 52n);
273
+ function widened(low, high) {
274
+ const room = (bound) => (bound.comparedTo(zero) < 0 ? bound.times(new Rational(-1n)) : bound).times(rounding);
275
+ return {
276
+ low: low.comparedTo(fractionOf(Number.MIN_SAFE_INTEGER)) < 0 ? low.minus(room(low)) : low,
277
+ high: high.comparedTo(fractionOf(Number.MAX_SAFE_INTEGER)) > 0 ? high.plus(room(high)) : high,
278
+ };
279
+ }
280
+ function measuredRange(value, scope, steps) {
281
+ const node = nodeOf(value);
282
+ if (node?.kind === "construct")
283
+ return measuredRange(node.value, scope, steps);
284
+ if (node?.kind === "operation" && (node.operator === "add" || node.operator === "subtract" || node.operator === "multiply")) {
285
+ const left = measuredRange(node.left, scope, steps), right = measuredRange(node.right, scope, steps);
286
+ if (!left || !right)
287
+ return undefined;
288
+ let low, high;
289
+ if (node.operator === "add") {
290
+ low = left.low.plus(right.low);
291
+ high = left.high.plus(right.high);
292
+ }
293
+ else if (node.operator === "subtract") {
294
+ low = left.low.minus(right.high);
295
+ high = left.high.minus(right.low);
296
+ }
297
+ else {
298
+ const values = [left.low, left.high].flatMap(a => [right.low, right.high].map(b => a.times(b)));
299
+ low = values.reduce(min);
300
+ high = values.reduce(max);
301
+ }
302
+ const floating = left.floating || right.floating;
303
+ return floating ? { ...widened(low, high), floating } : { low, high, floating };
304
+ }
305
+ const found = interval(value, scope, steps);
306
+ if (found === undefined || onTimeline(found.kind))
307
+ return undefined;
308
+ const floating = found.kind === "number";
309
+ return floating && !found.integral ? undefined : { low: found.low, high: found.high, floating };
310
+ }
311
+ //# sourceMappingURL=interval.js.map