@bepalo/spine 1.1.8 → 1.2.10

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.
Files changed (42) hide show
  1. package/README.md +84 -5
  2. package/dist/auth-middlewares.d.ts +2 -2
  3. package/dist/auth-middlewares.js +2 -2
  4. package/dist/cjs/auth-middlewares.d.ts +2 -2
  5. package/dist/cjs/auth-middlewares.js +2 -2
  6. package/dist/cjs/generator.d.ts +4 -0
  7. package/dist/cjs/generator.d.ts.map +1 -0
  8. package/dist/cjs/generator.js +166 -0
  9. package/dist/cjs/generator.js.map +1 -0
  10. package/dist/cjs/index.d.ts +1 -0
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +1 -0
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/middlewares.d.ts +1 -1
  15. package/dist/cjs/middlewares.js +1 -1
  16. package/dist/cjs/router.d.ts +80 -73
  17. package/dist/cjs/router.d.ts.map +1 -1
  18. package/dist/cjs/router.js +279 -278
  19. package/dist/cjs/router.js.map +1 -1
  20. package/dist/cjs/types.d.ts +6 -2
  21. package/dist/cjs/types.d.ts.map +1 -1
  22. package/dist/cjs/types.js +1 -1
  23. package/dist/cjs/types.js.map +1 -1
  24. package/dist/generator.d.ts +4 -0
  25. package/dist/generator.d.ts.map +1 -0
  26. package/dist/generator.js +166 -0
  27. package/dist/generator.js.map +1 -0
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/middlewares.d.ts +1 -1
  33. package/dist/middlewares.js +1 -1
  34. package/dist/router.d.ts +80 -73
  35. package/dist/router.d.ts.map +1 -1
  36. package/dist/router.js +279 -278
  37. package/dist/router.js.map +1 -1
  38. package/dist/types.d.ts +6 -2
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/types.js +1 -1
  41. package/dist/types.js.map +1 -1
  42. package/package.json +1 -1
@@ -26,16 +26,16 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
26
26
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
27
27
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
28
28
  };
29
- var _Router_instances, _Router_config, _Router_routes, _Router_register, _Router_processPath, _Router_getRouteEntries, _Router_InitEntries, _Router_initRoutes;
29
+ var _Router_instances, _Router_config, _Router_routes, _Router_processPath, _Router_getRouteEntries, _Router_InitEntries, _Router_initRoutes;
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.Router = exports.HANDLER_TYPES = exports.HTTP_METHODS_UPPER = exports.CRUD_METHODS = exports.HTTP_METHODS = void 0;
31
+ exports.Router = exports.HANDLER_TYPES = exports.HTTP_METHODS_UPPER = exports.CRUD_METHODS = exports.HTTP_METHODS = exports.REGISTER_PATH_REGEX = exports.PATH_PART_REGEX = void 0;
32
32
  const status_ts_1 = require("./status.js");
33
33
  const types_ts_1 = require("./types.js");
34
34
  const utils_node_ts_1 = require("./utils.node.js");
35
35
  const EMPTY_PARAMS = Object.freeze({});
36
36
  const W = "[\\p{L}\\p{M}\\p{N}\\p{S}\\p{P}_\\-.]";
