@deepkit/http 1.0.1-alpha.59 → 1.0.1-alpha.63
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/coverage/clover.xml +1086 -0
- package/coverage/coverage-final.json +12 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +126 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/src/controllers.ts.html +113 -0
- package/coverage/lcov-report/src/decorator.ts.html +1280 -0
- package/coverage/lcov-report/src/filter.ts.html +734 -0
- package/coverage/lcov-report/src/http.ts.html +2192 -0
- package/coverage/lcov-report/src/index.html +246 -0
- package/coverage/lcov-report/src/kernel.ts.html +260 -0
- package/coverage/lcov-report/src/middleware.ts.html +428 -0
- package/coverage/lcov-report/src/model.ts.html +937 -0
- package/coverage/lcov-report/src/module.config.ts.html +89 -0
- package/coverage/lcov-report/src/module.ts.html +245 -0
- package/coverage/lcov-report/src/router.ts.html +2318 -0
- package/coverage/lcov-report/tests/index.html +111 -0
- package/coverage/lcov-report/tests/utils.ts.html +176 -0
- package/coverage/lcov.info +2225 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/controllers.d.ts +4 -4
- package/dist/cjs/src/controllers.js +3 -0
- package/dist/cjs/src/controllers.js.map +1 -1
- package/dist/cjs/src/decorator.d.ts +29 -94
- package/dist/cjs/src/decorator.js +53 -118
- package/dist/cjs/src/decorator.js.map +1 -1
- package/dist/cjs/src/filter.d.ts +1 -0
- package/dist/cjs/src/filter.js +11 -17
- package/dist/cjs/src/filter.js.map +1 -1
- package/dist/cjs/src/http.d.ts +5 -3
- package/dist/cjs/src/http.js +91 -55
- package/dist/cjs/src/http.js.map +1 -1
- package/dist/cjs/src/kernel.d.ts +3 -3
- package/dist/cjs/src/kernel.js +5 -25
- package/dist/cjs/src/kernel.js.map +1 -1
- package/dist/cjs/src/logger.d.ts +2 -2
- package/dist/cjs/src/logger.js +4 -8
- package/dist/cjs/src/logger.js.map +1 -1
- package/dist/cjs/src/middleware.d.ts +5 -1
- package/dist/cjs/src/middleware.js +15 -3
- package/dist/cjs/src/middleware.js.map +1 -1
- package/dist/cjs/src/model.d.ts +62 -2
- package/dist/cjs/src/model.js +101 -26
- package/dist/cjs/src/model.js.map +1 -1
- package/dist/cjs/src/module.config.d.ts +3 -4
- package/dist/cjs/src/module.config.js +8 -6
- package/dist/cjs/src/module.config.js.map +1 -1
- package/dist/cjs/src/module.d.ts +2 -3
- package/dist/cjs/src/module.js +4 -2
- package/dist/cjs/src/module.js.map +1 -1
- package/dist/cjs/src/router.d.ts +24 -53
- package/dist/cjs/src/router.js +140 -159
- package/dist/cjs/src/router.js.map +1 -1
- package/dist/cjs/src/static-serving.d.ts +1 -0
- package/dist/cjs/src/static-serving.js +46 -39
- package/dist/cjs/src/static-serving.js.map +1 -1
- package/dist/cjs/src/utils.js +1 -0
- package/dist/cjs/tests/filter.spec.js +61 -47
- package/dist/cjs/tests/filter.spec.js.map +1 -1
- package/dist/cjs/tests/middleware.spec.d.ts +1 -1
- package/dist/cjs/tests/middleware.spec.js +157 -145
- package/dist/cjs/tests/middleware.spec.js.map +1 -1
- package/dist/cjs/tests/model.spec.js +4 -4
- package/dist/cjs/tests/model.spec.js.map +1 -1
- package/dist/cjs/tests/module.spec.js +4 -3
- package/dist/cjs/tests/module.spec.js.map +1 -1
- package/dist/cjs/tests/router.spec.d.ts +1 -1
- package/dist/cjs/tests/router.spec.js +298 -333
- package/dist/cjs/tests/router.spec.js.map +1 -1
- package/dist/cjs/tests/utils.js +5 -2
- package/dist/cjs/tests/utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/controllers.d.ts +4 -4
- package/dist/esm/src/controllers.js +3 -0
- package/dist/esm/src/controllers.js.map +1 -1
- package/dist/esm/src/decorator.d.ts +29 -94
- package/dist/esm/src/decorator.js +49 -114
- package/dist/esm/src/decorator.js.map +1 -1
- package/dist/esm/src/filter.d.ts +1 -0
- package/dist/esm/src/filter.js +11 -18
- package/dist/esm/src/filter.js.map +1 -1
- package/dist/esm/src/http.d.ts +5 -3
- package/dist/esm/src/http.js +89 -55
- package/dist/esm/src/http.js.map +1 -1
- package/dist/esm/src/kernel.d.ts +3 -3
- package/dist/esm/src/kernel.js +6 -27
- package/dist/esm/src/kernel.js.map +1 -1
- package/dist/esm/src/logger.d.ts +2 -2
- package/dist/esm/src/logger.js +4 -9
- package/dist/esm/src/logger.js.map +1 -1
- package/dist/esm/src/middleware.d.ts +5 -1
- package/dist/esm/src/middleware.js +12 -0
- package/dist/esm/src/middleware.js.map +1 -1
- package/dist/esm/src/model.d.ts +62 -2
- package/dist/esm/src/model.js +92 -24
- package/dist/esm/src/model.js.map +1 -1
- package/dist/esm/src/module.config.d.ts +3 -4
- package/dist/esm/src/module.config.js +6 -5
- package/dist/esm/src/module.config.js.map +1 -1
- package/dist/esm/src/module.d.ts +2 -3
- package/dist/esm/src/module.js +5 -3
- package/dist/esm/src/module.js.map +1 -1
- package/dist/esm/src/router.d.ts +24 -53
- package/dist/esm/src/router.js +136 -155
- package/dist/esm/src/router.js.map +1 -1
- package/dist/esm/src/static-serving.d.ts +1 -0
- package/dist/esm/src/static-serving.js +39 -32
- package/dist/esm/src/static-serving.js.map +1 -1
- package/dist/esm/src/utils.js +1 -0
- package/dist/esm/tests/filter.spec.js +14 -0
- package/dist/esm/tests/filter.spec.js.map +1 -1
- package/dist/esm/tests/middleware.spec.d.ts +1 -1
- package/dist/esm/tests/middleware.spec.js +60 -48
- package/dist/esm/tests/middleware.spec.js.map +1 -1
- package/dist/esm/tests/module.spec.js +1 -0
- package/dist/esm/tests/module.spec.js.map +1 -1
- package/dist/esm/tests/router.spec.d.ts +1 -1
- package/dist/esm/tests/router.spec.js +167 -202
- package/dist/esm/tests/router.spec.js.map +1 -1
- package/dist/esm/tests/utils.js +4 -1
- package/dist/esm/tests/utils.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +14 -15
- package/src/controllers.ts +3 -3
- package/src/decorator.ts +42 -131
- package/src/filter.ts +0 -2
- package/src/http.ts +35 -36
- package/src/kernel.ts +4 -5
- package/src/logger.ts +2 -4
- package/src/middleware.ts +2 -1
- package/src/model.ts +80 -8
- package/src/module.config.ts +3 -6
- package/src/module.ts +2 -2
- package/src/router.ts +121 -161
- package/src/static-serving.ts +14 -12
- package/tests/middleware.spec.ts +0 -1
- package/tests/router.spec.ts +131 -133
- package/tsconfig.json +2 -1
|
@@ -8,22 +8,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var { __ΩHttpRegExp } = require('../src/model');
|
|
13
|
+
var { __ΩRouteParameterResolverContext } = require('../src/router');
|
|
14
|
+
var { __ΩHttpBody } = require('../src/model');
|
|
15
|
+
var { __ΩHttpQuery } = require('../src/model');
|
|
16
|
+
var { __ΩHttpQueries } = require('../src/model');
|
|
17
|
+
var { __ΩGroup } = require('@deepkit/type');
|
|
18
|
+
var { __ΩMinLength } = require('@deepkit/type');
|
|
19
|
+
var { __ΩHttpBodyValidation } = require('../src/model');
|
|
15
20
|
const globals_1 = require("@jest/globals");
|
|
16
|
-
require("reflect-metadata");
|
|
17
21
|
const router_1 = require("../src/router");
|
|
18
22
|
const decorator_1 = require("../src/decorator");
|
|
19
|
-
const type_1 = require("@deepkit/type");
|
|
20
23
|
const http_1 = require("../src/http");
|
|
21
24
|
const event_1 = require("@deepkit/event");
|
|
22
|
-
const injector_1 = require("@deepkit/injector");
|
|
23
25
|
const model_1 = require("../src/model");
|
|
24
26
|
const core_1 = require("@deepkit/core");
|
|
25
27
|
const utils_1 = require("./utils");
|
|
26
|
-
globals_1.test('router', async () => {
|
|
28
|
+
(0, globals_1.test)('router', async () => {
|
|
27
29
|
var _a, _b, _c;
|
|
28
30
|
class Controller {
|
|
29
31
|
helloWorld() {
|
|
@@ -37,6 +39,7 @@ globals_1.test('router', async () => {
|
|
|
37
39
|
any() {
|
|
38
40
|
}
|
|
39
41
|
}
|
|
42
|
+
Controller.__type = ['helloWorld', 'name', 'hello', 'id', 'userStatic', 'id2', 'userStatic2', 'any', 'P"0!P&2""0#P&2$"0%P&2$&2&"0\'P"0(5'];
|
|
40
43
|
__decorate([
|
|
41
44
|
decorator_1.http.GET(),
|
|
42
45
|
__metadata("design:type", Function),
|
|
@@ -68,21 +71,22 @@ globals_1.test('router', async () => {
|
|
|
68
71
|
__metadata("design:returntype", void 0)
|
|
69
72
|
], Controller.prototype, "any", null);
|
|
70
73
|
const router = router_1.Router.forControllers([Controller]);
|
|
71
|
-
globals_1.expect((_a = (await router.resolve('GET', '/'))) === null || _a === void 0 ? void 0 : _a.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'helloWorld' });
|
|
72
|
-
globals_1.expect((_b = (await router.resolve('GET', '/peter'))) === null || _b === void 0 ? void 0 : _b.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'hello' });
|
|
73
|
-
globals_1.expect((_c = (await router.resolve('GET', '/peter'))) === null || _c === void 0 ? void 0 : _c.parameters(undefined)).toEqual(['peter']);
|
|
74
|
+
(0, globals_1.expect)((_a = (await router.resolve('GET', '/'))) === null || _a === void 0 ? void 0 : _a.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'helloWorld' });
|
|
75
|
+
(0, globals_1.expect)((_b = (await router.resolve('GET', '/peter'))) === null || _b === void 0 ? void 0 : _b.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'hello' });
|
|
76
|
+
(0, globals_1.expect)((_c = (await router.resolve('GET', '/peter'))) === null || _c === void 0 ? void 0 : _c.parameters(undefined)).toEqual(['peter']);
|
|
74
77
|
const userStatic = await router.resolve('GET', '/user/1233/static');
|
|
75
|
-
globals_1.expect(userStatic === null || userStatic === void 0 ? void 0 : userStatic.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'userStatic' });
|
|
76
|
-
globals_1.expect(userStatic === null || userStatic === void 0 ? void 0 : userStatic.parameters(undefined)).toEqual(['1233']);
|
|
78
|
+
(0, globals_1.expect)(userStatic === null || userStatic === void 0 ? void 0 : userStatic.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'userStatic' });
|
|
79
|
+
(0, globals_1.expect)(userStatic === null || userStatic === void 0 ? void 0 : userStatic.parameters(undefined)).toEqual(['1233']);
|
|
77
80
|
const userStatic2 = await router.resolve('GET', '/user2/1233/static/123');
|
|
78
|
-
globals_1.expect(userStatic2 === null || userStatic2 === void 0 ? void 0 : userStatic2.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'userStatic2' });
|
|
79
|
-
globals_1.expect(userStatic2 === null || userStatic2 === void 0 ? void 0 : userStatic2.parameters(undefined)).toEqual(['1233', '123']);
|
|
81
|
+
(0, globals_1.expect)(userStatic2 === null || userStatic2 === void 0 ? void 0 : userStatic2.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'userStatic2' });
|
|
82
|
+
(0, globals_1.expect)(userStatic2 === null || userStatic2 === void 0 ? void 0 : userStatic2.parameters(undefined)).toEqual(['1233', '123']);
|
|
80
83
|
});
|
|
81
|
-
globals_1.test('any', async () => {
|
|
84
|
+
(0, globals_1.test)('any', async () => {
|
|
82
85
|
class Controller {
|
|
83
86
|
any() {
|
|
84
87
|
}
|
|
85
88
|
}
|
|
89
|
+
Controller.__type = ['any', 'P"0!5'];
|
|
86
90
|
__decorate([
|
|
87
91
|
decorator_1.http.ANY('/any'),
|
|
88
92
|
__metadata("design:type", Function),
|
|
@@ -90,11 +94,11 @@ globals_1.test('any', async () => {
|
|
|
90
94
|
__metadata("design:returntype", void 0)
|
|
91
95
|
], Controller.prototype, "any", null);
|
|
92
96
|
const router = router_1.Router.forControllers([Controller]);
|
|
93
|
-
globals_1.expect((await router.resolve('GET', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
94
|
-
globals_1.expect((await router.resolve('POST', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
95
|
-
globals_1.expect((await router.resolve('OPTIONS', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
97
|
+
(0, globals_1.expect)((await router.resolve('GET', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
98
|
+
(0, globals_1.expect)((await router.resolve('POST', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
99
|
+
(0, globals_1.expect)((await router.resolve('OPTIONS', '/any')).routeConfig.action.methodName).toEqual('any');
|
|
96
100
|
});
|
|
97
|
-
globals_1.test('router parameters', async () => {
|
|
101
|
+
(0, globals_1.test)('router parameters', async () => {
|
|
98
102
|
var _a;
|
|
99
103
|
class Controller {
|
|
100
104
|
string(name) {
|
|
@@ -110,6 +114,7 @@ globals_1.test('router parameters', async () => {
|
|
|
110
114
|
return new http_1.JSONResponse(path);
|
|
111
115
|
}
|
|
112
116
|
}
|
|
117
|
+
Controller.__type = ['name', 'string', 'id', 'number', 'yes', 'boolean', () => __ΩHttpRegExp, ".*", 'path', 'any', 'P&2!"0"P\'2#"0$P)2%"0&P&.(o\'#2)"0*5'];
|
|
113
118
|
__decorate([
|
|
114
119
|
decorator_1.http.GET('/user/:name'),
|
|
115
120
|
__metadata("design:type", Function),
|
|
@@ -129,48 +134,51 @@ globals_1.test('router parameters', async () => {
|
|
|
129
134
|
__metadata("design:returntype", void 0)
|
|
130
135
|
], Controller.prototype, "boolean", null);
|
|
131
136
|
__decorate([
|
|
132
|
-
decorator_1.http.GET(':path')
|
|
137
|
+
decorator_1.http.GET(':path'),
|
|
133
138
|
__metadata("design:type", Function),
|
|
134
|
-
__metadata("design:paramtypes", [
|
|
139
|
+
__metadata("design:paramtypes", [Object]),
|
|
135
140
|
__metadata("design:returntype", void 0)
|
|
136
141
|
], Controller.prototype, "any", null);
|
|
137
142
|
const router = router_1.Router.forControllers([Controller]);
|
|
138
|
-
globals_1.expect((_a = (await router.resolve('GET', '/user/peter'))) === null || _a === void 0 ? void 0 : _a.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'string' });
|
|
139
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
140
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toBe('peter');
|
|
141
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user-id/123'))).json).toBe(123);
|
|
142
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user-id/asd'))).json).toMatchObject({ message: 'Validation
|
|
143
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/boolean/1'))).json).toBe(true);
|
|
144
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/boolean/false'))).json).toBe(false);
|
|
145
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/any'))).json).toBe('any');
|
|
146
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/any/path'))).json).toBe('any/path');
|
|
143
|
+
(0, globals_1.expect)((_a = (await router.resolve('GET', '/user/peter'))) === null || _a === void 0 ? void 0 : _a.routeConfig.action).toMatchObject({ controller: Controller, methodName: 'string' });
|
|
144
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
145
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toBe('peter');
|
|
146
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user-id/123'))).json).toBe(123);
|
|
147
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user-id/asd'))).json).toMatchObject({ message: 'Validation error:\nid(type): Cannot convert asd to number' });
|
|
148
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/boolean/1'))).json).toBe(true);
|
|
149
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/boolean/false'))).json).toBe(false);
|
|
150
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/any'))).json).toBe('any');
|
|
151
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/any/path'))).json).toBe('any/path');
|
|
147
152
|
});
|
|
148
|
-
globals_1.test('router HttpRequest', async () => {
|
|
153
|
+
(0, globals_1.test)('router HttpRequest', async () => {
|
|
149
154
|
class Controller {
|
|
150
155
|
anyReq(req, path) {
|
|
151
156
|
return [req.url, path];
|
|
152
157
|
}
|
|
153
158
|
}
|
|
159
|
+
Controller.__type = [() => model_1.HttpRequest, 'req', () => __ΩHttpRegExp, ".*", 'path', 'anyReq', 'PP7!2"&.$o##2%"0&5'];
|
|
154
160
|
__decorate([
|
|
155
|
-
decorator_1.http.GET(':path')
|
|
161
|
+
decorator_1.http.GET(':path'),
|
|
156
162
|
__metadata("design:type", Function),
|
|
157
|
-
__metadata("design:paramtypes", [model_1.HttpRequest,
|
|
163
|
+
__metadata("design:paramtypes", [model_1.HttpRequest, Object]),
|
|
158
164
|
__metadata("design:returntype", void 0)
|
|
159
165
|
], Controller.prototype, "anyReq", null);
|
|
160
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
161
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/req/any/path'))).json).toEqual(['/req/any/path', 'req/any/path']);
|
|
166
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
167
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/req/any/path'))).json).toEqual(['/req/any/path', 'req/any/path']);
|
|
162
168
|
});
|
|
163
|
-
globals_1.test('router parameter resolver by class', async () => {
|
|
169
|
+
(0, globals_1.test)('router parameter resolver by class', async () => {
|
|
164
170
|
class User {
|
|
165
171
|
constructor(username) {
|
|
166
172
|
this.username = username;
|
|
167
173
|
}
|
|
168
174
|
}
|
|
175
|
+
User.__type = ['username', 'constructor', 'P&2!:"0"5'];
|
|
169
176
|
class Group {
|
|
170
177
|
constructor(name) {
|
|
171
178
|
this.name = name;
|
|
172
179
|
}
|
|
173
180
|
}
|
|
181
|
+
Group.__type = ['name', 'constructor', 'P&2!:"0"5'];
|
|
174
182
|
class UserResolver {
|
|
175
183
|
resolve(context) {
|
|
176
184
|
const value = context.value || context.parameters.username;
|
|
@@ -179,6 +187,7 @@ globals_1.test('router parameter resolver by class', async () => {
|
|
|
179
187
|
return new User(value);
|
|
180
188
|
}
|
|
181
189
|
}
|
|
190
|
+
UserResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
182
191
|
class GroupResolver {
|
|
183
192
|
resolve(context) {
|
|
184
193
|
if (!context.value)
|
|
@@ -186,6 +195,7 @@ globals_1.test('router parameter resolver by class', async () => {
|
|
|
186
195
|
return new Group(context.value);
|
|
187
196
|
}
|
|
188
197
|
}
|
|
198
|
+
GroupResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
189
199
|
let Controller = class Controller {
|
|
190
200
|
route1(user) {
|
|
191
201
|
return [user.username];
|
|
@@ -197,6 +207,7 @@ globals_1.test('router parameter resolver by class', async () => {
|
|
|
197
207
|
return [user.username, group.name];
|
|
198
208
|
}
|
|
199
209
|
};
|
|
210
|
+
Controller.__type = [() => User, 'user', 'route1', () => User, 'route2', () => User, () => Group, 'group', 'route3', 'PP7!2""0#PP7$2""0%PP7&2"P7\'2("0)5'];
|
|
200
211
|
__decorate([
|
|
201
212
|
decorator_1.http.GET('user/:username'),
|
|
202
213
|
__metadata("design:type", Function),
|
|
@@ -219,26 +230,28 @@ globals_1.test('router parameter resolver by class', async () => {
|
|
|
219
230
|
decorator_1.http.resolveParameter(User, UserResolver)
|
|
220
231
|
], Controller);
|
|
221
232
|
const data = decorator_1.httpClass._fetch(Controller);
|
|
222
|
-
globals_1.expect(data.getActions().size).toBe(3);
|
|
223
|
-
globals_1.expect(data.resolverForToken.get(User)).toBe(UserResolver);
|
|
224
|
-
globals_1.expect(data.resolverForToken.get(User)).toBe(UserResolver);
|
|
225
|
-
globals_1.expect(data.getAction('route3').resolverForToken.get(Group)).toBe(GroupResolver);
|
|
226
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [UserResolver, GroupResolver]);
|
|
227
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toEqual(['peter']);
|
|
228
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user/peter/group/a'))).json).toEqual(['peter', 'a']);
|
|
229
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/invalid'))).bodyString).toEqual('Internal error');
|
|
233
|
+
(0, globals_1.expect)(data.getActions().size).toBe(3);
|
|
234
|
+
(0, globals_1.expect)(data.resolverForToken.get(User)).toBe(UserResolver);
|
|
235
|
+
(0, globals_1.expect)(data.resolverForToken.get(User)).toBe(UserResolver);
|
|
236
|
+
(0, globals_1.expect)(data.getAction('route3').resolverForToken.get(Group)).toBe(GroupResolver);
|
|
237
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [UserResolver, GroupResolver]);
|
|
238
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toEqual(['peter']);
|
|
239
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter/group/a'))).json).toEqual(['peter', 'a']);
|
|
240
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/invalid'))).bodyString).toEqual('Internal error');
|
|
230
241
|
});
|
|
231
|
-
globals_1.test('router parameter resolver by name', async () => {
|
|
242
|
+
(0, globals_1.test)('router parameter resolver by name', async () => {
|
|
232
243
|
class User {
|
|
233
244
|
constructor(username) {
|
|
234
245
|
this.username = username;
|
|
235
246
|
}
|
|
236
247
|
}
|
|
248
|
+
User.__type = ['username', 'constructor', 'P&2!:"0"5'];
|
|
237
249
|
class Group {
|
|
238
250
|
constructor(name) {
|
|
239
251
|
this.name = name;
|
|
240
252
|
}
|
|
241
253
|
}
|
|
254
|
+
Group.__type = ['name', 'constructor', 'P&2!:"0"5'];
|
|
242
255
|
class UserResolver {
|
|
243
256
|
resolve(context) {
|
|
244
257
|
const value = context.value || context.parameters.username;
|
|
@@ -248,6 +261,7 @@ globals_1.test('router parameter resolver by name', async () => {
|
|
|
248
261
|
return new User(value);
|
|
249
262
|
}
|
|
250
263
|
}
|
|
264
|
+
UserResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
251
265
|
class GroupResolver {
|
|
252
266
|
resolve(context) {
|
|
253
267
|
if (!context.value)
|
|
@@ -255,16 +269,19 @@ globals_1.test('router parameter resolver by name', async () => {
|
|
|
255
269
|
return new Group(context.value);
|
|
256
270
|
}
|
|
257
271
|
}
|
|
272
|
+
GroupResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
258
273
|
class MyAuth {
|
|
259
274
|
constructor(name) {
|
|
260
275
|
this.name = name;
|
|
261
276
|
}
|
|
262
277
|
}
|
|
278
|
+
MyAuth.__type = ['name', 'constructor', 'P&2!:"0"5'];
|
|
263
279
|
class AuthResolver {
|
|
264
280
|
resolve(context) {
|
|
265
281
|
return new MyAuth('auth');
|
|
266
282
|
}
|
|
267
283
|
}
|
|
284
|
+
AuthResolver.__type = [() => __ΩRouteParameterResolverContext, 'context', 'resolve', 'Pn!2"P""`J0#5'];
|
|
268
285
|
let Controller = class Controller {
|
|
269
286
|
route1(user) {
|
|
270
287
|
return [user.username];
|
|
@@ -276,9 +293,10 @@ globals_1.test('router parameter resolver by name', async () => {
|
|
|
276
293
|
return [user.username, group.name];
|
|
277
294
|
}
|
|
278
295
|
nonClass(auth) {
|
|
279
|
-
return [auth.name, core_1.getClassName(auth)];
|
|
296
|
+
return [auth.name, (0, core_1.getClassName)(auth)];
|
|
280
297
|
}
|
|
281
298
|
};
|
|
299
|
+
Controller.__type = [() => User, 'user', 'route1', () => User, 'route2', () => User, () => Group, 'group', 'route3', 'auth', 'nonClass', 'PP7!2""0#PP7$2""0%PP7&2"P7\'2("0)P"2*"0+5'];
|
|
282
300
|
__decorate([
|
|
283
301
|
decorator_1.http.GET('user/:username'),
|
|
284
302
|
__metadata("design:type", Function),
|
|
@@ -307,95 +325,98 @@ globals_1.test('router parameter resolver by name', async () => {
|
|
|
307
325
|
decorator_1.http.resolveParameterByName('user', UserResolver)
|
|
308
326
|
], Controller);
|
|
309
327
|
const data = decorator_1.httpClass._fetch(Controller);
|
|
310
|
-
globals_1.expect(data.getActions().size).toBe(4);
|
|
311
|
-
globals_1.expect(data.resolverForParameterName.get('user')).toBe(UserResolver);
|
|
312
|
-
globals_1.expect(data.getAction('route3').resolverForParameterName.get('group')).toBe(GroupResolver);
|
|
313
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [UserResolver, GroupResolver, AuthResolver]);
|
|
314
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toEqual(['peter']);
|
|
315
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/user/peter/group/a'))).json).toEqual(['peter', 'a']);
|
|
316
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/invalid'))).bodyString).toEqual('Internal error');
|
|
317
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/nonClass'))).json).toEqual(['auth', 'MyAuth']);
|
|
328
|
+
(0, globals_1.expect)(data.getActions().size).toBe(4);
|
|
329
|
+
(0, globals_1.expect)(data.resolverForParameterName.get('user')).toBe(UserResolver);
|
|
330
|
+
(0, globals_1.expect)(data.getAction('route3').resolverForParameterName.get('group')).toBe(GroupResolver);
|
|
331
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [UserResolver, GroupResolver, AuthResolver]);
|
|
332
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter'))).json).toEqual(['peter']);
|
|
333
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/user/peter/group/a'))).json).toEqual(['peter', 'a']);
|
|
334
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/invalid'))).bodyString).toEqual('Internal error');
|
|
335
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/nonClass'))).json).toEqual(['auth', 'MyAuth']);
|
|
318
336
|
});
|
|
319
|
-
globals_1.test('router body', async () => {
|
|
337
|
+
(0, globals_1.test)('router body class', async () => {
|
|
320
338
|
class Body {
|
|
321
339
|
}
|
|
322
|
-
|
|
323
|
-
type_1.t,
|
|
324
|
-
__metadata("design:type", String)
|
|
325
|
-
], Body.prototype, "username", void 0);
|
|
340
|
+
Body.__type = ['username', '&3!5'];
|
|
326
341
|
class Controller {
|
|
327
342
|
anyReq(body, req) {
|
|
328
343
|
return [body.username, body instanceof Body, req.url];
|
|
329
344
|
}
|
|
330
345
|
}
|
|
346
|
+
Controller.__type = [() => __ΩHttpBody, () => Body, 'body', () => model_1.HttpRequest, 'req', 'anyReq', 'PP7"o!"2#P7$2%"0&5'];
|
|
331
347
|
__decorate([
|
|
332
348
|
decorator_1.http.POST(),
|
|
333
|
-
__param(0, decorator_1.http.body()),
|
|
334
349
|
__metadata("design:type", Function),
|
|
335
|
-
__metadata("design:paramtypes", [
|
|
350
|
+
__metadata("design:paramtypes", [Object, model_1.HttpRequest]),
|
|
336
351
|
__metadata("design:returntype", void 0)
|
|
337
352
|
], Controller.prototype, "anyReq", null);
|
|
338
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
339
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', true, '/']);
|
|
353
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
354
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', true, '/']);
|
|
340
355
|
});
|
|
341
|
-
globals_1.test('router body is safe for simultaneous requests', async () => {
|
|
356
|
+
(0, globals_1.test)('router body is safe for simultaneous requests', async () => {
|
|
342
357
|
class Body {
|
|
343
358
|
}
|
|
344
|
-
|
|
345
|
-
type_1.t,
|
|
346
|
-
__metadata("design:type", String)
|
|
347
|
-
], Body.prototype, "username", void 0);
|
|
359
|
+
Body.__type = ['username', '&3!5'];
|
|
348
360
|
class Controller {
|
|
349
361
|
anyReq(body, req) {
|
|
350
362
|
return [body.username, body instanceof Body, req.url];
|
|
351
363
|
}
|
|
352
364
|
}
|
|
365
|
+
Controller.__type = [() => __ΩHttpBody, () => Body, 'body', () => model_1.HttpRequest, 'req', 'anyReq', 'PP7"o!"2#P7$2%"0&5'];
|
|
353
366
|
__decorate([
|
|
354
367
|
decorator_1.http.POST(),
|
|
355
|
-
__param(0, decorator_1.http.body()),
|
|
356
368
|
__metadata("design:type", Function),
|
|
357
|
-
__metadata("design:paramtypes", [
|
|
369
|
+
__metadata("design:paramtypes", [Object, model_1.HttpRequest]),
|
|
358
370
|
__metadata("design:returntype", void 0)
|
|
359
371
|
], Controller.prototype, "anyReq", null);
|
|
360
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
372
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
361
373
|
const makeReq = () => httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }));
|
|
362
|
-
const results = await Promise.all([...new Array(100)].map(() => makeReq().then(res => res.json)));
|
|
363
|
-
globals_1.expect(results).toEqual(results.map(() => ['Peter', true, '/']));
|
|
374
|
+
const results = await Promise.all([...new Array(100)].map(() => makeReq().then(Object.assign(res => res.json, { __type: ['res', '', 'P"2!"/"'] }))));
|
|
375
|
+
(0, globals_1.expect)(results).toEqual(results.map(() => ['Peter', true, '/']));
|
|
364
376
|
});
|
|
365
|
-
globals_1.test('router body
|
|
366
|
-
|
|
377
|
+
(0, globals_1.test)('router body interface', async () => {
|
|
378
|
+
var __ΩBody = ['username', 'P&4!M'];
|
|
379
|
+
class Controller {
|
|
380
|
+
anyReq(body, req) {
|
|
381
|
+
return [body.username, typeof body.username, req.url];
|
|
382
|
+
}
|
|
367
383
|
}
|
|
384
|
+
Controller.__type = [() => __ΩHttpBody, () => __ΩBody, 'body', () => model_1.HttpRequest, 'req', 'anyReq', 'Pn"o!"2#P7$2%"0&5'];
|
|
368
385
|
__decorate([
|
|
369
|
-
|
|
370
|
-
__metadata("design:type",
|
|
371
|
-
|
|
386
|
+
decorator_1.http.POST(),
|
|
387
|
+
__metadata("design:type", Function),
|
|
388
|
+
__metadata("design:paramtypes", [Object, model_1.HttpRequest]),
|
|
389
|
+
__metadata("design:returntype", void 0)
|
|
390
|
+
], Controller.prototype, "anyReq", null);
|
|
391
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
392
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', 'string', '/']);
|
|
393
|
+
});
|
|
394
|
+
(0, globals_1.test)('router body double', async () => {
|
|
395
|
+
class Body {
|
|
396
|
+
}
|
|
397
|
+
Body.__type = ['username', '&3!5'];
|
|
372
398
|
class Controller {
|
|
373
399
|
anyReq(body, body2, req) {
|
|
374
400
|
return [body2.username, body2 instanceof Body && body instanceof Body, req.url];
|
|
375
401
|
}
|
|
376
402
|
}
|
|
403
|
+
Controller.__type = [() => __ΩHttpBody, () => Body, 'body', () => __ΩHttpBody, () => Body, 'body2', () => model_1.HttpRequest, 'req', 'anyReq', 'PP7"o!"2#P7%o$"2&P7\'2("0)5'];
|
|
377
404
|
__decorate([
|
|
378
405
|
decorator_1.http.POST(),
|
|
379
|
-
__param(0, decorator_1.http.body()),
|
|
380
|
-
__param(1, decorator_1.http.body()),
|
|
381
406
|
__metadata("design:type", Function),
|
|
382
|
-
__metadata("design:paramtypes", [
|
|
407
|
+
__metadata("design:paramtypes", [Object, Object, model_1.HttpRequest]),
|
|
383
408
|
__metadata("design:returntype", void 0)
|
|
384
409
|
], Controller.prototype, "anyReq", null);
|
|
385
410
|
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
386
411
|
if (!httpData)
|
|
387
412
|
throw new Error('httpClass undefined');
|
|
388
413
|
const action = [...httpData.getActions()][0];
|
|
389
|
-
globals_1.expect(action.methodName).toBe('anyReq');
|
|
390
|
-
globals_1.expect(action.httpMethods).toEqual(['POST']);
|
|
391
|
-
|
|
392
|
-
globals_1.expect(
|
|
393
|
-
globals_1.expect(action.parameters['body2']).not.toBeUndefined();
|
|
394
|
-
globals_1.expect(action.parameters['body2'].name).toBe('body2');
|
|
395
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
396
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', true, '/']);
|
|
414
|
+
(0, globals_1.expect)(action.methodName).toBe('anyReq');
|
|
415
|
+
(0, globals_1.expect)(action.httpMethods).toEqual(['POST']);
|
|
416
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
417
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/').json({ username: 'Peter' }))).json).toEqual(['Peter', true, '/']);
|
|
397
418
|
});
|
|
398
|
-
globals_1.test('router groups', async () => {
|
|
419
|
+
(0, globals_1.test)('router groups', async () => {
|
|
399
420
|
{
|
|
400
421
|
class Controller {
|
|
401
422
|
a() {
|
|
@@ -405,6 +426,7 @@ globals_1.test('router groups', async () => {
|
|
|
405
426
|
c() {
|
|
406
427
|
}
|
|
407
428
|
}
|
|
429
|
+
Controller.__type = ['a', 'b', 'c', 'P"0!P"0"P"0#5'];
|
|
408
430
|
__decorate([
|
|
409
431
|
decorator_1.http.GET('a').group('a'),
|
|
410
432
|
__metadata("design:type", Function),
|
|
@@ -426,9 +448,9 @@ globals_1.test('router groups', async () => {
|
|
|
426
448
|
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
427
449
|
if (!httpData)
|
|
428
450
|
throw new Error('httpClass undefined');
|
|
429
|
-
globals_1.expect(httpData.getAction('a').groups).toEqual(['a']);
|
|
430
|
-
globals_1.expect(httpData.getAction('b').groups).toEqual([]);
|
|
431
|
-
globals_1.expect(httpData.getAction('c').groups).toEqual(['c']);
|
|
451
|
+
(0, globals_1.expect)(httpData.getAction('a').groups).toEqual(['a']);
|
|
452
|
+
(0, globals_1.expect)(httpData.getAction('b').groups).toEqual([]);
|
|
453
|
+
(0, globals_1.expect)(httpData.getAction('c').groups).toEqual(['c']);
|
|
432
454
|
}
|
|
433
455
|
{
|
|
434
456
|
let Controller = class Controller {
|
|
@@ -439,6 +461,7 @@ globals_1.test('router groups', async () => {
|
|
|
439
461
|
c() {
|
|
440
462
|
}
|
|
441
463
|
};
|
|
464
|
+
Controller.__type = ['a', 'b', 'c', 'P"0!P"0"P"0#5'];
|
|
442
465
|
__decorate([
|
|
443
466
|
decorator_1.http.GET('a').group('a'),
|
|
444
467
|
__metadata("design:type", Function),
|
|
@@ -463,115 +486,87 @@ globals_1.test('router groups', async () => {
|
|
|
463
486
|
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
464
487
|
if (!httpData)
|
|
465
488
|
throw new Error('httpClass undefined');
|
|
466
|
-
globals_1.expect(httpData.getAction('a').groups).toEqual(['a', 'all']);
|
|
467
|
-
globals_1.expect(httpData.getAction('b').groups).toEqual(['all']);
|
|
468
|
-
globals_1.expect(httpData.getAction('c').groups).toEqual(['c', 'all']);
|
|
489
|
+
(0, globals_1.expect)(httpData.getAction('a').groups).toEqual(['a', 'all']);
|
|
490
|
+
(0, globals_1.expect)(httpData.getAction('b').groups).toEqual(['all']);
|
|
491
|
+
(0, globals_1.expect)(httpData.getAction('c').groups).toEqual(['c', 'all']);
|
|
469
492
|
}
|
|
470
493
|
});
|
|
471
|
-
globals_1.test('router query', async () => {
|
|
494
|
+
(0, globals_1.test)('router query', async () => {
|
|
472
495
|
class Controller {
|
|
473
496
|
anyReq(test) {
|
|
474
497
|
return test;
|
|
475
498
|
}
|
|
476
499
|
}
|
|
500
|
+
Controller.__type = [() => __ΩHttpQuery, 'test', 'anyReq', 'P\'o!"2"8"0#5'];
|
|
477
501
|
__decorate([
|
|
478
502
|
decorator_1.http.GET('my-action'),
|
|
479
|
-
__param(0, decorator_1.http.query().optional),
|
|
480
503
|
__metadata("design:type", Function),
|
|
481
|
-
__metadata("design:paramtypes", [
|
|
504
|
+
__metadata("design:paramtypes", [Object]),
|
|
482
505
|
__metadata("design:returntype", void 0)
|
|
483
506
|
], Controller.prototype, "anyReq", null);
|
|
484
507
|
const httpData = decorator_1.httpClass._fetch(Controller);
|
|
485
508
|
if (!httpData)
|
|
486
509
|
throw new Error('httpClass undefined');
|
|
487
510
|
const action = [...httpData.getActions()][0];
|
|
488
|
-
globals_1.expect(action.methodName).toBe('anyReq');
|
|
489
|
-
globals_1.expect(action.httpMethods).toEqual(['GET']);
|
|
490
|
-
|
|
491
|
-
globals_1.expect(
|
|
492
|
-
globals_1.expect(
|
|
493
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
494
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/my-action?test=123'))).json).toEqual(123);
|
|
495
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/my-action'))).bodyString).toEqual('');
|
|
511
|
+
(0, globals_1.expect)(action.methodName).toBe('anyReq');
|
|
512
|
+
(0, globals_1.expect)(action.httpMethods).toEqual(['GET']);
|
|
513
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
514
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action?test=123'))).json).toEqual(123);
|
|
515
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action'))).bodyString).toEqual('');
|
|
496
516
|
});
|
|
497
|
-
globals_1.test('router query all', async () => {
|
|
517
|
+
(0, globals_1.test)('router query all', async () => {
|
|
498
518
|
class AnyReqQuery {
|
|
499
519
|
}
|
|
500
|
-
|
|
501
|
-
type_1.t.optional,
|
|
502
|
-
__metadata("design:type", String)
|
|
503
|
-
], AnyReqQuery.prototype, "test", void 0);
|
|
504
|
-
__decorate([
|
|
505
|
-
type_1.t.optional,
|
|
506
|
-
__metadata("design:type", String)
|
|
507
|
-
], AnyReqQuery.prototype, "filter", void 0);
|
|
508
|
-
__decorate([
|
|
509
|
-
type_1.t.optional,
|
|
510
|
-
__metadata("design:type", Number)
|
|
511
|
-
], AnyReqQuery.prototype, "page", void 0);
|
|
520
|
+
AnyReqQuery.__type = ['test', 'filter', 'page', '&3!8&3"8\'3#85'];
|
|
512
521
|
class Controller {
|
|
513
522
|
anyReq(anyReqQuery) {
|
|
514
523
|
return anyReqQuery;
|
|
515
524
|
}
|
|
516
525
|
}
|
|
526
|
+
Controller.__type = [() => __ΩHttpQueries, () => AnyReqQuery, 'anyReqQuery', 'anyReq', 'PP7"o!"2#"0$5'];
|
|
517
527
|
__decorate([
|
|
518
528
|
decorator_1.http.GET('my-action'),
|
|
519
|
-
__param(0, decorator_1.http.queries()),
|
|
520
529
|
__metadata("design:type", Function),
|
|
521
|
-
__metadata("design:paramtypes", [
|
|
530
|
+
__metadata("design:paramtypes", [Object]),
|
|
522
531
|
__metadata("design:returntype", void 0)
|
|
523
532
|
], Controller.prototype, "anyReq", null);
|
|
524
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
525
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/my-action?test=123'))).json).toEqual({ test: '123' });
|
|
526
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/my-action'))).json).toEqual({});
|
|
527
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/my-action?filter=page&page=5'))).json).toEqual({ filter: 'page', page: 5 });
|
|
533
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
534
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action?test=123'))).json).toEqual({ test: '123' });
|
|
535
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action'))).json).toEqual({});
|
|
536
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/my-action?filter=page&page=5'))).json).toEqual({ filter: 'page', page: 5 });
|
|
528
537
|
});
|
|
529
|
-
globals_1.test('serializer options', async () => {
|
|
538
|
+
(0, globals_1.test)('serializer options', async () => {
|
|
530
539
|
class User {
|
|
531
540
|
}
|
|
532
|
-
|
|
533
|
-
type_1.t,
|
|
534
|
-
__metadata("design:type", String)
|
|
535
|
-
], User.prototype, "username", void 0);
|
|
536
|
-
__decorate([
|
|
537
|
-
type_1.t.group('sensitive'),
|
|
538
|
-
__metadata("design:type", String)
|
|
539
|
-
], User.prototype, "password", void 0);
|
|
541
|
+
User.__type = ['username', () => __ΩGroup, "sensitive", 'password', '&3!P&.#o""K3$5'];
|
|
540
542
|
class Controller {
|
|
541
543
|
anyReq() {
|
|
542
544
|
return { username: 'Peter', password: 'secret' };
|
|
543
545
|
}
|
|
544
546
|
}
|
|
547
|
+
Controller.__type = [() => User, 'anyReq', 'PP7!0"5'];
|
|
545
548
|
__decorate([
|
|
546
549
|
decorator_1.http.GET().serialization({ groupsExclude: ['sensitive'] }),
|
|
547
|
-
type_1.t.type(User),
|
|
548
550
|
__metadata("design:type", Function),
|
|
549
551
|
__metadata("design:paramtypes", []),
|
|
550
|
-
__metadata("design:returntype",
|
|
552
|
+
__metadata("design:returntype", User)
|
|
551
553
|
], Controller.prototype, "anyReq", null);
|
|
552
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
553
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/'))).json).toEqual({ username: 'Peter' });
|
|
554
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
555
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/'))).json).toEqual({ username: 'Peter' });
|
|
554
556
|
});
|
|
555
|
-
globals_1.test('hook after serializer', async () => {
|
|
557
|
+
(0, globals_1.test)('hook after serializer', async () => {
|
|
556
558
|
class User {
|
|
557
559
|
}
|
|
558
|
-
|
|
559
|
-
type_1.t,
|
|
560
|
-
__metadata("design:type", String)
|
|
561
|
-
], User.prototype, "username", void 0);
|
|
562
|
-
__decorate([
|
|
563
|
-
type_1.t.group('sensitive'),
|
|
564
|
-
__metadata("design:type", String)
|
|
565
|
-
], User.prototype, "password", void 0);
|
|
560
|
+
User.__type = ['username', () => __ΩGroup, "sensitive", 'password', '&3!P&.#o""K3$5'];
|
|
566
561
|
class Controller {
|
|
567
562
|
async anyReq() {
|
|
568
|
-
await core_1.sleep(0.1);
|
|
563
|
+
await (0, core_1.sleep)(0.1);
|
|
569
564
|
return { username: 'Peter', password: 'secret' };
|
|
570
565
|
}
|
|
571
566
|
}
|
|
567
|
+
Controller.__type = [() => User, 'anyReq', 'PP7!`0"5'];
|
|
572
568
|
__decorate([
|
|
573
569
|
decorator_1.http.GET().serialization({ groupsExclude: ['sensitive'] }),
|
|
574
|
-
type_1.t.type(User),
|
|
575
570
|
__metadata("design:type", Function),
|
|
576
571
|
__metadata("design:paramtypes", []),
|
|
577
572
|
__metadata("design:returntype", Promise)
|
|
@@ -581,37 +576,40 @@ globals_1.test('hook after serializer', async () => {
|
|
|
581
576
|
event.result = { processingTime: event.controllerActionTime, data: event.result };
|
|
582
577
|
}
|
|
583
578
|
}
|
|
579
|
+
Listener.__type = [() => http_1.httpWorkflow.onResponse.event, 'event', 'onResponse', 'Pi!2""0#5'];
|
|
584
580
|
__decorate([
|
|
585
581
|
event_1.eventDispatcher.listen(http_1.httpWorkflow.onResponse),
|
|
586
582
|
__metadata("design:type", Function),
|
|
587
583
|
__metadata("design:paramtypes", [Object]),
|
|
588
584
|
__metadata("design:returntype", void 0)
|
|
589
585
|
], Listener.prototype, "onResponse", null);
|
|
590
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [], [Listener]);
|
|
586
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [], [Listener]);
|
|
591
587
|
const result = (await httpKernel.request(model_1.HttpRequest.GET('/'))).json;
|
|
592
|
-
globals_1.expect(result.data).toEqual({ username: 'Peter' });
|
|
593
|
-
globals_1.expect(result.processingTime).toBeGreaterThanOrEqual(99);
|
|
588
|
+
(0, globals_1.expect)(result.data).toEqual({ username: 'Peter' });
|
|
589
|
+
(0, globals_1.expect)(result.processingTime).toBeGreaterThanOrEqual(99);
|
|
594
590
|
});
|
|
595
|
-
globals_1.test('invalid route definition', async () => {
|
|
591
|
+
(0, globals_1.test)('invalid route definition', async () => {
|
|
596
592
|
class Controller {
|
|
597
593
|
doIt(user) {
|
|
598
594
|
}
|
|
599
595
|
}
|
|
596
|
+
Controller.__type = ['user', 'doIt', 'P"2!"0"5'];
|
|
600
597
|
__decorate([
|
|
601
598
|
decorator_1.http.GET(),
|
|
602
599
|
__metadata("design:type", Function),
|
|
603
600
|
__metadata("design:paramtypes", [Object]),
|
|
604
601
|
__metadata("design:returntype", void 0)
|
|
605
602
|
], Controller.prototype, "doIt", null);
|
|
606
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
607
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/'))).bodyString).toEqual('
|
|
603
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
604
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/'))).bodyString).toEqual('Internal error');
|
|
608
605
|
});
|
|
609
|
-
globals_1.test('inject request storage ClassType', async () => {
|
|
606
|
+
(0, globals_1.test)('inject request storage ClassType', async () => {
|
|
610
607
|
class User {
|
|
611
608
|
constructor(username) {
|
|
612
609
|
this.username = username;
|
|
613
610
|
}
|
|
614
611
|
}
|
|
612
|
+
User.__type = ['username', 'constructor', 'P&2!:"0"5'];
|
|
615
613
|
class Controller {
|
|
616
614
|
doIt(user) {
|
|
617
615
|
return { isUser: user instanceof User, username: user.username };
|
|
@@ -620,6 +618,7 @@ globals_1.test('inject request storage ClassType', async () => {
|
|
|
620
618
|
return { isUser: user instanceof User };
|
|
621
619
|
}
|
|
622
620
|
}
|
|
621
|
+
Controller.__type = [() => User, 'user', 'doIt', () => User, 'doItOptional', 'PP7!2""0#PP7$2"8"0%5'];
|
|
623
622
|
__decorate([
|
|
624
623
|
decorator_1.http.GET(),
|
|
625
624
|
__metadata("design:type", Function),
|
|
@@ -628,7 +627,6 @@ globals_1.test('inject request storage ClassType', async () => {
|
|
|
628
627
|
], Controller.prototype, "doIt", null);
|
|
629
628
|
__decorate([
|
|
630
629
|
decorator_1.http.GET('optional'),
|
|
631
|
-
__param(0, injector_1.inject().optional),
|
|
632
630
|
__metadata("design:type", Function),
|
|
633
631
|
__metadata("design:paramtypes", [User]),
|
|
634
632
|
__metadata("design:returntype", void 0)
|
|
@@ -640,64 +638,26 @@ globals_1.test('inject request storage ClassType', async () => {
|
|
|
640
638
|
}
|
|
641
639
|
}
|
|
642
640
|
}
|
|
641
|
+
Listener.__type = [() => http_1.httpWorkflow.onAuth.event, 'event', 'onAuth', 'Pi!2""0#5'];
|
|
643
642
|
__decorate([
|
|
644
643
|
event_1.eventDispatcher.listen(http_1.httpWorkflow.onAuth),
|
|
645
644
|
__metadata("design:type", Function),
|
|
646
645
|
__metadata("design:paramtypes", [Object]),
|
|
647
646
|
__metadata("design:returntype", void 0)
|
|
648
647
|
], Listener.prototype, "onAuth", null);
|
|
649
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [
|
|
648
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [
|
|
650
649
|
{
|
|
651
|
-
provide: User, scope: 'http',
|
|
650
|
+
provide: User, scope: 'http',
|
|
651
|
+
useFactory: Object.assign(function useFactory(request) {
|
|
652
652
|
return request.store.user;
|
|
653
|
-
}
|
|
653
|
+
}, { __type: [() => model_1.HttpRequest, 'request', 'useFactory', 'PP7!2""/#'] })
|
|
654
654
|
}
|
|
655
655
|
], [Listener]);
|
|
656
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/').headers({ authorization: 'yes' }))).json).toEqual({ isUser: true, username: 'bar' });
|
|
657
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/').headers({ authorization: 'no' }))).bodyString).toEqual('Internal error');
|
|
658
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/optional').headers({ authorization: 'no' }))).json).toEqual({ isUser: false });
|
|
659
|
-
});
|
|
660
|
-
globals_1.test('inject request storage @inject', async () => {
|
|
661
|
-
class User {
|
|
662
|
-
constructor(username) {
|
|
663
|
-
this.username = username;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
class Controller {
|
|
667
|
-
doIt(user) {
|
|
668
|
-
return { isUser: user instanceof User, username: user.username };
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
__decorate([
|
|
672
|
-
decorator_1.http.GET(),
|
|
673
|
-
__param(0, injector_1.inject('user')),
|
|
674
|
-
__metadata("design:type", Function),
|
|
675
|
-
__metadata("design:paramtypes", [Object]),
|
|
676
|
-
__metadata("design:returntype", void 0)
|
|
677
|
-
], Controller.prototype, "doIt", null);
|
|
678
|
-
class Listener {
|
|
679
|
-
onAuth(event) {
|
|
680
|
-
event.request.store.user = new User('bar');
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
__decorate([
|
|
684
|
-
event_1.eventDispatcher.listen(http_1.httpWorkflow.onAuth),
|
|
685
|
-
__metadata("design:type", Function),
|
|
686
|
-
__metadata("design:paramtypes", [Object]),
|
|
687
|
-
__metadata("design:returntype", void 0)
|
|
688
|
-
], Listener.prototype, "onAuth", null);
|
|
689
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [
|
|
690
|
-
{
|
|
691
|
-
provide: 'user', scope: 'http', deps: [model_1.HttpRequest], useFactory(request) {
|
|
692
|
-
return request.store.user;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
], [Listener]);
|
|
696
|
-
const result = (await httpKernel.request(model_1.HttpRequest.GET('/'))).json;
|
|
697
|
-
globals_1.expect(result.isUser).toBe(true);
|
|
698
|
-
globals_1.expect(result.username).toBe('bar');
|
|
656
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/').headers({ authorization: 'yes' }))).json).toEqual({ isUser: true, username: 'bar' });
|
|
657
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/').headers({ authorization: 'no' }))).bodyString).toEqual('Internal error');
|
|
658
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/optional').headers({ authorization: 'no' }))).json).toEqual({ isUser: false });
|
|
699
659
|
});
|
|
700
|
-
globals_1.test('custom request handling', async () => {
|
|
660
|
+
(0, globals_1.test)('custom request handling', async () => {
|
|
701
661
|
class Listener {
|
|
702
662
|
onRouteNotFound(event) {
|
|
703
663
|
//CORS requirement for example
|
|
@@ -705,25 +665,27 @@ globals_1.test('custom request handling', async () => {
|
|
|
705
665
|
event.send(new http_1.JSONResponse(true, 200));
|
|
706
666
|
}
|
|
707
667
|
}
|
|
668
|
+
Listener.__type = [() => http_1.httpWorkflow.onRouteNotFound.event, 'event', 'onRouteNotFound', 'Pi!2""0#5'];
|
|
708
669
|
__decorate([
|
|
709
670
|
event_1.eventDispatcher.listen(http_1.httpWorkflow.onRouteNotFound),
|
|
710
671
|
__metadata("design:type", Function),
|
|
711
672
|
__metadata("design:paramtypes", [Object]),
|
|
712
673
|
__metadata("design:returntype", void 0)
|
|
713
674
|
], Listener.prototype, "onRouteNotFound", null);
|
|
714
|
-
const httpKernel = utils_1.createHttpKernel([], [], [Listener]);
|
|
715
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.OPTIONS('/'))).json).toBe(true);
|
|
675
|
+
const httpKernel = (0, utils_1.createHttpKernel)([], [], [Listener]);
|
|
676
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.OPTIONS('/'))).json).toBe(true);
|
|
716
677
|
});
|
|
717
|
-
globals_1.test('race condition', async () => {
|
|
678
|
+
(0, globals_1.test)('race condition', async () => {
|
|
718
679
|
let call = 0;
|
|
719
680
|
class Listener {
|
|
720
681
|
async onRouteNotFound(event) {
|
|
721
682
|
if (call === 0) {
|
|
722
|
-
await core_1.sleep(0.1);
|
|
683
|
+
await (0, core_1.sleep)(0.1);
|
|
723
684
|
}
|
|
724
685
|
call++;
|
|
725
686
|
}
|
|
726
687
|
}
|
|
688
|
+
Listener.__type = [() => http_1.httpWorkflow.onRouteNotFound.event, 'event', 'onRouteNotFound', 'Pi!2""0#5'];
|
|
727
689
|
__decorate([
|
|
728
690
|
event_1.eventDispatcher.listen(http_1.httpWorkflow.onAuth),
|
|
729
691
|
__metadata("design:type", Function),
|
|
@@ -738,6 +700,7 @@ globals_1.test('race condition', async () => {
|
|
|
738
700
|
return param2;
|
|
739
701
|
}
|
|
740
702
|
}
|
|
703
|
+
Controller.__type = ['param1', 'one', 'param2', 'second', 'P&2!"0"P&2#"0$5'];
|
|
741
704
|
__decorate([
|
|
742
705
|
decorator_1.http.GET('/one/:param1'),
|
|
743
706
|
__metadata("design:type", Function),
|
|
@@ -750,33 +713,34 @@ globals_1.test('race condition', async () => {
|
|
|
750
713
|
__metadata("design:paramtypes", [String]),
|
|
751
714
|
__metadata("design:returntype", void 0)
|
|
752
715
|
], Controller.prototype, "second", null);
|
|
753
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [], [Listener]);
|
|
716
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [], [Listener]);
|
|
754
717
|
const [a, b] = await Promise.all([
|
|
755
718
|
httpKernel.request(model_1.HttpRequest.GET('/one/a')),
|
|
756
719
|
httpKernel.request(model_1.HttpRequest.GET('/second/b')),
|
|
757
720
|
]);
|
|
758
|
-
globals_1.expect(a.json).toBe('a');
|
|
759
|
-
globals_1.expect(b.json).toBe('b');
|
|
721
|
+
(0, globals_1.expect)(a.json).toBe('a');
|
|
722
|
+
(0, globals_1.expect)(b.json).toBe('b');
|
|
760
723
|
});
|
|
761
|
-
globals_1.test('multiple methods', async () => {
|
|
724
|
+
(0, globals_1.test)('multiple methods', async () => {
|
|
762
725
|
class Controller {
|
|
763
726
|
one() {
|
|
764
727
|
return true;
|
|
765
728
|
}
|
|
766
729
|
}
|
|
730
|
+
Controller.__type = ['one', 'P"0!5'];
|
|
767
731
|
__decorate([
|
|
768
732
|
decorator_1.http.GET('/one').POST(),
|
|
769
733
|
__metadata("design:type", Function),
|
|
770
734
|
__metadata("design:paramtypes", []),
|
|
771
735
|
__metadata("design:returntype", void 0)
|
|
772
736
|
], Controller.prototype, "one", null);
|
|
773
|
-
const httpKernel = utils_1.createHttpKernel([Controller], [], []);
|
|
774
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/one'))).json).toBe(true);
|
|
775
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.POST('/one'))).json).toBe(true);
|
|
776
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.PATCH('/one'))).bodyString).toBe('Not found');
|
|
777
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.PUT('/one'))).bodyString).toBe('Not found');
|
|
737
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller], [], []);
|
|
738
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/one'))).json).toBe(true);
|
|
739
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/one'))).json).toBe(true);
|
|
740
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.PATCH('/one'))).bodyString).toBe('Not found');
|
|
741
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.PUT('/one'))).bodyString).toBe('Not found');
|
|
778
742
|
});
|
|
779
|
-
globals_1.test('promise serializer', async () => {
|
|
743
|
+
(0, globals_1.test)('promise serializer', async () => {
|
|
780
744
|
class Controller {
|
|
781
745
|
async anyReq1() {
|
|
782
746
|
return 'test';
|
|
@@ -785,6 +749,7 @@ globals_1.test('promise serializer', async () => {
|
|
|
785
749
|
return 1;
|
|
786
750
|
}
|
|
787
751
|
}
|
|
752
|
+
Controller.__type = ['anyReq1', 'anyReq2', 'P"0!P&`0"5'];
|
|
788
753
|
__decorate([
|
|
789
754
|
decorator_1.http.GET('1'),
|
|
790
755
|
__metadata("design:type", Function),
|
|
@@ -793,55 +758,53 @@ globals_1.test('promise serializer', async () => {
|
|
|
793
758
|
], Controller.prototype, "anyReq1", null);
|
|
794
759
|
__decorate([
|
|
795
760
|
decorator_1.http.GET('2'),
|
|
796
|
-
type_1.t.string,
|
|
797
761
|
__metadata("design:type", Function),
|
|
798
762
|
__metadata("design:paramtypes", []),
|
|
799
763
|
__metadata("design:returntype", Promise)
|
|
800
764
|
], Controller.prototype, "anyReq2", null);
|
|
801
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
802
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/1'))).json).toBe('test');
|
|
803
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/2'))).json).toBe('1');
|
|
765
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
766
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/1'))).json).toBe('test');
|
|
767
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/2'))).json).toBe('1');
|
|
804
768
|
});
|
|
805
|
-
globals_1.test('unions', async () => {
|
|
769
|
+
(0, globals_1.test)('unions', async () => {
|
|
806
770
|
class Controller {
|
|
807
771
|
list(page) {
|
|
808
772
|
return page;
|
|
809
773
|
}
|
|
810
774
|
}
|
|
775
|
+
Controller.__type = [() => __ΩHttpQuery, 'page', 'list', 'PP\')Jo!"2""0#5'];
|
|
811
776
|
__decorate([
|
|
812
777
|
decorator_1.http.GET('/list'),
|
|
813
|
-
__param(0, decorator_1.http.query()),
|
|
814
|
-
__param(0, type_1.t.union(type_1.t.number, type_1.t.boolean)),
|
|
815
778
|
__metadata("design:type", Function),
|
|
816
779
|
__metadata("design:paramtypes", [Object]),
|
|
817
780
|
__metadata("design:returntype", void 0)
|
|
818
781
|
], Controller.prototype, "list", null);
|
|
819
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
820
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/list?page=
|
|
821
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/list?page=
|
|
822
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/list?page=
|
|
782
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
783
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=0'))).json).toEqual(0);
|
|
784
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=1'))).json).toEqual(1);
|
|
785
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=2222'))).json).toEqual(2222);
|
|
786
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=false'))).json).toEqual(false);
|
|
787
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=true'))).json).toEqual(true);
|
|
788
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/list?page=asdasdc'))).json).toMatchObject({
|
|
789
|
+
'errors': [
|
|
790
|
+
{
|
|
791
|
+
'code': 'type',
|
|
792
|
+
'message': 'No value given',
|
|
793
|
+
'path': 'page'
|
|
794
|
+
}
|
|
795
|
+
],
|
|
796
|
+
});
|
|
823
797
|
});
|
|
824
|
-
globals_1.test('router dotToUrlPath', () => {
|
|
825
|
-
globals_1.expect(router_1.dotToUrlPath('peter')).toBe('peter');
|
|
826
|
-
globals_1.expect(router_1.dotToUrlPath('foo.bar')).toBe('foo[bar]');
|
|
827
|
-
globals_1.expect(router_1.dotToUrlPath('foo.bar.deep')).toBe('foo[bar][deep]');
|
|
828
|
-
globals_1.expect(router_1.dotToUrlPath('foo.bar.deep.very')).toBe('foo[bar][deep][very]');
|
|
798
|
+
(0, globals_1.test)('router dotToUrlPath', () => {
|
|
799
|
+
(0, globals_1.expect)((0, router_1.dotToUrlPath)('peter')).toBe('peter');
|
|
800
|
+
(0, globals_1.expect)((0, router_1.dotToUrlPath)('foo.bar')).toBe('foo[bar]');
|
|
801
|
+
(0, globals_1.expect)((0, router_1.dotToUrlPath)('foo.bar.deep')).toBe('foo[bar][deep]');
|
|
802
|
+
(0, globals_1.expect)((0, router_1.dotToUrlPath)('foo.bar.deep.very')).toBe('foo[bar][deep][very]');
|
|
829
803
|
});
|
|
830
|
-
globals_1.test('router url resolve', async () => {
|
|
804
|
+
(0, globals_1.test)('router url resolve', async () => {
|
|
831
805
|
class AnyReqQuery {
|
|
832
806
|
}
|
|
833
|
-
|
|
834
|
-
type_1.t.optional,
|
|
835
|
-
__metadata("design:type", String)
|
|
836
|
-
], AnyReqQuery.prototype, "test", void 0);
|
|
837
|
-
__decorate([
|
|
838
|
-
type_1.t.optional,
|
|
839
|
-
__metadata("design:type", String)
|
|
840
|
-
], AnyReqQuery.prototype, "filter", void 0);
|
|
841
|
-
__decorate([
|
|
842
|
-
type_1.t.optional,
|
|
843
|
-
__metadata("design:type", Number)
|
|
844
|
-
], AnyReqQuery.prototype, "page", void 0);
|
|
807
|
+
AnyReqQuery.__type = ['test', 'filter', 'page', '&3!8&3"8\'3#85'];
|
|
845
808
|
class Controller {
|
|
846
809
|
first() {
|
|
847
810
|
return '';
|
|
@@ -862,6 +825,7 @@ globals_1.test('router url resolve', async () => {
|
|
|
862
825
|
return params;
|
|
863
826
|
}
|
|
864
827
|
}
|
|
828
|
+
Controller.__type = ['first', 'peter', 'second', () => __ΩHttpQuery, 'secondQuery', () => __ΩHttpQuery, "changed", 'name', 'secondQuery2', () => __ΩHttpQueries, () => AnyReqQuery, 'params', 'third', () => __ΩHttpQueries, () => AnyReqQuery, "deep", 'third2', 'P"0!P&2""0#P&o$"2""0%P&P.\'4(Mo""0)PP7+o*"2,"0-PP7/P.04(Mo.#2,"015'];
|
|
865
829
|
__decorate([
|
|
866
830
|
decorator_1.http.GET('').name('first'),
|
|
867
831
|
__metadata("design:type", Function),
|
|
@@ -876,115 +840,63 @@ globals_1.test('router url resolve', async () => {
|
|
|
876
840
|
], Controller.prototype, "second", null);
|
|
877
841
|
__decorate([
|
|
878
842
|
decorator_1.http.GET('').name('secondQuery'),
|
|
879
|
-
__param(0, decorator_1.http.query()),
|
|
880
843
|
__metadata("design:type", Function),
|
|
881
|
-
__metadata("design:paramtypes", [
|
|
844
|
+
__metadata("design:paramtypes", [Object]),
|
|
882
845
|
__metadata("design:returntype", void 0)
|
|
883
846
|
], Controller.prototype, "secondQuery", null);
|
|
884
847
|
__decorate([
|
|
885
848
|
decorator_1.http.GET('').name('secondQuery2'),
|
|
886
|
-
__param(0, decorator_1.http.query('changed')),
|
|
887
849
|
__metadata("design:type", Function),
|
|
888
|
-
__metadata("design:paramtypes", [
|
|
850
|
+
__metadata("design:paramtypes", [Object]),
|
|
889
851
|
__metadata("design:returntype", void 0)
|
|
890
852
|
], Controller.prototype, "secondQuery2", null);
|
|
891
853
|
__decorate([
|
|
892
854
|
decorator_1.http.GET('third').name('third'),
|
|
893
|
-
__param(0, decorator_1.http.queries()),
|
|
894
855
|
__metadata("design:type", Function),
|
|
895
|
-
__metadata("design:paramtypes", [
|
|
856
|
+
__metadata("design:paramtypes", [Object]),
|
|
896
857
|
__metadata("design:returntype", void 0)
|
|
897
858
|
], Controller.prototype, "third", null);
|
|
898
859
|
__decorate([
|
|
899
860
|
decorator_1.http.GET('third2').name('third2'),
|
|
900
|
-
__param(0, decorator_1.http.queries('deep')),
|
|
901
861
|
__metadata("design:type", Function),
|
|
902
|
-
__metadata("design:paramtypes", [
|
|
862
|
+
__metadata("design:paramtypes", [Object]),
|
|
903
863
|
__metadata("design:returntype", void 0)
|
|
904
864
|
], Controller.prototype, "third2", null);
|
|
905
865
|
const router = router_1.Router.forControllers([Controller]);
|
|
906
|
-
globals_1.expect(router.resolveUrl('first')).toBe('/');
|
|
907
|
-
globals_1.expect(router.resolveUrl('second', { peter: 'foo' })).toBe('/foo');
|
|
908
|
-
globals_1.expect(router.resolveUrl('secondQuery', { peter: 'foo' })).toBe('/?peter=foo');
|
|
909
|
-
globals_1.expect(router.resolveUrl('secondQuery2', { peter: 'foo' })).toBe('/?changed=foo');
|
|
910
|
-
globals_1.expect(router.resolveUrl('third', {})).toBe('/third');
|
|
911
|
-
globals_1.expect(router.resolveUrl('third', { params: { test: 123 } })).toBe('/third?test=123');
|
|
912
|
-
globals_1.expect(router.resolveUrl('third', { params: { test: 123, filter: 'peter' } })).toBe('/third?test=123&filter=peter');
|
|
913
|
-
globals_1.expect(router.resolveUrl('third2', {})).toBe('/third2');
|
|
914
|
-
globals_1.expect(router.resolveUrl('third2', { params: { test: 123 } })).toBe('/third2?deep[test]=123');
|
|
915
|
-
globals_1.expect(router.resolveUrl('third2', { params: { test: 123, filter: 'peter' } })).toBe('/third2?deep[test]=123&deep[filter]=peter');
|
|
866
|
+
(0, globals_1.expect)(router.resolveUrl('first')).toBe('/');
|
|
867
|
+
(0, globals_1.expect)(router.resolveUrl('second', { peter: 'foo' })).toBe('/foo');
|
|
868
|
+
(0, globals_1.expect)(router.resolveUrl('secondQuery', { peter: 'foo' })).toBe('/?peter=foo');
|
|
869
|
+
(0, globals_1.expect)(router.resolveUrl('secondQuery2', { peter: 'foo' })).toBe('/?changed=foo');
|
|
870
|
+
(0, globals_1.expect)(router.resolveUrl('third', {})).toBe('/third');
|
|
871
|
+
(0, globals_1.expect)(router.resolveUrl('third', { params: { test: 123 } })).toBe('/third?test=123');
|
|
872
|
+
(0, globals_1.expect)(router.resolveUrl('third', { params: { test: 123, filter: 'peter' } })).toBe('/third?test=123&filter=peter');
|
|
873
|
+
(0, globals_1.expect)(router.resolveUrl('third2', {})).toBe('/third2');
|
|
874
|
+
(0, globals_1.expect)(router.resolveUrl('third2', { params: { test: 123 } })).toBe('/third2?deep[test]=123');
|
|
875
|
+
(0, globals_1.expect)(router.resolveUrl('third2', { params: { test: 123, filter: 'peter' } })).toBe('/third2?deep[test]=123&deep[filter]=peter');
|
|
916
876
|
});
|
|
917
|
-
globals_1.test('destructing params', async () => {
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
__decorate([
|
|
921
|
-
type_1.t.required,
|
|
922
|
-
__metadata("design:type", String)
|
|
923
|
-
], DTO.prototype, "name", void 0);
|
|
924
|
-
__decorate([
|
|
925
|
-
type_1.t.required,
|
|
926
|
-
__metadata("design:type", String)
|
|
927
|
-
], DTO.prototype, "title", void 0);
|
|
877
|
+
(0, globals_1.test)('destructing params', async () => {
|
|
878
|
+
var __ΩDTO = ['name', 'title', 'P&4!&4"M'];
|
|
928
879
|
class Controller {
|
|
929
880
|
first({ name, title }) {
|
|
930
881
|
return [name, title];
|
|
931
882
|
}
|
|
932
883
|
}
|
|
884
|
+
Controller.__type = [() => __ΩHttpBody, () => __ΩDTO, 'param0', 'first', 'Pn"o!"2#"0$5'];
|
|
933
885
|
__decorate([
|
|
934
886
|
decorator_1.http.GET(''),
|
|
935
|
-
__param(0, decorator_1.http.body()),
|
|
936
|
-
__metadata("design:type", Function),
|
|
937
|
-
__metadata("design:paramtypes", [DTO]),
|
|
938
|
-
__metadata("design:returntype", void 0)
|
|
939
|
-
], Controller.prototype, "first", null);
|
|
940
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
941
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/').json({ name: 'Peter', title: 'CTO' }))).json).toEqual(['Peter', 'CTO']);
|
|
942
|
-
});
|
|
943
|
-
globals_1.test('dynamic parameter name', async () => {
|
|
944
|
-
let Controller = class Controller {
|
|
945
|
-
first(id) {
|
|
946
|
-
return [id];
|
|
947
|
-
}
|
|
948
|
-
second(id, second) {
|
|
949
|
-
return [id, second];
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
__decorate([
|
|
953
|
-
decorator_1.http.GET('first/:another'),
|
|
954
|
-
__param(0, type_1.t.description('The identifier').name('another')),
|
|
955
887
|
__metadata("design:type", Function),
|
|
956
|
-
__metadata("design:paramtypes", [
|
|
888
|
+
__metadata("design:paramtypes", [Object]),
|
|
957
889
|
__metadata("design:returntype", void 0)
|
|
958
890
|
], Controller.prototype, "first", null);
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
__param(0, type_1.t.description('The identifier').name('another2')),
|
|
962
|
-
__param(1, decorator_1.http.query()),
|
|
963
|
-
__metadata("design:type", Function),
|
|
964
|
-
__metadata("design:paramtypes", [String, String]),
|
|
965
|
-
__metadata("design:returntype", void 0)
|
|
966
|
-
], Controller.prototype, "second", null);
|
|
967
|
-
Controller = __decorate([
|
|
968
|
-
decorator_1.http.controller()
|
|
969
|
-
], Controller);
|
|
970
|
-
const schema = type_1.getClassSchema(Controller);
|
|
971
|
-
globals_1.expect(schema.getMethodProperties('first')[0].name).toBe('another');
|
|
972
|
-
globals_1.expect(schema.getMethodProperties('second')[0].name).toBe('another2');
|
|
973
|
-
globals_1.expect(schema.getMethodProperties('second')[1].name).toBe('second');
|
|
974
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
975
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/first/peter'))).json).toEqual(['peter']);
|
|
976
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/second/peter?second=true'))).json).toEqual(['peter', 'true']);
|
|
891
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
892
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/').json({ name: 'Peter', title: 'CTO' }))).json).toEqual(['Peter', 'CTO']);
|
|
977
893
|
});
|
|
978
|
-
globals_1.test('use http.response for serialization', async () => {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
982
|
-
const errorSchema = type_1.t.schema({
|
|
983
|
-
message: type_1.t.string
|
|
984
|
-
});
|
|
894
|
+
(0, globals_1.test)('use http.response for serialization', async () => {
|
|
895
|
+
var __ΩDefaultResponse = ['title', 'P&4!M'];
|
|
896
|
+
var __ΩErrorResponse = ['message', 'P&4!M'];
|
|
985
897
|
class Controller {
|
|
986
898
|
action1() {
|
|
987
|
-
return [{ title: 'a' }, { title: 1 }];
|
|
899
|
+
return [{ title: 'a' }, { title: '1' }];
|
|
988
900
|
}
|
|
989
901
|
action2() {
|
|
990
902
|
return [{ title: 'a' }, { title: 1 }];
|
|
@@ -993,30 +905,83 @@ globals_1.test('use http.response for serialization', async () => {
|
|
|
993
905
|
return new http_1.JSONResponse([{ message: 'error' }, { message: 1 }]).status(400);
|
|
994
906
|
}
|
|
995
907
|
}
|
|
908
|
+
Controller.__type = [() => __ΩDefaultResponse, 'action1', 'action2', 'action3', 'Pn!F0"P"0#P"0$5'];
|
|
996
909
|
__decorate([
|
|
997
910
|
decorator_1.http.GET('/action1'),
|
|
998
|
-
type_1.t.array(schemaString),
|
|
999
911
|
__metadata("design:type", Function),
|
|
1000
912
|
__metadata("design:paramtypes", []),
|
|
1001
|
-
__metadata("design:returntype",
|
|
913
|
+
__metadata("design:returntype", Array)
|
|
1002
914
|
], Controller.prototype, "action1", null);
|
|
1003
915
|
__decorate([
|
|
1004
|
-
decorator_1.http.GET('/action2').response(200, `List`,
|
|
916
|
+
decorator_1.http.GET('/action2').response(200, `List`, [() => __ΩDefaultResponse, 'n!F']),
|
|
1005
917
|
__metadata("design:type", Function),
|
|
1006
918
|
__metadata("design:paramtypes", []),
|
|
1007
919
|
__metadata("design:returntype", void 0)
|
|
1008
920
|
], Controller.prototype, "action2", null);
|
|
1009
921
|
__decorate([
|
|
1010
922
|
decorator_1.http.GET('/action3')
|
|
1011
|
-
.response(200, `List`,
|
|
1012
|
-
.response(400, `Error`,
|
|
923
|
+
.response(200, `List`, [() => __ΩDefaultResponse, 'n!F'])
|
|
924
|
+
.response(400, `Error`, [() => __ΩErrorResponse, 'n!F']),
|
|
1013
925
|
__metadata("design:type", Function),
|
|
1014
926
|
__metadata("design:paramtypes", []),
|
|
1015
927
|
__metadata("design:returntype", void 0)
|
|
1016
928
|
], Controller.prototype, "action3", null);
|
|
1017
|
-
const httpKernel = utils_1.createHttpKernel([Controller]);
|
|
1018
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/action1'))).json).toEqual([{ title: 'a' }, { title: '1' }]);
|
|
1019
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/action2'))).json).toEqual([{ title: 'a' }, { title: '1' }]);
|
|
1020
|
-
globals_1.expect((await httpKernel.request(model_1.HttpRequest.GET('/action3'))).json).toEqual([{ message: 'error' }, { message: '1' }]);
|
|
929
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
930
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/action1'))).json).toEqual([{ title: 'a' }, { title: '1' }]);
|
|
931
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/action2'))).json).toEqual([{ title: 'a' }, { title: '1' }]);
|
|
932
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.GET('/action3'))).json).toEqual([{ message: 'error' }, { message: '1' }]);
|
|
933
|
+
});
|
|
934
|
+
(0, globals_1.test)('BodyValidation', async () => {
|
|
935
|
+
class User {
|
|
936
|
+
}
|
|
937
|
+
User.__type = [() => __ΩMinLength, 3, 'username', 'P&."o!"K3#5'];
|
|
938
|
+
class AddUserDto extends User {
|
|
939
|
+
}
|
|
940
|
+
AddUserDto.__type = [() => router_1.UploadedFile, 'imageUpload', 'P7!3"85'];
|
|
941
|
+
class Controller {
|
|
942
|
+
action1(user) {
|
|
943
|
+
return user;
|
|
944
|
+
}
|
|
945
|
+
action2(user) {
|
|
946
|
+
if (user.valid()) {
|
|
947
|
+
return user.value;
|
|
948
|
+
}
|
|
949
|
+
throw new http_1.HttpBadRequestError('Invalid: ' + user.error.getErrorMessageForPath('username'));
|
|
950
|
+
}
|
|
951
|
+
action3(user) {
|
|
952
|
+
if (user.valid()) {
|
|
953
|
+
return user.value;
|
|
954
|
+
}
|
|
955
|
+
throw new http_1.HttpBadRequestError('Invalid: ' + user.error.getErrorMessageForPath('username'));
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
Controller.__type = [() => __ΩHttpBody, () => User, 'user', 'action1', () => __ΩHttpBodyValidation, () => User, () => User, 'action2', () => __ΩHttpBodyValidation, () => AddUserDto, () => User, 'action3', 'PP7"o!"2#"0$PP7&o%"2#P7\'0(PP7*o)"2#P7+0,5'];
|
|
959
|
+
__decorate([
|
|
960
|
+
decorator_1.http.POST('/action1'),
|
|
961
|
+
__metadata("design:type", Function),
|
|
962
|
+
__metadata("design:paramtypes", [Object]),
|
|
963
|
+
__metadata("design:returntype", Object)
|
|
964
|
+
], Controller.prototype, "action1", null);
|
|
965
|
+
__decorate([
|
|
966
|
+
decorator_1.http.POST('/action2'),
|
|
967
|
+
__metadata("design:type", Function),
|
|
968
|
+
__metadata("design:paramtypes", [Object]),
|
|
969
|
+
__metadata("design:returntype", User)
|
|
970
|
+
], Controller.prototype, "action2", null);
|
|
971
|
+
__decorate([
|
|
972
|
+
decorator_1.http.POST('/action3'),
|
|
973
|
+
__metadata("design:type", Function),
|
|
974
|
+
__metadata("design:paramtypes", [Object]),
|
|
975
|
+
__metadata("design:returntype", User)
|
|
976
|
+
], Controller.prototype, "action3", null);
|
|
977
|
+
const httpKernel = (0, utils_1.createHttpKernel)([Controller]);
|
|
978
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action1').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
|
|
979
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action1').json({ username: 'Pe' }))).json).toEqual({
|
|
980
|
+
errors: [{ code: 'minLength', message: 'Min length is 3', path: 'username' }], message: 'Validation error:\nusername(minLength): Min length is 3'
|
|
981
|
+
});
|
|
982
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action2').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
|
|
983
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action2').json({ username: 'Pe' }))).bodyString).toEqual(`{"message":"Invalid: Min length is 3"}`);
|
|
984
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action3').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
|
|
985
|
+
(0, globals_1.expect)((await httpKernel.request(model_1.HttpRequest.POST('/action3').json({ username: 'Pe' }))).bodyString).toEqual(`{"message":"Invalid: Min length is 3"}`);
|
|
1021
986
|
});
|
|
1022
987
|
//# sourceMappingURL=router.spec.js.map
|