@loopback/boot 2.3.1 → 2.3.5

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 (104) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/.sandbox/{63541odlHvc → 18043muTUQs}/model-endpoints/product.rest-config.js +0 -0
  3. package/dist/.sandbox/18043muTUQs/models/product.model.js +25 -0
  4. package/dist/.sandbox/{635419mu8mo → 18043wLA3S3}/application.js +0 -0
  5. package/dist/.sandbox/18043wLA3S3/controllers/multiple.controller.js +39 -0
  6. package/dist/.sandbox/{63541DlS0Ic → 18044FOwh70}/application.js +0 -0
  7. package/dist/.sandbox/18044FOwh70/interceptors/interceptor.interceptor.js +51 -0
  8. package/dist/.sandbox/18044FOwh70/interceptors/non-global-interceptor.interceptor.js +51 -0
  9. package/dist/.sandbox/{63541DshyBF → 18045Jt9E5K}/application.js +0 -0
  10. package/dist/.sandbox/{63541ik89oh → 18045Jt9E5K}/models/multiple-models.model.js +0 -0
  11. package/dist/.sandbox/18045Jt9E5K/models/no-entity.model.js +25 -0
  12. package/dist/.sandbox/18045Jt9E5K/models/product.model.js +25 -0
  13. package/dist/.sandbox/{63541IEce5V → 18045YaR1P2}/application.js +0 -0
  14. package/dist/.sandbox/{63541DshyBF → 18045YaR1P2}/observers/lifecycle-observer.observer.js +0 -0
  15. package/dist/.sandbox/{635415cxfJi → 18045e2CYyx}/service-provider.artifact.js +0 -0
  16. package/dist/.sandbox/18045hzRuQ4/dist/application.js +20 -0
  17. package/dist/.sandbox/{63541meTxP7 → 18045hzRuQ4}/package.json +1 -1
  18. package/dist/.sandbox/{635419t6TqH → 18045rgy7Ui}/datasource.artifact.js +5 -8
  19. package/dist/.sandbox/{63541ik89oh → 18046d8C54w}/application.js +0 -0
  20. package/dist/.sandbox/18046d8C54w/controllers/multiple.controller.js +39 -0
  21. package/dist/.sandbox/{package.json → 18046d8C54w/package.json} +1 -1
  22. package/dist/.sandbox/18046kEhstv/multiple.artifact.js +39 -0
  23. package/dist/.sandbox/18046obZENY/multiple.artifact.js +39 -0
  24. package/dist/.sandbox/{63541meTxP7 → 18047EeHfXu}/application.js +0 -0
  25. package/dist/.sandbox/18047EeHfXu/repositories/multiple.repository.js +39 -0
  26. package/dist/.sandbox/{63541nGmQFL → 18048e1iuZt}/application.js +0 -0
  27. package/dist/.sandbox/{635419mu8mo → 18048e1iuZt}/services/bindable-classes.service.js +19 -25
  28. package/dist/.sandbox/{635419mu8mo → 18048e1iuZt}/services/geocoder.service.js +0 -0
  29. package/dist/.sandbox/{635419mu8mo → 18048e1iuZt}/services/greeting.service.js +0 -0
  30. package/dist/.sandbox/18048urj9RP/application.js +20 -0
  31. package/dist/.sandbox/18048urj9RP/controllers/multiple.controller.js +39 -0
  32. package/dist/.sandbox/18048urj9RP/package.json +18 -0
  33. package/dist/.sandbox/{635411GGsm1 → 18049UriL05}/model-endpoints/no-entity.rest-config.js +0 -0
  34. package/dist/.sandbox/18049UriL05/models/no-entity.model.js +25 -0
  35. package/dist/.sandbox/{63541ruUDNf → 18049gfsPc4}/application.js +0 -0
  36. package/dist/.sandbox/{63541IEce5V → 18049gfsPc4}/datasources/db.datasource.js +5 -8
  37. package/dist/boot.component.js +30 -34
  38. package/dist/boot.component.js.map +1 -1
  39. package/dist/booters/application-metadata.booter.js +19 -23
  40. package/dist/booters/application-metadata.booter.js.map +1 -1
  41. package/dist/booters/base-artifact.booter.d.ts +1 -1
  42. package/dist/booters/base-artifact.booter.js +1 -1
  43. package/dist/booters/booter-utils.d.ts +1 -1
  44. package/dist/booters/component-application.booter.js +39 -42
  45. package/dist/booters/component-application.booter.js.map +1 -1
  46. package/dist/booters/controller.booter.js +26 -30
  47. package/dist/booters/controller.booter.js.map +1 -1
  48. package/dist/booters/datasource.booter.js +36 -40
  49. package/dist/booters/datasource.booter.js.map +1 -1
  50. package/dist/booters/interceptor.booter.d.ts +1 -2
  51. package/dist/booters/interceptor.booter.js +28 -32
  52. package/dist/booters/interceptor.booter.js.map +1 -1
  53. package/dist/booters/lifecyle-observer.booter.d.ts +1 -1
  54. package/dist/booters/lifecyle-observer.booter.js +29 -32
  55. package/dist/booters/lifecyle-observer.booter.js.map +1 -1
  56. package/dist/booters/model-api.booter.js +63 -66
  57. package/dist/booters/model-api.booter.js.map +1 -1
  58. package/dist/booters/model.booter.js +31 -35
  59. package/dist/booters/model.booter.js.map +1 -1
  60. package/dist/booters/repository.booter.js +35 -39
  61. package/dist/booters/repository.booter.js.map +1 -1
  62. package/dist/booters/service.booter.js +30 -34
  63. package/dist/booters/service.booter.js.map +1 -1
  64. package/dist/bootstrapper.d.ts +1 -2
  65. package/dist/bootstrapper.js +77 -85
  66. package/dist/bootstrapper.js.map +1 -1
  67. package/dist/keys.d.ts +1 -1
  68. package/dist/keys.js +4 -4
  69. package/dist/keys.js.map +1 -1
  70. package/dist/mixins/boot.mixin.d.ts +52 -41
  71. package/dist/mixins/boot.mixin.js +40 -18
  72. package/dist/mixins/boot.mixin.js.map +1 -1
  73. package/dist/types.d.ts +7 -1
  74. package/dist/types.js +2 -2
  75. package/dist/types.js.map +1 -1
  76. package/package.json +18 -19
  77. package/src/boot.component.ts +7 -2
  78. package/src/booters/application-metadata.booter.ts +1 -2
  79. package/src/booters/base-artifact.booter.ts +2 -2
  80. package/src/booters/booter-utils.ts +1 -1
  81. package/src/booters/controller.booter.ts +1 -2
  82. package/src/booters/datasource.booter.ts +2 -3
  83. package/src/booters/interceptor.booter.ts +3 -2
  84. package/src/booters/lifecyle-observer.booter.ts +1 -1
  85. package/src/booters/model.booter.ts +1 -2
  86. package/src/booters/repository.booter.ts +1 -2
  87. package/src/booters/service.booter.ts +2 -2
  88. package/src/bootstrapper.ts +11 -10
  89. package/src/keys.ts +1 -1
  90. package/src/mixins/boot.mixin.ts +50 -45
  91. package/src/types.ts +8 -1
  92. package/dist/.sandbox/635411GGsm1/models/no-entity.model.js +0 -28
  93. package/dist/.sandbox/63541BtDxTa/multiple.artifact.js +0 -45
  94. package/dist/.sandbox/63541DlS0Ic/repositories/multiple.repository.js +0 -45
  95. package/dist/.sandbox/63541ik89oh/models/no-entity.model.js +0 -28
  96. package/dist/.sandbox/63541ik89oh/models/product.model.js +0 -28
  97. package/dist/.sandbox/63541meTxP7/controllers/multiple.controller.js +0 -45
  98. package/dist/.sandbox/63541nGmQFL/controllers/multiple.controller.js +0 -45
  99. package/dist/.sandbox/63541odlHvc/models/product.model.js +0 -28
  100. package/dist/.sandbox/63541ruUDNf/interceptors/interceptor.interceptor.js +0 -54
  101. package/dist/.sandbox/63541ruUDNf/interceptors/non-global-interceptor.interceptor.js +0 -54
  102. package/dist/.sandbox/63541vSi6af/multiple.artifact.js +0 -45
  103. package/dist/.sandbox/application.js +0 -20
  104. package/dist/.sandbox/controllers/multiple.controller.js +0 -45
