moost 0.5.16 → 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 +15 -4
- package/dist/index.d.ts +30 -3
- package/dist/index.mjs +14 -4
- package/package.json +2 -2
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,17 @@ function Replace(type, newType) {
|
|
|
749
751
|
function Inject(type) {
|
|
750
752
|
return getMoostMate().decorate('inject', type);
|
|
751
753
|
}
|
|
752
|
-
function
|
|
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 ? getInfactScopeVars(scopeId)?.[name] : getInfactScopeVars(scopeId);
|
|
761
|
+
}
|
|
762
|
+
return undefined;
|
|
763
|
+
});
|
|
764
|
+
}
|
|
755
765
|
|
|
756
766
|
function defineInterceptorFn(fn, priority = exports.TInterceptorPriority.INTERCEPTOR) {
|
|
757
767
|
fn.priority = priority;
|
|
@@ -1034,13 +1044,14 @@ exports.Const = Const;
|
|
|
1034
1044
|
exports.ConstFactory = ConstFactory;
|
|
1035
1045
|
exports.Controller = Controller;
|
|
1036
1046
|
exports.Description = Description;
|
|
1037
|
-
exports.FromScope = FromScope;
|
|
1038
1047
|
exports.Id = Id;
|
|
1039
1048
|
exports.ImportController = ImportController;
|
|
1040
1049
|
exports.Inherit = Inherit;
|
|
1041
1050
|
exports.Inject = Inject;
|
|
1042
1051
|
exports.InjectEventLogger = InjectEventLogger;
|
|
1052
|
+
exports.InjectFromScope = InjectFromScope;
|
|
1043
1053
|
exports.InjectMoostLogger = InjectMoostLogger;
|
|
1054
|
+
exports.InjectScopeVars = InjectScopeVars;
|
|
1044
1055
|
exports.Injectable = Injectable;
|
|
1045
1056
|
exports.Intercept = Intercept;
|
|
1046
1057
|
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
|
+
/**
|
|
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
|
+
*/
|
|
150
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
|
+
*/
|
|
151
163
|
declare function getInfactScopeVars(name: string | symbol): Record<string, unknown> | 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;
|
|
@@ -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
|
-
|
|
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,
|
|
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,17 @@ function Replace(type, newType) {
|
|
|
751
753
|
function Inject(type) {
|
|
752
754
|
return getMoostMate().decorate('inject', type);
|
|
753
755
|
}
|
|
754
|
-
function
|
|
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 ? getInfactScopeVars(scopeId)?.[name] : getInfactScopeVars(scopeId);
|
|
763
|
+
}
|
|
764
|
+
return undefined;
|
|
765
|
+
});
|
|
766
|
+
}
|
|
757
767
|
|
|
758
768
|
function defineInterceptorFn(fn, priority = TInterceptorPriority.INTERCEPTOR) {
|
|
759
769
|
fn.priority = priority;
|
|
@@ -979,4 +989,4 @@ class Moost extends Hookable {
|
|
|
979
989
|
}
|
|
980
990
|
}
|
|
981
991
|
|
|
982
|
-
export { Circular, Const, ConstFactory, Controller, Description,
|
|
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.
|
|
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.
|
|
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",
|