@skmtc/core 0.0.782 → 0.0.785

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/esm/context/CoreContext.d.ts +175 -0
  2. package/esm/context/CoreContext.d.ts.map +1 -1
  3. package/esm/context/CoreContext.js +178 -0
  4. package/esm/dsl/ContentBase.d.ts +115 -0
  5. package/esm/dsl/ContentBase.d.ts.map +1 -1
  6. package/esm/dsl/ContentBase.js +110 -0
  7. package/esm/dsl/File.d.ts +208 -0
  8. package/esm/dsl/File.d.ts.map +1 -1
  9. package/esm/dsl/File.js +197 -0
  10. package/esm/dsl/model/ModelBase.d.ts +257 -0
  11. package/esm/dsl/model/ModelBase.d.ts.map +1 -1
  12. package/esm/dsl/model/ModelBase.js +248 -0
  13. package/esm/dsl/operation/OperationBase.d.ts +175 -0
  14. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  15. package/esm/dsl/operation/OperationBase.js +166 -0
  16. package/esm/helpers/strings.d.ts +63 -0
  17. package/esm/helpers/strings.d.ts.map +1 -1
  18. package/esm/helpers/strings.js +59 -0
  19. package/esm/mod.d.ts +66 -0
  20. package/esm/mod.d.ts.map +1 -1
  21. package/esm/mod.js +66 -0
  22. package/esm/run/toArtifacts.d.ts +114 -0
  23. package/esm/run/toArtifacts.d.ts.map +1 -1
  24. package/esm/run/toArtifacts.js +86 -0
  25. package/esm/types/Settings.d.ts +129 -0
  26. package/esm/types/Settings.d.ts.map +1 -1
  27. package/esm/types/Settings.js +3 -0
  28. package/esm/typescript/List.d.ts +111 -0
  29. package/esm/typescript/List.d.ts.map +1 -1
  30. package/esm/typescript/List.js +106 -0
  31. package/package.json +5 -1
  32. package/script/context/CoreContext.d.ts +175 -0
  33. package/script/context/CoreContext.d.ts.map +1 -1
  34. package/script/context/CoreContext.js +178 -0
  35. package/script/dsl/ContentBase.d.ts +115 -0
  36. package/script/dsl/ContentBase.d.ts.map +1 -1
  37. package/script/dsl/ContentBase.js +110 -0
  38. package/script/dsl/File.d.ts +208 -0
  39. package/script/dsl/File.d.ts.map +1 -1
  40. package/script/dsl/File.js +197 -0
  41. package/script/dsl/model/ModelBase.d.ts +257 -0
  42. package/script/dsl/model/ModelBase.d.ts.map +1 -1
  43. package/script/dsl/model/ModelBase.js +248 -0
  44. package/script/dsl/operation/OperationBase.d.ts +175 -0
  45. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  46. package/script/dsl/operation/OperationBase.js +166 -0
  47. package/script/helpers/strings.d.ts +63 -0
  48. package/script/helpers/strings.d.ts.map +1 -1
  49. package/script/helpers/strings.js +59 -0
  50. package/script/mod.d.ts +66 -0
  51. package/script/mod.d.ts.map +1 -1
  52. package/script/mod.js +66 -0
  53. package/script/run/toArtifacts.d.ts +114 -0
  54. package/script/run/toArtifacts.d.ts.map +1 -1
  55. package/script/run/toArtifacts.js +86 -0
  56. package/script/types/Settings.d.ts +129 -0
  57. package/script/types/Settings.d.ts.map +1 -1
  58. package/script/types/Settings.js +3 -0
  59. package/script/typescript/List.d.ts +111 -0
  60. package/script/typescript/List.d.ts.map +1 -1
  61. package/script/typescript/List.js +106 -0
@@ -1,24 +1,130 @@
1
1
  import { match } from 'ts-pattern';