@@ -6,7 +6,6 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.ServiceDefaults = exports.ServiceBooter = void 0;
8
8
  const tslib_1 = require("tslib");
9
- const context_1 = require("@loopback/context");
10
9
  const core_1 = require("@loopback/core");
11
10
  const debug_1 = tslib_1.__importDefault(require("debug"));
12
11
  const keys_1 = require("../keys");
@@ -23,39 +22,36 @@ const debug = debug_1.default('loopback:boot:service-booter');
23
22
  * @param projectRoot - Root of User Project relative to which all paths are resolved
24
23
  * @param bootConfig - Service Artifact Options Object
25
24
  */
26
- let ServiceBooter = /** @class */ (() => {
27
- let ServiceBooter = class ServiceBooter extends base_artifact_booter_1.BaseArtifactBooter {
28
- constructor(app, projectRoot, serviceConfig = {}) {
29
- super(projectRoot,
30
- // Set Service Booter Options if passed in via bootConfig
31
- Object.assign({}, exports.ServiceDefaults, serviceConfig));
32
- this.app = app;
33
- this.serviceConfig = serviceConfig;
34
- }
35
- /**
36
- * Uses super method to get a list of Artifact classes. Boot each file by
37
- * creating a DataSourceConstructor and binding it to the application class.
38
- */
39
- async load() {
40
- await super.load();
41
- for (const cls of this.classes) {
42
- if (!isBindableClass(cls))
43
- continue;
44
- debug('Bind class: %s', cls.name);
45
- const binding = this.app.service(cls);
46
- debug('Binding created for class: %j', binding);
47
- }
25
+ let ServiceBooter = class ServiceBooter extends base_artifact_booter_1.BaseArtifactBooter {
26
+ constructor(app, projectRoot, serviceConfig = {}) {
27
+ super(projectRoot,
28
+ // Set Service Booter Options if passed in via bootConfig
29
+ Object.assign({}, exports.ServiceDefaults, serviceConfig));
30
+ this.app = app;
31
+ this.serviceConfig = serviceConfig;
32
+ }
33
+ /**
34
+ * Uses super method to get a list of Artifact classes. Boot each file by
35
+ * creating a DataSourceConstructor and binding it to the application class.
36
+ */
37
+ async load() {
38
+ await super.load();
39
+ for (const cls of this.classes) {
40
+ if (!isBindableClass(cls))
41
+ continue;
42
+ debug('Bind class: %s', cls.name);
43
+ const binding = this.app.service(cls);
44
+ debug('Binding created for class: %j', binding);
48
45
  }
49
- };
50
- ServiceBooter = tslib_1.__decorate([
51
- types_1.booter('services'),
52
- tslib_1.__param(0, context_1.inject(core_1.CoreBindings.APPLICATION_INSTANCE)),
53
- tslib_1.__param(1, context_1.inject(keys_1.BootBindings.PROJECT_ROOT)),
54
- tslib_1.__param(2, context_1.config()),
55
- tslib_1.__metadata("design:paramtypes", [Object, String, Object])
56
- ], ServiceBooter);
57
- return ServiceBooter;
58
- })();
46
+ }
47
+ };
48
+ ServiceBooter = tslib_1.__decorate([
49
+ types_1.booter('services'),
50
+ tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_INSTANCE)),
51
+ tslib_1.__param(1, core_1.inject(keys_1.BootBindings.PROJECT_ROOT)),
52
+ tslib_1.__param(2, core_1.config()),
53
+ tslib_1.__metadata("design:paramtypes", [Object, String, Object])
54
+ ], ServiceBooter);
59
55
  exports.ServiceBooter = ServiceBooter;
