@skmtc/core 0.0.785 → 0.0.786

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 (47) hide show
  1. package/esm/dsl/Identifier.d.ts +152 -0
  2. package/esm/dsl/Identifier.d.ts.map +1 -1
  3. package/esm/dsl/Identifier.js +152 -0
  4. package/esm/dsl/Import.d.ts +221 -0
  5. package/esm/dsl/Import.d.ts.map +1 -1
  6. package/esm/dsl/Import.js +202 -0
  7. package/esm/dsl/operation/OperationBase.d.ts +181 -1
  8. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  9. package/esm/dsl/operation/OperationBase.js +181 -1
  10. package/esm/oas/document/Document.d.ts +155 -1
  11. package/esm/oas/document/Document.d.ts.map +1 -1
  12. package/esm/oas/document/Document.js +141 -2
  13. package/esm/oas/object/Object.d.ts +255 -10
  14. package/esm/oas/object/Object.d.ts.map +1 -1
  15. package/esm/oas/object/Object.js +229 -10
  16. package/esm/types/GeneratorKeys.d.ts +336 -0
  17. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  18. package/esm/types/GeneratorKeys.js +243 -0
  19. package/esm/types/GeneratorType.d.ts +119 -0
  20. package/esm/types/GeneratorType.d.ts.map +1 -1
  21. package/esm/types/Method.d.ts +109 -0
  22. package/esm/types/Method.d.ts.map +1 -1
  23. package/esm/types/Method.js +84 -0
  24. package/package.json +1 -1
  25. package/script/dsl/Identifier.d.ts +152 -0
  26. package/script/dsl/Identifier.d.ts.map +1 -1
  27. package/script/dsl/Identifier.js +152 -0
  28. package/script/dsl/Import.d.ts +221 -0
  29. package/script/dsl/Import.d.ts.map +1 -1
  30. package/script/dsl/Import.js +202 -0
  31. package/script/dsl/operation/OperationBase.d.ts +181 -1
  32. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  33. package/script/dsl/operation/OperationBase.js +181 -1
  34. package/script/oas/document/Document.d.ts +155 -1
  35. package/script/oas/document/Document.d.ts.map +1 -1
  36. package/script/oas/document/Document.js +141 -2
  37. package/script/oas/object/Object.d.ts +255 -10
  38. package/script/oas/object/Object.d.ts.map +1 -1
  39. package/script/oas/object/Object.js +229 -10
  40. package/script/types/GeneratorKeys.d.ts +336 -0
  41. package/script/types/GeneratorKeys.d.ts.map +1 -1
  42. package/script/types/GeneratorKeys.js +243 -0
  43. package/script/types/GeneratorType.d.ts +119 -0
  44. package/script/types/GeneratorType.d.ts.map +1 -1
  45. package/script/types/Method.d.ts +109 -0
  46. package/script/types/Method.d.ts.map +1 -1
  47. package/script/types/Method.js +84 -0
@@ -1,23 +1,148 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import { isMethod } from './Method.js';
3
+ /**
4
+ * Creates an operation generator key from generator ID and operation details.
5
+ *
6
+ * Operation generator keys uniquely identify generators processing specific
7
+ * API operations. The key format is: `generatorId|path|method`
8
+ *
9
+ * @param args - Operation generator key arguments
10
+ * @returns A branded OperationGeneratorKey
11
+ *
12
+ * @example With explicit path and method
13
+ * ```typescript
14
+ * const key = toOperationGeneratorKey({
15
+ * generatorId: 'api-client',
16
+ * path: '/users/{id}',
17
+ * method: 'get'
18
+ * });
19
+ * // Result: 'api-client|/users/{id}|get' (branded)
20
+ * ```
21
+ *
22
+ * @example With OasOperation object
23
+ * ```typescript
24
+ * const operation = new OasOperation({
25
+ * path: '/posts',
26
+ * method: 'post',
27
+ * // ... other operation details
28
+ * });
29
+ *
30
+ * const key = toOperationGeneratorKey({
31
+ * generatorId: 'rest-client',
32
+ * operation
33
+ * });
34
+ * // Result: 'rest-client|/posts|post' (branded)
35
+ * ```
36
+ */
3
37
  export const toOperationGeneratorKey = ({ generatorId, ...rest }) => {
4
38
  const { path, method } = 'operation' in rest ? rest.operation : rest;
5
39
  const nakedKey = `${generatorId}|${path}|${method}`;
6
40
  return nakedKey;
7
41
  };
