@lyxa.ai/core 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/libraries/logger/index.d.ts +2 -0
  3. package/dist/libraries/logger/index.js +17 -1
  4. package/dist/libraries/logger/index.js.map +1 -1
  5. package/dist/libraries/mongo/index.js +49 -16
  6. package/dist/libraries/mongo/index.js.map +1 -1
  7. package/dist/libraries/mongo/models/cart.model.js +9 -2
  8. package/dist/libraries/mongo/models/cart.model.js.map +1 -1
  9. package/dist/libraries/mongo/models/embedded/price-breakdown.model.d.ts +5 -0
  10. package/dist/libraries/mongo/models/embedded/price-breakdown.model.js +32 -0
  11. package/dist/libraries/mongo/models/embedded/price-breakdown.model.js.map +1 -0
  12. package/dist/libraries/mongo/models/index.d.ts +24 -3
  13. package/dist/libraries/mongo/models/index.js +26 -5
  14. package/dist/libraries/mongo/models/index.js.map +1 -1
  15. package/dist/libraries/mongo/models/line-item.model.d.ts +4 -4
  16. package/dist/libraries/mongo/models/line-item.model.js +8 -8
  17. package/dist/libraries/mongo/models/line-item.model.js.map +1 -1
  18. package/dist/libraries/mongo/models/product.model.d.ts +24 -7
  19. package/dist/libraries/mongo/models/product.model.js +84 -19
  20. package/dist/libraries/mongo/models/product.model.js.map +1 -1
  21. package/dist/libraries/mongo/models/shared/work-hour.model.js +1 -1
  22. package/dist/libraries/mongo/models/shared/work-hour.model.js.map +1 -1
  23. package/dist/libraries/mongo/models/shop-access-control.model.js +10 -6
  24. package/dist/libraries/mongo/models/shop-access-control.model.js.map +1 -1
  25. package/dist/libraries/mongo/models/shop-product.model.d.ts +4 -4
  26. package/dist/libraries/mongo/models/shop-product.model.js +7 -7
  27. package/dist/libraries/mongo/models/shop-product.model.js.map +1 -1
  28. package/dist/libraries/mongo/models/shop.model.js.map +1 -1
  29. package/dist/libraries/trpc/index.d.ts +99 -9
  30. package/dist/libraries/trpc/index.js +22 -1
  31. package/dist/libraries/trpc/index.js.map +1 -1
  32. package/dist/libraries/trpc/middlewares/auth.d.ts +11 -1
  33. package/dist/utilities/common/password.d.ts +1 -0
  34. package/dist/utilities/common/password.js +12 -0
  35. package/dist/utilities/common/password.js.map +1 -0
  36. package/dist/utilities/common/week.d.ts +1 -0
  37. package/dist/utilities/common/week.js +5 -0
  38. package/dist/utilities/common/week.js.map +1 -0
  39. package/dist/utilities/enum.d.ts +9 -6
  40. package/dist/utilities/enum.js +21 -17
  41. package/dist/utilities/enum.js.map +1 -1
  42. package/dist/utilities/error-handler.js +20 -5
  43. package/dist/utilities/error-handler.js.map +1 -1
  44. package/dist/utilities/transformers.js.map +1 -1
  45. package/dist/utilities/validation/common-validation.d.ts +110 -110
  46. package/dist/utilities/validation/common-validation.js +5 -2
  47. package/dist/utilities/validation/common-validation.js.map +1 -1
  48. package/dist/utilities/validation/global-validation.d.ts +19 -5
  49. package/dist/utilities/validation/global-validation.js +34 -14
  50. package/dist/utilities/validation/global-validation.js.map +1 -1
  51. 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":";;;;;;AAoBA,sCAyBC;AAED,8CAyDC;AAED,oCAEC;AA5GD,2CAA6C;AAC7C,mCAAmC;AACnC,wDAAgC;AAChC,6DAAuF;AACvF,+GAA4G;AAC5G,+CAAgD;AAChD,6CAAiD;AACjD,6CAAyD;AACzD,iDAA2D;AAC3D,uDAAgE;AAChE,+CAAmD;AACnD,mDAAuD;AACvD,6CAAmE;AACnE,0FAAuF;AAIvF,6GAA4G;AAAnG,4IAAA,4BAA4B,OAAA;AACrC,2CAA4G;AAAnG,6GAAA,oBAAoB,OAAA;AAAE,0GAAA,iBAAiB,OAAA;AAAE,uHAAA,8BAA8B,OAAA;AAEzE,KAAK,UAAU,aAAa,CAAC,OAA8B;IACjE,IAAI,CAAC;QACJ,MAAM,iBAAiB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C,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":["import { LibraryManager } from './libraries';\r\nimport { Container } from 'typedi';\r\nimport mongoose from 'mongoose';\r\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\r\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\r\nimport { LyxaLogger } from './libraries/logger';\r\nimport { RedisService } from './libraries/redis';\r\nimport { initGlobalConnection } from './libraries/mongo';\r\nimport { SecretManagerService } from './libraries/secrets';\r\nimport { MicroServiceDispatcher } from './libraries/dispatcher';\r\nimport { TwilioService } from './libraries/twilio';\r\nimport { FirebaseService } from './libraries/firebase';\r\nimport { initEventBus, subscribeToEvent } from './libraries/event';\r\nimport { SubscriptionRegistry } from './libraries/event/registry/SubscriptionRegistry';\r\nimport { AuthEntityType, signTokenPair } from './libraries/auth';\r\n\r\nexport { ConfigurationOptions } from './libraries/configuration';\r\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\r\nexport { initGlobalConnection, createGlobalModel, createGlobalDiscriminatorModel } from './libraries/mongo';\r\n\r\nexport async function bootstrapCore(options?: ConfigurationOptions) {\r\n\ttry {\r\n\t\tawait registerLibraries(options);\r\n\r\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\r\n\r\n\t\tconst gracefulShutdown = async () => {\r\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\r\n\t\t\tprocess.exit()\r\n\t\t};\r\n\r\n\t\tprocess.on('SIGTERM', gracefulShutdown);\r\n\t\tprocess.on('SIGINT', gracefulShutdown);\r\n\t\tprocess.on('uncaughtException', err => {\r\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\r\n\t\t\tgracefulShutdown();\r\n\t\t});\r\n\t\tprocess.on('exit', (code) => {\r\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\r\n\t\t});\r\n\r\n\t\tconsole.log('Created hooks.');\r\n\t} catch (e) {\r\n\t\tconsole.error(e);\r\n\t}\r\n}\r\n\r\nexport async function registerLibraries(options?: ConfigurationOptions) {\r\n\t// Setup configuration.\r\n\tconst configurationInstance = new ConfigurationService(options);\r\n\tContainer.set(ConfigurationService, configurationInstance);\r\n\r\n\t// Setup redis.\r\n\tconst redisInstance = new RedisService(configurationInstance.options.redisURL!);\r\n\tContainer.set(RedisService, redisInstance);\r\n\r\n\t// Setup secret\r\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\r\n\tContainer.set(SecretManagerService, secretInstance);\r\n\r\n\tconst mongoUrl = await getLibraries().getSecretsService().getKey('MONGO_URL');\r\n\r\n\tawait mongoose.connect(mongoUrl!, { dbName: `lyxa-${options!.environment}-${options!.tenet}` });\r\n\tmongoose.set(\r\n\t\t'debug',\r\n\t\tgetLibraries().getConfigurationService().options.environment == EnvironmentConfigurationType.DEV\r\n\t);\r\n\r\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\r\n\r\n\t// Setup logger\r\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\r\n\tContainer.set(LyxaLogger, loggerInstance);\r\n\r\n\t// Setup firebase\r\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\r\n\tContainer.set(FirebaseService, firebaseInstance);\r\n\r\n\t// Setup microservice dispatcher\r\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\r\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\r\n\r\n\t// Setup twilio\r\n\tconst twilioServiceInstance = new TwilioService();\r\n\tContainer.set(TwilioService, twilioServiceInstance);\r\n\r\n\tconsole.log('Initialized everything');\r\n\r\n\tawait initEventBus('amqps://vgyuplrd:wto6vUYnb4zeBI5lntKT4gj7rT8n1vwg@dog.lmq.cloudamqp.com/vgyuplrd');\r\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\r\n\r\n\tconst instantiatedServices = new Map<Function, any>();\r\n\r\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\r\n\t\tlet instance = instantiatedServices.get(targetConstructor);\r\n\t\tif (!instance) {\r\n\t\t\tinstance = Container.get(targetConstructor as any);\r\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\r\n\t\t}\r\n\r\n\t\tawait subscribeToEvent(eventId, async payload => {\r\n\t\t\treturn instance[methodName](payload);\r\n\t\t});\r\n\t}\r\n}\r\n\r\nexport function getLibraries(): LibraryManager {\r\n\treturn Container.get(LibraryManager);\r\n}\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;AAmBA,sCAyBC;AAED,8CAyDC;AAED,oCAEC;AA3GD,2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AAC","sourcesContent":["import {LibraryManager} from './libraries';\r\nimport {Container} from 'typedi';\r\nimport mongoose from 'mongoose';\r\nimport {ConfigurationOptions, ConfigurationService} from './libraries/configuration';\r\nimport {EnvironmentConfigurationType} from './libraries/configuration/types/EnvironmentConfigurationType';\r\nimport {LyxaLogger} from './libraries/logger';\r\nimport {RedisService} from './libraries/redis';\r\nimport {initGlobalConnection} from './libraries/mongo';\r\nimport {SecretManagerService} from './libraries/secrets';\r\nimport {MicroServiceDispatcher} from './libraries/dispatcher';\r\nimport {TwilioService} from './libraries/twilio';\r\nimport {FirebaseService} from './libraries/firebase';\r\nimport {initEventBus, subscribeToEvent} from './libraries/event';\r\nimport {SubscriptionRegistry} from './libraries/event/registry/SubscriptionRegistry';\r\n\r\nexport { ConfigurationOptions } from './libraries/configuration';\r\nexport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\r\nexport { initGlobalConnection, createGlobalModel, createGlobalDiscriminatorModel } from './libraries/mongo';\r\n\r\nexport async function bootstrapCore(options?: ConfigurationOptions) {\r\n\ttry {\r\n\t\tawait registerLibraries(options);\r\n\r\n\t\tgetLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');\r\n\r\n\t\tconst gracefulShutdown = async () => {\r\n\t\t\tgetLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');\r\n\t\t\tprocess.exit()\r\n\t\t};\r\n\r\n\t\tprocess.on('SIGTERM', gracefulShutdown);\r\n\t\tprocess.on('SIGINT', gracefulShutdown);\r\n\t\tprocess.on('uncaughtException', err => {\r\n\t\t\tgetLibraries().getLogger().logger.error('Uncaught exception, shutting down...', err);\r\n\t\t\tgracefulShutdown();\r\n\t\t});\r\n\t\tprocess.on('exit', (code) => {\r\n\t\t\tgetLibraries().getLogger().logger.info(`Exiting with code: ${code}`);\r\n\t\t});\r\n\r\n\t\tconsole.log('Created hooks.');\r\n\t} catch (e) {\r\n\t\tconsole.error(e);\r\n\t}\r\n}\r\n\r\nexport async function registerLibraries(options?: ConfigurationOptions) {\r\n\t// Setup configuration.\r\n\tconst configurationInstance = new ConfigurationService(options);\r\n\tContainer.set(ConfigurationService, configurationInstance);\r\n\r\n\t// Setup redis.\r\n\tconst redisInstance = new RedisService(configurationInstance.options.redisURL!);\r\n\tContainer.set(RedisService, redisInstance);\r\n\r\n\t// Setup secret\r\n\tconst secretInstance = new SecretManagerService(configurationInstance, redisInstance);\r\n\tContainer.set(SecretManagerService, secretInstance);\r\n\r\n\tconst mongoUrl = await getLibraries().getSecretsService().getKey('MONGO_URL');\r\n\r\n\tawait mongoose.connect(mongoUrl!, { dbName: `lyxa-${options!.environment}-${options!.tenet}` });\r\n\tmongoose.set(\r\n\t\t'debug',\r\n\t\tgetLibraries().getConfigurationService().options.environment == EnvironmentConfigurationType.DEV\r\n\t);\r\n\r\n\tawait initGlobalConnection(mongoUrl!, options!.environment);\r\n\r\n\t// Setup logger\r\n\tconst loggerInstance = new LyxaLogger(options!.instanceType!, mongoUrl!);\r\n\tContainer.set(LyxaLogger, loggerInstance);\r\n\r\n\t// Setup firebase\r\n\tconst firebaseInstance = new FirebaseService(configurationInstance!);\r\n\tContainer.set(FirebaseService, firebaseInstance);\r\n\r\n\t// Setup microservice dispatcher\r\n\tconst microserviceDispatcherInstance = new MicroServiceDispatcher(secretInstance);\r\n\tContainer.set(MicroServiceDispatcher, microserviceDispatcherInstance);\r\n\r\n\t// Setup twilio\r\n\tconst twilioServiceInstance = new TwilioService();\r\n\tContainer.set(TwilioService, twilioServiceInstance);\r\n\r\n\tconsole.log('Initialized everything');\r\n\r\n\tawait initEventBus('amqps://vgyuplrd:wto6vUYnb4zeBI5lntKT4gj7rT8n1vwg@dog.lmq.cloudamqp.com/vgyuplrd');\r\n\tconst allSubscriptions = SubscriptionRegistry.getAllSubscriptions();\r\n\r\n\tconst instantiatedServices = new Map<Function, any>();\r\n\r\n\tfor (const { eventId, targetConstructor, methodName } of allSubscriptions) {\r\n\t\tlet instance = instantiatedServices.get(targetConstructor);\r\n\t\tif (!instance) {\r\n\t\t\tinstance = Container.get(targetConstructor as any);\r\n\t\t\tinstantiatedServices.set(targetConstructor, instance);\r\n\t\t}\r\n\r\n\t\tawait subscribeToEvent(eventId, async payload => {\r\n\t\t\treturn instance[methodName](payload);\r\n\t\t});\r\n\t}\r\n}\r\n\r\nexport function getLibraries(): LibraryManager {\r\n\treturn Container.get(LibraryManager);\r\n}\r\n"]}
@@ -1,6 +1,8 @@
1
1
  import { Logger } from 'pino';
2
2
  export declare class LyxaLogger {
3
3
  private readonly _logger;
4
+ private readonly logDirectory;
4
5
  constructor(identifier: string, mongoURI: string);
6
+ private ensureLogDirectoryExists;
5
7
  get logger(): Logger;
6
8
  }
@@ -8,13 +8,21 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.LyxaLogger = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
13
18
  const pino_1 = require("pino");
14
19
  const typedi_1 = require("typedi");
15
20
  let LyxaLogger = class LyxaLogger {
16
21
  _logger;
22
+ logDirectory;
17
23
  constructor(identifier, mongoURI) {
24
+ this.logDirectory = path_1.default.join(process.cwd(), 'logs');
25
+ this.ensureLogDirectoryExists();
18
26
  const transports = pino_1.pino.transport({
19
27
  targets: [
20
28
  {
@@ -27,7 +35,7 @@ let LyxaLogger = class LyxaLogger {
27
35
  {
28
36
  target: 'pino/file',
29
37
  options: {
30
- destination: './logs/error.log',
38
+ destination: path_1.default.join(this.logDirectory, 'error.log'),
31
39
  },
32
40
  level: 'error',
33
41
  },
@@ -46,6 +54,14 @@ let LyxaLogger = class LyxaLogger {
46
54
  level: 'info',
47
55
  }, transports);
48
56
  }
57
+ ensureLogDirectoryExists() {
58
+ try {
59
+ fs_1.default.mkdirSync(this.logDirectory, { recursive: true });
60
+ }
61
+ catch (error) {
62
+ console.error('Failed to create log directory:', error);
63
+ }
64
+ }
49
65
  get logger() {
50
66
  return this._logger;
51
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+BAAoC;AACpC,mCAAiC;AAG1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACL,OAAO,CAAS;IAEjC,YAAY,UAAkB,EAAE,QAAgB;QAC/C,MAAM,UAAU,GAAG,WAAI,CAAC,SAAS,CAAC;YACjC,OAAO,EAAE;gBACR;oBACC,MAAM,EAAE,aAAa;oBACrB,OAAO,EAAE;wBACR,QAAQ,EAAE,IAAI;qBACd;oBACD,KAAK,EAAE,MAAM;iBACb;gBACD;oBACC,MAAM,EAAE,WAAW;oBACnB,OAAO,EAAE;wBACR,WAAW,EAAE,kBAAkB;qBAC/B;oBACD,KAAK,EAAE,OAAO;iBACd;gBACD;oBACC,MAAM,EAAE,cAAc;oBACtB,OAAO,EAAE;wBACR,GAAG,EAAE,QAAQ;wBACb,QAAQ,EAAE,WAAW;wBACrB,UAAU,EAAE,UAAU;qBACtB;oBACD,KAAK,EAAE,OAAO;iBACd;aACD;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,GAAG,IAAA,WAAI,EAClB;YACC,KAAK,EAAE,MAAM;SACb,EACD,UAAU,CACV,CAAC;IACH,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD,CAAA;AA3CY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA2CtB","sourcesContent":["import { pino, Logger } from 'pino';\r\nimport { Service } from 'typedi';\r\n\r\n@Service()\r\nexport class LyxaLogger {\r\n\tprivate readonly _logger: Logger;\r\n\r\n\tconstructor(identifier: string, mongoURI: string) {\r\n\t\tconst transports = pino.transport({\r\n\t\t\ttargets: [\r\n\t\t\t\t{\r\n\t\t\t\t\ttarget: 'pino-pretty',\r\n\t\t\t\t\toptions: {\r\n\t\t\t\t\t\tcolorize: true,\r\n\t\t\t\t\t},\r\n\t\t\t\t\tlevel: 'info',\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\ttarget: 'pino/file',\r\n\t\t\t\t\toptions: {\r\n\t\t\t\t\t\tdestination: './logs/error.log',\r\n\t\t\t\t\t},\r\n\t\t\t\t\tlevel: 'error',\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\ttarget: 'pino-mongodb',\r\n\t\t\t\t\toptions: {\r\n\t\t\t\t\t\turi: mongoURI,\r\n\t\t\t\t\t\tdatabase: 'lyxa-logs',\r\n\t\t\t\t\t\tcollection: identifier,\r\n\t\t\t\t\t},\r\n\t\t\t\t\tlevel: 'error',\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\r\n\t\tthis._logger = pino(\r\n\t\t\t{\r\n\t\t\t\tlevel: 'info',\r\n\t\t\t},\r\n\t\t\ttransports\r\n\t\t);\r\n\t}\r\n\r\n\tget logger(): Logger {\r\n\t\treturn this._logger;\r\n\t}\r\n}\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,+BAAoC;AACpC,mCAAiC;AAG1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACL,OAAO,CAAS;IAChB,YAAY,CAAS;IAEtC,YAAY,UAAkB,EAAE,QAAgB;QAC/C,IAAI,CAAC,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;QAErD,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAEhC,MAAM,UAAU,GAAG,WAAI,CAAC,SAAS,CAAC;YACjC,OAAO,EAAE;gBACR;oBACC,MAAM,EAAE,aAAa;oBACrB,OAAO,EAAE;wBACR,QAAQ,EAAE,IAAI;qBACd;oBACD,KAAK,EAAE,MAAM;iBACb;gBACD;oBACC,MAAM,EAAE,WAAW;oBACnB,OAAO,EAAE;wBACR,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;qBACtD;oBACD,KAAK,EAAE,OAAO;iBACd;gBACD;oBACC,MAAM,EAAE,cAAc;oBACtB,OAAO,EAAE;wBACR,GAAG,EAAE,QAAQ;wBACb,QAAQ,EAAE,WAAW;wBACrB,UAAU,EAAE,UAAU;qBACtB;oBACD,KAAK,EAAE,OAAO;iBACd;aACD;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,GAAG,IAAA,WAAI,EAClB;YACC,KAAK,EAAE,MAAM;SACb,EACD,UAAU,CACV,CAAC;IACH,CAAC;IAEO,wBAAwB;QAC/B,IAAI,CAAC;YACJ,YAAE,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD,CAAA;AAxDY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CAwDtB","sourcesContent":["import fs from 'fs';\r\nimport path from 'path';\r\nimport { pino, Logger } from 'pino';\r\nimport { Service } from 'typedi';\r\n\r\n@Service()\r\nexport class LyxaLogger {\r\n\tprivate readonly _logger: Logger;\r\n\tprivate readonly logDirectory: string;\r\n\r\n\tconstructor(identifier: string, mongoURI: string) {\r\n\t\tthis.logDirectory = path.join(process.cwd(), 'logs');\r\n\r\n\t\tthis.ensureLogDirectoryExists();\r\n\r\n\t\tconst transports = pino.transport({\r\n\t\t\ttargets: [\r\n\t\t\t\t{\r\n\t\t\t\t\ttarget: 'pino-pretty',\r\n\t\t\t\t\toptions: {\r\n\t\t\t\t\t\tcolorize: true,\r\n\t\t\t\t\t},\r\n\t\t\t\t\tlevel: 'info',\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\ttarget: 'pino/file',\r\n\t\t\t\t\toptions: {\r\n\t\t\t\t\t\tdestination: path.join(this.logDirectory, 'error.log'),\r\n\t\t\t\t\t},\r\n\t\t\t\t\tlevel: 'error',\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\ttarget: 'pino-mongodb',\r\n\t\t\t\t\toptions: {\r\n\t\t\t\t\t\turi: mongoURI,\r\n\t\t\t\t\t\tdatabase: 'lyxa-logs',\r\n\t\t\t\t\t\tcollection: identifier,\r\n\t\t\t\t\t},\r\n\t\t\t\t\tlevel: 'error',\r\n\t\t\t\t},\r\n\t\t\t],\r\n\t\t});\r\n\r\n\t\tthis._logger = pino(\r\n\t\t\t{\r\n\t\t\t\tlevel: 'info',\r\n\t\t\t},\r\n\t\t\ttransports\r\n\t\t);\r\n\t}\r\n\r\n\tprivate ensureLogDirectoryExists(): void {\r\n\t\ttry {\r\n\t\t\tfs.mkdirSync(this.logDirectory, { recursive: true });\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error('Failed to create log directory:', error);\r\n\t\t}\r\n\t}\r\n\r\n\tget logger(): Logger {\r\n\t\treturn this._logger;\r\n\t}\r\n}\r\n"]}
@@ -18,7 +18,7 @@ async function initGlobalConnection(uri, environment) {
18
18
  const connection = (0, mongoose_1.createConnection)(uri, {
19
19
  dbName: `lyxa-${environment}-global`,
20
20
  });
21
- connection.once('connected', () => {
21
+ connection.once('connected', async () => {
22
22
  console.log('Global connection successfully established');
23
23
  globalConnection = connection;
24
24
  for (const [modelName, { Class, options, resolve }] of pendingModels.entries()) {
@@ -29,12 +29,19 @@ async function initGlobalConnection(uri, environment) {
29
29
  resolve(model);
30
30
  }
31
31
  pendingModels.clear();
32
- for (const [modelName, { baseModel, subClass, discriminatorName, options, resolve },] of pendingDiscriminatorModels.entries()) {
33
- const model = (0, typegoose_1.getDiscriminatorModelForClass)(baseModel, subClass, discriminatorName, {
34
- existingConnection: globalConnection,
35
- ...options,
36
- });
37
- resolve(model);
32
+ for (const [modelName, { baseModelPromise, subClass, discriminatorName, options, resolve },] of pendingDiscriminatorModels.entries()) {
33
+ try {
34
+ const actualBaseModel = await baseModelPromise;
35
+ const model = (0, typegoose_1.getDiscriminatorModelForClass)(actualBaseModel, subClass, discriminatorName, {
36
+ existingConnection: globalConnection,
37
+ ...options,
38
+ });
39
+ resolve(model);
40
+ }
41
+ catch (error) {
42
+ console.error(`Failed to create discriminator model ${modelName}:`, error);
43
+ resolve(Promise.reject(error));
44
+ }
38
45
  }
39
46
  pendingDiscriminatorModels.clear();
40
47
  resolve(connection);
@@ -53,12 +60,15 @@ function createGlobalModel(Class, options) {
53
60
  }
54
61
  console.log(`Registering model ${modelName} to be initialized when global connection is ready`);
55
62
  let actualModel = null;
56
- let modelReadyPromise = null;
63
+ let modelReadyPromise;
57
64
  modelReadyPromise = new Promise(resolve => {
58
65
  pendingModels.set(modelName, { Class, options, resolve });
59
66
  });
60
67
  const modelProxy = new Proxy({}, {
61
68
  get(target, prop, receiver) {
69
+ if (prop === 'then') {
70
+ return modelReadyPromise.then.bind(modelReadyPromise);
71
+ }
62
72
  return async function (...args) {
63
73
  if (!actualModel) {
64
74
  actualModel = await modelReadyPromise;
@@ -76,6 +86,16 @@ function createGlobalModel(Class, options) {
76
86
  function createGlobalDiscriminatorModel(baseModel, subClass, discriminatorName, options) {
77
87
  const modelName = discriminatorName || subClass.name;
78
88
  if (globalConnection) {
89
+ if (baseModel instanceof Promise || baseModel.then) {
90
+ const discriminatorPromise = (async () => {
91
+ const resolvedBaseModel = await baseModel;
92
+ return (0, typegoose_1.getDiscriminatorModelForClass)(resolvedBaseModel, subClass, discriminatorName, {
93
+ existingConnection: globalConnection,
94
+ ...options,
95
+ });
96
+ })();
97
+ return createProxyForPromise(discriminatorPromise);
98
+ }
79
99
  return (0, typegoose_1.getDiscriminatorModelForClass)(baseModel, subClass, discriminatorName, {
80
100
  existingConnection: globalConnection,
81
101
  ...options,
@@ -83,30 +103,43 @@ function createGlobalDiscriminatorModel(baseModel, subClass, discriminatorName,
83
103
  }
84
104
  console.log(`Registering discriminator model ${modelName} to be initialized when global connection is ready`);
85
105
  let actualModel = null;
86
- let modelReadyPromise = null;
106
+ let modelReadyPromise;
107
+ let baseModelPromise;
108
+ if (baseModel instanceof Promise || baseModel.then) {
109
+ baseModelPromise = Promise.resolve(baseModel);
110
+ }
111
+ else {
112
+ baseModelPromise = Promise.resolve(baseModel);
113
+ }
87
114
  modelReadyPromise = new Promise(resolve => {
88
115
  pendingDiscriminatorModels.set(modelName, {
89
- baseModel,
116
+ baseModelPromise,
90
117
  subClass,
91
118
  discriminatorName,
92
119
  options,
93
120
  resolve,
94
121
  });
95
122
  });
96
- const modelProxy = new Proxy({}, {
123
+ return createProxyForPromise(modelReadyPromise);
124
+ }
125
+ function createProxyForPromise(promise) {
126
+ let resolvedValue = null;
127
+ return new Proxy({}, {
97
128
  get(target, prop, receiver) {
129
+ if (prop === 'then') {
130
+ return promise.then.bind(promise);
131
+ }
98
132
  return async function (...args) {
99
- if (!actualModel) {
100
- actualModel = await modelReadyPromise;
133
+ if (!resolvedValue) {
134
+ resolvedValue = await promise;
101
135
  }
102
- const propValue = actualModel[prop];
136
+ const propValue = resolvedValue[prop];
103
137
  if (typeof propValue === 'function') {
104
- return propValue.apply(actualModel, args);
138
+ return propValue.apply(resolvedValue, args);
105
139
  }
106
140
  return propValue;
107
141
  };
108
142
  },
109
143
  });
110
- return modelProxy;
111
144
  }
112
145
  //# sourceMappingUR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,EAAE,CAAC;oBAClB,WAAW,GAAG,MAAM,iBAAkB,CAAC;gBACxC,CAAC;gBAED,MAAM,SAAS,GAAI,WAAmB,CAAC,IAAI,CAAC,CAAC;gBAC7C,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;oBACrC,OAAO,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBAC3C,CAAC;gBACD,OAAO,SAAS,CAAC;YAClB,CAAC,CAAC;QACH,CAAC;KACD,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import mongoose, { Connection, createConnection } from 'mongoose';\r\nimport { getDiscriminatorModelForClass, getModelForClass, ReturnModelType } from '@typegoose/typegoose';\r\nimport { AnyParamConstructor, IModelOptions } from '@typegoose/typegoose/lib/types';\r\nimport { applySoftDeletePlugin } from './plugins/soft-delete-plugin';\r\n\r\n// Apply the soft delete plugin globally before any connections or models\r\napplySoftDeletePlugin();\r\n\r\n// Track connection status\r\nlet globalConnection: Connection | undefined;\r\nlet connectionPromise: Promise<Connection> | null = null;\r\nlet pendingModels = new Map<\r\n\tstring,\r\n\t{\r\n\t\tClass: AnyParamConstructor<any>;\r\n\t\toptions?: IModelOptions;\r\n\t\tresolve: (model: any) => void;\r\n\t}\r\n>();\r\n\r\nlet pendingDiscriminatorModels = new Map<\r\n\tstring,\r\n\t{\r\n\t\tbaseModel: any;\r\n\t\tsubClass: AnyParamConstructor<any>;\r\n\t\tdiscriminatorName?: string;\r\n\t\toptions?: IModelOptions;\r\n\t\tresolve: (model: any) => void;\r\n\t}\r\n>();\r\n\r\n/**\r\n * Initialize the global database connection\r\n */\r\nexport async function initGlobalConnection(uri: string, environment: string): Promise<Connection> {\r\n\tif (!connectionPromise) {\r\n\t\tconnectionPromise = new Promise<Connection>(resolve => {\r\n\t\t\tconsole.log(`Initializing global connection for environment: ${environment}`);\r\n\t\t\tconst connection = createConnection(uri, {\r\n\t\t\t\tdbName: `lyxa-${environment}-global`,\r\n\t\t\t});\r\n\r\n\t\t\tconnection.once('connected', () => {\r\n\t\t\t\tconsole.log('Global connection successfully established');\r\n\t\t\t\tglobalConnection = connection;\r\n\r\n\t\t\t\t// Initialize any pending models with the real connection\r\n\t\t\t\tfor (const [modelName, { Class, options, resolve }] of pendingModels.entries()) {\r\n\t\t\t\t\tconst model = getModelForClass(Class, {\r\n\t\t\t\t\t\texistingConnection: globalConnection,\r\n\t\t\t\t\t\t...options,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tresolve(model);\r\n\t\t\t\t}\r\n\t\t\t\tpendingModels.clear();\r\n\r\n\t\t\t\t// Initialize any pending discriminator models\r\n\t\t\t\tfor (const [\r\n\t\t\t\t\tmodelName,\r\n\t\t\t\t\t{ baseModel, subClass, discriminatorName, options, resolve },\r\n\t\t\t\t] of pendingDiscriminatorModels.entries()) {\r\n\t\t\t\t\tconst model = getDiscriminatorModelForClass(baseModel, subClass, discriminatorName, {\r\n\t\t\t\t\t\texistingConnection: globalConnection,\r\n\t\t\t\t\t\t...options,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tresolve(model);\r\n\t\t\t\t}\r\n\t\t\t\tpendingDiscriminatorModels.clear();\r\n\r\n\t\t\t\tresolve(connection);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\treturn connectionPromise;\r\n}\r\n\r\n/**\r\n * Creates a Typegoose model that will use the global connection when it's ready.\r\n * Safe to call during module initialization before initGlobalConnection.\r\n */\r\nexport function createGlobalModel<T extends AnyParamConstructor<any>>(\r\n\tClass: T,\r\n\toptions?: IModelOptions\r\n): ReturnModelType<T> {\r\n\tconst modelName = options?.schemaOptions?.collection || Class.name;\r\n\r\n\t// If the connection is already initialized, create the model directly\r\n\tif (globalConnection) {\r\n\t\treturn getModelForClass(Class, {\r\n\t\t\texistingConnection: globalConnection,\r\n\t\t\t...options,\r\n\t\t});\r\n\t}\r\n\r\n\tconsole.log(`Registering model ${modelName} to be initialized when global connection is ready`);\r\n\r\n\t// Create a lazy-loaded model instance that will initialize once the connection is ready\r\n\tlet actualModel: ReturnModelType<T> | null = null;\r\n\tlet modelReadyPromise: Promise<ReturnModelType<T>> | null = null;\r\n\r\n\t// Setup the promise that will resolve once the model is ready\r\n\tmodelReadyPromise = new Promise<ReturnModelType<T>>(resolve => {\r\n\t\t// Register this model to be initialized when connection is ready\r\n\t\tpendingModels.set(modelName, { Class, options, resolve });\r\n\t});\r\n\r\n\t// Create a proxy that forwards operations to the real model once it's available\r\n\tconst modelProxy = new Proxy({} as ReturnModelType<T>, {\r\n\t\tget(target, prop, receiver) {\r\n\t\t\treturn async function (...args: any[]) {\r\n\t\t\t\tif (!actualModel) {\r\n\t\t\t\t\tactualModel = await modelReadyPromise!;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst propValue = (actualModel as any)[prop];\r\n\t\t\t\tif (typeof propValue === 'function') {\r\n\t\t\t\t\treturn propValue.apply(actualModel, args);\r\n\t\t\t\t}\r\n\t\t\t\treturn propValue;\r\n\t\t\t};\r\n\t\t},\r\n\t});\r\n\r\n\treturn modelProxy;\r\n}\r\n\r\n/**\r\n * Creates a Typegoose discriminator model that will use the global connection when it's ready.\r\n * Safe to call during module initialization before initGlobalConnection.\r\n */\r\nexport function createGlobalDiscriminatorModel<\r\n\tBase extends AnyParamConstructor<any>,\r\n\tSub extends AnyParamConstructor<any>,\r\n>(\r\n\tbaseModel: ReturnModelType<Base>,\r\n\tsubClass: Sub,\r\n\tdiscriminatorName?: string,\r\n\toptions?: IModelOptions\r\n): ReturnModelType<Sub> {\r\n\tconst modelName = discriminatorName || subClass.name;\r\n\r\n\t// If the connection is already initialized, create the model directly\r\n\tif (globalConnection) {\r\n\t\treturn getDiscriminatorModelForClass(baseModel, subClass, discriminatorName, {\r\n\t\t\texistingConnection: globalConnection,\r\n\t\t\t...options,\r\n\t\t});\r\n\t}\r\n\r\n\tconsole.log(\r\n\t\t`Registering discriminator model ${modelName} to be initialized when global connection is ready`\r\n\t);\r\n\r\n\t// Create a lazy-loaded model instance that will initialize once the connection is ready\r\n\tlet actualModel: ReturnModelType<Sub> | null = null;\r\n\tlet modelReadyPromise: Promise<ReturnModelType<Sub>> | null = null;\r\n\r\n\t// Setup the promise that will resolve once the model is ready\r\n\tmodelReadyPromise = new Promise<ReturnModelType<Sub>>(resolve => {\r\n\t\t// Register this discriminator model to be initialized when connection is ready\r\n\t\tpendingDiscriminatorModels.set(modelName, {\r\n\t\t\tbaseModel,\r\n\t\t\tsubClass,\r\n\t\t\tdiscriminatorName,\r\n\t\t\toptions,\r\n\t\t\tresolve,\r\n\t\t});\r\n\t});\r\n\r\n\t// Create a proxy that forwards operations to the real model once it's available\r\n\tconst modelProxy = new Proxy({} as ReturnModelType<Sub>, {\r\n\t\tget(target, prop, receiver) {\r\n\t\t\treturn async function (...args: any[]) {\r\n\t\t\t\tif (!actualModel) {\r\n\t\t\t\t\tactualModel = await modelReadyPromise!;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst propValue = (actualModel as any)[prop];\r\n\t\t\t\tif (typeof propValue === 'function') {\r\n\t\t\t\t\treturn propValue.apply(actualModel, args);\r\n\t\t\t\t}\r\n\t\t\t\treturn propValue;\r\n\t\t\t};\r\n\t\t},\r\n\t});\r\n\r\n\treturn modelProxy;\r\n}\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/mongo/index.ts"],"names":[],"mappings":";;AAkCA,oDAmDC;AAMD,8CAiDC;AAMD,wEAgEC;AAlND,uCAAkE;AAClE,oDAAwG;AAExG,qEAAqE;AAGrE,IAAA,0CAAqB,GAAE,CAAC;AAGxB,IAAI,gBAAwC,CAAC;AAC7C,IAAI,iBAAiB,GAA+B,IAAI,CAAC;AACzD,IAAI,aAAa,GAAG,IAAI,GAAG,EAOxB,CAAC;AAEJ,IAAI,0BAA0B,GAAG,IAAI,GAAG,EASrC,CAAC;AAKG,KAAK,UAAU,oBAAoB,CAAC,GAAW,EAAE,WAAmB;IAC1E,IAAI,CAAC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OAAO,IAAK,SAAiB,CAAC,IAAI,EAAE,CAAC;QAC7D,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACP,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAGD,iBAAiB,GAAG,IAAI,OAAO,CAAuB,OAAO,CAAC,EAAE;QAE/D,0BAA0B,CAAC,GAAG,CAAC,SAAS,EAAE;YACzC,gBAAgB;YAChB,QAAQ;YACR,iBAAiB;YACjB,OAAO;YACP,OAAO;SACP,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;AACjD,CAAC;AAKD,SAAS,qBAAqB,CAAmB,OAAmB;IACnE,IAAI,aAAa,GAAa,IAAI,CAAC;IAEnC,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE;QACzB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YAEzB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACrB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;YAED,OAAO,KAAK,WAAW,GAAG,IAAW;gBACpC,IAAI,CAAC,aAAa,EAAE,CAAC;oBACpB,aAAa,GAAG,MAAM,OAAO,CAAC;gBAC/B,CAAC;gBAED,MAAM,SAAS,GAAI,aAAqB,CAAC,IAAI,CAAC,CAAC;gBAC/C,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;oBACrC,OAAO,SAAS,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;gBAC7C,CAAC;gBACD,OAAO,SAAS,CAAC;YAClB,CAAC,CAAC;QACH,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import mongoose, { Connection, createConnection } from 'mongoose';\r\nimport { getDiscriminatorModelForClass, getModelForClass, ReturnModelType } from '@typegoose/typegoose';\r\nimport { AnyParamConstructor, IModelOptions } from '@typegoose/typegoose/lib/types';\r\nimport { applySoftDeletePlugin } from './plugins/soft-delete-plugin';\r\n\r\n// Apply the soft delete plugin globally before any connections or models\r\napplySoftDeletePlugin();\r\n\r\n// Track connection status\r\nlet globalConnection: Connection | undefined;\r\nlet connectionPromise: Promise<Connection> | null = null;\r\nlet pendingModels = new Map<\r\n\tstring,\r\n\t{\r\n\t\tClass: AnyParamConstructor<any>;\r\n\t\toptions?: IModelOptions;\r\n\t\tresolve: (model: any) => void;\r\n\t}\r\n>();\r\n\r\nlet pendingDiscriminatorModels = new Map<\r\n\tstring,\r\n\t{\r\n\t\tbaseModelPromise: Promise<any>; // Store the promise for the base model\r\n\t\tsubClass: AnyParamConstructor<any>;\r\n\t\tdiscriminatorName?: string;\r\n\t\toptions?: IModelOptions;\r\n\t\tresolve: (model: any) => void;\r\n\t}\r\n>();\r\n\r\n/**\r\n * Initialize the global database connection\r\n */\r\nexport async function initGlobalConnection(uri: string, environment: string): Promise<Connection> {\r\n\tif (!connectionPromise) {\r\n\t\tconnectionPromise = new Promise<Connection>(resolve => {\r\n\t\t\tconsole.log(`Initializing global connection for environment: ${environment}`);\r\n\t\t\tconst connection = createConnection(uri, {\r\n\t\t\t\tdbName: `lyxa-${environment}-global`,\r\n\t\t\t});\r\n\r\n\t\t\tconnection.once('connected', async () => {\r\n\t\t\t\tconsole.log('Global connection successfully established');\r\n\t\t\t\tglobalConnection = connection;\r\n\r\n\t\t\t\t// Initialize any pending models with the real connection\r\n\t\t\t\tfor (const [modelName, { Class, options, resolve }] of pendingModels.entries()) {\r\n\t\t\t\t\tconst model = getModelForClass(Class, {\r\n\t\t\t\t\t\texistingConnection: globalConnection,\r\n\t\t\t\t\t\t...options,\r\n\t\t\t\t\t});\r\n\t\t\t\t\tresolve(model);\r\n\t\t\t\t}\r\n\t\t\t\tpendingModels.clear();\r\n\r\n\t\t\t\t// Initialize any pending discriminator models\r\n\t\t\t\t// Process discriminators sequentially to ensure dependencies are resolved\r\n\t\t\t\tfor (const [\r\n\t\t\t\t\tmodelName,\r\n\t\t\t\t\t{ baseModelPromise, subClass, discriminatorName, options, resolve },\r\n\t\t\t\t] of pendingDiscriminatorModels.entries()) {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\t// Await the base model to be fully resolved\r\n\t\t\t\t\t\tconst actualBaseModel = await baseModelPromise;\r\n\r\n\t\t\t\t\t\t// Create the discriminator model with the actual base model\r\n\t\t\t\t\t\tconst model = getDiscriminatorModelForClass(actualBaseModel, subClass, discriminatorName, {\r\n\t\t\t\t\t\t\texistingConnection: globalConnection,\r\n\t\t\t\t\t\t\t...options,\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t\tresolve(model);\r\n\t\t\t\t\t} catch (error) {\r\n\t\t\t\t\t\tconsole.error(`Failed to create discriminator model ${modelName}:`, error);\r\n\t\t\t\t\t\t// Resolve with error to unblock the promise chain\r\n\t\t\t\t\t\tresolve(Promise.reject(error));\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tpendingDiscriminatorModels.clear();\r\n\r\n\t\t\t\tresolve(connection);\r\n\t\t\t});\r\n\t\t});\r\n\t}\r\n\treturn connectionPromise;\r\n}\r\n\r\n/**\r\n * Creates a Typegoose model that will use the global connection when it's ready.\r\n * Safe to call during module initialization before initGlobalConnection.\r\n */\r\nexport function createGlobalModel<T extends AnyParamConstructor<any>>(\r\n\tClass: T,\r\n\toptions?: IModelOptions\r\n): ReturnModelType<T> {\r\n\tconst modelName = options?.schemaOptions?.collection || Class.name;\r\n\r\n\t// If the connection is already initialized, create the model directly\r\n\tif (globalConnection) {\r\n\t\treturn getModelForClass(Class, {\r\n\t\t\texistingConnection: globalConnection,\r\n\t\t\t...options,\r\n\t\t});\r\n\t}\r\n\r\n\tconsole.log(`Registering model ${modelName} to be initialized when global connection is ready`);\r\n\r\n\t// Create a lazy-loaded model instance that will initialize once the connection is ready\r\n\tlet actualModel: ReturnModelType<T> | null = null;\r\n\tlet modelReadyPromise: Promise<ReturnModelType<T>>;\r\n\r\n\t// Setup the promise that will resolve once the model is ready\r\n\tmodelReadyPromise = new Promise<ReturnModelType<T>>(resolve => {\r\n\t\t// Register this model to be initialized when connection is ready\r\n\t\tpendingModels.set(modelName, { Class, options, resolve });\r\n\t});\r\n\r\n\t// Create a proxy that forwards operations to the real model once it's available\r\n\tconst modelProxy = new Proxy({} as ReturnModelType<T>, {\r\n\t\tget(target, prop, receiver) {\r\n\t\t\t// Handle special case for 'then' to make the proxy thenable\r\n\t\t\tif (prop === 'then') {\r\n\t\t\t\treturn modelReadyPromise.then.bind(modelReadyPromise);\r\n\t\t\t}\r\n\r\n\t\t\treturn async function (...args: any[]) {\r\n\t\t\t\tif (!actualModel) {\r\n\t\t\t\t\tactualModel = await modelReadyPromise;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst propValue = (actualModel as any)[prop];\r\n\t\t\t\tif (typeof propValue === 'function') {\r\n\t\t\t\t\treturn propValue.apply(actualModel, args);\r\n\t\t\t\t}\r\n\t\t\t\treturn propValue;\r\n\t\t\t};\r\n\t\t},\r\n\t});\r\n\r\n\treturn modelProxy;\r\n}\r\n\r\n/**\r\n * Creates a Typegoose discriminator model that will use the global connection when it's ready.\r\n * Safe to call during module initialization before initGlobalConnection.\r\n */\r\nexport function createGlobalDiscriminatorModel<\r\n\tBase extends AnyParamConstructor<any>,\r\n\tSub extends AnyParamConstructor<any>,\r\n>(\r\n\tbaseModel: ReturnModelType<Base>,\r\n\tsubClass: Sub,\r\n\tdiscriminatorName?: string,\r\n\toptions?: IModelOptions\r\n): ReturnModelType<Sub> {\r\n\tconst modelName = discriminatorName || subClass.name;\r\n\r\n\t// If the connection is already initialized, create the model directly\r\n\tif (globalConnection) {\r\n\t\t// Ensure baseModel is fully resolved if it's a promise or proxy\r\n\t\tif (baseModel instanceof Promise || (baseModel as any).then) {\r\n\t\t\t// Create a new promise that will resolve with the discriminator model\r\n\t\t\tconst discriminatorPromise = (async () => {\r\n\t\t\t\tconst resolvedBaseModel = await baseModel;\r\n\t\t\t\treturn getDiscriminatorModelForClass(resolvedBaseModel, subClass, discriminatorName, {\r\n\t\t\t\t\texistingConnection: globalConnection,\r\n\t\t\t\t\t...options,\r\n\t\t\t\t});\r\n\t\t\t})();\r\n\r\n\t\t\t// Return a proxy that will await the discriminator model\r\n\t\t\treturn createProxyForPromise(discriminatorPromise);\r\n\t\t}\r\n\r\n\t\t// If baseModel is not a promise, create the discriminator directly\r\n\t\treturn getDiscriminatorModelForClass(baseModel, subClass, discriminatorName, {\r\n\t\t\texistingConnection: globalConnection,\r\n\t\t\t...options,\r\n\t\t});\r\n\t}\r\n\r\n\tconsole.log(\r\n\t\t`Registering discriminator model ${modelName} to be initialized when global connection is ready`\r\n\t);\r\n\r\n\t// Create a lazy-loaded model instance that will initialize once the connection is ready\r\n\tlet actualModel: ReturnModelType<Sub> | null = null;\r\n\tlet modelReadyPromise: Promise<ReturnModelType<Sub>>;\r\n\r\n\t// Handle the case where baseModel might be a proxy or promise\r\n\tlet baseModelPromise: Promise<any>;\r\n\tif (baseModel instanceof Promise || (baseModel as any).then) {\r\n\t\tbaseModelPromise = Promise.resolve(baseModel);\r\n\t} else {\r\n\t\tbaseModelPromise = Promise.resolve(baseModel);\r\n\t}\r\n\r\n\t// Setup the promise that will resolve once the model is ready\r\n\tmodelReadyPromise = new Promise<ReturnModelType<Sub>>(resolve => {\r\n\t\t// Register this discriminator model to be initialized when connection is ready\r\n\t\tpendingDiscriminatorModels.set(modelName, {\r\n\t\t\tbaseModelPromise,\r\n\t\t\tsubClass,\r\n\t\t\tdiscriminatorName,\r\n\t\t\toptions,\r\n\t\t\tresolve,\r\n\t\t});\r\n\t});\r\n\r\n\treturn createProxyForPromise(modelReadyPromise);\r\n}\r\n\r\n/**\r\n * Helper function to create a proxy for a promise that will resolve to a model\r\n */\r\nfunction createProxyForPromise<T extends object>(promise: Promise<T>): T {\r\n\tlet resolvedValue: T | null = null;\r\n\r\n\treturn new Proxy({} as T, {\r\n\t\tget(target, prop, receiver) {\r\n\t\t\t// Handle special case for 'then' to make the proxy thenable\r\n\t\t\tif (prop === 'then') {\r\n\t\t\t\treturn promise.then.bind(promise);\r\n\t\t\t}\r\n\r\n\t\t\treturn async function (...args: any[]) {\r\n\t\t\t\tif (!resolvedValue) {\r\n\t\t\t\t\tresolvedValue = await promise;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst propValue = (resolvedValue as any)[prop];\r\n\t\t\t\tif (typeof propValue === 'function') {\r\n\t\t\t\t\treturn propValue.apply(resolvedValue, args);\r\n\t\t\t\t}\r\n\t\t\t\treturn propValue;\r\n\t\t\t};\r\n\t\t},\r\n\t});\r\n}\r\n"]}
@@ -41,7 +41,7 @@ __decorate([
41
41
  __metadata("design:type", String)
42
42
  ], Cart.prototype, "title", void 0);
43
43
  __decorate([
44
- (0, typegoose_1.prop)({ unique: true, sparse: true }),
44
+ (0, typegoose_1.prop)(),
45
45
  __metadata("design:type", String)
46
46
  ], Cart.prototype, "slug", void 0);
47
47
  __decorate([
@@ -96,10 +96,17 @@ exports.Cart = Cart = __decorate([
96
96
  allowMixed: typegoose_1.Severity.ALLOW,
97
97
  },
98
98
  }),
99
- (0, typegoose_1.index)({ slug: 1 }, { unique: true }),
99
+ (0, typegoose_1.index)({ slug: 1 }, { unique: true, sparse: true }),
100
100
  (0, typegoose_1.index)({ user: 1 }),
101
101
  (0, typegoose_1.index)({ shop: 1 }),
102
102
  (0, typegoose_1.index)({ status: 1 }),
103
+ (0, typegoose_1.index)({ user: 1, shop: 1 }, {
104
+ unique: true,
105
+ partialFilterExpression: {
106
+ status: { $in: [enum_1.CartStatus.ACTIVE, enum_1.CartStatus.LOCKED] },
107
+ deletedAt: null,
108
+ },
109
+ }),
103
110
  (0, typegoose_1.pre)('save', async function (next) {
104
111
  if (this.title && !this.slug) {
105
112
  const baseSlug = (0, slugify_1.default)(this.title, {
@@ -1 +1 @@
1
-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EAAE,IAAI;gBACX,MAAM,EAAE,IAAI;gBACZ,IAAI,EAAE,IAAI;aACV,CAAC,CAAC;YAEH,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChD,IAAI,CAAC,IAAI,GAAG,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC;QACvC,CAAC;QACD,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,IAAI,CAsChB","sourcesContent":["import { prop, Ref, index, modelOptions, Severity, pre } from '@typegoose/typegoose';\r\nimport { Shop } from './shop.model';\r\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\r\nimport { CartStatus, PaymentPreference, ValueType } from '../../../utilities/enum';\r\nimport { UserAddress } from './shared/address.model';\r\nimport slugify from 'slugify';\r\nimport { randomBytes } from 'crypto';\r\n\r\nimport { Coupon } from './coupon.model';\r\nimport { User } from './user.model';\r\n\r\n/**\r\n * Cart configuration model using Typegoose with automatic slug generation\r\n */\r\n@modelOptions({\r\n\tschemaOptions: {\r\n\t\tcollection: 'carts',\r\n\t\ttoJSON: { virtuals: true },\r\n\t\ttoObject: { virtuals: true },\r\n\t},\r\n\toptions: {\r\n\t\tallowMixed: Severity.ALLOW,\r\n\t},\r\n})\r\n@index({ slug: 1 }, { unique: true })\r\n@index({ user: 1 })\r\n@index({ shop: 1 })\r\n@index({ status: 1 })\r\n@pre<Cart>('save', async function (next) {\r\n\tif (this.title && !this.slug) {\r\n\t\tconst baseSlug = slugify(this.title, {\r\n\t\t\tlower: true,\r\n\t\t\tstrict: true,\r\n\t\t\ttrim: true,\r\n\t\t});\r\n\r\n\t\tconst uniqueId = randomBytes(8).toString('hex');\r\n\t\tthis.slug = `${baseSlug}-${uniqueId}`;\r\n\t}\r\n\tnext();\r\n})\r\nexport class Cart extends TimeStamps {\r\n\t@prop({ trim: true, maxlength: 100 })\r\n\tpublic title?: string;\r\n\r\n\t@prop({ unique: true, sparse: true })\r\n\tpublic slug?: string;\r\n\r\n\t@prop({ required: true, ref: () => User })\r\n\tpublic user!: Ref<User>;\r\n\r\n\t@prop({ required: true, ref: () => Shop })\r\n\tpublic shop!: Ref<Shop>;\r\n\r\n\t@prop({ required: false, type: UserAddress })\r\n\tpublic deliveryAddress?: UserAddress;\r\n\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic isGroupOrder?: boolean;\r\n\r\n\t@prop({ type: Date })\r\n\tpublic deadlineToOrder?: Date;\r\n\r\n\t@prop({ type: String, enum: PaymentPreference })\r\n\tpublic paymentPreference?: PaymentPreference;\r\n\r\n\t@prop({ type: Number, default: Infinity })\r\n\tpublic spendingLimitForGuest?: number;\r\n\r\n\t@prop({\r\n\t\tenum: CartStatus,\r\n\t\ttype: String,\r\n\t\tdefault: CartStatus.ACTIVE,\r\n\t\trequired: true,\r\n\t})\r\n\tpublic status!: CartStatus;\r\n\r\n\t@prop({ ref: () => Coupon })\r\n\tpublic coupon?: Ref<Coupon>;\r\n}\r\n"]}
1
+ {"version":3,"file":"cart.model.js","sourceRoot":"/","sources":["libraries/mongo/models/cart.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAqF;AACrF,6CAAoC;AACpC,4EAAqE;AACrE,kDAAwE;AACxE,0DAAqD;AACrD,sDAA8B;AAC9B,mCAAqC;AAErC,iDAAwC;AACxC,6CAAoC;AA0C7B,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,2BAAU;IAE5B,KAAK,CAAU;IAGf,IAAI,CAAU;IAGd,IAAI,CAAa;IAGjB,IAAI,CAAa;IAGjB,eAAe,CAAe;IAG9B,YAAY,CAAW;IAGvB,eAAe,CAAQ;IAGvB,iBAAiB,CAAqB;IAGtC,qBAAqB,CAAU;IAQ/B,MAAM,CAAc;IAGpB,MAAM,CAAe;CAC5B,CAAA;AAtCY,oBAAI;AAET;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE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r\nimport { Shop } from './shop.model';\r\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\r\nimport { CartStatus, PaymentPreference } from '../../../utilities/enum';\r\nimport { UserAddress } from './shared/address.model';\r\nimport slugify from 'slugify';\r\nimport { randomBytes } from 'crypto';\r\n\r\nimport { Coupon } from './coupon.model';\r\nimport { User } from './user.model';\r\n\r\n/**\r\n * Cart configuration model using Typegoose with automatic slug generation\r\n */\r\n@modelOptions({\r\n\tschemaOptions: {\r\n\t\tcollection: 'carts',\r\n\t\ttoJSON: { virtuals: true },\r\n\t\ttoObject: { virtuals: true },\r\n\t},\r\n\toptions: {\r\n\t\tallowMixed: Severity.ALLOW,\r\n\t},\r\n})\r\n@index({ slug: 1 }, { unique: true, sparse: true })\r\n@index({ user: 1 })\r\n@index({ shop: 1 })\r\n@index({ status: 1 })\r\n@index(\r\n\t{ user: 1, shop: 1 },\r\n\t{\r\n\t\tunique: true,\r\n\t\tpartialFilterExpression: {\r\n\t\t\tstatus: { $in: [CartStatus.ACTIVE, CartStatus.LOCKED] },\r\n\t\t\tdeletedAt: null,\r\n\t\t},\r\n\t}\r\n)\r\n@pre<Cart>('save', async function (next) {\r\n\tif (this.title && !this.slug) {\r\n\t\tconst baseSlug = slugify(this.title, {\r\n\t\t\tlower: true,\r\n\t\t\tstrict: true,\r\n\t\t\ttrim: true,\r\n\t\t});\r\n\r\n\t\tconst uniqueId = randomBytes(8).toString('hex');\r\n\t\tthis.slug = `${baseSlug}-${uniqueId}`;\r\n\t}\r\n\tnext();\r\n})\r\nexport class Cart extends TimeStamps {\r\n\t@prop({ trim: true, maxlength: 100 })\r\n\tpublic title?: string;\r\n\r\n\t@prop()\r\n\tpublic slug?: string;\r\n\r\n\t@prop({ required: true, ref: () => User })\r\n\tpublic user!: Ref<User>;\r\n\r\n\t@prop({ required: true, ref: () => Shop })\r\n\tpublic shop!: Ref<Shop>;\r\n\r\n\t@prop({ required: false, type: UserAddress })\r\n\tpublic deliveryAddress?: UserAddress;\r\n\r\n\t@prop({ type: Boolean, default: false })\r\n\tpublic isGroupOrder?: boolean;\r\n\r\n\t@prop({ type: Date })\r\n\tpublic deadlineToOrder?: Date;\r\n\r\n\t@prop({ type: String, enum: PaymentPreference })\r\n\tpublic paymentPreference?: PaymentPreference;\r\n\r\n\t@prop({ type: Number, default: Infinity })\r\n\tpublic spendingLimitForGuest?: number;\r\n\r\n\t@prop({\r\n\t\tenum: CartStatus,\r\n\t\ttype: String,\r\n\t\tdefault: CartStatus.ACTIVE,\r\n\t\trequired: true,\r\n\t})\r\n\tpublic status!: CartStatus;\r\n\r\n\t@prop({ ref: () => Coupon })\r\n\tpublic coupon?: Ref<Coupon>;\r\n}\r\n"]}
@@ -0,0 +1,5 @@
1
+ export declare class PriceBreakdown {
2
+ unit?: string;
3
+ unitValue?: number;
4
+ price: number;
5
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PriceBreakdown = void 0;
13
+ const typegoose_1 = require("@typegoose/typegoose");
14
+ class PriceBreakdown {
15
+ unit;
16
+ unitValue;
17
+ price;
18
+ }
19
+ exports.PriceBreakdown = PriceBreakdown;
20
+ __decorate([
21
+ (0, typegoose_1.prop)({ type: String }),
22
+ __metadata("design:type", String)
23
+ ], PriceBreakdown.prototype, "unit", void 0);
24
+ __decorate([
25
+ (0, typegoose_1.prop)({ type: Number, min: 0 }),
26
+ __metadata("design:type", Number)
27
+ ], PriceBreakdown.prototype, "unitValue", void 0);
28
+ __decorate([
29
+ (0, typegoose_1.prop)({ required: true, type: Number, min: 0, max: 99999999 }),
30
+ __metadata("design:type", Number)
31
+ ], PriceBreakdown.prototype, "price", void 0);
32
+ //# sourceMappingURL=price-breakdown.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-breakdown.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/price-breakdown.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,cAAc;IAEnB,IAAI,CAAU;IAGd,SAAS,CAAU;IAGnB,KAAK,CAAU;CACtB;AATD,wCASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;4CACF;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;;iDACL;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;;6CACxC","sourcesContent":["import { prop } from '@typegoose/typegoose';\r\n\r\nexport class PriceBreakdown {\r\n\t@prop({ type: String })\r\n\tpublic unit?: string;\r\n\r\n\t@prop({ type: Number, min: 0 })\r\n\tpublic unitValue?: number;\r\n\r\n\t@prop({ required: true, type: Number, min: 0, max: 99999999 })\r\n\tpublic price!: number;\r\n}\r\n"]}
@@ -35,7 +35,6 @@ import { Setting } from './setting.model';
35
35
  import { ShopAccessControl } from './shop-access-control.model';
36
36
  import { ShopCategory } from './shop-category.model';
37
37
  import { ShopMealPlan } from './shop-meal-plan.model';
38
- import { ShopProduct } from './shop-product.model';
39
38
  import { ShopReview } from './shop-review.model';
40
39
  import { Shop } from './shop.model';
41
40
  import { SubscriptionSetting } from './subscription-setting.model';
@@ -55,6 +54,14 @@ import { PunchMarketing } from './providers/punch-marketing.model';
55
54
  import { ReferralCodeCoupon } from './providers/referral-code-coupon.model';
56
55
  import { ReferralRewardCoupon } from './providers/referral-reward-coupon.model';
57
56
  import { Notification } from './notification.model';
57
+ import { CoreAuthIdentity } from './core-auth-identity.model';
58
+ import { CoreEmailAuthIdentity } from './providers/core-email-auth-identity.model';
59
+ import { CorePhoneAuthIdentity } from './providers/core-phone-auth-identity.model';
60
+ import { CoreGoogleAuthIdentity } from './providers/core-google-auth-identity.model';
61
+ import { CoreAppleAuthIdentity } from './providers/core-apple-auth-identity.model';
62
+ import { CoreUser } from './core-user.model';
63
+ import { Card } from './card.model';
64
+ import { AreebaCard } from './providers/areeba-card.model';
58
65
  import { RiderTracking } from './rider-tracking.model';
59
66
  import { Rider } from './rider.model';
60
67
  import { RiderTimeout } from './rider-timeout.model';
@@ -78,8 +85,24 @@ export declare const BOBFinanceModel: ReturnModelType<typeof BOBFinance>;
78
85
  export * from './bob-finance.model';
79
86
  export declare const BrandModel: ReturnModelType<typeof Brand>;
80
87
  export * from './brand.model';
88
+ export declare const CardModel: ReturnModelType<typeof Card>;
89
+ export declare const AreebaCardModel: ReturnModelType<typeof AreebaCard>;
90
+ export * from './card.model';
91
+ export * from './providers/areeba-card.model';
81
92
  export declare const CategoryModel: ReturnModelType<typeof Category>;
82
93
  export * from './category.model';
94
+ export declare const CoreAuthIdentityModel: ReturnModelType<typeof CoreAuthIdentity>;
95
+ export declare const CoreEmailAuthIdentityModel: ReturnModelType<typeof CoreEmailAuthIdentity>;
96
+ export declare const CorePhoneAuthIdentityModel: ReturnModelType<typeof CorePhoneAuthIdentity>;
97
+ export declare const CoreGoogleAuthIdentityModel: ReturnModelType<typeof CoreGoogleAuthIdentity>;
98
+ export declare const CoreAppleAuthIdentityModel: ReturnModelType<typeof CoreAppleAuthIdentity>;
99
+ export * from './core-auth-identity.model';
100
+ export * from './providers/core-apple-auth-identity.model';
101
+ export * from './providers/core-email-auth-identity.model';
102
+ export * from './providers/core-google-auth-identity.model';
103
+ export * from './providers/core-phone-auth-identity.model';
104
+ export declare const CoreUserModel: ReturnModelType<typeof CoreUser>;
105
+ export * from './core-user.model';
83
106
  export declare const CounterModel: ReturnModelType<typeof Counter>;
84
107
  export * from './counter.model';
85
108
  export declare const CouponModel: ReturnModelType<typeof Coupon>;
@@ -166,8 +189,6 @@ export declare const ShopCategoryModel: ReturnModelType<typeof ShopCategory>;
166
189
  export * from './shop-category.model';
167
190
  export declare const ShopMealPlanModel: ReturnModelType<typeof ShopMealPlan>;
168
191
  export * from './shop-meal-plan.model';
169
- export declare const ShopProductModel: ReturnModelType<typeof ShopProduct>;
170
- export * from './shop-product.model';
171
192
  export declare const ShopReviewModel: ReturnModelType<typeof ShopReview>;
172
193
  export * from './shop-review.model';
173
194
  export declare const ShopModel: ReturnModelType<typeof Shop>;
@@ -14,8 +14,8 @@ 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.ShopAccessControlModel = exports.SettingModel = exports.RoleModel = exports.RiderModel = exports.RiderTrackingModel = exports.RiderTimeoutModel = exports.RiderReviewModel = exports.RequestAreaModel = exports.ReferralSettingModel = exports.RatingSettingModel = exports.PunchMarketingHistoryModel = exports.ProductModel = exports.ProductMarketingModel = exports.ParentModel = exports.NutritionModel = exports.NotificationModel = exports.MealPlanModel = exports.PunchMarketingModel = exports.LoyaltyPointMarketingModel = exports.FreeDeliveryMarketingModel = exports.FeaturedMarketingModel = exports.DiscountMarketingModel = exports.Buy1Get1MarketingModel = exports.MarketingModel = exports.LoyaltyPointSettingModel = exports.LoyaltyPointCategoryModel = exports.ListContainerModel = exports.FilterContainerModel = exports.FeaturedSettingModel = exports.FavouriteModel = exports.FaqModel = exports.DishModel = exports.DealSettingModel = exports.ReferralRewardCouponModel = exports.ReferralCodeCouponModel = exports.IndividualUserCouponModel = exports.IndividualStoreCouponModel = exports.GlobalCouponModel = exports.CustomCouponModel = exports.CouponModel = exports.CounterModel = exports.CategoryModel = exports.BrandModel = exports.BOBFinanceModel = exports.BannerModel = exports.AttributeModel = exports.AppScreenSettingModel = exports.AdminModel = exports.AdminAccessControlModel = exports.ActivityLogModel = void 0;
18
- exports.CartParticipantModel = exports.LineItemModel = exports.CartModel = exports.ZoneModel = exports.UserModel = exports.TagModel = exports.SubscriptionModel = exports.SubscriptionSettingModel = exports.ShopModel = exports.ShopReviewModel = exports.ShopProductModel = exports.ShopMealPlanModel = exports.ShopCategoryModel = void 0;
17
+ exports.ReferralSettingModel = exports.RatingSettingModel = exports.PunchMarketingHistoryModel = exports.ProductModel = exports.ProductMarketingModel = exports.ParentModel = exports.NutritionModel = exports.NotificationModel = exports.MealPlanModel = exports.PunchMarketingModel = exports.LoyaltyPointMarketingModel = exports.FreeDeliveryMarketingModel = exports.FeaturedMarketingModel = exports.DiscountMarketingModel = exports.Buy1Get1MarketingModel = exports.MarketingModel = exports.LoyaltyPointSettingModel = exports.LoyaltyPointCategoryModel = exports.ListContainerModel = exports.FilterContainerModel = exports.FeaturedSettingModel = exports.FavouriteModel = exports.FaqModel = exports.DishModel = exports.DealSettingModel = exports.ReferralRewardCouponModel = exports.ReferralCodeCouponModel = exports.IndividualUserCouponModel = exports.IndividualStoreCouponModel = exports.GlobalCouponModel = exports.CustomCouponModel = exports.CouponModel = exports.CounterModel = exports.CoreUserModel = exports.CoreAppleAuthIdentityModel = exports.CoreGoogleAuthIdentityModel = exports.CorePhoneAuthIdentityModel = exports.CoreEmailAuthIdentityModel = exports.CoreAuthIdentityModel = exports.CategoryModel = exports.AreebaCardModel = exports.CardModel = exports.BrandModel = exports.BOBFinanceModel = exports.BannerModel = exports.AttributeModel = exports.AppScreenSettingModel = exports.AdminModel = exports.AdminAccessControlModel = exports.ActivityLogModel = void 0;
18
+ exports.CartParticipantModel = exports.LineItemModel = exports.CartModel = exports.ZoneModel = exports.UserModel = exports.TagModel = exports.SubscriptionModel = exports.SubscriptionSettingModel = exports.ShopModel = exports.ShopReviewModel = exports.ShopMealPlanModel = exports.ShopCategoryModel = exports.ShopAccessControlModel = exports.SettingModel = exports.RoleModel = exports.RiderModel = exports.RiderTrackingModel = exports.RiderTimeoutModel = exports.RiderReviewModel = exports.RequestAreaModel = void 0;
19
19
  const typegoose_1 = require("@typegoose/typegoose");
20
20
  const admin_model_1 = require("./admin.model");
21
21
  const admin_access_control_model_1 = require("./admin-access-control.model");
@@ -54,7 +54,6 @@ const setting_model_1 = require("./setting.model");
54
54
  const shop_access_control_model_1 = require("./shop-access-control.model");
55
55
  const shop_category_model_1 = require("./shop-category.model");
56
56
  const shop_meal_plan_model_1 = require("./shop-meal-plan.model");
57
- const shop_product_model_1 = require("./shop-product.model");
58
57
  const shop_review_model_1 = require("./shop-review.model");
59
58
  const shop_model_1 = require("./shop.model");
60
59
  const subscription_setting_model_1 = require("./subscription-setting.model");
@@ -75,6 +74,14 @@ const punch_marketing_model_1 = require("./providers/punch-marketing.model");
75
74
  const referral_code_coupon_model_1 = require("./providers/referral-code-coupon.model");
76
75
  const referral_reward_coupon_model_1 = require("./providers/referral-reward-coupon.model");
77
76
  const notification_model_1 = require("./notification.model");
77
+ const core_auth_identity_model_1 = require("./core-auth-identity.model");
78
+ const core_email_auth_identity_model_1 = require("./providers/core-email-auth-identity.model");
79
+ const core_phone_auth_identity_model_1 = require("./providers/core-phone-auth-identity.model");
80
+ const core_google_auth_identity_model_1 = require("./providers/core-google-auth-identity.model");
81
+ const core_apple_auth_identity_model_1 = require("./providers/core-apple-auth-identity.model");
82
+ const core_user_model_1 = require("./core-user.model");
83
+ const card_model_1 = require("./card.model");
84
+ const areeba_card_model_1 = require("./providers/areeba-card.model");
78
85
  const rider_tracking_model_1 = require("./rider-tracking.model");
79
86
  const rider_model_1 = require("./rider.model");
80
87
  const rider_timeout_model_1 = require("./rider-timeout.model");
@@ -98,8 +105,24 @@ exports.BOBFinanceModel = (0, typegoose_1.getModelForClass)(bob_finance_model_1.
98
105
  __exportStar(require("./bob-finance.model"), exports);
99
106
  exports.BrandModel = (0, typegoose_1.getModelForClass)(brand_model_1.Brand);
100
107
  __exportStar(require("./brand.model"), exports);
108
+ exports.CardModel = (0, mongo_1.createGlobalModel)(card_model_1.Card);
109
+ exports.AreebaCardModel = (0, mongo_1.createGlobalDiscriminatorModel)(exports.CardModel, areeba_card_model_1.AreebaCard, enum_1.CardType.AREEBA);
110
+ __exportStar(require("./card.model"), exports);
111
+ __exportStar(require("./providers/areeba-card.model"), exports);
101
112
  exports.CategoryModel = (0, typegoose_1.getModelForClass)(category_model_1.Category);
102
113
  __exportStar(require("./category.model"), exports);
114
+ exports.CoreAuthIdentityModel = (0, mongo_1.createGlobalModel)(core_auth_identity_model_1.CoreAuthIdentity);
115
+ exports.CoreEmailAuthIdentityModel = (0, mongo_1.createGlobalDiscriminatorModel)(exports.CoreAuthIdentityModel, core_email_auth_identity_model_1.CoreEmailAuthIdentity, enum_1.CoreAuthIdentityType.EMAIL);
116
+ exports.CorePhoneAuthIdentityModel = (0, mongo_1.createGlobalDiscriminatorModel)(exports.CoreAuthIdentityModel, core_phone_auth_identity_model_1.CorePhoneAuthIdentity, enum_1.CoreAuthIdentityType.PHONE);
117
+ exports.CoreGoogleAuthIdentityModel = (0, mongo_1.createGlobalDiscriminatorModel)(exports.CoreAuthIdentityModel, core_google_auth_identity_model_1.CoreGoogleAuthIdentity, enum_1.CoreAuthIdentityType.GOOGLE);
118
+ exports.CoreAppleAuthIdentityModel = (0, mongo_1.createGlobalDiscriminatorModel)(exports.CoreAuthIdentityModel, core_apple_auth_identity_model_1.CoreAppleAuthIdentity, enum_1.CoreAuthIdentityType.APPLE);
119
+ __exportStar(require("./core-auth-identity.model"), exports);
120
+ __exportStar(require("./providers/core-apple-auth-identity.model"), exports);
121
+ __exportStar(require("./providers/core-email-auth-identity.model"), exports);
122
+ __exportStar(require("./providers/core-google-auth-identity.model"), exports);
123
+ __exportStar(require("./providers/core-phone-auth-identity.model"), exports);
124
+ exports.CoreUserModel = (0, mongo_1.createGlobalModel)(core_user_model_1.CoreUser);
125
+ __exportStar(require("./core-user.model"), exports);
103
126
  exports.CounterModel = (0, typegoose_1.getModelForClass)(counter_model_1.Counter);
104
127
  __exportStar(require("./counter.model"), exports);
105
128
  exports.CouponModel = (0, typegoose_1.getModelForClass)(coupon_model_1.Coupon);
@@ -186,8 +209,6 @@ exports.ShopCategoryModel = (0, typegoose_1.getModelForClass)(shop_category_mode
186
209
  __exportStar(require("./shop-category.model"), exports);
187
210
  exports.ShopMealPlanModel = (0, typegoose_1.getModelForClass)(shop_meal_plan_model_1.ShopMealPlan);
188
211
  __exportStar(require("./shop-meal-plan.model"), exports);
189
- exports.ShopProductModel = (0, typegoose_1.getModelForClass)(shop_product_model_1.ShopProduct);
190
- __exportStar(require("./shop-product.model"), exports);
191
212
  exports.ShopReviewModel = (0, typegoose_1.getModelForClass)(shop_review_model_1.ShopReview);
192
213
  __exportStar(require("./shop-review.model"), exports);
193
214
  exports.ShopModel = (0, typegoose_1.getModelForClass)(shop_model_1.Shop);