@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/merge.js CHANGED
@@ -1,100 +1,118 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeRoutes = void 0;
4
- const index_1 = require("./index");
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
- const builderRoutes = {};
7
- for (const { entrypoint, routes, use } of builds) {
8
- if (routes) {
9
- if (!builderRoutes[entrypoint]) {
10
- builderRoutes[entrypoint] = {};
11
- }
12
- builderRoutes[entrypoint][use] = routes;
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
- return builderRoutes;
34
+ }
35
+ return builderRoutes;
16
36
  }
17
37
  function getCheckAndContinue(routes) {
18
- const checks = [];
19
- const continues = [];
20
- const others = [];
21
- for (const route of routes) {
22
- if ((0, index_1.isHandler)(route)) {
23
- // Should never happen, only here to make TS happy
24
- throw new Error(`Unexpected route found in getCheckAndContinue(): ${JSON.stringify(route)}`);
25
- }
26
- else if (route.check && !route.override) {
27
- checks.push(route);
28
- }
29
- else if (route.continue && !route.override) {
30
- continues.push(route);
31
- }
32
- else {
33
- others.push(route);
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
- return { checks, continues, others };
55
+ }
56
+ return { checks, continues, others };
37
57
  }
38
58
  function mergeRoutes({ userRoutes, builds }) {
39
- const userHandleMap = new Map();
40
- let userPrevHandle = null;
41
- (userRoutes || []).forEach(route => {
42
- if ((0, index_1.isHandler)(route)) {
43
- userPrevHandle = route.handle;
44
- }
45
- else {
46
- const routes = userHandleMap.get(userPrevHandle);
47
- if (!routes) {
48
- userHandleMap.set(userPrevHandle, [route]);
49
- }
50
- else {
51
- routes.push(route);
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
- const builderHandleMap = new Map();
56
- const builderRoutes = getBuilderRoutesMapping(builds);
57
- const sortedPaths = Object.keys(builderRoutes).sort();
58
- sortedPaths.forEach(path => {
59
- const br = builderRoutes[path];
60
- const sortedBuilders = Object.keys(br).sort();
61
- sortedBuilders.forEach(use => {
62
- let builderPrevHandle = null;
63
- br[use].forEach(route => {
64
- if ((0, index_1.isHandler)(route)) {
65
- builderPrevHandle = route.handle;
66
- }
67
- else {
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
- return outputRoutes;
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
- exports.mergeRoutes = mergeRoutes;
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;