@teyik0/furin 0.3.0-alpha.1 → 0.4.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/adapter/bun.d.ts +1 -1
- package/dist/build/client.d.ts +2 -2
- package/dist/build/entry-template.d.ts +4 -0
- package/dist/build/entry-template.ts +17 -3
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +8288 -6629
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +1 -1
- package/dist/cli/index.js +7862 -6168
- package/dist/client/boundaries.d.ts +2 -0
- package/dist/client/define-route.d.ts +35 -0
- package/dist/client/document.d.ts +26 -0
- package/dist/client/hmr.d.ts +10 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1177 -894
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/types.d.ts +32 -24
- package/dist/client.d.ts +4 -159
- package/dist/client.js +183 -21
- package/dist/config.d.ts +8 -8
- package/dist/config.js +8 -8
- package/dist/define-route.d.ts +1355 -0
- package/dist/furin.d.ts +17 -33
- package/dist/furin.js +13444 -10301
- package/dist/plugin/index.js +953 -244
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +27 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +1 -1
- package/dist/rsc.js +3 -3
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/devtools/instrumentation.d.ts +2 -2
- package/dist/server/devtools/instrumentation.production.d.ts +2 -2
- package/dist/server/devtools/plugin.d.ts +2 -2
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +0 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +2 -1
- package/dist/server/render/index.d.ts +1 -1
- package/dist/server/render/index.ts +0 -1
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-route.d.ts +1 -1
- package/dist/server/render/ssg.d.ts +1 -1
- package/dist/server/render/ssr.d.ts +7 -6
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/hmr.d.ts +16 -8
- package/dist/server/router/patterns.d.ts +6 -0
- package/dist/server/router/plugin.d.ts +4 -3
- package/dist/server/router/schema-merge.d.ts +2 -2
- package/dist/server/router/schemas.d.ts +5 -5
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -0
- package/dist/server/sync/index.js +961 -806
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/shared/await.d.ts +6 -7
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +44 -41
- package/src/adapter/bun.ts +42 -22
- package/src/adapter/package.ts +20 -14
- package/src/adapter/static.ts +4 -3
- package/src/build/client.ts +20 -3
- package/src/build/entry-template.ts +17 -3
- package/src/build/hydrate.ts +98 -28
- package/src/build/index.ts +2 -2
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +1 -1
- package/src/build/ssg-cache.ts +2 -5
- package/src/build/types.ts +1 -1
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +7 -7
- package/src/client/boundaries.tsx +9 -1
- package/src/client/define-route.ts +48 -0
- package/src/client/document.tsx +165 -0
- package/src/client/hmr.ts +40 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +25 -2
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/types.ts +50 -24
- package/src/client.ts +14 -316
- package/src/config.ts +10 -10
- package/src/define-route.ts +959 -0
- package/src/devtools/devtools-element.js +11 -10
- package/src/furin.ts +303 -53
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +891 -0
- package/src/plugin/transform-client.ts +132 -266
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +1 -1
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/dev-page-plugin.ts +31 -12
- package/src/server/devtools/instrumentation.production.ts +2 -2
- package/src/server/devtools/instrumentation.ts +2 -2
- package/src/server/devtools/plugin.ts +5 -3
- package/src/server/instance.ts +3 -3
- package/src/server/internal.ts +3 -0
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +0 -41
- package/src/server/render/document.tsx +25 -0
- package/src/server/render/element.tsx +13 -1
- package/src/server/render/index.ts +0 -1
- package/src/server/render/isr.ts +31 -10
- package/src/server/render/loaders.ts +31 -6
- package/src/server/render/not-found.ts +51 -27
- package/src/server/render/ppr-route.ts +1 -1
- package/src/server/render/ssg.ts +1 -1
- package/src/server/render/ssr.ts +271 -113
- package/src/server/render/template.ts +91 -1
- package/src/server/router/defined-route.ts +110 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.ts +111 -40
- package/src/server/router/patterns.ts +40 -12
- package/src/server/router/plugin.ts +63 -46
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +16 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/shared/await.tsx +6 -7
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/route-map.ts +37 -0
- package/src/shared/utils/index.ts +2 -20
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/router/index.d.ts +0 -7
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/router/index.ts +0 -28
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
import { type Context, Elysia, ValidationError } from "elysia";
|
|
2
|
+
import type { RequestLogger } from "evlog";
|
|
3
|
+
import type { HeadOptions, RenderingMode } from "./client.ts";
|
|
4
|
+
import { applySchemaDefaults } from "./server/router/schemas.ts";
|
|
5
|
+
import type {
|
|
6
|
+
ElysiaRouteLeaf,
|
|
7
|
+
ElysiaRouteParams,
|
|
8
|
+
FurinSchema,
|
|
9
|
+
FurinUnwrap,
|
|
10
|
+
} from "./shared/elysia-contract.ts";
|
|
11
|
+
import { getSchemaValidator, isTypeBoxObjectSchema } from "./shared/elysia-contract.ts";
|
|
12
|
+
|
|
13
|
+
type NoFields = NonNullable<unknown>;
|
|
14
|
+
type Awaitable<T> = Promise<T> | T;
|
|
15
|
+
export const FURIN_RENDER_DECORATOR = "$furinRender";
|
|
16
|
+
|
|
17
|
+
export interface FurinNativeRouteContext {
|
|
18
|
+
params: unknown;
|
|
19
|
+
query: unknown;
|
|
20
|
+
request: Request;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type FurinRouteDispatcher = (context: FurinNativeRouteContext) => unknown;
|
|
25
|
+
|
|
26
|
+
interface LoaderData {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
interface SchemaValues {
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
type ParamsOf<Schema extends FurinSchema | undefined> = Schema extends FurinSchema
|
|
33
|
+
? FurinUnwrap<Schema>
|
|
34
|
+
: NoFields;
|
|
35
|
+
type DataOfRoute<Route> = Route extends {
|
|
36
|
+
component: (props: infer Props) => unknown;
|
|
37
|
+
}
|
|
38
|
+
? Props extends { data: infer Data extends LoaderData }
|
|
39
|
+
? Data
|
|
40
|
+
: NoFields
|
|
41
|
+
: NoFields;
|
|
42
|
+
type PromisedData<Data extends LoaderData> = {
|
|
43
|
+
[Key in keyof Data]: Promise<Awaited<Data[Key]>>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export interface RequestLoaderContext<Params = NoFields, Query = NoFields> {
|
|
47
|
+
readonly cookies: { get: (name: string) => unknown };
|
|
48
|
+
readonly headers: {
|
|
49
|
+
entries: () => IterableIterator<[string, string]>;
|
|
50
|
+
get: (name: string) => string | null;
|
|
51
|
+
has: (name: string) => boolean;
|
|
52
|
+
};
|
|
53
|
+
readonly log: RequestLogger;
|
|
54
|
+
readonly params: Params;
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly query: Query;
|
|
57
|
+
readonly request: Request;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface SharedRouteConfig {
|
|
61
|
+
tags?: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type RenderingConfig<Params> = SharedRouteConfig &
|
|
65
|
+
(
|
|
66
|
+
| {
|
|
67
|
+
mode: "ssr";
|
|
68
|
+
revalidate?: never;
|
|
69
|
+
staticParams?: never;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
mode: "ssg";
|
|
73
|
+
revalidate?: never;
|
|
74
|
+
staticParams?: () => Awaitable<readonly Params[]>;
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
mode: "isr";
|
|
78
|
+
revalidate: number;
|
|
79
|
+
staticParams?: () => Awaitable<readonly Params[]>;
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export type DefineRouteConfig = RenderingConfig<unknown>;
|
|
84
|
+
|
|
85
|
+
type ConfigFor<Params> = RenderingConfig<Params>;
|
|
86
|
+
|
|
87
|
+
type LoaderContext<Params, Query, ParentData extends LoaderData> = {
|
|
88
|
+
params: Params;
|
|
89
|
+
query: Query;
|
|
90
|
+
log: RequestLogger;
|
|
91
|
+
} & Omit<Context<{ params: Params; query: Query }>, "params" | "query"> &
|
|
92
|
+
PromisedData<ParentData>;
|
|
93
|
+
|
|
94
|
+
type Loader<Params, Query, ParentData extends LoaderData, Data extends LoaderData> = (
|
|
95
|
+
context: LoaderContext<Params, Query, ParentData>
|
|
96
|
+
) => Awaitable<Data>;
|
|
97
|
+
|
|
98
|
+
type RequestDataContext<RequestData extends LoaderData> = keyof RequestData extends never
|
|
99
|
+
? NoFields
|
|
100
|
+
: { requestData: Promise<RequestData> };
|
|
101
|
+
|
|
102
|
+
type RequestLoader<Params, Query, Data extends LoaderData> = (
|
|
103
|
+
context: RequestLoaderContext<Params, Query>
|
|
104
|
+
) => Awaitable<Data>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Same-name parent/loader fields whose types are incompatible map to a
|
|
108
|
+
* readable branded error object; compatible overrides (same-type) map to
|
|
109
|
+
* `never` and are dropped from the mapped type.
|
|
110
|
+
*/
|
|
111
|
+
type ParentDataConflicts<ParentData extends LoaderData, Data extends LoaderData> = {
|
|
112
|
+
[Key in keyof Data & keyof ParentData as Data[Key] extends ParentData[Key] ? never : Key]: {
|
|
113
|
+
__furinConflict: "this loader key overwrites a parent loader key with an incompatible type";
|
|
114
|
+
parentType: ParentData[Key];
|
|
115
|
+
loaderType: Data[Key];
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type WithoutParentDataConflicts<
|
|
120
|
+
ParentData extends LoaderData,
|
|
121
|
+
Data extends LoaderData,
|
|
122
|
+
> = keyof ParentDataConflicts<ParentData, Data> extends never
|
|
123
|
+
? ParentData & Data
|
|
124
|
+
: Omit<ParentData & Data, keyof ParentDataConflicts<ParentData, Data>> &
|
|
125
|
+
ParentDataConflicts<ParentData, Data>;
|
|
126
|
+
|
|
127
|
+
type RenderContext<
|
|
128
|
+
Params,
|
|
129
|
+
Query,
|
|
130
|
+
ParentData extends LoaderData,
|
|
131
|
+
Data extends LoaderData,
|
|
132
|
+
RequestData extends LoaderData,
|
|
133
|
+
> = {
|
|
134
|
+
data: WithoutParentDataConflicts<ParentData, Data>;
|
|
135
|
+
params: Params;
|
|
136
|
+
path: string;
|
|
137
|
+
query: Query;
|
|
138
|
+
} & RequestDataContext<RequestData>;
|
|
139
|
+
|
|
140
|
+
type Component<
|
|
141
|
+
Params,
|
|
142
|
+
Query,
|
|
143
|
+
ParentData extends LoaderData,
|
|
144
|
+
Data extends LoaderData,
|
|
145
|
+
RequestData extends LoaderData,
|
|
146
|
+
> = (props: RenderContext<Params, Query, ParentData, Data, RequestData>) => React.ReactNode;
|
|
147
|
+
|
|
148
|
+
type LayoutComponent<
|
|
149
|
+
Params,
|
|
150
|
+
Query,
|
|
151
|
+
ParentData extends LoaderData,
|
|
152
|
+
Data extends LoaderData,
|
|
153
|
+
RequestData extends LoaderData,
|
|
154
|
+
> = (
|
|
155
|
+
props: RenderContext<Params, Query, ParentData, Data, RequestData> & {
|
|
156
|
+
children: React.ReactNode;
|
|
157
|
+
}
|
|
158
|
+
) => React.ReactNode;
|
|
159
|
+
|
|
160
|
+
type Head<Params, Query, ParentData extends LoaderData, Data extends LoaderData> = (
|
|
161
|
+
context: RenderContext<Params, Query, ParentData, Data, NoFields>
|
|
162
|
+
) => HeadOptions;
|
|
163
|
+
|
|
164
|
+
export function getFurinRenderer(context: object): FurinRouteDispatcher | undefined {
|
|
165
|
+
const renderer = (context as { $furinRender?: unknown })[FURIN_RENDER_DECORATOR];
|
|
166
|
+
return typeof renderer === "function" ? (renderer as FurinRouteDispatcher) : undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function registerPlain<Params, Query, ParentData extends LoaderData, Data extends LoaderData>(
|
|
170
|
+
loader: Loader<Params, Query, ParentData, Data> | undefined
|
|
171
|
+
) {
|
|
172
|
+
return new Elysia().get("/", async (context) => {
|
|
173
|
+
const renderer = getFurinRenderer(context);
|
|
174
|
+
if (renderer) {
|
|
175
|
+
return renderer(context as unknown as FurinNativeRouteContext);
|
|
176
|
+
}
|
|
177
|
+
return Response.json(
|
|
178
|
+
loader
|
|
179
|
+
? await loader({
|
|
180
|
+
...context,
|
|
181
|
+
params: {} as Params,
|
|
182
|
+
query: {} as Query,
|
|
183
|
+
} as LoaderContext<Params, Query, ParentData>)
|
|
184
|
+
: {}
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function registerSchema<
|
|
190
|
+
Params,
|
|
191
|
+
Query,
|
|
192
|
+
ParamsSchema extends FurinSchema,
|
|
193
|
+
QuerySchema extends FurinSchema | undefined,
|
|
194
|
+
ParentData extends LoaderData,
|
|
195
|
+
Data extends LoaderData,
|
|
196
|
+
>(
|
|
197
|
+
paramsSchema: ParamsSchema,
|
|
198
|
+
querySchema: QuerySchema,
|
|
199
|
+
loader: Loader<Params, Query, ParentData, Data> | undefined
|
|
200
|
+
) {
|
|
201
|
+
return new Elysia().get(
|
|
202
|
+
"/",
|
|
203
|
+
async (context) => {
|
|
204
|
+
const renderer = getFurinRenderer(context);
|
|
205
|
+
if (renderer) {
|
|
206
|
+
return renderer(context as unknown as FurinNativeRouteContext);
|
|
207
|
+
}
|
|
208
|
+
return Response.json(
|
|
209
|
+
loader
|
|
210
|
+
? await loader({
|
|
211
|
+
...context,
|
|
212
|
+
params: context.params as Params,
|
|
213
|
+
query: context.query as Query,
|
|
214
|
+
} as LoaderContext<Params, Query, ParentData>)
|
|
215
|
+
: {}
|
|
216
|
+
);
|
|
217
|
+
},
|
|
218
|
+
{ params: paramsSchema, query: querySchema }
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function registerQuery<
|
|
223
|
+
Query,
|
|
224
|
+
QuerySchema extends FurinSchema,
|
|
225
|
+
ParentData extends LoaderData,
|
|
226
|
+
Data extends LoaderData,
|
|
227
|
+
>(querySchema: QuerySchema, loader: Loader<NoFields, Query, ParentData, Data> | undefined) {
|
|
228
|
+
return new Elysia().get(
|
|
229
|
+
"/",
|
|
230
|
+
async (context) => {
|
|
231
|
+
const renderer = getFurinRenderer(context);
|
|
232
|
+
if (renderer) {
|
|
233
|
+
return renderer(context as unknown as FurinNativeRouteContext);
|
|
234
|
+
}
|
|
235
|
+
return Response.json(
|
|
236
|
+
loader
|
|
237
|
+
? await loader({
|
|
238
|
+
...context,
|
|
239
|
+
params: {},
|
|
240
|
+
query: context.query as Query,
|
|
241
|
+
} as LoaderContext<NoFields, Query, ParentData>)
|
|
242
|
+
: {}
|
|
243
|
+
);
|
|
244
|
+
},
|
|
245
|
+
{ query: querySchema }
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function schemaValues(value: unknown): SchemaValues {
|
|
250
|
+
return value !== null && typeof value === "object" ? (value as SchemaValues) : {};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function selectLayoutSchemaValues(schema: FurinSchema, value: unknown): SchemaValues {
|
|
254
|
+
const values = schemaValues(value);
|
|
255
|
+
if (!isTypeBoxObjectSchema(schema)) {
|
|
256
|
+
return values;
|
|
257
|
+
}
|
|
258
|
+
const { properties } = schema;
|
|
259
|
+
if (properties === null || typeof properties !== "object") {
|
|
260
|
+
return values;
|
|
261
|
+
}
|
|
262
|
+
const selected: SchemaValues = {};
|
|
263
|
+
for (const key of Object.keys(properties)) {
|
|
264
|
+
if (key in values) {
|
|
265
|
+
selected[key] = values[key];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return selected;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function validateLayoutSchema(
|
|
272
|
+
type: "params" | "query",
|
|
273
|
+
schema: FurinSchema,
|
|
274
|
+
value: unknown
|
|
275
|
+
): Promise<SchemaValues> {
|
|
276
|
+
const selectedValues = selectLayoutSchemaValues(schema, value);
|
|
277
|
+
const selected = isTypeBoxObjectSchema(schema)
|
|
278
|
+
? applySchemaDefaults(schema, selectedValues)
|
|
279
|
+
: selectedValues;
|
|
280
|
+
const validator = getSchemaValidator(schema, { coerce: true, dynamic: true });
|
|
281
|
+
const checked = await validator?.Check(selected);
|
|
282
|
+
if (
|
|
283
|
+
checked === false ||
|
|
284
|
+
(checked !== null && typeof checked === "object" && "issues" in checked)
|
|
285
|
+
) {
|
|
286
|
+
throw new ValidationError(type, schema, selected);
|
|
287
|
+
}
|
|
288
|
+
const parsed =
|
|
289
|
+
checked !== null && typeof checked === "object" && "value" in checked
|
|
290
|
+
? checked.value
|
|
291
|
+
: validator?.parse(selected);
|
|
292
|
+
return { ...schemaValues(value), ...schemaValues(parsed) };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function registerLayout<Params, Query, ParentData extends LoaderData, Data extends LoaderData>(
|
|
296
|
+
paramsSchema: FurinSchema | undefined,
|
|
297
|
+
querySchema: FurinSchema | undefined,
|
|
298
|
+
loader: Loader<Params, Query, ParentData, Data> | undefined
|
|
299
|
+
) {
|
|
300
|
+
const app = new Elysia();
|
|
301
|
+
if (paramsSchema || querySchema || loader) {
|
|
302
|
+
app.resolve(async (context) => {
|
|
303
|
+
const params = paramsSchema
|
|
304
|
+
? await validateLayoutSchema("params", paramsSchema, context.params)
|
|
305
|
+
: context.params;
|
|
306
|
+
const query = querySchema
|
|
307
|
+
? await validateLayoutSchema("query", querySchema, context.query)
|
|
308
|
+
: context.query;
|
|
309
|
+
if (getFurinRenderer(context)) {
|
|
310
|
+
return { params, query };
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
...(loader
|
|
314
|
+
? await loader({
|
|
315
|
+
...context,
|
|
316
|
+
params: params as Params,
|
|
317
|
+
query: query as Query,
|
|
318
|
+
} as LoaderContext<Params, Query, ParentData>)
|
|
319
|
+
: {}),
|
|
320
|
+
};
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
return app;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function withMetadata<Metadata extends DefineRouteConfig>(metadata: Metadata) {
|
|
327
|
+
return {
|
|
328
|
+
mode: metadata.mode,
|
|
329
|
+
revalidate: metadata.revalidate,
|
|
330
|
+
staticParams: metadata.staticParams,
|
|
331
|
+
tags: metadata.tags,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
class NoSchemaChain<
|
|
336
|
+
Params = NoFields,
|
|
337
|
+
Query = NoFields,
|
|
338
|
+
ParentData extends LoaderData = NoFields,
|
|
339
|
+
RequestData extends LoaderData = NoFields,
|
|
340
|
+
> {
|
|
341
|
+
protected readonly metadata: DefineRouteConfig;
|
|
342
|
+
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
343
|
+
|
|
344
|
+
constructor(
|
|
345
|
+
metadata: DefineRouteConfig,
|
|
346
|
+
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
347
|
+
) {
|
|
348
|
+
this.metadata = metadata;
|
|
349
|
+
this.requestLoaderFunction = requestLoader;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
requestLoader<Data extends LoaderData>(
|
|
353
|
+
requestLoader: RequestLoader<Params, Query, Data>
|
|
354
|
+
): NoSchemaChain<Params, Query, ParentData, Data> {
|
|
355
|
+
return new NoSchemaChain(this.metadata, requestLoader);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
loader<Data extends LoaderData>(
|
|
359
|
+
loader: Loader<Params, Query, ParentData, Data>
|
|
360
|
+
): LoadedNoSchema<Params, Query, ParentData, Data, RequestData> {
|
|
361
|
+
return new LoadedNoSchema(this.metadata, loader, undefined, this.requestLoaderFunction);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
page(component: Component<Params, Query, ParentData, NoFields, RequestData>) {
|
|
365
|
+
return {
|
|
366
|
+
__type: "FURIN_ROUTE" as const,
|
|
367
|
+
...withMetadata(this.metadata),
|
|
368
|
+
component,
|
|
369
|
+
elysia: registerPlain<Params, Query, ParentData, NoFields>(undefined),
|
|
370
|
+
page: component,
|
|
371
|
+
requestLoader: this.requestLoaderFunction,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
layout(component: LayoutComponent<Params, Query, ParentData, NoFields, RequestData>) {
|
|
376
|
+
return {
|
|
377
|
+
__type: "FURIN_ROUTE" as const,
|
|
378
|
+
...withMetadata(this.metadata),
|
|
379
|
+
component,
|
|
380
|
+
elysia: registerLayout<Params, Query, ParentData, NoFields>(undefined, undefined, undefined),
|
|
381
|
+
layout: component,
|
|
382
|
+
requestLoader: this.requestLoaderFunction,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
class LoadedNoSchema<
|
|
388
|
+
Params,
|
|
389
|
+
Query,
|
|
390
|
+
ParentData extends LoaderData,
|
|
391
|
+
Data extends LoaderData,
|
|
392
|
+
RequestData extends LoaderData,
|
|
393
|
+
> {
|
|
394
|
+
protected readonly headFunction: Head<Params, Query, ParentData, Data> | undefined;
|
|
395
|
+
protected readonly loaderFunction: Loader<Params, Query, ParentData, Data>;
|
|
396
|
+
protected readonly metadata: DefineRouteConfig;
|
|
397
|
+
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
398
|
+
|
|
399
|
+
constructor(
|
|
400
|
+
metadata: DefineRouteConfig,
|
|
401
|
+
loader: Loader<Params, Query, ParentData, Data>,
|
|
402
|
+
head: Head<Params, Query, ParentData, Data> | undefined,
|
|
403
|
+
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
404
|
+
) {
|
|
405
|
+
this.metadata = metadata;
|
|
406
|
+
this.loaderFunction = loader;
|
|
407
|
+
this.headFunction = head;
|
|
408
|
+
this.requestLoaderFunction = requestLoader;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
head(
|
|
412
|
+
head: Head<Params, Query, ParentData, Data>
|
|
413
|
+
): HeadedNoSchema<Params, Query, ParentData, Data, RequestData> {
|
|
414
|
+
return new HeadedNoSchema(this.metadata, this.loaderFunction, head, this.requestLoaderFunction);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
page(component: Component<Params, Query, ParentData, Data, RequestData>) {
|
|
418
|
+
return {
|
|
419
|
+
__type: "FURIN_ROUTE" as const,
|
|
420
|
+
...withMetadata(this.metadata),
|
|
421
|
+
component,
|
|
422
|
+
elysia: registerPlain<Params, Query, ParentData, Data>(this.loaderFunction),
|
|
423
|
+
head: this.headFunction,
|
|
424
|
+
loader: this.loaderFunction,
|
|
425
|
+
page: component,
|
|
426
|
+
requestLoader: this.requestLoaderFunction,
|
|
427
|
+
useLoaderData: (): ParentData & Data => undefined as unknown as ParentData & Data,
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
layout(component: LayoutComponent<Params, Query, ParentData, Data, RequestData>) {
|
|
432
|
+
return {
|
|
433
|
+
__type: "FURIN_ROUTE" as const,
|
|
434
|
+
...withMetadata(this.metadata),
|
|
435
|
+
component,
|
|
436
|
+
elysia: registerLayout<Params, Query, ParentData, Data>(
|
|
437
|
+
undefined,
|
|
438
|
+
undefined,
|
|
439
|
+
this.loaderFunction
|
|
440
|
+
),
|
|
441
|
+
head: this.headFunction,
|
|
442
|
+
layout: component,
|
|
443
|
+
loader: this.loaderFunction,
|
|
444
|
+
requestLoader: this.requestLoaderFunction,
|
|
445
|
+
useLoaderData: (): ParentData & Data => undefined as unknown as ParentData & Data,
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
class HeadedNoSchema<
|
|
451
|
+
Params,
|
|
452
|
+
Query,
|
|
453
|
+
ParentData extends LoaderData,
|
|
454
|
+
Data extends LoaderData,
|
|
455
|
+
RequestData extends LoaderData,
|
|
456
|
+
> extends LoadedNoSchema<Params, Query, ParentData, Data, RequestData> {
|
|
457
|
+
declare readonly head: never;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
class QuerySchemaChain<
|
|
461
|
+
Query,
|
|
462
|
+
QuerySchema extends FurinSchema,
|
|
463
|
+
ParentData extends LoaderData = NoFields,
|
|
464
|
+
RequestData extends LoaderData = NoFields,
|
|
465
|
+
> {
|
|
466
|
+
protected readonly metadata: DefineRouteConfig;
|
|
467
|
+
protected readonly querySchema: QuerySchema;
|
|
468
|
+
protected readonly requestLoaderFunction: RequestLoader<NoFields, Query, RequestData> | undefined;
|
|
469
|
+
|
|
470
|
+
constructor(
|
|
471
|
+
metadata: DefineRouteConfig,
|
|
472
|
+
querySchema: QuerySchema,
|
|
473
|
+
requestLoader: RequestLoader<NoFields, Query, RequestData> | undefined
|
|
474
|
+
) {
|
|
475
|
+
this.metadata = metadata;
|
|
476
|
+
this.querySchema = querySchema;
|
|
477
|
+
this.requestLoaderFunction = requestLoader;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
requestLoader<Data extends LoaderData>(
|
|
481
|
+
requestLoader: RequestLoader<NoFields, Query, Data>
|
|
482
|
+
): QuerySchemaChain<Query, QuerySchema, ParentData, Data> {
|
|
483
|
+
return new QuerySchemaChain(this.metadata, this.querySchema, requestLoader);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
loader<Data extends LoaderData>(
|
|
487
|
+
loader: Loader<NoFields, Query, ParentData, Data>
|
|
488
|
+
): LoadedQuerySchema<Query, QuerySchema, ParentData, Data, RequestData> {
|
|
489
|
+
return new LoadedQuerySchema(
|
|
490
|
+
this.metadata,
|
|
491
|
+
this.querySchema,
|
|
492
|
+
loader,
|
|
493
|
+
undefined,
|
|
494
|
+
this.requestLoaderFunction
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
page(component: Component<NoFields, Query, ParentData, NoFields, RequestData>) {
|
|
499
|
+
return {
|
|
500
|
+
__type: "FURIN_ROUTE" as const,
|
|
501
|
+
...withMetadata(this.metadata),
|
|
502
|
+
component,
|
|
503
|
+
elysia: registerQuery<Query, QuerySchema, ParentData, NoFields>(this.querySchema, undefined),
|
|
504
|
+
page: component,
|
|
505
|
+
requestLoader: this.requestLoaderFunction,
|
|
506
|
+
schemas: { query: this.querySchema },
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
layout(component: LayoutComponent<NoFields, Query, ParentData, NoFields, RequestData>) {
|
|
511
|
+
return {
|
|
512
|
+
__type: "FURIN_ROUTE" as const,
|
|
513
|
+
...withMetadata(this.metadata),
|
|
514
|
+
component,
|
|
515
|
+
elysia: registerLayout<NoFields, Query, ParentData, NoFields>(
|
|
516
|
+
undefined,
|
|
517
|
+
this.querySchema,
|
|
518
|
+
undefined
|
|
519
|
+
),
|
|
520
|
+
layout: component,
|
|
521
|
+
requestLoader: this.requestLoaderFunction,
|
|
522
|
+
schemas: { query: this.querySchema },
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
class LoadedQuerySchema<
|
|
528
|
+
Query,
|
|
529
|
+
QuerySchema extends FurinSchema,
|
|
530
|
+
ParentData extends LoaderData,
|
|
531
|
+
Data extends LoaderData,
|
|
532
|
+
RequestData extends LoaderData,
|
|
533
|
+
> {
|
|
534
|
+
protected readonly headFunction: Head<NoFields, Query, ParentData, Data> | undefined;
|
|
535
|
+
protected readonly loaderFunction: Loader<NoFields, Query, ParentData, Data>;
|
|
536
|
+
protected readonly metadata: DefineRouteConfig;
|
|
537
|
+
protected readonly querySchema: QuerySchema;
|
|
538
|
+
protected readonly requestLoaderFunction: RequestLoader<NoFields, Query, RequestData> | undefined;
|
|
539
|
+
|
|
540
|
+
constructor(
|
|
541
|
+
metadata: DefineRouteConfig,
|
|
542
|
+
querySchema: QuerySchema,
|
|
543
|
+
loader: Loader<NoFields, Query, ParentData, Data>,
|
|
544
|
+
head: Head<NoFields, Query, ParentData, Data> | undefined,
|
|
545
|
+
requestLoader: RequestLoader<NoFields, Query, RequestData> | undefined
|
|
546
|
+
) {
|
|
547
|
+
this.metadata = metadata;
|
|
548
|
+
this.querySchema = querySchema;
|
|
549
|
+
this.loaderFunction = loader;
|
|
550
|
+
this.headFunction = head;
|
|
551
|
+
this.requestLoaderFunction = requestLoader;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
head(
|
|
555
|
+
head: Head<NoFields, Query, ParentData, Data>
|
|
556
|
+
): HeadedQuerySchema<Query, QuerySchema, ParentData, Data, RequestData> {
|
|
557
|
+
return new HeadedQuerySchema(
|
|
558
|
+
this.metadata,
|
|
559
|
+
this.querySchema,
|
|
560
|
+
this.loaderFunction,
|
|
561
|
+
head,
|
|
562
|
+
this.requestLoaderFunction
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
page(component: Component<NoFields, Query, ParentData, Data, RequestData>) {
|
|
567
|
+
return {
|
|
568
|
+
__type: "FURIN_ROUTE" as const,
|
|
569
|
+
...withMetadata(this.metadata),
|
|
570
|
+
component,
|
|
571
|
+
elysia: registerQuery<Query, QuerySchema, ParentData, Data>(
|
|
572
|
+
this.querySchema,
|
|
573
|
+
this.loaderFunction
|
|
574
|
+
),
|
|
575
|
+
head: this.headFunction,
|
|
576
|
+
loader: this.loaderFunction,
|
|
577
|
+
page: component,
|
|
578
|
+
requestLoader: this.requestLoaderFunction,
|
|
579
|
+
schemas: { query: this.querySchema },
|
|
580
|
+
useLoaderData: (): ParentData & Data => undefined as unknown as ParentData & Data,
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
layout(component: LayoutComponent<NoFields, Query, ParentData, Data, RequestData>) {
|
|
585
|
+
return {
|
|
586
|
+
__type: "FURIN_ROUTE" as const,
|
|
587
|
+
...withMetadata(this.metadata),
|
|
588
|
+
component,
|
|
589
|
+
elysia: registerLayout<NoFields, Query, ParentData, Data>(
|
|
590
|
+
undefined,
|
|
591
|
+
this.querySchema,
|
|
592
|
+
this.loaderFunction
|
|
593
|
+
),
|
|
594
|
+
head: this.headFunction,
|
|
595
|
+
layout: component,
|
|
596
|
+
loader: this.loaderFunction,
|
|
597
|
+
requestLoader: this.requestLoaderFunction,
|
|
598
|
+
schemas: { query: this.querySchema },
|
|
599
|
+
useLoaderData: (): ParentData & Data => undefined as unknown as ParentData & Data,
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
class HeadedQuerySchema<
|
|
605
|
+
Query,
|
|
606
|
+
QuerySchema extends FurinSchema,
|
|
607
|
+
ParentData extends LoaderData,
|
|
608
|
+
Data extends LoaderData,
|
|
609
|
+
RequestData extends LoaderData,
|
|
610
|
+
> extends LoadedQuerySchema<Query, QuerySchema, ParentData, Data, RequestData> {
|
|
611
|
+
declare readonly head: never;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
class SchemaChain<
|
|
615
|
+
Params,
|
|
616
|
+
Query,
|
|
617
|
+
ParamsSchema extends FurinSchema,
|
|
618
|
+
QuerySchema extends FurinSchema | undefined,
|
|
619
|
+
ParentData extends LoaderData = NoFields,
|
|
620
|
+
RequestData extends LoaderData = NoFields,
|
|
621
|
+
> {
|
|
622
|
+
protected readonly metadata: DefineRouteConfig;
|
|
623
|
+
protected readonly paramsSchema: ParamsSchema;
|
|
624
|
+
protected readonly querySchema: QuerySchema;
|
|
625
|
+
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
626
|
+
|
|
627
|
+
constructor(
|
|
628
|
+
metadata: DefineRouteConfig,
|
|
629
|
+
paramsSchema: ParamsSchema,
|
|
630
|
+
querySchema: QuerySchema,
|
|
631
|
+
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
632
|
+
) {
|
|
633
|
+
this.metadata = metadata;
|
|
634
|
+
this.paramsSchema = paramsSchema;
|
|
635
|
+
this.querySchema = querySchema;
|
|
636
|
+
this.requestLoaderFunction = requestLoader;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
requestLoader<RequestLoaderData extends LoaderData>(
|
|
640
|
+
requestLoader: RequestLoader<Params, Query, RequestLoaderData>
|
|
641
|
+
): SchemaChain<Params, Query, ParamsSchema, QuerySchema, ParentData, RequestLoaderData> {
|
|
642
|
+
return new SchemaChain(this.metadata, this.paramsSchema, this.querySchema, requestLoader);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
loader<Data extends LoaderData>(
|
|
646
|
+
loader: Loader<Params, Query, ParentData, Data>
|
|
647
|
+
): LoadedSchema<Params, Query, ParamsSchema, QuerySchema, ParentData, Data, RequestData> {
|
|
648
|
+
return new LoadedSchema(
|
|
649
|
+
this.metadata,
|
|
650
|
+
this.paramsSchema,
|
|
651
|
+
this.querySchema,
|
|
652
|
+
loader,
|
|
653
|
+
undefined,
|
|
654
|
+
this.requestLoaderFunction
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
page(component: Component<Params, Query, ParentData, NoFields, RequestData>) {
|
|
659
|
+
return {
|
|
660
|
+
__type: "FURIN_ROUTE" as const,
|
|
661
|
+
...withMetadata(this.metadata),
|
|
662
|
+
component,
|
|
663
|
+
elysia: registerSchema<Params, Query, ParamsSchema, QuerySchema, ParentData, NoFields>(
|
|
664
|
+
this.paramsSchema,
|
|
665
|
+
this.querySchema,
|
|
666
|
+
undefined
|
|
667
|
+
),
|
|
668
|
+
page: component,
|
|
669
|
+
requestLoader: this.requestLoaderFunction,
|
|
670
|
+
schemas: { params: this.paramsSchema, query: this.querySchema },
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
layout(component: LayoutComponent<Params, Query, ParentData, NoFields, RequestData>) {
|
|
675
|
+
return {
|
|
676
|
+
__type: "FURIN_ROUTE" as const,
|
|
677
|
+
...withMetadata(this.metadata),
|
|
678
|
+
component,
|
|
679
|
+
elysia: registerLayout<Params, Query, ParentData, NoFields>(
|
|
680
|
+
this.paramsSchema,
|
|
681
|
+
this.querySchema,
|
|
682
|
+
undefined
|
|
683
|
+
),
|
|
684
|
+
layout: component,
|
|
685
|
+
requestLoader: this.requestLoaderFunction,
|
|
686
|
+
schemas: { params: this.paramsSchema, query: this.querySchema },
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
class LoadedSchema<
|
|
692
|
+
Params,
|
|
693
|
+
Query,
|
|
694
|
+
ParamsSchema extends FurinSchema,
|
|
695
|
+
QuerySchema extends FurinSchema | undefined,
|
|
696
|
+
ParentData extends LoaderData,
|
|
697
|
+
Data extends LoaderData,
|
|
698
|
+
RequestData extends LoaderData,
|
|
699
|
+
> {
|
|
700
|
+
protected readonly headFunction: Head<Params, Query, ParentData, Data> | undefined;
|
|
701
|
+
protected readonly loaderFunction: Loader<Params, Query, ParentData, Data>;
|
|
702
|
+
protected readonly metadata: DefineRouteConfig;
|
|
703
|
+
protected readonly paramsSchema: ParamsSchema;
|
|
704
|
+
protected readonly querySchema: QuerySchema;
|
|
705
|
+
protected readonly requestLoaderFunction: RequestLoader<Params, Query, RequestData> | undefined;
|
|
706
|
+
|
|
707
|
+
constructor(
|
|
708
|
+
metadata: DefineRouteConfig,
|
|
709
|
+
paramsSchema: ParamsSchema,
|
|
710
|
+
querySchema: QuerySchema,
|
|
711
|
+
loader: Loader<Params, Query, ParentData, Data>,
|
|
712
|
+
head: Head<Params, Query, ParentData, Data> | undefined,
|
|
713
|
+
requestLoader: RequestLoader<Params, Query, RequestData> | undefined
|
|
714
|
+
) {
|
|
715
|
+
this.metadata = metadata;
|
|
716
|
+
this.paramsSchema = paramsSchema;
|
|
717
|
+
this.querySchema = querySchema;
|
|
718
|
+
this.loaderFunction = loader;
|
|
719
|
+
this.headFunction = head;
|
|
720
|
+
this.requestLoaderFunction = requestLoader;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
head(
|
|
724
|
+
head: Head<Params, Query, ParentData, Data>
|
|
725
|
+
): HeadedSchema<Params, Query, ParamsSchema, QuerySchema, ParentData, Data, RequestData> {
|
|
726
|
+
return new HeadedSchema(
|
|
727
|
+
this.metadata,
|
|
728
|
+
this.paramsSchema,
|
|
729
|
+
this.querySchema,
|
|
730
|
+
this.loaderFunction,
|
|
731
|
+
head,
|
|
732
|
+
this.requestLoaderFunction
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
page(component: Component<Params, Query, ParentData, Data, RequestData>) {
|
|
737
|
+
return {
|
|
738
|
+
__type: "FURIN_ROUTE" as const,
|
|
739
|
+
...withMetadata(this.metadata),
|
|
740
|
+
component,
|
|
741
|
+
elysia: registerSchema<Params, Query, ParamsSchema, QuerySchema, ParentData, Data>(
|
|
742
|
+
this.paramsSchema,
|
|
743
|
+
this.querySchema,
|
|
744
|
+
this.loaderFunction
|
|
745
|
+
),
|
|
746
|
+
head: this.headFunction,
|
|
747
|
+
loader: this.loaderFunction,
|
|
748
|
+
page: component,
|
|
749
|
+
requestLoader: this.requestLoaderFunction,
|
|
750
|
+
schemas: { params: this.paramsSchema, query: this.querySchema },
|
|
751
|
+
useLoaderData: (): ParentData & Data => undefined as unknown as ParentData & Data,
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
layout(component: LayoutComponent<Params, Query, ParentData, Data, RequestData>) {
|
|
756
|
+
return {
|
|
757
|
+
__type: "FURIN_ROUTE" as const,
|
|
758
|
+
...withMetadata(this.metadata),
|
|
759
|
+
component,
|
|
760
|
+
elysia: registerLayout<Params, Query, ParentData, Data>(
|
|
761
|
+
this.paramsSchema,
|
|
762
|
+
this.querySchema,
|
|
763
|
+
this.loaderFunction
|
|
764
|
+
),
|
|
765
|
+
head: this.headFunction,
|
|
766
|
+
layout: component,
|
|
767
|
+
loader: this.loaderFunction,
|
|
768
|
+
requestLoader: this.requestLoaderFunction,
|
|
769
|
+
schemas: { params: this.paramsSchema, query: this.querySchema },
|
|
770
|
+
useLoaderData: (): ParentData & Data => undefined as unknown as ParentData & Data,
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
class HeadedSchema<
|
|
776
|
+
Params,
|
|
777
|
+
Query,
|
|
778
|
+
ParamsSchema extends FurinSchema,
|
|
779
|
+
QuerySchema extends FurinSchema | undefined,
|
|
780
|
+
ParentData extends LoaderData,
|
|
781
|
+
Data extends LoaderData,
|
|
782
|
+
RequestData extends LoaderData,
|
|
783
|
+
> extends LoadedSchema<Params, Query, ParamsSchema, QuerySchema, ParentData, Data, RequestData> {
|
|
784
|
+
declare readonly head: never;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* First stage of the builder: `config()` is MANDATORY and must declare at
|
|
789
|
+
* least `layout` and `mode`. Loader/page/layout are intentionally unreachable
|
|
790
|
+
* before it — a route without an explicit rendering contract does not compile.
|
|
791
|
+
*/
|
|
792
|
+
class UnconfiguredRoute {
|
|
793
|
+
config<LayoutRoute, QuerySchema extends FurinSchema>(
|
|
794
|
+
options: ConfigFor<NoFields> & {
|
|
795
|
+
layout: LayoutRoute;
|
|
796
|
+
mode: RenderingMode;
|
|
797
|
+
params?: undefined;
|
|
798
|
+
query: QuerySchema;
|
|
799
|
+
}
|
|
800
|
+
): QuerySchemaChain<ParamsOf<QuerySchema>, QuerySchema, DataOfRoute<LayoutRoute>>;
|
|
801
|
+
config<LayoutRoute, ParamsSchema extends FurinSchema, QuerySchema extends FurinSchema>(
|
|
802
|
+
options: ConfigFor<ParamsOf<ParamsSchema>> & {
|
|
803
|
+
layout: LayoutRoute;
|
|
804
|
+
mode: RenderingMode;
|
|
805
|
+
params: ParamsSchema;
|
|
806
|
+
query: QuerySchema;
|
|
807
|
+
}
|
|
808
|
+
): SchemaChain<
|
|
809
|
+
ParamsOf<ParamsSchema>,
|
|
810
|
+
ParamsOf<QuerySchema>,
|
|
811
|
+
ParamsSchema,
|
|
812
|
+
QuerySchema,
|
|
813
|
+
DataOfRoute<LayoutRoute>
|
|
814
|
+
>;
|
|
815
|
+
config<LayoutRoute, ParamsSchema extends FurinSchema>(
|
|
816
|
+
options: ConfigFor<ParamsOf<ParamsSchema>> & {
|
|
817
|
+
layout: LayoutRoute;
|
|
818
|
+
mode: RenderingMode;
|
|
819
|
+
params: ParamsSchema;
|
|
820
|
+
query?: undefined;
|
|
821
|
+
}
|
|
822
|
+
): SchemaChain<
|
|
823
|
+
ParamsOf<ParamsSchema>,
|
|
824
|
+
NoFields,
|
|
825
|
+
ParamsSchema,
|
|
826
|
+
undefined,
|
|
827
|
+
DataOfRoute<LayoutRoute>
|
|
828
|
+
>;
|
|
829
|
+
config<LayoutRoute>(
|
|
830
|
+
options: ConfigFor<NoFields> & {
|
|
831
|
+
layout: LayoutRoute;
|
|
832
|
+
mode: RenderingMode;
|
|
833
|
+
params?: undefined;
|
|
834
|
+
query?: undefined;
|
|
835
|
+
}
|
|
836
|
+
): NoSchemaChain<NoFields, NoFields, DataOfRoute<LayoutRoute>>;
|
|
837
|
+
config<
|
|
838
|
+
LayoutRoute,
|
|
839
|
+
ParamsSchema extends FurinSchema | undefined,
|
|
840
|
+
QuerySchema extends FurinSchema | undefined,
|
|
841
|
+
>(
|
|
842
|
+
options: DefineRouteConfig & {
|
|
843
|
+
layout: LayoutRoute;
|
|
844
|
+
mode: RenderingMode;
|
|
845
|
+
params?: ParamsSchema;
|
|
846
|
+
query?: QuerySchema;
|
|
847
|
+
}
|
|
848
|
+
) {
|
|
849
|
+
if (options.params === undefined) {
|
|
850
|
+
if (options.query !== undefined) {
|
|
851
|
+
return new QuerySchemaChain<
|
|
852
|
+
ParamsOf<Exclude<QuerySchema, undefined>>,
|
|
853
|
+
Exclude<QuerySchema, undefined>,
|
|
854
|
+
DataOfRoute<LayoutRoute>
|
|
855
|
+
>(options, options.query as Exclude<QuerySchema, undefined>, undefined);
|
|
856
|
+
}
|
|
857
|
+
return new NoSchemaChain<NoFields, NoFields, DataOfRoute<LayoutRoute>>(options, undefined);
|
|
858
|
+
}
|
|
859
|
+
return new SchemaChain<
|
|
860
|
+
ParamsOf<Exclude<ParamsSchema, undefined>>,
|
|
861
|
+
ParamsOf<Exclude<QuerySchema, undefined>>,
|
|
862
|
+
Exclude<ParamsSchema, undefined>,
|
|
863
|
+
Exclude<QuerySchema, undefined>,
|
|
864
|
+
DataOfRoute<LayoutRoute>
|
|
865
|
+
>(
|
|
866
|
+
options,
|
|
867
|
+
options.params as Exclude<ParamsSchema, undefined>,
|
|
868
|
+
options.query as Exclude<QuerySchema, undefined>,
|
|
869
|
+
undefined
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Stage for `pages/root.tsx` — the document shell has no layout above it, so
|
|
876
|
+
* `config()` requires only `mode` (the TanStack `createRootRoute` analogue).
|
|
877
|
+
*/
|
|
878
|
+
class UnconfiguredRootRoute {
|
|
879
|
+
config<QuerySchema extends FurinSchema>(
|
|
880
|
+
options: ConfigFor<NoFields> & {
|
|
881
|
+
mode: RenderingMode;
|
|
882
|
+
params?: undefined;
|
|
883
|
+
query: QuerySchema;
|
|
884
|
+
}
|
|
885
|
+
): QuerySchemaChain<ParamsOf<QuerySchema>, QuerySchema, NoFields>;
|
|
886
|
+
config<ParamsSchema extends FurinSchema, QuerySchema extends FurinSchema>(
|
|
887
|
+
options: ConfigFor<ParamsOf<ParamsSchema>> & {
|
|
888
|
+
mode: RenderingMode;
|
|
889
|
+
params: ParamsSchema;
|
|
890
|
+
query: QuerySchema;
|
|
891
|
+
}
|
|
892
|
+
): SchemaChain<
|
|
893
|
+
ParamsOf<ParamsSchema>,
|
|
894
|
+
ParamsOf<QuerySchema>,
|
|
895
|
+
ParamsSchema,
|
|
896
|
+
QuerySchema,
|
|
897
|
+
NoFields
|
|
898
|
+
>;
|
|
899
|
+
config<ParamsSchema extends FurinSchema>(
|
|
900
|
+
options: ConfigFor<ParamsOf<ParamsSchema>> & {
|
|
901
|
+
mode: RenderingMode;
|
|
902
|
+
params: ParamsSchema;
|
|
903
|
+
query?: undefined;
|
|
904
|
+
}
|
|
905
|
+
): SchemaChain<ParamsOf<ParamsSchema>, NoFields, ParamsSchema, undefined, NoFields>;
|
|
906
|
+
config(
|
|
907
|
+
options: ConfigFor<NoFields> & {
|
|
908
|
+
mode: RenderingMode;
|
|
909
|
+
params?: undefined;
|
|
910
|
+
query?: undefined;
|
|
911
|
+
}
|
|
912
|
+
): NoSchemaChain<NoFields, NoFields, NoFields>;
|
|
913
|
+
config<ParamsSchema extends FurinSchema | undefined, QuerySchema extends FurinSchema | undefined>(
|
|
914
|
+
options: DefineRouteConfig & {
|
|
915
|
+
mode: RenderingMode;
|
|
916
|
+
params?: ParamsSchema;
|
|
917
|
+
query?: QuerySchema;
|
|
918
|
+
}
|
|
919
|
+
) {
|
|
920
|
+
if (options.params === undefined) {
|
|
921
|
+
if (options.query !== undefined) {
|
|
922
|
+
return new QuerySchemaChain<
|
|
923
|
+
ParamsOf<Exclude<QuerySchema, undefined>>,
|
|
924
|
+
Exclude<QuerySchema, undefined>,
|
|
925
|
+
NoFields
|
|
926
|
+
>(options, options.query as Exclude<QuerySchema, undefined>, undefined);
|
|
927
|
+
}
|
|
928
|
+
return new NoSchemaChain<NoFields, NoFields, NoFields>(options, undefined);
|
|
929
|
+
}
|
|
930
|
+
return new SchemaChain<
|
|
931
|
+
ParamsOf<Exclude<ParamsSchema, undefined>>,
|
|
932
|
+
ParamsOf<Exclude<QuerySchema, undefined>>,
|
|
933
|
+
Exclude<ParamsSchema, undefined>,
|
|
934
|
+
Exclude<QuerySchema, undefined>,
|
|
935
|
+
NoFields
|
|
936
|
+
>(
|
|
937
|
+
options,
|
|
938
|
+
options.params as Exclude<ParamsSchema, undefined>,
|
|
939
|
+
options.query as Exclude<QuerySchema, undefined>,
|
|
940
|
+
undefined
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
export function defineRoute(): UnconfiguredRoute {
|
|
946
|
+
return new UnconfiguredRoute();
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
export function defineRootRoute(): UnconfiguredRootRoute {
|
|
950
|
+
return new UnconfiguredRootRoute();
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
export type RouteParams<Route> = Route extends { elysia: infer App }
|
|
954
|
+
? ElysiaRouteParams<ElysiaRouteLeaf<App>>
|
|
955
|
+
: never;
|
|
956
|
+
|
|
957
|
+
export type RouteLoaderData<Route> = Route extends { useLoaderData: () => infer Data }
|
|
958
|
+
? Data
|
|
959
|
+
: never;
|