@fabricorg/compiler 2.2.8 → 2.2.9

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