@n1k1t/mock-server
Version:
The ultimate toolkit to intercept, transform, and simulate HTTP/WS traffic with type-safe expectations
67 lines • 2.34 kB
TypeScript
import type { SystemHttpRequestContext, SystemSocketIoRequestContext } from '../transports';
import type { TFunction } from '../../../types';
type TEndpointHandler<TSchema extends IEndpointSchema<any>> = TFunction<any, [
SystemHttpRequestContext<TSchema['outgoing']['data']> & {
incoming: TSchema['incoming'];
} | SystemSocketIoRequestContext<TSchema['outgoing']['data']> & {
incoming: TSchema['incoming'];
}
]>;
export interface IEndpointResponse<T> {
code: 'OK' | 'INTERNAL_ERROR' | 'VALIDATION_ERROR' | 'NOT_FOUND';
timestamp: number;
data: T;
}
export interface IEndpointInput {
incoming?: {
query?: any;
data?: any;
};
outgoing?: any;
}
export interface IEndpointSchema<TInput extends IEndpointInput = {}> {
locations: {
http?: {
method: string;
path: string;
};
io?: {
path: string;
};
};
incoming: {
query?: NonNullable<TInput['incoming']>['query'];
data?: NonNullable<TInput['incoming']>['data'];
};
outgoing: IEndpointResponse<TInput['outgoing']>;
}
export declare class EndpointFactory<TSchema extends IEndpointSchema<any> = any> {
TSchema: TSchema;
private provided;
http<T extends NonNullable<IEndpointSchema['locations']['http']>, TReturn extends EndpointFactory<{
locations: {
http: T;
io: TSchema['locations']['io'];
};
incoming: TSchema['incoming'];
outgoing: TSchema['outgoing'];
}>>(payload: T): TReturn;
io<T extends NonNullable<IEndpointSchema['locations']['io']>, TReturn extends EndpointFactory<{
locations: {
http: TSchema['locations']['http'];
io: T;
};
incoming: TSchema['incoming'];
outgoing: TSchema['outgoing'];
}>>(payload: T): TReturn;
compile(handler: TEndpointHandler<TSchema>): Endpoint<TSchema>;
static build<TInput extends IEndpointInput>(): EndpointFactory<IEndpointSchema<TInput>>;
}
export declare class Endpoint<TSchema extends IEndpointSchema = any> {
locations: TSchema['locations'];
handler: TEndpointHandler<TSchema>;
TSchema: TSchema;
constructor(locations: TSchema['locations'], handler: TEndpointHandler<TSchema>);
}
export {};
//# sourceMappingURL=endpoint.d.ts.map