@antelopejs/api 0.1.0 → 1.0.0
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/README.md +6 -3
- package/dist/implementations/api/index.d.ts +19 -0
- package/dist/implementations/api/index.js +71 -0
- package/dist/implementations/api/index.js.map +1 -0
- package/dist/index.d.ts +19 -14
- package/dist/index.js +97 -31
- package/dist/index.js.map +1 -1
- package/dist/middlewares/cors.d.ts +3 -3
- package/dist/middlewares/cors.js +50 -36
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/server.d.ts +8 -7
- package/dist/server.js +229 -108
- package/dist/server.js.map +1 -1
- package/dist/test/antelope.test.d.ts +2 -0
- package/dist/test/antelope.test.js +25 -0
- package/dist/test/antelope.test.js.map +1 -0
- package/package.json +19 -35
- package/dist/implementations/api/beta.d.ts +0 -21
- package/dist/implementations/api/beta.js +0 -54
- package/dist/implementations/api/beta.js.map +0 -1
- package/dist/interfaces/api/beta/index.d.ts +0 -117
- package/dist/interfaces/api/beta/index.js +0 -311
- package/dist/interfaces/api/beta/index.js.map +0 -1
- package/dist/test/interface/api.d.ts +0 -69
- package/dist/test/interface/api.js +0 -739
- package/dist/test/interface/api.js.map +0 -1
|
@@ -1,739 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TestWebsocketController1 = exports.TestExecutionController3 = exports.TestExecutionController2 = exports.TestExecutionController1 = exports.TestRoutingController3 = exports.TestRoutingController2 = exports.TestRoutingController1 = exports.TestRoutingController0 = void 0;
|
|
19
|
-
const beta_1 = require("@ajs/api/beta");
|
|
20
|
-
const decorators_1 = require("@ajs/core/beta/decorators");
|
|
21
|
-
const assert_1 = __importDefault(require("assert"));
|
|
22
|
-
const sinon_1 = __importDefault(require("sinon"));
|
|
23
|
-
const stream_1 = require("stream");
|
|
24
|
-
const ws_1 = __importDefault(require("ws"));
|
|
25
|
-
const SpyMethod = (0, decorators_1.MakeMethodDecorator)((_target, _key, descriptor) => {
|
|
26
|
-
descriptor.value = sinon_1.default.spy(descriptor.value);
|
|
27
|
-
});
|
|
28
|
-
const URL_BASE = 'http://127.0.0.1:5010';
|
|
29
|
-
function FetchTest(name, options) {
|
|
30
|
-
it(`${name}: ${options.method ?? 'GET'} ${options.route}`, async function () {
|
|
31
|
-
const init = { method: options.method ?? 'GET' };
|
|
32
|
-
if (options.prepare) {
|
|
33
|
-
await options.prepare.apply(this, [init, options]);
|
|
34
|
-
}
|
|
35
|
-
const res = await fetch(URL_BASE + options.route, init);
|
|
36
|
-
if (res.status !== options.status) {
|
|
37
|
-
throw new Error(`Wrong response status (expected ${options.status}, got ${res.status}): ${await res.text()}`);
|
|
38
|
-
}
|
|
39
|
-
if (options.result !== undefined) {
|
|
40
|
-
assert_1.default.equal(await res.text(), options.result, 'Incorrect response body');
|
|
41
|
-
}
|
|
42
|
-
if (options.callCount) {
|
|
43
|
-
sinon_1.default.assert.callCount(options.callCount[0], options.callCount[1]);
|
|
44
|
-
}
|
|
45
|
-
if (options.postCheck) {
|
|
46
|
-
await options.postCheck.apply(this, [res, options]);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
class TestRoutingController0 extends (0, beta_1.Controller)('/') {
|
|
51
|
-
test() { }
|
|
52
|
-
testPrefixHigh() { }
|
|
53
|
-
testPrefixLow() { }
|
|
54
|
-
testPriority() { }
|
|
55
|
-
testPostfixHigh() { }
|
|
56
|
-
testPostfixLow() { }
|
|
57
|
-
testPrefixEarlyReturn() {
|
|
58
|
-
return 'Ok Early';
|
|
59
|
-
}
|
|
60
|
-
testEarlyReturn() {
|
|
61
|
-
return 'Not Ok';
|
|
62
|
-
}
|
|
63
|
-
testOverride() {
|
|
64
|
-
return 'Not Ok';
|
|
65
|
-
}
|
|
66
|
-
testPostfixOverride() {
|
|
67
|
-
return 'Ok Override';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.TestRoutingController0 = TestRoutingController0;
|
|
71
|
-
__decorate([
|
|
72
|
-
(0, beta_1.Get)(),
|
|
73
|
-
__metadata("design:type", Function),
|
|
74
|
-
__metadata("design:paramtypes", []),
|
|
75
|
-
__metadata("design:returntype", void 0)
|
|
76
|
-
], TestRoutingController0.prototype, "test", null);
|
|
77
|
-
__decorate([
|
|
78
|
-
(0, beta_1.Prefix)('get', 'testPriority', beta_1.HandlerPriority.HIGH),
|
|
79
|
-
SpyMethod(),
|
|
80
|
-
__metadata("design:type", Function),
|
|
81
|
-
__metadata("design:paramtypes", []),
|
|
82
|
-
__metadata("design:returntype", void 0)
|
|
83
|
-
], TestRoutingController0.prototype, "testPrefixHigh", null);
|
|
84
|
-
__decorate([
|
|
85
|
-
(0, beta_1.Prefix)('get', 'testPriority', beta_1.HandlerPriority.LOW),
|
|
86
|
-
SpyMethod(),
|
|
87
|
-
__metadata("design:type", Function),
|
|
88
|
-
__metadata("design:paramtypes", []),
|
|
89
|
-
__metadata("design:returntype", void 0)
|
|
90
|
-
], TestRoutingController0.prototype, "testPrefixLow", null);
|
|
91
|
-
__decorate([
|
|
92
|
-
(0, beta_1.Get)(),
|
|
93
|
-
SpyMethod(),
|
|
94
|
-
__metadata("design:type", Function),
|
|
95
|
-
__metadata("design:paramtypes", []),
|
|
96
|
-
__metadata("design:returntype", void 0)
|
|
97
|
-
], TestRoutingController0.prototype, "testPriority", null);
|
|
98
|
-
__decorate([
|
|
99
|
-
(0, beta_1.Postfix)('get', 'testPriority', beta_1.HandlerPriority.HIGH),
|
|
100
|
-
SpyMethod(),
|
|
101
|
-
__metadata("design:type", Function),
|
|
102
|
-
__metadata("design:paramtypes", []),
|
|
103
|
-
__metadata("design:returntype", void 0)
|
|
104
|
-
], TestRoutingController0.prototype, "testPostfixHigh", null);
|
|
105
|
-
__decorate([
|
|
106
|
-
(0, beta_1.Postfix)('get', 'testPriority', beta_1.HandlerPriority.LOW),
|
|
107
|
-
SpyMethod(),
|
|
108
|
-
__metadata("design:type", Function),
|
|
109
|
-
__metadata("design:paramtypes", []),
|
|
110
|
-
__metadata("design:returntype", void 0)
|
|
111
|
-
], TestRoutingController0.prototype, "testPostfixLow", null);
|
|
112
|
-
__decorate([
|
|
113
|
-
(0, beta_1.Prefix)('get', 'testEarlyReturn'),
|
|
114
|
-
SpyMethod(),
|
|
115
|
-
__metadata("design:type", Function),
|
|
116
|
-
__metadata("design:paramtypes", []),
|
|
117
|
-
__metadata("design:returntype", void 0)
|
|
118
|
-
], TestRoutingController0.prototype, "testPrefixEarlyReturn", null);
|
|
119
|
-
__decorate([
|
|
120
|
-
(0, beta_1.Get)(),
|
|
121
|
-
SpyMethod(),
|
|
122
|
-
__metadata("design:type", Function),
|
|
123
|
-
__metadata("design:paramtypes", []),
|
|
124
|
-
__metadata("design:returntype", void 0)
|
|
125
|
-
], TestRoutingController0.prototype, "testEarlyReturn", null);
|
|
126
|
-
__decorate([
|
|
127
|
-
(0, beta_1.Get)(),
|
|
128
|
-
SpyMethod(),
|
|
129
|
-
__metadata("design:type", Function),
|
|
130
|
-
__metadata("design:paramtypes", []),
|
|
131
|
-
__metadata("design:returntype", void 0)
|
|
132
|
-
], TestRoutingController0.prototype, "testOverride", null);
|
|
133
|
-
__decorate([
|
|
134
|
-
(0, beta_1.Postfix)('get', 'testOverride'),
|
|
135
|
-
SpyMethod(),
|
|
136
|
-
__metadata("design:type", Function),
|
|
137
|
-
__metadata("design:paramtypes", []),
|
|
138
|
-
__metadata("design:returntype", void 0)
|
|
139
|
-
], TestRoutingController0.prototype, "testPostfixOverride", null);
|
|
140
|
-
class TestRoutingController1 extends (0, beta_1.Controller)('/routing/controller1') {
|
|
141
|
-
test() {
|
|
142
|
-
return 'Ok';
|
|
143
|
-
}
|
|
144
|
-
testPost() {
|
|
145
|
-
return 'Ok Post';
|
|
146
|
-
}
|
|
147
|
-
testPut() {
|
|
148
|
-
return 'Ok Put';
|
|
149
|
-
}
|
|
150
|
-
testDelete() {
|
|
151
|
-
return 'Ok Delete';
|
|
152
|
-
}
|
|
153
|
-
testCustom() {
|
|
154
|
-
return 'Ok Patch';
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.TestRoutingController1 = TestRoutingController1;
|
|
158
|
-
__decorate([
|
|
159
|
-
(0, beta_1.Get)(),
|
|
160
|
-
SpyMethod(),
|
|
161
|
-
__metadata("design:type", Function),
|
|
162
|
-
__metadata("design:paramtypes", []),
|
|
163
|
-
__metadata("design:returntype", void 0)
|
|
164
|
-
], TestRoutingController1.prototype, "test", null);
|
|
165
|
-
__decorate([
|
|
166
|
-
(0, beta_1.Post)('test'),
|
|
167
|
-
SpyMethod(),
|
|
168
|
-
__metadata("design:type", Function),
|
|
169
|
-
__metadata("design:paramtypes", []),
|
|
170
|
-
__metadata("design:returntype", void 0)
|
|
171
|
-
], TestRoutingController1.prototype, "testPost", null);
|
|
172
|
-
__decorate([
|
|
173
|
-
(0, beta_1.Put)('test'),
|
|
174
|
-
SpyMethod(),
|
|
175
|
-
__metadata("design:type", Function),
|
|
176
|
-
__metadata("design:paramtypes", []),
|
|
177
|
-
__metadata("design:returntype", void 0)
|
|
178
|
-
], TestRoutingController1.prototype, "testPut", null);
|
|
179
|
-
__decorate([
|
|
180
|
-
(0, beta_1.Delete)('test'),
|
|
181
|
-
SpyMethod(),
|
|
182
|
-
__metadata("design:type", Function),
|
|
183
|
-
__metadata("design:paramtypes", []),
|
|
184
|
-
__metadata("design:returntype", void 0)
|
|
185
|
-
], TestRoutingController1.prototype, "testDelete", null);
|
|
186
|
-
__decorate([
|
|
187
|
-
(0, beta_1.Route)('handler', 'patch', 'test'),
|
|
188
|
-
SpyMethod(),
|
|
189
|
-
__metadata("design:type", Function),
|
|
190
|
-
__metadata("design:paramtypes", []),
|
|
191
|
-
__metadata("design:returntype", void 0)
|
|
192
|
-
], TestRoutingController1.prototype, "testCustom", null);
|
|
193
|
-
class TestRoutingController2 extends TestRoutingController1.extend('/explicit') {
|
|
194
|
-
test() {
|
|
195
|
-
return 'Ok 2';
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
exports.TestRoutingController2 = TestRoutingController2;
|
|
199
|
-
__decorate([
|
|
200
|
-
(0, beta_1.Get)(),
|
|
201
|
-
__metadata("design:type", Function),
|
|
202
|
-
__metadata("design:paramtypes", []),
|
|
203
|
-
__metadata("design:returntype", void 0)
|
|
204
|
-
], TestRoutingController2.prototype, "test", null);
|
|
205
|
-
class TestRoutingController3 extends (0, beta_1.Controller)('///routing///controller2///') {
|
|
206
|
-
test() { }
|
|
207
|
-
}
|
|
208
|
-
exports.TestRoutingController3 = TestRoutingController3;
|
|
209
|
-
__decorate([
|
|
210
|
-
(0, beta_1.Get)(),
|
|
211
|
-
__metadata("design:type", Function),
|
|
212
|
-
__metadata("design:paramtypes", []),
|
|
213
|
-
__metadata("design:returntype", void 0)
|
|
214
|
-
], TestRoutingController3.prototype, "test", null);
|
|
215
|
-
describe('Routing', () => {
|
|
216
|
-
describe('Controller', () => {
|
|
217
|
-
FetchTest('Root Controller', { route: '/test', method: 'GET', status: 200 });
|
|
218
|
-
FetchTest('Normal Controller', {
|
|
219
|
-
route: '/routing/controller1/test',
|
|
220
|
-
method: 'GET',
|
|
221
|
-
status: 200,
|
|
222
|
-
result: 'Ok',
|
|
223
|
-
});
|
|
224
|
-
FetchTest('Extended Controller', {
|
|
225
|
-
route: '/routing/controller1/explicit/test',
|
|
226
|
-
method: 'GET',
|
|
227
|
-
status: 200,
|
|
228
|
-
result: 'Ok 2',
|
|
229
|
-
});
|
|
230
|
-
FetchTest('Redundant Slash Controller', { route: '/routing/controller2/test', method: 'GET', status: 200 });
|
|
231
|
-
});
|
|
232
|
-
describe('Handler', () => {
|
|
233
|
-
const testRoute1 = TestRoutingController1.prototype.test;
|
|
234
|
-
FetchTest('Normal Call', {
|
|
235
|
-
route: '/routing/controller1/test',
|
|
236
|
-
method: 'GET',
|
|
237
|
-
status: 200,
|
|
238
|
-
callCount: [testRoute1, 1],
|
|
239
|
-
prepare: () => testRoute1.resetHistory(),
|
|
240
|
-
});
|
|
241
|
-
FetchTest('Options Call', {
|
|
242
|
-
route: '/routing/controller1/test',
|
|
243
|
-
method: 'OPTIONS',
|
|
244
|
-
status: 404,
|
|
245
|
-
callCount: [testRoute1, 0],
|
|
246
|
-
prepare: () => testRoute1.resetHistory(),
|
|
247
|
-
});
|
|
248
|
-
FetchTest('Head Call', {
|
|
249
|
-
route: '/routing/controller1/test',
|
|
250
|
-
method: 'HEAD',
|
|
251
|
-
status: 200,
|
|
252
|
-
result: '',
|
|
253
|
-
callCount: [testRoute1, 1],
|
|
254
|
-
prepare: () => testRoute1.resetHistory(),
|
|
255
|
-
});
|
|
256
|
-
FetchTest('Post Call', {
|
|
257
|
-
route: '/routing/controller1/test',
|
|
258
|
-
method: 'POST',
|
|
259
|
-
status: 200,
|
|
260
|
-
result: 'Ok Post',
|
|
261
|
-
});
|
|
262
|
-
FetchTest('Put Call', {
|
|
263
|
-
route: '/routing/controller1/test',
|
|
264
|
-
method: 'PUT',
|
|
265
|
-
status: 200,
|
|
266
|
-
result: 'Ok Put',
|
|
267
|
-
});
|
|
268
|
-
FetchTest('Delete Call', {
|
|
269
|
-
route: '/routing/controller1/test',
|
|
270
|
-
method: 'DELETE',
|
|
271
|
-
status: 200,
|
|
272
|
-
result: 'Ok Delete',
|
|
273
|
-
});
|
|
274
|
-
FetchTest('Custom Call (PATCH)', {
|
|
275
|
-
route: '/routing/controller1/test',
|
|
276
|
-
method: 'PATCH',
|
|
277
|
-
status: 200,
|
|
278
|
-
result: 'Ok Patch',
|
|
279
|
-
});
|
|
280
|
-
FetchTest('Prefix Priority', {
|
|
281
|
-
route: '/testPriority',
|
|
282
|
-
method: 'GET',
|
|
283
|
-
status: 200,
|
|
284
|
-
postCheck: () => {
|
|
285
|
-
sinon_1.default.assert.callOrder(TestRoutingController0.prototype.testPrefixHigh, TestRoutingController0.prototype.testPrefixLow, TestRoutingController0.prototype.testPriority);
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
FetchTest('Prefix Early Return', {
|
|
289
|
-
route: '/testEarlyReturn',
|
|
290
|
-
method: 'GET',
|
|
291
|
-
status: 200,
|
|
292
|
-
result: 'Ok Early',
|
|
293
|
-
callCount: [TestRoutingController0.prototype.testEarlyReturn, 0],
|
|
294
|
-
});
|
|
295
|
-
FetchTest('Postfix Priority', {
|
|
296
|
-
route: '/testPriority',
|
|
297
|
-
method: 'GET',
|
|
298
|
-
status: 200,
|
|
299
|
-
postCheck: () => {
|
|
300
|
-
sinon_1.default.assert.callOrder(TestRoutingController0.prototype.testPriority, TestRoutingController0.prototype.testPostfixHigh, TestRoutingController0.prototype.testPostfixLow);
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
FetchTest('Postfix Override', {
|
|
304
|
-
route: '/testOverride',
|
|
305
|
-
method: 'GET',
|
|
306
|
-
status: 200,
|
|
307
|
-
result: 'Ok Override',
|
|
308
|
-
callCount: [TestRoutingController0.prototype.testOverride, 1],
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
const ConstantProvider = (0, decorators_1.MakeParameterAndPropertyDecorator)((target, key, index, value) => (0, beta_1.SetParameterProvider)(target, key, index, () => value));
|
|
313
|
-
class TestExecutionController1 extends (0, beta_1.Controller)('/execution/controller1') {
|
|
314
|
-
testProperty() {
|
|
315
|
-
return this.prop;
|
|
316
|
-
}
|
|
317
|
-
testParameter(param) {
|
|
318
|
-
return param;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
exports.TestExecutionController1 = TestExecutionController1;
|
|
322
|
-
__decorate([
|
|
323
|
-
ConstantProvider('Ok'),
|
|
324
|
-
__metadata("design:type", String)
|
|
325
|
-
], TestExecutionController1.prototype, "prop", void 0);
|
|
326
|
-
__decorate([
|
|
327
|
-
(0, beta_1.Get)(),
|
|
328
|
-
SpyMethod(),
|
|
329
|
-
__metadata("design:type", Function),
|
|
330
|
-
__metadata("design:paramtypes", []),
|
|
331
|
-
__metadata("design:returntype", void 0)
|
|
332
|
-
], TestExecutionController1.prototype, "testProperty", null);
|
|
333
|
-
__decorate([
|
|
334
|
-
(0, beta_1.Get)(),
|
|
335
|
-
SpyMethod(),
|
|
336
|
-
__param(0, ConstantProvider('Ok')),
|
|
337
|
-
__metadata("design:type", Function),
|
|
338
|
-
__metadata("design:paramtypes", [String]),
|
|
339
|
-
__metadata("design:returntype", void 0)
|
|
340
|
-
], TestExecutionController1.prototype, "testParameter", null);
|
|
341
|
-
class TestExecutionController2 extends (0, beta_1.Controller)('/execution/controller2') {
|
|
342
|
-
testProviderContext(_ctx) { }
|
|
343
|
-
testProviderRawBody(_body) { }
|
|
344
|
-
testProviderParameterParam(_param) { }
|
|
345
|
-
testProviderParameterHeader(_param) { }
|
|
346
|
-
testProviderParameterQuery(_param) { }
|
|
347
|
-
testProviderMultiParameterHeader(_params) { }
|
|
348
|
-
testProviderMultiParameterQuery(_params) { }
|
|
349
|
-
testProviderWriteStream(param) {
|
|
350
|
-
param.write('Ok');
|
|
351
|
-
param.end();
|
|
352
|
-
}
|
|
353
|
-
testProviderResult() {
|
|
354
|
-
return 'Ok';
|
|
355
|
-
}
|
|
356
|
-
testProviderResultPostfix(_res) { }
|
|
357
|
-
testModifierTransform(_param) { }
|
|
358
|
-
}
|
|
359
|
-
exports.TestExecutionController2 = TestExecutionController2;
|
|
360
|
-
__decorate([
|
|
361
|
-
(0, beta_1.Get)(),
|
|
362
|
-
SpyMethod(),
|
|
363
|
-
__param(0, (0, beta_1.Context)()),
|
|
364
|
-
__metadata("design:type", Function),
|
|
365
|
-
__metadata("design:paramtypes", [Object]),
|
|
366
|
-
__metadata("design:returntype", void 0)
|
|
367
|
-
], TestExecutionController2.prototype, "testProviderContext", null);
|
|
368
|
-
__decorate([
|
|
369
|
-
(0, beta_1.Post)(),
|
|
370
|
-
SpyMethod(),
|
|
371
|
-
__param(0, (0, beta_1.RawBody)()),
|
|
372
|
-
__metadata("design:type", Function),
|
|
373
|
-
__metadata("design:paramtypes", [Buffer]),
|
|
374
|
-
__metadata("design:returntype", void 0)
|
|
375
|
-
], TestExecutionController2.prototype, "testProviderRawBody", null);
|
|
376
|
-
__decorate([
|
|
377
|
-
(0, beta_1.Get)('testProviderParameterParam/:key'),
|
|
378
|
-
SpyMethod(),
|
|
379
|
-
__param(0, (0, beta_1.Parameter)('key', 'param')),
|
|
380
|
-
__metadata("design:type", Function),
|
|
381
|
-
__metadata("design:paramtypes", [String]),
|
|
382
|
-
__metadata("design:returntype", void 0)
|
|
383
|
-
], TestExecutionController2.prototype, "testProviderParameterParam", null);
|
|
384
|
-
__decorate([
|
|
385
|
-
(0, beta_1.Get)(),
|
|
386
|
-
SpyMethod(),
|
|
387
|
-
__param(0, (0, beta_1.Parameter)('key', 'header')),
|
|
388
|
-
__metadata("design:type", Function),
|
|
389
|
-
__metadata("design:paramtypes", [String]),
|
|
390
|
-
__metadata("design:returntype", void 0)
|
|
391
|
-
], TestExecutionController2.prototype, "testProviderParameterHeader", null);
|
|
392
|
-
__decorate([
|
|
393
|
-
(0, beta_1.Get)(),
|
|
394
|
-
SpyMethod(),
|
|
395
|
-
__param(0, (0, beta_1.Parameter)('key', 'query')),
|
|
396
|
-
__metadata("design:type", Function),
|
|
397
|
-
__metadata("design:paramtypes", [String]),
|
|
398
|
-
__metadata("design:returntype", void 0)
|
|
399
|
-
], TestExecutionController2.prototype, "testProviderParameterQuery", null);
|
|
400
|
-
__decorate([
|
|
401
|
-
(0, beta_1.Get)(),
|
|
402
|
-
SpyMethod(),
|
|
403
|
-
__param(0, (0, beta_1.MultiParameter)('key', 'header')),
|
|
404
|
-
__metadata("design:type", Function),
|
|
405
|
-
__metadata("design:paramtypes", [Array]),
|
|
406
|
-
__metadata("design:returntype", void 0)
|
|
407
|
-
], TestExecutionController2.prototype, "testProviderMultiParameterHeader", null);
|
|
408
|
-
__decorate([
|
|
409
|
-
(0, beta_1.Get)(),
|
|
410
|
-
SpyMethod(),
|
|
411
|
-
__param(0, (0, beta_1.MultiParameter)('key', 'query')),
|
|
412
|
-
__metadata("design:type", Function),
|
|
413
|
-
__metadata("design:paramtypes", [Array]),
|
|
414
|
-
__metadata("design:returntype", void 0)
|
|
415
|
-
], TestExecutionController2.prototype, "testProviderMultiParameterQuery", null);
|
|
416
|
-
__decorate([
|
|
417
|
-
(0, beta_1.Get)(),
|
|
418
|
-
SpyMethod(),
|
|
419
|
-
__param(0, (0, beta_1.WriteStream)()),
|
|
420
|
-
__metadata("design:type", Function),
|
|
421
|
-
__metadata("design:paramtypes", [stream_1.PassThrough]),
|
|
422
|
-
__metadata("design:returntype", void 0)
|
|
423
|
-
], TestExecutionController2.prototype, "testProviderWriteStream", null);
|
|
424
|
-
__decorate([
|
|
425
|
-
(0, beta_1.Get)(),
|
|
426
|
-
__metadata("design:type", Function),
|
|
427
|
-
__metadata("design:paramtypes", []),
|
|
428
|
-
__metadata("design:returntype", void 0)
|
|
429
|
-
], TestExecutionController2.prototype, "testProviderResult", null);
|
|
430
|
-
__decorate([
|
|
431
|
-
(0, beta_1.Postfix)('get', 'testProviderResult'),
|
|
432
|
-
SpyMethod(),
|
|
433
|
-
__param(0, (0, beta_1.Result)()),
|
|
434
|
-
__metadata("design:type", Function),
|
|
435
|
-
__metadata("design:paramtypes", [String]),
|
|
436
|
-
__metadata("design:returntype", void 0)
|
|
437
|
-
], TestExecutionController2.prototype, "testProviderResultPostfix", null);
|
|
438
|
-
__decorate([
|
|
439
|
-
(0, beta_1.Get)(),
|
|
440
|
-
SpyMethod(),
|
|
441
|
-
__param(0, ConstantProvider('O')),
|
|
442
|
-
__param(0, (0, beta_1.Transform)((_ctx, val) => val + 'k')),
|
|
443
|
-
__metadata("design:type", Function),
|
|
444
|
-
__metadata("design:paramtypes", [String]),
|
|
445
|
-
__metadata("design:returntype", void 0)
|
|
446
|
-
], TestExecutionController2.prototype, "testModifierTransform", null);
|
|
447
|
-
class TestExecutionController3 extends (0, beta_1.Controller)('/execution/controller3') {
|
|
448
|
-
test() {
|
|
449
|
-
return new beta_1.HTTPResult();
|
|
450
|
-
}
|
|
451
|
-
testThrow() {
|
|
452
|
-
throw new beta_1.HTTPResult();
|
|
453
|
-
}
|
|
454
|
-
testStatus() {
|
|
455
|
-
return new beta_1.HTTPResult(201);
|
|
456
|
-
}
|
|
457
|
-
testHeader() {
|
|
458
|
-
const res = new beta_1.HTTPResult(200);
|
|
459
|
-
res.addHeader('key', 'Ok');
|
|
460
|
-
return res;
|
|
461
|
-
}
|
|
462
|
-
testBody() {
|
|
463
|
-
return new beta_1.HTTPResult(200, 'Ok', 'text/plain');
|
|
464
|
-
}
|
|
465
|
-
testConsistencyPrefix(res) {
|
|
466
|
-
res.addHeader('key1', 'Ok');
|
|
467
|
-
}
|
|
468
|
-
testConsistency(res) {
|
|
469
|
-
res.addHeader('key2', 'Ok');
|
|
470
|
-
res.setStatus(200);
|
|
471
|
-
res.setBody('Ok', 'text/plain');
|
|
472
|
-
return res;
|
|
473
|
-
}
|
|
474
|
-
testConsistencyPostfix(res) {
|
|
475
|
-
res.addHeader('key3', 'Ok');
|
|
476
|
-
}
|
|
477
|
-
async testControllerInstance(ctx) {
|
|
478
|
-
const controller1 = await (0, beta_1.GetControllerInstance)(TestExecutionController1, ctx);
|
|
479
|
-
return controller1.prop;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
exports.TestExecutionController3 = TestExecutionController3;
|
|
483
|
-
__decorate([
|
|
484
|
-
(0, beta_1.Get)(),
|
|
485
|
-
__metadata("design:type", Function),
|
|
486
|
-
__metadata("design:paramtypes", []),
|
|
487
|
-
__metadata("design:returntype", void 0)
|
|
488
|
-
], TestExecutionController3.prototype, "test", null);
|
|
489
|
-
__decorate([
|
|
490
|
-
(0, beta_1.Get)(),
|
|
491
|
-
__metadata("design:type", Function),
|
|
492
|
-
__metadata("design:paramtypes", []),
|
|
493
|
-
__metadata("design:returntype", void 0)
|
|
494
|
-
], TestExecutionController3.prototype, "testThrow", null);
|
|
495
|
-
__decorate([
|
|
496
|
-
(0, beta_1.Get)(),
|
|
497
|
-
__metadata("design:type", Function),
|
|
498
|
-
__metadata("design:paramtypes", []),
|
|
499
|
-
__metadata("design:returntype", void 0)
|
|
500
|
-
], TestExecutionController3.prototype, "testStatus", null);
|
|
501
|
-
__decorate([
|
|
502
|
-
(0, beta_1.Get)(),
|
|
503
|
-
__metadata("design:type", Function),
|
|
504
|
-
__metadata("design:paramtypes", []),
|
|
505
|
-
__metadata("design:returntype", void 0)
|
|
506
|
-
], TestExecutionController3.prototype, "testHeader", null);
|
|
507
|
-
__decorate([
|
|
508
|
-
(0, beta_1.Get)(),
|
|
509
|
-
__metadata("design:type", Function),
|
|
510
|
-
__metadata("design:paramtypes", []),
|
|
511
|
-
__metadata("design:returntype", void 0)
|
|
512
|
-
], TestExecutionController3.prototype, "testBody", null);
|
|
513
|
-
__decorate([
|
|
514
|
-
(0, beta_1.Postfix)('get', 'testConsistency'),
|
|
515
|
-
__param(0, (0, beta_1.Result)()),
|
|
516
|
-
__metadata("design:type", Function),
|
|
517
|
-
__metadata("design:paramtypes", [beta_1.HTTPResult]),
|
|
518
|
-
__metadata("design:returntype", void 0)
|
|
519
|
-
], TestExecutionController3.prototype, "testConsistencyPrefix", null);
|
|
520
|
-
__decorate([
|
|
521
|
-
(0, beta_1.Get)(),
|
|
522
|
-
__param(0, (0, beta_1.Result)()),
|
|
523
|
-
__metadata("design:type", Function),
|
|
524
|
-
__metadata("design:paramtypes", [beta_1.HTTPResult]),
|
|
525
|
-
__metadata("design:returntype", void 0)
|
|
526
|
-
], TestExecutionController3.prototype, "testConsistency", null);
|
|
527
|
-
__decorate([
|
|
528
|
-
(0, beta_1.Postfix)('get', 'testConsistency'),
|
|
529
|
-
__param(0, (0, beta_1.Result)()),
|
|
530
|
-
__metadata("design:type", Function),
|
|
531
|
-
__metadata("design:paramtypes", [beta_1.HTTPResult]),
|
|
532
|
-
__metadata("design:returntype", void 0)
|
|
533
|
-
], TestExecutionController3.prototype, "testConsistencyPostfix", null);
|
|
534
|
-
__decorate([
|
|
535
|
-
(0, beta_1.Get)(),
|
|
536
|
-
SpyMethod(),
|
|
537
|
-
__param(0, (0, beta_1.Context)()),
|
|
538
|
-
__metadata("design:type", Function),
|
|
539
|
-
__metadata("design:paramtypes", [Object]),
|
|
540
|
-
__metadata("design:returntype", Promise)
|
|
541
|
-
], TestExecutionController3.prototype, "testControllerInstance", null);
|
|
542
|
-
describe('Execution', () => {
|
|
543
|
-
FetchTest('Property Access', {
|
|
544
|
-
route: '/execution/controller1/testProperty',
|
|
545
|
-
method: 'GET',
|
|
546
|
-
status: 200,
|
|
547
|
-
result: 'Ok',
|
|
548
|
-
});
|
|
549
|
-
FetchTest('Parameter Access', {
|
|
550
|
-
route: '/execution/controller1/testParameter',
|
|
551
|
-
method: 'GET',
|
|
552
|
-
status: 200,
|
|
553
|
-
result: 'Ok',
|
|
554
|
-
});
|
|
555
|
-
FetchTest('GetControllerInstance', {
|
|
556
|
-
route: '/execution/controller3/testControllerInstance',
|
|
557
|
-
method: 'GET',
|
|
558
|
-
status: 200,
|
|
559
|
-
result: 'Ok',
|
|
560
|
-
});
|
|
561
|
-
describe('Providers', () => {
|
|
562
|
-
FetchTest('Context', {
|
|
563
|
-
route: '/execution/controller2/testProviderContext',
|
|
564
|
-
method: 'GET',
|
|
565
|
-
status: 200,
|
|
566
|
-
postCheck() {
|
|
567
|
-
const res = TestExecutionController2.prototype.testProviderContext.lastCall
|
|
568
|
-
.args[0];
|
|
569
|
-
assert_1.default.equal(typeof res, 'object', 'Context object type');
|
|
570
|
-
(0, assert_1.default)(res.rawRequest, 'Context object');
|
|
571
|
-
},
|
|
572
|
-
});
|
|
573
|
-
FetchTest('RawBody', {
|
|
574
|
-
route: '/execution/controller2/testProviderRawBody',
|
|
575
|
-
method: 'POST',
|
|
576
|
-
status: 200,
|
|
577
|
-
prepare(init) {
|
|
578
|
-
init.body = 'Test';
|
|
579
|
-
},
|
|
580
|
-
postCheck() {
|
|
581
|
-
const res = TestExecutionController2.prototype.testProviderRawBody.lastCall.args[0];
|
|
582
|
-
(0, assert_1.default)(Buffer.isBuffer(res), 'Buffer object');
|
|
583
|
-
assert_1.default.equal(res.toString(), 'Test');
|
|
584
|
-
},
|
|
585
|
-
});
|
|
586
|
-
FetchTest('Parameter (param)', {
|
|
587
|
-
route: '/execution/controller2/testProviderParameterParam/Ok',
|
|
588
|
-
method: 'GET',
|
|
589
|
-
status: 200,
|
|
590
|
-
postCheck() {
|
|
591
|
-
assert_1.default.equal(TestExecutionController2.prototype.testProviderParameterParam.lastCall.args[0], 'Ok', 'Parameter value');
|
|
592
|
-
},
|
|
593
|
-
});
|
|
594
|
-
FetchTest('Parameter (header)', {
|
|
595
|
-
route: '/execution/controller2/testProviderParameterHeader',
|
|
596
|
-
method: 'GET',
|
|
597
|
-
status: 200,
|
|
598
|
-
prepare(init) {
|
|
599
|
-
init.headers = { key: 'Ok' };
|
|
600
|
-
},
|
|
601
|
-
postCheck() {
|
|
602
|
-
assert_1.default.equal(TestExecutionController2.prototype.testProviderParameterHeader.lastCall.args[0], 'Ok', 'Parameter value');
|
|
603
|
-
},
|
|
604
|
-
});
|
|
605
|
-
FetchTest('Parameter (query)', {
|
|
606
|
-
route: '/execution/controller2/testProviderParameterQuery?key=Ok',
|
|
607
|
-
method: 'GET',
|
|
608
|
-
status: 200,
|
|
609
|
-
postCheck() {
|
|
610
|
-
assert_1.default.equal(TestExecutionController2.prototype.testProviderParameterQuery.lastCall.args[0], 'Ok', 'Parameter value');
|
|
611
|
-
},
|
|
612
|
-
});
|
|
613
|
-
FetchTest('MultiParameter (header)', {
|
|
614
|
-
route: '/execution/controller2/testProviderMultiParameterHeader',
|
|
615
|
-
method: 'GET',
|
|
616
|
-
status: 200,
|
|
617
|
-
prepare(init) {
|
|
618
|
-
init.headers = { key: ['Ok 1', 'Ok 2'] };
|
|
619
|
-
},
|
|
620
|
-
postCheck() {
|
|
621
|
-
assert_1.default.equal(TestExecutionController2.prototype.testProviderMultiParameterHeader.lastCall.args[0].toString(), ['Ok 1', 'Ok 2'].toString(), 'Parameter value');
|
|
622
|
-
},
|
|
623
|
-
});
|
|
624
|
-
FetchTest('MultiParameter (query)', {
|
|
625
|
-
route: '/execution/controller2/testProviderMultiParameterQuery?key=Ok1&key=Ok2',
|
|
626
|
-
method: 'GET',
|
|
627
|
-
status: 200,
|
|
628
|
-
postCheck() {
|
|
629
|
-
assert_1.default.equal(TestExecutionController2.prototype.testProviderMultiParameterQuery.lastCall.args[0].toString(), ['Ok1', 'Ok2'].toString(), 'Parameter value');
|
|
630
|
-
},
|
|
631
|
-
});
|
|
632
|
-
FetchTest('Result', {
|
|
633
|
-
route: '/execution/controller2/testProviderResult',
|
|
634
|
-
method: 'GET',
|
|
635
|
-
status: 200,
|
|
636
|
-
postCheck() {
|
|
637
|
-
const res = TestExecutionController2.prototype.testProviderResultPostfix.lastCall
|
|
638
|
-
.args[0];
|
|
639
|
-
(0, assert_1.default)(res instanceof beta_1.HTTPResult, 'HTTPResult object');
|
|
640
|
-
assert_1.default.equal(res.getBody(), 'Ok', 'HTTPResult value');
|
|
641
|
-
},
|
|
642
|
-
});
|
|
643
|
-
FetchTest('WriteStream', {
|
|
644
|
-
route: '/execution/controller2/testProviderWriteStream',
|
|
645
|
-
method: 'Get',
|
|
646
|
-
status: 200,
|
|
647
|
-
result: 'Ok',
|
|
648
|
-
postCheck() {
|
|
649
|
-
const res = TestExecutionController2.prototype.testProviderWriteStream.lastCall
|
|
650
|
-
.args[0];
|
|
651
|
-
(0, assert_1.default)(res instanceof stream_1.PassThrough, 'Stream object');
|
|
652
|
-
},
|
|
653
|
-
});
|
|
654
|
-
});
|
|
655
|
-
describe('Modifiers', () => {
|
|
656
|
-
FetchTest('Transform', {
|
|
657
|
-
route: '/execution/controller2/testModifierTransform',
|
|
658
|
-
method: 'GET',
|
|
659
|
-
status: 200,
|
|
660
|
-
postCheck() {
|
|
661
|
-
assert_1.default.equal(TestExecutionController2.prototype.testModifierTransform.lastCall.args[0], 'Ok', 'Parameter value');
|
|
662
|
-
},
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
describe('HTTPResult', () => {
|
|
666
|
-
FetchTest('Normal Return', { route: '/execution/controller3/test', method: 'GET', status: 200 });
|
|
667
|
-
FetchTest('Throw', { route: '/execution/controller3/testThrow', method: 'GET', status: 200 });
|
|
668
|
-
FetchTest('Status', { route: '/execution/controller3/testStatus', method: 'GET', status: 201 });
|
|
669
|
-
FetchTest('Header', {
|
|
670
|
-
route: '/execution/controller3/testHeader',
|
|
671
|
-
method: 'GET',
|
|
672
|
-
status: 200,
|
|
673
|
-
postCheck(res) {
|
|
674
|
-
assert_1.default.equal(res.headers.get('key'), 'Ok', 'Header value');
|
|
675
|
-
},
|
|
676
|
-
});
|
|
677
|
-
FetchTest('Body', { route: '/execution/controller3/testBody', method: 'GET', status: 200, result: 'Ok' });
|
|
678
|
-
FetchTest('Prefix/Postfix Consistency', {
|
|
679
|
-
route: '/execution/controller3/testConsistency',
|
|
680
|
-
method: 'GET',
|
|
681
|
-
status: 200,
|
|
682
|
-
result: 'Ok',
|
|
683
|
-
postCheck(res) {
|
|
684
|
-
assert_1.default.equal(res.headers.get('key1'), 'Ok', 'Prefix Header value');
|
|
685
|
-
assert_1.default.equal(res.headers.get('key2'), 'Ok', 'Handler Header value');
|
|
686
|
-
assert_1.default.equal(res.headers.get('key3'), 'Ok', 'Postfix Header value');
|
|
687
|
-
},
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
const testWSReceiver = sinon_1.default.spy();
|
|
692
|
-
let testWSSocket;
|
|
693
|
-
class TestWebsocketController1 extends (0, beta_1.Controller)('/websocket/controller1') {
|
|
694
|
-
test(connection) {
|
|
695
|
-
testWSSocket = connection;
|
|
696
|
-
connection.on('message', testWSReceiver);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
exports.TestWebsocketController1 = TestWebsocketController1;
|
|
700
|
-
__decorate([
|
|
701
|
-
(0, beta_1.WebsocketHandler)(),
|
|
702
|
-
SpyMethod(),
|
|
703
|
-
__param(0, (0, beta_1.Connection)()),
|
|
704
|
-
__metadata("design:type", Function),
|
|
705
|
-
__metadata("design:paramtypes", [ws_1.default]),
|
|
706
|
-
__metadata("design:returntype", void 0)
|
|
707
|
-
], TestWebsocketController1.prototype, "test", null);
|
|
708
|
-
describe('WebSocket', () => {
|
|
709
|
-
let ws;
|
|
710
|
-
const clientReceiver = sinon_1.default.spy();
|
|
711
|
-
after(() => ws && ws.close());
|
|
712
|
-
it('Connect', async () => {
|
|
713
|
-
ws = new ws_1.default(URL_BASE + '/websocket/controller1/test');
|
|
714
|
-
ws.on('message', clientReceiver);
|
|
715
|
-
await new Promise((resolve, reject) => {
|
|
716
|
-
ws.on('open', resolve);
|
|
717
|
-
ws.on('error', reject);
|
|
718
|
-
});
|
|
719
|
-
});
|
|
720
|
-
it('Client -> Server', async () => {
|
|
721
|
-
ws.send('Ok');
|
|
722
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
723
|
-
sinon_1.default.assert.calledOnce(testWSReceiver);
|
|
724
|
-
assert_1.default.equal(testWSReceiver.lastCall.firstArg.toString(), 'Ok');
|
|
725
|
-
});
|
|
726
|
-
it('Client <- Server', async () => {
|
|
727
|
-
testWSSocket.send('Ok');
|
|
728
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
729
|
-
sinon_1.default.assert.calledOnce(clientReceiver);
|
|
730
|
-
assert_1.default.equal(clientReceiver.lastCall.firstArg.toString(), 'Ok');
|
|
731
|
-
});
|
|
732
|
-
it('Close', async () => {
|
|
733
|
-
await new Promise((resolve) => {
|
|
734
|
-
ws.on('close', resolve);
|
|
735
|
-
testWSSocket.close();
|
|
736
|
-
});
|
|
737
|
-
});
|
|
738
|
-
});
|
|
739
|
-
//# sourceMappingURL=api.js.map
|