UNPKG

@lyxa.ai/types

Version:

Lyxa type definitions and validation schemas for both frontend and backend

162 lines (161 loc) 11.8 kB
import { z } from 'zod'; import { mongoose } from '@typegoose/typegoose'; export declare class ZodValidation { static objectIdOrStringSchema: z.ZodType<string | mongoose.Types.ObjectId, z.ZodTypeDef, string | mongoose.Types.ObjectId>; static objectId(field?: string): z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; static enumType<T extends z.EnumLike>(enumObj: T, field?: string): z.ZodNativeEnum<T>; static number(field?: string, options?: { min?: number; max?: number; isInt?: boolean; isPositive?: boolean; isNonpositive?: boolean; isNegative?: boolean; isNonnegative?: boolean; }): z.ZodNumber; static string(field?: string, options?: { minLength?: number; maxLength?: number; minMessage?: string; maxMessage?: string; requiredMessage?: string; regex?: { pattern: RegExp; message: string; }; isTrimmed?: boolean; }): z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>; static email(field?: string, options?: { requiredMessage?: string; invalidMessage?: string; }): z.ZodEffects<z.ZodString, string, string>; static url(field?: string): z.ZodString; static phoneNumber(field?: string): z.ZodEffects<z.ZodString, string, string>; static validPhoneNumber(field?: string): z.ZodEffects<z.ZodString, string, string>; static date(field?: string, minDate?: Date, maxDate?: Date): z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>; static boolean(field?: string): z.ZodBoolean; static array<T extends z.ZodTypeAny>(schema: T, field?: string, minItems?: number, maxItems?: number): z.ZodArray<T, "many">; static timestamps(): { createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>; updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>; deletedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>; }; static trackingFields(): { createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>; updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>; deletedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>; createdBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>>; updatedBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>>; deletedBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>>; }; static coerce: { number: (field?: string, options?: { min?: number; max?: number; isInt?: boolean; isPositive?: boolean; isNonpositive?: boolean; isNegative?: boolean; isNonnegative?: boolean; }) => z.ZodNumber; date: (field?: string, minDate?: Date, maxDate?: Date) => z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>; boolean: (field?: string) => z.ZodBoolean; objectId: (field?: string) => z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, mongoose.Types.ObjectId, mongoose.Types.ObjectId>; }; } export type ExcludeFromUpdate = { createdAt?: true; updatedAt?: true; deletedAt?: true; createdBy?: true; _id?: true; } & Record<string, true>; export declare class SchemaBuilder<T extends z.ZodRawShape> { private includeTimestamps; private includeTracking; private baseSchema; constructor(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean); private createBaseSchema; getBaseSchema(): z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>; getEntitySchema(): z.ZodObject<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<T_1[k]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_2 extends z.ZodRawShape ? { [k in keyof T_2]: z.ZodOptional<T_2[k]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<T_3[k]>; } : never, z.ZodTypeAny, "passthrough">>; getIdSchema(): z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; getUpdateSchema(excludeFields?: ExcludeFromUpdate): z.ZodObject<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<T_1[k]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_2 extends z.ZodRawShape ? { [k in keyof T_2]: z.ZodOptional<T_2[k]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<T_3[k]>; } : never, z.ZodTypeAny, "passthrough">> | z.ZodObject<{ [x: string]: z.ZodOptional<z.ZodTypeAny>; }, "strict", z.ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>; getDeleteSchema(): z.ZodObject<{ _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; softDelete: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { _id: mongoose.Types.ObjectId; softDelete: boolean; }, { _id: string | mongoose.Types.ObjectId; softDelete?: boolean | undefined; }>; updateBaseSchema(extendFields?: z.ZodRawShape, omitFields?: string[]): z.ZodObject<any, z.UnknownKeysParam, z.ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>; getAllSchemas(excludeFromUpdate?: ExcludeFromUpdate): { BaseSchema: z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>; EntitySchema: z.ZodObject<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_3 extends z.ZodRawShape ? { [k_2 in keyof T_3]: z.ZodOptional<T_3[k_2]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_4 extends z.ZodRawShape ? { [k_2 in keyof T_4]: z.ZodOptional<T_4[k_2]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_5 extends z.ZodRawShape ? { [k_2 in keyof T_5]: z.ZodOptional<T_5[k_2]>; } : never, z.ZodTypeAny, "passthrough">>; IdSchema: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; UpdateSchema: z.ZodObject<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_6 extends z.ZodRawShape ? { [k_2 in keyof T_6]: z.ZodOptional<T_6[k_2]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_7 extends z.ZodRawShape ? { [k_2 in keyof T_7]: z.ZodOptional<T_7[k_2]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, { _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; }> extends infer T_8 extends z.ZodRawShape ? { [k_2 in keyof T_8]: z.ZodOptional<T_8[k_2]>; } : never, z.ZodTypeAny, "passthrough">> | z.ZodObject<{ [x: string]: z.ZodOptional<z.ZodTypeAny>; }, "strict", z.ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>; DeleteSchema: z.ZodObject<{ _id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>; softDelete: z.ZodDefault<z.ZodBoolean>; }, "strip", z.ZodTypeAny, { _id: mongoose.Types.ObjectId; softDelete: boolean; }, { _id: string | mongoose.Types.ObjectId; softDelete?: boolean | undefined; }>; }; } export type DTO<T extends z.ZodType> = z.infer<T>; export type PaginatedResponse<T> = { metadata: { page: number; size: number; totalElements: number; totalPages: number; }; documents: T[]; }; export declare function createSchemaBuilder<T extends z.ZodRawShape>(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean): SchemaBuilder<T>;