import type { DefinitionBase } from '../dsl/Definition.js'; import type { PendingDefinition } from '../dsl/PendingDefinition.js'; import type { OasSchema } from '../oas/schema/Schema.js'; import type { OasRef } from '../oas/ref/Ref.js'; import type { SkmtcParsedDocument } from '../types/SkmtcDocument.js'; import type { SupportedSubjects } from '../types/SupportedSubjects.js'; import type { EnrichmentDefaults } from '../types/EnrichmentDefaults.js'; import type { BuildModelSettingsArgs, GenerateContextType, GenerateResult, InsertModelOptions, InsertNormalizedModelArgs, InsertNormalizedModelOptions, InsertNormalizedModelReturn, InsertOperationArgs, InsertWebhookArgs, FindDefinitionArgs, ContextRegisterArgs, RegisterJsonArgs, RegisterMarkdownArgs, ToOperationSettingsArgs, ToWebhookSettingsArgs } from './generateTypes.js'; import type { ClientSettings } from '../types/Settings.js'; import { type Method } from '../types/Method.js'; import type { OasOperation } from '../oas/operation/Operation.js'; import type { OasWebhook } from '../oas/webhook/Webhook.js'; import { type ProjectionOptionsRest } from '../types/ProjectionOptions.js'; import type { GeneratedValue } from '../dsl/GeneratedValue.js'; import { ContentSettings } from '../dsl/ContentSettings.js'; import type { RefName } from '../types/RefName.js'; import type * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js'; import type { Logger } from '../types/Logger.js'; import type { ResultType } from '../types/Results.js'; import type { StackTrail } from './StackTrail.js'; import type { IdentifierBase } from '../dsl/IdentifierBase.js'; import type { SchemaToValueFn, SchemaType } from '../types/TypeSystem.js'; import { Inserted } from '../dsl/Inserted.js'; import type { CaptureChannel, CaptureSink } from '../anchors/CaptureSink.js'; import type { FileBase } from '../dsl/FileBase.js'; import type { GeneratorsMapContainer } from '../types/GeneratorType.js'; import type { OasOperationSource, WebhookSource, GqlOperationSource, ModelSource } from '../types/Preview.js'; import type { GqlOperation } from '../gql/operation/GqlOperation.js'; import type { OasVoid } from '../oas/void/Void.js'; import type { ModelProjection, NormalizedModelProjection } from '../dsl/model/types.js'; import { type EnrichmentWarning } from '../enrichments/EnrichmentWarning.js'; type ConstructorArgs = { /** * Source document for generation, wrapped in the {@link SkmtcParsedDocument} * discriminated union. Generators that target a specific protocol * narrow on `document.type` to access the underlying `OasDocument` or * `GqlDocument` via `document.value`. */ document: SkmtcParsedDocument; settings: ClientSettings | undefined; logger: log.Logger; captureCurrentResult: (result: ResultType, stackTrail: StackTrail) => void; toGeneratorConfigMap: () => GeneratorsMapContainer; /** * Shared attribution capture channel — the slot `RenderContext` flips to * open/close the capture interval. Snippets read it through this * context's {@link GenerateContext.captureSink}. Optional: when omitted * (tests, capture-less runs) `captureSink` is always `undefined`. */ captureChannel?: CaptureChannel; }; /** * Arguments for applying package imports to a generated file. * * Used to configure import statements and dependencies when generating * code files that need to reference external packages or modules. */ export type ApplyPackageImportsArgs = { /** The destination file path where imports should be applied */ destinationPath: string; /** The export path for the module being imported */ exportPath: string; }; /** * Arguments for creating and registering a definition from a schema. * * Used to transform OpenAPI schema objects into code definitions and * register them in the generation context for output file creation. * * @template Schema - The schema type extending SchemaType */ export type CreateAndRegisterDefinition = { /** The OpenAPI schema to transform into a definition */ schema: Schema; /** The identifier for the generated definition */ identifier: IdentifierBase; /** The destination file path where the definition should be registered */ destinationPath: string; /** Function to transform the schema into a generated value */ schemaToValueFn: SchemaToValueFn; /** Optional root reference name for the schema */ rootRef?: RefName; /** Whether to exclude this definition from exports */ noExport?: boolean; }; /** * Arguments for retrieving operation-specific settings. * * Used to get generator-specific configuration for a particular * OpenAPI operation based on its path and HTTP method. */ export type GetOperationSettingsArgs = { /** The ID of the generator requesting settings */ generatorId: string; /** The API path for the operation */ path: string; /** The HTTP method for the operation */ method: Method; }; /** * Arguments for adding render dependencies for an operation. * * Used to specify additional dependencies that should be included * when rendering code for a specific OpenAPI operation. */ export type AddRenderDependencyArgs = { /** The ID of the generator adding dependencies */ generatorId: string; /** The OpenAPI operation requiring dependencies */ operation: OasOperation; /** Array of dependency names or paths to include */ dependencies: string[]; }; /** * Arguments for retrieving model-specific settings. * * Used to get generator-specific configuration for a particular * OpenAPI model based on its reference name. */ export type ToModelSettingsArgs = { /** The ID of the generator requesting model settings */ generatorId: string; /** The reference name of the model */ refName: RefName; }; /** * Return type for insert operations in the generation context. * * Represents the result of inserting content into the generation * context, providing type-safe access to the inserted content. * * @template V - The generated value type * @template T - The generation type * @template EnrichmentType - The enrichment data type */ export type InsertReturn = Inserted; export declare class GenerateContext implements GenerateContextType { #private; /** * Parsed source document, wrapped in the {@link SkmtcParsedDocument} * discriminated union. Canonical representation; both protocol-neutral * (model) and protocol-specific (operation) dispatch reads through this. */ document: SkmtcParsedDocument; /** Client settings for customization (optional) */ settings: ClientSettings | undefined; /** Logger instance for tracking generation progress */ logger: Logger; /** Function to capture processing results at current stack position */ captureCurrentResult: (result: ResultType, stackTrail: StackTrail) => void; /** Function that returns the generator configuration map */ toGeneratorConfigMap: () => GeneratorsMapContainer; /** The pending models, outermost first: the last is the model whose projection constructor is running. */ pendingStack: PendingDefinition[]; constructor({ document, settings, logger, captureCurrentResult, toGeneratorConfigMap, captureChannel }: ConstructorArgs); /** * The recording enrichment accessor — the single choke point every * enrichment lookup routes through (dispatch loops, projection-base * `toEnrichments`, the Drivers' peer-variant guards). Segments are * literal keys (the array form of `get` keeps dotted paths intact); * the read is recorded so the post-walk consumption audit can flag * configured entries no lookup ever touched. */ readEnrichment(segments: readonly string[]): unknown; /** Add a warning to this run's enrichment audit (deduplicated). */ reportEnrichmentWarning(warning: EnrichmentWarning): void; /** * The active attribution capture sink, or `undefined` outside the * capture interval. Every `SnippetBase` instance's `toString` wrapper * reads this; `RenderContext` opens/closes the interval by flipping the * shared channel's `sink`. */ get captureSink(): CaptureSink | undefined; /** * The trail of the subject whose variant is being generated, or * `undefined` outside one. Log lines and the results the logger * records are addressed by it. */ get currentSubjectTrail(): StackTrail | undefined; /** * Runs `fn` with {@link currentSubjectTrail} set to `stackTrail`, and * restores the previous value afterwards. */ withSubjectTrail(stackTrail: StackTrail, fn: () => T): T; /** * @internal */ toArtifacts(stackTrail: StackTrail): GenerateResult; /** * Evaluate each generator's `isSupported` over the parsed document's subjects * and report the subjects each generator supports — capability only, no * transform and no render. Operation generators report the operations their * `isSupported` accepts; model generators report the models theirs accepts * (a generator that declares no `isSupported` defaults to every subject). A * generator targeting the other protocol reports nothing. */ toSupportedSubjects(): SupportedSubjects; /** * The seed enrichment values each configured generator derives from the * document — the *values* counterpart of {@link toSupportedSubjects}. For * every generator that advertises `toEnrichmentDefaults`, calls it over the * subjects the generator supports and keeps the non-`undefined` subject-scope * leaves, keyed by the `client.json#settings.enrichments` routing: * `[id][path][method]['main']` for operations, `[id][refName]['main']` for * models. Seeding targets the `'main'` variant; a generator that advertises * no defaults (or whose every subject returns `undefined`) is omitted. * * Like {@link toSupportedSubjects} it neither transforms nor renders, and is * defensive: a generator whose hook throws contributes nothing rather than * failing the whole pass. */ toEnrichmentDefaults(): EnrichmentDefaults; /** * Look up an already-registered file by path, or `undefined` if none * exists. Neutral primitive: returns the abstract `FileBase` and never * constructs anything, so a (future) language-owned `register` can ask * "does this file exist yet?" without the engine knowing the language. * To create-on-miss, use the internal `#getFile`; to add a * language-constructed file, use {@link addFile}. */ getFile(filePath: string): FileBase | undefined; /** * Read-only view of every file generated so far, keyed by (normalized) * export path. An **inspection / tooling** seam — NOT a coordination * surface: generators must still register via `register` / `insert*`, and * the storage stays `#`-private so nothing outside can mutate or re-bind it. * * Unlike {@link getFile} (which needs a path) this lets tooling *enumerate* * the files map — e.g. a debugger visualiser snapshotting the in-progress * state at a breakpoint. The `ReadonlyMap` type signals look-don't-touch. */ get inspectedFiles(): ReadonlyMap; /** * Store a language-constructed file. The engine never constructs a * concrete (language) `File`; the language's `register` builds its own * `FileBase` subclass and hands it in here. Throws if a file already * exists at the (normalized) path. Returns the stored file, so * get-or-create is a single expression at the call site * (`context.getFile(path) ?? context.addFile(new KtFile({ … }))`). */ addFile(file: File): File; /** * Registers JSON content for output to a file. * * @experimental This method is experimental and may change in future versions * @param args - Registration arguments with destination path and JSON content */ registerJson({ destinationPath, json }: RegisterJsonArgs): void; /** * Registers Markdown content for output to a file. * * The Markdown counterpart of {@link registerJson} — create-or-replace, last * write wins. The `markdown` is any {@link Stringable} (typically a composed * snippet tree), rendered verbatim into a {@link MarkdownFile}. * * @experimental This method is experimental and may change in future versions */ registerMarkdown({ destinationPath, markdown }: RegisterMarkdownArgs): void; /** * Insert supplied `imports` and `definitions` into file at `destinationPath`. * * If an import from a specified module already exists in the file, the * import names are appended to the existing import. * * Definitions will only be added if there is not already a definition with * the same name in the file. * * @mutates this.files */ register({ imports, reExports, definitions, custom, destinationPath, into }: ContextRegisterArgs): void; /** * Insert operation into the output file with path `destinationPath`. * * Insert will perform the following steps: * Insert an operation definition into `destinationPath`. * * Resolves identifier and export path from the projection, registers the * definition (or reuses a cached one), and stitches an import into * `destinationPath` if it differs from the projection's `exportPath`. * * @mutates this.files */ insertOperation(args: InsertOperationArgs): Inserted; /** * Insert a webhook's projection. Sibling of {@link insertOperation} for * the OAS 3.1 webhook subject — webhooks are OAS-only, so there is no * protocol discrimination. */ insertWebhook(args: InsertWebhookArgs): Inserted; /** * Insert a normalized model: dispatch to {@link insertModel} when the schema * is a `$ref`, otherwise produce a one-off definition under `fallbackName`. */ insertNormalizedModel | OasVoid, EnrichmentType, ProjectionOptions = undefined>(projection: NormalizedModelProjection, { schema, fallbackName, destinationPath }: InsertNormalizedModelArgs, ...rest: ProjectionOptionsRest, ProjectionOptions>): InsertNormalizedModelReturn; /** * Insert a model definition into `destinationPath`. * * Resolves identifier and export path from the projection, registers the * definition (or reuses a cached one), and stitches an import into * `destinationPath` if it differs from the projection's `exportPath`. * * @mutates this.files */ insertModel(projection: ModelProjection, refName: RefName, ...rest: ProjectionOptionsRest, ProjectionOptions>): Inserted; /** * Build content settings for an operation projection by calling its * statics `toIdentifierName` + `toIdentifierType`, `toExportPath`, and * `toEnrichments` against the * given operation. */ toOperationContentSettings(settingsArgs: ToOperationSettingsArgs): ContentSettings; /** * Build content settings for a webhook projection. Sibling of * {@link toOperationContentSettings}; webhooks are OAS-only, so there is no * protocol discrimination. */ toWebhookContentSettings(args: ToWebhookSettingsArgs): ContentSettings; /** * Build content settings for a model projection by calling its statics * `toIdentifierName` (pure, for the name) + `toIdentifierType` * (context-aware, for type/typeName/exported), `toExportPath`, and * `toEnrichments` against the given `refName` and `variant`. The full * identifier is assembled through the projection's language * (`lang.toIdentifier`). */ toModelContentSettings(args: BuildModelSettingsArgs): ContentSettings; /** * Perform one lookup of schema by `refName`. * @param refName * @returns Matching schema or ref * @throws {DanglingRefError} when no schema has that name */ resolveSchemaRefOnce(refName: RefName): OasSchema | OasRef<'schema'>; /** * Check if definition name `name` in file with path `exportPath` * has already been created and registered. * * @param { name, exportPath } * @returns Matching definition if found or `undefined` otherwise */ findDefinition({ name, exportPath, into }: FindDefinitionArgs): DefinitionBase | undefined; } type ToOasOperationSourceArgs = { operation: OasOperation; generatorId: string; /** Operation variant the artifact was emitted for (see {@link Variant}) */ variant: string; }; /** * Creates an OasOperationSource from an operation, generator ID, and variant. * * Transforms operation and generator information into a source descriptor * that can be used for tracking operation origins in the generation pipeline. * * @param args - Arguments containing operation, generator ID, and variant * @returns OasOperationSource descriptor for the operation */ export declare const toOasOperationSource: ({ operation, generatorId, variant }: ToOasOperationSourceArgs) => OasOperationSource; type ToWebhookSourceArgs = { webhook: OasWebhook; generatorId: string; /** Webhook variant the artifact was emitted for (see {@link Variant}) */ variant: string; }; /** * Creates a {@link WebhookSource} from a webhook, generator ID, and variant. * Sibling of {@link toOasOperationSource} for the 3.1 webhook subject. */ export declare const toWebhookSource: ({ webhook, generatorId, variant }: ToWebhookSourceArgs) => WebhookSource; type ToGqlOperationSourceArgs = { operation: GqlOperation; generatorId: string; /** Operation variant the artifact was emitted for (see {@link Variant}) */ variant: string; }; /** * Creates a GraphQL operation source descriptor. * * Sibling to {@link toOasOperationSource} for the GraphQL protocol — encodes * `rootKind` and `fieldName` instead of `path` / `method`. */ export declare const toGqlOperationSource: ({ operation, generatorId, variant }: ToGqlOperationSourceArgs) => GqlOperationSource; type ToModelSourceArgs = { refName: RefName; generatorId: string; /** Model variant the artifact was emitted for (see {@link Variant}) */ variant: string; }; /** * Creates a ModelSource from a reference name, generator ID, and variant. * * Transforms model reference and generator information into a source descriptor * that can be used for tracking model origins in the generation pipeline. * * @param args - Arguments containing reference name, generator ID, and variant * @returns ModelSource descriptor for the model */ export declare const toModelSource: ({ refName, generatorId, variant }: ToModelSourceArgs) => ModelSource; export {};