@typewirets/inversify 0.1.0 → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ - Depends on `@typewirets/core` 0.2.0.
6
+ - **Node.js 22 or later is required.** `engines.node` is now `>=22`, because Node.js 20 reached end-of-life on 30 April 2026. CI tests Node.js 22, 24 and 26.
7
+ - **Re-applying a wire after it was resolved builds a fresh value, by design.** The adapter replaces the Inversify binding, and Inversify discards its cached instance, so caching stays Inversify's job. `@typewirets/core`'s `TypeWireContainer` keeps the cached value instead. The README and `bind`'s TSDoc now say so, and a test pins it.
8
+ - **Always `await` `bind` and `apply`.** Inversify 7 has no synchronous unbind, so on an already-bound type the new binding is registered only after the old one is removed. Until then, resolving the type returns the old binding's value.
9
+ - Release this adapter together with `@typewirets/core` and `@typewirets/react`. It pins core exactly, so an adapter released on its own can be installed next to a core whose `BindingContext` contract it does not match. See the release checklist in `MAINTAINING.md`.
10
+
11
+ ### Also in this release: changes prepared as 0.1.1, which was never published
12
+
13
+ - `InversifyAdapter.bind` now replaces an existing binding for the same type itself, because `@typewirets/core`'s `apply` no longer unbinds before binding. Re-applying a wire still replaces its Inversify binding and discards Inversify's cached instance, as in 0.1.0.
14
+ - Upgrade this adapter together with `@typewirets/core` 0.2.0. Adapter 0.1.0 with wires from this core adds a second Inversify binding when a wire is re-applied, because neither side unbinds.
15
+ - **CommonJS `require()` works.** The package is `"type": "module"`, so Node loaded the CommonJS build in `dist/cjs` as an ES module: `require()` from plain Node (TypeScript compiled to CommonJS, ts-node) threw `ReferenceError: exports is not defined`. Bundlers, Jest and ESM `import` were not affected. The build now writes `dist/cjs/package.json` with `{"type":"commonjs"}`.
16
+
17
+ ## 0.2.0-rc.1
18
+
19
+ Release candidate for 0.2.0, with the same changes. They are listed under 0.2.0.
20
+
21
+ ## 0.1.0
22
+
23
+ - Initial release.
package/README.md CHANGED
@@ -156,6 +156,12 @@ await loggerWire.apply(adapter); // Note the await
156
156
  const logger = loggerWire.getInstance(adapter);