2
+ /**
3
+ * A powerful utility class for building formatted lists of stringable items.
4
+ *
5
+ * The `List` class is a core component of the SKMTC DSL system, providing type-safe
6
+ * construction of formatted lists with customizable separators and bookends. It's
7
+ * extensively used throughout the codebase for generating code constructs like
8
+ * function parameters, object properties, array literals, and more.
9
+ *
10
+ * ## Type Safety
11
+ *
12
+ * The class uses TypeScript's generic system to provide compile-time guarantees
13
+ * about the list structure, separator, and bookend styles. This enables rich
14
+ * type inference and helps prevent formatting errors.
15
+ *
16
+ * ## Common Patterns
17
+ *
18
+ * - **Objects**: `List.toObject()` creates `{key: value, ...}` structures
19
+ * - **Arrays**: `List.toArray()` creates `[item, item, ...]` structures
20
+ * - **Parameters**: `List.toParams()` creates `(param, param, ...)` structures
21
+ * - **Lines**: `List.toLines()` creates newline-separated content
22
+ *
23
+ * @template Values - Array of stringable values
24
+ * @template Separator - String used to separate items
25
+ * @template Bookends - Style of bookends ('[]', '{}', '()', '<>', 'none')
26
+ *
27
+ * @example Basic usage
28
+ * ```typescript
29
+ * import { List } from '@skmtc/core';
30
+ *
31
+ * // Create a comma-separated list
32
+ * const items = new List(['apple', 'banana', 'cherry']);
33
+ * console.log(items.toString()); // "apple, banana, cherry"
34
+ *
35
+ * // Create an array-style list
36
+ * const array = new List(['a', 'b', 'c'], { bookends: '[]' });
37
+ * console.log(array.toString()); // "[a, b, c]"
38
+ *
39
+ * // Create an object-style list
40
+ * const obj = new List(['x: 1', 'y: 2'], { bookends: '{}' });
41
+ * console.log(obj.toString()); // "{x: 1, y: 2}"
42
+ * ```
43
+ *
44
+ * @example Using type aliases
45
+ * ```typescript
46
+ * // Type-safe array construction
47
+ * const params: ListParams<string> = List.toParams(['id', 'name', 'email']);
48
+ * console.log(params.toString()); // "(id, name, email)"
49
+ *
50
+ * // Object properties with filtering
51
+ * const props = List.toObject(['title', undefined, 'author'], { skipEmpty: true });
52
+ * console.log(props.toString()); // "{title, author}"
53
+ *
54
+ * // Line-separated content
55
+ * const lines = List.toLines(['import React from "react"', 'import { useState } from "react"']);
56
+ * console.log(lines.toString());
57
+ * // import React from "react"
58
+ * // import { useState } from "react"
59
+ * ```
60
+ *
61
+ * @example Advanced usage with builders
62
+ * ```typescript
63
+ * // Function signature generation
64
+ * const signature = List.toParams([
65
+ * 'id: string',
66
+ * 'options?: RequestOptions',
67
+ * 'callback?: (result: T) => void'
68
+ * ]);
69
+ *
70
+ * // Interface properties
71
+ * const interfaceProps = List.toObject([
72
+ * 'readonly id: string',
73
+ * 'name: string',
74
+ * 'createdAt: Date',
75
+ * 'updatedAt?: Date'
76
+ * ]);
77
+ *
78
+ * console.log(`interface User ${interfaceProps}`);
79
+ * // interface User {readonly id: string, name: string, createdAt: Date, updatedAt?: Date}
80
+ * ```
81
+ */
2
82
  export class List {
83
+ /**
84
+ * Creates a new List instance.
85
+ *
86
+ * @param values - Array of values (undefined values are automatically filtered out)
87
+ * @param options - Configuration options
88
+ * @param options.separator - String to use between items (default: ', ')
89
+ * @param options.bookends - Style of bookends to wrap the list (default: 'none')
90
+ * @param options.skipEmpty - Whether to return empty string for empty lists (default: false)
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * // Basic list with default comma separator
95
+ * const basic = new List(['a', 'b', 'c']);
96
+ *
97
+ * // Custom separator and bookends
98
+ * const custom = new List(['x', 'y', 'z'], {
99
+ * separator: ' | ',
100
+ * bookends: '[]',
101
+ * skipEmpty: true
102
+ * });
103
+ * ```
104
+ */
3
105
  constructor(values, { separator, bookends, skipEmpty } = {}) {
106
+ /** The array of values in this list */
4
107
  Object.defineProperty(this, "values", {
5
108
  enumerable: true,
6
109
  configurable: true,
7
110
  writable: true,
8
111
  value: void 0
9
112
  });
113
+ /** The separator string used between items */
10
114
  Object.defineProperty(this, "separator", {
11
115
  enumerable: true,
12
116
  configurable: true,
13
117
  writable: true,
14
118
  value: void 0
15
119
  });
120
+ /** The bookend style for wrapping the list */
16
121
  Object.defineProperty(this, "bookends", {
17
122
  enumerable: true,
18
123
  configurable: true,
19
124
  writable: true,
20
125
  value: void 0
21
126
  });
127
+ /** Whether to skip rendering when the list is empty */
22
128
  Object.defineProperty(this, "skipEmpty", {
23
129
  enumerable: true,
24
130
  configurable: true,
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.782",
3
+ "version": "0.0.785",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/skmtc/skmtc.git"
7
+ },
4
8
  "main": "./script/mod.js",
5
9
  "module": "./esm/mod.js",
6
10
  "exports": {
@@ -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,mBA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AE,QAAQ,EAAE,MAAM,EAAE,EAAE,eAAe;IAmDzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,QAAQ,GAAG;QAAE,WAAW,EAAE,WAAW,CAAA;KAAE;IAUvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsEG;IACG,WAAW,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,oBAAoB,EAAE,QAAQ,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC;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"}
@@ -57,18 +57,93 @@ const tracer_js_1 = require("../helpers/tracer.js");
57
57
  const ResultsLog_js_1 = require("../helpers/ResultsLog.js");
58
58
  const Sentry = __importStar(require("@sentry/node"));
59
59
  const join_js_1 = require("../deps/jsr.io/@std/path/1.1.2/join.js");
60
+ /**
61
+ * The main orchestration class for the SKMTC transformation pipeline.
62
+ *
63
+ * `CoreContext` manages the three-phase process of transforming OpenAPI v3 documents
64
+ * into code artifacts. It coordinates parsing, generation, and rendering phases while
65
+ * providing logging, tracing, and error handling capabilities.
66
+ *
67
+ * ## Pipeline Phases
68
+ *
69
+ * 1. **Parse Phase**: Uses {@link ParseContext} to convert OpenAPI JSON into OAS objects
70
+ * 2. **Generate Phase**: Uses {@link GenerateContext} to transform OAS objects with generators
71
+ * 3. **Render Phase**: Uses {@link RenderContext} to format and prepare final artifacts
72
+ *
73
+ * @example Basic usage
74
+ * ```typescript
75
+ * import { CoreContext } from '@skmtc/core';
76
+ *
77
+ * const context = new CoreContext({
78
+ * spanId: 'user-api-generation',
79
+ * logsPath: './logs',
80
+ * silent: false
81
+ * });
82
+ *
83
+ * const result = await context.toArtifacts({
84
+ * documentObject: openApiDoc,
85
+ * settings: clientSettings,
86
+ * toGeneratorConfigMap: () => generators,
87
+ * prettier: prettierConfig,
88
+ * silent: false
89
+ * });
90
+ * ```
91
+ *
92
+ * @example Using individual phases
93
+ * ```typescript
94
+ * const context = new CoreContext({
95
+ * spanId: 'custom-pipeline',
96
+ * silent: true
97
+ * });
98
+ *
99
+ * // Parse phase only
100
+ * const { oasDocument } = context.parse(openApiDoc);
101
+ *
102
+ * // Then use document for custom processing
103
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components.schemas));
104
+ * ```
105
+ */
60
106
  class CoreContext {
107
+ /**
108
+ * Creates a new CoreContext instance.
109
+ *
110
+ * @param args - Configuration for the context
111
+ * @param args.spanId - Unique identifier for this transformation span
112
+ * @param args.logsPath - Optional directory path for log files
113
+ * @param args.silent - Whether to suppress console output
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Basic context with console logging
118
+ * const context = new CoreContext({
119
+ * spanId: 'my-generation',
120
+ * silent: false
121
+ * });
122
+ *
123
+ * // Context with file logging
124
+ * const context = new CoreContext({
125
+ * spanId: 'batch-job-123',
126
+ * logsPath: './logs/generation',
127
+ * silent: true
128
+ * });
129
+ * ```
130
+ */
61
131
  constructor({ spanId, logsPath, silent }) {
62
132
  _CoreContext_instances.add(this);
133
+ /** Logger instance for the context */
63
134
  Object.defineProperty(this, "logger", {
64
135
  enumerable: true,
65
136
  configurable: true,
66
137
  writable: true,
67
138
  value: void 0
68
139
  });
140
+ /** Current execution phase for pipeline tracking */
69
141
  _CoreContext_phase.set(this, void 0);
142
+ /** Results log for tracking generation outcomes */
70
143
  _CoreContext_results.set(this, void 0);
144
+ /** Stack trail for distributed tracing */
71
145
  _CoreContext_stackTrail.set(this, void 0);
146
+ /** Whether to suppress console output */
72
147
  Object.defineProperty(this, "silent", {
73
148
  enumerable: true,
74
149
  configurable: true,
@@ -80,6 +155,38 @@ class CoreContext {
80
155
  this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, { spanId, logsPath });
81
156
  this.silent = silent;
82
157
  }
158
+ /**
159
+ * Parses an OpenAPI v3 document into internal OAS objects.
160
+ *
161
+ * This method executes only the parse phase of the pipeline, converting
162
+ * the raw OpenAPI JSON into structured OAS objects that can be used for
163
+ * generation or custom processing.
164
+ *
165
+ * @param documentObject - The OpenAPI v3 document to parse
166
+ * @returns An object containing the parsed OAS document
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { CoreContext } from '@skmtc/core';
171
+ *
172
+ * const context = new CoreContext({
173
+ * spanId: 'parse-only',
174
+ * silent: true
175
+ * });
176
+ *
177
+ * const { oasDocument } = context.parse(openApiDoc);
178
+ *
179
+ * // Access parsed components
180
+ * console.log('Models:', Object.keys(oasDocument.components.schemas));
181
+ * console.log('Paths:', Object.keys(oasDocument.paths));
182
+ *
183
+ * // Use for custom processing
184
+ * const userModel = oasDocument.components.schemas['User'];
185
+ * if (userModel && !userModel.isRef()) {
186
+ * console.log('User properties:', Object.keys(userModel.properties));
187
+ * }
188
+ * ```
189
+ */
83
190
  parse(documentObject) {
84
191
  __classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, documentObject), "f");
85
192
  const oasDocument = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse();
@@ -87,6 +194,77 @@ class CoreContext {
87
194
  oasDocument
88
195
  };
89
196
  }
197
+ /**
198
+ * Executes the complete transformation pipeline to generate code artifacts.
199
+ *
200
+ * This method orchestrates all three phases:
201
+ * 1. **Parse**: Convert OpenAPI document to OAS objects
202
+ * 2. **Generate**: Transform OAS objects using generators
203
+ * 3. **Render**: Format and prepare final artifacts
204
+ *
205
+ * The result includes both the generated code files and comprehensive metadata
206
+ * about the generation process, including file mappings, previews, and results.
207
+ *
208
+ * @param args - Configuration for the artifact generation
209
+ * @param args.documentObject - The OpenAPI v3 document to process
210
+ * @param args.settings - Client settings for customization
211
+ * @param args.toGeneratorConfigMap - Function returning generator configuration
212
+ * @param args.prettier - Optional Prettier configuration for code formatting
213
+ * @param args.silent - Whether to suppress console output during generation
214
+ * @returns Promise resolving to rendered artifacts and metadata
215
+ *
216
+ * @example Complete pipeline
217
+ * ```typescript
218
+ * const context = new CoreContext({
219
+ * spanId: 'api-client-gen',
220
+ * silent: false
221
+ * });
222
+ *
223
+ * const result = await context.toArtifacts({
224
+ * documentObject: openApiDoc,
225
+ * settings: {
226
+ * basePath: './src/api',
227
+ * skip: {
228
+ * models: ['Internal*'],
229
+ * operations: {
230
+ * '/health': ['get'],
231
+ * '/debug/**': ['*']
232
+ * }
233
+ * }
234
+ * },
235
+ * toGeneratorConfigMap: () => ({
236
+ * models: {
237
+ * generator: MyModelGenerator,
238
+ * settings: { includeValidation: true }
239
+ * },
240
+ * operations: {
241
+ * generator: MyOperationGenerator,
242
+ * settings: { generateTypes: true }
243
+ * }
244
+ * }),
245
+ * prettier: {
246
+ * semi: false,
247
+ * singleQuote: true,
248
+ * trailingComma: 'all'
249
+ * },
250
+ * silent: false
251
+ * });
252
+ *
253
+ * // Access generated artifacts
254
+ * console.log('Generated files:', Object.keys(result.artifacts));
255
+ *
256
+ * // Write to filesystem
257
+ * for (const [path, content] of Object.entries(result.artifacts)) {
258
+ * await Deno.writeTextFile(path, content);
259
+ * }
260
+ *
261
+ * // Access metadata
262
+ * console.log('Generation results:', result.results);
263
+ * console.log('File mappings:', result.files);
264
+ * ```
265
+ *
266
+ * @throws Will throw an error if any phase of the pipeline fails
267
+ */
90
268
  async toArtifacts({ documentObject, settings, toGeneratorConfigMap, prettier }) {
91
269
  try {
92
270
  const oasDocument = this.trace('parse', () => {
@@ -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;IACxB,OAAO,EAAE,OAAO,CAAQ;IACxB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAA;gBAE1B,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,eAAe;IAKtD,QAAQ,CAAC,IAAI,EAAE,YAAY;CAG5B"}
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,CA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