1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.TrieRouter = void 0;
|
8 | const tslib_1 = require("tslib");
|
9 | const core_1 = require("@loopback/core");
|
10 | const util_1 = require("util");
|
11 | const keys_1 = require("../keys");
|
12 | const route_entry_1 = require("./route-entry");
|
13 | const router_base_1 = require("./router-base");
|
14 | const trie_1 = require("./trie");
|
15 | const debug = require('debug')('loopback:rest:router:trie');
|
16 |
|
17 |
|
18 |
|
19 | let TrieRouter = class TrieRouter extends router_base_1.BaseRouter {
|
20 | constructor(options) {
|
21 | super(options);
|
22 | this.trie = new trie_1.Trie();
|
23 | }
|
24 | addRouteWithPathVars(route) {
|
25 |
|
26 | const key = this.getKeyForRoute(route);
|
27 | this.trie.create(key, route);
|
28 | }
|
29 | findRouteWithPathVars(verb, path) {
|
30 | var _a;
|
31 | const key = this.getKey(verb, path);
|
32 | const found = this.trie.match(key);
|
33 | debug('Route matched: %j', found);
|
34 | if (found) {
|
35 | const route = found.node.value;
|
36 | if (route) {
|
37 | debug('Route found: %s', (0, util_1.inspect)(route, { depth: 5 }));
|
38 | return (0, route_entry_1.createResolvedRoute)(route, (_a = found.params) !== null && _a !== void 0 ? _a : {});
|
39 | }
|
40 | }
|
41 | return undefined;
|
42 | }
|
43 | listRoutesWithPathVars() {
|
44 | return this.trie.list().map(n => n.value);
|
45 | }
|
46 | };
|
47 | exports.TrieRouter = TrieRouter;
|
48 | exports.TrieRouter = TrieRouter = tslib_1.__decorate([
|
49 | tslib_1.__param(0, (0, core_1.inject)(keys_1.RestBindings.ROUTER_OPTIONS, { optional: true })),
|
50 | tslib_1.__metadata("design:paramtypes", [Object])
|
51 | ], TrieRouter);
|
52 |
|
\ | No newline at end of file |