@fabricorg/compiler 2.2.8 → 2.2.10
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 +28 -0
- package/dist/index.cjs +627 -351
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -59
- package/dist/index.d.ts +58 -59
- package/dist/index.js +602 -318
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.cjs
CHANGED
|
@@ -1,388 +1,664 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
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
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
FABRIC_COMPILER_VERSION: () => FABRIC_COMPILER_VERSION,
|
|
34
|
-
compareCanonicalStrings: () => compareCanonicalStrings,
|
|
35
|
-
compileManifestBundle: () => compileManifestBundle,
|
|
36
|
-
diffModuleManifests: () => diffModuleManifests,
|
|
37
|
-
runGenerator: () => runGenerator,
|
|
38
|
-
stableStringify: () => stableStringify
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(index_exports);
|
|
41
|
-
var import_node_crypto = require("crypto");
|
|
42
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
43
|
-
var import_platform = require("@fabricorg/platform");
|
|
44
|
-
var FABRIC_COMPILER_VERSION = "2.2.8";
|
|
45
|
-
var compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let crypto = require("crypto");
|
|
25
|
+
let path = require("path");
|
|
26
|
+
path = __toESM(path, 1);
|
|
27
|
+
let _fabricorg_platform = require("@fabricorg/platform");
|
|
28
|
+
//#region index.ts
|
|
29
|
+
const FABRIC_COMPILER_VERSION = "2.2.10";
|
|
30
|
+
const compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
46
31
|
function stableStringify(value) {
|
|
47
|
-
|
|
32
|
+
return JSON.stringify(sortJson(value));
|
|
48
33
|
}
|
|
49
34
|
function sortJson(value) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Object.entries(value).sort(([left], [right]) => compareCanonicalStrings(left, right)).map(([key, child]) => [key, sortJson(child)])
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
return value;
|
|
35
|
+
if (Array.isArray(value)) return value.map(sortJson);
|
|
36
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).sort(([left], [right]) => compareCanonicalStrings(left, right)).map(([key, child]) => [key, sortJson(child)]));
|
|
37
|
+
return value;
|
|
57
38
|
}
|
|
58
39
|
function compileManifestBundle(input, options = {}) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
40
|
+
const bundle = (0, _fabricorg_platform.normalizeModuleManifestBundle)(input);
|
|
41
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const module of bundle.modules) {
|
|
43
|
+
if (namespaces.has(module.namespace)) throw new Error(`Duplicate module namespace "${module.namespace}" in compiler input.`);
|
|
44
|
+
namespaces.add(module.namespace);
|
|
45
|
+
}
|
|
46
|
+
const modules = [...bundle.modules].sort((left, right) => compareCanonicalStrings(left.namespace, right.namespace));
|
|
47
|
+
assertCompilerManifests(modules, options.certificationProfiles ?? []);
|
|
48
|
+
const canonical = stableStringify({
|
|
49
|
+
manifestVersion: bundle.manifestVersion,
|
|
50
|
+
modules
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
compilerVersion: FABRIC_COMPILER_VERSION,
|
|
54
|
+
manifestVersion: bundle.manifestVersion,
|
|
55
|
+
manifestDigest: (0, crypto.createHash)("sha256").update(canonical).digest("hex"),
|
|
56
|
+
modules,
|
|
57
|
+
conformance: (options.conformanceAdapters ?? []).flatMap((adapter) => modules.map((module) => ({
|
|
58
|
+
adapterId: adapter.id,
|
|
59
|
+
moduleNamespace: module.namespace,
|
|
60
|
+
findings: adapter.evaluate(module)
|
|
61
|
+
})))
|
|
62
|
+
};
|
|
77
63
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Manifests reach the compiler without passing through a registry, so declared
|
|
66
|
+
* durability is validated here too. A contradiction between an action's declared
|
|
67
|
+
* completion and its kind is a manifest defect, and fails the build rather than a
|
|
68
|
+
* running host.
|
|
69
|
+
*/
|
|
70
|
+
function assertManifestWorkflows(module) {
|
|
71
|
+
for (const action of module.actions) if (action.execution?.completion === "immediate" && action.kind === "saga") throw new Error(`Action "${action.actionId}" declares immediate completion but is a multi-step saga.`);
|
|
72
|
+
const actionsById = new Map(module.actions.map((action) => [action.actionId, action]));
|
|
73
|
+
const names = /* @__PURE__ */ new Set();
|
|
74
|
+
for (const workflow of module.capability?.workflows ?? []) {
|
|
75
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(workflow.name)) throw new Error(`Module "${module.namespace}" declares invalid workflow name "${workflow.name}".`);
|
|
76
|
+
if (names.has(workflow.name)) throw new Error(`Module "${module.namespace}" declares duplicate workflow "${workflow.name}".`);
|
|
77
|
+
names.add(workflow.name);
|
|
78
|
+
if (!/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*$/.test(workflow.taskQueue)) throw new Error(`Module "${module.namespace}" workflow "${workflow.name}" declares invalid task queue "${workflow.taskQueue}".`);
|
|
79
|
+
const timerNames = /* @__PURE__ */ new Set();
|
|
80
|
+
for (const timer of workflow.timers ?? []) {
|
|
81
|
+
if (!timer.name?.trim() || !timer.configKey?.trim()) throw new Error(`Module "${module.namespace}" workflow "${workflow.name}" has a timer without a name or configKey.`);
|
|
82
|
+
if (timerNames.has(timer.name)) throw new Error(`Module "${module.namespace}" workflow "${workflow.name}" declares duplicate timer "${timer.name}".`);
|
|
83
|
+
timerNames.add(timer.name);
|
|
84
|
+
}
|
|
85
|
+
const steps = /* @__PURE__ */ new Set();
|
|
86
|
+
for (const compensation of workflow.compensations ?? []) {
|
|
87
|
+
if (steps.has(compensation.step)) throw new Error(`Module "${module.namespace}" workflow "${workflow.name}" declares duplicate compensation for step "${compensation.step}".`);
|
|
88
|
+
steps.add(compensation.step);
|
|
89
|
+
const compensating = actionsById.get(compensation.actionId);
|
|
90
|
+
if (!compensating) throw new Error(`Module "${module.namespace}" workflow "${workflow.name}" compensates step "${compensation.step}" with unknown action "${compensation.actionId}".`);
|
|
91
|
+
if (!compensating.idempotent) throw new Error(`Module "${module.namespace}" workflow "${workflow.name}" compensates step "${compensation.step}" with non-idempotent action "${compensation.actionId}"; a reversal must be safely repeatable.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
106
94
|
}
|
|
107
95
|
function assertCompilerManifests(modules, certificationProfiles) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
96
|
+
const profiles = new Map(certificationProfiles.map((profile) => [profile.id, profile]));
|
|
97
|
+
if (profiles.size !== certificationProfiles.length) throw new Error("Certification profile IDs must be unique.");
|
|
98
|
+
for (const [moduleIndex, module] of modules.entries()) {
|
|
99
|
+
const at = `modules[${moduleIndex}]`;
|
|
100
|
+
if (!module || typeof module !== "object") throw new Error(`${at} ${describeValue(module)}; a compiler module must be the object returned by exportModuleManifest().`);
|
|
101
|
+
if (!/^[a-z][a-z0-9-]*$/.test(module.namespace)) throw new Error(`${at}.namespace ${describeValue(module.namespace)}; a namespace is lowercase letters, digits, and hyphens, such as "orders".`);
|
|
102
|
+
for (const field of ["objectTypes", "actions"]) if (!Array.isArray(module[field])) throw new Error(`${at} ("${module.namespace}") .${field} ${describeValue(module[field])}; it must be an array. exportModuleManifest() fills every array, so a missing one usually means the manifest was hand-written rather than exported.`);
|
|
103
|
+
}
|
|
104
|
+
for (const module of modules) assertManifestWorkflows(module);
|
|
105
|
+
const targets = new Set(modules.flatMap((module) => module.objectTypes.map((objectType) => `${module.namespace}.${objectType.type}`)));
|
|
106
|
+
for (const module of modules) {
|
|
107
|
+
if (module.capability) {
|
|
108
|
+
if (!module.capability.displayName?.trim() || !module.capability.description?.trim()) throw new Error(`Module "${module.namespace}" capability requires displayName and description.`);
|
|
109
|
+
if (![
|
|
110
|
+
"experimental",
|
|
111
|
+
"beta",
|
|
112
|
+
"stable",
|
|
113
|
+
"deprecated"
|
|
114
|
+
].includes(module.capability.stability)) throw new Error(`Module "${module.namespace}" capability has invalid stability.`);
|
|
115
|
+
}
|
|
116
|
+
const certification = module.capability?.certification;
|
|
117
|
+
const profile = certification?.required ? profiles.get(certification.profile) : void 0;
|
|
118
|
+
for (const objectType of module.objectTypes) {
|
|
119
|
+
if (!/^[A-Z][A-Za-z0-9]*$/.test(objectType.type)) throw new Error(`Invalid object type at ${module.namespace}.objectTypes[${module.objectTypes.indexOf(objectType)}].type: ${describeValue(objectType.type)}; it must be PascalCase alphanumeric, such as "ServiceVisit".`);
|
|
120
|
+
if (objectType.schema) (0, _fabricorg_platform.assertPortableJsonSchema)(objectType.schema, `${module.namespace}.${objectType.type}`);
|
|
121
|
+
for (const relation of objectType.relations ?? []) if (!targets.has(relation.target)) throw new Error(`Relation ${module.namespace}.${objectType.type}.${relation.name} targets missing object type "${relation.target}".`);
|
|
122
|
+
for (const invariant of objectType.invariants ?? []) if (invariant.required && !resolvesRequiredInvariant(module, objectType, invariant, profile)) throw new Error(`Required invariant "${module.namespace}.${objectType.type}.${invariant.id}" has no resolvable enforcement evidence under certification profile "${certification?.profile ?? "none"}".`);
|
|
123
|
+
}
|
|
124
|
+
for (const view of module.views) {
|
|
125
|
+
if (!view.name.startsWith(`${module.namespace}/`)) throw new Error(`View "${view.name}" must use module namespace "${module.namespace}/".`);
|
|
126
|
+
(0, _fabricorg_platform.assertPortableJsonSchema)(view.shape, `View ${view.name}@${view.version}`);
|
|
127
|
+
if (view.parameterSchema !== void 0) (0, _fabricorg_platform.assertPortableJsonSchema)(view.parameterSchema, `View ${view.name}@${view.version} parameters`);
|
|
128
|
+
if (view.usage?.collection?.filterSchema) (0, _fabricorg_platform.assertPortableJsonSchema)(view.usage.collection.filterSchema, `View ${view.name}@${view.version} filter`);
|
|
129
|
+
}
|
|
130
|
+
for (const eventType of module.eventTypes) if (eventType.schema) (0, _fabricorg_platform.assertPortableJsonSchema)(eventType.schema, `Event ${eventType.eventType}@${eventType.schemaVersion}`);
|
|
131
|
+
for (const [actionIndex, action] of module.actions.entries()) {
|
|
132
|
+
const at = `${module.namespace}.actions[${actionIndex}]`;
|
|
133
|
+
if (typeof action.actionId !== "string" || !/^[a-z][a-z0-9-]*\.[a-z][a-z0-9_]*$/.test(action.actionId)) throw new Error(`${at}.actionId ${describeValue(action.actionId)}; it must be "<namespace>.<lower_snake_case>", such as "${module.namespace}.approve_order".`);
|
|
134
|
+
if (!action.actionId.startsWith(`${module.namespace}.`)) throw new Error(`${at}.actionId "${action.actionId}" must start with its own module namespace "${module.namespace}.".`);
|
|
135
|
+
if (!["atomic", "saga"].includes(action.kind)) throw new Error(`Action "${action.actionId}" kind ${describeValue(action.kind)}; it must be "atomic" or "saga".`);
|
|
136
|
+
if (typeof action.idempotent !== "boolean") throw new Error(`Action "${action.actionId}" idempotent ${describeValue(action.idempotent)}; it must be true or false.`);
|
|
137
|
+
if (typeof action.mutatesDomain !== "boolean") throw new Error(`Action "${action.actionId}" mutatesDomain ${describeValue(action.mutatesDomain)}; it must be true or false.`);
|
|
138
|
+
if (!Array.isArray(action.emitsEvents)) throw new Error(`Action "${action.actionId}" emitsEvents ${describeValue(action.emitsEvents)}; it must be an array of event type names, empty if the action emits none.`);
|
|
139
|
+
if (action.parameterSchema) (0, _fabricorg_platform.assertPortableJsonSchema)(action.parameterSchema, `Action ${action.actionId} parameters`);
|
|
140
|
+
if (action.resultSchema) (0, _fabricorg_platform.assertPortableJsonSchema)(action.resultSchema, `Action ${action.actionId} result`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
156
143
|
}
|
|
144
|
+
/** Names what a field actually holds, so a message locates the mistake instead of printing "undefined". */
|
|
157
145
|
function describeValue(value) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
146
|
+
if (value === void 0) return "is missing";
|
|
147
|
+
if (value === null) return "is null";
|
|
148
|
+
if (Array.isArray(value)) return `is an array of ${value.length}`;
|
|
149
|
+
if (typeof value === "object") return "is an object";
|
|
150
|
+
return `is ${JSON.stringify(value)}`;
|
|
163
151
|
}
|
|
164
|
-
function resolvesRequiredInvariant(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
152
|
+
function resolvesRequiredInvariant(module, objectType, invariant, profile) {
|
|
153
|
+
const reference = invariant.enforcementRef?.trim();
|
|
154
|
+
if (!reference) return false;
|
|
155
|
+
if (invariant.enforcement === "json-schema") {
|
|
156
|
+
const requiredMatch = /^#\/required\/([^/]+)$/.exec(reference);
|
|
157
|
+
if (requiredMatch) return Array.isArray(objectType.schema?.required) && objectType.schema.required.includes(decodeJsonPointerToken(requiredMatch[1]));
|
|
158
|
+
const propertyMatch = /^#\/properties\/([^/]+)$/.exec(reference);
|
|
159
|
+
if (propertyMatch) return Boolean(objectType.schema?.properties?.[decodeJsonPointerToken(propertyMatch[1])]);
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (invariant.enforcement === "state-machine") return module.stateMachines.some((machine) => machine.entityType === reference);
|
|
163
|
+
if (invariant.enforcement === "policy") return module.policies.some((policy) => policy.policyId === reference);
|
|
164
|
+
return profile?.resolveInvariant?.({
|
|
165
|
+
module,
|
|
166
|
+
objectType,
|
|
167
|
+
invariant
|
|
168
|
+
}) === true;
|
|
177
169
|
}
|
|
178
170
|
function decodeJsonPointerToken(token) {
|
|
179
|
-
|
|
171
|
+
return token.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
180
172
|
}
|
|
181
|
-
|
|
173
|
+
const severityRank = {
|
|
174
|
+
compatible: 0,
|
|
175
|
+
potentially_breaking: 1,
|
|
176
|
+
breaking: 2
|
|
177
|
+
};
|
|
182
178
|
function diffModuleManifests(before, after) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
179
|
+
if (before.namespace !== after.namespace) return report([{
|
|
180
|
+
severity: "breaking",
|
|
181
|
+
path: "namespace",
|
|
182
|
+
code: "module_renamed",
|
|
183
|
+
message: `Module namespace changed from ${before.namespace} to ${after.namespace}.`
|
|
184
|
+
}]);
|
|
185
|
+
const changes = [];
|
|
186
|
+
if (before.version !== after.version) changes.push({
|
|
187
|
+
severity: "potentially_breaking",
|
|
188
|
+
path: "version",
|
|
189
|
+
code: "module_version_changed",
|
|
190
|
+
message: "Module version changed."
|
|
191
|
+
});
|
|
192
|
+
if (stableStringify(withoutWorkflows(before.capability)) !== stableStringify(withoutWorkflows(after.capability))) changes.push({
|
|
193
|
+
severity: "potentially_breaking",
|
|
194
|
+
path: "capability",
|
|
195
|
+
code: "capability_changed",
|
|
196
|
+
message: "Capability stability, requirements, extensions, deprecation, or certification metadata changed."
|
|
197
|
+
});
|
|
198
|
+
diffCapabilityWorkflows(before.capability?.workflows ?? [], after.capability?.workflows ?? [], changes);
|
|
199
|
+
diffStringList(before.subjectTypes, after.subjectTypes, "subjectTypes", changes);
|
|
200
|
+
diffNamed(before.idPrefixes, after.idPrefixes, "idPrefixes", "prefix", changes, (oldValue, newValue, path) => {
|
|
201
|
+
if (stableStringify(oldValue) !== stableStringify(newValue)) changes.push({
|
|
202
|
+
severity: "breaking",
|
|
203
|
+
path,
|
|
204
|
+
code: "id_prefix_changed",
|
|
205
|
+
message: "ID prefix ownership changed."
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
if (stableStringify(before.dependencies) !== stableStringify(after.dependencies)) changes.push({
|
|
209
|
+
severity: "potentially_breaking",
|
|
210
|
+
path: "dependencies",
|
|
211
|
+
code: "module_dependencies_changed",
|
|
212
|
+
message: "Module dependencies changed."
|
|
213
|
+
});
|
|
214
|
+
if (stableStringify(before.policies) !== stableStringify(after.policies)) changes.push({
|
|
215
|
+
severity: "potentially_breaking",
|
|
216
|
+
path: "policies",
|
|
217
|
+
code: "module_policies_changed",
|
|
218
|
+
message: "Module policy definitions changed."
|
|
219
|
+
});
|
|
220
|
+
diffNamed(before.objectTypes, after.objectTypes, "objectTypes", "type", changes, (oldValue, newValue, path) => {
|
|
221
|
+
diffSchema(oldValue.schema, newValue.schema, `${path}.schema`, changes);
|
|
222
|
+
const oldArchetype = oldValue.semantics?.["fabric.archetype"];
|
|
223
|
+
const newArchetype = newValue.semantics?.["fabric.archetype"];
|
|
224
|
+
if (oldArchetype && !newArchetype) changes.push({
|
|
225
|
+
severity: "breaking",
|
|
226
|
+
path: `${path}.semantics.fabric.archetype`,
|
|
227
|
+
code: "archetype_removed",
|
|
228
|
+
message: "Archetype certification metadata was removed."
|
|
229
|
+
});
|
|
230
|
+
else if (oldArchetype && newArchetype && stableStringify(oldArchetype) !== stableStringify(newArchetype)) changes.push({
|
|
231
|
+
severity: "breaking",
|
|
232
|
+
path: `${path}.semantics.fabric.archetype`,
|
|
233
|
+
code: "archetype_mapping_changed",
|
|
234
|
+
message: "Archetype identity, version, or state mapping changed."
|
|
235
|
+
});
|
|
236
|
+
diffNamed(oldValue.relations ?? [], newValue.relations ?? [], `${path}.relations`, "name", changes, (oldRelation, newRelation, relationPath) => {
|
|
237
|
+
if (oldRelation.cardinality !== newRelation.cardinality) changes.push({
|
|
238
|
+
severity: "breaking",
|
|
239
|
+
path: `${relationPath}.cardinality`,
|
|
240
|
+
code: "relation_cardinality_changed",
|
|
241
|
+
message: "Relation cardinality changed."
|
|
242
|
+
});
|
|
243
|
+
if (oldRelation.target !== newRelation.target) changes.push({
|
|
244
|
+
severity: "breaking",
|
|
245
|
+
path: `${relationPath}.target`,
|
|
246
|
+
code: "relation_target_changed",
|
|
247
|
+
message: "Relation target changed."
|
|
248
|
+
});
|
|
249
|
+
if (!oldRelation.required && newRelation.required) changes.push({
|
|
250
|
+
severity: "breaking",
|
|
251
|
+
path: `${relationPath}.required`,
|
|
252
|
+
code: "relation_became_required",
|
|
253
|
+
message: "Optional relation became required."
|
|
254
|
+
});
|
|
255
|
+
if (oldRelation.semantics !== newRelation.semantics) changes.push({
|
|
256
|
+
severity: "breaking",
|
|
257
|
+
path: `${relationPath}.semantics`,
|
|
258
|
+
code: "relation_ownership_changed",
|
|
259
|
+
message: "Relation ownership semantics changed."
|
|
260
|
+
});
|
|
261
|
+
if (oldRelation.onTargetDelete !== newRelation.onTargetDelete) changes.push({
|
|
262
|
+
severity: "breaking",
|
|
263
|
+
path: `${relationPath}.onTargetDelete`,
|
|
264
|
+
code: "relation_delete_behavior_changed",
|
|
265
|
+
message: "Relation deletion behavior changed."
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
diffNamed(oldValue.invariants ?? [], newValue.invariants ?? [], `${path}.invariants`, "id", changes, (oldInvariant, newInvariant, invariantPath) => {
|
|
269
|
+
if (oldInvariant.enforcement !== newInvariant.enforcement || oldInvariant.enforcementRef !== newInvariant.enforcementRef) changes.push({
|
|
270
|
+
severity: "potentially_breaking",
|
|
271
|
+
path: invariantPath,
|
|
272
|
+
code: "invariant_enforcement_changed",
|
|
273
|
+
message: "Invariant enforcement ownership or reference changed."
|
|
274
|
+
});
|
|
275
|
+
if (!oldInvariant.required && newInvariant.required) changes.push({
|
|
276
|
+
severity: "breaking",
|
|
277
|
+
path: `${invariantPath}.required`,
|
|
278
|
+
code: "invariant_became_required",
|
|
279
|
+
message: "Invariant became required."
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
diffNamed(before.actions, after.actions, "actions", "actionId", changes, (oldValue, newValue, path) => {
|
|
284
|
+
diffSchema(oldValue.parameterSchema, newValue.parameterSchema, `${path}.parameterSchema`, changes);
|
|
285
|
+
diffSchema(oldValue.resultSchema, newValue.resultSchema, `${path}.resultSchema`, changes);
|
|
286
|
+
if (stableStringify(oldValue.execution) !== stableStringify(newValue.execution)) changes.push({
|
|
287
|
+
severity: oldValue.execution ? "breaking" : "potentially_breaking",
|
|
288
|
+
path: `${path}.execution`,
|
|
289
|
+
code: "action_execution_changed",
|
|
290
|
+
message: "Action execution semantics changed and hosts or offline consumers must be reviewed."
|
|
291
|
+
});
|
|
292
|
+
for (const field of [
|
|
293
|
+
"version",
|
|
294
|
+
"kind",
|
|
295
|
+
"idempotent",
|
|
296
|
+
"mutatesDomain",
|
|
297
|
+
"eventPhase"
|
|
298
|
+
]) if (stableStringify(oldValue[field]) !== stableStringify(newValue[field])) changes.push({
|
|
299
|
+
severity: "breaking",
|
|
300
|
+
path: `${path}.${field}`,
|
|
301
|
+
code: `action_${field}_changed`,
|
|
302
|
+
message: `Action ${field} changed.`
|
|
303
|
+
});
|
|
304
|
+
const oldEvents = new Set(oldValue.emitsEvents);
|
|
305
|
+
const newEvents = new Set(newValue.emitsEvents);
|
|
306
|
+
for (const event of oldEvents) if (!newEvents.has(event)) changes.push({
|
|
307
|
+
severity: "breaking",
|
|
308
|
+
path: `${path}.emitsEvents.${event}`,
|
|
309
|
+
code: "action_event_removed",
|
|
310
|
+
message: `Declared action event "${event}" was removed.`
|
|
311
|
+
});
|
|
312
|
+
for (const event of newEvents) if (!oldEvents.has(event)) changes.push({
|
|
313
|
+
severity: "compatible",
|
|
314
|
+
path: `${path}.emitsEvents.${event}`,
|
|
315
|
+
code: "action_event_added",
|
|
316
|
+
message: `Declared action event "${event}" was added.`
|
|
317
|
+
});
|
|
318
|
+
for (const field of [
|
|
319
|
+
"policies",
|
|
320
|
+
"requiredRoles",
|
|
321
|
+
"requiredPermissions",
|
|
322
|
+
"stateMachine",
|
|
323
|
+
"adapterSteps",
|
|
324
|
+
"surface",
|
|
325
|
+
"surfaceReason"
|
|
326
|
+
]) if (stableStringify(oldValue[field]) !== stableStringify(newValue[field])) changes.push({
|
|
327
|
+
severity: "potentially_breaking",
|
|
328
|
+
path: `${path}.${field}`,
|
|
329
|
+
code: `action_${field}_changed`,
|
|
330
|
+
message: `Action ${field} changed and requires consumer review.`
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
diffNamed(before.eventTypes, after.eventTypes, "eventTypes", "eventType", changes, (oldValue, newValue, path) => {
|
|
334
|
+
diffEventSchema(oldValue.schema, newValue.schema, `${path}.schema`, changes);
|
|
335
|
+
if (oldValue.schemaVersion > newValue.schemaVersion) changes.push({
|
|
336
|
+
severity: "breaking",
|
|
337
|
+
path: `${path}.schemaVersion`,
|
|
338
|
+
code: "event_version_decreased",
|
|
339
|
+
message: "Event schema version decreased."
|
|
340
|
+
});
|
|
341
|
+
else if (oldValue.schemaVersion < newValue.schemaVersion) changes.push({
|
|
342
|
+
severity: "potentially_breaking",
|
|
343
|
+
path: `${path}.schemaVersion`,
|
|
344
|
+
code: "event_version_changed",
|
|
345
|
+
message: "Event schema version changed; old consumers require compatibility evidence."
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
const oldViews = new Map(before.views.map((view) => [`${view.name}@${view.version}`, view]));
|
|
349
|
+
const newViews = new Map(after.views.map((view) => [`${view.name}@${view.version}`, view]));
|
|
350
|
+
for (const [key, oldView] of oldViews) {
|
|
351
|
+
const newView = newViews.get(key);
|
|
352
|
+
if (!newView) changes.push({
|
|
353
|
+
severity: "breaking",
|
|
354
|
+
path: `views.${key}`,
|
|
355
|
+
code: "view_version_removed",
|
|
356
|
+
message: `View contract "${key}" was removed.`
|
|
357
|
+
});
|
|
358
|
+
else {
|
|
359
|
+
for (const field of ["surface", "surfaceReason"]) if (stableStringify(oldView[field]) !== stableStringify(newView[field])) changes.push({
|
|
360
|
+
severity: "potentially_breaking",
|
|
361
|
+
path: `views.${key}.${field}`,
|
|
362
|
+
code: `view_${field}_changed`,
|
|
363
|
+
message: `View ${field} changed and requires consumer review.`
|
|
364
|
+
});
|
|
365
|
+
diffSchema(oldView.shape, newView.shape, `views.${key}.shape`, changes);
|
|
366
|
+
diffSchema(oldView.parameterSchema, newView.parameterSchema, `views.${key}.parameterSchema`, changes);
|
|
367
|
+
if (stableStringify(oldView.usage) !== stableStringify(newView.usage)) changes.push({
|
|
368
|
+
severity: "potentially_breaking",
|
|
369
|
+
path: `views.${key}.usage`,
|
|
370
|
+
code: "view_usage_changed",
|
|
371
|
+
message: "View usage semantics changed and generated consumers require review."
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
for (const key of newViews.keys()) if (!oldViews.has(key)) changes.push({
|
|
376
|
+
severity: "compatible",
|
|
377
|
+
path: `views.${key}`,
|
|
378
|
+
code: "view_version_added",
|
|
379
|
+
message: `View contract "${key}" was added.`
|
|
380
|
+
});
|
|
381
|
+
diffNamed(before.stateMachines, after.stateMachines, "stateMachines", "entityType", changes, (oldValue, newValue, path) => {
|
|
382
|
+
const newStates = new Set(newValue.states.map((state) => state.id));
|
|
383
|
+
for (const state of oldValue.states) if (!newStates.has(state.id)) changes.push({
|
|
384
|
+
severity: "breaking",
|
|
385
|
+
path: `${path}.states.${state.id}`,
|
|
386
|
+
code: "state_removed",
|
|
387
|
+
message: `State "${state.id}" was removed.`
|
|
388
|
+
});
|
|
389
|
+
const transitions = new Set(newValue.transitions.map((transition) => `${transition.from}->${transition.to}`));
|
|
390
|
+
for (const transition of oldValue.transitions) if (!transitions.has(`${transition.from}->${transition.to}`)) changes.push({
|
|
391
|
+
severity: "breaking",
|
|
392
|
+
path: `${path}.transitions.${transition.from}->${transition.to}`,
|
|
393
|
+
code: "transition_removed",
|
|
394
|
+
message: "A state transition was removed or remapped."
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
return report(changes);
|
|
256
398
|
}
|
|
257
399
|
function withoutWorkflows(capability) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return rest;
|
|
400
|
+
if (!capability) return capability;
|
|
401
|
+
const { workflows, ...rest } = capability;
|
|
402
|
+
return rest;
|
|
262
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Durability is a contract, so its diff is classified rather than lumped into a
|
|
406
|
+
* single "capability changed": gaining a workflow is safe, losing one is not, and
|
|
407
|
+
* moving a queue or a deadline is a review.
|
|
408
|
+
*/
|
|
263
409
|
function diffCapabilityWorkflows(before, after, changes) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
410
|
+
const oldWorkflows = new Map(before.map((workflow) => [workflow.name, workflow]));
|
|
411
|
+
const newWorkflows = new Map(after.map((workflow) => [workflow.name, workflow]));
|
|
412
|
+
for (const [name, oldWorkflow] of oldWorkflows) {
|
|
413
|
+
const path = `capability.workflows.${name}`;
|
|
414
|
+
const newWorkflow = newWorkflows.get(name);
|
|
415
|
+
if (!newWorkflow) {
|
|
416
|
+
changes.push({
|
|
417
|
+
severity: "breaking",
|
|
418
|
+
path,
|
|
419
|
+
code: "workflow_removed",
|
|
420
|
+
message: `Declared workflow "${name}" was removed.`
|
|
421
|
+
});
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (oldWorkflow.taskQueue !== newWorkflow.taskQueue) changes.push({
|
|
425
|
+
severity: "potentially_breaking",
|
|
426
|
+
path: `${path}.taskQueue`,
|
|
427
|
+
code: "workflow_task_queue_changed",
|
|
428
|
+
message: `Workflow "${name}" moved from task queue "${oldWorkflow.taskQueue}" to "${newWorkflow.taskQueue}"; in-flight executions and worker routing require review.`
|
|
429
|
+
});
|
|
430
|
+
if (oldWorkflow.startedBy !== newWorkflow.startedBy) changes.push({
|
|
431
|
+
severity: "potentially_breaking",
|
|
432
|
+
path: `${path}.startedBy`,
|
|
433
|
+
code: "workflow_trigger_changed",
|
|
434
|
+
message: `Workflow "${name}" changed the event that starts it.`
|
|
435
|
+
});
|
|
436
|
+
const oldTimers = new Map((oldWorkflow.timers ?? []).map((timer) => [timer.name, timer]));
|
|
437
|
+
const newTimers = new Map((newWorkflow.timers ?? []).map((timer) => [timer.name, timer]));
|
|
438
|
+
for (const [timerName, oldTimer] of oldTimers) {
|
|
439
|
+
const timerPath = `${path}.timers.${timerName}`;
|
|
440
|
+
const newTimer = newTimers.get(timerName);
|
|
441
|
+
if (!newTimer) {
|
|
442
|
+
changes.push({
|
|
443
|
+
severity: "potentially_breaking",
|
|
444
|
+
path: timerPath,
|
|
445
|
+
code: "workflow_timer_removed",
|
|
446
|
+
message: `Workflow "${name}" no longer carries the deadline "${timerName}".`
|
|
447
|
+
});
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (oldTimer.configKey !== newTimer.configKey) changes.push({
|
|
451
|
+
severity: "potentially_breaking",
|
|
452
|
+
path: `${timerPath}.configKey`,
|
|
453
|
+
code: "workflow_timer_config_changed",
|
|
454
|
+
message: `Deadline "${timerName}" now resolves from configuration key "${newTimer.configKey}".`
|
|
455
|
+
});
|
|
456
|
+
if (oldTimer.description !== newTimer.description) changes.push({
|
|
457
|
+
severity: "compatible",
|
|
458
|
+
path: `${timerPath}.description`,
|
|
459
|
+
code: "workflow_timer_description_changed",
|
|
460
|
+
message: `Deadline "${timerName}" changed its description.`
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
for (const timerName of newTimers.keys()) if (!oldTimers.has(timerName)) changes.push({
|
|
464
|
+
severity: "compatible",
|
|
465
|
+
path: `${path}.timers.${timerName}`,
|
|
466
|
+
code: "workflow_timer_added",
|
|
467
|
+
message: `Workflow "${name}" gained the deadline "${timerName}".`
|
|
468
|
+
});
|
|
469
|
+
const oldCompensations = new Map((oldWorkflow.compensations ?? []).map((compensation) => [compensation.step, compensation]));
|
|
470
|
+
const newCompensations = new Map((newWorkflow.compensations ?? []).map((compensation) => [compensation.step, compensation]));
|
|
471
|
+
for (const [step, oldCompensation] of oldCompensations) {
|
|
472
|
+
const stepPath = `${path}.compensations.${step}`;
|
|
473
|
+
const newCompensation = newCompensations.get(step);
|
|
474
|
+
if (!newCompensation) {
|
|
475
|
+
changes.push({
|
|
476
|
+
severity: "breaking",
|
|
477
|
+
path: stepPath,
|
|
478
|
+
code: "workflow_compensation_removed",
|
|
479
|
+
message: `Workflow "${name}" no longer reverses step "${step}".`
|
|
480
|
+
});
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (oldCompensation.actionId !== newCompensation.actionId) changes.push({
|
|
484
|
+
severity: "potentially_breaking",
|
|
485
|
+
path: `${stepPath}.actionId`,
|
|
486
|
+
code: "workflow_compensation_changed",
|
|
487
|
+
message: `Step "${step}" is now reversed by "${newCompensation.actionId}".`
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
for (const step of newCompensations.keys()) if (!oldCompensations.has(step)) changes.push({
|
|
491
|
+
severity: "compatible",
|
|
492
|
+
path: `${path}.compensations.${step}`,
|
|
493
|
+
code: "workflow_compensation_added",
|
|
494
|
+
message: `Workflow "${name}" gained a reversal for step "${step}".`
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
for (const name of newWorkflows.keys()) if (!oldWorkflows.has(name)) changes.push({
|
|
498
|
+
severity: "compatible",
|
|
499
|
+
path: `capability.workflows.${name}`,
|
|
500
|
+
code: "workflow_added",
|
|
501
|
+
message: `Workflow "${name}" was added.`
|
|
502
|
+
});
|
|
302
503
|
}
|
|
303
|
-
function diffEventSchema(before, after,
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
504
|
+
function diffEventSchema(before, after, path, changes) {
|
|
505
|
+
const start = changes.length;
|
|
506
|
+
diffSchema(before, after, path, changes);
|
|
507
|
+
for (let index = start; index < changes.length; index += 1) {
|
|
508
|
+
const change = changes[index];
|
|
509
|
+
change.code = `event_${change.code}`;
|
|
510
|
+
change.message = `Event schema: ${change.message}`;
|
|
511
|
+
}
|
|
311
512
|
}
|
|
312
|
-
function diffStringList(before, after,
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
513
|
+
function diffStringList(before, after, path, changes) {
|
|
514
|
+
const oldValues = new Set(before);
|
|
515
|
+
const newValues = new Set(after);
|
|
516
|
+
for (const value of oldValues) if (!newValues.has(value)) changes.push({
|
|
517
|
+
severity: "breaking",
|
|
518
|
+
path: `${path}.${value}`,
|
|
519
|
+
code: `${path}_removed`,
|
|
520
|
+
message: `Public ${path} value "${value}" was removed.`
|
|
521
|
+
});
|
|
522
|
+
for (const value of newValues) if (!oldValues.has(value)) changes.push({
|
|
523
|
+
severity: "compatible",
|
|
524
|
+
path: `${path}.${value}`,
|
|
525
|
+
code: `${path}_added`,
|
|
526
|
+
message: `Public ${path} value "${value}" was added.`
|
|
527
|
+
});
|
|
317
528
|
}
|
|
318
|
-
function diffNamed(before, after,
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
529
|
+
function diffNamed(before, after, path, key, changes, compare) {
|
|
530
|
+
const oldMap = new Map(before.map((value) => [String(value[key]), value]));
|
|
531
|
+
const newMap = new Map(after.map((value) => [String(value[key]), value]));
|
|
532
|
+
for (const [name, value] of oldMap) {
|
|
533
|
+
const next = newMap.get(name);
|
|
534
|
+
if (!next) changes.push({
|
|
535
|
+
severity: "breaking",
|
|
536
|
+
path: `${path}.${name}`,
|
|
537
|
+
code: `${String(key)}_removed`,
|
|
538
|
+
message: `${String(key)} "${name}" was removed.`
|
|
539
|
+
});
|
|
540
|
+
else compare(value, next, `${path}.${name}`);
|
|
541
|
+
}
|
|
542
|
+
for (const name of newMap.keys()) if (!oldMap.has(name)) changes.push({
|
|
543
|
+
severity: "compatible",
|
|
544
|
+
path: `${path}.${name}`,
|
|
545
|
+
code: `${String(key)}_added`,
|
|
546
|
+
message: `${String(key)} "${name}" was added.`
|
|
547
|
+
});
|
|
327
548
|
}
|
|
328
|
-
function diffSchema(before, after,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
549
|
+
function diffSchema(before, after, path, changes) {
|
|
550
|
+
const changeCount = changes.length;
|
|
551
|
+
if (!before && after) {
|
|
552
|
+
changes.push({
|
|
553
|
+
severity: "potentially_breaking",
|
|
554
|
+
path,
|
|
555
|
+
code: "schema_added",
|
|
556
|
+
message: "A schema was added to an existing contract."
|
|
557
|
+
});
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if (before && !after) {
|
|
561
|
+
changes.push({
|
|
562
|
+
severity: "breaking",
|
|
563
|
+
path,
|
|
564
|
+
code: "schema_removed",
|
|
565
|
+
message: "An existing schema was removed."
|
|
566
|
+
});
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (!before || !after) return;
|
|
570
|
+
const oldRequired = new Set(before.required ?? []);
|
|
571
|
+
for (const required of after.required ?? []) if (!oldRequired.has(required)) changes.push({
|
|
572
|
+
severity: "breaking",
|
|
573
|
+
path: `${path}.required.${required}`,
|
|
574
|
+
code: "required_property_added",
|
|
575
|
+
message: `Required property "${required}" was added.`
|
|
576
|
+
});
|
|
577
|
+
const oldProperties = before.properties ?? {};
|
|
578
|
+
const newProperties = after.properties ?? {};
|
|
579
|
+
for (const property of Object.keys(oldProperties)) if (!(property in newProperties)) changes.push({
|
|
580
|
+
severity: "breaking",
|
|
581
|
+
path: `${path}.properties.${property}`,
|
|
582
|
+
code: "schema_property_removed",
|
|
583
|
+
message: `Schema property "${property}" was removed.`
|
|
584
|
+
});
|
|
585
|
+
for (const property of Object.keys(newProperties)) if (!(property in oldProperties)) changes.push({
|
|
586
|
+
severity: (after.required ?? []).includes(property) ? "breaking" : "compatible",
|
|
587
|
+
path: `${path}.properties.${property}`,
|
|
588
|
+
code: "schema_property_added",
|
|
589
|
+
message: `Schema property "${property}" was added.`
|
|
590
|
+
});
|
|
591
|
+
for (const property of Object.keys(oldProperties)) if (newProperties[property]) diffSchema(oldProperties[property], newProperties[property], `${path}.properties.${property}`, changes);
|
|
592
|
+
if (before.additionalProperties !== false && after.additionalProperties === false) changes.push({
|
|
593
|
+
severity: "breaking",
|
|
594
|
+
path: `${path}.additionalProperties`,
|
|
595
|
+
code: "additional_properties_forbidden",
|
|
596
|
+
message: "Schema now rejects undeclared properties."
|
|
597
|
+
});
|
|
598
|
+
if (before.items && after.items && !Array.isArray(before.items) && !Array.isArray(after.items)) diffSchema(before.items, after.items, `${path}.items`, changes);
|
|
599
|
+
for (const keyword of [
|
|
600
|
+
"minimum",
|
|
601
|
+
"maximum",
|
|
602
|
+
"minLength",
|
|
603
|
+
"maxLength",
|
|
604
|
+
"pattern"
|
|
605
|
+
]) if (stableStringify(before[keyword]) !== stableStringify(after[keyword])) changes.push({
|
|
606
|
+
severity: "potentially_breaking",
|
|
607
|
+
path: `${path}.${keyword}`,
|
|
608
|
+
code: "schema_constraint_changed",
|
|
609
|
+
message: `Schema constraint "${keyword}" changed.`
|
|
610
|
+
});
|
|
611
|
+
if (stableStringify(before.type) !== stableStringify(after.type)) {
|
|
612
|
+
const oldTypes = new Set(Array.isArray(before.type) ? before.type : before.type ? [before.type] : []);
|
|
613
|
+
const newTypes = new Set(Array.isArray(after.type) ? after.type : after.type ? [after.type] : []);
|
|
614
|
+
const widened = oldTypes.size > 0 && [...oldTypes].every((type) => newTypes.has(type));
|
|
615
|
+
changes.push({
|
|
616
|
+
severity: "breaking",
|
|
617
|
+
path: `${path}.type`,
|
|
618
|
+
code: widened ? "schema_type_widened" : "schema_type_narrowed",
|
|
619
|
+
message: widened ? "Schema type widened; generated consumers may receive a new value type." : "Schema type no longer accepts every prior type."
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
if (before.enum && after.enum && before.enum.some((value) => !after.enum.some((newValue) => stableStringify(newValue) === stableStringify(value)))) changes.push({
|
|
623
|
+
severity: "breaking",
|
|
624
|
+
path: `${path}.enum`,
|
|
625
|
+
code: "schema_enum_narrowed",
|
|
626
|
+
message: "Schema enum no longer accepts a previously valid value."
|
|
627
|
+
});
|
|
628
|
+
if (stableStringify(before) !== stableStringify(after) && changes.length === changeCount) changes.push({
|
|
629
|
+
severity: "potentially_breaking",
|
|
630
|
+
path,
|
|
631
|
+
code: "schema_changed",
|
|
632
|
+
message: "Schema changed and requires consumer review."
|
|
633
|
+
});
|
|
363
634
|
}
|
|
364
635
|
function report(changes) {
|
|
365
|
-
|
|
366
|
-
|
|
636
|
+
const highestSeverity = changes.reduce((highest, change) => severityRank[change.severity] > severityRank[highest] ? change.severity : highest, "compatible");
|
|
637
|
+
return {
|
|
638
|
+
compatible: highestSeverity === "compatible",
|
|
639
|
+
highestSeverity,
|
|
640
|
+
changes
|
|
641
|
+
};
|
|
367
642
|
}
|
|
368
643
|
async function runGenerator(target, ir) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
644
|
+
const files = await target.generate(ir);
|
|
645
|
+
const paths = /* @__PURE__ */ new Set();
|
|
646
|
+
return [...files].sort((left, right) => compareCanonicalStrings(left.path, right.path)).map((file) => {
|
|
647
|
+
if (!file.path || path.default.isAbsolute(file.path) || path.default.win32.isAbsolute(file.path) || file.path.includes("\\") || file.path.split("/").includes("..")) throw new Error(`Generator "${target.name}" returned unsafe path "${file.path}".`);
|
|
648
|
+
if (paths.has(file.path)) throw new Error(`Generator "${target.name}" returned duplicate path "${file.path}".`);
|
|
649
|
+
paths.add(file.path);
|
|
650
|
+
return {
|
|
651
|
+
path: file.path,
|
|
652
|
+
content: file.content.endsWith("\n") ? file.content : `${file.content}\n`
|
|
653
|
+
};
|
|
654
|
+
});
|
|
378
655
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
});
|
|
656
|
+
//#endregion
|
|
657
|
+
exports.FABRIC_COMPILER_VERSION = FABRIC_COMPILER_VERSION;
|
|
658
|
+
exports.compareCanonicalStrings = compareCanonicalStrings;
|
|
659
|
+
exports.compileManifestBundle = compileManifestBundle;
|
|
660
|
+
exports.diffModuleManifests = diffModuleManifests;
|
|
661
|
+
exports.runGenerator = runGenerator;
|
|
662
|
+
exports.stableStringify = stableStringify;
|
|
663
|
+
|
|
388
664
|
//# sourceMappingURL=index.cjs.map
|