@common-stack/store-mongo 7.1.1-alpha.4 → 7.1.1-alpha.41

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.
Files changed (75) hide show
  1. package/lib/containers/container.d.ts +14 -0
  2. package/lib/containers/container.js +17 -0
  3. package/lib/containers/container.js.map +1 -0
  4. package/lib/containers/index.d.ts +1 -0
  5. package/lib/dataloaders/bulk-dataloader-v2.d.ts +7 -0
  6. package/lib/dataloaders/bulk-dataloader-v2.js +34 -0
  7. package/lib/dataloaders/bulk-dataloader-v2.js.map +1 -0
  8. package/lib/dataloaders/bulk-dataloader.d.ts +6 -4
  9. package/lib/dataloaders/bulk-dataloader.js +5 -7
  10. package/lib/dataloaders/bulk-dataloader.js.map +1 -1
  11. package/lib/dataloaders/index.d.ts +1 -0
  12. package/lib/graphql/schema/base-services.graphql +237 -0
  13. package/lib/helpers/mongoose-connection.js.map +1 -1
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.js +1 -1
  16. package/lib/interfaces/base-repository.d.ts +15 -25
  17. package/lib/interfaces/base-service.d.ts +19 -18
  18. package/lib/interfaces/dataloaders.d.ts +10 -0
  19. package/lib/interfaces/getAllArgs.d.ts +133 -0
  20. package/lib/interfaces/getAllArgs.js +39 -0
  21. package/lib/interfaces/getAllArgs.js.map +1 -0
  22. package/lib/interfaces/index.d.ts +2 -2
  23. package/lib/mixins/BaseServiceMixin.d.ts +45 -0
  24. package/lib/mixins/BaseServiceMixin.js +208 -0
  25. package/lib/mixins/BaseServiceMixin.js.map +1 -0
  26. package/lib/mixins/base-service-mixin.d.ts +1 -1
  27. package/lib/mixins/base-service-mixin.js +2 -2
  28. package/lib/mixins/base-service-mixin.js.map +1 -1
  29. package/lib/mixins/index.d.ts +1 -0
  30. package/lib/module.d.ts +3 -0
  31. package/lib/module.js +4 -0
  32. package/lib/module.js.map +1 -0
  33. package/lib/services/BaseProxyService.d.ts +28 -0
  34. package/lib/services/BaseProxyService.js +52 -0
  35. package/lib/services/BaseProxyService.js.map +1 -0
  36. package/lib/services/BaseService.d.ts +23 -0
  37. package/lib/services/BaseService.js +65 -0
  38. package/lib/services/BaseService.js.map +1 -0
  39. package/lib/services/base-proxy-service.d.ts +17 -20
  40. package/lib/services/base-proxy-service.js +0 -3
  41. package/lib/services/base-proxy-service.js.map +1 -1
  42. package/lib/services/base-service.d.ts +18 -19
  43. package/lib/services/base-service.js +11 -13
  44. package/lib/services/base-service.js.map +1 -1
  45. package/lib/services/index.d.ts +2 -0
  46. package/lib/store/models/common-options-v2.d.ts +16 -0
  47. package/lib/store/models/common-options-v2.js +40 -0
  48. package/lib/store/models/common-options-v2.js.map +1 -0
  49. package/lib/store/models/common-options.d.ts +2 -3
  50. package/lib/store/models/common-options.js +3 -23
  51. package/lib/store/models/common-options.js.map +1 -1
  52. package/lib/store/models/index.d.ts +1 -0
  53. package/lib/store/repositories/BaseMongoRepository.d.ts +65 -0
  54. package/lib/store/repositories/BaseMongoRepository.js +395 -0
  55. package/lib/store/repositories/BaseMongoRepository.js.map +1 -0
  56. package/lib/store/repositories/base-repository.d.ts +22 -58
  57. package/lib/store/repositories/base-repository.js +135 -277
  58. package/lib/store/repositories/base-repository.js.map +1 -1
  59. package/lib/store/repositories/index.d.ts +1 -0
  60. package/lib/templates/constants/SERVER_TYPES.ts.template +7 -0
  61. package/lib/templates/repositories/DataLoader.ts.template +211 -0
  62. package/lib/templates/repositories/DatabaseMigration.ts.template +13 -0
  63. package/lib/templates/repositories/IBaseMongoRepository.ts.template +284 -0
  64. package/lib/templates/repositories/IBaseService.ts.template +231 -0
  65. package/lib/templates/repositories/IBaseServiceMixin.ts.template +473 -0
  66. package/lib/templates/repositories/dbCommonTypes.ts.template +139 -0
  67. package/lib/templates/repositories/mongoCommonTypes.ts.template +21 -0
  68. package/package.json +21 -5
  69. package/lib/interfaces/dataloader.d.ts +0 -17
  70. package/lib/interfaces/get-all-args.d.ts +0 -28
  71. package/lib/interfaces/get-all-args.js +0 -5
  72. package/lib/interfaces/get-all-args.js.map +0 -1
  73. /package/lib/services/{base-service.test.d.ts → BaseService.test.d.ts} +0 -0
  74. /package/lib/store/repositories/{base-repository.test.d.ts → BaseMongoRepository.test.d.ts} +0 -0
  75. /package/lib/store/repositories/{custom-id-repository.test.d.ts → CustomIdRepository.test.d.ts} +0 -0
