Open MrOxMasTer opened 6 days ago
I'm not so versed in Effect yet that I can come up with anything, but I guess you could probably do something like this:
import { Schema as S } from “effect”;
const TodoSchema = S.Struct({
id: S.String,
content: S.String
});
const TodoFormDataSchema = S.formData(Todo);
const decoded = S.decodeUnknownPromise(TodoFormDataSchema)
const encoded = S.encodePromise(TodoFormDataSchema)
const serverAction = async (formData: FormData) => {
const decode = await decoded(formData) // -> { id: “...”, content: “...” };
const encode = await encoded(decode) // -> formData
}
await serverAction();
It's also worth considering other things that can be passed in formData
:
You should add more types related to FormData
, these are:
const SchemaFormData = S.FormData(S.Struct({
text: S.Text(),
numeric: S.Numeric(),
checkbox: S.Checkbox(),
file: S.File(),
repeatable: S.Repeatable(),
repeatableOfType: S.RepeatableOfType()
}))
What is the problem this feature would solve?
FormData validation
What is the feature you are proposing to solve the problem?
Use schemas to validate formData
What alternatives have you considered?
https://www.npmjs.com/package/zod-form-data