@@ -1,4 +1,5 @@
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
|
import type * as FormField from "./FormField.js"
|
||||||
|
|
||||||
|
|
||||||
export interface Form<A, I, R> {
|
export interface Form<A, I, R> {
|
||||||
@@ -7,31 +8,12 @@ export interface Form<A, I, R> {
|
|||||||
|
|
||||||
|
|
||||||
export type FormTree<S extends Schema.Schema<any>> = (
|
export type FormTree<S extends Schema.Schema<any>> = (
|
||||||
S extends Schema.Array$<any> ? ArrayFormField<S> :
|
S extends Schema.Array$<any> ? FormField.ArrayFormField<S> :
|
||||||
S extends Schema.Struct<any> ? StructFormField<S> :
|
S extends Schema.Struct<any> ? FormField.StructFormField<S> :
|
||||||
GenericFormField<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({
|
const MySchema = Schema.Struct({
|
||||||
name: Schema.String,
|
name: Schema.String,
|
||||||
symbol: Schema.SymbolFromSelf,
|
symbol: Schema.SymbolFromSelf,
|
||||||
|
|||||||
25
packages/extension-form/src/internal/FormField.ts
Normal file
25
packages/extension-form/src/internal/FormField.ts
Normal 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]> }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user