@@ -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":["/* eslint-disable import/no-extraneous-dependencies */\nimport DataLoader from 'dataloader';\nimport { injectable, unmanaged } from 'inversify';\nimport { FilterQuery } from 'mongoose';\nimport { IBaseService, IDataLoader, AsDomainType, DataLoaderOptions } 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":";AAOO,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,7 +1,9 @@
1
1
  import DataLoader from 'dataloader';
2
- import { DataLoaderOptions, IBaseService, IDataLoader, AsDomainType } from '../interfaces';
3
- export declare class BulkDataLoader<SchemaType> extends DataLoader<string, AsDomainType<SchemaType> | null> implements IDataLoader<SchemaType> {
2
+ import { DataLoaderOptions, IBaseService, IDataLoader } from '../interfaces';
3
+ export declare class BulkDataLoader<T extends {
4
+ id: string;
5
+ }> extends DataLoader<string, T | null> implements IDataLoader<T> {
4
6
  private readonly service;
5
- constructor(service: IBaseService<SchemaType>);
6
- withOptions: DataLoader<DataLoaderOptions<SchemaType>, AsDomainType<SchemaType>[], DataLoaderOptions<SchemaType>>;
7
+ constructor(service: IBaseService<T>);
8
+ withOptions: DataLoader<DataLoaderOptions<T>, T[], DataLoaderOptions<T>>;
7
9
  }
@@ -10,19 +10,17 @@ import {__decorate,__param,__metadata}from'tslib';import DataLoader from'dataloa
10
10
  withOptions = new DataLoader(async (options) => {
11
11
  const [{ searchKey, comparator, ...rest }] = options;
12
12
  const ids = options.map((option) => option.id);
13
- // Create a properly typed criteria object with explicit type assertion
14
- const criteria = {
15
- ...(rest.criteria || {}),
16
- [searchKey]: { $in: ids },
17
- };
18
13
  const results = await this.service.getAll({
19
14
  ...rest,
20
- criteria,
15
+ criteria: {
16
+ ...rest.criteria,
17
+ [searchKey]: { $in: ids },
18
+ },
21
19
  });
22
20
  return options.map((option) => results.filter((item) => {
23
21
  if (typeof comparator === 'function')
24
22
  return comparator(option, item);
25
- return item[searchKey]?.toString() === option.id.toString();
23
+ return item[searchKey].toString() === option.id.toString();
26
24
  }));
27
25
  });
28
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bulk-dataloader.js","sources":["../../src/dataloaders/bulk-dataloader.ts"],"sourcesContent":[null],"names":[],"mappings":"kIAMO,IAAM,cAAc,GAApB,MAAM,cACT,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,cAAc,GAAA,UAAA,CAAA;AAD1B,IAAA,UAAU,EAAE;IAKI,OAAA,CAAA,CAAA,EAAA,SAAS,EAAE,CAAA;;AAJf,CAAA,EAAA,cAAc,CAiC1B"}
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"}
@@ -1 +1,2 @@
1
+ export * from './bulk-dataloader-v2';
1
2
  export * from './bulk-dataloader';
@@ -1,16 +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
+ """
12
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
+ """
13
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
+ """
14
251
  getAllWithCount
15
252
  }
16
253
 
@@ -1 +1 @@
1
- {"version":3,"file":"mongoose-connection.js","sources":["../../src/helpers/mongoose-connection.ts"],"sourcesContent":[null],"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"}
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
@@ -1,6 +1,6 @@
1
- export * from './interfaces';
2
1
  export * from './helpers';
3
2
  export * from './services';
4
3
  export * from './store';
5
4
  export * from './dataloaders';
6
5
  export * from './mixins';
6
+ export * from './interfaces';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export{PAGINATION_OPTIONS}from'./interfaces/get-all-args.js';export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields,commonModelSchemaOptions}from'./store/models/common-options.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.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{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,26 +1,16 @@
1
- import { FilterQuery, Model, PipelineStage, UpdateQuery } from 'mongoose';
2
- import { AsDomainType, CreateType, GetAllArgs, UpdateType } from './get-all-args';
3
- export interface IBaseRepository<SchemaType> {
4
- model: Model<SchemaType>;
5
- count(conditions?: FilterQuery<SchemaType>): Promise<number>;
6
- getAll(options: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]>;
7
- getAllWithPipeline(options: GetAllArgs<SchemaType>, customPipeline?: PipelineStage[]): Promise<AsDomainType<SchemaType>[]>;
8
- getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{
9
- data: AsDomainType<SchemaType>[];
10
- totalCount: number;
11
- }>;
12
- getAllWithCountAndPipeline(options: GetAllArgs<SchemaType>, customPipeline?: PipelineStage[]): Promise<{
13
- data: AsDomainType<SchemaType>[];
14
- totalCount: number;
15
- }>;
16
- get(conditions?: FilterQuery<SchemaType>, selectedFields?: string): Promise<AsDomainType<SchemaType> | null>;
17
- find(conditions: Partial<FilterQuery<SchemaType>>, selectedFields?: string): Promise<AsDomainType<SchemaType> | null>;
18
- create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>>;
19
- upsert<T = UpdateType<SchemaType>>(conditions: FilterQuery<SchemaType>, update: T, options?: Record<string, unknown>): Promise<AsDomainType<SchemaType>>;
20
- update<T = UpdateType<SchemaType>>(criteria: FilterQuery<SchemaType>, update: T | UpdateQuery<SchemaType>, options?: Record<string, unknown>): Promise<AsDomainType<SchemaType>>;
21
- bulkUpdate<T = UpdateType<SchemaType>>(criteria: FilterQuery<SchemaType>, update: T | UpdateQuery<SchemaType>, options?: Record<string, unknown>): Promise<AsDomainType<SchemaType>[]>;
22
- delete(criteria: FilterQuery<SchemaType>): Promise<boolean>;
23
- bulkGet(ids: string[], selectedFields?: string): Promise<AsDomainType<SchemaType>[]>;
24
- bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]>;
25
- bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number>;
1
+ import { Document, FilterQuery, Model, UpdateQuery } from 'mongoose';
2
+ import { GetAllArgs } from './getAllArgs';
3
+ export interface IBaseRepository<T, D = Document<T>> {
4
+ model: Model<D>;
5
+ count(conditions?: FilterQuery<D>): Promise<number>;
6
+ getAll(options: GetAllArgs<D>): Promise<T[]>;
7
+ get(conditions?: FilterQuery<D>, selectedFields?: string): Promise<T>;
8
+ create<I>(data: I): Promise<T>;
9
+ upsert<I>(conditions: FilterQuery<D>, update: I, options: any): Promise<T>;
10
+ update<I>(criteria: FilterQuery<D>, update: UpdateQuery<D>, options?: any): Promise<T>;
11
+ bulkUpdate<I>(criteria: FilterQuery<D>, update: UpdateQuery<D>, options?: any): Promise<T[]>;
12
+ delete(criteria: FilterQuery<D>): Promise<boolean>;
13
+ bulkGet(ids: string[], selectedFields?: string): Promise<T[]>;
14
+ bulkCreate<I>(data: I[]): Promise<T[]>;
15
+ bulkDelete(criteria: FilterQuery<D>): Promise<number>;
26
16
  }
@@ -1,21 +1,22 @@
1
- import { FilterQuery } from 'mongoose';
2
- import { GetAllArgs, AsDomainType, CreateType, UpdateType } from './get-all-args';
3
- export interface IBaseService<SchemaType> {
4
- getAllWithCount(options: GetAllArgs<SchemaType>): Promise<{
5
- data: AsDomainType<SchemaType>[];
1
+ import { FilterQuery, Document } from 'mongoose';
2
+ import { GetAllArgs } from './getAllArgs';
3
+ export interface IBaseService<T, C = Omit<T, 'id'>, U = C> {
4
+ count(conditions?: FilterQuery<Document<T>>): Promise<number>;
5
+ get(id: string): Promise<T>;
6
+ get(conditions?: string | FilterQuery<Document<T>>): Promise<T>;
7
+ getByName(name: string): Promise<T>;
8
+ getAll(options?: GetAllArgs<Document<T>>): Promise<T[]>;
9
+ getByIds(ids: string[]): Promise<T[]>;
10
+ create(data: C): Promise<T>;
11
+ insert(data: (C | U) & {
12
+ id?: string;
13
+ }, overwrite?: boolean): Promise<T>;
14
+ bulkCreate(data: C[]): Promise<T[]>;
15
+ update(id: string, data: U, overwrite?: boolean): Promise<T>;
16
+ delete(id: string): Promise<boolean>;
17
+ delete(conditions: string | FilterQuery<Document<T>>): Promise<boolean>;
18
+ getAllWithCount(options: GetAllArgs<Document<T>>): Promise<{
19
+ data: T[];
6
20
  totalCount: number;
7
21
  }>;
8
- count(conditions?: FilterQuery<SchemaType>): Promise<number>;
9
- get(conditions: string | FilterQuery<SchemaType>): Promise<AsDomainType<SchemaType> | null>;
10
- getByName(name: string): Promise<AsDomainType<SchemaType> | null>;
11
- getAll(options: GetAllArgs<SchemaType>): Promise<AsDomainType<SchemaType>[]>;
12
- getByIds(ids: string[]): Promise<AsDomainType<SchemaType>[]>;
13
- create<T = CreateType<SchemaType>>(data: T): Promise<AsDomainType<SchemaType>>;
14
- bulkCreate<T = CreateType<SchemaType>>(data: T[]): Promise<AsDomainType<SchemaType>[]>;
15
- update<T = UpdateType<SchemaType>>(id: string, data: T, overwrite?: boolean): Promise<AsDomainType<SchemaType>>;
16
- insert<T = CreateType<SchemaType>>(data: T & {
17
- id?: string;
18
- }, overwrite?: boolean): Promise<AsDomainType<SchemaType>>;
19
- delete(id: string | FilterQuery<SchemaType>): Promise<boolean>;
20
- bulkDelete(criteria: FilterQuery<SchemaType>): Promise<number>;
21
22
  }
@@ -0,0 +1,10 @@
1
+ import DataLoader from 'dataloader';
2
+ import { IBaseService } from './base-service';
3
+ export type DataLoaderOptions<T> = Parameters<IBaseService<T>['getAll']>[0] & {
4
+ id: string;
5
+ searchKey: keyof T;
6
+ comparator?: (source: Omit<DataLoaderOptions<T>, 'comparator'>, target: T) => boolean;
7
+ };
8
+ export type IDataLoader<T> = DataLoader<string, T> & {
9
+ withOptions: DataLoader<DataLoaderOptions<T>, T[]>;
10
+ };