automategraph 1.5.1 → 1.5.3
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 +18 -5
- package/UPGRADE-PROPOSAL.md +141 -0
- package/docs/diagrams/c19-resilience-scenario.md +61 -0
- package/docs/diagrams/c19-resilience-scenario.mmd +28 -0
- package/docs/diagrams/c19-resilience-scenario.svg +181 -0
- package/examples/README.md +206 -0
- package/examples/branching-edges.ts +192 -0
- package/examples/branching-graph.ts +333 -0
- package/examples/branching-router.ts +475 -0
- package/examples/json-graph.ts +231 -0
- package/examples/json-scripts.ts +152 -0
- package/examples/order-flow.functions.cjs +32 -0
- package/examples/order-flow.graph.json +27 -0
- package/examples/order-flow.scripted.graph.json +68 -0
- package/js/examples/branching-edges.js +133 -0
- package/js/examples/branching-edges.js.map +1 -0
- package/js/examples/branching-graph.js +232 -0
- package/js/examples/branching-graph.js.map +1 -0
- package/js/examples/branching-router.js +305 -0
- package/js/examples/branching-router.js.map +1 -0
- package/js/examples/json-graph.js +197 -0
- package/js/examples/json-graph.js.map +1 -0
- package/js/examples/json-scripts.js +131 -0
- package/js/examples/json-scripts.js.map +1 -0
- package/js/tests/async.test.js +592 -0
- package/js/tests/async.test.js.map +1 -0
- package/js/tests/complex.test.js +972 -0
- package/js/tests/complex.test.js.map +1 -0
- package/js/tests/conformance.test.js +365 -0
- package/js/tests/conformance.test.js.map +1 -0
- package/js/tests/edges.test.js +702 -0
- package/js/tests/edges.test.js.map +1 -0
- package/js/tests/graphjson.test.js +504 -0
- package/js/tests/graphjson.test.js.map +1 -0
- package/js/tests/harness.js +192 -0
- package/js/tests/harness.js.map +1 -0
- package/js/tests/helpers.js +136 -0
- package/js/tests/helpers.js.map +1 -0
- package/js/tests/lint.test.js +317 -0
- package/js/tests/lint.test.js.map +1 -0
- package/js/tests/registry.test.js +705 -0
- package/js/tests/registry.test.js.map +1 -0
- package/js/tests/report.js +422 -0
- package/js/tests/report.js.map +1 -0
- package/js/tests/runner.js +67 -0
- package/js/tests/runner.js.map +1 -0
- package/js/tests/scripts.test.js +552 -0
- package/js/tests/scripts.test.js.map +1 -0
- package/js/tests/unit.test.js +1239 -0
- package/js/tests/unit.test.js.map +1 -0
- package/js/tests/upgrade.test.js +618 -0
- package/js/tests/upgrade.test.js.map +1 -0
- package/package.json +2 -9
- package/report/index.html +3727 -0
- package/report/report.json +3053 -0
- package/tests/async.test.ts +668 -0
- package/tests/complex.test.ts +1123 -0
- package/tests/conformance.test.ts +442 -0
- package/tests/edges.test.ts +848 -0
- package/tests/fixtures/scripts/bad-registration.cjs +4 -0
- package/tests/fixtures/scripts/broken.cjs +2 -0
- package/tests/fixtures/scripts/cjs-default.js +4 -0
- package/tests/fixtures/scripts/collide-a.cjs +4 -0
- package/tests/fixtures/scripts/collide-b.cjs +4 -0
- package/tests/fixtures/scripts/empty.cjs +2 -0
- package/tests/fixtures/scripts/esm-functions.mjs +10 -0
- package/tests/fixtures/scripts/esm-syntax.js +3 -0
- package/tests/fixtures/scripts/global-channel.cjs +6 -0
- package/tests/fixtures/scripts/global-channel.mjs +7 -0
- package/tests/fixtures/scripts/mismatch.cjs +4 -0
- package/tests/fixtures/scripts/needs-sibling.cjs +7 -0
- package/tests/fixtures/scripts/order.cjs +14 -0
- package/tests/fixtures/scripts/sibling-helper.cjs +3 -0
- package/tests/fixtures/scripts/throwing-global.mjs +6 -0
- package/tests/graphjson.test.ts +737 -0
- package/tests/harness.ts +291 -0
- package/tests/helpers.ts +216 -0
- package/tests/lint.test.ts +381 -0
- package/tests/registry.test.ts +1134 -0
- package/tests/report.ts +452 -0
- package/tests/runner.ts +58 -0
- package/tests/scripts.test.ts +970 -0
- package/tests/unit.test.ts +1192 -0
- package/tests/upgrade.test.ts +725 -0
- package/tools/server.mjs +152 -0
- package/tsconfig.browser.json +19 -0
- package/tsconfig.json +18 -0
- package/tsconfig.publish.json +13 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================
|
|
3
|
+
* A document that brings its own code (v1.5)
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* order-flow.scripted.graph.json declares WHICH functions it needs and
|
|
6
|
+
* WHERE they come from:
|
|
7
|
+
*
|
|
8
|
+
* scripts: [
|
|
9
|
+
* { "namespace": "order", "path": "./order-flow.functions.cjs" },
|
|
10
|
+
* { "namespace": "audit", "source": "…registerEngineNamespace('audit', …)" }
|
|
11
|
+
* ]
|
|
12
|
+
*
|
|
13
|
+
* Two strategies in one document:
|
|
14
|
+
* • `order` — a CommonJS FILE whose export table is the contribution
|
|
15
|
+
* • `audit` — INLINE source that registers itself from inside the
|
|
16
|
+
* script through globalThis.GraphEngine (the loader
|
|
17
|
+
* installs that global for the duration of the load only)
|
|
18
|
+
*
|
|
19
|
+
* The pipeline stays two-step:
|
|
20
|
+
*
|
|
21
|
+
* const { functions } = await loadGraphScripts(document);
|
|
22
|
+
* const engine = createEngineFromJSON(document, { functions });
|
|
23
|
+
*
|
|
24
|
+
* Run: npm run example:scripts (after npm run build)
|
|
25
|
+
* ============================================================ */
|
|
26
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
29
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
30
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(o, k2, desc);
|
|
33
|
+
}) : (function(o, m, k, k2) {
|
|
34
|
+
if (k2 === undefined) k2 = k;
|
|
35
|
+
o[k2] = m[k];
|
|
36
|
+
}));
|
|
37
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
38
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
39
|
+
}) : function(o, v) {
|
|
40
|
+
o["default"] = v;
|
|
41
|
+
});
|
|
42
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const graph_scripts_1 = require("../src/node/graph-scripts");
|
|
53
|
+
const graph_json_1 = require("../src/graph-json");
|
|
54
|
+
const EXAMPLES = path.join(__dirname, "..", "..", "examples");
|
|
55
|
+
const DOCUMENT_PATH = path.join(EXAMPLES, "order-flow.scripted.graph.json");
|
|
56
|
+
async function main() {
|
|
57
|
+
const document = fs.readFileSync(DOCUMENT_PATH, "utf8");
|
|
58
|
+
console.log("=".repeat(96));
|
|
59
|
+
console.log(`graph with scripts — ${path.basename(DOCUMENT_PATH)} ` +
|
|
60
|
+
"(functions live in the document's own scripts)");
|
|
61
|
+
console.log("=".repeat(96));
|
|
62
|
+
/* ---------- 1. load ---------- */
|
|
63
|
+
const loaded = await (0, graph_scripts_1.loadGraphScripts)(document, {
|
|
64
|
+
baseDir: EXAMPLES,
|
|
65
|
+
onLog: (level, message) => {
|
|
66
|
+
if (level === "warn" || level === "error")
|
|
67
|
+
console.log(` log[${level}] ${message}`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
for (const script of loaded.scripts) {
|
|
71
|
+
console.log(`\n▶ namespace "${script.namespace}" (${script.source}, ${script.format})`);
|
|
72
|
+
console.log(` provided: ${script.names.join(", ")}`);
|
|
73
|
+
if (script.ignoredExports.length > 0) {
|
|
74
|
+
console.log(` ignored (not functions): ${script.ignoredExports.join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
console.log(`\nmerged registry: ${loaded.registry.names.length} functions, ` +
|
|
78
|
+
`fingerprint ${loaded.registry.fingerprint}`);
|
|
79
|
+
/* ---------- 2. run ---------- */
|
|
80
|
+
const engine = (0, graph_json_1.createEngineFromJSON)(document, {
|
|
81
|
+
functions: loaded.functions,
|
|
82
|
+
lint: "error"
|
|
83
|
+
});
|
|
84
|
+
const report = await engine.run();
|
|
85
|
+
const path2 = report.results
|
|
86
|
+
.filter(result => result.status === "SUCCEEDED")
|
|
87
|
+
.map(result => result.nodeId)
|
|
88
|
+
.join(" → ");
|
|
89
|
+
console.log("\n" + "-".repeat(96));
|
|
90
|
+
console.log(`run: ${report.status} path: ${path2}` +
|
|
91
|
+
` ${path2 === "classify → audit → charge → ship" ? "✓" : "✗ expected classify → audit → charge → ship"}`);
|
|
92
|
+
for (const result of report.results) {
|
|
93
|
+
console.log(` ${result.nodeId.padEnd(9)} fn=${(result.fn ?? "-").padEnd(15)} ` +
|
|
94
|
+
`attempt=${result.attempt} ${result.status}` +
|
|
95
|
+
(result.output === undefined ? "" : ` output=${JSON.stringify(result.output)}`));
|
|
96
|
+
}
|
|
97
|
+
console.log(` report.registry: ${report.registry?.fingerprint} ` +
|
|
98
|
+
`(${report.registry?.fingerprint === loaded.registry.fingerprint ? "matches the loaded table" : "MISMATCH"})`);
|
|
99
|
+
console.log(` lint issues: ${report.lintIssues.length}`);
|
|
100
|
+
if (report.errors.length > 0) {
|
|
101
|
+
for (const error of report.errors) {
|
|
102
|
+
console.log(` error ${error.code} @${error.nodeId} handled=${error.handled}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/* ---------- 3. the freeze ---------- */
|
|
106
|
+
console.log("\n" + "-".repeat(96));
|
|
107
|
+
console.log("the namespace freeze: one claim per process\n");
|
|
108
|
+
console.log(` claims now: ${(0, graph_scripts_1.registeredNamespaces)()
|
|
109
|
+
.map(claim => `${claim.namespace} (${claim.names}, from ${claim.source})`)
|
|
110
|
+
.join("; ")}`);
|
|
111
|
+
try {
|
|
112
|
+
await (0, graph_scripts_1.loadGraphScripts)(document, { baseDir: EXAMPLES });
|
|
113
|
+
console.log(" ✗ a second load succeeded — the freeze is broken");
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const scripted = error;
|
|
117
|
+
console.log(` second load → ${scripted.code}`);
|
|
118
|
+
console.log(` ${scripted.message.split(". ")[0]}.`);
|
|
119
|
+
}
|
|
120
|
+
console.log("\n (resetGraphScriptNamespaces() clears the claims — test/CI hygiene;\n" +
|
|
121
|
+
" production code should not need it: a document is loaded once.)");
|
|
122
|
+
(0, graph_scripts_1.resetGraphScriptNamespaces)();
|
|
123
|
+
const reloaded = await (0, graph_scripts_1.loadGraphScripts)(document, { baseDir: EXAMPLES });
|
|
124
|
+
console.log(` after reset → loaded again: ${reloaded.registry.names.length} functions, ` +
|
|
125
|
+
`fingerprint ${reloaded.registry.fingerprint}`);
|
|
126
|
+
console.log("\n" + "=".repeat(96));
|
|
127
|
+
}
|
|
128
|
+
if (require.main === module) {
|
|
129
|
+
void main();
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=json-scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-scripts.js","sourceRoot":"","sources":["../../examples/json-scripts.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;kEAuBkE;;;;;;;;;;;;;;;;;;;;;;;;;AAElE,uCAAyB;AACzB,2CAA6B;AAE7B,6DAKmC;AACnC,kDAAyD;AAEzD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;AAC9D,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAC7B,QAAQ,EACR,gCAAgC,CACjC,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,aAAa,EAA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