foldkit-entity 0.16.0 → 0.18.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 (82) hide show
  1. package/README.md +582 -240
  2. package/dist/conformance/index.d.ts.map +1 -1
  3. package/dist/conformance/index.js +30 -4
  4. package/dist/conformance/index.js.map +1 -1
  5. package/dist/conformance/operator.d.ts.map +1 -1
  6. package/dist/conformance/operator.js +13 -4
  7. package/dist/conformance/operator.js.map +1 -1
  8. package/dist/descriptor.d.ts +5 -1
  9. package/dist/descriptor.d.ts.map +1 -1
  10. package/dist/descriptor.js +6 -2
  11. package/dist/descriptor.js.map +1 -1
  12. package/dist/entity.d.ts +16 -3
  13. package/dist/entity.d.ts.map +1 -1
  14. package/dist/entity.js +44 -14
  15. package/dist/entity.js.map +1 -1
  16. package/dist/enumerate.d.ts +44 -0
  17. package/dist/enumerate.d.ts.map +1 -0
  18. package/dist/enumerate.js +128 -0
  19. package/dist/enumerate.js.map +1 -0
  20. package/dist/evaluate.d.ts +12 -6
  21. package/dist/evaluate.d.ts.map +1 -1
  22. package/dist/evaluate.js +48 -23
  23. package/dist/evaluate.js.map +1 -1
  24. package/dist/expr.d.ts +78 -22
  25. package/dist/expr.d.ts.map +1 -1
  26. package/dist/expr.js +86 -57
  27. package/dist/expr.js.map +1 -1
  28. package/dist/footprint.d.ts +120 -0
  29. package/dist/footprint.d.ts.map +1 -0
  30. package/dist/footprint.js +41 -0
  31. package/dist/footprint.js.map +1 -0
  32. package/dist/held.js +11 -3
  33. package/dist/held.js.map +1 -1
  34. package/dist/index.d.ts +24 -7
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +10 -6
  37. package/dist/index.js.map +1 -1
  38. package/dist/invariant.d.ts +41 -11
  39. package/dist/invariant.d.ts.map +1 -1
  40. package/dist/invariant.js +102 -51
  41. package/dist/invariant.js.map +1 -1
  42. package/dist/law.d.ts.map +1 -1
  43. package/dist/law.js +3 -9
  44. package/dist/law.js.map +1 -1
  45. package/dist/lawCore.d.ts +42 -0
  46. package/dist/lawCore.d.ts.map +1 -0
  47. package/dist/lawCore.js +12 -0
  48. package/dist/lawCore.js.map +1 -0
  49. package/dist/lawIds.d.ts +15 -0
  50. package/dist/lawIds.d.ts.map +1 -0
  51. package/dist/lawIds.js +13 -0
  52. package/dist/lawIds.js.map +1 -0
  53. package/dist/laws.d.ts +308 -0
  54. package/dist/laws.d.ts.map +1 -0
  55. package/dist/laws.js +566 -0
  56. package/dist/laws.js.map +1 -0
  57. package/dist/memoryTable.d.ts +11 -0
  58. package/dist/memoryTable.d.ts.map +1 -0
  59. package/dist/memoryTable.js +69 -0
  60. package/dist/memoryTable.js.map +1 -0
  61. package/dist/operators.d.ts +1 -1
  62. package/dist/operators.d.ts.map +1 -1
  63. package/dist/operators.js +2 -66
  64. package/dist/operators.js.map +1 -1
  65. package/dist/refine.d.ts +64 -0
  66. package/dist/refine.d.ts.map +1 -0
  67. package/dist/refine.js +104 -0
  68. package/dist/refine.js.map +1 -0
  69. package/dist/rows.d.ts +15 -0
  70. package/dist/rows.d.ts.map +1 -0
  71. package/dist/rows.js +23 -0
  72. package/dist/rows.js.map +1 -0
  73. package/dist/sets.js.map +1 -1
  74. package/dist/uncollated.d.ts +10 -0
  75. package/dist/uncollated.d.ts.map +1 -0
  76. package/dist/uncollated.js +18 -0
  77. package/dist/uncollated.js.map +1 -0
  78. package/dist/write.d.ts +65 -7
  79. package/dist/write.d.ts.map +1 -1
  80. package/dist/write.js +128 -30
  81. package/dist/write.js.map +1 -1
  82. package/package.json +3 -3
