@lyxa.ai/core 1.3.159 → 1.3.161

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.
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.3.159
25
+ Version: 1.3.161
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.3.159",
3
+ "version": "1.3.161",
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",
@@ -8,7 +8,7 @@ exports.RabbitMQUrlMap = {
8
8
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.DEV]: 'amqps://adlvedna:oY_X4qH1AphtB83YNcf9DHMO3UVmX23s@dog.lmq.cloudamqp.com/adlvedna',
9
9
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.PREPROD]: 'amqps://ndzofsci:ItlgvubZLAdmc13eF6sULXy9TxWKmdPU@dog.lmq.cloudamqp.com/ndzofsci',
10
10
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.STAGING]: 'amqps://pkyqvrvt:R5DRopXgBoHkprIyrarUj_MOXiLfgvGW@dog.lmq.cloudamqp.com/pkyqvrvt',
11
- [EnvironmentConfigurationType_1.EnvironmentConfigurationType.PROD]: '',
12
11
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.MIGRATION]: 'amqps://napncdtl:cRqTXDMdEQ02u_hnBnyJ5I20TOPc4C36@dog.lmq.cloudamqp.com/napncdtl',
12
+ [EnvironmentConfigurationType_1.EnvironmentConfigurationType.PROD]: 'amqps://witvvsxj:etcoOPd_L1X4wX6Y9r9MUtuSmDK11Kmb@dog.lmq.cloudamqp.com/witvvsxj',
13
13
  };
14
14
  //# sourceMappingURL=rabbitmq-environments.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq-environments.js","sourceRoot":"/","sources":["utilities/environment/rabbitmq-environments.ts"],"names":[],"mappings":";;;AAAA,mHAAgH;AAEnG,QAAA,cAAc,GAAiD;IAC3E,CAAC,2DAA4B,CAAC,KAAK,CAAC,EAAE,EAAE;IACxC,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAAE,EAAE;IACvC,CAAC,2DAA4B,CAAC,GAAG,CAAC,EACjC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAAE,EAAE;IACvC,CAAC,2DAA4B,CAAC,SAAS,CAAC,EACvC,kFAAkF;CACnF,CAAC","sourcesContent":["import { EnvironmentConfigurationType } from '../../libraries/configuration/types/EnvironmentConfigurationType';\n\nexport const RabbitMQUrlMap: Record<EnvironmentConfigurationType, string> = {\n\t[EnvironmentConfigurationType.LOCAL]: '',\n\t[EnvironmentConfigurationType.MOCK]: '',\n\t[EnvironmentConfigurationType.DEV]:\n\t\t'amqps://adlvedna:oY_X4qH1AphtB83YNcf9DHMO3UVmX23s@dog.lmq.cloudamqp.com/adlvedna',\n\t[EnvironmentConfigurationType.PREPROD]:\n\t\t'amqps://ndzofsci:ItlgvubZLAdmc13eF6sULXy9TxWKmdPU@dog.lmq.cloudamqp.com/ndzofsci',\n\t[EnvironmentConfigurationType.STAGING]:\n\t\t'amqps://pkyqvrvt:R5DRopXgBoHkprIyrarUj_MOXiLfgvGW@dog.lmq.cloudamqp.com/pkyqvrvt',\n\t[EnvironmentConfigurationType.PROD]: '',\n\t[EnvironmentConfigurationType.MIGRATION]:\n\t\t'amqps://napncdtl:cRqTXDMdEQ02u_hnBnyJ5I20TOPc4C36@dog.lmq.cloudamqp.com/napncdtl',\n};\n"]}
1
+ {"version":3,"file":"rabbitmq-environments.js","sourceRoot":"/","sources":["utilities/environment/rabbitmq-environments.ts"],"names":[],"mappings":";;;AAAA,mHAAgH;AAEnG,QAAA,cAAc,GAAiD;IAC3E,CAAC,2DAA4B,CAAC,KAAK,CAAC,EAAE,EAAE;IACxC,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAAE,EAAE;IACvC,CAAC,2DAA4B,CAAC,GAAG,CAAC,EACjC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,SAAS,CAAC,EACvC,kFAAkF;IACnF,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAClC,kFAAkF;CACnF,CAAC","sourcesContent":["import { EnvironmentConfigurationType } from '../../libraries/configuration/types/EnvironmentConfigurationType';\n\nexport const RabbitMQUrlMap: Record<EnvironmentConfigurationType, string> = {\n\t[EnvironmentConfigurationType.LOCAL]: '',\n\t[EnvironmentConfigurationType.MOCK]: '',\n\t[EnvironmentConfigurationType.DEV]:\n\t\t'amqps://adlvedna:oY_X4qH1AphtB83YNcf9DHMO3UVmX23s@dog.lmq.cloudamqp.com/adlvedna',\n\t[EnvironmentConfigurationType.PREPROD]:\n\t\t'amqps://ndzofsci:ItlgvubZLAdmc13eF6sULXy9TxWKmdPU@dog.lmq.cloudamqp.com/ndzofsci',\n\t[EnvironmentConfigurationType.STAGING]:\n\t\t'amqps://pkyqvrvt:R5DRopXgBoHkprIyrarUj_MOXiLfgvGW@dog.lmq.cloudamqp.com/pkyqvrvt',\n\t[EnvironmentConfigurationType.MIGRATION]:\n\t\t'amqps://napncdtl:cRqTXDMdEQ02u_hnBnyJ5I20TOPc4C36@dog.lmq.cloudamqp.com/napncdtl',\n\t[EnvironmentConfigurationType.PROD]:\n\t\t'amqps://witvvsxj:etcoOPd_L1X4wX6Y9r9MUtuSmDK11Kmb@dog.lmq.cloudamqp.com/witvvsxj',\n};\n"]}
@@ -8,7 +8,7 @@ exports.RedisUrlMap = {
8
8
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.DEV]: 'redis://default:nkrBeCA41QyMaLH00mj67CWf3Muz9ubc@redis-12266.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12266',
9
9
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.PREPROD]: 'redis://default:ngpwdRevVIBGVIvtBoLO7tE8jPzBdGLh@redis-12965.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12965',
10
10
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.STAGING]: 'redis://default:5QynNeFWdCcBcu3QVNR2LbfLlWcxdP4o@redis-10162.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:10162',
11
- [EnvironmentConfigurationType_1.EnvironmentConfigurationType.PROD]: 'redis://default:8RCVCiwXRMo6isHgJanL1pE86cRt29YP@redis-12296.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12296',
12
11
  [EnvironmentConfigurationType_1.EnvironmentConfigurationType.MIGRATION]: 'redis://default:E7qfnmO5ENgWi51Wfk1LAZJHamJS1HpY@redis-17414.c304.europe-west1-2.gce.cloud.redislabs.com:17414',
