@enshou/di 0.1.1 → 0.1.2
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 +0 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +7 -9
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -5,12 +5,6 @@ A small dependency injection container for TypeScript.
|
|
|
5
5
|
It gives you a typed token system, a simple container, and an explicit
|
|
6
6
|
`@Inject(...)` decorator for constructor dependencies.
|
|
7
7
|
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
pnpm add @enshou/di
|
|
12
|
-
```
|
|
13
|
-
|
|
14
8
|
## Quick example
|
|
15
9
|
|
|
16
10
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
//#region ../shared/src/index.d.ts
|
|
2
|
+
type Class<T> = new (...args: any[]) => T;
|
|
3
|
+
//#endregion
|
|
1
4
|
//#region src/token.d.ts
|
|
2
5
|
type Token<T> = symbol & {
|
|
3
6
|
__type: T;
|
|
@@ -5,18 +8,16 @@ type Token<T> = symbol & {
|
|
|
5
8
|
declare function createToken<T>(description: string): Token<T>;
|
|
6
9
|
//#endregion
|
|
7
10
|
//#region src/container.d.ts
|
|
8
|
-
type Class$1<T> = new (...args: any[]) => T;
|
|
9
11
|
type Scope = "singleton" | "transient";
|
|
10
12
|
declare class Container {
|
|
11
13
|
private readonly providers;
|
|
12
14
|
private readonly singletonCache;
|
|
13
|
-
registerValue(token: Token<unknown
|
|
14
|
-
registerClass(token: Token<unknown>, value: Class
|
|
15
|
-
resolve<T>(token: Token<T>): T;
|
|
15
|
+
registerValue(token: Token<unknown> | string, value: unknown): void;
|
|
16
|
+
registerClass(token: Token<unknown> | string | Class<any>, value: Class<any>, scope?: Scope): void;
|
|
17
|
+
resolve<T>(token: Token<T> | string | Class<any>): T;
|
|
16
18
|
}
|
|
17
19
|
//#endregion
|
|
18
20
|
//#region src/inject.d.ts
|
|
19
|
-
|
|
20
|
-
declare function Inject(tokens: Array<Token<any>>): <T extends Class<any>>(target: T, _context?: ClassDecoratorContext<T>) => void;
|
|
21
|
+
declare function Inject(tokens: Array<Token<any> | string | Class<any>>): (target: any, _context?: ClassDecoratorContext) => void;
|
|
21
22
|
//#endregion
|
|
22
23
|
export { Container, Inject, type Scope, type Token, createToken };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
const INJECTS_KEY = Symbol(
|
|
1
|
+
//#region src/inject.ts
|
|
2
|
+
const INJECTS_KEY = Symbol();
|
|
3
|
+
function Inject(tokens) {
|
|
4
|
+
return function(target, _context) {
|
|
5
|
+
target[INJECTS_KEY] = tokens;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
3
8
|
//#endregion
|
|
4
9
|
//#region src/container.ts
|
|
5
10
|
var Container = class {
|
|
@@ -26,13 +31,6 @@ var Container = class {
|
|
|
26
31
|
}
|
|
27
32
|
};
|
|
28
33
|
//#endregion
|
|
29
|
-
//#region src/inject.ts
|
|
30
|
-
function Inject(tokens) {
|
|
31
|
-
return function(target, _context) {
|
|
32
|
-
target[INJECTS_KEY] = tokens;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
34
|
//#region src/token.ts
|
|
37
35
|
function createToken(description) {
|
|
38
36
|
return Symbol(description);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enshou/di",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Ivan Popov <iiivanpopov999@gmail.com>",
|
|
@@ -19,11 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@
|
|
22
|
+
"@swc/core": "^1.15.21",
|
|
23
|
+
"@typescript/native-preview": "7.0.0-dev.20260329.1",
|
|
23
24
|
"tsdown": "^0.21.7",
|
|
25
|
+
"unplugin-swc": "^1.5.9",
|
|
24
26
|
"vitest": "^4.1.2"
|
|
25
27
|
},
|
|
26
28
|
"scripts": {
|
|
27
|
-
"build": "tsdown"
|
|
29
|
+
"build": "tsdown",
|
|
30
|
+
"test": "vitest run"
|
|
28
31
|
}
|
|
29
32
|
}
|