@skmtc/core 0.0.788 → 0.0.789

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.
@@ -5,62 +5,240 @@ import type * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
5
5
  import type { StackTrail } from './StackTrail.js';
6
6
  import * as v from 'valibot';
7
7
  import type { IssueType } from './types.js';
8
+ /**
9
+ * Constructor arguments for {@link ParseContext}.
10
+ */
8
11
  type ConstructorArgs = {
12
+ /** The OpenAPI v3 document to parse */
9
13
  documentObject: OpenAPIV3.Document;
14
+ /** Logger instance for debug information */
10
15
  logger: log.Logger;
16
+ /** Stack trail for distributed tracing */
11
17
  stackTrail: StackTrail;
18
+ /** Whether to suppress console output */
12
19
  silent: boolean;
13
20
  };
21
+ /**
22
+ * Return type for the parse operation.
23
+ */
14
24
  export type ParseReturn = {
25
+ /** The parsed OAS document */
15
26
  oasDocument: OasDocument;
27
+ /** Array of parsing issues encountered */
16
28
  issues: ParseIssue[];
17
29
  };
30
+ /**
31
+ * Base type for parse warning messages.
32
+ */
18
33
  type ParseWarningBase = {
34
+ /** Issue severity level */
19
35
  level: 'warning';
36
+ /** Warning message */
20
37
  message: string;
21
38
  };
39
+ /**
40
+ * Base type for parse error messages.
41
+ */
22
42
  type ParseErrorBase = {
43
+ /** Issue severity level */
23
44
  level: 'error';
45
+ /** The error that occurred */
24
46
  error: Error;
25
47
  };
48
+ /**
49
+ * Base union type for parse issues.
50
+ */
26
51
  type ParseIssueBase = ParseErrorBase | ParseWarningBase;
52
+ /**
53
+ * Arguments for logging issues with a specific key.
54
+ */
27
55
  export type LogIssueArgs = ParseIssueBase & {
56
+ /** The key where the issue occurred */
28
57
  key: string;
58
+ /** The parent object containing the issue */
29
59
  parent: unknown;
60
+ /** The type of issue for categorization */
30
61
  type: IssueType;
31
62
  };
63
+ /**
64
+ * Arguments for logging issues without a specific key.
65
+ */
32
66
  export type LogIssueNoKeyArgs = ParseIssueBase & {
67
+ /** The parent object containing the issue */
33
68
  parent: unknown;
69
+ /** The type of issue for categorization */
34
70
  type: IssueType;
35
71
  };
72
+ /**
73
+ * Arguments for provisional parsing with validation.
74
+ */
36
75
  export type ProvisionalParseArgs<T> = {
76
+ /** The key being parsed */
37
77
  key: string;
78
+ /** The value to validate */
38
79
  value: unknown;
80
+ /** The parent object context */
39
81
  parent: unknown;
82
+ /** Valibot schema for validation */
40
83
  schema: v.GenericSchema<T>;
84
+ /** Function to generate error messages */
41
85
  toMessage: (value: unknown) => string;
86
+ /** The type of issue for categorization */
42
87
  type: IssueType;
43
88
  };
89
+ /**
90
+ * Arguments for logging skipped values during parsing.
91
+ */
44
92
  export type LogSkippedValuesArgs = {
93
+ /** Record of skipped key-value pairs */
45
94
  skipped: Record<string, unknown>;
95
+ /** The parent object context */
46
96
  parent: unknown;
97
+ /** String description of the parent type */
47
98
  parentType: string;
48
99
  };
100
+ /**
101
+ * Represents a parsing error with location context.
102
+ */
49
103
  export type ParseError = {
104
+ /** Error severity level */
50
105
  level: 'error';
106
+ /** The error that occurred */
51
107
  error: Error;
108
+ /** Location string where the error occurred */
52
109
  location: string;
110
+ /** The parent object context */
53
111
  parent: unknown;
112
+ /** The type of issue for categorization */
54
113
  type: IssueType;
55
114
  };
115
+ /**
116
+ * Represents a parsing warning with location context.
117
+ */
56
118
  export type ParseWarning = {
119
+ /** Warning severity level */
57
120
  level: 'warning';
121
+ /** Warning message */
58
122
  message: string;
123
+ /** Location string where the warning occurred */
59
124
  location: string;
125
+ /** The parent object context */
60
126
  parent: unknown;
127
+ /** The type of issue for categorization */
61
128
  type: IssueType;
62
129
  };