12
+ [EnvironmentConfigurationType_1.EnvironmentConfigurationType.PROD]: 'redis://default:RFdRld7ZxRKRLzUS3dfNgobSjw44QDir@redis-15191.c304.europe-west1-2.gce.cloud.redislabs.com:15191',
13
13
  };
14
14
  //# sourceMappingURL=redis-environments.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redis-environments.js","sourceRoot":"/","sources":["utilities/environment/redis-environments.ts"],"names":[],"mappings":";;;AAAA,mHAAgH;AAEnG,QAAA,WAAW,GAAiD;IACxE,CAAC,2DAA4B,CAAC,KAAK,CAAC,EAAE,EAAE;IACxC,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAAE,EAAE;IACvC,CAAC,2DAA4B,CAAC,GAAG,CAAC,EACjC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAClC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,SAAS,CAAC,EACvC,gHAAgH;CACjH,CAAC","sourcesContent":["import { EnvironmentConfigurationType } from '../../libraries/configuration/types/EnvironmentConfigurationType';\n\nexport const RedisUrlMap: Record<EnvironmentConfigurationType, string> = {\n\t[EnvironmentConfigurationType.LOCAL]: '',\n\t[EnvironmentConfigurationType.MOCK]: '',\n\t[EnvironmentConfigurationType.DEV]:\n\t\t'redis://default:nkrBeCA41QyMaLH00mj67CWf3Muz9ubc@redis-12266.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12266',\n\t[EnvironmentConfigurationType.PREPROD]:\n\t\t'redis://default:ngpwdRevVIBGVIvtBoLO7tE8jPzBdGLh@redis-12965.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12965',\n\t[EnvironmentConfigurationType.STAGING]:\n\t\t'redis://default:5QynNeFWdCcBcu3QVNR2LbfLlWcxdP4o@redis-10162.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:10162',\n\t[EnvironmentConfigurationType.PROD]:\n\t\t'redis://default:8RCVCiwXRMo6isHgJanL1pE86cRt29YP@redis-12296.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12296',\n\t[EnvironmentConfigurationType.MIGRATION]:\n\t\t'redis://default:E7qfnmO5ENgWi51Wfk1LAZJHamJS1HpY@redis-17414.c304.europe-west1-2.gce.cloud.redislabs.com:17414',\n};\n"]}
1
+ {"version":3,"file":"redis-environments.js","sourceRoot":"/","sources":["utilities/environment/redis-environments.ts"],"names":[],"mappings":";;;AAAA,mHAAgH;AAEnG,QAAA,WAAW,GAAiD;IACxE,CAAC,2DAA4B,CAAC,KAAK,CAAC,EAAE,EAAE;IACxC,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAAE,EAAE;IACvC,CAAC,2DAA4B,CAAC,GAAG,CAAC,EACjC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,OAAO,CAAC,EACrC,mHAAmH;IACpH,CAAC,2DAA4B,CAAC,SAAS,CAAC,EACvC,gHAAgH;IACjH,CAAC,2DAA4B,CAAC,IAAI,CAAC,EAClC,gHAAgH;CACjH,CAAC","sourcesContent":["import { EnvironmentConfigurationType } from '../../libraries/configuration/types/EnvironmentConfigurationType';\n\nexport const RedisUrlMap: Record<EnvironmentConfigurationType, string> = {\n\t[EnvironmentConfigurationType.LOCAL]: '',\n\t[EnvironmentConfigurationType.MOCK]: '',\n\t[EnvironmentConfigurationType.DEV]:\n\t\t'redis://default:nkrBeCA41QyMaLH00mj67CWf3Muz9ubc@redis-12266.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12266',\n\t[EnvironmentConfigurationType.PREPROD]:\n\t\t'redis://default:ngpwdRevVIBGVIvtBoLO7tE8jPzBdGLh@redis-12965.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:12965',\n\t[EnvironmentConfigurationType.STAGING]:\n\t\t'redis://default:5QynNeFWdCcBcu3QVNR2LbfLlWcxdP4o@redis-10162.fcrce173.eu-west-1-1.ec2.redns.redis-cloud.com:10162',\n\t[EnvironmentConfigurationType.MIGRATION]:\n\t\t'redis://default:E7qfnmO5ENgWi51Wfk1LAZJHamJS1HpY@redis-17414.c304.europe-west1-2.gce.cloud.redislabs.com:17414',\n\t[EnvironmentConfigurationType.PROD]:\n\t\t'redis://default:RFdRld7ZxRKRLzUS3dfNgobSjw44QDir@redis-15191.c304.europe-west1-2.gce.cloud.redislabs.com:15191',\n};\n"]}
@@ -8,17 +8,17 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
8
8
  size: z.ZodNumber;
9
9
  totalElements: z.ZodNumber;
10
10
  totalPages: z.ZodNumber;