60
56
  /**
61
57
  * Default ArtifactOptions for DataSourceBooter.
@@ -71,7 +67,7 @@ function isServiceProvider(cls) {
71
67
  return hasSupportedName && hasValueMethod;
72
68
  }
73
69
  function isBindableClass(cls) {
74
- if (context_1.MetadataInspector.getClassMetadata(context_1.BINDING_METADATA_KEY, cls)) {
70
+ if (core_1.MetadataInspector.getClassMetadata(core_1.BINDING_METADATA_KEY, cls)) {
75
71
  return true;
76
72
  }
77
73
  if (isServiceProvider(cls)) {
@@ -1 +1 @@
1
- {"version":3,"file":"service.booter.js","sourceRoot":"","sources":["../../src/booters/service.booter.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAM2B;AAC3B,yCAA4C;AAE5C,0DAAiC;AACjC,kCAAqC;AACrC,oCAAiD;AACjD,iEAA0D;AAE1D,MAAM,KAAK,GAAG,eAAY,CAAC,8BAA8B,CAAC,CAAC;AAE3D;;;;;;;;;GASG;AAEH;IAAA,IAAa,aAAa,GAA1B,MAAa,aAAc,SAAQ,yCAAkB;QACnD,YAES,GAA4B,EACA,WAAmB,EAE/C,gBAAiC,EAAE;YAE1C,KAAK,CACH,WAAW;YACX,yDAAyD;YACzD,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,uBAAe,EAAE,aAAa,CAAC,CAClD,CAAC;YATK,QAAG,GAAH,GAAG,CAAyB;YAG5B,kBAAa,GAAb,aAAa,CAAsB;QAO5C,CAAC;QAED;;;WAGG;QACH,KAAK,CAAC,IAAI;YACR,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YAEnB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE;gBAC9B,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC;oBAAE,SAAS;gBAEpC,KAAK,CAAC,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;gBAClC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBACtC,KAAK,CAAC,+BAA+B,EAAE,OAAO,CAAC,CAAC;aACjD;QACH,CAAC;KACF,CAAA;IA9BY,aAAa;QADzB,cAAM,CA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AC,CAAC;IACvD,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,KAAK,UAAU,CAAC;IACjE,OAAO,gBAAgB,IAAI,cAAc,CAAC;AAC5C,CAAC;AAED,SAAS,eAAe,CAAC,GAAyB;IAChD,IAAI,wBAAiB,CAAC,gBAAgB,CAAC,2BAAoB,EAAE,GAAG,CAAC,EAAE;QACjE,OAAO,IAAI,CAAC;KACb;IACD,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE;QAC1B,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;KACb;IACD,KAAK,CAAC,yCAAyC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,5 +1,4 @@
1
- import { Context } from '@loopback/context';
2
- import { Application } from '@loopback/core';
1
+ import { Application, Context } from '@loopback/core';
3
2
  import { Bootable, BootExecutionOptions, BootOptions } from './types';
4
3
  /**
5
4
  * The Bootstrapper class provides the `boot` function that is responsible for
@@ -6,7 +6,6 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.Bootstrapper = void 0;
8
8
  const tslib_1 = require("tslib");
9
- const context_1 = require("@loopback/context");
10
9
  const core_1 = require("@loopback/core");
11
10
  const debug_1 = tslib_1.__importDefault(require("debug"));
12
11
  const path_1 = require("path");
@@ -25,93 +24,86 @@ const debug = debug_1.default('loopback:boot:bootstrapper');
25
24
  * @param projectRoot - The root directory of the project, relative to which all other paths are resolved
26
25
  * @param bootOptions - The BootOptions describing the conventions to be used by various Booters
27
26
  */
