@unispechq/unispec-core 0.3.0 → 0.3.2

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 (306) hide show
  1. package/dist/cjs/diff/annotators.js +36 -9
  2. package/dist/cjs/src/cache/cache-factory.js +72 -0
  3. package/dist/cjs/src/cache/cache-manager.js +128 -0
  4. package/dist/cjs/src/cache/constants.js +25 -0
  5. package/dist/cjs/src/cache/hash-utils.js +19 -0
  6. package/dist/cjs/src/cache/hashing.js +230 -0
  7. package/dist/cjs/src/cache/index.js +24 -0
  8. package/dist/cjs/src/cache/lru-cache.js +144 -0
  9. package/dist/cjs/src/cache/types.js +5 -0
  10. package/dist/cjs/src/diff/annotators.js +160 -0
  11. package/dist/cjs/src/diff/change-reports.js +369 -0
  12. package/dist/cjs/src/diff/core.js +158 -0
  13. package/dist/cjs/src/diff/enhanced-diff.js +65 -0
  14. package/dist/cjs/src/diff/impact-strategies-refactored.js +230 -0
  15. package/dist/cjs/src/diff/impact-strategies.js +219 -0
  16. package/dist/cjs/src/diff/index.js +27 -0
  17. package/dist/cjs/src/diff/metrics-calculator.js +69 -0
  18. package/dist/cjs/src/diff/risk-calculator.js +58 -0
  19. package/dist/cjs/src/diff/suggestion-generator.js +78 -0
  20. package/dist/cjs/src/diff/types.js +11 -0
  21. package/dist/cjs/src/errors/base-error.js +33 -0
  22. package/dist/cjs/src/errors/config-error.js +11 -0
  23. package/dist/cjs/src/errors/error-factory.js +48 -0
  24. package/dist/cjs/src/errors/index.js +19 -0
  25. package/dist/cjs/src/errors/loader-error.js +11 -0
  26. package/dist/cjs/src/errors/reference-error.js +11 -0
  27. package/dist/cjs/src/errors/schema-error.js +11 -0
  28. package/dist/cjs/src/errors/security-error.js +11 -0
  29. package/dist/cjs/src/errors/semantic-error.js +11 -0
  30. package/dist/cjs/src/generated-schemas.js +2100 -0
  31. package/dist/cjs/src/index.js +59 -0
  32. package/dist/cjs/src/loader/index.js +13 -0
  33. package/dist/cjs/src/loader/security-validator.js +53 -0
  34. package/dist/cjs/src/loader/types.js +11 -0
  35. package/dist/cjs/src/loader/unispec-loader.js +84 -0
  36. package/dist/cjs/src/loader/yaml-loader.js +76 -0
  37. package/dist/cjs/src/normalizer/core.js +37 -0
  38. package/dist/cjs/src/normalizer/graphql-normalizer.js +67 -0
  39. package/dist/cjs/src/normalizer/index.js +7 -0
  40. package/dist/cjs/src/normalizer/rest-normalizer.js +51 -0
  41. package/dist/cjs/src/normalizer/types.js +2 -0
  42. package/dist/cjs/src/normalizer/utils.js +49 -0
  43. package/dist/cjs/src/normalizer/websocket-normalizer.js +81 -0
  44. package/dist/cjs/src/optimizer/core.js +140 -0
  45. package/dist/cjs/src/optimizer/index.js +17 -0
  46. package/dist/cjs/src/optimizer/optimization-functions.js +185 -0
  47. package/dist/cjs/src/optimizer/types.js +2 -0
  48. package/dist/cjs/src/optimizer/utils.js +32 -0
  49. package/dist/cjs/src/schemas/dedupe.js +113 -0
  50. package/dist/cjs/src/schemas/index.js +14 -0
  51. package/dist/cjs/src/schemas/resolver.js +42 -0
  52. package/dist/cjs/src/schemas/utils.js +53 -0
  53. package/dist/cjs/src/types/index.js +2 -0
  54. package/dist/cjs/src/validator/ajv-validator.js +82 -0
  55. package/dist/cjs/src/validator/config-validator-main.js +34 -0
  56. package/dist/cjs/src/validator/config-validator.js +17 -0
  57. package/dist/cjs/src/validator/index.js +23 -0
  58. package/dist/cjs/src/validator/object-traversal.js +112 -0
  59. package/dist/cjs/src/validator/reference-validator.js +233 -0
  60. package/dist/cjs/src/validator/schema-references.js +116 -0
  61. package/dist/cjs/src/validator/semantic-validator.js +328 -0
  62. package/dist/cjs/src/validator/tests-validator.js +16 -0
  63. package/dist/cjs/src/validator/types.js +2 -0
  64. package/dist/cjs/src/validator/unispec-validator.js +80 -0
  65. package/dist/cjs/src/validator/validator-factory.js +77 -0
  66. package/dist/cjs/src/versions.js +147 -0
  67. package/dist/cjs/tests/cache/cache.test.js +274 -0
  68. package/dist/cjs/tests/cache/utils.js +32 -0
  69. package/dist/cjs/tests/concurrency-normalizer-optimizer.test.js +1 -0
  70. package/dist/cjs/tests/diff/diff-annotators.test.js +280 -0
  71. package/dist/cjs/tests/diff/diff-comprehensive.test.js +262 -0
  72. package/dist/cjs/tests/diff/diff-extended.test.js +235 -0
  73. package/dist/cjs/tests/diff/diff.test.js +189 -0
  74. package/dist/cjs/tests/diff/utils.js +8 -0
  75. package/dist/cjs/tests/errors/errors-integration.test.js +173 -0
  76. package/dist/cjs/tests/errors/errors.test.js +280 -0
  77. package/dist/cjs/tests/errors/utils.js +7 -0
  78. package/dist/cjs/tests/loader/integration.test.js +216 -0
  79. package/dist/cjs/tests/loader/loader.test.js +341 -0
  80. package/dist/cjs/tests/normalizer/normalizer-comprehensive.test.js +648 -0
  81. package/dist/cjs/tests/normalizer/normalizer-invalid.test.js +258 -0
  82. package/dist/cjs/tests/normalizer/normalizer-valid.test.js +238 -0
  83. package/dist/cjs/tests/normalizer/utils.js +47 -0
  84. package/dist/cjs/tests/optimizer/compress-references.test.js +304 -0
  85. package/dist/cjs/tests/optimizer/deduplication.test.js +132 -0
  86. package/dist/cjs/tests/optimizer/integration.test.js +131 -0
  87. package/dist/cjs/tests/optimizer/optimization-report.test.js +222 -0
  88. package/dist/cjs/tests/optimizer/optimize-document.test.js +187 -0
  89. package/dist/cjs/tests/optimizer/orphaned-schemas.test.js +194 -0
  90. package/dist/cjs/tests/optimizer/sort-schemas.test.js +131 -0
  91. package/dist/cjs/tests/optimizer/utils.js +209 -0
  92. package/dist/cjs/tests/schemas/schemas-edge-cases.test.js +223 -0
  93. package/dist/cjs/tests/schemas/schemas.test.js +400 -0
  94. package/dist/cjs/tests/schemas/utils.js +7 -0
  95. package/dist/cjs/tests/utils.js +131 -0
  96. package/dist/cjs/tests/validator/config-validator.test.js +78 -0
  97. package/dist/cjs/tests/validator/debug-config.js +1 -0
  98. package/dist/cjs/tests/validator/debug-missing-service.js +1 -0
  99. package/dist/cjs/tests/validator/debug-other-configs.js +1 -0
  100. package/dist/cjs/tests/validator/debug-references.js +1 -0
  101. package/dist/cjs/tests/validator/unispec-validator.test.js +103 -0
  102. package/dist/cjs/tests/validator/utils.js +25 -0
  103. package/dist/diff/annotators.js +36 -9
  104. package/dist/src/cache/cache-factory.d.ts +31 -0
  105. package/dist/src/cache/cache-factory.js +65 -0
  106. package/dist/src/cache/cache-manager.d.ts +62 -0
  107. package/dist/src/cache/cache-manager.js +124 -0
  108. package/dist/src/cache/constants.d.ts +21 -0
  109. package/dist/src/cache/constants.js +22 -0
  110. package/dist/src/cache/hash-utils.d.ts +11 -0
  111. package/dist/src/cache/hash-utils.js +15 -0
  112. package/dist/src/cache/hashing.d.ts +28 -0
  113. package/dist/src/cache/hashing.js +193 -0
  114. package/dist/src/cache/index.d.ts +6 -0
  115. package/dist/src/cache/index.js +10 -0
  116. package/dist/src/cache/lru-cache.d.ts +44 -0
  117. package/dist/src/cache/lru-cache.js +140 -0
  118. package/dist/src/cache/types.d.ts +24 -0
  119. package/dist/src/cache/types.js +4 -0
  120. package/dist/src/diff/annotators.d.ts +4 -0
  121. package/dist/src/diff/annotators.js +155 -0
  122. package/dist/src/diff/change-reports.d.ts +37 -0
  123. package/dist/src/diff/change-reports.js +366 -0
  124. package/dist/src/diff/core.d.ts +26 -0
  125. package/dist/src/diff/core.js +155 -0
  126. package/dist/src/diff/enhanced-diff.d.ts +51 -0
  127. package/dist/src/diff/enhanced-diff.js +62 -0
  128. package/dist/src/diff/impact-strategies-refactored.d.ts +69 -0
  129. package/dist/src/diff/impact-strategies-refactored.js +223 -0
  130. package/dist/src/diff/impact-strategies.d.ts +41 -0
  131. package/dist/src/diff/impact-strategies.js +212 -0
  132. package/dist/src/diff/index.d.ts +8 -0
  133. package/dist/src/diff/index.js +11 -0
  134. package/dist/src/diff/metrics-calculator.d.ts +23 -0
  135. package/dist/src/diff/metrics-calculator.js +65 -0
  136. package/dist/src/diff/risk-calculator.d.ts +23 -0
  137. package/dist/src/diff/risk-calculator.js +55 -0
  138. package/dist/src/diff/suggestion-generator.d.ts +18 -0
  139. package/dist/src/diff/suggestion-generator.js +74 -0
  140. package/dist/src/diff/types.d.ts +24 -0
  141. package/dist/src/diff/types.js +8 -0
  142. package/dist/src/errors/base-error.d.ts +20 -0
  143. package/dist/src/errors/base-error.js +29 -0
  144. package/dist/src/errors/config-error.d.ts +4 -0
  145. package/dist/src/errors/config-error.js +7 -0
  146. package/dist/src/errors/error-factory.d.ts +22 -0
  147. package/dist/src/errors/error-factory.js +45 -0
  148. package/dist/src/errors/index.d.ts +8 -0
  149. package/dist/src/errors/index.js +8 -0
  150. package/dist/src/errors/loader-error.d.ts +4 -0
  151. package/dist/src/errors/loader-error.js +7 -0
  152. package/dist/src/errors/reference-error.d.ts +4 -0
  153. package/dist/src/errors/reference-error.js +7 -0
  154. package/dist/src/errors/schema-error.d.ts +4 -0
  155. package/dist/src/errors/schema-error.js +7 -0
  156. package/dist/src/errors/security-error.d.ts +4 -0
  157. package/dist/src/errors/security-error.js +7 -0
  158. package/dist/src/errors/semantic-error.d.ts +4 -0
  159. package/dist/src/errors/semantic-error.js +7 -0
  160. package/dist/src/generated-schemas.d.ts +2073 -0
  161. package/dist/src/generated-schemas.js +2097 -0
  162. package/dist/src/index.d.ts +13 -0
  163. package/dist/src/index.js +43 -0
  164. package/dist/src/loader/index.d.ts +5 -0
  165. package/dist/src/loader/index.js +5 -0
  166. package/dist/src/loader/security-validator.d.ts +5 -0
  167. package/dist/src/loader/security-validator.js +50 -0
  168. package/dist/src/loader/types.d.ts +30 -0
  169. package/dist/src/loader/types.js +8 -0
  170. package/dist/src/loader/unispec-loader.d.ts +10 -0
  171. package/dist/src/loader/unispec-loader.js +81 -0
  172. package/dist/src/loader/yaml-loader.d.ts +10 -0
  173. package/dist/src/loader/yaml-loader.js +39 -0
  174. package/dist/src/normalizer/core.d.ts +24 -0
  175. package/dist/src/normalizer/core.js +34 -0
  176. package/dist/src/normalizer/graphql-normalizer.d.ts +8 -0
  177. package/dist/src/normalizer/graphql-normalizer.js +64 -0
  178. package/dist/src/normalizer/index.d.ts +2 -0
  179. package/dist/src/normalizer/index.js +3 -0
  180. package/dist/src/normalizer/rest-normalizer.d.ts +8 -0
  181. package/dist/src/normalizer/rest-normalizer.js +48 -0
  182. package/dist/src/normalizer/types.d.ts +7 -0
  183. package/dist/src/normalizer/types.js +1 -0
  184. package/dist/src/normalizer/utils.d.ts +17 -0
  185. package/dist/src/normalizer/utils.js +45 -0
  186. package/dist/src/normalizer/websocket-normalizer.d.ts +8 -0
  187. package/dist/src/normalizer/websocket-normalizer.js +78 -0
  188. package/dist/src/optimizer/core.d.ts +17 -0
  189. package/dist/src/optimizer/core.js +136 -0
  190. package/dist/src/optimizer/index.d.ts +4 -0
  191. package/dist/src/optimizer/index.js +7 -0
  192. package/dist/src/optimizer/optimization-functions.d.ts +32 -0
  193. package/dist/src/optimizer/optimization-functions.js +179 -0
  194. package/dist/src/optimizer/types.d.ts +28 -0
  195. package/dist/src/optimizer/types.js +1 -0
  196. package/dist/src/optimizer/utils.d.ts +7 -0
  197. package/dist/src/optimizer/utils.js +29 -0
  198. package/dist/src/schemas/dedupe.d.ts +9 -0
  199. package/dist/src/schemas/dedupe.js +110 -0
  200. package/dist/src/schemas/index.d.ts +3 -0
  201. package/dist/src/schemas/index.js +6 -0
  202. package/dist/src/schemas/resolver.d.ts +19 -0
  203. package/dist/src/schemas/resolver.js +38 -0
  204. package/dist/src/schemas/utils.d.ts +20 -0
  205. package/dist/src/schemas/utils.js +49 -0
  206. package/dist/src/types/index.d.ts +434 -0
  207. package/dist/src/types/index.js +1 -0
  208. package/dist/src/validator/ajv-validator.d.ts +15 -0
  209. package/dist/src/validator/ajv-validator.js +75 -0
  210. package/dist/src/validator/config-validator-main.d.ts +10 -0
  211. package/dist/src/validator/config-validator-main.js +31 -0
  212. package/dist/src/validator/config-validator.d.ts +5 -0
  213. package/dist/src/validator/config-validator.js +14 -0
  214. package/dist/src/validator/index.d.ts +10 -0
  215. package/dist/src/validator/index.js +11 -0
  216. package/dist/src/validator/object-traversal.d.ts +52 -0
  217. package/dist/src/validator/object-traversal.js +104 -0
  218. package/dist/src/validator/reference-validator.d.ts +31 -0
  219. package/dist/src/validator/reference-validator.js +230 -0
  220. package/dist/src/validator/schema-references.d.ts +23 -0
  221. package/dist/src/validator/schema-references.js +111 -0
  222. package/dist/src/validator/semantic-validator.d.ts +26 -0
  223. package/dist/src/validator/semantic-validator.js +325 -0
  224. package/dist/src/validator/tests-validator.d.ts +9 -0
  225. package/dist/src/validator/tests-validator.js +13 -0
  226. package/dist/src/validator/types.d.ts +29 -0
  227. package/dist/src/validator/types.js +1 -0
  228. package/dist/src/validator/unispec-validator.d.ts +15 -0
  229. package/dist/src/validator/unispec-validator.js +77 -0
  230. package/dist/src/validator/validator-factory.d.ts +10 -0
  231. package/dist/src/validator/validator-factory.js +73 -0
  232. package/dist/src/versions.d.ts +10 -0
  233. package/dist/src/versions.js +143 -0
  234. package/dist/tests/cache/cache.test.d.ts +1 -0
  235. package/dist/tests/cache/cache.test.js +269 -0
  236. package/dist/tests/cache/utils.d.ts +4 -0
  237. package/dist/tests/cache/utils.js +24 -0
  238. package/dist/tests/concurrency-normalizer-optimizer.test.d.ts +0 -0
  239. package/dist/tests/concurrency-normalizer-optimizer.test.js +1 -0
  240. package/dist/tests/diff/diff-annotators.test.d.ts +1 -0
  241. package/dist/tests/diff/diff-annotators.test.js +275 -0
  242. package/dist/tests/diff/diff-comprehensive.test.d.ts +1 -0
  243. package/dist/tests/diff/diff-comprehensive.test.js +257 -0
  244. package/dist/tests/diff/diff-extended.test.d.ts +1 -0
  245. package/dist/tests/diff/diff-extended.test.js +230 -0
  246. package/dist/tests/diff/diff.test.d.ts +1 -0
  247. package/dist/tests/diff/diff.test.js +184 -0
  248. package/dist/tests/diff/utils.d.ts +2 -0
  249. package/dist/tests/diff/utils.js +3 -0
  250. package/dist/tests/errors/errors-integration.test.d.ts +1 -0
  251. package/dist/tests/errors/errors-integration.test.js +168 -0
  252. package/dist/tests/errors/errors.test.d.ts +1 -0
  253. package/dist/tests/errors/errors.test.js +275 -0
  254. package/dist/tests/errors/utils.d.ts +2 -0
  255. package/dist/tests/errors/utils.js +3 -0
  256. package/dist/tests/loader/integration.test.d.ts +1 -0
  257. package/dist/tests/loader/integration.test.js +211 -0
  258. package/dist/tests/loader/loader.test.d.ts +1 -0
  259. package/dist/tests/loader/loader.test.js +336 -0
  260. package/dist/tests/normalizer/normalizer-comprehensive.test.d.ts +1 -0
  261. package/dist/tests/normalizer/normalizer-comprehensive.test.js +643 -0
  262. package/dist/tests/normalizer/normalizer-invalid.test.d.ts +1 -0
  263. package/dist/tests/normalizer/normalizer-invalid.test.js +253 -0
  264. package/dist/tests/normalizer/normalizer-valid.test.d.ts +1 -0
  265. package/dist/tests/normalizer/normalizer-valid.test.js +233 -0
  266. package/dist/tests/normalizer/utils.d.ts +18 -0
  267. package/dist/tests/normalizer/utils.js +36 -0
  268. package/dist/tests/optimizer/compress-references.test.d.ts +1 -0
  269. package/dist/tests/optimizer/compress-references.test.js +299 -0
  270. package/dist/tests/optimizer/deduplication.test.d.ts +1 -0
  271. package/dist/tests/optimizer/deduplication.test.js +127 -0
  272. package/dist/tests/optimizer/integration.test.d.ts +1 -0
  273. package/dist/tests/optimizer/integration.test.js +126 -0
  274. package/dist/tests/optimizer/optimization-report.test.d.ts +1 -0
  275. package/dist/tests/optimizer/optimization-report.test.js +217 -0
  276. package/dist/tests/optimizer/optimize-document.test.d.ts +1 -0
  277. package/dist/tests/optimizer/optimize-document.test.js +182 -0
  278. package/dist/tests/optimizer/orphaned-schemas.test.d.ts +1 -0
  279. package/dist/tests/optimizer/orphaned-schemas.test.js +189 -0
  280. package/dist/tests/optimizer/sort-schemas.test.d.ts +1 -0
  281. package/dist/tests/optimizer/sort-schemas.test.js +126 -0
  282. package/dist/tests/optimizer/utils.d.ts +8 -0
  283. package/dist/tests/optimizer/utils.js +199 -0
  284. package/dist/tests/schemas/schemas-edge-cases.test.d.ts +1 -0
  285. package/dist/tests/schemas/schemas-edge-cases.test.js +218 -0
  286. package/dist/tests/schemas/schemas.test.d.ts +1 -0
  287. package/dist/tests/schemas/schemas.test.js +395 -0
  288. package/dist/tests/schemas/utils.d.ts +2 -0
  289. package/dist/tests/schemas/utils.js +3 -0
  290. package/dist/tests/utils.d.ts +10 -0
  291. package/dist/tests/utils.js +118 -0
  292. package/dist/tests/validator/config-validator.test.d.ts +1 -0
  293. package/dist/tests/validator/config-validator.test.js +73 -0
  294. package/dist/tests/validator/debug-config.d.ts +0 -0
  295. package/dist/tests/validator/debug-config.js +1 -0
  296. package/dist/tests/validator/debug-missing-service.d.ts +0 -0
  297. package/dist/tests/validator/debug-missing-service.js +1 -0
  298. package/dist/tests/validator/debug-other-configs.d.ts +0 -0
  299. package/dist/tests/validator/debug-other-configs.js +1 -0
  300. package/dist/tests/validator/debug-references.d.ts +0 -0
  301. package/dist/tests/validator/debug-references.js +1 -0
  302. package/dist/tests/validator/unispec-validator.test.d.ts +1 -0
  303. package/dist/tests/validator/unispec-validator.test.js +98 -0
  304. package/dist/tests/validator/utils.d.ts +6 -0
  305. package/dist/tests/validator/utils.js +20 -0
  306. package/package.json +4 -3
