import type { AnyMutationProcedure, // AnyQueryProcedure, AnySubscriptionProcedure, inferAsyncReturnType } from '@trpc/server'; import { initTRPC } from '@trpc/server'; import type { CreateWSSContextFnOptions } from '@trpc/server/adapters/ws'; /** * The type of transformed function. */ export type TransformedFunction = (...args: unknown[]) => Promise; /** * The type of parsed options from command line input. */ export type ParsedCommandOptions = Record; /** * Create Context. * @param opts The options of creating ws context function. * @returns The context. */ export function createContext(opts: CreateWSSContextFnOptions) { return { ...opts, socketId: 0 }; } type Context = inferAsyncReturnType; export const trpc = initTRPC.context().create(); type Resolve = (value: unknown) => void; type Reject = (reason?: unknown) => void; /** * It is used for client function call from server. */ export interface MappedPromiseItem { resolve: Resolve; reject: Reject; } /** * The type of request data sent from server to client. */ export interface RequestData { mappingId: string; reqId: string; payloads: unknown[]; } /** * The type of response data received from client to server. */ export interface ResponseData { mappingId: string; reqId: string; socketId: number; payload: unknown; } /** * The type of projectRegistyRouter. */ // eslint-disable-next-line export type AdapterRouter = { createInstance: AnyMutationProcedure; call: AnyMutationProcedure; destroy: AnyMutationProcedure; }; /** * The type of commonRouter. */ // eslint-disable-next-line export type CommonRouter = { event: AnySubscriptionProcedure; returnCallbackValue: AnyMutationProcedure; }; /** * The type of combined router. */ // eslint-disable-next-line export type CombinedRouter = { common: ReturnType>; adapter: ReturnType>; }; /** * The type of the app router which is served by the RPC Server. */ export type AppRouter = ReturnType>;