import { ILanguageConverter, IRNode } from "../types.js"; import { TypescriptBaseConverter } from "./TypescriptBaseConverter.js"; import { JSONSchema7Definition } from "json-schema"; import { BaseConverterOpts, LanguageProfile } from "../converter/BaseConverter.js"; export interface TypescriptConverterOpts extends BaseConverterOpts { /** * If true, referenced types will not be created for objects and instead * the object type will be inlined. */ inlineTypes?: boolean; /** * Controls how enum values are emitted. * - `"union"` (default) → `"a" | "b" | "c"` * - `"enum"` → `export enum Status { A = "a", B = "b", C = "c" }` * Only applies when `inlineTypes` is false and all values are strings. */ enumStyle?: "union" | "enum"; /** * Whether to emit JSDoc comments from JSON Schema `description` (and * `title`) annotations. Defaults to `true`. Set to `false` to suppress them. * Only applies when `inlineTypes` is false (the default). */ jsdoc?: boolean; } /** * A TypeScript language converter plugin. */ export declare class TypescriptConverter extends TypescriptBaseConverter implements ILanguageConverter { /** @internal Public for `BaseConverterContext`; treat as protected for subclasses. */ readonly languageProfile: LanguageProfile; private schemaConverter; private opts; private inlineTypes; private enumStyle; /** * Stores enum declarations keyed by canonical signature (sorted JSON values) * for deduplication across the schema. */ private enumDeclarations; readonly code: string; readonly rootTypeName: string; readonly extractedTypeNames: string[]; readonly imports: string[]; readonly referencedNamedTypes: string[]; constructor(schema: JSONSchema7Definition, opts?: TypescriptConverterOpts); private computeRefTypeNamingConfigOverrides; /** * Pre-scans the IR tree to discover and register all enum declarations * before type generation begins. Traversal order mirrors generateType's * DFS order so that canonical-key deduplication picks the same "first" * path that runtime generation would encounter. */ private preRegisterEnumNames; protected generateEnumType(ir: IRNode): string; protected generateLiteralType(ir: IRNode): string; /** * Returns (or creates) a deduplicated enum declaration for the given string values. * Same set of values at different paths reuses the same enum. * * Name derivation uses PathUtils to strip array indices, then progressively * includes parent path segments for collision resolution (e.g. "Type" → * "ArgsType" → "DataArgsType") before falling back to a numeric suffix. */ private getOrCreateEnumDeclaration; /** * Derives a unique, valid TypeScript enum name from a dot-notation path. * Strips array indices via PathUtils, then tries the last segment ("Type"), * escalates to include parent segments on collision ("ArgsType", "DataArgsType"), * and falls back to a numeric suffix as a last resort. */ private deriveEnumName; /** * Converts a string value to a valid PascalCase enum member name. */ private toEnumMemberName; }