@lyxa.ai/core 1.4.64 → 1.4.65

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.
@@ -40,13 +40,13 @@ function getChannel() {
40
40
  }
41
41
  async function publishEvent(event) {
42
42
  console.log('taking event', event);
43
- const ch = getChannel().pubChannel;
43
+ pubChannel = await connection.createConfirmChannel();
44
44
  const messageBuffer = Buffer.from(JSON.stringify(event.payload));
45
- ch.publish(exports.EXCHANGE_NAME, event.eventId, messageBuffer, {
45
+ pubChannel.publish(exports.EXCHANGE_NAME, event.eventId, messageBuffer, {
46
46
  contentType: 'application/json',
47
47
  persistent: true,
48
48
  });
49
- await ch.waitForConfirms();
49
+ await pubChannel.waitForConfirms();
50
50
  }
51
51
  async function subscribeToEvent(eventId, onMessage, opts) {
52
52
  const ch = getChannel().subChannel;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/event/index.ts"],"names":[],"mappings":";;;;;;AAiBA,oCAUC;AAED,gCAOC;AAED,oCAYC;AAED,4CAyCC;AAED,gDAyBC;AAED,sCAKC;AA/HD,sDAA2B;AAE3B,mEAA+D;AAC/D,uCAA2C;AAC3C,+CAA8C;AAE9C,IAAI,UAA6B,CAAC;AAClC,IAAI,UAA+B,CAAC;AACpC,IAAI,UAAwB,CAAC;AAMhB,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,UAAU,GAAG,MAAM,UAAU,CAAC,oBAAoB,EAAE,CAAC;IACrD,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAEhC,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;IAC9C,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;I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K,EAAE,CAAC;YACpB,UAAU,GAAG,MAAM,UAAU,CAAC,oBAAoB,EAAE,CAAC;YACrD,MAAM,UAAU,CAAC,cAAc,CAAC,qBAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3E,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;YAC9C,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;QACpB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,gBAAgB,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\nimport { getLibraries } from '../../index';\nimport { LogTag } from '../../utilities/enum';\n\nlet connection: amqp.ChannelModel;\nlet pubChannel: amqp.ConfirmChannel;\nlet subChannel: amqp.Channel;\n\nexport interface RabbitMQEventOptions {\n\tconsumeImmediately?: boolean;\n}\n\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\tpubChannel = await connection.createConfirmChannel();\n\tattachGuards(pubChannel, 'pub');\n\n\tsubChannel = await connection.createChannel();\n\tattachGuards(subChannel, 'sub');\n\n\tawait pubChannel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nexport function getChannel(): { pubChannel: amqp.ConfirmChannel; subChannel: amqp.Channel } {\n\tif (!pubChannel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tif (!subChannel) throw new Error('Channel not initialized. Call initEventBus first.');\n\treturn {\n\t\tpubChannel,\n\t\tsubChannel,\n\t};\n}\n\nexport async function publishEvent<TPayload extends object>(\n\tevent: BaseEvent<TPayload>\n): Promise<void> {\n\tconsole.log('taking event', event);\n\n\tconst ch = getChannel().pubChannel;\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tch.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t\tpersistent: true,\n\t});\n\tawait ch.waitForConfirms();\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>,\n\topts?: RabbitMQEventOptions\n): Promise<void> {\n\tconst ch = getChannel().subChannel;\n\tconst queueName = `${eventId}`;\n\t// const queueName = `${eventId}.${getInstanceId()}`;\n\n\tawait ch.assertQueue(queueName, {\n\t\tdurable: true, // survive broker restart\n\t\texclusive: false, // Allow multiple consumers to attach. Only one connection can use it (each pod has own queue). Set to TRUE if each pod needs it's own queue\n\t\tautoDelete: false, // Queue removed when pod disconnects when set to TRUE\n\t\t// arguments: {\n\t\t// \t// Optional safety: limit queue size and TTL to prevent disk issues\n\t\t// \t'x-max-length': 50000, // max 50k messages\n\t\t// \t'x-message-ttl': 24 * 60 * 60 * 1000, // 24h TTL\n\t\t// \t'x-overflow': 'drop-head', // drop oldest messages if full\n\t\t// },\n\t});\n\n\tawait ch.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\tif (opts?.consumeImmediately !== false) {\n\t\tawait ch.consume(queueName, async msg => {\n\t\t\tif (!msg) return;\n\t\t\tlet processed = false;\n\t\t\ttry {\n\t\t\t\tconst payload = JSON.parse(msg.content.toString());\n\t\t\t\tawait onMessage(payload);\n\t\t\t\tprocessed = true;\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Error handling event [${eventId}]`, err);\n\t\t\t} finally {\n\t\t\t\tif (processed) ch.ack(msg);\n\t\t\t\telse ch.nack(msg, false, true); // retry\n\t\t\t}\n\t\t});\n\t}\n\n\t// console.log(`Subscribed to event [${eventId}] on queue [${queueName}]`);\n\tconsole.log(`Subscribed to event [${eventId}]`);\n}\n\nexport async function consumeAllMessages<T>(queueName: string): Promise<T[]> {\n\tconst logger = getLibraries().getLoggerKit();\n\tconst ch = getChannel().subChannel;\n\tconst messages: T[] = [];\n\n\twhile (true) {\n\t\tconst msg = await ch.get(queueName, { noAck: false });\n\t\tif (!msg) break;\n\n\t\ttry {\n\t\t\tconst payload = JSON.parse(msg.content.toString()) as T;\n\t\t\tmessages.push(payload);\n\t\t\tch.ack(msg);\n\t\t\tlogger.debug(`Message consumed successfully for event ${queueName}`, {\n\t\t\t\ttag: LogTag.INFRA_QUEUE,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tlogger.error(`Error processing message for event ${queueName}:`, err, {\n\t\t\t\ttag: LogTag.INFRA_QUEUE,\n\t\t\t});\n\t\t\tch.nack(msg, false, true);\n\t\t}\n\t}\n\tlogger.debug(`Fetched ${messages.length} messages for event ${queueName}`, { tag: LogTag.INFRA_QUEUE });\n\treturn messages;\n}\n\nexport async function closeEventBus(): Promise<void> {\n\tif (pubChannel) await pubChannel.close();\n\tif (subChannel) await subChannel.close();\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}\n\nfunction attachGuards(ch: amqp.Channel | amqp.ConfirmChannel, type: 'pub' | 'sub') {\n\tch.on('close', async () => {\n\t\tconsole.error(`${type} channel closed, recreating...`);\n\t\tif (type === 'pub') {\n\t\t\tpubChannel = await connection.createConfirmChannel();\n\t\t\tawait pubChannel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\t\t\tattachGuards(pubChannel, 'pub');\n\t\t} else {\n\t\t\tsubChannel = await connection.createChannel();\n\t\t\tattachGuards(subChannel, 'sub');\n\t\t}\n\t});\n\n\tch.on('error', err => {\n\t\tconsole.error(`${type} channel error`, err);\n\t});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C,CAAC;AACJ,CAAC","sourcesContent":["import amqp from 'amqplib';\nimport { BaseEvent } from './BaseEvent';\nimport { getInstanceId } from '../../utilities/instance.utils';\nimport { getLibraries } from '../../index';\nimport { LogTag } from '../../utilities/enum';\n\nlet connection: amqp.ChannelModel;\nlet pubChannel: amqp.ConfirmChannel;\nlet subChannel: amqp.Channel;\n\nexport interface RabbitMQEventOptions {\n\tconsumeImmediately?: boolean;\n}\n\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\tpubChannel = await connection.createConfirmChannel();\n\tattachGuards(pubChannel, 'pub');\n\n\tsubChannel = await connection.createChannel();\n\tattachGuards(subChannel, 'sub');\n\n\tawait pubChannel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\tconsole.log(`EventBus initialized with instance ID: ${getInstanceId()}`);\n}\n\nexport function getChannel(): { pubChannel: amqp.ConfirmChannel; subChannel: amqp.Channel } {\n\tif (!pubChannel) throw new Error('Channel not initialized. Call initEventBus first.');\n\tif (!subChannel) throw new Error('Channel not initialized. Call initEventBus first.');\n\treturn {\n\t\tpubChannel,\n\t\tsubChannel,\n\t};\n}\n\nexport async function publishEvent<TPayload extends object>(event: BaseEvent<TPayload>): Promise<void> {\n\tconsole.log('taking event', event);\n\tpubChannel = await connection.createConfirmChannel();\n\t// const ch = getChannel().pubChannel;\n\tconst messageBuffer = Buffer.from(JSON.stringify(event.payload));\n\tpubChannel.publish(EXCHANGE_NAME, event.eventId, messageBuffer, {\n\t\tcontentType: 'application/json',\n\t\tpersistent: true,\n\t});\n\tawait pubChannel.waitForConfirms();\n}\n\nexport async function subscribeToEvent(\n\teventId: string,\n\tonMessage: (payload: any) => Promise<void>,\n\topts?: RabbitMQEventOptions\n): Promise<void> {\n\tconst ch = getChannel().subChannel;\n\tconst queueName = `${eventId}`;\n\t// const queueName = `${eventId}.${getInstanceId()}`;\n\n\tawait ch.assertQueue(queueName, {\n\t\tdurable: true, // survive broker restart\n\t\texclusive: false, // Allow multiple consumers to attach. Only one connection can use it (each pod has own queue). Set to TRUE if each pod needs it's own queue\n\t\tautoDelete: false, // Queue removed when pod disconnects when set to TRUE\n\t\t// arguments: {\n\t\t// \t// Optional safety: limit queue size and TTL to prevent disk issues\n\t\t// \t'x-max-length': 50000, // max 50k messages\n\t\t// \t'x-message-ttl': 24 * 60 * 60 * 1000, // 24h TTL\n\t\t// \t'x-overflow': 'drop-head', // drop oldest messages if full\n\t\t// },\n\t});\n\n\tawait ch.bindQueue(queueName, EXCHANGE_NAME, eventId);\n\tif (opts?.consumeImmediately !== false) {\n\t\tawait ch.consume(queueName, async msg => {\n\t\t\tif (!msg) return;\n\t\t\tlet processed = false;\n\t\t\ttry {\n\t\t\t\tconst payload = JSON.parse(msg.content.toString());\n\t\t\t\tawait onMessage(payload);\n\t\t\t\tprocessed = true;\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Error handling event [${eventId}]`, err);\n\t\t\t} finally {\n\t\t\t\tif (processed) ch.ack(msg);\n\t\t\t\telse ch.nack(msg, false, true); // retry\n\t\t\t}\n\t\t});\n\t}\n\n\t// console.log(`Subscribed to event [${eventId}] on queue [${queueName}]`);\n\tconsole.log(`Subscribed to event [${eventId}]`);\n}\n\nexport async function consumeAllMessages<T>(queueName: string): Promise<T[]> {\n\tconst logger = getLibraries().getLoggerKit();\n\tconst ch = getChannel().subChannel;\n\tconst messages: T[] = [];\n\n\twhile (true) {\n\t\tconst msg = await ch.get(queueName, { noAck: false });\n\t\tif (!msg) break;\n\n\t\ttry {\n\t\t\tconst payload = JSON.parse(msg.content.toString()) as T;\n\t\t\tmessages.push(payload);\n\t\t\tch.ack(msg);\n\t\t\tlogger.debug(`Message consumed successfully for event ${queueName}`, {\n\t\t\t\ttag: LogTag.INFRA_QUEUE,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tlogger.error(`Error processing message for event ${queueName}:`, err, {\n\t\t\t\ttag: LogTag.INFRA_QUEUE,\n\t\t\t});\n\t\t\tch.nack(msg, false, true);\n\t\t}\n\t}\n\tlogger.debug(`Fetched ${messages.length} messages for event ${queueName}`, { tag: LogTag.INFRA_QUEUE });\n\treturn messages;\n}\n\nexport async function closeEventBus(): Promise<void> {\n\tif (pubChannel) await pubChannel.close();\n\tif (subChannel) await subChannel.close();\n\tif (connection) await connection.close();\n\tconsole.log(`EventBus closed for instance [${getInstanceId()}]`);\n}\n\nfunction attachGuards(ch: amqp.Channel | amqp.ConfirmChannel, type: 'pub' | 'sub') {\n\tch.on('close', async () => {\n\t\tconsole.error(`${type} channel closed, recreating...`);\n\t\tif (type === 'pub') {\n\t\t\tpubChannel = await connection.createConfirmChannel();\n\t\t\tawait pubChannel.assertExchange(EXCHANGE_NAME, 'topic', { durable: true });\n\t\t\tattachGuards(pubChannel, 'pub');\n\t\t} else {\n\t\t\tsubChannel = await connection.createChannel();\n\t\t\tattachGuards(subChannel, 'sub');\n\t\t}\n\t});\n\n\tch.on('error', err => {\n\t\tconsole.error(`${type} channel error`, err);\n\t});\n}\n"]}
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
+ req: import("http").IncomingMessage;
8
9
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
10
  tokenType: TokenType | undefined;
10
- req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
4
4
  allowedRoles: string[];
5
5
  }
6
6
  export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
7
+ req: import("http").IncomingMessage;
7
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
8
9
  tokenType: import("../../auth").TokenType | undefined;
9
- req: import("http").IncomingMessage;
10
10
  requestId: string | undefined;
11
11
  entity: import("../context").EntityContext | undefined;
12
12
  usedRefreshToken: boolean | undefined;
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
3
3
  entityTypes: AuthEntityType[];
4
4
  }
5
5
  export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
6
+ req: import("http").IncomingMessage;
6
7
  res: import("http").ServerResponse<import("http").IncomingMessage>;
7
8
  tokenType: import("../../auth").TokenType | undefined;
8
- req: import("http").IncomingMessage;
9
9
  requestId: string | undefined;
10
10
  entity: import("../context").EntityContext | undefined;
11
11
  usedRefreshToken: boolean | undefined;
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
+ req: import("http").IncomingMessage;
8
9
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
10
  tokenType: TokenType | undefined;
10
- req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.4.64
25
+ Version: 1.4.65
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.4.64",
3
+ "version": "1.4.65",
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",
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
26
26
  searchFields?: string[] | undefined;
27
27
  } | undefined;
