@gennext/lb-infra 0.1.0 → 0.1.3

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 (94) hide show
  1. package/README.md +0 -6
  2. package/dist/base/index.d.ts +2 -0
  3. package/dist/base/index.d.ts.map +1 -1
  4. package/dist/base/index.js +2 -0
  5. package/dist/base/index.js.map +1 -1
  6. package/dist/base/migration/index.d.ts +3 -0
  7. package/dist/base/migration/index.d.ts.map +1 -0
  8. package/dist/base/migration/index.js +19 -0
  9. package/dist/base/migration/index.js.map +1 -0
  10. package/dist/base/migration/migration.interface.d.ts +5 -0
  11. package/dist/base/migration/migration.interface.d.ts.map +1 -0
  12. package/dist/base/migration/migration.interface.js +3 -0
  13. package/dist/base/migration/migration.interface.js.map +1 -0
  14. package/dist/base/migration/migration.service.d.ts +9 -0
  15. package/dist/base/migration/migration.service.d.ts.map +1 -0
  16. package/dist/base/migration/migration.service.js +146 -0
  17. package/dist/base/migration/migration.service.js.map +1 -0
  18. package/dist/base/models/base.model.d.ts +12 -6
  19. package/dist/base/models/base.model.d.ts.map +1 -1
  20. package/dist/base/models/base.model.js +10 -6
  21. package/dist/base/models/base.model.js.map +1 -1
  22. package/dist/base/models/index.d.ts +1 -0
  23. package/dist/base/models/index.d.ts.map +1 -1
  24. package/dist/base/models/index.js +1 -0
  25. package/dist/base/models/index.js.map +1 -1
  26. package/dist/base/models/migration.model.d.ts +12 -0
  27. package/dist/base/models/migration.model.d.ts.map +1 -0
  28. package/dist/base/models/migration.model.js +46 -0
  29. package/dist/base/models/migration.model.js.map +1 -0
  30. package/dist/base/repository/index.d.ts +3 -0
  31. package/dist/base/repository/index.d.ts.map +1 -0
  32. package/dist/base/repository/index.js +19 -0
  33. package/dist/base/repository/index.js.map +1 -0
  34. package/dist/base/repository/migration.repository.d.ts +6 -0
  35. package/dist/base/repository/migration.repository.d.ts.map +1 -0
  36. package/dist/base/repository/migration.repository.js +29 -0
  37. package/dist/base/repository/migration.repository.js.map +1 -0
  38. package/dist/base/repository/soft-delete.repository.d.ts +40 -0
  39. package/dist/base/repository/soft-delete.repository.d.ts.map +1 -0
  40. package/dist/base/repository/soft-delete.repository.js +74 -0
  41. package/dist/base/repository/soft-delete.repository.js.map +1 -0
  42. package/dist/helpers/migrate/type.d.ts +10 -0
  43. package/dist/helpers/migrate/type.d.ts.map +1 -0
  44. package/dist/helpers/migrate/type.js +3 -0
  45. package/dist/helpers/migrate/type.js.map +1 -0
  46. package/dist/index.d.ts +1 -0
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +1 -0
  49. package/dist/index.js.map +1 -1
  50. package/dist/utilities/axios.utility.d.ts +14 -0
  51. package/dist/utilities/axios.utility.d.ts.map +1 -0
  52. package/dist/utilities/axios.utility.js +122 -0
  53. package/dist/utilities/axios.utility.js.map +1 -0
  54. package/dist/utilities/index.d.ts +5 -0
  55. package/dist/utilities/index.d.ts.map +1 -1
  56. package/dist/utilities/index.js +28 -0
  57. package/dist/utilities/index.js.map +1 -1
  58. package/dist/utilities/lb-filter.utility.d.ts +5 -0
  59. package/dist/utilities/lb-filter.utility.d.ts.map +1 -0
  60. package/dist/utilities/lb-filter.utility.js +9 -0
  61. package/dist/utilities/lb-filter.utility.js.map +1 -0
  62. package/dist/utilities/migrate-helper.d.ts +10 -0
  63. package/dist/utilities/migrate-helper.d.ts.map +1 -0
  64. package/dist/utilities/migrate-helper.js +45 -0
  65. package/dist/utilities/migrate-helper.js.map +1 -0
  66. package/dist/utilities/migration-engine.d.ts +16 -0
  67. package/dist/utilities/migration-engine.d.ts.map +1 -0
  68. package/dist/utilities/migration-engine.js +40 -0
  69. package/dist/utilities/migration-engine.js.map +1 -0
  70. package/dist/utilities/migration.utility.d.ts +7 -0
  71. package/dist/utilities/migration.utility.d.ts.map +1 -0
  72. package/dist/utilities/migration.utility.js +23 -0
  73. package/dist/utilities/migration.utility.js.map +1 -0
  74. package/dist/utilities/model.utility.d.ts +44 -23
  75. package/dist/utilities/model.utility.d.ts.map +1 -1
  76. package/dist/utilities/model.utility.js +56 -37
  77. package/dist/utilities/model.utility.js.map +1 -1
  78. package/dist/validators/base.schema.d.ts +56 -0
  79. package/dist/validators/base.schema.d.ts.map +1 -0
  80. package/dist/validators/base.schema.js +84 -0
  81. package/dist/validators/base.schema.js.map +1 -0
  82. package/dist/validators/common.schema.d.ts +50 -0
  83. package/dist/validators/common.schema.d.ts.map +1 -0
  84. package/dist/validators/common.schema.js +51 -0
  85. package/dist/validators/common.schema.js.map +1 -0
  86. package/dist/validators/index.d.ts +15 -0
  87. package/dist/validators/index.d.ts.map +1 -0
  88. package/dist/validators/index.js +36 -0
  89. package/dist/validators/index.js.map +1 -0
  90. package/dist/validators/with-zod.d.ts +66 -0
  91. package/dist/validators/with-zod.d.ts.map +1 -0
  92. package/dist/validators/with-zod.js +117 -0
  93. package/dist/validators/with-zod.js.map +1 -0
  94. package/package.json +4 -2
