UNPKG

zomoc

Version:

A type-safe API mocking tool for frontend development, powered by axios and Zod.

160 lines (157 loc) 6.08 kB
import { ZodType } from 'zod'; type PaginationOptions = { itemsKey: string; totalKey: string; pageKey?: string; sizeKey?: string; }; /** * Core options shared between different Zomoc environments (CLI, Vite plugin). * @description Zomoc의 다양한 환경(CLI, Vite 플러그인)에서 공유되는 핵심 옵션입니다. */ interface ZomocCoreOptions { /** * Glob patterns for mock definition files (e.g., `mock.json`). * @description Mock 정의 파일(예: `mock.json`)을 찾기 위한 Glob 패턴입니다. */ mockPaths?: string[]; /** * Glob patterns for TypeScript interface files to be scanned. * @description 스캔할 타입스크립트 인터페이스 파일을 찾기 위한 Glob 패턴입니다. */ interfacePaths?: string[]; } /** * Options specific to the Zomoc Vite plugin. * @description Zomoc Vite 플러그인에 특화된 옵션입니다. */ interface ZomocVitePluginOptions extends ZomocCoreOptions { } /** * A map of custom generator functions to override default data generation for primitive types. * @description 원시 타입에 대한 기본 데이터 생성을 재정의하기 위한 커스텀 생성기 함수 맵입니다. */ interface CustomGenerators { /** * A custom function to generate strings. It receives the property key for context-aware generation. * @description 문자열을 생성하는 커스텀 함수. 문맥에 맞는 생성을 위해 속성의 키를 전달받습니다. */ string?: (key: string) => string; /** * A custom function to generate numbers. * @description 숫자를 생성하는 커스텀 함수. */ number?: () => number; /** * A custom function to generate booleans. * @description 불리언 값을 생성하는 커스텀 함수. */ boolean?: () => boolean; /** * A custom function to generate date-time strings. * @description 날짜-시간 문자열을 생성하는 커스텀 함수. */ dateTime?: () => string; } /** * Represents the configuration for a single mocked endpoint in the URL-based registry. * @description URL 기반 레지스트리에서 단일 Mock 엔드포인트에 대한 설정을 나타냅니다. */ interface RegistryValue { /** * The Zod schema for the response type. * @description 응답 타입에 대한 Zod 스키마. */ schema?: ZodType; /** * A direct response body to be returned, bypassing schema generation. * @description 스키마 생성을 건너뛰고 직접 반환될 응답 본문입니다. */ responseBody?: any; /** * The HTTP status code of the mock response. * @description 모의 응답의 HTTP 상태 코드입니다. */ status: number; /** * Configuration for paginated responses. If present, the interceptor will generate paginated mock data. * @description 페이지네이션 응답에 대한 설정. 이 값이 있으면 인터셉터가 페이지네이션된 Mock 데이터를 생성합니다. */ pagination?: PaginationOptions; /** * The data generation strategy. 'random' (default) or 'fixed' (for predictable data). * @description 데이터 생성 전략. 'random'(기본값) 또는 'fixed'(예측 가능한 데이터). */ strategy?: "random" | "fixed"; /** * The number of items to generate for array types when pagination is not used. * @description 페이지네이션을 사용하지 않을 때, 배열 타입에 대해 생성할 항목의 수. */ repeatCount?: number; } /** * @deprecated This type is kept for backward compatibility but might be removed. */ type MockDataRegistry = Record<string, RegistryValue>; /** * A registry used by the axios interceptor, mapping URL patterns to their mock configurations. * @example ` { 'POST /api/users': { schema: iUserSchema, ... } } ` * @description axios 인터셉터가 사용하는 레지스트리로, URL 패턴을 Mock 설정에 매핑합니다. */ type UrlRegistry = Record<string, RegistryValue>; /** * A registry used by the standalone generator, mapping interface names to their Zod schemas. * @example ` { 'IUser': iUserSchema, 'IProduct': iProductSchema } ` * @description 독립 실행형 생성기가 사용하는 레지스트리로, 인터페이스 이름을 Zod 스키마에 매핑합니다. */ type TypeRegistry = Record<string, ZodType>; /** * Configuration options for setting up the mock interceptor. * @description Mock 인터셉터 설정을 위한 옵션 객체입니다. */ interface SetupMockingInterceptorOptions { /** * @description Whether to enable the mocking interceptor. * @default true */ enabled?: boolean; /** * @description The URL-based registry generated by Zomoc's core engine. */ registry: UrlRegistry; /** * @description Enables detailed logging for mocked requests. * @default false */ debug?: boolean; /** * @description A map of custom generator functions to override default data generation. */ customGenerators?: CustomGenerators; } /** * @description 'responses' 맵 내의 단일 응답 정의를 위한 설정 객체입니다. */ type ResponseDefinition = { responseType?: string; responseBody?: any; pagination?: PaginationOptions; repeatCount?: number; mockingStrategy?: "fixed" | "random"; }; /** * '응답 맵 모드'를 사용할 때 API 엔드포인트에 대한 메인 설정 객체입니다. */ type ResponseMap = { status: number; responses: { [statusCode: string]: ResponseDefinition; }; }; /** * 처리되기 전, mock.json의 URL 패턴에 연결된 값입니다. */ type MockConfig = string | (Omit<ResponseDefinition, "responseBody"> & { status?: number; }) | ResponseMap; export type { CustomGenerators, MockConfig, MockDataRegistry, PaginationOptions, RegistryValue, ResponseDefinition, ResponseMap, SetupMockingInterceptorOptions, TypeRegistry, UrlRegistry, ZomocCoreOptions, ZomocVitePluginOptions };