42
+ /**
43
+ * Creates a model generator key from generator ID and schema reference name.
44
+ *
45
+ * Model generator keys uniquely identify generators processing specific
46
+ * OpenAPI schema models. The key format is: `generatorId|refName`
47
+ *
48
+ * @param args - Model generator key arguments
49
+ * @returns A branded ModelGeneratorKey
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const key = toModelGeneratorKey({
54
+ * generatorId: 'typescript-interfaces',
55
+ * refName: 'User'
56
+ * });
57
+ * // Result: 'typescript-interfaces|User' (branded)
58
+ *
59
+ * const validationKey = toModelGeneratorKey({
60
+ * generatorId: 'zod-schemas',
61
+ * refName: 'CreateUserRequest'
62
+ * });
63
+ * // Result: 'zod-schemas|CreateUserRequest' (branded)
64
+ * ```
65
+ */
8
66
  export const toModelGeneratorKey = ({ generatorId, refName }) => {
9
67
  const nakedKey = `${generatorId}|${refName}`;
10
68
  return nakedKey;
11
69
  };
70
+ /**
71
+ * Creates a generator-only key for global/utility generators.
72
+ *
73
+ * Generator-only keys identify generators that produce artifacts not tied
74
+ * to specific operations or models, such as configuration files, base classes,
75
+ * utilities, or documentation.
76
+ *
77
+ * @param args - Generator-only key arguments
78
+ * @returns A branded GeneratorOnlyKey
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const configKey = toGeneratorOnlyKey({
83
+ * generatorId: 'api-config'
84
+ * });
85
+ * // Result: 'api-config' (branded)
86
+ *
87
+ * const utilsKey = toGeneratorOnlyKey({
88
+ * generatorId: 'common-utilities'
89
+ * });
90
+ * // Result: 'common-utilities' (branded)
91
+ * ```
92
+ */
12
93
  export const toGeneratorOnlyKey = ({ generatorId }) => {
13
94
  const nakedKey = `${generatorId}`;
14
95
  return nakedKey;
15
96
  };
97
+ /**
98
+ * Type guard to check if a value is a valid GeneratorKey.
99
+ *
100
+ * This function validates that the argument is one of the three
101
+ * generator key types: operation, model, or generator-only.
102
+ *
103
+ * @param arg - Value to check
104
+ * @returns True if the value is a valid GeneratorKey
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const key = 'api-client|/users|get';
109
+ *
110
+ * if (isGeneratorKey(key)) {
111
+ * // key is now typed as GeneratorKey
112
+ * const generatorId = toGeneratorId(key);
113
+ * console.log(generatorId); // 'api-client'
114
+ * }
115
+ * ```
116
+ */
16
117
  export const isGeneratorKey = (arg) => {
17
118
  return (isModelGeneratorKey(arg) ||
18
119
  isOperationGeneratorKey(arg) ||
19
120
  isGeneratorOnlyKey(arg));
20
121
  };
