@lyxa.ai/core 1.1.22 → 1.1.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 (53) hide show
  1. package/dist/libraries/event/index.d.ts +3 -3
  2. package/dist/libraries/event/index.js +18 -61
  3. package/dist/libraries/event/index.js.map +1 -1
  4. package/dist/libraries/mongo/models/user.model.d.ts +1 -1
  5. package/dist/libraries/socket/BaseSocketEvent.d.ts +4 -1
  6. package/dist/libraries/socket/BaseSocketEvent.js +4 -4
  7. package/dist/libraries/socket/BaseSocketEvent.js.map +1 -1
  8. package/dist/libraries/socket/PushNotificationEvent.d.ts +13 -0
  9. package/dist/libraries/socket/PushNotificationEvent.js +20 -0
  10. package/dist/libraries/socket/PushNotificationEvent.js.map +1 -0
  11. package/dist/libraries/socket/core/socket-event-consumer.d.ts +1 -0
  12. package/dist/libraries/socket/core/socket-event-consumer.js +27 -0
  13. package/dist/libraries/socket/core/socket-event-consumer.js.map +1 -0
  14. package/dist/libraries/socket/core/socket-event-publisher.d.ts +4 -0
  15. package/dist/libraries/socket/core/socket-event-publisher.js +68 -0
  16. package/dist/libraries/socket/core/socket-event-publisher.js.map +1 -0
  17. package/dist/libraries/socket/core/socket-event-registry.d.ts +1 -1
  18. package/dist/libraries/socket/core/socket-event-registry.js +1 -1
  19. package/dist/libraries/socket/core/socket-event-registry.js.map +1 -1
  20. package/dist/libraries/socket/{socket-event-registry.map.d.ts → core/socket-event-registry.map.d.ts} +33 -19
  21. package/dist/libraries/socket/core/socket-event-registry.map.js +33 -0
  22. package/dist/libraries/socket/core/socket-event-registry.map.js.map +1 -0
  23. package/dist/libraries/socket/events/chatlist-message-send.socket.event.d.ts +5 -4
  24. package/dist/libraries/socket/events/chatlist-message-send.socket.event.js +10 -7
  25. package/dist/libraries/socket/events/chatlist-message-send.socket.event.js.map +1 -1
  26. package/dist/libraries/socket/events/chatroom-message-send.socket.event.d.ts +10 -5
  27. package/dist/libraries/socket/events/chatroom-message-send.socket.event.js +17 -7
  28. package/dist/libraries/socket/events/chatroom-message-send.socket.event.js.map +1 -1
  29. package/dist/libraries/socket/events/notification.socket.event.d.ts +25 -0
  30. package/dist/libraries/socket/events/notification.socket.event.js +22 -0
  31. package/dist/libraries/socket/events/notification.socket.event.js.map +1 -0
  32. package/dist/libraries/socket/events/ticket-assign.socket.event.d.ts +5 -4
  33. package/dist/libraries/socket/events/ticket-assign.socket.event.js +4 -4
  34. package/dist/libraries/socket/events/ticket-assign.socket.event.js.map +1 -1
  35. package/dist/libraries/socket/events/ticket-unassign.socket.event.d.ts +5 -4
  36. package/dist/libraries/socket/events/ticket-unassign.socket.event.js +7 -4
  37. package/dist/libraries/socket/events/ticket-unassign.socket.event.js.map +1 -1
  38. package/dist/libraries/trpc/middlewares/createSocketSubscriptionProcedure.d.ts +1 -1
  39. package/dist/types/README.md +1 -1
  40. package/dist/types/package.json +1 -1
  41. package/dist/types/utilities/enum.d.ts +5 -1
  42. package/dist/types/utilities/enum.js +6 -1
  43. package/dist/types/utilities/enum.js.map +1 -1
  44. package/dist/types/utilities/validation/common-validation.d.ts +78 -2
  45. package/dist/types/utilities/validation/global-validation.d.ts +38 -14
  46. package/dist/utilities/enum.d.ts +5 -1
  47. package/dist/utilities/enum.js +6 -1
  48. package/dist/utilities/enum.js.map +1 -1
  49. package/dist/utilities/validation/common-validation.d.ts +78 -2
  50. package/dist/utilities/validation/global-validation.d.ts +38 -14
  51. package/package.json +1 -1
  52. package/dist/libraries/socket/socket-event-registry.map.js +0 -28
  53. package/dist/libraries/socket/socket-event-registry.map.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import amqp from 'amqplib';
2
2
  import { BaseEvent } from './BaseEvent';
3
- import { BaseSocketEvent } from '../socket/BaseSocketEvent';
3
+ export declare const EXCHANGE_NAME = "lyxa.events";
4
+ export declare const INSTANCE_ROUTE_PREFIX = "instance";
4
5
  export declare function initEventBus(rabbitUrl: string): Promise<void>;
6
+ export declare function getChannel(): amqp.Channel;
5
7
  export declare function publishEvent<TPayload extends Record<string, unknown>>(event: BaseEvent<TPayload>): Promise<void>;
6
8
  export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>): Promise<void>;
7
- export declare function subscribeToSocketEvent(): Promise<amqp.Channel>;
8
- export declare function publishSocketEvent(event: BaseSocketEvent<any, any>, recipients: string[]): Promise<void>;
9
9
  export declare function closeEventBus(): Promise<void>;
@@ -3,102 +3,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.INSTANCE_ROUTE_PREFIX = exports.EXCHANGE_NAME = void 0;
6
7
  exports.initEventBus = initEventBus;
8
+ exports.getChannel = getChannel;
7
9
  exports.publishEvent = publishEvent;
8
10
  exports.subscribeToEvent = subscribeToEvent;
9
- exports.subscribeToSocketEvent = subscribeToSocketEvent;
10
- exports.publishSocketEvent = publishSocketEvent;
11
11
  exports.closeEventBus = closeEventBus;
12
12
  const amqplib_1 = __importDefault(require("amqplib"));
13
13
  const instance_utils_1 = require("../../utilities/instance.utils");
14
- const index_1 = require("../../index");
15
- const local_subscription_registry_1 = require("../socket/core/local-subscription-registry");
16
- const socket_redis_connections_1 = require("../socket/core/socket-redis-connections");
17
14
  let connection;
18
15
  let channel;
19
- const EXCHANGE_NAME = 'lyxa.events';
20
- const INSTANCE_ROUTE_PREFIX = 'instance';
16
+ exports.EXCHANGE_NAME = 'lyxa.events';
17
+ exports.INSTANCE_ROUTE_PREFIX = 'instance';
21
18
  async function initEventBus(rabbitUrl) {
22
19
  connection = await amqplib_1.default.connect(rabbitUrl);
23
20
  channel = await connection.createChannel();
24
- await channel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });
21
+ await channel.assertExchange(exports.EXCHANGE_NAME, 'topic', { durable: true });
25
22
  console.log(`EventBus initialized with instance ID: ${(0, instance_utils_1.getInstanceId)()}`);
26
23
  }
