@deepkit/http 1.0.1-alpha.68 → 1.0.1-alpha.72
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 +128 -37
- 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 +58 -26
- 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 +280 -94
- 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 +101 -23
- 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 +47 -15
- package/dist/esm/src/model.js.map +1 -1
- package/dist/esm/src/module.js +5 -3
- package/dist/esm/src/module.js.map +1 -1
- package/dist/esm/src/router.d.ts +84 -11
- package/dist/esm/src/router.js +278 -94
- 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 +88 -15
- package/src/kernel.ts +2 -2
- package/src/model.ts +35 -6
- package/src/module.ts +5 -3
- package/src/router.ts +286 -73
- 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 core_2 = require("@deepkit/core");
|
|
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?:&F2@:&2A:PnBnCJ2D:)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,50 +290,253 @@ 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
|
+
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 = (0, core_2.isArray)(data) ? data.find(__assignType(v => v instanceof decorator_1.HttpAction, ['v', '', 'P"2!"/"'])) : undefined;
|
|
349
|
+
if (!action)
|
|
350
|
+
throw new Error('No HttpAction available');
|
|
351
|
+
const fn = type_1.ReflectionFunction.from(callback);
|
|
352
|
+
const routeConfig = createRouteConfigFromHttpAction({
|
|
353
|
+
type: 'function',
|
|
354
|
+
fn: callback,
|
|
355
|
+
}, action);
|
|
356
|
+
routeConfig.returnType = 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 = type_1.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 = fn.getReturnType();
|
|
422
|
+
this.addRoute(routeConfig);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
exports.HttpRouterRegistryFunctionRegistrar = HttpRouterRegistryFunctionRegistrar;
|
|
426
|
+
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'];
|
|
427
|
+
function createRouteConfigFromHttpAction(routeAction, action, module, controller) {
|
|
428
|
+
const routeConfig = new RouteConfig(action.name, action.httpMethods, action.path, routeAction);
|
|
429
|
+
routeConfig.responses = action.responses;
|
|
430
|
+
routeConfig.description = action.description;
|
|
431
|
+
routeConfig.category = action.category;
|
|
432
|
+
routeConfig.groups = action.groups;
|
|
433
|
+
routeConfig.data = new Map(action.data);
|
|
434
|
+
if (controller) {
|
|
435
|
+
routeConfig.baseUrl = controller.baseUrl;
|
|
436
|
+
routeConfig.middlewares = controller.middlewares.map(__assignType(v => {
|
|
437
|
+
return { config: v(), module };
|
|
438
|
+
}, ['v', '', 'P"2!"/"']));
|
|
439
|
+
routeConfig.resolverForToken = new Map(controller.resolverForToken);
|
|
440
|
+
routeConfig.resolverForParameterName = new Map(controller.resolverForParameterName);
|
|
441
|
+
}
|
|
442
|
+
routeConfig.middlewares.push(...action.middlewares.map(__assignType(v => {
|
|
443
|
+
return { config: v(), module };
|
|
444
|
+
}, ['v', '', 'P"2!"/"'])));
|
|
445
|
+
for (const item of action.resolverForToken)
|
|
446
|
+
routeConfig.resolverForToken.set(...item);
|
|
447
|
+
for (const item of action.resolverForParameterName)
|
|
448
|
+
routeConfig.resolverForParameterName.set(...item);
|
|
449
|
+
routeConfig.serializer = action.serializer;
|
|
450
|
+
routeConfig.serializationOptions = action.serializationOptions;
|
|
451
|
+
return routeConfig;
|
|
452
|
+
}
|
|
453
|
+
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"/*'];
|
|
454
|
+
class HttpRouterRegistry extends HttpRouterRegistryFunctionRegistrar {
|
|
455
|
+
constructor() {
|
|
456
|
+
super(...arguments);
|
|
457
|
+
this.routes = [];
|
|
458
|
+
this.buildId = 1;
|
|
459
|
+
}
|
|
460
|
+
getBuildId() {
|
|
461
|
+
return this.buildId;
|
|
462
|
+
}
|
|
463
|
+
getRoutes() {
|
|
464
|
+
return this.routes;
|
|
465
|
+
}
|
|
466
|
+
addRouteForController(controller, module) {
|
|
467
|
+
const controllerData = decorator_1.httpClass._fetch(controller);
|
|
468
|
+
if (!controllerData)
|
|
469
|
+
throw new Error(`Http controller class ${(0, core_1.getClassName)(controller)} has no @http.controller decorator.`);
|
|
470
|
+
const schema = type_1.ReflectionClass.from(controller);
|
|
471
|
+
for (const action of controllerData.getActions()) {
|
|
472
|
+
const routeAction = {
|
|
473
|
+
type: 'controller',
|
|
474
|
+
controller,
|
|
475
|
+
module,
|
|
476
|
+
methodName: action.methodName
|
|
477
|
+
};
|
|
478
|
+
const routeConfig = createRouteConfigFromHttpAction(routeAction, action, module, controllerData);
|
|
479
|
+
routeConfig.module = module;
|
|
480
|
+
if (schema.hasMethod(action.methodName))
|
|
481
|
+
routeConfig.returnType = schema.getMethod(action.methodName).getReturnType();
|
|
482
|
+
this.addRoute(routeConfig);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
addRoute(routeConfig) {
|
|
486
|
+
this.routes.push(routeConfig);
|
|
487
|
+
this.buildId++;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
exports.HttpRouterRegistry = HttpRouterRegistry;
|
|
491
|
+
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'];
|
|
492
|
+
class HttpRouter {
|
|
493
|
+
constructor(controllers, logger, tagRegistry, middlewareRegistry = new app_1.MiddlewareRegistry, registry = new HttpRouterRegistry) {
|
|
282
494
|
this.logger = logger;
|
|
283
495
|
this.middlewareRegistry = middlewareRegistry;
|
|
284
|
-
this.
|
|
496
|
+
this.registry = registry;
|
|
497
|
+
this.buildId = 0;
|
|
285
498
|
for (const controller of controllers.controllers) {
|
|
286
499
|
this.addRouteForController(controller.controller, controller.module);
|
|
287
500
|
}
|
|
288
501
|
}
|
|
289
|
-
parseBody(req,
|
|
502
|
+
parseBody(req, foundFiles) {
|
|
290
503
|
const form = (0, formidable_1.default)({
|
|
291
504
|
multiples: true,
|
|
292
505
|
hash: 'sha1',
|
|
293
|
-
enabledPlugins: ['octetstream', 'querystring', 'json'],
|
|
294
506
|
});
|
|
295
|
-
return (0, core_1.asyncOperation)(
|
|
507
|
+
return (0, core_1.asyncOperation)(__assignType((resolve, reject) => {
|
|
296
508
|
if (req.body) {
|
|
297
509
|
return resolve(req.body);
|
|
298
510
|
}
|
|
299
|
-
form.parse(req,
|
|
511
|
+
form.parse(req, __assignType((err, fields, files) => {
|
|
300
512
|
if (err) {
|
|
301
513
|
reject(err);
|
|
302
514
|
}
|
|
303
515
|
else {
|
|
304
|
-
const
|
|
516
|
+
for (const [name, file] of Object.entries(files)) {
|
|
517
|
+
if (file.size === 0)
|
|
518
|
+
continue;
|
|
519
|
+
foundFiles[name] = {
|
|
520
|
+
size: file.size,
|
|
521
|
+
path: file.filepath,
|
|
522
|
+
name: file.originalFilename,
|
|
523
|
+
type: file.mimetype,
|
|
524
|
+
lastModifiedDate: file.lastModifiedDate,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const body = req.body = { ...fields, ...foundFiles };
|
|
305
528
|
resolve(body);
|
|
306
529
|
}
|
|
307
|
-
},
|
|
308
|
-
},
|
|
530
|
+
}, ['err', 'fields', 'files', '', 'P"2!"2""2#"/$']));
|
|
531
|
+
}, ['resolve', 'reject', '', 'P"2!"2""/#']));
|
|
309
532
|
}
|
|
310
533
|
getRoutes() {
|
|
311
|
-
return this.
|
|
534
|
+
return this.registry.getRoutes();
|
|
312
535
|
}
|
|
313
536
|
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(
|
|
537
|
+
return new this(new controllers_1.HttpControllers(controllers.map(__assignType(v => {
|
|
315
538
|
return (0, core_1.isClass)(v) ? { controller: v, module } : v;
|
|
316
|
-
},
|
|
539
|
+
}, ['v', '', 'P"2!"/"']))), new logger_1.Logger([], []), tagRegistry, middlewareRegistry);
|
|
317
540
|
}
|
|
318
541
|
getRouteCode(compiler, routeConfig) {
|
|
319
542
|
const routeConfigVar = compiler.reserveVariable('routeConfigVar', routeConfig);
|
|
@@ -364,7 +587,7 @@ class Router {
|
|
|
364
587
|
else {
|
|
365
588
|
parameterNames.push(`parameters.${parameter.parameter.name}`);
|
|
366
589
|
if (parameter.isPartOfPath()) {
|
|
367
|
-
if (parameter.parameter.type.kind !==
|
|
590
|
+
if (parameter.parameter.type.kind !== type_1.ReflectionKind.class) {
|
|
368
591
|
const converted = (0, type_1.getSerializeFunction)(parameter.parameter.parameter, type_1.serializer.deserializeRegistry, undefined, parameter.getName());
|
|
369
592
|
const converterVar = compiler.reserveVariable('argumentConverter', converted);
|
|
370
593
|
setParameters.push(`parameters.${parameter.parameter.name} = ${converterVar}(_match[${1 + (parameter.regexPosition || 0)}], {loosely: true});`);
|
|
@@ -376,7 +599,7 @@ class Router {
|
|
|
376
599
|
setParameters.push(`parameters.${parameter.parameter.name} = _match[${1 + (parameter.regexPosition || 0)}];`);
|
|
377
600
|
}
|
|
378
601
|
}
|
|
379
|
-
const injectorToken = parameter.parameter.type.kind ===
|
|
602
|
+
const injectorToken = parameter.parameter.type.kind === type_1.ReflectionKind.class ? parameter.parameter.type.classType : undefined;
|
|
380
603
|
const injectorTokenVar = compiler.reserveVariable('classType', injectorToken);
|
|
381
604
|
const parameterResolverFoundVar = compiler.reserveVariable('parameterResolverFound', false);
|
|
382
605
|
setParameters.push(`${parameterResolverFoundVar} = false;`);
|
|
@@ -400,7 +623,7 @@ class Router {
|
|
|
400
623
|
${parameterResolverFoundVar} = true;
|
|
401
624
|
parameters.${parameter.parameter.name} = await ${instance}.resolve({
|
|
402
625
|
token: ${injectorTokenVar},
|
|
403
|
-
|
|
626
|
+
route: ${routeConfigVar},
|
|
404
627
|
request: request,
|
|
405
628
|
name: ${JSON.stringify(parameter.parameter.name)},
|
|
406
629
|
value: parameters.${parameter.parameter.name},
|
|
@@ -467,9 +690,9 @@ class Router {
|
|
|
467
690
|
}
|
|
468
691
|
let methodCheck = '';
|
|
469
692
|
if (routeConfig.httpMethods.length) {
|
|
470
|
-
methodCheck = '(' + routeConfig.httpMethods.map(
|
|
693
|
+
methodCheck = '(' + routeConfig.httpMethods.map(__assignType(v => {
|
|
471
694
|
return `_method === '${v.toUpperCase()}'`;
|
|
472
|
-
},
|
|
695
|
+
}, ['v', '', 'P"2!"/"'])).join(' || ') + ') && ';
|
|
473
696
|
}
|
|
474
697
|
return `
|
|
475
698
|
//=> ${routeConfig.httpMethods.join(',')} ${path}
|
|
@@ -481,14 +704,14 @@ class Router {
|
|
|
481
704
|
getRouteUrlResolveCode(compiler, routeConfig) {
|
|
482
705
|
const parsedRoute = parseRouteControllerAction(routeConfig);
|
|
483
706
|
let url = routeConfig.getFullPath();
|
|
484
|
-
url = url.replace(/:(\w+)/g,
|
|
707
|
+
url = url.replace(/:(\w+)/g, __assignType((a, name) => {
|
|
485
708
|
return `\${parameters.${name}}`;
|
|
486
|
-
},
|
|
709
|
+
}, ['a', 'name', '', 'P"2!"2""/#']));
|
|
487
710
|
const modify = [];
|
|
488
711
|
for (const parameter of parsedRoute.getParameters()) {
|
|
489
712
|
if (parameter.query || parameter.queries) {
|
|
490
713
|
const queryPath = parameter.typePath === undefined && parameter.query ? parameter.parameter.name : parameter.typePath || '';
|
|
491
|
-
if (parameter.parameter.type.kind ===
|
|
714
|
+
if (parameter.parameter.type.kind === type_1.ReflectionKind.class || parameter.parameter.type.kind === type_1.ReflectionKind.objectLiteral) {
|
|
492
715
|
for (const property of type_1.ReflectionClass.from(parameter.parameter.type).getProperties()) {
|
|
493
716
|
const accessor = `parameters.${parameter.getName()}?.${property.name}`;
|
|
494
717
|
const thisPath = queryPath ? queryPath + '.' + property.name : property.name;
|
|
@@ -510,55 +733,18 @@ class Router {
|
|
|
510
733
|
`;
|
|
511
734
|
}
|
|
512
735
|
addRoute(routeConfig) {
|
|
513
|
-
this.
|
|
514
|
-
this.fn = undefined;
|
|
736
|
+
this.registry.addRoute(routeConfig);
|
|
515
737
|
}
|
|
516
738
|
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
|
-
}
|
|
739
|
+
this.registry.addRouteForController(controller, module);
|
|
555
740
|
}
|
|
556
741
|
build() {
|
|
742
|
+
this.buildId = this.registry.getBuildId();
|
|
557
743
|
const compiler = new core_1.CompilerContext;
|
|
558
744
|
compiler.context.set('ValidationError', type_1.ValidationError);
|
|
559
745
|
compiler.context.set('qs', qs_1.default);
|
|
560
746
|
const code = [];
|
|
561
|
-
for (const route of this.
|
|
747
|
+
for (const route of this.getRoutes()) {
|
|
562
748
|
code.push(this.getRouteCode(compiler, route));
|
|
563
749
|
}
|
|
564
750
|
return compiler.build(`
|
|
@@ -575,7 +761,7 @@ class Router {
|
|
|
575
761
|
buildUrlResolver() {
|
|
576
762
|
const compiler = new core_1.CompilerContext;
|
|
577
763
|
const code = [];
|
|
578
|
-
for (const route of this.
|
|
764
|
+
for (const route of this.getRoutes()) {
|
|
579
765
|
code.push(this.getRouteUrlResolveCode(compiler, route));
|
|
580
766
|
}
|
|
581
767
|
return compiler.build(`
|
|
@@ -592,7 +778,7 @@ class Router {
|
|
|
592
778
|
return this.resolveFn(routeName, parameters);
|
|
593
779
|
}
|
|
594
780
|
resolveRequest(request) {
|
|
595
|
-
if (!this.fn) {
|
|
781
|
+
if (!this.fn || this.buildId !== this.registry.getBuildId()) {
|
|
596
782
|
this.fn = this.build();
|
|
597
783
|
}
|
|
598
784
|
return this.fn(request);
|
|
@@ -602,6 +788,6 @@ class Router {
|
|
|
602
788
|
return this.resolveRequest({ url, method });
|
|
603
789
|
}
|
|
604
790
|
}
|
|
605
|
-
exports.
|
|
606
|
-
|
|
791
|
+
exports.HttpRouter = HttpRouter;
|
|
792
|
+
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>IP7J0KPP7L2MP7N2O&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
793
|
//# sourceMappingURL=router.js.map
|