@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.
@@ -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/cjs/index.js CHANGED
@@ -1115,33 +1115,57 @@ function isDisposable(value) {
1115
1115
  return new ContainerImpl(undefined, options);
1116
1116
  }
1117
1117
 
1118
- // @__NO_SIDE_EFFECTS__
1118
+ /**
1119
+ * Class decorator that enables auto-registration of an unregistered class
1120
+ * when the class is first resolved from the container.
1121
+ *
1122
+ * Example:
1123
+ * ```ts
1124
+ * @AutoRegister
1125
+ * class Wizard {}
1126
+ *
1127
+ * const wizard = container.resolve(Wizard);
1128
+ * container.isRegistered(Wizard); // => true
1129
+ * ```
1130
+ */ // @__NO_SIDE_EFFECTS__
1119
1131
  function AutoRegister(target) {
1120
- const decorator = (Class)=>{
1121
- const metadata = getMetadata(Class);
1122
- metadata.autoRegister = true;
1123
- };
1124
- return target === undefined ? decorator : decorator(target);
1132
+ const metadata = getMetadata(target);
1133
+ metadata.autoRegister = true;
1125
1134
  }
1126
1135
 
1127
- // @__NO_SIDE_EFFECTS__
1136
+ /**
1137
+ * Class decorator that sets the class scope to **Container** and enables
1138
+ * eager instantiation when the class is registered in the container.
1139
+ *
1140
+ * This causes the container to create and cache the instance of the class
1141
+ * immediately, instead of deferring it until the first resolution.
1142
+ *
1143
+ * If the class cannot be resolved at registration time, registration fails.
1144
+ *
1145
+ * Example:
1146
+ * ```ts
1147
+ * @EagerInstantiate
1148
+ * class Wizard {}
1149
+ *
1150
+ * // Wizard is registered with Container scope, and an instance
1151
+ * // is created and cached immediately by the container
1152
+ * container.register(Wizard);
1153
+ * ```
1154
+ */ // @__NO_SIDE_EFFECTS__
1128
1155
  function EagerInstantiate(target) {
1129
- const decorator = (Class)=>{
1130
- const metadata = getMetadata(Class);
1131
- const currentScope = metadata.scope;
1132
- check(!currentScope || currentScope.value === "Container", ()=>{
1133
- const { value, appliedBy } = currentScope;
1134
- const by = appliedBy === "Scoped" ? `${appliedBy}(${value})` : appliedBy;
1135
- const className = getTokenName(Class);
1136
- 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.`;
1137
- });
1138
- metadata.eagerInstantiate = true;
1139
- metadata.scope = {
1140
- value: "Container",
1141
- appliedBy: "EagerInstantiate"
1142
- };
1156
+ const metadata = getMetadata(target);
1157
+ const currentScope = metadata.scope;
1158
+ check(!currentScope || currentScope.value === "Container", ()=>{
1159
+ const { value, appliedBy } = currentScope;
1160
+ const by = appliedBy === "Scoped" ? `${appliedBy}(${value})` : appliedBy;
1161
+ const className = getTokenName(target);
1162
+ 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.`;
1163
+ });
1164
+ metadata.eagerInstantiate = true;
1165
+ metadata.scope = {
1166
+ value: "Container",
1167
+ appliedBy: "EagerInstantiate"
1143
1168
  };
1144
- return target === undefined ? decorator : decorator(target);
1145
1169
  }
1146
1170
 
1147
1171
  // @__NO_SIDE_EFFECTS__
@@ -1157,8 +1181,8 @@ function Inject(token) {
1157
1181
 
1158
1182
  // @__NO_SIDE_EFFECTS__
1159
1183
  function Injectable(...args) {
1160
- return (Class)=>{
1161
- const metadata = getMetadata(Class);
1184
+ return (target)=>{
1185
+ const metadata = getMetadata(target);
1162
1186
  const arg0 = args[0];
1163
1187
  const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
1164
1188
  const currentRef = metadata.tokenRef;
@@ -1251,20 +1275,55 @@ function OptionalAll(token) {
1251
1275
  };
1252
1276
  }
1253
1277
 
1254
- // @__NO_SIDE_EFFECTS__
1278
+ /**
1279
+ * Class decorator that registers the decorated type with the **Container** scope.
1280
+ *
1281
+ * Use this scope when you want one cached instance per container,
1282
+ * with parent-container lookup fallback.
1283
+ *
1284
+ * Example:
1285
+ * ```ts
1286
+ * @ContainerScoped
1287
+ * class Wizard {
1288
+ * // ...
1289
+ * }
1290
+ * ```
1291
+ */ // @__NO_SIDE_EFFECTS__
1255
1292
  function ContainerScoped(target) {
1256
- const decorator = scoped("Container", "ContainerScoped");
1257
- return target === undefined ? decorator : decorator(target);
1293
+ scoped(target, "Container", "ContainerScoped");
1258
1294
  }
1259
- // @__NO_SIDE_EFFECTS__
1295
+ /**
1296
+ * Class decorator that registers the decorated type with the **Resolution** scope.
1297
+ *
1298
+ * Use this scope when you want one cached instance per resolution graph,
1299
+ * so repeated resolutions within the same request reuse the same value.
1300
+ *
1301
+ * Example:
1302
+ * ```ts
1303
+ * @ResolutionScoped
1304
+ * class Wand {
1305
+ * // ...
1306
+ * }
1307
+ * ```
1308
+ */ // @__NO_SIDE_EFFECTS__
1260
1309
  function ResolutionScoped(target) {
1261
- const decorator = scoped("Resolution", "ResolutionScoped");
1262
- return target === undefined ? decorator : decorator(target);
1310
+ scoped(target, "Resolution", "ResolutionScoped");
1263
1311
  }
1264
- // @__NO_SIDE_EFFECTS__
1312
+ /**
1313
+ * Class decorator that registers the decorated type with the **Transient** scope.
1314
+ *
1315
+ * Use this scope when you want a fresh instance every time the class is resolved.
1316
+ *
1317
+ * Example:
1318
+ * ```ts
1319
+ * @TransientScoped
1320
+ * class Wand {
1321
+ * // ...
1322
+ * }
1323
+ * ```
1324
+ */ // @__NO_SIDE_EFFECTS__
1265
1325
  function TransientScoped(target) {
1266
- const decorator = scoped("Transient", "TransientScoped");
1267
- return target === undefined ? decorator : decorator(target);
1326
+ scoped(target, "Transient", "TransientScoped");
1268
1327
  }
1269
1328
  /**
1270
1329
  * Class decorator for setting the scope of the decorated type when registering it.
@@ -1287,22 +1346,20 @@ function TransientScoped(target) {
1287
1346
  * ```
1288
1347
  */ // @__NO_SIDE_EFFECTS__
1289
1348
  function Scoped(scope) {
1290
- return scoped(scope, "Scoped");
1291
- }
1292
- function scoped(scope, decorator) {
1293
- return (Class)=>{
1294
- const metadata = getMetadata(Class);
1295
- const currentScope = metadata.scope;
1296
- check(!currentScope || currentScope.value === scope, ()=>{
1297
- const { value, appliedBy } = currentScope;
1298
- const by = appliedBy === "Scoped" ? `${appliedBy}(${value})` : appliedBy;
1299
- const className = getTokenName(Class);
1300
- 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.`;
1301
- });
1302
- metadata.scope = {
1303
- value: scope,
1304
- appliedBy: decorator
1305
- };
1349
+ return (target)=>scoped(target, scope, "Scoped");
1350
+ }
1351
+ function scoped(target, scope, decorator) {
1352
+ const metadata = getMetadata(target);
1353
+ const currentScope = metadata.scope;
1354
+ check(!currentScope || currentScope.value === scope, ()=>{
1355
+ const { value, appliedBy } = currentScope;
1356
+ const by = appliedBy === "Scoped" ? `${appliedBy}(${value})` : appliedBy;
1357
+ const className = getTokenName(target);
1358
+ 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.`;
1359
+ });
1360
+ metadata.scope = {
1361
+ value: scope,
1362
+ appliedBy: decorator
1306
1363
  };
1307
1364
  }
1308
1365