@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/esm/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/esm/types/Method.js
CHANGED
|
@@ -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/esm/types/RefName.d.ts
CHANGED
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,182 @@
|
|
|
1
1
|
import type { Identifier } from './Identifier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Arguments for creating empty ContentSettings without enrichments.
|
|
4
|
+
*/
|
|
2
5
|
type EmptyArgs = {
|
|
6
|
+
/** The path where generated content will be exported */
|
|
3
7
|
exportPath: string;
|
|
8
|
+
/** The identifier for the content being generated */
|
|
4
9
|
identifier: Identifier;
|
|
5
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Arguments for creating ContentSettings with enrichments.
|
|
13
|
+
*
|
|
14
|
+
* @template EnrichmentType - The type of enrichment data
|
|
15
|
+
*/
|
|
6
16
|
type CreateArgs<EnrichmentType = undefined> = {
|
|
17
|
+
/** The identifier for the content being generated */
|
|
7
18
|
identifier: Identifier;
|
|
19
|
+
/** The path where generated content will be exported */
|
|
8
20
|
exportPath: string;
|
|
21
|
+
/** Custom enrichment data for extending generation */
|
|
9
22
|
enrichments: EnrichmentType;
|
|
10
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Configuration settings for content generators in the SKMTC DSL system.
|
|
26
|
+
*
|
|
27
|
+
* `ContentSettings` encapsulates the configuration needed by generators to
|
|
28
|
+
* produce content, including where to export the generated files, how to
|
|
29
|
+
* identify the content, and any custom enrichment data for extending
|
|
30
|
+
* the generation process.
|
|
31
|
+
*
|
|
32
|
+
* This class is used by both {@link ModelBase} and {@link OperationBase}
|
|
33
|
+
* to configure their generation behavior, providing a consistent interface
|
|
34
|
+
* for generator settings across the system.
|
|
35
|
+
*
|
|
36
|
+
* ## Key Features
|
|
37
|
+
*
|
|
38
|
+
* - **Export Path Management**: Specifies where generated content should be written
|
|
39
|
+
* - **Identifier Integration**: Links content to specific identifiers for naming
|
|
40
|
+
* - **Enrichment Support**: Allows custom data to extend generation capabilities
|
|
41
|
+
* - **Type Safety**: Generic enrichment typing for compile-time validation
|
|
42
|
+
*
|
|
43
|
+
* @template EnrichmentType - The type of enrichment data (default: undefined)
|
|
44
|
+
*
|
|
45
|
+
* @example Basic settings without enrichments
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { ContentSettings, Identifier } from '@skmtc/core';
|
|
48
|
+
*
|
|
49
|
+
* const settings = ContentSettings.empty({
|
|
50
|
+
* exportPath: './src/generated/models.ts',
|
|
51
|
+
* identifier: Identifier.createType('UserModels')
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* console.log(settings.exportPath); // './src/generated/models.ts'
|
|
55
|
+
* console.log(settings.enrichments); // undefined
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Settings with custom enrichments
|
|
59
|
+
* ```typescript
|
|
60
|
+
* type ValidationEnrichment = {
|
|
61
|
+
* validateRequired: boolean;
|
|
62
|
+
* generateComments: boolean;
|
|
63
|
+
* customValidators: string[];
|
|
64
|
+
* };
|
|
65
|
+
*
|
|
66
|
+
* const enrichedSettings = new ContentSettings({
|
|
67
|
+
* identifier: Identifier.createType('ValidatedModels'),
|
|
68
|
+
* exportPath: './src/models/validated.ts',
|
|
69
|
+
* enrichments: {
|
|
70
|
+
* validateRequired: true,
|
|
71
|
+
* generateComments: true,
|
|
72
|
+
* customValidators: ['email', 'phone']
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Access enrichment data in generators
|
|
77
|
+
* if (enrichedSettings.enrichments?.validateRequired) {
|
|
78
|
+
* // Generate validation logic
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Using with ModelBase
|
|
83
|
+
* ```typescript
|
|
84
|
+
* class ValidatedModelGenerator extends ModelBase<ValidationEnrichment> {
|
|
85
|
+
* constructor(args) {
|
|
86
|
+
* super({
|
|
87
|
+
* ...args,
|
|
88
|
+
* settings: new ContentSettings({
|
|
89
|
+
* identifier: Identifier.createType(args.refName),
|
|
90
|
+
* exportPath: './src/validated-models.ts',
|
|
91
|
+
* enrichments: {
|
|
92
|
+
* validateRequired: true,
|
|
93
|
+
* generateComments: false,
|
|
94
|
+
* customValidators: []
|
|
95
|
+
* }
|
|
96
|
+
* })
|
|
97
|
+
* });
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* toDefinition(): Definition {
|
|
101
|
+
* const validation = this.settings.enrichments?.validateRequired
|
|
102
|
+
* ? this.generateValidation()
|
|
103
|
+
* : '';
|
|
104
|
+
*
|
|
105
|
+
* return new Definition({
|
|
106
|
+
* context: this.context,
|
|
107
|
+
* identifier: this.settings.identifier,
|
|
108
|
+
* value: {
|
|
109
|
+
* generatorKey: this.generatorKey,
|
|
110
|
+
* content: `${this.generateInterface()}${validation}`
|
|
111
|
+
* }
|
|
112
|
+
* });
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
11
117
|
export declare class ContentSettings<EnrichmentType = undefined> {
|
|
118
|
+
/** The identifier for the content being generated */
|
|
12
119
|
identifier: Identifier;
|
|
120
|
+
/** The path where generated content will be exported */
|
|
13
121
|
exportPath: string;
|
|
122
|
+
/** Custom enrichment data for extending generation */
|
|
14
123
|
enrichments: EnrichmentType;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new ContentSettings instance with enrichments.
|
|
126
|
+
*
|
|
127
|
+
* @param args - Settings configuration
|
|
128
|
+
* @param args.identifier - The identifier for the content being generated
|
|
129
|
+
* @param args.exportPath - The path where generated content will be exported
|
|
130
|
+
* @param args.enrichments - Custom enrichment data for extending generation
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const settings = new ContentSettings({
|
|
135
|
+
* identifier: Identifier.createType('ApiModels'),
|
|
136
|
+
* exportPath: './src/api/models.ts',
|
|
137
|
+
* enrichments: {
|
|
138
|
+
* includeValidation: true,
|
|
139
|
+
* format: 'detailed'
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
15
144
|
constructor({ identifier, exportPath, enrichments }: CreateArgs<EnrichmentType>);
|
|
145
|
+
/**
|
|
146
|
+
* Factory method to create ContentSettings without enrichments.
|
|
147
|
+
*
|
|
148
|
+
* This is a convenience method for creating ContentSettings when no
|
|
149
|
+
* custom enrichment data is needed. It explicitly sets enrichments
|
|
150
|
+
* to undefined and returns a properly typed instance.
|
|
151
|
+
*
|
|
152
|
+
* @param args - Basic settings arguments
|
|
153
|
+
* @param args.identifier - The identifier for the content being generated
|
|
154
|
+
* @param args.exportPath - The path where generated content will be exported
|
|
155
|
+
* @returns ContentSettings instance with undefined enrichments
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const basicSettings = ContentSettings.empty({
|
|
160
|
+
* identifier: Identifier.createType('SimpleModels'),
|
|
161
|
+
* exportPath: './src/models.ts'
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* console.log(basicSettings.enrichments); // undefined
|
|
165
|
+
*
|
|
166
|
+
* // Use in generator
|
|
167
|
+
* class SimpleGenerator extends ModelBase {
|
|
168
|
+
* constructor(args) {
|
|
169
|
+
* super({
|
|
170
|
+
* ...args,
|
|
171
|
+
* settings: ContentSettings.empty({
|
|
172
|
+
* identifier: Identifier.createType(args.refName),
|
|
173
|
+
* exportPath: './src/simple-models.ts'
|
|
174
|
+
* })
|
|
175
|
+
* });
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
16
180
|
static empty({ identifier, exportPath }: EmptyArgs): ContentSettings<undefined>;
|
|
17
181
|
}
|
|
18
182
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSettings.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,KAAK,UAAU,CAAC,cAAc,GAAG,SAAS,IAAI;IAC5C,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,cAAc,CAAA;CAC5B,CAAA;AAED,qBAAa,eAAe,CAAC,cAAc,GAAG,SAAS;IACrD,UAAU,EAAE,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"ContentSettings.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;GAEG;AACH,KAAK,SAAS,GAAG;IACf,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAClB,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED;;;;GAIG;AACH,KAAK,UAAU,CAAC,cAAc,GAAG,SAAS,IAAI;IAC5C,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAA;IACtB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAClB,sDAAsD;IACtD,WAAW,EAAE,cAAc,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4FG;AACH,qBAAa,eAAe,CAAC,cAAc,GAAG,SAAS;IACrD,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAA;IAEtB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAElB,sDAAsD;IACtD,WAAW,EAAE,cAAc,CAAA;IAE3B;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,UAAU,CAAC,cAAc,CAAC;IAM/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC;CAOhF"}
|