@armscye/container 0.1.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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/class-provider.interface.d.ts +15 -0
- package/dist/container.interface.d.ts +20 -0
- package/dist/existing-provider.interface.d.ts +14 -0
- package/dist/factory-provider.interface.d.ts +16 -0
- package/dist/factory.interface.d.ts +6 -0
- package/dist/index.d.ts +8 -0
- package/dist/provider-token.interface.d.ts +4 -0
- package/dist/provider.interface.d.ts +5 -0
- package/dist/value-provider.interface.d.ts +14 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Augustus Kamau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @armscye/container
|
|
2
|
+
|
|
3
|
+
> A collection of shared standard TypeScript definitions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Using npm:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev @armscye/container
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or using yarn:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @armscye/container --dev
|
|
17
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NoArgument } from '@armscye/core';
|
|
2
|
+
import { ProviderToken } from './provider-token.interface';
|
|
3
|
+
/**
|
|
4
|
+
* Configures the `Container` to return an instance of `useClass` for a token.
|
|
5
|
+
*/
|
|
6
|
+
export interface ClassProvider<T = any> {
|
|
7
|
+
/**
|
|
8
|
+
* Provider token.
|
|
9
|
+
*/
|
|
10
|
+
provide: ProviderToken;
|
|
11
|
+
/**
|
|
12
|
+
* Class to instantiate for the `token`.
|
|
13
|
+
*/
|
|
14
|
+
useClass: NoArgument<T>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ProviderToken } from './provider-token.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Describes the interface of a container that exposes methods to read its entries.
|
|
4
|
+
*/
|
|
5
|
+
export interface Container {
|
|
6
|
+
/**
|
|
7
|
+
* Find an entry of the container based on the provided token.
|
|
8
|
+
* @param token the provider token of the entry to look for
|
|
9
|
+
* @returns an entry from the container if defined
|
|
10
|
+
* @throws Error if no entry was found for the token
|
|
11
|
+
* @throws Error if error while retrieving the entry
|
|
12
|
+
*/
|
|
13
|
+
get<T>(token: ProviderToken): T;
|
|
14
|
+
/**
|
|
15
|
+
* Check if an entry for the given provider token exists.
|
|
16
|
+
* @param token the provider token of the entry to look for
|
|
17
|
+
* @returns whether an entry for the given provider exists
|
|
18
|
+
*/
|
|
19
|
+
has(token: ProviderToken): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProviderToken } from './provider-token.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Configures the `Container` to return a value of another `useExisting` token.
|
|
4
|
+
*/
|
|
5
|
+
export interface ExistingProvider<T = any> {
|
|
6
|
+
/**
|
|
7
|
+
* Provider token.
|
|
8
|
+
*/
|
|
9
|
+
provide: ProviderToken;
|
|
10
|
+
/**
|
|
11
|
+
* Existing `token` to return.
|
|
12
|
+
*/
|
|
13
|
+
useExisting: T;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Factory } from './factory.interface';
|
|
2
|
+
import { ProviderToken } from './provider-token.interface';
|
|
3
|
+
/**
|
|
4
|
+
* Configures the `Container` to return a value by invoking a `useFactory` function.
|
|
5
|
+
*/
|
|
6
|
+
export interface FactoryProvider<T = any> {
|
|
7
|
+
/**
|
|
8
|
+
* Provider token.
|
|
9
|
+
*/
|
|
10
|
+
provide: ProviderToken;
|
|
11
|
+
/**
|
|
12
|
+
* A function to invoke to create an instance for this `token`. The function is
|
|
13
|
+
* invoked with resolved values of token`s from an instance of the container.
|
|
14
|
+
*/
|
|
15
|
+
useFactory: Factory<T>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Container } from './container.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Represents type for a factory. A factory is a function that is able to create an object.
|
|
4
|
+
* It is provided with an instance of the container in order to access required dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export type Factory<T = any> = (container: Container) => T;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +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';
|
|
@@ -0,0 +1,5 @@
|
|
|
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>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProviderToken } from './provider-token.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Configures the `Container` to return a value for a token.
|
|
4
|
+
*/
|
|
5
|
+
export interface ValueProvider<T = any> {
|
|
6
|
+
/**
|
|
7
|
+
* Provider token.
|
|
8
|
+
*/
|
|
9
|
+
provide: ProviderToken;
|
|
10
|
+
/**
|
|
11
|
+
* The value to inject.
|
|
12
|
+
*/
|
|
13
|
+
useValue: T;
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@armscye/container",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A collection of shared standard TypeScript definitions",
|
|
5
|
+
"author": "Augustus Kamau",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"armscye",
|
|
13
|
+
"typescript",
|
|
14
|
+
"types"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@armscye/core": "^0.1.0"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/armscye/armscye#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/armscye/armscye.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/armscye/armscye/issues"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "052fa1099c964068feda456b787214c025533e6c"
|
|
31
|
+
}
|