@remix-run/router 0.0.0-experimental-cffa549a1 → 0.0.0-experimental-5df42afed

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction as unstable_DataStrategyFunction, DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs, DataStrategyMatch as unstable_DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, AgnosticPatchRoutesOnMissFunction as unstable_AgnosticPatchRoutesOnMissFunction, 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, replace, resolvePath, resolveTo, stripBasename, } from "./utils";
2
+ export { AbortedDeferredError, data as unstable_data, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, replace, 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";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-cffa549a1
2
+ * @remix-run/router v0.0.0-experimental-5df42afed
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1327,6 +1327,23 @@ const json = function json(data, init) {
1327
1327
  headers
1328
1328
  }));
1329
1329
  };
1330
+ class DataWithResponseInit {
1331
+ constructor(data, init) {
1332
+ this.type = "DataWithResponseInit";
1333
+ this.data = data;
1334
+ this.init = init || null;
1335
+ }
1336
+ }
1337
+
1338
+ /**
1339
+ * Create "responses" that contain `status`/`headers` without forcing
1340
+ * serialization into an actual `Response` - used by Remix single fetch
1341
+ */
1342
+ function data(data, init) {
1343
+ return new DataWithResponseInit(data, typeof init === "number" ? {
1344
+ status: init
1345
+ } : init);
1346
+ }
1330
1347
  class AbortedDeferredError extends Error {}
1331
1348
  class DeferredData {
1332
1349
  constructor(data, responseInit) {
@@ -4739,8 +4756,7 @@ async function callLoaderOrAction(type, request, match, manifest, mapRouteProper
4739
4756
  async function convertHandlerResultToDataResult(handlerResult) {
4740
4757
  let {
4741
4758
  result,
4742
- type,
4743
- status
4759
+ type
4744
4760
  } = handlerResult;
4745
4761
  if (isResponse(result)) {
4746
4762
  let data;
@@ -4779,25 +4795,38 @@ async function convertHandlerResultToDataResult(handlerResult) {
4779
4795
  };
4780
4796
  }
4781
4797
  if (type === ResultType.error) {
4798
+ if (isDataWithResponseInit(result)) {
4799
+ var _result$init;
4800
+ // Convert thrown unstable_data() to ErrorResponse instances
4801
+ result = new ErrorResponseImpl(((_result$init = result.init) == null ? void 0 : _result$init.status) || 500, undefined, result.data);
4802
+ }
4782
4803
  return {
4783
4804
  type: ResultType.error,
4784
4805
  error: result,
4785
- statusCode: isRouteErrorResponse(result) ? result.status : status
4806
+ statusCode: isRouteErrorResponse(result) ? result.status : undefined
4786
4807
  };
4787
4808
  }
4788
4809
  if (isDeferredData(result)) {
4789
- var _result$init, _result$init2;
4810
+ var _result$init2, _result$init3;
4790
4811
  return {
4791
4812
  type: ResultType.deferred,
4792
4813
  deferredData: result,
4793
- statusCode: (_result$init = result.init) == null ? void 0 : _result$init.status,
4794
- headers: ((_result$init2 = result.init) == null ? void 0 : _result$init2.headers) && new Headers(result.init.headers)
4814
+ statusCode: (_result$init2 = result.init) == null ? void 0 : _result$init2.status,
4815
+ headers: ((_result$init3 = result.init) == null ? void 0 : _result$init3.headers) && new Headers(result.init.headers)
4816
+ };
4817
+ }
4818
+ if (isDataWithResponseInit(result)) {
4819
+ var _result$init4, _result$init5;
4820
+ return {
4821
+ type: ResultType.data,
4822
+ data: result.data,
4823
+ statusCode: (_result$init4 = result.init) == null ? void 0 : _result$init4.status,
4824
+ headers: (_result$init5 = result.init) != null && _result$init5.headers ? new Headers(result.init.headers) : undefined
4795
4825
  };
4796
4826
  }
4797
4827
  return {
4798
4828
  type: ResultType.data,
4799
- data: result,
4800
- statusCode: status
4829
+ data: result
4801
4830
  };
4802
4831
  }
4803
4832
 
@@ -5160,6 +5189,9 @@ function isErrorResult(result) {
5160
5189
  function isRedirectResult(result) {
5161
5190
  return (result && result.type) === ResultType.redirect;
5162
5191
  }
5192
+ function isDataWithResponseInit(value) {
5193
+ return typeof value === "object" && value != null && "type" in value && "data" in value && "init" in value && value.type === "DataWithResponseInit";
5194
+ }
5163
5195
  function isDeferredData(value) {
5164
5196
  let deferred = value;
5165
5197
  return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
@@ -5436,6 +5468,7 @@ exports.defer = defer;
5436
5468
  exports.generatePath = generatePath;
5437
5469
  exports.getStaticContextFromError = getStaticContextFromError;
5438
5470
  exports.getToPathname = getToPathname;
5471
+ exports.isDataWithResponseInit = isDataWithResponseInit;
5439
5472
  exports.isDeferredData = isDeferredData;
5440
5473
  exports.isRouteErrorResponse = isRouteErrorResponse;
5441
5474
  exports.joinPaths = joinPaths;
@@ -5450,4 +5483,5 @@ exports.replace = replace;
5450
5483
  exports.resolvePath = resolvePath;
5451
5484
  exports.resolveTo = resolveTo;
5452
5485
  exports.stripBasename = stripBasename;
5486
+ exports.unstable_data = data;
5453
5487
  //# sourceMappingURL=router.cjs.js.map