@lyxa.ai/core 1.0.383 → 1.0.384

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 CHANGED
@@ -28,6 +28,7 @@ const settings_1 = require("./libraries/cache/settings");
28
28
  const fcmService_1 = require("./libraries/firebase/fcmService");
29
29
  const bull_mq_service_1 = require("./libraries/bullmq/bull-mq-service");
30
30
  const cash_settlement_1 = require("./libraries/cash-settlement");
31
+ const socket_1 = require("./libraries/socket");
31
32
  var EnvironmentConfigurationType_2 = require("./libraries/configuration/types/EnvironmentConfigurationType");
32
33
  Object.defineProperty(exports, "EnvironmentConfigurationType", { enumerable: true, get: function () { return EnvironmentConfigurationType_2.EnvironmentConfigurationType; } });
33
34
  var mongo_2 = require("./libraries/mongo");
@@ -38,6 +39,7 @@ async function bootstrapCore(options) {
38
39
  getLibraries().getLogger().logger.info('Successfully bootstrapped lyxa-core.');
39
40
  const gracefulShutdown = async () => {
40
41
  getLibraries().getLogger().logger.info('Received shutdown signal, shutting down gracefully...');
42
+ await (0, socket_1.disconnectAllEntitiesFromInstance)();
41
43
  process.exit();
42
44
  };
43
45
  process.on('SIGTERM', gracefulShutdown);
@@ -64,7 +66,9 @@ async function registerLibraries(options) {
64
66
  typedi_1.Container.set(secrets_1.SecretManagerService, secretInstance);
65
67
  const bullMQInstance = new bull_mq_service_1.BullMQService(redisInstance);
66
68
  typedi_1.Container.set(bull_mq_service_1.BullMQService, bullMQInstance);
67
- const mongoUrl = options?.mongoDbUrl ? options.mongoDbUrl : await getLibraries().getSecretsService().getKey('MONGO_URL');
69
+ const mongoUrl = options?.mongoDbUrl
70
+ ? options.mongoDbUrl
71
+ : await getLibraries().getSecretsService().getKey('MONGO_URL');
68
72
  await mongoose_1.default.connect(mongoUrl, {
69
73
  dbName: `lyxa-${options.environment}-${options.tenet}`,
70
74
  maxPoolSize: 20,
@@ -78,7 +82,7 @@ async function registerLibraries(options) {
78
82
  serverSelectionTimeoutMS: 5000,
79
83
  heartbeatFrequencyMS: 10000,
80
84
  bufferCommands: false,
81
- compressors: ['zlib']
85
+ compressors: ['zlib'],
82
86
  });
83
87
  mongoose_1.default.set('debug', options?.mongooseDebug !== undefined
84
88
  ? options?.mongooseDebug
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;AAkCA,sCAyBC;AAED,8CAgHC;AAED,oCAEC;AAhLD,qFAAqF;AACrF,IAAA,0CAAqB,GAAE,CAAC;AAExB,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;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,gEAKyC;AACzC,wEAAmE;AACnE,iEAA4F;AAI5F,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,OAAO,CAAC,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;QACxC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACvC,OAAO,C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AO,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';\napplySoftDeletePlugin();\n\nimport { LibraryManager } from './libraries';\nimport { Container } from 'typedi';\nimport mongoose from 'mongoose';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection } 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 { RedisUrlMap } from './utilities/environment/redis-environments';\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\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\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 ? options.mongoDbUrl : await getLibraries().getSecretsService().getKey('MONGO_URL');\t\n\n\tawait mongoose.connect(mongoUrl!, {\n\t\tdbName: `lyxa-${options!.environment}-${options!.tenet}`,\n\t\tmaxPoolSize: 20,\n\t\tminPoolSize: 4,\n\t\tmaxIdleTimeMS: 30000,\n\t\twaitQueueTimeoutMS: 10000,\n\t\tretryWrites: true,\n\t\tw: 1,\n\t\treadPreference: 'primary',\n \treadConcern: { level: 'local' },\n\t\tserverSelectionTimeoutMS: 5000,\n\t\theartbeatFrequencyMS: 10000,\n\t\tbufferCommands: false,\n\t\tcompressors: ['zlib'] // Reduces network traffic\n\t});\n\tmongoose.set(\n\t\t'debug',\n\t\toptions?.mongooseDebug !== undefined\n\t\t\t? options?.mongooseDebug\n\t\t\t: getLibraries().getConfigurationService().options.environment == EnvironmentConfigurationType.DEV\n\t);\n\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}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;AAmCA,sCA0BC;AAED,8CAiHC;AAED,oCAEC;AAnLD,qFAAqF;AAErF,IAAA,0CAAqB,GAAE,CAAC;AAExB,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;AACvF,yCAAgE;AAChE,yDAAmE;AACnE,gEAKyC;AACzC,wEAAmE;AACnE,iEAA4F;AAC5F,+CAAuE;AAGvE,6GAA4G;AAAnG,4IAAA,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AAO,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 mongoose from 'mongoose';\nimport { ConfigurationOptions, ConfigurationService } from './libraries/configuration';\nimport { EnvironmentConfigurationType } from './libraries/configuration/types/EnvironmentConfigurationType';\nimport { LyxaLogger } from './libraries/logger';\nimport { RedisService } from './libraries/redis';\nimport { initGlobalConnection } 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\tawait 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 mongoose.connect(mongoUrl!, {\n\t\tdbName: `lyxa-${options!.environment}-${options!.tenet}`,\n\t\tmaxPoolSize: 20,\n\t\tminPoolSize: 4,\n\t\tmaxIdleTimeMS: 30000,\n\t\twaitQueueTimeoutMS: 10000,\n\t\tretryWrites: true,\n\t\tw: 1,\n\t\treadPreference: 'primary',\n\t\treadConcern: { level: 'local' },\n\t\tserverSelectionTimeoutMS: 5000,\n\t\theartbeatFrequencyMS: 10000,\n\t\tbufferCommands: false,\n\t\tcompressors: ['zlib'], // Reduces network traffic\n\t});\n\tmongoose.set(\n\t\t'debug',\n\t\toptions?.mongooseDebug !== undefined\n\t\t\t? options?.mongooseDebug\n\t\t\t: getLibraries().getConfigurationService().options.environment == EnvironmentConfigurationType.DEV\n\t);\n\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}\n"]}
@@ -39,24 +39,21 @@ async function disconnectAllEntitiesFromInstance() {
39
39
  const instanceId = (0, instance_utils_1.getInstanceId)();
40
40
  const redis = (0, __1.getLibraries)().getRedisService();
41
41
  const connectedEntities = await redis.getSetMembers((0, exports.kEntityConnection)());
42
- if (connectedEntities.length === 0)
42
+ if (!connectedEntities.length)
43
43
  return;
44
44
  for (const entityId of connectedEntities) {
45
45
  const allEvents = await redis.getSetMembers((0, exports.kEntityEvents)(entityId));
46
- if (allEvents.length === 0)
46
+ if (!allEvents.length)
47
47
  continue;
48
- const eventsToKeep = [];
49
- for (const e of allEvents) {
48
+ const eventsToKeep = allEvents.filter(e => {
50
49
  const parsed = JSON.parse(e);
51
- if (parsed.instanceId === instanceId) {
52
- await redis.removeFromSet((0, exports.kEntityEvents)(entityId), e);
53
- }
54
- else {
55
- eventsToKeep.push(e);
56
- }
50
+ return parsed.instanceId !== instanceId;
51
+ });
52
+ const eventsToRemove = allEvents.filter(e => !eventsToKeep.includes(e));
53
+ for (const e of eventsToRemove) {
54
+ await redis.removeFromSet((0, exports.kEntityEvents)(entityId), e);
57
55
  }
58
- const stillOnInstance = eventsToKeep.some(e => JSON.parse(e).instanceId === instanceId);
59
- if (!stillOnInstance) {
56
+ if (!eventsToKeep.some(e => JSON.parse(e).instanceId === instanceId)) {
60
57
  await redis.removeFromSet((0, exports.kEntityInstances)(entityId), instanceId);
61
58
  }
62
59
  if (eventsToKeep.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"socket-redis-connections.js","sourceRoot":"/","sources":["libraries/socket/core/socket-redis-connections.ts"],"names":[],"mappings":";;;AAaA,gEASC;AAED,0EAmBC;AAED,gDAIC;AAED,8EAgCC;AAnF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,MAAM,KAAK,CAAC,aAAa,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,CAAC,CAAC;QACrE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAErC,MAAM,YAAY,GAAa,EAAE,CAAC;QAElC,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAgC,CAAC;YAC5D,IAAI,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;gBACtC,MAAM,KAAK,CAAC,aAAa,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;YACvD,CAAC;iBAAM,CAAC;gBACP,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtB,CAAC;QACF,CAAC;QAED,MAAM,eAAe,GAAG,YAAY,CAAC,IAAI,CACxC,CAAC,CAAC,EAAE,CAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAiC,CAAC,UAAU,KAAK,UAAU,CAC7E,CAAC;QACF,IAAI,CAAC,eAAe,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC,aAAa,CAAC,IAAA,wBAAgB,EAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,KAAK,CAAC,aAAa,CAAC,IAAA,yBAAiB,GAAE,EAAE,QAAQ,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { getLibraries } from '../../..';\nimport { getInstanceId } from '../../../utilities/instance.utils';\n\nexport const kEntityEvents = (entityId: string) => `socket:events:entity:${entityId}`;\nexport const kEntityInstances = (entityId: string) => `socket:instances:entity:${entityId}`;\nexport const kEntityConnection = () => `socket:connections`;\n\nexport interface SocketRedisEventInformation {\n\teventKey: string;\n\tinstanceId: string;\n\tsocketId: string;\n}\n\nexport async function connectEntityToSocketEvent(\n\tentityId: string,\n\tsocketRedisEventInformation: SocketRedisEventInformation\n) {\n\tconst redis = getLibraries().getRedisService();\n\n\tawait redis.addToSet(kEntityEvents(entityId), JSON.stringify(socketRedisEventInformation));\n\tawait redis.addToSet(kEntityInstances(entityId), socketRedisEventInformation.instanceId);\n\tawait redis.addToSet(kEntityConnection(), entityId);\n}\n\nexport async function disconnectEntityFromSocketEvent(\n\tentityId: string,\n\tsocketRedisEventInformation: SocketRedisEventInformation\n) {\n\tconst redis = getLibraries().getRedisService();\n\n\tawait redis.removeFromSet(kEntityEvents(entityId), JSON.stringify(socketRedisEventInformation));\n\n\tconst remainingEvents = (await redis.getSetMembers(kEntityEvents(entityId))).map(\n\t\tr => JSON.parse(r) as SocketRedisEventInformation\n\t);\n\n\tif (remainingEvents.filter(e => e.instanceId === socketRedisEventInformation.instanceId).length === 0) {\n\t\tawait redis.removeFromSet(kEntityInstances(entityId), socketRedisEventInformation.instanceId);\n\t}\n\n\tif (remainingEvents.length === 0) {\n\t\tawait redis.removeFromSet(kEntityConnection(), entityId);\n\t}\n}\n\nexport async function isEntitySubscribed(entityId: string, eventKey: string): Promise<boolean> {\n\tconst redis = getLibraries().getRedisService();\n\tconst events = await redis.getSetMembers(kEntityEvents(entityId));\n\treturn events.map(e => JSON.parse(e) as SocketRedisEventInformation).some(e => e.eventKey === eventKey);\n}\n\nexport async function disconnectAllEntitiesFromInstance() {\n\tconst instanceId = getInstanceId();\n\tconst redis = getLibraries().getRedisService();\n\n\tconst connectedEntities = await redis.getSetMembers(kEntityConnection());\n\tif (connectedEntities.length === 0) return;\n\n\tfor (const entityId of connectedEntities) {\n\t\tconst allEvents = await redis.getSetMembers(kEntityEvents(entityId));\n\t\tif (allEvents.length === 0) continue;\n\n\t\tconst eventsToKeep: string[] = [];\n\n\t\tfor (const e of allEvents) {\n\t\t\tconst parsed = JSON.parse(e) as SocketRedisEventInformation;\n\t\t\tif (parsed.instanceId === instanceId) {\n\t\t\t\tawait redis.removeFromSet(kEntityEvents(entityId), e);\n\t\t\t} else {\n\t\t\t\teventsToKeep.push(e);\n\t\t\t}\n\t\t}\n\n\t\tconst stillOnInstance = eventsToKeep.some(\n\t\t\te => (JSON.parse(e) as SocketRedisEventInformation).instanceId === instanceId\n\t\t);\n\t\tif (!stillOnInstance) {\n\t\t\tawait redis.removeFromSet(kEntityInstances(entityId), instanceId);\n\t\t}\n\t\tif (eventsToKeep.length === 0) {\n\t\t\tawait redis.removeFromSet(kEntityConnection(), entityId);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"socket-redis-connections.js","sourceRoot":"/","sources":["libraries/socket/core/socket-redis-connections.ts"],"names":[],"mappings":";;;AAaA,gEASC;AAED,0EAmBC;AAED,gDAIC;AAED,8EA6BC;AAhFD,gCAAwC;AACxC,sEAAkE;AAE3D,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,wBAAwB,QAAQ,EAAE,CAAC;AAAzE,QAAA,aAAa,iBAA4D;AAC/E,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,2BAA2B,QAAQ,EAAE,CAAC;AAA/E,QAAA,gBAAgB,oBAA+D;AACrF,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,oBAAoB,CAAC;AAA/C,QAAA,iBAAiB,qBAA8B;AAQrD,KAAK,UAAU,0BAA0B,CAC/C,QAAgB,EAChB,2BAAwD;IAExD,MAAM,KAAK,GAAG,IAAA,gBAAY,GAAE,CAAC,eAAe,EAAE,CAAC;IAE/C,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC,CAAC;IAC3F,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAA,wBAAgB,EAAC,QAAQ,CAAC,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;IACzF,MAAM,KAAK,CAAC,QAA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CAAC,EAAE,CAAC;YACvG,MAAM,KAAK,CAAC,aAAa,CAAC,IAAA,wBAAgB,EAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,MAAM,KAAK,CAAC,aAAa,CAAC,IAAA,yBAAiB,GAAE,EAAE,QAAQ,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { getLibraries } from '../../..';\nimport { getInstanceId } from '../../../utilities/instance.utils';\n\nexport const kEntityEvents = (entityId: string) => `socket:events:entity:${entityId}`;\nexport const kEntityInstances = (entityId: string) => `socket:instances:entity:${entityId}`;\nexport const kEntityConnection = () => `socket:connections`;\n\nexport interface SocketRedisEventInformation {\n\teventKey: string;\n\tinstanceId: string;\n\tsocketId: string;\n}\n\nexport async function connectEntityToSocketEvent(\n\tentityId: string,\n\tsocketRedisEventInformation: SocketRedisEventInformation\n) {\n\tconst redis = getLibraries().getRedisService();\n\n\tawait redis.addToSet(kEntityEvents(entityId), JSON.stringify(socketRedisEventInformation));\n\tawait redis.addToSet(kEntityInstances(entityId), socketRedisEventInformation.instanceId);\n\tawait redis.addToSet(kEntityConnection(), entityId);\n}\n\nexport async function disconnectEntityFromSocketEvent(\n\tentityId: string,\n\tsocketRedisEventInformation: SocketRedisEventInformation\n) {\n\tconst redis = getLibraries().getRedisService();\n\n\tawait redis.removeFromSet(kEntityEvents(entityId), JSON.stringify(socketRedisEventInformation));\n\n\tconst remainingEvents = (await redis.getSetMembers(kEntityEvents(entityId))).map(\n\t\tr => JSON.parse(r) as SocketRedisEventInformation\n\t);\n\n\tif (remainingEvents.filter(e => e.instanceId === socketRedisEventInformation.instanceId).length === 0) {\n\t\tawait redis.removeFromSet(kEntityInstances(entityId), socketRedisEventInformation.instanceId);\n\t}\n\n\tif (remainingEvents.length === 0) {\n\t\tawait redis.removeFromSet(kEntityConnection(), entityId);\n\t}\n}\n\nexport async function isEntitySubscribed(entityId: string, eventKey: string): Promise<boolean> {\n\tconst redis = getLibraries().getRedisService();\n\tconst events = await redis.getSetMembers(kEntityEvents(entityId));\n\treturn events.map(e => JSON.parse(e) as SocketRedisEventInformation).some(e => e.eventKey === eventKey);\n}\n\nexport async function disconnectAllEntitiesFromInstance() {\n\tconst instanceId = getInstanceId();\n\tconst redis = getLibraries().getRedisService();\n\n\tconst connectedEntities = await redis.getSetMembers(kEntityConnection());\n\tif (!connectedEntities.length) return;\n\n\tfor (const entityId of connectedEntities) {\n\t\tconst allEvents = await redis.getSetMembers(kEntityEvents(entityId));\n\t\tif (!allEvents.length) continue;\n\n\t\tconst eventsToKeep = allEvents.filter(e => {\n\t\t\tconst parsed = JSON.parse(e) as SocketRedisEventInformation;\n\t\t\treturn parsed.instanceId !== instanceId;\n\t\t});\n\n\t\tconst eventsToRemove = allEvents.filter(e => !eventsToKeep.includes(e));\n\t\tfor (const e of eventsToRemove) {\n\t\t\tawait redis.removeFromSet(kEntityEvents(entityId), e);\n\t\t}\n\n\t\tif (!eventsToKeep.some(e => (JSON.parse(e) as SocketRedisEventInformation).instanceId === instanceId)) {\n\t\t\tawait redis.removeFromSet(kEntityInstances(entityId), instanceId);\n\t\t}\n\n\t\tif (eventsToKeep.length === 0) {\n\t\t\tawait redis.removeFromSet(kEntityConnection(), entityId);\n\t\t}\n\t}\n}\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.0.383
25
+ Version: 1.0.384
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.0.383",
3
+ "version": "1.0.384",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.0.383",
3
+ "version": "1.0.384",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",