@remix-run/router 1.15.3 → 1.16.0-pre.1

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/utils.ts CHANGED
@@ -20,7 +20,7 @@ export enum ResultType {
20
20
  */
21
21
  export interface SuccessResult {
22
22
  type: ResultType.data;
23
- data: any;
23
+ data: unknown;
24
24
  statusCode?: number;
25
25
  headers?: Headers;
26
26
  }
@@ -40,10 +40,8 @@ export interface DeferredResult {
40
40
  */
41
41
  export interface RedirectResult {
42
42
  type: ResultType.redirect;
43
- status: number;
44
- location: string;
45
- revalidate: boolean;
46
- reloadDocument?: boolean;
43
+ // We keep the raw Response for redirects so we can return it verbatim
44
+ response: Response;
47
45
  }
48
46
 
49
47
  /**
@@ -51,7 +49,8 @@ export interface RedirectResult {
51
49
  */
52
50
  export interface ErrorResult {
53
51
  type: ResultType.error;
54
- error: any;
52
+ error: unknown;
53
+ statusCode?: number;
55
54
  headers?: Headers;
56
55
  }
57
56
 
@@ -64,6 +63,15 @@ export type DataResult =
64
63
  | RedirectResult
65
64
  | ErrorResult;
66
65
 
66
+ /**
67
+ * Result from a loader or action called via dataStrategy
68
+ */
69
+ export interface HandlerResult {
70
+ type: "data" | "error";
71
+ result: unknown; // data, Error, Response, DeferredData
72
+ status?: number;
73
+ }
74
+
67
75
  type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
68
76
  type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
69
77
 
@@ -166,22 +174,26 @@ export interface ActionFunctionArgs<Context = any>
166
174
  */
167
175
  type DataFunctionValue = Response | NonNullable<unknown> | null;
168
176
 
177
+ type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
178
+
169
179
  /**
170
180
  * Route loader function signature
171
181
  */
172
182
  export type LoaderFunction<Context = any> = {
173
- (args: LoaderFunctionArgs<Context>):
174
- | Promise<DataFunctionValue>
175
- | DataFunctionValue;
183
+ (
184
+ args: LoaderFunctionArgs<Context>,
185
+ handlerCtx?: unknown
186
+ ): DataFunctionReturnValue;
176
187
  } & { hydrate?: boolean };
177
188
 
178
189
  /**
179
190
  * Route action function signature
180
191
  */
181
192
  export interface ActionFunction<Context = any> {
182
- (args: ActionFunctionArgs<Context>):
183
- | Promise<DataFunctionValue>
184
- | DataFunctionValue;
193
+ (
194
+ args: ActionFunctionArgs<Context>,
195
+ handlerCtx?: unknown
196
+ ): DataFunctionReturnValue;
185
197
  }
186
198
 
187
199
  /**
@@ -198,6 +210,7 @@ export interface ShouldRevalidateFunctionArgs {
198
210
  text?: Submission["text"];
199
211
  formData?: Submission["formData"];
200
212
  json?: Submission["json"];
213
+ unstable_actionStatus?: number;
201
214
  actionResult?: any;
202
215
  defaultShouldRevalidate: boolean;
203
216
  }
@@ -223,6 +236,25 @@ export interface DetectErrorBoundaryFunction {
223
236
  (route: AgnosticRouteObject): boolean;
224
237
  }
225
238
 
239
+ export interface DataStrategyMatch
240
+ extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
241
+ shouldLoad: boolean;
242
+ resolve: (
243
+ handlerOverride?: (
244
+ handler: (ctx?: unknown) => DataFunctionReturnValue
245
+ ) => Promise<HandlerResult>
246
+ ) => Promise<HandlerResult>;
247
+ }
248
+
249
+ export interface DataStrategyFunctionArgs<Context = any>
250
+ extends DataFunctionArgs<Context> {
251
+ matches: DataStrategyMatch[];
252
+ }
253
+
254
+ export interface DataStrategyFunction {
255
+ (args: DataStrategyFunctionArgs): Promise<HandlerResult[]>;
256
+ }
257
+
226
258
  /**
227
259
  * Function provided by the framework-aware layers to set any framework-specific
228
260
  * properties from framework-agnostic properties
@@ -277,8 +309,8 @@ type AgnosticBaseRouteObject = {
277
309
  caseSensitive?: boolean;
278
310
  path?: string;
279
311
  id?: string;
280
- loader?: LoaderFunction;
281
- action?: ActionFunction;
312
+ loader?: LoaderFunction | boolean;
313
+ action?: ActionFunction | boolean;
282
314
  hasErrorBoundary?: boolean;
283
315
  shouldRevalidate?: ShouldRevalidateFunction;
284
316
  handle?: any;