@zenofolio/hyper-decor 1.0.41 → 1.0.42
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.
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { MiddlewareHandler } from "hyper-express";
|
|
2
2
|
import { ScopeMap, ScopeType } from "../../decorators";
|
|
3
|
-
|
|
3
|
+
type Callback = (middleware: MiddlewareHandler, scopes: ScopeMap[], names: Set<string>) => void;
|
|
4
|
+
export default function scopeTransfrom(listScopes: ScopeType[], ...callback: Callback[]): MiddlewareHandler;
|
|
5
|
+
export {};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = scopeTransfrom;
|
|
4
4
|
const exeptions_1 = require("../../exeptions");
|
|
5
5
|
const helpers_1 = require("../../common/helpers");
|
|
6
|
-
function scopeTransfrom(listScopes, callback) {
|
|
6
|
+
function scopeTransfrom(listScopes, ...callback) {
|
|
7
7
|
const { scopes, scopeNames, isEmtpy } = resolveScopes(listScopes);
|
|
8
8
|
const middleware = (req, res, next) => {
|
|
9
9
|
var _a;
|
|
@@ -19,8 +19,9 @@ function scopeTransfrom(listScopes, callback) {
|
|
|
19
19
|
}
|
|
20
20
|
return next();
|
|
21
21
|
};
|
|
22
|
-
if (scopeNames.size > 0 && callback) {
|
|
23
|
-
|
|
22
|
+
if (scopeNames.size > 0 && callback && callback.length > 0) {
|
|
23
|
+
for (const cb of callback)
|
|
24
|
+
cb(middleware, scopes, scopeNames);
|
|
24
25
|
}
|
|
25
26
|
return middleware;
|
|
26
27
|
}
|
|
@@ -251,7 +251,10 @@ function prepareRoutes(_a) {
|
|
|
251
251
|
return;
|
|
252
252
|
const middlewares = [...metadata.middlewares];
|
|
253
253
|
(0, role_transform_1.default)(metadata.roles, (middleware) => middlewares.push(middleware));
|
|
254
|
-
(0, scope_transfrom_1.default)(metadata.scopes, (middleware) =>
|
|
254
|
+
(0, scope_transfrom_1.default)(metadata.scopes, (middleware, scopes) => {
|
|
255
|
+
middlewares.push(middleware);
|
|
256
|
+
collectors_1.ScopeStore.addAll(scopes);
|
|
257
|
+
});
|
|
255
258
|
log("routes", `${namespace}/${propertyKey} ${method.toUpperCase()} { ${path} }`);
|
|
256
259
|
if (!hasParams) {
|
|
257
260
|
$fn.call(router, path, ...middlewares, handler.bind(instance));
|