@half0wl/container 1.0.0 → 1.0.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/LICENSE +21 -0
- package/README.md +85 -0
- package/package.json +8 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ray Chen <meow@ray.cat>
|
|
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,85 @@
|
|
|
1
|
+
# 📦 container
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@half0wl/container)
|
|
4
|
+
[](https://github.com/half0wl/container-dev/actions/workflows/ci.yml)
|
|
5
|
+
[](https://container.lib.ray.cat)
|
|
6
|
+
|
|
7
|
+
Lightweight decorator-based dependency injection container for TypeScript.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm i @half0wl/container
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Container, BaseService, Service, Inject } from "@half0wl/container";
|
|
15
|
+
|
|
16
|
+
interface ContainerDeps {
|
|
17
|
+
db: DatabaseClient;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Service()
|
|
22
|
+
class UserService extends BaseService<ContainerDeps> {
|
|
23
|
+
findById(id: string) {
|
|
24
|
+
return this.deps.db.users.findUnique({ where: { id } });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Service()
|
|
29
|
+
class AuthService extends BaseService<ContainerDeps> {
|
|
30
|
+
@Inject(() => UserService)
|
|
31
|
+
declare readonly userService: UserService;
|
|
32
|
+
|
|
33
|
+
authenticate(token: string) {
|
|
34
|
+
return this.userService.findById(tokenToId(token));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const container = Container.create<ContainerDeps>({ db, logger });
|
|
39
|
+
const auth = container.get(AuthService);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Requires `"experimentalDecorators": true` in tsconfig.json.
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
Full guide and API reference at **[container.lib.ray.cat](https://container.lib.ray.cat)**.
|
|
47
|
+
|
|
48
|
+
- [Getting Started](https://container.lib.ray.cat/guide/getting-started)
|
|
49
|
+
- [Services](https://container.lib.ray.cat/guide/services)
|
|
50
|
+
- [Dependency Injection](https://container.lib.ray.cat/guide/injection)
|
|
51
|
+
- [Tracing](https://container.lib.ray.cat/guide/tracing)
|
|
52
|
+
- [Testing](https://container.lib.ray.cat/guide/testing)
|
|
53
|
+
- [API Reference](https://container.lib.ray.cat/api/)
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# install dependencies
|
|
59
|
+
pnpm install
|
|
60
|
+
|
|
61
|
+
# build all packages
|
|
62
|
+
pnpm -r build
|
|
63
|
+
|
|
64
|
+
# run tests
|
|
65
|
+
pnpm -r test
|
|
66
|
+
|
|
67
|
+
# lint with biome
|
|
68
|
+
pnpm lint
|
|
69
|
+
|
|
70
|
+
# lint and auto-fix
|
|
71
|
+
pnpm lint:fix
|
|
72
|
+
|
|
73
|
+
# run documentation site locally
|
|
74
|
+
pnpm --filter docs dev
|
|
75
|
+
|
|
76
|
+
# build documentation for production
|
|
77
|
+
pnpm --filter docs build
|
|
78
|
+
|
|
79
|
+
# run the demo
|
|
80
|
+
pnpm --filter demo build && pnpm --filter demo start
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
[MIT](./LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@half0wl/container",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Lightweight decorator-based dependency injection container for TypeScript services",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -21,13 +21,6 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
26
|
-
"typecheck": "tsc -p tsconfig.check.json",
|
|
27
|
-
"test": "vitest run",
|
|
28
|
-
"test:watch": "vitest",
|
|
29
|
-
"prepublishOnly": "npm run build"
|
|
30
|
-
},
|
|
31
24
|
"keywords": [
|
|
32
25
|
"dependency-injection",
|
|
33
26
|
"di",
|
|
@@ -41,5 +34,11 @@
|
|
|
41
34
|
"tsup": "^8.0.0",
|
|
42
35
|
"typescript": "^5.4.0",
|
|
43
36
|
"vitest": "^3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.check.json",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest"
|
|
44
43
|
}
|
|
45
|
-
}
|
|
44
|
+
}
|