UNPKG

t7m

Version:

Transformer for Elysia and Hono

92 lines 3.54 kB
import type { OnlyPossiblyUndefined } from './typeHelper'; /** * Include function type. * @template TInput The type of the input object. * @template TOutput The type of the output object. * @template K The key of the output object to include. * @template Props The type of the props object. */ export type IncludeFunction<TInput, TOutput, K extends keyof TOutput, Props> = (input: TInput, props: Props, forwardedIncludes: string[]) => Promise<TOutput[K]> | TOutput[K]; /** * Abstract transformer class. * @template TInput The type of the input object. * @template TOutput The type of the output object. * @template Props The type of the props object. * @template Includes The type of the includes object. */ export declare abstract class AbstractTransformer<TInput, TOutput, Props extends Record<string, unknown> | undefined = undefined, Includes extends keyof OnlyPossiblyUndefined<TOutput> = keyof OnlyPossiblyUndefined<TOutput>> { /** * Abstract method that must be implemented by subclasses to provide the core transformation logic. * @param input The input object to transform. * @param props Optional props object for additional parameters. * @returns The transformed output object. */ protected abstract data(input: TInput, props: Props): TOutput; /** * Map of include functions for each possible include. * @template K The key of the output object to include. * @template Props The type of the props object. */ protected readonly includesMap: { [K in Includes]: IncludeFunction<TInput, TOutput, K, Props>; }; /** * Transforms a single input object. * @param params The parameters for the transformation. * @returns The transformed output object. */ transform(params: { input: TInput; includes?: Includes[]; unsafeIncludes?: string[]; } & (Props extends undefined ? { props?: Props; } : { props: Props; })): Promise<TOutput>; /** * Transforms multiple input objects. * @param params The parameters for the transformation. * @returns The transformed output objects. */ transformMany(params: { inputs: TInput[]; includes?: (Includes | string)[]; unsafeIncludes?: string[]; } & (Props extends undefined ? { props?: Props; } : { props: Props; })): Promise<TOutput[]>; /** * Transforms a single input object. (Easier to use in generic functions) * @param params The parameters for the transformation. * @returns The transformed output object. */ _transform(params: { input: TInput; props: Props; includes?: (Includes | string)[]; unsafeIncludes?: string[]; }): Promise<TOutput>; /** * Transforms multiple input objects. (Easier to use in generic functions) * @param params The parameters for the transformation. * @returns The transformed output objects. */ _transformMany(params: { inputs: TInput[]; props: Props; includes?: (Includes | string)[]; unsafeIncludes?: string[]; }): Promise<TOutput[]>; /** * Transforms a single input object. * @param input The input object to transform. * @param props Optional props object for additional parameters. * @param includes Optional array of includes to transform. * @returns The transformed output object. */ private __transform; } //# sourceMappingURL=abstractTransformer.d.ts.map