import * as z from 'zod'; import { JUNO_FUNCTION_TYPE } from '../constants'; /** * The type of a serverless function. Not exposed to the developer. It allows the CLI * to discover the functions when parsing the code. */ export type CustomFunctionType = (typeof JUNO_FUNCTION_TYPE)[keyof typeof JUNO_FUNCTION_TYPE]; export declare const CustomFunctionGuardSchema: z.ZodCustom, z.core.$InferInnerFunctionType>; /** * @see CustomFunctionWithArgsAndResult */ export declare const CustomFunctionWithArgsAndResultSchema: z.ZodObject<{ args: z.ZodCustom, z.ZodObject>; result: z.ZodCustom, z.ZodObject>; handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>; /** * @see CustomFunctionWithArgs */ export declare const CustomFunctionWithArgsSchema: z.ZodObject<{ args: z.ZodCustom, z.ZodObject>; handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>; /** * @see CustomFunctionWithResult */ export declare const CustomFunctionWithResultSchema: z.ZodObject<{ result: z.ZodCustom, z.ZodObject>; handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>; /** * @see CustomFunctionWithoutArgsAndResult */ export declare const CustomFunctionWithoutArgsAndResultSchema: z.ZodObject<{ handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>; /** * @see CustomFunction */ export declare const CustomFunctionSchema: z.ZodUnion, z.ZodObject>; result: z.ZodCustom, z.ZodObject>; handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>, z.ZodObject<{ args: z.ZodCustom, z.ZodObject>; handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>, z.ZodObject<{ result: z.ZodCustom, z.ZodObject>; handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>, z.ZodObject<{ handler: z.ZodCustom, z.ZodUnion]>>, z.core.$InferInnerFunctionType, z.ZodUnion]>>>; guard: z.ZodOptional, z.core.$InferInnerFunctionType>>; hidden: z.ZodOptional; type: z.ZodEnum<{ __juno_function_query: "__juno_function_query"; __juno_function_update: "__juno_function_update"; }>; }, z.core.$strict>]>; /** * Base interface for all serverless function variants. */ interface CustomFunctionBase { /** * The type of the function, either a query or an update. */ type: CustomFunctionType; /** * An optional function that runs before the function is executed. * If the guard throws, the function is not executed. */ guard?: () => void; /** * If true, the function is not exposed in the public Candid interface. * Useful for internal functions such as HTTP response transform functions. */ hidden?: boolean; } /** * A serverless function with both input arguments and an output result. * * @template TArgs - The type of the input arguments. * @template TResult - The type of the output result. */ export interface CustomFunctionWithArgsAndResult extends CustomFunctionBase { /** * A Zod schema describing the input arguments. */ args: z.ZodObject; /** * A Zod schema describing the output result. */ result: z.ZodObject; /** * The function handler. Can be synchronous or asynchronous. * * @param {TArgs} args - The input arguments. * @returns {TResult | Promise} */ handler: (args: z.infer>) => z.infer> | Promise>>; } /** * A serverless function with input arguments but no output result. * * @template TArgs - The type of the input arguments. */ export interface CustomFunctionWithArgs extends CustomFunctionBase { /** * A Zod schema describing the input arguments. */ args: z.ZodObject; /** * The function handler. Can be synchronous or asynchronous. * * @param {TArgs} args - The input arguments. * @returns {void | Promise} */ handler: (args: z.infer>) => void | Promise; } /** * A serverless function with an output result but no input arguments. * * @template TResult - The type of the output result. */ export interface CustomFunctionWithResult extends CustomFunctionBase { /** * A Zod schema describing the output result. */ result: z.ZodObject; /** * The function handler. Can be synchronous or asynchronous. * * @returns {TResult | Promise} */ handler: () => z.infer> | Promise>>; } /** * A serverless function with no input arguments and no output result. */ export interface CustomFunctionWithoutArgsAndResult extends CustomFunctionBase { /** * The function handler. Can be synchronous or asynchronous. * * @returns {void | Promise} */ handler: () => void | Promise; } /** * A serverless function definition. The four variants cover all combinations * of optional input arguments and output result. * * @template TArgs - The type of the input arguments. * @template TResult - The type of the output result. */ export type CustomFunction = CustomFunctionWithArgsAndResult | CustomFunctionWithArgs | CustomFunctionWithResult | CustomFunctionWithoutArgsAndResult; export {};