@alterior/runtime 3.13.3 → 3.13.4

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 (65) hide show
  1. package/dist/app-options.d.ts +65 -65
  2. package/dist/app-options.js +26 -26
  3. package/dist/app-options.js.map +1 -1
  4. package/dist/application.d.ts +52 -52
  5. package/dist/application.js +172 -171
  6. package/dist/application.js.map +1 -1
  7. package/dist/args.d.ts +7 -7
  8. package/dist/args.js +13 -13
  9. package/dist/expose.d.ts +12 -12
  10. package/dist/expose.d.ts.map +1 -1
  11. package/dist/expose.js +36 -36
  12. package/dist/expose.js.map +1 -1
  13. package/dist/index.d.ts +9 -9
  14. package/dist/index.js +12 -12
  15. package/dist/lifecycle.d.ts +24 -24
  16. package/dist/lifecycle.js +2 -2
  17. package/dist/module.test.d.ts +1 -1
  18. package/dist/modules.d.ts +120 -120
  19. package/dist/modules.js +282 -282
  20. package/dist/modules.js.map +1 -1
  21. package/dist/reflector.d.ts +123 -123
  22. package/dist/reflector.js +306 -306
  23. package/dist/reflector.js.map +1 -1
  24. package/dist/roles.service.d.ts +79 -79
  25. package/dist/roles.service.js +124 -124
  26. package/dist/roles.service.js.map +1 -1
  27. package/dist/service.d.ts +24 -24
  28. package/dist/service.js +19 -19
  29. package/dist/service.js.map +1 -1
  30. package/dist/test.d.ts +1 -1
  31. package/dist.esm/app-options.d.ts +65 -65
  32. package/dist.esm/app-options.js +23 -23
  33. package/dist.esm/app-options.js.map +1 -1
  34. package/dist.esm/application.d.ts +52 -52
  35. package/dist.esm/application.js +167 -166
  36. package/dist.esm/application.js.map +1 -1
  37. package/dist.esm/args.d.ts +7 -7
  38. package/dist.esm/args.js +9 -9
  39. package/dist.esm/expose.d.ts +12 -12
  40. package/dist.esm/expose.d.ts.map +1 -1
  41. package/dist.esm/expose.js +31 -31
  42. package/dist.esm/expose.js.map +1 -1
  43. package/dist.esm/index.d.ts +9 -9
  44. package/dist.esm/index.js +9 -9
  45. package/dist.esm/lifecycle.d.ts +24 -24
  46. package/dist.esm/lifecycle.js +1 -1
  47. package/dist.esm/module.test.d.ts +1 -1
  48. package/dist.esm/modules.d.ts +120 -120
  49. package/dist.esm/modules.js +276 -276
  50. package/dist.esm/modules.js.map +1 -1
  51. package/dist.esm/reflector.d.ts +123 -123
  52. package/dist.esm/reflector.js +296 -296
  53. package/dist.esm/reflector.js.map +1 -1
  54. package/dist.esm/roles.service.d.ts +79 -79
  55. package/dist.esm/roles.service.js +121 -121
  56. package/dist.esm/roles.service.js.map +1 -1
  57. package/dist.esm/service.d.ts +24 -24
  58. package/dist.esm/service.js +15 -15
  59. package/dist.esm/service.js.map +1 -1
  60. package/dist.esm/test.d.ts +1 -1
  61. package/package.json +9 -9
  62. package/src/application.ts +1 -1
  63. package/tsconfig.esm.tsbuildinfo +1 -0
  64. package/tsconfig.json +0 -2
  65. package/tsconfig.tsbuildinfo +1 -5546
