ditox 1.4.1 → 2.2.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/README.md +6 -5
- package/dist/{index.d.ts → browser/index.d.ts} +98 -42
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cjs/ditox.d.ts +125 -0
- package/dist/cjs/ditox.js +210 -0
- package/dist/cjs/ditox.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/modules.d.ts +118 -0
- package/dist/cjs/modules.js +109 -0
- package/dist/cjs/modules.js.map +1 -0
- package/dist/cjs/utils-deprecated.d.ts +59 -0
- package/dist/cjs/utils-deprecated.js +66 -0
- package/dist/cjs/utils-deprecated.js.map +1 -0
- package/dist/cjs/utils.d.ts +136 -0
- package/dist/cjs/utils.js +156 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/ditox.d.ts +125 -0
- package/{lib/index.js → dist/esm/ditox.js} +10 -201
- package/dist/esm/ditox.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules.d.ts +118 -0
- package/dist/esm/modules.js +102 -0
- package/dist/esm/modules.js.map +1 -0
- package/dist/esm/utils-deprecated.d.ts +59 -0
- package/dist/esm/utils-deprecated.js +59 -0
- package/dist/esm/utils-deprecated.js.map +1 -0
- package/dist/esm/utils.d.ts +136 -0
- package/dist/esm/utils.js +145 -0
- package/dist/esm/utils.js.map +1 -0
- package/{lib → dist/umd}/index.d.ts +98 -42
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +250 -164
- package/docs/classes/{resolvererror.md → ResolverError.md} +14 -12
- package/package.json +15 -16
- package/src/ditox.test.ts +10 -1
- package/src/index.ts +13 -13
- package/src/modules.test.ts +2 -0
- package/src/modules.ts +1 -8
- package/src/utils.test.ts +173 -58
- package/src/utils.ts +164 -66
- package/CHANGELOG.md +0 -121
- package/dist/index.browser.js +0 -2
- package/dist/index.browser.js.flow +0 -4
- package/dist/index.browser.js.map +0 -1
- package/dist/index.js +0 -411
- package/dist/index.js.flow +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index.module.d.ts +0 -301
- package/dist/index.module.js +0 -393
- package/dist/index.module.js.flow +0 -4
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.d.ts +0 -301
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.flow +0 -4
- package/dist/index.umd.js.map +0 -1
- package/lib/index.js.flow +0 -4
- package/lib/index.js.map +0 -1
- package/mod.ts +0 -2
- package/src/ditox.js.flow +0 -131
- package/src/index.js.flow +0 -34
- package/src/modules.js.flow +0 -156
- package/src/utils.js.flow +0 -113
package/docs/README.md
CHANGED
|
@@ -6,7 +6,7 @@ ditox
|
|
|
6
6
|
|
|
7
7
|
### Classes
|
|
8
8
|
|
|
9
|
-
- [ResolverError](classes/
|
|
9
|
+
- [ResolverError](classes/ResolverError.md)
|
|
10
10
|
|
|
11
11
|
### Type aliases
|
|
12
12
|
|
|
@@ -27,14 +27,15 @@ ditox
|
|
|
27
27
|
- [createContainer](README.md#createcontainer)
|
|
28
28
|
- [declareModule](README.md#declaremodule)
|
|
29
29
|
- [declareModuleBindings](README.md#declaremodulebindings)
|
|
30
|
-
- [getProps](README.md#getprops)
|
|
31
|
-
- [getValues](README.md#getvalues)
|
|
32
30
|
- [injectable](README.md#injectable)
|
|
33
|
-
- [
|
|
31
|
+
- [injectableClass](README.md#injectableclass)
|
|
32
|
+
- [isToken](README.md#istoken)
|
|
34
33
|
- [optional](README.md#optional)
|
|
35
|
-
- [
|
|
34
|
+
- [resolveValue](README.md#resolvevalue)
|
|
36
35
|
- [resolveValues](README.md#resolvevalues)
|
|
37
36
|
- [token](README.md#token)
|
|
37
|
+
- [tryResolveValue](README.md#tryresolvevalue)
|
|
38
|
+
- [tryResolveValues](README.md#tryresolvevalues)
|
|
38
39
|
|
|
39
40
|
## Type aliases
|
|
40
41
|
|
|
@@ -56,7 +57,7 @@ Options for module binding.
|
|
|
56
57
|
|
|
57
58
|
#### Defined in
|
|
58
59
|
|
|
59
|
-
[packages/ditox/src/modules.ts:
|
|
60
|
+
[packages/ditox/src/modules.ts:76](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L76)
|
|
60
61
|
|
|
61
62
|
___
|
|
62
63
|
|
|
@@ -70,23 +71,23 @@ Dependency container.
|
|
|
70
71
|
|
|
71
72
|
| Name | Type |
|
|
72
73
|
| :------ | :------ |
|
|
73
|
-
| `bindFactory` | <T\>(`token`: [Token](README.md#token)
|
|
74
|
-
| `bindValue` | <T\>(`token`: [Token](README.md#token)
|
|
75
|
-
| `get` | <T\>(`token`: [Token](README.md#token)
|
|
76
|
-
| `hasToken` | (`token`: [Token](README.md#token)
|
|
77
|
-
| `remove` | <T\>(`token`: [Token](README.md#token)
|
|
74
|
+
| `bindFactory` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `factory`: (`container`: [`Container`](README.md#container)) => `T`, `options?`: [`FactoryOptions`](README.md#factoryoptions)<`T`\>) => `void` |
|
|
75
|
+
| `bindValue` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `value`: `T`) => `void` |
|
|
76
|
+
| `get` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `undefined` \| `T` |
|
|
77
|
+
| `hasToken` | (`token`: [`Token`](README.md#token)<`unknown`\>) => `boolean` |
|
|
78
|
+
| `remove` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `void` |
|
|
78
79
|
| `removeAll` | () => `void` |
|
|
79
|
-
| `resolve` | <T\>(`token`: [Token](README.md#token)
|
|
80
|
+
| `resolve` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `T` |
|
|
80
81
|
|
|
81
82
|
#### Defined in
|
|
82
83
|
|
|
83
|
-
[packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/
|
|
84
|
+
[packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L95)
|
|
84
85
|
|
|
85
86
|
___
|
|
86
87
|
|
|
87
88
|
### FactoryOptions
|
|
88
89
|
|
|
89
|
-
Ƭ **FactoryOptions
|
|
90
|
+
Ƭ **FactoryOptions**<`T`\>: { `scope?`: ``"scoped"`` \| ``"singleton"`` ; `onRemoved?`: (`value`: `T`) => `void` } \| { `scope`: ``"transient"`` }
|
|
90
91
|
|
|
91
92
|
Options for factory binding.
|
|
92
93
|
|
|
@@ -105,7 +106,7 @@ Options for factory binding.
|
|
|
105
106
|
|
|
106
107
|
#### Defined in
|
|
107
108
|
|
|
108
|
-
[packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/
|
|
109
|
+
[packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L83)
|
|
109
110
|
|
|
110
111
|
___
|
|
111
112
|
|
|
@@ -117,13 +118,13 @@ ___
|
|
|
117
118
|
|
|
118
119
|
#### Defined in
|
|
119
120
|
|
|
120
|
-
[packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/
|
|
121
|
+
[packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L71)
|
|
121
122
|
|
|
122
123
|
___
|
|
123
124
|
|
|
124
125
|
### Module
|
|
125
126
|
|
|
126
|
-
Ƭ **Module
|
|
127
|
+
Ƭ **Module**<`ModuleProps`\>: `ModuleController` & `ModuleProps`
|
|
127
128
|
|
|
128
129
|
Dependency module
|
|
129
130
|
|
|
@@ -138,27 +139,27 @@ type LoggerModule = Module<{
|
|
|
138
139
|
|
|
139
140
|
| Name | Type |
|
|
140
141
|
| :------ | :------ |
|
|
141
|
-
| `ModuleProps` |
|
|
142
|
+
| `ModuleProps` | extends `AnyObject` = `EmptyObject` |
|
|
142
143
|
|
|
143
144
|
#### Defined in
|
|
144
145
|
|
|
145
|
-
[packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/
|
|
146
|
+
[packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L22)
|
|
146
147
|
|
|
147
148
|
___
|
|
148
149
|
|
|
149
150
|
### ModuleBindingEntry
|
|
150
151
|
|
|
151
|
-
Ƭ **ModuleBindingEntry**: [ModuleDeclaration](README.md#moduledeclaration)
|
|
152
|
+
Ƭ **ModuleBindingEntry**: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> \| { `module`: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> ; `options`: [`BindModuleOptions`](README.md#bindmoduleoptions) }
|
|
152
153
|
|
|
153
154
|
#### Defined in
|
|
154
155
|
|
|
155
|
-
[packages/ditox/src/modules.ts:
|
|
156
|
+
[packages/ditox/src/modules.ts:80](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L80)
|
|
156
157
|
|
|
157
158
|
___
|
|
158
159
|
|
|
159
160
|
### ModuleDeclaration
|
|
160
161
|
|
|
161
|
-
Ƭ **ModuleDeclaration
|
|
162
|
+
Ƭ **ModuleDeclaration**<`T`\>: `Object`
|
|
162
163
|
|
|
163
164
|
Description how to bind the module in declarative way.
|
|
164
165
|
|
|
@@ -183,29 +184,28 @@ const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
|
183
184
|
|
|
184
185
|
| Name | Type |
|
|
185
186
|
| :------ | :------ |
|
|
186
|
-
| `T` |
|
|
187
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
187
188
|
|
|
188
189
|
#### Type declaration
|
|
189
190
|
|
|
190
191
|
| Name | Type | Description |
|
|
191
192
|
| :------ | :------ | :------ |
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
194
|
-
| `
|
|
195
|
-
| `
|
|
196
|
-
| `
|
|
197
|
-
| `
|
|
198
|
-
| `token` | [Token](README.md#token)<T\> | Token for the module |
|
|
193
|
+
| `exports?` | { [K in keyof GetModuleProps<T\>]?: Token<GetModuleProps<T\>[K]\> } | Dictionary of module properties which are bound to tokens. |
|
|
194
|
+
| `imports?` | `ReadonlyArray`<[`ModuleBindingEntry`](README.md#modulebindingentry)\> | Modules for binding |
|
|
195
|
+
| `token` | [`Token`](README.md#token)<`T`\> | Token for the module |
|
|
196
|
+
| `afterBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to export complex dependencies from the module. It is called after binding the module. |
|
|
197
|
+
| `beforeBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to prepare an environment. It is called before binding the module. |
|
|
198
|
+
| `factory` | (`container`: [`Container`](README.md#container)) => `T` | Factory of the module |
|
|
199
199
|
|
|
200
200
|
#### Defined in
|
|
201
201
|
|
|
202
|
-
[packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/
|
|
202
|
+
[packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L47)
|
|
203
203
|
|
|
204
204
|
___
|
|
205
205
|
|
|
206
206
|
### Token
|
|
207
207
|
|
|
208
|
-
Ƭ **Token
|
|
208
|
+
Ƭ **Token**<`T`\>: `RequiredToken`<`T`\> \| `OptionalToken`<`T`\>
|
|
209
209
|
|
|
210
210
|
Binding token.
|
|
211
211
|
|
|
@@ -217,13 +217,13 @@ Binding token.
|
|
|
217
217
|
|
|
218
218
|
#### Defined in
|
|
219
219
|
|
|
220
|
-
[packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/
|
|
220
|
+
[packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L25)
|
|
221
221
|
|
|
222
222
|
## Functions
|
|
223
223
|
|
|
224
224
|
### bindModule
|
|
225
225
|
|
|
226
|
-
▸ **bindModule
|
|
226
|
+
▸ **bindModule**<`T`\>(`container`, `moduleDeclaration`, `options?`): `void`
|
|
227
227
|
|
|
228
228
|
Binds the dependency module to the container
|
|
229
229
|
|
|
@@ -236,15 +236,15 @@ bindModule(container, LOGGER_MODULE);
|
|
|
236
236
|
|
|
237
237
|
| Name | Type |
|
|
238
238
|
| :------ | :------ |
|
|
239
|
-
| `T` |
|
|
239
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
240
240
|
|
|
241
241
|
#### Parameters
|
|
242
242
|
|
|
243
243
|
| Name | Type | Description |
|
|
244
244
|
| :------ | :------ | :------ |
|
|
245
|
-
| `container` | [Container](README.md#container) | Dependency container. |
|
|
246
|
-
| `moduleDeclaration` | [ModuleDeclaration](README.md#moduledeclaration)
|
|
247
|
-
| `options?` | [BindModuleOptions](README.md#bindmoduleoptions) | Options for module binding. |
|
|
245
|
+
| `container` | [`Container`](README.md#container) | Dependency container. |
|
|
246
|
+
| `moduleDeclaration` | [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\> | Declaration of the dependency module. |
|
|
247
|
+
| `options?` | [`BindModuleOptions`](README.md#bindmoduleoptions) | Options for module binding. |
|
|
248
248
|
|
|
249
249
|
#### Returns
|
|
250
250
|
|
|
@@ -252,7 +252,7 @@ bindModule(container, LOGGER_MODULE);
|
|
|
252
252
|
|
|
253
253
|
#### Defined in
|
|
254
254
|
|
|
255
|
-
[packages/ditox/src/modules.ts:
|
|
255
|
+
[packages/ditox/src/modules.ts:98](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L98)
|
|
256
256
|
|
|
257
257
|
___
|
|
258
258
|
|
|
@@ -266,8 +266,8 @@ Binds dependency modules to the container
|
|
|
266
266
|
|
|
267
267
|
| Name | Type | Description |
|
|
268
268
|
| :------ | :------ | :------ |
|
|
269
|
-
| `container` | [Container](README.md#container) | Dependency container for binding |
|
|
270
|
-
| `modules` | `
|
|
269
|
+
| `container` | [`Container`](README.md#container) | Dependency container for binding |
|
|
270
|
+
| `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects. |
|
|
271
271
|
|
|
272
272
|
#### Returns
|
|
273
273
|
|
|
@@ -275,13 +275,13 @@ Binds dependency modules to the container
|
|
|
275
275
|
|
|
276
276
|
#### Defined in
|
|
277
277
|
|
|
278
|
-
[packages/ditox/src/modules.ts:
|
|
278
|
+
[packages/ditox/src/modules.ts:159](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L159)
|
|
279
279
|
|
|
280
280
|
___
|
|
281
281
|
|
|
282
282
|
### bindMultiValue
|
|
283
283
|
|
|
284
|
-
▸ **bindMultiValue
|
|
284
|
+
▸ **bindMultiValue**<`T`\>(`container`, `token`, `value`): `void`
|
|
285
285
|
|
|
286
286
|
Rebinds the array by the token with added new value.
|
|
287
287
|
|
|
@@ -295,8 +295,8 @@ Rebinds the array by the token with added new value.
|
|
|
295
295
|
|
|
296
296
|
| Name | Type | Description |
|
|
297
297
|
| :------ | :------ | :------ |
|
|
298
|
-
| `container` | [Container](README.md#container) | Dependency container. |
|
|
299
|
-
| `token` | [Token](README.md#token)<T[]\> | Token for an array of values. |
|
|
298
|
+
| `container` | [`Container`](README.md#container) | Dependency container. |
|
|
299
|
+
| `token` | [`Token`](README.md#token)<readonly `T`[]\> | Token for an array of values. |
|
|
300
300
|
| `value` | `T` | New value which is added to the end of the array. |
|
|
301
301
|
|
|
302
302
|
#### Returns
|
|
@@ -305,13 +305,13 @@ Rebinds the array by the token with added new value.
|
|
|
305
305
|
|
|
306
306
|
#### Defined in
|
|
307
307
|
|
|
308
|
-
[packages/ditox/src/utils.ts:
|
|
308
|
+
[packages/ditox/src/utils.ts:27](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L27)
|
|
309
309
|
|
|
310
310
|
___
|
|
311
311
|
|
|
312
312
|
### createContainer
|
|
313
313
|
|
|
314
|
-
▸ **createContainer**(`parentContainer?`): [Container](README.md#container)
|
|
314
|
+
▸ **createContainer**(`parentContainer?`): [`Container`](README.md#container)
|
|
315
315
|
|
|
316
316
|
Creates a new dependency container.
|
|
317
317
|
|
|
@@ -321,21 +321,21 @@ Container can have an optional parent to chain token resolution. The parent is u
|
|
|
321
321
|
|
|
322
322
|
| Name | Type | Description |
|
|
323
323
|
| :------ | :------ | :------ |
|
|
324
|
-
| `parentContainer?` | [Container](README.md#container) | Optional parent container. |
|
|
324
|
+
| `parentContainer?` | [`Container`](README.md#container) | Optional parent container. |
|
|
325
325
|
|
|
326
326
|
#### Returns
|
|
327
327
|
|
|
328
|
-
[Container](README.md#container)
|
|
328
|
+
[`Container`](README.md#container)
|
|
329
329
|
|
|
330
330
|
#### Defined in
|
|
331
331
|
|
|
332
|
-
[packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/
|
|
332
|
+
[packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L204)
|
|
333
333
|
|
|
334
334
|
___
|
|
335
335
|
|
|
336
336
|
### declareModule
|
|
337
337
|
|
|
338
|
-
▸ **declareModule
|
|
338
|
+
▸ **declareModule**<`T`\>(`declaration`): [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>
|
|
339
339
|
|
|
340
340
|
Declares a module binding
|
|
341
341
|
|
|
@@ -365,21 +365,21 @@ const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
|
365
365
|
|
|
366
366
|
| Name | Type | Description |
|
|
367
367
|
| :------ | :------ | :------ |
|
|
368
|
-
| `declaration` | `Omit`<[ModuleDeclaration](README.md#moduledeclaration)
|
|
368
|
+
| `declaration` | `Omit`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, ``"token"``\> & `Partial`<`Pick`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, ``"token"``\>\> | a module declaration |
|
|
369
369
|
|
|
370
370
|
#### Returns
|
|
371
371
|
|
|
372
|
-
[ModuleDeclaration](README.md#moduledeclaration)
|
|
372
|
+
[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>
|
|
373
373
|
|
|
374
374
|
#### Defined in
|
|
375
375
|
|
|
376
|
-
[packages/ditox/src/modules.ts:
|
|
376
|
+
[packages/ditox/src/modules.ts:194](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L194)
|
|
377
377
|
|
|
378
378
|
___
|
|
379
379
|
|
|
380
380
|
### declareModuleBindings
|
|
381
381
|
|
|
382
|
-
▸ **declareModuleBindings**(`modules`): [ModuleDeclaration](README.md#moduledeclaration)<[Module](README.md#module)\>
|
|
382
|
+
▸ **declareModuleBindings**(`modules`): [`ModuleDeclaration`](README.md#moduledeclaration)<[`Module`](README.md#module)\>
|
|
383
383
|
|
|
384
384
|
Declares bindings of several modules
|
|
385
385
|
|
|
@@ -387,184 +387,161 @@ Declares bindings of several modules
|
|
|
387
387
|
|
|
388
388
|
| Name | Type | Description |
|
|
389
389
|
| :------ | :------ | :------ |
|
|
390
|
-
| `modules` | `
|
|
390
|
+
| `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | module declaration entries |
|
|
391
391
|
|
|
392
392
|
#### Returns
|
|
393
393
|
|
|
394
|
-
[ModuleDeclaration](README.md#moduledeclaration)<[Module](README.md#module)\>
|
|
394
|
+
[`ModuleDeclaration`](README.md#moduledeclaration)<[`Module`](README.md#module)\>
|
|
395
395
|
|
|
396
396
|
#### Defined in
|
|
397
397
|
|
|
398
|
-
[packages/ditox/src/modules.ts:
|
|
398
|
+
[packages/ditox/src/modules.ts:206](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/modules.ts#L206)
|
|
399
399
|
|
|
400
400
|
___
|
|
401
401
|
|
|
402
|
-
###
|
|
402
|
+
### injectable
|
|
403
403
|
|
|
404
|
-
▸ **
|
|
404
|
+
▸ **injectable**<`Tokens`, `Values`, `Result`\>(`factory`, ...`tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
405
405
|
|
|
406
|
-
|
|
407
|
-
If a token is not found, then `undefined` value is used.
|
|
406
|
+
Decorates a factory by passing resolved values as factory arguments.
|
|
408
407
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const props = getProps(container, {a: tokenA, b: tokenB});
|
|
412
|
-
console.log(props); // {a: 1, b: 2}
|
|
413
|
-
```
|
|
408
|
+
If an argument is an object which has tokens as its properties,
|
|
409
|
+
then returns an object containing resolved values as properties.
|
|
414
410
|
|
|
415
411
|
#### Type parameters
|
|
416
412
|
|
|
417
413
|
| Name | Type |
|
|
418
414
|
| :------ | :------ |
|
|
419
|
-
| `
|
|
415
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
416
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
|
|
417
|
+
| `Result` | `Result` |
|
|
420
418
|
|
|
421
419
|
#### Parameters
|
|
422
420
|
|
|
423
|
-
| Name | Type |
|
|
424
|
-
| :------ | :------ |
|
|
425
|
-
| `
|
|
426
|
-
|
|
|
421
|
+
| Name | Type | Description |
|
|
422
|
+
| :------ | :------ | :------ |
|
|
423
|
+
| `factory` | (...`params`: `Values`) => `Result` | A factory. |
|
|
424
|
+
| `...tokens` | `Tokens` | Tokens which correspond to factory arguments. |
|
|
427
425
|
|
|
428
426
|
#### Returns
|
|
429
427
|
|
|
430
|
-
`
|
|
431
|
-
|
|
432
|
-
#### Defined in
|
|
433
|
-
|
|
434
|
-
[packages/ditox/src/utils.ts:83](https://github.com/mnasyrov/ditox/blob/153c602/packages/ditox/src/utils.ts#L83)
|
|
428
|
+
`fn`
|
|
435
429
|
|
|
436
|
-
|
|
430
|
+
Decorated factory which takes a dependency container as a single argument.
|
|
437
431
|
|
|
438
|
-
|
|
432
|
+
▸ (`container`): `Result`
|
|
439
433
|
|
|
440
|
-
|
|
434
|
+
Decorates a factory by passing resolved values as factory arguments.
|
|
441
435
|
|
|
442
|
-
|
|
443
|
-
|
|
436
|
+
If an argument is an object which has tokens as its properties,
|
|
437
|
+
then returns an object containing resolved values as properties.
|
|
444
438
|
|
|
445
|
-
|
|
439
|
+
##### Parameters
|
|
446
440
|
|
|
447
441
|
| Name | Type |
|
|
448
442
|
| :------ | :------ |
|
|
449
|
-
| `
|
|
450
|
-
| `Values` | `Values`: { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : never} |
|
|
443
|
+
| `container` | [`Container`](README.md#container) |
|
|
451
444
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
| Name | Type |
|
|
455
|
-
| :------ | :------ |
|
|
456
|
-
| `container` | [Container](README.md#container) |
|
|
457
|
-
| `...tokens` | `Tokens` |
|
|
445
|
+
##### Returns
|
|
458
446
|
|
|
459
|
-
|
|
447
|
+
`Result`
|
|
460
448
|
|
|
461
|
-
|
|
449
|
+
Decorated factory which takes a dependency container as a single argument.
|
|
462
450
|
|
|
463
451
|
#### Defined in
|
|
464
452
|
|
|
465
|
-
[packages/ditox/src/utils.ts:
|
|
453
|
+
[packages/ditox/src/utils.ts:178](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L178)
|
|
466
454
|
|
|
467
455
|
___
|
|
468
456
|
|
|
469
|
-
###
|
|
457
|
+
### injectableClass
|
|
470
458
|
|
|
471
|
-
▸ **
|
|
459
|
+
▸ **injectableClass**<`Tokens`, `Values`, `Result`\>(`constructor`, ...`tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
472
460
|
|
|
473
|
-
Decorates a
|
|
461
|
+
Decorates a class by passing resolved values as arguments to its constructor.
|
|
462
|
+
|
|
463
|
+
If an argument is an object which has tokens as its properties,
|
|
464
|
+
then returns an object containing resolved values as properties.
|
|
474
465
|
|
|
475
466
|
#### Type parameters
|
|
476
467
|
|
|
477
468
|
| Name | Type |
|
|
478
469
|
| :------ | :------ |
|
|
479
|
-
| `Tokens` | `
|
|
480
|
-
| `Values` |
|
|
470
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
471
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
|
|
481
472
|
| `Result` | `Result` |
|
|
482
473
|
|
|
483
474
|
#### Parameters
|
|
484
475
|
|
|
485
476
|
| Name | Type | Description |
|
|
486
477
|
| :------ | :------ | :------ |
|
|
487
|
-
| `
|
|
488
|
-
| `...tokens` | `Tokens` | Tokens which correspond to
|
|
478
|
+
| `constructor` | (...`params`: `Values`) => `Result` | Constructor of a class |
|
|
479
|
+
| `...tokens` | `Tokens` | Tokens which correspond to constructor arguments |
|
|
489
480
|
|
|
490
481
|
#### Returns
|
|
491
482
|
|
|
492
483
|
`fn`
|
|
493
484
|
|
|
494
|
-
|
|
485
|
+
A factory function which takes a dependency container as a single argument
|
|
486
|
+
and returns a new created class.
|
|
495
487
|
|
|
496
488
|
▸ (`container`): `Result`
|
|
497
489
|
|
|
490
|
+
Decorates a class by passing resolved values as arguments to its constructor.
|
|
491
|
+
|
|
492
|
+
If an argument is an object which has tokens as its properties,
|
|
493
|
+
then returns an object containing resolved values as properties.
|
|
494
|
+
|
|
498
495
|
##### Parameters
|
|
499
496
|
|
|
500
497
|
| Name | Type |
|
|
501
498
|
| :------ | :------ |
|
|
502
|
-
| `container` | [Container](README.md#container) |
|
|
499
|
+
| `container` | [`Container`](README.md#container) |
|
|
503
500
|
|
|
504
501
|
##### Returns
|
|
505
502
|
|
|
506
503
|
`Result`
|
|
507
504
|
|
|
505
|
+
A factory function which takes a dependency container as a single argument
|
|
506
|
+
and returns a new created class.
|
|
507
|
+
|
|
508
508
|
#### Defined in
|
|
509
509
|
|
|
510
|
-
[packages/ditox/src/utils.ts:
|
|
510
|
+
[packages/ditox/src/utils.ts:211](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L211)
|
|
511
511
|
|
|
512
512
|
___
|
|
513
513
|
|
|
514
|
-
###
|
|
514
|
+
### isToken
|
|
515
515
|
|
|
516
|
-
▸ **
|
|
516
|
+
▸ **isToken**<`T`\>(`value`): value is Token<T\>
|
|
517
517
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
**`example`**
|
|
521
|
-
```ts
|
|
522
|
-
const factory = ({a, b}: {a: number, b: number}) => a + b;
|
|
523
|
-
const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
|
|
524
|
-
const result = decoratedFactory(container);
|
|
525
|
-
```
|
|
518
|
+
Checks if a value is the token
|
|
526
519
|
|
|
527
520
|
#### Type parameters
|
|
528
521
|
|
|
529
|
-
| Name |
|
|
530
|
-
| :------ |
|
|
531
|
-
| `
|
|
532
|
-
| `Result` | `Result` |
|
|
522
|
+
| Name |
|
|
523
|
+
| :------ |
|
|
524
|
+
| `T` |
|
|
533
525
|
|
|
534
526
|
#### Parameters
|
|
535
527
|
|
|
536
|
-
| Name | Type | Description |
|
|
537
|
-
| :------ | :------ | :------ |
|
|
538
|
-
| `factory` | (`props`: `Props`) => `Result` | A factory. |
|
|
539
|
-
| `tokens` | `TokenProps`<Props\> | Object with tokens. |
|
|
540
|
-
|
|
541
|
-
#### Returns
|
|
542
|
-
|
|
543
|
-
`fn`
|
|
544
|
-
|
|
545
|
-
Decorated factory which takes a dependency container as a single argument.
|
|
546
|
-
|
|
547
|
-
▸ (`container`): `Result`
|
|
548
|
-
|
|
549
|
-
##### Parameters
|
|
550
|
-
|
|
551
528
|
| Name | Type |
|
|
552
529
|
| :------ | :------ |
|
|
553
|
-
| `
|
|
530
|
+
| `value` | `unknown` |
|
|
554
531
|
|
|
555
|
-
|
|
532
|
+
#### Returns
|
|
556
533
|
|
|
557
|
-
|
|
534
|
+
value is Token<T\>
|
|
558
535
|
|
|
559
536
|
#### Defined in
|
|
560
537
|
|
|
561
|
-
[packages/ditox/src/utils.ts:
|
|
538
|
+
[packages/ditox/src/utils.ts:11](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L11)
|
|
562
539
|
|
|
563
540
|
___
|
|
564
541
|
|
|
565
542
|
### optional
|
|
566
543
|
|
|
567
|
-
▸ **optional
|
|
544
|
+
▸ **optional**<`T`\>(`token`, `optionalValue`): `OptionalToken`<`T`\>
|
|
568
545
|
|
|
569
546
|
Decorate a token with an optional value.
|
|
570
547
|
This value is be used as default value in case a container does not have registered token.
|
|
@@ -579,18 +556,18 @@ This value is be used as default value in case a container does not have registe
|
|
|
579
556
|
|
|
580
557
|
| Name | Type | Description |
|
|
581
558
|
| :------ | :------ | :------ |
|
|
582
|
-
| `token` | [Token](README.md#token)
|
|
559
|
+
| `token` | [`Token`](README.md#token)<`T`\> | Existed token. |
|
|
583
560
|
| `optionalValue` | `T` | Default value for the resolver. |
|
|
584
561
|
|
|
585
562
|
#### Returns
|
|
586
563
|
|
|
587
|
-
`OptionalToken
|
|
564
|
+
`OptionalToken`<`T`\>
|
|
588
565
|
|
|
589
566
|
#### Defined in
|
|
590
567
|
|
|
591
|
-
[packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/
|
|
568
|
+
[packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L41)
|
|
592
569
|
|
|
593
|
-
▸ **optional
|
|
570
|
+
▸ **optional**<`T`\>(`token`): `OptionalToken`<`T` \| `undefined`\>
|
|
594
571
|
|
|
595
572
|
#### Type parameters
|
|
596
573
|
|
|
@@ -602,28 +579,35 @@ This value is be used as default value in case a container does not have registe
|
|
|
602
579
|
|
|
603
580
|
| Name | Type |
|
|
604
581
|
| :------ | :------ |
|
|
605
|
-
| `token` | [Token](README.md#token)
|
|
582
|
+
| `token` | [`Token`](README.md#token)<`T`\> |
|
|
606
583
|
|
|
607
584
|
#### Returns
|
|
608
585
|
|
|
609
|
-
`OptionalToken
|
|
586
|
+
`OptionalToken`<`T` \| `undefined`\>
|
|
610
587
|
|
|
611
588
|
#### Defined in
|
|
612
589
|
|
|
613
|
-
[packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/
|
|
590
|
+
[packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L45)
|
|
614
591
|
|
|
615
592
|
___
|
|
616
593
|
|
|
617
|
-
###
|
|
594
|
+
### resolveValue
|
|
618
595
|
|
|
619
|
-
▸ **
|
|
596
|
+
▸ **resolveValue**<`Tokens`, `Values`\>(`container`, `token`): `Values`
|
|
620
597
|
|
|
621
|
-
|
|
622
|
-
|
|
598
|
+
Resolves a value by the provided token.
|
|
599
|
+
|
|
600
|
+
If an argument is an object which has tokens as its properties,
|
|
601
|
+
then returns an object containing resolved values as properties.
|
|
602
|
+
|
|
603
|
+
If a value is not found by the token, then `ResolverError` is thrown.
|
|
623
604
|
|
|
624
605
|
**`example`**
|
|
625
606
|
```ts
|
|
626
|
-
const
|
|
607
|
+
const value = resolveValue(container, tokenA);
|
|
608
|
+
console.log(value); // 1
|
|
609
|
+
|
|
610
|
+
const props = resolveValue(container, {a: tokenA, b: tokenB});
|
|
627
611
|
console.log(props); // {a: 1, b: 2}
|
|
628
612
|
```
|
|
629
613
|
|
|
@@ -631,44 +615,58 @@ console.log(props); // {a: 1, b: 2}
|
|
|
631
615
|
|
|
632
616
|
| Name | Type |
|
|
633
617
|
| :------ | :------ |
|
|
634
|
-
| `
|
|
618
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; } |
|
|
619
|
+
| `Values` | extends `unknown` |
|
|
635
620
|
|
|
636
621
|
#### Parameters
|
|
637
622
|
|
|
638
623
|
| Name | Type |
|
|
639
624
|
| :------ | :------ |
|
|
640
|
-
| `container` | [Container](README.md#container) |
|
|
641
|
-
| `
|
|
625
|
+
| `container` | [`Container`](README.md#container) |
|
|
626
|
+
| `token` | `Tokens` |
|
|
642
627
|
|
|
643
628
|
#### Returns
|
|
644
629
|
|
|
645
|
-
`
|
|
630
|
+
`Values`
|
|
646
631
|
|
|
647
632
|
#### Defined in
|
|
648
633
|
|
|
649
|
-
[packages/ditox/src/utils.ts:
|
|
634
|
+
[packages/ditox/src/utils.ts:118](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L118)
|
|
650
635
|
|
|
651
636
|
___
|
|
652
637
|
|
|
653
638
|
### resolveValues
|
|
654
639
|
|
|
655
|
-
▸ **resolveValues
|
|
640
|
+
▸ **resolveValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
|
|
641
|
+
|
|
642
|
+
Returns an array of resolved values or objects with resolved values.
|
|
643
|
+
|
|
644
|
+
If an item of the array is an object which has tokens as its properties,
|
|
645
|
+
then returns an object containing resolved values as properties.
|
|
656
646
|
|
|
657
|
-
Returns an array of resolved values by the specified token.
|
|
658
647
|
If a token is not found, then `ResolverError` is thrown.
|
|
659
648
|
|
|
649
|
+
**`example`**
|
|
650
|
+
```ts
|
|
651
|
+
const items1 = resolveValues(container, tokenA);
|
|
652
|
+
console.log(items1); // [1]
|
|
653
|
+
|
|
654
|
+
const items2 = resolveValues(container, tokenA, {a: tokenA, b: tokenB});
|
|
655
|
+
console.log(items2); // [1, {a: 1, b: 2}]
|
|
656
|
+
```
|
|
657
|
+
|
|
660
658
|
#### Type parameters
|
|
661
659
|
|
|
662
660
|
| Name | Type |
|
|
663
661
|
| :------ | :------ |
|
|
664
|
-
| `Tokens` | `
|
|
665
|
-
| `Values` |
|
|
662
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
663
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
|
|
666
664
|
|
|
667
665
|
#### Parameters
|
|
668
666
|
|
|
669
667
|
| Name | Type |
|
|
670
668
|
| :------ | :------ |
|
|
671
|
-
| `container` | [Container](README.md#container) |
|
|
669
|
+
| `container` | [`Container`](README.md#container) |
|
|
672
670
|
| `...tokens` | `Tokens` |
|
|
673
671
|
|
|
674
672
|
#### Returns
|
|
@@ -677,13 +675,13 @@ If a token is not found, then `ResolverError` is thrown.
|
|
|
677
675
|
|
|
678
676
|
#### Defined in
|
|
679
677
|
|
|
680
|
-
[packages/ditox/src/utils.ts:
|
|
678
|
+
[packages/ditox/src/utils.ts:154](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L154)
|
|
681
679
|
|
|
682
680
|
___
|
|
683
681
|
|
|
684
682
|
### token
|
|
685
683
|
|
|
686
|
-
▸ **token
|
|
684
|
+
▸ **token**<`T`\>(`description?`): [`Token`](README.md#token)<`T`\>
|
|
687
685
|
|
|
688
686
|
Creates a new binding token.
|
|
689
687
|
|
|
@@ -701,8 +699,96 @@ Creates a new binding token.
|
|
|
701
699
|
|
|
702
700
|
#### Returns
|
|
703
701
|
|
|
704
|
-
[Token](README.md#token)
|
|
702
|
+
[`Token`](README.md#token)<`T`\>
|
|
703
|
+
|
|
704
|
+
#### Defined in
|
|
705
|
+
|
|
706
|
+
[packages/ditox/src/ditox.ts:31](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/ditox.ts#L31)
|
|
707
|
+
|
|
708
|
+
___
|
|
709
|
+
|
|
710
|
+
### tryResolveValue
|
|
711
|
+
|
|
712
|
+
▸ **tryResolveValue**<`Tokens`, `Values`\>(`container`, `token`): `Values`
|
|
713
|
+
|
|
714
|
+
Tries to resolve a value by the provided token.
|
|
715
|
+
|
|
716
|
+
If an argument is an object which has tokens as its properties,
|
|
717
|
+
then returns an object containing resolved values as properties.
|
|
718
|
+
|
|
719
|
+
If a token is not found, then `undefined` value is used.
|
|
720
|
+
|
|
721
|
+
**`example`**
|
|
722
|
+
```ts
|
|
723
|
+
const value = tryResolveValue(container, tokenA);
|
|
724
|
+
console.log(value); // 1
|
|
725
|
+
|
|
726
|
+
const props = tryResolveValue(container, {a: tokenA, b: tokenB});
|
|
727
|
+
console.log(props); // {a: 1, b: 2}
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
#### Type parameters
|
|
731
|
+
|
|
732
|
+
| Name | Type |
|
|
733
|
+
| :------ | :------ |
|
|
734
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; } |
|
|
735
|
+
| `Values` | extends `unknown` |
|
|
736
|
+
|
|
737
|
+
#### Parameters
|
|
738
|
+
|
|
739
|
+
| Name | Type |
|
|
740
|
+
| :------ | :------ |
|
|
741
|
+
| `container` | [`Container`](README.md#container) |
|
|
742
|
+
| `token` | `Tokens` |
|
|
743
|
+
|
|
744
|
+
#### Returns
|
|
745
|
+
|
|
746
|
+
`Values`
|
|
747
|
+
|
|
748
|
+
#### Defined in
|
|
749
|
+
|
|
750
|
+
[packages/ditox/src/utils.ts:54](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L54)
|
|
751
|
+
|
|
752
|
+
___
|
|
753
|
+
|
|
754
|
+
### tryResolveValues
|
|
755
|
+
|
|
756
|
+
▸ **tryResolveValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
|
|
757
|
+
|
|
758
|
+
Returns an array of resolved values or objects with resolved values.
|
|
759
|
+
|
|
760
|
+
If an item of the array is an object which has tokens as its properties,
|
|
761
|
+
then returns an object containing resolved values as properties.
|
|
762
|
+
|
|
763
|
+
If a token is not found, then `undefined` value is used.
|
|
764
|
+
|
|
765
|
+
**`example`**
|
|
766
|
+
```ts
|
|
767
|
+
const items1 = tryResolveValues(container, tokenA);
|
|
768
|
+
console.log(items1); // [1]
|
|
769
|
+
|
|
770
|
+
const items2 = tryResolveValues(container, tokenA, {a: tokenA, b: tokenB});
|
|
771
|
+
console.log(items2); // [1, {a: 1, b: 2}]
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
#### Type parameters
|
|
775
|
+
|
|
776
|
+
| Name | Type |
|
|
777
|
+
| :------ | :------ |
|
|
778
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
779
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? undefined \| V : Tokens[K] extends TokenProps<Props\> ? Partial<Props\> : never } |
|
|
780
|
+
|
|
781
|
+
#### Parameters
|
|
782
|
+
|
|
783
|
+
| Name | Type |
|
|
784
|
+
| :------ | :------ |
|
|
785
|
+
| `container` | [`Container`](README.md#container) |
|
|
786
|
+
| `...tokens` | `Tokens` |
|
|
787
|
+
|
|
788
|
+
#### Returns
|
|
789
|
+
|
|
790
|
+
`Values`
|
|
705
791
|
|
|
706
792
|
#### Defined in
|
|
707
793
|
|
|
708
|
-
[packages/ditox/src/
|
|
794
|
+
[packages/ditox/src/utils.ts:88](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox/src/utils.ts#L88)
|