package/dist/laws.js ADDED
@@ -0,0 +1,566 @@
1
+ import { Data, Match, Option } from "effect";
2
+ import { Evidence } from "foldkit-metadata";
3
+ import { own } from "./record.js";
4
+ import { inState, states } from "./refine.js";
5
+ import { invariantsOf, judgeAgainst, readsBefore } from "./invariant.js";
6
+ import { kernelOperators } from "./memoryTable.js";
7
+ import { Footprint, declaredOwner } from "./footprint.js";
8
+ import { lawId, transitionId } from "./lawIds.js";
9
+ import { Write, writtenKeys } from "./write.js";
10
+ import { Steps, finiteValues, steps } from "./enumerate.js";
11
+ // src/laws.ts
12
+ /**
13
+ * `Laws.check`: each transition against each invariant of its Entity, and
14
+ * the arrows its writes make between the Entity's states, by enumeration over
15
+ * finite fields and nothing cleverer. Pure: it reads declarations and returns
16
+ * a report, which is data; `Laws.show` prints it.
17
+ */
18
+ const LawVerdict = Data.taggedEnum();
19
+ const Finding = Data.taggedEnum();
20
+ const isWriteEntry = (entry) => Object.hasOwn(entry, "write");
21
+ const entityOf = (entry) => isWriteEntry(entry) ? entry.write.input.entity : entry.entity;
22
+ const footprintOf = (entry) => {
23
+ if (isWriteEntry(entry)) return Write.footprint(entry.write);
24
+ const owner = declaredOwner.get(entry.footprint);
25
+ if (owner !== void 0 && owner !== entry.entity.identity) throw new Error(`[foldkit-entity] Laws.check: ${entry.name} is over ${entry.entity.name}, but its footprint names ${owner.name}'s fields`);
26
+ return entry.footprint;
27
+ };
28
+ /** Every member an invariant reads, before and after. */
29
+ const readOf = (held) => [.../* @__PURE__ */ new Set([...held.before, ...held.after])];
30
+ const disjoint = (writes, reads) => !writes.some((key) => reads.includes(key));
31
+ const issuer = Evidence.issuer("foldkit-entity/laws");
32
+ const transition = transitionId;
33
+ const law = lawId;
34
+ /** The record for a pair the check decided it keeps, unless only its author says so. */
35
+ const evidenceOf = (name, held, verdict) => LawVerdict.$match(verdict, {
36
+ Kept: ({ by }) => by === "declared" ? Option.none() : Option.some(issuer.issue(Evidence.Enumerated({
37
+ transition: transition({ name }),
38
+ law: law(held)
39
+ }))),
40
+ Refused: () => Option.none(),
41
+ Undecided: () => Option.none()
42
+ });
43
+ /** One declared write against one invariant. */
44
+ const judgeWrite = (write, held, operators) => {
45
+ if (write._tag === "Delete") return LawVerdict.Kept({
46
+ by: "delete",
47
+ rows: 0
48
+ });
49
+ const transition = readsBefore(held);
50
+ if (write._tag === "Insert" && transition) return LawVerdict.Kept({
51
+ by: "create",
52
+ rows: 0
53
+ });
54
+ const reads = readOf(held);
55
+ if (write._tag === "Update" && !transition && disjoint(writtenKeys(write), reads)) return LawVerdict.Kept({
56
+ by: "disjointness",
57
+ rows: 0
58
+ });
59
+ return Steps.$match(steps(write, reads, { operators }), {
60
+ Undecided: ({ reason }) => LawVerdict.Undecided({ reason }),
61
+ Steps: ({ steps: each }) => {
62
+ const refused = [];
63
+ for (const step of each) {
64
+ const undecided = Match.valueTags(judgeAgainst([held], step, operators), {
65
+ Valid: () => Option.none(),
66
+ Invalid: () => {
67
+ refused.push(step);
68
+ return Option.none();
69
+ },
70
+ Undecided: ({ fields, operators: unrun }) => Option.some(unrun.length > 0 ? `it calls ${unrun.join(", ")}, which the operator table does not run` : `the write may leave ${fields.join(", ")} unwritten`)
71
+ });
72
+ if (Option.isSome(undecided)) return LawVerdict.Undecided({ reason: undecided.value });
73
+ }
74
+ return refused.length > 0 ? LawVerdict.Refused({ steps: refused }) : LawVerdict.Kept({
75
+ by: "enumeration",
76
+ rows: each.length
77
+ });
78
+ }
79
+ });
80
+ };
81
+ /** One transition known by its footprint alone against one invariant. */
82
+ const judgeFootprint = (footprint, held) => Footprint.$match(footprint, {
83
+ Unknown: () => LawVerdict.Undecided({ reason: "what it writes is unknown, so every member" }),
84
+ Derived: () => LawVerdict.Undecided({ reason: "a derived footprint needs its write" }),
85
+ Declared: ({ writes, by }) => {
86
+ if (readsBefore(held)) return LawVerdict.Undecided({ reason: `a transition invariant is not kept by disjointness, and ${by}'s word is all there is` });
87
+ const touched = writes.filter((key) => readOf(held).includes(key));
88
+ return touched.length === 0 ? LawVerdict.Kept({
89
+ by: "declared",
90
+ rows: 0
91
+ }) : LawVerdict.Undecided({ reason: `${by} says it writes ${touched.join(", ")}` });
92
+ }
93
+ });
94
+ /** The arrows one write makes between `local`, its Entity's local states. */
95
+ const arrowsOf = (name, write, local, invariants, operators) => {
96
+ const entity = write.input.entity.name;
97
+ const none = {
98
+ arrows: [],
99
+ findings: [],
100
+ reached: /* @__PURE__ */ new Set(),
101
+ left: /* @__PURE__ */ new Set(),
102
+ undecided: /* @__PURE__ */ new Set()
103
+ };
104
+ if (write._tag === "Delete") return none;
105
+ const written = writtenKeys(write);
106
+ const moved = local.filter((state) => state.reads.some((key) => written.includes(key)));
107
+ const fields = write.input.entity.fields;
108
+ const finite = (state) => state.reads.every((key) => Option.isSome(Option.flatMap(Option.fromUndefinedOr(own(fields, key)), (field) => finiteValues(field.schema))));
109
+ const enumerable = local.filter(finite);
110
+ const unenumerable = new Set(moved.filter((state) => !finite(state)).map((state) => state.name));
111
+ if (!moved.some(finite)) return {
112
+ ...none,
113
+ undecided: unenumerable
114
+ };
115
+ const members = [...new Set(enumerable.flatMap((state) => state.reads))];
116
+ return Steps.$match(steps(write, members, { operators }), {
117
+ Undecided: () => ({
118
+ ...none,
119
+ undecided: new Set(moved.map((state) => state.name))
120
+ }),
121
+ Steps: ({ steps: each }) => {
122
+ const reached = /* @__PURE__ */ new Set();
123
+ const left = /* @__PURE__ */ new Set();
124
+ const groups = /* @__PURE__ */ new Map();
125
+ const inOf = (row) => enumerable.filter((state) => Option.getOrElse(inState(state, row, operators), () => false));
126
+ for (const step of each) {
127
+ const after = inOf(step.after);
128
+ if (write._tag === "Insert") {
129
+ after.forEach((state) => reached.add(state.name));
130
+ continue;
131
+ }
132
+ const before = inOf(step.before);
133
+ const judged = judgeAgainst(invariants, step, operators);
134
+ const refusedBy = Match.valueTags(judged, {
135
+ Invalid: ({ failures }) => Option.some(failures[0].id),
136
+ Valid: () => Option.none(),
137
+ Undecided: () => Option.none()
138
+ });
139
+ for (const from of before) for (const to of after) {
140
+ if (from === to || before.includes(to)) continue;
141
+ const key = JSON.stringify([from.name, to.name]);
142
+ const group = groups.get(key);
143
+ groups.set(key, {
144
+ from: from.name,
145
+ to: to.name,
146
+ refusedBy: group === void 0 ? refusedBy : Option.flatMap(group.refusedBy, () => refusedBy)
147
+ });
148
+ left.add(from.name);
149
+ if (Option.isNone(refusedBy)) reached.add(to.name);
150
+ }
151
+ }
152
+ const arrows = [];
153
+ const findings = [];
154
+ for (const { from, to, refusedBy } of groups.values()) {
155
+ const arrow = {
156
+ entity,
157
+ write: name,
158
+ from,
159
+ to
160
+ };
161
+ arrows.push(arrow);
162
+ findings.push(Option.match(refusedBy, {
163
+ onSome: (invariant) => Finding.Refused({
164
+ ...arrow,
165
+ invariant
166
+ }),
167
+ onNone: () => Option.exists(write.becomes, (state) => state.name === to) ? Finding.Holds(arrow) : Finding.Undeclared(arrow)
168
+ }));
169
+ }
170
+ return {
171
+ arrows,
172
+ findings,
173
+ reached,
174
+ left,
175
+ undecided: unenumerable
176
+ };
177
+ }
178
+ });
179
+ };
180
+ /**
181
+ * Checks each transition against each invariant of its Entity, and the arrows
182
+ * its writes make between the Entity's declared states. An entry is a
183
+ * declared write (`{ name, write }`, as `Mutation.write` returns), or a
184
+ * transition known by its footprint (`{ name, entity, footprint }`). Pure, and
185
+ * what it finds is a report, never a fault; it throws only for two entries of
186
+ * one name, which its report could not tell apart.
187
+ */
188
+ const check = (options) => {
189
+ const operators = options.operators ?? kernelOperators;
190
+ const entries = options.writes;
191
+ const pairs = [];
192
+ const entities = [];
193
+ const names = /* @__PURE__ */ new Set();
194
+ for (const entry of entries) {
195
+ if (names.has(entry.name)) throw new Error(`[foldkit-entity] Laws.check: two transitions are named ${entry.name}`);
196
+ names.add(entry.name);
197
+ const entity = entityOf(entry);
198
+ if (!entities.some((known) => known.identity === entity.identity)) entities.push(entity);
199
+ const footprint = footprintOf(entry);
200
+ const ensured = isWriteEntry(entry) ? Option.toArray(entry.write.ensures) : [];
201
+ for (const held of [...invariantsOf(entity), ...ensured]) {
202
+ const verdict = isWriteEntry(entry) ? judgeWrite(entry.write, held, operators) : judgeFootprint(entry.footprint, held);
203
+ pairs.push({
204
+ write: entry.name,
205
+ entity: entity.name,
206
+ invariant: held.id,
207
+ reads: readOf(held),
208
+ readsBefore: readsBefore(held),
209
+ footprint,
210
+ verdict,
211
+ postcondition: ensured.includes(held),
212
+ evidence: evidenceOf(entry.name, held, verdict)
213
+ });
214
+ }
215
+ }
216
+ const arrows = [];
217
+ const findings = [];
218
+ const stateList = [];
219
+ for (const entity of entities) {
220
+ const local = states(entity).filter((state) => state.local);
221
+ if (local.length === 0) continue;
222
+ stateList.push({
223
+ entity: entity.name,
224
+ names: local.map((state) => state.name)
225
+ });
226
+ const invariants = invariantsOf(entity);
227
+ const reached = /* @__PURE__ */ new Set();
228
+ const left = /* @__PURE__ */ new Set();
229
+ const undecided = /* @__PURE__ */ new Set();
230
+ for (const entry of entries) {
231
+ if (entityOf(entry).identity !== entity.identity) continue;
232
+ if (!isWriteEntry(entry)) {
233
+ const footprint = footprintOf(entry);
234
+ const writes = Footprint.$match(footprint, {
235
+ Unknown: () => void 0,
236
+ Derived: ({ writes }) => writes,
237
+ Declared: ({ writes }) => writes
238
+ });
239
+ local.filter((state) => writes === void 0 || state.reads.some((key) => writes.includes(key))).forEach((state) => undecided.add(state.name));
240
+ continue;
241
+ }
242
+ const made = arrowsOf(entry.name, entry.write, local, invariants, operators);
243
+ arrows.push(...made.arrows);
244
+ findings.push(...made.findings);
245
+ const { becomes, ensures } = entry.write;
246
+ if (Option.isSome(ensures) && Option.isSome(becomes)) {
247
+ const to = becomes.value.name;
248
+ findings.push(Finding.Enforced({
249
+ entity: entity.name,
250
+ write: entry.name,
251
+ to
252
+ }));
253
+ reached.add(to);
254
+ }
255
+ made.reached.forEach((state) => reached.add(state));
256
+ made.left.forEach((state) => left.add(state));
257
+ made.undecided.forEach((state) => undecided.add(state));
258
+ }
259
+ for (const state of local) {
260
+ if (undecided.has(state.name)) continue;
261
+ if (!reached.has(state.name)) findings.push(Finding.Unreached({
262
+ entity: entity.name,
263
+ state: state.name
264
+ }));
265
+ if (!left.has(state.name)) findings.push(Finding.Terminal({
266
+ entity: entity.name,
267
+ state: state.name
268
+ }));
269
+ }
270
+ }
271
+ return {
272
+ pairs,
273
+ arrows,
274
+ states: stateList,
275
+ findings
276
+ };
277
+ };
278
+ const pad = (rows) => {
279
+ const widths = rows.reduce((most, row) => row.map((cell, at) => Math.max(most[at] ?? 0, cell.length)), []);
280
+ return rows.map((row) => row.map((cell, at) => at === row.length - 1 ? cell : cell.padEnd(widths[at] + 3)).join("").trimEnd());
281
+ };
282
+ const shownVerdict = (verdict) => LawVerdict.$match(verdict, {
283
+ Kept: ({ by, rows }) => ({
284
+ disjointness: "kept: writes no member it reads",
285
+ declared: "kept: declared to write no member it reads",
286
+ enumeration: `kept: ${rows} row${rows === 1 ? "" : "s"} enumerated`,
287
+ create: "kept: a create has no row before",
288
+ delete: "kept: a delete leaves no row"
289
+ })[by],
290
+ Refused: ({ steps: each }) => `refused: from ${JSON.stringify(each[0].before)} it leaves ${JSON.stringify(each[0].after)}`,
291
+ Undecided: ({ reason }) => `undecided: ${reason}`
292
+ });
293
+ const shownFinding = (finding) => Finding.$match(finding, {
294
+ Holds: ({ from, to, write }) => [
295
+ `${from} -> ${to}`,
296
+ write,
297
+ "holds"
298
+ ],
299
+ Undeclared: ({ from, to, write }) => [
300
+ `${from} -> ${to}`,
301
+ write,
302
+ "undeclared"
303
+ ],
304
+ Enforced: ({ to, write }) => [
305
+ `* -> ${to}`,
306
+ write,
307
+ "enforced"
308
+ ],
309
+ Refused: ({ from, to, write, invariant }) => [
310
+ `${from} -> ${to}`,
311
+ write,
312
+ `refused by ${invariant}`
313
+ ],
314
+ Unreached: ({ state }) => [
315
+ state,
316
+ "",
317
+ "unreached"
318
+ ],
319
+ Terminal: ({ state }) => [
320
+ state,
321
+ "",
322
+ "terminal"
323
+ ]
324
+ });
325
+ /** The entity a finding is of. */
326
+ const findingEntity = (finding) => finding.entity;
327
+ /** The report as text: each Entity's states and arrows, then each pair. */
328
+ const show = (report) => {
329
+ const sections = report.states.map(({ entity }) => {
330
+ return [entity, ...pad(report.findings.filter((finding) => findingEntity(finding) === entity).map(shownFinding)).map((line) => ` ${line}`)].join("\n");
331
+ });
332
+ const pairs = pad(report.pairs.map((pair) => [
333
+ pair.write,
334
+ `x ${pair.invariant}`,
335
+ shownVerdict(pair.verdict)
336
+ ]));
337
+ return [...sections, pairs.join("\n")].filter((part) => part.length > 0).join("\n\n");
338
+ };
339
+ const LawNode = Data.taggedEnum();
340
+ const LawEdge = Data.taggedEnum();
341
+ /**
342
+ * The report as graph facts: a Law per invariant, a Transition per write in
343
+ * a pair or an arrow (one judged against nothing and moving no state has no
344
+ * law to keep), a State per local state, what each law reads and each transition writes,
345
+ * each arrow's `from` and `to`, and a `keeps` edge per transition and law whose every
346
+ * pair carries an `Enumerated` record.
347
+ * A write's own `ensures` is no law of its Entity and is left out. An
348
+ * `Unknown` footprint writes every member, so it has a `writes` edge to each
349
+ * member a law of its Entity reads: every edge a rule of the graph can ask of.
350
+ */
351
+ const facts = (report) => {
352
+ const nodes = /* @__PURE__ */ new Map();
353
+ const edges = /* @__PURE__ */ new Map();
354
+ const node = (made) => nodes.set(JSON.stringify(made), made);
355
+ const edge = (key, made) => edges.set(JSON.stringify(key), made);
356
+ const keeps = /* @__PURE__ */ new Map();
357
+ const path = (entity, member) => {
358
+ const at = [entity, member];
359
+ node(LawNode.Path({
360
+ space: "entity",
361
+ path: at
362
+ }));
363
+ return at;
364
+ };
365
+ const write = (name, entity) => {
366
+ const id = transition({ name });
367
+ node(LawNode.Transition({
368
+ id,
369
+ kind: "write",
370
+ entity
371
+ }));
372
+ return id;
373
+ };
374
+ for (const { entity, names } of report.states) for (const name of names) node(LawNode.State({
375
+ entity,
376
+ name
377
+ }));
378
+ for (const pair of report.pairs) {
379
+ const by = write(pair.write, pair.entity);
380
+ const writes = Footprint.$match(pair.footprint, {
381
+ Derived: ({ writes }) => writes,
382
+ Declared: ({ writes }) => writes,
383
+ Unknown: () => pair.reads
384
+ });
385
+ for (const member of writes) edge([
386
+ "writes",
387
+ by,
388
+ pair.entity,
389
+ member
390
+ ], LawEdge.Writes({
391
+ transition: by,
392
+ space: "entity",
393
+ path: path(pair.entity, member)
394
+ }));
395
+ if (pair.postcondition) continue;
396
+ const id = law({
397
+ id: pair.invariant,
398
+ entity: pair.entity
399
+ });
400
+ node(LawNode.Law({ id }));
401
+ for (const member of pair.reads) edge([
402
+ "reads",
403
+ id,
404
+ pair.entity,
405
+ member
406
+ ], LawEdge.Reads({
407
+ law: id,
408
+ space: "entity",
409
+ path: path(pair.entity, member)
410
+ }));
411
+ if (pair.readsBefore) {
412
+ node(LawNode.Path({
413
+ space: "entity",
414
+ path: [pair.entity]
415
+ }));
416
+ edge([
417
+ "reads",
418
+ id,
419
+ pair.entity
420
+ ], LawEdge.Reads({
421
+ law: id,
422
+ space: "entity",
423
+ path: [pair.entity]
424
+ }));
425
+ }
426
+ const key = JSON.stringify([
427
+ "keeps",
428
+ by,
429
+ id
430
+ ]);
431
+ const known = keeps.get(key);
432
+ keeps.set(key, {
433
+ transition: by,
434
+ law: id,
435
+ evidence: known === void 0 ? pair.evidence : Option.flatMap(known.evidence, () => pair.evidence)
436
+ });
437
+ }
438
+ for (const { transition: by, law: id, evidence } of keeps.values()) if (Option.isSome(evidence)) edge([
439
+ "keeps",
440
+ by,
441
+ id
442
+ ], LawEdge.Keeps({
443
+ transition: by,
444
+ law: id,
445
+ evidence: evidence.value
446
+ }));
447
+ for (const { entity, write: name, from, to } of report.arrows) {
448
+ const by = write(name, entity);
449
+ edge([
450
+ "from",
451
+ by,
452
+ entity,
453
+ from
454
+ ], LawEdge.From({
455
+ transition: by,
456
+ entity,
457
+ state: from
458
+ }));
459
+ edge([
460
+ "to",
461
+ by,
462
+ entity,
463
+ to
464
+ ], LawEdge.To({
465
+ transition: by,
466
+ entity,
467
+ state: to
468
+ }));
469
+ }
470
+ for (const finding of report.findings) if (Finding.$is("Enforced")(finding)) {
471
+ const by = write(finding.write, finding.entity);
472
+ edge([
473
+ "to",
474
+ by,
475
+ finding.entity,
476
+ finding.to
477
+ ], LawEdge.To({
478
+ transition: by,
479
+ entity: finding.entity,
480
+ state: finding.to
481
+ }));
482
+ }
483
+ return {
484
+ nodes: [...nodes.values()],
485
+ edges: [...edges.values()]
486
+ };
487
+ };
488
+ /**
489
+ * Declared transitions as graph facts, read off the declarations alone: a
490
+ * transition per entry and the members it writes (an `Unknown` footprint
491
+ * every field), a law per invariant of its Entity and the members it reads,
492
+ * the Entity's states, and a write's `from` and `becomes`. Nothing is
493
+ * enumerated, since whether a transition keeps a law is evidence. What
494
+ * `foldkit-surface`'s `Graph.of` derives a contract's `laws.entities`
495
+ * with; a function by name, so that path does not carry `Laws.check`.
496
+ */
497
+ const lawFactsOf = (entries) => {
498
+ const nodes = /* @__PURE__ */ new Map();
499
+ const edges = /* @__PURE__ */ new Map();
500
+ const node = (made) => nodes.set(JSON.stringify(made), made);
501
+ const edge = (made) => edges.set(JSON.stringify(made), made);
502
+ for (const entry of entries) {
503
+ const entity = entityOf(entry);
504
+ const by = transition(entry);
505
+ const member = (key) => ({
506
+ space: "entity",
507
+ path: [entity.name, key]
508
+ });
509
+ node(LawNode.Transition({
510
+ id: by,
511
+ kind: "write",
512
+ entity: entity.name
513
+ }));
514
+ const written = Footprint.$match(footprintOf(entry), {
515
+ Derived: ({ writes }) => writes,
516
+ Declared: ({ writes }) => writes,
517
+ Unknown: () => Object.keys(entity.fields)
518
+ });
519
+ for (const key of written) edge(LawEdge.Writes({
520
+ transition: by,
521
+ ...member(key)
522
+ }));
523
+ for (const held of invariantsOf(entity)) {
524
+ const id = law(held);
525
+ node(LawNode.Law({ id }));
526
+ for (const key of readOf(held)) edge(LawEdge.Reads({
527
+ law: id,
528
+ ...member(key)
529
+ }));
530
+ if (readsBefore(held)) edge(LawEdge.Reads({
531
+ law: id,
532
+ space: "entity",
533
+ path: [entity.name]
534
+ }));
535
+ }
536
+ for (const state of states(entity)) node(LawNode.State({
537
+ entity: entity.name,
538
+ name: state.name
539
+ }));
540
+ if (!isWriteEntry(entry)) continue;
541
+ for (const state of Option.toArray(entry.write.from)) edge(LawEdge.From({
542
+ transition: by,
543
+ entity: entity.name,
544
+ state: state.name
545
+ }));
546
+ for (const state of Option.toArray(entry.write.becomes)) edge(LawEdge.To({
547
+ transition: by,
548
+ entity: entity.name,
549
+ state: state.name
550
+ }));
551
+ }
552
+ return {
553
+ nodes: [...nodes.values()],
554
+ edges: [...edges.values()]
555
+ };
556
+ };
557
+ const Laws = {
558
+ check,
559
+ show,
560
+ facts,
561
+ transition,
562
+ law
563
+ };
564
+ export { Finding, LawEdge, LawNode, LawVerdict, Laws, lawFactsOf };
565
+
566
+ //# sourceMappingURL=laws.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"laws.js","names":[],"sources":["../src/laws.ts"],"sourcesContent":["/**\n * `Laws.check`: each transition against each invariant of its Entity, and\n * the arrows its writes make between the Entity's states, by enumeration over\n * finite fields and nothing cleverer. Pure: it reads declarations and returns\n * a report, which is data; `Laws.show` prints it.\n */\nimport { Data, Match, Option, type Schema } from 'effect'\nimport { Evidence } from 'foldkit-metadata'\nimport { Steps, finiteValues, steps, type Step } from './enumerate.js'\nimport { judgeAgainst, readsBefore, invariantsOf, type Invariant } from './invariant.js'\nimport { declaredOwner, Footprint } from './footprint.js'\nimport { lawId, transitionId } from './lawIds.js'\nimport type { AnyEntity, EntityField } from './index.js'\nimport { kernelOperators } from './memoryTable.js'\nimport type { MemoryOperators } from './operators.js'\nimport { own } from './record.js'\nimport { inState, states, type AnyRefinement } from './refine.js'\n\ntype AnyField = EntityField<string, string, Schema.Constraint>\nimport { Write, writtenKeys, type AnyWrite } from './write.js'\n\n/** A declared write, as `Mutation.write` returns one. */\nexport interface WriteEntry {\n readonly name: string\n readonly write: AnyWrite\n}\n\n/** A transition that is no declared write: what it touches is the author's word, or unknown. */\nexport interface FootprintEntry<E extends AnyEntity = AnyEntity> {\n readonly name: string\n readonly entity: E\n readonly footprint: Footprint\n}\n\nexport type LawEntry = WriteEntry | FootprintEntry\n\n/** Refuses, at the entry, a declared footprint over another Entity than the entry's. */\ntype Checked<X> = X extends {\n readonly entity: infer E extends AnyEntity\n readonly footprint: infer F\n}\n ? F extends { readonly _tag: 'Declared'; readonly entity: infer Name }\n ? Name extends E['name']\n ? X\n : { readonly entity: E; readonly footprint: Footprint & { readonly entity: E['name'] } }\n : X\n : X\n\n/** How one transition stands against one invariant. */\nexport type LawVerdict = Data.TaggedEnum<{\n /**\n * It cannot break it. `by`: it writes nothing the (state) invariant reads,\n * its author says so, every row it can start from was enumerated, or there\n * is no row to judge (a create and a transition, a delete).\n */\n Kept: {\n readonly by: 'disjointness' | 'declared' | 'enumeration' | 'create' | 'delete'\n readonly rows: number\n }\n /** These steps leave a row that breaks it. */\n Refused: { readonly steps: ReadonlyArray<Step> }\n /** Nothing here can say, and why. */\n Undecided: { readonly reason: string }\n}>\nexport const LawVerdict = Data.taggedEnum<LawVerdict>()\n\n/** One transition against one invariant of its Entity. */\nexport interface LawPair {\n readonly write: string\n readonly entity: string\n readonly invariant: string\n /** The members the invariant reads, before and after, by field key. */\n readonly reads: ReadonlyArray<string>\n /**\n * True for a transition invariant, which reads the row before: a write that\n * leaves every member it reads alone can still break it, so the graph reads\n * it as reading the whole row.\n */\n readonly readsBefore: boolean\n readonly footprint: Footprint\n readonly verdict: LawVerdict\n /** True for a write's own `ensures`: a law of that write alone, held where it commits. */\n readonly postcondition: boolean\n /**\n * An `Enumerated` record for a pair the check kept by reading the\n * declarations; none for an author's word (`declared`), a refusal, or an\n * undecided pair.\n */\n readonly evidence: Option.Option<Evidence>\n}\n\n/** A write taking a row from one state of its Entity to another. */\nexport interface Arrow {\n readonly entity: string\n readonly write: string\n readonly from: string\n readonly to: string\n}\n\n/** What the check says of an arrow or a state. A report, never a fault. */\nexport type Finding = Data.TaggedEnum<{\n /** The arrow into the state its write declared it `becomes`. */\n Holds: Arrow\n /** A write with no such `becomes` makes the arrow. */\n Undeclared: Arrow\n /**\n * The write's `becomes` enumeration could not decide, kept where it commits\n * by its postcondition: every row it lands is in `to`, from whatever state.\n */\n Enforced: { readonly entity: string; readonly write: string; readonly to: string }\n /** Every row the arrow leaves breaks `invariant`, which refuses the write there. */\n Refused: Arrow & { readonly invariant: string }\n /** No write leaves a row in the state. */\n Unreached: { readonly entity: string; readonly state: string }\n /** No write starts from it. */\n Terminal: { readonly entity: string; readonly state: string }\n}>\nexport const Finding = Data.taggedEnum<Finding>()\n\nexport interface LawReport {\n readonly pairs: ReadonlyArray<LawPair>\n readonly arrows: ReadonlyArray<Arrow>\n /** Each Entity's local states, by name. */\n readonly states: ReadonlyArray<{ readonly entity: string; readonly names: ReadonlyArray<string> }>\n readonly findings: ReadonlyArray<Finding>\n}\n\nconst isWriteEntry = (entry: LawEntry): entry is WriteEntry => Object.hasOwn(entry, 'write')\n\nconst entityOf = (entry: LawEntry): AnyEntity =>\n isWriteEntry(entry) ? entry.write.input.entity : entry.entity\n\nconst footprintOf = (entry: LawEntry): Footprint => {\n if (isWriteEntry(entry)) return Write.footprint(entry.write)\n const owner = declaredOwner.get(entry.footprint)\n if (owner !== undefined && owner !== entry.entity.identity)\n throw new Error(\n `[foldkit-entity] Laws.check: ${entry.name} is over ${entry.entity.name}, but its footprint names ${owner.name}'s fields`,\n )\n return entry.footprint\n}\n\n/** Every member an invariant reads, before and after. */\nconst readOf = (held: Invariant): ReadonlyArray<string> => [\n ...new Set([...held.before, ...held.after]),\n]\n\nconst disjoint = (writes: ReadonlyArray<string>, reads: ReadonlyArray<string>): boolean =>\n !writes.some(key => reads.includes(key))\n\nconst issuer = Evidence.issuer('foldkit-entity/laws')\n\nconst transition = transitionId\nconst law = lawId\n\n/** The record for a pair the check decided it keeps, unless only its author says so. */\nconst evidenceOf = (name: string, held: Invariant, verdict: LawVerdict): Option.Option<Evidence> =>\n LawVerdict.$match(verdict, {\n Kept: ({ by }) =>\n by === 'declared'\n ? Option.none()\n : Option.some(\n issuer.issue(Evidence.Enumerated({ transition: transition({ name }), law: law(held) })),\n ),\n Refused: () => Option.none(),\n Undecided: () => Option.none(),\n })\n\n/** One declared write against one invariant. */\nconst judgeWrite = (write: AnyWrite, held: Invariant, operators: MemoryOperators): LawVerdict => {\n if (write._tag === 'Delete') return LawVerdict.Kept({ by: 'delete', rows: 0 })\n const transition = readsBefore(held)\n if (write._tag === 'Insert' && transition) return LawVerdict.Kept({ by: 'create', rows: 0 })\n const reads = readOf(held)\n // Disjointness decides a state invariant only: a transition invariant can be broken by a write leaving it alone.\n if (write._tag === 'Update' && !transition && disjoint(writtenKeys(write), reads))\n return LawVerdict.Kept({ by: 'disjointness', rows: 0 })\n return Steps.$match(steps(write, reads, { operators }), {\n Undecided: ({ reason }) => LawVerdict.Undecided({ reason }),\n Steps: ({ steps: each }) => {\n const refused: Array<Step> = []\n // An insert's step has an empty row before, which a state invariant does not read.\n for (const step of each) {\n const undecided = Match.valueTags(judgeAgainst([held], step, operators), {\n Valid: () => Option.none<string>(),\n Invalid: () => {\n refused.push(step)\n return Option.none<string>()\n },\n Undecided: ({ fields, operators: unrun }) =>\n Option.some(\n unrun.length > 0\n ? `it calls ${unrun.join(', ')}, which the operator table does not run`\n : `the write may leave ${fields.join(', ')} unwritten`,\n ),\n })\n if (Option.isSome(undecided)) return LawVerdict.Undecided({ reason: undecided.value })\n }\n return refused.length > 0\n ? LawVerdict.Refused({ steps: refused })\n : LawVerdict.Kept({ by: 'enumeration', rows: each.length })\n },\n })\n}\n\n/** One transition known by its footprint alone against one invariant. */\nconst judgeFootprint = (footprint: Footprint, held: Invariant): LawVerdict =>\n Footprint.$match(footprint, {\n Unknown: () => LawVerdict.Undecided({ reason: 'what it writes is unknown, so every member' }),\n Derived: () => LawVerdict.Undecided({ reason: 'a derived footprint needs its write' }),\n Declared: ({ writes, by }) => {\n if (readsBefore(held))\n return LawVerdict.Undecided({\n reason: `a transition invariant is not kept by disjointness, and ${by}'s word is all there is`,\n })\n const touched = writes.filter(key => readOf(held).includes(key))\n return touched.length === 0\n ? LawVerdict.Kept({ by: 'declared', rows: 0 })\n : LawVerdict.Undecided({ reason: `${by} says it writes ${touched.join(', ')}` })\n },\n })\n\ninterface Arrows {\n readonly arrows: ReadonlyArray<Arrow>\n readonly findings: ReadonlyArray<Finding>\n readonly reached: ReadonlySet<string>\n readonly left: ReadonlySet<string>\n /** The states a write may move a row into or out of that enumeration could not decide. */\n readonly undecided: ReadonlySet<string>\n}\n\n/** The arrows one write makes between `local`, its Entity's local states. */\nconst arrowsOf = (\n name: string,\n write: AnyWrite,\n local: ReadonlyArray<AnyRefinement>,\n invariants: ReadonlyArray<Invariant>,\n operators: MemoryOperators,\n): Arrows => {\n const entity = write.input.entity.name\n const none: Arrows = {\n arrows: [],\n findings: [],\n reached: new Set<string>(),\n left: new Set<string>(),\n undecided: new Set<string>(),\n }\n if (write._tag === 'Delete') return none\n const written = writtenKeys(write)\n const moved = local.filter(state => state.reads.some(key => written.includes(key)))\n // A state over a field that is not finite (`InStock`, over a number) is never enumerated,\n // so it costs the others nothing: a write moving a row into or out of it is undecided there.\n const fields = write.input.entity.fields as Readonly<Record<string, AnyField>>\n const finite = (state: AnyRefinement) =>\n state.reads.every(key =>\n Option.isSome(\n Option.flatMap(Option.fromUndefinedOr(own(fields, key)), field =>\n finiteValues(field.schema as unknown as Schema.Top),\n ),\n ),\n )\n const enumerable = local.filter(finite)\n const unenumerable = new Set(moved.filter(state => !finite(state)).map(state => state.name))\n if (!moved.some(finite)) return { ...none, undecided: unenumerable }\n const members = [...new Set(enumerable.flatMap(state => state.reads))]\n return Steps.$match(steps(write, members, { operators }), {\n Undecided: () => ({ ...none, undecided: new Set(moved.map(state => state.name)) }),\n Steps: ({ steps: each }) => {\n const reached = new Set<string>()\n const left = new Set<string>()\n // Per arrow: whether every row it leaves is refused, and by which invariant first.\n const groups = new Map<\n string,\n { from: string; to: string; refusedBy: Option.Option<string> }\n >()\n const inOf = (row: Step['after']) =>\n enumerable.filter(state => Option.getOrElse(inState(state, row, operators), () => false))\n for (const step of each) {\n const after = inOf(step.after)\n if (write._tag === 'Insert') {\n after.forEach(state => reached.add(state.name))\n continue\n }\n const before = inOf(step.before)\n const judged = judgeAgainst(invariants, step, operators)\n const refusedBy = Match.valueTags(judged, {\n Invalid: ({ failures }) => Option.some(failures[0]!.id),\n Valid: () => Option.none<string>(),\n Undecided: () => Option.none<string>(),\n })\n for (const from of before) {\n for (const to of after) {\n if (from === to || before.includes(to)) continue\n const key = JSON.stringify([from.name, to.name])\n const group = groups.get(key)\n groups.set(key, {\n from: from.name,\n to: to.name,\n refusedBy:\n group === undefined ? refusedBy : Option.flatMap(group.refusedBy, () => refusedBy),\n })\n left.add(from.name)\n if (Option.isNone(refusedBy)) reached.add(to.name)\n }\n }\n }\n const arrows: Array<Arrow> = []\n const findings: Array<Finding> = []\n for (const { from, to, refusedBy } of groups.values()) {\n const arrow = { entity, write: name, from, to }\n arrows.push(arrow)\n findings.push(\n Option.match(refusedBy, {\n onSome: invariant => Finding.Refused({ ...arrow, invariant }),\n onNone: () =>\n Option.exists(write.becomes, state => state.name === to)\n ? Finding.Holds(arrow)\n : Finding.Undeclared(arrow),\n }),\n )\n }\n return { arrows, findings, reached, left, undecided: unenumerable }\n },\n })\n}\n\n/**\n * Checks each transition against each invariant of its Entity, and the arrows\n * its writes make between the Entity's declared states. An entry is a\n * declared write (`{ name, write }`, as `Mutation.write` returns), or a\n * transition known by its footprint (`{ name, entity, footprint }`). Pure, and\n * what it finds is a report, never a fault; it throws only for two entries of\n * one name, which its report could not tell apart.\n */\nconst check = <const W extends ReadonlyArray<LawEntry>>(options: {\n readonly writes: W & { readonly [K in keyof W]: Checked<W[K]> }\n readonly operators?: MemoryOperators | undefined\n}): LawReport => {\n const operators = options.operators ?? kernelOperators\n const entries = options.writes as ReadonlyArray<LawEntry>\n const pairs: Array<LawPair> = []\n const entities: Array<AnyEntity> = []\n const names = new Set<string>()\n for (const entry of entries) {\n // Pairs, arrows and evidence name a transition by its name alone.\n if (names.has(entry.name))\n throw new Error(`[foldkit-entity] Laws.check: two transitions are named ${entry.name}`)\n names.add(entry.name)\n const entity = entityOf(entry)\n if (!entities.some(known => known.identity === entity.identity)) entities.push(entity)\n const footprint = footprintOf(entry)\n // A write's own postcondition is judged as an invariant of that write alone.\n const ensured = isWriteEntry(entry) ? Option.toArray(entry.write.ensures) : []\n for (const held of [...invariantsOf(entity), ...ensured]) {\n const verdict = isWriteEntry(entry)\n ? judgeWrite(entry.write, held, operators)\n : judgeFootprint(entry.footprint, held)\n pairs.push({\n write: entry.name,\n entity: entity.name,\n invariant: held.id,\n reads: readOf(held),\n readsBefore: readsBefore(held),\n footprint,\n verdict,\n postcondition: ensured.includes(held),\n evidence: evidenceOf(entry.name, held, verdict),\n })\n }\n }\n const arrows: Array<Arrow> = []\n const findings: Array<Finding> = []\n const stateList: Array<{ readonly entity: string; readonly names: ReadonlyArray<string> }> = []\n for (const entity of entities) {\n const local = states(entity).filter(state => state.local)\n if (local.length === 0) continue\n stateList.push({ entity: entity.name, names: local.map(state => state.name) })\n const invariants = invariantsOf(entity)\n const reached = new Set<string>()\n const left = new Set<string>()\n const undecided = new Set<string>()\n for (const entry of entries) {\n if (entityOf(entry).identity !== entity.identity) continue\n // A transition without a write makes no arrows, but may move a row anywhere it writes.\n if (!isWriteEntry(entry)) {\n const footprint = footprintOf(entry)\n const writes = Footprint.$match(footprint, {\n Unknown: () => undefined,\n Derived: ({ writes }) => writes,\n Declared: ({ writes }) => writes,\n })\n local\n .filter(state => writes === undefined || state.reads.some(key => writes.includes(key)))\n .forEach(state => undecided.add(state.name))\n continue\n }\n const made = arrowsOf(entry.name, entry.write, local, invariants, operators)\n arrows.push(...made.arrows)\n findings.push(...made.findings)\n const { becomes, ensures } = entry.write\n if (Option.isSome(ensures) && Option.isSome(becomes)) {\n const to = becomes.value.name\n findings.push(Finding.Enforced({ entity: entity.name, write: entry.name, to }))\n reached.add(to)\n }\n made.reached.forEach(state => reached.add(state))\n made.left.forEach(state => left.add(state))\n made.undecided.forEach(state => undecided.add(state))\n }\n for (const state of local) {\n if (undecided.has(state.name)) continue\n if (!reached.has(state.name))\n findings.push(Finding.Unreached({ entity: entity.name, state: state.name }))\n if (!left.has(state.name))\n findings.push(Finding.Terminal({ entity: entity.name, state: state.name }))\n }\n }\n return { pairs, arrows, states: stateList, findings }\n}\n\nconst pad = (rows: ReadonlyArray<ReadonlyArray<string>>): ReadonlyArray<string> => {\n const widths = rows.reduce<Array<number>>(\n (most, row) => row.map((cell, at) => Math.max(most[at] ?? 0, cell.length)),\n [],\n )\n return rows.map(row =>\n row\n .map((cell, at) => (at === row.length - 1 ? cell : cell.padEnd(widths[at]! + 3)))\n .join('')\n .trimEnd(),\n )\n}\n\nconst shownVerdict = (verdict: LawVerdict): string =>\n LawVerdict.$match(verdict, {\n Kept: ({ by, rows }) =>\n ({\n disjointness: 'kept: writes no member it reads',\n declared: 'kept: declared to write no member it reads',\n enumeration: `kept: ${rows} row${rows === 1 ? '' : 's'} enumerated`,\n create: 'kept: a create has no row before',\n delete: 'kept: a delete leaves no row',\n })[by],\n Refused: ({ steps: each }) =>\n `refused: from ${JSON.stringify(each[0]!.before)} it leaves ${JSON.stringify(each[0]!.after)}`,\n Undecided: ({ reason }) => `undecided: ${reason}`,\n })\n\nconst shownFinding = (finding: Finding): readonly [string, string, string] =>\n Finding.$match(finding, {\n Holds: ({ from, to, write }) => [`${from} -> ${to}`, write, 'holds'] as const,\n Undeclared: ({ from, to, write }) => [`${from} -> ${to}`, write, 'undeclared'] as const,\n Enforced: ({ to, write }) => [`* -> ${to}`, write, 'enforced'] as const,\n Refused: ({ from, to, write, invariant }) =>\n [`${from} -> ${to}`, write, `refused by ${invariant}`] as const,\n Unreached: ({ state }) => [state, '', 'unreached'] as const,\n Terminal: ({ state }) => [state, '', 'terminal'] as const,\n })\n\n/** The entity a finding is of. */\nconst findingEntity = (finding: Finding): string => finding.entity\n\n/** The report as text: each Entity's states and arrows, then each pair. */\nconst show = (report: LawReport): string => {\n const sections = report.states.map(({ entity }) => {\n const lines = pad(\n report.findings.filter(finding => findingEntity(finding) === entity).map(shownFinding),\n )\n return [entity, ...lines.map(line => ` ${line}`)].join('\\n')\n })\n const pairs = pad(\n report.pairs.map(pair => [pair.write, `x ${pair.invariant}`, shownVerdict(pair.verdict)]),\n )\n return [...sections, pairs.join('\\n')].filter(part => part.length > 0).join('\\n\\n')\n}\n\n/** A node of the law half of `foldkit-surface`'s graph, as plain data. */\nexport type LawNode = Data.TaggedEnum<{\n /** A member of an Entity (`['Product', 'reserved']`), or its whole row (`['Product']`), which a transition invariant reads. */\n Path: { readonly space: 'entity'; readonly path: ReadonlyArray<string> }\n /** A transition over one Entity's rows: a delete, which writes no member, is still of its Entity. */\n Transition: { readonly id: string; readonly kind: 'write'; readonly entity: string }\n Law: { readonly id: string }\n State: { readonly entity: string; readonly name: string }\n}>\nexport const LawNode = Data.taggedEnum<LawNode>()\n\n/** An edge of the law half of the graph, naming its nodes by id or path, each path an Entity member. */\nexport type LawEdge = Data.TaggedEnum<{\n Reads: { readonly law: string; readonly space: 'entity'; readonly path: ReadonlyArray<string> }\n Writes: {\n readonly transition: string\n readonly space: 'entity'\n readonly path: ReadonlyArray<string>\n }\n From: { readonly transition: string; readonly entity: string; readonly state: string }\n To: { readonly transition: string; readonly entity: string; readonly state: string }\n Keeps: { readonly transition: string; readonly law: string; readonly evidence: Evidence }\n}>\nexport const LawEdge = Data.taggedEnum<LawEdge>()\n\nexport interface LawFacts {\n readonly nodes: ReadonlyArray<LawNode>\n readonly edges: ReadonlyArray<LawEdge>\n}\n\n/**\n * The report as graph facts: a Law per invariant, a Transition per write in\n * a pair or an arrow (one judged against nothing and moving no state has no\n * law to keep), a State per local state, what each law reads and each transition writes,\n * each arrow's `from` and `to`, and a `keeps` edge per transition and law whose every\n * pair carries an `Enumerated` record.\n * A write's own `ensures` is no law of its Entity and is left out. An\n * `Unknown` footprint writes every member, so it has a `writes` edge to each\n * member a law of its Entity reads: every edge a rule of the graph can ask of.\n */\nconst facts = (report: LawReport): LawFacts => {\n const nodes = new Map<string, LawNode>()\n const edges = new Map<string, LawEdge>()\n const node = (made: LawNode) => nodes.set(JSON.stringify(made), made)\n const edge = (key: unknown, made: LawEdge) => edges.set(JSON.stringify(key), made)\n // Per (transition, law), the last record, or none once any pair for it has none.\n const keeps = new Map<\n string,\n {\n readonly transition: string\n readonly law: string\n readonly evidence: Option.Option<Evidence>\n }\n >()\n const path = (entity: string, member: string) => {\n const at = [entity, member]\n node(LawNode.Path({ space: 'entity', path: at }))\n return at\n }\n const write = (name: string, entity: string) => {\n const id = transition({ name })\n node(LawNode.Transition({ id, kind: 'write', entity }))\n return id\n }\n for (const { entity, names } of report.states)\n for (const name of names) node(LawNode.State({ entity, name }))\n for (const pair of report.pairs) {\n const by = write(pair.write, pair.entity)\n const writes = Footprint.$match(pair.footprint, {\n Derived: ({ writes }) => writes,\n Declared: ({ writes }) => writes,\n Unknown: () => pair.reads,\n })\n for (const member of writes)\n edge(\n ['writes', by, pair.entity, member],\n LawEdge.Writes({ transition: by, space: 'entity', path: path(pair.entity, member) }),\n )\n if (pair.postcondition) continue\n const id = law({ id: pair.invariant, entity: pair.entity })\n node(LawNode.Law({ id }))\n for (const member of pair.reads)\n edge(\n ['reads', id, pair.entity, member],\n LawEdge.Reads({ law: id, space: 'entity', path: path(pair.entity, member) }),\n )\n if (pair.readsBefore) {\n node(LawNode.Path({ space: 'entity', path: [pair.entity] }))\n edge(\n ['reads', id, pair.entity],\n LawEdge.Reads({ law: id, space: 'entity', path: [pair.entity] }),\n )\n }\n const key = JSON.stringify(['keeps', by, id])\n const known = keeps.get(key)\n keeps.set(key, {\n transition: by,\n law: id,\n evidence:\n known === undefined ? pair.evidence : Option.flatMap(known.evidence, () => pair.evidence),\n })\n }\n for (const { transition: by, law: id, evidence } of keeps.values())\n if (Option.isSome(evidence))\n edge(['keeps', by, id], LawEdge.Keeps({ transition: by, law: id, evidence: evidence.value }))\n for (const { entity, write: name, from, to } of report.arrows) {\n const by = write(name, entity)\n edge(['from', by, entity, from], LawEdge.From({ transition: by, entity, state: from }))\n edge(['to', by, entity, to], LawEdge.To({ transition: by, entity, state: to }))\n }\n for (const finding of report.findings)\n if (Finding.$is('Enforced')(finding)) {\n const by = write(finding.write, finding.entity)\n edge(\n ['to', by, finding.entity, finding.to],\n LawEdge.To({ transition: by, entity: finding.entity, state: finding.to }),\n )\n }\n return { nodes: [...nodes.values()], edges: [...edges.values()] }\n}\n\n/**\n * Declared transitions as graph facts, read off the declarations alone: a\n * transition per entry and the members it writes (an `Unknown` footprint\n * every field), a law per invariant of its Entity and the members it reads,\n * the Entity's states, and a write's `from` and `becomes`. Nothing is\n * enumerated, since whether a transition keeps a law is evidence. What\n * `foldkit-surface`'s `Graph.of` derives a contract's `laws.entities`\n * with; a function by name, so that path does not carry `Laws.check`.\n */\nexport const lawFactsOf = (entries: ReadonlyArray<LawEntry>): LawFacts => {\n const nodes = new Map<string, LawNode>()\n const edges = new Map<string, LawEdge>()\n const node = (made: LawNode) => nodes.set(JSON.stringify(made), made)\n const edge = (made: LawEdge) => edges.set(JSON.stringify(made), made)\n for (const entry of entries) {\n const entity = entityOf(entry)\n const by = transition(entry)\n const member = (key: string) => ({ space: 'entity' as const, path: [entity.name, key] })\n node(LawNode.Transition({ id: by, kind: 'write', entity: entity.name }))\n const written = Footprint.$match(footprintOf(entry), {\n Derived: ({ writes }) => writes,\n Declared: ({ writes }) => writes,\n Unknown: () => Object.keys(entity.fields),\n })\n for (const key of written) edge(LawEdge.Writes({ transition: by, ...member(key) }))\n for (const held of invariantsOf(entity)) {\n const id = law(held)\n node(LawNode.Law({ id }))\n for (const key of readOf(held)) edge(LawEdge.Reads({ law: id, ...member(key) }))\n // A write leaving a transition invariant's members alone can still break it: it reads the row.\n if (readsBefore(held)) edge(LawEdge.Reads({ law: id, space: 'entity', path: [entity.name] }))\n }\n for (const state of states(entity))\n node(LawNode.State({ entity: entity.name, name: state.name }))\n if (!isWriteEntry(entry)) continue\n for (const state of Option.toArray(entry.write.from))\n edge(LawEdge.From({ transition: by, entity: entity.name, state: state.name }))\n for (const state of Option.toArray(entry.write.becomes))\n edge(LawEdge.To({ transition: by, entity: entity.name, state: state.name }))\n }\n return { nodes: [...nodes.values()], edges: [...edges.values()] }\n}\n\nexport const Laws = {\n check,\n show,\n facts,\n transition,\n law,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgEA,MAAa,aAAa,KAAK,WAAuB;AAqDtD,MAAa,UAAU,KAAK,WAAoB;AAUhD,MAAM,gBAAgB,UAAyC,OAAO,OAAO,OAAO,OAAO;AAE3F,MAAM,YAAY,UAChB,aAAa,KAAK,IAAI,MAAM,MAAM,MAAM,SAAS,MAAM;AAEzD,MAAM,eAAe,UAA+B;CAClD,IAAI,aAAa,KAAK,GAAG,OAAO,MAAM,UAAU,MAAM,KAAK;CAC3D,MAAM,QAAQ,cAAc,IAAI,MAAM,SAAS;CAC/C,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO,UAChD,MAAM,IAAI,MACR,gCAAgC,MAAM,KAAK,WAAW,MAAM,OAAO,KAAK,4BAA4B,MAAM,KAAK,UACjH;CACF,OAAO,MAAM;AACf;;AAGA,MAAM,UAAU,SAA2C,CACzD,mBAAG,IAAI,IAAI,CAAC,GAAG,KAAK,QAAQ,GAAG,KAAK,KAAK,CAAC,CAC5C;AAEA,MAAM,YAAY,QAA+B,UAC/C,CAAC,OAAO,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AAEzC,MAAM,SAAS,SAAS,OAAO,qBAAqB;AAEpD,MAAM,aAAa;AACnB,MAAM,MAAM;;AAGZ,MAAM,cAAc,MAAc,MAAiB,YACjD,WAAW,OAAO,SAAS;CACzB,OAAO,EAAE,SACP,OAAO,aACH,OAAO,KAAK,IACZ,OAAO,KACL,OAAO,MAAM,SAAS,WAAW;EAAE,YAAY,WAAW,EAAE,KAAK,CAAC;EAAG,KAAK,IAAI,IAAI;CAAE,CAAC,CAAC,CACxF;CACN,eAAe,OAAO,KAAK;CAC3B,iBAAiB,OAAO,KAAK;AAC/B,CAAC;;AAGH,MAAM,cAAc,OAAiB,MAAiB,cAA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3
+ /** An operator by its id, and its version when that is not the first. */
4
+ export declare const nameOf: (operator: OperatorDescriptor) => string;
5
+ export declare const fail: (what: string) => never;
6
+ export declare const table: (implementations: ReadonlyArray<MemoryImplementation>, checked: boolean, evidence: ReadonlyArray<Evidence>) => MemoryOperators;
7
+ /** An implementation, its operator's null rule checked against the function chosen for it. */
8
+ export declare const implementation: (operator: OperatorDescriptor, nulls: OperatorDescriptor['nulls'], run: (...args: ReadonlyArray<unknown>) => unknown) => MemoryImplementation;
9
+ /** The kernel's own operators (`Text.startsWith`): every memory interpreter's default. */
10
+ export declare const kernelOperators: MemoryOperators;
11
+ //# sourceMappingURL=memoryTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryTable.d.ts","names":[],"sources":["../src/memoryTable.ts"],"mappings":";;;qBAgBa,SAAM,UAAc;qBAGpB,OAAI;qBAIJ,QAAK,iBACC,cAAc,uBAAqB,kBACpC,UACN,cAAc,cACvB;;qBA+BU,iBAAc,UACf,oBAAkB,OACrB,6BAA2B,SACzB,MAAM,uCACd;;qBAoDU,iBAAe"}