foldkit-form 0.1.0 → 0.1.2

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.
@@ -1 +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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AAK,CAAC,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"}
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 * There is one primitive. A control is a `kind` (a name), the draft the Model\n * holds while the user edits, and whatever data its kind needs. `Input.text()`\n * and `Input.toggle()` are values of it, made by `Input.kind`, which is what an\n * application calls for a date picker or a rich text editor. The kinds here are\n * a collection, not a special case. Which DOM, component, or design system\n * draws a kind is the application's.\n */\nimport { Schema } from 'effect'\nimport type { AnyEntity, InputMember } from 'foldkit-entity'\nimport { Metadata } from 'foldkit-metadata'\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\n/** The draft a control holds. `rows` is a nested key: rows of a form, not a draft. */\nexport type DraftKind = 'text' | 'flag' | 'list' | 'rows'\n\n/** What edits one key: the primitive every kind of control is a value of. */\nexport interface Control<Data = unknown> {\n /** The name a renderer is found by. */\n readonly kind: string\n readonly draft: DraftKind\n /** Whether a view draws it. A control carried and submitted, not shown, is `false`. */\n readonly shown: boolean\n /**\n * Whether the form also holds what the user typed to find a choice, which the\n * application reads as the input of the query that lists the choices.\n */\n readonly searches: boolean\n /** What this kind needs: a select's options, a relation's target. */\n readonly data: Data\n /**\n * For a `text` draft: the value the key's schema is given, when that is not the\n * text itself. `undefined` means the text does not read as one.\n */\n readonly parse?: ((draft: string) => unknown) | undefined\n /** What to say when `parse` gives `undefined`. */\n readonly unparsed?: string | undefined\n /**\n * For a `text` draft: another key of the form this one is written from until\n * the author writes it themselves. A slug follows a title.\n */\n readonly follows?: Follows | undefined\n}\n\n/** Which key a draft follows, and what it makes of that key's text. */\nexport interface Follows {\n readonly key: string\n readonly through: (text: string) => string\n}\n\n/** A kind of control: how its values are made, and how one is told from another. */\nexport interface ControlKind<Data> {\n readonly kind: string\n readonly of: (data: Data) => Control<Data>\n readonly is: (control: Control) => control is Control<Data>\n}\n\n/**\n * Under `inputs`, in place of a control: a change to the control the form would\n * have resolved, such as giving the key's relation picker a search.\n */\nexport interface ControlChange {\n readonly change: (resolved: Control | undefined, key: string) => Control\n}\n\nexport const isControlChange = (value: Control | ControlChange): value is ControlChange =>\n 'change' in value\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 search: (model: never, key: never) => string\n readonly isFollowing: (model: never, key: never) => boolean\n readonly Message: {\n readonly Changed: (payload: never) => unknown\n readonly Blurred: (payload: never) => unknown\n readonly Searched: (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/** A kind of control. The kinds below are made with it, and so is an application's. */\nconst kind = <Data = Record<string, never>>(\n name: string,\n spec: {\n readonly draft: DraftKind\n readonly shown?: boolean\n readonly searches?: boolean | ((data: Data) => boolean)\n readonly parse?: (draft: string) => unknown\n readonly unparsed?: string\n },\n): ControlKind<Data> => ({\n kind: name,\n of: data =>\n Object.freeze({\n kind: name,\n draft: spec.draft,\n shown: spec.shown ?? true,\n searches:\n typeof spec.searches === 'function' ? spec.searches(data) : (spec.searches ?? false),\n data,\n parse: spec.parse,\n unparsed: spec.unparsed,\n }),\n is: (control): control is Control<Data> => control.kind === name,\n})\n\n/** A relation picker: what it chooses from, and whether it searches. */\nexport interface RelationData {\n readonly target: AnyEntity\n readonly search: boolean\n}\n\n/** A nested key: how many rows it may hold, and the form each row is a Model of. */\nexport interface NestedData {\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\nconst nothing: Record<string, never> = Object.freeze({})\n\nconst Text = kind('Text', { draft: 'text' })\nconst Hidden = kind('Hidden', { draft: 'text', shown: false })\nconst Multiline = kind('Multiline', { draft: 'text' })\nconst Number_ = kind('Number', {\n draft: 'text',\n // `Number(' ')` is 0, which nobody typed: a number's draft of spaces is nothing.\n parse: draft => {\n const value = globalThis.Number(draft)\n return draft.trim() === '' || !globalThis.Number.isFinite(value) ? undefined : value\n },\n unparsed: 'Enter a number',\n})\nconst Toggle = kind('Toggle', { draft: 'flag' })\nconst Select = kind<{ readonly options: ReadonlyArray<string> }>('Select', { draft: 'text' })\nconst RelationOne = kind<RelationData>('RelationOne', {\n draft: 'text',\n searches: data => data.search,\n})\nconst RelationMany = kind<RelationData>('RelationMany', {\n draft: 'list',\n searches: data => data.search,\n})\nconst Nested = kind<NestedData>('Nested', { draft: 'rows' })\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.kind,\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 Text.of(nothing)\n if (only._tag === 'Number') return Number_.of(nothing)\n if (only._tag === 'Boolean') return Toggle.of(nothing)\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 ? Select.of({ options: literals as ReadonlyArray<string> })\n : undefined\n}\n\nexport const Input = {\n /**\n * A kind of control. `Input.kind<{ min: string }>('Date', { draft: 'text' })`\n * gives `.of(data)` to make one and `.is(control)` to tell one, exactly as the\n * kinds below were made. A view draws it once it is given a renderer for `Date`.\n */\n kind,\n\n // The kinds this package resolves to. A view finds its renderer by `kind`.\n Text,\n Hidden,\n Multiline,\n Number: Number_,\n Toggle,\n Select,\n RelationOne,\n RelationMany,\n Nested,\n\n text: (): Control => Text.of(nothing),\n /** Carried and submitted, not shown: the id of the thing being edited. Set it with `fill`. */\n hidden: (): Control => Hidden.of(nothing),\n multiline: (): Control => Multiline.of(nothing),\n number: (): Control => Number_.of(nothing),\n toggle: (): Control => Toggle.of(nothing),\n select: (options: ReadonlyArray<string>): Control => Select.of({ options }),\n\n /**\n * For a relation key, under `inputs`: its picker, with a search. Too many to\n * list is the usual case for a relation; the form holds the search text, and\n * the query that lists the options takes it as input.\n */\n search: (): ControlChange => ({\n change: (resolved, inputKey) => {\n if (resolved !== undefined && RelationOne.is(resolved))\n return RelationOne.of({ ...resolved.data, search: true })\n if (resolved !== undefined && RelationMany.is(resolved))\n return RelationMany.of({ ...resolved.data, search: true })\n throw new Error(`\"${inputKey}\" is not a relation, so it has no picker to search`)\n },\n }),\n\n /**\n * Under `inputs`: the key's own control, following another key. Until the\n * author writes this key, its draft is `through` of that key's text, rewritten\n * as that key is edited; once they write it, it is theirs. Emptying it hands\n * it back. A form filled with a value for it does not follow: an address that\n * is already published must not move because its title did.\n */\n following: (key: string, through: (text: string) => string = text => text): ControlChange => ({\n change: (resolved, inputKey) => {\n if (resolved === undefined || resolved.draft !== 'text')\n throw new Error(`\"${inputKey}\" holds no text, so it cannot follow \"${key}\"`)\n return Object.freeze({ ...resolved, follows: { key, through } })\n },\n }),\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 data = { target: member.relation.target(), search: false }\n return member.relation.cardinality === 'many' ? RelationMany.of(data) : RelationOne.of(data)\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, Pipeable, 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 isControlChange,\n type Control,\n type ControlChange,\n type Draft,\n type DraftKind,\n type FormRow,\n type NestedForm,\n} from './input.js'\n\nexport {\n Input,\n type Control,\n type ControlChange,\n type ControlKind,\n type Draft,\n type DraftKind,\n type Follows,\n type FormRow,\n type NestedData,\n type NestedForm,\n type RelationData,\n} 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 /** What was typed to find a choice, by key, for the relation pickers that search. */\n readonly searches: Readonly<Record<string, string>>\n /**\n * The keys that follow another and that the author has written themselves, so\n * they follow no longer. A key that follows nothing is never here.\n */\n readonly touched: Readonly<Record<string, boolean>>\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 * What the form is editing, which its values do not say: a post's own row id,\n * so a check that asks whether an address is taken can tell the post's own\n * address from someone else's. Empty until `Message.About` says otherwise,\n * which is what a form that creates something means.\n */\n readonly subject: Readonly<Record<string, string>>\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: {\n readonly values: Values\n /** What the form is editing: `{}` while it creates. See `FormModel.subject`. */\n readonly subject: Readonly<Record<string, string>>\n },\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. `{label}`, `{key}`. Default `Required`. */\n readonly required?: string | ((field: MessageField<Key>) => string)\n /** Text its control cannot read: a `Number` that is not one. `{label}`, `{key}`. Default: the kind's own words (`Enter a number`). */\n readonly unparsed?: string | ((field: MessageField<Key>) => string)\n /** A draft the key's schema rejects. `{message}` is the check's own, or Schema's; `{label}`, `{key}`. Default: `{message}`. */\n readonly invalid?: string | ((field: MessageField<Key>, message: string) => string)\n /** A failure of the input as a whole: a rule that spans keys. `{message}`. Default: `{message}`. */\n readonly form?: string | ((message: string) => string)\n}\n\n/**\n * Words with their blanks filled: `fillWords('{label} is required', { label: 'Title' })`.\n * A blank with no value is left as it is written. Words as text, not functions,\n * can be kept in one place, translated, and passed anywhere, a view's inputs\n * included, where Foldkit admits no nested function.\n */\nexport const fillWords = (\n template: string,\n values: Readonly<Record<string, string | number>>,\n): string =>\n template.replace(/\\{(\\w+)\\}/g, (blank, name: string) =>\n Object.hasOwn(values, name) ? String(values[name]) : blank,\n )\n\n/**\n * A form made with `Form.make` from the input a key nests. It is an ordinary\n * form: the one that edits an author alone is the one a post's form nests.\n */\nexport interface FormFor<\n Fields extends Schema.Struct.Fields,\n Members,\n R = never,\n> extends NestedForm {\n readonly input: EntityInput<any, Fields, Members>\n readonly bundle: {\n readonly Model: Schema.Codec<FormModel<Fields, Members>, unknown>\n readonly Message: Schema.Codec<any, unknown>\n readonly update: (\n model: any,\n message: any,\n args: void,\n ) => {\n readonly model: any\n readonly commands?: ReadonlyArray<Command<any, never, R>> | undefined\n }\n }\n readonly initial: FormModel<Fields, Members>\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<Command<any, never, R>>\n }\n readonly isValidating: (model: any) => boolean\n readonly value: (model: any) => unknown\n }\n readonly settled: (model: any) => any\n}\n\n/** The forms a form may be given for its nested keys: each one made from that key's nested input. */\nexport type NestedForms<Fields extends Schema.Struct.Fields, Members, R> = {\n readonly [K in NestedKey<Members> & keyof Fields]?: Members[K] extends NestedInput<\n any,\n EntityInput<any, infer NestedFields, infer NestedMembers>\n >\n ? NestedFields extends Schema.Struct.Fields\n ? FormFor<NestedFields, NestedMembers, R>\n : never\n : never\n}\n\n/** The constructors of a form's Messages that a row's handle offers, wrapped for the row. */\ntype RowConstructor =\n 'Changed' | 'Blurred' | 'Searched' | 'Submitted' | 'Reset' | 'RowAdded' | 'RowRemoved'\n\n/**\n * One row of a nested key, addressed: the nested form's own Message constructors,\n * each giving the Message of the form the row is in. `send` wraps a Message\n * already made, which is how a row inside a row is reached.\n */\nexport type RowHandle<Child, Message> = {\n readonly [T in RowConstructor]: Child extends {\n readonly Message: { readonly [C in T]: (...args: infer Args) => unknown }\n }\n ? (...args: Args) => Message\n : never\n} & { readonly send: (message: unknown) => Message }\n\n/** What `Form.make` takes beside the input. */\nexport interface FormOptions<\n Fields extends Schema.Struct.Fields,\n Members,\n R,\n Nest extends NestedForms<Fields, Members, R> = {},\n> {\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?: {\n readonly [K in Exclude<keyof Fields, NestedKey<Members>>]?: Control | ControlChange\n }\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 /**\n * The form of a nested key, made with `Form.make` from the input the key nests\n * (`Relation.nested(relation, input)`): the same form that edits the target\n * alone. A nested key given none gets a plain form of its input, with this\n * form's `messages` and `debounce`.\n */\n readonly nested?: Nest\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 readonly settled: (model: any) => any\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/**\n * The checks a form may be given by key, with what they need left open. Effect's\n * `R` is not an inference site a mapped type can win: asked to infer it, TypeScript\n * answers `never`, and a check that needs anything is refused by the shape meant to\n * accept it. So the shape admits any requirement and `RequirementOf` reads back what\n * was actually passed.\n */\nexport type ChecksFor<F extends Remakeable> = {\n readonly [K in Exclude<keyof F['types']['Fields'], NestedKey<F['types']['Members']>>]?: FormCheck<\n Schema.Schema.Type<F['types']['Fields'][K]>,\n Partial<Schema.Struct.Type<F['types']['Fields']>>,\n any\n >\n}\n\n/** What a set of checks needs between them, read off the functions that were given. */\nexport type RequirementOf<C> = {\n [K in keyof C]: C[K] extends (...args: never) => Effect.Effect<any, any, infer R> ? R : never\n}[keyof C]\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: HeldDraft\n readonly empty: Draft\n readonly check: (draft: Draft) => Checked\n readonly rules: FieldValidation.Rules<Draft>\n}\n\n/** The drafts a key holds. `rows` is a nested key's, which holds rows instead. */\ntype HeldDraft = Exclude<DraftKind, 'rows'>\n\nconst kindOf = (draft: unknown): HeldDraft | 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/** Text that is read as something else is blank when it is only spaces: `Number(' ')` is 0, which nobody typed. */\nconst isBlank = (control: Control, draft: Draft): boolean =>\n isEmpty(draft) ||\n (control.parse !== undefined && 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 given: AnyForm | undefined,\n inherited: 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 if (given !== undefined && (given as { readonly input?: unknown }).input !== member.input)\n fail(\n name,\n `\"${key}\" is given a form of another input than the one it nests; make it from the input passed to Relation.nested`,\n )\n const form = given ?? makeNested(`${name}.${key}`, member.input, inherited)\n return {\n key,\n ...wordsOf(key, schema, member),\n control: Input.Nested.of({ 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 | ControlChange | undefined,\n messages: FormMessages,\n): Plan => {\n const resolved = Input.resolve(member, schema)\n const chosen =\n override === undefined\n ? resolved\n : isControlChange(override)\n ? attempt(name, () => override.change(resolved, key))\n : override\n const control = chosen ?? fail(name, `no control for \"${key}\"; name one under \"inputs\"`)\n if (control.draft === 'rows')\n return fail(\n name,\n `\"${key}\" cannot be given a ${control.kind} control; map it with Relation.nested`,\n )\n const kind = control.draft\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.kind}, 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: worded(messages.required, [field], { label, key }) ?? 'Required',\n unparsed: worded(messages.unparsed, [field], { label, key }) ?? control.unparsed ?? 'Not valid',\n invalid: (message: string) =>\n worded(messages.invalid, [field, message], { label, key, 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 // A kind may read its text as something else before the schema sees it.\n const value =\n control.parse !== undefined && typeof draft === 'string' ? control.parse(draft) : draft\n if (value === undefined) return Result.fail(say.unparsed)\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\n/** Words given as text have their blanks filled; given as a function, it is asked. */\nconst worded = <Args extends ReadonlyArray<unknown>>(\n words: string | ((...args: Args) => string) | undefined,\n args: Args,\n values: Readonly<Record<string, string | number>>,\n): string | undefined =>\n words === undefined\n ? undefined\n : typeof words === 'string'\n ? fillWords(words, values)\n : words(...args)\n\nconst fail = (name: string, message: string): never => {\n throw new Error(`Form \"${name}\": ${message}`)\n}\n\n/** A failure inside a control change, said as the form's. */\nconst attempt = <A>(name: string, run: () => A): A => {\n try {\n return run()\n } catch (error) {\n return fail(name, error instanceof Error ? error.message : String(error))\n }\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\nconst Core = {\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 const Nest extends NestedForms<Fields, Members, R> = {},\n >(\n name: Name,\n input: EntityInput<E, Fields, Members>,\n options: FormOptions<Fields, Members, R, Nest> = {},\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 | ControlChange | undefined>> =\n 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 givenForms: Readonly<Record<string, AnyForm | undefined>> = (options.nested ??\n {}) as never\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 givenForms[key],\n // A nested form made here takes this form's words and pace.\n { messages: options.messages, debounce: options.debounce },\n ),\n ]),\n ) as Readonly<Record<RowsKey, NestedPlan>>\n\n const draftSchema: Record<HeldDraft, 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 searches: Schema.Record(Schema.String, Schema.String),\n touched: Schema.Record(Schema.String, Schema.Boolean),\n errors: Schema.Array(Schema.String),\n submitPending: Schema.Boolean,\n subject: Schema.Record(Schema.String, Schema.String),\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 /**\n * The outside world refused this key's value: a unique index, a rule only a\n * server knows. The key reads invalid with that reason, keeping what was\n * typed, until it is edited again. Unlike `Checked`, it answers no question\n * the form asked, so it lands whatever state the key is in.\n */\n Refused: { key: KeySchema, error: Schema.String },\n /**\n * What the form is editing, for the checks that need to know: a post's own\n * row id, so \"is this address taken?\" can pass over the post's own address.\n * It changes no draft and validates nothing; a form that creates something\n * never sends it. See `FormModel.subject`.\n */\n About: { subject: Schema.Record(Schema.String, Schema.String) },\n /** What was typed to find a choice for a relation key. It changes no draft and validates nothing. */\n Searched: { key: KeySchema, text: 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 searches: {},\n touched: {},\n errors: [],\n submitPending: false,\n subject: {},\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), subject: model.subject })),\n Effect.map(error => Message.Checked({ key, draft, error: error ?? null })),\n ),\n } as Command<Message, never, R>,\n ],\n }\n }\n\n // The keys that follow another, and for each key, the keys that follow it.\n const followers = keys.filter(key => plans[key].control.follows !== undefined)\n const followedBy = (key: Key): ReadonlyArray<Key> =>\n followers.filter(follower => plans[follower].control.follows!.key === key)\n for (const follower of followers) {\n const source = plans[follower].control.follows!.key as Key\n if (plans[source] === undefined || plans[source].kind !== 'text' || source === follower)\n fail(name, `\"${follower}\" follows \"${source}\", which is not another text key of the form`)\n // A follows B follows A never settles.\n const seen = new Set<string>([follower])\n for (let next: Key | undefined = source; next !== undefined;) {\n if (seen.has(next)) fail(name, `\"${follower}\" follows itself, through \"${next}\"`)\n seen.add(next)\n next = plans[next].control.follows?.key as Key | undefined\n }\n }\n\n /** What a follower's draft is, from the key it follows. */\n const derived = (model: Model, follower: Key): string => {\n const { key, through } = plans[follower].control.follows!\n return through(String(drafts(model)[key as Key].value))\n }\n\n /**\n * An author's edit of one key, and what follows from it. The key becomes theirs,\n * unless they emptied a key that follows another, which hands it back. Every\n * key still following this one is rewritten, and so on down.\n */\n const changed = (\n model: Model,\n key: Key,\n draft: Draft,\n ): { readonly model: Model; readonly commands: Commands } => {\n const follows = plans[key].control.follows !== undefined\n const handedBack = follows && isEmpty(draft)\n const owned: Model = follows\n ? { ...model, touched: { ...model.touched, [key]: !handedBack } }\n : model\n const written = validateKey(owned, key, handedBack ? derived(owned, key) : draft)\n return followedBy(key).reduce((result, follower) => {\n if (result.model.touched[follower] === true) return result\n const next = rewritten(result.model, follower)\n return { model: next.model, commands: [...result.commands, ...next.commands] }\n }, written)\n }\n\n /** A follower written from the key it follows, and its own followers after it. */\n const rewritten = (\n model: Model,\n follower: Key,\n ): { readonly model: Model; readonly commands: Commands } => {\n const draft = derived(model, follower)\n // Nothing to follow yet is nothing entered, not a failure to show.\n const written = isEmpty(draft)\n ? {\n model: withField(model, follower, FieldValidation.NotValidated({ value: draft })),\n commands: [] as Commands,\n }\n : validateKey(model, follower, draft)\n return followedBy(follower).reduce((result, next) => {\n if (result.model.touched[next] === true) return result\n const after = rewritten(result.model, next)\n return { model: after.model, commands: [...result.commands, ...after.commands] }\n }, written)\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: [\n worded(options.messages?.form, [error.message], { message: error.message }) ??\n error.message,\n ],\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 // Another value to edit is another search.\n searches: {},\n // A key given a value is the author's: a published address does not move\n // because its title did. One given nothing follows again.\n touched: Object.fromEntries(\n followers.flatMap(key =>\n key in given\n ? isEmpty(draftOf(plans[key], given[key]))\n ? []\n : [[key, true] as const]\n : model.touched[key] === true\n ? [[key, true] as const]\n : [],\n ),\n ),\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 : changed(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 'Refused': {\n const state = drafts(model)[message.key]\n return {\n model: {\n // A refusal settles a submit that was waiting: it cannot go through.\n ...withField(\n model,\n message.key,\n FieldValidation.Invalid({ value: state.value, errors: [message.error] }),\n ),\n submitPending: false,\n },\n }\n }\n case 'About':\n return { model: { ...model, subject: message.subject } }\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 'Searched': {\n return plans[message.key].control.searches\n ? {\n model: { ...model, searches: { ...model.searches, [message.key]: message.text } },\n }\n : { model }\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 // Emptying the form does not change which row it is about.\n return { model: { ...initial, subject: model.subject } }\n case 'Submitted':\n return submitted(model)\n }\n },\n helpers: { fill },\n })\n\n return {\n /** The name, input and options the form was made from: what a pipe step makes the next form from. */\n name,\n options,\n /** Type-only: the form's type parameters, for a pipe step to read. Never set. */\n types: undefined as unknown as {\n readonly Name: Name\n readonly E: E\n readonly Fields: Fields\n readonly Members: Members\n readonly R: R\n readonly Nest: Nest\n },\n // Typed by `Pipeable`'s overloads, which read `this` at the call.\n ...({\n pipe() {\n return Pipeable.pipeArguments(this, arguments)\n },\n } as Pipeable.Pipeable),\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 /** What was typed to find a choice for a relation key that searches; `''` until something is. */\n search: (model: Model, key: Key): string => model.searches[key] ?? '',\n /** What the form is editing; `{}` while it creates. See `FormModel.subject`. */\n subject: (model: Model): Readonly<Record<string, string>> => model.subject,\n /**\n * The form of each nested key, typed when it was given under `nested`: its\n * `controls`, its `field`, its Messages.\n */\n nested: Object.fromEntries(rowsKeys.map(key => [key, nestedPlans[key].form])) as {\n readonly [K in RowsKey]: K extends keyof Nest ? NonNullable<Nest[K]> : NestedForm\n },\n /**\n * One row of a nested key, addressed: `form.row('author', id).Changed({ key: 'name', value })`\n * is this form's Message for that edit in that row.\n */\n row: <K extends RowsKey>(\n key: K,\n row: string,\n ): RowHandle<K extends keyof Nest ? NonNullable<Nest[K]> : NestedForm, Message> => {\n const make = (nestedPlans[key] ?? fail(name, `\"${key}\" holds a draft, not rows`)).form\n .Message as unknown as Readonly<\n Record<string, (...args: ReadonlyArray<unknown>) => unknown>\n >\n const send = (message: unknown): Message => Message.Nested({ key, row, message })\n return {\n send,\n ...Object.fromEntries(\n (\n [\n 'Changed',\n 'Blurred',\n 'Searched',\n 'Submitted',\n 'Reset',\n 'RowAdded',\n 'RowRemoved',\n ] as const\n ).map(constructor => [\n constructor,\n (...args: ReadonlyArray<unknown>) => send(make[constructor]!(...args)),\n ]),\n ),\n } as never\n },\n /**\n * Whether a key that follows another still does: `false` once the author has\n * written it themselves. A view offers \"regenerate\" by sending the key an empty draft.\n */\n isFollowing: (model: Model, key: Key): boolean =>\n plans[key].control.follows !== undefined && model.touched[key] !== true,\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 /**\n * The Model with nothing in flight, for one that was stored and is shown\n * again: a check that was running when it was stored will never answer, so\n * its key is not validated yet, and no submit is waiting. Rows too.\n */\n settled: (model: Model): Model => ({\n ...model,\n submitPending: false,\n fields: fieldsFrom(plan => {\n const field = drafts(model)[plan.key as Key]\n return field._tag === 'Validating'\n ? FieldValidation.NotValidated({ value: field.value })\n : field\n }),\n rows: Object.fromEntries(\n rowsKeys.map(key => [\n key,\n rowsOf(model)[key]!.map(row => ({\n ...row,\n model: nestedPlans[key].form.settled(row.model),\n })),\n ]),\n ) as unknown as Model['rows'],\n }),\n /**\n * What of the form decodes as it stands, by key: the value, less every key\n * that is not valid yet. For saving unfinished work, which `engine.value`\n * cannot give. A nested key is there once each of its rows has a value.\n */\n partial: (model: Model): Partial<Value> => ({\n ...decoded(model),\n ...Object.fromEntries(\n rowsKeys.flatMap(key => {\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 []\n const held =\n plan.cardinality === 'many' ? values : values.length === 0 ? plan.nothing : values[0]\n return [[key, held] as const]\n }),\n ),\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\n/** The type parameters a form was made with. */\ninterface FormTypes {\n readonly Name: string\n readonly E: AnyEntity\n readonly Fields: Schema.Struct.Fields\n readonly Members: any\n readonly R: unknown\n readonly Nest: any\n}\n\n/** A form as a pipe step takes it: what it was made from, and its type parameters. */\ninterface Remakeable<T extends FormTypes = FormTypes> {\n readonly name: string\n readonly input: EntityInput<any, any, any>\n readonly options: object\n readonly types: T\n}\n\n/** The form `Form.make` gives for these type parameters. */\ntype Made<T extends FormTypes> = ReturnType<\n typeof Core.make<T['Name'], T['E'], T['Fields'], T['Members'], T['R'], T['Nest']>\n>\n\ntype OptionsOf<T extends FormTypes> = FormOptions<T['Fields'], T['Members'], T['R'], T['Nest']>\n\n/** The form again, with some of its options replaced or added to. */\nconst remake = (form: Remakeable, change: (options: Record<string, any>) => object): never =>\n (Core.make as (name: string, input: unknown, options: object) => unknown)(form.name, form.input, {\n ...form.options,\n ...change(form.options as Record<string, any>),\n }) as never\n\n/**\n * Pipe steps. Each gives a new form, made from the same input with one option\n * added to, so a form can be handed over partly configured and finished where it\n * is used: `AuthorForm.pipe(Form.inputs({ bio: Input.multiline() }), Form.messages(german))`.\n */\nconst steps = {\n /** Controls by key, beside the ones the form already names. */\n inputs:\n <F extends Remakeable>(inputs: NonNullable<OptionsOf<F['types']>['inputs']>) =>\n (form: F): F =>\n remake(form, options => ({ inputs: { ...options.inputs, ...inputs } })),\n\n /** The form's words, beside the ones it already has. */\n messages:\n <F extends Remakeable>(messages: NonNullable<OptionsOf<F['types']>['messages']>) =>\n (form: F): F =>\n remake(form, options => ({ messages: { ...options.messages, ...messages } })),\n\n /** How long a key rests before its check runs. */\n debounce:\n (debounce: Duration.Input) =>\n <F extends Remakeable>(form: F): F =>\n remake(form, () => ({ debounce })),\n\n /**\n * Checks by key, beside the ones the form already has. What they need (`R`) is\n * added to what the form needs.\n */\n checks:\n <F extends Remakeable, const C extends ChecksFor<F>>(checks: C) =>\n (\n form: F,\n ): Made<{\n readonly Name: F['types']['Name']\n readonly E: F['types']['E']\n readonly Fields: F['types']['Fields']\n readonly Members: F['types']['Members']\n readonly R: F['types']['R'] | RequirementOf<C>\n readonly Nest: F['types']['Nest']\n }> =>\n remake(form, options => ({ checks: { ...options.checks, ...checks } })),\n\n /** The forms of nested keys, beside the ones the form was already given. */\n nested:\n <\n F extends Remakeable,\n const N extends NestedForms<F['types']['Fields'], F['types']['Members'], F['types']['R']>,\n >(\n forms: N,\n ) =>\n (\n form: F,\n ): Made<{\n readonly Name: F['types']['Name']\n readonly E: F['types']['E']\n readonly Fields: F['types']['Fields']\n readonly Members: F['types']['Members']\n readonly R: F['types']['R']\n readonly Nest: F['types']['Nest'] & N\n }> =>\n remake(form, options => ({ nested: { ...options.nested, ...forms } })),\n}\n\nexport const Form = {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C,CAAC;;;;;;AAOH,MAAM,QAAQ;;CAEZ,SACyB,YACtB,SACC,OAAO,OAAM,aAAY,EAAE,QAAQ;EAAE,GAAG,QAAQ;EAAQ,GAAG;CAAO,EAAE,EAAE;;CAG1E,WACyB,cACtB,SACC,OAAO,OAAM,aAAY,EAAE,UAAU;EAAE,GAAG,QAAQ;EAAU,GAAG;CAAS,EAAE,EAAE;;CAGhF,WACG,cACsB,SACrB,OAAO,aAAa,EAAE,SAAS,EAAE;;;;;CAMrC,SACuD,YAEnD,SASA,OAAO,OAAM,aAAY,EAAE,QAAQ;EAAE,GAAG,QAAQ;EAAQ,GAAG;CAAO,EAAE,EAAE;;CAG1E,SAKI,WAGA,SASA,OAAO,OAAM,aAAY,EAAE,QAAQ;EAAE,GAAG,QAAQ;EAAQ,GAAG;CAAM,EAAE,EAAE;AAC3E;AAEA,MAAa,OAAO;CAAE,GAAG;CAAM,GAAG;AAAM;AAExC,aAAa,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit-form",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Forms for Foldkit: a Bundle over core field validation, built from an operation's input and the Entity it writes.",
5
5
  "keywords": [
6
6
  "foldkit",
@@ -38,8 +38,8 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "dependencies": {
41
+ "foldkit-entity": "0.3.0",
41
42
  "foldkit-bundle": "0.2.0",
42
- "foldkit-entity": "0.1.0",
43
43
  "foldkit-metadata": "0.1.0"
44
44
  },
45
45
  "peerDependencies": {