@lyxa.ai/core 1.0.21 → 1.0.23
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/index.js.map +1 -1
- package/dist/libraries/logger/index.d.ts +2 -0
- package/dist/libraries/logger/index.js +17 -1
- package/dist/libraries/logger/index.js.map +1 -1
- package/dist/libraries/mongo/index.js +49 -16
- package/dist/libraries/mongo/index.js.map +1 -1
- package/dist/libraries/mongo/models/cart.model.js +9 -2
- package/dist/libraries/mongo/models/cart.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/price-breakdown.model.d.ts +5 -0
- package/dist/libraries/mongo/models/embedded/price-breakdown.model.js +32 -0
- package/dist/libraries/mongo/models/embedded/price-breakdown.model.js.map +1 -0
- package/dist/libraries/mongo/models/index.d.ts +24 -3
- package/dist/libraries/mongo/models/index.js +26 -5
- package/dist/libraries/mongo/models/index.js.map +1 -1
- package/dist/libraries/mongo/models/line-item.model.d.ts +4 -4
- package/dist/libraries/mongo/models/line-item.model.js +8 -8
- package/dist/libraries/mongo/models/line-item.model.js.map +1 -1
- package/dist/libraries/mongo/models/product.model.d.ts +24 -7
- package/dist/libraries/mongo/models/product.model.js +84 -19
- package/dist/libraries/mongo/models/product.model.js.map +1 -1
- package/dist/libraries/mongo/models/shared/work-hour.model.js +1 -1
- package/dist/libraries/mongo/models/shared/work-hour.model.js.map +1 -1
- package/dist/libraries/mongo/models/shop-access-control.model.js +10 -6
- package/dist/libraries/mongo/models/shop-access-control.model.js.map +1 -1
- package/dist/libraries/mongo/models/shop-product.model.d.ts +4 -4
- package/dist/libraries/mongo/models/shop-product.model.js +7 -7
- package/dist/libraries/mongo/models/shop-product.model.js.map +1 -1
- package/dist/libraries/mongo/models/shop.model.js.map +1 -1
- package/dist/libraries/trpc/index.d.ts +99 -9
- package/dist/libraries/trpc/index.js +22 -1
- package/dist/libraries/trpc/index.js.map +1 -1
- package/dist/libraries/trpc/middlewares/auth.d.ts +11 -1
- package/dist/utilities/common/password.d.ts +1 -0
- package/dist/utilities/common/password.js +12 -0
- package/dist/utilities/common/password.js.map +1 -0
- package/dist/utilities/common/week.d.ts +1 -0
- package/dist/utilities/common/week.js +5 -0
- package/dist/utilities/common/week.js.map +1 -0
- package/dist/utilities/enum.d.ts +9 -6
- package/dist/utilities/enum.js +21 -17
- package/dist/utilities/enum.js.map +1 -1
- package/dist/utilities/error-handler.js +20 -5
- package/dist/utilities/error-handler.js.map +1 -1
- package/dist/utilities/transformers.js.map +1 -1
- package/dist/utilities/validation/common-validation.d.ts +110 -110
- package/dist/utilities/validation/common-validation.js +5 -2
- package/dist/utilities/validation/common-validation.js.map +1 -1
- package/dist/utilities/validation/global-validation.d.ts +19 -5
- package/dist/utilities/validation/global-validation.js +34 -14
- package/dist/utilities/validation/global-validation.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.js","sourceRoot":"/","sources":["utilities/error-handler.ts"],"names":[],"mappings":";;;AAKA,yCAAyC;AACzC,qCAA0E;AAC1E,6BAA+B;AAM/B,MAAa,YAAY;IAKhB,MAAM,CAAU,MAAM,GAAG;QAEhC,eAAe,EAAE,IAAI;QAErB,kBAAkB,EAAE,EAAE;QAEtB,eAAe,EAAE,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;KAC9E,CAAC;IAMM,MAAM,CAAU,iBAAiB,GAMrC;QACH,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,+DAA+D,EAAE;QACrG,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,sCAAsC,EAAE;QAC5E,GAAG,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,6BAA6B,EAAE;QACpE,CAAC,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,6CAA6C,EAAE;QAC5F,E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AE,WAAW;gBACjB,aAAa,EAAE,KAAK;gBACpB,OAAO,EAAE;oBACR,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,IAAI,EAAG,KAA+B,CAAC,IAAI;iBAC3C;aACD,CAAC;QACH,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACvD,CAAC;;AAvTF,oCAwTC","sourcesContent":["/**\r\n * @fileoverview Error handling utility for TRPC and MongoDB operations.\r\n * Provides centralized error handling, logging, and retry mechanisms.\r\n */\r\n\r\nimport { TRPCError } from '@trpc/server';\r\nimport { MongoServerError, MongoError, MongoNetworkError } from 'mongodb';\r\nimport { ZodError } from 'zod';\r\n\r\n/**\r\n * A utility class for handling various types of errors in a TRPC-MongoDB application.\r\n * Provides error transformation, logging, and retry mechanisms.\r\n */\r\nexport class ErrorHandler {\r\n\t/**\r\n\t * Configuration options for error handling behavior\r\n\t * @private\r\n\t */\r\n\tprivate static readonly CONFIG = {\r\n\t\t/** Whether to log errors to console */\r\n\t\tshouldLogErrors: true,\r\n\t\t/** Maximum number of stack trace lines to include in logs */\r\n\t\tmaxStackTraceLines: 10,\r\n\t\t/** Set of error codes that are considered retryable */\r\n\t\tretryableErrors: new Set(['ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'EPIPE']),\r\n\t};\r\n\r\n\t/**\r\n\t * Mapping of MongoDB error codes to TRPC error types and messages\r\n\t * @private\r\n\t */\r\n\tprivate static readonly MONGO_ERROR_CODES: Record<\r\n\t\tnumber,\r\n\t\t{\r\n\t\t\tcode: TRPCError['code'];\r\n\t\t\tmessage: string;\r\n\t\t}\r\n\t> = {\r\n\t\t11000: { code: 'CONFLICT', message: 'Duplicate key error: A record with this value already exists.' },\r\n\t\t11001: { code: 'CONFLICT', message: 'Duplicate key error on index update.' },\r\n\t\t121: { code: 'BAD_REQUEST', message: 'Document validation failed.' },\r\n\t\t7: { code: 'INTERNAL_SERVER_ERROR', message: 'Not primary - database is in recovery mode.' },\r\n\t\t89: { code: 'FORBIDDEN', message: 'Unauthorized operation attempted.' },\r\n\t\t91: { code: 'TIMEOUT', message: 'Operation timeout exceeded.' },\r\n\t\t189: { code: 'BAD_REQUEST', message: 'Invalid modification - document would exceed size limit.' },\r\n\t\t50: { code: 'INTERNAL_SERVER_ERROR', message: 'Database execution error.' },\r\n\t};\r\n\r\n\t/**\r\n\t * Logs error information with metadata and stack trace\r\n\t * @private\r\n\t * @param error - The error to log\r\n\t * @param context - Additional context information for the error\r\n\t */\r\n\tprivate static logError(error: unknown, context: Record<string, unknown> = {}): void {\r\n\t\tif (!this.CONFIG.shouldLogErrors) return;\r\n\r\n\t\tconst errorMeta = this.extractErrorMetadata(error);\r\n\t\tconst timestamp = new Date().toISOString();\r\n\r\n\t\tconst logData = {\r\n\t\t\ttimestamp,\r\n\t\t\ttype: errorMeta.type,\r\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\r\n\t\t\tstack:\r\n\t\t\t\terror instanceof Error\r\n\t\t\t\t\t? error.stack?.split('\\n').slice(0, this.CONFIG.maxStackTraceLines).join('\\n')\r\n\t\t\t\t\t: undefined,\r\n\t\t\tcontext,\r\n\t\t\tmetadata: errorMeta,\r\n\t\t};\r\n\r\n\t\tconsole.error('[ErrorHandler]:', JSON.stringify(logData, null, 2));\r\n\t}\r\n\r\n\t/**\r\n\t * Main error handling method that transforms various error types into TRPC errors\r\n\t * @param error - The error to handle\r\n\t * @param customMessage - Optional custom error message\r\n\t * @param context - Additional context information\r\n\t * @throws {TRPCError} Transformed error with appropriate error code and message\r\n\t */\r\n\tpublic static handleError(\r\n\t\terror: unknown,\r\n\t\tcustomMessage = 'An unexpected error occurred',\r\n\t\tcontext: Record<string, unknown> = {}\r\n\t): never {\r\n\t\tthis.logError(error, context);\r\n\r\n\t\tif (error instanceof TRPCError) {\r\n\t\t\tthrow error;\r\n\t\t}\r\n\r\n\t\tif (error instanceof ZodError) {\r\n\t\t\tthrow new TRPCError({\r\n\t\t\t\tcode: 'BAD_REQUEST',\r\n\t\t\t\tmessage: 'Validation error',\r\n\t\t\t\tcause: error.flatten(),\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tif (error instanceof MongoNetworkError) {\r\n\t\t\tthrow new TRPCError({\r\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\t\tmessage: 'Database connection error',\r\n\t\t\t\tcause: error,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tif (this.isMongoError(error)) {\r\n\t\t\tthrow this.createMongoTRPCError(error);\r\n\t\t}\r\n\r\n\t\tif (error instanceof Error) {\r\n\t\t\tthrow new TRPCError({\r\n\t\t\t\tcode: this.mapNodeErrorCode(error),\r\n\t\t\t\tmessage: error.message || customMessage,\r\n\t\t\t\tcause: error,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tthrow new TRPCError({\r\n\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tmessage: customMessage,\r\n\t\t\tcause: error,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Type guard to check if an error is a MongoDB error\r\n\t * @private\r\n\t * @param error - The error to check\r\n\t * @returns True if the error is a MongoDB error\r\n\t */\r\n\tprivate static isMongoError(error: unknown): error is MongoServerError {\r\n\t\treturn (\r\n\t\t\terror instanceof MongoServerError ||\r\n\t\t\terror instanceof MongoError ||\r\n\t\t\t(typeof error === 'object' &&\r\n\t\t\t\terror !== null &&\r\n\t\t\t\t'code' in error &&\r\n\t\t\t\t'name' in error &&\r\n\t\t\t\t((error as MongoServerError).name === 'MongoServerError' ||\r\n\t\t\t\t\t(error as MongoServerError).name === 'MongoError'))\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a TRPC error from a MongoDB error\r\n\t * @private\r\n\t * @param error - MongoDB error to transform\r\n\t * @returns Transformed TRPC error\r\n\t */\r\n\tprivate static createMongoTRPCError(error: MongoServerError): TRPCError {\r\n\t\tconst errorCode = typeof error.code === 'number' ? error.code : 0;\r\n\t\tconst errorInfo = this.MONGO_ERROR_CODES[errorCode] || {\r\n\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tmessage: `Database error occurred. Code: ${errorCode}`,\r\n\t\t};\r\n\r\n\t\treturn new TRPCError({\r\n\t\t\tcode: errorInfo.code,\r\n\t\t\tmessage: errorInfo.message,\r\n\t\t\tcause: error,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Maps Node.js error codes to TRPC error codes\r\n\t * @private\r\n\t * @param error - Node.js error to map\r\n\t * @returns Appropriate TRPC error code\r\n\t */\r\n\tprivate static mapNodeErrorCode(error: Error): TRPCError['code'] {\r\n\t\tconst nodeErrorMap: Record<string, TRPCError['code']> = {\r\n\t\t\tENOENT: 'NOT_FOUND',\r\n\t\t\tEACCES: 'FORBIDDEN',\r\n\t\t\tECONNREFUSED: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tECONNRESET: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tETIMEDOUT: 'TIMEOUT',\r\n\t\t\tEPIPE: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tENOTFOUND: 'NOT_FOUND',\r\n\t\t\tEINVAL: 'BAD_REQUEST',\r\n\t\t\tEMFILE: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tEPERM: 'FORBIDDEN',\r\n\t\t};\r\n\r\n\t\tconst code = (error as NodeJS.ErrnoException).code;\r\n\t\treturn code ? nodeErrorMap[code] || 'INTERNAL_SERVER_ERROR' : 'INTERNAL_SERVER_ERROR';\r\n\t}\r\n\r\n\t/**\r\n\t * Wraps an async function with error handling\r\n\t * @param fn - Async function to wrap\r\n\t * @param context - Additional context information\r\n\t * @returns Promise resolving to the function's return type\r\n\t * @throws {TRPCError} If the function throws an error\r\n\t */\r\n\tpublic static async wrapAsync<T>(fn: () => Promise<T>, context: Record<string, unknown> = {}): Promise<T> {\r\n\t\ttry {\r\n\t\t\treturn await fn();\r\n\t\t} catch (error) {\r\n\t\t\tthis.handleError(error, undefined, context);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Executes an async function with retry mechanism for transient errors\r\n\t * @param fn - Async function to execute\r\n\t * @param options - Retry configuration options\r\n\t * @returns Promise resolving to the function's return type\r\n\t * @throws {TRPCError} If all retry attempts fail\r\n\t */\r\n\tpublic static async withRetry<T>(\r\n\t\tfn: () => Promise<T>,\r\n\t\toptions: {\r\n\t\t\tmaxAttempts?: number;\r\n\t\t\tdelayMs?: number;\r\n\t\t\tbackoffFactor?: number;\r\n\t\t\tcontext?: Record<string, unknown>;\r\n\t\t} = {}\r\n\t): Promise<T> {\r\n\t\tconst { maxAttempts = 3, delayMs = 1000, backoffFactor = 2, context = {} } = options;\r\n\r\n\t\tlet lastError: unknown;\r\n\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\r\n\t\t\ttry {\r\n\t\t\t\treturn await fn();\r\n\t\t\t} catch (error) {\r\n\t\t\t\tlastError = error;\r\n\r\n\t\t\t\tconst isRetryable = this.isRetryableError(error);\r\n\t\t\t\tconst isLastAttempt = attempt === maxAttempts;\r\n\r\n\t\t\t\tif (!isRetryable || isLastAttempt) {\r\n\t\t\t\t\tthis.handleError(error, undefined, { ...context, attempt });\r\n\t\t\t\t}\r\n\r\n\t\t\t\tawait new Promise(resolve => setTimeout(resolve, delayMs * Math.pow(backoffFactor, attempt - 1)));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tthrow lastError;\r\n\t}\r\n\r\n\t/**\r\n\t * Determines if an error is retryable\r\n\t * @private\r\n\t * @param error - The error to check\r\n\t * @returns True if the error is retryable\r\n\t */\r\n\tprivate static isRetryableError(error: unknown): boolean {\r\n\t\tif (error instanceof MongoNetworkError) return true;\r\n\t\tif (error instanceof Error) {\r\n\t\t\tconst code = (error as NodeJS.ErrnoException).code;\r\n\t\t\treturn code ? this.CONFIG.retryableErrors.has(code) : false;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Extracts metadata from an error for logging and analysis\r\n\t * @param error - The error to extract metadata from\r\n\t * @returns Object containing error type, original error, and additional details\r\n\t */\r\n\tpublic static extractErrorMetadata(error: unknown): {\r\n\t\ttype: string;\r\n\t\toriginalError: unknown;\r\n\t\tdetails?: Record<string, unknown>;\r\n\t} {\r\n\t\tif (error instanceof TRPCError) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'TRPCError',\r\n\t\t\t\toriginalError: error.cause ?? error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tcode: error.code,\r\n\t\t\t\t\tmessage: error.message,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (error instanceof ZodError) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'ZodError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: error.flatten(),\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (error instanceof MongoNetworkError) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'MongoNetworkError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tmessage: error.message,\r\n\t\t\t\t\tisRetryable: true,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (this.isMongoError(error)) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'MongoError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tcode: (error as MongoServerError).code,\r\n\t\t\t\t\tcodeName: (error as MongoServerError).codeName,\r\n\t\t\t\t\tkeyPattern: (error as MongoServerError).keyPattern,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (error instanceof Error) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'NodeError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tname: error.name,\r\n\t\t\t\t\tcode: (error as NodeJS.ErrnoException).code,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\treturn { type: 'UnknownError', originalError: error };\r\n\t}\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"/","sources":["utilities/error-handler.ts"],"names":[],"mappings":";;;AAKA,yCAAyC;AACzC,qCAA0E;AAC1E,6BAA+B;AAM/B,MAAa,YAAY;IAKhB,MAAM,CAAU,MAAM,GAAG;QAEhC,eAAe,EAAE,IAAI;QAErB,kBAAkB,EAAE,EAAE;QAEtB,eAAe,EAAE,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;KAC9E,CAAC;IAMM,MAAM,CAAU,iBAAiB,GAMrC;QACH,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,+DAA+D,EAAE;QACrG,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,sCAAsC,EAAE;QAC5E,GAAG,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,6BAA6B,EAAE;QACpE,CAAC,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,6CAA6C,EAAE;QAC5F,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,mCAAmC,EAAE;QACvE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,6BAA6B,EAAE;QAC/D,GAAG,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,0DAA0D,EAAE;QACjG,EAAE,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,OAAO,EAAE,2BAA2B,EAAE;KAC3E,CAAC;IAQM,MAAM,CAAC,QAAQ,CAAC,KAAc,EAAE,UAAmC,EAAE;QAC5E,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe;YAAE,OAAO;QAEzC,MAAM,SAAS,GAAG,IA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AAU;iBAClD;aACD,CAAC;QACH,CAAC;QAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC5B,OAAO;gBACN,IAAI,EAAE,WAAW;gBACjB,aAAa,EAAE,KAAK;gBACpB,OAAO,EAAE;oBACR,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,IAAI,EAAG,KAA+B,CAAC,IAAI;iBAC3C;aACD,CAAC;QACH,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACvD,CAAC;;AAtUF,oCAuUC","sourcesContent":["/**\r\n * @fileoverview Error handling utility for TRPC and MongoDB operations.\r\n * Provides centralized error handling, logging, and retry mechanisms.\r\n */\r\n\r\nimport { TRPCError } from '@trpc/server';\r\nimport { MongoServerError, MongoError, MongoNetworkError } from 'mongodb';\r\nimport { ZodError } from 'zod';\r\n\r\n/**\r\n * A utility class for handling various types of errors in a TRPC-MongoDB application.\r\n * Provides error transformation, logging, and retry mechanisms.\r\n */\r\nexport class ErrorHandler {\r\n\t/**\r\n\t * Configuration options for error handling behavior\r\n\t * @private\r\n\t */\r\n\tprivate static readonly CONFIG = {\r\n\t\t/** Whether to log errors to console */\r\n\t\tshouldLogErrors: true,\r\n\t\t/** Maximum number of stack trace lines to include in logs */\r\n\t\tmaxStackTraceLines: 10,\r\n\t\t/** Set of error codes that are considered retryable */\r\n\t\tretryableErrors: new Set(['ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'EPIPE']),\r\n\t};\r\n\r\n\t/**\r\n\t * Mapping of MongoDB error codes to TRPC error types and messages\r\n\t * @private\r\n\t */\r\n\tprivate static readonly MONGO_ERROR_CODES: Record<\r\n\t\tnumber,\r\n\t\t{\r\n\t\t\tcode: TRPCError['code'];\r\n\t\t\tmessage: string;\r\n\t\t}\r\n\t> = {\r\n\t\t11000: { code: 'CONFLICT', message: 'Duplicate key error: A record with this value already exists.' },\r\n\t\t11001: { code: 'CONFLICT', message: 'Duplicate key error on index update.' },\r\n\t\t121: { code: 'BAD_REQUEST', message: 'Document validation failed.' },\r\n\t\t7: { code: 'INTERNAL_SERVER_ERROR', message: 'Not primary - database is in recovery mode.' },\r\n\t\t89: { code: 'FORBIDDEN', message: 'Unauthorized operation attempted.' },\r\n\t\t91: { code: 'TIMEOUT', message: 'Operation timeout exceeded.' },\r\n\t\t189: { code: 'BAD_REQUEST', message: 'Invalid modification - document would exceed size limit.' },\r\n\t\t50: { code: 'INTERNAL_SERVER_ERROR', message: 'Database execution error.' },\r\n\t};\r\n\r\n\t/**\r\n\t * Logs error information with metadata and stack trace\r\n\t * @private\r\n\t * @param error - The error to log\r\n\t * @param context - Additional context information for the error\r\n\t */\r\n\tprivate static logError(error: unknown, context: Record<string, unknown> = {}): void {\r\n\t\tif (!this.CONFIG.shouldLogErrors) return;\r\n\r\n\t\tconst errorMeta = this.extractErrorMetadata(error);\r\n\t\tconst timestamp = new Date().toISOString();\r\n\r\n\t\tconst logData = {\r\n\t\t\ttimestamp,\r\n\t\t\ttype: errorMeta.type,\r\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\r\n\t\t\tstack:\r\n\t\t\t\terror instanceof Error\r\n\t\t\t\t\t? error.stack?.split('\\n').slice(0, this.CONFIG.maxStackTraceLines).join('\\n')\r\n\t\t\t\t\t: undefined,\r\n\t\t\tcontext,\r\n\t\t\tmetadata: errorMeta,\r\n\t\t};\r\n\r\n\t\tconsole.error('[ErrorHandler]:', JSON.stringify(logData, null, 2));\r\n\t}\r\n\r\n\t/**\r\n\t * Main error handling method that transforms various error types into TRPC errors\r\n\t * @param error - The error to handle\r\n\t * @param customMessage - Optional custom error message\r\n\t * @param context - Additional context information\r\n\t * @throws {TRPCError} Transformed error with appropriate error code and message\r\n\t */\r\n\tpublic static handleError(\r\n\t\terror: unknown,\r\n\t\tcustomMessage = 'An unexpected error occurred',\r\n\t\tcontext: Record<string, unknown> = {}\r\n\t): never {\r\n\t\tthis.logError(error, context);\r\n\r\n\t\tif (error instanceof TRPCError) {\r\n\t\t\tthrow error;\r\n\t\t}\r\n\r\n\t\tif (error instanceof ZodError) {\r\n\t\t\ttry {\r\n\t\t\t\tconsole.log('ZodError:', error.flatten());\r\n\t\t\t\tconst formatted = error.errors.map(e => ({\r\n\t\t\t\t\tfield: e.path.join('.'),\r\n\t\t\t\t\tmessage: e.message,\r\n\t\t\t\t}));\r\n\r\n\t\t\t\tthrow new TRPCError({\r\n\t\t\t\t\tcode: 'BAD_REQUEST',\r\n\t\t\t\t\tmessage: 'Validation error',\r\n\t\t\t\t\tcause: formatted,\r\n\t\t\t\t});\r\n\t\t\t} catch (err) {\r\n\t\t\t\t// Handle any issues with flattening or logging\r\n\t\t\t\tconsole.error('Error while processing ZodError:', err);\r\n\t\t\t\tthrow new TRPCError({\r\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\t\t\tmessage: 'Error processing validation error',\r\n\t\t\t\t\tcause: err,\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (error instanceof MongoNetworkError) {\r\n\t\t\tthrow new TRPCError({\r\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\t\tmessage: 'Database connection error',\r\n\t\t\t\tcause: error,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tif (this.isMongoError(error)) {\r\n\t\t\tthrow this.createMongoTRPCError(error);\r\n\t\t}\r\n\r\n\t\tif (error instanceof Error) {\r\n\t\t\tthrow new TRPCError({\r\n\t\t\t\tcode: this.mapNodeErrorCode(error),\r\n\t\t\t\tmessage: error.message || customMessage,\r\n\t\t\t\tcause: error,\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tthrow new TRPCError({\r\n\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tmessage: customMessage,\r\n\t\t\tcause: error,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Type guard to check if an error is a MongoDB error\r\n\t * @private\r\n\t * @param error - The error to check\r\n\t * @returns True if the error is a MongoDB error\r\n\t */\r\n\tprivate static isMongoError(error: unknown): error is MongoServerError {\r\n\t\treturn (\r\n\t\t\terror instanceof MongoServerError ||\r\n\t\t\terror instanceof MongoError ||\r\n\t\t\t(typeof error === 'object' &&\r\n\t\t\t\terror !== null &&\r\n\t\t\t\t'code' in error &&\r\n\t\t\t\t'name' in error &&\r\n\t\t\t\t((error as MongoServerError).name === 'MongoServerError' ||\r\n\t\t\t\t\t(error as MongoServerError).name === 'MongoError'))\r\n\t\t);\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a TRPC error from a MongoDB error\r\n\t * @private\r\n\t * @param error - MongoDB error to transform\r\n\t * @returns Transformed TRPC error\r\n\t */\r\n\tprivate static createMongoTRPCError(error: MongoServerError): TRPCError {\r\n\t\tconst errorCode = typeof error.code === 'number' ? error.code : 0;\r\n\t\tconst errorInfo = this.MONGO_ERROR_CODES[errorCode] || {\r\n\t\t\tcode: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tmessage: `Database error occurred. Code: ${errorCode}`,\r\n\t\t};\r\n\r\n\t\treturn new TRPCError({\r\n\t\t\tcode: errorInfo.code,\r\n\t\t\tmessage: errorInfo.message,\r\n\t\t\tcause: error,\r\n\t\t});\r\n\t}\r\n\r\n\t/**\r\n\t * Maps Node.js error codes to TRPC error codes\r\n\t * @private\r\n\t * @param error - Node.js error to map\r\n\t * @returns Appropriate TRPC error code\r\n\t */\r\n\tprivate static mapNodeErrorCode(error: Error): TRPCError['code'] {\r\n\t\tconst nodeErrorMap: Record<string, TRPCError['code']> = {\r\n\t\t\tENOENT: 'NOT_FOUND',\r\n\t\t\tEACCES: 'FORBIDDEN',\r\n\t\t\tECONNREFUSED: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tECONNRESET: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tETIMEDOUT: 'TIMEOUT',\r\n\t\t\tEPIPE: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tENOTFOUND: 'NOT_FOUND',\r\n\t\t\tEINVAL: 'BAD_REQUEST',\r\n\t\t\tEMFILE: 'INTERNAL_SERVER_ERROR',\r\n\t\t\tEPERM: 'FORBIDDEN',\r\n\t\t};\r\n\r\n\t\tconst code = (error as NodeJS.ErrnoException).code;\r\n\t\treturn code ? nodeErrorMap[code] || 'INTERNAL_SERVER_ERROR' : 'INTERNAL_SERVER_ERROR';\r\n\t}\r\n\r\n\t/**\r\n\t * Wraps an async function with error handling\r\n\t * @param fn - Async function to wrap\r\n\t * @param context - Additional context information\r\n\t * @returns Promise resolving to the function's return type\r\n\t * @throws {TRPCError} If the function throws an error\r\n\t */\r\n\tpublic static async wrapAsync<T>(fn: () => Promise<T>, context: Record<string, unknown> = {}): Promise<T> {\r\n\t\ttry {\r\n\t\t\treturn await fn();\r\n\t\t} catch (error) {\r\n\t\t\tthis.handleError(error, undefined, context);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Executes an async function with retry mechanism for transient errors\r\n\t * @param fn - Async function to execute\r\n\t * @param options - Retry configuration options\r\n\t * @returns Promise resolving to the function's return type\r\n\t * @throws {TRPCError} If all retry attempts fail\r\n\t */\r\n\tpublic static async withRetry<T>(\r\n\t\tfn: () => Promise<T>,\r\n\t\toptions: {\r\n\t\t\tmaxAttempts?: number;\r\n\t\t\tdelayMs?: number;\r\n\t\t\tbackoffFactor?: number;\r\n\t\t\tcontext?: Record<string, unknown>;\r\n\t\t} = {}\r\n\t): Promise<T> {\r\n\t\tconst { maxAttempts = 3, delayMs = 1000, backoffFactor = 2, context = {} } = options;\r\n\r\n\t\tlet lastError: unknown;\r\n\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\r\n\t\t\ttry {\r\n\t\t\t\treturn await fn();\r\n\t\t\t} catch (error) {\r\n\t\t\t\tlastError = error;\r\n\r\n\t\t\t\tconst isRetryable = this.isRetryableError(error);\r\n\t\t\t\tconst isLastAttempt = attempt === maxAttempts;\r\n\r\n\t\t\t\tif (!isRetryable || isLastAttempt) {\r\n\t\t\t\t\tthis.handleError(error, undefined, { ...context, attempt });\r\n\t\t\t\t}\r\n\r\n\t\t\t\tawait new Promise(resolve => setTimeout(resolve, delayMs * Math.pow(backoffFactor, attempt - 1)));\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tthrow lastError;\r\n\t}\r\n\r\n\t/**\r\n\t * Determines if an error is retryable\r\n\t * @private\r\n\t * @param error - The error to check\r\n\t * @returns True if the error is retryable\r\n\t */\r\n\tprivate static isRetryableError(error: unknown): boolean {\r\n\t\tif (error instanceof MongoNetworkError) return true;\r\n\t\tif (error instanceof Error) {\r\n\t\t\tconst code = (error as NodeJS.ErrnoException).code;\r\n\t\t\treturn code ? this.CONFIG.retryableErrors.has(code) : false;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Extracts metadata from an error for logging and analysis\r\n\t * @param error - The error to extract metadata from\r\n\t * @returns Object containing error type, original error, and additional details\r\n\t */\r\n\tpublic static extractErrorMetadata(error: unknown): {\r\n\t\ttype: string;\r\n\t\toriginalError: unknown;\r\n\t\tdetails?: Record<string, unknown>;\r\n\t} {\r\n\t\tif (error instanceof TRPCError) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'TRPCError',\r\n\t\t\t\toriginalError: error.cause ?? error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tcode: error.code,\r\n\t\t\t\t\tmessage: error.message,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (error instanceof ZodError) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'ZodError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: error.flatten(),\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (error instanceof MongoNetworkError) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'MongoNetworkError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tmessage: error.message,\r\n\t\t\t\t\tisRetryable: true,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (this.isMongoError(error)) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'MongoError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tcode: (error as MongoServerError).code,\r\n\t\t\t\t\tcodeName: (error as MongoServerError).codeName,\r\n\t\t\t\t\tkeyPattern: (error as MongoServerError).keyPattern,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tif (error instanceof Error) {\r\n\t\t\treturn {\r\n\t\t\t\ttype: 'NodeError',\r\n\t\t\t\toriginalError: error,\r\n\t\t\t\tdetails: {\r\n\t\t\t\t\tname: error.name,\r\n\t\t\t\t\tcode: (error as NodeJS.ErrnoException).code,\r\n\t\t\t\t},\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\treturn { type: 'UnknownError', originalError: error };\r\n\t}\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.js","sourceRoot":"/","sources":["utilities/transformers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuPA,8CAQC;AA9PD,iDAA4C;AAC5C,6BAAwB;AA4BjB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAMT;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IASvC,oBAAoB,CAAC,MAAyC;QACpE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;IAC7C,CAAC;IASM,yBAAyB,CAC/B,OAAmC;QAGnC,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,UAAU,IAAI,OAAO,I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B,CAC7B,MAA+B,EAC/B,IAAY,EACZ,YAA4B;QAE5B,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,OAAO,GAAQ,MAAM,CAAC;QAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;gBAChC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,sBAAsB,CAAC,CAAC;YACrD,CAAC;QACF,CAAC;QAED,OAAO,YAAY,CAAC,KAAK,CAAC,OAAO,CAAe,CAAC;IAClD,CAAC;IASM,qBAAqB,CAAC,MAA+B,EAAE,QAA0B;QACvF,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAC;IACxC,CAAC;CACD,CAAA;AA9MY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gBAAO,GAAE;qCAOmB,OAAC,CAAC,OAAO;GANzB,iBAAiB,CA8M7B;AAWD,SAAgB,iBAAiB,CAChC,MAAsB;IAEtB,IAAI,CAAC;QACJ,OAAO,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAA0C,CAAC;IAClF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,IAAI,iBAAiB,CAAqB,MAAM,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC","sourcesContent":["import { DocumentType } from '@typegoose/typegoose';\r\nimport Container, { Service } from 'typedi';\r\nimport { z } from 'zod';\r\n\r\n/**\r\n * Type definition for pagination metadata\r\n */\r\ntype Metadata = {\r\n\tpage: number;\r\n\tsize: number;\r\n\ttotalElements: number;\r\n\ttotalPages: number;\r\n};\r\n\r\n/**\r\n * Type definition for paginated response\r\n */\r\ntype PaginatedResponse<T> = {\r\n\tmetadata?: Metadata;\r\n\tdocuments: T[];\r\n};\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\t/**\r\n\t * Creates a new GlobalTransformer\r\n\t *\r\n\t * @param {z.ZodType<any>} schema - Zod schema used for validation and transformation\r\n\t */\r\n\tconstructor(private schema: z.ZodType<any>) {}\r\n\r\n\t/**\r\n\t * Transforms a single document to a DTO\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @returns {DTOType} The transformed DTO\r\n\t * @throws {Error} When record is not found\r\n\t */\r\n\tpublic transformToBasicView(record: DocumentType<ModelType> | DTOType): DTOType {\r\n\t\tif (!record) {\r\n\t\t\tthrow new Error('Record not found');\r\n\t\t}\r\n\r\n\t\treturn this.schema.parse(record) as DTOType;\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms an array of documents or a paginated response to a paginated DTO response\r\n\t *\r\n\t * @param {DocumentType<ModelType>[] | DTOType[] | PaginatedResponse<DocumentType<ModelType>> | PaginatedResponse<DTOType>} records - Records to transform\r\n\t * @returns {PaginatedResponse<DTOType>} Paginated response with transformed DTOs\r\n\t * @throws {Error} When input type is invalid\r\n\t */\r\n\tpublic transformToBasicViewArray<T extends DocumentType<ModelType> | DTOType>(\r\n\t\trecords: T[] | PaginatedResponse<T>\r\n\t): PaginatedResponse<DTOType> {\r\n\t\t// Case 1: If records is already in the paginated format\r\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\r\n\t\t\tconst paginatedRecords = records as\r\n\t\t\t\t| PaginatedResponse<DocumentType<ModelType>>\r\n\t\t\t\t| PaginatedResponse<DTOType>;\r\n\r\n\t\t\t// Process the documents array\r\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\r\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToBasicView(doc))\r\n\t\t\t\t: [];\r\n\r\n\t\t\t// Return the entire paginated structure\r\n\t\t\treturn {\r\n\t\t\t\tmetadata: paginatedRecords.metadata,\r\n\t\t\t\tdocuments: processedDocuments,\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t// Case 2: If records is an array\r\n\t\tif (Array.isArray(records)) {\r\n\t\t\tif (records.length === 0) {\r\n\t\t\t\treturn {\r\n\t\t\t\t\tdocuments: [],\r\n\t\t\t\t};\r\n\t\t\t}\r\n\r\n\t\t\tconst transformedRecords = records.map(record => this.transformToBasicView(record));\r\n\r\n\t\t\t// Return in paginated format with default metadata\r\n\t\t\treturn {\r\n\t\t\t\tdocuments: transformedRecords,\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t// Fallback for unexpected input\r\n\t\tthrow new Error('Invalid input type for transformToBasicViewArray');\r\n\t}\r\n\r\n\t/**\r\n\t * Creates a partial view with only the specified fields\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\r\n\t * @returns {Partial<DTOType>} Partial DTO with only the specified fields\r\n\t */\r\n\tpublic transformToPartialView(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tfields: (keyof DTOType)[]\r\n\t): Partial<DTOType> {\r\n\t\tconst fullView = this.transformToBasicView(record);\r\n\t\tconst partialView: Partial<DTOType> = {};\r\n\r\n\t\tfields.forEach(field => {\r\n\t\t\tconst dto = fullView as Record<keyof DTOType, any>;\r\n\t\t\tpartialView[field] = dto[field];\r\n\t\t});\r\n\r\n\t\treturn partialView;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates partial views for an array of documents\r\n\t *\r\n\t * @param {DocumentType<ModelType>[]} records - Array of documents to transform\r\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\r\n\t * @returns {Partial<DTOType>[]} Array of partial DTOs\r\n\t */\r\n\tpublic transformToPartialViewArray(\r\n\t\trecords: DocumentType<ModelType>[] | PaginatedResponse<DocumentType<ModelType>>,\r\n\t\tfields: (keyof DTOType)[]\r\n\t): Partial<DTOType>[] | PaginatedResponse<Partial<DTOType>> {\r\n\t\t// Case 1: If records is already in the paginated format\r\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\r\n\t\t\tconst paginatedRecords = records as PaginatedResponse<DocumentType<ModelType>>;\r\n\r\n\t\t\t// Process the documents array\r\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\r\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToPartialView(doc, fields))\r\n\t\t\t\t: [];\r\n\r\n\t\t\t// Return the entire paginated structure\r\n\t\t\treturn {\r\n\t\t\t\tmetadata: paginatedRecords.metadata,\r\n\t\t\t\tdocuments: processedDocuments,\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t// Case 2: If records is an array\r\n\t\tif (Array.isArray(records)) {\r\n\t\t\tif (records.length === 0) {\r\n\t\t\t\treturn [];\r\n\t\t\t}\r\n\t\t\treturn records.map(record => this.transformToPartialView(record, fields));\r\n\t\t}\r\n\r\n\t\t// Fallback for unexpected input\r\n\t\tthrow new Error('Invalid input type for transformToPartialViewArray');\r\n\t}\r\n\t/**\r\n\t * Transforms a document and adds additional computed fields\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {Partial<Record<string, any>>} additionalData - Additional fields to add\r\n\t * @returns {DTOType & Record<string, any>} DTO with additional fields\r\n\t */\r\n\tpublic transformWithAdditionalData(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tadditionalData: Partial<Record<string, any>>\r\n\t): DTOType & Record<string, any> {\r\n\t\tconst basicView = this.transformToBasicView(record);\r\n\t\treturn { ...basicView, ...additionalData };\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms a document using a custom mapping function\r\n\t *\r\n\t * @template OutputType - The output type after mapping\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {(input: DTOType) => OutputType} mapFn - Mapping function for custom transformation\r\n\t * @returns {OutputType} Custom transformed output\r\n\t */\r\n\tpublic transformWithMapping<OutputType = DTOType>(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tmapFn: (input: DTOType) => OutputType\r\n\t): OutputType {\r\n\t\tconst basicView = this.transformToBasicView(record);\r\n\t\treturn mapFn(basicView);\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms a nested property of the document\r\n\t *\r\n\t * @template NestedType - The type of the nested property\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {string} path - Dot-notation path to the nested property\r\n\t * @param {z.ZodType<any>} nestedSchema - Zod schema for the nested property\r\n\t * @returns {NestedType} The transformed nested property\r\n\t * @throws {Error} When path is not found in record\r\n\t */\r\n\tpublic transformNestedProperty<NestedType>(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tpath: string,\r\n\t\tnestedSchema: z.ZodType<any>\r\n\t): NestedType {\r\n\t\tif (!record) {\r\n\t\t\tthrow new Error('Record not found');\r\n\t\t}\r\n\r\n\t\tconst parts = path.split('.');\r\n\t\tlet current: any = record;\r\n\r\n\t\tfor (const part of parts) {\r\n\t\t\tif (current && part in current) {\r\n\t\t\t\tcurrent = current[part];\r\n\t\t\t} else {\r\n\t\t\t\tthrow new Error(`Path ${path} not found in record`);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn nestedSchema.parse(current) as NestedType;\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms a document with default values for missing fields\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {Partial<DTOType>} defaults - Default values for fields\r\n\t * @returns {DTOType} DTO with defaults applied\r\n\t */\r\n\tpublic transformWithDefaults(record: DocumentType<ModelType>, defaults: Partial<DTOType>): DTOType {\r\n\t\tconst transformed = this.transformToBasicView(record);\r\n\t\treturn { ...defaults, ...transformed };\r\n\t}\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\tschema: z.ZodType<any>\r\n): GlobalTransformer<ModelType, DTOType> {\r\n\ttry {\r\n\t\treturn Container.get(GlobalTransformer) as GlobalTransformer<ModelType, DTOType>;\r\n\t} catch (error) {\r\n\t\treturn new GlobalTransformer<ModelType, DTOType>(schema);\r\n\t}\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"transformers.js","sourceRoot":"/","sources":["utilities/transformers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuPA,8CAQC;AA9PD,iDAA4C;AAC5C,6BAAwB;AA4BjB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAMT;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IASvC,oBAAoB,CAAC,MAAyC;QACpE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;IAC7C,CAAC;IASM,yBAAyB,CAC/B,OAAmC;QAGnC,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,UAAU,IAAI,OAAO,IAAI,WAAW,IAAI,OAAO,EAAE,CAAC;YAC/F,MAAM,gBAAgB,GAAG,OAEI,CAAC;YAG9B,MAAM,kBAAkB,GAAG,KA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AAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,OAAO,GAAQ,MAAM,CAAC;QAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;gBAChC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,sBAAsB,CAAC,CAAC;YACrD,CAAC;QACF,CAAC;QAED,OAAO,YAAY,CAAC,KAAK,CAAC,OAAO,CAAe,CAAC;IAClD,CAAC;IASM,qBAAqB,CAAC,MAA+B,EAAE,QAA0B;QACvF,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAC;IACxC,CAAC;CACD,CAAA;AA9MY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gBAAO,GAAE;qCAOmB,OAAC,CAAC,OAAO;GANzB,iBAAiB,CA8M7B;AAWD,SAAgB,iBAAiB,CAChC,MAAsB;IAEtB,IAAI,CAAC;QACJ,OAAO,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAA0C,CAAC;IAClF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,IAAI,iBAAiB,CAAqB,MAAM,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC","sourcesContent":["import { DocumentType } from '@typegoose/typegoose';\r\nimport Container, { Service } from 'typedi';\r\nimport { z } from 'zod';\r\n\r\n/**\r\n * Type definition for pagination metadata\r\n */\r\ntype Metadata = {\r\n\tpage: number;\r\n\tsize: number;\r\n\ttotalElements: number;\r\n\ttotalPages: number;\r\n};\r\n\r\n/**\r\n * Type definition for paginated response\r\n */\r\ntype PaginatedResponse<T> = {\r\n\tmetadata?: Metadata;\r\n\tdocuments: T[];\r\n};\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\t/**\r\n\t * Creates a new GlobalTransformer\r\n\t *\r\n\t * @param {z.ZodType<any>} schema - Zod schema used for validation and transformation\r\n\t */\r\n\tconstructor(private schema: z.ZodType<any>) {}\r\n\r\n\t/**\r\n\t * Transforms a single document to a DTO\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @returns {DTOType} The transformed DTO\r\n\t * @throws {Error} When record is not found\r\n\t */\r\n\tpublic transformToBasicView(record: DocumentType<ModelType> | DTOType): DTOType {\r\n\t\tif (!record) {\r\n\t\t\tthrow new Error('Record not found');\r\n\t\t}\r\n\r\n\t\treturn this.schema.parse(record) as DTOType;\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms an array of documents or a paginated response to a paginated DTO response\r\n\t *\r\n\t * @param {DocumentType<ModelType>[] | DTOType[] | PaginatedResponse<DocumentType<ModelType>> | PaginatedResponse<DTOType>} records - Records to transform\r\n\t * @returns {PaginatedResponse<DTOType>} Paginated response with transformed DTOs\r\n\t * @throws {Error} When input type is invalid\r\n\t */\r\n\tpublic transformToBasicViewArray<T extends DocumentType<ModelType> | DTOType>(\r\n\t\trecords: T[] | PaginatedResponse<T>\r\n\t): PaginatedResponse<DTOType> {\r\n\t\t// Case 1: If records is already in the paginated format\r\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\r\n\t\t\tconst paginatedRecords = records as\r\n\t\t\t\t| PaginatedResponse<DocumentType<ModelType>>\r\n\t\t\t\t| PaginatedResponse<DTOType>;\r\n\r\n\t\t\t// Process the documents array\r\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\r\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToBasicView(doc))\r\n\t\t\t\t: [];\r\n\r\n\t\t\t// Return the entire paginated structure\r\n\t\t\treturn {\r\n\t\t\t\tmetadata: paginatedRecords.metadata,\r\n\t\t\t\tdocuments: processedDocuments,\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t// Case 2: If records is an array\r\n\t\tif (Array.isArray(records)) {\r\n\t\t\tif (records.length === 0) {\r\n\t\t\t\treturn {\r\n\t\t\t\t\tdocuments: [],\r\n\t\t\t\t};\r\n\t\t\t}\r\n\r\n\t\t\tconst transformedRecords = records.map(record => this.transformToBasicView(record));\r\n\r\n\t\t\t// Return in paginated format with default metadata\r\n\t\t\treturn {\r\n\t\t\t\tdocuments: transformedRecords,\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t// Fallback for unexpected input\r\n\t\tthrow new Error('Invalid input type for transformToBasicViewArray');\r\n\t}\r\n\r\n\t/**r\r\n\t * Creates a partial view with only the specified fields\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\r\n\t * @returns {Partial<DTOType>} Partial DTO with only the specified fields\r\n\t */\r\n\tpublic transformToPartialView(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tfields: (keyof DTOType)[]\r\n\t): Partial<DTOType> {\r\n\t\tconst fullView = this.transformToBasicView(record);\r\n\t\tconst partialView: Partial<DTOType> = {};\r\n\r\n\t\tfields.forEach(field => {\r\n\t\t\tconst dto = fullView as Record<keyof DTOType, any>;\r\n\t\t\tpartialView[field] = dto[field];\r\n\t\t});\r\n\r\n\t\treturn partialView;\r\n\t}\r\n\r\n\t/**\r\n\t * Creates partial views for an array of documents\r\n\t *\r\n\t * @param {DocumentType<ModelType>[]} records - Array of documents to transform\r\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\r\n\t * @returns {Partial<DTOType>[]} Array of partial DTOs\r\n\t */\r\n\tpublic transformToPartialViewArray(\r\n\t\trecords: DocumentType<ModelType>[] | PaginatedResponse<DocumentType<ModelType>>,\r\n\t\tfields: (keyof DTOType)[]\r\n\t): Partial<DTOType>[] | PaginatedResponse<Partial<DTOType>> {\r\n\t\t// Case 1: If records is already in the paginated format\r\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\r\n\t\t\tconst paginatedRecords = records as PaginatedResponse<DocumentType<ModelType>>;\r\n\r\n\t\t\t// Process the documents array\r\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\r\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToPartialView(doc, fields))\r\n\t\t\t\t: [];\r\n\r\n\t\t\t// Return the entire paginated structure\r\n\t\t\treturn {\r\n\t\t\t\tmetadata: paginatedRecords.metadata,\r\n\t\t\t\tdocuments: processedDocuments,\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\t// Case 2: If records is an array\r\n\t\tif (Array.isArray(records)) {\r\n\t\t\tif (records.length === 0) {\r\n\t\t\t\treturn [];\r\n\t\t\t}\r\n\t\t\treturn records.map(record => this.transformToPartialView(record, fields));\r\n\t\t}\r\n\r\n\t\t// Fallback for unexpected input\r\n\t\tthrow new Error('Invalid input type for transformToPartialViewArray');\r\n\t}\r\n\t/**\r\n\t * Transforms a document and adds additional computed fields\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {Partial<Record<string, any>>} additionalData - Additional fields to add\r\n\t * @returns {DTOType & Record<string, any>} DTO with additional fields\r\n\t */\r\n\tpublic transformWithAdditionalData(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tadditionalData: Partial<Record<string, any>>\r\n\t): DTOType & Record<string, any> {\r\n\t\tconst basicView = this.transformToBasicView(record);\r\n\t\treturn { ...basicView, ...additionalData };\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms a document using a custom mapping function\r\n\t *\r\n\t * @template OutputType - The output type after mapping\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {(input: DTOType) => OutputType} mapFn - Mapping function for custom transformation\r\n\t * @returns {OutputType} Custom transformed output\r\n\t */\r\n\tpublic transformWithMapping<OutputType = DTOType>(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tmapFn: (input: DTOType) => OutputType\r\n\t): OutputType {\r\n\t\tconst basicView = this.transformToBasicView(record);\r\n\t\treturn mapFn(basicView);\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms a nested property of the document\r\n\t *\r\n\t * @template NestedType - The type of the nested property\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {string} path - Dot-notation path to the nested property\r\n\t * @param {z.ZodType<any>} nestedSchema - Zod schema for the nested property\r\n\t * @returns {NestedType} The transformed nested property\r\n\t * @throws {Error} When path is not found in record\r\n\t */\r\n\tpublic transformNestedProperty<NestedType>(\r\n\t\trecord: DocumentType<ModelType>,\r\n\t\tpath: string,\r\n\t\tnestedSchema: z.ZodType<any>\r\n\t): NestedType {\r\n\t\tif (!record) {\r\n\t\t\tthrow new Error('Record not found');\r\n\t\t}\r\n\r\n\t\tconst parts = path.split('.');\r\n\t\tlet current: any = record;\r\n\r\n\t\tfor (const part of parts) {\r\n\t\t\tif (current && part in current) {\r\n\t\t\t\tcurrent = current[part];\r\n\t\t\t} else {\r\n\t\t\t\tthrow new Error(`Path ${path} not found in record`);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn nestedSchema.parse(current) as NestedType;\r\n\t}\r\n\r\n\t/**\r\n\t * Transforms a document with default values for missing fields\r\n\t *\r\n\t * @param {DocumentType<ModelType>} record - The document to transform\r\n\t * @param {Partial<DTOType>} defaults - Default values for fields\r\n\t * @returns {DTOType} DTO with defaults applied\r\n\t */\r\n\tpublic transformWithDefaults(record: DocumentType<ModelType>, defaults: Partial<DTOType>): DTOType {\r\n\t\tconst transformed = this.transformToBasicView(record);\r\n\t\treturn { ...defaults, ...transformed };\r\n\t}\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\tschema: z.ZodType<any>\r\n): GlobalTransformer<ModelType, DTOType> {\r\n\ttry {\r\n\t\treturn Container.get(GlobalTransformer) as GlobalTransformer<ModelType, DTOType>;\r\n\t} catch (error) {\r\n\t\treturn new GlobalTransformer<ModelType, DTOType>(schema);\r\n\t}\r\n}\r\n"]}
|
|
@@ -132,81 +132,81 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
132
132
|
export type FilterDTO = z.infer<typeof FilterSchema>;
|
|
133
133
|
export declare const StringSchema: z.ZodString;
|
|
134
134
|
export declare const AddressSchema: z.ZodObject<{
|
|
135
|
-
address: z.ZodString
|
|
136
|
-
description: z.ZodOptional<z.ZodString
|
|
137
|
-
city: z.ZodString
|
|
138
|
-
state: z.ZodString
|
|
139
|
-
country: z.ZodString
|
|
135
|
+
address: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
136
|
+
description: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
137
|
+
city: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
138
|
+
state: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
139
|
+
country: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
140
140
|
geoLocationType: z.ZodDefault<z.ZodNativeEnum<typeof GeoLocationType>>;
|
|
141
141
|
coordinates: z.ZodArray<z.ZodNumber, "many">;
|
|
142
142
|
latitude: z.ZodNumber;
|
|
143
143
|
longitude: z.ZodNumber;
|
|
144
144
|
}, "strip", z.ZodTypeAny, {
|
|
145
|
-
state: string;
|
|
146
|
-
address: string;
|
|
147
|
-
country: string;
|
|
148
145
|
coordinates: number[];
|
|
149
|
-
city: string;
|
|
150
146
|
latitude: number;
|
|
151
147
|
longitude: number;
|
|
152
148
|
geoLocationType: GeoLocationType;
|
|
153
|
-
|
|
149
|
+
state?: string | null | undefined;
|
|
150
|
+
address?: string | null | undefined;
|
|
151
|
+
country?: string | null | undefined;
|
|
152
|
+
description?: string | null | undefined;
|
|
153
|
+
city?: string | null | undefined;
|
|
154
154
|
}, {
|
|
155
|
-
state: string;
|
|
156
|
-
address: string;
|
|
157
|
-
country: string;
|
|
158
155
|
coordinates: number[];
|
|
159
|
-
city: string;
|
|
160
156
|
latitude: number;
|
|
161
157
|
longitude: number;
|
|
162
|
-
|
|
158
|
+
state?: string | null | undefined;
|
|
159
|
+
address?: string | null | undefined;
|
|
160
|
+
country?: string | null | undefined;
|
|
161
|
+
description?: string | null | undefined;
|
|
162
|
+
city?: string | null | undefined;
|
|
163
163
|
geoLocationType?: GeoLocationType | undefined;
|
|
164
164
|
}>;
|
|
165
165
|
export declare const UserAddressSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
166
|
-
address: z.ZodString
|
|
167
|
-
description: z.ZodOptional<z.ZodString
|
|
168
|
-
city: z.ZodString
|
|
169
|
-
state: z.ZodString
|
|
170
|
-
country: z.ZodString
|
|
166
|
+
address: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
167
|
+
description: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
168
|
+
city: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
169
|
+
state: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
170
|
+
country: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
171
171
|
geoLocationType: z.ZodDefault<z.ZodNativeEnum<typeof GeoLocationType>>;
|
|
172
172
|
coordinates: z.ZodArray<z.ZodNumber, "many">;
|
|
173
173
|
latitude: z.ZodNumber;
|
|
174
174
|
longitude: z.ZodNumber;
|
|
175
175
|
}, {
|
|
176
|
-
addressLabel: z.ZodString
|
|
177
|
-
apartment: z.ZodString
|
|
178
|
-
buildingName: z.ZodString
|
|
179
|
-
deliveryOption: z.ZodOptional<z.ZodString
|
|
180
|
-
instructions: z.ZodOptional<z.ZodString
|
|
176
|
+
addressLabel: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
177
|
+
apartment: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
178
|
+
buildingName: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
179
|
+
deliveryOption: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
180
|
+
instructions: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodString>> | z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
181
181
|
}>, "strip", z.ZodTypeAny, {
|
|
182
|
-
state: string;
|
|
183
|
-
address: string;
|
|
184
|
-
country: string;
|
|
185
182
|
coordinates: number[];
|
|
186
|
-
city: string;
|
|
187
183
|
latitude: number;
|
|
188
184
|
longitude: number;
|
|
189
|
-
addressLabel: string;
|
|
190
|
-
apartment: string;
|
|
191
|
-
buildingName: string;
|
|
192
185
|
geoLocationType: GeoLocationType;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
186
|
+
state?: string | null | undefined;
|
|
187
|
+
address?: string | null | undefined;
|
|
188
|
+
country?: string | null | undefined;
|
|
189
|
+
description?: string | null | undefined;
|
|
190
|
+
city?: string | null | undefined;
|
|
191
|
+
addressLabel?: string | null | undefined;
|
|
192
|
+
apartment?: string | null | undefined;
|
|
193
|
+
buildingName?: string | null | undefined;
|
|
194
|
+
deliveryOption?: string | null | undefined;
|
|
195
|
+
instructions?: string | null | undefined;
|
|
196
196
|
}, {
|
|
197
|
-
state: string;
|
|
198
|
-
address: string;
|
|
199
|
-
country: string;
|
|
200
197
|
coordinates: number[];
|
|
201
|
-
city: string;
|
|
202
198
|
latitude: number;
|
|
203
199
|
longitude: number;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
description?: string | undefined;
|
|
208
|
-
|
|
209
|
-
|
|
200
|
+
state?: string | null | undefined;
|
|
201
|
+
address?: string | null | undefined;
|
|
202
|
+
country?: string | null | undefined;
|
|
203
|
+
description?: string | null | undefined;
|
|
204
|
+
city?: string | null | undefined;
|
|
205
|
+
addressLabel?: string | null | undefined;
|
|
206
|
+
apartment?: string | null | undefined;
|
|
207
|
+
buildingName?: string | null | undefined;
|
|
208
|
+
deliveryOption?: string | null | undefined;
|
|
209
|
+
instructions?: string | null | undefined;
|
|
210
210
|
geoLocationType?: GeoLocationType | undefined;
|
|
211
211
|
}>;
|
|
212
212
|
export declare const DurationSchema: z.ZodObject<{
|
|
@@ -223,56 +223,56 @@ export declare const NormalHourSchema: z.ZodObject<{
|
|
|
223
223
|
day: z.ZodNativeEnum<typeof WeekDay>;
|
|
224
224
|
status: z.ZodNativeEnum<typeof WorkStatus>;
|
|
225
225
|
openingHours: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
226
|
-
start: z.ZodString
|
|
227
|
-
end: z.ZodString
|
|
226
|
+
start: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
227
|
+
end: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
228
228
|
}, "strip", z.ZodTypeAny, {
|
|
229
|
-
end
|
|
230
|
-
start
|
|
229
|
+
end?: string | null | undefined;
|
|
230
|
+
start?: string | null | undefined;
|
|
231
231
|
}, {
|
|
232
|
-
end
|
|
233
|
-
start
|
|
232
|
+
end?: string | null | undefined;
|
|
233
|
+
start?: string | null | undefined;
|
|
234
234
|
}>, "many">>;
|
|
235
235
|
}, "strip", z.ZodTypeAny, {
|
|
236
236
|
status: WorkStatus;
|
|
237
237
|
day: WeekDay;
|
|
238
238
|
openingHours: {
|
|
239
|
-
end
|
|
240
|
-
start
|
|
239
|
+
end?: string | null | undefined;
|
|
240
|
+
start?: string | null | undefined;
|
|
241
241
|
}[];
|
|
242
242
|
}, {
|
|
243
243
|
status: WorkStatus;
|
|
244
244
|
day: WeekDay;
|
|
245
245
|
openingHours?: {
|
|
246
|
-
end
|
|
247
|
-
start
|
|
246
|
+
end?: string | null | undefined;
|
|
247
|
+
start?: string | null | undefined;
|
|
248
248
|
}[] | undefined;
|
|
249
249
|
}>;
|
|
250
250
|
export declare const HolidayHourSchema: z.ZodObject<{
|
|
251
251
|
date: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
252
252
|
status: z.ZodNativeEnum<typeof HolidayWorkStatus>;
|
|
253
253
|
closingHour: z.ZodObject<{
|
|
254
|
-
start: z.ZodString
|
|
255
|
-
end: z.ZodString
|
|
254
|
+
start: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
255
|
+
end: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
256
256
|
}, "strip", z.ZodTypeAny, {
|
|
257
|
-
end
|
|
258
|
-
start
|
|
257
|
+
end?: string | null | undefined;
|
|
258
|
+
start?: string | null | undefined;
|
|
259
259
|
}, {
|
|
260
|
-
end
|
|
261
|
-
start
|
|
260
|
+
end?: string | null | undefined;
|
|
261
|
+
start?: string | null | undefined;
|
|
262
262
|
}>;
|
|
263
263
|
}, "strip", z.ZodTypeAny, {
|
|
264
264
|
status: HolidayWorkStatus;
|
|
265
265
|
date: Date;
|
|
266
266
|
closingHour: {
|
|
267
|
-
end
|
|
268
|
-
start
|
|
267
|
+
end?: string | null | undefined;
|
|
268
|
+
start?: string | null | undefined;
|
|
269
269
|
};
|
|
270
270
|
}, {
|
|
271
271
|
status: HolidayWorkStatus;
|
|
272
272
|
date: string | Date;
|
|
273
273
|
closingHour: {
|
|
274
|
-
end
|
|
275
|
-
start
|
|
274
|
+
end?: string | null | undefined;
|
|
275
|
+
start?: string | null | undefined;
|
|
276
276
|
};
|
|
277
277
|
}>;
|
|
278
278
|
export declare const WorkHourSettingSchema: z.ZodObject<{
|
|
@@ -280,56 +280,56 @@ export declare const WorkHourSettingSchema: z.ZodObject<{
|
|
|
280
280
|
day: z.ZodNativeEnum<typeof WeekDay>;
|
|
281
281
|
status: z.ZodNativeEnum<typeof WorkStatus>;
|
|
282
282
|
openingHours: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
283
|
-
start: z.ZodString
|
|
284
|
-
end: z.ZodString
|
|
283
|
+
start: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
284
|
+
end: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
285
285
|
}, "strip", z.ZodTypeAny, {
|
|
286
|
-
end
|
|
287
|
-
start
|
|
286
|
+
end?: string | null | undefined;
|
|
287
|
+
start?: string | null | undefined;
|
|
288
288
|
}, {
|
|
289
|
-
end
|
|
290
|
-
start
|
|
289
|
+
end?: string | null | undefined;
|
|
290
|
+
start?: string | null | undefined;
|
|
291
291
|
}>, "many">>;
|
|
292
292
|
}, "strip", z.ZodTypeAny, {
|
|
293
293
|
status: WorkStatus;
|
|
294
294
|
day: WeekDay;
|
|
295
295
|
openingHours: {
|
|
296
|
-
end
|
|
297
|
-
start
|
|
296
|
+
end?: string | null | undefined;
|
|
297
|
+
start?: string | null | undefined;
|
|
298
298
|
}[];
|
|
299
299
|
}, {
|
|
300
300
|
status: WorkStatus;
|
|
301
301
|
day: WeekDay;
|
|
302
302
|
openingHours?: {
|
|
303
|
-
end
|
|
304
|
-
start
|
|
303
|
+
end?: string | null | undefined;
|
|
304
|
+
start?: string | null | undefined;
|
|
305
305
|
}[] | undefined;
|
|
306
306
|
}>, "many">>;
|
|
307
307
|
holidayHours: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
308
308
|
date: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
309
309
|
status: z.ZodNativeEnum<typeof HolidayWorkStatus>;
|
|
310
310
|
closingHour: z.ZodObject<{
|
|
311
|
-
start: z.ZodString
|
|
312
|
-
end: z.ZodString
|
|
311
|
+
start: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
312
|
+
end: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
313
313
|
}, "strip", z.ZodTypeAny, {
|
|
314
|
-
end
|
|
315
|
-
start
|
|
314
|
+
end?: string | null | undefined;
|
|
315
|
+
start?: string | null | undefined;
|
|
316
316
|
}, {
|
|
317
|
-
end
|
|
318
|
-
start
|
|
317
|
+
end?: string | null | undefined;
|
|
318
|
+
start?: string | null | undefined;
|
|
319
319
|
}>;
|
|
320
320
|
}, "strip", z.ZodTypeAny, {
|
|
321
321
|
status: HolidayWorkStatus;
|
|
322
322
|
date: Date;
|
|
323
323
|
closingHour: {
|
|
324
|
-
end
|
|
325
|
-
start
|
|
324
|
+
end?: string | null | undefined;
|
|
325
|
+
start?: string | null | undefined;
|
|
326
326
|
};
|
|
327
327
|
}, {
|
|
328
328
|
status: HolidayWorkStatus;
|
|
329
329
|
date: string | Date;
|
|
330
330
|
closingHour: {
|
|
331
|
-
end
|
|
332
|
-
start
|
|
331
|
+
end?: string | null | undefined;
|
|
332
|
+
start?: string | null | undefined;
|
|
333
333
|
};
|
|
334
334
|
}>, "many">>;
|
|
335
335
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -337,16 +337,16 @@ export declare const WorkHourSettingSchema: z.ZodObject<{
|
|
|
337
337
|
status: WorkStatus;
|
|
338
338
|
day: WeekDay;
|
|
339
339
|
openingHours: {
|
|
340
|
-
end
|
|
341
|
-
start
|
|
340
|
+
end?: string | null | undefined;
|
|
341
|
+
start?: string | null | undefined;
|
|
342
342
|
}[];
|
|
343
343
|
}[];
|
|
344
344
|
holidayHours: {
|
|
345
345
|
status: HolidayWorkStatus;
|
|
346
346
|
date: Date;
|
|
347
347
|
closingHour: {
|
|
348
|
-
end
|
|
349
|
-
start
|
|
348
|
+
end?: string | null | undefined;
|
|
349
|
+
start?: string | null | undefined;
|
|
350
350
|
};
|
|
351
351
|
}[];
|
|
352
352
|
}, {
|
|
@@ -354,28 +354,28 @@ export declare const WorkHourSettingSchema: z.ZodObject<{
|
|
|
354
354
|
status: WorkStatus;
|
|
355
355
|
day: WeekDay;
|
|
356
356
|
openingHours?: {
|
|
357
|
-
end
|
|
358
|
-
start
|
|
357
|
+
end?: string | null | undefined;
|
|
358
|
+
start?: string | null | undefined;
|
|
359
359
|
}[] | undefined;
|
|
360
360
|
}[] | undefined;
|
|
361
361
|
holidayHours?: {
|
|
362
362
|
status: HolidayWorkStatus;
|
|
363
363
|
date: string | Date;
|
|
364
364
|
closingHour: {
|
|
365
|
-
end
|
|
366
|
-
start
|
|
365
|
+
end?: string | null | undefined;
|
|
366
|
+
start?: string | null | undefined;
|
|
367
367
|
};
|
|
368
368
|
}[] | undefined;
|
|
369
369
|
}>;
|
|
370
370
|
export declare const LoginSchema: z.ZodObject<{
|
|
371
|
-
email: z.ZodString
|
|
372
|
-
password: z.ZodString
|
|
371
|
+
email: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
372
|
+
password: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
373
373
|
}, "strip", z.ZodTypeAny, {
|
|
374
|
-
email
|
|
375
|
-
password
|
|
374
|
+
email?: string | null | undefined;
|
|
375
|
+
password?: string | null | undefined;
|
|
376
376
|
}, {
|
|
377
|
-
email
|
|
378
|
-
password
|
|
377
|
+
email?: string | null | undefined;
|
|
378
|
+
password?: string | null | undefined;
|
|
379
379
|
}>;
|
|
380
380
|
export declare const createPaginatedSchema: <T>(documentSchema: z.ZodSchema<T>) => z.ZodObject<{
|
|
381
381
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
@@ -414,7 +414,7 @@ export declare const createPaginatedSchema: <T>(documentSchema: z.ZodSchema<T>)
|
|
|
414
414
|
}>;
|
|
415
415
|
export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodObject<{
|
|
416
416
|
success: z.ZodBoolean;
|
|
417
|
-
message: z.ZodString
|
|
417
|
+
message: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
418
418
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
419
419
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
420
420
|
page: z.ZodNumber;
|
|
@@ -452,7 +452,7 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
452
452
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
453
453
|
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
454
454
|
success: z.ZodBoolean;
|
|
455
|
-
message: z.ZodString
|
|
455
|
+
message: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
456
456
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
457
457
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
458
458
|
page: z.ZodNumber;
|
|
@@ -490,7 +490,7 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
490
490
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
491
491
|
}>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
492
492
|
success: z.ZodBoolean;
|
|
493
|
-
message: z.ZodString
|
|
493
|
+
message: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
494
494
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
495
495
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
496
496
|
page: z.ZodNumber;
|
|
@@ -528,7 +528,7 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
528
528
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
529
529
|
}>, any>[k]; } : never, z.baseObjectInputType<{
|
|
530
530
|
success: z.ZodBoolean;
|
|
531
|
-
message: z.ZodString
|
|
531
|
+
message: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
532
532
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
533
533
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
534
534
|
page: z.ZodNumber;
|
|
@@ -566,7 +566,7 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
566
566
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
567
567
|
}> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{
|
|
568
568
|
success: z.ZodBoolean;
|
|
569
|
-
message: z.ZodString
|
|
569
|
+
message: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
570
570
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
571
571
|
metadata: z.ZodOptional<z.ZodObject<{
|
|
572
572
|
page: z.ZodNumber;
|
|
@@ -604,14 +604,14 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
604
604
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
605
605
|
}>[k_1]; } : never>;
|
|
606
606
|
export declare const TokenSchema: z.ZodObject<{
|
|
607
|
-
accessToken: z.ZodString
|
|
608
|
-
refreshToken: z.ZodString
|
|
607
|
+
accessToken: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
608
|
+
refreshToken: z.ZodString | z.ZodOptional<z.ZodString> | z.ZodNullable<z.ZodString> | z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
609
609
|
}, "strip", z.ZodTypeAny, {
|
|
610
|
-
refreshToken
|
|
611
|
-
accessToken
|
|
610
|
+
refreshToken?: string | null | undefined;
|
|
611
|
+
accessToken?: string | null | undefined;
|
|
612
612
|
}, {
|
|
613
|
-
refreshToken
|
|
614
|
-
accessToken
|
|
613
|
+
refreshToken?: string | null | undefined;
|
|
614
|
+
accessToken?: string | null | undefined;
|
|
615
615
|
}>;
|
|
616
616
|
export declare const UpdateSortingOrderSchema: z.ZodObject<{
|
|
617
617
|
startIndex: z.ZodDefault<z.ZodNumber>;
|
|
@@ -91,8 +91,11 @@ exports.WorkHourSettingSchema = zod_1.z.object({
|
|
|
91
91
|
holidayHours: global_validation_1.ZodValidation.array(exports.HolidayHourSchema).default([]),
|
|
92
92
|
});
|
|
93
93
|
exports.LoginSchema = zod_1.z.object({
|
|
94
|
-
email: global_validation_1.ZodValidation.email('Email'
|
|
95
|
-
|
|
94
|
+
email: global_validation_1.ZodValidation.email('Email', {
|
|
95
|
+
requiredMessage: 'Please enter a valid email address.',
|
|
96
|
+
invalidMessage: 'Please enter a valid email address.',
|
|
97
|
+
}),
|
|
98
|
+
password: global_validation_1.ZodValidation.string('Password', { requiredMessage: 'Please enter password' }),
|
|
96
99
|
});
|
|
97
100
|
const metadataSchema = zod_1.z.object({
|
|
98
101
|
page: global_validation_1.ZodValidation.number(),
|