@e22m4u/ts-rest-router 0.0.5 → 0.0.6
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/package.json +3 -2
- package/tsconfig.json +2 -1
- package/dist/esm/controller-registry.spec.d.ts +0 -1
- package/dist/esm/controller-registry.spec.js +0 -719
- package/dist/esm/debuggable-service.spec.d.ts +0 -1
- package/dist/esm/debuggable-service.spec.js +0 -16
- package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@e22m4u/ts-rest-router",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"description": "Controllers-based REST router implementation for TypeScript",
|
5
5
|
"author": "e22m4u <e22m4u@yandex.ru>",
|
6
6
|
"keywords": [
|
@@ -31,6 +31,7 @@
|
|
31
31
|
"build:esm": "tsc --build",
|
32
32
|
"build:cjs": "rimraf ./dist/cjs && node --no-warnings=ExperimentalWarning build-cjs.js",
|
33
33
|
"build": "rimraf dist && npm run build:esm && npm run build:cjs",
|
34
|
+
"postbuild": "rimraf ./dist/**/*.spec.* --glob ./dist/tsconfig.tsbuildinfo",
|
34
35
|
"lint": "eslint ./src",
|
35
36
|
"lint:fix": "eslint ./src --fix",
|
36
37
|
"format": "prettier --write \"./src/**/*.ts\"",
|
@@ -40,7 +41,7 @@
|
|
40
41
|
},
|
41
42
|
"dependencies": {
|
42
43
|
"@e22m4u/js-format": "0.1.x",
|
43
|
-
"@e22m4u/js-service": "0.
|
44
|
+
"@e22m4u/js-service": "0.2.x",
|
44
45
|
"@e22m4u/js-trie-router": "0.0.x",
|
45
46
|
"@e22m4u/ts-data-schema": "0.0.x",
|
46
47
|
"@e22m4u/ts-reflector": "0.1.x",
|
package/tsconfig.json
CHANGED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,719 +0,0 @@
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
-
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;
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
-
};
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
-
};
|
10
|
-
import { expect } from 'chai';
|
11
|
-
import { get } from './decorators/index.js';
|
12
|
-
import { post } from './decorators/index.js';
|
13
|
-
import { HookName } from '@e22m4u/js-trie-router';
|
14
|
-
import { controller } from './decorators/index.js';
|
15
|
-
import { TrieRouter } from '@e22m4u/js-trie-router';
|
16
|
-
import { HttpMethod } from '@e22m4u/js-trie-router';
|
17
|
-
import { RouteRegistry } from '@e22m4u/js-trie-router';
|
18
|
-
import { createRequestMock } from '@e22m4u/js-trie-router';
|
19
|
-
import { ControllerReflector } from './decorators/index.js';
|
20
|
-
import { ControllerRegistry } from './controller-registry.js';
|
21
|
-
const PRE_HANDLER_1 = () => undefined;
|
22
|
-
const PRE_HANDLER_2 = () => undefined;
|
23
|
-
const PRE_HANDLER_3 = () => undefined;
|
24
|
-
const PRE_HANDLER_4 = () => undefined;
|
25
|
-
const POST_HANDLER_1 = () => undefined;
|
26
|
-
const POST_HANDLER_2 = () => undefined;
|
27
|
-
const POST_HANDLER_3 = () => undefined;
|
28
|
-
const POST_HANDLER_4 = () => undefined;
|
29
|
-
describe('ControllerRegistry', function () {
|
30
|
-
it('has a public property with set of controllers', function () {
|
31
|
-
const s = new ControllerRegistry();
|
32
|
-
expect(s).to.have.property('controllers');
|
33
|
-
expect(s.controllers).to.be.instanceof(Set);
|
34
|
-
});
|
35
|
-
describe('addController', function () {
|
36
|
-
it('returns itself', function () {
|
37
|
-
const s = new ControllerRegistry();
|
38
|
-
let MyController = class MyController {
|
39
|
-
};
|
40
|
-
MyController = __decorate([
|
41
|
-
controller()
|
42
|
-
], MyController);
|
43
|
-
const res = s.addController(MyController);
|
44
|
-
expect(res).to.be.eq(s);
|
45
|
-
});
|
46
|
-
it('adds a given controller to controllers set', function () {
|
47
|
-
const s = new ControllerRegistry();
|
48
|
-
let MyController = class MyController {
|
49
|
-
};
|
50
|
-
MyController = __decorate([
|
51
|
-
controller()
|
52
|
-
], MyController);
|
53
|
-
expect(s.hasController(MyController)).to.be.false;
|
54
|
-
s.addController(MyController);
|
55
|
-
expect(s.hasController(MyController)).to.be.true;
|
56
|
-
});
|
57
|
-
it('passes action method and path of a given controller to the route', function () {
|
58
|
-
const s = new ControllerRegistry();
|
59
|
-
let MyController = class MyController {
|
60
|
-
foo() { }
|
61
|
-
};
|
62
|
-
__decorate([
|
63
|
-
get('/myAction'),
|
64
|
-
__metadata("design:type", Function),
|
65
|
-
__metadata("design:paramtypes", []),
|
66
|
-
__metadata("design:returntype", void 0)
|
67
|
-
], MyController.prototype, "foo", null);
|
68
|
-
MyController = __decorate([
|
69
|
-
controller()
|
70
|
-
], MyController);
|
71
|
-
s.addController(MyController);
|
72
|
-
const reg = s.getService(TrieRouter).getService(RouteRegistry);
|
73
|
-
const req = createRequestMock({
|
74
|
-
method: HttpMethod.GET,
|
75
|
-
path: '/myAction',
|
76
|
-
});
|
77
|
-
const matching = reg.matchRouteByRequest(req);
|
78
|
-
expect(matching).to.be.not.empty;
|
79
|
-
expect(matching.route.method).to.be.eq(HttpMethod.GET);
|
80
|
-
expect(matching.route.path).to.be.eq('/myAction');
|
81
|
-
});
|
82
|
-
it('creates routes for multiple actions of a given controller', function () {
|
83
|
-
const s = new ControllerRegistry();
|
84
|
-
let MyController = class MyController {
|
85
|
-
foo() { }
|
86
|
-
bar() { }
|
87
|
-
};
|
88
|
-
__decorate([
|
89
|
-
get('/foo'),
|
90
|
-
__metadata("design:type", Function),
|
91
|
-
__metadata("design:paramtypes", []),
|
92
|
-
__metadata("design:returntype", void 0)
|
93
|
-
], MyController.prototype, "foo", null);
|
94
|
-
__decorate([
|
95
|
-
post('/bar'),
|
96
|
-
__metadata("design:type", Function),
|
97
|
-
__metadata("design:paramtypes", []),
|
98
|
-
__metadata("design:returntype", void 0)
|
99
|
-
], MyController.prototype, "bar", null);
|
100
|
-
MyController = __decorate([
|
101
|
-
controller()
|
102
|
-
], MyController);
|
103
|
-
s.addController(MyController);
|
104
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
105
|
-
const fooReq = createRequestMock({
|
106
|
-
method: HttpMethod.GET,
|
107
|
-
path: '/foo',
|
108
|
-
});
|
109
|
-
const fooMatching = routeReg.matchRouteByRequest(fooReq);
|
110
|
-
expect(fooMatching).to.be.not.empty;
|
111
|
-
const barReq = createRequestMock({
|
112
|
-
method: HttpMethod.POST,
|
113
|
-
path: '/bar',
|
114
|
-
});
|
115
|
-
const barMatching = routeReg.matchRouteByRequest(barReq);
|
116
|
-
expect(barMatching).to.be.not.empty;
|
117
|
-
});
|
118
|
-
describe('single pre-handler', function () {
|
119
|
-
it('passes pre-handler of a given options to the route', function () {
|
120
|
-
const s = new ControllerRegistry();
|
121
|
-
let MyController = class MyController {
|
122
|
-
myAction() { }
|
123
|
-
};
|
124
|
-
__decorate([
|
125
|
-
get('/myAction'),
|
126
|
-
__metadata("design:type", Function),
|
127
|
-
__metadata("design:paramtypes", []),
|
128
|
-
__metadata("design:returntype", void 0)
|
129
|
-
], MyController.prototype, "myAction", null);
|
130
|
-
MyController = __decorate([
|
131
|
-
controller()
|
132
|
-
], MyController);
|
133
|
-
s.addController(MyController, { before: PRE_HANDLER_1 });
|
134
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
135
|
-
const req = createRequestMock({
|
136
|
-
method: HttpMethod.GET,
|
137
|
-
path: '/myAction',
|
138
|
-
});
|
139
|
-
const matching = routeReg.matchRouteByRequest(req);
|
140
|
-
expect(matching).to.be.not.empty;
|
141
|
-
const res = matching.route.hookRegistry.getHooks(HookName.PRE_HANDLER);
|
142
|
-
expect(res).to.be.eql([PRE_HANDLER_1]);
|
143
|
-
});
|
144
|
-
it('passes pre-handler of a given controller to the route', function () {
|
145
|
-
const s = new ControllerRegistry();
|
146
|
-
let MyController = class MyController {
|
147
|
-
myAction() { }
|
148
|
-
};
|
149
|
-
__decorate([
|
150
|
-
get('/myAction'),
|
151
|
-
__metadata("design:type", Function),
|
152
|
-
__metadata("design:paramtypes", []),
|
153
|
-
__metadata("design:returntype", void 0)
|
154
|
-
], MyController.prototype, "myAction", null);
|
155
|
-
MyController = __decorate([
|
156
|
-
controller({ before: PRE_HANDLER_1 })
|
157
|
-
], MyController);
|
158
|
-
s.addController(MyController);
|
159
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
160
|
-
const req = createRequestMock({
|
161
|
-
method: HttpMethod.GET,
|
162
|
-
path: '/myAction',
|
163
|
-
});
|
164
|
-
const matching = routeReg.matchRouteByRequest(req);
|
165
|
-
expect(matching).to.be.not.empty;
|
166
|
-
const res = matching.route.hookRegistry.getHooks(HookName.PRE_HANDLER);
|
167
|
-
expect(res).to.be.eql([PRE_HANDLER_1]);
|
168
|
-
});
|
169
|
-
it('passes action pre-handler of a given controller to the route', function () {
|
170
|
-
const s = new ControllerRegistry();
|
171
|
-
let MyController = class MyController {
|
172
|
-
myAction() { }
|
173
|
-
};
|
174
|
-
__decorate([
|
175
|
-
get('/myAction', { before: PRE_HANDLER_1 }),
|
176
|
-
__metadata("design:type", Function),
|
177
|
-
__metadata("design:paramtypes", []),
|
178
|
-
__metadata("design:returntype", void 0)
|
179
|
-
], MyController.prototype, "myAction", null);
|
180
|
-
MyController = __decorate([
|
181
|
-
controller()
|
182
|
-
], MyController);
|
183
|
-
s.addController(MyController);
|
184
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
185
|
-
const req = createRequestMock({
|
186
|
-
method: HttpMethod.GET,
|
187
|
-
path: '/myAction',
|
188
|
-
});
|
189
|
-
const matching = routeReg.matchRouteByRequest(req);
|
190
|
-
expect(matching).to.be.not.empty;
|
191
|
-
const res = matching.route.hookRegistry.getHooks(HookName.PRE_HANDLER);
|
192
|
-
expect(res).to.be.eql([PRE_HANDLER_1]);
|
193
|
-
});
|
194
|
-
});
|
195
|
-
describe('multiple pre-handlers', function () {
|
196
|
-
it('passes pre-handlers of a given options to the route', function () {
|
197
|
-
const s = new ControllerRegistry();
|
198
|
-
let MyController = class MyController {
|
199
|
-
myAction() { }
|
200
|
-
};
|
201
|
-
__decorate([
|
202
|
-
get('/myAction'),
|
203
|
-
__metadata("design:type", Function),
|
204
|
-
__metadata("design:paramtypes", []),
|
205
|
-
__metadata("design:returntype", void 0)
|
206
|
-
], MyController.prototype, "myAction", null);
|
207
|
-
MyController = __decorate([
|
208
|
-
controller()
|
209
|
-
], MyController);
|
210
|
-
s.addController(MyController, {
|
211
|
-
before: [PRE_HANDLER_1, PRE_HANDLER_2],
|
212
|
-
});
|
213
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
214
|
-
const req = createRequestMock({
|
215
|
-
method: HttpMethod.GET,
|
216
|
-
path: '/myAction',
|
217
|
-
});
|
218
|
-
const matching = routeReg.matchRouteByRequest(req);
|
219
|
-
expect(matching).to.be.not.empty;
|
220
|
-
const res = matching.route.hookRegistry.getHooks(HookName.PRE_HANDLER);
|
221
|
-
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
222
|
-
});
|
223
|
-
it('passes pre-handlers of a given controller to the route', function () {
|
224
|
-
const s = new ControllerRegistry();
|
225
|
-
let MyController = class MyController {
|
226
|
-
myAction() { }
|
227
|
-
};
|
228
|
-
__decorate([
|
229
|
-
get('/myAction'),
|
230
|
-
__metadata("design:type", Function),
|
231
|
-
__metadata("design:paramtypes", []),
|
232
|
-
__metadata("design:returntype", void 0)
|
233
|
-
], MyController.prototype, "myAction", null);
|
234
|
-
MyController = __decorate([
|
235
|
-
controller({
|
236
|
-
before: [PRE_HANDLER_1, PRE_HANDLER_2],
|
237
|
-
})
|
238
|
-
], MyController);
|
239
|
-
s.addController(MyController);
|
240
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
241
|
-
const req = createRequestMock({
|
242
|
-
method: HttpMethod.GET,
|
243
|
-
path: '/myAction',
|
244
|
-
});
|
245
|
-
const matching = routeReg.matchRouteByRequest(req);
|
246
|
-
expect(matching).to.be.not.empty;
|
247
|
-
const res = matching.route.hookRegistry.getHooks(HookName.PRE_HANDLER);
|
248
|
-
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
249
|
-
});
|
250
|
-
it('passes action pre-handlers of a given controller to the route', function () {
|
251
|
-
const s = new ControllerRegistry();
|
252
|
-
let MyController = class MyController {
|
253
|
-
myAction() { }
|
254
|
-
};
|
255
|
-
__decorate([
|
256
|
-
get('/myAction', {
|
257
|
-
before: [PRE_HANDLER_1, PRE_HANDLER_2],
|
258
|
-
}),
|
259
|
-
__metadata("design:type", Function),
|
260
|
-
__metadata("design:paramtypes", []),
|
261
|
-
__metadata("design:returntype", void 0)
|
262
|
-
], MyController.prototype, "myAction", null);
|
263
|
-
MyController = __decorate([
|
264
|
-
controller()
|
265
|
-
], MyController);
|
266
|
-
s.addController(MyController);
|
267
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
268
|
-
const req = createRequestMock({
|
269
|
-
method: HttpMethod.GET,
|
270
|
-
path: '/myAction',
|
271
|
-
});
|
272
|
-
const matching = routeReg.matchRouteByRequest(req);
|
273
|
-
expect(matching).to.be.not.empty;
|
274
|
-
const res = matching.route.hookRegistry.getHooks(HookName.PRE_HANDLER);
|
275
|
-
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
276
|
-
});
|
277
|
-
});
|
278
|
-
describe('single post-handler', function () {
|
279
|
-
it('passes post-handler of a given options to the route', function () {
|
280
|
-
const s = new ControllerRegistry();
|
281
|
-
let MyController = class MyController {
|
282
|
-
myAction() { }
|
283
|
-
};
|
284
|
-
__decorate([
|
285
|
-
get('/myAction'),
|
286
|
-
__metadata("design:type", Function),
|
287
|
-
__metadata("design:paramtypes", []),
|
288
|
-
__metadata("design:returntype", void 0)
|
289
|
-
], MyController.prototype, "myAction", null);
|
290
|
-
MyController = __decorate([
|
291
|
-
controller()
|
292
|
-
], MyController);
|
293
|
-
s.addController(MyController, { after: POST_HANDLER_1 });
|
294
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
295
|
-
const req = createRequestMock({
|
296
|
-
method: HttpMethod.GET,
|
297
|
-
path: '/myAction',
|
298
|
-
});
|
299
|
-
const matching = routeReg.matchRouteByRequest(req);
|
300
|
-
expect(matching).to.be.not.empty;
|
301
|
-
const res = matching.route.hookRegistry.getHooks(HookName.POST_HANDLER);
|
302
|
-
expect(res).to.be.eql([POST_HANDLER_1]);
|
303
|
-
});
|
304
|
-
it('passes post-handler of a given controller to the route', function () {
|
305
|
-
const s = new ControllerRegistry();
|
306
|
-
let MyController = class MyController {
|
307
|
-
myAction() { }
|
308
|
-
};
|
309
|
-
__decorate([
|
310
|
-
get('/myAction'),
|
311
|
-
__metadata("design:type", Function),
|
312
|
-
__metadata("design:paramtypes", []),
|
313
|
-
__metadata("design:returntype", void 0)
|
314
|
-
], MyController.prototype, "myAction", null);
|
315
|
-
MyController = __decorate([
|
316
|
-
controller({ after: POST_HANDLER_1 })
|
317
|
-
], MyController);
|
318
|
-
s.addController(MyController);
|
319
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
320
|
-
const req = createRequestMock({
|
321
|
-
method: HttpMethod.GET,
|
322
|
-
path: '/myAction',
|
323
|
-
});
|
324
|
-
const matching = routeReg.matchRouteByRequest(req);
|
325
|
-
expect(matching).to.be.not.empty;
|
326
|
-
const res = matching.route.hookRegistry.getHooks(HookName.POST_HANDLER);
|
327
|
-
expect(res).to.be.eql([POST_HANDLER_1]);
|
328
|
-
});
|
329
|
-
it('passes action post-handler of a given controller to the route', function () {
|
330
|
-
const s = new ControllerRegistry();
|
331
|
-
let MyController = class MyController {
|
332
|
-
myAction() { }
|
333
|
-
};
|
334
|
-
__decorate([
|
335
|
-
get('/myAction', { after: POST_HANDLER_1 }),
|
336
|
-
__metadata("design:type", Function),
|
337
|
-
__metadata("design:paramtypes", []),
|
338
|
-
__metadata("design:returntype", void 0)
|
339
|
-
], MyController.prototype, "myAction", null);
|
340
|
-
MyController = __decorate([
|
341
|
-
controller()
|
342
|
-
], MyController);
|
343
|
-
s.addController(MyController);
|
344
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
345
|
-
const req = createRequestMock({
|
346
|
-
method: HttpMethod.GET,
|
347
|
-
path: '/myAction',
|
348
|
-
});
|
349
|
-
const matching = routeReg.matchRouteByRequest(req);
|
350
|
-
expect(matching).to.be.not.empty;
|
351
|
-
const res = matching.route.hookRegistry.getHooks(HookName.POST_HANDLER);
|
352
|
-
expect(res).to.be.eql([POST_HANDLER_1]);
|
353
|
-
});
|
354
|
-
});
|
355
|
-
describe('multiple post-handlers', function () {
|
356
|
-
it('passes post-handlers of a given options to the route', function () {
|
357
|
-
const s = new ControllerRegistry();
|
358
|
-
let MyController = class MyController {
|
359
|
-
myAction() { }
|
360
|
-
};
|
361
|
-
__decorate([
|
362
|
-
get('/myAction'),
|
363
|
-
__metadata("design:type", Function),
|
364
|
-
__metadata("design:paramtypes", []),
|
365
|
-
__metadata("design:returntype", void 0)
|
366
|
-
], MyController.prototype, "myAction", null);
|
367
|
-
MyController = __decorate([
|
368
|
-
controller()
|
369
|
-
], MyController);
|
370
|
-
s.addController(MyController, {
|
371
|
-
after: [POST_HANDLER_1, POST_HANDLER_2],
|
372
|
-
});
|
373
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
374
|
-
const req = createRequestMock({
|
375
|
-
method: HttpMethod.GET,
|
376
|
-
path: '/myAction',
|
377
|
-
});
|
378
|
-
const matching = routeReg.matchRouteByRequest(req);
|
379
|
-
expect(matching).to.be.not.empty;
|
380
|
-
const res = matching.route.hookRegistry.getHooks(HookName.POST_HANDLER);
|
381
|
-
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
382
|
-
});
|
383
|
-
it('passes post-handlers of a given controller to the route', function () {
|
384
|
-
const s = new ControllerRegistry();
|
385
|
-
let MyController = class MyController {
|
386
|
-
myAction() { }
|
387
|
-
};
|
388
|
-
__decorate([
|
389
|
-
get('/myAction'),
|
390
|
-
__metadata("design:type", Function),
|
391
|
-
__metadata("design:paramtypes", []),
|
392
|
-
__metadata("design:returntype", void 0)
|
393
|
-
], MyController.prototype, "myAction", null);
|
394
|
-
MyController = __decorate([
|
395
|
-
controller({
|
396
|
-
after: [POST_HANDLER_1, POST_HANDLER_2],
|
397
|
-
})
|
398
|
-
], MyController);
|
399
|
-
s.addController(MyController);
|
400
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
401
|
-
const req = createRequestMock({
|
402
|
-
method: HttpMethod.GET,
|
403
|
-
path: '/myAction',
|
404
|
-
});
|
405
|
-
const matching = routeReg.matchRouteByRequest(req);
|
406
|
-
expect(matching).to.be.not.empty;
|
407
|
-
const res = matching.route.hookRegistry.getHooks(HookName.POST_HANDLER);
|
408
|
-
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
409
|
-
});
|
410
|
-
it('passes action post-handlers of a given controller to the route', function () {
|
411
|
-
const s = new ControllerRegistry();
|
412
|
-
let MyController = class MyController {
|
413
|
-
myAction() { }
|
414
|
-
};
|
415
|
-
__decorate([
|
416
|
-
get('/myAction', {
|
417
|
-
after: [POST_HANDLER_1, POST_HANDLER_2],
|
418
|
-
}),
|
419
|
-
__metadata("design:type", Function),
|
420
|
-
__metadata("design:paramtypes", []),
|
421
|
-
__metadata("design:returntype", void 0)
|
422
|
-
], MyController.prototype, "myAction", null);
|
423
|
-
MyController = __decorate([
|
424
|
-
controller()
|
425
|
-
], MyController);
|
426
|
-
s.addController(MyController);
|
427
|
-
const routeReg = s.getService(TrieRouter).getService(RouteRegistry);
|
428
|
-
const req = createRequestMock({
|
429
|
-
method: HttpMethod.GET,
|
430
|
-
path: '/myAction',
|
431
|
-
});
|
432
|
-
const matching = routeReg.matchRouteByRequest(req);
|
433
|
-
expect(matching).to.be.not.empty;
|
434
|
-
const res = matching.route.hookRegistry.getHooks(HookName.POST_HANDLER);
|
435
|
-
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
436
|
-
});
|
437
|
-
});
|
438
|
-
});
|
439
|
-
describe('hasController', function () {
|
440
|
-
it('returns false if a given controller is not registered', function () {
|
441
|
-
const s = new ControllerRegistry();
|
442
|
-
let MyController = class MyController {
|
443
|
-
};
|
444
|
-
MyController = __decorate([
|
445
|
-
controller()
|
446
|
-
], MyController);
|
447
|
-
expect(s.hasController(MyController)).to.be.false;
|
448
|
-
});
|
449
|
-
it('returns true if a given controller is registered', function () {
|
450
|
-
const s = new ControllerRegistry();
|
451
|
-
let MyController = class MyController {
|
452
|
-
};
|
453
|
-
MyController = __decorate([
|
454
|
-
controller()
|
455
|
-
], MyController);
|
456
|
-
expect(s.hasController(MyController)).to.be.false;
|
457
|
-
s.addController(MyController);
|
458
|
-
expect(s.hasController(MyController)).to.be.true;
|
459
|
-
});
|
460
|
-
});
|
461
|
-
describe('getPathPrefixByControllerMetadata', function () {
|
462
|
-
it('returns an empty string if no prefix is specified', function () {
|
463
|
-
const s = new ControllerRegistry();
|
464
|
-
let MyController = class MyController {
|
465
|
-
};
|
466
|
-
MyController = __decorate([
|
467
|
-
controller()
|
468
|
-
], MyController);
|
469
|
-
const md = ControllerReflector.getMetadata(MyController);
|
470
|
-
const res = s.getPathPrefixByControllerMetadata(md);
|
471
|
-
expect(res).to.be.eq('');
|
472
|
-
});
|
473
|
-
it('returns controller path prefix that starts with slash', function () {
|
474
|
-
const s = new ControllerRegistry();
|
475
|
-
let MyController = class MyController {
|
476
|
-
};
|
477
|
-
MyController = __decorate([
|
478
|
-
controller({ path: 'myPrefix' })
|
479
|
-
], MyController);
|
480
|
-
const md = ControllerReflector.getMetadata(MyController);
|
481
|
-
const res = s.getPathPrefixByControllerMetadata(md);
|
482
|
-
expect(res).to.be.eq('/myPrefix');
|
483
|
-
});
|
484
|
-
it('returns path prefix from options that starts with slash', function () {
|
485
|
-
const s = new ControllerRegistry();
|
486
|
-
let MyController = class MyController {
|
487
|
-
};
|
488
|
-
MyController = __decorate([
|
489
|
-
controller()
|
490
|
-
], MyController);
|
491
|
-
const md = ControllerReflector.getMetadata(MyController);
|
492
|
-
const res = s.getPathPrefixByControllerMetadata(md, {
|
493
|
-
pathPrefix: 'myPrefix',
|
494
|
-
});
|
495
|
-
expect(res).to.be.eq('/myPrefix');
|
496
|
-
});
|
497
|
-
it('combines a path prefix from options and controller', function () {
|
498
|
-
const s = new ControllerRegistry();
|
499
|
-
let MyController = class MyController {
|
500
|
-
};
|
501
|
-
MyController = __decorate([
|
502
|
-
controller({ path: 'controller' })
|
503
|
-
], MyController);
|
504
|
-
const md = ControllerReflector.getMetadata(MyController);
|
505
|
-
const res = s.getPathPrefixByControllerMetadata(md, {
|
506
|
-
pathPrefix: 'root',
|
507
|
-
});
|
508
|
-
expect(res).to.be.eq('/root/controller');
|
509
|
-
});
|
510
|
-
});
|
511
|
-
describe('getPreHandlersByControllerMetadata', function () {
|
512
|
-
it('returns an empty array if no handlers are specified', function () {
|
513
|
-
const s = new ControllerRegistry();
|
514
|
-
let MyController = class MyController {
|
515
|
-
};
|
516
|
-
MyController = __decorate([
|
517
|
-
controller()
|
518
|
-
], MyController);
|
519
|
-
const md = ControllerReflector.getMetadata(MyController);
|
520
|
-
const res = s.getPreHandlersByControllerMetadata(md);
|
521
|
-
expect(res).to.be.eql([]);
|
522
|
-
});
|
523
|
-
describe('single handler', function () {
|
524
|
-
it('returns pre-handlers from a given controller', function () {
|
525
|
-
const s = new ControllerRegistry();
|
526
|
-
let MyController = class MyController {
|
527
|
-
};
|
528
|
-
MyController = __decorate([
|
529
|
-
controller({
|
530
|
-
before: PRE_HANDLER_1,
|
531
|
-
})
|
532
|
-
], MyController);
|
533
|
-
const md = ControllerReflector.getMetadata(MyController);
|
534
|
-
const res = s.getPreHandlersByControllerMetadata(md);
|
535
|
-
expect(res).to.be.eql([PRE_HANDLER_1]);
|
536
|
-
});
|
537
|
-
it('returns pre-handlers from a given options', function () {
|
538
|
-
const s = new ControllerRegistry();
|
539
|
-
let MyController = class MyController {
|
540
|
-
};
|
541
|
-
MyController = __decorate([
|
542
|
-
controller()
|
543
|
-
], MyController);
|
544
|
-
const md = ControllerReflector.getMetadata(MyController);
|
545
|
-
const res = s.getPreHandlersByControllerMetadata(md, {
|
546
|
-
before: PRE_HANDLER_1,
|
547
|
-
});
|
548
|
-
expect(res).to.be.eql([PRE_HANDLER_1]);
|
549
|
-
});
|
550
|
-
it('combines pre-handlers from a given options and controller', function () {
|
551
|
-
const s = new ControllerRegistry();
|
552
|
-
let MyController = class MyController {
|
553
|
-
};
|
554
|
-
MyController = __decorate([
|
555
|
-
controller({
|
556
|
-
before: PRE_HANDLER_2,
|
557
|
-
})
|
558
|
-
], MyController);
|
559
|
-
const md = ControllerReflector.getMetadata(MyController);
|
560
|
-
const res = s.getPreHandlersByControllerMetadata(md, {
|
561
|
-
before: PRE_HANDLER_1,
|
562
|
-
});
|
563
|
-
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
564
|
-
});
|
565
|
-
});
|
566
|
-
describe('multiple handlers', function () {
|
567
|
-
it('returns pre-handlers from a given controller', function () {
|
568
|
-
const s = new ControllerRegistry();
|
569
|
-
let MyController = class MyController {
|
570
|
-
};
|
571
|
-
MyController = __decorate([
|
572
|
-
controller({
|
573
|
-
before: [PRE_HANDLER_1, PRE_HANDLER_2],
|
574
|
-
})
|
575
|
-
], MyController);
|
576
|
-
const md = ControllerReflector.getMetadata(MyController);
|
577
|
-
const res = s.getPreHandlersByControllerMetadata(md);
|
578
|
-
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
579
|
-
});
|
580
|
-
it('returns pre-handlers from a given options', function () {
|
581
|
-
const s = new ControllerRegistry();
|
582
|
-
let MyController = class MyController {
|
583
|
-
};
|
584
|
-
MyController = __decorate([
|
585
|
-
controller()
|
586
|
-
], MyController);
|
587
|
-
const md = ControllerReflector.getMetadata(MyController);
|
588
|
-
const res = s.getPreHandlersByControllerMetadata(md, {
|
589
|
-
before: [PRE_HANDLER_1, PRE_HANDLER_2],
|
590
|
-
});
|
591
|
-
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
592
|
-
});
|
593
|
-
it('combines pre-handlers from a given options and controller', function () {
|
594
|
-
const s = new ControllerRegistry();
|
595
|
-
let MyController = class MyController {
|
596
|
-
};
|
597
|
-
MyController = __decorate([
|
598
|
-
controller({
|
599
|
-
before: [PRE_HANDLER_3, PRE_HANDLER_4],
|
600
|
-
})
|
601
|
-
], MyController);
|
602
|
-
const md = ControllerReflector.getMetadata(MyController);
|
603
|
-
const res = s.getPreHandlersByControllerMetadata(md, {
|
604
|
-
before: [PRE_HANDLER_1, PRE_HANDLER_2],
|
605
|
-
});
|
606
|
-
expect(res).to.be.eql([
|
607
|
-
PRE_HANDLER_1,
|
608
|
-
PRE_HANDLER_2,
|
609
|
-
PRE_HANDLER_3,
|
610
|
-
PRE_HANDLER_4,
|
611
|
-
]);
|
612
|
-
});
|
613
|
-
});
|
614
|
-
});
|
615
|
-
describe('getPostHandlersByControllerMetadata', function () {
|
616
|
-
it('returns an empty array if no handlers are specified', function () {
|
617
|
-
const s = new ControllerRegistry();
|
618
|
-
let MyController = class MyController {
|
619
|
-
};
|
620
|
-
MyController = __decorate([
|
621
|
-
controller()
|
622
|
-
], MyController);
|
623
|
-
const md = ControllerReflector.getMetadata(MyController);
|
624
|
-
const res = s.getPostHandlersByControllerMetadata(md);
|
625
|
-
expect(res).to.be.eql([]);
|
626
|
-
});
|
627
|
-
describe('single handler', function () {
|
628
|
-
it('returns pre-handlers from a given controller', function () {
|
629
|
-
const s = new ControllerRegistry();
|
630
|
-
let MyController = class MyController {
|
631
|
-
};
|
632
|
-
MyController = __decorate([
|
633
|
-
controller({
|
634
|
-
after: POST_HANDLER_1,
|
635
|
-
})
|
636
|
-
], MyController);
|
637
|
-
const md = ControllerReflector.getMetadata(MyController);
|
638
|
-
const res = s.getPostHandlersByControllerMetadata(md);
|
639
|
-
expect(res).to.be.eql([POST_HANDLER_1]);
|
640
|
-
});
|
641
|
-
it('returns pre-handlers from a given options', function () {
|
642
|
-
const s = new ControllerRegistry();
|
643
|
-
let MyController = class MyController {
|
644
|
-
};
|
645
|
-
MyController = __decorate([
|
646
|
-
controller()
|
647
|
-
], MyController);
|
648
|
-
const md = ControllerReflector.getMetadata(MyController);
|
649
|
-
const res = s.getPostHandlersByControllerMetadata(md, {
|
650
|
-
after: POST_HANDLER_1,
|
651
|
-
});
|
652
|
-
expect(res).to.be.eql([POST_HANDLER_1]);
|
653
|
-
});
|
654
|
-
it('combines pre-handlers from a given options and controller', function () {
|
655
|
-
const s = new ControllerRegistry();
|
656
|
-
let MyController = class MyController {
|
657
|
-
};
|
658
|
-
MyController = __decorate([
|
659
|
-
controller({
|
660
|
-
after: POST_HANDLER_2,
|
661
|
-
})
|
662
|
-
], MyController);
|
663
|
-
const md = ControllerReflector.getMetadata(MyController);
|
664
|
-
const res = s.getPostHandlersByControllerMetadata(md, {
|
665
|
-
after: POST_HANDLER_1,
|
666
|
-
});
|
667
|
-
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
668
|
-
});
|
669
|
-
});
|
670
|
-
describe('multiple handlers', function () {
|
671
|
-
it('returns pre-handlers from a given controller', function () {
|
672
|
-
const s = new ControllerRegistry();
|
673
|
-
let MyController = class MyController {
|
674
|
-
};
|
675
|
-
MyController = __decorate([
|
676
|
-
controller({
|
677
|
-
after: [POST_HANDLER_1, POST_HANDLER_2],
|
678
|
-
})
|
679
|
-
], MyController);
|
680
|
-
const md = ControllerReflector.getMetadata(MyController);
|
681
|
-
const res = s.getPostHandlersByControllerMetadata(md);
|
682
|
-
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
683
|
-
});
|
684
|
-
it('returns pre-handlers from a given options', function () {
|
685
|
-
const s = new ControllerRegistry();
|
686
|
-
let MyController = class MyController {
|
687
|
-
};
|
688
|
-
MyController = __decorate([
|
689
|
-
controller()
|
690
|
-
], MyController);
|
691
|
-
const md = ControllerReflector.getMetadata(MyController);
|
692
|
-
const res = s.getPostHandlersByControllerMetadata(md, {
|
693
|
-
after: [POST_HANDLER_1, POST_HANDLER_2],
|
694
|
-
});
|
695
|
-
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
696
|
-
});
|
697
|
-
it('combines pre-handlers from a given options and controller', function () {
|
698
|
-
const s = new ControllerRegistry();
|
699
|
-
let MyController = class MyController {
|
700
|
-
};
|
701
|
-
MyController = __decorate([
|
702
|
-
controller({
|
703
|
-
after: [POST_HANDLER_3, POST_HANDLER_4],
|
704
|
-
})
|
705
|
-
], MyController);
|
706
|
-
const md = ControllerReflector.getMetadata(MyController);
|
707
|
-
const res = s.getPostHandlersByControllerMetadata(md, {
|
708
|
-
after: [POST_HANDLER_1, POST_HANDLER_2],
|
709
|
-
});
|
710
|
-
expect(res).to.be.eql([
|
711
|
-
POST_HANDLER_1,
|
712
|
-
POST_HANDLER_2,
|
713
|
-
POST_HANDLER_3,
|
714
|
-
POST_HANDLER_4,
|
715
|
-
]);
|
716
|
-
});
|
717
|
-
});
|
718
|
-
});
|
719
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { expect } from 'chai';
|
2
|
-
import { describe } from 'mocha';
|
3
|
-
import { Service } from '@e22m4u/js-service';
|
4
|
-
import { DebuggableService } from './debuggable-service.js';
|
5
|
-
describe('DebuggableService', function () {
|
6
|
-
it('has the debug method', function () {
|
7
|
-
const res = new DebuggableService();
|
8
|
-
expect(typeof res.debug).to.be.eq('function');
|
9
|
-
});
|
10
|
-
describe('constructor', function () {
|
11
|
-
it('extends the Service class', function () {
|
12
|
-
const res = new DebuggableService();
|
13
|
-
expect(res).to.be.instanceof(Service);
|
14
|
-
});
|
15
|
-
});
|
16
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
{"root":["../src/controller-registry.spec.ts","../src/controller-registry.ts","../src/debuggable-service.spec.ts","../src/debuggable-service.ts","../src/index.ts","../src/rest-router.ts","../src/types.ts","../src/decorators/index.ts","../src/decorators/action/action-decorator.spec.ts","../src/decorators/action/action-decorator.ts","../src/decorators/action/action-metadata.ts","../src/decorators/action/action-reflector.spec.ts","../src/decorators/action/action-reflector.ts","../src/decorators/action/index.ts","../src/decorators/controller/controller-decorator.spec.ts","../src/decorators/controller/controller-decorator.ts","../src/decorators/controller/controller-metadata.ts","../src/decorators/controller/controller-reflector.spec.ts","../src/decorators/controller/controller-reflector.ts","../src/decorators/controller/index.ts","../src/decorators/request-context/index.ts","../src/decorators/request-context/request-context-decorator.spec.ts","../src/decorators/request-context/request-context-decorator.ts","../src/decorators/request-context/request-context-metadata.ts","../src/decorators/request-context/request-context-reflector.spec.ts","../src/decorators/request-context/request-context-reflector.ts","../src/decorators/request-data/index.ts","../src/decorators/request-data/request-data-decorator.spec.ts","../src/decorators/request-data/request-data-decorator.ts","../src/decorators/request-data/request-data-metadata.ts","../src/decorators/request-data/request-data-reflector.spec.ts","../src/decorators/request-data/request-data-reflector.ts","../src/errors/index.ts","../src/errors/not-a-controller-error.ts","../src/utils/capitalize.spec.ts","../src/utils/capitalize.ts","../src/utils/create-debugger.spec.ts","../src/utils/create-debugger.ts","../src/utils/create-error.spec.ts","../src/utils/create-error.ts","../src/utils/index.ts","../src/utils/to-camel-case.spec.ts","../src/utils/to-camel-case.ts"],"version":"5.6.3"}
|