@e22m4u/ts-rest-router 0.6.4 → 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.
@@ -68,9 +68,6 @@ __export(index_exports, {
68
68
  });
69
69
  module.exports = __toCommonJS(index_exports);
70
70
 
71
- // dist/esm/rest-router.js
72
- var import_js_trie_router3 = require("@e22m4u/js-trie-router");
73
-
74
71
  // dist/esm/debuggable-service.js
75
72
  var import_js_service = require("@e22m4u/js-service");
76
73
  var _DebuggableService = class _DebuggableService extends import_js_service.DebuggableService {
@@ -89,6 +86,9 @@ var _DebuggableService = class _DebuggableService extends import_js_service.Debu
89
86
  __name(_DebuggableService, "DebuggableService");
90
87
  var DebuggableService = _DebuggableService;
91
88
 
89
+ // dist/esm/rest-router.js
90
+ var import_js_trie_router3 = require("@e22m4u/js-trie-router");
91
+
92
92
  // dist/esm/controller-registry.js
93
93
  var import_js_format2 = require("@e22m4u/js-format");
94
94
  var import_js_trie_router2 = require("@e22m4u/js-trie-router");
@@ -1,7 +1,6 @@
1
1
  import { Constructor } from './types.js';
2
- import { HookType } from '@e22m4u/js-trie-router';
3
- import { RouterHook } from '@e22m4u/js-trie-router';
4
2
  import { DebuggableService } from './debuggable-service.js';
3
+ import { RouterHookType, PostHandlerHook, PreHandlerHook } from '@e22m4u/js-trie-router';
5
4
  import { ControllerRootOptions } from './controller-registry.js';
6
5
  /**
7
6
  * Rest router.
@@ -24,5 +23,12 @@ export declare class RestRouter extends DebuggableService {
24
23
  * @param type
25
24
  * @param hook
26
25
  */
27
- addHook(type: HookType, hook: RouterHook): this;
26
+ addHook(type: typeof RouterHookType.PRE_HANDLER, hook: PreHandlerHook): this;
27
+ /**
28
+ * Add hook.
29
+ *
30
+ * @param type
31
+ * @param hook
32
+ */
33
+ addHook(type: typeof RouterHookType.POST_HANDLER, hook: PostHandlerHook): this;
28
34
  }
@@ -1,6 +1,6 @@
1
- import { TrieRouter } from '@e22m4u/js-trie-router';
2
1
  import { DebuggableService } from './debuggable-service.js';
3
- import { ControllerRegistry } from './controller-registry.js';
2
+ import { TrieRouter, } from '@e22m4u/js-trie-router';
3
+ import { ControllerRegistry, } from './controller-registry.js';
4
4
  /**
5
5
  * Rest router.
6
6
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e22m4u/ts-rest-router",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "Декларативный REST-маршрутизатор на основе контроллеров для TypeScript",
5
5
  "author": "Mikhail Evstropov <e22m4u@yandex.ru>",
6
6
  "license": "MIT",
@@ -41,27 +41,27 @@
41
41
  "prepare": "husky"
42
42
  },
43
43
  "dependencies": {
44
- "@e22m4u/js-debug": "~0.3.1",
45
- "@e22m4u/js-format": "~0.2.0",
46
- "@e22m4u/js-service": "~0.4.3",
47
- "@e22m4u/js-trie-router": "~0.3.2",
48
44
  "@e22m4u/js-data-schema": "~0.4.6",
45
+ "@e22m4u/js-debug": "~0.3.2",
46
+ "@e22m4u/js-format": "~0.2.0",
47
+ "@e22m4u/js-service": "~0.4.4",
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
  },
52
52
  "devDependencies": {
53
53
  "@commitlint/cli": "~20.1.0",
54
54
  "@commitlint/config-conventional": "~20.0.0",
55
- "@eslint/js": "~9.37.0",
56
- "@types/chai": "~5.2.2",
55
+ "@eslint/js": "~9.38.0",
56
+ "@types/chai": "~5.2.3",
57
57
  "@types/debug": "~4.1.12",
58
58
  "@types/http-errors": "~2.0.5",
59
59
  "@types/mocha": "~10.0.10",
60
- "@types/node": "~24.7.2",
60
+ "@types/node": "~24.9.2",
61
61
  "c8": "~10.1.3",
62
62
  "chai": "~6.2.0",
63
- "esbuild": "~0.25.10",
64
- "eslint": "~9.37.0",
63
+ "esbuild": "~0.25.11",
64
+ "eslint": "~9.38.0",
65
65
  "eslint-config-prettier": "~10.1.8",
66
66
  "eslint-plugin-chai-expect": "~3.1.0",
67
67
  "eslint-plugin-mocha": "~11.2.0",
@@ -71,6 +71,6 @@
71
71
  "rimraf": "~6.0.1",
72
72
  "tsx": "~4.20.6",
73
73
  "typescript": "~5.9.3",
74
- "typescript-eslint": "~8.46.1"
74
+ "typescript-eslint": "~8.46.2"
75
75
  }
76
76
  }
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  createRequestMock,
4
4
  createResponseMock,
5
- HookType,
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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(HookType.PRE_HANDLER);
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
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
- HookType.POST_HANDLER,
611
+ RouterHookType.POST_HANDLER,
592
612
  );
593
613
  expect(res).to.be.eql([POST_HANDLER_1, POST_HANDLER_2]);
594
614
  });
@@ -1,10 +1,18 @@
1
1
  import {Constructor} from './types.js';
2
- import {HookType} from '@e22m4u/js-trie-router';
3
- import {RouterHook} from '@e22m4u/js-trie-router';
4
- import {TrieRouter} from '@e22m4u/js-trie-router';
5
2
  import {DebuggableService} from './debuggable-service.js';
6
- import {ControllerRegistry} from './controller-registry.js';
7
- import {ControllerRootOptions} from './controller-registry.js';
3
+
4
+ import {
5
+ TrieRouter,
6
+ RouterHook,
7
+ RouterHookType,
8
+ PostHandlerHook,
9
+ PreHandlerHook,
10
+ } from '@e22m4u/js-trie-router';
11
+
12
+ import {
13
+ ControllerRegistry,
14
+ ControllerRootOptions,
15
+ } from './controller-registry.js';
8
16
 
9
17
  /**
10
18
  * Rest router.
@@ -37,7 +45,26 @@ export class RestRouter extends DebuggableService {
37
45
  * @param type
38
46
  * @param hook
39
47
  */
40
- addHook(type: HookType, hook: RouterHook) {
48
+ addHook(type: typeof RouterHookType.PRE_HANDLER, hook: PreHandlerHook): this;
49
+
50
+ /**
51
+ * Add hook.
52
+ *
53
+ * @param type
54
+ * @param hook
55
+ */
56
+ addHook(
57
+ type: typeof RouterHookType.POST_HANDLER,
58
+ hook: PostHandlerHook,
59
+ ): this;
60
+
61
+ /**
62
+ * Add hook.
63
+ *
64
+ * @param type
65
+ * @param hook
66
+ */
67
+ addHook(type: RouterHookType, hook: RouterHook) {
41
68
  this.getService(TrieRouter).addHook(type, hook);
42
69
  return this;
43
70
  }