import { NamedType, NodeDocument, ConversionResult as CoreTypesConversionResult } from "core-types"; import type { Reader } from "./reader.js"; import type { Writer } from "./writer.js"; import type { Source } from "./file.js"; import { TypeImplementation } from "./types.js"; export interface Target { filename: string; relFilename?: string; } export interface ConversionResultInformation { in: Omit; out: Omit; } export type ConversionResult = ConversionResultInformation & { data: T; }; export interface Converter { /** * Convert and save to file */ convert(from: Source, to: Target): Promise>; /** * Convert and return result as string */ convert(from: Source): Promise>; /** * The current working directory for this converter */ cwd: string; /** * From format */ fromFormat: TypeImplementation; } export type ConvertMapFunction = (node: NamedType, index: number, array: ReadonlyArray) => NamedType; export type ConvertFilterFunction = (node: NamedType, index: number, array: ReadonlyArray) => boolean; export type ConvertTransformFunction = (doc: NodeDocument) => NodeDocument; export interface ConvertOptions { /** * The current working directory to use when converting to or from files. * Is not necessary for string-to-string conversion. */ cwd?: string; /** * When simplify is true, the converter will let core-types _compress_ the * types after having converted from {reader} format to core-types. * This is usually recommended, but may cause some annotations (comments) * to be dropped. * * @default * true */ simplify?: boolean; /** * When simplifying (which is implied by this option), and-types of objects * will be merged into one self-contained object. * This is useful for type systems that don't treat object intersections the * same way e.g. TypeScript does. */ mergeObjects?: boolean; /** * Custom map function for transforming each type after it has been * converted *from* the source type (and after it has been simplified), * but before it's written to the target type system. * * If `filter` is used as well, this runs before `filter`. * If `transform` is used as well, this runs before `transform`. */ map?: ConvertMapFunction; /** * Custom filter function for filtering types after they have been * converted *from* the source type. * * If `map` is used as well, this runs after `map`. * If `transform` is used as well, this runs before `transform`. */ filter?: ConvertFilterFunction; /** * Custom filter function for filtering types after they have been * converted *from* the source type. * * If `map` is used as well, this runs after `map`. * If `filter` is used as well, this runs after `filter`. */ transform?: ConvertTransformFunction; /** * Shortcut reader and writer if possible (bypassing core-types). * * @default * true */ shortcut?: boolean; } export declare function makeConverter(reader: Reader, writer: Writer, options?: ConvertOptions): Converter;