@lyxa.ai/core 1.4.275 → 1.4.277
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 +1 -5
- package/dist/index.js.map +1 -1
- package/dist/libraries/google-translate/google-translate.client.d.ts +5 -0
- package/dist/libraries/google-translate/google-translate.client.js +44 -0
- package/dist/libraries/google-translate/google-translate.client.js.map +1 -0
- package/dist/libraries/google-translate/google-translate.dto.d.ts +13 -0
- package/dist/libraries/google-translate/google-translate.dto.js +3 -0
- package/dist/libraries/google-translate/google-translate.dto.js.map +1 -0
- package/dist/libraries/google-translate/google-translate.service.d.ts +5 -5
- package/dist/libraries/google-translate/google-translate.service.js +56 -39
- package/dist/libraries/google-translate/google-translate.service.js.map +1 -1
- package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +12 -12
- package/dist/types/utilities/validation/global-validation.d.ts +2 -0
- package/dist/types/utilities/validation/global-validation.js.map +1 -1
- package/dist/utilities/validation/global-validation.d.ts +2 -0
- package/dist/utilities/validation/global-validation.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -120,11 +120,7 @@ async function registerLibraries(options) {
|
|
|
120
120
|
typedi_1.Container.set(logger_kit_1.LyxaLoggerKit, loggerKit);
|
|
121
121
|
const firebaseInstance = new firebase_1.FirebaseService(configurationInstance);
|
|
122
122
|
typedi_1.Container.set(firebase_1.FirebaseService, firebaseInstance);
|
|
123
|
-
|
|
124
|
-
if (!googleTranslateApiKey) {
|
|
125
|
-
throw new Error('GOOGLE_TRANSLATE_API_KEY not found');
|
|
126
|
-
}
|
|
127
|
-
typedi_1.Container.set(google_translate_1.GoogleTranslateService, new google_translate_1.GoogleTranslateService(googleTranslateApiKey));
|
|
123
|
+
typedi_1.Container.set(google_translate_1.GoogleTranslateService, typedi_1.Container.get(google_translate_1.GoogleTranslateService));
|
|
128
124
|
const microserviceDispatcherInstance = new dispatcher_1.MicroServiceDispatcher(secretInstance);
|
|
129
125
|
typedi_1.Container.set(dispatcher_1.MicroServiceDispatcher, microserviceDispatcherInstance);
|
|
130
126
|
const twilioServiceInstance = new twilio_1.TwilioService();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,sCA0BC;AAED,8CAkHC;AAED,oCAEC;AAvLD,qFAAqF;AAErF,IAAA,0CAAqB,GAAE,CAAC;AAExB,2CAA6C;AAC7C,mCAAmC;AACnC,6DAAuF;AACvF,+CAAgD;AAChD,6CAAiD;AACjD,6CAAoF;AACpF,iDAA2D;AAC3D,uDAAgE;AAChE,+CAAmD;AACnD,mDAAuD;AACvD,6CAA6E;AAC7E,0FAAuF;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,wFAAmF;AACnF,wEAAmE;AACnE,iEAA4F;AAC5F,+GAA4G;AAC5G,yDAAgE;AAChE,yFAA+E;AAC/E,4FAAuG;AACvG,uDAAuD;AACvD,gFAA2E;AAC3E,8EAAyE;AACzE,gGAAkG;AAClG,mEAAsE;AACtE,iGAAsH;AAGtH,6GAA4G;AAAnG,4IAAA,4BAA4B,OAAA;AACrC,2CAAyD;AAAhD,6GAAA,oBAAoB,OAAA;AAC7B,+DAA6C;AAEtC,KAAK,UAAU,aAAa,CAAC,OAA8B;IACjE,IAAI,CAAC;QACJ,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACjC,YAAY,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,sCAA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,kBAAS,CAAC,GAAG,CAAC,iCAAc,EAAE,cAAc,CAAC,CAAC;IAE9C,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAEtC,MAAM,IAAA,8BAAsB,EAAC,sCAAc,CAAC,OAAO,EAAE,WAAW,IAAI,2DAA4B,CAAC,GAAG,CAAC,CAAC,CAAC;IAEvG,MAAM,gBAAgB,GAAG,2CAAoB,CAAC,mBAAmB,EAAE,CAAC;IAEpE,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEtD,KAAK,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,gBAAgB,EAAE,CAAC;QAC3E,IAAI,QAAQ,GAAG,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,QAAQ,GAAG,kBAAS,CAAC,GAAG,CAAC,iBAAwB,CAAC,CAAC;YACnD,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,IAAA,wBAAgB,EAAC,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,CAAC;AACF,CAAC;AAED,SAAgB,YAAY;IAC3B,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACtC,CAAC","sourcesContent":["// Apply the soft delete plugin globally before any connections or models\nimport { applySoftDeletePlugin } from './libraries/mongo/plugins/soft-delete-plugin';\n\napplySoftDeletePlugin();\n\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection, initLyxaMongoDbConnection } from './libraries/mongo';\nimport { SecretManagerService } from './libraries/secrets';\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\nimport { TwilioService } from './libraries/twilio';\nimport { FirebaseService } from './libraries/firebase';\nimport { initRabbitMQConnection, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { GoogleMapsService, MapService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport { FirebaseFcmService } from './libraries/notification/firebase-fcm.service';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { OsrmMapService } from './libraries/map/providers/osrm';\nimport { RabbitMQUrlMap } from './utilities/environment/rabbitmq-environments';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket/connections/instance-disconnect';\nimport { LyxaLoggerKit } from './libraries/logger-kit';\nimport { LyxaFcmService } from './libraries/notification/lyxa-fcm.service';\nimport { LyxaFcmSender } from './libraries/notification/lyxa-fcm-sender';\nimport { FirebaseMessageBuilderFactory } from './libraries/notification/firebase-message.builder';\nimport { GoogleTranslateService } from './libraries/google-translate';\nimport { TransliterationProvider, TransliterationService } from './libraries/transliteration/transliteration-service';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\nexport * from './libraries/google-translate';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\n\n\t\tconst gracefulShutdown = async () => {\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\n\t\t\tif (options?.instanceType == 'socket') await disconnectAllEntitiesFromInstance();\n\t\t\tprocess.exit();\n\t\t};\n\n\t\tprocess.on('SIGTERM', gracefulShutdown);\n\t\tprocess.on('SIGINT', gracefulShutdown);\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.log('err', err);\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\n\t\t\tgracefulShutdown();\n\t\t});\n\t\tprocess.on('exit', code => {\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\n\t\t});\n\n\t\tconsole.log('Created hooks.');\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n}\n\nexport async function registerLibraries(options?: ConfigurationOptions) {\n\t// Setup configuration.\n\tconst configurationInstance = new ConfigurationService(options);\n\tContainer.set(ConfigurationService, configurationInstance);\n\n\t// Setup redis.\n\tconst redisInstance = new RedisService(configurationInstance.redisURL);\n\tContainer.set(RedisService, redisInstance);\n\n\t// Setup secret\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\n\tContainer.set(SecretManagerService, secretInstance);\n\n\t// Setup BullMQ\n\tconst bullMQInstance = new BullMQService(redisInstance);\n\tContainer.set(BullMQService, bullMQInstance);\n\n\tconst mongoUrl = options?.mongoDbUrl\n\t\t? options.mongoDbUrl\n\t\t: await getLibraries().getSecretsService().getKey('MONGO_URL');\n\n\tawait initLyxaMongoDbConnection(mongoUrl!, options);\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\n\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\tconst loggerKit = new LyxaLoggerKit({ instanceType: options!.instanceType! });\n\tContainer.set(LyxaLoggerKit, loggerKit);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\n\n\t//Setup google translate\n\tconst googleTranslateApiKey = await getLibraries().getSecretsService().getKey('GOOGLE_TRANSLATE_API_KEY');\n\n\tif (!googleTranslateApiKey) {\n\t\tthrow new Error('GOOGLE_TRANSLATE_API_KEY not found');\n\t}\n\n\tContainer.set(GoogleTranslateService, new GoogleTranslateService(googleTranslateApiKey));\n\n\t// Setup microservice dispatcher\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\n\n\t// Setup twilio\n\tconst twilioServiceInstance = new TwilioService();\n\tContainer.set(TwilioService, twilioServiceInstance);\n\n\t// Setup Transliteration service\n\tconst transliterationService = new TransliterationService(TransliterationProvider.OPENAI);\n\tContainer.set(TransliterationService, transliterationService);\n\n\t// Setup map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(redisInstance, googleMapsKey as string);\n\tconst osrmMapService = new OsrmMapService();\n\tconst mapServiceInstance = new MapService(googleMapService, osrmMapService);\n\tContainer.set(MapService, mapServiceInstance);\n\n\t// Setup cash settlement service\n\tconst bobUsername = await getLibraries().getSecretsService().getKey('BOB_USER_NAME');\n\tconst bobPassword = await getLibraries().getSecretsService().getKey('BOB_PASSWORD');\n\tconst bobURL = await getLibraries().getSecretsService().getKey('BOB_URL');\n\n\tconst bobService = new BOBService({\n\t\tBOB_USER_NAME: bobUsername,\n\t\tBOB_PASSWORD: bobPassword,\n\t\tBOB_URL: bobURL,\n\t} as BOBSecrets);\n\tconst cashSettlementServiceInstance = new CashSettlementService(bobService);\n\tContainer.set(CashSettlementService, cashSettlementServiceInstance);\n\tContainer.set(BOBService, bobService);\n\n\tconst settingsServiceInstance = new CachedSettingsService(redisInstance);\n\tContainer.set(CachedSettingsService, settingsServiceInstance);\n\n\ttry {\n\t\tconst settings = await settingsServiceInstance.getSettings();\n\t\tconst { _setTimezone } = await import('./utilities/dayjs/dayjs');\n\t\t_setTimezone(settings?.timezone || 'Asia/Beirut');\n\t\tconsole.log('Timezone initialized:', settings?.timezone || 'Asia/Beirut');\n\t} catch (error) {\n\t\tconsole.error('Failed to initialize timezone:', error);\n\t}\n\n\t// Setup fcm service\n\tconst fcmService = new FirebaseFcmService();\n\tconst builder = new FirebaseMessageBuilderFactory();\n\tconst lyxaFcmSender = new LyxaFcmSender(fcmService, builder);\n\tconst lyxaFcmService = new LyxaFcmService(lyxaFcmSender);\n\n\tContainer.set(FirebaseFcmService, fcmService);\n\tContainer.set(LyxaFcmService, lyxaFcmService);\n\n\tconsole.log('Initialized everything');\n\n\tawait initRabbitMQConnection(RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType.DEV]);\n\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\n\n\tconst instantiatedServices = new Map<Function, any>();\n\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\n\t\tlet instance = instantiatedServices.get(targetConstructor);\n\t\tif (!instance) {\n\t\t\tinstance = Container.get(targetConstructor as any);\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\n\t\t}\n\n\t\tawait subscribeToEvent(eventId, async payload => instance[methodName](payload));\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,sCA0BC;AAED,8CA4GC;AAED,oCAEC;AAjLD,qFAAqF;AAErF,IAAA,0CAAqB,GAAE,CAAC;AAExB,2CAA6C;AAC7C,mCAAmC;AACnC,6DAAuF;AACvF,+CAAgD;AAChD,6CAAiD;AACjD,6CAAoF;AACpF,iDAA2D;AAC3D,uDAAgE;AAChE,+CAAmD;AACnD,mDAAuD;AACvD,6CAA6E;AAC7E,0FAAuF;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,wFAAmF;AACnF,wEAAmE;AACnE,iEAA4F;AAC5F,+GAA4G;AAC5G,yDAAgE;AAChE,yFAA+E;AAC/E,4FAAuG;AACvG,uDAAuD;AACvD,gFAA2E;AAC3E,8EAAyE;AACzE,gGAAkG;AAClG,mEAAsE;AACtE,iGAAsH;AAGtH,6G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,kBAAS,CAAC,GAAG,CAAC,yCAAkB,EAAE,UAAU,CAAC,CAAC;IAC9C,kBAAS,CAAC,GAAG,CAAC,iCAAc,EAAE,cAAc,CAAC,CAAC;IAE9C,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAEtC,MAAM,IAAA,8BAAsB,EAAC,sCAAc,CAAC,OAAO,EAAE,WAAW,IAAI,2DAA4B,CAAC,GAAG,CAAC,CAAC,CAAC;IAEvG,MAAM,gBAAgB,GAAG,2CAAoB,CAAC,mBAAmB,EAAE,CAAC;IAEpE,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEtD,KAAK,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,gBAAgB,EAAE,CAAC;QAC3E,IAAI,QAAQ,GAAG,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,QAAQ,GAAG,kBAAS,CAAC,GAAG,CAAC,iBAAwB,CAAC,CAAC;YACnD,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,IAAA,wBAAgB,EAAC,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,CAAC;AACF,CAAC;AAED,SAAgB,YAAY;IAC3B,OAAO,kBAAS,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACtC,CAAC","sourcesContent":["// Apply the soft delete plugin globally before any connections or models\nimport { applySoftDeletePlugin } from './libraries/mongo/plugins/soft-delete-plugin';\n\napplySoftDeletePlugin();\n\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection, initLyxaMongoDbConnection } from './libraries/mongo';\nimport { SecretManagerService } from './libraries/secrets';\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\nimport { TwilioService } from './libraries/twilio';\nimport { FirebaseService } from './libraries/firebase';\nimport { initRabbitMQConnection, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { GoogleMapsService, MapService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport { FirebaseFcmService } from './libraries/notification/firebase-fcm.service';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { OsrmMapService } from './libraries/map/providers/osrm';\nimport { RabbitMQUrlMap } from './utilities/environment/rabbitmq-environments';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket/connections/instance-disconnect';\nimport { LyxaLoggerKit } from './libraries/logger-kit';\nimport { LyxaFcmService } from './libraries/notification/lyxa-fcm.service';\nimport { LyxaFcmSender } from './libraries/notification/lyxa-fcm-sender';\nimport { FirebaseMessageBuilderFactory } from './libraries/notification/firebase-message.builder';\nimport { GoogleTranslateService } from './libraries/google-translate';\nimport { TransliterationProvider, TransliterationService } from './libraries/transliteration/transliteration-service';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\nexport * from './libraries/google-translate';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\n\n\t\tconst gracefulShutdown = async () => {\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\n\t\t\tif (options?.instanceType == 'socket') await disconnectAllEntitiesFromInstance();\n\t\t\tprocess.exit();\n\t\t};\n\n\t\tprocess.on('SIGTERM', gracefulShutdown);\n\t\tprocess.on('SIGINT', gracefulShutdown);\n\t\tprocess.on('uncaughtException', err => {\n\t\t\tconsole.log('err', err);\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\n\t\t\tgracefulShutdown();\n\t\t});\n\t\tprocess.on('exit', code => {\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\n\t\t});\n\n\t\tconsole.log('Created hooks.');\n\t} catch (e) {\n\t\tconsole.error(e);\n\t}\n}\n\nexport async function registerLibraries(options?: ConfigurationOptions) {\n\t// Setup configuration.\n\tconst configurationInstance = new ConfigurationService(options);\n\tContainer.set(ConfigurationService, configurationInstance);\n\n\t// Setup redis.\n\tconst redisInstance = new RedisService(configurationInstance.redisURL);\n\tContainer.set(RedisService, redisInstance);\n\n\t// Setup secret\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\n\tContainer.set(SecretManagerService, secretInstance);\n\n\t// Setup BullMQ\n\tconst bullMQInstance = new BullMQService(redisInstance);\n\tContainer.set(BullMQService, bullMQInstance);\n\n\tconst mongoUrl = options?.mongoDbUrl\n\t\t? options.mongoDbUrl\n\t\t: await getLibraries().getSecretsService().getKey('MONGO_URL');\n\n\tawait initLyxaMongoDbConnection(mongoUrl!, options);\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\n\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\tconst loggerKit = new LyxaLoggerKit({ instanceType: options!.instanceType! });\n\tContainer.set(LyxaLoggerKit, loggerKit);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\n\n\t//Setup google translate\n\tContainer.set(GoogleTranslateService, Container.get(GoogleTranslateService));\n\n\t// Setup microservice dispatcher\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\n\n\t// Setup twilio\n\tconst twilioServiceInstance = new TwilioService();\n\tContainer.set(TwilioService, twilioServiceInstance);\n\n\t// Setup Transliteration service\n\tconst transliterationService = new TransliterationService(TransliterationProvider.OPENAI);\n\tContainer.set(TransliterationService, transliterationService);\n\n\t// Setup map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(redisInstance, googleMapsKey as string);\n\tconst osrmMapService = new OsrmMapService();\n\tconst mapServiceInstance = new MapService(googleMapService, osrmMapService);\n\tContainer.set(MapService, mapServiceInstance);\n\n\t// Setup cash settlement service\n\tconst bobUsername = await getLibraries().getSecretsService().getKey('BOB_USER_NAME');\n\tconst bobPassword = await getLibraries().getSecretsService().getKey('BOB_PASSWORD');\n\tconst bobURL = await getLibraries().getSecretsService().getKey('BOB_URL');\n\n\tconst bobService = new BOBService({\n\t\tBOB_USER_NAME: bobUsername,\n\t\tBOB_PASSWORD: bobPassword,\n\t\tBOB_URL: bobURL,\n\t} as BOBSecrets);\n\tconst cashSettlementServiceInstance = new CashSettlementService(bobService);\n\tContainer.set(CashSettlementService, cashSettlementServiceInstance);\n\tContainer.set(BOBService, bobService);\n\n\tconst settingsServiceInstance = new CachedSettingsService(redisInstance);\n\tContainer.set(CachedSettingsService, settingsServiceInstance);\n\n\ttry {\n\t\tconst settings = await settingsServiceInstance.getSettings();\n\t\tconst { _setTimezone } = await import('./utilities/dayjs/dayjs');\n\t\t_setTimezone(settings?.timezone || 'Asia/Beirut');\n\t\tconsole.log('Timezone initialized:', settings?.timezone || 'Asia/Beirut');\n\t} catch (error) {\n\t\tconsole.error('Failed to initialize timezone:', error);\n\t}\n\n\t// Setup fcm service\n\tconst fcmService = new FirebaseFcmService();\n\tconst builder = new FirebaseMessageBuilderFactory();\n\tconst lyxaFcmSender = new LyxaFcmSender(fcmService, builder);\n\tconst lyxaFcmService = new LyxaFcmService(lyxaFcmSender);\n\n\tContainer.set(FirebaseFcmService, fcmService);\n\tContainer.set(LyxaFcmService, lyxaFcmService);\n\n\tconsole.log('Initialized everything');\n\n\tawait initRabbitMQConnection(RabbitMQUrlMap[options?.environment ?? EnvironmentConfigurationType.DEV]);\n\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\n\n\tconst instantiatedServices = new Map<Function, any>();\n\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\n\t\tlet instance = instantiatedServices.get(targetConstructor);\n\t\tif (!instance) {\n\t\t\tinstance = Container.get(targetConstructor as any);\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\n\t\t}\n\n\t\tawait subscribeToEvent(eventId, async payload => instance[methodName](payload));\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GoogleTranslateClient = void 0;
|
|
10
|
+
const typedi_1 = require("typedi");
|
|
11
|
+
const logSettings_1 = require("@typegoose/typegoose/lib/logSettings");
|
|
12
|
+
let GoogleTranslateClient = class GoogleTranslateClient {
|
|
13
|
+
getUrl(apiKey) {
|
|
14
|
+
return `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;
|
|
15
|
+
}
|
|
16
|
+
async translate(apiKey, input) {
|
|
17
|
+
const response = await fetch(this.getUrl(apiKey), {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(input),
|
|
23
|
+
});
|
|
24
|
+
const responseBody = await response.text();
|
|
25
|
+
logSettings_1.logger.info(`Google Translate Response: ${JSON.stringify({
|
|
26
|
+
status: response.status,
|
|
27
|
+
body: responseBody,
|
|
28
|
+
})}`);
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
logSettings_1.logger.error(`Google Translate API request failed: ${JSON.stringify({
|
|
31
|
+
status: response.status,
|
|
32
|
+
input,
|
|
33
|
+
body: responseBody,
|
|
34
|
+
})}`);
|
|
35
|
+
throw new Error(responseBody);
|
|
36
|
+
}
|
|
37
|
+
return JSON.parse(responseBody);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.GoogleTranslateClient = GoogleTranslateClient;
|
|
41
|
+
exports.GoogleTranslateClient = GoogleTranslateClient = __decorate([
|
|
42
|
+
(0, typedi_1.Service)()
|
|
43
|
+
], GoogleTranslateClient);
|
|
44
|
+
//# sourceMappingURL=google-translate.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-translate.client.js","sourceRoot":"/","sources":["libraries/google-translate/google-translate.client.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mCAAiC;AAEjC,sEAA8D;AAGvD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACzB,MAAM,CAAC,MAAc;QAC5B,OAAO,gEAAgE,MAAM,EAAE,CAAC;IACjF,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,KAA8B;QACpE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACjD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACR,cAAc,EAAE,kBAAkB;aAClC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC3B,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE3C,oBAAM,CAAC,IAAI,CACV,8BAA8B,IAAI,CAAC,SAAS,CAAC;YAC5C,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,IAAI,EAAE,YAAY;SAClB,CAAC,EAAE,CACJ,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YAClB,oBAAM,CAAC,KAAK,CACX,wCAAwC,IAAI,CAAC,SAAS,CAAC;gBACtD,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,KAAK;gBACL,IAAI,EAAE,YAAY;aAClB,CAAC,EAAE,CACJ,CAAC;YAEF,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAsB,CAAC;IACtD,CAAC;CACD,CAAA;AApCY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,gBAAO,GAAE;GACG,qBAAqB,CAoCjC","sourcesContent":["import { Service } from 'typedi';\nimport { GoogleTranslateInputDTO, TranslateResponse } from './google-translate.dto';\nimport { logger } from '@typegoose/typegoose/lib/logSettings';\n\n@Service()\nexport class GoogleTranslateClient {\n\tprivate getUrl(apiKey: string): string {\n\t\treturn `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;\n\t}\n\n\tpublic async translate(apiKey: string, input: GoogleTranslateInputDTO): Promise<TranslateResponse> {\n\t\tconst response = await fetch(this.getUrl(apiKey), {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t},\n\t\t\tbody: JSON.stringify(input),\n\t\t});\n\n\t\tconst responseBody = await response.text();\n\n\t\tlogger.info(\n\t\t\t`Google Translate Response: ${JSON.stringify({\n\t\t\t\tstatus: response.status,\n\t\t\t\tbody: responseBody,\n\t\t\t})}`\n\t\t);\n\t\tif (!response.ok) {\n\t\t\tlogger.error(\n\t\t\t\t`Google Translate API request failed: ${JSON.stringify({\n\t\t\t\t\tstatus: response.status,\n\t\t\t\t\tinput,\n\t\t\t\t\tbody: responseBody,\n\t\t\t\t})}`\n\t\t\t);\n\n\t\t\tthrow new Error(responseBody);\n\t\t}\n\n\t\treturn JSON.parse(responseBody) as TranslateResponse;\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-translate.dto.js","sourceRoot":"/","sources":["libraries/google-translate/google-translate.dto.ts"],"names":[],"mappings":"","sourcesContent":["export interface GoogleTranslateInputDTO {\n\tq: string | string[];\n\ttarget: string;\n\tsource?: string;\n\tformat: 'text';\n}\n\nexport interface TranslateResponse {\n\tdata: {\n\t\ttranslations: {\n\t\t\ttranslatedText: string;\n\t\t}[];\n\t};\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { GoogleTranslateClient } from './google-translate.client';
|
|
1
2
|
export declare class GoogleTranslateService {
|
|
2
|
-
private readonly
|
|
3
|
-
constructor(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
translateBatch(texts: string[], targetLanguage: string, sourceLanguage?: string): Promise<string[]>;
|
|
3
|
+
private readonly googleTranslateClient;
|
|
4
|
+
constructor(googleTranslateClient: GoogleTranslateClient);
|
|
5
|
+
translate(apiKey: string, text: string, targetLanguage: string, sourceLanguage?: string): Promise<string>;
|
|
6
|
+
translateBatch(apiKey: string, texts: string[], targetLanguage: string, sourceLanguage?: string): Promise<string[]>;
|
|
7
7
|
}
|
|
@@ -8,65 +8,82 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.GoogleTranslateService = void 0;
|
|
13
16
|
const typedi_1 = require("typedi");
|
|
17
|
+
const google_translate_client_1 = require("./google-translate.client");
|
|
18
|
+
const logSettings_1 = require("@typegoose/typegoose/lib/logSettings");
|
|
14
19
|
let GoogleTranslateService = class GoogleTranslateService {
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
this.
|
|
18
|
-
}
|
|
19
|
-
get url() {
|
|
20
|
-
return `https://translation.googleapis.com/language/translate/v2?key=${this.apiKey}`;
|
|
20
|
+
googleTranslateClient;
|
|
21
|
+
constructor(googleTranslateClient) {
|
|
22
|
+
this.googleTranslateClient = googleTranslateClient;
|
|
21
23
|
}
|
|
22
|
-
async translate(text, targetLanguage, sourceLanguage) {
|
|
24
|
+
async translate(apiKey, text, targetLanguage, sourceLanguage) {
|
|
23
25
|
if (!text?.trim()) {
|
|
24
26
|
return text;
|
|
25
27
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
source: sourceLanguage,
|
|
35
|
-
format: 'text',
|
|
36
|
-
}),
|
|
28
|
+
const input = {
|
|
29
|
+
q: text,
|
|
30
|
+
target: targetLanguage,
|
|
31
|
+
source: sourceLanguage,
|
|
32
|
+
format: 'text',
|
|
33
|
+
};
|
|
34
|
+
logSettings_1.logger.info('Google Translate request', {
|
|
35
|
+
input,
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
try {
|
|
38
|
+
const result = await this.googleTranslateClient.translate(apiKey, input);
|
|
39
|
+
logSettings_1.logger.info('Google Translate response', {
|
|
40
|
+
input,
|
|
41
|
+
result: result.data,
|
|
42
|
+
});
|
|
43
|
+
return result.data.translations[0]?.translatedText ?? text;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
logSettings_1.logger.error('Google Translate failed', {
|
|
47
|
+
input,
|
|
48
|
+
error,
|
|
49
|
+
});
|
|
50
|
+
throw error;
|
|
40
51
|
}
|
|
41
|
-
const result = (await response.json());
|
|
42
|
-
return result.data.translations[0]?.translatedText ?? text;
|
|
43
52
|
}
|
|
44
|
-
async translateBatch(texts, targetLanguage, sourceLanguage) {
|
|
53
|
+
async translateBatch(apiKey, texts, targetLanguage, sourceLanguage) {
|
|
45
54
|
if (!texts.length) {
|
|
46
55
|
return [];
|
|
47
56
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
source: sourceLanguage,
|
|
57
|
-
format: 'text',
|
|
58
|
-
}),
|
|
57
|
+
const input = {
|
|
58
|
+
q: texts,
|
|
59
|
+
target: targetLanguage,
|
|
60
|
+
source: sourceLanguage,
|
|
61
|
+
format: 'text',
|
|
62
|
+
};
|
|
63
|
+
logSettings_1.logger.info('Google Translate request', {
|
|
64
|
+
input,
|
|
59
65
|
});
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
try {
|
|
67
|
+
const result = await this.googleTranslateClient.translate(apiKey, input);
|
|
68
|
+
logSettings_1.logger.info('Google Translate batch response', {
|
|
69
|
+
input,
|
|
70
|
+
result: result.data,
|
|
71
|
+
});
|
|
72
|
+
return result.data.translations.map(x => x.translatedText);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logSettings_1.logger.error('Google Translate batch failed', {
|
|
76
|
+
input,
|
|
77
|
+
error,
|
|
78
|
+
});
|
|
79
|
+
throw error;
|
|
62
80
|
}
|
|
63
|
-
const result = (await response.json());
|
|
64
|
-
return result.data.translations.map(x => x.translatedText);
|
|
65
81
|
}
|
|
66
82
|
};
|
|
67
83
|
exports.GoogleTranslateService = GoogleTranslateService;
|
|
68
84
|
exports.GoogleTranslateService = GoogleTranslateService = __decorate([
|
|
69
85
|
(0, typedi_1.Service)(),
|
|
70
|
-
|
|
86
|
+
__param(0, (0, typedi_1.Inject)()),
|
|
87
|
+
__metadata("design:paramtypes", [google_translate_client_1.GoogleTranslateClient])
|
|
71
88
|
], GoogleTranslateService);
|
|
72
89
|
//# sourceMappingURL=google-translate.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-translate.service.js","sourceRoot":"/","sources":["libraries/google-translate/google-translate.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-translate.service.js","sourceRoot":"/","sources":["libraries/google-translate/google-translate.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mCAAyC;AACzC,uEAAkE;AAElE,sEAA8D;AAGvD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAGhB;IAFlB,YAEkB,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;IAC3D,CAAC;IAEG,KAAK,CAAC,SAAS,CACrB,MAAc,EACd,IAAY,EACZ,cAAsB,EACtB,cAAuB;QAEvB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,KAAK,GAA4B;YACtC,CAAC,EAAE,IAAI;YACP,MAAM,EAAE,cAAc;YACtB,MAAM,EAAE,cAAc;YACtB,MAAM,EAAE,MAAM;SACd,CAAC;QACF,oBAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;YACvC,KAAK;SACL,CAAC,CAAC;QACH,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACzE,oBAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;gBACxC,KAAK;gBACL,MAAM,EAAE,MAAM,CAAC,IAAI;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AAE;IAGP,WAAA,IAAA,eAAM,GAAE,CAAA;qCAC+B,+CAAqB;GAHlD,sBAAsB,CA+ElC","sourcesContent":["import { Inject, Service } from 'typedi';\nimport { GoogleTranslateClient } from './google-translate.client';\nimport { GoogleTranslateInputDTO } from './google-translate.dto';\nimport { logger } from '@typegoose/typegoose/lib/logSettings';\n\n@Service()\nexport class GoogleTranslateService {\n\tconstructor(\n\t\t@Inject()\n\t\tprivate readonly googleTranslateClient: GoogleTranslateClient\n\t) {}\n\n\tpublic async translate(\n\t\tapiKey: string,\n\t\ttext: string,\n\t\ttargetLanguage: string,\n\t\tsourceLanguage?: string\n\t): Promise<string> {\n\t\tif (!text?.trim()) {\n\t\t\treturn text;\n\t\t}\n\n\t\tconst input: GoogleTranslateInputDTO = {\n\t\t\tq: text,\n\t\t\ttarget: targetLanguage,\n\t\t\tsource: sourceLanguage,\n\t\t\tformat: 'text',\n\t\t};\n\t\tlogger.info('Google Translate request', {\n\t\t\tinput,\n\t\t});\n\t\ttry {\n\t\t\tconst result = await this.googleTranslateClient.translate(apiKey, input);\n\t\t\tlogger.info('Google Translate response', {\n\t\t\t\tinput,\n\t\t\t\tresult: result.data,\n\t\t\t});\n\n\t\t\treturn result.data.translations[0]?.translatedText ?? text;\n\t\t} catch (error) {\n\t\t\tlogger.error('Google Translate failed', {\n\t\t\t\tinput,\n\t\t\t\terror,\n\t\t\t});\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic async translateBatch(\n\t\tapiKey: string,\n\t\ttexts: string[],\n\t\ttargetLanguage: string,\n\t\tsourceLanguage?: string\n\t): Promise<string[]> {\n\t\tif (!texts.length) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst input: GoogleTranslateInputDTO = {\n\t\t\tq: texts,\n\t\t\ttarget: targetLanguage,\n\t\t\tsource: sourceLanguage,\n\t\t\tformat: 'text',\n\t\t};\n\t\tlogger.info('Google Translate request', {\n\t\t\tinput,\n\t\t});\n\n\t\ttry {\n\t\t\tconst result = await this.googleTranslateClient.translate(apiKey, input);\n\t\t\tlogger.info('Google Translate batch response', {\n\t\t\t\tinput,\n\t\t\t\tresult: result.data,\n\t\t\t});\n\n\t\t\treturn result.data.translations.map(x => x.translatedText);\n\t\t} catch (error) {\n\t\t\tlogger.error('Google Translate batch failed', {\n\t\t\t\tinput,\n\t\t\t\terror,\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -5,9 +5,9 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
+
req: import("http").IncomingMessage;
|
|
8
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
10
|
tokenType: TokenType | undefined;
|
|
10
|
-
req: import("http").IncomingMessage;
|
|
11
11
|
requestId: string | undefined;
|
|
12
12
|
entity: import("../context").EntityContext | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
|
|
|
4
4
|
allowedRoles: string[];
|
|
5
5
|
}
|
|
6
6
|
export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
7
|
+
req: import("http").IncomingMessage;
|
|
7
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
8
9
|
tokenType: import("../../auth").TokenType | undefined;
|
|
9
|
-
req: import("http").IncomingMessage;
|
|
10
10
|
requestId: string | undefined;
|
|
11
11
|
entity: import("../context").EntityContext | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
|
|
|
3
3
|
entityTypes: AuthEntityType[];
|
|
4
4
|
}
|
|
5
5
|
export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
6
|
+
req: import("http").IncomingMessage;
|
|
6
7
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
7
8
|
tokenType: import("../../auth").TokenType | undefined;
|
|
8
|
-
req: import("http").IncomingMessage;
|
|
9
9
|
requestId: string | undefined;
|
|
10
10
|
entity: import("../context").EntityContext | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
@@ -5,9 +5,9 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
+
req: import("http").IncomingMessage;
|
|
8
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
10
|
tokenType: TokenType | undefined;
|
|
10
|
-
req: import("http").IncomingMessage;
|
|
11
11
|
requestId: string | undefined;
|
|
12
12
|
entity: import("../context").EntityContext | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
26
26
|
searchFields?: string[] | undefined;
|
|
27
27
|
} | undefined;
|
|
28
28
|
sort?: Record<string, 1 | -1> | undefined;
|
|
29
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
30
29
|
populate?: any;
|
|
30
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
31
31
|
query?: Record<string, any> | undefined;
|
|
32
32
|
}, {
|
|
33
33
|
search?: {
|
|
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
36
36
|
} | undefined;
|
|
37
37
|
sort?: Record<string, 1 | -1> | undefined;
|
|
38
38
|
size?: number | undefined;
|
|
39
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
40
39
|
populate?: any;
|
|
40
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
41
41
|
query?: Record<string, any> | undefined;
|
|
42
42
|
page?: number | undefined;
|
|
43
43
|
}>>;
|
|
@@ -736,12 +736,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
|
|
|
736
736
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
737
737
|
}, "strip", z.ZodTypeAny, {
|
|
738
738
|
_id: import("mongoose").Types.ObjectId;
|
|
739
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
740
739
|
populate?: any;
|
|
740
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
741
741
|
}, {
|
|
742
742
|
_id: string | import("mongoose").Types.ObjectId;
|
|
743
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
744
743
|
populate?: any;
|
|
744
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
745
745
|
}>;
|
|
746
746
|
export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
|
|
747
747
|
export declare const GetProductByIdInputSchema: z.ZodObject<{
|
|
@@ -754,12 +754,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
|
|
|
754
754
|
_id: import("mongoose").Types.ObjectId;
|
|
755
755
|
withAttributeHiddenItems: boolean;
|
|
756
756
|
withAddonsHiddenItems: boolean;
|
|
757
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
758
757
|
populate?: any;
|
|
758
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
759
759
|
}, {
|
|
760
760
|
_id: string | import("mongoose").Types.ObjectId;
|
|
761
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
762
761
|
populate?: any;
|
|
762
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
763
763
|
withAttributeHiddenItems?: boolean | undefined;
|
|
764
764
|
withAddonsHiddenItems?: boolean | undefined;
|
|
765
765
|
}>;
|
|
@@ -773,15 +773,15 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
|
|
|
773
773
|
userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
|
|
774
774
|
}, "strip", z.ZodTypeAny, {
|
|
775
775
|
_id: import("mongoose").Types.ObjectId;
|
|
776
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
777
776
|
populate?: any;
|
|
777
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
778
778
|
groupByCategories?: boolean | undefined;
|
|
779
779
|
getParentCategory?: boolean | undefined;
|
|
780
780
|
userOrderCompletionScope?: UserOrderCompletionScope | undefined;
|
|
781
781
|
}, {
|
|
782
782
|
_id: string | import("mongoose").Types.ObjectId;
|
|
783
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
784
783
|
populate?: any;
|
|
784
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
785
785
|
groupByCategories?: boolean | undefined;
|
|
786
786
|
getParentCategory?: boolean | undefined;
|
|
787
787
|
userOrderCompletionScope?: UserOrderCompletionScope | undefined;
|
|
@@ -791,11 +791,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
|
|
|
791
791
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
792
792
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
793
793
|
}, "strip", z.ZodTypeAny, {
|
|
794
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
795
794
|
populate?: any;
|
|
796
|
-
}, {
|
|
797
795
|
select?: Record<string, 0 | 1> | undefined;
|
|
796
|
+
}, {
|
|
798
797
|
populate?: any;
|
|
798
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
799
799
|
}>>;
|
|
800
800
|
export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
|
|
801
801
|
export declare const GetOneQuerySchema: z.ZodObject<{
|
|
@@ -803,12 +803,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
|
|
|
803
803
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
804
804
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
805
805
|
}, "strip", z.ZodTypeAny, {
|
|
806
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
807
806
|
populate?: any;
|
|
807
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
808
808
|
query?: Record<string, any> | undefined;
|
|
809
809
|
}, {
|
|
810
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
811
810
|
populate?: any;
|
|
811
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
812
812
|
query?: Record<string, any> | undefined;
|
|
813
813
|
}>;
|
|
814
814
|
export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { mongoose } from '@typegoose/typegoose';
|
|
3
|
+
import { Require_id, FlattenMaps } from 'mongoose';
|
|
3
4
|
export declare class ZodValidation {
|
|
4
5
|
static objectIdOrStringSchema: z.ZodType<string | mongoose.Types.ObjectId, z.ZodTypeDef, string | mongoose.Types.ObjectId>;
|
|
5
6
|
static objectId(field?: string): z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
@@ -178,3 +179,4 @@ export interface CustomPaginatedResponse<T> {
|
|
|
178
179
|
totalPages: number;
|
|
179
180
|
};
|
|
180
181
|
}
|
|
182
|
+
export type LeanDocument<T> = Require_id<FlattenMaps<T>>;
|
|
@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AAqB,IAAI,CAAC,UAAU,CAAC;QAE/C,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC;QAED,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;QACvF,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAmBD,aAAa,CAAC,iBAAqC;QAClD,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;YACrD,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;SACpC,CAAC;IACH,CAAC;CACD;AAlND,sCAkNC;AA8CD,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';\nimport { mongoose } from '@typegoose/typegoose';\nimport { parsePhoneNumberFromString } from 'libphonenumber-js';\n\n/**\n * Enhanced validation utilities for creating robust Zod schemas.\n * This class provides a collection of static methods to create common validation patterns.\n *\n * @example\n * ```typescript\n * const userSchema = z.object({\n * username: ZodValidation.requiredString(\"Username is required\"),\n * email: ZodValidation.email(),\n * role: ZodValidation.enumType(UserRole)\n * });\n * ```\n */\nexport class ZodValidation {\n\t/**\n\t * Creates a union type that accepts both string ObjectId and mongoose ObjectId instance.\n\t * This is useful when dealing with both raw string IDs and Mongoose ObjectId instances.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod union schema that accepts both string and ObjectId\n\t *\n\t * @example\n\t * ```typescript\n\t * const idSchema = ZodValidation.objectIdUnion();\n\t * // Accepts \"507f1f77bcf86cd799439011\" or new mongoose.Types.ObjectId(\"507f1f77bcf86cd799439011\")\n\t * ```\n\t */\n\tstatic objectIdOrStringSchema = z.custom<mongoose.Types.ObjectId | string>(\n\t\tval => {\n\t\t\tif (typeof val === 'string' && /^[0-9a-fA-F]{24}$/.test(val)) return true;\n\t\t\tif (typeof val === 'object' && val instanceof mongoose.Types.ObjectId) return true;\n\t\t\treturn false;\n\t\t},\n\t\t{ message: 'Invalid ObjectId' }\n\t);\n\n\tstatic objectId(field: string = 'Field') {\n\t\treturn z.union(\n\t\t\t[\n\t\t\t\tz\n\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t.refine(val => mongoose.Types.ObjectId.isValid(val), {\n\t\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t\t})\n\t\t\t\t\t.transform(val => new mongoose.Types.ObjectId(val)),\n\t\t\t\tz.instanceof(mongoose.Types.ObjectId, {\n\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ message: `${field} is required` }\n\t\t);\n\t}\n\n\t/**\n\t * Creates an enum validation with custom error message.\n\t * This validates that a value is one of the values defined in the enum.\n\t *\n\t * @template T - Type of the enum\n\t * @param enumObj - The enum object to validate against\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates against the provided enum\n\t *\n\t * @example\n\t * ```typescript\n\t * enum UserRole { ADMIN = \"admin\", USER = \"user\" }\n\t * const roleSchema = ZodValidation.enumType(UserRole, \"Invalid user role\");\n\t * ```\n\t */\n\tstatic enumType<T extends z.EnumLike>(enumObj: T, field: string = 'Field') {\n\t\treturn z.nativeEnum(enumObj, {\n\t\t\tmessage: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a required number validation with a minimum length.\n\t * The number is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param min - Minimum number (optional)\n\t * @param max - MAximum number (optional)\n\t * @param options - options (optional)\n\t * @returns A Zod schema that validates numbers with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.Number(\"Price\");\n\t * ```\n\t */\n\tstatic number(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tmin?: number;\n\t\t\tmax?: number;\n\t\t\tisInt?: boolean;\n\t\t\tisPositive?: boolean;\n\t\t\tisNonpositive?: boolean;\n\t\t\tisNegative?: boolean;\n\t\t\tisNonnegative?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.number({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t});\n\n\t\t// Range validation\n\t\tif (options?.min !== undefined) {\n\t\t\tschema = schema.gte(options?.min, {\n\t\t\t\tmessage: `${field} must be at least ${options?.min}`,\n\t\t\t});\n\t\t}\n\t\tif (options?.max !== undefined) {\n\t\t\tschema = schema.lte(options?.max, {\n\t\t\t\tmessage: `${field} must be at most ${options?.max}`,\n\t\t\t});\n\t\t}\n\n\t\t// Option validation\n\t\tif (options?.isInt) {\n\t\t\tschema = schema.int({ message: `${field} must be an integer` });\n\t\t}\n\t\tif (options?.isPositive) {\n\t\t\tschema = schema.positive({ message: `${field} must be positive` });\n\t\t}\n\t\tif (options?.isNonpositive) {\n\t\t\tschema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t}\n\t\tif (options?.isNegative) {\n\t\t\tschema = schema.negative({ message: `${field} must be negative` });\n\t\t}\n\t\tif (options?.isNonnegative) {\n\t\t\tschema = schema.nonnegative({ message: `${field} must be non-negative` });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a required string validation with a minimum length.\n\t * The string is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param minLength - Minimum required length (optional)\n\t * @param maxLength - Maximum required length (optional)\n\t * @param regex - Regular expression (optional)\n\t * @returns A Zod schema that validates strings with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.String(\"Name\");\n\t * ```\n\t */\n\tstatic string(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tminLength?: number;\n\t\t\tmaxLength?: number;\n\t\t\tminMessage?: string;\n\t\t\tmaxMessage?: string;\n\t\t\trequiredMessage?: string;\n\t\t\tregex?: { pattern: RegExp; message: string }; // Add regex option\n\t\t\tisTrimmed?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.string({\n\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t});\n\n\t\tif (options?.minLength) {\n\t\t\tschema = schema.min(\n\t\t\t\toptions.minLength,\n\t\t\t\toptions.minMessage || `${field} must be at least ${options.minLength} characters`\n\t\t\t);\n\t\t}\n\n\t\tif (options?.maxLength) {\n\t\t\tschema = schema.max(\n\t\t\t\toptions.maxLength,\n\t\t\t\toptions.maxMessage || `${field} shouldn’t exceed ${options.maxLength} characters`\n\t\t\t);\n\t\t}\n\n\t\t// Check for regex pattern and add regex validation\n\t\tif (options?.regex) {\n\t\t\tschema = schema.regex(options.regex.pattern, options.regex.message);\n\t\t}\n\n\t\tif (options?.isTrimmed) {\n\t\t\treturn schema\n\t\t\t\t.transform(val => val?.trim())\n\t\t\t\t.refine(val => val?.length && val?.length > 0, {\n\t\t\t\t\tmessage: options?.requiredMessage || `${field} is required`,\n\t\t\t\t});\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates an email validation.\n\t * Validates that the string is a valid email address format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates email addresses\n\t *\n\t * @example\n\t * ```typescript\n\t * const emailSchema = ZodValidation.email(\"Please enter a valid email\");\n\t * ```\n\t */\n\tstatic email(\n\t\tfield: string = 'Email',\n\t\toptions?: {\n\t\t\trequiredMessage?: string;\n\t\t\tinvalidMessage?: string;\n\t\t}\n\t) {\n\t\tconst schema = z\n\t\t\t.string({\n\t\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t\t})\n\t\t\t.trim()\n\t\t\t.email(options?.invalidMessage || `${field} must be a valid email address`)\n\t\t\t.transform(value => value.toLowerCase());\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a URL validation.\n\t * Validates that the string is a valid URL format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates URLs\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.url(\"Please enter a valid URL\");\n\t * ```\n\t */\n\tstatic url(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);\n\t}\n\n\t/**\n\t * Creates a Password validation.\n\t * Validates that the string is a valid password format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates password\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.password(\"Please enter a valid password\");\n\t * ```\n\t */\n\tstatic password(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tval =>\n\t\t\t\t!val || // allow undefined or empty, but validate when provided\n\t\t\t\t(val.length >= 8 && // minimum length\n\t\t\t\t\t/[a-z]/.test(val) && // lowercase\n\t\t\t\t\t/[A-Z]/.test(val) && // uppercase\n\t\t\t\t\t/[0-9]/.test(val) && // number\n\t\t\t\t\t/[!@#$%^&*(),.?\":{}|<>]/.test(val)), // special char\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t'Password must include at least one uppercase letter, one lowercase letter, one number, one special character and minimum 8 character required',\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Creates a phone number validation schema using a regex pattern for global phone numbers.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates phone numbers\n\t *\n\t * @example\n\t * ```typescript\n\t * const phoneSchema = ZodValidation.phoneNumber(\"Phone number\");\n\t * ```\n\t */\n\n\tstatic phoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tvalue => {\n\t\t\t\ttry {\n\t\t\t\t\tconst phone = parsePhoneNumberFromString(value);\n\t\t\t\t\treturn phone?.isValid();\n\t\t\t\t} catch {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\tmessage: `Please enter a valid phone number`,\n\t\t\t}\n\t\t);\n\t}\n\n\tstatic validPhoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).superRefine((phoneWithCountryCode, ctx) => {\n\t\t\tconst phoneWithoutCountryCode = phoneWithCountryCode.replace(/^\\+\\d{1,3}/, '');\n\t\t\tif (phoneWithoutCountryCode.length < 4) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `${field} must have 4 or more digits`,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (/^\\d{4}$|^\\d{5}$|^\\d{7}$|^\\d{8}$/.test(phoneWithoutCountryCode)) {\n\t\t\t\treturn; // ✅ Accept 4,5,7 or 8 digit short numbers\n\t\t\t}\n\t\t\t// Otherwise, parse as real phone number\n\t\t\tconst phone = parsePhoneNumberFromString(phoneWithCountryCode);\n\t\t\tif (!phone) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Invalid phone number format in ${field}`,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!phone.isValid()) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Please enter a valid phone number in ${field}`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a date validation.\n\t * Validates that the input is a JavaScript Date object.\n\t *@param field - The name of the field to be included in the error message\n\t *@param minDate - Minimum required date (optional)\n\t *@param maxDate - Maximum required date (optional)\n\t * @returns A Zod schema that validates Date objects\n\t *\n\t * @example\n\t * ```typescript\n\t * const createdAtSchema = ZodValidation.date();\n\t * ```\n\t */\n\tstatic date(field: string = 'Field', minDate?: Date, maxDate?: Date) {\n\t\treturn z\n\t\t\t.union(\n\t\t\t\t[\n\t\t\t\t\tz\n\t\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t\t.refine(val => {\n\t\t\t\t\t\t\tconst date = new Date(val);\n\t\t\t\t\t\t\treturn !isNaN(date.getTime());\n\t\t\t\t\t\t}, `${field} must be a valid date`)\n\t\t\t\t\t\t.transform(val => new Date(val)),\n\t\t\t\t\tz.date({\n\t\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\t{ message: `${field} is required` }\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => minDate === undefined || val >= minDate,\n\t\t\t\t`${field} must be on or after ${minDate?.toISOString()}`\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => maxDate === undefined || val <= maxDate,\n\t\t\t\t`${field} must be on or before ${maxDate?.toISOString()}`\n\t\t\t);\n\t}\n\n\t/**\n\t * Creates a boolean validation with an optional default value.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates booleans\n\t *\n\t * @example\n\t * ```typescript\n\t * const isActiveSchema = ZodValidation.boolean(true); // Defaults to true\n\t * ```\n\t */\n\tstatic boolean(field: string = 'Field') {\n\t\treturn z.boolean({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a boolean`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an array validation with optional minimum items constraint.\n\t *\n\t * @template T - Type of the schema for array items\n\t * @param schema - The schema for validating array items\n\t * @param field - The name of the field to be included in the error message\n\t * @param minItems - Minimum number of items required (optional)\n\t * @param maxItems - Maximum number of items required (optional)\n\t * @returns A Zod schema that validates arrays\n\t *\n\t * @example\n\t * ```typescript\n\t * const tagsSchema = ZodValidation.array(z.string(), \"At least one tag required\", 1);\n\t * ```\n\t */\n\tstatic array<T extends z.ZodTypeAny>(\n\t\tschema: T,\n\t\tfield: string = 'Array',\n\t\tminItems?: number,\n\t\tmaxItems?: number\n\t) {\n\t\tlet arraySchema = z.array(schema, {\n\t\t\trequired_error: `${field} is required`,\n\t\t});\n\n\t\tif (minItems === 1) {\n\t\t\tarraySchema = arraySchema.min(1, `${field} cannot be empty`);\n\t\t}\n\t\tif (minItems !== undefined && minItems !== 1) {\n\t\t\tarraySchema = arraySchema.min(minItems, `${field} must have at least ${minItems} items`);\n\t\t}\n\t\tif (maxItems !== undefined) {\n\t\t\tarraySchema = arraySchema.max(maxItems, `${field} must have at most ${maxItems} items`);\n\t\t}\n\n\t\treturn arraySchema;\n\t}\n\n\t/**\n\t * Standard timestamp fields for entities.\n\t * Includes createdAt, updatedAt, and deletedAt fields.\n\t *\n\t * @returns An object containing timestamp field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = z.object({\n\t * name: z.string(),\n\t * ...ZodValidation.timestamps()\n\t * });\n\t * ```\n\t */\n\tstatic timestamps() {\n\t\treturn {\n\t\t\tcreatedAt: z.date().nullable().optional(),\n\t\t\tupdatedAt: z.date().nullable().optional(),\n\t\t\tdeletedAt: z.date().nullable().optional(),\n\t\t};\n\t}\n\n\t/**\n\t * Common fields for tracking model metadata.\n\t * Includes timestamps and user tracking fields (createdBy, updatedBy, deletedBy).\n\t *\n\t * @returns An object containing tracking field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const postSchema = z.object({\n\t * title: z.string(),\n\t * content: z.string(),\n\t * ...ZodValidation.trackingFields()\n\t * });\n\t * ```\n\t */\n\tstatic trackingFields() {\n\t\treturn {\n\t\t\tcreatedBy: ZodValidation.objectId().optional(),\n\t\t\tupdatedBy: ZodValidation.objectId().optional(),\n\t\t\tdeletedBy: ZodValidation.objectId().optional(),\n\t\t\t...ZodValidation.timestamps(),\n\t\t};\n\t}\n\n\t/**\n\t * Namespace for coercion-based Zod validators.\n\t * Provides schemas that automatically convert input types to the expected type.\n\t *\n\t * @example\n\t * ```typescript\n\t * const schema = z.object({\n\t * startDate: ZodValidation.coerce.date(\"Start Date\"),\n\t * age: ZodValidation.coerce.number(\"Age\", { min: 18 }),\n\t * isActive: ZodValidation.coerce.boolean(\"Active\"),\n\t * });\n\t * ```\n\t */\n\tstatic coerce = {\n\t\tnumber: (\n\t\t\tfield: string = 'Field',\n\t\t\toptions?: {\n\t\t\t\tmin?: number;\n\t\t\t\tmax?: number;\n\t\t\t\tisInt?: boolean;\n\t\t\t\tisPositive?: boolean;\n\t\t\t\tisNonpositive?: boolean;\n\t\t\t\tisNegative?: boolean;\n\t\t\t\tisNonnegative?: boolean;\n\t\t\t}\n\t\t) => {\n\t\t\tlet schema = z.coerce.number({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t\t});\n\n\t\t\tif (options?.min !== undefined) {\n\t\t\t\tschema = schema.gte(options.min, { message: `${field} must be at least ${options.min}` });\n\t\t\t}\n\t\t\tif (options?.max !== undefined) {\n\t\t\t\tschema = schema.lte(options.max, { message: `${field} must be at most ${options.max}` });\n\t\t\t}\n\t\t\tif (options?.isInt) schema = schema.int({ message: `${field} must be an integer` });\n\t\t\tif (options?.isPositive) schema = schema.positive({ message: `${field} must be positive` });\n\t\t\tif (options?.isNonpositive) schema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t\tif (options?.isNegative) schema = schema.negative({ message: `${field} must be negative` });\n\t\t\tif (options?.isNonnegative) schema = schema.nonnegative({ message: `${field} must be non-negative` });\n\n\t\t\treturn schema;\n\t\t},\n\n\t\tdate: (field: string = 'Field', minDate?: Date, maxDate?: Date) => {\n\t\t\treturn z.coerce\n\t\t\t\t.date({\n\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t})\n\t\t\t\t.refine(val => minDate === undefined || val >= minDate, {\n\t\t\t\t\tmessage: `${field} must be on or after ${minDate?.toISOString()}`,\n\t\t\t\t})\n\t\t\t\t.refine(val => maxDate === undefined || val <= maxDate, {\n\t\t\t\t\tmessage: `${field} must be on or before ${maxDate?.toISOString()}`,\n\t\t\t\t});\n\t\t},\n\n\t\tboolean: (field: string = 'Field') => {\n\t\t\treturn z.coerce.boolean({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be true or false`,\n\t\t\t});\n\t\t},\n\t\tobjectId: (field: string = 'Field') =>\n\t\t\tz\n\t\t\t\t.custom<mongoose.Types.ObjectId>(\n\t\t\t\t\tval => {\n\t\t\t\t\t\tif (typeof val === 'string' && mongoose.Types.ObjectId.isValid(val)) return true;\n\t\t\t\t\t\tif (val instanceof mongoose.Types.ObjectId) return true;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t\t{ message: `${field} must be a valid ObjectId` }\n\t\t\t\t)\n\t\t\t\t.transform(val => (typeof val === 'string' ? new mongoose.Types.ObjectId(val) : val)),\n\t};\n}\n\n/**\n * Represents the common fields to exclude from update operations.\n * This is used to specify which fields should not be updateable.\n *\n * @example\n * ```typescript\n * const excludeFields: ExcludeFromUpdate = {\n * createdAt: true,\n * createdBy: true,\n * status: true // Prevent status from being updated\n * };\n * ```\n */\nexport type ExcludeFromUpdate = {\n\tcreatedAt?: true;\n\tupdatedAt?: true;\n\tdeletedAt?: true;\n\tcreatedBy?: true;\n\t_id?: true;\n} & Record<string, true>;\n\n/**\n * Schema builder for creating consistent CRUD schemas.\n * Provides utility methods to generate schemas for create, read, update, and delete operations.\n *\n * @template T - Type of the base schema shape\n *\n * @example\n * ```typescript\n * const userBuilder = new SchemaBuilder({\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * const schemas = userBuilder.getAllSchemas();\n * ```\n */\nexport class SchemaBuilder<T extends z.ZodRawShape> {\n\tprivate baseSchema: z.ZodObject<T>;\n\n\t/**\n\t * Create a new schema builder\n\t *\n\t * @param baseFields - The base fields for the schema\n\t * @param includeTimestamps - Whether to include timestamp fields (default: true)\n\t * @param includeTracking - Whether to include tracking fields (createdBy, etc.) (default: false)\n\t *\n\t * @example\n\t * ```typescript\n\t * const userFields = {\n\t * name: ZodValidation.requiredString(),\n\t * email: ZodValidation.email()\n\t * };\n\t *\n\t * // With timestamps\n\t * const builder1 = new SchemaBuilder(userFields);\n\t *\n\t * // Without timestamps\n\t * const builder2 = new SchemaBuilder(userFields, false);\n\t *\n\t * // With tracking fields\n\t * const builder3 = new SchemaBuilder(userFields, true, true);\n\t * ```\n\t */\n\tconstructor(\n\t\tbaseFields: T,\n\t\tprivate includeTimestamps: boolean = true,\n\t\tprivate includeTracking: boolean = false\n\t) {\n\t\tthis.baseSchema = this.createBaseSchema(baseFields);\n\t}\n\n\t/**\n\t * Creates the base schema with optional timestamps and tracking fields.\n\t */\n\tprivate createBaseSchema(baseFields: T) {\n\t\tconst additionalFields = this.includeTracking\n\t\t\t? ZodValidation.trackingFields()\n\t\t\t: this.includeTimestamps\n\t\t\t\t? ZodValidation.timestamps()\n\t\t\t\t: {};\n\n\t\treturn z.object({\n\t\t\t...baseFields,\n\t\t\t...additionalFields,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the base validation schema without ID.\n\t * Used for creating new entities.\n\t *\n\t * @returns The base schema for creating new entities\n\t *\n\t * @example\n\t * ```typescript\n\t * const createUserSchema = userBuilder.getBaseSchema();\n\t * ```\n\t */\n\tgetBaseSchema() {\n\t\treturn this.baseSchema.strict();\n\t}\n\n\t/**\n\t * Gets the schema for entities with ID.\n\t * Used for representing complete entities with their ID.\n\t *\n\t * @returns The entity schema including ID\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = userBuilder.getEntitySchema();\n\t * ```\n\t */\n\tgetEntitySchema() {\n\t\treturn this.baseSchema\n\t\t\t.extend({\n\t\t\t\t_id: ZodValidation.objectId(),\n\t\t\t})\n\t\t\t.partial()\n\t\t\t.passthrough();\n\t}\n\n\t/**\n\t * Gets the schema for validating an entity ID.\n\t * Used for validating ID parameters in requests.\n\t *\n\t * @returns The ID validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const userIdSchema = userBuilder.getIdSchema();\n\t * ```\n\t */\n\tgetIdSchema() {\n\t\treturn ZodValidation.objectId();\n\t}\n\n\t/**\n\t * Gets the schema for updating an entity, excluding specified fields.\n\t * Creates a partial schema where all fields are optional, and removes\n\t * fields that should not be updatable.\n\t *\n\t * @param excludeFields - Fields to exclude from update operations\n\t * @returns The update schema with excluded fields removed\n\t *\n\t * @example\n\t * ```typescript\n\t * // Prevent updating createdAt and status\n\t * const updateUserSchema = userBuilder.getUpdateSchema({\n\t * createdAt: true,\n\t * status: true\n\t * });\n\t * ```\n\t */\n\tgetUpdateSchema(excludeFields: ExcludeFromUpdate = { createdAt: true, updatedAt: true }) {\n\t\tconst entitySchema = this.getEntitySchema();\n\n\t\t// Simple approach - just make everything optional\n\t\tif (Object.keys(excludeFields).length === 0) {\n\t\t\treturn entitySchema;\n\t\t}\n\n\t\t// For the type-safe approach, we need to create a new schema\n\t\t// without the excluded fields and then make it partial\n\n\t\t// Get all fields from the entity schema\n\t\tconst shape = entitySchema._def.shape();\n\n\t\t// Filter out the fields we want to exclude\n\t\tconst filteredShape: z.ZodRawShape = {};\n\t\tfor (const key in shape) {\n\t\t\tif (!excludeFields[key as keyof typeof excludeFields]) {\n\t\t\t\tfilteredShape[key] = shape[key];\n\t\t\t}\n\t\t}\n\n\t\t// Create a new schema with the filtered fields\n\t\treturn z.object(filteredShape).partial().strict();\n\t}\n\n\t/**\n\t * Gets the schema for validating a delete request.\n\t * Used for validating parameters in delete requests, including the entity ID and soft delete flag.\n\t *\n\t * @returns The delete validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const deleteSchema = userBuilder.getDeleteSchema();\n\t * ```\n\t */\n\tgetDeleteSchema() {\n\t\treturn z.object({\n\t\t\t_id: ZodValidation.objectId('_id'),\n\t\t\tsoftDelete: ZodValidation.boolean('Soft Delete').default(true),\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update schema by optionally extending the base schema with additional fields\n\t * and optionally omitting specified fields.\n\t *\n\t * @param extendFields - Optional fields to add to the schema (e.g., `_id`, `softDelete`).\n\t * @param omitFields - Optional fields to omit from the base schema (e.g., `name`).\n\t * @returns A new Zod schema for updates.\n\t */\n\tupdateBaseSchema(extendFields?: z.ZodRawShape, omitFields?: string[]) {\n\t\tlet schema: z.ZodObject<any> = this.baseSchema;\n\n\t\tif (omitFields && omitFields.length > 0) {\n\t\t\tschema = schema.omit(omitFields.reduce((acc, key) => ({ ...acc, [key]: true }), {}));\n\t\t}\n\n\t\tif (extendFields) {\n\t\t\tschema = schema.extend({ _id: ZodValidation.objectId().optional(), ...extendFields });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Gets all common schemas for an entity.\n\t * Returns base, entity, ID, and update schemas in a single object.\n\t *\n\t * @param excludeFromUpdate - Fields to exclude from update operations\n\t * @returns Object containing all schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const {\n\t * BaseSchema, // For creating\n\t * EntitySchema, // For reading\n\t * IdSchema, // For validating IDs\n\t * UpdateSchema // For updating\n\t * } = userBuilder.getAllSchemas();\n\t * ```\n\t */\n\tgetAllSchemas(excludeFromUpdate?: ExcludeFromUpdate) {\n\t\treturn {\n\t\t\tBaseSchema: this.getBaseSchema(),\n\t\t\tEntitySchema: this.getEntitySchema(),\n\t\t\tIdSchema: this.getIdSchema(),\n\t\t\tUpdateSchema: this.getUpdateSchema(excludeFromUpdate),\n\t\t\tDeleteSchema: this.getDeleteSchema(),\n\t\t};\n\t}\n}\n\n/**\n * Type helper for creating DTO types from creation schemas.\n * Used to derive the type for creating new entities.\n *\n * @template T - The schema type\n *\n * @example\n * ```typescript\n * type CreateUserDTO = DTO<typeof UserValidationSchema>;\n * ```\n */\nexport type DTO<T extends z.ZodType> = z.infer<T>;\n\n/**\n * Creates a schema builder for an entity.\n * Helper function to create a new SchemaBuilder instance.\n *\n * @template T - Type of the base schema shape\n * @param baseFields - Base fields for the entity\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\n * @param includeTracking - Whether to include tracking fields (default: false)\n * @returns A new SchemaBuilder instance\n *\n * @example\n * ```typescript\n * const userFields = {\n * name: ZodValidation.requiredString(),\n * email: ZodValidation.email()\n * };\n *\n * const userSchemaBuilder = createSchemaBuilder(userFields);\n * const userSchemaBuilder = createSchemaBuilder(userFields, true, true); // With tracking\n * ```\n */\nexport type PaginatedResponse<T> = {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n\tdocuments: T[];\n};\n\nexport function createSchemaBuilder<T extends z.ZodRawShape>(\n\tbaseFields: T,\n\tincludeTimestamps: boolean = true,\n\tincludeTracking: boolean = false\n) {\n\treturn new SchemaBuilder(baseFields, includeTimestamps, includeTracking);\n}\n\n// Custom Pagination utilities\nexport interface CustomPaginatorOptions<T> {\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tquery?: any;\n\tselect?: any;\n\tpopulate?: string[] | any[];\n\t// Optional function to transform each document\n\ttransform?: (doc: T) => any;\n}\n\nexport interface CustomPaginatedResponse<T> {\n\tdocuments: T[];\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n}\n"]}
|
|
1
|
+
{"version":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E/C,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC;QAED,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;QACvF,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAmBD,aAAa,CAAC,iBAAqC;QAClD,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;YACrD,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;SACpC,CAAC;IACH,CAAC;CACD;AAlND,sCAkNC;AA8CD,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';\nimport { mongoose } from '@typegoose/typegoose';\nimport { parsePhoneNumberFromString } from 'libphonenumber-js';\nimport { Require_id, FlattenMaps } from 'mongoose';\n\n/**\n * Enhanced validation utilities for creating robust Zod schemas.\n * This class provides a collection of static methods to create common validation patterns.\n *\n * @example\n * ```typescript\n * const userSchema = z.object({\n * username: ZodValidation.requiredString(\"Username is required\"),\n * email: ZodValidation.email(),\n * role: ZodValidation.enumType(UserRole)\n * });\n * ```\n */\nexport class ZodValidation {\n\t/**\n\t * Creates a union type that accepts both string ObjectId and mongoose ObjectId instance.\n\t * This is useful when dealing with both raw string IDs and Mongoose ObjectId instances.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod union schema that accepts both string and ObjectId\n\t *\n\t * @example\n\t * ```typescript\n\t * const idSchema = ZodValidation.objectIdUnion();\n\t * // Accepts \"507f1f77bcf86cd799439011\" or new mongoose.Types.ObjectId(\"507f1f77bcf86cd799439011\")\n\t * ```\n\t */\n\tstatic objectIdOrStringSchema = z.custom<mongoose.Types.ObjectId | string>(\n\t\tval => {\n\t\t\tif (typeof val === 'string' && /^[0-9a-fA-F]{24}$/.test(val)) return true;\n\t\t\tif (typeof val === 'object' && val instanceof mongoose.Types.ObjectId) return true;\n\t\t\treturn false;\n\t\t},\n\t\t{ message: 'Invalid ObjectId' }\n\t);\n\n\tstatic objectId(field: string = 'Field') {\n\t\treturn z.union(\n\t\t\t[\n\t\t\t\tz\n\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t.refine(val => mongoose.Types.ObjectId.isValid(val), {\n\t\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t\t})\n\t\t\t\t\t.transform(val => new mongoose.Types.ObjectId(val)),\n\t\t\t\tz.instanceof(mongoose.Types.ObjectId, {\n\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ message: `${field} is required` }\n\t\t);\n\t}\n\n\t/**\n\t * Creates an enum validation with custom error message.\n\t * This validates that a value is one of the values defined in the enum.\n\t *\n\t * @template T - Type of the enum\n\t * @param enumObj - The enum object to validate against\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates against the provided enum\n\t *\n\t * @example\n\t * ```typescript\n\t * enum UserRole { ADMIN = \"admin\", USER = \"user\" }\n\t * const roleSchema = ZodValidation.enumType(UserRole, \"Invalid user role\");\n\t * ```\n\t */\n\tstatic enumType<T extends z.EnumLike>(enumObj: T, field: string = 'Field') {\n\t\treturn z.nativeEnum(enumObj, {\n\t\t\tmessage: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a required number validation with a minimum length.\n\t * The number is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param min - Minimum number (optional)\n\t * @param max - MAximum number (optional)\n\t * @param options - options (optional)\n\t * @returns A Zod schema that validates numbers with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.Number(\"Price\");\n\t * ```\n\t */\n\tstatic number(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tmin?: number;\n\t\t\tmax?: number;\n\t\t\tisInt?: boolean;\n\t\t\tisPositive?: boolean;\n\t\t\tisNonpositive?: boolean;\n\t\t\tisNegative?: boolean;\n\t\t\tisNonnegative?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.number({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t});\n\n\t\t// Range validation\n\t\tif (options?.min !== undefined) {\n\t\t\tschema = schema.gte(options?.min, {\n\t\t\t\tmessage: `${field} must be at least ${options?.min}`,\n\t\t\t});\n\t\t}\n\t\tif (options?.max !== undefined) {\n\t\t\tschema = schema.lte(options?.max, {\n\t\t\t\tmessage: `${field} must be at most ${options?.max}`,\n\t\t\t});\n\t\t}\n\n\t\t// Option validation\n\t\tif (options?.isInt) {\n\t\t\tschema = schema.int({ message: `${field} must be an integer` });\n\t\t}\n\t\tif (options?.isPositive) {\n\t\t\tschema = schema.positive({ message: `${field} must be positive` });\n\t\t}\n\t\tif (options?.isNonpositive) {\n\t\t\tschema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t}\n\t\tif (options?.isNegative) {\n\t\t\tschema = schema.negative({ message: `${field} must be negative` });\n\t\t}\n\t\tif (options?.isNonnegative) {\n\t\t\tschema = schema.nonnegative({ message: `${field} must be non-negative` });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a required string validation with a minimum length.\n\t * The string is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param minLength - Minimum required length (optional)\n\t * @param maxLength - Maximum required length (optional)\n\t * @param regex - Regular expression (optional)\n\t * @returns A Zod schema that validates strings with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.String(\"Name\");\n\t * ```\n\t */\n\tstatic string(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tminLength?: number;\n\t\t\tmaxLength?: number;\n\t\t\tminMessage?: string;\n\t\t\tmaxMessage?: string;\n\t\t\trequiredMessage?: string;\n\t\t\tregex?: { pattern: RegExp; message: string }; // Add regex option\n\t\t\tisTrimmed?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.string({\n\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t});\n\n\t\tif (options?.minLength) {\n\t\t\tschema = schema.min(\n\t\t\t\toptions.minLength,\n\t\t\t\toptions.minMessage || `${field} must be at least ${options.minLength} characters`\n\t\t\t);\n\t\t}\n\n\t\tif (options?.maxLength) {\n\t\t\tschema = schema.max(\n\t\t\t\toptions.maxLength,\n\t\t\t\toptions.maxMessage || `${field} shouldn’t exceed ${options.maxLength} characters`\n\t\t\t);\n\t\t}\n\n\t\t// Check for regex pattern and add regex validation\n\t\tif (options?.regex) {\n\t\t\tschema = schema.regex(options.regex.pattern, options.regex.message);\n\t\t}\n\n\t\tif (options?.isTrimmed) {\n\t\t\treturn schema\n\t\t\t\t.transform(val => val?.trim())\n\t\t\t\t.refine(val => val?.length && val?.length > 0, {\n\t\t\t\t\tmessage: options?.requiredMessage || `${field} is required`,\n\t\t\t\t});\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates an email validation.\n\t * Validates that the string is a valid email address format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates email addresses\n\t *\n\t * @example\n\t * ```typescript\n\t * const emailSchema = ZodValidation.email(\"Please enter a valid email\");\n\t * ```\n\t */\n\tstatic email(\n\t\tfield: string = 'Email',\n\t\toptions?: {\n\t\t\trequiredMessage?: string;\n\t\t\tinvalidMessage?: string;\n\t\t}\n\t) {\n\t\tconst schema = z\n\t\t\t.string({\n\t\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t\t})\n\t\t\t.trim()\n\t\t\t.email(options?.invalidMessage || `${field} must be a valid email address`)\n\t\t\t.transform(value => value.toLowerCase());\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a URL validation.\n\t * Validates that the string is a valid URL format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates URLs\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.url(\"Please enter a valid URL\");\n\t * ```\n\t */\n\tstatic url(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);\n\t}\n\n\t/**\n\t * Creates a Password validation.\n\t * Validates that the string is a valid password format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates password\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.password(\"Please enter a valid password\");\n\t * ```\n\t */\n\tstatic password(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tval =>\n\t\t\t\t!val || // allow undefined or empty, but validate when provided\n\t\t\t\t(val.length >= 8 && // minimum length\n\t\t\t\t\t/[a-z]/.test(val) && // lowercase\n\t\t\t\t\t/[A-Z]/.test(val) && // uppercase\n\t\t\t\t\t/[0-9]/.test(val) && // number\n\t\t\t\t\t/[!@#$%^&*(),.?\":{}|<>]/.test(val)), // special char\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t'Password must include at least one uppercase letter, one lowercase letter, one number, one special character and minimum 8 character required',\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Creates a phone number validation schema using a regex pattern for global phone numbers.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates phone numbers\n\t *\n\t * @example\n\t * ```typescript\n\t * const phoneSchema = ZodValidation.phoneNumber(\"Phone number\");\n\t * ```\n\t */\n\n\tstatic phoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tvalue => {\n\t\t\t\ttry {\n\t\t\t\t\tconst phone = parsePhoneNumberFromString(value);\n\t\t\t\t\treturn phone?.isValid();\n\t\t\t\t} catch {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\tmessage: `Please enter a valid phone number`,\n\t\t\t}\n\t\t);\n\t}\n\n\tstatic validPhoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).superRefine((phoneWithCountryCode, ctx) => {\n\t\t\tconst phoneWithoutCountryCode = phoneWithCountryCode.replace(/^\\+\\d{1,3}/, '');\n\t\t\tif (phoneWithoutCountryCode.length < 4) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `${field} must have 4 or more digits`,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (/^\\d{4}$|^\\d{5}$|^\\d{7}$|^\\d{8}$/.test(phoneWithoutCountryCode)) {\n\t\t\t\treturn; // ✅ Accept 4,5,7 or 8 digit short numbers\n\t\t\t}\n\t\t\t// Otherwise, parse as real phone number\n\t\t\tconst phone = parsePhoneNumberFromString(phoneWithCountryCode);\n\t\t\tif (!phone) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Invalid phone number format in ${field}`,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!phone.isValid()) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Please enter a valid phone number in ${field}`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a date validation.\n\t * Validates that the input is a JavaScript Date object.\n\t *@param field - The name of the field to be included in the error message\n\t *@param minDate - Minimum required date (optional)\n\t *@param maxDate - Maximum required date (optional)\n\t * @returns A Zod schema that validates Date objects\n\t *\n\t * @example\n\t * ```typescript\n\t * const createdAtSchema = ZodValidation.date();\n\t * ```\n\t */\n\tstatic date(field: string = 'Field', minDate?: Date, maxDate?: Date) {\n\t\treturn z\n\t\t\t.union(\n\t\t\t\t[\n\t\t\t\t\tz\n\t\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t\t.refine(val => {\n\t\t\t\t\t\t\tconst date = new Date(val);\n\t\t\t\t\t\t\treturn !isNaN(date.getTime());\n\t\t\t\t\t\t}, `${field} must be a valid date`)\n\t\t\t\t\t\t.transform(val => new Date(val)),\n\t\t\t\t\tz.date({\n\t\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\t{ message: `${field} is required` }\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => minDate === undefined || val >= minDate,\n\t\t\t\t`${field} must be on or after ${minDate?.toISOString()}`\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => maxDate === undefined || val <= maxDate,\n\t\t\t\t`${field} must be on or before ${maxDate?.toISOString()}`\n\t\t\t);\n\t}\n\n\t/**\n\t * Creates a boolean validation with an optional default value.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates booleans\n\t *\n\t * @example\n\t * ```typescript\n\t * const isActiveSchema = ZodValidation.boolean(true); // Defaults to true\n\t * ```\n\t */\n\tstatic boolean(field: string = 'Field') {\n\t\treturn z.boolean({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a boolean`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an array validation with optional minimum items constraint.\n\t *\n\t * @template T - Type of the schema for array items\n\t * @param schema - The schema for validating array items\n\t * @param field - The name of the field to be included in the error message\n\t * @param minItems - Minimum number of items required (optional)\n\t * @param maxItems - Maximum number of items required (optional)\n\t * @returns A Zod schema that validates arrays\n\t *\n\t * @example\n\t * ```typescript\n\t * const tagsSchema = ZodValidation.array(z.string(), \"At least one tag required\", 1);\n\t * ```\n\t */\n\tstatic array<T extends z.ZodTypeAny>(\n\t\tschema: T,\n\t\tfield: string = 'Array',\n\t\tminItems?: number,\n\t\tmaxItems?: number\n\t) {\n\t\tlet arraySchema = z.array(schema, {\n\t\t\trequired_error: `${field} is required`,\n\t\t});\n\n\t\tif (minItems === 1) {\n\t\t\tarraySchema = arraySchema.min(1, `${field} cannot be empty`);\n\t\t}\n\t\tif (minItems !== undefined && minItems !== 1) {\n\t\t\tarraySchema = arraySchema.min(minItems, `${field} must have at least ${minItems} items`);\n\t\t}\n\t\tif (maxItems !== undefined) {\n\t\t\tarraySchema = arraySchema.max(maxItems, `${field} must have at most ${maxItems} items`);\n\t\t}\n\n\t\treturn arraySchema;\n\t}\n\n\t/**\n\t * Standard timestamp fields for entities.\n\t * Includes createdAt, updatedAt, and deletedAt fields.\n\t *\n\t * @returns An object containing timestamp field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = z.object({\n\t * name: z.string(),\n\t * ...ZodValidation.timestamps()\n\t * });\n\t * ```\n\t */\n\tstatic timestamps() {\n\t\treturn {\n\t\t\tcreatedAt: z.date().nullable().optional(),\n\t\t\tupdatedAt: z.date().nullable().optional(),\n\t\t\tdeletedAt: z.date().nullable().optional(),\n\t\t};\n\t}\n\n\t/**\n\t * Common fields for tracking model metadata.\n\t * Includes timestamps and user tracking fields (createdBy, updatedBy, deletedBy).\n\t *\n\t * @returns An object containing tracking field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const postSchema = z.object({\n\t * title: z.string(),\n\t * content: z.string(),\n\t * ...ZodValidation.trackingFields()\n\t * });\n\t * ```\n\t */\n\tstatic trackingFields() {\n\t\treturn {\n\t\t\tcreatedBy: ZodValidation.objectId().optional(),\n\t\t\tupdatedBy: ZodValidation.objectId().optional(),\n\t\t\tdeletedBy: ZodValidation.objectId().optional(),\n\t\t\t...ZodValidation.timestamps(),\n\t\t};\n\t}\n\n\t/**\n\t * Namespace for coercion-based Zod validators.\n\t * Provides schemas that automatically convert input types to the expected type.\n\t *\n\t * @example\n\t * ```typescript\n\t * const schema = z.object({\n\t * startDate: ZodValidation.coerce.date(\"Start Date\"),\n\t * age: ZodValidation.coerce.number(\"Age\", { min: 18 }),\n\t * isActive: ZodValidation.coerce.boolean(\"Active\"),\n\t * });\n\t * ```\n\t */\n\tstatic coerce = {\n\t\tnumber: (\n\t\t\tfield: string = 'Field',\n\t\t\toptions?: {\n\t\t\t\tmin?: number;\n\t\t\t\tmax?: number;\n\t\t\t\tisInt?: boolean;\n\t\t\t\tisPositive?: boolean;\n\t\t\t\tisNonpositive?: boolean;\n\t\t\t\tisNegative?: boolean;\n\t\t\t\tisNonnegative?: boolean;\n\t\t\t}\n\t\t) => {\n\t\t\tlet schema = z.coerce.number({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t\t});\n\n\t\t\tif (options?.min !== undefined) {\n\t\t\t\tschema = schema.gte(options.min, { message: `${field} must be at least ${options.min}` });\n\t\t\t}\n\t\t\tif (options?.max !== undefined) {\n\t\t\t\tschema = schema.lte(options.max, { message: `${field} must be at most ${options.max}` });\n\t\t\t}\n\t\t\tif (options?.isInt) schema = schema.int({ message: `${field} must be an integer` });\n\t\t\tif (options?.isPositive) schema = schema.positive({ message: `${field} must be positive` });\n\t\t\tif (options?.isNonpositive) schema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t\tif (options?.isNegative) schema = schema.negative({ message: `${field} must be negative` });\n\t\t\tif (options?.isNonnegative) schema = schema.nonnegative({ message: `${field} must be non-negative` });\n\n\t\t\treturn schema;\n\t\t},\n\n\t\tdate: (field: string = 'Field', minDate?: Date, maxDate?: Date) => {\n\t\t\treturn z.coerce\n\t\t\t\t.date({\n\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t})\n\t\t\t\t.refine(val => minDate === undefined || val >= minDate, {\n\t\t\t\t\tmessage: `${field} must be on or after ${minDate?.toISOString()}`,\n\t\t\t\t})\n\t\t\t\t.refine(val => maxDate === undefined || val <= maxDate, {\n\t\t\t\t\tmessage: `${field} must be on or before ${maxDate?.toISOString()}`,\n\t\t\t\t});\n\t\t},\n\n\t\tboolean: (field: string = 'Field') => {\n\t\t\treturn z.coerce.boolean({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be true or false`,\n\t\t\t});\n\t\t},\n\t\tobjectId: (field: string = 'Field') =>\n\t\t\tz\n\t\t\t\t.custom<mongoose.Types.ObjectId>(\n\t\t\t\t\tval => {\n\t\t\t\t\t\tif (typeof val === 'string' && mongoose.Types.ObjectId.isValid(val)) return true;\n\t\t\t\t\t\tif (val instanceof mongoose.Types.ObjectId) return true;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t\t{ message: `${field} must be a valid ObjectId` }\n\t\t\t\t)\n\t\t\t\t.transform(val => (typeof val === 'string' ? new mongoose.Types.ObjectId(val) : val)),\n\t};\n}\n\n/**\n * Represents the common fields to exclude from update operations.\n * This is used to specify which fields should not be updateable.\n *\n * @example\n * ```typescript\n * const excludeFields: ExcludeFromUpdate = {\n * createdAt: true,\n * createdBy: true,\n * status: true // Prevent status from being updated\n * };\n * ```\n */\nexport type ExcludeFromUpdate = {\n\tcreatedAt?: true;\n\tupdatedAt?: true;\n\tdeletedAt?: true;\n\tcreatedBy?: true;\n\t_id?: true;\n} & Record<string, true>;\n\n/**\n * Schema builder for creating consistent CRUD schemas.\n * Provides utility methods to generate schemas for create, read, update, and delete operations.\n *\n * @template T - Type of the base schema shape\n *\n * @example\n * ```typescript\n * const userBuilder = new SchemaBuilder({\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * const schemas = userBuilder.getAllSchemas();\n * ```\n */\nexport class SchemaBuilder<T extends z.ZodRawShape> {\n\tprivate baseSchema: z.ZodObject<T>;\n\n\t/**\n\t * Create a new schema builder\n\t *\n\t * @param baseFields - The base fields for the schema\n\t * @param includeTimestamps - Whether to include timestamp fields (default: true)\n\t * @param includeTracking - Whether to include tracking fields (createdBy, etc.) (default: false)\n\t *\n\t * @example\n\t * ```typescript\n\t * const userFields = {\n\t * name: ZodValidation.requiredString(),\n\t * email: ZodValidation.email()\n\t * };\n\t *\n\t * // With timestamps\n\t * const builder1 = new SchemaBuilder(userFields);\n\t *\n\t * // Without timestamps\n\t * const builder2 = new SchemaBuilder(userFields, false);\n\t *\n\t * // With tracking fields\n\t * const builder3 = new SchemaBuilder(userFields, true, true);\n\t * ```\n\t */\n\tconstructor(\n\t\tbaseFields: T,\n\t\tprivate includeTimestamps: boolean = true,\n\t\tprivate includeTracking: boolean = false\n\t) {\n\t\tthis.baseSchema = this.createBaseSchema(baseFields);\n\t}\n\n\t/**\n\t * Creates the base schema with optional timestamps and tracking fields.\n\t */\n\tprivate createBaseSchema(baseFields: T) {\n\t\tconst additionalFields = this.includeTracking\n\t\t\t? ZodValidation.trackingFields()\n\t\t\t: this.includeTimestamps\n\t\t\t\t? ZodValidation.timestamps()\n\t\t\t\t: {};\n\n\t\treturn z.object({\n\t\t\t...baseFields,\n\t\t\t...additionalFields,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the base validation schema without ID.\n\t * Used for creating new entities.\n\t *\n\t * @returns The base schema for creating new entities\n\t *\n\t * @example\n\t * ```typescript\n\t * const createUserSchema = userBuilder.getBaseSchema();\n\t * ```\n\t */\n\tgetBaseSchema() {\n\t\treturn this.baseSchema.strict();\n\t}\n\n\t/**\n\t * Gets the schema for entities with ID.\n\t * Used for representing complete entities with their ID.\n\t *\n\t * @returns The entity schema including ID\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = userBuilder.getEntitySchema();\n\t * ```\n\t */\n\tgetEntitySchema() {\n\t\treturn this.baseSchema\n\t\t\t.extend({\n\t\t\t\t_id: ZodValidation.objectId(),\n\t\t\t})\n\t\t\t.partial()\n\t\t\t.passthrough();\n\t}\n\n\t/**\n\t * Gets the schema for validating an entity ID.\n\t * Used for validating ID parameters in requests.\n\t *\n\t * @returns The ID validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const userIdSchema = userBuilder.getIdSchema();\n\t * ```\n\t */\n\tgetIdSchema() {\n\t\treturn ZodValidation.objectId();\n\t}\n\n\t/**\n\t * Gets the schema for updating an entity, excluding specified fields.\n\t * Creates a partial schema where all fields are optional, and removes\n\t * fields that should not be updatable.\n\t *\n\t * @param excludeFields - Fields to exclude from update operations\n\t * @returns The update schema with excluded fields removed\n\t *\n\t * @example\n\t * ```typescript\n\t * // Prevent updating createdAt and status\n\t * const updateUserSchema = userBuilder.getUpdateSchema({\n\t * createdAt: true,\n\t * status: true\n\t * });\n\t * ```\n\t */\n\tgetUpdateSchema(excludeFields: ExcludeFromUpdate = { createdAt: true, updatedAt: true }) {\n\t\tconst entitySchema = this.getEntitySchema();\n\n\t\t// Simple approach - just make everything optional\n\t\tif (Object.keys(excludeFields).length === 0) {\n\t\t\treturn entitySchema;\n\t\t}\n\n\t\t// For the type-safe approach, we need to create a new schema\n\t\t// without the excluded fields and then make it partial\n\n\t\t// Get all fields from the entity schema\n\t\tconst shape = entitySchema._def.shape();\n\n\t\t// Filter out the fields we want to exclude\n\t\tconst filteredShape: z.ZodRawShape = {};\n\t\tfor (const key in shape) {\n\t\t\tif (!excludeFields[key as keyof typeof excludeFields]) {\n\t\t\t\tfilteredShape[key] = shape[key];\n\t\t\t}\n\t\t}\n\n\t\t// Create a new schema with the filtered fields\n\t\treturn z.object(filteredShape).partial().strict();\n\t}\n\n\t/**\n\t * Gets the schema for validating a delete request.\n\t * Used for validating parameters in delete requests, including the entity ID and soft delete flag.\n\t *\n\t * @returns The delete validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const deleteSchema = userBuilder.getDeleteSchema();\n\t * ```\n\t */\n\tgetDeleteSchema() {\n\t\treturn z.object({\n\t\t\t_id: ZodValidation.objectId('_id'),\n\t\t\tsoftDelete: ZodValidation.boolean('Soft Delete').default(true),\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update schema by optionally extending the base schema with additional fields\n\t * and optionally omitting specified fields.\n\t *\n\t * @param extendFields - Optional fields to add to the schema (e.g., `_id`, `softDelete`).\n\t * @param omitFields - Optional fields to omit from the base schema (e.g., `name`).\n\t * @returns A new Zod schema for updates.\n\t */\n\tupdateBaseSchema(extendFields?: z.ZodRawShape, omitFields?: string[]) {\n\t\tlet schema: z.ZodObject<any> = this.baseSchema;\n\n\t\tif (omitFields && omitFields.length > 0) {\n\t\t\tschema = schema.omit(omitFields.reduce((acc, key) => ({ ...acc, [key]: true }), {}));\n\t\t}\n\n\t\tif (extendFields) {\n\t\t\tschema = schema.extend({ _id: ZodValidation.objectId().optional(), ...extendFields });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Gets all common schemas for an entity.\n\t * Returns base, entity, ID, and update schemas in a single object.\n\t *\n\t * @param excludeFromUpdate - Fields to exclude from update operations\n\t * @returns Object containing all schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const {\n\t * BaseSchema, // For creating\n\t * EntitySchema, // For reading\n\t * IdSchema, // For validating IDs\n\t * UpdateSchema // For updating\n\t * } = userBuilder.getAllSchemas();\n\t * ```\n\t */\n\tgetAllSchemas(excludeFromUpdate?: ExcludeFromUpdate) {\n\t\treturn {\n\t\t\tBaseSchema: this.getBaseSchema(),\n\t\t\tEntitySchema: this.getEntitySchema(),\n\t\t\tIdSchema: this.getIdSchema(),\n\t\t\tUpdateSchema: this.getUpdateSchema(excludeFromUpdate),\n\t\t\tDeleteSchema: this.getDeleteSchema(),\n\t\t};\n\t}\n}\n\n/**\n * Type helper for creating DTO types from creation schemas.\n * Used to derive the type for creating new entities.\n *\n * @template T - The schema type\n *\n * @example\n * ```typescript\n * type CreateUserDTO = DTO<typeof UserValidationSchema>;\n * ```\n */\nexport type DTO<T extends z.ZodType> = z.infer<T>;\n\n/**\n * Creates a schema builder for an entity.\n * Helper function to create a new SchemaBuilder instance.\n *\n * @template T - Type of the base schema shape\n * @param baseFields - Base fields for the entity\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\n * @param includeTracking - Whether to include tracking fields (default: false)\n * @returns A new SchemaBuilder instance\n *\n * @example\n * ```typescript\n * const userFields = {\n * name: ZodValidation.requiredString(),\n * email: ZodValidation.email()\n * };\n *\n * const userSchemaBuilder = createSchemaBuilder(userFields);\n * const userSchemaBuilder = createSchemaBuilder(userFields, true, true); // With tracking\n * ```\n */\nexport type PaginatedResponse<T> = {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n\tdocuments: T[];\n};\n\nexport function createSchemaBuilder<T extends z.ZodRawShape>(\n\tbaseFields: T,\n\tincludeTimestamps: boolean = true,\n\tincludeTracking: boolean = false\n) {\n\treturn new SchemaBuilder(baseFields, includeTimestamps, includeTracking);\n}\n\n// Custom Pagination utilities\nexport interface CustomPaginatorOptions<T> {\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tquery?: any;\n\tselect?: any;\n\tpopulate?: string[] | any[];\n\t// Optional function to transform each document\n\ttransform?: (doc: T) => any;\n}\n\nexport interface CustomPaginatedResponse<T> {\n\tdocuments: T[];\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n}\n\nexport type LeanDocument<T> = Require_id<FlattenMaps<T>>;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { mongoose } from '@typegoose/typegoose';
|
|
3
|
+
import { Require_id, FlattenMaps } from 'mongoose';
|
|
3
4
|
export declare class ZodValidation {
|
|
4
5
|
static objectIdOrStringSchema: z.ZodType<string | mongoose.Types.ObjectId, z.ZodTypeDef, string | mongoose.Types.ObjectId>;
|
|
5
6
|
static objectId(field?: string): z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
@@ -178,3 +179,4 @@ export interface CustomPaginatedResponse<T> {
|
|
|
178
179
|
totalPages: number;
|
|
179
180
|
};
|
|
180
181
|
}
|
|
182
|
+
export type LeanDocument<T> = Require_id<FlattenMaps<T>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-validation.js","sourceRoot":"/","sources":["utilities/validation/global-validation.ts"],"names":[],"mappings":";;;AAm1BA,kDAMC;AAz1BD,6BAAwB;AACxB,oDAAgD;AAChD,yDAA+D;AAe/D,MAAa,aAAa;IAczB,MAAM,CAAC,sBAAsB,GAAG,OAAC,CAAC,MAAM,CACvC,GAAG,CAAC,EAAE;QACL,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAC1E,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,oBAAQ,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QACnF,OAAO,KAAK,CAAC;IACd,CAAC,EACD,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAC/B,CAAC;IAEF,MAAM,CAAC,QAAQ,CAAC,QAAgB,OAAO;QACtC,OAAO,OAAC,CAAC,KAAK,CACb;YACC,OAAC;iBACC,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E;YACpC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE;YAC5B,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC;YACrD,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;SACpC,CAAC;IACH,CAAC;CACD;AAlND,sCAkNC;AA8CD,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';\nimport { mongoose } from '@typegoose/typegoose';\nimport { parsePhoneNumberFromString } from 'libphonenumber-js';\n\n/**\n * Enhanced validation utilities for creating robust Zod schemas.\n * This class provides a collection of static methods to create common validation patterns.\n *\n * @example\n * ```typescript\n * const userSchema = z.object({\n * username: ZodValidation.requiredString(\"Username is required\"),\n * email: ZodValidation.email(),\n * role: ZodValidation.enumType(UserRole)\n * });\n * ```\n */\nexport class ZodValidation {\n\t/**\n\t * Creates a union type that accepts both string ObjectId and mongoose ObjectId instance.\n\t * This is useful when dealing with both raw string IDs and Mongoose ObjectId instances.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod union schema that accepts both string and ObjectId\n\t *\n\t * @example\n\t * ```typescript\n\t * const idSchema = ZodValidation.objectIdUnion();\n\t * // Accepts \"507f1f77bcf86cd799439011\" or new mongoose.Types.ObjectId(\"507f1f77bcf86cd799439011\")\n\t * ```\n\t */\n\tstatic objectIdOrStringSchema = z.custom<mongoose.Types.ObjectId | string>(\n\t\tval => {\n\t\t\tif (typeof val === 'string' && /^[0-9a-fA-F]{24}$/.test(val)) return true;\n\t\t\tif (typeof val === 'object' && val instanceof mongoose.Types.ObjectId) return true;\n\t\t\treturn false;\n\t\t},\n\t\t{ message: 'Invalid ObjectId' }\n\t);\n\n\tstatic objectId(field: string = 'Field') {\n\t\treturn z.union(\n\t\t\t[\n\t\t\t\tz\n\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t.refine(val => mongoose.Types.ObjectId.isValid(val), {\n\t\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t\t})\n\t\t\t\t\t.transform(val => new mongoose.Types.ObjectId(val)),\n\t\t\t\tz.instanceof(mongoose.Types.ObjectId, {\n\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ message: `${field} is required` }\n\t\t);\n\t}\n\n\t/**\n\t * Creates an enum validation with custom error message.\n\t * This validates that a value is one of the values defined in the enum.\n\t *\n\t * @template T - Type of the enum\n\t * @param enumObj - The enum object to validate against\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates against the provided enum\n\t *\n\t * @example\n\t * ```typescript\n\t * enum UserRole { ADMIN = \"admin\", USER = \"user\" }\n\t * const roleSchema = ZodValidation.enumType(UserRole, \"Invalid user role\");\n\t * ```\n\t */\n\tstatic enumType<T extends z.EnumLike>(enumObj: T, field: string = 'Field') {\n\t\treturn z.nativeEnum(enumObj, {\n\t\t\tmessage: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a required number validation with a minimum length.\n\t * The number is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param min - Minimum number (optional)\n\t * @param max - MAximum number (optional)\n\t * @param options - options (optional)\n\t * @returns A Zod schema that validates numbers with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.Number(\"Price\");\n\t * ```\n\t */\n\tstatic number(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tmin?: number;\n\t\t\tmax?: number;\n\t\t\tisInt?: boolean;\n\t\t\tisPositive?: boolean;\n\t\t\tisNonpositive?: boolean;\n\t\t\tisNegative?: boolean;\n\t\t\tisNonnegative?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.number({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t});\n\n\t\t// Range validation\n\t\tif (options?.min !== undefined) {\n\t\t\tschema = schema.gte(options?.min, {\n\t\t\t\tmessage: `${field} must be at least ${options?.min}`,\n\t\t\t});\n\t\t}\n\t\tif (options?.max !== undefined) {\n\t\t\tschema = schema.lte(options?.max, {\n\t\t\t\tmessage: `${field} must be at most ${options?.max}`,\n\t\t\t});\n\t\t}\n\n\t\t// Option validation\n\t\tif (options?.isInt) {\n\t\t\tschema = schema.int({ message: `${field} must be an integer` });\n\t\t}\n\t\tif (options?.isPositive) {\n\t\t\tschema = schema.positive({ message: `${field} must be positive` });\n\t\t}\n\t\tif (options?.isNonpositive) {\n\t\t\tschema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t}\n\t\tif (options?.isNegative) {\n\t\t\tschema = schema.negative({ message: `${field} must be negative` });\n\t\t}\n\t\tif (options?.isNonnegative) {\n\t\t\tschema = schema.nonnegative({ message: `${field} must be non-negative` });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a required string validation with a minimum length.\n\t * The string is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param minLength - Minimum required length (optional)\n\t * @param maxLength - Maximum required length (optional)\n\t * @param regex - Regular expression (optional)\n\t * @returns A Zod schema that validates strings with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.String(\"Name\");\n\t * ```\n\t */\n\tstatic string(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tminLength?: number;\n\t\t\tmaxLength?: number;\n\t\t\tminMessage?: string;\n\t\t\tmaxMessage?: string;\n\t\t\trequiredMessage?: string;\n\t\t\tregex?: { pattern: RegExp; message: string }; // Add regex option\n\t\t\tisTrimmed?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.string({\n\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t});\n\n\t\tif (options?.minLength) {\n\t\t\tschema = schema.min(\n\t\t\t\toptions.minLength,\n\t\t\t\toptions.minMessage || `${field} must be at least ${options.minLength} characters`\n\t\t\t);\n\t\t}\n\n\t\tif (options?.maxLength) {\n\t\t\tschema = schema.max(\n\t\t\t\toptions.maxLength,\n\t\t\t\toptions.maxMessage || `${field} shouldn’t exceed ${options.maxLength} characters`\n\t\t\t);\n\t\t}\n\n\t\t// Check for regex pattern and add regex validation\n\t\tif (options?.regex) {\n\t\t\tschema = schema.regex(options.regex.pattern, options.regex.message);\n\t\t}\n\n\t\tif (options?.isTrimmed) {\n\t\t\treturn schema\n\t\t\t\t.transform(val => val?.trim())\n\t\t\t\t.refine(val => val?.length && val?.length > 0, {\n\t\t\t\t\tmessage: options?.requiredMessage || `${field} is required`,\n\t\t\t\t});\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates an email validation.\n\t * Validates that the string is a valid email address format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates email addresses\n\t *\n\t * @example\n\t * ```typescript\n\t * const emailSchema = ZodValidation.email(\"Please enter a valid email\");\n\t * ```\n\t */\n\tstatic email(\n\t\tfield: string = 'Email',\n\t\toptions?: {\n\t\t\trequiredMessage?: string;\n\t\t\tinvalidMessage?: string;\n\t\t}\n\t) {\n\t\tconst schema = z\n\t\t\t.string({\n\t\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t\t})\n\t\t\t.trim()\n\t\t\t.email(options?.invalidMessage || `${field} must be a valid email address`)\n\t\t\t.transform(value => value.toLowerCase());\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a URL validation.\n\t * Validates that the string is a valid URL format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates URLs\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.url(\"Please enter a valid URL\");\n\t * ```\n\t */\n\tstatic url(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);\n\t}\n\n\t/**\n\t * Creates a Password validation.\n\t * Validates that the string is a valid password format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates password\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.password(\"Please enter a valid password\");\n\t * ```\n\t */\n\tstatic password(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tval =>\n\t\t\t\t!val || // allow undefined or empty, but validate when provided\n\t\t\t\t(val.length >= 8 && // minimum length\n\t\t\t\t\t/[a-z]/.test(val) && // lowercase\n\t\t\t\t\t/[A-Z]/.test(val) && // uppercase\n\t\t\t\t\t/[0-9]/.test(val) && // number\n\t\t\t\t\t/[!@#$%^&*(),.?\":{}|<>]/.test(val)), // special char\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t'Password must include at least one uppercase letter, one lowercase letter, one number, one special character and minimum 8 character required',\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Creates a phone number validation schema using a regex pattern for global phone numbers.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates phone numbers\n\t *\n\t * @example\n\t * ```typescript\n\t * const phoneSchema = ZodValidation.phoneNumber(\"Phone number\");\n\t * ```\n\t */\n\n\tstatic phoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tvalue => {\n\t\t\t\ttry {\n\t\t\t\t\tconst phone = parsePhoneNumberFromString(value);\n\t\t\t\t\treturn phone?.isValid();\n\t\t\t\t} catch {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\tmessage: `Please enter a valid phone number`,\n\t\t\t}\n\t\t);\n\t}\n\n\tstatic validPhoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).superRefine((phoneWithCountryCode, ctx) => {\n\t\t\tconst phoneWithoutCountryCode = phoneWithCountryCode.replace(/^\\+\\d{1,3}/, '');\n\t\t\tif (phoneWithoutCountryCode.length < 4) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `${field} must have 4 or more digits`,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (/^\\d{4}$|^\\d{5}$|^\\d{7}$|^\\d{8}$/.test(phoneWithoutCountryCode)) {\n\t\t\t\treturn; // ✅ Accept 4,5,7 or 8 digit short numbers\n\t\t\t}\n\t\t\t// Otherwise, parse as real phone number\n\t\t\tconst phone = parsePhoneNumberFromString(phoneWithCountryCode);\n\t\t\tif (!phone) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Invalid phone number format in ${field}`,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!phone.isValid()) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Please enter a valid phone number in ${field}`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a date validation.\n\t * Validates that the input is a JavaScript Date object.\n\t *@param field - The name of the field to be included in the error message\n\t *@param minDate - Minimum required date (optional)\n\t *@param maxDate - Maximum required date (optional)\n\t * @returns A Zod schema that validates Date objects\n\t *\n\t * @example\n\t * ```typescript\n\t * const createdAtSchema = ZodValidation.date();\n\t * ```\n\t */\n\tstatic date(field: string = 'Field', minDate?: Date, maxDate?: Date) {\n\t\treturn z\n\t\t\t.union(\n\t\t\t\t[\n\t\t\t\t\tz\n\t\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t\t.refine(val => {\n\t\t\t\t\t\t\tconst date = new Date(val);\n\t\t\t\t\t\t\treturn !isNaN(date.getTime());\n\t\t\t\t\t\t}, `${field} must be a valid date`)\n\t\t\t\t\t\t.transform(val => new Date(val)),\n\t\t\t\t\tz.date({\n\t\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\t{ message: `${field} is required` }\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => minDate === undefined || val >= minDate,\n\t\t\t\t`${field} must be on or after ${minDate?.toISOString()}`\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => maxDate === undefined || val <= maxDate,\n\t\t\t\t`${field} must be on or before ${maxDate?.toISOString()}`\n\t\t\t);\n\t}\n\n\t/**\n\t * Creates a boolean validation with an optional default value.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates booleans\n\t *\n\t * @example\n\t * ```typescript\n\t * const isActiveSchema = ZodValidation.boolean(true); // Defaults to true\n\t * ```\n\t */\n\tstatic boolean(field: string = 'Field') {\n\t\treturn z.boolean({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a boolean`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an array validation with optional minimum items constraint.\n\t *\n\t * @template T - Type of the schema for array items\n\t * @param schema - The schema for validating array items\n\t * @param field - The name of the field to be included in the error message\n\t * @param minItems - Minimum number of items required (optional)\n\t * @param maxItems - Maximum number of items required (optional)\n\t * @returns A Zod schema that validates arrays\n\t *\n\t * @example\n\t * ```typescript\n\t * const tagsSchema = ZodValidation.array(z.string(), \"At least one tag required\", 1);\n\t * ```\n\t */\n\tstatic array<T extends z.ZodTypeAny>(\n\t\tschema: T,\n\t\tfield: string = 'Array',\n\t\tminItems?: number,\n\t\tmaxItems?: number\n\t) {\n\t\tlet arraySchema = z.array(schema, {\n\t\t\trequired_error: `${field} is required`,\n\t\t});\n\n\t\tif (minItems === 1) {\n\t\t\tarraySchema = arraySchema.min(1, `${field} cannot be empty`);\n\t\t}\n\t\tif (minItems !== undefined && minItems !== 1) {\n\t\t\tarraySchema = arraySchema.min(minItems, `${field} must have at least ${minItems} items`);\n\t\t}\n\t\tif (maxItems !== undefined) {\n\t\t\tarraySchema = arraySchema.max(maxItems, `${field} must have at most ${maxItems} items`);\n\t\t}\n\n\t\treturn arraySchema;\n\t}\n\n\t/**\n\t * Standard timestamp fields for entities.\n\t * Includes createdAt, updatedAt, and deletedAt fields.\n\t *\n\t * @returns An object containing timestamp field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = z.object({\n\t * name: z.string(),\n\t * ...ZodValidation.timestamps()\n\t * });\n\t * ```\n\t */\n\tstatic timestamps() {\n\t\treturn {\n\t\t\tcreatedAt: z.date().nullable().optional(),\n\t\t\tupdatedAt: z.date().nullable().optional(),\n\t\t\tdeletedAt: z.date().nullable().optional(),\n\t\t};\n\t}\n\n\t/**\n\t * Common fields for tracking model metadata.\n\t * Includes timestamps and user tracking fields (createdBy, updatedBy, deletedBy).\n\t *\n\t * @returns An object containing tracking field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const postSchema = z.object({\n\t * title: z.string(),\n\t * content: z.string(),\n\t * ...ZodValidation.trackingFields()\n\t * });\n\t * ```\n\t */\n\tstatic trackingFields() {\n\t\treturn {\n\t\t\tcreatedBy: ZodValidation.objectId().optional(),\n\t\t\tupdatedBy: ZodValidation.objectId().optional(),\n\t\t\tdeletedBy: ZodValidation.objectId().optional(),\n\t\t\t...ZodValidation.timestamps(),\n\t\t};\n\t}\n\n\t/**\n\t * Namespace for coercion-based Zod validators.\n\t * Provides schemas that automatically convert input types to the expected type.\n\t *\n\t * @example\n\t * ```typescript\n\t * const schema = z.object({\n\t * startDate: ZodValidation.coerce.date(\"Start Date\"),\n\t * age: ZodValidation.coerce.number(\"Age\", { min: 18 }),\n\t * isActive: ZodValidation.coerce.boolean(\"Active\"),\n\t * });\n\t * ```\n\t */\n\tstatic coerce = {\n\t\tnumber: (\n\t\t\tfield: string = 'Field',\n\t\t\toptions?: {\n\t\t\t\tmin?: number;\n\t\t\t\tmax?: number;\n\t\t\t\tisInt?: boolean;\n\t\t\t\tisPositive?: boolean;\n\t\t\t\tisNonpositive?: boolean;\n\t\t\t\tisNegative?: boolean;\n\t\t\t\tisNonnegative?: boolean;\n\t\t\t}\n\t\t) => {\n\t\t\tlet schema = z.coerce.number({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t\t});\n\n\t\t\tif (options?.min !== undefined) {\n\t\t\t\tschema = schema.gte(options.min, { message: `${field} must be at least ${options.min}` });\n\t\t\t}\n\t\t\tif (options?.max !== undefined) {\n\t\t\t\tschema = schema.lte(options.max, { message: `${field} must be at most ${options.max}` });\n\t\t\t}\n\t\t\tif (options?.isInt) schema = schema.int({ message: `${field} must be an integer` });\n\t\t\tif (options?.isPositive) schema = schema.positive({ message: `${field} must be positive` });\n\t\t\tif (options?.isNonpositive) schema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t\tif (options?.isNegative) schema = schema.negative({ message: `${field} must be negative` });\n\t\t\tif (options?.isNonnegative) schema = schema.nonnegative({ message: `${field} must be non-negative` });\n\n\t\t\treturn schema;\n\t\t},\n\n\t\tdate: (field: string = 'Field', minDate?: Date, maxDate?: Date) => {\n\t\t\treturn z.coerce\n\t\t\t\t.date({\n\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t})\n\t\t\t\t.refine(val => minDate === undefined || val >= minDate, {\n\t\t\t\t\tmessage: `${field} must be on or after ${minDate?.toISOString()}`,\n\t\t\t\t})\n\t\t\t\t.refine(val => maxDate === undefined || val <= maxDate, {\n\t\t\t\t\tmessage: `${field} must be on or before ${maxDate?.toISOString()}`,\n\t\t\t\t});\n\t\t},\n\n\t\tboolean: (field: string = 'Field') => {\n\t\t\treturn z.coerce.boolean({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be true or false`,\n\t\t\t});\n\t\t},\n\t\tobjectId: (field: string = 'Field') =>\n\t\t\tz\n\t\t\t\t.custom<mongoose.Types.ObjectId>(\n\t\t\t\t\tval => {\n\t\t\t\t\t\tif (typeof val === 'string' && mongoose.Types.ObjectId.isValid(val)) return true;\n\t\t\t\t\t\tif (val instanceof mongoose.Types.ObjectId) return true;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t\t{ message: `${field} must be a valid ObjectId` }\n\t\t\t\t)\n\t\t\t\t.transform(val => (typeof val === 'string' ? new mongoose.Types.ObjectId(val) : val)),\n\t};\n}\n\n/**\n * Represents the common fields to exclude from update operations.\n * This is used to specify which fields should not be updateable.\n *\n * @example\n * ```typescript\n * const excludeFields: ExcludeFromUpdate = {\n * createdAt: true,\n * createdBy: true,\n * status: true // Prevent status from being updated\n * };\n * ```\n */\nexport type ExcludeFromUpdate = {\n\tcreatedAt?: true;\n\tupdatedAt?: true;\n\tdeletedAt?: true;\n\tcreatedBy?: true;\n\t_id?: true;\n} & Record<string, true>;\n\n/**\n * Schema builder for creating consistent CRUD schemas.\n * Provides utility methods to generate schemas for create, read, update, and delete operations.\n *\n * @template T - Type of the base schema shape\n *\n * @example\n * ```typescript\n * const userBuilder = new SchemaBuilder({\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * const schemas = userBuilder.getAllSchemas();\n * ```\n */\nexport class SchemaBuilder<T extends z.ZodRawShape> {\n\tprivate baseSchema: z.ZodObject<T>;\n\n\t/**\n\t * Create a new schema builder\n\t *\n\t * @param baseFields - The base fields for the schema\n\t * @param includeTimestamps - Whether to include timestamp fields (default: true)\n\t * @param includeTracking - Whether to include tracking fields (createdBy, etc.) (default: false)\n\t *\n\t * @example\n\t * ```typescript\n\t * const userFields = {\n\t * name: ZodValidation.requiredString(),\n\t * email: ZodValidation.email()\n\t * };\n\t *\n\t * // With timestamps\n\t * const builder1 = new SchemaBuilder(userFields);\n\t *\n\t * // Without timestamps\n\t * const builder2 = new SchemaBuilder(userFields, false);\n\t *\n\t * // With tracking fields\n\t * const builder3 = new SchemaBuilder(userFields, true, true);\n\t * ```\n\t */\n\tconstructor(\n\t\tbaseFields: T,\n\t\tprivate includeTimestamps: boolean = true,\n\t\tprivate includeTracking: boolean = false\n\t) {\n\t\tthis.baseSchema = this.createBaseSchema(baseFields);\n\t}\n\n\t/**\n\t * Creates the base schema with optional timestamps and tracking fields.\n\t */\n\tprivate createBaseSchema(baseFields: T) {\n\t\tconst additionalFields = this.includeTracking\n\t\t\t? ZodValidation.trackingFields()\n\t\t\t: this.includeTimestamps\n\t\t\t\t? ZodValidation.timestamps()\n\t\t\t\t: {};\n\n\t\treturn z.object({\n\t\t\t...baseFields,\n\t\t\t...additionalFields,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the base validation schema without ID.\n\t * Used for creating new entities.\n\t *\n\t * @returns The base schema for creating new entities\n\t *\n\t * @example\n\t * ```typescript\n\t * const createUserSchema = userBuilder.getBaseSchema();\n\t * ```\n\t */\n\tgetBaseSchema() {\n\t\treturn this.baseSchema.strict();\n\t}\n\n\t/**\n\t * Gets the schema for entities with ID.\n\t * Used for representing complete entities with their ID.\n\t *\n\t * @returns The entity schema including ID\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = userBuilder.getEntitySchema();\n\t * ```\n\t */\n\tgetEntitySchema() {\n\t\treturn this.baseSchema\n\t\t\t.extend({\n\t\t\t\t_id: ZodValidation.objectId(),\n\t\t\t})\n\t\t\t.partial()\n\t\t\t.passthrough();\n\t}\n\n\t/**\n\t * Gets the schema for validating an entity ID.\n\t * Used for validating ID parameters in requests.\n\t *\n\t * @returns The ID validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const userIdSchema = userBuilder.getIdSchema();\n\t * ```\n\t */\n\tgetIdSchema() {\n\t\treturn ZodValidation.objectId();\n\t}\n\n\t/**\n\t * Gets the schema for updating an entity, excluding specified fields.\n\t * Creates a partial schema where all fields are optional, and removes\n\t * fields that should not be updatable.\n\t *\n\t * @param excludeFields - Fields to exclude from update operations\n\t * @returns The update schema with excluded fields removed\n\t *\n\t * @example\n\t * ```typescript\n\t * // Prevent updating createdAt and status\n\t * const updateUserSchema = userBuilder.getUpdateSchema({\n\t * createdAt: true,\n\t * status: true\n\t * });\n\t * ```\n\t */\n\tgetUpdateSchema(excludeFields: ExcludeFromUpdate = { createdAt: true, updatedAt: true }) {\n\t\tconst entitySchema = this.getEntitySchema();\n\n\t\t// Simple approach - just make everything optional\n\t\tif (Object.keys(excludeFields).length === 0) {\n\t\t\treturn entitySchema;\n\t\t}\n\n\t\t// For the type-safe approach, we need to create a new schema\n\t\t// without the excluded fields and then make it partial\n\n\t\t// Get all fields from the entity schema\n\t\tconst shape = entitySchema._def.shape();\n\n\t\t// Filter out the fields we want to exclude\n\t\tconst filteredShape: z.ZodRawShape = {};\n\t\tfor (const key in shape) {\n\t\t\tif (!excludeFields[key as keyof typeof excludeFields]) {\n\t\t\t\tfilteredShape[key] = shape[key];\n\t\t\t}\n\t\t}\n\n\t\t// Create a new schema with the filtered fields\n\t\treturn z.object(filteredShape).partial().strict();\n\t}\n\n\t/**\n\t * Gets the schema for validating a delete request.\n\t * Used for validating parameters in delete requests, including the entity ID and soft delete flag.\n\t *\n\t * @returns The delete validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const deleteSchema = userBuilder.getDeleteSchema();\n\t * ```\n\t */\n\tgetDeleteSchema() {\n\t\treturn z.object({\n\t\t\t_id: ZodValidation.objectId('_id'),\n\t\t\tsoftDelete: ZodValidation.boolean('Soft Delete').default(true),\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update schema by optionally extending the base schema with additional fields\n\t * and optionally omitting specified fields.\n\t *\n\t * @param extendFields - Optional fields to add to the schema (e.g., `_id`, `softDelete`).\n\t * @param omitFields - Optional fields to omit from the base schema (e.g., `name`).\n\t * @returns A new Zod schema for updates.\n\t */\n\tupdateBaseSchema(extendFields?: z.ZodRawShape, omitFields?: string[]) {\n\t\tlet schema: z.ZodObject<any> = this.baseSchema;\n\n\t\tif (omitFields && omitFields.length > 0) {\n\t\t\tschema = schema.omit(omitFields.reduce((acc, key) => ({ ...acc, [key]: true }), {}));\n\t\t}\n\n\t\tif (extendFields) {\n\t\t\tschema = schema.extend({ _id: ZodValidation.objectId().optional(), ...extendFields });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Gets all common schemas for an entity.\n\t * Returns base, entity, ID, and update schemas in a single object.\n\t *\n\t * @param excludeFromUpdate - Fields to exclude from update operations\n\t * @returns Object containing all schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const {\n\t * BaseSchema, // For creating\n\t * EntitySchema, // For reading\n\t * IdSchema, // For validating IDs\n\t * UpdateSchema // For updating\n\t * } = userBuilder.getAllSchemas();\n\t * ```\n\t */\n\tgetAllSchemas(excludeFromUpdate?: ExcludeFromUpdate) {\n\t\treturn {\n\t\t\tBaseSchema: this.getBaseSchema(),\n\t\t\tEntitySchema: this.getEntitySchema(),\n\t\t\tIdSchema: this.getIdSchema(),\n\t\t\tUpdateSchema: this.getUpdateSchema(excludeFromUpdate),\n\t\t\tDeleteSchema: this.getDeleteSchema(),\n\t\t};\n\t}\n}\n\n/**\n * Type helper for creating DTO types from creation schemas.\n * Used to derive the type for creating new entities.\n *\n * @template T - The schema type\n *\n * @example\n * ```typescript\n * type CreateUserDTO = DTO<typeof UserValidationSchema>;\n * ```\n */\nexport type DTO<T extends z.ZodType> = z.infer<T>;\n\n/**\n * Creates a schema builder for an entity.\n * Helper function to create a new SchemaBuilder instance.\n *\n * @template T - Type of the base schema shape\n * @param baseFields - Base fields for the entity\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\n * @param includeTracking - Whether to include tracking fields (default: false)\n * @returns A new SchemaBuilder instance\n *\n * @example\n * ```typescript\n * const userFields = {\n * name: ZodValidation.requiredString(),\n * email: ZodValidation.email()\n * };\n *\n * const userSchemaBuilder = createSchemaBuilder(userFields);\n * const userSchemaBuilder = createSchemaBuilder(userFields, true, true); // With tracking\n * ```\n */\nexport type PaginatedResponse<T> = {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n\tdocuments: T[];\n};\n\nexport function createSchemaBuilder<T extends z.ZodRawShape>(\n\tbaseFields: T,\n\tincludeTimestamps: boolean = true,\n\tincludeTracking: boolean = false\n) {\n\treturn new SchemaBuilder(baseFields, includeTimestamps, includeTracking);\n}\n\n// Custom Pagination utilities\nexport interface CustomPaginatorOptions<T> {\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tquery?: any;\n\tselect?: any;\n\tpopulate?: string[] | any[];\n\t// Optional function to transform each document\n\ttransform?: (doc: T) => any;\n}\n\nexport interface CustomPaginatedResponse<T> {\n\tdocuments: T[];\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"global-validation.js","sourceRoot":"/","sources":["utilities/validation/global-validation.ts"],"names":[],"mappings":";;;AAo1BA,kDAMC;AA11BD,6BAAwB;AACxB,oDAAgD;AAChD,yDAA+D;AAgB/D,MAAa,aAAa;IAczB,MAAM,CAAC,sBAAsB,GAAG,OAAC,CAAC,MAAM,CACvC,GAAG,CAAC,EAAE;QACL,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAC1E,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,oBAAQ,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QACnF,OAAO,KAAK,CAAC;IACd,CAAC,EACD,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAC/B,CAAC;IAEF,MAAM,CAAC,QAAQ,CAAC,QAAgB,OAAO;QACtC,OAAO,OAAC,CAAC,KAAK,CACb;YACC,OAAC;iBACC,MAAM,CAAC,EAAE,cAAc,EAAE,GA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,WAAW,EAAE;YAC5B,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC;YACrD,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;SACpC,CAAC;IACH,CAAC;CACD;AAlND,sCAkNC;AA8CD,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';\nimport { mongoose } from '@typegoose/typegoose';\nimport { parsePhoneNumberFromString } from 'libphonenumber-js';\nimport { Require_id, FlattenMaps } from 'mongoose';\n\n/**\n * Enhanced validation utilities for creating robust Zod schemas.\n * This class provides a collection of static methods to create common validation patterns.\n *\n * @example\n * ```typescript\n * const userSchema = z.object({\n * username: ZodValidation.requiredString(\"Username is required\"),\n * email: ZodValidation.email(),\n * role: ZodValidation.enumType(UserRole)\n * });\n * ```\n */\nexport class ZodValidation {\n\t/**\n\t * Creates a union type that accepts both string ObjectId and mongoose ObjectId instance.\n\t * This is useful when dealing with both raw string IDs and Mongoose ObjectId instances.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod union schema that accepts both string and ObjectId\n\t *\n\t * @example\n\t * ```typescript\n\t * const idSchema = ZodValidation.objectIdUnion();\n\t * // Accepts \"507f1f77bcf86cd799439011\" or new mongoose.Types.ObjectId(\"507f1f77bcf86cd799439011\")\n\t * ```\n\t */\n\tstatic objectIdOrStringSchema = z.custom<mongoose.Types.ObjectId | string>(\n\t\tval => {\n\t\t\tif (typeof val === 'string' && /^[0-9a-fA-F]{24}$/.test(val)) return true;\n\t\t\tif (typeof val === 'object' && val instanceof mongoose.Types.ObjectId) return true;\n\t\t\treturn false;\n\t\t},\n\t\t{ message: 'Invalid ObjectId' }\n\t);\n\n\tstatic objectId(field: string = 'Field') {\n\t\treturn z.union(\n\t\t\t[\n\t\t\t\tz\n\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t.refine(val => mongoose.Types.ObjectId.isValid(val), {\n\t\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t\t})\n\t\t\t\t\t.transform(val => new mongoose.Types.ObjectId(val)),\n\t\t\t\tz.instanceof(mongoose.Types.ObjectId, {\n\t\t\t\t\tmessage: `${field} must be a valid ObjectID`,\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ message: `${field} is required` }\n\t\t);\n\t}\n\n\t/**\n\t * Creates an enum validation with custom error message.\n\t * This validates that a value is one of the values defined in the enum.\n\t *\n\t * @template T - Type of the enum\n\t * @param enumObj - The enum object to validate against\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates against the provided enum\n\t *\n\t * @example\n\t * ```typescript\n\t * enum UserRole { ADMIN = \"admin\", USER = \"user\" }\n\t * const roleSchema = ZodValidation.enumType(UserRole, \"Invalid user role\");\n\t * ```\n\t */\n\tstatic enumType<T extends z.EnumLike>(enumObj: T, field: string = 'Field') {\n\t\treturn z.nativeEnum(enumObj, {\n\t\t\tmessage: `${field} must be one of: ${Object.values(enumObj).join(', ')}`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates a required number validation with a minimum length.\n\t * The number is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param min - Minimum number (optional)\n\t * @param max - MAximum number (optional)\n\t * @param options - options (optional)\n\t * @returns A Zod schema that validates numbers with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.Number(\"Price\");\n\t * ```\n\t */\n\tstatic number(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tmin?: number;\n\t\t\tmax?: number;\n\t\t\tisInt?: boolean;\n\t\t\tisPositive?: boolean;\n\t\t\tisNonpositive?: boolean;\n\t\t\tisNegative?: boolean;\n\t\t\tisNonnegative?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.number({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t});\n\n\t\t// Range validation\n\t\tif (options?.min !== undefined) {\n\t\t\tschema = schema.gte(options?.min, {\n\t\t\t\tmessage: `${field} must be at least ${options?.min}`,\n\t\t\t});\n\t\t}\n\t\tif (options?.max !== undefined) {\n\t\t\tschema = schema.lte(options?.max, {\n\t\t\t\tmessage: `${field} must be at most ${options?.max}`,\n\t\t\t});\n\t\t}\n\n\t\t// Option validation\n\t\tif (options?.isInt) {\n\t\t\tschema = schema.int({ message: `${field} must be an integer` });\n\t\t}\n\t\tif (options?.isPositive) {\n\t\t\tschema = schema.positive({ message: `${field} must be positive` });\n\t\t}\n\t\tif (options?.isNonpositive) {\n\t\t\tschema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t}\n\t\tif (options?.isNegative) {\n\t\t\tschema = schema.negative({ message: `${field} must be negative` });\n\t\t}\n\t\tif (options?.isNonnegative) {\n\t\t\tschema = schema.nonnegative({ message: `${field} must be non-negative` });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a required string validation with a minimum length.\n\t * The string is also trimmed to remove leading/trailing whitespace.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @param minLength - Minimum required length (optional)\n\t * @param maxLength - Maximum required length (optional)\n\t * @param regex - Regular expression (optional)\n\t * @returns A Zod schema that validates strings with minimum length\n\t *\n\t * @example\n\t * ```typescript\n\t * const nameSchema = ZodValidation.String(\"Name\");\n\t * ```\n\t */\n\tstatic string(\n\t\tfield: string = 'Field',\n\t\toptions?: {\n\t\t\tminLength?: number;\n\t\t\tmaxLength?: number;\n\t\t\tminMessage?: string;\n\t\t\tmaxMessage?: string;\n\t\t\trequiredMessage?: string;\n\t\t\tregex?: { pattern: RegExp; message: string }; // Add regex option\n\t\t\tisTrimmed?: boolean;\n\t\t}\n\t) {\n\t\tlet schema = z.string({\n\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t});\n\n\t\tif (options?.minLength) {\n\t\t\tschema = schema.min(\n\t\t\t\toptions.minLength,\n\t\t\t\toptions.minMessage || `${field} must be at least ${options.minLength} characters`\n\t\t\t);\n\t\t}\n\n\t\tif (options?.maxLength) {\n\t\t\tschema = schema.max(\n\t\t\t\toptions.maxLength,\n\t\t\t\toptions.maxMessage || `${field} shouldn’t exceed ${options.maxLength} characters`\n\t\t\t);\n\t\t}\n\n\t\t// Check for regex pattern and add regex validation\n\t\tif (options?.regex) {\n\t\t\tschema = schema.regex(options.regex.pattern, options.regex.message);\n\t\t}\n\n\t\tif (options?.isTrimmed) {\n\t\t\treturn schema\n\t\t\t\t.transform(val => val?.trim())\n\t\t\t\t.refine(val => val?.length && val?.length > 0, {\n\t\t\t\t\tmessage: options?.requiredMessage || `${field} is required`,\n\t\t\t\t});\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates an email validation.\n\t * Validates that the string is a valid email address format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates email addresses\n\t *\n\t * @example\n\t * ```typescript\n\t * const emailSchema = ZodValidation.email(\"Please enter a valid email\");\n\t * ```\n\t */\n\tstatic email(\n\t\tfield: string = 'Email',\n\t\toptions?: {\n\t\t\trequiredMessage?: string;\n\t\t\tinvalidMessage?: string;\n\t\t}\n\t) {\n\t\tconst schema = z\n\t\t\t.string({\n\t\t\t\trequired_error: options?.requiredMessage || `${field} is required`,\n\t\t\t})\n\t\t\t.trim()\n\t\t\t.email(options?.invalidMessage || `${field} must be a valid email address`)\n\t\t\t.transform(value => value.toLowerCase());\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Creates a URL validation.\n\t * Validates that the string is a valid URL format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates URLs\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.url(\"Please enter a valid URL\");\n\t * ```\n\t */\n\tstatic url(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).url(`${field} must be a valid URL`);\n\t}\n\n\t/**\n\t * Creates a Password validation.\n\t * Validates that the string is a valid password format.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates password\n\t *\n\t * @example\n\t * ```typescript\n\t * const websiteSchema = ZodValidation.password(\"Please enter a valid password\");\n\t * ```\n\t */\n\tstatic password(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tval =>\n\t\t\t\t!val || // allow undefined or empty, but validate when provided\n\t\t\t\t(val.length >= 8 && // minimum length\n\t\t\t\t\t/[a-z]/.test(val) && // lowercase\n\t\t\t\t\t/[A-Z]/.test(val) && // uppercase\n\t\t\t\t\t/[0-9]/.test(val) && // number\n\t\t\t\t\t/[!@#$%^&*(),.?\":{}|<>]/.test(val)), // special char\n\t\t\t{\n\t\t\t\tmessage:\n\t\t\t\t\t'Password must include at least one uppercase letter, one lowercase letter, one number, one special character and minimum 8 character required',\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Creates a phone number validation schema using a regex pattern for global phone numbers.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates phone numbers\n\t *\n\t * @example\n\t * ```typescript\n\t * const phoneSchema = ZodValidation.phoneNumber(\"Phone number\");\n\t * ```\n\t */\n\n\tstatic phoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).refine(\n\t\t\tvalue => {\n\t\t\t\ttry {\n\t\t\t\t\tconst phone = parsePhoneNumberFromString(value);\n\t\t\t\t\treturn phone?.isValid();\n\t\t\t\t} catch {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t},\n\t\t\t{\n\t\t\t\tmessage: `Please enter a valid phone number`,\n\t\t\t}\n\t\t);\n\t}\n\n\tstatic validPhoneNumber(field: string = 'Field') {\n\t\treturn z.string({ required_error: `${field} is required` }).superRefine((phoneWithCountryCode, ctx) => {\n\t\t\tconst phoneWithoutCountryCode = phoneWithCountryCode.replace(/^\\+\\d{1,3}/, '');\n\t\t\tif (phoneWithoutCountryCode.length < 4) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `${field} must have 4 or more digits`,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (/^\\d{4}$|^\\d{5}$|^\\d{7}$|^\\d{8}$/.test(phoneWithoutCountryCode)) {\n\t\t\t\treturn; // ✅ Accept 4,5,7 or 8 digit short numbers\n\t\t\t}\n\t\t\t// Otherwise, parse as real phone number\n\t\t\tconst phone = parsePhoneNumberFromString(phoneWithCountryCode);\n\t\t\tif (!phone) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Invalid phone number format in ${field}`,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!phone.isValid()) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: `Please enter a valid phone number in ${field}`,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a date validation.\n\t * Validates that the input is a JavaScript Date object.\n\t *@param field - The name of the field to be included in the error message\n\t *@param minDate - Minimum required date (optional)\n\t *@param maxDate - Maximum required date (optional)\n\t * @returns A Zod schema that validates Date objects\n\t *\n\t * @example\n\t * ```typescript\n\t * const createdAtSchema = ZodValidation.date();\n\t * ```\n\t */\n\tstatic date(field: string = 'Field', minDate?: Date, maxDate?: Date) {\n\t\treturn z\n\t\t\t.union(\n\t\t\t\t[\n\t\t\t\t\tz\n\t\t\t\t\t\t.string({ required_error: `${field} is required` })\n\t\t\t\t\t\t.refine(val => {\n\t\t\t\t\t\t\tconst date = new Date(val);\n\t\t\t\t\t\t\treturn !isNaN(date.getTime());\n\t\t\t\t\t\t}, `${field} must be a valid date`)\n\t\t\t\t\t\t.transform(val => new Date(val)),\n\t\t\t\t\tz.date({\n\t\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t\t{ message: `${field} is required` }\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => minDate === undefined || val >= minDate,\n\t\t\t\t`${field} must be on or after ${minDate?.toISOString()}`\n\t\t\t)\n\t\t\t.refine(\n\t\t\t\tval => maxDate === undefined || val <= maxDate,\n\t\t\t\t`${field} must be on or before ${maxDate?.toISOString()}`\n\t\t\t);\n\t}\n\n\t/**\n\t * Creates a boolean validation with an optional default value.\n\t *\n\t * @param field - The name of the field to be included in the error message\n\t * @returns A Zod schema that validates booleans\n\t *\n\t * @example\n\t * ```typescript\n\t * const isActiveSchema = ZodValidation.boolean(true); // Defaults to true\n\t * ```\n\t */\n\tstatic boolean(field: string = 'Field') {\n\t\treturn z.boolean({\n\t\t\trequired_error: `${field} is required`,\n\t\t\tinvalid_type_error: `${field} must be a boolean`,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an array validation with optional minimum items constraint.\n\t *\n\t * @template T - Type of the schema for array items\n\t * @param schema - The schema for validating array items\n\t * @param field - The name of the field to be included in the error message\n\t * @param minItems - Minimum number of items required (optional)\n\t * @param maxItems - Maximum number of items required (optional)\n\t * @returns A Zod schema that validates arrays\n\t *\n\t * @example\n\t * ```typescript\n\t * const tagsSchema = ZodValidation.array(z.string(), \"At least one tag required\", 1);\n\t * ```\n\t */\n\tstatic array<T extends z.ZodTypeAny>(\n\t\tschema: T,\n\t\tfield: string = 'Array',\n\t\tminItems?: number,\n\t\tmaxItems?: number\n\t) {\n\t\tlet arraySchema = z.array(schema, {\n\t\t\trequired_error: `${field} is required`,\n\t\t});\n\n\t\tif (minItems === 1) {\n\t\t\tarraySchema = arraySchema.min(1, `${field} cannot be empty`);\n\t\t}\n\t\tif (minItems !== undefined && minItems !== 1) {\n\t\t\tarraySchema = arraySchema.min(minItems, `${field} must have at least ${minItems} items`);\n\t\t}\n\t\tif (maxItems !== undefined) {\n\t\t\tarraySchema = arraySchema.max(maxItems, `${field} must have at most ${maxItems} items`);\n\t\t}\n\n\t\treturn arraySchema;\n\t}\n\n\t/**\n\t * Standard timestamp fields for entities.\n\t * Includes createdAt, updatedAt, and deletedAt fields.\n\t *\n\t * @returns An object containing timestamp field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = z.object({\n\t * name: z.string(),\n\t * ...ZodValidation.timestamps()\n\t * });\n\t * ```\n\t */\n\tstatic timestamps() {\n\t\treturn {\n\t\t\tcreatedAt: z.date().nullable().optional(),\n\t\t\tupdatedAt: z.date().nullable().optional(),\n\t\t\tdeletedAt: z.date().nullable().optional(),\n\t\t};\n\t}\n\n\t/**\n\t * Common fields for tracking model metadata.\n\t * Includes timestamps and user tracking fields (createdBy, updatedBy, deletedBy).\n\t *\n\t * @returns An object containing tracking field schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const postSchema = z.object({\n\t * title: z.string(),\n\t * content: z.string(),\n\t * ...ZodValidation.trackingFields()\n\t * });\n\t * ```\n\t */\n\tstatic trackingFields() {\n\t\treturn {\n\t\t\tcreatedBy: ZodValidation.objectId().optional(),\n\t\t\tupdatedBy: ZodValidation.objectId().optional(),\n\t\t\tdeletedBy: ZodValidation.objectId().optional(),\n\t\t\t...ZodValidation.timestamps(),\n\t\t};\n\t}\n\n\t/**\n\t * Namespace for coercion-based Zod validators.\n\t * Provides schemas that automatically convert input types to the expected type.\n\t *\n\t * @example\n\t * ```typescript\n\t * const schema = z.object({\n\t * startDate: ZodValidation.coerce.date(\"Start Date\"),\n\t * age: ZodValidation.coerce.number(\"Age\", { min: 18 }),\n\t * isActive: ZodValidation.coerce.boolean(\"Active\"),\n\t * });\n\t * ```\n\t */\n\tstatic coerce = {\n\t\tnumber: (\n\t\t\tfield: string = 'Field',\n\t\t\toptions?: {\n\t\t\t\tmin?: number;\n\t\t\t\tmax?: number;\n\t\t\t\tisInt?: boolean;\n\t\t\t\tisPositive?: boolean;\n\t\t\t\tisNonpositive?: boolean;\n\t\t\t\tisNegative?: boolean;\n\t\t\t\tisNonnegative?: boolean;\n\t\t\t}\n\t\t) => {\n\t\t\tlet schema = z.coerce.number({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be a number`,\n\t\t\t});\n\n\t\t\tif (options?.min !== undefined) {\n\t\t\t\tschema = schema.gte(options.min, { message: `${field} must be at least ${options.min}` });\n\t\t\t}\n\t\t\tif (options?.max !== undefined) {\n\t\t\t\tschema = schema.lte(options.max, { message: `${field} must be at most ${options.max}` });\n\t\t\t}\n\t\t\tif (options?.isInt) schema = schema.int({ message: `${field} must be an integer` });\n\t\t\tif (options?.isPositive) schema = schema.positive({ message: `${field} must be positive` });\n\t\t\tif (options?.isNonpositive) schema = schema.nonpositive({ message: `${field} must be non-positive` });\n\t\t\tif (options?.isNegative) schema = schema.negative({ message: `${field} must be negative` });\n\t\t\tif (options?.isNonnegative) schema = schema.nonnegative({ message: `${field} must be non-negative` });\n\n\t\t\treturn schema;\n\t\t},\n\n\t\tdate: (field: string = 'Field', minDate?: Date, maxDate?: Date) => {\n\t\t\treturn z.coerce\n\t\t\t\t.date({\n\t\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\t\tinvalid_type_error: `${field} must be a valid date`,\n\t\t\t\t})\n\t\t\t\t.refine(val => minDate === undefined || val >= minDate, {\n\t\t\t\t\tmessage: `${field} must be on or after ${minDate?.toISOString()}`,\n\t\t\t\t})\n\t\t\t\t.refine(val => maxDate === undefined || val <= maxDate, {\n\t\t\t\t\tmessage: `${field} must be on or before ${maxDate?.toISOString()}`,\n\t\t\t\t});\n\t\t},\n\n\t\tboolean: (field: string = 'Field') => {\n\t\t\treturn z.coerce.boolean({\n\t\t\t\trequired_error: `${field} is required`,\n\t\t\t\tinvalid_type_error: `${field} must be true or false`,\n\t\t\t});\n\t\t},\n\t\tobjectId: (field: string = 'Field') =>\n\t\t\tz\n\t\t\t\t.custom<mongoose.Types.ObjectId>(\n\t\t\t\t\tval => {\n\t\t\t\t\t\tif (typeof val === 'string' && mongoose.Types.ObjectId.isValid(val)) return true;\n\t\t\t\t\t\tif (val instanceof mongoose.Types.ObjectId) return true;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t\t{ message: `${field} must be a valid ObjectId` }\n\t\t\t\t)\n\t\t\t\t.transform(val => (typeof val === 'string' ? new mongoose.Types.ObjectId(val) : val)),\n\t};\n}\n\n/**\n * Represents the common fields to exclude from update operations.\n * This is used to specify which fields should not be updateable.\n *\n * @example\n * ```typescript\n * const excludeFields: ExcludeFromUpdate = {\n * createdAt: true,\n * createdBy: true,\n * status: true // Prevent status from being updated\n * };\n * ```\n */\nexport type ExcludeFromUpdate = {\n\tcreatedAt?: true;\n\tupdatedAt?: true;\n\tdeletedAt?: true;\n\tcreatedBy?: true;\n\t_id?: true;\n} & Record<string, true>;\n\n/**\n * Schema builder for creating consistent CRUD schemas.\n * Provides utility methods to generate schemas for create, read, update, and delete operations.\n *\n * @template T - Type of the base schema shape\n *\n * @example\n * ```typescript\n * const userBuilder = new SchemaBuilder({\n * name: z.string(),\n * email: z.string().email()\n * });\n *\n * const schemas = userBuilder.getAllSchemas();\n * ```\n */\nexport class SchemaBuilder<T extends z.ZodRawShape> {\n\tprivate baseSchema: z.ZodObject<T>;\n\n\t/**\n\t * Create a new schema builder\n\t *\n\t * @param baseFields - The base fields for the schema\n\t * @param includeTimestamps - Whether to include timestamp fields (default: true)\n\t * @param includeTracking - Whether to include tracking fields (createdBy, etc.) (default: false)\n\t *\n\t * @example\n\t * ```typescript\n\t * const userFields = {\n\t * name: ZodValidation.requiredString(),\n\t * email: ZodValidation.email()\n\t * };\n\t *\n\t * // With timestamps\n\t * const builder1 = new SchemaBuilder(userFields);\n\t *\n\t * // Without timestamps\n\t * const builder2 = new SchemaBuilder(userFields, false);\n\t *\n\t * // With tracking fields\n\t * const builder3 = new SchemaBuilder(userFields, true, true);\n\t * ```\n\t */\n\tconstructor(\n\t\tbaseFields: T,\n\t\tprivate includeTimestamps: boolean = true,\n\t\tprivate includeTracking: boolean = false\n\t) {\n\t\tthis.baseSchema = this.createBaseSchema(baseFields);\n\t}\n\n\t/**\n\t * Creates the base schema with optional timestamps and tracking fields.\n\t */\n\tprivate createBaseSchema(baseFields: T) {\n\t\tconst additionalFields = this.includeTracking\n\t\t\t? ZodValidation.trackingFields()\n\t\t\t: this.includeTimestamps\n\t\t\t\t? ZodValidation.timestamps()\n\t\t\t\t: {};\n\n\t\treturn z.object({\n\t\t\t...baseFields,\n\t\t\t...additionalFields,\n\t\t});\n\t}\n\n\t/**\n\t * Gets the base validation schema without ID.\n\t * Used for creating new entities.\n\t *\n\t * @returns The base schema for creating new entities\n\t *\n\t * @example\n\t * ```typescript\n\t * const createUserSchema = userBuilder.getBaseSchema();\n\t * ```\n\t */\n\tgetBaseSchema() {\n\t\treturn this.baseSchema.strict();\n\t}\n\n\t/**\n\t * Gets the schema for entities with ID.\n\t * Used for representing complete entities with their ID.\n\t *\n\t * @returns The entity schema including ID\n\t *\n\t * @example\n\t * ```typescript\n\t * const userSchema = userBuilder.getEntitySchema();\n\t * ```\n\t */\n\tgetEntitySchema() {\n\t\treturn this.baseSchema\n\t\t\t.extend({\n\t\t\t\t_id: ZodValidation.objectId(),\n\t\t\t})\n\t\t\t.partial()\n\t\t\t.passthrough();\n\t}\n\n\t/**\n\t * Gets the schema for validating an entity ID.\n\t * Used for validating ID parameters in requests.\n\t *\n\t * @returns The ID validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const userIdSchema = userBuilder.getIdSchema();\n\t * ```\n\t */\n\tgetIdSchema() {\n\t\treturn ZodValidation.objectId();\n\t}\n\n\t/**\n\t * Gets the schema for updating an entity, excluding specified fields.\n\t * Creates a partial schema where all fields are optional, and removes\n\t * fields that should not be updatable.\n\t *\n\t * @param excludeFields - Fields to exclude from update operations\n\t * @returns The update schema with excluded fields removed\n\t *\n\t * @example\n\t * ```typescript\n\t * // Prevent updating createdAt and status\n\t * const updateUserSchema = userBuilder.getUpdateSchema({\n\t * createdAt: true,\n\t * status: true\n\t * });\n\t * ```\n\t */\n\tgetUpdateSchema(excludeFields: ExcludeFromUpdate = { createdAt: true, updatedAt: true }) {\n\t\tconst entitySchema = this.getEntitySchema();\n\n\t\t// Simple approach - just make everything optional\n\t\tif (Object.keys(excludeFields).length === 0) {\n\t\t\treturn entitySchema;\n\t\t}\n\n\t\t// For the type-safe approach, we need to create a new schema\n\t\t// without the excluded fields and then make it partial\n\n\t\t// Get all fields from the entity schema\n\t\tconst shape = entitySchema._def.shape();\n\n\t\t// Filter out the fields we want to exclude\n\t\tconst filteredShape: z.ZodRawShape = {};\n\t\tfor (const key in shape) {\n\t\t\tif (!excludeFields[key as keyof typeof excludeFields]) {\n\t\t\t\tfilteredShape[key] = shape[key];\n\t\t\t}\n\t\t}\n\n\t\t// Create a new schema with the filtered fields\n\t\treturn z.object(filteredShape).partial().strict();\n\t}\n\n\t/**\n\t * Gets the schema for validating a delete request.\n\t * Used for validating parameters in delete requests, including the entity ID and soft delete flag.\n\t *\n\t * @returns The delete validation schema\n\t *\n\t * @example\n\t * ```typescript\n\t * const deleteSchema = userBuilder.getDeleteSchema();\n\t * ```\n\t */\n\tgetDeleteSchema() {\n\t\treturn z.object({\n\t\t\t_id: ZodValidation.objectId('_id'),\n\t\t\tsoftDelete: ZodValidation.boolean('Soft Delete').default(true),\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update schema by optionally extending the base schema with additional fields\n\t * and optionally omitting specified fields.\n\t *\n\t * @param extendFields - Optional fields to add to the schema (e.g., `_id`, `softDelete`).\n\t * @param omitFields - Optional fields to omit from the base schema (e.g., `name`).\n\t * @returns A new Zod schema for updates.\n\t */\n\tupdateBaseSchema(extendFields?: z.ZodRawShape, omitFields?: string[]) {\n\t\tlet schema: z.ZodObject<any> = this.baseSchema;\n\n\t\tif (omitFields && omitFields.length > 0) {\n\t\t\tschema = schema.omit(omitFields.reduce((acc, key) => ({ ...acc, [key]: true }), {}));\n\t\t}\n\n\t\tif (extendFields) {\n\t\t\tschema = schema.extend({ _id: ZodValidation.objectId().optional(), ...extendFields });\n\t\t}\n\n\t\treturn schema;\n\t}\n\n\t/**\n\t * Gets all common schemas for an entity.\n\t * Returns base, entity, ID, and update schemas in a single object.\n\t *\n\t * @param excludeFromUpdate - Fields to exclude from update operations\n\t * @returns Object containing all schemas\n\t *\n\t * @example\n\t * ```typescript\n\t * const {\n\t * BaseSchema, // For creating\n\t * EntitySchema, // For reading\n\t * IdSchema, // For validating IDs\n\t * UpdateSchema // For updating\n\t * } = userBuilder.getAllSchemas();\n\t * ```\n\t */\n\tgetAllSchemas(excludeFromUpdate?: ExcludeFromUpdate) {\n\t\treturn {\n\t\t\tBaseSchema: this.getBaseSchema(),\n\t\t\tEntitySchema: this.getEntitySchema(),\n\t\t\tIdSchema: this.getIdSchema(),\n\t\t\tUpdateSchema: this.getUpdateSchema(excludeFromUpdate),\n\t\t\tDeleteSchema: this.getDeleteSchema(),\n\t\t};\n\t}\n}\n\n/**\n * Type helper for creating DTO types from creation schemas.\n * Used to derive the type for creating new entities.\n *\n * @template T - The schema type\n *\n * @example\n * ```typescript\n * type CreateUserDTO = DTO<typeof UserValidationSchema>;\n * ```\n */\nexport type DTO<T extends z.ZodType> = z.infer<T>;\n\n/**\n * Creates a schema builder for an entity.\n * Helper function to create a new SchemaBuilder instance.\n *\n * @template T - Type of the base schema shape\n * @param baseFields - Base fields for the entity\n * @param includeTimestamps - Whether to include timestamp fields (default: true)\n * @param includeTracking - Whether to include tracking fields (default: false)\n * @returns A new SchemaBuilder instance\n *\n * @example\n * ```typescript\n * const userFields = {\n * name: ZodValidation.requiredString(),\n * email: ZodValidation.email()\n * };\n *\n * const userSchemaBuilder = createSchemaBuilder(userFields);\n * const userSchemaBuilder = createSchemaBuilder(userFields, true, true); // With tracking\n * ```\n */\nexport type PaginatedResponse<T> = {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n\tdocuments: T[];\n};\n\nexport function createSchemaBuilder<T extends z.ZodRawShape>(\n\tbaseFields: T,\n\tincludeTimestamps: boolean = true,\n\tincludeTracking: boolean = false\n) {\n\treturn new SchemaBuilder(baseFields, includeTimestamps, includeTracking);\n}\n\n// Custom Pagination utilities\nexport interface CustomPaginatorOptions<T> {\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tquery?: any;\n\tselect?: any;\n\tpopulate?: string[] | any[];\n\t// Optional function to transform each document\n\ttransform?: (doc: T) => any;\n}\n\nexport interface CustomPaginatedResponse<T> {\n\tdocuments: T[];\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n}\n\nexport type LeanDocument<T> = Require_id<FlattenMaps<T>>;\n"]}
|