@skmtc/core 0.0.782 → 0.0.783
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/context/CoreContext.d.ts +175 -0
- package/esm/context/CoreContext.d.ts.map +1 -1
- package/esm/context/CoreContext.js +178 -0
- package/esm/dsl/ContentBase.d.ts +115 -0
- package/esm/dsl/ContentBase.d.ts.map +1 -1
- package/esm/dsl/ContentBase.js +110 -0
- package/esm/helpers/strings.d.ts +63 -0
- package/esm/helpers/strings.d.ts.map +1 -1
- package/esm/helpers/strings.js +59 -0
- package/esm/mod.d.ts +66 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +66 -0
- package/esm/run/toArtifacts.d.ts +114 -0
- package/esm/run/toArtifacts.d.ts.map +1 -1
- package/esm/run/toArtifacts.js +86 -0
- package/esm/types/Settings.d.ts +129 -0
- package/esm/types/Settings.d.ts.map +1 -1
- package/esm/types/Settings.js +3 -0
- package/esm/typescript/List.d.ts +111 -0
- package/esm/typescript/List.d.ts.map +1 -1
- package/esm/typescript/List.js +106 -0
- package/package.json +1 -1
- package/script/context/CoreContext.d.ts +175 -0
- package/script/context/CoreContext.d.ts.map +1 -1
- package/script/context/CoreContext.js +178 -0
- package/script/dsl/ContentBase.d.ts +115 -0
- package/script/dsl/ContentBase.d.ts.map +1 -1
- package/script/dsl/ContentBase.js +110 -0
- package/script/helpers/strings.d.ts +63 -0
- package/script/helpers/strings.d.ts.map +1 -1
- package/script/helpers/strings.js +59 -0
- package/script/mod.d.ts +66 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +66 -0
- package/script/run/toArtifacts.d.ts +114 -0
- package/script/run/toArtifacts.d.ts.map +1 -1
- package/script/run/toArtifacts.js +86 -0
- package/script/types/Settings.d.ts +129 -0
- package/script/types/Settings.d.ts.map +1 -1
- package/script/types/Settings.js +3 -0
- package/script/typescript/List.d.ts +111 -0
- package/script/typescript/List.d.ts.map +1 -1
- package/script/typescript/List.js +106 -0
|
@@ -34,14 +34,189 @@ type ToArtifactsArgs = {
|
|
|
34
34
|
prettier?: PrettierConfigType;
|
|
35
35
|
silent: boolean;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* The main orchestration class for the SKMTC transformation pipeline.
|
|
39
|
+
*
|
|
40
|
+
* `CoreContext` manages the three-phase process of transforming OpenAPI v3 documents
|
|
41
|
+
* into code artifacts. It coordinates parsing, generation, and rendering phases while
|
|
42
|
+
* providing logging, tracing, and error handling capabilities.
|
|
43
|
+
*
|
|
44
|
+
* ## Pipeline Phases
|
|
45
|
+
*
|
|
46
|
+
* 1. **Parse Phase**: Uses {@link ParseContext} to convert OpenAPI JSON into OAS objects
|
|
47
|
+
* 2. **Generate Phase**: Uses {@link GenerateContext} to transform OAS objects with generators
|
|
48
|
+
* 3. **Render Phase**: Uses {@link RenderContext} to format and prepare final artifacts
|
|
49
|
+
*
|
|
50
|
+
* @example Basic usage
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { CoreContext } from '@skmtc/core';
|
|
53
|
+
*
|
|
54
|
+
* const context = new CoreContext({
|
|
55
|
+
* spanId: 'user-api-generation',
|
|
56
|
+
* logsPath: './logs',
|
|
57
|
+
* silent: false
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* const result = await context.toArtifacts({
|
|
61
|
+
* documentObject: openApiDoc,
|
|
62
|
+
* settings: clientSettings,
|
|
63
|
+
* toGeneratorConfigMap: () => generators,
|
|
64
|
+
* prettier: prettierConfig,
|
|
65
|
+
* silent: false
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Using individual phases
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const context = new CoreContext({
|
|
72
|
+
* spanId: 'custom-pipeline',
|
|
73
|
+
* silent: true
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Parse phase only
|
|
77
|
+
* const { oasDocument } = context.parse(openApiDoc);
|
|
78
|
+
*
|
|
79
|
+
* // Then use document for custom processing
|
|
80
|
+
* console.log('Parsed schemas:', Object.keys(oasDocument.components.schemas));
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
37
83
|
export declare class CoreContext {
|
|
38
84
|
#private;
|
|
85
|
+
/** Logger instance for the context */
|
|
39
86
|
logger: log.Logger;
|
|
87
|
+
/** Whether to suppress console output */
|
|
40
88
|
silent: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new CoreContext instance.
|
|
91
|
+
*
|
|
92
|
+
* @param args - Configuration for the context
|
|
93
|
+
* @param args.spanId - Unique identifier for this transformation span
|
|
94
|
+
* @param args.logsPath - Optional directory path for log files
|
|
95
|
+
* @param args.silent - Whether to suppress console output
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // Basic context with console logging
|
|
100
|
+
* const context = new CoreContext({
|
|
101
|
+
* spanId: 'my-generation',
|
|
102
|
+
* silent: false
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* // Context with file logging
|
|
106
|
+
* const context = new CoreContext({
|
|
107
|
+
* spanId: 'batch-job-123',
|
|
108
|
+
* logsPath: './logs/generation',
|
|
109
|
+
* silent: true
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
41
113
|
constructor({ spanId, logsPath, silent }: CoreContextArgs);
|
|
114
|
+
/**
|
|
115
|
+
* Parses an OpenAPI v3 document into internal OAS objects.
|
|
116
|
+
*
|
|
117
|
+
* This method executes only the parse phase of the pipeline, converting
|
|
118
|
+
* the raw OpenAPI JSON into structured OAS objects that can be used for
|
|
119
|
+
* generation or custom processing.
|
|
120
|
+
*
|
|
121
|
+
* @param documentObject - The OpenAPI v3 document to parse
|
|
122
|
+
* @returns An object containing the parsed OAS document
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { CoreContext } from '@skmtc/core';
|
|
127
|
+
*
|
|
128
|
+
* const context = new CoreContext({
|
|
129
|
+
* spanId: 'parse-only',
|
|
130
|
+
* silent: true
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* const { oasDocument } = context.parse(openApiDoc);
|
|
134
|
+
*
|
|
135
|
+
* // Access parsed components
|
|
136
|
+
* console.log('Models:', Object.keys(oasDocument.components.schemas));
|
|
137
|
+
* console.log('Paths:', Object.keys(oasDocument.paths));
|
|
138
|
+
*
|
|
139
|
+
* // Use for custom processing
|
|
140
|
+
* const userModel = oasDocument.components.schemas['User'];
|
|
141
|
+
* if (userModel && !userModel.isRef()) {
|
|
142
|
+
* console.log('User properties:', Object.keys(userModel.properties));
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
42
146
|
parse(documentObject: OpenAPIV3.Document): {
|
|
43
147
|
oasDocument: OasDocument;
|
|
44
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Executes the complete transformation pipeline to generate code artifacts.
|
|
151
|
+
*
|
|
152
|
+
* This method orchestrates all three phases:
|
|
153
|
+
* 1. **Parse**: Convert OpenAPI document to OAS objects
|
|
154
|
+
* 2. **Generate**: Transform OAS objects using generators
|
|
155
|
+
* 3. **Render**: Format and prepare final artifacts
|
|
156
|
+
*
|
|
157
|
+
* The result includes both the generated code files and comprehensive metadata
|
|
158
|
+
* about the generation process, including file mappings, previews, and results.
|
|
159
|
+
*
|
|
160
|
+
* @param args - Configuration for the artifact generation
|
|
161
|
+
* @param args.documentObject - The OpenAPI v3 document to process
|
|
162
|
+
* @param args.settings - Client settings for customization
|
|
163
|
+
* @param args.toGeneratorConfigMap - Function returning generator configuration
|
|
164
|
+
* @param args.prettier - Optional Prettier configuration for code formatting
|
|
165
|
+
* @param args.silent - Whether to suppress console output during generation
|
|
166
|
+
* @returns Promise resolving to rendered artifacts and metadata
|
|
167
|
+
*
|
|
168
|
+
* @example Complete pipeline
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const context = new CoreContext({
|
|
171
|
+
* spanId: 'api-client-gen',
|
|
172
|
+
* silent: false
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* const result = await context.toArtifacts({
|
|
176
|
+
* documentObject: openApiDoc,
|
|
177
|
+
* settings: {
|
|
178
|
+
* basePath: './src/api',
|
|
179
|
+
* skip: {
|
|
180
|
+
* models: ['Internal*'],
|
|
181
|
+
* operations: {
|
|
182
|
+
* '/health': ['get'],
|
|
183
|
+
* '/debug/**': ['*']
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* },
|
|
187
|
+
* toGeneratorConfigMap: () => ({
|
|
188
|
+
* models: {
|
|
189
|
+
* generator: MyModelGenerator,
|
|
190
|
+
* settings: { includeValidation: true }
|
|
191
|
+
* },
|
|
192
|
+
* operations: {
|
|
193
|
+
* generator: MyOperationGenerator,
|
|
194
|
+
* settings: { generateTypes: true }
|
|
195
|
+
* }
|
|
196
|
+
* }),
|
|
197
|
+
* prettier: {
|
|
198
|
+
* semi: false,
|
|
199
|
+
* singleQuote: true,
|
|
200
|
+
* trailingComma: 'all'
|
|
201
|
+
* },
|
|
202
|
+
* silent: false
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* // Access generated artifacts
|
|
206
|
+
* console.log('Generated files:', Object.keys(result.artifacts));
|
|
207
|
+
*
|
|
208
|
+
* // Write to filesystem
|
|
209
|
+
* for (const [path, content] of Object.entries(result.artifacts)) {
|
|
210
|
+
* await Deno.writeTextFile(path, content);
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* // Access metadata
|
|
214
|
+
* console.log('Generation results:', result.results);
|
|
215
|
+
* console.log('File mappings:', result.files);
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @throws Will throw an error if any phase of the pipeline fails
|
|
219
|
+
*/
|
|
45
220
|
toArtifacts({ documentObject, settings, toGeneratorConfigMap, prettier }: ToArtifactsArgs): Promise<RenderResult>;
|
|
46
221
|
trace<T>(token: string | string[], fn: () => T): T;
|
|
47
222
|
captureCurrentResult(result: ResultType): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreContext.d.ts","sourceRoot":"","sources":["../../src/context/CoreContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,GAAG,MAAM,yCAAyC,CAAA;AAQ9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAEvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,eAAe,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,aAAa,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,aAAa,GAAG,WAAW,CAAA;AAQrE,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;C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;IA2DvH,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAkClD,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAkB/C;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,GAAG,CAAC,SAAS,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAQnF"}
|
|
@@ -20,18 +20,93 @@ import { tracer } from '../helpers/tracer.js';
|
|
|
20
20
|
import { ResultsLog } from '../helpers/ResultsLog.js';
|
|
21
21
|
import * as Sentry from '@sentry/node';
|
|
22
22
|
import { join } from '../deps/jsr.io/@std/path/1.1.2/join.js';
|
|
23
|
+
/**
|
|
24
|
+
* The main orchestration class for the SKMTC transformation pipeline.
|
|
25
|
+
*
|
|
26
|
+
* `CoreContext` manages the three-phase process of transforming OpenAPI v3 documents
|
|
27
|
+
* into code artifacts. It coordinates parsing, generation, and rendering phases while
|
|
28
|
+
* providing logging, tracing, and error handling capabilities.
|
|
29
|
+
*
|
|
30
|
+
* ## Pipeline Phases
|
|
31
|
+
*
|
|
32
|
+
* 1. **Parse Phase**: Uses {@link ParseContext} to convert OpenAPI JSON into OAS objects
|
|
33
|
+
* 2. **Generate Phase**: Uses {@link GenerateContext} to transform OAS objects with generators
|
|
34
|
+
* 3. **Render Phase**: Uses {@link RenderContext} to format and prepare final artifacts
|
|
35
|
+
*
|
|
36
|
+
* @example Basic usage
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { CoreContext } from '@skmtc/core';
|
|
39
|
+
*
|
|
40
|
+
* const context = new CoreContext({
|
|
41
|
+
* spanId: 'user-api-generation',
|
|
42
|
+
* logsPath: './logs',
|
|
43
|
+
* silent: false
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* const result = await context.toArtifacts({
|
|
47
|
+
* documentObject: openApiDoc,
|
|
48
|
+
* settings: clientSettings,
|
|
49
|
+
* toGeneratorConfigMap: () => generators,
|
|
50
|
+
* prettier: prettierConfig,
|
|
51
|
+
* silent: false
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example Using individual phases
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const context = new CoreContext({
|
|
58
|
+
* spanId: 'custom-pipeline',
|
|
59
|
+
* silent: true
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Parse phase only
|
|
63
|
+
* const { oasDocument } = context.parse(openApiDoc);
|
|
64
|
+
*
|
|
65
|
+
* // Then use document for custom processing
|
|
66
|
+
* console.log('Parsed schemas:', Object.keys(oasDocument.components.schemas));
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
23
69
|
export class CoreContext {
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new CoreContext instance.
|
|
72
|
+
*
|
|
73
|
+
* @param args - Configuration for the context
|
|
74
|
+
* @param args.spanId - Unique identifier for this transformation span
|
|
75
|
+
* @param args.logsPath - Optional directory path for log files
|
|
76
|
+
* @param args.silent - Whether to suppress console output
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Basic context with console logging
|
|
81
|
+
* const context = new CoreContext({
|
|
82
|
+
* spanId: 'my-generation',
|
|
83
|
+
* silent: false
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* // Context with file logging
|
|
87
|
+
* const context = new CoreContext({
|
|
88
|
+
* spanId: 'batch-job-123',
|
|
89
|
+
* logsPath: './logs/generation',
|
|
90
|
+
* silent: true
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
24
94
|
constructor({ spanId, logsPath, silent }) {
|
|
25
95
|
_CoreContext_instances.add(this);
|
|
96
|
+
/** Logger instance for the context */
|
|
26
97
|
Object.defineProperty(this, "logger", {
|
|
27
98
|
enumerable: true,
|
|
28
99
|
configurable: true,
|
|
29
100
|
writable: true,
|
|
30
101
|
value: void 0
|
|
31
102
|
});
|
|
103
|
+
/** Current execution phase for pipeline tracking */
|
|
32
104
|
_CoreContext_phase.set(this, void 0);
|
|
105
|
+
/** Results log for tracking generation outcomes */
|
|
33
106
|
_CoreContext_results.set(this, void 0);
|
|
107
|
+
/** Stack trail for distributed tracing */
|
|
34
108
|
_CoreContext_stackTrail.set(this, void 0);
|
|
109
|
+
/** Whether to suppress console output */
|
|
35
110
|
Object.defineProperty(this, "silent", {
|
|
36
111
|
enumerable: true,
|
|
37
112
|
configurable: true,
|
|
@@ -43,6 +118,38 @@ export class CoreContext {
|
|
|
43
118
|
this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, { spanId, logsPath });
|
|
44
119
|
this.silent = silent;
|
|
45
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Parses an OpenAPI v3 document into internal OAS objects.
|
|
123
|
+
*
|
|
124
|
+
* This method executes only the parse phase of the pipeline, converting
|
|
125
|
+
* the raw OpenAPI JSON into structured OAS objects that can be used for
|
|
126
|
+
* generation or custom processing.
|
|
127
|
+
*
|
|
128
|
+
* @param documentObject - The OpenAPI v3 document to parse
|
|
129
|
+
* @returns An object containing the parsed OAS document
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* import { CoreContext } from '@skmtc/core';
|
|
134
|
+
*
|
|
135
|
+
* const context = new CoreContext({
|
|
136
|
+
* spanId: 'parse-only',
|
|
137
|
+
* silent: true
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* const { oasDocument } = context.parse(openApiDoc);
|
|
141
|
+
*
|
|
142
|
+
* // Access parsed components
|
|
143
|
+
* console.log('Models:', Object.keys(oasDocument.components.schemas));
|
|
144
|
+
* console.log('Paths:', Object.keys(oasDocument.paths));
|
|
145
|
+
*
|
|
146
|
+
* // Use for custom processing
|
|
147
|
+
* const userModel = oasDocument.components.schemas['User'];
|
|
148
|
+
* if (userModel && !userModel.isRef()) {
|
|
149
|
+
* console.log('User properties:', Object.keys(userModel.properties));
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
46
153
|
parse(documentObject) {
|
|
47
154
|
__classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, documentObject), "f");
|
|
48
155
|
const oasDocument = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse();
|
|
@@ -50,6 +157,77 @@ export class CoreContext {
|
|
|
50
157
|
oasDocument
|
|
51
158
|
};
|
|
52
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Executes the complete transformation pipeline to generate code artifacts.
|
|
162
|
+
*
|
|
163
|
+
* This method orchestrates all three phases:
|
|
164
|
+
* 1. **Parse**: Convert OpenAPI document to OAS objects
|
|
165
|
+
* 2. **Generate**: Transform OAS objects using generators
|
|
166
|
+
* 3. **Render**: Format and prepare final artifacts
|
|
167
|
+
*
|
|
168
|
+
* The result includes both the generated code files and comprehensive metadata
|
|
169
|
+
* about the generation process, including file mappings, previews, and results.
|
|
170
|
+
*
|
|
171
|
+
* @param args - Configuration for the artifact generation
|
|
172
|
+
* @param args.documentObject - The OpenAPI v3 document to process
|
|
173
|
+
* @param args.settings - Client settings for customization
|
|
174
|
+
* @param args.toGeneratorConfigMap - Function returning generator configuration
|
|
175
|
+
* @param args.prettier - Optional Prettier configuration for code formatting
|
|
176
|
+
* @param args.silent - Whether to suppress console output during generation
|
|
177
|
+
* @returns Promise resolving to rendered artifacts and metadata
|
|
178
|
+
*
|
|
179
|
+
* @example Complete pipeline
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const context = new CoreContext({
|
|
182
|
+
* spanId: 'api-client-gen',
|
|
183
|
+
* silent: false
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* const result = await context.toArtifacts({
|
|
187
|
+
* documentObject: openApiDoc,
|
|
188
|
+
* settings: {
|
|
189
|
+
* basePath: './src/api',
|
|
190
|
+
* skip: {
|
|
191
|
+
* models: ['Internal*'],
|
|
192
|
+
* operations: {
|
|
193
|
+
* '/health': ['get'],
|
|
194
|
+
* '/debug/**': ['*']
|
|
195
|
+
* }
|
|
196
|
+
* }
|
|
197
|
+
* },
|
|
198
|
+
* toGeneratorConfigMap: () => ({
|
|
199
|
+
* models: {
|
|
200
|
+
* generator: MyModelGenerator,
|
|
201
|
+
* settings: { includeValidation: true }
|
|
202
|
+
* },
|
|
203
|
+
* operations: {
|
|
204
|
+
* generator: MyOperationGenerator,
|
|
205
|
+
* settings: { generateTypes: true }
|
|
206
|
+
* }
|
|
207
|
+
* }),
|
|
208
|
+
* prettier: {
|
|
209
|
+
* semi: false,
|
|
210
|
+
* singleQuote: true,
|
|
211
|
+
* trailingComma: 'all'
|
|
212
|
+
* },
|
|
213
|
+
* silent: false
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* // Access generated artifacts
|
|
217
|
+
* console.log('Generated files:', Object.keys(result.artifacts));
|
|
218
|
+
*
|
|
219
|
+
* // Write to filesystem
|
|
220
|
+
* for (const [path, content] of Object.entries(result.artifacts)) {
|
|
221
|
+
* await Deno.writeTextFile(path, content);
|
|
222
|
+
* }
|
|
223
|
+
*
|
|
224
|
+
* // Access metadata
|
|
225
|
+
* console.log('Generation results:', result.results);
|
|
226
|
+
* console.log('File mappings:', result.files);
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @throws Will throw an error if any phase of the pipeline fails
|
|
230
|
+
*/
|
|
53
231
|
async toArtifacts({ documentObject, settings, toGeneratorConfigMap, prettier }) {
|
|
54
232
|
try {
|
|
55
233
|
const oasDocument = this.trace('parse', () => {
|
package/esm/dsl/ContentBase.d.ts
CHANGED
|
@@ -1,15 +1,130 @@
|
|
|
1
1
|
import type { GenerateContext } from '../context/GenerateContext.js';
|
|
2
2
|
import type { RegisterArgs } from '../context/GenerateContext.js';
|
|
3
3
|
import type { GeneratorKey } from '../types/GeneratorKeys.js';
|
|
4
|
+
/**
|
|
5
|
+
* Constructor arguments for {@link ContentBase}.
|
|
6
|
+
*/
|
|
4
7
|
type ContentBaseArgs = {
|
|
8
|
+
/** The generation context providing OAS objects and utilities */
|
|
5
9
|
context: GenerateContext;
|
|
10
|
+
/** Optional generator key for tracking and identification */
|
|
6
11
|
generatorKey?: GeneratorKey;
|
|
7
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Base class for all content generators in the SKMTC DSL system.
|
|
15
|
+
*
|
|
16
|
+
* `ContentBase` provides the foundation for creating custom generators that transform
|
|
17
|
+
* OpenAPI Schema (OAS) objects into code artifacts. It handles registration with the
|
|
18
|
+
* generation context, skipping logic, and provides access to the pipeline's utilities.
|
|
19
|
+
*
|
|
20
|
+
* ## Generator Lifecycle
|
|
21
|
+
*
|
|
22
|
+
* 1. **Construction**: Initialize with context and optional generator key
|
|
23
|
+
* 2. **Registration**: Call {@link register} to add artifacts to the pipeline
|
|
24
|
+
* 3. **Generation**: Implement custom logic using context utilities
|
|
25
|
+
* 4. **Rendering**: Artifacts are automatically rendered by the pipeline
|
|
26
|
+
*
|
|
27
|
+
* @example Basic generator
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { ContentBase } from '@skmtc/core';
|
|
30
|
+
*
|
|
31
|
+
* class MyModelGenerator extends ContentBase {
|
|
32
|
+
* generate() {
|
|
33
|
+
* // Skip if not needed
|
|
34
|
+
* if (this.shouldSkip()) return;
|
|
35
|
+
*
|
|
36
|
+
* // Access OAS objects through context
|
|
37
|
+
* const schemas = this.context.oasDocument.components.schemas;
|
|
38
|
+
*
|
|
39
|
+
* for (const [name, schema] of Object.entries(schemas)) {
|
|
40
|
+
* if (schema.isRef()) continue;
|
|
41
|
+
*
|
|
42
|
+
* const file = new File({
|
|
43
|
+
* context: this.context,
|
|
44
|
+
* path: `./models/${name}.ts`,
|
|
45
|
+
* content: this.generateModelContent(schema)
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Register the file for rendering
|
|
49
|
+
* this.register({ file });
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* private generateModelContent(schema: OasObject): string {
|
|
54
|
+
* // Custom model generation logic
|
|
55
|
+
* return `export interface ${schema.name} { ... }`;
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Generator with skipping logic
|
|
61
|
+
* ```typescript
|
|
62
|
+
* class ConditionalGenerator extends ContentBase {
|
|
63
|
+
* generate() {
|
|
64
|
+
* // Check if generation should be skipped
|
|
65
|
+
* if (this.shouldSkipBasedOnSettings()) {
|
|
66
|
+
* this.skip('Disabled in settings');
|
|
67
|
+
* return;
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
* // Continue with generation...
|
|
71
|
+
* const file = this.createOutputFile();
|
|
72
|
+
* this.register({ file });
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* private shouldSkipBasedOnSettings(): boolean {
|
|
76
|
+
* return this.context.settings?.skip?.models?.includes('MyModel') ?? false;
|
|
77
|
+
* }
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
8
81
|
export declare class ContentBase {
|
|
82
|
+
/** The generation context providing access to OAS objects and utilities */
|
|
9
83
|
context: GenerateContext;
|
|
84
|
+
/** Whether this generator has been skipped */
|
|
10
85
|
skipped: boolean;
|
|
86
|
+
/** Optional generator key for identification and tracking */
|
|
11
87
|
generatorKey: GeneratorKey | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a new ContentBase instance.
|
|
90
|
+
*
|
|
91
|
+
* @param args - Construction arguments
|
|
92
|
+
* @param args.context - The generation context
|
|
93
|
+
* @param args.generatorKey - Optional generator key
|
|
94
|
+
*/
|
|
12
95
|
constructor({ context, generatorKey }: ContentBaseArgs);
|
|
96
|
+
/**
|
|
97
|
+
* Registers generated artifacts with the rendering pipeline.
|
|
98
|
+
*
|
|
99
|
+
* This method is called by generator implementations to add files,
|
|
100
|
+
* JSON artifacts, or other content to the generation output.
|
|
101
|
+
*
|
|
102
|
+
* @param args - The artifacts to register
|
|
103
|
+
* @param args.file - Optional file to register
|
|
104
|
+
* @param args.jsonFile - Optional JSON file to register
|
|
105
|
+
*
|
|
106
|
+
* @example Registering a file
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const file = new File({
|
|
109
|
+
* context: this.context,
|
|
110
|
+
* path: './output.ts',
|
|
111
|
+
* content: 'export const value = 42;'
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* this.register({ file });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example Registering JSON data
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const jsonFile = new JsonFile({
|
|
120
|
+
* context: this.context,
|
|
121
|
+
* path: './config.json',
|
|
122
|
+
* data: { version: '1.0.0', features: ['api'] }
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* this.register({ jsonFile });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
13
128
|
register(args: RegisterArgs): void;
|
|
14
129
|
}
|
|
15
130
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED,qBAAa,WAAW;IACtB,OAAO,EAAE,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"ContentBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,iEAAiE;IACjE,OAAO,EAAE,eAAe,CAAA;IACxB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,qBAAa,WAAW;IACtB,2EAA2E;IAC3E,OAAO,EAAE,eAAe,CAAA;IAExB,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAQ;IAExB,6DAA6D;IAC7D,YAAY,EAAE,YAAY,GAAG,SAAS,CAAA;IAEtC;;;;;;OAMG;gBACS,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,eAAe;IAKtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;CAGnC"}
|
package/esm/dsl/ContentBase.js
CHANGED
|
@@ -1,17 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all content generators in the SKMTC DSL system.
|
|
3
|
+
*
|
|
4
|
+
* `ContentBase` provides the foundation for creating custom generators that transform
|
|
5
|
+
* OpenAPI Schema (OAS) objects into code artifacts. It handles registration with the
|
|
6
|
+
* generation context, skipping logic, and provides access to the pipeline's utilities.
|
|
7
|
+
*
|
|
8
|
+
* ## Generator Lifecycle
|
|
9
|
+
*
|
|
10
|
+
* 1. **Construction**: Initialize with context and optional generator key
|
|
11
|
+
* 2. **Registration**: Call {@link register} to add artifacts to the pipeline
|
|
12
|
+
* 3. **Generation**: Implement custom logic using context utilities
|
|
13
|
+
* 4. **Rendering**: Artifacts are automatically rendered by the pipeline
|
|
14
|
+
*
|
|
15
|
+
* @example Basic generator
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { ContentBase } from '@skmtc/core';
|
|
18
|
+
*
|
|
19
|
+
* class MyModelGenerator extends ContentBase {
|
|
20
|
+
* generate() {
|
|
21
|
+
* // Skip if not needed
|
|
22
|
+
* if (this.shouldSkip()) return;
|
|
23
|
+
*
|
|
24
|
+
* // Access OAS objects through context
|
|
25
|
+
* const schemas = this.context.oasDocument.components.schemas;
|
|
26
|
+
*
|
|
27
|
+
* for (const [name, schema] of Object.entries(schemas)) {
|
|
28
|
+
* if (schema.isRef()) continue;
|
|
29
|
+
*
|
|
30
|
+
* const file = new File({
|
|
31
|
+
* context: this.context,
|
|
32
|
+
* path: `./models/${name}.ts`,
|
|
33
|
+
* content: this.generateModelContent(schema)
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Register the file for rendering
|
|
37
|
+
* this.register({ file });
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* private generateModelContent(schema: OasObject): string {
|
|
42
|
+
* // Custom model generation logic
|
|
43
|
+
* return `export interface ${schema.name} { ... }`;
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Generator with skipping logic
|
|
49
|
+
* ```typescript
|
|
50
|
+
* class ConditionalGenerator extends ContentBase {
|
|
51
|
+
* generate() {
|
|
52
|
+
* // Check if generation should be skipped
|
|
53
|
+
* if (this.shouldSkipBasedOnSettings()) {
|
|
54
|
+
* this.skip('Disabled in settings');
|
|
55
|
+
* return;
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Continue with generation...
|
|
59
|
+
* const file = this.createOutputFile();
|
|
60
|
+
* this.register({ file });
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* private shouldSkipBasedOnSettings(): boolean {
|
|
64
|
+
* return this.context.settings?.skip?.models?.includes('MyModel') ?? false;
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
1
69
|
export class ContentBase {
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new ContentBase instance.
|
|
72
|
+
*
|
|
73
|
+
* @param args - Construction arguments
|
|
74
|
+
* @param args.context - The generation context
|
|
75
|
+
* @param args.generatorKey - Optional generator key
|
|
76
|
+
*/
|
|
2
77
|
constructor({ context, generatorKey }) {
|
|
78
|
+
/** The generation context providing access to OAS objects and utilities */
|
|
3
79
|
Object.defineProperty(this, "context", {
|
|
4
80
|
enumerable: true,
|
|
5
81
|
configurable: true,
|
|
6
82
|
writable: true,
|
|
7
83
|
value: void 0
|
|
8
84
|
});
|
|
85
|
+
/** Whether this generator has been skipped */
|
|
9
86
|
Object.defineProperty(this, "skipped", {
|
|
10
87
|
enumerable: true,
|
|
11
88
|
configurable: true,
|
|
12
89
|
writable: true,
|
|
13
90
|
value: false
|
|
14
91
|
});
|
|
92
|
+
/** Optional generator key for identification and tracking */
|
|
15
93
|
Object.defineProperty(this, "generatorKey", {
|
|
16
94
|
enumerable: true,
|
|
17
95
|
configurable: true,
|
|
@@ -21,6 +99,38 @@ export class ContentBase {
|
|
|
21
99
|
this.context = context;
|
|
22
100
|
this.generatorKey = generatorKey;
|
|
23
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Registers generated artifacts with the rendering pipeline.
|
|
104
|
+
*
|
|
105
|
+
* This method is called by generator implementations to add files,
|
|
106
|
+
* JSON artifacts, or other content to the generation output.
|
|
107
|
+
*
|
|
108
|
+
* @param args - The artifacts to register
|
|
109
|
+
* @param args.file - Optional file to register
|
|
110
|
+
* @param args.jsonFile - Optional JSON file to register
|
|
111
|
+
*
|
|
112
|
+
* @example Registering a file
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const file = new File({
|
|
115
|
+
* context: this.context,
|
|
116
|
+
* path: './output.ts',
|
|
117
|
+
* content: 'export const value = 42;'
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* this.register({ file });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example Registering JSON data
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const jsonFile = new JsonFile({
|
|
126
|
+
* context: this.context,
|
|
127
|
+
* path: './config.json',
|
|
128
|
+
* data: { version: '1.0.0', features: ['api'] }
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* this.register({ jsonFile });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
24
134
|
register(args) {
|
|
25
135
|
this.context.register(args);
|
|
26
136
|
}
|