Docs@skmtc/core

Projections and snippets

CLASS

Inserted

@skmtc/core 0.63.4

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>
V

The type of generated value (preserves generator output type)

EnrichmentType

Optional type for custom enrichment data

Examples

Basic usage with forced generation
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.

args

Insertion configuration

args.settings

Content settings with identifier and export path

args.definition

The generated definition containing the value

Properties

settings, ContentSettings<EnrichmentType>

Content settings including identifier and export path

definition, GeneratedDefinition<V>

The generated definition with its value

Methods

toName

toName(): string

Gets 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.

Returns

The name of the inserted artifact

toIdentifier

toIdentifier(): IdentifierBase

Gets 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.

Returns

The complete IdentifierBase object

toExportPath

toExportPath(): WorkspacePath

Gets 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.

Returns

The export path of the generated artifact

toValue

toValue(): V

Gets the generated value from the inserted artifact.

This method returns the actual generated content with proper type safety

Returns

The generated value