deltafold 0.0.0 → 0.0.1
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 +274 -4
- package/dist/changelog.d.ts +116 -0
- package/dist/changelog.d.ts.map +1 -0
- package/dist/changelog.js +304 -0
- package/dist/changelog.js.map +1 -0
- package/dist/document-BZcZo9nr.js +171 -0
- package/dist/document-BZcZo9nr.js.map +1 -0
- package/dist/document-DWHsgywm.d.ts +257 -0
- package/dist/document-DWHsgywm.d.ts.map +1 -0
- package/dist/html.d.ts +8 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +13 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +378 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2058 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.d.ts +8 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +16 -0
- package/dist/markdown.js.map +1 -0
- package/dist/mdast-DiRsYwPU.js +108 -0
- package/dist/mdast-DiRsYwPU.js.map +1 -0
- package/dist/package-BfBYnaCz.d.ts +1125 -0
- package/dist/package-BfBYnaCz.d.ts.map +1 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/package.json +13 -1
- package/src/features/documents/changelog.ts +450 -0
- package/src/features/documents/document.ts +357 -0
- package/src/features/documents/index.ts +4 -0
- package/src/features/documents/public-document.ts +31 -0
- package/src/features/documents/sections.ts +44 -0
- package/src/features/execution/executor.ts +826 -0
- package/src/features/execution/handler.ts +257 -0
- package/src/features/execution/settlement.ts +49 -0
- package/src/features/package.ts +32 -0
- package/src/features/planning/guide.ts +56 -0
- package/src/features/planning/history.ts +174 -0
- package/src/features/planning/identifiers.ts +43 -0
- package/src/features/planning/resolve-error.ts +201 -0
- package/src/features/planning/resolve.ts +724 -0
- package/src/features/planning/rewrite.ts +331 -0
- package/src/features/planning/validate.ts +388 -0
- package/src/foundation/action.ts +188 -0
- package/src/foundation/change.ts +147 -0
- package/src/foundation/instruction.ts +110 -0
- package/src/foundation/migration.ts +236 -0
- package/src/foundation/plan.ts +245 -0
- package/src/foundation/rule.ts +74 -0
- package/src/foundation/shortcut.ts +79 -0
- package/src/foundation/template.ts +28 -0
- package/src/foundation/version.ts +78 -0
- package/src/index.ts +22 -11
- package/src/renderers/html.ts +12 -0
- package/src/renderers/markdown.ts +12 -0
- package/src/renderers/mdast.ts +120 -0
- package/src/types.ts +2 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { Array as Arr, Equal, Graph, Option, Order } from "effect";
|
|
2
|
+
|
|
3
|
+
import type * as Action from "../../foundation/action.ts";
|
|
4
|
+
import type * as Change from "../../foundation/change.ts";
|
|
5
|
+
import type * as Migration from "../../foundation/migration.ts";
|
|
6
|
+
import type * as Rule from "../../foundation/rule.ts";
|
|
7
|
+
import type * as Shortcut from "../../foundation/shortcut.ts";
|
|
8
|
+
import type { Version } from "../../foundation/version.ts";
|
|
9
|
+
import { stepKey } from "./rewrite.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A problem in a history's declarations.
|
|
13
|
+
*
|
|
14
|
+
* @since @next
|
|
15
|
+
*/
|
|
16
|
+
export type Issue = {
|
|
17
|
+
readonly _tag:
|
|
18
|
+
| "DuplicateVersion"
|
|
19
|
+
| "UnregisteredVersion"
|
|
20
|
+
| "AncestryCycle"
|
|
21
|
+
| "ConflictingChange"
|
|
22
|
+
| "ConflictingAction"
|
|
23
|
+
| "DuplicateMigration"
|
|
24
|
+
| "DuplicateEdge"
|
|
25
|
+
| "SelfMigration"
|
|
26
|
+
| "EmptyMigration"
|
|
27
|
+
| "DuplicateOccurrence"
|
|
28
|
+
| "DuplicateRule"
|
|
29
|
+
| "InvalidRule"
|
|
30
|
+
| "DuplicateShortcut"
|
|
31
|
+
| "InvalidShortcut";
|
|
32
|
+
/** The identifier of the declaration the issue is about. */
|
|
33
|
+
readonly subject: string;
|
|
34
|
+
readonly message: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type Declarations = {
|
|
38
|
+
readonly versions: ReadonlyArray<Version>;
|
|
39
|
+
readonly migrations: ReadonlyArray<Migration.Any>;
|
|
40
|
+
readonly rules: ReadonlyArray<Rule.Any>;
|
|
41
|
+
readonly shortcuts: ReadonlyArray<Shortcut.Any>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const issueOrder = Order.combine(
|
|
45
|
+
Order.combine(
|
|
46
|
+
Order.mapInput(Order.String, (issue: Issue) => issue._tag),
|
|
47
|
+
Order.mapInput(Order.String, (issue: Issue) => issue.subject),
|
|
48
|
+
),
|
|
49
|
+
Order.mapInput(Order.String, (issue: Issue) => issue.message),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/** Action instances declared by steps, in declaration order. */
|
|
53
|
+
export const actionsOfSteps = (steps: ReadonlyArray<Action.Step>): ReadonlyArray<Action.Any> =>
|
|
54
|
+
steps.flatMap((step): ReadonlyArray<Action.Any> => {
|
|
55
|
+
switch (step._tag) {
|
|
56
|
+
case "Action":
|
|
57
|
+
return [step];
|
|
58
|
+
case "Instruction":
|
|
59
|
+
return [step.action];
|
|
60
|
+
case "Sequence":
|
|
61
|
+
return actionsOfSteps(step.children);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return actionsOfSteps(step.branches);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const stepsOf = (content: Migration.Content): ReadonlyArray<Action.Step> =>
|
|
68
|
+
content.flatMap((fragment) =>
|
|
69
|
+
fragment._tag === "Text" || fragment._tag === "ActionRef" ? [] : [fragment],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
/** Whether two definitions with the same identifier describe the same change. */
|
|
73
|
+
const sameDefinition = (self: Change.Any, that: Change.Any): boolean =>
|
|
74
|
+
self === that ||
|
|
75
|
+
(self.id === that.id &&
|
|
76
|
+
Equal.equals(self.metadata, that.metadata) &&
|
|
77
|
+
self.description === that.description &&
|
|
78
|
+
self.backportOf?.id === that.backportOf?.id &&
|
|
79
|
+
self.reverts.length === that.reverts.length &&
|
|
80
|
+
self.reverts.every((change, index) => change.id === that.reverts[index]?.id));
|
|
81
|
+
|
|
82
|
+
/** Whether content declares at least one occurrence. Empty groups declare none. */
|
|
83
|
+
const hasOccurrences = (content: Migration.Content): boolean =>
|
|
84
|
+
actionsOfSteps(stepsOf(content)).length > 0;
|
|
85
|
+
|
|
86
|
+
/** Whether content has prose or mentions. */
|
|
87
|
+
export const hasProse = (content: Migration.Content): boolean =>
|
|
88
|
+
content.some(
|
|
89
|
+
(fragment) =>
|
|
90
|
+
fragment._tag === "ActionRef" ||
|
|
91
|
+
(fragment._tag === "Text" && fragment.text.trim() !== ""),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const sameAction = (self: Action.Any, that: Action.Any) =>
|
|
95
|
+
self === that || (self.kind === that.kind && Equal.equals(self.payload, that.payload));
|
|
96
|
+
|
|
97
|
+
/** Collects every distinct migration: registered ones and those inside shortcuts. */
|
|
98
|
+
export const allMigrations = (declarations: Declarations): ReadonlyArray<Migration.Any> => {
|
|
99
|
+
const result: Array<Migration.Any> = [...declarations.migrations];
|
|
100
|
+
for (const shortcut of declarations.shortcuts) {
|
|
101
|
+
for (const migration of shortcut.migrations) {
|
|
102
|
+
if (!result.includes(migration)) result.push(migration);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const isChain = (migrations: ReadonlyArray<Migration.Any>, from: Version, to: Version): boolean => {
|
|
110
|
+
let current = from.id;
|
|
111
|
+
for (const migration of migrations) {
|
|
112
|
+
if (migration.from.id !== current) return false;
|
|
113
|
+
current = migration.to.id;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return migrations.length > 0 && current === to.id;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const validate = (declarations: Declarations): ReadonlyArray<Issue> => {
|
|
120
|
+
const issues: Array<Issue> = [];
|
|
121
|
+
const issue = (tag: Issue["_tag"], subject: string, message: string) =>
|
|
122
|
+
issues.push({ _tag: tag, subject, message });
|
|
123
|
+
|
|
124
|
+
// Versions and ancestry.
|
|
125
|
+
const versions = new Map<string, Version>();
|
|
126
|
+
for (const version of declarations.versions) {
|
|
127
|
+
if (versions.has(version.id)) {
|
|
128
|
+
issue(
|
|
129
|
+
"DuplicateVersion",
|
|
130
|
+
version.id,
|
|
131
|
+
`Version "${version.id}" is registered more than once.`,
|
|
132
|
+
);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
versions.set(version.id, version);
|
|
136
|
+
}
|
|
137
|
+
const unregistered = new Map<string, Array<string>>();
|
|
138
|
+
const requireVersion = (version: Version, referencedBy: string) => {
|
|
139
|
+
if (versions.get(version.id) !== undefined) return;
|
|
140
|
+
|
|
141
|
+
const referrers = unregistered.get(version.id) ?? [];
|
|
142
|
+
if (!referrers.includes(referencedBy)) referrers.push(referencedBy);
|
|
143
|
+
unregistered.set(version.id, referrers);
|
|
144
|
+
};
|
|
145
|
+
for (const version of versions.values()) {
|
|
146
|
+
if (version.previous !== undefined)
|
|
147
|
+
requireVersion(version.previous, `version "${version.id}"`);
|
|
148
|
+
}
|
|
149
|
+
const ancestry = Graph.directed<string, undefined>((graph) => {
|
|
150
|
+
const nodes = new Map<string, Graph.NodeIndex>();
|
|
151
|
+
for (const id of versions.keys()) nodes.set(id, Graph.addNode(graph, id));
|
|
152
|
+
for (const version of versions.values()) {
|
|
153
|
+
const source = nodes.get(version.id);
|
|
154
|
+
const target =
|
|
155
|
+
version.previous === undefined ? undefined : nodes.get(version.previous.id);
|
|
156
|
+
if (source !== undefined && target !== undefined)
|
|
157
|
+
Graph.addEdge(graph, source, target, undefined);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
const cycle = Graph.findCycle(ancestry);
|
|
161
|
+
if (Option.isSome(cycle)) {
|
|
162
|
+
const ids = cycle.value.path.flatMap((index) =>
|
|
163
|
+
Option.toArray(Graph.getNode(ancestry, index)),
|
|
164
|
+
);
|
|
165
|
+
issue(
|
|
166
|
+
"AncestryCycle",
|
|
167
|
+
ids[0] ?? "",
|
|
168
|
+
`Release ancestry contains a cycle: ${ids.join(" -> ")}.`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Change definitions.
|
|
173
|
+
const changes = new Map<string, Change.Any>();
|
|
174
|
+
// Every distinct object is compared and has its relationships followed, so a repeated
|
|
175
|
+
// definition cannot hide a conflict between the changes it refers to.
|
|
176
|
+
const visited = new Set<Change.Any>();
|
|
177
|
+
const conflictingChanges = new Set<string>();
|
|
178
|
+
const visitChange = (change: Change.Any) => {
|
|
179
|
+
if (visited.has(change)) return;
|
|
180
|
+
visited.add(change);
|
|
181
|
+
const known = changes.get(change.id);
|
|
182
|
+
if (known === undefined) changes.set(change.id, change);
|
|
183
|
+
else if (!sameDefinition(known, change) && !conflictingChanges.has(change.id)) {
|
|
184
|
+
conflictingChanges.add(change.id);
|
|
185
|
+
issue(
|
|
186
|
+
"ConflictingChange",
|
|
187
|
+
change.id,
|
|
188
|
+
`Change "${change.id}" has conflicting definitions.`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
for (const reverted of change.reverts) visitChange(reverted);
|
|
192
|
+
if (change.backportOf !== undefined) visitChange(change.backportOf);
|
|
193
|
+
};
|
|
194
|
+
for (const version of declarations.versions) {
|
|
195
|
+
for (const change of version.changes) visitChange(change);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Action identities.
|
|
199
|
+
const actions = new Map<string, Action.Any>();
|
|
200
|
+
const conflicting = new Set<string>();
|
|
201
|
+
const visitAction = (action: Action.Any) => {
|
|
202
|
+
const known = actions.get(action.id);
|
|
203
|
+
if (known === undefined) {
|
|
204
|
+
actions.set(action.id, action);
|
|
205
|
+
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!sameAction(known, action) && !conflicting.has(action.id)) {
|
|
209
|
+
conflicting.add(action.id);
|
|
210
|
+
issue(
|
|
211
|
+
"ConflictingAction",
|
|
212
|
+
action.id,
|
|
213
|
+
`Action "${action.id}" has conflicting definitions; action identifiers must be unique.`,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Migrations.
|
|
219
|
+
const migrations = allMigrations(declarations);
|
|
220
|
+
const migrationIds = new Map<string, Migration.Any>();
|
|
221
|
+
const registered = new Set<Migration.Any>();
|
|
222
|
+
for (const migration of declarations.migrations) {
|
|
223
|
+
if (registered.has(migration) || migrationIds.has(migration.id)) {
|
|
224
|
+
issue(
|
|
225
|
+
"DuplicateMigration",
|
|
226
|
+
migration.id,
|
|
227
|
+
`Migration "${migration.id}" is registered more than once. Register a migration once; register the result of Migration.withRevert in place of the original.`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
registered.add(migration);
|
|
231
|
+
migrationIds.set(migration.id, migration);
|
|
232
|
+
}
|
|
233
|
+
for (const migration of migrations) {
|
|
234
|
+
const known = migrationIds.get(migration.id);
|
|
235
|
+
if (known !== undefined && known !== migration && !registered.has(migration)) {
|
|
236
|
+
issue(
|
|
237
|
+
"DuplicateMigration",
|
|
238
|
+
migration.id,
|
|
239
|
+
`Migration "${migration.id}" has another definition inside a shortcut.`,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
if (known === undefined) migrationIds.set(migration.id, migration);
|
|
243
|
+
|
|
244
|
+
requireVersion(migration.from, `migration "${migration.id}"`);
|
|
245
|
+
requireVersion(migration.to, `migration "${migration.id}"`);
|
|
246
|
+
if (migration.from.id === migration.to.id) {
|
|
247
|
+
issue(
|
|
248
|
+
"SelfMigration",
|
|
249
|
+
migration.id,
|
|
250
|
+
`Migration "${migration.id}" starts and ends at the same version.`,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
for (const change of migration.addresses) visitChange(change);
|
|
254
|
+
|
|
255
|
+
const sides: ReadonlyArray<[string, Migration.Content | undefined]> = [
|
|
256
|
+
["forward", migration.content],
|
|
257
|
+
["revert", migration.revert],
|
|
258
|
+
];
|
|
259
|
+
for (const [direction, content] of sides) {
|
|
260
|
+
if (content === undefined) continue;
|
|
261
|
+
if (!migration.noop && !hasOccurrences(content) && !hasProse(content)) {
|
|
262
|
+
issue(
|
|
263
|
+
"EmptyMigration",
|
|
264
|
+
migration.id,
|
|
265
|
+
`The ${direction} side of migration "${migration.id}" is empty. Use Migration.noop to declare a zero-work transition.`,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
const counts = new Map<string, number>();
|
|
269
|
+
for (const action of actionsOfSteps(stepsOf(content))) {
|
|
270
|
+
visitAction(action);
|
|
271
|
+
counts.set(action.id, (counts.get(action.id) ?? 0) + 1);
|
|
272
|
+
}
|
|
273
|
+
for (const [actionId, count] of counts) {
|
|
274
|
+
if (count < 2) continue;
|
|
275
|
+
|
|
276
|
+
issue(
|
|
277
|
+
"DuplicateOccurrence",
|
|
278
|
+
migration.id,
|
|
279
|
+
`Action "${actionId}" occurs ${count} times in the ${direction} side of migration "${migration.id}". Use Action.ref to mention an action, or a separate action instance to repeat the work.`,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Edges. Each pair of versions has at most one migration side, so a transition's work
|
|
286
|
+
// lives in one migration.
|
|
287
|
+
const edgeSides = new Map<
|
|
288
|
+
string,
|
|
289
|
+
{ readonly from: string; readonly to: string; readonly labels: Array<string> }
|
|
290
|
+
>();
|
|
291
|
+
const addSide = (from: Version, to: Version, label: string) => {
|
|
292
|
+
const key = JSON.stringify([from.id, to.id]);
|
|
293
|
+
const side = edgeSides.get(key) ?? { from: from.id, to: to.id, labels: [] };
|
|
294
|
+
side.labels.push(label);
|
|
295
|
+
edgeSides.set(key, side);
|
|
296
|
+
};
|
|
297
|
+
// A migration registered twice is already a DuplicateMigration issue.
|
|
298
|
+
for (const migration of new Set(migrationIds.values())) {
|
|
299
|
+
if (!registered.has(migration)) continue;
|
|
300
|
+
addSide(migration.from, migration.to, `"${migration.id}"`);
|
|
301
|
+
if (migration.revert !== undefined)
|
|
302
|
+
addSide(migration.to, migration.from, `the revert of "${migration.id}"`);
|
|
303
|
+
}
|
|
304
|
+
for (const { from, to, labels } of edgeSides.values()) {
|
|
305
|
+
if (labels.length < 2) continue;
|
|
306
|
+
|
|
307
|
+
issue(
|
|
308
|
+
"DuplicateEdge",
|
|
309
|
+
`${from} -> ${to}`,
|
|
310
|
+
`${labels.join(" and ")} both go from "${from}" to "${to}". Merge them into one migration.`,
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Rules.
|
|
315
|
+
const rules = new Set<string>();
|
|
316
|
+
for (const rule of declarations.rules) {
|
|
317
|
+
if (rules.has(rule.id)) {
|
|
318
|
+
issue("DuplicateRule", rule.id, `Rule "${rule.id}" is registered more than once.`);
|
|
319
|
+
}
|
|
320
|
+
rules.add(rule.id);
|
|
321
|
+
if (rule.match.length === 0) {
|
|
322
|
+
issue("InvalidRule", rule.id, `Rule "${rule.id}" matches nothing.`);
|
|
323
|
+
}
|
|
324
|
+
const patternActions = actionsOfSteps(rule.match);
|
|
325
|
+
const replacementActions = actionsOfSteps(rule.replacement);
|
|
326
|
+
for (const action of [...patternActions, ...replacementActions]) visitAction(action);
|
|
327
|
+
const unique = new Set(replacementActions.map((action) => action.id));
|
|
328
|
+
if (unique.size !== replacementActions.length) {
|
|
329
|
+
issue(
|
|
330
|
+
"InvalidRule",
|
|
331
|
+
rule.id,
|
|
332
|
+
`Rule "${rule.id}" repeats an action in its replacement.`,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
// Same actions in a different structure, such as a sequence made parallel, is a
|
|
336
|
+
// real replacement.
|
|
337
|
+
if (rule.match.length > 0 && stepKey(rule.match) === stepKey(rule.replacement)) {
|
|
338
|
+
issue("InvalidRule", rule.id, `Rule "${rule.id}" replaces its match with itself.`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Shortcuts.
|
|
343
|
+
const shortcuts = new Set<string>();
|
|
344
|
+
for (const shortcut of declarations.shortcuts) {
|
|
345
|
+
if (shortcuts.has(shortcut.id)) {
|
|
346
|
+
issue(
|
|
347
|
+
"DuplicateShortcut",
|
|
348
|
+
shortcut.id,
|
|
349
|
+
`Shortcut "${shortcut.id}" is registered more than once.`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
shortcuts.add(shortcut.id);
|
|
353
|
+
requireVersion(shortcut.from, `shortcut "${shortcut.id}"`);
|
|
354
|
+
requireVersion(shortcut.to, `shortcut "${shortcut.id}"`);
|
|
355
|
+
const unknown = shortcut.replaces.filter((migration) => !registered.has(migration));
|
|
356
|
+
if (unknown.length > 0) {
|
|
357
|
+
issue(
|
|
358
|
+
"InvalidShortcut",
|
|
359
|
+
shortcut.id,
|
|
360
|
+
`Shortcut "${shortcut.id}" replaces unregistered migrations: ${unknown.map((migration) => migration.id).join(", ")}.`,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
if (!isChain(shortcut.replaces, shortcut.from, shortcut.to)) {
|
|
364
|
+
issue(
|
|
365
|
+
"InvalidShortcut",
|
|
366
|
+
shortcut.id,
|
|
367
|
+
`Shortcut "${shortcut.id}" must replace a consecutive route from "${shortcut.from.id}" to "${shortcut.to.id}".`,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
if (!isChain(shortcut.migrations, shortcut.from, shortcut.to)) {
|
|
371
|
+
issue(
|
|
372
|
+
"InvalidShortcut",
|
|
373
|
+
shortcut.id,
|
|
374
|
+
`The migrations of shortcut "${shortcut.id}" must form a route from "${shortcut.from.id}" to "${shortcut.to.id}".`,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
for (const [id, referrers] of unregistered) {
|
|
380
|
+
issue(
|
|
381
|
+
"UnregisteredVersion",
|
|
382
|
+
id,
|
|
383
|
+
`Version "${id}" is referenced by ${referrers.join(", ")} but is not registered.`,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return Arr.sort(issues, issueOrder);
|
|
388
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Predicate } from "effect";
|
|
2
|
+
|
|
3
|
+
import type { Instruction } from "./instruction.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Describes one kind of consumer-owned operation and its payload.
|
|
7
|
+
*
|
|
8
|
+
* @since @next
|
|
9
|
+
*/
|
|
10
|
+
export type Kind<P> = {
|
|
11
|
+
readonly _tag: "ActionKind";
|
|
12
|
+
readonly kind: string;
|
|
13
|
+
readonly describe: (payload: P) => string;
|
|
14
|
+
/** Creates an action instance with a stable identifier. */
|
|
15
|
+
readonly make: <const Id extends string>(id: Id, payload: P) => Action<Id, P>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* One concrete instruction. Its `id` identifies the instruction across plans, handler
|
|
20
|
+
* bindings, rules, and reports.
|
|
21
|
+
*
|
|
22
|
+
* @since @next
|
|
23
|
+
*/
|
|
24
|
+
export type Action<Id extends string = string, P = unknown> = {
|
|
25
|
+
readonly _tag: "Action";
|
|
26
|
+
readonly id: Id;
|
|
27
|
+
readonly kind: string;
|
|
28
|
+
readonly payload: P;
|
|
29
|
+
/** The description produced by the kind's `describe` function. */
|
|
30
|
+
readonly description: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Any action instance.
|
|
35
|
+
*
|
|
36
|
+
* @since @next
|
|
37
|
+
*/
|
|
38
|
+
export type Any = Action<string, any>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A mention of an action in prose. It does not declare an occurrence.
|
|
42
|
+
*
|
|
43
|
+
* @since @next
|
|
44
|
+
*/
|
|
45
|
+
export type Ref = {
|
|
46
|
+
readonly _tag: "ActionRef";
|
|
47
|
+
readonly action: Any;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Children run one after another.
|
|
52
|
+
*
|
|
53
|
+
* @since @next
|
|
54
|
+
*/
|
|
55
|
+
export type Sequence<A extends Any = Any> = {
|
|
56
|
+
readonly _tag: "Sequence";
|
|
57
|
+
readonly children: ReadonlyArray<Step>;
|
|
58
|
+
/** Type-level record of the action instances in `children`. */
|
|
59
|
+
readonly "~actions"?: A;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* How many branches of a parallel group may run at the same time.
|
|
64
|
+
*
|
|
65
|
+
* @since @next
|
|
66
|
+
*/
|
|
67
|
+
export type Concurrency = number | "unbounded";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Branches are independent of each other and may run concurrently. The group asserts
|
|
71
|
+
* that independence; the concurrency limit only controls scheduling.
|
|
72
|
+
*
|
|
73
|
+
* @since @next
|
|
74
|
+
*/
|
|
75
|
+
export type Parallel<A extends Any = Any> = {
|
|
76
|
+
readonly _tag: "Parallel";
|
|
77
|
+
readonly branches: ReadonlyArray<Step>;
|
|
78
|
+
readonly concurrency: Concurrency;
|
|
79
|
+
/** Type-level record of the action instances in `branches`. */
|
|
80
|
+
readonly "~actions"?: A;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A node that declares action occurrences.
|
|
85
|
+
*
|
|
86
|
+
* @since @next
|
|
87
|
+
*/
|
|
88
|
+
export type Step<A extends Any = Any> = A | Instruction<A> | Sequence<A> | Parallel<A>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extracts the action instances declared by a step.
|
|
92
|
+
*
|
|
93
|
+
* @since @next
|
|
94
|
+
*/
|
|
95
|
+
export type ActionsOf<S> =
|
|
96
|
+
S extends Action<infer Id, infer P>
|
|
97
|
+
? Action<Id, P>
|
|
98
|
+
: S extends Instruction<infer A>
|
|
99
|
+
? A
|
|
100
|
+
: S extends Sequence<infer A>
|
|
101
|
+
? A
|
|
102
|
+
: S extends Parallel<infer A>
|
|
103
|
+
? A
|
|
104
|
+
: never;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Defines an action kind.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const RenameKey = Action.define<{ target: string; from: string; to: string }>(
|
|
112
|
+
* "config.rename",
|
|
113
|
+
* { describe: ({ target, from, to }) => `In ${target}, rename "${from}" to "${to}"` },
|
|
114
|
+
* );
|
|
115
|
+
* const renameExportA = RenameKey.make("rename-export-a-timeout", {
|
|
116
|
+
* target: "export-a",
|
|
117
|
+
* from: "timeout",
|
|
118
|
+
* to: "requestTimeout",
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @since @next
|
|
123
|
+
*/
|
|
124
|
+
export const define = <P>(
|
|
125
|
+
kind: string,
|
|
126
|
+
options: { readonly describe?: (payload: P) => string } = {},
|
|
127
|
+
): Kind<P> => {
|
|
128
|
+
const describe = options.describe ?? (() => kind);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
_tag: "ActionKind",
|
|
132
|
+
kind,
|
|
133
|
+
describe,
|
|
134
|
+
make: (id, payload) => ({
|
|
135
|
+
_tag: "Action",
|
|
136
|
+
id,
|
|
137
|
+
kind,
|
|
138
|
+
payload,
|
|
139
|
+
description: describe(payload),
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Mentions an action in prose without declaring another occurrence.
|
|
146
|
+
*
|
|
147
|
+
* @since @next
|
|
148
|
+
*/
|
|
149
|
+
export const ref = (action: Any): Ref => ({ _tag: "ActionRef", action });
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Declares steps that run one after another.
|
|
153
|
+
*
|
|
154
|
+
* @since @next
|
|
155
|
+
*/
|
|
156
|
+
export const sequence = <const S extends ReadonlyArray<Step>>(
|
|
157
|
+
children: S,
|
|
158
|
+
): Sequence<ActionsOf<S[number]>> => ({ _tag: "Sequence", children });
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Declares independent branches that may run concurrently. Each branch can be a single
|
|
162
|
+
* step or a sequence.
|
|
163
|
+
*
|
|
164
|
+
* @since @next
|
|
165
|
+
*/
|
|
166
|
+
export const parallel = <const S extends ReadonlyArray<Step>>(
|
|
167
|
+
branches: S,
|
|
168
|
+
options: { readonly concurrency?: Concurrency } = {},
|
|
169
|
+
): Parallel<ActionsOf<S[number]>> => ({
|
|
170
|
+
_tag: "Parallel",
|
|
171
|
+
branches,
|
|
172
|
+
concurrency: options.concurrency ?? "unbounded",
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/** @since @next */
|
|
176
|
+
export const isAction = (value: unknown): value is Any =>
|
|
177
|
+
Predicate.isTagged(value, "Action") && Predicate.hasProperty(value, "id");
|
|
178
|
+
|
|
179
|
+
/** @since @next */
|
|
180
|
+
export const isRef = (value: unknown): value is Ref => Predicate.isTagged(value, "ActionRef");
|
|
181
|
+
|
|
182
|
+
/** @since @next */
|
|
183
|
+
export const isSequence = (value: unknown): value is Sequence =>
|
|
184
|
+
Predicate.isTagged(value, "Sequence");
|
|
185
|
+
|
|
186
|
+
/** @since @next */
|
|
187
|
+
export const isParallel = (value: unknown): value is Parallel =>
|
|
188
|
+
Predicate.isTagged(value, "Parallel");
|