@axium/server 0.5.0 → 0.5.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/package.json +1 -1
- package/web/utils.ts +3 -2
package/package.json
CHANGED
package/web/utils.ts
CHANGED
|
@@ -13,9 +13,9 @@ export async function loadSession(event: RequestEvent): Promise<{ session: Sessi
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
16
|
-
export interface FormFail<S extends z.AnyZodObject> extends ActionFailure<z.infer<S> & { error: string }> {}
|
|
16
|
+
export interface FormFail<S extends z.AnyZodObject, E extends object = object> extends ActionFailure<z.infer<S> & { error: string } & E> {}
|
|
17
17
|
|
|
18
|
-
export async function parseForm<S extends z.AnyZodObject>(event: RequestEvent, schema: S): Promise<[z.infer<S>, FormFail<S> | null]> {
|
|
18
|
+
export async function parseForm<S extends z.AnyZodObject, E extends object = object>(event: RequestEvent, schema: S, errorData?: E): Promise<[z.infer<S>, FormFail<S, E> | null]> {
|
|
19
19
|
const formData = Object.fromEntries(await event.request.formData());
|
|
20
20
|
const { data, error, success } = schema.safeParse(formData);
|
|
21
21
|
|
|
@@ -25,6 +25,7 @@ export async function parseForm<S extends z.AnyZodObject>(event: RequestEvent, s
|
|
|
25
25
|
data,
|
|
26
26
|
fail(400, {
|
|
27
27
|
...data,
|
|
28
|
+
...errorData,
|
|
28
29
|
error: fromError(error, { prefix: null }).toString(),
|
|
29
30
|
}),
|
|
30
31
|
];
|