@deepkit/http 1.0.1-alpha.71 → 1.0.1-alpha.74
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/cjs/src/decorator.d.ts +8 -6
- package/dist/cjs/src/decorator.js +49 -12
- package/dist/cjs/src/decorator.js.map +1 -1
- package/dist/cjs/src/filter.d.ts +3 -3
- package/dist/cjs/src/filter.js +3 -3
- package/dist/cjs/src/filter.js.map +1 -1
- package/dist/cjs/src/http.d.ts +49 -11
- package/dist/cjs/src/http.js +125 -39
- package/dist/cjs/src/http.js.map +1 -1
- package/dist/cjs/src/kernel.d.ts +3 -3
- package/dist/cjs/src/kernel.js +1 -1
- package/dist/cjs/src/kernel.js.map +1 -1
- package/dist/cjs/src/model.d.ts +11 -3
- package/dist/cjs/src/model.js +59 -27
- package/dist/cjs/src/model.js.map +1 -1
- package/dist/cjs/src/module.js +5 -3
- package/dist/cjs/src/module.js.map +1 -1
- package/dist/cjs/src/router.d.ts +84 -11
- package/dist/cjs/src/router.js +292 -96
- package/dist/cjs/src/router.js.map +1 -1
- package/dist/cjs/src/static-serving.js +15 -8
- package/dist/cjs/src/static-serving.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/decorator.d.ts +8 -6
- package/dist/esm/src/decorator.js +47 -11
- package/dist/esm/src/decorator.js.map +1 -1
- package/dist/esm/src/filter.d.ts +3 -3
- package/dist/esm/src/filter.js +4 -4
- package/dist/esm/src/filter.js.map +1 -1
- package/dist/esm/src/http.d.ts +49 -11
- package/dist/esm/src/http.js +112 -39
- package/dist/esm/src/http.js.map +1 -1
- package/dist/esm/src/kernel.d.ts +3 -3
- package/dist/esm/src/kernel.js +2 -2
- package/dist/esm/src/kernel.js.map +1 -1
- package/dist/esm/src/model.d.ts +11 -3
- package/dist/esm/src/model.js +51 -19
- package/dist/esm/src/model.js.map +1 -1
- package/dist/esm/src/module.js +6 -4
- package/dist/esm/src/module.js.map +1 -1
- package/dist/esm/src/router.d.ts +84 -11
- package/dist/esm/src/router.js +291 -97
- package/dist/esm/src/router.js.map +1 -1
- package/dist/esm/src/static-serving.js +16 -9
- package/dist/esm/src/static-serving.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +17 -14
- package/src/decorator.ts +9 -6
- package/src/filter.ts +4 -4
- package/src/http.ts +83 -15
- package/src/kernel.ts +2 -2
- package/src/model.ts +35 -6
- package/src/module.ts +5 -3
- package/src/router.ts +298 -77
- package/src/static-serving.ts +6 -3
- package/coverage/clover.xml +0 -1086
- package/coverage/coverage-final.json +0 -12
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/controllers.ts.html +0 -113
- package/coverage/lcov-report/src/decorator.ts.html +0 -1280
- package/coverage/lcov-report/src/filter.ts.html +0 -734
- package/coverage/lcov-report/src/http.ts.html +0 -2192
- package/coverage/lcov-report/src/index.html +0 -246
- package/coverage/lcov-report/src/kernel.ts.html +0 -260
- package/coverage/lcov-report/src/middleware.ts.html +0 -428
- package/coverage/lcov-report/src/model.ts.html +0 -937
- package/coverage/lcov-report/src/module.config.ts.html +0 -89
- package/coverage/lcov-report/src/module.ts.html +0 -245
- package/coverage/lcov-report/src/router.ts.html +0 -2318
- package/coverage/lcov-report/tests/index.html +0 -111
- package/coverage/lcov-report/tests/utils.ts.html +0 -176
- package/coverage/lcov.info +0 -2225
- package/dist/cjs/tests/filter.spec.d.ts +0 -1
- package/dist/cjs/tests/filter.spec.js +0 -251
- package/dist/cjs/tests/filter.spec.js.map +0 -1
- package/dist/cjs/tests/middleware.spec.d.ts +0 -1
- package/dist/cjs/tests/middleware.spec.js +0 -471
- package/dist/cjs/tests/middleware.spec.js.map +0 -1
- package/dist/cjs/tests/model.spec.d.ts +0 -1
- package/dist/cjs/tests/model.spec.js +0 -23
- package/dist/cjs/tests/model.spec.js.map +0 -1
- package/dist/cjs/tests/module.spec.d.ts +0 -1
- package/dist/cjs/tests/module.spec.js +0 -46
- package/dist/cjs/tests/module.spec.js.map +0 -1
- package/dist/cjs/tests/router.spec.d.ts +0 -1
- package/dist/cjs/tests/router.spec.js +0 -987
- package/dist/cjs/tests/router.spec.js.map +0 -1
- package/dist/cjs/tests/utils.d.ts +0 -8
- package/dist/cjs/tests/utils.js +0 -30
- package/dist/cjs/tests/utils.js.map +0 -1
- package/dist/esm/tests/filter.spec.d.ts +0 -1
- package/dist/esm/tests/filter.spec.js +0 -249
- package/dist/esm/tests/filter.spec.js.map +0 -1
- package/dist/esm/tests/middleware.spec.d.ts +0 -1
- package/dist/esm/tests/middleware.spec.js +0 -469
- package/dist/esm/tests/middleware.spec.js.map +0 -1
- package/dist/esm/tests/model.spec.d.ts +0 -1
- package/dist/esm/tests/model.spec.js +0 -21
- package/dist/esm/tests/model.spec.js.map +0 -1
- package/dist/esm/tests/module.spec.d.ts +0 -1
- package/dist/esm/tests/module.spec.js +0 -44
- package/dist/esm/tests/module.spec.js.map +0 -1
- package/dist/esm/tests/router.spec.d.ts +0 -1
- package/dist/esm/tests/router.spec.js +0 -985
- package/dist/esm/tests/router.spec.js.map +0 -1
- package/dist/esm/tests/utils.d.ts +0 -8
- package/dist/esm/tests/utils.js +0 -26
- package/dist/esm/tests/utils.js.map +0 -1
- package/tests/filter.spec.ts +0 -181
- package/tests/middleware.spec.ts +0 -440
- package/tests/model.spec.ts +0 -26
- package/tests/module.spec.ts +0 -32
- package/tests/router.spec.ts +0 -781
- package/tests/utils.ts +0 -32
package/dist/esm/src/router.js
CHANGED
|
@@ -7,10 +7,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { __ΩSerializationOptions as __ΩSerializationOptions } from '@deepkit/type';
|
|
8
8
|
import { __ΩClassType as __ΩClassType } from '@deepkit/core';
|
|
9
9
|
import { __ΩMiddlewareRegistryEntry as __ΩMiddlewareRegistryEntry } from '@deepkit/app';
|
|
10
|
+
import { __ΩHttpDecorator as __ΩHttpDecorator } from './decorator';
|
|
10
11
|
import { __ΩLoggerInterface as __ΩLoggerInterface } from '@deepkit/logger';
|
|
11
12
|
import { __ΩHttpMiddlewareFn as __ΩHttpMiddlewareFn } from './middleware';
|
|
12
13
|
import { __ΩHttpRequestQuery as __ΩHttpRequestQuery } from './model';
|
|
13
14
|
import { __ΩHttpRequestResolvedParameters as __ΩHttpRequestResolvedParameters } from './model';
|
|
15
|
+
function __assignType(fn, args) {
|
|
16
|
+
fn.__type = args;
|
|
17
|
+
return fn;
|
|
18
|
+
}
|
|
19
|
+
const __ΩPartial = ['T', 'l+e#!e"!fRb!Pde"!gN#"'];
|
|
20
|
+
const __ΩRecord = ['K', 'T', 'l\'e#"Rb!b"Pde"!N#!'];
|
|
14
21
|
/*
|
|
15
22
|
* Deepkit Framework
|
|
16
23
|
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
|
|
@@ -20,11 +27,11 @@ import { __ΩHttpRequestResolvedParameters as __ΩHttpRequestResolvedParameters
|
|
|
20
27
|
*
|
|
21
28
|
* You should have received a copy of the MIT License along with this program.
|
|
22
29
|
*/
|
|
23
|
-
import { asyncOperation, CompilerContext, getClassName, isClass, isObject, urlJoin } from '@deepkit/core';
|
|
24
|
-
import { assertType, entity, findMember, getSerializeFunction, getValidatorFunction, metaAnnotation, ReflectionClass, ReflectionParameter, serializer, Serializer, stringifyType, typeToObject, ValidationError } from '@deepkit/type';
|
|
30
|
+
import { asyncOperation, CompilerContext, getClassName, isArray, isClass, isObject, urlJoin } from '@deepkit/core';
|
|
31
|
+
import { assertType, entity, findMember, getSerializeFunction, getValidatorFunction, metaAnnotation, ReflectionClass, ReflectionFunction, ReflectionKind, ReflectionParameter, serializer, Serializer, stringifyType, typeToObject, ValidationError } from '@deepkit/type';
|
|
25
32
|
// @ts-ignore
|
|
26
33
|
import formidable from 'formidable';
|
|
27
|
-
import { httpClass } from './decorator';
|
|
34
|
+
import { HttpAction, httpClass, HttpController } from './decorator';
|
|
28
35
|
import { BodyValidationError, getRegExp, HttpRequest, ValidatedBody } from './model';
|
|
29
36
|
import { InjectorContext, InjectorModule, TagRegistry } from '@deepkit/injector';
|
|
30
37
|
import { Logger } from '@deepkit/logger';
|
|
@@ -33,6 +40,7 @@ import { MiddlewareRegistry } from '@deepkit/app';
|
|
|
33
40
|
import { HttpMiddlewareConfig } from './middleware';
|
|
34
41
|
//@ts-ignore
|
|
35
42
|
import qs from 'qs';
|
|
43
|
+
import { HtmlResponse, JSONResponse, Response } from './http.js';
|
|
36
44
|
const __ΩRouteParameterResolverForInjector = [() => InjectorContext, 'injector', '', 'PP7!2"P"F"F`J/#'];
|
|
37
45
|
export { __ΩRouteParameterResolverForInjector as __ΩRouteParameterResolverForInjector };
|
|
38
46
|
const __ΩResolvedController = [() => __ΩRouteParameterResolverForInjector, 'parameters', () => RouteConfig, 'routeConfig', () => UploadedFile, 'uploadedFiles', () => InjectorContext, 'injector', () => __ΩHttpMiddlewareFn, 'fn', 'timeout', '', 'middlewares', 'Pn!4"P7#4$P&P7%LM4&PP7\'2(Pn)4*\'4+MF/,4-8M'];
|
|
@@ -43,12 +51,10 @@ UploadedFile = __decorate([
|
|
|
43
51
|
entity.name('@deepkit/UploadedFile')
|
|
44
52
|
], UploadedFile);
|
|
45
53
|
export { UploadedFile };
|
|
46
|
-
const __Ω
|
|
47
|
-
export { __Ω
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
getRouterControllerActionName.__type = [() => __ΩRouteControllerAction, 'action', 'getRouterControllerActionName', 'Pn!2"&/#'];
|
|
54
|
+
const __ΩRouteFunctionControllerAction = ["function", 'type', () => InjectorModule, 'module', 'args', '', 'fn', 'P.!4"P"7#4$8P"@2%"/&4\'M'];
|
|
55
|
+
export { __ΩRouteFunctionControllerAction as __ΩRouteFunctionControllerAction };
|
|
56
|
+
const __ΩRouteClassControllerAction = ["controller", 'type', () => InjectorModule, 'module', () => __ΩClassType, 'controller', 'methodName', 'P.!4"P"7#4$8n%4&&4\'M'];
|
|
57
|
+
export { __ΩRouteClassControllerAction as __ΩRouteClassControllerAction };
|
|
52
58
|
export class RouteConfig {
|
|
53
59
|
constructor(name, httpMethods, path, action, internal = false) {
|
|
54
60
|
this.name = name;
|
|
@@ -69,6 +75,11 @@ export class RouteConfig {
|
|
|
69
75
|
*/
|
|
70
76
|
this.data = new Map();
|
|
71
77
|
}
|
|
78
|
+
getReflectionFunction() {
|
|
79
|
+
return this.action.type === 'controller' ?
|
|
80
|
+
ReflectionClass.from(this.action.controller).getMethod(this.action.methodName)
|
|
81
|
+
: ReflectionFunction.from(this.action.fn);
|
|
82
|
+
}
|
|
72
83
|
getSchemaForResponse(statusCode) {
|
|
73
84
|
if (!this.responses.length)
|
|
74
85
|
return;
|
|
@@ -85,7 +96,7 @@ export class RouteConfig {
|
|
|
85
96
|
return path;
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
|
-
RouteConfig.__type = ['baseUrl', function () { return ''; }, 'statusCode', 'description', 'type', 'responses', function () { return []; }, function () { return ''; }, 'groups', function () { return []; }, 'category', function () { return ''; }, 'returnType', () => __ΩSerializationOptions, 'serializationOptions', () => Serializer, 'serializer', () => InjectorModule, 'module', () => __ΩClassType, 'resolverForToken', function () { return new Map(); }, () => HttpMiddlewareConfig, 'config', () => InjectorModule, 'middlewares', function () { return []; }, () => __ΩClassType, 'resolverForParameterName', function () { return new Map(); }, 'name', 'httpMethods', 'path', () => __Ω
|
|
99
|
+
RouteConfig.__type = ['baseUrl', function () { return ''; }, 'statusCode', 'description', 'type', 'responses', function () { return []; }, function () { return ''; }, 'groups', function () { return []; }, 'category', function () { return ''; }, 'returnType', () => __ΩSerializationOptions, 'serializationOptions', () => Serializer, 'serializer', () => InjectorModule, 'module', () => __ΩClassType, 'resolverForToken', function () { return new Map(); }, () => HttpMiddlewareConfig, 'config', () => InjectorModule, 'middlewares', function () { return []; }, () => __ΩClassType, 'resolverForParameterName', function () { return new Map(); }, 'name', 'httpMethods', 'path', () => __ΩRouteClassControllerAction, () => __ΩRouteFunctionControllerAction, 'action', 'internal', () => false, 'constructor', () => ReflectionFunction, 'getReflectionFunction', 'getSchemaForResponse', 'getFullPath', '&3!>"P\'4#&4$"4%8MF3&>\'&3$>(&F3)>*&3+>,"3-8n.3/8P70318P"72338"n4E35>6PP7748P"79438MF3:>;&n<E3=>>P&2?:9&F2@:9&2A:9PnBnCJ2D:9)2E:>F"0GPP7H0IP\'2#P"-J0JP&0K5'];
|
|
89
100
|
class ParsedRoute {
|
|
90
101
|
constructor(routeConfig) {
|
|
91
102
|
this.routeConfig = routeConfig;
|
|
@@ -121,9 +132,9 @@ class ParsedRouteParameter {
|
|
|
121
132
|
}
|
|
122
133
|
getType() {
|
|
123
134
|
if (this.bodyValidation) {
|
|
124
|
-
assertType(this.parameter.type,
|
|
125
|
-
const valueType = findMember('value', this.parameter.type);
|
|
126
|
-
if (!valueType || valueType.kind !==
|
|
135
|
+
assertType(this.parameter.type, ReflectionKind.class);
|
|
136
|
+
const valueType = findMember('value', this.parameter.type.types);
|
|
137
|
+
if (!valueType || valueType.kind !== ReflectionKind.property)
|
|
127
138
|
throw new Error(`No property value found at ${stringifyType(this.parameter.type)}`);
|
|
128
139
|
return valueType.type;
|
|
129
140
|
}
|
|
@@ -155,26 +166,29 @@ ParsedRouteParameter.__type = ['regexPosition', () => ReflectionParameter, 'para
|
|
|
155
166
|
function parseRoutePathToRegex(routeConfig) {
|
|
156
167
|
const parameterNames = {};
|
|
157
168
|
let path = routeConfig.getFullPath();
|
|
158
|
-
const
|
|
169
|
+
const fn = routeConfig.getReflectionFunction();
|
|
159
170
|
let argumentIndex = 0;
|
|
160
|
-
path = path.replace(/:(\w+)/g,
|
|
171
|
+
path = path.replace(/:(\w+)/g, __assignType((a, name) => {
|
|
161
172
|
parameterNames[name] = argumentIndex;
|
|
162
173
|
argumentIndex++;
|
|
163
|
-
const parameter =
|
|
174
|
+
const parameter = fn.getParameterOrUndefined(name);
|
|
164
175
|
if (parameter) {
|
|
165
176
|
const regExp = getRegExp(parameter.type);
|
|
166
|
-
if (regExp)
|
|
177
|
+
if (regExp instanceof RegExp) {
|
|
178
|
+
return '(' + regExp.source + ')';
|
|
179
|
+
}
|
|
180
|
+
else if (regExp) {
|
|
167
181
|
return '(' + regExp + ')';
|
|
182
|
+
}
|
|
168
183
|
}
|
|
169
184
|
return String.raw `([^/]+)`;
|
|
170
|
-
},
|
|
185
|
+
}, ['a', 'name', '', 'P"2!"2""/#']));
|
|
171
186
|
return { regex: path, parameterNames };
|
|
172
187
|
}
|
|
173
188
|
parseRoutePathToRegex.__type = [() => RouteConfig, 'routeConfig', 'regex', 'parameterNames', 'parseRoutePathToRegex', 'PP7!2"P&4#P&\'LM4$M/%'];
|
|
174
189
|
export function parseRouteControllerAction(routeConfig) {
|
|
175
|
-
const schema = ReflectionClass.from(routeConfig.action.controller);
|
|
176
190
|
const parsedRoute = new ParsedRoute(routeConfig);
|
|
177
|
-
const methodArgumentProperties =
|
|
191
|
+
const methodArgumentProperties = routeConfig.getReflectionFunction().getParameters();
|
|
178
192
|
const parsedPath = parseRoutePathToRegex(routeConfig);
|
|
179
193
|
parsedRoute.regex = parsedPath.regex;
|
|
180
194
|
parsedRoute.pathParameterNames = parsedPath.parameterNames;
|
|
@@ -198,14 +212,14 @@ export { __ΩRouteParameterResolverContext as __ΩRouteParameterResolverContext
|
|
|
198
212
|
function filterMiddlewaresForRoute(middlewareRawConfigs, routeConfig, fullPath) {
|
|
199
213
|
const middlewares = middlewareRawConfigs.slice(0);
|
|
200
214
|
middlewares.push(...routeConfig.middlewares);
|
|
201
|
-
const middlewareConfigs = middlewares.filter(
|
|
215
|
+
const middlewareConfigs = middlewares.filter(__assignType((v) => {
|
|
202
216
|
var _a;
|
|
203
217
|
if (!(v.config instanceof HttpMiddlewareConfig))
|
|
204
218
|
return false;
|
|
205
|
-
if (v.config.controllers.length && !v.config.controllers.includes(routeConfig.action.controller)) {
|
|
219
|
+
if (v.config.controllers.length && routeConfig.action.type === 'controller' && !v.config.controllers.includes(routeConfig.action.controller)) {
|
|
206
220
|
return false;
|
|
207
221
|
}
|
|
208
|
-
if (v.config.excludeControllers.length && v.config.excludeControllers.includes(routeConfig.action.controller)) {
|
|
222
|
+
if (v.config.excludeControllers.length && routeConfig.action.type === 'controller' && v.config.excludeControllers.includes(routeConfig.action.controller)) {
|
|
209
223
|
return false;
|
|
210
224
|
}
|
|
211
225
|
if (v.config.modules.length && (!routeConfig.module || !v.config.modules.includes(routeConfig.module))) {
|
|
@@ -219,16 +233,22 @@ function filterMiddlewaresForRoute(middlewareRawConfigs, routeConfig, fullPath)
|
|
|
219
233
|
if (v.config.selfModule && v.module.id !== ((_a = routeConfig.module) === null || _a === void 0 ? void 0 : _a.id))
|
|
220
234
|
return false;
|
|
221
235
|
if (v.config.routeNames.length) {
|
|
236
|
+
let found = false;
|
|
222
237
|
for (const name of v.config.routeNames) {
|
|
223
238
|
if (name.includes('*')) {
|
|
224
239
|
const regex = new RegExp('^' + name.replace(/\*/g, '.*') + '$');
|
|
225
|
-
if (
|
|
226
|
-
|
|
240
|
+
if (regex.test(routeConfig.name)) {
|
|
241
|
+
found = true;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
227
244
|
}
|
|
228
|
-
else if (name
|
|
229
|
-
|
|
245
|
+
else if (name === routeConfig.name) {
|
|
246
|
+
found = true;
|
|
247
|
+
break;
|
|
230
248
|
}
|
|
231
249
|
}
|
|
250
|
+
if (!found)
|
|
251
|
+
return false;
|
|
232
252
|
}
|
|
233
253
|
if (v.config.excludeRouteNames.length) {
|
|
234
254
|
for (const name of v.config.excludeRouteNames) {
|
|
@@ -261,63 +281,274 @@ function filterMiddlewaresForRoute(middlewareRawConfigs, routeConfig, fullPath)
|
|
|
261
281
|
}
|
|
262
282
|
}
|
|
263
283
|
return true;
|
|
264
|
-
},
|
|
265
|
-
middlewareConfigs.sort(
|
|
284
|
+
}, ['v', '', 'P"2!"/"']));
|
|
285
|
+
middlewareConfigs.sort(__assignType((a, b) => {
|
|
266
286
|
return a.config.order - b.config.order;
|
|
267
|
-
},
|
|
287
|
+
}, ['a', 'b', '', 'P"2!"2""/#']));
|
|
268
288
|
return middlewareConfigs;
|
|
269
289
|
}
|
|
270
290
|
filterMiddlewaresForRoute.__type = [() => __ΩMiddlewareRegistryEntry, 'middlewareRawConfigs', () => RouteConfig, 'routeConfig', 'fullPath', () => HttpMiddlewareConfig, 'config', () => InjectorModule, 'module', 'filterMiddlewaresForRoute', 'Pn!F2"P7#2$&2%PP7&4\'P"7(4)MF/*'];
|
|
271
|
-
|
|
272
|
-
|
|
291
|
+
const __ΩHttpRouterFunctionOptions = ['path', 'name', 'methods', 'description', 'category', 'groups', () => __ΩRecord, 'data', 'baseUrl', () => HttpMiddlewareConfig, '', 'middlewares', () => Serializer, 'serializer', () => __ΩSerializationOptions, 'serializationOptions', () => __ΩClassType, 'resolverForToken', () => __ΩClassType, 'resolverForParameterName', 'statusCode', 'type', 'responses', 'P&4!&4"8&F4#8&4$8&4%8&F4&8""o\'#4(8&4)8PP7*/+F4,8P7-4.8n/408"n1E428&n3E448P\'45&4$"468MF478M'];
|
|
292
|
+
export { __ΩHttpRouterFunctionOptions as __ΩHttpRouterFunctionOptions };
|
|
293
|
+
function convertOptions(methods, pathOrOptions, defaultOptions) {
|
|
294
|
+
const options = 'string' === typeof pathOrOptions ? { path: pathOrOptions } : pathOrOptions;
|
|
295
|
+
if (options.methods)
|
|
296
|
+
return options;
|
|
297
|
+
return { ...options, methods };
|
|
298
|
+
}
|
|
299
|
+
convertOptions.__type = ['methods', () => __ΩHttpRouterFunctionOptions, 'pathOrOptions', () => __ΩPartial, () => __ΩHttpRouterFunctionOptions, 'defaultOptions', () => __ΩHttpRouterFunctionOptions, 'convertOptions', 'P&F2!P&n"J2#n%o$"2&n\'/('];
|
|
300
|
+
/**
|
|
301
|
+
* Annotated types like HTMLResponse/JSONResponse are not used for serialization.
|
|
302
|
+
*/
|
|
303
|
+
function filterValidReturnType(type) {
|
|
304
|
+
if (type.kind === ReflectionKind.class && (type.classType === HtmlResponse || type.classType === JSONResponse || type.classType === Response))
|
|
305
|
+
return;
|
|
306
|
+
return type;
|
|
307
|
+
}
|
|
308
|
+
filterValidReturnType.__type = ['type', 'filterValidReturnType', 'P"2!P"-J/"'];
|
|
309
|
+
export class HttpRouterRegistryFunctionRegistrar {
|
|
310
|
+
constructor() {
|
|
311
|
+
this.defaultOptions = {};
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Returns a new registrar object with default options that apply to each registered route through this registrar.
|
|
315
|
+
*
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const registry: HttpRouterRegistry = ...;
|
|
318
|
+
*
|
|
319
|
+
* const secretRegistry = registry.forOptions({groups: ['secret']});
|
|
320
|
+
*
|
|
321
|
+
* secretRegistry.get('/admin/groups', () => {
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* secretRegistry.get('/admin/users', () => {
|
|
325
|
+
* });
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
forOptions(options) {
|
|
329
|
+
var _a;
|
|
330
|
+
const that = this;
|
|
331
|
+
return new (_a = class extends HttpRouterRegistryFunctionRegistrar {
|
|
332
|
+
constructor() {
|
|
333
|
+
super(...arguments);
|
|
334
|
+
this.defaultOptions = options;
|
|
335
|
+
}
|
|
336
|
+
addRoute(routeConfig) {
|
|
337
|
+
that.addRoute(routeConfig);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
_a.__type = [() => HttpRouterRegistryFunctionRegistrar, () => RouteConfig, 'routeConfig', 'addRoute', 'P7!PP7"2#"0$5'],
|
|
341
|
+
_a);
|
|
342
|
+
}
|
|
343
|
+
any(pathOrOptions, callback) {
|
|
344
|
+
this.register(convertOptions([], pathOrOptions, this.defaultOptions), callback);
|
|
345
|
+
}
|
|
346
|
+
add(decorator, callback) {
|
|
347
|
+
const data = decorator(Object, '_');
|
|
348
|
+
const action = isArray(data) ? data.find(__assignType(v => v instanceof HttpAction, ['v', '', 'P"2!"/"'])) : undefined;
|
|
349
|
+
if (!action)
|
|
350
|
+
throw new Error('No HttpAction available');
|
|
351
|
+
const fn = ReflectionFunction.from(callback);
|
|
352
|
+
const routeConfig = createRouteConfigFromHttpAction({
|
|
353
|
+
type: 'function',
|
|
354
|
+
fn: callback,
|
|
355
|
+
}, action);
|
|
356
|
+
routeConfig.returnType = filterValidReturnType(fn.getReturnType());
|
|
357
|
+
this.addRoute(routeConfig);
|
|
358
|
+
}
|
|
359
|
+
get(pathOrOptions, callback) {
|
|
360
|
+
this.register(convertOptions(['GET'], pathOrOptions, this.defaultOptions), callback);
|
|
361
|
+
}
|
|
362
|
+
post(pathOrOptions, callback) {
|
|
363
|
+
this.register(convertOptions(['POST'], pathOrOptions, this.defaultOptions), callback);
|
|
364
|
+
}
|
|
365
|
+
put(pathOrOptions, callback) {
|
|
366
|
+
this.register(convertOptions(['PUT'], pathOrOptions, this.defaultOptions), callback);
|
|
367
|
+
}
|
|
368
|
+
patch(pathOrOptions, callback) {
|
|
369
|
+
this.register(convertOptions(['PATCH'], pathOrOptions, this.defaultOptions), callback);
|
|
370
|
+
}
|
|
371
|
+
delete(pathOrOptions, callback) {
|
|
372
|
+
this.register(convertOptions(['DELETE'], pathOrOptions, this.defaultOptions), callback);
|
|
373
|
+
}
|
|
374
|
+
options(pathOrOptions, callback) {
|
|
375
|
+
this.register(convertOptions(['OPTIONS'], pathOrOptions, this.defaultOptions), callback);
|
|
376
|
+
}
|
|
377
|
+
trace(pathOrOptions, callback) {
|
|
378
|
+
this.register(convertOptions(['TRACE'], pathOrOptions, this.defaultOptions), callback);
|
|
379
|
+
}
|
|
380
|
+
head(pathOrOptions, callback) {
|
|
381
|
+
this.register(convertOptions(['HEAD'], pathOrOptions, this.defaultOptions), callback);
|
|
382
|
+
}
|
|
383
|
+
register(options, callback, module) {
|
|
384
|
+
const fn = ReflectionFunction.from(callback);
|
|
385
|
+
const routeConfig = new RouteConfig(options.name || '', options.methods || [], options.path, {
|
|
386
|
+
type: 'function',
|
|
387
|
+
fn: callback,
|
|
388
|
+
});
|
|
389
|
+
routeConfig.module = module;
|
|
390
|
+
if (options.responses)
|
|
391
|
+
routeConfig.responses = options.responses;
|
|
392
|
+
if (options.description)
|
|
393
|
+
routeConfig.description = options.description;
|
|
394
|
+
if (options.category)
|
|
395
|
+
routeConfig.category = options.category;
|
|
396
|
+
if (options.groups)
|
|
397
|
+
routeConfig.groups = options.groups;
|
|
398
|
+
if (options.data)
|
|
399
|
+
routeConfig.data = new Map(Object.entries(options.data));
|
|
400
|
+
if (options.baseUrl)
|
|
401
|
+
routeConfig.baseUrl = options.baseUrl;
|
|
402
|
+
if (options.middlewares) {
|
|
403
|
+
routeConfig.middlewares = options.middlewares.map(__assignType(v => {
|
|
404
|
+
return { config: v(), module };
|
|
405
|
+
}, ['v', '', 'P"2!"/"']));
|
|
406
|
+
}
|
|
407
|
+
if (options.resolverForToken) {
|
|
408
|
+
for (const item of options.resolverForToken)
|
|
409
|
+
routeConfig.resolverForToken.set(...item);
|
|
410
|
+
}
|
|
411
|
+
if (options.resolverForToken) {
|
|
412
|
+
for (const item of options.resolverForToken)
|
|
413
|
+
routeConfig.resolverForToken.set(...item);
|
|
414
|
+
}
|
|
415
|
+
if (options.resolverForParameterName) {
|
|
416
|
+
for (const item of options.resolverForParameterName)
|
|
417
|
+
routeConfig.resolverForParameterName.set(...item);
|
|
418
|
+
}
|
|
419
|
+
routeConfig.serializer = options.serializer;
|
|
420
|
+
routeConfig.serializationOptions = options.serializationOptions;
|
|
421
|
+
routeConfig.returnType = filterValidReturnType(fn.getReturnType());
|
|
422
|
+
this.addRoute(routeConfig);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
HttpRouterRegistryFunctionRegistrar.__type = [() => __ΩPartial, () => __ΩHttpRouterFunctionOptions, 'defaultOptions', function () { return {}; }, () => RouteConfig, 'routeConfig', 'addRoute', () => __ΩPartial, () => __ΩHttpRouterFunctionOptions, 'options', () => HttpRouterRegistryFunctionRegistrar, 'forOptions', () => __ΩHttpRouterFunctionOptions, 'pathOrOptions', 'args', '', 'callback', 'any', () => __ΩHttpDecorator, 'decorator', 'add', () => __ΩHttpRouterFunctionOptions, 'get', () => __ΩHttpRouterFunctionOptions, 'post', () => __ΩHttpRouterFunctionOptions, 'put', () => __ΩHttpRouterFunctionOptions, 'patch', () => __ΩHttpRouterFunctionOptions, 'delete', () => __ΩHttpRouterFunctionOptions, () => __ΩHttpRouterFunctionOptions, 'trace', () => __ΩHttpRouterFunctionOptions, 'head', () => __ΩHttpRouterFunctionOptions, () => InjectorModule, 'module', 'register', 'n"o!"3#<>$PP7%2&$0\'=Pn)o("2*P7+0,PP&n-J2.P"@2/"/021"02Pn324P"@2/"/021"05PP&n6J2.P"@2/"/021"07PP&n8J2.P"@2/"/021"09PP&n:J2.P"@2/"/021"0;PP&n<J2.P"@2/"/021"0=PP&n>J2.P"@2/"/021"0?PP&n@J2.P"@2/"/021"0*PP&nAJ2.P"@2/"/021"0BPP&nCJ2.P"@2/"/021"0DPnE2*P"@2/"/021P"7F2G8"0H;5'];
|
|
426
|
+
function createRouteConfigFromHttpAction(routeAction, action, module, controller) {
|
|
427
|
+
const routeConfig = new RouteConfig(action.name, action.httpMethods, action.path, routeAction);
|
|
428
|
+
routeConfig.responses = action.responses;
|
|
429
|
+
routeConfig.description = action.description;
|
|
430
|
+
routeConfig.category = action.category;
|
|
431
|
+
routeConfig.groups = action.groups;
|
|
432
|
+
routeConfig.data = new Map(action.data);
|
|
433
|
+
if (controller) {
|
|
434
|
+
routeConfig.baseUrl = controller.baseUrl;
|
|
435
|
+
routeConfig.middlewares = controller.middlewares.map(__assignType(v => {
|
|
436
|
+
return { config: v(), module };
|
|
437
|
+
}, ['v', '', 'P"2!"/"']));
|
|
438
|
+
routeConfig.resolverForToken = new Map(controller.resolverForToken);
|
|
439
|
+
routeConfig.resolverForParameterName = new Map(controller.resolverForParameterName);
|
|
440
|
+
}
|
|
441
|
+
routeConfig.middlewares.push(...action.middlewares.map(__assignType(v => {
|
|
442
|
+
return { config: v(), module };
|
|
443
|
+
}, ['v', '', 'P"2!"/"'])));
|
|
444
|
+
for (const item of action.resolverForToken)
|
|
445
|
+
routeConfig.resolverForToken.set(...item);
|
|
446
|
+
for (const item of action.resolverForParameterName)
|
|
447
|
+
routeConfig.resolverForParameterName.set(...item);
|
|
448
|
+
routeConfig.serializer = action.serializer;
|
|
449
|
+
routeConfig.serializationOptions = action.serializationOptions;
|
|
450
|
+
return routeConfig;
|
|
451
|
+
}
|
|
452
|
+
createRouteConfigFromHttpAction.__type = [() => __ΩRouteClassControllerAction, () => __ΩRouteFunctionControllerAction, 'routeAction', () => HttpAction, 'action', () => InjectorModule, 'module', () => HttpController, 'controller', 'createRouteConfigFromHttpAction', 'PPn!n"J2#P7$2%P"7&2\'8P7(2)8"/*'];
|
|
453
|
+
export class HttpRouterRegistry extends HttpRouterRegistryFunctionRegistrar {
|
|
454
|
+
constructor() {
|
|
455
|
+
super(...arguments);
|
|
456
|
+
this.routes = [];
|
|
457
|
+
this.buildId = 1;
|
|
458
|
+
}
|
|
459
|
+
getBuildId() {
|
|
460
|
+
return this.buildId;
|
|
461
|
+
}
|
|
462
|
+
getRoutes() {
|
|
463
|
+
return this.routes;
|
|
464
|
+
}
|
|
465
|
+
addRouteForController(controller, module) {
|
|
466
|
+
const controllerData = httpClass._fetch(controller);
|
|
467
|
+
if (!controllerData)
|
|
468
|
+
throw new Error(`Http controller class ${getClassName(controller)} has no @http.controller decorator.`);
|
|
469
|
+
const schema = ReflectionClass.from(controller);
|
|
470
|
+
for (const action of controllerData.getActions()) {
|
|
471
|
+
const routeAction = {
|
|
472
|
+
type: 'controller',
|
|
473
|
+
controller,
|
|
474
|
+
module,
|
|
475
|
+
methodName: action.methodName
|
|
476
|
+
};
|
|
477
|
+
const routeConfig = createRouteConfigFromHttpAction(routeAction, action, module, controllerData);
|
|
478
|
+
routeConfig.module = module;
|
|
479
|
+
if (schema.hasMethod(action.methodName))
|
|
480
|
+
routeConfig.returnType = filterValidReturnType(schema.getMethod(action.methodName).getReturnType());
|
|
481
|
+
this.addRoute(routeConfig);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
addRoute(routeConfig) {
|
|
485
|
+
this.routes.push(routeConfig);
|
|
486
|
+
this.buildId++;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
HttpRouterRegistry.__type = [() => HttpRouterRegistryFunctionRegistrar, () => RouteConfig, 'routes', function () { return []; }, 'buildId', function () { return 1; }, 'getBuildId', () => RouteConfig, 'getRoutes', () => __ΩClassType, 'controller', () => InjectorModule, 'module', 'addRouteForController', () => RouteConfig, 'routeConfig', 'addRoute', 'P7!P7"F3#<>$\'3%;>&P\'0\'PP7(F0)Pn*2+P"7,2-"0.PP7/20"015'];
|
|
490
|
+
export class HttpRouter {
|
|
491
|
+
constructor(controllers, logger, tagRegistry, middlewareRegistry = new MiddlewareRegistry, registry = new HttpRouterRegistry) {
|
|
273
492
|
this.logger = logger;
|
|
274
493
|
this.middlewareRegistry = middlewareRegistry;
|
|
275
|
-
this.
|
|
494
|
+
this.registry = registry;
|
|
495
|
+
this.buildId = 0;
|
|
276
496
|
for (const controller of controllers.controllers) {
|
|
277
497
|
this.addRouteForController(controller.controller, controller.module);
|
|
278
498
|
}
|
|
279
499
|
}
|
|
280
|
-
parseBody(req,
|
|
500
|
+
parseBody(req, foundFiles) {
|
|
281
501
|
const form = formidable({
|
|
282
502
|
multiples: true,
|
|
283
503
|
hash: 'sha1',
|
|
284
|
-
enabledPlugins: ['octetstream', 'querystring', 'json'],
|
|
285
504
|
});
|
|
286
|
-
return asyncOperation(
|
|
505
|
+
return asyncOperation(__assignType((resolve, reject) => {
|
|
287
506
|
if (req.body) {
|
|
288
507
|
return resolve(req.body);
|
|
289
508
|
}
|
|
290
|
-
form.parse(req,
|
|
509
|
+
form.parse(req, __assignType((err, fields, files) => {
|
|
291
510
|
if (err) {
|
|
292
511
|
reject(err);
|
|
293
512
|
}
|
|
294
513
|
else {
|
|
295
|
-
const
|
|
514
|
+
for (const [name, file] of Object.entries(files)) {
|
|
515
|
+
if (file.size === 0)
|
|
516
|
+
continue;
|
|
517
|
+
foundFiles[name] = {
|
|
518
|
+
size: file.size,
|
|
519
|
+
path: file.filepath,
|
|
520
|
+
name: file.originalFilename,
|
|
521
|
+
type: file.mimetype,
|
|
522
|
+
lastModifiedDate: file.lastModifiedDate,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
const body = req.body = { ...fields, ...foundFiles };
|
|
296
526
|
resolve(body);
|
|
297
527
|
}
|
|
298
|
-
},
|
|
299
|
-
},
|
|
528
|
+
}, ['err', 'fields', 'files', '', 'P"2!"2""2#"/$']));
|
|
529
|
+
}, ['resolve', 'reject', '', 'P"2!"2""/#']));
|
|
300
530
|
}
|
|
301
531
|
getRoutes() {
|
|
302
|
-
return this.
|
|
532
|
+
return this.registry.getRoutes();
|
|
303
533
|
}
|
|
304
534
|
static forControllers(controllers, tagRegistry = new TagRegistry(), middlewareRegistry = new MiddlewareRegistry(), module = new InjectorModule()) {
|
|
305
|
-
return new this(new HttpControllers(controllers.map(
|
|
535
|
+
return new this(new HttpControllers(controllers.map(__assignType(v => {
|
|
306
536
|
return isClass(v) ? { controller: v, module } : v;
|
|
307
|
-
},
|
|
537
|
+
}, ['v', '', 'P"2!"/"']))), new Logger([], []), tagRegistry, middlewareRegistry);
|
|
308
538
|
}
|
|
309
539
|
getRouteCode(compiler, routeConfig) {
|
|
310
540
|
const routeConfigVar = compiler.reserveVariable('routeConfigVar', routeConfig);
|
|
311
541
|
const parsedRoute = parseRouteControllerAction(routeConfig);
|
|
312
542
|
const path = routeConfig.getFullPath();
|
|
313
|
-
const
|
|
543
|
+
const pathParamStarter = path.indexOf(':');
|
|
544
|
+
const prefix = path.substr(0, pathParamStarter);
|
|
314
545
|
const regexVar = compiler.reserveVariable('regex', new RegExp('^' + parsedRoute.regex + '$'));
|
|
315
546
|
const setParameters = [];
|
|
316
547
|
const parameterNames = [];
|
|
317
548
|
const parameterValidator = [];
|
|
318
549
|
let bodyValidationErrorHandling = `if (bodyErrors.length) throw ValidationError.from(bodyErrors);`;
|
|
319
550
|
let enableParseBody = false;
|
|
320
|
-
const hasParameters = parsedRoute.getParameters().length > 0;
|
|
551
|
+
const hasParameters = pathParamStarter !== -1 || parsedRoute.getParameters().length > 0;
|
|
321
552
|
let requiresAsyncParameters = false;
|
|
322
553
|
let setParametersFromPath = '';
|
|
323
554
|
const fullPath = routeConfig.getFullPath();
|
|
@@ -355,7 +586,7 @@ export class Router {
|
|
|
355
586
|
else {
|
|
356
587
|
parameterNames.push(`parameters.${parameter.parameter.name}`);
|
|
357
588
|
if (parameter.isPartOfPath()) {
|
|
358
|
-
if (parameter.parameter.type.kind !==
|
|
589
|
+
if (parameter.parameter.type.kind !== ReflectionKind.class) {
|
|
359
590
|
const converted = getSerializeFunction(parameter.parameter.parameter, serializer.deserializeRegistry, undefined, parameter.getName());
|
|
360
591
|
const converterVar = compiler.reserveVariable('argumentConverter', converted);
|
|
361
592
|
setParameters.push(`parameters.${parameter.parameter.name} = ${converterVar}(_match[${1 + (parameter.regexPosition || 0)}], {loosely: true});`);
|
|
@@ -367,7 +598,7 @@ export class Router {
|
|
|
367
598
|
setParameters.push(`parameters.${parameter.parameter.name} = _match[${1 + (parameter.regexPosition || 0)}];`);
|
|
368
599
|
}
|
|
369
600
|
}
|
|
370
|
-
const injectorToken = parameter.parameter.type.kind ===
|
|
601
|
+
const injectorToken = parameter.parameter.type.kind === ReflectionKind.class ? parameter.parameter.type.classType : undefined;
|
|
371
602
|
const injectorTokenVar = compiler.reserveVariable('classType', injectorToken);
|
|
372
603
|
const parameterResolverFoundVar = compiler.reserveVariable('parameterResolverFound', false);
|
|
373
604
|
setParameters.push(`${parameterResolverFoundVar} = false;`);
|
|
@@ -391,7 +622,7 @@ export class Router {
|
|
|
391
622
|
${parameterResolverFoundVar} = true;
|
|
392
623
|
parameters.${parameter.parameter.name} = await ${instance}.resolve({
|
|
393
624
|
token: ${injectorTokenVar},
|
|
394
|
-
|
|
625
|
+
route: ${routeConfigVar},
|
|
395
626
|
request: request,
|
|
396
627
|
name: ${JSON.stringify(parameter.parameter.name)},
|
|
397
628
|
value: parameters.${parameter.parameter.name},
|
|
@@ -458,9 +689,9 @@ export class Router {
|
|
|
458
689
|
}
|
|
459
690
|
let methodCheck = '';
|
|
460
691
|
if (routeConfig.httpMethods.length) {
|
|
461
|
-
methodCheck = '(' + routeConfig.httpMethods.map(
|
|
692
|
+
methodCheck = '(' + routeConfig.httpMethods.map(__assignType(v => {
|
|
462
693
|
return `_method === '${v.toUpperCase()}'`;
|
|
463
|
-
},
|
|
694
|
+
}, ['v', '', 'P"2!"/"'])).join(' || ') + ') && ';
|
|
464
695
|
}
|
|
465
696
|
return `
|
|
466
697
|
//=> ${routeConfig.httpMethods.join(',')} ${path}
|
|
@@ -472,14 +703,14 @@ export class Router {
|
|
|
472
703
|
getRouteUrlResolveCode(compiler, routeConfig) {
|
|
473
704
|
const parsedRoute = parseRouteControllerAction(routeConfig);
|
|
474
705
|
let url = routeConfig.getFullPath();
|
|
475
|
-
url = url.replace(/:(\w+)/g,
|
|
706
|
+
url = url.replace(/:(\w+)/g, __assignType((a, name) => {
|
|
476
707
|
return `\${parameters.${name}}`;
|
|
477
|
-
},
|
|
708
|
+
}, ['a', 'name', '', 'P"2!"2""/#']));
|
|
478
709
|
const modify = [];
|
|
479
710
|
for (const parameter of parsedRoute.getParameters()) {
|
|
480
711
|
if (parameter.query || parameter.queries) {
|
|
481
712
|
const queryPath = parameter.typePath === undefined && parameter.query ? parameter.parameter.name : parameter.typePath || '';
|
|
482
|
-
if (parameter.parameter.type.kind ===
|
|
713
|
+
if (parameter.parameter.type.kind === ReflectionKind.class || parameter.parameter.type.kind === ReflectionKind.objectLiteral) {
|
|
483
714
|
for (const property of ReflectionClass.from(parameter.parameter.type).getProperties()) {
|
|
484
715
|
const accessor = `parameters.${parameter.getName()}?.${property.name}`;
|
|
485
716
|
const thisPath = queryPath ? queryPath + '.' + property.name : property.name;
|
|
@@ -501,55 +732,18 @@ export class Router {
|
|
|
501
732
|
`;
|
|
502
733
|
}
|
|
503
734
|
addRoute(routeConfig) {
|
|
504
|
-
this.
|
|
505
|
-
this.fn = undefined;
|
|
735
|
+
this.registry.addRoute(routeConfig);
|
|
506
736
|
}
|
|
507
737
|
addRouteForController(controller, module) {
|
|
508
|
-
|
|
509
|
-
if (!data)
|
|
510
|
-
throw new Error(`Http controller class ${getClassName(controller)} has no @http.controller decorator.`);
|
|
511
|
-
const schema = ReflectionClass.from(controller);
|
|
512
|
-
for (const action of data.getActions()) {
|
|
513
|
-
const routeConfig = new RouteConfig(action.name, action.httpMethods, action.path, {
|
|
514
|
-
controller,
|
|
515
|
-
module,
|
|
516
|
-
methodName: action.methodName
|
|
517
|
-
});
|
|
518
|
-
routeConfig.module = module;
|
|
519
|
-
routeConfig.responses = action.responses;
|
|
520
|
-
routeConfig.description = action.description;
|
|
521
|
-
routeConfig.category = action.category;
|
|
522
|
-
routeConfig.groups = action.groups;
|
|
523
|
-
routeConfig.data = new Map(action.data);
|
|
524
|
-
routeConfig.baseUrl = data.baseUrl;
|
|
525
|
-
routeConfig.middlewares = data.middlewares.map(Object.assign(v => {
|
|
526
|
-
return { config: v(), module };
|
|
527
|
-
}, { __type: ['v', '', 'P"2!"/"'] }));
|
|
528
|
-
routeConfig.middlewares.push(...action.middlewares.map(Object.assign(v => {
|
|
529
|
-
return { config: v(), module };
|
|
530
|
-
}, { __type: ['v', '', 'P"2!"/"'] })));
|
|
531
|
-
for (const item of action.resolverForToken)
|
|
532
|
-
routeConfig.resolverForToken.set(...item);
|
|
533
|
-
routeConfig.resolverForToken = new Map(data.resolverForToken);
|
|
534
|
-
for (const item of action.resolverForToken)
|
|
535
|
-
routeConfig.resolverForToken.set(...item);
|
|
536
|
-
routeConfig.resolverForParameterName = new Map(data.resolverForParameterName);
|
|
537
|
-
for (const item of action.resolverForParameterName)
|
|
538
|
-
routeConfig.resolverForParameterName.set(...item);
|
|
539
|
-
routeConfig.serializationOptions = action.serializationOptions;
|
|
540
|
-
routeConfig.serializer = action.serializer;
|
|
541
|
-
routeConfig.serializer = action.serializer;
|
|
542
|
-
if (schema.hasMethod(action.methodName))
|
|
543
|
-
routeConfig.returnType = schema.getMethod(action.methodName).getReturnType();
|
|
544
|
-
this.addRoute(routeConfig);
|
|
545
|
-
}
|
|
738
|
+
this.registry.addRouteForController(controller, module);
|
|
546
739
|
}
|
|
547
740
|
build() {
|
|
741
|
+
this.buildId = this.registry.getBuildId();
|
|
548
742
|
const compiler = new CompilerContext;
|
|
549
743
|
compiler.context.set('ValidationError', ValidationError);
|
|
550
744
|
compiler.context.set('qs', qs);
|
|
551
745
|
const code = [];
|
|
552
|
-
for (const route of this.
|
|
746
|
+
for (const route of this.getRoutes()) {
|
|
553
747
|
code.push(this.getRouteCode(compiler, route));
|
|
554
748
|
}
|
|
555
749
|
return compiler.build(`
|
|
@@ -566,7 +760,7 @@ export class Router {
|
|
|
566
760
|
buildUrlResolver() {
|
|
567
761
|
const compiler = new CompilerContext;
|
|
568
762
|
const code = [];
|
|
569
|
-
for (const route of this.
|
|
763
|
+
for (const route of this.getRoutes()) {
|
|
570
764
|
code.push(this.getRouteUrlResolveCode(compiler, route));
|
|
571
765
|
}
|
|
572
766
|
return compiler.build(`
|
|
@@ -583,7 +777,7 @@ export class Router {
|
|
|
583
777
|
return this.resolveFn(routeName, parameters);
|
|
584
778
|
}
|
|
585
779
|
resolveRequest(request) {
|
|
586
|
-
if (!this.fn) {
|
|
780
|
+
if (!this.fn || this.buildId !== this.registry.getBuildId()) {
|
|
587
781
|
this.fn = this.build();
|
|
588
782
|
}
|
|
589
783
|
return this.fn(request);
|
|
@@ -593,5 +787,5 @@ export class Router {
|
|
|
593
787
|
return this.resolveRequest({ url, method });
|
|
594
788
|
}
|
|
595
789
|
}
|
|
596
|
-
|
|
790
|
+
HttpRouter.__type = [() => HttpRequest, 'request', () => __ΩResolvedController, '', 'fn', 'buildId', function () { return 0; }, 'name', 'parameters', 'resolveFn', () => HttpRequest, 'req', () => UploadedFile, 'foundFiles', 'parseBody', () => HttpControllers, 'controllers', () => __ΩLoggerInterface, 'logger', () => TagRegistry, 'tagRegistry', () => MiddlewareRegistry, 'middlewareRegistry', () => new MiddlewareRegistry, () => HttpRouterRegistry, 'registry', () => new HttpRouterRegistry, 'constructor', () => RouteConfig, 'getRoutes', () => __ΩClassType, () => InjectorModule, 'module', () => __ΩClassType, 'controller', () => TagRegistry, () => new TagRegistry(), () => MiddlewareRegistry, () => new MiddlewareRegistry(), () => InjectorModule, () => new InjectorModule(), () => HttpRouter, 'forControllers', () => CompilerContext, 'compiler', () => RouteConfig, 'routeConfig', 'getRouteCode', () => CompilerContext, () => RouteConfig, 'getRouteUrlResolveCode', () => RouteConfig, 'addRoute', () => __ΩClassType, () => InjectorModule, 'addRouteForController', () => HttpRequest, () => __ΩResolvedController, 'build', 'buildUrlResolver', 'routeName', () => ({}), 'resolveUrl', () => HttpRequest, () => __ΩResolvedController, 'resolveRequest', 'method', 'url', () => __ΩResolvedController, 'resolve', 'PP7!2"Pn#-J/$3%8<\'3&<>\'P&2(P&"LM2)&/$3*8<PP7+2,P&P7-LM2."0/;PP7021n223;P7425P7627;>8P792:;>;"0<PP7=F0>PPn?PP"7@4AnB4CMJF21P7D25>EP7F27>GP"7H2A>IP7J0KsPP7L2MP7N2O&0P<PP7Q2MP7R2O&0S<PP7T2O"0UPnV2CP"7W2A"0XPPP7Y2"PnZ-J/$0[<P"0\\<P&2]P&"LM2)>^&0_PP7`2"Pna-J0bP&2c&2dPne-J0f5'];
|
|
597
791
|
//# sourceMappingURL=router.js.map
|