@teyik0/furin 0.4.0-alpha.2 → 0.5.0-alpha.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/build/compile-entry.d.ts +2 -1
- package/dist/build/compile-entry.ts +17 -13
- package/dist/build/elysia-aot.d.ts +9 -0
- package/dist/build/entry-template.d.ts +5 -1
- package/dist/build/entry-template.ts +24 -5
- package/dist/build/index.js +753 -453
- package/dist/build/server-app-entry.d.ts +12 -0
- package/dist/cache.d.ts +1 -0
- package/dist/cache.js +185 -0
- package/dist/cli/index.js +766 -466
- package/dist/client/internal/runtime-types.d.ts +8 -1
- package/dist/client/link.js +221 -11
- package/dist/client/sync.d.ts +1 -0
- package/dist/config.d.ts +22 -21
- package/dist/config.js +1 -1
- package/dist/define-route.d.ts +273 -1009
- package/dist/furin.d.ts +20 -5
- package/dist/furin.js +6222 -5383
- package/dist/plugin/routes.d.ts +6 -0
- package/dist/server/assets/production.d.ts +3 -0
- package/dist/server/auto-invalidate/plugin.d.ts +8 -24
- package/dist/server/auto-invalidate/runtime.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +1 -1
- package/dist/server/cache/page-cache-state.d.ts +5 -0
- package/dist/server/cache/page-cache.d.ts +53 -0
- package/dist/server/cache/redis/index.d.ts +39 -0
- package/dist/server/cache/redis/index.js +396 -0
- package/dist/server/cache/redis/scripts.d.ts +6 -0
- package/dist/server/context-logger.d.ts +2 -2
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +7 -0
- package/dist/server/evlog.d.ts +14 -0
- package/dist/server/internal.d.ts +6 -0
- package/dist/server/internal.js +2537 -0
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ssg.d.ts +5 -0
- package/dist/server/render/static-params.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +1 -1
- package/dist/server/router/schemas.d.ts +1 -0
- package/dist/server/sync/index.js +794 -116
- package/dist/server/sync/plugin.d.ts +31 -158
- package/dist/server/sync/stream.d.ts +34 -49
- package/dist/shared/elysia-contract.d.ts +8 -14
- package/package.json +13 -7
- package/src/adapter/README.md +9 -2
- package/src/adapter/bun.ts +73 -27
- package/src/adapter/package.ts +6 -2
- package/src/adapter/runtime-build.ts +11 -4
- package/src/adapter/static.ts +8 -6
- package/src/adapter/vercel.ts +49 -30
- package/src/build/client.ts +18 -1
- package/src/build/compile-entry.ts +17 -13
- package/src/build/elysia-aot.ts +102 -0
- package/src/build/entry-template.ts +24 -5
- package/src/build/index.ts +0 -5
- package/src/build/production-instrumentation.ts +2 -2
- package/src/build/server-app-entry.ts +60 -0
- package/src/build/shared.ts +3 -1
- package/src/build/ssg-cache.ts +5 -10
- package/src/build/virtual-entry.ts +5 -4
- package/src/cache.ts +12 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +5 -2
- package/src/client/internal/runtime-types.ts +10 -1
- package/src/client/sync.ts +1 -0
- package/src/config.ts +3 -2
- package/src/define-route.ts +266 -128
- package/src/furin.ts +138 -149
- package/src/plugin/route-config-autofix.ts +11 -2
- package/src/plugin/routes.ts +85 -29
- package/src/server/assets/production.ts +99 -0
- package/src/server/auto-invalidate/plugin.ts +4 -4
- package/src/server/auto-invalidate/runtime.ts +74 -42
- package/src/server/browser-events/plugin.ts +6 -1
- package/src/server/cache/invalidation.ts +61 -20
- package/src/server/cache/page-cache-state.ts +22 -0
- package/src/server/cache/page-cache.ts +300 -0
- package/src/server/cache/redis/index.ts +350 -0
- package/src/server/cache/redis/scripts.ts +160 -0
- package/src/server/context-logger.ts +5 -5
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev-page-plugin.ts +54 -10
- package/src/server/evlog.ts +99 -0
- package/src/server/internal.ts +7 -0
- package/src/server/render/isr.ts +480 -132
- package/src/server/render/loaders.ts +18 -12
- package/src/server/render/not-found.ts +4 -4
- package/src/server/render/ppr-document.ts +2 -2
- package/src/server/render/ppr-route.ts +193 -7
- package/src/server/render/ssg.ts +148 -4
- package/src/server/render/ssr.ts +4 -6
- package/src/server/render/static-params.ts +174 -0
- package/src/server/router/defined-route.ts +2 -1
- package/src/server/router/hmr.ts +2 -0
- package/src/server/router/plugin.ts +44 -35
- package/src/server/router/schema-merge.ts +1 -1
- package/src/server/router/schemas.ts +174 -61
- package/src/server/sync/plugin.ts +14 -10
- package/src/server/sync/response.ts +3 -3
- package/src/shared/elysia-contract.ts +23 -25
package/src/define-route.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Context, Elysia, ValidationError } from "elysia";
|
|
2
2
|
import type { RequestLogger } from "evlog";
|
|
3
3
|
import type { HeadOptions, RenderingMode } from "./client.ts";
|
|
4
|
-
import { applySchemaDefaults } from "./server/router/schemas.ts";
|
|
4
|
+
import { applySchemaDefaults, coerceRouteInput } from "./server/router/schemas.ts";
|
|
5
5
|
import type {
|
|
6
6
|
ElysiaRouteLeaf,
|
|
7
7
|
ElysiaRouteParams,
|
|
@@ -27,13 +27,17 @@ interface LoaderData {
|
|
|
27
27
|
[key: string]: unknown;
|
|
28
28
|
}
|
|
29
29
|
type ReservedRenderContextKey =
|
|
30
|
+
| "catch"
|
|
30
31
|
| "children"
|
|
32
|
+
| "finally"
|
|
31
33
|
| "key"
|
|
32
34
|
| "params"
|
|
33
35
|
| "path"
|
|
34
36
|
| "query"
|
|
35
37
|
| "ref"
|
|
36
|
-
| "requestData"
|
|
38
|
+
| "requestData"
|
|
39
|
+
| "then"
|
|
40
|
+
| "toJSON";
|
|
37
41
|
type PublicLoaderData = LoaderData & {
|
|
38
42
|
[Key in ReservedRenderContextKey]?: never;
|
|
39
43
|
} & {
|
|
@@ -52,6 +56,13 @@ type DataOfRoute<Route> = Route extends {
|
|
|
52
56
|
? Omit<Props, ReservedRenderContextKey>
|
|
53
57
|
: NoFields
|
|
54
58
|
: NoFields;
|
|
59
|
+
type ParamsOfRoute<Route> = Route extends {
|
|
60
|
+
component: (props: infer Props) => unknown;
|
|
61
|
+
}
|
|
62
|
+
? Props extends { params: infer Params }
|
|
63
|
+
? Params
|
|
64
|
+
: NoFields
|
|
65
|
+
: NoFields;
|
|
55
66
|
type PromisedData<Data extends LoaderData> = {
|
|
56
67
|
[Key in keyof Data]: Promise<Awaited<Data[Key]>>;
|
|
57
68
|
};
|
|
@@ -74,28 +85,48 @@ interface SharedRouteConfig {
|
|
|
74
85
|
tags?: readonly string[];
|
|
75
86
|
}
|
|
76
87
|
|
|
77
|
-
type RenderingConfig
|
|
88
|
+
type RenderingConfig = SharedRouteConfig &
|
|
78
89
|
(
|
|
79
90
|
| {
|
|
80
91
|
mode: "ssr";
|
|
81
92
|
revalidate?: never;
|
|
82
|
-
staticParams?: never;
|
|
83
93
|
}
|
|
84
94
|
| {
|
|
85
95
|
mode: "ssg";
|
|
86
96
|
revalidate?: never;
|
|
87
|
-
staticParams?: () => Awaitable<readonly Params[]>;
|
|
88
97
|
}
|
|
89
98
|
| {
|
|
90
99
|
mode: "isr";
|
|
91
100
|
revalidate: number;
|
|
92
|
-
staticParams?: () => Awaitable<readonly Params[]>;
|
|
93
101
|
}
|
|
94
102
|
);
|
|
95
103
|
|
|
96
|
-
export type DefineRouteConfig = RenderingConfig
|
|
104
|
+
export type DefineRouteConfig = RenderingConfig;
|
|
105
|
+
|
|
106
|
+
type ConfigFor = RenderingConfig;
|
|
107
|
+
|
|
108
|
+
type StaticParamsContext<ParentParams, ParentData extends LoaderData> = {
|
|
109
|
+
params: Partial<ParentParams>;
|
|
110
|
+
} & PromisedData<ParentData>;
|
|
97
111
|
|
|
98
|
-
type
|
|
112
|
+
type StaticParamsResult<Params, ParentParams> = Omit<Params, keyof ParentParams> & Partial<Params>;
|
|
113
|
+
|
|
114
|
+
type StaticParams<Params, ParentParams, ParentData extends LoaderData> = (
|
|
115
|
+
context: StaticParamsContext<ParentParams, ParentData>
|
|
116
|
+
) => Awaitable<readonly StaticParamsResult<Params, ParentParams>[]>;
|
|
117
|
+
|
|
118
|
+
interface ErasedStaticParamsContext {
|
|
119
|
+
params: unknown;
|
|
120
|
+
[key: string]: unknown;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type RouteMetadata = DefineRouteConfig & {
|
|
124
|
+
staticParams?: (context: ErasedStaticParamsContext) => Awaitable<readonly unknown[]>;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
type ConfiguredChain<Mode extends RenderingMode, Chain> = Mode extends "ssr"
|
|
128
|
+
? Omit<Chain, "staticParams">
|
|
129
|
+
: Chain;
|
|
99
130
|
|
|
100
131
|
type LoaderContext<Params, Query, ParentData extends LoaderData> = {
|
|
101
132
|
params: Params;
|
|
@@ -182,7 +213,7 @@ export function getFurinRenderer(context: object): FurinRouteDispatcher | undefi
|
|
|
182
213
|
function registerPlain<Params, Query, ParentData extends LoaderData, Data extends LoaderData>(
|
|
183
214
|
loader: Loader<Params, Query, ParentData, Data> | undefined
|
|
184
215
|
) {
|
|
185
|
-
return new Elysia().get("
|
|
216
|
+
return new Elysia().get("", async (context) => {
|
|
186
217
|
const renderer = getFurinRenderer(context);
|
|
187
218
|
if (renderer) {
|
|
188
219
|
return renderer(context as unknown as FurinNativeRouteContext);
|
|
@@ -211,25 +242,21 @@ function registerSchema<
|
|
|
211
242
|
querySchema: QuerySchema,
|
|
212
243
|
loader: Loader<Params, Query, ParentData, Data> | undefined
|
|
213
244
|
) {
|
|
214
|
-
return new Elysia().get(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
);
|
|
230
|
-
},
|
|
231
|
-
{ params: paramsSchema, query: querySchema }
|
|
232
|
-
);
|
|
245
|
+
return new Elysia().get("", { params: paramsSchema, query: querySchema }, async (context) => {
|
|
246
|
+
const renderer = getFurinRenderer(context);
|
|
247
|
+
if (renderer) {
|
|
248
|
+
return renderer(context as unknown as FurinNativeRouteContext);
|
|
249
|
+
}
|
|
250
|
+
return Response.json(
|
|
251
|
+
loader
|
|
252
|
+
? await loader({
|
|
253
|
+
...context,
|
|
254
|
+
params: context.params as Params,
|
|
255
|
+
query: context.query as Query,
|
|
256
|
+
} as LoaderContext<Params, Query, ParentData>)
|
|
257
|
+
: {}
|
|
258
|
+
);
|
|
259
|
+
});
|
|
233
260
|
}
|
|
234
261
|
|
|
235
262
|
function registerQuery<
|
|
@@ -238,25 +265,21 @@ function registerQuery<
|
|
|
238
265
|
ParentData extends LoaderData,
|
|
239
266
|
Data extends LoaderData,
|
|
240
267
|
>(querySchema: QuerySchema, loader: Loader<NoFields, Query, ParentData, Data> | undefined) {
|
|
241
|
-
return new Elysia().get(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
);
|
|
257
|
-
},
|
|
258
|
-
{ query: querySchema }
|
|
259
|
-
);
|
|
268
|
+
return new Elysia().get("", { query: querySchema }, async (context) => {
|
|
269
|
+
const renderer = getFurinRenderer(context);
|
|
270
|
+
if (renderer) {
|
|
271
|
+
return renderer(context as unknown as FurinNativeRouteContext);
|
|
272
|
+
}
|
|
273
|
+
return Response.json(
|
|
274
|
+
loader
|
|
275
|
+
? await loader({
|
|
276
|
+
...context,
|
|
277
|
+
params: {},
|
|
278
|
+
query: context.query as Query,
|
|
279
|
+
} as LoaderContext<NoFields, Query, ParentData>)
|
|
280
|
+
: {}
|
|
281
|
+
);
|
|
282
|
+
});
|
|
260
283
|
}
|
|
261
284
|
|
|
262
285
|
function schemaValues(value: unknown): SchemaValues {
|
|
@@ -288,20 +311,13 @@ async function validateLayoutSchema(
|
|
|
288
311
|
): Promise<SchemaValues> {
|
|
289
312
|
const selectedValues = selectLayoutSchemaValues(schema, value);
|
|
290
313
|
const selected = isTypeBoxObjectSchema(schema)
|
|
291
|
-
? applySchemaDefaults(schema, selectedValues)
|
|
314
|
+
? coerceRouteInput(schema, applySchemaDefaults(schema, selectedValues))
|
|
292
315
|
: selectedValues;
|
|
293
|
-
const validator = getSchemaValidator(schema
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
checked === false ||
|
|
297
|
-
(checked !== null && typeof checked === "object" && "issues" in checked)
|
|
298
|
-
) {
|
|
299
|
-
throw new ValidationError(type, schema, selected);
|
|
316
|
+
const validator = getSchemaValidator(schema);
|
|
317
|
+
if (validator?.Check(selected) === false) {
|
|
318
|
+
throw new ValidationError(type, selected, [...validator.Errors(selected)], schema);
|
|
300
319
|
}
|
|
301
|
-
const parsed =
|
|
302
|
-
checked !== null && typeof checked === "object" && "value" in checked
|
|
303
|
-
? checked.value
|
|
304
|
-
: validator?.parse(selected);
|
|
320
|
+
const parsed = await validator?.parse(selected, type);
|
|
305
321
|
return { ...schemaValues(value), ...schemaValues(parsed) };
|
|
306
322
|
}
|
|
307
323
|
|
|
@@ -312,7 +328,7 @@ function registerLayout<Params, Query, ParentData extends LoaderData, Data exten
|
|
|
312
328
|
) {
|
|
313
329
|
const app = new Elysia();
|
|
314
330
|
if (paramsSchema || querySchema || loader) {
|
|
315
|
-
app.
|
|
331
|
+
app.derive(async (context) => {
|
|
316
332
|
const params = paramsSchema
|
|
317
333
|
? await validateLayoutSchema("params", paramsSchema, context.params)
|
|
318
334
|
: context.params;
|
|
@@ -336,7 +352,7 @@ function registerLayout<Params, Query, ParentData extends LoaderData, Data exten
|
|
|
336
352
|
return app;
|
|
337
353
|
}
|
|
338
354
|
|
|
339
|
-
function withMetadata
|
|
355
|
+
function withMetadata(metadata: RouteMetadata) {
|
|
340
356
|
return {
|
|
341
357
|
mode: metadata.mode,
|
|
342
358
|
revalidate: metadata.revalidate,
|
|
@@ -345,17 +361,41 @@ function withMetadata<Metadata extends DefineRouteConfig>(metadata: Metadata) {
|
|
|
345
361
|
};
|
|
346
362
|
}
|
|
347
363
|
|
|
364
|
+
function withStaticParams<Params, ParentParams, ParentData extends LoaderData>(
|
|
365
|
+
metadata: RouteMetadata,
|
|
366
|
+
staticParams: StaticParams<Params, ParentParams, ParentData>,
|
|
367
|
+
hasRequestLoader: boolean
|
|
368
|
+
): RouteMetadata {
|
|
369
|
+
if (metadata.mode === "ssr") {
|
|
370
|
+
throw new TypeError("[furin] staticParams() requires mode ssg or isr.");
|
|
371
|
+
}
|
|
372
|
+
if (hasRequestLoader) {
|
|
373
|
+
throw new TypeError("[furin] staticParams() must be declared before requestLoader().");
|
|
374
|
+
}
|
|
375
|
+
if (metadata.staticParams) {
|
|
376
|
+
throw new TypeError("[furin] staticParams() can only be declared once.");
|
|
377
|
+
}
|
|
378
|
+
return { ...metadata, staticParams: staticParams as RouteMetadata["staticParams"] };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function assertStaticParamsOutsideConfig(options: object): void {
|
|
382
|
+
if ("staticParams" in options) {
|
|
383
|
+
throw new TypeError("[furin] staticParams() must be chained after config().");
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
348
387
|
class NoSchemaChain<
|
|
349
388
|
Params = NoFields,
|
|
350
389
|
Query = NoFields,
|
|
351
390
|
ParentData extends LoaderData = NoFields,
|
|
352
391
|
RequestData extends LoaderData = NoFields,
|
|
392
|
+
ParentParams = NoFields,
|
|
353
393
|
> {
|
|
354
|
-
protected readonly metadata:
|
|
394
|
+
protected readonly metadata: RouteMetadata;
|
|
355
395
|
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
356
396
|
|
|
357
397
|
constructor(
|
|
358
|
-
metadata:
|
|
398
|
+
metadata: RouteMetadata,
|
|
359
399
|
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
360
400
|
) {
|
|
361
401
|
this.metadata = metadata;
|
|
@@ -364,10 +404,19 @@ class NoSchemaChain<
|
|
|
364
404
|
|
|
365
405
|
requestLoader<Data extends LoaderData>(
|
|
366
406
|
requestLoader: RequestLoader<Params, Query, Data>
|
|
367
|
-
): NoSchemaChain<Params, Query, ParentData, Data> {
|
|
407
|
+
): Omit<NoSchemaChain<Params, Query, ParentData, Data, ParentParams>, "staticParams"> {
|
|
368
408
|
return new NoSchemaChain(this.metadata, requestLoader);
|
|
369
409
|
}
|
|
370
410
|
|
|
411
|
+
staticParams(
|
|
412
|
+
staticParams: StaticParams<Params, ParentParams, ParentData>
|
|
413
|
+
): Omit<NoSchemaChain<Params, Query, ParentData, RequestData, ParentParams>, "staticParams"> {
|
|
414
|
+
return new NoSchemaChain(
|
|
415
|
+
withStaticParams(this.metadata, staticParams, this.requestLoaderFunction !== undefined),
|
|
416
|
+
this.requestLoaderFunction
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
371
420
|
loader<Data extends PublicLoaderData>(
|
|
372
421
|
loader: Loader<Params, Query, ParentData, Data>
|
|
373
422
|
): LoadedNoSchema<Params, Query, ParentData, Data, RequestData> {
|
|
@@ -406,11 +455,11 @@ class LoadedNoSchema<
|
|
|
406
455
|
> {
|
|
407
456
|
protected readonly headFunction: Head<Params, Query, ParentData, Data> | undefined;
|
|
408
457
|
protected readonly loaderFunction: Loader<Params, Query, ParentData, Data>;
|
|
409
|
-
protected readonly metadata:
|
|
458
|
+
protected readonly metadata: RouteMetadata;
|
|
410
459
|
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
411
460
|
|
|
412
461
|
constructor(
|
|
413
|
-
metadata:
|
|
462
|
+
metadata: RouteMetadata,
|
|
414
463
|
loader: Loader<Params, Query, ParentData, Data>,
|
|
415
464
|
head: Head<Params, Query, ParentData, Data> | undefined,
|
|
416
465
|
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
@@ -475,13 +524,14 @@ class QuerySchemaChain<
|
|
|
475
524
|
QuerySchema extends FurinSchema,
|
|
476
525
|
ParentData extends LoaderData = NoFields,
|
|
477
526
|
RequestData extends LoaderData = NoFields,
|
|
527
|
+
ParentParams = NoFields,
|
|
478
528
|
> {
|
|
479
|
-
protected readonly metadata:
|
|
529
|
+
protected readonly metadata: RouteMetadata;
|
|
480
530
|
protected readonly querySchema: QuerySchema;
|
|
481
531
|
protected readonly requestLoaderFunction: RequestLoader<NoFields, Query, RequestData> | undefined;
|
|
482
532
|
|
|
483
533
|
constructor(
|
|
484
|
-
metadata:
|
|
534
|
+
metadata: RouteMetadata,
|
|
485
535
|
querySchema: QuerySchema,
|
|
486
536
|
requestLoader: RequestLoader<NoFields, Query, RequestData> | undefined
|
|
487
537
|
) {
|
|
@@ -492,10 +542,23 @@ class QuerySchemaChain<
|
|
|
492
542
|
|
|
493
543
|
requestLoader<Data extends LoaderData>(
|
|
494
544
|
requestLoader: RequestLoader<NoFields, Query, Data>
|
|
495
|
-
): QuerySchemaChain<Query, QuerySchema, ParentData, Data> {
|
|
545
|
+
): Omit<QuerySchemaChain<Query, QuerySchema, ParentData, Data, ParentParams>, "staticParams"> {
|
|
496
546
|
return new QuerySchemaChain(this.metadata, this.querySchema, requestLoader);
|
|
497
547
|
}
|
|
498
548
|
|
|
549
|
+
staticParams(
|
|
550
|
+
staticParams: StaticParams<NoFields, ParentParams, ParentData>
|
|
551
|
+
): Omit<
|
|
552
|
+
QuerySchemaChain<Query, QuerySchema, ParentData, RequestData, ParentParams>,
|
|
553
|
+
"staticParams"
|
|
554
|
+
> {
|
|
555
|
+
return new QuerySchemaChain(
|
|
556
|
+
withStaticParams(this.metadata, staticParams, this.requestLoaderFunction !== undefined),
|
|
557
|
+
this.querySchema,
|
|
558
|
+
this.requestLoaderFunction
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
499
562
|
loader<Data extends PublicLoaderData>(
|
|
500
563
|
loader: Loader<NoFields, Query, ParentData, Data>
|
|
501
564
|
): LoadedQuerySchema<Query, QuerySchema, ParentData, Data, RequestData> {
|
|
@@ -546,12 +609,12 @@ class LoadedQuerySchema<
|
|
|
546
609
|
> {
|
|
547
610
|
protected readonly headFunction: Head<NoFields, Query, ParentData, Data> | undefined;
|
|
548
611
|
protected readonly loaderFunction: Loader<NoFields, Query, ParentData, Data>;
|
|
549
|
-
protected readonly metadata:
|
|
612
|
+
protected readonly metadata: RouteMetadata;
|
|
550
613
|
protected readonly querySchema: QuerySchema;
|
|
551
614
|
protected readonly requestLoaderFunction: RequestLoader<NoFields, Query, RequestData> | undefined;
|
|
552
615
|
|
|
553
616
|
constructor(
|
|
554
|
-
metadata:
|
|
617
|
+
metadata: RouteMetadata,
|
|
555
618
|
querySchema: QuerySchema,
|
|
556
619
|
loader: Loader<NoFields, Query, ParentData, Data>,
|
|
557
620
|
head: Head<NoFields, Query, ParentData, Data> | undefined,
|
|
@@ -631,14 +694,15 @@ class SchemaChain<
|
|
|
631
694
|
QuerySchema extends FurinSchema | undefined,
|
|
632
695
|
ParentData extends LoaderData = NoFields,
|
|
633
696
|
RequestData extends LoaderData = NoFields,
|
|
697
|
+
ParentParams = NoFields,
|
|
634
698
|
> {
|
|
635
|
-
protected readonly metadata:
|
|
699
|
+
protected readonly metadata: RouteMetadata;
|
|
636
700
|
protected readonly paramsSchema: ParamsSchema;
|
|
637
701
|
protected readonly querySchema: QuerySchema;
|
|
638
702
|
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
639
703
|
|
|
640
704
|
constructor(
|
|
641
|
-
metadata:
|
|
705
|
+
metadata: RouteMetadata,
|
|
642
706
|
paramsSchema: ParamsSchema,
|
|
643
707
|
querySchema: QuerySchema,
|
|
644
708
|
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
@@ -651,10 +715,35 @@ class SchemaChain<
|
|
|
651
715
|
|
|
652
716
|
requestLoader<RequestLoaderData extends LoaderData>(
|
|
653
717
|
requestLoader: RequestLoader<Params, Query, RequestLoaderData>
|
|
654
|
-
):
|
|
718
|
+
): Omit<
|
|
719
|
+
SchemaChain<
|
|
720
|
+
Params,
|
|
721
|
+
Query,
|
|
722
|
+
ParamsSchema,
|
|
723
|
+
QuerySchema,
|
|
724
|
+
ParentData,
|
|
725
|
+
RequestLoaderData,
|
|
726
|
+
ParentParams
|
|
727
|
+
>,
|
|
728
|
+
"staticParams"
|
|
729
|
+
> {
|
|
655
730
|
return new SchemaChain(this.metadata, this.paramsSchema, this.querySchema, requestLoader);
|
|
656
731
|
}
|
|
657
732
|
|
|
733
|
+
staticParams(
|
|
734
|
+
staticParams: StaticParams<Params, ParentParams, ParentData>
|
|
735
|
+
): Omit<
|
|
736
|
+
SchemaChain<Params, Query, ParamsSchema, QuerySchema, ParentData, RequestData, ParentParams>,
|
|
737
|
+
"staticParams"
|
|
738
|
+
> {
|
|
739
|
+
return new SchemaChain(
|
|
740
|
+
withStaticParams(this.metadata, staticParams, this.requestLoaderFunction !== undefined),
|
|
741
|
+
this.paramsSchema,
|
|
742
|
+
this.querySchema,
|
|
743
|
+
this.requestLoaderFunction
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
|
|
658
747
|
loader<Data extends PublicLoaderData>(
|
|
659
748
|
loader: Loader<Params, Query, ParentData, Data>
|
|
660
749
|
): LoadedSchema<Params, Query, ParamsSchema, QuerySchema, ParentData, Data, RequestData> {
|
|
@@ -712,13 +801,13 @@ class LoadedSchema<
|
|
|
712
801
|
> {
|
|
713
802
|
protected readonly headFunction: Head<Params, Query, ParentData, Data> | undefined;
|
|
714
803
|
protected readonly loaderFunction: Loader<Params, Query, ParentData, Data>;
|
|
715
|
-
protected readonly metadata:
|
|
804
|
+
protected readonly metadata: RouteMetadata;
|
|
716
805
|
protected readonly paramsSchema: ParamsSchema;
|
|
717
806
|
protected readonly querySchema: QuerySchema;
|
|
718
807
|
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
719
808
|
|
|
720
809
|
constructor(
|
|
721
|
-
metadata:
|
|
810
|
+
metadata: RouteMetadata,
|
|
722
811
|
paramsSchema: ParamsSchema,
|
|
723
812
|
querySchema: QuerySchema,
|
|
724
813
|
loader: Loader<Params, Query, ParentData, Data>,
|
|
@@ -803,50 +892,83 @@ class HeadedSchema<
|
|
|
803
892
|
* before it — a route without an explicit rendering contract does not compile.
|
|
804
893
|
*/
|
|
805
894
|
class UnconfiguredRoute {
|
|
806
|
-
config<LayoutRoute, QuerySchema extends FurinSchema>(
|
|
807
|
-
options: ConfigFor
|
|
895
|
+
config<LayoutRoute, QuerySchema extends FurinSchema, Mode extends RenderingMode>(
|
|
896
|
+
options: ConfigFor & {
|
|
808
897
|
layout: LayoutRoute;
|
|
809
|
-
mode:
|
|
898
|
+
mode: Mode;
|
|
810
899
|
params?: undefined;
|
|
811
900
|
query: QuerySchema;
|
|
812
901
|
}
|
|
813
|
-
):
|
|
814
|
-
|
|
815
|
-
|
|
902
|
+
): ConfiguredChain<
|
|
903
|
+
Mode,
|
|
904
|
+
QuerySchemaChain<
|
|
905
|
+
ParamsOf<QuerySchema>,
|
|
906
|
+
QuerySchema,
|
|
907
|
+
DataOfRoute<LayoutRoute>,
|
|
908
|
+
NoFields,
|
|
909
|
+
ParamsOfRoute<LayoutRoute>
|
|
910
|
+
>
|
|
911
|
+
>;
|
|
912
|
+
config<
|
|
913
|
+
LayoutRoute,
|
|
914
|
+
ParamsSchema extends FurinSchema,
|
|
915
|
+
QuerySchema extends FurinSchema,
|
|
916
|
+
Mode extends RenderingMode,
|
|
917
|
+
>(
|
|
918
|
+
options: ConfigFor & {
|
|
816
919
|
layout: LayoutRoute;
|
|
817
|
-
mode:
|
|
920
|
+
mode: Mode;
|
|
818
921
|
params: ParamsSchema;
|
|
819
922
|
query: QuerySchema;
|
|
820
923
|
}
|
|
821
|
-
):
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
924
|
+
): ConfiguredChain<
|
|
925
|
+
Mode,
|
|
926
|
+
SchemaChain<
|
|
927
|
+
ParamsOf<ParamsSchema>,
|
|
928
|
+
ParamsOf<QuerySchema>,
|
|
929
|
+
ParamsSchema,
|
|
930
|
+
QuerySchema,
|
|
931
|
+
DataOfRoute<LayoutRoute>,
|
|
932
|
+
NoFields,
|
|
933
|
+
ParamsOfRoute<LayoutRoute>
|
|
934
|
+
>
|
|
827
935
|
>;
|
|
828
|
-
config<LayoutRoute, ParamsSchema extends FurinSchema>(
|
|
829
|
-
options: ConfigFor
|
|
936
|
+
config<LayoutRoute, ParamsSchema extends FurinSchema, Mode extends RenderingMode>(
|
|
937
|
+
options: ConfigFor & {
|
|
830
938
|
layout: LayoutRoute;
|
|
831
|
-
mode:
|
|
939
|
+
mode: Mode;
|
|
832
940
|
params: ParamsSchema;
|
|
833
941
|
query?: undefined;
|
|
834
942
|
}
|
|
835
|
-
):
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
943
|
+
): ConfiguredChain<
|
|
944
|
+
Mode,
|
|
945
|
+
SchemaChain<
|
|
946
|
+
ParamsOf<ParamsSchema>,
|
|
947
|
+
NoFields,
|
|
948
|
+
ParamsSchema,
|
|
949
|
+
undefined,
|
|
950
|
+
DataOfRoute<LayoutRoute>,
|
|
951
|
+
NoFields,
|
|
952
|
+
ParamsOfRoute<LayoutRoute>
|
|
953
|
+
>
|
|
841
954
|
>;
|
|
842
|
-
config<LayoutRoute>(
|
|
843
|
-
options: ConfigFor
|
|
955
|
+
config<LayoutRoute, Mode extends RenderingMode>(
|
|
956
|
+
options: ConfigFor & {
|
|
844
957
|
layout: LayoutRoute;
|
|
845
|
-
mode:
|
|
958
|
+
mode: Mode;
|
|
846
959
|
params?: undefined;
|
|
847
960
|
query?: undefined;
|
|
848
961
|
}
|
|
849
|
-
):
|
|
962
|
+
): ConfiguredChain<
|
|
963
|
+
Mode,
|
|
964
|
+
NoSchemaChain<
|
|
965
|
+
NoFields,
|
|
966
|
+
NoFields,
|
|
967
|
+
DataOfRoute<LayoutRoute>,
|
|
968
|
+
NoFields,
|
|
969
|
+
ParamsOfRoute<LayoutRoute>
|
|
970
|
+
>
|
|
971
|
+
>;
|
|
850
972
|
config<
|
|
851
973
|
LayoutRoute,
|
|
852
974
|
ParamsSchema extends FurinSchema | undefined,
|
|
@@ -858,23 +980,34 @@ class UnconfiguredRoute {
|
|
|
858
980
|
params?: ParamsSchema;
|
|
859
981
|
query?: QuerySchema;
|
|
860
982
|
}
|
|
861
|
-
) {
|
|
983
|
+
): unknown {
|
|
984
|
+
assertStaticParamsOutsideConfig(options);
|
|
862
985
|
if (options.params === undefined) {
|
|
863
986
|
if (options.query !== undefined) {
|
|
864
987
|
return new QuerySchemaChain<
|
|
865
988
|
ParamsOf<Exclude<QuerySchema, undefined>>,
|
|
866
989
|
Exclude<QuerySchema, undefined>,
|
|
867
|
-
DataOfRoute<LayoutRoute
|
|
990
|
+
DataOfRoute<LayoutRoute>,
|
|
991
|
+
NoFields,
|
|
992
|
+
ParamsOfRoute<LayoutRoute>
|
|
868
993
|
>(options, options.query as Exclude<QuerySchema, undefined>, undefined);
|
|
869
994
|
}
|
|
870
|
-
return new NoSchemaChain<
|
|
995
|
+
return new NoSchemaChain<
|
|
996
|
+
NoFields,
|
|
997
|
+
NoFields,
|
|
998
|
+
DataOfRoute<LayoutRoute>,
|
|
999
|
+
NoFields,
|
|
1000
|
+
ParamsOfRoute<LayoutRoute>
|
|
1001
|
+
>(options, undefined);
|
|
871
1002
|
}
|
|
872
1003
|
return new SchemaChain<
|
|
873
1004
|
ParamsOf<Exclude<ParamsSchema, undefined>>,
|
|
874
1005
|
ParamsOf<Exclude<QuerySchema, undefined>>,
|
|
875
1006
|
Exclude<ParamsSchema, undefined>,
|
|
876
1007
|
Exclude<QuerySchema, undefined>,
|
|
877
|
-
DataOfRoute<LayoutRoute
|
|
1008
|
+
DataOfRoute<LayoutRoute>,
|
|
1009
|
+
NoFields,
|
|
1010
|
+
ParamsOfRoute<LayoutRoute>
|
|
878
1011
|
>(
|
|
879
1012
|
options,
|
|
880
1013
|
options.params as Exclude<ParamsSchema, undefined>,
|
|
@@ -889,47 +1022,52 @@ class UnconfiguredRoute {
|
|
|
889
1022
|
* `config()` requires only `mode` (the TanStack `createRootRoute` analogue).
|
|
890
1023
|
*/
|
|
891
1024
|
class UnconfiguredRootRoute {
|
|
892
|
-
config<QuerySchema extends FurinSchema>(
|
|
893
|
-
options: ConfigFor
|
|
894
|
-
mode:
|
|
1025
|
+
config<QuerySchema extends FurinSchema, Mode extends RenderingMode>(
|
|
1026
|
+
options: ConfigFor & {
|
|
1027
|
+
mode: Mode;
|
|
895
1028
|
params?: undefined;
|
|
896
1029
|
query: QuerySchema;
|
|
897
1030
|
}
|
|
898
|
-
): QuerySchemaChain<ParamsOf<QuerySchema>, QuerySchema, NoFields
|
|
899
|
-
config<
|
|
900
|
-
|
|
901
|
-
|
|
1031
|
+
): ConfiguredChain<Mode, QuerySchemaChain<ParamsOf<QuerySchema>, QuerySchema, NoFields>>;
|
|
1032
|
+
config<
|
|
1033
|
+
ParamsSchema extends FurinSchema,
|
|
1034
|
+
QuerySchema extends FurinSchema,
|
|
1035
|
+
Mode extends RenderingMode,
|
|
1036
|
+
>(
|
|
1037
|
+
options: ConfigFor & {
|
|
1038
|
+
mode: Mode;
|
|
902
1039
|
params: ParamsSchema;
|
|
903
1040
|
query: QuerySchema;
|
|
904
1041
|
}
|
|
905
|
-
):
|
|
906
|
-
|
|
907
|
-
ParamsOf<QuerySchema>,
|
|
908
|
-
ParamsSchema,
|
|
909
|
-
QuerySchema,
|
|
910
|
-
NoFields
|
|
1042
|
+
): ConfiguredChain<
|
|
1043
|
+
Mode,
|
|
1044
|
+
SchemaChain<ParamsOf<ParamsSchema>, ParamsOf<QuerySchema>, ParamsSchema, QuerySchema, NoFields>
|
|
911
1045
|
>;
|
|
912
|
-
config<ParamsSchema extends FurinSchema>(
|
|
913
|
-
options: ConfigFor
|
|
914
|
-
mode:
|
|
1046
|
+
config<ParamsSchema extends FurinSchema, Mode extends RenderingMode>(
|
|
1047
|
+
options: ConfigFor & {
|
|
1048
|
+
mode: Mode;
|
|
915
1049
|
params: ParamsSchema;
|
|
916
1050
|
query?: undefined;
|
|
917
1051
|
}
|
|
918
|
-
):
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1052
|
+
): ConfiguredChain<
|
|
1053
|
+
Mode,
|
|
1054
|
+
SchemaChain<ParamsOf<ParamsSchema>, NoFields, ParamsSchema, undefined, NoFields>
|
|
1055
|
+
>;
|
|
1056
|
+
config<Mode extends RenderingMode>(
|
|
1057
|
+
options: ConfigFor & {
|
|
1058
|
+
mode: Mode;
|
|
922
1059
|
params?: undefined;
|
|
923
1060
|
query?: undefined;
|
|
924
1061
|
}
|
|
925
|
-
): NoSchemaChain<NoFields, NoFields, NoFields
|
|
1062
|
+
): ConfiguredChain<Mode, NoSchemaChain<NoFields, NoFields, NoFields>>;
|
|
926
1063
|
config<ParamsSchema extends FurinSchema | undefined, QuerySchema extends FurinSchema | undefined>(
|
|
927
1064
|
options: DefineRouteConfig & {
|
|
928
1065
|
mode: RenderingMode;
|
|
929
1066
|
params?: ParamsSchema;
|
|
930
1067
|
query?: QuerySchema;
|
|
931
1068
|
}
|
|
932
|
-
) {
|
|
1069
|
+
): unknown {
|
|
1070
|
+
assertStaticParamsOutsideConfig(options);
|
|
933
1071
|
if (options.params === undefined) {
|
|
934
1072
|
if (options.query !== undefined) {
|
|
935
1073
|
return new QuerySchemaChain<
|