157
157
  ```
158
158
 
159
+ ## Re-applying a Wire
160
+
161
+ Re-applying a wire for a type that is already bound replaces its Inversify binding, and Inversify discards the cached instance with it. A singleton that was already resolved is built again on the next resolve, from the new wire's creator (for example after `wire.withCreator(...).apply(adapter)`). Caching is Inversify's job here. This differs from `TypeWireContainer` in `@typewirets/core`, which keeps a cached singleton when the wire is re-applied.
162
+
163
+ Always `await` `apply` (and `bind`). Inversify 7 only unbinds asynchronously, so when the type is already bound, the new binding is registered only after the old one has been removed. Until then, resolving the type still returns the old binding's value.
164
+
159
165
  ## Scope Mapping and Behavior
160
166
 
161
167
  The adapter automatically maps TypeWire scopes to Inversify binding scopes:
@@ -69,12 +69,26 @@ export declare class InversifyAdapter implements TypeWireResolutionContext, Bind
69
69
  */
70
70
  get<T>(typeSymbol: TypeSymbol<T>): Promise<T>;
71
71
  /**
72
- * Binds a TypeWire to the InversifyJS container.
73
- * Configures the binding with the appropriate scope and creator function.
72
+ * Binds a TypeWire to the InversifyJS container, replacing any existing
73
+ * binding for the same type. Configures the binding with the appropriate
74
+ * scope and creator function.
75
+ *
76
+ * Replacing a binding discards Inversify's cached instance, so re-applying a
77
+ * singleton wire after it was resolved (for example
78
+ * `wire.withCreator(...).apply(adapter)`) builds a fresh value on the next
79
+ * resolve. Caching is Inversify's job here. This differs from
80
+ * `TypeWireContainer` in `@typewirets/core`, which keeps the cached value.
81
+ *
82
+ * Always await `bind` (or `wire.apply(adapter)`). When the type is already
83
+ * bound, the old binding is removed with Inversify's asynchronous
84
+ * `container.unbind` (Inversify 7 has no synchronous unbind) and the new
85
+ * binding is registered only after that resolves. Until then, resolving the
86
+ * type still returns the old binding's value.
74
87
  *
75
88
  * @param typeWire - The TypeWire to bind
89
+ * @returns A promise that resolves once the new binding is registered
76
90
  */
77
- bind(typeWire: AnyTypeWire): void | Promise<void>;
91
+ bind(typeWire: AnyTypeWire): Promise<void>;
78
92
  /**
79
93
  * Removes a binding from the InversifyJS container.
80
94
  * Also removes any tracking information for the binding.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,cAAc,EACd,UAAU,EACV,iBAAiB,IAAI,yBAAyB,EAC/C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAanE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBACX,YAAW,yBAAyB,EAAE,cAAc;;IAkBxC,QAAQ,CAAC,SAAS,EAAE,SAAS;IAhBzC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IAEjD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IAErD;;;;OAIG;gBACkB,SAAS,EAAE,SAAS;IAYzC;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,GAAG,CAAC;IAUxC;;;;;;;;OAQG;IACG,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAUnD;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBjD;;;;;;OAMG;IACG,MAAM,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO;CAG5C;AAED;;;;;;;;;;;;;;;;;;GAkBG;A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,EAAE,SAAS,GACnB,yBAAyB,GAAG,cAAc,CAE5C"}
package/dist/cjs/index.js CHANGED
@@ -105,12 +105,29 @@ class InversifyAdapter {
105
105
  return result;
106
106
  }
107
107
  /**
108
- * Binds a TypeWire to the InversifyJS container.
109
- * Configures the binding with the appropriate scope and creator function.
108
+ * Binds a TypeWire to the InversifyJS container, replacing any existing
109
+ * binding for the same type. Configures the binding with the appropriate
110
+ * scope and creator function.
111
+ *
112
+ * Replacing a binding discards Inversify's cached instance, so re-applying a
113
+ * singleton wire after it was resolved (for example
114
+ * `wire.withCreator(...).apply(adapter)`) builds a fresh value on the next
115
+ * resolve. Caching is Inversify's job here. This differs from
116
+ * `TypeWireContainer` in `@typewirets/core`, which keeps the cached value.
117
+ *
118
+ * Always await `bind` (or `wire.apply(adapter)`). When the type is already
119
+ * bound, the old binding is removed with Inversify's asynchronous
120
+ * `container.unbind` (Inversify 7 has no synchronous unbind) and the new
121
+ * binding is registered only after that resolves. Until then, resolving the
122
+ * type still returns the old binding's value.
110
123
  *
111
124
  * @param typeWire - The TypeWire to bind
125
+ * @returns A promise that resolves once the new binding is registered
112
126
  */
113
- bind(typeWire) {
127
+ async bind(typeWire) {
128
+ if (this.isBound(typeWire.type)) {
129
+ await this.unbind(typeWire.type);
130
+ }
114
131
  const bound = this.container
115
132
  .bind(typeWire.type.symbol)
116
133
  .toDynamicValue((_ctx) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAqBA,gCAaC;AAgKD,wDAIC;AA7LD;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,QAAQ,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;QAC5B,KAAK,WAAW;YACd,OAAO,WAAW,CAAC;QACrB,KAAK,WAAW;YACd,OAAO,WAAW,CAA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,KAAK,CAAC,cAAc,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,UAAyB;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,UAAyB;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;CACF;AA1ID,4CA0IC;oHA/Gc,MAAc;IACzB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AA+GH;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,sBAAsB,CACpC,SAAoB;IAEpB,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -69,12 +69,26 @@ export declare class InversifyAdapter implements TypeWireResolutionContext, Bind
69
69
  */
70
70
  get<T>(typeSymbol: TypeSymbol<T>): Promise<T>;
71
71
  /**
72
- * Binds a TypeWire to the InversifyJS container.
73
- * Configures the binding with the appropriate scope and creator function.
72
+ * Binds a TypeWire to the InversifyJS container, replacing any existing
73
+ * binding for the same type. Configures the binding with the appropriate
74
+ * scope and creator function.
75
+ *
76
+ * Replacing a binding discards Inversify's cached instance, so re-applying a
77
+ * singleton wire after it was resolved (for example
78
+ * `wire.withCreator(...).apply(adapter)`) builds a fresh value on the next
79
+ * resolve. Caching is Inversify's job here. This differs from
80
+ * `TypeWireContainer` in `@typewirets/core`, which keeps the cached value.
81
+ *
82
+ * Always await `bind` (or `wire.apply(adapter)`). When the type is already
83
+ * bound, the old binding is removed with Inversify's asynchronous
84
+ * `container.unbind` (Inversify 7 has no synchronous unbind) and the new
85
+ * binding is registered only after that resolves. Until then, resolving the
86
+ * type still returns the old binding's value.
74
87
  *
75
88
  * @param typeWire - The TypeWire to bind
89
+ * @returns A promise that resolves once the new binding is registered
76
90
  */
77
- bind(typeWire: AnyTypeWire): void | Promise<void>;
91
+ bind(typeWire: AnyTypeWire): Promise<void>;
78
92
  /**
79
93
  * Removes a binding from the InversifyJS container.
80
94
  * Also removes any tracking information for the binding.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,cAAc,EACd,UAAU,EACV,iBAAiB,IAAI,yBAAyB,EAC/C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAanE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBACX,YAAW,yBAAyB,EAAE,cAAc;;IAkBxC,QAAQ,CAAC,SAAS,EAAE,SAAS;IAhBzC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IAEjD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IAErD;;;;OAIG;gBACkB,SAAS,EAAE,SAAS;IAYzC;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,GAAG,CAAC;IAUxC;;;;;;;;OAQG;IACG,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAUnD;;;;;OAKG;IACH,IAAI,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WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BhD;;;;;;OAMG;IACG,MAAM,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO;CAG5C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,GACnB,yBAAyB,GAAG,cAAc,CAE5C"}
package/dist/esm/index.js CHANGED
@@ -100,12 +100,29 @@ export class InversifyAdapter {
100
100
  return result;
101
101
  }
102
102
  /**
103
- * Binds a TypeWire to the InversifyJS container.
104
- * Configures the binding with the appropriate scope and creator function.
103
+ * Binds a TypeWire to the InversifyJS container, replacing any existing
104
+ * binding for the same type. Configures the binding with the appropriate
105
+ * scope and creator function.
106
+ *
107
+ * Replacing a binding discards Inversify's cached instance, so re-applying a
108
+ * singleton wire after it was resolved (for example
109
+ * `wire.withCreator(...).apply(adapter)`) builds a fresh value on the next
110
+ * resolve. Caching is Inversify's job here. This differs from
111
+ * `TypeWireContainer` in `@typewirets/core`, which keeps the cached value.
112
+ *
113
+ * Always await `bind` (or `wire.apply(adapter)`). When the type is already
114
+ * bound, the old binding is removed with Inversify's asynchronous
115
+ * `container.unbind` (Inversify 7 has no synchronous unbind) and the new
116
+ * binding is registered only after that resolves. Until then, resolving the
117
+ * type still returns the old binding's value.
105
118
  *
106
119
  * @param typeWire - The TypeWire to bind
120
+ * @returns A promise that resolves once the new binding is registered
107
121
  */
108
- bind(typeWire) {
122
+ async bind(typeWire) {
123
+ if (this.isBound(typeWire.type)) {
124
+ await this.unbind(typeWire.type);
125
+ }
109
126
  const bound = this.container
110
127
  .bind(typeWire.type.symbol)
111
128
  .toDynamicValue((_ctx) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AASA;;;;;;;;;;;GAWG;AACH,M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AG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC1C,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACzB,MAAM;gBACR,KAAK,WAAW;oBACd,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACzB,MAAM;gBACR,KAAK,SAAS;oBACZ,KAAK,CAAC,cAAc,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,UAAyB;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,UAAyB;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;CACF;oHA/Gc,MAAc;IACzB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AA+GH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAoB;IAEpB,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC"}
@@ -69,12 +69,26 @@ export declare class InversifyAdapter implements TypeWireResolutionContext, Bind
69
69
  */
70
70
  get<T>(typeSymbol: TypeSymbol<T>): Promise<T>;
71
71
  /**
72
- * Binds a TypeWire to the InversifyJS container.
73
- * Configures the binding with the appropriate scope and creator function.
72
+ * Binds a TypeWire to the InversifyJS container, replacing any existing
73
+ * binding for the same type. Configures the binding with the appropriate
74
+ * scope and creator function.
75
+ *
76
+ * Replacing a binding discards Inversify's cached instance, so re-applying a
77
+ * singleton wire after it was resolved (for example
78
+ * `wire.withCreator(...).apply(adapter)`) builds a fresh value on the next
79
+ * resolve. Caching is Inversify's job here. This differs from
80
+ * `TypeWireContainer` in `@typewirets/core`, which keeps the cached value.
81
+ *
82
+ * Always await `bind` (or `wire.apply(adapter)`). When the type is already
83
+ * bound, the old binding is removed with Inversify's asynchronous
84
+ * `container.unbind` (Inversify 7 has no synchronous unbind) and the new
85
+ * binding is registered only after that resolves. Until then, resolving the
86
+ * type still returns the old binding's value.
74
87
  *
75
88
  * @param typeWire - The TypeWire to bind
89
+ * @returns A promise that resolves once the new binding is registered
76
90
  */
77
- bind(typeWire: AnyTypeWire): void | Promise<void>;
91
+ bind(typeWire: AnyTypeWire): Promise<void>;
78
92
  /**
79
93
  * Removes a binding from the InversifyJS container.
80
94
  * Also removes any tracking information for the binding.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,cAAc,EACd,UAAU,EACV,iBAAiB,IAAI,yBAAyB,EAC/C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAanE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBACX,YAAW,yBAAyB,EAAE,cAAc;;IAkBxC,QAAQ,CAAC,SAAS,EAAE,SAAS;IAhBzC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IAEjD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IAErD;;;;OAIG;gBACkB,SAAS,EAAE,SAAS;IAYzC;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,GAAG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G,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAUnD;;;;;;;;;;;;;;;;;;;OAmBG;IACG,IAAI,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BhD;;;;;;OAMG;IACG,MAAM,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO;CAG5C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,GACnB,yBAAyB,GAAG,cAAc,CAE5C"}
@@ -100,12 +100,29 @@ export class InversifyAdapter {
100
100
  return result;
101
101
  }
102
102
  /**
103
- * Binds a TypeWire to the InversifyJS container.
104
- * Configures the binding with the appropriate scope and creator function.
103
+ * Binds a TypeWire to the InversifyJS container, replacing any existing
104
+ * binding for the same type. Configures the binding with the appropriate
105
+ * scope and creator function.
106
+ *
107
+ * Replacing a binding discards Inversify's cached instance, so re-applying a
108
+ * singleton wire after it was resolved (for example
109
+ * `wire.withCreator(...).apply(adapter)`) builds a fresh value on the next
110
+ * resolve. Caching is Inversify's job here. This differs from
111
+ * `TypeWireContainer` in `@typewirets/core`, which keeps the cached value.
112
+ *
113
+ * Always await `bind` (or `wire.apply(adapter)`). When the type is already
114
+ * bound, the old binding is removed with Inversify's asynchronous
115
+ * `container.unbind` (Inversify 7 has no synchronous unbind) and the new
116
+ * binding is registered only after that resolves. Until then, resolving the
117
+ * type still returns the old binding's value.
105
118
  *
106
119
  * @param typeWire - The TypeWire to bind
120
+ * @returns A promise that resolves once the new binding is registered
107
121
  */
108
- bind(typeWire) {
122
+ async bind(typeWire) {
123
+ if (this.isBound(typeWire.type)) {
124
+ await this.unbind(typeWire.type);
125
+ }
109
126
  const bound = this.container
110
127
  .bind(typeWire.type.symbol)
111
128
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AC,KAAK,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE,CAAC;YACV,QAAQ,KAAK,EAAE,CAAC;gBACd,KAAK,WAAW;oBACd,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC1C,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACzB,MAAM;gBACR,KAAK,WAAW;oBACd,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACzB,MAAM;gBACR,KAAK,SAAS;oBACZ,KAAK,CAAC,cAAc,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,UAAyB;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,UAAyB;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;CACF;oHA/Gc,MAAc;IACzB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AA+GH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAoB;IAEpB,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typewirets/inversify",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "InversifyJS adapter for TypeWire dependency injection",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",
@@ -15,10 +15,8 @@
15
15
  },
16
16
  "files": [
17
17
  "dist",
18
- "src/*.ts",
19
- "!src/**/*.test.ts",
20
- "!src/**/__tests__/**",
21
18
  "README.md",
19
+ "CHANGELOG.md",
22
20
  "LICENSE"
23
21
  ],
24
22
  "keywords": [
@@ -40,24 +38,31 @@
40
38
  "url": "https://github.com/typewirets/typewirets/issues"
41
39
  },
42
40
  "homepage": "https://github.com/typewirets/typewirets#readme",
41
+ "sideEffects": false,
42
+ "engines": {
43
+ "node": ">=22"
44
+ },
43
45
  "devDependencies": {
44
46
  "@types/node": "^22.13.10",
47
+ "inversify": "^7.1.0",
45
48
  "rimraf": "^6.0.1",
46
49
  "typescript": "5.8.2",
47
50
  "vitest": "^3.0.8",
48
51
  "@typewirets/typescript-config": "0.0.0"
49
52
  },
53
+ "peerDependencies": {
54
+ "inversify": "^7.0.0"
55
+ },
50
56
  "dependencies": {
51
- "inversify": "^7.1.0",
52
- "@typewirets/core": "0.1.0"
57
+ "@typewirets/core": "0.2.0"
53
58
  },
54
59
  "scripts": {
55
60
  "build": "pnpm clean && pnpm --filter '@typewirets/inversify' --parallel '/^build:.*/'",
56
- "build:cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module Commonjs --moduleResolution Node",
61
+ "build:cjs": "node ../../scripts/write-cjs-package-json.mjs && tsc --project tsconfig.build.json --outDir dist/cjs --module Commonjs --moduleResolution Node",
57
62
  "build:esm": "tsc --project tsconfig.build.json --outDir dist/esm --module ES2020 --moduleResolution Node",
58
63
  "build:types": "tsc --project tsconfig.build.json --outDir dist/types --declaration --declarationMap",
59
64
  "dev": "pnpm clean && pnpm --filter '@typewirets/inversify' --parallel '/^dev:.*/'",
60
- "dev:cjs": "tsc --watch --project tsconfig.build.json --outDir dist/cjs --module Commonjs --moduleResolution Node",
65
+ "dev:cjs": "node ../../scripts/write-cjs-package-json.mjs && tsc --watch --project tsconfig.build.json --outDir dist/cjs --module Commonjs --moduleResolution Node",
61
66
  "dev:esm": "tsc --watch --project tsconfig.build.json --outDir dist/esm --module ES2020 --moduleResolution Node",
62
67
  "dev:types": "tsc --watch --project tsconfig.build.json --outDir dist/types --declaration --declarationMap",
63
68
  "clean": "rimraf dist",
package/src/index.ts DELETED
@@ -1,199 +0,0 @@
1
- import type {
2
- AnyTypeSymbol,
3
- AnyTypeWire,
4
- BindingContext,
5
- TypeSymbol,
6
- ResolutionContext as TypeWireResolutionContext,
7
- } from "@typewirets/core";
8
- import type { BindingScope, Container } from "inversify";
9
-
10
- /**
11
- * Converts a TypeWire scope string to the equivalent InversifyJS BindingScope.
12
- *
13
- * @param scope - The TypeWire scope string (e.g., 'singleton', 'transient', 'request')
14
- * @returns The equivalent InversifyJS BindingScope or undefined if no conversion is possible
15
- *
16
- * @example
17
- * ```typescript
18
- * // Convert a TypeWire scope to InversifyJS scope
19
- * const inversifyScope = adoptScope('singleton'); // returns 'Singleton'
20
- * ```
21
- */
22
- export function adoptScope(scope?: string): BindingScope | undefined {
23
- if (!scope) {
24
- return "Singleton";
25
- }
26
-
27
- switch (scope.toLowerCase()) {
28
- case "singleton":
29
- return "Singleton";
30
- case "transient":
31
- return "Transient";
32
- case "request":
33
- return "Request";
34
- }
35
- }
36
-
37
- /**
38
- * Adapter class that provides both TypeWire ResolutionContext and BindingContext
39
- * interfaces on top of an InversifyJS container.
40
- *
41
- * This adapter allows TypeWire definitions to work with an existing InversifyJS
42
- * container, providing a bridge between the two dependency injection systems.
43
- *
44
- * @example
45
- * ```typescript
46
- * const container = new Container();
47
- * const adapter = new InversifyAdapter(container);
48
- *
49
- * // Now you can use TypeWire with your InversifyJS container
50
- * await serviceWire.apply(adapter);
51
- * const service = await serviceWire.getInstance(adapter);
52
- * ```
53
- */
54
- export class InversifyAdapter
55
- implements TypeWireResolutionContext, BindingContext
56
- {
57
- /**
58
- * Set of symbols for which instances have been loaded/initialized.
59
- * Used to track which singleton instances have already been created.
60
- */
61
- private readonly loaded: Set<symbol> = new Set();
62
-
63
- /**
64
- * Set of symbols that represent singleton-scoped dependencies.
65
- */
66
- private readonly singletons: Set<symbol> = new Set();
67
-
68
- /**
69
- * Creates a new InversifyAdapter for the specified container.
70
- *
71
- * @param container - The InversifyJS container to adapt
72
- */
73
- constructor(readonly container: Container) {}
74
-
75
- /**
76
- * Checks if a symbol represents a singleton-scoped dependency.
77
- *
78
- * @param symbol - The symbol to check
79
- * @returns True if the dependency is singleton-scoped, false otherwise
80
- */
81
- #isSingleton(symbol: symbol): boolean {
82
- return this.singletons.has(symbol);
83
- }
84
-
85
- /**
86
- * Gets an instance of type T synchronously.
87
- * For singleton-scoped dependencies, also tracks that they have been loaded.
88
- *
89
- * @template T - The type of instance to get
90
- * @param typeSymbol - The type symbol identifying the dependency
91
- * @returns An instance of type T
92
- * @throws Error if the dependency cannot be resolved synchronously
93
- */
94
- getSync<T>(typeSymbol: AnyTypeSymbol): T {
95
- if (!this.#isSingleton(typeSymbol.symbol)) {
96
- return this.container.get(typeSymbol.symbol);
97
- }
98
-
99
- const result = this.container.get(typeSymbol.symbol) as T;
100
- this.loaded.add(typeSymbol.symbol);
101
- return result;
102
- }
103
-
104
- /**
105
- * Gets an instance of type T asynchronously.
106
- * For singleton-scoped dependencies, also tracks that they have been loaded.
107
- *
108
- * @template T - The type of instance to get
109
- * @param typeSymbol - The type symbol identifying the dependency
110
- * @returns A promise that resolves to an instance of type T
111
- * @throws Error if the dependency is not found
112
- */
113
- async get<T>(typeSymbol: TypeSymbol<T>): Promise<T> {
114
- if (!this.#isSingleton(typeSymbol.symbol)) {
115
- return this.container.getAsync(typeSymbol.symbol);
116
- }
117
-
118
- const result = await this.container.getAsync(typeSymbol.symbol);
119
- this.loaded.add(typeSymbol.symbol);
120
- return result as T;
121
- }
122
-
123
- /**
124
- * Binds a TypeWire to the InversifyJS container.
125
- * Configures the binding with the appropriate scope and creator function.
126
- *
127
- * @param typeWire - The TypeWire to bind
128
- */
129
- bind(typeWire: AnyTypeWire): void | Promise<void> {
130
- const bound = this.container
131
- .bind(typeWire.type.symbol)
132
- .toDynamicValue((_ctx) => {
133
- return typeWire.creator(this);
134
- });
135
-
136
- const scope = adoptScope(typeWire.scope);
137
- if (scope) {
138
- switch (scope) {
139
- case "Singleton":
140
- this.singletons.add(typeWire.type.symbol);
141
- bound.inSingletonScope();
142
- break;
143
- case "Transient":
144
- bound.inTransientScope();
145
- break;
146
- case "Request":
147
- bound.inRequestScope();
148
- }
149
- }
150
- }
151
-
152
- /**
153
- * Removes a binding from the InversifyJS container.
154
- * Also removes any tracking information for the binding.
155
- *
156
- * @param typeSymbol - The type symbol identifying the binding to remove
157
- * @returns A promise that resolves when the unbinding is complete
158
- */
159
- async unbind(typeSymbol: AnyTypeSymbol): Promise<void> {
160
- this.loaded.delete(typeSymbol.symbol);
161
- this.singletons.delete(typeSymbol.symbol);
162
- return this.container.unbind(typeSymbol.symbol);
163
- }
164
-
165
- /**
166
- * Checks if a binding exists in the InversifyJS container.
167
- *
168
- * @param typeSymbol - The type symbol to check
169
- * @returns True if the binding exists, false otherwise
170
- */
171
- isBound(typeSymbol: AnyTypeSymbol): boolean {
172
- return this.container.isBound(typeSymbol.symbol);
173
- }
174
- }
175
-
176
- /**
177
- * Creates an adapter that provides both TypeWire ResolutionContext and BindingContext
178
- * interfaces using an InversifyJS container.
179
- *
180
- * This is a convenience function for creating an InversifyAdapter.
181
- *
182
- * @param container - The InversifyJS container to adapt
183
- * @returns An object implementing both TypeWire interfaces
184
- *
185
- * @example
186
- * ```typescript
187
- * const container = new Container();
188
- * const adapter = createInversifyAdapter(container);
189
- *
190
- * // Now you can use TypeWire with your InversifyJS container
191
- * await serviceWire.apply(adapter);
192
- * const service = await serviceWire.getInstance(adapter);
193
- * ```
194
- */
195
- export function createInversifyAdapter(
196
- container: Container,
197
- ): TypeWireResolutionContext & BindingContext {
198
- return new InversifyAdapter(container);
199
- }