@skmtc/core 0.0.787 → 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.
Files changed (55) hide show
  1. package/esm/context/GenerateContext.d.ts +95 -0
  2. package/esm/context/GenerateContext.d.ts.map +1 -1
  3. package/esm/context/GenerateContext.js +95 -0
  4. package/esm/context/ParseContext.d.ts +178 -0
  5. package/esm/context/ParseContext.d.ts.map +1 -1
  6. package/esm/context/ParseContext.js +108 -0
  7. package/esm/dsl/Inserted.d.ts +240 -0
  8. package/esm/dsl/Inserted.d.ts.map +1 -1
  9. package/esm/dsl/Inserted.js +231 -0
  10. package/esm/dsl/JsonFile.d.ts +162 -0
  11. package/esm/dsl/JsonFile.d.ts.map +1 -1
  12. package/esm/dsl/JsonFile.js +157 -0
  13. package/esm/helpers/refFns.d.ts +160 -0
  14. package/esm/helpers/refFns.d.ts.map +1 -1
  15. package/esm/helpers/refFns.js +156 -0
  16. package/esm/oas/components/Components.d.ts +252 -2
  17. package/esm/oas/components/Components.d.ts.map +1 -1
  18. package/esm/oas/components/Components.js +241 -2
  19. package/esm/oas/operation/Operation.d.ts +107 -1
  20. package/esm/oas/operation/Operation.d.ts.map +1 -1
  21. package/esm/oas/operation/Operation.js +107 -1
  22. package/esm/oas/ref/Ref.d.ts +86 -0
  23. package/esm/oas/ref/Ref.d.ts.map +1 -1
  24. package/esm/oas/ref/Ref.js +86 -0
  25. package/esm/oas/union/Union.d.ts +119 -5
  26. package/esm/oas/union/Union.d.ts.map +1 -1
  27. package/esm/oas/union/Union.js +108 -5
  28. package/package.json +1 -1
  29. package/script/context/GenerateContext.d.ts +95 -0
  30. package/script/context/GenerateContext.d.ts.map +1 -1
  31. package/script/context/GenerateContext.js +95 -0
  32. package/script/context/ParseContext.d.ts +178 -0
  33. package/script/context/ParseContext.d.ts.map +1 -1
  34. package/script/context/ParseContext.js +108 -0
  35. package/script/dsl/Inserted.d.ts +240 -0
  36. package/script/dsl/Inserted.d.ts.map +1 -1
  37. package/script/dsl/Inserted.js +231 -0
  38. package/script/dsl/JsonFile.d.ts +162 -0
  39. package/script/dsl/JsonFile.d.ts.map +1 -1
  40. package/script/dsl/JsonFile.js +157 -0
  41. package/script/helpers/refFns.d.ts +160 -0
  42. package/script/helpers/refFns.d.ts.map +1 -1
  43. package/script/helpers/refFns.js +156 -0
  44. package/script/oas/components/Components.d.ts +252 -2
  45. package/script/oas/components/Components.d.ts.map +1 -1
  46. package/script/oas/components/Components.js +241 -2
  47. package/script/oas/operation/Operation.d.ts +107 -1
  48. package/script/oas/operation/Operation.d.ts.map +1 -1
  49. package/script/oas/operation/Operation.js +107 -1
  50. package/script/oas/ref/Ref.d.ts +86 -0
  51. package/script/oas/ref/Ref.d.ts.map +1 -1
  52. package/script/oas/ref/Ref.js +86 -0
  53. package/script/oas/union/Union.d.ts +119 -5
  54. package/script/oas/union/Union.d.ts.map +1 -1
  55. package/script/oas/union/Union.js +108 -5
