@unispechq/unispec-core 0.2.13 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +85 -160
  2. package/dist/cache/cache-factory.d.ts +31 -0
  3. package/dist/cache/cache-factory.js +65 -0
  4. package/dist/cache/cache-manager.d.ts +62 -0
  5. package/dist/cache/cache-manager.js +122 -0
  6. package/dist/cache/constants.d.ts +21 -0
  7. package/dist/cache/constants.js +22 -0
  8. package/dist/cache/hash-utils.d.ts +21 -0
  9. package/dist/cache/hash-utils.js +35 -0
  10. package/dist/cache/hashing.d.ts +19 -0
  11. package/dist/cache/hashing.js +197 -0
  12. package/dist/cache/index.d.ts +6 -0
  13. package/dist/cache/index.js +10 -0
  14. package/dist/cache/lru-cache.d.ts +56 -0
  15. package/dist/cache/lru-cache.js +161 -0
  16. package/dist/cache/types.d.ts +24 -0
  17. package/dist/cache/types.js +4 -0
  18. package/dist/cjs/cache/cache-factory.js +72 -0
  19. package/dist/cjs/cache/cache-manager.js +126 -0
  20. package/dist/cjs/cache/constants.js +25 -0
  21. package/dist/cjs/cache/hash-utils.js +41 -0
  22. package/dist/cjs/cache/hashing.js +236 -0
  23. package/dist/cjs/cache/index.js +26 -0
  24. package/dist/cjs/cache/lru-cache.js +165 -0
  25. package/dist/cjs/cache/types.js +5 -0
  26. package/dist/cjs/diff/annotators.js +132 -0
  27. package/dist/cjs/diff/change-reports.js +369 -0
  28. package/dist/cjs/diff/core.js +158 -0
  29. package/dist/cjs/diff/enhanced-diff.js +79 -0
  30. package/dist/cjs/diff/impact-strategies-refactored.js +230 -0
  31. package/dist/cjs/diff/impact-strategies.js +219 -0
  32. package/dist/cjs/diff/index.js +25 -247
  33. package/dist/cjs/diff/metrics-calculator.js +69 -0
  34. package/dist/cjs/diff/risk-calculator.js +58 -0
  35. package/dist/cjs/diff/suggestion-generator.js +78 -0
  36. package/dist/cjs/diff/types.js +11 -0
  37. package/dist/cjs/errors/base-error.js +33 -0
  38. package/dist/cjs/errors/config-error.js +11 -0
  39. package/dist/cjs/errors/error-factory.js +48 -0
  40. package/dist/cjs/errors/index.js +19 -0
  41. package/dist/cjs/errors/loader-error.js +11 -0
  42. package/dist/cjs/errors/reference-error.js +11 -0
  43. package/dist/cjs/errors/schema-error.js +11 -0
  44. package/dist/cjs/errors/security-error.js +11 -0
  45. package/dist/cjs/errors/semantic-error.js +11 -0
  46. package/dist/cjs/generated-schemas.js +2100 -0
  47. package/dist/cjs/index.js +41 -5
  48. package/dist/cjs/loader/index.js +11 -75
  49. package/dist/cjs/loader/security-validator.js +53 -0
  50. package/dist/cjs/loader/types.js +11 -0
  51. package/dist/cjs/loader/unispec-loader.js +84 -0
  52. package/dist/cjs/loader/yaml-loader.js +76 -0
  53. package/dist/cjs/normalizer/core.js +32 -0
  54. package/dist/cjs/normalizer/graphql-normalizer.js +67 -0
  55. package/dist/cjs/normalizer/index.js +5 -119
  56. package/dist/cjs/normalizer/rest-normalizer.js +51 -0
  57. package/dist/cjs/normalizer/types.js +2 -0
  58. package/dist/cjs/normalizer/utils.js +33 -0
  59. package/dist/cjs/normalizer/websocket-normalizer.js +81 -0
  60. package/dist/cjs/optimizer/core.js +115 -0
  61. package/dist/cjs/optimizer/index.js +17 -0
  62. package/dist/cjs/optimizer/optimization-functions.js +185 -0
  63. package/dist/cjs/optimizer/types.js +2 -0
  64. package/dist/cjs/optimizer/utils.js +32 -0
  65. package/dist/cjs/schemas/dedupe.js +100 -0
  66. package/dist/cjs/schemas/index.js +12 -132
  67. package/dist/cjs/schemas/resolver.js +41 -0
  68. package/dist/cjs/schemas/utils.js +53 -0
  69. package/dist/cjs/types/index.js +0 -1
  70. package/dist/cjs/validator/ajv-validator.js +82 -0
  71. package/dist/cjs/validator/config-validator-main.js +34 -0
  72. package/dist/cjs/validator/config-validator.js +17 -0
  73. package/dist/cjs/validator/index.js +21 -108
  74. package/dist/cjs/validator/object-traversal.js +112 -0
  75. package/dist/cjs/validator/reference-validator.js +233 -0
  76. package/dist/cjs/validator/schema-references.js +116 -0
  77. package/dist/cjs/validator/semantic-validator.js +328 -0
  78. package/dist/cjs/validator/tests-validator.js +16 -0
  79. package/dist/cjs/validator/types.js +2 -0
  80. package/dist/cjs/validator/unispec-validator.js +84 -0
  81. package/dist/cjs/validator/validator-factory.js +77 -0
  82. package/dist/cjs/versions.js +147 -0
  83. package/dist/diff/annotators.d.ts +4 -0
  84. package/dist/diff/annotators.js +127 -0
  85. package/dist/diff/change-reports.d.ts +37 -0
  86. package/dist/diff/change-reports.js +366 -0
  87. package/dist/diff/core.d.ts +26 -0
  88. package/dist/diff/core.js +155 -0
  89. package/dist/diff/enhanced-diff.d.ts +51 -0
  90. package/dist/diff/enhanced-diff.js +76 -0
  91. package/dist/diff/impact-strategies-refactored.d.ts +69 -0
  92. package/dist/diff/impact-strategies-refactored.js +223 -0
  93. package/dist/diff/impact-strategies.d.ts +41 -0
  94. package/dist/diff/impact-strategies.js +212 -0
  95. package/dist/diff/index.d.ts +8 -34
  96. package/dist/diff/index.js +11 -246
  97. package/dist/diff/metrics-calculator.d.ts +23 -0
  98. package/dist/diff/metrics-calculator.js +65 -0
  99. package/dist/diff/risk-calculator.d.ts +23 -0
  100. package/dist/diff/risk-calculator.js +55 -0
  101. package/dist/diff/suggestion-generator.d.ts +18 -0
  102. package/dist/diff/suggestion-generator.js +74 -0
  103. package/dist/diff/types.d.ts +24 -0
  104. package/dist/diff/types.js +8 -0
  105. package/dist/errors/base-error.d.ts +20 -0
  106. package/dist/errors/base-error.js +29 -0
  107. package/dist/errors/config-error.d.ts +4 -0
  108. package/dist/errors/config-error.js +7 -0
  109. package/dist/errors/error-factory.d.ts +22 -0
  110. package/dist/errors/error-factory.js +45 -0
  111. package/dist/errors/index.d.ts +8 -0
  112. package/dist/errors/index.js +8 -0
  113. package/dist/errors/loader-error.d.ts +4 -0
  114. package/dist/errors/loader-error.js +7 -0
  115. package/dist/errors/reference-error.d.ts +4 -0
  116. package/dist/errors/reference-error.js +7 -0
  117. package/dist/errors/schema-error.d.ts +4 -0
  118. package/dist/errors/schema-error.js +7 -0
  119. package/dist/errors/security-error.d.ts +4 -0
  120. package/dist/errors/security-error.js +7 -0
  121. package/dist/errors/semantic-error.d.ts +4 -0
  122. package/dist/errors/semantic-error.js +7 -0
  123. package/dist/generated-schemas.d.ts +2073 -0
  124. package/dist/generated-schemas.js +2097 -0
  125. package/dist/index.cjs +41 -5
  126. package/dist/index.d.ts +11 -5
  127. package/dist/index.js +41 -5
  128. package/dist/loader/index.d.ts +5 -12
  129. package/dist/loader/index.js +5 -41
  130. package/dist/loader/security-validator.d.ts +5 -0
  131. package/dist/loader/security-validator.js +50 -0
  132. package/dist/loader/types.d.ts +30 -0
  133. package/dist/loader/types.js +8 -0
  134. package/dist/loader/unispec-loader.d.ts +10 -0
  135. package/dist/loader/unispec-loader.js +81 -0
  136. package/dist/loader/yaml-loader.d.ts +10 -0
  137. package/dist/loader/yaml-loader.js +39 -0
  138. package/dist/normalizer/core.d.ts +24 -0
  139. package/dist/normalizer/core.js +29 -0
  140. package/dist/normalizer/graphql-normalizer.d.ts +8 -0
  141. package/dist/normalizer/graphql-normalizer.js +64 -0
  142. package/dist/normalizer/index.d.ts +2 -25
  143. package/dist/normalizer/index.js +3 -118
  144. package/dist/normalizer/rest-normalizer.d.ts +8 -0
  145. package/dist/normalizer/rest-normalizer.js +48 -0
  146. package/dist/normalizer/types.d.ts +7 -0
  147. package/dist/normalizer/types.js +1 -0
  148. package/dist/normalizer/utils.d.ts +14 -0
  149. package/dist/normalizer/utils.js +29 -0
  150. package/dist/normalizer/websocket-normalizer.d.ts +8 -0
  151. package/dist/normalizer/websocket-normalizer.js +78 -0
  152. package/dist/optimizer/core.d.ts +17 -0
  153. package/dist/optimizer/core.js +111 -0
  154. package/dist/optimizer/index.d.ts +4 -0
  155. package/dist/optimizer/index.js +7 -0
  156. package/dist/optimizer/optimization-functions.d.ts +32 -0
  157. package/dist/optimizer/optimization-functions.js +179 -0
  158. package/dist/optimizer/types.d.ts +28 -0
  159. package/dist/optimizer/types.js +1 -0
  160. package/dist/optimizer/utils.d.ts +7 -0
  161. package/dist/optimizer/utils.js +29 -0
  162. package/dist/schemas/dedupe.d.ts +9 -0
  163. package/dist/schemas/dedupe.js +97 -0
  164. package/dist/schemas/index.d.ts +3 -4
  165. package/dist/schemas/index.js +6 -129
  166. package/dist/schemas/resolver.d.ts +19 -0
  167. package/dist/schemas/resolver.js +37 -0
  168. package/dist/schemas/utils.d.ts +20 -0
  169. package/dist/schemas/utils.js +49 -0
  170. package/dist/types/index.d.ts +279 -41
  171. package/dist/types/index.js +0 -1
  172. package/dist/validator/ajv-validator.d.ts +15 -0
  173. package/dist/validator/ajv-validator.js +75 -0
  174. package/dist/validator/config-validator-main.d.ts +10 -0
  175. package/dist/validator/config-validator-main.js +31 -0
  176. package/dist/validator/config-validator.d.ts +5 -0
  177. package/dist/validator/config-validator.js +14 -0
  178. package/dist/validator/index.d.ts +10 -23
  179. package/dist/validator/index.js +11 -103
  180. package/dist/validator/object-traversal.d.ts +52 -0
  181. package/dist/validator/object-traversal.js +104 -0
  182. package/dist/validator/reference-validator.d.ts +31 -0
  183. package/dist/validator/reference-validator.js +230 -0
  184. package/dist/validator/schema-references.d.ts +23 -0
  185. package/dist/validator/schema-references.js +111 -0
  186. package/dist/validator/semantic-validator.d.ts +26 -0
  187. package/dist/validator/semantic-validator.js +325 -0
  188. package/dist/validator/tests-validator.d.ts +9 -0
  189. package/dist/validator/tests-validator.js +13 -0
  190. package/dist/validator/types.d.ts +29 -0
  191. package/dist/validator/types.js +1 -0
  192. package/dist/validator/unispec-validator.d.ts +15 -0
  193. package/dist/validator/unispec-validator.js +81 -0
  194. package/dist/validator/validator-factory.d.ts +10 -0
  195. package/dist/validator/validator-factory.js +73 -0
  196. package/dist/versions.d.ts +10 -0
  197. package/dist/versions.js +143 -0
  198. package/package.json +11 -9
  199. package/dist/cjs/converters/index.js +0 -204
  200. package/dist/cjs/validator/generated-schemas.js +0 -827
  201. package/dist/converters/index.d.ts +0 -14
  202. package/dist/converters/index.js +0 -199
  203. package/dist/validator/generated-schemas.d.ts +0 -842
  204. package/dist/validator/generated-schemas.js +0 -824