28
- let Bootstrapper = /** @class */ (() => {
29
- let Bootstrapper = class Bootstrapper {
30
- constructor(app, projectRoot, bootOptions = {}) {
31
- this.app = app;
32
- this.projectRoot = projectRoot;
33
- this.bootOptions = bootOptions;
34
- // Resolve path to projectRoot and re-bind
35
- this.projectRoot = path_1.resolve(this.projectRoot);
36
- app.bind(keys_1.BootBindings.PROJECT_ROOT).to(this.projectRoot);
37
- // This is re-bound for testing reasons where this value may be passed directly
38
- // and needs to be propagated to the Booters via DI
39
- app.bind(keys_1.BootBindings.BOOT_OPTIONS).to(this.bootOptions);
27
+ let Bootstrapper = class Bootstrapper {
28
+ constructor(app, projectRoot, bootOptions = {}) {
29
+ this.app = app;
30
+ this.projectRoot = projectRoot;
31
+ this.bootOptions = bootOptions;
32
+ // Resolve path to projectRoot and re-bind
33
+ this.projectRoot = path_1.resolve(this.projectRoot);
34
+ app.bind(keys_1.BootBindings.PROJECT_ROOT).to(this.projectRoot);
35
+ // This is re-bound for testing reasons where this value may be passed directly
36
+ // and needs to be propagated to the Booters via DI
37
+ app.bind(keys_1.BootBindings.BOOT_OPTIONS).to(this.bootOptions);
38
+ }
39
+ /**
40
+ * Function is responsible for calling all registered Booter classes that
41
+ * are bound to the Application instance. Each phase of an instance must
42
+ * complete before the next phase is started.
43
+ *
44
+ * @param execOptions - Execution options for boot. These
45
+ * determine the phases and booters that are run.
46
+ * @param ctx - Optional Context to use to resolve bindings. This is
47
+ * primarily useful when running app.boot() again but with different settings
48
+ * (in particular phases) such as 'start' / 'stop'. Using a returned Context from
49
+ * a previous boot call allows DI to retrieve the same instances of Booters previously
50
+ * used as they are bound using a CONTEXT scope. This is important as Booter instances
51
+ * may maintain state.
52
+ */
53
+ async boot(execOptions, ctx) {
54
+ var _a, _b, _c;
55
+ const bootCtx = ctx !== null && ctx !== void 0 ? ctx : new core_1.Context(this.app);
56
+ // Bind booters passed in as a part of BootOptions
57
+ // We use _bindBooter so this Class can be used without the Mixin
58
+ if (execOptions === null || execOptions === void 0 ? void 0 : execOptions.booters) {
59
+ execOptions.booters.forEach(booter => mixins_1.bindBooter(this.app, booter));
40
60
  }
41
- /**
42
- * Function is responsible for calling all registered Booter classes that
43
- * are bound to the Application instance. Each phase of an instance must
44
- * complete before the next phase is started.
45
- *
46
- * @param execOptions - Execution options for boot. These
47
- * determine the phases and booters that are run.
48
- * @param ctx - Optional Context to use to resolve bindings. This is
49
- * primarily useful when running app.boot() again but with different settings
50
- * (in particular phases) such as 'start' / 'stop'. Using a returned Context from
51
- * a previous boot call allows DI to retrieve the same instances of Booters previously
52
- * used as they are bound using a CONTEXT scope. This is important as Booter instances
53
- * may maintain state.
54
- */
55
- async boot(execOptions, ctx) {
56
- const bootCtx = ctx !== null && ctx !== void 0 ? ctx : new context_1.Context(this.app);
57
- // Bind booters passed in as a part of BootOptions
58
- // We use _bindBooter so this Class can be used without the Mixin
59
- if (execOptions === null || execOptions === void 0 ? void 0 : execOptions.booters) {
60
- execOptions.booters.forEach(booter => mixins_1._bindBooter(this.app, booter));
61
- }
62
- // Determine the phases to be run. If a user set a phases filter, those
63
- // are selected otherwise we run the default phases (BOOTER_PHASES).
64
- const phases = execOptions
65
- ? execOptions.filter && execOptions.filter.phases
66
- ? execOptions.filter.phases
67
- : types_1.BOOTER_PHASES
68
- : types_1.BOOTER_PHASES;
69
- // Find booters registered to the BOOTERS_TAG by getting the bindings
70
- const bindings = bootCtx.findByTag(keys_1.BootTags.BOOTER);
71
- // Prefix length. +1 because of `.` => 'booters.'
72
- const prefixLength = keys_1.BootBindings.BOOTER_PREFIX.length + 1;
73
- // Names of all registered booters.
74
- const defaultBooterNames = bindings.map(binding => binding.key.slice(prefixLength));
75
- // Determining the booters to be run. If a user set a booters filter (class
76
- // names of booters that should be run), that is the value, otherwise it
77
- // is all the registered booters by default.
78
- const names = execOptions
79
- ? execOptions.filter && execOptions.filter.booters
80
- ? execOptions.filter.booters
81
- : defaultBooterNames
82
- : defaultBooterNames;
83
- // Filter bindings by names
84
- const filteredBindings = bindings.filter(binding => names.includes(binding.key.slice(prefixLength)));
85
- // Resolve Booter Instances
86
- const booterInsts = await context_1.resolveList(filteredBindings, binding =>
87
- // We cannot use Booter interface here because "filter.booters"
88
- // allows arbitrary string values, not only the phases defined
89
- // by Booter interface
90
- bootCtx.get(binding.key));
91
- // Run phases of booters
92
- for (const phase of phases) {
93
- for (const inst of booterInsts) {
94
- const instName = inst.constructor.name;
95
- if (inst[phase]) {
96
- debug(`${instName} phase: ${phase} starting.`);
97
- await inst[phase]();
98
- debug(`${instName} phase: ${phase} complete.`);
99
- }
100
- else {
101
- debug(`${instName} phase: ${phase} not implemented.`);
102
- }
61
+ // Determine the phases to be run. If a user set a phases filter, those
62
+ // are selected otherwise we run the default phases (BOOTER_PHASES).
63
+ const phases = (_b = (_a = execOptions === null || execOptions === void 0 ? void 0 : execOptions.filter) === null || _a === void 0 ? void 0 : _a.phases) !== null && _b !== void 0 ? _b : types_1.BOOTER_PHASES;
64
+ // Find booters registered to the BOOTERS_TAG by getting the bindings
65
+ const bindings = bootCtx.findByTag(keys_1.BootTags.BOOTER);
66
+ // Prefix length. +1 because of `.` => 'booters.'
67
+ const prefixLength = keys_1.BootBindings.BOOTER_PREFIX.length + 1;
68
+ // Names of all registered booters.
69
+ const defaultBooterNames = bindings.map(binding => binding.key.slice(prefixLength));
70
+ // Determining the booters to be run. If a user set a booters filter (class
71
+ // names of booters that should be run), that is the value, otherwise it
72
+ // is all the registered booters by default.
73
+ const names = execOptions
74
+ ? ((_c = execOptions.filter) === null || _c === void 0 ? void 0 : _c.booters) ? execOptions.filter.booters
75
+ : defaultBooterNames
76
+ : defaultBooterNames;
77
+ // Filter bindings by names
78
+ const filteredBindings = bindings.filter(binding => names.includes(binding.key.slice(prefixLength)));
79
+ // Resolve Booter Instances
80
+ const booterInsts = await core_1.resolveList(filteredBindings, binding =>
81
+ // We cannot use Booter interface here because "filter.booters"
82
+ // allows arbitrary string values, not only the phases defined
83
+ // by Booter interface
84
+ bootCtx.get(binding.key));
85
+ // Run phases of booters
86
+ for (const phase of phases) {
87
+ for (const inst of booterInsts) {
88
+ const instName = inst.constructor.name;
89
+ if (inst[phase]) {
90
+ debug(`${instName} phase: ${phase} starting.`);
91
+ await inst[phase]();
92
+ debug(`${instName} phase: ${phase} complete.`);
93
+ }
94
+ else {
95
+ debug(`${instName} phase: ${phase} not implemented.`);
103
96
  }
104
97
  }
105
- return bootCtx;
106
98
  }
107
- };
108
- Bootstrapper = tslib_1.__decorate([
109
- tslib_1.__param(0, context_1.inject(core_1.CoreBindings.APPLICATION_INSTANCE)),
110
- tslib_1.__param(1, context_1.inject(keys_1.BootBindings.PROJECT_ROOT)),
111
- tslib_1.__param(2, context_1.inject(keys_1.BootBindings.BOOT_OPTIONS, { optional: true })),
112
- tslib_1.__metadata("design:paramtypes", [Object, String, Object])
113
- ], Bootstrapper);
114
- return Bootstrapper;
115
- })();
99
+ return bootCtx;
100
+ }
101
+ };
102
+ Bootstrapper = tslib_1.__decorate([
103
+ tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_INSTANCE)),
104
+ tslib_1.__param(1, core_1.inject(keys_1.BootBindings.PROJECT_ROOT)),
105
+ tslib_1.__param(2, core_1.inject(keys_1.BootBindings.BOOT_OPTIONS, { optional: true })),
106
+ tslib_1.__metadata("design:paramtypes", [Object, String, Object])
107
+ ], Bootstrapper);
116
108
  exports.Bootstrapper = Bootstrapper;
117
109
  //# sourceMappingURL=bootstrapper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrapper.js","sourceRoot":"","sources":["../src/bootstrapper.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAA+D;AAC/D,yCAAyD;AACzD,0DAAgC;AAChC,+BAA6B;AAC7B,iCAA8C;AAC9C,qCAAqC;AACrC,mCAKiB;AAEjB,MAAM,KAAK,GAAG,eAAW,CAAC,4BAA4B,CAAC,CAAC;AAExD;;;;;;;;;;GAUG;AACH;IAAA,IAAa,YAAY,GAAzB,MAAa,YAAY;QACvB,YAEU,GAA2B,EACQ,WAAmB,EAEtD,cAA2B,EAAE;YAH7B,QAAG,GAAH,GAAG,CAAwB;YACQ,gBAAW,GAAX,WAAW,CAAQ;YAEtD,gBAAW,GAAX,WAAW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QAEF,2BAA2B;QAC3B,MAAM,WAAW,GAAG,MAAM,kBAAW,CAAC,gBAAgB,EAAE,OAAO,CAAC,EAAE;QAChE,+DAA+D;QAC/D,8DAA8D;QAC9D,sBAAsB;QACtB,OAAO,CAAC,GAAG,CAAyC,OAAO,CAAC,GAAG,CAAC,CACjE,CAAC;QAEF,wBAAwB;QACxB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;gBAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;gBACvC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE;oBACf,KAAK,CAAC,GAAG,QAAQ,WAAW,KAAK,YAAY,CAAC,CAAC;oBAC/C,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACpB,KAAK,CAAC,GAAG,QAAQ,WAAW,KAAK,YAAY,CAAC,CAAC;iBAChD;qBAAM;oBACL,KAAK,CAAC,GAAG,QAAQ,WAAW,KAAK,mBAAmB,CAAC,CAAC;iBACvD;aACF;SACF;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAhGY,YAAY;IAEpB,mBAAA,aAAM,CAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;IAEzC,mBAAA,aAAM,CAAC,mBAAY,CAAC,YAAY,CAAC,CAAA;IACjC,mBAAA,aAAM,CAAC,mBAAY,CAAC,YAAY,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;;GAL3C,YAAY,CAgGxB;AAhGY,oCAAY"}
package/dist/keys.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BindingKey } from '@loopback/context';
1
+ import { BindingKey } from '@loopback/core';
2
2
  import { Bootstrapper } from './bootstrapper';
3
3
  import { BootOptions } from './types';
4
4
  /**
package/dist/keys.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.BootTags = exports.BootBindings = void 0;
8
- const context_1 = require("@loopback/context");
8
+ const core_1 = require("@loopback/core");
9
9
  /**
10
10
  * Namespace for boot related binding keys
11
11
  */
@@ -14,15 +14,15 @@ var BootBindings;
14
14
  /**
15
15
  * Binding key for boot options
16
16
  */
17
- BootBindings.BOOT_OPTIONS = context_1.BindingKey.create('boot.options');
17
+ BootBindings.BOOT_OPTIONS = core_1.BindingKey.create('boot.options');
18
18
  /**
19
19
  * Binding key for determining project root directory
20
20
  */
21
- BootBindings.PROJECT_ROOT = context_1.BindingKey.create('boot.project_root');
21
+ BootBindings.PROJECT_ROOT = core_1.BindingKey.create('boot.project_root');
22
22
  /**
23
23
  * Binding key for binding the BootStrapper class
24
24
  */
25
- BootBindings.BOOTSTRAPPER_KEY = context_1.BindingKey.create('application.bootstrapper');
25
+ BootBindings.BOOTSTRAPPER_KEY = core_1.BindingKey.create('application.bootstrapper');
26
26
  BootBindings.BOOTER_PREFIX = 'booters';
27
27
  })(BootBindings = exports.BootBindings || (exports.BootBindings = {}));
