@lppedd/di-wise-neo 0.24.0 → 0.25.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/dist/cjs/index.d.ts +0 -88
- package/dist/cjs/index.js +106 -49
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +0 -88
- package/dist/es/index.mjs +106 -49
- package/dist/es/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/es/index.d.mts
CHANGED
|
@@ -658,22 +658,6 @@ declare function createContainer(options?: ContainerOptions): Container;
|
|
|
658
658
|
* ```
|
|
659
659
|
*/
|
|
660
660
|
declare function AutoRegister<This extends object, Ctor extends Constructor<This>>(target: Ctor): void;
|
|
661
|
-
/**
|
|
662
|
-
* Class decorator that enables auto-registration of an unregistered class
|
|
663
|
-
* when the class is first resolved from the container.
|
|
664
|
-
*
|
|
665
|
-
* Example:
|
|
666
|
-
* ```ts
|
|
667
|
-
* @AutoRegister()
|
|
668
|
-
* class Wizard {}
|
|
669
|
-
*
|
|
670
|
-
* const wizard = container.resolve(Wizard);
|
|
671
|
-
* container.isRegistered(Wizard); // => true
|
|
672
|
-
* ```
|
|
673
|
-
*
|
|
674
|
-
* @deprecated Use `@AutoRegister` instead of `AutoRegister()`.
|
|
675
|
-
*/
|
|
676
|
-
declare function AutoRegister<This extends object>(): ClassDecorator<This>;
|
|
677
661
|
|
|
678
662
|
/**
|
|
679
663
|
* Class decorator that sets the class scope to **Container** and enables
|
|
@@ -695,28 +679,6 @@ declare function AutoRegister<This extends object>(): ClassDecorator<This>;
|
|
|
695
679
|
* ```
|
|
696
680
|
*/
|
|
697
681
|
declare function EagerInstantiate<This extends object, Ctor extends Constructor<This>>(target: Ctor): void;
|
|
698
|
-
/**
|
|
699
|
-
* Class decorator that sets the class scope to **Container** and enables
|
|
700
|
-
* eager instantiation when the class is registered in the container.
|
|
701
|
-
*
|
|
702
|
-
* This causes the container to create and cache the instance of the class
|
|
703
|
-
* immediately, instead of deferring it until the first resolution.
|
|
704
|
-
*
|
|
705
|
-
* If the class cannot be resolved at registration time, registration fails.
|
|
706
|
-
*
|
|
707
|
-
* Example:
|
|
708
|
-
* ```ts
|
|
709
|
-
* @EagerInstantiate()
|
|
710
|
-
* class Wizard {}
|
|
711
|
-
*
|
|
712
|
-
* // Wizard is registered with Container scope, and an instance
|
|
713
|
-
* // is created and cached immediately by the container
|
|
714
|
-
* container.register(Wizard);
|
|
715
|
-
* ```
|
|
716
|
-
*
|
|
717
|
-
* @deprecated Use `@EagerInstantiate` instead of `@EagerInstantiate()`.
|
|
718
|
-
*/
|
|
719
|
-
declare function EagerInstantiate<This extends object>(): ClassDecorator<This>;
|
|
720
682
|
|
|
721
683
|
/**
|
|
722
684
|
* Parameter decorator that injects the instance associated with the given class.
|
|
@@ -964,23 +926,6 @@ declare function OptionalAll<Value>(tokens: TokenRef<Value>): ParameterDecorator
|
|
|
964
926
|
* ```
|
|
965
927
|
*/
|
|
966
928
|
declare function ContainerScoped<This extends object, Ctor extends Constructor<This>>(target: Ctor): void;
|
|
967
|
-
/**
|
|
968
|
-
* Class decorator that registers the decorated type with the **Container** scope.
|
|
969
|
-
*
|
|
970
|
-
* Use this scope when you want one cached instance per container,
|
|
971
|
-
* with parent-container lookup fallback.
|
|
972
|
-
*
|
|
973
|
-
* Example:
|
|
974
|
-
* ```ts
|
|
975
|
-
* @ContainerScoped()
|
|
976
|
-
* class Wizard {
|
|
977
|
-
* // ...
|
|
978
|
-
* }
|
|
979
|
-
* ```
|
|
980
|
-
*
|
|
981
|
-
* @deprecated Use `@ContainerScoped` instead of `@ContainerScoped()`.
|
|
982
|
-
*/
|
|
983
|
-
declare function ContainerScoped<This extends object>(): ClassDecorator<This>;
|
|
984
929
|
/**
|
|
985
930
|
* Class decorator that registers the decorated type with the **Resolution** scope.
|
|
986
931
|
*
|
|
@@ -996,23 +941,6 @@ declare function ContainerScoped<This extends object>(): ClassDecorator<This>;
|
|
|
996
941
|
* ```
|
|
997
942
|
*/
|
|
998
943
|
declare function ResolutionScoped<This extends object, Ctor extends Constructor<This>>(target: Ctor): void;
|
|
999
|
-
/**
|
|
1000
|
-
* Class decorator that registers the decorated type with the **Resolution** scope.
|
|
1001
|
-
*
|
|
1002
|
-
* Use this scope when you want one cached instance per resolution graph,
|
|
1003
|
-
* so repeated resolutions within the same request reuse the same value.
|
|
1004
|
-
*
|
|
1005
|
-
* Example:
|
|
1006
|
-
* ```ts
|
|
1007
|
-
* @ResolutionScoped()
|
|
1008
|
-
* class Wand {
|
|
1009
|
-
* // ...
|
|
1010
|
-
* }
|
|
1011
|
-
* ```
|
|
1012
|
-
*
|
|
1013
|
-
* @deprecated Use `@ResolutionScoped` instead of `@ResolutionScoped()`.
|
|
1014
|
-
*/
|
|
1015
|
-
declare function ResolutionScoped<This extends object>(): ClassDecorator<This>;
|
|
1016
944
|
/**
|
|
1017
945
|
* Class decorator that registers the decorated type with the **Transient** scope.
|
|
1018
946
|
*
|
|
@@ -1027,22 +955,6 @@ declare function ResolutionScoped<This extends object>(): ClassDecorator<This>;
|
|
|
1027
955
|
* ```
|
|
1028
956
|
*/
|
|
1029
957
|
declare function TransientScoped<This extends object, Ctor extends Constructor<This>>(target: Ctor): void;
|
|
1030
|
-
/**
|
|
1031
|
-
* Class decorator that registers the decorated type with the **Transient** scope.
|
|
1032
|
-
*
|
|
1033
|
-
* Use this scope when you want a fresh instance every time the class is resolved.
|
|
1034
|
-
*
|
|
1035
|
-
* Example:
|
|
1036
|
-
* ```ts
|
|
1037
|
-
* @TransientScoped()
|
|
1038
|
-
* class Wand {
|
|
1039
|
-
* // ...
|
|
1040
|
-
* }
|
|
1041
|
-
* ```
|
|
1042
|
-
*
|
|
1043
|
-
* @deprecated Use `@TransientScoped` instead of `@TransientScoped()`.
|
|
1044
|
-
*/
|
|
1045
|
-
declare function TransientScoped<This extends object>(): ClassDecorator<This>;
|
|
1046
958
|
/**
|
|
1047
959
|
* Class decorator for setting the scope of the decorated type when registering it.
|
|
1048
960
|
*
|
package/dist/es/index.mjs
CHANGED
|
@@ -1113,33 +1113,57 @@ function isDisposable(value) {
|
|
|
1113
1113
|
return new ContainerImpl(undefined, options);
|
|
1114
1114
|
}
|
|
1115
1115
|
|
|
1116
|
-
|
|
1116
|
+
/**
|
|
1117
|
+
* Class decorator that enables auto-registration of an unregistered class
|
|
1118
|
+
* when the class is first resolved from the container.
|
|
1119
|
+
*
|
|
1120
|
+
* Example:
|
|
1121
|
+
* ```ts
|
|
1122
|
+
* @AutoRegister
|
|
1123
|
+
* class Wizard {}
|
|
1124
|
+
*
|
|
1125
|
+
* const wizard = container.resolve(Wizard);
|
|
1126
|
+
* container.isRegistered(Wizard); // => true
|
|
1127
|
+
* ```
|
|
1128
|
+
*/ // @__NO_SIDE_EFFECTS__
|
|
1117
1129
|
function AutoRegister(target) {
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
metadata.autoRegister = true;
|
|
1121
|
-
};
|
|
1122
|
-
return target === undefined ? decorator : decorator(target);
|
|
1130
|
+
const metadata = getMetadata(target);
|
|
1131
|
+
metadata.autoRegister = true;
|
|
1123
1132
|
}
|
|
1124
1133
|
|
|
1125
|
-
|
|
1134
|
+
/**
|
|
1135
|
+
* Class decorator that sets the class scope to **Container** and enables
|
|
1136
|
+
* eager instantiation when the class is registered in the container.
|
|
1137
|
+
*
|
|
1138
|
+
* This causes the container to create and cache the instance of the class
|
|
1139
|
+
* immediately, instead of deferring it until the first resolution.
|
|
1140
|
+
*
|
|
1141
|
+
* If the class cannot be resolved at registration time, registration fails.
|
|
1142
|
+
*
|
|
1143
|
+
* Example:
|
|
1144
|
+
* ```ts
|
|
1145
|
+
* @EagerInstantiate
|
|
1146
|
+
* class Wizard {}
|
|
1147
|
+
*
|
|
1148
|
+
* // Wizard is registered with Container scope, and an instance
|
|
1149
|
+
* // is created and cached immediately by the container
|
|
1150
|
+
* container.register(Wizard);
|
|
1151
|
+
* ```
|
|
1152
|
+
*/ // @__NO_SIDE_EFFECTS__
|
|
1126
1153
|
function EagerInstantiate(target) {
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
appliedBy: "EagerInstantiate"
|
|
1140
|
-
};
|
|
1154
|
+
const metadata = getMetadata(target);
|
|
1155
|
+
const currentScope = metadata.scope;
|
|
1156
|
+
check(!currentScope || currentScope.value === "Container", ()=>{
|
|
1157
|
+
const { value, appliedBy } = currentScope;
|
|
1158
|
+
const by = appliedBy === "Scoped" ? `${appliedBy}(${value})` : appliedBy;
|
|
1159
|
+
const className = getTokenName(target);
|
|
1160
|
+
return `class ${className}: scope ${value} was already set by @${by},\n ` + `but @EagerInstantiate is trying to set a conflicting scope Container.\n ` + `Only one decorator should set the class scope, or all must use the same value.`;
|
|
1161
|
+
});
|
|
1162
|
+
metadata.eagerInstantiate = true;
|
|
1163
|
+
metadata.scope = {
|
|
1164
|
+
value: "Container",
|
|
1165
|
+
appliedBy: "EagerInstantiate"
|
|
1141
1166
|
};
|
|
1142
|
-
return target === undefined ? decorator : decorator(target);
|
|
1143
1167
|
}
|
|
1144
1168
|
|
|
1145
1169
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -1155,8 +1179,8 @@ function Inject(token) {
|
|
|
1155
1179
|
|
|
1156
1180
|
// @__NO_SIDE_EFFECTS__
|
|
1157
1181
|
function Injectable(...args) {
|
|
1158
|
-
return (
|
|
1159
|
-
const metadata = getMetadata(
|
|
1182
|
+
return (target)=>{
|
|
1183
|
+
const metadata = getMetadata(target);
|
|
1160
1184
|
const arg0 = args[0];
|
|
1161
1185
|
const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
|
|
1162
1186
|
const currentRef = metadata.tokenRef;
|
|
@@ -1249,20 +1273,55 @@ function OptionalAll(token) {
|
|
|
1249
1273
|
};
|
|
1250
1274
|
}
|
|
1251
1275
|
|
|
1252
|
-
|
|
1276
|
+
/**
|
|
1277
|
+
* Class decorator that registers the decorated type with the **Container** scope.
|
|
1278
|
+
*
|
|
1279
|
+
* Use this scope when you want one cached instance per container,
|
|
1280
|
+
* with parent-container lookup fallback.
|
|
1281
|
+
*
|
|
1282
|
+
* Example:
|
|
1283
|
+
* ```ts
|
|
1284
|
+
* @ContainerScoped
|
|
1285
|
+
* class Wizard {
|
|
1286
|
+
* // ...
|
|
1287
|
+
* }
|
|
1288
|
+
* ```
|
|
1289
|
+
*/ // @__NO_SIDE_EFFECTS__
|
|
1253
1290
|
function ContainerScoped(target) {
|
|
1254
|
-
|
|
1255
|
-
return target === undefined ? decorator : decorator(target);
|
|
1291
|
+
scoped(target, "Container", "ContainerScoped");
|
|
1256
1292
|
}
|
|
1257
|
-
|
|
1293
|
+
/**
|
|
1294
|
+
* Class decorator that registers the decorated type with the **Resolution** scope.
|
|
1295
|
+
*
|
|
1296
|
+
* Use this scope when you want one cached instance per resolution graph,
|
|
1297
|
+
* so repeated resolutions within the same request reuse the same value.
|
|
1298
|
+
*
|
|
1299
|
+
* Example:
|
|
1300
|
+
* ```ts
|
|
1301
|
+
* @ResolutionScoped
|
|
1302
|
+
* class Wand {
|
|
1303
|
+
* // ...
|
|
1304
|
+
* }
|
|
1305
|
+
* ```
|
|
1306
|
+
*/ // @__NO_SIDE_EFFECTS__
|
|
1258
1307
|
function ResolutionScoped(target) {
|
|
1259
|
-
|
|
1260
|
-
return target === undefined ? decorator : decorator(target);
|
|
1308
|
+
scoped(target, "Resolution", "ResolutionScoped");
|
|
1261
1309
|
}
|
|
1262
|
-
|
|
1310
|
+
/**
|
|
1311
|
+
* Class decorator that registers the decorated type with the **Transient** scope.
|
|
1312
|
+
*
|
|
1313
|
+
* Use this scope when you want a fresh instance every time the class is resolved.
|
|
1314
|
+
*
|
|
1315
|
+
* Example:
|
|
1316
|
+
* ```ts
|
|
1317
|
+
* @TransientScoped
|
|
1318
|
+
* class Wand {
|
|
1319
|
+
* // ...
|
|
1320
|
+
* }
|
|
1321
|
+
* ```
|
|
1322
|
+
*/ // @__NO_SIDE_EFFECTS__
|
|
1263
1323
|
function TransientScoped(target) {
|
|
1264
|
-
|
|
1265
|
-
return target === undefined ? decorator : decorator(target);
|
|
1324
|
+
scoped(target, "Transient", "TransientScoped");
|
|
1266
1325
|
}
|
|
1267
1326
|
/**
|
|
1268
1327
|
* Class decorator for setting the scope of the decorated type when registering it.
|
|
@@ -1285,22 +1344,20 @@ function TransientScoped(target) {
|
|
|
1285
1344
|
* ```
|
|
1286
1345
|
*/ // @__NO_SIDE_EFFECTS__
|
|
1287
1346
|
function Scoped(scope) {
|
|
1288
|
-
return scoped(scope, "Scoped");
|
|
1289
|
-
}
|
|
1290
|
-
function scoped(scope, decorator) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
appliedBy: decorator
|
|
1303
|
-
};
|
|
1347
|
+
return (target)=>scoped(target, scope, "Scoped");
|
|
1348
|
+
}
|
|
1349
|
+
function scoped(target, scope, decorator) {
|
|
1350
|
+
const metadata = getMetadata(target);
|
|
1351
|
+
const currentScope = metadata.scope;
|
|
1352
|
+
check(!currentScope || currentScope.value === scope, ()=>{
|
|
1353
|
+
const { value, appliedBy } = currentScope;
|
|
1354
|
+
const by = appliedBy === "Scoped" ? `${appliedBy}(${value})` : appliedBy;
|
|
1355
|
+
const className = getTokenName(target);
|
|
1356
|
+
return `class ${className}: scope ${value} was already set by @${by},\n ` + `but @${decorator} is trying to set a conflicting scope ${scope}.\n ` + `Only one decorator should set the class scope, or all must use the same value.`;
|
|
1357
|
+
});
|
|
1358
|
+
metadata.scope = {
|
|
1359
|
+
value: scope,
|
|
1360
|
+
appliedBy: decorator
|
|
1304
1361
|
};
|
|
1305
1362
|
}
|
|
1306
1363
|
|