11
- }, "strip", z.ZodTypeAny, {
12
- page: number;
13
- size: number;
14
- totalElements: number;
15
- totalPages: number;
16
- }, {
17
- page: number;
18
- size: number;
19
- totalElements: number;
20
- totalPages: number;
21
- }>;
11
+ }, "strip", z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber]>, z.ZodBoolean]>, z.ZodNull]>, z.ZodUndefined]>, z.objectOutputType<{
12
+ page: z.ZodNumber;
13
+ size: z.ZodNumber;
14
+ totalElements: z.ZodNumber;
15
+ totalPages: z.ZodNumber;
16
+ }, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber]>, z.ZodBoolean]>, z.ZodNull]>, z.ZodUndefined]>, "strip">, z.objectInputType<{
17
+ page: z.ZodNumber;
18
+ size: z.ZodNumber;
19
+ totalElements: z.ZodNumber;
20
+ totalPages: z.ZodNumber;
21
+ }, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber]>, z.ZodBoolean]>, z.ZodNull]>, z.ZodUndefined]>, "strip">>;
22
22
  items: z.ZodArray<ItemType, "many">;
23
23
  }, "strip", z.ZodTypeAny, {
24
24
  metadata: {
@@ -26,6 +26,8 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
26
26
  size: number;
27
27
  totalElements: number;
28
28
  totalPages: number;
29
+ } & {
30
+ [k: string]: string | number | boolean | null | undefined;
29
31
  };
30
32
  items: ItemType["_output"][];
31
33
  }, {
@@ -34,6 +36,8 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
34
36
  size: number;
35
37
  totalElements: number;
36
38
  totalPages: number;
39
+ } & {
40
+ [k: string]: string | number | boolean | null | undefined;
37
41
  };
38
42
  items: ItemType["_input"][];
39
43
  }>;
@@ -43,6 +47,7 @@ export interface RawPaginatedResult<T extends AnyParamConstructor<any>> {
43
47
  size: number;
44
48
  totalElements: number;
45
49
  totalPages: number;
50
+ [key: string]: string | number | boolean | null | undefined;
46
51
  };
47
52
  documents: DocumentType<T>[];
48
53
  }
@@ -61,6 +66,8 @@ export declare function createPaginatorObject<T extends AnyParamConstructor<any>
61
66
  size: number;
62
67
  totalElements: number;
63
68
  totalPages: number;
69
+ } & {
70
+ [k: string]: string | number | boolean | null | undefined;
64
71
  };
65
72
  items: any[];
66
73
  }>;
@@ -12,7 +12,7 @@ function createPaginatedSchema(itemSchema) {
12
12
  size: zod_1.z.number(),
13
13
  totalElements: zod_1.z.number(),
14
14
  totalPages: zod_1.z.number(),
15
- }),
15
+ }).catchall(zod_1.z.string().or(zod_1.z.number()).or(zod_1.z.boolean()).or(zod_1.z.null()).or(zod_1.z.undefined())),
16
16
  items: zod_1.z.array(itemSchema),
