@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/cjs/index.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- // ============================================================================
3
- // CORE TYPES AND INTERFACES
4
- // ============================================================================
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- // ============================================================================
21
- // CACHING SYSTEM
22
- // ============================================================================
23
- __exportStar(require("./cache/index.js"), exports);
24
- // ============================================================================
25
- // DIFF AND CHANGE ANALYSIS
26
- // ============================================================================
27
- __exportStar(require("./diff/index.js"), exports);
28
- // ============================================================================
29
- // DOCUMENT LOADING AND PARSING
30
- // ============================================================================
31
- __exportStar(require("./loader/index.js"), exports);
32
- // ============================================================================
33
- // DOCUMENT NORMALIZATION
34
- // ============================================================================
35
- __exportStar(require("./normalizer/index.js"), exports);
36
- // ============================================================================
37
- // DOCUMENT OPTIMIZATION
38
- // ============================================================================
39
- __exportStar(require("./optimizer/index.js"), exports);
40
- // ============================================================================
41
- // SCHEMA MANAGEMENT
42
- // ============================================================================
43
- __exportStar(require("./schemas/index.js"), exports);
44
- __exportStar(require("./types/index.js"), exports);
45
- // ============================================================================
46
- // VALIDATION SYSTEM
47
- // ============================================================================
48
- __exportStar(require("./validator/index.js"), exports);
49
- // ============================================================================
50
- // UTILITY FUNCTIONS
51
- // ============================================================================
52
- __exportStar(require("./validator/object-traversal.js"), exports);
53
- __exportStar(require("./validator/reference-validator.js"), exports);
54
- __exportStar(require("./validator/schema-references.js"), exports);
55
- __exportStar(require("./validator/semantic-validator.js"), exports);
56
- // ============================================================================
57
- // VERSION INFORMATION
58
- // ============================================================================
59
- __exportStar(require("./versions.js"), exports);
@@ -1,13 +0,0 @@
1
- "use strict";
2
- // Export all loader functionality
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.validateYamlModule = exports.getYamlModule = exports.loadUniSpec = exports.ALLOWED_YAML_MODULES = exports.validateDocumentSecurity = void 0;
5
- var security_validator_1 = require("./security-validator.js");
6
- Object.defineProperty(exports, "validateDocumentSecurity", { enumerable: true, get: function () { return security_validator_1.validateDocumentSecurity; } });
7
- var types_1 = require("./types.js");
8
- Object.defineProperty(exports, "ALLOWED_YAML_MODULES", { enumerable: true, get: function () { return types_1.ALLOWED_YAML_MODULES; } });
9
- var unispec_loader_1 = require("./unispec-loader.js");
10
- Object.defineProperty(exports, "loadUniSpec", { enumerable: true, get: function () { return unispec_loader_1.loadUniSpec; } });
11
- var yaml_loader_1 = require("./yaml-loader.js");
12
- Object.defineProperty(exports, "getYamlModule", { enumerable: true, get: function () { return yaml_loader_1.getYamlModule; } });
13
- Object.defineProperty(exports, "validateYamlModule", { enumerable: true, get: function () { return yaml_loader_1.validateYamlModule; } });
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateDocumentSecurity = validateDocumentSecurity;
4
- const errors_1 = require("../errors/index.js");
5
- /**
6
- * Validate document security constraints using iterative approach to prevent stack overflow.
7
- */
8
- function validateDocumentSecurity(doc, options) {
9
- let keyCount = 0;
10
- let maxDepth = 0;
11
- // Use stack-based iteration instead of recursion
12
- const stack = [
13
- { obj: doc, depth: 0, path: "" },
14
- ];
15
- while (stack.length > 0) {
16
- const item = stack.pop();
17
- if (!item)
18
- break;
19
- const { obj, depth, path } = item;
20
- // Check depth limit
21
- if (depth > options.maxDepth) {
22
- throw errors_1.ErrorFactory.createSecurityError(`Document depth (${depth}) exceeds maximum allowed depth (${options.maxDepth}) at path: ${path}`, path, { currentDepth: depth, maxDepth: options.maxDepth });
23
- }
24
- maxDepth = Math.max(maxDepth, depth);
25
- if (Array.isArray(obj)) {
26
- // Process array elements
27
- for (let i = obj.length - 1; i >= 0; i--) {
28
- stack.push({
29
- obj: obj[i],
30
- depth: depth + 1,
31
- path: `${path}[${i}]`,
32
- });
33
- }
34
- }
35
- else if (obj && typeof obj === "object") {
36
- // Process object properties
37
- const objRecord = obj;
38
- const keys = Object.keys(objRecord);
39
- for (let i = keys.length - 1; i >= 0; i--) {
40
- const key = keys[i];
41
- keyCount++;
42
- if (keyCount > options.maxKeys) {
43
- throw errors_1.ErrorFactory.createSecurityError(`Document key count (${keyCount}) exceeds maximum allowed keys (${options.maxKeys}) at path: ${path}`, path, { keyCount, maxKeys: options.maxKeys });
44
- }
45
- stack.push({
46
- obj: objRecord[key],
47
- depth: depth + 1,
48
- path: path ? `${path}.${key}` : key,
49
- });
50
- }
51
- }
52
- }
53
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALLOWED_YAML_MODULES = void 0;
4
- /**
5
- * Allowed YAML module patterns for security validation.
6
- */
7
- exports.ALLOWED_YAML_MODULES = [
8
- "js-yaml",
9
- "@js-yaml/fork",
10
- "yaml",
11
- ];
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadUniSpec = loadUniSpec;
4
- const index_1 = require("../errors/index.js");
5
- const security_validator_1 = require("./security-validator.js");
6
- const yaml_loader_1 = require("./yaml-loader.js");
7
- /**
8
- * Load a UniSpec document from a raw input value.
9
- * Supports:
10
- * - JavaScript objects (treated as already parsed UniSpec)
11
- * - JSON strings
12
- * - YAML strings
13
- */
14
- async function loadUniSpec(input, options = {}) {
15
- // Set default security limits
16
- const secureOptions = {
17
- maxDepth: options.maxDepth ?? 100,
18
- maxKeys: options.maxKeys ?? 10000,
19
- allowedTags: options.allowedTags ?? [
20
- "str",
21
- "int",
22
- "float",
23
- "bool",
24
- "null",
25
- "seq",
26
- "map",
27
- "binary",
28
- "timestamp",
29
- "merge",
30
- "omap",
31
- "pairs",
32
- "set",
33
- ],
34
- maxDocumentSize: options.maxDocumentSize ?? 10 * 1024 * 1024,
35
- strictYamlTags: options.strictYamlTags ?? false,
36
- };
37
- if (typeof input === "string") {
38
- const trimmed = input.trim();
39
- if (!trimmed) {
40
- throw index_1.ErrorFactory.createLoaderError("Cannot load UniSpec: input string is empty", "");
41
- }
42
- // Check document size limit
43
- if (trimmed.length > secureOptions.maxDocumentSize) {
44
- throw index_1.ErrorFactory.createSecurityError(`Document size (${trimmed.length} bytes) exceeds maximum allowed size (${secureOptions.maxDocumentSize} bytes)`, "", {
45
- documentSize: trimmed.length,
46
- maxSize: secureOptions.maxDocumentSize,
47
- });
48
- }
49
- // Try JSON first (faster and more common)
50
- try {
51
- const parsed = JSON.parse(trimmed);
52
- (0, security_validator_1.validateDocumentSecurity)(parsed, secureOptions);
53
- return parsed;
54
- }
55
- catch (jsonError) {
56
- // If JSON fails, try YAML with security validation
57
- try {
58
- // Get validated YAML module
59
- const yaml = await (0, yaml_loader_1.getYamlModule)();
60
- const doc = yaml.load(trimmed, {
61
- filename: options.filename,
62
- // Enhanced security options
63
- schema: yaml.FAILSAFE_SCHEMA,
64
- // Additional security constraints would go here if the library supports them
65
- });
66
- (0, security_validator_1.validateDocumentSecurity)(doc, secureOptions);
67
- return doc;
68
- }
69
- catch (yamlError) {
70
- const jsonMsg = jsonError instanceof Error ? jsonError.message : String(jsonError);
71
- const yamlMsg = yamlError instanceof Error ? yamlError.message : String(yamlError);
72
- // Create specific error based on what failed
73
- if (yamlMsg.includes("not in the allowed list") ||
74
- yamlMsg.includes("security")) {
75
- const securityError = index_1.ErrorFactory.fromError(yamlError, "yaml_security_error");
76
- throw securityError;
77
- }
78
- throw index_1.ErrorFactory.createLoaderError(`Failed to parse input as JSON or YAML. JSON error: ${jsonMsg}. YAML error: ${yamlMsg}`, "", { jsonError: jsonMsg, yamlError: yamlMsg });
79
- }
80
- }
81
- }
82
- (0, security_validator_1.validateDocumentSecurity)(input, secureOptions);
83
- return input;
84
- }
@@ -1,76 +0,0 @@
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.getYamlModule = getYamlModule;
37
- exports.validateYamlModule = validateYamlModule;
38
- const index_1 = require("../errors/index.js");
39
- // Static import with security validation
40
- let yamlModule = null;
41
- /**
42
- * Securely load YAML module with validation.
43
- * Uses static import path and validates the module structure.
44
- */
45
- async function getYamlModule() {
46
- if (yamlModule) {
47
- return yamlModule;
48
- }
49
- try {
50
- // Use static import path for security
51
- const importedModule = (await Promise.resolve().then(() => __importStar(require("js-yaml"))));
52
- validateYamlModule(importedModule);
53
- yamlModule = importedModule;
54
- return yamlModule;
55
- }
56
- catch (error) {
57
- throw index_1.ErrorFactory.createSecurityError("Failed to load and validate YAML module", "", { error: error instanceof Error ? error.message : String(error) });
58
- }
59
- }
60
- /**
61
- * Validate YAML module for security.
62
- */
63
- function validateYamlModule(yamlModule) {
64
- if (!yamlModule || typeof yamlModule !== "object") {
65
- throw index_1.ErrorFactory.createLoaderError("Invalid YAML module: module must be an object", "", { moduleType: typeof yamlModule });
66
- }
67
- const module = yamlModule;
68
- // Check for required functions
69
- if (!module.load || typeof module.load !== "function") {
70
- throw index_1.ErrorFactory.createLoaderError("Invalid YAML module: missing load function", "", { hasLoad: !!module.load, loadType: typeof module.load });
71
- }
72
- // Check for FAILSAFE_SCHEMA
73
- if (!module.FAILSAFE_SCHEMA) {
74
- throw index_1.ErrorFactory.createSecurityError("YAML module must support FAILSAFE_SCHEMA for security", "", { hasFailsafeSchema: !!module.FAILSAFE_SCHEMA });
75
- }
76
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeUniSpec = normalizeUniSpec;
4
- const graphql_normalizer_1 = require("./graphql-normalizer.js");
5
- const rest_normalizer_1 = require("./rest-normalizer.js");
6
- const utils_1 = require("./utils.js");
7
- const websocket_normalizer_1 = require("./websocket-normalizer.js");
8
- /**
9
- * Normalize a UniSpec document into a canonical, deterministic form.
10
- *
11
- * This function ensures consistent representation of UniSpec documents
12
- * by sorting object keys and protocol-specific structures in a predictable order.
13
- * Useful for:
14
- * - Generating stable diffs between documents
15
- * - Creating consistent output for caching
16
- * - Ensuring reproducible builds
17
- *
18
- * Current behavior:
19
- * - Recursively sorts object keys lexicographically
20
- * - Sorts REST routes by name or path+method
21
- * - Sorts GraphQL operations by name within each operation type
22
- * - Sorts WebSocket channels and messages by name
23
- * - Preserves all values as-is
24
- *
25
- * @param doc - The UniSpec document to normalize
26
- * @param options - Normalization options (currently unused, reserved for future)
27
- * @returns The normalized UniSpec document
28
- */
29
- function normalizeUniSpec(doc, _options = {}) {
30
- const normalized = (0, utils_1.normalizeValue)(doc);
31
- return (0, websocket_normalizer_1.normalizeWebSocket)((0, graphql_normalizer_1.normalizeGraphqlOperations)((0, rest_normalizer_1.normalizeRestRoutes)(normalized)));
32
- }
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeGraphqlOperations = normalizeGraphqlOperations;
4
- /**
5
- * Normalize GraphQL operations by sorting them lexicographically by name within each operation type.
6
- *
7
- * @param doc - The UniSpec document to normalize
8
- * @returns The document with normalized GraphQL operations
9
- */
10
- function normalizeGraphqlOperations(doc) {
11
- if (!doc || !doc.service?.protocols) {
12
- return doc;
13
- }
14
- const protocols = doc.service.protocols;
15
- const graphql = protocols.graphql;
16
- if (!graphql) {
17
- return doc;
18
- }
19
- const kinds = ["queries", "mutations", "subscriptions"];
20
- // Sort operations within each kind only if needed
21
- const normalizedOperations = {};
22
- let hasChanges = false;
23
- for (const kind of kinds) {
24
- const ops = graphql[kind];
25
- if (!Array.isArray(ops)) {
26
- normalizedOperations[kind] = ops;
27
- continue;
28
- }
29
- // Check if operations are already sorted
30
- const areOpsSorted = ops.every((op, index, arr) => {
31
- if (index === 0)
32
- return true;
33
- const prevName = arr[index - 1]?.name ?? "";
34
- const currentName = op?.name ?? "";
35
- return prevName.localeCompare(currentName) <= 0;
36
- });
37
- if (areOpsSorted) {
38
- normalizedOperations[kind] = ops; // No changes needed
39
- }
40
- else {
41
- const sortedOps = [...ops].sort((a, b) => {
42
- const aName = a?.name ?? "";
43
- const bName = b?.name ?? "";
44
- return aName.localeCompare(bName);
45
- });
46
- normalizedOperations[kind] = sortedOps;
47
- hasChanges = true;
48
- }
49
- }
50
- if (!hasChanges) {
51
- return doc; // No changes needed
52
- }
53
- // Return new document with sorted operations (immutable)
54
- return {
55
- ...doc,
56
- service: {
57
- ...doc.service,
58
- protocols: {
59
- ...protocols,
60
- graphql: {
61
- ...graphql,
62
- ...normalizedOperations,
63
- },
64
- },
65
- },
66
- };
67
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- // Re-export types
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.normalizeUniSpec = void 0;
5
- // Re-export core function
6
- var core_1 = require("./core.js");
7
- Object.defineProperty(exports, "normalizeUniSpec", { enumerable: true, get: function () { return core_1.normalizeUniSpec; } });
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeRestRoutes = normalizeRestRoutes;
4
- /**
5
- * Normalize REST routes by sorting them lexicographically by name or path+method.
6
- *
7
- * @param doc - The UniSpec document to normalize
8
- * @returns The document with normalized REST routes
9
- */
10
- function normalizeRestRoutes(doc) {
11
- if (!doc || !doc.service?.protocols) {
12
- return doc;
13
- }
14
- const protocols = doc.service.protocols;
15
- const rest = protocols.rest;
16
- if (!rest || !Array.isArray(rest.routes)) {
17
- return doc;
18
- }
19
- // Check if routes are already sorted to avoid unnecessary cloning
20
- const isSorted = rest.routes.every((route, index, arr) => {
21
- if (index === 0)
22
- return true;
23
- const prevKey = arr[index - 1].name ||
24
- `${arr[index - 1].path} ${arr[index - 1].method}`;
25
- const currentKey = route.name || `${route.path} ${route.method}`;
26
- return prevKey.localeCompare(currentKey) <= 0;
27
- });
28
- if (isSorted) {
29
- return doc; // No changes needed
30
- }
31
- // Create immutable copy with sorted routes
32
- const sortedRoutes = [...rest.routes].sort((a, b) => {
33
- const keyA = a.name || `${a.path} ${a.method}`;
34
- const keyB = b.name || `${b.path} ${b.method}`;
35
- return keyA.localeCompare(keyB);
36
- });
37
- // Return new document with sorted routes (immutable)
38
- return {
39
- ...doc,
40
- service: {
41
- ...doc.service,
42
- protocols: {
43
- ...protocols,
44
- rest: {
45
- ...rest,
46
- routes: sortedRoutes,
47
- },
48
- },
49
- },
50
- };
51
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPlainObject = isPlainObject;
4
- exports.normalizeValue = normalizeValue;
5
- /**
6
- * Check if a value is a plain object (not array, null, or other object types).
7
- *
8
- * @param value - The value to check
9
- * @returns true if the value is a plain object, false otherwise
10
- */
11
- function isPlainObject(value) {
12
- return Object.prototype.toString.call(value) === "[object Object]";
13
- }
14
- /**
15
- * Recursively normalize a value by sorting object keys lexicographically.
16
- *
17
- * @param value - The value to normalize
18
- * @returns The normalized value
19
- */
20
- function normalizeValue(value) {
21
- if (Array.isArray(value)) {
22
- return value.map((item) => normalizeValue(item));
23
- }
24
- if (isPlainObject(value)) {
25
- const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
26
- const normalized = {};
27
- for (const [key, val] of entries) {
28
- normalized[key] = normalizeValue(val);
29
- }
30
- return normalized;
31
- }
32
- return value;
33
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeWebSocket = normalizeWebSocket;
4
- /**
5
- * Normalize WebSocket channels and messages by sorting them lexicographically by name.
6
- *
7
- * @param doc - The UniSpec document to normalize
8
- * @returns The document with normalized WebSocket channels and messages
9
- */
10
- function normalizeWebSocket(doc) {
11
- if (!doc || !doc.service?.protocols) {
12
- return doc;
13
- }
14
- const protocols = doc.service.protocols;
15
- const websocket = protocols.websocket;
16
- if (!websocket || !Array.isArray(websocket.channels)) {
17
- return doc;
18
- }
19
- // Check if channels are already sorted
20
- const areChannelsSorted = websocket.channels.every((channel, index, arr) => {
21
- if (index === 0)
22
- return true;
23
- const prevName = arr[index - 1]?.name ?? "";
24
- const currentName = channel?.name ?? "";
25
- return prevName.localeCompare(currentName) <= 0;
26
- });
27
- // Sort messages within each channel only if needed
28
- const normalizedChannels = websocket.channels.map((channel) => {
29
- if (!channel || !Array.isArray(channel.messages)) {
30
- return channel;
31
- }
32
- // Check if messages are already sorted
33
- const areMessagesSorted = channel.messages.every((message, index, arr) => {
34
- if (index === 0)
35
- return true;
36
- const prevName = arr[index - 1]?.name ?? "";
37
- const currentName = message?.name ?? "";
38
- return prevName.localeCompare(currentName) <= 0;
39
- });
40
- if (areMessagesSorted) {
41
- return channel; // No changes needed
42
- }
43
- const sortedMessages = [...channel.messages].sort((a, b) => {
44
- const aName = a?.name ?? "";
45
- const bName = b?.name ?? "";
46
- return aName.localeCompare(bName);
47
- });
48
- // Return new channel with sorted messages (immutable)
49
- return {
50
- ...channel,
51
- messages: sortedMessages,
52
- };
53
- });
54
- if (areChannelsSorted) {
55
- // Check if any channels were modified
56
- const channelsModified = normalizedChannels.some((channel, index) => channel !== websocket.channels?.[index]);
57
- if (!channelsModified) {
58
- return doc; // No changes needed
59
- }
60
- }
61
- // Sort channels
62
- const sortedChannels = normalizedChannels.sort((a, b) => {
63
- const aName = a?.name ?? "";
64
- const bName = b?.name ?? "";
65
- return aName.localeCompare(bName);
66
- });
67
- // Return new document with sorted channels (immutable)
68
- return {
69
- ...doc,
70
- service: {
71
- ...doc.service,
72
- protocols: {
73
- ...protocols,
74
- websocket: {
75
- ...websocket,
76
- channels: sortedChannels,
77
- },
78
- },
79
- },
80
- };
81
- }