@e22m4u/js-trie-router 0.5.4 → 0.5.5
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/dist/cjs/index.cjs
CHANGED
|
@@ -1968,7 +1968,7 @@ var _RouterBranch = class _RouterBranch extends DebuggableService {
|
|
|
1968
1968
|
*
|
|
1969
1969
|
* @type {TrieRouter}
|
|
1970
1970
|
*/
|
|
1971
|
-
|
|
1971
|
+
get router() {
|
|
1972
1972
|
return this._router;
|
|
1973
1973
|
}
|
|
1974
1974
|
/**
|
|
@@ -1982,8 +1982,8 @@ var _RouterBranch = class _RouterBranch extends DebuggableService {
|
|
|
1982
1982
|
*
|
|
1983
1983
|
* @type {RouterBranchDefinition}
|
|
1984
1984
|
*/
|
|
1985
|
-
|
|
1986
|
-
return
|
|
1985
|
+
get definition() {
|
|
1986
|
+
return this._definition;
|
|
1987
1987
|
}
|
|
1988
1988
|
/**
|
|
1989
1989
|
* Parent branch.
|
|
@@ -1996,7 +1996,7 @@ var _RouterBranch = class _RouterBranch extends DebuggableService {
|
|
|
1996
1996
|
*
|
|
1997
1997
|
* @returns {RouterBranch|undefined}
|
|
1998
1998
|
*/
|
|
1999
|
-
|
|
1999
|
+
get parentBranch() {
|
|
2000
2000
|
return this._parentBranch;
|
|
2001
2001
|
}
|
|
2002
2002
|
/**
|
|
@@ -2023,13 +2023,14 @@ var _RouterBranch = class _RouterBranch extends DebuggableService {
|
|
|
2023
2023
|
}
|
|
2024
2024
|
this._parentBranch = parentBranch;
|
|
2025
2025
|
if (parentBranch) {
|
|
2026
|
-
|
|
2027
|
-
parentBranch.
|
|
2026
|
+
const mergedDef = mergeRouterBranchDefinitions(
|
|
2027
|
+
parentBranch.definition,
|
|
2028
2028
|
branchDef
|
|
2029
2029
|
);
|
|
2030
|
+
this._definition = cloneDeep(mergedDef);
|
|
2030
2031
|
} else {
|
|
2031
2032
|
validateRouterBranchDefinition(branchDef);
|
|
2032
|
-
this._definition = branchDef;
|
|
2033
|
+
this._definition = cloneDeep(branchDef);
|
|
2033
2034
|
}
|
|
2034
2035
|
this.ctorDebug("Branch %v created.", normalizePath(branchDef.path, true));
|
|
2035
2036
|
this.ctorDebug("Branch path was %v.", this._definition.path);
|
package/package.json
CHANGED
|
@@ -13,12 +13,12 @@ import {
|
|
|
13
13
|
/**
|
|
14
14
|
* Router branch definition.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export interface RouterBranchDefinition {
|
|
17
17
|
path: string;
|
|
18
18
|
preHandler?: RoutePreHandler | RoutePreHandler[];
|
|
19
19
|
postHandler?: RoutePostHandler | RoutePostHandler[];
|
|
20
20
|
meta?: RouteMeta;
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Router branch.
|
|
@@ -27,28 +27,26 @@ export declare class RouterBranch extends DebuggableService {
|
|
|
27
27
|
/**
|
|
28
28
|
* Get router.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
get router(): TrieRouter;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Get
|
|
33
|
+
* Get definition.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
get definition(): RouterBranchDefinition;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Get
|
|
38
|
+
* Get parent branch.
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
get parentBranch(): RouterBranch | undefined;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Constructor.
|
|
44
44
|
*
|
|
45
|
-
* @param container
|
|
46
45
|
* @param router
|
|
47
46
|
* @param branchDef
|
|
48
47
|
* @param parentBranch
|
|
49
48
|
*/
|
|
50
49
|
constructor(
|
|
51
|
-
container: ServiceContainer,
|
|
52
50
|
router: TrieRouter,
|
|
53
51
|
branchDef: RouterBranchDefinition,
|
|
54
52
|
parentBranch?: RouterBranch,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Route} from '../route/index.js';
|
|
2
|
+
import {cloneDeep} from '../utils/index.js';
|
|
2
3
|
import {TrieRouter} from '../trie-router.js';
|
|
3
4
|
import {InvalidArgumentError} from '@e22m4u/js-format';
|
|
4
5
|
import {normalizePath} from '../utils/normalize-path.js';
|
|
@@ -35,7 +36,7 @@ export class RouterBranch extends DebuggableService {
|
|
|
35
36
|
*
|
|
36
37
|
* @type {TrieRouter}
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
+
get router() {
|
|
39
40
|
return this._router;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -51,8 +52,8 @@ export class RouterBranch extends DebuggableService {
|
|
|
51
52
|
*
|
|
52
53
|
* @type {RouterBranchDefinition}
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
-
return
|
|
55
|
+
get definition() {
|
|
56
|
+
return this._definition;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
/**
|
|
@@ -67,7 +68,7 @@ export class RouterBranch extends DebuggableService {
|
|
|
67
68
|
*
|
|
68
69
|
* @returns {RouterBranch|undefined}
|
|
69
70
|
*/
|
|
70
|
-
|
|
71
|
+
get parentBranch() {
|
|
71
72
|
return this._parentBranch;
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -96,13 +97,14 @@ export class RouterBranch extends DebuggableService {
|
|
|
96
97
|
}
|
|
97
98
|
this._parentBranch = parentBranch;
|
|
98
99
|
if (parentBranch) {
|
|
99
|
-
|
|
100
|
-
parentBranch.
|
|
100
|
+
const mergedDef = mergeRouterBranchDefinitions(
|
|
101
|
+
parentBranch.definition,
|
|
101
102
|
branchDef,
|
|
102
103
|
);
|
|
104
|
+
this._definition = cloneDeep(mergedDef);
|
|
103
105
|
} else {
|
|
104
106
|
validateRouterBranchDefinition(branchDef);
|
|
105
|
-
this._definition = branchDef;
|
|
107
|
+
this._definition = cloneDeep(branchDef);
|
|
106
108
|
}
|
|
107
109
|
this.ctorDebug('Branch %v created.', normalizePath(branchDef.path, true));
|
|
108
110
|
this.ctorDebug('Branch path was %v.', this._definition.path);
|
|
@@ -16,33 +16,28 @@ describe('RouterBranch', function () {
|
|
|
16
16
|
const router = new TrieRouter();
|
|
17
17
|
const parent = router.createBranch({path: 'foo'});
|
|
18
18
|
const S = new RouterBranch(router, {path: 'bar'}, parent);
|
|
19
|
-
expect(S.
|
|
19
|
+
expect(S.definition.path).to.be.eq('/foo/bar');
|
|
20
20
|
});
|
|
21
|
-
});
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
it('should return the router instance that was provided to the constructor', function () {
|
|
22
|
+
it('should set a given router to the "router" property', function () {
|
|
25
23
|
const router = new TrieRouter();
|
|
26
24
|
const S = new RouterBranch(router, {path: ROOT_PATH});
|
|
27
|
-
expect(S.
|
|
25
|
+
expect(S.router).to.be.eq(router);
|
|
28
26
|
});
|
|
29
|
-
});
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
it('should return the branch definition that was provided to the constructor', function () {
|
|
28
|
+
it('should set a given definition to the "definition" property as a copy', function () {
|
|
33
29
|
const router = new TrieRouter();
|
|
34
30
|
const branchDef = {path: ROOT_PATH};
|
|
35
31
|
const S = new RouterBranch(router, branchDef);
|
|
36
|
-
expect(S.
|
|
32
|
+
expect(S.definition).to.be.eql(branchDef);
|
|
33
|
+
expect(S.definition).to.be.not.eq(branchDef);
|
|
37
34
|
});
|
|
38
|
-
});
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
it('should return the parent branch that was provided to the constructor', function () {
|
|
36
|
+
it('should set a parent branch to the "parentBranch" property', function () {
|
|
42
37
|
const router = new TrieRouter();
|
|
43
38
|
const parent = router.createBranch({path: ROOT_PATH});
|
|
44
39
|
const S = new RouterBranch(router, {path: ROOT_PATH}, parent);
|
|
45
|
-
expect(S.
|
|
40
|
+
expect(S.parentBranch).to.be.eq(parent);
|
|
46
41
|
});
|
|
47
42
|
});
|
|
48
43
|
|
|
@@ -82,7 +77,7 @@ describe('RouterBranch', function () {
|
|
|
82
77
|
const router = new TrieRouter();
|
|
83
78
|
const S = new RouterBranch(router, {path: 'foo'});
|
|
84
79
|
const res = S.createBranch({path: 'bar'});
|
|
85
|
-
expect(res.
|
|
80
|
+
expect(res.definition.path).to.be.eq('/foo/bar');
|
|
86
81
|
});
|
|
87
82
|
});
|
|
88
83
|
});
|
package/src/route/route.d.ts
CHANGED
|
@@ -46,14 +46,14 @@ export type RouteMeta = {
|
|
|
46
46
|
/**
|
|
47
47
|
* Route definition.
|
|
48
48
|
*/
|
|
49
|
-
export
|
|
49
|
+
export interface RouteDefinition {
|
|
50
50
|
method: string;
|
|
51
51
|
path: string;
|
|
52
52
|
handler: RouteHandler;
|
|
53
53
|
preHandler?: RoutePreHandler | RoutePreHandler[];
|
|
54
54
|
postHandler?: RoutePostHandler | RoutePostHandler[];
|
|
55
55
|
meta?: RouteMeta;
|
|
56
|
-
}
|
|
56
|
+
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Route.
|
package/src/trie-router.spec.js
CHANGED
|
@@ -34,7 +34,7 @@ describe('TrieRouter', function () {
|
|
|
34
34
|
const router = new TrieRouter();
|
|
35
35
|
const branchDef = {path: 'foo'};
|
|
36
36
|
const res = router.createBranch(branchDef);
|
|
37
|
-
expect(res.
|
|
37
|
+
expect(res.definition.path).to.be.eq(branchDef.path);
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
|