import type { FilesRenderResult, RenderResult } from './generateTypes.js'; import type { DefinitionBase } from '../dsl/Definition.js'; import type { PickArgs } from './generateTypes.js'; import type { ResultType } from '../types/Results.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 { FileBase } from '../dsl/FileBase.js'; import type { Preview } from '../types/Preview.js'; import type { StackTrail } from './StackTrail.js'; import { type CaptureChannel } from '../anchors/CaptureSink.js'; import type { GenerationMapEntry } from '../anchors/generationMap.js'; import type { AttributionState } from '../types/AttributionState.js'; import type { Sidecar } from '../anchors/sidecar.js'; /** * Result of the render phase: artifacts + file metadata + previews + * mappings, plus the attribution sidecars / generation-map when the run * configured `attribution.postPass`. */ type RenderPhaseResult = Omit & { sidecars?: Record; generationMap?: GenerationMapEntry[]; }; /** * Constructor arguments for {@link RenderContext}. */ type ConstructorArgs = { /** Map of generated files to render */ files: Map; /** Preview data for generated content */ previews: Record; /** Base path for resolving file paths */ basePath: string | undefined; /** Logger instance for debug information */ logger: log.Logger; /** Function to capture result status */ captureCurrentResult: (result: ResultType, stackTrail: StackTrail) => void; /** * Attribution (gen-maps) emission config. When `postPass` is set, the * single render pass also captures the producer occurrence tree and * emits sidecars + a generation map. Capture is skipped entirely when * absent — plain render, the capture interval never opens. */ attribution?: AttributionState; /** * Shared attribution capture channel — the same object the run's * `GenerateContext` holds, so snippets see the sink this context * publishes during the capturing render. Wired by `CoreContext`. */ captureChannel?: CaptureChannel; }; export declare class RenderContext { #private; /** Map of generated files to render */ files: Map; /** Preview data for generated content */ previews: Record; /** Base path for resolving file paths */ basePath: string | undefined; /** Logger instance for debug information */ logger: Logger; /** Function to capture result status */ captureCurrentResult: (result: ResultType, stackTrail: StackTrail) => void; /** Attribution (gen-maps) emission config; see {@link ConstructorArgs}. */ attribution: AttributionState | undefined; /** * Creates a new RenderContext instance with the specified configuration. * * Initializes the rendering context with files to render, preview data, * formatting configuration, and logging/tracing infrastructure. * * @param args - Constructor arguments containing all required configuration */ constructor({ files, previews, basePath, logger, captureCurrentResult, attribution, captureChannel }: ConstructorArgs); /** * Renders all files in the context to their final form. * * This is the main rendering method that orchestrates the collation of * all generated files. It resolves paths and produces the final * artifacts ready for writing to the filesystem. * * @returns Promise resolving to render result containing artifacts, file metadata, previews, and mappings * * @example * ```typescript * const renderContext = new RenderContext({ * files: generatedFiles, * previews: previewData, * mappings: mappingData, * basePath: './src/generated', * stackTrail: traceStack, * logger: logger, * captureCurrentResult: resultHandler * }); * * const result = await renderContext.render(); * * // Access rendered files * Object.entries(result.artifacts).forEach(([path, content]) => { * console.log(`Rendered ${path}: ${result.files[path].lines} lines`); * }); * ``` */ render(stackTrail: StackTrail): RenderPhaseResult; /** * Collates all files in the context into a unified render result. * * This method processes each file in the context through the rendering pipeline, * applying path resolution. It coordinates the parallel processing of all files * and aggregates the results into a single output structure. * * The collation process includes: * - File content rendering * - Path resolution using base path configuration * - Metadata calculation (line count, character count) * - Result aggregation into artifacts and file metadata maps * * @returns Promise resolving to collated files with artifacts and metadata * * @example * ```typescript * const collated = await renderContext.collate(); * * // Access rendered file content * console.log(collated.artifacts['/path/to/file.ts']); * * // Access file metadata * console.log(collated.files['/path/to/file.ts'].lines); * console.log(collated.files['/path/to/file.ts'].characters); * ``` */ collate(stackTrail: StackTrail): FilesRenderResult; /** * Retrieves a file from the context by its export path. * * The path is canonicalized first ({@link normalizeWorkspacePath}), so any * spelling of the same export path finds the same file. Throws when no * file exists at that path. * * @param filePath - The export path to retrieve, in any spelling * @returns The File or JsonFile instance * @throws {Error} When the file is not found in the context * * @example * ```typescript * const file = renderContext.getFile('./src/models/User.ts'); * console.log(file.toString()); // Access file content * * // Every spelling of the same export path finds the same file * const sameFile = renderContext.getFile('src/models/User.ts'); * const alsoSameFile = renderContext.getFile('@/src/models/User.ts'); * ``` */ getFile(filePath: string): FileBase; /** * Picks a specific definition from a file in the context. * * This method retrieves a named definition (type, interface, etc.) from * a specific file in the context. It validates that the target file is * a File type (not JsonFile) and returns the requested definition if found. * * @param args - Object containing the definition name and export path * @param args.name - The name of the definition to retrieve * @param args.exportPath - The path to the file containing the definition * @returns The Definition instance if found, undefined otherwise * @throws {Error} When the file is not found or is not a File type * * @example * ```typescript * const userDefinition = renderContext.pick({ * name: 'User', * exportPath: './src/models/User.ts' * }); * * if (userDefinition) { * console.log(userDefinition.identifier); // Access definition details * } * * // Pick interface definition * const apiInterface = renderContext.pick({ * name: 'ApiResponse', * exportPath: './src/types/api.ts' * }); * ``` */ pick({ name, exportPath }: PickArgs): DefinitionBase | undefined; } export {};