@e22m4u/ts-rest-router 0.6.5 → 0.6.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Constructor } from './types.js';
|
|
2
2
|
import { DebuggableService } from './debuggable-service.js';
|
|
3
|
-
import {
|
|
3
|
+
import { RouterHookType, PostHandlerHook, PreHandlerHook } from '@e22m4u/js-trie-router';
|
|
4
4
|
import { ControllerRootOptions } from './controller-registry.js';
|
|
5
5
|
/**
|
|
6
6
|
* Rest router.
|
|
@@ -23,12 +23,12 @@ export declare class RestRouter extends DebuggableService {
|
|
|
23
23
|
* @param type
|
|
24
24
|
* @param hook
|
|
25
25
|
*/
|
|
26
|
-
addHook(type: typeof
|
|
26
|
+
addHook(type: typeof RouterHookType.PRE_HANDLER, hook: PreHandlerHook): this;
|
|
27
27
|
/**
|
|
28
28
|
* Add hook.
|
|
29
29
|
*
|
|
30
30
|
* @param type
|
|
31
31
|
* @param hook
|
|
32
32
|
*/
|
|
33
|
-
addHook(type: typeof
|
|
33
|
+
addHook(type: typeof RouterHookType.POST_HANDLER, hook: PostHandlerHook): this;
|
|
34
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/ts-rest-router",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "Декларативный REST-маршрутизатор на основе контроллеров для TypeScript",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@e22m4u/js-debug": "~0.3.2",
|
|
46
46
|
"@e22m4u/js-format": "~0.2.0",
|
|
47
47
|
"@e22m4u/js-service": "~0.4.4",
|
|
48
|
-
"@e22m4u/js-trie-router": "~0.3.
|
|
48
|
+
"@e22m4u/js-trie-router": "~0.3.4",
|
|
49
49
|
"@e22m4u/ts-reflector": "~0.1.8",
|
|
50
50
|
"http-errors": "~2.0.0"
|
|
51
51
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createRequestMock,
|
|
4
4
|
createResponseMock,
|
|
5
|
-
|
|
5
|
+
RouterHookType,
|
|
6
6
|
HttpMethod,
|
|
7
7
|
ParsedCookies,
|
|
8
8
|
ParsedHeaders,
|
|
@@ -182,7 +182,9 @@ describe('ControllerRegistry', function () {
|
|
|
182
182
|
});
|
|
183
183
|
const matching = routeReg.matchRouteByRequest(req);
|
|
184
184
|
expect(matching).to.be.not.empty;
|
|
185
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
185
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
186
|
+
RouterHookType.PRE_HANDLER,
|
|
187
|
+
);
|
|
186
188
|
expect(res).to.be.eql([PRE_HANDLER_1]);
|
|
187
189
|
});
|
|
188
190
|
|
|
@@ -202,7 +204,9 @@ describe('ControllerRegistry', function () {
|
|
|
202
204
|
});
|
|
203
205
|
const matching = routeReg.matchRouteByRequest(req);
|
|
204
206
|
expect(matching).to.be.not.empty;
|
|
205
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
207
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
208
|
+
RouterHookType.PRE_HANDLER,
|
|
209
|
+
);
|
|
206
210
|
expect(res).to.be.eql([PRE_HANDLER_1]);
|
|
207
211
|
});
|
|
208
212
|
|
|
@@ -222,7 +226,9 @@ describe('ControllerRegistry', function () {
|
|
|
222
226
|
});
|
|
223
227
|
const matching = routeReg.matchRouteByRequest(req);
|
|
224
228
|
expect(matching).to.be.not.empty;
|
|
225
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
229
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
230
|
+
RouterHookType.PRE_HANDLER,
|
|
231
|
+
);
|
|
226
232
|
expect(res).to.be.eql([PRE_HANDLER_1]);
|
|
227
233
|
});
|
|
228
234
|
|
|
@@ -241,7 +247,9 @@ describe('ControllerRegistry', function () {
|
|
|
241
247
|
});
|
|
242
248
|
const matching = routeReg.matchRouteByRequest(req);
|
|
243
249
|
expect(matching).to.be.not.empty;
|
|
244
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
250
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
251
|
+
RouterHookType.PRE_HANDLER,
|
|
252
|
+
);
|
|
245
253
|
expect(res).to.be.eql([PRE_HANDLER_1]);
|
|
246
254
|
});
|
|
247
255
|
|
|
@@ -260,7 +268,9 @@ describe('ControllerRegistry', function () {
|
|
|
260
268
|
});
|
|
261
269
|
const matching = routeReg.matchRouteByRequest(req);
|
|
262
270
|
expect(matching).to.be.not.empty;
|
|
263
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
271
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
272
|
+
RouterHookType.PRE_HANDLER,
|
|
273
|
+
);
|
|
264
274
|
expect(res).to.be.eql([PRE_HANDLER_1]);
|
|
265
275
|
});
|
|
266
276
|
});
|
|
@@ -283,7 +293,9 @@ describe('ControllerRegistry', function () {
|
|
|
283
293
|
});
|
|
284
294
|
const matching = routeReg.matchRouteByRequest(req);
|
|
285
295
|
expect(matching).to.be.not.empty;
|
|
286
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
296
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
297
|
+
RouterHookType.PRE_HANDLER,
|
|
298
|
+
);
|
|
287
299
|
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
|
288
300
|
});
|
|
289
301
|
|
|
@@ -303,7 +315,9 @@ describe('ControllerRegistry', function () {
|
|
|
303
315
|
});
|
|
304
316
|
const matching = routeReg.matchRouteByRequest(req);
|
|
305
317
|
expect(matching).to.be.not.empty;
|
|
306
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
318
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
319
|
+
RouterHookType.PRE_HANDLER,
|
|
320
|
+
);
|
|
307
321
|
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
|
308
322
|
});
|
|
309
323
|
|
|
@@ -323,7 +337,9 @@ describe('ControllerRegistry', function () {
|
|
|
323
337
|
});
|
|
324
338
|
const matching = routeReg.matchRouteByRequest(req);
|
|
325
339
|
expect(matching).to.be.not.empty;
|
|
326
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
340
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
341
|
+
RouterHookType.PRE_HANDLER,
|
|
342
|
+
);
|
|
327
343
|
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
|
328
344
|
});
|
|
329
345
|
|
|
@@ -344,7 +360,9 @@ describe('ControllerRegistry', function () {
|
|
|
344
360
|
});
|
|
345
361
|
const matching = routeReg.matchRouteByRequest(req);
|
|
346
362
|
expect(matching).to.be.not.empty;
|
|
347
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
363
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
364
|
+
RouterHookType.PRE_HANDLER,
|
|
365
|
+
);
|
|
348
366
|
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
|
349
367
|
});
|
|
350
368
|
|
|
@@ -365,7 +383,9 @@ describe('ControllerRegistry', function () {
|
|
|
365
383
|
});
|
|
366
384
|
const matching = routeReg.matchRouteByRequest(req);
|
|
367
385
|
expect(matching).to.be.not.empty;
|
|
368
|
-
const res = matching!.route.hookRegistry.getHooks(
|
|
386
|
+
const res = matching!.route.hookRegistry.getHooks(
|
|
387
|
+
RouterHookType.PRE_HANDLER,
|
|
388
|
+
);
|
|
369
389
|
expect(res).to.be.eql([PRE_HANDLER_1, PRE_HANDLER_2]);
|
|
370
390
|
});
|
|
371
391
|
});
|
|
@@ -387,7 +407,7 @@ describe('ControllerRegistry', function () {
|
|
|
387
407
|
const matching = routeReg.matchRouteByRequest(req);
|
|
388
408
|
expect(matching).to.be.not.empty;
|
|
389
409
|
const res = matching!.route.hookRegistry.getHooks(
|
|
390
|
-
|
|
410
|
+
RouterHookType.POST_HANDLER,
|
|
391
411
|
);
|
|
392
412
|
expect(res).to.be.eql([POST_HANDLER_1]);
|
|
393
413
|
});
|
|
@@ -409,7 +429,7 @@ describe('ControllerRegistry', function () {
|
|
|
409
429
|
const matching = routeReg.matchRouteByRequest(req);
|
|
410
430
|
expect(matching).to.be.not.empty;
|
|
411
431
|
const res = matching!.route.hookRegistry.getHooks(
|
|
412
|
-
|
|
432
|
+
RouterHookType.POST_HANDLER,
|
|
413
433
|
);
|
|
414
434
|
expect(res).to.be.eql([POST_HANDLER_1]);
|
|
415
435
|
});
|
|
@@ -431,7 +451,7 @@ describe('ControllerRegistry', function () {
|
|
|
431
451
|
const matching = routeReg.matchRouteByRequest(req);
|
|
432
452
|
expect(matching).to.be.not.empty;
|
|
433
453
|
const res = matching!.route.hookRegistry.getHooks(
|
|
434
|
-
|
|
454
|
+
RouterHookType.POST_HANDLER,
|
|
435
455
|
);
|
|
436
456
|
expect(res).to.be.eql([POST_HANDLER_1]);
|
|
437
457
|
});
|
|
@@ -452,7 +472,7 @@ describe('ControllerRegistry', function () {
|
|
|
452
472
|
const matching = routeReg.matchRouteByRequest(req);
|
|
453
473
|
expect(matching).to.be.not.empty;
|
|
454
474
|
const res = matching!.route.hookRegistry.getHooks(
|
|
455
|
-
|
|
475
|
+
RouterHookType.POST_HANDLER,
|
|
456
476
|
);
|
|
457
477
|
expect(res).to.be.eql([POST_HANDLER_1]);
|
|
458
478
|
});
|
|
@@ -473,7 +493,7 @@ describe('ControllerRegistry', function () {
|
|
|
473
493
|
const matching = routeReg.matchRouteByRequest(req);
|
|
474
494
|
expect(matching).to.be.not.empty;
|
|
475
495
|
const res = matching!.route.hookRegistry.getHooks(
|
|
476
|
-
|
|
496
|
+
RouterHookType.POST_HANDLER,
|
|
477
497
|
);
|
|
478
498
|
expect(res).to.be.eql([POST_HANDLER_1]);
|
|
479
499
|
});
|
|
@@ -498,7 +518,7 @@ describe('ControllerRegistry', function () {
|
|
|
498
518
|
const matching = routeReg.matchRouteByRequest(req);
|
|
499
519
|
expect(matching).to.be.not.empty;
|
|
500
520
|
const res = matching!.route.hookRegistry.getHooks(
|
|
501
|
-
|
|
521
|
+
RouterHookType.POST_HANDLER,
|
|
502
522
|
);
|
|
503
523
|
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
|
504
524
|
});
|
|
@@ -520,7 +540,7 @@ describe('ControllerRegistry', function () {
|
|
|
520
540
|
const matching = routeReg.matchRouteByRequest(req);
|
|
521
541
|
expect(matching).to.be.not.empty;
|
|
522
542
|
const res = matching!.route.hookRegistry.getHooks(
|
|
523
|
-
|
|
543
|
+
RouterHookType.POST_HANDLER,
|
|
524
544
|
);
|
|
525
545
|
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
|
526
546
|
});
|
|
@@ -542,7 +562,7 @@ describe('ControllerRegistry', function () {
|
|
|
542
562
|
const matching = routeReg.matchRouteByRequest(req);
|
|
543
563
|
expect(matching).to.be.not.empty;
|
|
544
564
|
const res = matching!.route.hookRegistry.getHooks(
|
|
545
|
-
|
|
565
|
+
RouterHookType.POST_HANDLER,
|
|
546
566
|
);
|
|
547
567
|
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
|
548
568
|
});
|
|
@@ -565,7 +585,7 @@ describe('ControllerRegistry', function () {
|
|
|
565
585
|
const matching = routeReg.matchRouteByRequest(req);
|
|
566
586
|
expect(matching).to.be.not.empty;
|
|
567
587
|
const res = matching!.route.hookRegistry.getHooks(
|
|
568
|
-
|
|
588
|
+
RouterHookType.POST_HANDLER,
|
|
569
589
|
);
|
|
570
590
|
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
|
571
591
|
});
|
|
@@ -588,7 +608,7 @@ describe('ControllerRegistry', function () {
|
|
|
588
608
|
const matching = routeReg.matchRouteByRequest(req);
|
|
589
609
|
expect(matching).to.be.not.empty;
|
|
590
610
|
const res = matching!.route.hookRegistry.getHooks(
|
|
591
|
-
|
|
611
|
+
RouterHookType.POST_HANDLER,
|
|
592
612
|
);
|
|
593
613
|
expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
|
|
594
614
|
});
|
package/src/rest-router.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {DebuggableService} from './debuggable-service.js';
|
|
|
4
4
|
import {
|
|
5
5
|
TrieRouter,
|
|
6
6
|
RouterHook,
|
|
7
|
-
|
|
7
|
+
RouterHookType,
|
|
8
8
|
PostHandlerHook,
|
|
9
9
|
PreHandlerHook,
|
|
10
10
|
} from '@e22m4u/js-trie-router';
|
|
@@ -45,7 +45,7 @@ export class RestRouter extends DebuggableService {
|
|
|
45
45
|
* @param type
|
|
46
46
|
* @param hook
|
|
47
47
|
*/
|
|
48
|
-
addHook(type: typeof
|
|
48
|
+
addHook(type: typeof RouterHookType.PRE_HANDLER, hook: PreHandlerHook): this;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Add hook.
|
|
@@ -53,7 +53,10 @@ export class RestRouter extends DebuggableService {
|
|
|
53
53
|
* @param type
|
|
54
54
|
* @param hook
|
|
55
55
|
*/
|
|
56
|
-
addHook(
|
|
56
|
+
addHook(
|
|
57
|
+
type: typeof RouterHookType.POST_HANDLER,
|
|
58
|
+
hook: PostHandlerHook,
|
|
59
|
+
): this;
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* Add hook.
|
|
@@ -61,7 +64,7 @@ export class RestRouter extends DebuggableService {
|
|
|
61
64
|
* @param type
|
|
62
65
|
* @param hook
|
|
63
66
|
*/
|
|
64
|
-
addHook(type:
|
|
67
|
+
addHook(type: RouterHookType, hook: RouterHook) {
|
|
65
68
|
this.getService(TrieRouter).addHook(type, hook);
|
|
66
69
|
return this;
|
|
67
70
|
}
|