async-injection 1.2.4 → 1.3.0
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 +43 -1
- package/ReadMe.md +6 -2
- package/lib/cjs/async-factory-provider.d.ts +10 -2
- package/lib/cjs/async-factory-provider.js +11 -1
- package/lib/cjs/async-factory-provider.js.map +1 -1
- package/lib/cjs/bindable-provider.d.ts +34 -2
- package/lib/cjs/bindable-provider.js +52 -22
- package/lib/cjs/bindable-provider.js.map +1 -1
- package/lib/cjs/binder.d.ts +85 -1
- package/lib/cjs/binder.js.map +1 -1
- package/lib/cjs/class-provider.d.ts +24 -2
- package/lib/cjs/class-provider.js +59 -13
- package/lib/cjs/class-provider.js.map +1 -1
- package/lib/cjs/constant-provider.d.ts +5 -1
- package/lib/cjs/constant-provider.js +5 -1
- package/lib/cjs/constant-provider.js.map +1 -1
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/container.d.ts +54 -1
- package/lib/cjs/container.js +104 -22
- package/lib/cjs/container.js.map +1 -1
- package/lib/cjs/decorators.d.ts +53 -6
- package/lib/cjs/decorators.js +110 -14
- package/lib/cjs/decorators.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +5 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/injector.d.ts +29 -3
- package/lib/cjs/injector.js.map +1 -1
- package/lib/cjs/provider.d.ts +30 -0
- package/lib/cjs/provider.js +38 -1
- package/lib/cjs/provider.js.map +1 -1
- package/lib/cjs/state.d.ts +7 -4
- package/lib/cjs/state.js +6 -2
- package/lib/cjs/state.js.map +1 -1
- package/lib/cjs/sync-factory-provider.d.ts +14 -2
- package/lib/cjs/sync-factory-provider.js +16 -1
- package/lib/cjs/sync-factory-provider.js.map +1 -1
- package/lib/cjs/utils.d.ts +14 -0
- package/lib/cjs/utils.js +48 -0
- package/lib/cjs/utils.js.map +1 -0
- package/lib/esm/async-factory-provider.d.ts +10 -2
- package/lib/esm/async-factory-provider.js +11 -1
- package/lib/esm/async-factory-provider.js.map +1 -1
- package/lib/esm/bindable-provider.d.ts +34 -2
- package/lib/esm/bindable-provider.js +50 -20
- package/lib/esm/bindable-provider.js.map +1 -1
- package/lib/esm/binder.d.ts +85 -1
- package/lib/esm/binder.js.map +1 -1
- package/lib/esm/class-provider.d.ts +24 -2
- package/lib/esm/class-provider.js +59 -13
- package/lib/esm/class-provider.js.map +1 -1
- package/lib/esm/constant-provider.d.ts +5 -1
- package/lib/esm/constant-provider.js +5 -1
- package/lib/esm/constant-provider.js.map +1 -1
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/container.d.ts +54 -1
- package/lib/esm/container.js +104 -22
- package/lib/esm/container.js.map +1 -1
- package/lib/esm/decorators.d.ts +53 -6
- package/lib/esm/decorators.js +109 -14
- package/lib/esm/decorators.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/injector.d.ts +29 -3
- package/lib/esm/injector.js.map +1 -1
- package/lib/esm/provider.d.ts +30 -0
- package/lib/esm/provider.js +38 -1
- package/lib/esm/provider.js.map +1 -1
- package/lib/esm/state.d.ts +7 -4
- package/lib/esm/state.js +6 -2
- package/lib/esm/state.js.map +1 -1
- package/lib/esm/sync-factory-provider.d.ts +14 -2
- package/lib/esm/sync-factory-provider.js +16 -1
- package/lib/esm/sync-factory-provider.js.map +1 -1
- package/lib/esm/utils.d.ts +14 -0
- package/lib/esm/utils.js +42 -0
- package/lib/esm/utils.js.map +1 -0
- package/package.json +17 -12
package/Changelog.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Fix issue #1
|
|
3
3
|
Update ts-node and source-map-support devDependencies
|
|
4
4
|
Add tslint and Changelog
|
|
5
|
-
Update ReadMe with badges
|
|
5
|
+
Update ReadMe with badges
|
|
6
6
|
|
|
7
7
|
**1.0.8 / 2020-06-08**
|
|
8
8
|
Add ability to walk up the parent container hierarchy to methods Injector.isIdKnown and Container.removeBinding
|
|
@@ -13,3 +13,45 @@ Update ts-node and nyc devDependencies.
|
|
|
13
13
|
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.
|
|
14
14
|
Updated tslib
|
|
15
15
|
Updated jasmine devDependency.
|
|
16
|
+
|
|
17
|
+
**1.2.0 / 2021-06-08**
|
|
18
|
+
New Feature: Allow alternate polyfill for Reflect API
|
|
19
|
+
WARNING: This is a a breaking change release.
|
|
20
|
+
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).
|
|
21
|
+
Previously Async-Injection relied on reflect-metadata (which is still supported), but this release also allows for the use of alternative implementations such as:
|
|
22
|
+
core-js (core-js/es7/reflect)
|
|
23
|
+
reflection
|
|
24
|
+
Thank you to @tripodsgames for this contribution.
|
|
25
|
+
|
|
26
|
+
**1.2.3 / 2021-06-11**
|
|
27
|
+
cjs and esm distributions.
|
|
28
|
+
Build now generates both cjs and esm distributions.
|
|
29
|
+
tslib (where used) is now inlined instead of imported.
|
|
30
|
+
No other code changes.
|
|
31
|
+
|
|
32
|
+
**1.2.4 / 2021-06-17**
|
|
33
|
+
Build esm into esm dir (not mjs).
|
|
34
|
+
No actual source code changes.
|
|
35
|
+
|
|
36
|
+
**1.2.5 / 2021-06-28**
|
|
37
|
+
No actual source code changes.
|
|
38
|
+
Added Reflect type from reflect-metadata in order to remove the @ts-ignore comments.
|
|
39
|
+
Improved tsconfig.json structure for IDE compatibility.
|
|
40
|
+
Thanks to @tripodsgames for those contributions.
|
|
41
|
+
Update tsc devDependency from 4.3.3 to 4.3.4.
|
|
42
|
+
Update the ChangeLog to properly reflect recent GitHub releases.
|
|
43
|
+
|
|
44
|
+
**1.2.6 / 2021-07-14**
|
|
45
|
+
Merge PR #9 [ESLINT integration + Improvements](https://github.com/pcafstockf/async-injection/pull/9).
|
|
46
|
+
Update devDependencies.
|
|
47
|
+
Resolved a couple of eslint warnings.
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
**1.2.7 / 2021-08-02**
|
|
51
|
+
Revert type declaration for AbstractConstructor which was broken during eslint integration.
|
|
52
|
+
Update eslint related dev-dependencies.
|
|
53
|
+
|
|
54
|
+
**1.3.0 / 2021-11-27**
|
|
55
|
+
Support Container driven release of Singleton allocated resources (see Container.releaseSingletons).
|
|
56
|
+
Update devDependencies.
|
|
57
|
+
Minor updates to ReadMe.
|
package/ReadMe.md
CHANGED
|
@@ -18,7 +18,8 @@ You can get the latest release using npm:
|
|
|
18
18
|
$ npm install async-injection --save
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
To enhance flexibility, Async-Injection does not dictate which Reflect API implementation you use. However, you will need to explicitly choose and load one.
|
|
22
|
+
You can use:
|
|
22
23
|
|
|
23
24
|
- [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
|
|
24
25
|
- [core-js (core-js/es7/reflect)](https://www.npmjs.com/package/core-js)
|
|
@@ -32,6 +33,9 @@ import "reflect-metadata";
|
|
|
32
33
|
// Your code here...
|
|
33
34
|
```
|
|
34
35
|
|
|
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
|
+
|
|
35
39
|
## Basic Usage (synchronous)
|
|
36
40
|
Here we 'get' a new transaction handling object, that itself, relies on a shared service:
|
|
37
41
|
|
|
@@ -233,7 +237,7 @@ Thanks to Carlos Delgado for the idea of a ["QuerablePromise"](https://ourcodewo
|
|
|
233
237
|
|
|
234
238
|
## MIT License
|
|
235
239
|
|
|
236
|
-
Copyright (c)
|
|
240
|
+
Copyright (c) 2021 Frank Stock
|
|
237
241
|
|
|
238
242
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
239
243
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BindableProvider } from './bindable-provider';
|
|
2
2
|
import { AsyncFactory } from './binder';
|
|
3
|
+
import { InjectableId, Injector } from './injector';
|
|
3
4
|
import { State } from './state';
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @inheritDoc
|
|
7
|
+
* This specialization invokes it's configured Factory asynchronously and waits until it can provide the result.
|
|
8
|
+
*/
|
|
5
9
|
export declare class AsyncFactoryBasedProvider<T> extends BindableProvider<T, AsyncFactory<T>> {
|
|
6
10
|
constructor(injector: Injector, id: InjectableId<T>, maker: AsyncFactory<T>);
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
* This specialization invokes it's configured Factory and provides the result (or invokes the error handler if necessary).
|
|
14
|
+
*/
|
|
7
15
|
provideAsState(): State<T>;
|
|
8
16
|
}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncFactoryBasedProvider = void 0;
|
|
4
|
-
const state_1 = require("./state");
|
|
5
4
|
const bindable_provider_1 = require("./bindable-provider");
|
|
5
|
+
const state_1 = require("./state");
|
|
6
|
+
/**
|
|
7
|
+
* @inheritDoc
|
|
8
|
+
* This specialization invokes it's configured Factory asynchronously and waits until it can provide the result.
|
|
9
|
+
*/
|
|
6
10
|
class AsyncFactoryBasedProvider extends bindable_provider_1.BindableProvider {
|
|
7
11
|
constructor(injector, id, maker) {
|
|
8
12
|
super(injector, id, maker);
|
|
9
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
* This specialization invokes it's configured Factory and provides the result (or invokes the error handler if necessary).
|
|
17
|
+
*/
|
|
10
18
|
provideAsState() {
|
|
11
19
|
let retVal = this.singleton;
|
|
12
20
|
if (!retVal) {
|
|
21
|
+
// Wrap the async factory's Promise in an errorHandler aware Promise.
|
|
22
|
+
// Our contract is that an AsyncFactory may not throw and must return a valid Promise (e.g. pending, resolved, rejected, etc).
|
|
13
23
|
retVal = state_1.State.MakeState(this.makePromiseForObj(this.maker(this.injector), obj => obj));
|
|
14
24
|
}
|
|
15
25
|
if (this.singleton === null)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-factory-provider.js","sourceRoot":"","sources":["../../src/async-factory-provider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"async-factory-provider.js","sourceRoot":"","sources":["../../src/async-factory-provider.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAGvD,mCAAgC;AAEhC;;;GAGG;AACH,MAAa,yBAA6B,SAAQ,oCAAoC;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,aAAK,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';\nimport { AsyncFactory } from './binder';\nimport { InjectableId, Injector } from './injector';\nimport { State } from './state';\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,14 +1,46 @@
|
|
|
1
|
-
import { InjectableId, Injector, ClassConstructor } from './injector';
|
|
2
1
|
import { AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory } from './binder';
|
|
2
|
+
import { ClassConstructor, InjectableId, Injector } from './injector';
|
|
3
3
|
import { Provider } from './provider';
|
|
4
|
+
/**
|
|
5
|
+
* @inheritDoc
|
|
6
|
+
* This abstraction is for Providers that can be additionally configured as Singletons and/or configured with error and/or success handling callback(s).
|
|
7
|
+
*/
|
|
4
8
|
export declare abstract class BindableProvider<T, M = ClassConstructor<T> | SyncFactory<T> | AsyncFactory<T>> extends Provider<T> {
|
|
5
9
|
protected injector: Injector;
|
|
6
10
|
protected id: InjectableId<T>;
|
|
7
11
|
protected maker: M;
|
|
8
12
|
protected constructor(injector: Injector, id: InjectableId<T>, maker: M);
|
|
13
|
+
/**
|
|
14
|
+
* A user supplied success handling function.
|
|
15
|
+
* Default value is undefined.
|
|
16
|
+
*/
|
|
9
17
|
protected successHandler?: OnSuccessCallback<T, any>;
|
|
18
|
+
/**
|
|
19
|
+
* A user supplied error handling function.
|
|
20
|
+
* Default value is undefined.
|
|
21
|
+
*/
|
|
10
22
|
protected errorHandler?: OnErrorCallback<T, any>;
|
|
23
|
+
/**
|
|
24
|
+
* Invoked by the Binder to create chain-able configuration
|
|
25
|
+
*
|
|
26
|
+
* @see BindAs
|
|
27
|
+
*/
|
|
11
28
|
makeBindAs(): BindAs<T, M>;
|
|
12
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Encapsulate the logic of invoking any configured error handler, and processing it's result.
|
|
31
|
+
*
|
|
32
|
+
* @see OnErrorCallback
|
|
33
|
+
*
|
|
34
|
+
* @returns The object substituted by the callback (otherwise this method throws the appropriate error).
|
|
35
|
+
*/
|
|
36
|
+
protected queryErrorHandler(err: Error, obj?: T): T;
|
|
37
|
+
/**
|
|
38
|
+
* This is like a retry mechanism that uses the Provider's errorHandler (if any) to attempt recovery whenever the supplied Promise rejects.
|
|
39
|
+
* This method returns a Promise that rejects if recovery was not possible.
|
|
40
|
+
* If the supplied Promise resolves, then this method passes the result to the callback, and then resolve as whatever that callback returns.
|
|
41
|
+
*
|
|
42
|
+
* @param waitFor The supplied Promise.
|
|
43
|
+
* @param cb Callback to be invoked if the supplied Promise resolves.
|
|
44
|
+
*/
|
|
13
45
|
protected makePromiseForObj<R>(waitFor: Promise<R>, cb: (result: R) => T): Promise<T>;
|
|
14
46
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BindableProvider = void 0;
|
|
4
4
|
const provider_1 = require("./provider");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
/**
|
|
7
|
+
* @inheritDoc
|
|
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
|
+
*/
|
|
10
10
|
class BindableProvider extends provider_1.Provider {
|
|
11
11
|
constructor(injector, id, maker) {
|
|
12
12
|
super();
|
|
@@ -14,47 +14,77 @@ class BindableProvider extends provider_1.Provider {
|
|
|
14
14
|
this.id = id;
|
|
15
15
|
this.maker = maker;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Invoked by the Binder to create chain-able configuration
|
|
19
|
+
*
|
|
20
|
+
* @see BindAs
|
|
21
|
+
*/
|
|
17
22
|
makeBindAs() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const retVal = {
|
|
24
|
+
onError: (cb) => {
|
|
25
|
+
this.errorHandler = cb;
|
|
26
|
+
},
|
|
27
|
+
onSuccess: (cb) => {
|
|
28
|
+
this.successHandler = cb;
|
|
29
|
+
return retVal;
|
|
30
|
+
},
|
|
31
|
+
asSingleton: () => {
|
|
32
|
+
this.singleton = null; // Flag state as no longer undefined.
|
|
33
|
+
return retVal;
|
|
34
|
+
}
|
|
29
35
|
};
|
|
30
36
|
return retVal;
|
|
31
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Encapsulate the logic of invoking any configured error handler, and processing it's result.
|
|
40
|
+
*
|
|
41
|
+
* @see OnErrorCallback
|
|
42
|
+
*
|
|
43
|
+
* @returns The object substituted by the callback (otherwise this method throws the appropriate error).
|
|
44
|
+
*/
|
|
32
45
|
queryErrorHandler(err, obj) {
|
|
46
|
+
// There was an error during construction, see if an error handler was provided, and if so, see what it wants to do.
|
|
33
47
|
if (this.errorHandler) {
|
|
34
|
-
|
|
35
|
-
|
|
48
|
+
const handlerResult = this.errorHandler(this.injector, this.id, this.maker, err, obj);
|
|
49
|
+
// Error handler wants us to propagate an error.
|
|
50
|
+
if (utils_1.isErrorObj(handlerResult))
|
|
36
51
|
throw handlerResult;
|
|
52
|
+
// Error handler has no opinion, so provideAsState a state that reflects the error we just caught.
|
|
37
53
|
if (typeof handlerResult === 'undefined')
|
|
38
54
|
throw err;
|
|
55
|
+
// Error handler provided a valid (fully resolved) replacement.
|
|
39
56
|
return handlerResult;
|
|
40
57
|
}
|
|
58
|
+
// No error handler, provideAsState a state that reflects the error we just caught.
|
|
41
59
|
throw err;
|
|
42
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* This is like a retry mechanism that uses the Provider's errorHandler (if any) to attempt recovery whenever the supplied Promise rejects.
|
|
63
|
+
* This method returns a Promise that rejects if recovery was not possible.
|
|
64
|
+
* If the supplied Promise resolves, then this method passes the result to the callback, and then resolve as whatever that callback returns.
|
|
65
|
+
*
|
|
66
|
+
* @param waitFor The supplied Promise.
|
|
67
|
+
* @param cb Callback to be invoked if the supplied Promise resolves.
|
|
68
|
+
*/
|
|
43
69
|
makePromiseForObj(waitFor, cb) {
|
|
44
70
|
return new Promise((resolve, reject) => {
|
|
45
71
|
const errHandlerFn = (err) => {
|
|
72
|
+
// There was an error during async post construction, see if an error handler was provided, and if so, see what it wants to do.
|
|
46
73
|
if (this.errorHandler) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
74
|
+
const handlerResult = this.errorHandler(this.injector, this.id, this.maker, err);
|
|
75
|
+
// Error handler wants us to propagate an alternative error.
|
|
76
|
+
if (utils_1.isErrorObj(handlerResult))
|
|
77
|
+
err = handlerResult; // Fall thru
|
|
50
78
|
else if (typeof handlerResult !== 'undefined') {
|
|
51
|
-
resolve(handlerResult);
|
|
79
|
+
resolve(handlerResult); // Error handler provided a replacement, so change the State that we returned from pending to resolved.
|
|
52
80
|
return;
|
|
53
81
|
}
|
|
54
82
|
}
|
|
83
|
+
// This will change the State that we returned from pending to rejected.
|
|
55
84
|
reject(err);
|
|
56
85
|
};
|
|
57
86
|
waitFor.then((result) => {
|
|
87
|
+
// This will change the State that we returned from pending to resolved.
|
|
58
88
|
try {
|
|
59
89
|
resolve(cb(result));
|
|
60
90
|
}
|
|
@@ -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,yCAAsC;AACtC,mCAAqC;AAErC;;;GAGG;AACH,MAAsB,gBAAgF,SAAQ,mBAAW;IACxH,YAAgC,QAAkB,EAAY,EAAmB,EAAY,KAAQ;QACpG,KAAK,EAAE,CAAC;QADuB,aAAQ,GAAR,QAAQ,CAAU;QAAY,OAAE,GAAF,EAAE,CAAiB;QAAY,UAAK,GAAL,KAAK,CAAG;IAErG,CAAC;IAcD;;;;OAIG;IACH,UAAU;QACT,MAAM,MAAM,GAAiB;YAC5B,OAAO,EAAE,CAAC,EAAyB,EAAE,EAAE;gBACtC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;YACxB,CAAC;YACD,SAAS,EAAE,CAAC,EAA2B,EAAE,EAAE;gBAC1C,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;gBACzB,OAAO,MAAM,CAAC;YACf,CAAC;YACD,WAAW,EAAE,GAAG,EAAE;gBACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,qCAAqC;gBAC5D,OAAO,MAAM,CAAC;YACf,CAAC;SACD,CAAC;QACF,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACO,iBAAiB,CAAC,GAAU,EAAE,GAAO;QAC9C,oHAAoH;QACpH,IAAI,IAAI,CAAC,YAAY,EAAE;YACtB,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YACtF,gDAAgD;YAChD,IAAI,kBAAU,CAAC,aAAa,CAAC;gBAC5B,MAAM,aAAa,CAAC;YACrB,kGAAkG;YAClG,IAAI,OAAO,aAAa,KAAK,WAAW;gBACvC,MAAM,GAAG,CAAC;YACX,+DAA+D;YAC/D,OAAO,aAAa,CAAC;SACrB;QACD,mFAAmF;QACnF,MAAM,GAAG,CAAC;IACX,CAAC;IAED;;;;;;;OAOG;IACO,iBAAiB,CAAI,OAAmB,EAAE,EAAoB;QACvE,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,YAAY,GAAG,CAAC,GAAQ,EAAE,EAAE;gBACjC,+HAA+H;gBAC/H,IAAI,IAAI,CAAC,YAAY,EAAE;oBACtB,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;oBACjF,4DAA4D;oBAC5D,IAAI,kBAAU,CAAC,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,CAAC,CAAC;iBAClB;YACF,CAAC,CACD,CAAC,KAAK,CACN,CAAC,GAAG,EAAE,EAAE;gBACP,YAAY,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAzGD,4CAyGC","sourcesContent":["import { AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory } from './binder';\nimport { ClassConstructor, InjectableId, Injector } from './injector';\nimport { Provider } from './provider';\nimport { isErrorObj } from './utils';\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: Error, 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) => {\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);\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);\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);\n\t\t\t\t}\n\t\t\t);\n\t\t});\n\t}\n}\n"]}
|
package/lib/cjs/binder.d.ts
CHANGED
|
@@ -1,22 +1,106 @@
|
|
|
1
|
-
import { ClassConstructor, InjectableId, Injector
|
|
1
|
+
import { AbstractConstructor, ClassConstructor, InjectableId, Injector } from './injector';
|
|
2
|
+
/**
|
|
3
|
+
* Type definition for functions that return a value.
|
|
4
|
+
* The function should return a valid value, but may throw an exception if it cannot.
|
|
5
|
+
*/
|
|
2
6
|
export declare type SyncFactory<T> = (injector: Injector) => T;
|
|
7
|
+
/**
|
|
8
|
+
* Type definition for functions that return a Promise for a value.
|
|
9
|
+
* The function *must* not throw and must return a valid Promise (e.g. pending, resolved, rejected).
|
|
10
|
+
*/
|
|
3
11
|
export declare type AsyncFactory<T> = (injector: Injector) => Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* You may bind an error handler which will be invoked, if the bound InjectableId could not be put into service.
|
|
14
|
+
* An error handler *must* not throw, but may return an Error that will be propagated back up the call chain.
|
|
15
|
+
*
|
|
16
|
+
* @param binder The Binder that experienced the error.
|
|
17
|
+
* @param id The identifier for what was trying to be made.
|
|
18
|
+
* @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.
|
|
19
|
+
* @param error Identifies the problem that occurred.
|
|
20
|
+
* @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.
|
|
21
|
+
* @returns one of 3 results...
|
|
22
|
+
* A substitute thing (kind of like a 'maker' do-over) which must be fully operational (e.g. any `@PostConstruct` will be ignored).
|
|
23
|
+
* An alternate Error which will be propagated back up the call chain.
|
|
24
|
+
* Undefined, which means the 'error' parameter will be propagated back up the call chain.
|
|
25
|
+
*/
|
|
4
26
|
export declare type OnErrorCallback<T, M> = (injector: Injector, id: InjectableId<T>, maker: M, error: Error, value?: T) => T | Error | void;
|
|
27
|
+
/**
|
|
28
|
+
* You may bind a success handler which will be invoked just before the bound InjectableId is put into service.
|
|
29
|
+
* This is an alternative to the more preferred `@PostConstruct` decorator for scenarios when usage of that decorator is not feasible.
|
|
30
|
+
* WARNING:
|
|
31
|
+
* By registering a success handler, you override and nullify any `@PostConstruct` decorator on the class.
|
|
32
|
+
* In such a scenario, the success handler should perform whatever care and feeding the class expected from the `@PostConstruct` decorator.
|
|
33
|
+
* A success handler *must* not throw, but may return an Error that will be propagated back up the call chain.
|
|
34
|
+
*
|
|
35
|
+
* @param binder The Binder that performed the construction.
|
|
36
|
+
* @param id The identifier for what was made.
|
|
37
|
+
* @param maker The thing that made. Will be one of type ClassConstructor, SyncFactory, or AsyncFactory, depending on how you registered the binding.
|
|
38
|
+
* @param value The thing that was made.
|
|
39
|
+
* @returns one of 3 results...
|
|
40
|
+
* An Error which will be propagated back up the call chain.
|
|
41
|
+
* Undefined, which means the object is ready to be placed into service.
|
|
42
|
+
* A Promise that resolves to one of the above two values (undefined or Error).
|
|
43
|
+
*/
|
|
5
44
|
export declare type OnSuccessCallback<T, M> = (value: T, injector: Injector, id: InjectableId<T>, maker: M) => Promise<Error | void> | Error | void;
|
|
45
|
+
/**
|
|
46
|
+
* An interface allowing binding of an error handler.
|
|
47
|
+
*
|
|
48
|
+
* @see OnErrorCallback
|
|
49
|
+
*/
|
|
6
50
|
export interface BindErrHandler<T, M> {
|
|
7
51
|
onError(cb: OnErrorCallback<T, M>): void;
|
|
8
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* An interface allowing binding of a post construction handler.
|
|
55
|
+
*
|
|
56
|
+
* @see OnSuccessCallback
|
|
57
|
+
*/
|
|
9
58
|
export interface BindHandler<T, M> extends BindErrHandler<T, M> {
|
|
10
59
|
onSuccess(cb: OnSuccessCallback<T, M>): BindErrHandler<T, M>;
|
|
11
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* @inheritDoc
|
|
63
|
+
* This specialization also allows you to specify that the binding is 'Singleton' (e.g. only one in the system).
|
|
64
|
+
*/
|
|
12
65
|
export interface BindAs<T, M> extends BindHandler<T, M> {
|
|
13
66
|
asSingleton(): BindHandler<T, M>;
|
|
14
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Bind Ids to producers.
|
|
70
|
+
*/
|
|
15
71
|
export interface Binder extends Injector {
|
|
72
|
+
/**
|
|
73
|
+
* Bind an InjectableId to a constant value.
|
|
74
|
+
* Constants are by their very nature singleton, and are assumed to be error proof.
|
|
75
|
+
*/
|
|
16
76
|
bindConstant<T>(id: InjectableId<T>, value: T): void;
|
|
77
|
+
/**
|
|
78
|
+
* Bind an InjectableId to a class (actually it's constructor).
|
|
79
|
+
* As a shortcut, you may use the class constructor as the 'id' (e.g. container.bindClass(A); ).
|
|
80
|
+
* The container will also invoke any `@PostConstruct` present on the class.
|
|
81
|
+
*/
|
|
17
82
|
bindClass<T>(id: ClassConstructor<T>, constructor?: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;
|
|
18
83
|
bindClass<T>(id: string | symbol | AbstractConstructor<T>, constructor: ClassConstructor<T>): BindAs<T, ClassConstructor<T>>;
|
|
84
|
+
/**
|
|
85
|
+
* Bind an InjectableId to a synchronous factory that will be invoked on demand when the object is needed.
|
|
86
|
+
* The factory should produce the needed value
|
|
87
|
+
* NOTE: The container will not invoke any `@PostConstruct` present on the class, this is the responsibility of the factory.
|
|
88
|
+
*/
|
|
19
89
|
bindFactory<T>(id: InjectableId<T>, factory: SyncFactory<T>): BindAs<T, SyncFactory<T>>;
|
|
90
|
+
/**
|
|
91
|
+
* Bind an InjectableId to an asynchronous factory that will be invoked on demand when the object is needed.
|
|
92
|
+
* The factory should produce the needed value (asynchronously of course).
|
|
93
|
+
* NOTE: The container will not invoke any `@PostConstruct` present on the class, this is the responsibility of the factory.
|
|
94
|
+
* WARNING!!! The factory may not throw and must return a valid Promise (which can be pending, resolved, rejected, etc.).
|
|
95
|
+
*/
|
|
20
96
|
bindAsyncFactory<T>(id: InjectableId<T>, factory: AsyncFactory<T>): BindAs<T, AsyncFactory<T>>;
|
|
97
|
+
/**
|
|
98
|
+
* This essentially pre creates/loads all *singleton* InjectableIds currently known to the Binder.
|
|
99
|
+
* This *may* be helpful if you wish to use Injector.get on a dependency tree that has asynchronous singletons within the tree.
|
|
100
|
+
*
|
|
101
|
+
* @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.
|
|
102
|
+
* @param parentRecursion If true and the the container has a parent, resolveIfSingleton will first be called for the parent
|
|
103
|
+
* @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>
|
|
104
|
+
*/
|
|
21
105
|
resolveSingletons(asyncOnly?: boolean, parentRecursion?: boolean): Promise<void>;
|
|
22
106
|
}
|
package/lib/cjs/binder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binder.js","sourceRoot":"","sources":["../../src/binder.ts"],"names":[],"mappings":"","sourcesContent":["import {ClassConstructor, InjectableId, Injector
|
|
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: Error, 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 * 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\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<void>;\n}\n"]}
|
|
@@ -2,12 +2,34 @@ import { BindableProvider } from './bindable-provider';
|
|
|
2
2
|
import { ClassConstructor, InjectableId, Injector } from './injector';
|
|
3
3
|
import { State } from './state';
|
|
4
4
|
export declare type ResolveStateCallback = (id: InjectableId<any>) => State;
|
|
5
|
+
/**
|
|
6
|
+
* @inheritDoc
|
|
7
|
+
* This specialization invokes it's configured class constructor synchronously and then scans for (and invokes) any @PostConstruct (which may be synchronous or asynchronous).
|
|
8
|
+
*/
|
|
5
9
|
export declare class ClassBasedProvider<T> extends BindableProvider<T, ClassConstructor<T>> {
|
|
6
10
|
protected stateResolver: ResolveStateCallback;
|
|
7
11
|
constructor(injector: Injector, id: InjectableId<T>, maker: ClassConstructor<T>, stateResolver: ResolveStateCallback);
|
|
12
|
+
/**
|
|
13
|
+
* @inheritDoc
|
|
14
|
+
* @see the class description for this Provider.
|
|
15
|
+
* This method is just a singleton guard, the real work is done by provideAsStateImpl.
|
|
16
|
+
*/
|
|
8
17
|
provideAsState(): State<T>;
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
* This specialization returns undefined if 'asyncOnly' is true and there is no asynchronous PostConstruct annotation (since class constructors can never by asynchronous).
|
|
21
|
+
*/
|
|
9
22
|
resolveIfSingleton(asyncOnly: boolean): Promise<T>;
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Make a resolved or pending State that reflects any @PostConstruct annotations.
|
|
25
|
+
*/
|
|
26
|
+
protected makePostConstructState(obj: T): State<T>;
|
|
27
|
+
/**
|
|
28
|
+
* This method collects the States of all the constructor parameters for our target class.
|
|
29
|
+
*/
|
|
30
|
+
protected getConstructorParameterStates(): State[];
|
|
31
|
+
/**
|
|
32
|
+
* Gather the needed constructor parameters, invoke the constructor, and figure out what post construction needs done.
|
|
33
|
+
*/
|
|
12
34
|
private provideAsStateImpl;
|
|
13
35
|
}
|