helene
Version:
Real-time Web Apps for Node.js
29 lines (28 loc) • 1.13 kB
TypeScript
import { AnyFunction, MethodParams } from '../utils';
import { AnyObjectSchema } from 'yup';
import { z } from 'zod';
import { ClientNode } from './client-node';
import { Server } from './server';
export type MethodFunction<T = any, R = any> = (this: ClientNode, params?: MethodParams<T>) => Promise<R> | R;
/**
* @todo Add support for timeout monitoring.
*/
export interface MethodOptions<Schema extends z.ZodUndefined | z.ZodObject<any>> {
cache?: boolean;
maxAge?: number;
protected?: boolean;
middleware?: AnyFunction[];
schema?: Schema | AnyObjectSchema;
}
export declare class Method<Schema extends z.ZodUndefined | z.ZodObject<any>, Result> {
uuid: string;
fn: MethodFunction;
isProtected: boolean;
middleware: AnyFunction[];
schema: AnyObjectSchema | z.ZodSchema | null;
name: string;
server: Server;
constructor(server: Server, name: string, fn: MethodFunction<z.input<Schema> | any, Result>, opts: MethodOptions<Schema>);
runMiddleware(params: MethodParams, node?: ClientNode): Promise<any>;
exec(params: MethodParams, node?: ClientNode): Promise<any>;
}