@skmtc/core 0.0.785 → 0.0.787
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.
- package/esm/dsl/ContentSettings.d.ts +164 -0
- package/esm/dsl/ContentSettings.d.ts.map +1 -1
- package/esm/dsl/ContentSettings.js +151 -0
- package/esm/dsl/Definition.d.ts +199 -0
- package/esm/dsl/Definition.d.ts.map +1 -1
- package/esm/dsl/Definition.js +189 -0
- package/esm/dsl/EntityType.d.ts +83 -0
- package/esm/dsl/EntityType.d.ts.map +1 -1
- package/esm/dsl/EntityType.js +83 -0
- package/esm/dsl/Identifier.d.ts +152 -0
- package/esm/dsl/Identifier.d.ts.map +1 -1
- package/esm/dsl/Identifier.js +152 -0
- package/esm/dsl/Import.d.ts +221 -0
- package/esm/dsl/Import.d.ts.map +1 -1
- package/esm/dsl/Import.js +202 -0
- package/esm/dsl/operation/OperationBase.d.ts +181 -1
- package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
- package/esm/dsl/operation/OperationBase.js +181 -1
- package/esm/oas/array/Array.d.ts +109 -1
- package/esm/oas/array/Array.d.ts.map +1 -1
- package/esm/oas/array/Array.js +93 -1
- package/esm/oas/document/Document.d.ts +155 -1
- package/esm/oas/document/Document.d.ts.map +1 -1
- package/esm/oas/document/Document.js +141 -2
- package/esm/oas/integer/Integer.d.ts +98 -0
- package/esm/oas/integer/Integer.d.ts.map +1 -1
- package/esm/oas/integer/Integer.js +80 -0
- package/esm/oas/object/Object.d.ts +255 -10
- package/esm/oas/object/Object.d.ts.map +1 -1
- package/esm/oas/object/Object.js +229 -10
- package/esm/oas/string/String.d.ts +103 -1
- package/esm/oas/string/String.d.ts.map +1 -1
- package/esm/oas/string/String.js +87 -1
- package/esm/types/Brand.d.ts +74 -0
- package/esm/types/Brand.d.ts.map +1 -1
- package/esm/types/Brand.js +9 -0
- package/esm/types/GeneratorKeys.d.ts +336 -0
- package/esm/types/GeneratorKeys.d.ts.map +1 -1
- package/esm/types/GeneratorKeys.js +243 -0
- package/esm/types/GeneratorType.d.ts +119 -0
- package/esm/types/GeneratorType.d.ts.map +1 -1
- package/esm/types/Method.d.ts +109 -0
- package/esm/types/Method.d.ts.map +1 -1
- package/esm/types/Method.js +84 -0
- package/esm/types/RefName.d.ts +61 -0
- package/esm/types/RefName.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/dsl/ContentSettings.d.ts +164 -0
- package/script/dsl/ContentSettings.d.ts.map +1 -1
- package/script/dsl/ContentSettings.js +151 -0
- package/script/dsl/Definition.d.ts +199 -0
- package/script/dsl/Definition.d.ts.map +1 -1
- package/script/dsl/Definition.js +189 -0
- package/script/dsl/EntityType.d.ts +83 -0
- package/script/dsl/EntityType.d.ts.map +1 -1
- package/script/dsl/EntityType.js +83 -0
- package/script/dsl/Identifier.d.ts +152 -0
- package/script/dsl/Identifier.d.ts.map +1 -1
- package/script/dsl/Identifier.js +152 -0
- package/script/dsl/Import.d.ts +221 -0
- package/script/dsl/Import.d.ts.map +1 -1
- package/script/dsl/Import.js +202 -0
- package/script/dsl/operation/OperationBase.d.ts +181 -1
- package/script/dsl/operation/OperationBase.d.ts.map +1 -1
- package/script/dsl/operation/OperationBase.js +181 -1
- package/script/oas/array/Array.d.ts +109 -1
- package/script/oas/array/Array.d.ts.map +1 -1
- package/script/oas/array/Array.js +93 -1
- package/script/oas/document/Document.d.ts +155 -1
- package/script/oas/document/Document.d.ts.map +1 -1
- package/script/oas/document/Document.js +141 -2
- package/script/oas/integer/Integer.d.ts +98 -0
- package/script/oas/integer/Integer.d.ts.map +1 -1
- package/script/oas/integer/Integer.js +80 -0
- package/script/oas/object/Object.d.ts +255 -10
- package/script/oas/object/Object.d.ts.map +1 -1
- package/script/oas/object/Object.js +229 -10
- package/script/oas/string/String.d.ts +103 -1
- package/script/oas/string/String.d.ts.map +1 -1
- package/script/oas/string/String.js +87 -1
- package/script/types/Brand.d.ts +74 -0
- package/script/types/Brand.d.ts.map +1 -1
- package/script/types/Brand.js +9 -0
- package/script/types/GeneratorKeys.d.ts +336 -0
- package/script/types/GeneratorKeys.d.ts.map +1 -1
- package/script/types/GeneratorKeys.js +243 -0
- package/script/types/GeneratorType.d.ts +119 -0
- package/script/types/GeneratorType.d.ts.map +1 -1
- package/script/types/Method.d.ts +109 -0
- package/script/types/Method.d.ts.map +1 -1
- package/script/types/Method.js +84 -0
- package/script/types/RefName.d.ts +61 -0
- package/script/types/RefName.d.ts.map +1 -1
|
@@ -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"}
|
package/script/types/Method.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
package/script/types/Method.js
CHANGED
|
@@ -36,6 +36,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.isMethod = exports.methods = exports.method = exports.methodValuesNoTrace = exports.methodValues = void 0;
|
|
37
37
|
require("../_dnt.polyfills.js");
|
|
38
38
|
const v = __importStar(require("valibot"));
|
|
39
|
+
/**
|
|
40
|
+
* Array of all valid HTTP methods supported by OpenAPI v3.
|
|
41
|
+
*
|
|
42
|
+
* This constant array includes all HTTP methods that can be used
|
|
43
|
+
* in OpenAPI path operations, as defined by the OpenAPI specification.
|
|
44
|
+
*/
|
|
39
45
|
exports.methodValues = [
|
|
40
46
|
'get',
|
|
41
47
|
'put',
|
|
@@ -46,7 +52,36 @@ exports.methodValues = [
|
|
|
46
52
|
'patch',
|
|
47
53
|
'trace'
|
|
48
54
|
];
|
|
55
|
+
/**
|
|
56
|
+
* Array of HTTP methods excluding TRACE.
|
|
57
|
+
*
|
|
58
|
+
* This is a filtered version of {@link methodValues} that excludes the TRACE method,
|
|
59
|
+
* which is sometimes excluded from API operations for security reasons.
|
|
60
|
+
*/
|
|
49
61
|
exports.methodValuesNoTrace = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch'];
|
|
62
|
+
/**
|
|
63
|
+
* Valibot schema for validating HTTP method strings.
|
|
64
|
+
*
|
|
65
|
+
* This union schema validates that a string value is one of the valid
|
|
66
|
+
* HTTP methods supported by OpenAPI. Used throughout the codebase for
|
|
67
|
+
* runtime validation of method values.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import * as v from 'valibot';
|
|
72
|
+
* import { method } from '@skmtc/core';
|
|
73
|
+
*
|
|
74
|
+
* // Valid method
|
|
75
|
+
* const result1 = v.parse(method, 'get'); // 'get'
|
|
76
|
+
*
|
|
77
|
+
* // Invalid method throws ValiError
|
|
78
|
+
* try {
|
|
79
|
+
* v.parse(method, 'invalid');
|
|
80
|
+
* } catch (error) {
|
|
81
|
+
* console.log('Invalid method');
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
50
85
|
exports.method = v.union([
|
|
51
86
|
v.literal('get'),
|
|
52
87
|
v.literal('post'),
|
|
@@ -57,7 +92,56 @@ exports.method = v.union([
|
|
|
57
92
|
v.literal('options'),
|
|
58
93
|
v.literal('trace')
|
|
59
94
|
]);
|
|
95
|
+
/**
|
|
96
|
+
* Valibot schema for validating arrays of HTTP methods.
|
|
97
|
+
*
|
|
98
|
+
* This schema validates that an array contains only valid HTTP method strings.
|
|
99
|
+
* Useful for validating configuration objects that specify multiple methods.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import * as v from 'valibot';
|
|
104
|
+
* import { methods } from '@skmtc/core';
|
|
105
|
+
*
|
|
106
|
+
* // Valid methods array
|
|
107
|
+
* const validMethods = v.parse(methods, ['get', 'post', 'put']); // ['get', 'post', 'put']
|
|
108
|
+
*
|
|
109
|
+
* // Invalid methods array throws ValiError
|
|
110
|
+
* try {
|
|
111
|
+
* v.parse(methods, ['get', 'invalid', 'post']);
|
|
112
|
+
* } catch (error) {
|
|
113
|
+
* console.log('Invalid methods in array');
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
60
117
|
exports.methods = v.array(exports.method);
|
|
118
|
+
/**
|
|
119
|
+
* Type guard to check if a value is a valid HTTP Method.
|
|
120
|
+
*
|
|
121
|
+
* This function uses the Valibot schema to safely determine if an unknown
|
|
122
|
+
* value is a valid HTTP method string. It's particularly useful when parsing
|
|
123
|
+
* user input or external data.
|
|
124
|
+
*
|
|
125
|
+
* @param arg - Value to check
|
|
126
|
+
* @returns True if the value is a valid Method
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* import { isMethod } from '@skmtc/core';
|
|
131
|
+
*
|
|
132
|
+
* function handleRequest(methodStr: unknown, path: string) {
|
|
133
|
+
* if (isMethod(methodStr)) {
|
|
134
|
+
* // methodStr is now typed as Method
|
|
135
|
+
* console.log(`Processing ${methodStr.toUpperCase()} ${path}`);
|
|
136
|
+
* } else {
|
|
137
|
+
* throw new Error(`Invalid HTTP method: ${methodStr}`);
|
|
138
|
+
* }
|
|
139
|
+
* }
|
|
140
|
+
*
|
|
141
|
+
* handleRequest('get', '/users'); // Works
|
|
142
|
+
* handleRequest('invalid', '/users'); // Throws error
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
61
145
|
const isMethod = (arg) => {
|
|
62
146
|
return v.safeParse(exports.method, arg).success;
|
|
63
147
|
};
|
|
@@ -1,4 +1,65 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
2
|
import type { Brand } from './Brand.js';
|
|
3
|
+
/**
|
|
4
|
+
* Branded type representing a reference name for OpenAPI schemas.
|
|
5
|
+
*
|
|
6
|
+
* `RefName` is a branded string type that ensures type safety when working
|
|
7
|
+
* with schema reference names throughout the SKMTC system. It prevents
|
|
8
|
+
* accidental mixing of regular strings with schema reference identifiers.
|
|
9
|
+
*
|
|
10
|
+
* Reference names typically correspond to keys in the OpenAPI `components.schemas`
|
|
11
|
+
* section and are used to create cross-references between different parts
|
|
12
|
+
* of the schema definition.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { RefName } from '@skmtc/core';
|
|
17
|
+
*
|
|
18
|
+
* // RefName is extracted from OpenAPI schema references
|
|
19
|
+
* const userRefName: RefName = 'User' as RefName;
|
|
20
|
+
* const productRefName: RefName = 'Product' as RefName;
|
|
21
|
+
*
|
|
22
|
+
* // Used in schema references
|
|
23
|
+
* const userRef = new OasRef({
|
|
24
|
+
* refName: userRefName, // Type-safe reference name
|
|
25
|
+
* ref: '#/components/schemas/User'
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example In generator contexts
|
|
30
|
+
* ```typescript
|
|
31
|
+
* class ModelGenerator extends ModelBase {
|
|
32
|
+
* constructor(args: { refName: RefName; ... }) {
|
|
33
|
+
* super(args);
|
|
34
|
+
* // this.refName is guaranteed to be a valid schema reference
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* toDefinition(): Definition {
|
|
38
|
+
* // RefName ensures we're working with valid schema identifiers
|
|
39
|
+
* const schemaName = this.refName; // Type: RefName
|
|
40
|
+
* return new Definition({
|
|
41
|
+
* identifier: Identifier.createType(schemaName),
|
|
42
|
+
* // ...
|
|
43
|
+
* });
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Type safety benefits
|
|
49
|
+
* ```typescript
|
|
50
|
+
* function processSchema(refName: RefName) {
|
|
51
|
+
* // RefName brand ensures this is a valid schema reference
|
|
52
|
+
* console.log(`Processing schema: ${refName}`);
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* const validRef: RefName = 'User' as RefName;
|
|
56
|
+
* const regularString = 'just a string';
|
|
57
|
+
*
|
|
58
|
+
* processSchema(validRef); // ✅ Works - RefName type
|
|
59
|
+
* processSchema(regularString); // ❌ TypeScript error - string is not RefName
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @see {@link Brand} for the underlying branding mechanism
|
|
63
|
+
*/
|
|
3
64
|
export type RefName = Brand<string, 'RefName'>;
|
|
4
65
|
//# sourceMappingURL=RefName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefName.d.ts","sourceRoot":"","sources":["../../src/types/RefName.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"RefName.d.ts","sourceRoot":"","sources":["../../src/types/RefName.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA"}
|