Projections and snippets
Inserted
Represents a successfully inserted generator artifact in the SKMTC DSL system.
The Inserted class is returned when generators are inserted into the generation context, providing access to the generated content, metadata, and configuration. It acts as a bridge between the insertion process and the consuming code that needs to reference or use the generated artifacts.
This class provides type-safe access to generated values with proper handling of both forced and lazy generation modes, ensuring the correct optionality of the generated content based on the generation strategy used.
Key Features
- Type Safety: Generic parameters preserve exact types from generators
- Metadata Access: Provides access to identifiers, export paths, and settings
- Value Extraction: Type-safe value extraction with proper optionality
- Enrichment Support: Full support for custom enrichment data types
Signature
import { Inserted } from '@skmtc/core'
class Inserted<V extends GeneratedValue, EnrichmentType>The type of generated value (preserves generator output type)
Optional type for custom enrichment data
Examples
import { Inserted } from '@skmtc/core';
class MyGenerator extends ModelProjectionBase {
generate(): Definition {
// Insert a related model with forced generation
const userModel = this.insertModel(
new UserModelGenerator({ ... }),
'User'
); // Returns Inserted<UserModelValue, EnrichmentType>
// Access the generated value (guaranteed to be present)
const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
const exportPath = userModel.toExportPath(); // '@/src/models.ts'
const identifier = userModel.toName(); // 'User'
return new Definition({
identifier: createType(this.ref.refName),
value: {
generatorKey: this.generatorKey,
content: `export interface Order { user: ${userTypeName}; }`
}
});
}
}Constructor
constructor
constructor(args: ConstructorArgs<V, EnrichmentType>)Creates a new Inserted instance.
Insertion configuration
Content settings with identifier and export path
The generated definition containing the value
Properties
Content settings including identifier and export path
The generated definition with its value
Methods
toName
toName(): stringGets the name of the inserted artifact.
This method returns the string name from the identifier, which is commonly used when referencing the generated artifact in code or templates.
The name of the inserted artifact
toIdentifier
toIdentifier(): IdentifierBaseGets the full identifier of the inserted artifact.
This method returns the complete IdentifierBase object, which carries the name and (language-neutrally) the type annotation. Useful when you need access to the type annotation or export flag.
The complete IdentifierBase object
toExportPath
toExportPath(): WorkspacePathGets the export path where the artifact was generated.
This method returns the file path where the generated artifact is located, which is useful for creating import statements or understanding the file structure of generated code.
The export path of the generated artifact
toValue
toValue(): VGets the generated value from the inserted artifact.
This method returns the actual generated content with proper type safety
The generated value