@common-stack/store-mongo 7.0.4-alpha.6 → 7.1.1-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.d.ts +14 -0
- package/lib/containers/container.js +17 -0
- package/lib/containers/container.js.map +1 -0
- package/lib/containers/index.d.ts +1 -0
- package/lib/dataloaders/bulk-dataloader-v2.d.ts +7 -0
- package/lib/dataloaders/bulk-dataloader-v2.js +34 -0
- package/lib/dataloaders/bulk-dataloader-v2.js.map +1 -0
- package/lib/dataloaders/bulk-dataloader.js.map +1 -1
- package/lib/dataloaders/bulk-dataloader.test.d.ts +1 -0
- package/lib/dataloaders/index.d.ts +1 -0
- package/lib/graphql/schema/base-services.graphql +238 -0
- package/lib/helpers/mongoose-connection.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/interfaces/base-repository.d.ts +1 -5
- package/lib/interfaces/base-service.d.ts +1 -1
- package/lib/interfaces/getAllArgs.d.ts +133 -0
- package/lib/interfaces/getAllArgs.js +39 -0
- package/lib/interfaces/getAllArgs.js.map +1 -0
- package/lib/interfaces/index.d.ts +1 -1
- package/lib/mixins/BaseServiceMixin.d.ts +45 -0
- package/lib/mixins/BaseServiceMixin.js +199 -0
- package/lib/mixins/BaseServiceMixin.js.map +1 -0
- package/lib/mixins/base-service-mixin.js.map +1 -1
- package/lib/mixins/index.d.ts +1 -0
- package/lib/module.d.ts +2 -0
- package/lib/module.js +4 -0
- package/lib/module.js.map +1 -0
- package/lib/services/BaseProxyService.d.ts +28 -0
- package/lib/services/BaseProxyService.js +52 -0
- package/lib/services/BaseProxyService.js.map +1 -0
- package/lib/services/BaseService.d.ts +23 -0
- package/lib/services/BaseService.js +65 -0
- package/lib/services/BaseService.js.map +1 -0
- package/lib/services/BaseService.test.d.ts +1 -0
- package/lib/services/base-proxy-service.js.map +1 -1
- package/lib/services/base-service.js.map +1 -1
- package/lib/services/index.d.ts +2 -0
- package/lib/store/models/common-options-v2.d.ts +16 -0
- package/lib/store/models/common-options-v2.js +40 -0
- package/lib/store/models/common-options-v2.js.map +1 -0
- package/lib/store/models/common-options.js.map +1 -1
- package/lib/store/models/index.d.ts +1 -0
- package/lib/store/repositories/BaseMongoRepository.d.ts +65 -0
- package/lib/store/repositories/BaseMongoRepository.js +389 -0
- package/lib/store/repositories/BaseMongoRepository.js.map +1 -0
- package/lib/store/repositories/BaseMongoRepository.test.d.ts +1 -0
- package/lib/store/repositories/CustomIdRepository.test.d.ts +1 -0
- package/lib/store/repositories/base-repository.js +1 -1
- package/lib/store/repositories/base-repository.js.map +1 -1
- package/lib/store/repositories/index.d.ts +1 -0
- package/lib/templates/constants/SERVER_TYPES.ts.template +5 -0
- package/lib/templates/repositories/DatabaseMigration.ts.template +13 -0
- package/lib/templates/repositories/IBaseMongoRepository.ts.template +284 -0
- package/lib/templates/repositories/IBaseService.ts.template +231 -0
- package/lib/templates/repositories/IBaseServiceMixin.ts.template +461 -0
- package/lib/templates/repositories/IDataloader.ts.template +211 -0
- package/lib/templates/repositories/dbCommonTypes.ts.template +139 -0
- package/lib/templates/repositories/mongoCommonTypes.ts.template +21 -0
- package/package.json +21 -4
- package/lib/interfaces/base-repository.js +0 -5
- package/lib/interfaces/base-repository.js.map +0 -1
- package/lib/interfaces/get-all-args.d.ts +0 -9
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { interfaces } from 'inversify';
|
|
2
|
+
/**
|
|
3
|
+
* Local services and exposed microservices to serve remote connections.
|
|
4
|
+
* Operates within in the Gateway.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export declare const localContainerModule: (settings: any) => interfaces.ContainerModule;
|
|
8
|
+
/**
|
|
9
|
+
* Operates external to the Gateway. Usually a broker listen to calls and invoke this service
|
|
10
|
+
* local to the micro container.
|
|
11
|
+
*
|
|
12
|
+
* @param settings Settings
|
|
13
|
+
*/
|
|
14
|
+
export declare const externalContainerModule: (settings: any) => interfaces.ContainerModule;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {ContainerModule}from'inversify';import {SERVER_TYPES}from'common/server';import {BaseMongoRepository}from'../store/repositories/BaseMongoRepository.js';import'../store/repositories/base-repository.js';/**
|
|
2
|
+
* Local services and exposed microservices to serve remote connections.
|
|
3
|
+
* Operates within in the Gateway.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
const localContainerModule = () => new ContainerModule((bind) => {
|
|
7
|
+
bind(SERVER_TYPES.BaseMongoRepository).to(BaseMongoRepository).inSingletonScope().whenTargetIsDefault();
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Operates external to the Gateway. Usually a broker listen to calls and invoke this service
|
|
11
|
+
* local to the micro container.
|
|
12
|
+
*
|
|
13
|
+
* @param settings Settings
|
|
14
|
+
*/
|
|
15
|
+
const externalContainerModule = () => new ContainerModule((bind) => {
|
|
16
|
+
bind(SERVER_TYPES.BaseMongoRepository).to(BaseMongoRepository).inSingletonScope().whenTargetIsDefault();
|
|
17
|
+
});export{externalContainerModule,localContainerModule};//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +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":"iNAIA;;;;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './container';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import DataLoader from 'dataloader';
|
|
2
|
+
import { IBaseService, IDataLoader, AsDomainType } from 'common/server';
|
|
3
|
+
export declare class BulkDataLoader2<SchemaType> extends DataLoader<string, AsDomainType<SchemaType> | null> implements IDataLoader<SchemaType> {
|
|
4
|
+
private readonly service;
|
|
5
|
+
constructor(service: IBaseService<SchemaType>);
|
|
6
|
+
withOptions: DataLoader<DataLoaderOptions<SchemaType>, AsDomainType<SchemaType>[], DataLoaderOptions<SchemaType>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {__decorate,__param,__metadata}from'tslib';import DataLoader from'dataloader';import {injectable,unmanaged}from'inversify';import {IBaseService}from'common/server';var _a;
|
|
2
|
+
let BulkDataLoader2 = class BulkDataLoader2 extends DataLoader {
|
|
3
|
+
service;
|
|
4
|
+
constructor(service) {
|
|
5
|
+
super(async (ids) => {
|
|
6
|
+
const data = await this.service.getByIds(ids);
|
|
7
|
+
return ids.map((id) => data.find((record) => record.id === id) || null);
|
|
8
|
+
});
|
|
9
|
+
this.service = service;
|
|
10
|
+
}
|
|
11
|
+
withOptions = new DataLoader(async (options) => {
|
|
12
|
+
const [{ searchKey, comparator, ...rest }] = options;
|
|
13
|
+
const ids = options.map((option) => option.id);
|
|
14
|
+
// Create a properly typed criteria object with explicit type assertion
|
|
15
|
+
const criteria = {
|
|
16
|
+
...(rest.criteria || {}),
|
|
17
|
+
[searchKey]: { $in: ids },
|
|
18
|
+
};
|
|
19
|
+
const results = await this.service.getAll({
|
|
20
|
+
...rest,
|
|
21
|
+
criteria,
|
|
22
|
+
});
|
|
23
|
+
return options.map((option) => results.filter((item) => {
|
|
24
|
+
if (typeof comparator === 'function')
|
|
25
|
+
return comparator(option, item);
|
|
26
|
+
return item[searchKey]?.toString() === option.id.toString();
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
BulkDataLoader2 = __decorate([
|
|
31
|
+
injectable(),
|
|
32
|
+
__param(0, unmanaged()),
|
|
33
|
+
__metadata("design:paramtypes", [typeof (_a = typeof IBaseService !== "undefined" && IBaseService) === "function" ? _a : Object])
|
|
34
|
+
], BulkDataLoader2);export{BulkDataLoader2};//# sourceMappingURL=bulk-dataloader-v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-dataloader-v2.js","sources":["../../src/dataloaders/bulk-dataloader-v2.ts"],"sourcesContent":["import DataLoader from 'dataloader';\nimport { injectable, unmanaged } from 'inversify';\nimport { FilterQuery } from 'mongoose';\nimport { IBaseService, IDataLoader, AsDomainType } from 'common/server';\n\n@injectable()\nexport class BulkDataLoader2<SchemaType>\n extends DataLoader<string, AsDomainType<SchemaType> | null>\n implements IDataLoader<SchemaType>\n{\n constructor(@unmanaged() private readonly service: IBaseService<SchemaType>) {\n super(async (ids: string[]) => {\n const data = await this.service.getByIds(ids);\n return ids.map((id) => data.find((record) => record.id === id) || null);\n });\n }\n\n withOptions = new DataLoader<DataLoaderOptions<SchemaType>, AsDomainType<SchemaType>[]>(async (options) => {\n const [{ searchKey, comparator, ...rest }] = options;\n const ids = options.map((option) => option.id);\n\n // Create a properly typed criteria object with explicit type assertion\n const criteria = {\n ...(rest.criteria || {}),\n [searchKey as string]: { $in: ids },\n } as FilterQuery<SchemaType>;\n\n const results = await this.service.getAll({\n ...rest,\n criteria,\n });\n\n return options.map((option) =>\n results.filter((item) => {\n if (typeof comparator === 'function') return comparator(option, item);\n return item[searchKey as keyof AsDomainType<SchemaType>]?.toString() === option.id.toString();\n }),\n );\n });\n}\n"],"names":[],"mappings":";AAMO,IAAM,eAAe,GAArB,MAAM,eACT,SAAQ,UAAmD,CAAA;AAGjB,IAAA,OAAA,CAAA;AAA1C,IAAA,WAAA,CAA0C,OAAiC,EAAA;AACvE,QAAA,KAAK,CAAC,OAAO,GAAa,KAAI;YAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC;AAC5E,SAAC,CAAC,CAAC;QAJmC,IAAO,CAAA,OAAA,GAAP,OAAO,CAA0B;KAK1E;IAED,WAAW,GAAG,IAAI,UAAU,CAA4D,OAAO,OAAO,KAAI;AACtG,QAAA,MAAM,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC;AACrD,QAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;;AAG/C,QAAA,MAAM,QAAQ,GAAG;AACb,YAAA,IAAI,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;AACxB,YAAA,CAAC,SAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;SACX,CAAC;QAE7B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;AACtC,YAAA,GAAG,IAAI;YACP,QAAQ;AACX,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,KAAI;YACpB,IAAI,OAAO,UAAU,KAAK,UAAU;AAAE,gBAAA,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACtE,YAAA,OAAO,IAAI,CAAC,SAA2C,CAAC,EAAE,QAAQ,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;SACjG,CAAC,CACL,CAAC;AACN,KAAC,CAAC,CAAC;EACN;AAjCY,eAAe,GAAA,UAAA,CAAA;AAD3B,IAAA,UAAU,EAAE;IAKI,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;AAA2B,IAAA,UAAA,CAAA,mBAAA,EAAA,CAAA,QAAA,EAAA,GAAA,OAAA,YAAY,oBAAZ,YAAY,CAAA,KAAA,UAAA,GAAA,EAAA,GAAA,MAAA,CAAA,CAAA;AAJtD,CAAA,EAAA,eAAe,CAiC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulk-dataloader.js","sources":["../../src/dataloaders/bulk-dataloader.ts"],"sourcesContent":[null],"names":[],"mappings":"kIAKO,IAAM,cAAc,GAApB,MAAM,cAAyC,SAAQ,UAA4B,CAAA;AAC5C,IAAA,OAAA,CAAA;AAA1C,IAAA,WAAA,CAA0C,OAAwB,EAAA;AAC9D,QAAA,KAAK,CAAC,OAAO,GAAa,KAAI;YAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC;AAC5E,SAAC,CAAC,CAAC;QAJmC,IAAO,CAAA,OAAA,GAAP,OAAO,CAAiB;KAKjE;IAED,WAAW,GAAG,IAAI,UAAU,CAA4B,OAAO,OAAO,KAAI;AACtE,QAAA,MAAM,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC;AACrD,QAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;AACtC,YAAA,GAAG,IAAI;AACP,YAAA,QAAQ,EAAE;gBACN,GAAG,IAAI,CAAC,QAAQ;AAChB,gBAAA,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAC5B,aAAA;AACJ,SAAA,CAAC,CAAC;AACH,QAAA,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,KAAI;YACpB,IAAI,OAAO,UAAU,KAAK,UAAU;AAAE,gBAAA,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACtE,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;SAC9D,CAAC,CACL,CAAC;AACN,KAAC,CAAC,CAAC;EACN;AAzBY,cAAc,GAAA,UAAA,CAAA;AAD1B,IAAA,UAAU,EAAE;IAEI,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;;AADf,CAAA,EAAA,cAAc,CAyB1B"}
|
|
1
|
+
{"version":3,"file":"bulk-dataloader.js","sources":["../../src/dataloaders/bulk-dataloader.ts"],"sourcesContent":["import DataLoader from 'dataloader';\nimport { injectable, unmanaged } from 'inversify';\nimport { DataLoaderOptions, IBaseService, IDataLoader } from '../interfaces';\n\n@injectable()\nexport class BulkDataLoader<T extends { id: string }> extends DataLoader<string, T | null> implements IDataLoader<T> {\n constructor(@unmanaged() private readonly service: IBaseService<T>) {\n super(async (ids: string[]) => {\n const data = await this.service.getByIds(ids);\n return ids.map((id) => data.find((record) => record.id === id) || null);\n });\n }\n\n withOptions = new DataLoader<DataLoaderOptions<T>, T[]>(async (options) => {\n const [{ searchKey, comparator, ...rest }] = options;\n const ids = options.map((option) => option.id);\n const results = await this.service.getAll({\n ...rest,\n criteria: {\n ...rest.criteria,\n [searchKey]: { $in: ids },\n },\n });\n return options.map((option) =>\n results.filter((item) => {\n if (typeof comparator === 'function') return comparator(option, item);\n return item[searchKey].toString() === option.id.toString();\n }),\n );\n });\n}\n"],"names":[],"mappings":"kIAKO,IAAM,cAAc,GAApB,MAAM,cAAyC,SAAQ,UAA4B,CAAA;AAC5C,IAAA,OAAA,CAAA;AAA1C,IAAA,WAAA,CAA0C,OAAwB,EAAA;AAC9D,QAAA,KAAK,CAAC,OAAO,GAAa,KAAI;YAC1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC;AAC5E,SAAC,CAAC,CAAC;QAJmC,IAAO,CAAA,OAAA,GAAP,OAAO,CAAiB;KAKjE;IAED,WAAW,GAAG,IAAI,UAAU,CAA4B,OAAO,OAAO,KAAI;AACtE,QAAA,MAAM,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC;AACrD,QAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;AACtC,YAAA,GAAG,IAAI;AACP,YAAA,QAAQ,EAAE;gBACN,GAAG,IAAI,CAAC,QAAQ;AAChB,gBAAA,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAC5B,aAAA;AACJ,SAAA,CAAC,CAAC;AACH,QAAA,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,KAAI;YACpB,IAAI,OAAO,UAAU,KAAK,UAAU;AAAE,gBAAA,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACtE,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;SAC9D,CAAC,CACL,CAAC;AACN,KAAC,CAAC,CAAC;EACN;AAzBY,cAAc,GAAA,UAAA,CAAA;AAD1B,IAAA,UAAU,EAAE;IAEI,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;;AADf,CAAA,EAAA,cAAc,CAyB1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -1,15 +1,253 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Standard service commands that represent the core CRUD operations available in the BaseServiceMixin.
|
|
3
|
+
These commands are used as action names in Moleculer services and for event emission.
|
|
4
|
+
They provide a consistent API across all services for common data operations.
|
|
5
|
+
"""
|
|
1
6
|
enum BaseServiceCommands {
|
|
7
|
+
"""
|
|
8
|
+
Count documents matching criteria
|
|
9
|
+
|
|
10
|
+
This command counts entities matching the provided filter criteria.
|
|
11
|
+
It maps to the IBaseService.count method and handles parameter validation.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
```
|
|
15
|
+
// Count active users
|
|
16
|
+
const count = await broker.call('users.count', {
|
|
17
|
+
criteria: { active: true }
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
"""
|
|
2
21
|
count
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
Get a single document by ID or criteria
|
|
25
|
+
|
|
26
|
+
This command retrieves a single entity by its unique identifier.
|
|
27
|
+
It maps to the IBaseService.get method and handles parameter validation.
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
```
|
|
31
|
+
// Get user by ID
|
|
32
|
+
const user = await broker.call('users.get', { id: '123' });
|
|
33
|
+
|
|
34
|
+
// Get user by email
|
|
35
|
+
const user = await broker.call('users.get', {
|
|
36
|
+
criteria: { email: 'user@example.com' }
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
"""
|
|
3
40
|
get
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
Get documents with pagination
|
|
44
|
+
|
|
45
|
+
This command retrieves multiple entities with filtering, sorting, and pagination.
|
|
46
|
+
It maps to the IBaseService.getAll method and handles parameter validation.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
```
|
|
50
|
+
// Get active users sorted by creation date
|
|
51
|
+
const users = await broker.call('users.getAll', {
|
|
52
|
+
criteria: { active: true },
|
|
53
|
+
sort: { createdAt: -1 },
|
|
54
|
+
skip: 0,
|
|
55
|
+
limit: 10
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
"""
|
|
4
59
|
getAll
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
Get a single document by name field
|
|
63
|
+
|
|
64
|
+
This command retrieves a single entity by its name field.
|
|
65
|
+
It maps to the IBaseService.getByName method and handles parameter validation.
|
|
66
|
+
Commonly used for entities that have a unique name identifier.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
```
|
|
70
|
+
// Get product by name
|
|
71
|
+
const product = await broker.call('products.getByName', {
|
|
72
|
+
name: 'Premium Subscription'
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
"""
|
|
5
76
|
getByName
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
Get multiple documents by their IDs
|
|
80
|
+
|
|
81
|
+
This command retrieves multiple entities by their unique identifiers.
|
|
82
|
+
It maps to the IBaseService.getByIds method and handles parameter validation.
|
|
83
|
+
Useful for retrieving a specific set of entities in a single operation.
|
|
84
|
+
|
|
85
|
+
Example:
|
|
86
|
+
```
|
|
87
|
+
// Get multiple users by their IDs
|
|
88
|
+
const users = await broker.call('users.getByIds', {
|
|
89
|
+
ids: ['user1', 'user2', 'user3']
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
"""
|
|
6
93
|
getByIds
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
Create a single document
|
|
97
|
+
|
|
98
|
+
This command creates a single entity.
|
|
99
|
+
It maps to the IBaseService.create method and handles parameter validation.
|
|
100
|
+
It also emits an event for the created entity if configured.
|
|
101
|
+
|
|
102
|
+
Example:
|
|
103
|
+
```
|
|
104
|
+
// Create a new user
|
|
105
|
+
const user = await broker.call('users.create', {
|
|
106
|
+
data: { name: 'John', email: 'john@example.com' }
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
"""
|
|
7
110
|
create
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
Create or update a document
|
|
114
|
+
|
|
115
|
+
This command creates a new entity or updates an existing one if an ID is provided.
|
|
116
|
+
It maps to the IBaseService.insert method and handles parameter validation.
|
|
117
|
+
It also emits an event for the created or updated entity if configured.
|
|
118
|
+
|
|
119
|
+
Example:
|
|
120
|
+
```
|
|
121
|
+
// Create a new product
|
|
122
|
+
const newProduct = await broker.call('products.insert', {
|
|
123
|
+
data: { name: 'New Product', price: 99.99 }
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Update an existing product
|
|
127
|
+
const updatedProduct = await broker.call('products.insert', {
|
|
128
|
+
data: { id: 'product123', name: 'Updated Product', price: 129.99 }
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
"""
|
|
8
132
|
insert
|
|
133
|
+
|
|
134
|
+
"""
|
|
135
|
+
Create multiple documents
|
|
136
|
+
|
|
137
|
+
This command creates multiple entities in a single operation.
|
|
138
|
+
It maps to the IBaseService.bulkCreate method and handles parameter validation.
|
|
139
|
+
It also emits events for the created entities if configured.
|
|
140
|
+
|
|
141
|
+
Example:
|
|
142
|
+
```
|
|
143
|
+
// Create multiple users
|
|
144
|
+
const users = await broker.call('users.bulkCreate', {
|
|
145
|
+
data: [
|
|
146
|
+
{ name: 'John', email: 'john@example.com' },
|
|
147
|
+
{ name: 'Jane', email: 'jane@example.com' }
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
"""
|
|
9
152
|
bulkCreate
|
|
153
|
+
|
|
154
|
+
"""
|
|
155
|
+
Update a document by ID
|
|
156
|
+
|
|
157
|
+
This command updates an existing entity by its unique identifier.
|
|
158
|
+
It maps to the IBaseService.update method and handles parameter validation.
|
|
159
|
+
It also emits an event for the updated entity if configured.
|
|
160
|
+
|
|
161
|
+
Example:
|
|
162
|
+
```
|
|
163
|
+
// Update a user's role
|
|
164
|
+
const updatedUser = await broker.call('users.update', {
|
|
165
|
+
id: 'user123',
|
|
166
|
+
data: { role: 'admin', active: true }
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Replace a user document entirely
|
|
170
|
+
const replacedUser = await broker.call('users.update', {
|
|
171
|
+
id: 'user123',
|
|
172
|
+
data: { name: 'New Name', email: 'new@example.com', role: 'user' },
|
|
173
|
+
overwrite: true
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
"""
|
|
10
177
|
update
|
|
178
|
+
|
|
179
|
+
"""
|
|
180
|
+
Delete a document by ID
|
|
181
|
+
|
|
182
|
+
This command deletes a single entity by its unique identifier.
|
|
183
|
+
It maps to the IBaseService.delete method and handles parameter validation.
|
|
184
|
+
It also emits an event for the deleted entity if configured.
|
|
185
|
+
|
|
186
|
+
Example:
|
|
187
|
+
```
|
|
188
|
+
// Delete a user
|
|
189
|
+
const success = await broker.call('users.delete', { id: '123' });
|
|
190
|
+
```
|
|
191
|
+
"""
|
|
11
192
|
delete
|
|
193
|
+
|
|
194
|
+
"""
|
|
195
|
+
Delete multiple documents by IDs
|
|
196
|
+
|
|
197
|
+
This command deletes multiple entities by their unique identifiers.
|
|
198
|
+
It maps to the IBaseService.bulkDelete method and handles parameter validation.
|
|
199
|
+
It also emits events for the deleted entities if configured.
|
|
200
|
+
|
|
201
|
+
Example:
|
|
202
|
+
```
|
|
203
|
+
// Delete multiple users
|
|
204
|
+
const deletedCount = await broker.call('users.BulkDelete', {
|
|
205
|
+
ids: ['user1', 'user2', 'user3']
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
"""
|
|
209
|
+
BulkDelete
|
|
210
|
+
|
|
211
|
+
"""
|
|
212
|
+
Delete multiple documents matching criteria
|
|
213
|
+
|
|
214
|
+
This command deletes multiple entities matching the provided filter criteria.
|
|
215
|
+
It maps to the IBaseService.delete method and handles parameter validation.
|
|
216
|
+
It also emits an event with the deletion criteria if configured.
|
|
217
|
+
|
|
218
|
+
Example:
|
|
219
|
+
```
|
|
220
|
+
// Delete all inactive users
|
|
221
|
+
const deletedCount = await broker.call('users.deleteMany', {
|
|
222
|
+
criteria: { active: false }
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Delete users with a specific role
|
|
226
|
+
const deletedCount = await broker.call('users.deleteMany', {
|
|
227
|
+
criteria: { role: 'guest' }
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
"""
|
|
12
231
|
deleteMany
|
|
232
|
+
|
|
233
|
+
"""
|
|
234
|
+
Get documents with pagination and total count
|
|
235
|
+
|
|
236
|
+
This command retrieves multiple entities with filtering, sorting, pagination,
|
|
237
|
+
and includes the total count of matching documents (useful for UI pagination).
|
|
238
|
+
It maps to the IBaseService.getAllWithCount method and handles parameter validation.
|
|
239
|
+
|
|
240
|
+
Example:
|
|
241
|
+
```
|
|
242
|
+
// Get paginated users with total count for UI pagination
|
|
243
|
+
const { data, totalCount } = await broker.call('users.getAllWithCount', {
|
|
244
|
+
criteria: { role: 'user' },
|
|
245
|
+
skip: 20,
|
|
246
|
+
limit: 10,
|
|
247
|
+
sort: { createdAt: -1 }
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
"""
|
|
13
251
|
getAllWithCount
|
|
14
252
|
}
|
|
15
253
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoose-connection.js","sources":["../../src/helpers/mongoose-connection.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"mongoose-connection.js","sources":["../../src/helpers/mongoose-connection.ts"],"sourcesContent":["import * as mongoose from 'mongoose';\n\nconst generateMongo: (monoUrl) => mongoose.Connection = (mongoUrl) => {\n // creates default connection\n mongoose\n .connect(mongoUrl, {})\n .then(() => {\n console.info('mogoose connect - success');\n // console.info(`uri - ${uri}`);\n // console.info(`connectionOptions - ${connectionOptions}`);\n })\n .catch((err: mongoose.Error) => {\n console.error('mogoose connect - error - ', err);\n // throw err;\n process.kill(process.pid);\n });\n // to access default connection\n const mongooseConnection: mongoose.Connection = mongoose.connection;\n\n return mongooseConnection;\n};\n\nexport { generateMongo };\n"],"names":[],"mappings":"kCAEA,MAAM,aAAa,GAAqC,CAAC,QAAQ,KAAI;;IAEjE,QAAQ;AACH,SAAA,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,IAAI,CAAC,MAAK;AACP,QAAA,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;;;AAG9C,KAAC,CAAC;AACD,SAAA,KAAK,CAAC,CAAC,GAAmB,KAAI;AAC3B,QAAA,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;;AAEjD,QAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9B,KAAC,CAAC,CAAC;;AAEP,IAAA,MAAM,kBAAkB,GAAwB,QAAQ,CAAC,UAAU,CAAC;AAEpE,IAAA,OAAO,kBAAkB,CAAC;AAC9B"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.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,9 +1,5 @@
|
|
|
1
1
|
import { Document, FilterQuery, Model, UpdateQuery } from 'mongoose';
|
|
2
|
-
import { GetAllArgs } from './
|
|
3
|
-
export declare enum PAGINATION_OPTIONS {
|
|
4
|
-
limit = 10,
|
|
5
|
-
skip = 0
|
|
6
|
-
}
|
|
2
|
+
import { GetAllArgs } from './getAllArgs';
|
|
7
3
|
export interface IBaseRepository<T, D = Document<T>> {
|
|
8
4
|
model: Model<D>;
|
|
9
5
|
count(conditions?: FilterQuery<D>): Promise<number>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FilterQuery, Document } from 'mongoose';
|
|
2
|
-
import { GetAllArgs } from './
|
|
2
|
+
import { GetAllArgs } from './getAllArgs';
|
|
3
3
|
export interface IBaseService<T, C = Omit<T, 'id'>, U = C> {
|
|
4
4
|
count(conditions?: FilterQuery<Document<T>>): Promise<number>;
|
|
5
5
|
get(id: string): Promise<T>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-all-args.ts
|
|
3
|
+
* @description Defines common types and interfaces used across the data access layer for MongoDB operations.
|
|
4
|
+
* This file contains essential type definitions that standardize how data is queried, transformed, and returned.
|
|
5
|
+
*
|
|
6
|
+
* Key components include:
|
|
7
|
+
* - GetAllArgs: Interface for pagination, sorting, and filtering when retrieving collections of documents
|
|
8
|
+
* - AsDomainType: Type transformer that converts MongoDB schema types (with _id) to domain types (with id)
|
|
9
|
+
* - GetAllWithCountResult: Type for paginated results that include both data and total count
|
|
10
|
+
* - CreateType/UpdateType: Utility types that define the shape of data for create and update operations
|
|
11
|
+
* - PAGINATION_OPTIONS: Default pagination settings used throughout the application
|
|
12
|
+
*
|
|
13
|
+
* Usage examples:
|
|
14
|
+
* 1. Retrieving paginated data:
|
|
15
|
+
* const result = await repository.getAllWithCount({ limit: 10, skip: 0, sort: { createdAt: -1 } });
|
|
16
|
+
*
|
|
17
|
+
* 2. Converting MongoDB documents to domain objects:
|
|
18
|
+
* const domainUser: AsDomainType<UserSchema> = { ...userDoc, id: userDoc._id.toString() };
|
|
19
|
+
*
|
|
20
|
+
* 3. Creating new documents with proper typing:
|
|
21
|
+
* const newUser: CreateType<UserSchema> = { name: 'John', email: 'john@example.com' };
|
|
22
|
+
*
|
|
23
|
+
* These types ensure consistency across repositories and services, providing type safety and
|
|
24
|
+
* clear contracts for data manipulation throughout the application. They form the foundation
|
|
25
|
+
* of the data access pattern used across the entire system.
|
|
26
|
+
*
|
|
27
|
+
* @see IBaseRepository2 - Uses these types for repository operations
|
|
28
|
+
* @see IBaseService2 - Implements service methods using these types
|
|
29
|
+
* @see IDataLoader2 - Utilizes these types for efficient data loading
|
|
30
|
+
*/
|
|
31
|
+
import type { FilterQuery } from 'mongoose';
|
|
32
|
+
import type { ISort } from 'common';
|
|
33
|
+
/**
|
|
34
|
+
* Interface for the arguments used in the getAll method
|
|
35
|
+
*
|
|
36
|
+
* @property criteria - MongoDB filter query to narrow down results
|
|
37
|
+
* @property sort - Sorting configuration with field names and directions (1 for ascending, -1 for descending)
|
|
38
|
+
* @property skip - Number of documents to skip (for pagination)
|
|
39
|
+
* @property limit - Maximum number of documents to return (for pagination)
|
|
40
|
+
* @property selectedFields - String of space-separated field names to include in the results
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Get active users, sorted by creation date, second page with 10 items per page
|
|
44
|
+
* const options: GetAllArgs<UserSchema> = {
|
|
45
|
+
* criteria: { active: true },
|
|
46
|
+
* sort: { createdAt: -1 },
|
|
47
|
+
* skip: 10,
|
|
48
|
+
* limit: 10,
|
|
49
|
+
* selectedFields: 'name email createdAt'
|
|
50
|
+
* };
|
|
51
|
+
*/
|
|
52
|
+
export interface GetAllArgs<T> {
|
|
53
|
+
criteria?: FilterQuery<T>;
|
|
54
|
+
sort?: ISort;
|
|
55
|
+
skip?: number;
|
|
56
|
+
limit?: number;
|
|
57
|
+
selectedFields?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Type that converts a schema type with _id to a domain type with id
|
|
61
|
+
* This transformation is essential for presenting MongoDB documents as domain objects
|
|
62
|
+
* throughout the application, hiding the database-specific _id field.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // MongoDB document
|
|
66
|
+
* const userDoc = { _id: '123', name: 'John', email: 'john@example.com' };
|
|
67
|
+
*
|
|
68
|
+
* // Transformed domain object
|
|
69
|
+
* const user: AsDomainType<UserSchema> = { id: '123', name: 'John', email: 'john@example.com' };
|
|
70
|
+
*/
|
|
71
|
+
export type AsDomainType<SchemaType> = Omit<SchemaType, '_id'> & {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Type for the result of getAllWithCount
|
|
76
|
+
* Provides both the paginated data and the total count of matching documents
|
|
77
|
+
* This is used for implementing pagination UI components that need to know
|
|
78
|
+
* the total number of pages or items.
|
|
79
|
+
*
|
|
80
|
+
* @property data - Array of domain objects matching the query criteria
|
|
81
|
+
* @property totalCount - Total number of documents that match the criteria (without pagination)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const result: GetAllWithCountResult<UserSchema> = {
|
|
85
|
+
* data: [{ id: '1', name: 'John' }, { id: '2', name: 'Jane' }],
|
|
86
|
+
* totalCount: 50
|
|
87
|
+
* };
|
|
88
|
+
*/
|
|
89
|
+
export type GetAllWithCountResult<SchemaType> = {
|
|
90
|
+
data: AsDomainType<SchemaType>[];
|
|
91
|
+
totalCount: number;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Default pagination settings used throughout the application
|
|
95
|
+
* These values are used when no explicit pagination parameters are provided
|
|
96
|
+
*/
|
|
97
|
+
export declare enum PAGINATION_OPTIONS {
|
|
98
|
+
limit = 10,
|
|
99
|
+
skip = 0
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Type for create operations - omits _id, id, and auto-generated fields
|
|
103
|
+
* This ensures that clients cannot specify fields that should be generated by the database
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* // Valid create operation data
|
|
107
|
+
* const newUser: CreateType<UserSchema> = {
|
|
108
|
+
* name: 'John Doe',
|
|
109
|
+
* email: 'john@example.com',
|
|
110
|
+
* role: 'user'
|
|
111
|
+
* };
|
|
112
|
+
*
|
|
113
|
+
* // The following fields will be generated automatically and should not be included:
|
|
114
|
+
* // - _id (MongoDB document ID)
|
|
115
|
+
* // - id (Domain object ID)
|
|
116
|
+
* // - createdAt (Creation timestamp)
|
|
117
|
+
* // - updatedAt (Last update timestamp)
|
|
118
|
+
*/
|
|
119
|
+
export type CreateType<SchemaType> = Omit<Partial<SchemaType>, '_id' | 'id' | 'createdAt' | 'updatedAt'>;
|
|
120
|
+
/**
|
|
121
|
+
* Type for update operations - partial of the schema without _id
|
|
122
|
+
* This allows for partial updates where only changed fields are specified
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* // Update a user's email and role
|
|
126
|
+
* const updateData: UpdateType<UserSchema> = {
|
|
127
|
+
* email: 'new.email@example.com',
|
|
128
|
+
* role: 'admin'
|
|
129
|
+
* };
|
|
130
|
+
*
|
|
131
|
+
* // Fields not specified will remain unchanged
|
|
132
|
+
*/
|
|
133
|
+
export type UpdateType<SchemaType> = Partial<Omit<SchemaType, '_id'>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file get-all-args.ts
|
|
3
|
+
* @description Defines common types and interfaces used across the data access layer for MongoDB operations.
|
|
4
|
+
* This file contains essential type definitions that standardize how data is queried, transformed, and returned.
|
|
5
|
+
*
|
|
6
|
+
* Key components include:
|
|
7
|
+
* - GetAllArgs: Interface for pagination, sorting, and filtering when retrieving collections of documents
|
|
8
|
+
* - AsDomainType: Type transformer that converts MongoDB schema types (with _id) to domain types (with id)
|
|
9
|
+
* - GetAllWithCountResult: Type for paginated results that include both data and total count
|
|
10
|
+
* - CreateType/UpdateType: Utility types that define the shape of data for create and update operations
|
|
11
|
+
* - PAGINATION_OPTIONS: Default pagination settings used throughout the application
|
|
12
|
+
*
|
|
13
|
+
* Usage examples:
|
|
14
|
+
* 1. Retrieving paginated data:
|
|
15
|
+
* const result = await repository.getAllWithCount({ limit: 10, skip: 0, sort: { createdAt: -1 } });
|
|
16
|
+
*
|
|
17
|
+
* 2. Converting MongoDB documents to domain objects:
|
|
18
|
+
* const domainUser: AsDomainType<UserSchema> = { ...userDoc, id: userDoc._id.toString() };
|
|
19
|
+
*
|
|
20
|
+
* 3. Creating new documents with proper typing:
|
|
21
|
+
* const newUser: CreateType<UserSchema> = { name: 'John', email: 'john@example.com' };
|
|
22
|
+
*
|
|
23
|
+
* These types ensure consistency across repositories and services, providing type safety and
|
|
24
|
+
* clear contracts for data manipulation throughout the application. They form the foundation
|
|
25
|
+
* of the data access pattern used across the entire system.
|
|
26
|
+
*
|
|
27
|
+
* @see IBaseRepository2 - Uses these types for repository operations
|
|
28
|
+
* @see IBaseService2 - Implements service methods using these types
|
|
29
|
+
* @see IDataLoader2 - Utilizes these types for efficient data loading
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Default pagination settings used throughout the application
|
|
33
|
+
* These values are used when no explicit pagination parameters are provided
|
|
34
|
+
*/
|
|
35
|
+
var PAGINATION_OPTIONS;
|
|
36
|
+
(function (PAGINATION_OPTIONS) {
|
|
37
|
+
PAGINATION_OPTIONS[PAGINATION_OPTIONS["limit"] = 10] = "limit";
|
|
38
|
+
PAGINATION_OPTIONS[PAGINATION_OPTIONS["skip"] = 0] = "skip";
|
|
39
|
+
})(PAGINATION_OPTIONS || (PAGINATION_OPTIONS = {}));export{PAGINATION_OPTIONS};//# sourceMappingURL=getAllArgs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllArgs.js","sources":["../../src/interfaces/getAllArgs.ts"],"sourcesContent":["/**\n * @file get-all-args.ts\n * @description Defines common types and interfaces used across the data access layer for MongoDB operations.\n * This file contains essential type definitions that standardize how data is queried, transformed, and returned.\n *\n * Key components include:\n * - GetAllArgs: Interface for pagination, sorting, and filtering when retrieving collections of documents\n * - AsDomainType: Type transformer that converts MongoDB schema types (with _id) to domain types (with id)\n * - GetAllWithCountResult: Type for paginated results that include both data and total count\n * - CreateType/UpdateType: Utility types that define the shape of data for create and update operations\n * - PAGINATION_OPTIONS: Default pagination settings used throughout the application\n *\n * Usage examples:\n * 1. Retrieving paginated data:\n * const result = await repository.getAllWithCount({ limit: 10, skip: 0, sort: { createdAt: -1 } });\n *\n * 2. Converting MongoDB documents to domain objects:\n * const domainUser: AsDomainType<UserSchema> = { ...userDoc, id: userDoc._id.toString() };\n *\n * 3. Creating new documents with proper typing:\n * const newUser: CreateType<UserSchema> = { name: 'John', email: 'john@example.com' };\n *\n * These types ensure consistency across repositories and services, providing type safety and\n * clear contracts for data manipulation throughout the application. They form the foundation\n * of the data access pattern used across the entire system.\n *\n * @see IBaseRepository2 - Uses these types for repository operations\n * @see IBaseService2 - Implements service methods using these types\n * @see IDataLoader2 - Utilizes these types for efficient data loading\n */\n\nimport type { FilterQuery } from 'mongoose';\nimport type { ISort } from 'common';\n\n/**\n * Interface for the arguments used in the getAll method\n *\n * @property criteria - MongoDB filter query to narrow down results\n * @property sort - Sorting configuration with field names and directions (1 for ascending, -1 for descending)\n * @property skip - Number of documents to skip (for pagination)\n * @property limit - Maximum number of documents to return (for pagination)\n * @property selectedFields - String of space-separated field names to include in the results\n *\n * @example\n * // Get active users, sorted by creation date, second page with 10 items per page\n * const options: GetAllArgs<UserSchema> = {\n * criteria: { active: true },\n * sort: { createdAt: -1 },\n * skip: 10,\n * limit: 10,\n * selectedFields: 'name email createdAt'\n * };\n */\nexport interface GetAllArgs<T> {\n criteria?: FilterQuery<T>;\n sort?: ISort;\n skip?: number;\n limit?: number;\n selectedFields?: string;\n}\n\n/**\n * Type that converts a schema type with _id to a domain type with id\n * This transformation is essential for presenting MongoDB documents as domain objects\n * throughout the application, hiding the database-specific _id field.\n *\n * @example\n * // MongoDB document\n * const userDoc = { _id: '123', name: 'John', email: 'john@example.com' };\n *\n * // Transformed domain object\n * const user: AsDomainType<UserSchema> = { id: '123', name: 'John', email: 'john@example.com' };\n */\nexport type AsDomainType<SchemaType> = Omit<SchemaType, '_id'> & { id: string };\n\n/**\n * Type for the result of getAllWithCount\n * Provides both the paginated data and the total count of matching documents\n * This is used for implementing pagination UI components that need to know\n * the total number of pages or items.\n *\n * @property data - Array of domain objects matching the query criteria\n * @property totalCount - Total number of documents that match the criteria (without pagination)\n *\n * @example\n * const result: GetAllWithCountResult<UserSchema> = {\n * data: [{ id: '1', name: 'John' }, { id: '2', name: 'Jane' }],\n * totalCount: 50\n * };\n */\nexport type GetAllWithCountResult<SchemaType> = {\n data: AsDomainType<SchemaType>[];\n totalCount: number;\n};\n\n/**\n * Default pagination settings used throughout the application\n * These values are used when no explicit pagination parameters are provided\n */\nexport enum PAGINATION_OPTIONS {\n limit = 10,\n skip = 0,\n}\n\n/**\n * Type for create operations - omits _id, id, and auto-generated fields\n * This ensures that clients cannot specify fields that should be generated by the database\n *\n * @example\n * // Valid create operation data\n * const newUser: CreateType<UserSchema> = {\n * name: 'John Doe',\n * email: 'john@example.com',\n * role: 'user'\n * };\n *\n * // The following fields will be generated automatically and should not be included:\n * // - _id (MongoDB document ID)\n * // - id (Domain object ID)\n * // - createdAt (Creation timestamp)\n * // - updatedAt (Last update timestamp)\n */\nexport type CreateType<SchemaType> = Omit<Partial<SchemaType>, '_id' | 'id' | 'createdAt' | 'updatedAt'>;\n\n/**\n * Type for update operations - partial of the schema without _id\n * This allows for partial updates where only changed fields are specified\n *\n * @example\n * // Update a user's email and role\n * const updateData: UpdateType<UserSchema> = {\n * email: 'new.email@example.com',\n * role: 'admin'\n * };\n *\n * // Fields not specified will remain unchanged\n */\nexport type UpdateType<SchemaType> = Partial<Omit<SchemaType, '_id'>>;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AAkEH;;;AAGG;IACS,mBAGX;AAHD,CAAA,UAAY,kBAAkB,EAAA;AAC1B,IAAA,kBAAA,CAAA,kBAAA,CAAA,OAAA,CAAA,GAAA,EAAA,CAAA,GAAA,OAAU,CAAA;AACV,IAAA,kBAAA,CAAA,kBAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ,CAAA;AACZ,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,GAG7B,EAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file BaseServiceMixin.ts
|
|
3
|
+
* @description Provides a mixin function that adds standardized service methods to Moleculer service schemas.
|
|
4
|
+
* This mixin implements the IBaseService interface and connects it to Moleculer's service framework,
|
|
5
|
+
* creating action handlers for all standard service operations.
|
|
6
|
+
*
|
|
7
|
+
* The mixin pattern allows for composable service functionality, where multiple mixins can be combined
|
|
8
|
+
* to create feature-rich services without code duplication. This particular mixin handles the core CRUD
|
|
9
|
+
* operations and emits events when data changes.
|
|
10
|
+
*
|
|
11
|
+
* Key features:
|
|
12
|
+
* - Automatic action creation for all IBaseService methods
|
|
13
|
+
* - Event emission for data changes (create, update, delete)
|
|
14
|
+
* - Parameter validation for all actions
|
|
15
|
+
* - Consistent error handling
|
|
16
|
+
* - Type safety through generics
|
|
17
|
+
*
|
|
18
|
+
* @see IBaseService - The interface this mixin implements
|
|
19
|
+
* @see IBaseMongoRepository - The repository interface used for data access
|
|
20
|
+
*/
|
|
21
|
+
import { ServiceBroker, ServiceSchema } from 'moleculer';
|
|
22
|
+
import { IBaseService, BaseServiceCommands } from 'common';
|
|
23
|
+
/**
|
|
24
|
+
* Creates a mixin that implements the IBaseService interface as Moleculer actions
|
|
25
|
+
*
|
|
26
|
+
* @param service - Implementation of IBaseService that will handle the actual business logic
|
|
27
|
+
* @param broker - Moleculer service broker for event emission
|
|
28
|
+
* @param name - Service name used for event naming
|
|
29
|
+
* @param events - List of operations that should emit events
|
|
30
|
+
* @returns A partial ServiceSchema that can be merged with other service definitions
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Create a user service with the base service mixin
|
|
34
|
+
* const UserService: ServiceSchema = {
|
|
35
|
+
* name: "users",
|
|
36
|
+
* mixins: [
|
|
37
|
+
* BaseServiceMixin(userService, broker, "users")
|
|
38
|
+
* ],
|
|
39
|
+
* // Additional service-specific actions and methods
|
|
40
|
+
* actions: {
|
|
41
|
+
* changePassword: { ... }
|
|
42
|
+
* }
|
|
43
|
+
* };
|
|
44
|
+
*/
|
|
45
|
+
export declare const BaseServiceMixin: <T>(service: IBaseService<T>, broker?: ServiceBroker, name?: string, events?: BaseServiceCommands[]) => Partial<ServiceSchema>;
|