@zenofolio/hyper-decor 1.0.52 → 1.0.54
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/creators/routes.creator.d.ts +1 -1
- package/dist/__internals/creators/routes.creator.js +2 -1
- package/dist/__internals/helpers/prepare.helper.js +15 -11
- package/dist/decorators/Routes.d.ts +14 -13
- package/dist/decorators/Service.d.ts +5 -1
- package/dist/decorators/Service.js +5 -9
- package/dist/decorators/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -8,4 +8,4 @@ import { Request, Response } from "hyper-express";
|
|
|
8
8
|
* @returns {(path?: string) => MethodDecorator} - A method decorator for defining routes.
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
|
-
export default function createRouteDecorator(method: string, resolver?: (req: Request, res: Response) => any): (path?: string) => MethodDecorator & ClassDecorator;
|
|
11
|
+
export default function createRouteDecorator<T extends any = undefined>(method: string, resolver?: (req: Request, res: Response) => any): (path?: string, options?: T) => MethodDecorator & ClassDecorator;
|
|
@@ -13,7 +13,7 @@ const decorator_base_1 = require("../decorator-base");
|
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
15
|
function createRouteDecorator(method, resolver) {
|
|
16
|
-
return (path = "/") => (0, decorator_base_1.DecoratorHelper)({
|
|
16
|
+
return (path = "/", options) => (0, decorator_base_1.DecoratorHelper)({
|
|
17
17
|
type: constants_1.KEY_TYPE_CONTROLLER,
|
|
18
18
|
key: constants_1.KEY_PARAMS_ROUTE,
|
|
19
19
|
targetResolver: (target) => { var _a; return (_a = target.constructor) !== null && _a !== void 0 ? _a : target; },
|
|
@@ -32,6 +32,7 @@ function createRouteDecorator(method, resolver) {
|
|
|
32
32
|
path,
|
|
33
33
|
propertyKey,
|
|
34
34
|
handler: handler,
|
|
35
|
+
options,
|
|
35
36
|
});
|
|
36
37
|
return saved;
|
|
37
38
|
},
|
|
@@ -75,16 +75,7 @@ function prepareApplication(options, Target, app, log) {
|
|
|
75
75
|
const data = getData(Target);
|
|
76
76
|
const prefix = (_a = options.prefix) !== null && _a !== void 0 ? _a : "/";
|
|
77
77
|
const imports = (_b = options.imports) !== null && _b !== void 0 ? _b : [];
|
|
78
|
-
|
|
79
|
-
// initialize servies stored
|
|
80
|
-
for (const service of service_store_1.serviceStore) {
|
|
81
|
-
const instance = tsyringe_1.container.resolve(service);
|
|
82
|
-
if (instance.onInit)
|
|
83
|
-
yield instance.onInit();
|
|
84
|
-
}
|
|
85
|
-
// clean up the service store
|
|
86
|
-
service_store_1.serviceStore.clear();
|
|
87
|
-
}
|
|
78
|
+
yield prepareServices(service_store_1.serviceStore);
|
|
88
79
|
yield (0, imports_helper_1.prepareImports)(Target, imports);
|
|
89
80
|
if (data.middlewares.length) {
|
|
90
81
|
app.use(...data.middlewares);
|
|
@@ -218,7 +209,7 @@ function prepareTarget(_a) {
|
|
|
218
209
|
function prepareRoutes(_a) {
|
|
219
210
|
return __awaiter(this, arguments, void 0, function* ({ target, router, route, instance, namespace, log, }) {
|
|
220
211
|
var _b, _c, _d;
|
|
221
|
-
const { method, path, handler, propertyKey } = route;
|
|
212
|
+
const { method, path, handler, propertyKey, options } = route;
|
|
222
213
|
const metadata = getData(handler);
|
|
223
214
|
const params = (_d = (_c = (_b = metadata.params) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c[propertyKey]) !== null && _d !== void 0 ? _d : [];
|
|
224
215
|
const $fn = Reflect.get(router, method);
|
|
@@ -233,6 +224,10 @@ function prepareRoutes(_a) {
|
|
|
233
224
|
});
|
|
234
225
|
log("routes", `${namespace}/${propertyKey} ${method.toUpperCase()} { ${path} }`);
|
|
235
226
|
if (!hasParams) {
|
|
227
|
+
if (method === "ws" && options) {
|
|
228
|
+
router.ws(path, options, handler.bind(instance));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
236
231
|
$fn.call(router, path, ...middlewares, handler.bind(instance));
|
|
237
232
|
}
|
|
238
233
|
else {
|
|
@@ -246,3 +241,12 @@ function prepareRoutes(_a) {
|
|
|
246
241
|
}
|
|
247
242
|
});
|
|
248
243
|
}
|
|
244
|
+
function prepareServices(list) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
yield Promise.all(Array.from(list).map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
const instance = tsyringe_1.container.resolve(service);
|
|
248
|
+
if (instance.onInit)
|
|
249
|
+
yield instance.onInit();
|
|
250
|
+
})));
|
|
251
|
+
});
|
|
252
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
2
|
+
import { WSRouteOptions } from "hyper-express/types";
|
|
3
|
+
export declare const Get: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
4
|
+
export declare const Post: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
5
|
+
export declare const Put: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
6
|
+
export declare const Delete: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
7
|
+
export declare const Patch: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
8
|
+
export declare const Options: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
9
|
+
export declare const Head: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
10
|
+
export declare const Trace: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
11
|
+
export declare const Any: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
12
|
+
export declare const All: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
13
|
+
export declare const Connect: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
14
|
+
export declare const WS: (path?: string, options?: WSRouteOptions | undefined) => MethodDecorator & ClassDecorator;
|
|
15
|
+
export declare const Upgrade: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
@@ -3,18 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Service = void 0;
|
|
4
4
|
const tsyringe_1 = require("tsyringe");
|
|
5
5
|
const service_store_1 = require("../__internals/stores/service.store");
|
|
6
|
-
const Service = () => {
|
|
6
|
+
const Service = ({ singleton = true, } = {}) => {
|
|
7
7
|
return (target) => {
|
|
8
|
-
if (!service_store_1.serviceStore.has(target)) {
|
|
9
|
-
service_store_1.serviceStore.add(target);
|
|
10
|
-
}
|
|
11
|
-
const instance = tsyringe_1.container.resolve(target);
|
|
12
8
|
if (!tsyringe_1.container.isRegistered(target)) {
|
|
13
|
-
|
|
9
|
+
singleton
|
|
10
|
+
? tsyringe_1.container.registerSingleton(target)
|
|
11
|
+
: tsyringe_1.container.register(target, target);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
return instance;
|
|
17
|
-
};
|
|
13
|
+
service_store_1.serviceStore.add(target);
|
|
18
14
|
};
|
|
19
15
|
};
|
|
20
16
|
exports.Service = Service;
|