@@ -1,66 +1,66 @@
1
- import { Annotation } from '@alterior/annotations';
2
- import { Injector, Provider } from '@alterior/di';
3
- export interface ApplicationOptions {
4
- /**
5
- * Specify a human readable name for your application.
6
- */
7
- name?: string;
8
- /**
9
- * Version of the service
10
- */
11
- version?: string;
12
- /**
13
- * The computer-readable name for your application. Should match your NPM package name.
14
- */
15
- packageName?: string;
16
- /**
17
- * A long-form description for your application, when necessary. If you implement only one,
18
- * implement summary instead.
19
- */
20
- description?: string;
21
- /**
22
- * A shorter-form description for your application, when necessary. If you implement only one,
23
- * implement this instead of description.
24
- */
25
- summary?: string;
26
- /**
27
- * A set of string tags related to your application.
28
- */
29
- tags?: string[];
30
- group?: string;
31
- /**
32
- * Enable verbose console logging for Alterior
33
- */
34
- verbose?: boolean;
35
- /**
36
- * Whether to start the service immediately on startup.
37
- * Defaults to true.
38
- */
39
- autostart?: boolean;
40
- /**
41
- * Turn off all console output
42
- */
43
- silent?: boolean;
44
- /**
45
- * Additional dependency injection providers to include in the application's injector.
46
- */
47
- providers?: Provider[];
48
- /**
49
- * An injector to use as the parent of the application injector. Optional, useful when doing more complex
50
- * application bootstrapping.
51
- */
52
- parentInjector?: Injector;
53
- }
54
- /**
55
- * Used to attach an ApplicationOptions object onto a class definition.
56
- */
57
- export declare class AppOptionsAnnotation extends Annotation {
58
- readonly options?: ApplicationOptions;
59
- constructor(options?: ApplicationOptions);
60
- }
61
- /**
62
- * Use this decorator to define the options for your application,
63
- * either on the entry module, or service class when using `@alterior/web-server`.
64
- */
65
- export declare const AppOptions: (options?: ApplicationOptions) => ClassDecorator;
1
+ import { Annotation } from '@alterior/annotations';
2
+ import { Injector, Provider } from '@alterior/di';
3
+ export interface ApplicationOptions {
4
+ /**
5
+ * Specify a human readable name for your application.
6
+ */
7
+ name?: string;
8
+ /**
9
+ * Version of the service
10
+ */
11
+ version?: string;
12
+ /**
13
+ * The computer-readable name for your application. Should match your NPM package name.
14
+ */
15
+ packageName?: string;
16
+ /**
17
+ * A long-form description for your application, when necessary. If you implement only one,
18
+ * implement summary instead.
19
+ */
20
+ description?: string;
21
+ /**
22
+ * A shorter-form description for your application, when necessary. If you implement only one,
23
+ * implement this instead of description.
24
+ */
25
+ summary?: string;
26
+ /**
27
+ * A set of string tags related to your application.
28
+ */
29
+ tags?: string[];
30
+ group?: string;
31
+ /**
32
+ * Enable verbose console logging for Alterior
33
+ */
34
+ verbose?: boolean;
35
+ /**
36
+ * Whether to start the service immediately on startup.
37
+ * Defaults to true.
38
+ */
39
+ autostart?: boolean;
40
+ /**
41
+ * Turn off all console output
42
+ */
43
+ silent?: boolean;
44
+ /**
45
+ * Additional dependency injection providers to include in the application's injector.
46
+ */
47
+ providers?: Provider[];
48
+ /**
49
+ * An injector to use as the parent of the application injector. Optional, useful when doing more complex
50
+ * application bootstrapping.
51
+ */
52
+ parentInjector?: Injector;
53
+ }
54
+ /**
55
+ * Used to attach an ApplicationOptions object onto a class definition.
56
+ */
57
+ export declare class AppOptionsAnnotation extends Annotation {
58
+ readonly options?: ApplicationOptions;
59
+ constructor(options?: ApplicationOptions);
60
+ }
61
+ /**
62
+ * Use this decorator to define the options for your application,
63
+ * either on the entry module, or service class when using `@alterior/web-server`.
64
+ */
65
+ export declare const AppOptions: (options?: ApplicationOptions) => ClassDecorator;
66
66
  //# sourceMappingURL=app-options.d.ts.map
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppOptions = exports.AppOptionsAnnotation = void 0;
4
- const tslib_1 = require("tslib");
5
- const annotations_1 = require("@alterior/annotations");
6
- /**
7
- * Used to attach an ApplicationOptions object onto a class definition.
8
- */
9
- let AppOptionsAnnotation = class AppOptionsAnnotation extends annotations_1.Annotation {
10
- constructor(options) {
11
- super();
12
- this.options = options;
13
- }
14
- };
15
- AppOptionsAnnotation = tslib_1.__decorate([
16
- (0, annotations_1.MetadataName)('@alterior/di:Application'),
17
- tslib_1.__metadata("design:paramtypes", [Object])
18
- ], AppOptionsAnnotation);
19
- exports.AppOptionsAnnotation = AppOptionsAnnotation;
20
- /**
21
- * Use this decorator to define the options for your application,
22
- * either on the entry module, or service class when using `@alterior/web-server`.
23
- */
24
- exports.AppOptions = AppOptionsAnnotation.decorator({
25
- validTargets: ['class']
26
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppOptions = exports.AppOptionsAnnotation = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const annotations_1 = require("@alterior/annotations");
6
+ /**
7
+ * Used to attach an ApplicationOptions object onto a class definition.
8
+ */
9
+ let AppOptionsAnnotation = class AppOptionsAnnotation extends annotations_1.Annotation {
10
+ constructor(options) {
11
+ super();
12
+ this.options = options;
13
+ }
14
+ };
15
+ exports.AppOptionsAnnotation = AppOptionsAnnotation;
16
+ exports.AppOptionsAnnotation = AppOptionsAnnotation = tslib_1.__decorate([
17
+ (0, annotations_1.MetadataName)('@alterior/di:Application'),
18
+ tslib_1.__metadata("design:paramtypes", [Object])
19
+ ], AppOptionsAnnotation);
20
+ /**
21
+ * Use this decorator to define the options for your application,
22
+ * either on the entry module, or service class when using `@alterior/web-server`.
23
+ */
24
+ exports.AppOptions = AppOptionsAnnotation.decorator({
25
+ validTargets: ['class']
26
+ });
27
27
  //# sourceMappingURL=app-options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-options.js","sourceRoot":"","sources":["../src/app-options.ts"],"names":[],"mappings":";;;;AAAA,uDAAsF;AAmEtF;;GAEG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,wBAAU;IACnD,YAAqB,OAA4B;QAChD,KAAK,EAAE,CAAC;QADY,YAAO,GAAP,OAAO,CAAqB;IAEjD,CAAC;CACD,CAAA;AAJY,oBAAoB;IADhC,IAAA,0BAAY,EAAC,0BAA0B,CAAC;;GAC5B,oBAAoB,CAIhC;AAJY,oDAAoB;AAMjC;;;GAGG;AACU,QAAA,UAAU,GAAG,oBAAoB,CAAC,SAAS,CAAC;IACxD,YAAY,EAAE,CAAC,OAAO,CAAC;CACvB,CAAC,CAAC"}
1
+ {"version":3,"file":"app-options.js","sourceRoot":"","sources":["../src/app-options.ts"],"names":[],"mappings":";;;;AAAA,uDAAsF;AAmEtF;;GAEG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,wBAAU;IACnD,YAAqB,OAA4B;QAChD,KAAK,EAAE,CAAC;QADY,YAAO,GAAP,OAAO,CAAqB;IAEjD,CAAC;CACD,CAAA;AAJY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,0BAAY,EAAC,0BAA0B,CAAC;;GAC5B,oBAAoB,CAIhC;AAED;;;GAGG;AACU,QAAA,UAAU,GAAG,oBAAoB,CAAC,SAAS,CAAC;IACxD,YAAY,EAAE,CAAC,OAAO,CAAC;CACvB,CAAC,CAAC"}
@@ -1,53 +1,53 @@
1
- import 'reflect-metadata';
2
- import { ApplicationOptions } from './app-options';
3
- import { Runtime } from './modules';
4
- export declare class ApplicationOptionsRef {
5
- constructor(options: ApplicationOptions);
6
- readonly options: ApplicationOptions;
7
- }
8
- /**
9
- * Represents the current runtime execution context.
10
- * This is exposed via a zone-local variable, and the Runtime
11
- * populates it with useful information as it becomes available.
12
- */
13
- export declare class ExecutionContext {
14
- /**
15
- * Retrieve the Alterior application which is currently being executed.
16
- * If an application has not been bootstrapped yet, the value is null.
17
- */
18
- application: Application;
19
- static readonly ZONE_LOCAL_NAME = "@alterior/runtime:ExecutionContext";
20
- /**
21
- * Get the current execution context, if any.
22
- */
23
- static get current(): ExecutionContext;
24
- /**
25
- * Execute the given function in a new zone which has
26
- * this ExecutionContext instance as the current execution context.
27
- */
28
- run<T>(callback: () => Promise<T>): Promise<T>;
29
- runSync<T>(callback: () => T): T;
30
- }
31
- /**
32
- * Handles bootstrapping the application.
33
- */
34
- export declare class Application {
35
- readonly runtime: Runtime;
36
- private _optionsRef;
37
- private _args;
38
- start(): void;
39
- stop(): void;
40
- get injector(): import("@alterior/di").Injector;
41
- inject<T>(ctor: {
42
- new (...args: any[]): T;
43
- }, notFoundValue?: T): T;
44
- get args(): string[];
45
- get options(): ApplicationOptions;
46
- private static loadOptions;
47
- private static validateEntryModule;
48
- /**
49
- * Bootstrap an Alterior application.
50
- */
51
- static bootstrap(entryModule: Function, options?: ApplicationOptions): Application;
52
- }
1
+ import 'reflect-metadata';
2
+ import { ApplicationOptions } from './app-options';
3
+ import { Runtime } from './modules';
4
+ export declare class ApplicationOptionsRef {
5
+ constructor(options: ApplicationOptions);
6
+ readonly options: ApplicationOptions;
7
+ }
8
+ /**
9
+ * Represents the current runtime execution context.
10
+ * This is exposed via a zone-local variable, and the Runtime
11
+ * populates it with useful information as it becomes available.
12
+ */
13
+ export declare class ExecutionContext {
14
+ /**
15
+ * Retrieve the Alterior application which is currently being executed.
16
+ * If an application has not been bootstrapped yet, the value is null.
17
+ */
18
+ application: Application;
19
+ static readonly ZONE_LOCAL_NAME = "@alterior/runtime:ExecutionContext";
20
+ /**
21
+ * Get the current execution context, if any.
22
+ */
23
+ static get current(): ExecutionContext;
24
+ /**
25
+ * Execute the given function in a new zone which has
26
+ * this ExecutionContext instance as the current execution context.
27
+ */
28
+ run<T>(callback: () => Promise<T>): Promise<T>;
29
+ runSync<T>(callback: () => T): T;
30
+ }
31
+ /**
32
+ * Handles bootstrapping the application.
33
+ */
34
+ export declare class Application {
35
+ readonly runtime: Runtime;
36
+ private _optionsRef;
37
+ private _args;
38
+ start(): void;
39
+ stop(): void;
40
+ get injector(): import("@alterior/di").Injector;
41
+ inject<T>(ctor: {
42
+ new (...args: any[]): T;
43
+ }, notFoundValue?: T): T;
44
+ get args(): string[];
45
+ get options(): ApplicationOptions;
46
+ private static loadOptions;
47
+ private static validateEntryModule;
48
+ /**
49
+ * Bootstrap an Alterior application.
50
+ */
51
+ static bootstrap(entryModule: Function, options?: ApplicationOptions): Application;
52
+ }
53
53
  //# sourceMappingURL=application.d.ts.map
@@ -1,172 +1,173 @@
1
- "use strict";
2
- var Application_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Application = exports.ExecutionContext = exports.ApplicationOptionsRef = void 0;
5
- const tslib_1 = require("tslib");
6
- require("reflect-metadata");
7
- const common_1 = require("@alterior/common");
8
- const di_1 = require("@alterior/di");
9
- const app_options_1 = require("./app-options");
10
- const args_1 = require("./args");
11
- const modules_1 = require("./modules");
12
- const roles_service_1 = require("./roles.service");
13
- class ApplicationOptionsRef {
14
- constructor(options) {
15
- this.options = Object.assign({}, options);
16
- }
17
- }
18
- exports.ApplicationOptionsRef = ApplicationOptionsRef;
19
- /**
20
- * Represents the current runtime execution context.
21
- * This is exposed via a zone-local variable, and the Runtime
22
- * populates it with useful information as it becomes available.
23
- */
24
- class ExecutionContext {
25
- constructor() {
26
- /**
27
- * Retrieve the Alterior application which is currently being executed.
28
- * If an application has not been bootstrapped yet, the value is null.
29
- */
30
- this.application = null;
31
- }
32
- /**
33
- * Get the current execution context, if any.
34
- */
35
- static get current() {
36
- return Zone.current.get(ExecutionContext.ZONE_LOCAL_NAME);
37
- }
38
- /**
39
- * Execute the given function in a new zone which has
40
- * this ExecutionContext instance as the current execution context.
41
- */
42
- run(callback) {
43
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
- let zone = Zone.current.fork({
45
- name: `AlteriorExecutionContext`,
46
- properties: {
47
- [ExecutionContext.ZONE_LOCAL_NAME]: this
48
- }
49
- });
50
- return yield zone.run(() => callback());
51
- });
52
- }
53
- runSync(callback) {
54
- let zone = Zone.current.fork({
55
- name: `AlteriorExecutionContext`,
56
- properties: {
57
- [ExecutionContext.ZONE_LOCAL_NAME]: this
58
- }
59
- });
60
- return zone.run(() => callback());
61
- }
62
- }
63
- exports.ExecutionContext = ExecutionContext;
64
- ExecutionContext.ZONE_LOCAL_NAME = '@alterior/runtime:ExecutionContext';
65
- /**
66
- * Handles bootstrapping the application.
67
- */
68
- let Application = Application_1 = class Application {
69
- constructor() {
70
- this.runtime = (0, di_1.inject)(modules_1.Runtime);
71
- this._optionsRef = (0, di_1.inject)(ApplicationOptionsRef);
72
- this._args = (0, di_1.inject)(args_1.ApplicationArgs);
73
- }
74
- start() {
75
- this.runtime.start();
76
- }
77
- stop() {
78
- this.runtime.stop();
79
- }
80
- get injector() {
81
- return this.runtime.injector;
82
- }
83
- inject(ctor, notFoundValue) {
84
- return this.injector.get(ctor, notFoundValue);
85
- }
86
- get args() {
87
- return this._args.get();
88
- }
89
- get options() {
90
- return this._optionsRef.options;
91
- }
92
- static loadOptions(entryModule, bootstrapOptions) {
93
- // Read an @AppOptions() decorator if any, and merge providers from it
94
- // into the bootstrapped providers
95
- let appOptionsAnnotation = app_options_1.AppOptionsAnnotation.getForClass(entryModule);
96
- let appProvidedOptions = appOptionsAnnotation ? appOptionsAnnotation.options : {} || {};
97
- return Object.assign({
98
- version: '0.0.0',
99
- verbose: false,
100
- silent: false,
101
- autostart: true,
102
- providers: []
103
- }, appProvidedOptions, bootstrapOptions);
104
- }
105
- static validateEntryModule(module) {
106
- if (typeof module !== 'function') {
107
- throw new Error(`You must pass a Module class as the first parameter `
108
- + `to bootstrap(). You provided: `
109
- + `${typeof module} with value '${module}'`);
110
- }
111
- let moduleMetadata = di_1.ModuleAnnotation.getForClass(module);
112
- if (!moduleMetadata)
113
- throw new Error(`You must pass a module class decorated by @Module()`);
114
- }
115
- /**
116
- * Bootstrap an Alterior application.
117
- */
118
- static bootstrap(entryModule, options) {
119
- let executionContext = new ExecutionContext();
120
- return executionContext.runSync(() => {
121
- var _a;
122
- this.validateEntryModule(entryModule);
123
- options = this.loadOptions(entryModule, options);
124
- let runtime = new modules_1.Runtime(entryModule);
125
- let providers = [
126
- args_1.ApplicationArgs,
127
- roles_service_1.RolesService,
128
- common_1.Environment,
129
- common_1.Time
130
- ];
131
- runtime.contributeProviders(providers);
132
- providers.push({
133
- provide: ApplicationOptionsRef,
134
- useValue: new ApplicationOptionsRef(options)
135
- });
136
- providers.push(Application_1);
137
- providers.push((_a = options.providers) !== null && _a !== void 0 ? _a : []);
138
- runtime.providers = providers;
139
- let injector;
140
- try {
141
- injector = di_1.ReflectiveInjector.resolveAndCreate(providers, options.parentInjector);
142
- }
143
- catch (e) {
144
- console.error(`Failed to resolve injector:`);
145
- console.error(e);
146
- console.error(`Providers:`);
147
- console.dir(providers);
148
- console.error(`Modules:`);
149
- console.dir(runtime.definitions);
150
- throw e;
151
- }
152
- injector.get(roles_service_1.RolesService).silent = options.silent;
153
- runtime.load(injector);
154
- executionContext.application = runtime.getService(Application_1);
155
- runtime.fireEvent('OnInit');
156
- runtime.configure();
157
- if (runtime.selfTest) {
158
- console.log(`[Self Test] ✔ Looks good!`);
159
- process.exit(0);
160
- }
161
- if (options.autostart)
162
- runtime.start();
163
- runtime.fireEvent('AfterStart');
164
- return executionContext.application;
165
- });
166
- }
167
- };
168
- Application = Application_1 = tslib_1.__decorate([
169
- (0, di_1.Injectable)()
170
- ], Application);
171
- exports.Application = Application;
1
+ "use strict";
2
+ var Application_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Application = exports.ExecutionContext = exports.ApplicationOptionsRef = void 0;
5
+ const tslib_1 = require("tslib");
6
+ require("reflect-metadata");
7
+ const common_1 = require("@alterior/common");
8
+ const di_1 = require("@alterior/di");
9
+ const app_options_1 = require("./app-options");
10
+ const args_1 = require("./args");
11
+ const modules_1 = require("./modules");
12
+ const roles_service_1 = require("./roles.service");
13
+ class ApplicationOptionsRef {
14
+ constructor(options) {
15
+ this.options = Object.assign({}, options);
16
+ }
17
+ }
18
+ exports.ApplicationOptionsRef = ApplicationOptionsRef;
19
+ /**
20
+ * Represents the current runtime execution context.
21
+ * This is exposed via a zone-local variable, and the Runtime
22
+ * populates it with useful information as it becomes available.
23
+ */
24
+ class ExecutionContext {
25
+ constructor() {
26
+ /**
27
+ * Retrieve the Alterior application which is currently being executed.
28
+ * If an application has not been bootstrapped yet, the value is null.
29
+ */
30
+ this.application = null;
31
+ }
32
+ /**
33
+ * Get the current execution context, if any.
34
+ */
35
+ static get current() {
36
+ return Zone.current.get(ExecutionContext.ZONE_LOCAL_NAME);
37
+ }
38
+ /**
39
+ * Execute the given function in a new zone which has
40
+ * this ExecutionContext instance as the current execution context.
41
+ */
42
+ run(callback) {
43
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
+ let zone = Zone.current.fork({
45
+ name: `AlteriorExecutionContext`,
46
+ properties: {
47
+ [ExecutionContext.ZONE_LOCAL_NAME]: this
48
+ }
49
+ });
50
+ return yield zone.run(() => callback());
51
+ });
52
+ }
53
+ runSync(callback) {
54
+ let zone = Zone.current.fork({
55
+ name: `AlteriorExecutionContext`,
56
+ properties: {
57
+ [ExecutionContext.ZONE_LOCAL_NAME]: this
58
+ }
59
+ });
60
+ return zone.run(() => callback());
61
+ }
62
+ }
63
+ exports.ExecutionContext = ExecutionContext;
64
+ ExecutionContext.ZONE_LOCAL_NAME = '@alterior/runtime:ExecutionContext';
65
+ /**
66
+ * Handles bootstrapping the application.
67
+ */
68
+ let Application = Application_1 = class Application {
69
+ constructor() {
70
+ this.runtime = (0, di_1.inject)(modules_1.Runtime);
71
+ this._optionsRef = (0, di_1.inject)(ApplicationOptionsRef);
72
+ this._args = (0, di_1.inject)(args_1.ApplicationArgs);
73
+ }
74
+ start() {
75
+ this.runtime.start();
76
+ }
77
+ stop() {
78
+ this.runtime.stop();
79
+ }
80
+ get injector() {
81
+ return this.runtime.injector;
82
+ }
83
+ inject(ctor, notFoundValue) {
84
+ return this.injector.get(ctor, notFoundValue);
85
+ }
86
+ get args() {
87
+ return this._args.get();
88
+ }
89
+ get options() {
90
+ return this._optionsRef.options;
91
+ }
92
+ static loadOptions(entryModule, bootstrapOptions) {
93
+ // Read an @AppOptions() decorator if any, and merge providers from it
94
+ // into the bootstrapped providers
95
+ var _a;
96
+ let appOptionsAnnotation = app_options_1.AppOptionsAnnotation.getForClass(entryModule);
97
+ let appProvidedOptions = (_a = appOptionsAnnotation === null || appOptionsAnnotation === void 0 ? void 0 : appOptionsAnnotation.options) !== null && _a !== void 0 ? _a : {};
98
+ return Object.assign({
99
+ version: '0.0.0',
100
+ verbose: false,
101
+ silent: false,
102
+ autostart: true,
103
+ providers: []
104
+ }, appProvidedOptions, bootstrapOptions);
105
+ }
106
+ static validateEntryModule(module) {
107
+ if (typeof module !== 'function') {
108
+ throw new Error(`You must pass a Module class as the first parameter `
109
+ + `to bootstrap(). You provided: `
110
+ + `${typeof module} with value '${module}'`);
111
+ }
112
+ let moduleMetadata = di_1.ModuleAnnotation.getForClass(module);
113
+ if (!moduleMetadata)
114
+ throw new Error(`You must pass a module class decorated by @Module()`);
115
+ }
116
+ /**
117
+ * Bootstrap an Alterior application.
118
+ */
119
+ static bootstrap(entryModule, options) {
120
+ let executionContext = new ExecutionContext();
121
+ return executionContext.runSync(() => {
122
+ var _a;
123
+ this.validateEntryModule(entryModule);
124
+ options = this.loadOptions(entryModule, options);
125
+ let runtime = new modules_1.Runtime(entryModule);
126
+ let providers = [
127
+ args_1.ApplicationArgs,
128
+ roles_service_1.RolesService,
129
+ common_1.Environment,
130
+ common_1.Time
131
+ ];
132
+ runtime.contributeProviders(providers);
133
+ providers.push({
134
+ provide: ApplicationOptionsRef,
135
+ useValue: new ApplicationOptionsRef(options)
136
+ });
137
+ providers.push(Application_1);
138
+ providers.push((_a = options.providers) !== null && _a !== void 0 ? _a : []);
139
+ runtime.providers = providers;
140
+ let injector;
141
+ try {
142
+ injector = di_1.ReflectiveInjector.resolveAndCreate(providers, options.parentInjector);
143
+ }
144
+ catch (e) {
145
+ console.error(`Failed to resolve injector:`);
146
+ console.error(e);
147
+ console.error(`Providers:`);
148
+ console.dir(providers);
149
+ console.error(`Modules:`);
150
+ console.dir(runtime.definitions);
151
+ throw e;
152
+ }
153
+ injector.get(roles_service_1.RolesService).silent = options.silent;
154
+ runtime.load(injector);
155
+ executionContext.application = runtime.getService(Application_1);
156
+ runtime.fireEvent('OnInit');
157
+ runtime.configure();
158
+ if (runtime.selfTest) {
159
+ console.log(`[Self Test] ✔ Looks good!`);
160
+ process.exit(0);
161
+ }
162
+ if (options.autostart)
163
+ runtime.start();
164
+ runtime.fireEvent('AfterStart');
165
+ return executionContext.application;
166
+ });
167
+ }
168
+ };
169
+ exports.Application = Application;
170
+ exports.Application = Application = Application_1 = tslib_1.__decorate([
171
+ (0, di_1.Injectable)()
172
+ ], Application);
172
173
  //# sourceMappingURL=application.js.map