@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
@@ -1,154 +0,0 @@
1
- export function annotateRestChange(change) {
2
- // Add defensive check for null/undefined path
3
- if (!change.path || typeof change.path !== "string") {
4
- return change;
5
- }
6
- if (!change.path.startsWith("/service/protocols/rest/routes/")) {
7
- return change;
8
- }
9
- const segments = change.path.split("/").filter(Boolean);
10
- // Expected shape: ["service", "protocols", "rest", "routes", routeName, ...]
11
- if (segments[0] !== "service" ||
12
- segments[1] !== "protocols" ||
13
- segments[2] !== "rest" ||
14
- segments[3] !== "routes") {
15
- return change;
16
- }
17
- const routeName = segments[4];
18
- if (typeof routeName === "undefined") {
19
- return change;
20
- }
21
- const annotated = {
22
- ...change,
23
- protocol: "rest",
24
- };
25
- if (change.description === "Item removed") {
26
- annotated.kind = "rest.route.removed";
27
- annotated.severity = "breaking";
28
- }
29
- else if (change.description === "Item added") {
30
- annotated.kind = "rest.route.added";
31
- annotated.severity = "non-breaking";
32
- }
33
- else if (change.path.includes("/required") &&
34
- change.description === "Value changed") {
35
- // Changing required field from false to true is breaking
36
- annotated.kind = "rest.parameter.required_changed";
37
- annotated.severity = "breaking";
38
- }
39
- return annotated;
40
- }
41
- export function annotateWebSocketChange(change) {
42
- // Add defensive check for null/undefined path
43
- if (!change.path || typeof change.path !== "string") {
44
- return change;
45
- }
46
- if (!change.path.startsWith("/service/protocols/websocket/channels/")) {
47
- return change;
48
- }
49
- const segments = change.path.split("/").filter(Boolean);
50
- // Expected base: ["service","protocols","websocket","channels", channelName, ...]
51
- if (segments[0] !== "service" ||
52
- segments[1] !== "protocols" ||
53
- segments[2] !== "websocket" ||
54
- segments[3] !== "channels") {
55
- return change;
56
- }
57
- const channelName = segments[4];
58
- const next = segments[5];
59
- const annotated = {
60
- ...change,
61
- protocol: "websocket",
62
- };
63
- if (typeof channelName === "undefined") {
64
- return annotated;
65
- }
66
- // Channel-level changes: /service/protocols/websocket/channels/{channelName}
67
- if (!next) {
68
- if (change.description === "Item removed") {
69
- annotated.kind = "websocket.channel.removed";
70
- annotated.severity = "breaking";
71
- }
72
- else if (change.description === "Item added") {
73
- annotated.kind = "websocket.channel.added";
74
- annotated.severity = "non-breaking";
75
- }
76
- return annotated;
77
- }
78
- // Message-level changes: /service/protocols/websocket/channels/{channelName}/messages/{messageName}
79
- if (next === "messages") {
80
- const messageName = segments[6];
81
- if (typeof messageName === "undefined") {
82
- return annotated;
83
- }
84
- if (change.description === "Item removed") {
85
- annotated.kind = "websocket.message.removed";
86
- annotated.severity = "breaking";
87
- }
88
- else if (change.description === "Item added") {
89
- annotated.kind = "websocket.message.added";
90
- annotated.severity = "non-breaking";
91
- }
92
- }
93
- return annotated;
94
- }
95
- export function annotateGraphQLChange(change) {
96
- // Add defensive check for null/undefined path
97
- if (!change.path || typeof change.path !== "string") {
98
- return change;
99
- }
100
- if (!change.path.startsWith("/service/protocols/graphql/")) {
101
- return change;
102
- }
103
- const segments = change.path.split("/").filter(Boolean);
104
- // Expected: ["service","protocols","graphql", operationType, operationName, ...]
105
- if (segments[0] !== "service" ||
106
- segments[1] !== "protocols" ||
107
- segments[2] !== "graphql") {
108
- return change;
109
- }
110
- const operationType = segments[3];
111
- const operationName = segments[4];
112
- if (!operationType || typeof operationName === "undefined") {
113
- return change;
114
- }
115
- if (operationType !== "queries" &&
116
- operationType !== "mutations" &&
117
- operationType !== "subscriptions") {
118
- return change;
119
- }
120
- const annotated = {
121
- ...change,
122
- protocol: "graphql",
123
- };
124
- // Create operation-specific annotations
125
- const singularMap = {
126
- queries: "query",
127
- mutations: "mutation",
128
- subscriptions: "subscription"
129
- };
130
- const operationKind = `graphql.${singularMap[operationType]}`;
131
- // Check for specific changes first, then general ones
132
- if (change.path.includes("/returnType") &&
133
- change.description === "Value changed") {
134
- // Changing return type is breaking
135
- annotated.kind = `${operationKind}.return_type_changed`;
136
- annotated.severity = "breaking";
137
- }
138
- else if (change.path.includes("/args") &&
139
- (change.description === "Item added" || change.description === "Item removed")) {
140
- // Argument changes
141
- const action = change.description === "Item added" ? "added" : "removed";
142
- annotated.kind = `${operationKind}.argument_${action}`;
143
- annotated.severity = action === "added" ? "non-breaking" : "breaking";
144
- }
145
- else if (change.description === "Item removed") {
146
- annotated.kind = `${operationKind}.removed`;
147
- annotated.severity = "breaking";
148
- }
149
- else if (change.description === "Item added") {
150
- annotated.kind = `${operationKind}.added`;
151
- annotated.severity = "non-breaking";
152
- }
153
- return annotated;
154
- }
@@ -1,37 +0,0 @@
1
- import type { EnhancedDiffResult, EnhancedUniSpecChange } from "./enhanced-diff.js";
2
- export interface ReportOptions {
3
- format: "markdown" | "html" | "json";
4
- includeSuggestions?: boolean;
5
- includeExamples?: boolean;
6
- groupByRisk?: boolean;
7
- groupByProtocol?: boolean;
8
- title?: string;
9
- versionInfo?: {
10
- oldVersion?: string;
11
- newVersion?: string;
12
- comparisonDate?: string;
13
- };
14
- }
15
- export interface ChangeReport {
16
- title: string;
17
- summary: {
18
- totalChanges: number;
19
- breakingChanges: number;
20
- compatibilityScore: number;
21
- migrationEffort: string;
22
- };
23
- sections: ReportSection[];
24
- }
25
- export interface ReportSection {
26
- title: string;
27
- changes: EnhancedUniSpecChange[];
28
- summary: string;
29
- }
30
- /**
31
- * Generate a comprehensive change report.
32
- *
33
- * @param diff - Enhanced diff result
34
- * @param options - Report generation options
35
- * @returns Formatted report in the specified format
36
- */
37
- export declare function generateChangeReport(diff: EnhancedDiffResult, options: ReportOptions): string;
@@ -1,366 +0,0 @@
1
- /**
2
- * Generate a markdown report from enhanced diff result.
3
- */
4
- function generateMarkdownReport(diff, options) {
5
- const lines = [];
6
- // Title and metadata
7
- lines.push(`# ${options.title || "UniSpec Changes Report"}`);
8
- lines.push("");
9
- if (options.versionInfo) {
10
- lines.push("## Version Information");
11
- if (options.versionInfo.oldVersion) {
12
- lines.push(`- **From:** ${options.versionInfo.oldVersion}`);
13
- }
14
- if (options.versionInfo.newVersion) {
15
- lines.push(`- **To:** ${options.versionInfo.newVersion}`);
16
- }
17
- if (options.versionInfo.comparisonDate) {
18
- lines.push(`- **Date:** ${options.versionInfo.comparisonDate}`);
19
- }
20
- lines.push("");
21
- }
22
- // Executive summary
23
- lines.push("## Executive Summary");
24
- lines.push("");
25
- lines.push(`- **Total Changes:** ${diff.summary.totalChanges}`);
26
- lines.push(`- **Critical Changes:** ${diff.summary.criticalChanges}`);
27
- lines.push(`- **High Risk Changes:** ${diff.summary.highRiskChanges}`);
28
- lines.push(`- **Compatibility Score:** ${diff.metrics.overallCompatibility}%`);
29
- lines.push(`- **Migration Effort:** ${diff.metrics.migrationEffort}`);
30
- lines.push("");
31
- // Compatibility metrics
32
- lines.push("## Compatibility Metrics");
33
- lines.push("");
34
- lines.push("| Metric | Score | Status |");
35
- lines.push("|--------|-------|--------|");
36
- const overallStatus = diff.metrics.overallCompatibility >= 80
37
- ? "✅ Good"
38
- : diff.metrics.overallCompatibility >= 60
39
- ? "⚠️ Moderate"
40
- : "❌ Poor";
41
- lines.push(`| Overall Compatibility | ${diff.metrics.overallCompatibility}% | ${overallStatus} |`);
42
- const clientStatus = diff.metrics.clientCompatibilityScore >= 80
43
- ? "✅ Good"
44
- : diff.metrics.clientCompatibilityScore >= 60
45
- ? "⚠️ Moderate"
46
- : "❌ Poor";
47
- lines.push(`| Client Compatibility | ${diff.metrics.clientCompatibilityScore}% | ${clientStatus} |`);
48
- const serverStatus = diff.metrics.serverCompatibilityScore >= 80
49
- ? "✅ Good"
50
- : diff.metrics.serverCompatibilityScore >= 60
51
- ? "⚠️ Moderate"
52
- : "❌ Poor";
53
- lines.push(`| Server Compatibility | ${diff.metrics.serverCompatibilityScore}% | ${serverStatus} |`);
54
- lines.push("");
55
- // Group changes
56
- const groupedChanges = groupChanges(diff.changes, options);
57
- for (const section of groupedChanges) {
58
- lines.push(`## ${section.title}`);
59
- lines.push("");
60
- lines.push(section.summary);
61
- lines.push("");
62
- if (section.changes.length === 0) {
63
- lines.push("No changes in this category.");
64
- lines.push("");
65
- continue;
66
- }
67
- for (const change of section.changes) {
68
- lines.push(`### ${getChangeIcon(change.riskLevel)} ${getChangeTitle(change)}`);
69
- lines.push("");
70
- lines.push(`- **Path:** \`${change.path}\``);
71
- lines.push(`- **Protocol:** ${change.protocol || "Unknown"}`);
72
- lines.push(`- **Risk Level:** ${change.riskLevel.toUpperCase()}`);
73
- lines.push(`- **Impact:** ${formatImpact(change.impact)}`);
74
- lines.push("");
75
- if (change.description) {
76
- lines.push(`**Description:** ${change.description}`);
77
- lines.push("");
78
- }
79
- if (options.includeSuggestions && change.suggestions.length > 0) {
80
- lines.push("**Migration Suggestions:**");
81
- for (const suggestion of change.suggestions) {
82
- lines.push(`- ${suggestion}`);
83
- }
84
- lines.push("");
85
- }
86
- }
87
- }
88
- // Migration recommendations
89
- if (diff.summary.criticalChanges > 0 || diff.summary.highRiskChanges > 0) {
90
- lines.push("## Migration Recommendations");
91
- lines.push("");
92
- if (diff.summary.criticalChanges > 0) {
93
- lines.push("⚠️ **Critical Changes Detected**");
94
- lines.push("");
95
- lines.push("Immediate action required:");
96
- lines.push("- Review all critical changes");
97
- lines.push("- Plan migration strategy");
98
- lines.push("- Communicate changes to all stakeholders");
99
- lines.push("- Consider feature flags for gradual rollout");
100
- lines.push("");
101
- }
102
- if (diff.metrics.migrationEffort === "major") {
103
- lines.push("🔧 **Major Migration Effort**");
104
- lines.push("");
105
- lines.push("Recommended approach:");
106
- lines.push("- Break migration into phases");
107
- lines.push("- Use parallel development");
108
- lines.push("- Implement comprehensive testing");
109
- lines.push("- Provide detailed migration guides");
110
- lines.push("");
111
- }
112
- }
113
- return lines.join("\n");
114
- }
115
- /**
116
- * Generate an HTML report from enhanced diff result.
117
- */
118
- function generateHtmlReport(diff, options) {
119
- const styles = `
120
- <style>
121
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 40px; }
122
- .header { border-bottom: 2px solid #e1e5e9; padding-bottom: 20px; margin-bottom: 30px; }
123
- .metric { display: inline-block; margin: 10px 20px 10px 0; text-align: center; }
124
- .metric-value { font-size: 2em; font-weight: bold; display: block; }
125
- .metric-label { color: #666; font-size: 0.9em; }
126
- .critical { color: #dc3545; }
127
- .high { color: #fd7e14; }
128
- .medium { color: #ffc107; }
129
- .low { color: #28a745; }
130
- .change { border: 1px solid #e1e5e9; border-radius: 8px; padding: 20px; margin: 20px 0; }
131
- .change-header { font-weight: bold; margin-bottom: 10px; }
132
- .suggestions { background: #f8f9fa; padding: 15px; border-radius: 5px; margin-top: 10px; }
133
- .compatibility-bar { height: 20px; background: #e9ecef; border-radius: 10px; overflow: hidden; margin: 10px 0; }
134
- .compatibility-fill { height: 100%; transition: width 0.3s ease; }
135
- </style>
136
- `;
137
- const groupedChanges = groupChanges(diff.changes, options);
138
- let html = `
139
- <!DOCTYPE html>
140
- <html>
141
- <head>
142
- <title>${options.title || "UniSpec Changes Report"}</title>
143
- ${styles}
144
- </head>
145
- <body>
146
- <div class="header">
147
- <h1>${options.title || "UniSpec Changes Report"}</h1>
148
- <p>Generated on ${new Date().toLocaleDateString()}</p>
149
- </div>
150
-
151
- <div class="summary">
152
- <h2>Executive Summary</h2>
153
- <div class="metric">
154
- <span class="metric-value">${diff.summary.totalChanges}</span>
155
- <span class="metric-label">Total Changes</span>
156
- </div>
157
- <div class="metric">
158
- <span class="metric-value critical">${diff.summary.criticalChanges}</span>
159
- <span class="metric-label">Critical</span>
160
- </div>
161
- <div class="metric">
162
- <span class="metric-value high">${diff.summary.highRiskChanges}</span>
163
- <span class="metric-label">High Risk</span>
164
- </div>
165
- <div class="metric">
166
- <span class="metric-value">${diff.metrics.overallCompatibility}%</span>
167
- <span class="metric-label">Compatibility</span>
168
- </div>
169
- </div>
170
-
171
- <div class="compatibility">
172
- <h2>Compatibility Metrics</h2>
173
- <div>
174
- <strong>Overall Compatibility: ${diff.metrics.overallCompatibility}%</strong>
175
- <div class="compatibility-bar">
176
- <div class="compatibility-fill ${getCompatibilityClass(diff.metrics.overallCompatibility)}"
177
- style="width: ${diff.metrics.overallCompatibility}%"></div>
178
- </div>
179
- </div>
180
- <div>
181
- <strong>Client Compatibility: ${diff.metrics.clientCompatibilityScore}%</strong>
182
- <div class="compatibility-bar">
183
- <div class="compatibility-fill ${getCompatibilityClass(diff.metrics.clientCompatibilityScore)}"
184
- style="width: ${diff.metrics.clientCompatibilityScore}%"></div>
185
- </div>
186
- </div>
187
- <div>
188
- <strong>Server Compatibility: ${diff.metrics.serverCompatibilityScore}%</strong>
189
- <div class="compatibility-bar">
190
- <div class="compatibility-fill ${getCompatibilityClass(diff.metrics.serverCompatibilityScore)}"
191
- style="width: ${diff.metrics.serverCompatibilityScore}%"></div>
192
- </div>
193
- </div>
194
- </div>
195
- `;
196
- for (const section of groupedChanges) {
197
- html += `
198
- <div class="section">
199
- <h2>${section.title}</h2>
200
- <p>${section.summary}</p>
201
- `;
202
- for (const change of section.changes) {
203
- html += `
204
- <div class="change ${change.riskLevel}">
205
- <div class="change-header">
206
- ${getChangeIcon(change.riskLevel)} ${getChangeTitle(change)}
207
- </div>
208
- <p><strong>Path:</strong> <code>${change.path}</code></p>
209
- <p><strong>Protocol:</strong> ${change.protocol || "Unknown"}</p>
210
- <p><strong>Risk Level:</strong> <span class="${change.riskLevel}">${change.riskLevel.toUpperCase()}</span></p>
211
- <p><strong>Description:</strong> ${change.description}</p>
212
- <p><strong>Impact:</strong> ${formatImpact(change.impact)}</p>
213
- `;
214
- if (options.includeSuggestions && change.suggestions.length > 0) {
215
- html += `
216
- <div class="suggestions">
217
- <strong>Migration Suggestions:</strong>
218
- <ul>
219
- `;
220
- for (const suggestion of change.suggestions) {
221
- html += `<li>${suggestion}</li>`;
222
- }
223
- html += `
224
- </ul>
225
- </div>
226
- `;
227
- }
228
- html += `
229
- </div>
230
- `;
231
- }
232
- html += `
233
- </div>
234
- `;
235
- }
236
- html += `
237
- </body>
238
- </html>
239
- `;
240
- return html;
241
- }
242
- /**
243
- * Group changes by risk level or protocol.
244
- */
245
- function groupChanges(changes, options) {
246
- const sections = [];
247
- if (options.groupByRisk) {
248
- const riskGroups = {
249
- critical: changes.filter((c) => c.riskLevel === "critical"),
250
- high: changes.filter((c) => c.riskLevel === "high"),
251
- medium: changes.filter((c) => c.riskLevel === "medium"),
252
- low: changes.filter((c) => c.riskLevel === "low"),
253
- };
254
- for (const [risk, riskChanges] of Object.entries(riskGroups)) {
255
- sections.push({
256
- title: `${risk.charAt(0).toUpperCase() + risk.slice(1)} Risk Changes`,
257
- changes: riskChanges,
258
- summary: `${riskChanges.length} ${risk} risk changes that ${getRiskDescription(risk)}.`,
259
- });
260
- }
261
- }
262
- if (options.groupByProtocol) {
263
- const protocolGroups = {
264
- rest: changes.filter((c) => c.protocol === "rest"),
265
- graphql: changes.filter((c) => c.protocol === "graphql"),
266
- websocket: changes.filter((c) => c.protocol === "websocket"),
267
- other: changes.filter((c) => !c.protocol || !["rest", "graphql", "websocket"].includes(c.protocol)),
268
- };
269
- for (const [protocol, protocolChanges] of Object.entries(protocolGroups)) {
270
- if (protocolChanges.length > 0) {
271
- sections.push({
272
- title: `${protocol.charAt(0).toUpperCase() + protocol.slice(1)} Protocol Changes`,
273
- changes: protocolChanges,
274
- summary: `${protocolChanges.length} changes affecting ${protocol} protocol.`,
275
- });
276
- }
277
- }
278
- }
279
- // If no grouping, create a single section
280
- if (sections.length === 0) {
281
- sections.push({
282
- title: "All Changes",
283
- changes,
284
- summary: `${changes.length} total changes detected.`,
285
- });
286
- }
287
- return sections;
288
- }
289
- /**
290
- * Helper functions for formatting.
291
- */
292
- function getChangeIcon(riskLevel) {
293
- switch (riskLevel) {
294
- case "critical":
295
- return "🚨";
296
- case "high":
297
- return "⚠️";
298
- case "medium":
299
- return "⚡";
300
- case "low":
301
- return "✅";
302
- default:
303
- return "📝";
304
- }
305
- }
306
- function getChangeTitle(change) {
307
- const parts = change.path.split("/").filter(Boolean);
308
- const lastPart = parts[parts.length - 1];
309
- if (change.kind) {
310
- return `${change.kind.replace(/\./g, " ").toUpperCase()} - ${lastPart}`;
311
- }
312
- return `${change.description} - ${lastPart}`;
313
- }
314
- function formatImpact(impact) {
315
- const parts = [];
316
- if (impact.backwardCompatibility !== "unknown") {
317
- parts.push(`Compatibility: ${impact.backwardCompatibility}`);
318
- }
319
- if (impact.clientImpact !== "none") {
320
- parts.push(`Client: ${impact.clientImpact}`);
321
- }
322
- if (impact.serverImpact !== "none") {
323
- parts.push(`Server: ${impact.serverImpact}`);
324
- }
325
- return parts.join(", ");
326
- }
327
- function getRiskDescription(risk) {
328
- switch (risk) {
329
- case "critical":
330
- return "require immediate attention and breaking changes";
331
- case "high":
332
- return "involve breaking changes or significant impact";
333
- case "medium":
334
- return "require attention but are manageable";
335
- case "low":
336
- return "are minor and easily handled";
337
- default:
338
- return "have unknown impact";
339
- }
340
- }
341
- function getCompatibilityClass(score) {
342
- if (score >= 80)
343
- return "low";
344
- if (score >= 60)
345
- return "medium";
346
- return "high";
347
- }
348
- /**
349
- * Generate a comprehensive change report.
350
- *
351
- * @param diff - Enhanced diff result
352
- * @param options - Report generation options
353
- * @returns Formatted report in the specified format
354
- */
355
- export function generateChangeReport(diff, options) {
356
- switch (options.format) {
357
- case "markdown":
358
- return generateMarkdownReport(diff, options);
359
- case "html":
360
- return generateHtmlReport(diff, options);
361
- case "json":
362
- return JSON.stringify(diff, null, 2);
363
- default:
364
- throw new Error(`Unsupported format: ${options.format}`);
365
- }
366
- }
@@ -1,26 +0,0 @@
1
- import type { UniSpecDocument } from "../types/index.js";
2
- import { type DiffOptions, type DiffResult } from "./types.js";
3
- /**
4
- * Compare two UniSpec documents and return detected changes.
5
- *
6
- * This function performs a deep comparison between two UniSpec documents
7
- * and categorizes changes by severity and protocol. Useful for:
8
- * - API change detection in CI/CD pipelines
9
- * - Breaking change analysis
10
- * - Version compatibility checks
11
- * - Audit trails for API evolution
12
- *
13
- * Features:
14
- * - Detects added/removed fields at any depth
15
- * - Special handling for named collections (routes, operations, channels)
16
- * - Severity classification: "breaking" | "non-breaking" | "unknown"
17
- * - Protocol categorization: "rest" | "graphql" | "websocket"
18
- * - Detailed change descriptions with JSON paths
19
- * - Configurable named collection paths and comparison depth
20
- *
21
- * @param oldDoc - The previous version of the UniSpec document
22
- * @param newDoc - The current version of the UniSpec document
23
- * @param options - Configuration options for diff behavior
24
- * @returns Object containing all detected changes
25
- */
26
- export declare function diffUniSpec(oldDoc: UniSpecDocument, newDoc: UniSpecDocument, options?: DiffOptions): DiffResult;