@zenofolio/hyper-decor 0.0.3 → 1.0.41
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/__internals/transform/scope.transfrom.d.ts +2 -6
- package/dist/__internals/transform/scope.transfrom.js +1 -3
- package/dist/collectors/index.d.ts +1 -0
- package/dist/collectors/index.js +17 -0
- package/dist/collectors/scope.collector.d.ts +14 -0
- package/dist/collectors/scope.collector.js +29 -0
- package/dist/decorators/HyperApp.js +11 -4
- package/dist/decorators/types.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -5
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { MiddlewareHandler } from "hyper-express";
|
|
2
|
-
import { ScopeType } from "../../decorators";
|
|
3
|
-
export default function scopeTransfrom(listScopes: ScopeType[], callback?: (middleware: MiddlewareHandler, scopes:
|
|
4
|
-
scope: string;
|
|
5
|
-
description: string;
|
|
6
|
-
message: string | null;
|
|
7
|
-
}[], names: Set<string>) => void): MiddlewareHandler;
|
|
2
|
+
import { ScopeMap, ScopeType } from "../../decorators";
|
|
3
|
+
export default function scopeTransfrom(listScopes: ScopeType[], callback?: (middleware: MiddlewareHandler, scopes: ScopeMap[], names: Set<string>) => void): MiddlewareHandler;
|
|
@@ -39,7 +39,6 @@ const resolveScopes = (scopes) => {
|
|
|
39
39
|
$scopes[scope] = {
|
|
40
40
|
scope,
|
|
41
41
|
description: "",
|
|
42
|
-
message: null,
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
44
|
else if (Array.isArray(scope)) {
|
|
@@ -49,14 +48,13 @@ const resolveScopes = (scopes) => {
|
|
|
49
48
|
$scopes[s] = {
|
|
50
49
|
scope: s,
|
|
51
50
|
description: "",
|
|
52
|
-
message: null,
|
|
53
51
|
};
|
|
54
52
|
break;
|
|
55
53
|
case "object":
|
|
56
54
|
$scopes[s.scope] = {
|
|
57
55
|
scope: s.scope,
|
|
58
56
|
description: (_a = s.description) !== null && _a !== void 0 ? _a : "",
|
|
59
|
-
message: (_b = s.message) !== null && _b !== void 0 ? _b :
|
|
57
|
+
message: (_b = s.message) !== null && _b !== void 0 ? _b : `You don't have the required scopes to access this resource`,
|
|
60
58
|
};
|
|
61
59
|
break;
|
|
62
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./scope.collector";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./scope.collector"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ScopeMap } from "../decorators";
|
|
2
|
+
/**
|
|
3
|
+
* This class is a store for the scopes that are defined in the application.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class ScopeStore {
|
|
7
|
+
private static scopes;
|
|
8
|
+
static add(scope: ScopeMap): void;
|
|
9
|
+
static addAll(scopes: ScopeMap[]): void;
|
|
10
|
+
static getScopes(): ScopeMap[];
|
|
11
|
+
static getScopeNames(): string[];
|
|
12
|
+
static isEmpty(): boolean;
|
|
13
|
+
static clear(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeStore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This class is a store for the scopes that are defined in the application.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
class ScopeStore {
|
|
9
|
+
static add(scope) {
|
|
10
|
+
this.scopes.set(scope.scope, scope); // Evita duplicados basados en el nombre del scope
|
|
11
|
+
}
|
|
12
|
+
static addAll(scopes) {
|
|
13
|
+
scopes.forEach((scope) => this.add(scope));
|
|
14
|
+
}
|
|
15
|
+
static getScopes() {
|
|
16
|
+
return Array.from(this.scopes.values());
|
|
17
|
+
}
|
|
18
|
+
static getScopeNames() {
|
|
19
|
+
return Array.from(this.scopes.keys());
|
|
20
|
+
}
|
|
21
|
+
static isEmpty() {
|
|
22
|
+
return this.scopes.size === 0;
|
|
23
|
+
}
|
|
24
|
+
static clear() {
|
|
25
|
+
this.scopes.clear();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ScopeStore = ScopeStore;
|
|
29
|
+
ScopeStore.scopes = new Map();
|
|
@@ -23,6 +23,7 @@ const role_transform_1 = __importDefault(require("../__internals/transform/role.
|
|
|
23
23
|
const object_util_1 = require("../__internals/utils/object.util");
|
|
24
24
|
const merge_metadata_1 = require("../__internals/helpers/merge-metadata");
|
|
25
25
|
const tsyringe_1 = require("tsyringe");
|
|
26
|
+
const collectors_1 = require("../collectors");
|
|
26
27
|
/**
|
|
27
28
|
* Decorator to define the main application class with assigned modules.
|
|
28
29
|
* @param modules - List of modules to be used in the application.
|
|
@@ -133,9 +134,12 @@ function applyAppOptions(options, Target, app, log) {
|
|
|
133
134
|
const services = (_b = options.imports) !== null && _b !== void 0 ? _b : [];
|
|
134
135
|
if (data.middlewares.length) {
|
|
135
136
|
app.use(...data.middlewares);
|
|
136
|
-
log("middleware", `${Target.name} with middlewares: ${data.middlewares
|
|
137
|
+
log("middleware", `${Target.name} with middlewares: ${data.middlewares
|
|
138
|
+
.map((e) => e.name)
|
|
139
|
+
.join(", ")}`);
|
|
137
140
|
}
|
|
138
|
-
(0, scope_transfrom_1.default)(data.scopes, (middleware) => {
|
|
141
|
+
(0, scope_transfrom_1.default)(data.scopes, (middleware, scopes) => {
|
|
142
|
+
collectors_1.ScopeStore.addAll(scopes);
|
|
139
143
|
app.use(middleware);
|
|
140
144
|
log("middleware", `${Target.name} with scopes: ${data.scopes.join(", ")}`);
|
|
141
145
|
});
|
|
@@ -175,7 +179,10 @@ function prepareTarget(_a) {
|
|
|
175
179
|
/// Attach Middlewares
|
|
176
180
|
////////////////////////////////
|
|
177
181
|
_router.use(...middlewares);
|
|
178
|
-
(0, scope_transfrom_1.default)(scopes, (middleware) =>
|
|
182
|
+
(0, scope_transfrom_1.default)(scopes, (middleware, scopes) => {
|
|
183
|
+
collectors_1.ScopeStore.addAll(scopes);
|
|
184
|
+
_router.use(middleware);
|
|
185
|
+
});
|
|
179
186
|
(0, role_transform_1.default)(roles, (middleware) => _router.use(middleware));
|
|
180
187
|
////////////////////////////////
|
|
181
188
|
/// Prepare Modules
|
|
@@ -233,7 +240,7 @@ function prepareTarget(_a) {
|
|
|
233
240
|
});
|
|
234
241
|
}
|
|
235
242
|
function prepareRoutes(_a) {
|
|
236
|
-
return __awaiter(this, arguments, void 0, function* ({ target, router, route, instance, namespace,
|
|
243
|
+
return __awaiter(this, arguments, void 0, function* ({ target, router, route, instance, namespace, log, }) {
|
|
237
244
|
var _b, _c, _d;
|
|
238
245
|
const { method, path, handler, propertyKey } = route;
|
|
239
246
|
const metadata = getData(handler);
|
|
@@ -61,7 +61,7 @@ export type RoleMap<T> = {
|
|
|
61
61
|
* It can accept a single role, an array of roles, or a function that evaluates roles dynamically.
|
|
62
62
|
*/
|
|
63
63
|
export type RoleType<T extends string = string> = T | T[] | RoleMap<T> | RoleMap<T>[];
|
|
64
|
-
export type ScopeMap<T> = {
|
|
64
|
+
export type ScopeMap<T extends string = string> = {
|
|
65
65
|
scope: T;
|
|
66
66
|
description: string;
|
|
67
67
|
message?: string;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,4 +22,5 @@ __exportStar(require("./common/helpers"), exports);
|
|
|
22
22
|
__exportStar(require("./common/bootstrap"), exports);
|
|
23
23
|
__exportStar(require("hyper-express"), exports);
|
|
24
24
|
__exportStar(require("tsyringe"), exports);
|
|
25
|
+
__exportStar(require("./collectors"), exports);
|
|
25
26
|
__exportStar(require("./type"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenofolio/hyper-decor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.41",
|
|
4
4
|
"description": "Project core with utilities and features",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "zenozaga",
|
|
@@ -45,6 +45,10 @@
|
|
|
45
45
|
"node": "./dist/common/helpers/*.js",
|
|
46
46
|
"default": "./src/common/helpers/*.ts"
|
|
47
47
|
},
|
|
48
|
+
"./collectors/*": {
|
|
49
|
+
"node": "./dist/common/collectors/*.js",
|
|
50
|
+
"default": "./src/common/collectors/*.ts"
|
|
51
|
+
},
|
|
48
52
|
"./exceptions/*": {
|
|
49
53
|
"node": "./dist/common/exceptions/*.js",
|
|
50
54
|
"default": "./src/common/exceptions/*.ts"
|
|
@@ -52,10 +56,6 @@
|
|
|
52
56
|
"./extension": {
|
|
53
57
|
"node": "./dist/extension.js",
|
|
54
58
|
"default": "./src/extension.ts"
|
|
55
|
-
},
|
|
56
|
-
"./injector": {
|
|
57
|
-
"node": "./dist/injector.js",
|
|
58
|
-
"default": "./src/injector.ts"
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|