@tsed/agenda 7.0.0-beta.3 → 7.0.0-beta.6

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 (44) hide show
  1. package/.mocharc.js +2 -2
  2. package/.nycrc +1 -1
  3. package/lib/cjs/AgendaModule.js +11 -11
  4. package/lib/cjs/AgendaModule.js.map +1 -1
  5. package/lib/cjs/constants/{index.js → constants.js} +1 -1
  6. package/lib/cjs/constants/constants.js.map +1 -0
  7. package/lib/cjs/decorators/agenda.js +1 -1
  8. package/lib/cjs/decorators/agenda.js.map +1 -1
  9. package/lib/cjs/index.js +11 -5
  10. package/lib/cjs/index.js.map +1 -1
  11. package/lib/cjs/interfaces/interfaces.js +3 -0
  12. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  13. package/lib/cjs/package.json +3 -0
  14. package/lib/esm/AgendaModule.js +3 -3
  15. package/lib/esm/AgendaModule.js.map +1 -1
  16. package/lib/esm/constants/{index.js → constants.js} +1 -1
  17. package/lib/esm/constants/constants.js.map +1 -0
  18. package/lib/esm/decorators/agenda.js +1 -1
  19. package/lib/esm/decorators/agenda.js.map +1 -1
  20. package/lib/esm/decorators/every.js +1 -1
  21. package/lib/esm/index.js +11 -5
  22. package/lib/esm/index.js.map +1 -1
  23. package/lib/esm/interfaces/interfaces.js +2 -0
  24. package/lib/esm/interfaces/interfaces.js.map +1 -0
  25. package/lib/esm/package.json +3 -0
  26. package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
  27. package/lib/types/index.d.ts +8 -15
  28. package/lib/types/interfaces/interfaces.d.ts +13 -0
  29. package/package.json +9 -7
  30. package/readme.md +9 -12
  31. package/src/AgendaModule.ts +2 -2
  32. package/src/constants/{index.ts → constants.ts} +0 -0
  33. package/src/decorators/agenda.ts +1 -1
  34. package/src/index.ts +8 -16
  35. package/src/interfaces/interfaces.ts +14 -0
  36. package/tsconfig.compile.esm.json +1 -12
  37. package/lib/cjs/constants/index.js.map +0 -1
  38. package/lib/cjs/decorators/index.js +0 -7
  39. package/lib/cjs/decorators/index.js.map +0 -1
  40. package/lib/esm/constants/index.js.map +0 -1
  41. package/lib/esm/decorators/index.js +0 -4
  42. package/lib/esm/decorators/index.js.map +0 -1
  43. package/lib/types/decorators/index.d.ts +0 -3
  44. package/src/decorators/index.ts +0 -3
package/.mocharc.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- ...require('@tsed/mocha-config')(),
2
+ ...require("@tsed/mocha-config")(),
3
3
  spec: ["{src,test}/**/*.spec.ts"],
4
- exclude: [],
4
+ exclude: []
5
5
  };
package/.nycrc CHANGED
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "check-coverage": true,
23
23
  "statements": 100,
24
- "branches": 90.63,
24
+ "branches": 90.62,
25
25
  "functions": 100,
26
26
  "lines": 100
27
27
  }
@@ -4,7 +4,7 @@ exports.AgendaModule = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@tsed/common");
6
6
  const di_1 = require("@tsed/di");
7
- const index_1 = require("./constants/index");
7
+ const constants_1 = require("./constants/constants");
8
8
  const AgendaFactory_1 = require("./services/AgendaFactory");
