@armscye/container 0.3.0 → 0.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @armscye/container
2
2
 
3
- > A collection of shared standard TypeScript definitions.
3
+ > A collection of shared standard TypeScript definitions (@container).
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,3 +15,166 @@ or using yarn:
15
15
  ```sh
16
16
  yarn add @armscye/container --dev
17
17
  ```
18
+
19
+ ## Reference
20
+
21
+ ### ClassProvider `Interface`
22
+
23
+ Configures the `Container` to return an instance of `useClass` for a token.
24
+
25
+ ```ts
26
+ interface ClassProvider {
27
+ provide: ProviderToken;
28
+
29
+ useClass: NoArgument<any>;
30
+
31
+ shared?: boolean;
32
+ }
33
+ ```
34
+
35
+ **Properties**
36
+
37
+ | Property | Description |
38
+ | --------------------------- | ------------------------------------------ |
39
+ | provide: `ProviderToken` | A provider token. |
40
+ | useClass: `NoArgument<any>` | A class to instantiate for the `token`. |
41
+ | shared?: boolean | When true, the created instance is cached. |
42
+
43
+ ### Container `Interface`
44
+
45
+ Describes the interface of a container that exposes methods to read its entries.
46
+
47
+ ```ts
48
+ interface Container {
49
+ get<T>(token: ProviderToken): T;
50
+
51
+ has(token: ProviderToken): boolean;
52
+ }
53
+ ```
54
+
55
+ **Methods**
56
+
57
+ #### `get<T>(token: ProviderToken): T`
58
+
59
+ Retrieves an entry from the container based on its provider token.
60
+
61
+ _Parameters_
62
+
63
+ - `token`: The unique identifier of the entry to retrieve.
64
+
65
+ _Returns_
66
+
67
+ The entry associated with the provided token, if found.
68
+
69
+ _Throws_
70
+
71
+ `Error` if the entry doesn't exist or an error occurs during retrieval.
72
+
73
+ #### `has(token: ProviderToken): boolean`
74
+
75
+ Checks whether an entry for a specific provider token exists in the container.
76
+
77
+ _Parameters_
78
+
79
+ - `token`: The unique identifier of the entry to check for.
80
+
81
+ _Returns_
82
+
83
+ `true` if an entry for the provided token exists, `false` otherwise.
84
+
85
+ ### ExistingProvider `Interface`
86
+
87
+ Configures the `Container` to return a value of another `useExisting` token.
88
+
89
+ ```ts
90
+ interface ExistingProvider {
91
+ provide: ProviderToken;
92
+
93
+ useExisting: ProviderToken;
94
+
95
+ shared?: boolean;
96
+ }
97
+ ```
98
+
99
+ **Properties**
100
+
101
+ | Property | Description |
102
+ | ---------------------------- | ------------------------------------------ |
103
+ | provide: `ProviderToken` | A provider token. |
104
+ | useExisting: `ProviderToken` | Existing `token` to return. |
105
+ | shared?: boolean | When true, the created instance is cached. |
106
+
107
+ ### FactoryProvider `Interface`
108
+
109
+ Configures the `Container` to return a value by invoking a `useFactory` function.
110
+
111
+ ```ts
112
+ interface FactoryProvider {
113
+ provide: ProviderToken;
114
+
115
+ useFactory: Factory<any>;
116
+
117
+ shared?: boolean;
118
+ }
119
+ ```
120
+
121
+ **Properties**
122
+
123
+ | Property | Description |
124
+ | -------------------------- | ----------------------------------------------------------------- |
125
+ | provide: `ProviderToken` | A provider token. |
126
+ | useFactory: `Factory<any>` | A factory function to invoke to create an object for the `token`. |
127
+ | shared?: boolean | When true, the created instance is cached. |
128
+
129
+ ### Factory `Type`
130
+
131
+ A function to invoke to create an object. The function is invoked with an instance of the container in order to access required dependencies.
132
+
133
+ ```ts
134
+ type Factory<T = any> = (container: Container) => T;
135
+ ```
136
+
137
+ ### ProviderToken `Type`
138
+
139
+ Token that can be used to retrieve an instance from a container.
140
+
141
+ ```ts
142
+ type ProviderToken = string | symbol;
143
+ ```
144
+
145
+ ### Provider `Type`
146
+
147
+ Describes how the `Container` should be configured.
148
+
149
+ ```ts
150
+ type Provider =
151
+ | ValueProvider
152
+ | ClassProvider
153
+ | FactoryProvider
154
+ | ExistingProvider;
155
+ ```
156
+
157
+ ### ValueProvider `Interface`
158
+
159
+ Configures the `Container` to return a value for a token.
160
+
161
+ ```ts
162
+ interface ValueProvider {
163
+ provide: ProviderToken;
164
+
165
+ useValue: any;
166
+ }
167
+ ```
168
+
169
+ **Properties**
170
+
171
+ | Property | Description |
172
+ | ------------------------ | ----------------------------------------------------------- |
173
+ | provide: `ProviderToken` | A provider token. |
174
+ | useValue: any | The actual value that will be provided for the given token. |
175
+
176
+ ## License
177
+
178
+ This project is licensed under the **MIT license**.
179
+
180
+ See [LICENSE](LICENSE) for more information.
@@ -3,7 +3,7 @@ import { ProviderToken } from './provider-token';
3
3
  /**
4
4
  * Configures the `Container` to return a value by instantiating `useClass` class.
5
5
  */