@@ -1,40 +1,108 @@
1
- export interface UniSpecGraphQLOperation {
1
+ export interface UniSpecNamedItem {
2
2
  name: string;
3
3
  description?: string;
4
+ }
5
+ export interface UniSpecDeprecatedItem {
4
6
  deprecated?: boolean;
5
7
  deprecationReason?: string;
6
8
  }
7
- export interface UniSpecGraphQLProtocol {
9
+ export interface UniSpecTaggedItem {
10
+ tags?: string[];
11
+ }
12
+ export interface UniSpecProtocolBase {
8
13
  url?: string;
9
- schema?: string;
10
- queries?: UniSpecGraphQLOperation[];
11
- mutations?: UniSpecGraphQLOperation[];
12
- subscriptions?: UniSpecGraphQLOperation[];
14
+ securitySchemes?: Record<string, UniSpecSecurityScheme>;
13
15
  }
14
16
  export interface UniSpecSecurityRequirement extends Array<string> {
15
17
  }
16
- export interface UniSpecWebSocketMessage {
18
+ export interface UniSpecBaseHeader {
17
19
  name: string;
18
20
  description?: string;
21
+ required?: boolean;
22
+ }
23
+ export interface UniSpecHeader extends UniSpecBaseHeader {
24
+ defaultValue?: string;
19
25
  schemaRef?: string;
20
26
  }
21
- export interface UniSpecWebSocketChannel {
27
+ export interface UniSpecApiKeyScheme {
28
+ type: "apiKey";
22
29
  name: string;
30
+ in: "header" | "query" | "cookie";
31
+ description?: string;
32
+ }
33
+ export interface UniSpecHttpScheme {
34
+ type: "http";
35
+ scheme: "basic" | "bearer" | "digest";
36
+ bearerFormat?: string;
23
37
  description?: string;
38
+ }
39
+ export interface UniSpecOAuth2Flow {
40
+ authorizationUrl: string;
41
+ tokenUrl: string;
42
+ refreshUrl?: string;
43
+ scopes: Record<string, string>;
44
+ }
45
+ export interface UniSpecOAuth2Scheme {
46
+ type: "oauth2";
47
+ flows: {
48
+ authorizationCode?: UniSpecOAuth2Flow;
49
+ clientCredentials?: UniSpecOAuth2Flow;
50
+ implicit?: UniSpecOAuth2Flow;
51
+ };
52
+ description?: string;
53
+ }
54
+ export interface UniSpecJwtScheme {
55
+ type: "jwt";
56
+ issuer?: string;
57
+ audience?: string[];
58
+ algorithms?: string[];
59
+ description?: string;
60
+ }
61
+ export type UniSpecSecurityScheme = UniSpecApiKeyScheme | UniSpecHttpScheme | UniSpecOAuth2Scheme | UniSpecJwtScheme;
62
+ export interface UniSpecGraphQLArgument extends UniSpecNamedItem, UniSpecDeprecatedItem {
63
+ type: string;
64
+ defaultValue?: unknown;
65
+ }
66
+ export interface UniSpecGraphQLOperation extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
67
+ args?: UniSpecGraphQLArgument[];
68
+ returnType?: string;
69
+ headers?: UniSpecGraphQLHeader[];
70
+ security?: UniSpecSecurityRequirement[];
71
+ }
72
+ export interface UniSpecGraphQLHeader extends UniSpecBaseHeader {
73
+ }
74
+ export interface UniSpecGraphQLProtocol extends UniSpecProtocolBase {
75
+ schema?: string;
76
+ headers?: UniSpecGraphQLHeader[];
77
+ queries?: UniSpecGraphQLOperation[];
78
+ mutations?: UniSpecGraphQLOperation[];
79
+ subscriptions?: UniSpecGraphQLOperation[];
80
+ }
81
+ export interface UniSpecWebSocketMessage extends UniSpecNamedItem, UniSpecDeprecatedItem {
24
82
  direction?: "publish" | "subscribe" | "both";
83
+ schemaRef?: string;
84
+ }
85
+ export interface UniSpecWebSocketHeader extends UniSpecBaseHeader {
86
+ }
87
+ export interface UniSpecWebSocketReconnectStrategy {
88
+ maxAttempts?: number;
89
+ delay?: number;
90
+ backoffMultiplier?: number;
91
+ }
92
+ export interface UniSpecWebSocketChannel extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
93
+ namespace?: string;
94
+ direction?: "publish" | "subscribe" | "both";
95
+ connectionParams?: Record<string, string>;
96
+ reconnectStrategy?: UniSpecWebSocketReconnectStrategy;
97
+ headers?: UniSpecWebSocketHeader[];
25
98
  messages?: UniSpecWebSocketMessage[];
26
99
  security?: UniSpecSecurityRequirement[];
27
- extensions?: Record<string, unknown>;
28
100
  }
29
- export interface UniSpecWebSocketProtocol {
30
- url?: string;
101
+ export interface UniSpecWebSocketProtocol extends UniSpecProtocolBase {
102
+ headers?: UniSpecWebSocketHeader[];
31
103
  channels?: UniSpecWebSocketChannel[];
32
- securitySchemes?: Record<string, Record<string, unknown>>;
33
104
  }
34
- export interface UniSpecRestParameter {
35
- name: string;
36
- description?: string;
37
- required?: boolean;
105
+ export interface UniSpecRestParameter extends UniSpecBaseHeader {
38
106
  schemaRef?: string;
39
107
  }
40
108
  export interface UniSpecRestMediaType {
@@ -48,14 +116,15 @@ export interface UniSpecRestRequestBody {
48
116
  required?: boolean;
49
117
  content?: UniSpecRestContent;
50
118
  }
119
+ export interface UniSpecRestResponseHeader extends UniSpecHeader {
120
+ }
51
121
  export interface UniSpecRestResponse {
52
122
  description?: string;
123
+ headers?: UniSpecRestResponseHeader[];
53
124
  content?: UniSpecRestContent;
54
125
  }
55
- export interface UniSpecRestRoute {
56
- name?: string;
126
+ export interface UniSpecRestRoute extends UniSpecNamedItem, UniSpecDeprecatedItem, UniSpecTaggedItem {
57
127
  summary?: string;
58
- description?: string;
59
128
  path: string;
60
129
  method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
61
130
  pathParams?: UniSpecRestParameter[];
@@ -65,12 +134,23 @@ export interface UniSpecRestRoute {
65
134
  responses?: Record<string, UniSpecRestResponse>;
66
135
  security?: UniSpecSecurityRequirement[];
67
136
  }
68
- export interface UniSpecRestProtocol {
137
+ export interface UniSpecRestProtocol extends UniSpecProtocolBase {
69
138
  routes?: UniSpecRestRoute[];
70
- securitySchemes?: Record<string, Record<string, unknown>>;
71
139
  }
72
- export interface UniSpecSchemaDefinition {
140
+ export interface UniSpecSchemaValidation {
141
+ strict?: boolean;
142
+ additionalProperties?: boolean;
143
+ customValidators?: UniSpecCustomValidator[];
144
+ }
145
+ export interface UniSpecCustomValidator {
146
+ name: string;
147
+ rule: string;
148
+ message: string;
149
+ }
150
+ export interface UniSpecSchemaDefinition extends UniSpecNamedItem, UniSpecDeprecatedItem {
151
+ examples?: unknown[];
73
152
  jsonSchema: Record<string, unknown>;
153
+ validation?: UniSpecSchemaValidation;
74
154
  }
75
155
  export interface UniSpecSchemas {
76
156
  [name: string]: UniSpecSchemaDefinition;
@@ -82,6 +162,30 @@ export interface UniSpecEnvironment {
82
162
  labels?: Record<string, string>;
83
163
  isDefault?: boolean;
84
164
  }
165
+ export interface UniSpecServer {
166
+ url: string;
167
+ description?: string;
168
+ }
169
+ export interface UniSpecContact {
170
+ name?: string;
171
+ email?: string;
172
+ url?: string;
173
+ }
174
+ export interface UniSpecLicense {
175
+ name?: string;
176
+ url?: string;
177
+ }
178
+ export interface UniSpecRateLimit {
179
+ requestsPerMinute?: number;
180
+ requestsPerHour?: number;
181
+ requestsPerDay?: number;
182
+ burstLimit?: number;
183
+ perUser?: boolean;
184
+ perApiKey?: boolean;
185
+ customKey?: string;
186
+ }
187
+ export type UniSpecCompliance = "GDPR" | "SOC2" | "HIPAA" | "PCI-DSS" | "ISO27001" | "CCPA";
188
+ export type UniSpecDataClassification = "public" | "internal" | "confidential" | "restricted";
85
189
  export interface UniSpecServiceProtocols {
86
190
  rest?: UniSpecRestProtocol;
87
191
  graphql?: UniSpecGraphQLProtocol;
@@ -90,14 +194,19 @@ export interface UniSpecServiceProtocols {
90
194
  export interface UniSpecDocument {
91
195
  unispecVersion: string;
92
196
  service: UniSpecService;
93
- extensions?: Record<string, unknown>;
94
197
  }
95
- export interface UniSpecService {
96
- name: string;
97
- description?: string;
198
+ export interface UniSpecService extends UniSpecNamedItem, UniSpecTaggedItem {
98
199
  version?: string;
200
+ baseUrl?: string;
201
+ contact?: UniSpecContact;
202
+ license?: UniSpecLicense;
203
+ servers?: UniSpecServer[];
99
204
  protocols?: UniSpecServiceProtocols;
100
205
  schemas?: UniSpecSchemas;
206
+ securitySchemes?: Record<string, UniSpecSecurityScheme>;
207
+ rateLimit?: UniSpecRateLimit;
208
+ compliance?: UniSpecCompliance[];
209
+ dataClassification?: UniSpecDataClassification;
101
210
  }
102
211
  export interface ValidationError {
103
212
  message: string;
@@ -108,6 +217,10 @@ export interface ValidationResult {
108
217
  valid: boolean;
109
218
  errors: ValidationError[];
110
219
  }
220
+ export interface UniSpecTestRequestBase {
221
+ headers?: Record<string, unknown>;
222
+ authProfile?: string;
223
+ }
111
224
  export type UniSpecTestProtocol = "rest" | "graphql" | "websocket";
112
225
  export interface UniSpecTestTarget {
113
226
  protocol: UniSpecTestProtocol;
@@ -118,16 +231,13 @@ export interface UniSpecRestTestParams {
118
231
  path?: Record<string, unknown>;
119
232
  query?: Record<string, unknown>;
120
233
  }
121
- export interface UniSpecRestTestRequest {
234
+ export interface UniSpecRestTestRequest extends UniSpecTestRequestBase {
122
235
  params?: UniSpecRestTestParams;
123
- headers?: Record<string, unknown>;
124
236
  body?: unknown;
125
- authProfile?: string;
126
237
  }
127
238
  export type UniSpecRestExpectedStatus = number | number[];
128
- export type UniSpecRestBodyExpectationMode = "exact" | "contains" | "schemaOnly" | "snapshot";
129
239
  export interface UniSpecRestBodyExpectation {
130
- mode?: UniSpecRestBodyExpectationMode;
240
+ mode?: "exact" | "contains" | "schemaOnly" | "snapshot";
131
241
  json?: unknown;
132
242
  schemaRef?: string;
133
243
  }
@@ -136,12 +246,10 @@ export interface UniSpecRestTestExpect {
136
246
  headers?: Record<string, unknown>;
137
247
  body?: UniSpecRestBodyExpectation;
138
248
  }
139
- export interface UniSpecGraphQLTestRequest {
249
+ export interface UniSpecGraphQLTestRequest extends UniSpecTestRequestBase {
140
250
  operationName?: string;
141
251
  query: string;
142
252
  variables?: Record<string, unknown>;
143
- headers?: Record<string, unknown>;
144
- authProfile?: string;
145
253
  }
146
254
  export interface UniSpecGraphQLTestExpect {
147
255
  data?: unknown;
@@ -154,11 +262,10 @@ export interface UniSpecWebSocketTestMessageAction {
154
262
  messageName: string;
155
263
  payload?: unknown;
156
264
  }
157
- export interface UniSpecWebSocketTestRequest {
265
+ export interface UniSpecWebSocketTestRequest extends UniSpecTestRequestBase {
158
266
  channel: string;
159
267
  direction?: "publish" | "subscribe" | "both";
160
268
  messages?: UniSpecWebSocketTestMessageAction[];
161
- authProfile?: string;
162
269
  }
163
270
  export interface UniSpecWebSocketTestExpect {
164
271
  messages?: UniSpecWebSocketTestMessageAction[];
@@ -174,14 +281,11 @@ export interface UniSpecTestExpect {
174
281
  graphql?: UniSpecGraphQLTestExpect;
175
282
  websocket?: UniSpecWebSocketTestExpect;
176
283
  }
177
- export interface UniSpecTestCase {
178
- name: string;
179
- description?: string;
284
+ export interface UniSpecTestCase extends UniSpecNamedItem {
180
285
  target: UniSpecTestTarget;
181
286
  request: UniSpecTestRequest;
182
287
  expect: UniSpecTestExpect;
183
288
  tags?: string[];
184
- extensions?: Record<string, unknown>;
185
289
  }
186
290
  export interface UniSpecTestsDocument {
187
291
  uniSpecTestsVersion: string;
@@ -191,5 +295,139 @@ export interface UniSpecTestsDocument {
191
295
  environment?: string;
192
296
  };
193
297
  tests: UniSpecTestCase[];
194
- extensions?: Record<string, unknown>;
298
+ loadTesting?: {
299
+ concurrentUsers?: number;
300
+ duration?: string;
301
+ rampUp?: string;
302
+ thresholds?: {
303
+ responseTime?: string;
304
+ errorRate?: number;
305
+ throughput?: string;
306
+ };
307
+ scenario?: {
308
+ weight?: Record<string, number>;
309
+ thinkTime?: string;
310
+ };
311
+ };
312
+ }
313
+ export interface UniSpecConfigDocument {
314
+ version: number;
315
+ services: UniSpecConfigServiceEntry[];
316
+ discovery?: UniSpecConfigDiscovery;
317
+ environments?: UniSpecConfigEnvironment[];
318
+ }
319
+ export interface UniSpecConfigServiceEntry {
320
+ name: string;
321
+ baseUrl?: string;
322
+ spec: UniSpecConfigSpecReference;
323
+ health?: UniSpecConfigHealth;
324
+ discovery?: UniSpecConfigDiscovery;
325
+ headers?: UniSpecConfigHeader[];
326
+ security?: UniSpecConfigSecurityRequirement[];
327
+ }
328
+ export type UniSpecConfigSpecReference = string | UniSpecConfigHttpSpecReference | UniSpecConfigFileSpecReference | UniSpecConfigRegistrySpecReference;
329
+ export interface UniSpecConfigHttpSpecReference {
330
+ type: "http";
331
+ url?: string;
332
+ path?: string;
333
+ }
334
+ export interface UniSpecConfigFileSpecReference {
335
+ type: "file";
336
+ path: string;
337
+ }
338
+ export interface UniSpecConfigRegistrySpecReference {
339
+ type: "registry";
340
+ ref: string;
341
+ }
342
+ export interface UniSpecConfigHealth {
343
+ path: string;
344
+ }
345
+ export interface UniSpecConfigDiscovery {
346
+ dnsTemplate?: string;
347
+ }
348
+ export interface UniSpecConfigEnvironment {
349
+ name: string;
350
+ overrides?: UniSpecConfigEnvironmentOverrides;
351
+ observability?: UniSpecConfigObservability;
352
+ deployment?: UniSpecConfigDeployment;
353
+ dataResidency?: string;
354
+ audit?: UniSpecConfigAudit;
355
+ }
356
+ export interface UniSpecConfigEnvironmentOverrides {
357
+ services?: Record<string, UniSpecConfigServiceOverride>;
358
+ }
359
+ export interface UniSpecConfigServiceOverride {
360
+ baseUrl?: string;
361
+ spec?: UniSpecConfigSpecReference;
362
+ health?: UniSpecConfigHealth;
363
+ discovery?: UniSpecConfigDiscovery;
364
+ headers?: UniSpecConfigHeader[];
365
+ security?: UniSpecConfigSecurityRequirement[];
366
+ }
367
+ export interface UniSpecConfigHeader {
368
+ name: string;
369
+ description?: string;
370
+ required?: boolean;
371
+ defaultValue?: string;
372
+ }
373
+ export type UniSpecConfigSecurityRequirement = string[];
374
+ export interface UniSpecConfigObservability {
375
+ logging?: {
376
+ level?: "debug" | "info" | "warn" | "error";
377
+ format?: "json" | "text";
378
+ fields?: string[];
379
+ };
380
+ metrics?: {
381
+ enabled?: boolean;
382
+ endpoints?: string[];
383
+ customMetrics?: UniSpecConfigCustomMetric[];
384
+ };
385
+ tracing?: {
386
+ enabled?: boolean;
387
+ samplingRate?: number;
388
+ exporter?: string;
389
+ };
390
+ }
391
+ export interface UniSpecConfigCustomMetric {
392
+ name: string;
393
+ type: "counter" | "gauge" | "histogram" | "summary";
394
+ description?: string;
395
+ labels?: string[];
396
+ }
397
+ export interface UniSpecConfigDeployment {
398
+ kubernetes?: UniSpecConfigKubernetesConfig;
399
+ docker?: UniSpecConfigDockerConfig;
400
+ replicas?: number;
401
+ resources?: UniSpecConfigResources;
402
+ }
403
+ export interface UniSpecConfigKubernetesConfig {
404
+ namespace?: string;
405
+ image?: string;
406
+ port?: number;
407
+ serviceType?: "ClusterIP" | "NodePort" | "LoadBalancer";
408
+ ingress?: {
409
+ host?: string;
410
+ path?: string;
411
+ tls?: boolean;
412
+ };
413
+ }
414
+ export interface UniSpecConfigDockerConfig {
415
+ image?: string;
416
+ port?: number;
417
+ environment?: Record<string, string>;
418
+ volumes?: string[];
419
+ }
420
+ export interface UniSpecConfigResources {
421
+ cpu?: string;
422
+ memory?: string;
423
+ storage?: string;
424
+ }
425
+ export interface UniSpecConfigAudit {
426
+ enabled?: boolean;
427
+ retention?: string;
428
+ fields?: string[];
429
+ export?: {
430
+ format?: "json" | "csv";
431
+ destination?: string;
432
+ };
195
433
  }
@@ -1,2 +1 @@
1
- // GraphQL protocol types
2
1
  export {};
@@ -0,0 +1,15 @@
1
+ import type { AjvValidateFn, ValidateOptions } from "./types.js";
2
+ declare let cached: {
3
+ validateUniSpecFn: AjvValidateFn;
4
+ validateUniSpecTestsFn?: AjvValidateFn;
5
+ validateUniSpecConfigFn?: AjvValidateFn;
6
+ } | null;
7
+ /**
8
+ * Get compiled AJV validators for different document types.
9
+ */
10
+ export declare function getValidator(options?: ValidateOptions): Promise<NonNullable<typeof cached>>;
11
+ /**
12
+ * Clear cached validators (useful for testing or when schemas change).
13
+ */
14
+ export declare function clearValidatorCache(): void;
15
+ export {};
@@ -0,0 +1,75 @@
1
+ import Ajv2020 from "ajv/dist/2020.js";
2
+ import { GENERATED_SCHEMAS } from "../generated-schemas.js";
3
+ let cached = null;
4
+ /**
5
+ * Load default schemas from generated schemas.
6
+ */
7
+ async function loadDefaultSchemas() {
8
+ // Always use generated schemas - they work in all environments
9
+ return {
10
+ unispec: GENERATED_SCHEMAS.unispec,
11
+ unispecTests: GENERATED_SCHEMAS.unispecTests,
12
+ unispecConfig: GENERATED_SCHEMAS.unispecConfig,
13
+ subschemas: GENERATED_SCHEMAS.subschemas,
14
+ };
15
+ }
16
+ /**
17
+ * Create AJV instance with custom formats and options.
18
+ */
19
+ function createAjv(options) {
20
+ const ajv = new Ajv2020({
21
+ allErrors: true,
22
+ strict: false, // Disabled to support discriminator keyword in new schema
23
+ ...(options.ajvOptions ?? {}),
24
+ });
25
+ // Add format validators
26
+ ajv.addFormat("uri", true);
27
+ ajv.addFormat("email", {
28
+ type: "string",
29
+ validate: (data) => {
30
+ // Basic email validation regex
31
+ const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
32
+ return typeof data === "string" && emailRegex.test(data);
33
+ },
34
+ });
35
+ return ajv;
36
+ }
37
+ /**
38
+ * Get compiled AJV validators for different document types.
39
+ */
40
+ export async function getValidator(options = {}) {
41
+ if (cached &&
42
+ !options.schemas &&
43
+ !options.schemaProvider &&
44
+ !options.ajvOptions)
45
+ return cached;
46
+ const schemas = options.schemas ?? (await loadDefaultSchemas());
47
+ const ajv = createAjv(options);
48
+ if (schemas.subschemas?.length) {
49
+ ajv.addSchema(schemas.subschemas);
50
+ }
51
+ const validateUniSpecFn = ajv.compile(schemas.unispec);
52
+ let validateUniSpecTestsFn;
53
+ if (schemas.unispecTests) {
54
+ validateUniSpecTestsFn = ajv.compile(schemas.unispecTests);
55
+ }
56
+ let validateUniSpecConfigFn;
57
+ if (schemas.unispecConfig) {
58
+ validateUniSpecConfigFn = ajv.compile(schemas.unispecConfig);
59
+ }
60
+ const result = {
61
+ validateUniSpecFn,
62
+ validateUniSpecTestsFn,
63
+ validateUniSpecConfigFn,
64
+ };
65
+ if (!options.schemas && !options.schemaProvider && !options.ajvOptions) {
66
+ cached = result;
67
+ }
68
+ return result;
69
+ }
70
+ /**
71
+ * Clear cached validators (useful for testing or when schemas change).
72
+ */
73
+ export function clearValidatorCache() {
74
+ cached = null;
75
+ }
@@ -0,0 +1,10 @@
1
+ import type { UniSpecConfigDocument, ValidationResult } from "../types/index.js";
2
+ import type { ValidateOptions } from "./types.js";
3
+ /**
4
+ * Validate a UniSpec Config document against the UniSpec Config JSON Schema.
5
+ *
6
+ * @param doc - The UniSpec Config document to validate
7
+ * @param options - Validation options including custom schemas
8
+ * @returns Validation result with success status and error details
9
+ */
10
+ export declare function validateUniSpecConfig(doc: UniSpecConfigDocument, options?: ValidateOptions): Promise<ValidationResult>;
@@ -0,0 +1,31 @@
1
+ import { ErrorFactory } from "../errors/index.js";
2
+ import { getValidator } from "./ajv-validator.js";
3
+ import { validateConfigCustomRules } from "./config-validator.js";
4
+ import { createValidator } from "./validator-factory.js";
5
+ /**
6
+ * Validate a UniSpec Config document against the UniSpec Config JSON Schema.
7
+ *
8
+ * @param doc - The UniSpec Config document to validate
9
+ * @param options - Validation options including custom schemas
10
+ * @returns Validation result with success status and error details
11
+ */
12
+ export async function validateUniSpecConfig(doc, options = {}) {
13
+ // Handle null input
14
+ if (doc === null || doc === undefined) {
15
+ const error = ErrorFactory.fromError(new Error("Config validation error: input must be an object"), "validation_error");
16
+ return {
17
+ valid: false,
18
+ errors: [error.toJSON()],
19
+ };
20
+ }
21
+ // Use factory for the rest of validation
22
+ const factoryValidator = createValidator("unispecConfig", async (options) => {
23
+ // If custom schemas are provided but unispecConfig is missing, return undefined
24
+ if (options.schemas && !options.schemas.unispecConfig) {
25
+ return undefined; // Will trigger schema missing error
26
+ }
27
+ const { validateUniSpecConfigFn } = await getValidator(options);
28
+ return validateUniSpecConfigFn;
29
+ }, validateConfigCustomRules);
30
+ return await factoryValidator(doc, options);
31
+ }
@@ -0,0 +1,5 @@
1
+ import type { UniSpecConfigDocument, ValidationError } from "../types/index.js";
2
+ /**
3
+ * Custom validation for UniSpec Config documents.
4
+ */
5
+ export declare function validateConfigCustomRules(doc: UniSpecConfigDocument): ValidationError[];
@@ -0,0 +1,14 @@
1
+ import { ErrorFactory } from "../errors/index.js";
2
+ /**
3
+ * Custom validation for UniSpec Config documents.
4
+ */
5
+ export function validateConfigCustomRules(doc) {
6
+ const customErrors = [];
7
+ // Check for empty services array
8
+ if (doc.services &&
9
+ Array.isArray(doc.services) &&
10
+ doc.services.length === 0) {
11
+ customErrors.push(ErrorFactory.createConfigError("services array must contain at least one service", "/services", { code: "minItems" }).toJSON());
12
+ }
13
+ return customErrors;
14
+ }
@@ -1,23 +1,10 @@
1
- import Ajv2020 from "ajv/dist/2020.js";
2
- import { UniSpecDocument, UniSpecTestsDocument, ValidationResult } from "../types";
3
- export interface SchemaProvider {
4
- getSchema: (schemaPath: string) => Promise<object>;
5
- }
6
- export interface ValidatorSchemas {
7
- unispec: object;
8
- unispecTests?: object;
9
- subschemas?: object[];
10
- }
11
- export interface ValidateOptions {
12
- schemas?: ValidatorSchemas;
13
- schemaProvider?: SchemaProvider;
14
- ajvOptions?: ConstructorParameters<typeof Ajv2020>[0];
15
- }
16
- /**
17
- * Validate a UniSpec document against the UniSpec JSON Schema.
18
- */
19
- export declare function validateUniSpec(doc: UniSpecDocument, options?: ValidateOptions): Promise<ValidationResult>;
20
- /**
21
- * Validate a UniSpec Tests document against the UniSpec Tests JSON Schema.
22
- */
23
- export declare function validateUniSpecTests(doc: UniSpecTestsDocument, options?: ValidateOptions): Promise<ValidationResult>;
1
+ export { clearValidatorCache, getValidator } from "./ajv-validator.js";
2
+ export { validateUniSpecConfig } from "./config-validator-main.js";
3
+ export type { ReferenceValidationOptions, ReferenceValidationResult, } from "./reference-validator.js";
4
+ export { validateReferences } from "./reference-validator.js";
5
+ export type { SemanticValidationOptions, SemanticValidationResult, } from "./semantic-validator.js";
6
+ export { validateSemantic } from "./semantic-validator.js";
7
+ export { validateUniSpecTests } from "./tests-validator.js";
8
+ export type { Ajv2020, AjvValidateFn, ExtendedValidationResult, SchemaProvider, ValidateOptions, ValidatorSchemas, } from "./types.js";
9
+ export { validateUniSpec } from "./unispec-validator.js";
10
+ export { createValidator, mapAjvErrors } from "./validator-factory.js";