import type { Context, DefArgument, DefResult, Definitions, Request } from './shared'; export { Request }; type InvokePayload = { call: { functionKey: string; payload?: Argument; jobId?: string; }; context: Context; }; export type Response = { [key: string]: any; } | string | void; export type ResolverFunction = (request: Request) => Promise | Result; type DefinitionsHandler = (payload: InvokePayload, backendRuntimePayload?: Record) => Promise; export default class Resolver { private functions; constructor(); define(functionKey: string, cb: ResolverFunction): this; /** * Defines a resolver with explicit payload and return types. * * The first generic is the payload shape and the second generic is the return type. * * @example * type Payload = { name: string }; * type Response = { message: string }; * resolver.define('greet', ({ payload }) => ({ * message: `Hello ${payload.name}` * })); */ define(functionKey: string, cb: ResolverFunction): this; /** * Defines a resolver using the return-only generic form. * * The single type argument is the return type. * * @example * type Response = { message: string }; * resolver.define('greet', () => ({ message: 'ok' })); */ define(functionKey: string, cb: ResolverFunction): this; private getFunction; private sanitizeObject; getDefinitions(): DefinitionsHandler; } /** * Given a type specialising Definitions shared between frontend and backend, * Handlers will return a type for a record of resolver functions that are * needed to implement this on the backend. */ export type Handlers = { [Def in keyof D & string]: ResolverFunction, DefResult>; }; /** * Creates resolver definitions corresponding to a given Definitions type. * * @param handlers Resolver functions implementing the definitions * @returns Resolver definitions */ export declare function makeResolver(handlers: Handlers): DefinitionsHandler; //# sourceMappingURL=index.d.ts.map