inversify-typesafe 0.5.2 → 0.5.4
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 +189 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<h1 align="center">inversify-typesafe</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
Boost InversifyJS with Type Safety. <br/>
|
|
4
|
+
Boost <a href="https://inversify.io/" target="_blank">InversifyJS</a> with Type Safety. <br/>
|
|
5
5
|
<a href="https://stackblitz.com/edit/inversify-typesafe?file=test%2Fmain.test.ts" target="_blank">
|
|
6
6
|
<strong>See Demo</strong>
|
|
7
7
|
</a>
|
|
@@ -23,4 +23,191 @@
|
|
|
23
23
|
<a href="https://raw.githubusercontent.com/myeongjae-kim/inversify-typesafe/main/LICENSE">
|
|
24
24
|
<img src="https://img.shields.io/npm/l/inversify-typesafe.svg" alt="MIT license" height="18">
|
|
25
25
|
</a>
|
|
26
|
-
</p>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { createTypesafeContainer, returnTypesafeInject, TypesafeServiceConfig } from "inversify-typesafe";
|
|
30
|
+
|
|
31
|
+
// https://inversify.io/docs/introduction/dependency-inversion/
|
|
32
|
+
interface Weapon {
|
|
33
|
+
damage: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class Katana implements Weapon {
|
|
37
|
+
public readonly damage: number = 10;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const typesafeInject = returnTypesafeInject<Services>()
|
|
41
|
+
|
|
42
|
+
class Ninja {
|
|
43
|
+
constructor(
|
|
44
|
+
@typesafeInject("weaponServiceId") // compile error if a parameter value is not a key of Services
|
|
45
|
+
public readonly weapon: Weapon,
|
|
46
|
+
) { }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type Services = {
|
|
50
|
+
"ninjaServiceId": Ninja; // class
|
|
51
|
+
"weaponServiceId": Weapon; // interface
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const serviceConfig: TypesafeServiceConfig<Services> = {
|
|
55
|
+
// compile error if not compatible with Ninja
|
|
56
|
+
"ninjaServiceId": (bind) => bind().to(Ninja),
|
|
57
|
+
// compile error if not compatible with Katana. Use the second parameter if you need to access the container
|
|
58
|
+
"weaponServiceId": (bind, _container) => bind().to(Katana),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const typesafeContainer = createTypesafeContainer(serviceConfig);
|
|
62
|
+
|
|
63
|
+
console.log(typesafeContainer.get("ninjaServiceId").weapon.damage);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Background
|
|
67
|
+
|
|
68
|
+
[InversifyJS](https://inversify.io/) is a powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript. Although it is excellent on its own, adding a few more type declarations allows you to write more type-safe code by leveraging TypeScript's powerful type system. Wouldn't it be great if entering just a service ID automatically infers type of the service, and if entering an unregistered service ID could be magically detected at compile time? I wrote this library to create a type-safe container by exploiting [TypeScript's String Literal Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) and introduce a service registration method inspired by [Spring](https://spring.io/).
|
|
69
|
+
|
|
70
|
+
### Philosophy
|
|
71
|
+
|
|
72
|
+
In implementing the `inversify-typesafe`, I considered the following points:
|
|
73
|
+
|
|
74
|
+
1. The library proposes an opinionated service registration method, but it should not limit InversifyJS's features.
|
|
75
|
+
2. Users of the library should be able to use all features of InversifyJS whenever they want.
|
|
76
|
+
3. While adhering to the above two principles, user mistakes should be caught at compile time as much as possible.
|
|
77
|
+
4. The types that the library user needs to declare should be minimized.
|
|
78
|
+
|
|
79
|
+
### Good Things
|
|
80
|
+
|
|
81
|
+
- Entering a string service ID into the container automatically infers the registered type without additional type writing.
|
|
82
|
+
- When entering a string into the `get` method to find a service, you can check registered service IDs via autocomplete in your code editor.
|
|
83
|
+
- Compile-time errors occur if you enter a service ID that is not registered in the container.
|
|
84
|
+
- Compile-time errors occur if you enter an unregistered service ID when injecting a service.
|
|
85
|
+
- No additional peer dependencies. Just `inversify` and `reflect-metadata`.
|
|
86
|
+
- 100% test coverage.
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
Via npm
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install inversify-typesafe
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Via yarn
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
yarn add inversify-typesafe
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Via pnpm
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pnpm add inversify-typesafe
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Demo
|
|
109
|
+
|
|
110
|
+
Try it out on <a href="https://stackblitz.com/edit/inversify-typesafe?file=test%2Fmain.test.ts" target="_blank">Stickblitz</a>.
|
|
111
|
+
|
|
112
|
+
## Types
|
|
113
|
+
|
|
114
|
+
https://inversify-typesafe.myeongjae.kim/modules.html
|
|
115
|
+
|
|
116
|
+
## Usage
|
|
117
|
+
|
|
118
|
+
### 1. Declare `Services` Map Type
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
export type Services = {
|
|
122
|
+
"ninjaServiceId": Ninja; // class
|
|
123
|
+
"weaponServiceId": Weapon; // interface
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Users should write `Services`(or whatever name you want) map type to declare the services that will be registered in the container. The keys of the `Services` type are used as service IDs. While InversifyJS registers various types (`class`, `symbol`, etc.) as service IDs, `inversify-typesafe` uses only `string` types as service IDs. Using `string` allows exploiting [TypeScript's String Literal Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) feature to provide magical type safety.
|
|
128
|
+
|
|
129
|
+
### 2. Write Service Config
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { TypesafeServiceConfig } from "inversify-typesafe";
|
|
133
|
+
|
|
134
|
+
export const serviceConfig: TypesafeServiceConfig<Services> = {
|
|
135
|
+
"ninjaServiceId": (bind) => bind().to(Ninja),
|
|
136
|
+
"weaponServiceId": (bind, _container) => bind().to(Katana),
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
This library provides a utility type called `TypesafeServiceConfig<T>`. `TypesafeServiceConfig<T>` constrains the keys of type `T` to be used as service IDs. Passing the previously declared `Services` type as the type parameter to `TypesafeServiceConfig` restricts usage to only the keys of the `Services` type. If you enter a key that does not exist in `Services` or do not provide a function for every key in `Services`, a compile-time error occurs, allowing users to write code more safely.
|
|
141
|
+
|
|
142
|
+
The object's values use lambdas to allow users to utilize all binding features of Inversify. The lambda accepts `bind` as the first parameter and `container` as the second. The first parameter is a [thunk](https://en.wikipedia.org/wiki/Thunk) `() => container.bind(serviceId)` to bind the service ID to the container. Since the thunk to bind the object's key as a service ID is passed as a parameter, the user can choose how to map a service to the service ID. If the user attempts to map a service that is incompatible with the `Services` type declaration, a compile-time error occurs.
|
|
143
|
+
|
|
144
|
+
<img src="./docs/resources/service-config-compile-error.png" alt="" width="707" />
|
|
145
|
+
|
|
146
|
+
The lambda's second parameter receives `container`. For simple cases, using only the first parameter `bind` is sufficient, but you can utilize the second parameter if you need to access the container directly during the service registration process.
|
|
147
|
+
|
|
148
|
+
### 3. Create Typesafe Container
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { createTypesafeContainer } from "inversify-typesafe";
|
|
152
|
+
|
|
153
|
+
const typesafeContainer = createTypesafeContainer(serviceConfig);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The `createTypesafeContainer()` function takes an argument of type `TypesafeServiceConfig<T>` and returns `TypesafeContainer<T>`. Users do not need to specify generic type parameters manually.
|
|
157
|
+
|
|
158
|
+
### 4. Get Service
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
const ninjaService = typesafeContainer.get("ninjaServiceId");
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Passing a key of the user-declared `Services` type as an argument returns the bound service. The return type is inferred well without any additional type writing, and registered service IDs can be checked via autocomplete in the code editor.
|
|
165
|
+
|
|
166
|
+
<img src="./docs/resources/autocomplete.png" alt="" width="626" />
|
|
167
|
+
|
|
168
|
+
Entering a value that is not a key of `Services` causes a compile error.
|
|
169
|
+
|
|
170
|
+
<img src="./docs/resources/get-compile-error.png" alt="" width="955" />
|
|
171
|
+
|
|
172
|
+
### 5. Inject Service
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { returnTypesafeInject } from "inversify-typesafe";
|
|
176
|
+
|
|
177
|
+
export const typesafeInject = returnTypesafeInject<Services>()
|
|
178
|
+
|
|
179
|
+
class Ninja {
|
|
180
|
+
constructor(
|
|
181
|
+
@typesafeInject("weaponServiceId")
|
|
182
|
+
public readonly weapon: Weapon,
|
|
183
|
+
) { }
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Calling the high order function `returnTypesafeInject<T>()` with the user-declared `Services` type as the type parameter returns a decorator function. Entering a value other than a key of the `Services` type into this decorator's parameter causes a compile error.
|
|
188
|
+
|
|
189
|
+
<img src="./docs/resources/inject-compile-error.png" alt="" width="924" />
|
|
190
|
+
|
|
191
|
+
### 6. Every InversifyJS feature is possible
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { ServiceIdentifier } from "inversify";
|
|
195
|
+
|
|
196
|
+
const ninjaService = typesafeContainer._get("ninjaServiceId" as ServiceIdentifier<Ninja>);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The `_get` method of type `TypesafeContainer<T>` performs the same function as the `get` method of the existing `Container` type. You can use the `_get` method when you need the original `get` method rather than the type-safety enhanced function.
|
|
200
|
+
|
|
201
|
+
All methods except the `get` method are identical to the InversifyJS `Container` type.
|
|
202
|
+
|
|
203
|
+
## inversify-typesafe-spring-like
|
|
204
|
+
|
|
205
|
+
Add-On Library for inversify-typesafe to make it more like Spring.
|
|
206
|
+
|
|
207
|
+
https://github.com/myeongjae-kim/inversify-typesafe/tree/main/packages/inversify-typesafe-spring-like
|
|
208
|
+
|
|
209
|
+
Try it out on <a href="https://stackblitz.com/edit/inversify-typesafe-spring-like?file=test%2Fmain.test.ts" target="_blank">Stickblitz</a>.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
MIT © [Myeongjae Kim](https://myeongjae.kim)
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("inversify");exports.createTypesafeContainer=function(n,r){var t=new e.Container(r);return t._get=t.get,Object.entries(n).forEach(function(e){(0,e[1])(t.bind(
|
|
1
|
+
var e=require("inversify");exports.createTypesafeContainer=function(n,r){var t=new e.Container(r);return t._get=t.get,Object.entries(n).forEach(function(e){var n=e[0];(0,e[1])(function(){return t.bind(n)},t)}),t},exports.returnTypesafeInject=function(){return function(n){return e.inject(n)}};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { BindToFluentSyntax, Container, ContainerOptions, inject } from \"inversify\";\n\ntype AbstractServiceMap = Record<string, unknown>;\n\nexport type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, \"get\"> & {\n get<T extends keyof S>(
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { BindToFluentSyntax, Container, ContainerOptions, GetOptions, inject, OptionalGetOptions } from \"inversify\";\n\ntype AbstractServiceMap = Record<string, unknown>;\n\nexport type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, \"get\"> & {\n get<T extends keyof S>(serviceIdentifier: T, options: OptionalGetOptions): S[T] | undefined;\n get<T extends keyof S>(serviceIdentifier: T, options?: GetOptions): S[T];\n _get: Container[\"get\"];\n};\n\nexport type TypesafeServiceConfig<S extends AbstractServiceMap> = {\n [K in keyof S]: ((bind: () => BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);\n};\n\nexport const returnTypesafeInject = <S extends AbstractServiceMap>() => (name: Extract<keyof S, string>) => inject(name);\n\nexport const createTypesafeContainer = <S extends AbstractServiceMap>(\n serviceConfig: TypesafeServiceConfig<S>,\n options?: ContainerOptions,\n): TypesafeContainer<S> => {\n const container = new Container(options) as unknown as TypesafeContainer<S>;\n container._get = container.get;\n\n Object.entries(serviceConfig).forEach(([name, bindingFunction]) => {\n bindingFunction(() => container.bind(name), container);\n });\n\n return container;\n};"],"names":["serviceConfig","options","container","Container","_get","get","Object","entries","forEach","_ref","name","bindingFunction","bind","inject"],"mappings":"2DAgBuC,SACrCA,EACAC,GAEA,IAAMC,EAAY,IAAIC,EAAAA,UAAUF,GAOhC,OANAC,EAAUE,KAAOF,EAAUG,IAE3BC,OAAOC,QAAQP,GAAeQ,QAAQ,SAAAC,GAA4B,IAA1BC,EAAID,MAC1CE,EAD2DF,EAC3DE,IAAgB,WAAM,OAAAT,EAAUU,KAAKF,EAAK,EAAER,EAC9C,GAEOA,CACT,+BAdoC,WAAH,gBAAwCQ,GAA8B,OAAKG,EAAAA,OAAOH,EAAK,CAExH"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { BindToFluentSyntax, Container, ContainerOptions } from "inversify";
|
|
1
|
+
import { BindToFluentSyntax, Container, ContainerOptions, GetOptions, OptionalGetOptions } from "inversify";
|
|
2
2
|
type AbstractServiceMap = Record<string, unknown>;
|
|
3
3
|
export type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, "get"> & {
|
|
4
|
-
get<T extends keyof S>(
|
|
4
|
+
get<T extends keyof S>(serviceIdentifier: T, options: OptionalGetOptions): S[T] | undefined;
|
|
5
|
+
get<T extends keyof S>(serviceIdentifier: T, options?: GetOptions): S[T];
|
|
5
6
|
_get: Container["get"];
|
|
6
7
|
};
|
|
7
8
|
export type TypesafeServiceConfig<S extends AbstractServiceMap> = {
|
|
8
|
-
[K in keyof S]: ((bind: BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);
|
|
9
|
+
[K in keyof S]: ((bind: () => BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);
|
|
9
10
|
};
|
|
10
11
|
export declare const returnTypesafeInject: <S extends AbstractServiceMap>() => (name: Extract<keyof S, string>) => MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
11
12
|
export declare const createTypesafeContainer: <S extends AbstractServiceMap>(serviceConfig: TypesafeServiceConfig<S>, options?: ContainerOptions) => TypesafeContainer<S>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { BindToFluentSyntax, Container, ContainerOptions } from "inversify";
|
|
1
|
+
import { BindToFluentSyntax, Container, ContainerOptions, GetOptions, OptionalGetOptions } from "inversify";
|
|
2
2
|
type AbstractServiceMap = Record<string, unknown>;
|
|
3
3
|
export type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, "get"> & {
|
|
4
|
-
get<T extends keyof S>(
|
|
4
|
+
get<T extends keyof S>(serviceIdentifier: T, options: OptionalGetOptions): S[T] | undefined;
|
|
5
|
+
get<T extends keyof S>(serviceIdentifier: T, options?: GetOptions): S[T];
|
|
5
6
|
_get: Container["get"];
|
|
6
7
|
};
|
|
7
8
|
export type TypesafeServiceConfig<S extends AbstractServiceMap> = {
|
|
8
|
-
[K in keyof S]: ((bind: BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);
|
|
9
|
+
[K in keyof S]: ((bind: () => BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);
|
|
9
10
|
};
|
|
10
11
|
export declare const returnTypesafeInject: <S extends AbstractServiceMap>() => (name: Extract<keyof S, string>) => MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
11
12
|
export declare const createTypesafeContainer: <S extends AbstractServiceMap>(serviceConfig: TypesafeServiceConfig<S>, options?: ContainerOptions) => TypesafeContainer<S>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{inject as e,Container as t}from"inversify";const r=()=>t=>e(t),n=(e,r)=>{const n=new t(r);return n._get=n.get,Object.entries(e).forEach(([e,t])=>{t(n.bind(e),n)}),n};export{n as createTypesafeContainer,r as returnTypesafeInject};
|
|
1
|
+
import{inject as e,Container as t}from"inversify";const r=()=>t=>e(t),n=(e,r)=>{const n=new t(r);return n._get=n.get,Object.entries(e).forEach(([e,t])=>{t(()=>n.bind(e),n)}),n};export{n as createTypesafeContainer,r as returnTypesafeInject};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { BindToFluentSyntax, Container, ContainerOptions, inject } from \"inversify\";\n\ntype AbstractServiceMap = Record<string, unknown>;\n\nexport type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, \"get\"> & {\n get<T extends keyof S>(
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { BindToFluentSyntax, Container, ContainerOptions, GetOptions, inject, OptionalGetOptions } from \"inversify\";\n\ntype AbstractServiceMap = Record<string, unknown>;\n\nexport type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, \"get\"> & {\n get<T extends keyof S>(serviceIdentifier: T, options: OptionalGetOptions): S[T] | undefined;\n get<T extends keyof S>(serviceIdentifier: T, options?: GetOptions): S[T];\n _get: Container[\"get\"];\n};\n\nexport type TypesafeServiceConfig<S extends AbstractServiceMap> = {\n [K in keyof S]: ((bind: () => BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);\n};\n\nexport const returnTypesafeInject = <S extends AbstractServiceMap>() => (name: Extract<keyof S, string>) => inject(name);\n\nexport const createTypesafeContainer = <S extends AbstractServiceMap>(\n serviceConfig: TypesafeServiceConfig<S>,\n options?: ContainerOptions,\n): TypesafeContainer<S> => {\n const container = new Container(options) as unknown as TypesafeContainer<S>;\n container._get = container.get;\n\n Object.entries(serviceConfig).forEach(([name, bindingFunction]) => {\n bindingFunction(() => container.bind(name), container);\n });\n\n return container;\n};"],"names":["returnTypesafeInject","name","inject","createTypesafeContainer","serviceConfig","options","container","Container","_get","get","Object","entries","forEach","bindingFunction","bind"],"mappings":"kDAca,MAAAA,EAAuBA,IAAqCC,GAAmCC,EAAOD,GAEtGE,EAA0BA,CACrCC,EACAC,KAEA,MAAMC,EAAY,IAAIC,EAAUF,GAOhC,OANAC,EAAUE,KAAOF,EAAUG,IAE3BC,OAAOC,QAAQP,GAAeQ,QAAQ,EAAEX,EAAMY,MAC5CA,EAAgB,IAAMP,EAAUQ,KAAKb,GAAOK,KAGvCA"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("inversify")):"function"==typeof define&&define.amd?define(["exports","inversify"],n):n((e||self).inversifyTypesafe={},e.inversify)}(this,function(e,n){e.createTypesafeContainer=function(e,
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("inversify")):"function"==typeof define&&define.amd?define(["exports","inversify"],n):n((e||self).inversifyTypesafe={},e.inversify)}(this,function(e,n){e.createTypesafeContainer=function(e,t){var i=new n.Container(t);return i._get=i.get,Object.entries(e).forEach(function(e){var n=e[0];(0,e[1])(function(){return i.bind(n)},i)}),i},e.returnTypesafeInject=function(){return function(e){return n.inject(e)}}});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { BindToFluentSyntax, Container, ContainerOptions, inject } from \"inversify\";\n\ntype AbstractServiceMap = Record<string, unknown>;\n\nexport type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, \"get\"> & {\n get<T extends keyof S>(
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { BindToFluentSyntax, Container, ContainerOptions, GetOptions, inject, OptionalGetOptions } from \"inversify\";\n\ntype AbstractServiceMap = Record<string, unknown>;\n\nexport type TypesafeContainer<S extends AbstractServiceMap> = Omit<Container, \"get\"> & {\n get<T extends keyof S>(serviceIdentifier: T, options: OptionalGetOptions): S[T] | undefined;\n get<T extends keyof S>(serviceIdentifier: T, options?: GetOptions): S[T];\n _get: Container[\"get\"];\n};\n\nexport type TypesafeServiceConfig<S extends AbstractServiceMap> = {\n [K in keyof S]: ((bind: () => BindToFluentSyntax<S[K]>, container: TypesafeContainer<S>) => void);\n};\n\nexport const returnTypesafeInject = <S extends AbstractServiceMap>() => (name: Extract<keyof S, string>) => inject(name);\n\nexport const createTypesafeContainer = <S extends AbstractServiceMap>(\n serviceConfig: TypesafeServiceConfig<S>,\n options?: ContainerOptions,\n): TypesafeContainer<S> => {\n const container = new Container(options) as unknown as TypesafeContainer<S>;\n container._get = container.get;\n\n Object.entries(serviceConfig).forEach(([name, bindingFunction]) => {\n bindingFunction(() => container.bind(name), container);\n });\n\n return container;\n};"],"names":["serviceConfig","options","container","Container","_get","get","Object","entries","forEach","_ref","name","bindingFunction","bind","inject"],"mappings":"oTAgBuC,SACrCA,EACAC,GAEA,IAAMC,EAAY,IAAIC,EAAAA,UAAUF,GAOhC,OANAC,EAAUE,KAAOF,EAAUG,IAE3BC,OAAOC,QAAQP,GAAeQ,QAAQ,SAAAC,GAA4B,IAA1BC,EAAID,MAC1CE,EAD2DF,EAC3DE,IAAgB,WAAM,OAAAT,EAAUU,KAAKF,EAAK,EAAER,EAC9C,GAEOA,CACT,yBAdoC,WAAH,gBAAwCQ,GAA8B,OAAKG,EAAAA,OAAOH,EAAK,CAExH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inversify-typesafe",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.4",
|
|
5
5
|
"description": "Boost InversifyJS with Type Safety.",
|
|
6
6
|
"source": "src/index.ts",
|
|
7
7
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"setup": "husky install",
|
|
33
33
|
"clean": "rimraf dist",
|
|
34
34
|
"bundle": "microbundle --format modern,cjs,umd",
|
|
35
|
-
"typedoc": "typedoc src/index.ts --out docs/
|
|
35
|
+
"typedoc": "typedoc src/index.ts --out docs/web/types",
|
|
36
36
|
"build": "pnpm run clean && pnpm run bundle && sh ./scripts/generate-cts.sh && rimraf dist/index.d.ts\\'\\'",
|
|
37
37
|
"dev": "microbundle watch",
|
|
38
38
|
"prepublishOnly": "pnpm run test && pnpm run build",
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"author": "Myeongjae Kim",
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@types/inversify": "^2.0.33",
|
|
65
64
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
66
65
|
"@typescript-eslint/parser": "^8.50.1",
|
|
67
66
|
"@vitest/coverage-v8": "^4.0.16",
|