@armscye/container 0.2.0 → 0.4.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<T = any> {
27
+ provide: ProviderToken;
28
+
29
+ useClass: NoArgument<T>;
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(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<T = any> {
91
+ provide: ProviderToken;
92
+
93
+ useExisting: T;
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<T = any> {
113
+ provide: ProviderToken;
114
+
115
+ useFactory: Factory<T>;
116
+
117
+ shared?: boolean;
118
+ }
119
+ ```
120
+
121
+ **Properties**
122
+
123
+ | Property | Description |
124
+ | ---------------------- | ----------------------------------------------------------------- |
125
+ | provide: ProviderToken | A provider token. |
126
+ | useFactory: Factory | 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<T = any> =
151
+ | ValueProvider<T>
152
+ | ClassProvider<T>
153
+ | FactoryProvider<T>
154
+ | ExistingProvider<T>;
155
+ ```
156
+
157
+ ### ValueProvider `Interface`
158
+
159
+ Configures the `Container` to return a value for a token.
160
+
161
+ ```ts
162
+ interface ValueProvider<T = any> {
163
+ provide: ProviderToken;
164
+
165
+ useValue: T;
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.
@@ -1,7 +1,7 @@
1
1
  import { NoArgument } from '@armscye/core';
2
- import { ProviderToken } from './provider-token.interface';
2
+ import { ProviderToken } from './provider-token';
3
3
  /**
4
- * Configures the `Container` to return an instance of `useClass` for a token.
4
+ * Configures the `Container` to return a value by instantiating `useClass` class.
5
5
  */
6
6
  export interface ClassProvider<T = any> {
7
7
  /**
@@ -12,4 +12,8 @@ export interface ClassProvider<T = any> {
12
12
  * Class to instantiate for the `token`.
13
13
  */
14
14
  useClass: NoArgument<T>;
15
+ /**
16
+ * Whether the created instance should be cached.
17
+ */
18
+ shared?: boolean;
15
19
  }
@@ -1,4 +1,4 @@
1
- import { ProviderToken } from './provider-token.interface';
1
+ import { ProviderToken } from './provider-token';
2
2
  /**
3
3
  * Describes the interface of a container that exposes methods to read its entries.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { ProviderToken } from './provider-token.interface';
1
+ import { ProviderToken } from './provider-token';
2
2
  /**
3
3
  * Configures the `Container` to return a value of another `useExisting` token.
4
4
  */
@@ -11,4 +11,8 @@ export interface ExistingProvider<T = any> {
11
11
  * Existing `token` to return.
12
12
  */
13
13
  useExisting: T;
14
+ /**
15
+ * Whether the created instance should be cached.
16
+ */
17
+ shared?: boolean;
14
18
  }
@@ -1,5 +1,5 @@
1
- import { Factory } from './factory.interface';
2
- import { ProviderToken } from './provider-token.interface';
1
+ import { Factory } from './factory';
2
+ import { ProviderToken } from './provider-token';
3
3
  /**
4
4
  * Configures the `Container` to return a value by invoking a `useFactory` function.
5
5
  */
@@ -13,4 +13,8 @@ export interface FactoryProvider<T = any> {
13
13
  * invoked with resolved values of token`s from an instance of the container.
14
14
  */
15
15
  useFactory: Factory<T>;
16
+ /**
17
+ * Whether the created instance should be cached.
18
+ */
19
+ shared?: boolean;
16
20
  }
@@ -1,4 +1,4 @@
1
- import { Container } from './container.interface';
1
+ import { Container } from './container';
2
2
  /**
3
3
  * Represents type for a factory. A factory is a function that is able to create an object.
4
4
  * It is provided with an instance of the container in order to access required dependencies.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export * from './class-provider.interface';
2
- export * from './container.interface';
3
- export * from './existing-provider.interface';
4
- export * from './factory-provider.interface';
5
- export * from './factory.interface';
6
- export * from './provider-token.interface';
7
- export * from './provider.interface';
8
- export * from './value-provider.interface';
1
+ export * from './class-provider';
2
+ export * from './container';
3
+ export * from './existing-provider';
4
+ export * from './factory-provider';
5
+ export * from './factory';
6
+ export * from './provider-token';
7
+ export * from './provider';
8
+ export * from './value-provider';
@@ -0,0 +1,5 @@
1
+ import { ClassProvider } from './class-provider';
2
+ import { ExistingProvider } from './existing-provider';
3
+ import { FactoryProvider } from './factory-provider';
4
+ import { ValueProvider } from './value-provider';
5
+ export type Provider<T = any> = ValueProvider<T> | ClassProvider<T> | FactoryProvider<T> | ExistingProvider<T>;
@@ -1,4 +1,4 @@
1
- import { ProviderToken } from './provider-token.interface';
1
+ import { ProviderToken } from './provider-token';
2
2
  /**
3
3
  * Configures the `Container` to return a value for a token.
4
4
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@armscye/container",
3
- "version": "0.2.0",
4
- "description": "A collection of shared standard TypeScript definitions",
3
+ "version": "0.4.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.1.0"
18
+ "@armscye/core": "^0.3.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": "3f346ded1e7a06cf1afac1ba29a6e4f5377d4664"
31
+ "gitHead": "a26e3829ccbd43eae0ab1a1dd165af7ae7b355c1"
31
32
  }
@@ -1,5 +0,0 @@
1
- import { ClassProvider } from './class-provider.interface';
2
- import { ExistingProvider } from './existing-provider.interface';
3
- import { FactoryProvider } from './factory-provider.interface';
4
- import { ValueProvider } from './value-provider.interface';
5
- export type Provider<T = any> = ValueProvider<T> | ClassProvider<T> | FactoryProvider<T> | ExistingProvider<T>;