28
28
  /**
package/dist/keys.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAA6C;AAI7C;;GAEG;AACH,IAAiB,YAAY,CAkB5B;AAlBD,WAAiB,YAAY;IAC3B;;OAEG;IACU,yBAAY,GAAG,oBAAU,CAAC,MAAM,CAAc,cAAc,CAAC,CAAC;IAC3E;;OAEG;IACU,yBAAY,GAAG,oBAAU,CAAC,MAAM,CAAS,mBAAmB,CAAC,CAAC;IAE3E;;OAEG;IACU,6BAAgB,GAAG,oBAAU,CAAC,MAAM,CAC/C,0BAA0B,CAC3B,CAAC;IAEW,0BAAa,GAAG,SAAS,CAAC;AACzC,CAAC,EAlBgB,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAkB5B;AAED;;GAEG;AACH,IAAiB,QAAQ,CAMxB;AAND,WAAiB,QAAQ;IACV,eAAM,GAAG,QAAQ,CAAC;IAC/B;;OAEG;IACU,mBAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC5C,CAAC,EANgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAMxB"}
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAA0C;AAI1C;;GAEG;AACH,IAAiB,YAAY,CAkB5B;AAlBD,WAAiB,YAAY;IAC3B;;OAEG;IACU,yBAAY,GAAG,iBAAU,CAAC,MAAM,CAAc,cAAc,CAAC,CAAC;IAC3E;;OAEG;IACU,yBAAY,GAAG,iBAAU,CAAC,MAAM,CAAS,mBAAmB,CAAC,CAAC;IAE3E;;OAEG;IACU,6BAAgB,GAAG,iBAAU,CAAC,MAAM,CAC/C,0BAA0B,CAC3B,CAAC;IAEW,0BAAa,GAAG,SAAS,CAAC;AACzC,CAAC,EAlBgB,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAkB5B;AAED;;GAEG;AACH,IAAiB,QAAQ,CAMxB;AAND,WAAiB,QAAQ;IACV,eAAM,GAAG,QAAQ,CAAC;IAC/B;;OAEG;IACU,mBAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC5C,CAAC,EANgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAMxB"}
@@ -1,8 +1,7 @@
1
- import { Binding, BindingFilter, BindingFromClassOptions, Constructor, Context } from '@loopback/context';
1
+ import { Binding, BindingFilter, BindingFromClassOptions, Constructor, Context } from '@loopback/core';
2
2
  import { Application, Component, MixinTarget } from '@loopback/core';
3
- import { Bootable, Booter, BootOptions } from '../types';
4
- import { BindingAddress, JSONObject, Provider, ContextSubscriptionManager, ContextEvent, Interceptor, InterceptorBindingOptions, ResolutionOptions, BindingKey, ValueOrPromise, ContextEventObserver, ContextObserver, Subscription, BindingComparator, ContextView, ResolutionSession, BindingCreationPolicy, ContextInspectOptions } from '@loopback/context';
5
- import { Server, ApplicationConfig, ApplicationMetadata, LifeCycleObserver, ServiceOptions } from '@loopback/core';
3
+ import { Bootable, Booter, BootOptions, InstanceWithBooters } from '../types';
4
+ import * as loopbackContext from '@loopback/core';
6
5
  export { Binding };
7
6
  /**
8
7
  * Mixin for @loopback/boot. This Mixin provides the following:
@@ -15,6 +14,11 @@ export { Binding };
15
14
  * - Provides the `booter()` convenience method to bind a Booter(s) to the Application
16
15
  * - Override `component()` to call `mountComponentBooters`
17
16
  * - Adds `mountComponentBooters` which binds Booters to the application from `component.booters[]`
17
+ *
18
+ * @param superClass - Application class
19
+ * @returns A new class that extends the super class with boot related methods
20
+ *
21
+ * @typeParam T - Type of the application class as the target for the mixin
18
22
  */
