@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/cjs/src/router.js
CHANGED
|
@@ -9,14 +9,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.HttpRouter = exports.HttpRouterRegistry = exports.HttpRouterRegistryFunctionRegistrar = exports.__ΩHttpRouterFunctionOptions = exports.__ΩRouteParameterResolverContext = exports.__ΩRouteParameterResolver = exports.dotToUrlPath = exports.parseRouteControllerAction = exports.RouteConfig = exports.__ΩRouteClassControllerAction = exports.__ΩRouteFunctionControllerAction = exports.UploadedFile = exports.__ΩRouteParameterResolverForInjector = void 0;
|
|
13
13
|
const { __ΩSerializationOptions } = require('@deepkit/type');
|
|
14
14
|
const { __ΩClassType } = require('@deepkit/core');
|
|
15
15
|
const { __ΩMiddlewareRegistryEntry } = require('@deepkit/app');
|
|
16
|
+
const { __ΩHttpDecorator } = require('./decorator');
|
|
16
17
|
const { __ΩLoggerInterface } = require('@deepkit/logger');
|
|
17
18
|
const { __ΩHttpMiddlewareFn } = require('./middleware');
|
|
18
19
|
const { __ΩHttpRequestQuery } = require('./model');
|
|
19
20
|
const { __ΩHttpRequestResolvedParameters } = require('./model');
|
|
21
|
+
function __assignType(fn, args) {
|
|
22
|
+
fn.__type = args;
|
|
23
|
+
return fn;
|
|
24
|
+
}
|
|
25
|
+
const __ΩPartial = ['T', 'l+e#!e"!fRb!Pde"!gN#"'];
|
|
26
|
+
const __ΩRecord = ['K', 'T', 'l\'e#"Rb!b"Pde"!N#!'];
|
|
20
27
|
/*
|
|
21
28
|
* Deepkit Framework
|
|
22
29
|
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
|
|
@@ -39,6 +46,7 @@ const app_1 = require("@deepkit/app");
|
|
|
39
46
|
const middleware_1 = require("./middleware");
|
|
40
47
|
//@ts-ignore
|
|
41
48
|
const qs_1 = __importDefault(require("qs"));
|
|
49
|
+
const http_js_1 = require("./http.js");
|
|
42
50
|
const __ΩRouteParameterResolverForInjector = [() => injector_1.InjectorContext, 'injector', '', 'PP7!2"P"F"F`J/#'];
|
|
43
51
|
exports.__ΩRouteParameterResolverForInjector = __ΩRouteParameterResolverForInjector;
|
|
44
52
|
const __ΩResolvedController = [() => __ΩRouteParameterResolverForInjector, 'parameters', () => RouteConfig, 'routeConfig', () => UploadedFile, 'uploadedFiles', () => injector_1.InjectorContext, 'injector', () => __ΩHttpMiddlewareFn, 'fn', 'timeout', '', 'middlewares', 'Pn!4"P7#4$P&P7%LM4&PP7\'2(Pn)4*\'4+MF/,4-8M'];
|
|
@@ -49,12 +57,10 @@ UploadedFile = __decorate([
|
|
|
49
57
|
type_1.entity.name('@deepkit/UploadedFile')
|
|
50
58
|
], UploadedFile);
|
|
51
59
|
exports.UploadedFile = UploadedFile;
|
|
52
|
-
const __Ω
|
|
53
|
-
exports.__Ω
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
getRouterControllerActionName.__type = [() => __ΩRouteControllerAction, 'action', 'getRouterControllerActionName', 'Pn!2"&/#'];
|
|
60
|
+
const __ΩRouteFunctionControllerAction = ["function", 'type', () => injector_1.InjectorModule, 'module', 'args', '', 'fn', 'P.!4"P"7#4$8P"@2%"/&4\'M'];
|
|
61
|
+
exports.__ΩRouteFunctionControllerAction = __ΩRouteFunctionControllerAction;
|
|
62
|
+
const __ΩRouteClassControllerAction = ["controller", 'type', () => injector_1.InjectorModule, 'module', () => __ΩClassType, 'controller', 'methodName', 'P.!4"P"7#4$8n%4&&4\'M'];
|
|
63
|
+
exports.__ΩRouteClassControllerAction = __ΩRouteClassControllerAction;
|
|
58
64
|
class RouteConfig {
|
|
59
65
|
constructor(name, httpMethods, path, action, internal = false) {
|
|
60
66
|
this.name = name;
|
|
@@ -75,6 +81,11 @@ class RouteConfig {
|
|
|
75
81
|
*/
|
|
76
82
|
this.data = new Map();
|
|
77
83
|
}
|
|
84
|
+
getReflectionFunction() {
|
|
85
|
+
return this.action.type === 'controller' ?
|
|
86
|
+
type_1.ReflectionClass.from(this.action.controller).getMethod(this.action.methodName)
|
|
87
|
+
: type_1.ReflectionFunction.from(this.action.fn);
|
|
88
|
+
}
|
|
78
89
|
getSchemaForResponse(statusCode) {
|
|
79
90
|
if (!this.responses.length)
|
|
80
91
|
return;
|
|
@@ -92,7 +103,7 @@ class RouteConfig {
|
|
|
92
103
|
}
|
|
93
104
|
}
|
|
94
105
|
exports.RouteConfig = RouteConfig;
|
|
95
|
-
RouteConfig.__type = ['baseUrl', function () { return ''; }, 'statusCode', 'description', 'type', 'responses', function () { return []; }, function () { return ''; }, 'groups', function () { return []; }, 'category', function () { return ''; }, 'returnType', () => __ΩSerializationOptions, 'serializationOptions', () => type_1.Serializer, 'serializer', () => injector_1.InjectorModule, 'module', () => __ΩClassType, 'resolverForToken', function () { return new Map(); }, () => middleware_1.HttpMiddlewareConfig, 'config', () => injector_1.InjectorModule, 'middlewares', function () { return []; }, () => __ΩClassType, 'resolverForParameterName', function () { return new Map(); }, 'name', 'httpMethods', 'path', () => __Ω
|
|
106
|
+
RouteConfig.__type = ['baseUrl', function () { return ''; }, 'statusCode', 'description', 'type', 'responses', function () { return []; }, function () { return ''; }, 'groups', function () { return []; }, 'category', function () { return ''; }, 'returnType', () => __ΩSerializationOptions, 'serializationOptions', () => type_1.Serializer, 'serializer', () => injector_1.InjectorModule, 'module', () => __ΩClassType, 'resolverForToken', function () { return new Map(); }, () => middleware_1.HttpMiddlewareConfig, 'config', () => injector_1.InjectorModule, 'middlewares', function () { return []; }, () => __ΩClassType, 'resolverForParameterName', function () { return new Map(); }, 'name', 'httpMethods', 'path', () => __ΩRouteClassControllerAction, () => __ΩRouteFunctionControllerAction, 'action', 'internal', () => false, 'constructor', () => type_1.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'];
|
|
96
107
|
class ParsedRoute {
|
|
97
108
|
constructor(routeConfig) {
|
|
98
109
|
this.routeConfig = routeConfig;
|
|
@@ -128,9 +139,9 @@ class ParsedRouteParameter {
|
|
|
128
139
|
}
|
|
129
140
|
getType() {
|
|
130
141
|
if (this.bodyValidation) {
|
|
131
|
-
(0, type_1.assertType)(this.parameter.type,
|
|
132
|
-
const valueType = (0, type_1.findMember)('value', this.parameter.type);
|
|
133
|
-
if (!valueType || valueType.kind !==
|
|
142
|
+
(0, type_1.assertType)(this.parameter.type, type_1.ReflectionKind.class);
|
|
143
|
+
const valueType = (0, type_1.findMember)('value', this.parameter.type.types);
|
|
144
|
+
if (!valueType || valueType.kind !== type_1.ReflectionKind.property)
|
|
134
145
|
throw new Error(`No property value found at ${(0, type_1.stringifyType)(this.parameter.type)}`);
|
|
135
146
|
return valueType.type;
|
|
136
147
|
}
|
|
@@ -162,26 +173,29 @@ ParsedRouteParameter.__type = ['regexPosition', () => type_1.ReflectionParameter
|
|
|
162
173
|
function parseRoutePathToRegex(routeConfig) {
|
|
163
174
|
const parameterNames = {};
|
|
164
175
|
let path = routeConfig.getFullPath();
|
|
165
|
-
const
|
|
176
|
+
const fn = routeConfig.getReflectionFunction();
|
|
166
177
|
let argumentIndex = 0;
|
|
167
|
-
path = path.replace(/:(\w+)/g,
|
|
178
|
+
path = path.replace(/:(\w+)/g, __assignType((a, name) => {
|
|
168
179
|
parameterNames[name] = argumentIndex;
|
|
169
180
|
argumentIndex++;
|
|
170
|
-
const parameter =
|
|
181
|
+
const parameter = fn.getParameterOrUndefined(name);
|
|
171
182
|
if (parameter) {
|
|
172
183
|
const regExp = (0, model_1.getRegExp)(parameter.type);
|
|
173
|
-
if (regExp)
|
|
184
|
+
if (regExp instanceof RegExp) {
|
|
185
|
+
return '(' + regExp.source + ')';
|
|
186
|
+
}
|
|
187
|
+
else if (regExp) {
|
|
174
188
|
return '(' + regExp + ')';
|
|
189
|
+
}
|
|
175
190
|
}
|
|
176
191
|
return String.raw `([^/]+)`;
|
|
177
|
-
},
|
|
192
|
+
}, ['a', 'name', '', 'P"2!"2""/#']));
|
|
178
193
|
return { regex: path, parameterNames };
|
|
179
194
|
}
|
|
180
195
|
parseRoutePathToRegex.__type = [() => RouteConfig, 'routeConfig', 'regex', 'parameterNames', 'parseRoutePathToRegex', 'PP7!2"P&4#P&\'LM4$M/%'];
|
|
181
196
|
function parseRouteControllerAction(routeConfig) {
|
|
182
|
-
const schema = type_1.ReflectionClass.from(routeConfig.action.controller);
|
|
183
197
|
const parsedRoute = new ParsedRoute(routeConfig);
|
|
184
|
-
const methodArgumentProperties =
|
|
198
|
+
const methodArgumentProperties = routeConfig.getReflectionFunction().getParameters();
|
|
185
199
|
const parsedPath = parseRoutePathToRegex(routeConfig);
|
|
186
200
|
parsedRoute.regex = parsedPath.regex;
|
|
187
201
|
parsedRoute.pathParameterNames = parsedPath.parameterNames;
|
|
@@ -207,14 +221,14 @@ exports.__ΩRouteParameterResolverContext = __ΩRouteParameterResolverContext;
|
|
|
207
221
|
function filterMiddlewaresForRoute(middlewareRawConfigs, routeConfig, fullPath) {
|
|
208
222
|
const middlewares = middlewareRawConfigs.slice(0);
|
|
209
223
|
middlewares.push(...routeConfig.middlewares);
|
|
210
|
-
const middlewareConfigs = middlewares.filter(
|
|
224
|
+
const middlewareConfigs = middlewares.filter(__assignType((v) => {
|
|
211
225
|
var _a;
|
|
212
226
|
if (!(v.config instanceof middleware_1.HttpMiddlewareConfig))
|
|
213
227
|
return false;
|
|
214
|
-
if (v.config.controllers.length && !v.config.controllers.includes(routeConfig.action.controller)) {
|
|
228
|
+
if (v.config.controllers.length && routeConfig.action.type === 'controller' && !v.config.controllers.includes(routeConfig.action.controller)) {
|
|
215
229
|
return false;
|
|
216
230
|
}
|
|
217
|
-
if (v.config.excludeControllers.length && v.config.excludeControllers.includes(routeConfig.action.controller)) {
|
|
231
|
+
if (v.config.excludeControllers.length && routeConfig.action.type === 'controller' && v.config.excludeControllers.includes(routeConfig.action.controller)) {
|
|
218
232
|
return false;
|
|
219
233
|
}
|
|
220
234
|
if (v.config.modules.length && (!routeConfig.module || !v.config.modules.includes(routeConfig.module))) {
|
|
@@ -228,16 +242,22 @@ function filterMiddlewaresForRoute(middlewareRawConfigs, routeConfig, fullPath)
|
|
|
228
242
|
if (v.config.selfModule && v.module.id !== ((_a = routeConfig.module) === null || _a === void 0 ? void 0 : _a.id))
|
|
229
243
|
return false;
|
|
230
244
|
if (v.config.routeNames.length) {
|
|
245
|
+
let found = false;
|
|
231
246
|
for (const name of v.config.routeNames) {
|
|
232
247
|
if (name.includes('*')) {
|
|
233
248
|
const regex = new RegExp('^' + name.replace(/\*/g, '.*') + '$');
|
|
234
|
-
if (
|
|
235
|
-
|
|
249
|
+
if (regex.test(routeConfig.name)) {
|
|
250
|
+
found = true;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
236
253
|
}
|
|
237
|
-
else if (name
|
|
238
|
-
|
|
254
|
+
else if (name === routeConfig.name) {
|
|
255
|
+
found = true;
|
|
256
|
+
break;
|
|
239
257
|
}
|
|
240
258
|
}
|
|
259
|
+
if (!found)
|
|
260
|
+
return false;
|
|
241
261
|
}
|
|
242
262
|
if (v.config.excludeRouteNames.length) {
|
|
243
263
|
for (const name of v.config.excludeRouteNames) {
|
|
@@ -270,63 +290,276 @@ function filterMiddlewaresForRoute(middlewareRawConfigs, routeConfig, fullPath)
|
|
|
270
290
|
}
|
|
271
291
|
}
|
|
272
292
|
return true;
|
|
273
|
-
},
|
|
274
|
-
middlewareConfigs.sort(
|
|
293
|
+
}, ['v', '', 'P"2!"/"']));
|
|
294
|
+
middlewareConfigs.sort(__assignType((a, b) => {
|
|
275
295
|
return a.config.order - b.config.order;
|
|
276
|
-
},
|
|
296
|
+
}, ['a', 'b', '', 'P"2!"2""/#']));
|
|
277
297
|
return middlewareConfigs;
|
|
278
298
|
}
|
|
279
299
|
filterMiddlewaresForRoute.__type = [() => __ΩMiddlewareRegistryEntry, 'middlewareRawConfigs', () => RouteConfig, 'routeConfig', 'fullPath', () => middleware_1.HttpMiddlewareConfig, 'config', () => injector_1.InjectorModule, 'module', 'filterMiddlewaresForRoute', 'Pn!F2"P7#2$&2%PP7&4\'P"7(4)MF/*'];
|
|
280
|
-
|
|
281
|
-
|
|
300
|
+
const __ΩHttpRouterFunctionOptions = ['path', 'name', 'methods', 'description', 'category', 'groups', () => __ΩRecord, 'data', 'baseUrl', () => middleware_1.HttpMiddlewareConfig, '', 'middlewares', () => type_1.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'];
|
|
301
|
+
exports.__ΩHttpRouterFunctionOptions = __ΩHttpRouterFunctionOptions;
|
|
302
|
+
function convertOptions(methods, pathOrOptions, defaultOptions) {
|
|
303
|
+
const options = 'string' === typeof pathOrOptions ? { path: pathOrOptions } : pathOrOptions;
|
|
304
|
+
if (options.methods)
|
|
305
|
+
return options;
|
|
306
|
+
return { ...options, methods };
|
|
307
|
+
}
|
|
308
|
+
convertOptions.__type = ['methods', () => __ΩHttpRouterFunctionOptions, 'pathOrOptions', () => __ΩPartial, () => __ΩHttpRouterFunctionOptions, 'defaultOptions', () => __ΩHttpRouterFunctionOptions, 'convertOptions', 'P&F2!P&n"J2#n%o$"2&n\'/('];
|
|
309
|
+
/**
|
|
310
|
+
* Annotated types like HTMLResponse/JSONResponse are not used for serialization.
|
|
311
|
+
*/
|
|
312
|
+
function filterValidReturnType(type) {
|
|
313
|
+
if (type.kind === type_1.ReflectionKind.class && (type.classType === http_js_1.HtmlResponse || type.classType === http_js_1.JSONResponse || type.classType === http_js_1.Response))
|
|
314
|
+
return;
|
|
315
|
+
return type;
|
|
316
|
+
}
|
|
317
|
+
filterValidReturnType.__type = ['type', 'filterValidReturnType', 'P"2!P"-J/"'];
|
|
318
|
+
class HttpRouterRegistryFunctionRegistrar {
|
|
319
|
+
constructor() {
|
|
320
|
+
this.defaultOptions = {};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Returns a new registrar object with default options that apply to each registered route through this registrar.
|
|
324
|
+
*
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const registry: HttpRouterRegistry = ...;
|
|
327
|
+
*
|
|
328
|
+
* const secretRegistry = registry.forOptions({groups: ['secret']});
|
|
329
|
+
*
|
|
330
|
+
* secretRegistry.get('/admin/groups', () => {
|
|
331
|
+
* });
|
|
332
|
+
*
|
|
333
|
+
* secretRegistry.get('/admin/users', () => {
|
|
334
|
+
* });
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
forOptions(options) {
|
|
338
|
+
var _a;
|
|
339
|
+
const that = this;
|
|
340
|
+
return new (_a = class extends HttpRouterRegistryFunctionRegistrar {
|
|
341
|
+
constructor() {
|
|
342
|
+
super(...arguments);
|
|
343
|
+
this.defaultOptions = options;
|
|
344
|
+
}
|
|
345
|
+
addRoute(routeConfig) {
|
|
346
|
+
that.addRoute(routeConfig);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
_a.__type = [() => HttpRouterRegistryFunctionRegistrar, () => RouteConfig, 'routeConfig', 'addRoute', 'P7!PP7"2#"0$5'],
|
|
350
|
+
_a);
|
|
351
|
+
}
|
|
352
|
+
any(pathOrOptions, callback) {
|
|
353
|
+
this.register(convertOptions([], pathOrOptions, this.defaultOptions), callback);
|
|
354
|
+
}
|
|
355
|
+
add(decorator, callback) {
|
|
356
|
+
const data = decorator(Object, '_');
|
|
357
|
+
const action = (0, core_1.isArray)(data) ? data.find(__assignType(v => v instanceof decorator_1.HttpAction, ['v', '', 'P"2!"/"'])) : undefined;
|
|
358
|
+
if (!action)
|
|
359
|
+
throw new Error('No HttpAction available');
|
|
360
|
+
const fn = type_1.ReflectionFunction.from(callback);
|
|
361
|
+
const routeConfig = createRouteConfigFromHttpAction({
|
|
362
|
+
type: 'function',
|
|
363
|
+
fn: callback,
|
|
364
|
+
}, action);
|
|
365
|
+
routeConfig.returnType = filterValidReturnType(fn.getReturnType());
|
|
366
|
+
this.addRoute(routeConfig);
|
|
367
|
+
}
|
|
368
|
+
get(pathOrOptions, callback) {
|
|
369
|
+
this.register(convertOptions(['GET'], pathOrOptions, this.defaultOptions), callback);
|
|
370
|
+
}
|
|
371
|
+
post(pathOrOptions, callback) {
|
|
372
|
+
this.register(convertOptions(['POST'], pathOrOptions, this.defaultOptions), callback);
|
|
373
|
+
}
|
|
374
|
+
put(pathOrOptions, callback) {
|
|
375
|
+
this.register(convertOptions(['PUT'], pathOrOptions, this.defaultOptions), callback);
|
|
376
|
+
}
|
|
377
|
+
patch(pathOrOptions, callback) {
|
|
378
|
+
this.register(convertOptions(['PATCH'], pathOrOptions, this.defaultOptions), callback);
|
|
379
|
+
}
|
|
380
|
+
delete(pathOrOptions, callback) {
|
|
381
|
+
this.register(convertOptions(['DELETE'], pathOrOptions, this.defaultOptions), callback);
|
|
382
|
+
}
|
|
383
|
+
options(pathOrOptions, callback) {
|
|
384
|
+
this.register(convertOptions(['OPTIONS'], pathOrOptions, this.defaultOptions), callback);
|
|
385
|
+
}
|
|
386
|
+
trace(pathOrOptions, callback) {
|
|
387
|
+
this.register(convertOptions(['TRACE'], pathOrOptions, this.defaultOptions), callback);
|
|
388
|
+
}
|
|
389
|
+
head(pathOrOptions, callback) {
|
|
390
|
+
this.register(convertOptions(['HEAD'], pathOrOptions, this.defaultOptions), callback);
|
|
391
|
+
}
|
|
392
|
+
register(options, callback, module) {
|
|
393
|
+
const fn = type_1.ReflectionFunction.from(callback);
|
|
394
|
+
const routeConfig = new RouteConfig(options.name || '', options.methods || [], options.path, {
|
|
395
|
+
type: 'function',
|
|
396
|
+
fn: callback,
|
|
397
|
+
});
|
|
398
|
+
routeConfig.module = module;
|
|
399
|
+
if (options.responses)
|
|
400
|
+
routeConfig.responses = options.responses;
|
|
401
|
+
if (options.description)
|
|
402
|
+
routeConfig.description = options.description;
|
|
403
|
+
if (options.category)
|
|
404
|
+
routeConfig.category = options.category;
|
|
405
|
+
if (options.groups)
|
|
406
|
+
routeConfig.groups = options.groups;
|
|
407
|
+
if (options.data)
|
|
408
|
+
routeConfig.data = new Map(Object.entries(options.data));
|
|
409
|
+
if (options.baseUrl)
|
|
410
|
+
routeConfig.baseUrl = options.baseUrl;
|
|
411
|
+
if (options.middlewares) {
|
|
412
|
+
routeConfig.middlewares = options.middlewares.map(__assignType(v => {
|
|
413
|
+
return { config: v(), module };
|
|
414
|
+
}, ['v', '', 'P"2!"/"']));
|
|
415
|
+
}
|
|
416
|
+
if (options.resolverForToken) {
|
|
417
|
+
for (const item of options.resolverForToken)
|
|
418
|
+
routeConfig.resolverForToken.set(...item);
|
|
419
|
+
}
|
|
420
|
+
if (options.resolverForToken) {
|
|
421
|
+
for (const item of options.resolverForToken)
|
|
422
|
+
routeConfig.resolverForToken.set(...item);
|
|
423
|
+
}
|
|
424
|
+
if (options.resolverForParameterName) {
|
|
425
|
+
for (const item of options.resolverForParameterName)
|
|
426
|
+
routeConfig.resolverForParameterName.set(...item);
|
|
427
|
+
}
|
|
428
|
+
routeConfig.serializer = options.serializer;
|
|
429
|
+
routeConfig.serializationOptions = options.serializationOptions;
|
|
430
|
+
routeConfig.returnType = filterValidReturnType(fn.getReturnType());
|
|
431
|
+
this.addRoute(routeConfig);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
exports.HttpRouterRegistryFunctionRegistrar = HttpRouterRegistryFunctionRegistrar;
|
|
435
|
+
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, () => injector_1.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'];
|
|
436
|
+
function createRouteConfigFromHttpAction(routeAction, action, module, controller) {
|
|
437
|
+
const routeConfig = new RouteConfig(action.name, action.httpMethods, action.path, routeAction);
|
|
438
|
+
routeConfig.responses = action.responses;
|
|
439
|
+
routeConfig.description = action.description;
|
|
440
|
+
routeConfig.category = action.category;
|
|
441
|
+
routeConfig.groups = action.groups;
|
|
442
|
+
routeConfig.data = new Map(action.data);
|
|
443
|
+
if (controller) {
|
|
444
|
+
routeConfig.baseUrl = controller.baseUrl;
|
|
445
|
+
routeConfig.middlewares = controller.middlewares.map(__assignType(v => {
|
|
446
|
+
return { config: v(), module };
|
|
447
|
+
}, ['v', '', 'P"2!"/"']));
|
|
448
|
+
routeConfig.resolverForToken = new Map(controller.resolverForToken);
|
|
449
|
+
routeConfig.resolverForParameterName = new Map(controller.resolverForParameterName);
|
|
450
|
+
}
|
|
451
|
+
routeConfig.middlewares.push(...action.middlewares.map(__assignType(v => {
|
|
452
|
+
return { config: v(), module };
|
|
453
|
+
}, ['v', '', 'P"2!"/"'])));
|
|
454
|
+
for (const item of action.resolverForToken)
|
|
455
|
+
routeConfig.resolverForToken.set(...item);
|
|
456
|
+
for (const item of action.resolverForParameterName)
|
|
457
|
+
routeConfig.resolverForParameterName.set(...item);
|
|
458
|
+
routeConfig.serializer = action.serializer;
|
|
459
|
+
routeConfig.serializationOptions = action.serializationOptions;
|
|
460
|
+
return routeConfig;
|
|
461
|
+
}
|
|
462
|
+
createRouteConfigFromHttpAction.__type = [() => __ΩRouteClassControllerAction, () => __ΩRouteFunctionControllerAction, 'routeAction', () => decorator_1.HttpAction, 'action', () => injector_1.InjectorModule, 'module', () => decorator_1.HttpController, 'controller', 'createRouteConfigFromHttpAction', 'PPn!n"J2#P7$2%P"7&2\'8P7(2)8"/*'];
|
|
463
|
+
class HttpRouterRegistry extends HttpRouterRegistryFunctionRegistrar {
|
|
464
|
+
constructor() {
|
|
465
|
+
super(...arguments);
|
|
466
|
+
this.routes = [];
|
|
467
|
+
this.buildId = 1;
|
|
468
|
+
}
|
|
469
|
+
getBuildId() {
|
|
470
|
+
return this.buildId;
|
|
471
|
+
}
|
|
472
|
+
getRoutes() {
|
|
473
|
+
return this.routes;
|
|
474
|
+
}
|
|
475
|
+
addRouteForController(controller, module) {
|
|
476
|
+
const controllerData = decorator_1.httpClass._fetch(controller);
|
|
477
|
+
if (!controllerData)
|
|
478
|
+
throw new Error(`Http controller class ${(0, core_1.getClassName)(controller)} has no @http.controller decorator.`);
|
|
479
|
+
const schema = type_1.ReflectionClass.from(controller);
|
|
480
|
+
for (const action of controllerData.getActions()) {
|
|
481
|
+
const routeAction = {
|
|
482
|
+
type: 'controller',
|
|
483
|
+
controller,
|
|
484
|
+
module,
|
|
485
|
+
methodName: action.methodName
|
|
486
|
+
};
|
|
487
|
+
const routeConfig = createRouteConfigFromHttpAction(routeAction, action, module, controllerData);
|
|
488
|
+
routeConfig.module = module;
|
|
489
|
+
if (schema.hasMethod(action.methodName))
|
|
490
|
+
routeConfig.returnType = filterValidReturnType(schema.getMethod(action.methodName).getReturnType());
|
|
491
|
+
this.addRoute(routeConfig);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
addRoute(routeConfig) {
|
|
495
|
+
this.routes.push(routeConfig);
|
|
496
|
+
this.buildId++;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
exports.HttpRouterRegistry = HttpRouterRegistry;
|
|
500
|
+
HttpRouterRegistry.__type = [() => HttpRouterRegistryFunctionRegistrar, () => RouteConfig, 'routes', function () { return []; }, 'buildId', function () { return 1; }, 'getBuildId', () => RouteConfig, 'getRoutes', () => __ΩClassType, 'controller', () => injector_1.InjectorModule, 'module', 'addRouteForController', () => RouteConfig, 'routeConfig', 'addRoute', 'P7!P7"F3#<>$\'3%;>&P\'0\'PP7(F0)Pn*2+P"7,2-"0.PP7/20"015'];
|
|
501
|
+
class HttpRouter {
|
|
502
|
+
constructor(controllers, logger, tagRegistry, middlewareRegistry = new app_1.MiddlewareRegistry, registry = new HttpRouterRegistry) {
|
|
282
503
|
this.logger = logger;
|
|
283
504
|
this.middlewareRegistry = middlewareRegistry;
|
|
284
|
-
this.
|
|
505
|
+
this.registry = registry;
|
|
506
|
+
this.buildId = 0;
|
|
285
507
|
for (const controller of controllers.controllers) {
|
|
286
508
|
this.addRouteForController(controller.controller, controller.module);
|
|
287
509
|
}
|
|
288
510
|
}
|
|
289
|
-
parseBody(req,
|
|
511
|
+
parseBody(req, foundFiles) {
|
|
290
512
|
const form = (0, formidable_1.default)({
|
|
291
513
|
multiples: true,
|
|
292
514
|
hash: 'sha1',
|
|
293
|
-
enabledPlugins: ['octetstream', 'querystring', 'json'],
|
|
294
515
|
});
|
|
295
|
-
return (0, core_1.asyncOperation)(
|
|
516
|
+
return (0, core_1.asyncOperation)(__assignType((resolve, reject) => {
|
|
296
517
|
if (req.body) {
|
|
297
518
|
return resolve(req.body);
|
|
298
519
|
}
|
|
299
|
-
form.parse(req,
|
|
520
|
+
form.parse(req, __assignType((err, fields, files) => {
|
|
300
521
|
if (err) {
|
|
301
522
|
reject(err);
|
|
302
523
|
}
|
|
303
524
|
else {
|
|
304
|
-
const
|
|
525
|
+
for (const [name, file] of Object.entries(files)) {
|
|
526
|
+
if (file.size === 0)
|
|
527
|
+
continue;
|
|
528
|
+
foundFiles[name] = {
|
|
529
|
+
size: file.size,
|
|
530
|
+
path: file.filepath,
|
|
531
|
+
name: file.originalFilename,
|
|
532
|
+
type: file.mimetype,
|
|
533
|
+
lastModifiedDate: file.lastModifiedDate,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
const body = req.body = { ...fields, ...foundFiles };
|
|
305
537
|
resolve(body);
|
|
306
538
|
}
|
|
307
|
-
},
|
|
308
|
-
},
|
|
539
|
+
}, ['err', 'fields', 'files', '', 'P"2!"2""2#"/$']));
|
|
540
|
+
}, ['resolve', 'reject', '', 'P"2!"2""/#']));
|
|
309
541
|
}
|
|
310
542
|
getRoutes() {
|
|
311
|
-
return this.
|
|
543
|
+
return this.registry.getRoutes();
|
|
312
544
|
}
|
|
313
545
|
static forControllers(controllers, tagRegistry = new injector_1.TagRegistry(), middlewareRegistry = new app_1.MiddlewareRegistry(), module = new injector_1.InjectorModule()) {
|
|
314
|
-
return new this(new controllers_1.HttpControllers(controllers.map(
|
|
546
|
+
return new this(new controllers_1.HttpControllers(controllers.map(__assignType(v => {
|
|
315
547
|
return (0, core_1.isClass)(v) ? { controller: v, module } : v;
|
|
316
|
-
},
|
|
548
|
+
}, ['v', '', 'P"2!"/"']))), new logger_1.Logger([], []), tagRegistry, middlewareRegistry);
|
|
317
549
|
}
|
|
318
550
|
getRouteCode(compiler, routeConfig) {
|
|
319
551
|
const routeConfigVar = compiler.reserveVariable('routeConfigVar', routeConfig);
|
|
320
552
|
const parsedRoute = parseRouteControllerAction(routeConfig);
|
|
321
553
|
const path = routeConfig.getFullPath();
|
|
322
|
-
const
|
|
554
|
+
const pathParamStarter = path.indexOf(':');
|
|
555
|
+
const prefix = path.substr(0, pathParamStarter);
|
|
323
556
|
const regexVar = compiler.reserveVariable('regex', new RegExp('^' + parsedRoute.regex + '$'));
|
|
324
557
|
const setParameters = [];
|
|
325
558
|
const parameterNames = [];
|
|
326
559
|
const parameterValidator = [];
|
|
327
560
|
let bodyValidationErrorHandling = `if (bodyErrors.length) throw ValidationError.from(bodyErrors);`;
|
|
328
561
|
let enableParseBody = false;
|
|
329
|
-
const hasParameters = parsedRoute.getParameters().length > 0;
|
|
562
|
+
const hasParameters = pathParamStarter !== -1 || parsedRoute.getParameters().length > 0;
|
|
330
563
|
let requiresAsyncParameters = false;
|
|
331
564
|
let setParametersFromPath = '';
|
|
332
565
|
const fullPath = routeConfig.getFullPath();
|
|
@@ -364,7 +597,7 @@ class Router {
|
|
|
364
597
|
else {
|
|
365
598
|
parameterNames.push(`parameters.${parameter.parameter.name}`);
|
|
366
599
|
if (parameter.isPartOfPath()) {
|
|
367
|
-
if (parameter.parameter.type.kind !==
|
|
600
|
+
if (parameter.parameter.type.kind !== type_1.ReflectionKind.class) {
|
|
368
601
|
const converted = (0, type_1.getSerializeFunction)(parameter.parameter.parameter, type_1.serializer.deserializeRegistry, undefined, parameter.getName());
|
|
369
602
|
const converterVar = compiler.reserveVariable('argumentConverter', converted);
|
|
370
603
|
setParameters.push(`parameters.${parameter.parameter.name} = ${converterVar}(_match[${1 + (parameter.regexPosition || 0)}], {loosely: true});`);
|
|
@@ -376,7 +609,7 @@ class Router {
|
|
|
376
609
|
setParameters.push(`parameters.${parameter.parameter.name} = _match[${1 + (parameter.regexPosition || 0)}];`);
|
|
377
610
|
}
|
|
378
611
|
}
|
|
379
|
-
const injectorToken = parameter.parameter.type.kind ===
|
|
612
|
+
const injectorToken = parameter.parameter.type.kind === type_1.ReflectionKind.class ? parameter.parameter.type.classType : undefined;
|
|
380
613
|
const injectorTokenVar = compiler.reserveVariable('classType', injectorToken);
|
|
381
614
|
const parameterResolverFoundVar = compiler.reserveVariable('parameterResolverFound', false);
|
|
382
615
|
setParameters.push(`${parameterResolverFoundVar} = false;`);
|
|
@@ -400,7 +633,7 @@ class Router {
|
|
|
400
633
|
${parameterResolverFoundVar} = true;
|
|
401
634
|
parameters.${parameter.parameter.name} = await ${instance}.resolve({
|
|
402
635
|
token: ${injectorTokenVar},
|
|
403
|
-
|
|
636
|
+
route: ${routeConfigVar},
|
|
404
637
|
request: request,
|
|
405
638
|
name: ${JSON.stringify(parameter.parameter.name)},
|
|
406
639
|
value: parameters.${parameter.parameter.name},
|
|
@@ -467,9 +700,9 @@ class Router {
|
|
|
467
700
|
}
|
|
468
701
|
let methodCheck = '';
|
|
469
702
|
if (routeConfig.httpMethods.length) {
|
|
470
|
-
methodCheck = '(' + routeConfig.httpMethods.map(
|
|
703
|
+
methodCheck = '(' + routeConfig.httpMethods.map(__assignType(v => {
|
|
471
704
|
return `_method === '${v.toUpperCase()}'`;
|
|
472
|
-
},
|
|
705
|
+
}, ['v', '', 'P"2!"/"'])).join(' || ') + ') && ';
|
|
473
706
|
}
|
|
474
707
|
return `
|
|
475
708
|
//=> ${routeConfig.httpMethods.join(',')} ${path}
|
|
@@ -481,14 +714,14 @@ class Router {
|
|
|
481
714
|
getRouteUrlResolveCode(compiler, routeConfig) {
|
|
482
715
|
const parsedRoute = parseRouteControllerAction(routeConfig);
|
|
483
716
|
let url = routeConfig.getFullPath();
|
|
484
|
-
url = url.replace(/:(\w+)/g,
|
|
717
|
+
url = url.replace(/:(\w+)/g, __assignType((a, name) => {
|
|
485
718
|
return `\${parameters.${name}}`;
|
|
486
|
-
},
|
|
719
|
+
}, ['a', 'name', '', 'P"2!"2""/#']));
|
|
487
720
|
const modify = [];
|
|
488
721
|
for (const parameter of parsedRoute.getParameters()) {
|
|
489
722
|
if (parameter.query || parameter.queries) {
|
|
490
723
|
const queryPath = parameter.typePath === undefined && parameter.query ? parameter.parameter.name : parameter.typePath || '';
|
|
491
|
-
if (parameter.parameter.type.kind ===
|
|
724
|
+
if (parameter.parameter.type.kind === type_1.ReflectionKind.class || parameter.parameter.type.kind === type_1.ReflectionKind.objectLiteral) {
|
|
492
725
|
for (const property of type_1.ReflectionClass.from(parameter.parameter.type).getProperties()) {
|
|
493
726
|
const accessor = `parameters.${parameter.getName()}?.${property.name}`;
|
|
494
727
|
const thisPath = queryPath ? queryPath + '.' + property.name : property.name;
|
|
@@ -510,55 +743,18 @@ class Router {
|
|
|
510
743
|
`;
|
|
511
744
|
}
|
|
512
745
|
addRoute(routeConfig) {
|
|
513
|
-
this.
|
|
514
|
-
this.fn = undefined;
|
|
746
|
+
this.registry.addRoute(routeConfig);
|
|
515
747
|
}
|
|
516
748
|
addRouteForController(controller, module) {
|
|
517
|
-
|
|
518
|
-
if (!data)
|
|
519
|
-
throw new Error(`Http controller class ${(0, core_1.getClassName)(controller)} has no @http.controller decorator.`);
|
|
520
|
-
const schema = type_1.ReflectionClass.from(controller);
|
|
521
|
-
for (const action of data.getActions()) {
|
|
522
|
-
const routeConfig = new RouteConfig(action.name, action.httpMethods, action.path, {
|
|
523
|
-
controller,
|
|
524
|
-
module,
|
|
525
|
-
methodName: action.methodName
|
|
526
|
-
});
|
|
527
|
-
routeConfig.module = module;
|
|
528
|
-
routeConfig.responses = action.responses;
|
|
529
|
-
routeConfig.description = action.description;
|
|
530
|
-
routeConfig.category = action.category;
|
|
531
|
-
routeConfig.groups = action.groups;
|
|
532
|
-
routeConfig.data = new Map(action.data);
|
|
533
|
-
routeConfig.baseUrl = data.baseUrl;
|
|
534
|
-
routeConfig.middlewares = data.middlewares.map(Object.assign(v => {
|
|
535
|
-
return { config: v(), module };
|
|
536
|
-
}, { __type: ['v', '', 'P"2!"/"'] }));
|
|
537
|
-
routeConfig.middlewares.push(...action.middlewares.map(Object.assign(v => {
|
|
538
|
-
return { config: v(), module };
|
|
539
|
-
}, { __type: ['v', '', 'P"2!"/"'] })));
|
|
540
|
-
for (const item of action.resolverForToken)
|
|
541
|
-
routeConfig.resolverForToken.set(...item);
|
|
542
|
-
routeConfig.resolverForToken = new Map(data.resolverForToken);
|
|
543
|
-
for (const item of action.resolverForToken)
|
|
544
|
-
routeConfig.resolverForToken.set(...item);
|
|
545
|
-
routeConfig.resolverForParameterName = new Map(data.resolverForParameterName);
|
|
546
|
-
for (const item of action.resolverForParameterName)
|
|
547
|
-
routeConfig.resolverForParameterName.set(...item);
|
|
548
|
-
routeConfig.serializationOptions = action.serializationOptions;
|
|
549
|
-
routeConfig.serializer = action.serializer;
|
|
550
|
-
routeConfig.serializer = action.serializer;
|
|
551
|
-
if (schema.hasMethod(action.methodName))
|
|
552
|
-
routeConfig.returnType = schema.getMethod(action.methodName).getReturnType();
|
|
553
|
-
this.addRoute(routeConfig);
|
|
554
|
-
}
|
|
749
|
+
this.registry.addRouteForController(controller, module);
|
|
555
750
|
}
|
|
556
751
|
build() {
|
|
752
|
+
this.buildId = this.registry.getBuildId();
|
|
557
753
|
const compiler = new core_1.CompilerContext;
|
|
558
754
|
compiler.context.set('ValidationError', type_1.ValidationError);
|
|
559
755
|
compiler.context.set('qs', qs_1.default);
|
|
560
756
|
const code = [];
|
|
561
|
-
for (const route of this.
|
|
757
|
+
for (const route of this.getRoutes()) {
|
|
562
758
|
code.push(this.getRouteCode(compiler, route));
|
|
563
759
|
}
|
|
564
760
|
return compiler.build(`
|
|
@@ -575,7 +771,7 @@ class Router {
|
|
|
575
771
|
buildUrlResolver() {
|
|
576
772
|
const compiler = new core_1.CompilerContext;
|
|
577
773
|
const code = [];
|
|
578
|
-
for (const route of this.
|
|
774
|
+
for (const route of this.getRoutes()) {
|
|
579
775
|
code.push(this.getRouteUrlResolveCode(compiler, route));
|
|
580
776
|
}
|
|
581
777
|
return compiler.build(`
|
|
@@ -592,7 +788,7 @@ class Router {
|
|
|
592
788
|
return this.resolveFn(routeName, parameters);
|
|
593
789
|
}
|
|
594
790
|
resolveRequest(request) {
|
|
595
|
-
if (!this.fn) {
|
|
791
|
+
if (!this.fn || this.buildId !== this.registry.getBuildId()) {
|
|
596
792
|
this.fn = this.build();
|
|
597
793
|
}
|
|
598
794
|
return this.fn(request);
|
|
@@ -602,6 +798,6 @@ class Router {
|
|
|
602
798
|
return this.resolveRequest({ url, method });
|
|
603
799
|
}
|
|
604
800
|
}
|
|
605
|
-
exports.
|
|
606
|
-
|
|
801
|
+
exports.HttpRouter = HttpRouter;
|
|
802
|
+
HttpRouter.__type = [() => model_1.HttpRequest, 'request', () => __ΩResolvedController, '', 'fn', 'buildId', function () { return 0; }, 'name', 'parameters', 'resolveFn', () => model_1.HttpRequest, 'req', () => UploadedFile, 'foundFiles', 'parseBody', () => controllers_1.HttpControllers, 'controllers', () => __ΩLoggerInterface, 'logger', () => injector_1.TagRegistry, 'tagRegistry', () => app_1.MiddlewareRegistry, 'middlewareRegistry', () => new app_1.MiddlewareRegistry, () => HttpRouterRegistry, 'registry', () => new HttpRouterRegistry, 'constructor', () => RouteConfig, 'getRoutes', () => __ΩClassType, () => injector_1.InjectorModule, 'module', () => __ΩClassType, 'controller', () => injector_1.TagRegistry, () => new injector_1.TagRegistry(), () => app_1.MiddlewareRegistry, () => new app_1.MiddlewareRegistry(), () => injector_1.InjectorModule, () => new injector_1.InjectorModule(), () => HttpRouter, 'forControllers', () => core_1.CompilerContext, 'compiler', () => RouteConfig, 'routeConfig', 'getRouteCode', () => core_1.CompilerContext, () => RouteConfig, 'getRouteUrlResolveCode', () => RouteConfig, 'addRoute', () => __ΩClassType, () => injector_1.InjectorModule, 'addRouteForController', () => model_1.HttpRequest, () => __ΩResolvedController, 'build', 'buildUrlResolver', 'routeName', () => ({}), 'resolveUrl', () => model_1.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'];
|
|
607
803
|
//# sourceMappingURL=router.js.map
|