@@ -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,CAAC,CAAA;IACzC,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CACtC,CAAA;AAED,qBAAa,QAAQ,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,cAAc,EAAE,cAAc;IACtF,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAC,CAAA;IACzC,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;gBACzB,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC;IAK3E,MAAM,IAAI,MAAM;IAIhB,YAAY,IAAI,UAAU;IAI1B,YAAY,IAAI,MAAM;IAItB,OAAO,IAAI,CAAC,SAAS,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS;CAGjD"}
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;;;;;;GAMG;AACH,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,cAAc,EAAE,cAAc,IAAI;IACzF,4DAA4D;IAC5D,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAC,CAAA;IACzC,8CAA8C;IAC9C,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CACtC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsIG;AACH,qBAAa,QAAQ,CAAC,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,cAAc,EAAE,cAAc;IACtF,4DAA4D;IAC5D,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAC,CAAA;IAEzC,8CAA8C;IAC9C,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAErC;;;;;;OAMG;gBACS,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC;IAK3E;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,IAAI,MAAM;IAIhB;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,IAAI,UAAU;IAI1B;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,IAAI,MAAM;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,OAAO,IAAI,CAAC,SAAS,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS;CAGjD"}
@@ -1,11 +1,155 @@
1
+ /**
2
+ * Represents a successfully inserted generator artifact in the SKMTC DSL system.
3
+ *
4
+ * The `Inserted` class is returned when generators are inserted into the generation
5
+ * context, providing access to the generated content, metadata, and configuration.
6
+ * It acts as a bridge between the insertion process and the consuming code that
7
+ * needs to reference or use the generated artifacts.
8
+ *
9
+ * This class provides type-safe access to generated values with proper handling
10
+ * of both forced and lazy generation modes, ensuring the correct optionality
11
+ * of the generated content based on the generation strategy used.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Type Safety**: Generic parameters preserve exact types from generators
16
+ * - **Generation Modes**: Handles both 'force' and 'lazy' generation strategies
17
+ * - **Metadata Access**: Provides access to identifiers, export paths, and settings
18
+ * - **Value Extraction**: Type-safe value extraction with proper optionality
19
+ * - **Enrichment Support**: Full support for custom enrichment data types
20
+ *
21
+ * @template V - The type of generated value (preserves generator output type)
22
+ * @template T - The generation type ('force' ensures non-null, 'lazy' allows undefined)
23
+ * @template EnrichmentType - Optional type for custom enrichment data
24
+ *
25
+ * @example Basic usage with forced generation
26
+ * ```typescript
27
+ * import { Inserted } from '@skmtc/core';
28
+ *
29
+ * class MyGenerator extends ModelBase {
30
+ * generate(): Definition {
31
+ * // Insert a related model with forced generation
32
+ * const userModel = this.insertModel(
33
+ * new UserModelGenerator({ ... }),
34
+ * 'User'
35
+ * ); // Returns Inserted<UserModelValue, 'force', EnrichmentType>
36
+ *
37
+ * // Access the generated value (guaranteed to be present)
38
+ * const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
39
+ * const exportPath = userModel.toExportPath(); // './src/models.ts'
40
+ * const identifier = userModel.toName(); // 'User'
41
+ *
42
+ * return new Definition({
43
+ * identifier: Identifier.createType(this.refName),
44
+ * value: {
45
+ * generatorKey: this.generatorKey,
46
+ * content: `export interface Order { user: ${userTypeName}; }`
47
+ * }
48
+ * });
49
+ * }
50
+ * }
51
+ * ```
52
+ *
53
+ * @example Working with lazy generation
54
+ * ```typescript
55
+ * class ConditionalGenerator extends ModelBase {
56
+ * generate(): Definition {
57
+ * // Insert with lazy generation (may not generate if already exists)
58
+ * const optionalModel = this.insertModel(
59
+ * new OptionalModelGenerator({ ... }),
60
+ * 'OptionalModel',
61
+ * { generation: 'lazy' }
62
+ * ); // Returns Inserted<OptionalValue, 'lazy', EnrichmentType>
63
+ *
64
+ * // Value might be undefined with lazy generation
65
+ * const value = optionalModel.toValue(); // OptionalValue | undefined
66
+ *
67
+ * if (value) {
68
+ * // Use the generated value
69
+ * return this.createDefinitionWith(value);
70
+ * } else {
71
+ * // Handle case where generation was skipped
72
+ * return this.createFallbackDefinition();
73
+ * }
74
+ * }
75
+ * }
76
+ * ```
77
+ *
78
+ * @example Accessing insertion metadata
79
+ * ```typescript
80
+ * class MetadataAwareGenerator extends OperationBase {
81
+ * generate(): Definition {
82
+ * const requestModel = this.insertModel(
83
+ * new RequestModelGenerator({ ... }),
84
+ * 'CreateUserRequest'
85
+ * );
86
+ *
87
+ * // Access various metadata
88
+ * const modelName = requestModel.toName(); // 'CreateUserRequest'
89
+ * const identifier = requestModel.toIdentifier(); // Full Identifier object
90
+ * const exportPath = requestModel.toExportPath(); // './src/api/types.ts'
91
+ * const enrichments = requestModel.settings.enrichments; // Custom data
92
+ *
93
+ * console.log(`Generated ${modelName} in ${exportPath}`);
94
+ *
95
+ * return new Definition({
96
+ * identifier: Identifier.createVariable(this.operation.operationId!),
97
+ * value: {
98
+ * generatorKey: this.generatorKey,
99
+ * content: `async function createUser(data: ${modelName}) { ... }`
100
+ * }
101
+ * });
102
+ * }
103
+ * }
104
+ * ```
105
+ *
106
+ * @example With enrichment data
107
+ * ```typescript
108
+ * type ValidationEnrichment = {
109
+ * validators: string[];
110
+ * required: boolean;
111
+ * };
112
+ *
113
+ * class EnrichedGenerator extends ModelBase<ValidationEnrichment> {
114
+ * generate(): Definition {
115
+ * const validatedModel = this.insertModel(
116
+ * new ValidatedModelGenerator({ ... }),
117
+ * 'ValidatedUser'
118
+ * ); // Returns Inserted<ModelValue, 'force', ValidationEnrichment>
119
+ *
120
+ * // Access enrichment data
121
+ * const enrichment = validatedModel.settings.enrichments;
122
+ * const validators = enrichment?.validators ?? [];
123
+ * const isRequired = enrichment?.required ?? false;
124
+ *
125
+ * return new Definition({
126
+ * identifier: Identifier.createType(this.refName),
127
+ * value: {
128
+ * generatorKey: this.generatorKey,
129
+ * content: this.generateWithValidation(validatedModel.toValue(), validators)
130
+ * }
131
+ * });
132
+ * }
133
+ * }
134
+ * ```
135
+ */
1
136
  export class Inserted {
137
+ /**
138
+ * Creates a new Inserted instance.
139
+ *
140
+ * @param args - Insertion configuration
141
+ * @param args.settings - Content settings with identifier and export path
142
+ * @param args.definition - The generated definition containing the value
143
+ */
2
144
  constructor({ settings, definition }) {
145
+ /** Content settings including identifier and export path */
3
146
  Object.defineProperty(this, "settings", {
4
147
  enumerable: true,
5
148
  configurable: true,
6
149
  writable: true,
7
150
  value: void 0
8
151
  });
152
+ /** The generated definition with its value */
9
153
  Object.defineProperty(this, "definition", {
10
154
  enumerable: true,
11
155
  configurable: true,
@@ -15,15 +159,102 @@ export class Inserted {
15
159
  this.settings = settings;
16
160
  this.definition = definition;
17
161
  }
162
+ /**
163
+ * Gets the name of the inserted artifact.
164
+ *
165
+ * This method returns the string name from the identifier, which is commonly
166
+ * used when referencing the generated artifact in code or templates.
167
+ *
168
+ * @returns The name of the inserted artifact
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const userModel = this.insertModel(generator, 'User');
173
+ * const name = userModel.toName(); // 'User'
174
+ *
175
+ * // Use in generated code
176
+ * const code = `interface Order { user: ${name}; }`;
177
+ * ```
178
+ */
18
179
  toName() {
19
180
  return this.settings.identifier.name;
20
181
  }
182
+ /**
183
+ * Gets the full identifier of the inserted artifact.
184
+ *
185
+ * This method returns the complete Identifier object, which includes both
186
+ * the name and type information. Useful when you need access to entity type
187
+ * or type annotations.
188
+ *
189
+ * @returns The complete Identifier object
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const model = this.insertModel(generator, 'User');
194
+ * const identifier = model.toIdentifier();
195
+ *
196
+ * console.log(identifier.name); // 'User'
197
+ * console.log(identifier.entityType); // EntityType instance
198
+ * console.log(identifier.typeName); // Optional type annotation
199
+ * ```
200
+ */
21
201
  toIdentifier() {
22
202
  return this.settings.identifier;
23
203
  }
204
+ /**
205
+ * Gets the export path where the artifact was generated.
206
+ *
207
+ * This method returns the file path where the generated artifact is located,
208
+ * which is useful for creating import statements or understanding the file
209
+ * structure of generated code.
210
+ *
211
+ * @returns The export path of the generated artifact
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const userModel = this.insertModel(generator, 'User');
216
+ * const exportPath = userModel.toExportPath(); // './src/models/User.ts'
217
+ *
218
+ * // Create import statement
219
+ * const importStmt = `import { User } from '${exportPath}';`;
220
+ * ```
221
+ */
24
222
  toExportPath() {
25
223
  return this.settings.exportPath;
26
224
  }
225
+ /**
226
+ * Gets the generated value from the inserted artifact.
227
+ *
228
+ * This method returns the actual generated content with proper type safety
229
+ * based on the generation mode. For 'force' generation, the value is guaranteed
230
+ * to be present. For 'lazy' generation, the value might be undefined if
231
+ * generation was skipped.
232
+ *
233
+ * @returns The generated value, with optionality based on generation type
234
+ *
235
+ * @example Forced generation (guaranteed value)
236
+ * ```typescript
237
+ * const userModel = this.insertModel(generator, 'User'); // 'force' by default
238
+ * const value = userModel.toValue(); // UserModelValue (never undefined)
239
+ *
240
+ * // Safe to use directly
241
+ * const code = `type OrderUser = ${value};`;
242
+ * ```
243
+ *
244
+ * @example Lazy generation (optional value)
245
+ * ```typescript
246
+ * const optionalModel = this.insertModel(generator, 'Optional', { generation: 'lazy' });
247
+ * const value = optionalModel.toValue(); // OptionalValue | undefined
248
+ *
249
+ * if (value) {
250
+ * // Use the generated value
251
+ * const code = `type Optional = ${value};`;
252
+ * } else {
253
+ * // Handle missing value (generation was skipped)
254
+ * const code = 'type Optional = any; // Fallback';
255
+ * }
256
+ * ```
257
+ */
27
258
  toValue() {
28
259
  return this.definition?.value;
29
260
  }
@@ -1,12 +1,174 @@
1
+ /**
2
+ * Constructor arguments for {@link JsonFile}.
3
+ */
1
4
  type JsonFileArgs = {
5
+ /** The file path for the generated JSON file */
2
6
  path: string;
7
+ /** The JSON content to write to the file */
3
8
  content: Record<string, unknown>;
4
9
  };
10
+ /**
11
+ * Represents a JSON file in the SKMTC DSL system.
12
+ *
13
+ * The `JsonFile` class is used to generate JSON files as part of the code generation
14
+ * process. It provides a simple interface for creating configuration files, manifests,
15
+ * package.json files, and other JSON-based artifacts with proper formatting.
16
+ *
17
+ * ## Key Features
18
+ *
19
+ * - **JSON Formatting**: Automatically formats JSON with 2-space indentation
20
+ * - **Type Safety**: Accepts any valid JSON-serializable content structure
21
+ * - **Path Management**: Associates content with specific file paths
22
+ * - **String Conversion**: Easy integration with file writing systems
23
+ *
24
+ * @example Basic JSON file creation
25
+ * ```typescript
26
+ * import { JsonFile } from '@skmtc/core';
27
+ *
28
+ * const packageJson = new JsonFile({
29
+ * path: './package.json',
30
+ * content: {
31
+ * name: 'my-api-client',
32
+ * version: '1.0.0',
33
+ * type: 'module',
34
+ * main: './index.js',
35
+ * dependencies: {
36
+ * 'axios': '^1.0.0'
37
+ * }
38
+ * }
39
+ * });
40
+ *
41
+ * const jsonContent = packageJson.toString();
42
+ * console.log(jsonContent);
43
+ * // {
44
+ * // "name": "my-api-client",
45
+ * // "version": "1.0.0",
46
+ * // "type": "module",
47
+ * // "main": "./index.js",
48
+ * // "dependencies": {
49
+ * // "axios": "^1.0.0"
50
+ * // }
51
+ * // }
52
+ * ```
53
+ *
54
+ * @example Configuration file generation
55
+ * ```typescript
56
+ * const configFile = new JsonFile({
57
+ * path: './src/config/api.json',
58
+ * content: {
59
+ * baseUrl: 'https://api.example.com',
60
+ * timeout: 5000,
61
+ * retryAttempts: 3,
62
+ * endpoints: {
63
+ * users: '/users',
64
+ * products: '/products',
65
+ * orders: '/orders'
66
+ * }
67
+ * }
68
+ * });
69
+ *
70
+ * // Write to file system
71
+ * await Deno.writeTextFile(configFile.path, configFile.toString());
72
+ * ```
73
+ *
74
+ * @example OpenAPI specification output
75
+ * ```typescript
76
+ * const openApiFile = new JsonFile({
77
+ * path: './dist/openapi.json',
78
+ * content: {
79
+ * openapi: '3.0.0',
80
+ * info: {
81
+ * title: 'My API',
82
+ * version: '1.0.0'
83
+ * },
84
+ * paths: {
85
+ * '/users': {
86
+ * get: {
87
+ * summary: 'List users',
88
+ * responses: {
89
+ * '200': {
90
+ * description: 'Success'
91
+ * }
92
+ * }
93
+ * }
94
+ * }
95
+ * }
96
+ * }
97
+ * });
98
+ * ```
99
+ *
100
+ * @example Using with generator registration
101
+ * ```typescript
102
+ * class MyGenerator extends ContentBase {
103
+ * generate() {
104
+ * const manifestFile = new JsonFile({
105
+ * path: './generated/manifest.json',
106
+ * content: {
107
+ * generatedAt: new Date().toISOString(),
108
+ * version: '1.0.0',
109
+ * files: [
110
+ * './models/User.ts',
111
+ * './models/Product.ts'
112
+ * ]
113
+ * }
114
+ * });
115
+ *
116
+ * // Register with the generation context
117
+ * this.register({ jsonFile: manifestFile });
118
+ * }
119
+ * }
120
+ * ```
121
+ */
5
122
  export declare class JsonFile {
123
+ /** The file type, always 'json' for JSON files */
6
124
  fileType: 'json';
125
+ /** The file path for this generated JSON file */
7
126
  path: string;
127
+ /** The JSON content to write to the file */
8
128
  content: Record<string, unknown>;
129
+ /**
130
+ * Creates a new JsonFile instance.
131
+ *
132
+ * @param args - JSON file configuration
133
+ * @param args.path - The output path for this JSON file
134
+ * @param args.content - The JSON content to write
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const configFile = new JsonFile({
139
+ * path: './config/settings.json',
140
+ * content: {
141
+ * theme: 'dark',
142
+ * language: 'en',
143
+ * features: ['auth', 'notifications']
144
+ * }
145
+ * });
146
+ * ```
147
+ */
9
148
  constructor({ path, content }: JsonFileArgs);
149
+ /**
150
+ * Converts the JSON content to a formatted string.
151
+ *
152
+ * This method serializes the content object to JSON with 2-space indentation
153
+ * for readable output. The resulting string is suitable for writing directly
154
+ * to a file or including in the generation pipeline.
155
+ *
156
+ * @returns The formatted JSON content as a string
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const file = new JsonFile({
161
+ * path: './data.json',
162
+ * content: { name: 'test', value: 42 }
163
+ * });
164
+ *
165
+ * console.log(file.toString());
166
+ * // {
167
+ * // "name": "test",
168
+ * // "value": 42
169
+ * // }
170
+ * ```
171
+ */
10
172
  toString(): string;
11
173
  }
12
174
  export {};