@smthrs/plan 0.0.0-stage → 1.0.0-rc.4
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/CHANGELOG.md +183 -0
- package/LICENSE +21 -0
- package/README.md +228 -2
- package/dist/cjs/CachePolicy.d.ts +131 -0
- package/dist/cjs/CachePolicy.d.ts.map +1 -0
- package/dist/cjs/CachePolicy.js +50 -0
- package/dist/cjs/CachePolicy.js.map +7 -0
- package/dist/cjs/Effects.d.ts +240 -0
- package/dist/cjs/Effects.d.ts.map +1 -0
- package/dist/cjs/Effects.js +76 -0
- package/dist/cjs/Effects.js.map +7 -0
- package/dist/cjs/FileSet.d.ts +288 -0
- package/dist/cjs/FileSet.d.ts.map +1 -0
- package/dist/cjs/FileSet.js +191 -0
- package/dist/cjs/FileSet.js.map +7 -0
- package/dist/cjs/GraphBuildError.d.ts +122 -0
- package/dist/cjs/GraphBuildError.d.ts.map +1 -0
- package/dist/cjs/GraphBuildError.js +71 -0
- package/dist/cjs/GraphBuildError.js.map +7 -0
- package/dist/cjs/KeyMaterial.d.ts +102 -0
- package/dist/cjs/KeyMaterial.d.ts.map +1 -0
- package/dist/cjs/KeyMaterial.js +64 -0
- package/dist/cjs/KeyMaterial.js.map +7 -0
- package/dist/cjs/Node.d.ts +606 -0
- package/dist/cjs/Node.d.ts.map +1 -0
- package/dist/cjs/Node.js +207 -0
- package/dist/cjs/Node.js.map +7 -0
- package/dist/cjs/Placement.d.ts +117 -0
- package/dist/cjs/Placement.d.ts.map +1 -0
- package/dist/cjs/Placement.js +46 -0
- package/dist/cjs/Placement.js.map +7 -0
- package/dist/cjs/Plan.d.ts +440 -0
- package/dist/cjs/Plan.d.ts.map +1 -0
- package/dist/cjs/Plan.js +508 -0
- package/dist/cjs/Plan.js.map +7 -0
- package/dist/cjs/PlanDiff.d.ts +58 -0
- package/dist/cjs/PlanDiff.d.ts.map +1 -0
- package/dist/cjs/PlanDiff.js +124 -0
- package/dist/cjs/PlanDiff.js.map +7 -0
- package/dist/cjs/Planned.d.ts +121 -0
- package/dist/cjs/Planned.d.ts.map +1 -0
- package/dist/cjs/Planned.js +72 -0
- package/dist/cjs/Planned.js.map +7 -0
- package/dist/cjs/Repetition.d.ts +31 -0
- package/dist/cjs/Repetition.d.ts.map +1 -0
- package/dist/cjs/Repetition.js +36 -0
- package/dist/cjs/Repetition.js.map +7 -0
- package/dist/cjs/Scheduling.d.ts +89 -0
- package/dist/cjs/Scheduling.d.ts.map +1 -0
- package/dist/cjs/Scheduling.js +76 -0
- package/dist/cjs/Scheduling.js.map +7 -0
- package/dist/cjs/StepKey.d.ts +333 -0
- package/dist/cjs/StepKey.d.ts.map +1 -0
- package/dist/cjs/StepKey.js +311 -0
- package/dist/cjs/StepKey.js.map +7 -0
- package/dist/cjs/index.d.ts +91 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +59 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/ConflictAnnotation.d.ts +59 -0
- package/dist/cjs/internal/ConflictAnnotation.d.ts.map +1 -0
- package/dist/cjs/internal/ConflictAnnotation.js +247 -0
- package/dist/cjs/internal/ConflictAnnotation.js.map +7 -0
- package/dist/cjs/internal/EffectCandidates.d.ts +19 -0
- package/dist/cjs/internal/EffectCandidates.d.ts.map +1 -0
- package/dist/cjs/internal/EffectCandidates.js +92 -0
- package/dist/cjs/internal/EffectCandidates.js.map +7 -0
- package/dist/cjs/internal/JsonMirror.d.ts +34 -0
- package/dist/cjs/internal/JsonMirror.d.ts.map +1 -0
- package/dist/cjs/internal/JsonMirror.js +195 -0
- package/dist/cjs/internal/JsonMirror.js.map +7 -0
- package/dist/cjs/internal/effects.d.ts +245 -0
- package/dist/cjs/internal/effects.d.ts.map +1 -0
- package/dist/cjs/internal/effects.js +290 -0
- package/dist/cjs/internal/effects.js.map +7 -0
- package/dist/cjs/internal/node.d.ts +526 -0
- package/dist/cjs/internal/node.d.ts.map +1 -0
- package/dist/cjs/internal/node.js +312 -0
- package/dist/cjs/internal/node.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/PlanFixtures.d.ts +127 -0
- package/dist/cjs/test/PlanFixtures.d.ts.map +1 -0
- package/dist/cjs/test/PlanFixtures.js +59 -0
- package/dist/cjs/test/PlanFixtures.js.map +7 -0
- package/dist/esm/CachePolicy.d.ts +131 -0
- package/dist/esm/CachePolicy.d.ts.map +1 -0
- package/dist/esm/CachePolicy.js +117 -0
- package/dist/esm/CachePolicy.js.map +1 -0
- package/dist/esm/Effects.d.ts +240 -0
- package/dist/esm/Effects.d.ts.map +1 -0
- package/dist/esm/Effects.js +167 -0
- package/dist/esm/Effects.js.map +1 -0
- package/dist/esm/FileSet.d.ts +288 -0
- package/dist/esm/FileSet.d.ts.map +1 -0
- package/dist/esm/FileSet.js +324 -0
- package/dist/esm/FileSet.js.map +1 -0
- package/dist/esm/GraphBuildError.d.ts +122 -0
- package/dist/esm/GraphBuildError.d.ts.map +1 -0
- package/dist/esm/GraphBuildError.js +146 -0
- package/dist/esm/GraphBuildError.js.map +1 -0
- package/dist/esm/KeyMaterial.d.ts +102 -0
- package/dist/esm/KeyMaterial.d.ts.map +1 -0
- package/dist/esm/KeyMaterial.js +85 -0
- package/dist/esm/KeyMaterial.js.map +1 -0
- package/dist/esm/Node.d.ts +606 -0
- package/dist/esm/Node.d.ts.map +1 -0
- package/dist/esm/Node.js +521 -0
- package/dist/esm/Node.js.map +1 -0
- package/dist/esm/Placement.d.ts +117 -0
- package/dist/esm/Placement.d.ts.map +1 -0
- package/dist/esm/Placement.js +65 -0
- package/dist/esm/Placement.js.map +1 -0
- package/dist/esm/Plan.d.ts +440 -0
- package/dist/esm/Plan.d.ts.map +1 -0
- package/dist/esm/Plan.js +673 -0
- package/dist/esm/Plan.js.map +1 -0
- package/dist/esm/PlanDiff.d.ts +58 -0
- package/dist/esm/PlanDiff.d.ts.map +1 -0
- package/dist/esm/PlanDiff.js +159 -0
- package/dist/esm/PlanDiff.js.map +1 -0
- package/dist/esm/Planned.d.ts +121 -0
- package/dist/esm/Planned.d.ts.map +1 -0
- package/dist/esm/Planned.js +147 -0
- package/dist/esm/Planned.js.map +1 -0
- package/dist/esm/Repetition.d.ts +31 -0
- package/dist/esm/Repetition.d.ts.map +1 -0
- package/dist/esm/Repetition.js +24 -0
- package/dist/esm/Repetition.js.map +1 -0
- package/dist/esm/Scheduling.d.ts +89 -0
- package/dist/esm/Scheduling.d.ts.map +1 -0
- package/dist/esm/Scheduling.js +82 -0
- package/dist/esm/Scheduling.js.map +1 -0
- package/dist/esm/StepKey.d.ts +333 -0
- package/dist/esm/StepKey.d.ts.map +1 -0
- package/dist/esm/StepKey.js +478 -0
- package/dist/esm/StepKey.js.map +1 -0
- package/dist/esm/index.d.ts +91 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +91 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/ConflictAnnotation.d.ts +59 -0
- package/dist/esm/internal/ConflictAnnotation.d.ts.map +1 -0
- package/dist/esm/internal/ConflictAnnotation.js +332 -0
- package/dist/esm/internal/ConflictAnnotation.js.map +1 -0
- package/dist/esm/internal/EffectCandidates.d.ts +19 -0
- package/dist/esm/internal/EffectCandidates.d.ts.map +1 -0
- package/dist/esm/internal/EffectCandidates.js +86 -0
- package/dist/esm/internal/EffectCandidates.js.map +1 -0
- package/dist/esm/internal/JsonMirror.d.ts +34 -0
- package/dist/esm/internal/JsonMirror.d.ts.map +1 -0
- package/dist/esm/internal/JsonMirror.js +204 -0
- package/dist/esm/internal/JsonMirror.js.map +1 -0
- package/dist/esm/internal/effects.d.ts +245 -0
- package/dist/esm/internal/effects.d.ts.map +1 -0
- package/dist/esm/internal/effects.js +459 -0
- package/dist/esm/internal/effects.js.map +1 -0
- package/dist/esm/internal/node.d.ts +526 -0
- package/dist/esm/internal/node.d.ts.map +1 -0
- package/dist/esm/internal/node.js +564 -0
- package/dist/esm/internal/node.js.map +1 -0
- package/dist/esm/test/PlanFixtures.d.ts +127 -0
- package/dist/esm/test/PlanFixtures.d.ts.map +1 -0
- package/dist/esm/test/PlanFixtures.js +60 -0
- package/dist/esm/test/PlanFixtures.js.map +1 -0
- package/docs/README.md +165 -0
- package/docs/api.md +1475 -0
- package/docs/concepts/authoring-ast.md +203 -0
- package/docs/concepts/effects-and-conflicts.md +135 -0
- package/docs/concepts/plan-value.md +168 -0
- package/docs/concepts/step-keys.md +179 -0
- package/docs/guides/author-a-node-graph.md +182 -0
- package/docs/guides/compile-a-plan.md +146 -0
- package/docs/guides/declare-file-effects.md +143 -0
- package/docs/guides/diff-two-plans.md +101 -0
- package/docs/installation.md +71 -0
- package/docs/quickstart.md +128 -0
- package/docs/testing.md +73 -0
- package/docs/troubleshooting.md +314 -0
- package/package.json +254 -3
- package/src/CachePolicy.ts +143 -0
- package/src/Effects.ts +284 -0
- package/src/FileSet.ts +411 -0
- package/src/GraphBuildError.ts +158 -0
- package/src/KeyMaterial.ts +106 -0
- package/src/Node.ts +871 -0
- package/src/Placement.ts +99 -0
- package/src/Plan.ts +868 -0
- package/src/PlanDiff.ts +199 -0
- package/src/Planned.ts +208 -0
- package/src/Repetition.ts +33 -0
- package/src/Scheduling.ts +154 -0
- package/src/StepKey.ts +710 -0
- package/src/index.ts +103 -0
- package/src/internal/ConflictAnnotation.ts +374 -0
- package/src/internal/EffectCandidates.ts +89 -0
- package/src/internal/JsonMirror.ts +255 -0
- package/src/internal/effects.ts +543 -0
- package/src/internal/node.ts +858 -0
- package/src/test/PlanFixtures.ts +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlanDiff.d.ts","sourceRoot":"","sources":["../../src/PlanDiff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAGtC;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACxC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IACxC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAC1C;AAuGD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,GAAI,UAAU,IAAI,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,IAAI,KAAG,QAmC3D,CAAA"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var PlanDiff_exports = {};
|
|
20
|
+
__export(PlanDiff_exports, {
|
|
21
|
+
diff: () => diff
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(PlanDiff_exports);
|
|
24
|
+
var import_JsonMirror = require("./internal/JsonMirror.js");
|
|
25
|
+
const stable = (value) => {
|
|
26
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
27
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "undefined";
|
|
28
|
+
if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
|
|
29
|
+
const entries = Object.entries(value).sort(([left], [right]) => left < right ? -1 : 1);
|
|
30
|
+
return `{${entries.map(([name, entry]) => `${JSON.stringify(name)}:${stable(entry)}`).join(",")}}`;
|
|
31
|
+
};
|
|
32
|
+
const plannedReference = (_value, reference) => ({
|
|
33
|
+
_tag: "PlannedReference",
|
|
34
|
+
node: reference.node,
|
|
35
|
+
path: reference.path
|
|
36
|
+
});
|
|
37
|
+
const fieldComparison = () => {
|
|
38
|
+
const refused = /* @__PURE__ */ new Map();
|
|
39
|
+
const token = (input, nodeId, field) => {
|
|
40
|
+
try {
|
|
41
|
+
return stable((0, import_JsonMirror.jsonMirror)(input, plannedReference));
|
|
42
|
+
} catch {
|
|
43
|
+
const address = JSON.stringify([nodeId, field]);
|
|
44
|
+
let fields = refused.get(input);
|
|
45
|
+
if (fields === void 0) {
|
|
46
|
+
fields = /* @__PURE__ */ new Map();
|
|
47
|
+
refused.set(input, fields);
|
|
48
|
+
}
|
|
49
|
+
let sentinel = fields.get(address);
|
|
50
|
+
if (sentinel === void 0) {
|
|
51
|
+
sentinel = Symbol(address);
|
|
52
|
+
fields.set(address, sentinel);
|
|
53
|
+
}
|
|
54
|
+
return sentinel;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return (previous, next, nodeId, field) => token(previous, nodeId, field) === token(next, nodeId, field);
|
|
58
|
+
};
|
|
59
|
+
const changedFields = (previous, next, rekeyedDependencies, sameField) => {
|
|
60
|
+
const changed = [];
|
|
61
|
+
if (!sameField(previous.material.version, next.material.version, next.id, "version")) changed.push("version");
|
|
62
|
+
if (previous.material.kind !== next.material.kind) changed.push("kind");
|
|
63
|
+
if (!sameField(previous.material.body, next.material.body, next.id, "body")) changed.push("body");
|
|
64
|
+
if (!sameField(previous.material.nondeterministic, next.material.nondeterministic, next.id, "nondeterministic")) {
|
|
65
|
+
changed.push("nondeterministic");
|
|
66
|
+
}
|
|
67
|
+
if (!sameField(previous.material.effects, next.material.effects, next.id, "effects")) changed.push("effects");
|
|
68
|
+
if (!sameField(previous.material.placement, next.material.placement, next.id, "placement")) {
|
|
69
|
+
changed.push("placement");
|
|
70
|
+
}
|
|
71
|
+
const width = Math.max(previous.material.inputs.length, next.material.inputs.length);
|
|
72
|
+
for (let index = 0; index < width; index++) {
|
|
73
|
+
const before = previous.material.inputs[index];
|
|
74
|
+
const after = next.material.inputs[index];
|
|
75
|
+
const field = `input[${index}]`;
|
|
76
|
+
if (before === void 0 || after === void 0 || !sameField(before, after, next.id, field)) {
|
|
77
|
+
changed.push(field);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (after._tag !== "Literal" && rekeyedDependencies.has(after.from)) changed.push(field);
|
|
81
|
+
}
|
|
82
|
+
if (!sameField(previous.material.layers, next.material.layers, next.id, "layers")) changed.push("layers");
|
|
83
|
+
if (!sameField(previous.material.capabilities, next.material.capabilities, next.id, "capabilities")) {
|
|
84
|
+
changed.push("capabilities");
|
|
85
|
+
}
|
|
86
|
+
return changed;
|
|
87
|
+
};
|
|
88
|
+
const diff = (previous, next) => {
|
|
89
|
+
const before = new Map(previous.nodes.map((node) => [node.id, node]));
|
|
90
|
+
const after = new Map(next.nodes.map((node) => [node.id, node]));
|
|
91
|
+
const rekeyedIds = /* @__PURE__ */ new Set();
|
|
92
|
+
for (const node of next.nodes) {
|
|
93
|
+
const original = before.get(node.id);
|
|
94
|
+
if (original !== void 0 && original.key !== node.key) rekeyedIds.add(node.id);
|
|
95
|
+
}
|
|
96
|
+
const added = [];
|
|
97
|
+
const rekeyed = [];
|
|
98
|
+
const unchanged = [];
|
|
99
|
+
const sameField = fieldComparison();
|
|
100
|
+
for (const node of next.nodes) {
|
|
101
|
+
const original = before.get(node.id);
|
|
102
|
+
if (original === void 0) {
|
|
103
|
+
added.push(node.id);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (original.key === node.key) {
|
|
107
|
+
unchanged.push(node.id);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
rekeyed.push({
|
|
111
|
+
id: node.id,
|
|
112
|
+
from: original.key,
|
|
113
|
+
to: node.key,
|
|
114
|
+
changed: changedFields(original, node, rekeyedIds, sameField)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
added,
|
|
119
|
+
removed: previous.nodes.filter((node) => !after.has(node.id)).map((node) => node.id),
|
|
120
|
+
rekeyed,
|
|
121
|
+
unchanged
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=PlanDiff.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/PlanDiff.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A plan comparison, as a value.\n *\n * A plan diff answers \"which steps changed key (and _which input_\n * changed them), what entered the envelope, what joined the release set \u2014\n * 'what is different about this run' is a set comparison, not archaeology.\"\n * This module is the set comparison.\n *\n * The **verdict** is the key: two nodes with the same id and the same key are\n * the same step and nothing else needs saying. The **attribution** \u2014\n * `changed: [\"input[1]\"]` \u2014 is a report for a human, derived by comparing the\n * declarations field by field. It is deliberately not part of any digest.\n *\n * @since 0.1.0\n */\n\nimport { jsonMirror } from \"./internal/JsonMirror.ts\"\nimport type * as Plan from \"./Plan.ts\"\nimport type * as Planned from \"./Planned.ts\"\n\n/**\n * A node whose key moved, with the fields that moved it.\n *\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport interface Rekeyed {\n readonly id: string\n readonly from: string\n readonly to: string\n /**\n * Field labels such as `\"kind\"`, `\"body\"`, `\"layers\"`, `\"capabilities\"`,\n * `\"effects\"`, and `\"input[0]\"` whose declaration differs. `\"kind\"` is the\n * effect tier (`sealed`, `compensable`, or `irreversible`). A\n * `Pending`-referenced upstream re-key is attributed to that input position\n * too. `changed` is empty only when none of the compared fields moved.\n */\n readonly changed: ReadonlyArray<string>\n}\n\n/**\n * What changed between two plans of the same flow.\n *\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport interface PlanDiff {\n readonly added: ReadonlyArray<string>\n readonly removed: ReadonlyArray<string>\n readonly rekeyed: ReadonlyArray<Rekeyed>\n readonly unchanged: ReadonlyArray<string>\n}\n\n/**\n * Order-insensitive structural comparison for the attribution report only.\n * Digests go through RFC 8785 canonical JSON; this does not have to, and\n * saying so keeps the two from being confused.\n *\n * @private\n */\nconst stable = (value: unknown): string => {\n if (typeof value === \"bigint\") return `${value}n`\n if (value === null || typeof value !== \"object\") return JSON.stringify(value) ?? \"undefined\"\n if (Array.isArray(value)) return `[${value.map(stable).join(\",\")}]`\n const entries = Object.entries(value as Record<string, unknown>).sort(([left], [right]) => left < right ? -1 : 1)\n return `{${entries.map(([name, entry]) => `${JSON.stringify(name)}:${stable(entry)}`).join(\",\")}}`\n}\n\n/**\n * A planned value compares as the reference an AST stores for it, so the same\n * reference at the same place is unchanged.\n *\n * @private\n */\nconst plannedReference = (_value: unknown, reference: Planned.Reference) => ({\n _tag: \"PlannedReference\",\n node: reference.node,\n path: reference.path\n})\n\n/** @private */\ntype ComparisonToken = string | symbol\n\n/**\n * Projects compared fields through the key's JSON semantics. A refused value\n * receives an identity token scoped to its node and field, so the same value\n * remains equal to itself without equating two distinct refused values.\n *\n * @private\n */\nconst fieldComparison = () => {\n const refused = new Map<unknown, Map<string, symbol>>()\n const token = (input: unknown, nodeId: string, field: string): ComparisonToken => {\n try {\n return stable(jsonMirror(input, plannedReference))\n } catch {\n const address = JSON.stringify([nodeId, field])\n let fields = refused.get(input)\n if (fields === undefined) {\n fields = new Map()\n refused.set(input, fields)\n }\n let sentinel = fields.get(address)\n if (sentinel === undefined) {\n sentinel = Symbol(address)\n fields.set(address, sentinel)\n }\n return sentinel\n }\n }\n return (previous: unknown, next: unknown, nodeId: string, field: string): boolean =>\n token(previous, nodeId, field) === token(next, nodeId, field)\n}\n\n/** @private */\nconst changedFields = (\n previous: Plan.PlanNode,\n next: Plan.PlanNode,\n rekeyedDependencies: ReadonlySet<string>,\n sameField: ReturnType<typeof fieldComparison>\n): ReadonlyArray<string> => {\n const changed: Array<string> = []\n // StepKey.materialBody is the identity list this attribution must mirror.\n // Inputs, layers, and capabilities complete fromKeyMaterial's hashed value,\n // and material.kind selects the key namespace (content versus tier-bearing\n // plan declaration), so a tier-only move still re-keys and is blamed here.\n if (!sameField(previous.material.version, next.material.version, next.id, \"version\")) changed.push(\"version\")\n if (previous.material.kind !== next.material.kind) changed.push(\"kind\")\n if (!sameField(previous.material.body, next.material.body, next.id, \"body\")) changed.push(\"body\")\n if (!sameField(previous.material.nondeterministic, next.material.nondeterministic, next.id, \"nondeterministic\")) {\n changed.push(\"nondeterministic\")\n }\n if (!sameField(previous.material.effects, next.material.effects, next.id, \"effects\")) changed.push(\"effects\")\n if (!sameField(previous.material.placement, next.material.placement, next.id, \"placement\")) {\n changed.push(\"placement\")\n }\n const width = Math.max(previous.material.inputs.length, next.material.inputs.length)\n for (let index = 0; index < width; index++) {\n const before = previous.material.inputs[index]\n const after = next.material.inputs[index]\n const field = `input[${index}]`\n if (before === undefined || after === undefined || !sameField(before, after, next.id, field)) {\n changed.push(field)\n continue\n }\n if (after._tag !== \"Literal\" && rekeyedDependencies.has(after.from)) changed.push(field)\n }\n if (!sameField(previous.material.layers, next.material.layers, next.id, \"layers\")) changed.push(\"layers\")\n if (!sameField(previous.material.capabilities, next.material.capabilities, next.id, \"capabilities\")) {\n changed.push(\"capabilities\")\n }\n return changed\n}\n\n/**\n * Compares a plan against the last plan for the same flow.\n *\n * @since 0.1.0\n * @category constructors\n * @slop\n */\nexport const diff = (previous: Plan.Plan, next: Plan.Plan): PlanDiff => {\n const before = new Map(previous.nodes.map((node) => [node.id, node]))\n const after = new Map(next.nodes.map((node) => [node.id, node]))\n const rekeyedIds = new Set<string>()\n for (const node of next.nodes) {\n const original = before.get(node.id)\n if (original !== undefined && original.key !== node.key) rekeyedIds.add(node.id)\n }\n const added: Array<string> = []\n const rekeyed: Array<Rekeyed> = []\n const unchanged: Array<string> = []\n const sameField = fieldComparison()\n for (const node of next.nodes) {\n const original = before.get(node.id)\n if (original === undefined) {\n added.push(node.id)\n continue\n }\n if (original.key === node.key) {\n unchanged.push(node.id)\n continue\n }\n rekeyed.push({\n id: node.id,\n from: original.key,\n to: node.key,\n changed: changedFields(original, node, rekeyedIds, sameField)\n })\n }\n return {\n added,\n removed: previous.nodes.filter((node) => !after.has(node.id)).map((node) => node.id),\n rekeyed,\n unchanged\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,wBAA2B;AA8C3B,MAAM,SAAS,CAAC,UAA2B;AACzC,MAAI,OAAO,UAAU,SAAU,QAAO,GAAG,KAAK;AAC9C,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO,KAAK,UAAU,KAAK,KAAK;AACjF,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,IAAI,MAAM,IAAI,MAAM,EAAE,KAAK,GAAG,CAAC;AAChE,QAAM,UAAU,OAAO,QAAQ,KAAgC,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,MAAM,OAAO,QAAQ,KAAK,CAAC;AAChH,SAAO,IAAI,QAAQ,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,KAAK,UAAU,IAAI,CAAC,IAAI,OAAO,KAA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M,aAAa,oBAAI,IAAY;AACnC,aAAW,QAAQ,KAAK,OAAO;AAC7B,UAAM,WAAW,OAAO,IAAI,KAAK,EAAE;AACnC,QAAI,aAAa,UAAa,SAAS,QAAQ,KAAK,IAAK,YAAW,IAAI,KAAK,EAAE;AAAA,EACjF;AACA,QAAM,QAAuB,CAAC;AAC9B,QAAM,UAA0B,CAAC;AACjC,QAAM,YAA2B,CAAC;AAClC,QAAM,YAAY,gBAAgB;AAClC,aAAW,QAAQ,KAAK,OAAO;AAC7B,UAAM,WAAW,OAAO,IAAI,KAAK,EAAE;AACnC,QAAI,aAAa,QAAW;AAC1B,YAAM,KAAK,KAAK,EAAE;AAClB;AAAA,IACF;AACA,QAAI,SAAS,QAAQ,KAAK,KAAK;AAC7B,gBAAU,KAAK,KAAK,EAAE;AACtB;AAAA,IACF;AACA,YAAQ,KAAK;AAAA,MACX,IAAI,KAAK;AAAA,MACT,MAAM,SAAS;AAAA,MACf,IAAI,KAAK;AAAA,MACT,SAAS,cAAc,UAAU,MAAM,YAAY,SAAS;AAAA,IAC9D,CAAC;AAAA,EACH;AACA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,SAAS,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,KAAK,EAAE;AAAA,IACnF;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The placeholder a body sees where a step result will be.
|
|
3
|
+
*
|
|
4
|
+
* A flow body runs at PLAN time, so its
|
|
5
|
+
* own payload is real data while every step result is a value that does not
|
|
6
|
+
* exist yet. That value has a name and one rule: a planned value may be **passed** — into a payload field,
|
|
7
|
+
* into a branch, into a map — and field access is allowed, because it records a
|
|
8
|
+
* reference path. It may never be **computed on**.
|
|
9
|
+
*
|
|
10
|
+
* {@link Planned} is branded, so arithmetic is a compile error.
|
|
11
|
+
* {@link make} returns a strict proxy
|
|
12
|
+
* whose `Symbol.toPrimitive`, `valueOf`, `toString`, `toJSON`, and call traps
|
|
13
|
+
* throw {@link module:GraphBuildError.GraphBuildError} rather than let a plan be
|
|
14
|
+
* built around `NaN` or `"[object Object]"`. The lenient proxy this adapts
|
|
15
|
+
* (`@smthrs/core`'s `Graph.plannedValue`) answered `toPrimitive` with a
|
|
16
|
+
* readable string, which is exactly the silent-wrong-plan path this module
|
|
17
|
+
* exists to close.
|
|
18
|
+
*
|
|
19
|
+
* JavaScript does not expose traps for `Boolean(value)` or strict identity
|
|
20
|
+
* (`value === other`), so those operations cannot be refused at run time.
|
|
21
|
+
* They reveal only proxy truthiness or identity and never the planned result;
|
|
22
|
+
* authors must use {@link module:Node.branch} for decisions on real values.
|
|
23
|
+
* Type-aware ESLint `@typescript-eslint/strict-boolean-expressions` rejects
|
|
24
|
+
* planned conditions, but does not reject explicit Boolean coercion or all
|
|
25
|
+
* reference comparisons. Those still require review.
|
|
26
|
+
*
|
|
27
|
+
* @since 0.1.0
|
|
28
|
+
*/
|
|
29
|
+
import type * as Types from "effect/Types";
|
|
30
|
+
/**
|
|
31
|
+
* The brand carried by every planned value, and the key its reference is read
|
|
32
|
+
* from. Interned with `Symbol.for` so a value that crossed a module boundary is
|
|
33
|
+
* still recognised. The interned symbol is a recognition aid, not a
|
|
34
|
+
* capability, so {@link reference} validates the value stored under it.
|
|
35
|
+
*
|
|
36
|
+
* @since 0.1.0
|
|
37
|
+
* @category symbols
|
|
38
|
+
* @slop
|
|
39
|
+
*/
|
|
40
|
+
export declare const TypeId: unique symbol;
|
|
41
|
+
/**
|
|
42
|
+
* The type-level form of {@link TypeId}.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.1.0
|
|
45
|
+
* @category symbols
|
|
46
|
+
* @slop
|
|
47
|
+
*/
|
|
48
|
+
export type TypeId = typeof TypeId;
|
|
49
|
+
/**
|
|
50
|
+
* What a planned value points at: the node that will produce the result, and
|
|
51
|
+
* the property path read from it. `path` is empty for the result itself.
|
|
52
|
+
*
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
* @category models
|
|
55
|
+
* @slop
|
|
56
|
+
*/
|
|
57
|
+
export interface Reference {
|
|
58
|
+
readonly node: string;
|
|
59
|
+
readonly path: ReadonlyArray<string>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A {@link Reference} plus the phantom type of the value it stands for, so
|
|
63
|
+
* `Planned<string>` and `Planned<number>` are not interchangeable.
|
|
64
|
+
*
|
|
65
|
+
* @since 0.1.0
|
|
66
|
+
* @category models
|
|
67
|
+
* @slop
|
|
68
|
+
*/
|
|
69
|
+
export interface Identity<out T> extends Reference {
|
|
70
|
+
readonly _T: Types.Covariant<T>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A step result that has not been produced yet.
|
|
74
|
+
*
|
|
75
|
+
* The brand rejects arithmetic and ordinary value arguments. The mapped half keeps field
|
|
76
|
+
* access typed — `result.files` is a `Planned` of the field, which is what
|
|
77
|
+
* makes "pass it on, never compute on it" expressible rather than merely
|
|
78
|
+
* documented.
|
|
79
|
+
*
|
|
80
|
+
* @since 0.1.0
|
|
81
|
+
* @category models
|
|
82
|
+
* @slop
|
|
83
|
+
*/
|
|
84
|
+
export type Planned<T> = {
|
|
85
|
+
readonly [TypeId]: Identity<T>;
|
|
86
|
+
} & ([T] extends [object] ? {
|
|
87
|
+
readonly [K in keyof T]: Planned<T[K]>;
|
|
88
|
+
} : unknown);
|
|
89
|
+
/**
|
|
90
|
+
* Creates the strict placeholder standing for a node's result.
|
|
91
|
+
*
|
|
92
|
+
* Planning hands one of these to every builder that consumes an upstream
|
|
93
|
+
* value — a branch arm, a continuation — and reads the {@link Reference} back
|
|
94
|
+
* off whatever the builder passed it into.
|
|
95
|
+
*
|
|
96
|
+
* @since 0.1.0
|
|
97
|
+
* @category constructors
|
|
98
|
+
* @slop
|
|
99
|
+
*/
|
|
100
|
+
export declare const make: <T>(node: string) => Planned<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Reads the reference a planned value records, or `undefined` for anything
|
|
103
|
+
* else. An interned symbol is a recognition aid rather than a capability, so a
|
|
104
|
+
* forged carrier is accepted only when its node and path have the complete
|
|
105
|
+
* reference shape. This is how a payload is scanned for the upstream results
|
|
106
|
+
* it consumes.
|
|
107
|
+
*
|
|
108
|
+
* @since 0.1.0
|
|
109
|
+
* @category accessors
|
|
110
|
+
* @slop
|
|
111
|
+
*/
|
|
112
|
+
export declare const reference: (value: unknown) => Reference | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* Checks whether a value is a planned placeholder.
|
|
115
|
+
*
|
|
116
|
+
* @since 0.1.0
|
|
117
|
+
* @category guards
|
|
118
|
+
* @slop
|
|
119
|
+
*/
|
|
120
|
+
export declare const isPlanned: (value: unknown) => value is Planned<unknown>;
|
|
121
|
+
//# sourceMappingURL=Planned.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Planned.d.ts","sourceRoot":"","sources":["../../src/Planned.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAG1C;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,MAA2C,CAAA;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAA;AAElC;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAE,SAAQ,SAAS;IAChD,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;CAChC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IACjB;IAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAAE,GAClC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,OAAO,CAAC,CAAA;AAmEjF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,MAAM,MAAM,KAAG,OAAO,CAAC,CAAC,CAAkD,CAAA;AAalG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,SAAS,GAAG,SAItD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAAO,CAAC,OAAO,CAAmC,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Planned_exports = {};
|
|
20
|
+
__export(Planned_exports, {
|
|
21
|
+
TypeId: () => TypeId,
|
|
22
|
+
isPlanned: () => isPlanned,
|
|
23
|
+
make: () => make,
|
|
24
|
+
reference: () => reference
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(Planned_exports);
|
|
27
|
+
var import_GraphBuildError = require("./GraphBuildError.js");
|
|
28
|
+
const TypeId = /* @__PURE__ */ Symbol.for("@smthrs/plan/Planned");
|
|
29
|
+
const refusals = /* @__PURE__ */ new Map([
|
|
30
|
+
[Symbol.toPrimitive, "Symbol.toPrimitive"],
|
|
31
|
+
["valueOf", "valueOf"],
|
|
32
|
+
["toString", "toString"],
|
|
33
|
+
["toJSON", "toJSON"]
|
|
34
|
+
]);
|
|
35
|
+
const describe = (reference2) => reference2.path.length === 0 ? reference2.node : `${reference2.node}.${reference2.path.join(".")}`;
|
|
36
|
+
const refuse = (reference2, operation) => new import_GraphBuildError.GraphBuildError({
|
|
37
|
+
code: "planned_value_computed",
|
|
38
|
+
node: reference2.node,
|
|
39
|
+
path: reference2.path,
|
|
40
|
+
message: `Planned value ${describe(reference2)} was computed at plan time by ${operation}. Use Node.map to compute, Node.branch to decide, or pass the value into a payload.`
|
|
41
|
+
});
|
|
42
|
+
const placeholder = (reference2) => {
|
|
43
|
+
const target = () => void 0;
|
|
44
|
+
return new Proxy(target, {
|
|
45
|
+
get: (_target, key) => {
|
|
46
|
+
if (key === TypeId) return reference2;
|
|
47
|
+
const refusal = refusals.get(key);
|
|
48
|
+
if (refusal !== void 0) throw refuse(reference2, refusal);
|
|
49
|
+
if (key === "then") return void 0;
|
|
50
|
+
return placeholder({ node: reference2.node, path: [...reference2.path, String(key)] });
|
|
51
|
+
},
|
|
52
|
+
apply: () => {
|
|
53
|
+
throw refuse(reference2, "function application");
|
|
54
|
+
},
|
|
55
|
+
has: () => {
|
|
56
|
+
throw refuse(reference2, "property existence (`in`)");
|
|
57
|
+
},
|
|
58
|
+
ownKeys: () => {
|
|
59
|
+
throw refuse(reference2, "property enumeration");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const make = (node) => placeholder({ node, path: [] });
|
|
64
|
+
const carrier = (value) => typeof value === "object" && value !== null || typeof value === "function";
|
|
65
|
+
const validReference = (value) => typeof value === "object" && value !== null && typeof value.node === "string" && value.node.length > 0 && Array.isArray(value.path) && Array.from(value.path).every((segment) => typeof segment === "string");
|
|
66
|
+
const reference = (value) => {
|
|
67
|
+
if (!carrier(value)) return void 0;
|
|
68
|
+
const candidate = value[TypeId];
|
|
69
|
+
return validReference(candidate) ? candidate : void 0;
|
|
70
|
+
};
|
|
71
|
+
const isPlanned = (value) => reference(value) !== void 0;
|
|
72
|
+
//# sourceMappingURL=Planned.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Planned.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The placeholder a body sees where a step result will be.\n *\n * A flow body runs at PLAN time, so its\n * own payload is real data while every step result is a value that does not\n * exist yet. That value has a name and one rule: a planned value may be **passed** \u2014 into a payload field,\n * into a branch, into a map \u2014 and field access is allowed, because it records a\n * reference path. It may never be **computed on**.\n *\n * {@link Planned} is branded, so arithmetic is a compile error.\n * {@link make} returns a strict proxy\n * whose `Symbol.toPrimitive`, `valueOf`, `toString`, `toJSON`, and call traps\n * throw {@link module:GraphBuildError.GraphBuildError} rather than let a plan be\n * built around `NaN` or `\"[object Object]\"`. The lenient proxy this adapts\n * (`@smthrs/core`'s `Graph.plannedValue`) answered `toPrimitive` with a\n * readable string, which is exactly the silent-wrong-plan path this module\n * exists to close.\n *\n * JavaScript does not expose traps for `Boolean(value)` or strict identity\n * (`value === other`), so those operations cannot be refused at run time.\n * They reveal only proxy truthiness or identity and never the planned result;\n * authors must use {@link module:Node.branch} for decisions on real values.\n * Type-aware ESLint `@typescript-eslint/strict-boolean-expressions` rejects\n * planned conditions, but does not reject explicit Boolean coercion or all\n * reference comparisons. Those still require review.\n *\n * @since 0.1.0\n */\n\nimport type * as Types from \"effect/Types\"\nimport { GraphBuildError } from \"./GraphBuildError.ts\"\n\n/**\n * The brand carried by every planned value, and the key its reference is read\n * from. Interned with `Symbol.for` so a value that crossed a module boundary is\n * still recognised. The interned symbol is a recognition aid, not a\n * capability, so {@link reference} validates the value stored under it.\n *\n * @since 0.1.0\n * @category symbols\n * @slop\n */\nexport const TypeId: unique symbol = Symbol.for(\"@smthrs/plan/Planned\")\n\n/**\n * The type-level form of {@link TypeId}.\n *\n * @since 0.1.0\n * @category symbols\n * @slop\n */\nexport type TypeId = typeof TypeId\n\n/**\n * What a planned value points at: the node that will produce the result, and\n * the property path read from it. `path` is empty for the result itself.\n *\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport interface Reference {\n readonly node: string\n readonly path: ReadonlyArray<string>\n}\n\n/**\n * A {@link Reference} plus the phantom type of the value it stands for, so\n * `Planned<string>` and `Planned<number>` are not interchangeable.\n *\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport interface Identity<out T> extends Reference {\n readonly _T: Types.Covariant<T>\n}\n\n/**\n * A step result that has not been produced yet.\n *\n * The brand rejects arithmetic and ordinary value arguments. The mapped half keeps field\n * access typed \u2014 `result.files` is a `Planned` of the field, which is what\n * makes \"pass it on, never compute on it\" expressible rather than merely\n * documented.\n *\n * @since 0.1.0\n * @category models\n * @slop\n */\nexport type Planned<T> =\n & { readonly [TypeId]: Identity<T> }\n & ([T] extends [object] ? { readonly [K in keyof T]: Planned<T[K]> } : unknown)\n\n/**\n * The operations that are computation rather than reference, keyed by the\n * property that performs them. `toJSON` is here because `JSON.stringify` reads\n * it, and a plan that serialized a placeholder would look correct.\n *\n * @private\n */\nconst refusals = new Map<PropertyKey, string>([\n [Symbol.toPrimitive, \"Symbol.toPrimitive\"],\n [\"valueOf\", \"valueOf\"],\n [\"toString\", \"toString\"],\n [\"toJSON\", \"toJSON\"]\n])\n\n/** @private */\nconst describe = (reference: Reference): string =>\n reference.path.length === 0 ? reference.node : `${reference.node}.${reference.path.join(\".\")}`\n\n/**\n * The one refusal this module raises. The guidance is spelled out rather than\n * linked because the author reading it is inside a body and needs the\n * correction on the spot.\n *\n * @private\n */\nconst refuse = (reference: Reference, operation: string): GraphBuildError =>\n new GraphBuildError({\n code: \"planned_value_computed\",\n node: reference.node,\n path: reference.path,\n message: `Planned value ${describe(reference)} was computed at plan time by ${operation}. ` +\n \"Use Node.map to compute, Node.branch to decide, or pass the value into a payload.\"\n })\n\n/**\n * The proxy itself. `_T` of {@link Identity} is a phantom and never exists at\n * run time, so the trap carries the plain {@link Reference}.\n *\n * @private\n */\nconst placeholder = (reference: Reference): unknown => {\n /* v8 ignore next -- a Proxy application always enters the `apply` trap below, so the callable target is unreachable by construction */\n const target = (): undefined => undefined\n return new Proxy(target, {\n get: (_target, key) => {\n if (key === TypeId) return reference\n const refusal = refusals.get(key)\n if (refusal !== undefined) throw refuse(reference, refusal)\n // Not a thenable: a body that returns a planned value inside a promise\n // must resolve to the placeholder, not hang awaiting a proxy.\n if (key === \"then\") return undefined\n return placeholder({ node: reference.node, path: [...reference.path, String(key)] })\n },\n apply: () => {\n throw refuse(reference, \"function application\")\n },\n has: () => {\n throw refuse(reference, \"property existence (`in`)\")\n },\n ownKeys: () => {\n throw refuse(reference, \"property enumeration\")\n }\n })\n}\n\n/**\n * Creates the strict placeholder standing for a node's result.\n *\n * Planning hands one of these to every builder that consumes an upstream\n * value \u2014 a branch arm, a continuation \u2014 and reads the {@link Reference} back\n * off whatever the builder passed it into.\n *\n * @since 0.1.0\n * @category constructors\n * @slop\n */\nexport const make = <T>(node: string): Planned<T> => placeholder({ node, path: [] }) as Planned<T>\n\n/** @private */\nconst carrier = (value: unknown): value is { readonly [TypeId]?: Reference } =>\n (typeof value === \"object\" && value !== null) || typeof value === \"function\"\n\n/** @private */\nconst validReference = (value: unknown): value is Reference =>\n typeof value === \"object\" && value !== null &&\n typeof (value as Reference).node === \"string\" && (value as Reference).node.length > 0 &&\n Array.isArray((value as Reference).path) &&\n Array.from((value as Reference).path).every((segment) => typeof segment === \"string\")\n\n/**\n * Reads the reference a planned value records, or `undefined` for anything\n * else. An interned symbol is a recognition aid rather than a capability, so a\n * forged carrier is accepted only when its node and path have the complete\n * reference shape. This is how a payload is scanned for the upstream results\n * it consumes.\n *\n * @since 0.1.0\n * @category accessors\n * @slop\n */\nexport const reference = (value: unknown): Reference | undefined => {\n if (!carrier(value)) return undefined\n const candidate = value[TypeId]\n return validReference(candidate) ? candidate : undefined\n}\n\n/**\n * Checks whether a value is a planned placeholder.\n *\n * @since 0.1.0\n * @category guards\n * @slop\n */\nexport const isPlanned = (value: unknown): value is Planned<unknown> => reference(value) !== undefined\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,6BAAgC;AAYzB,MAAM,SAAwB,uBAAO,IAAI,sBAAsB;AA2DtE,MAAM,WAAW,oBAAI,IAAyB;AAAA,EAC5C,CAAC,OAAO,aAAa,oBAAoB;AAAA,EACzC,CAAC,WAAW,SAAS;AAAA,EACrB,CAAC,YAAY,UAAU;AAAA,EACvB,CAAC,UAAU,QAAQ;AACrB,CAAC;AAGD,MAAM,WAAW,CAACA,eAChBA,WAAU,KAAK,WAAW,IAAIA,WAAU,OAAO,GAAGA,WAAU,IAAI,IAAIA,WAAU,KAAK,KAAK,GAAG,CAAC;AAS9F,MAAM,SAAS,CAACA,YAAsB,cACpC,IAAI,uCAAgB;AAAA,EAClB,MAAM;AAAA,EACN,MAAMA,WAAU;AAAA,EAChB,MAAMA,WAAU;AAAA,EAChB,SAAS,iBAAiB,SAASA,UAAS,CAAC,iCAAiC,SAAS;AAEzF,CAAC;AAQH,MAAM,cAAc,CAACA,eAAkC;AAErD,QA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
+
* What a bounded repetition does when it reaches its ceiling.
|
|
3
|
+
*
|
|
4
|
+
* This is the ONE ceiling vocabulary. `@smthrs/flow`'s `Poll.make` takes it as
|
|
5
|
+
* `onTimeout`, for the attempt a poll gives up on, and `@smthrs/patterns`'
|
|
6
|
+
* `Loop` takes it as `onMaxReached`, for the iteration a loop gives up on. It
|
|
7
|
+
* was the same two words written out in both packages, with no edge between
|
|
8
|
+
* them, so a third member added on one side would have been invisible to the
|
|
9
|
+
* other. It lives here because `@smthrs/plan` is the package both already
|
|
10
|
+
* depend on.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0-rc.0
|
|
13
|
+
*/
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
/**
|
|
16
|
+
* What a bounded repetition answers with at its ceiling: `fail` raises the
|
|
17
|
+
* repetition's own typed failure, and `return-last` settles with the last
|
|
18
|
+
* value it produced.
|
|
19
|
+
*
|
|
20
|
+
* @category models
|
|
21
|
+
* @since 1.0.0-rc.0
|
|
22
|
+
*/
|
|
23
|
+
export declare const AtCeiling: Schema.Literals<readonly ["fail", "return-last"]>;
|
|
24
|
+
/**
|
|
25
|
+
* The value form of {@link AtCeiling}.
|
|
26
|
+
*
|
|
27
|
+
* @category models
|
|
28
|
+
* @since 1.0.0-rc.0
|
|
29
|
+
*/
|
|
30
|
+
export type AtCeiling = typeof AtCeiling.Type;
|
|
31
|
+
//# sourceMappingURL=Repetition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Repetition.d.ts","sourceRoot":"","sources":["../../src/Repetition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mDAA2C,CAAA;AAEjE;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Repetition_exports = {};
|
|
30
|
+
__export(Repetition_exports, {
|
|
31
|
+
AtCeiling: () => AtCeiling
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Repetition_exports);
|
|
34
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
35
|
+
const AtCeiling = Schema.Literals(["fail", "return-last"]);
|
|
36
|
+
//# sourceMappingURL=Repetition.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Repetition.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * What a bounded repetition does when it reaches its ceiling.\n *\n * This is the ONE ceiling vocabulary. `@smthrs/flow`'s `Poll.make` takes it as\n * `onTimeout`, for the attempt a poll gives up on, and `@smthrs/patterns`'\n * `Loop` takes it as `onMaxReached`, for the iteration a loop gives up on. It\n * was the same two words written out in both packages, with no edge between\n * them, so a third member added on one side would have been invisible to the\n * other. It lives here because `@smthrs/plan` is the package both already\n * depend on.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as Schema from \"effect/Schema\"\n\n/**\n * What a bounded repetition answers with at its ceiling: `fail` raises the\n * repetition's own typed failure, and `return-last` settles with the last\n * value it produced.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport const AtCeiling = Schema.Literals([\"fail\", \"return-last\"])\n\n/**\n * The value form of {@link AtCeiling}.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport type AtCeiling = typeof AtCeiling.Type\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,aAAwB;AAUjB,MAAM,YAAY,OAAO,SAAS,CAAC,QAAQ,aAAa,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared ready-work admission policy. This module decides priority, aging,
|
|
3
|
+
* deterministic ties, and step/agent capacity. It does not decide which nodes
|
|
4
|
+
* are ready, evaluate branches, launch effects, or own execution lifetimes.
|
|
5
|
+
* Those decisions must use the compiled graph and the caller's activation
|
|
6
|
+
* state before presenting candidates here.
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
import type * as Plan from "./Plan.ts";
|
|
11
|
+
/**
|
|
12
|
+
* Admission limits, independent of graph width and provider capacity.
|
|
13
|
+
* Omitted limits are unbounded within JavaScript's safe-integer range.
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
* @category models
|
|
17
|
+
*/
|
|
18
|
+
export interface Concurrency {
|
|
19
|
+
readonly steps?: number | undefined;
|
|
20
|
+
readonly agents?: number | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Currently held permits. Every agent also holds a step permit.
|
|
24
|
+
*
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
* @category models
|
|
27
|
+
*/
|
|
28
|
+
export interface Usage {
|
|
29
|
+
readonly steps: number;
|
|
30
|
+
readonly agents: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The part of a plan node admission reads. Declared once here so the three
|
|
34
|
+
* places that name it, {@link Candidate}, {@link Admission} and
|
|
35
|
+
* {@link Policy.admit}, cannot drift apart.
|
|
36
|
+
*/
|
|
37
|
+
type Schedulable = Pick<Plan.PlanNode, "id" | "kind" | "priority">;
|
|
38
|
+
/**
|
|
39
|
+
* A ready node's scheduling state. `order` is its position in the compiled
|
|
40
|
+
* plan, not arrival order. `waited` counts capacity-constrained admission
|
|
41
|
+
* passes, not wall-clock time.
|
|
42
|
+
*
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
* @category models
|
|
45
|
+
*/
|
|
46
|
+
export interface Candidate<N extends Schedulable = Plan.PlanNode> {
|
|
47
|
+
readonly node: N;
|
|
48
|
+
readonly order: number;
|
|
49
|
+
readonly waited: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One admission decision. Deferred candidates carry their incremented age;
|
|
53
|
+
* admitted candidates retain their age for dispatch diagnostics. No input is
|
|
54
|
+
* mutated and neither array owns or freezes the caller's node values.
|
|
55
|
+
*
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
* @category models
|
|
58
|
+
*/
|
|
59
|
+
export interface Admission<N extends Schedulable = Plan.PlanNode> {
|
|
60
|
+
readonly admitted: ReadonlyArray<Candidate<N>>;
|
|
61
|
+
readonly deferred: ReadonlyArray<Candidate<N>>;
|
|
62
|
+
readonly agents: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Pure policy shared by execution coordinators.
|
|
66
|
+
*
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
* @category models
|
|
69
|
+
*/
|
|
70
|
+
export interface Policy {
|
|
71
|
+
readonly limits: Usage;
|
|
72
|
+
readonly admit: <N extends Schedulable>(ready: ReadonlyArray<Candidate<N>>, active: Usage) => Admission<N>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Snapshots validated limits. Admission orders by declared priority plus age,
|
|
76
|
+
* using exact integer arithmetic even when their sum exceeds MAX_SAFE_INTEGER.
|
|
77
|
+
* Ties preserve compiled plan order. An agent blocked by its subset cap does
|
|
78
|
+
* not prevent ordinary ready work from using spare step capacity.
|
|
79
|
+
*
|
|
80
|
+
* Invalid candidate/permit state is refused before any decision is returned.
|
|
81
|
+
* At MAX_SAFE_INTEGER the age saturates; a bounded plan cannot require that
|
|
82
|
+
* many capacity-constrained passes to drain finite work.
|
|
83
|
+
*
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
* @category constructors
|
|
86
|
+
*/
|
|
87
|
+
export declare const make: (concurrency?: Concurrency) => Policy;
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=Scheduling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scheduling.d.ts","sourceRoot":"","sources":["../../src/Scheduling.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAEtC;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;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
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Scheduling_exports = {};
|
|
20
|
+
__export(Scheduling_exports, {
|
|
21
|
+
make: () => make
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Scheduling_exports);
|
|
24
|
+
const integer = (name, value, minimum) => {
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < minimum) {
|
|
26
|
+
throw new RangeError(`${name} must be a ${minimum === 1 ? "positive" : "non-negative"} safe integer`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const make = (concurrency = {}) => {
|
|
31
|
+
const limits = Object.freeze({
|
|
32
|
+
steps: integer("concurrency.steps", concurrency.steps ?? Number.MAX_SAFE_INTEGER, 1),
|
|
33
|
+
agents: integer("concurrency.agents", concurrency.agents ?? Number.MAX_SAFE_INTEGER, 1)
|
|
34
|
+
});
|
|
35
|
+
const admit = (ready, active) => {
|
|
36
|
+
integer("active.steps", active.steps, 0);
|
|
37
|
+
integer("active.agents", active.agents, 0);
|
|
38
|
+
if (active.agents > active.steps) throw new RangeError("active.agents cannot exceed active.steps");
|
|
39
|
+
const ids = /* @__PURE__ */ new Set();
|
|
40
|
+
const positions = /* @__PURE__ */ new Set();
|
|
41
|
+
const ranked = ready.map((candidate) => {
|
|
42
|
+
const { node, order, waited } = candidate;
|
|
43
|
+
integer("candidate.order", order, 0);
|
|
44
|
+
integer("candidate.waited", waited, 0);
|
|
45
|
+
if (!Number.isSafeInteger(node.priority)) throw new RangeError("candidate.priority must be a safe integer");
|
|
46
|
+
if (node.kind !== "step" && node.kind !== "agent" && node.kind !== "merge") {
|
|
47
|
+
throw new RangeError("invalid candidate kind");
|
|
48
|
+
}
|
|
49
|
+
if (typeof node.id !== "string" || node.id === "" || ids.has(node.id)) {
|
|
50
|
+
throw new RangeError("candidate ids must be non-empty and unique");
|
|
51
|
+
}
|
|
52
|
+
if (positions.has(order)) throw new RangeError("candidate plan positions must be unique");
|
|
53
|
+
ids.add(node.id);
|
|
54
|
+
positions.add(order);
|
|
55
|
+
return { candidate, priority: BigInt(node.priority) + BigInt(waited) };
|
|
56
|
+
});
|
|
57
|
+
ranked.sort(
|
|
58
|
+
(left, right) => left.priority === right.priority ? left.candidate.order - right.candidate.order : left.priority > right.priority ? -1 : 1
|
|
59
|
+
);
|
|
60
|
+
const admitted = [];
|
|
61
|
+
const deferred = [];
|
|
62
|
+
let agents = 0;
|
|
63
|
+
for (const { candidate } of ranked) {
|
|
64
|
+
const isAgent = candidate.node.kind === "agent";
|
|
65
|
+
if (admitted.length >= limits.steps - active.steps || isAgent && agents >= limits.agents - active.agents) {
|
|
66
|
+
deferred.push(Object.freeze({ ...candidate, waited: Math.min(Number.MAX_SAFE_INTEGER, candidate.waited + 1) }));
|
|
67
|
+
} else {
|
|
68
|
+
admitted.push(Object.freeze({ ...candidate }));
|
|
69
|
+
if (isAgent) agents++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Object.freeze({ admitted: Object.freeze(admitted), deferred: Object.freeze(deferred), agents });
|
|
73
|
+
};
|
|
74
|
+
return Object.freeze({ limits, admit });
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=Scheduling.js.map
|