@remix-run/router 1.6.3 → 1.7.0

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
@@ -49,38 +49,62 @@ export interface ErrorResult {
49
49
  /**
50
50
  * Result from a loader or action - potentially successful or unsuccessful
51
51
  */
52
- export declare type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
53
- declare type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
54
- declare type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
52
+ export type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
53
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
54
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
55
55
  /**
56
56
  * Users can specify either lowercase or uppercase form methods on <Form>,
57
57
  * useSubmit(), <fetcher.Form>, etc.
58
58
  */
59
- export declare type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
59
+ export type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
60
60
  /**
61
61
  * Active navigation/fetcher form methods are exposed in lowercase on the
62
62
  * RouterState
63
63
  */
64
- export declare type FormMethod = LowerCaseFormMethod;
65
- export declare type MutationFormMethod = Exclude<FormMethod, "get">;
64
+ export type FormMethod = LowerCaseFormMethod;
65
+ export type MutationFormMethod = Exclude<FormMethod, "get">;
66
66
  /**
67
67
  * In v7, active navigation/fetcher form methods are exposed in uppercase on the
68
68
  * RouterState. This is to align with the normalization done via fetch().
69
69
  */
70
- export declare type V7_FormMethod = UpperCaseFormMethod;
71
- export declare type V7_MutationFormMethod = Exclude<V7_FormMethod, "GET">;
72
- export declare type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data";
70
+ export type V7_FormMethod = UpperCaseFormMethod;
71
+ export type V7_MutationFormMethod = Exclude<V7_FormMethod, "GET">;
72
+ export type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
73
+ type JsonObject = {
74
+ [Key in string]: JsonValue;
75
+ } & {
76
+ [Key in string]?: JsonValue | undefined;
77
+ };
78
+ type JsonArray = JsonValue[] | readonly JsonValue[];
79
+ type JsonPrimitive = string | number | boolean | null;
80
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
73
81
  /**
74
82
  * @private
75
83
  * Internal interface to pass around for action submissions, not intended for
76
84
  * external consumption
77
85
  */
78
- export interface Submission {
86
+ export type Submission = {
79
87
  formMethod: FormMethod | V7_FormMethod;
80
88
  formAction: string;
81
89
  formEncType: FormEncType;
82
90
  formData: FormData;
83
- }
91
+ json: undefined;
92
+ text: undefined;
93
+ } | {
94
+ formMethod: FormMethod | V7_FormMethod;
95
+ formAction: string;
96
+ formEncType: FormEncType;
97
+ formData: undefined;
98
+ json: JsonValue;
99
+ text: undefined;
100
+ } | {
101
+ formMethod: FormMethod | V7_FormMethod;
102
+ formAction: string;
103
+ formEncType: FormEncType;
104
+ formData: undefined;
105
+ json: undefined;
106
+ text: string;
107
+ };
84
108
  /**
85
109
  * @private
86
110
  * Arguments passed to route loader/action functions. Same for now but we keep
@@ -106,7 +130,7 @@ export interface ActionFunctionArgs extends DataFunctionArgs {
106
130
  * valid return value if there is no data to return). Responses are preferred
107
131
  * and will ease any future migration to Remix
108
132
  */
109
- declare type DataFunctionValue = Response | NonNullable<unknown> | null;
133
+ type DataFunctionValue = Response | NonNullable<unknown> | null;
110
134
  /**
111
135
  * Route loader function signature
112
136
  */
@@ -135,7 +159,9 @@ export interface ShouldRevalidateFunction {
135
159
  formMethod?: Submission["formMethod"];
136
160
  formAction?: Submission["formAction"];
137
161
  formEncType?: Submission["formEncType"];
162
+ text?: Submission["text"];
138
163
  formData?: Submission["formData"];
164
+ json?: Submission["json"];
139
165
  actionResult?: DataResult;
140
166
  defaultShouldRevalidate: boolean;
141
167
  }): boolean;
