@unispechq/unispec-core 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/dist/cjs/src/cache/cache-factory.js +1 -1
  2. package/dist/cjs/src/cache/cache-manager.js +2 -2
  3. package/dist/cjs/src/cache/hash-utils.js +1 -1
  4. package/dist/cjs/src/cache/hashing.js +1 -1
  5. package/dist/cjs/src/cache/index.js +5 -5
  6. package/dist/cjs/src/cache/lru-cache.js +1 -1
  7. package/dist/cjs/src/diff/core.js +2 -2
  8. package/dist/cjs/src/diff/enhanced-diff.js +5 -5
  9. package/dist/cjs/src/diff/index.js +8 -8
  10. package/dist/cjs/src/errors/config-error.js +1 -1
  11. package/dist/cjs/src/errors/error-factory.js +7 -7
  12. package/dist/cjs/src/errors/index.js +8 -8
  13. package/dist/cjs/src/errors/loader-error.js +1 -1
  14. package/dist/cjs/src/errors/reference-error.js +1 -1
  15. package/dist/cjs/src/errors/schema-error.js +1 -1
  16. package/dist/cjs/src/errors/security-error.js +1 -1
  17. package/dist/cjs/src/errors/semantic-error.js +1 -1
  18. package/dist/cjs/src/index.js +13 -13
  19. package/dist/cjs/src/loader/index.js +4 -4
  20. package/dist/cjs/src/loader/security-validator.js +1 -1
  21. package/dist/cjs/src/loader/unispec-loader.js +3 -3
  22. package/dist/cjs/src/loader/yaml-loader.js +1 -1
  23. package/dist/cjs/src/normalizer/core.js +4 -4
  24. package/dist/cjs/src/normalizer/index.js +1 -1
  25. package/dist/cjs/src/optimizer/core.js +2 -2
  26. package/dist/cjs/src/optimizer/index.js +3 -3
  27. package/dist/cjs/src/optimizer/optimization-functions.js +2 -2
  28. package/dist/cjs/src/schemas/dedupe.js +1 -1
  29. package/dist/cjs/src/schemas/index.js +3 -3
  30. package/dist/cjs/src/schemas/resolver.js +1 -1
  31. package/dist/cjs/src/validator/ajv-validator.js +1 -1
  32. package/dist/cjs/src/validator/config-validator-main.js +4 -4
  33. package/dist/cjs/src/validator/config-validator.js +1 -1
  34. package/dist/cjs/src/validator/index.js +7 -7
  35. package/dist/cjs/src/validator/reference-validator.js +1 -1
  36. package/dist/cjs/src/validator/tests-validator.js +2 -2
  37. package/dist/cjs/src/validator/unispec-validator.js +5 -5
  38. package/dist/cjs/src/validator/validator-factory.js +1 -1
  39. package/dist/cjs/tests/cache/cache.test.js +4 -4
  40. package/dist/cjs/tests/cache/utils.js +1 -1
  41. package/dist/cjs/tests/diff/diff-annotators.test.js +2 -2
  42. package/dist/cjs/tests/diff/diff-comprehensive.test.js +2 -2
  43. package/dist/cjs/tests/diff/diff-extended.test.js +2 -2
  44. package/dist/cjs/tests/diff/diff.test.js +2 -2
  45. package/dist/cjs/tests/diff/utils.js +1 -1
  46. package/dist/cjs/tests/errors/errors-integration.test.js +3 -3
  47. package/dist/cjs/tests/errors/errors.test.js +2 -2
  48. package/dist/cjs/tests/errors/utils.js +1 -1
  49. package/dist/cjs/tests/loader/integration.test.js +2 -2
  50. package/dist/cjs/tests/loader/loader.test.js +2 -2
  51. package/dist/cjs/tests/normalizer/normalizer-comprehensive.test.js +2 -2
  52. package/dist/cjs/tests/normalizer/normalizer-invalid.test.js +2 -2
  53. package/dist/cjs/tests/normalizer/normalizer-valid.test.js +2 -2
  54. package/dist/cjs/tests/normalizer/utils.js +1 -1
  55. package/dist/cjs/tests/optimizer/compress-references.test.js +2 -2
  56. package/dist/cjs/tests/optimizer/deduplication.test.js +2 -2
  57. package/dist/cjs/tests/optimizer/integration.test.js +3 -3
  58. package/dist/cjs/tests/optimizer/optimization-report.test.js +2 -2
  59. package/dist/cjs/tests/optimizer/optimize-document.test.js +2 -2
  60. package/dist/cjs/tests/optimizer/orphaned-schemas.test.js +2 -2
  61. package/dist/cjs/tests/optimizer/sort-schemas.test.js +2 -2
  62. package/dist/cjs/tests/optimizer/utils.js +1 -1
  63. package/dist/cjs/tests/schemas/schemas-edge-cases.test.js +3 -3
  64. package/dist/cjs/tests/schemas/schemas.test.js +3 -3
  65. package/dist/cjs/tests/schemas/utils.js +1 -1
  66. package/dist/cjs/tests/validator/config-validator.test.js +2 -2
  67. package/dist/cjs/tests/validator/unispec-validator.test.js +2 -2
  68. package/dist/cjs/tests/validator/utils.js +1 -1
  69. package/package.json +1 -1
  70. package/dist/cache/cache-factory.d.ts +0 -31
  71. package/dist/cache/cache-factory.js +0 -65
  72. package/dist/cache/cache-manager.d.ts +0 -62
  73. package/dist/cache/cache-manager.js +0 -122
  74. package/dist/cache/constants.d.ts +0 -21
  75. package/dist/cache/constants.js +0 -22
  76. package/dist/cache/hash-utils.d.ts +0 -21
  77. package/dist/cache/hash-utils.js +0 -35
  78. package/dist/cache/hashing.d.ts +0 -19
  79. package/dist/cache/hashing.js +0 -197
  80. package/dist/cache/index.d.ts +0 -6
  81. package/dist/cache/index.js +0 -10
  82. package/dist/cache/lru-cache.d.ts +0 -56
  83. package/dist/cache/lru-cache.js +0 -161
  84. package/dist/cache/types.d.ts +0 -24
  85. package/dist/cache/types.js +0 -4
  86. package/dist/cjs/cache/cache-factory.js +0 -72
  87. package/dist/cjs/cache/cache-manager.js +0 -126
  88. package/dist/cjs/cache/constants.js +0 -25
  89. package/dist/cjs/cache/hash-utils.js +0 -41
  90. package/dist/cjs/cache/hashing.js +0 -236
  91. package/dist/cjs/cache/index.js +0 -26
  92. package/dist/cjs/cache/lru-cache.js +0 -165
  93. package/dist/cjs/cache/types.js +0 -5
  94. package/dist/cjs/diff/annotators.js +0 -159
  95. package/dist/cjs/diff/change-reports.js +0 -369
  96. package/dist/cjs/diff/core.js +0 -158
  97. package/dist/cjs/diff/enhanced-diff.js +0 -79
  98. package/dist/cjs/diff/impact-strategies-refactored.js +0 -230
  99. package/dist/cjs/diff/impact-strategies.js +0 -219
  100. package/dist/cjs/diff/index.js +0 -27
  101. package/dist/cjs/diff/metrics-calculator.js +0 -69
  102. package/dist/cjs/diff/risk-calculator.js +0 -58
  103. package/dist/cjs/diff/suggestion-generator.js +0 -78
  104. package/dist/cjs/diff/types.js +0 -11
  105. package/dist/cjs/errors/base-error.js +0 -33
  106. package/dist/cjs/errors/config-error.js +0 -11
  107. package/dist/cjs/errors/error-factory.js +0 -48
  108. package/dist/cjs/errors/index.js +0 -19
  109. package/dist/cjs/errors/loader-error.js +0 -11
  110. package/dist/cjs/errors/reference-error.js +0 -11
  111. package/dist/cjs/errors/schema-error.js +0 -11
  112. package/dist/cjs/errors/security-error.js +0 -11
  113. package/dist/cjs/errors/semantic-error.js +0 -11
  114. package/dist/cjs/generated-schemas.js +0 -2100
  115. package/dist/cjs/index.js +0 -59
  116. package/dist/cjs/loader/index.js +0 -13
  117. package/dist/cjs/loader/security-validator.js +0 -53
  118. package/dist/cjs/loader/types.js +0 -11
  119. package/dist/cjs/loader/unispec-loader.js +0 -84
  120. package/dist/cjs/loader/yaml-loader.js +0 -76
  121. package/dist/cjs/normalizer/core.js +0 -32
  122. package/dist/cjs/normalizer/graphql-normalizer.js +0 -67
  123. package/dist/cjs/normalizer/index.js +0 -7
  124. package/dist/cjs/normalizer/rest-normalizer.js +0 -51
  125. package/dist/cjs/normalizer/types.js +0 -2
  126. package/dist/cjs/normalizer/utils.js +0 -33
  127. package/dist/cjs/normalizer/websocket-normalizer.js +0 -81
  128. package/dist/cjs/optimizer/core.js +0 -115
  129. package/dist/cjs/optimizer/index.js +0 -17
  130. package/dist/cjs/optimizer/optimization-functions.js +0 -185
  131. package/dist/cjs/optimizer/types.js +0 -2
  132. package/dist/cjs/optimizer/utils.js +0 -32
  133. package/dist/cjs/schemas/dedupe.js +0 -100
  134. package/dist/cjs/schemas/index.js +0 -14
  135. package/dist/cjs/schemas/resolver.js +0 -41
  136. package/dist/cjs/schemas/utils.js +0 -53
  137. package/dist/cjs/types/index.js +0 -2
  138. package/dist/cjs/validator/ajv-validator.js +0 -82
  139. package/dist/cjs/validator/config-validator-main.js +0 -34
  140. package/dist/cjs/validator/config-validator.js +0 -17
  141. package/dist/cjs/validator/index.js +0 -23
  142. package/dist/cjs/validator/object-traversal.js +0 -112
  143. package/dist/cjs/validator/reference-validator.js +0 -233
  144. package/dist/cjs/validator/schema-references.js +0 -116
  145. package/dist/cjs/validator/semantic-validator.js +0 -328
  146. package/dist/cjs/validator/tests-validator.js +0 -16
  147. package/dist/cjs/validator/types.js +0 -2
  148. package/dist/cjs/validator/unispec-validator.js +0 -84
  149. package/dist/cjs/validator/validator-factory.js +0 -77
  150. package/dist/cjs/versions.js +0 -147
  151. package/dist/diff/annotators.d.ts +0 -4
  152. package/dist/diff/annotators.js +0 -154
  153. package/dist/diff/change-reports.d.ts +0 -37
  154. package/dist/diff/change-reports.js +0 -366
  155. package/dist/diff/core.d.ts +0 -26
  156. package/dist/diff/core.js +0 -155
  157. package/dist/diff/enhanced-diff.d.ts +0 -51
  158. package/dist/diff/enhanced-diff.js +0 -76
  159. package/dist/diff/impact-strategies-refactored.d.ts +0 -69
  160. package/dist/diff/impact-strategies-refactored.js +0 -223
  161. package/dist/diff/impact-strategies.d.ts +0 -41
  162. package/dist/diff/impact-strategies.js +0 -212
  163. package/dist/diff/index.d.ts +0 -8
  164. package/dist/diff/index.js +0 -11
  165. package/dist/diff/metrics-calculator.d.ts +0 -23
  166. package/dist/diff/metrics-calculator.js +0 -65
  167. package/dist/diff/risk-calculator.d.ts +0 -23
  168. package/dist/diff/risk-calculator.js +0 -55
  169. package/dist/diff/suggestion-generator.d.ts +0 -18
  170. package/dist/diff/suggestion-generator.js +0 -74
  171. package/dist/diff/types.d.ts +0 -24
  172. package/dist/diff/types.js +0 -8
  173. package/dist/errors/base-error.d.ts +0 -20
  174. package/dist/errors/base-error.js +0 -29
  175. package/dist/errors/config-error.d.ts +0 -4
  176. package/dist/errors/config-error.js +0 -7
  177. package/dist/errors/error-factory.d.ts +0 -22
  178. package/dist/errors/error-factory.js +0 -45
  179. package/dist/errors/index.d.ts +0 -8
  180. package/dist/errors/index.js +0 -8
  181. package/dist/errors/loader-error.d.ts +0 -4
  182. package/dist/errors/loader-error.js +0 -7
  183. package/dist/errors/reference-error.d.ts +0 -4
  184. package/dist/errors/reference-error.js +0 -7
  185. package/dist/errors/schema-error.d.ts +0 -4
  186. package/dist/errors/schema-error.js +0 -7
  187. package/dist/errors/security-error.d.ts +0 -4
  188. package/dist/errors/security-error.js +0 -7
  189. package/dist/errors/semantic-error.d.ts +0 -4
  190. package/dist/errors/semantic-error.js +0 -7
  191. package/dist/generated-schemas.d.ts +0 -2073
  192. package/dist/generated-schemas.js +0 -2097
  193. package/dist/index.cjs +0 -59
  194. package/dist/index.d.ts +0 -13
  195. package/dist/index.js +0 -43
  196. package/dist/loader/index.d.ts +0 -5
  197. package/dist/loader/index.js +0 -5
  198. package/dist/loader/security-validator.d.ts +0 -5
  199. package/dist/loader/security-validator.js +0 -50
  200. package/dist/loader/types.d.ts +0 -30
  201. package/dist/loader/types.js +0 -8
  202. package/dist/loader/unispec-loader.d.ts +0 -10
  203. package/dist/loader/unispec-loader.js +0 -81
  204. package/dist/loader/yaml-loader.d.ts +0 -10
  205. package/dist/loader/yaml-loader.js +0 -39
  206. package/dist/normalizer/core.d.ts +0 -24
  207. package/dist/normalizer/core.js +0 -29
  208. package/dist/normalizer/graphql-normalizer.d.ts +0 -8
  209. package/dist/normalizer/graphql-normalizer.js +0 -64
  210. package/dist/normalizer/index.d.ts +0 -2
  211. package/dist/normalizer/index.js +0 -3
  212. package/dist/normalizer/rest-normalizer.d.ts +0 -8
  213. package/dist/normalizer/rest-normalizer.js +0 -48
  214. package/dist/normalizer/types.d.ts +0 -7
  215. package/dist/normalizer/types.js +0 -1
  216. package/dist/normalizer/utils.d.ts +0 -14
  217. package/dist/normalizer/utils.js +0 -29
  218. package/dist/normalizer/websocket-normalizer.d.ts +0 -8
  219. package/dist/normalizer/websocket-normalizer.js +0 -78
  220. package/dist/optimizer/core.d.ts +0 -17
  221. package/dist/optimizer/core.js +0 -111
  222. package/dist/optimizer/index.d.ts +0 -4
  223. package/dist/optimizer/index.js +0 -7
  224. package/dist/optimizer/optimization-functions.d.ts +0 -32
  225. package/dist/optimizer/optimization-functions.js +0 -179
  226. package/dist/optimizer/types.d.ts +0 -28
  227. package/dist/optimizer/types.js +0 -1
  228. package/dist/optimizer/utils.d.ts +0 -7
  229. package/dist/optimizer/utils.js +0 -29
  230. package/dist/schemas/dedupe.d.ts +0 -9
  231. package/dist/schemas/dedupe.js +0 -97
  232. package/dist/schemas/index.d.ts +0 -3
  233. package/dist/schemas/index.js +0 -6
  234. package/dist/schemas/resolver.d.ts +0 -19
  235. package/dist/schemas/resolver.js +0 -37
  236. package/dist/schemas/utils.d.ts +0 -20
  237. package/dist/schemas/utils.js +0 -49
  238. package/dist/types/index.d.ts +0 -433
  239. package/dist/types/index.js +0 -1
  240. package/dist/validator/ajv-validator.d.ts +0 -15
  241. package/dist/validator/ajv-validator.js +0 -75
  242. package/dist/validator/config-validator-main.d.ts +0 -10
  243. package/dist/validator/config-validator-main.js +0 -31
  244. package/dist/validator/config-validator.d.ts +0 -5
  245. package/dist/validator/config-validator.js +0 -14
  246. package/dist/validator/index.d.ts +0 -10
  247. package/dist/validator/index.js +0 -11
  248. package/dist/validator/object-traversal.d.ts +0 -52
  249. package/dist/validator/object-traversal.js +0 -104
  250. package/dist/validator/reference-validator.d.ts +0 -31
  251. package/dist/validator/reference-validator.js +0 -230
  252. package/dist/validator/schema-references.d.ts +0 -23
  253. package/dist/validator/schema-references.js +0 -111
  254. package/dist/validator/semantic-validator.d.ts +0 -26
  255. package/dist/validator/semantic-validator.js +0 -325
  256. package/dist/validator/tests-validator.d.ts +0 -9
  257. package/dist/validator/tests-validator.js +0 -13
  258. package/dist/validator/types.d.ts +0 -29
  259. package/dist/validator/types.js +0 -1
  260. package/dist/validator/unispec-validator.d.ts +0 -15
  261. package/dist/validator/unispec-validator.js +0 -81
  262. package/dist/validator/validator-factory.d.ts +0 -10
  263. package/dist/validator/validator-factory.js +0 -73
  264. package/dist/versions.d.ts +0 -10
  265. package/dist/versions.js +0 -143
