@eventcatalog/breaking-changes 0.1.0 → 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-2026 boyney123
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Note: Source code within `packages/core/eventcatalog/src/enterprise/` is
26
+ licensed under the EventCatalog Commercial License and is NOT covered by the
27
+ MIT License above. See `packages/core/eventcatalog/src/enterprise/LICENSE`
28
+ for the full terms.
package/dist/index.d.mts CHANGED
@@ -1,45 +1,24 @@
1
1
  type CompatibilityStrategy = "BACKWARD" | "FORWARD" | "FULL" | "NONE";
2
- type SchemaChangeType =
3
- | "FIELD_ADDED_REQUIRED"
4
- | "FIELD_ADDED_OPTIONAL"
5
- | "FIELD_REMOVED_REQUIRED"
6
- | "FIELD_REMOVED_OPTIONAL"
7
- | "TYPE_CHANGED"
8
- | "REQUIRED_ADDED"
9
- | "REQUIRED_REMOVED";
2
+ type SchemaChangeType = "FIELD_ADDED_REQUIRED" | "FIELD_ADDED_OPTIONAL" | "FIELD_REMOVED_REQUIRED" | "FIELD_REMOVED_OPTIONAL" | "TYPE_CHANGED" | "REQUIRED_ADDED" | "REQUIRED_REMOVED";
10
3
  type SchemaChange = {
11
- type: SchemaChangeType;
12
- field: string;
13
- message: string;
14
- previousType?: string;
15
- currentType?: string;
4
+ type: SchemaChangeType;
5
+ field: string;
6
+ message: string;
7
+ previousType?: string;
8
+ currentType?: string;
16
9
  };
17
10
  type BreakingChange = SchemaChange & {
18
- breaking: true;
11
+ breaking: true;
19
12
  };
20
13
 
21
- declare const detectBreakingChanges: (
22
- before: object,
23
- after: object,
24
- strategy: CompatibilityStrategy,
25
- ) => BreakingChange[];
14
+ declare const detectBreakingChanges: (before: object, after: object, strategy: CompatibilityStrategy) => BreakingChange[];
26
15
 
27
16
  type JsonSchemaObject = {
28
- type?: string;
29
- properties?: Record<string, JsonSchemaObject>;
30
- required?: string[];
31
- [key: string]: any;
17
+ type?: string;
18
+ properties?: Record<string, JsonSchemaObject>;
19
+ required?: string[];
20
+ [key: string]: any;
32
21
  };
33
- declare const diffJsonSchemas: (
34
- before: JsonSchemaObject,
35
- after: JsonSchemaObject,
36
- ) => SchemaChange[];
22
+ declare const diffJsonSchemas: (before: JsonSchemaObject, after: JsonSchemaObject) => SchemaChange[];
37
23
 
38
- export {
39
- type BreakingChange,
40
- type CompatibilityStrategy,
41
- type SchemaChange,
42
- type SchemaChangeType,
43
- detectBreakingChanges,
44
- diffJsonSchemas,
45
- };
24
+ export { type BreakingChange, type CompatibilityStrategy, type SchemaChange, type SchemaChangeType, detectBreakingChanges, diffJsonSchemas };
package/dist/index.d.ts CHANGED
@@ -1,45 +1,24 @@
1
1
  type CompatibilityStrategy = "BACKWARD" | "FORWARD" | "FULL" | "NONE";
2
- type SchemaChangeType =
3
- | "FIELD_ADDED_REQUIRED"
4
- | "FIELD_ADDED_OPTIONAL"
5
- | "FIELD_REMOVED_REQUIRED"
6
- | "FIELD_REMOVED_OPTIONAL"
7
- | "TYPE_CHANGED"
8
- | "REQUIRED_ADDED"
9
- | "REQUIRED_REMOVED";
2
+ type SchemaChangeType = "FIELD_ADDED_REQUIRED" | "FIELD_ADDED_OPTIONAL" | "FIELD_REMOVED_REQUIRED" | "FIELD_REMOVED_OPTIONAL" | "TYPE_CHANGED" | "REQUIRED_ADDED" | "REQUIRED_REMOVED";
10
3
  type SchemaChange = {
11
- type: SchemaChangeType;
12
- field: string;
13
- message: string;
14
- previousType?: string;
15
- currentType?: string;
4
+ type: SchemaChangeType;
5
+ field: string;
6
+ message: string;
7
+ previousType?: string;
8
+ currentType?: string;
16
9
  };
17
10
  type BreakingChange = SchemaChange & {
18
- breaking: true;
11
+ breaking: true;
19
12
  };
20
13
 
21
- declare const detectBreakingChanges: (
22
- before: object,
23
- after: object,
24
- strategy: CompatibilityStrategy,
25
- ) => BreakingChange[];
14
+ declare const detectBreakingChanges: (before: object, after: object, strategy: CompatibilityStrategy) => BreakingChange[];
26
15
 
27
16
  type JsonSchemaObject = {
28
- type?: string;
29
- properties?: Record<string, JsonSchemaObject>;
30
- required?: string[];
31
- [key: string]: any;
17
+ type?: string;
18
+ properties?: Record<string, JsonSchemaObject>;
19
+ required?: string[];
20
+ [key: string]: any;
32
21
  };
33
- declare const diffJsonSchemas: (
34
- before: JsonSchemaObject,
35
- after: JsonSchemaObject,
36
- ) => SchemaChange[];
22
+ declare const diffJsonSchemas: (before: JsonSchemaObject, after: JsonSchemaObject) => SchemaChange[];
37
23
 
