@lyxa.ai/core 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/libraries/auth/index.js +1 -1
  3. package/dist/libraries/auth/index.js.map +1 -1
  4. package/dist/libraries/mongo/index.js +2 -0
  5. package/dist/libraries/mongo/index.js.map +1 -1
  6. package/dist/libraries/mongo/models/address.model.d.ts +19 -0
  7. package/dist/libraries/mongo/models/address.model.js +91 -0
  8. package/dist/libraries/mongo/models/address.model.js.map +1 -0
  9. package/dist/libraries/mongo/models/duration.model.d.ts +4 -0
  10. package/dist/libraries/mongo/models/duration.model.js +27 -0
  11. package/dist/libraries/mongo/models/duration.model.js.map +1 -0
  12. package/dist/libraries/mongo/models/work-hour.model.d.ts +5 -6
  13. package/dist/libraries/mongo/models/work-hour.model.js +14 -10
  14. package/dist/libraries/mongo/models/work-hour.model.js.map +1 -1
  15. package/dist/libraries/mongo/plugins/soft-delete-plugin.d.ts +25 -0
  16. package/dist/libraries/mongo/plugins/soft-delete-plugin.js +90 -0
  17. package/dist/libraries/mongo/plugins/soft-delete-plugin.js.map +1 -0
  18. package/dist/libraries/redis/index.js +1 -1
  19. package/dist/libraries/redis/index.js.map +1 -1
  20. package/dist/libraries/secrets/index.js +1 -0
  21. package/dist/libraries/secrets/index.js.map +1 -1
  22. package/dist/utilities/enum.d.ts +8 -0
  23. package/dist/utilities/enum.js +11 -1
  24. package/dist/utilities/enum.js.map +1 -1
  25. package/dist/utilities/validation/common-validation.d.ts +233 -36
  26. package/dist/utilities/validation/common-validation.js +44 -16
  27. package/dist/utilities/validation/common-validation.js.map +1 -1
  28. package/dist/utilities/validation/global-validation.d.ts +51 -43
  29. package/dist/utilities/validation/global-validation.js +102 -50
  30. package/dist/utilities/validation/global-validation.js.map +1 -1
  31. package/package.json +1 -1
@@ -1,17 +1,25 @@
1
- import { z } from 'zod';
2
- import { mongoose } from '@typegoose/typegoose';
1
+ import { z } from "zod";
2
+ import { mongoose } from "@typegoose/typegoose";
3
3
  export declare class ZodValidation {
4
- static objectId(field?: string): z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
4
+ 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>]>;
5
5
  static enumType<T extends z.EnumLike>(enumObj: T, field?: string): z.ZodNativeEnum<T>;
6
- static number(field?: string, minLength?: number): z.ZodNumber;
7
- static string(field?: string, minLength?: number): z.ZodString;
6
+ static number(field?: string, min?: number, max?: number, options?: {
7
+ isInt?: boolean;
8
+ isPositive?: boolean;
9
+ isNonpositive?: boolean;
10
+ isNegative?: boolean;
11
+ isNonnegative?: boolean;
12
+ }): z.ZodNumber;
13
+ static string(field?: string, minLength?: number, maxLength?: number, regex?: {
14
+ pattern: RegExp;
15
+ message: string;
16
+ }): z.ZodString;
8
17
  static email(field?: string): z.ZodString;
9
18
  static url(field?: string): z.ZodString;
10
19
  static phoneNumber(field?: string): z.ZodString;
11
- static dateString(field?: string): z.ZodEffects<z.ZodString, string, string>;
12
- static date(field?: string): z.ZodDate;
20
+ 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>;
13
21
  static boolean(field?: string): z.ZodBoolean;
14
- static array<T extends z.ZodTypeAny>(schema: T, field?: string, minItems?: number): z.ZodArray<T, "many">;
22
+ static array<T extends z.ZodTypeAny>(schema: T, field?: string, minItems?: number, maxItems?: number): z.ZodArray<T, "many">;
15
23
  static timestamps(): {
16
24
  createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
17
25
  updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
@@ -21,9 +29,9 @@ export declare class ZodValidation {
21
29
  createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
22
30
  updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
23
31
  deletedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
24
- createdBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>>;
25
- updatedBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>>;
26
- deletedBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>>;
32
+ 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>]>>;
33
+ 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>]>>;
34
+ 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>]>>;
27
35
  };
28
36
  }
29
37
  export type ExcludeFromUpdate = {
@@ -40,37 +48,37 @@ export declare class SchemaBuilder<T extends z.ZodRawShape> {
40
48
  constructor(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean);
41
49
  getBaseSchema(): z.ZodObject<T, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>;
42
50
  getEntitySchema(): z.ZodObject<z.objectUtil.extendShape<T, {
43
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
51
+ _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>]>;
44
52
  }>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
45
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
53
+ _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>]>;
46
54
  }>>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
47
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
55
+ _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>]>;
48
56
  }>>, any>[k]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<T, {
49
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
57
+ _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>]>;
50
58
  }>> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<z.objectUtil.extendShape<T, {
51
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
59
+ _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>]>;
52
60
  }>>[k_1]; } : never>;
53
- getIdSchema(): z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
61
+ 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>]>;
54
62
  getUpdateSchema(excludeFields?: ExcludeFromUpdate): z.ZodObject<z.objectUtil.extendShape<T, {
55
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
63
+ _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>]>;
56
64
  }> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<z.objectUtil.extendShape<T, {
57
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
65
+ _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>]>;
58
66
  }>[k]>; } : never, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
59
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
67
+ _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>]>;
60
68
  }> extends infer T_4 extends z.ZodRawShape ? { [k in keyof T_4]: z.ZodOptional<z.objectUtil.extendShape<T, {
61
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
69
+ _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>]>;
62
70
  }>[k]>; } : never>, any> extends infer T_2 ? { [k_1 in keyof T_2]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
63
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
71
+ _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>]>;
64
72
  }> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
65
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
73
+ _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>]>;
66
74
  }>[k]>; } : never>, any>[k_1]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<T, {
67
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
75
+ _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>]>;
68
76
  }> extends infer T_7 extends z.ZodRawShape ? { [k in keyof T_7]: z.ZodOptional<z.objectUtil.extendShape<T, {
69
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
77
+ _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>]>;
70
78
  }>[k]>; } : never> extends infer T_5 ? { [k_2 in keyof T_5]: z.baseObjectInputType<z.objectUtil.extendShape<T, {
71
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
79
+ _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>]>;
72
80
  }> extends infer T_6 extends z.ZodRawShape ? { [k in keyof T_6]: z.ZodOptional<z.objectUtil.extendShape<T, {
73
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
81
+ _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>]>;
74
82
  }>[k]>; } : never>[k_2]; } : never> | z.ZodObject<{
75
83
  [x: string]: z.ZodOptional<z.ZodTypeAny>;
76
84
  }, "strip", z.ZodTypeAny, {
@@ -81,37 +89,37 @@ export declare class SchemaBuilder<T extends z.ZodRawShape> {
81
89
  getAllSchemas(excludeFromUpdate?: ExcludeFromUpdate): {
82
90
  BaseSchema: z.ZodObject<T, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>;
83
91
  EntitySchema: z.ZodObject<z.objectUtil.extendShape<T, {
84
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
92
+ _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>]>;
85
93
  }>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
86
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
94
+ _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>]>;
87
95
  }>>, any> extends infer T_3 ? { [k_2 in keyof T_3]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
88
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
96
+ _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>]>;
89
97
  }>>, any>[k_2]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<T, {
90
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
98
+ _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>]>;
91
99
  }>> extends infer T_4 ? { [k_3 in keyof T_4]: z.baseObjectInputType<z.objectUtil.extendShape<T, {
92
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
100
+ _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>]>;
93
101
  }>>[k_3]; } : never>;
