@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/dist/utils.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare enum ResultType {
16
16
  */
17
17
  export interface SuccessResult {
18
18
  type: ResultType.data;
19
- data: any;
19
+ data: unknown;
20
20
  statusCode?: number;
21
21
  headers?: Headers;
22
22
  }
@@ -34,23 +34,29 @@ export interface DeferredResult {
34
34
  */
35
35
  export interface RedirectResult {
36
36
  type: ResultType.redirect;
37
- status: number;
38
- location: string;
39
- revalidate: boolean;
40
- reloadDocument?: boolean;
37
+ response: Response;
41
38
  }
42
39
  /**
43
40
  * Unsuccessful result from a loader or action
44
41
  */
45
42
  export interface ErrorResult {
46
43
  type: ResultType.error;
47
- error: any;
44
+ error: unknown;
45
+ statusCode?: number;
48
46
  headers?: Headers;
49
47
  }
50
48
  /**
51
49
  * Result from a loader or action - potentially successful or unsuccessful
52
50
  */
53
51
  export type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
52
+ /**
53
+ * Result from a loader or action called via dataStrategy
54
+ */
55
+ export interface HandlerResult {
56
+ type: "data" | "error";
57
+ result: unknown;
58
+ status?: number;
59
+ }
54
60
  type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
55
61
  type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
56
62
  /**
@@ -132,11 +138,12 @@ export interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Cont
132
138
  * and will ease any future migration to Remix
133
139
  */
134
140
  type DataFunctionValue = Response | NonNullable<unknown> | null;
141
+ type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
135
142
  /**
136
143
  * Route loader function signature
137
144
  */
138
145
  export type LoaderFunction<Context = any> = {
139
- (args: LoaderFunctionArgs<Context>): Promise<DataFunctionValue> | DataFunctionValue;
146
+ (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
140
147
  } & {
141
148
  hydrate?: boolean;
142
149
  };
@@ -144,7 +151,7 @@ export type LoaderFunction<Context = any> = {
144
151
  * Route action function signature
145
152
  */
146
153
  export interface ActionFunction<Context = any> {
147
- (args: ActionFunctionArgs<Context>): Promise<DataFunctionValue> | DataFunctionValue;
154
+ (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
148
155
  }
149
156
  /**
150
157
  * Arguments passed to shouldRevalidate function
@@ -160,6 +167,7 @@ export interface ShouldRevalidateFunctionArgs {
160
167
  text?: Submission["text"];
161
168
  formData?: Submission["formData"];
162
169
  json?: Submission["json"];
170
+ unstable_actionStatus?: number;
163
171
  actionResult?: any;
164
172
  defaultShouldRevalidate: boolean;
165
173
  }
@@ -182,6 +190,16 @@ export interface ShouldRevalidateFunction {
182
190
  export interface DetectErrorBoundaryFunction {
183
191
  (route: AgnosticRouteObject): boolean;
184
192
  }
193
+ export interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
194
+ shouldLoad: boolean;
195
+ resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => Promise<HandlerResult>) => Promise<HandlerResult>;
196
+ }
197
+ export interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
198
+ matches: DataStrategyMatch[];
199
+ }
200
+ export interface DataStrategyFunction {
201
+ (args: DataStrategyFunctionArgs): Promise<HandlerResult[]>;
202
+ }
185
203
  /**
186
204
  * Function provided by the framework-aware layers to set any framework-specific
187
205
  * properties from framework-agnostic properties
@@ -215,8 +233,8 @@ type AgnosticBaseRouteObject = {
215
233
  caseSensitive?: boolean;
216
234
  path?: string;
217
235
  id?: string;
218
- loader?: LoaderFunction;
219
- action?: ActionFunction;
236
+ loader?: LoaderFunction | boolean;
237
+ action?: ActionFunction | boolean;
220
238
  hasErrorBoundary?: boolean;
221
239
  shouldRevalidate?: ShouldRevalidateFunction;
222
240
  handle?: any;
package/index.ts CHANGED
@@ -9,9 +9,13 @@ export type {
9
9
  AgnosticNonIndexRouteObject,
10
10
  AgnosticRouteMatch,
11
11
  AgnosticRouteObject,
12
+ DataStrategyFunction as unstable_DataStrategyFunction,
13
+ DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs,
14
+ DataStrategyMatch as unstable_DataStrategyMatch,
12
15
  ErrorResponse,
13
16
  FormEncType,
14
17
  FormMethod,
18
+ HandlerResult as unstable_HandlerResult,
15
19
  HTMLFormMethod,
16
20
  JsonFunction,
17
21
  LazyRouteFunction,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.15.3",
3
+ "version": "1.16.0-pre.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
@@ -30,4 +30,4 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  }
33
- }
33
+ }