@lyxa.ai/core 1.0.381 → 1.0.382

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 (37) hide show
  1. package/dist/libraries/event/index.d.ts +1 -1
  2. package/dist/libraries/event/index.js +15 -16
  3. package/dist/libraries/event/index.js.map +1 -1
  4. package/dist/libraries/socket/{core/BaseSocketEvent.d.ts → BaseSocketEvent.d.ts} +1 -1
  5. package/dist/libraries/socket/BaseSocketEvent.js.map +1 -0
  6. package/dist/libraries/socket/core/index.d.ts +2 -2
  7. package/dist/libraries/socket/core/index.js +2 -2
  8. package/dist/libraries/socket/core/index.js.map +1 -1
  9. package/dist/libraries/socket/core/{LocalSubscriptionRegistry.js → local-subscription-registry.js} +1 -1
  10. package/dist/libraries/socket/core/local-subscription-registry.js.map +1 -0
  11. package/dist/libraries/socket/core/socket-event-registry.d.ts +12 -12
  12. package/dist/libraries/socket/core/socket-event-registry.js.map +1 -1
  13. package/dist/libraries/socket/events/chatlist-message-send.socket.event.d.ts +15 -15
  14. package/dist/libraries/socket/events/chatlist-message-send.socket.event.js +12 -12
  15. package/dist/libraries/socket/events/chatlist-message-send.socket.event.js.map +1 -1
  16. package/dist/libraries/socket/events/chatroom-message-send.socket.event.d.ts +23 -23
  17. package/dist/libraries/socket/events/chatroom-message-send.socket.event.js +8 -7
  18. package/dist/libraries/socket/events/chatroom-message-send.socket.event.js.map +1 -1
  19. package/dist/libraries/socket/index.d.ts +1 -0
  20. package/dist/libraries/socket/index.js +1 -0
  21. package/dist/libraries/socket/index.js.map +1 -1
  22. package/dist/libraries/trpc/middlewares/createSocketSubscriptionProcedure.d.ts +14 -0
  23. package/dist/libraries/trpc/middlewares/createSocketSubscriptionProcedure.js +38 -0
  24. package/dist/libraries/trpc/middlewares/createSocketSubscriptionProcedure.js.map +1 -0
  25. package/dist/types/README.md +1 -1
  26. package/dist/types/package.json +1 -1
  27. package/dist/types/utilities/validation/global-validation.d.ts +14 -0
  28. package/dist/types/utilities/validation/global-validation.js +57 -6
  29. package/dist/types/utilities/validation/global-validation.js.map +1 -1
  30. package/dist/utilities/validation/global-validation.d.ts +14 -0
  31. package/dist/utilities/validation/global-validation.js +57 -6
  32. package/dist/utilities/validation/global-validation.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/libraries/socket/core/BaseSocketEvent.js.map +0 -1
  35. package/dist/libraries/socket/core/LocalSubscriptionRegistry.js.map +0 -1
  36. /package/dist/libraries/socket/{core/BaseSocketEvent.js → BaseSocketEvent.js} +0 -0
  37. /package/dist/libraries/socket/core/{LocalSubscriptionRegistry.d.ts → local-subscription-registry.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import amqp from 'amqplib';
2
2
  import { BaseEvent } from './BaseEvent';
3
- import { BaseSocketEvent } from '../socket/core/BaseSocketEvent';
3
+ import { BaseSocketEvent } from '../socket/BaseSocketEvent';
4
4
  export declare function initEventBus(rabbitUrl: string): Promise<void>;
5
5
  export declare function publishEvent<TPayload extends Record<string, unknown>>(event: BaseEvent<TPayload>): Promise<void>;
6
6
  export declare function subscribeToEvent(eventId: string, onMessage: (payload: any) => Promise<void>): Promise<void>;
@@ -12,7 +12,7 @@ exports.closeEventBus = closeEventBus;
12
12
  const amqplib_1 = __importDefault(require("amqplib"));
13
13
  const instance_utils_1 = require("../../utilities/instance.utils");
14
14
  const index_1 = require("../../index");
15
- const LocalSubscriptionRegistry_1 = require("../socket/core/LocalSubscriptionRegistry");
15
+ const local_subscription_registry_1 = require("../socket/core/local-subscription-registry");
16
16
  const socket_redis_connections_1 = require("../socket/core/socket-redis-connections");
17
17
  let connection;
18
18
  let channel;
@@ -67,7 +67,7 @@ async function subscribeToSocketEvent() {
67
67
  return;
68
68
  try {
69
69
  const { localKey, payload, recipient } = JSON.parse(msg.content.toString('utf8'));
70
- LocalSubscriptionRegistry_1.LocalSubs.emit(recipient, localKey, payload);
70
+ local_subscription_registry_1.LocalSubs.emit(recipient, localKey, payload);
71
71
  channel.ack(msg);
72
72
  }
73
73
  catch (e) {
@@ -83,21 +83,20 @@ async function publishSocketEvent(event, recipients) {
83
83
  const payload = event.payload();
84
84
  for (const recipient of recipients) {
85
85
  const isSub = await (0, socket_redis_connections_1.isEntitySubscribed)(recipient, localKey);
86
- if (isSub) {
87
- const instanceNames = await redisService.getSetMembers((0, socket_redis_connections_1.kEntityInstances)(recipient));
88
- if (!instanceNames.length) {
89
- continue;
90
- }
91
- for (const instanceName of instanceNames) {
92
- const routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}`;
93
- const messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');
94
- channel.publish(EXCHANGE_NAME, routingKey, messageBuffer, {
95
- contentType: 'application/json',
96
- persistent: true,
97
- });
98
- }
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;
99
92
  }
100
- else {
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
+ });
101
100
  }
102
101
  }
103
102
  }
@@ -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,gDAgCC;AAED,sCAIC;AAvHD,sDAA2B;AAE3B,mEAA+D;AAE/D,uCAA2C;AAC3C,wFAAqE;AACrE,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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AAO,CAAC,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE;oBACzD,WAAW,EAAE,kBAAkB;oBAC/B,UAAU,EAAE,IAAI;iBAChB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;aAAM,CAAC;QAGR,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/core/BaseSocketEvent';\nimport { getLibraries } from '../../index';\nimport { LocalSubs } from '../socket/core/LocalSubscriptionRegistry';\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.getIdentifier(); // e.g. \"CHAT_UPSERT_MESSAGE:123123\"\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\tconst instanceNames = await redisService.getSetMembers(kEntityInstances(recipient));\n\t\t\tif (!instanceNames.length) {\n\t\t\t\t// No active instances → push notification fallback\n\t\t\t\t// TODO: queue push notification for { recipient, eventType, payload }\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// 3) Publish to every instance with routing\n\t\t\tfor (const instanceName of instanceNames) {\n\t\t\t\tconst routingKey = `${INSTANCE_ROUTE_PREFIX}.${instanceName}`;\n\t\t\t\tconst messageBuffer = Buffer.from(JSON.stringify({ localKey, payload, recipient }), 'utf8');\n\t\t\t\tchannel.publish(EXCHANGE_NAME, routingKey, messageBuffer, {\n\t\t\t\t\tcontentType: 'application/json',\n\t\t\t\t\tpersistent: true,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\t// Not subscribed → push notification fallback\n\t\t\t// TODO: queue push notification for { recipient, eventType, payload }\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":";;;;;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,KAAK,UAAU,YAAY,CAAC,SAAiB;IACnD,UAAU,GAAG,MAAM,iBAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,OAAO,GAAG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AE,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.getIdentifier();\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,5 +1,5 @@
1
1
  import z, { ZodTypeAny } from 'zod';
2
- import { SocketEventType } from '../../../utilities/enum';
2
+ import { SocketEventType } from '../../utilities/enum';
3
3
  export declare abstract class BaseSocketEvent<SIn extends ZodTypeAny, SOut extends ZodTypeAny> {
4
4
  protected readonly _eventType: SocketEventType;
5
5
  protected readonly inputSchema: SIn;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseSocketEvent.js","sourceRoot":"/","sources":["libraries/socket/BaseSocketEvent.ts"],"names":[],"mappings":";;;AAGA,MAAsB,eAAe;IACjB,UAAU,CAAkB;IAC5B,WAAW,CAAM;IACjB,YAAY,CAAO;IAEnB,IAAI,CAAgB;IAIvC,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;AA5BD,0CA4BC","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\tprotected readonly inputSchema: SIn;\n\tprotected readonly outputSchema: SOut;\n\n\tprotected readonly data: z.infer<SOut>;\n\n\tabstract getIdentifier(): string;\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"]}
@@ -1,5 +1,5 @@
1
- export * from './BaseSocketEvent';
2
- export * from './LocalSubscriptionRegistry';
1
+ export * from '../BaseSocketEvent';
2
+ export * from './local-subscription-registry';
3
3
  export * from './socket-event-registry';
4
4
  export * from './zAsyncIterable';
5
5
  export * from './socket-redis-connections';
@@ -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
- __exportStar(require("./BaseSocketEvent"), exports);
18
- __exportStar(require("./LocalSubscriptionRegistry"), exports);
17
+ __exportStar(require("../BaseSocketEvent"), exports);
18
+ __exportStar(require("./local-subscription-registry"), exports);
19
19
  __exportStar(require("./socket-event-registry"), exports);
20
20
  __exportStar(require("./zAsyncIterable"), exports);
21
21
  __exportStar(require("./socket-redis-connections"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/socket/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,8DAA4C;AAC5C,0DAAwC;AACxC,mDAAiC;AACjC,6DAA2C","sourcesContent":["export * from './BaseSocketEvent';\nexport * from './LocalSubscriptionRegistry';\nexport * from './socket-event-registry';\nexport * from './zAsyncIterable';\nexport * from './socket-redis-connections';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/socket/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,gEAA8C;AAC9C,0DAAwC;AACxC,mDAAiC;AACjC,6DAA2C","sourcesContent":["export * from '../BaseSocketEvent';\nexport * from './local-subscription-registry';\nexport * from './socket-event-registry';\nexport * from './zAsyncIterable';\nexport * from './socket-redis-connections';\n"]}
@@ -55,4 +55,4 @@ class LocalSubscriptionRegistry {
55
55
  }
56
56
  }
57
57
  exports.LocalSubs = new LocalSubscriptionRegistry();
58
- //# sourceMappingURL=LocalSubscriptionRegistry.js.map
58
+ //# sourceMappingURL=local-subscription-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-subscription-registry.js","sourceRoot":"/","sources":["libraries/socket/core/local-subscription-registry.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAkC;AAMlC,MAAa,iBAAiB;IACrB,GAAG,CAAe;IAClB,SAAS,CAAW;IAE5B,YAAY,QAAkB;QAC7B,IAAI,CAAC,GAAG,GAAG,IAAI,gBAAY,EAAE,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,IAAI,EAAE;QACL,OAAO,IAAI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,CAAC,QAAkB,EAAE,QAAkB,EAAE,OAAgB;QAC5D,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,EAAE;YAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;CACD;AAEY,QAAA,SAAS,GAAG,IAAI,yBAAyB,EAAE,CAAC","sourcesContent":["import EventEmitter from 'events';\n\ntype EventKey = string; // \"EVENT_TYPE:identifier\"\ntype EntityId = string;\ntype SocketId = string;\n\nexport class LocalEventEmitter {\n\tprivate _ee: EventEmitter;\n\tprivate _socketId: SocketId;\n\n\tconstructor(socketId: SocketId) {\n\t\tthis._ee = new EventEmitter();\n\t\tthis._socketId = socketId;\n\t}\n\n\tget socketId() {\n\t\treturn this._socketId;\n\t}\n\n\tget ee() {\n\t\treturn this._ee;\n\t}\n}\n\nclass LocalSubscriptionRegistry {\n\tprivate byEntity = new Map<EntityId, Map<EventKey, Set<LocalEventEmitter>>>();\n\n\tbind(entityId: EntityId, eventKey: EventKey, ee: LocalEventEmitter) {\n\t\tlet m = this.byEntity.get(entityId);\n\t\tif (!m) {\n\t\t\tm = new Map();\n\t\t\tthis.byEntity.set(entityId, m);\n\t\t}\n\t\tconst s = m.get(eventKey);\n\t\tif (!s) {\n\t\t\tm.set(eventKey, new Set());\n\t\t}\n\t\tm.get(eventKey)?.add(ee);\n\t}\n\n\tunbind(entityId: EntityId, eventKey: EventKey, ee: LocalEventEmitter) {\n\t\tconst m = this.byEntity.get(entityId);\n\t\tif (!m) return;\n\t\tconst s = m.get(eventKey);\n\t\tif (s) {\n\t\t\ts.delete(ee);\n\t\t\tif (s.size === 0) m.delete(eventKey);\n\t\t}\n\t\tif (m.size === 0) this.byEntity.delete(entityId);\n\t}\n\n\temit(entityId: EntityId, eventKey: EventKey, payload: unknown) {\n\t\tconst m = this.byEntity.get(entityId);\n\t\tconst ee = m?.get(eventKey);\n\t\tif (ee) ee.forEach(e => e.ee.emit(eventKey, payload));\n\t}\n}\n\nexport const LocalSubs = new LocalSubscriptionRegistry();\n"]}
@@ -1,33 +1,33 @@
1
1
  import z, { ZodTypeAny } from 'zod';
2
2
  import { ChatroomMessageSendEvent, ChatroomMessageSendInput, ChatroomMessageSendOutput } from '../events/chatroom-message-send.socket.event';
3
3
  import { SocketEventType } from '../../../utilities/enum';
4
- import { BaseSocketEvent } from './BaseSocketEvent';
4
+ import { BaseSocketEvent } from '../BaseSocketEvent';
5
5
  type EventCtor<SIn extends ZodTypeAny, SOut extends ZodTypeAny, C extends BaseSocketEvent<SIn, SOut>> = new (data: z.input<SOut>) => C;
6
6
  declare const REGISTRY: {
7
7
  readonly CHATROOM_MESSAGE_SEND: {
8
8
  readonly ctor: EventCtor<typeof ChatroomMessageSendInput, typeof ChatroomMessageSendOutput, ChatroomMessageSendEvent>;
9
9
  readonly input: z.ZodObject<{
10
- chatId: z.ZodString;
10
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
11
11
  }, "strip", z.ZodTypeAny, {
12
- chatId: string;
12
+ chatroomId: import("mongoose").Types.ObjectId;
13
13
  }, {
14
- chatId: string;
14
+ chatroomId: import("mongoose").Types.ObjectId;
15
15
  }>;
16
16
  readonly output: z.ZodObject<{
17
- chatId: z.ZodString;
18
- messageId: z.ZodString;
19
- content: z.ZodString;
20
- createdAt: z.ZodDate;
17
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
18
+ messageId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
19
+ content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
20
+ createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
21
21
  }, "strip", z.ZodTypeAny, {
22
22
  content: string;
23
23
  createdAt: Date;
24
- chatId: string;
25
- messageId: string;
24
+ chatroomId: import("mongoose").Types.ObjectId;
25
+ messageId: import("mongoose").Types.ObjectId;
26
26
  }, {
27
27
  content: string;
28
28
  createdAt: Date;
29
- chatId: string;
30
- messageId: string;
29
+ chatroomId: import("mongoose").Types.ObjectId;
30
+ messageId: import("mongoose").Types.ObjectId;
31
31
  }>;
32
32
  readonly identifier: typeof ChatroomMessageSendEvent.identifier;
33
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"socket-event-registry.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-registry.ts"],"names":[],"mappings":";;;AACA,qGAIsD;AACtD,kDAA0D;AAO1D,MAAM,QAAQ,GAAG;IAChB,CAAC,sBAAe,CAAC,qBAAqB,CAAC,EAAE;QACxC,IAAI,EAAE,6DAIL;QACD,KAAK,EAAE,6DAAwB,CAAC,OAAO,CAAC,KAAK;QAC7C,MAAM,EAAE,6DAAwB,CAAC,OAAO,CAAC,MAAM;QAC/C,UAAU,EAAE,6DAAwB,CAAC,UAAU;KAC/C;CACQ,CAAC;AAOX,MAAa,YAAY;IACjB,MAAM,CAAC,WAAW,CAA4B,eAAkB,EAAE,IAAmB;QAC3F,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAgB,CAAC;IACtC,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC/B,eAAkB,EAClB,KAA6C;QAE7C,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjD,OAAO,GAAG,eAAe,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;IAClD,CAAC;CACD;AAbD,oCAaC","sourcesContent":["import z, { ZodTypeAny } from 'zod';\nimport {\n\tChatroomMessageSendEvent,\n\tChatroomMessageSendInput,\n\tChatroomMessageSendOutput,\n} from '../events/chatroom-message-send.socket.event';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { BaseSocketEvent } from './BaseSocketEvent';\n\ntype EventCtor<SIn extends ZodTypeAny, SOut extends ZodTypeAny, C extends BaseSocketEvent<SIn, SOut>> = new (\n\tdata: z.input<SOut>\n) => C;\n\nconst REGISTRY = {\n\t[SocketEventType.CHATROOM_MESSAGE_SEND]: {\n\t\tctor: ChatroomMessageSendEvent as EventCtor<\n\t\t\ttypeof ChatroomMessageSendInput,\n\t\t\ttypeof ChatroomMessageSendOutput,\n\t\t\tChatroomMessageSendEvent\n\t\t>,\n\t\tinput: ChatroomMessageSendEvent.schemas.input,\n\t\toutput: ChatroomMessageSendEvent.schemas.output,\n\t\tidentifier: ChatroomMessageSendEvent.identifier,\n\t},\n} as const;\n\ntype Registry = typeof REGISTRY;\n\ntype PayloadFor<T extends SocketEventType> = z.input<Registry[T]['output']>;\ntype EventFor<T extends SocketEventType> = InstanceType<Registry[T]['ctor']>;\n\nexport class EventFactory {\n\tpublic static createEvent<T extends SocketEventType>(SocketEventType: T, data: PayloadFor<T>): EventFor<T> {\n\t\tconst { ctor } = REGISTRY[SocketEventType];\n\t\treturn new ctor(data) as EventFor<T>;\n\t}\n\n\tpublic static getSubscriptionKey<T extends SocketEventType>(\n\t\tSocketEventType: T,\n\t\tinput: z.infer<(typeof REGISTRY)[T]['input']>\n\t): string {\n\t\tconst { identifier } = REGISTRY[SocketEventType];\n\t\treturn `${SocketEventType}:${identifier(input)}`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"socket-event-registry.js","sourceRoot":"/","sources":["libraries/socket/core/socket-event-registry.ts"],"names":[],"mappings":";;;AACA,qGAIsD;AACtD,kDAA0D;AAO1D,MAAM,QAAQ,GAAG;IAChB,CAAC,sBAAe,CAAC,qBAAqB,CAAC,EAAE;QACxC,IAAI,EAAE,6DAIL;QACD,KAAK,EAAE,6DAAwB,CAAC,OAAO,CAAC,KAAK;QAC7C,MAAM,EAAE,6DAAwB,CAAC,OAAO,CAAC,MAAM;QAC/C,UAAU,EAAE,6DAAwB,CAAC,UAAU;KAC/C;CACQ,CAAC;AAOX,MAAa,YAAY;IACjB,MAAM,CAAC,WAAW,CAA4B,eAAkB,EAAE,IAAmB;QAC3F,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,OAAO,IAAI,IAAI,CAAC,IAAI,CAAgB,CAAC;IACtC,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC/B,eAAkB,EAClB,KAA6C;QAE7C,MAAM,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjD,OAAO,GAAG,eAAe,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;IAClD,CAAC;CACD;AAbD,oCAaC","sourcesContent":["import z, { ZodTypeAny } from 'zod';\nimport {\n\tChatroomMessageSendEvent,\n\tChatroomMessageSendInput,\n\tChatroomMessageSendOutput,\n} from '../events/chatroom-message-send.socket.event';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\n\ntype EventCtor<SIn extends ZodTypeAny, SOut extends ZodTypeAny, C extends BaseSocketEvent<SIn, SOut>> = new (\n\tdata: z.input<SOut>\n) => C;\n\nconst REGISTRY = {\n\t[SocketEventType.CHATROOM_MESSAGE_SEND]: {\n\t\tctor: ChatroomMessageSendEvent as EventCtor<\n\t\t\ttypeof ChatroomMessageSendInput,\n\t\t\ttypeof ChatroomMessageSendOutput,\n\t\t\tChatroomMessageSendEvent\n\t\t>,\n\t\tinput: ChatroomMessageSendEvent.schemas.input,\n\t\toutput: ChatroomMessageSendEvent.schemas.output,\n\t\tidentifier: ChatroomMessageSendEvent.identifier,\n\t},\n} as const;\n\ntype Registry = typeof REGISTRY;\n\ntype PayloadFor<T extends SocketEventType> = z.input<Registry[T]['output']>;\ntype EventFor<T extends SocketEventType> = InstanceType<Registry[T]['ctor']>;\n\nexport class EventFactory {\n\tpublic static createEvent<T extends SocketEventType>(SocketEventType: T, data: PayloadFor<T>): EventFor<T> {\n\t\tconst { ctor } = REGISTRY[SocketEventType];\n\t\treturn new ctor(data) as EventFor<T>;\n\t}\n\n\tpublic static getSubscriptionKey<T extends SocketEventType>(\n\t\tSocketEventType: T,\n\t\tinput: z.infer<(typeof REGISTRY)[T]['input']>\n\t): string {\n\t\tconst { identifier } = REGISTRY[SocketEventType];\n\t\treturn `${SocketEventType}:${identifier(input)}`;\n\t}\n}\n"]}
@@ -1,18 +1,18 @@
1
1
  import z from 'zod';
2
- import { BaseSocketEvent } from '../core/BaseSocketEvent';
3
2
  import { DTO } from '../../../utilities/validation';
4
- export declare const ChatroomMessageSendInput: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
5
- export declare const ChatroomMessageSendOutput: z.ZodObject<{
6
- chatroomId: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>;
3
+ import { BaseSocketEvent } from '../BaseSocketEvent';
4
+ export declare const ChatlistMessageSendInput: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
5
+ export declare const ChatlistMessageSendOutput: z.ZodObject<{
6
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
7
7
  lastMessage: z.ZodObject<{
8
8
  content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
9
- createdAt: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
9
+ createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
10
10
  }, "strip", z.ZodTypeAny, {
11
11
  content: string;
12
12
  createdAt: Date;
13
13
  }, {
14
14
  content: string;
15
- createdAt: string | Date;
15
+ createdAt: Date;
16
16
  }>;
17
17
  unreadCount: z.ZodNumber;
18
18
  }, "strip", z.ZodTypeAny, {
@@ -25,25 +25,25 @@ export declare const ChatroomMessageSendOutput: z.ZodObject<{
25
25
  }, {
26
26
  lastMessage: {
27
27
  content: string;
28
- createdAt: string | Date;
28
+ createdAt: Date;
29
29
  };
30
30
  unreadCount: number;
31
- chatroomId: string | import("mongoose").Types.ObjectId;
31
+ chatroomId: import("mongoose").Types.ObjectId;
32
32
  }>;
33
- export declare class ChatroomMessageSendEvent extends BaseSocketEvent<typeof ChatroomMessageSendInput, typeof ChatroomMessageSendOutput> {
33
+ export declare class ChatlistMessageSendEvent extends BaseSocketEvent<typeof ChatlistMessageSendInput, typeof ChatlistMessageSendOutput> {
34
34
  static readonly schemas: {
35
35
  input: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
36
36
  output: z.ZodObject<{
37
- chatroomId: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>;
37
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
38
38
  lastMessage: z.ZodObject<{
39
39
  content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
40
- createdAt: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>;
40
+ createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
41
41
  }, "strip", z.ZodTypeAny, {
42
42
  content: string;
43
43
  createdAt: Date;
44
44
  }, {
45
45
  content: string;
46
- createdAt: string | Date;
46
+ createdAt: Date;
47
47
  }>;
48
48
  unreadCount: z.ZodNumber;
49
49
  }, "strip", z.ZodTypeAny, {
@@ -56,12 +56,12 @@ export declare class ChatroomMessageSendEvent extends BaseSocketEvent<typeof Cha
56
56
  }, {
57
57
  lastMessage: {
58
58
  content: string;
59
- createdAt: string | Date;
59
+ createdAt: Date;
60
60
  };
61
61
  unreadCount: number;
62
- chatroomId: string | import("mongoose").Types.ObjectId;
62
+ chatroomId: import("mongoose").Types.ObjectId;
63
63
  }>;
64
64
  };
65
- constructor(payload: DTO<typeof ChatroomMessageSendOutput>);
65
+ constructor(payload: DTO<typeof ChatlistMessageSendOutput>);
66
66
  getIdentifier(): string;
67
67
  }
@@ -3,28 +3,28 @@ 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.ChatroomMessageSendEvent = exports.ChatroomMessageSendOutput = exports.ChatroomMessageSendInput = void 0;
6
+ exports.ChatlistMessageSendEvent = exports.ChatlistMessageSendOutput = exports.ChatlistMessageSendInput = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
- const BaseSocketEvent_1 = require("../core/BaseSocketEvent");
9
8
  const enum_1 = require("../../../utilities/enum");
10
9
  const validation_1 = require("../../../utilities/validation");
11
- exports.ChatroomMessageSendInput = zod_1.default.object({});
12
- exports.ChatroomMessageSendOutput = zod_1.default.object({
13
- chatroomId: validation_1.ZodValidation.objectId('chatroomId'),
10
+ const BaseSocketEvent_1 = require("../BaseSocketEvent");
11
+ exports.ChatlistMessageSendInput = zod_1.default.object({});
12
+ exports.ChatlistMessageSendOutput = zod_1.default.object({
13
+ chatroomId: validation_1.ZodValidation.coerce.objectId(),
14
14
  lastMessage: zod_1.default.object({
15
- content: validation_1.ZodValidation.string('content'),
16
- createdAt: validation_1.ZodValidation.date('createdAt'),
15
+ content: validation_1.ZodValidation.string(),
16
+ createdAt: validation_1.ZodValidation.coerce.date(),
17
17
  }),
18
- unreadCount: validation_1.ZodValidation.number('unreadCount').min(0),
18
+ unreadCount: validation_1.ZodValidation.number(),
19
19
  });
20
- class ChatroomMessageSendEvent extends BaseSocketEvent_1.BaseSocketEvent {
21
- static schemas = { input: exports.ChatroomMessageSendInput, output: exports.ChatroomMessageSendOutput };
20
+ class ChatlistMessageSendEvent extends BaseSocketEvent_1.BaseSocketEvent {
21
+ static schemas = { input: exports.ChatlistMessageSendInput, output: exports.ChatlistMessageSendOutput };
22
22
  constructor(payload) {
23
- super(enum_1.SocketEventType.CHATROOM_MESSAGE_SEND, ChatroomMessageSendEvent.schemas, payload);
23
+ super(enum_1.SocketEventType.CHATROOM_MESSAGE_SEND, ChatlistMessageSendEvent.schemas, payload);
24
24
  }
25
25
  getIdentifier() {
26
26
  return enum_1.SocketEventType.CHATROOM_MESSAGE_SEND;
27
27
  }
28
28
  }
29
- exports.ChatroomMessageSendEvent = ChatroomMessageSendEvent;
29
+ exports.ChatlistMessageSendEvent = ChatlistMessageSendEvent;
30
30
  //# sourceMappingURL=chatlist-message-send.socket.event.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chatlist-message-send.socket.event.js","sourceRoot":"/","sources":["libraries/socket/events/chatlist-message-send.socket.event.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoB;AACpB,6DAA0D;AAC1D,kDAA0D;AAC1D,8DAAmE;AAEtD,QAAA,wBAAwB,GAAG,aAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAExC,QAAA,yBAAyB,GAAG,aAAC,CAAC,MAAM,CAAC;IACjD,UAAU,EAAE,0BAAa,CAAC,QAAQ,CAAC,YAAY,CAAC;IAChD,WAAW,EAAE,aAAC,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,0BAAa,CAAC,MAAM,CAAC,SAAS,CAAC;QACxC,SAAS,EAAE,0BAAa,CAAC,IAAI,CAAC,WAAW,CAAC;KAC1C,CAAC;IACF,WAAW,EAAE,0BAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CACvD,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,iCAG7C;IACA,MAAM,CAAU,OAAO,GAAG,EAAE,KAAK,EAAE,gCAAwB,EAAE,MAAM,EAAE,iCAAyB,EAAE,CAAC;IAEjG,YAAY,OAA8C;QACzD,KAAK,CAAC,sBAAe,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzF,CAAC;IAEM,aAAa;QACnB,OAAO,sBAAe,CAAC,qBAAqB,CAAC;IAC9C,CAAC;;AAZF,4DAaC","sourcesContent":["import z from 'zod';\nimport { BaseSocketEvent } from '../core/BaseSocketEvent';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { DTO, ZodValidation } from '../../../utilities/validation';\n\nexport const ChatroomMessageSendInput = z.object({});\n\nexport const ChatroomMessageSendOutput = z.object({\n\tchatroomId: ZodValidation.objectId('chatroomId'),\n\tlastMessage: z.object({\n\t\tcontent: ZodValidation.string('content'),\n\t\tcreatedAt: ZodValidation.date('createdAt'),\n\t}),\n\tunreadCount: ZodValidation.number('unreadCount').min(0),\n});\n\nexport class ChatroomMessageSendEvent extends BaseSocketEvent<\n\ttypeof ChatroomMessageSendInput,\n\ttypeof ChatroomMessageSendOutput\n> {\n\tstatic readonly schemas = { input: ChatroomMessageSendInput, output: ChatroomMessageSendOutput };\n\n\tconstructor(payload: DTO<typeof ChatroomMessageSendOutput>) {\n\t\tsuper(SocketEventType.CHATROOM_MESSAGE_SEND, ChatroomMessageSendEvent.schemas, payload);\n\t}\n\n\tpublic getIdentifier(): string {\n\t\treturn SocketEventType.CHATROOM_MESSAGE_SEND;\n\t}\n}\n"]}
1
+ {"version":3,"file":"chatlist-message-send.socket.event.js","sourceRoot":"/","sources":["libraries/socket/events/chatlist-message-send.socket.event.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoB;AACpB,kDAA0D;AAC1D,8DAAmE;AACnE,wDAAqD;AAExC,QAAA,wBAAwB,GAAG,aAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAExC,QAAA,yBAAyB,GAAG,aAAC,CAAC,MAAM,CAAC;IACjD,UAAU,EAAE,0BAAa,CAAC,MAAM,CAAC,QAAQ,EAAE;IAC3C,WAAW,EAAE,aAAC,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,0BAAa,CAAC,MAAM,EAAE;QAC/B,SAAS,EAAE,0BAAa,CAAC,MAAM,CAAC,IAAI,EAAE;KACtC,CAAC;IACF,WAAW,EAAE,0BAAa,CAAC,MAAM,EAAE;CACnC,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,iCAG7C;IACA,MAAM,CAAU,OAAO,GAAG,EAAE,KAAK,EAAE,gCAAwB,EAAE,MAAM,EAAE,iCAAyB,EAAE,CAAC;IAEjG,YAAY,OAA8C;QACzD,KAAK,CAAC,sBAAe,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzF,CAAC;IAEM,aAAa;QACnB,OAAO,sBAAe,CAAC,qBAAqB,CAAC;IAC9C,CAAC;;AAZF,4DAaC","sourcesContent":["import z from 'zod';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { DTO, ZodValidation } from '../../../utilities/validation';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\n\nexport const ChatlistMessageSendInput = z.object({});\n\nexport const ChatlistMessageSendOutput = z.object({\n\tchatroomId: ZodValidation.coerce.objectId(),\n\tlastMessage: z.object({\n\t\tcontent: ZodValidation.string(),\n\t\tcreatedAt: ZodValidation.coerce.date(),\n\t}),\n\tunreadCount: ZodValidation.number(),\n});\n\nexport class ChatlistMessageSendEvent extends BaseSocketEvent<\n\ttypeof ChatlistMessageSendInput,\n\ttypeof ChatlistMessageSendOutput\n> {\n\tstatic readonly schemas = { input: ChatlistMessageSendInput, output: ChatlistMessageSendOutput };\n\n\tconstructor(payload: DTO<typeof ChatlistMessageSendOutput>) {\n\t\tsuper(SocketEventType.CHATROOM_MESSAGE_SEND, ChatlistMessageSendEvent.schemas, payload);\n\t}\n\n\tpublic getIdentifier(): string {\n\t\treturn SocketEventType.CHATROOM_MESSAGE_SEND;\n\t}\n}\n"]}
@@ -1,53 +1,53 @@
1
1
  import z from 'zod';
2
- import { BaseSocketEvent } from '../core/BaseSocketEvent';
3
2
  import { DTO } from '../../../utilities/validation';
3
+ import { BaseSocketEvent } from '../BaseSocketEvent';
4
4
  export declare const ChatroomMessageSendInput: z.ZodObject<{
5
- chatId: z.ZodString;
5
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
6
6
  }, "strip", z.ZodTypeAny, {
7
- chatId: string;
7
+ chatroomId: import("mongoose").Types.ObjectId;
8
8
  }, {
9
- chatId: string;
9
+ chatroomId: import("mongoose").Types.ObjectId;
10
10
  }>;
11
11
  export declare const ChatroomMessageSendOutput: z.ZodObject<{
12
- chatId: z.ZodString;
13
- messageId: z.ZodString;
14
- content: z.ZodString;
15
- createdAt: z.ZodDate;
12
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
13
+ messageId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
14
+ content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
15
+ createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
16
16
  }, "strip", z.ZodTypeAny, {
17
17
  content: string;
18
18
  createdAt: Date;
19
- chatId: string;
20
- messageId: string;
19
+ chatroomId: import("mongoose").Types.ObjectId;
20
+ messageId: import("mongoose").Types.ObjectId;
21
21
  }, {
22
22
  content: string;
23
23
  createdAt: Date;
24
- chatId: string;
25
- messageId: string;
24
+ chatroomId: import("mongoose").Types.ObjectId;
25
+ messageId: import("mongoose").Types.ObjectId;
26
26
  }>;
27
27
  export declare class ChatroomMessageSendEvent extends BaseSocketEvent<typeof ChatroomMessageSendInput, typeof ChatroomMessageSendOutput> {
28
28
  static readonly schemas: {
29
29
  input: z.ZodObject<{
30
- chatId: z.ZodString;
30
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
31
31
  }, "strip", z.ZodTypeAny, {
32
- chatId: string;
32
+ chatroomId: import("mongoose").Types.ObjectId;
33
33
  }, {
34
- chatId: string;
34
+ chatroomId: import("mongoose").Types.ObjectId;
35
35
  }>;
36
36
  output: z.ZodObject<{
37
- chatId: z.ZodString;
38
- messageId: z.ZodString;
39
- content: z.ZodString;
40
- createdAt: z.ZodDate;
37
+ chatroomId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
38
+ messageId: z.ZodEffects<z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>, import("mongoose").Types.ObjectId, import("mongoose").Types.ObjectId>;
39
+ content: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
40
+ createdAt: z.ZodEffects<z.ZodEffects<z.ZodDate, Date, Date>, Date, Date>;
41
41
  }, "strip", z.ZodTypeAny, {
42
42
  content: string;
43
43
  createdAt: Date;
44
- chatId: string;
45
- messageId: string;
44
+ chatroomId: import("mongoose").Types.ObjectId;
45
+ messageId: import("mongoose").Types.ObjectId;
46
46
  }, {
47
47
  content: string;
48
48
  createdAt: Date;
49
- chatId: string;
50
- messageId: string;
49
+ chatroomId: import("mongoose").Types.ObjectId;
50
+ messageId: import("mongoose").Types.ObjectId;
51
51
  }>;
52
52
  };
53
53
  constructor(payload: DTO<typeof ChatroomMessageSendOutput>);
@@ -5,16 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ChatroomMessageSendEvent = exports.ChatroomMessageSendOutput = exports.ChatroomMessageSendInput = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
- const BaseSocketEvent_1 = require("../core/BaseSocketEvent");
9
8
  const enum_1 = require("../../../utilities/enum");
9
+ const validation_1 = require("../../../utilities/validation");
10
+ const BaseSocketEvent_1 = require("../BaseSocketEvent");
10
11
  exports.ChatroomMessageSendInput = zod_1.default.object({
11
- chatId: zod_1.default.string(),
12
+ chatroomId: validation_1.ZodValidation.coerce.objectId(),
12
13
  });
13
14
  exports.ChatroomMessageSendOutput = zod_1.default.object({
14
- chatId: zod_1.default.string(),
15
- messageId: zod_1.default.string(),
16
- content: zod_1.default.string(),
17
- createdAt: zod_1.default.coerce.date(),
15
+ chatroomId: validation_1.ZodValidation.coerce.objectId(),
16
+ messageId: validation_1.ZodValidation.coerce.objectId(),
17
+ content: validation_1.ZodValidation.string(),
18
+ createdAt: validation_1.ZodValidation.coerce.date(),
18
19
  });
19
20
  class ChatroomMessageSendEvent extends BaseSocketEvent_1.BaseSocketEvent {
20
21
  static schemas = { input: exports.ChatroomMessageSendInput, output: exports.ChatroomMessageSendOutput };
@@ -25,7 +26,7 @@ class ChatroomMessageSendEvent extends BaseSocketEvent_1.BaseSocketEvent {
25
26
  return enum_1.SocketEventType.CHATROOM_MESSAGE_SEND + ':' + ChatroomMessageSendEvent.identifier(this.data);
26
27
  }
27
28
  static identifier(input) {
28
- return input.chatId;
29
+ return input.chatroomId.toString();
29
30
  }
30
31
  }
31
32
  exports.ChatroomMessageSendEvent = ChatroomMessageSendEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"chatroom-message-send.socket.event.js","sourceRoot":"/","sources":["libraries/socket/events/chatroom-message-send.socket.event.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoB;AACpB,6DAA0D;AAC1D,kDAA0D;AAG7C,QAAA,wBAAwB,GAAG,aAAC,CAAC,MAAM,CAAC;IAChD,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,aAAC,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,aAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE;IACnB,SAAS,EAAE,aAAC,CAAC,MAAM,CAAC,IAAI,EAAE;CAC1B,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,iCAG7C;IACA,MAAM,CAAU,OAAO,GAAG,EAAE,KAAK,EAAE,gCAAwB,EAAE,MAAM,EAAE,iCAAyB,EAAE,CAAC;IAEjG,YAAY,OAA8C;QACzD,KAAK,CAAC,sBAAe,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzF,CAAC;IAEM,aAAa;QACnB,OAAO,sBAAe,CAAC,qBAAqB,GAAG,GAAG,GAAG,wBAAwB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrG,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAA+C;QAChE,OAAO,KAAK,CAAC,MAAM,CAAC;IACrB,CAAC;;AAhBF,4DAiBC","sourcesContent":["import z from 'zod';\nimport { BaseSocketEvent } from '../core/BaseSocketEvent';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { DTO } from '../../../utilities/validation';\n\nexport const ChatroomMessageSendInput = z.object({\n\tchatId: z.string(),\n});\n\nexport const ChatroomMessageSendOutput = z.object({\n\tchatId: z.string(),\n\tmessageId: z.string(),\n\tcontent: z.string(),\n\tcreatedAt: z.coerce.date(),\n});\n\nexport class ChatroomMessageSendEvent extends BaseSocketEvent<\n\ttypeof ChatroomMessageSendInput,\n\ttypeof ChatroomMessageSendOutput\n> {\n\tstatic readonly schemas = { input: ChatroomMessageSendInput, output: ChatroomMessageSendOutput };\n\n\tconstructor(payload: DTO<typeof ChatroomMessageSendOutput>) {\n\t\tsuper(SocketEventType.CHATROOM_MESSAGE_SEND, ChatroomMessageSendEvent.schemas, payload);\n\t}\n\n\tpublic getIdentifier(): string {\n\t\treturn SocketEventType.CHATROOM_MESSAGE_SEND + ':' + ChatroomMessageSendEvent.identifier(this.data);\n\t}\n\n\tstatic identifier(input: z.infer<typeof ChatroomMessageSendInput>): string {\n\t\treturn input.chatId;\n\t}\n}\n"]}
1
+ {"version":3,"file":"chatroom-message-send.socket.event.js","sourceRoot":"/","sources":["libraries/socket/events/chatroom-message-send.socket.event.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAoB;AACpB,kDAA0D;AAC1D,8DAAmE;AACnE,wDAAqD;AAExC,QAAA,wBAAwB,GAAG,aAAC,CAAC,MAAM,CAAC;IAChD,UAAU,EAAE,0BAAa,CAAC,MAAM,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,aAAC,CAAC,MAAM,CAAC;IACjD,UAAU,EAAE,0BAAa,CAAC,MAAM,CAAC,QAAQ,EAAE;IAC3C,SAAS,EAAE,0BAAa,CAAC,MAAM,CAAC,QAAQ,EAAE;IAC1C,OAAO,EAAE,0BAAa,CAAC,MAAM,EAAE;IAC/B,SAAS,EAAE,0BAAa,CAAC,MAAM,CAAC,IAAI,EAAE;CACtC,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,iCAG7C;IACA,MAAM,CAAU,OAAO,GAAG,EAAE,KAAK,EAAE,gCAAwB,EAAE,MAAM,EAAE,iCAAyB,EAAE,CAAC;IAEjG,YAAY,OAA8C;QACzD,KAAK,CAAC,sBAAe,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzF,CAAC;IAEM,aAAa;QACnB,OAAO,sBAAe,CAAC,qBAAqB,GAAG,GAAG,GAAG,wBAAwB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrG,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAA+C;QAChE,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,CAAC;;AAhBF,4DAiBC","sourcesContent":["import z from 'zod';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { DTO, ZodValidation } from '../../../utilities/validation';\nimport { BaseSocketEvent } from '../BaseSocketEvent';\n\nexport const ChatroomMessageSendInput = z.object({\n\tchatroomId: ZodValidation.coerce.objectId(),\n});\n\nexport const ChatroomMessageSendOutput = z.object({\n\tchatroomId: ZodValidation.coerce.objectId(),\n\tmessageId: ZodValidation.coerce.objectId(),\n\tcontent: ZodValidation.string(),\n\tcreatedAt: ZodValidation.coerce.date(),\n});\n\nexport class ChatroomMessageSendEvent extends BaseSocketEvent<\n\ttypeof ChatroomMessageSendInput,\n\ttypeof ChatroomMessageSendOutput\n> {\n\tstatic readonly schemas = { input: ChatroomMessageSendInput, output: ChatroomMessageSendOutput };\n\n\tconstructor(payload: DTO<typeof ChatroomMessageSendOutput>) {\n\t\tsuper(SocketEventType.CHATROOM_MESSAGE_SEND, ChatroomMessageSendEvent.schemas, payload);\n\t}\n\n\tpublic getIdentifier(): string {\n\t\treturn SocketEventType.CHATROOM_MESSAGE_SEND + ':' + ChatroomMessageSendEvent.identifier(this.data);\n\t}\n\n\tstatic identifier(input: z.infer<typeof ChatroomMessageSendInput>): string {\n\t\treturn input.chatroomId.toString();\n\t}\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  export * from './events';
2
2
  export * from './adapters';
3
3
  export * from './core';
4
+ export * from './BaseSocketEvent';
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./events"), exports);
18
18
  __exportStar(require("./adapters"), exports);
19
19
  __exportStar(require("./core"), exports);
20
+ __exportStar(require("./BaseSocketEvent"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/socket/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,yCAAuB","sourcesContent":["export * from './events';\nexport * from './adapters';\nexport * from './core';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/socket/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,yCAAuB;AACvB,oDAAkC","sourcesContent":["export * from './events';\nexport * from './adapters';\nexport * from './core';\nexport * from './BaseSocketEvent';\n"]}
@@ -0,0 +1,14 @@
1
+ import { z, ZodTypeAny } from 'zod';
2
+ import { SocketEventType } from '../../../utilities/enum';
3
+ import { AuthEntityType } from '../../auth';
4
+ export declare function createSocketSubscriptionProcedure<I extends ZodTypeAny, O extends ZodTypeAny>({ eventType, entityTypes, inputSchema, outputSchema, getId, }: {
5
+ eventType: SocketEventType;
6
+ entityTypes: AuthEntityType[];
7
+ inputSchema: I;
8
+ outputSchema: O;
9
+ getId: (out: z.infer<O>) => string;
10
+ }): import("@trpc/server").TRPCSubscriptionProcedure<{
11
+ input: import("@trpc/server/dist/unstable-core-do-not-import.d-C6mFWtNG.cjs").inferParser<I>["in"] extends infer T ? T extends import("@trpc/server/dist/unstable-core-do-not-import.d-C6mFWtNG.cjs").inferParser<I>["in"] ? T extends import("@trpc/server").TRPCUnsetMarker ? void : T : never : never;
12
+ output: AsyncIterable<import("@trpc/server/dist/unstable-core-do-not-import.d-C6mFWtNG.cjs").TrackedData<any>, void, unknown>;
13
+ meta: object;
14
+ }>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSocketSubscriptionProcedure = createSocketSubscriptionProcedure;
4
+ const auth_1 = require("./auth");
5
+ const socket_1 = require("../../socket");
6
+ const crypto_1 = require("crypto");
7
+ const instance_utils_1 = require("../../../utilities/instance.utils");
8
+ const ws_1 = require("ws");
9
+ const server_1 = require("@trpc/server");
10
+ function createSocketSubscriptionProcedure({ eventType, entityTypes, inputSchema, outputSchema, getId, }) {
11
+ return (0, auth_1.createAuthenticatedProcedure)({ entityTypes })
12
+ .input(inputSchema)
13
+ .output((0, socket_1.zAsyncIterable)({
14
+ yield: outputSchema,
15
+ tracked: true,
16
+ }))
17
+ .subscription(async function* (opts) {
18
+ const socketId = (0, crypto_1.randomUUID)();
19
+ const localEE = new socket_1.LocalEventEmitter(socketId);
20
+ const entityId = opts.ctx.entity.id;
21
+ const eventKey = socket_1.EventFactory.getSubscriptionKey(eventType, opts.input);
22
+ const instanceId = (0, instance_utils_1.getInstanceId)();
23
+ const socketInfo = { socketId, eventKey, instanceId };
24
+ await (0, socket_1.connectEntityToSocketEvent)(entityId, socketInfo);
25
+ socket_1.LocalSubs.bind(entityId, eventKey, localEE);
26
+ opts.signal?.addEventListener('abort', () => {
27
+ socket_1.LocalSubs.unbind(entityId, eventKey, localEE);
28
+ (0, socket_1.disconnectEntityFromSocketEvent)(entityId, socketInfo).catch(console.error);
29
+ });
30
+ for await (const [data] of (0, ws_1.on)(localEE.ee, eventKey, {
31
+ signal: opts.signal,
32
+ })) {
33
+ const payload = data;
34
+ yield (0, server_1.tracked)(getId(payload), payload);
35
+ }
36
+ });
37
+ }
38
+ //# sourceMappingURL=createSocketSubscriptionProcedure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSocketSubscriptionProcedure.js","sourceRoot":"/","sources":["libraries/trpc/middlewares/createSocketSubscriptionProcedure.ts"],"names":[],"mappings":";;AAiBA,8EAgDC;AA9DD,iCAAsD;AACtD,yCAOsB;AACtB,mCAAoC;AACpC,sEAAkE;AAClE,2BAAwB;AACxB,yCAAuC;AAEvC,SAAgB,iCAAiC,CAA6C,EAC7F,SAAS,EACT,WAAW,EACX,WAAW,EACX,YAAY,EACZ,KAAK,GAOL;IACA,OAAO,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC;SAClD,KAAK,CAAC,WAAW,CAAC;SAClB,MAAM,CACN,IAAA,uBAAc,EAAC;QACd,KAAK,EAAE,YAAY;QACnB,OAAO,EAAE,IAAI;KACb,CAAC,CACF;SACA,YAAY,CAAC,KAAK,SAAS,CAAC,EAAE,IAAI;QAClC,MAAM,QAAQ,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,0BAAiB,CAAC,QAAQ,CAAC,CAAC;QAEhD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAO,CAAC,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,qBAAY,CAAC,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,MAAM,UAAU,GAAG,IAAA,8BAAa,GAAE,CAAC;QACnC,MAAM,UAAU,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;QAEtD,MAAM,IAAA,mCAA0B,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEvD,kBAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE5C,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAC3C,kBAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC9C,IAAA,wCAA+B,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;QAIH,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAA,OAAE,EAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE;YACnD,MAAM,EAAE,IAAI,CAAC,MAAM;SACnB,CAAC,EAAE,CAAC;YACJ,MAAM,OAAO,GAAG,IAAW,CAAC;YAC5B,MAAM,IAAA,gBAAO,EAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { z, ZodTypeAny } from 'zod';\nimport { SocketEventType } from '../../../utilities/enum';\nimport { AuthEntityType } from '../../auth';\nimport { createAuthenticatedProcedure } from './auth';\nimport {\n\tconnectEntityToSocketEvent,\n\tdisconnectEntityFromSocketEvent,\n\tEventFactory,\n\tLocalEventEmitter,\n\tLocalSubs,\n\tzAsyncIterable,\n} from '../../socket';\nimport { randomUUID } from 'crypto';\nimport { getInstanceId } from '../../../utilities/instance.utils';\nimport { on } from 'ws';\nimport { tracked } from '@trpc/server';\n\nexport function createSocketSubscriptionProcedure<I extends ZodTypeAny, O extends ZodTypeAny>({\n\teventType,\n\tentityTypes,\n\tinputSchema,\n\toutputSchema,\n\tgetId,\n}: {\n\teventType: SocketEventType;\n\tentityTypes: AuthEntityType[];\n\tinputSchema: I;\n\toutputSchema: O;\n\tgetId: (out: z.infer<O>) => string;\n}) {\n\treturn createAuthenticatedProcedure({ entityTypes })\n\t\t.input(inputSchema)\n\t\t.output(\n\t\t\tzAsyncIterable({\n\t\t\t\tyield: outputSchema,\n\t\t\t\ttracked: true,\n\t\t\t})\n\t\t)\n\t\t.subscription(async function* (opts) {\n\t\t\tconst socketId = randomUUID();\n\t\t\tconst localEE = new LocalEventEmitter(socketId);\n\n\t\t\tconst entityId = opts.ctx.entity!.id;\n\t\t\tconst eventKey = EventFactory.getSubscriptionKey(eventType, opts.input);\n\t\t\tconst instanceId = getInstanceId();\n\t\t\tconst socketInfo = { socketId, eventKey, instanceId };\n\n\t\t\tawait connectEntityToSocketEvent(entityId, socketInfo);\n\n\t\t\tLocalSubs.bind(entityId, eventKey, localEE);\n\n\t\t\topts.signal?.addEventListener('abort', () => {\n\t\t\t\tLocalSubs.unbind(entityId, eventKey, localEE);\n\t\t\t\tdisconnectEntityFromSocketEvent(entityId, socketInfo).catch(console.error);\n\t\t\t});\n\n\t\t\ttype Out = z.infer<O>;\n\n\t\t\tfor await (const [data] of on(localEE.ee, eventKey, {\n\t\t\t\tsignal: opts.signal,\n\t\t\t})) {\n\t\t\t\tconst payload = data as Out;\n\t\t\t\tyield tracked(getId(payload), payload);\n\t\t\t}\n\t\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.381
25
+ Version: 1.0.382
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.0.381",
3
+ "version": "1.0.382",
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",