UNPKG

@dbs-portal/tool-mock

Version:

API mocking toolkit using MSW for DBS Portal development workflows

61 lines 3.09 kB
/** * Handler factory functions for creating common request handlers */ import type { RequestHandler } from 'msw'; import type { CustomHandlerOptions, AuthRequirements } from './types'; import type { MockRequest, MockResponseFactory } from '../core/types'; /** * Create a custom handler with built-in utilities */ export declare function createHandler<T = any>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, options: Omit<CustomHandlerOptions<T>, 'method' | 'path'>): RequestHandler; /** * Create multiple handlers from a configuration object */ export declare function createHandlers(config: Record<string, Omit<CustomHandlerOptions, 'method' | 'path'> & { method: string; path: string; }>): RequestHandler[]; /** * Create a typed handler with TypeScript support */ export declare function createTypedHandler<TRequest = any, TResponse = any>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, responseFactory: (request: MockRequest & { body: TRequest; }) => Promise<TResponse> | TResponse, options?: Partial<Omit<CustomHandlerOptions, 'method' | 'path' | 'response'>>): RequestHandler; /** * Create a GET handler */ export declare function createGetHandler<T = any>(path: string, responseFactory: MockResponseFactory<T>, options?: Partial<Omit<CustomHandlerOptions<T>, 'method' | 'path' | 'response'>>): RequestHandler; /** * Create a POST handler */ export declare function createPostHandler<T = any>(path: string, responseFactory: MockResponseFactory<T>, options?: Partial<Omit<CustomHandlerOptions<T>, 'method' | 'path' | 'response'>>): RequestHandler; /** * Create a PUT handler */ export declare function createPutHandler<T = any>(path: string, responseFactory: MockResponseFactory<T>, options?: Partial<Omit<CustomHandlerOptions<T>, 'method' | 'path' | 'response'>>): RequestHandler; /** * Create a PATCH handler */ export declare function createPatchHandler<T = any>(path: string, responseFactory: MockResponseFactory<T>, options?: Partial<Omit<CustomHandlerOptions<T>, 'method' | 'path' | 'response'>>): RequestHandler; /** * Create a DELETE handler */ export declare function createDeleteHandler<T = any>(path: string, responseFactory: MockResponseFactory<T>, options?: Partial<Omit<CustomHandlerOptions<T>, 'method' | 'path' | 'response'>>): RequestHandler; /** * Create handlers with authentication protection */ export declare function withAuth(handler: RequestHandler, _authRequirements: AuthRequirements): RequestHandler; /** * Create a handler that always returns an error */ export declare function createErrorHandler(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, error: { status: number; code: string; message: string; details?: any; }): RequestHandler; /** * Create a handler that simulates loading */ export declare function createLoadingHandler<T = any>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, responseFactory: MockResponseFactory<T>, loadingTime?: number | [number, number]): RequestHandler; //# sourceMappingURL=factory.d.ts.map