27
- async function publishEvent(event) {
24
+ function getChannel() {
28
25
  if (!channel)
29
26
  throw new Error('Channel not initialized. Call initEventBus first.');
27
+ return channel;
28
+ }
29
+ async function publishEvent(event) {
30
+ const ch = getChannel();
30
31
  const messageBuffer = Buffer.from(JSON.stringify(event.payload));
31
- channel.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {
32
+ ch.publish(exports.EXCHANGE_NAME, event.eventId, messageBuffer, {
32
33
  contentType: 'application/json',
33
34
  });
34
35
  console.log(`Published event [${event.eventId}] with payload`, event.payload);
35
36
  }
36
37
  async function subscribeToEvent(eventId, onMessage) {
37
- if (!channel)
38
- throw new Error('Channel not initialized. Call initEventBus first.');
38
+ const ch = getChannel();
39
39
  const queueName = `${eventId}-${(0, instance_utils_1.getInstanceId)()}`;
40
- await channel.assertQueue(queueName, {
40
+ await ch.assertQueue(queueName, {
41
41
  durable: false,
42
42
  exclusive: true,
43
43
  autoDelete: true,
44
44
  });
45
- await channel.bindQueue(queueName, EXCHANGE_NAME, eventId);
46
- await channel.consume(queueName, async (msg) => {
45
+ await ch.bindQueue(queueName, exports.EXCHANGE_NAME, eventId);
46
+ await ch.consume(queueName, async (msg) => {
47
47
  if (msg !== null) {
48
- const payloadString = msg.content.toString();
49
- const payload = JSON.parse(payloadString);
48
+ const payload = JSON.parse(msg.content.toString());
50
49
  try {
51
50
  await onMessage(payload);
52
- channel.ack(msg);
51
+ ch.ack(msg);
53
52
  }
54
53
  catch (err) {
55
54
  console.error(`Error handling event [${eventId}] on instance [${(0, instance_utils_1.getInstanceId)()}]`, err);
56
55
  }
57
56
  }
58
57
  }, { noAck: false });
59
- console.log(`Subscribed to event [${eventId}] on queue [${queueName}] for instance [${(0, instance_utils_1.getInstanceId)()}]`);
60
- }
61
- async function subscribeToSocketEvent() {
62
- const queueName = `socket-events-${(0, instance_utils_1.getInstanceId)()}`;
63
- await channel.assertQueue(queueName, { durable: true });
64
- await channel.bindQueue(queueName, EXCHANGE_NAME, `instance.${(0, instance_utils_1.getInstanceId)()}`);
65
- await channel.consume(queueName, msg => {
66
- if (!msg)
67
- return;
68
- try {
69
- const { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));
70
- local_subscription_registry_1.LocalSubs.emit(recipient, localKey, payload);
71
- channel.ack(msg);
72
- }
73
- catch (e) {
74
- console.error('Failed to handle instance event', e);
75
- channel.nack(msg, false, false);
76
- }
77
- });
78
- return channel;
79
- }
80
- async function publishSocketEvent(event, recipients) {
81
- const redisService = (0, index_1.getLibraries)().getRedisService();
82
- const localKey = event.getSubscriptionKey();
83
- const payload = event.payload();
84
- for (const recipient of recipients) {
85
- const isSub = await (0, socket_redis_connections_1.isEntitySubscribed)(recipient, localKey);
86
- if (!isSub) {
87
- continue;
88
- }
89
- const instanceNames = await redisService.getSetMembers((0, socket_redis_connections_1.kEntityInstances)(recipient));
90
- if (!instanceNames.length) {
91
- continue;
92
- }
93
- for (const instanceName of instanceNames) {
94
- const routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}`;
95
- const messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');
96
- channel.publish(EXCHANGE_NAME, routingKey, messageBuffer, {
97
- contentType: 'application/json',
98
- persistent: true,
99
- });
100
- }
101
- }
58
+ console.log(`Subscribed to event [${eventId}] on queue [${queueName}]`);
102
59
  }
103
60
  async function closeEventBus() {
104
61
  if (channel)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;AAaA,oCAKC;AAED,oCASC;AAED,4CA6BC;AAED,wDAkBC;AACD,gDAiCC;AAED,sCAIC;AAxHD,sDAA2B;AAE3B,mEAA+D;AAE/D,uCAA2C;AAC3C,4FAAuE;AACvE,sFAA8G;AAE9G,IAAI,UAA6B,CAAC;AAClC,IAAI,OAAqB,CAAC;AAC1B,MAAM,aAAa,GAAG,aAAa,CAAC;AACpC,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAElC,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C,CAAC;YAC5F,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE;gBACzD,WAAW,EAAE,kBAAkB;gBAC/B,UAAU,EAAE,IAAI;aAChB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC;AAEM,KAAK,UAAU,aAAa;IAClC,IAAI,OAAO;QAAE,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACnC,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAA,8BAAa,GAAE,GAAG,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\nimport { BaseSocketEvent } from '../socket/BaseSocketEvent';\nimport { getLibraries } from '../../index';\nimport { LocalSubs } from '../socket/core/local-subscription-registry';\nimport { isEntitySubscribed, kEntityEvents, kEntityInstances } from '../socket/core/socket-redis-connections';\n\nlet connection: amqp.ChannelModel;\nlet channel: amqp.Channel;\nconst EXCHANGE_NAME = 'lyxa.events';\nconst INSTANCE_ROUTE_PREFIX = 'instance'; // routing key: instance.{instanceName}.{eventType}\n\nexport async function initEventBus(rabbitUrl: string) {\n\tconnection = await amqp.connect(rabbitUrl);\n\tchannel = await connection.createChannel();\n\tawait channel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nexport async function publishEvent<TPayload extends Record<string, unknown>>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tif (!channel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tchannel.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t});\n\tconsole.log(`Published event [${event.eventId}] with payload`, event.payload);\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>\n): Promise<void> {\n\tif (!channel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tconst queueName = `${eventId}-${getInstanceId()}`;\n\tawait channel.assertQueue(queueName, {\n\t\tdurable: false,\n\t\texclusive: true,\n\t\tautoDelete: true,\n\t});\n\tawait channel.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\tawait channel.consume(\n\t\tqueueName,\n\t\tasync msg => {\n\t\t\tif (msg !== null) {\n\t\t\t\tconst payloadString = msg.content.toString();\n\t\t\t\tconst payload = JSON.parse(payloadString);\n\t\t\t\ttry {\n\t\t\t\t\tawait onMessage(payload);\n\t\t\t\t\tchannel.ack(msg);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(`Error handling event [${eventId}] on instance [${getInstanceId()}]`, err);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{ noAck: false }\n\t);\n\tconsole.log(`Subscribed to event [${eventId}] on queue [${queueName}] for instance [${getInstanceId()}]`);\n}\n\nexport async function subscribeToSocketEvent() {\n\tconst queueName = `socket-events-${getInstanceId()}`;\n\tawait channel.assertQueue(queueName, { durable: true });\n\tawait channel.bindQueue(queueName, EXCHANGE_NAME, `instance.${getInstanceId()}`);\n\n\tawait channel.consume(queueName, msg => {\n\t\tif (!msg) return;\n\t\ttry {\n\t\t\tconst { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));\n\t\t\tLocalSubs.emit(recipient, localKey, payload);\n\t\t\tchannel.ack(msg);\n\t\t} catch (e) {\n\t\t\tconsole.error('Failed to handle instance event', e);\n\t\t\tchannel.nack(msg, false, false);\n\t\t}\n\t});\n\n\treturn channel;\n}\nexport async function publishSocketEvent(\n\tevent: BaseSocketEvent<any, any>,\n\trecipients: string[]\n): Promise<void> {\n\tconst redisService = getLibraries().getRedisService();\n\tconst localKey = event.getSubscriptionKey();\n\tconst payload = event.payload();\n\n\tfor (const recipient of recipients) {\n\t\tconst isSub = await isEntitySubscribed(recipient, localKey);\n\t\tif (!isSub) {\n\t\t\t// Not subscribed → push notification fallback\n\t\t\t// TODO: queue push notification for { recipient, eventType, payload }\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst instanceNames = await redisService.getSetMembers(kEntityInstances(recipient));\n\t\tif (!instanceNames.length) {\n\t\t\t// No active instances → push notification fallback\n\t\t\t// TODO: queue push notification for { recipient, eventType, payload }\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Publish to every instance with routing\n\t\tfor (const instanceName of instanceNames) {\n\t\t\tconst routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}`;\n\t\t\tconst messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');\n\t\t\tchannel.publish(EXCHANGE_NAME, routingKey, messageBuffer, {\n\t\t\t\tcontentType: 'application/json',\n\t\t\t\tpersistent: true,\n\t\t\t});\n\t\t}\n\t}\n}\n\nexport async function closeEventBus(): Promise<void> {\n\tif (channel) await channel.close();\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;;AASA,oCAKC;AAED,gCAGC;AAED,oCASC;AAED,4CAgCC;AAED,sCAIC;AAtED,sDAA2B;AAE3B,mEAA+D;AAE/D,IAAI,UAA6B,CAAC;AAClC,IAAI,OAAqB,CAAC;AACb,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9B,QAAA,qBAAqB,GAAG,UAAU,CAAC;AAEzC,KAAK,UAAU,YAAY,CAAC,SAAiB;IACnD,UAAU,GAAG,MAAM,iBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,OAAO,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;IAC3C,MAAM,OAAO,CAAC,cAAc,CAAC,qBAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC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,CAAC,CAAC;YACnD,IAAI,CAAC;gBACJ,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;gBACzB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACb,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,OAAO,CAAC,KAAK,CAAC,yBAAyB,OAAO,kBAAkB,IAAA,8BAAa,GAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YAC1F,CAAC;QACF,CAAC;IACF,CAAC,EACD,EAAE,KAAK,EAAE,KAAK,EAAE,CAChB,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,wBAAwB,OAAO,eAAe,SAAS,GAAG,CAAC,CAAC;AACzE,CAAC;AAEM,KAAK,UAAU,aAAa;IAClC,IAAI,OAAO;QAAE,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACnC,IAAI,UAAU;QAAE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAA,8BAAa,GAAE,GAAG,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\n\nlet connection: amqp.ChannelModel;\nlet channel: amqp.Channel;\nexport const EXCHANGE_NAME = 'lyxa.events';\nexport const INSTANCE_ROUTE_PREFIX = 'instance'; // routing key: instance.{instanceName}.{eventType}\n\nexport async function initEventBus(rabbitUrl: string) {\n\tconnection = await amqp.connect(rabbitUrl);\n\tchannel = await connection.createChannel();\n\tawait channel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nexport function getChannel(): amqp.Channel {\n\tif (!channel) throw new Error('Channel not initialized. Call initEventBus first.');\n\treturn channel;\n}\n\nexport async function publishEvent<TPayload extends Record<string, unknown>>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tconst ch = getChannel();\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tch.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t});\n\tconsole.log(`Published event [${event.eventId}] with payload`, event.payload);\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>\n): Promise<void> {\n\tconst ch = getChannel();\n\tconst queueName = `${eventId}-${getInstanceId()}`;\n\n\tawait ch.assertQueue(queueName, {\n\t\tdurable: false,\n\t\texclusive: true,\n\t\tautoDelete: true,\n\t});\n\n\tawait ch.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\n\tawait ch.consume(\n\t\tqueueName,\n\t\tasync msg => {\n\t\t\tif (msg !== null) {\n\t\t\t\tconst payload = JSON.parse(msg.content.toString());\n\t\t\t\ttry {\n\t\t\t\t\tawait onMessage(payload);\n\t\t\t\t\tch.ack(msg);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(`Error handling event [${eventId}] on instance [${getInstanceId()}]`, err);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{ noAck: false }\n\t);\n\n\tconsole.log(`Subscribed to event [${eventId}] on queue [${queueName}]`);\n}\n\nexport async function closeEventBus(): Promise<void> {\n\tif (channel) await channel.close();\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}"]}
@@ -31,7 +31,7 @@ export declare class User extends TimeStamps {
31
31
  isPhoneVerified?: boolean;
32
32
  onlineStatus?: OnlineStatus;
33
33
  fcmTokens?: string[];
34
- static updateWallet(this: ReturnModelType<typeof User>, userId: string, amount: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<User & {
34
+ static updateWallet(this: ReturnModelType<typeof User>, userId: string, amount: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject> & Omit<User & {
35
35
  _id: import("mongoose").Types.ObjectId;
36
36
  } & {
37
37
  __v: number;
@@ -1,16 +1,19 @@
1
1
  import z, { ZodTypeAny } from 'zod';
2
2
  import { SocketEventType } from '../../utilities/enum';
3
+ import { NotificationSocketEvent } from './events/notification.socket.event';
3
4
  export declare abstract class BaseSocketEvent<SIn extends ZodTypeAny, SOut extends ZodTypeAny> {
4
5
  protected readonly _eventType: SocketEventType;
5
6
  readonly inputSchema: SIn;
6
7
  readonly outputSchema: SOut;
7
8
  protected readonly data: z.infer<SOut>;
8
- getSubscriptionKey(): string;
9
9
  static identifier(input: any): string;
10
+ notification?(): NotificationSocketEvent | null;
11
+ pushNotification?(): NotificationSocketEvent | null;
10
12
  protected constructor(eventType: SocketEventType, schemas: {
11
13
  input: SIn;
12
14
  output: SOut;
13
15
  }, data: z.infer<SOut>);
14
16
  payload(): z.infer<SOut>;
15
17
  eventType(): SocketEventType;
18
+ getSubscriptionKey(): string;
16
19
  }
@@ -6,10 +6,6 @@ class BaseSocketEvent {
6
6
  inputSchema;
7
7
  outputSchema;
8
8
  data;
9
- getSubscriptionKey() {
10
- const identifier = this.constructor.identifier(this.data);
11
- return `${this._eventType}:${identifier}`;
12
- }
13
9
  static identifier(input) {
14
10
  return 'default';
15
11
  }
@@ -25,6 +21,10 @@ class BaseSocketEvent {
25
21
  eventType() {
26
22
  return this._eventType;
27
23
  }
24
+ getSubscriptionKey() {
25
+ const identifier = this.constructor.identifier(this.data);
26
+ return `${this._eventType}:${identifier}`;
27
+ }
28
28
  }
29
29
  exports.BaseSocketEvent = BaseSocketEvent;
30
30
  //# sourceMappingURL=BaseSocketEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSocketEvent.js","sourceRoot":"/","sources":["libraries/socket/BaseSocketEvent.ts"],"names":[],"mappings":";;;AAGA,MAAsB,eAAe;IACjB,UAAU,CAAkB;IACtC,WAAW,CAAM;IACjB,YAAY,CAAO;IACT,IAAI,CAAgB;IAEhC,kBAAkB;QACxB,MAAM,UAAU,GAAI,IAAI,CAAC,WAAsC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtF,OAAO,GAAG,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAU;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,YACC,SAA0B,EAC1B,OAAqC,EACrC,IAAmB;QAEnB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;QAEnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAEM,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,SAAS;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;CACD;AAlCD,0CAkCC","sourcesContent":["import z, { ZodTypeAny } from 'zod';\nimport { SocketEventType } from '../../utilities/enum';\n\nexport abstract class BaseSocketEvent<SIn extends ZodTypeAny, SOut extends ZodTypeAny> {\n\tprotected readonly _eventType: SocketEventType;\n\treadonly inputSchema: SIn;\n\treadonly outputSchema: SOut;\n\tprotected readonly data: z.infer<SOut>;\n\n\tpublic getSubscriptionKey(): string {\n\t\tconst identifier = (this.constructor as typeof BaseSocketEvent).identifier(this.data);\n\t\treturn `${this._eventType}:${identifier}`;\n\t}\n\n\tstatic identifier(input: any): string {\n\t\treturn 'default';\n\t}\n\n\tprotected constructor(\n\t\teventType: SocketEventType,\n\t\tschemas: { input: SIn; output: SOut },\n\t\tdata: z.infer<SOut>\n\t) {\n\t\tthis._eventType = eventType;\n\t\tthis.inputSchema = schemas.input;\n\t\tthis.outputSchema = schemas.output;\n\n\t\tthis.data = this.outputSchema.parse(data);\n\t}\n\n\tpublic payload(): z.infer<SOut> {\n\t\treturn this.data;\n\t}\n\n\tpublic eventType(): SocketEventType {\n\t\treturn this._eventType;\n\t}\n}"]}
1
+ {"version":3,"file":"BaseSocketEvent.js","sourceRoot":"/","sources":["libraries/socket/BaseSocketEvent.ts"],"names":[],"mappings":";;;AAIA,MAAsB,eAAe;IACjB,UAAU,CAAkB;IACtC,WAAW,CAAM;IACjB,YAAY,CAAO;IACT,IAAI,CAAgB;IAEvC,MAAM,CAAC,UAAU,CAAC,KAAU;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAKD,YACC,SAA0B,EAC1B,OAAqC,EACrC,IAAmB;QAEnB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;QAEnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAEM,OAAO;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,SAAS;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAEM,kBAAkB;QACxB,MAAM,UAAU,GAAI,IAAI,CAAC,WAAsC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtF,OAAO,GAAG,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE,CAAC;IAC3C,CAAC;CACD;AArCD,0CAqCC","sourcesContent":["import z, { ZodTypeAny } from 'zod';\nimport { SocketEventType } from '../../utilities/enum';\nimport { NotificationSocketEvent } from './events/notification.socket.event';\n\nexport abstract class BaseSocketEvent<SIn extends ZodTypeAny, SOut extends ZodTypeAny> {\n\tprotected readonly _eventType: SocketEventType;\n\treadonly inputSchema: SIn;\n\treadonly outputSchema: SOut;\n\tprotected readonly data: z.infer<SOut>;\n\n\tstatic identifier(input: any): string {\n\t\treturn 'default';\n\t}\n\n\tpublic notification?(): NotificationSocketEvent | null;\n\tpublic pushNotification?(): NotificationSocketEvent | null;\n\n\tprotected constructor(\n\t\teventType: SocketEventType,\n\t\tschemas: { input: SIn; output: SOut },\n\t\tdata: z.infer<SOut>\n\t) {\n\t\tthis._eventType = eventType;\n\t\tthis.inputSchema = schemas.input;\n\t\tthis.outputSchema = schemas.output;\n\n\t\tthis.data = this.outputSchema.parse(data);\n\t}\n\n\tpublic payload(): z.infer<SOut> {\n\t\treturn this.data;\n\t}\n\n\tpublic eventType(): SocketEventType {\n\t\treturn this._eventType;\n\t}\n\n\tpublic getSubscriptionKey(): string {\n\t\tconst identifier = (this.constructor as typeof BaseSocketEvent).identifier(this.data);\n\t\treturn `${this._eventType}:${identifier}`;\n\t}\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { BaseEvent } from '../event/BaseEvent';
2
+ import { PushNotificationEventType } from '../../utilities/enum';
3
+ import { ChatroomMessageSendSocketOutputDTO } from './events';
4
+ type PushNotificationMap = {
5
+ [PushNotificationEventType.CHATROOM_MESSAGE_SEND]: ChatroomMessageSendSocketOutputDTO;
6
+ };
7
+ export declare class PushNotificationEvent<T extends PushNotificationEventType> extends BaseEvent<PushNotificationMap[T]> {
8
+ private readonly _type;
9
+ constructor(type: T, data: PushNotificationMap[T]);
10
+ get type(): T;
11
+ getPayload(): PushNotificationMap[T];
12
+ }
13
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PushNotificationEvent = void 0;
4
+ const BaseEvent_1 = require("../event/BaseEvent");
5
+ const enum_1 = require("../../utilities/enum");
6
+ class PushNotificationEvent extends BaseEvent_1.BaseEvent {
7
+ _type;
8
+ constructor(type, data) {
9
+ super('notification.push', data);
10
+ this._type = type;
11
+ }
12
+ get type() {
13
+ return this._type;
14
+ }
15
+ getPayload() {
16
+ return this.payload;
17
+ }
18
+ }
19
+ exports.PushNotificationEvent = PushNotificationEvent;
20
+ //# sourceMappingURL=PushNotificationEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PushNotificationEvent.js","sourceRoot":"/","sources":["libraries/socket/PushNotificationEvent.ts"],"names":[],"mappings":";;;AAAA,kDAA+C;AAC/C,+CAAiE;AAOjE,MAAa,qBAA2D,SAAQ,qBAE/E;IACiB,KAAK,CAAI;IAE1B,YAAY,IAAO,EAAE,IAA4B;QAChD,KAAK,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;IAEM,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD;AAjBD,sDAiBC","sourcesContent":["import { BaseEvent } from '../event/BaseEvent';\nimport { PushNotificationEventType } from '../../utilities/enum';\nimport { ChatroomMessageSendSocketOutputDTO } from './events';\n\ntype PushNotificationMap = {\n\t[PushNotificationEventType.CHATROOM_MESSAGE_SEND]: ChatroomMessageSendSocketOutputDTO;\n};\n\nexport class PushNotificationEvent<T extends PushNotificationEventType> extends BaseEvent<\n\tPushNotificationMap[T]\n> {\n\tprivate readonly _type: T;\n\n\tconstructor(type: T, data: PushNotificationMap[T]) {\n\t\tsuper('notification.push', data);\n\t\tthis._type = type;\n\t}\n\n\tget type(): T {\n\t\treturn this._type;\n\t}\n\n\tpublic getPayload(): PushNotificationMap[T] {\n\t\treturn this.payload;\n\t}\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function subscribeToSocketEvent(): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subscribeToSocketEvent = subscribeToSocketEvent;
4
+ const instance_utils_1 = require("../../../utilities/instance.utils");
5
+ const event_1 = require("../../event");
6
+ const local_subscription_registry_1 = require("./local-subscription-registry");
7
+ async function subscribeToSocketEvent() {
8
+ const channel = (0, event_1.getChannel)();
9
+ const queueName = `socket-events-${(0, instance_utils_1.getInstanceId)()}`;
10
+ await channel.assertQueue(queueName, { durable: true });
11
+ await channel.bindQueue(queueName, event_1.EXCHANGE_NAME, `instance.${(0, instance_utils_1.getInstanceId)()}`);
12
+ await channel.consume(queueName, msg => {
13
+ if (!msg)
14
+ return;
15
+ try {
16
+ const { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));
17
+ local_subscription_registry_1.LocalSubs.emit(recipient, localKey, payload);
18
+ channel.ack(msg);
19
+ }
20
+ catch (e) {
21
+ console.error('Failed to handle socket event:', e);
22
+ channel.nack(msg, false, false);
23
+ }
24
+ });
25
+ console.log(`Subscribed to socket events on queue [${queueName}]`);
26
+ }
27
+ //# sourceMappingURL=socket-event-consumer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-event-consumer.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-consumer.ts"],"names":[],"mappings":";;AAIA,wDAoBC;AAxBD,sEAAkE;AAClE,uCAAwD;AACxD,+EAA0D;AAEnD,KAAK,UAAU,sBAAsB;IAC3C,MAAM,OAAO,GAAG,IAAA,kBAAU,GAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,iBAAiB,IAAA,8BAAa,GAAE,EAAE,CAAC;IAErD,MAAM,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,MAAM,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,qBAAa,EAAE,YAAY,IAAA,8BAAa,GAAE,EAAE,CAAC,CAAC;IAEjF,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE;QACtC,IAAI,CAAC,GAAG;YAAE,OAAO;QACjB,IAAI,CAAC;YACJ,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YAClF,uCAAS,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,CAAC,CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,yCAAyC,SAAS,GAAG,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { getInstanceId } from '../../../utilities/instance.utils';\nimport { EXCHANGE_NAME, getChannel } from '../../event';\nimport { LocalSubs } from './local-subscription-registry';\n\nexport async function subscribeToSocketEvent() {\n\tconst channel = getChannel();\n\tconst queueName = `socket-events-${getInstanceId()}`;\n\n\tawait channel.assertQueue(queueName, { durable: true });\n\tawait channel.bindQueue(queueName, EXCHANGE_NAME, `instance.${getInstanceId()}`);\n\n\tawait channel.consume(queueName, msg => {\n\t\tif (!msg) return;\n\t\ttry {\n\t\t\tconst { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));\n\t\t\tLocalSubs.emit(recipient, localKey, payload);\n\t\t\tchannel.ack(msg);\n\t\t} catch (e) {\n\t\t\tconsole.error('Failed to handle socket event:', e);\n\t\t\tchannel.nack(msg, false, false);\n\t\t}\n\t});\n\n\tconsole.log(`Subscribed to socket events on queue [${queueName}]`);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { BaseSocketEvent } from '../BaseSocketEvent';
2
+ import { NotificationSocketEvent } from '../events/notification.socket.event';
3
+ export declare function publishSocketEvent(event: BaseSocketEvent<any, any>, recipients: string[]): Promise<void>;
4
+ export declare function publishNotificationSocketEvent(event: NotificationSocketEvent, recipients: string[]): Promise<void>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.publishSocketEvent = publishSocketEvent;
4
+ exports.publishNotificationSocketEvent = publishNotificationSocketEvent;
5
+ const __1 = require("../../..");
6
+ const socket_redis_connections_1 = require("./socket-redis-connections");
7
+ const event_1 = require("../../event");
8
+ const PushNotificationEvent_1 = require("../PushNotificationEvent");
9
+ const enum_1 = require("../../../utilities/enum");
10
+ async function publishToInstances(recipients, localKey, payload) {
11
+ const channel = (0, event_1.getChannel)();
12
+ const redisService = (0, __1.getLibraries)().getRedisService();
13
+ const publishOptions = {
14
+ contentType: 'application/json',
15
+ persistent: true,
16
+ };
17
+ for (const recipient of recipients) {
18
+ const instanceNames = await redisService.getSetMembers((0, socket_redis_connections_1.kEntityInstances)(recipient));
19
+ if (!instanceNames.length)
20
+ continue;
21
+ const messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');
22
+ for (const instanceName of instanceNames) {
23
+ const routingKey = `${event_1.INSTANCE_ROUTE_PREFIX}.${instanceName}`;
24
+ channel.publish(event_1.EXCHANGE_NAME, routingKey, messageBuffer, publishOptions);
25
+ }
26
+ }
27
+ }
28
+ async function getActiveSubscribedRecipients(recipients, localKey) {
29
+ const redisService = (0, __1.getLibraries)().getRedisService();
30
+ const subscribed = [];
31
+ const unsubscribed = [];
32
+ for (const recipient of recipients) {
33
+ const [instanceNames, isSub] = await Promise.all([
34
+ redisService.getSetMembers((0, socket_redis_connections_1.kEntityInstances)(recipient)),
35
+ (0, socket_redis_connections_1.isEntitySubscribed)(recipient, localKey),
36
+ ]);
37
+ if (instanceNames.length && isSub) {
38
+ subscribed.push(recipient);
39
+ }
40
+ else {
41
+ unsubscribed.push(recipient);
42
+ }
43
+ }
44
+ return { subscribed, unsubscribed };
45
+ }
46
+ async function publishSocketEvent(event, recipients) {
47
+ const localKey = event.getSubscriptionKey();
48
+ const payload = event.payload();
49
+ const { subscribed, unsubscribed } = await getActiveSubscribedRecipients(recipients, localKey);
50
+ if (subscribed.length > 0) {
51
+ await publishToInstances(subscribed, localKey, payload);
52
+ }
53
+ if (unsubscribed.length > 0) {
54
+ const notificationEvent = event.notification?.();
55
+ const pushNotificationEvent = event.pushNotification?.();
56
+ if (pushNotificationEvent) {
57
+ const pushNotificationEvent = new PushNotificationEvent_1.PushNotificationEvent(enum_1.PushNotificationEventType.CHATROOM_MESSAGE_SEND, payload);
58
+ await (0, event_1.publishEvent)(pushNotificationEvent);
59
+ }
60
+ if (notificationEvent) {
61
+ await publishNotificationSocketEvent(notificationEvent, unsubscribed);
62
+ }
63
+ }
64
+ }
65
+ async function publishNotificationSocketEvent(event, recipients) {
66
+ await publishToInstances(recipients, event.getSubscriptionKey(), event.payload());
67
+ }
68
+ //# sourceMappingURL=socket-event-publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-event-publisher.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-publisher.ts"],"names":[],"mappings":";;AAsDA,gDA6BC;AAED,wEAKC;AA1FD,gCAAwC;AAExC,yEAAkF;AAElF,uCAA6F;AAC7F,oEAAiE;AACjE,kDAAoE;AAEpE,KAAK,UAAU,kBAAkB,CAAC,UAAoB,EAAE,QAAgB,EAAE,OAAY;IACrF,MAAM,OAAO,GAAG,IAAA,kBAAU,GAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,IAAA,gBAAY,GAAE,CAAC,eAAe,EAAE,CAAC;IAEtD,MAAM,cAAc,GAAG;QACtB,WAAW,EAAE,kBAAkB;QAC/B,UAAU,EAAE,IAAI;KAChB,CAAC;IAEF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,aAAa,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,IAAA,2CAAgB,EAAC,SAAS,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,aAAa,CAAC,MAAM;YAAE,SAAS;QAEp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AK,CAAC,OAAO,EAAE,CAAC;IAEhC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,MAAM,6BAA6B,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE/F,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,kBAAkB,CAAC,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,MAAM,iBAAiB,GAAG,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC;QACjD,MAAM,qBAAqB,GAAG,KAAK,CAAC,gBAAgB,EAAE,EAAE,CAAC;QAEzD,IAAI,qBAAqB,EAAE,CAAC;YAC3B,MAAM,qBAAqB,GAAG,IAAI,6CAAqB,CACtD,gCAAyB,CAAC,qBAAqB,EAC/C,OAAO,CACP,CAAC;YAEF,MAAM,IAAA,oBAAY,EAAC,qBAAqB,CAAC,CAAC;QAC3C,CAAC;QACD,IAAI,iBAAiB,EAAE,CAAC;YACvB,MAAM,8BAA8B,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;AACF,CAAC;AAEM,KAAK,UAAU,8BAA8B,CACnD,KAA8B,EAC9B,UAAoB;IAEpB,MAAM,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,kBAAkB,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import { getLibraries } from '../../..';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\nimport { isEntitySubscribed, kEntityInstances } from './socket-redis-connections';\nimport { NotificationSocketEvent } from '../events/notification.socket.event';\nimport { EXCHANGE_NAME, getChannel, INSTANCE_ROUTE_PREFIX, publishEvent } from '../../event';\nimport { PushNotificationEvent } from '../PushNotificationEvent';\nimport { PushNotificationEventType } from '../../../utilities/enum';\n\nasync function publishToInstances(recipients: string[], localKey: string, payload: any): Promise<void> {\n\tconst channel = getChannel();\n\tconst redisService = getLibraries().getRedisService();\n\n\tconst publishOptions = {\n\t\tcontentType: 'application/json',\n\t\tpersistent: true,\n\t};\n\n\tfor (const recipient of recipients) {\n\t\tconst instanceNames = await redisService.getSetMembers(kEntityInstances(recipient));\n\t\tif (!instanceNames.length) continue;\n\n\t\tconst messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');\n\n\t\tfor (const instanceName of instanceNames) {\n\t\t\tconst routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}`;\n\t\t\tchannel.publish(EXCHANGE_NAME, routingKey, messageBuffer, publishOptions);\n\t\t}\n\t}\n}\n\nasync function getActiveSubscribedRecipients(\n\trecipients: string[],\n\tlocalKey: string\n): Promise<{ subscribed: string[]; unsubscribed: string[] }> {\n\tconst redisService = getLibraries().getRedisService();\n\tconst subscribed: string[] = [];\n\tconst unsubscribed: string[] = [];\n\n\tfor (const recipient of recipients) {\n\t\tconst [instanceNames, isSub] = await Promise.all([\n\t\t\tredisService.getSetMembers(kEntityInstances(recipient)),\n\t\t\tisEntitySubscribed(recipient, localKey),\n\t\t]);\n\n\t\tif (instanceNames.length && isSub) {\n\t\t\tsubscribed.push(recipient);\n\t\t} else {\n\t\t\tunsubscribed.push(recipient);\n\t\t}\n\t}\n\n\treturn { subscribed, unsubscribed };\n}\n\nexport async function publishSocketEvent(\n\tevent: BaseSocketEvent<any, any>,\n\trecipients: string[]\n): Promise<void> {\n\tconst localKey = event.getSubscriptionKey();\n\tconst payload = event.payload();\n\n\tconst { subscribed, unsubscribed } = await getActiveSubscribedRecipients(recipients, localKey);\n\n\tif (subscribed.length > 0) {\n\t\tawait publishToInstances(subscribed, localKey, payload);\n\t}\n\n\tif (unsubscribed.length > 0) {\n\t\tconst notificationEvent = event.notification?.();\n\t\tconst pushNotificationEvent = event.pushNotification?.();\n\n\t\tif (pushNotificationEvent) {\n\t\t\tconst pushNotificationEvent = new PushNotificationEvent(\n\t\t\t\tPushNotificationEventType.CHATROOM_MESSAGE_SEND,\n\t\t\t\tpayload\n\t\t\t);\n\n\t\t\tawait publishEvent(pushNotificationEvent);\n\t\t}\n\t\tif (notificationEvent) {\n\t\t\tawait publishNotificationSocketEvent(notificationEvent, unsubscribed);\n\t\t}\n\t}\n}\n\nexport async function publishNotificationSocketEvent(\n\tevent: NotificationSocketEvent,\n\trecipients: string[]\n): Promise<void> {\n\tawait publishToInstances(recipients, event.getSubscriptionKey(), event.payload());\n}"]}
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { SocketEventType } from '../../../utilities/enum';
3
3
  import { BaseSocketEvent } from '../BaseSocketEvent';
4
- import { Registry } from '../socket-event-registry.map';
4
+ import { Registry } from './socket-event-registry.map';
5
5
  interface EventRegistration<TEvent extends BaseSocketEvent<any, any>> {
6
6
  ctor: new (payload: z.input<TEvent['outputSchema']>) => TEvent;
7
7
  schemas: {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventFactory = void 0;
4
- const socket_event_registry_map_1 = require("../socket-event-registry.map");
4
+ const socket_event_registry_map_1 = require("./socket-event-registry.map");
5
5
  class EventFactory {
6
6
  static getRegistration(eventType) {
7
7
  return socket_event_registry_map_1.REGISTRY[eventType];
@@ -1 +1 @@
1
- {"version":3,"file":"socket-event-registry.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-registry.ts"],"names":[],"mappings":";;;AAGA,4EAAkE;AAYlE,MAAa,YAAY;IACxB,MAAM,CAAC,eAAe,CAA4B,SAAY;QAC7D,OAAO,oCAAQ,CAAC,SAAS,CAAgB,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,kBAAkB,CAA4B,eAAkB,EAAE,KAAkB;QAC1F,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QACtE,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC,cAAc,CAAC,IAAI,SAAS,CAAC;QACtD,OAAO,GAAG,eAAe,IAAI,GAAG,EAAE,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,WAAW,CAA4B,eAAkB,EAAE,IAAkB;QAC1F,MAAM,EAAE,IAAI,EAAE,GAAG,oCAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAgB,CAAC;IACtC,CAAC;CACD;AAhBD,oCAgBC","sourcesContent":["import { z } from 'zod';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\nimport { Registry, REGISTRY } from '../socket-event-registry.map';\n\ninterface EventRegistration<TEvent extends BaseSocketEvent<any, any>> {\n\tctor: new (payload: z.input<TEvent['outputSchema']>) => TEvent;\n\tschemas: { input: TEvent['inputSchema']; output: TEvent['outputSchema'] };\n\tidentifier?: (input: z.infer<TEvent['inputSchema']>) => string;\n}\n\ntype InputFor<T extends SocketEventType> = z.infer<Registry[T]['schemas']['input']>;\ntype OutputFor<T extends SocketEventType> = z.infer<Registry[T]['schemas']['output']>;\ntype EventFor<T extends SocketEventType> = InstanceType<Registry[T]['ctor']>;\n\nexport class EventFactory {\n\tstatic getRegistration<T extends SocketEventType>(eventType: T) {\n\t\treturn REGISTRY[eventType] as Registry[T];\n\t}\n\n\tstatic getSubscriptionKey<T extends SocketEventType>(SocketEventType: T, input: InputFor<T>) {\n\t\tconst { identifier, schemas } = this.getRegistration(SocketEventType);\n\t\tconst validatedInput = schemas.input.parse(input);\n\t\tconst key = identifier?.(validatedInput) ?? 'default';\n\t\treturn `${SocketEventType}:${key}`;\n\t}\n\n\tpublic static createEvent<T extends SocketEventType>(SocketEventType: T, data: OutputFor<T>): EventFor<T> {\n\t\tconst { ctor } = REGISTRY[SocketEventType];\n\t\treturn new ctor(data) as EventFor<T>;\n\t}\n}\n\nexport type { Registry, EventFor, InputFor, OutputFor, EventRegistration };\n"]}
1
+ {"version":3,"file":"socket-event-registry.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-registry.ts"],"names":[],"mappings":";;;AAGA,2EAAiE;AAajE,MAAa,YAAY;IACxB,MAAM,CAAC,eAAe,CAA4B,SAAY;QAC7D,OAAO,oCAAQ,CAAC,SAAS,CAAgB,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,kBAAkB,CAA4B,eAAkB,EAAE,KAAkB;QAC1F,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QACtE,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC,cAAc,CAAC,IAAI,SAAS,CAAC;QACtD,OAAO,GAAG,eAAe,IAAI,GAAG,EAAE,CAAC;IACpC,CAAC;IAEM,MAAM,CAAC,WAAW,CAA4B,eAAkB,EAAE,IAAkB;QAC1F,MAAM,EAAE,IAAI,EAAE,GAAG,oCAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAgB,CAAC;IACtC,CAAC;CAED;AAjBD,oCAiBC","sourcesContent":["import { z } from 'zod';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\nimport { Registry, REGISTRY } from './socket-event-registry.map';\nimport { EventRegistry } from '../../event/decorators/metadata';\n\ninterface EventRegistration<TEvent extends BaseSocketEvent<any, any>> {\n\tctor: new (payload: z.input<TEvent['outputSchema']>) => TEvent;\n\tschemas: { input: TEvent['inputSchema']; output: TEvent['outputSchema'] };\n\tidentifier?: (input: z.infer<TEvent['inputSchema']>) => string;\n}\n\ntype InputFor<T extends SocketEventType> = z.infer<Registry[T]['schemas']['input']>;\ntype OutputFor<T extends SocketEventType> = z.infer<Registry[T]['schemas']['output']>;\ntype EventFor<T extends SocketEventType> = InstanceType<Registry[T]['ctor']>;\n\nexport class EventFactory {\n\tstatic getRegistration<T extends SocketEventType>(eventType: T) {\n\t\treturn REGISTRY[eventType] as Registry[T];\n\t}\n\n\tstatic getSubscriptionKey<T extends SocketEventType>(SocketEventType: T, input: InputFor<T>) {\n\t\tconst { identifier, schemas } = this.getRegistration(SocketEventType);\n\t\tconst validatedInput = schemas.input.parse(input);\n\t\tconst key = identifier?.(validatedInput) ?? 'default';\n\t\treturn `${SocketEventType}:${key}`;\n\t}\n\n\tpublic static createEvent<T extends SocketEventType>(SocketEventType: T, data: OutputFor<T>): EventFor<T> {\n\t\tconst { ctor } = REGISTRY[SocketEventType];\n\t\treturn new ctor(data) as EventFor<T>;\n\t}\n\n}\n\nexport type { Registry, EventFor, InputFor, OutputFor, EventRegistration };\n"]}
@@ -1,10 +1,11 @@
1
- import { ChatlistMessageSendEvent, ChatroomMessageSendEvent } from './events';
2
- import { TicketAssignEvent } from './events/ticket-assign.socket.event';
3
- import { TicketUnassignEvent } from './events/ticket-unassign.socket.event';
4
- import { EventRegistration } from './core';
1
+ import { ChatlistMessageSendSocketEvent, ChatroomMessageSendSocketEvent } from '../events';
2
+ import { TicketAssignEvent } from '../events/ticket-assign.socket.event';
3
+ import { TicketUnassignEvent } from '../events/ticket-unassign.socket.event';
4
+ import { EventRegistration } from './index';
5
+ import { NotificationSocketEvent } from '../events/notification.socket.event';
5
6
  export declare const REGISTRY: {
6
7
  readonly CHATROOM_MESSAGE_SEND: {
7
- readonly ctor: typeof ChatroomMessageSendEvent;
8
+ readonly ctor: typeof ChatroomMessageSendSocketEvent;
8
9
  readonly schemas: {
9
10
  input: import("zod").ZodObject<{
10
11
  chatroomId: import("zod").ZodEffects<import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
@@ -30,10 +31,10 @@ export declare const REGISTRY: {
30
31
  messageId: import("mongoose").Types.ObjectId;
31
32
  }>;
32
33
  };
33
- readonly identifier: typeof ChatroomMessageSendEvent.identifier;
34
+ readonly identifier: typeof ChatroomMessageSendSocketEvent.identifier;
34
35
  };
35
36
  readonly CHATLIST_MESSAGE_RECEIVED: {
36
- readonly ctor: typeof ChatlistMessageSendEvent;
37
+ readonly ctor: typeof ChatlistMessageSendSocketEvent;
37
38
  readonly schemas: {
38
39
  input: import("zod").ZodObject<{}, "strip", import("zod").ZodTypeAny, {}, {}>;
39
40
  output: import("zod").ZodObject<{
@@ -72,21 +73,21 @@ export declare const REGISTRY: {
72
73
  input: import("zod").ZodUndefined;
73
74
  output: import("zod").ZodObject<{
74
75
  _id: import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>;
75
- type: import("zod").ZodNativeEnum<typeof import("../../utilities/enum").TicketType>;
76
- status: import("zod").ZodNativeEnum<typeof import("../../utilities/enum").TicketStatus>;
76
+ type: import("zod").ZodNativeEnum<typeof import("../../../utilities/enum").TicketType>;
77
+ status: import("zod").ZodNativeEnum<typeof import("../../../utilities/enum").TicketStatus>;
77
78
  client: import("zod").ZodObject<{
78
79
  _id: import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>;
79
- type: import("zod").ZodNativeEnum<typeof import("../../utilities/enum").UserRef>;
80
+ type: import("zod").ZodNativeEnum<typeof import("../../../utilities/enum").UserRef>;
80
81
  name: import("zod").ZodString | import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, string, string>;
81
82
  profilePhoto: import("zod").ZodNullable<import("zod").ZodString> | import("zod").ZodNullable<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, string, string>>;
82
83
  }, "strip", import("zod").ZodTypeAny, {
83
84
  name: string;
84
- type: import("../../utilities/enum").UserRef;
85
+ type: import("../../../utilities/enum").UserRef;
85
86
  _id: import("mongoose").Types.ObjectId;
86
87
  profilePhoto: string | null;
87
88
  }, {
88
89
  name: string;
89
- type: import("../../utilities/enum").UserRef;
90
+ type: import("../../../utilities/enum").UserRef;
90
91
  _id: string | import("mongoose").Types.ObjectId;
91
92
  profilePhoto: string | null;
92
93
  }>;
@@ -106,14 +107,14 @@ export declare const REGISTRY: {
106
107
  }>;
107
108
  unreadCount: import("zod").ZodNumber;
108
109
  }, "strip", import("zod").ZodTypeAny, {
109
- type: import("../../utilities/enum").TicketType;
110
+ type: import("../../../utilities/enum").TicketType;
110
111
  client: {
111
112
  name: string;
112
- type: import("../../utilities/enum").UserRef;
113
+ type: import("../../../utilities/enum").UserRef;
113
114
  _id: import("mongoose").Types.ObjectId;
114
115
  profilePhoto: string | null;
115
116
  };
116
- status: import("../../utilities/enum").TicketStatus;
117
+ status: import("../../../utilities/enum").TicketStatus;
117
118
  _id: import("mongoose").Types.ObjectId;
118
119
  createdAt: Date;
119
120
  updatedAt: Date;
@@ -125,14 +126,14 @@ export declare const REGISTRY: {
125
126
  chatroomId: import("mongoose").Types.ObjectId;
126
127
  orderId?: import("mongoose").Types.ObjectId | undefined;
127
128
  }, {
128
- type: import("../../utilities/enum").TicketType;
129
+ type: import("../../../utilities/enum").TicketType;
129
130
  client: {
130
131
  name: string;
131
- type: import("../../utilities/enum").UserRef;
132
+ type: import("../../../utilities/enum").UserRef;
132
133
  _id: string | import("mongoose").Types.ObjectId;
133
134
  profilePhoto: string | null;
134
135
  };
135
- status: import("../../utilities/enum").TicketStatus;
136
+ status: import("../../../utilities/enum").TicketStatus;
136
137
  _id: string | import("mongoose").Types.ObjectId;
137
138
  createdAt: string | Date;
138
139
  updatedAt: string | Date;
@@ -158,7 +159,20 @@ export declare const REGISTRY: {
158
159
  _id: import("mongoose").Types.ObjectId;
159
160
  }>;
160
161
  };
161
- readonly identifier: typeof import("./BaseSocketEvent").BaseSocketEvent.identifier;
162
+ readonly identifier: typeof import("./index").BaseSocketEvent.identifier;
163
+ };
164
+ readonly NOTIFICATION: {
165
+ readonly ctor: typeof NotificationSocketEvent;
166
+ readonly schemas: {
167
+ input: import("zod").ZodUndefined;
168
+ output: import("zod").ZodObject<{
169
+ message: import("zod").ZodString | import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, string, string>;
170
+ }, "strip", import("zod").ZodTypeAny, {
171
+ message: string;
172
+ }, {
173
+ message: string;
174
+ }>;
175
+ };
162
176
  };
163
177
  };
164
178
  export type Registry = {
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REGISTRY = void 0;
4
+ const enum_1 = require("../../../utilities/enum");
5
+ const events_1 = require("../events");
6
+ const ticket_assign_socket_event_1 = require("../events/ticket-assign.socket.event");
7
+ const ticket_unassign_socket_event_1 = require("../events/ticket-unassign.socket.event");
8
+ const notification_socket_event_1 = require("../events/notification.socket.event");
9
+ exports.REGISTRY = {
10
+ [enum_1.SocketEventType.CHATROOM_MESSAGE_SEND]: {
11
+ ctor: events_1.ChatroomMessageSendSocketEvent,
12
+ schemas: events_1.ChatroomMessageSendSocketEvent.schemas,
13
+ identifier: events_1.ChatroomMessageSendSocketEvent.identifier,
14
+ },
15
+ [enum_1.SocketEventType.CHATLIST_MESSAGE_RECEIVED]: {
16
+ ctor: events_1.ChatlistMessageSendSocketEvent,
17
+ schemas: events_1.ChatlistMessageSendSocketEvent.schemas,
18
+ },
19
+ [enum_1.SocketEventType.TICKET_ASSIGN]: {
20
+ ctor: ticket_assign_socket_event_1.TicketAssignEvent,
21
+ schemas: ticket_assign_socket_event_1.TicketAssignEvent.schemas,
22
+ },
23
+ [enum_1.SocketEventType.TICKET_UNASSIGN]: {
24
+ ctor: ticket_unassign_socket_event_1.TicketUnassignEvent,
25
+ schemas: ticket_unassign_socket_event_1.TicketUnassignEvent.schemas,
26
+ identifier: ticket_unassign_socket_event_1.TicketUnassignEvent.identifier,
27
+ },
28
+ [enum_1.SocketEventType.NOTIFICATION]: {
29
+ ctor: notification_socket_event_1.NotificationSocketEvent,
30
+ schemas: notification_socket_event_1.NotificationSocketEvent.schemas,
31
+ },
32
+ };
33
+ //# sourceMappingURL=socket-event-registry.map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-event-registry.map.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-registry.map.ts"],"names":[],"mappings":";;;AAAA,kDAA0D;AAC1D,sCAA2F;AAC3F,qFAAyE;AACzE,yFAA6E;AAE7E,mFAA8E;AAEjE,QAAA,QAAQ,GAAG;IACvB,CAAC,sBAAe,CAAC,qBAAqB,CAAC,EAAE;QACxC,IAAI,EAAE,uCAA8B;QACpC,OAAO,EAAE,uCAA8B,CAAC,OAAO;QAC/C,UAAU,EAAE,uCAA8B,CAAC,UAAU;KACrD;IACD,CAAC,sBAAe,CAAC,yBAAyB,CAAC,EAAE;QAC5C,IAAI,EAAE,uCAA8B;QACpC,OAAO,EAAE,uCAA8B,CAAC,OAAO;KAC/C;IACD,CAAC,sBAAe,CAAC,aAAa,CAAC,EAAE;QAChC,IAAI,EAAE,8CAAiB;QACvB,OAAO,EAAE,8CAAiB,CAAC,OAAO;KAClC;IACD,CAAC,sBAAe,CAAC,eAAe,CAAC,EAAE;QAClC,IAAI,EAAE,kDAAmB;QACzB,OAAO,EAAE,kDAAmB,CAAC,OAAO;QACpC,UAAU,EAAE,kDAAmB,CAAC,UAAU;KAC1C;IACD,CAAC,sBAAe,CAAC,YAAY,CAAC,EAAE;QAC/B,IAAI,EAAE,mDAAuB;QAC7B,OAAO,EAAE,mDAAuB,CAAC,OAAO;KACxC;CACQ,CAAC","sourcesContent":["import { SocketEventType } from '../../../utilities/enum';\nimport { ChatlistMessageSendSocketEvent, ChatroomMessageSendSocketEvent } from '../events';\nimport { TicketAssignEvent } from '../events/ticket-assign.socket.event';\nimport { TicketUnassignEvent } from '../events/ticket-unassign.socket.event';\nimport { EventRegistration } from './index';\nimport { NotificationSocketEvent } from '../events/notification.socket.event';\n\nexport const REGISTRY = {\n\t[SocketEventType.CHATROOM_MESSAGE_SEND]: {\n\t\tctor: ChatroomMessageSendSocketEvent,\n\t\tschemas: ChatroomMessageSendSocketEvent.schemas,\n\t\tidentifier: ChatroomMessageSendSocketEvent.identifier,\n\t},\n\t[SocketEventType.CHATLIST_MESSAGE_RECEIVED]: {\n\t\tctor: ChatlistMessageSendSocketEvent,\n\t\tschemas: ChatlistMessageSendSocketEvent.schemas,\n\t},\n\t[SocketEventType.TICKET_ASSIGN]: {\n\t\tctor: TicketAssignEvent,\n\t\tschemas: TicketAssignEvent.schemas,\n\t},\n\t[SocketEventType.TICKET_UNASSIGN]: {\n\t\tctor: TicketUnassignEvent,\n\t\tschemas: TicketUnassignEvent.schemas,\n\t\tidentifier: TicketUnassignEvent.identifier,\n\t},\n\t[SocketEventType.NOTIFICATION]: {\n\t\tctor: NotificationSocketEvent,\n\t\tschemas: NotificationSocketEvent.schemas,\n\t},\n} as const;\n\nexport type Registry = {\n\t[K in keyof typeof REGISTRY]: (typeof REGISTRY)[K] extends EventRegistration<any>\n\t\t? (typeof REGISTRY)[K]\n\t\t: never;\n};\n"]}