@lyxa.ai/core 1.1.50 → 1.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -1
- package/dist/libraries/mongo/models/user.model.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 +78 -2
- package/dist/types/utilities/validation/filter-schema.factory.d.ts +34 -0
- package/dist/types/utilities/validation/filter-schema.factory.js +38 -0
- package/dist/types/utilities/validation/filter-schema.factory.js.map +1 -0
- package/dist/types/utilities/validation/global-validation.d.ts +38 -14
- package/dist/types/utilities/validation/index.d.ts +1 -0
- package/dist/types/utilities/validation/index.js +3 -0
- package/dist/types/utilities/validation/index.js.map +1 -1
- package/dist/utilities/validation/common-validation.d.ts +78 -2
- package/dist/utilities/validation/filter-schema.factory.d.ts +34 -0
- package/dist/utilities/validation/filter-schema.factory.js +38 -0
- package/dist/utilities/validation/filter-schema.factory.js.map +1 -0
- package/dist/utilities/validation/global-validation.d.ts +38 -14
- package/dist/utilities/validation/index.d.ts +1 -0
- package/dist/utilities/validation/index.js +3 -0
- package/dist/utilities/validation/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;AAiCA,sCA0BC;AAED,8CA4FC;AAED,oCAEC;AA5JD,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,6CAAmE;AACnE,0FAAuF;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,gEAKyC;AACzC,wEAAmE;AACnE,iEAA4F;AAC5F,+CAAuE;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AM,IAAA,wBAAgB,EAAC,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;YAC/C,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACJ,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 { initEventBus, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { MapService, GoogleMapsService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport {\n\tFCMService,\n\tFCMServiceForRider,\n\tFCMServiceForShop,\n\tFCMServiceForUser,\n} from './libraries/firebase/fcmService';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\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\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\t// Setup logger\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\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 map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(googleMapsKey as string);\n\tconst mapServiceInstance = new MapService(googleMapService);\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\t// Setup fcm service\n\tconst firebaseService = getLibraries().getFirebaseService();\n\tconst fcmServiceInstance = new FCMService(firebaseService.superApp);\n\tconst fcmServiceInstanceForUser = new FCMService(firebaseService.userApp);\n\tconst fcmServiceInstanceForRider = new FCMService(firebaseService.riderApp);\n\tconst fcmServiceInstanceForShop = new FCMService(firebaseService.shopApp);\n\tContainer.set(FCMService, fcmServiceInstance);\n\tContainer.set(FCMServiceForUser, fcmServiceInstanceForUser);\n\tContainer.set(FCMServiceForRider, fcmServiceInstanceForRider);\n\tContainer.set(FCMServiceForShop, fcmServiceInstanceForShop);\n\n\tconsole.log('Initialized everything');\n\n\tawait initEventBus('amqps://adlvedna:oY_X4qH1AphtB83YNcf9DHMO3UVmX23s@dog.lmq.cloudamqp.com/adlvedna');\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 => {\n\t\t\treturn instance[methodName](payload);\n\t\t});\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;AAkCA,sCA0BC;AAED,8CA4FC;AAED,oCAEC;AA7JD,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,6CAAmE;AACnE,0FAAuF;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,gEAKyC;AACzC,wEAAmE;AACnE,iEAA4F;AAC5F,+CAAuE;AAIvE,6GAA4G;AAAnG,4IAAA,4BAA4B,OAAA;AACrC,2CAAyD;AAAhD,6GAAA,oBAAoB,OAAA;AAEtB,KAAK,UAAU,aAAa,CAAC,OAA8B;IACjE,IAAI,CAAC;QACJ,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEjC,YAAY,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QAE/E,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;YACnC,YAAY,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;YAChG,IAAI,OAAO,EAAE,YAAY,IAAI,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B,CAAC,CAAC;IAC9C,kBAAS,CAAC,GAAG,CAAC,8BAAiB,EAAE,yBAAyB,CAAC,CAAC;IAC5D,kBAAS,CAAC,GAAG,CAAC,+BAAkB,EAAE,0BAA0B,CAAC,CAAC;IAC9D,kBAAS,CAAC,GAAG,CAAC,8BAAiB,EAAE,yBAAyB,CAAC,CAAC;IAE5D,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAEtC,MAAM,IAAA,oBAAY,EAAC,kFAAkF,CAAC,CAAC;IACvG,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;YAC/C,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACJ,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 { initEventBus, subscribeToEvent } from './libraries/event';\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\nimport { MapService, GoogleMapsService } from './libraries/map';\nimport { CachedSettingsService } from './libraries/cache/settings';\nimport {\n\tFCMService,\n\tFCMServiceForRider,\n\tFCMServiceForShop,\n\tFCMServiceForUser,\n} from './libraries/firebase/fcmService';\nimport { BullMQService } from './libraries/bullmq/bull-mq-service';\nimport { BOBSecrets, BOBService, CashSettlementService } from './libraries/cash-settlement';\nimport { disconnectAllEntitiesFromInstance } from './libraries/socket';\nimport { createFilterSchema } from './utilities/validation/filter-schema.factory';\n\nexport { ConfigurationOptions } from './libraries/configuration';\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nexport { initGlobalConnection } from './libraries/mongo';\n\nexport async function bootstrapCore(options?: ConfigurationOptions) {\n\ttry {\n\t\tawait registerLibraries(options);\n\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\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\t// Setup logger\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\n\tContainer.set(LyxaLogger, loggerInstance);\n\n\t// Setup firebase\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\n\tContainer.set(FirebaseService, firebaseInstance);\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 map service\n\tconst googleMapsKey = await getLibraries().getSecretsService().getKey('GOOGLE_MAPS_API_KEY');\n\tconst googleMapService = new GoogleMapsService(googleMapsKey as string);\n\tconst mapServiceInstance = new MapService(googleMapService);\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\t// Setup fcm service\n\tconst firebaseService = getLibraries().getFirebaseService();\n\tconst fcmServiceInstance = new FCMService(firebaseService.superApp);\n\tconst fcmServiceInstanceForUser = new FCMService(firebaseService.userApp);\n\tconst fcmServiceInstanceForRider = new FCMService(firebaseService.riderApp);\n\tconst fcmServiceInstanceForShop = new FCMService(firebaseService.shopApp);\n\tContainer.set(FCMService, fcmServiceInstance);\n\tContainer.set(FCMServiceForUser, fcmServiceInstanceForUser);\n\tContainer.set(FCMServiceForRider, fcmServiceInstanceForRider);\n\tContainer.set(FCMServiceForShop, fcmServiceInstanceForShop);\n\n\tconsole.log('Initialized everything');\n\n\tawait initEventBus('amqps://adlvedna:oY_X4qH1AphtB83YNcf9DHMO3UVmX23s@dog.lmq.cloudamqp.com/adlvedna');\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 => {\n\t\t\treturn instance[methodName](payload);\n\t\t});\n\t}\n}\n\nexport function getLibraries(): LibraryManager {\n\treturn Container.get(LibraryManager);\n}"]}
|
|
@@ -32,7 +32,7 @@ export declare class User extends TimeStamps {
|
|
|
32
32
|
isPhoneVerified?: boolean;
|
|
33
33
|
onlineStatus?: OnlineStatus;
|
|
34
34
|
fcmTokens?: string[];
|
|
35
|
-
static updateWallet(this: ReturnModelType<typeof User>, userId: string, amount: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject
|
|
35
|
+
static updateWallet(this: ReturnModelType<typeof User>, userId: string, amount: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject> & Omit<User & {
|
|
36
36
|
_id: import("mongoose").Types.ObjectId;
|
|
37
37
|
} & {
|
|
38
38
|
__v: number;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -646,7 +646,7 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
646
646
|
totalPages: number;
|
|
647
647
|
} | undefined;
|
|
648
648
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
649
|
-
}>, any> extends infer T_1 ? { [k in keyof T_1]:
|
|
649
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
650
650
|
success: z.ZodBoolean;
|
|
651
651
|
message: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
652
652
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
@@ -684,7 +684,83 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
684
684
|
totalPages: number;
|
|
685
685
|
} | undefined;
|
|
686
686
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
687
|
-
}>
|
|
687
|
+
}>, any>[k]; } : never, z.baseObjectInputType<{
|
|
688
|
+
success: z.ZodBoolean;
|
|
689
|
+
message: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
690
|
+
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
691
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
692
|
+
page: z.ZodNumber;
|
|
693
|
+
size: z.ZodNumber;
|
|
694
|
+
totalElements: z.ZodNumber;
|
|
695
|
+
totalPages: z.ZodNumber;
|
|
696
|
+
}, "strip", z.ZodTypeAny, {
|
|
697
|
+
size: number;
|
|
698
|
+
page: number;
|
|
699
|
+
totalElements: number;
|
|
700
|
+
totalPages: number;
|
|
701
|
+
}, {
|
|
702
|
+
size: number;
|
|
703
|
+
page: number;
|
|
704
|
+
totalElements: number;
|
|
705
|
+
totalPages: number;
|
|
706
|
+
}>>;
|
|
707
|
+
documents: z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">;
|
|
708
|
+
}, "strip", z.ZodTypeAny, {
|
|
709
|
+
documents: T[];
|
|
710
|
+
metadata?: {
|
|
711
|
+
size: number;
|
|
712
|
+
page: number;
|
|
713
|
+
totalElements: number;
|
|
714
|
+
totalPages: number;
|
|
715
|
+
} | undefined;
|
|
716
|
+
}, {
|
|
717
|
+
documents: T[];
|
|
718
|
+
metadata?: {
|
|
719
|
+
size: number;
|
|
720
|
+
page: number;
|
|
721
|
+
totalElements: number;
|
|
722
|
+
totalPages: number;
|
|
723
|
+
} | undefined;
|
|
724
|
+
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
725
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{
|
|
726
|
+
success: z.ZodBoolean;
|
|
727
|
+
message: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
728
|
+
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
729
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
730
|
+
page: z.ZodNumber;
|
|
731
|
+
size: z.ZodNumber;
|
|
732
|
+
totalElements: z.ZodNumber;
|
|
733
|
+
totalPages: z.ZodNumber;
|
|
734
|
+
}, "strip", z.ZodTypeAny, {
|
|
735
|
+
size: number;
|
|
736
|
+
page: number;
|
|
737
|
+
totalElements: number;
|
|
738
|
+
totalPages: number;
|
|
739
|
+
}, {
|
|
740
|
+
size: number;
|
|
741
|
+
page: number;
|
|
742
|
+
totalElements: number;
|
|
743
|
+
totalPages: number;
|
|
744
|
+
}>>;
|
|
745
|
+
documents: z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">;
|
|
746
|
+
}, "strip", z.ZodTypeAny, {
|
|
747
|
+
documents: T[];
|
|
748
|
+
metadata?: {
|
|
749
|
+
size: number;
|
|
750
|
+
page: number;
|
|
751
|
+
totalElements: number;
|
|
752
|
+
totalPages: number;
|
|
753
|
+
} | undefined;
|
|
754
|
+
}, {
|
|
755
|
+
documents: T[];
|
|
756
|
+
metadata?: {
|
|
757
|
+
size: number;
|
|
758
|
+
page: number;
|
|
759
|
+
totalElements: number;
|
|
760
|
+
totalPages: number;
|
|
761
|
+
} | undefined;
|
|
762
|
+
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
763
|
+
}>[k_1]; } : never>;
|
|
688
764
|
export type PaginatedDTO<T> = {
|
|
689
765
|
metadata: DTO<typeof metadataSchema>;
|
|
690
766
|
documents: T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
|
|
3
|
+
export interface FilterSchemaConfig<TSelect extends ReadonlyNonEmptyArray<string>, TPopulate extends ReadonlyNonEmptyArray<string>, TSearch extends ReadonlyNonEmptyArray<string>> {
|
|
4
|
+
selectableFields: TSelect;
|
|
5
|
+
populatableFields: TPopulate;
|
|
6
|
+
searchableFields: TSearch;
|
|
7
|
+
maxSize?: number;
|
|
8
|
+
defaultSize?: number;
|
|
9
|
+
}
|
|
10
|
+
export type PopulateObject<TPopulate extends ReadonlyNonEmptyArray<string>, TSelect extends ReadonlyNonEmptyArray<string>> = {
|
|
11
|
+
path: TPopulate[number];
|
|
12
|
+
select?: Partial<Record<TSelect[number], 0 | 1>>;
|
|
13
|
+
match?: Record<string, any>;
|
|
14
|
+
options?: {
|
|
15
|
+
sort?: Record<string, 1 | -1>;
|
|
16
|
+
limit?: number;
|
|
17
|
+
skip?: number;
|
|
18
|
+
};
|
|
19
|
+
populate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];
|
|
20
|
+
};
|
|
21
|
+
export type FilterDTO<TSelect extends ReadonlyNonEmptyArray<string>, TPopulate extends ReadonlyNonEmptyArray<string>, TSearch extends ReadonlyNonEmptyArray<string>> = {
|
|
22
|
+
size?: number;
|
|
23
|
+
page?: number;
|
|
24
|
+
sort?: Record<string, 1 | -1>;
|
|
25
|
+
query?: Record<string, any>;
|
|
26
|
+
select?: Partial<Record<TSelect[number], 0 | 1>>;
|
|
27
|
+
populate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];
|
|
28
|
+
search?: {
|
|
29
|
+
searchKey: string;
|
|
30
|
+
searchFields?: TSearch[number][];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare function createFilterSchema<TSelect extends ReadonlyNonEmptyArray<string>, TPopulate extends ReadonlyNonEmptyArray<string>, TSearch extends ReadonlyNonEmptyArray<string>>(config: FilterSchemaConfig<TSelect, TPopulate, TSearch>): z.ZodType<FilterDTO<TSelect, TPopulate, TSearch>>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFilterSchema = createFilterSchema;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const sortSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.literal(1), zod_1.z.literal(-1)]));
|
|
6
|
+
const MongoQuerySchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
|
|
7
|
+
function createFilterSchema(config) {
|
|
8
|
+
const { selectableFields, populatableFields, searchableFields, maxSize = 100, defaultSize = 10 } = config;
|
|
9
|
+
const selectSchema = zod_1.z.record(zod_1.z.enum(selectableFields), zod_1.z.union([zod_1.z.literal(0), zod_1.z.literal(1)]));
|
|
10
|
+
const populateSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
11
|
+
path: zod_1.z.enum(populatableFields),
|
|
12
|
+
select: zod_1.z.record(zod_1.z.enum(selectableFields), zod_1.z.union([zod_1.z.literal(0), zod_1.z.literal(1)])).optional(),
|
|
13
|
+
match: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
14
|
+
options: zod_1.z
|
|
15
|
+
.object({
|
|
16
|
+
sort: sortSchema.optional(),
|
|
17
|
+
limit: zod_1.z.number().optional(),
|
|
18
|
+
skip: zod_1.z.number().optional(),
|
|
19
|
+
})
|
|
20
|
+
.optional(),
|
|
21
|
+
populate: zod_1.z.union([populateSchema, zod_1.z.array(populateSchema)]).optional(),
|
|
22
|
+
}));
|
|
23
|
+
const searchSchema = zod_1.z.object({
|
|
24
|
+
searchKey: zod_1.z.string(),
|
|
25
|
+
searchFields: zod_1.z.array(zod_1.z.enum(searchableFields)).optional(),
|
|
26
|
+
});
|
|
27
|
+
const schema = zod_1.z.object({
|
|
28
|
+
size: zod_1.z.number().min(1).max(maxSize).optional().default(defaultSize),
|
|
29
|
+
page: zod_1.z.number().min(1).optional().default(1),
|
|
30
|
+
sort: sortSchema.optional(),
|
|
31
|
+
query: MongoQuerySchema.optional(),
|
|
32
|
+
select: selectSchema.optional(),
|
|
33
|
+
populate: zod_1.z.union([populateSchema, zod_1.z.array(populateSchema)]).optional(),
|
|
34
|
+
search: searchSchema.optional(),
|
|
35
|
+
});
|
|
36
|
+
return schema;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=filter-schema.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-schema.factory.js","sourceRo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,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;QACvE,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE;KAC/B,CAAC,CAAC;IAEH,OAAO,MAA2D,CAAC;AACpE,CAAC","sourcesContent":["import { z } from 'zod';\n\nconst sortSchema = z.record(z.string(), z.union([z.literal(1), z.literal(-1)]));\nconst MongoQuerySchema = z.record(z.string(), z.any());\n\ntype ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];\n\nexport interface FilterSchemaConfig<\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSearch extends ReadonlyNonEmptyArray<string>,\n> {\n\tselectableFields: TSelect;\n\tpopulatableFields: TPopulate;\n\tsearchableFields: TSearch;\n\tmaxSize?: number;\n\tdefaultSize?: number;\n}\n\nexport type PopulateObject<\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n> = {\n\tpath: TPopulate[number];\n\tselect?: Partial<Record<TSelect[number], 0 | 1>>;\n\tmatch?: Record<string, any>;\n\toptions?: { sort?: Record<string, 1 | -1>; limit?: number; skip?: number };\n\tpopulate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];\n};\n\nexport type FilterDTO<\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSearch extends ReadonlyNonEmptyArray<string>,\n> = {\n\tsize?: number;\n\tpage?: number;\n\tsort?: Record<string, 1 | -1>;\n\tquery?: Record<string, any>;\n\tselect?: Partial<Record<TSelect[number], 0 | 1>>;\n\tpopulate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];\n\tsearch?: { searchKey: string; searchFields?: TSearch[number][] };\n};\n\nexport function createFilterSchema<\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSearch extends ReadonlyNonEmptyArray<string>,\n>(config: FilterSchemaConfig<TSelect, TPopulate, TSearch>) {\n\tconst { selectableFields, populatableFields, searchableFields, maxSize = 100, defaultSize = 10 } = config;\n\n\tconst selectSchema = z.record(z.enum(selectableFields), z.union([z.literal(0), z.literal(1)]));\n\n\tconst populateSchema: z.ZodType<PopulateObject<TPopulate, TSelect>> = z.lazy(\n\t\t() =>\n\t\t\tz.object({\n\t\t\t\tpath: z.enum(populatableFields),\n\t\t\t\tselect: z.record(z.enum(selectableFields), z.union([z.literal(0), z.literal(1)])).optional(),\n\t\t\t\tmatch: z.record(z.string(), z.any()).optional(),\n\t\t\t\toptions: z\n\t\t\t\t\t.object({\n\t\t\t\t\t\tsort: sortSchema.optional(),\n\t\t\t\t\t\tlimit: z.number().optional(),\n\t\t\t\t\t\tskip: z.number().optional(),\n\t\t\t\t\t})\n\t\t\t\t\t.optional(),\n\t\t\t\tpopulate: z.union([populateSchema, z.array(populateSchema)]).optional(),\n\t\t\t}) as z.ZodType<PopulateObject<TPopulate, TSelect>>\n\t);\n\n\tconst searchSchema = z.object({\n\t\tsearchKey: z.string(),\n\t\tsearchFields: z.array(z.enum(searchableFields)).optional(),\n\t});\n\n\tconst schema = z.object({\n\t\tsize: z.number().min(1).max(maxSize).optional().default(defaultSize),\n\t\tpage: z.number().min(1).optional().default(1),\n\t\tsort: sortSchema.optional(),\n\t\tquery: MongoQuerySchema.optional(),\n\t\tselect: selectSchema.optional(),\n\t\tpopulate: z.union([populateSchema, z.array(populateSchema)]).optional(),\n\t\tsearch: searchSchema.optional(),\n\t});\n\n\treturn schema as z.ZodType<FilterDTO<TSelect, TPopulate, TSearch>>;\n}\n\n/**\n * @Example\n *\n * const UserFilterSchema = createFilterSchema({\n * \tselectableFields: ['_id', 'name', 'email', 'role', 'createdAt', 'updatedAt'] as const,\n * \tpopulatableFields: ['organization', 'permissions', 'addresses'] as const,\n * \tsearchableFields: ['name', 'email', 'role'] as const,\n * });\n *\n * type UserFilterDTO = z.infer<typeof UserFilterSchema>;\n *\n * const correctFilter: UserFilterDTO = {\n * \tselect: { name: 1, email: 1 },\n * \tpopulate: [{ path: 'organization', select: { name: 1 } }],\n * \tsearch: { searchKey: 'john', searchFields: ['name', 'email'] },\n * \tpage: 1,\n * \tsize: 20,\n * };\n *\n * const wrongFilter: UserFilterDTO = {\n * \tselect: { name: 1, email: 1, password: 1 }, ❌ Password is not in selectableFields\n * \tpopulate: [{ path: 'shops', select: { name: 1 } }], ❌ Shops is not in populatableFields\n * \tsearch: { searchKey: 'john', searchFields: ['name', 'email', 'price'] }, ❌ Price is not in searchableFields\n * \tpage: 1,\n * \tsize: 20,\n * };\n */\n"]}
|
|
@@ -76,22 +76,34 @@ export declare class SchemaBuilder<T extends z.ZodRawShape> {
|
|
|
76
76
|
private baseSchema;
|
|
77
77
|
constructor(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean);
|
|
78
78
|
private createBaseSchema;
|
|
79
|
-
getBaseSchema(): z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]:
|
|
79
|
+
getBaseSchema(): z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>;
|
|
80
80
|
getEntitySchema(): z.ZodObject<z.objectUtil.extendShape<T, {
|
|
81
81
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
82
|
-
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<
|
|
82
|
+
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
83
83
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
84
|
-
}>
|
|
84
|
+
}>[k]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
85
85
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
86
|
-
}> extends infer
|
|
86
|
+
}> extends infer T_2 extends z.ZodRawShape ? { [k in keyof T_2]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
87
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
88
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
89
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
90
|
+
}> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
91
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
92
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">>;
|
|
87
93
|
getIdSchema(): z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
88
94
|
getUpdateSchema(excludeFields?: ExcludeFromUpdate): z.ZodObject<z.objectUtil.extendShape<T, {
|
|
89
95
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
90
|
-
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<
|
|
96
|
+
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
97
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
98
|
+
}>[k]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
99
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
100
|
+
}> extends infer T_2 extends z.ZodRawShape ? { [k in keyof T_2]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
101
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
102
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
91
103
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
92
|
-
}> extends infer
|
|
104
|
+
}> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
93
105
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
94
|
-
}>
|
|
106
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">> | z.ZodObject<{
|
|
95
107
|
[x: string]: z.ZodOptional<z.ZodTypeAny>;
|
|
96
108
|
}, "strict", z.ZodTypeAny, {
|
|
97
109
|
[x: string]: any;
|
|
@@ -114,22 +126,34 @@ export declare class SchemaBuilder<T extends z.ZodRawShape> {
|
|
|
114
126
|
[x: string]: any;
|
|
115
127
|
}>;
|
|
116
128
|
getAllSchemas(excludeFromUpdate?: ExcludeFromUpdate): {
|
|
117
|
-
BaseSchema: z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]:
|
|
129
|
+
BaseSchema: z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>;
|
|
118
130
|
EntitySchema: z.ZodObject<z.objectUtil.extendShape<T, {
|
|
119
131
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
120
|
-
}> extends infer T_3 extends z.ZodRawShape ? { [k_2 in keyof T_3]: z.ZodOptional<
|
|
132
|
+
}> extends infer T_3 extends z.ZodRawShape ? { [k_2 in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
121
133
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
122
|
-
}>
|
|
134
|
+
}>[k_2]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
123
135
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
124
|
-
}> extends infer
|
|
136
|
+
}> extends infer T_4 extends z.ZodRawShape ? { [k_2 in keyof T_4]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
137
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
138
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
139
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
140
|
+
}> extends infer T_5 extends z.ZodRawShape ? { [k_2 in keyof T_5]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
141
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
142
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">>;
|
|
125
143
|
IdSchema: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
126
144
|
UpdateSchema: z.ZodObject<z.objectUtil.extendShape<T, {
|
|
127
145
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
128
|
-
}> extends infer T_6 extends z.ZodRawShape ? { [k_2 in keyof T_6]: z.ZodOptional<
|
|
146
|
+
}> extends infer T_6 extends z.ZodRawShape ? { [k_2 in keyof T_6]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
147
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
148
|
+
}>[k_2]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
149
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
150
|
+
}> extends infer T_7 extends z.ZodRawShape ? { [k_2 in keyof T_7]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
151
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
152
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
129
153
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
130
|
-
}> extends infer
|
|
154
|
+
}> extends infer T_8 extends z.ZodRawShape ? { [k_2 in keyof T_8]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
131
155
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
132
|
-
}>
|
|
156
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">> | z.ZodObject<{
|
|
133
157
|
[x: string]: z.ZodOptional<z.ZodTypeAny>;
|
|
134
158
|
}, "strict", z.ZodTypeAny, {
|
|
135
159
|
[x: string]: any;
|
|
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createFilterSchema = void 0;
|
|
17
18
|
__exportStar(require("./common-validation"), exports);
|
|
18
19
|
__exportStar(require("./global-validation"), exports);
|
|
19
20
|
__exportStar(require("./validation-for-frontend"), exports);
|
|
21
|
+
var filter_schema_factory_1 = require("./filter-schema.factory");
|
|
22
|
+
Object.defineProperty(exports, "createFilterSchema", { enumerable: true, get: function () { return filter_schema_factory_1.createFilterSchema; } });
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/validation/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/validation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,sDAAoC;AACpC,4DAA0C;AAC1C,iEAAiG;AAAxF,2HAAA,kBAAkB,OAAA","sourcesContent":["export * from './common-validation';\nexport * from './global-validation';\nexport * from './validation-for-frontend';\nexport { createFilterSchema, FilterSchemaConfig, PopulateObject } from './filter-schema.factory';"]}
|
|
@@ -646,7 +646,7 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
646
646
|
totalPages: number;
|
|
647
647
|
} | undefined;
|
|
648
648
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
649
|
-
}>, any> extends infer T_1 ? { [k in keyof T_1]:
|
|
649
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
650
650
|
success: z.ZodBoolean;
|
|
651
651
|
message: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
652
652
|
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
@@ -684,7 +684,83 @@ export declare const createResponseSchema: <T>(schema: z.ZodSchema<T>) => z.ZodO
|
|
|
684
684
|
totalPages: number;
|
|
685
685
|
} | undefined;
|
|
686
686
|
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
687
|
-
}>
|
|
687
|
+
}>, any>[k]; } : never, z.baseObjectInputType<{
|
|
688
|
+
success: z.ZodBoolean;
|
|
689
|
+
message: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
690
|
+
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
691
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
692
|
+
page: z.ZodNumber;
|
|
693
|
+
size: z.ZodNumber;
|
|
694
|
+
totalElements: z.ZodNumber;
|
|
695
|
+
totalPages: z.ZodNumber;
|
|
696
|
+
}, "strip", z.ZodTypeAny, {
|
|
697
|
+
page: number;
|
|
698
|
+
size: number;
|
|
699
|
+
totalElements: number;
|
|
700
|
+
totalPages: number;
|
|
701
|
+
}, {
|
|
702
|
+
page: number;
|
|
703
|
+
size: number;
|
|
704
|
+
totalElements: number;
|
|
705
|
+
totalPages: number;
|
|
706
|
+
}>>;
|
|
707
|
+
documents: z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">;
|
|
708
|
+
}, "strip", z.ZodTypeAny, {
|
|
709
|
+
documents: T[];
|
|
710
|
+
metadata?: {
|
|
711
|
+
page: number;
|
|
712
|
+
size: number;
|
|
713
|
+
totalElements: number;
|
|
714
|
+
totalPages: number;
|
|
715
|
+
} | undefined;
|
|
716
|
+
}, {
|
|
717
|
+
documents: T[];
|
|
718
|
+
metadata?: {
|
|
719
|
+
page: number;
|
|
720
|
+
size: number;
|
|
721
|
+
totalElements: number;
|
|
722
|
+
totalPages: number;
|
|
723
|
+
} | undefined;
|
|
724
|
+
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
725
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{
|
|
726
|
+
success: z.ZodBoolean;
|
|
727
|
+
message: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
728
|
+
data: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
729
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
730
|
+
page: z.ZodNumber;
|
|
731
|
+
size: z.ZodNumber;
|
|
732
|
+
totalElements: z.ZodNumber;
|
|
733
|
+
totalPages: z.ZodNumber;
|
|
734
|
+
}, "strip", z.ZodTypeAny, {
|
|
735
|
+
page: number;
|
|
736
|
+
size: number;
|
|
737
|
+
totalElements: number;
|
|
738
|
+
totalPages: number;
|
|
739
|
+
}, {
|
|
740
|
+
page: number;
|
|
741
|
+
size: number;
|
|
742
|
+
totalElements: number;
|
|
743
|
+
totalPages: number;
|
|
744
|
+
}>>;
|
|
745
|
+
documents: z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">;
|
|
746
|
+
}, "strip", z.ZodTypeAny, {
|
|
747
|
+
documents: T[];
|
|
748
|
+
metadata?: {
|
|
749
|
+
page: number;
|
|
750
|
+
size: number;
|
|
751
|
+
totalElements: number;
|
|
752
|
+
totalPages: number;
|
|
753
|
+
} | undefined;
|
|
754
|
+
}, {
|
|
755
|
+
documents: T[];
|
|
756
|
+
metadata?: {
|
|
757
|
+
page: number;
|
|
758
|
+
size: number;
|
|
759
|
+
totalElements: number;
|
|
760
|
+
totalPages: number;
|
|
761
|
+
} | undefined;
|
|
762
|
+
}>, z.ZodType<T, z.ZodTypeDef, T>]>>;
|
|
763
|
+
}>[k_1]; } : never>;
|
|
688
764
|
export type PaginatedDTO<T> = {
|
|
689
765
|
metadata: DTO<typeof metadataSchema>;
|
|
690
766
|
documents: T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
|
|
3
|
+
export interface FilterSchemaConfig<TSelect extends ReadonlyNonEmptyArray<string>, TPopulate extends ReadonlyNonEmptyArray<string>, TSearch extends ReadonlyNonEmptyArray<string>> {
|
|
4
|
+
selectableFields: TSelect;
|
|
5
|
+
populatableFields: TPopulate;
|
|
6
|
+
searchableFields: TSearch;
|
|
7
|
+
maxSize?: number;
|
|
8
|
+
defaultSize?: number;
|
|
9
|
+
}
|
|
10
|
+
export type PopulateObject<TPopulate extends ReadonlyNonEmptyArray<string>, TSelect extends ReadonlyNonEmptyArray<string>> = {
|
|
11
|
+
path: TPopulate[number];
|
|
12
|
+
select?: Partial<Record<TSelect[number], 0 | 1>>;
|
|
13
|
+
match?: Record<string, any>;
|
|
14
|
+
options?: {
|
|
15
|
+
sort?: Record<string, 1 | -1>;
|
|
16
|
+
limit?: number;
|
|
17
|
+
skip?: number;
|
|
18
|
+
};
|
|
19
|
+
populate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];
|
|
20
|
+
};
|
|
21
|
+
export type FilterDTO<TSelect extends ReadonlyNonEmptyArray<string>, TPopulate extends ReadonlyNonEmptyArray<string>, TSearch extends ReadonlyNonEmptyArray<string>> = {
|
|
22
|
+
size?: number;
|
|
23
|
+
page?: number;
|
|
24
|
+
sort?: Record<string, 1 | -1>;
|
|
25
|
+
query?: Record<string, any>;
|
|
26
|
+
select?: Partial<Record<TSelect[number], 0 | 1>>;
|
|
27
|
+
populate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];
|
|
28
|
+
search?: {
|
|
29
|
+
searchKey: string;
|
|
30
|
+
searchFields?: TSearch[number][];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare function createFilterSchema<TSelect extends ReadonlyNonEmptyArray<string>, TPopulate extends ReadonlyNonEmptyArray<string>, TSearch extends ReadonlyNonEmptyArray<string>>(config: FilterSchemaConfig<TSelect, TPopulate, TSearch>): z.ZodType<FilterDTO<TSelect, TPopulate, TSearch>>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFilterSchema = createFilterSchema;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const sortSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.literal(1), zod_1.z.literal(-1)]));
|
|
6
|
+
const MongoQuerySchema = zod_1.z.record(zod_1.z.string(), zod_1.z.any());
|
|
7
|
+
function createFilterSchema(config) {
|
|
8
|
+
const { selectableFields, populatableFields, searchableFields, maxSize = 100, defaultSize = 10 } = config;
|
|
9
|
+
const selectSchema = zod_1.z.record(zod_1.z.enum(selectableFields), zod_1.z.union([zod_1.z.literal(0), zod_1.z.literal(1)]));
|
|
10
|
+
const populateSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
11
|
+
path: zod_1.z.enum(populatableFields),
|
|
12
|
+
select: zod_1.z.record(zod_1.z.enum(selectableFields), zod_1.z.union([zod_1.z.literal(0), zod_1.z.literal(1)])).optional(),
|
|
13
|
+
match: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
14
|
+
options: zod_1.z
|
|
15
|
+
.object({
|
|
16
|
+
sort: sortSchema.optional(),
|
|
17
|
+
limit: zod_1.z.number().optional(),
|
|
18
|
+
skip: zod_1.z.number().optional(),
|
|
19
|
+
})
|
|
20
|
+
.optional(),
|
|
21
|
+
populate: zod_1.z.union([populateSchema, zod_1.z.array(populateSchema)]).optional(),
|
|
22
|
+
}));
|
|
23
|
+
const searchSchema = zod_1.z.object({
|
|
24
|
+
searchKey: zod_1.z.string(),
|
|
25
|
+
searchFields: zod_1.z.array(zod_1.z.enum(searchableFields)).optional(),
|
|
26
|
+
});
|
|
27
|
+
const schema = zod_1.z.object({
|
|
28
|
+
size: zod_1.z.number().min(1).max(maxSize).optional().default(defaultSize),
|
|
29
|
+
page: zod_1.z.number().min(1).optional().default(1),
|
|
30
|
+
sort: sortSchema.optional(),
|
|
31
|
+
query: MongoQuerySchema.optional(),
|
|
32
|
+
select: selectSchema.optional(),
|
|
33
|
+
populate: zod_1.z.union([populateSchema, zod_1.z.array(populateSchema)]).optional(),
|
|
34
|
+
search: searchSchema.optional(),
|
|
35
|
+
});
|
|
36
|
+
return schema;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=filter-schema.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-schema.factory.js","sourceRoot":"/","sources":["utilities/validation/filter-schema.factory.ts"],"names":[],"mappings":";;AA4CA,gDA0CC;AAtFD,6BAAwB;AAExB,MAAM,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,CAAC,CAAC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EmptyArray<T> = readonly [T, ...T[]];\n\nexport interface FilterSchemaConfig<\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSearch extends ReadonlyNonEmptyArray<string>,\n> {\n\tselectableFields: TSelect;\n\tpopulatableFields: TPopulate;\n\tsearchableFields: TSearch;\n\tmaxSize?: number;\n\tdefaultSize?: number;\n}\n\nexport type PopulateObject<\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n> = {\n\tpath: TPopulate[number];\n\tselect?: Partial<Record<TSelect[number], 0 | 1>>;\n\tmatch?: Record<string, any>;\n\toptions?: { sort?: Record<string, 1 | -1>; limit?: number; skip?: number };\n\tpopulate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];\n};\n\nexport type FilterDTO<\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSearch extends ReadonlyNonEmptyArray<string>,\n> = {\n\tsize?: number;\n\tpage?: number;\n\tsort?: Record<string, 1 | -1>;\n\tquery?: Record<string, any>;\n\tselect?: Partial<Record<TSelect[number], 0 | 1>>;\n\tpopulate?: PopulateObject<TPopulate, TSelect> | PopulateObject<TPopulate, TSelect>[];\n\tsearch?: { searchKey: string; searchFields?: TSearch[number][] };\n};\n\nexport function createFilterSchema<\n\tTSelect extends ReadonlyNonEmptyArray<string>,\n\tTPopulate extends ReadonlyNonEmptyArray<string>,\n\tTSearch extends ReadonlyNonEmptyArray<string>,\n>(config: FilterSchemaConfig<TSelect, TPopulate, TSearch>) {\n\tconst { selectableFields, populatableFields, searchableFields, maxSize = 100, defaultSize = 10 } = config;\n\n\tconst selectSchema = z.record(z.enum(selectableFields), z.union([z.literal(0), z.literal(1)]));\n\n\tconst populateSchema: z.ZodType<PopulateObject<TPopulate, TSelect>> = z.lazy(\n\t\t() =>\n\t\t\tz.object({\n\t\t\t\tpath: z.enum(populatableFields),\n\t\t\t\tselect: z.record(z.enum(selectableFields), z.union([z.literal(0), z.literal(1)])).optional(),\n\t\t\t\tmatch: z.record(z.string(), z.any()).optional(),\n\t\t\t\toptions: z\n\t\t\t\t\t.object({\n\t\t\t\t\t\tsort: sortSchema.optional(),\n\t\t\t\t\t\tlimit: z.number().optional(),\n\t\t\t\t\t\tskip: z.number().optional(),\n\t\t\t\t\t})\n\t\t\t\t\t.optional(),\n\t\t\t\tpopulate: z.union([populateSchema, z.array(populateSchema)]).optional(),\n\t\t\t}) as z.ZodType<PopulateObject<TPopulate, TSelect>>\n\t);\n\n\tconst searchSchema = z.object({\n\t\tsearchKey: z.string(),\n\t\tsearchFields: z.array(z.enum(searchableFields)).optional(),\n\t});\n\n\tconst schema = z.object({\n\t\tsize: z.number().min(1).max(maxSize).optional().default(defaultSize),\n\t\tpage: z.number().min(1).optional().default(1),\n\t\tsort: sortSchema.optional(),\n\t\tquery: MongoQuerySchema.optional(),\n\t\tselect: selectSchema.optional(),\n\t\tpopulate: z.union([populateSchema, z.array(populateSchema)]).optional(),\n\t\tsearch: searchSchema.optional(),\n\t});\n\n\treturn schema as z.ZodType<FilterDTO<TSelect, TPopulate, TSearch>>;\n}\n\n/**\n * @Example\n *\n * const UserFilterSchema = createFilterSchema({\n * \tselectableFields: ['_id', 'name', 'email', 'role', 'createdAt', 'updatedAt'] as const,\n * \tpopulatableFields: ['organization', 'permissions', 'addresses'] as const,\n * \tsearchableFields: ['name', 'email', 'role'] as const,\n * });\n *\n * type UserFilterDTO = z.infer<typeof UserFilterSchema>;\n *\n * const correctFilter: UserFilterDTO = {\n * \tselect: { name: 1, email: 1 },\n * \tpopulate: [{ path: 'organization', select: { name: 1 } }],\n * \tsearch: { searchKey: 'john', searchFields: ['name', 'email'] },\n * \tpage: 1,\n * \tsize: 20,\n * };\n *\n * const wrongFilter: UserFilterDTO = {\n * \tselect: { name: 1, email: 1, password: 1 }, ❌ Password is not in selectableFields\n * \tpopulate: [{ path: 'shops', select: { name: 1 } }], ❌ Shops is not in populatableFields\n * \tsearch: { searchKey: 'john', searchFields: ['name', 'email', 'price'] }, ❌ Price is not in searchableFields\n * \tpage: 1,\n * \tsize: 20,\n * };\n */\n"]}
|
|
@@ -76,22 +76,34 @@ export declare class SchemaBuilder<T extends z.ZodRawShape> {
|
|
|
76
76
|
private baseSchema;
|
|
77
77
|
constructor(baseFields: T, includeTimestamps?: boolean, includeTracking?: boolean);
|
|
78
78
|
private createBaseSchema;
|
|
79
|
-
getBaseSchema(): z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]:
|
|
79
|
+
getBaseSchema(): z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>;
|
|
80
80
|
getEntitySchema(): z.ZodObject<z.objectUtil.extendShape<T, {
|
|
81
81
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
82
|
-
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<
|
|
82
|
+
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
83
83
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
84
|
-
}>
|
|
84
|
+
}>[k]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
85
85
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
86
|
-
}> extends infer
|
|
86
|
+
}> extends infer T_2 extends z.ZodRawShape ? { [k in keyof T_2]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
87
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
88
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
89
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
90
|
+
}> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
91
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
92
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">>;
|
|
87
93
|
getIdSchema(): z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
88
94
|
getUpdateSchema(excludeFields?: ExcludeFromUpdate): z.ZodObject<z.objectUtil.extendShape<T, {
|
|
89
95
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
90
|
-
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<
|
|
96
|
+
}> extends infer T_1 extends z.ZodRawShape ? { [k in keyof T_1]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
97
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
98
|
+
}>[k]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
99
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
100
|
+
}> extends infer T_2 extends z.ZodRawShape ? { [k in keyof T_2]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
101
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
102
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
91
103
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
92
|
-
}> extends infer
|
|
104
|
+
}> extends infer T_3 extends z.ZodRawShape ? { [k in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
93
105
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
94
|
-
}>
|
|
106
|
+
}>[k]>; } : never, z.ZodTypeAny, "passthrough">> | z.ZodObject<{
|
|
95
107
|
[x: string]: z.ZodOptional<z.ZodTypeAny>;
|
|
96
108
|
}, "strict", z.ZodTypeAny, {
|
|
97
109
|
[x: string]: any;
|
|
@@ -114,22 +126,34 @@ export declare class SchemaBuilder<T extends z.ZodRawShape> {
|
|
|
114
126
|
[x: string]: any;
|
|
115
127
|
}>;
|
|
116
128
|
getAllSchemas(excludeFromUpdate?: ExcludeFromUpdate): {
|
|
117
|
-
BaseSchema: z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]:
|
|
129
|
+
BaseSchema: z.ZodObject<T, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>;
|
|
118
130
|
EntitySchema: z.ZodObject<z.objectUtil.extendShape<T, {
|
|
119
131
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
120
|
-
}> extends infer T_3 extends z.ZodRawShape ? { [k_2 in keyof T_3]: z.ZodOptional<
|
|
132
|
+
}> extends infer T_3 extends z.ZodRawShape ? { [k_2 in keyof T_3]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
121
133
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
122
|
-
}>
|
|
134
|
+
}>[k_2]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
123
135
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
124
|
-
}> extends infer
|
|
136
|
+
}> extends infer T_4 extends z.ZodRawShape ? { [k_2 in keyof T_4]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
137
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
138
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
139
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
140
|
+
}> extends infer T_5 extends z.ZodRawShape ? { [k_2 in keyof T_5]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
141
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
142
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">>;
|
|
125
143
|
IdSchema: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
126
144
|
UpdateSchema: z.ZodObject<z.objectUtil.extendShape<T, {
|
|
127
145
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
128
|
-
}> extends infer T_6 extends z.ZodRawShape ? { [k_2 in keyof T_6]: z.ZodOptional<
|
|
146
|
+
}> extends infer T_6 extends z.ZodRawShape ? { [k_2 in keyof T_6]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
147
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
148
|
+
}>[k_2]>; } : never, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<T, {
|
|
149
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
150
|
+
}> extends infer T_7 extends z.ZodRawShape ? { [k_2 in keyof T_7]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
151
|
+
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
152
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<T, {
|
|
129
153
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
130
|
-
}> extends infer
|
|
154
|
+
}> extends infer T_8 extends z.ZodRawShape ? { [k_2 in keyof T_8]: z.ZodOptional<z.objectUtil.extendShape<T, {
|
|
131
155
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, mongoose.Types.ObjectId, string>, z.ZodType<mongoose.Types.ObjectId, z.ZodTypeDef, mongoose.Types.ObjectId>]>;
|
|
132
|
-
}>
|
|
156
|
+
}>[k_2]>; } : never, z.ZodTypeAny, "passthrough">> | z.ZodObject<{
|
|
133
157
|
[x: string]: z.ZodOptional<z.ZodTypeAny>;
|
|
134
158
|
}, "strict", z.ZodTypeAny, {
|
|
135
159
|
[x: string]: any;
|
|
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createFilterSchema = void 0;
|
|
17
18
|
__exportStar(require("./common-validation"), exports);
|
|
18
19
|
__exportStar(require("./global-validation"), exports);
|
|
19
20
|
__exportStar(require("./validation-for-frontend"), exports);
|
|
21
|
+
var filter_schema_factory_1 = require("./filter-schema.factory");
|
|
22
|
+
Object.defineProperty(exports, "createFilterSchema", { enumerable: true, get: function () { return filter_schema_factory_1.createFilterSchema; } });
|
|
20
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/validation/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/validation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,sDAAoC;AACpC,4DAA0C;AAC1C,iEAAiG;AAAxF,2HAAA,kBAAkB,OAAA","sourcesContent":["export * from './common-validation';\nexport * from './global-validation';\nexport * from './validation-for-frontend';\nexport { createFilterSchema, FilterSchemaConfig, PopulateObject } from './filter-schema.factory';"]}
|