@uxf/router 15.0.0 → 16.0.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/LICENSE +21 -0
- package/README.md +85 -12
- package/create-client-router.d.ts +12 -5
- package/create-client-router.js +13 -7
- package/create-router.d.ts +10 -4
- package/create-router.js +7 -0
- package/esm/schema/array.js +10 -0
- package/esm/schema/boolean.js +11 -0
- package/esm/schema/index.js +6 -0
- package/esm/schema/integer.js +14 -0
- package/index.d.ts +1 -0
- package/index.js +3 -0
- package/package.json +13 -16
- package/query-params-validation.d.ts +17 -0
- package/query-params-validation.js +46 -0
- package/schema/array.d.ts +8 -0
- package/schema/array.js +46 -0
- package/schema/boolean.d.ts +6 -0
- package/schema/boolean.js +47 -0
- package/{superstruct → schema}/index.d.ts +1 -1
- package/{superstruct → schema}/index.js +6 -4
- package/schema/integer.d.ts +9 -0
- package/schema/integer.js +50 -0
- package/types.d.ts +17 -3
- package/create-router.test.d.ts +0 -1
- package/create-router.test.js +0 -237
- package/helper.test.d.ts +0 -1
- package/helper.test.js +0 -89
- package/routes-check/routes-check.test.d.ts +0 -1
- package/routes-check/routes-check.test.js +0 -33
- package/sitemap-generator.test.d.ts +0 -1
- package/sitemap-generator.test.js +0 -56
- package/superstruct/array.d.ts +0 -7
- package/superstruct/array.js +0 -14
- package/superstruct/boolean.d.ts +0 -1
- package/superstruct/boolean.js +0 -8
- package/superstruct/integer.d.ts +0 -1
- package/superstruct/integer.js +0 -12
- package/utils/object-to-xml.test.d.ts +0 -1
- package/utils/object-to-xml.test.js +0 -43
- package/utils/path-specificity.test.d.ts +0 -1
- package/utils/path-specificity.test.js +0 -72
- package/utils/path-to-regex.test.d.ts +0 -1
- package/utils/path-to-regex.test.js +0 -109
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* An integer that also accepts its URL form: Next.js hands every path and query param over as a string.
|
|
4
|
+
*
|
|
5
|
+
* A string is read with `Number.parseInt(value, 10)`, as the router always did, so `"12abc"` reads as `12`. A string
|
|
6
|
+
* that is not a number at all (`?id=abc`, `?id=`) is a validation issue, not a thrown error, and so is a number
|
|
7
|
+
* outside the safe integer range (`?id=9999999999999999999`), which a JavaScript number cannot hold exactly.
|
|
8
|
+
*/
|
|
9
|
+
export declare function integer(): v.SchemaWithPipe<readonly [v.UnionSchema<[v.NumberSchema<undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, number>]>], undefined>, v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>]>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.integer = integer;
|
|
37
|
+
const v = __importStar(require("valibot"));
|
|
38
|
+
/**
|
|
39
|
+
* An integer that also accepts its URL form: Next.js hands every path and query param over as a string.
|
|
40
|
+
*
|
|
41
|
+
* A string is read with `Number.parseInt(value, 10)`, as the router always did, so `"12abc"` reads as `12`. A string
|
|
42
|
+
* that is not a number at all (`?id=abc`, `?id=`) is a validation issue, not a thrown error, and so is a number
|
|
43
|
+
* outside the safe integer range (`?id=9999999999999999999`), which a JavaScript number cannot hold exactly.
|
|
44
|
+
*/
|
|
45
|
+
function integer() {
|
|
46
|
+
return v.pipe(v.union([
|
|
47
|
+
v.number(),
|
|
48
|
+
v.pipe(v.string(), v.transform((value) => Number.parseInt(value, 10))),
|
|
49
|
+
]), v.number(), v.safeInteger());
|
|
50
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
1
2
|
import { GetServerSideProps, GetStaticProps, PreviewData as NextPreviewData } from "next";
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Schema of the route params: any synchronous Standard Schema (https://standardschema.dev), e.g. a Valibot schema
|
|
5
|
+
* built with `@uxf/router/schema`. It gets the page params as the URL gives them (strings, string arrays) and has to
|
|
6
|
+
* turn them into the typed params.
|
|
7
|
+
*/
|
|
8
|
+
export type RouteSchema = StandardSchemaV1<any, any>;
|
|
3
9
|
export type RouteDefinition<Locales extends string[]> = {
|
|
4
10
|
path: string | Record<Locales[number], string>;
|
|
5
|
-
schema?:
|
|
11
|
+
schema?: RouteSchema | null;
|
|
6
12
|
};
|
|
7
13
|
export type RoutesDefinition<Locales extends string[]> = Record<string, RouteDefinition<Locales>>;
|
|
14
|
+
/** The names of the routes that have a schema. */
|
|
15
|
+
export type RoutesWithSchema<RouteList extends RoutesDefinition<any>> = {
|
|
16
|
+
[K in keyof RouteList]: RouteList[K] extends {
|
|
17
|
+
schema: RouteSchema;
|
|
18
|
+
} ? K : never;
|
|
19
|
+
}[keyof RouteList];
|
|
20
|
+
/** The typed params of a route, i.e. the output of its schema. */
|
|
21
|
+
export type RouteParams<RouteList extends RoutesDefinition<any>, Route extends keyof RouteList> = StandardSchemaV1.InferOutput<NonNullable<RouteList[Route]["schema"]>>;
|
|
8
22
|
export type QueryParams<RouteList extends RoutesDefinition<any>, Route extends keyof RouteList> = RouteList[Route]["schema"] extends null ? never : {
|
|
9
|
-
[key in keyof
|
|
23
|
+
[key in keyof RouteParams<RouteList, Route>]: string | string[] | undefined;
|
|
10
24
|
};
|
|
11
25
|
export type UxfGetStaticProps<RouteList extends RoutesDefinition<any>, Route extends keyof RouteList, Props extends {
|
|
12
26
|
[key: string]: any;
|
package/create-router.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/create-router.test.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs_1 = require("fs");
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const superstruct_1 = require("superstruct");
|
|
6
|
-
const create_router_1 = require("./create-router");
|
|
7
|
-
const merge_route_matchers_1 = require("./merge-route-matchers");
|
|
8
|
-
const superstruct_2 = require("./superstruct");
|
|
9
|
-
const { routeToUrl, createRouteMatcher } = (0, create_router_1.createRouter)({
|
|
10
|
-
index: {
|
|
11
|
-
path: "/",
|
|
12
|
-
schema: (0, superstruct_1.object)({
|
|
13
|
-
queryParam: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
14
|
-
}),
|
|
15
|
-
},
|
|
16
|
-
manyParameters: {
|
|
17
|
-
path: "/many-parameters/[param1]/form/[param2]",
|
|
18
|
-
schema: (0, superstruct_1.object)({
|
|
19
|
-
param1: (0, superstruct_1.string)(),
|
|
20
|
-
param2: (0, superstruct_1.string)(),
|
|
21
|
-
queryParam1: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
22
|
-
queryParam2: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
23
|
-
}),
|
|
24
|
-
},
|
|
25
|
-
catchAllSegments: {
|
|
26
|
-
path: "/catch-all/[...pathParams]",
|
|
27
|
-
schema: (0, superstruct_1.object)({
|
|
28
|
-
pathParams: (0, superstruct_2.array)((0, superstruct_1.string)()),
|
|
29
|
-
queryParam: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
optionalCatchAllSegments: {
|
|
33
|
-
path: "/catch-all-optional/[[...pathParams]]",
|
|
34
|
-
schema: (0, superstruct_1.object)({
|
|
35
|
-
pathParams: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.union)([(0, superstruct_2.array)((0, superstruct_1.string)()), (0, superstruct_1.string)()]))),
|
|
36
|
-
queryParam: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
37
|
-
}),
|
|
38
|
-
},
|
|
39
|
-
routeWithoutParams: {
|
|
40
|
-
path: "/route-without-params",
|
|
41
|
-
},
|
|
42
|
-
localizedRouteWithoutParams: {
|
|
43
|
-
path: {
|
|
44
|
-
cs: "/lokalizovany-odkaz",
|
|
45
|
-
en: "/localized-url",
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
localizedRouteWithParams: {
|
|
49
|
-
path: {
|
|
50
|
-
cs: "/lokalizovany-odkaz-s-parametry",
|
|
51
|
-
en: "/localized-url-with-parameters",
|
|
52
|
-
},
|
|
53
|
-
schema: (0, superstruct_1.object)({
|
|
54
|
-
test: (0, superstruct_1.string)(),
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
57
|
-
}, {
|
|
58
|
-
locales: ["cs", "en"],
|
|
59
|
-
baseUrl: "https://www.uxf.cz",
|
|
60
|
-
});
|
|
61
|
-
const DATA = [
|
|
62
|
-
{
|
|
63
|
-
actual: routeToUrl("index", {}),
|
|
64
|
-
expected: "/",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
actual: routeToUrl("index", { queryParam: "value" }),
|
|
68
|
-
expected: "/?queryParam=value",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
actual: routeToUrl("catchAllSegments", { pathParams: ["param1", "param2"] }),
|
|
72
|
-
expected: "/catch-all/param1/param2",
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
actual: routeToUrl("catchAllSegments", { pathParams: ["param1", "param2"], queryParam: "value" }),
|
|
76
|
-
expected: "/catch-all/param1/param2?queryParam=value",
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
actual: routeToUrl("optionalCatchAllSegments", { pathParams: ["param1", "param2"], queryParam: "value" }),
|
|
80
|
-
expected: "/catch-all-optional/param1/param2?queryParam=value",
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
actual: routeToUrl("optionalCatchAllSegments", { pathParams: [] }),
|
|
84
|
-
expected: "/catch-all-optional",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
actual: routeToUrl("optionalCatchAllSegments", { pathParams: null }),
|
|
88
|
-
expected: "/catch-all-optional",
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
actual: routeToUrl("optionalCatchAllSegments", { pathParams: undefined }),
|
|
92
|
-
expected: "/catch-all-optional",
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
actual: routeToUrl("optionalCatchAllSegments", { pathParams: "" }),
|
|
96
|
-
expected: "/catch-all-optional",
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
actual: routeToUrl("optionalCatchAllSegments", { pathParams: "", queryParam: "value" }),
|
|
100
|
-
expected: "/catch-all-optional?queryParam=value",
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
// key omitted entirely — the optional segment must still be stripped
|
|
104
|
-
actual: routeToUrl("optionalCatchAllSegments", {}),
|
|
105
|
-
expected: "/catch-all-optional",
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
// key omitted but a query param is present
|
|
109
|
-
actual: routeToUrl("optionalCatchAllSegments", { queryParam: "value" }),
|
|
110
|
-
expected: "/catch-all-optional?queryParam=value",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
actual: routeToUrl("routeWithoutParams"),
|
|
114
|
-
expected: "/route-without-params",
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
actual: routeToUrl("localizedRouteWithoutParams", null, { locale: "en" }),
|
|
118
|
-
expected: "/localized-url",
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
actual: routeToUrl("localizedRouteWithoutParams", null, { locale: "cs" }),
|
|
122
|
-
expected: "/lokalizovany-odkaz",
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
actual: routeToUrl("localizedRouteWithParams", { test: "value" }, { locale: "en" }),
|
|
126
|
-
expected: "/localized-url-with-parameters?test=value",
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
actual: routeToUrl("localizedRouteWithParams", { test: "value" }, { locale: "cs" }),
|
|
130
|
-
expected: "/lokalizovany-odkaz-s-parametry?test=value",
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
actual: routeToUrl("index", { queryParam: "value" }, { shouldBeAbsolute: true }),
|
|
134
|
-
expected: "https://www.uxf.cz/?queryParam=value",
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
actual: routeToUrl("routeWithoutParams", null, { shouldBeAbsolute: true }),
|
|
138
|
-
expected: "https://www.uxf.cz/route-without-params",
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
actual: routeToUrl("localizedRouteWithoutParams", null, { locale: "cs", shouldBeAbsolute: true }),
|
|
142
|
-
expected: "https://www.uxf.cz/lokalizovany-odkaz",
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
actual: routeToUrl("localizedRouteWithParams", { test: "value" }, { locale: "en", shouldBeAbsolute: true }),
|
|
146
|
-
expected: "https://www.uxf.cz/localized-url-with-parameters?test=value",
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
test("routeToUrl", () => {
|
|
150
|
-
DATA.map(({ actual, expected }) => expect(actual).toBe(expected));
|
|
151
|
-
});
|
|
152
|
-
test("routeToUrl throws when a required param is missing", () => {
|
|
153
|
-
expect(() =>
|
|
154
|
-
// @ts-expect-error param2 is required, so this call is invalid on purpose — the point is the runtime guard
|
|
155
|
-
routeToUrl("manyParameters", { param1: "value-1" })).toThrow("Missing parameter '[param2]' for route 'manyParameters'.");
|
|
156
|
-
expect(() =>
|
|
157
|
-
// @ts-expect-error pathParams is required, so this call is invalid on purpose — the point is the runtime guard
|
|
158
|
-
routeToUrl("catchAllSegments", {})).toThrow("Missing parameter '[...pathParams]' for route 'catchAllSegments'.");
|
|
159
|
-
});
|
|
160
|
-
test('routeToUrl puts "$" in a param value literally', () => {
|
|
161
|
-
expect(routeToUrl("manyParameters", { param1: "a$&b", param2: "$$" })).toBe("/many-parameters/a$&b/form/$$");
|
|
162
|
-
expect(routeToUrl("catchAllSegments", { pathParams: ["x$`y"] })).toBe("/catch-all/x$`y");
|
|
163
|
-
expect(routeToUrl("optionalCatchAllSegments", { pathParams: ["$'"] })).toBe("/catch-all-optional/$'");
|
|
164
|
-
});
|
|
165
|
-
test("create route matcher", () => {
|
|
166
|
-
expect(createRouteMatcher("manyParameters", { param1: "value-1" })("/many-parameters/value-1/form/any", {
|
|
167
|
-
param1: "value-1",
|
|
168
|
-
param2: "any",
|
|
169
|
-
})).toBe(true);
|
|
170
|
-
expect(createRouteMatcher("manyParameters", { param1: "value-1" })("/many-parameters/any/form/any", {
|
|
171
|
-
param1: "any",
|
|
172
|
-
param2: "any",
|
|
173
|
-
})).toBe(false);
|
|
174
|
-
expect(createRouteMatcher("manyParameters", { param1: "value-1" })("/many-parameters/value-1/form/any", {
|
|
175
|
-
param1: "value-1",
|
|
176
|
-
param2: "any",
|
|
177
|
-
})).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
test("merge route matchers", () => {
|
|
180
|
-
const routeMatcher1 = createRouteMatcher("manyParameters", { param1: "value-1" });
|
|
181
|
-
const routeMatcher2 = createRouteMatcher("manyParameters", { param1: "value-2" });
|
|
182
|
-
const routeMatcher = (0, merge_route_matchers_1.mergeRouteMatchers)([routeMatcher1, routeMatcher2]);
|
|
183
|
-
expect(routeMatcher("/many-parameters/value-1/form/any", {
|
|
184
|
-
param1: "value-1",
|
|
185
|
-
param2: "any",
|
|
186
|
-
})).toBe(true);
|
|
187
|
-
expect(routeMatcher("/many-parameters/value-2/form/any", {
|
|
188
|
-
param1: "value-2",
|
|
189
|
-
param2: "any",
|
|
190
|
-
})).toBe(true);
|
|
191
|
-
expect(routeMatcher("/many-parameters/value-3/form/any", {
|
|
192
|
-
param1: "value-3",
|
|
193
|
-
param2: "any",
|
|
194
|
-
})).toBe(false);
|
|
195
|
-
});
|
|
196
|
-
// Guards the RSC-safety invariant: the router must not pull in any client-only modules.
|
|
197
|
-
test("create-router has no client-only imports", () => {
|
|
198
|
-
const source = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, "create-router.ts"), "utf8");
|
|
199
|
-
expect(source).not.toMatch(/from "next\/navigation"/);
|
|
200
|
-
expect(source).not.toMatch(/from "next\/router"/);
|
|
201
|
-
expect(source).not.toMatch(/from "react"/);
|
|
202
|
-
expect(source).not.toMatch(/from "react-dom"/);
|
|
203
|
-
});
|
|
204
|
-
describe("getRouteInfo", () => {
|
|
205
|
-
const { getRouteInfo, createRouteMatcher: matcher } = (0, create_router_1.createRouter)({
|
|
206
|
-
hotelDetail: { path: "/hotel/[hotel-id]" },
|
|
207
|
-
hotelEdit: { path: "/hotel/[hotel-id]/edit" },
|
|
208
|
-
hotelTab: { path: "/hotel/[hotel-id]/[tab]" },
|
|
209
|
-
hotelCreate: { path: "/hotel/create-hotel" },
|
|
210
|
-
hotelCatchAll: { path: "/hotel/[...rest]" },
|
|
211
|
-
}, {});
|
|
212
|
-
it("resolves a static path declared after a matching dynamic one", () => {
|
|
213
|
-
var _a;
|
|
214
|
-
expect((_a = getRouteInfo("/hotel/create-hotel")) === null || _a === void 0 ? void 0 : _a.routeName).toBe("hotelCreate");
|
|
215
|
-
});
|
|
216
|
-
it("resolves dynamic paths", () => {
|
|
217
|
-
var _a, _b, _c;
|
|
218
|
-
expect((_a = getRouteInfo("/hotel/12")) === null || _a === void 0 ? void 0 : _a.routeName).toBe("hotelDetail");
|
|
219
|
-
expect((_b = getRouteInfo("/hotel/12/edit")) === null || _b === void 0 ? void 0 : _b.routeName).toBe("hotelEdit");
|
|
220
|
-
expect((_c = getRouteInfo("/hotel/12/rooms")) === null || _c === void 0 ? void 0 : _c.routeName).toBe("hotelTab");
|
|
221
|
-
});
|
|
222
|
-
it("falls back to a catch-all only when nothing more specific matches", () => {
|
|
223
|
-
var _a;
|
|
224
|
-
expect((_a = getRouteInfo("/hotel/12/a/b")) === null || _a === void 0 ? void 0 : _a.routeName).toBe("hotelCatchAll");
|
|
225
|
-
});
|
|
226
|
-
it("returns null when nothing matches", () => {
|
|
227
|
-
expect(getRouteInfo("/not-a-route")).toBeNull();
|
|
228
|
-
});
|
|
229
|
-
it("exposes the matched route definition", () => {
|
|
230
|
-
var _a;
|
|
231
|
-
expect((_a = getRouteInfo("/hotel/create-hotel")) === null || _a === void 0 ? void 0 : _a.routeDefinition.path).toBe("/hotel/create-hotel");
|
|
232
|
-
});
|
|
233
|
-
it("makes createRouteMatcher agree with getRouteInfo", () => {
|
|
234
|
-
expect(matcher("hotelCreate")("/hotel/create-hotel")).toBe(true);
|
|
235
|
-
expect(matcher("hotelDetail")("/hotel/create-hotel")).toBe(false);
|
|
236
|
-
});
|
|
237
|
-
});
|
package/helper.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/helper.test.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helper_1 = require("./helper");
|
|
4
|
-
describe("Query Parameter Functions", () => {
|
|
5
|
-
describe("queryParamToString", () => {
|
|
6
|
-
it("should return the string when provided", () => {
|
|
7
|
-
expect((0, helper_1.queryParamToString)("test")).toBe("test");
|
|
8
|
-
});
|
|
9
|
-
it("should return undefined when provided as undefined", () => {
|
|
10
|
-
expect((0, helper_1.queryParamToString)(undefined)).toBeUndefined();
|
|
11
|
-
});
|
|
12
|
-
it("should throw an error when provided an array", () => {
|
|
13
|
-
expect(() => (0, helper_1.queryParamToString)(["test"])).toThrow("Query parameter is array. Should be string.");
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe("queryParamToStringStrict", () => {
|
|
17
|
-
it("should return the string when provided", () => {
|
|
18
|
-
expect((0, helper_1.queryParamToStringStrict)("test")).toBe("test");
|
|
19
|
-
});
|
|
20
|
-
it("should throw an error when provided as undefined", () => {
|
|
21
|
-
expect(() => (0, helper_1.queryParamToStringStrict)(undefined)).toThrow("Parameter not found.");
|
|
22
|
-
});
|
|
23
|
-
it("should throw an error when provided an array", () => {
|
|
24
|
-
expect(() => (0, helper_1.queryParamToStringStrict)(["test"])).toThrow("Query parameter is array. Should be string.");
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe("queryParamToBoolean", () => {
|
|
28
|
-
it('should return true when provided as "true"', () => {
|
|
29
|
-
expect((0, helper_1.queryParamToBoolean)("true")).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
it('should return false when provided as "false"', () => {
|
|
32
|
-
expect((0, helper_1.queryParamToBoolean)("false")).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
it("should return undefined when provided as undefined", () => {
|
|
35
|
-
expect((0, helper_1.queryParamToBoolean)(undefined)).toBeUndefined();
|
|
36
|
-
});
|
|
37
|
-
it("should throw an error when provided as an invalid boolean string", () => {
|
|
38
|
-
expect(() => (0, helper_1.queryParamToBoolean)("invalid")).toThrow("Parameter should be boolean (true|false). Given 'invalid'.");
|
|
39
|
-
});
|
|
40
|
-
it("should throw an error when provided an array", () => {
|
|
41
|
-
expect(() => (0, helper_1.queryParamToBoolean)(["true"])).toThrow("Query parameter is array. Should be string.");
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
describe("queryParamToBooleanStrict", () => {
|
|
45
|
-
it('should return true when provided as "true"', () => {
|
|
46
|
-
expect((0, helper_1.queryParamToBooleanStrict)("true")).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
it('should return false when provided as "false"', () => {
|
|
49
|
-
expect((0, helper_1.queryParamToBooleanStrict)("false")).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
it("should throw an error when provided as undefined", () => {
|
|
52
|
-
expect(() => (0, helper_1.queryParamToBooleanStrict)(undefined)).toThrow("Parameter not found.");
|
|
53
|
-
});
|
|
54
|
-
it("should throw an error when provided an invalid boolean string", () => {
|
|
55
|
-
expect(() => (0, helper_1.queryParamToBooleanStrict)("invalid")).toThrow("Parameter should be boolean (true|false). Given 'invalid'.");
|
|
56
|
-
});
|
|
57
|
-
it("should throw an error when provided an array", () => {
|
|
58
|
-
expect(() => (0, helper_1.queryParamToBooleanStrict)(["true"])).toThrow("Query parameter is array. Should be string.");
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe("queryParamToNumber", () => {
|
|
62
|
-
it("should return a number when provided a valid string", () => {
|
|
63
|
-
expect((0, helper_1.queryParamToNumber)("123")).toBe(123);
|
|
64
|
-
});
|
|
65
|
-
it("should return undefined when provided as undefined", () => {
|
|
66
|
-
expect((0, helper_1.queryParamToNumber)(undefined)).toBeUndefined();
|
|
67
|
-
});
|
|
68
|
-
it("should throw an error when provided as an invalid number string", () => {
|
|
69
|
-
expect(() => (0, helper_1.queryParamToNumber)("invalid")).toThrow("Query parameter is NaN. Should be number.");
|
|
70
|
-
});
|
|
71
|
-
it("should throw an error when provided an array", () => {
|
|
72
|
-
expect(() => (0, helper_1.queryParamToNumber)(["123"])).toThrow("Query parameter is array. Should be number.");
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe("queryParamToNumberStrict", () => {
|
|
76
|
-
it("should return a number when provided a valid string", () => {
|
|
77
|
-
expect((0, helper_1.queryParamToNumberStrict)("123")).toBe(123);
|
|
78
|
-
});
|
|
79
|
-
it("should throw an error when provided as undefined", () => {
|
|
80
|
-
expect(() => (0, helper_1.queryParamToNumberStrict)(undefined)).toThrow("Parameter not found.");
|
|
81
|
-
});
|
|
82
|
-
it("should throw an error when provided as an invalid number string", () => {
|
|
83
|
-
expect(() => (0, helper_1.queryParamToNumberStrict)("invalid")).toThrow("Query parameter is NaN. Should be number.");
|
|
84
|
-
});
|
|
85
|
-
it("should throw an error when provided an array", () => {
|
|
86
|
-
expect(() => (0, helper_1.queryParamToNumberStrict)(["123"])).toThrow("Query parameter is array. Should be number.");
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const routes_check_1 = require("./routes-check");
|
|
5
|
-
describe("routesCheck", () => {
|
|
6
|
-
it("should be valid", () => {
|
|
7
|
-
expect(() => (0, routes_check_1.routesCheck)({
|
|
8
|
-
route1: { path: "/" }, // index
|
|
9
|
-
route2: { path: "/product" }, // index file
|
|
10
|
-
route3: { path: "/product/edit" }, // file with specific name
|
|
11
|
-
route4: { path: "/product/[id]" }, // path parameter, file with specific name
|
|
12
|
-
route5: { path: "/product-2/[id]" }, // path parameter, index file
|
|
13
|
-
app1: { path: "/app-directory" },
|
|
14
|
-
app2: { path: "/app-directory/[param]" },
|
|
15
|
-
app3: { path: "/api" },
|
|
16
|
-
app4: { path: "/grouped-route" }, // page lives inside a (group) folder
|
|
17
|
-
app5: { path: "/nested/deep" }, // page lives inside nested (group) folders
|
|
18
|
-
}, {
|
|
19
|
-
shouldProcessExit: false,
|
|
20
|
-
appDir: (0, path_1.join)(__dirname, "__test__", "app"),
|
|
21
|
-
pagesDir: (0, path_1.join)(__dirname, "__test__", "pages"),
|
|
22
|
-
})).not.toThrow();
|
|
23
|
-
});
|
|
24
|
-
it("should fail", () => {
|
|
25
|
-
expect(() => (0, routes_check_1.routesCheck)({
|
|
26
|
-
unknown: { path: "/unknown-route" }, // index
|
|
27
|
-
}, {
|
|
28
|
-
shouldProcessExit: false,
|
|
29
|
-
appDir: (0, path_1.join)(__dirname, "__test__", "app"),
|
|
30
|
-
pagesDir: (0, path_1.join)(__dirname, "__test__", "pages"),
|
|
31
|
-
})).toThrow();
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const superstruct_1 = require("superstruct");
|
|
4
|
-
const create_router_1 = require("./create-router");
|
|
5
|
-
const { createSitemapGenerator, routeToUrl } = (0, create_router_1.createRouter)({
|
|
6
|
-
index: {
|
|
7
|
-
path: "/",
|
|
8
|
-
schema: (0, superstruct_1.object)({
|
|
9
|
-
queryParam: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
10
|
-
}),
|
|
11
|
-
},
|
|
12
|
-
skippedRoute: {
|
|
13
|
-
path: "/skipped",
|
|
14
|
-
},
|
|
15
|
-
catchAllSegments: {
|
|
16
|
-
path: "/catch-all/[...pathParams]",
|
|
17
|
-
schema: (0, superstruct_1.object)({
|
|
18
|
-
pathParams: (0, superstruct_1.array)(),
|
|
19
|
-
queryParam: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
optionalCatchAllSegments: {
|
|
23
|
-
path: "/catch-all-optional/[[...pathParams]]",
|
|
24
|
-
schema: (0, superstruct_1.object)({
|
|
25
|
-
pathParams: (0, superstruct_1.optional)((0, superstruct_1.nullable)((0, superstruct_1.union)([(0, superstruct_1.array)(), (0, superstruct_1.string)()]))),
|
|
26
|
-
queryParam: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
27
|
-
}),
|
|
28
|
-
},
|
|
29
|
-
}, { baseUrl: "https://www.uxf.cz" });
|
|
30
|
-
const BASE_URL = "www.uxf.cz";
|
|
31
|
-
test("routeToUrl", async () => {
|
|
32
|
-
const xml = await createSitemapGenerator({
|
|
33
|
-
index: async (route) => ({ loc: routeToUrl(route, { queryParam: "test" }) }),
|
|
34
|
-
catchAllSegments: async (route) => ({ loc: routeToUrl(route, { pathParams: ["param-1"] }) }),
|
|
35
|
-
optionalCatchAllSegments: async (route) => ({
|
|
36
|
-
loc: routeToUrl(route, { pathParams: ["param-1", "param-2"] }),
|
|
37
|
-
priority: 10,
|
|
38
|
-
}),
|
|
39
|
-
skippedRoute: null,
|
|
40
|
-
}, {
|
|
41
|
-
baseUrl: BASE_URL,
|
|
42
|
-
}).toXml();
|
|
43
|
-
expect(xml).toBe(`<?xml version="1.0" encoding="UTF-8"?>
|
|
44
|
-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
|
45
|
-
<url>
|
|
46
|
-
<loc>${BASE_URL}/?queryParam=test</loc>
|
|
47
|
-
</url>
|
|
48
|
-
<url>
|
|
49
|
-
<loc>${BASE_URL}/catch-all/param-1</loc>
|
|
50
|
-
</url>
|
|
51
|
-
<url>
|
|
52
|
-
<loc>${BASE_URL}/catch-all-optional/param-1/param-2</loc>
|
|
53
|
-
<priority>10</priority>
|
|
54
|
-
</url>
|
|
55
|
-
</urlset>`);
|
|
56
|
-
});
|
package/superstruct/array.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Infer, Struct } from "superstruct";
|
|
2
|
-
/**
|
|
3
|
-
* NextJS používá následující zápis pole v url `?item=a&item=b&item=c`
|
|
4
|
-
*
|
|
5
|
-
* Není teda schopen rozeznat, zda parametr `?item=a` je pole o jednom prvku nebo pouze string
|
|
6
|
-
*/
|
|
7
|
-
export declare function array<T extends Struct<any>>(inner: T): Struct<Infer<T>[], null>;
|
package/superstruct/array.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.array = array;
|
|
4
|
-
const superstruct_1 = require("superstruct");
|
|
5
|
-
/**
|
|
6
|
-
* NextJS používá následující zápis pole v url `?item=a&item=b&item=c`
|
|
7
|
-
*
|
|
8
|
-
* Není teda schopen rozeznat, zda parametr `?item=a` je pole o jednom prvku nebo pouze string
|
|
9
|
-
*/
|
|
10
|
-
function array(inner) {
|
|
11
|
-
return (0, superstruct_1.coerce)((0, superstruct_1.array)(inner), (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.array)((0, superstruct_1.string)())]), (value) => {
|
|
12
|
-
return Array.isArray(value) ? value : [value];
|
|
13
|
-
});
|
|
14
|
-
}
|
package/superstruct/boolean.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const boolean: () => import("superstruct").Struct<boolean, null>;
|
package/superstruct/boolean.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.boolean = void 0;
|
|
4
|
-
const superstruct_1 = require("superstruct");
|
|
5
|
-
const boolean = () => (0, superstruct_1.coerce)((0, superstruct_1.boolean)(), (0, superstruct_1.string)(), (value) => {
|
|
6
|
-
return value === "1" || value === "true" || value === "";
|
|
7
|
-
});
|
|
8
|
-
exports.boolean = boolean;
|
package/superstruct/integer.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const integer: () => import("superstruct").Struct<number, null>;
|
package/superstruct/integer.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.integer = void 0;
|
|
4
|
-
const superstruct_1 = require("superstruct");
|
|
5
|
-
const integer = () => (0, superstruct_1.coerce)((0, superstruct_1.integer)(), (0, superstruct_1.string)(), (value) => {
|
|
6
|
-
const parsed = parseInt(value, 10);
|
|
7
|
-
if (isNaN(parsed)) {
|
|
8
|
-
throw new Error("Invalid number string");
|
|
9
|
-
}
|
|
10
|
-
return parsed;
|
|
11
|
-
});
|
|
12
|
-
exports.integer = integer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const object_to_xml_1 = require("./object-to-xml");
|
|
4
|
-
describe("objectToXml", () => {
|
|
5
|
-
it("should convert a simple object to XML format", () => {
|
|
6
|
-
const input = {
|
|
7
|
-
name: "John Doe",
|
|
8
|
-
age: 30,
|
|
9
|
-
city: "New York",
|
|
10
|
-
};
|
|
11
|
-
const expectedOutput = ` <name>John Doe</name>
|
|
12
|
-
<age>30</age>
|
|
13
|
-
<city>New York</city>`;
|
|
14
|
-
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
15
|
-
});
|
|
16
|
-
it("should ignore null and undefined values", () => {
|
|
17
|
-
const input = {
|
|
18
|
-
name: "John Doe",
|
|
19
|
-
age: null,
|
|
20
|
-
city: undefined,
|
|
21
|
-
country: "USA",
|
|
22
|
-
};
|
|
23
|
-
const expectedOutput = ` <name>John Doe</name>
|
|
24
|
-
<country>USA</country>`;
|
|
25
|
-
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
26
|
-
});
|
|
27
|
-
it("should handle empty objects", () => {
|
|
28
|
-
const input = {};
|
|
29
|
-
const expectedOutput = "";
|
|
30
|
-
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
31
|
-
});
|
|
32
|
-
it("should handle numeric values", () => {
|
|
33
|
-
const input = {
|
|
34
|
-
a: 1,
|
|
35
|
-
b: 2.5,
|
|
36
|
-
c: 0,
|
|
37
|
-
};
|
|
38
|
-
const expectedOutput = ` <a>1</a>
|
|
39
|
-
<b>2.5</b>
|
|
40
|
-
<c>0</c>`;
|
|
41
|
-
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|