Form work
Some checks failed
Lint / lint (push) Failing after 15s

This commit is contained in:
Julien Valverdé
2025-04-15 23:55:50 +02:00
parent 9436602443
commit ab0dce107d
2 changed files with 29 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
import { Schema } from "effect"
import type * as FormField from "./FormField.js"
export interface Form<A, I, R> {
@@ -7,31 +8,12 @@ export interface Form<A, I, R> {
export type FormTree<S extends Schema.Schema<any>> = (
S extends Schema.Array$<any> ? ArrayFormField<S> :
S extends Schema.Struct<any> ? StructFormField<S> :
GenericFormField<S>
S extends Schema.Array$<any> ? FormField.ArrayFormField<S> :
S extends Schema.Struct<any> ? FormField.StructFormField<S> :
FormField.GenericFormField<S>
)
export interface GenericFormField<S extends Schema.Schema<any>> {
readonly _tag: "GenericFormField"
readonly schema: S
readonly value: S["Type"]
}
export interface ArrayFormField<S extends Schema.Array$<any>> {
readonly _tag: "ArrayFormField"
readonly schema: S
readonly elements: readonly FormTree<S["value"]>[]
}
export interface StructFormField<S extends Schema.Struct<any>> {
readonly _tag: "StructFormField"
readonly schema: S
readonly fields: { [K in keyof S["fields"]]: FormTree<S["fields"][K]> }
}
const MySchema = Schema.Struct({
name: Schema.String,
symbol: Schema.SymbolFromSelf,

View File

@@ -0,0 +1,25 @@
import type { Schema } from "effect"
import type * as Form from "./Form.ts"
export interface FormField<S extends Schema.Schema.Any> {
}
export interface GenericFormField<S extends Schema.Schema.Any> extends FormField<S> {
readonly _tag: "GenericFormField"
readonly schema: S
readonly value: S["Type"]
}
export interface ArrayFormField<S extends Schema.Array$<Schema.Schema.Any>> extends FormField<S> {
readonly _tag: "ArrayFormField"
readonly schema: S
readonly elements: readonly Form.FormTree<S["value"]>[]
}
export interface StructFormField<S extends Schema.Struct<Schema.Struct.Fields>> extends FormField<S> {
readonly _tag: "StructFormField"
readonly schema: S
readonly fields: { [K in keyof S["fields"]]: Form.FormTree<S["fields"][K]> }
}