package/dist/diff/core.js DELETED
@@ -1,155 +0,0 @@
1
- import { annotateGraphQLChange, annotateRestChange, annotateWebSocketChange, } from "./annotators.js";
2
- import { DEFAULT_NAMED_COLLECTION_PATHS, } from "./types.js";
3
- /**
4
- * Check if a value is a plain object (not array, null, or other object types).
5
- *
6
- * @param value - The value to check
7
- * @returns true if the value is a plain object, false otherwise
8
- */
9
- function isPlainObject(value) {
10
- return Object.prototype.toString.call(value) === "[object Object]";
11
- }
12
- function diffValues(oldVal, newVal, basePath, out, options = {}) {
13
- if (oldVal === newVal) {
14
- return;
15
- }
16
- // Both plain objects → recurse by keys
17
- if (isPlainObject(oldVal) && isPlainObject(newVal)) {
18
- const oldKeys = new Set(Object.keys(oldVal));
19
- const newKeys = new Set(Object.keys(newVal));
20
- // Removed keys
21
- for (const key of oldKeys) {
22
- if (!newKeys.has(key)) {
23
- out.push({
24
- path: `${basePath}/${key}`,
25
- description: "Field removed",
26
- severity: "unknown",
27
- });
28
- }
29
- }
30
- // Added / changed keys
31
- for (const key of newKeys) {
32
- const childPath = `${basePath}/${key}`;
33
- if (!oldKeys.has(key)) {
34
- out.push({
35
- path: childPath,
36
- description: "Field added",
37
- severity: "unknown",
38
- });
39
- continue;
40
- }
41
- const shouldRecurse = options.deepComparison !== false;
42
- if (shouldRecurse) {
43
- diffValues(oldVal[key], newVal[key], childPath, out, options);
44
- }
45
- }
46
- return;
47
- }
48
- // Arrays
49
- if (Array.isArray(oldVal) && Array.isArray(newVal)) {
50
- // Special handling for UniSpec collections identified by "name"
51
- const _namedCollectionPaths = options.namedCollectionPaths || DEFAULT_NAMED_COLLECTION_PATHS;
52
- const isNamedCollection = (options.namedCollectionPaths || [...DEFAULT_NAMED_COLLECTION_PATHS]).includes(basePath) || basePath.endsWith("/messages"); // Handle messages in channels
53
- if (isNamedCollection) {
54
- const oldByName = new Map();
55
- const newByName = new Map();
56
- for (const item of oldVal) {
57
- if (item && typeof item === "object" && typeof item.name === "string") {
58
- oldByName.set(item.name, item);
59
- }
60
- }
61
- for (const item of newVal) {
62
- if (item && typeof item === "object" && typeof item.name === "string") {
63
- newByName.set(item.name, item);
64
- }
65
- }
66
- // Removed
67
- for (const [name, oldItem] of oldByName.entries()) {
68
- if (!newByName.has(name)) {
69
- out.push({
70
- path: `${basePath}/${name}`,
71
- description: "Item removed",
72
- severity: "unknown",
73
- });
74
- }
75
- else {
76
- const newItem = newByName.get(name);
77
- const shouldRecurse = options.deepComparison !== false;
78
- if (shouldRecurse) {
79
- diffValues(oldItem, newItem, `${basePath}/${name}`, out, options);
80
- }
81
- }
82
- }
83
- // Added
84
- for (const [name, _newItem] of newByName.entries()) {
85
- if (!oldByName.has(name)) {
86
- out.push({
87
- path: `${basePath}/${name}`,
88
- description: "Item added",
89
- severity: "unknown",
90
- });
91
- }
92
- }
93
- return;
94
- }
95
- // Regular array comparison
96
- const maxLength = Math.max(oldVal.length, newVal.length);
97
- for (let i = 0; i < maxLength; i++) {
98
- if (i >= oldVal.length) {
99
- out.push({
100
- path: `${basePath}/${i}`,
101
- description: "Item added",
102
- severity: "unknown",
103
- });
104
- }
105
- else if (i >= newVal.length) {
106
- out.push({
107
- path: `${basePath}/${i}`,
108
- description: "Item removed",
109
- severity: "unknown",
110
- });
111
- }
112
- else {
113
- const shouldRecurse = options.deepComparison !== false;
114
- if (shouldRecurse) {
115
- diffValues(oldVal[i], newVal[i], `${basePath}/${i}`, out, options);
116
- }
117
- }
118
- }
119
- }
120
- // Primitive values or different types
121
- out.push({
122
- path: basePath,
123
- description: "Value changed",
124
- severity: "unknown",
125
- });
126
- }
127
- /**
128
- * Compare two UniSpec documents and return detected changes.
129
- *
130
- * This function performs a deep comparison between two UniSpec documents
131
- * and categorizes changes by severity and protocol. Useful for:
132
- * - API change detection in CI/CD pipelines
133
- * - Breaking change analysis
134
- * - Version compatibility checks
135
- * - Audit trails for API evolution
136
- *
137
- * Features:
138
- * - Detects added/removed fields at any depth
139
- * - Special handling for named collections (routes, operations, channels)
140
- * - Severity classification: "breaking" | "non-breaking" | "unknown"
141
- * - Protocol categorization: "rest" | "graphql" | "websocket"
142
- * - Detailed change descriptions with JSON paths
143
- * - Configurable named collection paths and comparison depth
144
- *
145
- * @param oldDoc - The previous version of the UniSpec document
146
- * @param newDoc - The current version of the UniSpec document
147
- * @param options - Configuration options for diff behavior
148
- * @returns Object containing all detected changes
149
- */
150
- export function diffUniSpec(oldDoc, newDoc, options = {}) {
151
- const changes = [];
152
- diffValues(oldDoc, newDoc, "", changes, options);
153
- const annotated = changes.map((change) => annotateWebSocketChange(annotateGraphQLChange(annotateRestChange(change))));
154
- return { changes: annotated };
155
- }
@@ -1,51 +0,0 @@
1
- import type { UniSpecDocument } from "../types/index.js";
2
- import { type RiskLevel } from "./risk-calculator.js";
3
- import type { UniSpecChange } from "./types.js";
4
- export interface ChangeImpact {
5
- backwardCompatibility: "compatible" | "incompatible" | "unknown";
6
- clientImpact: "none" | "low" | "medium" | "high";
7
- serverImpact: "none" | "low" | "medium" | "high";
8
- migrationComplexity: "none" | "simple" | "moderate" | "complex";
9
- }
10
- export interface EnhancedUniSpecChange extends UniSpecChange {
11
- impact: ChangeImpact;
12
- suggestions: string[];
13
- examples?: {
14
- before: UniSpecDocument;
15
- after: UniSpecDocument;
16
- };
17
- riskLevel: RiskLevel;
18
- }
19
- export interface CompatibilityMetrics {
20
- overallCompatibility: number;
21
- breakingChangesCount: number;
22
- nonBreakingChangesCount: number;
23
- clientCompatibilityScore: number;
24
- serverCompatibilityScore: number;
25
- migrationEffort: "minimal" | "moderate" | "significant" | "major";
26
- }
27
- export interface EnhancedDiffResult {
28
- changes: EnhancedUniSpecChange[];
29
- metrics: CompatibilityMetrics;
30
- summary: {
31
- totalChanges: number;
32
- criticalChanges: number;
33
- highRiskChanges: number;
34
- mediumRiskChanges: number;
35
- lowRiskChanges: number;
36
- };
37
- }
38
- /**
39
- * Perform enhanced diff analysis with impact assessment and compatibility metrics.
40
- *
41
- * This function extends the basic diff functionality with:
42
- * - Detailed impact analysis for each change
43
- * - Compatibility metrics
44
- * - Migration suggestions
45
- * - Risk assessment
46
- *
47
- * @param oldDoc - The previous version of the UniSpec document
48
- * @param newDoc - The current version of the UniSpec document
49
- * @returns Enhanced diff result with comprehensive analysis
50
- */
51
- export declare function diffUniSpecEnhanced(oldDoc: UniSpecDocument, newDoc: UniSpecDocument): EnhancedDiffResult;
@@ -1,76 +0,0 @@
1
- import { diffUniSpec } from "./core.js";
2
- import { ImpactAnalysisStrategyFactory } from "./impact-strategies-refactored.js";
3
- import { MetricsCalculatorService } from "./metrics-calculator.js";
4
- import { RiskLevelCalculator } from "./risk-calculator.js";
5
- import { SuggestionGeneratorService } from "./suggestion-generator.js";
6
- /**
7
- * Service instances for better separation of concerns.
8
- */
9
- const suggestionGenerator = new SuggestionGeneratorService();
10
- const metricsCalculator = new MetricsCalculatorService();
11
- /**
12
- * Generate migration suggestions based on change impact.
13
- * @deprecated Use SuggestionGeneratorService.generateSuggestions instead
14
- */
15
- function generateSuggestions(change, impact) {
16
- return suggestionGenerator.generateSuggestions(change, impact);
17
- }
18
- /**
19
- * Calculate compatibility metrics from enhanced changes.
20
- * @deprecated Use MetricsCalculatorService.calculateMetrics instead
21
- */
22
- function calculateMetrics(changes) {
23
- return metricsCalculator.calculateMetrics(changes);
24
- }
25
- /**
26
- * Perform enhanced diff analysis with impact assessment and compatibility metrics.
27
- *
28
- * This function extends the basic diff functionality with:
29
- * - Detailed impact analysis for each change
30
- * - Compatibility metrics
31
- * - Migration suggestions
32
- * - Risk assessment
33
- *
34
- * @param oldDoc - The previous version of the UniSpec document
35
- * @param newDoc - The current version of the UniSpec document
36
- * @returns Enhanced diff result with comprehensive analysis
37
- */
38
- export function diffUniSpecEnhanced(oldDoc, newDoc) {
39
- // Get basic diff
40
- const basicDiff = diffUniSpec(oldDoc, newDoc);
41
- // Enhance each change with impact analysis using strategy pattern
42
- const enhancedChanges = basicDiff.changes.map((change) => {
43
- // Get appropriate strategy for the protocol
44
- const strategy = ImpactAnalysisStrategyFactory.getStrategy(change.protocol);
45
- // Analyze impact using strategy
46
- const impact = strategy.analyze(change);
47
- // Generate suggestions
48
- const suggestions = generateSuggestions(change, impact);
49
- // Calculate risk level using calculator
50
- const riskLevel = RiskLevelCalculator.calculate(impact);
51
- return {
52
- ...change,
53
- impact,
54
- suggestions,
55
- riskLevel,
56
- };
57
- });
58
- // Calculate metrics
59
- const metrics = calculateMetrics(enhancedChanges);
60
- // Generate summary
61
- const summary = {
62
- totalChanges: enhancedChanges.length,
63
- criticalChanges: enhancedChanges.filter((c) => c.riskLevel === "critical")
64
- .length,
65
- highRiskChanges: enhancedChanges.filter((c) => c.riskLevel === "high")
66
- .length,
67
- mediumRiskChanges: enhancedChanges.filter((c) => c.riskLevel === "medium")
68
- .length,
69
- lowRiskChanges: enhancedChanges.filter((c) => c.riskLevel === "low").length,
70
- };
71
- return {
72
- changes: enhancedChanges,
73
- metrics,
74
- summary,
75
- };
76
- }
@@ -1,69 +0,0 @@
1
- import type { ChangeImpact } from "./enhanced-diff.js";
2
- import type { UniSpecChange } from "./types.js";
3
- /**
4
- * Strategy interface for analyzing change impact.
5
- */
6
- export interface ImpactAnalysisStrategy {
7
- analyze(change: UniSpecChange): ChangeImpact;
8
- }
9
- /**
10
- * Base class for impact analysis strategies with common functionality.
11
- */
12
- declare abstract class BaseImpactStrategy implements ImpactAnalysisStrategy {
13
- protected createDefaultImpact(): ChangeImpact;
14
- protected setBreakingChange(impact: ChangeImpact, clientImpact?: "low" | "medium" | "high", serverImpact?: "low" | "medium" | "high", migrationComplexity?: "simple" | "moderate" | "complex"): ChangeImpact;
15
- protected setNonBreakingChange(impact: ChangeImpact, clientImpact?: "none" | "low" | "medium" | "high", serverImpact?: "none" | "low" | "medium" | "high", migrationComplexity?: "none" | "simple" | "moderate" | "complex"): ChangeImpact;
16
- abstract analyze(change: UniSpecChange): ChangeImpact;
17
- }
18
- /**
19
- * REST route impact analysis strategy.
20
- */
21
- export declare class RestRouteImpactStrategy extends BaseImpactStrategy {
22
- analyze(change: UniSpecChange): ChangeImpact;
23
- private isRouteRemoval;
24
- private isRouteAddition;
25
- private isMethodChange;
26
- private isPathChange;
27
- private isRequiredParameterChange;
28
- private isResponseRemoval;
29
- private isOptionalParameterAddition;
30
- }
31
- /**
32
- * GraphQL operation impact analysis strategy.
33
- */
34
- export declare class GraphQLOperationImpactStrategy extends BaseImpactStrategy {
35
- analyze(change: UniSpecChange): ChangeImpact;
36
- private isOperationRemoval;
37
- private isOperationAddition;
38
- private isReturnTypeChange;
39
- private isOptionalArgumentAddition;
40
- private isRequiredArgumentChange;
41
- }
42
- /**
43
- * WebSocket impact analysis strategy.
44
- */
45
- export declare class WebSocketImpactStrategy extends BaseImpactStrategy {
46
- analyze(change: UniSpecChange): ChangeImpact;
47
- private isChannelRemoval;
48
- private isChannelAddition;
49
- private isMessageRemoval;
50
- private isMessageAddition;
51
- private isMessageSchemaChange;
52
- }
53
- /**
54
- * Default impact analysis strategy for unknown changes.
55
- */
56
- export declare class DefaultImpactStrategy extends BaseImpactStrategy {
57
- analyze(_change: UniSpecChange): ChangeImpact;
58
- }
59
- /**
60
- * Factory for creating impact analysis strategies.
61
- */
62
- declare const ImpactAnalysisStrategyFactory: {
63
- strategies: Map<string, ImpactAnalysisStrategy>;
64
- getStrategy(protocol?: string): ImpactAnalysisStrategy;
65
- registerStrategy(protocol: string, strategy: ImpactAnalysisStrategy): void;
66
- getAvailableStrategies(): string[];
67
- clearStrategies(): void;
68
- };
69
- export { ImpactAnalysisStrategyFactory };
@@ -1,223 +0,0 @@
1
- /**
2
- * Base class for impact analysis strategies with common functionality.
3
- */
4
- class BaseImpactStrategy {
5
- createDefaultImpact() {
6
- return {
7
- backwardCompatibility: "unknown",
8
- clientImpact: "none",
9
- serverImpact: "none",
10
- migrationComplexity: "none",
11
- };
12
- }
13
- setBreakingChange(impact, clientImpact = "high", serverImpact = "medium", migrationComplexity = "moderate") {
14
- impact.backwardCompatibility = "incompatible";
15
- impact.clientImpact = clientImpact;
16
- impact.serverImpact = serverImpact;
17
- impact.migrationComplexity = migrationComplexity;
18
- return impact;
19
- }
20
- setNonBreakingChange(impact, clientImpact = "none", serverImpact = "low", migrationComplexity = "none") {
21
- impact.backwardCompatibility = "compatible";
22
- impact.clientImpact = clientImpact;
23
- impact.serverImpact = serverImpact;
24
- impact.migrationComplexity = migrationComplexity;
25
- return impact;
26
- }
27
- }
28
- /**
29
- * REST route impact analysis strategy.
30
- */
31
- export class RestRouteImpactStrategy extends BaseImpactStrategy {
32
- analyze(change) {
33
- const impact = this.createDefaultImpact();
34
- // Route removal is always breaking
35
- if (this.isRouteRemoval(change)) {
36
- return this.setBreakingChange(impact, "high", "medium", "complex");
37
- }
38
- // Route addition is non-breaking
39
- if (this.isRouteAddition(change)) {
40
- return this.setNonBreakingChange(impact, "none", "low", "none");
41
- }
42
- // Method change is breaking
43
- if (this.isMethodChange(change)) {
44
- return this.setBreakingChange(impact, "high", "medium", "moderate");
45
- }
46
- // Path change is breaking
47
- if (this.isPathChange(change)) {
48
- return this.setBreakingChange(impact, "high", "medium", "moderate");
49
- }
50
- // Required parameter change is breaking
51
- if (this.isRequiredParameterChange(change)) {
52
- return this.setBreakingChange(impact, "medium", "low", "simple");
53
- }
54
- // Response status code removal is breaking
55
- if (this.isResponseRemoval(change)) {
56
- return this.setBreakingChange(impact, "medium", "low", "simple");
57
- }
58
- // Adding optional parameter is non-breaking
59
- if (this.isOptionalParameterAddition(change)) {
60
- return this.setNonBreakingChange(impact, "none", "low", "none");
61
- }
62
- return impact;
63
- }
64
- isRouteRemoval(change) {
65
- return (change.description === "Item removed" &&
66
- !!change.kind?.includes("route.removed"));
67
- }
68
- isRouteAddition(change) {
69
- return (change.description === "Item added" &&
70
- !!change.kind?.includes("route.added"));
71
- }
72
- isMethodChange(change) {
73
- return (change.path.includes("/method") && change.description === "Value changed");
74
- }
75
- isPathChange(change) {
76
- return (change.path.includes("/path") && change.description === "Value changed");
77
- }
78
- isRequiredParameterChange(change) {
79
- return (change.path.includes("/required") &&
80
- change.description === "Value changed");
81
- }
82
- isResponseRemoval(change) {
83
- return (change.path.includes("/responses/") &&
84
- change.description === "Item removed");
85
- }
86
- isOptionalParameterAddition(change) {
87
- return (change.path.includes("/queryParams/") &&
88
- change.description === "Item added");
89
- }
90
- }
91
- /**
92
- * GraphQL operation impact analysis strategy.
93
- */
94
- export class GraphQLOperationImpactStrategy extends BaseImpactStrategy {
95
- analyze(change) {
96
- const impact = this.createDefaultImpact();
97
- // Operation removal is breaking
98
- if (this.isOperationRemoval(change)) {
99
- return this.setBreakingChange(impact, "high", "medium", "complex");
100
- }
101
- // Operation addition is non-breaking
102
- if (this.isOperationAddition(change)) {
103
- return this.setNonBreakingChange(impact, "none", "low", "none");
104
- }
105
- // Return type change is breaking
106
- if (this.isReturnTypeChange(change)) {
107
- return this.setBreakingChange(impact, "high", "medium", "moderate");
108
- }
109
- // Adding optional argument is non-breaking
110
- if (this.isOptionalArgumentAddition(change)) {
111
- return this.setNonBreakingChange(impact, "none", "low", "none");
112
- }
113
- // Making argument required is breaking
114
- if (this.isRequiredArgumentChange(change)) {
115
- return this.setBreakingChange(impact, "medium", "low", "simple");
116
- }
117
- return impact;
118
- }
119
- isOperationRemoval(change) {
120
- return (change.description === "Item removed" &&
121
- !!change.kind?.includes("operation.removed"));
122
- }
123
- isOperationAddition(change) {
124
- return (change.description === "Item added" &&
125
- !!change.kind?.includes("operation.added"));
126
- }
127
- isReturnTypeChange(change) {
128
- return (change.path.includes("/returnType") &&
129
- change.description === "Value changed");
130
- }
131
- isOptionalArgumentAddition(change) {
132
- return (change.path.includes("/args/") && change.description === "Item added");
133
- }
134
- isRequiredArgumentChange(change) {
135
- return (change.path.includes("/args/") &&
136
- change.path.includes("/required") &&
137
- change.description === "Value changed");
138
- }
139
- }
140
- /**
141
- * WebSocket impact analysis strategy.
142
- */
143
- export class WebSocketImpactStrategy extends BaseImpactStrategy {
144
- analyze(change) {
145
- const impact = this.createDefaultImpact();
146
- // Channel removal is breaking
147
- if (this.isChannelRemoval(change)) {
148
- return this.setBreakingChange(impact, "high", "medium", "complex");
149
- }
150
- // Channel addition is non-breaking
151
- if (this.isChannelAddition(change)) {
152
- return this.setNonBreakingChange(impact, "none", "low", "none");
153
- }
154
- // Message removal is breaking
155
- if (this.isMessageRemoval(change)) {
156
- return this.setBreakingChange(impact, "medium", "low", "moderate");
157
- }
158
- // Message addition is non-breaking
159
- if (this.isMessageAddition(change)) {
160
- return this.setNonBreakingChange(impact, "none", "low", "none");
161
- }
162
- // Message schema change is breaking
163
- if (this.isMessageSchemaChange(change)) {
164
- return this.setBreakingChange(impact, "medium", "low", "moderate");
165
- }
166
- return impact;
167
- }
168
- isChannelRemoval(change) {
169
- return (change.description === "Item removed" &&
170
- !!change.kind?.includes("channel.removed"));
171
- }
172
- isChannelAddition(change) {
173
- return (change.description === "Item added" &&
174
- !!change.kind?.includes("channel.added"));
175
- }
176
- isMessageRemoval(change) {
177
- return (change.description === "Item removed" &&
178
- !!change.kind?.includes("message.removed"));
179
- }
180
- isMessageAddition(change) {
181
- return (change.description === "Item added" &&
182
- !!change.kind?.includes("message.added"));
183
- }
184
- isMessageSchemaChange(change) {
185
- return (change.path.includes("/schemaRef") &&
186
- change.description === "Value changed");
187
- }
188
- }
189
- /**
190
- * Default impact analysis strategy for unknown changes.
191
- */
192
- export class DefaultImpactStrategy extends BaseImpactStrategy {
193
- analyze(_change) {
194
- return this.createDefaultImpact();
195
- }
196
- }
197
- /**
198
- * Factory for creating impact analysis strategies.
199
- */
200
- const ImpactAnalysisStrategyFactory = {
201
- strategies: new Map([
202
- ["rest", new RestRouteImpactStrategy()],
203
- ["graphql", new GraphQLOperationImpactStrategy()],
204
- ["websocket", new WebSocketImpactStrategy()],
205
- ]),
206
- getStrategy(protocol) {
207
- if (!protocol) {
208
- return new DefaultImpactStrategy();
209
- }
210
- const strategy = this.strategies.get(protocol);
211
- return strategy || new DefaultImpactStrategy();
212
- },
213
- registerStrategy(protocol, strategy) {
214
- this.strategies.set(protocol, strategy);
215
- },
216
- getAvailableStrategies() {
217
- return Array.from(this.strategies.keys());
218
- },
219
- clearStrategies() {
220
- this.strategies.clear();
221
- },
222
- };
223
- export { ImpactAnalysisStrategyFactory };
@@ -1,41 +0,0 @@
1
- import type { ChangeImpact } from "./enhanced-diff.js";
2
- import type { UniSpecChange } from "./types.js";
3
- /**
4
- * Strategy interface for analyzing change impact.
5
- */
6
- export interface ImpactAnalysisStrategy {
7
- analyze(change: UniSpecChange): ChangeImpact;
8
- }
9
- /**
10
- * REST route impact analysis strategy.
11
- */
12
- export declare class RestRouteImpactStrategy implements ImpactAnalysisStrategy {
13
- analyze(change: UniSpecChange): ChangeImpact;
14
- }
15
- /**
16
- * GraphQL operation impact analysis strategy.
17
- */
18
- export declare class GraphQLOperationImpactStrategy implements ImpactAnalysisStrategy {
19
- analyze(change: UniSpecChange): ChangeImpact;
20
- }
21
- /**
22
- * WebSocket impact analysis strategy.
23
- */
24
- export declare class WebSocketImpactStrategy implements ImpactAnalysisStrategy {
25
- analyze(change: UniSpecChange): ChangeImpact;
26
- }
27
- /**
28
- * Default impact analysis strategy for unknown changes.
29
- */
30
- export declare class DefaultImpactStrategy implements ImpactAnalysisStrategy {
31
- analyze(_change: UniSpecChange): ChangeImpact;
32
- }
33
- /**
34
- * Factory for creating impact analysis strategies.
35
- */
36
- declare const ImpactAnalysisStrategyFactory: {
37
- strategies: Map<string, ImpactAnalysisStrategy>;
38
- getStrategy(protocol?: string): ImpactAnalysisStrategy;
39
- registerStrategy(protocol: string, strategy: ImpactAnalysisStrategy): void;
40
- };
41
- export { ImpactAnalysisStrategyFactory };