@remix-run/router 0.0.0-experimental-0141b5ec → 0.0.0-experimental-432fcb2e
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/index.d.ts +2 -2
- package/dist/router.cjs.js +35 -54
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +36 -51
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +35 -54
- 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 +3 -20
- package/index.ts +1 -2
- package/package.json +1 -1
- package/router.ts +30 -38
- package/utils.ts +3 -42
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
|
|
2
|
-
export { AbortedDeferredError,
|
|
1
|
+
export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
|
|
2
|
+
export { AbortedDeferredError, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
|
|
3
3
|
export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
|
|
4
4
|
export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
|
|
5
5
|
export * from "./router";
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v0.0.0-experimental-
|
|
2
|
+
* @remix-run/router v0.0.0-experimental-432fcb2e
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -1519,22 +1519,6 @@ class ErrorResponseImpl {
|
|
|
1519
1519
|
}
|
|
1520
1520
|
}
|
|
1521
1521
|
|
|
1522
|
-
/**
|
|
1523
|
-
* Utility class we use to hold unwrapped Responses while preserving status
|
|
1524
|
-
* codes and headers. This is most useful for dataStrategy implementations
|
|
1525
|
-
* where implementors want to use a custom decoding mechanism and return
|
|
1526
|
-
* pre-decoded data while also preserving response meta information
|
|
1527
|
-
*/
|
|
1528
|
-
class DecodedResponse {
|
|
1529
|
-
constructor(status, statusText, headers, data) {
|
|
1530
|
-
this._isDecodedResponse = true;
|
|
1531
|
-
this.status = status;
|
|
1532
|
-
this.statusText = statusText;
|
|
1533
|
-
this.headers = headers;
|
|
1534
|
-
this.data = data;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
1522
|
/**
|
|
1539
1523
|
* Check if the given error is an ErrorResponse generated from a 4xx/5xx
|
|
1540
1524
|
* Response thrown from an action/loader
|
|
@@ -1543,13 +1527,6 @@ function isRouteErrorResponse(error) {
|
|
|
1543
1527
|
return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
|
1544
1528
|
}
|
|
1545
1529
|
|
|
1546
|
-
/**
|
|
1547
|
-
* Check if the given error is an DecodedResponse
|
|
1548
|
-
*/
|
|
1549
|
-
function isDecodedResponse(value) {
|
|
1550
|
-
return value != null && value._isDecodedResponse === true && typeof value.status === "number" && typeof value.statusText === "string" && value.headers != null && "data" in value;
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
1530
|
////////////////////////////////////////////////////////////////////////////////
|
|
1554
1531
|
//#region Types and Constants
|
|
1555
1532
|
////////////////////////////////////////////////////////////////////////////////
|
|
@@ -4223,10 +4200,12 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
|
|
|
4223
4200
|
let runHandler = handler => {
|
|
4224
4201
|
// Setup a promise we can race against so that abort signals short circuit
|
|
4225
4202
|
let reject;
|
|
4203
|
+
// This will never resolve so safe to type it as Promise<HandlerResult> to
|
|
4204
|
+
// satisfy the function return value
|
|
4226
4205
|
let abortPromise = new Promise((_, r) => reject = r);
|
|
4227
4206
|
onReject = () => reject();
|
|
4228
4207
|
request.signal.addEventListener("abort", onReject);
|
|
4229
|
-
let
|
|
4208
|
+
let actualHandler = ctx => {
|
|
4230
4209
|
if (typeof handler !== "function") {
|
|
4231
4210
|
return Promise.reject(new Error("You cannot call the handler for a route which defines a boolean " + ("\"" + type + "\" [routeId: " + match.route.id + "]")));
|
|
4232
4211
|
}
|
|
@@ -4236,7 +4215,25 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
|
|
|
4236
4215
|
context: staticContext
|
|
4237
4216
|
}, ...(ctx !== undefined ? [ctx] : []));
|
|
4238
4217
|
};
|
|
4239
|
-
let handlerPromise
|
|
4218
|
+
let handlerPromise;
|
|
4219
|
+
if (handlerOverride) {
|
|
4220
|
+
handlerPromise = handlerOverride(ctx => actualHandler(ctx));
|
|
4221
|
+
} else {
|
|
4222
|
+
handlerPromise = (async () => {
|
|
4223
|
+
try {
|
|
4224
|
+
let val = await actualHandler();
|
|
4225
|
+
return {
|
|
4226
|
+
type: "data",
|
|
4227
|
+
result: val
|
|
4228
|
+
};
|
|
4229
|
+
} catch (e) {
|
|
4230
|
+
return {
|
|
4231
|
+
type: "error",
|
|
4232
|
+
result: e
|
|
4233
|
+
};
|
|
4234
|
+
}
|
|
4235
|
+
})();
|
|
4236
|
+
}
|
|
4240
4237
|
return Promise.race([handlerPromise, abortPromise]);
|
|
4241
4238
|
};
|
|
4242
4239
|
try {
|
|
@@ -4291,8 +4288,11 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
|
|
|
4291
4288
|
} else {
|
|
4292
4289
|
result = await runHandler(handler);
|
|
4293
4290
|
}
|
|
4294
|
-
invariant(result !== undefined, "You defined " + (type === "action" ? "an action" : "a loader") + " for route " + ("\"" + match.route.id + "\" but didn't return anything from your `" + type + "` ") + "function. Please return a value or `null`.");
|
|
4291
|
+
invariant(result.result !== undefined, "You defined " + (type === "action" ? "an action" : "a loader") + " for route " + ("\"" + match.route.id + "\" but didn't return anything from your `" + type + "` ") + "function. Please return a value or `null`.");
|
|
4295
4292
|
} catch (e) {
|
|
4293
|
+
// We should already be catching and converting normal handler executions to
|
|
4294
|
+
// HandlerResults and returning them, so anything that throws here is an
|
|
4295
|
+
// unexpected error we still need to wrap
|
|
4296
4296
|
return {
|
|
4297
4297
|
type: ResultType.error,
|
|
4298
4298
|
result: e
|
|
@@ -4302,15 +4302,13 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
|
|
|
4302
4302
|
request.signal.removeEventListener("abort", onReject);
|
|
4303
4303
|
}
|
|
4304
4304
|
}
|
|
4305
|
-
return
|
|
4306
|
-
type: ResultType.data,
|
|
4307
|
-
result
|
|
4308
|
-
};
|
|
4305
|
+
return result;
|
|
4309
4306
|
}
|
|
4310
4307
|
async function convertHandlerResultToDataResult(handlerResult) {
|
|
4311
4308
|
let {
|
|
4312
4309
|
result,
|
|
4313
|
-
type
|
|
4310
|
+
type,
|
|
4311
|
+
status
|
|
4314
4312
|
} = handlerResult;
|
|
4315
4313
|
if (isResponse(result)) {
|
|
4316
4314
|
let data;
|
|
@@ -4335,7 +4333,7 @@ async function convertHandlerResultToDataResult(handlerResult) {
|
|
|
4335
4333
|
}
|
|
4336
4334
|
if (type === ResultType.error) {
|
|
4337
4335
|
return {
|
|
4338
|
-
type,
|
|
4336
|
+
type: ResultType.error,
|
|
4339
4337
|
error: new ErrorResponseImpl(result.status, result.statusText, data),
|
|
4340
4338
|
statusCode: result.status,
|
|
4341
4339
|
headers: result.headers
|
|
@@ -4348,27 +4346,11 @@ async function convertHandlerResultToDataResult(handlerResult) {
|
|
|
4348
4346
|
headers: result.headers
|
|
4349
4347
|
};
|
|
4350
4348
|
}
|
|
4351
|
-
if (isDecodedResponse(result)) {
|
|
4352
|
-
if (type === ResultType.error) {
|
|
4353
|
-
return {
|
|
4354
|
-
type,
|
|
4355
|
-
error: new ErrorResponseImpl(result.status, result.statusText, result.data),
|
|
4356
|
-
statusCode: result.status,
|
|
4357
|
-
headers: result.headers
|
|
4358
|
-
};
|
|
4359
|
-
}
|
|
4360
|
-
return {
|
|
4361
|
-
type: ResultType.data,
|
|
4362
|
-
data: result.data,
|
|
4363
|
-
statusCode: result.status,
|
|
4364
|
-
headers: result.headers
|
|
4365
|
-
};
|
|
4366
|
-
}
|
|
4367
4349
|
if (type === ResultType.error) {
|
|
4368
4350
|
return {
|
|
4369
|
-
type,
|
|
4351
|
+
type: ResultType.error,
|
|
4370
4352
|
error: result,
|
|
4371
|
-
statusCode: isRouteErrorResponse(result) ? result.status :
|
|
4353
|
+
statusCode: isRouteErrorResponse(result) ? result.status : status
|
|
4372
4354
|
};
|
|
4373
4355
|
}
|
|
4374
4356
|
if (isDeferredData(result)) {
|
|
@@ -4382,7 +4364,8 @@ async function convertHandlerResultToDataResult(handlerResult) {
|
|
|
4382
4364
|
}
|
|
4383
4365
|
return {
|
|
4384
4366
|
type: ResultType.data,
|
|
4385
|
-
data: result
|
|
4367
|
+
data: result,
|
|
4368
|
+
statusCode: status
|
|
4386
4369
|
};
|
|
4387
4370
|
}
|
|
4388
4371
|
|
|
@@ -5012,6 +4995,4 @@ exports.redirectDocument = redirectDocument;
|
|
|
5012
4995
|
exports.resolvePath = resolvePath;
|
|
5013
4996
|
exports.resolveTo = resolveTo;
|
|
5014
4997
|
exports.stripBasename = stripBasename;
|
|
5015
|
-
exports.unstable_DecodedResponse = DecodedResponse;
|
|
5016
|
-
exports.unstable_isDecodedResponse = isDecodedResponse;
|
|
5017
4998
|
//# sourceMappingURL=router.cjs.js.map
|