28
28
  sort?: Record<string, 1 | -1> | undefined;
29
- select?: Record<string, 0 | 1> | undefined;
30
29
  populate?: any;
30
+ select?: Record<string, 0 | 1> | undefined;
31
31
  query?: Record<string, any> | undefined;
32
32
  }, {
33
33
  search?: {
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
36
36
  } | undefined;
37
37
  sort?: Record<string, 1 | -1> | undefined;
38
38
  size?: number | undefined;
39
- select?: Record<string, 0 | 1> | undefined;
40
39
  populate?: any;
40
+ select?: Record<string, 0 | 1> | undefined;
41
41
  query?: Record<string, any> | undefined;
42
42
  page?: number | undefined;
43
43
  }>>;
@@ -736,12 +736,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
736
736
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
737
737
  }, "strip", z.ZodTypeAny, {
738
738
  _id: import("mongoose").Types.ObjectId;
739
- select?: Record<string, 0 | 1> | undefined;
740
739
  populate?: any;
740
+ select?: Record<string, 0 | 1> | undefined;
741
741
  }, {
742
742
  _id: string | import("mongoose").Types.ObjectId;
743
- select?: Record<string, 0 | 1> | undefined;
744
743
  populate?: any;
744
+ select?: Record<string, 0 | 1> | undefined;
745
745
  }>;
