@vercel/routing-utils 2.2.1 → 3.1.0
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/append.js +62 -41
- package/dist/index.js +339 -282
- package/dist/merge.js +106 -88
- package/dist/schemas.d.ts +7 -0
- package/dist/schemas.js +315 -275
- package/dist/superstatic.js +312 -300
- package/dist/types.d.ts +1 -0
- package/dist/types.js +15 -1
- package/package.json +9 -8
package/dist/merge.js
CHANGED
|
@@ -1,100 +1,118 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var merge_exports = {};
|
|
20
|
+
__export(merge_exports, {
|
|
21
|
+
mergeRoutes: () => mergeRoutes
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(merge_exports);
|
|
24
|
+
var import_index = require("./index");
|
|
5
25
|
function getBuilderRoutesMapping(builds) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
26
|
+
const builderRoutes = {};
|
|
27
|
+
for (const { entrypoint, routes, use } of builds) {
|
|
28
|
+
if (routes) {
|
|
29
|
+
if (!builderRoutes[entrypoint]) {
|
|
30
|
+
builderRoutes[entrypoint] = {};
|
|
31
|
+
}
|
|
32
|
+
builderRoutes[entrypoint][use] = routes;
|
|
14
33
|
}
|
|
15
|
-
|
|
34
|
+
}
|
|
35
|
+
return builderRoutes;
|
|
16
36
|
}
|
|
17
37
|
function getCheckAndContinue(routes) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
38
|
+
const checks = [];
|
|
39
|
+
const continues = [];
|
|
40
|
+
const others = [];
|
|
41
|
+
for (const route of routes) {
|
|
42
|
+
if ((0, import_index.isHandler)(route)) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Unexpected route found in getCheckAndContinue(): ${JSON.stringify(
|
|
45
|
+
route
|
|
46
|
+
)}`
|
|
47
|
+
);
|
|
48
|
+
} else if (route.check && !route.override) {
|
|
49
|
+
checks.push(route);
|
|
50
|
+
} else if (route.continue && !route.override) {
|
|
51
|
+
continues.push(route);
|
|
52
|
+
} else {
|
|
53
|
+
others.push(route);
|
|
35
54
|
}
|
|
36
|
-
|
|
55
|
+
}
|
|
56
|
+
return { checks, continues, others };
|
|
37
57
|
}
|
|
38
58
|
function mergeRoutes({ userRoutes, builds }) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
const userHandleMap = /* @__PURE__ */ new Map();
|
|
60
|
+
let userPrevHandle = null;
|
|
61
|
+
(userRoutes || []).forEach((route) => {
|
|
62
|
+
if ((0, import_index.isHandler)(route)) {
|
|
63
|
+
userPrevHandle = route.handle;
|
|
64
|
+
} else {
|
|
65
|
+
const routes = userHandleMap.get(userPrevHandle);
|
|
66
|
+
if (!routes) {
|
|
67
|
+
userHandleMap.set(userPrevHandle, [route]);
|
|
68
|
+
} else {
|
|
69
|
+
routes.push(route);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const builderHandleMap = /* @__PURE__ */ new Map();
|
|
74
|
+
const builderRoutes = getBuilderRoutesMapping(builds);
|
|
75
|
+
const sortedPaths = Object.keys(builderRoutes).sort();
|
|
76
|
+
sortedPaths.forEach((path) => {
|
|
77
|
+
const br = builderRoutes[path];
|
|
78
|
+
const sortedBuilders = Object.keys(br).sort();
|
|
79
|
+
sortedBuilders.forEach((use) => {
|
|
80
|
+
let builderPrevHandle = null;
|
|
81
|
+
br[use].forEach((route) => {
|
|
82
|
+
if ((0, import_index.isHandler)(route)) {
|
|
83
|
+
builderPrevHandle = route.handle;
|
|
84
|
+
} else {
|
|
85
|
+
const routes = builderHandleMap.get(builderPrevHandle);
|
|
86
|
+
if (!routes) {
|
|
87
|
+
builderHandleMap.set(builderPrevHandle, [route]);
|
|
88
|
+
} else {
|
|
89
|
+
routes.push(route);
|
|
90
|
+
}
|
|
53
91
|
}
|
|
92
|
+
});
|
|
54
93
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const routes = builderHandleMap.get(builderPrevHandle);
|
|
69
|
-
if (!routes) {
|
|
70
|
-
builderHandleMap.set(builderPrevHandle, [route]);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
routes.push(route);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
const outputRoutes = [];
|
|
80
|
-
const uniqueHandleValues = new Set([
|
|
81
|
-
null,
|
|
82
|
-
...userHandleMap.keys(),
|
|
83
|
-
...builderHandleMap.keys(),
|
|
84
|
-
]);
|
|
85
|
-
for (const handle of uniqueHandleValues) {
|
|
86
|
-
const userRoutes = userHandleMap.get(handle) || [];
|
|
87
|
-
const builderRoutes = builderHandleMap.get(handle) || [];
|
|
88
|
-
const builderSorted = getCheckAndContinue(builderRoutes);
|
|
89
|
-
if (handle !== null &&
|
|
90
|
-
(userRoutes.length > 0 || builderRoutes.length > 0)) {
|
|
91
|
-
outputRoutes.push({ handle });
|
|
92
|
-
}
|
|
93
|
-
outputRoutes.push(...builderSorted.continues);
|
|
94
|
-
outputRoutes.push(...userRoutes);
|
|
95
|
-
outputRoutes.push(...builderSorted.checks);
|
|
96
|
-
outputRoutes.push(...builderSorted.others);
|
|
94
|
+
});
|
|
95
|
+
const outputRoutes = [];
|
|
96
|
+
const uniqueHandleValues = /* @__PURE__ */ new Set([
|
|
97
|
+
null,
|
|
98
|
+
...userHandleMap.keys(),
|
|
99
|
+
...builderHandleMap.keys()
|
|
100
|
+
]);
|
|
101
|
+
for (const handle of uniqueHandleValues) {
|
|
102
|
+
const userRoutes2 = userHandleMap.get(handle) || [];
|
|
103
|
+
const builderRoutes2 = builderHandleMap.get(handle) || [];
|
|
104
|
+
const builderSorted = getCheckAndContinue(builderRoutes2);
|
|
105
|
+
if (handle !== null && (userRoutes2.length > 0 || builderRoutes2.length > 0)) {
|
|
106
|
+
outputRoutes.push({ handle });
|
|
97
107
|
}
|
|
98
|
-
|
|
108
|
+
outputRoutes.push(...builderSorted.continues);
|
|
109
|
+
outputRoutes.push(...userRoutes2);
|
|
110
|
+
outputRoutes.push(...builderSorted.checks);
|
|
111
|
+
outputRoutes.push(...builderSorted.others);
|
|
112
|
+
}
|
|
113
|
+
return outputRoutes;
|
|
99
114
|
}
|
|
100
|
-
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {
|
|
117
|
+
mergeRoutes
|
|
118
|
+
});
|
package/dist/schemas.d.ts
CHANGED
|
@@ -376,6 +376,12 @@ export declare const rewritesSchema: {
|
|
|
376
376
|
}];
|
|
377
377
|
};
|
|
378
378
|
};
|
|
379
|
+
readonly statusCode: {
|
|
380
|
+
readonly description: "An optional integer to override the status code of the response.";
|
|
381
|
+
readonly type: "integer";
|
|
382
|
+
readonly minimum: 100;
|
|
383
|
+
readonly maximum: 999;
|
|
384
|
+
};
|
|
379
385
|
};
|
|
380
386
|
};
|
|
381
387
|
};
|
|
@@ -404,6 +410,7 @@ export declare const redirectsSchema: {
|
|
|
404
410
|
readonly type: "boolean";
|
|
405
411
|
};
|
|
406
412
|
readonly statusCode: {
|
|
413
|
+
readonly description: "An optional integer to define the status code of the redirect.";
|
|
407
414
|
readonly private: true;
|
|
408
415
|
readonly type: "integer";
|
|
409
416
|
readonly minimum: 100;
|