@vercel/routing-utils 2.1.1 → 2.1.3
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/superstatic.js +24 -3
- package/package.json +3 -3
package/dist/superstatic.js
CHANGED
|
@@ -41,6 +41,8 @@ function convertRedirects(redirects, defaultStatus = 308) {
|
|
|
41
41
|
return redirects.map(r => {
|
|
42
42
|
const { src, segments } = sourceToRegex(r.source);
|
|
43
43
|
const hasSegments = collectHasSegments(r.has);
|
|
44
|
+
normalizeHasKeys(r.has);
|
|
45
|
+
normalizeHasKeys(r.missing);
|
|
44
46
|
try {
|
|
45
47
|
const loc = replaceSegments(segments, hasSegments, r.destination, true);
|
|
46
48
|
let status;
|
|
@@ -61,6 +63,9 @@ function convertRedirects(redirects, defaultStatus = 308) {
|
|
|
61
63
|
if (r.has) {
|
|
62
64
|
route.has = r.has;
|
|
63
65
|
}
|
|
66
|
+
if (r.missing) {
|
|
67
|
+
route.missing = r.missing;
|
|
68
|
+
}
|
|
64
69
|
return route;
|
|
65
70
|
}
|
|
66
71
|
catch (e) {
|
|
@@ -73,12 +78,17 @@ function convertRewrites(rewrites, internalParamNames) {
|
|
|
73
78
|
return rewrites.map(r => {
|
|
74
79
|
const { src, segments } = sourceToRegex(r.source);
|
|
75
80
|
const hasSegments = collectHasSegments(r.has);
|
|
81
|
+
normalizeHasKeys(r.has);
|
|
82
|
+
normalizeHasKeys(r.missing);
|
|
76
83
|
try {
|
|
77
84
|
const dest = replaceSegments(segments, hasSegments, r.destination, false, internalParamNames);
|
|
78
85
|
const route = { src, dest, check: true };
|
|
79
86
|
if (r.has) {
|
|
80
87
|
route.has = r.has;
|
|
81
88
|
}
|
|
89
|
+
if (r.missing) {
|
|
90
|
+
route.missing = r.missing;
|
|
91
|
+
}
|
|
82
92
|
return route;
|
|
83
93
|
}
|
|
84
94
|
catch (e) {
|
|
@@ -92,6 +102,8 @@ function convertHeaders(headers) {
|
|
|
92
102
|
const obj = {};
|
|
93
103
|
const { src, segments } = sourceToRegex(h.source);
|
|
94
104
|
const hasSegments = collectHasSegments(h.has);
|
|
105
|
+
normalizeHasKeys(h.has);
|
|
106
|
+
normalizeHasKeys(h.missing);
|
|
95
107
|
const namedSegments = segments.filter(name => name !== UN_NAMED_SEGMENT);
|
|
96
108
|
const indexes = {};
|
|
97
109
|
segments.forEach((name, index) => {
|
|
@@ -119,6 +131,9 @@ function convertHeaders(headers) {
|
|
|
119
131
|
if (h.has) {
|
|
120
132
|
route.has = h.has;
|
|
121
133
|
}
|
|
134
|
+
if (h.missing) {
|
|
135
|
+
route.missing = h.missing;
|
|
136
|
+
}
|
|
122
137
|
return route;
|
|
123
138
|
});
|
|
124
139
|
}
|
|
@@ -169,12 +184,17 @@ function sourceToRegex(source) {
|
|
|
169
184
|
}
|
|
170
185
|
exports.sourceToRegex = sourceToRegex;
|
|
171
186
|
const namedGroupsRegex = /\(\?<([a-zA-Z][a-zA-Z0-9]*)>/g;
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
for (const hasItem of has || []) {
|
|
187
|
+
const normalizeHasKeys = (hasItems = []) => {
|
|
188
|
+
for (const hasItem of hasItems) {
|
|
175
189
|
if ('key' in hasItem && hasItem.type === 'header') {
|
|
176
190
|
hasItem.key = hasItem.key.toLowerCase();
|
|
177
191
|
}
|
|
192
|
+
}
|
|
193
|
+
return hasItems;
|
|
194
|
+
};
|
|
195
|
+
function collectHasSegments(has) {
|
|
196
|
+
const hasSegments = new Set();
|
|
197
|
+
for (const hasItem of has || []) {
|
|
178
198
|
if (!hasItem.value && 'key' in hasItem) {
|
|
179
199
|
hasSegments.add(hasItem.key);
|
|
180
200
|
}
|
|
@@ -247,6 +267,7 @@ function replaceSegments(segments, hasItemSegments, destination, isRedirect, int
|
|
|
247
267
|
query[key] = strOrArray.map(str => safelyCompile(unescapeSegments(str), indexes, true));
|
|
248
268
|
}
|
|
249
269
|
else {
|
|
270
|
+
// TODO: handle strOrArray is undefined
|
|
250
271
|
query[key] = safelyCompile(unescapeSegments(strOrArray), indexes, true);
|
|
251
272
|
}
|
|
252
273
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/routing-utils",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Vercel routing utilities",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "27.4.1",
|
|
26
|
-
"@types/node": "
|
|
26
|
+
"@types/node": "14.18.33",
|
|
27
27
|
"ajv": "^6.0.0",
|
|
28
28
|
"typescript": "4.3.4"
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
31
|
"ajv": "^6.0.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "1b211f28dfdcb112f1aecb53a2b9f257ecc58420"
|
|
34
34
|
}
|