9
9
  let AgendaModule = class AgendaModule {
10
10
  async $afterListen() {
@@ -28,7 +28,7 @@ let AgendaModule = class AgendaModule {
28
28
  }
29
29
  }
30
30
  getProviders() {
31
- return Array.from(this.injector.getProviders(index_1.PROVIDER_TYPE_AGENDA));
31
+ return this.injector.getProviders(constants_1.PROVIDER_TYPE_AGENDA);
32
32
  }
33
33
  addAgendaDefinitionsForProvider(provider) {
34
34
  const store = provider.store.get("agenda");
@@ -59,23 +59,23 @@ let AgendaModule = class AgendaModule {
59
59
  return namespace ? `${namespace}.${name}` : name;
60
60
  }
61
61
  };
62
- (0, tslib_1.__decorate)([
62
+ tslib_1.__decorate([
63
63
  (0, di_1.Inject)(),
64
- (0, tslib_1.__metadata)("design:type", common_1.Logger)
64
+ tslib_1.__metadata("design:type", common_1.Logger)
65
65
  ], AgendaModule.prototype, "logger", void 0);
66
- (0, tslib_1.__decorate)([
66
+ tslib_1.__decorate([
67
67
  (0, di_1.Inject)(),
68
- (0, tslib_1.__metadata)("design:type", di_1.InjectorService)
68
+ tslib_1.__metadata("design:type", di_1.InjectorService)
69
69
  ], AgendaModule.prototype, "injector", void 0);
70
- (0, tslib_1.__decorate)([
70
+ tslib_1.__decorate([
71
71
  (0, di_1.Inject)(),
72
- (0, tslib_1.__metadata)("design:type", AgendaFactory_1.AgendaService)
72
+ tslib_1.__metadata("design:type", AgendaFactory_1.AgendaService)
73
73
  ], AgendaModule.prototype, "agenda", void 0);
74
- (0, tslib_1.__decorate)([
74
+ tslib_1.__decorate([
75
75
  (0, di_1.Constant)("agenda.enabled", false),
76
- (0, tslib_1.__metadata)("design:type", Boolean)
76
+ tslib_1.__metadata("design:type", Boolean)
77
77
  ], AgendaModule.prototype, "loadAgenda", void 0);
78
- AgendaModule = (0, tslib_1.__decorate)([
78
+ AgendaModule = tslib_1.__decorate([
79
79
  (0, di_1.Module)()
80
80
  ], AgendaModule);
81
81
  exports.AgendaModule = AgendaModule;
@@ -1 +1 @@
1
- {"version":3,"file":"AgendaModule.js","sourceRoot":"","sources":["../../src/AgendaModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA4D;AAC5D,iCAA6E;AAE7E,6CAAuD;AAEvD,4DAAuD;AAGvD,IAAa,YAAY,GAAzB,MAAa,YAAY;IAavB,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEhF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YAC9C,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YA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AE,KAAK,CAAC;;gDACN;AAXjB,YAAY;IADxB,IAAA,WAAM,GAAE;GACI,YAAY,CA8ExB;AA9EY,oCAAY","sourcesContent":["import {AfterListen, Logger, OnDestroy} from \"@tsed/common\";\nimport {Constant, Inject, InjectorService, Module, Provider} from \"@tsed/di\";\nimport {Processor} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"./constants/index\";\nimport {AgendaStore} from \"./interfaces/AgendaStore\";\nimport {AgendaService} from \"./services/AgendaFactory\";\n\n@Module()\nexport class AgendaModule implements OnDestroy, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected agenda: AgendaService;\n\n @Constant(\"agenda.enabled\", false)\n private loadAgenda: boolean;\n\n async $afterListen(): Promise<any> {\n if (this.loadAgenda) {\n const providers = this.getProviders();\n providers.forEach((provider) => this.addAgendaDefinitionsForProvider(provider));\n\n this.logger.info(\"Agenda add definitions...\");\n await this.agenda.start();\n\n this.logger.info(\"Agenda add scheduled jobs...\");\n providers.forEach((provider) => this.scheduleJobsForProvider(provider));\n } else {\n this.logger.info(\"Agenda jobs disabled...\");\n }\n }\n\n async $onDestroy(): Promise<any> {\n if (this.loadAgenda) {\n await this.agenda.stop();\n await this.agenda.close({force: true});\n\n this.logger.info(\"Agenda jobs stopped...\");\n }\n }\n\n protected getProviders(): Provider<any>[] {\n return Array.from(this.injector.getProviders(PROVIDER_TYPE_AGENDA));\n }\n\n protected addAgendaDefinitionsForProvider(provider: Provider): void {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n\n if (!store.define) {\n return;\n }\n\n const jobsToDefine = Object.entries(store.define);\n\n for (const [propertyKey, {name, ...options}] of jobsToDefine) {\n const instance = this.injector.get(provider.token);\n\n const jobProcessor: Processor = instance[propertyKey].bind(instance) as Processor;\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n this.agenda.define(jobName, options, jobProcessor);\n }\n }\n\n protected async scheduleJobsForProvider(provider: Provider<any>): Promise<void> {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n if (!store.every) {\n return;\n }\n\n const jobsToSchedule = Object.entries(store.every);\n await Promise.all(\n jobsToSchedule.map(([propertyKey, {interval, name, ...options}]) => {\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n return this.agenda.every(interval, jobName, {}, options);\n })\n );\n }\n\n protected getNameForJob(propertyKey: string, namespace?: string, customName?: string): string {\n const name = customName || propertyKey;\n return namespace ? `${namespace}.${name}` : name;\n }\n}\n"]}
1
+ {"version":3,"file":"AgendaModule.js","sourceRoot":"","sources":["../../src/AgendaModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA4D;AAC5D,iCAA6E;AAE7E,qDAA2D;AAE3D,4DAAuD;AAGvD,IAAa,YAAY,GAAzB,MAAa,YAAY;IAavB,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEhF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YAC9C,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAE1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YACjD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC;SACzE;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;SAC7C;IACH,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACzB,M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AC,CAAC;QACnD,MAAM,OAAO,CAAC,GAAG,CACf,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,EAAC,CAAC,EAAE,EAAE;YACjE,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACvE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAES,aAAa,CAAC,WAAmB,EAAE,SAAkB,EAAE,UAAmB;QAClF,MAAM,IAAI,GAAG,UAAU,IAAI,WAAW,CAAC;QACvC,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC;CACF,CAAA;AA5EC;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;4CAAC;AAGzB;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;8CAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACS,6BAAa;4CAAC;AAGhC;IADC,IAAA,aAAQ,EAAC,gBAAgB,EAAE,KAAK,CAAC;;gDACN;AAXjB,YAAY;IADxB,IAAA,WAAM,GAAE;GACI,YAAY,CA8ExB;AA9EY,oCAAY","sourcesContent":["import {AfterListen, Logger, OnDestroy} from \"@tsed/common\";\nimport {Constant, Inject, InjectorService, Module, Provider} from \"@tsed/di\";\nimport {Processor} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"./constants/constants\";\nimport {AgendaStore} from \"./interfaces/AgendaStore\";\nimport {AgendaService} from \"./services/AgendaFactory\";\n\n@Module()\nexport class AgendaModule implements OnDestroy, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected agenda: AgendaService;\n\n @Constant(\"agenda.enabled\", false)\n private loadAgenda: boolean;\n\n async $afterListen(): Promise<any> {\n if (this.loadAgenda) {\n const providers = this.getProviders();\n providers.forEach((provider) => this.addAgendaDefinitionsForProvider(provider));\n\n this.logger.info(\"Agenda add definitions...\");\n await this.agenda.start();\n\n this.logger.info(\"Agenda add scheduled jobs...\");\n providers.forEach((provider) => this.scheduleJobsForProvider(provider));\n } else {\n this.logger.info(\"Agenda jobs disabled...\");\n }\n }\n\n async $onDestroy(): Promise<any> {\n if (this.loadAgenda) {\n await this.agenda.stop();\n await this.agenda.close({force: true});\n\n this.logger.info(\"Agenda jobs stopped...\");\n }\n }\n\n protected getProviders(): Provider<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_AGENDA);\n }\n\n protected addAgendaDefinitionsForProvider(provider: Provider): void {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n\n if (!store.define) {\n return;\n }\n\n const jobsToDefine = Object.entries(store.define);\n\n for (const [propertyKey, {name, ...options}] of jobsToDefine) {\n const instance = this.injector.get(provider.token);\n\n const jobProcessor: Processor = instance[propertyKey].bind(instance) as Processor;\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n this.agenda.define(jobName, options, jobProcessor);\n }\n }\n\n protected async scheduleJobsForProvider(provider: Provider<any>): Promise<void> {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n if (!store.every) {\n return;\n }\n\n const jobsToSchedule = Object.entries(store.every);\n await Promise.all(\n jobsToSchedule.map(([propertyKey, {interval, name, ...options}]) => {\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n return this.agenda.every(interval, jobName, {}, options);\n })\n );\n }\n\n protected getNameForJob(propertyKey: string, namespace?: string, customName?: string): string {\n const name = customName || propertyKey;\n return namespace ? `${namespace}.${name}` : name;\n }\n}\n"]}
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROVIDER_TYPE_AGENDA = void 0;
4
4
  exports.PROVIDER_TYPE_AGENDA = "PROVIDER_TYPE_AGENDA";
5
- //# sourceMappingURL=index.js.map
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,sBAAsB,CAAC","sourcesContent":["export const PROVIDER_TYPE_AGENDA = \"PROVIDER_TYPE_AGENDA\";\n"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Agenda = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const di_1 = require("@tsed/di");
6
- const constants_1 = require("../constants");
6
+ const constants_1 = require("../constants/constants");
7
7
  function Agenda(options) {
8
8
  return (0, core_1.useDecorators)((0, core_1.StoreMerge)("agenda", { namespace: options === null || options === void 0 ? void 0 : options.namespace }), (0, di_1.Injectable)({
9
9
  type: constants_1.PROVIDER_TYPE_AGENDA
@@ -1 +1 @@
1
- {"version":3,"file":"agenda.js","sourceRoot":"","sources":["../../../src/decorators/agenda.ts"],"names":[],"mappings":";;;AAAA,qCAAqD;AACrD,iCAAoC;AAEpC,4CAAkD;AAiBlD,SAAgB,MAAM,CAAC,OAAuB;IAC5C,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAU,EAAC,QAAQ,EAAE,EAAC,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAC,CAAC,EACrD,IAAA,eAAU,EAAC;QACT,IAAI,EAAE,gCAAoB;KAC3B,CAAC,CACH,CAAC;AACJ,CAAC;AAPD,wBAOC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {AgendaConfig} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"../constants\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /** * Enable Agenda jobs. Default false. */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n\ninterface AgendaOptions {\n namespace?: string;\n}\n\nexport function Agenda(options?: AgendaOptions): ClassDecorator {\n return useDecorators(\n StoreMerge(\"agenda\", {namespace: options?.namespace}),\n Injectable({\n type: PROVIDER_TYPE_AGENDA\n })\n );\n}\n"]}
1
+ {"version":3,"file":"agenda.js","sourceRoot":"","sources":["../../../src/decorators/agenda.ts"],"names":[],"mappings":";;;AAAA,qCAAqD;AACrD,iCAAoC;AAEpC,sDAA4D;AAiB5D,SAAgB,MAAM,CAAC,OAAuB;IAC5C,OAAO,IAAA,oBAAa,EAClB,IAAA,iBAAU,EAAC,QAAQ,EAAE,EAAC,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAC,CAAC,EACrD,IAAA,eAAU,EAAC;QACT,IAAI,EAAE,gCAAoB;KAC3B,CAAC,CACH,CAAC;AACJ,CAAC;AAPD,wBAOC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {AgendaConfig} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"../constants/constants\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /** * Enable Agenda jobs. Default false. */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n\ninterface AgendaOptions {\n namespace?: string;\n}\n\nexport function Agenda(options?: AgendaOptions): ClassDecorator {\n return useDecorators(\n StoreMerge(\"agenda\", {namespace: options?.namespace}),\n Injectable({\n type: PROVIDER_TYPE_AGENDA\n })\n );\n}\n"]}
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./AgendaModule"), exports);
5
- (0, tslib_1.__exportStar)(require("./constants"), exports);
6
- (0, tslib_1.__exportStar)(require("./decorators"), exports);
7
- (0, tslib_1.__exportStar)(require("./interfaces/AgendaStore"), exports);
8
- (0, tslib_1.__exportStar)(require("./services/AgendaFactory"), exports);
7
+ tslib_1.__exportStar(require("./AgendaModule"), exports);
8
+ tslib_1.__exportStar(require("./constants/constants"), exports);
9
+ tslib_1.__exportStar(require("./decorators/agenda"), exports);
10
+ tslib_1.__exportStar(require("./decorators/define"), exports);
11
+ tslib_1.__exportStar(require("./decorators/every"), exports);
12
+ tslib_1.__exportStar(require("./interfaces/AgendaStore"), exports);
13
+ tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
14
+ tslib_1.__exportStar(require("./services/AgendaFactory"), exports);
9
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAeA,8DAA+B;AAC/B,2DAA4B;AAC5B,4DAA6B;AAC7B,wEAAyC;AACzC,wEAAyC","sourcesContent":["import {AgendaConfig} from \"agenda\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /**\n * Enable Agenda jobs. Default false.\n */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n\nexport * from \"./AgendaModule\";\nexport * from \"./constants\";\nexport * from \"./decorators\";\nexport * from \"./interfaces/AgendaStore\";\nexport * from \"./services/AgendaFactory\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yDAA+B;AAC/B,gEAAsC;AACtC,8DAAoC;AACpC,8DAAoC;AACpC,6DAAmC;AACnC,mEAAyC;AACzC,kEAAwC;AACxC,mEAAyC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./AgendaModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/agenda\";\nexport * from \"./decorators/define\";\nexport * from \"./decorators/every\";\nexport * from \"./interfaces/AgendaStore\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/AgendaFactory\";\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {AgendaConfig} from \"agenda\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /**\n * Enable Agenda jobs. Default false.\n */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -1,8 +1,8 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Logger } from "@tsed/common";
3
3
  import { Constant, Inject, InjectorService, Module } from "@tsed/di";
4
- import { PROVIDER_TYPE_AGENDA } from "./constants/index";
5
- import { AgendaService } from "./services/AgendaFactory";
4
+ import { PROVIDER_TYPE_AGENDA } from "./constants/constants.js";
5
+ import { AgendaService } from "./services/AgendaFactory.js";
6
6
  let AgendaModule = class AgendaModule {
7
7
  async $afterListen() {
8
8
  if (this.loadAgenda) {
@@ -25,7 +25,7 @@ let AgendaModule = class AgendaModule {
25
25
  }
26
26
  }
27
27
  getProviders() {
28
- return Array.from(this.injector.getProviders(PROVIDER_TYPE_AGENDA));
28
+ return this.injector.getProviders(PROVIDER_TYPE_AGENDA);
29
29
  }
30
30
  addAgendaDefinitionsForProvider(provider) {
31
31
  const store = provider.store.get("agenda");
@@ -1 +1 @@
1
- {"version":3,"file":"AgendaModule.js","sourceRoot":"","sources":["../../src/AgendaModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,MAAM,EAAY,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAW,MAAM,UAAU,CAAC;AAE7E,OAAO,EAAC,oBAAoB,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,CAAC,CAAC;QAC3D,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAES,aAAa,CAAC,WAAmB,EAAE,SAAkB,EAAE,UAAmB;QAClF,MAAM,IAAI,GAAG,UAAU,IAAI,WAAW,CAAC;QACvC,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC;CACF,CAAA;AA5EC;IADC,MAAM,EAAE;8BACS,MAAM;4CAAC;AAGzB;IADC,MAAM,EAAE;8BACW,eAAe;8CAAC;AAGpC;IADC,MAAM,EAAE;8BACS,aAAa;4CAAC;AAGhC;IADC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;;gDACN;AAXjB,YAAY;IADxB,MAAM,EAAE;GACI,YAAY,CA8ExB;SA9EY,YAAY","sourcesContent":["import {AfterListen, Logger, OnDestroy} from \"@tsed/common\";\nimport {Constant, Inject, InjectorService, Module, Provider} from \"@tsed/di\";\nimport {Processor} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"./constants/index\";\nimport {AgendaStore} from \"./interfaces/AgendaStore\";\nimport {AgendaService} from \"./services/AgendaFactory\";\n\n@Module()\nexport class AgendaModule implements OnDestroy, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected agenda: AgendaService;\n\n @Constant(\"agenda.enabled\", false)\n private loadAgenda: boolean;\n\n async $afterListen(): Promise<any> {\n if (this.loadAgenda) {\n const providers = this.getProviders();\n providers.forEach((provider) => this.addAgendaDefinitionsForProvider(provider));\n\n this.logger.info(\"Agenda add definitions...\");\n await this.agenda.start();\n\n this.logger.info(\"Agenda add scheduled jobs...\");\n providers.forEach((provider) => this.scheduleJobsForProvider(provider));\n } else {\n this.logger.info(\"Agenda jobs disabled...\");\n }\n }\n\n async $onDestroy(): Promise<any> {\n if (this.loadAgenda) {\n await this.agenda.stop();\n await this.agenda.close({force: true});\n\n this.logger.info(\"Agenda jobs stopped...\");\n }\n }\n\n protected getProviders(): Provider<any>[] {\n return Array.from(this.injector.getProviders(PROVIDER_TYPE_AGENDA));\n }\n\n protected addAgendaDefinitionsForProvider(provider: Provider): void {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n\n if (!store.define) {\n return;\n }\n\n const jobsToDefine = Object.entries(store.define);\n\n for (const [propertyKey, {name, ...options}] of jobsToDefine) {\n const instance = this.injector.get(provider.token);\n\n const jobProcessor: Processor = instance[propertyKey].bind(instance) as Processor;\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n this.agenda.define(jobName, options, jobProcessor);\n }\n }\n\n protected async scheduleJobsForProvider(provider: Provider<any>): Promise<void> {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n if (!store.every) {\n return;\n }\n\n const jobsToSchedule = Object.entries(store.every);\n await Promise.all(\n jobsToSchedule.map(([propertyKey, {interval, name, ...options}]) => {\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n return this.agenda.every(interval, jobName, {}, options);\n })\n );\n }\n\n protected getNameForJob(propertyKey: string, namespace?: string, customName?: string): string {\n const name = customName || propertyKey;\n return namespace ? `${namespace}.${name}` : name;\n }\n}\n"]}
1
+ {"version":3,"file":"AgendaModule.js","sourceRoot":"","sources":["../../src/AgendaModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,MAAM,EAAY,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAW,MAAM,UAAU,CAAC;AAE7E,OAAO,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAGvD,IAAa,YAAY,GAAzB,MAAa,YAAY;IAavB,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,SAAS,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;AA5EC;IADC,MAAM,EAAE;8BACS,MAAM;4CAAC;AAGzB;IADC,MAAM,EAAE;8BACW,eAAe;8CAAC;AAGpC;IADC,MAAM,EAAE;8BACS,aAAa;4CAAC;AAGhC;IADC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;;gDACN;AAXjB,YAAY;IADxB,MAAM,EAAE;GACI,YAAY,CA8ExB;SA9EY,YAAY","sourcesContent":["import {AfterListen, Logger, OnDestroy} from \"@tsed/common\";\nimport {Constant, Inject, InjectorService, Module, Provider} from \"@tsed/di\";\nimport {Processor} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"./constants/constants\";\nimport {AgendaStore} from \"./interfaces/AgendaStore\";\nimport {AgendaService} from \"./services/AgendaFactory\";\n\n@Module()\nexport class AgendaModule implements OnDestroy, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected agenda: AgendaService;\n\n @Constant(\"agenda.enabled\", false)\n private loadAgenda: boolean;\n\n async $afterListen(): Promise<any> {\n if (this.loadAgenda) {\n const providers = this.getProviders();\n providers.forEach((provider) => this.addAgendaDefinitionsForProvider(provider));\n\n this.logger.info(\"Agenda add definitions...\");\n await this.agenda.start();\n\n this.logger.info(\"Agenda add scheduled jobs...\");\n providers.forEach((provider) => this.scheduleJobsForProvider(provider));\n } else {\n this.logger.info(\"Agenda jobs disabled...\");\n }\n }\n\n async $onDestroy(): Promise<any> {\n if (this.loadAgenda) {\n await this.agenda.stop();\n await this.agenda.close({force: true});\n\n this.logger.info(\"Agenda jobs stopped...\");\n }\n }\n\n protected getProviders(): Provider<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_AGENDA);\n }\n\n protected addAgendaDefinitionsForProvider(provider: Provider): void {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n\n if (!store.define) {\n return;\n }\n\n const jobsToDefine = Object.entries(store.define);\n\n for (const [propertyKey, {name, ...options}] of jobsToDefine) {\n const instance = this.injector.get(provider.token);\n\n const jobProcessor: Processor = instance[propertyKey].bind(instance) as Processor;\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n this.agenda.define(jobName, options, jobProcessor);\n }\n }\n\n protected async scheduleJobsForProvider(provider: Provider<any>): Promise<void> {\n const store = provider.store.get<AgendaStore>(\"agenda\");\n if (!store.every) {\n return;\n }\n\n const jobsToSchedule = Object.entries(store.every);\n await Promise.all(\n jobsToSchedule.map(([propertyKey, {interval, name, ...options}]) => {\n const jobName = this.getNameForJob(propertyKey, store.namespace, name);\n return this.agenda.every(interval, jobName, {}, options);\n })\n );\n }\n\n protected getNameForJob(propertyKey: string, namespace?: string, customName?: string): string {\n const name = customName || propertyKey;\n return namespace ? `${namespace}.${name}` : name;\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
1
  export const PROVIDER_TYPE_AGENDA = "PROVIDER_TYPE_AGENDA";
2
- //# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC","sourcesContent":["export const PROVIDER_TYPE_AGENDA = \"PROVIDER_TYPE_AGENDA\";\n"]}
@@ -1,6 +1,6 @@
1
1
  import { StoreMerge, useDecorators } from "@tsed/core";
2
2
  import { Injectable } from "@tsed/di";
3
- import { PROVIDER_TYPE_AGENDA } from "../constants";
3
+ import { PROVIDER_TYPE_AGENDA } from "../constants/constants.js";
4
4
  export function Agenda(options) {
5
5
  return useDecorators(StoreMerge("agenda", { namespace: options === null || options === void 0 ? void 0 : options.namespace }), Injectable({
6
6
  type: PROVIDER_TYPE_AGENDA
@@ -1 +1 @@
1
- {"version":3,"file":"agenda.js","sourceRoot":"","sources":["../../../src/decorators/agenda.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAC,oBAAoB,EAAC,MAAM,cAAc,CAAC;AAiBlD,MAAM,UAAU,MAAM,CAAC,OAAuB;IAC5C,OAAO,aAAa,CAClB,UAAU,CAAC,QAAQ,EAAE,EAAC,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAC,CAAC,EACrD,UAAU,CAAC;QACT,IAAI,EAAE,oBAAoB;KAC3B,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {AgendaConfig} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"../constants\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /** * Enable Agenda jobs. Default false. */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n\ninterface AgendaOptions {\n namespace?: string;\n}\n\nexport function Agenda(options?: AgendaOptions): ClassDecorator {\n return useDecorators(\n StoreMerge(\"agenda\", {namespace: options?.namespace}),\n Injectable({\n type: PROVIDER_TYPE_AGENDA\n })\n );\n}\n"]}
1
+ {"version":3,"file":"agenda.js","sourceRoot":"","sources":["../../../src/decorators/agenda.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAiB5D,MAAM,UAAU,MAAM,CAAC,OAAuB;IAC5C,OAAO,aAAa,CAClB,UAAU,CAAC,QAAQ,EAAE,EAAC,SAAS,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAC,CAAC,EACrD,UAAU,CAAC;QACT,IAAI,EAAE,oBAAoB;KAC3B,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {StoreMerge, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {AgendaConfig} from \"agenda\";\nimport {PROVIDER_TYPE_AGENDA} from \"../constants/constants\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /** * Enable Agenda jobs. Default false. */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n\ninterface AgendaOptions {\n namespace?: string;\n}\n\nexport function Agenda(options?: AgendaOptions): ClassDecorator {\n return useDecorators(\n StoreMerge(\"agenda\", {namespace: options?.namespace}),\n Injectable({\n type: PROVIDER_TYPE_AGENDA\n })\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Store, useDecorators } from "@tsed/core";
2
- import { Define } from "./define";
2
+ import { Define } from "./define.js";
3
3
  export function Every(interval, options = {}) {
4
4
  return useDecorators(Define(options), (target, propertyKey) => {
5
5
  const store = {
package/lib/esm/index.js CHANGED
@@ -1,6 +1,12 @@
1
- export * from "./AgendaModule";
2
- export * from "./constants";
3
- export * from "./decorators";
4
- export * from "./interfaces/AgendaStore";
5
- export * from "./services/AgendaFactory";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./AgendaModule.js";
5
+ export * from "./constants/constants.js";
6
+ export * from "./decorators/agenda.js";
7
+ export * from "./decorators/define.js";
8
+ export * from "./decorators/every.js";
9
+ export * from "./interfaces/AgendaStore.js";
10
+ export * from "./interfaces/interfaces.js";
11
+ export * from "./services/AgendaFactory.js";
6
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAeA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC","sourcesContent":["import {AgendaConfig} from \"agenda\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /**\n * Enable Agenda jobs. Default false.\n */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n\nexport * from \"./AgendaModule\";\nexport * from \"./constants\";\nexport * from \"./decorators\";\nexport * from \"./interfaces/AgendaStore\";\nexport * from \"./services/AgendaFactory\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./AgendaModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/agenda\";\nexport * from \"./decorators/define\";\nexport * from \"./decorators/every\";\nexport * from \"./interfaces/AgendaStore\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/AgendaFactory\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {AgendaConfig} from \"agenda\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n agenda?: {\n /**\n * Enable Agenda jobs. Default false.\n */\n enabled?: boolean;\n } & AgendaConfig;\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -1,18 +1,11 @@
1
- import { AgendaConfig } from "agenda";
2
- declare global {
3
- namespace TsED {
4
- interface Configuration {
5
- agenda?: {
6
- /**
7
- * Enable Agenda jobs. Default false.
8
- */
9
- enabled?: boolean;
10
- } & AgendaConfig;
11
- }
12
- }
13
- }
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
14
4
  export * from "./AgendaModule";
15
- export * from "./constants";
16
- export * from "./decorators";
5
+ export * from "./constants/constants";
6
+ export * from "./decorators/agenda";
7
+ export * from "./decorators/define";
8
+ export * from "./decorators/every";
17
9
  export * from "./interfaces/AgendaStore";
10
+ export * from "./interfaces/interfaces";
18
11
  export * from "./services/AgendaFactory";
@@ -0,0 +1,13 @@
1
+ import { AgendaConfig } from "agenda";
2
+ declare global {
3
+ namespace TsED {
4
+ interface Configuration {
5
+ agenda?: {
6
+ /**
7
+ * Enable Agenda jobs. Default false.
8
+ */
9
+ enabled?: boolean;
10
+ } & AgendaConfig;
11
+ }
12
+ }
13
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@tsed/agenda",
3
- "version": "7.0.0-beta.3",
3
+ "version": "7.0.0-beta.6",
4
4
  "description": "Agenda package for Ts.ED framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/cjs/index.js",
7
+ "module": "./lib/esm/index.js",
7
8
  "typings": "./lib/types/index.d.ts",
8
9
  "exports": {
9
10
  "types": "./lib/types/index.d.ts",
@@ -12,19 +13,20 @@
12
13
  "default": "./lib/esm/index.js"
13
14
  },
14
15
  "scripts": {
15
- "build": "yarn run build:esm && yarn run build:cjs",
16
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
16
17
  "build:cjs": "tsc --build tsconfig.compile.json",
17
18
  "build:esm": "tsc --build tsconfig.compile.esm.json",
19
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
18
20
  "test": "cross-env NODE_ENV=test nyc mocha"
19
21
  },
20
22
  "dependencies": {
21
- "tslib": "2.2.0"
23
+ "tslib": "2.3.1"
22
24
  },
23
25
  "private": false,
24
26
  "devDependencies": {
25
- "@tsed/common": "7.0.0-beta.3",
26
- "@tsed/core": "7.0.0-beta.3",
27
- "@tsed/di": "7.0.0-beta.3",
27
+ "@tsed/common": "7.0.0-beta.6",
28
+ "@tsed/core": "7.0.0-beta.6",
29
+ "@tsed/di": "7.0.0-beta.6",
28
30
  "agenda": "^4.1.3"
29
31
  },
30
32
  "peerDependencies": {
@@ -34,7 +36,7 @@
34
36
  "bugs": {
35
37
  "url": "https://github.com/tsedio/tsed/issues"
36
38
  },
37
- "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/third-parties/agenda",
39
+ "homepage": "https://github.com/tsedio/tsed/tree/production/packages/third-parties/agenda",
38
40
  "author": "Romain Lenzotti",
39
41
  "license": "MIT"
40
42
  }
package/readme.md CHANGED
@@ -59,16 +59,14 @@ const mongoConnectionString = "mongodb://127.0.0.1/agenda";
59
59
 
60
60
  @Configuration({
61
61
  agenda: {
62
- enabled: true, // Enable Agenda jobs for this instance.
63
- // pass any options that you would normally pass to new Agenda(), e.g.
64
- db: {
65
- address: mongoConnectionString
66
- }
62
+ enabled: true, // Enable Agenda jobs for this instance.
63
+ // pass any options that you would normally pass to new Agenda(), e.g.
64
+ db: {
65
+ address: mongoConnectionString
66
+ }
67
67
  }
68
68
  })
69
- export class Server {
70
-
71
- }
69
+ export class Server {}
72
70
  ```
73
71
 
74
72
  ## Create a new Service
@@ -130,8 +128,8 @@ export class UsersService implements AfterRoutesInit {
130
128
  // do something
131
129
  // ...
132
130
  // then schedule some jobs
133
- await this.agenda.now("email.sendWelcomeEmail", {user})
134
- await this.agenda.schedule("in 2 hours", "email.sendFollowUpEmail", {user})
131
+ await this.agenda.now("email.sendWelcomeEmail", {user});
132
+ await this.agenda.schedule("in 2 hours", "email.sendFollowUpEmail", {user});
135
133
 
136
134
  return user;
137
135
  }
@@ -139,18 +137,17 @@ export class UsersService implements AfterRoutesInit {
139
137
  ```
140
138
 
141
139
  ## Contributors
140
+
142
141
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
143
142
 
144
143
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
145
144
 
146
-
147
145
  ## Backers
148
146
 
149
147
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
150
148
 
151
149
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
152
150
 
153
-
154
151
  ## Sponsors
155
152
 
156
153
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -1,7 +1,7 @@
1
1
  import {AfterListen, Logger, OnDestroy} from "@tsed/common";
2
2
  import {Constant, Inject, InjectorService, Module, Provider} from "@tsed/di";
3
3
  import {Processor} from "agenda";
4
- import {PROVIDER_TYPE_AGENDA} from "./constants/index";
4
+ import {PROVIDER_TYPE_AGENDA} from "./constants/constants";
5
5
  import {AgendaStore} from "./interfaces/AgendaStore";
6
6
  import {AgendaService} from "./services/AgendaFactory";
7
7
 
@@ -44,7 +44,7 @@ export class AgendaModule implements OnDestroy, AfterListen {
44
44
  }
45
45
 
46
46
  protected getProviders(): Provider<any>[] {
47
- return Array.from(this.injector.getProviders(PROVIDER_TYPE_AGENDA));
47
+ return this.injector.getProviders(PROVIDER_TYPE_AGENDA);
48
48
  }
49
49
 
50
50
  protected addAgendaDefinitionsForProvider(provider: Provider): void {
File without changes
@@ -1,7 +1,7 @@
1
1
  import {StoreMerge, useDecorators} from "@tsed/core";
2
2
  import {Injectable} from "@tsed/di";
3
3
  import {AgendaConfig} from "agenda";
4
- import {PROVIDER_TYPE_AGENDA} from "../constants";
4
+ import {PROVIDER_TYPE_AGENDA} from "../constants/constants";
5
5
 
6
6
  declare global {
7
7
  namespace TsED {
package/src/index.ts CHANGED
@@ -1,20 +1,12 @@
1
- import {AgendaConfig} from "agenda";
2
-
3
- declare global {
4
- namespace TsED {
5
- interface Configuration {
6
- agenda?: {
7
- /**
8
- * Enable Agenda jobs. Default false.
9
- */
10
- enabled?: boolean;
11
- } & AgendaConfig;
12
- }
13
- }
14
- }
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
15
4
 
16
5
  export * from "./AgendaModule";
17
- export * from "./constants";
18
- export * from "./decorators";
6
+ export * from "./constants/constants";
7
+ export * from "./decorators/agenda";
8
+ export * from "./decorators/define";
9
+ export * from "./decorators/every";
19
10
  export * from "./interfaces/AgendaStore";
11
+ export * from "./interfaces/interfaces";
20
12
  export * from "./services/AgendaFactory";
@@ -0,0 +1,14 @@
1
+ import {AgendaConfig} from "agenda";
2
+
3
+ declare global {
4
+ namespace TsED {
5
+ interface Configuration {
6
+ agenda?: {
7
+ /**
8
+ * Enable Agenda jobs. Default false.
9
+ */
10
+ enabled?: boolean;
11
+ } & AgendaConfig;
12
+ }
13
+ }
14
+ }
@@ -8,16 +8,5 @@
8
8
  "declaration": true,
9
9
  "declarationDir": "./lib/types"
10
10
  },
11
- "exclude": [
12
- "node_modules",
13
- "test",
14
- "lib",
15
- "benchmark",
16
- "coverage",
17
- "spec",
18
- "**/*.benchmark.ts",
19
- "**/*.spec.ts",
20
- "keys",
21
- "jest.config.js"
22
- ]
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
23
12
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,sBAAsB,CAAC","sourcesContent":["export const PROVIDER_TYPE_AGENDA = \"PROVIDER_TYPE_AGENDA\";\n"]}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./agenda"), exports);
5
- (0, tslib_1.__exportStar)(require("./define"), exports);
6
- (0, tslib_1.__exportStar)(require("./every"), exports);
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,wDAAyB;AACzB,wDAAyB;AACzB,uDAAwB","sourcesContent":["export * from \"./agenda\";\nexport * from \"./define\";\nexport * from \"./every\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC","sourcesContent":["export const PROVIDER_TYPE_AGENDA = \"PROVIDER_TYPE_AGENDA\";\n"]}
@@ -1,4 +0,0 @@
1
- export * from "./agenda";
2
- export * from "./define";
3
- export * from "./every";
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC","sourcesContent":["export * from \"./agenda\";\nexport * from \"./define\";\nexport * from \"./every\";\n"]}
@@ -1,3 +0,0 @@
1
- export * from "./agenda";
2
- export * from "./define";
3
- export * from "./every";
@@ -1,3 +0,0 @@
1
- export * from "./agenda";
2
- export * from "./define";
3
- export * from "./every";