foldkit-surface 0.14.0 → 0.15.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 +205 -6
- package/dist/closure.d.ts +75 -0
- package/dist/closure.d.ts.map +1 -0
- package/dist/closure.js +95 -0
- package/dist/closure.js.map +1 -0
- package/dist/graph.d.ts +238 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +350 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +56 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -23
- package/dist/index.js.map +1 -1
- package/dist/messageTags.d.ts +9 -0
- package/dist/messageTags.d.ts.map +1 -0
- package/dist/messageTags.js +14 -0
- package/dist/messageTags.js.map +1 -0
- package/dist/text.d.ts +6 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +8 -0
- package/dist/text.js.map +1 -0
- package/package.json +5 -4
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
import { LawEntry } from "foldkit-entity";
|
|
3
|
+
import { Evidence } from "foldkit-metadata";
|
|
4
|
+
import { Finding, Module } from "./index.js";
|
|
5
|
+
/** Where a path is: a Model field (`['todos']`) or an Entity member (`['Product', 'stock']`). */
|
|
6
|
+
export type GraphSpace = 'model' | 'entity';
|
|
7
|
+
export type GraphNode = Data.TaggedEnum<{
|
|
8
|
+
/** A contract that owns Model paths: `remote:Shop`, `sync:todos-capped`. */
|
|
9
|
+
Owner: {
|
|
10
|
+
readonly kind: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
};
|
|
13
|
+
Path: {
|
|
14
|
+
readonly space: GraphSpace;
|
|
15
|
+
readonly path: ReadonlyArray<string>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A declared write (`write:Sell`), with the Entity whose rows it writes, or
|
|
19
|
+
* a durable Message (`durable:CreatedTodo`), with none.
|
|
20
|
+
*/
|
|
21
|
+
Transition: {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly kind: 'write' | 'durable';
|
|
24
|
+
readonly entity?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
/** An Entity's invariant (`Product.reservedWithinStock`), a document's law, or a closed Surface's closure. */
|
|
27
|
+
Law: {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
};
|
|
30
|
+
/** A declared state of an Entity. */
|
|
31
|
+
State: {
|
|
32
|
+
readonly entity: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
};
|
|
35
|
+
/** A Surface declared `closed: true`. */
|
|
36
|
+
Level: {
|
|
37
|
+
readonly surface: string;
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
export declare const GraphNode: Data.TaggedEnum.Constructor<{
|
|
41
|
+
readonly _tag: "Law";
|
|
42
|
+
readonly id: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly _tag: "Level";
|
|
45
|
+
readonly surface: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly _tag: "Owner";
|
|
48
|
+
readonly kind: string;
|
|
49
|
+
readonly name: string;
|
|
50
|
+
} | {
|
|
51
|
+
readonly _tag: "Path";
|
|
52
|
+
readonly space: GraphSpace;
|
|
53
|
+
readonly path: ReadonlyArray<string>;
|
|
54
|
+
} | {
|
|
55
|
+
readonly _tag: "State";
|
|
56
|
+
readonly entity: string;
|
|
57
|
+
readonly name: string;
|
|
58
|
+
} | {
|
|
59
|
+
readonly _tag: "Transition";
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly kind: 'write' | 'durable';
|
|
62
|
+
readonly entity?: string | undefined;
|
|
63
|
+
}>;
|
|
64
|
+
export type GraphEdge = Data.TaggedEnum<{
|
|
65
|
+
/** `owner` (`kind:name`) is the authority for a Model path. */
|
|
66
|
+
Owns: {
|
|
67
|
+
readonly owner: string;
|
|
68
|
+
readonly path: ReadonlyArray<string>;
|
|
69
|
+
};
|
|
70
|
+
Reads: {
|
|
71
|
+
readonly law: string;
|
|
72
|
+
readonly space: GraphSpace;
|
|
73
|
+
readonly path: ReadonlyArray<string>;
|
|
74
|
+
};
|
|
75
|
+
Writes: {
|
|
76
|
+
readonly transition: string;
|
|
77
|
+
readonly space: GraphSpace;
|
|
78
|
+
readonly path: ReadonlyArray<string>;
|
|
79
|
+
};
|
|
80
|
+
/** A closed Surface's projection reads a Model path. */
|
|
81
|
+
Observes: {
|
|
82
|
+
readonly level: string;
|
|
83
|
+
readonly path: ReadonlyArray<string>;
|
|
84
|
+
};
|
|
85
|
+
/** The write starts only from this state. */
|
|
86
|
+
From: {
|
|
87
|
+
readonly transition: string;
|
|
88
|
+
readonly entity: string;
|
|
89
|
+
readonly state: string;
|
|
90
|
+
};
|
|
91
|
+
/** The write leaves its row in this state. */
|
|
92
|
+
To: {
|
|
93
|
+
readonly transition: string;
|
|
94
|
+
readonly entity: string;
|
|
95
|
+
readonly state: string;
|
|
96
|
+
};
|
|
97
|
+
/** The transition keeps the law, and the record that shows it. */
|
|
98
|
+
Keeps: {
|
|
99
|
+
readonly transition: string;
|
|
100
|
+
readonly law: string;
|
|
101
|
+
readonly evidence: Evidence;
|
|
102
|
+
};
|
|
103
|
+
/** `level`'s projection contains every path of `of`'s, and more. */
|
|
104
|
+
Refines: {
|
|
105
|
+
readonly level: string;
|
|
106
|
+
readonly of: string;
|
|
107
|
+
};
|
|
108
|
+
}>;
|
|
109
|
+
export declare const GraphEdge: Data.TaggedEnum.Constructor<{
|
|
110
|
+
readonly _tag: "From";
|
|
111
|
+
readonly transition: string;
|
|
112
|
+
readonly entity: string;
|
|
113
|
+
readonly state: string;
|
|
114
|
+
} | {
|
|
115
|
+
readonly _tag: "Keeps";
|
|
116
|
+
readonly transition: string;
|
|
117
|
+
readonly law: string;
|
|
118
|
+
readonly evidence: Evidence;
|
|
119
|
+
} | {
|
|
120
|
+
readonly _tag: "Observes";
|
|
121
|
+
readonly level: string;
|
|
122
|
+
readonly path: ReadonlyArray<string>;
|
|
123
|
+
} | {
|
|
124
|
+
readonly _tag: "Owns";
|
|
125
|
+
readonly owner: string;
|
|
126
|
+
readonly path: ReadonlyArray<string>;
|
|
127
|
+
} | {
|
|
128
|
+
readonly _tag: "Reads";
|
|
129
|
+
readonly law: string;
|
|
130
|
+
readonly space: GraphSpace;
|
|
131
|
+
readonly path: ReadonlyArray<string>;
|
|
132
|
+
} | {
|
|
133
|
+
readonly _tag: "Refines";
|
|
134
|
+
readonly level: string;
|
|
135
|
+
readonly of: string;
|
|
136
|
+
} | {
|
|
137
|
+
readonly _tag: "To";
|
|
138
|
+
readonly transition: string;
|
|
139
|
+
readonly entity: string;
|
|
140
|
+
readonly state: string;
|
|
141
|
+
} | {
|
|
142
|
+
readonly _tag: "Writes";
|
|
143
|
+
readonly transition: string;
|
|
144
|
+
readonly space: GraphSpace;
|
|
145
|
+
readonly path: ReadonlyArray<string>;
|
|
146
|
+
}>;
|
|
147
|
+
/** Nodes and edges, as `Graph.of` returns them. */
|
|
148
|
+
export interface GraphFacts {
|
|
149
|
+
readonly nodes: ReadonlyArray<GraphNode>;
|
|
150
|
+
readonly edges: ReadonlyArray<GraphEdge>;
|
|
151
|
+
}
|
|
152
|
+
/** What a contract declares of its laws, read by `Graph.of` when asked. */
|
|
153
|
+
export interface ContractLaws {
|
|
154
|
+
/**
|
|
155
|
+
* Laws over the contract's Model slice, by id, as a Sync document declares
|
|
156
|
+
* them: each is `<kind>:<name>.<id>`, taken to read every path the contract
|
|
157
|
+
* owns (a law is a function, so the whole slice), and each of the
|
|
158
|
+
* contract's Messages is a transition `durable:<tag>` writing it. Given,
|
|
159
|
+
* even empty, the transitions are drawn.
|
|
160
|
+
*/
|
|
161
|
+
readonly model?: ReadonlyArray<string> | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Transitions over Entities, as `Laws.check` takes them: a declared write
|
|
164
|
+
* (`{ name, write }`, as `Mutation.write` returns), or one known by its
|
|
165
|
+
* footprint. Each is `write:<name>`, beside each invariant of its Entity.
|
|
166
|
+
*/
|
|
167
|
+
readonly entities?: ReadonlyArray<LawEntry> | undefined;
|
|
168
|
+
}
|
|
169
|
+
/** An application's graph: every contract's facts, its closed Surfaces, and the evidence admitted. */
|
|
170
|
+
export interface Graph extends GraphFacts {}
|
|
171
|
+
/** What `Graph` reads beside the contracts. */
|
|
172
|
+
export interface GraphOptions {
|
|
173
|
+
/**
|
|
174
|
+
* Records that a transition keeps a law: what a test's walks and scenarios
|
|
175
|
+
* returned, `Laws.check`'s `Enumerated` records, and `Evidence.runtimeOnly`
|
|
176
|
+
* lines. One issued by no producer, or naming a pair the graph does not
|
|
177
|
+
* join, is not admitted and is reported as `evidence-unmatched`.
|
|
178
|
+
*/
|
|
179
|
+
readonly evidence?: ReadonlyArray<Evidence> | undefined;
|
|
180
|
+
}
|
|
181
|
+
/** A transition that writes a path a law reads, and what shows it keeps the law (empty: nothing). */
|
|
182
|
+
export interface Breaker {
|
|
183
|
+
readonly transition: string;
|
|
184
|
+
/** The paths it writes that the law reads, in the law's space. */
|
|
185
|
+
readonly paths: ReadonlyArray<ReadonlyArray<string>>;
|
|
186
|
+
readonly evidence: ReadonlyArray<Evidence>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The laws of a Module's contracts as a graph, the rules over it, and its
|
|
190
|
+
* renderers. `Module` asks who owns what; `Graph` asks which transitions can
|
|
191
|
+
* break which laws and what shows they keep them. A page that imports only
|
|
192
|
+
* `Module` carries none of this.
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* Graph.validate(Shop, { evidence }) // law-unwitnessed, evidence-unmatched, …
|
|
196
|
+
* Graph.toMarkdown(Shop, { evidence }) // the Laws section
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare const Graph: {
|
|
200
|
+
/**
|
|
201
|
+
* The contracts' laws as a graph: what each contract's `laws` declare, a
|
|
202
|
+
* level and a `closure:<name>` law per closed Surface, which level refines
|
|
203
|
+
* which, and a `keeps` edge per record of `evidence` that is issued and
|
|
204
|
+
* joins its pair. Pure, and computed each time it is asked.
|
|
205
|
+
*/
|
|
206
|
+
of: (module: Module<any, any, any>, options?: GraphOptions) => Graph;
|
|
207
|
+
/**
|
|
208
|
+
* Each transition that writes a path `law` reads, which is each that could
|
|
209
|
+
* break it, and the evidence admitted that it keeps it. Throws for a law
|
|
210
|
+
* the graph does not hold, which a misspelt id would otherwise answer with
|
|
211
|
+
* nothing.
|
|
212
|
+
*/
|
|
213
|
+
breakersOf: (graph: Graph, law: string) => ReadonlyArray<Breaker>;
|
|
214
|
+
/**
|
|
215
|
+
* The rules over the graph, which `Module.validate` does not ask: each
|
|
216
|
+
* transition that writes what a law reads with no evidence it keeps it
|
|
217
|
+
* (`law-unwitnessed`), each record of `evidence` not admitted
|
|
218
|
+
* (`evidence-unmatched`), each write two contracts declare
|
|
219
|
+
* (`transition-declared-twice`), and each two closed Surfaces with one
|
|
220
|
+
* projection and one Message set (`level-declared-twice`). With no
|
|
221
|
+
* `evidence`, every pair a transition can break is unwitnessed.
|
|
222
|
+
*/
|
|
223
|
+
validate: (module: Module<any, any, any>, options?: GraphOptions) => readonly Finding[];
|
|
224
|
+
/**
|
|
225
|
+
* A Laws section in Markdown, to set beside `Module.toMarkdown`'s: each law
|
|
226
|
+
* by each transition that writes what it reads and its evidence, then
|
|
227
|
+
* `Graph.validate`'s findings.
|
|
228
|
+
*/
|
|
229
|
+
toMarkdown: (module: Module<any, any, any>, options?: GraphOptions) => string;
|
|
230
|
+
/**
|
|
231
|
+
* The laws as a Mermaid flowchart of their own: a node per law and per
|
|
232
|
+
* transition that writes what one reads, a solid edge from each shown
|
|
233
|
+
* keeping it, labelled with its kinds of evidence, and a dotted one from
|
|
234
|
+
* each with none.
|
|
235
|
+
*/
|
|
236
|
+
toMermaid: (module: Module<any, any, any>, options?: GraphOptions) => string;
|
|
237
|
+
};
|
|
238
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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hF,aAAU,QAAW,uBAAqB,UAAW;;;;;;;EA+BrD,YAAS,QAAW,uBAAqB,UAAW"}
|
package/dist/graph.js
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { Data, Option } from "effect";
|
|
2
|
+
import { lawFactsOf } from "foldkit-entity";
|
|
3
|
+
import { Evidence } from "foldkit-metadata";
|
|
4
|
+
import { labelOf, pathText, tableCell } from "./text.js";
|
|
5
|
+
// src/graph.ts
|
|
6
|
+
/**
|
|
7
|
+
* The law half of the contract graph (#537): which transitions write what
|
|
8
|
+
* which laws read, and what shows each keeps each. A contract declares its
|
|
9
|
+
* laws and transitions as plain data (`Contract.laws`), and `Graph` derives
|
|
10
|
+
* their nodes and edges here, when asked; a closed Surface contributes a
|
|
11
|
+
* level from its flag; tests contribute evidence. `Graph` is its own module
|
|
12
|
+
* so a page that reads `Module` alone carries none of it. `Graph.validate`
|
|
13
|
+
* asks the graph's one question: is every transition that can break a law
|
|
14
|
+
* witnessed keeping it?
|
|
15
|
+
*/
|
|
16
|
+
const GraphNode = /* @__PURE__ */ Data.taggedEnum();
|
|
17
|
+
const GraphEdge = /* @__PURE__ */ Data.taggedEnum();
|
|
18
|
+
const isPrefix = (prefix, path) => prefix.length <= path.length && prefix.every((segment, index) => segment === path[index]);
|
|
19
|
+
/** One path is within the other: writing `['todos']` writes `['todos', 'title']`, and the reverse. */
|
|
20
|
+
const overlaps = (a, b) => a.space === b.space && a.path.length > 0 && b.path.length > 0 && (isPrefix(a.path, b.path) || isPrefix(b.path, a.path));
|
|
21
|
+
const keyOf = (value) => JSON.stringify(value);
|
|
22
|
+
/** A contract's declared laws as nodes and edges. */
|
|
23
|
+
const factsOf = (contract, laws) => {
|
|
24
|
+
const model = (laws.model ?? []).map((id) => `${labelOf(contract)}.${id}`);
|
|
25
|
+
const durable = laws.model === void 0 ? [] : contract.messages.map((tag) => `durable:${tag}`);
|
|
26
|
+
const entities = lawFactsOf(laws.entities ?? []);
|
|
27
|
+
return {
|
|
28
|
+
nodes: [
|
|
29
|
+
...model.map((id) => GraphNode.Law({ id })),
|
|
30
|
+
...durable.map((id) => GraphNode.Transition({
|
|
31
|
+
id,
|
|
32
|
+
kind: "durable"
|
|
33
|
+
})),
|
|
34
|
+
...entities.nodes
|
|
35
|
+
],
|
|
36
|
+
edges: [
|
|
37
|
+
...model.flatMap((law) => contract.owns.map((path) => GraphEdge.Reads({
|
|
38
|
+
law,
|
|
39
|
+
space: "model",
|
|
40
|
+
path
|
|
41
|
+
}))),
|
|
42
|
+
...durable.flatMap((transition) => contract.owns.map((path) => GraphEdge.Writes({
|
|
43
|
+
transition,
|
|
44
|
+
space: "model",
|
|
45
|
+
path
|
|
46
|
+
}))),
|
|
47
|
+
...entities.edges
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** The contracts' declared laws, their closed Surfaces as levels, and the evidence that joins a pair. */
|
|
52
|
+
const assemble = (contracts, options) => {
|
|
53
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
54
|
+
const edges = /* @__PURE__ */ new Map();
|
|
55
|
+
const contributors = /* @__PURE__ */ new Map();
|
|
56
|
+
const reads = /* @__PURE__ */ new Map();
|
|
57
|
+
const writes = /* @__PURE__ */ new Map();
|
|
58
|
+
const levels = [];
|
|
59
|
+
const node = (made) => nodes.set(keyOf(made), made);
|
|
60
|
+
const contributed = (key, label) => {
|
|
61
|
+
const known = contributors.get(key) ?? [];
|
|
62
|
+
if (!known.includes(label)) contributors.set(key, [...known, label]);
|
|
63
|
+
};
|
|
64
|
+
const located = (into, id, at) => {
|
|
65
|
+
const known = into.get(id) ?? [];
|
|
66
|
+
if (!known.some((each) => each.space === at.space && keyOf(each.path) === keyOf(at.path))) into.set(id, [...known, at]);
|
|
67
|
+
node(GraphNode.Path({
|
|
68
|
+
space: at.space,
|
|
69
|
+
path: at.path
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
const edge = (made) => {
|
|
73
|
+
if (GraphEdge.$match(made, {
|
|
74
|
+
Owns: ({ path }) => {
|
|
75
|
+
node(GraphNode.Path({
|
|
76
|
+
space: "model",
|
|
77
|
+
path
|
|
78
|
+
}));
|
|
79
|
+
return true;
|
|
80
|
+
},
|
|
81
|
+
Reads: ({ law, space, path }) => {
|
|
82
|
+
located(reads, law, {
|
|
83
|
+
space,
|
|
84
|
+
path
|
|
85
|
+
});
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
Writes: ({ transition, space, path }) => {
|
|
89
|
+
located(writes, transition, {
|
|
90
|
+
space,
|
|
91
|
+
path
|
|
92
|
+
});
|
|
93
|
+
return true;
|
|
94
|
+
},
|
|
95
|
+
Observes: ({ path }) => {
|
|
96
|
+
node(GraphNode.Path({
|
|
97
|
+
space: "model",
|
|
98
|
+
path
|
|
99
|
+
}));
|
|
100
|
+
return true;
|
|
101
|
+
},
|
|
102
|
+
From: () => true,
|
|
103
|
+
To: () => true,
|
|
104
|
+
Keeps: () => false,
|
|
105
|
+
Refines: () => true
|
|
106
|
+
})) edges.set(keyOf(made), made);
|
|
107
|
+
};
|
|
108
|
+
for (const contract of new Set(contracts)) {
|
|
109
|
+
const label = labelOf(contract);
|
|
110
|
+
if (contract.owns.length > 0) {
|
|
111
|
+
node(GraphNode.Owner({
|
|
112
|
+
kind: contract.kind,
|
|
113
|
+
name: contract.name
|
|
114
|
+
}));
|
|
115
|
+
for (const path of contract.owns) edge(GraphEdge.Owns({
|
|
116
|
+
owner: label,
|
|
117
|
+
path
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
if (contract.closed === true) {
|
|
121
|
+
const law = `closure:${contract.name}`;
|
|
122
|
+
node(GraphNode.Level({ surface: contract.name }));
|
|
123
|
+
node(GraphNode.Law({ id: law }));
|
|
124
|
+
contributed(`law:${law}`, label);
|
|
125
|
+
levels.push(contract);
|
|
126
|
+
for (const path of contract.observes) {
|
|
127
|
+
edge(GraphEdge.Observes({
|
|
128
|
+
level: contract.name,
|
|
129
|
+
path
|
|
130
|
+
}));
|
|
131
|
+
edge(GraphEdge.Reads({
|
|
132
|
+
law,
|
|
133
|
+
space: "model",
|
|
134
|
+
path
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (contract.laws === void 0) continue;
|
|
139
|
+
const facts = factsOf(contract, contract.laws);
|
|
140
|
+
for (const made of facts.nodes) {
|
|
141
|
+
node(made);
|
|
142
|
+
const key = GraphNode.$match(made, {
|
|
143
|
+
Owner: () => Option.none(),
|
|
144
|
+
Path: () => Option.none(),
|
|
145
|
+
Transition: ({ id }) => Option.some(`transition:${id}`),
|
|
146
|
+
Law: ({ id }) => Option.some(`law:${id}`),
|
|
147
|
+
State: () => Option.none(),
|
|
148
|
+
Level: () => Option.none()
|
|
149
|
+
});
|
|
150
|
+
if (Option.isSome(key)) contributed(key.value, label);
|
|
151
|
+
}
|
|
152
|
+
for (const made of facts.edges) edge(made);
|
|
153
|
+
}
|
|
154
|
+
const covers = (wider, narrower) => narrower.observes.every((path) => wider.observes.some((own) => isPrefix(own, path)));
|
|
155
|
+
for (const a of levels) for (const b of levels) if (a !== b && covers(a, b) && !covers(b, a)) edge(GraphEdge.Refines({
|
|
156
|
+
level: a.name,
|
|
157
|
+
of: b.name
|
|
158
|
+
}));
|
|
159
|
+
const laws = new Set([...nodes.values()].filter(GraphNode.$is("Law")).map((law) => law.id));
|
|
160
|
+
const transitions = new Map([...nodes.values()].filter(GraphNode.$is("Transition")).map((transition) => [transition.id, transition.entity]));
|
|
161
|
+
const unmatched = [];
|
|
162
|
+
const kept = /* @__PURE__ */ new Set();
|
|
163
|
+
const admit = (record) => {
|
|
164
|
+
const { transition, law } = record;
|
|
165
|
+
const involved = [...contributors.get(`transition:${transition}`) ?? [], ...contributors.get(`law:${law}`) ?? []];
|
|
166
|
+
const refuse = (why) => {
|
|
167
|
+
unmatched.push({
|
|
168
|
+
record,
|
|
169
|
+
contracts: [...new Set(involved)],
|
|
170
|
+
message: `Evidence that ${transition} keeps ${law} ${why}`
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
if (Option.isNone(Evidence.issuedBy(record))) return refuse("was issued by no producer: it was typed by hand or copied");
|
|
174
|
+
if (!transitions.has(transition)) return refuse(`names ${transition}, which no contract declares`);
|
|
175
|
+
if (!laws.has(law)) return refuse(`names ${law}, which no contract declares`);
|
|
176
|
+
const written = writes.get(transition) ?? [];
|
|
177
|
+
const entity = transitions.get(transition);
|
|
178
|
+
const entities = /* @__PURE__ */ new Set([...written.flatMap((at) => at.space === "entity" ? [at.path[0]] : []), ...entity === void 0 ? [] : [entity]]);
|
|
179
|
+
const joins = (at) => at.space === "entity" ? entities.has(at.path[0]) : written.some((each) => overlaps(each, at));
|
|
180
|
+
if (!(reads.get(law) ?? []).some(joins)) return refuse(`names a pair the graph does not join: ${transition} writes nothing beside what ${law} reads`);
|
|
181
|
+
if (kept.has(record)) return;
|
|
182
|
+
kept.add(record);
|
|
183
|
+
edges.set(`keeps:${kept.size}`, GraphEdge.Keeps({
|
|
184
|
+
transition,
|
|
185
|
+
law,
|
|
186
|
+
evidence: record
|
|
187
|
+
}));
|
|
188
|
+
};
|
|
189
|
+
for (const record of options.evidence ?? []) admit(record);
|
|
190
|
+
return {
|
|
191
|
+
graph: {
|
|
192
|
+
nodes: [...nodes.values()],
|
|
193
|
+
edges: [...edges.values()]
|
|
194
|
+
},
|
|
195
|
+
contributors,
|
|
196
|
+
unmatched
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
/** The ids of the graph's laws, in the order contracts declared them. */
|
|
200
|
+
const lawsOf = (graph) => graph.nodes.filter(GraphNode.$is("Law")).map((law) => law.id);
|
|
201
|
+
const breakers = (graph, law) => {
|
|
202
|
+
const read = graph.edges.filter(GraphEdge.$is("Reads")).filter((edge) => edge.law === law).map(({ space, path }) => ({
|
|
203
|
+
space,
|
|
204
|
+
path
|
|
205
|
+
}));
|
|
206
|
+
const keeps = graph.edges.filter(GraphEdge.$is("Keeps")).filter((edge) => edge.law === law);
|
|
207
|
+
return graph.nodes.filter(GraphNode.$is("Transition")).flatMap(({ id }) => {
|
|
208
|
+
const paths = graph.edges.filter(GraphEdge.$is("Writes")).filter((edge) => edge.transition === id && read.some((at) => overlaps(at, edge))).map((edge) => edge.path);
|
|
209
|
+
if (paths.length === 0) return [];
|
|
210
|
+
return [{
|
|
211
|
+
transition: id,
|
|
212
|
+
paths,
|
|
213
|
+
evidence: keeps.filter((edge) => edge.transition === id).map((edge) => edge.evidence)
|
|
214
|
+
}];
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
const sameSet = (a, b) => a.length === b.length && a.every((each) => b.includes(each)) && b.every((each) => a.includes(each));
|
|
218
|
+
/** The rules over the graph, as `Graph.validate` documents them. */
|
|
219
|
+
const findingsOf = (contracts, { graph, contributors, unmatched }) => {
|
|
220
|
+
const involved = (transition, law) => [.../* @__PURE__ */ new Set([...contributors.get(`transition:${transition}`) ?? [], ...contributors.get(`law:${law}`) ?? []])];
|
|
221
|
+
const findings = lawsOf(graph).flatMap((law) => breakers(graph, law).filter((breaker) => breaker.evidence.length === 0).map(({ transition, paths }) => ({
|
|
222
|
+
rule: "law-unwitnessed",
|
|
223
|
+
contracts: involved(transition, law),
|
|
224
|
+
message: `${transition} writes ${paths.map(pathText).join(", ")}, which ${law} reads, and no evidence shows it keeps ${law}`
|
|
225
|
+
})));
|
|
226
|
+
for (const { contracts: named, message } of unmatched) findings.push({
|
|
227
|
+
rule: "evidence-unmatched",
|
|
228
|
+
contracts: named,
|
|
229
|
+
message
|
|
230
|
+
});
|
|
231
|
+
for (const { id, kind } of graph.nodes.filter(GraphNode.$is("Transition"))) if (kind === "write") {
|
|
232
|
+
const named = contributors.get(`transition:${id}`) ?? [];
|
|
233
|
+
if (named.length > 1) findings.push({
|
|
234
|
+
rule: "transition-declared-twice",
|
|
235
|
+
contracts: named,
|
|
236
|
+
message: `${id} is declared by ${named.join(" and ")}, so evidence naming it cannot say which`
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const closed = [...new Set(contracts)].filter((contract) => contract.closed === true);
|
|
240
|
+
for (let i = 0; i < closed.length; i += 1) for (let j = i + 1; j < closed.length; j += 1) {
|
|
241
|
+
const [a, b] = [closed[i], closed[j]];
|
|
242
|
+
if (sameSet(a.observes.map(pathText), b.observes.map(pathText)) && sameSet(a.messages, b.messages)) findings.push({
|
|
243
|
+
rule: "level-declared-twice",
|
|
244
|
+
contracts: [labelOf(a), labelOf(b)],
|
|
245
|
+
message: `${labelOf(a)} and ${labelOf(b)} are closed over the same paths and the same Messages`
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return findings;
|
|
249
|
+
};
|
|
250
|
+
/** One line of a record, for the renderers. */
|
|
251
|
+
const evidenceText = (record) => Evidence.$match(record, {
|
|
252
|
+
Enumerated: () => "enumerated",
|
|
253
|
+
Walked: ({ seeds, steps, starts }) => `walked: ${seeds} seeds of ${steps} steps from ${starts.join(", ")}`,
|
|
254
|
+
Scenario: ({ name, runner }) => `scenario on ${runner}: ${name}`,
|
|
255
|
+
RuntimeOnly: ({ why }) => `runtime only: ${why}`
|
|
256
|
+
});
|
|
257
|
+
/**
|
|
258
|
+
* The laws of a Module's contracts as a graph, the rules over it, and its
|
|
259
|
+
* renderers. `Module` asks who owns what; `Graph` asks which transitions can
|
|
260
|
+
* break which laws and what shows they keep them. A page that imports only
|
|
261
|
+
* `Module` carries none of this.
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* Graph.validate(Shop, { evidence }) // law-unwitnessed, evidence-unmatched, …
|
|
265
|
+
* Graph.toMarkdown(Shop, { evidence }) // the Laws section
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
const Graph = {
|
|
269
|
+
/**
|
|
270
|
+
* The contracts' laws as a graph: what each contract's `laws` declare, a
|
|
271
|
+
* level and a `closure:<name>` law per closed Surface, which level refines
|
|
272
|
+
* which, and a `keeps` edge per record of `evidence` that is issued and
|
|
273
|
+
* joins its pair. Pure, and computed each time it is asked.
|
|
274
|
+
*/
|
|
275
|
+
of: (module, options = {}) => assemble(module.contracts, options).graph,
|
|
276
|
+
/**
|
|
277
|
+
* Each transition that writes a path `law` reads, which is each that could
|
|
278
|
+
* break it, and the evidence admitted that it keeps it. Throws for a law
|
|
279
|
+
* the graph does not hold, which a misspelt id would otherwise answer with
|
|
280
|
+
* nothing.
|
|
281
|
+
*/
|
|
282
|
+
breakersOf: (graph, law) => {
|
|
283
|
+
if (!lawsOf(graph).includes(law)) throw new Error(`Graph.breakersOf: the graph holds no law ${law}`);
|
|
284
|
+
return breakers(graph, law);
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* The rules over the graph, which `Module.validate` does not ask: each
|
|
288
|
+
* transition that writes what a law reads with no evidence it keeps it
|
|
289
|
+
* (`law-unwitnessed`), each record of `evidence` not admitted
|
|
290
|
+
* (`evidence-unmatched`), each write two contracts declare
|
|
291
|
+
* (`transition-declared-twice`), and each two closed Surfaces with one
|
|
292
|
+
* projection and one Message set (`level-declared-twice`). With no
|
|
293
|
+
* `evidence`, every pair a transition can break is unwitnessed.
|
|
294
|
+
*/
|
|
295
|
+
validate: (module, options = {}) => findingsOf(module.contracts, assemble(module.contracts, options)),
|
|
296
|
+
/**
|
|
297
|
+
* A Laws section in Markdown, to set beside `Module.toMarkdown`'s: each law
|
|
298
|
+
* by each transition that writes what it reads and its evidence, then
|
|
299
|
+
* `Graph.validate`'s findings.
|
|
300
|
+
*/
|
|
301
|
+
toMarkdown: (module, options = {}) => {
|
|
302
|
+
const assembled = assemble(module.contracts, options);
|
|
303
|
+
const { graph } = assembled;
|
|
304
|
+
const laws = lawsOf(graph);
|
|
305
|
+
const lines = ["## Laws", ""];
|
|
306
|
+
if (laws.length === 0) lines.push("No contract declares a law.");
|
|
307
|
+
else {
|
|
308
|
+
lines.push("| Law | Transition | Evidence |", "| --- | --- | --- |");
|
|
309
|
+
for (const law of laws) {
|
|
310
|
+
const found = breakers(graph, law);
|
|
311
|
+
if (found.length === 0) lines.push(`| ${tableCell(law)} | | nothing writes what it reads |`);
|
|
312
|
+
for (const { transition, evidence } of found) lines.push(`| ${tableCell(law)} | ${tableCell(transition)} | ${evidence.length === 0 ? "**none**" : tableCell(evidence.map(evidenceText).join("; "))} |`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const findings = findingsOf(module.contracts, assembled);
|
|
316
|
+
if (findings.length > 0) {
|
|
317
|
+
lines.push("", "### Findings", "");
|
|
318
|
+
for (const finding of findings) lines.push(`- **${finding.rule}** ${finding.message}`);
|
|
319
|
+
}
|
|
320
|
+
return lines.join("\n");
|
|
321
|
+
},
|
|
322
|
+
/**
|
|
323
|
+
* The laws as a Mermaid flowchart of their own: a node per law and per
|
|
324
|
+
* transition that writes what one reads, a solid edge from each shown
|
|
325
|
+
* keeping it, labelled with its kinds of evidence, and a dotted one from
|
|
326
|
+
* each with none.
|
|
327
|
+
*/
|
|
328
|
+
toMermaid: (module, options = {}) => {
|
|
329
|
+
const graph = Graph.of(module, options);
|
|
330
|
+
const laws = lawsOf(graph);
|
|
331
|
+
const lines = ["flowchart LR", ...laws.map((law, index) => ` l${index}["${law}"]`)];
|
|
332
|
+
const transitions = [];
|
|
333
|
+
const transitionId = (id) => {
|
|
334
|
+
if (!transitions.includes(id)) {
|
|
335
|
+
transitions.push(id);
|
|
336
|
+
lines.push(` t${transitions.length - 1}["${id}"]`);
|
|
337
|
+
}
|
|
338
|
+
return `t${transitions.indexOf(id)}`;
|
|
339
|
+
};
|
|
340
|
+
const arrows = laws.flatMap((law, index) => breakers(graph, law).map(({ transition, evidence }) => {
|
|
341
|
+
const from = transitionId(transition);
|
|
342
|
+
return evidence.length === 0 ? ` ${from} -.->|unwitnessed| l${index}` : ` ${from} -->|${[...new Set(evidence.map((record) => record._tag))].join(", ")}| l${index}`;
|
|
343
|
+
}));
|
|
344
|
+
lines.push(...arrows);
|
|
345
|
+
return lines.join("\n");
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
export { Graph, GraphEdge, GraphNode };
|
|
349
|
+
|
|
350
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","names":[],"sources":["../src/graph.ts"],"sourcesContent":["/**\n * The law half of the contract graph (#537): which transitions write what\n * which laws read, and what shows each keeps each. A contract declares its\n * laws and transitions as plain data (`Contract.laws`), and `Graph` derives\n * their nodes and edges here, when asked; a closed Surface contributes a\n * level from its flag; tests contribute evidence. `Graph` is its own module\n * so a page that reads `Module` alone carries none of it. `Graph.validate`\n * asks the graph's one question: is every transition that can break a law\n * witnessed keeping it?\n */\nimport { Data, Option } from 'effect'\nimport { lawFactsOf, type LawEntry } from 'foldkit-entity'\nimport { Evidence } from 'foldkit-metadata'\nimport type { Contract, Finding, Module } from './index.js'\nimport { labelOf, pathText, tableCell } from './text.js'\n\n/** Where a path is: a Model field (`['todos']`) or an Entity member (`['Product', 'stock']`). */\nexport type GraphSpace = 'model' | 'entity'\n\nexport type GraphNode = Data.TaggedEnum<{\n /** A contract that owns Model paths: `remote:Shop`, `sync:todos-capped`. */\n Owner: { readonly kind: string; readonly name: string }\n Path: { readonly space: GraphSpace; readonly path: ReadonlyArray<string> }\n /**\n * A declared write (`write:Sell`), with the Entity whose rows it writes, or\n * a durable Message (`durable:CreatedTodo`), with none.\n */\n Transition: {\n readonly id: string\n readonly kind: 'write' | 'durable'\n readonly entity?: string | undefined\n }\n /** An Entity's invariant (`Product.reservedWithinStock`), a document's law, or a closed Surface's closure. */\n Law: { readonly id: string }\n /** A declared state of an Entity. */\n State: { readonly entity: string; readonly name: string }\n /** A Surface declared `closed: true`. */\n Level: { readonly surface: string }\n}>\nexport const GraphNode = /* @__PURE__ */ Data.taggedEnum<GraphNode>()\n\nexport type GraphEdge = Data.TaggedEnum<{\n /** `owner` (`kind:name`) is the authority for a Model path. */\n Owns: { readonly owner: string; readonly path: ReadonlyArray<string> }\n Reads: { readonly law: string; readonly space: GraphSpace; readonly path: ReadonlyArray<string> }\n Writes: {\n readonly transition: string\n readonly space: GraphSpace\n readonly path: ReadonlyArray<string>\n }\n /** A closed Surface's projection reads a Model path. */\n Observes: { readonly level: string; readonly path: ReadonlyArray<string> }\n /** The write starts only from this state. */\n From: { readonly transition: string; readonly entity: string; readonly state: string }\n /** The write leaves its row in this state. */\n To: { readonly transition: string; readonly entity: string; readonly state: string }\n /** The transition keeps the law, and the record that shows it. */\n Keeps: { readonly transition: string; readonly law: string; readonly evidence: Evidence }\n /** `level`'s projection contains every path of `of`'s, and more. */\n Refines: { readonly level: string; readonly of: string }\n}>\nexport const GraphEdge = /* @__PURE__ */ Data.taggedEnum<GraphEdge>()\n\n/** Nodes and edges, as `Graph.of` returns them. */\nexport interface GraphFacts {\n readonly nodes: ReadonlyArray<GraphNode>\n readonly edges: ReadonlyArray<GraphEdge>\n}\n\n/** What a contract declares of its laws, read by `Graph.of` when asked. */\nexport interface ContractLaws {\n /**\n * Laws over the contract's Model slice, by id, as a Sync document declares\n * them: each is `<kind>:<name>.<id>`, taken to read every path the contract\n * owns (a law is a function, so the whole slice), and each of the\n * contract's Messages is a transition `durable:<tag>` writing it. Given,\n * even empty, the transitions are drawn.\n */\n readonly model?: ReadonlyArray<string> | undefined\n /**\n * Transitions over Entities, as `Laws.check` takes them: a declared write\n * (`{ name, write }`, as `Mutation.write` returns), or one known by its\n * footprint. Each is `write:<name>`, beside each invariant of its Entity.\n */\n readonly entities?: ReadonlyArray<LawEntry> | undefined\n}\n\n/** An application's graph: every contract's facts, its closed Surfaces, and the evidence admitted. */\nexport interface Graph extends GraphFacts {}\n\n/** What `Graph` reads beside the contracts. */\nexport interface GraphOptions {\n /**\n * Records that a transition keeps a law: what a test's walks and scenarios\n * returned, `Laws.check`'s `Enumerated` records, and `Evidence.runtimeOnly`\n * lines. One issued by no producer, or naming a pair the graph does not\n * join, is not admitted and is reported as `evidence-unmatched`.\n */\n readonly evidence?: ReadonlyArray<Evidence> | undefined\n}\n\n/** A transition that writes a path a law reads, and what shows it keeps the law (empty: nothing). */\nexport interface Breaker {\n readonly transition: string\n /** The paths it writes that the law reads, in the law's space. */\n readonly paths: ReadonlyArray<ReadonlyArray<string>>\n readonly evidence: ReadonlyArray<Evidence>\n}\n\ninterface Located {\n readonly space: GraphSpace\n readonly path: ReadonlyArray<string>\n}\n\n/** A record not admitted, and why, for `evidence-unmatched`. */\ninterface Unmatched {\n readonly record: Evidence\n readonly contracts: ReadonlyArray<string>\n readonly message: string\n}\n\n/** The graph, with who contributed each law and transition and what evidence was turned away. */\ninterface Assembled {\n readonly graph: Graph\n readonly contributors: ReadonlyMap<string, ReadonlyArray<string>>\n readonly unmatched: ReadonlyArray<Unmatched>\n}\n\nconst isPrefix = (prefix: ReadonlyArray<string>, path: ReadonlyArray<string>): boolean =>\n prefix.length <= path.length && prefix.every((segment, index) => segment === path[index])\n\n/** One path is within the other: writing `['todos']` writes `['todos', 'title']`, and the reverse. */\nconst overlaps = (a: Located, b: Located): boolean =>\n a.space === b.space &&\n a.path.length > 0 &&\n b.path.length > 0 &&\n (isPrefix(a.path, b.path) || isPrefix(b.path, a.path))\n\nconst keyOf = (value: unknown): string => JSON.stringify(value)\n\n/** A contract's declared laws as nodes and edges. */\nconst factsOf = (contract: Contract, laws: ContractLaws): GraphFacts => {\n const model = (laws.model ?? []).map(id => `${labelOf(contract)}.${id}`)\n const durable = laws.model === undefined ? [] : contract.messages.map(tag => `durable:${tag}`)\n // An Entity's laws come out shaped as the graph's own nodes and edges.\n const entities: GraphFacts = lawFactsOf(laws.entities ?? [])\n return {\n nodes: [\n ...model.map(id => GraphNode.Law({ id })),\n ...durable.map(id => GraphNode.Transition({ id, kind: 'durable' })),\n ...entities.nodes,\n ],\n edges: [\n ...model.flatMap(law =>\n contract.owns.map(path => GraphEdge.Reads({ law, space: 'model', path })),\n ),\n ...durable.flatMap(transition =>\n contract.owns.map(path => GraphEdge.Writes({ transition, space: 'model', path })),\n ),\n ...entities.edges,\n ],\n }\n}\n\n/** The contracts' declared laws, their closed Surfaces as levels, and the evidence that joins a pair. */\nconst assemble = (contracts: ReadonlyArray<Contract>, options: GraphOptions): Assembled => {\n const nodes = new Map<string, GraphNode>()\n const edges = new Map<string, GraphEdge>()\n const contributors = new Map<string, Array<string>>()\n const reads = new Map<string, Array<Located>>()\n const writes = new Map<string, Array<Located>>()\n const levels: Array<Contract> = []\n\n const node = (made: GraphNode) => nodes.set(keyOf(made), made)\n const contributed = (key: string, label: string) => {\n const known = contributors.get(key) ?? []\n if (!known.includes(label)) contributors.set(key, [...known, label])\n }\n const located = (into: Map<string, Array<Located>>, id: string, at: Located) => {\n const known = into.get(id) ?? []\n if (!known.some(each => each.space === at.space && keyOf(each.path) === keyOf(at.path)))\n into.set(id, [...known, at])\n node(GraphNode.Path({ space: at.space, path: at.path }))\n }\n const edge = (made: GraphEdge) => {\n const kept = GraphEdge.$match(made, {\n Owns: ({ path }) => {\n node(GraphNode.Path({ space: 'model', path }))\n return true\n },\n Reads: ({ law, space, path }) => {\n located(reads, law, { space, path })\n return true\n },\n Writes: ({ transition, space, path }) => {\n located(writes, transition, { space, path })\n return true\n },\n Observes: ({ path }) => {\n node(GraphNode.Path({ space: 'model', path }))\n return true\n },\n From: () => true,\n To: () => true,\n // Only admitted evidence is a keeps edge, made below.\n Keeps: () => false,\n Refines: () => true,\n })\n if (kept) edges.set(keyOf(made), made)\n }\n\n for (const contract of new Set(contracts)) {\n const label = labelOf(contract)\n if (contract.owns.length > 0) {\n node(GraphNode.Owner({ kind: contract.kind, name: contract.name }))\n for (const path of contract.owns) edge(GraphEdge.Owns({ owner: label, path }))\n }\n if (contract.closed === true) {\n const law = `closure:${contract.name}`\n node(GraphNode.Level({ surface: contract.name }))\n node(GraphNode.Law({ id: law }))\n contributed(`law:${law}`, label)\n levels.push(contract)\n for (const path of contract.observes) {\n edge(GraphEdge.Observes({ level: contract.name, path }))\n edge(GraphEdge.Reads({ law, space: 'model', path }))\n }\n }\n if (contract.laws === undefined) continue\n const facts = factsOf(contract, contract.laws)\n for (const made of facts.nodes) {\n node(made)\n const key = GraphNode.$match(made, {\n Owner: () => Option.none<string>(),\n Path: () => Option.none<string>(),\n Transition: ({ id }) => Option.some(`transition:${id}`),\n Law: ({ id }) => Option.some(`law:${id}`),\n State: () => Option.none<string>(),\n Level: () => Option.none<string>(),\n })\n if (Option.isSome(key)) contributed(key.value, label)\n }\n for (const made of facts.edges) edge(made)\n }\n\n // A level refines another when its paths cover every one of the other's and the reverse fails.\n const covers = (wider: Contract, narrower: Contract) =>\n narrower.observes.every(path => wider.observes.some(own => isPrefix(own, path)))\n for (const a of levels)\n for (const b of levels)\n if (a !== b && covers(a, b) && !covers(b, a))\n edge(GraphEdge.Refines({ level: a.name, of: b.name }))\n\n const laws = new Set([...nodes.values()].filter(GraphNode.$is('Law')).map(law => law.id))\n const transitions = new Map(\n [...nodes.values()]\n .filter(GraphNode.$is('Transition'))\n .map(transition => [transition.id, transition.entity] as const),\n )\n const unmatched: Array<Unmatched> = []\n const kept = new Set<Evidence>()\n const admit = (record: Evidence) => {\n const { transition, law } = record\n const involved = [\n ...(contributors.get(`transition:${transition}`) ?? []),\n ...(contributors.get(`law:${law}`) ?? []),\n ]\n const refuse = (why: string): void => {\n unmatched.push({\n record,\n contracts: [...new Set(involved)],\n message: `Evidence that ${transition} keeps ${law} ${why}`,\n })\n }\n if (Option.isNone(Evidence.issuedBy(record)))\n return refuse('was issued by no producer: it was typed by hand or copied')\n if (!transitions.has(transition))\n return refuse(`names ${transition}, which no contract declares`)\n if (!laws.has(law)) return refuse(`names ${law}, which no contract declares`)\n // What a record's pair must share. Over an Entity, the Entity: a pair within one is joined\n // even when it shares no member, as `Laws.check` records one kept by disjointness, and a\n // transition's own Entity counts where it writes no member (a delete). Over the Model, a\n // path: Model laws read their owner's slice, so a slice is what tells two owners apart.\n const written = writes.get(transition) ?? []\n const entity = transitions.get(transition)\n const entities = new Set([\n ...written.flatMap(at => (at.space === 'entity' ? [at.path[0]] : [])),\n ...(entity === undefined ? [] : [entity]),\n ])\n const joins = (at: Located) =>\n at.space === 'entity' ? entities.has(at.path[0]) : written.some(each => overlaps(each, at))\n if (!(reads.get(law) ?? []).some(joins))\n return refuse(\n `names a pair the graph does not join: ${transition} writes nothing beside what ${law} reads`,\n )\n if (kept.has(record)) return\n kept.add(record)\n // Every admitted record is an edge of its own: a walk and a scenario of one pair are two.\n edges.set(`keeps:${kept.size}`, GraphEdge.Keeps({ transition, law, evidence: record }))\n }\n for (const record of options.evidence ?? []) admit(record)\n\n return {\n graph: { nodes: [...nodes.values()], edges: [...edges.values()] },\n contributors,\n unmatched,\n }\n}\n\n/** The ids of the graph's laws, in the order contracts declared them. */\nconst lawsOf = (graph: Graph): ReadonlyArray<string> =>\n graph.nodes.filter(GraphNode.$is('Law')).map(law => law.id)\n\nconst breakers = (graph: Graph, law: string): ReadonlyArray<Breaker> => {\n const read = graph.edges\n .filter(GraphEdge.$is('Reads'))\n .filter(edge => edge.law === law)\n .map(({ space, path }) => ({ space, path }))\n const keeps = graph.edges.filter(GraphEdge.$is('Keeps')).filter(edge => edge.law === law)\n return graph.nodes.filter(GraphNode.$is('Transition')).flatMap(({ id }) => {\n const paths = graph.edges\n .filter(GraphEdge.$is('Writes'))\n .filter(edge => edge.transition === id && read.some(at => overlaps(at, edge)))\n .map(edge => edge.path)\n if (paths.length === 0) return []\n const evidence = keeps.filter(edge => edge.transition === id).map(edge => edge.evidence)\n return [{ transition: id, paths, evidence }]\n })\n}\n\nconst sameSet = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): boolean =>\n a.length === b.length && a.every(each => b.includes(each)) && b.every(each => a.includes(each))\n\n/** The rules over the graph, as `Graph.validate` documents them. */\nconst findingsOf = (\n contracts: ReadonlyArray<Contract>,\n { graph, contributors, unmatched }: Assembled,\n): readonly Finding[] => {\n const involved = (transition: string, law: string) => [\n ...new Set([\n ...(contributors.get(`transition:${transition}`) ?? []),\n ...(contributors.get(`law:${law}`) ?? []),\n ]),\n ]\n const findings: Array<Finding> = lawsOf(graph).flatMap(law =>\n breakers(graph, law)\n .filter(breaker => breaker.evidence.length === 0)\n .map(({ transition, paths }) => ({\n rule: 'law-unwitnessed' as const,\n contracts: involved(transition, law),\n message: `${transition} writes ${paths.map(pathText).join(', ')}, which ${law} reads, and no evidence shows it keeps ${law}`,\n })),\n )\n for (const { contracts: named, message } of unmatched)\n findings.push({ rule: 'evidence-unmatched', contracts: named, message })\n // A write is named by its name alone, in the graph and in evidence, so two contracts'\n // writes of one name are one node no record can tell apart.\n for (const { id, kind } of graph.nodes.filter(GraphNode.$is('Transition')))\n if (kind === 'write') {\n const named = contributors.get(`transition:${id}`) ?? []\n if (named.length > 1)\n findings.push({\n rule: 'transition-declared-twice',\n contracts: named,\n message: `${id} is declared by ${named.join(' and ')}, so evidence naming it cannot say which`,\n })\n }\n const closed = [...new Set(contracts)].filter(contract => contract.closed === true)\n for (let i = 0; i < closed.length; i += 1)\n for (let j = i + 1; j < closed.length; j += 1) {\n const [a, b] = [closed[i]!, closed[j]!]\n if (\n sameSet(a.observes.map(pathText), b.observes.map(pathText)) &&\n sameSet(a.messages, b.messages)\n )\n findings.push({\n rule: 'level-declared-twice',\n contracts: [labelOf(a), labelOf(b)],\n message: `${labelOf(a)} and ${labelOf(b)} are closed over the same paths and the same Messages`,\n })\n }\n return findings\n}\n\n/** One line of a record, for the renderers. */\nconst evidenceText = (record: Evidence): string =>\n Evidence.$match(record, {\n Enumerated: () => 'enumerated',\n Walked: ({ seeds, steps, starts }) =>\n `walked: ${seeds} seeds of ${steps} steps from ${starts.join(', ')}`,\n Scenario: ({ name, runner }) => `scenario on ${runner}: ${name}`,\n RuntimeOnly: ({ why }) => `runtime only: ${why}`,\n })\n\n/**\n * The laws of a Module's contracts as a graph, the rules over it, and its\n * renderers. `Module` asks who owns what; `Graph` asks which transitions can\n * break which laws and what shows they keep them. A page that imports only\n * `Module` carries none of this.\n *\n * ```ts\n * Graph.validate(Shop, { evidence }) // law-unwitnessed, evidence-unmatched, …\n * Graph.toMarkdown(Shop, { evidence }) // the Laws section\n * ```\n */\nexport const Graph = {\n /**\n * The contracts' laws as a graph: what each contract's `laws` declare, a\n * level and a `closure:<name>` law per closed Surface, which level refines\n * which, and a `keeps` edge per record of `evidence` that is issued and\n * joins its pair. Pure, and computed each time it is asked.\n */\n of: (module: Module<any, any, any>, options: GraphOptions = {}): Graph =>\n assemble(module.contracts, options).graph,\n\n /**\n * Each transition that writes a path `law` reads, which is each that could\n * break it, and the evidence admitted that it keeps it. Throws for a law\n * the graph does not hold, which a misspelt id would otherwise answer with\n * nothing.\n */\n breakersOf: (graph: Graph, law: string): ReadonlyArray<Breaker> => {\n if (!lawsOf(graph).includes(law))\n throw new Error(`Graph.breakersOf: the graph holds no law ${law}`)\n return breakers(graph, law)\n },\n\n /**\n * The rules over the graph, which `Module.validate` does not ask: each\n * transition that writes what a law reads with no evidence it keeps it\n * (`law-unwitnessed`), each record of `evidence` not admitted\n * (`evidence-unmatched`), each write two contracts declare\n * (`transition-declared-twice`), and each two closed Surfaces with one\n * projection and one Message set (`level-declared-twice`). With no\n * `evidence`, every pair a transition can break is unwitnessed.\n */\n validate: (module: Module<any, any, any>, options: GraphOptions = {}): readonly Finding[] =>\n findingsOf(module.contracts, assemble(module.contracts, options)),\n\n /**\n * A Laws section in Markdown, to set beside `Module.toMarkdown`'s: each law\n * by each transition that writes what it reads and its evidence, then\n * `Graph.validate`'s findings.\n */\n toMarkdown: (module: Module<any, any, any>, options: GraphOptions = {}): string => {\n const assembled = assemble(module.contracts, options)\n const { graph } = assembled\n const laws = lawsOf(graph)\n const lines = ['## Laws', '']\n if (laws.length === 0) lines.push('No contract declares a law.')\n else {\n lines.push('| Law | Transition | Evidence |', '| --- | --- | --- |')\n for (const law of laws) {\n const found = breakers(graph, law)\n if (found.length === 0) lines.push(`| ${tableCell(law)} | | nothing writes what it reads |`)\n for (const { transition, evidence } of found)\n lines.push(\n `| ${tableCell(law)} | ${tableCell(transition)} | ${evidence.length === 0 ? '**none**' : tableCell(evidence.map(evidenceText).join('; '))} |`,\n )\n }\n }\n const findings = findingsOf(module.contracts, assembled)\n if (findings.length > 0) {\n lines.push('', '### Findings', '')\n for (const finding of findings) lines.push(`- **${finding.rule}** ${finding.message}`)\n }\n return lines.join('\\n')\n },\n\n /**\n * The laws as a Mermaid flowchart of their own: a node per law and per\n * transition that writes what one reads, a solid edge from each shown\n * keeping it, labelled with its kinds of evidence, and a dotted one from\n * each with none.\n */\n toMermaid: (module: Module<any, any, any>, options: GraphOptions = {}): string => {\n const graph = Graph.of(module, options)\n const laws = lawsOf(graph)\n const lines = ['flowchart LR', ...laws.map((law, index) => ` l${index}[\"${law}\"]`)]\n const transitions: string[] = []\n const transitionId = (id: string): string => {\n if (!transitions.includes(id)) {\n transitions.push(id)\n lines.push(` t${transitions.length - 1}[\"${id}\"]`)\n }\n return `t${transitions.indexOf(id)}`\n }\n const arrows = laws.flatMap((law, index) =>\n breakers(graph, law).map(({ transition, evidence }) => {\n const from = transitionId(transition)\n return evidence.length === 0\n ? ` ${from} -.->|unwitnessed| l${index}`\n : ` ${from} -->|${[...new Set(evidence.map(record => record._tag))].join(', ')}| l${index}`\n }),\n )\n lines.push(...arrows)\n return lines.join('\\n')\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,MAAa,YAA4B,qBAAK,WAAsB;AAsBpE,MAAa,YAA4B,qBAAK,WAAsB;AAmEpE,MAAM,YAAY,QAA+B,SAC/C,OAAO,UAAU,KAAK,UAAU,OAAO,OAAO,SAAS,UAAU,YAAY,KAAK,MAAM;;AAG1F,MAAM,YAAY,GAAY,MAC5B,EAAE,UAAU,EAAE,SACd,EAAE,KAAK,SAAS,KAChB,EAAE,KAAK,SAAS,MACf,SAAS,EAAE,MAAM,EAAE,IAAI,KAAK,SAAS,EAAE,MAAM,EAAE,IAAI;AAEtD,MAAM,SAAS,UAA2B,KAAK,UAAU,KAAK;;AAG9D,MAAM,W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