@venok/http 1.1.0 → 2.0.0
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/constants.js +33 -0
- package/dist/decorators/controller.decorator.js +45 -0
- package/dist/decorators/header.decorator.js +28 -0
- package/dist/decorators/http-code.decorator.js +22 -0
- package/dist/decorators/http-params.decorator.js +63 -0
- package/dist/decorators/method.decorator.js +57 -0
- package/dist/decorators/redirect.decorator.js +28 -0
- package/dist/decorators/version.decorator.js +31 -0
- package/dist/enums/method.enum.js +32 -0
- package/dist/enums/paramtypes.enum.js +33 -0
- package/dist/enums/status.enum.js +71 -0
- package/dist/enums/version-type.enum.js +27 -0
- package/dist/exceptions/bad-gateway.exception.js +29 -0
- package/dist/exceptions/bad-request.exception.js +29 -0
- package/dist/exceptions/conflict.exception.js +29 -0
- package/dist/exceptions/expectation-failed.exception.js +29 -0
- package/dist/exceptions/failed-dependency.exception.js +29 -0
- package/dist/exceptions/forbidden.exception.js +29 -0
- package/dist/exceptions/gateway-timeout.exception.js +29 -0
- package/dist/exceptions/gone.exception.js +29 -0
- package/dist/exceptions/http-version-not-supported.exception.js +29 -0
- package/dist/exceptions/http.exception.js +94 -0
- package/dist/exceptions/im-a-teapot.exception.js +29 -0
- package/dist/exceptions/internal-server-error.exception.js +29 -0
- package/dist/exceptions/length-required.exception.js +29 -0
- package/dist/exceptions/method-not-allowed.exception.js +29 -0
- package/dist/exceptions/misdirected.exception.js +29 -0
- package/dist/exceptions/not-acceptable.exception.js +29 -0
- package/dist/exceptions/not-found.exception.js +29 -0
- package/dist/exceptions/not-implemented.exception.js +29 -0
- package/dist/exceptions/payload-too-large.exception.js +29 -0
- package/dist/exceptions/payment-required.exception.js +29 -0
- package/dist/exceptions/precondition-failed.exception.js +29 -0
- package/dist/exceptions/precondition-required.exception.js +29 -0
- package/dist/exceptions/proxy-authentication-required.exception.js +29 -0
- package/dist/exceptions/request-timeout.exception.js +29 -0
- package/dist/exceptions/requested-range-not-satisfiable.exception.js +29 -0
- package/dist/exceptions/service-unavailable.exception.js +29 -0
- package/dist/exceptions/too-many-requests.exception.js +29 -0
- package/dist/exceptions/unauthorized.exception.js +29 -0
- package/dist/exceptions/unprocessable-entity.exception.js +29 -0
- package/dist/exceptions/unsupported-media-type.exception.js +29 -0
- package/dist/exceptions/uri-too-long.exception.js +29 -0
- package/dist/filters/context.js +28 -0
- package/dist/filters/filter.js +56 -0
- package/dist/helpers/discovery.helper.js +69 -0
- package/dist/helpers/messages.helper.js +41 -0
- package/dist/helpers/middleware.helper.js +69 -0
- package/dist/helpers/path.helper.js +53 -0
- package/dist/helpers/route.helper.js +54 -0
- package/dist/http/adapter.js +294 -0
- package/dist/http/config.js +67 -0
- package/dist/http/configurable-module.js +26 -0
- package/dist/http/context.js +117 -0
- package/dist/http/explorer.js +133 -0
- package/dist/http/module.js +35 -0
- package/dist/http/starter-module.js +85 -0
- package/dist/index.d.ts +2117 -0
- package/dist/index.js +82 -0
- package/dist/interfaces/adapter.interface.js +0 -0
- package/dist/interfaces/exception.interface.js +0 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/interfaces/middleware/config-proxy.interface.js +0 -0
- package/dist/interfaces/middleware/consumer.interface.js +0 -0
- package/dist/interfaces/middleware/index.js +3 -0
- package/dist/interfaces/options.interface.js +0 -0
- package/dist/interfaces/prefix.interface.js +0 -0
- package/dist/interfaces/router/definition.interface.js +0 -0
- package/dist/interfaces/router/exclude-route.interface.js +0 -0
- package/dist/interfaces/router/index.js +7 -0
- package/dist/interfaces/router/info.interface.js +0 -0
- package/dist/interfaces/router/path-metadata.interface.js +0 -0
- package/dist/interfaces/router/tree.interface.js +0 -0
- package/dist/interfaces/router/version.interface.js +21 -0
- package/dist/middleware/builder.js +96 -0
- package/dist/middleware/module.js +22 -0
- package/dist/middleware/routes-mapper.js +107 -0
- package/dist/middleware/service.js +48 -0
- package/dist/middleware/tree.js +91 -0
- package/dist/router/finder.js +64 -0
- package/dist/router/module.js +89 -0
- package/dist/router/path-factory.js +110 -0
- package/dist/symbols.js +33 -0
- package/package.json +41 -46
- package/adapter/adapter.d.ts +0 -57
- package/adapter/adapter.js +0 -58
- package/adapter/host.d.ts +0 -27
- package/adapter/host.js +0 -33
- package/application/application.d.ts +0 -18
- package/application/application.js +0 -51
- package/application/config.d.ts +0 -16
- package/application/config.js +0 -47
- package/application/http.module-defenition.d.ts +0 -8
- package/application/http.module-defenition.js +0 -6
- package/application/http.module.d.ts +0 -3
- package/application/http.module.js +0 -21
- package/application/http.service.d.ts +0 -11
- package/application/http.service.js +0 -43
- package/application/starter.d.ts +0 -41
- package/application/starter.js +0 -140
- package/constants.d.ts +0 -12
- package/constants.js +0 -15
- package/context/context.d.ts +0 -56
- package/context/context.js +0 -102
- package/context/response.controller.d.ts +0 -30
- package/context/response.controller.js +0 -86
- package/decorators/controller.decorator.d.ts +0 -82
- package/decorators/controller.decorator.js +0 -53
- package/decorators/header.decorator.d.ts +0 -12
- package/decorators/header.decorator.js +0 -23
- package/decorators/http-code.decorator.d.ts +0 -9
- package/decorators/http-code.decorator.js +0 -19
- package/decorators/index.d.ts +0 -9
- package/decorators/index.js +0 -25
- package/decorators/redirect.decorator.d.ts +0 -6
- package/decorators/redirect.decorator.js +0 -16
- package/decorators/render.decorator.d.ts +0 -10
- package/decorators/render.decorator.js +0 -20
- package/decorators/request-mapping.decorator.d.ts +0 -78
- package/decorators/request-mapping.decorator.js +0 -98
- package/decorators/route-params.decorator.d.ts +0 -378
- package/decorators/route-params.decorator.js +0 -227
- package/decorators/sse.decorator.d.ts +0 -6
- package/decorators/sse.decorator.js +0 -20
- package/decorators/version.decorator.d.ts +0 -7
- package/decorators/version.decorator.js +0 -20
- package/enums/http-status.enum.d.ts +0 -53
- package/enums/http-status.enum.js +0 -57
- package/enums/index.d.ts +0 -4
- package/enums/index.js +0 -20
- package/enums/request-method.enum.d.ts +0 -11
- package/enums/request-method.enum.js +0 -15
- package/enums/route-paramtypes.enum.d.ts +0 -14
- package/enums/route-paramtypes.enum.js +0 -18
- package/enums/version-type.enum.d.ts +0 -9
- package/enums/version-type.enum.js +0 -13
- package/errors/bad-gateway.exception.d.ts +0 -33
- package/errors/bad-gateway.exception.js +0 -41
- package/errors/bad-request.exception.d.ts +0 -33
- package/errors/bad-request.exception.js +0 -41
- package/errors/conflict.exception.d.ts +0 -33
- package/errors/conflict.exception.js +0 -41
- package/errors/forbidden.exception.d.ts +0 -33
- package/errors/forbidden.exception.js +0 -41
- package/errors/gateway-timeout.exception.d.ts +0 -33
- package/errors/gateway-timeout.exception.js +0 -41
- package/errors/gone.exception.d.ts +0 -33
- package/errors/gone.exception.js +0 -41
- package/errors/http-version-not-supported.exception.d.ts +0 -33
- package/errors/http-version-not-supported.exception.js +0 -41
- package/errors/http.exception.d.ts +0 -79
- package/errors/http.exception.js +0 -123
- package/errors/im-a-teapot.exception.d.ts +0 -36
- package/errors/im-a-teapot.exception.js +0 -44
- package/errors/index.d.ts +0 -11
- package/errors/index.js +0 -27
- package/errors/internal-server-error.exception.d.ts +0 -33
- package/errors/internal-server-error.exception.js +0 -41
- package/errors/invalid-middleware-configuration.exception.d.ts +0 -4
- package/errors/invalid-middleware-configuration.exception.js +0 -11
- package/errors/invalid-middleware.exception.d.ts +0 -4
- package/errors/invalid-middleware.exception.js +0 -11
- package/errors/not-found.exception.d.ts +0 -33
- package/errors/not-found.exception.js +0 -41
- package/errors/unknown-request-mapping.exception.d.ts +0 -5
- package/errors/unknown-request-mapping.exception.js +0 -11
- package/exceptions/messages.d.ts +0 -4
- package/exceptions/messages.js +0 -13
- package/explorers/path.explorer.d.ts +0 -8
- package/explorers/path.explorer.js +0 -38
- package/explorers/router.explorer.d.ts +0 -51
- package/explorers/router.explorer.js +0 -195
- package/factory/context-id.factory.d.ts +0 -41
- package/factory/context-id.factory.js +0 -52
- package/factory/index.d.ts +0 -4
- package/factory/index.js +0 -20
- package/factory/method.factory.d.ts +0 -5
- package/factory/method.factory.js +0 -30
- package/factory/params.factory.d.ts +0 -5
- package/factory/params.factory.js +0 -39
- package/factory/path.factory.d.ts +0 -13
- package/factory/path.factory.js +0 -95
- package/filters/context.d.ts +0 -9
- package/filters/context.js +0 -15
- package/filters/filter.d.ts +0 -22
- package/filters/filter.js +0 -78
- package/helpers/adapter.helper.d.ts +0 -27
- package/helpers/adapter.helper.js +0 -37
- package/helpers/exclude-route.helper.d.ts +0 -4
- package/helpers/exclude-route.helper.js +0 -18
- package/helpers/flatten-routes.helper.d.ts +0 -5
- package/helpers/flatten-routes.helper.js +0 -27
- package/helpers/index.d.ts +0 -6
- package/helpers/index.js +0 -22
- package/helpers/messages.helper.d.ts +0 -6
- package/helpers/messages.helper.js +0 -25
- package/helpers/path.helper.d.ts +0 -3
- package/helpers/path.helper.js +0 -13
- package/helpers/sse.helper.d.ts +0 -45
- package/helpers/sse.helper.js +0 -83
- package/index.d.ts +0 -1
- package/index.js +0 -3
- package/interfaces/http/cors.interface.d.ts +0 -58
- package/interfaces/http/cors.interface.js +0 -2
- package/interfaces/http/exception.interface.d.ts +0 -6
- package/interfaces/http/exception.interface.js +0 -2
- package/interfaces/http/exclude-route.interface.d.ts +0 -15
- package/interfaces/http/exclude-route.interface.js +0 -2
- package/interfaces/http/index.d.ts +0 -10
- package/interfaces/http/index.js +0 -26
- package/interfaces/http/message-event.interface.d.ts +0 -6
- package/interfaces/http/message-event.interface.js +0 -2
- package/interfaces/http/module.inteface.d.ts +0 -5
- package/interfaces/http/module.inteface.js +0 -2
- package/interfaces/http/options.interface.d.ts +0 -127
- package/interfaces/http/options.interface.js +0 -2
- package/interfaces/http/path-metadata.interface.d.ts +0 -31
- package/interfaces/http/path-metadata.interface.js +0 -2
- package/interfaces/http/prefix-options.interface.d.ts +0 -7
- package/interfaces/http/prefix-options.interface.js +0 -2
- package/interfaces/http/raw-request.d.ts +0 -4
- package/interfaces/http/raw-request.js +0 -2
- package/interfaces/http/routes.interface.d.ts +0 -7
- package/interfaces/http/routes.interface.js +0 -2
- package/interfaces/http/server.interface.d.ts +0 -54
- package/interfaces/http/server.interface.js +0 -2
- package/interfaces/index.d.ts +0 -3
- package/interfaces/index.js +0 -19
- package/interfaces/middleware/config-proxy.interface.d.ts +0 -23
- package/interfaces/middleware/config-proxy.interface.js +0 -2
- package/interfaces/middleware/configuration.interface.d.ts +0 -12
- package/interfaces/middleware/configuration.interface.js +0 -2
- package/interfaces/middleware/consumer.interface.d.ts +0 -16
- package/interfaces/middleware/consumer.interface.js +0 -2
- package/interfaces/middleware/index.d.ts +0 -4
- package/interfaces/middleware/index.js +0 -20
- package/interfaces/middleware/middleware.interface.d.ts +0 -7
- package/interfaces/middleware/middleware.interface.js +0 -2
- package/interfaces/router/callback-paramtypes.interface.d.ts +0 -1
- package/interfaces/router/callback-paramtypes.interface.js +0 -2
- package/interfaces/router/definition.interface.d.ts +0 -10
- package/interfaces/router/definition.interface.js +0 -2
- package/interfaces/router/index.d.ts +0 -3
- package/interfaces/router/index.js +0 -19
- package/interfaces/router/version-options.interface.d.ts +0 -92
- package/interfaces/router/version-options.interface.js +0 -9
- package/middleware/builder.d.ts +0 -15
- package/middleware/builder.js +0 -78
- package/middleware/container.d.ts +0 -13
- package/middleware/container.js +0 -50
- package/middleware/extractor.d.ts +0 -15
- package/middleware/extractor.js +0 -50
- package/middleware/index.d.ts +0 -1
- package/middleware/index.js +0 -17
- package/middleware/module.d.ts +0 -33
- package/middleware/module.js +0 -180
- package/middleware/resolver.d.ts +0 -10
- package/middleware/resolver.js +0 -27
- package/middleware/routes-mapper.d.ts +0 -19
- package/middleware/routes-mapper.js +0 -111
- package/middleware/utils.d.ts +0 -8
- package/middleware/utils.js +0 -86
- package/router/module.d.ts +0 -18
- package/router/module.js +0 -88
- package/router/resolver.d.ts +0 -31
- package/router/resolver.js +0 -128
- package/storage/http-instance.storage.d.ts +0 -9
- package/storage/http-instance.storage.js +0 -19
- package/stream/index.d.ts +0 -1
- package/stream/index.js +0 -17
- package/stream/interfaces/index.d.ts +0 -2
- package/stream/interfaces/index.js +0 -18
- package/stream/interfaces/streamable-handler-response.interface.d.ts +0 -12
- package/stream/interfaces/streamable-handler-response.interface.js +0 -2
- package/stream/interfaces/streamable-options.interface.d.ts +0 -10
- package/stream/interfaces/streamable-options.interface.js +0 -2
- package/stream/streamable-file.d.ts +0 -22
- package/stream/streamable-file.js +0 -55
- package/test/context/response.controller.spec.d.ts +0 -1
- package/test/context/response.controller.spec.js +0 -328
- package/test/decorators/controller.decorator.spec.d.ts +0 -1
- package/test/decorators/controller.decorator.spec.js +0 -113
- package/test/decorators/header.decorator.spec.d.ts +0 -1
- package/test/decorators/header.decorator.spec.js +0 -33
- package/test/decorators/http-code.decorator.spec.d.ts +0 -1
- package/test/decorators/http-code.decorator.spec.js +0 -30
- package/test/decorators/redirect.decorator.spec.d.ts +0 -1
- package/test/decorators/redirect.decorator.spec.js +0 -36
- package/test/decorators/render.decorator.spec.d.ts +0 -1
- package/test/decorators/render.decorator.spec.js +0 -30
- package/test/decorators/request-mapping.decorator.spec.d.ts +0 -1
- package/test/decorators/request-mapping.decorator.spec.js +0 -85
- package/test/decorators/route-params.decorator.spec.d.ts +0 -1
- package/test/decorators/route-params.decorator.spec.js +0 -493
- package/test/decorators/sse.decorator.spec.d.ts +0 -1
- package/test/decorators/sse.decorator.spec.js +0 -35
- package/test/decorators/version.decorator.spec.d.ts +0 -1
- package/test/decorators/version.decorator.spec.js +0 -43
- package/test/exceptions/handler.spec.d.ts +0 -1
- package/test/exceptions/handler.spec.js +0 -145
- package/test/exceptions/proxy.spec.d.ts +0 -1
- package/test/exceptions/proxy.spec.js +0 -74
- package/test/explorers/path.explorer.spec.d.ts +0 -1
- package/test/explorers/path.explorer.spec.js +0 -190
- package/test/explorers/router.explorer.spec.d.ts +0 -1
- package/test/explorers/router.explorer.spec.js +0 -206
- package/test/factory/method.factory.spec.d.ts +0 -1
- package/test/factory/method.factory.spec.js +0 -33
- package/test/factory/params.factory.spec.d.ts +0 -1
- package/test/factory/params.factory.spec.js +0 -104
- package/test/factory/path.factory.spec.d.ts +0 -1
- package/test/factory/path.factory.spec.js +0 -260
- package/test/filters/context.spec.d.ts +0 -1
- package/test/filters/context.spec.js +0 -96
- package/test/filters/filter.spec.d.ts +0 -1
- package/test/filters/filter.spec.js +0 -96
- package/test/helpers/flatten-routes.helper.spec.d.ts +0 -1
- package/test/helpers/flatten-routes.helper.spec.js +0 -131
- package/test/helpers/sse.helper.spec.d.ts +0 -1
- package/test/helpers/sse.helper.spec.js +0 -132
- package/test/middleware/builder.spec.d.ts +0 -1
- package/test/middleware/builder.spec.js +0 -235
- package/test/middleware/container.spec.d.ts +0 -1
- package/test/middleware/container.spec.js +0 -81
- package/test/middleware/module.spec.d.ts +0 -1
- package/test/middleware/module.spec.js +0 -206
- package/test/middleware/route-info-path-extractor.spec.d.ts +0 -1
- package/test/middleware/route-info-path-extractor.spec.js +0 -123
- package/test/middleware/routes-mapper.spec.d.ts +0 -1
- package/test/middleware/routes-mapper.spec.js +0 -162
- package/test/middleware/utils.spec.d.ts +0 -1
- package/test/middleware/utils.spec.js +0 -132
- package/test/router/module.spec.d.ts +0 -1
- package/test/router/module.spec.js +0 -40
- package/test/router/resolver.spec.d.ts +0 -1
- package/test/router/resolver.spec.js +0 -326
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/http/src/router/module.ts
|
|
18
|
+
import { Inject, Module, MODULE_PATH, ModulesContainer } from "@venok/core";
|
|
19
|
+
import { normalizePath } from "../helpers/path.helper.js";
|
|
20
|
+
import { flattenRoutePaths } from "../helpers/route.helper.js";
|
|
21
|
+
var ROUTES = Symbol("ROUTES");
|
|
22
|
+
var targetModulesByContainer = new WeakMap;
|
|
23
|
+
|
|
24
|
+
class RouterModule {
|
|
25
|
+
modulesContainer;
|
|
26
|
+
routes;
|
|
27
|
+
constructor(modulesContainer, routes) {
|
|
28
|
+
this.modulesContainer = modulesContainer;
|
|
29
|
+
this.routes = routes;
|
|
30
|
+
this.routes = this.deepCloneRoutes(routes);
|
|
31
|
+
this.initialize();
|
|
32
|
+
}
|
|
33
|
+
static register(routes) {
|
|
34
|
+
return {
|
|
35
|
+
module: RouterModule,
|
|
36
|
+
providers: [{ provide: ROUTES, useValue: routes }]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
deepCloneRoutes(routes) {
|
|
40
|
+
return routes.map((routeOrType) => {
|
|
41
|
+
if (typeof routeOrType === "function")
|
|
42
|
+
return routeOrType;
|
|
43
|
+
if (routeOrType.children) {
|
|
44
|
+
return {
|
|
45
|
+
...routeOrType,
|
|
46
|
+
children: this.deepCloneRoutes(routeOrType.children)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return { ...routeOrType };
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
initialize() {
|
|
53
|
+
const flattenedRoutes = flattenRoutePaths(this.routes);
|
|
54
|
+
flattenedRoutes.forEach((route) => {
|
|
55
|
+
const modulePath = normalizePath(route.path);
|
|
56
|
+
this.registerModulePathMetadata(route.module, modulePath);
|
|
57
|
+
this.updateTargetModulesCache(route.module);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
registerModulePathMetadata(moduleCtor, modulePath) {
|
|
61
|
+
Reflect.defineMetadata(MODULE_PATH + this.modulesContainer.applicationId, modulePath, moduleCtor);
|
|
62
|
+
}
|
|
63
|
+
updateTargetModulesCache(moduleCtor) {
|
|
64
|
+
let moduleClassSet;
|
|
65
|
+
if (targetModulesByContainer.has(this.modulesContainer)) {
|
|
66
|
+
moduleClassSet = targetModulesByContainer.get(this.modulesContainer);
|
|
67
|
+
} else {
|
|
68
|
+
moduleClassSet = new WeakSet;
|
|
69
|
+
targetModulesByContainer.set(this.modulesContainer, moduleClassSet);
|
|
70
|
+
}
|
|
71
|
+
const moduleRef = Array.from(this.modulesContainer.values()).find((item) => item?.metatype === moduleCtor);
|
|
72
|
+
if (!moduleRef)
|
|
73
|
+
return;
|
|
74
|
+
moduleClassSet.add(moduleRef);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
RouterModule = __legacyDecorateClassTS([
|
|
78
|
+
Module({}),
|
|
79
|
+
__legacyDecorateParamTS(1, Inject(ROUTES)),
|
|
80
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
81
|
+
typeof ModulesContainer === "undefined" ? Object : ModulesContainer,
|
|
82
|
+
typeof Routes === "undefined" ? Object : Routes
|
|
83
|
+
])
|
|
84
|
+
], RouterModule);
|
|
85
|
+
export {
|
|
86
|
+
targetModulesByContainer,
|
|
87
|
+
RouterModule,
|
|
88
|
+
ROUTES
|
|
89
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/http/src/router/path-factory.ts
|
|
18
|
+
import { flatten, isUndefined } from "@venok/core";
|
|
19
|
+
import { VERSION_NEUTRAL } from "../interfaces/index.js";
|
|
20
|
+
import { HttpVersioningType } from "../enums/version-type.enum.js";
|
|
21
|
+
import { addLeadingSlash, stripEndSlash } from "../helpers/path.helper.js";
|
|
22
|
+
import { isRouteExcluded } from "../helpers/route.helper.js";
|
|
23
|
+
|
|
24
|
+
class RoutePathFactory {
|
|
25
|
+
config;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
}
|
|
29
|
+
create(metadata, requestMethod) {
|
|
30
|
+
let paths = [""];
|
|
31
|
+
const versionOrVersions = this.getVersion(metadata);
|
|
32
|
+
if (versionOrVersions && metadata.versioningOptions?.type === HttpVersioningType.URI) {
|
|
33
|
+
const versionPrefix = this.getVersionPrefix(metadata.versioningOptions);
|
|
34
|
+
if (Array.isArray(versionOrVersions)) {
|
|
35
|
+
paths = flatten(paths.map((path) => versionOrVersions.map((version) => version === VERSION_NEUTRAL ? path : `${path}/${versionPrefix}${version}`)));
|
|
36
|
+
} else {
|
|
37
|
+
if (versionOrVersions !== VERSION_NEUTRAL) {
|
|
38
|
+
paths = paths.map((path) => `${path}/${versionPrefix}${versionOrVersions}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
paths = this.appendToAllIfDefined(paths, metadata.modulePath);
|
|
43
|
+
paths = this.appendToAllIfDefined(paths, metadata.controllerPath);
|
|
44
|
+
paths = this.appendToAllIfDefined(paths, metadata.methodPath);
|
|
45
|
+
if (metadata.globalPrefix) {
|
|
46
|
+
paths = paths.map((path) => {
|
|
47
|
+
if (this.isExcludedFromGlobalPrefix(path, requestMethod, versionOrVersions, metadata.versioningOptions)) {
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
return stripEndSlash(metadata.globalPrefix || "") + path;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return paths.map((path) => addLeadingSlash(path || "/")).map((path) => path !== "/" ? stripEndSlash(path) : path);
|
|
54
|
+
}
|
|
55
|
+
extractControllerPath(path) {
|
|
56
|
+
if (isUndefined(path))
|
|
57
|
+
return [];
|
|
58
|
+
if (Array.isArray(path))
|
|
59
|
+
return path.map((p) => addLeadingSlash(p));
|
|
60
|
+
return [addLeadingSlash(path)];
|
|
61
|
+
}
|
|
62
|
+
getVersion(metadata) {
|
|
63
|
+
return metadata.methodVersion || metadata.controllerVersion;
|
|
64
|
+
}
|
|
65
|
+
getVersionPrefix(versioningOptions) {
|
|
66
|
+
const defaultPrefix = "v";
|
|
67
|
+
if (versioningOptions.type === HttpVersioningType.URI) {
|
|
68
|
+
if (versioningOptions.prefix === false)
|
|
69
|
+
return "";
|
|
70
|
+
else if (versioningOptions.prefix !== undefined)
|
|
71
|
+
return versioningOptions.prefix;
|
|
72
|
+
}
|
|
73
|
+
return defaultPrefix;
|
|
74
|
+
}
|
|
75
|
+
appendToAllIfDefined(paths, fragmentToAppend) {
|
|
76
|
+
if (!fragmentToAppend)
|
|
77
|
+
return paths;
|
|
78
|
+
const concatPaths = (a, b) => stripEndSlash(a) + addLeadingSlash(b);
|
|
79
|
+
if (Array.isArray(fragmentToAppend)) {
|
|
80
|
+
const paths2dArray = paths.map((path) => fragmentToAppend.map((fragment) => concatPaths(path, fragment)));
|
|
81
|
+
return flatten(paths2dArray);
|
|
82
|
+
}
|
|
83
|
+
return paths.map((path) => concatPaths(path, fragmentToAppend));
|
|
84
|
+
}
|
|
85
|
+
isExcludedFromGlobalPrefix(path, requestMethod, versionOrVersions, versioningOptions) {
|
|
86
|
+
if (isUndefined(requestMethod))
|
|
87
|
+
return false;
|
|
88
|
+
const options = this.config.getGlobalPrefixOptions();
|
|
89
|
+
const excludedRoutes = options.exclude;
|
|
90
|
+
if (versionOrVersions && versionOrVersions !== VERSION_NEUTRAL && versioningOptions?.type === HttpVersioningType.URI) {
|
|
91
|
+
path = this.truncateVersionPrefixFromPath(path, versionOrVersions, versioningOptions);
|
|
92
|
+
}
|
|
93
|
+
return Array.isArray(excludedRoutes) && isRouteExcluded(excludedRoutes, path, requestMethod);
|
|
94
|
+
}
|
|
95
|
+
truncateVersionPrefixFromPath(path, versionValue, versioningOptions) {
|
|
96
|
+
if (typeof versionValue !== "string") {
|
|
97
|
+
versionValue.forEach((version) => {
|
|
98
|
+
if (typeof version === "string") {
|
|
99
|
+
path = this.truncateVersionPrefixFromPath(path, version, versioningOptions);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return path;
|
|
103
|
+
}
|
|
104
|
+
const prefix = `/${this.getVersionPrefix(versioningOptions)}${versionValue}`;
|
|
105
|
+
return path.startsWith(prefix) ? path.replace(prefix, "") : path;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
RoutePathFactory
|
|
110
|
+
};
|
package/dist/symbols.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/http/src/symbols.ts
|
|
18
|
+
var VENOK_ADAPTER_BUILD = Symbol("VENOK_ADAPTER_BUILD");
|
|
19
|
+
var VENOK_ADAPTER_ADD_ROUTE = Symbol("VENOK_ADAPTER_ADD_ROUTE");
|
|
20
|
+
var VENOK_ADAPTER_ADD_MIDDLEWARE = Symbol("VENOK_ADAPTER_ADD_MIDDLEWARE");
|
|
21
|
+
var VENOK_ADAPTER_SET_EXCEPTION_FILTER = Symbol("VENOK_ADAPTER_SET_EXCEPTION_FILTER");
|
|
22
|
+
var VENOK_APPLY_ROUTES_TO_INSTANCE = Symbol("VENOK_APPLY_ROUTES_TO_INSTANCE");
|
|
23
|
+
var VENOK_ADAPTER_RESPONSE = Symbol("VENOK_ADAPTER_RESPONSE");
|
|
24
|
+
var VENOK_ADAPTER_TRANSFORM_NATIVE_ARGS_TO_CONTEXT = Symbol("VENOK_ADAPTER_TRANSFORM_NATIVE_ARGS_TO_CONTEXT");
|
|
25
|
+
export {
|
|
26
|
+
VENOK_APPLY_ROUTES_TO_INSTANCE,
|
|
27
|
+
VENOK_ADAPTER_TRANSFORM_NATIVE_ARGS_TO_CONTEXT,
|
|
28
|
+
VENOK_ADAPTER_SET_EXCEPTION_FILTER,
|
|
29
|
+
VENOK_ADAPTER_RESPONSE,
|
|
30
|
+
VENOK_ADAPTER_BUILD,
|
|
31
|
+
VENOK_ADAPTER_ADD_ROUTE,
|
|
32
|
+
VENOK_ADAPTER_ADD_MIDDLEWARE
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@venok/http",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"author": "
|
|
6
|
-
"homepage": "",
|
|
7
|
-
"main": "index.js",
|
|
8
|
-
"types": "./index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
"dependencies": {
|
|
44
|
-
"path-to-regexp": "^6.2.1"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@venok/http",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "shiz-ceo",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"files": ["package.json", "dist"],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/venokjs/venok.git",
|
|
29
|
+
"directory": "packages/http"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@venok/core": "1.1.0",
|
|
34
|
+
"@venok/integration": "1.1.0",
|
|
35
|
+
"reflect-metadata": "^0.2.2",
|
|
36
|
+
"rxjs": "^7.8.1"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"path-to-regexp": "^6.2.1"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/adapter/adapter.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { RequestMethod } from "@venok/http/enums";
|
|
2
|
-
import { CorsOptions, CorsOptionsDelegate, HttpServer, RequestHandler, VenokApplicationOptions, VersioningOptions, VersionValue } from "@venok/http/interfaces";
|
|
3
|
-
/**
|
|
4
|
-
* @publicApi
|
|
5
|
-
*/
|
|
6
|
-
export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any, TResponse = any> implements HttpServer<TRequest, TResponse> {
|
|
7
|
-
protected instance?: any;
|
|
8
|
-
protected httpServer: TServer;
|
|
9
|
-
constructor(instance?: any);
|
|
10
|
-
init(): Promise<void>;
|
|
11
|
-
use(...args: any[]): any;
|
|
12
|
-
get(handler: RequestHandler): any;
|
|
13
|
-
get(path: any, handler: RequestHandler): any;
|
|
14
|
-
post(handler: RequestHandler): any;
|
|
15
|
-
post(path: any, handler: RequestHandler): any;
|
|
16
|
-
head(handler: RequestHandler): any;
|
|
17
|
-
head(path: any, handler: RequestHandler): any;
|
|
18
|
-
delete(handler: RequestHandler): any;
|
|
19
|
-
delete(path: any, handler: RequestHandler): any;
|
|
20
|
-
put(handler: RequestHandler): any;
|
|
21
|
-
put(path: any, handler: RequestHandler): any;
|
|
22
|
-
patch(handler: RequestHandler): any;
|
|
23
|
-
patch(path: any, handler: RequestHandler): any;
|
|
24
|
-
all(handler: RequestHandler): any;
|
|
25
|
-
all(path: any, handler: RequestHandler): any;
|
|
26
|
-
search(port: string | number, callback?: () => void): any;
|
|
27
|
-
search(port: string | number, hostname: string, callback?: () => void): any;
|
|
28
|
-
options(handler: RequestHandler): any;
|
|
29
|
-
options(path: any, handler: RequestHandler): any;
|
|
30
|
-
listen(port: string | number, callback?: () => void): void;
|
|
31
|
-
listen(port: string | number, hostname: string, callback?: () => void): void;
|
|
32
|
-
getHttpServer(): TServer;
|
|
33
|
-
setHttpServer(httpServer: TServer): void;
|
|
34
|
-
setInstance<T = any>(instance: T): void;
|
|
35
|
-
getInstance<T = any>(): T;
|
|
36
|
-
abstract close(): this | Promise<this>;
|
|
37
|
-
abstract initHttpServer(options: VenokApplicationOptions): this;
|
|
38
|
-
abstract useStaticAssets(...args: any[]): this;
|
|
39
|
-
abstract setViewEngine(engine: string): this;
|
|
40
|
-
abstract getRequestHostname(request: any): any;
|
|
41
|
-
abstract getRequestMethod(request: any): any;
|
|
42
|
-
abstract getRequestUrl(request: any): any;
|
|
43
|
-
abstract status(response: any, statusCode: number): any;
|
|
44
|
-
abstract reply(response: any, body: any, statusCode?: number): any;
|
|
45
|
-
abstract end(response: any, message?: string): any;
|
|
46
|
-
abstract render(response: any, view: string, options: any): any;
|
|
47
|
-
abstract redirect(response: any, statusCode: number, url: string): any;
|
|
48
|
-
abstract setErrorHandler(handler: Function, prefix?: string): any;
|
|
49
|
-
abstract setNotFoundHandler(handler: Function, prefix?: string): any;
|
|
50
|
-
abstract isHeadersSent(response: any): any;
|
|
51
|
-
abstract setHeader(response: any, name: string, value: string): any;
|
|
52
|
-
abstract registerParserMiddleware(prefix?: string, rawBody?: boolean): any;
|
|
53
|
-
abstract enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>, prefix?: string): any;
|
|
54
|
-
abstract createMiddlewareFactory(requestMethod: RequestMethod): ((path: string, callback: Function) => any) | Promise<(path: string, callback: Function) => any>;
|
|
55
|
-
abstract getType(): string;
|
|
56
|
-
abstract applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): (req: TRequest, res: TResponse, next: () => void) => Function;
|
|
57
|
-
}
|
package/adapter/adapter.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbstractHttpAdapter = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @publicApi
|
|
6
|
-
*/
|
|
7
|
-
class AbstractHttpAdapter {
|
|
8
|
-
constructor(instance) {
|
|
9
|
-
this.instance = instance;
|
|
10
|
-
}
|
|
11
|
-
async init() { }
|
|
12
|
-
use(...args) {
|
|
13
|
-
return this.instance.use(...args);
|
|
14
|
-
}
|
|
15
|
-
get(...args) {
|
|
16
|
-
return this.instance.get(...args);
|
|
17
|
-
}
|
|
18
|
-
post(...args) {
|
|
19
|
-
return this.instance.post(...args);
|
|
20
|
-
}
|
|
21
|
-
head(...args) {
|
|
22
|
-
return this.instance.head(...args);
|
|
23
|
-
}
|
|
24
|
-
delete(...args) {
|
|
25
|
-
return this.instance.delete(...args);
|
|
26
|
-
}
|
|
27
|
-
put(...args) {
|
|
28
|
-
return this.instance.put(...args);
|
|
29
|
-
}
|
|
30
|
-
patch(...args) {
|
|
31
|
-
return this.instance.patch(...args);
|
|
32
|
-
}
|
|
33
|
-
all(...args) {
|
|
34
|
-
return this.instance.all(...args);
|
|
35
|
-
}
|
|
36
|
-
search(port, hostname, callback) {
|
|
37
|
-
return this.instance.search(port, hostname, callback);
|
|
38
|
-
}
|
|
39
|
-
options(...args) {
|
|
40
|
-
return this.instance.options(...args);
|
|
41
|
-
}
|
|
42
|
-
listen(port, hostname, callback) {
|
|
43
|
-
return this.instance.listen(port, hostname, callback);
|
|
44
|
-
}
|
|
45
|
-
getHttpServer() {
|
|
46
|
-
return this.httpServer;
|
|
47
|
-
}
|
|
48
|
-
setHttpServer(httpServer) {
|
|
49
|
-
this.httpServer = httpServer;
|
|
50
|
-
}
|
|
51
|
-
setInstance(instance) {
|
|
52
|
-
this.instance = instance;
|
|
53
|
-
}
|
|
54
|
-
getInstance() {
|
|
55
|
-
return this.instance;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.AbstractHttpAdapter = AbstractHttpAdapter;
|
package/adapter/host.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { AbstractHttpAdapter } from "@venok/http/adapter/adapter";
|
|
2
|
-
/**
|
|
3
|
-
* Defines the `HttpAdapterHost` object.
|
|
4
|
-
*
|
|
5
|
-
* `HttpAdapterHost` wraps the underlying
|
|
6
|
-
* platform-specific `HttpAdapter`. The `HttpAdapter` is a wrapper around the underlying
|
|
7
|
-
* native HTTP server library (e.g., Express). The `HttpAdapterHost` object
|
|
8
|
-
* provides methods to `get` and `set` the underlying HttpAdapter.
|
|
9
|
-
*
|
|
10
|
-
* @publicApi
|
|
11
|
-
*/
|
|
12
|
-
export declare class HttpAdapterHost<T extends AbstractHttpAdapter = AbstractHttpAdapter> {
|
|
13
|
-
private _httpAdapter?;
|
|
14
|
-
/**
|
|
15
|
-
* Accessor for the underlying `HttpAdapter`
|
|
16
|
-
*
|
|
17
|
-
* @param httpAdapter reference to the `HttpAdapter` to be set
|
|
18
|
-
*/
|
|
19
|
-
set httpAdapter(httpAdapter: T);
|
|
20
|
-
/**
|
|
21
|
-
* Accessor for the underlying `HttpAdapter`
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* `const httpAdapter = adapterHost.httpAdapter;`
|
|
25
|
-
*/
|
|
26
|
-
get httpAdapter(): T;
|
|
27
|
-
}
|
package/adapter/host.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpAdapterHost = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Defines the `HttpAdapterHost` object.
|
|
6
|
-
*
|
|
7
|
-
* `HttpAdapterHost` wraps the underlying
|
|
8
|
-
* platform-specific `HttpAdapter`. The `HttpAdapter` is a wrapper around the underlying
|
|
9
|
-
* native HTTP server library (e.g., Express). The `HttpAdapterHost` object
|
|
10
|
-
* provides methods to `get` and `set` the underlying HttpAdapter.
|
|
11
|
-
*
|
|
12
|
-
* @publicApi
|
|
13
|
-
*/
|
|
14
|
-
class HttpAdapterHost {
|
|
15
|
-
/**
|
|
16
|
-
* Accessor for the underlying `HttpAdapter`
|
|
17
|
-
*
|
|
18
|
-
* @param httpAdapter reference to the `HttpAdapter` to be set
|
|
19
|
-
*/
|
|
20
|
-
set httpAdapter(httpAdapter) {
|
|
21
|
-
this._httpAdapter = httpAdapter;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Accessor for the underlying `HttpAdapter`
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* `const httpAdapter = adapterHost.httpAdapter;`
|
|
28
|
-
*/
|
|
29
|
-
get httpAdapter() {
|
|
30
|
-
return this._httpAdapter;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.HttpAdapterHost = HttpAdapterHost;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { CorsOptions, CorsOptionsDelegate, GlobalPrefixOptions, HttpServer, VersioningOptions } from "../interfaces";
|
|
2
|
-
import { HttpConfig } from "./config";
|
|
3
|
-
import { AbstractHttpAdapter } from "../adapter/adapter";
|
|
4
|
-
export declare class HttpApplication {
|
|
5
|
-
private readonly httpAdapter;
|
|
6
|
-
private readonly config;
|
|
7
|
-
private start;
|
|
8
|
-
constructor(httpAdapter: HttpServer, config: HttpConfig);
|
|
9
|
-
use(...args: [any, any?]): this;
|
|
10
|
-
getHttpAdapter(): AbstractHttpAdapter;
|
|
11
|
-
enableCors(options?: CorsOptions | CorsOptionsDelegate<any>): this;
|
|
12
|
-
enableVersioning(options?: VersioningOptions): this;
|
|
13
|
-
setGlobalPrefix(prefix: string, options?: GlobalPrefixOptions): this;
|
|
14
|
-
useStaticAssets(options: any): this;
|
|
15
|
-
useStaticAssets(path: string, options?: any): this;
|
|
16
|
-
setBaseViewsDir(path: string | string[]): this;
|
|
17
|
-
setViewEngine(engineOrOptions: any): this;
|
|
18
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpApplication = void 0;
|
|
4
|
-
const enums_1 = require("../enums");
|
|
5
|
-
const utils_1 = require("../middleware/utils");
|
|
6
|
-
class HttpApplication {
|
|
7
|
-
constructor(httpAdapter, config) {
|
|
8
|
-
this.httpAdapter = httpAdapter;
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.start = false;
|
|
11
|
-
}
|
|
12
|
-
use(...args) {
|
|
13
|
-
this.httpAdapter.use(...args);
|
|
14
|
-
return this;
|
|
15
|
-
}
|
|
16
|
-
getHttpAdapter() {
|
|
17
|
-
return this.httpAdapter;
|
|
18
|
-
}
|
|
19
|
-
enableCors(options) {
|
|
20
|
-
this.httpAdapter.enableCors(options);
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
enableVersioning(options = { type: enums_1.VersioningType.URI }) {
|
|
24
|
-
this.config.enableVersioning(options);
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
setGlobalPrefix(prefix, options) {
|
|
28
|
-
this.config.setGlobalPrefix(prefix);
|
|
29
|
-
if (options) {
|
|
30
|
-
const exclude = options?.exclude ? (0, utils_1.mapToExcludeRoute)(options.exclude) : [];
|
|
31
|
-
this.config.setGlobalPrefixOptions({
|
|
32
|
-
...options,
|
|
33
|
-
exclude,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
useStaticAssets(pathOrOptions, options) {
|
|
39
|
-
this.httpAdapter.useStaticAssets && this.httpAdapter.useStaticAssets(pathOrOptions, options);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
setBaseViewsDir(path) {
|
|
43
|
-
this.httpAdapter.setBaseViewsDir && this.httpAdapter.setBaseViewsDir(path);
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
setViewEngine(engineOrOptions) {
|
|
47
|
-
this.httpAdapter.setViewEngine && this.httpAdapter.setViewEngine(engineOrOptions);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.HttpApplication = HttpApplication;
|
package/application/config.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ExcludeRouteMetadata, GlobalPrefixOptions, VersioningOptions } from "../interfaces";
|
|
2
|
-
export declare class HttpConfig {
|
|
3
|
-
private globalPrefix;
|
|
4
|
-
private globalPrefixOptions;
|
|
5
|
-
private versioningOptions;
|
|
6
|
-
private readonly httpInstanceStorage;
|
|
7
|
-
setHttpAdapter(httpAdapter: any): void;
|
|
8
|
-
getHttpAdapterRef(): import("../adapter/adapter").AbstractHttpAdapter<any, any, any>;
|
|
9
|
-
getHttpAdapterHostRef(): import("../adapter/host").HttpAdapterHost<import("../adapter/adapter").AbstractHttpAdapter<any, any, any>>;
|
|
10
|
-
setGlobalPrefix(prefix: string): void;
|
|
11
|
-
getGlobalPrefix(): string;
|
|
12
|
-
setGlobalPrefixOptions(options: GlobalPrefixOptions<ExcludeRouteMetadata>): void;
|
|
13
|
-
getGlobalPrefixOptions(): GlobalPrefixOptions<ExcludeRouteMetadata>;
|
|
14
|
-
enableVersioning(options: VersioningOptions): void;
|
|
15
|
-
getVersioning(): VersioningOptions | undefined;
|
|
16
|
-
}
|
package/application/config.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpConfig = void 0;
|
|
4
|
-
const http_instance_storage_1 = require("../storage/http-instance.storage");
|
|
5
|
-
class HttpConfig {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.globalPrefix = "";
|
|
8
|
-
this.globalPrefixOptions = {};
|
|
9
|
-
this.httpInstanceStorage = new http_instance_storage_1.HttpInstanceStorage();
|
|
10
|
-
}
|
|
11
|
-
setHttpAdapter(httpAdapter) {
|
|
12
|
-
this.httpInstanceStorage.httpAdapter = httpAdapter;
|
|
13
|
-
if (!this.httpInstanceStorage.httpAdapterHost)
|
|
14
|
-
return;
|
|
15
|
-
const host = this.httpInstanceStorage.httpAdapterHost;
|
|
16
|
-
host.httpAdapter = httpAdapter;
|
|
17
|
-
}
|
|
18
|
-
getHttpAdapterRef() {
|
|
19
|
-
return this.httpInstanceStorage.httpAdapter;
|
|
20
|
-
}
|
|
21
|
-
getHttpAdapterHostRef() {
|
|
22
|
-
return this.httpInstanceStorage.httpAdapterHost;
|
|
23
|
-
}
|
|
24
|
-
setGlobalPrefix(prefix) {
|
|
25
|
-
this.globalPrefix = prefix;
|
|
26
|
-
}
|
|
27
|
-
getGlobalPrefix() {
|
|
28
|
-
return this.globalPrefix;
|
|
29
|
-
}
|
|
30
|
-
setGlobalPrefixOptions(options) {
|
|
31
|
-
this.globalPrefixOptions = options;
|
|
32
|
-
}
|
|
33
|
-
getGlobalPrefixOptions() {
|
|
34
|
-
return this.globalPrefixOptions;
|
|
35
|
-
}
|
|
36
|
-
enableVersioning(options) {
|
|
37
|
-
if (Array.isArray(options.defaultVersion)) {
|
|
38
|
-
// Drop duplicated versions
|
|
39
|
-
options.defaultVersion = Array.from(new Set(options.defaultVersion));
|
|
40
|
-
}
|
|
41
|
-
this.versioningOptions = options;
|
|
42
|
-
}
|
|
43
|
-
getVersioning() {
|
|
44
|
-
return this.versioningOptions;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.HttpConfig = HttpConfig;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { HttpApplication } from "./application";
|
|
2
|
-
import { AbstractHttpAdapter } from "../adapter/adapter";
|
|
3
|
-
export interface HttpAppOptions {
|
|
4
|
-
port: number;
|
|
5
|
-
callback?: (app: HttpApplication) => void;
|
|
6
|
-
adapter?: AbstractHttpAdapter;
|
|
7
|
-
}
|
|
8
|
-
export declare const HttpConfigurableModuleClass: import("@venok/core/module").ConfigurableModuleCls<HttpAppOptions, "register", "create", {}>, HTTP_APP_OPTIONS: string | symbol;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HTTP_APP_OPTIONS = exports.HttpConfigurableModuleClass = void 0;
|
|
5
|
-
const module_1 = require("../../core/module");
|
|
6
|
-
_a = new module_1.ConfigurableModuleBuilder().build(), exports.HttpConfigurableModuleClass = _a.ConfigurableModuleClass, exports.HTTP_APP_OPTIONS = _a.MODULE_OPTIONS_TOKEN;
|