17
17
  });
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.js","sourceRoot":"/","sources":["utilities/pagination.ts"],"names":[],"mappings":";;AASA,sDAUC;AAqED,4EAWC;AASD,sDAmBC;AACD,kDA6CC;AA3KD,6BAAwB;AAOxB,SAAgB,qBAAqB,CAAgC,UAAoB;IACxF,OAAO,OAAC,CAAC,MAAM,CAAC;QACf,QAAQ,EAAE,OAAC,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;YACzB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;SACtB,CAAC;QACF,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,UAAU,CAAC;KAC1B,CAAC,CAAC;AACJ,CAAC;AA+BD,KAAK,UAAU,aAAa,CAC3B,KAAyB,EACzB,OAA4B;IAE5B,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAEjF,MAAM,IAAI,G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EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAG1C,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;IAG7D,MAAM,aAAa,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAG3F,OAAO;QACN,QAAQ,EAAE;YACT,IAAI;YACJ,IAAI;YACJ,aAAa;YACb,UAAU;SACV;QACD,SAAS,EAAE,aAAa;KACxB,CAAC;AACH,CAAC","sourcesContent":["import { DocumentType, ReturnModelType } from '@typegoose/typegoose';\nimport { FilterQuery, PopulateOptions } from 'mongoose';\nimport { z } from 'zod';\nimport { AnyParamConstructor } from '@typegoose/typegoose/lib/types';\nimport { FilterDTO, PaginatedResponse } from './validation';\n\n/**\n * A helper to create a paginated Zod schema for an item type.\n */\nexport function createPaginatedSchema<ItemType extends z.ZodTypeAny>(itemSchema: ItemType) {\n\treturn z.object({\n\t\tmetadata: z.object({\n\t\t\tpage: z.number(),\n\t\t\tsize: z.number(),\n\t\t\ttotalElements: z.number(),\n\t\t\ttotalPages: z.number(),\n\t\t}),\n\t\titems: z.array(itemSchema),\n\t});\n}\n\nexport interface RawPaginatedResult<T extends AnyParamConstructor<any>> {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t};\n\tdocuments: DocumentType<T>[];\n}\n\n/**\n * The common pagination options.\n */\nexport interface PaginatorOptions<TClass extends AnyParamConstructor<any>> {\n\tquery?: FilterQuery<DocumentType<TClass>>;\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tselect?: Record<string, 0 | 1>;\n\tpopulate?: PopulateOptions | (PopulateOptions | string)[];\n}\n\n/**\n * This internal function wraps the common query logic:\n * - filter, page, size, sort, populate\n * - fetch documents, count documents\n * - compute totalPages\n * Returns a standard object with `metadata` & `documents`.\n */\nasync function _basePaginate<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\toptions: PaginatorOptions<T>\n): Promise<RawPaginatedResult<T>> {\n\tconst { query = {}, page = 1, size = 10, sort = {}, select, populate } = options;\n\n\tconst skip = (page - 1) * size;\n\n\tlet result = model.find(query).sort(sort).skip(skip).limit(size);\n\n\tif (select) {\n\t\tresult = result.select(select) as any;\n\t}\n\tif (populate) {\n\t\tresult = result.populate(populate);\n\t}\n\n\tconst [documents, totalElements] = await Promise.all([result.exec(), model.countDocuments(query)]);\n\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: documents as unknown as DocumentType<T>[],\n\t};\n}\n\n/**\n * Creates a paginator returning raw documents.\n *\n * @param model The Typegoose model\n * @returns A function that, when passed `PaginatorOptions`, returns raw docs + metadata.\n */\nexport function createRawDocumentPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>\n) {\n\treturn async function paginate(options: PaginatorOptions<T>): Promise<RawPaginatedResult<T>> {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\treturn {\n\t\t\tmetadata,\n\t\t\tdocuments,\n\t\t};\n\t};\n}\n\n/**\n * Creates a paginator that returns Zod-validated items.\n *\n * @param model The Typegoose model\n * @param itemSchema A Zod schema describing the shape of each item\n * @param transformFn Optional transform function to convert raw doc -> item\n */\nexport function createPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\titemSchema: z.ZodTypeAny,\n\ttransformFn?: (doc: DocumentType<T>) => z.infer<typeof itemSchema>\n) {\n\tconst PaginatedSchema = createPaginatedSchema(itemSchema);\n\n\treturn async function paginate(options: PaginatorOptions<T>) {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\tconst items = transformFn ? documents.map(transformFn) : documents;\n\n\t\tconst paginatedResult = {\n\t\t\tmetadata,\n\t\t\titems,\n\t\t};\n\n\t\treturn PaginatedSchema.parse(paginatedResult);\n\t};\n}\nexport async function paginateAggregation(\n\tmodel: any,\n\tpipeline: any[],\n\tpage: number = 1,\n\tsize: number = 10,\n\tsort: any = { createdAt: -1 },\n\tpopulateOptions?: any\n) {\n\t// Calculate skip and limit based on the page and size\n\tconst skip = (page - 1) * size;\n\tconst limit = size;\n\n\t// Copy the pipeline to avoid mutation\n\tconst pipelineWithCount = [...pipeline];\n\n\t// Step 1: Calculate total count\n\tpipelineWithCount.push({ $count: 'totalCount' });\n\n\t// Step 2: Execute to get total count\n\tconst totalCountResult = await model.aggregate(pipelineWithCount).exec();\n\tconst totalElements = totalCountResult?.[0]?.totalCount || 0;\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\t// Step 3: Apply pagination to the original pipeline\n\tconst paginatedPipeline = [...pipeline];\n\tpaginatedPipeline.push({ $sort: sort });\n\tpaginatedPipeline.push({ $skip: skip });\n\tpaginatedPipeline.push({ $limit: limit });\n\n\t// Step 4: Execute the paginated pipeline\n\tconst data = await model.aggregate(paginatedPipeline).exec();\n\n\t// Step 5: Optional populate\n\tconst populatedData = populateOptions ? await model.populate(data, populateOptions) : data;\n\n\t// Return the paginated data with metadata\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: populatedData,\n\t};\n}\n"]}
1
+ {"version":3,"file":"pagination.js","sourceRoot":"/","sources":["utilities/pagination.ts"],"names":[],"mappings":";;AASA,sDAUC;AAuED,4EAWC;AASD,sDAmBC;AACD,kDA6CC;AA7KD,6BAAwB;AAOxB,SAAgB,qBAAqB,CAAgC,UAAoB;IACxF,OAAO,OAAC,CAAC,MAAM,CAAC;QACf,QAAQ,EAAE,OAAC,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE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CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC;IAGnB,MAAM,iBAAiB,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IAGxC,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAGjD,MAAM,gBAAgB,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;IACzE,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,IAAI,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAGnD,MAAM,iBAAiB,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;IACxC,iBAAiB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,iBAAiB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,iBAAiB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAG1C,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC;IAG7D,MAAM,aAAa,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAG3F,OAAO;QACN,QAAQ,EAAE;YACT,IAAI;YACJ,IAAI;YACJ,aAAa;YACb,UAAU;SACV;QACD,SAAS,EAAE,aAAa;KACxB,CAAC;AACH,CAAC","sourcesContent":["import { DocumentType, ReturnModelType } from '@typegoose/typegoose';\nimport { FilterQuery, PopulateOptions } from 'mongoose';\nimport { z } from 'zod';\nimport { AnyParamConstructor } from '@typegoose/typegoose/lib/types';\nimport { FilterDTO, PaginatedResponse } from './validation';\n\n/**\n * A helper to create a paginated Zod schema for an item type.\n */\nexport function createPaginatedSchema<ItemType extends z.ZodTypeAny>(itemSchema: ItemType) {\n\treturn z.object({\n\t\tmetadata: z.object({\n\t\t\tpage: z.number(),\n\t\t\tsize: z.number(),\n\t\t\ttotalElements: z.number(),\n\t\t\ttotalPages: z.number(),\n\t\t}).catchall(z.string().or(z.number()).or(z.boolean()).or(z.null()).or(z.undefined())),\n\t\titems: z.array(itemSchema),\n\t});\n}\n\nexport interface RawPaginatedResult<T extends AnyParamConstructor<any>> {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t\t// Use a more specific index signature\n \t[key: string]: string | number | boolean | null | undefined;\n\t};\n\tdocuments: DocumentType<T>[];\n}\n\n/**\n * The common pagination options.\n */\nexport interface PaginatorOptions<TClass extends AnyParamConstructor<any>> {\n\tquery?: FilterQuery<DocumentType<TClass>>;\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tselect?: Record<string, 0 | 1>;\n\tpopulate?: PopulateOptions | (PopulateOptions | string)[];\n}\n\n/**\n * This internal function wraps the common query logic:\n * - filter, page, size, sort, populate\n * - fetch documents, count documents\n * - compute totalPages\n * Returns a standard object with `metadata` & `documents`.\n */\nasync function _basePaginate<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\toptions: PaginatorOptions<T>\n): Promise<RawPaginatedResult<T>> {\n\tconst { query = {}, page = 1, size = 10, sort = {}, select, populate } = options;\n\n\tconst skip = (page - 1) * size;\n\n\tlet result = model.find(query).sort(sort).skip(skip).limit(size);\n\n\tif (select) {\n\t\tresult = result.select(select) as any;\n\t}\n\tif (populate) {\n\t\tresult = result.populate(populate);\n\t}\n\n\tconst [documents, totalElements] = await Promise.all([result.exec(), model.countDocuments(query)]);\n\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: documents as unknown as DocumentType<T>[],\n\t};\n}\n\n/**\n * Creates a paginator returning raw documents.\n *\n * @param model The Typegoose model\n * @returns A function that, when passed `PaginatorOptions`, returns raw docs + metadata.\n */\nexport function createRawDocumentPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>\n) {\n\treturn async function paginate(options: PaginatorOptions<T>): Promise<RawPaginatedResult<T>> {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\treturn {\n\t\t\tmetadata,\n\t\t\tdocuments,\n\t\t};\n\t};\n}\n\n/**\n * Creates a paginator that returns Zod-validated items.\n *\n * @param model The Typegoose model\n * @param itemSchema A Zod schema describing the shape of each item\n * @param transformFn Optional transform function to convert raw doc -> item\n */\nexport function createPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\titemSchema: z.ZodTypeAny,\n\ttransformFn?: (doc: DocumentType<T>) => z.infer<typeof itemSchema>\n) {\n\tconst PaginatedSchema = createPaginatedSchema(itemSchema);\n\n\treturn async function paginate(options: PaginatorOptions<T>) {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\tconst items = transformFn ? documents.map(transformFn) : documents;\n\n\t\tconst paginatedResult = {\n\t\t\tmetadata,\n\t\t\titems,\n\t\t};\n\n\t\treturn PaginatedSchema.parse(paginatedResult);\n\t};\n}\nexport async function paginateAggregation(\n\tmodel: any,\n\tpipeline: any[],\n\tpage: number = 1,\n\tsize: number = 10,\n\tsort: any = { createdAt: -1 },\n\tpopulateOptions?: any\n) {\n\t// Calculate skip and limit based on the page and size\n\tconst skip = (page - 1) * size;\n\tconst limit = size;\n\n\t// Copy the pipeline to avoid mutation\n\tconst pipelineWithCount = [...pipeline];\n\n\t// Step 1: Calculate total count\n\tpipelineWithCount.push({ $count: 'totalCount' });\n\n\t// Step 2: Execute to get total count\n\tconst totalCountResult = await model.aggregate(pipelineWithCount).exec();\n\tconst totalElements = totalCountResult?.[0]?.totalCount || 0;\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\t// Step 3: Apply pagination to the original pipeline\n\tconst paginatedPipeline = [...pipeline];\n\tpaginatedPipeline.push({ $sort: sort });\n\tpaginatedPipeline.push({ $skip: skip });\n\tpaginatedPipeline.push({ $limit: limit });\n\n\t// Step 4: Execute the paginated pipeline\n\tconst data = await model.aggregate(paginatedPipeline).exec();\n\n\t// Step 5: Optional populate\n\tconst populatedData = populateOptions ? await model.populate(data, populateOptions) : data;\n\n\t// Return the paginated data with metadata\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: populatedData,\n\t};\n}\n"]}
@@ -5,6 +5,7 @@ type Metadata = {
5
5
  size: number;
6
6
  totalElements: number;
7
7
  totalPages: number;
8
+ [key: string]: string | number | boolean | null | undefined;
8
9
  };
9
10
  type PaginatedResponse<T> = {
10
11
  metadata?: Metadata;
@@ -1 +1 @@
1
- {"version":3,"file":"transformers.js","sourceRoot":"/","sources":["utilities/transformers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuPA,8CAQC;AA9PD,iDAA4C;AAC5C,6BAAwB;AA4BjB,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAMT;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IASvC,oBAAoB,CAAC,MAAyC;QACpE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;IAC7C,CAAC;IASM,yBAAyB,CAC/B,OAAmC;Q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 'typedi';\nimport { z } from 'zod';\n\n/**\n * Type definition for pagination metadata\n */\ntype Metadata = {\n\tpage: number;\n\tsize: number;\n\ttotalElements: number;\n\ttotalPages: number;\n};\n\n/**\n * Type definition for paginated response\n */\ntype PaginatedResponse<T> = {\n\tmetadata?: Metadata;\n\tdocuments: T[];\n};\n\n/**\n * GlobalTransformer provides a reusable way to transform Mongoose documents\n * into DTOs using Zod schemas for validation and type safety.\n *\n * @template ModelType - The Mongoose model type\n * @template DTOType - The output DTO type\n */\n@Service()\nexport class GlobalTransformer<ModelType, DTOType> {\n\t/**\n\t * Creates a new GlobalTransformer\n\t *\n\t * @param {z.ZodType<any>} schema - Zod schema used for validation and transformation\n\t */\n\tconstructor(private schema: z.ZodType<any>) {}\n\n\t/**\n\t * Transforms a single document to a DTO\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @returns {DTOType} The transformed DTO\n\t * @throws {Error} When record is not found\n\t */\n\tpublic transformToBasicView(record: DocumentType<ModelType> | DTOType): DTOType {\n\t\tif (!record) {\n\t\t\tthrow new Error('Record not found');\n\t\t}\n\n\t\treturn this.schema.parse(record) as DTOType;\n\t}\n\n\t/**\n\t * Transforms an array of documents or a paginated response to a paginated DTO response\n\t *\n\t * @param {DocumentType<ModelType>[] | DTOType[] | PaginatedResponse<DocumentType<ModelType>> | PaginatedResponse<DTOType>} records - Records to transform\n\t * @returns {PaginatedResponse<DTOType>} Paginated response with transformed DTOs\n\t * @throws {Error} When input type is invalid\n\t */\n\tpublic transformToBasicViewArray<T extends DocumentType<ModelType> | DTOType>(\n\t\trecords: T[] | PaginatedResponse<T>\n\t): PaginatedResponse<DTOType> {\n\t\t// Case 1: If records is already in the paginated format\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\n\t\t\tconst paginatedRecords = records as\n\t\t\t\t| PaginatedResponse<DocumentType<ModelType>>\n\t\t\t\t| PaginatedResponse<DTOType>;\n\n\t\t\t// Process the documents array\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToBasicView(doc))\n\t\t\t\t: [];\n\n\t\t\t// Return the entire paginated structure\n\t\t\treturn {\n\t\t\t\tmetadata: paginatedRecords.metadata,\n\t\t\t\tdocuments: processedDocuments,\n\t\t\t};\n\t\t}\n\n\t\t// Case 2: If records is an array\n\t\tif (Array.isArray(records)) {\n\t\t\tif (records.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tdocuments: [],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst transformedRecords = records.map(record => this.transformToBasicView(record));\n\n\t\t\t// Return in paginated format with default metadata\n\t\t\treturn {\n\t\t\t\tdocuments: transformedRecords,\n\t\t\t};\n\t\t}\n\n\t\t// Fallback for unexpected input\n\t\tthrow new Error('Invalid input type for transformToBasicViewArray');\n\t}\n\n\t/**r\n\t * Creates a partial view with only the specified fields\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\n\t * @returns {Partial<DTOType>} Partial DTO with only the specified fields\n\t */\n\tpublic transformToPartialView(\n\t\trecord: DocumentType<ModelType>,\n\t\tfields: (keyof DTOType)[]\n\t): Partial<DTOType> {\n\t\tconst fullView = this.transformToBasicView(record);\n\t\tconst partialView: Partial<DTOType> = {};\n\n\t\tfields.forEach(field => {\n\t\t\tconst dto = fullView as Record<keyof DTOType, any>;\n\t\t\tpartialView[field] = dto[field];\n\t\t});\n\n\t\treturn partialView;\n\t}\n\n\t/**\n\t * Creates partial views for an array of documents\n\t *\n\t * @param {DocumentType<ModelType>[]} records - Array of documents to transform\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\n\t * @returns {Partial<DTOType>[]} Array of partial DTOs\n\t */\n\tpublic transformToPartialViewArray(\n\t\trecords: DocumentType<ModelType>[] | PaginatedResponse<DocumentType<ModelType>>,\n\t\tfields: (keyof DTOType)[]\n\t): Partial<DTOType>[] | PaginatedResponse<Partial<DTOType>> {\n\t\t// Case 1: If records is already in the paginated format\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\n\t\t\tconst paginatedRecords = records as PaginatedResponse<DocumentType<ModelType>>;\n\n\t\t\t// Process the documents array\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToPartialView(doc, fields))\n\t\t\t\t: [];\n\n\t\t\t// Return the entire paginated structure\n\t\t\treturn {\n\t\t\t\tmetadata: paginatedRecords.metadata,\n\t\t\t\tdocuments: processedDocuments,\n\t\t\t};\n\t\t}\n\n\t\t// Case 2: If records is an array\n\t\tif (Array.isArray(records)) {\n\t\t\tif (records.length === 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn records.map(record => this.transformToPartialView(record, fields));\n\t\t}\n\n\t\t// Fallback for unexpected input\n\t\tthrow new Error('Invalid input type for transformToPartialViewArray');\n\t}\n\t/**\n\t * Transforms a document and adds additional computed fields\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {Partial<Record<string, any>>} additionalData - Additional fields to add\n\t * @returns {DTOType & Record<string, any>} DTO with additional fields\n\t */\n\tpublic transformWithAdditionalData(\n\t\trecord: DocumentType<ModelType>,\n\t\tadditionalData: Partial<Record<string, any>>\n\t): DTOType & Record<string, any> {\n\t\tconst basicView = this.transformToBasicView(record);\n\t\treturn { ...basicView, ...additionalData };\n\t}\n\n\t/**\n\t * Transforms a document using a custom mapping function\n\t *\n\t * @template OutputType - The output type after mapping\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {(input: DTOType) => OutputType} mapFn - Mapping function for custom transformation\n\t * @returns {OutputType} Custom transformed output\n\t */\n\tpublic transformWithMapping<OutputType = DTOType>(\n\t\trecord: DocumentType<ModelType>,\n\t\tmapFn: (input: DTOType) => OutputType\n\t): OutputType {\n\t\tconst basicView = this.transformToBasicView(record);\n\t\treturn mapFn(basicView);\n\t}\n\n\t/**\n\t * Transforms a nested property of the document\n\t *\n\t * @template NestedType - The type of the nested property\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {string} path - Dot-notation path to the nested property\n\t * @param {z.ZodType<any>} nestedSchema - Zod schema for the nested property\n\t * @returns {NestedType} The transformed nested property\n\t * @throws {Error} When path is not found in record\n\t */\n\tpublic transformNestedProperty<NestedType>(\n\t\trecord: DocumentType<ModelType>,\n\t\tpath: string,\n\t\tnestedSchema: z.ZodType<any>\n\t): NestedType {\n\t\tif (!record) {\n\t\t\tthrow new Error('Record not found');\n\t\t}\n\n\t\tconst parts = path.split('.');\n\t\tlet current: any = record;\n\n\t\tfor (const part of parts) {\n\t\t\tif (current && part in current) {\n\t\t\t\tcurrent = current[part];\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Path ${path} not found in record`);\n\t\t\t}\n\t\t}\n\n\t\treturn nestedSchema.parse(current) as NestedType;\n\t}\n\n\t/**\n\t * Transforms a document with default values for missing fields\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {Partial<DTOType>} defaults - Default values for fields\n\t * @returns {DTOType} DTO with defaults applied\n\t */\n\tpublic transformWithDefaults(record: DocumentType<ModelType>, defaults: Partial<DTOType>): DTOType {\n\t\tconst transformed = this.transformToBasicView(record);\n\t\treturn { ...defaults, ...transformed };\n\t}\n}\n\n/**\n * Creates a transformer instance for the given schema.\n * Uses dependency injection if available, falls back to creating a new instance.\n *\n * @template ModelType - The Mongoose model type\n * @template DTOType - The output DTO type\n * @param {z.ZodType<any>} schema - Zod schema for validation and transformation\n * @returns {GlobalTransformer<ModelType, DTOType>} Instance of GlobalTransformer\n */\nexport function createTransformer<ModelType, DTOType>(\n\tschema: z.ZodType<any>\n): GlobalTransformer<ModelType, DTOType> {\n\ttry {\n\t\treturn Container.get(GlobalTransformer) as GlobalTransformer<ModelType, DTOType>;\n\t} catch (error) {\n\t\treturn new GlobalTransformer<ModelType, DTOType>(schema);\n\t}\n}\n"]}
1
+ {"version":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oBAAoB,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAC;IACxC,CAAC;CACD,CAAA;AA9MY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gBAAO,GAAE;qCAOmB,OAAC,CAAC,OAAO;GANzB,iBAAiB,CA8M7B;AAWD,SAAgB,iBAAiB,CAChC,MAAsB;IAEtB,IAAI,CAAC;QACJ,OAAO,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAA0C,CAAC;IAClF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,IAAI,iBAAiB,CAAqB,MAAM,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC","sourcesContent":["import { DocumentType } from '@typegoose/typegoose';\nimport Container, { Service } from 'typedi';\nimport { z } from 'zod';\n\n/**\n * Type definition for pagination metadata\n */\ntype Metadata = {\n\tpage: number;\n\tsize: number;\n\ttotalElements: number;\n\ttotalPages: number;\n\t[key: string]: string | number | boolean | null | undefined;\n};\n\n/**\n * Type definition for paginated response\n */\ntype PaginatedResponse<T> = {\n\tmetadata?: Metadata;\n\tdocuments: T[];\n};\n\n/**\n * GlobalTransformer provides a reusable way to transform Mongoose documents\n * into DTOs using Zod schemas for validation and type safety.\n *\n * @template ModelType - The Mongoose model type\n * @template DTOType - The output DTO type\n */\n@Service()\nexport class GlobalTransformer<ModelType, DTOType> {\n\t/**\n\t * Creates a new GlobalTransformer\n\t *\n\t * @param {z.ZodType<any>} schema - Zod schema used for validation and transformation\n\t */\n\tconstructor(private schema: z.ZodType<any>) {}\n\n\t/**\n\t * Transforms a single document to a DTO\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @returns {DTOType} The transformed DTO\n\t * @throws {Error} When record is not found\n\t */\n\tpublic transformToBasicView(record: DocumentType<ModelType> | DTOType): DTOType {\n\t\tif (!record) {\n\t\t\tthrow new Error('Record not found');\n\t\t}\n\n\t\treturn this.schema.parse(record) as DTOType;\n\t}\n\n\t/**\n\t * Transforms an array of documents or a paginated response to a paginated DTO response\n\t *\n\t * @param {DocumentType<ModelType>[] | DTOType[] | PaginatedResponse<DocumentType<ModelType>> | PaginatedResponse<DTOType>} records - Records to transform\n\t * @returns {PaginatedResponse<DTOType>} Paginated response with transformed DTOs\n\t * @throws {Error} When input type is invalid\n\t */\n\tpublic transformToBasicViewArray<T extends DocumentType<ModelType> | DTOType>(\n\t\trecords: T[] | PaginatedResponse<T>\n\t): PaginatedResponse<DTOType> {\n\t\t// Case 1: If records is already in the paginated format\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\n\t\t\tconst paginatedRecords = records as\n\t\t\t\t| PaginatedResponse<DocumentType<ModelType>>\n\t\t\t\t| PaginatedResponse<DTOType>;\n\n\t\t\t// Process the documents array\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToBasicView(doc))\n\t\t\t\t: [];\n\n\t\t\t// Return the entire paginated structure\n\t\t\treturn {\n\t\t\t\tmetadata: paginatedRecords.metadata,\n\t\t\t\tdocuments: processedDocuments,\n\t\t\t};\n\t\t}\n\n\t\t// Case 2: If records is an array\n\t\tif (Array.isArray(records)) {\n\t\t\tif (records.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tdocuments: [],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst transformedRecords = records.map(record => this.transformToBasicView(record));\n\n\t\t\t// Return in paginated format with default metadata\n\t\t\treturn {\n\t\t\t\tdocuments: transformedRecords,\n\t\t\t};\n\t\t}\n\n\t\t// Fallback for unexpected input\n\t\tthrow new Error('Invalid input type for transformToBasicViewArray');\n\t}\n\n\t/**r\n\t * Creates a partial view with only the specified fields\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\n\t * @returns {Partial<DTOType>} Partial DTO with only the specified fields\n\t */\n\tpublic transformToPartialView(\n\t\trecord: DocumentType<ModelType>,\n\t\tfields: (keyof DTOType)[]\n\t): Partial<DTOType> {\n\t\tconst fullView = this.transformToBasicView(record);\n\t\tconst partialView: Partial<DTOType> = {};\n\n\t\tfields.forEach(field => {\n\t\t\tconst dto = fullView as Record<keyof DTOType, any>;\n\t\t\tpartialView[field] = dto[field];\n\t\t});\n\n\t\treturn partialView;\n\t}\n\n\t/**\n\t * Creates partial views for an array of documents\n\t *\n\t * @param {DocumentType<ModelType>[]} records - Array of documents to transform\n\t * @param {(keyof DTOType)[]} fields - Fields to include in the output\n\t * @returns {Partial<DTOType>[]} Array of partial DTOs\n\t */\n\tpublic transformToPartialViewArray(\n\t\trecords: DocumentType<ModelType>[] | PaginatedResponse<DocumentType<ModelType>>,\n\t\tfields: (keyof DTOType)[]\n\t): Partial<DTOType>[] | PaginatedResponse<Partial<DTOType>> {\n\t\t// Case 1: If records is already in the paginated format\n\t\tif (records && typeof records === 'object' && 'metadata' in records && 'documents' in records) {\n\t\t\tconst paginatedRecords = records as PaginatedResponse<DocumentType<ModelType>>;\n\n\t\t\t// Process the documents array\n\t\t\tconst processedDocuments = Array.isArray(paginatedRecords.documents)\n\t\t\t\t? paginatedRecords.documents.map(doc => this.transformToPartialView(doc, fields))\n\t\t\t\t: [];\n\n\t\t\t// Return the entire paginated structure\n\t\t\treturn {\n\t\t\t\tmetadata: paginatedRecords.metadata,\n\t\t\t\tdocuments: processedDocuments,\n\t\t\t};\n\t\t}\n\n\t\t// Case 2: If records is an array\n\t\tif (Array.isArray(records)) {\n\t\t\tif (records.length === 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn records.map(record => this.transformToPartialView(record, fields));\n\t\t}\n\n\t\t// Fallback for unexpected input\n\t\tthrow new Error('Invalid input type for transformToPartialViewArray');\n\t}\n\t/**\n\t * Transforms a document and adds additional computed fields\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {Partial<Record<string, any>>} additionalData - Additional fields to add\n\t * @returns {DTOType & Record<string, any>} DTO with additional fields\n\t */\n\tpublic transformWithAdditionalData(\n\t\trecord: DocumentType<ModelType>,\n\t\tadditionalData: Partial<Record<string, any>>\n\t): DTOType & Record<string, any> {\n\t\tconst basicView = this.transformToBasicView(record);\n\t\treturn { ...basicView, ...additionalData };\n\t}\n\n\t/**\n\t * Transforms a document using a custom mapping function\n\t *\n\t * @template OutputType - The output type after mapping\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {(input: DTOType) => OutputType} mapFn - Mapping function for custom transformation\n\t * @returns {OutputType} Custom transformed output\n\t */\n\tpublic transformWithMapping<OutputType = DTOType>(\n\t\trecord: DocumentType<ModelType>,\n\t\tmapFn: (input: DTOType) => OutputType\n\t): OutputType {\n\t\tconst basicView = this.transformToBasicView(record);\n\t\treturn mapFn(basicView);\n\t}\n\n\t/**\n\t * Transforms a nested property of the document\n\t *\n\t * @template NestedType - The type of the nested property\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {string} path - Dot-notation path to the nested property\n\t * @param {z.ZodType<any>} nestedSchema - Zod schema for the nested property\n\t * @returns {NestedType} The transformed nested property\n\t * @throws {Error} When path is not found in record\n\t */\n\tpublic transformNestedProperty<NestedType>(\n\t\trecord: DocumentType<ModelType>,\n\t\tpath: string,\n\t\tnestedSchema: z.ZodType<any>\n\t): NestedType {\n\t\tif (!record) {\n\t\t\tthrow new Error('Record not found');\n\t\t}\n\n\t\tconst parts = path.split('.');\n\t\tlet current: any = record;\n\n\t\tfor (const part of parts) {\n\t\t\tif (current && part in current) {\n\t\t\t\tcurrent = current[part];\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Path ${path} not found in record`);\n\t\t\t}\n\t\t}\n\n\t\treturn nestedSchema.parse(current) as NestedType;\n\t}\n\n\t/**\n\t * Transforms a document with default values for missing fields\n\t *\n\t * @param {DocumentType<ModelType>} record - The document to transform\n\t * @param {Partial<DTOType>} defaults - Default values for fields\n\t * @returns {DTOType} DTO with defaults applied\n\t */\n\tpublic transformWithDefaults(record: DocumentType<ModelType>, defaults: Partial<DTOType>): DTOType {\n\t\tconst transformed = this.transformToBasicView(record);\n\t\treturn { ...defaults, ...transformed };\n\t}\n}\n\n/**\n * Creates a transformer instance for the given schema.\n * Uses dependency injection if available, falls back to creating a new instance.\n *\n * @template ModelType - The Mongoose model type\n * @template DTOType - The output DTO type\n * @param {z.ZodType<any>} schema - Zod schema for validation and transformation\n * @returns {GlobalTransformer<ModelType, DTOType>} Instance of GlobalTransformer\n */\nexport function createTransformer<ModelType, DTOType>(\n\tschema: z.ZodType<any>\n): GlobalTransformer<ModelType, DTOType> {\n\ttry {\n\t\treturn Container.get(GlobalTransformer) as GlobalTransformer<ModelType, DTOType>;\n\t} catch (error) {\n\t\treturn new GlobalTransformer<ModelType, DTOType>(schema);\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.3.159",
3
+ "version": "1.3.161",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",