@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
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, VenokContainer } from "@venok/core";
|
|
2
|
-
import { InstanceWrapper } from "@venok/core/injector/instance/wrapper";
|
|
3
|
-
import { MiddlewareConfiguration } from "../interfaces/middleware";
|
|
4
|
-
export declare class MiddlewareContainer {
|
|
5
|
-
private readonly container;
|
|
6
|
-
private readonly middleware;
|
|
7
|
-
private readonly configurationSets;
|
|
8
|
-
constructor(container: VenokContainer);
|
|
9
|
-
getMiddlewareCollection(moduleKey: string): Map<InjectionToken, InstanceWrapper>;
|
|
10
|
-
getConfigurations(): Map<string, Set<MiddlewareConfiguration>>;
|
|
11
|
-
insertConfig(configList: MiddlewareConfiguration[], moduleKey: string): void;
|
|
12
|
-
private getTargetConfig;
|
|
13
|
-
}
|
package/middleware/container.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MiddlewareContainer = void 0;
|
|
4
|
-
const wrapper_1 = require("../../core/injector/instance/wrapper");
|
|
5
|
-
const class_scope_helper_1 = require("../../core/injector/helpers/class-scope.helper");
|
|
6
|
-
const is_durable_helper_1 = require("../../core/injector/helpers/is-durable.helper");
|
|
7
|
-
class MiddlewareContainer {
|
|
8
|
-
constructor(container) {
|
|
9
|
-
this.container = container;
|
|
10
|
-
this.middleware = new Map();
|
|
11
|
-
this.configurationSets = new Map();
|
|
12
|
-
}
|
|
13
|
-
getMiddlewareCollection(moduleKey) {
|
|
14
|
-
if (!this.middleware.has(moduleKey)) {
|
|
15
|
-
const moduleRef = this.container.getModuleByKey(moduleKey);
|
|
16
|
-
// Global change
|
|
17
|
-
this.middleware.set(moduleKey, new Map());
|
|
18
|
-
}
|
|
19
|
-
return this.middleware.get(moduleKey);
|
|
20
|
-
}
|
|
21
|
-
getConfigurations() {
|
|
22
|
-
return this.configurationSets;
|
|
23
|
-
}
|
|
24
|
-
insertConfig(configList, moduleKey) {
|
|
25
|
-
const middleware = this.getMiddlewareCollection(moduleKey);
|
|
26
|
-
const targetConfig = this.getTargetConfig(moduleKey);
|
|
27
|
-
const configurations = configList || [];
|
|
28
|
-
const insertMiddleware = (metatype) => {
|
|
29
|
-
const token = metatype;
|
|
30
|
-
middleware.set(token, new wrapper_1.InstanceWrapper({
|
|
31
|
-
scope: (0, class_scope_helper_1.getClassScope)(metatype),
|
|
32
|
-
durable: (0, is_durable_helper_1.isDurable)(metatype),
|
|
33
|
-
name: token?.name ?? token,
|
|
34
|
-
metatype,
|
|
35
|
-
token,
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
configurations.forEach((config) => {
|
|
39
|
-
[].concat(config.middleware).map(insertMiddleware);
|
|
40
|
-
targetConfig.add(config);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
getTargetConfig(moduleName) {
|
|
44
|
-
if (!this.configurationSets.has(moduleName)) {
|
|
45
|
-
this.configurationSets.set(moduleName, new Set());
|
|
46
|
-
}
|
|
47
|
-
return this.configurationSets.get(moduleName);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.MiddlewareContainer = MiddlewareContainer;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RouteInfo } from "../interfaces";
|
|
2
|
-
import { HttpConfig } from "../application/config";
|
|
3
|
-
export declare class RouteInfoPathExtractor {
|
|
4
|
-
private readonly httpConfig;
|
|
5
|
-
private routePathFactory;
|
|
6
|
-
private readonly prefixPath;
|
|
7
|
-
private readonly excludedGlobalPrefixRoutes;
|
|
8
|
-
private readonly versioningConfig?;
|
|
9
|
-
constructor(httpConfig: HttpConfig);
|
|
10
|
-
extractPathsFrom({ path, method, version }: RouteInfo): string[];
|
|
11
|
-
extractPathFrom(route: RouteInfo): string;
|
|
12
|
-
private isAWildcard;
|
|
13
|
-
private extractNonWildcardPathFrom;
|
|
14
|
-
private extractVersionPathFrom;
|
|
15
|
-
}
|
package/middleware/extractor.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RouteInfoPathExtractor = void 0;
|
|
4
|
-
const factory_1 = require("../factory");
|
|
5
|
-
const helpers_1 = require("../helpers");
|
|
6
|
-
const enums_1 = require("../enums");
|
|
7
|
-
class RouteInfoPathExtractor {
|
|
8
|
-
constructor(httpConfig) {
|
|
9
|
-
this.httpConfig = httpConfig;
|
|
10
|
-
this.routePathFactory = new factory_1.RoutePathFactory(httpConfig);
|
|
11
|
-
this.prefixPath = (0, helpers_1.stripEndSlash)((0, helpers_1.addLeadingSlash)(this.httpConfig.getGlobalPrefix()));
|
|
12
|
-
this.excludedGlobalPrefixRoutes = this.httpConfig.getGlobalPrefixOptions().exclude ?? [];
|
|
13
|
-
this.versioningConfig = this.httpConfig.getVersioning();
|
|
14
|
-
}
|
|
15
|
-
extractPathsFrom({ path, method, version }) {
|
|
16
|
-
const versionPath = this.extractVersionPathFrom(version);
|
|
17
|
-
if (this.isAWildcard(path)) {
|
|
18
|
-
return Array.isArray(this.excludedGlobalPrefixRoutes)
|
|
19
|
-
? [
|
|
20
|
-
this.prefixPath + versionPath + (0, helpers_1.addLeadingSlash)(path),
|
|
21
|
-
...this.excludedGlobalPrefixRoutes.map((route) => versionPath + (0, helpers_1.addLeadingSlash)(route.path)),
|
|
22
|
-
]
|
|
23
|
-
: [this.prefixPath + versionPath + (0, helpers_1.addLeadingSlash)(path)];
|
|
24
|
-
}
|
|
25
|
-
return [this.extractNonWildcardPathFrom({ path, method, version })];
|
|
26
|
-
}
|
|
27
|
-
extractPathFrom(route) {
|
|
28
|
-
if (this.isAWildcard(route.path) && !route.version)
|
|
29
|
-
return (0, helpers_1.addLeadingSlash)(route.path);
|
|
30
|
-
return this.extractNonWildcardPathFrom(route);
|
|
31
|
-
}
|
|
32
|
-
isAWildcard(path) {
|
|
33
|
-
return ["*", "/*", "/*/", "(.*)", "/(.*)"].includes(path);
|
|
34
|
-
}
|
|
35
|
-
extractNonWildcardPathFrom({ path, method, version }) {
|
|
36
|
-
const versionPath = this.extractVersionPathFrom(version);
|
|
37
|
-
if (Array.isArray(this.excludedGlobalPrefixRoutes) &&
|
|
38
|
-
(0, helpers_1.isRouteExcluded)(this.excludedGlobalPrefixRoutes, path, method)) {
|
|
39
|
-
return versionPath + (0, helpers_1.addLeadingSlash)(path);
|
|
40
|
-
}
|
|
41
|
-
return this.prefixPath + versionPath + (0, helpers_1.addLeadingSlash)(path);
|
|
42
|
-
}
|
|
43
|
-
extractVersionPathFrom(version) {
|
|
44
|
-
if (!version || this.versioningConfig?.type !== enums_1.VersioningType.URI)
|
|
45
|
-
return "";
|
|
46
|
-
const versionPrefix = this.routePathFactory.getVersionPrefix(this.versioningConfig);
|
|
47
|
-
return (0, helpers_1.addLeadingSlash)(versionPrefix + version.toString());
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.RouteInfoPathExtractor = RouteInfoPathExtractor;
|
package/middleware/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './builder';
|
package/middleware/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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("./builder"), exports);
|
package/middleware/module.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Injector } from "@venok/core/injector/injector";
|
|
2
|
-
import { HttpServer } from "../interfaces";
|
|
3
|
-
import { GraphInspector } from "@venok/core/inspector/graph-inspector";
|
|
4
|
-
import { MiddlewareContainer } from "./container";
|
|
5
|
-
import { ApplicationConfig, VenokContainer } from "@venok/core";
|
|
6
|
-
import { ApplicationContextOptions } from "@venok/core/interfaces/application/context-options.interface";
|
|
7
|
-
import { Module } from "@venok/core/injector/module/module";
|
|
8
|
-
import { MiddlewareConfiguration, RouteInfo } from "../interfaces";
|
|
9
|
-
import { HttpConfig } from "../application/config";
|
|
10
|
-
export declare class MiddlewareModule<TAppOptions extends ApplicationContextOptions = ApplicationContextOptions> {
|
|
11
|
-
private readonly routerProxy;
|
|
12
|
-
private readonly exceptionFiltersCache;
|
|
13
|
-
private readonly logger;
|
|
14
|
-
private injector;
|
|
15
|
-
private routerExceptionFilter;
|
|
16
|
-
private routesMapper;
|
|
17
|
-
private resolver;
|
|
18
|
-
private container;
|
|
19
|
-
private httpAdapter;
|
|
20
|
-
private graphInspector;
|
|
21
|
-
private appOptions;
|
|
22
|
-
private routeInfoPathExtractor;
|
|
23
|
-
register(middlewareContainer: MiddlewareContainer, container: VenokContainer, applicationConfig: ApplicationConfig, httpConfig: HttpConfig, injector: Injector, httpAdapter: HttpServer, graphInspector: GraphInspector, options: TAppOptions): Promise<void>;
|
|
24
|
-
resolveMiddleware(middlewareContainer: MiddlewareContainer, modules: Map<string, Module>): Promise<void>;
|
|
25
|
-
loadConfiguration(middlewareContainer: MiddlewareContainer, moduleRef: Module, moduleKey: string): Promise<void>;
|
|
26
|
-
registerMiddleware(middlewareContainer: MiddlewareContainer, applicationRef: any): Promise<void>;
|
|
27
|
-
registerMiddlewareConfig(middlewareContainer: MiddlewareContainer, config: MiddlewareConfiguration, moduleKey: string, applicationRef: any): Promise<void>;
|
|
28
|
-
registerRouteMiddleware(middlewareContainer: MiddlewareContainer, routeInfo: RouteInfo, config: MiddlewareConfiguration, moduleKey: string, applicationRef: any): Promise<void>;
|
|
29
|
-
private bindHandler;
|
|
30
|
-
private createProxy;
|
|
31
|
-
private registerHandler;
|
|
32
|
-
private getContextId;
|
|
33
|
-
}
|
package/middleware/module.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MiddlewareModule = void 0;
|
|
4
|
-
const context_1 = require("../filters/context");
|
|
5
|
-
const logger_service_1 = require("../../core/services/logger.service");
|
|
6
|
-
const routes_mapper_1 = require("./routes-mapper");
|
|
7
|
-
const resolver_1 = require("./resolver");
|
|
8
|
-
const extractor_1 = require("./extractor");
|
|
9
|
-
const builder_1 = require("./builder");
|
|
10
|
-
const module_1 = require("../../core/injector/module/module");
|
|
11
|
-
const shared_helper_1 = require("../../core/helpers/shared.helper");
|
|
12
|
-
const exceptions_1 = require("../../core/errors/exceptions");
|
|
13
|
-
const enums_1 = require("../enums");
|
|
14
|
-
const execution_host_1 = require("../../core/context/execution-host");
|
|
15
|
-
const constants_1 = require("../../core/injector/constants");
|
|
16
|
-
const helpers_1 = require("../helpers");
|
|
17
|
-
const factory_1 = require("../factory");
|
|
18
|
-
const constants_2 = require("../constants");
|
|
19
|
-
const invalid_middleware_exception_1 = require("../errors/invalid-middleware.exception");
|
|
20
|
-
const context_2 = require("../../core/context");
|
|
21
|
-
class MiddlewareModule {
|
|
22
|
-
constructor() {
|
|
23
|
-
this.routerProxy = new context_2.VenokProxy();
|
|
24
|
-
this.exceptionFiltersCache = new WeakMap();
|
|
25
|
-
this.logger = new logger_service_1.Logger(module_1.Module.name);
|
|
26
|
-
}
|
|
27
|
-
async register(middlewareContainer, container, applicationConfig, httpConfig, injector, httpAdapter, graphInspector, options) {
|
|
28
|
-
this.appOptions = options;
|
|
29
|
-
const appRef = httpConfig.getHttpAdapterRef();
|
|
30
|
-
this.routerExceptionFilter = new context_1.RouterExceptionFiltersContext(container, applicationConfig, appRef);
|
|
31
|
-
this.routesMapper = new routes_mapper_1.RoutesMapper(container, httpConfig);
|
|
32
|
-
this.resolver = new resolver_1.MiddlewareResolver(middlewareContainer, injector);
|
|
33
|
-
this.routeInfoPathExtractor = new extractor_1.RouteInfoPathExtractor(httpConfig);
|
|
34
|
-
this.injector = injector;
|
|
35
|
-
this.container = container;
|
|
36
|
-
this.httpAdapter = httpAdapter;
|
|
37
|
-
this.graphInspector = graphInspector;
|
|
38
|
-
const modules = container.getModules();
|
|
39
|
-
await this.resolveMiddleware(middlewareContainer, modules);
|
|
40
|
-
}
|
|
41
|
-
async resolveMiddleware(middlewareContainer, modules) {
|
|
42
|
-
const moduleEntries = [...modules.entries()];
|
|
43
|
-
const loadMiddlewareConfiguration = async ([moduleName, moduleRef]) => {
|
|
44
|
-
await this.loadConfiguration(middlewareContainer, moduleRef, moduleName);
|
|
45
|
-
await this.resolver.resolveInstances(moduleRef, moduleName);
|
|
46
|
-
};
|
|
47
|
-
await Promise.all(moduleEntries.map(loadMiddlewareConfiguration));
|
|
48
|
-
}
|
|
49
|
-
async loadConfiguration(middlewareContainer, moduleRef, moduleKey) {
|
|
50
|
-
const { instance } = moduleRef;
|
|
51
|
-
if (!instance.configure)
|
|
52
|
-
return;
|
|
53
|
-
const middlewareBuilder = new builder_1.MiddlewareBuilder(this.routesMapper, this.httpAdapter, this.routeInfoPathExtractor);
|
|
54
|
-
try {
|
|
55
|
-
await instance.configure(middlewareBuilder);
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
if (!this.appOptions.preview)
|
|
59
|
-
throw err;
|
|
60
|
-
const warningMessage = `Warning! "${moduleRef.name}" module exposes a "configure" method that throws an exception in the preview mode` +
|
|
61
|
-
` (possibly due to missing dependencies). Note: you can ignore this message, just be aware that some of those conditional middlewares will not be reflected in your graph.`;
|
|
62
|
-
this.logger.warn(warningMessage);
|
|
63
|
-
}
|
|
64
|
-
if (!(middlewareBuilder instanceof builder_1.MiddlewareBuilder))
|
|
65
|
-
return;
|
|
66
|
-
const config = middlewareBuilder.build();
|
|
67
|
-
middlewareContainer.insertConfig(config, moduleKey);
|
|
68
|
-
}
|
|
69
|
-
async registerMiddleware(middlewareContainer, applicationRef) {
|
|
70
|
-
const configs = middlewareContainer.getConfigurations();
|
|
71
|
-
const registerAllConfigs = async (moduleKey, middlewareConfig) => {
|
|
72
|
-
for (const config of middlewareConfig) {
|
|
73
|
-
await this.registerMiddlewareConfig(middlewareContainer, config, moduleKey, applicationRef);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const entriesSortedByDistance = [...configs.entries()].sort(([moduleA], [moduleB]) => {
|
|
77
|
-
return this.container.getModuleByKey(moduleA).distance - this.container.getModuleByKey(moduleB).distance;
|
|
78
|
-
});
|
|
79
|
-
for (const [moduleRef, moduleConfigurations] of entriesSortedByDistance) {
|
|
80
|
-
await registerAllConfigs(moduleRef, [...moduleConfigurations]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async registerMiddlewareConfig(middlewareContainer, config, moduleKey, applicationRef) {
|
|
84
|
-
const { forRoutes } = config;
|
|
85
|
-
for (const routeInfo of forRoutes) {
|
|
86
|
-
await this.registerRouteMiddleware(middlewareContainer, routeInfo, config, moduleKey, applicationRef);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async registerRouteMiddleware(middlewareContainer, routeInfo, config, moduleKey, applicationRef) {
|
|
90
|
-
const middlewareCollection = [].concat(config.middleware);
|
|
91
|
-
const moduleRef = this.container.getModuleByKey(moduleKey);
|
|
92
|
-
for (const metatype of middlewareCollection) {
|
|
93
|
-
const collection = middlewareContainer.getMiddlewareCollection(moduleKey);
|
|
94
|
-
const instanceWrapper = collection.get(metatype);
|
|
95
|
-
if ((0, shared_helper_1.isUndefined)(instanceWrapper))
|
|
96
|
-
throw new exceptions_1.RuntimeException();
|
|
97
|
-
if (instanceWrapper.isTransient)
|
|
98
|
-
return;
|
|
99
|
-
this.graphInspector.insertClassNode(moduleRef, instanceWrapper, "middleware");
|
|
100
|
-
const middlewareDefinition = {
|
|
101
|
-
type: "middleware",
|
|
102
|
-
methodName: "use",
|
|
103
|
-
className: instanceWrapper.name,
|
|
104
|
-
classNodeId: instanceWrapper.id,
|
|
105
|
-
metadata: {
|
|
106
|
-
key: routeInfo.path,
|
|
107
|
-
path: routeInfo.path,
|
|
108
|
-
requestMethod: enums_1.RequestMethod[routeInfo.method] ?? "ALL",
|
|
109
|
-
version: routeInfo.version,
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
this.graphInspector.insertEntrypointDefinition(middlewareDefinition, instanceWrapper.id);
|
|
113
|
-
await this.bindHandler(instanceWrapper, applicationRef, routeInfo, moduleRef, collection);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async bindHandler(wrapper, applicationRef, routeInfo, moduleRef, collection) {
|
|
117
|
-
const { instance, metatype } = wrapper;
|
|
118
|
-
if ((0, shared_helper_1.isUndefined)(instance?.use))
|
|
119
|
-
throw new invalid_middleware_exception_1.InvalidMiddlewareException(metatype.name);
|
|
120
|
-
const isStatic = wrapper.isDependencyTreeStatic();
|
|
121
|
-
if (isStatic) {
|
|
122
|
-
const proxy = await this.createProxy(instance);
|
|
123
|
-
return this.registerHandler(applicationRef, routeInfo, proxy);
|
|
124
|
-
}
|
|
125
|
-
const isTreeDurable = wrapper.isDependencyTreeDurable();
|
|
126
|
-
await this.registerHandler(applicationRef, routeInfo, async (req, res, next) => {
|
|
127
|
-
try {
|
|
128
|
-
const contextId = this.getContextId(req, isTreeDurable);
|
|
129
|
-
const contextInstance = await this.injector.loadPerContext(instance, moduleRef, collection, contextId);
|
|
130
|
-
const proxy = await this.createProxy(contextInstance, contextId);
|
|
131
|
-
return proxy(req, res, next);
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
let exceptionsHandler = this.exceptionFiltersCache.get(instance.use);
|
|
135
|
-
if (!exceptionsHandler) {
|
|
136
|
-
exceptionsHandler = this.routerExceptionFilter.create(instance, instance.use, undefined);
|
|
137
|
-
this.exceptionFiltersCache.set(instance.use, exceptionsHandler);
|
|
138
|
-
}
|
|
139
|
-
const host = new execution_host_1.ExecutionContextHost([req, res, next]);
|
|
140
|
-
exceptionsHandler.next(err, host);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
async createProxy(instance, contextId = constants_1.STATIC_CONTEXT) {
|
|
145
|
-
const exceptionsHandler = this.routerExceptionFilter.create(instance, instance.use, undefined, contextId);
|
|
146
|
-
const middleware = instance.use.bind(instance);
|
|
147
|
-
return this.routerProxy.createProxy(middleware, exceptionsHandler);
|
|
148
|
-
}
|
|
149
|
-
async registerHandler(applicationRef, routeInfo, proxy) {
|
|
150
|
-
const { method } = routeInfo;
|
|
151
|
-
const paths = this.routeInfoPathExtractor.extractPathsFrom(routeInfo);
|
|
152
|
-
const isMethodAll = (0, helpers_1.isRequestMethodAll)(method);
|
|
153
|
-
const requestMethod = enums_1.RequestMethod[method];
|
|
154
|
-
const router = await applicationRef.createMiddlewareFactory(method);
|
|
155
|
-
const middlewareFunction = isMethodAll
|
|
156
|
-
? proxy
|
|
157
|
-
: (req, res, next) => {
|
|
158
|
-
if (applicationRef.getRequestMethod && applicationRef.getRequestMethod(req) === requestMethod) {
|
|
159
|
-
return proxy(req, res, next);
|
|
160
|
-
}
|
|
161
|
-
return next();
|
|
162
|
-
};
|
|
163
|
-
paths.forEach((path) => router(path, middlewareFunction));
|
|
164
|
-
}
|
|
165
|
-
getContextId(request, isTreeDurable) {
|
|
166
|
-
const contextId = factory_1.ContextIdFactory.getByRequest(request);
|
|
167
|
-
if (!request[constants_2.REQUEST_CONTEXT_ID]) {
|
|
168
|
-
Object.defineProperty(request, constants_2.REQUEST_CONTEXT_ID, {
|
|
169
|
-
value: contextId,
|
|
170
|
-
enumerable: false,
|
|
171
|
-
writable: false,
|
|
172
|
-
configurable: false,
|
|
173
|
-
});
|
|
174
|
-
const requestProviderValue = isTreeDurable ? contextId.payload : request;
|
|
175
|
-
this.container.registerRequestProvider(requestProviderValue, contextId);
|
|
176
|
-
}
|
|
177
|
-
return contextId;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.MiddlewareModule = MiddlewareModule;
|
package/middleware/resolver.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MiddlewareContainer } from "./container";
|
|
2
|
-
import { Injector } from "@venok/core/injector/injector";
|
|
3
|
-
import { Module } from "@venok/core/injector/module/module";
|
|
4
|
-
export declare class MiddlewareResolver {
|
|
5
|
-
private readonly middlewareContainer;
|
|
6
|
-
private readonly injector;
|
|
7
|
-
constructor(middlewareContainer: MiddlewareContainer, injector: Injector);
|
|
8
|
-
resolveInstances(moduleRef: Module, moduleName: string): Promise<void>;
|
|
9
|
-
private resolveMiddlewareInstance;
|
|
10
|
-
}
|
package/middleware/resolver.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MiddlewareResolver = void 0;
|
|
4
|
-
const shared_helper_1 = require("../../core/helpers/shared.helper");
|
|
5
|
-
const constants_1 = require("../../core/injector/constants");
|
|
6
|
-
class MiddlewareResolver {
|
|
7
|
-
constructor(middlewareContainer, injector) {
|
|
8
|
-
this.middlewareContainer = middlewareContainer;
|
|
9
|
-
this.injector = injector;
|
|
10
|
-
}
|
|
11
|
-
async resolveInstances(moduleRef, moduleName) {
|
|
12
|
-
const middlewareMap = this.middlewareContainer.getMiddlewareCollection(moduleName);
|
|
13
|
-
const resolveInstance = async (wrapper) => this.resolveMiddlewareInstance(wrapper, middlewareMap, moduleRef);
|
|
14
|
-
await Promise.all([...middlewareMap.values()].map(resolveInstance));
|
|
15
|
-
}
|
|
16
|
-
async resolveMiddlewareInstance(wrapper, middlewareMap, moduleRef) {
|
|
17
|
-
const { metatype, token } = wrapper;
|
|
18
|
-
const targetWrapper = middlewareMap.get(token);
|
|
19
|
-
if (!targetWrapper)
|
|
20
|
-
return;
|
|
21
|
-
if (!(0, shared_helper_1.isUndefined)(targetWrapper.instance))
|
|
22
|
-
return;
|
|
23
|
-
targetWrapper.instance = Object.create(metatype.prototype);
|
|
24
|
-
await this.injector.loadInstance(wrapper, middlewareMap, moduleRef, constants_1.STATIC_CONTEXT, wrapper);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.MiddlewareResolver = MiddlewareResolver;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Type, VenokContainer } from "@venok/core";
|
|
2
|
-
import { HttpConfig } from "../application/config";
|
|
3
|
-
import { RouteInfo } from "../interfaces";
|
|
4
|
-
export declare class RoutesMapper {
|
|
5
|
-
private readonly container;
|
|
6
|
-
private readonly httpConfig;
|
|
7
|
-
private readonly pathsExplorer;
|
|
8
|
-
constructor(container: VenokContainer, httpConfig: HttpConfig);
|
|
9
|
-
mapRouteToRouteInfo(controllerOrRoute: Type | RouteInfo | string): RouteInfo[];
|
|
10
|
-
private getRouteInfoFromPath;
|
|
11
|
-
private getRouteInfoFromObject;
|
|
12
|
-
private getRouteInfoFromController;
|
|
13
|
-
private isRouteInfo;
|
|
14
|
-
private normalizeGlobalPath;
|
|
15
|
-
private getRoutePath;
|
|
16
|
-
private getHostModuleOfController;
|
|
17
|
-
private getModulePath;
|
|
18
|
-
private getVersionMetadata;
|
|
19
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoutesMapper = void 0;
|
|
4
|
-
const path_explorer_1 = require("../explorers/path.explorer");
|
|
5
|
-
const core_1 = require("../../core");
|
|
6
|
-
const interfaces_1 = require("../interfaces");
|
|
7
|
-
const shared_helper_1 = require("../../core/helpers/shared.helper");
|
|
8
|
-
const helpers_1 = require("../helpers");
|
|
9
|
-
const constants_1 = require("../constants");
|
|
10
|
-
const module_1 = require("../router/module");
|
|
11
|
-
const constants_2 = require("../../core/constants");
|
|
12
|
-
class RoutesMapper {
|
|
13
|
-
constructor(container, httpConfig) {
|
|
14
|
-
this.container = container;
|
|
15
|
-
this.httpConfig = httpConfig;
|
|
16
|
-
this.pathsExplorer = new path_explorer_1.PathsExplorer(new core_1.MetadataScanner());
|
|
17
|
-
}
|
|
18
|
-
mapRouteToRouteInfo(controllerOrRoute) {
|
|
19
|
-
if ((0, shared_helper_1.isString)(controllerOrRoute))
|
|
20
|
-
return this.getRouteInfoFromPath(controllerOrRoute);
|
|
21
|
-
const routePathOrPaths = this.getRoutePath(controllerOrRoute);
|
|
22
|
-
if (this.isRouteInfo(routePathOrPaths, controllerOrRoute))
|
|
23
|
-
return this.getRouteInfoFromObject(controllerOrRoute);
|
|
24
|
-
return this.getRouteInfoFromController(controllerOrRoute, routePathOrPaths);
|
|
25
|
-
}
|
|
26
|
-
getRouteInfoFromPath(routePath) {
|
|
27
|
-
const defaultRequestMethod = -1;
|
|
28
|
-
return [
|
|
29
|
-
{
|
|
30
|
-
path: (0, helpers_1.addLeadingSlash)(routePath),
|
|
31
|
-
method: defaultRequestMethod,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
}
|
|
35
|
-
getRouteInfoFromObject(routeInfoObject) {
|
|
36
|
-
const routeInfo = {
|
|
37
|
-
path: (0, helpers_1.addLeadingSlash)(routeInfoObject.path),
|
|
38
|
-
method: routeInfoObject.method,
|
|
39
|
-
};
|
|
40
|
-
if (routeInfoObject.version)
|
|
41
|
-
routeInfo.version = routeInfoObject.version;
|
|
42
|
-
return [routeInfo];
|
|
43
|
-
}
|
|
44
|
-
getRouteInfoFromController(controller, routePath) {
|
|
45
|
-
const controllerPaths = this.pathsExplorer.scanForPaths(Object.create(controller), controller.prototype);
|
|
46
|
-
const controllerVersion = this.getVersionMetadata(controller);
|
|
47
|
-
const versioningConfig = this.httpConfig.getVersioning();
|
|
48
|
-
const moduleRef = this.getHostModuleOfController(controller);
|
|
49
|
-
const modulePath = this.getModulePath(moduleRef?.metatype);
|
|
50
|
-
const concatPaths = (acc, currentValue) => acc.concat(currentValue);
|
|
51
|
-
const toUndefinedIfNeural = (version) => (version === interfaces_1.VERSION_NEUTRAL ? undefined : version);
|
|
52
|
-
const toRouteInfo = (item, prefix) => item.path
|
|
53
|
-
?.map((p) => {
|
|
54
|
-
let endpointPath = modulePath ?? "";
|
|
55
|
-
endpointPath += this.normalizeGlobalPath(prefix) + (0, helpers_1.addLeadingSlash)(p);
|
|
56
|
-
const routeInfo = {
|
|
57
|
-
path: endpointPath,
|
|
58
|
-
method: item.requestMethod,
|
|
59
|
-
};
|
|
60
|
-
const version = item.version ?? controllerVersion;
|
|
61
|
-
if (version && versioningConfig) {
|
|
62
|
-
if (typeof version !== "string" && Array.isArray(version)) {
|
|
63
|
-
return version.map((v) => ({
|
|
64
|
-
...routeInfo,
|
|
65
|
-
version: toUndefinedIfNeural(v),
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
routeInfo.version = toUndefinedIfNeural(version);
|
|
69
|
-
}
|
|
70
|
-
return routeInfo;
|
|
71
|
-
})
|
|
72
|
-
.flat();
|
|
73
|
-
const mapped = Array.isArray(routePath) ? routePath : [routePath];
|
|
74
|
-
return mapped
|
|
75
|
-
.map((path) => controllerPaths.map((item) => toRouteInfo(item, path)).reduce(concatPaths, []))
|
|
76
|
-
.reduce(concatPaths, []);
|
|
77
|
-
}
|
|
78
|
-
isRouteInfo(path, objectOrClass) {
|
|
79
|
-
return (0, shared_helper_1.isUndefined)(path);
|
|
80
|
-
}
|
|
81
|
-
normalizeGlobalPath(path) {
|
|
82
|
-
const prefix = (0, helpers_1.addLeadingSlash)(path);
|
|
83
|
-
return prefix === "/" ? "" : prefix;
|
|
84
|
-
}
|
|
85
|
-
getRoutePath(route) {
|
|
86
|
-
return Reflect.getMetadata(constants_1.PATH_METADATA, route);
|
|
87
|
-
}
|
|
88
|
-
getHostModuleOfController(metatype) {
|
|
89
|
-
if (!metatype)
|
|
90
|
-
return;
|
|
91
|
-
const modulesContainer = this.container.getModules();
|
|
92
|
-
const moduleRefsSet = module_1.targetModulesByContainer.get(modulesContainer);
|
|
93
|
-
if (!moduleRefsSet)
|
|
94
|
-
return;
|
|
95
|
-
const modules = Array.from(modulesContainer.values()).filter((moduleRef) => moduleRefsSet.has(moduleRef));
|
|
96
|
-
return modules.find(({ injectables }) => injectables.has(metatype));
|
|
97
|
-
}
|
|
98
|
-
getModulePath(metatype) {
|
|
99
|
-
if (!metatype)
|
|
100
|
-
return;
|
|
101
|
-
const modulesContainer = this.container.getModules();
|
|
102
|
-
const modulePath = Reflect.getMetadata(constants_2.MODULE_PATH + modulesContainer.applicationId, metatype);
|
|
103
|
-
return modulePath ?? Reflect.getMetadata(constants_2.MODULE_PATH, metatype);
|
|
104
|
-
}
|
|
105
|
-
getVersionMetadata(metatype) {
|
|
106
|
-
const versioningConfig = this.httpConfig.getVersioning();
|
|
107
|
-
if (versioningConfig)
|
|
108
|
-
return Reflect.getMetadata(constants_1.VERSION_METADATA, metatype) ?? versioningConfig.defaultVersion;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.RoutesMapper = RoutesMapper;
|
package/middleware/utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ExcludeRouteMetadata, HttpServer, RouteInfo } from "../interfaces";
|
|
2
|
-
import { Type } from "@venok/core";
|
|
3
|
-
export declare const mapToExcludeRoute: (routes: (string | RouteInfo)[]) => ExcludeRouteMetadata[];
|
|
4
|
-
export declare const filterMiddleware: <T extends Function | Type<any> = any>(middleware: T[], routes: RouteInfo[], httpAdapter: HttpServer) => Type<any>[];
|
|
5
|
-
export declare const mapToClass: <T extends Function | Type<any>>(middleware: T, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer) => Type<any>;
|
|
6
|
-
export declare function isMiddlewareClass(middleware: any): middleware is Type;
|
|
7
|
-
export declare function assignToken(metatype: Type, token?: string): Type;
|
|
8
|
-
export declare function isMiddlewareRouteExcluded(req: Record<string, any>, excludedRoutes: ExcludeRouteMetadata[], httpAdapter: HttpServer): boolean;
|
package/middleware/utils.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMiddlewareRouteExcluded = exports.assignToken = exports.isMiddlewareClass = exports.mapToClass = exports.filterMiddleware = exports.mapToExcludeRoute = void 0;
|
|
4
|
-
const path_to_regexp_1 = require("path-to-regexp");
|
|
5
|
-
const uid_1 = require("uid");
|
|
6
|
-
const shared_helper_1 = require("../../core/helpers/shared.helper");
|
|
7
|
-
const enums_1 = require("../enums");
|
|
8
|
-
const helpers_1 = require("../helpers");
|
|
9
|
-
const mapToExcludeRoute = (routes) => {
|
|
10
|
-
return routes.map((route) => {
|
|
11
|
-
if ((0, shared_helper_1.isString)(route)) {
|
|
12
|
-
return {
|
|
13
|
-
path: route,
|
|
14
|
-
requestMethod: enums_1.RequestMethod.ALL,
|
|
15
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, helpers_1.addLeadingSlash)(route)),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
path: route.path,
|
|
20
|
-
requestMethod: route.method,
|
|
21
|
-
pathRegex: (0, path_to_regexp_1.pathToRegexp)((0, helpers_1.addLeadingSlash)(route.path)),
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
exports.mapToExcludeRoute = mapToExcludeRoute;
|
|
26
|
-
const filterMiddleware = (middleware, routes, httpAdapter) => {
|
|
27
|
-
const excludedRoutes = (0, exports.mapToExcludeRoute)(routes);
|
|
28
|
-
return middleware.filter(shared_helper_1.isFunction).map((item) => (0, exports.mapToClass)(item, excludedRoutes, httpAdapter));
|
|
29
|
-
};
|
|
30
|
-
exports.filterMiddleware = filterMiddleware;
|
|
31
|
-
const mapToClass = (middleware, excludedRoutes, httpAdapter) => {
|
|
32
|
-
if (isMiddlewareClass(middleware)) {
|
|
33
|
-
if (excludedRoutes.length <= 0) {
|
|
34
|
-
return middleware;
|
|
35
|
-
}
|
|
36
|
-
const MiddlewareHost = class extends middleware {
|
|
37
|
-
use(...params) {
|
|
38
|
-
const [req, _, next] = params;
|
|
39
|
-
const isExcluded = isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter);
|
|
40
|
-
if (isExcluded) {
|
|
41
|
-
return next();
|
|
42
|
-
}
|
|
43
|
-
return super.use(...params);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
return assignToken(MiddlewareHost, middleware.name);
|
|
47
|
-
}
|
|
48
|
-
return assignToken(class {
|
|
49
|
-
constructor() {
|
|
50
|
-
this.use = (...params) => {
|
|
51
|
-
const [req, _, next] = params;
|
|
52
|
-
const isExcluded = isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter);
|
|
53
|
-
if (isExcluded) {
|
|
54
|
-
return next();
|
|
55
|
-
}
|
|
56
|
-
return middleware(...params);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
exports.mapToClass = mapToClass;
|
|
62
|
-
function isMiddlewareClass(middleware) {
|
|
63
|
-
const middlewareStr = middleware.toString();
|
|
64
|
-
if (middlewareStr.substring(0, 5) === "class") {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
const middlewareArr = middlewareStr.split(" ");
|
|
68
|
-
return (middlewareArr[0] === "function" && /[A-Z]/.test(middlewareArr[1]?.[0]) && (0, shared_helper_1.isFunction)(middleware.prototype?.use));
|
|
69
|
-
}
|
|
70
|
-
exports.isMiddlewareClass = isMiddlewareClass;
|
|
71
|
-
function assignToken(metatype, token = (0, uid_1.uid)(21)) {
|
|
72
|
-
Object.defineProperty(metatype, "name", { value: token });
|
|
73
|
-
return metatype;
|
|
74
|
-
}
|
|
75
|
-
exports.assignToken = assignToken;
|
|
76
|
-
function isMiddlewareRouteExcluded(req, excludedRoutes, httpAdapter) {
|
|
77
|
-
if (excludedRoutes.length <= 0 || !httpAdapter.getRequestUrl || !httpAdapter.getRequestMethod) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const reqMethod = httpAdapter.getRequestMethod(req);
|
|
81
|
-
const originalUrl = httpAdapter.getRequestUrl(req);
|
|
82
|
-
const queryParamsIndex = originalUrl && originalUrl.indexOf("?");
|
|
83
|
-
const pathname = (0, shared_helper_1.isNumber)(queryParamsIndex) && queryParamsIndex >= 0 ? originalUrl.slice(0, +queryParamsIndex) : originalUrl;
|
|
84
|
-
return (0, helpers_1.isRouteExcluded)(excludedRoutes, pathname, enums_1.RequestMethod[reqMethod]);
|
|
85
|
-
}
|
|
86
|
-
exports.isMiddlewareRouteExcluded = isMiddlewareRouteExcluded;
|
package/router/module.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { DynamicModule, ModulesContainer } from "@venok/core";
|
|
2
|
-
import { Module as ModuleClass } from "@venok/core/injector/module/module";
|
|
3
|
-
import { Routes } from "../interfaces";
|
|
4
|
-
export declare const ROUTES: unique symbol;
|
|
5
|
-
export declare const targetModulesByContainer: WeakMap<ModulesContainer, WeakSet<ModuleClass>>;
|
|
6
|
-
/**
|
|
7
|
-
* @publicApi
|
|
8
|
-
*/
|
|
9
|
-
export declare class RouterModule {
|
|
10
|
-
private readonly modulesContainer;
|
|
11
|
-
private readonly routes;
|
|
12
|
-
constructor(modulesContainer: ModulesContainer, routes: Routes);
|
|
13
|
-
static register(routes: Routes): DynamicModule;
|
|
14
|
-
private deepCloneRoutes;
|
|
15
|
-
private initialize;
|
|
16
|
-
private registerModulePathMetadata;
|
|
17
|
-
private updateTargetModulesCache;
|
|
18
|
-
}
|