746
746
  export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
747
747
  export declare const GetProductByIdInputSchema: z.ZodObject<{
@@ -754,12 +754,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
754
754
  _id: import("mongoose").Types.ObjectId;
755
755
  withAttributeHiddenItems: boolean;
756
756
  withAddonsHiddenItems: boolean;
757
- select?: Record<string, 0 | 1> | undefined;
758
757
  populate?: any;
758
+ select?: Record<string, 0 | 1> | undefined;
759
759
  }, {
760
760
  _id: string | import("mongoose").Types.ObjectId;
761
- select?: Record<string, 0 | 1> | undefined;
762
761
  populate?: any;
762
+ select?: Record<string, 0 | 1> | undefined;
763
763
  withAttributeHiddenItems?: boolean | undefined;
764
764
  withAddonsHiddenItems?: boolean | undefined;
765
765
  }>;
@@ -773,15 +773,15 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
773
773
  userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
774
774
  }, "strip", z.ZodTypeAny, {
775
775
  _id: import("mongoose").Types.ObjectId;
776
- select?: Record<string, 0 | 1> | undefined;
777
776
  populate?: any;
777
+ select?: Record<string, 0 | 1> | undefined;
778
778
  groupByCategories?: boolean | undefined;
779
779
  getParentCategory?: boolean | undefined;
780
780
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
781
781
  }, {
782
782
  _id: string | import("mongoose").Types.ObjectId;
783
- select?: Record<string, 0 | 1> | undefined;
784
783
  populate?: any;
784
+ select?: Record<string, 0 | 1> | undefined;
785
785
  groupByCategories?: boolean | undefined;
786
786
  getParentCategory?: boolean | undefined;
787
787
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
@@ -791,11 +791,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
791
791
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
792
792
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
793
793
  }, "strip", z.ZodTypeAny, {
794
- select?: Record<string, 0 | 1> | undefined;
795
794
  populate?: any;
796
- }, {
797
795
  select?: Record<string, 0 | 1> | undefined;
796
+ }, {
798
797
  populate?: any;
798
+ select?: Record<string, 0 | 1> | undefined;
799
799
  }>>;
800
800
  export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
801
801
  export declare const GetOneQuerySchema: z.ZodObject<{
@@ -803,12 +803,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
803
803
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
804
804
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
805
805
  }, "strip", z.ZodTypeAny, {
806
- select?: Record<string, 0 | 1> | undefined;
807
806
  populate?: any;
807
+ select?: Record<string, 0 | 1> | undefined;
808
808
  query?: Record<string, any> | undefined;
809
809
  }, {
810
- select?: Record<string, 0 | 1> | undefined;
811
810
  populate?: any;
811
+ select?: Record<string, 0 | 1> | undefined;
812
812
  query?: Record<string, any> | undefined;
813
813
  }>;
814
814
  export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.4.64",
3
+ "version": "1.4.65",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",