foldkit-form 0.1.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/input.ts","../src/index.ts"],"sourcesContent":["/**\n * Controls: what edits one key of a form, described without a renderer.\n *\n * A control names the kind of editing (text, a toggle, a relation picker) and\n * fixes the draft the Model holds while the user edits. Which DOM, component,\n * or design system draws it is the application's.\n */\nimport { Schema } from 'effect'\nimport type { AnyEntity, InputMember } from 'foldkit-entity'\nimport { Metadata } from 'foldkit-metadata'\n\nexport type Control =\n | { readonly _tag: 'Text' }\n /** Carried and submitted, not shown: the id of the thing being edited. Set it with `fill`. */\n | { readonly _tag: 'Hidden' }\n | { readonly _tag: 'Multiline' }\n | { readonly _tag: 'Number' }\n | { readonly _tag: 'Toggle' }\n | { readonly _tag: 'Select'; readonly options: ReadonlyArray<string> }\n /** Chooses one of `target`. The options are the application's to supply. */\n | { readonly _tag: 'RelationOne'; readonly target: AnyEntity }\n | { readonly _tag: 'RelationMany'; readonly target: AnyEntity }\n /**\n * The target itself, edited through a form of its own (`Relation.nested`). The\n * key holds rows of that form: exactly one, at most one, or any number.\n */\n | {\n readonly _tag: 'Nested'\n readonly cardinality: 'one' | 'many'\n /** Whether the rows may be none: always for a `many`, for a `one` when its schema admits nothing. */\n readonly optional: boolean\n readonly form: NestedForm\n }\n\n/** One row of a nested key: a Model of the nested form, under an id that outlives reordering. */\nexport interface FormRow<Model = unknown> {\n readonly id: string\n readonly model: Model\n}\n\n/** What a view needs of a nested form to draw its rows. Every form `Form.make` returns is one. */\nexport interface NestedForm {\n readonly controls: ReadonlyArray<{\n readonly key: string\n readonly control: Control\n readonly label: string\n readonly description: string | undefined\n readonly required: boolean\n }>\n readonly field: (model: never, key: never) => unknown\n readonly rows: (model: never, key: never) => ReadonlyArray<FormRow>\n readonly Message: {\n readonly Changed: (payload: never) => unknown\n readonly Blurred: (payload: never) => unknown\n readonly Nested: (payload: never) => unknown\n readonly RowAdded: (payload: never) => unknown\n readonly RowRemoved: (payload: never) => unknown\n }\n}\n\n/**\n * What a control holds while it is edited, which is not the value it submits: a\n * number being typed is text, and an unchosen relation is the empty string.\n */\nexport type Draft = string | boolean | ReadonlyArray<string>\n\nexport type DraftKind = 'text' | 'flag' | 'list'\n\n/** The draft of a control that edits one value. A `Nested` key holds rows, not a draft. */\nexport const draftKind = (control: Exclude<Control, { readonly _tag: 'Nested' }>): DraftKind =>\n control._tag === 'Toggle' ? 'flag' : control._tag === 'RelationMany' ? 'list' : 'text'\n\nconst key = Metadata.key<Control>('foldkit-form/input', {\n // The last control attached wins: a later annotation refines an earlier one.\n merge: controls => controls.slice(-1),\n summarize: control => control._tag,\n})\n\ninterface AstLike {\n readonly _tag: string\n readonly literal?: unknown\n readonly types?: ReadonlyArray<AstLike>\n}\n\n/** The schema with `null` and `undefined` set aside: optional text is still text. */\nconst present = (ast: AstLike): ReadonlyArray<AstLike> =>\n ast._tag === 'Union'\n ? (ast.types ?? []).filter(member => member._tag !== 'Null' && member._tag !== 'Undefined')\n : [ast]\n\nconst fromSchema = (schema: Schema.Top): Control | undefined => {\n const members = present(schema.ast as unknown as AstLike)\n const [only] = members\n if (members.length === 1 && only !== undefined) {\n if (only._tag === 'String') return { _tag: 'Text' }\n if (only._tag === 'Number') return { _tag: 'Number' }\n if (only._tag === 'Boolean') return { _tag: 'Toggle' }\n }\n const literals = members.map(member => (member._tag === 'Literal' ? member.literal : undefined))\n return literals.length > 0 && literals.every(literal => typeof literal === 'string')\n ? { _tag: 'Select', options: literals as ReadonlyArray<string> }\n : undefined\n}\n\nexport const Input = {\n text: (): Control => ({ _tag: 'Text' }),\n hidden: (): Control => ({ _tag: 'Hidden' }),\n multiline: (): Control => ({ _tag: 'Multiline' }),\n number: (): Control => ({ _tag: 'Number' }),\n toggle: (): Control => ({ _tag: 'Toggle' }),\n select: (options: ReadonlyArray<string>): Control => ({ _tag: 'Select', options }),\n\n /**\n * Entity metadata: the control a member is edited with wherever it appears,\n * e.g. `Entity.annotateMembers({ body: Input.of(Input.multiline()) })`.\n */\n of: (control: Control) => key.of(control),\n\n /**\n * The control for one input key, from the most to the least explicit source:\n * the member's `Input.of` metadata, the relation it writes, then the shape of\n * its schema. `undefined` when none of them says, which a form reports rather\n * than guessing.\n */\n resolve: (member: InputMember, schema: Schema.Top): Control | undefined => {\n if (member._tag === 'Unmapped') return fromSchema(schema)\n // A nested key is not a control to choose: the form builds it from the nested input.\n if (member._tag === 'NestedInput') return undefined\n const owner = member._tag === 'Field' ? member : member.relation\n const [explicit] = key.get(owner.metadata)\n if (explicit !== undefined) return explicit\n if (member._tag === 'Field') return fromSchema(schema)\n const target = member.relation.target()\n return member.relation.cardinality === 'many'\n ? { _tag: 'RelationMany', target }\n : { _tag: 'RelationOne', target }\n },\n}\n","/**\n * `foldkit-form` — a form as a Bundle over Foldkit's own field validation.\n *\n * A form is built from an operation's input (`Entity.input`): the struct says\n * what may be submitted, and the Entity says what each key means. The Model\n * holds one `fieldValidation` Field per key, carrying the draft the control\n * edits. `Submitted` leaves as an out Message with the decoded value; what\n * happens to it (a Remote mutation, a Sync operation, a plain `update`) is the\n * parent's.\n */\nimport { Duration, Effect, Result, Schema } from 'effect'\nimport { Bundle } from 'foldkit-bundle'\nimport type { AnyEntity, EntityInput, InputMember, NestedInput } from 'foldkit-entity'\nimport { Metadata } from 'foldkit-metadata'\nimport type { Command } from 'foldkit/command'\nimport * as FieldValidation from 'foldkit/fieldValidation'\nimport { defineMessageUnion } from 'foldkit/message'\nimport type * as Update from 'foldkit/update'\nimport {\n Input,\n draftKind,\n type Control,\n type Draft,\n type DraftKind,\n type FormRow,\n type NestedForm,\n} from './input.js'\n\nexport { Input, type Control, type Draft, type FormRow, type NestedForm } from './input.js'\n\n/** The draft a key holds, as far as the input's type says: a flag, a list of ids, or text. */\nexport type DraftOf<Value> = [Exclude<Value, null | undefined>] extends [boolean]\n ? boolean\n : [Exclude<Value, null | undefined>] extends [ReadonlyArray<unknown>]\n ? ReadonlyArray<string>\n : string\n\n/** The keys of an input that hold a nested input (`Relation.nested`): rows of a form, not a draft. */\nexport type NestedKey<Members> = {\n [K in keyof Members]: Members[K] extends NestedInput<any, any> ? K : never\n}[keyof Members]\n\n/** The Model of the form a nested key's rows hold. */\nexport type NestedModel<Member> =\n Member extends NestedInput<any, EntityInput<any, infer Fields, infer Members>>\n ? FormModel<Fields, Members>\n : never\n\nexport interface FormModel<Fields extends Schema.Struct.Fields, Members = {}> {\n readonly fields: {\n readonly [K in keyof Fields as K extends NestedKey<Members> ? never : K]: FieldValidation.Field<\n DraftOf<Schema.Schema.Type<Fields[K]>>\n >\n }\n /** The rows of each nested key, each a Model of the nested form. */\n readonly rows: {\n readonly [K in keyof Fields as K extends NestedKey<Members> ? K : never]: ReadonlyArray<\n FormRow<NestedModel<Members[K & keyof Members]>>\n >\n }\n /** Counts the rows ever added, so a row's id is never reused. */\n readonly nextRow: number\n /** Failures of the input as a whole, from the last submit: a rule that spans keys. */\n readonly errors: ReadonlyArray<string>\n /** A submit is waiting for checks still running; it goes out when the last one passes. */\n readonly submitPending: boolean\n}\n\n/**\n * A rule only something outside the form can answer: is this slug taken? It is\n * given the decoded value of the key and whatever else in the form currently\n * decodes, and answers with what is wrong, or nothing. It runs after the schema\n * of the key passes, never instead of it.\n */\nexport type FormCheck<A, Values, R = never> = (\n value: A,\n context: { readonly values: Values },\n) => Effect.Effect<string | undefined, never, R>\n\n/** The form's out Message: every key is valid and the input decoded. */\nexport interface Submitted<Value> {\n readonly _tag: 'Submitted'\n readonly value: Value\n}\n\n/** One key of the form, with everything a view needs to draw it except the pixels. */\nexport interface FormControl<Key extends string = string> {\n readonly key: Key\n readonly control: Control\n /** The schema's `title` annotation, else `Form.label` metadata, else the key. */\n readonly label: string\n readonly description: string | undefined\n /** Whether an empty draft fails. */\n readonly required: boolean\n readonly member: InputMember\n}\n\n/** The key a message is about, for wording that names it. */\nexport interface MessageField<Key extends string = string> {\n readonly key: Key\n readonly label: string\n readonly control: Control\n}\n\n/**\n * The form's words. A rule's own wording belongs on the rule\n * (`Schema.isMinLength(3, { message: '…' })`) and arrives here as `message`;\n * these cover what the form says itself, and let an application translate or\n * rewrite what Schema says by default.\n */\nexport interface FormMessages<Key extends string = string> {\n /** An empty draft the schema does not admit. Default `Required`. */\n readonly required?: (field: MessageField<Key>) => string\n /** A `Number` control whose draft is not a number. Default `Enter a number`. */\n readonly notANumber?: (field: MessageField<Key>) => string\n /** A draft the key's schema rejects. `message` is the check's own, or Schema's. Default: `message`. */\n readonly invalid?: (field: MessageField<Key>, message: string) => string\n /** A failure of the input as a whole: a rule that spans keys. Default: `message`. */\n readonly form?: (message: string) => string\n}\n\n/** What `Form.make` takes beside the input. A nested key's form takes the same, under `nested`. */\nexport interface FormOptions<Fields extends Schema.Struct.Fields, Members, R> {\n /**\n * The control for a key the resolver cannot decide, or should not: an unmapped\n * key with an unusual schema, or text that wants a multiline control here only.\n */\n readonly inputs?: { readonly [K in Exclude<keyof Fields, NestedKey<Members>>]?: Control }\n /** The form's own words, and a rewrite of Schema's: for wording and for translation. */\n readonly messages?: FormMessages<keyof Fields & string>\n /** Rules answered outside the form, by key. The key reads `Validating` while one runs. */\n readonly checks?: {\n readonly [K in Exclude<keyof Fields, NestedKey<Members>>]?: FormCheck<\n Schema.Schema.Type<Fields[K]>,\n Partial<Schema.Struct.Type<Fields>>,\n R\n >\n }\n /** How long a key rests before its check runs, so typing does not ask per keystroke. Default 300ms. */\n readonly debounce?: Duration.Input\n /** The options of each nested key's form. `messages` and `debounce` are inherited when not given. */\n readonly nested?: {\n readonly [K in NestedKey<Members> & keyof Fields]?: Members[K] extends NestedInput<\n any,\n EntityInput<any, infer NestedFields, infer NestedMembers>\n >\n ? FormOptions<NestedFields, NestedMembers, R>\n : never\n }\n}\n\ninterface Label {\n readonly label: string\n readonly description?: string | undefined\n}\n\nconst labelKey = Metadata.key<Label>('foldkit-form/label', {\n merge: labels => labels.slice(-1),\n summarize: label => label.label,\n})\n\ntype Checked = Result.Result<unknown, string>\n\ntype AnyCommand = Command<any, never, any>\n\n/** A form as the form that nests it uses it: untyped, since a nested input is only known at runtime. */\ninterface AnyForm extends NestedForm {\n readonly bundle: {\n readonly Model: Schema.Codec<any, unknown>\n readonly Message: Schema.Codec<any, unknown>\n readonly update: (\n model: any,\n message: any,\n args: void,\n ) => { readonly model: any; readonly commands?: ReadonlyArray<AnyCommand> | undefined }\n }\n readonly initial: unknown\n readonly fill: (model: any, values: any) => { readonly model: any }\n readonly engine: {\n readonly submit: (model: any) => {\n readonly model: any\n readonly commands: ReadonlyArray<AnyCommand>\n }\n readonly isValidating: (model: any) => boolean\n readonly value: (model: any) => unknown\n }\n}\n\n/** Assigned once `Form` exists: a form builds the forms of its nested keys with itself. */\nlet makeNested: (name: string, input: unknown, options: unknown) => AnyForm\n\ninterface NestedPlan extends FormControl {\n readonly form: AnyForm\n readonly cardinality: 'one' | 'many'\n readonly optional: boolean\n /** What no row submits, for a `one` whose schema admits nothing. */\n readonly nothing: null | undefined\n}\n\n/** An edit, however deep: it answers the last submit. An answered check or a blur does not. */\nconst isEdit = (message: { readonly _tag: string; readonly message?: unknown }): boolean =>\n message._tag === 'Nested'\n ? isEdit(message.message as { readonly _tag: string })\n : ['Changed', 'RowAdded', 'RowRemoved', 'Reset'].includes(message._tag)\n\ninterface Plan extends FormControl {\n readonly kind: DraftKind\n readonly empty: Draft\n readonly check: (draft: Draft) => Checked\n readonly rules: FieldValidation.Rules<Draft>\n}\n\nconst kindOf = (draft: unknown): DraftKind | undefined =>\n typeof draft === 'string'\n ? 'text'\n : typeof draft === 'boolean'\n ? 'flag'\n : Array.isArray(draft) && draft.every(item => typeof item === 'string')\n ? 'list'\n : undefined\n\nconst sameDraft = (left: Draft, right: Draft): boolean =>\n Array.isArray(left) && Array.isArray(right)\n ? left.length === right.length && left.every((item, index) => item === right[index])\n : left === right\n\nconst isEmpty = (draft: Draft): boolean =>\n draft === '' || (Array.isArray(draft) && draft.length === 0)\n\n/** A number's draft is blank when it is only spaces: `Number(' ')` is 0, which nobody typed. */\nconst isBlank = (control: Control, draft: Draft): boolean =>\n isEmpty(draft) || (control._tag === 'Number' && typeof draft === 'string' && draft.trim() === '')\n\nconst annotationsOf = (schema: Schema.Top): { title?: unknown; description?: unknown } =>\n Schema.resolveAnnotations(schema) ?? {}\n\n/** The schema's `title`, else `Form.label` metadata on the member, else the key. */\nconst wordsOf = (\n key: string,\n schema: Schema.Top,\n member: InputMember,\n): { readonly label: string; readonly description: string | undefined } => {\n const own =\n member._tag === 'Unmapped' ? undefined : member._tag === 'Field' ? member : member.relation\n const [labelled] = own === undefined ? [] : labelKey.get(own.metadata)\n const annotated = [schema, ...(member._tag === 'Field' ? [member.schema as Schema.Top] : [])].map(\n annotationsOf,\n )\n const title = annotated.map(entry => entry.title).find(value => typeof value === 'string')\n const description = annotated\n .map(entry => entry.description)\n .find(value => typeof value === 'string')\n return {\n label: (title as string | undefined) ?? labelled?.label ?? key,\n description: (description as string | undefined) ?? labelled?.description,\n }\n}\n\nconst nestedPlanOf = (\n name: string,\n key: string,\n schema: Schema.Top,\n member: Extract<InputMember, { readonly _tag: 'NestedInput' }>,\n options: unknown,\n): NestedPlan => {\n const accepts = Schema.is(Schema.toType(schema) as Schema.Codec<unknown>)\n const cardinality = member.relation.cardinality\n const optional = cardinality === 'many' || accepts(undefined) || accepts(null)\n const form = makeNested(`${name}.${key}`, member.input, options)\n return {\n key,\n ...wordsOf(key, schema, member),\n control: { _tag: 'Nested', cardinality, optional, form },\n required: !optional,\n member,\n form,\n cardinality,\n optional,\n nothing: accepts(undefined) ? undefined : null,\n }\n}\n\nconst planOf = (\n name: string,\n key: string,\n schema: Schema.Top,\n member: InputMember,\n override: Control | undefined,\n messages: FormMessages,\n): Plan => {\n const control =\n override ??\n Input.resolve(member, schema) ??\n fail(name, `no control for \"${key}\"; name one under \"inputs\"`)\n if (control._tag === 'Nested')\n return fail(name, `\"${key}\" cannot be given a Nested control; map it with Relation.nested`)\n const kind = draftKind(control)\n const type = Schema.toType(schema) as Schema.Codec<unknown>\n const decode = Schema.decodeUnknownResult(type)\n const accepts = Schema.is(type)\n const empty: Draft = kind === 'flag' ? false : kind === 'list' ? [] : ''\n\n // A control whose draft can never become the key's value is a wiring mistake.\n const samples: ReadonlyArray<unknown> =\n kind === 'flag' ? [true, false] : kind === 'list' ? [[], ['id']] : []\n if (samples.length > 0 && !samples.some(accepts))\n fail(name, `\"${key}\" is edited as ${control._tag}, but its schema accepts no such value`)\n\n const { label, description } = wordsOf(key, schema, member)\n const field: MessageField = { key, label, control }\n const say = {\n required: messages.required?.(field) ?? 'Required',\n notANumber: messages.notANumber?.(field) ?? 'Enter a number',\n invalid: (message: string) => messages.invalid?.(field, message) ?? message,\n }\n\n const check = (draft: Draft): Checked => {\n if (isBlank(control, draft)) {\n // What \"nothing entered\" submits is whatever the schema admits for it.\n for (const nothing of [undefined, null, empty])\n if (accepts(nothing)) return Result.succeed(nothing)\n return Result.fail(say.required)\n }\n const value = control._tag === 'Number' ? Number(draft) : draft\n if (typeof value === 'number' && !Number.isFinite(value)) return Result.fail(say.notANumber)\n return Result.mapError(decode(value), error => say.invalid(error.message))\n }\n\n const required = kind !== 'flag' && Result.isFailure(check(empty))\n return {\n key,\n control,\n kind,\n empty,\n check,\n required,\n member,\n label,\n description,\n rules: FieldValidation.makeRules<Draft>({\n isEmpty: draft => isBlank(control, draft),\n ...(required ? { required: say.required } : {}),\n rules: [\n [\n draft => Result.isSuccess(check(draft)),\n draft => Result.match(check(draft), { onSuccess: () => '', onFailure: error => error }),\n ],\n ],\n }),\n }\n}\n\nconst fail = (name: string, message: string): never => {\n throw new Error(`Form \"${name}\": ${message}`)\n}\n\n/** The draft that shows `value`: a number as its text, nothing as the empty draft. */\nconst draftOf = (plan: Plan, value: unknown): Draft =>\n value === null || value === undefined\n ? plan.empty\n : plan.kind === 'text'\n ? String(value)\n : (value as Draft)\n\nexport const Form = {\n /**\n * A form for one operation's input. A key mapped with `Relation.nested` holds\n * rows of a form of its own, built here from the nested input; every other key\n * holds a draft. `options` names what the input cannot say: a control, the\n * words, the checks.\n */\n make: <\n const Name extends string,\n E extends AnyEntity,\n Fields extends Schema.Struct.Fields,\n Members extends { readonly [K in keyof Fields]: InputMember },\n R = never,\n >(\n name: Name,\n input: EntityInput<E, Fields, Members>,\n options: FormOptions<Fields, Members, R> = {},\n ) => {\n type AnyKey = keyof Fields & string\n type Key = Exclude<AnyKey, NestedKey<Members>>\n type RowsKey = Extract<AnyKey, NestedKey<Members>>\n type Value = Schema.Struct.Type<Fields>\n type Model = FormModel<Fields, Members>\n\n const members: Readonly<Record<string, InputMember>> = input.members\n const everyKey = Object.keys(input.schema.fields) as ReadonlyArray<AnyKey>\n const keys = everyKey.filter(\n key => members[key]!._tag !== 'NestedInput',\n ) as unknown as ReadonlyArray<Key>\n const rowsKeys = everyKey.filter(\n key => members[key]!._tag === 'NestedInput',\n ) as unknown as ReadonlyArray<RowsKey>\n\n const overrides: Readonly<Record<string, Control | undefined>> = options.inputs ?? {}\n const plans = Object.fromEntries(\n keys.map(key => [\n key,\n planOf(\n name,\n key,\n input.schema.fields[key] as Schema.Top,\n members[key]!,\n overrides[key],\n (options.messages ?? {}) as FormMessages,\n ),\n ]),\n ) as Readonly<Record<Key, Plan>>\n\n const nestedOptions: Readonly<Record<string, object | undefined>> = options.nested ?? {}\n const nestedPlans = Object.fromEntries(\n rowsKeys.map(key => [\n key,\n nestedPlanOf(\n name,\n key,\n input.schema.fields[key] as Schema.Top,\n members[key] as Extract<InputMember, { readonly _tag: 'NestedInput' }>,\n // The form's words and pace are its nested forms' too, unless they bring their own.\n { messages: options.messages, debounce: options.debounce, ...nestedOptions[key] },\n ),\n ]),\n ) as Readonly<Record<RowsKey, NestedPlan>>\n\n const draftSchema: Record<DraftKind, Schema.Codec<Draft, any>> = {\n text: Schema.String,\n flag: Schema.Boolean,\n list: Schema.Array(Schema.String),\n }\n const Model = Schema.Struct({\n fields: Schema.Struct(\n Object.fromEntries(\n keys.map(key => [key, FieldValidation.Field(draftSchema[plans[key].kind])]),\n ),\n ),\n rows: Schema.Struct(\n Object.fromEntries(\n rowsKeys.map(key => [\n key,\n Schema.Array(\n Schema.Struct({ id: Schema.String, model: nestedPlans[key].form.bundle.Model }),\n ),\n ]),\n ),\n ),\n nextRow: Schema.Number,\n errors: Schema.Array(Schema.String),\n submitPending: Schema.Boolean,\n }) as unknown as Schema.Codec<Model, unknown>\n\n // A form of nested keys only has no key to change, and `Literals` needs one.\n const KeySchema = (\n keys.length === 0\n ? Schema.Never\n : Schema.Literals(keys as unknown as readonly [Key, ...Key[]])\n ) as Schema.Literals<readonly [Key, ...Key[]]>\n const DraftSchema = Schema.Union([Schema.String, Schema.Boolean, Schema.Array(Schema.String)])\n const Message = defineMessageUnion({\n Changed: { key: KeySchema, value: DraftSchema },\n /** Validates the key as it stands, so a required key left empty says so. */\n Blurred: { key: KeySchema },\n Submitted: {},\n Reset: {},\n /** The answer of a check for the draft it was asked about; one for an older draft is dropped. */\n Checked: { key: KeySchema, draft: DraftSchema, error: Schema.NullOr(Schema.String) },\n /** A Message of the nested form in one row of a nested key. One that row does not take is dropped. */\n Nested: { key: Schema.String, row: Schema.String, message: Schema.Unknown },\n /** A new, empty row. A `one` that already has its row takes no other. */\n RowAdded: { key: Schema.String },\n /** Removes a row. A `one` that must be there stays. */\n RowRemoved: { key: Schema.String, row: Schema.String },\n })\n type Message = typeof Message.Type\n type Commands = ReadonlyArray<Command<Message, never, R>>\n\n const fieldsFrom = (draft: (plan: Plan) => FieldValidation.Field<Draft>): Model['fields'] =>\n Object.fromEntries(keys.map(key => [key, draft(plans[key])])) as Model['fields']\n\n type Rows = ReadonlyArray<FormRow<any>>\n const rowsOf = (model: Model): Readonly<Record<string, Rows>> => model.rows as never\n const withRows = (model: Model, key: string, rows: Rows): Model => ({\n ...model,\n rows: { ...model.rows, [key]: rows },\n })\n\n /** Rows numbered from the Model's count, so an id is never reused. */\n const numbered = (model: Model, key: string, models: ReadonlyArray<unknown>): Model => ({\n ...withRows(\n model,\n key,\n models.map((row, index) => ({ id: `r${model.nextRow + index}`, model: row })),\n ),\n nextRow: model.nextRow + models.length,\n })\n\n // A `one` that must be there starts with its row; every other nested key starts with none.\n const initial: Model = rowsKeys.reduce<Model>(\n (model, key) =>\n numbered(model, key, nestedPlans[key].optional ? [] : [nestedPlans[key].form.initial]),\n {\n fields: fieldsFrom(plan => FieldValidation.NotValidated({ value: plan.empty })),\n rows: {} as Model['rows'],\n nextRow: 0,\n errors: [],\n submitPending: false,\n },\n )\n const drafts = (model: Model): Readonly<Record<Key, FieldValidation.Field<Draft>>> =>\n model.fields as never\n const withField = (model: Model, key: Key, field: FieldValidation.Field<Draft>): Model => ({\n ...model,\n fields: { ...model.fields, [key]: field },\n })\n\n const checks: Readonly<Partial<Record<Key, FormCheck<unknown, Partial<Value>, R>>>> =\n (options.checks ?? {}) as never\n const debounce = options.debounce ?? '300 millis'\n\n /** What currently decodes, by key: the context of a check, and the makings of the value. */\n const decoded = (model: Model): Partial<Value> =>\n Object.fromEntries(\n keys.flatMap(key => {\n const value = Result.getOrUndefined(plans[key].check(drafts(model)[key].value))\n return value === undefined ? [] : [[key, value] as const]\n }),\n ) as Partial<Value>\n\n /** The value of each nested key, or `undefined` while some row has none. */\n const nestedValues = (model: Model): Readonly<Record<string, unknown>> | undefined => {\n const entries: Array<readonly [string, unknown]> = []\n for (const key of rowsKeys) {\n const plan = nestedPlans[key]\n const values = rowsOf(model)[key]!.map(row => plan.form.engine.value(row.model))\n if (values.includes(undefined)) return undefined\n entries.push([\n key,\n plan.cardinality === 'many' ? values : values.length === 0 ? plan.nothing : values[0],\n ])\n }\n return Object.fromEntries(entries)\n }\n\n /** A nested form's Commands as this form's: their Messages arrive wrapped for the row. */\n const lift = (key: string, row: string, commands: ReadonlyArray<AnyCommand>): Commands =>\n commands.map(\n command =>\n ({\n name: command.name,\n args: { ...(command.args as object), at: key, row },\n effect: Effect.map(command.effect, message => Message.Nested({ key, row, message })),\n }) as Command<Message, never, R>,\n )\n\n /**\n * Validates the draft of one key. A key with a check that passes its schema is\n * not `Valid` yet: it is `Validating`, with the Command that asks.\n */\n const validateKey = (\n model: Model,\n key: Key,\n draft: Draft,\n ): { readonly model: Model; readonly commands: Commands } => {\n const state = FieldValidation.validate(plans[key].rules)(draft)\n const check = checks[key]\n if (check === undefined || state._tag !== 'Valid') {\n return { model: withField(model, key, state), commands: [] }\n }\n const asking = withField(model, key, FieldValidation.Validating({ value: draft }))\n const value = Result.getOrUndefined(plans[key].check(draft))\n return {\n model: asking,\n commands: [\n {\n name: `${name}.check`,\n args: { key },\n effect: Effect.sleep(debounce).pipe(\n Effect.andThen(check(value, { values: decoded(asking) })),\n Effect.map(error => Message.Checked({ key, draft, error: error ?? null })),\n ),\n } as Command<Message, never, R>,\n ],\n }\n }\n\n const decodeInput = Schema.decodeUnknownResult(\n Schema.toType(input.schema) as Schema.Codec<Value>,\n )\n\n const acceptable = (model: Model): boolean =>\n keys.every(key => FieldValidation.isValid(plans[key].rules)(drafts(model)[key]))\n /** A check is running, in this form or in a row of it. */\n const isValidating = (model: Model): boolean =>\n keys.some(key => drafts(model)[key]._tag === 'Validating') ||\n rowsKeys.some(key =>\n rowsOf(model)[key]!.some(row => nestedPlans[key].form.engine.isValidating(row.model)),\n )\n\n /** The decoded input, once every key and every row is acceptable; else what is wrong with the whole. */\n const finish = (model: Model): { readonly model: Model; readonly value?: Value } => {\n const settled: Model = { ...model, submitPending: false }\n const nested = acceptable(model) ? nestedValues(model) : undefined\n if (nested === undefined) return { model: settled }\n return Result.match(decodeInput({ ...decoded(model), ...nested }), {\n onSuccess: value => ({ model: { ...settled, errors: [] }, value }),\n onFailure: error => ({\n model: {\n ...settled,\n errors: [options.messages?.form?.(error.message) ?? error.message],\n },\n }),\n })\n }\n\n /**\n * A submit: every key not yet validated is, in every row too, so every failure\n * shows. With none, the value goes out; with checks still running, the submit\n * waits for them.\n */\n const submit = (\n model: Model,\n ): { readonly model: Model; readonly commands: Commands; readonly value?: Value } => {\n let next: Model = { ...model, errors: [], submitPending: false }\n const commands: Array<Command<Message, never, R>> = []\n for (const key of keys) {\n const state = drafts(next)[key]\n // Any other state already answers for this draft: an edit always revalidates.\n if (state._tag !== 'NotValidated') continue\n const validated = validateKey(next, key, state.value)\n next = validated.model\n commands.push(...validated.commands)\n }\n for (const key of rowsKeys) {\n const rows = rowsOf(next)[key]!.map(row => {\n const submitted = nestedPlans[key].form.engine.submit(row.model)\n commands.push(...lift(key, row.id, submitted.commands))\n return { id: row.id, model: submitted.model }\n })\n next = withRows(next, key, rows)\n }\n if (isValidating(next)) return { model: { ...next, submitPending: true }, commands }\n return { ...finish(next), commands }\n }\n\n interface Out {\n readonly model: Model\n readonly commands: Commands\n readonly outMessage?: Submitted<Value>\n }\n const out = (model: Model, commands: Commands, value: Value | undefined): Out =>\n value === undefined\n ? { model, commands }\n : { model, commands, outMessage: { _tag: 'Submitted', value } }\n\n const submitted = (model: Model): Out => {\n const { model: next, commands, value } = submit(model)\n return out(next, commands, value)\n }\n\n /** After an answer: a submit that was waiting goes out once nothing is asked any more. */\n const resume = (model: Model, commands: Commands = []): Out => {\n if (!model.submitPending || isValidating(model)) return { model, commands }\n const { model: next, value } = finish(model)\n return out(next, commands, value)\n }\n\n /** An edit answers the last submit: its failures describe a form that has changed. */\n const edited = (model: Model): Model => ({ ...model, errors: [], submitPending: false })\n\n /** Shows existing values, as an edit form does; keys not given keep their draft and their rows. */\n const fill = (model: Model, values: Partial<Value>): { readonly model: Model } => {\n const given = values as Readonly<Record<string, unknown>>\n const filled: Model = {\n ...model,\n errors: [],\n submitPending: false,\n fields: fieldsFrom(plan =>\n plan.key in given\n ? FieldValidation.NotValidated({ value: draftOf(plan, given[plan.key]) })\n : drafts(model)[plan.key as Key],\n ),\n }\n return {\n model: rowsKeys.reduce<Model>((next, key) => {\n if (!(key in given)) return next\n const { form, optional } = nestedPlans[key]\n const held = given[key]\n const shown = Array.isArray(held)\n ? held\n : held === null || held === undefined\n ? []\n : [held]\n const models = shown.map(value => form.fill(form.initial, value).model)\n // A `one` that must be there keeps an empty row when it is given nothing.\n return numbered(next, key, models.length === 0 && !optional ? [form.initial] : models)\n }, filled),\n }\n }\n\n const bundle = Bundle.make(name, {\n Model,\n Message,\n init: () => ({ model: initial }),\n update: (\n model: Model,\n message: Message,\n ): Update.ReturnWithOutMessage<Model, Message, Submitted<Value>, R> => {\n switch (message._tag) {\n case 'Changed':\n // A draft of another kind than the control of the key holds is not an edit.\n return kindOf(message.value) !== plans[message.key].kind\n ? { model }\n : validateKey(edited(model), message.key, message.value)\n case 'Blurred': {\n const state = drafts(model)[message.key]\n // Only a key not validated yet: any other state already answers for this draft.\n return state._tag === 'NotValidated'\n ? validateKey(model, message.key, state.value)\n : { model }\n }\n case 'Checked': {\n const state = drafts(model)[message.key]\n // An answer for a draft the key no longer holds is dropped.\n if (state._tag !== 'Validating' || !sameDraft(state.value, message.draft)) {\n return { model }\n }\n return resume(\n withField(\n model,\n message.key,\n message.error === null\n ? FieldValidation.Valid({ value: state.value })\n : FieldValidation.Invalid({ value: state.value, errors: [message.error] }),\n ),\n )\n }\n case 'Nested': {\n const plan: NestedPlan | undefined = nestedPlans[message.key as RowsKey]\n const row = rowsOf(model)[message.key]?.find(held => held.id === message.row)\n if (plan === undefined || row === undefined) return { model }\n if (!Schema.is(plan.form.bundle.Message)(message.message)) return { model }\n const inner = message.message as { readonly _tag: string }\n // Enter in a row submits the form the row is in.\n if (inner._tag === 'Submitted') return submitted(model)\n const answered = plan.form.bundle.update(row.model, inner, undefined)\n const next = withRows(\n model,\n message.key,\n rowsOf(model)[message.key]!.map(held =>\n held.id === row.id ? { id: row.id, model: answered.model } : held,\n ),\n )\n return resume(\n isEdit(inner) ? edited(next) : next,\n lift(message.key, row.id, answered.commands ?? []),\n )\n }\n case 'RowAdded': {\n const plan: NestedPlan | undefined = nestedPlans[message.key as RowsKey]\n const rows = rowsOf(model)[message.key]\n if (plan === undefined || rows === undefined) return { model }\n if (plan.cardinality === 'one' && rows.length > 0) return { model }\n const added = numbered(edited(model), message.key, [plan.form.initial])\n return {\n model: withRows(added, message.key, [...rows, ...rowsOf(added)[message.key]!]),\n }\n }\n case 'RowRemoved': {\n const plan: NestedPlan | undefined = nestedPlans[message.key as RowsKey]\n const rows = rowsOf(model)[message.key]\n if (plan === undefined || rows === undefined) return { model }\n if (plan.cardinality === 'one' && !plan.optional) return { model }\n return {\n model: withRows(\n edited(model),\n message.key,\n rows.filter(held => held.id !== message.row),\n ),\n }\n }\n case 'Reset':\n return { model: initial }\n case 'Submitted':\n return submitted(model)\n }\n },\n helpers: { fill },\n })\n\n return {\n bundle,\n Message,\n /** The reading the form was made from, for `Entity.selectFor` and `Entity.valuesFor`. */\n input,\n /** The `fill` helper as a plain function of the form's Model, for a package that wraps the form. */\n fill,\n /** The Model the form starts from and resets to: every key empty and not validated. */\n initial,\n /** The keys in the input's order, each with its control, label, and member. */\n controls: everyKey.map((key): FormControl<AnyKey> => {\n const { control, label, description, required, member } =\n (plans as Readonly<Record<string, FormControl>>)[key] ??\n (nestedPlans as Readonly<Record<string, FormControl>>)[key]!\n return { key, control, label, description, required, member }\n }),\n /**\n * One key's state with its draft as any `Draft`, for a view that walks\n * `controls`. `model.fields.title` is the same value, typed to that key. A\n * nested key has rows and no draft.\n */\n field: (model: Model, key: Key): FieldValidation.Field<Draft> =>\n drafts(model)[key] ?? fail(name, `\"${key}\" holds rows, not a draft; read it with rows`),\n /** The rows of a nested key, each a Model of `control.form`. */\n rows: (model: Model, key: RowsKey): Model['rows'][RowsKey] =>\n (rowsOf(model)[key] ?? fail(name, `\"${key}\" holds a draft, not rows`)) as never,\n /**\n * Whether a submit now could go through: nothing is invalid. A check still\n * running does not stop it; the submit waits for the answer.\n */\n canSubmit: (model: Model): boolean => {\n const next = submit(model)\n return next.value !== undefined || next.model.submitPending\n },\n /** The form as the form that nests it drives it. */\n engine: {\n submit: (model: Model) => {\n const { model: next, commands } = submit(model)\n return { model: next, commands }\n },\n isValidating,\n /** The decoded input when every key and row is valid as it stands; validates nothing. */\n value: (model: Model): Value | undefined => finish(model).value,\n },\n }\n },\n\n /**\n * Entity metadata: the label of a member that has no schema to annotate (a\n * relation, a derived member). A field is labelled on its schema, with\n * `Schema.String.annotate({ title })`.\n */\n label: (label: string, description?: string) =>\n labelKey.of(description === undefined ? { label } : { label, description }),\n\n /**\n * What `Form.label` attached to an Entity member, for a package that labels\n * the same member elsewhere, such as a table column.\n */\n labelOf: (member: { readonly metadata: Metadata }): string | undefined =>\n labelKey.get(member.metadata)[0]?.label,\n}\n\nmakeNested = Form.make as never\n"],"mappings":";;;;;;;AAqEA,MAAa,aAAa,YACxB,QAAQ,SAAS,WAAW,SAAS,QAAQ,SAAS,iBAAiB,SAAS;AAElF,MAAM,MAAM,SAAS,IAAa,sBAAsB;CAEtD,QAAO,aAAY,SAAS,MAAM,EAAE;CACpC,YAAW,YAAW,QAAQ;AAChC,CAAC;;AASD,MAAM,WAAW,QACf,IAAI,SAAS,WACR,IAAI,SAAS,CAAC,EAAA,CAAG,QAAO,WAAU,OAAO,SAAS,UAAU,OAAO,SAAS,WAAW,IACxF,CAAC,GAAG;AAEV,MAAM,cAAc,WAA4C;CAC9D,MAAM,UAAU,QAAQ,OAAO,GAAyB;CACxD,MAAM,CAAC,QAAQ;CACf,IAAI,QAAQ,WAAW,KAAK,SAAS,KAAA,GAAW;EAC9C,IAAI,KAAK,SAAS,UAAU,OAAO,EAAE,MAAM,OAAO;EAClD,IAAI,KAAK,SAAS,UAAU,OAAO,EAAE,MAAM,SAAS;EACpD,IAAI,KAAK,SAAS,WAAW,OAAO,EAAE,MAAM,SAAS;CACvD;CACA,MAAM,WAAW,QAAQ,KAAI,WAAW,OAAO,SAAS,YAAY,OAAO,UAAU,KAAA,CAAU;CAC/F,OAAO,SAAS,SAAS,KAAK,SAAS,OAAM,YAAW,OAAO,YAAY,QAAQ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AAC,CAAC,QAAQ,KAAK,MAAM,IAAI,IAAI,0BAA0B;;;;;GAKtE,YAAY,UAA0B;IACpC,MAAM,OAAO,OAAO,KAAK;IACzB,OAAO,KAAK,UAAU,KAAA,KAAa,KAAK,MAAM;GAChD;;GAEA,QAAQ;IACN,SAAS,UAAiB;KACxB,MAAM,EAAE,OAAO,MAAM,aAAa,OAAO,KAAK;KAC9C,OAAO;MAAE,OAAO;MAAM;KAAS;IACjC;IACA;;IAEA,QAAQ,UAAoC,OAAO,KAAK,CAAC,CAAC;GAC5D;EACF;CACF;;;;;;CAOA,QAAQ,OAAe,gBACrB,SAAS,GAAG,gBAAgB,KAAA,IAAY,EAAE,MAAM,IAAI;EAAE;EAAO;CAAY,CAAC;;;;;CAM5E,UAAU,WACR,SAAS,IAAI,OAAO,QAAQ,CAAC,CAAC,EAAE,EAAE;AACtC;AAEA,aAAa,KAAK"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "foldkit-form",
3
+ "version": "0.1.0",
4
+ "description": "Forms for Foldkit: a Bundle over core field validation, built from an operation's input and the Entity it writes.",
5
+ "keywords": [
6
+ "foldkit",
7
+ "effect",
8
+ "form",
9
+ "validation",
10
+ "schema",
11
+ "typescript"
12
+ ],
13
+ "type": "module",
14
+ "license": "MIT",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "author": "Patrick Glenn <doeixd@gmail.com>",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/doeixd/foldkit-plus.git",
22
+ "directory": "packages/form"
23
+ },
24
+ "homepage": "https://github.com/doeixd/foldkit-plus/tree/main/packages/form#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/doeixd/foldkit-plus/issues"
27
+ },
28
+ "sideEffects": false,
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.mts",
32
+ "import": "./dist/index.mjs"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "dependencies": {
41
+ "foldkit-bundle": "0.2.0",
42
+ "foldkit-entity": "0.1.0",
43
+ "foldkit-metadata": "0.1.0"
44
+ },
45
+ "peerDependencies": {
46
+ "effect": "^4.0.0-rc.112",
47
+ "foldkit": "^0.158.2"
48
+ },
49
+ "devDependencies": {
50
+ "effect": "4.0.0-rc.112",
51
+ "foldkit": "0.158.2",
52
+ "tsdown": "^0.23.0",
53
+ "typescript": "5.9.3"
54
+ },
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "typecheck": "tsc -b"
58
+ }
59
+ }