litzjs 0.0.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/LICENSE +21 -0
- package/README.md +936 -0
- package/dist/bindings-B1P6pL93.js +21 -0
- package/dist/bindings-BDe-v5i6.mjs +10 -0
- package/dist/chunk-8l464Juk.js +28 -0
- package/dist/client.d.mts +35 -0
- package/dist/client.d.ts +35 -0
- package/dist/client.js +1633 -0
- package/dist/client.mjs +1625 -0
- package/dist/index.d.mts +559 -0
- package/dist/index.d.ts +559 -0
- package/dist/index.js +360 -0
- package/dist/index.mjs +344 -0
- package/dist/internal-transport-DR0r68ff.js +161 -0
- package/dist/internal-transport-dsMykcNK.mjs +114 -0
- package/dist/request-headers-DepZ5tjg.mjs +35 -0
- package/dist/request-headers-ZPR3TQs3.js +46 -0
- package/dist/server.d.mts +74 -0
- package/dist/server.d.ts +74 -0
- package/dist/server.js +316 -0
- package/dist/server.mjs +315 -0
- package/dist/vite.d.mts +10043 -0
- package/dist/vite.d.ts +10043 -0
- package/dist/vite.js +1481 -0
- package/dist/vite.mjs +1474 -0
- package/package.json +90 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type MiddlewareOverrides<TContext = unknown> = {
|
|
5
|
+
context?: TContext;
|
|
6
|
+
};
|
|
7
|
+
type MiddlewareContext<TContext = unknown> = {
|
|
8
|
+
request: Request;
|
|
9
|
+
params: Record<string, string>;
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
context: TContext;
|
|
12
|
+
};
|
|
13
|
+
type MiddlewareNext<TContext = unknown, TResult = unknown> = (overrides?: MiddlewareOverrides<TContext>) => Promise<TResult>;
|
|
14
|
+
type MiddlewareHandler<TContext = unknown, TResult = unknown> = (context: MiddlewareContext<TContext>, next: MiddlewareNext<TContext, TResult>) => TResult | Promise<TResult>;
|
|
15
|
+
type Middleware<TContext = unknown, TResult = ServerResult> = MiddlewareHandler<TContext, TResult>;
|
|
16
|
+
type MiddlewareRef<TContext = unknown, TResult = unknown> = MiddlewareHandler<TContext, TResult>;
|
|
17
|
+
type RouteErrorLike = {
|
|
18
|
+
kind: "error";
|
|
19
|
+
status: number;
|
|
20
|
+
message: string;
|
|
21
|
+
code?: string;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "fault";
|
|
25
|
+
status: number;
|
|
26
|
+
message: string;
|
|
27
|
+
digest?: string;
|
|
28
|
+
};
|
|
29
|
+
type RouteStatus = "idle" | "loading" | "submitting" | "revalidating" | "offline-stale" | "error";
|
|
30
|
+
type SubmitOptions<TResult extends ServerResult = ServerResult> = {
|
|
31
|
+
onBeforeSubmit?: (formData: FormData) => void;
|
|
32
|
+
onSuccess?: (result: ActionSuccessResultFor<TResult>) => void;
|
|
33
|
+
onError?: (result: ActionErrorResultFor<TResult>) => void;
|
|
34
|
+
replace?: boolean;
|
|
35
|
+
revalidate?: boolean | string[];
|
|
36
|
+
};
|
|
37
|
+
type SearchParamsUpdate = Record<string, string | string[] | null | undefined>;
|
|
38
|
+
type LitzLocation = {
|
|
39
|
+
href: string;
|
|
40
|
+
pathname: string;
|
|
41
|
+
search: URLSearchParams;
|
|
42
|
+
hash: string;
|
|
43
|
+
};
|
|
44
|
+
type SetSearchParams = (params: SearchParamsUpdate, options?: {
|
|
45
|
+
replace?: boolean;
|
|
46
|
+
}) => void;
|
|
47
|
+
type RouteFormProps = Omit<React.ComponentPropsWithoutRef<"form">, "action" | "method"> & {
|
|
48
|
+
replace?: boolean;
|
|
49
|
+
revalidate?: boolean | string[];
|
|
50
|
+
};
|
|
51
|
+
type NormalizedResult = {
|
|
52
|
+
kind: "data";
|
|
53
|
+
status: number;
|
|
54
|
+
headers: Headers;
|
|
55
|
+
data: unknown;
|
|
56
|
+
revalidate: string[];
|
|
57
|
+
} | {
|
|
58
|
+
kind: "invalid";
|
|
59
|
+
status: number;
|
|
60
|
+
headers: Headers;
|
|
61
|
+
fields?: Record<string, string>;
|
|
62
|
+
formError?: string;
|
|
63
|
+
data?: unknown;
|
|
64
|
+
} | {
|
|
65
|
+
kind: "redirect";
|
|
66
|
+
status: number;
|
|
67
|
+
headers: Headers;
|
|
68
|
+
location: string;
|
|
69
|
+
replace: boolean;
|
|
70
|
+
revalidate: string[];
|
|
71
|
+
} | {
|
|
72
|
+
kind: "error";
|
|
73
|
+
status: number;
|
|
74
|
+
headers: Headers;
|
|
75
|
+
message: string;
|
|
76
|
+
code?: string;
|
|
77
|
+
data?: unknown;
|
|
78
|
+
} | {
|
|
79
|
+
kind: "fault";
|
|
80
|
+
status: number;
|
|
81
|
+
headers: Headers;
|
|
82
|
+
message: string;
|
|
83
|
+
digest?: string;
|
|
84
|
+
};
|
|
85
|
+
type DataResult<TData = unknown> = {
|
|
86
|
+
kind: "data";
|
|
87
|
+
status?: number;
|
|
88
|
+
headers?: HeadersInit;
|
|
89
|
+
data: TData;
|
|
90
|
+
revalidate?: string[];
|
|
91
|
+
};
|
|
92
|
+
type ViewResult<TNode extends React.ReactNode = React.ReactNode> = {
|
|
93
|
+
kind: "view";
|
|
94
|
+
headers?: HeadersInit;
|
|
95
|
+
node: TNode;
|
|
96
|
+
revalidate?: string[];
|
|
97
|
+
};
|
|
98
|
+
type InvalidResult<TData = unknown> = {
|
|
99
|
+
kind: "invalid";
|
|
100
|
+
status?: number;
|
|
101
|
+
headers?: HeadersInit;
|
|
102
|
+
fields?: Record<string, string>;
|
|
103
|
+
formError?: string;
|
|
104
|
+
data?: TData;
|
|
105
|
+
};
|
|
106
|
+
type RedirectResult = {
|
|
107
|
+
kind: "redirect";
|
|
108
|
+
status?: number;
|
|
109
|
+
headers?: HeadersInit;
|
|
110
|
+
location: string;
|
|
111
|
+
replace?: boolean;
|
|
112
|
+
revalidate?: string[];
|
|
113
|
+
};
|
|
114
|
+
type ErrorResult<TData = unknown> = {
|
|
115
|
+
kind: "error";
|
|
116
|
+
status: number;
|
|
117
|
+
headers?: HeadersInit;
|
|
118
|
+
message: string;
|
|
119
|
+
code?: string;
|
|
120
|
+
data?: TData;
|
|
121
|
+
};
|
|
122
|
+
type FaultResult = {
|
|
123
|
+
kind: "fault";
|
|
124
|
+
status: number;
|
|
125
|
+
headers?: HeadersInit;
|
|
126
|
+
message: string;
|
|
127
|
+
digest?: string;
|
|
128
|
+
};
|
|
129
|
+
type ServerResult = DataResult<any> | ViewResult<any> | InvalidResult<any> | RedirectResult | ErrorResult<any> | FaultResult;
|
|
130
|
+
type ResultWithHeaders = {
|
|
131
|
+
headers?: HeadersInit;
|
|
132
|
+
};
|
|
133
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
134
|
+
type NoInferType<T> = [T][T extends any ? 0 : never];
|
|
135
|
+
type PresentResult<T> = [T] extends [never] ? never : T;
|
|
136
|
+
type ExtractPathParamName<TSegment extends string> = TSegment extends `${infer TParam}/${string}` ? TParam : TSegment extends `${infer TParam}?${string}` ? TParam : TSegment extends `${infer TParam}#${string}` ? TParam : TSegment;
|
|
137
|
+
type ExtractPathParamRest<TSegment extends string> = TSegment extends `${string}/${infer TRest}` ? TRest : never;
|
|
138
|
+
type ExtractPathParamNames<TPath extends string> = string extends TPath ? string : TPath extends `${string}:${infer TSegment}` ? ExtractPathParamName<TSegment> | (ExtractPathParamRest<TSegment> extends never ? never : ExtractPathParamNames<ExtractPathParamRest<TSegment>>) : never;
|
|
139
|
+
type PathParams<TPath extends string> = string extends TPath ? Record<string, string> : [ExtractPathParamNames<TPath>] extends [never] ? {} : Simplify<{ [TKey in ExtractPathParamNames<TPath>]: string }>;
|
|
140
|
+
type PathRequestParams<TPath extends string> = string extends TPath ? {
|
|
141
|
+
params?: Record<string, string>;
|
|
142
|
+
} : [ExtractPathParamNames<TPath>] extends [never] ? {
|
|
143
|
+
params?: {};
|
|
144
|
+
} : {
|
|
145
|
+
params: PathParams<TPath>;
|
|
146
|
+
};
|
|
147
|
+
type SearchRequest = {
|
|
148
|
+
search?: URLSearchParams | Record<string, string>;
|
|
149
|
+
};
|
|
150
|
+
type HasRequiredPathParams<TPath extends string> = string extends TPath ? false : [ExtractPathParamNames<TPath>] extends [never] ? false : true;
|
|
151
|
+
type MaybeRequiredArg<TPath extends string, TValue> = HasRequiredPathParams<TPath> extends true ? [value: TValue] : [value?: TValue];
|
|
152
|
+
type LoaderDataFor<TResult extends ServerResult> = Extract<TResult, {
|
|
153
|
+
kind: "data";
|
|
154
|
+
}> extends {
|
|
155
|
+
data: infer TData;
|
|
156
|
+
} ? TData : never;
|
|
157
|
+
type LoaderNodeFor<TResult extends ServerResult> = Extract<TResult, {
|
|
158
|
+
kind: "view";
|
|
159
|
+
}> extends {
|
|
160
|
+
node: infer TNode;
|
|
161
|
+
} ? TNode : never;
|
|
162
|
+
type InvalidDataFor<TResult extends ServerResult> = Extract<TResult, {
|
|
163
|
+
kind: "invalid";
|
|
164
|
+
}> extends {
|
|
165
|
+
data?: infer TData;
|
|
166
|
+
} ? TData : never;
|
|
167
|
+
type ActionDataFor<TResult extends ServerResult> = Extract<TResult, {
|
|
168
|
+
kind: "data";
|
|
169
|
+
}> extends {
|
|
170
|
+
data: infer TData;
|
|
171
|
+
} ? TData : never;
|
|
172
|
+
type ActionViewNodeFor<TResult extends ServerResult> = Extract<TResult, {
|
|
173
|
+
kind: "view";
|
|
174
|
+
}> extends {
|
|
175
|
+
node: infer TNode;
|
|
176
|
+
} ? TNode : never;
|
|
177
|
+
type ErrorDataFor<TResult extends ServerResult> = Extract<TResult, {
|
|
178
|
+
kind: "error";
|
|
179
|
+
}> extends {
|
|
180
|
+
data?: infer TData;
|
|
181
|
+
} ? TData : never;
|
|
182
|
+
type LoaderDataHookBranch<TData> = {
|
|
183
|
+
kind: "data";
|
|
184
|
+
status: number;
|
|
185
|
+
headers: Headers;
|
|
186
|
+
stale: boolean;
|
|
187
|
+
data: TData;
|
|
188
|
+
render(this: void): React.ReactNode;
|
|
189
|
+
};
|
|
190
|
+
type LoaderViewHookBranch<TNode extends React.ReactNode> = {
|
|
191
|
+
kind: "view";
|
|
192
|
+
status: number;
|
|
193
|
+
headers: Headers;
|
|
194
|
+
stale: boolean;
|
|
195
|
+
node: TNode;
|
|
196
|
+
render(this: void): React.ReactNode;
|
|
197
|
+
};
|
|
198
|
+
type ActionInvalidHookBranch<TData> = {
|
|
199
|
+
kind: "invalid";
|
|
200
|
+
status: number;
|
|
201
|
+
headers: Headers;
|
|
202
|
+
fields?: Record<string, string>;
|
|
203
|
+
formError?: string;
|
|
204
|
+
data?: TData;
|
|
205
|
+
};
|
|
206
|
+
type ActionDataHookBranch<TData> = {
|
|
207
|
+
kind: "data";
|
|
208
|
+
status: number;
|
|
209
|
+
headers: Headers;
|
|
210
|
+
data: TData;
|
|
211
|
+
};
|
|
212
|
+
type ActionViewHookBranch<TNode extends React.ReactNode> = {
|
|
213
|
+
kind: "view";
|
|
214
|
+
status: number;
|
|
215
|
+
headers: Headers;
|
|
216
|
+
node: TNode;
|
|
217
|
+
render(this: void): React.ReactNode;
|
|
218
|
+
};
|
|
219
|
+
type ActionRedirectHookBranch = {
|
|
220
|
+
kind: "redirect";
|
|
221
|
+
status: number;
|
|
222
|
+
headers: Headers;
|
|
223
|
+
location: string;
|
|
224
|
+
replace: boolean;
|
|
225
|
+
};
|
|
226
|
+
type ActionErrorHookBranch<TData> = {
|
|
227
|
+
kind: "error";
|
|
228
|
+
status: number;
|
|
229
|
+
headers: Headers;
|
|
230
|
+
message: string;
|
|
231
|
+
code?: string;
|
|
232
|
+
data?: TData;
|
|
233
|
+
};
|
|
234
|
+
type ActionFaultHookBranch = {
|
|
235
|
+
kind: "fault";
|
|
236
|
+
status: number;
|
|
237
|
+
headers: Headers;
|
|
238
|
+
message: string;
|
|
239
|
+
digest?: string;
|
|
240
|
+
};
|
|
241
|
+
type LoaderHookResultFor<TResult extends ServerResult = ServerResult> = PresentResult<Extract<TResult, {
|
|
242
|
+
kind: "data";
|
|
243
|
+
}> extends never ? never : LoaderDataHookBranch<LoaderDataFor<TResult>>> | PresentResult<Extract<TResult, {
|
|
244
|
+
kind: "view";
|
|
245
|
+
}> extends never ? never : LoaderViewHookBranch<LoaderNodeFor<TResult> & React.ReactNode>>;
|
|
246
|
+
type ActionHookResultFor<TResult extends ServerResult = ServerResult> = null | PresentResult<Extract<TResult, {
|
|
247
|
+
kind: "invalid";
|
|
248
|
+
}> extends never ? never : ActionInvalidHookBranch<InvalidDataFor<TResult>>> | PresentResult<Extract<TResult, {
|
|
249
|
+
kind: "data";
|
|
250
|
+
}> extends never ? never : ActionDataHookBranch<ActionDataFor<TResult>>> | PresentResult<Extract<TResult, {
|
|
251
|
+
kind: "view";
|
|
252
|
+
}> extends never ? never : ActionViewHookBranch<ActionViewNodeFor<TResult> & React.ReactNode>> | PresentResult<Extract<TResult, {
|
|
253
|
+
kind: "redirect";
|
|
254
|
+
}> extends never ? never : ActionRedirectHookBranch> | PresentResult<Extract<TResult, {
|
|
255
|
+
kind: "error";
|
|
256
|
+
}> extends never ? never : ActionErrorHookBranch<ErrorDataFor<TResult>>> | PresentResult<Extract<TResult, {
|
|
257
|
+
kind: "fault";
|
|
258
|
+
}> extends never ? never : ActionFaultHookBranch>;
|
|
259
|
+
type LoaderHookResult = LoaderHookResultFor<ServerResult>;
|
|
260
|
+
type ActionHookResult = ActionHookResultFor<ServerResult>;
|
|
261
|
+
type LoaderDataValueFor<TResult extends ServerResult> = LoaderDataFor<TResult> | null;
|
|
262
|
+
type LoaderViewValueFor<TResult extends ServerResult> = (LoaderNodeFor<TResult> & React.ReactNode) | null;
|
|
263
|
+
type ActionDataValueFor<TResult extends ServerResult> = ActionDataFor<TResult> | null;
|
|
264
|
+
type ActionViewValueFor<TResult extends ServerResult> = (ActionViewNodeFor<TResult> & React.ReactNode) | null;
|
|
265
|
+
type ActionInvalidValueFor<TResult extends ServerResult> = Extract<ActionHookResultFor<TResult>, {
|
|
266
|
+
kind: "invalid";
|
|
267
|
+
}> | null;
|
|
268
|
+
type ActionExplicitErrorValueFor<TResult extends ServerResult> = Extract<ActionHookResultFor<TResult>, {
|
|
269
|
+
kind: "error";
|
|
270
|
+
}> | null;
|
|
271
|
+
type MergedDataValueFor<TLoaderResult extends ServerResult, TActionResult extends ServerResult> = LoaderDataFor<TLoaderResult> | ActionDataFor<TActionResult> | null;
|
|
272
|
+
type MergedViewValueFor<TLoaderResult extends ServerResult, TActionResult extends ServerResult> = (LoaderNodeFor<TLoaderResult> & React.ReactNode) | (ActionViewNodeFor<TActionResult> & React.ReactNode) | null;
|
|
273
|
+
type ActionErrorResultFor<TResult extends ServerResult = ServerResult> = Extract<ActionHookResultFor<TResult>, {
|
|
274
|
+
kind: "error" | "fault";
|
|
275
|
+
}>;
|
|
276
|
+
type ActionSuccessResultFor<TResult extends ServerResult = ServerResult> = Exclude<ActionHookResultFor<TResult>, null | ActionErrorResultFor<TResult>>;
|
|
277
|
+
type RouteHandlerContext<TContext = unknown, TPath extends string = string> = {
|
|
278
|
+
request: Request;
|
|
279
|
+
params: PathParams<TPath>;
|
|
280
|
+
signal: AbortSignal;
|
|
281
|
+
context: TContext;
|
|
282
|
+
};
|
|
283
|
+
type ResourceHandlerContext<TContext = unknown, TPath extends string = string> = {
|
|
284
|
+
request: Request;
|
|
285
|
+
params: PathParams<TPath>;
|
|
286
|
+
signal: AbortSignal;
|
|
287
|
+
context: TContext;
|
|
288
|
+
};
|
|
289
|
+
type ApiHandlerContext<TContext = unknown, TPath extends string = string> = {
|
|
290
|
+
request: Request;
|
|
291
|
+
params: PathParams<TPath>;
|
|
292
|
+
signal: AbortSignal;
|
|
293
|
+
context: TContext;
|
|
294
|
+
};
|
|
295
|
+
type ApiRouteMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "HEAD" | "ALL";
|
|
296
|
+
type ApiRouteHandler<TContext = unknown, TPath extends string = string> = (context: ApiHandlerContext<TContext, TPath>) => Promise<Response> | Response;
|
|
297
|
+
type ApiRouteHandlers<TContext = unknown, TPath extends string = string> = Partial<Record<ApiRouteMethod, ApiRouteHandler<TContext, TPath>>>;
|
|
298
|
+
type DefineApiRouteOptions<TContext = unknown, TPath extends string = string, TMethods extends ApiRouteHandlers<TContext, TPath> = ApiRouteHandlers<TContext, TPath>> = Simplify<TMethods & {
|
|
299
|
+
middleware?: MiddlewareRef<NoInferType<TContext>, Response>[];
|
|
300
|
+
}>;
|
|
301
|
+
type ApiFetchMethod<TMethods extends ApiRouteHandlers<any, any>> = "ALL" extends keyof TMethods ? Exclude<ApiRouteMethod, "ALL"> : Exclude<Extract<keyof TMethods, ApiRouteMethod>, "ALL">;
|
|
302
|
+
type ApiFetchOptions<TPath extends string = string, TMethods extends ApiRouteHandlers<any, TPath> = ApiRouteHandlers<any, TPath>> = Omit<RequestInit, "method"> & PathRequestParams<TPath> & SearchRequest & {
|
|
303
|
+
method?: ApiFetchMethod<TMethods>;
|
|
304
|
+
};
|
|
305
|
+
type RouteServerHandler<TContext = unknown, TResult extends ServerResult = ServerResult, TPath extends string = string> = (context: RouteHandlerContext<TContext, TPath>) => Promise<TResult> | TResult;
|
|
306
|
+
type ResourceServerHandler<TContext = unknown, TResult extends ServerResult = ServerResult, TPath extends string = string> = (context: ResourceHandlerContext<TContext, TPath>) => Promise<TResult> | TResult;
|
|
307
|
+
type ServerHandler<TContext = unknown, TResult extends ServerResult = ServerResult> = RouteServerHandler<TContext, TResult> | ResourceServerHandler<TContext, TResult>;
|
|
308
|
+
type DefineRouteOptions<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = ServerResult, TActionResult extends ServerResult = ServerResult> = {
|
|
309
|
+
component: React.ComponentType;
|
|
310
|
+
layout?: LayoutReference;
|
|
311
|
+
loader?: RouteServerHandler<TContext, TLoaderResult, NoInferType<TPath>>;
|
|
312
|
+
action?: RouteServerHandler<TContext, TActionResult, NoInferType<TPath>>;
|
|
313
|
+
middleware?: MiddlewareRef<TContext, ServerResult>[];
|
|
314
|
+
pendingComponent?: React.ComponentType;
|
|
315
|
+
errorComponent?: React.ComponentType<{
|
|
316
|
+
error: RouteErrorLike;
|
|
317
|
+
}>;
|
|
318
|
+
offline?: {
|
|
319
|
+
fallbackComponent?: React.ComponentType;
|
|
320
|
+
preserveStaleOnFailure?: boolean;
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
type RouteBaseOptions<TPath extends string = string, TContext = unknown> = Omit<DefineRouteOptions<TPath, TContext, ServerResult, ServerResult>, "loader" | "action">;
|
|
324
|
+
type RouteLoaderOption<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never> = [TLoaderResult] extends [never] ? {
|
|
325
|
+
loader?: never;
|
|
326
|
+
} : {
|
|
327
|
+
loader: RouteServerHandler<TContext, TLoaderResult, TPath>;
|
|
328
|
+
};
|
|
329
|
+
type RouteActionOption<TPath extends string = string, TContext = unknown, TActionResult extends ServerResult = never> = [TActionResult] extends [never] ? {
|
|
330
|
+
action?: never;
|
|
331
|
+
} : {
|
|
332
|
+
action: RouteServerHandler<TContext, TActionResult, TPath>;
|
|
333
|
+
};
|
|
334
|
+
type DefineLayoutOptions<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = ServerResult> = {
|
|
335
|
+
component: React.JSXElementConstructor<{
|
|
336
|
+
children: React.ReactNode;
|
|
337
|
+
}>;
|
|
338
|
+
layout?: LayoutReference;
|
|
339
|
+
loader?: RouteServerHandler<TContext, TLoaderResult, NoInferType<TPath>>;
|
|
340
|
+
middleware?: MiddlewareRef<TContext, ServerResult>[];
|
|
341
|
+
pendingComponent?: React.ComponentType;
|
|
342
|
+
errorComponent?: React.ComponentType<{
|
|
343
|
+
error: RouteErrorLike;
|
|
344
|
+
}>;
|
|
345
|
+
};
|
|
346
|
+
type LayoutBaseOptions<TPath extends string = string, TContext = unknown> = Omit<DefineLayoutOptions<TPath, TContext, ServerResult>, "loader">;
|
|
347
|
+
type LayoutLoaderOption<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never> = [TLoaderResult] extends [never] ? {
|
|
348
|
+
loader?: never;
|
|
349
|
+
} : {
|
|
350
|
+
loader: RouteServerHandler<TContext, TLoaderResult, TPath>;
|
|
351
|
+
};
|
|
352
|
+
type LitzLayout<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never> = Simplify<{
|
|
353
|
+
id: TPath;
|
|
354
|
+
path: TPath;
|
|
355
|
+
component: React.JSXElementConstructor<{
|
|
356
|
+
children: React.ReactNode;
|
|
357
|
+
}>;
|
|
358
|
+
options: LayoutBaseOptions<TPath, TContext> & LayoutLoaderOption<TPath, TContext, TLoaderResult>;
|
|
359
|
+
useParams(): PathParams<TPath>;
|
|
360
|
+
useSearch(): [URLSearchParams, SetSearchParams];
|
|
361
|
+
useStatus(): RouteStatus;
|
|
362
|
+
usePending(): boolean;
|
|
363
|
+
} & ([TLoaderResult] extends [never] ? {} : LayoutLoaderClientHooks<TLoaderResult>)>;
|
|
364
|
+
type LayoutReference = {
|
|
365
|
+
id: string;
|
|
366
|
+
path: string;
|
|
367
|
+
component: React.JSXElementConstructor<{
|
|
368
|
+
children: React.ReactNode;
|
|
369
|
+
}>;
|
|
370
|
+
options?: {
|
|
371
|
+
layout?: LayoutReference;
|
|
372
|
+
loader?: unknown;
|
|
373
|
+
middleware?: MiddlewareRef<any, ServerResult>[];
|
|
374
|
+
pendingComponent?: React.ComponentType;
|
|
375
|
+
errorComponent?: React.ComponentType<{
|
|
376
|
+
error: RouteErrorLike;
|
|
377
|
+
}>;
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
type LayoutLoaderClientHooks<TLoaderResult extends ServerResult> = {
|
|
381
|
+
useLoaderResult(): LoaderHookResultFor<TLoaderResult> | null;
|
|
382
|
+
useLoaderData(): LoaderDataValueFor<TLoaderResult>;
|
|
383
|
+
useLoaderView(): LoaderViewValueFor<TLoaderResult>;
|
|
384
|
+
useData(): LoaderDataValueFor<TLoaderResult>;
|
|
385
|
+
useView(): LoaderViewValueFor<TLoaderResult>;
|
|
386
|
+
useRetry(): () => void;
|
|
387
|
+
useReload(): () => void;
|
|
388
|
+
};
|
|
389
|
+
type RouteLoaderClientHooks<TLoaderResult extends ServerResult> = {
|
|
390
|
+
useLoaderResult(): LoaderHookResultFor<TLoaderResult> | null;
|
|
391
|
+
useLoaderData(): LoaderDataValueFor<TLoaderResult>;
|
|
392
|
+
useLoaderView(): LoaderViewValueFor<TLoaderResult>;
|
|
393
|
+
useRetry(): () => void;
|
|
394
|
+
useReload(): () => void;
|
|
395
|
+
};
|
|
396
|
+
type RouteActionClientHooks<TActionResult extends ServerResult> = {
|
|
397
|
+
useActionResult(): ActionHookResultFor<TActionResult>;
|
|
398
|
+
useActionData(): ActionDataValueFor<TActionResult>;
|
|
399
|
+
useActionView(): ActionViewValueFor<TActionResult>;
|
|
400
|
+
useActionError(): ActionExplicitErrorValueFor<TActionResult>;
|
|
401
|
+
useInvalid(): ActionInvalidValueFor<TActionResult>;
|
|
402
|
+
useSubmit(opts?: SubmitOptions<TActionResult>): (payload: FormData | Record<string, unknown>) => Promise<void>;
|
|
403
|
+
Form: React.ComponentType<RouteFormProps>;
|
|
404
|
+
};
|
|
405
|
+
type LitzRoute<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never, TActionResult extends ServerResult = never> = Simplify<{
|
|
406
|
+
id: TPath;
|
|
407
|
+
path: TPath;
|
|
408
|
+
component: React.ComponentType;
|
|
409
|
+
options: RouteBaseOptions<TPath, TContext> & RouteLoaderOption<TPath, TContext, TLoaderResult> & RouteActionOption<TPath, TContext, TActionResult>;
|
|
410
|
+
useParams(): PathParams<TPath>;
|
|
411
|
+
useSearch(): [URLSearchParams, SetSearchParams];
|
|
412
|
+
useStatus(): RouteStatus;
|
|
413
|
+
usePending(): boolean;
|
|
414
|
+
} & ([TLoaderResult] extends [never] ? {} : RouteLoaderClientHooks<TLoaderResult>) & ([TActionResult] extends [never] ? {} : RouteActionClientHooks<TActionResult>) & ([TLoaderResult] extends [never] ? [TActionResult] extends [never] ? {} : {
|
|
415
|
+
useData(): ActionDataValueFor<TActionResult>;
|
|
416
|
+
useView(): ActionViewValueFor<TActionResult>;
|
|
417
|
+
useError(): ActionExplicitErrorValueFor<TActionResult>;
|
|
418
|
+
} : [TActionResult] extends [never] ? {
|
|
419
|
+
useData(): LoaderDataValueFor<TLoaderResult>;
|
|
420
|
+
useView(): LoaderViewValueFor<TLoaderResult>;
|
|
421
|
+
} : {
|
|
422
|
+
useData(): MergedDataValueFor<TLoaderResult, TActionResult>;
|
|
423
|
+
useView(): MergedViewValueFor<TLoaderResult, TActionResult>;
|
|
424
|
+
useError(): ActionExplicitErrorValueFor<TActionResult>;
|
|
425
|
+
})>;
|
|
426
|
+
type LitzMatch<TPath extends string = string> = {
|
|
427
|
+
id: TPath;
|
|
428
|
+
path: TPath;
|
|
429
|
+
params: PathParams<TPath>;
|
|
430
|
+
search: URLSearchParams;
|
|
431
|
+
};
|
|
432
|
+
type ResourceRequest<TPath extends string = string> = Simplify<PathRequestParams<TPath> & SearchRequest>;
|
|
433
|
+
type ResourceComponentProps<TPath extends string = string> = ResourceRequest<TPath>;
|
|
434
|
+
type LitzApiRoute<TPath extends string = string, TContext = unknown, TMethods extends ApiRouteHandlers<TContext, TPath> = ApiRouteHandlers<TContext, TPath>> = {
|
|
435
|
+
path: TPath;
|
|
436
|
+
middleware?: MiddlewareRef<TContext, Response>[];
|
|
437
|
+
methods: TMethods;
|
|
438
|
+
fetch(...args: MaybeRequiredArg<TPath, ApiFetchOptions<TPath, TMethods>>): Promise<Response>;
|
|
439
|
+
};
|
|
440
|
+
type LitzResource<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never, TActionResult extends ServerResult = never, TComponent extends React.ComponentType<ResourceComponentProps<TPath>> = React.ComponentType<ResourceComponentProps<TPath>>> = Simplify<{
|
|
441
|
+
path: TPath;
|
|
442
|
+
middleware?: MiddlewareRef<TContext, ServerResult>[];
|
|
443
|
+
component: TComponent;
|
|
444
|
+
Component: React.ComponentType<ResourceComponentProps<TPath>>;
|
|
445
|
+
useParams(): PathParams<TPath>;
|
|
446
|
+
useSearch(): [URLSearchParams, SetSearchParams];
|
|
447
|
+
useStatus(): RouteStatus;
|
|
448
|
+
usePending(): boolean;
|
|
449
|
+
} & ([TLoaderResult] extends [never] ? {} : {
|
|
450
|
+
loader: ResourceServerHandler<TContext, TLoaderResult, TPath>;
|
|
451
|
+
useLoaderResult(): LoaderHookResultFor<TLoaderResult> | null;
|
|
452
|
+
useLoaderData(): LoaderDataValueFor<TLoaderResult>;
|
|
453
|
+
useLoaderView(): LoaderViewValueFor<TLoaderResult>;
|
|
454
|
+
useRetry(): () => void;
|
|
455
|
+
useReload(): () => void;
|
|
456
|
+
}) & ([TActionResult] extends [never] ? {} : {
|
|
457
|
+
action: ResourceServerHandler<TContext, TActionResult, TPath>;
|
|
458
|
+
useActionResult(): ActionHookResultFor<TActionResult>;
|
|
459
|
+
useActionData(): ActionDataValueFor<TActionResult>;
|
|
460
|
+
useActionView(): ActionViewValueFor<TActionResult>;
|
|
461
|
+
useActionError(): ActionExplicitErrorValueFor<TActionResult>;
|
|
462
|
+
useInvalid(): ActionInvalidValueFor<TActionResult>;
|
|
463
|
+
useSubmit(opts?: SubmitOptions<TActionResult>): (payload: FormData | Record<string, unknown>) => Promise<void>;
|
|
464
|
+
Form: React.ComponentType<RouteFormProps>;
|
|
465
|
+
}) & ([TLoaderResult] extends [never] ? [TActionResult] extends [never] ? {} : {
|
|
466
|
+
useData(): ActionDataValueFor<TActionResult>;
|
|
467
|
+
useView(): ActionViewValueFor<TActionResult>;
|
|
468
|
+
useError(): ActionExplicitErrorValueFor<TActionResult>;
|
|
469
|
+
} : [TActionResult] extends [never] ? {
|
|
470
|
+
useData(): LoaderDataValueFor<TLoaderResult>;
|
|
471
|
+
useView(): LoaderViewValueFor<TLoaderResult>;
|
|
472
|
+
} : {
|
|
473
|
+
useData(): MergedDataValueFor<TLoaderResult, TActionResult>;
|
|
474
|
+
useView(): MergedViewValueFor<TLoaderResult, TActionResult>;
|
|
475
|
+
useError(): ActionExplicitErrorValueFor<TActionResult>;
|
|
476
|
+
})>;
|
|
477
|
+
type ResourceComponentOption<TPath extends string = string, TComponent extends React.ComponentType<ResourceComponentProps<TPath>> = React.ComponentType<ResourceComponentProps<TPath>>> = {
|
|
478
|
+
component: TComponent;
|
|
479
|
+
};
|
|
480
|
+
type ResourceLoaderOption<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never> = [TLoaderResult] extends [never] ? {
|
|
481
|
+
loader?: never;
|
|
482
|
+
} : {
|
|
483
|
+
loader: ResourceServerHandler<TContext, TLoaderResult, TPath>;
|
|
484
|
+
};
|
|
485
|
+
type ResourceActionOption<TPath extends string = string, TContext = unknown, TActionResult extends ServerResult = never> = [TActionResult] extends [never] ? {
|
|
486
|
+
action?: never;
|
|
487
|
+
} : {
|
|
488
|
+
action: ResourceServerHandler<TContext, TActionResult, TPath>;
|
|
489
|
+
};
|
|
490
|
+
type ResourceOptions<TPath extends string = string, TContext = unknown, TLoaderResult extends ServerResult = never, TActionResult extends ServerResult = never, TComponent extends React.ComponentType<ResourceComponentProps<TPath>> = never> = ResourceComponentOption<TPath, TComponent> & ResourceLoaderOption<TPath, TContext, TLoaderResult> & ResourceActionOption<TPath, TContext, TActionResult> & {
|
|
491
|
+
middleware?: MiddlewareRef<TContext, ServerResult>[];
|
|
492
|
+
};
|
|
493
|
+
declare function defineRoute<TContext = unknown, const TPath extends string = string>(path: TPath, options: RouteBaseOptions<NoInferType<TPath>, TContext> & {
|
|
494
|
+
loader?: never;
|
|
495
|
+
action?: never;
|
|
496
|
+
}): LitzRoute<TPath, TContext, never, never>;
|
|
497
|
+
declare function defineRoute<TContext = unknown, const TPath extends string = string, TLoaderResult extends ServerResult = ServerResult>(path: TPath, options: RouteBaseOptions<NoInferType<TPath>, TContext> & {
|
|
498
|
+
loader: RouteServerHandler<TContext, TLoaderResult, NoInferType<TPath>>;
|
|
499
|
+
action?: never;
|
|
500
|
+
}): LitzRoute<TPath, TContext, TLoaderResult, never>;
|
|
501
|
+
declare function defineRoute<TContext = unknown, const TPath extends string = string, TActionResult extends ServerResult = ServerResult>(path: TPath, options: RouteBaseOptions<NoInferType<TPath>, TContext> & {
|
|
502
|
+
loader?: never;
|
|
503
|
+
action: RouteServerHandler<TContext, TActionResult, NoInferType<TPath>>;
|
|
504
|
+
}): LitzRoute<TPath, TContext, never, TActionResult>;
|
|
505
|
+
declare function defineRoute<TContext = unknown, const TPath extends string = string, TLoaderResult extends ServerResult = ServerResult, TActionResult extends ServerResult = ServerResult>(path: TPath, options: RouteBaseOptions<NoInferType<TPath>, TContext> & {
|
|
506
|
+
loader: RouteServerHandler<TContext, TLoaderResult, NoInferType<TPath>>;
|
|
507
|
+
action: RouteServerHandler<TContext, TActionResult, NoInferType<TPath>>;
|
|
508
|
+
}): LitzRoute<TPath, TContext, TLoaderResult, TActionResult>;
|
|
509
|
+
declare function defineLayout<TContext = unknown, const TPath extends string = string>(path: TPath, options: LayoutBaseOptions<NoInferType<TPath>, TContext> & {
|
|
510
|
+
loader?: never;
|
|
511
|
+
}): LitzLayout<TPath, TContext, never>;
|
|
512
|
+
declare function defineLayout<TContext = unknown, const TPath extends string = string, TLoaderResult extends ServerResult = ServerResult>(path: TPath, options: LayoutBaseOptions<NoInferType<TPath>, TContext> & {
|
|
513
|
+
loader: RouteServerHandler<TContext, TLoaderResult, NoInferType<TPath>>;
|
|
514
|
+
}): LitzLayout<TPath, TContext, TLoaderResult>;
|
|
515
|
+
declare function useMatches(): LitzMatch[];
|
|
516
|
+
declare function usePathname(): string;
|
|
517
|
+
declare function useLocation(): LitzLocation;
|
|
518
|
+
declare function defineApiRoute<TContext = unknown, const TPath extends string = string, TMethods extends ApiRouteHandlers<TContext, TPath> = ApiRouteHandlers<TContext, TPath>>(path: TPath, definition: DefineApiRouteOptions<NoInferType<TContext>, NoInferType<TPath>, TMethods>): LitzApiRoute<TPath, TContext, TMethods>;
|
|
519
|
+
declare function defineResource<TContext = unknown, const TPath extends string = string>(path: TPath, options: ResourceOptions<NoInferType<TPath>, NoInferType<TContext>, never, never, React.ComponentType<ResourceComponentProps<TPath>>>): LitzResource<TPath, TContext, never, never, React.ComponentType<ResourceComponentProps<TPath>>>;
|
|
520
|
+
declare function defineResource<TContext = unknown, const TPath extends string = string, TLoaderResult extends ServerResult = ServerResult, TComponent extends React.ComponentType<ResourceComponentProps<TPath>> = React.ComponentType<ResourceComponentProps<TPath>>>(path: TPath, options: ResourceOptions<NoInferType<TPath>, NoInferType<TContext>, TLoaderResult, never, TComponent>): LitzResource<TPath, TContext, TLoaderResult, never, TComponent>;
|
|
521
|
+
declare function defineResource<TContext = unknown, const TPath extends string = string, TActionResult extends ServerResult = ServerResult, TComponent extends React.ComponentType<ResourceComponentProps<TPath>> = React.ComponentType<ResourceComponentProps<TPath>>>(path: TPath, options: ResourceOptions<NoInferType<TPath>, NoInferType<TContext>, never, TActionResult, TComponent>): LitzResource<TPath, TContext, never, TActionResult, TComponent>;
|
|
522
|
+
declare function defineResource<TContext = unknown, const TPath extends string = string, TLoaderResult extends ServerResult = ServerResult, TActionResult extends ServerResult = ServerResult, TComponent extends React.ComponentType<ResourceComponentProps<TPath>> = React.ComponentType<ResourceComponentProps<TPath>>>(path: TPath, options: ResourceOptions<NoInferType<TPath>, NoInferType<TContext>, TLoaderResult, TActionResult, TComponent>): LitzResource<TPath, TContext, TLoaderResult, TActionResult, TComponent>;
|
|
523
|
+
declare function server<TContext = unknown, TResult extends ServerResult = ServerResult, TPath extends string = string>(handler: (context: {
|
|
524
|
+
request: Request;
|
|
525
|
+
params: PathParams<NoInferType<TPath>>;
|
|
526
|
+
signal: AbortSignal;
|
|
527
|
+
context: NoInferType<TContext>;
|
|
528
|
+
}) => Promise<TResult> | TResult): RouteServerHandler<TContext, TResult, TPath>;
|
|
529
|
+
declare function withHeaders<TResponse extends Response>(result: TResponse, headers: HeadersInit): TResponse;
|
|
530
|
+
declare function withHeaders<TResult extends ResultWithHeaders>(result: TResult, headers: HeadersInit): TResult;
|
|
531
|
+
declare function data<TData>(value: TData, options?: {
|
|
532
|
+
headers?: HeadersInit;
|
|
533
|
+
status?: number;
|
|
534
|
+
revalidate?: string[];
|
|
535
|
+
}): DataResult<TData>;
|
|
536
|
+
declare function view<TNode extends React.ReactNode>(node: TNode, options?: {
|
|
537
|
+
headers?: HeadersInit;
|
|
538
|
+
revalidate?: string[];
|
|
539
|
+
}): ViewResult<TNode>;
|
|
540
|
+
declare function invalid<TData = unknown>(options: {
|
|
541
|
+
headers?: HeadersInit;
|
|
542
|
+
status?: number;
|
|
543
|
+
fields?: Record<string, string>;
|
|
544
|
+
formError?: string;
|
|
545
|
+
data?: TData;
|
|
546
|
+
}): InvalidResult<TData>;
|
|
547
|
+
declare function redirect(location: string, options?: {
|
|
548
|
+
headers?: HeadersInit;
|
|
549
|
+
status?: number;
|
|
550
|
+
replace?: boolean;
|
|
551
|
+
revalidate?: string[];
|
|
552
|
+
}): RedirectResult;
|
|
553
|
+
declare function error<TData = unknown>(status: number, message: string, options?: {
|
|
554
|
+
headers?: HeadersInit;
|
|
555
|
+
code?: string;
|
|
556
|
+
data?: TData;
|
|
557
|
+
}): ErrorResult<TData>;
|
|
558
|
+
//#endregion
|
|
559
|
+
export { ActionErrorResultFor, ActionHookResult, ActionHookResultFor, ActionSuccessResultFor, ApiFetchOptions, ApiHandlerContext, ApiRouteHandler, ApiRouteHandlers, ApiRouteMethod, DataResult, DefineApiRouteOptions, DefineLayoutOptions, DefineRouteOptions, ErrorResult, FaultResult, InvalidResult, LayoutReference, LitzApiRoute, LitzLayout, LitzLocation, LitzMatch, LitzResource, LitzRoute, LoaderHookResult, LoaderHookResultFor, Middleware, MiddlewareContext, MiddlewareHandler, MiddlewareNext, MiddlewareOverrides, MiddlewareRef, NormalizedResult, PathParams, RedirectResult, ResourceComponentProps, ResourceHandlerContext, ResourceRequest, ResourceServerHandler, RouteErrorLike, RouteFormProps, RouteHandlerContext, RouteServerHandler, RouteStatus, SearchParamsUpdate, ServerHandler, ServerResult, SetSearchParams, SubmitOptions, ViewResult, data, defineApiRoute, defineLayout, defineResource, defineRoute, error, invalid, redirect, server, useLocation, useMatches, usePathname, view, withHeaders };
|