/** * @file API 参数检测 * 基于 zod 实现 * @author Yourtion Guo */ import { type ZodType, z } from "zod"; import type ERest from "."; import type API from "./api"; /** * 检测是否为 Zod Schema */ export declare function isZodSchema(obj: unknown): obj is ZodType; /** * 检测是否为 ISchemaType 对象 */ export declare function isISchemaType(obj: unknown): obj is ISchemaType; /** * 检测是否为 ISchemaType 对象的集合 */ export declare function isISchemaTypeRecord(obj: unknown): obj is Record; export interface ISchemaType { type: string; comment?: string; format?: boolean; default?: unknown; required?: boolean; params?: unknown; } export interface INumericParams { min?: number; max?: number; } export interface IEnumParams extends Array { } export type IArrayParams = string | ISchemaType; export type SchemaType = ZodType; export declare const zodTypeMap: { readonly string: z.ZodString; readonly String: z.ZodString; readonly TrimString: z.ZodPipe>; readonly number: z.ZodUnion>]>; readonly Number: z.ZodUnion>]>; readonly Integer: z.ZodUnion>]>; readonly Float: z.ZodUnion>]>; readonly boolean: z.ZodUnion>]>; readonly Boolean: z.ZodUnion>]>; readonly date: z.ZodUnion>]>; readonly Date: z.ZodUnion>]>; readonly email: z.ZodString; readonly Email: z.ZodString; readonly url: z.ZodString; readonly URL: z.ZodString; readonly uuid: z.ZodString; readonly array: z.ZodArray; readonly Array: z.ZodArray; readonly Object: z.ZodAny; readonly object: z.ZodObject<{}, z.core.$strip>; readonly any: z.ZodAny; readonly Any: z.ZodAny; readonly JSON: z.ZodAny; readonly JSONString: z.ZodString; readonly ENUM: z.ZodEnum<{ placeholder: "placeholder"; }>; readonly IntArray: z.ZodUnion, z.ZodPipe>]>; readonly StringArray: z.ZodUnion, z.ZodPipe>, z.ZodPipe, z.ZodTransform>]>; readonly NullableString: z.ZodNullable; readonly NullableInteger: z.ZodNullable>]>>; readonly MongoIdString: z.ZodString; readonly Domain: z.ZodString; readonly Alpha: z.ZodString; readonly AlphaNumeric: z.ZodString; readonly Ascii: z.ZodString; readonly Base64: z.ZodString; }; export declare function createZodSchema(typeInfo: ISchemaType | string): ZodType; export declare function paramsChecker(ctx: ERest, name: string, input: unknown, typeInfo: ISchemaType): unknown; export declare function schemaChecker>(ctx: ERest, data: T, schema: SchemaType | Record, requiredOneOf?: string[]): Record; export declare function responseChecker>(_ctx: ERest, data: T, schema: ISchemaType | SchemaType | Record): T | { ok: boolean; message: string; value: unknown; }; /** * API 参数检查 */ export declare function apiParamsCheck(ctx: ERest, schema: API, params?: Record, query?: Record, body?: Record, headers?: Record): Record;