async-injection 1.5.1 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +70 -61
- package/License.txt +1 -1
- package/ReadMe.md +2 -3
- package/lib/cjs/async-factory-provider.d.ts +4 -4
- package/lib/cjs/async-factory-provider.js +4 -4
- package/lib/cjs/async-factory-provider.js.map +1 -1
- package/lib/cjs/bindable-provider.d.ts +3 -3
- package/lib/cjs/bindable-provider.js +5 -5
- package/lib/cjs/bindable-provider.js.map +1 -1
- package/lib/cjs/binder.d.ts +2 -2
- package/lib/cjs/binder.js.map +1 -1
- package/lib/cjs/class-provider.d.ts +3 -3
- package/lib/cjs/class-provider.js +21 -21
- package/lib/cjs/class-provider.js.map +1 -1
- package/lib/cjs/constant-provider.d.ts +2 -2
- package/lib/cjs/constant-provider.js +4 -4
- package/lib/cjs/constant-provider.js.map +1 -1
- package/lib/cjs/container.d.ts +5 -5
- package/lib/cjs/container.js +18 -18
- package/lib/cjs/container.js.map +1 -1
- package/lib/cjs/decorators.d.ts +1 -1
- package/lib/cjs/decorators.js +13 -13
- package/lib/cjs/decorators.js.map +1 -1
- package/lib/cjs/index.d.ts +4 -4
- package/lib/cjs/index.js +11 -10
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/provider.d.ts +1 -1
- package/lib/cjs/provider.js +3 -3
- package/lib/cjs/provider.js.map +1 -1
- package/lib/cjs/state.js +2 -2
- package/lib/cjs/state.js.map +1 -1
- package/lib/cjs/sync-factory-provider.d.ts +4 -4
- package/lib/cjs/sync-factory-provider.js +6 -6
- package/lib/cjs/sync-factory-provider.js.map +1 -1
- package/lib/cjs/utils.js +2 -2
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/async-factory-provider.d.ts +4 -4
- package/lib/esm/async-factory-provider.js +2 -2
- package/lib/esm/async-factory-provider.js.map +1 -1
- package/lib/esm/bindable-provider.d.ts +3 -3
- package/lib/esm/bindable-provider.js +2 -2
- package/lib/esm/bindable-provider.js.map +1 -1
- package/lib/esm/binder.d.ts +2 -2
- package/lib/esm/binder.js.map +1 -1
- package/lib/esm/class-provider.d.ts +3 -3
- package/lib/esm/class-provider.js +5 -5
- package/lib/esm/class-provider.js.map +1 -1
- package/lib/esm/constant-provider.d.ts +2 -2
- package/lib/esm/constant-provider.js +2 -2
- package/lib/esm/constant-provider.js.map +1 -1
- package/lib/esm/container.d.ts +5 -5
- package/lib/esm/container.js +8 -8
- package/lib/esm/container.js.map +1 -1
- package/lib/esm/decorators.d.ts +1 -1
- package/lib/esm/decorators.js +1 -1
- package/lib/esm/decorators.js.map +1 -1
- package/lib/esm/index.d.ts +4 -4
- package/lib/esm/index.js +3 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/provider.d.ts +1 -1
- package/lib/esm/provider.js +1 -1
- package/lib/esm/provider.js.map +1 -1
- package/lib/esm/state.js +1 -1
- package/lib/esm/state.js.map +1 -1
- package/lib/esm/sync-factory-provider.d.ts +4 -4
- package/lib/esm/sync-factory-provider.js +2 -2
- package/lib/esm/sync-factory-provider.js.map +1 -1
- package/lib/esm/utils.js +1 -1
- package/lib/esm/utils.js.map +1 -1
- package/package.json +8 -8
package/Changelog.md
CHANGED
|
@@ -1,73 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Update ReadMe with badges
|
|
1
|
+
## 1.5.3 / 2023-06-05
|
|
2
|
+
* Address esm issues [#10](https://github.com/pcafstockf/async-injection/issues/10) and [#15](https://github.com/pcafstockf/async-injection/issues/15)
|
|
3
|
+
* Fix missing type overload on Binder interface.
|
|
4
|
+
* Update dev dependencies.
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Update ts-node and nyc devDependencies.
|
|
6
|
+
## 1.5.2 / 2023-01-18
|
|
7
|
+
* No code changes.
|
|
8
|
+
* Updates to docs for consistency across projects.
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
## 1.5.1 / 2023-01-18
|
|
11
|
+
* Update dev dependencies.
|
|
12
|
+
* Update github workflows.
|
|
13
|
+
* Update badges in main ReadMe.
|
|
14
|
+
* Add support directory.
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
## 1.5.0 / 2022-04-16
|
|
17
|
+
* Add experimental ability to clone a Container (see Container.clone JSDoc comments for details).
|
|
18
|
+
* Fix error handling callback to pass instantiated object when construction succeeds but post construction fails.
|
|
19
|
+
* Reformat code project wide (based on IntelliJ formatting options).
|
|
20
|
+
|
|
21
|
+
## 1.4.0 / 2022-02-16
|
|
22
|
+
* Add Angular style InjectionToken class as a variant of InjectableId to support implicit typing of constants and interfaces.
|
|
23
|
+
* Minor update to Binder.resolveSingletons to make it chainable (aka return the Container/Binder instance).
|
|
24
|
+
* Minor updates to ReadMe.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
No other code changes.
|
|
26
|
+
## 1.3.0 / 2021-11-27
|
|
27
|
+
* Support Container driven release of Singleton allocated resources (see Container.releaseSingletons).
|
|
28
|
+
* Update devDependencies.
|
|
29
|
+
* Minor updates to ReadMe.
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
## 1.2.7 / 2021-08-02
|
|
32
|
+
* Revert type declaration for AbstractConstructor which was broken during eslint integration.
|
|
33
|
+
* Update eslint related dev-dependencies.
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Update tsc devDependency from 4.3.3 to 4.3.4.
|
|
42
|
-
Update the ChangeLog to properly reflect recent GitHub releases.
|
|
35
|
+
## 1.2.6 / 2021-07-14
|
|
36
|
+
* Merge PR #9 [ESLINT integration + Improvements](https://github.com/pcafstockf/async-injection/pull/9).
|
|
37
|
+
* Update devDependencies.
|
|
38
|
+
* Resolved a couple of eslint warnings.
|
|
39
|
+
* tsc no longer removes comments in generated code. This can cause problems with post-processing tools such as istanbul. If file size is of concern to you, you should probably be minifying anyway.
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
## 1.2.5 / 2021-06-28
|
|
42
|
+
* No actual source code changes.
|
|
43
|
+
* Added Reflect type from reflect-metadata in order to remove the @ts-ignore comments.
|
|
44
|
+
* Improved tsconfig.json structure for IDE compatibility.
|
|
45
|
+
** Thanks to @tripodsgames for those contributions.
|
|
46
|
+
* Update tsc devDependency from 4.3.3 to 4.3.4.
|
|
47
|
+
* Update the ChangeLog to properly reflect recent GitHub releases.
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
## 1.2.4 / 2021-06-17
|
|
50
|
+
* Build esm into esm dir (not mjs).
|
|
51
|
+
* No actual source code changes.
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
## 1.2.3 / 2021-06-11
|
|
54
|
+
* cjs and esm distributions.
|
|
55
|
+
* Build now generates both cjs and esm distributions.
|
|
56
|
+
* tslib (where used) is now inlined instead of imported.
|
|
57
|
+
* No other code changes.
|
|
58
|
+
|
|
59
|
+
## 1.2.0 / 2021-06-08
|
|
60
|
+
* New Feature: Allow alternate polyfill for Reflect API
|
|
61
|
+
WARNING: This is a a breaking change release.
|
|
62
|
+
The API and code have not changed, but you will need to explicitly import a polyfill into your own code in order to use this release (see the ReadMe).
|
|
63
|
+
Previously Async-Injection relied on reflect-metadata (which is still supported), but this release also allows for the use of alternative implementations such as:
|
|
64
|
+
core-js (core-js/es7/reflect)
|
|
65
|
+
reflection
|
|
66
|
+
Thank you to @tripodsgames for this contribution.
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
Add
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
## 1.1.0 / 2021-05-07
|
|
69
|
+
* Add post construction handling feature to Binder.bindClass. This is for scenarios where it is not feasible to add the @PostConstruct decorator to the target class.
|
|
70
|
+
* Updated tslib
|
|
71
|
+
* Updated jasmine devDependency.
|
|
63
72
|
|
|
64
|
-
|
|
65
|
-
Add
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
## 1.0.8 / 2020-06-08
|
|
74
|
+
* Add ability to walk up the parent container hierarchy to methods Injector.isIdKnown and Container.removeBinding
|
|
75
|
+
* Update tslib
|
|
76
|
+
* Update ts-node and nyc devDependencies.
|
|
68
77
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
Update
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
## 1.0.7 / 2019-04-27
|
|
79
|
+
* Fix issue #1
|
|
80
|
+
* Update ts-node and source-map-support devDependencies
|
|
81
|
+
* Add tslint and Changelog
|
|
82
|
+
* Update ReadMe with badges
|
package/License.txt
CHANGED
package/ReadMe.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://github.com/pcafstockf/async-injection/actions)
|
|
4
4
|
[](https://badge.fury.io/js/async-injection)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
|
|
6
|
+

|
|
7
7
|
|
|
8
8
|
A robust lightweight dependency injection library for TypeScript.
|
|
9
9
|
|
|
@@ -34,7 +34,6 @@ import "reflect-metadata";
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
Please note that this library supports a wide variety of runtimes and is distributed as both esm and cjs modules, side by side.
|
|
37
|
-
Please see this [link](https://github.com/pcafstockf/async-injection/issues/10) if you experience module errors when compiling.
|
|
38
37
|
|
|
39
38
|
## Basic Usage (synchronous)
|
|
40
39
|
Here we 'get' a new transaction handling object, that itself, relies on a shared service:
|
|
@@ -237,7 +236,7 @@ Thanks to Carlos Delgado for the idea of a ["QuerablePromise"](https://ourcodewo
|
|
|
237
236
|
|
|
238
237
|
## MIT License
|
|
239
238
|
|
|
240
|
-
Copyright (c) 2020-
|
|
239
|
+
Copyright (c) 2020-2023 Frank Stock
|
|
241
240
|
|
|
242
241
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
243
242
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BindableProvider } from './bindable-provider';
|
|
2
|
-
import { AsyncFactory } from './binder';
|
|
3
|
-
import { InjectableId, Injector } from './injector';
|
|
4
|
-
import { State } from './state';
|
|
1
|
+
import { BindableProvider } from './bindable-provider.js';
|
|
2
|
+
import { AsyncFactory } from './binder.js';
|
|
3
|
+
import { InjectableId, Injector } from './injector.js';
|
|
4
|
+
import { State } from './state.js';
|
|
5
5
|
/**
|
|
6
6
|
* @inheritDoc
|
|
7
7
|
* This specialization invokes it's configured Factory asynchronously and waits until it can provide the result.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncFactoryBasedProvider = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const bindable_provider_js_1 = require("./bindable-provider.js");
|
|
5
|
+
const state_js_1 = require("./state.js");
|
|
6
6
|
/**
|
|
7
7
|
* @inheritDoc
|
|
8
8
|
* This specialization invokes it's configured Factory asynchronously and waits until it can provide the result.
|
|
9
9
|
*/
|
|
10
|
-
class AsyncFactoryBasedProvider extends
|
|
10
|
+
class AsyncFactoryBasedProvider extends bindable_provider_js_1.BindableProvider {
|
|
11
11
|
constructor(injector, id, maker) {
|
|
12
12
|
super(injector, id, maker);
|
|
13
13
|
}
|
|
@@ -20,7 +20,7 @@ class AsyncFactoryBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
20
20
|
if (!retVal) {
|
|
21
21
|
// Wrap the async factory's Promise in an errorHandler aware Promise.
|
|
22
22
|
// Our contract is that an AsyncFactory may not throw and must return a valid Promise (e.g. pending, resolved, rejected, etc).
|
|
23
|
-
retVal =
|
|
23
|
+
retVal = state_js_1.State.MakeState(this.makePromiseForObj(this.maker(this.injector), obj => obj));
|
|
24
24
|
}
|
|
25
25
|
if (this.singleton === null)
|
|
26
26
|
this.singleton = retVal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-factory-provider.js","sourceRoot":"","sources":["../../src/async-factory-provider.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"async-factory-provider.js","sourceRoot":"","sources":["../../src/async-factory-provider.ts"],"names":[],"mappings":";;;AAAA,iEAAwD;AAGxD,yCAAiC;AAEjC;;;GAGG;AACH,MAAa,yBAA6B,SAAQ,uCAAoC;IACrF,YAAY,QAAkB,EAAE,EAAmB,EAAE,KAAsB;QAC1E,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,cAAc;QACb,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,EAAE;YACZ,qEAAqE;YACrE,8HAA8H;YAC9H,MAAM,GAAG,gBAAK,CAAC,SAAS,CAAI,IAAI,CAAC,iBAAiB,CAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;SAC9F;QACD,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YAC1B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AApBD,8DAoBC","sourcesContent":["import {BindableProvider} from './bindable-provider.js';\nimport {AsyncFactory} from './binder.js';\nimport {InjectableId, Injector} from './injector.js';\nimport {State} from './state.js';\n\n/**\n * @inheritDoc\n * This specialization invokes it's configured Factory asynchronously and waits until it can provide the result.\n */\nexport class AsyncFactoryBasedProvider<T> extends BindableProvider<T, AsyncFactory<T>> {\n\tconstructor(injector: Injector, id: InjectableId<T>, maker: AsyncFactory<T>) {\n\t\tsuper(injector, id, maker);\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * This specialization invokes it's configured Factory and provides the result (or invokes the error handler if necessary).\n\t */\n\tprovideAsState(): State<T> {\n\t\tlet retVal = this.singleton;\n\t\tif (!retVal) {\n\t\t\t// Wrap the async factory's Promise in an errorHandler aware Promise.\n\t\t\t// Our contract is that an AsyncFactory may not throw and must return a valid Promise (e.g. pending, resolved, rejected, etc).\n\t\t\tretVal = State.MakeState<T>(this.makePromiseForObj<T>(this.maker(this.injector), obj => obj));\n\t\t}\n\t\tif (this.singleton === null)\n\t\t\tthis.singleton = retVal;\n\t\treturn retVal;\n\t}\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory } from './binder';
|
|
2
|
-
import { ClassConstructor, InjectableId, Injector } from './injector';
|
|
3
|
-
import { Provider } from './provider';
|
|
1
|
+
import { AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory } from './binder.js';
|
|
2
|
+
import { ClassConstructor, InjectableId, Injector } from './injector.js';
|
|
3
|
+
import { Provider } from './provider.js';
|
|
4
4
|
/**
|
|
5
5
|
* @inheritDoc
|
|
6
6
|
* This abstraction is for Providers that can be additionally configured as Singletons and/or configured with error and/or success handling callback(s).
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindableProvider = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const provider_js_1 = require("./provider.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
6
|
/**
|
|
7
7
|
* @inheritDoc
|
|
8
8
|
* This abstraction is for Providers that can be additionally configured as Singletons and/or configured with error and/or success handling callback(s).
|
|
9
9
|
*/
|
|
10
|
-
class BindableProvider extends
|
|
10
|
+
class BindableProvider extends provider_js_1.Provider {
|
|
11
11
|
constructor(injector, id, maker) {
|
|
12
12
|
super();
|
|
13
13
|
this.injector = injector;
|
|
@@ -47,7 +47,7 @@ class BindableProvider extends provider_1.Provider {
|
|
|
47
47
|
if (this.errorHandler) {
|
|
48
48
|
const handlerResult = this.errorHandler(this.injector, this.id, this.maker, err, obj);
|
|
49
49
|
// Error handler wants us to propagate an error.
|
|
50
|
-
if ((0,
|
|
50
|
+
if ((0, utils_js_1.isErrorObj)(handlerResult))
|
|
51
51
|
throw handlerResult;
|
|
52
52
|
// Error handler has no opinion, so provideAsState a state that reflects the error we just caught.
|
|
53
53
|
if (typeof handlerResult === 'undefined')
|
|
@@ -73,7 +73,7 @@ class BindableProvider extends provider_1.Provider {
|
|
|
73
73
|
if (this.errorHandler) {
|
|
74
74
|
const handlerResult = this.errorHandler(this.injector, this.id, this.maker, err, objValue);
|
|
75
75
|
// Error handler wants us to propagate an alternative error.
|
|
76
|
-
if ((0,
|
|
76
|
+
if ((0, utils_js_1.isErrorObj)(handlerResult))
|
|
77
77
|
err = handlerResult; // Fall thru
|
|
78
78
|
else if (typeof handlerResult !== 'undefined') {
|
|
79
79
|
resolve(handlerResult); // Error handler provided a replacement, so change the State that we returned from pending to resolved.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindable-provider.js","sourceRoot":"","sources":["../../src/bindable-provider.ts"],"names":[],"mappings":";;;AAEA
|
|
1
|
+
{"version":3,"file":"bindable-provider.js","sourceRoot":"","sources":["../../src/bindable-provider.ts"],"names":[],"mappings":";;;AAEA,+CAAuC;AACvC,yCAAsC;AAEtC;;;GAGG;AACH,MAAsB,gBAAgF,SAAQ,sBAAW;IACxH,YAAgC,QAAkB,EAAY,EAAmB,EAAY,KAAQ;QACpG,KAAK,EAAE,CAAC;QADuB,aAAQ,GAAR,QAAQ,CAAU;QAAY,OAAE,GAAF,EAAE,CAAiB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E;oBACtB,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;oBAC3F,4DAA4D;oBAC5D,IAAI,IAAA,qBAAU,EAAC,aAAa,CAAC;wBAC5B,GAAG,GAAG,aAAa,CAAC,CAAG,YAAY;yBAC/B,IAAI,OAAO,aAAa,KAAK,WAAW,EAAE;wBAC9C,OAAO,CAAC,aAAa,CAAC,CAAC,CAAI,uGAAuG;wBAClI,OAAO;qBACP;iBACD;gBACD,wEAAwE;gBACxE,MAAM,CAAC,GAAG,CAAC,CAAC;YACb,CAAC,CAAC;YACF,OAAO,CAAC,IAAI,CACX,CAAC,MAAM,EAAE,EAAE;gBACV,wEAAwE;gBACxE,IAAI;oBACH,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;iBACpB;gBACD,OAAO,GAAG,EAAE;oBACX,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;iBAC9B;YACF,CAAC,CACD,CAAC,KAAK,CACN,CAAC,GAAG,EAAE,EAAE;gBACP,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAClC,CAAC,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAzGD,4CAyGC","sourcesContent":["import {AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory} from './binder.js';\nimport {ClassConstructor, InjectableId, Injector} from './injector.js';\nimport {Provider} from './provider.js';\nimport {isErrorObj} from './utils.js';\n\n/**\n * @inheritDoc\n * This abstraction is for Providers that can be additionally configured as Singletons and/or configured with error and/or success handling callback(s).\n */\nexport abstract class BindableProvider<T, M = ClassConstructor<T> | SyncFactory<T> | AsyncFactory<T>> extends Provider<T> {\n\tprotected constructor(protected injector: Injector, protected id: InjectableId<T>, protected maker: M) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * A user supplied success handling function.\n\t * Default value is undefined.\n\t */\n\tprotected successHandler?: OnSuccessCallback<T, any>;\n\n\t/**\n\t * A user supplied error handling function.\n\t * Default value is undefined.\n\t */\n\tprotected errorHandler?: OnErrorCallback<T, any>;\n\n\t/**\n\t * Invoked by the Binder to create chain-able configuration\n\t *\n\t * @see BindAs\n\t */\n\tmakeBindAs(): BindAs<T, M> {\n\t\tconst retVal: BindAs<T, M> = {\n\t\t\tonError: (cb: OnErrorCallback<T, M>) => {\n\t\t\t\tthis.errorHandler = cb;\n\t\t\t},\n\t\t\tonSuccess: (cb: OnSuccessCallback<T, M>) => {\n\t\t\t\tthis.successHandler = cb;\n\t\t\t\treturn retVal;\n\t\t\t},\n\t\t\tasSingleton: () => {\n\t\t\t\tthis.singleton = null; // Flag state as no longer undefined.\n\t\t\t\treturn retVal;\n\t\t\t}\n\t\t};\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * Encapsulate the logic of invoking any configured error handler, and processing it's result.\n\t *\n\t * @see OnErrorCallback\n\t *\n\t * @returns The object substituted by the callback (otherwise this method throws the appropriate error).\n\t */\n\tprotected queryErrorHandler(err: unknown, obj?: T): T {\n\t\t// There was an error during construction, see if an error handler was provided, and if so, see what it wants to do.\n\t\tif (this.errorHandler) {\n\t\t\tconst handlerResult = this.errorHandler(this.injector, this.id, this.maker, err, obj);\n\t\t\t// Error handler wants us to propagate an error.\n\t\t\tif (isErrorObj(handlerResult))\n\t\t\t\tthrow handlerResult;\n\t\t\t// Error handler has no opinion, so provideAsState a state that reflects the error we just caught.\n\t\t\tif (typeof handlerResult === 'undefined')\n\t\t\t\tthrow err;\n\t\t\t// Error handler provided a valid (fully resolved) replacement.\n\t\t\treturn handlerResult;\n\t\t}\n\t\t// No error handler, provideAsState a state that reflects the error we just caught.\n\t\tthrow err;\n\t}\n\n\t/**\n\t * This is like a retry mechanism that uses the Provider's errorHandler (if any) to attempt recovery whenever the supplied Promise rejects.\n\t * This method returns a Promise that rejects if recovery was not possible.\n\t * If the supplied Promise resolves, then this method passes the result to the callback, and then resolve as whatever that callback returns.\n\t *\n\t * @param waitFor The supplied Promise.\n\t * @param cb Callback to be invoked if the supplied Promise resolves.\n\t */\n\tprotected makePromiseForObj<R>(waitFor: Promise<R>, cb: (result: R) => T): Promise<T> {\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tconst errHandlerFn = (err: any, objValue?: T) => {\n\t\t\t\t// There was an error during async post construction, see if an error handler was provided, and if so, see what it wants to do.\n\t\t\t\tif (this.errorHandler) {\n\t\t\t\t\tconst handlerResult = this.errorHandler(this.injector, this.id, this.maker, err, objValue);\n\t\t\t\t\t// Error handler wants us to propagate an alternative error.\n\t\t\t\t\tif (isErrorObj(handlerResult))\n\t\t\t\t\t\terr = handlerResult; // Fall thru\n\t\t\t\t\telse if (typeof handlerResult !== 'undefined') {\n\t\t\t\t\t\tresolve(handlerResult); // Error handler provided a replacement, so change the State that we returned from pending to resolved.\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// This will change the State that we returned from pending to rejected.\n\t\t\t\treject(err);\n\t\t\t};\n\t\t\twaitFor.then(\n\t\t\t\t(result) => {\n\t\t\t\t\t// This will change the State that we returned from pending to resolved.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresolve(cb(result));\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\terrHandlerFn(err, cb(result));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t).catch(\n\t\t\t\t(err) => {\n\t\t\t\t\terrHandlerFn(err, cb(undefined));\n\t\t\t\t}\n\t\t\t);\n\t\t});\n\t}\n}\n"]}
|
package/lib/cjs/binder.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractConstructor, ClassConstructor, InjectableId, Injector } from './injector';
|
|
1
|
+
import { AbstractConstructor, ClassConstructor, InjectableId, Injector } from './injector.js';
|
|
2
2
|
/**
|
|
3
3
|
* Type definition for functions that return a value.
|
|
4
4
|
* The function should return a valid value, but may throw an exception if it cannot.
|
|
@@ -80,7 +80,7 @@ export interface Binder extends Injector {
|
|
|
80
80
|
* The container will also invoke any `@PostConstruct` present on the class.
|
|
81
81
|
*/
|
|
82
82
|
bindClass<T>(id: ClassConstructor<T>, constructor?: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;
|
|
83
|
-
bindClass<T>(id: string | symbol | AbstractConstructor<T>, constructor: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;
|
|
83
|
+
bindClass<T>(id: string | symbol | AbstractConstructor<T> | InjectableId<T>, constructor: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;
|
|
84
84
|
/**
|
|
85
85
|
* Bind an InjectableId to a synchronous factory that will be invoked on demand when the object is needed.
|
|
86
86
|
* The factory should produce the needed value
|
package/lib/cjs/binder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binder.js","sourceRoot":"","sources":["../../src/binder.ts"],"names":[],"mappings":"","sourcesContent":["import {AbstractConstructor, ClassConstructor, InjectableId, Injector} from './injector';\n\n/**\n * Type definition for functions that return a value.\n * The function should return a valid value, but may throw an exception if it cannot.\n */\nexport type SyncFactory<T> = (injector: Injector) => T;\n\n/**\n * Type definition for functions that return a Promise for a value.\n * The function *must* not throw and must return a valid Promise (e.g. pending, resolved, rejected).\n */\nexport type AsyncFactory<T> = (injector: Injector) => Promise<T>;\n\n/**\n * You may bind an error handler which will be invoked, if the bound InjectableId could not be put into service.\n * An error handler *must* not throw, but may return an Error that will be propagated back up the call chain.\n *\n * @param binder The Binder that experienced the error.\n * @param id The identifier for what was trying to be made.\n * @param maker The thing that made (or tried to provideAsState). Will be one of type ClassConstructor, SyncFactory, or AsyncFactory, depending on how you registered the binding.\n * @param error Identifies the problem that occurred.\n * @param value If the 'maker' was able to create the thing, but it had an error during post construction, the made thing will be passed here.\n * @returns one of 3 results...\n * A substitute thing (kind of like a 'maker' do-over) which must be fully operational (e.g. any `@PostConstruct` will be ignored).\n * An alternate Error which will be propagated back up the call chain.\n * Undefined, which means the 'error' parameter will be propagated back up the call chain.\n */\nexport type OnErrorCallback<T, M> = (injector: Injector, id: InjectableId<T>, maker: M, error: unknown, value?: T) => T | Error | void;\n\n/**\n * You may bind a success handler which will be invoked just before the bound InjectableId is put into service.\n * This is an alternative to the more preferred `@PostConstruct` decorator for scenarios when usage of that decorator is not feasible.\n * WARNING:\n * By registering a success handler, you override and nullify any `@PostConstruct` decorator on the class.\n * In such a scenario, the success handler should perform whatever care and feeding the class expected from the `@PostConstruct` decorator.\n * A success handler *must* not throw, but may return an Error that will be propagated back up the call chain.\n *\n * @param binder The Binder that performed the construction.\n * @param id The identifier for what was made.\n * @param maker The thing that made. Will be one of type ClassConstructor, SyncFactory, or AsyncFactory, depending on how you registered the binding.\n * @param value The thing that was made.\n * @returns one of 3 results...\n * An Error which will be propagated back up the call chain.\n * Undefined, which means the object is ready to be placed into service.\n * A Promise that resolves to one of the above two values (undefined or Error).\n */\nexport type OnSuccessCallback<T, M> = (value: T, injector: Injector, id: InjectableId<T>, maker: M) => Promise<Error | void> | Error | void;\n\n/**\n * An interface allowing binding of an error handler.\n *\n * @see OnErrorCallback\n */\nexport interface BindErrHandler<T, M> {\n\tonError(cb: OnErrorCallback<T, M>): void;\n}\n\n/**\n * An interface allowing binding of a post construction handler.\n *\n * @see OnSuccessCallback\n */\nexport interface BindHandler<T, M> extends BindErrHandler<T, M> {\n\tonSuccess(cb: OnSuccessCallback<T, M>): BindErrHandler<T, M>;\n}\n\n/**\n * @inheritDoc\n * This specialization also allows you to specify that the binding is 'Singleton' (e.g. only one in the system).\n */\nexport interface BindAs<T, M> extends BindHandler<T, M> {\n\tasSingleton(): BindHandler<T, M>;\n}\n\n/**\n * Bind Ids to producers.\n */\nexport interface Binder extends Injector {\n\n\t/**\n\t * Bind an InjectableId to a constant value.\n\t * Constants are by their very nature singleton, and are assumed to be error proof.\n\t */\n\tbindConstant<T>(id: InjectableId<T>, value: T): void;\n\n\t/**\n\t * Bind an InjectableId to a class (actually it's constructor).\n\t * As a shortcut, you may use the class constructor as the 'id' (e.g. container.bindClass(A); ).\n\t * The container will also invoke any `@PostConstruct` present on the class.\n\t */\n\tbindClass<T>(id: ClassConstructor<T>, constructor?: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;\n\n\tbindClass<T>(id: string | symbol | AbstractConstructor<T>, constructor: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;\n\n\t/**\n\t * Bind an InjectableId to a synchronous factory that will be invoked on demand when the object is needed.\n\t * The factory should produce the needed value\n\t * NOTE: The container will not invoke any `@PostConstruct` present on the class, this is the responsibility of the factory.\n\t */\n\tbindFactory<T>(id: InjectableId<T>, factory: SyncFactory<T>): BindAs<T, SyncFactory<T>>;\n\n\t/**\n\t * Bind an InjectableId to an asynchronous factory that will be invoked on demand when the object is needed.\n\t * The factory should produce the needed value (asynchronously of course).\n\t * NOTE: The container will not invoke any `@PostConstruct` present on the class, this is the responsibility of the factory.\n\t * WARNING!!! The factory may not throw and must return a valid Promise (which can be pending, resolved, rejected, etc.).\n\t */\n\tbindAsyncFactory<T>(id: InjectableId<T>, factory: AsyncFactory<T>): BindAs<T, AsyncFactory<T>>;\n\n\t/**\n\t * This essentially pre creates/loads all *singleton* InjectableIds currently known to the Binder.\n\t * This *may* be helpful if you wish to use Injector.get on a dependency tree that has asynchronous singletons within the tree.\n\t *\n\t * @param asyncOnly Only resolve AsyncFactorys as well as any bound classes that have an asynchronous `@PostConstruct` decorator. WARNING: If true, SyncFactorys will *not* be resolved even if they are Singletons.\n\t * @param parentRecursion If true and the the container has a parent, resolveIfSingleton will first be called for the parent\n\t * @returns A Promise that resolves when all Singleton's have been resolved, OR rejects if one or more of the Singleton's failed to resolve. NOTE: Rejection does not occur until all Singleton resolutions have settled, and the rejection reason/err will be a Map<InjectableId, Error>\n\t */\n\tresolveSingletons(asyncOnly?: boolean, parentRecursion?: boolean): Promise<this>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"binder.js","sourceRoot":"","sources":["../../src/binder.ts"],"names":[],"mappings":"","sourcesContent":["import {AbstractConstructor, ClassConstructor, InjectableId, Injector} from './injector.js';\n\n/**\n * Type definition for functions that return a value.\n * The function should return a valid value, but may throw an exception if it cannot.\n */\nexport type SyncFactory<T> = (injector: Injector) => T;\n\n/**\n * Type definition for functions that return a Promise for a value.\n * The function *must* not throw and must return a valid Promise (e.g. pending, resolved, rejected).\n */\nexport type AsyncFactory<T> = (injector: Injector) => Promise<T>;\n\n/**\n * You may bind an error handler which will be invoked, if the bound InjectableId could not be put into service.\n * An error handler *must* not throw, but may return an Error that will be propagated back up the call chain.\n *\n * @param binder The Binder that experienced the error.\n * @param id The identifier for what was trying to be made.\n * @param maker The thing that made (or tried to provideAsState). Will be one of type ClassConstructor, SyncFactory, or AsyncFactory, depending on how you registered the binding.\n * @param error Identifies the problem that occurred.\n * @param value If the 'maker' was able to create the thing, but it had an error during post construction, the made thing will be passed here.\n * @returns one of 3 results...\n * A substitute thing (kind of like a 'maker' do-over) which must be fully operational (e.g. any `@PostConstruct` will be ignored).\n * An alternate Error which will be propagated back up the call chain.\n * Undefined, which means the 'error' parameter will be propagated back up the call chain.\n */\nexport type OnErrorCallback<T, M> = (injector: Injector, id: InjectableId<T>, maker: M, error: unknown, value?: T) => T | Error | void;\n\n/**\n * You may bind a success handler which will be invoked just before the bound InjectableId is put into service.\n * This is an alternative to the more preferred `@PostConstruct` decorator for scenarios when usage of that decorator is not feasible.\n * WARNING:\n * By registering a success handler, you override and nullify any `@PostConstruct` decorator on the class.\n * In such a scenario, the success handler should perform whatever care and feeding the class expected from the `@PostConstruct` decorator.\n * A success handler *must* not throw, but may return an Error that will be propagated back up the call chain.\n *\n * @param binder The Binder that performed the construction.\n * @param id The identifier for what was made.\n * @param maker The thing that made. Will be one of type ClassConstructor, SyncFactory, or AsyncFactory, depending on how you registered the binding.\n * @param value The thing that was made.\n * @returns one of 3 results...\n * An Error which will be propagated back up the call chain.\n * Undefined, which means the object is ready to be placed into service.\n * A Promise that resolves to one of the above two values (undefined or Error).\n */\nexport type OnSuccessCallback<T, M> = (value: T, injector: Injector, id: InjectableId<T>, maker: M) => Promise<Error | void> | Error | void;\n\n/**\n * An interface allowing binding of an error handler.\n *\n * @see OnErrorCallback\n */\nexport interface BindErrHandler<T, M> {\n\tonError(cb: OnErrorCallback<T, M>): void;\n}\n\n/**\n * An interface allowing binding of a post construction handler.\n *\n * @see OnSuccessCallback\n */\nexport interface BindHandler<T, M> extends BindErrHandler<T, M> {\n\tonSuccess(cb: OnSuccessCallback<T, M>): BindErrHandler<T, M>;\n}\n\n/**\n * @inheritDoc\n * This specialization also allows you to specify that the binding is 'Singleton' (e.g. only one in the system).\n */\nexport interface BindAs<T, M> extends BindHandler<T, M> {\n\tasSingleton(): BindHandler<T, M>;\n}\n\n/**\n * Bind Ids to producers.\n */\nexport interface Binder extends Injector {\n\n\t/**\n\t * Bind an InjectableId to a constant value.\n\t * Constants are by their very nature singleton, and are assumed to be error proof.\n\t */\n\tbindConstant<T>(id: InjectableId<T>, value: T): void;\n\n\t/**\n\t * Bind an InjectableId to a class (actually it's constructor).\n\t * As a shortcut, you may use the class constructor as the 'id' (e.g. container.bindClass(A); ).\n\t * The container will also invoke any `@PostConstruct` present on the class.\n\t */\n\tbindClass<T>(id: ClassConstructor<T>, constructor?: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;\n\n\tbindClass<T>(id: string | symbol | AbstractConstructor<T> | InjectableId<T>, constructor: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;\n\n\t/**\n\t * Bind an InjectableId to a synchronous factory that will be invoked on demand when the object is needed.\n\t * The factory should produce the needed value\n\t * NOTE: The container will not invoke any `@PostConstruct` present on the class, this is the responsibility of the factory.\n\t */\n\tbindFactory<T>(id: InjectableId<T>, factory: SyncFactory<T>): BindAs<T, SyncFactory<T>>;\n\n\t/**\n\t * Bind an InjectableId to an asynchronous factory that will be invoked on demand when the object is needed.\n\t * The factory should produce the needed value (asynchronously of course).\n\t * NOTE: The container will not invoke any `@PostConstruct` present on the class, this is the responsibility of the factory.\n\t * WARNING!!! The factory may not throw and must return a valid Promise (which can be pending, resolved, rejected, etc.).\n\t */\n\tbindAsyncFactory<T>(id: InjectableId<T>, factory: AsyncFactory<T>): BindAs<T, AsyncFactory<T>>;\n\n\t/**\n\t * This essentially pre creates/loads all *singleton* InjectableIds currently known to the Binder.\n\t * This *may* be helpful if you wish to use Injector.get on a dependency tree that has asynchronous singletons within the tree.\n\t *\n\t * @param asyncOnly Only resolve AsyncFactorys as well as any bound classes that have an asynchronous `@PostConstruct` decorator. WARNING: If true, SyncFactorys will *not* be resolved even if they are Singletons.\n\t * @param parentRecursion If true and the the container has a parent, resolveIfSingleton will first be called for the parent\n\t * @returns A Promise that resolves when all Singleton's have been resolved, OR rejects if one or more of the Singleton's failed to resolve. NOTE: Rejection does not occur until all Singleton resolutions have settled, and the rejection reason/err will be a Map<InjectableId, Error>\n\t */\n\tresolveSingletons(asyncOnly?: boolean, parentRecursion?: boolean): Promise<this>;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BindableProvider } from './bindable-provider';
|
|
2
|
-
import { ClassConstructor, InjectableId, Injector } from './injector';
|
|
3
|
-
import { State } from './state';
|
|
1
|
+
import { BindableProvider } from './bindable-provider.js';
|
|
2
|
+
import { ClassConstructor, InjectableId, Injector } from './injector.js';
|
|
3
|
+
import { State } from './state.js';
|
|
4
4
|
interface StateResolvingInjector extends Injector {
|
|
5
5
|
resolveState<T>(id: InjectableId<T>): State<T>;
|
|
6
6
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClassBasedProvider = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const bindable_provider_js_1 = require("./bindable-provider.js");
|
|
5
|
+
const constants_js_1 = require("./constants.js");
|
|
6
|
+
const decorators_js_1 = require("./decorators.js");
|
|
7
|
+
const state_js_1 = require("./state.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
/**
|
|
10
10
|
* @inheritDoc
|
|
11
11
|
* This specialization invokes it's configured class constructor synchronously and then scans for (and invokes) any @PostConstruct (which may be synchronous or asynchronous).
|
|
12
12
|
*/
|
|
13
|
-
class ClassBasedProvider extends
|
|
13
|
+
class ClassBasedProvider extends bindable_provider_js_1.BindableProvider {
|
|
14
14
|
constructor(injector, id, maker) {
|
|
15
15
|
super(injector, id, maker);
|
|
16
16
|
}
|
|
@@ -33,7 +33,7 @@ class ClassBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
33
33
|
* This specialization returns undefined if 'asyncOnly' is true and there is no asynchronous PostConstruct annotation (since class constructors can never by asynchronous).
|
|
34
34
|
*/
|
|
35
35
|
resolveIfSingleton(asyncOnly) {
|
|
36
|
-
if ((!asyncOnly) || Reflect.getMetadata(
|
|
36
|
+
if ((!asyncOnly) || Reflect.getMetadata(constants_js_1.POSTCONSTRUCT_ASYNC_METADATA_KEY, this.maker))
|
|
37
37
|
return super.resolveIfSingleton(false);
|
|
38
38
|
return undefined;
|
|
39
39
|
}
|
|
@@ -54,10 +54,10 @@ class ClassBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
54
54
|
else {
|
|
55
55
|
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */
|
|
56
56
|
// Check to see if there is a @PostConstruct annotation on a method of the class.
|
|
57
|
-
let postConstruct = Reflect.getMetadata(
|
|
57
|
+
let postConstruct = Reflect.getMetadata(constants_js_1.POSTCONSTRUCT_SYNC_METADATA_KEY, obj.constructor);
|
|
58
58
|
if (!postConstruct) {
|
|
59
59
|
maybeAsync = true;
|
|
60
|
-
postConstruct = Reflect.getMetadata(
|
|
60
|
+
postConstruct = Reflect.getMetadata(constants_js_1.POSTCONSTRUCT_ASYNC_METADATA_KEY, obj.constructor);
|
|
61
61
|
}
|
|
62
62
|
if (postConstruct && obj.constructor.prototype[postConstruct] && typeof obj.constructor.prototype[postConstruct] === 'function')
|
|
63
63
|
pcFn = (_b = (_a = obj[postConstruct]).bind) === null || _b === void 0 ? void 0 : _b.call(_a, obj);
|
|
@@ -72,29 +72,29 @@ class ClassBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
72
72
|
// The post construction method threw while executing, give the errorHandler (if any) a crack at recovery.
|
|
73
73
|
try {
|
|
74
74
|
obj = this.queryErrorHandler(err, obj); // The returned obj is unlikely to be the original obj.
|
|
75
|
-
return
|
|
75
|
+
return state_js_1.State.MakeState(null, undefined, obj);
|
|
76
76
|
}
|
|
77
77
|
catch (e) {
|
|
78
78
|
// could not recover, propagate the error.
|
|
79
|
-
return
|
|
79
|
+
return state_js_1.State.MakeState(null, e, undefined);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
// The post construction method says it will let us know when it's finished.
|
|
83
|
-
if (result && (result instanceof Promise || (maybeAsync && (0,
|
|
83
|
+
if (result && (result instanceof Promise || (maybeAsync && (0, utils_js_1.isPromise)(result)))) {
|
|
84
84
|
// Return a State that is pending (the other return statements in this method return a State which is resolved or rejected).
|
|
85
85
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
86
|
-
return
|
|
86
|
+
return state_js_1.State.MakeState(this.makePromiseForObj(result, () => obj));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
// No PostConstruct, just return a resolved State
|
|
91
|
-
return
|
|
91
|
+
return state_js_1.State.MakeState(null, undefined, obj);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* This method collects the States of all the constructor parameters for our target class.
|
|
95
95
|
*/
|
|
96
96
|
getConstructorParameterStates() {
|
|
97
|
-
const argTypes = Reflect.getMetadata(
|
|
97
|
+
const argTypes = Reflect.getMetadata(constants_js_1.REFLECT_PARAMS, this.maker);
|
|
98
98
|
if (argTypes === undefined || !Array.isArray(argTypes)) {
|
|
99
99
|
return [];
|
|
100
100
|
}
|
|
@@ -104,16 +104,16 @@ class ClassBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
104
104
|
throw new Error(`Injection error. Recursive dependency in constructor for ${this.maker.toString()} at index ${index}`);
|
|
105
105
|
}
|
|
106
106
|
// Check if an Inject annotation precedes the parameter.
|
|
107
|
-
const overrideToken = (0,
|
|
107
|
+
const overrideToken = (0, decorators_js_1._getInjectedIdAt)(this.maker, index);
|
|
108
108
|
const actualToken = overrideToken === undefined ? argType : overrideToken;
|
|
109
109
|
// Ask our container to resolve the parameter.
|
|
110
110
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
111
111
|
let param = this.injector.resolveState(actualToken);
|
|
112
112
|
// If the parameter could not be resolved, see if there is an @Optional annotation
|
|
113
113
|
if ((!param.pending) && param.rejected) {
|
|
114
|
-
const md = (0,
|
|
114
|
+
const md = (0, decorators_js_1._getOptionalDefaultAt)(this.maker, index);
|
|
115
115
|
if (md)
|
|
116
|
-
param =
|
|
116
|
+
param = state_js_1.State.MakeState(null, undefined, md.value);
|
|
117
117
|
}
|
|
118
118
|
return param;
|
|
119
119
|
});
|
|
@@ -144,7 +144,7 @@ class ClassBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
144
144
|
return Reflect.construct(this.maker, params.map((p) => p.fulfilled));
|
|
145
145
|
});
|
|
146
146
|
// Once the obj is resolved, then we need to check for PostConstruct and if it was async, wait for that too.
|
|
147
|
-
return
|
|
147
|
+
return state_js_1.State.MakeState(objPromise.then((obj) => {
|
|
148
148
|
const state = this.makePostConstructState(obj);
|
|
149
149
|
if (state.pending) {
|
|
150
150
|
return state.promise; // chain (aka wait some more).
|
|
@@ -167,11 +167,11 @@ class ClassBasedProvider extends bindable_provider_1.BindableProvider {
|
|
|
167
167
|
catch (err) {
|
|
168
168
|
// There was an error, give the errorHandler (if any) a crack at recovery.
|
|
169
169
|
try {
|
|
170
|
-
return
|
|
170
|
+
return state_js_1.State.MakeState(null, undefined, this.queryErrorHandler(err));
|
|
171
171
|
}
|
|
172
172
|
catch (e) {
|
|
173
173
|
// could not recover, propagate the error.
|
|
174
|
-
return
|
|
174
|
+
return state_js_1.State.MakeState(null, e, undefined);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-provider.js","sourceRoot":"","sources":["../../src/class-provider.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AACrD,2CAA8G;AAC9G,6CAAqE;AAErE,mCAA8B;AAC9B,mCAAkC;AAYlC;;;GAGG;AACH,MAAa,kBAAsB,SAAQ,oCAAwC;IAClF,YAAY,QAAgC,EAAE,EAAmB,EAAE,KAA0B;QAC5F,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,cAAc;QACb,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;SACnC;QACD,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YAC1B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,kBAAkB,CAAC,SAAkB;QACpC,IAAI,CAAC,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,WAAW,CAAC,4CAAgC,EAAE,IAAI,CAAC,KAAK,CAAC;YACpF,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;OAEG;IACO,sBAAsB,CAAC,GAAM;;QACtC,IAAI,OAAO,GAAG,KAAK,QAAQ,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EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;iBAC9C;aACD;SACD;IACF,CAAC;CACD;AA5KD,gDA4KC","sourcesContent":["import {BindableProvider} from './bindable-provider';\nimport {POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_PARAMS} from './constants';\nimport {_getInjectedIdAt, _getOptionalDefaultAt} from './decorators';\nimport {ClassConstructor, InjectableId, Injector} from './injector';\nimport {State} from './state';\nimport {isPromise} from './utils';\n\n/*\n * This is a bit of a hack, but it avoids a ton of alternative hacks.\n * Note that in the Container, resolveState is a protected method.\n * Injector was never meant to publicly expose State.\n * Gotta love JS!\n */\ninterface StateResolvingInjector extends Injector {\n\tresolveState<T>(id: InjectableId<T>): State<T>;\n}\n\n/**\n * @inheritDoc\n * This specialization invokes it's configured class constructor synchronously and then scans for (and invokes) any @PostConstruct (which may be synchronous or asynchronous).\n */\nexport class ClassBasedProvider<T> extends BindableProvider<T, ClassConstructor<T>> {\n\tconstructor(injector: StateResolvingInjector, id: InjectableId<T>, maker: ClassConstructor<T>) {\n\t\tsuper(injector, id, maker);\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * @see the class description for this Provider.\n\t * This method is just a singleton guard, the real work is done by provideAsStateImpl.\n\t */\n\tprovideAsState(): State<T> {\n\t\tlet retVal = this.singleton;\n\t\tif (!retVal) {\n\t\t\tretVal = this.provideAsStateImpl();\n\t\t}\n\t\tif (this.singleton === null)\n\t\t\tthis.singleton = retVal;\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * This specialization returns undefined if 'asyncOnly' is true and there is no asynchronous PostConstruct annotation (since class constructors can never by asynchronous).\n\t */\n\tresolveIfSingleton(asyncOnly: boolean): Promise<T> {\n\t\tif ((!asyncOnly) || Reflect.getMetadata(POSTCONSTRUCT_ASYNC_METADATA_KEY, this.maker))\n\t\t\treturn super.resolveIfSingleton(false);\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Make a resolved or pending State that reflects any @PostConstruct annotations.\n\t */\n\tprotected makePostConstructState(obj: T): State<T> {\n\t\tif (typeof obj === 'object' && (!Array.isArray(obj)) && obj.constructor) {\n\t\t\tlet maybeAsync = false;\n\t\t\tlet pcFn: () => void | Error | Promise<void | Error>;\n\t\t\tif (typeof this.successHandler === 'function') {\n\t\t\t\tmaybeAsync = true;\n\t\t\t\tpcFn = () => {\n\t\t\t\t\treturn this.successHandler(obj, this.injector, this.id, this.maker);\n\t\t\t\t};\n\t\t\t}\n\t\t\telse {\n\t\t\t\t/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */\n\t\t\t\t// Check to see if there is a @PostConstruct annotation on a method of the class.\n\t\t\t\tlet postConstruct: string = Reflect.getMetadata(POSTCONSTRUCT_SYNC_METADATA_KEY, obj.constructor);\n\t\t\t\tif (!postConstruct) {\n\t\t\t\t\tmaybeAsync = true;\n\t\t\t\t\tpostConstruct = Reflect.getMetadata(POSTCONSTRUCT_ASYNC_METADATA_KEY, obj.constructor);\n\t\t\t\t}\n\t\t\t\tif (postConstruct && obj.constructor.prototype[postConstruct] && typeof obj.constructor.prototype[postConstruct] === 'function')\n\t\t\t\t\tpcFn = obj[postConstruct].bind?.(obj);\n\n\t\t\t\t/* eslint-enable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */\n\t\t\t}\n\t\t\tif (pcFn) {\n\t\t\t\tlet result: any;\n\t\t\t\ttry {\n\t\t\t\t\tresult = pcFn();\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\t// The post construction method threw while executing, give the errorHandler (if any) a crack at recovery.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tobj = this.queryErrorHandler(err, obj); // The returned obj is unlikely to be the original obj.\n\t\t\t\t\t\treturn State.MakeState<T>(null, undefined, obj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t// could not recover, propagate the error.\n\t\t\t\t\t\treturn State.MakeState<T>(null, e, undefined);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// The post construction method says it will let us know when it's finished.\n\t\t\t\tif (result && (result instanceof Promise || (maybeAsync && isPromise<void>(result)))) {\n\t\t\t\t\t// Return a State that is pending (the other return statements in this method return a State which is resolved or rejected).\n\t\t\t\t\t/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\t\t\t\t\treturn State.MakeState<T>(this.makePromiseForObj<T>(result, () => obj));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// No PostConstruct, just return a resolved State\n\t\treturn State.MakeState<T>(null, undefined, obj);\n\t}\n\n\t/**\n\t * This method collects the States of all the constructor parameters for our target class.\n\t */\n\tprotected getConstructorParameterStates(): State[] {\n\t\tconst argTypes = Reflect.getMetadata(REFLECT_PARAMS, this.maker);\n\t\tif (argTypes === undefined || !Array.isArray(argTypes)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn argTypes.map((argType, index) => {\n\t\t\t// The reflect-metadata API fails on circular dependencies, and will return undefined for the argument instead.\n\t\t\tif (argType === undefined) {\n\t\t\t\tthrow new Error(`Injection error. Recursive dependency in constructor for ${this.maker.toString()} at index ${index}`);\n\t\t\t}\n\t\t\t// Check if an Inject annotation precedes the parameter.\n\t\t\tconst overrideToken = _getInjectedIdAt(this.maker, index);\n\t\t\tconst actualToken = overrideToken === undefined ? argType : overrideToken;\n\t\t\t// Ask our container to resolve the parameter.\n\t\t\t/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\t\t\tlet param = (this.injector as StateResolvingInjector).resolveState(actualToken);\n\t\t\t// If the parameter could not be resolved, see if there is an @Optional annotation\n\t\t\tif ((!param.pending) && param.rejected) {\n\t\t\t\tconst md = _getOptionalDefaultAt(this.maker, index);\n\t\t\t\tif (md)\n\t\t\t\t\tparam = State.MakeState<any>(null, undefined, md.value);\n\t\t\t}\n\t\t\treturn param;\n\t\t});\n\t}\n\n\t/**\n\t * Gather the needed constructor parameters, invoke the constructor, and figure out what post construction needs done.\n\t */\n\tprivate provideAsStateImpl(): State<T> {\n\t\tconst params = this.getConstructorParameterStates();\n\n\t\t// If any of the params are in a rejected state, we cannot construct.\n\t\tconst paramRejection = params.find((p) => {\n\t\t\treturn (!p.pending) && p.rejected;\n\t\t});\n\t\tif (paramRejection) {\n\t\t\treturn paramRejection as State<T>;\n\t\t}\n\t\t// If any of the params are in a pending state, we will have to wait for them to be resolved before we can construct.\n\t\tconst pendingParams = params.filter((p) => {\n\t\t\treturn p.pending;\n\t\t}).map((p) => {\n\t\t\treturn p.promise;\n\t\t});\n\t\tif (pendingParams.length > 0) {\n\t\t\t// Some of the parameters needed for construction are not yet available, wait for them and then attempt construction.\n\t\t\tconst objPromise = this.makePromiseForObj<any[]>(Promise.all(pendingParams), () => {\n\t\t\t\t// All the parameters are now available, instantiate the class.\n\t\t\t\t// If this throws, it will be handled by our caller.\n\t\t\t\treturn Reflect.construct(this.maker, params.map((p) => p.fulfilled as unknown));\n\t\t\t});\n\t\t\t// Once the obj is resolved, then we need to check for PostConstruct and if it was async, wait for that too.\n\t\t\treturn State.MakeState<T>(objPromise.then((obj) => {\n\t\t\t\tconst state = this.makePostConstructState(obj);\n\t\t\t\tif (state.pending) {\n\t\t\t\t\treturn state.promise; // chain (aka wait some more).\n\t\t\t\t}\n\t\t\t\telse if (state.rejected) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\t\t\treturn state.rejected as any; // error\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn state.fulfilled; // value (aka obj).\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\t// All parameters needed for construction are available, instantiate the object.\n\t\t\ttry {\n\t\t\t\tconst newObj = Reflect.construct(this.maker, params.map((p) => p.fulfilled as unknown));\n\t\t\t\treturn this.makePostConstructState(newObj);\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\t// There was an error, give the errorHandler (if any) a crack at recovery.\n\t\t\t\ttry {\n\t\t\t\t\treturn State.MakeState<T>(null, undefined, this.queryErrorHandler(err));\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\t// could not recover, propagate the error.\n\t\t\t\t\treturn State.MakeState<T>(null, e, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"class-provider.js","sourceRoot":"","sources":["../../src/class-provider.ts"],"names":[],"mappings":";;;AAAA,iEAAwD;AACxD,iDAAiH;AACjH,mDAAwE;AAExE,yCAAiC;AACjC,yCAAqC;AAYrC;;;GAGG;AACH,MAAa,kBAAsB,SAAQ,uCAAwC;IAClF,YAAY,QAAgC,EAAE,EAAmB,EAAE,KAA0B;QAC5F,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,cAAc;QACb,IAAI,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;SACnC;QACD,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI;YAC1B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;QACzB,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,kBAAkB,CAAC,SAAkB;QACpC,IAAI,CAAC,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,WAAW,CAAC,+CAAgC,EAAE,IAAI,CAAC,KAAK,CAAC;YACpF,OAAO,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;OAEG;IACO,sBAAsB,CAAC,GAAM;;QACtC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE;YACxE,IAAI,UAAU,GAAG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ider} from './bindable-provider.js';\nimport {POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_PARAMS} from './constants.js';\nimport {_getInjectedIdAt, _getOptionalDefaultAt} from './decorators.js';\nimport {ClassConstructor, InjectableId, Injector} from './injector.js';\nimport {State} from './state.js';\nimport {isPromise} from './utils.js';\n\n/*\n * This is a bit of a hack, but it avoids a ton of alternative hacks.\n * Note that in the Container, resolveState is a protected method.\n * Injector was never meant to publicly expose State.\n * Gotta love JS!\n */\ninterface StateResolvingInjector extends Injector {\n\tresolveState<T>(id: InjectableId<T>): State<T>;\n}\n\n/**\n * @inheritDoc\n * This specialization invokes it's configured class constructor synchronously and then scans for (and invokes) any @PostConstruct (which may be synchronous or asynchronous).\n */\nexport class ClassBasedProvider<T> extends BindableProvider<T, ClassConstructor<T>> {\n\tconstructor(injector: StateResolvingInjector, id: InjectableId<T>, maker: ClassConstructor<T>) {\n\t\tsuper(injector, id, maker);\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * @see the class description for this Provider.\n\t * This method is just a singleton guard, the real work is done by provideAsStateImpl.\n\t */\n\tprovideAsState(): State<T> {\n\t\tlet retVal = this.singleton;\n\t\tif (!retVal) {\n\t\t\tretVal = this.provideAsStateImpl();\n\t\t}\n\t\tif (this.singleton === null)\n\t\t\tthis.singleton = retVal;\n\t\treturn retVal;\n\t}\n\n\t/**\n\t * @inheritDoc\n\t * This specialization returns undefined if 'asyncOnly' is true and there is no asynchronous PostConstruct annotation (since class constructors can never by asynchronous).\n\t */\n\tresolveIfSingleton(asyncOnly: boolean): Promise<T> {\n\t\tif ((!asyncOnly) || Reflect.getMetadata(POSTCONSTRUCT_ASYNC_METADATA_KEY, this.maker))\n\t\t\treturn super.resolveIfSingleton(false);\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Make a resolved or pending State that reflects any @PostConstruct annotations.\n\t */\n\tprotected makePostConstructState(obj: T): State<T> {\n\t\tif (typeof obj === 'object' && (!Array.isArray(obj)) && obj.constructor) {\n\t\t\tlet maybeAsync = false;\n\t\t\tlet pcFn: () => void | Error | Promise<void | Error>;\n\t\t\tif (typeof this.successHandler === 'function') {\n\t\t\t\tmaybeAsync = true;\n\t\t\t\tpcFn = () => {\n\t\t\t\t\treturn this.successHandler(obj, this.injector, this.id, this.maker);\n\t\t\t\t};\n\t\t\t}\n\t\t\telse {\n\t\t\t\t/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */\n\t\t\t\t// Check to see if there is a @PostConstruct annotation on a method of the class.\n\t\t\t\tlet postConstruct: string = Reflect.getMetadata(POSTCONSTRUCT_SYNC_METADATA_KEY, obj.constructor);\n\t\t\t\tif (!postConstruct) {\n\t\t\t\t\tmaybeAsync = true;\n\t\t\t\t\tpostConstruct = Reflect.getMetadata(POSTCONSTRUCT_ASYNC_METADATA_KEY, obj.constructor);\n\t\t\t\t}\n\t\t\t\tif (postConstruct && obj.constructor.prototype[postConstruct] && typeof obj.constructor.prototype[postConstruct] === 'function')\n\t\t\t\t\tpcFn = obj[postConstruct].bind?.(obj);\n\n\t\t\t\t/* eslint-enable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */\n\t\t\t}\n\t\t\tif (pcFn) {\n\t\t\t\tlet result: any;\n\t\t\t\ttry {\n\t\t\t\t\tresult = pcFn();\n\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\t// The post construction method threw while executing, give the errorHandler (if any) a crack at recovery.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tobj = this.queryErrorHandler(err, obj); // The returned obj is unlikely to be the original obj.\n\t\t\t\t\t\treturn State.MakeState<T>(null, undefined, obj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {\n\t\t\t\t\t\t// could not recover, propagate the error.\n\t\t\t\t\t\treturn State.MakeState<T>(null, e, undefined);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// The post construction method says it will let us know when it's finished.\n\t\t\t\tif (result && (result instanceof Promise || (maybeAsync && isPromise<void>(result)))) {\n\t\t\t\t\t// Return a State that is pending (the other return statements in this method return a State which is resolved or rejected).\n\t\t\t\t\t/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\t\t\t\t\treturn State.MakeState<T>(this.makePromiseForObj<T>(result, () => obj));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// No PostConstruct, just return a resolved State\n\t\treturn State.MakeState<T>(null, undefined, obj);\n\t}\n\n\t/**\n\t * This method collects the States of all the constructor parameters for our target class.\n\t */\n\tprotected getConstructorParameterStates(): State[] {\n\t\tconst argTypes = Reflect.getMetadata(REFLECT_PARAMS, this.maker);\n\t\tif (argTypes === undefined || !Array.isArray(argTypes)) {\n\t\t\treturn [];\n\t\t}\n\t\treturn argTypes.map((argType, index) => {\n\t\t\t// The reflect-metadata API fails on circular dependencies, and will return undefined for the argument instead.\n\t\t\tif (argType === undefined) {\n\t\t\t\tthrow new Error(`Injection error. Recursive dependency in constructor for ${this.maker.toString()} at index ${index}`);\n\t\t\t}\n\t\t\t// Check if an Inject annotation precedes the parameter.\n\t\t\tconst overrideToken = _getInjectedIdAt(this.maker, index);\n\t\t\tconst actualToken = overrideToken === undefined ? argType : overrideToken;\n\t\t\t// Ask our container to resolve the parameter.\n\t\t\t/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\t\t\tlet param = (this.injector as StateResolvingInjector).resolveState(actualToken);\n\t\t\t// If the parameter could not be resolved, see if there is an @Optional annotation\n\t\t\tif ((!param.pending) && param.rejected) {\n\t\t\t\tconst md = _getOptionalDefaultAt(this.maker, index);\n\t\t\t\tif (md)\n\t\t\t\t\tparam = State.MakeState<any>(null, undefined, md.value);\n\t\t\t}\n\t\t\treturn param;\n\t\t});\n\t}\n\n\t/**\n\t * Gather the needed constructor parameters, invoke the constructor, and figure out what post construction needs done.\n\t */\n\tprivate provideAsStateImpl(): State<T> {\n\t\tconst params = this.getConstructorParameterStates();\n\n\t\t// If any of the params are in a rejected state, we cannot construct.\n\t\tconst paramRejection = params.find((p) => {\n\t\t\treturn (!p.pending) && p.rejected;\n\t\t});\n\t\tif (paramRejection) {\n\t\t\treturn paramRejection as State<T>;\n\t\t}\n\t\t// If any of the params are in a pending state, we will have to wait for them to be resolved before we can construct.\n\t\tconst pendingParams = params.filter((p) => {\n\t\t\treturn p.pending;\n\t\t}).map((p) => {\n\t\t\treturn p.promise;\n\t\t});\n\t\tif (pendingParams.length > 0) {\n\t\t\t// Some of the parameters needed for construction are not yet available, wait for them and then attempt construction.\n\t\t\tconst objPromise = this.makePromiseForObj<any[]>(Promise.all(pendingParams), () => {\n\t\t\t\t// All the parameters are now available, instantiate the class.\n\t\t\t\t// If this throws, it will be handled by our caller.\n\t\t\t\treturn Reflect.construct(this.maker, params.map((p) => p.fulfilled as unknown));\n\t\t\t});\n\t\t\t// Once the obj is resolved, then we need to check for PostConstruct and if it was async, wait for that too.\n\t\t\treturn State.MakeState<T>(objPromise.then((obj) => {\n\t\t\t\tconst state = this.makePostConstructState(obj);\n\t\t\t\tif (state.pending) {\n\t\t\t\t\treturn state.promise; // chain (aka wait some more).\n\t\t\t\t}\n\t\t\t\telse if (state.rejected) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\t\t\treturn state.rejected as any; // error\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\treturn state.fulfilled; // value (aka obj).\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\t\telse {\n\t\t\t// All parameters needed for construction are available, instantiate the object.\n\t\t\ttry {\n\t\t\t\tconst newObj = Reflect.construct(this.maker, params.map((p) => p.fulfilled as unknown));\n\t\t\t\treturn this.makePostConstructState(newObj);\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\t// There was an error, give the errorHandler (if any) a crack at recovery.\n\t\t\t\ttry {\n\t\t\t\t\treturn State.MakeState<T>(null, undefined, this.queryErrorHandler(err));\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\t// could not recover, propagate the error.\n\t\t\t\t\treturn State.MakeState<T>(null, e, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstantProvider = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const provider_js_1 = require("./provider.js");
|
|
5
|
+
const state_js_1 = require("./state.js");
|
|
6
6
|
/**
|
|
7
7
|
* @inheritDoc
|
|
8
8
|
* This specialization is always a Singleton.
|
|
9
9
|
*/
|
|
10
|
-
class ConstantProvider extends
|
|
10
|
+
class ConstantProvider extends provider_js_1.Provider {
|
|
11
11
|
constructor(constant) {
|
|
12
12
|
super();
|
|
13
|
-
this.singleton =
|
|
13
|
+
this.singleton = state_js_1.State.MakeState(null, undefined, constant);
|
|
14
14
|
}
|
|
15
15
|
provideAsState() {
|
|
16
16
|
return this.singleton;
|