@common-stack/store-mongo 8.2.4-alpha.11 → 8.2.4-alpha.14
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.
- package/lib/containers/container.js +1 -1
- package/lib/containers/container.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/store/models/common-options.d.ts +21 -0
- package/lib/store/models/common-options.js +33 -2
- package/lib/store/models/common-options.js.map +1 -1
- package/lib/store/repositories/BaseMongoRepository.d.ts +13 -0
- package/lib/store/repositories/BaseMongoRepository.js +38 -36
- package/lib/store/repositories/BaseMongoRepository.js.map +1 -1
- package/package.json +5 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ContainerModule}from'inversify';import {SERVER_TYPES}from'common/server';import {BaseMongoRepository}from'../store/repositories/BaseMongoRepository.js';import'../store/repositories/base-repository.js';/**
|
|
1
|
+
import {ContainerModule}from'inversify';import {SERVER_TYPES}from'common/server';import'mongoose-lean-virtuals';import {BaseMongoRepository}from'../store/repositories/BaseMongoRepository.js';import'../store/repositories/base-repository.js';/**
|
|
2
2
|
* Local services and exposed microservices to serve remote connections.
|
|
3
3
|
* Operates within in the Gateway.
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sources":["../../src/containers/container.ts"],"sourcesContent":["import { ContainerModule, interfaces } from 'inversify';\nimport { SERVER_TYPES } from 'common/server';\nimport { BaseMongoRepository } from '../store';\n\n/**\n * Local services and exposed microservices to serve remote connections.\n * Operates within in the Gateway.\n *\n */\nexport const localContainerModule: (settings) => interfaces.ContainerModule = () =>\n new ContainerModule((bind: interfaces.Bind) => {\n bind(SERVER_TYPES.BaseMongoRepository).to(BaseMongoRepository).inSingletonScope().whenTargetIsDefault();\n });\n\n/**\n * Operates external to the Gateway. Usually a broker listen to calls and invoke this service\n * local to the micro container.\n *\n * @param settings Settings\n */\nexport const externalContainerModule: (settings) => interfaces.ContainerModule = () =>\n new ContainerModule((bind: interfaces.Bind) => {\n bind(SERVER_TYPES.BaseMongoRepository).to(BaseMongoRepository).inSingletonScope().whenTargetIsDefault();\n });\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"container.js","sources":["../../src/containers/container.ts"],"sourcesContent":["import { ContainerModule, interfaces } from 'inversify';\nimport { SERVER_TYPES } from 'common/server';\nimport { BaseMongoRepository } from '../store';\n\n/**\n * Local services and exposed microservices to serve remote connections.\n * Operates within in the Gateway.\n *\n */\nexport const localContainerModule: (settings) => interfaces.ContainerModule = () =>\n new ContainerModule((bind: interfaces.Bind) => {\n bind(SERVER_TYPES.BaseMongoRepository).to(BaseMongoRepository).inSingletonScope().whenTargetIsDefault();\n });\n\n/**\n * Operates external to the Gateway. Usually a broker listen to calls and invoke this service\n * local to the micro container.\n *\n * @param settings Settings\n */\nexport const externalContainerModule: (settings) => interfaces.ContainerModule = () =>\n new ContainerModule((bind: interfaces.Bind) => {\n bind(SERVER_TYPES.BaseMongoRepository).to(BaseMongoRepository).inSingletonScope().whenTargetIsDefault();\n });\n"],"names":[],"mappings":"gPAIA;;;;AAIG;AACI,MAAM,oBAAoB,GAA6C,MAC1E,IAAI,eAAe,CAAC,CAAC,IAAqB,KAAI;AAC1C,IAAA,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,gBAAgB,EAAE,CAAC,mBAAmB,EAAE,CAAC;AAC5G,CAAC,EAAE;AAEP;;;;;AAKG;AACI,MAAM,uBAAuB,GAA6C,MAC7E,IAAI,eAAe,CAAC,CAAC,IAAqB,KAAI;AAC1C,IAAA,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,gBAAgB,EAAE,CAAC,mBAAmB,EAAE,CAAC;AAC5G,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.js';export{ConnectionPoolManager}from'./services/ConnectionPoolManager.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields2,commonModelSchemaOptions2}from'./store/models/common-options-v2.js';export{addIdVirtualFields,commonModeSchemaOptions}from'./store/models/common-options.js';export{BaseMongoRepository}from'./store/repositories/BaseMongoRepository.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader2}from'./dataloaders/bulk-dataloader-v2.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin as BaseServiceMixin2}from'./mixins/BaseServiceMixin.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.js';export{PAGINATION_OPTIONS}from'./interfaces/getAllArgs.js';//# sourceMappingURL=index.js.map
|
|
1
|
+
export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.js';export{ConnectionPoolManager}from'./services/ConnectionPoolManager.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields2,commonModelSchemaOptions2}from'./store/models/common-options-v2.js';export{addIdVirtualFields,applyCommonSchemaPlugins,applyLeanVirtuals,commonModeSchemaOptions}from'./store/models/common-options.js';export{BaseMongoRepository}from'./store/repositories/BaseMongoRepository.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader2}from'./dataloaders/bulk-dataloader-v2.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin as BaseServiceMixin2}from'./mixins/BaseServiceMixin.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.js';export{PAGINATION_OPTIONS}from'./interfaces/getAllArgs.js';//# sourceMappingURL=index.js.map
|
|
@@ -10,6 +10,27 @@ export declare const commonModeSchemaOptions: {
|
|
|
10
10
|
transform(doc: any, ret: any): void;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Applies the mongoose-lean-virtuals plugin to a schema.
|
|
15
|
+
* This allows .lean() queries to include virtual fields automatically.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* const MySchema = new Schema({ ... });
|
|
19
|
+
* applyLeanVirtuals(MySchema);
|
|
20
|
+
* // Now .lean() will include virtuals, or use .lean({ virtuals: true })
|
|
21
|
+
*/
|
|
22
|
+
export declare const applyLeanVirtuals: (schema: Schema) => Schema;
|
|
23
|
+
/**
|
|
24
|
+
* Applies common schema configurations including:
|
|
25
|
+
* - toJSON with virtuals
|
|
26
|
+
* - toObject with virtuals
|
|
27
|
+
* - mongoose-lean-virtuals plugin for .lean() queries
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* const MySchema = new Schema({ ... });
|
|
31
|
+
* applyCommonSchemaPlugins(MySchema);
|
|
32
|
+
*/
|
|
33
|
+
export declare const applyCommonSchemaPlugins: (schema: Schema) => Schema;
|
|
13
34
|
export declare const addIdVirtualFields: (schema: Schema) => Schema<any, import("mongoose").Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
|
|
14
35
|
[x: string]: any;
|
|
15
36
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const commonModeSchemaOptions = {
|
|
1
|
+
import mongooseLeanVirtuals from'mongoose-lean-virtuals';const commonModeSchemaOptions = {
|
|
2
2
|
timestamps: true,
|
|
3
3
|
toJSON: {
|
|
4
4
|
virtuals: true,
|
|
@@ -12,9 +12,40 @@ const commonModeSchemaOptions = {
|
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Applies the mongoose-lean-virtuals plugin to a schema.
|
|
17
|
+
* This allows .lean() queries to include virtual fields automatically.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* const MySchema = new Schema({ ... });
|
|
21
|
+
* applyLeanVirtuals(MySchema);
|
|
22
|
+
* // Now .lean() will include virtuals, or use .lean({ virtuals: true })
|
|
23
|
+
*/
|
|
24
|
+
const applyLeanVirtuals = (schema) => {
|
|
25
|
+
schema.plugin(mongooseLeanVirtuals);
|
|
26
|
+
return schema;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Applies common schema configurations including:
|
|
30
|
+
* - toJSON with virtuals
|
|
31
|
+
* - toObject with virtuals
|
|
32
|
+
* - mongoose-lean-virtuals plugin for .lean() queries
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* const MySchema = new Schema({ ... });
|
|
36
|
+
* applyCommonSchemaPlugins(MySchema);
|
|
37
|
+
*/
|
|
38
|
+
const applyCommonSchemaPlugins = (schema) => {
|
|
39
|
+
schema.set('toJSON', { virtuals: true });
|
|
40
|
+
schema.set('toObject', { virtuals: true, getters: true });
|
|
41
|
+
schema.plugin(mongooseLeanVirtuals);
|
|
42
|
+
return schema;
|
|
43
|
+
};
|
|
15
44
|
const addIdVirtualFields = (schema) => {
|
|
16
45
|
schema.set('toJSON', {
|
|
17
46
|
virtuals: true,
|
|
18
47
|
});
|
|
48
|
+
// Apply mongoose-lean-virtuals plugin so .lean() queries include virtuals
|
|
49
|
+
schema.plugin(mongooseLeanVirtuals);
|
|
19
50
|
return schema;
|
|
20
|
-
};export{addIdVirtualFields,commonModeSchemaOptions};//# sourceMappingURL=common-options.js.map
|
|
51
|
+
};export{addIdVirtualFields,applyCommonSchemaPlugins,applyLeanVirtuals,commonModeSchemaOptions};//# sourceMappingURL=common-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-options.js","sources":["../../../src/store/models/common-options.ts"],"sourcesContent":["import { Schema } from 'mongoose';\n\nexport const commonModeSchemaOptions = {\n timestamps: true,\n toJSON: {\n virtuals: true,\n },\n toObject: {\n virtuals: true,\n getters: true,\n transform(doc, ret) {\n delete ret.__v;\n delete ret._id;\n },\n },\n};\n\nexport const addIdVirtualFields = (schema: Schema) => {\n schema.set('toJSON', {\n virtuals: true,\n });\n return schema;\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common-options.js","sources":["../../../src/store/models/common-options.ts"],"sourcesContent":["import { Schema } from 'mongoose';\nimport mongooseLeanVirtuals from 'mongoose-lean-virtuals';\n\nexport const commonModeSchemaOptions = {\n timestamps: true,\n toJSON: {\n virtuals: true,\n },\n toObject: {\n virtuals: true,\n getters: true,\n transform(doc, ret) {\n delete ret.__v;\n delete ret._id;\n },\n },\n};\n\n/**\n * Applies the mongoose-lean-virtuals plugin to a schema.\n * This allows .lean() queries to include virtual fields automatically.\n *\n * Usage:\n * const MySchema = new Schema({ ... });\n * applyLeanVirtuals(MySchema);\n * // Now .lean() will include virtuals, or use .lean({ virtuals: true })\n */\nexport const applyLeanVirtuals = (schema: Schema): Schema => {\n schema.plugin(mongooseLeanVirtuals);\n return schema;\n};\n\n/**\n * Applies common schema configurations including:\n * - toJSON with virtuals\n * - toObject with virtuals\n * - mongoose-lean-virtuals plugin for .lean() queries\n *\n * Usage:\n * const MySchema = new Schema({ ... });\n * applyCommonSchemaPlugins(MySchema);\n */\nexport const applyCommonSchemaPlugins = (schema: Schema): Schema => {\n schema.set('toJSON', { virtuals: true });\n schema.set('toObject', { virtuals: true, getters: true });\n schema.plugin(mongooseLeanVirtuals);\n return schema;\n};\n\nexport const addIdVirtualFields = (schema: Schema) => {\n schema.set('toJSON', {\n virtuals: true,\n });\n // Apply mongoose-lean-virtuals plugin so .lean() queries include virtuals\n schema.plugin(mongooseLeanVirtuals);\n return schema;\n};\n"],"names":[],"mappings":"yDAGa,MAAA,uBAAuB,GAAG;AACnC,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,MAAM,EAAE;AACJ,QAAA,QAAQ,EAAE,IAAI;AACjB,KAAA;AACD,IAAA,QAAQ,EAAE;AACN,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,OAAO,EAAE,IAAI;QACb,SAAS,CAAC,GAAG,EAAE,GAAG,EAAA;YACd,OAAO,GAAG,CAAC,GAAG,CAAC;YACf,OAAO,GAAG,CAAC,GAAG,CAAC;SAClB;AACJ,KAAA;EACH;AAEF;;;;;;;;AAQG;AACU,MAAA,iBAAiB,GAAG,CAAC,MAAc,KAAY;AACxD,IAAA,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACpC,IAAA,OAAO,MAAM,CAAC;AAClB,EAAE;AAEF;;;;;;;;;AASG;AACU,MAAA,wBAAwB,GAAG,CAAC,MAAc,KAAY;IAC/D,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,IAAA,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1D,IAAA,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACpC,IAAA,OAAO,MAAM,CAAC;AAClB,EAAE;AAEW,MAAA,kBAAkB,GAAG,CAAC,MAAc,KAAI;AACjD,IAAA,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;AACjB,QAAA,QAAQ,EAAE,IAAI;AACjB,KAAA,CAAC,CAAC;;AAEH,IAAA,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACpC,IAAA,OAAO,MAAM,CAAC;AAClB"}
|
|
@@ -18,6 +18,19 @@ export declare class BaseMongoRepository<SchemaType> implements IBaseMongoReposi
|
|
|
18
18
|
* Transforms a document to the domain model format
|
|
19
19
|
*/
|
|
20
20
|
protected transformDocument(doc: any): AsDomainType<SchemaType> | null;
|
|
21
|
+
/**
|
|
22
|
+
* Ensures the id field is present in a lean document
|
|
23
|
+
* This is a fallback for when .lean({ virtuals: true }) doesn't include the id virtual
|
|
24
|
+
*/
|
|
25
|
+
protected ensureIdField<T extends Record<string, any>>(doc: T): T & {
|
|
26
|
+
id: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Ensures id field is present in an array of lean documents
|
|
30
|
+
*/
|
|
31
|
+
protected ensureIdFields<T extends Record<string, any>>(docs: T[]): (T & {
|
|
32
|
+
id: string;
|
|
33
|
+
})[];
|
|
21
34
|
/**
|
|
22
35
|
* Transforms an array of documents
|
|
23
36
|
*/
|
|
@@ -57,6 +57,26 @@ let BaseMongoRepository = BaseMongoRepository_1 = class BaseMongoRepository {
|
|
|
57
57
|
// For Mongoose documents, use the built-in toObject transformation
|
|
58
58
|
return doc.toObject();
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Ensures the id field is present in a lean document
|
|
62
|
+
* This is a fallback for when .lean({ virtuals: true }) doesn't include the id virtual
|
|
63
|
+
*/
|
|
64
|
+
ensureIdField(doc) {
|
|
65
|
+
if (!doc)
|
|
66
|
+
return doc;
|
|
67
|
+
if (!doc.id && doc._id) {
|
|
68
|
+
doc.id = typeof doc._id === 'object' && doc._id.toString ? doc._id.toString() : doc._id;
|
|
69
|
+
}
|
|
70
|
+
return doc;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Ensures id field is present in an array of lean documents
|
|
74
|
+
*/
|
|
75
|
+
ensureIdFields(docs) {
|
|
76
|
+
if (!docs || !Array.isArray(docs))
|
|
77
|
+
return [];
|
|
78
|
+
return docs.map((doc) => this.ensureIdField(doc));
|
|
79
|
+
}
|
|
60
80
|
/**
|
|
61
81
|
* Transforms an array of documents
|
|
62
82
|
*/
|
|
@@ -174,14 +194,14 @@ let BaseMongoRepository = BaseMongoRepository_1 = class BaseMongoRepository {
|
|
|
174
194
|
}
|
|
175
195
|
async get(conditions, selectedFields) {
|
|
176
196
|
try {
|
|
177
|
-
const response = await this.model
|
|
197
|
+
const response = await this.model
|
|
198
|
+
.findOne(this.mapConditions(conditions), selectedFields)
|
|
199
|
+
.lean({ virtuals: true })
|
|
200
|
+
.exec();
|
|
178
201
|
if (!response)
|
|
179
202
|
return null;
|
|
180
|
-
// Ensure id
|
|
181
|
-
|
|
182
|
-
response.id = response._id.toString();
|
|
183
|
-
}
|
|
184
|
-
return response;
|
|
203
|
+
// Ensure id field is present (fallback for schemas without virtuals)
|
|
204
|
+
return this.ensureIdField(response);
|
|
185
205
|
}
|
|
186
206
|
catch (e) {
|
|
187
207
|
this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', conditions);
|
|
@@ -190,14 +210,11 @@ let BaseMongoRepository = BaseMongoRepository_1 = class BaseMongoRepository {
|
|
|
190
210
|
}
|
|
191
211
|
async find(conditions, selectedFields) {
|
|
192
212
|
try {
|
|
193
|
-
const response = await this.model.findOne(conditions, selectedFields).lean().exec();
|
|
213
|
+
const response = await this.model.findOne(conditions, selectedFields).lean({ virtuals: true }).exec();
|
|
194
214
|
if (!response)
|
|
195
215
|
return null;
|
|
196
|
-
// Ensure id
|
|
197
|
-
|
|
198
|
-
response.id = response._id.toString();
|
|
199
|
-
}
|
|
200
|
-
return response;
|
|
216
|
+
// Ensure id field is present (fallback for schemas without virtuals)
|
|
217
|
+
return this.ensureIdField(response);
|
|
201
218
|
}
|
|
202
219
|
catch (e) {
|
|
203
220
|
this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', conditions);
|
|
@@ -214,15 +231,10 @@ let BaseMongoRepository = BaseMongoRepository_1 = class BaseMongoRepository {
|
|
|
214
231
|
.sort(sortBy)
|
|
215
232
|
.limit(limit || PAGINATION_OPTIONS.limit)
|
|
216
233
|
.skip(skip || PAGINATION_OPTIONS.skip)
|
|
217
|
-
.lean()
|
|
234
|
+
.lean({ virtuals: true })
|
|
218
235
|
.exec();
|
|
219
|
-
// Ensure id
|
|
220
|
-
return
|
|
221
|
-
if (doc._id && !doc.id) {
|
|
222
|
-
doc.id = doc._id.toString();
|
|
223
|
-
}
|
|
224
|
-
return doc;
|
|
225
|
-
});
|
|
236
|
+
// Ensure id field is present for all documents (fallback for schemas without virtuals)
|
|
237
|
+
return this.ensureIdFields(response);
|
|
226
238
|
}
|
|
227
239
|
catch (e) {
|
|
228
240
|
this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', options);
|
|
@@ -339,14 +351,9 @@ let BaseMongoRepository = BaseMongoRepository_1 = class BaseMongoRepository {
|
|
|
339
351
|
const mappedCriteria = this.mapConditions(criteria);
|
|
340
352
|
await this.model.updateMany(mappedCriteria, update, options);
|
|
341
353
|
// Fetch the updated documents
|
|
342
|
-
const response = await this.model.find(mappedCriteria).lean().exec();
|
|
343
|
-
// Ensure id
|
|
344
|
-
return
|
|
345
|
-
if (doc._id && !doc.id) {
|
|
346
|
-
doc.id = doc._id.toString();
|
|
347
|
-
}
|
|
348
|
-
return doc;
|
|
349
|
-
});
|
|
354
|
+
const response = await this.model.find(mappedCriteria).lean({ virtuals: true }).exec();
|
|
355
|
+
// Ensure id field is present for all documents (fallback for schemas without virtuals)
|
|
356
|
+
return this.ensureIdFields(response);
|
|
350
357
|
}
|
|
351
358
|
catch (e) {
|
|
352
359
|
this.logger.error(e, 'Unable to Bulk Update with criteria [%j] and data [%j]', criteria, update);
|
|
@@ -399,14 +406,9 @@ let BaseMongoRepository = BaseMongoRepository_1 = class BaseMongoRepository {
|
|
|
399
406
|
if (selectedFields) {
|
|
400
407
|
findQuery = findQuery.select(selectedFields);
|
|
401
408
|
}
|
|
402
|
-
const results = await findQuery.lean().exec();
|
|
403
|
-
// Ensure id
|
|
404
|
-
return
|
|
405
|
-
if (doc._id && !doc.id) {
|
|
406
|
-
doc.id = doc._id.toString();
|
|
407
|
-
}
|
|
408
|
-
return doc;
|
|
409
|
-
});
|
|
409
|
+
const results = await findQuery.lean({ virtuals: true }).exec();
|
|
410
|
+
// Ensure id field is present for all documents (fallback for schemas without virtuals)
|
|
411
|
+
return this.ensureIdFields(results);
|
|
410
412
|
}
|
|
411
413
|
catch (e) {
|
|
412
414
|
this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', ids);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseMongoRepository.js","sources":["../../../src/store/repositories/BaseMongoRepository.ts"],"sourcesContent":["/* eslint-disable import/no-unresolved */\n/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable no-param-reassign */\n/* eslint-disable no-underscore-dangle */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable class-methods-use-this */\nimport { isObject } from 'lodash-es';\nimport { CdmLogger } from '@cdm-logger/core';\nimport { Connection, FilterQuery, Model, PipelineStage, Types, UpdateQuery } from 'mongoose';\nimport { injectable, unmanaged } from 'inversify';\nimport {\n GetAllArgs,\n ISort,\n IBaseMongoRepository,\n IMongoOptions,\n PAGINATION_OPTIONS,\n AsDomainType,\n CreateType,\n UpdateType,\n} from 'common/server';\n\n@injectable()\nexport class BaseMongoRepository<SchemaType> implements IBaseMongoRepository<SchemaType> {\n private options: IMongoOptions;\n\n protected logger: CdmLogger.ILogger;\n\n model: Model<SchemaType & { id: string }>;\n\n constructor(\n @unmanaged()\n private modelFunc: (db: Connection) => Model<SchemaType>,\n\n db: Connection,\n @unmanaged()\n logger: CdmLogger.ILogger,\n @unmanaged()\n options?: IMongoOptions,\n ) {\n // Safe model registration to prevent \"Cannot overwrite model once compiled\" errors\n this.model = this.safeModelRegistration(db) as Model<SchemaType & { id: string }>;\n this.options = options;\n this.logger = logger.child({ className: BaseMongoRepository.name });\n }\n\n /**\n * Safely registers or retrieves a Mongoose model to prevent overwrite errors\n * This is crucial for development environments where multiple containers might try to register the same model\n */\n private safeModelRegistration(db: Connection): Model<SchemaType> {\n try {\n return this.modelFunc(db);\n } catch (error) {\n // If the error is about overwriting a model, try to get the existing model\n if (error instanceof Error && error.message.includes('Cannot overwrite')) {\n // Extract model name from the error message or try to infer it\n const modelNameMatch = error.message.match(/Cannot overwrite `(\\w+)` model/);\n if (modelNameMatch) {\n const modelName = modelNameMatch[1];\n try {\n return db.model(modelName);\n } catch (getError) {\n // If we can't get the existing model, re-throw the original error\n throw error;\n }\n }\n }\n // For any other error, re-throw it\n throw error;\n }\n }\n\n /**\n * Transforms a document to the domain model format\n */\n protected transformDocument(doc: any): AsDomainType<SchemaType> | null {\n if (!doc) return null;\n\n // If it's already a plain object (not a Mongoose document)\n if (!doc.toObject) {\n // Ensure id exists if _id is present\n if (doc._id && !doc.id) {\n doc.id = typeof doc._id === 'object' && doc._id.toString ? doc._id.toString() : doc._id;\n }\n return doc as unknown as AsDomainType<SchemaType>;\n }\n\n // For Mongoose documents, use the built-in toObject transformation\n return doc.toObject() as AsDomainType<SchemaType>;\n }\n\n /**\n * Transforms an array of documents\n */\n protected transformDocuments(docs: SchemaType[]): AsDomainType<SchemaType>[] {\n if (!docs || !Array.isArray(docs)) return [];\n return docs.map((doc) => this.transformDocument(doc)).filter(Boolean) as AsDomainType<SchemaType>[];\n }\n\n /**\n * Maps API criteria with 'id' to MongoDB criteria with '_id'\n */\n private mapConditions(conditions?: FilterQuery<SchemaType>): FilterQuery<SchemaType> {\n if (!conditions) return {};\n\n const { id, ...remaining } = conditions as any;\n\n if (!id) return remaining as FilterQuery<SchemaType>;\n\n // Handle custom _id that might not be an ObjectId\n let _id;\n if (Types.ObjectId.isValid(id)) {\n _id = new Types.ObjectId(id);\n } else {\n _id = id; // Use the id as-is if it's not a valid ObjectId\n }\n\n return {\n _id,\n ...remaining,\n } as FilterQuery<SchemaType>;\n }\n\n /**\n * Computes sort object from GetAllArgs sort parameter\n * Handles both string-based and object-based sort specifications\n */\n protected computeSort(sort: ISort | string | ISort[]): Record<string, 1 | -1> {\n // Default sort by createdAt descending if available, otherwise empty sort\n if (!sort) {\n return { createdAt: -1 };\n }\n\n // Handle object-based sort { key: 'fieldName', value: 'asc'|'desc' }\n if (isObject(sort) && 'key' in sort) {\n return {\n [sort.key]: sort.value?.toLowerCase() === 'asc' ? 1 : -1,\n };\n }\n\n // Handle string-based sort 'fieldName:asc' or 'fieldName:desc'\n if (typeof sort === 'string') {\n const [field, direction] = sort.split(':');\n if (field) {\n return {\n [field]: direction?.toLowerCase() === 'asc' ? 1 : -1,\n };\n }\n }\n\n // Handle array of sort specifications\n if (Array.isArray(sort)) {\n return sort.reduce((acc, sortItem) => {\n if (isObject(sortItem) && sortItem.key) {\n acc[sortItem.key] = sortItem.value?.toLowerCase() === 'asc' ? 1 : -1;\n }\n return acc;\n }, {});\n }\n\n // Fallback to default sort\n return { createdAt: -1 };\n }\n\n /**\n * Prepares an aggregation pipeline with standard stages\n * @param options Query options including filtering, sorting, pagination\n * @param customPipeline Optional custom pipeline stages to include\n * @returns Complete MongoDB aggregation pipeline\n */\n protected preparePipeline(options: GetAllArgs<SchemaType>, customPipeline: PipelineStage[] = []): PipelineStage[] {\n const { criteria, sort, limit, skip } = options;\n const pipeline: PipelineStage[] = [];\n\n // Match stage (filtering)\n if (criteria) {\n pipeline.push({\n $match: this.mapConditions(criteria),\n });\n }\n\n // Add custom pipeline stages\n if (customPipeline.length > 0) {\n pipeline.push(...customPipeline);\n }\n\n // Sort stage\n const sortBy = this.computeSort(sort);\n if (Object.keys(sortBy).length > 0) {\n pipeline.push({ $sort: sortBy });\n }\n\n // Pagination stages\n if (skip !== undefined) {\n pipeline.push({ $skip: skip || PAGINATION_OPTIONS.skip });\n }\n\n if (limit !== undefined) {\n pipeline.push({ $limit: limit || PAGINATION_OPTIONS.limit });\n }\n\n return pipeline;\n }\n\n /**\n * Execute an aggregation pipeline and transform the results\n */\n protected async aggregate(pipeline: PipelineStage[]): Promise<AsDomainType<SchemaType>[]> {\n try {\n const results = await this.model.aggregate(pipeline).exec();\n return this.transformDocuments(results);\n } catch (e) {\n this.logger.error(e, 'Error executing aggregation pipeline: %j', pipeline);\n throw e;\n }\n }\n\n public async count(conditions?: FilterQuery<SchemaType>): Promise<number> {\n return this.model.count(this.mapConditions(conditions)).exec();\n }\n\n public async get(\n conditions?: FilterQuery<SchemaType>,\n selectedFields?: string,\n ): Promise<AsDomainType<SchemaType> | null> {\n try {\n const response = await this.model.findOne(this.mapConditions(conditions), selectedFields).lean().exec();\n\n if (!response) return null;\n\n // Ensure id exists\n if (response && (response as any)._id && !(response as any).id) {\n (response as any).id = (response as any)._id.toString();\n }\n\n return response as AsDomainType<SchemaType>;\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', conditions);\n throw e;\n }\n }\n\n public async find(\n conditions: Partial<FilterQuery<SchemaType>>,\n selectedFields?: string,\n ): Promise<AsDomainType<SchemaType> | null> {\n try {\n const response = await this.model.findOne(conditions, selectedFields).lean().exec();\n\n if (!response) return null;\n\n // Ensure id exists\n if (response && (response as any)._id && !(response as any).id) {\n (response as any).id = (response as any)._id.toString();\n }\n\n return response as AsDomainType<SchemaType>;\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', conditions);\n throw e;\n }\n }\n\n public async getAll(options: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]> {\n try {\n const { criteria, selectedFields, sort, limit, skip } = options;\n const mappedCriteria = this.mapConditions(criteria);\n const sortBy = this.computeSort(sort);\n\n const response = await this.model\n .find(mappedCriteria, selectedFields)\n .sort(sortBy as any)\n .limit(limit || PAGINATION_OPTIONS.limit)\n .skip(skip || PAGINATION_OPTIONS.skip)\n .lean()\n .exec();\n\n // Ensure id exists for each document\n return response.map((doc) => {\n if (doc._id && !doc.id) {\n doc.id = doc._id.toString();\n }\n return doc as AsDomainType<SchemaType>;\n });\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', options);\n throw e;\n }\n }\n\n /**\n * Get all documents using aggregation pipeline\n */\n public async getAllWithPipeline(\n options: GetAllArgs<SchemaType>,\n customPipeline: PipelineStage[] = [],\n ): Promise<AsDomainType<SchemaType>[]> {\n try {\n const pipeline = this.preparePipeline(options, customPipeline);\n return this.aggregate(pipeline);\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with pipeline [%j]', customPipeline);\n throw e;\n }\n }\n\n public async getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n }> {\n const data = await this.getAll(options);\n const totalCount = await this.count(options.criteria);\n return { totalCount, data };\n }\n\n /**\n * Get all documents with count using aggregation pipeline\n */\n public async getAllWithCountAndPipeline(\n options: GetAllArgs<SchemaType>,\n customPipeline: PipelineStage[] = [],\n ): Promise<{\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n }> {\n // Clone options to avoid modifying the original\n const countOptions = { ...options };\n\n // Remove pagination for count\n delete countOptions.limit;\n delete countOptions.skip;\n\n // Prepare count pipeline (without pagination)\n const countPipeline = this.preparePipeline(countOptions, customPipeline);\n countPipeline.push({ $count: 'total' });\n\n // Execute both queries in parallel\n const [data, countResult] = await Promise.all([\n this.getAllWithPipeline(options, customPipeline),\n this.model.aggregate(countPipeline).exec(),\n ]);\n\n const totalCount = countResult?.[0]?.total || 0;\n return { data, totalCount };\n }\n\n public async create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>> {\n try {\n // Handle custom _id if provided in the data\n const createData = { ...data } as any;\n\n // If id is provided but _id is not, map id to _id\n if (createData.id && !createData._id) {\n createData._id = Types.ObjectId.isValid(createData.id)\n ? new Types.ObjectId(createData.id)\n : createData.id;\n delete createData.id; // Remove id to avoid conflicts\n }\n\n const response = await this.model.create(createData);\n return this.transformDocument(response);\n } catch (e) {\n this.logger.error(e, 'Unable to create Model with data [%j]', data);\n throw e;\n }\n }\n\n public async bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]> {\n try {\n const response = await this.model.insertMany(data, {\n lean: true,\n ordered: true,\n });\n\n // Ensure id exists for each document\n return response.map((doc: any) => {\n if (doc._id && !doc.id) {\n doc.id = doc._id.toString();\n }\n return doc as AsDomainType<SchemaType>;\n });\n } catch (e) {\n this.logger.error(e, 'Unable to bulk create due to error [%s]', e.message);\n throw e;\n }\n }\n\n public async upsert<T = UpdateType<SchemaType>>(\n conditions: FilterQuery<SchemaType>,\n update: T,\n options: Record<string, unknown> = {},\n ): Promise<AsDomainType<SchemaType>> {\n return this.update(conditions, update, {\n upsert: true,\n ...options,\n });\n }\n\n public async update<T = UpdateType<SchemaType>>(\n criteria: FilterQuery<SchemaType>,\n update: T | UpdateQuery<SchemaType>,\n options: Record<string, unknown> = {},\n ): Promise<AsDomainType<SchemaType>> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n const mergedOptions = {\n new: true,\n useFindAndModify: false,\n ...options,\n };\n\n const { id } = criteria as any;\n let response;\n\n if (id) {\n response = await this.model.findByIdAndUpdate(id, update as any, mergedOptions).exec();\n } else {\n response = await this.model.findOneAndUpdate(mappedCriteria, update as any, mergedOptions).exec();\n }\n\n return this.transformDocument(response);\n } catch (e) {\n this.logger.error(e, 'Unable to Update with criteria [%j] and data [%j]', criteria, update);\n throw e;\n }\n }\n\n public async bulkUpdate<T = UpdateType<SchemaType>>(\n criteria: FilterQuery<SchemaType>,\n update: T | UpdateQuery<SchemaType>,\n options: Record<string, unknown> = {},\n ): Promise<AsDomainType<SchemaType>[]> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n await this.model.updateMany(mappedCriteria, update as any, options);\n\n // Fetch the updated documents\n const response = await this.model.find(mappedCriteria).lean().exec();\n\n // Ensure id exists for each document\n return response.map((doc) => {\n if (doc._id && !doc.id) {\n doc.id = doc._id.toString();\n }\n return doc as AsDomainType<SchemaType>;\n });\n } catch (e) {\n this.logger.error(e, 'Unable to Bulk Update with criteria [%j] and data [%j]', criteria, update);\n throw e;\n }\n }\n\n public async delete(criteria: FilterQuery<SchemaType>): Promise<boolean> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n let deleted;\n\n if (criteria?.id) {\n deleted = await this.model.findByIdAndDelete(criteria.id);\n } else {\n deleted = await this.model.findOneAndDelete(mappedCriteria);\n }\n\n return !!deleted;\n } catch (e) {\n this.logger.error(e, 'Unable to delete the model with criteria [%j]', criteria);\n throw e;\n }\n }\n\n public async bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n const deleted = await this.model.deleteMany(mappedCriteria);\n return deleted?.deletedCount || 0;\n } catch (e) {\n this.logger.error(e, 'Unable to delete the model with criteria [%j]', criteria);\n throw e;\n }\n }\n\n public async bulkGet(ids: string[], selectedFields?: string): Promise<AsDomainType<SchemaType>[]> {\n try {\n // Create a query that handles both ObjectId and string IDs\n const query: any = { _id: { $in: [] } };\n\n // Process each ID\n ids?.forEach((id) => {\n if (Types.ObjectId.isValid(id)) {\n query._id.$in.push(new Types.ObjectId(id));\n } else {\n query._id.$in.push(id); // Add as string\n }\n });\n\n let findQuery = this.model.find(query);\n\n // apply select if selectedFields is provided\n if (selectedFields) {\n findQuery = findQuery.select(selectedFields);\n }\n\n const results = await findQuery.lean().exec();\n\n // Ensure id exists for each document\n return results.map((doc) => {\n if ((doc as any)._id && !(doc as any).id) {\n (doc as any).id = (doc as any)._id.toString();\n }\n return doc as AsDomainType<SchemaType>;\n });\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', ids);\n throw e;\n }\n }\n}\n"],"names":[],"mappings":";;AAsBa,IAAA,mBAAmB,GAAzB,qBAAA,GAAA,MAAM,mBAAmB,CAAA;AAShB,IAAA,SAAA,CAAA;AARJ,IAAA,OAAO,CAAgB;AAErB,IAAA,MAAM,CAAoB;AAEpC,IAAA,KAAK,CAAqC;AAE1C,IAAA,WAAA,CAEY,SAAgD,EAExD,EAAc,EAEd,MAAyB,EAEzB,OAAuB,EAAA;QANf,IAAS,CAAA,SAAA,GAAT,SAAS,CAAuC;;QASxD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAuC,CAAC;AAClF,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AACvB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,qBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;KACvE;AAED;;;AAGG;AACK,IAAA,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I,EAAE,CAAC,IAAI,EAAE,CAAC;;AAG9C,YAAA,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,KAAI;gBACvB,IAAK,GAAW,CAAC,GAAG,IAAI,CAAE,GAAW,CAAC,EAAE,EAAE;oBACrC,GAAW,CAAC,EAAE,GAAI,GAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;iBACjD;AACD,gBAAA,OAAO,GAA+B,CAAC;AAC3C,aAAC,CAAC,CAAC;SACN;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,6CAA6C,EAAE,GAAG,CAAC,CAAC;AACzE,YAAA,MAAM,CAAC,CAAC;SACX;KACJ;EACJ;AA9eY,mBAAmB,GAAA,qBAAA,GAAA,UAAA,CAAA;AAD/B,IAAA,UAAU,EAAE;IASJ,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;IAIX,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;IAEX,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;+CAHR,UAAU,EAAA,MAAA,EAAA,QAAA,EAAA,GAAA,OAIJ,aAAa,KAAA,WAAA,IAAb,aAAa,CAAA,KAAA,UAAA,GAAA,EAAA,GAAA,MAAA,CAAA,CAAA;AAflB,CAAA,EAAA,mBAAmB,CA8e/B"}
|
|
1
|
+
{"version":3,"file":"BaseMongoRepository.js","sources":["../../../src/store/repositories/BaseMongoRepository.ts"],"sourcesContent":["/* eslint-disable import/no-unresolved */\n/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable no-param-reassign */\n/* eslint-disable no-underscore-dangle */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable class-methods-use-this */\nimport { isObject } from 'lodash-es';\nimport { CdmLogger } from '@cdm-logger/core';\nimport { Connection, FilterQuery, Model, PipelineStage, Types, UpdateQuery } from 'mongoose';\nimport { injectable, unmanaged } from 'inversify';\nimport {\n GetAllArgs,\n ISort,\n IBaseMongoRepository,\n IMongoOptions,\n PAGINATION_OPTIONS,\n AsDomainType,\n CreateType,\n UpdateType,\n} from 'common/server';\n\n@injectable()\nexport class BaseMongoRepository<SchemaType> implements IBaseMongoRepository<SchemaType> {\n private options: IMongoOptions;\n\n protected logger: CdmLogger.ILogger;\n\n model: Model<SchemaType & { id: string }>;\n\n constructor(\n @unmanaged()\n private modelFunc: (db: Connection) => Model<SchemaType>,\n\n db: Connection,\n @unmanaged()\n logger: CdmLogger.ILogger,\n @unmanaged()\n options?: IMongoOptions,\n ) {\n // Safe model registration to prevent \"Cannot overwrite model once compiled\" errors\n this.model = this.safeModelRegistration(db) as Model<SchemaType & { id: string }>;\n this.options = options;\n this.logger = logger.child({ className: BaseMongoRepository.name });\n }\n\n /**\n * Safely registers or retrieves a Mongoose model to prevent overwrite errors\n * This is crucial for development environments where multiple containers might try to register the same model\n */\n private safeModelRegistration(db: Connection): Model<SchemaType> {\n try {\n return this.modelFunc(db);\n } catch (error) {\n // If the error is about overwriting a model, try to get the existing model\n if (error instanceof Error && error.message.includes('Cannot overwrite')) {\n // Extract model name from the error message or try to infer it\n const modelNameMatch = error.message.match(/Cannot overwrite `(\\w+)` model/);\n if (modelNameMatch) {\n const modelName = modelNameMatch[1];\n try {\n return db.model(modelName);\n } catch (getError) {\n // If we can't get the existing model, re-throw the original error\n throw error;\n }\n }\n }\n // For any other error, re-throw it\n throw error;\n }\n }\n\n /**\n * Transforms a document to the domain model format\n */\n protected transformDocument(doc: any): AsDomainType<SchemaType> | null {\n if (!doc) return null;\n\n // If it's already a plain object (not a Mongoose document)\n if (!doc.toObject) {\n // Ensure id exists if _id is present\n if (doc._id && !doc.id) {\n doc.id = typeof doc._id === 'object' && doc._id.toString ? doc._id.toString() : doc._id;\n }\n return doc as unknown as AsDomainType<SchemaType>;\n }\n\n // For Mongoose documents, use the built-in toObject transformation\n return doc.toObject() as AsDomainType<SchemaType>;\n }\n\n /**\n * Ensures the id field is present in a lean document\n * This is a fallback for when .lean({ virtuals: true }) doesn't include the id virtual\n */\n protected ensureIdField<T extends Record<string, any>>(doc: T): T & { id: string } {\n if (!doc) return doc as T & { id: string };\n if (!doc.id && doc._id) {\n (doc as any).id = typeof doc._id === 'object' && doc._id.toString ? doc._id.toString() : doc._id;\n }\n return doc as T & { id: string };\n }\n\n /**\n * Ensures id field is present in an array of lean documents\n */\n protected ensureIdFields<T extends Record<string, any>>(docs: T[]): (T & { id: string })[] {\n if (!docs || !Array.isArray(docs)) return [];\n return docs.map((doc) => this.ensureIdField(doc));\n }\n\n /**\n * Transforms an array of documents\n */\n protected transformDocuments(docs: SchemaType[]): AsDomainType<SchemaType>[] {\n if (!docs || !Array.isArray(docs)) return [];\n return docs.map((doc) => this.transformDocument(doc)).filter(Boolean) as AsDomainType<SchemaType>[];\n }\n\n /**\n * Maps API criteria with 'id' to MongoDB criteria with '_id'\n */\n private mapConditions(conditions?: FilterQuery<SchemaType>): FilterQuery<SchemaType> {\n if (!conditions) return {};\n\n const { id, ...remaining } = conditions as any;\n\n if (!id) return remaining as FilterQuery<SchemaType>;\n\n // Handle custom _id that might not be an ObjectId\n let _id;\n if (Types.ObjectId.isValid(id)) {\n _id = new Types.ObjectId(id);\n } else {\n _id = id; // Use the id as-is if it's not a valid ObjectId\n }\n\n return {\n _id,\n ...remaining,\n } as FilterQuery<SchemaType>;\n }\n\n /**\n * Computes sort object from GetAllArgs sort parameter\n * Handles both string-based and object-based sort specifications\n */\n protected computeSort(sort: ISort | string | ISort[]): Record<string, 1 | -1> {\n // Default sort by createdAt descending if available, otherwise empty sort\n if (!sort) {\n return { createdAt: -1 };\n }\n\n // Handle object-based sort { key: 'fieldName', value: 'asc'|'desc' }\n if (isObject(sort) && 'key' in sort) {\n return {\n [sort.key]: sort.value?.toLowerCase() === 'asc' ? 1 : -1,\n };\n }\n\n // Handle string-based sort 'fieldName:asc' or 'fieldName:desc'\n if (typeof sort === 'string') {\n const [field, direction] = sort.split(':');\n if (field) {\n return {\n [field]: direction?.toLowerCase() === 'asc' ? 1 : -1,\n };\n }\n }\n\n // Handle array of sort specifications\n if (Array.isArray(sort)) {\n return sort.reduce((acc, sortItem) => {\n if (isObject(sortItem) && sortItem.key) {\n acc[sortItem.key] = sortItem.value?.toLowerCase() === 'asc' ? 1 : -1;\n }\n return acc;\n }, {});\n }\n\n // Fallback to default sort\n return { createdAt: -1 };\n }\n\n /**\n * Prepares an aggregation pipeline with standard stages\n * @param options Query options including filtering, sorting, pagination\n * @param customPipeline Optional custom pipeline stages to include\n * @returns Complete MongoDB aggregation pipeline\n */\n protected preparePipeline(options: GetAllArgs<SchemaType>, customPipeline: PipelineStage[] = []): PipelineStage[] {\n const { criteria, sort, limit, skip } = options;\n const pipeline: PipelineStage[] = [];\n\n // Match stage (filtering)\n if (criteria) {\n pipeline.push({\n $match: this.mapConditions(criteria),\n });\n }\n\n // Add custom pipeline stages\n if (customPipeline.length > 0) {\n pipeline.push(...customPipeline);\n }\n\n // Sort stage\n const sortBy = this.computeSort(sort);\n if (Object.keys(sortBy).length > 0) {\n pipeline.push({ $sort: sortBy });\n }\n\n // Pagination stages\n if (skip !== undefined) {\n pipeline.push({ $skip: skip || PAGINATION_OPTIONS.skip });\n }\n\n if (limit !== undefined) {\n pipeline.push({ $limit: limit || PAGINATION_OPTIONS.limit });\n }\n\n return pipeline;\n }\n\n /**\n * Execute an aggregation pipeline and transform the results\n */\n protected async aggregate(pipeline: PipelineStage[]): Promise<AsDomainType<SchemaType>[]> {\n try {\n const results = await this.model.aggregate(pipeline).exec();\n return this.transformDocuments(results);\n } catch (e) {\n this.logger.error(e, 'Error executing aggregation pipeline: %j', pipeline);\n throw e;\n }\n }\n\n public async count(conditions?: FilterQuery<SchemaType>): Promise<number> {\n return this.model.count(this.mapConditions(conditions)).exec();\n }\n\n public async get(\n conditions?: FilterQuery<SchemaType>,\n selectedFields?: string,\n ): Promise<AsDomainType<SchemaType> | null> {\n try {\n const response = await this.model\n .findOne(this.mapConditions(conditions), selectedFields)\n .lean({ virtuals: true })\n .exec();\n\n if (!response) return null;\n\n // Ensure id field is present (fallback for schemas without virtuals)\n return this.ensureIdField(response) as AsDomainType<SchemaType>;\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', conditions);\n throw e;\n }\n }\n\n public async find(\n conditions: Partial<FilterQuery<SchemaType>>,\n selectedFields?: string,\n ): Promise<AsDomainType<SchemaType> | null> {\n try {\n const response = await this.model.findOne(conditions, selectedFields).lean({ virtuals: true }).exec();\n\n if (!response) return null;\n\n // Ensure id field is present (fallback for schemas without virtuals)\n return this.ensureIdField(response) as AsDomainType<SchemaType>;\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', conditions);\n throw e;\n }\n }\n\n public async getAll(options: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]> {\n try {\n const { criteria, selectedFields, sort, limit, skip } = options;\n const mappedCriteria = this.mapConditions(criteria);\n const sortBy = this.computeSort(sort);\n\n const response = await this.model\n .find(mappedCriteria, selectedFields)\n .sort(sortBy as any)\n .limit(limit || PAGINATION_OPTIONS.limit)\n .skip(skip || PAGINATION_OPTIONS.skip)\n .lean({ virtuals: true })\n .exec();\n\n // Ensure id field is present for all documents (fallback for schemas without virtuals)\n return this.ensureIdFields(response) as AsDomainType<SchemaType>[];\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', options);\n throw e;\n }\n }\n\n /**\n * Get all documents using aggregation pipeline\n */\n public async getAllWithPipeline(\n options: GetAllArgs<SchemaType>,\n customPipeline: PipelineStage[] = [],\n ): Promise<AsDomainType<SchemaType>[]> {\n try {\n const pipeline = this.preparePipeline(options, customPipeline);\n return this.aggregate(pipeline);\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with pipeline [%j]', customPipeline);\n throw e;\n }\n }\n\n public async getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n }> {\n const data = await this.getAll(options);\n const totalCount = await this.count(options.criteria);\n return { totalCount, data };\n }\n\n /**\n * Get all documents with count using aggregation pipeline\n */\n public async getAllWithCountAndPipeline(\n options: GetAllArgs<SchemaType>,\n customPipeline: PipelineStage[] = [],\n ): Promise<{\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n }> {\n // Clone options to avoid modifying the original\n const countOptions = { ...options };\n\n // Remove pagination for count\n delete countOptions.limit;\n delete countOptions.skip;\n\n // Prepare count pipeline (without pagination)\n const countPipeline = this.preparePipeline(countOptions, customPipeline);\n countPipeline.push({ $count: 'total' });\n\n // Execute both queries in parallel\n const [data, countResult] = await Promise.all([\n this.getAllWithPipeline(options, customPipeline),\n this.model.aggregate(countPipeline).exec(),\n ]);\n\n const totalCount = countResult?.[0]?.total || 0;\n return { data, totalCount };\n }\n\n public async create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>> {\n try {\n // Handle custom _id if provided in the data\n const createData = { ...data } as any;\n\n // If id is provided but _id is not, map id to _id\n if (createData.id && !createData._id) {\n createData._id = Types.ObjectId.isValid(createData.id)\n ? new Types.ObjectId(createData.id)\n : createData.id;\n delete createData.id; // Remove id to avoid conflicts\n }\n\n const response = await this.model.create(createData);\n return this.transformDocument(response);\n } catch (e) {\n this.logger.error(e, 'Unable to create Model with data [%j]', data);\n throw e;\n }\n }\n\n public async bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]> {\n try {\n const response = await this.model.insertMany(data, {\n lean: true,\n ordered: true,\n });\n\n // Ensure id exists for each document\n return response.map((doc: any) => {\n if (doc._id && !doc.id) {\n doc.id = doc._id.toString();\n }\n return doc as AsDomainType<SchemaType>;\n });\n } catch (e) {\n this.logger.error(e, 'Unable to bulk create due to error [%s]', e.message);\n throw e;\n }\n }\n\n public async upsert<T = UpdateType<SchemaType>>(\n conditions: FilterQuery<SchemaType>,\n update: T,\n options: Record<string, unknown> = {},\n ): Promise<AsDomainType<SchemaType>> {\n return this.update(conditions, update, {\n upsert: true,\n ...options,\n });\n }\n\n public async update<T = UpdateType<SchemaType>>(\n criteria: FilterQuery<SchemaType>,\n update: T | UpdateQuery<SchemaType>,\n options: Record<string, unknown> = {},\n ): Promise<AsDomainType<SchemaType>> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n const mergedOptions = {\n new: true,\n useFindAndModify: false,\n ...options,\n };\n\n const { id } = criteria as any;\n let response;\n\n if (id) {\n response = await this.model.findByIdAndUpdate(id, update as any, mergedOptions).exec();\n } else {\n response = await this.model.findOneAndUpdate(mappedCriteria, update as any, mergedOptions).exec();\n }\n\n return this.transformDocument(response);\n } catch (e) {\n this.logger.error(e, 'Unable to Update with criteria [%j] and data [%j]', criteria, update);\n throw e;\n }\n }\n\n public async bulkUpdate<T = UpdateType<SchemaType>>(\n criteria: FilterQuery<SchemaType>,\n update: T | UpdateQuery<SchemaType>,\n options: Record<string, unknown> = {},\n ): Promise<AsDomainType<SchemaType>[]> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n await this.model.updateMany(mappedCriteria, update as any, options);\n\n // Fetch the updated documents\n const response = await this.model.find(mappedCriteria).lean({ virtuals: true }).exec();\n\n // Ensure id field is present for all documents (fallback for schemas without virtuals)\n return this.ensureIdFields(response) as AsDomainType<SchemaType>[];\n } catch (e) {\n this.logger.error(e, 'Unable to Bulk Update with criteria [%j] and data [%j]', criteria, update);\n throw e;\n }\n }\n\n public async delete(criteria: FilterQuery<SchemaType>): Promise<boolean> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n let deleted;\n\n if (criteria?.id) {\n deleted = await this.model.findByIdAndDelete(criteria.id);\n } else {\n deleted = await this.model.findOneAndDelete(mappedCriteria);\n }\n\n return !!deleted;\n } catch (e) {\n this.logger.error(e, 'Unable to delete the model with criteria [%j]', criteria);\n throw e;\n }\n }\n\n public async bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number> {\n try {\n const mappedCriteria = this.mapConditions(criteria);\n const deleted = await this.model.deleteMany(mappedCriteria);\n return deleted?.deletedCount || 0;\n } catch (e) {\n this.logger.error(e, 'Unable to delete the model with criteria [%j]', criteria);\n throw e;\n }\n }\n\n public async bulkGet(ids: string[], selectedFields?: string): Promise<AsDomainType<SchemaType>[]> {\n try {\n // Create a query that handles both ObjectId and string IDs\n const query: any = { _id: { $in: [] } };\n\n // Process each ID\n ids?.forEach((id) => {\n if (Types.ObjectId.isValid(id)) {\n query._id.$in.push(new Types.ObjectId(id));\n } else {\n query._id.$in.push(id); // Add as string\n }\n });\n\n let findQuery = this.model.find(query);\n\n // apply select if selectedFields is provided\n if (selectedFields) {\n findQuery = findQuery.select(selectedFields);\n }\n\n const results = await findQuery.lean({ virtuals: true }).exec();\n\n // Ensure id field is present for all documents (fallback for schemas without virtuals)\n return this.ensureIdFields(results) as AsDomainType<SchemaType>[];\n } catch (e) {\n this.logger.error(e, 'Unable to retrieve Model with criteria [%j]', ids);\n throw e;\n }\n }\n}\n"],"names":[],"mappings":";;AAsBa,IAAA,mBAAmB,GAAzB,qBAAA,GAAA,MAAM,mBAAmB,CAAA;AAShB,IAAA,SAAA,CAAA;AARJ,IAAA,OAAO,CAAgB;AAErB,IAAA,MAAM,CAAoB;AAEpC,IAAA,KAAK,CAAqC;AAE1C,IAAA,WAAA,CAEY,SAAgD,EAExD,EAAc,EAEd,MAAyB,EAEzB,OAAuB,EAAA;QANf,IAAS,CAAA,SAAA,GAAT,SAAS,CAAuC;;QASxD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,EAAE,CAAuC,CAAC;AAClF,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AACvB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,qBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;KACvE;AAED;;;AAGG;AACK,IAAA,qBAAqB,CAAC,EAAc,EAAA;AACxC,QAAA,IAAI;AACA,YAAA,OAAO,IAA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,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;aAChD;AAED,YAAA,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;;AAGhE,YAAA,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAA+B,CAAC;SACrE;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,6CAA6C,EAAE,GAAG,CAAC,CAAC;AACzE,YAAA,MAAM,CAAC,CAAC;SACX;KACJ;EACJ;AA9eY,mBAAmB,GAAA,qBAAA,GAAA,UAAA,CAAA;AAD/B,IAAA,UAAU,EAAE;IASJ,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;IAIX,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;IAEX,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;+CAHR,UAAU,EAAA,MAAA,EAAA,QAAA,EAAA,GAAA,OAIJ,aAAa,KAAA,WAAA,IAAb,aAAa,CAAA,KAAA,UAAA,GAAA,EAAA,GAAA,MAAA,CAAA,CAAA;AAflB,CAAA,EAAA,mBAAmB,CA8e/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/store-mongo",
|
|
3
|
-
"version": "8.2.4-alpha.
|
|
3
|
+
"version": "8.2.4-alpha.14",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
"watch": "npm run build:lib:watch"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@common-stack/core": "8.2.4-alpha.
|
|
27
|
+
"@common-stack/core": "8.2.4-alpha.14",
|
|
28
|
+
"mongoose-lean-virtuals": "^0.9.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"common": "8.2.4-alpha.
|
|
31
|
+
"common": "8.2.4-alpha.14",
|
|
31
32
|
"moleculer": "^0.14.33",
|
|
32
33
|
"mongoose": "^6.12.8"
|
|
33
34
|
},
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
]
|
|
56
57
|
}
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "e64a1941279f5618c2bb75aac1e4a74c9561c804",
|
|
59
60
|
"typescript": {
|
|
60
61
|
"definition": "lib/index.d.ts"
|
|
61
62
|
}
|