@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.cjs CHANGED
@@ -1,388 +1,664 @@
1
- "use strict";
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
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // index.ts
31
- var index_exports = {};
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.9";
30
+ const compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
46
31
  function stableStringify(value) {
47
- return JSON.stringify(sortJson(value));
32
+ return JSON.stringify(sortJson(value));
48
33
  }
49
34
  function sortJson(value) {
50
- if (Array.isArray(value)) return value.map(sortJson);
51
- if (value && typeof value === "object") {
52
- return Object.fromEntries(
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
- const bundle = (0, import_platform.normalizeModuleManifestBundle)(input);
60
- const namespaces = /* @__PURE__ */ new Set();
61
- for (const module2 of bundle.modules) {
62
- if (namespaces.has(module2.namespace)) throw new Error(`Duplicate module namespace "${module2.namespace}" in compiler input.`);
63
- namespaces.add(module2.namespace);
64
- }
65
- const modules = [...bundle.modules].sort((left, right) => compareCanonicalStrings(left.namespace, right.namespace));
66
- assertCompilerManifests(modules, options.certificationProfiles ?? []);
67
- const canonical = stableStringify({ manifestVersion: bundle.manifestVersion, modules });
68
- return {
69
- compilerVersion: FABRIC_COMPILER_VERSION,
70
- manifestVersion: bundle.manifestVersion,
71
- manifestDigest: (0, import_node_crypto.createHash)("sha256").update(canonical).digest("hex"),
72
- modules,
73
- conformance: (options.conformanceAdapters ?? []).flatMap(
74
- (adapter) => modules.map((module2) => ({ adapterId: adapter.id, moduleNamespace: module2.namespace, findings: adapter.evaluate(module2) }))
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
- function assertManifestWorkflows(module2) {
79
- for (const action of module2.actions) {
80
- if (action.execution?.completion === "immediate" && action.kind === "saga") {
81
- throw new Error(`Action "${action.actionId}" declares immediate completion but is a multi-step saga.`);
82
- }
83
- }
84
- const actionsById = new Map(module2.actions.map((action) => [action.actionId, action]));
85
- const names = /* @__PURE__ */ new Set();
86
- for (const workflow of module2.capability?.workflows ?? []) {
87
- if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(workflow.name)) throw new Error(`Module "${module2.namespace}" declares invalid workflow name "${workflow.name}".`);
88
- if (names.has(workflow.name)) throw new Error(`Module "${module2.namespace}" declares duplicate workflow "${workflow.name}".`);
89
- names.add(workflow.name);
90
- if (!/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*$/.test(workflow.taskQueue)) throw new Error(`Module "${module2.namespace}" workflow "${workflow.name}" declares invalid task queue "${workflow.taskQueue}".`);
91
- const timerNames = /* @__PURE__ */ new Set();
92
- for (const timer of workflow.timers ?? []) {
93
- if (!timer.name?.trim() || !timer.configKey?.trim()) throw new Error(`Module "${module2.namespace}" workflow "${workflow.name}" has a timer without a name or configKey.`);
94
- if (timerNames.has(timer.name)) throw new Error(`Module "${module2.namespace}" workflow "${workflow.name}" declares duplicate timer "${timer.name}".`);
95
- timerNames.add(timer.name);
96
- }
97
- const steps = /* @__PURE__ */ new Set();
98
- for (const compensation of workflow.compensations ?? []) {
99
- if (steps.has(compensation.step)) throw new Error(`Module "${module2.namespace}" workflow "${workflow.name}" declares duplicate compensation for step "${compensation.step}".`);
100
- steps.add(compensation.step);
101
- const compensating = actionsById.get(compensation.actionId);
102
- if (!compensating) throw new Error(`Module "${module2.namespace}" workflow "${workflow.name}" compensates step "${compensation.step}" with unknown action "${compensation.actionId}".`);
103
- if (!compensating.idempotent) throw new Error(`Module "${module2.namespace}" workflow "${workflow.name}" compensates step "${compensation.step}" with non-idempotent action "${compensation.actionId}"; a reversal must be safely repeatable.`);
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
- const profiles = new Map(certificationProfiles.map((profile) => [profile.id, profile]));
109
- if (profiles.size !== certificationProfiles.length) throw new Error("Certification profile IDs must be unique.");
110
- for (const [moduleIndex, module2] of modules.entries()) {
111
- const at = `modules[${moduleIndex}]`;
112
- if (!module2 || typeof module2 !== "object") throw new Error(`${at} ${describeValue(module2)}; a compiler module must be the object returned by exportModuleManifest().`);
113
- if (!/^[a-z][a-z0-9-]*$/.test(module2.namespace)) throw new Error(`${at}.namespace ${describeValue(module2.namespace)}; a namespace is lowercase letters, digits, and hyphens, such as "orders".`);
114
- for (const field of ["objectTypes", "actions"]) {
115
- if (!Array.isArray(module2[field])) throw new Error(`${at} ("${module2.namespace}") .${field} ${describeValue(module2[field])}; it must be an array. exportModuleManifest() fills every array, so a missing one usually means the manifest was hand-written rather than exported.`);
116
- }
117
- }
118
- for (const module2 of modules) assertManifestWorkflows(module2);
119
- const targets = new Set(modules.flatMap((module2) => module2.objectTypes.map((objectType) => `${module2.namespace}.${objectType.type}`)));
120
- for (const module2 of modules) {
121
- if (module2.capability) {
122
- if (!module2.capability.displayName?.trim() || !module2.capability.description?.trim()) throw new Error(`Module "${module2.namespace}" capability requires displayName and description.`);
123
- if (!["experimental", "beta", "stable", "deprecated"].includes(module2.capability.stability)) throw new Error(`Module "${module2.namespace}" capability has invalid stability.`);
124
- }
125
- const certification = module2.capability?.certification;
126
- const profile = certification?.required ? profiles.get(certification.profile) : void 0;
127
- for (const objectType of module2.objectTypes) {
128
- if (!/^[A-Z][A-Za-z0-9]*$/.test(objectType.type)) throw new Error(`Invalid object type at ${module2.namespace}.objectTypes[${module2.objectTypes.indexOf(objectType)}].type: ${describeValue(objectType.type)}; it must be PascalCase alphanumeric, such as "ServiceVisit".`);
129
- if (objectType.schema) (0, import_platform.assertPortableJsonSchema)(objectType.schema, `${module2.namespace}.${objectType.type}`);
130
- for (const relation of objectType.relations ?? []) if (!targets.has(relation.target)) throw new Error(`Relation ${module2.namespace}.${objectType.type}.${relation.name} targets missing object type "${relation.target}".`);
131
- for (const invariant of objectType.invariants ?? []) {
132
- if (invariant.required && !resolvesRequiredInvariant(module2, objectType, invariant, profile)) {
133
- throw new Error(`Required invariant "${module2.namespace}.${objectType.type}.${invariant.id}" has no resolvable enforcement evidence under certification profile "${certification?.profile ?? "none"}".`);
134
- }
135
- }
136
- }
137
- for (const view of module2.views) {
138
- if (!view.name.startsWith(`${module2.namespace}/`)) throw new Error(`View "${view.name}" must use module namespace "${module2.namespace}/".`);
139
- (0, import_platform.assertPortableJsonSchema)(view.shape, `View ${view.name}@${view.version}`);
140
- if (view.parameterSchema !== void 0) (0, import_platform.assertPortableJsonSchema)(view.parameterSchema, `View ${view.name}@${view.version} parameters`);
141
- if (view.usage?.collection?.filterSchema) (0, import_platform.assertPortableJsonSchema)(view.usage.collection.filterSchema, `View ${view.name}@${view.version} filter`);
142
- }
143
- for (const eventType of module2.eventTypes) if (eventType.schema) (0, import_platform.assertPortableJsonSchema)(eventType.schema, `Event ${eventType.eventType}@${eventType.schemaVersion}`);
144
- for (const [actionIndex, action] of module2.actions.entries()) {
145
- const at = `${module2.namespace}.actions[${actionIndex}]`;
146
- 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 "${module2.namespace}.approve_order".`);
147
- if (!action.actionId.startsWith(`${module2.namespace}.`)) throw new Error(`${at}.actionId "${action.actionId}" must start with its own module namespace "${module2.namespace}.".`);
148
- if (!["atomic", "saga"].includes(action.kind)) throw new Error(`Action "${action.actionId}" kind ${describeValue(action.kind)}; it must be "atomic" or "saga".`);
149
- if (typeof action.idempotent !== "boolean") throw new Error(`Action "${action.actionId}" idempotent ${describeValue(action.idempotent)}; it must be true or false.`);
150
- if (typeof action.mutatesDomain !== "boolean") throw new Error(`Action "${action.actionId}" mutatesDomain ${describeValue(action.mutatesDomain)}; it must be true or false.`);
151
- 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.`);
152
- if (action.parameterSchema) (0, import_platform.assertPortableJsonSchema)(action.parameterSchema, `Action ${action.actionId} parameters`);
153
- if (action.resultSchema) (0, import_platform.assertPortableJsonSchema)(action.resultSchema, `Action ${action.actionId} result`);
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
- if (value === void 0) return "is missing";
159
- if (value === null) return "is null";
160
- if (Array.isArray(value)) return `is an array of ${value.length}`;
161
- if (typeof value === "object") return "is an object";
162
- return `is ${JSON.stringify(value)}`;
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(module2, objectType, invariant, profile) {
165
- const reference = invariant.enforcementRef?.trim();
166
- if (!reference) return false;
167
- if (invariant.enforcement === "json-schema") {
168
- const requiredMatch = /^#\/required\/([^/]+)$/.exec(reference);
169
- if (requiredMatch) return Array.isArray(objectType.schema?.required) && objectType.schema.required.includes(decodeJsonPointerToken(requiredMatch[1]));
170
- const propertyMatch = /^#\/properties\/([^/]+)$/.exec(reference);
171
- if (propertyMatch) return Boolean(objectType.schema?.properties?.[decodeJsonPointerToken(propertyMatch[1])]);
172
- return false;
173
- }
174
- if (invariant.enforcement === "state-machine") return module2.stateMachines.some((machine) => machine.entityType === reference);
175
- if (invariant.enforcement === "policy") return module2.policies.some((policy) => policy.policyId === reference);
176
- return profile?.resolveInvariant?.({ module: module2, objectType, invariant }) === true;
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
- return token.replace(/~1/g, "/").replace(/~0/g, "~");
171
+ return token.replace(/~1/g, "/").replace(/~0/g, "~");
180
172
  }
181
- var severityRank = { compatible: 0, potentially_breaking: 1, breaking: 2 };
173
+ const severityRank = {
174
+ compatible: 0,
175
+ potentially_breaking: 1,
176
+ breaking: 2
177
+ };
182
178
  function diffModuleManifests(before, after) {
183
- if (before.namespace !== after.namespace) {
184
- return report([{ severity: "breaking", path: "namespace", code: "module_renamed", message: `Module namespace changed from ${before.namespace} to ${after.namespace}.` }]);
185
- }
186
- const changes = [];
187
- if (before.version !== after.version) changes.push({ severity: "potentially_breaking", path: "version", code: "module_version_changed", message: "Module version changed." });
188
- 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." });
189
- diffCapabilityWorkflows(before.capability?.workflows ?? [], after.capability?.workflows ?? [], changes);
190
- diffStringList(before.subjectTypes, after.subjectTypes, "subjectTypes", changes);
191
- diffNamed(before.idPrefixes, after.idPrefixes, "idPrefixes", "prefix", changes, (oldValue, newValue, path2) => {
192
- if (stableStringify(oldValue) !== stableStringify(newValue)) changes.push({ severity: "breaking", path: path2, code: "id_prefix_changed", message: "ID prefix ownership changed." });
193
- });
194
- if (stableStringify(before.dependencies) !== stableStringify(after.dependencies)) changes.push({ severity: "potentially_breaking", path: "dependencies", code: "module_dependencies_changed", message: "Module dependencies changed." });
195
- if (stableStringify(before.policies) !== stableStringify(after.policies)) changes.push({ severity: "potentially_breaking", path: "policies", code: "module_policies_changed", message: "Module policy definitions changed." });
196
- diffNamed(before.objectTypes, after.objectTypes, "objectTypes", "type", changes, (oldValue, newValue, path2) => {
197
- diffSchema(oldValue.schema, newValue.schema, `${path2}.schema`, changes);
198
- const oldArchetype = oldValue.semantics?.["fabric.archetype"];
199
- const newArchetype = newValue.semantics?.["fabric.archetype"];
200
- if (oldArchetype && !newArchetype) changes.push({ severity: "breaking", path: `${path2}.semantics.fabric.archetype`, code: "archetype_removed", message: "Archetype certification metadata was removed." });
201
- 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." });
202
- diffNamed(oldValue.relations ?? [], newValue.relations ?? [], `${path2}.relations`, "name", changes, (oldRelation, newRelation, relationPath) => {
203
- if (oldRelation.cardinality !== newRelation.cardinality) changes.push({ severity: "breaking", path: `${relationPath}.cardinality`, code: "relation_cardinality_changed", message: "Relation cardinality changed." });
204
- if (oldRelation.target !== newRelation.target) changes.push({ severity: "breaking", path: `${relationPath}.target`, code: "relation_target_changed", message: "Relation target changed." });
205
- if (!oldRelation.required && newRelation.required) changes.push({ severity: "breaking", path: `${relationPath}.required`, code: "relation_became_required", message: "Optional relation became required." });
206
- if (oldRelation.semantics !== newRelation.semantics) changes.push({ severity: "breaking", path: `${relationPath}.semantics`, code: "relation_ownership_changed", message: "Relation ownership semantics changed." });
207
- if (oldRelation.onTargetDelete !== newRelation.onTargetDelete) changes.push({ severity: "breaking", path: `${relationPath}.onTargetDelete`, code: "relation_delete_behavior_changed", message: "Relation deletion behavior changed." });
208
- });
209
- diffNamed(oldValue.invariants ?? [], newValue.invariants ?? [], `${path2}.invariants`, "id", changes, (oldInvariant, newInvariant, invariantPath) => {
210
- 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." });
211
- if (!oldInvariant.required && newInvariant.required) changes.push({ severity: "breaking", path: `${invariantPath}.required`, code: "invariant_became_required", message: "Invariant became required." });
212
- });
213
- });
214
- diffNamed(before.actions, after.actions, "actions", "actionId", changes, (oldValue, newValue, path2) => {
215
- diffSchema(oldValue.parameterSchema, newValue.parameterSchema, `${path2}.parameterSchema`, changes);
216
- diffSchema(oldValue.resultSchema, newValue.resultSchema, `${path2}.resultSchema`, changes);
217
- 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." });
218
- for (const field of ["version", "kind", "idempotent", "mutatesDomain", "eventPhase"]) {
219
- if (stableStringify(oldValue[field]) !== stableStringify(newValue[field])) changes.push({ severity: "breaking", path: `${path2}.${field}`, code: `action_${field}_changed`, message: `Action ${field} changed.` });
220
- }
221
- const oldEvents = new Set(oldValue.emitsEvents);
222
- const newEvents = new Set(newValue.emitsEvents);
223
- 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.` });
224
- 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.` });
225
- for (const field of ["policies", "requiredRoles", "requiredPermissions", "stateMachine", "adapterSteps", "surface", "surfaceReason"]) {
226
- 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.` });
227
- }
228
- });
229
- diffNamed(before.eventTypes, after.eventTypes, "eventTypes", "eventType", changes, (oldValue, newValue, path2) => {
230
- diffEventSchema(oldValue.schema, newValue.schema, `${path2}.schema`, changes);
231
- if (oldValue.schemaVersion > newValue.schemaVersion) changes.push({ severity: "breaking", path: `${path2}.schemaVersion`, code: "event_version_decreased", message: "Event schema version decreased." });
232
- 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." });
233
- });
234
- const oldViews = new Map(before.views.map((view) => [`${view.name}@${view.version}`, view]));
235
- const newViews = new Map(after.views.map((view) => [`${view.name}@${view.version}`, view]));
236
- for (const [key, oldView] of oldViews) {
237
- const newView = newViews.get(key);
238
- if (!newView) changes.push({ severity: "breaking", path: `views.${key}`, code: "view_version_removed", message: `View contract "${key}" was removed.` });
239
- else {
240
- for (const field of ["surface", "surfaceReason"]) {
241
- 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.` });
242
- }
243
- diffSchema(oldView.shape, newView.shape, `views.${key}.shape`, changes);
244
- diffSchema(oldView.parameterSchema, newView.parameterSchema, `views.${key}.parameterSchema`, changes);
245
- 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." });
246
- }
247
- }
248
- 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.` });
249
- diffNamed(before.stateMachines, after.stateMachines, "stateMachines", "entityType", changes, (oldValue, newValue, path2) => {
250
- const newStates = new Set(newValue.states.map((state) => state.id));
251
- 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.` });
252
- const transitions = new Set(newValue.transitions.map((transition) => `${transition.from}->${transition.to}`));
253
- 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." });
254
- });
255
- return report(changes);
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
- if (!capability) return capability;
259
- const { workflows, ...rest } = capability;
260
- void workflows;
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
- const oldWorkflows = new Map(before.map((workflow) => [workflow.name, workflow]));
265
- const newWorkflows = new Map(after.map((workflow) => [workflow.name, workflow]));
266
- for (const [name, oldWorkflow] of oldWorkflows) {
267
- const path2 = `capability.workflows.${name}`;
268
- const newWorkflow = newWorkflows.get(name);
269
- if (!newWorkflow) {
270
- changes.push({ severity: "breaking", path: path2, code: "workflow_removed", message: `Declared workflow "${name}" was removed.` });
271
- continue;
272
- }
273
- 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.` });
274
- 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.` });
275
- const oldTimers = new Map((oldWorkflow.timers ?? []).map((timer) => [timer.name, timer]));
276
- const newTimers = new Map((newWorkflow.timers ?? []).map((timer) => [timer.name, timer]));
277
- for (const [timerName, oldTimer] of oldTimers) {
278
- const timerPath = `${path2}.timers.${timerName}`;
279
- const newTimer = newTimers.get(timerName);
280
- if (!newTimer) {
281
- changes.push({ severity: "potentially_breaking", path: timerPath, code: "workflow_timer_removed", message: `Workflow "${name}" no longer carries the deadline "${timerName}".` });
282
- continue;
283
- }
284
- 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}".` });
285
- if (oldTimer.description !== newTimer.description) changes.push({ severity: "compatible", path: `${timerPath}.description`, code: "workflow_timer_description_changed", message: `Deadline "${timerName}" changed its description.` });
286
- }
287
- 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}".` });
288
- const oldCompensations = new Map((oldWorkflow.compensations ?? []).map((compensation) => [compensation.step, compensation]));
289
- const newCompensations = new Map((newWorkflow.compensations ?? []).map((compensation) => [compensation.step, compensation]));
290
- for (const [step, oldCompensation] of oldCompensations) {
291
- const stepPath = `${path2}.compensations.${step}`;
292
- const newCompensation = newCompensations.get(step);
293
- if (!newCompensation) {
294
- changes.push({ severity: "breaking", path: stepPath, code: "workflow_compensation_removed", message: `Workflow "${name}" no longer reverses step "${step}".` });
295
- continue;
296
- }
297
- 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}".` });
298
- }
299
- 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}".` });
300
- }
301
- 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.` });
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, path2, changes) {
304
- const start = changes.length;
305
- diffSchema(before, after, path2, changes);
306
- for (let index = start; index < changes.length; index += 1) {
307
- const change = changes[index];
308
- change.code = `event_${change.code}`;
309
- change.message = `Event schema: ${change.message}`;
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, path2, changes) {
313
- const oldValues = new Set(before);
314
- const newValues = new Set(after);
315
- 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.` });
316
- 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.` });
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, path2, key, changes, compare) {
319
- const oldMap = new Map(before.map((value) => [String(value[key]), value]));
320
- const newMap = new Map(after.map((value) => [String(value[key]), value]));
321
- for (const [name, value] of oldMap) {
322
- const next = newMap.get(name);
323
- if (!next) changes.push({ severity: "breaking", path: `${path2}.${name}`, code: `${String(key)}_removed`, message: `${String(key)} "${name}" was removed.` });
324
- else compare(value, next, `${path2}.${name}`);
325
- }
326
- 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.` });
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, path2, changes) {
329
- const changeCount = changes.length;
330
- if (!before && after) {
331
- changes.push({ severity: "potentially_breaking", path: path2, code: "schema_added", message: "A schema was added to an existing contract." });
332
- return;
333
- }
334
- if (before && !after) {
335
- changes.push({ severity: "breaking", path: path2, code: "schema_removed", message: "An existing schema was removed." });
336
- return;
337
- }
338
- if (!before || !after) return;
339
- const oldRequired = new Set(before.required ?? []);
340
- 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.` });
341
- const oldProperties = before.properties ?? {};
342
- const newProperties = after.properties ?? {};
343
- 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.` });
344
- 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.` });
345
- for (const property of Object.keys(oldProperties)) {
346
- if (newProperties[property]) diffSchema(oldProperties[property], newProperties[property], `${path2}.properties.${property}`, changes);
347
- }
348
- if (before.additionalProperties !== false && after.additionalProperties === false) changes.push({ severity: "breaking", path: `${path2}.additionalProperties`, code: "additional_properties_forbidden", message: "Schema now rejects undeclared properties." });
349
- if (before.items && after.items && !Array.isArray(before.items) && !Array.isArray(after.items)) diffSchema(before.items, after.items, `${path2}.items`, changes);
350
- for (const keyword of ["minimum", "maximum", "minLength", "maxLength", "pattern"]) {
351
- if (stableStringify(before[keyword]) !== stableStringify(after[keyword])) changes.push({ severity: "potentially_breaking", path: `${path2}.${keyword}`, code: "schema_constraint_changed", message: `Schema constraint "${keyword}" changed.` });
352
- }
353
- if (stableStringify(before.type) !== stableStringify(after.type)) {
354
- const oldTypes = new Set(Array.isArray(before.type) ? before.type : before.type ? [before.type] : []);
355
- const newTypes = new Set(Array.isArray(after.type) ? after.type : after.type ? [after.type] : []);
356
- const widened = oldTypes.size > 0 && [...oldTypes].every((type) => newTypes.has(type));
357
- 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." });
358
- }
359
- if (before.enum && after.enum && before.enum.some((value) => !after.enum.some((newValue) => stableStringify(newValue) === stableStringify(value)))) {
360
- changes.push({ severity: "breaking", path: `${path2}.enum`, code: "schema_enum_narrowed", message: "Schema enum no longer accepts a previously valid value." });
361
- }
362
- 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." });
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
- const highestSeverity = changes.reduce((highest, change) => severityRank[change.severity] > severityRank[highest] ? change.severity : highest, "compatible");
366
- return { compatible: highestSeverity === "compatible", highestSeverity, changes };
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
- const files = await target.generate(ir);
370
- const paths = /* @__PURE__ */ new Set();
371
- return [...files].sort((left, right) => compareCanonicalStrings(left.path, right.path)).map((file) => {
372
- if (!file.path || import_node_path.default.isAbsolute(file.path) || import_node_path.default.win32.isAbsolute(file.path) || file.path.includes("\\") || file.path.split("/").includes("..")) throw new Error(`Generator "${target.name}" returned unsafe path "${file.path}".`);
373
- if (paths.has(file.path)) throw new Error(`Generator "${target.name}" returned duplicate path "${file.path}".`);
374
- paths.add(file.path);
375
- return { path: file.path, content: file.content.endsWith("\n") ? file.content : `${file.content}
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
- // Annotate the CommonJS export names for ESM import in node:
380
- 0 && (module.exports = {
381
- FABRIC_COMPILER_VERSION,
382
- compareCanonicalStrings,
383
- compileManifestBundle,
384
- diffModuleManifests,
385
- runGenerator,
386
- stableStringify
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