@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.
- package/README.md +84 -5
- package/dist/auth-middlewares.d.ts +2 -2
- package/dist/auth-middlewares.js +2 -2
- package/dist/cjs/auth-middlewares.d.ts +2 -2
- package/dist/cjs/auth-middlewares.js +2 -2
- package/dist/cjs/generator.d.ts +4 -0
- package/dist/cjs/generator.d.ts.map +1 -0
- package/dist/cjs/generator.js +166 -0
- package/dist/cjs/generator.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/middlewares.d.ts +1 -1
- package/dist/cjs/middlewares.js +1 -1
- package/dist/cjs/router.d.ts +80 -73
- package/dist/cjs/router.d.ts.map +1 -1
- package/dist/cjs/router.js +279 -278
- package/dist/cjs/router.js.map +1 -1
- package/dist/cjs/types.d.ts +6 -2
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/generator.d.ts +4 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +166 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/middlewares.d.ts +1 -1
- package/dist/middlewares.js +1 -1
- package/dist/router.d.ts +80 -73
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +279 -278
- package/dist/router.js.map +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/router.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
38
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
? {
|
|
426
|
+
? { pipe: _definition }
|
|
427
427
|
: {
|
|
428
|
-
|
|
428
|
+
pipe: _definition.pipe,
|
|
429
429
|
openApi: _definition.openApi,
|
|
430
430
|
};
|
|
431
|
-
const
|
|
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 (
|
|
437
|
-
throw new types_ts_1.RouterError(`Undefined
|
|
436
|
+
if (pipe == null) {
|
|
437
|
+
throw new types_ts_1.RouterError(`Undefined pipe in '${node.path}' ${_method}`);
|
|
438
438
|
}
|
|
439
|
-
if (!Array.isArray(
|
|
440
|
-
throw new types_ts_1.RouterError(`Bad
|
|
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(
|
|
449
|
-
|
|
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,
|
|
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
|
|
535
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
536
536
|
}
|
|
537
|
-
crud(paths,
|
|
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
|
|
545
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
546
546
|
}
|
|
547
|
-
head(paths,
|
|
547
|
+
head(paths, pipe, options) {
|
|
548
548
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
549
549
|
const methodPaths = paths.map((p) => `Head ${p}`);
|
|
550
|
-
return
|
|
550
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
551
551
|
}
|
|
552
|
-
get(paths,
|
|
552
|
+
get(paths, pipe, options) {
|
|
553
553
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
554
554
|
const methodPaths = paths.map((p) => `Get ${p}`);
|
|
555
|
-
return
|
|
555
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
556
556
|
}
|
|
557
|
-
post(paths,
|
|
557
|
+
post(paths, pipe, options) {
|
|
558
558
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
559
559
|
const methodPaths = paths.map((p) => `Post ${p}`);
|
|
560
|
-
return
|
|
560
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
561
561
|
}
|
|
562
|
-
put(paths,
|
|
562
|
+
put(paths, pipe, options) {
|
|
563
563
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
564
564
|
const methodPaths = paths.map((p) => `Put ${p}`);
|
|
565
|
-
return
|
|
565
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
566
566
|
}
|
|
567
|
-
patch(paths,
|
|
567
|
+
patch(paths, pipe, options) {
|
|
568
568
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
569
569
|
const methodPaths = paths.map((p) => `Patch ${p}`);
|
|
570
|
-
return
|
|
570
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
571
571
|
}
|
|
572
|
-
delete(paths,
|
|
572
|
+
delete(paths, pipe, options) {
|
|
573
573
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
574
574
|
const methodPaths = paths.map((p) => `Delete ${p}`);
|
|
575
|
-
return
|
|
575
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
576
576
|
}
|
|
577
|
-
options(paths,
|
|
577
|
+
options(paths, pipe, options) {
|
|
578
578
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
579
579
|
const methodPaths = paths.map((p) => `Options ${p}`);
|
|
580
|
-
return
|
|
580
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
581
581
|
}
|
|
582
|
-
trace(paths,
|
|
582
|
+
trace(paths, pipe, options) {
|
|
583
583
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
584
584
|
const methodPaths = paths.map((p) => `Trace ${p}`);
|
|
585
|
-
return
|
|
585
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
586
586
|
}
|
|
587
|
-
connect(paths,
|
|
587
|
+
connect(paths, pipe, options) {
|
|
588
588
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
589
589
|
const methodPaths = paths.map((p) => `Connect ${p}`);
|
|
590
|
-
return
|
|
590
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
591
591
|
}
|
|
592
|
-
filterAll(paths,
|
|
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
|
|
600
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
601
601
|
}
|
|
602
|
-
filterCrud(paths,
|
|
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
|
|
610
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
611
611
|
}
|
|
612
|
-
filterHead(paths,
|
|
612
|
+
filterHead(paths, pipe, options) {
|
|
613
613
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
614
614
|
const methodPaths = paths.map((p) => `Head ${p}`);
|
|
615
|
-
return
|
|
615
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
616
616
|
}
|
|
617
|
-
filterGet(paths,
|
|
617
|
+
filterGet(paths, pipe, options) {
|
|
618
618
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
619
619
|
const methodPaths = paths.map((p) => `Get ${p}`);
|
|
620
|
-
return
|
|
620
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
621
621
|
}
|
|
622
|
-
filterPost(paths,
|
|
622
|
+
filterPost(paths, pipe, options) {
|
|
623
623
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
624
624
|
const methodPaths = paths.map((p) => `Post ${p}`);
|
|
625
|
-
return
|
|
625
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
626
626
|
}
|
|
627
|
-
filterPut(paths,
|
|
627
|
+
filterPut(paths, pipe, options) {
|
|
628
628
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
629
629
|
const methodPaths = paths.map((p) => `Put ${p}`);
|
|
630
|
-
return
|
|
630
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
631
631
|
}
|
|
632
|
-
filterPatch(paths,
|
|
632
|
+
filterPatch(paths, pipe, options) {
|
|
633
633
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
634
634
|
const methodPaths = paths.map((p) => `Patch ${p}`);
|
|
635
|
-
return
|
|
635
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
636
636
|
}
|
|
637
|
-
filterDelete(paths,
|
|
637
|
+
filterDelete(paths, pipe, options) {
|
|
638
638
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
639
639
|
const methodPaths = paths.map((p) => `Delete ${p}`);
|
|
640
|
-
return
|
|
640
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
641
641
|
}
|
|
642
|
-
filterOptions(paths,
|
|
642
|
+
filterOptions(paths, pipe, options) {
|
|
643
643
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
644
644
|
const methodPaths = paths.map((p) => `Options ${p}`);
|
|
645
|
-
return
|
|
645
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
646
646
|
}
|
|
647
|
-
filterTrace(paths,
|
|
647
|
+
filterTrace(paths, pipe, options) {
|
|
648
648
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
649
649
|
const methodPaths = paths.map((p) => `Trace ${p}`);
|
|
650
|
-
return
|
|
650
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
651
651
|
}
|
|
652
|
-
filterConnect(paths,
|
|
652
|
+
filterConnect(paths, pipe, options) {
|
|
653
653
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
654
654
|
const methodPaths = paths.map((p) => `Connect ${p}`);
|
|
655
|
-
return
|
|
655
|
+
return this.register("filter", methodPaths, pipe, options);
|
|
656
656
|
}
|
|
657
|
-
handleAll(paths,
|
|
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
|
|
665
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
666
666
|
}
|
|
667
|
-
handleCrud(paths,
|
|
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
|
|
675
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
676
676
|
}
|
|
677
|
-
handleHead(paths,
|
|
677
|
+
handleHead(paths, pipe, options) {
|
|
678
678
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
679
679
|
const methodPaths = paths.map((p) => `Head ${p}`);
|
|
680
|
-
return
|
|
680
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
681
681
|
}
|
|
682
|
-
handleGet(paths,
|
|
682
|
+
handleGet(paths, pipe, options) {
|
|
683
683
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
684
684
|
const methodPaths = paths.map((p) => `Get ${p}`);
|
|
685
|
-
return
|
|
685
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
686
686
|
}
|
|
687
|
-
handlePost(paths,
|
|
687
|
+
handlePost(paths, pipe, options) {
|
|
688
688
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
689
689
|
const methodPaths = paths.map((p) => `Post ${p}`);
|
|
690
|
-
return
|
|
690
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
691
691
|
}
|
|
692
|
-
handlePut(paths,
|
|
692
|
+
handlePut(paths, pipe, options) {
|
|
693
693
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
694
694
|
const methodPaths = paths.map((p) => `Put ${p}`);
|
|
695
|
-
return
|
|
695
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
696
696
|
}
|
|
697
|
-
handlePatch(paths,
|
|
697
|
+
handlePatch(paths, pipe, options) {
|
|
698
698
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
699
699
|
const methodPaths = paths.map((p) => `Patch ${p}`);
|
|
700
|
-
return
|
|
700
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
701
701
|
}
|
|
702
|
-
handleDelete(paths,
|
|
702
|
+
handleDelete(paths, pipe, options) {
|
|
703
703
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
704
704
|
const methodPaths = paths.map((p) => `Delete ${p}`);
|
|
705
|
-
return
|
|
705
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
706
706
|
}
|
|
707
|
-
handleOptions(paths,
|
|
707
|
+
handleOptions(paths, pipe, options) {
|
|
708
708
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
709
709
|
const methodPaths = paths.map((p) => `Options ${p}`);
|
|
710
|
-
return
|
|
710
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
711
711
|
}
|
|
712
|
-
handleTrace(paths,
|
|
712
|
+
handleTrace(paths, pipe, options) {
|
|
713
713
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
714
714
|
const methodPaths = paths.map((p) => `Trace ${p}`);
|
|
715
|
-
return
|
|
715
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
716
716
|
}
|
|
717
|
-
handleConnect(paths,
|
|
717
|
+
handleConnect(paths, pipe, options) {
|
|
718
718
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
719
719
|
const methodPaths = paths.map((p) => `Connect ${p}`);
|
|
720
|
-
return
|
|
720
|
+
return this.register("handler", methodPaths, pipe, options);
|
|
721
721
|
}
|
|
722
|
-
fallbackAll(paths,
|
|
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
|
|
730
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
731
731
|
}
|
|
732
|
-
fallbackCrud(paths,
|
|
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
|
|
740
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
741
741
|
}
|
|
742
|
-
fallbackHead(paths,
|
|
742
|
+
fallbackHead(paths, pipe, options) {
|
|
743
743
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
744
744
|
const methodPaths = paths.map((p) => `Head ${p}`);
|
|
745
|
-
return
|
|
745
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
746
746
|
}
|
|
747
|
-
fallbackGet(paths,
|
|
747
|
+
fallbackGet(paths, pipe, options) {
|
|
748
748
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
749
749
|
const methodPaths = paths.map((p) => `Get ${p}`);
|
|
750
|
-
return
|
|
750
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
751
751
|
}
|
|
752
|
-
fallbackPost(paths,
|
|
752
|
+
fallbackPost(paths, pipe, options) {
|
|
753
753
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
754
754
|
const methodPaths = paths.map((p) => `Post ${p}`);
|
|
755
|
-
return
|
|
755
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
756
756
|
}
|
|
757
|
-
fallbackPut(paths,
|
|
757
|
+
fallbackPut(paths, pipe, options) {
|
|
758
758
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
759
759
|
const methodPaths = paths.map((p) => `Put ${p}`);
|
|
760
|
-
return
|
|
760
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
761
761
|
}
|
|
762
|
-
fallbackPatch(paths,
|
|
762
|
+
fallbackPatch(paths, pipe, options) {
|
|
763
763
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
764
764
|
const methodPaths = paths.map((p) => `Patch ${p}`);
|
|
765
|
-
return
|
|
765
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
766
766
|
}
|
|
767
|
-
fallbackDelete(paths,
|
|
767
|
+
fallbackDelete(paths, pipe, options) {
|
|
768
768
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
769
769
|
const methodPaths = paths.map((p) => `Delete ${p}`);
|
|
770
|
-
return
|
|
770
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
771
771
|
}
|
|
772
|
-
fallbackOptions(paths,
|
|
772
|
+
fallbackOptions(paths, pipe, options) {
|
|
773
773
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
774
774
|
const methodPaths = paths.map((p) => `Options ${p}`);
|
|
775
|
-
return
|
|
775
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
776
776
|
}
|
|
777
|
-
fallbackTrace(paths,
|
|
777
|
+
fallbackTrace(paths, pipe, options) {
|
|
778
778
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
779
779
|
const methodPaths = paths.map((p) => `Trace ${p}`);
|
|
780
|
-
return
|
|
780
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
781
781
|
}
|
|
782
|
-
fallbackConnect(paths,
|
|
782
|
+
fallbackConnect(paths, pipe, options) {
|
|
783
783
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
784
784
|
const methodPaths = paths.map((p) => `Connect ${p}`);
|
|
785
|
-
return
|
|
785
|
+
return this.register("fallback", methodPaths, pipe, options);
|
|
786
786
|
}
|
|
787
|
-
afterAll(paths,
|
|
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
|
|
795
|
+
return this.register("after", methodPaths, pipe, options);
|
|
796
796
|
}
|
|
797
|
-
afterCrud(paths,
|
|
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
|
|
805
|
+
return this.register("after", methodPaths, pipe, options);
|
|
806
806
|
}
|
|
807
|
-
afterHead(paths,
|
|
807
|
+
afterHead(paths, pipe, options) {
|
|
808
808
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
809
809
|
const methodPaths = paths.map((p) => `Head ${p}`);
|
|
810
|
-
return
|
|
810
|
+
return this.register("after", methodPaths, pipe, options);
|
|
811
811
|
}
|
|
812
|
-
afterGet(paths,
|
|
812
|
+
afterGet(paths, pipe, options) {
|
|
813
813
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
814
814
|
const methodPaths = paths.map((p) => `Get ${p}`);
|
|
815
|
-
return
|
|
815
|
+
return this.register("after", methodPaths, pipe, options);
|
|
816
816
|
}
|
|
817
|
-
afterPost(paths,
|
|
817
|
+
afterPost(paths, pipe, options) {
|
|
818
818
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
819
819
|
const methodPaths = paths.map((p) => `Post ${p}`);
|
|
820
|
-
return
|
|
820
|
+
return this.register("after", methodPaths, pipe, options);
|
|
821
821
|
}
|
|
822
|
-
afterPut(paths,
|
|
822
|
+
afterPut(paths, pipe, options) {
|
|
823
823
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
824
824
|
const methodPaths = paths.map((p) => `Put ${p}`);
|
|
825
|
-
return
|
|
825
|
+
return this.register("after", methodPaths, pipe, options);
|
|
826
826
|
}
|
|
827
|
-
afterPatch(paths,
|
|
827
|
+
afterPatch(paths, pipe, options) {
|
|
828
828
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
829
829
|
const methodPaths = paths.map((p) => `Patch ${p}`);
|
|
830
|
-
return
|
|
830
|
+
return this.register("after", methodPaths, pipe, options);
|
|
831
831
|
}
|
|
832
|
-
afterDelete(paths,
|
|
832
|
+
afterDelete(paths, pipe, options) {
|
|
833
833
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
834
834
|
const methodPaths = paths.map((p) => `Delete ${p}`);
|
|
835
|
-
return
|
|
835
|
+
return this.register("after", methodPaths, pipe, options);
|
|
836
836
|
}
|
|
837
|
-
afterOptions(paths,
|
|
837
|
+
afterOptions(paths, pipe, options) {
|
|
838
838
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
839
839
|
const methodPaths = paths.map((p) => `Options ${p}`);
|
|
840
|
-
return
|
|
840
|
+
return this.register("after", methodPaths, pipe, options);
|
|
841
841
|
}
|
|
842
|
-
afterTrace(paths,
|
|
842
|
+
afterTrace(paths, pipe, options) {
|
|
843
843
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
844
844
|
const methodPaths = paths.map((p) => `Trace ${p}`);
|
|
845
|
-
return
|
|
845
|
+
return this.register("after", methodPaths, pipe, options);
|
|
846
846
|
}
|
|
847
|
-
afterConnect(paths,
|
|
847
|
+
afterConnect(paths, pipe, options) {
|
|
848
848
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
849
849
|
const methodPaths = paths.map((p) => `Connect ${p}`);
|
|
850
|
-
return
|
|
850
|
+
return this.register("after", methodPaths, pipe, options);
|
|
851
851
|
}
|
|
852
|
-
catchAll(paths,
|
|
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
|
|
860
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
861
861
|
}
|
|
862
|
-
catchCrud(paths,
|
|
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
|
|
870
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
871
871
|
}
|
|
872
|
-
catchHead(paths,
|
|
872
|
+
catchHead(paths, pipe, options) {
|
|
873
873
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
874
874
|
const methodPaths = paths.map((p) => `Head ${p}`);
|
|
875
|
-
return
|
|
875
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
876
876
|
}
|
|
877
|
-
catchGet(paths,
|
|
877
|
+
catchGet(paths, pipe, options) {
|
|
878
878
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
879
879
|
const methodPaths = paths.map((p) => `Get ${p}`);
|
|
880
|
-
return
|
|
880
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
881
881
|
}
|
|
882
|
-
catchPost(paths,
|
|
882
|
+
catchPost(paths, pipe, options) {
|
|
883
883
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
884
884
|
const methodPaths = paths.map((p) => `Post ${p}`);
|
|
885
|
-
return
|
|
885
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
886
886
|
}
|
|
887
|
-
catchPut(paths,
|
|
887
|
+
catchPut(paths, pipe, options) {
|
|
888
888
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
889
889
|
const methodPaths = paths.map((p) => `Put ${p}`);
|
|
890
|
-
return
|
|
890
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
891
891
|
}
|
|
892
|
-
catchPatch(paths,
|
|
892
|
+
catchPatch(paths, pipe, options) {
|
|
893
893
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
894
894
|
const methodPaths = paths.map((p) => `Patch ${p}`);
|
|
895
|
-
return
|
|
895
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
896
896
|
}
|
|
897
|
-
catchDelete(paths,
|
|
897
|
+
catchDelete(paths, pipe, options) {
|
|
898
898
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
899
899
|
const methodPaths = paths.map((p) => `Delete ${p}`);
|
|
900
|
-
return
|
|
900
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
901
901
|
}
|
|
902
|
-
catchOptions(paths,
|
|
902
|
+
catchOptions(paths, pipe, options) {
|
|
903
903
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
904
904
|
const methodPaths = paths.map((p) => `Options ${p}`);
|
|
905
|
-
return
|
|
905
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
906
906
|
}
|
|
907
|
-
catchTrace(paths,
|
|
907
|
+
catchTrace(paths, pipe, options) {
|
|
908
908
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
909
909
|
const methodPaths = paths.map((p) => `Trace ${p}`);
|
|
910
|
-
return
|
|
910
|
+
return this.register("catcher", methodPaths, pipe, options);
|
|
911
911
|
}
|
|
912
|
-
catchConnect(paths,
|
|
912
|
+
catchConnect(paths, pipe, options) {
|
|
913
913
|
paths = Array.isArray(paths) ? paths : [paths];
|
|
914
914
|
const methodPaths = paths.map((p) => `Connect ${p}`);
|
|
915
|
-
return
|
|
916
|
-
}
|
|
917
|
-
filter(methodPaths,
|
|
918
|
-
return
|
|
919
|
-
}
|
|
920
|
-
handle(methodPaths,
|
|
921
|
-
return
|
|
922
|
-
}
|
|
923
|
-
fallback(methodPaths,
|
|
924
|
-
return
|
|
925
|
-
}
|
|
926
|
-
after(methodPaths,
|
|
927
|
-
return
|
|
928
|
-
}
|
|
929
|
-
catch(methodPaths,
|
|
930
|
-
return
|
|
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(),
|
|
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
|
};
|