94
- IdSchema: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
102
+ 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>]>;
95
103
  UpdateSchema: z.ZodObject<z.objectUtil.extendShape<T, {
96
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
104
+ _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>]>;
97
105
  }> extends infer T_5 extends z.ZodRawShape ? { [k_4 in keyof T_5]: z.ZodOptional<z.objectUtil.extendShape<T, {
98
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
106
+ _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>]>;
99
107
  }>[k_4]>; } : never, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
100
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
108
+ _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>]>;
101
109
  }> extends infer T_8 extends z.ZodRawShape ? { [k_4 in keyof T_8]: z.ZodOptional<z.objectUtil.extendShape<T, {
102
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
110
+ _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>]>;
103
111
  }>[k_4]>; } : never>, any> extends infer T_6 ? { [k_5 in keyof T_6]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<T, {
104
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
112
+ _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>]>;
105
113
  }> extends infer T_7 extends z.ZodRawShape ? { [k_4 in keyof T_7]: z.ZodOptional<z.objectUtil.extendShape<T, {
106
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
114
+ _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>]>;
107
115
  }>[k_4]>; } : never>, any>[k_5]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<T, {
108
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
116
+ _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>]>;
109
117
  }> extends infer T_11 extends z.ZodRawShape ? { [k_4 in keyof T_11]: z.ZodOptional<z.objectUtil.extendShape<T, {
110
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
118
+ _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>]>;
111
119
  }>[k_4]>; } : never> extends infer T_9 ? { [k_6 in keyof T_9]: z.baseObjectInputType<z.objectUtil.extendShape<T, {
112
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
120
+ _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>]>;
113
121
  }> extends infer T_10 extends z.ZodRawShape ? { [k_4 in keyof T_10]: z.ZodOptional<z.objectUtil.extendShape<T, {
114
- _id: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>, string, mongoose.Types.ObjectId>]>;
122
+ _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>]>;
115
123
  }>[k_4]>; } : never>[k_6]; } : never> | z.ZodObject<{
116
124
  [x: string]: z.ZodOptional<z.ZodTypeAny>;
117
125
  }, "strip", z.ZodTypeAny, {
@@ -5,75 +5,127 @@ exports.createSchemaBuilder = createSchemaBuilder;
5
5
  const zod_1 = require("zod");
6
6
  const typegoose_1 = require("@typegoose/typegoose");
7
7
  class ZodValidation {
8
- static objectId(field = 'Field') {
8
+ static objectId(field = "Field") {
9
9
  return zod_1.z.union([
10
- zod_1.z.string().refine(val => typegoose_1.mongoose.Types.ObjectId.isValid(val), {
11
- message: `Invalid ${field} ObjectID format`,
12
- }),
13
- zod_1.z.instanceof(typegoose_1.mongoose.Types.ObjectId).transform(val => val.toString()),
14
- ]);
15
- }
16
- static enumType(enumObj, field = 'Field') {
10
+ zod_1.z
11
+ .string({ required_error: `${field} is required` })
12
+ .refine((val) => typegoose_1.mongoose.Types.ObjectId.isValid(val), {
13
+ message: `${field} must be a valid ObjectID`
14
+ })
15
+ .transform((val) => new typegoose_1.mongoose.Types.ObjectId(val)),
16
+ zod_1.z.instanceof(typegoose_1.mongoose.Types.ObjectId, {
17
+ message: `${field} must be a valid ObjectID`
18
+ })
19
+ ], { message: `${field} is required` });
20
+ }
21
+ static enumType(enumObj, field = "Field") {
17
22
  return zod_1.z.nativeEnum(enumObj, {
18
- message: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,
23
+ message: `${field} must be one of: ${Object.values(enumObj).join(", ")}`
24
+ });
25
+ }
26
+ static number(field = "Field", min, max, options) {
27
+ let schema = zod_1.z.number({
28
+ required_error: `${field} is required`,
29
+ invalid_type_error: `${field} must be a number`
19
30
  });
31
+ if (min !== undefined) {
32
+ schema = schema.gte(min, { message: `${field} must be at least ${min}` });
33
+ }
34
+ if (max !== undefined) {
35
+ schema = schema.lte(max, { message: `${field} must be at most ${max}` });
36
+ }
37
+ if (options?.isInt) {
38
+ schema = schema.int({ message: `${field} must be an integer` });
39
+ }
40
+ if (options?.isPositive) {
41
+ schema = schema.positive({ message: `${field} must be positive` });
42
+ }
43
+ if (options?.isNonpositive) {
44
+ schema = schema.nonpositive({ message: `${field} must be non-positive` });
45
+ }
46
+ if (options?.isNegative) {
47
+ schema = schema.negative({ message: `${field} must be negative` });
48
+ }
49
+ if (options?.isNonnegative) {
50
+ schema = schema.nonnegative({ message: `${field} must be non-negative` });
51
+ }
52
+ return schema;
20
53
  }
21
- static number(field = 'Field', minLength) {
22
- const numberSchema = zod_1.z.number({
54
+ static string(field = "Field", minLength, maxLength, regex) {
55
+ let schema = zod_1.z.string({
23
56
  required_error: `${field} is required`,
24
- invalid_type_error: `${field} must be a number`,
57
+ invalid_type_error: `${field} must be a string`
25
58
  });
26
- return minLength !== undefined
27
- ? numberSchema.min(minLength, `${field} value must be greater than or equal to ${minLength}`)
28
- : numberSchema;
29
- }
30
- static string(field = 'Field', minLength) {
31
- const stringSchema = zod_1.z
32
- .string({ required_error: `${field} is required`, invalid_type_error: `${field} must be a string` })
33
- .trim();
34
- return minLength !== undefined
35
- ? stringSchema.min(minLength, `${field} value length must be greater than or equal to ${minLength}`)
36
- : stringSchema;
37
- }
38
- static email(field = 'Field') {
59
+ if (minLength !== undefined) {
60
+ schema = schema.min(minLength, `${field} value length must be greater than or equal to ${minLength}`);
61
+ }
62
+ if (maxLength !== undefined) {
63
+ schema = schema.max(maxLength, `${field} value length must be less than or equal to ${maxLength}`);
64
+ }
65
+ if (regex !== undefined) {
66
+ schema = schema.regex(regex.pattern, regex.message);
67
+ }
68
+ return schema;
69
+ }
70
+ static email(field = "Field") {
39
71
  return zod_1.z
40
72
  .string({ required_error: `${field} is required` })
41
73
  .email(`${field} must be a valid email address`);
42
74
  }
43
- static url(field = 'Field') {
44
- return zod_1.z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);
75
+ static url(field = "Field") {
76
+ return zod_1.z
77
+ .string({ required_error: `${field} is required` })
78
+ .url(`${field} must be a valid URL`);
45
79
  }
46
- static phoneNumber(field = 'Field') {
80
+ static phoneNumber(field = "Field") {
47
81
  return zod_1.z
48
82
  .string({ required_error: `${field} is required` })
49
83
  .regex(/^[+]{1}(?:[0-9\-\\(\\)\\/.]\s?){6,15}[0-9]{1}$/, `${field} must be a valid phone number`);
50
84
  }
51
- static dateString(field = 'Field') {
52
- return zod_1.z.string({ required_error: `${field} is required` }).refine(val => !isNaN(Date.parse(val)), {
53
- message: `${field} must be a valid date format`,
54
- });
55
- }
56
- static date(field = 'Field') {
57
- return zod_1.z.date({
58
- required_error: `${field} is required`,
59
- invalid_type_error: `${field} must be a date`,
60
- });
61
- }
62
- static boolean(field = 'Field') {
85
+ static date(field = "Field", minDate, maxDate) {
86
+ return zod_1.z
87
+ .union([
88
+ zod_1.z
89
+ .string({ required_error: `${field} is required` })
90
+ .refine((val) => {
91
+ const date = new Date(val);
92
+ return !isNaN(date.getTime());
93
+ }, `${field} must be a valid date`)
94
+ .transform((val) => new Date(val)),
95
+ zod_1.z.date({
96
+ required_error: `${field} is required`,
97
+ invalid_type_error: `${field} must be a valid date`
98
+ })
99
+ ], { message: `${field} is required` })
100
+ .refine((val) => minDate === undefined || val >= minDate, `${field} must be on or after ${minDate?.toISOString()}`)
101
+ .refine((val) => maxDate === undefined || val <= maxDate, `${field} must be on or before ${maxDate?.toISOString()}`);
102
+ }
103
+ static boolean(field = "Field") {
63
104
  return zod_1.z.boolean({
64
105
  required_error: `${field} is required`,
65
- invalid_type_error: `${field} must be a boolean`,
106
+ invalid_type_error: `${field} must be a boolean`
66
107
  });
67
108
  }
68
- static array(schema, field = 'Array', minItems) {
69
- const arraySchema = zod_1.z.array(schema);
70
- return minItems !== undefined ? arraySchema.min(minItems, `${field} cannot be empty`) : arraySchema;
109
+ static array(schema, field = "Array", minItems, maxItems) {
110
+ let arraySchema = zod_1.z.array(schema, {
111
+ required_error: `${field} is required`
112
+ });
113
+ if (minItems === 1) {
114
+ arraySchema = arraySchema.min(1, `${field} cannot be empty`);
115
+ }
116
+ if (minItems !== undefined && minItems !== 1) {
117
+ arraySchema = arraySchema.min(minItems, `${field} must have at least ${minItems} items`);
118
+ }
119
+ if (maxItems !== undefined) {
120
+ arraySchema = arraySchema.max(maxItems, `${field} must have at most ${maxItems} items`);
121
+ }
122
+ return arraySchema;
71
123
  }
72
124
  static timestamps() {
73
125
  return {
74
126
  createdAt: zod_1.z.date().nullable().optional(),
75
127
  updatedAt: zod_1.z.date().nullable().optional(),
76
- deletedAt: zod_1.z.date().nullable().optional(),
128
+ deletedAt: zod_1.z.date().nullable().optional()
77
129
  };
78
130
  }
79
131
  static trackingFields() {
@@ -81,7 +133,7 @@ class ZodValidation {
81
133
  createdBy: ZodValidation.objectId().optional(),
82
134
  updatedBy: ZodValidation.objectId().optional(),
83
135
  deletedBy: ZodValidation.objectId().optional(),
84
- ...ZodValidation.timestamps(),
136
+ ...ZodValidation.timestamps()
85
137
  };
86
138
  }
87
139
  }
@@ -96,13 +148,13 @@ class SchemaBuilder {
96
148
  if (includeTracking) {
97
149
  this.baseSchema = zod_1.z.object({
98
150
  ...baseFields,
99
- ...ZodValidation.trackingFields(),
151
+ ...ZodValidation.trackingFields()
100
152
  });
101
153
  }
102
154
  else if (includeTimestamps) {
103
155
  this.baseSchema = zod_1.z.object({
104
156
  ...baseFields,
105
- ...ZodValidation.timestamps(),
157
+ ...ZodValidation.timestamps()
106
158
  });
107
159
  }
108
160
  else {
@@ -114,7 +166,7 @@ class SchemaBuilder {
114
166
  }
115
167
  getEntitySchema() {
116
168
  return this.baseSchema.extend({
117
- _id: ZodValidation.objectId(),
169
+ _id: ZodValidation.objectId()
118
170
  });
119
171
  }
120
172
  getIdSchema() {
@@ -139,7 +191,7 @@ class SchemaBuilder {
139
191
  BaseSchema: this.getBaseSchema(),
140
192
  EntitySchema: this.getEntitySchema(),
141
193
  IdSchema: this.getIdSchema(),
142
- UpdateSchema: this.getUpdateSchema(excludeFromUpdate),
194
+ UpdateSchema: this.getUpdateSchema(excludeFromUpdate)
143
195
  };
144
196
  }
145
197
  }
@@ -1 +1 @@
1
- {"version":3,"file":"global-validation.js","sourceRoot":"/","sources":["utilities/validation/global-validation.ts"],"names":[],"mappings":";;;AAqiBA,kDAMC;AA3iBD,6BAAwB;AACxB,oDAAgD;AAehD,MAAa,aAAa;IAczB,MAAM,CAAC,QAAQ,CAAC,QAAgB,OAAO;QACtC,OAAO,OAAC,CAAC,KAAK,CAAC;YACd,OAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAQ,CAAC,KAAK,CAAC,QA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C,OAAO,EAAE,CAAC;IAC1C,CAAC;IAmBD,aAAa,CAAC,oBAAuC,EAAE,SAAS,EAAE,IAAI,EAAE;QACvE,OAAO;YACN,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE;YAC5B,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC;SACrD,CAAC;IACH,CAAC;CACD;AAlKD,sCAkKC;AAyED,SAAgB,mBAAmB,CAClC,UAAa,EACb,oBAA6B,IAAI,EACjC,kBAA2B,KAAK;IAEhC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import { z } from 'zod';\r\nimport { mongoose } from '@typegoose/typegoose';\r\n\r\n/**\r\n * Enhanced validation utilities for creating robust Zod schemas.\r\n * This class provides a collection of static methods to create common validation patterns.\r\n *\r\n * @example\r\n * ```typescript\r\n * const userSchema = z.object({\r\n * username: ZodValidation.requiredString(\"Username is required\"),\r\n * email: ZodValidation.email(),\r\n * role: ZodValidation.enumType(UserRole)\r\n * });\r\n * ```\r\n */\r\nexport class ZodValidation {\r\n\t/**\r\n\t * Creates a union type that accepts both string ObjectId and mongoose ObjectId instance.\r\n\t * This is useful when dealing with both raw string IDs and Mongoose ObjectId instances.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod union schema that accepts both string and ObjectId\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const idSchema = ZodValidation.objectIdUnion();\r\n\t * // Accepts \"507f1f77bcf86cd799439011\" or new mongoose.Types.ObjectId(\"507f1f77bcf86cd799439011\")\r\n\t * ```\r\n\t */\r\n\tstatic objectId(field: string = 'Field') {\r\n\t\treturn z.union([\r\n\t\t\tz.string().refine(val => mongoose.Types.ObjectId.isValid(val), {\r\n\t\t\t\tmessage: `Invalid ${field} ObjectID format`,\r\n\t\t\t}),\r\n\t\t\tz.instanceof(mongoose.Types.ObjectId).transform(val => val.toString()),\r\n\t\t]);\r\n\t}\r\n\r\n\t/**\r\n\t * Creates an enum validation with custom error message.\r\n\t * This validates that a value is one of the values defined in the enum.\r\n\t *\r\n\t * @template T - Type of the enum\r\n\t * @param enumObj - The enum object to validate against\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates against the provided enum\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * enum UserRole { ADMIN = \"admin\", USER = \"user\" }\r\n\t * const roleSchema = ZodValidation.enumType(UserRole, \"Invalid user role\");\r\n\t * ```\r\n\t */\r\n\tstatic enumType<T extends z.EnumLike>(enumObj: T, field: string = 'Field') {\r\n\t\treturn z.nativeEnum(enumObj, {\r\n\t\t\tmessage: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a required number validation with a minimum length.\r\n\t * The number is also trimmed to remove leading/trailing whitespace.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @param minLength - Minimum required length (default: 1)\r\n\t * @returns A Zod schema that validates numbers with minimum length\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const nameSchema = ZodValidation.Number(\"Price\");\r\n\t * ```\r\n\t */\r\n\tstatic number(field: string = 'Field', minLength?: number) {\r\n\t\tconst numberSchema = z.number({\r\n\t\t\trequired_error: `${field} is required`,\r\n\t\t\tinvalid_type_error: `${field} must be a number`,\r\n\t\t});\r\n\t\treturn minLength !== undefined\r\n\t\t\t? numberSchema.min(minLength, `${field} value must be greater than or equal to ${minLength}`)\r\n\t\t\t: numberSchema;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a required string validation with a minimum length.\r\n\t * The string is also trimmed to remove leading/trailing whitespace.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @param minLength - Minimum required length (default: 1)\r\n\t * @returns A Zod schema that validates strings with minimum length\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const nameSchema = ZodValidation.String(\"Name\");\r\n\t * ```\r\n\t */\r\n\tstatic string(field: string = 'Field', minLength?: number) {\r\n\t\tconst stringSchema = z\r\n\t\t\t.string({ required_error: `${field} is required`, invalid_type_error: `${field} must be a string` })\r\n\t\t\t.trim();\r\n\r\n\t\treturn minLength !== undefined\r\n\t\t\t? stringSchema.min(minLength, `${field} value length must be greater than or equal to ${minLength}`)\r\n\t\t\t: stringSchema;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates an email validation.\r\n\t * Validates that the string is a valid email address format.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates email addresses\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const emailSchema = ZodValidation.email(\"Please enter a valid email\");\r\n\t * ```\r\n\t */\r\n\tstatic email(field: string = 'Field') {\r\n\t\treturn z\r\n\t\t\t.string({ required_error: `${field} is required` })\r\n\t\t\t.email(`${field} must be a valid email address`);\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a URL validation.\r\n\t * Validates that the string is a valid URL format.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates URLs\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const websiteSchema = ZodValidation.url(\"Please enter a valid URL\");\r\n\t * ```\r\n\t */\r\n\tstatic url(field: string = 'Field') {\r\n\t\treturn z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a phone number validation schema using a regex pattern for global phone numbers.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates phone numbers\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const phoneSchema = ZodValidation.phoneNumber(\"Phone number\");\r\n\t * ```\r\n\t */\r\n\tstatic phoneNumber(field: string = 'Field') {\r\n\t\treturn z\r\n\t\t\t.string({ required_error: `${field} is required` })\r\n\t\t\t.regex(/^[+]{1}(?:[0-9\\-\\\\(\\\\)\\\\/.]\\s?){6,15}[0-9]{1}$/, `${field} must be a valid phone number`);\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a date string validation that ensures the input is a valid date.\r\n\t * Validates that the string can be parsed as a valid date.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates date strings\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const birthDateSchema = ZodValidation.dateString(\"Please enter a valid date\");\r\n\t * ```\r\n\t */\r\n\tstatic dateString(field: string = 'Field') {\r\n\t\treturn z.string({ required_error: `${field} is required` }).refine(val => !isNaN(Date.parse(val)), {\r\n\t\t\tmessage: `${field} must be a valid date format`,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a date validation.\r\n\t * Validates that the input is a JavaScript Date object.\r\n\t *@param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates Date objects\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const createdAtSchema = ZodValidation.date();\r\n\t * ```\r\n\t */\r\n\tstatic date(field: string = 'Field') {\r\n\t\treturn z.date({\r\n\t\t\trequired_error: `${field} is required`,\r\n\t\t\tinvalid_type_error: `${field} must be a date`,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a boolean validation with an optional default value.\r\n\t *\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @returns A Zod schema that validates booleans\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const isActiveSchema = ZodValidation.boolean(true); // Defaults to true\r\n\t * ```\r\n\t */\r\n\tstatic boolean(field: string = 'Field') {\r\n\t\treturn z.boolean({\r\n\t\t\trequired_error: `${field} is required`,\r\n\t\t\tinvalid_type_error: `${field} must be a boolean`,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Creates an array validation with optional minimum items constraint.\r\n\t *\r\n\t * @template T - Type of the schema for array items\r\n\t * @param schema - The schema for validating array items\r\n\t * @param field - The name of the field to be included in the error message\r\n\t * @param minItems - Minimum number of items required (optional)\r\n\t * @returns A Zod schema that validates arrays\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const tagsSchema = ZodValidation.array(z.string(), \"At least one tag required\", 1);\r\n\t * ```\r\n\t */\r\n\tstatic array<T extends z.ZodTypeAny>(schema: T, field: string = 'Array', minItems?: number) {\r\n\t\tconst arraySchema = z.array(schema);\r\n\t\treturn minItems !== undefined ? arraySchema.min(minItems, `${field} cannot be empty`) : arraySchema;\r\n\t}\r\n\r\n\t/**\r\n\t * Standard timestamp fields for entities.\r\n\t * Includes createdAt, updatedAt, and deletedAt fields.\r\n\t *\r\n\t * @returns An object containing timestamp field schemas\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const userSchema = z.object({\r\n\t * name: z.string(),\r\n\t * ...ZodValidation.timestamps()\r\n\t * });\r\n\t * ```\r\n\t */\r\n\tstatic timestamps() {\r\n\t\treturn {\r\n\t\t\tcreatedAt: z.date().nullable().optional(),\r\n\t\t\tupdatedAt: z.date().nullable().optional(),\r\n\t\t\tdeletedAt: z.date().nullable().optional(),\r\n\t\t};\r\n\t}\r\n\r\n\t/**\r\n\t * Common fields for tracking model metadata.\r\n\t * Includes timestamps and user tracking fields (createdBy, updatedBy, deletedBy).\r\n\t *\r\n\t * @returns An object containing tracking field schemas\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const postSchema = z.object({\r\n\t * title: z.string(),\r\n\t * content: z.string(),\r\n\t * ...ZodValidation.trackingFields()\r\n\t * });\r\n\t * ```\r\n\t */\r\n\tstatic trackingFields() {\r\n\t\treturn {\r\n\t\t\tcreatedBy: ZodValidation.objectId().optional(),\r\n\t\t\tupdatedBy: ZodValidation.objectId().optional(),\r\n\t\t\tdeletedBy: ZodValidation.objectId().optional(),\r\n\t\t\t...ZodValidation.timestamps(),\r\n\t\t};\r\n\t}\r\n}\r\n\r\n/**\r\n * Represents the common fields to exclude from update operations.\r\n * This is used to specify which fields should not be updateable.\r\n *\r\n * @example\r\n * ```typescript\r\n * const excludeFields: ExcludeFromUpdate = {\r\n * createdAt: true,\r\n * createdBy: true,\r\n * status: true // Prevent status from being updated\r\n * };\r\n * ```\r\n */\r\nexport type ExcludeFromUpdate = {\r\n\tcreatedAt?: true;\r\n\tupdatedAt?: true;\r\n\tdeletedAt?: true;\r\n\tcreatedBy?: true;\r\n\t_id?: true;\r\n} & Record<string, true>;\r\n\r\n/**\r\n * Schema builder for creating consistent CRUD schemas.\r\n * Provides utility methods to generate schemas for create, read, update, and delete operations.\r\n *\r\n * @template T - Type of the base schema shape\r\n *\r\n * @example\r\n * ```typescript\r\n * const userBuilder = new SchemaBuilder({\r\n * name: z.string(),\r\n * email: z.string().email()\r\n * });\r\n *\r\n * const schemas = userBuilder.getAllSchemas();\r\n * ```\r\n */\r\nexport class SchemaBuilder<T extends z.ZodRawShape> {\r\n\tprivate baseSchema: z.ZodObject<T>;\r\n\r\n\t/**\r\n\t * Create a new schema builder\r\n\t *\r\n\t * @param baseFields - The base fields for the schema\r\n\t * @param includeTimestamps - Whether to include timestamp fields (default: true)\r\n\t * @param includeTracking - Whether to include tracking fields (createdBy, etc.) (default: false)\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const userFields = {\r\n\t * name: ZodValidation.requiredString(),\r\n\t * email: ZodValidation.email()\r\n\t * };\r\n\t *\r\n\t * // With timestamps\r\n\t * const builder1 = new SchemaBuilder(userFields);\r\n\t *\r\n\t * // Without timestamps\r\n\t * const builder2 = new SchemaBuilder(userFields, false);\r\n\t *\r\n\t * // With tracking fields\r\n\t * const builder3 = new SchemaBuilder(userFields, true, true);\r\n\t * ```\r\n\t */\r\n\tconstructor(\r\n\t\tbaseFields: T,\r\n\t\tprivate includeTimestamps: boolean = true,\r\n\t\tprivate includeTracking: boolean = false\r\n\t) {\r\n\t\tif (includeTracking) {\r\n\t\t\tthis.baseSchema = z.object({\r\n\t\t\t\t...baseFields,\r\n\t\t\t\t...ZodValidation.trackingFields(),\r\n\t\t\t});\r\n\t\t} else if (includeTimestamps) {\r\n\t\t\tthis.baseSchema = z.object({\r\n\t\t\t\t...baseFields,\r\n\t\t\t\t...ZodValidation.timestamps(),\r\n\t\t\t});\r\n\t\t} else {\r\n\t\t\tthis.baseSchema = z.object(baseFields);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the base validation schema without ID.\r\n\t * Used for creating new entities.\r\n\t *\r\n\t * @returns The base schema for creating new entities\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const createUserSchema = userBuilder.getBaseSchema();\r\n\t * ```\r\n\t */\r\n\tgetBaseSchema() {\r\n\t\treturn this.baseSchema;\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the schema for entities with ID.\r\n\t * Used for representing complete entities with their ID.\r\n\t *\r\n\t * @returns The entity schema including ID\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const userSchema = userBuilder.getEntitySchema();\r\n\t * ```\r\n\t */\r\n\tgetEntitySchema() {\r\n\t\treturn this.baseSchema.extend({\r\n\t\t\t_id: ZodValidation.objectId(),\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the schema for validating an entity ID.\r\n\t * Used for validating ID parameters in requests.\r\n\t *\r\n\t * @returns The ID validation schema\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const userIdSchema = userBuilder.getIdSchema();\r\n\t * ```\r\n\t */\r\n\tgetIdSchema() {\r\n\t\treturn ZodValidation.objectId();\r\n\t}\r\n\r\n\t/**\r\n\t * Gets the schema for updating an entity, excluding specified fields.\r\n\t * Creates a partial schema where all fields are optional, and removes\r\n\t * fields that should not be updateable.\r\n\t *\r\n\t * @param excludeFields - Fields to exclude from update operations\r\n\t * @returns The update schema with excluded fields removed\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * // Prevent updating createdAt and status\r\n\t * const updateUserSchema = userBuilder.getUpdateSchema({\r\n\t * createdAt: true,\r\n\t * status: true\r\n\t * });\r\n\t * ```\r\n\t */\r\n\tgetUpdateSchema(excludeFields: ExcludeFromUpdate = { createdAt: true }) {\r\n\t\tconst entitySchema = this.getEntitySchema();\r\n\r\n\t\t// Simple approach - just make everything optional\r\n\t\tif (Object.keys(excludeFields).length === 0) {\r\n\t\t\treturn entitySchema.partial();\r\n\t\t}\r\n\r\n\t\t// For the type-safe approach, we need to create a new schema\r\n\t\t// without the excluded fields and then make it partial\r\n\r\n\t\t// Get all fields from the entity schema\r\n\t\tconst shape = entitySchema._def.shape();\r\n\r\n\t\t// Filter out the fields we want to exclude\r\n\t\tconst filteredShape: z.ZodRawShape = {};\r\n\t\tfor (const key in shape) {\r\n\t\t\tif (!excludeFields[key as keyof typeof excludeFields]) {\r\n\t\t\t\tfilteredShape[key] = shape[key];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Create a new schema with the filtered fields\r\n\t\treturn z.object(filteredShape).partial();\r\n\t}\r\n\r\n\t/**\r\n\t * Gets all common schemas for an entity.\r\n\t * Returns base, entity, ID, and update schemas in a single object.\r\n\t *\r\n\t * @param excludeFromUpdate - Fields to exclude from update operations\r\n\t * @returns Object containing all schemas\r\n\t *\r\n\t * @example\r\n\t * ```typescript\r\n\t * const {\r\n\t * BaseSchema, // For creating\r\n\t * EntitySchema, // For reading\r\n\t * IdSchema, // For validating IDs\r\n\t * UpdateSchema // For updating\r\n\t * } = userBuilder.getAllSchemas();\r\n\t * ```\r\n\t */\r\n\tgetAllSchemas(excludeFromUpdate: ExcludeFromUpdate = { createdAt: true }) {\r\n\t\treturn {\r\n\t\t\tBaseSchema: this.getBaseSchema(),\r\n\t\t\tEntitySchema: this.getEntitySchema(),\r\n\t\t\tIdSchema: this.getIdSchema(),\r\n\t\t\tUpdateSchema: this.getUpdateSchema(excludeFromUpdate),\r\n\t\t};\r\n\t}\r\n}\r\n\r\n/**\r\n * Type helper for creating DTO types from creation schemas.\r\n * Used to derive the type for creating new entities.\r\n *\r\n * @template T - The schema type\r\n *\r\n * @example\r\n * ```typescript\r\n * type CreateUserDTO = CreateDTO<typeof UserValidationSchema>;\r\n * ```\r\n */\r\nexport type CreateDTO<T extends z.ZodType> = z.infer<T>;\r\n\r\n/**\r\n * Type helper for creating DTO types from entity schemas.\r\n * Used to derive the type for complete entities.\r\n *\r\n * @template T - The schema type\r\n *\r\n * @example\r\n * ```typescript\r\n * type UserDTO = EntityDTO<typeof UserSchema>;\r\n * ```\r\n */\r\nexport type EntityDTO<T extends z.ZodType> = z.infer<T>;\r\n\r\n/**\r\n * Type helper for creating DTO types from update schemas.\r\n * Used to derive the type for updating entities.\r\n *\r\n * @template T - The schema type\r\n *\r\n * @example\r\n * ```typescript\r\n * type UpdateUserDTO = UpdateDTO<typeof UpdateUserSchema>;\r\n * ```\r\n */\r\nexport type UpdateDTO<T extends z.ZodType> = z.infer<T>;\r\n\r\n/**\r\n * Type alias for ID DTOs.\r\n * Represents the type of entity IDs (string).\r\n *\r\n * @example\r\n * ```typescript\r\n * type UserIdDTO = IdDTO;\r\n * ```\r\n */\r\nexport type IdDTO = string;\r\n\r\n/**\r\n * Creates a schema builder for an entity.\r\n * Helper function to create a new SchemaBuilder instance.\r\n *\r\n * @template T - Type of the base schema shape\r\n * @param baseFields - Base fields for the entity\r\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\r\n * @param includeTracking - Whether to include tracking fields (default: false)\r\n * @returns A new SchemaBuilder instance\r\n *\r\n * @example\r\n * ```typescript\r\n * const userFields = {\r\n * name: ZodValidation.requiredString(),\r\n * email: ZodValidation.email()\r\n * };\r\n *\r\n * const userSchemaBuilder = createSchemaBuilder(userFields);\r\n * const userSchemaBuilder = createSchemaBuilder(userFields, true, true); // With tracking\r\n * ```\r\n */\r\nexport function createSchemaBuilder<T extends z.ZodRawShape>(\r\n\tbaseFields: T,\r\n\tincludeTimestamps: boolean = true,\r\n\tincludeTracking: boolean = false\r\n) {\r\n\treturn new SchemaBuilder(baseFields, includeTimestamps, includeTracking);\r\n}\r\n"]}
1
+ {"version":3,"file":"global-validation.js","sourceRoot":"/","sources":["utilities/validation/global-validation.ts"],"names":[],"mappings":";;;AA2oBA,kDAMC;AAjpBD,6BAAwB;AACxB,oDAAgD;AAehD,MAAa,aAAa;IAcxB,MAAM,CAAC,QAAQ,CAAC,QAAgB,OAAO;QACrC,OAAO,OAAC,CAAC,KAAK,CACZ;YACE,OAAC;iBACE,MAAM,CAAC,EAAE,cAAc,EAAE,GAAG,KAAK,cAAc,EAAE,CAAC;iBAClD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACrD,OAAO,EAAE,GAAG,KAAK,2BAA2B;aAC7C,CAAC;iBACD,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACvD,OAAC,CAAC,UAAU,CAAC,oBAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACpC,OAAO,EAAE,GAAG,KAAK,2BAA2B;aAC7C,CAAC;SACH,EACD,EAAE,OAAO,EAAE,GAAG,KAAK,cAAc,EAAE,CACpC,CAAC;IACJ,CAAC;IAiBD,MAAM,CAAC,QAAQ,CAAuB,OAAU,EAAE,QAAgB,OAAO;QACvE,OAAO,OAAC,CAAC,UAAU,CAAC,OAAO,EAAE;YAC3B,OAAO,EAAE,GAAG,KAAK,oBAAoB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACzE,CAAC,CAAC;IACL,CAAC;IAiBD,MAAM,CAAC,MAAM,CACX,QAAgB,OAAO,EACvB,GAAY,EACZ,GAAY,EACZ,OAMC;QAED,IAAI,MAAM,GAAG,OAAC,CAAC,MAAM,CAAC;YAC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C;QAChC,CAAC;QAMD,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAGxC,MAAM,aAAa,GAAkB,EAAE,CAAC;QACxC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,CAAC,GAAiC,CAAC,EAAE,CAAC;gBACtD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAGD,OAAO,OAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC;IAmBD,aAAa,CAAC,oBAAuC,EAAE,SAAS,EAAE,IAAI,EAAE;QACtE,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE;YAC5B,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC;SACtD,CAAC;IACJ,CAAC;CACF;AAlKD,sCAkKC;AAyED,SAAgB,mBAAmB,CACjC,UAAa,EACb,oBAA6B,IAAI,EACjC,kBAA2B,KAAK;IAEhC,OAAO,IAAI,aAAa,CAAC,UAAU,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import { z } from \"zod\";\r\nimport { mongoose } from \"@typegoose/typegoose\";\r\n\r\n/**\r\n * Enhanced validation utilities for creating robust Zod schemas.\r\n * This class provides a collection of static methods to create common validation patterns.\r\n *\r\n * @example\r\n * ```typescript\r\n * const userSchema = z.object({\r\n * username: ZodValidation.requiredString(\"Username is required\"),\r\n * email: ZodValidation.email(),\r\n * role: ZodValidation.enumType(UserRole)\r\n * });\r\n * ```\r\n */\r\nexport class ZodValidation {\r\n /**\r\n * Creates a union type that accepts both string ObjectId and mongoose ObjectId instance.\r\n * This is useful when dealing with both raw string IDs and Mongoose ObjectId instances.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @returns A Zod union schema that accepts both string and ObjectId\r\n *\r\n * @example\r\n * ```typescript\r\n * const idSchema = ZodValidation.objectIdUnion();\r\n * // Accepts \"507f1f77bcf86cd799439011\" or new mongoose.Types.ObjectId(\"507f1f77bcf86cd799439011\")\r\n * ```\r\n */\r\n static objectId(field: string = \"Field\") {\r\n return z.union(\r\n [\r\n z\r\n .string({ required_error: `${field} is required` })\r\n .refine((val) => mongoose.Types.ObjectId.isValid(val), {\r\n message: `${field} must be a valid ObjectID`\r\n })\r\n .transform((val) => new mongoose.Types.ObjectId(val)),\r\n z.instanceof(mongoose.Types.ObjectId, {\r\n message: `${field} must be a valid ObjectID`\r\n })\r\n ],\r\n { message: `${field} is required` }\r\n );\r\n }\r\n\r\n /**\r\n * Creates an enum validation with custom error message.\r\n * This validates that a value is one of the values defined in the enum.\r\n *\r\n * @template T - Type of the enum\r\n * @param enumObj - The enum object to validate against\r\n * @param field - The name of the field to be included in the error message\r\n * @returns A Zod schema that validates against the provided enum\r\n *\r\n * @example\r\n * ```typescript\r\n * enum UserRole { ADMIN = \"admin\", USER = \"user\" }\r\n * const roleSchema = ZodValidation.enumType(UserRole, \"Invalid user role\");\r\n * ```\r\n */\r\n static enumType<T extends z.EnumLike>(enumObj: T, field: string = \"Field\") {\r\n return z.nativeEnum(enumObj, {\r\n message: `${field} must be one of: ${Object.values(enumObj).join(\", \")}`\r\n });\r\n }\r\n\r\n /**\r\n * Creates a required number validation with a minimum length.\r\n * The number is also trimmed to remove leading/trailing whitespace.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @param min - Minimum number (optional)\r\n * @param max - MAximum number (optional)\r\n * @param options - options (optional)\r\n * @returns A Zod schema that validates numbers with minimum length\r\n *\r\n * @example\r\n * ```typescript\r\n * const nameSchema = ZodValidation.Number(\"Price\");\r\n * ```\r\n */\r\n static number(\r\n field: string = \"Field\",\r\n min?: number,\r\n max?: number,\r\n options?: {\r\n isInt?: boolean;\r\n isPositive?: boolean;\r\n isNonpositive?: boolean;\r\n isNegative?: boolean;\r\n isNonnegative?: boolean;\r\n }\r\n ) {\r\n let schema = z.number({\r\n required_error: `${field} is required`,\r\n invalid_type_error: `${field} must be a number`\r\n });\r\n\r\n // Range validation\r\n if (min !== undefined) {\r\n schema = schema.gte(min, { message: `${field} must be at least ${min}` });\r\n }\r\n if (max !== undefined) {\r\n schema = schema.lte(max, { message: `${field} must be at most ${max}` });\r\n }\r\n\r\n // Option validation\r\n if (options?.isInt) {\r\n schema = schema.int({ message: `${field} must be an integer` });\r\n }\r\n if (options?.isPositive) {\r\n schema = schema.positive({ message: `${field} must be positive` });\r\n }\r\n if (options?.isNonpositive) {\r\n schema = schema.nonpositive({ message: `${field} must be non-positive` });\r\n }\r\n if (options?.isNegative) {\r\n schema = schema.negative({ message: `${field} must be negative` });\r\n }\r\n if (options?.isNonnegative) {\r\n schema = schema.nonnegative({ message: `${field} must be non-negative` });\r\n }\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Creates a required string validation with a minimum length.\r\n * The string is also trimmed to remove leading/trailing whitespace.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @param minLength - Minimum required length (optional)\r\n * @param maxLength - Maximum required length (optional)\r\n * @param regex - Regular erpression (optional)\r\n * @returns A Zod schema that validates strings with minimum length\r\n *\r\n * @example\r\n * ```typescript\r\n * const nameSchema = ZodValidation.String(\"Name\");\r\n * ```\r\n */\r\n static string(\r\n field: string = \"Field\",\r\n minLength?: number,\r\n maxLength?: number,\r\n regex?: { pattern: RegExp; message: string }\r\n ) {\r\n let schema = z.string({\r\n required_error: `${field} is required`,\r\n invalid_type_error: `${field} must be a string`\r\n });\r\n\r\n if (minLength !== undefined) {\r\n schema = schema.min(\r\n minLength,\r\n `${field} value length must be greater than or equal to ${minLength}`\r\n );\r\n }\r\n if (maxLength !== undefined) {\r\n schema = schema.max(\r\n maxLength,\r\n `${field} value length must be less than or equal to ${maxLength}`\r\n );\r\n }\r\n if (regex !== undefined) {\r\n schema = schema.regex(regex.pattern, regex.message);\r\n }\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Creates an email validation.\r\n * Validates that the string is a valid email address format.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @returns A Zod schema that validates email addresses\r\n *\r\n * @example\r\n * ```typescript\r\n * const emailSchema = ZodValidation.email(\"Please enter a valid email\");\r\n * ```\r\n */\r\n static email(field: string = \"Field\") {\r\n return z\r\n .string({ required_error: `${field} is required` })\r\n .email(`${field} must be a valid email address`);\r\n }\r\n\r\n /**\r\n * Creates a URL validation.\r\n * Validates that the string is a valid URL format.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @returns A Zod schema that validates URLs\r\n *\r\n * @example\r\n * ```typescript\r\n * const websiteSchema = ZodValidation.url(\"Please enter a valid URL\");\r\n * ```\r\n */\r\n static url(field: string = \"Field\") {\r\n return z\r\n .string({ required_error: `${field} is required` })\r\n .url(`${field} must be a valid URL`);\r\n }\r\n\r\n /**\r\n * Creates a phone number validation schema using a regex pattern for global phone numbers.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @returns A Zod schema that validates phone numbers\r\n *\r\n * @example\r\n * ```typescript\r\n * const phoneSchema = ZodValidation.phoneNumber(\"Phone number\");\r\n * ```\r\n */\r\n static phoneNumber(field: string = \"Field\") {\r\n return z\r\n .string({ required_error: `${field} is required` })\r\n .regex(\r\n /^[+]{1}(?:[0-9\\-\\\\(\\\\)\\\\/.]\\s?){6,15}[0-9]{1}$/,\r\n `${field} must be a valid phone number`\r\n );\r\n }\r\n\r\n /**\r\n * Creates a date validation.\r\n * Validates that the input is a JavaScript Date object.\r\n *@param field - The name of the field to be included in the error message\r\n *@param minDate - Minimum required date (optional)\r\n *@param maxDate - Maximum required date (optional)\r\n * @returns A Zod schema that validates Date objects\r\n *\r\n * @example\r\n * ```typescript\r\n * const createdAtSchema = ZodValidation.date();\r\n * ```\r\n */\r\n static date(field: string = \"Field\", minDate?: Date, maxDate?: Date) {\r\n return z\r\n .union(\r\n [\r\n z\r\n .string({ required_error: `${field} is required` })\r\n .refine((val) => {\r\n const date = new Date(val);\r\n return !isNaN(date.getTime());\r\n }, `${field} must be a valid date`)\r\n .transform((val) => new Date(val)),\r\n z.date({\r\n required_error: `${field} is required`,\r\n invalid_type_error: `${field} must be a valid date`\r\n })\r\n ],\r\n { message: `${field} is required` }\r\n )\r\n .refine(\r\n (val) => minDate === undefined || val >= minDate,\r\n `${field} must be on or after ${minDate?.toISOString()}`\r\n )\r\n .refine(\r\n (val) => maxDate === undefined || val <= maxDate,\r\n `${field} must be on or before ${maxDate?.toISOString()}`\r\n );\r\n }\r\n\r\n /**\r\n * Creates a boolean validation with an optional default value.\r\n *\r\n * @param field - The name of the field to be included in the error message\r\n * @returns A Zod schema that validates booleans\r\n *\r\n * @example\r\n * ```typescript\r\n * const isActiveSchema = ZodValidation.boolean(true); // Defaults to true\r\n * ```\r\n */\r\n static boolean(field: string = \"Field\") {\r\n return z.boolean({\r\n required_error: `${field} is required`,\r\n invalid_type_error: `${field} must be a boolean`\r\n });\r\n }\r\n\r\n /**\r\n * Creates an array validation with optional minimum items constraint.\r\n *\r\n * @template T - Type of the schema for array items\r\n * @param schema - The schema for validating array items\r\n * @param field - The name of the field to be included in the error message\r\n * @param minItems - Minimum number of items required (optional)\r\n * @param maxItems - Maximum number of items required (optional)\r\n * @returns A Zod schema that validates arrays\r\n *\r\n * @example\r\n * ```typescript\r\n * const tagsSchema = ZodValidation.array(z.string(), \"At least one tag required\", 1);\r\n * ```\r\n */\r\n static array<T extends z.ZodTypeAny>(\r\n schema: T,\r\n field: string = \"Array\",\r\n minItems?: number,\r\n maxItems?: number\r\n ) {\r\n let arraySchema = z.array(schema, {\r\n required_error: `${field} is required`\r\n });\r\n\r\n if (minItems === 1) {\r\n arraySchema = arraySchema.min(1, `${field} cannot be empty`);\r\n }\r\n if (minItems !== undefined && minItems !== 1) {\r\n arraySchema = arraySchema.min(\r\n minItems,\r\n `${field} must have at least ${minItems} items`\r\n );\r\n }\r\n if (maxItems !== undefined) {\r\n arraySchema = arraySchema.max(\r\n maxItems,\r\n `${field} must have at most ${maxItems} items`\r\n );\r\n }\r\n\r\n return arraySchema;\r\n }\r\n\r\n /**\r\n * Standard timestamp fields for entities.\r\n * Includes createdAt, updatedAt, and deletedAt fields.\r\n *\r\n * @returns An object containing timestamp field schemas\r\n *\r\n * @example\r\n * ```typescript\r\n * const userSchema = z.object({\r\n * name: z.string(),\r\n * ...ZodValidation.timestamps()\r\n * });\r\n * ```\r\n */\r\n static timestamps() {\r\n return {\r\n createdAt: z.date().nullable().optional(),\r\n updatedAt: z.date().nullable().optional(),\r\n deletedAt: z.date().nullable().optional()\r\n };\r\n }\r\n\r\n /**\r\n * Common fields for tracking model metadata.\r\n * Includes timestamps and user tracking fields (createdBy, updatedBy, deletedBy).\r\n *\r\n * @returns An object containing tracking field schemas\r\n *\r\n * @example\r\n * ```typescript\r\n * const postSchema = z.object({\r\n * title: z.string(),\r\n * content: z.string(),\r\n * ...ZodValidation.trackingFields()\r\n * });\r\n * ```\r\n */\r\n static trackingFields() {\r\n return {\r\n createdBy: ZodValidation.objectId().optional(),\r\n updatedBy: ZodValidation.objectId().optional(),\r\n deletedBy: ZodValidation.objectId().optional(),\r\n ...ZodValidation.timestamps()\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Represents the common fields to exclude from update operations.\r\n * This is used to specify which fields should not be updateable.\r\n *\r\n * @example\r\n * ```typescript\r\n * const excludeFields: ExcludeFromUpdate = {\r\n * createdAt: true,\r\n * createdBy: true,\r\n * status: true // Prevent status from being updated\r\n * };\r\n * ```\r\n */\r\nexport type ExcludeFromUpdate = {\r\n createdAt?: true;\r\n updatedAt?: true;\r\n deletedAt?: true;\r\n createdBy?: true;\r\n _id?: true;\r\n} & Record<string, true>;\r\n\r\n/**\r\n * Schema builder for creating consistent CRUD schemas.\r\n * Provides utility methods to generate schemas for create, read, update, and delete operations.\r\n *\r\n * @template T - Type of the base schema shape\r\n *\r\n * @example\r\n * ```typescript\r\n * const userBuilder = new SchemaBuilder({\r\n * name: z.string(),\r\n * email: z.string().email()\r\n * });\r\n *\r\n * const schemas = userBuilder.getAllSchemas();\r\n * ```\r\n */\r\nexport class SchemaBuilder<T extends z.ZodRawShape> {\r\n private baseSchema: z.ZodObject<T>;\r\n\r\n /**\r\n * Create a new schema builder\r\n *\r\n * @param baseFields - The base fields for the schema\r\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\r\n * @param includeTracking - Whether to include tracking fields (createdBy, etc.) (default: false)\r\n *\r\n * @example\r\n * ```typescript\r\n * const userFields = {\r\n * name: ZodValidation.requiredString(),\r\n * email: ZodValidation.email()\r\n * };\r\n *\r\n * // With timestamps\r\n * const builder1 = new SchemaBuilder(userFields);\r\n *\r\n * // Without timestamps\r\n * const builder2 = new SchemaBuilder(userFields, false);\r\n *\r\n * // With tracking fields\r\n * const builder3 = new SchemaBuilder(userFields, true, true);\r\n * ```\r\n */\r\n constructor(\r\n baseFields: T,\r\n private includeTimestamps: boolean = true,\r\n private includeTracking: boolean = false\r\n ) {\r\n if (includeTracking) {\r\n this.baseSchema = z.object({\r\n ...baseFields,\r\n ...ZodValidation.trackingFields()\r\n });\r\n } else if (includeTimestamps) {\r\n this.baseSchema = z.object({\r\n ...baseFields,\r\n ...ZodValidation.timestamps()\r\n });\r\n } else {\r\n this.baseSchema = z.object(baseFields);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the base validation schema without ID.\r\n * Used for creating new entities.\r\n *\r\n * @returns The base schema for creating new entities\r\n *\r\n * @example\r\n * ```typescript\r\n * const createUserSchema = userBuilder.getBaseSchema();\r\n * ```\r\n */\r\n getBaseSchema() {\r\n return this.baseSchema;\r\n }\r\n\r\n /**\r\n * Gets the schema for entities with ID.\r\n * Used for representing complete entities with their ID.\r\n *\r\n * @returns The entity schema including ID\r\n *\r\n * @example\r\n * ```typescript\r\n * const userSchema = userBuilder.getEntitySchema();\r\n * ```\r\n */\r\n getEntitySchema() {\r\n return this.baseSchema.extend({\r\n _id: ZodValidation.objectId()\r\n });\r\n }\r\n\r\n /**\r\n * Gets the schema for validating an entity ID.\r\n * Used for validating ID parameters in requests.\r\n *\r\n * @returns The ID validation schema\r\n *\r\n * @example\r\n * ```typescript\r\n * const userIdSchema = userBuilder.getIdSchema();\r\n * ```\r\n */\r\n getIdSchema() {\r\n return ZodValidation.objectId();\r\n }\r\n\r\n /**\r\n * Gets the schema for updating an entity, excluding specified fields.\r\n * Creates a partial schema where all fields are optional, and removes\r\n * fields that should not be updateable.\r\n *\r\n * @param excludeFields - Fields to exclude from update operations\r\n * @returns The update schema with excluded fields removed\r\n *\r\n * @example\r\n * ```typescript\r\n * // Prevent updating createdAt and status\r\n * const updateUserSchema = userBuilder.getUpdateSchema({\r\n * createdAt: true,\r\n * status: true\r\n * });\r\n * ```\r\n */\r\n getUpdateSchema(excludeFields: ExcludeFromUpdate = { createdAt: true }) {\r\n const entitySchema = this.getEntitySchema();\r\n\r\n // Simple approach - just make everything optional\r\n if (Object.keys(excludeFields).length === 0) {\r\n return entitySchema.partial();\r\n }\r\n\r\n // For the type-safe approach, we need to create a new schema\r\n // without the excluded fields and then make it partial\r\n\r\n // Get all fields from the entity schema\r\n const shape = entitySchema._def.shape();\r\n\r\n // Filter out the fields we want to exclude\r\n const filteredShape: z.ZodRawShape = {};\r\n for (const key in shape) {\r\n if (!excludeFields[key as keyof typeof excludeFields]) {\r\n filteredShape[key] = shape[key];\r\n }\r\n }\r\n\r\n // Create a new schema with the filtered fields\r\n return z.object(filteredShape).partial();\r\n }\r\n\r\n /**\r\n * Gets all common schemas for an entity.\r\n * Returns base, entity, ID, and update schemas in a single object.\r\n *\r\n * @param excludeFromUpdate - Fields to exclude from update operations\r\n * @returns Object containing all schemas\r\n *\r\n * @example\r\n * ```typescript\r\n * const {\r\n * BaseSchema, // For creating\r\n * EntitySchema, // For reading\r\n * IdSchema, // For validating IDs\r\n * UpdateSchema // For updating\r\n * } = userBuilder.getAllSchemas();\r\n * ```\r\n */\r\n getAllSchemas(excludeFromUpdate: ExcludeFromUpdate = { createdAt: true }) {\r\n return {\r\n BaseSchema: this.getBaseSchema(),\r\n EntitySchema: this.getEntitySchema(),\r\n IdSchema: this.getIdSchema(),\r\n UpdateSchema: this.getUpdateSchema(excludeFromUpdate)\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Type helper for creating DTO types from creation schemas.\r\n * Used to derive the type for creating new entities.\r\n *\r\n * @template T - The schema type\r\n *\r\n * @example\r\n * ```typescript\r\n * type CreateUserDTO = CreateDTO<typeof UserValidationSchema>;\r\n * ```\r\n */\r\nexport type CreateDTO<T extends z.ZodType> = z.infer<T>;\r\n\r\n/**\r\n * Type helper for creating DTO types from entity schemas.\r\n * Used to derive the type for complete entities.\r\n *\r\n * @template T - The schema type\r\n *\r\n * @example\r\n * ```typescript\r\n * type UserDTO = EntityDTO<typeof UserSchema>;\r\n * ```\r\n */\r\nexport type EntityDTO<T extends z.ZodType> = z.infer<T>;\r\n\r\n/**\r\n * Type helper for creating DTO types from update schemas.\r\n * Used to derive the type for updating entities.\r\n *\r\n * @template T - The schema type\r\n *\r\n * @example\r\n * ```typescript\r\n * type UpdateUserDTO = UpdateDTO<typeof UpdateUserSchema>;\r\n * ```\r\n */\r\nexport type UpdateDTO<T extends z.ZodType> = z.infer<T>;\r\n\r\n/**\r\n * Type alias for ID DTOs.\r\n * Represents the type of entity IDs (string).\r\n *\r\n * @example\r\n * ```typescript\r\n * type UserIdDTO = IdDTO;\r\n * ```\r\n */\r\nexport type IdDTO = string;\r\n\r\n/**\r\n * Creates a schema builder for an entity.\r\n * Helper function to create a new SchemaBuilder instance.\r\n *\r\n * @template T - Type of the base schema shape\r\n * @param baseFields - Base fields for the entity\r\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\r\n * @param includeTracking - Whether to include tracking fields (default: false)\r\n * @returns A new SchemaBuilder instance\r\n *\r\n * @example\r\n * ```typescript\r\n * const userFields = {\r\n * name: ZodValidation.requiredString(),\r\n * email: ZodValidation.email()\r\n * };\r\n *\r\n * const userSchemaBuilder = createSchemaBuilder(userFields);\r\n * const userSchemaBuilder = createSchemaBuilder(userFields, true, true); // With tracking\r\n * ```\r\n */\r\nexport function createSchemaBuilder<T extends z.ZodRawShape>(\r\n baseFields: T,\r\n includeTimestamps: boolean = true,\r\n includeTracking: boolean = false\r\n) {\r\n return new SchemaBuilder(baseFields, includeTimestamps, includeTracking);\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",