@deepkit/http 1.0.1-alpha.73 → 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/http.js +1 -1
- package/dist/cjs/src/model.js +4 -4
- package/dist/cjs/src/model.js.map +1 -1
- package/dist/cjs/src/router.js +19 -9
- package/dist/cjs/src/router.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/http.js +1 -1
- package/dist/esm/src/model.js +6 -6
- package/dist/esm/src/model.js.map +1 -1
- package/dist/esm/src/router.js +19 -9
- package/dist/esm/src/router.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/src/router.ts +16 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepkit/http",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.74",
|
|
4
4
|
"description": "Deepkit HTTP server and router.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"send": "^0.18.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@deepkit/app": "^1.0.1-alpha.
|
|
42
|
-
"@deepkit/core": "^1.0.1-alpha.
|
|
43
|
-
"@deepkit/event": "^1.0.1-alpha.
|
|
44
|
-
"@deepkit/injector": "^1.0.1-alpha.
|
|
45
|
-
"@deepkit/logger": "^1.0.1-alpha.
|
|
46
|
-
"@deepkit/stopwatch": "^1.0.1-alpha.
|
|
47
|
-
"@deepkit/template": "^1.0.1-alpha.
|
|
48
|
-
"@deepkit/type": "^1.0.1-alpha.
|
|
49
|
-
"@deepkit/workflow": "^1.0.1-alpha.
|
|
41
|
+
"@deepkit/app": "^1.0.1-alpha.74",
|
|
42
|
+
"@deepkit/core": "^1.0.1-alpha.74",
|
|
43
|
+
"@deepkit/event": "^1.0.1-alpha.74",
|
|
44
|
+
"@deepkit/injector": "^1.0.1-alpha.74",
|
|
45
|
+
"@deepkit/logger": "^1.0.1-alpha.74",
|
|
46
|
+
"@deepkit/stopwatch": "^1.0.1-alpha.74",
|
|
47
|
+
"@deepkit/template": "^1.0.1-alpha.74",
|
|
48
|
+
"@deepkit/type": "^1.0.1-alpha.74",
|
|
49
|
+
"@deepkit/workflow": "^1.0.1-alpha.74",
|
|
50
50
|
"@types/node": "14.14.28",
|
|
51
51
|
"@types/send": "^0.14.6"
|
|
52
52
|
},
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"**/tests/**/*.spec.ts"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "b45ede82baf9b92917b49b50fff58efb16e3959d"
|
|
66
66
|
}
|
package/src/router.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* You should have received a copy of the MIT License along with this program.
|
|
9
9
|
*/
|
|
10
|
-
import { asyncOperation, ClassType, CompilerContext, getClassName, isClass, isObject, urlJoin } from '@deepkit/core';
|
|
10
|
+
import { asyncOperation, ClassType, CompilerContext, getClassName, isArray, isClass, isObject, urlJoin } from '@deepkit/core';
|
|
11
11
|
import {
|
|
12
12
|
assertType,
|
|
13
13
|
entity,
|
|
@@ -29,7 +29,6 @@ import {
|
|
|
29
29
|
} from '@deepkit/type';
|
|
30
30
|
// @ts-ignore
|
|
31
31
|
import formidable from 'formidable';
|
|
32
|
-
import querystring from 'querystring';
|
|
33
32
|
import { HttpAction, httpClass, HttpController, HttpDecorator } from './decorator';
|
|
34
33
|
import { BodyValidationError, getRegExp, HttpRequest, HttpRequestQuery, HttpRequestResolvedParameters, ValidatedBody } from './model';
|
|
35
34
|
import { InjectorContext, InjectorModule, TagRegistry } from '@deepkit/injector';
|
|
@@ -40,7 +39,7 @@ import { HttpMiddlewareConfig, HttpMiddlewareFn } from './middleware';
|
|
|
40
39
|
|
|
41
40
|
//@ts-ignore
|
|
42
41
|
import qs from 'qs';
|
|
43
|
-
import {
|
|
42
|
+
import { HtmlResponse, JSONResponse, Response } from './http.js';
|
|
44
43
|
|
|
45
44
|
export type RouteParameterResolverForInjector = ((injector: InjectorContext) => any[] | Promise<any[]>);
|
|
46
45
|
|
|
@@ -418,6 +417,14 @@ function convertOptions(methods: string[], pathOrOptions: string | HttpRouterFun
|
|
|
418
417
|
return { ...options, methods };
|
|
419
418
|
}
|
|
420
419
|
|
|
420
|
+
/**
|
|
421
|
+
* Annotated types like HTMLResponse/JSONResponse are not used for serialization.
|
|
422
|
+
*/
|
|
423
|
+
function filterValidReturnType(type: Type): Type | undefined {
|
|
424
|
+
if (type.kind === ReflectionKind.class && (type.classType === HtmlResponse || type.classType === JSONResponse || type.classType === Response)) return;
|
|
425
|
+
return type;
|
|
426
|
+
}
|
|
427
|
+
|
|
421
428
|
export abstract class HttpRouterRegistryFunctionRegistrar {
|
|
422
429
|
protected defaultOptions: Partial<HttpRouterFunctionOptions> = {};
|
|
423
430
|
|
|
@@ -463,7 +470,7 @@ export abstract class HttpRouterRegistryFunctionRegistrar {
|
|
|
463
470
|
type: 'function',
|
|
464
471
|
fn: callback,
|
|
465
472
|
}, action);
|
|
466
|
-
routeConfig.returnType = fn.getReturnType();
|
|
473
|
+
routeConfig.returnType = filterValidReturnType(fn.getReturnType());
|
|
467
474
|
this.addRoute(routeConfig);
|
|
468
475
|
}
|
|
469
476
|
|
|
@@ -534,7 +541,7 @@ export abstract class HttpRouterRegistryFunctionRegistrar {
|
|
|
534
541
|
routeConfig.serializer = options.serializer;
|
|
535
542
|
routeConfig.serializationOptions = options.serializationOptions;
|
|
536
543
|
|
|
537
|
-
routeConfig.returnType = fn.getReturnType();
|
|
544
|
+
routeConfig.returnType = filterValidReturnType(fn.getReturnType());
|
|
538
545
|
this.addRoute(routeConfig);
|
|
539
546
|
}
|
|
540
547
|
}
|
|
@@ -597,7 +604,7 @@ export class HttpRouterRegistry extends HttpRouterRegistryFunctionRegistrar {
|
|
|
597
604
|
|
|
598
605
|
routeConfig.module = module;
|
|
599
606
|
|
|
600
|
-
if (schema.hasMethod(action.methodName)) routeConfig.returnType = schema.getMethod(action.methodName).getReturnType();
|
|
607
|
+
if (schema.hasMethod(action.methodName)) routeConfig.returnType = filterValidReturnType(schema.getMethod(action.methodName).getReturnType());
|
|
601
608
|
this.addRoute(routeConfig);
|
|
602
609
|
}
|
|
603
610
|
}
|
|
@@ -674,7 +681,8 @@ export class HttpRouter {
|
|
|
674
681
|
const routeConfigVar = compiler.reserveVariable('routeConfigVar', routeConfig);
|
|
675
682
|
const parsedRoute = parseRouteControllerAction(routeConfig);
|
|
676
683
|
const path = routeConfig.getFullPath();
|
|
677
|
-
const
|
|
684
|
+
const pathParamStarter = path.indexOf(':')
|
|
685
|
+
const prefix = path.substr(0, pathParamStarter);
|
|
678
686
|
|
|
679
687
|
const regexVar = compiler.reserveVariable('regex', new RegExp('^' + parsedRoute.regex + '$'));
|
|
680
688
|
const setParameters: string[] = [];
|
|
@@ -683,7 +691,7 @@ export class HttpRouter {
|
|
|
683
691
|
let bodyValidationErrorHandling = `if (bodyErrors.length) throw ValidationError.from(bodyErrors);`;
|
|
684
692
|
|
|
685
693
|
let enableParseBody = false;
|
|
686
|
-
const hasParameters = parsedRoute.getParameters().length > 0;
|
|
694
|
+
const hasParameters = pathParamStarter !== -1 || parsedRoute.getParameters().length > 0;
|
|
687
695
|
let requiresAsyncParameters = false;
|
|
688
696
|
let setParametersFromPath = '';
|
|
689
697
|
|