import type { JSONB, JSONBObjectTypeIfDefined, MaybePromise } from "prostgles-types"; import type { SessionUser } from "../Auth/AuthTypes"; import type { PublishParams } from "./publishTypesAndUtils"; export type ServerFunctionDefinition = { input?: Record | undefined; description?: string; /** * undefined if not allowed */ run: undefined | ((args: Record | undefined) => MaybePromise); }; export declare const defineServerFunction: | undefined = undefined>(args: { input?: TInput; description?: string; /** * undefined if not allowed */ run: undefined | ((args: JSONBObjectTypeIfDefined) => MaybePromise); }) => ServerFunctionDefinition; export type ServerFunctionDefinitions = ( /** * params will be undefined on first run to generate the definitions */ params: undefined | PublishParams) => MaybePromise>; export declare const createServerFunctionWithContext: ( /** * undefined if not allowed */ context: Context | undefined) => | undefined, Run extends (args: JSONBObjectTypeIfDefined, context: Context) => MaybePromise>(args: { input?: Input; description?: string; run: Run; }) => { run: ((validatedArgs: any) => Run) | undefined; input?: Input; description?: string; }; type InputOf = T extends { input?: infer I; } ? I : undefined; type SafeInput = I extends Record ? I : undefined; type ServerFunctionArgsFrom = { input?: InputOf; description?: string; run: (args: JSONBObjectTypeIfDefined>>, context: Context) => MaybePromise; }; type ServerFunctionBlock = { [K in keyof Defs]: ServerFunctionArgsFrom; }; type WrappedDef = Def extends ({ input?: infer I; description?: infer D; run: (a: any, c: Context) => infer R; }) ? { input?: SafeInput; description?: D extends string ? D : string | undefined; run: undefined | ((a: any) => R); } : never; type WrappedBlock = { [K in keyof Defs]: WrappedDef; }; export declare const createServerFunctionBlockWithContext: (context: Context | undefined) => >(defs: Defs & ServerFunctionBlock) => WrappedBlock; export {}; //# sourceMappingURL=defineServerFunction.d.ts.map