@@ -163,7 +189,7 @@ export interface MapRoutePropertiesFunction {
163
189
  * onto the route. Either they're meaningful to the router, or they'll get
164
190
  * ignored.
165
191
  */
166
- export declare type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
192
+ export type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
167
193
  export declare const immutableRouteKeys: Set<ImmutableRouteKey>;
168
194
  /**
169
195
  * lazy() function to load a route definition, which can add non-matching
@@ -175,7 +201,7 @@ export interface LazyRouteFunction<R extends AgnosticRouteObject> {
175
201
  /**
176
202
  * Base RouteObject with common props shared by all types of routes
177
203
  */
178
- declare type AgnosticBaseRouteObject = {
204
+ type AgnosticBaseRouteObject = {
179
205
  caseSensitive?: boolean;
180
206
  path?: string;
181
207
  id?: string;
@@ -189,14 +215,14 @@ declare type AgnosticBaseRouteObject = {
189
215
  /**
190
216
  * Index routes must not have children
191
217
  */
192
- export declare type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
218
+ export type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
193
219
  children?: undefined;
194
220
  index: true;
195
221
  };
196
222
  /**
197
223
  * Non-index routes may have children, but cannot have index
198
224
  */
199
- export declare type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
225
+ export type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
200
226
  children?: AgnosticRouteObject[];
201
227
  index?: false;
202
228
  };
@@ -204,20 +230,20 @@ export declare type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
204
230
  * A route object represents a logical route, with (optionally) its child
205
231
  * routes organized in a tree-like structure.
206
232
  */
207
- export declare type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
208
- export declare type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
233
+ export type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
234
+ export type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
209
235
  id: string;
210
236
  };
211
- export declare type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
237
+ export type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
212
238
  children?: AgnosticDataRouteObject[];
213
239
  id: string;
214
240
  };
215
241
  /**
216
242
  * A data route object, which is just a RouteObject with a required unique ID
217
243
  */
218
- export declare type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
219
- export declare type RouteManifest = Record<string, AgnosticDataRouteObject | undefined>;
220
- declare type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?` ? Optional : Param : never;
244
+ export type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
245
+ export type RouteManifest = Record<string, AgnosticDataRouteObject | undefined>;
246
+ type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?` ? Optional : Param : never;
221
247
  /**
222
248
  * Examples:
223
249
  * "/a/b/*" -> "*"
@@ -227,14 +253,14 @@ declare type _PathParam<Path extends string> = Path extends `${infer L}/${infer
227
253
  * "/:a/:b" -> "a" | "b"
228
254
  * "/:a/b/:c/*" -> "a" | "c" | "*"
229
255
  */
230
- declare type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
231
- export declare type ParamParseKey<Segment extends string> = [
256
+ type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
257
+ export type ParamParseKey<Segment extends string> = [
232
258
  PathParam<Segment>
233
259
  ] extends [never] ? string : PathParam<Segment>;
234
260
  /**
235
261
  * The parameters that were parsed from the URL path.
236
262
  */
237
- export declare type Params<Key extends string = string> = {
263
+ export type Params<Key extends string = string> = {
238
264
  readonly [key in Key]: string | undefined;
239
265
  };
240
266
  /**
@@ -381,7 +407,7 @@ export declare const normalizeSearch: (search: string) => string;
381
407
  * @private
382
408
  */
383
409
  export declare const normalizeHash: (hash: string) => string;
384
- export declare type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => Response;
410
+ export type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => Response;
385
411
  /**
386
412
  * This is a shortcut for creating `application/json` responses. Converts `data`
387
413
  * to JSON and sets the `Content-Type` header.
@@ -414,9 +440,9 @@ export declare class DeferredData {
414
440
  get unwrappedData(): {};
415
441
  get pendingKeys(): string[];
416
442
  }
417
- export declare type DeferFunction = (data: Record<string, unknown>, init?: number | ResponseInit) => DeferredData;
443
+ export type DeferFunction = (data: Record<string, unknown>, init?: number | ResponseInit) => DeferredData;
418
444
  export declare const defer: DeferFunction;
419
- export declare type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
445
+ export type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
420
446
  /**
421
447
  * A redirect response. Sets the status code and the `Location` header.
422
448
  * Defaults to "302 Found".
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.6.3",
3
+ "version": "1.7.0",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",