@carno.js/core 1.1.1 → 1.1.2
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/LICENSE +21 -21
- package/README.md +188 -188
- package/dist/Carno.js +46 -26
- package/dist/Carno.mjs +46 -26
- package/dist/bun/index.js +4 -4
- package/dist/bun/index.js.map +29 -29
- package/package.json +2 -2
- package/src/Carno.ts +718 -673
- package/src/DefaultRoutes.ts +34 -34
- package/src/cache/CacheDriver.ts +50 -50
- package/src/cache/CacheService.ts +139 -139
- package/src/cache/MemoryDriver.ts +104 -104
- package/src/cache/RedisDriver.ts +116 -116
- package/src/compiler/JITCompiler.ts +167 -167
- package/src/container/Container.ts +168 -168
- package/src/context/Context.ts +130 -130
- package/src/cors/CorsHandler.ts +145 -145
- package/src/decorators/Controller.ts +63 -63
- package/src/decorators/Inject.ts +16 -16
- package/src/decorators/Middleware.ts +22 -22
- package/src/decorators/Service.ts +18 -18
- package/src/decorators/methods.ts +58 -58
- package/src/decorators/params.ts +47 -47
- package/src/events/Lifecycle.ts +97 -97
- package/src/exceptions/HttpException.ts +99 -99
- package/src/index.ts +95 -95
- package/src/metadata.ts +46 -46
- package/src/middleware/CarnoMiddleware.ts +14 -14
- package/src/router/RadixRouter.ts +225 -225
- package/src/testing/TestHarness.ts +185 -185
- package/src/utils/Metadata.ts +43 -43
- package/src/utils/parseQuery.ts +161 -161
- package/src/validation/ValibotAdapter.ts +95 -95
- package/src/validation/ValidatorAdapter.ts +69 -69
- package/src/validation/ZodAdapter.ts +102 -102
- package/dist/Carno.d.js +0 -14
- package/dist/Carno.d.mjs +0 -1
- package/dist/DefaultRoutes.d.js +0 -13
- package/dist/DefaultRoutes.d.mjs +0 -0
- package/dist/cache/CacheDriver.d.js +0 -13
- package/dist/cache/CacheDriver.d.mjs +0 -0
- package/dist/cache/CacheService.d.js +0 -13
- package/dist/cache/CacheService.d.mjs +0 -0
- package/dist/cache/MemoryDriver.d.js +0 -13
- package/dist/cache/MemoryDriver.d.mjs +0 -0
- package/dist/cache/RedisDriver.d.js +0 -13
- package/dist/cache/RedisDriver.d.mjs +0 -0
- package/dist/compiler/JITCompiler.d.js +0 -13
- package/dist/compiler/JITCompiler.d.mjs +0 -0
- package/dist/container/Container.d.js +0 -13
- package/dist/container/Container.d.mjs +0 -0
- package/dist/context/Context.d.js +0 -13
- package/dist/context/Context.d.mjs +0 -0
- package/dist/cors/CorsHandler.d.js +0 -13
- package/dist/cors/CorsHandler.d.mjs +0 -0
- package/dist/decorators/Controller.d.js +0 -13
- package/dist/decorators/Controller.d.mjs +0 -0
- package/dist/decorators/Inject.d.js +0 -13
- package/dist/decorators/Inject.d.mjs +0 -0
- package/dist/decorators/Middleware.d.js +0 -13
- package/dist/decorators/Middleware.d.mjs +0 -0
- package/dist/decorators/Service.d.js +0 -13
- package/dist/decorators/Service.d.mjs +0 -0
- package/dist/decorators/methods.d.js +0 -13
- package/dist/decorators/methods.d.mjs +0 -0
- package/dist/decorators/params.d.js +0 -13
- package/dist/decorators/params.d.mjs +0 -0
- package/dist/events/Lifecycle.d.js +0 -13
- package/dist/events/Lifecycle.d.mjs +0 -0
- package/dist/exceptions/HttpException.d.js +0 -13
- package/dist/exceptions/HttpException.d.mjs +0 -0
- package/dist/index.d.js +0 -130
- package/dist/index.d.mjs +0 -78
- package/dist/metadata.d.js +0 -13
- package/dist/metadata.d.mjs +0 -0
- package/dist/middleware/CarnoMiddleware.d.js +0 -13
- package/dist/middleware/CarnoMiddleware.d.mjs +0 -0
- package/dist/router/RadixRouter.d.js +0 -13
- package/dist/router/RadixRouter.d.mjs +0 -0
- package/dist/testing/TestHarness.d.js +0 -13
- package/dist/testing/TestHarness.d.mjs +0 -0
- package/dist/utils/Metadata.d.js +0 -13
- package/dist/utils/Metadata.d.mjs +0 -0
- package/dist/utils/parseQuery.d.js +0 -13
- package/dist/utils/parseQuery.d.mjs +0 -0
- package/dist/validation/ValibotAdapter.d.js +0 -13
- package/dist/validation/ValibotAdapter.d.mjs +0 -0
- package/dist/validation/ValidatorAdapter.d.js +0 -13
- package/dist/validation/ValidatorAdapter.d.mjs +0 -0
- package/dist/validation/ZodAdapter.d.js +0 -13
- package/dist/validation/ZodAdapter.d.mjs +0 -0
- package/src/Carno.d.ts +0 -135
- package/src/DefaultRoutes.d.ts +0 -19
- package/src/cache/CacheDriver.d.ts +0 -43
- package/src/cache/CacheService.d.ts +0 -89
- package/src/cache/MemoryDriver.d.ts +0 -32
- package/src/cache/RedisDriver.d.ts +0 -34
- package/src/compiler/JITCompiler.d.ts +0 -36
- package/src/container/Container.d.ts +0 -38
- package/src/context/Context.d.ts +0 -36
- package/src/cors/CorsHandler.d.ts +0 -47
- package/src/decorators/Controller.d.ts +0 -13
- package/src/decorators/Inject.d.ts +0 -6
- package/src/decorators/Middleware.d.ts +0 -5
- package/src/decorators/Service.d.ts +0 -9
- package/src/decorators/methods.d.ts +0 -7
- package/src/decorators/params.d.ts +0 -13
- package/src/events/Lifecycle.d.ts +0 -54
- package/src/exceptions/HttpException.d.ts +0 -43
- package/src/index.d.ts +0 -42
- package/src/metadata.d.ts +0 -41
- package/src/middleware/CarnoMiddleware.d.ts +0 -12
- package/src/router/RadixRouter.d.ts +0 -19
- package/src/testing/TestHarness.d.ts +0 -71
- package/src/utils/Metadata.d.ts +0 -20
- package/src/utils/parseQuery.d.ts +0 -23
- package/src/validation/ValibotAdapter.d.ts +0 -30
- package/src/validation/ValidatorAdapter.d.ts +0 -54
- package/src/validation/ZodAdapter.d.ts +0 -35
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ultra-fast Radix Router for Turbo.
|
|
3
|
-
*
|
|
4
|
-
* Optimizations:
|
|
5
|
-
* - Char code comparisons (no string allocations)
|
|
6
|
-
* - Frozen empty params object
|
|
7
|
-
* - O(1) method lookup via char code index
|
|
8
|
-
* - Minimal allocations in hot path
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const EMPTY_PARAMS: Readonly<Record<string, string>> = Object.freeze({});
|
|
12
|
-
|
|
13
|
-
interface Node<T> {
|
|
14
|
-
part: string;
|
|
15
|
-
store: T | null;
|
|
16
|
-
children: Map<number, Node<T>> | null;
|
|
17
|
-
paramChild: ParamNode<T> | null;
|
|
18
|
-
wildcardStore: T | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ParamNode<T> {
|
|
22
|
-
name: string;
|
|
23
|
-
store: T | null;
|
|
24
|
-
child: Node<T> | null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface RouteMatch<T> {
|
|
28
|
-
store: T;
|
|
29
|
-
params: Record<string, string>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function createNode<T>(part: string): Node<T> {
|
|
33
|
-
return {
|
|
34
|
-
part,
|
|
35
|
-
store: null,
|
|
36
|
-
children: null,
|
|
37
|
-
paramChild: null,
|
|
38
|
-
wildcardStore: null
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class RadixRouter<T> {
|
|
43
|
-
private roots: Record<string, Node<T>> = {};
|
|
44
|
-
|
|
45
|
-
add(method: string, path: string, store: T): void {
|
|
46
|
-
if (path === '') path = '/';
|
|
47
|
-
if (path[0] !== '/') path = '/' + path;
|
|
48
|
-
|
|
49
|
-
const isWildcard = path.endsWith('*');
|
|
50
|
-
|
|
51
|
-
if (isWildcard) path = path.slice(0, -1);
|
|
52
|
-
|
|
53
|
-
let node = this.roots[method];
|
|
54
|
-
|
|
55
|
-
if (!node) {
|
|
56
|
-
node = this.roots[method] = createNode('/');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let i = 0;
|
|
60
|
-
const len = path.length;
|
|
61
|
-
|
|
62
|
-
while (i < len) {
|
|
63
|
-
const char = path.charCodeAt(i);
|
|
64
|
-
|
|
65
|
-
if (char === 58) {
|
|
66
|
-
const paramStart = i + 1;
|
|
67
|
-
let paramEnd = paramStart;
|
|
68
|
-
|
|
69
|
-
while (paramEnd < len && path.charCodeAt(paramEnd) !== 47) {
|
|
70
|
-
paramEnd++;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const paramName = path.slice(paramStart, paramEnd);
|
|
74
|
-
|
|
75
|
-
if (!node.paramChild) {
|
|
76
|
-
node.paramChild = { name: paramName, store: null, child: null };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (paramEnd >= len) {
|
|
80
|
-
node.paramChild.store = store;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (!node.paramChild.child) {
|
|
85
|
-
node.paramChild.child = createNode(path.slice(paramEnd));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
node = node.paramChild.child;
|
|
89
|
-
i = paramEnd;
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let segmentEnd = i;
|
|
94
|
-
|
|
95
|
-
while (segmentEnd < len && path.charCodeAt(segmentEnd) !== 47 && path.charCodeAt(segmentEnd) !== 58) {
|
|
96
|
-
segmentEnd++;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (segmentEnd < len && path.charCodeAt(segmentEnd) === 47) {
|
|
100
|
-
segmentEnd++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const segment = path.slice(i, segmentEnd);
|
|
104
|
-
|
|
105
|
-
if (segment === node.part) {
|
|
106
|
-
i = segmentEnd;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!node.children) {
|
|
111
|
-
node.children = new Map();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const firstChar = segment.charCodeAt(0);
|
|
115
|
-
let child = node.children.get(firstChar);
|
|
116
|
-
|
|
117
|
-
if (!child) {
|
|
118
|
-
child = createNode(segment);
|
|
119
|
-
node.children.set(firstChar, child);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
node = child;
|
|
123
|
-
i = segmentEnd;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (isWildcard) {
|
|
127
|
-
node.wildcardStore = store;
|
|
128
|
-
} else {
|
|
129
|
-
node.store = store;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
find(method: string, path: string): RouteMatch<T> | null {
|
|
134
|
-
const root = this.roots[method];
|
|
135
|
-
|
|
136
|
-
if (!root) return null;
|
|
137
|
-
|
|
138
|
-
return this.matchPath(root, path, 0, path.length);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private matchPath(
|
|
142
|
-
node: Node<T>,
|
|
143
|
-
path: string,
|
|
144
|
-
start: number,
|
|
145
|
-
len: number
|
|
146
|
-
): RouteMatch<T> | null {
|
|
147
|
-
const partLen = node.part.length;
|
|
148
|
-
const end = start + partLen;
|
|
149
|
-
|
|
150
|
-
if (partLen > 1) {
|
|
151
|
-
if (end > len) return null;
|
|
152
|
-
|
|
153
|
-
for (let i = 1, j = start + 1; i < partLen; i++, j++) {
|
|
154
|
-
if (node.part.charCodeAt(i) !== path.charCodeAt(j)) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (end === len) {
|
|
161
|
-
if (node.store !== null) {
|
|
162
|
-
return { store: node.store, params: EMPTY_PARAMS };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (node.wildcardStore !== null) {
|
|
166
|
-
return { store: node.wildcardStore, params: { '*': '' } };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (node.children) {
|
|
173
|
-
const child = node.children.get(path.charCodeAt(end));
|
|
174
|
-
|
|
175
|
-
if (child) {
|
|
176
|
-
const result = this.matchPath(child, path, end, len);
|
|
177
|
-
|
|
178
|
-
if (result) return result;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (node.paramChild) {
|
|
183
|
-
const param = node.paramChild;
|
|
184
|
-
let paramEnd = end;
|
|
185
|
-
|
|
186
|
-
while (paramEnd < len && path.charCodeAt(paramEnd) !== 47) {
|
|
187
|
-
paramEnd++;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (paramEnd === end) return null;
|
|
191
|
-
|
|
192
|
-
const paramValue = path.slice(end, paramEnd);
|
|
193
|
-
|
|
194
|
-
if (paramEnd >= len) {
|
|
195
|
-
if (param.store !== null) {
|
|
196
|
-
return {
|
|
197
|
-
store: param.store,
|
|
198
|
-
params: { [param.name]: paramValue }
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
} else if (param.child) {
|
|
202
|
-
const result = this.matchPath(param.child, path, paramEnd, len);
|
|
203
|
-
|
|
204
|
-
if (result) {
|
|
205
|
-
if (result.params === EMPTY_PARAMS) {
|
|
206
|
-
result.params = { [param.name]: paramValue };
|
|
207
|
-
} else {
|
|
208
|
-
result.params[param.name] = paramValue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return result;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (node.wildcardStore !== null) {
|
|
217
|
-
return {
|
|
218
|
-
store: node.wildcardStore,
|
|
219
|
-
params: { '*': path.slice(end) }
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Ultra-fast Radix Router for Turbo.
|
|
3
|
+
*
|
|
4
|
+
* Optimizations:
|
|
5
|
+
* - Char code comparisons (no string allocations)
|
|
6
|
+
* - Frozen empty params object
|
|
7
|
+
* - O(1) method lookup via char code index
|
|
8
|
+
* - Minimal allocations in hot path
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const EMPTY_PARAMS: Readonly<Record<string, string>> = Object.freeze({});
|
|
12
|
+
|
|
13
|
+
interface Node<T> {
|
|
14
|
+
part: string;
|
|
15
|
+
store: T | null;
|
|
16
|
+
children: Map<number, Node<T>> | null;
|
|
17
|
+
paramChild: ParamNode<T> | null;
|
|
18
|
+
wildcardStore: T | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ParamNode<T> {
|
|
22
|
+
name: string;
|
|
23
|
+
store: T | null;
|
|
24
|
+
child: Node<T> | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RouteMatch<T> {
|
|
28
|
+
store: T;
|
|
29
|
+
params: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createNode<T>(part: string): Node<T> {
|
|
33
|
+
return {
|
|
34
|
+
part,
|
|
35
|
+
store: null,
|
|
36
|
+
children: null,
|
|
37
|
+
paramChild: null,
|
|
38
|
+
wildcardStore: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class RadixRouter<T> {
|
|
43
|
+
private roots: Record<string, Node<T>> = {};
|
|
44
|
+
|
|
45
|
+
add(method: string, path: string, store: T): void {
|
|
46
|
+
if (path === '') path = '/';
|
|
47
|
+
if (path[0] !== '/') path = '/' + path;
|
|
48
|
+
|
|
49
|
+
const isWildcard = path.endsWith('*');
|
|
50
|
+
|
|
51
|
+
if (isWildcard) path = path.slice(0, -1);
|
|
52
|
+
|
|
53
|
+
let node = this.roots[method];
|
|
54
|
+
|
|
55
|
+
if (!node) {
|
|
56
|
+
node = this.roots[method] = createNode('/');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let i = 0;
|
|
60
|
+
const len = path.length;
|
|
61
|
+
|
|
62
|
+
while (i < len) {
|
|
63
|
+
const char = path.charCodeAt(i);
|
|
64
|
+
|
|
65
|
+
if (char === 58) {
|
|
66
|
+
const paramStart = i + 1;
|
|
67
|
+
let paramEnd = paramStart;
|
|
68
|
+
|
|
69
|
+
while (paramEnd < len && path.charCodeAt(paramEnd) !== 47) {
|
|
70
|
+
paramEnd++;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const paramName = path.slice(paramStart, paramEnd);
|
|
74
|
+
|
|
75
|
+
if (!node.paramChild) {
|
|
76
|
+
node.paramChild = { name: paramName, store: null, child: null };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (paramEnd >= len) {
|
|
80
|
+
node.paramChild.store = store;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!node.paramChild.child) {
|
|
85
|
+
node.paramChild.child = createNode(path.slice(paramEnd));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
node = node.paramChild.child;
|
|
89
|
+
i = paramEnd;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let segmentEnd = i;
|
|
94
|
+
|
|
95
|
+
while (segmentEnd < len && path.charCodeAt(segmentEnd) !== 47 && path.charCodeAt(segmentEnd) !== 58) {
|
|
96
|
+
segmentEnd++;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (segmentEnd < len && path.charCodeAt(segmentEnd) === 47) {
|
|
100
|
+
segmentEnd++;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const segment = path.slice(i, segmentEnd);
|
|
104
|
+
|
|
105
|
+
if (segment === node.part) {
|
|
106
|
+
i = segmentEnd;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!node.children) {
|
|
111
|
+
node.children = new Map();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const firstChar = segment.charCodeAt(0);
|
|
115
|
+
let child = node.children.get(firstChar);
|
|
116
|
+
|
|
117
|
+
if (!child) {
|
|
118
|
+
child = createNode(segment);
|
|
119
|
+
node.children.set(firstChar, child);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
node = child;
|
|
123
|
+
i = segmentEnd;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (isWildcard) {
|
|
127
|
+
node.wildcardStore = store;
|
|
128
|
+
} else {
|
|
129
|
+
node.store = store;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
find(method: string, path: string): RouteMatch<T> | null {
|
|
134
|
+
const root = this.roots[method];
|
|
135
|
+
|
|
136
|
+
if (!root) return null;
|
|
137
|
+
|
|
138
|
+
return this.matchPath(root, path, 0, path.length);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private matchPath(
|
|
142
|
+
node: Node<T>,
|
|
143
|
+
path: string,
|
|
144
|
+
start: number,
|
|
145
|
+
len: number
|
|
146
|
+
): RouteMatch<T> | null {
|
|
147
|
+
const partLen = node.part.length;
|
|
148
|
+
const end = start + partLen;
|
|
149
|
+
|
|
150
|
+
if (partLen > 1) {
|
|
151
|
+
if (end > len) return null;
|
|
152
|
+
|
|
153
|
+
for (let i = 1, j = start + 1; i < partLen; i++, j++) {
|
|
154
|
+
if (node.part.charCodeAt(i) !== path.charCodeAt(j)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (end === len) {
|
|
161
|
+
if (node.store !== null) {
|
|
162
|
+
return { store: node.store, params: EMPTY_PARAMS };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (node.wildcardStore !== null) {
|
|
166
|
+
return { store: node.wildcardStore, params: { '*': '' } };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (node.children) {
|
|
173
|
+
const child = node.children.get(path.charCodeAt(end));
|
|
174
|
+
|
|
175
|
+
if (child) {
|
|
176
|
+
const result = this.matchPath(child, path, end, len);
|
|
177
|
+
|
|
178
|
+
if (result) return result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (node.paramChild) {
|
|
183
|
+
const param = node.paramChild;
|
|
184
|
+
let paramEnd = end;
|
|
185
|
+
|
|
186
|
+
while (paramEnd < len && path.charCodeAt(paramEnd) !== 47) {
|
|
187
|
+
paramEnd++;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (paramEnd === end) return null;
|
|
191
|
+
|
|
192
|
+
const paramValue = path.slice(end, paramEnd);
|
|
193
|
+
|
|
194
|
+
if (paramEnd >= len) {
|
|
195
|
+
if (param.store !== null) {
|
|
196
|
+
return {
|
|
197
|
+
store: param.store,
|
|
198
|
+
params: { [param.name]: paramValue }
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
} else if (param.child) {
|
|
202
|
+
const result = this.matchPath(param.child, path, paramEnd, len);
|
|
203
|
+
|
|
204
|
+
if (result) {
|
|
205
|
+
if (result.params === EMPTY_PARAMS) {
|
|
206
|
+
result.params = { [param.name]: paramValue };
|
|
207
|
+
} else {
|
|
208
|
+
result.params[param.name] = paramValue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (node.wildcardStore !== null) {
|
|
217
|
+
return {
|
|
218
|
+
store: node.wildcardStore,
|
|
219
|
+
params: { '*': path.slice(end) }
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|