37
- const PATH_PART_REGEX = new RegExp(`^(?:#?${W}+|\\[(?:${W}*|#{1,2}|##\\s*${W}*\\s*|\\[##\\s*${W}*\\s*\\]|\\[${W}*(?:,${W}*)*\\](?:\\s*${W}*\\s*|\\[\\s*${W}*\\s*\\]))\\])$`, "u");
38
- const REGISTER_PATH_REGEX = new RegExp(`^(?:/(?:${W}*|${W}*(?:\\|${W}*)*:${W}*|\\*))+|(?:/${W}*)*(?:/\\.?\\*\\*)|(?:/${W}*)*(?:/::${W}*)$`, "u");
37
+ exports.PATH_PART_REGEX = new RegExp(`^(?:#?${W}+|\\[(?:${W}*|#{1,2}|##\\s*${W}*\\s*|\\[##\\s*${W}*\\s*\\]|\\[${W}*(?:,${W}*)*\\](?:\\s*${W}*\\s*|\\[\\s*${W}*\\s*\\]))\\])$`, "u");
38
+ exports.REGISTER_PATH_REGEX = new RegExp(`^(?:/(?:${W}*|${W}*(?:\\|${W}*)*:${W}*|\\*))+|(?:/${W}*)*(?:/\\.?\\*\\*)|(?:/${W}*)*(?:/::${W}*)$`, "u");
39
39
  exports.HTTP_METHODS = new Set([
40
40
  "Head",
41
41
  "Get",
@@ -170,7 +170,7 @@ class Router {
170
170
  const params = routeEntry.parseParams(pathname, parts);
171
171
  ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
172
172
  // call request handlers
173
- for (const handler of routeEntry.pipeline) {
173
+ for (const handler of routeEntry.pipe) {
174
174
  const resp = yield handler.apply(this, [ctx]);
175
175
  if (resp instanceof Response) {
176
176
  response = resp;
@@ -203,7 +203,7 @@ class Router {
203
203
  const params = routeEntry.parseParams(pathname, parts);
204
204
  ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
205
205
  // call request handlers
206
- for (const handler of routeEntry.pipeline) {
206
+ for (const handler of routeEntry.pipe) {
207
207
  const resp = yield handler(ctx);
208
208
  if (resp instanceof Response) {
209
209
  response = resp;
@@ -231,7 +231,7 @@ class Router {
231
231
  const params = routeEntry.parseParams(pathname, parts);
232
232
  ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
233
233
  // call request handlers
234
- for (const handler of routeEntry.pipeline) {
234
+ for (const handler of routeEntry.pipe) {
235
235
  const resp = yield handler(ctx);
236
236
  if (resp instanceof Response) {
237
237
  response = resp;
@@ -292,7 +292,7 @@ class Router {
292
292
  const params = routeEntry.parseParams(url.pathname, parts);
293
293
  ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
294
294
  // call request handlers
295
- for (const handler of routeEntry.pipeline) {
295
+ for (const handler of routeEntry.pipe) {
296
296
  const resp = yield handler(ctx);
297
297
  if (resp instanceof Response) {
298
298
  response = resp;
@@ -343,7 +343,7 @@ class Router {
343
343
  ctx.params = params !== null && params !== void 0 ? params : EMPTY_PARAMS;
344
344
  ctx.response = response;
345
345
  // call request handlers
346
- for (const handler of routeEntry.pipeline) {
346
+ for (const handler of routeEntry.pipe) {
347
347
  const resp = yield handler(ctx);
348
348
  if (resp instanceof Response) {
349
349
  response = resp;
@@ -423,21 +423,21 @@ class Router {
423
423
  }
424
424
  }
425
425
  const definition = Array.isArray(_definition) || typeof _definition === "function"
426
- ? { pipeline: _definition }
426
+ ? { pipe: _definition }
427
427
  : {
428
- pipeline: _definition.pipeline,
428
+ pipe: _definition.pipe,
429
429
  openApi: _definition.openApi,
430
430
  };
431
- const pipeline = definition.pipeline;
431
+ const pipe = definition.pipe;
432
432
  const openApi = definition.openApi;
433
433
  if (openApi != null && handlerType !== "handler") {
434
434
  console.warn(`OpenApi definition will be ignored in '${node.path}' ${_method}`);
435
435
  }
436
- if (pipeline == null) {
437
- throw new types_ts_1.RouterError(`Undefined pipeline in '${node.path}' ${_method}`);
436
+ if (pipe == null) {
437
+ throw new types_ts_1.RouterError(`Undefined pipe in '${node.path}' ${_method}`);
438
438
  }
439
- if (!Array.isArray(pipeline) && typeof pipeline !== "function") {
440
- throw new types_ts_1.RouterError(`Bad pipeline type in '${node.path}' ${_method}`);
439
+ if (!Array.isArray(pipe) && typeof pipe !== "function") {
440
+ throw new types_ts_1.RouterError(`Bad pipe type in '${node.path}' ${_method}`);
441
441
  }
442
442
  if (openApi != null && typeof openApi !== "object") {
443
443
  throw new types_ts_1.RouterError(`Bad openApi type in '${node.path}' ${_method}`);
@@ -445,8 +445,8 @@ class Router {
445
445
  const options = handlerType === "handler" && openApi != null
446
446
  ? { openApi }
447
447
  : undefined;
448
- if (Array.isArray(pipeline) || typeof pipeline === "function") {
449
- __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, handlerType, `${method} ${path}`, pipeline, options);
448
+ if (Array.isArray(pipe) || typeof pipe === "function") {
449
+ this.register(handlerType, `${method} ${path}`, pipe, options);
450
450
  }
451
451
  }
452
452
  }
@@ -524,7 +524,7 @@ class Router {
524
524
  });
525
525
  });
526
526
  }
527
- all(paths, pipeline, options) {
527
+ all(paths, pipe, options) {
528
528
  paths = Array.isArray(paths) ? paths : [paths];
529
529
  const methodPaths = [];
530
530
  for (const p of paths) {
@@ -532,9 +532,9 @@ class Router {
532
532
  methodPaths.push(`${method} ${p}`);
533
533
  }
534
534
  }
535
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
535
+ return this.register("handler", methodPaths, pipe, options);
536
536
  }
537
- crud(paths, pipeline, options) {
537
+ crud(paths, pipe, options) {
538
538
  paths = Array.isArray(paths) ? paths : [paths];
539
539
  const methodPaths = [];
540
540
  for (const p of paths) {
@@ -542,54 +542,54 @@ class Router {
542
542
  methodPaths.push(`${method} ${p}`);
543
543
  }
544
544
  }
545
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
545
+ return this.register("handler", methodPaths, pipe, options);
546
546
  }
547
- head(paths, pipeline, options) {
547
+ head(paths, pipe, options) {
548
548
  paths = Array.isArray(paths) ? paths : [paths];
549
549
  const methodPaths = paths.map((p) => `Head ${p}`);
550
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
550
+ return this.register("handler", methodPaths, pipe, options);
551
551
  }
552
- get(paths, pipeline, options) {
552
+ get(paths, pipe, options) {
553
553
  paths = Array.isArray(paths) ? paths : [paths];
554
554
  const methodPaths = paths.map((p) => `Get ${p}`);
555
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
555
+ return this.register("handler", methodPaths, pipe, options);
556
556
  }
557
- post(paths, pipeline, options) {
557
+ post(paths, pipe, options) {
558
558
  paths = Array.isArray(paths) ? paths : [paths];
559
559
  const methodPaths = paths.map((p) => `Post ${p}`);
560
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
560
+ return this.register("handler", methodPaths, pipe, options);
561
561
  }
562
- put(paths, pipeline, options) {
562
+ put(paths, pipe, options) {
563
563
  paths = Array.isArray(paths) ? paths : [paths];
564
564
  const methodPaths = paths.map((p) => `Put ${p}`);
565
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
565
+ return this.register("handler", methodPaths, pipe, options);
566
566
  }
567
- patch(paths, pipeline, options) {
567
+ patch(paths, pipe, options) {
568
568
  paths = Array.isArray(paths) ? paths : [paths];
569
569
  const methodPaths = paths.map((p) => `Patch ${p}`);
570
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
570
+ return this.register("handler", methodPaths, pipe, options);
571
571
  }
572
- delete(paths, pipeline, options) {
572
+ delete(paths, pipe, options) {
573
573
  paths = Array.isArray(paths) ? paths : [paths];
574
574
  const methodPaths = paths.map((p) => `Delete ${p}`);
575
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
575
+ return this.register("handler", methodPaths, pipe, options);
576
576
  }
577
- options(paths, pipeline, options) {
577
+ options(paths, pipe, options) {
578
578
  paths = Array.isArray(paths) ? paths : [paths];
579
579
  const methodPaths = paths.map((p) => `Options ${p}`);
580
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
580
+ return this.register("handler", methodPaths, pipe, options);
581
581
  }
582
- trace(paths, pipeline, options) {
582
+ trace(paths, pipe, options) {
583
583
  paths = Array.isArray(paths) ? paths : [paths];
584
584
  const methodPaths = paths.map((p) => `Trace ${p}`);
585
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
585
+ return this.register("handler", methodPaths, pipe, options);
586
586
  }
587
- connect(paths, pipeline, options) {
587
+ connect(paths, pipe, options) {
588
588
  paths = Array.isArray(paths) ? paths : [paths];
589
589
  const methodPaths = paths.map((p) => `Connect ${p}`);
590
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
590
+ return this.register("handler", methodPaths, pipe, options);
591
591
  }
592
- filterAll(paths, pipeline, options) {
592
+ filterAll(paths, pipe, options) {
593
593
  paths = Array.isArray(paths) ? paths : [paths];
594
594
  const methodPaths = [];
595
595
  for (const p of paths) {
@@ -597,9 +597,9 @@ class Router {
597
597
  methodPaths.push(`${method} ${p}`);
598
598
  }
599
599
  }
600
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
600
+ return this.register("filter", methodPaths, pipe, options);
601
601
  }
602
- filterCrud(paths, pipeline, options) {
602
+ filterCrud(paths, pipe, options) {
603
603
  paths = Array.isArray(paths) ? paths : [paths];
604
604
  const methodPaths = [];
605
605
  for (const p of paths) {
@@ -607,54 +607,54 @@ class Router {
607
607
  methodPaths.push(`${method} ${p}`);
608
608
  }
609
609
  }
610
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
610
+ return this.register("filter", methodPaths, pipe, options);
611
611
  }
612
- filterHead(paths, pipeline, options) {
612
+ filterHead(paths, pipe, options) {
613
613
  paths = Array.isArray(paths) ? paths : [paths];
614
614
  const methodPaths = paths.map((p) => `Head ${p}`);
615
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
615
+ return this.register("filter", methodPaths, pipe, options);
616
616
  }
617
- filterGet(paths, pipeline, options) {
617
+ filterGet(paths, pipe, options) {
618
618
  paths = Array.isArray(paths) ? paths : [paths];
619
619
  const methodPaths = paths.map((p) => `Get ${p}`);
620
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
620
+ return this.register("filter", methodPaths, pipe, options);
621
621
  }
622
- filterPost(paths, pipeline, options) {
622
+ filterPost(paths, pipe, options) {
623
623
  paths = Array.isArray(paths) ? paths : [paths];
624
624
  const methodPaths = paths.map((p) => `Post ${p}`);
625
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
625
+ return this.register("filter", methodPaths, pipe, options);
626
626
  }
627
- filterPut(paths, pipeline, options) {
627
+ filterPut(paths, pipe, options) {
628
628
  paths = Array.isArray(paths) ? paths : [paths];
629
629
  const methodPaths = paths.map((p) => `Put ${p}`);
630
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
630
+ return this.register("filter", methodPaths, pipe, options);
631
631
  }
632
- filterPatch(paths, pipeline, options) {
632
+ filterPatch(paths, pipe, options) {
633
633
  paths = Array.isArray(paths) ? paths : [paths];
634
634
  const methodPaths = paths.map((p) => `Patch ${p}`);
635
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
635
+ return this.register("filter", methodPaths, pipe, options);
636
636
  }
637
- filterDelete(paths, pipeline, options) {
637
+ filterDelete(paths, pipe, options) {
638
638
  paths = Array.isArray(paths) ? paths : [paths];
639
639
  const methodPaths = paths.map((p) => `Delete ${p}`);
640
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
640
+ return this.register("filter", methodPaths, pipe, options);
641
641
  }
642
- filterOptions(paths, pipeline, options) {
642
+ filterOptions(paths, pipe, options) {
643
643
  paths = Array.isArray(paths) ? paths : [paths];
644
644
  const methodPaths = paths.map((p) => `Options ${p}`);
645
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
645
+ return this.register("filter", methodPaths, pipe, options);
646
646
  }
647
- filterTrace(paths, pipeline, options) {
647
+ filterTrace(paths, pipe, options) {
648
648
  paths = Array.isArray(paths) ? paths : [paths];
649
649
  const methodPaths = paths.map((p) => `Trace ${p}`);
650
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
650
+ return this.register("filter", methodPaths, pipe, options);
651
651
  }
652
- filterConnect(paths, pipeline, options) {
652
+ filterConnect(paths, pipe, options) {
653
653
  paths = Array.isArray(paths) ? paths : [paths];
654
654
  const methodPaths = paths.map((p) => `Connect ${p}`);
655
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
655
+ return this.register("filter", methodPaths, pipe, options);
656
656
  }
657
- handleAll(paths, pipeline, options) {
657
+ handleAll(paths, pipe, options) {
658
658
  paths = Array.isArray(paths) ? paths : [paths];
659
659
  const methodPaths = [];
660
660
  for (const p of paths) {
@@ -662,9 +662,9 @@ class Router {
662
662
  methodPaths.push(`${method} ${p}`);
663
663
  }
664
664
  }
665
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
665
+ return this.register("handler", methodPaths, pipe, options);
666
666
  }
667
- handleCrud(paths, pipeline, options) {
667
+ handleCrud(paths, pipe, options) {
668
668
  paths = Array.isArray(paths) ? paths : [paths];
669
669
  const methodPaths = [];
670
670
  for (const p of paths) {
@@ -672,54 +672,54 @@ class Router {
672
672
  methodPaths.push(`${method} ${p}`);
673
673
  }
674
674
  }
675
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
675
+ return this.register("handler", methodPaths, pipe, options);
676
676
  }
677
- handleHead(paths, pipeline, options) {
677
+ handleHead(paths, pipe, options) {
678
678
  paths = Array.isArray(paths) ? paths : [paths];
679
679
  const methodPaths = paths.map((p) => `Head ${p}`);
680
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
680
+ return this.register("handler", methodPaths, pipe, options);
681
681
  }
682
- handleGet(paths, pipeline, options) {
682
+ handleGet(paths, pipe, options) {
683
683
  paths = Array.isArray(paths) ? paths : [paths];
684
684
  const methodPaths = paths.map((p) => `Get ${p}`);
685
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
685
+ return this.register("handler", methodPaths, pipe, options);
686
686
  }
687
- handlePost(paths, pipeline, options) {
687
+ handlePost(paths, pipe, options) {
688
688
  paths = Array.isArray(paths) ? paths : [paths];
689
689
  const methodPaths = paths.map((p) => `Post ${p}`);
690
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
690
+ return this.register("handler", methodPaths, pipe, options);
691
691
  }
692
- handlePut(paths, pipeline, options) {
692
+ handlePut(paths, pipe, options) {
693
693
  paths = Array.isArray(paths) ? paths : [paths];
694
694
  const methodPaths = paths.map((p) => `Put ${p}`);
695
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
695
+ return this.register("handler", methodPaths, pipe, options);
696
696
  }
697
- handlePatch(paths, pipeline, options) {
697
+ handlePatch(paths, pipe, options) {
698
698
  paths = Array.isArray(paths) ? paths : [paths];
699
699
  const methodPaths = paths.map((p) => `Patch ${p}`);
700
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
700
+ return this.register("handler", methodPaths, pipe, options);
701
701
  }
702
- handleDelete(paths, pipeline, options) {
702
+ handleDelete(paths, pipe, options) {
703
703
  paths = Array.isArray(paths) ? paths : [paths];
704
704
  const methodPaths = paths.map((p) => `Delete ${p}`);
705
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
705
+ return this.register("handler", methodPaths, pipe, options);
706
706
  }
707
- handleOptions(paths, pipeline, options) {
707
+ handleOptions(paths, pipe, options) {
708
708
  paths = Array.isArray(paths) ? paths : [paths];
709
709
  const methodPaths = paths.map((p) => `Options ${p}`);
710
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
710
+ return this.register("handler", methodPaths, pipe, options);
711
711
  }
712
- handleTrace(paths, pipeline, options) {
712
+ handleTrace(paths, pipe, options) {
713
713
  paths = Array.isArray(paths) ? paths : [paths];
714
714
  const methodPaths = paths.map((p) => `Trace ${p}`);
715
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
715
+ return this.register("handler", methodPaths, pipe, options);
716
716
  }
717
- handleConnect(paths, pipeline, options) {
717
+ handleConnect(paths, pipe, options) {
718
718
  paths = Array.isArray(paths) ? paths : [paths];
719
719
  const methodPaths = paths.map((p) => `Connect ${p}`);
720
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
720
+ return this.register("handler", methodPaths, pipe, options);
721
721
  }
722
- fallbackAll(paths, pipeline, options) {
722
+ fallbackAll(paths, pipe, options) {
723
723
  paths = Array.isArray(paths) ? paths : [paths];
724
724
  const methodPaths = [];
725
725
  for (const p of paths) {
@@ -727,9 +727,9 @@ class Router {
727
727
  methodPaths.push(`${method} ${p}`);
728
728
  }
729
729
  }
730
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
730
+ return this.register("fallback", methodPaths, pipe, options);
731
731
  }
732
- fallbackCrud(paths, pipeline, options) {
732
+ fallbackCrud(paths, pipe, options) {
733
733
  paths = Array.isArray(paths) ? paths : [paths];
734
734
  const methodPaths = [];
735
735
  for (const p of paths) {
@@ -737,54 +737,54 @@ class Router {
737
737
  methodPaths.push(`${method} ${p}`);
738
738
  }
739
739
  }
740
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
740
+ return this.register("fallback", methodPaths, pipe, options);
741
741
  }
742
- fallbackHead(paths, pipeline, options) {
742
+ fallbackHead(paths, pipe, options) {
743
743
  paths = Array.isArray(paths) ? paths : [paths];
744
744
  const methodPaths = paths.map((p) => `Head ${p}`);
745
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
745
+ return this.register("fallback", methodPaths, pipe, options);
746
746
  }
747
- fallbackGet(paths, pipeline, options) {
747
+ fallbackGet(paths, pipe, options) {
748
748
  paths = Array.isArray(paths) ? paths : [paths];
749
749
  const methodPaths = paths.map((p) => `Get ${p}`);
750
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
750
+ return this.register("fallback", methodPaths, pipe, options);
751
751
  }
752
- fallbackPost(paths, pipeline, options) {
752
+ fallbackPost(paths, pipe, options) {
753
753
  paths = Array.isArray(paths) ? paths : [paths];
754
754
  const methodPaths = paths.map((p) => `Post ${p}`);
755
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
755
+ return this.register("fallback", methodPaths, pipe, options);
756
756
  }
757
- fallbackPut(paths, pipeline, options) {
757
+ fallbackPut(paths, pipe, options) {
758
758
  paths = Array.isArray(paths) ? paths : [paths];
759
759
  const methodPaths = paths.map((p) => `Put ${p}`);
760
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
760
+ return this.register("fallback", methodPaths, pipe, options);
761
761
  }
762
- fallbackPatch(paths, pipeline, options) {
762
+ fallbackPatch(paths, pipe, options) {
763
763
  paths = Array.isArray(paths) ? paths : [paths];
764
764
  const methodPaths = paths.map((p) => `Patch ${p}`);
765
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
765
+ return this.register("fallback", methodPaths, pipe, options);
766
766
  }
767
- fallbackDelete(paths, pipeline, options) {
767
+ fallbackDelete(paths, pipe, options) {
768
768
  paths = Array.isArray(paths) ? paths : [paths];
769
769
  const methodPaths = paths.map((p) => `Delete ${p}`);
770
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
770
+ return this.register("fallback", methodPaths, pipe, options);
771
771
  }
772
- fallbackOptions(paths, pipeline, options) {
772
+ fallbackOptions(paths, pipe, options) {
773
773
  paths = Array.isArray(paths) ? paths : [paths];
774
774
  const methodPaths = paths.map((p) => `Options ${p}`);
775
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
775
+ return this.register("fallback", methodPaths, pipe, options);
776
776
  }
777
- fallbackTrace(paths, pipeline, options) {
777
+ fallbackTrace(paths, pipe, options) {
778
778
  paths = Array.isArray(paths) ? paths : [paths];
779
779
  const methodPaths = paths.map((p) => `Trace ${p}`);
780
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
780
+ return this.register("fallback", methodPaths, pipe, options);
781
781
  }
782
- fallbackConnect(paths, pipeline, options) {
782
+ fallbackConnect(paths, pipe, options) {
783
783
  paths = Array.isArray(paths) ? paths : [paths];
784
784
  const methodPaths = paths.map((p) => `Connect ${p}`);
785
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
785
+ return this.register("fallback", methodPaths, pipe, options);
786
786
  }
787
- afterAll(paths, pipeline, options) {
787
+ afterAll(paths, pipe, options) {
788
788
  paths = Array.isArray(paths) ? paths : [paths];
789
789
  const methodPaths = [];
790
790
  for (const p of paths) {
@@ -792,9 +792,9 @@ class Router {
792
792
  methodPaths.push(`${method} ${p}`);
793
793
  }
794
794
  }
795
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
795
+ return this.register("after", methodPaths, pipe, options);
796
796
  }
797
- afterCrud(paths, pipeline, options) {
797
+ afterCrud(paths, pipe, options) {
798
798
  paths = Array.isArray(paths) ? paths : [paths];
799
799
  const methodPaths = [];
800
800
  for (const p of paths) {
@@ -802,54 +802,54 @@ class Router {
802
802
  methodPaths.push(`${method} ${p}`);
803
803
  }
804
804
  }
805
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
805
+ return this.register("after", methodPaths, pipe, options);
806
806
  }
807
- afterHead(paths, pipeline, options) {
807
+ afterHead(paths, pipe, options) {
808
808
  paths = Array.isArray(paths) ? paths : [paths];
809
809
  const methodPaths = paths.map((p) => `Head ${p}`);
810
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
810
+ return this.register("after", methodPaths, pipe, options);
811
811
  }
812
- afterGet(paths, pipeline, options) {
812
+ afterGet(paths, pipe, options) {
813
813
  paths = Array.isArray(paths) ? paths : [paths];
814
814
  const methodPaths = paths.map((p) => `Get ${p}`);
815
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
815
+ return this.register("after", methodPaths, pipe, options);
816
816
  }
817
- afterPost(paths, pipeline, options) {
817
+ afterPost(paths, pipe, options) {
818
818
  paths = Array.isArray(paths) ? paths : [paths];
819
819
  const methodPaths = paths.map((p) => `Post ${p}`);
820
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
820
+ return this.register("after", methodPaths, pipe, options);
821
821
  }
822
- afterPut(paths, pipeline, options) {
822
+ afterPut(paths, pipe, options) {
823
823
  paths = Array.isArray(paths) ? paths : [paths];
824
824
  const methodPaths = paths.map((p) => `Put ${p}`);
825
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
825
+ return this.register("after", methodPaths, pipe, options);
826
826
  }
827
- afterPatch(paths, pipeline, options) {
827
+ afterPatch(paths, pipe, options) {
828
828
  paths = Array.isArray(paths) ? paths : [paths];
829
829
  const methodPaths = paths.map((p) => `Patch ${p}`);
830
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
830
+ return this.register("after", methodPaths, pipe, options);
831
831
  }
832
- afterDelete(paths, pipeline, options) {
832
+ afterDelete(paths, pipe, options) {
833
833
  paths = Array.isArray(paths) ? paths : [paths];
834
834
  const methodPaths = paths.map((p) => `Delete ${p}`);
835
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
835
+ return this.register("after", methodPaths, pipe, options);
836
836
  }
837
- afterOptions(paths, pipeline, options) {
837
+ afterOptions(paths, pipe, options) {
838
838
  paths = Array.isArray(paths) ? paths : [paths];
839
839
  const methodPaths = paths.map((p) => `Options ${p}`);
840
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
840
+ return this.register("after", methodPaths, pipe, options);
841
841
  }
842
- afterTrace(paths, pipeline, options) {
842
+ afterTrace(paths, pipe, options) {
843
843
  paths = Array.isArray(paths) ? paths : [paths];
844
844
  const methodPaths = paths.map((p) => `Trace ${p}`);
845
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
845
+ return this.register("after", methodPaths, pipe, options);
846
846
  }
847
- afterConnect(paths, pipeline, options) {
847
+ afterConnect(paths, pipe, options) {
848
848
  paths = Array.isArray(paths) ? paths : [paths];
849
849
  const methodPaths = paths.map((p) => `Connect ${p}`);
850
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
850
+ return this.register("after", methodPaths, pipe, options);
851
851
  }
852
- catchAll(paths, pipeline, options) {
852
+ catchAll(paths, pipe, options) {
853
853
  paths = Array.isArray(paths) ? paths : [paths];
854
854
  const methodPaths = [];
855
855
  for (const p of paths) {
@@ -857,9 +857,9 @@ class Router {
857
857
  methodPaths.push(`${method} ${p}`);
858
858
  }
859
859
  }
860
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
860
+ return this.register("catcher", methodPaths, pipe, options);
861
861
  }
862
- catchCrud(paths, pipeline, options) {
862
+ catchCrud(paths, pipe, options) {
863
863
  paths = Array.isArray(paths) ? paths : [paths];
864
864
  const methodPaths = [];
865
865
  for (const p of paths) {
@@ -867,67 +867,179 @@ class Router {
867
867
  methodPaths.push(`${method} ${p}`);
868
868
  }
869
869
  }
870
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
870
+ return this.register("catcher", methodPaths, pipe, options);
871
871
  }
872
- catchHead(paths, pipeline, options) {
872
+ catchHead(paths, pipe, options) {
873
873
  paths = Array.isArray(paths) ? paths : [paths];
874
874
  const methodPaths = paths.map((p) => `Head ${p}`);
875
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
875
+ return this.register("catcher", methodPaths, pipe, options);
876
876
  }
877
- catchGet(paths, pipeline, options) {
877
+ catchGet(paths, pipe, options) {
878
878
  paths = Array.isArray(paths) ? paths : [paths];
879
879
  const methodPaths = paths.map((p) => `Get ${p}`);
880
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
880
+ return this.register("catcher", methodPaths, pipe, options);
881
881
  }
882
- catchPost(paths, pipeline, options) {
882
+ catchPost(paths, pipe, options) {
883
883
  paths = Array.isArray(paths) ? paths : [paths];
884
884
  const methodPaths = paths.map((p) => `Post ${p}`);
885
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
885
+ return this.register("catcher", methodPaths, pipe, options);
886
886
  }
887
- catchPut(paths, pipeline, options) {
887
+ catchPut(paths, pipe, options) {
888
888
  paths = Array.isArray(paths) ? paths : [paths];
889
889
  const methodPaths = paths.map((p) => `Put ${p}`);
890
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
890
+ return this.register("catcher", methodPaths, pipe, options);
891
891
  }
892
- catchPatch(paths, pipeline, options) {
892
+ catchPatch(paths, pipe, options) {
893
893
  paths = Array.isArray(paths) ? paths : [paths];
894
894
  const methodPaths = paths.map((p) => `Patch ${p}`);
895
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
895
+ return this.register("catcher", methodPaths, pipe, options);
896
896
  }
897
- catchDelete(paths, pipeline, options) {
897
+ catchDelete(paths, pipe, options) {
898
898
  paths = Array.isArray(paths) ? paths : [paths];
899
899
  const methodPaths = paths.map((p) => `Delete ${p}`);
900
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
900
+ return this.register("catcher", methodPaths, pipe, options);
901
901
  }
902
- catchOptions(paths, pipeline, options) {
902
+ catchOptions(paths, pipe, options) {
903
903
  paths = Array.isArray(paths) ? paths : [paths];
904
904
  const methodPaths = paths.map((p) => `Options ${p}`);
905
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
905
+ return this.register("catcher", methodPaths, pipe, options);
906
906
  }
907
- catchTrace(paths, pipeline, options) {
907
+ catchTrace(paths, pipe, options) {
908
908
  paths = Array.isArray(paths) ? paths : [paths];
909
909
  const methodPaths = paths.map((p) => `Trace ${p}`);
910
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
910
+ return this.register("catcher", methodPaths, pipe, options);
911
911
  }
912
- catchConnect(paths, pipeline, options) {
912
+ catchConnect(paths, pipe, options) {
913
913
  paths = Array.isArray(paths) ? paths : [paths];
914
914
  const methodPaths = paths.map((p) => `Connect ${p}`);
915
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
916
- }
917
- filter(methodPaths, pipeline, options) {
918
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "filter", methodPaths, pipeline, options);
919
- }
920
- handle(methodPaths, pipeline, options) {
921
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "handler", methodPaths, pipeline, options);
922
- }
923
- fallback(methodPaths, pipeline, options) {
924
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "fallback", methodPaths, pipeline, options);
925
- }
926
- after(methodPaths, pipeline, options) {
927
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "after", methodPaths, pipeline, options);
928
- }
929
- catch(methodPaths, pipeline, options) {
930
- return __classPrivateFieldGet(this, _Router_instances, "m", _Router_register).call(this, "catcher", methodPaths, pipeline, options);
915
+ return this.register("catcher", methodPaths, pipe, options);
916
+ }
917
+ filter(methodPaths, pipe, options) {
918
+ return this.register("filter", methodPaths, pipe, options);
919
+ }
920
+ handle(methodPaths, pipe, options) {
921
+ return this.register("handler", methodPaths, pipe, options);
922
+ }
923
+ fallback(methodPaths, pipe, options) {
924
+ return this.register("fallback", methodPaths, pipe, options);
925
+ }
926
+ after(methodPaths, pipe, options) {
927
+ return this.register("after", methodPaths, pipe, options);
928
+ }
929
+ catch(methodPaths, pipe, options) {
930
+ return this.register("catcher", methodPaths, pipe, options);
931
+ }
932
+ register(handlerType, methodPaths, pipe, options) {
933
+ const overwrite = (options === null || options === void 0 ? void 0 : options.overwrite) === true;
934
+ methodPaths = Array.isArray(methodPaths) ? methodPaths : [methodPaths];
935
+ pipe = Array.isArray(pipe) ? pipe : [pipe];
936
+ for (const methodPath of methodPaths) {
937
+ const [method, originalPath] = methodPath.split(" ", 2);
938
+ const processedPaths = __classPrivateFieldGet(this, _Router_instances, "m", _Router_processPath).call(this, originalPath);
939
+ const { params, paths } = processedPaths;
940
+ const paramsMap = params ? new Map(params) : undefined;
941
+ for (const path of paths) {
942
+ const standardPath = params
943
+ ? path
944
+ .split("/")
945
+ .map((p, idx) => (p === "*" ? `:${paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)}` : p))
946
+ .join("/")
947
+ : path;
948
+ const openApiPath = params
949
+ ? path
950
+ .split("/")
951
+ .map((p, idx) => (p === "*" ? `{${paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)}}` : p))
952
+ .join("/")
953
+ : path;
954
+ const upperMethod = method.toUpperCase();
955
+ if (!exports.HTTP_METHODS_UPPER.has(upperMethod)) {
956
+ throw new types_ts_1.RouterError(`Unsupported HTTP Method ${method}`);
957
+ }
958
+ const routes = __classPrivateFieldGet(this, _Router_routes, "f")[handlerType][upperMethod];
959
+ if (!exports.REGISTER_PATH_REGEX.test(path)) {
960
+ throw new types_ts_1.RouterError(`Invalid path for (${method} ${originalPath} -> ${path})`);
961
+ }
962
+ const parts = path.split("/", __classPrivateFieldGet(this, _Router_config, "f").maxPath + 1);
963
+ if (parts.length - 1 > __classPrivateFieldGet(this, _Router_config, "f").maxPath) {
964
+ throw new types_ts_1.RouterError(`Path parts length limit exceeded ${__classPrivateFieldGet(this, _Router_config, "f").maxPath}`);
965
+ }
966
+ const parts_len_1 = parts.length - 1;
967
+ const hasGlob = parts.some((p) => p === "*");
968
+ const superGlobIndex = path.endsWith("/**") ? path.length - 3 : -1;
969
+ const hasSuperGlob = superGlobIndex >= 0;
970
+ const entry = {
971
+ parseParams: parseParams.bind(null, hasSuperGlob ? superGlobIndex + 1 : undefined, params),
972
+ params,
973
+ pipe,
974
+ originalPath,
975
+ standardPath,
976
+ openApiPath,
977
+ path,
978
+ pathParts: parts,
979
+ openApi: options === null || options === void 0 ? void 0 : options.openApi,
980
+ };
981
+ // check for super globs
982
+ if (hasSuperGlob) {
983
+ if (hasGlob) {
984
+ throw new types_ts_1.RouterError(`SuperGlob route with Globs are not allowed. for (${method} ${originalPath} -> ${path})`);
985
+ }
986
+ let superGlobEntries = routes.superGlobs[parts_len_1];
987
+ const basePath = path.substring(0, superGlobIndex + 1);
988
+ if (!overwrite &&
989
+ superGlobEntries &&
990
+ superGlobEntries.has(basePath)) {
991
+ throw new types_ts_1.RouterError(`SuperGlob route already set for (${method} ${originalPath} -> ${path})`);
992
+ }
993
+ if (superGlobEntries == null) {
994
+ superGlobEntries = new Map();
995
+ routes.superGlobs[parts_len_1] = superGlobEntries;
996
+ }
997
+ superGlobEntries.set(basePath, entry);
998
+ }
999
+ else if (hasGlob) {
1000
+ // check for globs
1001
+ let globEntries = routes.globs[parts.length];
1002
+ if (globEntries) {
1003
+ if (!overwrite && globEntries && globEntries.has(path)) {
1004
+ throw new types_ts_1.RouterError(`Glob route already set for (${method} ${originalPath} -> ${path})`);
1005
+ }
1006
+ // check for collision
1007
+ for (const globEntry of globEntries.values()) {
1008
+ let collision = -1;
1009
+ for (let i = 1; i < parts.length; i++) {
1010
+ if (parts[i] === "*" && globEntry.pathParts[i] === "*") {
1011
+ collision = i;
1012
+ }
1013
+ else if (parts[i] !== globEntry.pathParts[i]) {
1014
+ collision = -1;
1015
+ break;
1016
+ }
1017
+ }
1018
+ if (collision >= 0 && !overwrite) {
1019
+ throw new types_ts_1.RouterError(`Route collision for (${method} ${originalPath} -> ${path} with ${globEntry.originalPath} at ${parts.slice(0, collision + 1).join("/")})`);
1020
+ }
1021
+ }
1022
+ }
1023
+ if (globEntries == null) {
1024
+ globEntries = new Map();
1025
+ routes.globs[parts.length] = globEntries;
1026
+ }
1027
+ globEntries.set(path, entry);
1028
+ }
1029
+ else {
1030
+ let entries = routes.entries[parts.length];
1031
+ if (!overwrite && entries && entries.has(path)) {
1032
+ throw new types_ts_1.RouterError(`Route already set for (${method} ${originalPath} -> ${path})`);
1033
+ }
1034
+ if (entries == null) {
1035
+ entries = new Map();
1036
+ routes.entries[parts.length] = entries;
1037
+ }
1038
+ entries.set(path, entry);
1039
+ }
1040
+ }
1041
+ }
1042
+ return this;
931
1043
  }
932
1044
  splitPath(pathname, parts, maxPath) {
933
1045
  const path_len_1 = pathname.length - 1;
@@ -968,7 +1080,7 @@ class Router {
968
1080
  continue;
969
1081
  }
970
1082
  // validate part
971
- if (!PATH_PART_REGEX.test(part)) {
1083
+ if (!exports.PATH_PART_REGEX.test(part)) {
972
1084
  throw new types_ts_1.RouterError(`Invalid path ${pathname} -> ${part}`);
973
1085
  }
974
1086
  // parse part
@@ -1059,118 +1171,7 @@ class Router {
1059
1171
  }
1060
1172
  }
1061
1173
  exports.Router = Router;
1062
- _Router_config = new WeakMap(), _Router_routes = new WeakMap(), _Router_instances = new WeakSet(), _Router_register = function _Router_register(handlerType, methodPaths, pipeline, options) {
1063
- const overwrite = (options === null || options === void 0 ? void 0 : options.overwrite) === true;
1064
- methodPaths = Array.isArray(methodPaths) ? methodPaths : [methodPaths];
1065
- pipeline = Array.isArray(pipeline) ? pipeline : [pipeline];
1066
- for (const methodPath of methodPaths) {
1067
- const [method, originalPath] = methodPath.split(" ", 2);
1068
- const processedPaths = __classPrivateFieldGet(this, _Router_instances, "m", _Router_processPath).call(this, originalPath);
1069
- const { params, paths } = processedPaths;
1070
- const paramsMap = params ? new Map(params) : undefined;
1071
- for (const path of paths) {
1072
- const standardPath = params
1073
- ? path
1074
- .split("/")
1075
- .map((p, idx) => (p === "*" ? `:${paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)}` : p))
1076
- .join("/")
1077
- : path;
1078
- const openApiPath = params
1079
- ? path
1080
- .split("/")
1081
- .map((p, idx) => (p === "*" ? `{${paramsMap === null || paramsMap === void 0 ? void 0 : paramsMap.get(idx)}}` : p))
1082
- .join("/")
1083
- : path;
1084
- const upperMethod = method.toUpperCase();
1085
- if (!exports.HTTP_METHODS_UPPER.has(upperMethod)) {
1086
- throw new types_ts_1.RouterError(`Unsupported HTTP Method ${method}`);
1087
- }
1088
- const routes = __classPrivateFieldGet(this, _Router_routes, "f")[handlerType][upperMethod];
1089
- if (!REGISTER_PATH_REGEX.test(path)) {
1090
- throw new types_ts_1.RouterError(`Invalid path for (${method} ${originalPath} -> ${path})`);
1091
- }
1092
- const parts = path.split("/", __classPrivateFieldGet(this, _Router_config, "f").maxPath + 1);
1093
- if (parts.length - 1 > __classPrivateFieldGet(this, _Router_config, "f").maxPath) {
1094
- throw new types_ts_1.RouterError(`Path parts length limit exceeded ${__classPrivateFieldGet(this, _Router_config, "f").maxPath}`);
1095
- }
1096
- const parts_len_1 = parts.length - 1;
1097
- const hasGlob = parts.some((p) => p === "*");
1098
- const superGlobIndex = path.endsWith("/**") ? path.length - 3 : -1;
1099
- const hasSuperGlob = superGlobIndex >= 0;
1100
- const entry = {
1101
- parseParams: parseParams.bind(null, hasSuperGlob ? superGlobIndex + 1 : undefined, params),
1102
- params,
1103
- pipeline,
1104
- originalPath,
1105
- standardPath,
1106
- openApiPath,
1107
- path,
1108
- pathParts: parts,
1109
- openApi: options === null || options === void 0 ? void 0 : options.openApi,
1110
- };
1111
- // check for super globs
1112
- if (hasSuperGlob) {
1113
- if (hasGlob) {
1114
- throw new types_ts_1.RouterError(`SuperGlob route with Globs are not allowed. for (${method} ${originalPath} -> ${path})`);
1115
- }
1116
- let superGlobEntries = routes.superGlobs[parts_len_1];
1117
- const basePath = path.substring(0, superGlobIndex + 1);
1118
- if (!overwrite &&
1119
- superGlobEntries &&
1120
- superGlobEntries.has(basePath)) {
1121
- throw new types_ts_1.RouterError(`SuperGlob route already set for (${method} ${originalPath} -> ${path})`);
1122
- }
1123
- if (superGlobEntries == null) {
1124
- superGlobEntries = new Map();
1125
- routes.superGlobs[parts_len_1] = superGlobEntries;
1126
- }
1127
- superGlobEntries.set(basePath, entry);
1128
- }
1129
- else if (hasGlob) {
1130
- // check for globs
1131
- let globEntries = routes.globs[parts.length];
1132
- if (globEntries) {
1133
- if (!overwrite && globEntries && globEntries.has(path)) {
1134
- throw new types_ts_1.RouterError(`Glob route already set for (${method} ${originalPath} -> ${path})`);
1135
- }
1136
- // check for collision
1137
- for (const globEntry of globEntries.values()) {
1138
- let collision = -1;
1139
- for (let i = 1; i < parts.length; i++) {
1140
- if (parts[i] === "*" && globEntry.pathParts[i] === "*") {
1141
- collision = i;
1142
- }
1143
- else if (parts[i] !== globEntry.pathParts[i]) {
1144
- collision = -1;
1145
- break;
1146
- }
1147
- }
1148
- if (collision >= 0 && !overwrite) {
1149
- throw new types_ts_1.RouterError(`Route collision for (${method} ${originalPath} -> ${path} with ${globEntry.originalPath} at ${parts.slice(0, collision + 1).join("/")})`);
1150
- }
1151
- }
1152
- }
1153
- if (globEntries == null) {
1154
- globEntries = new Map();
1155
- routes.globs[parts.length] = globEntries;
1156
- }
1157
- globEntries.set(path, entry);
1158
- }
1159
- else {
1160
- let entries = routes.entries[parts.length];
1161
- if (!overwrite && entries && entries.has(path)) {
1162
- throw new types_ts_1.RouterError(`Route already set for (${method} ${originalPath} -> ${path})`);
1163
- }
1164
- if (entries == null) {
1165
- entries = new Map();
1166
- routes.entries[parts.length] = entries;
1167
- }
1168
- entries.set(path, entry);
1169
- }
1170
- }
1171
- }
1172
- return this;
1173
- }, _Router_processPath = function _Router_processPath(path) {
1174
+ _Router_config = new WeakMap(), _Router_routes = new WeakMap(), _Router_instances = new WeakSet(), _Router_processPath = function _Router_processPath(path) {
1174
1175
  const processedPaths = {
1175
1176
  paths: [""],
1176
1177
  };