38
- export {
39
- type BreakingChange,
40
- type CompatibilityStrategy,
41
- type SchemaChange,
42
- type SchemaChangeType,
43
- detectBreakingChanges,
44
- diffJsonSchemas,
45
- };
24
+ export { type BreakingChange, type CompatibilityStrategy, type SchemaChange, type SchemaChangeType, detectBreakingChanges, diffJsonSchemas };
package/dist/index.js CHANGED
@@ -8,30 +8,36 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
 
24
20
  // src/index.ts
25
21
  var index_exports = {};
26
22
  __export(index_exports, {
27
23
  detectBreakingChanges: () => detectBreakingChanges,
28
- diffJsonSchemas: () => diffJsonSchemas,
24
+ diffJsonSchemas: () => diffJsonSchemas
29
25
  });
30
26
  module.exports = __toCommonJS(index_exports);
31
27
 
32
28
  // src/json-schema/differ.ts
29
+ var hasProperties = (schema) => !!(schema.properties || schema.required);
33
30
  var diffJsonSchemas = (before, after) => {
34
31
  const changes = [];
32
+ if (before.type && after.type && before.type !== after.type) {
33
+ changes.push({
34
+ type: "TYPE_CHANGED",
35
+ field: "(root)",
36
+ message: `Root type changed from '${before.type}' to '${after.type}'`,
37
+ previousType: before.type,
38
+ currentType: after.type
39
+ });
40
+ }
35
41
  compareProperties(before, after, "", changes);
36
42
  return changes;
37
43
  };