@@ -1,41 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIdType = exports.getIdSchema = void 0;
4
- const metadata_1 = require("@loopback/metadata");
5
- const rest_1 = require("@loopback/rest");
6
- /**
7
- * Extracts the JSON schema of the ID property from a LoopBack entity
8
- * @param entity - The LoopBack entity class (must extend BaseEntity)
9
- * @returns The SchemaObject representing the ID property
10
- * @example
11
- * const schema = getIdSchema(User);
12
- * // { type: 'number', minimum: 1 }
13
- */
14
- const getIdSchema = (entity) => {
15
- const idProp = entity.getIdProperties()[0];
16
- const modelSchema = (0, rest_1.jsonToSchemaObject)((0, rest_1.getJsonSchema)(entity));
17
- return modelSchema.properties?.[idProp];
3
+ exports.buildPaginationResponse = exports.buildArrayResponse = exports.buildResponse = exports.buildRequestBody = void 0;
4
+ const lb_rest_1 = require("@gennext/lb-infra/lb-rest");
5
+ const buildModelSchema = (model, options = {}) => (0, lb_rest_1.getModelSchemaRef)(model, {
6
+ title: options.title,
7
+ exclude: options.exclude,
8
+ partial: options.partial,
9
+ optional: options.optional,
10
+ includeRelations: options.includeRelations,
11
+ });
12
+ const buildArraySchema = (items) => ({
13
+ type: 'array',
14
+ items,
15
+ });
16
+ const buildRequestBody = (model, options = {}) => {
17
+ const { title = `${model.name} - Request body`, exclude = ['id'], required: isRequired = false, isConvertToArray = false, } = options;
18
+ const schema = isConvertToArray
19
+ ? buildArraySchema(buildModelSchema(model, { title, exclude }))
20
+ : buildModelSchema(model, { title, exclude });
21
+ return {
22
+ required: isRequired,
23
+ content: {
24
+ 'application/json': { schema },
25
+ },
26
+ };
18
27
  };
19
- exports.getIdSchema = getIdSchema;
20
- /**
21
- * Inspects the metadata of a LoopBack entity to determine the ID type
22
- * @param entity - The LoopBack entity class
23
- * @returns 'string' or 'number' (default: 'number')
24
- * @example
25
- * const type = getIdType(User); // 'number'
26
- */
27
- const getIdType = (entity) => {
28
- let idType = 'number';
29
- try {
30
- const idMetadata = metadata_1.MetadataInspector.getPropertyMetadata('loopback:model-properties', entity, 'id');
31
- idType = idMetadata?.type ?? 'number';
32
- }
33
- catch (e) {
34
- console.error("[getIdType] Failed to inspect entity id type! Use 'number' by default | Error: ", e);
35
- idType = 'number';
36
- return idType;
37
- }
38
- return idType;
39
- };
40
- exports.getIdType = getIdType;
28
+ exports.buildRequestBody = buildRequestBody;
29
+ const buildResponse = (model, options = {}) => buildModelSchema(model, {
30
+ title: options.title ?? `${model.name} - Response`,
31
+ ...options,
32
+ });
33
+ exports.buildResponse = buildResponse;
34
+ const buildArrayResponse = (model, options = {}) => ({
35
+ title: options.title ?? `${model.name} - List response`,
36
+ type: 'array',
37
+ items: buildModelSchema(model, options),
38
+ });
39
+ exports.buildArrayResponse = buildArrayResponse;
40
+ const buildPaginationResponse = (model, options = {}) => ({
41
+ content: {
42
+ 'application/json': {
43
+ schema: {
44
+ title: options.title ?? `${model.name} - Pagination response`,
45
+ type: 'object',
46
+ properties: {
47
+ count: { type: 'number' },
48
+ offset: { type: 'number' },
49
+ limit: { type: 'number' },
50
+ data: {
51
+ type: 'array',
52
+ items: buildModelSchema(model, options),
53
+ },
54
+ },
55
+ },
56
+ },
57
+ },
58
+ });
59
+ exports.buildPaginationResponse = buildPaginationResponse;
41
60
  //# sourceMappingURL=model.utility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.utility.js","sourceRoot":"","sources":["../../src/utilities/model.utility.ts"],"names":[],"mappings":";;;AAAA,iDAAuD;AACvD,yCAAiF;AAIjF;;;;;;;GAOG;AACI,MAAM,WAAW,GAAG,CACzB,MAA4C,EAC9B,EAAE;IAChB,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,IAAA,yBAAkB,EAAC,IAAA,oBAAa,EAAC,MAAM,CAAC,CAAiB,CAAC;IAC9E,OAAO,WAAW,CAAC,UAAU,EAAE,CAAC,MAAM,CAAiB,CAAC;AAC1D,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB;AAEF;;;;;;GAMG;AACI,MAAM,SAAS,GAAG,CACvB,MAA8C,EACzB,EAAE;IACvB,IAAI,MAAM,GAAwB,QAAQ,CAAC;IAE3C,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,4BAAiB,CAAC,mBAAmB,CAErD,2BAA2B,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAE9C,MAAM,GAAG,UAAU,EAAE,IAAI,IAAI,QAAQ,CAAC;IACxC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CACX,iFAAiF,EACjF,CAAC,CACF,CAAC;QAEF,MAAM,GAAG,QAAQ,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAtBW,QAAA,SAAS,aAsBpB"}
1
+ {"version":3,"file":"model.utility.js","sourceRoot":"","sources":["../../src/utilities/model.utility.ts"],"names":[],"mappings":";;;AAAA,uDAA+F;AAiB/F,MAAM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I,aAAa;IAClD,GAAG,OAAO;CACX,CAAC,CAAC;AAPQ,QAAA,aAAa,iBAOrB;AAEE,MAAM,kBAAkB,GAAG,CAChC,KAAoB,EACpB,UAA8B,EAAE,EAClB,EAAE,CAAC,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,kBAAkB;IACvD,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC;AAPU,QAAA,kBAAkB,sBAO5B;AAEI,MAAM,uBAAuB,GAAG,CACrC,KAAoB,EACpB,UAA8B,EAAE,EAChC,EAAE,CAAC,CAAC;IACJ,OAAO,EAAE;QACP,kBAAkB,EAAE;YAClB,MAAM,EAAE;gBACN,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,wBAAwB;gBAC7D,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACzB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC1B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACzB,IAAI,EAAE;wBACJ,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC;qBACxC;iBACF;aACF;SACF;KACF;CACF,CAAC,CAAC;AArBU,QAAA,uBAAuB,2BAqBjC"}
@@ -0,0 +1,56 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Common validation patterns designed for reuse across the application.
4
+ * Build domain-specific schemas by composing these primitives.
5
+ */
6
+ export declare const BaseSchemas: {
7
+ /** Standard UUID v4 */
8
+ UUID: z.ZodUUID;
9
+ /** Flexible ID – accepts UUID string or positive integer */
10
+ ID: z.ZodUnion<readonly [z.ZodUUID, z.ZodNumber]>;
11
+ Email: z.ZodEmail;
12
+ Username: z.ZodString;
13
+ Password: z.ZodString;
14
+ PhoneNumber: z.ZodString;
15
+ URL: z.ZodURL;
16
+ /** Non-empty, trimmed string */
17
+ NonEmptyString: z.ZodString;
18
+ /** Short description / label field */
19
+ Description: z.ZodOptional<z.ZodString>;
20
+ Port: z.ZodNumber;
21
+ PositiveInt: z.ZodNumber;
22
+ NonNegativeInt: z.ZodNumber;
23
+ SafeInt: z.ZodNumber;
24
+ /** ISO-8601 datetime string */
25
+ UnixTimestamp: z.ZodNumber;
26
+ Tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
27
+ Pagination: z.ZodObject<{
28
+ page: z.ZodDefault<z.ZodNumber>;
29
+ limit: z.ZodDefault<z.ZodNumber>;
30
+ offset: z.ZodOptional<z.ZodNumber>;
31
+ }, z.core.$strip>;
32
+ };
33
+ /**
34
+ * Wraps a shape in a standard auditable entity object.
35
+ *
36
+ * @example
37
+ * const UserSchema = createEntitySchema({ name: z.string() });
38
+ * type User = z.infer<typeof UserSchema>;
39
+ */
40
+ export declare const createEntitySchema: <T extends z.ZodRawShape>(shape: T) => z.ZodObject<{
41
+ id: z.ZodUUID;
42
+ createdAt: z.ZodDate;
43
+ updatedAt: z.ZodDate;
44
+ deletedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
45
+ } & T extends infer T_1 ? { -readonly [P in keyof T_1]: T_1[P]; } : never, z.core.$strip>;
46
+ /**
47
+ * Wraps a shape using numeric primary-key convention (mirrors
48
+ * the {@link TBaseIdEntity} pattern used in lb-infra models).
49
+ */
50
+ export declare const createNumericEntitySchema: <T extends z.ZodRawShape>(shape: T) => z.ZodObject<{
51
+ id: z.ZodNumber;
52
+ createdAt: z.ZodDate;
53
+ updatedAt: z.ZodDate;
54
+ deletedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
55
+ } & T extends infer T_1 ? { -readonly [P in keyof T_1]: T_1[P]; } : never, z.core.$strip>;
56
+ //# sourceMappingURL=base.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.schema.d.ts","sourceRoot":"","sources":["../../src/validators/base.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,WAAW;IAEtB,uBAAuB;;IAEvB,4DAA4D;;;;;;;IAkB5D,gCAAgC;;IAEhC,sCAAsC;;;;;;IAUtC,+BAA+B;;;;;;;;CAiBhC,CAAC;AAIF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC;;;;;yFAOhE,CAAC;AAEL;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,OAAO,CAAC;;;;;yFAOvE,CAAC"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNumericEntitySchema = exports.createEntitySchema = exports.BaseSchemas = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Common validation patterns designed for reuse across the application.
7
+ * Build domain-specific schemas by composing these primitives.
8
+ */
9
+ exports.BaseSchemas = {
10
+ // ─── Identity ────────────────────────────────────────────────────────────
11
+ /** Standard UUID v4 */
12
+ UUID: zod_1.z.uuid('Invalid UUID format'),
13
+ /** Flexible ID – accepts UUID string or positive integer */
14
+ ID: zod_1.z.union([
15
+ zod_1.z.uuid('Invalid UUID format'),
16
+ zod_1.z.number().int().positive('ID must be a positive integer'),
17
+ ]),
18
+ // ─── Strings ─────────────────────────────────────────────────────────────
19
+ Email: zod_1.z.email('Invalid email format'),
20
+ Username: zod_1.z
21
+ .string()
22
+ .min(3, 'Username must be at least 3 characters')
23
+ .max(50, 'Username must be at most 50 characters'),
24
+ Password: zod_1.z
25
+ .string()
26
+ .min(8, 'Password must be at least 8 characters')
27
+ .max(128, 'Password must be at most 128 characters'),
28
+ PhoneNumber: zod_1.z.string().regex(/^\+?[\d\s\-()\\.]{7,}$/, 'Invalid phone number format'),
29
+ URL: zod_1.z.url('Invalid URL format'),
30
+ /** Non-empty, trimmed string */
31
+ NonEmptyString: zod_1.z.string().trim().min(1, 'Value must not be empty'),
32
+ /** Short description / label field */
33
+ Description: zod_1.z.string().max(500, 'Description must be at most 500 characters').optional(),
34
+ // ─── Numbers ─────────────────────────────────────────────────────────────
35
+ Port: zod_1.z.number().int().min(1, 'Port must be >= 1').max(65535, 'Port must be <= 65535'),
36
+ PositiveInt: zod_1.z.number().int().positive('Must be a positive integer'),
37
+ NonNegativeInt: zod_1.z.number().int().min(0, 'Must be >= 0'),
38
+ SafeInt: zod_1.z.number().int(),
39
+ // ─── Dates ───────────────────────────────────────────────────────────────
40
+ /** ISO-8601 datetime string */
41
+ UnixTimestamp: zod_1.z.number().int().positive('Unix timestamp must be positive'),
42
+ // ─── Collections ─────────────────────────────────────────────────────────
43
+ Tags: zod_1.z.array(zod_1.z.string()).default([]),
44
+ // ─── Pagination ──────────────────────────────────────────────────────────
45
+ Pagination: zod_1.z.object({
46
+ page: zod_1.z.number().int().min(1, 'Page must be >= 1').default(1),
47
+ limit: zod_1.z
48
+ .number()
49
+ .int()
50
+ .min(1, 'Limit must be >= 1')
51
+ .max(1000, 'Limit must be <= 1000')
52
+ .default(20),
53
+ offset: zod_1.z.number().int().min(0).optional(),
54
+ }),
55
+ };
56
+ // ─── Entity Helpers ──────────────────────────────────────────────────────────
57
+ /**
58
+ * Wraps a shape in a standard auditable entity object.
59
+ *
60
+ * @example
61
+ * const UserSchema = createEntitySchema({ name: z.string() });
62
+ * type User = z.infer<typeof UserSchema>;
63
+ */
64
+ const createEntitySchema = (shape) => zod_1.z.object({
65
+ id: exports.BaseSchemas.UUID,
66
+ createdAt: zod_1.z.date(),
67
+ updatedAt: zod_1.z.date(),
68
+ deletedAt: zod_1.z.date().nullable().optional(),
69
+ ...shape,
70
+ });
71
+ exports.createEntitySchema = createEntitySchema;
72
+ /**
73
+ * Wraps a shape using numeric primary-key convention (mirrors
74
+ * the {@link TBaseIdEntity} pattern used in lb-infra models).
75
+ */
76
+ const createNumericEntitySchema = (shape) => zod_1.z.object({
77
+ id: exports.BaseSchemas.PositiveInt,
78
+ createdAt: zod_1.z.date(),
79
+ updatedAt: zod_1.z.date(),
80
+ deletedAt: zod_1.z.date().nullable().optional(),
81
+ ...shape,
82
+ });
83
+ exports.createNumericEntitySchema = createNumericEntitySchema;
84
+ //# sourceMappingURL=base.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.schema.js","sourceRoot":"","sources":["../../src/validators/base.schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;;GAGG;AACU,QAAA,WAAW,GAAG;IACzB,4EAA4E;IAC5E,uBAAuB;IACvB,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC;IACnC,4DAA4D;IAC5D,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC;QACV,OAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC;QAC7B,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;KAC3D,CAAC;IAEF,4EAA4E;IAC5E,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC;IACtC,QAAQ,EAAE,OAAC;SACR,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAChD,GAAG,CAAC,EAAE,EAAE,wCAAwC,CAAC;IACpD,QAAQ,EAAE,OAAC;SACR,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAChD,GAAG,CAAC,GAAG,EAAE,yCAAyC,CAAC;IACtD,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,wBAAwB,EAAE,6BAA6B,CAAC;IACtF,GAAG,EAAE,OAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAChC,gCAAgC;IAChC,cAAc,E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CAAC,EAAE,CAAC;QACd,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;KAC3C,CAAC;CACH,CAAC;AAEF,gFAAgF;AAEhF;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAA0B,KAAQ,EAAE,EAAE,CACtE,OAAC,CAAC,MAAM,CAAC;IACP,EAAE,EAAE,mBAAW,CAAC,IAAI;IACpB,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE;IACnB,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE;IACnB,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACzC,GAAG,KAAK;CACT,CAAC,CAAC;AAPQ,QAAA,kBAAkB,sBAO1B;AAEL;;;GAGG;AACI,MAAM,yBAAyB,GAAG,CAA0B,KAAQ,EAAE,EAAE,CAC7E,OAAC,CAAC,MAAM,CAAC;IACP,EAAE,EAAE,mBAAW,CAAC,WAAW;IAC3B,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE;IACnB,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE;IACnB,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACzC,GAAG,KAAK;CACT,CAAC,CAAC;AAPQ,QAAA,yBAAyB,6BAOjC"}
@@ -0,0 +1,50 @@
1
+ import { z } from 'zod';
2
+ export declare const ListQuerySchema: z.ZodObject<{
3
+ sortBy: z.ZodOptional<z.ZodString>;
4
+ sortOrder: z.ZodDefault<z.ZodEnum<{
5
+ desc: "desc";
6
+ asc: "asc";
7
+ }>>;
8
+ search: z.ZodOptional<z.ZodString>;
9
+ page: z.ZodDefault<z.ZodNumber>;
10
+ limit: z.ZodDefault<z.ZodNumber>;
11
+ offset: z.ZodOptional<z.ZodNumber>;
12
+ }, z.core.$strip>;
13
+ export type TListQuery = z.infer<typeof ListQuerySchema>;
14
+ /**
15
+ * Wraps any Zod schema in the standard API response envelope.
16
+ *
17
+ * @example
18
+ * const UserResponseSchema = ApiResponseSchema(UserEntitySchema);
19
+ */
20
+ export declare const ApiResponseSchema: <T extends z.ZodTypeAny>(dataSchema: T) => z.ZodObject<{
21
+ success: z.ZodBoolean;
22
+ code: z.ZodString;
23
+ message: z.ZodString;
24
+ data: z.ZodOptional<T>;
25
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
26
+ }, z.core.$strip>;
27
+ export declare const PaginatedResponseSchema: <T extends z.ZodTypeAny>(itemSchema: T) => z.ZodObject<{
28
+ items: z.ZodArray<T>;
29
+ total: z.ZodNumber;
30
+ page: z.ZodNumber;
31
+ limit: z.ZodNumber;
32
+ hasMore: z.ZodBoolean;
33
+ }, z.core.$strip>;
34
+ export declare const DatabaseConfigSchema: z.ZodObject<{
35
+ host: z.ZodString;
36
+ port: z.ZodDefault<z.ZodNumber>;
37
+ database: z.ZodString;
38
+ username: z.ZodString;
39
+ password: z.ZodString;
40
+ ssl: z.ZodDefault<z.ZodBoolean>;
41
+ }, z.core.$strip>;
42
+ export type TDatabaseConfig = z.infer<typeof DatabaseConfigSchema>;
43
+ export declare const RedisConfigSchema: z.ZodObject<{
44
+ host: z.ZodString;
45
+ port: z.ZodDefault<z.ZodNumber>;
46
+ password: z.ZodOptional<z.ZodString>;
47
+ db: z.ZodDefault<z.ZodNumber>;
48
+ }, z.core.$strip>;
49
+ export type TRedisConfig = z.infer<typeof RedisConfigSchema>;
50
+ //# sourceMappingURL=common.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.schema.d.ts","sourceRoot":"","sources":["../../src/validators/common.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,eAAe;;;;;;;;;;iBAK1B,CAAC;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAIzD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC;;;;;;iBAOnE,CAAC;AAEL,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC;;;;;;iBAOzE,CAAC;AAIL,eAAO,MAAM,oBAAoB;;;;;;;iBAO/B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEnE,eAAO,MAAM,iBAAiB;;;;;iBAK5B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisConfigSchema = exports.DatabaseConfigSchema = exports.PaginatedResponseSchema = exports.ApiResponseSchema = exports.ListQuerySchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const base_schema_1 = require("./base.schema");
6
+ // ─── Pagination & Query ──────────────────────────────────────────────────────
7
+ exports.ListQuerySchema = zod_1.z.object({
8
+ ...base_schema_1.BaseSchemas.Pagination.shape,
9
+ sortBy: zod_1.z.string().optional(),
10
+ sortOrder: zod_1.z.enum(['asc', 'desc']).default('asc'),
11
+ search: zod_1.z.string().optional(),
12
+ });
13
+ // ─── Generic API Response Wrappers ───────────────────────────────────────────
14
+ /**
15
+ * Wraps any Zod schema in the standard API response envelope.
16
+ *
17
+ * @example
18
+ * const UserResponseSchema = ApiResponseSchema(UserEntitySchema);
19
+ */
20
+ const ApiResponseSchema = (dataSchema) => zod_1.z.object({
21
+ success: zod_1.z.boolean(),
22
+ code: zod_1.z.string(),
23
+ message: zod_1.z.string(),
24
+ data: dataSchema.optional(),
25
+ metadata: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
26
+ });
27
+ exports.ApiResponseSchema = ApiResponseSchema;
28
+ const PaginatedResponseSchema = (itemSchema) => zod_1.z.object({
29
+ items: zod_1.z.array(itemSchema),
30
+ total: zod_1.z.number().int().min(0),
31
+ page: zod_1.z.number().int().min(1),
32
+ limit: zod_1.z.number().int().min(1),
33
+ hasMore: zod_1.z.boolean(),
34
+ });
35
+ exports.PaginatedResponseSchema = PaginatedResponseSchema;
36
+ // ─── Environment / Config ────────────────────────────────────────────────────
37
+ exports.DatabaseConfigSchema = zod_1.z.object({
38
+ host: zod_1.z.string().min(1, 'DB host is required'),
39
+ port: base_schema_1.BaseSchemas.Port.default(5432),
40
+ database: zod_1.z.string().min(1, 'DB name is required'),
41
+ username: zod_1.z.string().min(1, 'DB username is required'),
42
+ password: zod_1.z.string().min(1, 'DB password is required'),
43
+ ssl: zod_1.z.boolean().default(false),
44
+ });
45
+ exports.RedisConfigSchema = zod_1.z.object({
46
+ host: zod_1.z.string().min(1, 'Redis host is required'),
47
+ port: base_schema_1.BaseSchemas.Port.default(6379),
48
+ password: zod_1.z.string().optional(),
49
+ db: zod_1.z.number().int().min(0).default(0),
50
+ });
51
+ //# sourceMappingURL=common.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.schema.js","sourceRoot":"","sources":["../../src/validators/common.schema.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,+CAA4C;AAE5C,gFAAgF;AAEnE,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAC;IACtC,GAAG,yBAAW,CAAC,UAAU,CAAC,KAAK;IAC/B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACjD,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,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,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC;IAClD,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC;IACtD,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC;IACtD,GAAG,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;CAChC,CAAC,CAAC;AAGU,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,wBAAwB,CAAC;IACjD,IAAI,EAAE,yBAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IACpC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;CACvC,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @module validators
3
+ *
4
+ * Zod-based validation layer for @gennext/lb-infra.
5
+ *
6
+ * @example
7
+ * import { safeParse, LoginSchema, BaseSchemas } from '@gennext/lb-infra/validators';
8
+ *
9
+ * const loginData = safeParse(LoginSchema, req.body, 'Login');
10
+ */
11
+ export { BaseSchemas, createEntitySchema, createNumericEntitySchema } from './base.schema';
12
+ export { ListQuerySchema, ApiResponseSchema, PaginatedResponseSchema, DatabaseConfigSchema, RedisConfigSchema, } from './common.schema';
13
+ export type { TListQuery, TDatabaseConfig, TRedisConfig } from './common.schema';
14
+ export { TInfer, zodToValidationError, safeParse, safeParseAsync, validate, createValidationMiddleware, } from './with-zod';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAG3F,OAAO,EAEL,eAAe,EAEf,iBAAiB,EACjB,uBAAuB,EAEvB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGjF,OAAO,EACL,MAAM,EACN,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,QAAQ,EACR,0BAA0B,GAC3B,MAAM,YAAY,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * @module validators
4
+ *
5
+ * Zod-based validation layer for @gennext/lb-infra.
6
+ *
7
+ * @example
8
+ * import { safeParse, LoginSchema, BaseSchemas } from '@gennext/lb-infra/validators';
9
+ *
10
+ * const loginData = safeParse(LoginSchema, req.body, 'Login');
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.createValidationMiddleware = exports.validate = exports.safeParseAsync = exports.safeParse = exports.zodToValidationError = exports.RedisConfigSchema = exports.DatabaseConfigSchema = exports.PaginatedResponseSchema = exports.ApiResponseSchema = exports.ListQuerySchema = exports.createNumericEntitySchema = exports.createEntitySchema = exports.BaseSchemas = void 0;
14
+ // Base schemas & entity builders
15
+ var base_schema_1 = require("./base.schema");
16
+ Object.defineProperty(exports, "BaseSchemas", { enumerable: true, get: function () { return base_schema_1.BaseSchemas; } });
17
+ Object.defineProperty(exports, "createEntitySchema", { enumerable: true, get: function () { return base_schema_1.createEntitySchema; } });
18
+ Object.defineProperty(exports, "createNumericEntitySchema", { enumerable: true, get: function () { return base_schema_1.createNumericEntitySchema; } });
19
+ // Application-level schemas
20
+ var common_schema_1 = require("./common.schema");
21
+ // Query & Pagination
22
+ Object.defineProperty(exports, "ListQuerySchema", { enumerable: true, get: function () { return common_schema_1.ListQuerySchema; } });
23
+ // Response wrappers
24
+ Object.defineProperty(exports, "ApiResponseSchema", { enumerable: true, get: function () { return common_schema_1.ApiResponseSchema; } });
25
+ Object.defineProperty(exports, "PaginatedResponseSchema", { enumerable: true, get: function () { return common_schema_1.PaginatedResponseSchema; } });
26
+ // Config
27
+ Object.defineProperty(exports, "DatabaseConfigSchema", { enumerable: true, get: function () { return common_schema_1.DatabaseConfigSchema; } });
28
+ Object.defineProperty(exports, "RedisConfigSchema", { enumerable: true, get: function () { return common_schema_1.RedisConfigSchema; } });
29
+ // Zod integration utilities
30
+ var with_zod_1 = require("./with-zod");
31
+ Object.defineProperty(exports, "zodToValidationError", { enumerable: true, get: function () { return with_zod_1.zodToValidationError; } });
32
+ Object.defineProperty(exports, "safeParse", { enumerable: true, get: function () { return with_zod_1.safeParse; } });
33
+ Object.defineProperty(exports, "safeParseAsync", { enumerable: true, get: function () { return with_zod_1.safeParseAsync; } });
34
+ Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return with_zod_1.validate; } });
35
+ Object.defineProperty(exports, "createValidationMiddleware", { enumerable: true, get: function () { return with_zod_1.createValidationMiddleware; } });
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,iCAAiC;AACjC,6CAA2F;AAAlF,0GAAA,WAAW,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAAE,wHAAA,yBAAyB,OAAA;AAEnE,4BAA4B;AAC5B,iDASyB;AARvB,qBAAqB;AACrB,gHAAA,eAAe,OAAA;AACf,oBAAoB;AACpB,kHAAA,iBAAiB,OAAA;AACjB,wHAAA,uBAAuB,OAAA;AACvB,SAAS;AACT,qHAAA,oBAAoB,OAAA;AACpB,kHAAA,iBAAiB,OAAA;AAKnB,4BAA4B;AAC5B,uCAOoB;AALlB,gHAAA,oBAAoB,OAAA;AACpB,qGAAA,SAAS,OAAA;AACT,0GAAA,cAAc,OAAA;AACd,oGAAA,QAAQ,OAAA;AACR,sHAAA,0BAA0B,OAAA"}
@@ -0,0 +1,66 @@
1
+ import { z } from 'zod';
2
+ import { ValidationError } from '../utilities/error.utility';
3
+ /** Shorthand for `z.infer<typeof schema>` */
4
+ export type TInfer<T extends z.ZodTypeAny> = z.infer<T>;
5
+ /**
6
+ * Flatten a {@link z.ZodError} into a field-keyed record and wrap it
7
+ * in the project's {@link ValidationError}.
8
+ *
9
+ * @param error - The raw Zod validation error
10
+ * @param context - Optional human-readable context label (e.g. "Login validation")
11
+ *
12
+ * @example
13
+ * try {
14
+ * LoginSchema.parse(body);
15
+ * } catch (err) {
16
+ * if (err instanceof z.ZodError) {
17
+ * throw zodToValidationError(err, 'Login');
18
+ * }
19
+ * }
20
+ */
21
+ export declare function zodToValidationError(error: z.ZodError, context?: string): ValidationError;
22
+ /**
23
+ * Parse `data` against `schema`, converting any ZodError into a
24
+ * {@link ValidationError} automatically.
25
+ *
26
+ * @throws {@link ValidationError} when validation fails
27
+ *
28
+ * @example
29
+ * const loginInput = safeParse(LoginSchema, req.body, 'Login');
30
+ */
31
+ export declare function safeParse<T>(schema: z.ZodSchema<T>, data: unknown, context?: string): T;
32
+ /**
33
+ * Async variant of {@link safeParse} – necessary when the schema uses
34
+ * `.refine()` with an async callback.
35
+ *
36
+ * @throws {@link ValidationError} when validation fails
37
+ */
38
+ export declare function safeParseAsync<T>(schema: z.ZodSchema<T>, data: unknown, context?: string): Promise<T>;
39
+ /**
40
+ * Method decorator that validates the **first argument** of the decorated
41
+ * method against `schema` before the original method body executes.
42
+ *
43
+ * @example
44
+ * class UserService {
45
+ * \@validate(LoginSchema)
46
+ * async login(data: LoginInput) { ... }
47
+ * }
48
+ */
49
+ export declare function validate<T>(schema: z.ZodSchema<T>, context?: string): (_target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
50
+ /**
51
+ * Builds an Express-compatible middleware that validates `req.body` against
52
+ * `schema`. On success, the parsed + transformed data is assigned to
53
+ * `req.validatedBody`. On failure, a `400` JSON response is returned.
54
+ *
55
+ * @example
56
+ * router.post('/login', createValidationMiddleware(LoginSchema), loginHandler);
57
+ */
58
+ export declare function createValidationMiddleware<T>(schema: z.ZodSchema<T>, context?: string): (req: {
59
+ body: unknown;
60
+ validatedBody?: T;
61
+ }, res: {
62
+ status: (c: number) => {
63
+ json: (b: unknown) => void;
64
+ };
65
+ }, next: (err?: unknown) => void) => void;
66
+ //# sourceMappingURL=with-zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-zod.d.ts","sourceRoot":"","sources":["../../src/validators/with-zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAI5D,6CAA6C;AAC7C,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAIxD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,eAAe,CAgBzF;AAID;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAMvF;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,CAAC,CAAC,CAMZ;AAID;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,IACjD,SAAS,MAAM,EAAE,aAAa,MAAM,EAAE,YAAY,kBAAkB,wBAUtF;AAID;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,IAElF,KAAK;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,CAAC,CAAA;CAAE,EACzC,KAAK;IAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK;QAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;KAAE,CAAA;CAAE,EAC9D,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,UAiBhC"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zodToValidationError = zodToValidationError;
4
+ exports.safeParse = safeParse;
5
+ exports.safeParseAsync = safeParseAsync;
6
+ exports.validate = validate;
7
+ exports.createValidationMiddleware = createValidationMiddleware;
8
+ const error_utility_1 = require("../utilities/error.utility");
9
+ // ─── Error Conversion ────────────────────────────────────────────────────────
10
+ /**
11
+ * Flatten a {@link z.ZodError} into a field-keyed record and wrap it
12
+ * in the project's {@link ValidationError}.
13
+ *
14
+ * @param error - The raw Zod validation error
15
+ * @param context - Optional human-readable context label (e.g. "Login validation")
16
+ *
17
+ * @example
18
+ * try {
19
+ * LoginSchema.parse(body);
20
+ * } catch (err) {
21
+ * if (err instanceof z.ZodError) {
22
+ * throw zodToValidationError(err, 'Login');
23
+ * }
24
+ * }
25
+ */
26
+ function zodToValidationError(error, context) {
27
+ const fieldErrors = {};
28
+ for (const issue of error.issues) {
29
+ const path = issue.path.join('.') || '_root';
30
+ const msg = issue.message;
31
+ const existing = fieldErrors[path];
32
+ if (existing !== undefined) {
33
+ fieldErrors[path] = Array.isArray(existing) ? [...existing, msg] : [existing, msg];
34
+ }
35
+ else {
36
+ fieldErrors[path] = msg;
37
+ }
38
+ }
39
+ return new error_utility_1.ValidationError(context ?? 'Validation failed', fieldErrors);
40
+ }
41
+ // ─── Safe Parse ──────────────────────────────────────────────────────────────
42
+ /**
43
+ * Parse `data` against `schema`, converting any ZodError into a
44
+ * {@link ValidationError} automatically.
45
+ *
46
+ * @throws {@link ValidationError} when validation fails
47
+ *
48
+ * @example
49
+ * const loginInput = safeParse(LoginSchema, req.body, 'Login');
50
+ */
51
+ function safeParse(schema, data, context) {
52
+ const result = schema.safeParse(data);
53
+ if (!result.success) {
54
+ throw zodToValidationError(result.error, context);
55
+ }
56
+ return result.data;
57
+ }
58
+ /**
59
+ * Async variant of {@link safeParse} – necessary when the schema uses
60
+ * `.refine()` with an async callback.
61
+ *
62
+ * @throws {@link ValidationError} when validation fails
63
+ */
64
+ async function safeParseAsync(schema, data, context) {
65
+ const result = await schema.safeParseAsync(data);
66
+ if (!result.success) {
67
+ throw zodToValidationError(result.error, context);
68
+ }
69
+ return result.data;
70
+ }
71
+ // ─── Method Decorator ────────────────────────────────────────────────────────
72
+ /**
73
+ * Method decorator that validates the **first argument** of the decorated
74
+ * method against `schema` before the original method body executes.
75
+ *
76
+ * @example
77
+ * class UserService {
78
+ * \@validate(LoginSchema)
79
+ * async login(data: LoginInput) { ... }
80
+ * }
81
+ */
82
+ function validate(schema, context) {
83
+ return function (_target, propertyKey, descriptor) {
84
+ const originalMethod = descriptor.value;
85
+ descriptor.value = async function (data, ...rest) {
86
+ const validated = safeParse(schema, data, context ?? propertyKey);
87
+ return originalMethod.call(this, validated, ...rest);
88
+ };
89
+ return descriptor;
90
+ };
91
+ }
92
+ // ─── Express / LoopBack Middleware ───────────────────────────────────────────
93
+ /**
94
+ * Builds an Express-compatible middleware that validates `req.body` against
95
+ * `schema`. On success, the parsed + transformed data is assigned to
96
+ * `req.validatedBody`. On failure, a `400` JSON response is returned.
97
+ *
98
+ * @example
99
+ * router.post('/login', createValidationMiddleware(LoginSchema), loginHandler);
100
+ */
101
+ function createValidationMiddleware(schema, context) {
102
+ return (req, res, next) => {
103
+ const result = schema.safeParse(req.body);
104
+ if (!result.success) {
105
+ const validationError = zodToValidationError(result.error, context);
106
+ res.status(400).json({
107
+ code: 'VALIDATION_ERROR',
108
+ message: validationError.message,
109
+ details: validationError.context,
110
+ });
111
+ return;
112
+ }
113
+ req.validatedBody = result.data;
114
+ next();
115
+ };
116
+ }
117
+ //# sourceMappingURL=with-zod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-zod.js","sourceRoot":"","sources":["../../src/validators/with-zod.ts"],"names":[],"mappings":";;AA0BA,oDAgBC;AAaD,8BAMC;AAQD,wCAUC;AAcD,4BAWC;AAYD,gEAqBC;AAxID,6DAA4D;AAO5D,gFAAgF;AAEhF;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,oBAAoB,CAAC,KAAiB,EAAE,OAAgB;IACtE,MAAM,WAAW,GAAsC,EAAE,CAAC;IAE1D,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC;QAC7C,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC;QAE1B,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,WAAW,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrF,CAAC;aAAM,CAAC;YACN,WAAW,CAA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