import { AnyProcedure, ProcedureArgs } from './procedure'; import { AnyRouter, AnyRouterDef, Router } from './router'; import { inferTransformedProcedureOutput } from './shared'; export type inferRouterDef = TRouter extends Router< infer TParams > ? TParams extends AnyRouterDef ? TParams : never : never; export type inferRouterConfig = inferRouterDef['_config']; export type inferRouterContext = inferRouterConfig['$types']['ctx']; export type inferRouterError = inferRouterConfig['$types']['errorShape']; export type inferRouterMeta = inferRouterConfig['$types']['meta']; export const procedureTypes = ['query', 'mutation', 'subscription'] as const; /** * @public */ export type ProcedureType = (typeof procedureTypes)[number]; export type inferHandlerInput = ProcedureArgs< inferProcedureParams >; export type inferProcedureInput = inferProcedureParams['_input_in']; export type inferProcedureParams = TProcedure extends AnyProcedure ? TProcedure['_def'] : never; export type inferProcedureOutput = inferProcedureParams['_output_out']; type GetInferenceHelpers< TType extends 'input' | 'output', TRouter extends AnyRouter, > = { [TKey in keyof TRouter['_def']['record']]: TRouter['_def']['record'][TKey] extends infer TRouterOrProcedure ? TRouterOrProcedure extends AnyRouter ? GetInferenceHelpers : TRouterOrProcedure extends AnyProcedure ? TType extends 'input' ? inferProcedureInput : inferTransformedProcedureOutput< TRouter['_def']['_config'], TRouterOrProcedure > : never : never; }; export type inferRouterInputs = GetInferenceHelpers< 'input', TRouter >; export type inferRouterOutputs = GetInferenceHelpers< 'output', TRouter >; /** * @internal */ export type IntersectionError = `The property '${TKey}' in your router collides with a built-in method, rename this router or procedure on your backend.`; /** * @internal */ export type ProtectedIntersection = keyof TType & keyof TWith extends never ? TType & TWith : IntersectionError; /** * @public */ export type Maybe = TType | null | undefined; /** * @internal * @see https://github.com/ianstormtaylor/superstruct/blob/7973400cd04d8ad92bbdc2b6f35acbfb3c934079/src/utils.ts#L323-L325 */ export type Simplify = TType extends any[] | Date ? TType : { [K in keyof TType]: TType[K] }; /** * @public */ export type Dict = Record; /** * @public */ export type MaybePromise = Promise | TType; /** * @internal * * Creates a "lower-priority" type inference. * https://github.com/microsoft/TypeScript/issues/14829#issuecomment-322267089 */ export type InferLast = TType & { [KeyType in keyof TType]: TType[KeyType]; }; /** * @public */ export type inferAsyncReturnType any> = Awaited>; export type FilterKeys = { [TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never; }[keyof TObj]; /** * @internal */ export type Filter = Pick< TObj, FilterKeys >; /** * Unwrap return type if the type is a function (sync or async), else use the type as is * @internal */ export type Unwrap = TType extends (...args: any[]) => infer R ? Awaited : TType; /** * Makes the object recursively optional * @internal */ export type DeepPartial = TObject extends object ? { [P in keyof TObject]?: DeepPartial; } : TObject; /** * Omits the key without removing a potential union * @internal */ export type DistributiveOmit = TObj extends any ? Omit : never; /* * See https://github.com/microsoft/TypeScript/issues/41966#issuecomment-758187996 * Fixes issues with iterating over keys of objects with index signatures. * Without this, iterations over keys of objects with index signatures will lose * type information about the keys and only the index signature will remain. * @internal */ export type WithoutIndexSignature = { [K in keyof TObj as string extends K ? never : number extends K ? never : K]: TObj[K]; };