@decaf-ts/injectable-decorators 1.9.10 → 1.9.12
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 +59 -189
- package/dist/injectable-decorators.cjs.map +1 -1
- package/dist/injectable-decorators.js +1 -1
- package/dist/injectable-decorators.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -5,6 +5,13 @@ A lightweight TypeScript dependency injection library that provides decorators f
|
|
|
5
5
|
|
|
6
6
|
> Release docs refreshed on 2025-11-26. See [workdocs/reports/RELEASE_NOTES.md](./workdocs/reports/RELEASE_NOTES.md) for ticket summaries.
|
|
7
7
|
|
|
8
|
+
### Core Concepts
|
|
9
|
+
|
|
10
|
+
* **`@injectable()`**: A class decorator that registers a class with the dependency injection system, making it available for injection.
|
|
11
|
+
* **`@inject()`**: A property decorator that injects a registered dependency into a class property.
|
|
12
|
+
* **`Injectables` Class**: A static class that acts as the central registry for managing injectable dependencies.
|
|
13
|
+
* **Singleton vs. On-Demand**: Injectables can be configured to be singletons (one instance shared across the application) or on-demand (a new instance created each time it's injected).
|
|
14
|
+
|
|
8
15
|

|
|
9
16
|

|
|
10
17
|

|
|
@@ -78,243 +85,106 @@ The library follows a minimalist approach, focusing on providing essential depen
|
|
|
78
85
|
Unlike more complex DI frameworks, this library doesn't require extensive configuration or setup. The developer is responsible for initially decorating classes and properties, but the library handles the instantiation and injection process automatically.
|
|
79
86
|
|
|
80
87
|
|
|
81
|
-
|
|
88
|
+
# How to Use
|
|
82
89
|
|
|
83
|
-
|
|
90
|
+
This guide provides examples of how to use the main features of the `@decaf-ts/injectable-decorators` library.
|
|
84
91
|
|
|
85
|
-
##
|
|
92
|
+
## Creating an Injectable Service
|
|
86
93
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Description: Define a class with @injectable() so it becomes available through the central registry. Creating with new returns the instance managed by the registry.
|
|
94
|
+
The `@injectable()` decorator marks a class as available for dependency injection.
|
|
90
95
|
|
|
91
96
|
```typescript
|
|
92
|
-
import '
|
|
93
|
-
import { injectable, Injectables } from 'injectable-decorators';
|
|
97
|
+
import { injectable } from '@decaf-ts/injectable-decorators';
|
|
94
98
|
|
|
95
99
|
@injectable()
|
|
96
|
-
class
|
|
97
|
-
|
|
100
|
+
class MyService {
|
|
101
|
+
greet() {
|
|
102
|
+
return 'Hello from MyService!';
|
|
103
|
+
}
|
|
98
104
|
}
|
|
99
|
-
|
|
100
|
-
const obj = new InitialObject();
|
|
101
|
-
const same = Injectables.get(InitialObject);
|
|
102
|
-
// obj and same refer to the same instance (singleton by default)
|
|
103
105
|
```
|
|
104
106
|
|
|
105
|
-
|
|
107
|
+
## Injecting a Service
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
The `@inject()` decorator injects a registered dependency into a class property.
|
|
108
110
|
|
|
109
111
|
```typescript
|
|
110
|
-
import '
|
|
111
|
-
import {
|
|
112
|
+
import { inject } from '@decaf-ts/injectable-decorators';
|
|
113
|
+
import { MyService } from './MyService';
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
class SomeService { value = 5; }
|
|
115
|
-
|
|
116
|
-
class Controller {
|
|
115
|
+
class MyComponent {
|
|
117
116
|
@inject()
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const c = new Controller();
|
|
122
|
-
console.log(c.service.value); // 5
|
|
123
|
-
console.log(c.service === Injectables.get(SomeService)); // true
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### 3) Use a custom category (string) for minification or upcasting
|
|
127
|
-
|
|
128
|
-
Description: Provide a stable name when class names may change (e.g., minification) or to upcast through a base type.
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
import 'reflect-metadata';
|
|
132
|
-
import { injectable, inject, singleton } from 'injectable-decorators';
|
|
133
|
-
|
|
134
|
-
@singleton()
|
|
135
|
-
class AAA { a = 'aaa'; }
|
|
136
|
-
|
|
137
|
-
@injectable('AAA')
|
|
138
|
-
class BBB extends AAA { b = 'bbb'; }
|
|
117
|
+
private myService!: MyService;
|
|
139
118
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
@inject()
|
|
144
|
-
repo!: AAA; // resolves to the instance registered under category 'AAA'
|
|
119
|
+
doSomething() {
|
|
120
|
+
console.log(this.myService.greet());
|
|
121
|
+
}
|
|
145
122
|
}
|
|
146
123
|
|
|
147
|
-
const
|
|
148
|
-
|
|
124
|
+
const component = new MyComponent();
|
|
125
|
+
component.doSomething(); // Outputs: "Hello from MyService!"
|
|
149
126
|
```
|
|
150
127
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
Description: When a different string category was used at registration, pass that string to @inject.
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
import 'reflect-metadata';
|
|
157
|
-
import { inject, singleton } from 'injectable-decorators';
|
|
158
|
-
|
|
159
|
-
class DDD { a = 'aaa'; }
|
|
128
|
+
## Singleton vs. On-Demand
|
|
160
129
|
|
|
161
|
-
|
|
162
|
-
class CCC extends DDD { b = 'bbb'; }
|
|
130
|
+
By default, injectables are singletons. You can change this behavior using the `@onDemand` decorator or by passing a configuration object to `@injectable`.
|
|
163
131
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
class Holder {
|
|
167
|
-
@inject('EEE')
|
|
168
|
-
repo!: CCC;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const h = new Holder();
|
|
172
|
-
console.log(h.repo === instance); // true
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### 5) Map one constructor to another and inject by constructor
|
|
176
|
-
|
|
177
|
-
Description: You can register an injectable using another constructor as the category, then inject it by that constructor.
|
|
132
|
+
### Singleton (Default)
|
|
178
133
|
|
|
179
134
|
```typescript
|
|
180
|
-
import '
|
|
181
|
-
import { injectable, inject } from 'injectable-decorators';
|
|
135
|
+
import { injectable } from '@decaf-ts/injectable-decorators';
|
|
182
136
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
137
|
+
@injectable() // or @singleton()
|
|
138
|
+
class MySingletonService {
|
|
139
|
+
constructor() {
|
|
140
|
+
console.log('MySingletonService instance created');
|
|
141
|
+
}
|
|
188
142
|
}
|
|
189
143
|
|
|
190
|
-
|
|
191
|
-
@inject(Token)
|
|
192
|
-
object!: Impl; // injects the instance registered under Token (Impl instance)
|
|
193
|
-
}
|
|
144
|
+
// ...
|
|
194
145
|
|
|
195
|
-
const
|
|
196
|
-
|
|
146
|
+
const component1 = new MyComponent(); // MySingletonService instance created
|
|
147
|
+
const component2 = new MyComponent(); // No new instance created
|
|
197
148
|
```
|
|
198
149
|
|
|
199
|
-
###
|
|
200
|
-
|
|
201
|
-
Description: Use @onDemand() so each injection produces a fresh instance. You can pass args for construction via @inject({ args }).
|
|
150
|
+
### On-Demand
|
|
202
151
|
|
|
203
152
|
```typescript
|
|
204
|
-
import '
|
|
205
|
-
import { onDemand, inject } from 'injectable-decorators';
|
|
153
|
+
import { onDemand } from '@decaf-ts/injectable-decorators';
|
|
206
154
|
|
|
207
155
|
@onDemand()
|
|
208
|
-
class
|
|
209
|
-
constructor(
|
|
156
|
+
class MyOnDemandService {
|
|
157
|
+
constructor() {
|
|
158
|
+
console.log('MyOnDemandService instance created');
|
|
159
|
+
}
|
|
210
160
|
}
|
|
211
161
|
|
|
212
|
-
|
|
213
|
-
@inject()
|
|
214
|
-
fresh!: FreshObject; // new instance per parent
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
class ParentB {
|
|
218
|
-
@inject({ args: ['x', 'y'] })
|
|
219
|
-
fresh!: FreshObject; // passes constructor args to on-demand instance
|
|
220
|
-
}
|
|
162
|
+
// ...
|
|
221
163
|
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
console.log(p1.fresh !== p2.fresh); // true
|
|
225
|
-
|
|
226
|
-
const p3 = new ParentB();
|
|
227
|
-
console.log([p3.fresh.a, p3.fresh.b]); // ['x','y']
|
|
164
|
+
const component1 = new MyComponent(); // MyOnDemandService instance created
|
|
165
|
+
const component2 = new MyComponent(); // MyOnDemandService instance created
|
|
228
166
|
```
|
|
229
167
|
|
|
230
|
-
|
|
168
|
+
## Injecting with a Category
|
|
231
169
|
|
|
232
|
-
|
|
170
|
+
You can register and inject dependencies using a string or symbol as a category, which is useful for avoiding issues with minification or for upcasting.
|
|
233
171
|
|
|
234
172
|
```typescript
|
|
235
|
-
import '
|
|
236
|
-
import { injectable, inject } from 'injectable-decorators';
|
|
173
|
+
import { injectable, inject } from '@decaf-ts/injectable-decorators';
|
|
237
174
|
|
|
238
|
-
|
|
239
|
-
class SomeOtherObject { value() { return 10; } }
|
|
175
|
+
const IMyService = 'IMyService';
|
|
240
176
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
177
|
+
@injectable(IMyService)
|
|
178
|
+
class MyServiceImpl {
|
|
179
|
+
// ...
|
|
244
180
|
}
|
|
245
181
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
### 8) Registry operations: reset and swapping registry
|
|
251
|
-
|
|
252
|
-
Description: Reset clears all registrations. Swapping the registry replaces the storage, losing previous entries.
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
import { Injectables, InjectableRegistryImp } from 'injectable-decorators';
|
|
256
|
-
|
|
257
|
-
// ensure something is registered
|
|
258
|
-
Injectables.get('SomeOtherObject');
|
|
259
|
-
|
|
260
|
-
// swap to a fresh registry
|
|
261
|
-
Injectables.setRegistry(new InjectableRegistryImp());
|
|
262
|
-
console.log(Injectables.get('SomeOtherObject')); // undefined
|
|
263
|
-
|
|
264
|
-
// reset to a new empty default registry
|
|
265
|
-
Injectables.reset();
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### 9) Singleton vs onDemand convenience decorators
|
|
269
|
-
|
|
270
|
-
Description: Prefer @singleton() to force single instance, or @onDemand() for new instance per retrieval.
|
|
271
|
-
|
|
272
|
-
```typescript
|
|
273
|
-
import { singleton, onDemand } from 'injectable-decorators';
|
|
274
|
-
|
|
275
|
-
@singleton()
|
|
276
|
-
class OneOnly {}
|
|
277
|
-
|
|
278
|
-
@onDemand()
|
|
279
|
-
class Many {}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### 10) Utility helpers and constants
|
|
283
|
-
|
|
284
|
-
Description: Generate reflection keys and understand default config.
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
import { getInjectKey } from 'injectable-decorators';
|
|
288
|
-
|
|
289
|
-
console.log(getInjectKey('injectable')); // "inject.db.injectable"
|
|
290
|
-
console.log(getInjectKey('inject')); // "inject.db.inject"
|
|
182
|
+
class MyOtherComponent {
|
|
183
|
+
@inject(IMyService)
|
|
184
|
+
private myService!: MyServiceImpl;
|
|
185
|
+
}
|
|
291
186
|
```
|
|
292
187
|
|
|
293
|
-
Notes:
|
|
294
|
-
- Always include `import 'reflect-metadata'` once in your app before using decorators.
|
|
295
|
-
- VERSION is exported as a string placeholder defined at build time.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
## Coding Principles
|
|
299
|
-
|
|
300
|
-
- group similar functionality in folders (analog to namespaces but without any namespace declaration)
|
|
301
|
-
- one class per file;
|
|
302
|
-
- one interface per file (unless interface is just used as a type);
|
|
303
|
-
- group types as other interfaces in a types.ts file per folder;
|
|
304
|
-
- group constants or enums in a constants.ts file per folder;
|
|
305
|
-
- group decorators in a decorators.ts file per folder;
|
|
306
|
-
- always import from the specific file, never from a folder or index file (exceptions for dependencies on other packages);
|
|
307
|
-
- prefer the usage of established design patters where applicable:
|
|
308
|
-
- Singleton (can be an anti-pattern. use with care);
|
|
309
|
-
- factory;
|
|
310
|
-
- observer;
|
|
311
|
-
- strategy;
|
|
312
|
-
- builder;
|
|
313
|
-
- etc;
|
|
314
|
-
|
|
315
|
-
## Release Documentation Hooks
|
|
316
|
-
Stay aligned with the automated release pipeline by reviewing [Release Notes](./workdocs/reports/RELEASE_NOTES.md) and [Dependencies](./workdocs/reports/DEPENDENCIES.md) after trying these recipes (updated on 2025-11-26).
|
|
317
|
-
|
|
318
188
|
|
|
319
189
|
### Related
|
|
320
190
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable-decorators.cjs","sources":["../src/constants.ts","../src/utils.ts","../src/registry.ts","../src/Injectables.ts","../src/decorators.ts","../src/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["InjectablesKeys","REFLECT","INJECTABLE","INJECT","DefaultInjectablesConfig","singleton","getInjectKey","key","InjectableRegistryImp","constructor","this","cache","has","name","Symbol","for","toString","get","args","meta","Reflect","getMetadata","symbol","Error","options","instance","build","register","obj","category","force","castObj","undefined","e","callback","Injectables","actingInjectablesRegistry","getRegistry","setRegistry","operationsRegistry","reset","selectiveReset","match","regexp","RegExp","Object","entries","reduce","accum","val","injectableBaseDecorator","cfg","assign","original","class","defineMetadata","newConstructor","prototype","defineProperty","writable","enumerable","configurable","value","metadata","ModelKeys","CONSTRUCTOR","injectable","Decoration","define","decorator","apply","injectBaseDecorator","target","propertyKey","config","prop","definitionTarget","lookupConstructor","Metadata","type","String","values","WeakMap","transformer","set","delete","VERSION","PACKAGE_NAME","registerLibrary"],"mappings":"
|
|
1
|
+
{"version":3,"file":"injectable-decorators.cjs","sources":["../src/constants.ts","../src/utils.ts","../src/registry.ts","../src/Injectables.ts","../src/decorators.ts","../src/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["InjectablesKeys","REFLECT","INJECTABLE","INJECT","DefaultInjectablesConfig","singleton","getInjectKey","key","InjectableRegistryImp","constructor","this","cache","has","name","Symbol","for","toString","get","args","meta","Reflect","getMetadata","symbol","Error","options","instance","build","register","obj","category","force","castObj","undefined","e","callback","Injectables","actingInjectablesRegistry","getRegistry","setRegistry","operationsRegistry","reset","selectiveReset","match","regexp","RegExp","Object","entries","reduce","accum","val","injectableBaseDecorator","cfg","assign","original","class","defineMetadata","newConstructor","prototype","defineProperty","writable","enumerable","configurable","value","metadata","ModelKeys","CONSTRUCTOR","injectable","Decoration","define","decorator","apply","injectBaseDecorator","target","propertyKey","config","prop","definitionTarget","lookupConstructor","Metadata","type","String","values","WeakMap","transformer","set","delete","VERSION","PACKAGE_NAME","registerLibrary"],"mappings":"8CAWO,MAAMA,EAAkB,CAC7BC,QAAS,aACTC,WAAY,aACZC,OAAQ,UASGC,EAA6C,CACxDC,WAAW,GCdAC,EAAgBC,GAAgBP,EAAgBC,QAAUM,QCgG1DC,EAAb,WAAAC,GACUC,KAAAC,MAAuC,CAAA,CA6EjD,CA3EE,GAAAC,CAAOC,GACL,MAAoB,iBAATA,EAA0BA,KAAQH,KAAKC,MAC3CG,OAAOC,IAAIF,EAAKG,cAAeN,KAAKC,KAC7C,CAKA,GAAAM,CACEJ,KACGK,GAGH,GADoB,iBAATL,IAAmBA,EAAOC,OAAOC,IAAIF,IAC5B,iBAATA,EAAmB,CAC5B,MAAMM,EAAOC,QAAQC,YACnBf,EAAaN,EAAgBE,YAC7BW,GAEFA,EAAQM,GAAMG,QAAqBR,OAAOC,IAAIF,EAAKG,WACrD,CACA,IAAKH,EAAM,MAAUU,MAAM,cAAcV,eAEzC,KAAOA,KAAmBH,KAAKC,OAC7B,OAEF,MAAMA,EAAQD,KAAKC,MAAME,GACzB,OAAKF,EAAMa,QAAQnB,WAAcM,EAAMc,WAEhCd,EAAMc,UADJf,KAAKgB,MAASb,KAASK,EAElC,CAIA,QAAAS,CACEC,EACAC,EACAL,EACAM,GAAiB,GAEjB,MAAMC,EAA+BH,EAE/BnB,GAAesB,EAAQlB,MAAQkB,EAAQtB,YAC7C,GAAuB,mBAAZsB,IAA2BtB,EACpC,MAAUc,MACR,oEAGJ,MAAMV,EAAOgB,GAAYf,OAAOC,IAAKa,EAAYZ,YAE5CN,KAAKC,MAAME,KAASiB,IACvBpB,KAAKC,MAAME,GAAQ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hE,MAAQ,aAIpGO,QAAQmC,eACNjD,EAAaN,EAAgBG,QAC7B,CACE+D,WAAYrD,GAEd2D,EACAC,GAGF,MAAMQ,EAAS,IAAIC,QAEnBrC,OAAOa,eAAekB,EAAkBH,EAAa,CACnDZ,cAAc,EACdD,YAAY,EACZ,GAAA3C,GACE,IAAKgE,EAAOrE,IAAIF,MAAO,CACrB,IAAIkB,EAAMO,EAAYlB,IAAIJ,KAAiB6D,EAAOxD,MAAQ,IAC1D,IAAKU,EACH,MAAUL,MACR,4BAA6BV,EAAaG,2BAA2BN,KAAKD,YAAcC,KAAKD,YAAYI,KAAO2D,EAAO3D,UAAU4D,KAGrI,GAAIC,EAAOS,YACT,IACEvD,EAAM8C,EAAOS,YAAYvD,EAAKlB,KAChC,CAAE,MAAOuB,GAET,CAEFgD,EAAOG,IAAI1E,KAAMkB,EACnB,CAEA,OAAOqD,EAAOhE,IAAIP,KACpB,EACA,GAAA0E,CAAetB,QACQ,IAAVA,EAIXmB,EAAOG,IAAI1E,KAAMoD,GAHfmB,EAAOI,OAAO3E,KAIlB,GAEJ,CACF,CC9SO,MAAM4E,EAAU,cACVC,EAAe,cAC5BT,EAAAA,SAASU,gBAAgBD,EAAcD,yHLOhB,oDIuZjB,CACJzD,EACAsB,IAEOgB,EAAAA,WAAWpD,IAAIf,EAAgBG,QACnCiE,OAAO,CAAEC,UAAWE,EAAqBrD,KAAM,CAACW,EAAUsB,KAC1DmB,sFApOC,CACJzC,EACAsB,IAEOe,EACLrC,EACAgB,OAAOO,OAAO,CAAA,EAAID,GAAO,GAAI,CAAE9C,WAAW,iBAzBxC,CACJwB,EACAsB,IAEOe,EACLrC,EACAgB,OAAOO,OAAO,CAAA,EAAID,GAAO,GAAI,CAAE9C,WAAW"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Decoration as t,prop as e,Metadata as n,metadata as r}from"@decaf-ts/decoration";import{ModelKeys as o}from"@decaf-ts/decorator-validation";const i={REFLECT:"inject.db.",INJECTABLE:"injectable",INJECT:"inject"},c={singleton:!0},s="design:type",a=t=>i.REFLECT+t;class g{constructor(){this.cache={}}has(t){return"symbol"==typeof t?t in this.cache:Symbol.for(t.toString())in this.cache}get(t,...e){if("string"==typeof t&&(t=Symbol.for(t)),"symbol"!=typeof t){const e=Reflect.getMetadata(a("injectable"),t);t=e?.symbol||Symbol.for(t.toString())}if(!t)throw Error(`Injectable ${t} not found`);if(!(t in this.cache))return;const n=this.cache[t];return(n.options.singleton||n.instance)&&n.instance||this.build(t,...e)}register(t,e,n,r=!1){const o=t,i=!o.name&&o.constructor;if("function"!=typeof o&&!i)throw Error("Injectable registering failed. Missing Class name or constructor");const c=e||Symbol.for(t.toString());this.cache[c]&&!r||(this.cache[c]={instance:n.singleton&&i?t:void 0,constructor:i?t.constructor:t,options:n})}build(t,...e){const{constructor:n,options:r}=this.cache[t];let o;try{o=new n(...e)}catch(n){throw Error(`failed to build ${t.toString()} with args ${e}: ${n}`)}return r.singleton&&(this.cache[t].instance=o),r.callback&&(o=r.callback(o,...e)),o}}class l{static{this.actingInjectablesRegistry=void 0}constructor(){}static get(t,...e){return l.getRegistry().get(t,...e)}static register(t,...e){return l.getRegistry().register(t,...e)}static build(t,...e){return l.getRegistry().build(t,...e)}static setRegistry(t){l.actingInjectablesRegistry=t}static getRegistry(){return l.actingInjectablesRegistry||(l.actingInjectablesRegistry=new g),l.actingInjectablesRegistry}static reset(){l.setRegistry(new g)}static selectiveReset(t){const e="string"==typeof t?RegExp(t):t;l.actingInjectablesRegistry.cache=Object.entries(l.actingInjectablesRegistry.cache).reduce((t,[n,r])=>(n.match(e)||(t[n]=r),t),{})}}function f(t,e){return e=e||("object"==typeof t?Object.assign(t,c):c),t="object"==typeof t?void 0:"string"==typeof t||"function"==typeof t&&t.name?t:void 0,n=>{const i=Symbol.for(t||n.toString()),c={class:t=t||n.name,symbol:i};Reflect.defineMetadata(a("injectable"),c,n);const s=(...t)=>l.get(i,...t);return s.prototype=n.prototype,Object.defineProperty(s,"name",{writable:!1,enumerable:!0,configurable:!1,value:n.prototype.constructor.name}),Reflect.defineMetadata(a("injectable"),c,s),r(o.CONSTRUCTOR,n)(s),l.register(n,i,e),s}}function u(e,n){return t.for("injectable").define({decorator:f,args:[e,n]}).apply()}function b(t,e){return u(t,Object.assign({},e||{},{singleton:!0}))}function y(t,e){return u(t,Object.assign({},e||{},{singleton:!1}))}function h(t,r){return function(o,i){const c=r||"object"==typeof t?t:{};i&&e()(o,i);const s="function"==typeof o?o.prototype:o,g="function"==typeof o?o:o.constructor,f="object"!=typeof t&&t||n.type(g,i);if(!f)throw Error(`Could not determine injectable type for ${i+""} on ${g?.name||"unknown"}`);Reflect.defineMetadata(a("inject"),{injectable:f},o,i);const u=new WeakMap;Object.defineProperty(s,i,{configurable:!0,enumerable:!0,get(){if(!u.has(this)){let t=l.get(f,...c.args||[]);if(!t)throw Error(`Could not get Injectable ${f.toString()} to inject in ${this.constructor?this.constructor.name:o.name}'s ${i}`);if(c.transformer)try{t=c.transformer(t,this)}catch(t){}u.set(this,t)}return u.get(this)},set(t){void 0!==t?u.set(this,t):u.delete(this)}})}}function d(e,n){return t.for("inject").define({decorator:h,args:[e,n]}).apply()}const p="##VERSION##",j="##PACKAGE##";n.registerLibrary(j,p);export{c as DefaultInjectablesConfig,g as InjectableRegistryImp,l as Injectables,i as InjectablesKeys,j as PACKAGE_NAME,s as TypeKey,p as VERSION,a as getInjectKey,d as inject,h as injectBaseDecorator,u as injectable,f as injectableBaseDecorator,y as onDemand,b as singleton};
|
|
2
2
|
//# sourceMappingURL=injectable-decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable-decorators.js","sources":["../src/constants.ts","../src/utils.ts","../src/registry.ts","../src/Injectables.ts","../src/decorators.ts","../src/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["InjectablesKeys","REFLECT","INJECTABLE","INJECT","DefaultInjectablesConfig","singleton","TypeKey","getInjectKey","key","InjectableRegistryImp","constructor","this","cache","has","name","Symbol","for","toString","get","args","meta","Reflect","getMetadata","symbol","Error","options","instance","build","register","obj","category","force","castObj","undefined","e","callback","Injectables","actingInjectablesRegistry","getRegistry","setRegistry","operationsRegistry","reset","selectiveReset","match","regexp","RegExp","Object","entries","reduce","accum","val","injectableBaseDecorator","cfg","assign","original","class","defineMetadata","newConstructor","prototype","defineProperty","writable","enumerable","configurable","value","metadata","ModelKeys","CONSTRUCTOR","injectable","Decoration","define","decorator","apply","onDemand","injectBaseDecorator","target","propertyKey","config","prop","definitionTarget","lookupConstructor","Metadata","type","String","values","WeakMap","transformer","set","delete","inject","VERSION","PACKAGE_NAME","registerLibrary"],"mappings":"
|
|
1
|
+
{"version":3,"file":"injectable-decorators.js","sources":["../src/constants.ts","../src/utils.ts","../src/registry.ts","../src/Injectables.ts","../src/decorators.ts","../src/index.ts"],"sourcesContent":[null,null,null,null,null,null],"names":["InjectablesKeys","REFLECT","INJECTABLE","INJECT","DefaultInjectablesConfig","singleton","TypeKey","getInjectKey","key","InjectableRegistryImp","constructor","this","cache","has","name","Symbol","for","toString","get","args","meta","Reflect","getMetadata","symbol","Error","options","instance","build","register","obj","category","force","castObj","undefined","e","callback","Injectables","actingInjectablesRegistry","getRegistry","setRegistry","operationsRegistry","reset","selectiveReset","match","regexp","RegExp","Object","entries","reduce","accum","val","injectableBaseDecorator","cfg","assign","original","class","defineMetadata","newConstructor","prototype","defineProperty","writable","enumerable","configurable","value","metadata","ModelKeys","CONSTRUCTOR","injectable","Decoration","define","decorator","apply","onDemand","injectBaseDecorator","target","propertyKey","config","prop","definitionTarget","lookupConstructor","Metadata","type","String","values","WeakMap","transformer","set","delete","inject","VERSION","PACKAGE_NAME","registerLibrary"],"mappings":"mJAWO,MAAMA,EAAkB,CAC7BC,QAAS,aACTC,WAAY,aACZC,OAAQ,UASGC,EAA6C,CACxDC,WAAW,GASAC,EAAU,cCvBVC,EAAgBC,GAAgBR,EAAgBC,QAAUO,QCgG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AAO,CACrB,IAAIkB,EAAMO,EAAYlB,IAAIJ,KAAiB8D,EAAOzD,MAAQ,IAC1D,IAAKU,EACH,MAAUL,MACR,4BAA6BV,EAAaG,2BAA2BN,KAAKD,YAAcC,KAAKD,YAAYI,KAAO4D,EAAO5D,UAAU6D,KAGrI,GAAIC,EAAOS,YACT,IACExD,EAAM+C,EAAOS,YAAYxD,EAAKlB,KAChC,CAAE,MAAOuB,GAET,CAEFiD,EAAOG,IAAI3E,KAAMkB,EACnB,CAEA,OAAOsD,EAAOjE,IAAIP,KACpB,EACA,GAAA2E,CAAevB,QACQ,IAAVA,EAIXoB,EAAOG,IAAI3E,KAAMoD,GAHfoB,EAAOI,OAAO5E,KAIlB,GAEJ,CACF,CAkHM,SAAU6E,EACd1D,EACAsB,GAEA,OAAOgB,EAAWpD,IAAIhB,UACnBqE,OAAO,CAAEC,UAAWG,EAAqBtD,KAAM,CAACW,EAAUsB,KAC1DmB,OACL,CCvaO,MAAMkB,EAAU,cACVC,EAAe,cAC5BV,EAASW,gBAAgBD,EAAcD"}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export * from "./utils.js";
|
|
|
19
19
|
* @const VERSION
|
|
20
20
|
* @memberOf module:injectable-decorators
|
|
21
21
|
*/
|
|
22
|
-
export const VERSION = "1.9.
|
|
22
|
+
export const VERSION = "1.9.11";
|
|
23
23
|
export const PACKAGE_NAME = "@decaf-ts/injectable-decorators";
|
|
24
24
|
Metadata.registerLibrary(PACKAGE_NAME, VERSION);
|
|
25
25
|
//# sourceMappingURL=index.js.map
|
package/lib/index.cjs
CHANGED
|
@@ -36,7 +36,7 @@ __exportStar(require("./utils.cjs"), exports);
|
|
|
36
36
|
* @const VERSION
|
|
37
37
|
* @memberOf module:injectable-decorators
|
|
38
38
|
*/
|
|
39
|
-
exports.VERSION = "1.9.
|
|
39
|
+
exports.VERSION = "1.9.11";
|
|
40
40
|
exports.PACKAGE_NAME = "@decaf-ts/injectable-decorators";
|
|
41
41
|
decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
|
|
42
42
|
//# sourceMappingURL=index.js.map
|
package/lib/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decaf-ts/injectable-decorators",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.12",
|
|
4
4
|
"description": "injectable decorators extension for decorator validation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"build": "npx build-scripts --dev",
|
|
20
20
|
"build:prod": "npx build-scripts --prod",
|
|
21
21
|
"test": "jest --runInBand --coverage --detectOpenHandles",
|
|
22
|
-
"test:unit": "jest --
|
|
23
|
-
"test:integration": "jest --
|
|
24
|
-
"test:all": "jest --
|
|
22
|
+
"test:unit": "jest --testPathPatterns=\"/tests/unit\" --passWithNoTests --detectOpenHandles",
|
|
23
|
+
"test:integration": "jest --testPathPatterns=\"/tests/(integration)\" --passWithNoTests --detectOpenHandles",
|
|
24
|
+
"test:all": "jest --testPathPatterns=\"/tests\" --passWithNoTests --detectOpenHandles",
|
|
25
25
|
"test:circular": "dpdm -T --no-warning --no-tree ./src/index.ts",
|
|
26
|
-
"coverage": "rimraf ./workdocs/reports/data/*.json && npm run test:all -- --coverage --config=./workdocs/reports/jest.coverage.config.
|
|
26
|
+
"coverage": "rimraf ./workdocs/reports/data/*.json && npm run test:all -- --coverage --config=./workdocs/reports/jest.coverage.config.cjs",
|
|
27
27
|
"lint": "eslint .",
|
|
28
28
|
"lint-fix": "eslint --fix .",
|
|
29
29
|
"prepare-pr": "npm run lint-fix && npm run build:prod && npm run coverage && npm run docs",
|
|
@@ -75,9 +75,14 @@
|
|
|
75
75
|
"homepage": "https://github.com/decaf-ts/injectable-decorators#readme",
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@decaf-ts/decorator-validation": "latest",
|
|
78
|
-
"@decaf-ts/utils": "latest"
|
|
78
|
+
"@decaf-ts/utils": "latest",
|
|
79
|
+
"@types/jest": "^30.0.0"
|
|
79
80
|
},
|
|
80
81
|
"dependencies": {
|
|
81
82
|
"@decaf-ts/decoration": "latest"
|
|
83
|
+
},
|
|
84
|
+
"overrides": {
|
|
85
|
+
"minimatch": "^10.2.2",
|
|
86
|
+
"test-exclude": "7.0.1"
|
|
82
87
|
}
|
|
83
88
|
}
|