@husky-di/decorator 1.0.1 → 1.1.1
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 +3 -3
- package/dist/constants/metadata-key.const.d.ts +2 -2
- package/dist/enums/decorator-error-code.enum.d.ts +42 -0
- package/dist/exceptions/decorator.exception.d.ts +12 -0
- package/dist/index.cjs +60 -17
- package/dist/index.d.ts +2 -0
- package/dist/index.js +50 -13
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -178,7 +178,7 @@ console.log(result); // "Logged: Executing: SELECT * FROM users WHERE id = 123"
|
|
|
178
178
|
1. **重复使用 @injectable()**
|
|
179
179
|
|
|
180
180
|
```typescript
|
|
181
|
-
//
|
|
181
|
+
// 错误:不能对同一个类使用两次 @injectable()
|
|
182
182
|
@injectable()
|
|
183
183
|
@injectable()
|
|
184
184
|
class TestService {}
|
|
@@ -187,7 +187,7 @@ console.log(result); // "Logged: Executing: SELECT * FROM users WHERE id = 123"
|
|
|
187
187
|
2. **注入非可注入类**
|
|
188
188
|
|
|
189
189
|
```typescript
|
|
190
|
-
//
|
|
190
|
+
// 错误:依赖的类没有使用 @injectable()
|
|
191
191
|
class NonInjectableService {}
|
|
192
192
|
|
|
193
193
|
@injectable()
|
|
@@ -199,7 +199,7 @@ console.log(result); // "Logged: Executing: SELECT * FROM users WHERE id = 123"
|
|
|
199
199
|
3. **循环依赖**
|
|
200
200
|
|
|
201
201
|
```typescript
|
|
202
|
-
//
|
|
202
|
+
// 错误:检测到循环依赖
|
|
203
203
|
@injectable()
|
|
204
204
|
class ServiceA {
|
|
205
205
|
constructor(@inject(ServiceB) public serviceB: ServiceB) {}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @see {@link https://www.typescriptlang.org/tsconfig/#Language_and_Environment_6254}
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const PARAMS_METADATA_KEY = "design:paramtypes";
|
|
13
13
|
/**
|
|
14
14
|
* Custom metadata key for storing injection metadata of a class.
|
|
15
15
|
* Contains information about how each constructor parameter should be resolved,
|
|
@@ -19,4 +19,4 @@ export declare const ParamsMetadataKeyConst = "design:paramtypes";
|
|
|
19
19
|
* Stores: `Array<InjectionMetadata<T> | undefined>`
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const INJECTION_METADATA_KEY = "husky-di.injection-metadata";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @overview Decorator package error code enum.
|
|
3
|
+
* @author AEPKILL
|
|
4
|
+
* @created 2026-05-09 00:00:00
|
|
5
|
+
*/
|
|
6
|
+
export declare enum DecoratorErrorCodeEnum {
|
|
7
|
+
/**
|
|
8
|
+
* Class is decorated with @injectable() more than once.
|
|
9
|
+
* @see SPECIFICATION.md Section 4.1 M1
|
|
10
|
+
*/
|
|
11
|
+
E_DUPLICATE_INJECTABLE = "E_DUPLICATE_INJECTABLE",
|
|
12
|
+
/**
|
|
13
|
+
* Constructor parameter without explicit metadata is not a class type.
|
|
14
|
+
* @see SPECIFICATION.md Section 4.1 M3
|
|
15
|
+
*/
|
|
16
|
+
E_NON_CLASS_PARAMETER = "E_NON_CLASS_PARAMETER",
|
|
17
|
+
/**
|
|
18
|
+
* Class resolved through decorator middleware is not decorated with @injectable().
|
|
19
|
+
* @see SPECIFICATION.md Section 5.1 V1
|
|
20
|
+
*/
|
|
21
|
+
E_NOT_INJECTABLE = "E_NOT_INJECTABLE",
|
|
22
|
+
/**
|
|
23
|
+
* Injection metadata does not include a serviceIdentifier.
|
|
24
|
+
* @see SPECIFICATION.md Section 4.3 T2
|
|
25
|
+
*/
|
|
26
|
+
E_MISSING_SERVICE_IDENTIFIER = "E_MISSING_SERVICE_IDENTIFIER",
|
|
27
|
+
/**
|
|
28
|
+
* Injection metadata includes an invalid serviceIdentifier.
|
|
29
|
+
* @see SPECIFICATION.md Section 5.2 V3
|
|
30
|
+
*/
|
|
31
|
+
E_INVALID_SERVICE_IDENTIFIER = "E_INVALID_SERVICE_IDENTIFIER",
|
|
32
|
+
/**
|
|
33
|
+
* Injection metadata enables dynamic and ref at the same time.
|
|
34
|
+
* @see SPECIFICATION.md Section 5.2 V4
|
|
35
|
+
*/
|
|
36
|
+
E_CONFLICTING_OPTIONS = "E_CONFLICTING_OPTIONS",
|
|
37
|
+
/**
|
|
38
|
+
* Consolidated injection metadata is missing a parameter entry.
|
|
39
|
+
* @see SPECIFICATION.md Section 5.1 V2
|
|
40
|
+
*/
|
|
41
|
+
E_INCOMPLETE_METADATA = "E_INCOMPLETE_METADATA"
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @overview Decorator package exception.
|
|
3
|
+
* @author AEPKILL
|
|
4
|
+
* @created 2026-05-09 00:00:00
|
|
5
|
+
*/
|
|
6
|
+
import { CodedException } from "@husky-di/core";
|
|
7
|
+
import type { DecoratorErrorCodeEnum } from "../enums/decorator-error-code.enum";
|
|
8
|
+
export declare class DecoratorException extends CodedException<DecoratorErrorCodeEnum> {
|
|
9
|
+
/** Internal marker to identify DecoratorException instances across frames. */
|
|
10
|
+
private __isDecoratorException__;
|
|
11
|
+
static isDecoratorException(error: unknown): error is DecoratorException;
|
|
12
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
|
|
|
13
13
|
})();
|
|
14
14
|
(()=>{
|
|
15
15
|
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if (
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
17
|
value: 'Module'
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports1, '__esModule', {
|
|
@@ -25,27 +25,66 @@ var __webpack_exports__ = {};
|
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
inject: ()=>inject,
|
|
28
|
+
DecoratorErrorCodeEnum: ()=>decorator_error_code_enum_DecoratorErrorCodeEnum,
|
|
29
|
+
injectable: ()=>injectable,
|
|
30
|
+
DecoratorException: ()=>DecoratorException,
|
|
28
31
|
tagged: ()=>tagged,
|
|
29
|
-
decoratorMiddleware: ()=>decoratorMiddleware
|
|
30
|
-
injectable: ()=>injectable
|
|
32
|
+
decoratorMiddleware: ()=>decoratorMiddleware
|
|
31
33
|
});
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const PARAMS_METADATA_KEY = "design:paramtypes";
|
|
35
|
+
const INJECTION_METADATA_KEY = "husky-di.injection-metadata";
|
|
36
|
+
var decorator_error_code_enum_DecoratorErrorCodeEnum = /*#__PURE__*/ function(DecoratorErrorCodeEnum) {
|
|
37
|
+
DecoratorErrorCodeEnum["E_DUPLICATE_INJECTABLE"] = "E_DUPLICATE_INJECTABLE";
|
|
38
|
+
DecoratorErrorCodeEnum["E_NON_CLASS_PARAMETER"] = "E_NON_CLASS_PARAMETER";
|
|
39
|
+
DecoratorErrorCodeEnum["E_NOT_INJECTABLE"] = "E_NOT_INJECTABLE";
|
|
40
|
+
DecoratorErrorCodeEnum["E_MISSING_SERVICE_IDENTIFIER"] = "E_MISSING_SERVICE_IDENTIFIER";
|
|
41
|
+
DecoratorErrorCodeEnum["E_INVALID_SERVICE_IDENTIFIER"] = "E_INVALID_SERVICE_IDENTIFIER";
|
|
42
|
+
DecoratorErrorCodeEnum["E_CONFLICTING_OPTIONS"] = "E_CONFLICTING_OPTIONS";
|
|
43
|
+
DecoratorErrorCodeEnum["E_INCOMPLETE_METADATA"] = "E_INCOMPLETE_METADATA";
|
|
44
|
+
return DecoratorErrorCodeEnum;
|
|
45
|
+
}({});
|
|
46
|
+
const core_namespaceObject = require("@husky-di/core");
|
|
47
|
+
class DecoratorException extends core_namespaceObject.CodedException {
|
|
48
|
+
static isDecoratorException(error) {
|
|
49
|
+
return error?.__isDecoratorException__ === true;
|
|
50
|
+
}
|
|
51
|
+
constructor(...args){
|
|
52
|
+
super(...args), this.__isDecoratorException__ = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const tagged = (metadata)=>{
|
|
56
|
+
validateInjectionMetadata(metadata);
|
|
57
|
+
return (target, _propertyKey, parameterIndex)=>{
|
|
58
|
+
const parametersMetadata = Reflect.getMetadata(INJECTION_METADATA_KEY, target) || [];
|
|
36
59
|
parametersMetadata[parameterIndex] = metadata;
|
|
37
|
-
Reflect.defineMetadata(
|
|
60
|
+
Reflect.defineMetadata(INJECTION_METADATA_KEY, parametersMetadata, target);
|
|
38
61
|
};
|
|
62
|
+
};
|
|
63
|
+
function validateInjectionMetadata(metadata) {
|
|
64
|
+
const serviceIdentifier = metadata?.serviceIdentifier;
|
|
65
|
+
if (null == serviceIdentifier) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_MISSING_SERVICE_IDENTIFIER, "Injection metadata must include a serviceIdentifier");
|
|
66
|
+
const isValidServiceIdentifier = "function" == typeof serviceIdentifier || "symbol" == typeof serviceIdentifier || "string" == typeof serviceIdentifier && serviceIdentifier.length > 0;
|
|
67
|
+
if (!isValidServiceIdentifier) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_INVALID_SERVICE_IDENTIFIER, `Invalid service identifier: ${String(serviceIdentifier)}`);
|
|
68
|
+
if (metadata.dynamic && metadata.ref) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_CONFLICTING_OPTIONS, 'Cannot use both "dynamic" and "ref" options simultaneously');
|
|
69
|
+
}
|
|
39
70
|
const inject = (serviceIdentifier, options)=>tagged({
|
|
40
71
|
...options,
|
|
41
72
|
serviceIdentifier
|
|
42
73
|
});
|
|
43
|
-
const InjectionMetadataMap = "
|
|
74
|
+
const InjectionMetadataMap = "u" < typeof WeakMap ? Map : WeakMap;
|
|
44
75
|
const injectionMetadataMap = new InjectionMetadataMap();
|
|
76
|
+
const NON_CLASS_PARAMETER_TYPES = new Set([
|
|
77
|
+
String,
|
|
78
|
+
Number,
|
|
79
|
+
Boolean,
|
|
80
|
+
BigInt,
|
|
81
|
+
Symbol,
|
|
82
|
+
Object
|
|
83
|
+
]);
|
|
45
84
|
const injectable = ()=>(target)=>{
|
|
46
|
-
if (injectionMetadataMap.has(target)) throw new
|
|
47
|
-
const parametersServiceIdentifiers = Reflect.getMetadata(
|
|
48
|
-
const parametersMetadata = Reflect.getMetadata(
|
|
85
|
+
if (injectionMetadataMap.has(target)) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_DUPLICATE_INJECTABLE, `Class '${target.name}' is already decorated with @Injectable()`);
|
|
86
|
+
const parametersServiceIdentifiers = Reflect.getMetadata(PARAMS_METADATA_KEY, target) || [];
|
|
87
|
+
const parametersMetadata = Reflect.getMetadata(INJECTION_METADATA_KEY, target) || [];
|
|
49
88
|
const metadata = [];
|
|
50
89
|
const parametersMetadataLength = Math.max(parametersServiceIdentifiers.length, parametersMetadata.length);
|
|
51
90
|
for(let index = 0; index < parametersMetadataLength; index++){
|
|
@@ -54,14 +93,14 @@ const injectable = ()=>(target)=>{
|
|
|
54
93
|
continue;
|
|
55
94
|
}
|
|
56
95
|
const serviceIdentifier = parametersServiceIdentifiers[index];
|
|
57
|
-
if ("function" != typeof serviceIdentifier) throw new
|
|
96
|
+
if ("function" != typeof serviceIdentifier || NON_CLASS_PARAMETER_TYPES.has(serviceIdentifier)) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_NON_CLASS_PARAMETER, `Constructor '${target.name}' parameter #${index} must be a class type`);
|
|
58
97
|
metadata.push({
|
|
59
98
|
serviceIdentifier
|
|
60
99
|
});
|
|
61
100
|
}
|
|
101
|
+
if (metadata.length !== parametersMetadataLength) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_INCOMPLETE_METADATA, `Constructor '${target.name}' has incomplete injection metadata`);
|
|
62
102
|
injectionMetadataMap.set(target, metadata);
|
|
63
103
|
};
|
|
64
|
-
const core_namespaceObject = require("@husky-di/core");
|
|
65
104
|
const decoratorMiddleware = {
|
|
66
105
|
name: Symbol("DecoratorMiddleware"),
|
|
67
106
|
executor: (params, next)=>{
|
|
@@ -70,7 +109,7 @@ const decoratorMiddleware = {
|
|
|
70
109
|
const provider = registration.provider;
|
|
71
110
|
if (isPrimitiveConstructor(provider)) return new provider();
|
|
72
111
|
const parametersMetadata = injectionMetadataMap.get(provider);
|
|
73
|
-
if (!parametersMetadata) throw new core_namespaceObject.ResolveException(`Class '${provider.name}' must be decorated with @Injectable()`, resolveRecord);
|
|
112
|
+
if (!parametersMetadata) throw new core_namespaceObject.ResolveException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_NOT_INJECTABLE, `Class '${provider.name}' must be decorated with @Injectable()`, resolveRecord);
|
|
74
113
|
const parameters = parametersMetadata.map((metadata, index)=>{
|
|
75
114
|
const { serviceIdentifier, ...options } = metadata;
|
|
76
115
|
resolveRecord._internalStashCurrent();
|
|
@@ -88,16 +127,20 @@ const decoratorMiddleware = {
|
|
|
88
127
|
function isPrimitiveConstructor(value) {
|
|
89
128
|
return value === String || value === Number || value === Boolean || value === Symbol || value === BigInt;
|
|
90
129
|
}
|
|
130
|
+
exports.DecoratorErrorCodeEnum = __webpack_exports__.DecoratorErrorCodeEnum;
|
|
131
|
+
exports.DecoratorException = __webpack_exports__.DecoratorException;
|
|
91
132
|
exports.decoratorMiddleware = __webpack_exports__.decoratorMiddleware;
|
|
92
133
|
exports.inject = __webpack_exports__.inject;
|
|
93
134
|
exports.injectable = __webpack_exports__.injectable;
|
|
94
135
|
exports.tagged = __webpack_exports__.tagged;
|
|
95
|
-
for(var
|
|
136
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
137
|
+
"DecoratorErrorCodeEnum",
|
|
138
|
+
"DecoratorException",
|
|
96
139
|
"decoratorMiddleware",
|
|
97
140
|
"inject",
|
|
98
141
|
"injectable",
|
|
99
142
|
"tagged"
|
|
100
|
-
].indexOf(
|
|
143
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
101
144
|
Object.defineProperty(exports, '__esModule', {
|
|
102
145
|
value: true
|
|
103
146
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,7 @@
|
|
|
6
6
|
export * from "./decorators/inject.decorator";
|
|
7
7
|
export * from "./decorators/injectable.decorator";
|
|
8
8
|
export * from "./decorators/tagged.decorator";
|
|
9
|
+
export { DecoratorErrorCodeEnum } from "./enums/decorator-error-code.enum";
|
|
10
|
+
export { DecoratorException } from "./exceptions/decorator.exception";
|
|
9
11
|
export { decoratorMiddleware } from "./middlewares/decorator.middleware";
|
|
10
12
|
export * from "./types/injection-metadata.type";
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,57 @@
|
|
|
1
|
-
import { RegistrationTypeEnum, ResolveException, ResolveRecordTypeEnum, resolve } from "@husky-di/core";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CodedException, RegistrationTypeEnum, ResolveException, ResolveRecordTypeEnum, resolve } from "@husky-di/core";
|
|
2
|
+
const PARAMS_METADATA_KEY = "design:paramtypes";
|
|
3
|
+
const INJECTION_METADATA_KEY = "husky-di.injection-metadata";
|
|
4
|
+
var decorator_error_code_enum_DecoratorErrorCodeEnum = /*#__PURE__*/ function(DecoratorErrorCodeEnum) {
|
|
5
|
+
DecoratorErrorCodeEnum["E_DUPLICATE_INJECTABLE"] = "E_DUPLICATE_INJECTABLE";
|
|
6
|
+
DecoratorErrorCodeEnum["E_NON_CLASS_PARAMETER"] = "E_NON_CLASS_PARAMETER";
|
|
7
|
+
DecoratorErrorCodeEnum["E_NOT_INJECTABLE"] = "E_NOT_INJECTABLE";
|
|
8
|
+
DecoratorErrorCodeEnum["E_MISSING_SERVICE_IDENTIFIER"] = "E_MISSING_SERVICE_IDENTIFIER";
|
|
9
|
+
DecoratorErrorCodeEnum["E_INVALID_SERVICE_IDENTIFIER"] = "E_INVALID_SERVICE_IDENTIFIER";
|
|
10
|
+
DecoratorErrorCodeEnum["E_CONFLICTING_OPTIONS"] = "E_CONFLICTING_OPTIONS";
|
|
11
|
+
DecoratorErrorCodeEnum["E_INCOMPLETE_METADATA"] = "E_INCOMPLETE_METADATA";
|
|
12
|
+
return DecoratorErrorCodeEnum;
|
|
13
|
+
}({});
|
|
14
|
+
class DecoratorException extends CodedException {
|
|
15
|
+
static isDecoratorException(error) {
|
|
16
|
+
return error?.__isDecoratorException__ === true;
|
|
17
|
+
}
|
|
18
|
+
constructor(...args){
|
|
19
|
+
super(...args), this.__isDecoratorException__ = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const tagged = (metadata)=>{
|
|
23
|
+
validateInjectionMetadata(metadata);
|
|
24
|
+
return (target, _propertyKey, parameterIndex)=>{
|
|
25
|
+
const parametersMetadata = Reflect.getMetadata(INJECTION_METADATA_KEY, target) || [];
|
|
6
26
|
parametersMetadata[parameterIndex] = metadata;
|
|
7
|
-
Reflect.defineMetadata(
|
|
27
|
+
Reflect.defineMetadata(INJECTION_METADATA_KEY, parametersMetadata, target);
|
|
8
28
|
};
|
|
29
|
+
};
|
|
30
|
+
function validateInjectionMetadata(metadata) {
|
|
31
|
+
const serviceIdentifier = metadata?.serviceIdentifier;
|
|
32
|
+
if (null == serviceIdentifier) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_MISSING_SERVICE_IDENTIFIER, "Injection metadata must include a serviceIdentifier");
|
|
33
|
+
const isValidServiceIdentifier = "function" == typeof serviceIdentifier || "symbol" == typeof serviceIdentifier || "string" == typeof serviceIdentifier && serviceIdentifier.length > 0;
|
|
34
|
+
if (!isValidServiceIdentifier) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_INVALID_SERVICE_IDENTIFIER, `Invalid service identifier: ${String(serviceIdentifier)}`);
|
|
35
|
+
if (metadata.dynamic && metadata.ref) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_CONFLICTING_OPTIONS, 'Cannot use both "dynamic" and "ref" options simultaneously');
|
|
36
|
+
}
|
|
9
37
|
const inject = (serviceIdentifier, options)=>tagged({
|
|
10
38
|
...options,
|
|
11
39
|
serviceIdentifier
|
|
12
40
|
});
|
|
13
|
-
const InjectionMetadataMap = "
|
|
41
|
+
const InjectionMetadataMap = "u" < typeof WeakMap ? Map : WeakMap;
|
|
14
42
|
const injectionMetadataMap = new InjectionMetadataMap();
|
|
43
|
+
const NON_CLASS_PARAMETER_TYPES = new Set([
|
|
44
|
+
String,
|
|
45
|
+
Number,
|
|
46
|
+
Boolean,
|
|
47
|
+
BigInt,
|
|
48
|
+
Symbol,
|
|
49
|
+
Object
|
|
50
|
+
]);
|
|
15
51
|
const injectable = ()=>(target)=>{
|
|
16
|
-
if (injectionMetadataMap.has(target)) throw new
|
|
17
|
-
const parametersServiceIdentifiers = Reflect.getMetadata(
|
|
18
|
-
const parametersMetadata = Reflect.getMetadata(
|
|
52
|
+
if (injectionMetadataMap.has(target)) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_DUPLICATE_INJECTABLE, `Class '${target.name}' is already decorated with @Injectable()`);
|
|
53
|
+
const parametersServiceIdentifiers = Reflect.getMetadata(PARAMS_METADATA_KEY, target) || [];
|
|
54
|
+
const parametersMetadata = Reflect.getMetadata(INJECTION_METADATA_KEY, target) || [];
|
|
19
55
|
const metadata = [];
|
|
20
56
|
const parametersMetadataLength = Math.max(parametersServiceIdentifiers.length, parametersMetadata.length);
|
|
21
57
|
for(let index = 0; index < parametersMetadataLength; index++){
|
|
@@ -24,11 +60,12 @@ const injectable = ()=>(target)=>{
|
|
|
24
60
|
continue;
|
|
25
61
|
}
|
|
26
62
|
const serviceIdentifier = parametersServiceIdentifiers[index];
|
|
27
|
-
if ("function" != typeof serviceIdentifier) throw new
|
|
63
|
+
if ("function" != typeof serviceIdentifier || NON_CLASS_PARAMETER_TYPES.has(serviceIdentifier)) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_NON_CLASS_PARAMETER, `Constructor '${target.name}' parameter #${index} must be a class type`);
|
|
28
64
|
metadata.push({
|
|
29
65
|
serviceIdentifier
|
|
30
66
|
});
|
|
31
67
|
}
|
|
68
|
+
if (metadata.length !== parametersMetadataLength) throw new DecoratorException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_INCOMPLETE_METADATA, `Constructor '${target.name}' has incomplete injection metadata`);
|
|
32
69
|
injectionMetadataMap.set(target, metadata);
|
|
33
70
|
};
|
|
34
71
|
const decoratorMiddleware = {
|
|
@@ -39,7 +76,7 @@ const decoratorMiddleware = {
|
|
|
39
76
|
const provider = registration.provider;
|
|
40
77
|
if (isPrimitiveConstructor(provider)) return new provider();
|
|
41
78
|
const parametersMetadata = injectionMetadataMap.get(provider);
|
|
42
|
-
if (!parametersMetadata) throw new ResolveException(`Class '${provider.name}' must be decorated with @Injectable()`, resolveRecord);
|
|
79
|
+
if (!parametersMetadata) throw new ResolveException(decorator_error_code_enum_DecoratorErrorCodeEnum.E_NOT_INJECTABLE, `Class '${provider.name}' must be decorated with @Injectable()`, resolveRecord);
|
|
43
80
|
const parameters = parametersMetadata.map((metadata, index)=>{
|
|
44
81
|
const { serviceIdentifier, ...options } = metadata;
|
|
45
82
|
resolveRecord._internalStashCurrent();
|
|
@@ -57,4 +94,4 @@ const decoratorMiddleware = {
|
|
|
57
94
|
function isPrimitiveConstructor(value) {
|
|
58
95
|
return value === String || value === Number || value === Boolean || value === Symbol || value === BigInt;
|
|
59
96
|
}
|
|
60
|
-
export { decoratorMiddleware, inject, injectable, tagged };
|
|
97
|
+
export { DecoratorException, decoratorMiddleware, decorator_error_code_enum_DecoratorErrorCodeEnum as DecoratorErrorCodeEnum, inject, injectable, tagged };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@husky-di/decorator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@husky-di/core": "1.0
|
|
18
|
+
"@husky-di/core": "1.2.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@biomejs/biome": "2.
|
|
22
|
-
"@rslib/core": "^0.
|
|
23
|
-
"@types/node": "^
|
|
21
|
+
"@biomejs/biome": "2.4.15",
|
|
22
|
+
"@rslib/core": "^0.20.1",
|
|
23
|
+
"@types/node": "^25.5.0",
|
|
24
24
|
"reflect-metadata": "^0.2.2",
|
|
25
|
-
"typescript": "^
|
|
26
|
-
"vitest": "^
|
|
25
|
+
"typescript": "^6.0.3",
|
|
26
|
+
"vitest": "^4.1.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"reflect-metadata": "^0.2.2"
|