zomoc
Version:
A type-safe API mocking tool for frontend development, powered by axios and Zod.
40 lines (36 loc) • 2.28 kB
text/typescript
import { SetupMockingInterceptorOptions, TypeRegistry, CustomGenerators, PaginationOptions } from './types.cjs';
export { RegistryValue } from './types.cjs';
import { AxiosInstance } from 'axios';
import { z } from 'zod';
/**
* Sets up an axios request interceptor to mock API responses.
* When an outgoing request matches a URL pattern in the registry, the interceptor
* hijacks the request and returns a mock response generated from the associated Zod schema,
* instead of making an actual network call.
* @description API 응답을 모킹하기 위한 axios 요청 인터셉터를 설정합니다.
* 나가는 요청이 레지스트리에 등록된 URL 패턴과 일치하면, 인터셉터는 실제 네트워크 호출 대신
* 연결된 Zod 스키마로부터 생성된 Mock 응답을 반환합니다.
*
* @param instance - The axios instance to attach the interceptor to.
* @param options - Configuration options for the interceptor.
*/
declare function setupMockingInterceptor(instance: AxiosInstance, options: SetupMockingInterceptorOptions): void;
/**
* Creates a fully type-safe mock data generator based on a provided Zod schema registry.
* This function is the entry point for using Zomoc's standalone generator.
* @description 제공된 Zod 스키마 레지스트리를 기반으로, 완벽하게 타입이 보장되는 Mock 데이터 생성기를 만듭니다.
* 이 함수는 Zomoc의 독립 실행형 생성기를 사용하기 위한 진입점입니다.
*
* @param typeRegistry - A map where keys are interface names (e.g., 'IUser') and values are the corresponding Zod schemas.
* This is typically the `finalSchemaTypeMap` generated by Zomoc's core engine.
* @param customGenerators - Optional custom data generators to override default behavior.
* @returns A `getZomocGenerator` function, ready to create mock data.
*/
declare function createGenerator<T extends TypeRegistry>(typeRegistry: T, customGenerators?: CustomGenerators): <K extends keyof T>(typeName: K, options?: {
pagination?: PaginationOptions;
repeatCount?: number;
strategy?: "fixed" | "random";
page?: number;
size?: number;
}) => z.infer<T[K]>;
export { CustomGenerators, SetupMockingInterceptorOptions, createGenerator, setupMockingInterceptor };