@@ -4,6 +4,10 @@ exports.annotateRestChange = annotateRestChange;
4
4
  exports.annotateWebSocketChange = annotateWebSocketChange;
5
5
  exports.annotateGraphQLChange = annotateGraphQLChange;
6
6
  function annotateRestChange(change) {
7
+ // Add defensive check for null/undefined path
8
+ if (!change.path || typeof change.path !== "string") {
9
+ return change;
10
+ }
7
11
  if (!change.path.startsWith("/service/protocols/rest/routes/")) {
8
12
  return change;
9
13
  }
@@ -40,6 +44,10 @@ function annotateRestChange(change) {
40
44
  return annotated;
41
45
  }
42
46
  function annotateWebSocketChange(change) {
47
+ // Add defensive check for null/undefined path
48
+ if (!change.path || typeof change.path !== "string") {
49
+ return change;
50
+ }
43
51
  if (!change.path.startsWith("/service/protocols/websocket/channels/")) {
44
52
  return change;
45
53
  }
@@ -90,6 +98,10 @@ function annotateWebSocketChange(change) {
90
98
  return annotated;
91
99
  }
92
100
  function annotateGraphQLChange(change) {
101
+ // Add defensive check for null/undefined path
102
+ if (!change.path || typeof change.path !== "string") {
103
+ return change;
104
+ }
93
105
  if (!change.path.startsWith("/service/protocols/graphql/")) {
94
106
  return change;
95
107
  }
@@ -114,19 +126,34 @@ function annotateGraphQLChange(change) {
114
126
  ...change,
115
127
  protocol: "graphql",
116
128
  };
117
- if (change.description === "Item removed") {
118
- annotated.kind = "graphql.operation.removed";
129
+ // Create operation-specific annotations
130
+ const singularMap = {
131
+ queries: "query",
132
+ mutations: "mutation",
133
+ subscriptions: "subscription"
134
+ };
135
+ const operationKind = `graphql.${singularMap[operationType]}`;
136
+ // Check for specific changes first, then general ones
137
+ if (change.path.includes("/returnType") &&
138
+ change.description === "Value changed") {
139
+ // Changing return type is breaking
140
+ annotated.kind = `${operationKind}.return_type_changed`;
119
141
  annotated.severity = "breaking";
120
142
  }
121
- else if (change.description === "Item added") {
122
- annotated.kind = "graphql.operation.added";
123
- annotated.severity = "non-breaking";
143
+ else if (change.path.includes("/args") &&
144
+ (change.description === "Item added" || change.description === "Item removed")) {
145
+ // Argument changes
146
+ const action = change.description === "Item added" ? "added" : "removed";
147
+ annotated.kind = `${operationKind}.argument_${action}`;
148
+ annotated.severity = action === "added" ? "non-breaking" : "breaking";
124
149
  }
125
- else if (change.path.includes("/returnType") &&
126
- change.description === "Value changed") {
127
- // Changing return type is breaking
128
- annotated.kind = "graphql.operation.return_type_changed";
150
+ else if (change.description === "Item removed") {
151
+ annotated.kind = `${operationKind}.removed`;
129
152
  annotated.severity = "breaking";
130
153
  }
154
+ else if (change.description === "Item added") {
155
+ annotated.kind = `${operationKind}.added`;
156
+ annotated.severity = "non-breaking";
157
+ }
131
158
  return annotated;
132
159
  }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCacheManager = createCacheManager;
4
+ exports.createNamedCacheManager = createNamedCacheManager;
5
+ exports.getManagersStats = getManagersStats;
6
+ exports.destroyManagers = destroyManagers;
7
+ exports.clearTestRegistry = clearTestRegistry;
8
+ const cache_manager_1 = require("./cache-manager.js");
9
+ /**
10
+ * Simple registry for test cleanup (minimal, not persistent global state)
11
+ */
12
+ const testRegistry = new Map();
13
+ /**
14
+ * Create a new isolated cache manager instance.
15
+ * @param options - Cache configuration options
16
+ * @returns New cache manager instance
17
+ */
18
+ function createCacheManager(options) {
19
+ return new cache_manager_1.UniSpecCacheManager(options);
20
+ }
21
+ /**
22
+ * Create a named cache manager instance with simple registry.
23
+ * @param name - Instance name for identification
24
+ * @param options - Cache configuration options
25
+ * @returns Cache manager instance
26
+ */
27
+ function createNamedCacheManager(name = "default", options) {
28
+ // For testing, keep simple registry to enable cleanup
29
+ if (testRegistry.has(name)) {
30
+ const existing = testRegistry.get(name);
31
+ if (existing) {
32
+ existing.destroy(); // Cleanup existing instance
33
+ }
34
+ }
35
+ const manager = new cache_manager_1.UniSpecCacheManager(options);
36
+ manager._name = name; // Store name for debugging
37
+ testRegistry.set(name, manager); // Add to registry for cleanup
38
+ return manager;
39
+ }
40
+ /**
41
+ * Get cache manager statistics for multiple instances.
42
+ * @param managers - Array of cache manager instances
43
+ * @returns Statistics for all provided managers
44
+ */
45
+ function getManagersStats(managers) {
46
+ const stats = {};
47
+ for (const [index, manager] of managers.entries()) {
48
+ const name = manager._name ||
49
+ `manager_${index}`;
50
+ stats[name] = manager.getStats();
51
+ }
52
+ return stats;
53
+ }
54
+ /**
55
+ * Destroy multiple cache manager instances.
56
+ * @param managers - Array of cache manager instances to destroy
57
+ */
58
+ function destroyManagers(managers) {
59
+ for (const manager of managers) {
60
+ manager.destroy();
61
+ }
62
+ }
63
+ /**
64
+ * Clear test registry (for testing only).
65
+ * @internal
66
+ */
67
+ function clearTestRegistry() {
68
+ for (const manager of testRegistry.values()) {
69
+ manager.destroy();
70
+ }
71
+ testRegistry.clear();
72
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UniSpecCacheManager = void 0;
4
+ const constants_1 = require("./constants.js");
5
+ const lru_cache_1 = require("./lru-cache.js");
6
+ /**
7
+ * Cache manager for UniSpec operations.
8
+ */
9
+ class UniSpecCacheManager {
10
+ constructor(options = {}) {
11
+ this.cleanupInterval = null;
12
+ this.validationCache = new lru_cache_1.LRUCache({
13
+ ...options,
14
+ maxSize: options.maxSize || constants_1.CACHE_CONSTANTS.VALIDATION_MAX_SIZE,
15
+ });
16
+ this.normalizationCache = new lru_cache_1.LRUCache({
17
+ ...options,
18
+ maxSize: options.maxSize || constants_1.CACHE_CONSTANTS.NORMALIZATION_MAX_SIZE,
19
+ });
20
+ this.diffCache = new lru_cache_1.LRUCache({
21
+ ...options,
22
+ maxSize: options.maxSize || constants_1.CACHE_CONSTANTS.DIFF_MAX_SIZE,
23
+ });
24
+ // Only start cleanup if not in test environment
25
+ if (process.env.NODE_ENV !== "test") {
26
+ this.startCleanup();
27
+ }
28
+ }
29
+ /**
30
+ * Get cached validation result asynchronously.
31
+ */
32
+ async getValidationResult(documentHash) {
33
+ return await this.validationCache.get(documentHash);
34
+ }
35
+ /**
36
+ * Cache validation result asynchronously.
37
+ */
38
+ async setValidationResult(documentHash, result) {
39
+ await this.validationCache.set(documentHash, result);
40
+ }
41
+ /**
42
+ * Get cached normalization result asynchronously.
43
+ */
44
+ async getNormalizationResult(documentHash) {
45
+ return await this.normalizationCache.get(documentHash);
46
+ }
47
+ /**
48
+ * Cache normalization result asynchronously.
49
+ */
50
+ async setNormalizationResult(documentHash, result) {
51
+ await this.normalizationCache.set(documentHash, result);
52
+ }
53
+ /**
54
+ * Get cached diff result asynchronously.
55
+ */
56
+ async getDiffResult(docsHash) {
57
+ return await this.diffCache.get(docsHash);
58
+ }
59
+ /**
60
+ * Cache diff result asynchronously.
61
+ */
62
+ async setDiffResult(docsHash, result) {
63
+ await this.diffCache.set(docsHash, result);
64
+ }
65
+ /**
66
+ * Get comprehensive cache statistics.
67
+ */
68
+ getStats() {
69
+ const validationStats = this.validationCache.getStats();
70
+ const normalizationStats = this.normalizationCache.getStats();
71
+ const diffStats = this.diffCache.getStats();
72
+ const total = {
73
+ size: validationStats.size + normalizationStats.size + diffStats.size,
74
+ hits: validationStats.hits + normalizationStats.hits + diffStats.hits,
75
+ misses: validationStats.misses + normalizationStats.misses + diffStats.misses,
76
+ hitRate: 0,
77
+ };
78
+ const totalRequests = total.hits + total.misses;
79
+ total.hitRate = totalRequests > 0 ? total.hits / totalRequests : 0;
80
+ return {
81
+ validation: validationStats,
82
+ normalization: normalizationStats,
83
+ diff: diffStats,
84
+ total,
85
+ };
86
+ }
87
+ /**
88
+ * Clear all caches.
89
+ */
90
+ clearAll() {
91
+ this.validationCache.clear();
92
+ this.normalizationCache.clear();
93
+ this.diffCache.clear();
94
+ }
95
+ /**
96
+ * Start automatic cleanup interval.
97
+ */
98
+ startCleanup() {
99
+ try {
100
+ this.cleanupInterval = setInterval(() => {
101
+ try {
102
+ this.validationCache.cleanup();
103
+ this.normalizationCache.cleanup();
104
+ this.diffCache.cleanup();
105
+ }
106
+ catch (error) {
107
+ console.error(constants_1.CACHE_MESSAGES.CLEANUP_ERROR, error);
108
+ // Continue running cleanup even if one cache fails
109
+ }
110
+ }, constants_1.CACHE_CONSTANTS.CLEANUP_INTERVAL);
111
+ }
112
+ catch (error) {
113
+ console.error(constants_1.CACHE_MESSAGES.CLEANUP_START_ERROR, error);
114
+ // Cache will still work without automatic cleanup
115
+ }
116
+ }
117
+ /**
118
+ * Stop automatic cleanup.
119
+ */
120
+ destroy() {
121
+ if (this.cleanupInterval) {
122
+ clearInterval(this.cleanupInterval);
123
+ this.cleanupInterval = null;
124
+ }
125
+ this.clearAll();
126
+ }
127
+ }
128
+ exports.UniSpecCacheManager = UniSpecCacheManager;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Cache configuration constants.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CACHE_MESSAGES = exports.CACHE_CONSTANTS = void 0;
7
+ exports.CACHE_CONSTANTS = {
8
+ // Default cache sizes
9
+ DEFAULT_MAX_SIZE: 100,
10
+ VALIDATION_MAX_SIZE: 50,
11
+ NORMALIZATION_MAX_SIZE: 30,
12
+ DIFF_MAX_SIZE: 20,
13
+ // TTL values (in milliseconds)
14
+ DEFAULT_TTL: 5 * 60 * 1000, // 5 minutes
15
+ CLEANUP_INTERVAL: 60000, // 1 minute
16
+ // Hash configuration
17
+ HASH_GOLDEN_RATIO: 2654435761,
18
+ HASH_BASE: 31,
19
+ HASH_MASK: 0xffffffff,
20
+ };
21
+ exports.CACHE_MESSAGES = {
22
+ CLEANUP_ERROR: "Cache cleanup error",
23
+ CLEANUP_START_ERROR: "Failed to start cleanup interval",
24
+ CACHE_WILL_CONTINUE: "Cache will still work without automatic cleanup",
25
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateDocumentHash = generateDocumentHash;
4
+ exports.generateDiffHash = generateDiffHash;
5
+ const hashing_1 = require("./hashing.js");
6
+ /**
7
+ * Generate a hash for a UniSpec document for caching purposes.
8
+ * Uses optimized hashing for better performance and collision resistance.
9
+ */
10
+ async function generateDocumentHash(document) {
11
+ return await (0, hashing_1.generateOptimizedDocumentHash)(document);
12
+ }
13
+ /**
14
+ * Generate a hash for two documents (for diff caching).
15
+ * Uses optimized diff hashing with better collision resistance.
16
+ */
17
+ async function generateDiffHash(oldDoc, newDoc) {
18
+ return await (0, hashing_1.generateOptimizedDiffHash)(oldDoc, newDoc);
19
+ }
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateOptimizedDocumentHash = generateOptimizedDocumentHash;
37
+ exports.generateOptimizedDiffHash = generateOptimizedDiffHash;
38
+ exports.simpleHash = simpleHash;
39
+ exports.stableStringify = stableStringify;
40
+ const constants_1 = require("../cache/constants.js");
41
+ /**
42
+ * Secure document hashing utilities using Web Crypto API.
43
+ */
44
+ /**
45
+ * Secure hash using Web Crypto API (SHA-256) or Node.js crypto.
46
+ * Fallback to FNV-1a only if both crypto APIs are unavailable.
47
+ */
48
+ async function secureHash(str) {
49
+ // Try Web Crypto API first (browser environments)
50
+ if (typeof crypto !== "undefined" && crypto.subtle) {
51
+ try {
52
+ const encoder = new TextEncoder();
53
+ const data = encoder.encode(str);
54
+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);
55
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
56
+ return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
57
+ }
58
+ catch (error) {
59
+ console.warn("Web Crypto API failed, trying Node.js crypto:", error);
60
+ }
61
+ }
62
+ // Try Node.js crypto API (server environments)
63
+ try {
64
+ // Dynamic import for Node.js crypto to avoid browser compatibility issues
65
+ const crypto = await Promise.resolve().then(() => __importStar(require("node:crypto")));
66
+ const hash = crypto.createHash("sha256");
67
+ hash.update(str, "utf8");
68
+ return hash.digest("hex");
69
+ }
70
+ catch (error) {
71
+ console.warn("Node.js crypto API failed, falling back to FNV-1a:", error);
72
+ }
73
+ // Last resort: FNV-1a algorithm (non-cryptographic, for compatibility only)
74
+ console.warn("Using FNV-1a fallback hash - consider installing crypto support");
75
+ return fnv1aHashFallback(str).toString();
76
+ }
77
+ /**
78
+ * FNV-1a fallback hash function (non-cryptographic, for compatibility).
79
+ */
80
+ function fnv1aHashFallback(str) {
81
+ let hash = 2166136261; // FNV offset basis
82
+ for (let i = 0; i < str.length; i++) {
83
+ hash ^= str.charCodeAt(i);
84
+ hash = (hash * 16777619) & constants_1.CACHE_CONSTANTS.HASH_MASK; // FNV prime
85
+ }
86
+ return hash;
87
+ }
88
+ /**
89
+ * Generate a secure hash for a document using optimized sorting and Web Crypto API.
90
+ */
91
+ async function generateOptimizedDocumentHash(document) {
92
+ // Use optimized stable stringification
93
+ const str = stableStringify(document);
94
+ // Use secure hash for better distribution and collision resistance
95
+ const hash = await secureHash(str);
96
+ // Add length and type prefix for additional collision resistance
97
+ const typePrefix = getDocumentTypePrefix(document);
98
+ const combined = `${hash}_${str.length}_${typePrefix}`;
99
+ // Create final hash with combined string
100
+ const finalHash = await secureHash(combined);
101
+ return `${finalHash.slice(0, 16)}_${str.length}`;
102
+ }
103
+ /**
104
+ * Default configuration for stable stringification.
105
+ */
106
+ const DEFAULT_STRINGIFY_CONFIG = {
107
+ maxDepth: 100,
108
+ maxKeys: 10000,
109
+ handleCircular: true,
110
+ handleDeepObjects: true,
111
+ };
112
+ /**
113
+ * Optimized stable stringification that avoids recursion depth issues.
114
+ */
115
+ function stableStringify(obj, config = {}, depth = 0, visited = new WeakSet()) {
116
+ const finalConfig = { ...DEFAULT_STRINGIFY_CONFIG, ...config };
117
+ // Prevent infinite recursion
118
+ if (depth > finalConfig.maxDepth) {
119
+ return `"[MAX_DEPTH_REACHED:${depth}]"`;
120
+ }
121
+ // Handle circular references
122
+ if (finalConfig.handleCircular && obj && typeof obj === "object") {
123
+ if (visited.has(obj)) {
124
+ return `"[CIRCULAR_REFERENCE:${obj.constructor?.name || "Object"}]"`;
125
+ }
126
+ visited.add(obj);
127
+ }
128
+ // Handle primitives
129
+ if (obj === null || typeof obj !== "object") {
130
+ return JSON.stringify(obj);
131
+ }
132
+ // Handle special object types
133
+ if (obj instanceof Date) {
134
+ return obj.toISOString();
135
+ }
136
+ if (obj instanceof RegExp) {
137
+ return `"[REGEX:${obj.toString()}]"`;
138
+ }
139
+ if (obj instanceof Error) {
140
+ return `"[ERROR:${obj.name}:${obj.message}]"`;
141
+ }
142
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(obj)) {
143
+ return `"[BUFFER:${obj.toString("base64")}]"`;
144
+ }
145
+ // Handle Array
146
+ if (Array.isArray(obj)) {
147
+ if (obj.length > finalConfig.maxKeys) {
148
+ return `"[ARRAY_TOO_LARGE:${obj.length}]"`;
149
+ }
150
+ const elements = obj.map((item, index) => {
151
+ try {
152
+ return stableStringify(item, finalConfig, depth + 1, visited);
153
+ }
154
+ catch (error) {
155
+ return `"[ERROR_AT_INDEX_${index}:${error instanceof Error ? error.message : String(error)}]"`;
156
+ }
157
+ });
158
+ return `[${elements.join(",")}]`;
159
+ }
160
+ // Handle Object
161
+ if (typeof obj === "object") {
162
+ const objRecord = obj;
163
+ const keys = Object.keys(objRecord);
164
+ if (keys.length > finalConfig.maxKeys) {
165
+ return `"[OBJECT_TOO_LARGE:${keys.length}]"`;
166
+ }
167
+ const sortedKeys = keys.sort();
168
+ const pairs = [];
169
+ for (const key of sortedKeys) {
170
+ try {
171
+ const value = stableStringify(objRecord[key], finalConfig, depth + 1, visited);
172
+ pairs.push(`"${key}":${value}`);
173
+ }
174
+ catch (error) {
175
+ pairs.push(`"${key}":"[ERROR:${error instanceof Error ? error.message : String(error)}]"`);
176
+ }
177
+ }
178
+ return `{${pairs.join(",")}}`;
179
+ }
180
+ return "{}";
181
+ }
182
+ /**
183
+ * Get a numeric prefix based on document type to reduce collisions.
184
+ */
185
+ function getDocumentTypePrefix(document) {
186
+ if (!document || typeof document !== "object")
187
+ return 0;
188
+ const doc = document;
189
+ // Check for UniSpec document
190
+ if (doc.unispecVersion)
191
+ return 1;
192
+ if (doc.uniSpecTestsVersion)
193
+ return 2;
194
+ if (doc.version && doc.services)
195
+ return 3;
196
+ // Check for common patterns
197
+ if (Array.isArray(document))
198
+ return 4;
199
+ if (doc.$schema)
200
+ return 5;
201
+ if (doc.type)
202
+ return typeof doc.type === "string" ? doc.type.charCodeAt(0) || 6 : 6;
203
+ return 7;
204
+ }
205
+ /**
206
+ * Generate a secure hash for two documents (for diff caching) with optimized collision resistance.
207
+ */
208
+ async function generateOptimizedDiffHash(oldDoc, newDoc) {
209
+ const oldHash = await generateOptimizedDocumentHash(oldDoc);
210
+ const newHash = await generateOptimizedDocumentHash(newDoc);
211
+ // Combine hashes using order-sensitive operation
212
+ const combined = `${oldHash}:${newHash}`;
213
+ // Hash the combined string to get final result
214
+ const finalHash = await secureHash(combined);
215
+ return `${finalHash.slice(0, 16)}_${oldHash.length}_${newHash.length}`;
216
+ }
217
+ /**
218
+ * Simple hash for small objects (keys, strings) using built-in hash.
219
+ * Kept for backward compatibility but consider using secureHash for new code.
220
+ */
221
+ function simpleHash(str) {
222
+ let hash = 5381; // DJB2 hash initial value
223
+ for (let i = 0; i < str.length; i++) {
224
+ const char = str.charCodeAt(i);
225
+ hash = ((hash << 5) + hash + char) & constants_1.CACHE_CONSTANTS.HASH_MASK;
226
+ }
227
+ // Convert to hex and pad to 8 characters
228
+ const hex = hash.toString(16);
229
+ return hex.padStart(8, "0").slice(-8);
230
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // Constants and messages
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LRUCache = exports.generateDocumentHash = exports.generateDiffHash = exports.CACHE_MESSAGES = exports.CACHE_CONSTANTS = exports.UniSpecCacheManager = exports.getManagersStats = exports.destroyManagers = exports.createNamedCacheManager = exports.createCacheManager = exports.clearTestRegistry = void 0;
5
+ // Cache factory
6
+ var cache_factory_1 = require("./cache-factory.js");
7
+ Object.defineProperty(exports, "clearTestRegistry", { enumerable: true, get: function () { return cache_factory_1.clearTestRegistry; } });
8
+ Object.defineProperty(exports, "createCacheManager", { enumerable: true, get: function () { return cache_factory_1.createCacheManager; } });
9
+ Object.defineProperty(exports, "createNamedCacheManager", { enumerable: true, get: function () { return cache_factory_1.createNamedCacheManager; } });
10
+ Object.defineProperty(exports, "destroyManagers", { enumerable: true, get: function () { return cache_factory_1.destroyManagers; } });
11
+ Object.defineProperty(exports, "getManagersStats", { enumerable: true, get: function () { return cache_factory_1.getManagersStats; } });
12
+ // Cache manager
13
+ var cache_manager_1 = require("./cache-manager.js");
14
+ Object.defineProperty(exports, "UniSpecCacheManager", { enumerable: true, get: function () { return cache_manager_1.UniSpecCacheManager; } });
15
+ var constants_1 = require("./constants.js");
16
+ Object.defineProperty(exports, "CACHE_CONSTANTS", { enumerable: true, get: function () { return constants_1.CACHE_CONSTANTS; } });
17
+ Object.defineProperty(exports, "CACHE_MESSAGES", { enumerable: true, get: function () { return constants_1.CACHE_MESSAGES; } });
18
+ // Hash utilities
19
+ var hash_utils_1 = require("./hash-utils.js");
20
+ Object.defineProperty(exports, "generateDiffHash", { enumerable: true, get: function () { return hash_utils_1.generateDiffHash; } });
21
+ Object.defineProperty(exports, "generateDocumentHash", { enumerable: true, get: function () { return hash_utils_1.generateDocumentHash; } });
22
+ // Core cache implementation
23
+ var lru_cache_1 = require("./lru-cache.js");
24
+ Object.defineProperty(exports, "LRUCache", { enumerable: true, get: function () { return lru_cache_1.LRUCache; } });