130
+ /**
131
+ * Union type for all parsing issues.
132
+ */
63
133
  export type ParseIssue = ParseError | ParseWarning;
134
+ /**
135
+ * The parsing context for the first phase of the SKMTC transformation pipeline.
136
+ *
137
+ * `ParseContext` is responsible for converting OpenAPI v3 JSON documents into
138
+ * the internal OAS (OpenAPI Schema) object representation used by SKMTC. It
139
+ * provides comprehensive error handling, validation, and issue tracking during
140
+ * the parsing process.
141
+ *
142
+ * This context handles the complex task of transforming external OpenAPI
143
+ * specifications into type-safe internal representations while maintaining
144
+ * detailed information about any parsing issues or inconsistencies found.
145
+ *
146
+ * ## Key Features
147
+ *
148
+ * - **JSON to OAS Conversion**: Transforms OpenAPI JSON into typed OAS objects
149
+ * - **Validation & Error Handling**: Comprehensive validation with detailed error reporting
150
+ * - **Issue Tracking**: Collects warnings and errors with precise location information
151
+ * - **Reference Management**: Handles complex reference resolution and tracking
152
+ * - **Logging Integration**: Provides detailed logging and tracing capabilities
153
+ * - **Silent Mode**: Can suppress console output while maintaining error collection
154
+ *
155
+ * @example Basic parsing usage
156
+ * ```typescript
157
+ * import { ParseContext } from '@skmtc/core';
158
+ *
159
+ * const parseContext = new ParseContext({
160
+ * documentObject: openApiJsonDocument,
161
+ * logger: myLogger,
162
+ * stackTrail: traceStack,
163
+ * silent: false
164
+ * });
165
+ *
166
+ * const oasDocument = parseContext.parse();
167
+ *
168
+ * // Check for parsing issues
169
+ * if (parseContext.issues.length > 0) {
170
+ * console.log('Parsing issues found:');
171
+ * parseContext.issues.forEach(issue => {
172
+ * console.log(`${issue.level}: ${issue.location} - ${issue.message || issue.error?.message}`);
173
+ * });
174
+ * }
175
+ *
176
+ * // Use the parsed document
177
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components?.schemas || {}));
178
+ * ```
179
+ *
180
+ * @example Error handling during parsing
181
+ * ```typescript
182
+ * const parseContext = new ParseContext({
183
+ * documentObject: malformedOpenApiDoc,
184
+ * logger: logger,
185
+ * stackTrail: stack,
186
+ * silent: true
187
+ * });
188
+ *
189
+ * try {
190
+ * const parsed = parseContext.parse();
191
+ *
192
+ * // Separate errors from warnings
193
+ * const errors = parseContext.issues.filter(issue => issue.level === 'error');
194
+ * const warnings = parseContext.issues.filter(issue => issue.level === 'warning');
195
+ *
196
+ * if (errors.length > 0) {
197
+ * console.error(`${errors.length} parsing errors found`);
198
+ * errors.forEach(error => {
199
+ * console.error(`Error at ${error.location}: ${error.error.message}`);
200
+ * });
201
+ * }
202
+ *
203
+ * if (warnings.length > 0) {
204
+ * console.warn(`${warnings.length} parsing warnings found`);
205
+ * warnings.forEach(warning => {
206
+ * console.warn(`Warning at ${warning.location}: ${warning.message}`);
207
+ * });
208
+ * }
209
+ * } catch (error) {
210
+ * console.error('Critical parsing failure:', error);
211
+ * }
212
+ * ```
213
+ *
214
+ * @example Integration with CoreContext
215
+ * ```typescript
216
+ * // Typically used within CoreContext.parse()
217
+ * class CustomCoreContext extends CoreContext {
218
+ * parseWithCustomValidation(document: OpenAPIV3.Document) {
219
+ * const parseContext = new ParseContext({
220
+ * documentObject: document,
221
+ * logger: this.logger,
222
+ * stackTrail: this.stackTrail,
223
+ * silent: this.silent
224
+ * });
225
+ *
226
+ * const parsed = parseContext.parse();
227
+ *
228
+ * // Custom post-processing based on issues
229
+ * const criticalErrors = parseContext.issues.filter(issue =>
230
+ * issue.level === 'error' && issue.type === 'schema-validation'
231
+ * );
232
+ *
233
+ * if (criticalErrors.length > 0) {
234
+ * throw new Error(`Schema validation failed: ${criticalErrors.length} critical errors`);
235
+ * }
236
+ *
237
+ * return parsed;
238
+ * }
239
+ * }
240
+ * ```
241
+ */
64
242
  export declare class ParseContext {
65
243
  #private;
66
244
  documentObject: OpenAPIV3.Document;
@@ -1 +1 @@
1
- {"version":3,"file":"ParseContext.d.ts","sourceRoot":"","sources":["../../src/context/ParseContext.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,KAAK,KAAK,GAAG,MAAM,yCAAyC,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,KAAK,EAAE,SAAS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MAAM,GAAG,SAAS;IAQvD,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAIlD,gBAAgB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,oBAAoB;IAYtE,gBAAgB,CAAC,CAAC,EAAE,EAClB,GAAG,EACH,KAAK,EACL,MAAM,EACN,MAAM,EACN,SAAS,EACT,IAAI,EACL,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAgB1C,QAAQ,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,YAAY;IAItD,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB;CAqB5D;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,KAAG,SAAS,CAAC,QAMtD,CAAA"}
@@ -16,6 +16,114 @@ import { toDocumentFieldsV3 } from '../oas/document/toDocumentFieldsV3.js';
16
16
  import { OasDocument } from '../oas/document/Document.js';
17
17
  import { tracer } from '../helpers/tracer.js';
18
18
  import * as v from 'valibot';
19
+ /**
20
+ * The parsing context for the first phase of the SKMTC transformation pipeline.
21
+ *
22
+ * `ParseContext` is responsible for converting OpenAPI v3 JSON documents into
23
+ * the internal OAS (OpenAPI Schema) object representation used by SKMTC. It
24
+ * provides comprehensive error handling, validation, and issue tracking during
25
+ * the parsing process.
26
+ *
27
+ * This context handles the complex task of transforming external OpenAPI
28
+ * specifications into type-safe internal representations while maintaining
29
+ * detailed information about any parsing issues or inconsistencies found.
30
+ *
31
+ * ## Key Features
32
+ *
33
+ * - **JSON to OAS Conversion**: Transforms OpenAPI JSON into typed OAS objects
34
+ * - **Validation & Error Handling**: Comprehensive validation with detailed error reporting
35
+ * - **Issue Tracking**: Collects warnings and errors with precise location information
36
+ * - **Reference Management**: Handles complex reference resolution and tracking
37
+ * - **Logging Integration**: Provides detailed logging and tracing capabilities
38
+ * - **Silent Mode**: Can suppress console output while maintaining error collection
39
+ *
40
+ * @example Basic parsing usage
41
+ * ```typescript
42
+ * import { ParseContext } from '@skmtc/core';
43
+ *
44
+ * const parseContext = new ParseContext({
45
+ * documentObject: openApiJsonDocument,
46
+ * logger: myLogger,
47
+ * stackTrail: traceStack,
48
+ * silent: false
49
+ * });
50
+ *
51
+ * const oasDocument = parseContext.parse();
52
+ *
53
+ * // Check for parsing issues
54
+ * if (parseContext.issues.length > 0) {
55
+ * console.log('Parsing issues found:');
56
+ * parseContext.issues.forEach(issue => {
57
+ * console.log(`${issue.level}: ${issue.location} - ${issue.message || issue.error?.message}`);
58
+ * });
59
+ * }
60
+ *
61
+ * // Use the parsed document
62
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components?.schemas || {}));
63
+ * ```
64
+ *
65
+ * @example Error handling during parsing
66
+ * ```typescript
67
+ * const parseContext = new ParseContext({
68
+ * documentObject: malformedOpenApiDoc,
69
+ * logger: logger,
70
+ * stackTrail: stack,
71
+ * silent: true
72
+ * });
73
+ *
74
+ * try {
75
+ * const parsed = parseContext.parse();
76
+ *
77
+ * // Separate errors from warnings
78
+ * const errors = parseContext.issues.filter(issue => issue.level === 'error');
79
+ * const warnings = parseContext.issues.filter(issue => issue.level === 'warning');
80
+ *
81
+ * if (errors.length > 0) {
82
+ * console.error(`${errors.length} parsing errors found`);
83
+ * errors.forEach(error => {
84
+ * console.error(`Error at ${error.location}: ${error.error.message}`);
85
+ * });
86
+ * }
87
+ *
88
+ * if (warnings.length > 0) {
89
+ * console.warn(`${warnings.length} parsing warnings found`);
90
+ * warnings.forEach(warning => {
91
+ * console.warn(`Warning at ${warning.location}: ${warning.message}`);
92
+ * });
93
+ * }
94
+ * } catch (error) {
95
+ * console.error('Critical parsing failure:', error);
96
+ * }
97
+ * ```
98
+ *
99
+ * @example Integration with CoreContext
100
+ * ```typescript
101
+ * // Typically used within CoreContext.parse()
102
+ * class CustomCoreContext extends CoreContext {
103
+ * parseWithCustomValidation(document: OpenAPIV3.Document) {
104
+ * const parseContext = new ParseContext({
105
+ * documentObject: document,
106
+ * logger: this.logger,
107
+ * stackTrail: this.stackTrail,
108
+ * silent: this.silent
109
+ * });
110
+ *
111
+ * const parsed = parseContext.parse();
112
+ *
113
+ * // Custom post-processing based on issues
114
+ * const criticalErrors = parseContext.issues.filter(issue =>
115
+ * issue.level === 'error' && issue.type === 'schema-validation'
116
+ * );
117
+ *
118
+ * if (criticalErrors.length > 0) {
119
+ * throw new Error(`Schema validation failed: ${criticalErrors.length} critical errors`);
120
+ * }
121
+ *
122
+ * return parsed;
123
+ * }
124
+ * }
125
+ * ```
126
+ */
19
127
  export class ParseContext {
20
128
  constructor({ documentObject, logger, stackTrail, silent = true }) {
21
129
  Object.defineProperty(this, "documentObject", {
@@ -1,17 +1,257 @@
1
1
  import type { GeneratedDefinition, GeneratedValue, GenerationType } from '../types/GeneratedValue.js';
2
2
  import type { ContentSettings } from './ContentSettings.js';
3
3
  import type { Identifier } from './Identifier.js';
4
+ /**
5
+ * Constructor arguments for {@link Inserted}.
6
+ *
7
+ * @template V - The type of generated value
8
+ * @template T - The generation type ('force' or 'lazy')
9
+ * @template EnrichmentType - Optional enrichment data type
10
+ */
4
11
  type ConstructorArgs<V extends GeneratedValue, T extends GenerationType, EnrichmentType> = {
12
+ /** Content settings including identifier and export path */
5
13
  settings: ContentSettings<EnrichmentType>;
14
+ /** The generated definition with its value */
6
15
  definition: GeneratedDefinition<V, T>;
7
16
  };
17
+ /**
18
+ * Represents a successfully inserted generator artifact in the SKMTC DSL system.
19
+ *
20
+ * The `Inserted` class is returned when generators are inserted into the generation
21
+ * context, providing access to the generated content, metadata, and configuration.
22
+ * It acts as a bridge between the insertion process and the consuming code that
23
+ * needs to reference or use the generated artifacts.
24
+ *
25
+ * This class provides type-safe access to generated values with proper handling
26
+ * of both forced and lazy generation modes, ensuring the correct optionality
27
+ * of the generated content based on the generation strategy used.
28
+ *
29
+ * ## Key Features
30
+ *
31
+ * - **Type Safety**: Generic parameters preserve exact types from generators
32
+ * - **Generation Modes**: Handles both 'force' and 'lazy' generation strategies
33
+ * - **Metadata Access**: Provides access to identifiers, export paths, and settings
34
+ * - **Value Extraction**: Type-safe value extraction with proper optionality
35
+ * - **Enrichment Support**: Full support for custom enrichment data types
36
+ *
37
+ * @template V - The type of generated value (preserves generator output type)
38
+ * @template T - The generation type ('force' ensures non-null, 'lazy' allows undefined)
39
+ * @template EnrichmentType - Optional type for custom enrichment data
40
+ *
41
+ * @example Basic usage with forced generation
42
+ * ```typescript
43
+ * import { Inserted } from '@skmtc/core';
44
+ *
45
+ * class MyGenerator extends ModelBase {
46
+ * generate(): Definition {
47
+ * // Insert a related model with forced generation
48
+ * const userModel = this.insertModel(
49
+ * new UserModelGenerator({ ... }),
50
+ * 'User'
51
+ * ); // Returns Inserted<UserModelValue, 'force', EnrichmentType>
52
+ *
53
+ * // Access the generated value (guaranteed to be present)
54
+ * const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
55
+ * const exportPath = userModel.toExportPath(); // './src/models.ts'
56
+ * const identifier = userModel.toName(); // 'User'
57
+ *
58
+ * return new Definition({
59
+ * identifier: Identifier.createType(this.refName),
60
+ * value: {
61
+ * generatorKey: this.generatorKey,
62
+ * content: `export interface Order { user: ${userTypeName}; }`
63
+ * }
64
+ * });
65
+ * }
66
+ * }
67
+ * ```
68
+ *
69
+ * @example Working with lazy generation
70
+ * ```typescript
71
+ * class ConditionalGenerator extends ModelBase {
72
+ * generate(): Definition {
73
+ * // Insert with lazy generation (may not generate if already exists)
74
+ * const optionalModel = this.insertModel(
75
+ * new OptionalModelGenerator({ ... }),
76
+ * 'OptionalModel',
77
+ * { generation: 'lazy' }
78
+ * ); // Returns Inserted<OptionalValue, 'lazy', EnrichmentType>
79
+ *
80
+ * // Value might be undefined with lazy generation
81
+ * const value = optionalModel.toValue(); // OptionalValue | undefined
82
+ *
83
+ * if (value) {
84
+ * // Use the generated value
85
+ * return this.createDefinitionWith(value);
86
+ * } else {
87
+ * // Handle case where generation was skipped
88
+ * return this.createFallbackDefinition();
89
+ * }
90
+ * }
91
+ * }
92
+ * ```
93
+ *
94
+ * @example Accessing insertion metadata
95
+ * ```typescript
96
+ * class MetadataAwareGenerator extends OperationBase {
97
+ * generate(): Definition {
98
+ * const requestModel = this.insertModel(
99
+ * new RequestModelGenerator({ ... }),
100
+ * 'CreateUserRequest'
101
+ * );
102
+ *
103
+ * // Access various metadata
104
+ * const modelName = requestModel.toName(); // 'CreateUserRequest'
105
+ * const identifier = requestModel.toIdentifier(); // Full Identifier object
106
+ * const exportPath = requestModel.toExportPath(); // './src/api/types.ts'
107
+ * const enrichments = requestModel.settings.enrichments; // Custom data
108
+ *
109
+ * console.log(`Generated ${modelName} in ${exportPath}`);
110
+ *
111
+ * return new Definition({
112
+ * identifier: Identifier.createVariable(this.operation.operationId!),
113
+ * value: {
114
+ * generatorKey: this.generatorKey,
115
+ * content: `async function createUser(data: ${modelName}) { ... }`
116
+ * }
117
+ * });
118
+ * }
119
+ * }
120
+ * ```
121
+ *
122
+ * @example With enrichment data
123
+ * ```typescript
124
+ * type ValidationEnrichment = {
125
+ * validators: string[];
126
+ * required: boolean;
127
+ * };
128
+ *
129
+ * class EnrichedGenerator extends ModelBase<ValidationEnrichment> {
130
+ * generate(): Definition {
131
+ * const validatedModel = this.insertModel(
132
+ * new ValidatedModelGenerator({ ... }),
133
+ * 'ValidatedUser'
134
+ * ); // Returns Inserted<ModelValue, 'force', ValidationEnrichment>
135
+ *
136
+ * // Access enrichment data
137
+ * const enrichment = validatedModel.settings.enrichments;
138
+ * const validators = enrichment?.validators ?? [];
139
+ * const isRequired = enrichment?.required ?? false;
140
+ *
141
+ * return new Definition({
142
+ * identifier: Identifier.createType(this.refName),
143
+ * value: {
144
+ * generatorKey: this.generatorKey,
145
+ * content: this.generateWithValidation(validatedModel.toValue(), validators)
146
+ * }
147
+ * });
148
+ * }
149
+ * }
150
+ * ```
151
+ */
8
152
  export declare class Inserted<V extends GeneratedValue, T extends GenerationType, EnrichmentType> {
153
+ /** Content settings including identifier and export path */
9
154
  settings: ContentSettings<EnrichmentType>;
155
+ /** The generated definition with its value */
10
156
  definition: GeneratedDefinition<V, T>;
157
+ /**
158
+ * Creates a new Inserted instance.
159
+ *
160
+ * @param args - Insertion configuration
161
+ * @param args.settings - Content settings with identifier and export path
162
+ * @param args.definition - The generated definition containing the value
163
+ */
11
164
  constructor({ settings, definition }: ConstructorArgs<V, T, EnrichmentType>);
165
+ /**
166
+ * Gets the name of the inserted artifact.
167
+ *
168
+ * This method returns the string name from the identifier, which is commonly
169
+ * used when referencing the generated artifact in code or templates.
170
+ *
171
+ * @returns The name of the inserted artifact
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * const userModel = this.insertModel(generator, 'User');
176
+ * const name = userModel.toName(); // 'User'
177
+ *
178
+ * // Use in generated code
179
+ * const code = `interface Order { user: ${name}; }`;
180
+ * ```
181
+ */
12
182
  toName(): string;
183
+ /**
184
+ * Gets the full identifier of the inserted artifact.
185
+ *
186
+ * This method returns the complete Identifier object, which includes both
187
+ * the name and type information. Useful when you need access to entity type
188
+ * or type annotations.
189
+ *
190
+ * @returns The complete Identifier object
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * const model = this.insertModel(generator, 'User');
195
+ * const identifier = model.toIdentifier();
196
+ *
197
+ * console.log(identifier.name); // 'User'
198
+ * console.log(identifier.entityType); // EntityType instance
199
+ * console.log(identifier.typeName); // Optional type annotation
200
+ * ```
201
+ */
13
202
  toIdentifier(): Identifier;
203
+ /**
204
+ * Gets the export path where the artifact was generated.
205
+ *
206
+ * This method returns the file path where the generated artifact is located,
207
+ * which is useful for creating import statements or understanding the file
208
+ * structure of generated code.
209
+ *
210
+ * @returns The export path of the generated artifact
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * const userModel = this.insertModel(generator, 'User');
215
+ * const exportPath = userModel.toExportPath(); // './src/models/User.ts'
216
+ *
217
+ * // Create import statement
218
+ * const importStmt = `import { User } from '${exportPath}';`;
219
+ * ```
220
+ */
14
221
  toExportPath(): string;
222
+ /**
223
+ * Gets the generated value from the inserted artifact.
224
+ *
225
+ * This method returns the actual generated content with proper type safety
226
+ * based on the generation mode. For 'force' generation, the value is guaranteed
227
+ * to be present. For 'lazy' generation, the value might be undefined if
228
+ * generation was skipped.
229
+ *
230
+ * @returns The generated value, with optionality based on generation type
231
+ *
232
+ * @example Forced generation (guaranteed value)
233
+ * ```typescript
234
+ * const userModel = this.insertModel(generator, 'User'); // 'force' by default
235
+ * const value = userModel.toValue(); // UserModelValue (never undefined)
236
+ *
237
+ * // Safe to use directly
238
+ * const code = `type OrderUser = ${value};`;
239
+ * ```
240
+ *
241
+ * @example Lazy generation (optional value)
242
+ * ```typescript
243
+ * const optionalModel = this.insertModel(generator, 'Optional', { generation: 'lazy' });
244
+ * const value = optionalModel.toValue(); // OptionalValue | undefined
245
+ *
246
+ * if (value) {
247
+ * // Use the generated value
248
+ * const code = `type Optional = ${value};`;
249
+ * } else {
250
+ * // Handle missing value (generation was skipped)
251
+ * const code = 'type Optional = any; // Fallback';
252
+ * }
253
+ * ```
254
+ */
15
255
  toValue(): T extends 'force' ? V : V | undefined;
16
256
  }
17
257
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Inserted.d.ts","sourceRoot":"","sources":["../../src/dsl/Inserted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,cAAc,EACf,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,cAAc,EAAE,cAAc,IAAI;IACzF,QAAQ,EAAE,eAAe,CAAC,cAAc,CAA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