@remix-run/router 0.0.0-experimental-e960cf1a → 0.0.0-experimental-bc2c864b
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/CHANGELOG.md +199 -8
- package/dist/index.d.ts +2 -2
- package/dist/router.cjs.js +290 -257
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +2 -1
- package/dist/router.js +279 -244
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +290 -257
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/dist/utils.d.ts +19 -19
- package/index.ts +1 -3
- package/package.json +1 -1
- package/router.ts +453 -405
- package/utils.ts +44 -33
package/utils.ts
CHANGED
|
@@ -21,8 +21,7 @@ export enum ResultType {
|
|
|
21
21
|
export interface SuccessResult {
|
|
22
22
|
type: ResultType.data;
|
|
23
23
|
data: any;
|
|
24
|
-
|
|
25
|
-
headers?: Headers;
|
|
24
|
+
response?: Response;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -40,10 +39,7 @@ export interface DeferredResult {
|
|
|
40
39
|
*/
|
|
41
40
|
export interface RedirectResult {
|
|
42
41
|
type: ResultType.redirect;
|
|
43
|
-
|
|
44
|
-
location: string;
|
|
45
|
-
revalidate: boolean;
|
|
46
|
-
reloadDocument?: boolean;
|
|
42
|
+
response: Response;
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
/**
|
|
@@ -52,7 +48,7 @@ export interface RedirectResult {
|
|
|
52
48
|
export interface ErrorResult {
|
|
53
49
|
type: ResultType.error;
|
|
54
50
|
error: any;
|
|
55
|
-
|
|
51
|
+
response?: Response;
|
|
56
52
|
}
|
|
57
53
|
|
|
58
54
|
/**
|
|
@@ -64,6 +60,14 @@ export type DataResult =
|
|
|
64
60
|
| RedirectResult
|
|
65
61
|
| ErrorResult;
|
|
66
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Result from a loader or action called via dataStrategy
|
|
65
|
+
*/
|
|
66
|
+
export interface HandlerResult {
|
|
67
|
+
type: ResultType.data | ResultType.error;
|
|
68
|
+
result: any; // data, Error, Response, DeferredData
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
68
72
|
type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
|
|
69
73
|
|
|
@@ -166,22 +170,26 @@ export interface ActionFunctionArgs<Context = any>
|
|
|
166
170
|
*/
|
|
167
171
|
type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
168
172
|
|
|
173
|
+
type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
|
|
174
|
+
|
|
169
175
|
/**
|
|
170
176
|
* Route loader function signature
|
|
171
177
|
*/
|
|
172
178
|
export type LoaderFunction<Context = any> = {
|
|
173
|
-
(
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
(
|
|
180
|
+
args: LoaderFunctionArgs<Context>,
|
|
181
|
+
handlerCtx?: unknown
|
|
182
|
+
): DataFunctionReturnValue;
|
|
176
183
|
} & { hydrate?: boolean };
|
|
177
184
|
|
|
178
185
|
/**
|
|
179
186
|
* Route action function signature
|
|
180
187
|
*/
|
|
181
188
|
export interface ActionFunction<Context = any> {
|
|
182
|
-
(
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
(
|
|
190
|
+
args: ActionFunctionArgs<Context>,
|
|
191
|
+
handlerCtx?: unknown
|
|
192
|
+
): DataFunctionReturnValue;
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
/**
|
|
@@ -223,15 +231,23 @@ export interface DetectErrorBoundaryFunction {
|
|
|
223
231
|
(route: AgnosticRouteObject): boolean;
|
|
224
232
|
}
|
|
225
233
|
|
|
226
|
-
export interface
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
234
|
+
export interface DataStrategyMatch
|
|
235
|
+
extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
|
|
236
|
+
// TODO: What to call these?
|
|
237
|
+
bikeshed_loadRoute: (
|
|
238
|
+
bikeshed_handlerOverride?: (
|
|
239
|
+
bikeshed_handler: (ctx?: unknown) => DataFunctionReturnValue
|
|
240
|
+
) => DataFunctionReturnValue
|
|
241
|
+
) => Promise<HandlerResult>;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface DataStrategyFunctionArgs<Context = any>
|
|
245
|
+
extends DataFunctionArgs<Context> {
|
|
246
|
+
matches: DataStrategyMatch[];
|
|
231
247
|
}
|
|
232
248
|
|
|
233
249
|
export interface DataStrategyFunction {
|
|
234
|
-
(args: DataStrategyFunctionArgs): Promise<
|
|
250
|
+
(args: DataStrategyFunctionArgs): Promise<HandlerResult[]>;
|
|
235
251
|
}
|
|
236
252
|
|
|
237
253
|
/**
|
|
@@ -412,14 +428,6 @@ export interface AgnosticRouteMatch<
|
|
|
412
428
|
export interface AgnosticDataRouteMatch
|
|
413
429
|
extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {}
|
|
414
430
|
|
|
415
|
-
export type LazyRoutePromise = PromiseLike<AgnosticDataRouteObject> &
|
|
416
|
-
AgnosticDataRouteObject;
|
|
417
|
-
|
|
418
|
-
export interface AgnosticDataStrategyMatch
|
|
419
|
-
extends Omit<AgnosticRouteMatch<string, AgnosticDataRouteObject>, "route"> {
|
|
420
|
-
route: LazyRoutePromise;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
431
|
function isIndexRoute(
|
|
424
432
|
route: AgnosticRouteObject
|
|
425
433
|
): route is AgnosticIndexRouteObject {
|
|
@@ -704,7 +712,7 @@ function rankRouteBranches(branches: RouteBranch[]): void {
|
|
|
704
712
|
);
|
|
705
713
|
}
|
|
706
714
|
|
|
707
|
-
const paramRe =
|
|
715
|
+
const paramRe = /^:[\w-]+$/;
|
|
708
716
|
const dynamicSegmentValue = 3;
|
|
709
717
|
const indexRouteValue = 2;
|
|
710
718
|
const emptySegmentValue = 1;
|
|
@@ -841,7 +849,7 @@ export function generatePath<Path extends string>(
|
|
|
841
849
|
return stringify(params[star]);
|
|
842
850
|
}
|
|
843
851
|
|
|
844
|
-
const keyMatch = segment.match(/^:(\w+)(\??)$/);
|
|
852
|
+
const keyMatch = segment.match(/^:([\w-]+)(\??)$/);
|
|
845
853
|
if (keyMatch) {
|
|
846
854
|
const [, key, optional] = keyMatch;
|
|
847
855
|
let param = params[key as PathParam<Path>];
|
|
@@ -986,10 +994,13 @@ function compilePath(
|
|
|
986
994
|
.replace(/\/*\*?$/, "") // Ignore trailing / and /*, we'll handle it below
|
|
987
995
|
.replace(/^\/*/, "/") // Make sure it has a leading /
|
|
988
996
|
.replace(/[\\.*+^${}|()[\]]/g, "\\$&") // Escape special regex chars
|
|
989
|
-
.replace(
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
997
|
+
.replace(
|
|
998
|
+
/\/:([\w-]+)(\?)?/g,
|
|
999
|
+
(_: string, paramName: string, isOptional) => {
|
|
1000
|
+
params.push({ paramName, isOptional: isOptional != null });
|
|
1001
|
+
return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
993
1004
|
|
|
994
1005
|
if (path.endsWith("*")) {
|
|
995
1006
|
params.push({ paramName: "*" });
|