@@ -42,7 +48,7 @@ var compareProperties = (before, after, prefix, changes) => {
42
48
  const afterRequired = new Set(after.required || []);
43
49
  const allFields = /* @__PURE__ */ new Set([
44
50
  ...Object.keys(beforeProps),
45
- ...Object.keys(afterProps),
51
+ ...Object.keys(afterProps)
46
52
  ]);
47
53
  for (const field of allFields) {
48
54
  const fullPath = prefix ? `${prefix}.${field}` : field;
@@ -53,7 +59,7 @@ var compareProperties = (before, after, prefix, changes) => {
53
59
  changes.push({
54
60
  type: isRequired ? "FIELD_ADDED_REQUIRED" : "FIELD_ADDED_OPTIONAL",
55
61
  field: fullPath,
56
- message: `${isRequired ? "Required" : "Optional"} field '${fullPath}' was added`,
62
+ message: `${isRequired ? "Required" : "Optional"} field '${fullPath}' was added`
57
63
  });
58
64
  continue;
59
65
  }
@@ -62,7 +68,7 @@ var compareProperties = (before, after, prefix, changes) => {
62
68
  changes.push({
63
69
  type: wasRequired ? "FIELD_REMOVED_REQUIRED" : "FIELD_REMOVED_OPTIONAL",
64
70
  field: fullPath,
65
- message: `${wasRequired ? "Required" : "Optional"} field '${fullPath}' was removed`,
71
+ message: `${wasRequired ? "Required" : "Optional"} field '${fullPath}' was removed`
66
72
  });
67
73
  continue;
68
74
  }
@@ -74,7 +80,7 @@ var compareProperties = (before, after, prefix, changes) => {
74
80
  field: fullPath,
75
81
  message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`,
76
82
  previousType: beforeType,
77
- currentType: afterType,
83
+ currentType: afterType
78
84
  });
79
85
  }
80
86
  const wasPreviouslyRequired = beforeRequired.has(field);
@@ -83,24 +89,21 @@ var compareProperties = (before, after, prefix, changes) => {
83
89
  changes.push({
84
90
  type: "REQUIRED_ADDED",
85
91
  field: fullPath,
86
- message: `Field '${fullPath}' was made required`,
92
+ message: `Field '${fullPath}' was made required`
87
93
  });
88
94
  } else if (wasPreviouslyRequired && !isNowRequired) {
89
95
  changes.push({
90
96
  type: "REQUIRED_REMOVED",
91
97
  field: fullPath,
92
- message: `Field '${fullPath}' was made optional`,
98
+ message: `Field '${fullPath}' was made optional`
93
99
  });
94
100
  }
95
- if (
96
- beforeProps[field].type === "object" ||
97
- afterProps[field].type === "object"
98
- ) {
101
+ if (beforeProps[field].type === "object" || afterProps[field].type === "object" || hasProperties(beforeProps[field]) || hasProperties(afterProps[field])) {
99
102
  compareProperties(
100
103
  beforeProps[field],
101
104
  afterProps[field],
102
105
  fullPath,
103
- changes,
106
+ changes
104
107
  );
105
108
  }
106
109
  }
@@ -112,34 +115,31 @@ var BREAKING_RULES = {
112
115
  "FIELD_ADDED_REQUIRED",
113
116
  "FIELD_REMOVED_REQUIRED",
114
117
  "TYPE_CHANGED",
115
- "REQUIRED_ADDED",
118
+ "REQUIRED_ADDED"
116
119
  ]),
117
120
  FORWARD: /* @__PURE__ */ new Set([
118
121
  "FIELD_ADDED_REQUIRED",
119
122
  "FIELD_REMOVED_REQUIRED",
120
123
  "TYPE_CHANGED",
121
- "REQUIRED_ADDED",
124
+ "REQUIRED_ADDED"
122
125
  ]),
123
126
  FULL: /* @__PURE__ */ new Set([
124
127
  "FIELD_ADDED_REQUIRED",
125
128
  "FIELD_REMOVED_REQUIRED",
126
129
  "TYPE_CHANGED",
127
- "REQUIRED_ADDED",
130
+ "REQUIRED_ADDED"
128
131
  ]),
129
- NONE: /* @__PURE__ */ new Set(),
132
+ NONE: /* @__PURE__ */ new Set()
130
133
  };
131
134
  var detectBreakingChanges = (before, after, strategy) => {
132
135
  if (strategy === "NONE") return [];
133
136
  const changes = diffJsonSchemas(before, after);
134
137
  const breakingTypes = BREAKING_RULES[strategy];
135
- return changes
136
- .filter((change) => breakingTypes.has(change.type))
137
- .map((change) => ({ ...change, breaking: true }));
138
+ return changes.filter((change) => breakingTypes.has(change.type)).map((change) => ({ ...change, breaking: true }));
138
139
  };
139
140
  // Annotate the CommonJS export names for ESM import in node:
140
- 0 &&
141
- (module.exports = {
142
- detectBreakingChanges,
143
- diffJsonSchemas,
144
- });
145
- //# sourceMappingURL=index.js.map
141
+ 0 && (module.exports = {
142
+ detectBreakingChanges,
143
+ diffJsonSchemas
144
+ });
145
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/json-schema/differ.ts","../src/json-schema/rules.ts"],"sourcesContent":["export type { CompatibilityStrategy, SchemaChange, BreakingChange, SchemaChangeType } from './types';\n\nexport { detectBreakingChanges } from './json-schema/rules';\nexport { diffJsonSchemas } from './json-schema/differ';\n","import type { SchemaChange } from '../types';\n\ntype JsonSchemaObject = {\n type?: string;\n properties?: Record<string, JsonSchemaObject>;\n required?: string[];\n [key: string]: any;\n};\n\nexport const diffJsonSchemas = (before: JsonSchemaObject, after: JsonSchemaObject): SchemaChange[] => {\n const changes: SchemaChange[] = [];\n compareProperties(before, after, '', changes);\n return changes;\n};\n\nconst compareProperties = (\n before: JsonSchemaObject,\n after: JsonSchemaObject,\n prefix: string,\n changes: SchemaChange[]\n): void => {\n const beforeProps = before.properties || {};\n const afterProps = after.properties || {};\n const beforeRequired = new Set(before.required || []);\n const afterRequired = new Set(after.required || []);\n\n const allFields = new Set([...Object.keys(beforeProps), ...Object.keys(afterProps)]);\n\n for (const field of allFields) {\n const fullPath = prefix ? `${prefix}.${field}` : field;\n const inBefore = field in beforeProps;\n const inAfter = field in afterProps;\n\n if (!inBefore && inAfter) {\n const isRequired = afterRequired.has(field);\n changes.push({\n type: isRequired ? 'FIELD_ADDED_REQUIRED' : 'FIELD_ADDED_OPTIONAL',\n field: fullPath,\n message: `${isRequired ? 'Required' : 'Optional'} field '${fullPath}' was added`,\n });\n continue;\n }\n\n if (inBefore && !inAfter) {\n const wasRequired = beforeRequired.has(field);\n changes.push({\n type: wasRequired ? 'FIELD_REMOVED_REQUIRED' : 'FIELD_REMOVED_OPTIONAL',\n field: fullPath,\n message: `${wasRequired ? 'Required' : 'Optional'} field '${fullPath}' was removed`,\n });\n continue;\n }\n\n // Field exists in both — check type\n const beforeType = beforeProps[field].type;\n const afterType = afterProps[field].type;\n\n if (beforeType && afterType && beforeType !== afterType) {\n changes.push({\n type: 'TYPE_CHANGED',\n field: fullPath,\n message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`,\n previousType: beforeType,\n currentType: afterType,\n });\n }\n\n // Check required status change\n const wasPreviouslyRequired = beforeRequired.has(field);\n const isNowRequired = afterRequired.has(field);\n\n if (!wasPreviouslyRequired && isNowRequired) {\n changes.push({\n type: 'REQUIRED_ADDED',\n field: fullPath,\n message: `Field '${fullPath}' was made required`,\n });\n } else if (wasPreviouslyRequired && !isNowRequired) {\n changes.push({\n type: 'REQUIRED_REMOVED',\n field: fullPath,\n message: `Field '${fullPath}' was made optional`,\n });\n }\n\n // Recurse into nested objects\n if (beforeProps[field].type === 'object' || afterProps[field].type === 'object') {\n compareProperties(beforeProps[field], afterProps[field], fullPath, changes);\n }\n }\n};\n","import type { CompatibilityStrategy, SchemaChange, BreakingChange, SchemaChangeType } from '../types';\nimport { diffJsonSchemas } from './differ';\n\nconst BREAKING_RULES: Record<CompatibilityStrategy, Set<SchemaChangeType>> = {\n BACKWARD: new Set([\n 'FIELD_ADDED_REQUIRED',\n 'FIELD_REMOVED_REQUIRED',\n 'TYPE_CHANGED',\n 'REQUIRED_ADDED',\n ]),\n FORWARD: new Set([\n 'FIELD_ADDED_REQUIRED',\n 'FIELD_REMOVED_REQUIRED',\n 'TYPE_CHANGED',\n 'REQUIRED_ADDED',\n ]),\n FULL: new Set([\n 'FIELD_ADDED_REQUIRED',\n 'FIELD_REMOVED_REQUIRED',\n 'TYPE_CHANGED',\n 'REQUIRED_ADDED',\n ]),\n NONE: new Set(),\n};\n\nexport const detectBreakingChanges = (\n before: object,\n after: object,\n strategy: CompatibilityStrategy\n): BreakingChange[] => {\n if (strategy === 'NONE') return [];\n\n const changes = diffJsonSchemas(before, after);\n const breakingTypes = BREAKING_RULES[strategy];\n\n return changes\n .filter((change) => breakingTypes.has(change.type))\n .map((change) => ({ ...change, breaking: true as const }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,kBAAkB,CAAC,QAA0B,UAA4C;AACpG,QAAM,UAA0B,CAAC;AACjC,oBAAkB,QA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"],"sourcesContent":["export type {\n CompatibilityStrategy,\n SchemaChange,\n BreakingChange,\n SchemaChangeType,\n} from \"./types\";\n\nexport { detectBreakingChanges } from \"./json-schema/rules\";\nexport { diffJsonSchemas } from \"./json-schema/differ\";\n","import type { SchemaChange } from \"../types\";\n\ntype JsonSchemaObject = {\n type?: string;\n properties?: Record<string, JsonSchemaObject>;\n required?: string[];\n [key: string]: any;\n};\n\nconst hasProperties = (schema: JsonSchemaObject): boolean =>\n !!(schema.properties || schema.required);\n\nexport const diffJsonSchemas = (\n before: JsonSchemaObject,\n after: JsonSchemaObject,\n): SchemaChange[] => {\n const changes: SchemaChange[] = [];\n\n // Detect root-level type changes\n if (before.type && after.type && before.type !== after.type) {\n changes.push({\n type: \"TYPE_CHANGED\",\n field: \"(root)\",\n message: `Root type changed from '${before.type}' to '${after.type}'`,\n previousType: before.type,\n currentType: after.type,\n });\n }\n\n compareProperties(before, after, \"\", changes);\n return changes;\n};\n\nconst compareProperties = (\n before: JsonSchemaObject,\n after: JsonSchemaObject,\n prefix: string,\n changes: SchemaChange[],\n): void => {\n const beforeProps = before.properties || {};\n const afterProps = after.properties || {};\n const beforeRequired = new Set(before.required || []);\n const afterRequired = new Set(after.required || []);\n\n const allFields = new Set([\n ...Object.keys(beforeProps),\n ...Object.keys(afterProps),\n ]);\n\n for (const field of allFields) {\n const fullPath = prefix ? `${prefix}.${field}` : field;\n const inBefore = field in beforeProps;\n const inAfter = field in afterProps;\n\n if (!inBefore && inAfter) {\n const isRequired = afterRequired.has(field);\n changes.push({\n type: isRequired ? \"FIELD_ADDED_REQUIRED\" : \"FIELD_ADDED_OPTIONAL\",\n field: fullPath,\n message: `${isRequired ? \"Required\" : \"Optional\"} field '${fullPath}' was added`,\n });\n continue;\n }\n\n if (inBefore && !inAfter) {\n const wasRequired = beforeRequired.has(field);\n changes.push({\n type: wasRequired ? \"FIELD_REMOVED_REQUIRED\" : \"FIELD_REMOVED_OPTIONAL\",\n field: fullPath,\n message: `${wasRequired ? \"Required\" : \"Optional\"} field '${fullPath}' was removed`,\n });\n continue;\n }\n\n // Field exists in both — check type\n const beforeType = beforeProps[field].type;\n const afterType = afterProps[field].type;\n\n if (beforeType && afterType && beforeType !== afterType) {\n changes.push({\n type: \"TYPE_CHANGED\",\n field: fullPath,\n message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`,\n previousType: beforeType,\n currentType: afterType,\n });\n }\n\n // Check required status change\n const wasPreviouslyRequired = beforeRequired.has(field);\n const isNowRequired = afterRequired.has(field);\n\n if (!wasPreviouslyRequired && isNowRequired) {\n changes.push({\n type: \"REQUIRED_ADDED\",\n field: fullPath,\n message: `Field '${fullPath}' was made required`,\n });\n } else if (wasPreviouslyRequired && !isNowRequired) {\n changes.push({\n type: \"REQUIRED_REMOVED\",\n field: fullPath,\n message: `Field '${fullPath}' was made optional`,\n });\n }\n\n // Recurse into nested objects (explicit type or implicit via properties/required)\n if (\n beforeProps[field].type === \"object\" ||\n afterProps[field].type === \"object\" ||\n hasProperties(beforeProps[field]) ||\n hasProperties(afterProps[field])\n ) {\n compareProperties(\n beforeProps[field],\n afterProps[field],\n fullPath,\n changes,\n );\n }\n }\n};\n","import type {\n CompatibilityStrategy,\n SchemaChange,\n BreakingChange,\n SchemaChangeType,\n} from \"../types\";\nimport { diffJsonSchemas } from \"./differ\";\n\nconst BREAKING_RULES: Record<CompatibilityStrategy, Set<SchemaChangeType>> = {\n BACKWARD: new Set([\n \"FIELD_ADDED_REQUIRED\",\n \"FIELD_REMOVED_REQUIRED\",\n \"TYPE_CHANGED\",\n \"REQUIRED_ADDED\",\n ]),\n FORWARD: new Set([\n \"FIELD_ADDED_REQUIRED\",\n \"FIELD_REMOVED_REQUIRED\",\n \"TYPE_CHANGED\",\n \"REQUIRED_ADDED\",\n ]),\n FULL: new Set([\n \"FIELD_ADDED_REQUIRED\",\n \"FIELD_REMOVED_REQUIRED\",\n \"TYPE_CHANGED\",\n \"REQUIRED_ADDED\",\n ]),\n NONE: new Set(),\n};\n\nexport const detectBreakingChanges = (\n before: object,\n after: object,\n strategy: CompatibilityStrategy,\n): BreakingChange[] => {\n if (strategy === \"NONE\") return [];\n\n const changes = diffJsonSchemas(before, after);\n const breakingTypes = BREAKING_RULES[strategy];\n\n return changes\n .filter((change) => breakingTypes.has(change.type))\n .map((change) => ({ ...change, breaking: true as const }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,IAAM,gBAAgB,CAAC,WACrB,CAAC,EAAE,OAAO,cAAc,OAAO;AAE1B,IAAM,kBAAkB,CAC7B,QACA,UACmB;AACnB,QAAM,UAA0B,CAAC;AAGjC,MAAI,OAAO,QAAQ,MAAM,QAAQ,OAAO,SAAS,MAAM,MAAM;AAC3D,YAAQ,KAAK;AAAA,MACX,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS,2BAA2B,OAAO,IAAI,SAAS,MAAM,IAAI;AAAA,MAClE,cAAc,OAAO;AAAA,MACrB,aAAa,MAAM;AAAA,IACrB,CAAC;AAAA,EACH;AAEA,oBAAkB,QAAQ,OAAO,IAAI,OAAO;AAC5C,SAAO;AACT;AAEA,IAAM,oBAAoB,CACxB,QACA,OACA,QACA,YACS;AACT,QAAM,cAAc,OAAO,cAAc,CAAC;AAC1C,QAAM,aAAa,MAAM,cAAc,CAAC;AACxC,QAAM,iBAAiB,IAAI,IAAI,OAAO,YAAY,CAAC,CAAC;AACpD,QAAM,gBAAgB,IAAI,IAAI,MAAM,YAAY,CAAC,CAAC;AAElD,QAAM,YAAY,oBAAI,IAAI;AAAA,IACxB,GAAG,OAAO,KAAK,WAAW;AAAA,IAC1B,GAAG,OAAO,KAAK,UAAU;AAAA,EAC3B,CAAC;AAED,aAAW,SAAS,WAAW;AAC7B,UAAM,WAAW,SAAS,GAAG,MAAM,IAAI,KAAK,KAAK;AACjD,UAAM,WAAW,SAAS;AAC1B,UAAM,UAAU,SAAS;AAEzB,QAAI,CAAC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AAY,KAAK;AAAA,QACjB,WAAW,KAAK;AAAA,QAChB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;ACjHA,IAAM,iBAAuE;AAAA,EAC3E,UAAU,oBAAI,IAAI;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,SAAS,oBAAI,IAAI;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,MAAM,oBAAI,IAAI;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,MAAM,oBAAI,IAAI;AAChB;AAEO,IAAM,wBAAwB,CACnC,QACA,OACA,aACqB;AACrB,MAAI,aAAa,OAAQ,QAAO,CAAC;AAEjC,QAAM,UAAU,gBAAgB,QAAQ,KAAK;AAC7C,QAAM,gBAAgB,eAAe,QAAQ;AAE7C,SAAO,QACJ,OAAO,CAAC,WAAW,cAAc,IAAI,OAAO,IAAI,CAAC,EACjD,IAAI,CAAC,YAAY,EAAE,GAAG,QAAQ,UAAU,KAAc,EAAE;AAC7D;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,6 +1,16 @@
1
1
  // src/json-schema/differ.ts
