moost 0.5.15 → 0.5.17

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
@@ -70,6 +70,14 @@ function setInfactLoggingOptions(options) {
70
70
  function getMoostInfact() {
71
71
  return sharedMoostInfact;
72
72
  }
73
+ const scopeVarsMap = new Map();
74
+ function defineInfactScope(name, scopeVars) {
75
+ scopeVarsMap.set(name, scopeVars);
76
+ getMoostInfact().registerScope(name);
77
+ }
78
+ function getInfactScopeVars(name) {
79
+ return scopeVarsMap.get(name);
80
+ }
73
81
  function getNewMoostInfact() {
74
82
  return new infact$1.Infact({
75
83
  describeClass(classConstructor) {
@@ -83,12 +91,13 @@ function getNewMoostInfact() {
83
91
  scopeId: meta?.injectable === 'FOR_EVENT' ? eventCore.useEventId().getId() : undefined,
84
92
  };
85
93
  },
86
- resolveParam({ paramMeta, customData, classConstructor, index }) {
94
+ resolveParam({ paramMeta, customData, classConstructor, index, scopeId }) {
87
95
  if (paramMeta && customData?.pipes) {
88
96
  return runPipes(customData.pipes, undefined, {
89
97
  paramMeta,
90
98
  type: classConstructor,
91
99
  key: 'constructor',
100
+ scopeId,
92
101
  classMeta: getMoostMate().read(classConstructor),
93
102
  index,
94
103
  targetMeta: paramMeta,
@@ -99,12 +108,13 @@ function getNewMoostInfact() {
99
108
  const meta = getMoostMate().read(classConstructor, key);
100
109
  return meta;
101
110
  },
102
- resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
111
+ resolveProp({ instance, key, initialValue, propMeta, scopeId, classMeta, customData, classConstructor, }) {
103
112
  if (propMeta && customData?.pipes) {
104
113
  return runPipes(customData.pipes, initialValue, {
105
114
  instance,
106
115
  type: classConstructor,
107
116
  key,
117
+ scopeId,
108
118
  propMeta,
109
119
  targetMeta: propMeta,
110
120
  classMeta: classMeta,
@@ -741,6 +751,17 @@ function Replace(type, newType) {
741
751
  function Inject(type) {
742
752
  return getMoostMate().decorate('inject', type);
743
753
  }
754
+ function InjectFromScope(name) {
755
+ return getMoostMate().decorate('fromScope', name);
756
+ }
757
+ function InjectScopeVars(name) {
758
+ return Resolve(({ scopeId }) => {
759
+ if (scopeId) {
760
+ return name ? getInfactScopeVars(scopeId)?.[name] : getInfactScopeVars(scopeId);
761
+ }
762
+ return undefined;
763
+ });
764
+ }
744
765
 
745
766
  function defineInterceptorFn(fn, priority = exports.TInterceptorPriority.INTERCEPTOR) {
746
767
  fn.priority = priority;
@@ -1028,7 +1049,9 @@ exports.ImportController = ImportController;
1028
1049
  exports.Inherit = Inherit;
1029
1050
  exports.Inject = Inject;
1030
1051
  exports.InjectEventLogger = InjectEventLogger;
1052
+ exports.InjectFromScope = InjectFromScope;
1031
1053
  exports.InjectMoostLogger = InjectMoostLogger;
1054
+ exports.InjectScopeVars = InjectScopeVars;
1032
1055
  exports.Injectable = Injectable;
1033
1056
  exports.Intercept = Intercept;
1034
1057
  exports.InterceptorHandler = InterceptorHandler;
@@ -1044,9 +1067,11 @@ exports.Replace = Replace;
1044
1067
  exports.Required = Required;
1045
1068
  exports.Resolve = Resolve;
1046
1069
  exports.Value = Value;
1070
+ exports.defineInfactScope = defineInfactScope;
1047
1071
  exports.defineInterceptorFn = defineInterceptorFn;
1048
1072
  exports.defineMoostEventHandler = defineMoostEventHandler;
1049
1073
  exports.definePipeFn = definePipeFn;
1074
+ exports.getInfactScopeVars = getInfactScopeVars;
1050
1075
  exports.getInstanceOwnMethods = getInstanceOwnMethods;
1051
1076
  exports.getInstanceOwnProps = getInstanceOwnProps;
1052
1077
  exports.getMoostInfact = getMoostInfact;
package/dist/index.d.ts CHANGED
@@ -147,6 +147,23 @@ declare function getMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata
147
147
  interface TCustom {
148
148
  pipes?: TPipeData[];
149
149
  }
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(name: string | symbol, scopeVars: Record<string, unknown>): 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(name: string | symbol): Record<string, unknown> | undefined;
164
+ /**
165
+ * Get Infact instance (used for Dependency Injections)
166
+ */
150
167
  declare function getNewMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
151
168
 
152
169
  interface TPipeMetas<T extends TObject = TEmpty> {
@@ -156,6 +173,7 @@ interface TPipeMetas<T extends TObject = TEmpty> {
156
173
  paramMeta?: TMoostParamsMetadata & T;
157
174
  targetMeta?: TMoostParamsMetadata & T;
158
175
  instance?: TObject;
176
+ scopeId?: string | symbol;
159
177
  type: TFunction;
160
178
  index?: number;
161
179
  key: string | symbol;
@@ -208,6 +226,7 @@ interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
208
226
  nullable?: boolean;
209
227
  paramSource?: string;
210
228
  paramName?: string;
229
+ fromScope?: string | symbol;
211
230
  }
212
231
  type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
213
232
  type TMoostHandler<T> = {
@@ -302,7 +321,19 @@ declare function Replace(type: TClassConstructor, newType: TClassConstructor): C
302
321
  * (For optional values use with @Optional())
303
322
  * @param type - string or class constructor
304
323
  */
305
- declare function Inject(type: string | TClassConstructor): 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;
306
337
 
307
338
  /**
308
339
  * Hook to the Response Status
@@ -659,4 +690,4 @@ type TInterceptorClass = TClassFunction<TInterceptorFn>;
659
690
  */
660
691
  declare function definePipeFn<T extends TObject = TEmpty>(fn: TPipeFn<T>, priority?: TPipePriority): TPipeFn<T>;
661
692
 
662
- export { Circular, Const, ConstFactory, Controller, Description, 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, defineInterceptorFn, defineMoostEventHandler, definePipeFn, 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
@@ -72,6 +72,14 @@ function setInfactLoggingOptions(options) {
72
72
  function getMoostInfact() {
73
73
  return sharedMoostInfact;
74
74
  }
75
+ const scopeVarsMap = new Map();
76
+ function defineInfactScope(name, scopeVars) {
77
+ scopeVarsMap.set(name, scopeVars);
78
+ getMoostInfact().registerScope(name);
79
+ }
80
+ function getInfactScopeVars(name) {
81
+ return scopeVarsMap.get(name);
82
+ }
75
83
  function getNewMoostInfact() {
76
84
  return new Infact({
77
85
  describeClass(classConstructor) {
@@ -85,12 +93,13 @@ function getNewMoostInfact() {
85
93
  scopeId: meta?.injectable === 'FOR_EVENT' ? useEventId().getId() : undefined,
86
94
  };
87
95
  },
88
- resolveParam({ paramMeta, customData, classConstructor, index }) {
96
+ resolveParam({ paramMeta, customData, classConstructor, index, scopeId }) {
89
97
  if (paramMeta && customData?.pipes) {
90
98
  return runPipes(customData.pipes, undefined, {
91
99
  paramMeta,
92
100
  type: classConstructor,
93
101
  key: 'constructor',
102
+ scopeId,
94
103
  classMeta: getMoostMate().read(classConstructor),
95
104
  index,
96
105
  targetMeta: paramMeta,
@@ -101,12 +110,13 @@ function getNewMoostInfact() {
101
110
  const meta = getMoostMate().read(classConstructor, key);
102
111
  return meta;
103
112
  },
104
- resolveProp({ instance, key, initialValue, propMeta, classMeta, customData, classConstructor, }) {
113
+ resolveProp({ instance, key, initialValue, propMeta, scopeId, classMeta, customData, classConstructor, }) {
105
114
  if (propMeta && customData?.pipes) {
106
115
  return runPipes(customData.pipes, initialValue, {
107
116
  instance,
108
117
  type: classConstructor,
109
118
  key,
119
+ scopeId,
110
120
  propMeta,
111
121
  targetMeta: propMeta,
112
122
  classMeta: classMeta,
@@ -743,6 +753,17 @@ function Replace(type, newType) {
743
753
  function Inject(type) {
744
754
  return getMoostMate().decorate('inject', type);
745
755
  }
756
+ function InjectFromScope(name) {
757
+ return getMoostMate().decorate('fromScope', name);
758
+ }
759
+ function InjectScopeVars(name) {
760
+ return Resolve(({ scopeId }) => {
761
+ if (scopeId) {
762
+ return name ? getInfactScopeVars(scopeId)?.[name] : getInfactScopeVars(scopeId);
763
+ }
764
+ return undefined;
765
+ });
766
+ }
746
767
 
747
768
  function defineInterceptorFn(fn, priority = TInterceptorPriority.INTERCEPTOR) {
748
769
  fn.priority = priority;
@@ -968,4 +989,4 @@ class Moost extends Hookable {
968
989
  }
969
990
  }
970
991
 
971
- export { Circular, Const, ConstFactory, Controller, Description, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectMoostLogger, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, Provide, Replace, Required, Resolve, TInterceptorPriority, TPipePriority, Value, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, setInfactLoggingOptions, useControllerContext };
992
+ 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.15",
3
+ "version": "0.5.17",
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.0",
34
+ "@prostojs/infact": "^0.3.2",
35
35
  "@prostojs/mate": "^0.3.3",
36
36
  "@prostojs/logger": "^0.4.3",
37
37
  "@wooksjs/event-core": "^0.5.20",