@lyxa.ai/core 1.3.32 → 1.3.33

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.
@@ -23,6 +23,7 @@ let LyxaLogger = class LyxaLogger {
23
23
  constructor(identifier, mongoURI) {
24
24
  this.logDirectory = path_1.default.join(process.cwd(), 'logs');
25
25
  this.ensureLogDirectoryExists();
26
+ const baseLevel = process.env.NODE_ENV === 'DEV' || process.env.NODE_ENV === undefined ? 'debug' : 'info';
26
27
  const transports = pino_1.pino.transport({
27
28
  targets: [
28
29
  {
@@ -30,7 +31,7 @@ let LyxaLogger = class LyxaLogger {
30
31
  options: {
31
32
  colorize: true,
32
33
  },
33
- level: 'info',
34
+ level: baseLevel,
34
35
  },
35
36
  {
36
37
  target: 'pino/file',
@@ -51,7 +52,7 @@ let LyxaLogger = class LyxaLogger {
51
52
  ],
52
53
  });
53
54
  this._logger = (0, pino_1.pino)({
54
- level: 'info',
55
+ level: baseLevel,
55
56
  }, transports);
56
57
  }
57
58
  ensureLogDirectoryExists() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,+BAAoC;AACpC,mCAAiC;AAG1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACL,OAAO,CAAS;IAChB,YAAY,CAAS;IAEtC,YAAY,UAAkB,EAAE,QAAgB;QAC/C,IAAI,CAAC,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;QAErD,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAEhC,MAAM,UAAU,GAAG,WAAI,CAAC,SAAS,CAAC;YACjC,OAAO,EAAE;gBACR;oBACC,MAAM,EAAE,aAAa;oBACrB,OAAO,EAAE;wBACR,QAAQ,EAAE,IAAI;qBACd;oBACD,KAAK,EAAE,MAAM;iBACb;gBACD;oBACC,MAAM,EAAE,WAAW;oBACnB,OAAO,EAAE;wBACR,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;qBACtD;oBACD,KAAK,EAAE,OAAO;iBACd;gBACD;oBACC,MAAM,EAAE,cAAc;oBACtB,OAAO,EAAE;wBACR,GAAG,EAAE,QAAQ;wBACb,QAAQ,EAAE,WAAW;wBACrB,UAAU,EAAE,UAAU;qBACtB;oBACD,KAAK,EAAE,OAAO;iBACd;aACD;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,GAAG,IAAA,WAAI,EAClB;YACC,KAAK,EAAE,MAAM;SACb,EACD,UAAU,CACV,CAAC;IACH,CAAC;IAEO,wBAAwB;QAC/B,IAAI,CAAC;YACJ,YAAE,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD,CAAA;AAxDY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CAwDtB","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { pino, Logger } from 'pino';\nimport { Service } from 'typedi';\n\n@Service()\nexport class LyxaLogger {\n\tprivate readonly _logger: Logger;\n\tprivate readonly logDirectory: string;\n\n\tconstructor(identifier: string, mongoURI: string) {\n\t\tthis.logDirectory = path.join(process.cwd(), 'logs');\n\n\t\tthis.ensureLogDirectoryExists();\n\n\t\tconst transports = pino.transport({\n\t\t\ttargets: [\n\t\t\t\t{\n\t\t\t\t\ttarget: 'pino-pretty',\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tcolorize: true,\n\t\t\t\t\t},\n\t\t\t\t\tlevel: 'info',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttarget: 'pino/file',\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tdestination: path.join(this.logDirectory, 'error.log'),\n\t\t\t\t\t},\n\t\t\t\t\tlevel: 'error',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttarget: 'pino-mongodb',\n\t\t\t\t\toptions: {\n\t\t\t\t\t\turi: mongoURI,\n\t\t\t\t\t\tdatabase: 'lyxa-logs',\n\t\t\t\t\t\tcollection: identifier,\n\t\t\t\t\t},\n\t\t\t\t\tlevel: 'error',\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tthis._logger = pino(\n\t\t\t{\n\t\t\t\tlevel: 'info',\n\t\t\t},\n\t\t\ttransports\n\t\t);\n\t}\n\n\tprivate ensureLogDirectoryExists(): void {\n\t\ttry {\n\t\t\tfs.mkdirSync(this.logDirectory, { recursive: true });\n\t\t} catch (error) {\n\t\t\tconsole.error('Failed to create log directory:', error);\n\t\t}\n\t}\n\n\tget logger(): Logger {\n\t\treturn this._logger;\n\t}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,+BAAoC;AACpC,mCAAiC;AAG1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACL,OAAO,CAAS;IAChB,YAAY,CAAS;IAEtC,YAAY,UAAkB,EAAE,QAAgB;QAC/C,IAAI,CAAC,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;QAErD,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAEhC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;QAE1G,MAAM,UAAU,GAAG,WAAI,CAAC,SAAS,CAAC;YACjC,OAAO,EAAE;gBACR;oBACC,MAAM,EAAE,aAAa;oBACrB,OAAO,EAAE;wBACR,QAAQ,EAAE,IAAI;qBACd;oBACD,KAAK,EAAE,SAAS;iBAChB;gBACD;oBACC,MAAM,EAAE,WAAW;oBACnB,OAAO,EAAE;wBACR,WAAW,EAAE,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;qBACtD;oBACD,KAAK,EAAE,OAAO;iBACd;gBACD;oBACC,MAAM,EAAE,cAAc;oBACtB,OAAO,EAAE;wBACR,GAAG,EAAE,QAAQ;wBACb,QAAQ,EAAE,WAAW;wBACrB,UAAU,EAAE,UAAU;qBACtB;oBACD,KAAK,EAAE,OAAO;iBACd;aACD;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,GAAG,IAAA,WAAI,EAClB;YACC,KAAK,EAAE,SAAS;SAChB,EACD,UAAU,CACV,CAAC;IACH,CAAC;IAEO,wBAAwB;QAC/B,IAAI,CAAC;YACJ,YAAE,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD,CAAA;AA1DY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA0DtB","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { Logger, pino } from 'pino';\nimport { Service } from 'typedi';\n\n@Service()\nexport class LyxaLogger {\n\tprivate readonly _logger: Logger;\n\tprivate readonly logDirectory: string;\n\n\tconstructor(identifier: string, mongoURI: string) {\n\t\tthis.logDirectory = path.join(process.cwd(), 'logs');\n\n\t\tthis.ensureLogDirectoryExists();\n\n\t\tconst baseLevel = process.env.NODE_ENV === 'DEV' || process.env.NODE_ENV === undefined ? 'debug' : 'info';\n\n\t\tconst transports = pino.transport({\n\t\t\ttargets: [\n\t\t\t\t{\n\t\t\t\t\ttarget: 'pino-pretty',\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tcolorize: true,\n\t\t\t\t\t},\n\t\t\t\t\tlevel: baseLevel,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttarget: 'pino/file',\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tdestination: path.join(this.logDirectory, 'error.log'),\n\t\t\t\t\t},\n\t\t\t\t\tlevel: 'error',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttarget: 'pino-mongodb',\n\t\t\t\t\toptions: {\n\t\t\t\t\t\turi: mongoURI,\n\t\t\t\t\t\tdatabase: 'lyxa-logs',\n\t\t\t\t\t\tcollection: identifier,\n\t\t\t\t\t},\n\t\t\t\t\tlevel: 'error',\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tthis._logger = pino(\n\t\t\t{\n\t\t\t\tlevel: baseLevel,\n\t\t\t},\n\t\t\ttransports\n\t\t);\n\t}\n\n\tprivate ensureLogDirectoryExists(): void {\n\t\ttry {\n\t\t\tfs.mkdirSync(this.logDirectory, { recursive: true });\n\t\t} catch (error) {\n\t\t\tconsole.error('Failed to create log directory:', error);\n\t\t}\n\t}\n\n\tget logger(): Logger {\n\t\treturn this._logger;\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { SocketEventType } from '../../../utilities/enum';
2
- import { InputFor } from '../index';
2
+ import { InputFor, OutputFor } from '../core';
3
3
  import { TokenType } from '../../auth';
4
4
  import { ProcedureResolverOptions } from '@trpc/server/unstable-core-do-not-import';
5
5
  import { EntityContext, LyxaHTTPContext } from '../../trpc/context';
@@ -12,5 +12,5 @@ type optsType<TEventType extends SocketEventType, TInput extends InputFor<TEvent
12
12
  usedRefreshToken: boolean | undefined;
13
13
  tokenRenewed: boolean | undefined;
14
14
  }, TInput>;
15
- export declare function createSocketSubscriptionAdapter<TEventType extends SocketEventType, TInput extends InputFor<TEventType>>(eventType: TEventType): (opts: optsType<TEventType, TInput>) => AsyncGenerator<any, void, unknown>;
15
+ export declare function createSocketSubscriptionAdapter<TEventType extends SocketEventType, TInput extends InputFor<TEventType>>(eventType: TEventType): (opts: optsType<TEventType, TInput>) => AsyncGenerator<Awaited<OutputFor<TEventType>>, void, unknown>;
16
16
  export {};
@@ -1,30 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSocketSubscriptionAdapter = createSocketSubscriptionAdapter;
4
- const index_1 = require("../index");
4
+ const core_1 = require("../core");
5
5
  const crypto_1 = require("crypto");
6
6
  const instance_utils_1 = require("../../../utilities/instance.utils");
7
7
  const events_1 = require("events");
8
+ const index_1 = require("../../../index");
8
9
  async function* _createSocketSubscription(eventType, opts) {
9
10
  const { ctx } = opts;
10
- console.log('Options are: ', opts);
11
+ const logger = (0, index_1.getLibraries)().getLogger().logger;
11
12
  const entity = { id: ctx.entity.id, type: ctx.entity.type };
12
- const eventKey = index_1.EventFactory.getSubscriptionKey(eventType, opts.input);
13
+ const eventKey = core_1.EventFactory.getSubscriptionKey(eventType, opts.input);
13
14
  const socketId = (0, crypto_1.randomUUID)();
14
15
  const socketInfo = { socketId, eventKey, instanceId: (0, instance_utils_1.getInstanceId)() };
15
- const localEE = new index_1.LocalEventEmitter(socketId);
16
- await (0, index_1.connectEntityToSocketEvent)(entity, socketInfo);
17
- index_1.LocalSubs.bind(entity, eventKey, localEE);
16
+ const localEE = new core_1.LocalEventEmitter(socketId);
17
+ await (0, core_1.connectEntityToSocketEvent)(entity, socketInfo);
18
+ core_1.LocalSubs.bind(entity, eventKey, localEE);
19
+ logger.debug({ entity, socketId, eventKey }, 'Socket subscription connected');
18
20
  opts.signal?.addEventListener('abort', () => {
19
- index_1.LocalSubs.unbind(entity, eventKey, localEE);
20
- (0, index_1.disconnectEntityFromSocketEvent)(entity, socketInfo).catch(console.error);
21
- console.log('Unsubscribed from event listener:', entity.id, socketId);
22
- console.log('Abort signal reason:', opts.signal?.reason);
23
- console.log('Abort signal reason:', opts.signal);
21
+ core_1.LocalSubs.unbind(entity, eventKey, localEE);
22
+ (0, core_1.disconnectEntityFromSocketEvent)(entity, socketInfo);
23
+ logger.debug({ entity, socketId, eventKey }, 'Socket subscription disconnected');
24
24
  });
25
- yield { _ready: true };
26
25
  for await (const [data] of (0, events_1.on)(localEE.ee, eventKey, { signal: opts.signal })) {
27
- console.log('Yielding event with signal:', opts.signal);
26
+ logger.debug({ entity, socketId, eventKey, data }, 'Socket subscription sending data');
28
27
  yield data;
29
28
  }
30
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"socket-subscription.js","sourceRoot":"/","sources":["libraries/socket/adapters/socket-subscription.ts"],"names":[],"mappings":";;AAqFA,0EAKC;AAzFD,oCASkB;AAClB,mCAAoC;AACpC,sEAAkE;AAIlE,mCAA4B;AA8B5B,KAAK,SAAS,CAAC,CAAC,yBAAyB,CAGvC,SAAqB,EAAE,IAAkC;IAC1D,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErB,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAEnC,MAAM,MAAM,GAAuB,EAAE,EAAE,EAAE,GAAG,CAAC,MAAO,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,MAAO,CAAC,IAAI,EAAE,CAAC;IAElF,MAAM,QAAQ,GAAG,oBAAY,CAAC,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG,IAAA,mBAAU,GAAE,CAAC;IAC9B,MAAM,UAAU,GAAG,EAAE,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EAAE,IAAI,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { SocketEventType } from '../../../utilities/enum';\nimport {\n\tconnectEntityToSocketEvent,\n\tdisconnectEntityFromSocketEvent,\n\tEntitySubscription,\n\tEventFactory,\n\tInputFor,\n\tLocalEventEmitter,\n\tLocalSubs,\n\tOutputFor,\n} from '../index';\nimport { randomUUID } from 'crypto';\nimport { getInstanceId } from '../../../utilities/instance.utils';\nimport { AuthEntityType, TokenType } from '../../auth';\nimport { ProcedureResolverOptions } from '@trpc/server/unstable-core-do-not-import';\nimport { EntityContext, LyxaHTTPContext } from '../../trpc/context';\nimport { on } from 'events';\n\ntype optsType<\n\tTEventType extends SocketEventType,\n\tTInput extends InputFor<TEventType>,\n> = ProcedureResolverOptions<\n\tobject,\n\tLyxaHTTPContext,\n\t{\n\t\tres: import('http').ServerResponse<import('http').IncomingMessage>;\n\t\ttokenType: TokenType | undefined;\n\t\tentity: EntityContext | undefined;\n\t\treq: import('http').IncomingMessage;\n\t\trequestId: string | undefined;\n\t\tusedRefreshToken: boolean | undefined;\n\t\ttokenRenewed: boolean | undefined;\n\t},\n\tTInput\n>;\n\ninterface _SubscriptionContext {\n\tentity?: { id: string; type: AuthEntityType };\n\tsignal?: AbortSignal;\n}\n\ninterface _SubscriptionOpts<TEventType extends SocketEventType, TInput extends InputFor<TEventType>> {\n\tctx: _SubscriptionContext;\n\tinput: TInput;\n}\n\nasync function* _createSocketSubscription<\n\tTEventType extends SocketEventType,\n\tTInput extends InputFor<TEventType>,\n>(eventType: TEventType, opts: optsType<TEventType, TInput>) {\n\tconst { ctx } = opts;\n\n\tconsole.log('Options are: ', opts);\n\n\tconst entity: EntitySubscription = { id: ctx.entity!.id, type: ctx.entity!.type };\n\n\tconst eventKey = EventFactory.getSubscriptionKey(eventType, opts.input);\n\tconst socketId = randomUUID();\n\tconst socketInfo = { socketId, eventKey, instanceId: getInstanceId() };\n\n\tconst localEE = new LocalEventEmitter(socketId);\n\n\t// Setup: connect to Redis and local registry\n\tawait connectEntityToSocketEvent(entity, socketInfo);\n\tLocalSubs.bind(entity, eventKey, localEE);\n\n\t// Cleanup on abort\n\topts.signal?.addEventListener('abort', () => {\n\t\tLocalSubs.unbind(entity, eventKey, localEE);\n\t\tdisconnectEntityFromSocketEvent(entity, socketInfo).catch(console.error);\n\t\tconsole.log('Unsubscribed from event listener:', entity.id, socketId);\n\t\tconsole.log('Abort signal reason:', opts.signal?.reason);\n\t\tconsole.log('Abort signal reason:', opts.signal);\n\t});\n\n\tyield { _ready: true } as any;\n\n\t// Stream events\n\ttype Out = OutputFor<TEventType>;\n\tfor await (const [data] of on(localEE.ee, eventKey, { signal: opts.signal })) {\n\t\tconsole.log('Yielding event with signal:', opts.signal);\n\t\tyield data as Out;\n\t}\n}\n\nexport function createSocketSubscriptionAdapter<\n\tTEventType extends SocketEventType,\n\tTInput extends InputFor<TEventType>,\n>(eventType: TEventType) {\n\treturn (opts: optsType<TEventType, TInput>) => _createSocketSubscription(eventType, opts);\n}\n\n/**\n * @Example\n * const socketRouterTwo = createTRPCRouter({\n * \tonMessage: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM] })\n * \t\t.input(ChatroomMessageSendSocketInputSchema)\n * \t\t.output(zAsyncIterable({ yield: ChatroomMessageSendOutputSchema }))\n * \t\t.subscription(createSocketSubscriptionAdapter(SocketEventType.CHATROOM_MESSAGE_SEND)),\n * });\n */\n"]}
1
+ {"version":3,"file":"socket-subscription.js","sourceRoot":"/","sources":["libraries/socket/adapters/socket-subscription.ts"],"names":[],"mappings":";;AAiFA,0EAKC;AArFD,kCASiB;AACjB,mCAAoC;AACpC,sEAAkE;AAIlE,mCAA4B;AAC5B,0CAA8C;AA8B9C,KAAK,SAAS,CAAC,CAAC,yBAAyB,CAGvC,SAAqB,EAAE,IAAkC;IAC1D,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACrB,MAAM,MAAM,GAAG,IAAA,oBAAY,GAAE,CAAC,SAAS,EAAE,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C,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,kCAAkC,CAAC,CAAC;QACvF,MAAM,IAAW,CAAC;IACnB,CAAC;AACF,CAAC;AAED,SAAgB,+BAA+B,CAG7C,SAAqB;IACtB,OAAO,CAAC,IAAkC,EAAE,EAAE,CAAC,yBAAyB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { SocketEventType } from '../../../utilities/enum';\nimport {\n\tconnectEntityToSocketEvent,\n\tdisconnectEntityFromSocketEvent,\n\tEntitySubscription,\n\tEventFactory,\n\tInputFor,\n\tLocalEventEmitter,\n\tLocalSubs,\n\tOutputFor,\n} from '../core';\nimport { randomUUID } from 'crypto';\nimport { getInstanceId } from '../../../utilities/instance.utils';\nimport { AuthEntityType, TokenType } from '../../auth';\nimport { ProcedureResolverOptions } from '@trpc/server/unstable-core-do-not-import';\nimport { EntityContext, LyxaHTTPContext } from '../../trpc/context';\nimport { on } from 'events';\nimport { getLibraries } from '../../../index';\n\ntype optsType<\n\tTEventType extends SocketEventType,\n\tTInput extends InputFor<TEventType>,\n> = ProcedureResolverOptions<\n\tobject,\n\tLyxaHTTPContext,\n\t{\n\t\tres: import('http').ServerResponse<import('http').IncomingMessage>;\n\t\ttokenType: TokenType | undefined;\n\t\tentity: EntityContext | undefined;\n\t\treq: import('http').IncomingMessage;\n\t\trequestId: string | undefined;\n\t\tusedRefreshToken: boolean | undefined;\n\t\ttokenRenewed: boolean | undefined;\n\t},\n\tTInput\n>;\n\ninterface _SubscriptionContext {\n\tentity?: { id: string; type: AuthEntityType };\n\tsignal?: AbortSignal;\n}\n\ninterface _SubscriptionOpts<TEventType extends SocketEventType, TInput extends InputFor<TEventType>> {\n\tctx: _SubscriptionContext;\n\tinput: TInput;\n}\n\nasync function* _createSocketSubscription<\n\tTEventType extends SocketEventType,\n\tTInput extends InputFor<TEventType>,\n>(eventType: TEventType, opts: optsType<TEventType, TInput>) {\n\tconst { ctx } = opts;\n\tconst logger = getLibraries().getLogger().logger;\n\n\tconst entity: EntitySubscription = { id: ctx.entity!.id, type: ctx.entity!.type };\n\tconst eventKey = EventFactory.getSubscriptionKey(eventType, opts.input);\n\tconst socketId = randomUUID();\n\tconst socketInfo = { socketId, eventKey, instanceId: getInstanceId() };\n\n\tconst localEE = new LocalEventEmitter(socketId);\n\n\t// --- CONNECT ---\n\tawait connectEntityToSocketEvent(entity, socketInfo);\n\tLocalSubs.bind(entity, eventKey, localEE);\n\tlogger.debug({ entity, socketId, eventKey }, 'Socket subscription connected');\n\n\t// --- DISCONNECT ---\n\topts.signal?.addEventListener('abort', () => {\n\t\tLocalSubs.unbind(entity, eventKey, localEE);\n\t\tdisconnectEntityFromSocketEvent(entity, socketInfo);\n\t\tlogger.debug({ entity, socketId, eventKey }, 'Socket subscription disconnected');\n\t});\n\n\t// --- STREAM EVENTS ---\n\ttype Out = OutputFor<TEventType>;\n\tfor await (const [data] of on(localEE.ee, eventKey, { signal: opts.signal })) {\n\t\tlogger.debug({ entity, socketId, eventKey, data }, 'Socket subscription sending data');\n\t\tyield data as Out;\n\t}\n}\n\nexport function createSocketSubscriptionAdapter<\n\tTEventType extends SocketEventType,\n\tTInput extends InputFor<TEventType>,\n>(eventType: TEventType) {\n\treturn (opts: optsType<TEventType, TInput>) => _createSocketSubscription(eventType, opts);\n}\n\n/**\n * @Example\n * const socketRouterTwo = createTRPCRouter({\n * \tonMessage: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM] })\n * \t\t.input(ChatroomMessageSendSocketInputSchema)\n * \t\t.output(zAsyncIterable({ yield: ChatroomMessageSendOutputSchema }))\n * \t\t.subscription(createSocketSubscriptionAdapter(SocketEventType.CHATROOM_MESSAGE_SEND)),\n * });\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.3.32
25
+ Version: 1.3.33
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.3.32",
3
+ "version": "1.3.33",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.3.32",
3
+ "version": "1.3.33",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",