moost 0.2.18 → 0.2.19

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/index.cjs CHANGED
@@ -358,6 +358,16 @@ function Params() {
358
358
  function Const(value, label) {
359
359
  return Resolve(() => value, label);
360
360
  }
361
+ /**
362
+ * Provide Const Value from Factory fn
363
+ * @decorator
364
+ * @param factory - value Factory fn
365
+ * @param label - label of the field
366
+ * @paramType unknown
367
+ */
368
+ function ConstFactory(factory, label) {
369
+ return Resolve(() => __awaiter(this, void 0, void 0, function* () { return yield factory(); }), label);
370
+ }
361
371
  function fillLabel(target, key, index, name) {
362
372
  if (name) {
363
373
  const meta = getMoostMate().read(target, key);
@@ -429,6 +439,11 @@ function Intercept(handler, priority) {
429
439
  }, true);
430
440
  }
431
441
 
442
+ /**
443
+ * Defines provide registry for class (and all the children)
444
+ * @param type - string or class constructor
445
+ * @param fn - factory function for provided value
446
+ */
432
447
  function Provide(type, fn) {
433
448
  return getMoostMate().decorate(meta => {
434
449
  meta.provide = meta.provide || {};
@@ -436,8 +451,20 @@ function Provide(type, fn) {
436
451
  return meta;
437
452
  });
438
453
  }
454
+ /**
455
+ * Defines a key from provide registry to inject value
456
+ * (For optional values use with @Nullable())
457
+ * @param type - string or class constructor
458
+ */
439
459
  function Inject(type) {
440
460
  return getMoostMate().decorate('inject', type);
461
+ }
462
+ /**
463
+ * Makes injectable value optional
464
+ * @param value default true
465
+ */
466
+ function Nullable(v = true) {
467
+ return getMoostMate().decorate('nullable', v);
441
468
  }
442
469
 
443
470
  function Dto(dtoOptions = {}) {
@@ -796,6 +823,7 @@ const validatePipe = (opts) => {
796
823
 
797
824
  exports.Circular = Circular;
798
825
  exports.Const = Const;
826
+ exports.ConstFactory = ConstFactory;
799
827
  exports.Controller = Controller;
800
828
  exports.Dto = Dto;
801
829
  exports.Id = Id;
@@ -812,6 +840,7 @@ exports.IsString = IsString;
812
840
  exports.IsTypeOf = IsTypeOf;
813
841
  exports.Label = Label;
814
842
  exports.Moost = Moost;
843
+ exports.Nullable = Nullable;
815
844
  exports.Optional = Optional;
816
845
  exports.Param = Param;
817
846
  exports.Params = Params;
package/dist/index.d.ts CHANGED
@@ -17,7 +17,16 @@ export declare function Circular<T = unknown>(resolver: () => TClassConstructor<
17
17
  * @param label - label of the field
18
18
  * @paramType unknown
19
19
  */
20
- export declare function Const(value: unknown, label?: string): ParameterDecorator & PropertyDecorator;
20
+ export declare function Const<T>(value: T, label?: string): ParameterDecorator & PropertyDecorator;
21
+
22
+ /**
23
+ * Provide Const Value from Factory fn
24
+ * @decorator
25
+ * @param factory - value Factory fn
26
+ * @param label - label of the field
27
+ * @paramType unknown
28
+ */
29
+ export declare function ConstFactory<T>(factory: () => T | Promise<T>, label?: string): ParameterDecorator & PropertyDecorator;
21
30
 
22
31
  /**
23
32
  * Set Class as a Controller
@@ -57,6 +66,11 @@ export declare function ImportController(prefix: string, controller: TFunction |
57
66
 
58
67
  export declare const Inherit: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
59
68
 
69
+ /**
70
+ * Defines a key from provide registry to inject value
71
+ * (For optional values use with @Nullable())
72
+ * @param type - string or class constructor
73
+ */
60
74
  export declare function Inject(type: string | TClassConstructor): ParameterDecorator;
61
75
 
62
76
  /**
@@ -125,6 +139,12 @@ export declare class Moost {
125
139
  registerControllers(...controllers: (TObject | TFunction)[]): this;
126
140
  }
127
141
 
142
+ /**
143
+ * Makes injectable value optional
144
+ * @param value default true
145
+ */
146
+ export declare function Nullable(v?: boolean): ParameterDecorator;
147
+
128
148
  export declare function Optional(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
129
149
 
130
150
  /**
@@ -142,6 +162,11 @@ export declare function Param(name: string): ParameterDecorator & PropertyDecora
142
162
  */
143
163
  export declare function Params(): ParameterDecorator & PropertyDecorator;
144
164
 
165
+ /**
166
+ * Defines provide registry for class (and all the children)
167
+ * @param type - string or class constructor
168
+ * @param fn - factory function for provided value
169
+ */
145
170
  export declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
146
171
 
147
172
  declare function Required_2(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
@@ -281,6 +306,7 @@ export declare interface TMoostOptions {
281
306
  export declare interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
282
307
  circular?: () => TAny;
283
308
  inject?: string | symbol | TClassConstructor;
309
+ nullable?: boolean;
284
310
  }
285
311
 
286
312
  declare type TObject = object;
package/dist/index.mjs CHANGED
@@ -356,6 +356,16 @@ function Params() {
356
356
  function Const(value, label) {
357
357
  return Resolve(() => value, label);
358
358
  }
359
+ /**
360
+ * Provide Const Value from Factory fn
361
+ * @decorator
362
+ * @param factory - value Factory fn
363
+ * @param label - label of the field
364
+ * @paramType unknown
365
+ */
366
+ function ConstFactory(factory, label) {
367
+ return Resolve(() => __awaiter(this, void 0, void 0, function* () { return yield factory(); }), label);
368
+ }
359
369
  function fillLabel(target, key, index, name) {
360
370
  if (name) {
361
371
  const meta = getMoostMate().read(target, key);
@@ -427,6 +437,11 @@ function Intercept(handler, priority) {
427
437
  }, true);
428
438
  }
429
439
 
440
+ /**
441
+ * Defines provide registry for class (and all the children)
442
+ * @param type - string or class constructor
443
+ * @param fn - factory function for provided value
444
+ */
430
445
  function Provide(type, fn) {
431
446
  return getMoostMate().decorate(meta => {
432
447
  meta.provide = meta.provide || {};
@@ -434,8 +449,20 @@ function Provide(type, fn) {
434
449
  return meta;
435
450
  });
436
451
  }
452
+ /**
453
+ * Defines a key from provide registry to inject value
454
+ * (For optional values use with @Nullable())
455
+ * @param type - string or class constructor
456
+ */
437
457
  function Inject(type) {
438
458
  return getMoostMate().decorate('inject', type);
459
+ }
460
+ /**
461
+ * Makes injectable value optional
462
+ * @param value default true
463
+ */
464
+ function Nullable(v = true) {
465
+ return getMoostMate().decorate('nullable', v);
439
466
  }
440
467
 
441
468
  function Dto(dtoOptions = {}) {
@@ -792,4 +819,4 @@ const validatePipe = (opts) => {
792
819
  return pipe;
793
820
  };
794
821
 
795
- export { Circular, Const, Controller, Dto, Id, ImportController, Inherit, Inject, Injectable, Intercept, InterceptorHandler, IsArray, IsBoolean, IsNumber, IsString, IsTypeOf, Label, Moost, Optional, Param, Params, Provide, Required, Resolve, TInterceptorPriority, TPipePriority, Validate, genericTypesCastPipe, getMoostInfact, getMoostMate, getNewMoostInfact, resolvePipe, validatePipe };
822
+ export { Circular, Const, ConstFactory, Controller, Dto, Id, ImportController, Inherit, Inject, Injectable, Intercept, InterceptorHandler, IsArray, IsBoolean, IsNumber, IsString, IsTypeOf, Label, Moost, Nullable, Optional, Param, Params, Provide, Required, Resolve, TInterceptorPriority, TPipePriority, Validate, genericTypesCastPipe, getMoostInfact, getMoostMate, getNewMoostInfact, resolvePipe, validatePipe };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "moost",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -22,7 +22,7 @@
22
22
  "prostojs"
23
23
  ],
24
24
  "dependencies": {
25
- "@prostojs/infact": "^0.1.7",
25
+ "@prostojs/infact": "^0.1.8",
26
26
  "@prostojs/mate": "^0.1.13",
27
27
  "@prostojs/valido": "^0.0.2",
28
28
  "@wooksjs/event-core": "^0.2.12",