@stone-js/service-container 0.1.1 → 0.1.3
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 +1 -1
- package/README.md +4 -5
- package/dist/index.d.ts +109 -9
- package/package.json +11 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
4
|
[](https://www.npmjs.com/package/@stone-js/service-container)
|
|
5
5
|
[](https://www.npmjs.com/package/@stone-js/service-container)
|
|
6
|
-

|
|
7
7
|
[](https://github.com/stone-foundation/stone-js-service-container/actions/workflows/main.yml)
|
|
8
8
|
[](https://github.com/stone-foundation/stone-js-service-container/actions/workflows/release.yml)
|
|
9
9
|
[](https://sonarcloud.io/summary/new_code?id=stone-foundation_stone-js-service-container)
|
|
@@ -47,9 +47,8 @@ PNPM:
|
|
|
47
47
|
pnpm add @stone-js/service-container
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
> [!
|
|
51
|
-
> This package is
|
|
52
|
-
> please refer to [`this guide on Pure ESM packages`](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
50
|
+
> [!IMPORTANT]
|
|
51
|
+
> This package is **pure ESM**. Ensure your `package.json` includes `"type": "module"` or configure your bundler appropriately.
|
|
53
52
|
|
|
54
53
|
Make sure your project setup is compatible with ESM. This might involve updating your `package.json` or using certain bundler configurations.
|
|
55
54
|
|
|
@@ -339,7 +338,7 @@ The Stone Service Container simplifies dependency management in your application
|
|
|
339
338
|
|
|
340
339
|
This package is part of the Stone.js ecosystem, a modern JavaScript framework built around the Continuum Architecture.
|
|
341
340
|
|
|
342
|
-
Explore the full documentation: https://stonejs.dev
|
|
341
|
+
Explore the full documentation: [https://stonejs.dev](https://stonejs.dev)
|
|
343
342
|
|
|
344
343
|
## API documentation
|
|
345
344
|
|
package/dist/index.d.ts
CHANGED
|
@@ -24,13 +24,13 @@ declare abstract class Proxiable {
|
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
27
|
-
* const myResolver: Resolver<number> = (container:
|
|
27
|
+
* const myResolver: Resolver<number> = (container: IContainer) => {
|
|
28
28
|
* // Use the container to resolve dependencies and return a number.
|
|
29
29
|
* return 42;
|
|
30
30
|
* };
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
type Resolver<V> = (container:
|
|
33
|
+
type Resolver<V> = (container: IContainer) => V;
|
|
34
34
|
/**
|
|
35
35
|
* A union type representing the possible keys that can be used to bind values in the container.
|
|
36
36
|
*
|
|
@@ -59,6 +59,106 @@ type BindingKey = number | boolean | string | Function | object | symbol;
|
|
|
59
59
|
* Unlike `BindingKey`, `BindingValue` represents the actual data or instance being bound, while `BindingKey` represents the identifier used to access that data.
|
|
60
60
|
*/
|
|
61
61
|
type BindingValue = number | boolean | string | Function | object | symbol;
|
|
62
|
+
/**
|
|
63
|
+
* Interface representing a Binding.
|
|
64
|
+
*
|
|
65
|
+
* This interface defines the contract for all types of bindings in the service container.
|
|
66
|
+
* Bindings are used to manage dependencies and control how objects are instantiated within the container.
|
|
67
|
+
*
|
|
68
|
+
* @template V - The type of value that this binding holds.
|
|
69
|
+
* @author Mr. Stone <evensstone@gmail.com>
|
|
70
|
+
*/
|
|
71
|
+
interface IBinding<V extends BindingValue> {
|
|
72
|
+
/**
|
|
73
|
+
* Resolve and return the value of the binding.
|
|
74
|
+
*
|
|
75
|
+
* @param container - The container to resolve dependencies from.
|
|
76
|
+
* @returns The resolved value of the binding.
|
|
77
|
+
*/
|
|
78
|
+
resolve: (container: IContainer) => V | undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Interface representing a Container.
|
|
82
|
+
*
|
|
83
|
+
* This interface defines the public contract for dependency injection containers,
|
|
84
|
+
* allowing for better testability and preventing circular dependencies.
|
|
85
|
+
*
|
|
86
|
+
* @author Mr. Stone <evensstone@gmail.com>
|
|
87
|
+
*/
|
|
88
|
+
interface IContainer {
|
|
89
|
+
/**
|
|
90
|
+
* Retrieve the value of the bindings property.
|
|
91
|
+
*/
|
|
92
|
+
getBindings: () => Map<BindingKey, IBinding<BindingValue>>;
|
|
93
|
+
/**
|
|
94
|
+
* Retrieve the value of the aliases property.
|
|
95
|
+
*/
|
|
96
|
+
getAliases: () => Map<string, BindingKey>;
|
|
97
|
+
/**
|
|
98
|
+
* Set a binding as alias.
|
|
99
|
+
*/
|
|
100
|
+
alias: (key: BindingKey, aliases: string | string[]) => this;
|
|
101
|
+
/**
|
|
102
|
+
* Check if an alias exists in the container.
|
|
103
|
+
*/
|
|
104
|
+
isAlias: (alias: BindingKey) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Get a binding key by its alias.
|
|
107
|
+
*/
|
|
108
|
+
getAliasKey: (alias: BindingKey) => BindingKey | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Bind a single instance or value into the container under the provided key.
|
|
111
|
+
*/
|
|
112
|
+
instance: (key: BindingKey, value: BindingValue) => this;
|
|
113
|
+
/**
|
|
114
|
+
* Bind a single instance or value into the container under the provided key if not already bound.
|
|
115
|
+
*/
|
|
116
|
+
instanceIf: (key: BindingKey, value: BindingValue) => this;
|
|
117
|
+
/**
|
|
118
|
+
* Bind a resolver function into the container under the provided key as a singleton.
|
|
119
|
+
*/
|
|
120
|
+
singleton: <V extends BindingValue>(key: BindingKey, resolver: Resolver<V>) => this;
|
|
121
|
+
/**
|
|
122
|
+
* Bind a resolver function into the container under the provided key as a singleton if not already bound.
|
|
123
|
+
*/
|
|
124
|
+
singletonIf: <V extends BindingValue>(key: BindingKey, resolver: Resolver<V>) => this;
|
|
125
|
+
/**
|
|
126
|
+
* Bind a resolver function into the container under the provided key, returning a new instance each time.
|
|
127
|
+
*/
|
|
128
|
+
binding: <V extends BindingValue>(key: BindingKey, resolver: Resolver<V>) => this;
|
|
129
|
+
/**
|
|
130
|
+
* Bind a resolver function into the container under the provided key, returning a new instance each time if not already bound.
|
|
131
|
+
*/
|
|
132
|
+
bindingIf: <V extends BindingValue>(key: BindingKey, resolver: Resolver<V>) => this;
|
|
133
|
+
/**
|
|
134
|
+
* Resolve a registered value from the container by its key.
|
|
135
|
+
*/
|
|
136
|
+
make: <V extends BindingValue>(key: BindingKey) => V;
|
|
137
|
+
/**
|
|
138
|
+
* Resolve a value from the container by its key, binding it if necessary.
|
|
139
|
+
*/
|
|
140
|
+
resolve: <V extends BindingValue>(key: BindingKey, singleton?: boolean) => V;
|
|
141
|
+
/**
|
|
142
|
+
* Resolve a value from the container by its key and return it in a factory function.
|
|
143
|
+
*/
|
|
144
|
+
factory: <V extends BindingValue>(key: BindingKey) => () => V;
|
|
145
|
+
/**
|
|
146
|
+
* Check if a value is already bound in the container by its key.
|
|
147
|
+
*/
|
|
148
|
+
bound: (key: BindingKey) => boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Check if a value is already bound in the container by its key.
|
|
151
|
+
*/
|
|
152
|
+
has: (key: BindingKey) => boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Reset the container so that all bindings are removed.
|
|
155
|
+
*/
|
|
156
|
+
clear: () => this;
|
|
157
|
+
/**
|
|
158
|
+
* AutoBind value to the service container.
|
|
159
|
+
*/
|
|
160
|
+
autoBinding: <V extends BindingValue>(name: BindingKey, item?: V, singleton?: boolean, alias?: string | string[]) => this;
|
|
161
|
+
}
|
|
62
162
|
|
|
63
163
|
/**
|
|
64
164
|
* Abstract class representing a Binding.
|
|
@@ -70,7 +170,7 @@ type BindingValue = number | boolean | string | Function | object | symbol;
|
|
|
70
170
|
* @template V - The type of value that this binding holds.
|
|
71
171
|
* @author Mr. Stone <evensstone@gmail.com>
|
|
72
172
|
*/
|
|
73
|
-
declare abstract class Binding<V extends BindingValue> {
|
|
173
|
+
declare abstract class Binding<V extends BindingValue> implements IBinding<V> {
|
|
74
174
|
/**
|
|
75
175
|
* The value held by the binding.
|
|
76
176
|
*
|
|
@@ -97,7 +197,7 @@ declare abstract class Binding<V extends BindingValue> {
|
|
|
97
197
|
* @param container - The container to resolve dependencies from.
|
|
98
198
|
* @returns The resolved value of the binding.
|
|
99
199
|
*/
|
|
100
|
-
abstract resolve(container:
|
|
200
|
+
abstract resolve(container: IContainer): V | undefined;
|
|
101
201
|
}
|
|
102
202
|
|
|
103
203
|
/**
|
|
@@ -109,7 +209,7 @@ declare abstract class Binding<V extends BindingValue> {
|
|
|
109
209
|
*
|
|
110
210
|
* @author Mr. Stone <evensstone@gmail.com>
|
|
111
211
|
*/
|
|
112
|
-
declare class Container extends Proxiable {
|
|
212
|
+
declare class Container extends Proxiable implements IContainer {
|
|
113
213
|
private readonly aliases;
|
|
114
214
|
private readonly resolvingKeys;
|
|
115
215
|
private readonly bindings;
|
|
@@ -379,7 +479,7 @@ declare class Factory<V extends BindingValue> extends ResolverBinding<V> {
|
|
|
379
479
|
* @returns The resolved value of the binding.
|
|
380
480
|
* @throws ContainerError if the value cannot be resolved.
|
|
381
481
|
*/
|
|
382
|
-
resolve(container:
|
|
482
|
+
resolve(container: IContainer): V;
|
|
383
483
|
}
|
|
384
484
|
|
|
385
485
|
/**
|
|
@@ -398,7 +498,7 @@ declare class Instance<V extends BindingValue> extends Binding<V> {
|
|
|
398
498
|
* @param _container - Container to resolve dependencies (not used in this implementation).
|
|
399
499
|
* @returns The resolved value of the binding.
|
|
400
500
|
*/
|
|
401
|
-
resolve(_container:
|
|
501
|
+
resolve(_container: IContainer): V | undefined;
|
|
402
502
|
}
|
|
403
503
|
|
|
404
504
|
/**
|
|
@@ -421,8 +521,8 @@ declare class Singleton<V extends BindingValue> extends ResolverBinding<V> {
|
|
|
421
521
|
* @returns The resolved value of the binding.
|
|
422
522
|
* @throws ContainerError if the value cannot be resolved.
|
|
423
523
|
*/
|
|
424
|
-
resolve(container:
|
|
524
|
+
resolve(container: IContainer): V | undefined;
|
|
425
525
|
}
|
|
426
526
|
|
|
427
527
|
export { Binding, Container, ContainerError, Factory, Instance, Proxiable, ResolverBinding, Singleton };
|
|
428
|
-
export type { BindingKey, BindingValue, Resolver };
|
|
528
|
+
export type { BindingKey, BindingValue, IBinding, IContainer, Resolver };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stone-js/service-container",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Javascript/Typescript IoC Service Container with proxy resolver and destructuring injection",
|
|
5
5
|
"author": "Mr. Stone <evensstone@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=18.
|
|
39
|
+
"node": ">=18.17.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"lint": "ts-standard src",
|
|
@@ -55,24 +55,24 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@commitlint/cli": "^19.8.1",
|
|
57
57
|
"@commitlint/config-conventional": "^19.8.1",
|
|
58
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
58
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
59
59
|
"@rollup/plugin-multi-entry": "^6.0.1",
|
|
60
60
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
61
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
62
|
-
"@types/node": "^24.0.
|
|
63
|
-
"@vitest/coverage-v8": "^3.2.
|
|
61
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
62
|
+
"@types/node": "^24.0.7",
|
|
63
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
64
64
|
"husky": "^9.1.7",
|
|
65
65
|
"rimraf": "^6.0.1",
|
|
66
|
-
"rollup": "^4.
|
|
66
|
+
"rollup": "^4.44.1",
|
|
67
67
|
"rollup-plugin-delete": "^3.0.1",
|
|
68
68
|
"rollup-plugin-dts": "^6.2.1",
|
|
69
|
-
"rollup-plugin-node-externals": "^8.0.
|
|
69
|
+
"rollup-plugin-node-externals": "^8.0.1",
|
|
70
70
|
"ts-standard": "^12.0.2",
|
|
71
71
|
"tslib": "^2.8.1",
|
|
72
|
-
"typedoc": "^0.28.
|
|
73
|
-
"typedoc-plugin-markdown": "^4.
|
|
72
|
+
"typedoc": "^0.28.6",
|
|
73
|
+
"typedoc-plugin-markdown": "^4.7.0",
|
|
74
74
|
"typescript": "^5.6.3",
|
|
75
|
-
"vitest": "^3.2.
|
|
75
|
+
"vitest": "^3.2.4"
|
|
76
76
|
},
|
|
77
77
|
"ts-standard": {
|
|
78
78
|
"globals": [
|