@lyxa.ai/core 1.0.7 → 1.0.8-debug-1
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.
- package/dist/libraries/auth/index.js +1 -1
- package/dist/libraries/auth/index.js.map +1 -1
- package/dist/libraries/mongo/models/work-hour.model.d.ts +21 -0
- package/dist/libraries/mongo/models/work-hour.model.js +76 -0
- package/dist/libraries/mongo/models/work-hour.model.js.map +1 -0
- package/dist/libraries/redis/index.js +2 -1
- package/dist/libraries/redis/index.js.map +1 -1
- package/dist/libraries/secrets/index.js +1 -0
- package/dist/libraries/secrets/index.js.map +1 -1
- package/dist/utilities/enum.d.ts +53 -0
- package/dist/utilities/enum.js +67 -0
- package/dist/utilities/enum.js.map +1 -0
- package/dist/utilities/transformers.d.ts +2 -2
- package/dist/utilities/transformers.js +12 -6
- package/dist/utilities/transformers.js.map +1 -1
- package/dist/utilities/validation/common-validation.d.ts +65 -0
- package/dist/utilities/validation/common-validation.js +60 -0
- package/dist/utilities/validation/common-validation.js.map +1 -0
- package/dist/utilities/validation/global-validation.d.ts +128 -0
- package/dist/utilities/validation/global-validation.js +150 -0
- package/dist/utilities/validation/global-validation.js.map +1 -0
- package/dist/utilities/validation/index.d.ts +2 -0
- package/dist/utilities/validation/index.js +19 -0
- package/dist/utilities/validation/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -23,7 +23,7 @@ async function signToken(entity, options) {
|
|
|
23
23
|
.getSecretsService()
|
|
24
24
|
.getKey(`${entity.type.toUpperCase()}_JWT_TOKEN`);
|
|
25
25
|
if (!secret) {
|
|
26
|
-
throw new Error(`No secret found for entity type
|
|
26
|
+
throw new Error(`No secret found for entity type ${entity.type}`);
|
|
27
27
|
}
|
|
28
28
|
const payload = {
|
|
29
29
|
id: entity.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/auth/index.ts"],"names":[],"mappings":";;;;;;AAeA,8BAu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AAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,OAAO,GAAG;QACZ,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,UAAU,EAAE,MAAM,CAAC,UAAU;KAChC,CAAC;IAEF,OAAO,sBAAG,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,WAA6B,EAAE,KAAa;IAC1E,KAAI,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAY,GAAE,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,YAAY,CAAC,CAAC;QAExG,IAAI,CAAC;YACD,OAAO,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAO,CAAkB,CAAC;QACvD,CAAC;QAAC,OAAM,GAAG,EAAE,CAAC;QACd,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import jwt, {SignOptions} from \"jsonwebtoken\";\r\nimport {getLibraries} from \"../../index\";\r\nimport {EntityContext} from \"../trpc/context\";\r\n\r\nexport enum AuthEntityType {\r\n USER = \"USER\",\r\n SELLER = \"SELLER\",\r\n DELIVERY_BOY = \"DELIVERY_BOY\",\r\n CRM = \"CRM\"\r\n}\r\n\r\n/**\r\n * Sign a JWT for the given entity (id + type).\r\n * It will fetch the secret for that entity type and create a token.\r\n */\r\nexport async function signToken(\r\n entity: { id: string; type: AuthEntityType, parameters: Record<string, unknown> },\r\n options?: SignOptions\r\n): Promise<string> {\r\n if (!entity?.type) {\r\n throw new Error('Entity type is required to sign token');\r\n }\r\n\r\n const secret = await getLibraries()\r\n .getSecretsService()\r\n .getKey(`${entity.type.toUpperCase()}_JWT_TOKEN`);\r\n\r\n if (!secret) {\r\n throw new Error(`No secret found for entity type ${entity.type}`);\r\n }\r\n\r\n const payload = {\r\n id: entity.id,\r\n type: entity.type,\r\n parameters: entity.parameters,\r\n };\r\n\r\n return jwt.sign(payload, secret, options);\r\n}\r\n\r\nexport async function verifyToken(entityTypes: AuthEntityType[], token: string): Promise<EntityContext | undefined> {\r\n for(const entityType of entityTypes) {\r\n const secret = await getLibraries().getSecretsService().getKey(entityType.toUpperCase() + \"_JWT_TOKEN\");\r\n\r\n try {\r\n return jwt.verify(token, secret!) as EntityContext;\r\n } catch(err) {\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WeekDay, WorkStatus } from "../../../utilities/enum";
|
|
2
|
+
declare class StartEndTime {
|
|
3
|
+
start?: string;
|
|
4
|
+
end?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class NormalHour {
|
|
7
|
+
day: WeekDay;
|
|
8
|
+
status: WorkStatus;
|
|
9
|
+
openingHours?: StartEndTime[];
|
|
10
|
+
}
|
|
11
|
+
type HolidayWorkStatus = Exclude<WorkStatus, WorkStatus.OPEN>;
|
|
12
|
+
export declare class HolidayHour {
|
|
13
|
+
date?: Date;
|
|
14
|
+
status: HolidayWorkStatus;
|
|
15
|
+
closingHour?: StartEndTime[];
|
|
16
|
+
}
|
|
17
|
+
export declare class WrokHourSetting {
|
|
18
|
+
normalHours?: NormalHour[];
|
|
19
|
+
holidayHours?: HolidayHour[];
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WrokHourSetting = exports.HolidayHour = exports.NormalHour = void 0;
|
|
13
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
14
|
+
const enum_1 = require("../../../utilities/enum");
|
|
15
|
+
class StartEndTime {
|
|
16
|
+
start;
|
|
17
|
+
end;
|
|
18
|
+
}
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], StartEndTime.prototype, "start", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typegoose_1.prop)({ type: String }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], StartEndTime.prototype, "end", void 0);
|
|
27
|
+
class NormalHour {
|
|
28
|
+
day;
|
|
29
|
+
status;
|
|
30
|
+
openingHours;
|
|
31
|
+
}
|
|
32
|
+
exports.NormalHour = NormalHour;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typegoose_1.prop)({ required: true, unique: true, type: Number, enum: enum_1.WeekDay }),
|
|
35
|
+
__metadata("design:type", Number)
|
|
36
|
+
], NormalHour.prototype, "day", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typegoose_1.prop)({ required: true, type: String, enum: enum_1.WorkStatus }),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], NormalHour.prototype, "status", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typegoose_1.prop)({ type: () => [StartEndTime], default: [] }),
|
|
43
|
+
__metadata("design:type", Array)
|
|
44
|
+
], NormalHour.prototype, "openingHours", void 0);
|
|
45
|
+
class HolidayHour {
|
|
46
|
+
date;
|
|
47
|
+
status;
|
|
48
|
+
closingHour;
|
|
49
|
+
}
|
|
50
|
+
exports.HolidayHour = HolidayHour;
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, typegoose_1.prop)({ type: Date }),
|
|
53
|
+
__metadata("design:type", Date)
|
|
54
|
+
], HolidayHour.prototype, "date", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, typegoose_1.prop)({ required: true, type: String, enum: [enum_1.WorkStatus.CLOSED, enum_1.WorkStatus.FULL_DAY] }),
|
|
57
|
+
__metadata("design:type", String)
|
|
58
|
+
], HolidayHour.prototype, "status", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, typegoose_1.prop)({ type: StartEndTime }),
|
|
61
|
+
__metadata("design:type", Array)
|
|
62
|
+
], HolidayHour.prototype, "closingHour", void 0);
|
|
63
|
+
class WrokHourSetting {
|
|
64
|
+
normalHours;
|
|
65
|
+
holidayHours;
|
|
66
|
+
}
|
|
67
|
+
exports.WrokHourSetting = WrokHourSetting;
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, typegoose_1.prop)({ type: () => [NormalHour], default: [] }),
|
|
70
|
+
__metadata("design:type", Array)
|
|
71
|
+
], WrokHourSetting.prototype, "normalHours", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, typegoose_1.prop)({ type: () => [HolidayHour], default: [] }),
|
|
74
|
+
__metadata("design:type", Array)
|
|
75
|
+
], WrokHourSetting.prototype, "holidayHours", void 0);
|
|
76
|
+
//# sourceMappingURL=work-hour.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-hour.model.js","sourceRoot":"/","sources":["libraries/mongo/models/work-hour.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAC5C,kDAA8D;AAE9D,MAAM,YAAY;IAEV,KAAK,CAAU;IAGf,GAAG,CAAU;CAC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UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;oDACd;AAG3B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;qDACb","sourcesContent":["import { prop } from \"@typegoose/typegoose\";\r\nimport { WeekDay, WorkStatus } from \"../../../utilities/enum\";\r\n\r\nclass StartEndTime {\r\n\t@prop({ type: String })\r\n\tpublic start?: string;\r\n\r\n\t@prop({ type: String })\r\n\tpublic end?: string;\r\n}\r\n\r\nexport class NormalHour {\r\n\t@prop({ required: true, unique: true, type: Number, enum: WeekDay })\r\n\tpublic day!: WeekDay;\r\n\r\n\t@prop({ required: true, type: String, enum: WorkStatus })\r\n\tpublic status!: WorkStatus;\r\n\r\n\t@prop({ type: () => [StartEndTime], default: [] })\r\n\tpublic openingHours?: StartEndTime[];\r\n}\r\n\r\ntype HolidayWorkStatus = Exclude<WorkStatus, WorkStatus.OPEN>;\r\n\r\nexport class HolidayHour {\r\n\t@prop({ type: Date })\r\n\tpublic date?: Date;\r\n\r\n\t@prop({ required: true, type: String, enum: [WorkStatus.CLOSED, WorkStatus.FULL_DAY] })\r\n\tpublic status!: HolidayWorkStatus;\r\n\r\n\t@prop({ type: StartEndTime })\r\n\tpublic closingHour?: StartEndTime[];\r\n}\r\n\r\nexport class WrokHourSetting {\r\n\t@prop({ type: () => [NormalHour], default: [] })\r\n\tpublic normalHours?: NormalHour[];\r\n\r\n\t@prop({ type: () => [HolidayHour], default: [] })\r\n\tpublic holidayHours?: HolidayHour[];\r\n}"]}
|
|
@@ -19,7 +19,8 @@ let RedisService = class RedisService {
|
|
|
19
19
|
_redisClient;
|
|
20
20
|
constructor(redisURL) {
|
|
21
21
|
this._redisClient = new ioredis_1.default(redisURL);
|
|
22
|
-
|
|
22
|
+
console.log("Attempting to connecting " + redisURL);
|
|
23
|
+
this._redisClient.connect().then(r => console.log("Connected to Redis")).catch(e => console.log("Error whilst connecting to redis: " + e));
|
|
23
24
|
}
|
|
24
25
|
get redisClient() {
|
|
25
26
|
return this._redisClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA2B;AAC3B,mCAA+B;AAGxB,IAAM,YAAY,GAAlB,MAAM,YAAY;IACb,YAAY,CAAS;IAE7B,YAAY,QAAgB;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAK,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA2B;AAC3B,mCAA+B;AAGxB,IAAM,YAAY,GAAlB,MAAM,YAAY;IACb,YAAY,CAAS;IAE7B,YAAY,QAAgB;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAK,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,2BAA2B,GAAG,QAAQ,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAC3F,oCAAoC,GAAG,CAAC,CAC3C,CAAC,CAAA;IACN,CAAC;IAED,IAAI,WAAW;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,eAAe,CAAI,GAAW;QACvC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEtD,IAAG,aAAa,IAAI,SAAS,EAAE,CAAC;YAC5B,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,EAAE,GAAW;QAChE,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QACxC,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,WAAW,CAAC,GAAW;QAC1B,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3E,CAAC;CACJ,CAAA;AAnEY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CAmExB","sourcesContent":["import Redis from \"ioredis\"\r\nimport {Service} from \"typedi\";\r\n\r\n@Service()\r\nexport class RedisService {\r\n private _redisClient!: Redis;\r\n\r\n constructor(redisURL: string) {\r\n this._redisClient = new Redis(redisURL);\r\n console.log(\"Attempting to connecting \" + redisURL);\r\n this._redisClient.connect().then(r => console.log(\"Connected to Redis\")).catch(e => console.log(\r\n \"Error whilst connecting to redis: \" + e\r\n ))\r\n }\r\n\r\n get redisClient(): Redis {\r\n return this._redisClient;\r\n }\r\n\r\n public async getCachedObject<T>(key: string): Promise<T | undefined> {\r\n const usageResponse = await this._redisClient.get(key)\r\n\r\n if(usageResponse != undefined) {\r\n return JSON.parse(usageResponse) as T\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n public async cacheObject<T>(key: string, object: T, expiry?: number): Promise<boolean> {\r\n const stringifiedObject = JSON.stringify(object);\r\n\r\n if(expiry) {\r\n await this._redisClient.setex(key, expiry, stringifiedObject)\r\n } else {\r\n await this._redisClient.set(key, stringifiedObject)\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public async deleteCachedObject(key: string): Promise<boolean> {\r\n await this._redisClient.del(key);\r\n return true;\r\n }\r\n\r\n public async getCachedObjectByGroup<T>(group: string, key: string): Promise<T | undefined> {\r\n const usageResponse = await this._redisClient.hget(group, key)\r\n\r\n if(usageResponse != undefined) {\r\n return JSON.parse(usageResponse) as T\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n public async setCachedObjectByGroup<T>(group: string, key: string, object: T): Promise<boolean> {\r\n const stringifiedObject = JSON.stringify(object);\r\n await this._redisClient.hset(group, key, stringifiedObject)\r\n\r\n return true;\r\n }\r\n\r\n public async deleteCachedObjectByGroup<T>(group: string, key: string): Promise<boolean> {\r\n await this._redisClient.hdel(group, key)\r\n return true;\r\n }\r\n\r\n public sanitizeKey(key: string) {\r\n return key.replace(/[^\\w\\s]/gi, '').replace(/\\s+/g, '-').toLowerCase();\r\n }\r\n}\r\n"]}
|
|
@@ -35,6 +35,7 @@ let SecretManagerService = class SecretManagerService {
|
|
|
35
35
|
}
|
|
36
36
|
async getKey(key) {
|
|
37
37
|
const environmentTransformedKey = this._configurationService.options.environment + "_" + key;
|
|
38
|
+
console.log("Attempting to fetch the following secret key: " + environmentTransformedKey);
|
|
38
39
|
try {
|
|
39
40
|
const data = await this._redisManager.getCachedObjectByGroup(this._configurationService.options.environment + "_KEYS", key);
|
|
40
41
|
if (data != undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/secrets/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iEAAwE;AACxE,mCAA+B;AAC/B,oCAAsC;AACtC,oDAAsD;AAG/C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACrB,qBAAqB,CAAwB;IAC7C,aAAa,CAAgB;IAC7B,OAAO,CAA8B;IAE7C,YAAY,oBAA0C,EAAE,YAA0B;QAC9E,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;QAClD,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,2CAA0B,CAAC;YAC1C,WAAW,EAAE;gBACT,SAAS,EAAE,uBAAuB;gBAClC,cAAc,EAAE,0CAA0C;gBAC1D,IAAI,EAAE,iBAAiB;gBACvB,eAAe,EAAE,gBAAgB;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AAC,CAAA;YAEF,MAAM,GAAG,GAAG,cAAc,CAAC,OAAQ,CAAC,IAAK,CAAC,QAAQ,EAAE,CAAA;YACpD,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAE5B,OAAO,GAAG,CAAA;QACd,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,KAAa;QAC1C,MAAM,IAAI,CAAC,aAAa,CAAC,sBAAsB,CAAS,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,WAAW,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;QAC7H,OAAO,KAAK,CAAA;IAChB,CAAC;CAEJ,CAAA;AAnDY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,gBAAO,GAAE;qCAM4B,oCAAoB,EAAgB,oBAAY;GALzE,oBAAoB,CAmDhC","sourcesContent":["\r\nimport {SecretManagerServiceClient} from \"@google-cloud/secret-manager\";\r\nimport {Service} from \"typedi\";\r\nimport {RedisService} from \"../redis\";\r\nimport {ConfigurationService} from \"../configuration\";\r\n\r\n@Service()\r\nexport class SecretManagerService {\r\n private _configurationService!: ConfigurationService;\r\n private _redisManager!: RedisService;\r\n private _client!: SecretManagerServiceClient;\r\n\r\n constructor(configurationService: ConfigurationService, redisManager: RedisService) {\r\n this._configurationService = configurationService;\r\n this._redisManager = redisManager;\r\n this._client = new SecretManagerServiceClient({\r\n credentials: {\r\n client_id: \"107840895824406590900\",\r\n private_key_id: \"ece1ebdfde57414700f23f1f4014f5e83d4f7644\",\r\n type: \"service_account\",\r\n universe_domain: \"googleapis.com\",\r\n projectId: \"for-poc-325210\",\r\n private_key: \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDPTk9M5n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T2BzEwKBgQDlVD5lktDOQtWtj+yC607bVAZzhrCbUfX8FFEh6ZL3A2zgzXhN\\nZmBtaqfew3URf47UICy894MrCyYi2gSOZCfoz2vu+egLt0QBw/lCOQ4dD1gM/u+B\\nP5wifI14eIb2dLCZBV/83F5n24zo4gjBSNfS/6Jcbs/KvbAfjCptTkX10wKBgDxb\\nwy5WtlRVcqxaf50ilWzr8I/7fH7YceYDG4EbKxTHD0m+BOjbhrlmAlMO2sIUM3WK\\nfpmPCZiuLyCTmuC+kd8xK5ap79h3libgh/2/ReUpvdBhm+PQDOLC4CtCPYdtIn7T\\nP57jN8dRLXJokIIIBw+nH32dS62AQ9oXWYvZ1UKzAoGBAOWOSphZMnPlLeLN54/4\\nwKPI+D6G1JhzqQrUf8Z99J7m3r3ya+0ug5gRGQCoSRfqz9o87+fLCdSdc38L+j4T\\nBnuwIcY6n4LF+3yAPIF1rnrIBFRqzPta7epYPXHtUTvWOkEkKzNmsFVCZKF7nQjS\\ns/ucyyfUssPsTznYW3gXf3To\\n-----END PRIVATE KEY-----\\n\",\r\n client_email: \"lyxa-core@for-poc-325210.iam.gserviceaccount.com\"\r\n }\r\n })\r\n }\r\n\r\n public async getKey(key: string): Promise<string | undefined> {\r\n const environmentTransformedKey = this._configurationService.options.environment + \"_\" + key;\r\n\r\n console.log(\"Attempting to fetch the following secret key: \" + environmentTransformedKey);\r\n\r\n try {\r\n const data = await this._redisManager.getCachedObjectByGroup<string>(this._configurationService.options.environment + \"_KEYS\", key)\r\n\r\n if(data != undefined) {\r\n return data\r\n }\r\n\r\n const [accessResponse] = await this._client.accessSecretVersion({\r\n name: \"projects/899369746265/secrets/\" + environmentTransformedKey + \"/versions/latest\",\r\n })\r\n\r\n const val = accessResponse.payload!.data!.toString()\r\n await this.setKey(key, val);\r\n\r\n return val\r\n } catch (e) {\r\n console.error(e);\r\n }\r\n }\r\n\r\n public async setKey(key: string, value: string): Promise<string> {\r\n await this._redisManager.setCachedObjectByGroup<string>(this._configurationService.options.environment + \"_KEYS\", key, value)\r\n return value\r\n }\r\n\r\n}\r\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare enum Status {
|
|
2
|
+
ACTIVE = "active",
|
|
3
|
+
INACTIVE = "inactive"
|
|
4
|
+
}
|
|
5
|
+
export declare enum ItemType {
|
|
6
|
+
FOOD = "food",
|
|
7
|
+
GROCERY = "grocery",
|
|
8
|
+
PHARMACY = "pharmacy",
|
|
9
|
+
COFFEE = "coffee",
|
|
10
|
+
FLOWER = "flower",
|
|
11
|
+
PET = "pet",
|
|
12
|
+
HEALTHY_CORNER = "healthy_corner"
|
|
13
|
+
}
|
|
14
|
+
export declare enum WeekDay {
|
|
15
|
+
Sunday = 0,
|
|
16
|
+
Monday = 1,
|
|
17
|
+
Tuesday = 2,
|
|
18
|
+
Wednesday = 3,
|
|
19
|
+
Thursday = 4,
|
|
20
|
+
Friday = 5,
|
|
21
|
+
Saturday = 6
|
|
22
|
+
}
|
|
23
|
+
export declare enum WorkStatus {
|
|
24
|
+
OPEN = "open",
|
|
25
|
+
CLOSED = "closed",
|
|
26
|
+
FULL_DAY = "full_day"
|
|
27
|
+
}
|
|
28
|
+
export declare enum ValueType {
|
|
29
|
+
PERCENTAGE = "percentage",
|
|
30
|
+
FIXED = "fixed"
|
|
31
|
+
}
|
|
32
|
+
export declare enum PaymentMethod {
|
|
33
|
+
CASH = "cash",
|
|
34
|
+
CARD = "card"
|
|
35
|
+
}
|
|
36
|
+
export declare enum PaymentStatus {
|
|
37
|
+
PAID = "paid",
|
|
38
|
+
PENDING = "pending",
|
|
39
|
+
FAILED = "failed"
|
|
40
|
+
}
|
|
41
|
+
export declare enum PaidCurrency {
|
|
42
|
+
BASE = "base",
|
|
43
|
+
SECONDARY = "secondary",
|
|
44
|
+
MIXED = "mixed"
|
|
45
|
+
}
|
|
46
|
+
export declare enum SubscriptionPackage {
|
|
47
|
+
MONTHLY = "monthly",
|
|
48
|
+
YEARLY = "yearly"
|
|
49
|
+
}
|
|
50
|
+
export declare enum RatingAccountType {
|
|
51
|
+
SHOP = "shop",
|
|
52
|
+
RIDER = "rider"
|
|
53
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RatingAccountType = exports.SubscriptionPackage = exports.PaidCurrency = exports.PaymentStatus = exports.PaymentMethod = exports.ValueType = exports.WorkStatus = exports.WeekDay = exports.ItemType = exports.Status = void 0;
|
|
4
|
+
var Status;
|
|
5
|
+
(function (Status) {
|
|
6
|
+
Status["ACTIVE"] = "active";
|
|
7
|
+
Status["INACTIVE"] = "inactive";
|
|
8
|
+
})(Status || (exports.Status = Status = {}));
|
|
9
|
+
var ItemType;
|
|
10
|
+
(function (ItemType) {
|
|
11
|
+
ItemType["FOOD"] = "food";
|
|
12
|
+
ItemType["GROCERY"] = "grocery";
|
|
13
|
+
ItemType["PHARMACY"] = "pharmacy";
|
|
14
|
+
ItemType["COFFEE"] = "coffee";
|
|
15
|
+
ItemType["FLOWER"] = "flower";
|
|
16
|
+
ItemType["PET"] = "pet";
|
|
17
|
+
ItemType["HEALTHY_CORNER"] = "healthy_corner";
|
|
18
|
+
})(ItemType || (exports.ItemType = ItemType = {}));
|
|
19
|
+
var WeekDay;
|
|
20
|
+
(function (WeekDay) {
|
|
21
|
+
WeekDay[WeekDay["Sunday"] = 0] = "Sunday";
|
|
22
|
+
WeekDay[WeekDay["Monday"] = 1] = "Monday";
|
|
23
|
+
WeekDay[WeekDay["Tuesday"] = 2] = "Tuesday";
|
|
24
|
+
WeekDay[WeekDay["Wednesday"] = 3] = "Wednesday";
|
|
25
|
+
WeekDay[WeekDay["Thursday"] = 4] = "Thursday";
|
|
26
|
+
WeekDay[WeekDay["Friday"] = 5] = "Friday";
|
|
27
|
+
WeekDay[WeekDay["Saturday"] = 6] = "Saturday";
|
|
28
|
+
})(WeekDay || (exports.WeekDay = WeekDay = {}));
|
|
29
|
+
var WorkStatus;
|
|
30
|
+
(function (WorkStatus) {
|
|
31
|
+
WorkStatus["OPEN"] = "open";
|
|
32
|
+
WorkStatus["CLOSED"] = "closed";
|
|
33
|
+
WorkStatus["FULL_DAY"] = "full_day";
|
|
34
|
+
})(WorkStatus || (exports.WorkStatus = WorkStatus = {}));
|
|
35
|
+
var ValueType;
|
|
36
|
+
(function (ValueType) {
|
|
37
|
+
ValueType["PERCENTAGE"] = "percentage";
|
|
38
|
+
ValueType["FIXED"] = "fixed";
|
|
39
|
+
})(ValueType || (exports.ValueType = ValueType = {}));
|
|
40
|
+
var PaymentMethod;
|
|
41
|
+
(function (PaymentMethod) {
|
|
42
|
+
PaymentMethod["CASH"] = "cash";
|
|
43
|
+
PaymentMethod["CARD"] = "card";
|
|
44
|
+
})(PaymentMethod || (exports.PaymentMethod = PaymentMethod = {}));
|
|
45
|
+
var PaymentStatus;
|
|
46
|
+
(function (PaymentStatus) {
|
|
47
|
+
PaymentStatus["PAID"] = "paid";
|
|
48
|
+
PaymentStatus["PENDING"] = "pending";
|
|
49
|
+
PaymentStatus["FAILED"] = "failed";
|
|
50
|
+
})(PaymentStatus || (exports.PaymentStatus = PaymentStatus = {}));
|
|
51
|
+
var PaidCurrency;
|
|
52
|
+
(function (PaidCurrency) {
|
|
53
|
+
PaidCurrency["BASE"] = "base";
|
|
54
|
+
PaidCurrency["SECONDARY"] = "secondary";
|
|
55
|
+
PaidCurrency["MIXED"] = "mixed";
|
|
56
|
+
})(PaidCurrency || (exports.PaidCurrency = PaidCurrency = {}));
|
|
57
|
+
var SubscriptionPackage;
|
|
58
|
+
(function (SubscriptionPackage) {
|
|
59
|
+
SubscriptionPackage["MONTHLY"] = "monthly";
|
|
60
|
+
SubscriptionPackage["YEARLY"] = "yearly";
|
|
61
|
+
})(SubscriptionPackage || (exports.SubscriptionPackage = SubscriptionPackage = {}));
|
|
62
|
+
var RatingAccountType;
|
|
63
|
+
(function (RatingAccountType) {
|
|
64
|
+
RatingAccountType["SHOP"] = "shop";
|
|
65
|
+
RatingAccountType["RIDER"] = "rider";
|
|
66
|
+
})(RatingAccountType || (exports.RatingAccountType = RatingAccountType = {}));
|
|
67
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"/","sources":["utilities/enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAGX;AAHD,WAAY,MAAM;IACjB,2BAAiB,CAAA;IACjB,+BAAqB,CAAA;AACtB,CAAC,EAHW,MAAM,sBAAN,MAAM,QAGjB;AAED,IAAY,QAQX;AARD,WAAY,QAAQ;IACnB,yBAAa,CAAA;IACb,+BAAmB,CAAA;IACnB,iCAAqB,CAAA;IACrB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,uBAAW,CAAA;IACX,6CAAiC,CAAA;AAClC,CAAC,EARW,QAAQ,wBAAR,QAAQ,QAQnB;AAED,IAAY,OAQX;AARD,WAAY,OAAO;IAClB,yCAAU,CAAA;IACV,yCAAU,CAAA;IACV,2CAAW,CAAA;IACX,+CAAa,CAAA;IACb,6CAAY,CAAA;IACZ,yCAAU,CAAA;IACV,6CAAY,CAAA;AACb,CAAC,EARW,OAAO,uBAAP,OAAO,QAQlB;AAED,IAAY,UAIX;AAJD,WAAY,UAAU;IACrB,2BAAa,CAAA;IACb,+BAAiB,CAAA;IACjB,mCAAqB,CAAA;AACtB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACpB,sCAAyB,CAAA;IACzB,4BAAe,CAAA;AAChB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACxB,8BAAa,CAAA;IACb,8BAAa,CAAA;AACd,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAED,IAAY,aAIX;AAJD,WAAY,aAAa;IACxB,8BAAa,CAAA;IACb,oCAAmB,CAAA;IACnB,kCAAiB,CAAA;AAClB,CAAC,EAJW,aAAa,6BAAb,aAAa,QAIxB;AAED,IAAY,YAIX;AAJD,WAAY,YAAY;IACvB,6BAAa,CAAA;IACb,uCAAuB,CAAA;IACvB,+BAAe,CAAA;AAChB,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB;AAED,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC9B,0CAAmB,CAAA;IACnB,wCAAiB,CAAA;AAClB,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B;AAED,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC5B,kCAAa,CAAA;IACb,oCAAe,CAAA;AAChB,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B","sourcesContent":["export enum Status {\r\n\tACTIVE = 'active',\r\n\tINACTIVE = 'inactive',\r\n}\r\n\r\nexport enum ItemType {\r\n\tFOOD = 'food',\r\n\tGROCERY = 'grocery',\r\n\tPHARMACY = 'pharmacy',\r\n\tCOFFEE = 'coffee',\r\n\tFLOWER = 'flower',\r\n\tPET = 'pet',\r\n\tHEALTHY_CORNER = 'healthy_corner',\r\n}\r\n\r\nexport enum WeekDay {\r\n\tSunday = 0,\r\n\tMonday = 1,\r\n\tTuesday = 2,\r\n\tWednesday = 3,\r\n\tThursday = 4,\r\n\tFriday = 5,\r\n\tSaturday = 6,\r\n}\r\n\r\nexport enum WorkStatus {\r\n\tOPEN = 'open',\r\n\tCLOSED = 'closed',\r\n\tFULL_DAY = 'full_day',\r\n}\r\n\r\nexport enum ValueType {\r\n\tPERCENTAGE = 'percentage',\r\n\tFIXED = 'fixed',\r\n}\r\n\r\nexport enum PaymentMethod {\r\n\tCASH = 'cash',\r\n\tCARD = 'card',\r\n}\r\n\r\nexport enum PaymentStatus {\r\n\tPAID = 'paid',\r\n\tPENDING = 'pending',\r\n\tFAILED = 'failed',\r\n}\r\n\r\nexport enum PaidCurrency {\r\n\tBASE = 'base',\r\n\tSECONDARY = 'secondary',\r\n\tMIXED = 'mixed',\r\n}\r\n\r\nexport enum SubscriptionPackage {\r\n\tMONTHLY = 'monthly',\r\n\tYEARLY = 'yearly',\r\n}\r\n\r\nexport enum RatingAccountType {\r\n\tSHOP = 'shop',\r\n\tRIDER = 'rider',\r\n}"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DocumentType } from
|
|
2
|
-
import { z } from
|
|
1
|
+
import { DocumentType } from "@typegoose/typegoose";
|
|
2
|
+
import { z } from "zod";
|
|
3
3
|
export declare class GlobalTransformer<ModelType, DTOType> {
|
|
4
4
|
private schema;
|
|
5
5
|
constructor(schema: z.ZodType<any>);
|
|
@@ -53,24 +53,30 @@ let GlobalTransformer = class GlobalTransformer {
|
|
|
53
53
|
}
|
|
54
54
|
transformToBasicView(record) {
|
|
55
55
|
if (!record) {
|
|
56
|
-
throw new Error(
|
|
56
|
+
throw new Error("Record not found");
|
|
57
57
|
}
|
|
58
58
|
return this.schema.parse(record);
|
|
59
59
|
}
|
|
60
60
|
transformToBasicViewArray(records) {
|
|
61
|
-
|
|
61
|
+
if (records.length === 0) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return records.map((record) => this.transformToBasicView(record));
|
|
62
65
|
}
|
|
63
66
|
transformToPartialView(record, fields) {
|
|
64
67
|
const fullView = this.transformToBasicView(record);
|
|
65
68
|
const partialView = {};
|
|
66
|
-
fields.forEach(field => {
|
|
69
|
+
fields.forEach((field) => {
|
|
67
70
|
const dto = fullView;
|
|
68
71
|
partialView[field] = dto[field];
|
|
69
72
|
});
|
|
70
73
|
return partialView;
|
|
71
74
|
}
|
|
72
75
|
transformToPartialViewArray(records, fields) {
|
|
73
|
-
|
|
76
|
+
if (records.length === 0) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
return records.map((record) => this.transformToPartialView(record, fields));
|
|
74
80
|
}
|
|
75
81
|
transformWithAdditionalData(record, additionalData) {
|
|
76
82
|
const basicView = this.transformToBasicView(record);
|
|
@@ -82,9 +88,9 @@ let GlobalTransformer = class GlobalTransformer {
|
|
|
82
88
|
}
|
|
83
89
|
transformNestedProperty(record, path, nestedSchema) {
|
|
84
90
|
if (!record) {
|
|
85
|
-
throw new Error(
|
|
91
|
+
throw new Error("Record not found");
|
|
86
92
|
}
|
|
87
|
-
const parts = path.split(
|
|
93
|
+
const parts = path.split(".");
|
|
88
94
|
let current = record;
|
|
89
95
|
for (const part of parts) {
|
|
90
96
|
if (current && part in current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.js","sourceRoot":"/","sources":["utilities/transformers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"transformers.js","sourceRoot":"/","sources":["utilities/transformers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkLA,8CAWC;AA5LD,iDAA4C;AAC5C,6BAAwB;AAUjB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAMR;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IASvC,oBAAoB,CAAC,MAA+B;QACzD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;IAC9C,CAAC;IAQM,yBAAyB,CAC9B,OAAkC;QAElC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,CAAC;IASM,sBAAsB,CAC3B,MAA+B,EAC/B,MAAyB;QA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AAI,KAAK,EAAE,CAAC;YACzB,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC/B,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,sBAAsB,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC,KAAK,CAAC,OAAO,CAAe,CAAC;IACnD,CAAC;IASM,qBAAqB,CAC1B,MAA+B,EAC/B,QAA0B;QAE1B,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAC;IACzC,CAAC;CACF,CAAA;AA3JY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gBAAO,GAAE;qCAOoB,OAAC,CAAC,OAAO;GAN1B,iBAAiB,CA2J7B;AAWD,SAAgB,iBAAiB,CAC/B,MAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAGrC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,iBAAiB,CAAqB,MAAM,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["import { DocumentType } from \"@typegoose/typegoose\";\r\nimport Container, { Service } from \"typedi\";\r\nimport { z } from \"zod\";\r\n\r\n/**\r\n * GlobalTransformer provides a reusable way to transform Mongoose documents\r\n * into DTOs using Zod schemas for validation and type safety.\r\n *\r\n * @template ModelType - The Mongoose model type\r\n * @template DTOType - The output DTO type\r\n */\r\n@Service()\r\nexport class GlobalTransformer<ModelType, DTOType> {\r\n /**\r\n * Creates a new GlobalTransformer\r\n *\r\n * @param {z.ZodType<any>} schema - Zod schema used for validation and transformation\r\n */\r\n constructor(private schema: z.ZodType<any>) {}\r\n\r\n /**\r\n * Transforms a single document to a DTO\r\n *\r\n * @param {DocumentType<ModelType>} record - The document to transform\r\n * @returns {DTOType} The transformed DTO\r\n * @throws {Error} When record is not found\r\n */\r\n public transformToBasicView(record: DocumentType<ModelType>): DTOType {\r\n if (!record) {\r\n throw new Error(\"Record not found\");\r\n }\r\n\r\n return this.schema.parse(record) as DTOType;\r\n }\r\n\r\n /**\r\n * Transforms an array of documents to DTOs\r\n *\r\n * @param {DocumentType<ModelType>[]} records - Array of documents to transform\r\n * @returns {DTOType[]} Array of transformed DTOs\r\n */\r\n public transformToBasicViewArray(\r\n records: DocumentType<ModelType>[]\r\n ): DTOType[] {\r\n if (records.length === 0) {\r\n return [];\r\n }\r\n return records.map((record) => this.transformToBasicView(record));\r\n }\r\n\r\n /**\r\n * Creates a partial view with only the specified fields\r\n *\r\n * @param {DocumentType<ModelType>} record - The document to transform\r\n * @param {(keyof DTOType)[]} fields - Fields to include in the output\r\n * @returns {Partial<DTOType>} Partial DTO with only the specified fields\r\n */\r\n public transformToPartialView(\r\n record: DocumentType<ModelType>,\r\n fields: (keyof DTOType)[]\r\n ): Partial<DTOType> {\r\n const fullView = this.transformToBasicView(record);\r\n const partialView: Partial<DTOType> = {};\r\n\r\n fields.forEach((field) => {\r\n const dto = fullView as Record<keyof DTOType, any>;\r\n partialView[field] = dto[field];\r\n });\r\n\r\n return partialView;\r\n }\r\n\r\n /**\r\n * Creates partial views for an array of documents\r\n *\r\n * @param {DocumentType<ModelType>[]} records - Array of documents to transform\r\n * @param {(keyof DTOType)[]} fields - Fields to include in the output\r\n * @returns {Partial<DTOType>[]} Array of partial DTOs\r\n */\r\n public transformToPartialViewArray(\r\n records: DocumentType<ModelType>[],\r\n fields: (keyof DTOType)[]\r\n ): Partial<DTOType>[] {\r\n if (records.length === 0) {\r\n return [];\r\n }\r\n return records.map((record) => this.transformToPartialView(record, fields));\r\n }\r\n\r\n /**\r\n * Transforms a document and adds additional computed fields\r\n *\r\n * @param {DocumentType<ModelType>} record - The document to transform\r\n * @param {Partial<Record<string, any>>} additionalData - Additional fields to add\r\n * @returns {DTOType & Record<string, any>} DTO with additional fields\r\n */\r\n public transformWithAdditionalData(\r\n record: DocumentType<ModelType>,\r\n additionalData: Partial<Record<string, any>>\r\n ): DTOType & Record<string, any> {\r\n const basicView = this.transformToBasicView(record);\r\n return { ...basicView, ...additionalData };\r\n }\r\n\r\n /**\r\n * Transforms a document using a custom mapping function\r\n *\r\n * @template OutputType - The output type after mapping\r\n * @param {DocumentType<ModelType>} record - The document to transform\r\n * @param {(input: DTOType) => OutputType} mapFn - Mapping function for custom transformation\r\n * @returns {OutputType} Custom transformed output\r\n */\r\n public transformWithMapping<OutputType = DTOType>(\r\n record: DocumentType<ModelType>,\r\n mapFn: (input: DTOType) => OutputType\r\n ): OutputType {\r\n const basicView = this.transformToBasicView(record);\r\n return mapFn(basicView);\r\n }\r\n\r\n /**\r\n * Transforms a nested property of the document\r\n *\r\n * @template NestedType - The type of the nested property\r\n * @param {DocumentType<ModelType>} record - The document to transform\r\n * @param {string} path - Dot-notation path to the nested property\r\n * @param {z.ZodType<any>} nestedSchema - Zod schema for the nested property\r\n * @returns {NestedType} The transformed nested property\r\n * @throws {Error} When path is not found in record\r\n */\r\n public transformNestedProperty<NestedType>(\r\n record: DocumentType<ModelType>,\r\n path: string,\r\n nestedSchema: z.ZodType<any>\r\n ): NestedType {\r\n if (!record) {\r\n throw new Error(\"Record not found\");\r\n }\r\n\r\n const parts = path.split(\".\");\r\n let current: any = record;\r\n\r\n for (const part of parts) {\r\n if (current && part in current) {\r\n current = current[part];\r\n } else {\r\n throw new Error(`Path ${path} not found in record`);\r\n }\r\n }\r\n\r\n return nestedSchema.parse(current) as NestedType;\r\n }\r\n\r\n /**\r\n * Transforms a document with default values for missing fields\r\n *\r\n * @param {DocumentType<ModelType>} record - The document to transform\r\n * @param {Partial<DTOType>} defaults - Default values for fields\r\n * @returns {DTOType} DTO with defaults applied\r\n */\r\n public transformWithDefaults(\r\n record: DocumentType<ModelType>,\r\n defaults: Partial<DTOType>\r\n ): DTOType {\r\n const transformed = this.transformToBasicView(record);\r\n return { ...defaults, ...transformed };\r\n }\r\n}\r\n\r\n/**\r\n * Creates a transformer instance for the given schema.\r\n * Uses dependency injection if available, falls back to creating a new instance.\r\n *\r\n * @template ModelType - The Mongoose model type\r\n * @template DTOType - The output DTO type\r\n * @param {z.ZodType<any>} schema - Zod schema for validation and transformation\r\n * @returns {GlobalTransformer<ModelType, DTOType>} Instance of GlobalTransformer\r\n */\r\nexport function createTransformer<ModelType, DTOType>(\r\n schema: z.ZodType<any>\r\n): GlobalTransformer<ModelType, DTOType> {\r\n try {\r\n return Container.get(GlobalTransformer) as GlobalTransformer<\r\n ModelType,\r\n DTOType\r\n >;\r\n } catch (error) {\r\n return new GlobalTransformer<ModelType, DTOType>(schema);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
3
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
4
|
+
skip: z.ZodDefault<z.ZodNumber>;
|
|
5
|
+
sort: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<1>, z.ZodLiteral<-1>, z.ZodLiteral<"asc">, z.ZodLiteral<"desc">]>>>;
|
|
6
|
+
query: z.ZodOptional<z.ZodType<Record<string, any>, z.ZodTypeDef, Record<string, any>>>;
|
|
7
|
+
select: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
populate: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
skip: number;
|
|
11
|
+
limit: number;
|
|
12
|
+
sort?: Record<string, 1 | "desc" | -1 | "asc"> | undefined;
|
|
13
|
+
select?: string[] | undefined;
|
|
14
|
+
query?: Record<string, any> | undefined;
|
|
15
|
+
populate?: string[] | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
sort?: Record<string, 1 | "desc" | -1 | "asc"> | undefined;
|
|
18
|
+
select?: string[] | undefined;
|
|
19
|
+
query?: Record<string, any> | undefined;
|
|
20
|
+
skip?: number | undefined;
|
|
21
|
+
limit?: number | undefined;
|
|
22
|
+
populate?: string[] | undefined;
|
|
23
|
+
}>>;
|
|
24
|
+
export type FilterDTO = z.infer<typeof FilterSchema>;
|
|
25
|
+
export declare const StringSchema: z.ZodString;
|
|
26
|
+
export declare const AddressSchema: z.ZodObject<{
|
|
27
|
+
address: z.ZodOptional<z.ZodString>;
|
|
28
|
+
addressDescription: z.ZodOptional<z.ZodString>;
|
|
29
|
+
locationType: z.ZodDefault<z.ZodEnum<["Point", "Polygon"]>>;
|
|
30
|
+
coordinates: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
31
|
+
latitude: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
longitude: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
country: z.ZodOptional<z.ZodString>;
|
|
34
|
+
state: z.ZodOptional<z.ZodString>;
|
|
35
|
+
city: z.ZodOptional<z.ZodString>;
|
|
36
|
+
postCode: z.ZodOptional<z.ZodString>;
|
|
37
|
+
note: z.ZodOptional<z.ZodString>;
|
|
38
|
+
placeId: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
locationType: "Point" | "Polygon";
|
|
41
|
+
coordinates: [number, number];
|
|
42
|
+
state?: string | undefined;
|
|
43
|
+
address?: string | undefined;
|
|
44
|
+
country?: string | undefined;
|
|
45
|
+
addressDescription?: string | undefined;
|
|
46
|
+
latitude?: number | undefined;
|
|
47
|
+
longitude?: number | undefined;
|
|
48
|
+
city?: string | undefined;
|
|
49
|
+
postCode?: string | undefined;
|
|
50
|
+
note?: string | undefined;
|
|
51
|
+
placeId?: string | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
coordinates: [number, number];
|
|
54
|
+
state?: string | undefined;
|
|
55
|
+
address?: string | undefined;
|
|
56
|
+
country?: string | undefined;
|
|
57
|
+
locationType?: "Point" | "Polygon" | undefined;
|
|
58
|
+
addressDescription?: string | undefined;
|
|
59
|
+
latitude?: number | undefined;
|
|
60
|
+
longitude?: number | undefined;
|
|
61
|
+
city?: string | undefined;
|
|
62
|
+
postCode?: string | undefined;
|
|
63
|
+
note?: string | undefined;
|
|
64
|
+
placeId?: string | undefined;
|
|
65
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddressSchema = exports.StringSchema = exports.FilterSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const SortOrderSchema = zod_1.z.union([
|
|
6
|
+
zod_1.z.literal(1),
|
|
7
|
+
zod_1.z.literal(-1),
|
|
8
|
+
zod_1.z.literal("asc"),
|
|
9
|
+
zod_1.z.literal("desc"),
|
|
10
|
+
]);
|
|
11
|
+
const MongoQuerySchema = zod_1.z.lazy(() => zod_1.z.record(zod_1.z.union([zod_1.z.any(), MongoOperatorsSchema])));
|
|
12
|
+
const MongoOperatorsSchema = zod_1.z.object({
|
|
13
|
+
$eq: zod_1.z.any().optional(),
|
|
14
|
+
$ne: zod_1.z.any().optional(),
|
|
15
|
+
$gt: zod_1.z.any().optional(),
|
|
16
|
+
$gte: zod_1.z.any().optional(),
|
|
17
|
+
$lt: zod_1.z.any().optional(),
|
|
18
|
+
$lte: zod_1.z.any().optional(),
|
|
19
|
+
$in: zod_1.z.array(zod_1.z.any()).optional(),
|
|
20
|
+
$nin: zod_1.z.array(zod_1.z.any()).optional(),
|
|
21
|
+
$exists: zod_1.z.boolean().optional(),
|
|
22
|
+
$regex: zod_1.z.string().optional(),
|
|
23
|
+
$and: zod_1.z.array(MongoQuerySchema).optional(),
|
|
24
|
+
$or: zod_1.z.array(MongoQuerySchema).optional(),
|
|
25
|
+
$not: MongoQuerySchema.optional(),
|
|
26
|
+
$nor: zod_1.z.array(MongoQuerySchema).optional(),
|
|
27
|
+
});
|
|
28
|
+
exports.FilterSchema = zod_1.z
|
|
29
|
+
.object({
|
|
30
|
+
limit: zod_1.z
|
|
31
|
+
.number()
|
|
32
|
+
.min(1, { message: "Limit must be greater than 0." })
|
|
33
|
+
.max(100, { message: "Limit cannot exceed 100." })
|
|
34
|
+
.default(10),
|
|
35
|
+
skip: zod_1.z.number().min(0, { message: "Skip cannot be negative." }).default(0),
|
|
36
|
+
sort: zod_1.z.record(zod_1.z.string(), SortOrderSchema).optional(),
|
|
37
|
+
query: MongoQuerySchema.optional(),
|
|
38
|
+
select: zod_1.z.array(zod_1.z.string()).optional(),
|
|
39
|
+
populate: zod_1.z.array(zod_1.z.string()).optional(),
|
|
40
|
+
})
|
|
41
|
+
.optional();
|
|
42
|
+
exports.StringSchema = zod_1.z
|
|
43
|
+
.string()
|
|
44
|
+
.min(1, "String cannot be empty")
|
|
45
|
+
.max(255, "String is too long");
|
|
46
|
+
exports.AddressSchema = zod_1.z.object({
|
|
47
|
+
address: zod_1.z.string().optional(),
|
|
48
|
+
addressDescription: zod_1.z.string().optional(),
|
|
49
|
+
locationType: zod_1.z.enum(["Point", "Polygon"]).default("Point"),
|
|
50
|
+
coordinates: zod_1.z.tuple([zod_1.z.number(), zod_1.z.number()]),
|
|
51
|
+
latitude: zod_1.z.number().optional(),
|
|
52
|
+
longitude: zod_1.z.number().optional(),
|
|
53
|
+
country: zod_1.z.string().optional(),
|
|
54
|
+
state: zod_1.z.string().optional(),
|
|
55
|
+
city: zod_1.z.string().optional(),
|
|
56
|
+
postCode: zod_1.z.string().optional(),
|
|
57
|
+
note: zod_1.z.string().optional(),
|
|
58
|
+
placeId: zod_1.z.string().optional(),
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=common-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-validation.js","sourceRoot":"/","sources":["utilities/validation/common-valid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AE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,kBAAkB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzC,YAAY,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAC3D,WAAW,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\r\n\r\n/**\r\n * Define allowed MongoDB sort orders\r\n */\r\nconst SortOrderSchema = z.union([\r\n z.literal(1),\r\n z.literal(-1),\r\n z.literal(\"asc\"),\r\n z.literal(\"desc\"),\r\n]);\r\n\r\n/**\r\n * Define MongoDB query schema (fields + operators) using lazy evaluation to avoid circular dependency\r\n */\r\nconst MongoQuerySchema: z.ZodType<Record<string, any>> = z.lazy(() =>\r\n z.record(z.union([z.any(), MongoOperatorsSchema]))\r\n);\r\n\r\n/**\r\n * Define allowed MongoDB query operators\r\n */\r\nconst MongoOperatorsSchema = z.object({\r\n $eq: z.any().optional(),\r\n $ne: z.any().optional(),\r\n $gt: z.any().optional(),\r\n $gte: z.any().optional(),\r\n $lt: z.any().optional(),\r\n $lte: z.any().optional(),\r\n $in: z.array(z.any()).optional(),\r\n $nin: z.array(z.any()).optional(),\r\n $exists: z.boolean().optional(),\r\n $regex: z.string().optional(),\r\n $and: z.array(MongoQuerySchema).optional(),\r\n $or: z.array(MongoQuerySchema).optional(),\r\n $not: MongoQuerySchema.optional(),\r\n $nor: z.array(MongoQuerySchema).optional(),\r\n});\r\n\r\n/**\r\n * Define the filter schema using MongoQuerySchema\r\n */\r\nexport const FilterSchema = z\r\n .object({\r\n limit: z\r\n .number()\r\n .min(1, { message: \"Limit must be greater than 0.\" })\r\n .max(100, { message: \"Limit cannot exceed 100.\" })\r\n .default(10),\r\n skip: z.number().min(0, { message: \"Skip cannot be negative.\" }).default(0),\r\n sort: z.record(z.string(), SortOrderSchema).optional(),\r\n query: MongoQuerySchema.optional(),\r\n select: z.array(z.string()).optional(),\r\n populate: z.array(z.string()).optional(),\r\n })\r\n .optional();\r\n\r\n/**\r\n * Infer TypeScript type from Zod schema\r\n */\r\nexport type FilterDTO = z.infer<typeof FilterSchema>;\r\n\r\n/**\r\n * Define String schema\r\n */\r\nexport const StringSchema = z\r\n .string()\r\n .min(1, \"String cannot be empty\")\r\n .max(255, \"String is too long\");\r\n\r\n/**\r\n * Common address validation schema that can be reused across models.\r\n * Provides validation for address-related fields.\r\n *\r\n * @example\r\n * ```typescript\r\n * const userSchema = z.object({\r\n * name: z.string(),\r\n * address: AddressSchema\r\n * });\r\n * ```\r\n */\r\nexport const AddressSchema = z.object({\r\n address: z.string().optional(),\r\n addressDescription: z.string().optional(),\r\n locationType: z.enum([\"Point\", \"Polygon\"]).default(\"Point\"),\r\n coordinates: z.tuple([z.number(), z.number()]),\r\n latitude: z.number().optional(),\r\n longitude: z.number().optional(),\r\n country: z.string().optional(),\r\n state: z.string().optional(),\r\n city: z.string().optional(),\r\n postCode: z.string().optional(),\r\n note: z.string().optional(),\r\n placeId: z.string().optional(),\r\n});\r\n"]}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { mongoose } from '@typegoose/typegoose';
|
|
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>]>;
|
|
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;
|
|
8
|
+
static email(field?: string): z.ZodString;
|
|
9
|
+
static url(field?: string): z.ZodString;
|
|
10
|
+
static phoneNumber(field?: string): z.ZodString;
|
|
11
|
+
static dateString(field?: string): z.ZodEffects<z.ZodString, string, string>;
|
|
12
|
+
static date(field?: string): z.ZodDate;
|
|
13
|
+
static boolean(field?: string): z.ZodBoolean;
|
|
14
|
+
static array<T extends z.ZodTypeAny>(schema: T, field?: string, minItems?: number): z.ZodArray<T, "many">;
|
|
15
|
+
static timestamps(): {
|
|
16
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
17
|
+
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
18
|
+
deletedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
19
|
+
};
|
|
20
|
+
static trackingFields(): {
|
|
21
|
+
createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
22
|
+
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
23
|
+
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>]>>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export type ExcludeFromUpdate = {
|
|
30
|
+
createdAt?: true;
|
|
31
|
+
updatedAt?: true;
|
|
32
|
+
deletedAt?: true;
|
|
33
|
+
createdBy?: true;
|
|
34
|
+
_id?: true;
|
|
35
|
+
} & Record<string, true>;
|
|
36
|
+
export declare class SchemaBuilder<T extends z.ZodRawShape> {
|
|
37
|
+
private includeTimestamps;
|
|
38
|
+
private includeTracking;
|
|
39
|
+
private baseSchema;
|
|
40
|
+
constructor(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean);
|
|
41
|
+
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
|
+
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>]>;
|
|
44
|
+
}>, 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>]>;
|
|
46
|
+
}>>, 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>]>;
|
|
48
|
+
}>>, 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>]>;
|
|
50
|
+
}>> 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>]>;
|
|
52
|
+
}>>[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>]>;
|
|
54
|
+
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>]>;
|
|
56
|
+
}> 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>]>;
|
|
58
|
+
}>[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>]>;
|
|
60
|
+
}> 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>]>;
|
|
62
|
+
}>[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>]>;
|
|
64
|
+
}> 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>]>;
|
|
66
|
+
}>[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>]>;
|
|
68
|
+
}> 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>]>;
|
|
70
|
+
}>[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>]>;
|
|
72
|
+
}> 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>]>;
|
|
74
|
+
}>[k]>; } : never>[k_2]; } : never> | z.ZodObject<{
|
|
75
|
+
[x: string]: z.ZodOptional<z.ZodTypeAny>;
|
|
76
|
+
}, "strip", z.ZodTypeAny, {
|
|
77
|
+
[x: string]: any;
|
|
78
|
+
}, {
|
|
79
|
+
[x: string]: any;
|
|
80
|
+
}>;
|
|
81
|
+
getAllSchemas(excludeFromUpdate?: ExcludeFromUpdate): {
|
|
82
|
+
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
|
+
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>]>;
|
|
85
|
+
}>, 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>]>;
|
|
87
|
+
}>>, 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>]>;
|
|
89
|
+
}>>, 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>]>;
|
|
91
|
+
}>> 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>]>;
|
|
93
|
+
}>>[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>]>;
|
|
95
|
+
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>]>;
|
|
97
|
+
}> 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>]>;
|
|
99
|
+
}>[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>]>;
|
|
101
|
+
}> 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>]>;
|
|
103
|
+
}>[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>]>;
|
|
105
|
+
}> 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>]>;
|
|
107
|
+
}>[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>]>;
|
|
109
|
+
}> 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>]>;
|
|
111
|
+
}>[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>]>;
|
|
113
|
+
}> 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>]>;
|
|
115
|
+
}>[k_4]>; } : never>[k_6]; } : never> | z.ZodObject<{
|
|
116
|
+
[x: string]: z.ZodOptional<z.ZodTypeAny>;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
[x: string]: any;
|
|
119
|
+
}, {
|
|
120
|
+
[x: string]: any;
|
|
121
|
+
}>;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export type CreateDTO<T extends z.ZodType> = z.infer<T>;
|
|
125
|
+
export type EntityDTO<T extends z.ZodType> = z.infer<T>;
|
|
126
|
+
export type UpdateDTO<T extends z.ZodType> = z.infer<T>;
|
|
127
|
+
export type IdDTO = string;
|
|
128
|
+
export declare function createSchemaBuilder<T extends z.ZodRawShape>(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean): SchemaBuilder<T>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaBuilder = exports.ZodValidation = void 0;
|
|
4
|
+
exports.createSchemaBuilder = createSchemaBuilder;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
7
|
+
class ZodValidation {
|
|
8
|
+
static objectId(field = 'Field') {
|
|
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') {
|
|
17
|
+
return zod_1.z.nativeEnum(enumObj, {
|
|
18
|
+
message: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static number(field = 'Field', minLength) {
|
|
22
|
+
const numberSchema = zod_1.z.number({
|
|
23
|
+
required_error: `${field} is required`,
|
|
24
|
+
invalid_type_error: `${field} must be a number`,
|
|
25
|
+
});
|
|
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') {
|
|
39
|
+
return zod_1.z
|
|
40
|
+
.string({ required_error: `${field} is required` })
|
|
41
|
+
.email(`${field} must be a valid email address`);
|
|
42
|
+
}
|
|
43
|
+
static url(field = 'Field') {
|
|
44
|
+
return zod_1.z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);
|
|
45
|
+
}
|
|
46
|
+
static phoneNumber(field = 'Field') {
|
|
47
|
+
return zod_1.z
|
|
48
|
+
.string({ required_error: `${field} is required` })
|
|
49
|
+
.regex(/^[+]{1}(?:[0-9\-\\(\\)\\/.]\s?){6,15}[0-9]{1}$/, `${field} must be a valid phone number`);
|
|
50
|
+
}
|
|
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') {
|
|
63
|
+
return zod_1.z.boolean({
|
|
64
|
+
required_error: `${field} is required`,
|
|
65
|
+
invalid_type_error: `${field} must be a boolean`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
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;
|
|
71
|
+
}
|
|
72
|
+
static timestamps() {
|
|
73
|
+
return {
|
|
74
|
+
createdAt: zod_1.z.date().nullable().optional(),
|
|
75
|
+
updatedAt: zod_1.z.date().nullable().optional(),
|
|
76
|
+
deletedAt: zod_1.z.date().nullable().optional(),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
static trackingFields() {
|
|
80
|
+
return {
|
|
81
|
+
createdBy: ZodValidation.objectId().optional(),
|
|
82
|
+
updatedBy: ZodValidation.objectId().optional(),
|
|
83
|
+
deletedBy: ZodValidation.objectId().optional(),
|
|
84
|
+
...ZodValidation.timestamps(),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.ZodValidation = ZodValidation;
|
|
89
|
+
class SchemaBuilder {
|
|
90
|
+
includeTimestamps;
|
|
91
|
+
includeTracking;
|
|
92
|
+
baseSchema;
|
|
93
|
+
constructor(baseFields, includeTimestamps = true, includeTracking = false) {
|
|
94
|
+
this.includeTimestamps = includeTimestamps;
|
|
95
|
+
this.includeTracking = includeTracking;
|
|
96
|
+
if (includeTracking) {
|
|
97
|
+
this.baseSchema = zod_1.z.object({
|
|
98
|
+
...baseFields,
|
|
99
|
+
...ZodValidation.trackingFields(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else if (includeTimestamps) {
|
|
103
|
+
this.baseSchema = zod_1.z.object({
|
|
104
|
+
...baseFields,
|
|
105
|
+
...ZodValidation.timestamps(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this.baseSchema = zod_1.z.object(baseFields);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getBaseSchema() {
|
|
113
|
+
return this.baseSchema;
|
|
114
|
+
}
|
|
115
|
+
getEntitySchema() {
|
|
116
|
+
return this.baseSchema.extend({
|
|
117
|
+
_id: ZodValidation.objectId(),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
getIdSchema() {
|
|
121
|
+
return ZodValidation.objectId();
|
|
122
|
+
}
|
|
123
|
+
getUpdateSchema(excludeFields = { createdAt: true }) {
|
|
124
|
+
const entitySchema = this.getEntitySchema();
|
|
125
|
+
if (Object.keys(excludeFields).length === 0) {
|
|
126
|
+
return entitySchema.partial();
|
|
127
|
+
}
|
|
128
|
+
const shape = entitySchema._def.shape();
|
|
129
|
+
const filteredShape = {};
|
|
130
|
+
for (const key in shape) {
|
|
131
|
+
if (!excludeFields[key]) {
|
|
132
|
+
filteredShape[key] = shape[key];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return zod_1.z.object(filteredShape).partial();
|
|
136
|
+
}
|
|
137
|
+
getAllSchemas(excludeFromUpdate = { createdAt: true }) {
|
|
138
|
+
return {
|
|
139
|
+
BaseSchema: this.getBaseSchema(),
|
|
140
|
+
EntitySchema: this.getEntitySchema(),
|
|
141
|
+
IdSchema: this.getIdSchema(),
|
|
142
|
+
UpdateSchema: this.getUpdateSchema(excludeFromUpdate),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.SchemaBuilder = SchemaBuilder;
|
|
147
|
+
function createSchemaBuilder(baseFields, includeTimestamps = true, includeTracking = false) {
|
|
148
|
+
return new SchemaBuilder(baseFields, includeTimestamps, includeTracking);
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=global-validation.js.map
|
|
@@ -0,0 +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,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC9D,OAAO,EAAE,WAAW,KAAK,kBAAkB;aAC3C,CAAC;YACF,OAAC,CAAC,UAAU,CAAC,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;SACtE,CAAC,CAAC;IACJ,CAAC;IAiBD,MAAM,CAAC,QAAQ,CAAuB,OAAU,EAAE,QAAgB,OAAO;QACxE,OAAO,OAAC,CAAC,UAAU,CAAC,OAAO,EAAE;YAC5B,OAAO,EAAE,GAAG,KAAK,oBAAoB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACxE,CAAC,CAAC;IACJ,CAAC;IAeD,MAAM,CAAC,MAAM,CAAC,QAAgB,OAAO,EAAE,SAAkB;QACxD,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;YAC7B,cAAc,EAAE,GAAG,KAAK,cAAc;YACtC,kBAAkB,EAAE,GAAG,KAAK,mBAAmB;SAC/C,CAAC,CAAC;QACH,OAAO,SAAS,KAAK,SAAS;YAC7B,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,KAAK,2CAA2C,SAAS,EA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,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC;QAC/B,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;YACzB,IAAI,CAAC,aAAa,CAAC,GAAiC,CAAC,EAAE,CAAC;gBACvD,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACjC,CAAC;QACF,CAAC;QAGD,OAAO,OAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common-validation"), exports);
|
|
18
|
+
__exportStar(require("./global-validation"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/validation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,sDAAoC","sourcesContent":["export * from './common-validation';\r\nexport * from './global-validation';"]}
|