19
23
  export declare function BootMixin<T extends MixinTarget<Application>>(superClass: T): {
20
24
  new (...args: any[]): {
@@ -72,62 +76,68 @@ export declare function BootMixin<T extends MixinTarget<Application>>(superClass
72
76
  *
73
77
  * @param component - The component to mount booters of
74
78
  */
75
- mountComponentBooters(component: Constructor<{}>): void;
76
- readonly options: ApplicationConfig;
79
+ mountComponentBooters(componentInstanceOrClass: Constructor<unknown> | InstanceWithBooters): void;
80
+ readonly options: loopbackContext.ApplicationConfig;
77
81
  readonly state: string;
78
82
  controller: <T_1>(controllerCtor: Constructor<T_1>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_1>;
79
- server: <T_2 extends Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>;
80
- servers: <T_3 extends Server>(ctors: Constructor<T_3>[]) => Binding<any>[];
81
- getServer: <T_4 extends Server>(target: string | Constructor<T_4>) => Promise<T_4>;
83
+ server: <T_2 extends loopbackContext.Server>(ctor: Constructor<T_2>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_2>;
84
+ servers: <T_3 extends loopbackContext.Server>(ctors: Constructor<T_3>[]) => Binding<any>[];
85
+ getServer: <T_4 extends loopbackContext.Server>(target: string | Constructor<T_4>) => Promise<T_4>;
82
86
  start: () => Promise<void>;
83
87
  stop: () => Promise<void>;
84
- setMetadata: (metadata: ApplicationMetadata) => void;
85
- lifeCycleObserver: <T_5 extends LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>;
86
- service: <S>(cls: Constructor<S | Provider<S>>, nameOrOptions?: string | ServiceOptions | undefined) => Binding<S>;
87
- interceptor: (interceptor: Interceptor | Constructor<Provider<Interceptor>>, nameOrOptions?: string | InterceptorBindingOptions | undefined) => Binding<Interceptor>;
88
+ setMetadata: (metadata: loopbackContext.ApplicationMetadata) => void;
89
+ lifeCycleObserver: <T_5 extends loopbackContext.LifeCycleObserver>(ctor: Constructor<T_5>, nameOrOptions?: string | BindingFromClassOptions | undefined) => Binding<T_5>;
90
+ service: <S>(cls: Constructor<S | loopbackContext.Provider<S>>, nameOrOptions?: string | loopbackContext.ServiceOptions | undefined) => Binding<S>;
91
+ interceptor: (interceptor: loopbackContext.Interceptor | Constructor<loopbackContext.Provider<loopbackContext.Interceptor>>, nameOrOptions?: string | loopbackContext.InterceptorBindingOptions | undefined) => Binding<loopbackContext.Interceptor>;
88
92
  readonly name: string;
89
- readonly subscriptionManager: ContextSubscriptionManager;
93
+ readonly subscriptionManager: loopbackContext.ContextSubscriptionManager;
90
94
  readonly parent: Context | undefined;
91
- emitEvent: <T_6 extends ContextEvent>(type: string, event: T_6) => void;
95
+ emitEvent: <T_6 extends loopbackContext.ContextEvent>(type: string, event: T_6) => void;
92
96
  emitError: (err: unknown) => void;
93
- bind: <ValueType = any>(key: BindingAddress<ValueType>) => Binding<ValueType>;
97
+ bind: <ValueType = any>(key: loopbackContext.BindingAddress<ValueType>) => Binding<ValueType>;
94
98
  add: (binding: Binding<unknown>) => Application;
95
- configure: <ConfigValueType = any>(key?: string | BindingKey<unknown> | undefined) => Binding<ConfigValueType>;
96
- getConfigAsValueOrPromise: <ConfigValueType_1>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: ResolutionOptions | undefined) => ValueOrPromise<ConfigValueType_1 | undefined>;
97
- getConfig: <ConfigValueType_2>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
98
- getConfigSync: <ConfigValueType_3>(key: BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
99
- unbind: (key: BindingAddress<unknown>) => boolean;
100
- subscribe: (observer: ContextEventObserver) => Subscription;
101
- unsubscribe: (observer: ContextEventObserver) => boolean;
99
+ configure: <ConfigValueType = any>(key?: string | loopbackContext.BindingKey<unknown> | undefined) => Binding<ConfigValueType>;
100
+ getConfigAsValueOrPromise: <ConfigValueType_1>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ConfigValueType_1 | undefined>;
101
+ getConfig: <ConfigValueType_2>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => Promise<ConfigValueType_2 | undefined>;
102
+ getConfigSync: <ConfigValueType_3>(key: loopbackContext.BindingAddress<unknown>, propertyPath?: string | undefined, resolutionOptions?: loopbackContext.ResolutionOptions | undefined) => ConfigValueType_3 | undefined;
103
+ unbind: (key: loopbackContext.BindingAddress<unknown>) => boolean;
104
+ subscribe: (observer: loopbackContext.ContextEventObserver) => loopbackContext.Subscription;
105
+ unsubscribe: (observer: loopbackContext.ContextEventObserver) => boolean;
102
106
  close: () => void;
103
- isSubscribed: (observer: ContextObserver) => boolean;
104
- createView: <T_7 = unknown>(filter: BindingFilter, comparator?: BindingComparator | undefined) => ContextView<T_7>;
105
- contains: (key: BindingAddress<unknown>) => boolean;
106
- isBound: (key: BindingAddress<unknown>) => boolean;
107
- getOwnerContext: (key: BindingAddress<unknown>) => Context | undefined;
107
+ isSubscribed: (observer: loopbackContext.ContextObserver) => boolean;
108
+ createView: <T_7 = unknown>(filter: BindingFilter, comparator?: loopbackContext.BindingComparator | undefined) => loopbackContext.ContextView<T_7>;
109
+ contains: (key: loopbackContext.BindingAddress<unknown>) => boolean;
110
+ isBound: (key: loopbackContext.BindingAddress<unknown>) => boolean;
111
+ getOwnerContext: (key: loopbackContext.BindingAddress<unknown>) => Context | undefined;
108
112
  find: <ValueType_1 = any>(pattern?: string | RegExp | BindingFilter | undefined) => Readonly<Binding<ValueType_1>>[];
109
113
  findByTag: <ValueType_2 = any>(tagFilter: string | RegExp | Record<string, any>) => Readonly<Binding<ValueType_2>>[];
110
114
  get: {
111
- <ValueType_3>(keyWithPath: BindingAddress<ValueType_3>, session?: ResolutionSession | undefined): Promise<ValueType_3>;
112
- <ValueType_4>(keyWithPath: BindingAddress<ValueType_4>, options: ResolutionOptions): Promise<ValueType_4 | undefined>;
115
+ <ValueType_3>(keyWithPath: loopbackContext.BindingAddress<ValueType_3>, session?: loopbackContext.ResolutionSession | undefined): Promise<ValueType_3>;
116
+ <ValueType_4>(keyWithPath: loopbackContext.BindingAddress<ValueType_4>, options: loopbackContext.ResolutionOptions): Promise<ValueType_4 | undefined>;
113
117
  };
114
118
  getSync: {
115
- <ValueType_5>(keyWithPath: BindingAddress<ValueType_5>, session?: ResolutionSession | undefined): ValueType_5;
116
- <ValueType_6>(keyWithPath: BindingAddress<ValueType_6>, options?: ResolutionOptions | undefined): ValueType_6 | undefined;
119
+ <ValueType_5>(keyWithPath: loopbackContext.BindingAddress<ValueType_5>, session?: loopbackContext.ResolutionSession | undefined): ValueType_5;
120
+ <ValueType_6>(keyWithPath: loopbackContext.BindingAddress<ValueType_6>, options?: loopbackContext.ResolutionOptions | undefined): ValueType_6 | undefined;
117
121
  };
118
122
  getBinding: {
119
- <ValueType_7 = any>(key: BindingAddress<ValueType_7>): Binding<ValueType_7>;
120
- <ValueType_8>(key: BindingAddress<ValueType_8>, options?: {
123
+ <ValueType_7 = any>(key: loopbackContext.BindingAddress<ValueType_7>): Binding<ValueType_7>;
124
+ <ValueType_8>(key: loopbackContext.BindingAddress<ValueType_8>, options?: {
121
125
  optional?: boolean | undefined;
122
126
  } | undefined): Binding<ValueType_8> | undefined;
123
127
  };
124
- findOrCreateBinding: <T_8>(key: BindingAddress<T_8>, policy?: BindingCreationPolicy | undefined) => Binding<T_8>;
125
- getValueOrPromise: <ValueType_9>(keyWithPath: BindingAddress<ValueType_9>, optionsOrSession?: ResolutionSession | ResolutionOptions | undefined) => ValueOrPromise<ValueType_9 | undefined>;
126
- toJSON: () => JSONObject;
127
- inspect: (options?: ContextInspectOptions | undefined) => JSONObject;
128
+ findOrCreateBinding: <T_8>(key: loopbackContext.BindingAddress<T_8>, policy?: loopbackContext.BindingCreationPolicy | undefined) => Binding<T_8>;
129
+ getValueOrPromise: <ValueType_9>(keyWithPath: loopbackContext.BindingAddress<ValueType_9>, optionsOrSession?: loopbackContext.ResolutionSession | loopbackContext.ResolutionOptions | undefined) => loopbackContext.ValueOrPromise<ValueType_9 | undefined>;
130
+ toJSON: () => loopbackContext.JSONObject;
131
+ inspect: (options?: loopbackContext.ContextInspectOptions | undefined) => loopbackContext.JSONObject;
132
+ on: {
133
+ (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
134
+ (event: string | symbol, listener: (...args: any[]) => void): Application;
135
+ };
136
+ once: {
137
+ (eventName: "bind" | "unbind", listener: loopbackContext.ContextEventListener): Application;
138
+ (event: string | symbol, listener: (...args: any[]) => void): Application;
139
+ };
128
140
  addListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
129
- on: (event: string | symbol, listener: (...args: any[]) => void) => Application;
130
- once: (event: string | symbol, listener: (...args: any[]) => void) => Application;
131
141
  prependListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
132
142
  prependOnceListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
133
143
  removeListener: (event: string | symbol, listener: (...args: any[]) => void) => Application;
@@ -149,4 +159,5 @@ export declare function BootMixin<T extends MixinTarget<Application>>(superClass
149
159
  * @param ctx - The Context to bind the Booter Class
150
160
  * @param booterCls - Booter class to be bound
151
161
  */
152
- export declare function _bindBooter(ctx: Context, booterCls: Constructor<Booter>): Binding;
162
+ export declare function bindBooter(ctx: Context, booterCls: Constructor<Booter>): Binding;
163
+ export declare const _bindBooter: typeof bindBooter;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
- // Copyright IBM Corp. 2018,2019. All Rights Reserved.
2
+ // Copyright IBM Corp. 2018,2020. All Rights Reserved.
3
3
  // Node module: @loopback/boot
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports._bindBooter = exports.BootMixin = exports.Binding = void 0;
8
- const context_1 = require("@loopback/context");
9
- Object.defineProperty(exports, "Binding", { enumerable: true, get: function () { return context_1.Binding; } });
7
+ exports._bindBooter = exports.bindBooter = exports.BootMixin = exports.Binding = void 0;
8
+ const core_1 = require("@loopback/core");
9
+ Object.defineProperty(exports, "Binding", { enumerable: true, get: function () { return core_1.Binding; } });
10
+ const core_2 = require("@loopback/core");
10
11
  const boot_component_1 = require("../boot.component");
11
12
  const component_application_booter_1 = require("../booters/component-application.booter");
12
13
  const keys_1 = require("../keys");
@@ -21,6 +22,11 @@ const keys_1 = require("../keys");
21
22
  * - Provides the `booter()` convenience method to bind a Booter(s) to the Application
22
23
  * - Override `component()` to call `mountComponentBooters`
23
24
  * - Adds `mountComponentBooters` which binds Booters to the application from `component.booters[]`
25
+ *
26
+ * @param superClass - Application class
27
+ * @returns A new class that extends the super class with boot related methods
28
+ *
29
+ * @typeParam T - Type of the application class as the target for the mixin
24
30
  */
25
31
  function BootMixin(superClass) {
26
32
  return class extends superClass {
@@ -37,7 +43,7 @@ function BootMixin(superClass) {
37
43
  * Convenience method to call bootstrapper.boot() by resolving bootstrapper
38
44
  */
39
45
  async boot() {
40
- /* eslint-disable @typescript-eslint/ban-ts-ignore */
46
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
41
47
  // A workaround to access protected Application methods
42
48
  const self = this;
43
49
  if (this.state === 'booting') {
@@ -57,7 +63,7 @@ function BootMixin(superClass) {
57
63
  await bootstrapper.boot();
58
64
  // @ts-ignore
59
65
  this.setState('booted');
60
- /* eslint-enable @typescript-eslint/ban-ts-ignore */
66
+ /* eslint-enable @typescript-eslint/ban-ts-comment */
61
67
  }
62
68
  /**
63
69
  * Given a N number of Booter Classes, this method binds them using the
@@ -71,7 +77,7 @@ function BootMixin(superClass) {
71
77
  * ```
72
78
  */
73
79
  booters(...booterCls) {
74
- return booterCls.map(cls => _bindBooter(this, cls));
80
+ return booterCls.map(cls => bindBooter(this, cls));
75
81
  }
76
82
  /**
77
83
  * Register a booter to boot a sub-application. See
@@ -107,11 +113,12 @@ function BootMixin(superClass) {
107
113
  */
108
114
  // Unfortunately, TypeScript does not allow overriding methods inherited
109
115
  // from mapped types. https://github.com/microsoft/TypeScript/issues/38496
110
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
116
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
111
117
  // @ts-ignore
112
118
  component(componentCtor, nameOrOptions) {
113
119
  const binding = super.component(componentCtor, nameOrOptions);
114
- this.mountComponentBooters(componentCtor);
120
+ const instance = this.getSync(binding.key);
121
+ this.mountComponentBooters(instance);
115
122
  return binding;
116
123
  }
117
124
  /**
@@ -121,11 +128,24 @@ function BootMixin(superClass) {
121
128
  *
122
129
  * @param component - The component to mount booters of
123
130
  */
124
- mountComponentBooters(component) {
125
- const componentKey = `components.${component.name}`;
126
- const compInstance = this.getSync(componentKey);
127
- if (compInstance.booters) {
128
- this.booters(...compInstance.booters);
131
+ mountComponentBooters(componentInstanceOrClass) {
132
+ const componentInstance = resolveComponentInstance(this);
133
+ if (componentInstance.booters) {
134
+ this.booters(...componentInstance.booters);
135
+ }
136
+ /**
137
+ * Determines if componentInstanceOrClass is an instance of a component,
138
+ * or a class that needs to be instantiated from context.
139
+ * @param ctx
140
+ */
141
+ function resolveComponentInstance(ctx) {
142
+ if (typeof componentInstanceOrClass !== 'function') {
143
+ return componentInstanceOrClass;
144
+ }
145
+ // TODO(semver-major) @bajtos: Reminder to remove this on the next major release
146
+ const componentName = componentInstanceOrClass.name;
147
+ const componentKey = `${core_2.CoreBindings.COMPONENTS}.${componentName}`;
148
+ return ctx.getSync(componentKey);
129
149
  }
130
150
  }
131
151
  };
@@ -138,10 +158,10 @@ exports.BootMixin = BootMixin;
138
158
  * @param ctx - The Context to bind the Booter Class
139
159
  * @param booterCls - Booter class to be bound
140
160
  */
141
- function _bindBooter(ctx, booterCls) {
142
- const binding = context_1.createBindingFromClass(booterCls, {
161
+ function bindBooter(ctx, booterCls) {
162
+ const binding = core_1.createBindingFromClass(booterCls, {
143
163
  namespace: keys_1.BootBindings.BOOTER_PREFIX,
144
- defaultScope: context_1.BindingScope.SINGLETON,
164
+ defaultScope: core_1.BindingScope.SINGLETON,
145
165
  }).tag(keys_1.BootTags.BOOTER);
146
166
  ctx.add(binding);
147
167
  /**
@@ -155,5 +175,7 @@ function _bindBooter(ctx, booterCls) {
155
175
  }
156
176
  return binding;
157
177
  }
158
- exports._bindBooter = _bindBooter;
178
+ exports.bindBooter = bindBooter;
179
+ // eslint-disable-next-line @typescript-eslint/naming-convention
180
+ exports._bindBooter = bindBooter; // For backward-compatibility
159
181
  //# sourceMappingURL=boot.mixin.js.map