moost 0.5.16 → 0.5.18

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
@@ -91,12 +91,13 @@ function getNewMoostInfact() {
91
91
  scopeId: meta?.injectable === 'FOR_EVENT' ? eventCore.useEventId().getId() : undefined,
92
92
  };
93
93
  },
94
- resolveParam({ paramMeta, customData, classConstructor, index }) {
94
+ resolveParam({ paramMeta, customData, classConstructor, index, scopeId }) {
95
95
  if (paramMeta && customData?.pipes) {
96
96
  return runPipes(customData.pipes, undefined, {
97
97
  paramMeta,
98
98
  type: classConstructor,
99
99
  key: 'constructor',
100
+ scopeId,
100
101
  classMeta: getMoostMate().read(classConstructor),
101
102
  index,
102
103
  targetMeta: paramMeta,
@@ -107,12 +108,13 @@ function getNewMoostInfact() {
107
108
  const meta = getMoostMate().read(classConstructor, key);
108
109
  return meta;
109
110
  },
110
- resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
111
+ resolveProp({ instance, key, initialValue, propMeta, scopeId, classMeta, customData, classConstructor, }) {
111
112
  if (propMeta && customData?.pipes) {
112
113
  return runPipes(customData.pipes, initialValue, {
113
114
  instance,
114
115
  type: classConstructor,
115
116
  key,
117
+ scopeId,
116
118
  propMeta,
117
119
  targetMeta: propMeta,
118
120
  classMeta: classMeta,
@@ -749,9 +751,19 @@ function Replace(type, newType) {
749
751
  function Inject(type) {
750
752
  return getMoostMate().decorate('inject', type);
751
753
  }
752
- function FromScope(name) {
754
+ function InjectFromScope(name) {
753
755
  return getMoostMate().decorate('fromScope', name);
754
756
  }
757
+ function InjectScopeVars(name) {
758
+ return Resolve(({ scopeId }) => {
759
+ if (scopeId) {
760
+ return name
761
+ ? getInfactScopeVars(scopeId)?.[name]
762
+ : getInfactScopeVars(scopeId);
763
+ }
764
+ return undefined;
765
+ });
766
+ }
755
767
 
756
768
  function defineInterceptorFn(fn, priority = exports.TInterceptorPriority.INTERCEPTOR) {
757
769
  fn.priority = priority;
@@ -1034,13 +1046,14 @@ exports.Const = Const;
1034
1046
  exports.ConstFactory = ConstFactory;
1035
1047
  exports.Controller = Controller;
1036
1048
  exports.Description = Description;
1037
- exports.FromScope = FromScope;
1038
1049
  exports.Id = Id;
1039
1050
  exports.ImportController = ImportController;
1040
1051
  exports.Inherit = Inherit;
1041
1052
  exports.Inject = Inject;
1042
1053
  exports.InjectEventLogger = InjectEventLogger;
1054
+ exports.InjectFromScope = InjectFromScope;
1043
1055
  exports.InjectMoostLogger = InjectMoostLogger;
1056
+ exports.InjectScopeVars = InjectScopeVars;
1044
1057
  exports.Injectable = Injectable;
1045
1058
  exports.Intercept = Intercept;
1046
1059
  exports.InterceptorHandler = InterceptorHandler;
package/dist/index.d.ts CHANGED
@@ -147,8 +147,23 @@ declare function getMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata
147
147
  interface TCustom {
148
148
  pipes?: TPipeData[];
149
149
  }
150
- declare function defineInfactScope(name: string | symbol, scopeVars: Record<string, unknown>): void;
151
- declare function getInfactScopeVars(name: string | symbol): Record<string, unknown> | undefined;
150
+ /**
151
+ * Define global scope name to be used with `@InjectFromScope` and `@InjectScopeVars` decorators
152
+ *
153
+ * You can read scoped vars with `getInfactScopeVars`
154
+ * @param name scope name
155
+ * @param scopeVars key-value object as scoped vars
156
+ */
157
+ declare function defineInfactScope<T extends object>(name: string | symbol, scopeVars: T): void;
158
+ /**
159
+ * Read scoped vars defined with `defineInfactScope`
160
+ * @param name scope name
161
+ * @returns key-value object as scoped vars
162
+ */
163
+ declare function getInfactScopeVars<T extends object>(name: string | symbol): T | undefined;
164
+ /**
165
+ * Get Infact instance (used for Dependency Injections)
166
+ */
152
167
  declare function getNewMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
153
168
 
154
169
  interface TPipeMetas<T extends TObject = TEmpty> {
@@ -158,6 +173,7 @@ interface TPipeMetas<T extends TObject = TEmpty> {
158
173
  paramMeta?: TMoostParamsMetadata & T;
159
174
  targetMeta?: TMoostParamsMetadata & T;
160
175
  instance?: TObject;
176
+ scopeId?: string | symbol;
161
177
  type: TFunction;
162
178
  index?: number;
163
179
  key: string | symbol;
@@ -289,7 +305,7 @@ declare function Pipe(handler: TPipeFn, priority?: TPipePriority): ClassDecorato
289
305
  * @param type - string or class constructor
290
306
  * @param fn - factory function for provided value
291
307
  */
292
- declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
308
+ declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator & ParameterDecorator & PropertyDecorator;
293
309
  /**
294
310
  * ## Replace
295
311
  * ### @Decorator
@@ -305,8 +321,19 @@ declare function Replace(type: TClassConstructor, newType: TClassConstructor): C
305
321
  * (For optional values use with @Optional())
306
322
  * @param type - string or class constructor
307
323
  */
308
- declare function Inject(type: string | TClassConstructor): ParameterDecorator;
309
- declare function FromScope(name: string | symbol): ParameterDecorator;
324
+ declare function Inject(type: string | TClassConstructor): ParameterDecorator & PropertyDecorator;
325
+ /**
326
+ * Injects instance from scope
327
+ *
328
+ * (scope must be defined by `defineInfactScope` fn)
329
+ * @param name scope name
330
+ */
331
+ declare function InjectFromScope(name: string | symbol): ParameterDecorator & PropertyDecorator;
332
+ /**
333
+ * Inject vars from scope for instances
334
+ * instantiated with `@InjectFromScope` decorator
335
+ */
336
+ declare function InjectScopeVars(name?: string): ParameterDecorator & PropertyDecorator;
310
337
 
311
338
  /**
312
339
  * Hook to the Response Status
@@ -663,4 +690,4 @@ type TInterceptorClass = TClassFunction<TInterceptorFn>;
663
690
  */
664
691
  declare function definePipeFn<T extends TObject = TEmpty>(fn: TPipeFn<T>, priority?: TPipePriority): TPipeFn<T>;
665
692
 
666
- export { Circular, Const, ConstFactory, Controller, Description, FromScope, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectMoostLogger, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, Provide, Replace, Required, Resolve, type TCallableClassFunction, type TClassConstructor, type TClassFunction, type TContextInjectorHook, type TControllerOverview, type TInjectableScope, type TInterceptorAfter, type TInterceptorBefore, type TInterceptorClass, type TInterceptorData, type TInterceptorFn, type TInterceptorOnError, TInterceptorPriority, type TMoostAdapter, type TMoostAdapterOptions, type TMoostEventHandlerHookOptions, type TMoostEventHandlerOptions, type TMoostHandler, type TMoostMetadata, type TMoostOptions, type TMoostParamsMetadata, type TPipeData, type TPipeFn, type TPipeMetas, TPipePriority, Value, defineInfactScope, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getInfactScopeVars, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, setInfactLoggingOptions, useControllerContext };
693
+ export { Circular, Const, ConstFactory, Controller, Description, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectFromScope, InjectMoostLogger, InjectScopeVars, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, Provide, Replace, Required, Resolve, type TCallableClassFunction, type TClassConstructor, type TClassFunction, type TContextInjectorHook, type TControllerOverview, type TInjectableScope, type TInterceptorAfter, type TInterceptorBefore, type TInterceptorClass, type TInterceptorData, type TInterceptorFn, type TInterceptorOnError, TInterceptorPriority, type TMoostAdapter, type TMoostAdapterOptions, type TMoostEventHandlerHookOptions, type TMoostEventHandlerOptions, type TMoostHandler, type TMoostMetadata, type TMoostOptions, type TMoostParamsMetadata, type TPipeData, type TPipeFn, type TPipeMetas, TPipePriority, Value, defineInfactScope, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getInfactScopeVars, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, setInfactLoggingOptions, useControllerContext };
package/dist/index.mjs CHANGED
@@ -93,12 +93,13 @@ function getNewMoostInfact() {
93
93
  scopeId: meta?.injectable === 'FOR_EVENT' ? useEventId().getId() : undefined,
94
94
  };
95
95
  },
96
- resolveParam({ paramMeta, customData, classConstructor, index }) {
96
+ resolveParam({ paramMeta, customData, classConstructor, index, scopeId }) {
97
97
  if (paramMeta && customData?.pipes) {
98
98
  return runPipes(customData.pipes, undefined, {
99
99
  paramMeta,
100
100
  type: classConstructor,
101
101
  key: 'constructor',
102
+ scopeId,
102
103
  classMeta: getMoostMate().read(classConstructor),
103
104
  index,
104
105
  targetMeta: paramMeta,
@@ -109,12 +110,13 @@ function getNewMoostInfact() {
109
110
  const meta = getMoostMate().read(classConstructor, key);
110
111
  return meta;
111
112
  },
112
- resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
113
+ resolveProp({ instance, key, initialValue, propMeta, scopeId, classMeta, customData, classConstructor, }) {
113
114
  if (propMeta && customData?.pipes) {
114
115
  return runPipes(customData.pipes, initialValue, {
115
116
  instance,
116
117
  type: classConstructor,
117
118
  key,
119
+ scopeId,
118
120
  propMeta,
119
121
  targetMeta: propMeta,
120
122
  classMeta: classMeta,
@@ -751,9 +753,19 @@ function Replace(type, newType) {
751
753
  function Inject(type) {
752
754
  return getMoostMate().decorate('inject', type);
753
755
  }
754
- function FromScope(name) {
756
+ function InjectFromScope(name) {
755
757
  return getMoostMate().decorate('fromScope', name);
756
758
  }
759
+ function InjectScopeVars(name) {
760
+ return Resolve(({ scopeId }) => {
761
+ if (scopeId) {
762
+ return name
763
+ ? getInfactScopeVars(scopeId)?.[name]
764
+ : getInfactScopeVars(scopeId);
765
+ }
766
+ return undefined;
767
+ });
768
+ }
757
769
 
758
770
  function defineInterceptorFn(fn, priority = TInterceptorPriority.INTERCEPTOR) {
759
771
  fn.priority = priority;
@@ -979,4 +991,4 @@ class Moost extends Hookable {
979
991
  }
980
992
  }
981
993
 
982
- export { Circular, Const, ConstFactory, Controller, Description, FromScope, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectMoostLogger, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, Provide, Replace, Required, Resolve, TInterceptorPriority, TPipePriority, Value, defineInfactScope, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getInfactScopeVars, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, setInfactLoggingOptions, useControllerContext };
994
+ export { Circular, Const, ConstFactory, Controller, Description, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectFromScope, InjectMoostLogger, InjectScopeVars, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, Provide, Replace, Required, Resolve, TInterceptorPriority, TPipePriority, Value, defineInfactScope, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getInfactScopeVars, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, setInfactLoggingOptions, useControllerContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moost",
3
- "version": "0.5.16",
3
+ "version": "0.5.18",
4
4
  "description": "moost",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "prostojs"
32
32
  ],
33
33
  "dependencies": {
34
- "@prostojs/infact": "^0.3.1",
34
+ "@prostojs/infact": "^0.3.3",
35
35
  "@prostojs/mate": "^0.3.3",
36
36
  "@prostojs/logger": "^0.4.3",
37
37
  "@wooksjs/event-core": "^0.5.20",