2
+ var hasProperties = (schema) => !!(schema.properties || schema.required);
2
3
  var diffJsonSchemas = (before, after) => {
3
4
  const changes = [];
5
+ if (before.type && after.type && before.type !== after.type) {
6
+ changes.push({
7
+ type: "TYPE_CHANGED",
8
+ field: "(root)",
9
+ message: `Root type changed from '${before.type}' to '${after.type}'`,
10
+ previousType: before.type,
11
+ currentType: after.type
12
+ });
13
+ }
4
14
  compareProperties(before, after, "", changes);
5
15
  return changes;
6
16
  };
@@ -11,7 +21,7 @@ var compareProperties = (before, after, prefix, changes) => {
11
21
  const afterRequired = new Set(after.required || []);
12
22
  const allFields = /* @__PURE__ */ new Set([
13
23
  ...Object.keys(beforeProps),
14
- ...Object.keys(afterProps),
24
+ ...Object.keys(afterProps)
15
25
  ]);
16
26
  for (const field of allFields) {
17
27
  const fullPath = prefix ? `${prefix}.${field}` : field;
@@ -22,7 +32,7 @@ var compareProperties = (before, after, prefix, changes) => {
22
32
  changes.push({
23
33
  type: isRequired ? "FIELD_ADDED_REQUIRED" : "FIELD_ADDED_OPTIONAL",
24
34
  field: fullPath,
25
- message: `${isRequired ? "Required" : "Optional"} field '${fullPath}' was added`,
35
+ message: `${isRequired ? "Required" : "Optional"} field '${fullPath}' was added`
26
36
  });
27
37
  continue;
28
38
  }
@@ -31,7 +41,7 @@ var compareProperties = (before, after, prefix, changes) => {
31
41
  changes.push({
32
42
  type: wasRequired ? "FIELD_REMOVED_REQUIRED" : "FIELD_REMOVED_OPTIONAL",
33
43
  field: fullPath,
34
- message: `${wasRequired ? "Required" : "Optional"} field '${fullPath}' was removed`,
44
+ message: `${wasRequired ? "Required" : "Optional"} field '${fullPath}' was removed`
35
45
  });
36
46
  continue;
37
47
  }
@@ -43,7 +53,7 @@ var compareProperties = (before, after, prefix, changes) => {
43
53
  field: fullPath,
44
54
  message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`,
45
55
  previousType: beforeType,
46
- currentType: afterType,
56
+ currentType: afterType
47
57
  });
48
58
  }
49
59
  const wasPreviouslyRequired = beforeRequired.has(field);
@@ -52,24 +62,21 @@ var compareProperties = (before, after, prefix, changes) => {
52
62
  changes.push({
53
63
  type: "REQUIRED_ADDED",
54
64
  field: fullPath,
55
- message: `Field '${fullPath}' was made required`,
65
+ message: `Field '${fullPath}' was made required`
56
66
  });
57
67
  } else if (wasPreviouslyRequired && !isNowRequired) {
58
68
  changes.push({
59
69
  type: "REQUIRED_REMOVED",
60
70
  field: fullPath,
61
- message: `Field '${fullPath}' was made optional`,
71
+ message: `Field '${fullPath}' was made optional`
62
72
  });
63
73
  }
64
- if (
65
- beforeProps[field].type === "object" ||
66
- afterProps[field].type === "object"
67
- ) {
74
+ if (beforeProps[field].type === "object" || afterProps[field].type === "object" || hasProperties(beforeProps[field]) || hasProperties(afterProps[field])) {
68
75
  compareProperties(
69
76
  beforeProps[field],
70
77
  afterProps[field],
71
78
  fullPath,
72
- changes,
79
+ changes
73
80
  );
74
81
  }
75
82
  }
@@ -81,29 +88,30 @@ var BREAKING_RULES = {
81
88
  "FIELD_ADDED_REQUIRED",
82
89
  "FIELD_REMOVED_REQUIRED",
83
90
  "TYPE_CHANGED",
84
- "REQUIRED_ADDED",
91
+ "REQUIRED_ADDED"
85
92
  ]),
86
93
  FORWARD: /* @__PURE__ */ new Set([
87
94
  "FIELD_ADDED_REQUIRED",
88
95
  "FIELD_REMOVED_REQUIRED",
89
96
  "TYPE_CHANGED",
90
- "REQUIRED_ADDED",
97
+ "REQUIRED_ADDED"
91
98
  ]),
92
99
  FULL: /* @__PURE__ */ new Set([
93
100
  "FIELD_ADDED_REQUIRED",
94
101
  "FIELD_REMOVED_REQUIRED",
95
102
  "TYPE_CHANGED",
96
- "REQUIRED_ADDED",
103
+ "REQUIRED_ADDED"
97
104
  ]),
98
- NONE: /* @__PURE__ */ new Set(),
105
+ NONE: /* @__PURE__ */ new Set()
99
106
  };
100
107
  var detectBreakingChanges = (before, after, strategy) => {
101
108
  if (strategy === "NONE") return [];
102
109
  const changes = diffJsonSchemas(before, after);
103
110
  const breakingTypes = BREAKING_RULES[strategy];
104
- return changes
105
- .filter((change) => breakingTypes.has(change.type))
106
- .map((change) => ({ ...change, breaking: true }));
111
+ return changes.filter((change) => breakingTypes.has(change.type)).map((change) => ({ ...change, breaking: true }));
112
+ };
113
+ export {
114
+ detectBreakingChanges,
115
+ diffJsonSchemas
107
116
  };
108
- export { detectBreakingChanges, diffJsonSchemas };
109
- //# sourceMappingURL=index.mjs.map
117
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/json-schema/differ.ts","../src/json-schema/rules.ts"],"sourcesContent":["import type { SchemaChange } from '../types';\n\ntype JsonSchemaObject = {\n type?: string;\n properties?: Record<string, JsonSchemaObject>;\n required?: string[];\n [key: string]: any;\n};\n\nexport const diffJsonSchemas = (before: JsonSchemaObject, after: JsonSchemaObject): SchemaChange[] => {\n const changes: SchemaChange[] = [];\n compareProperties(before, after, '', changes);\n return changes;\n};\n\nconst compareProperties = (\n before: JsonSchemaObject,\n after: JsonSchemaObject,\n prefix: string,\n changes: SchemaChange[]\n): void => {\n const beforeProps = before.properties || {};\n const afterProps = after.properties || {};\n const beforeRequired = new Set(before.required || []);\n const afterRequired = new Set(after.required || []);\n\n const allFields = new Set([...Object.keys(beforeProps), ...Object.keys(afterProps)]);\n\n for (const field of allFields) {\n const fullPath = prefix ? `${prefix}.${field}` : field;\n const inBefore = field in beforeProps;\n const inAfter = field in afterProps;\n\n if (!inBefore && inAfter) {\n const isRequired = afterRequired.has(field);\n changes.push({\n type: isRequired ? 'FIELD_ADDED_REQUIRED' : 'FIELD_ADDED_OPTIONAL',\n field: fullPath,\n message: `${isRequired ? 'Required' : 'Optional'} field '${fullPath}' was added`,\n });\n continue;\n }\n\n if (inBefore && !inAfter) {\n const wasRequired = beforeRequired.has(field);\n changes.push({\n type: wasRequired ? 'FIELD_REMOVED_REQUIRED' : 'FIELD_REMOVED_OPTIONAL',\n field: fullPath,\n message: `${wasRequired ? 'Required' : 'Optional'} field '${fullPath}' was removed`,\n });\n continue;\n }\n\n // Field exists in both — check type\n const beforeType = beforeProps[field].type;\n const afterType = afterProps[field].type;\n\n if (beforeType && afterType && beforeType !== afterType) {\n changes.push({\n type: 'TYPE_CHANGED',\n field: fullPath,\n message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`,\n previousType: beforeType,\n currentType: afterType,\n });\n }\n\n // Check required status change\n const wasPreviouslyRequired = beforeRequired.has(field);\n const isNowRequired = afterRequired.has(field);\n\n if (!wasPreviouslyRequired && isNowRequired) {\n changes.push({\n type: 'REQUIRED_ADDED',\n field: fullPath,\n message: `Field '${fullPath}' was made required`,\n });\n } else if (wasPreviouslyRequired && !isNowRequired) {\n changes.push({\n type: 'REQUIRED_REMOVED',\n field: fullPath,\n message: `Field '${fullPath}' was made optional`,\n });\n }\n\n // Recurse into nested objects\n if (beforeProps[field].type === 'object' || afterProps[field].type === 'object') {\n compareProperties(beforeProps[field], afterProps[field], fullPath, changes);\n }\n }\n};\n","import type { CompatibilityStrategy, SchemaChange, BreakingChange, SchemaChangeType } from '../types';\nimport { diffJsonSchemas } from './differ';\n\nconst BREAKING_RULES: Record<CompatibilityStrategy, Set<SchemaChangeType>> = {\n BACKWARD: new Set([\n 'FIELD_ADDED_REQUIRED',\n 'FIELD_REMOVED_REQUIRED',\n 'TYPE_CHANGED',\n 'REQUIRED_ADDED',\n ]),\n FORWARD: new Set([\n 'FIELD_ADDED_REQUIRED',\n 'FIELD_REMOVED_REQUIRED',\n 'TYPE_CHANGED',\n 'REQUIRED_ADDED',\n ]),\n FULL: new Set([\n 'FIELD_ADDED_REQUIRED',\n 'FIELD_REMOVED_REQUIRED',\n 'TYPE_CHANGED',\n 'REQUIRED_ADDED',\n ]),\n NONE: new Set(),\n};\n\nexport const detectBreakingChanges = (\n before: object,\n after: object,\n strategy: CompatibilityStrategy\n): BreakingChange[] => {\n if (strategy === 'NONE') return [];\n\n const changes = diffJsonSchemas(before, after);\n const breakingTypes = BREAKING_RULES[strategy];\n\n return changes\n .filter((change) => breakingTypes.has(change.type))\n .map((change) => ({ ...change, breaking: true as const }));\n};\n"],"mappings":";AASO,IAAM,kBAAkB,CAAC,QAA0B,UAA4C;AACpG,QAAM,UAA0B,CAAC;AACjC,oBAAkB,QAAQ,OAAO,IAAI,OAAO;AAC5C,SAAO;AACT;AAEA,IAAM,oBAAoB,CACxB,QACA,OACA,QACA,YACS;AACT,QAAM,cAAc,OAAO,cAAc,CAAC;AAC1C,QAAM,aAAa,MAAM,cAAc,CAAC;AACxC,QAAM,iBAAiB,IAAI,IAAI,OAAO,YAAY,CAAC,CAAC;AACpD,QAAM,gBAAgB,IAAI,IAAI,MAAM,YAAY,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AClD,cAAQ,KAAK;AAAA,QACX,MAAM;AAAA,QACN,OAAO;AAAA,QACP,SAAS,UAAU,QAAQ;AAAA,MAC7B,CAAC;AAAA,IACH;AAGA,QAAI,YAAY,KAAK,EAAE,SAAS,YAAY,WAAW,KAAK,EAAE,SAAS,UAAU;AAC/E,wBAAkB,YAAY,KAAK,GAAG,WAAW,KAAK,GAAG,UAAU,OAAO;AAAA,IAC5E;AAAA,EACF;AACF;;;ACvFA,IAAM,iBAAuE;AAAA,EAC3E,UAAU,oBAAI,IAAI;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,SAAS,oBAAI,IAAI;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,MAAM,oBAAI,IAAI;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,MAAM,oBAAI,IAAI;AAChB;AAEO,IAAM,wBAAwB,CACnC,QACA,OACA,aACqB;AACrB,MAAI,aAAa,OAAQ,QAAO,CAAC;AAEjC,QAAM,UAAU,gBAAgB,QAAQ,KAAK;AAC7C,QAAM,gBAAgB,eAAe,QAAQ;AAE7C,SAAO,QACJ,OAAO,CAAC,WAAW,cAAc,IAAI,OAAO,IAAI,CAAC,EACjD,IAAI,CAAC,YAAY,EAAE,GAAG,QAAQ,UAAU,KAAc,EAAE;AAC7D;","names":[]}
1
+ {"version":3,"sources":["../src/json-schema/differ.ts","../src/json-schema/rules.ts"],"sourcesContent":["import type { SchemaChange } from \"../types\";\n\ntype JsonSchemaObject = {\n type?: string;\n properties?: Record<string, JsonSchemaObject>;\n required?: string[];\n [key: string]: any;\n};\n\nconst hasProperties = (schema: JsonSchemaObject): boolean =>\n !!(schema.properties || schema.required);\n\nexport const diffJsonSchemas = (\n before: JsonSchemaObject,\n after: JsonSchemaObject,\n): SchemaChange[] => {\n const changes: SchemaChange[] = [];\n\n // Detect root-level type changes\n if (before.type && after.type && before.type !== after.type) {\n changes.push({\n type: \"TYPE_CHANGED\",\n field: \"(root)\",\n message: `Root type changed from '${before.type}' to '${after.type}'`,\n previousType: before.type,\n currentType: after.type,\n });\n }\n\n compareProperties(before, after, \"\", changes);\n return changes;\n};\n\nconst compareProperties = (\n before: JsonSchemaObject,\n after: JsonSchemaObject,\n prefix: string,\n changes: SchemaChange[],\n): void => {\n const beforeProps = before.properties || {};\n const afterProps = after.properties || {};\n const beforeRequired = new Set(before.required || []);\n const afterRequired = new Set(after.required || []);\n\n const allFields = new Set([\n ...Object.keys(beforeProps),\n ...Object.keys(afterProps),\n ]);\n\n for (const field of allFields) {\n const fullPath = prefix ? `${prefix}.${field}` : field;\n const inBefore = field in beforeProps;\n const inAfter = field in afterProps;\n\n if (!inBefore && inAfter) {\n const isRequired = afterRequired.has(field);\n changes.push({\n type: isRequired ? \"FIELD_ADDED_REQUIRED\" : \"FIELD_ADDED_OPTIONAL\",\n field: fullPath,\n message: `${isRequired ? \"Required\" : \"Optional\"} field '${fullPath}' was added`,\n });\n continue;\n }\n\n if (inBefore && !inAfter) {\n const wasRequired = beforeRequired.has(field);\n changes.push({\n type: wasRequired ? \"FIELD_REMOVED_REQUIRED\" : \"FIELD_REMOVED_OPTIONAL\",\n field: fullPath,\n message: `${wasRequired ? \"Required\" : \"Optional\"} field '${fullPath}' was removed`,\n });\n continue;\n }\n\n // Field exists in both — check type\n const beforeType = beforeProps[field].type;\n const afterType = afterProps[field].type;\n\n if (beforeType && afterType && beforeType !== afterType) {\n changes.push({\n type: \"TYPE_CHANGED\",\n field: fullPath,\n message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`,\n previousType: beforeType,\n currentType: afterType,\n });\n }\n\n // Check required status change\n const wasPreviouslyRequired = beforeRequired.has(field);\n const isNowRequired = afterRequired.has(field);\n\n if (!wasPreviouslyRequired && isNowRequired) {\n changes.push({\n type: \"REQUIRED_ADDED\",\n field: fullPath,\n message: `Field '${fullPath}' was made required`,\n });\n } else if (wasPreviouslyRequired && !isNowRequired) {\n changes.push({\n type: \"REQUIRED_REMOVED\",\n field: fullPath,\n message: `Field '${fullPath}' was made optional`,\n });\n }\n\n // Recurse into nested objects (explicit type or implicit via properties/required)\n if (\n beforeProps[field].type === \"object\" ||\n afterProps[field].type === \"object\" ||\n hasProperties(beforeProps[field]) ||\n hasProperties(afterProps[field])\n ) {\n compareProperties(\n beforeProps[field],\n afterProps[field],\n fullPath,\n changes,\n );\n }\n }\n};\n","import type {\n CompatibilityStrategy,\n SchemaChange,\n BreakingChange,\n SchemaChangeType,\n} from \"../types\";\nimport { diffJsonSchemas } from \"./differ\";\n\nconst BREAKING_RULES: Record<CompatibilityStrategy, Set<SchemaChangeType>> = {\n BACKWARD: new Set([\n \"FIELD_ADDED_REQUIRED\",\n \"FIELD_REMOVED_REQUIRED\",\n \"TYPE_CHANGED\",\n \"REQUIRED_ADDED\",\n ]),\n FORWARD: new Set([\n \"FIELD_ADDED_REQUIRED\",\n \"FIELD_REMOVED_REQUIRED\",\n \"TYPE_CHANGED\",\n \"REQUIRED_ADDED\",\n ]),\n FULL: new Set([\n \"FIELD_ADDED_REQUIRED\",\n \"FIELD_REMOVED_REQUIRED\",\n \"TYPE_CHANGED\",\n \"REQUIRED_ADDED\",\n ]),\n NONE: new Set(),\n};\n\nexport const detectBreakingChanges = (\n before: object,\n after: object,\n strategy: CompatibilityStrategy,\n): BreakingChange[] => {\n if (strategy === \"NONE\") return [];\n\n const changes = diffJsonSchemas(before, after);\n const breakingTypes = BREAKING_RULES[strategy];\n\n return changes\n .filter((change) => breakingTypes.has(change.type))\n .map((change) => ({ ...change, breaking: true as const }));\n};\n"],"mappings":";AASA,IAAM,gBAAgB,CAAC,WACrB,CAAC,EAAE,OAAO,cAAc,OAAO;AAE1B,IAAM,kBAAkB,CAC7B,QACA,UACmB;AACnB,QAAM,UAA0B,CAAC;AAGjC,MAAI,OAAO,QAAQ,MAAM,QAAQ,OAAO,SA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;AACrB,MAAI,aAAa,OAAQ,QAAO,CAAC;AAEjC,QAAM,UAAU,gBAAgB,QAAQ,KAAK;AAC7C,QAAM,gBAAgB,eAAe,QAAQ;AAE7C,SAAO,QACJ,OAAO,CAAC,WAAW,cAAc,IAAI,OAAO,IAAI,CAAC,EACjD,IAAI,CAAC,YAAY,EAAE,GAAG,QAAQ,UAAU,KAAc,EAAE;AAC7D;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventcatalog/breaking-changes",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Breaking schema change detection for EventCatalog",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -15,14 +15,6 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "scripts": {
19
- "build": "tsup",
20
- "build:bin": "tsup",
21
- "test": "vitest --run",
22
- "test:ci": "vitest --run",
23
- "format": "prettier --write .",
24
- "format:diff": "prettier --list-different ."
25
- },
26
18
  "files": [
27
19
  "dist"
28
20
  ],
@@ -37,5 +29,13 @@
37
29
  "repository": {
38
30
  "type": "git",
39
31
  "url": "https://github.com/event-catalog/eventcatalog"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup",
35
+ "build:bin": "tsup",
36
+ "test": "vitest --run",
37
+ "test:ci": "vitest --run",
38
+ "format": "prettier --write .",
39
+ "format:diff": "prettier --list-different ."
40
40
  }
41
- }
41
+ }