@decaf-ts/injectable-decorators 1.11.0 → 1.13.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/lib/cjs/Injectables.cjs +4 -3
- package/lib/cjs/Injectables.cjs.map +1 -0
- package/lib/cjs/Metadata.cjs +1 -0
- package/lib/cjs/Metadata.cjs.map +1 -0
- package/lib/cjs/constants.cjs +1 -0
- package/lib/cjs/constants.cjs.map +1 -0
- package/lib/cjs/decorators.cjs +14 -13
- package/lib/cjs/decorators.cjs.map +1 -0
- package/lib/cjs/index.cjs +10 -9
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/overrides.cjs +4 -3
- package/lib/cjs/overrides.cjs.map +1 -0
- package/lib/cjs/registry.cjs +4 -3
- package/lib/cjs/registry.cjs.map +1 -0
- package/lib/cjs/types.cjs +1 -0
- package/lib/cjs/types.cjs.map +1 -0
- package/lib/cjs/utils.cjs +3 -2
- package/lib/cjs/utils.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/Injectables.d.cts +108 -0
- package/lib/types/Injectables.d.mts +108 -0
- package/lib/types/Metadata.d.cts +8 -0
- package/lib/types/Metadata.d.mts +8 -0
- package/lib/types/constants.d.cts +29 -0
- package/lib/types/constants.d.mts +29 -0
- package/lib/types/decorators.d.cts +157 -0
- package/lib/types/decorators.d.mts +157 -0
- package/lib/types/index.d.cts +22 -0
- package/lib/types/index.d.mts +22 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/overrides.d.cts +1 -0
- package/lib/types/overrides.d.mts +1 -0
- package/lib/types/registry.d.cts +115 -0
- package/lib/types/registry.d.mts +115 -0
- package/lib/types/types.d.cts +53 -0
- package/lib/types/types.d.mts +53 -0
- package/lib/types/utils.d.cts +9 -0
- package/lib/types/utils.d.mts +9 -0
- package/package.json +1 -1
- package/lib/cjs/Injectables.js.map +0 -1
- package/lib/cjs/Metadata.js.map +0 -1
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/decorators.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/overrides.js.map +0 -1
- package/lib/cjs/registry.js.map +0 -1
- package/lib/cjs/types.js.map +0 -1
- package/lib/cjs/utils.js.map +0 -1
package/lib/cjs/Injectables.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Injectables = void 0;
|
|
4
|
-
const
|
|
4
|
+
const registry_js_1 = require("./registry.cjs");
|
|
5
5
|
/**
|
|
6
6
|
* @description Central registry for managing injectable dependencies.
|
|
7
7
|
* @summary Static class holding the access to the injectables functions. Provides methods for registering,
|
|
@@ -102,7 +102,7 @@ class Injectables {
|
|
|
102
102
|
*/
|
|
103
103
|
static getRegistry() {
|
|
104
104
|
if (!Injectables.actingInjectablesRegistry)
|
|
105
|
-
Injectables.actingInjectablesRegistry = new
|
|
105
|
+
Injectables.actingInjectablesRegistry = new registry_js_1.InjectableRegistryImp();
|
|
106
106
|
return Injectables.actingInjectablesRegistry;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
@@ -111,7 +111,7 @@ class Injectables {
|
|
|
111
111
|
* @return {void}
|
|
112
112
|
*/
|
|
113
113
|
static reset() {
|
|
114
|
-
Injectables.setRegistry(new
|
|
114
|
+
Injectables.setRegistry(new registry_js_1.InjectableRegistryImp());
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* @description Removes specific injectables from the registry based on a pattern.
|
|
@@ -129,4 +129,5 @@ class Injectables {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
exports.Injectables = Injectables;
|
|
132
|
+
//# sourceMappingURL=Injectables.js.map
|
|
132
133
|
//# sourceMappingURL=Injectables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Injectables.js","sourceRoot":"","sources":["Injectables.js"],"names":[],"mappings":";;;AAAA,+CAAuD;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,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACrE,WAAW,CAAC,yBAAyB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;YACzI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC;gBAClB,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;CACJ;AAnFD,kCAmFC;AACD,uCAAuC"}
|
package/lib/cjs/Metadata.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metadata.js","sourceRoot":"","sources":["Metadata.js"],"names":[],"mappings":";;AACA,oCAAoC"}
|
package/lib/cjs/constants.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["constants.js"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACU,QAAA,eAAe,GAAG;IAC3B,OAAO,EAAE,YAAY;IACrB,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,QAAQ;CACnB,CAAC;AACF;;;;;GAKG;AACU,QAAA,wBAAwB,GAAG;IACpC,SAAS,EAAE,IAAI;CAClB,CAAC;AACF;;;;;GAKG;AACU,QAAA,OAAO,GAAG,aAAa,CAAC;AACrC,qCAAqC"}
|
package/lib/cjs/decorators.cjs
CHANGED
|
@@ -6,17 +6,17 @@ exports.singleton = singleton;
|
|
|
6
6
|
exports.onDemand = onDemand;
|
|
7
7
|
exports.injectBaseDecorator = injectBaseDecorator;
|
|
8
8
|
exports.inject = inject;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const constants_js_1 = require("./constants.cjs");
|
|
10
|
+
const Injectables_js_1 = require("./Injectables.cjs");
|
|
11
|
+
const utils_js_1 = require("./utils.cjs");
|
|
12
12
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
13
13
|
const decorator_validation_1 = require("@decaf-ts/decorator-validation");
|
|
14
14
|
function injectableBaseDecorator(category, cfg) {
|
|
15
15
|
cfg =
|
|
16
16
|
cfg ||
|
|
17
17
|
(typeof category === "object"
|
|
18
|
-
? Object.assign(category,
|
|
19
|
-
:
|
|
18
|
+
? Object.assign(category, constants_js_1.DefaultInjectablesConfig)
|
|
19
|
+
: constants_js_1.DefaultInjectablesConfig);
|
|
20
20
|
category =
|
|
21
21
|
typeof category === "object"
|
|
22
22
|
? undefined
|
|
@@ -32,10 +32,10 @@ function injectableBaseDecorator(category, cfg) {
|
|
|
32
32
|
class: category,
|
|
33
33
|
symbol: symbol,
|
|
34
34
|
};
|
|
35
|
-
Reflect.defineMetadata((0,
|
|
35
|
+
Reflect.defineMetadata((0, utils_js_1.getInjectKey)(constants_js_1.InjectablesKeys.INJECTABLE), meta, original);
|
|
36
36
|
// the new constructor behaviour
|
|
37
37
|
const newConstructor = function (...args) {
|
|
38
|
-
return
|
|
38
|
+
return Injectables_js_1.Injectables.get(symbol, ...args);
|
|
39
39
|
};
|
|
40
40
|
// copy prototype so instanceof operator still works
|
|
41
41
|
newConstructor.prototype = original.prototype;
|
|
@@ -47,9 +47,9 @@ function injectableBaseDecorator(category, cfg) {
|
|
|
47
47
|
configurable: false,
|
|
48
48
|
value: original.prototype.constructor.name,
|
|
49
49
|
});
|
|
50
|
-
Reflect.defineMetadata((0,
|
|
50
|
+
Reflect.defineMetadata((0, utils_js_1.getInjectKey)(constants_js_1.InjectablesKeys.INJECTABLE), meta, newConstructor);
|
|
51
51
|
(0, decoration_1.metadata)(decorator_validation_1.ModelKeys.CONSTRUCTOR, original)(newConstructor);
|
|
52
|
-
|
|
52
|
+
Injectables_js_1.Injectables.register(original, symbol, cfg);
|
|
53
53
|
// return new constructor (will override original)
|
|
54
54
|
return newConstructor;
|
|
55
55
|
};
|
|
@@ -93,7 +93,7 @@ function injectableBaseDecorator(category, cfg) {
|
|
|
93
93
|
* Decorator-->>Client: Return instance
|
|
94
94
|
*/
|
|
95
95
|
function injectable(category, cfg) {
|
|
96
|
-
return decoration_1.Decoration.for(
|
|
96
|
+
return decoration_1.Decoration.for(constants_js_1.InjectablesKeys.INJECTABLE)
|
|
97
97
|
.define({ decorator: injectableBaseDecorator, args: [category, cfg] })
|
|
98
98
|
.apply();
|
|
99
99
|
}
|
|
@@ -135,7 +135,7 @@ function injectBaseDecorator(category, cfg) {
|
|
|
135
135
|
if (!name) {
|
|
136
136
|
throw new Error(`Could not determine injectable type for ${String(propertyKey)} on ${lookupConstructor?.name || "unknown"}`);
|
|
137
137
|
}
|
|
138
|
-
Reflect.defineMetadata((0,
|
|
138
|
+
Reflect.defineMetadata((0, utils_js_1.getInjectKey)(constants_js_1.InjectablesKeys.INJECT), {
|
|
139
139
|
injectable: name,
|
|
140
140
|
}, target, propertyKey);
|
|
141
141
|
const values = new WeakMap();
|
|
@@ -144,7 +144,7 @@ function injectBaseDecorator(category, cfg) {
|
|
|
144
144
|
enumerable: true,
|
|
145
145
|
get() {
|
|
146
146
|
if (!values.has(this)) {
|
|
147
|
-
let obj =
|
|
147
|
+
let obj = Injectables_js_1.Injectables.get(name, ...(config.args || []));
|
|
148
148
|
if (!obj) {
|
|
149
149
|
throw new Error(`Could not get Injectable ${name.toString()} to inject in ${this.constructor ? this.constructor.name : target.name}'s ${propertyKey}`);
|
|
150
150
|
}
|
|
@@ -230,8 +230,9 @@ function injectBaseDecorator(category, cfg) {
|
|
|
230
230
|
* end
|
|
231
231
|
*/
|
|
232
232
|
function inject(category, cfg) {
|
|
233
|
-
return decoration_1.Decoration.for(
|
|
233
|
+
return decoration_1.Decoration.for(constants_js_1.InjectablesKeys.INJECT)
|
|
234
234
|
.define({ decorator: injectBaseDecorator, args: [category, cfg] })
|
|
235
235
|
.apply();
|
|
236
236
|
}
|
|
237
|
+
//# sourceMappingURL=decorators.js.map
|
|
237
238
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.js"],"names":[],"mappings":";;AAKA,0DA0CC;AAuCD,gCAIC;AAUD,8BAEC;AAUD,4BAEC;AACD,kDAgDC;AA4DD,wBAIC;AAnOD,iDAA2E;AAC3E,qDAA+C;AAC/C,yCAA0C;AAC1C,qDAA6E;AAC7E,yEAA2D;AAC3D,SAAgB,uBAAuB,CAAC,QAAQ,EAAE,GAAG;IACjD,GAAG;QACC,GAAG;YACC,CAAC,OAAO,QAAQ,KAAK,QAAQ;gBACzB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,uCAAwB,CAAC;gBACnD,CAAC,CAAC,uCAAwB,CAAC,CAAC;IACxC,QAAQ;QACJ,OAAO,QAAQ,KAAK,QAAQ;YACxB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ;gBAC1B,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,IAAI;oBAC7C,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,SAAS,CAAC;IAC5B,OAAO,SAAS,wBAAwB,CAAC,QAAQ;QAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3D,QAAQ,GAAG,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC;QACrC,MAAM,IAAI,GAAG;YACT,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,MAAM;SACjB,CAAC;QACF,OAAO,CAAC,cAAc,CAAC,IAAA,uBAAY,EAAC,8BAAe,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;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O;gBACX,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5B,CAAC;SACJ,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,SAAgB,MAAM,CAAC,QAAQ,EAAE,GAAG;IAChC,OAAO,uBAAU,CAAC,GAAG,CAAC,8BAAe,CAAC,MAAM,CAAC;SACxC,MAAM,CAAC,EAAE,SAAS,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;SACjE,KAAK,EAAE,CAAC;AACjB,CAAC;AACD,sCAAsC"}
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @description A lightweight dependency injection library for TypeScript applications.
|
|
4
|
-
* @summary Adds a simple Injectables implementation to create singleton instances of an object
|
|
5
|
-
* and easily inject it into other objects. Provides decorators for marking classes as injectable
|
|
6
|
-
* and for injecting dependencies into class properties.
|
|
7
|
-
*
|
|
8
|
-
* @module injectable-decorators
|
|
9
|
-
*/
|
|
10
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
3
|
if (k2 === undefined) k2 = k;
|
|
12
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -23,6 +15,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
23
15
|
};
|
|
24
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
17
|
exports.PACKAGE_NAME = exports.VERSION = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* @description A lightweight dependency injection library for TypeScript applications.
|
|
20
|
+
* @summary Adds a simple Injectables implementation to create singleton instances of an object
|
|
21
|
+
* and easily inject it into other objects. Provides decorators for marking classes as injectable
|
|
22
|
+
* and for injecting dependencies into class properties.
|
|
23
|
+
*
|
|
24
|
+
* @module injectable-decorators
|
|
25
|
+
*/
|
|
26
26
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
27
27
|
__exportStar(require("./constants.cjs"), exports);
|
|
28
28
|
__exportStar(require("./decorators.cjs"), exports);
|
|
@@ -36,7 +36,8 @@ __exportStar(require("./utils.cjs"), exports);
|
|
|
36
36
|
* @const VERSION
|
|
37
37
|
* @memberOf module:injectable-decorators
|
|
38
38
|
*/
|
|
39
|
-
exports.VERSION = "1.
|
|
39
|
+
exports.VERSION = "1.12.0";
|
|
40
40
|
exports.PACKAGE_NAME = "@decaf-ts/injectable-decorators";
|
|
41
41
|
decoration_1.Metadata.registerLibrary(exports.PACKAGE_NAME, exports.VERSION);
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
42
43
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;GAOG;AACH,qDAAgD;AAChD,iDAA+B;AAC/B,kDAAgC;AAChC,mDAAiC;AACjC,gDAA8B;AAC9B,6CAA2B;AAC3B,6CAA2B;AAC3B;;;;;GAKG;AACU,QAAA,OAAO,GAAG,aAAa,CAAC;AACxB,QAAA,YAAY,GAAG,aAAa,CAAC;AAC1C,qBAAQ,CAAC,eAAe,CAAC,oBAAY,EAAE,eAAO,CAAC,CAAC;AAChD,iCAAiC"}
|
package/lib/cjs/overrides.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const decoration_1 = require("@decaf-ts/decoration");
|
|
4
|
-
const
|
|
4
|
+
const constants_js_1 = require("./constants.cjs");
|
|
5
5
|
decoration_1.Metadata.injectables = function (category) {
|
|
6
|
-
const meta = decoration_1.Metadata["innerGet"](Symbol.for(
|
|
6
|
+
const meta = decoration_1.Metadata["innerGet"](Symbol.for(constants_js_1.InjectablesKeys.INJECTABLE));
|
|
7
7
|
if (!meta)
|
|
8
8
|
return undefined;
|
|
9
9
|
if (!category)
|
|
@@ -21,7 +21,8 @@ decoration_1.Metadata.injectables = function (category) {
|
|
|
21
21
|
return meta[symbol];
|
|
22
22
|
};
|
|
23
23
|
decoration_1.Metadata.injected = function (model, prop) {
|
|
24
|
-
const meta = decoration_1.Metadata.get(model, `${
|
|
24
|
+
const meta = decoration_1.Metadata.get(model, `${constants_js_1.InjectablesKeys.INJECT}${prop ? `${decoration_1.Metadata.splitter}${prop.toString()}` : ""}`);
|
|
25
25
|
return meta;
|
|
26
26
|
};
|
|
27
|
+
//# sourceMappingURL=overrides.js.map
|
|
27
28
|
//# sourceMappingURL=overrides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overrides.js","sourceRoot":"","sources":["overrides.js"],"names":[],"mappings":";;AAAA,qDAAgD;AAChD,iDAAiD;AACjD,qBAAQ,CAAC,WAAW,GAAG,UAAU,QAAQ;IACrC,MAAM,IAAI,GAAG,qBAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,8BAAe,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC,IAAI;QACL,OAAO,SAAS,CAAC;IACrB,IAAI,CAAC,QAAQ;QACT,OAAO,IAAI,CAAC;IAChB,IAAI,MAAM,CAAC;IACX,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAC5B,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;;YAE9B,MAAM,GAAG,qBAAQ,CAAC,MAAM,CAAC,qBAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC;IACxE,CAAC;SACI,CAAC;QACF,MAAM,GAAG,QAAQ,CAAC;IACtB,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACxB,CAAC,CAAC;AACF,qBAAQ,CAAC,QAAQ,GAAG,UAAU,KAAK,EAAE,IAAI;IACrC,MAAM,IAAI,GAAG,qBAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,8BAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,qBAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AACF,qCAAqC"}
|
package/lib/cjs/registry.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InjectableRegistryImp = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const constants_js_1 = require("./constants.cjs");
|
|
5
|
+
const utils_js_1 = require("./utils.cjs");
|
|
6
6
|
/**
|
|
7
7
|
* @description Default implementation of the InjectablesRegistry interface.
|
|
8
8
|
* @summary Holds the various {@link Injectable}s in a cache and provides methods to register, retrieve, and build them.
|
|
@@ -61,7 +61,7 @@ class InjectableRegistryImp {
|
|
|
61
61
|
if (typeof name === "string")
|
|
62
62
|
name = Symbol.for(name);
|
|
63
63
|
if (typeof name !== "symbol") {
|
|
64
|
-
const meta = Reflect.getMetadata((0,
|
|
64
|
+
const meta = Reflect.getMetadata((0, utils_js_1.getInjectKey)(constants_js_1.InjectablesKeys.INJECTABLE), name);
|
|
65
65
|
name = meta?.symbol || Symbol.for(name.toString());
|
|
66
66
|
}
|
|
67
67
|
if (!name)
|
|
@@ -111,4 +111,5 @@ class InjectableRegistryImp {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
exports.InjectableRegistryImp = InjectableRegistryImp;
|
|
114
|
+
//# sourceMappingURL=registry.js.map
|
|
114
115
|
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["registry.js"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,yCAA0C;AAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAa,qBAAqB;IAC9B;QACI,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IACD,GAAG,CAAC,IAAI;QACJ,IAAI,OAAO,IAAI,KAAK,QAAQ;YACxB,OAAO,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC;QAC9B,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;IACrD,CAAC;IACD;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI;QACb,IAAI,OAAO,IAAI,KAAK,QAAQ;YACxB,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,IAAA,uBAAY,EAAC,8BAAe,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;YACjF,IAAI,GAAG,IAAI,EAAE,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,CAAC,IAAI;YACL,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,YAAY,CAAC,CAAC;QACpD,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,IA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,GAAG,IAAI,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,QAAQ,EAAE,cAAc,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzC,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ;YAChB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;QACnD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AAhED,sDAgEC;AACD,oCAAoC"}
|
package/lib/cjs/types.cjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;AACA,iCAAiC"}
|
package/lib/cjs/utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInjectKey = void 0;
|
|
4
|
-
const
|
|
4
|
+
const constants_js_1 = require("./constants.cjs");
|
|
5
5
|
/**
|
|
6
6
|
* @description Generates a fully qualified reflection metadata key.
|
|
7
7
|
* @summary Returns the reflection key for injectables by prefixing the provided key with the base reflection key.
|
|
@@ -10,6 +10,7 @@ const constants_1 = require("./constants.cjs");
|
|
|
10
10
|
* @function getInjectKey
|
|
11
11
|
* @memberOf module:injectable-decorators
|
|
12
12
|
*/
|
|
13
|
-
const getInjectKey = (key) =>
|
|
13
|
+
const getInjectKey = (key) => constants_js_1.InjectablesKeys.REFLECT + key;
|
|
14
14
|
exports.getInjectKey = getInjectKey;
|
|
15
|
+
//# sourceMappingURL=utils.js.map
|
|
15
16
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD;;;;;;;GAOG;AACI,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,8BAAe,CAAC,OAAO,GAAG,GAAG,CAAC;AAAtD,QAAA,YAAY,gBAA0C;AACnE,iCAAiC"}
|
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.
|
|
22
|
+
export const VERSION = "1.12.0";
|
|
23
23
|
export const PACKAGE_NAME = "@decaf-ts/injectable-decorators";
|
|
24
24
|
Metadata.registerLibrary(PACKAGE_NAME, VERSION);
|
|
25
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Injectable, InjectablesRegistry } from "./registry.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* @description Central registry for managing injectable dependencies.
|
|
4
|
+
* @summary Static class holding the access to the injectables functions. Provides methods for registering,
|
|
5
|
+
* retrieving, and building injectable objects.
|
|
6
|
+
* @template T Type of the injectable object
|
|
7
|
+
*
|
|
8
|
+
* @class Injectables
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Define an injectable class
|
|
12
|
+
* @injectable()
|
|
13
|
+
* class MyService {
|
|
14
|
+
* doSomething() {
|
|
15
|
+
* return 'Hello World';
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* // Inject the service into another class
|
|
20
|
+
* class MyComponent {
|
|
21
|
+
* @inject()
|
|
22
|
+
* private service!: MyService;
|
|
23
|
+
*
|
|
24
|
+
* useService() {
|
|
25
|
+
* return this.service.doSomething();
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @mermaid
|
|
30
|
+
* sequenceDiagram
|
|
31
|
+
* participant Client
|
|
32
|
+
* participant Injectables
|
|
33
|
+
* participant Registry
|
|
34
|
+
*
|
|
35
|
+
* Client->>Injectables: register(MyService)
|
|
36
|
+
* Injectables->>Registry: register(MyService)
|
|
37
|
+
* Registry-->>Injectables: void
|
|
38
|
+
*
|
|
39
|
+
* Client->>Injectables: get("MyService")
|
|
40
|
+
* Injectables->>Registry: get("MyService")
|
|
41
|
+
* Registry-->>Injectables: MyService instance
|
|
42
|
+
* Injectables-->>Client: MyService instance
|
|
43
|
+
*/
|
|
44
|
+
export declare class Injectables {
|
|
45
|
+
/**
|
|
46
|
+
* @description Holds the active registry implementation used by the Injectables facade.
|
|
47
|
+
* @summary Internal static reference that can be swapped via setRegistry to customize how injectables are stored and retrieved.
|
|
48
|
+
* @type {InjectablesRegistry | undefined}
|
|
49
|
+
*/
|
|
50
|
+
private static actingInjectablesRegistry?;
|
|
51
|
+
private constructor();
|
|
52
|
+
/**
|
|
53
|
+
* @description Fetches an injectable instance by its registered name.
|
|
54
|
+
* @summary Retrieves the named {@link Injectable} from the registry. If the injectable is a singleton,
|
|
55
|
+
* returns the existing instance. Otherwise, creates a new instance.
|
|
56
|
+
* @template T Type of the injectable object to retrieve
|
|
57
|
+
* @param {string} name The registered name of the injectable to retrieve
|
|
58
|
+
* @param {any[]} args Constructor arguments to pass when instantiating the injectable
|
|
59
|
+
* @return {Injectable<T> | undefined} The injectable instance or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
static get<T>(name: symbol | string | {
|
|
62
|
+
new (...args: any[]): T;
|
|
63
|
+
}, ...args: any[]): T | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* @description Adds a class or object to the injectable registry.
|
|
66
|
+
* @summary Registers an injectable constructor or instance with the registry, making it available for injection.
|
|
67
|
+
* @template T Type of the injectable object to register
|
|
68
|
+
* @param {Injectable<T>} constructor The class constructor or object instance to register
|
|
69
|
+
* @param {any[]} args Additional arguments for registration (category, singleton flag, etc.)
|
|
70
|
+
* @return {void}
|
|
71
|
+
*/
|
|
72
|
+
static register<T>(constructor: Injectable<T>, ...args: any[]): void;
|
|
73
|
+
/**
|
|
74
|
+
* @description Creates a new instance of an injectable class.
|
|
75
|
+
* @summary Instantiates an injectable class using its constructor and the provided arguments.
|
|
76
|
+
* @template T Type of the object to build
|
|
77
|
+
* @param {symbol} name symbol referencing the injectable
|
|
78
|
+
* @param {any[]} args Constructor arguments to pass when instantiating the injectable
|
|
79
|
+
* @return {T} The newly created instance
|
|
80
|
+
*/
|
|
81
|
+
static build<T>(name: symbol, ...args: any[]): T;
|
|
82
|
+
/**
|
|
83
|
+
* @description Replaces the current registry implementation.
|
|
84
|
+
* @summary Sets a new {@link InjectablesRegistry} implementation, allowing for custom registry behavior.
|
|
85
|
+
* @param {InjectablesRegistry} operationsRegistry The new implementation of Registry to use
|
|
86
|
+
* @return {void}
|
|
87
|
+
*/
|
|
88
|
+
static setRegistry(operationsRegistry: InjectablesRegistry): void;
|
|
89
|
+
/**
|
|
90
|
+
* @description Provides access to the current registry instance.
|
|
91
|
+
* @summary Returns the current {@link InjectablesRegistry} or creates a default one if none exists.
|
|
92
|
+
* @return {InjectablesRegistry} The current registry instance
|
|
93
|
+
*/
|
|
94
|
+
private static getRegistry;
|
|
95
|
+
/**
|
|
96
|
+
* @description Clears all registered injectables.
|
|
97
|
+
* @summary Resets the registry to a clean state by creating a new empty registry instance.
|
|
98
|
+
* @return {void}
|
|
99
|
+
*/
|
|
100
|
+
static reset(): void;
|
|
101
|
+
/**
|
|
102
|
+
* @description Removes specific injectables from the registry based on a pattern.
|
|
103
|
+
* @summary Selectively resets the registry by removing only the injectables whose names match the provided pattern.
|
|
104
|
+
* @param {string | RegExp} match A string or regular expression pattern to match against injectable names
|
|
105
|
+
* @return {void}
|
|
106
|
+
*/
|
|
107
|
+
static selectiveReset(match: string | RegExp): void;
|
|
108
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Injectable, InjectablesRegistry } from "./registry.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description Central registry for managing injectable dependencies.
|
|
4
|
+
* @summary Static class holding the access to the injectables functions. Provides methods for registering,
|
|
5
|
+
* retrieving, and building injectable objects.
|
|
6
|
+
* @template T Type of the injectable object
|
|
7
|
+
*
|
|
8
|
+
* @class Injectables
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Define an injectable class
|
|
12
|
+
* @injectable()
|
|
13
|
+
* class MyService {
|
|
14
|
+
* doSomething() {
|
|
15
|
+
* return 'Hello World';
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* // Inject the service into another class
|
|
20
|
+
* class MyComponent {
|
|
21
|
+
* @inject()
|
|
22
|
+
* private service!: MyService;
|
|
23
|
+
*
|
|
24
|
+
* useService() {
|
|
25
|
+
* return this.service.doSomething();
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @mermaid
|
|
30
|
+
* sequenceDiagram
|
|
31
|
+
* participant Client
|
|
32
|
+
* participant Injectables
|
|
33
|
+
* participant Registry
|
|
34
|
+
*
|
|
35
|
+
* Client->>Injectables: register(MyService)
|
|
36
|
+
* Injectables->>Registry: register(MyService)
|
|
37
|
+
* Registry-->>Injectables: void
|
|
38
|
+
*
|
|
39
|
+
* Client->>Injectables: get("MyService")
|
|
40
|
+
* Injectables->>Registry: get("MyService")
|
|
41
|
+
* Registry-->>Injectables: MyService instance
|
|
42
|
+
* Injectables-->>Client: MyService instance
|
|
43
|
+
*/
|
|
44
|
+
export declare class Injectables {
|
|
45
|
+
/**
|
|
46
|
+
* @description Holds the active registry implementation used by the Injectables facade.
|
|
47
|
+
* @summary Internal static reference that can be swapped via setRegistry to customize how injectables are stored and retrieved.
|
|
48
|
+
* @type {InjectablesRegistry | undefined}
|
|
49
|
+
*/
|
|
50
|
+
private static actingInjectablesRegistry?;
|
|
51
|
+
private constructor();
|
|
52
|
+
/**
|
|
53
|
+
* @description Fetches an injectable instance by its registered name.
|
|
54
|
+
* @summary Retrieves the named {@link Injectable} from the registry. If the injectable is a singleton,
|
|
55
|
+
* returns the existing instance. Otherwise, creates a new instance.
|
|
56
|
+
* @template T Type of the injectable object to retrieve
|
|
57
|
+
* @param {string} name The registered name of the injectable to retrieve
|
|
58
|
+
* @param {any[]} args Constructor arguments to pass when instantiating the injectable
|
|
59
|
+
* @return {Injectable<T> | undefined} The injectable instance or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
static get<T>(name: symbol | string | {
|
|
62
|
+
new (...args: any[]): T;
|
|
63
|
+
}, ...args: any[]): T | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* @description Adds a class or object to the injectable registry.
|
|
66
|
+
* @summary Registers an injectable constructor or instance with the registry, making it available for injection.
|
|
67
|
+
* @template T Type of the injectable object to register
|
|
68
|
+
* @param {Injectable<T>} constructor The class constructor or object instance to register
|
|
69
|
+
* @param {any[]} args Additional arguments for registration (category, singleton flag, etc.)
|
|
70
|
+
* @return {void}
|
|
71
|
+
*/
|
|
72
|
+
static register<T>(constructor: Injectable<T>, ...args: any[]): void;
|
|
73
|
+
/**
|
|
74
|
+
* @description Creates a new instance of an injectable class.
|
|
75
|
+
* @summary Instantiates an injectable class using its constructor and the provided arguments.
|
|
76
|
+
* @template T Type of the object to build
|
|
77
|
+
* @param {symbol} name symbol referencing the injectable
|
|
78
|
+
* @param {any[]} args Constructor arguments to pass when instantiating the injectable
|
|
79
|
+
* @return {T} The newly created instance
|
|
80
|
+
*/
|
|
81
|
+
static build<T>(name: symbol, ...args: any[]): T;
|
|
82
|
+
/**
|
|
83
|
+
* @description Replaces the current registry implementation.
|
|
84
|
+
* @summary Sets a new {@link InjectablesRegistry} implementation, allowing for custom registry behavior.
|
|
85
|
+
* @param {InjectablesRegistry} operationsRegistry The new implementation of Registry to use
|
|
86
|
+
* @return {void}
|
|
87
|
+
*/
|
|
88
|
+
static setRegistry(operationsRegistry: InjectablesRegistry): void;
|
|
89
|
+
/**
|
|
90
|
+
* @description Provides access to the current registry instance.
|
|
91
|
+
* @summary Returns the current {@link InjectablesRegistry} or creates a default one if none exists.
|
|
92
|
+
* @return {InjectablesRegistry} The current registry instance
|
|
93
|
+
*/
|
|
94
|
+
private static getRegistry;
|
|
95
|
+
/**
|
|
96
|
+
* @description Clears all registered injectables.
|
|
97
|
+
* @summary Resets the registry to a clean state by creating a new empty registry instance.
|
|
98
|
+
* @return {void}
|
|
99
|
+
*/
|
|
100
|
+
static reset(): void;
|
|
101
|
+
/**
|
|
102
|
+
* @description Removes specific injectables from the registry based on a pattern.
|
|
103
|
+
* @summary Selectively resets the registry by removing only the injectables whose names match the provided pattern.
|
|
104
|
+
* @param {string | RegExp} match A string or regular expression pattern to match against injectable names
|
|
105
|
+
* @return {void}
|
|
106
|
+
*/
|
|
107
|
+
static selectiveReset(match: string | RegExp): void;
|
|
108
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import { InjectOptions } from "./decorators.cjs";
|
|
3
|
+
declare module "@decaf-ts/decoration" {
|
|
4
|
+
namespace Metadata {
|
|
5
|
+
function injectables<T extends string | symbol | Constructor>(category?: T): (T extends undefined ? Constructor[] : Constructor) | undefined;
|
|
6
|
+
function injected<T, K extends keyof T>(model: T | Constructor<T>, prop?: K): (K extends keyof T ? InjectOptions : Record<K, InjectOptions>) | undefined;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import { InjectOptions } from "./decorators.js";
|
|
3
|
+
declare module "@decaf-ts/decoration" {
|
|
4
|
+
namespace Metadata {
|
|
5
|
+
function injectables<T extends string | symbol | Constructor>(category?: T): (T extends undefined ? Constructor[] : Constructor) | undefined;
|
|
6
|
+
function injected<T, K extends keyof T>(model: T | Constructor<T>, prop?: K): (K extends keyof T ? InjectOptions : Record<K, InjectOptions>) | undefined;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InjectableConfig } from "./decorators.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* @description Constants used for reflection metadata keys in the dependency injection system.
|
|
4
|
+
* @summary Injectables Reflection keys used to store and retrieve metadata about injectable classes and properties.
|
|
5
|
+
* @property {string} REFLECT Reflection injectables base key prefix for all metadata keys
|
|
6
|
+
* @property {string} INJECTABLE Reflection key suffix for marking a class as injectable
|
|
7
|
+
* @property {string} INJECT Reflection key suffix for marking a property for injection
|
|
8
|
+
* @const InjectablesKeys
|
|
9
|
+
* @memberOf module:injectable-decorators
|
|
10
|
+
*/
|
|
11
|
+
export declare const InjectablesKeys: {
|
|
12
|
+
REFLECT: string;
|
|
13
|
+
INJECTABLE: string;
|
|
14
|
+
INJECT: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @description Default configuration applied by the @injectable decorator when none is provided.
|
|
18
|
+
* @summary Sets sensible defaults such as singleton lifecycle for newly registered injectables.
|
|
19
|
+
* @const DefaultInjectablesConfig
|
|
20
|
+
* @memberOf module:injectable-decorators
|
|
21
|
+
*/
|
|
22
|
+
export declare const DefaultInjectablesConfig: InjectableConfig;
|
|
23
|
+
/**
|
|
24
|
+
* @description Reflection metadata key for accessing TypeScript type information.
|
|
25
|
+
* @summary Holds the key for retrieving the design type from TypeScript's reflection metadata.
|
|
26
|
+
* @const TypeKey
|
|
27
|
+
* @memberOf module:injectable-decorators
|
|
28
|
+
*/
|
|
29
|
+
export declare const TypeKey = "design:type";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InjectableConfig } from "./decorators.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description Constants used for reflection metadata keys in the dependency injection system.
|
|
4
|
+
* @summary Injectables Reflection keys used to store and retrieve metadata about injectable classes and properties.
|
|
5
|
+
* @property {string} REFLECT Reflection injectables base key prefix for all metadata keys
|
|
6
|
+
* @property {string} INJECTABLE Reflection key suffix for marking a class as injectable
|
|
7
|
+
* @property {string} INJECT Reflection key suffix for marking a property for injection
|
|
8
|
+
* @const InjectablesKeys
|
|
9
|
+
* @memberOf module:injectable-decorators
|
|
10
|
+
*/
|
|
11
|
+
export declare const InjectablesKeys: {
|
|
12
|
+
REFLECT: string;
|
|
13
|
+
INJECTABLE: string;
|
|
14
|
+
INJECT: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @description Default configuration applied by the @injectable decorator when none is provided.
|
|
18
|
+
* @summary Sets sensible defaults such as singleton lifecycle for newly registered injectables.
|
|
19
|
+
* @const DefaultInjectablesConfig
|
|
20
|
+
* @memberOf module:injectable-decorators
|
|
21
|
+
*/
|
|
22
|
+
export declare const DefaultInjectablesConfig: InjectableConfig;
|
|
23
|
+
/**
|
|
24
|
+
* @description Reflection metadata key for accessing TypeScript type information.
|
|
25
|
+
* @summary Holds the key for retrieving the design type from TypeScript's reflection metadata.
|
|
26
|
+
* @const TypeKey
|
|
27
|
+
* @memberOf module:injectable-decorators
|
|
28
|
+
*/
|
|
29
|
+
export declare const TypeKey = "design:type";
|