6
- export interface ClassProvider<T = any> {
6
+ export interface ClassProvider {
7
7
  /**
8
8
  * Provider token.
9
9
  */
@@ -11,7 +11,7 @@ export interface ClassProvider<T = any> {
11
11
  /**
12
12
  * Class to instantiate for the `token`.
13
13
  */
14
- useClass: NoArgument<T>;
14
+ useClass: NoArgument<any>;
15
15
  /**
16
16
  * Whether the created instance should be cached.
17
17
  */
@@ -2,7 +2,7 @@ import { ProviderToken } from './provider-token';
2
2
  /**
3
3
  * Configures the `Container` to return a value of another `useExisting` token.
4
4
  */
5
- export interface ExistingProvider<T = any> {
5
+ export interface ExistingProvider {
6
6
  /**
7
7
  * Provider token.
8
8
  */
@@ -10,7 +10,7 @@ export interface ExistingProvider<T = any> {
10
10
  /**
11
11
  * Existing `token` to return.
12
12
  */
13
- useExisting: T;
13
+ useExisting: ProviderToken;
14
14
  /**
15
15
  * Whether the created instance should be cached.
16
16
  */
@@ -3,7 +3,7 @@ import { ProviderToken } from './provider-token';
3
3
  /**
4
4
  * Configures the `Container` to return a value by invoking a `useFactory` function.
5
5
  */
6
- export interface FactoryProvider<T = any> {
6
+ export interface FactoryProvider {
7
7
  /**
8
8
  * Provider token.
9
9
  */
@@ -12,7 +12,7 @@ export interface FactoryProvider<T = any> {
12
12
  * A function to invoke to create an instance for this `token`. The function is
13
13
  * invoked with resolved values of token`s from an instance of the container.
14
14
  */
15
- useFactory: Factory<T>;
15
+ useFactory: Factory<any>;
16
16
  /**
17
17
  * Whether the created instance should be cached.
18
18
  */
@@ -2,4 +2,4 @@ import { ClassProvider } from './class-provider';
2
2
  import { ExistingProvider } from './existing-provider';
3
3
  import { FactoryProvider } from './factory-provider';
4
4
  import { ValueProvider } from './value-provider';
5
- export type Provider<T = any> = ValueProvider<T> | ClassProvider<T> | FactoryProvider<T> | ExistingProvider<T>;
5
+ export type Provider = ValueProvider | ClassProvider | FactoryProvider | ExistingProvider;
@@ -2,7 +2,7 @@ import { ProviderToken } from './provider-token';
2
2
  /**
3
3
  * Configures the `Container` to return a value for a token.
4
4
  */
5
- export interface ValueProvider<T = any> {
5
+ export interface ValueProvider {
6
6
  /**
7
7
  * Provider token.
8
8
  */
@@ -10,5 +10,5 @@ export interface ValueProvider<T = any> {
10
10
  /**
11
11
  * The value to inject.
12
12
  */
13
- useValue: T;
13
+ useValue: any;
14
14
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@armscye/container",
3
- "version": "0.3.0",
4
- "description": "A collection of shared standard TypeScript definitions",
3
+ "version": "0.5.0",
4
+ "description": "A collection of shared standard TypeScript definitions (@container)",
5
5
  "author": "Augustus Kamau",
6
6
  "license": "MIT",
7
7
  "types": "./dist/index.d.ts",
@@ -11,10 +11,11 @@
11
11
  "keywords": [
12
12
  "armscye",
13
13
  "typescript",
14
- "types"
14
+ "types",
15
+ "container"
15
16
  ],
16
17
  "dependencies": {
17
- "@armscye/core": "^0.2.0"
18
+ "@armscye/core": "^0.4.0"
18
19
  },
19
20
  "homepage": "https://github.com/armscye/armscye#readme",
20
21
  "repository": {
@@ -27,5 +28,5 @@
27
28
  "publishConfig": {
28
29
  "access": "public"
29
30
  },
30
- "gitHead": "f2c94ab8ecb4161f6f8c82820a8bbad758d83209"
31
+ "gitHead": "0709eb7276b853296ef820d0e5bd8c170e6d2ee3"
31
32
  }