122
+ /**
123
+ * Type guard to check if a value is a valid OperationGeneratorKey.
124
+ *
125
+ * Validates that the argument is a string with the correct format:
126
+ * `generatorId|path|method` where each part is non-empty and method
127
+ * is a valid HTTP method.
128
+ *
129
+ * @param arg - Value to check
130
+ * @returns True if the value is a valid OperationGeneratorKey
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const key = 'api-client|/users/{id}|get';
135
+ *
136
+ * if (isOperationGeneratorKey(key)) {
137
+ * // key is now typed as OperationGeneratorKey
138
+ * const obj = fromGeneratorKey(key);
139
+ * console.log(obj.type); // 'operation'
140
+ * console.log(obj.generatorId); // 'api-client'
141
+ * console.log(obj.path); // '/users/{id}'
142
+ * console.log(obj.method); // 'get'
143
+ * }
144
+ * ```
145
+ */
21
146
  export const isOperationGeneratorKey = (arg) => {
22
147
  if (typeof arg !== 'string') {
23
148
  return false;
@@ -38,6 +163,28 @@ export const isOperationGeneratorKey = (arg) => {
38
163
  }
39
164
  return true;
40
165
  };
166
+ /**
167
+ * Type guard to check if a value is a valid ModelGeneratorKey.
168
+ *
169
+ * Validates that the argument is a string with the correct format:
170
+ * `generatorId|refName` where both parts are non-empty strings.
171
+ *
172
+ * @param arg - Value to check
173
+ * @returns True if the value is a valid ModelGeneratorKey
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * const key = 'zod-schemas|User';
178
+ *
179
+ * if (isModelGeneratorKey(key)) {
180
+ * // key is now typed as ModelGeneratorKey
181
+ * const obj = fromGeneratorKey(key);
182
+ * console.log(obj.type); // 'model'
183
+ * console.log(obj.generatorId); // 'zod-schemas'
184
+ * console.log(obj.refName); // 'User'
185
+ * }
186
+ * ```
187
+ */
41
188
  export const isModelGeneratorKey = (arg) => {
42
189
  if (typeof arg !== 'string') {
43
190
  return false;
@@ -55,12 +202,65 @@ export const isModelGeneratorKey = (arg) => {
55
202
  }
56
203
  return true;
57
204
  };
205
+ /**
206
+ * Type guard to check if a value is a valid GeneratorOnlyKey.
207
+ *
208
+ * Validates that the argument is a non-empty string. Generator-only keys
209
+ * are simple strings containing just the generator ID.
210
+ *
211
+ * @param arg - Value to check
212
+ * @returns True if the value is a valid GeneratorOnlyKey
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const key = 'api-config';
217
+ *
218
+ * if (isGeneratorOnlyKey(key)) {
219
+ * // key is now typed as GeneratorOnlyKey
220
+ * const obj = fromGeneratorKey(key);
221
+ * console.log(obj.type); // 'generator-only'
222
+ * console.log(obj.generatorId); // 'api-config'
223
+ * }
224
+ * ```
225
+ */
58
226
  export const isGeneratorOnlyKey = (arg) => {
59
227
  if (typeof arg !== 'string') {
60
228
  return false;
61
229
  }
62
230
  return Boolean(arg.length);
63
231
  };
232
+ /**
233
+ * Extracts the generator ID from any type of GeneratorKey.
234
+ *
235
+ * This utility function parses the generator key to extract just the
236
+ * generator identifier, regardless of the key type. For operation and
237
+ * model keys, it extracts the first part before the pipe. For generator-only
238
+ * keys, it returns the entire key since it's just the generator ID.
239
+ *
240
+ * @param generatorKey - Any type of generator key
241
+ * @returns The generator ID string
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * const opKey = toOperationGeneratorKey({
246
+ * generatorId: 'api-client',
247
+ * path: '/users',
248
+ * method: 'get'
249
+ * });
250
+ * console.log(toGeneratorId(opKey)); // 'api-client'
251
+ *
252
+ * const modelKey = toModelGeneratorKey({
253
+ * generatorId: 'typescript-types',
254
+ * refName: 'User'
255
+ * });
256
+ * console.log(toGeneratorId(modelKey)); // 'typescript-types'
257
+ *
258
+ * const globalKey = toGeneratorOnlyKey({
259
+ * generatorId: 'utilities'
260
+ * });
261
+ * console.log(toGeneratorId(globalKey)); // 'utilities'
262
+ * ```
263
+ */
64
264
  export const toGeneratorId = (generatorKey) => {
65
265
  if (isOperationGeneratorKey(generatorKey)) {
66
266
  return generatorKey.split('|')[0];
@@ -70,6 +270,49 @@ export const toGeneratorId = (generatorKey) => {
70
270
  }
71
271
  return generatorKey;
72
272
  };
273
+ /**
274
+ * Parses a GeneratorKey into its structured object representation.
275
+ *
276
+ * This function decomposes any generator key into a structured object
277
+ * with discriminated union types, making it easier to work with the
278
+ * key components in a type-safe manner.
279
+ *
280
+ * @param generatorKey - Any type of generator key to parse
281
+ * @returns Parsed generator key object with discriminated type
282
+ *
283
+ * @example Operation key parsing
284
+ * ```typescript
285
+ * const opKey = 'api-client|/users/{id}|get' as OperationGeneratorKey;
286
+ * const parsed = fromGeneratorKey(opKey);
287
+ *
288
+ * if (parsed.type === 'operation') {
289
+ * console.log(parsed.generatorId); // 'api-client'
290
+ * console.log(parsed.path); // '/users/{id}'
291
+ * console.log(parsed.method); // 'get'
292
+ * }
293
+ * ```
294
+ *
295
+ * @example Model key parsing
296
+ * ```typescript
297
+ * const modelKey = 'zod-schemas|User' as ModelGeneratorKey;
298
+ * const parsed = fromGeneratorKey(modelKey);
299
+ *
300
+ * if (parsed.type === 'model') {
301
+ * console.log(parsed.generatorId); // 'zod-schemas'
302
+ * console.log(parsed.refName); // 'User'
303
+ * }
304
+ * ```
305
+ *
306
+ * @example Generator-only key parsing
307
+ * ```typescript
308
+ * const globalKey = 'utilities' as GeneratorOnlyKey;
309
+ * const parsed = fromGeneratorKey(globalKey);
310
+ *
311
+ * if (parsed.type === 'generator-only') {
312
+ * console.log(parsed.generatorId); // 'utilities'
313
+ * }
314
+ * ```
315
+ */
73
316
  export const fromGeneratorKey = (generatorKey) => {
74
317
  if (isOperationGeneratorKey(generatorKey)) {
75
318
  const [generatorId, path, method] = generatorKey.split('|');
@@ -1,8 +1,127 @@
1
1
  import type { OperationConfig } from '../dsl/operation/types.js';
2
2
  import type { ModelConfig } from '../dsl/model/types.js';
3
+ /**
4
+ * Union type representing all possible generator configurations.
5
+ *
6
+ * Generator configurations define how different types of generators should
7
+ * process OpenAPI documents. This includes both operation generators (which
8
+ * process API endpoints) and model generators (which process data schemas).
9
+ *
10
+ * @template EnrichmentType - Optional type for custom enrichment data
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { GeneratorConfig } from '@skmtc/core';
15
+ *
16
+ * // Operation generator configuration
17
+ * const apiClientConfig: GeneratorConfig = {
18
+ * type: 'operation',
19
+ * generatorId: 'api-client',
20
+ * settings: {
21
+ * exportPath: './src/api/client.ts',
22
+ * enrichment: customEnrichments
23
+ * },
24
+ * toGenerator: (args) => new ApiClientGenerator(args)
25
+ * };
26
+ *
27
+ * // Model generator configuration
28
+ * const typescriptModels: GeneratorConfig = {
29
+ * type: 'model',
30
+ * generatorId: 'typescript-models',
31
+ * settings: {
32
+ * exportPath: './src/types/models.ts'
33
+ * },
34
+ * toGenerator: (args) => new TypeScriptModelGenerator(args)
35
+ * };
36
+ * ```
37
+ */
3
38
  export type GeneratorConfig<EnrichmentType = undefined> = OperationConfig<EnrichmentType> | ModelConfig<EnrichmentType>;
39
+ /**
40
+ * Type-safe mapping of generator configurations.
41
+ *
42
+ * This type preserves the structure and types of generator configurations
43
+ * within a map, ensuring that each generator maintains its specific
44
+ * configuration type and enrichment data.
45
+ *
46
+ * @template G - The generator configuration type
47
+ * @template EnrichmentType - The enrichment type for the generators
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * type MyGenerators = {
52
+ * 'api-client': OperationConfig<ApiEnrichment>;
53
+ * 'typescript-models': ModelConfig<ModelEnrichment>;
54
+ * 'validation': ModelConfig<ValidationEnrichment>;
55
+ * };
56
+ *
57
+ * type MyGeneratorsMap = GeneratorsMap<MyGenerators, undefined>;
58
+ * // Preserves the exact structure and types of MyGenerators
59
+ * ```
60
+ */
4
61
  export type GeneratorsMap<G extends GeneratorConfig<EnrichmentType>, EnrichmentType> = {
5
62
  [K in keyof G]: G[K];
6
63
  };
64
+ /**
65
+ * Container type for a complete generators map with optional enrichment.
66
+ *
67
+ * This type represents a complete mapping of generators that can process
68
+ * an OpenAPI document. It's used as the main configuration structure
69
+ * passed to the SKMTC processing pipeline.
70
+ *
71
+ * @template EnrichmentType - Optional type for custom enrichment data across all generators
72
+ *
73
+ * @example Basic generators map
74
+ * ```typescript
75
+ * import { GeneratorsMapContainer } from '@skmtc/core';
76
+ *
77
+ * const generators: GeneratorsMapContainer = {
78
+ * 'api-client': {
79
+ * type: 'operation',
80
+ * generatorId: 'api-client',
81
+ * settings: { exportPath: './src/api.ts' },
82
+ * toGenerator: (args) => new ApiClientGenerator(args)
83
+ * },
84
+ * 'typescript-models': {
85
+ * type: 'model',
86
+ * generatorId: 'typescript-models',
87
+ * settings: { exportPath: './src/models.ts' },
88
+ * toGenerator: (args) => new TypeScriptModels(args)
89
+ * }
90
+ * };
91
+ *
92
+ * // Use with toArtifacts
93
+ * const result = await toArtifacts({
94
+ * documentObject: openApiDoc,
95
+ * settings: clientSettings,
96
+ * toGeneratorConfigMap: () => generators,
97
+ * traceId: 'generation',
98
+ * spanId: 'main',
99
+ * startAt: Date.now()
100
+ * });
101
+ * ```
102
+ *
103
+ * @example With enrichments
104
+ * ```typescript
105
+ * type MyEnrichments = {
106
+ * customValidation: boolean;
107
+ * generateComments: boolean;
108
+ * };
109
+ *
110
+ * const enrichedGenerators: GeneratorsMapContainer<MyEnrichments> = {
111
+ * 'enhanced-models': {
112
+ * type: 'model',
113
+ * generatorId: 'enhanced-models',
114
+ * settings: {
115
+ * exportPath: './src/enhanced.ts',
116
+ * enrichment: {
117
+ * customValidation: true,
118
+ * generateComments: true
119
+ * }
120
+ * },
121
+ * toGenerator: (args) => new EnhancedModelGenerator(args)
122
+ * }
123
+ * };
124
+ * ```
125
+ */
7
126
  export type GeneratorsMapContainer<EnrichmentType = undefined> = GeneratorsMap<GeneratorConfig<EnrichmentType>, EnrichmentType>;
8
127
  //# sourceMappingURL=GeneratorType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GeneratorType.d.ts","sourceRoot":"","sources":["../../src/types/GeneratorType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,MAAM,eAAe,CAAC,cAAc,GAAG,SAAS,IAClD,eAAe,CAAC,cAAc,CAAC,GAC/B,WAAW,CAAC,cAAc,CAAC,CAAA;AAE/B,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,eAAe,CAAC,cAAc,CAAC,EAAE,cAAc,IAAI;KACpF,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,CAAA;AAED,MAAM,MAAM,sBAAsB,CAAC,cAAc,GAAG,SAAS,IAAI,aAAa,CAC5E,eAAe,CAAC,cAAc,CAAC,EAC/B,cAAc,CACf,CAAA"}
1
+ {"version":3,"file":"GeneratorType.d.ts","sourceRoot":"","sources":["../../src/types/GeneratorType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,eAAe,CAAC,cAAc,GAAG,SAAS,IAClD,eAAe,CAAC,cAAc,CAAC,GAC/B,WAAW,CAAC,cAAc,CAAC,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,eAAe,CAAC,cAAc,CAAC,EAAE,cAAc,IAAI;KACpF,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,MAAM,sBAAsB,CAAC,cAAc,GAAG,SAAS,IAAI,aAAa,CAC5E,eAAe,CAAC,cAAc,CAAC,EAC/B,cAAc,CACf,CAAA"}
@@ -1,7 +1,42 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import * as v from 'valibot';
3
+ /**
4
+ * Array of all valid HTTP methods supported by OpenAPI v3.
5
+ *
6
+ * This constant array includes all HTTP methods that can be used
7
+ * in OpenAPI path operations, as defined by the OpenAPI specification.
8
+ */
3
9
  export declare const methodValues: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
10
+ /**
11
+ * Array of HTTP methods excluding TRACE.
12
+ *
13
+ * This is a filtered version of {@link methodValues} that excludes the TRACE method,
14
+ * which is sometimes excluded from API operations for security reasons.
15
+ */
4
16
  export declare const methodValuesNoTrace: string[];
17
+ /**
18
+ * Valibot schema for validating HTTP method strings.
19
+ *
20
+ * This union schema validates that a string value is one of the valid
21
+ * HTTP methods supported by OpenAPI. Used throughout the codebase for
22
+ * runtime validation of method values.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import * as v from 'valibot';
27
+ * import { method } from '@skmtc/core';
28
+ *
29
+ * // Valid method
30
+ * const result1 = v.parse(method, 'get'); // 'get'
31
+ *
32
+ * // Invalid method throws ValiError
33
+ * try {
34
+ * v.parse(method, 'invalid');
35
+ * } catch (error) {
36
+ * console.log('Invalid method');
37
+ * }
38
+ * ```
39
+ */
5
40
  export declare const method: v.UnionSchema<[
6
41
  v.LiteralSchema<'get', undefined>,
7
42
  v.LiteralSchema<'post', undefined>,
@@ -12,7 +47,81 @@ export declare const method: v.UnionSchema<[
12
47
  v.LiteralSchema<'options', undefined>,
13
48
  v.LiteralSchema<'trace', undefined>
14
49
  ], undefined>;
50
+ /**
51
+ * TypeScript type representing valid HTTP methods.
52
+ *
53
+ * This union type includes all HTTP methods supported by OpenAPI v3 operations.
54
+ * It's used throughout the codebase for type safety when working with API methods.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { Method } from '@skmtc/core';
59
+ *
60
+ * function processOperation(method: Method, path: string) {
61
+ * switch (method) {
62
+ * case 'get':
63
+ * return handleGet(path);
64
+ * case 'post':
65
+ * return handlePost(path);
66
+ * // ... handle other methods
67
+ * default:
68
+ * // TypeScript ensures exhaustive checking
69
+ * const _exhaustive: never = method;
70
+ * throw new Error(`Unhandled method: ${method}`);
71
+ * }
72
+ * }
73
+ * ```
74
+ */
15
75
  export type Method = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
76
+ /**
77
+ * Valibot schema for validating arrays of HTTP methods.
78
+ *
79
+ * This schema validates that an array contains only valid HTTP method strings.
80
+ * Useful for validating configuration objects that specify multiple methods.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import * as v from 'valibot';
85
+ * import { methods } from '@skmtc/core';
86
+ *
87
+ * // Valid methods array
88
+ * const validMethods = v.parse(methods, ['get', 'post', 'put']); // ['get', 'post', 'put']
89
+ *
90
+ * // Invalid methods array throws ValiError
91
+ * try {
92
+ * v.parse(methods, ['get', 'invalid', 'post']);
93
+ * } catch (error) {
94
+ * console.log('Invalid methods in array');
95
+ * }
96
+ * ```
97
+ */
16
98
  export declare const methods: v.ArraySchema<typeof method, undefined>;
99
+ /**
100
+ * Type guard to check if a value is a valid HTTP Method.
101
+ *
102
+ * This function uses the Valibot schema to safely determine if an unknown
103
+ * value is a valid HTTP method string. It's particularly useful when parsing
104
+ * user input or external data.
105
+ *
106
+ * @param arg - Value to check
107
+ * @returns True if the value is a valid Method
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { isMethod } from '@skmtc/core';
112
+ *
113
+ * function handleRequest(methodStr: unknown, path: string) {
114
+ * if (isMethod(methodStr)) {
115
+ * // methodStr is now typed as Method
116
+ * console.log(`Processing ${methodStr.toUpperCase()} ${path}`);
117
+ * } else {
118
+ * throw new Error(`Invalid HTTP method: ${methodStr}`);
119
+ * }
120
+ * }
121
+ *
122
+ * handleRequest('get', '/users'); // Works
123
+ * handleRequest('invalid', '/users'); // Throws error
124
+ * ```
125
+ */
17
126
  export declare const isMethod: (arg: unknown) => arg is Method;
18
127
  //# sourceMappingURL=Method.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Method.d.ts","sourceRoot":"","sources":["../../src/types/Method.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,YAAY,gFASf,CAAA;AAEV,eAAO,MAAM,mBAAmB,UAA+D,CAAA;AAE/F,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,WAAW,CAChC;IACE,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC;IACjC,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC;IAClC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC;IACjC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC;IACnC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC;IACpC,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC;IAClC,CAAC,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC;IACrC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC;CACpC,EACD,SAAS,CAUT,CAAA;AAEF,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;AAI/F,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,OAAO,MAAM,EAAE,SAAS,CAAmB,CAAA;AAE/E,eAAO,MAAM,QAAQ,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,MAE9C,CAAA"}
1
+ {"version":3,"file":"Method.d.ts","sourceRoot":"","sources":["../../src/types/Method.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;;;GAKG;AACH,eAAO,MAAM,YAAY,gFASf,CAAA;AAEV;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,UAA+D,CAAA;AAE/F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,WAAW,CAChC;IACE,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC;IACjC,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC;IAClC,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC;IACjC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC;IACnC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC;IACpC,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC;IAClC,CAAC,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC;IACrC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC;CACpC,EACD,SAAS,CAUT,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;AAG/F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,WAAW,CAAC,OAAO,MAAM,EAAE,SAAS,CAAmB,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,MAE9C,CAAA"}
@@ -1,5 +1,11 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import * as v from 'valibot';
3
+ /**
4
+ * Array of all valid HTTP methods supported by OpenAPI v3.
5
+ *
6
+ * This constant array includes all HTTP methods that can be used
7
+ * in OpenAPI path operations, as defined by the OpenAPI specification.
8
+ */
3
9
  export const methodValues = [
4
10
  'get',
5
11
  'put',
@@ -10,7 +16,36 @@ export const methodValues = [
10
16
  'patch',
11
17
  'trace'
12
18
  ];
19
+ /**
20
+ * Array of HTTP methods excluding TRACE.
21
+ *
22
+ * This is a filtered version of {@link methodValues} that excludes the TRACE method,
23
+ * which is sometimes excluded from API operations for security reasons.
24
+ */
13
25
  export const methodValuesNoTrace = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch'];
26
+ /**
27
+ * Valibot schema for validating HTTP method strings.
28
+ *
29
+ * This union schema validates that a string value is one of the valid
30
+ * HTTP methods supported by OpenAPI. Used throughout the codebase for
31
+ * runtime validation of method values.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import * as v from 'valibot';
36
+ * import { method } from '@skmtc/core';
37
+ *
38
+ * // Valid method
39
+ * const result1 = v.parse(method, 'get'); // 'get'
40
+ *
41
+ * // Invalid method throws ValiError
42
+ * try {
43
+ * v.parse(method, 'invalid');
44
+ * } catch (error) {
45
+ * console.log('Invalid method');
46
+ * }
47
+ * ```
48
+ */
14
49
  export const method = v.union([
15
50
  v.literal('get'),
16
51
  v.literal('post'),
@@ -21,7 +56,56 @@ export const method = v.union([
21
56
  v.literal('options'),
22
57
  v.literal('trace')
23
58
  ]);
59
+ /**
60
+ * Valibot schema for validating arrays of HTTP methods.
61
+ *
62
+ * This schema validates that an array contains only valid HTTP method strings.
63
+ * Useful for validating configuration objects that specify multiple methods.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import * as v from 'valibot';
68
+ * import { methods } from '@skmtc/core';
69
+ *
70
+ * // Valid methods array
71
+ * const validMethods = v.parse(methods, ['get', 'post', 'put']); // ['get', 'post', 'put']
72
+ *
73
+ * // Invalid methods array throws ValiError
74
+ * try {
75
+ * v.parse(methods, ['get', 'invalid', 'post']);
76
+ * } catch (error) {
77
+ * console.log('Invalid methods in array');
78
+ * }
79
+ * ```
80
+ */
24
81
  export const methods = v.array(method);
82
+ /**
83
+ * Type guard to check if a value is a valid HTTP Method.
84
+ *
85
+ * This function uses the Valibot schema to safely determine if an unknown
86
+ * value is a valid HTTP method string. It's particularly useful when parsing
87
+ * user input or external data.
88
+ *
89
+ * @param arg - Value to check
90
+ * @returns True if the value is a valid Method
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { isMethod } from '@skmtc/core';
95
+ *
96
+ * function handleRequest(methodStr: unknown, path: string) {
97
+ * if (isMethod(methodStr)) {
98
+ * // methodStr is now typed as Method
99
+ * console.log(`Processing ${methodStr.toUpperCase()} ${path}`);
100
+ * } else {
101
+ * throw new Error(`Invalid HTTP method: ${methodStr}`);
102
+ * }
103
+ * }
104
+ *
105
+ * handleRequest('get', '/users'); // Works
106
+ * handleRequest('invalid', '/users'); // Throws error
107
+ * ```
108
+ */
25
109
  export const isMethod = (arg) => {
26
110
  return v.safeParse(method, arg).success;
27
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.785",
3
+ "version": "0.0.786",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/skmtc/skmtc.git"