@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.
@@ -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,14 +1,158 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Inserted = void 0;
4
+ /**
5
+ * Represents a successfully inserted generator artifact in the SKMTC DSL system.
6
+ *
7
+ * The `Inserted` class is returned when generators are inserted into the generation
8
+ * context, providing access to the generated content, metadata, and configuration.
9
+ * It acts as a bridge between the insertion process and the consuming code that
10
+ * needs to reference or use the generated artifacts.
11
+ *
12
+ * This class provides type-safe access to generated values with proper handling
13
+ * of both forced and lazy generation modes, ensuring the correct optionality
14
+ * of the generated content based on the generation strategy used.
15
+ *
16
+ * ## Key Features
17
+ *
18
+ * - **Type Safety**: Generic parameters preserve exact types from generators
19
+ * - **Generation Modes**: Handles both 'force' and 'lazy' generation strategies
20
+ * - **Metadata Access**: Provides access to identifiers, export paths, and settings
21
+ * - **Value Extraction**: Type-safe value extraction with proper optionality
22
+ * - **Enrichment Support**: Full support for custom enrichment data types
23
+ *
24
+ * @template V - The type of generated value (preserves generator output type)
25
+ * @template T - The generation type ('force' ensures non-null, 'lazy' allows undefined)
26
+ * @template EnrichmentType - Optional type for custom enrichment data
27
+ *
28
+ * @example Basic usage with forced generation
29
+ * ```typescript
30
+ * import { Inserted } from '@skmtc/core';
31
+ *
32
+ * class MyGenerator extends ModelBase {
33
+ * generate(): Definition {
34
+ * // Insert a related model with forced generation
35
+ * const userModel = this.insertModel(
36
+ * new UserModelGenerator({ ... }),
37
+ * 'User'
38
+ * ); // Returns Inserted<UserModelValue, 'force', EnrichmentType>
39
+ *
40
+ * // Access the generated value (guaranteed to be present)
41
+ * const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
42
+ * const exportPath = userModel.toExportPath(); // './src/models.ts'
43
+ * const identifier = userModel.toName(); // 'User'
44
+ *
45
+ * return new Definition({
46
+ * identifier: Identifier.createType(this.refName),
47
+ * value: {
48
+ * generatorKey: this.generatorKey,
49
+ * content: `export interface Order { user: ${userTypeName}; }`
50
+ * }
51
+ * });
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * @example Working with lazy generation
57
+ * ```typescript
58
+ * class ConditionalGenerator extends ModelBase {
59
+ * generate(): Definition {
60
+ * // Insert with lazy generation (may not generate if already exists)
61
+ * const optionalModel = this.insertModel(
62
+ * new OptionalModelGenerator({ ... }),
63
+ * 'OptionalModel',
64
+ * { generation: 'lazy' }
65
+ * ); // Returns Inserted<OptionalValue, 'lazy', EnrichmentType>
66
+ *
67
+ * // Value might be undefined with lazy generation
68
+ * const value = optionalModel.toValue(); // OptionalValue | undefined
69
+ *
70
+ * if (value) {
71
+ * // Use the generated value
72
+ * return this.createDefinitionWith(value);
73
+ * } else {
74
+ * // Handle case where generation was skipped
75
+ * return this.createFallbackDefinition();
76
+ * }
77
+ * }
78
+ * }
79
+ * ```
80
+ *
81
+ * @example Accessing insertion metadata
82
+ * ```typescript
83
+ * class MetadataAwareGenerator extends OperationBase {
84
+ * generate(): Definition {
85
+ * const requestModel = this.insertModel(
86
+ * new RequestModelGenerator({ ... }),
87
+ * 'CreateUserRequest'
88
+ * );
89
+ *
90
+ * // Access various metadata
91
+ * const modelName = requestModel.toName(); // 'CreateUserRequest'
92
+ * const identifier = requestModel.toIdentifier(); // Full Identifier object
93
+ * const exportPath = requestModel.toExportPath(); // './src/api/types.ts'
94
+ * const enrichments = requestModel.settings.enrichments; // Custom data
95
+ *
96
+ * console.log(`Generated ${modelName} in ${exportPath}`);
97
+ *
98
+ * return new Definition({
99
+ * identifier: Identifier.createVariable(this.operation.operationId!),
100
+ * value: {
101
+ * generatorKey: this.generatorKey,
102
+ * content: `async function createUser(data: ${modelName}) { ... }`
103
+ * }
104
+ * });
105
+ * }
106
+ * }
107
+ * ```
108
+ *
109
+ * @example With enrichment data
110
+ * ```typescript
111
+ * type ValidationEnrichment = {
112
+ * validators: string[];
113
+ * required: boolean;
114
+ * };
115
+ *
116
+ * class EnrichedGenerator extends ModelBase<ValidationEnrichment> {
117
+ * generate(): Definition {
118
+ * const validatedModel = this.insertModel(
119
+ * new ValidatedModelGenerator({ ... }),
120
+ * 'ValidatedUser'
121
+ * ); // Returns Inserted<ModelValue, 'force', ValidationEnrichment>
122
+ *
123
+ * // Access enrichment data
124
+ * const enrichment = validatedModel.settings.enrichments;
125
+ * const validators = enrichment?.validators ?? [];
126
+ * const isRequired = enrichment?.required ?? false;
127
+ *
128
+ * return new Definition({
129
+ * identifier: Identifier.createType(this.refName),
130
+ * value: {
131
+ * generatorKey: this.generatorKey,
132
+ * content: this.generateWithValidation(validatedModel.toValue(), validators)
133
+ * }
134
+ * });
135
+ * }
136
+ * }
137
+ * ```
138
+ */
4
139
  class Inserted {
140
+ /**
141
+ * Creates a new Inserted instance.
142
+ *
143
+ * @param args - Insertion configuration
144
+ * @param args.settings - Content settings with identifier and export path
145
+ * @param args.definition - The generated definition containing the value
146
+ */
5
147
  constructor({ settings, definition }) {
148
+ /** Content settings including identifier and export path */
6
149
  Object.defineProperty(this, "settings", {
7
150
  enumerable: true,
8
151
  configurable: true,
9
152
  writable: true,
10
153
  value: void 0
11
154
  });
155
+ /** The generated definition with its value */
12
156
  Object.defineProperty(this, "definition", {
13
157
  enumerable: true,
14
158
  configurable: true,
@@ -18,15 +162,102 @@ class Inserted {
18
162
  this.settings = settings;
19
163
  this.definition = definition;
20
164
  }
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
+ */
21
182
  toName() {
22
183
  return this.settings.identifier.name;
23
184
  }
185
+ /**
186
+ * Gets the full identifier of the inserted artifact.
187
+ *
188
+ * This method returns the complete Identifier object, which includes both
189
+ * the name and type information. Useful when you need access to entity type
190
+ * or type annotations.
191
+ *
192
+ * @returns The complete Identifier object
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const model = this.insertModel(generator, 'User');
197
+ * const identifier = model.toIdentifier();
198
+ *
199
+ * console.log(identifier.name); // 'User'
200
+ * console.log(identifier.entityType); // EntityType instance
201
+ * console.log(identifier.typeName); // Optional type annotation
202
+ * ```
203
+ */
24
204
  toIdentifier() {
25
205
  return this.settings.identifier;
26
206
  }
207
+ /**
208
+ * Gets the export path where the artifact was generated.
209
+ *
210
+ * This method returns the file path where the generated artifact is located,
211
+ * which is useful for creating import statements or understanding the file
212
+ * structure of generated code.
213
+ *
214
+ * @returns The export path of the generated artifact
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * const userModel = this.insertModel(generator, 'User');
219
+ * const exportPath = userModel.toExportPath(); // './src/models/User.ts'
220
+ *
221
+ * // Create import statement
222
+ * const importStmt = `import { User } from '${exportPath}';`;
223
+ * ```
224
+ */
27
225
  toExportPath() {
28
226
  return this.settings.exportPath;
29
227
  }
228
+ /**
229
+ * Gets the generated value from the inserted artifact.
230
+ *
231
+ * This method returns the actual generated content with proper type safety
232
+ * based on the generation mode. For 'force' generation, the value is guaranteed
233
+ * to be present. For 'lazy' generation, the value might be undefined if
234
+ * generation was skipped.
235
+ *
236
+ * @returns The generated value, with optionality based on generation type
237
+ *
238
+ * @example Forced generation (guaranteed value)
239
+ * ```typescript
240
+ * const userModel = this.insertModel(generator, 'User'); // 'force' by default
241
+ * const value = userModel.toValue(); // UserModelValue (never undefined)
242
+ *
243
+ * // Safe to use directly
244
+ * const code = `type OrderUser = ${value};`;
245
+ * ```
246
+ *
247
+ * @example Lazy generation (optional value)
248
+ * ```typescript
249
+ * const optionalModel = this.insertModel(generator, 'Optional', { generation: 'lazy' });
250
+ * const value = optionalModel.toValue(); // OptionalValue | undefined
251
+ *
252
+ * if (value) {
253
+ * // Use the generated value
254
+ * const code = `type Optional = ${value};`;
255
+ * } else {
256
+ * // Handle missing value (generation was skipped)
257
+ * const code = 'type Optional = any; // Fallback';
258
+ * }
259
+ * ```
260
+ */
30
261
  toValue() {
31
262
  return this.definition?.value;
32
263
  }
@@ -2,11 +2,171 @@ import "../_dnt.polyfills.js";
2
2
  import type { RefName } from '../types/RefName.js';
3
3
  import type { OpenAPIV3 } from 'openapi-types';
4
4
  import type { ReferenceObject } from '../oas/_merge-all-of/types.js';
5
+ /**
6
+ * Extracts a reference name from an OpenAPI $ref string.
7
+ *
8
+ * This function parses JSON Pointer references (like '#/components/schemas/User')
9
+ * and extracts the final component as a branded RefName type. It's used throughout
10
+ * the SKMTC system to convert string references into type-safe reference names.
11
+ *
12
+ * @param $ref - The OpenAPI reference string (e.g., '#/components/schemas/User')
13
+ * @returns The extracted reference name as a branded RefName type
14
+ *
15
+ * @throws {Error} When the reference string is invalid or empty
16
+ *
17
+ * @example Basic usage
18
+ * ```typescript
19
+ * import { toRefName } from '@skmtc/core/helpers';
20
+ *
21
+ * const refName = toRefName('#/components/schemas/User');
22
+ * console.log(refName); // 'User' (typed as RefName)
23
+ *
24
+ * const responseRef = toRefName('#/components/responses/ErrorResponse');
25
+ * console.log(responseRef); // 'ErrorResponse' (typed as RefName)
26
+ * ```
27
+ *
28
+ * @example Error cases
29
+ * ```typescript
30
+ * // These will throw errors:
31
+ * toRefName('invalid/ref/'); // Error: 'Invalid reference'
32
+ * toRefName('#/components/schemas/'); // Error: 'Invalid reference'
33
+ * ```
34
+ *
35
+ * @example Integration with OAS processing
36
+ * ```typescript
37
+ * class SchemaProcessor {
38
+ * processReference(ref: string) {
39
+ * const refName = toRefName(ref);
40
+ * const schema = this.document.components.schemas[refName];
41
+ * return this.processSchema(schema, refName);
42
+ * }
43
+ * }
44
+ * ```
45
+ */
5
46
  export declare const toRefName: ($ref: string) => RefName;
47
+ /**
48
+ * Type representing an object with a $ref property.
49
+ */
6
50
  type Ref = {
51
+ /** The OpenAPI reference string */
7
52
  $ref: string;
8
53
  };
54
+ /**
55
+ * Type guard function to check if a value is an OpenAPI reference object.
56
+ *
57
+ * This function performs runtime type checking to determine if an unknown value
58
+ * is an OpenAPI Reference Object (contains a $ref property with a string value).
59
+ * It's essential for safely handling mixed schema/reference data during processing.
60
+ *
61
+ * @param value - The value to check for reference properties
62
+ * @returns True if the value is a reference object, false otherwise
63
+ *
64
+ * @example Basic type checking
65
+ * ```typescript
66
+ * import { isRef } from '@skmtc/core/helpers';
67
+ *
68
+ * const schemaOrRef: unknown = { $ref: '#/components/schemas/User' };
69
+ *
70
+ * if (isRef(schemaOrRef)) {
71
+ * // TypeScript now knows schemaOrRef has a $ref property
72
+ * console.log(schemaOrRef.$ref); // Safe to access
73
+ * const refName = toRefName(schemaOrRef.$ref);
74
+ * } else {
75
+ * // Handle as actual schema object
76
+ * console.log('Direct schema object');
77
+ * }
78
+ * ```
79
+ *
80
+ * @example Processing mixed data
81
+ * ```typescript
82
+ * function processSchemaOrRef(data: unknown) {
83
+ * if (isRef(data)) {
84
+ * // Handle reference
85
+ * return resolveReference(data.$ref);
86
+ * } else {
87
+ * // Handle direct schema
88
+ * return processSchema(data as SchemaObject);
89
+ * }
90
+ * }
91
+ * ```
92
+ *
93
+ * @example Array processing
94
+ * ```typescript
95
+ * const mixedArray: unknown[] = [
96
+ * { type: 'string' },
97
+ * { $ref: '#/components/schemas/User' },
98
+ * { type: 'number' }
99
+ * ];
100
+ *
101
+ * const references = mixedArray.filter(isRef);
102
+ * const schemas = mixedArray.filter(item => !isRef(item));
103
+ * ```
104
+ */
9
105
  export declare const isRef: (value: unknown) => value is Ref;
106
+ /**
107
+ * Creates a reference resolver function for an OpenAPI document.
108
+ *
109
+ * This higher-order function returns a resolver that can dereference OpenAPI
110
+ * JSON Pointer references within the context of a specific document. It handles
111
+ * nested references by recursively resolving reference chains until it reaches
112
+ * an actual schema object.
113
+ *
114
+ * The resolver is particularly useful during schema processing where you need
115
+ * to follow reference chains to get the actual schema definitions.
116
+ *
117
+ * @param oasDocument - The OpenAPI document containing the schemas to resolve against
118
+ * @returns A function that resolves reference objects to schema objects
119
+ *
120
+ * @throws {Error} When a reference cannot be resolved or points to a non-existent schema
121
+ *
122
+ * @example Basic usage
123
+ * ```typescript
124
+ * import { toGetRef } from '@skmtc/core/helpers';
125
+ *
126
+ * const resolver = toGetRef(openApiDocument);
127
+ *
128
+ * const userSchema = resolver({ $ref: '#/components/schemas/User' });
129
+ * console.log(userSchema.type); // 'object'
130
+ * console.log(userSchema.properties); // User properties
131
+ * ```
132
+ *
133
+ * @example Resolving nested references
134
+ * ```typescript
135
+ * // If User references Address, and Address references Country
136
+ * const resolver = toGetRef(document);
137
+ *
138
+ * // This will follow the chain: User -> Address -> Country
139
+ * const resolvedSchema = resolver({ $ref: '#/components/schemas/User' });
140
+ * // Returns the final resolved schema object
141
+ * ```
142
+ *
143
+ * @example Error handling
144
+ * ```typescript
145
+ * const resolver = toGetRef(document);
146
+ *
147
+ * try {
148
+ * const schema = resolver({ $ref: '#/components/schemas/NonExistent' });
149
+ * } catch (error) {
150
+ * console.error('Reference resolution failed:', error.message);
151
+ * // Error: Invalid reference: #/components/schemas/NonExistent
152
+ * }
153
+ * ```
154
+ *
155
+ * @example Integration with schema processing
156
+ * ```typescript
157
+ * class SchemaProcessor {
158
+ * private resolver = toGetRef(this.document);
159
+ *
160
+ * processProperty(property: SchemaObject | ReferenceObject) {
161
+ * if (isRef(property)) {
162
+ * const resolved = this.resolver(property);
163
+ * return this.processSchema(resolved);
164
+ * }
165
+ * return this.processSchema(property);
166
+ * }
167
+ * }
168
+ * ```
169
+ */
10
170
  export declare const toGetRef: (oasDocument: OpenAPIV3.Document) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
11
171
  export {};
12
172
  //# sourceMappingURL=refFns.d.ts.map