foldkit-form 0.1.0 → 0.1.1

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.
package/dist/index.d.mts CHANGED
@@ -3,42 +3,60 @@ import { Bundle } from "foldkit-bundle";
3
3
  import { Metadata } from "foldkit-metadata";
4
4
  import * as FieldValidation from "foldkit/fieldValidation";
5
5
  import { AnyEntity, EntityInput, InputMember, NestedInput } from "foldkit-entity";
6
+ import { Command } from "foldkit/command";
6
7
  //#region src/input.d.ts
7
- type Control = {
8
- readonly _tag: 'Text';
9
- } |
10
- /** Carried and submitted, not shown: the id of the thing being edited. Set it with `fill`. */
11
- {
12
- readonly _tag: 'Hidden';
13
- } | {
14
- readonly _tag: 'Multiline';
15
- } | {
16
- readonly _tag: 'Number';
17
- } | {
18
- readonly _tag: 'Toggle';
19
- } | {
20
- readonly _tag: 'Select';
21
- readonly options: ReadonlyArray<string>;
22
- } |
23
- /** Chooses one of `target`. The options are the application's to supply. */
24
- {
25
- readonly _tag: 'RelationOne';
26
- readonly target: AnyEntity;
27
- } | {
28
- readonly _tag: 'RelationMany';
29
- readonly target: AnyEntity;
30
- } |
31
8
  /**
32
- * The target itself, edited through a form of its own (`Relation.nested`). The
33
- * key holds rows of that form: exactly one, at most one, or any number.
9
+ * What a control holds while it is edited, which is not the value it submits: a
10
+ * number being typed is text, and an unchosen relation is the empty string.
34
11
  */
35
- {
36
- readonly _tag: 'Nested';
37
- readonly cardinality: 'one' | 'many';
38
- /** Whether the rows may be none: always for a `many`, for a `one` when its schema admits nothing. */
39
- readonly optional: boolean;
40
- readonly form: NestedForm;
41
- };
12
+ type Draft = string | boolean | ReadonlyArray<string>;
13
+ /** The draft a control holds. `rows` is a nested key: rows of a form, not a draft. */
14
+ type DraftKind = 'text' | 'flag' | 'list' | 'rows';
15
+ /** What edits one key: the primitive every kind of control is a value of. */
16
+ interface Control<Data = unknown> {
17
+ /** The name a renderer is found by. */
18
+ readonly kind: string;
19
+ readonly draft: DraftKind;
20
+ /** Whether a view draws it. A control carried and submitted, not shown, is `false`. */
21
+ readonly shown: boolean;
22
+ /**
23
+ * Whether the form also holds what the user typed to find a choice, which the
24
+ * application reads as the input of the query that lists the choices.
25
+ */
26
+ readonly searches: boolean;
27
+ /** What this kind needs: a select's options, a relation's target. */
28
+ readonly data: Data;
29
+ /**
30
+ * For a `text` draft: the value the key's schema is given, when that is not the
31
+ * text itself. `undefined` means the text does not read as one.
32
+ */
33
+ readonly parse?: ((draft: string) => unknown) | undefined;
34
+ /** What to say when `parse` gives `undefined`. */
35
+ readonly unparsed?: string | undefined;
36
+ /**
37
+ * For a `text` draft: another key of the form this one is written from until
38
+ * the author writes it themselves. A slug follows a title.
39
+ */
40
+ readonly follows?: Follows | undefined;
41
+ }
42
+ /** Which key a draft follows, and what it makes of that key's text. */
43
+ interface Follows {
44
+ readonly key: string;
45
+ readonly through: (text: string) => string;
46
+ }
47
+ /** A kind of control: how its values are made, and how one is told from another. */
48
+ interface ControlKind<Data> {
49
+ readonly kind: string;
50
+ readonly of: (data: Data) => Control<Data>;
51
+ readonly is: (control: Control) => control is Control<Data>;
52
+ }
53
+ /**
54
+ * Under `inputs`, in place of a control: a change to the control the form would
55
+ * have resolved, such as giving the key's relation picker a search.
56
+ */
57
+ interface ControlChange {
58
+ readonly change: (resolved: Control | undefined, key: string) => Control;
59
+ }
42
60
  /** One row of a nested key: a Model of the nested form, under an id that outlives reordering. */
43
61
  interface FormRow<Model = unknown> {
44
62
  readonly id: string;
@@ -55,26 +73,74 @@ interface NestedForm {
55
73
  }>;
56
74
  readonly field: (model: never, key: never) => unknown;
57
75
  readonly rows: (model: never, key: never) => ReadonlyArray<FormRow>;
76
+ readonly search: (model: never, key: never) => string;
77
+ readonly isFollowing: (model: never, key: never) => boolean;
58
78
  readonly Message: {
59
79
  readonly Changed: (payload: never) => unknown;
60
80
  readonly Blurred: (payload: never) => unknown;
81
+ readonly Searched: (payload: never) => unknown;
61
82
  readonly Nested: (payload: never) => unknown;
62
83
  readonly RowAdded: (payload: never) => unknown;
63
84
  readonly RowRemoved: (payload: never) => unknown;
64
85
  };
65
86
  }
66
- /**
67
- * What a control holds while it is edited, which is not the value it submits: a
68
- * number being typed is text, and an unchosen relation is the empty string.
69
- */
70
- type Draft = string | boolean | ReadonlyArray<string>;
87
+ /** A relation picker: what it chooses from, and whether it searches. */
88
+ interface RelationData {
89
+ readonly target: AnyEntity;
90
+ readonly search: boolean;
91
+ }
92
+ /** A nested key: how many rows it may hold, and the form each row is a Model of. */
93
+ interface NestedData {
94
+ readonly cardinality: 'one' | 'many';
95
+ /** Whether the rows may be none: always for a `many`, for a `one` when its schema admits nothing. */
96
+ readonly optional: boolean;
97
+ readonly form: NestedForm;
98
+ }
71
99
  export declare const Input: {
100
+ /**
101
+ * A kind of control. `Input.kind<{ min: string }>('Date', { draft: 'text' })`
102
+ * gives `.of(data)` to make one and `.is(control)` to tell one, exactly as the
103
+ * kinds below were made. A view draws it once it is given a renderer for `Date`.
104
+ */
105
+ kind: <Data = Record<string, never>>(name: string, spec: {
106
+ readonly draft: DraftKind;
107
+ readonly shown?: boolean;
108
+ readonly searches?: boolean | ((data: Data) => boolean);
109
+ readonly parse?: (draft: string) => unknown;
110
+ readonly unparsed?: string;
111
+ }) => ControlKind<Data>;
112
+ Text: ControlKind<Record<string, never>>;
113
+ Hidden: ControlKind<Record<string, never>>;
114
+ Multiline: ControlKind<Record<string, never>>;
115
+ Number: ControlKind<Record<string, never>>;
116
+ Toggle: ControlKind<Record<string, never>>;
117
+ Select: ControlKind<{
118
+ readonly options: ReadonlyArray<string>;
119
+ }>;
120
+ RelationOne: ControlKind<RelationData>;
121
+ RelationMany: ControlKind<RelationData>;
122
+ Nested: ControlKind<NestedData>;
72
123
  text: () => Control;
124
+ /** Carried and submitted, not shown: the id of the thing being edited. Set it with `fill`. */
73
125
  hidden: () => Control;
74
126
  multiline: () => Control;
75
127
  number: () => Control;
76
128
  toggle: () => Control;
77
129
  select: (options: ReadonlyArray<string>) => Control;
130
+ /**
131
+ * For a relation key, under `inputs`: its picker, with a search. Too many to
132
+ * list is the usual case for a relation; the form holds the search text, and
133
+ * the query that lists the options takes it as input.
134
+ */
135
+ search: () => ControlChange;
136
+ /**
137
+ * Under `inputs`: the key's own control, following another key. Until the
138
+ * author writes this key, its draft is `through` of that key's text, rewritten
139
+ * as that key is edited; once they write it, it is theirs. Emptying it hands
140
+ * it back. A form filled with a value for it does not follow: an address that
141
+ * is already published must not move because its title did.
142
+ */
143
+ following: (key: string, through?: (text: string) => string) => ControlChange;
78
144
  /**
79
145
  * Entity metadata: the control a member is edited with wherever it appears,
80
146
  * e.g. `Entity.annotateMembers({ body: Input.of(Input.multiline()) })`.
@@ -102,10 +168,24 @@ export interface FormModel<Fields extends Schema.Struct.Fields, Members = {}> {
102
168
  readonly rows: { readonly [K in keyof Fields as K extends NestedKey<Members> ? K : never]: ReadonlyArray<FormRow<NestedModel<Members[K & keyof Members]>>>; };
103
169
  /** Counts the rows ever added, so a row's id is never reused. */
104
170
  readonly nextRow: number;
171
+ /** What was typed to find a choice, by key, for the relation pickers that search. */
172
+ readonly searches: Readonly<Record<string, string>>;
173
+ /**
174
+ * The keys that follow another and that the author has written themselves, so
175
+ * they follow no longer. A key that follows nothing is never here.
176
+ */
177
+ readonly touched: Readonly<Record<string, boolean>>;
105
178
  /** Failures of the input as a whole, from the last submit: a rule that spans keys. */
106
179
  readonly errors: ReadonlyArray<string>;
107
180
  /** A submit is waiting for checks still running; it goes out when the last one passes. */
108
181
  readonly submitPending: boolean;
182
+ /**
183
+ * What the form is editing, which its values do not say: a post's own row id,
184
+ * so a check that asks whether an address is taken can tell the post's own
185
+ * address from someone else's. Empty until `Message.About` says otherwise,
186
+ * which is what a form that creates something means.
187
+ */
188
+ readonly subject: Readonly<Record<string, string>>;
109
189
  }
110
190
  /**
111
191
  * A rule only something outside the form can answer: is this slug taken? It is
@@ -115,6 +195,8 @@ export interface FormModel<Fields extends Schema.Struct.Fields, Members = {}> {
115
195
  */
116
196
  export type FormCheck<A, Values, R = never> = (value: A, context: {
117
197
  readonly values: Values;
198
+ /** What the form is editing: `{}` while it creates. See `FormModel.subject`. */
199
+ readonly subject: Readonly<Record<string, string>>;
118
200
  }) => Effect.Effect<string | undefined, never, R>;
119
201
  /** The form's out Message: every key is valid and the input decoded. */
120
202
  export interface Submitted<Value> {
@@ -145,39 +227,460 @@ export interface MessageField<Key extends string = string> {
145
227
  * rewrite what Schema says by default.
146
228
  */
147
229
  export interface FormMessages<Key extends string = string> {
148
- /** An empty draft the schema does not admit. Default `Required`. */
149
- readonly required?: (field: MessageField<Key>) => string;
150
- /** A `Number` control whose draft is not a number. Default `Enter a number`. */
151
- readonly notANumber?: (field: MessageField<Key>) => string;
152
- /** A draft the key's schema rejects. `message` is the check's own, or Schema's. Default: `message`. */
153
- readonly invalid?: (field: MessageField<Key>, message: string) => string;
154
- /** A failure of the input as a whole: a rule that spans keys. Default: `message`. */
155
- readonly form?: (message: string) => string;
230
+ /** An empty draft the schema does not admit. `{label}`, `{key}`. Default `Required`. */
231
+ readonly required?: string | ((field: MessageField<Key>) => string);
232
+ /** Text its control cannot read: a `Number` that is not one. `{label}`, `{key}`. Default: the kind's own words (`Enter a number`). */
233
+ readonly unparsed?: string | ((field: MessageField<Key>) => string);
234
+ /** A draft the key's schema rejects. `{message}` is the check's own, or Schema's; `{label}`, `{key}`. Default: `{message}`. */
235
+ readonly invalid?: string | ((field: MessageField<Key>, message: string) => string);
236
+ /** A failure of the input as a whole: a rule that spans keys. `{message}`. Default: `{message}`. */
237
+ readonly form?: string | ((message: string) => string);
238
+ }
239
+ /**
240
+ * Words with their blanks filled: `fillWords('{label} is required', { label: 'Title' })`.
241
+ * A blank with no value is left as it is written. Words as text, not functions,
242
+ * can be kept in one place, translated, and passed anywhere, a view's inputs
243
+ * included, where Foldkit admits no nested function.
244
+ */
245
+ export declare const fillWords: (template: string, values: Readonly<Record<string, string | number>>) => string;
246
+ /**
247
+ * A form made with `Form.make` from the input a key nests. It is an ordinary
248
+ * form: the one that edits an author alone is the one a post's form nests.
249
+ */
250
+ export interface FormFor<Fields extends Schema.Struct.Fields, Members, R = never> extends NestedForm {
251
+ readonly input: EntityInput<any, Fields, Members>;
252
+ readonly bundle: {
253
+ readonly Model: Schema.Codec<FormModel<Fields, Members>, unknown>;
254
+ readonly Message: Schema.Codec<any, unknown>;
255
+ readonly update: (model: any, message: any, args: void) => {
256
+ readonly model: any;
257
+ readonly commands?: ReadonlyArray<Command<any, never, R>> | undefined;
258
+ };
259
+ };
260
+ readonly initial: FormModel<Fields, Members>;
261
+ readonly fill: (model: any, values: any) => {
262
+ readonly model: any;
263
+ };
264
+ readonly engine: {
265
+ readonly submit: (model: any) => {
266
+ readonly model: any;
267
+ readonly commands: ReadonlyArray<Command<any, never, R>>;
268
+ };
269
+ readonly isValidating: (model: any) => boolean;
270
+ readonly value: (model: any) => unknown;
271
+ };
272
+ readonly settled: (model: any) => any;
156
273
  }
157
- /** What `Form.make` takes beside the input. A nested key's form takes the same, under `nested`. */
158
- export interface FormOptions<Fields extends Schema.Struct.Fields, Members, R> {
274
+ /** The forms a form may be given for its nested keys: each one made from that key's nested input. */
275
+ export type NestedForms<Fields extends Schema.Struct.Fields, Members, R> = { readonly [K in NestedKey<Members> & keyof Fields]?: Members[K] extends NestedInput<any, EntityInput<any, infer NestedFields, infer NestedMembers>> ? NestedFields extends Schema.Struct.Fields ? FormFor<NestedFields, NestedMembers, R> : never : never; };
276
+ /** The constructors of a form's Messages that a row's handle offers, wrapped for the row. */
277
+ type RowConstructor = 'Changed' | 'Blurred' | 'Searched' | 'Submitted' | 'Reset' | 'RowAdded' | 'RowRemoved';
278
+ /**
279
+ * One row of a nested key, addressed: the nested form's own Message constructors,
280
+ * each giving the Message of the form the row is in. `send` wraps a Message
281
+ * already made, which is how a row inside a row is reached.
282
+ */
283
+ export type RowHandle<Child, Message> = { readonly [T in RowConstructor]: Child extends {
284
+ readonly Message: { readonly [C in T]: (...args: infer Args) => unknown; };
285
+ } ? (...args: Args) => Message : never; } & {
286
+ readonly send: (message: unknown) => Message;
287
+ };
288
+ /** What `Form.make` takes beside the input. */
289
+ export interface FormOptions<Fields extends Schema.Struct.Fields, Members, R, Nest extends NestedForms<Fields, Members, R> = {}> {
159
290
  /**
160
291
  * The control for a key the resolver cannot decide, or should not: an unmapped
161
292
  * key with an unusual schema, or text that wants a multiline control here only.
162
293
  */
163
- readonly inputs?: { readonly [K in Exclude<keyof Fields, NestedKey<Members>>]?: Control; };
294
+ readonly inputs?: { readonly [K in Exclude<keyof Fields, NestedKey<Members>>]?: Control | ControlChange; };
164
295
  /** The form's own words, and a rewrite of Schema's: for wording and for translation. */
165
296
  readonly messages?: FormMessages<keyof Fields & string>;
166
297
  /** Rules answered outside the form, by key. The key reads `Validating` while one runs. */
167
298
  readonly checks?: { readonly [K in Exclude<keyof Fields, NestedKey<Members>>]?: FormCheck<Schema.Schema.Type<Fields[K]>, Partial<Schema.Struct.Type<Fields>>, R>; };
168
299
  /** How long a key rests before its check runs, so typing does not ask per keystroke. Default 300ms. */
169
300
  readonly debounce?: Duration.Input;
170
- /** The options of each nested key's form. `messages` and `debounce` are inherited when not given. */
171
- readonly nested?: { readonly [K in NestedKey<Members> & keyof Fields]?: Members[K] extends NestedInput<any, EntityInput<any, infer NestedFields, infer NestedMembers>> ? FormOptions<NestedFields, NestedMembers, R> : never; };
301
+ /**
302
+ * The form of a nested key, made with `Form.make` from the input the key nests
303
+ * (`Relation.nested(relation, input)`): the same form that edits the target
304
+ * alone. A nested key given none gets a plain form of its input, with this
305
+ * form's `messages` and `debounce`.
306
+ */
307
+ readonly nested?: Nest;
172
308
  }
309
+ /**
310
+ * The checks a form may be given by key, with what they need left open. Effect's
311
+ * `R` is not an inference site a mapped type can win: asked to infer it, TypeScript
312
+ * answers `never`, and a check that needs anything is refused by the shape meant to
313
+ * accept it. So the shape admits any requirement and `RequirementOf` reads back what
314
+ * was actually passed.
315
+ */
316
+ export type ChecksFor<F extends Remakeable> = { readonly [K in Exclude<keyof F['types']['Fields'], NestedKey<F['types']['Members']>>]?: FormCheck<Schema.Schema.Type<F['types']['Fields'][K]>, Partial<Schema.Struct.Type<F['types']['Fields']>>, any>; };
317
+ /** What a set of checks needs between them, read off the functions that were given. */
318
+ export type RequirementOf<C> = { [K in keyof C]: C[K] extends ((...args: never) => Effect.Effect<any, any, infer R>) ? R : never; }[keyof C];
319
+ declare const Core: {
320
+ /**
321
+ * A form for one operation's input. A key mapped with `Relation.nested` holds
322
+ * rows of a form of its own, built here from the nested input; every other key
323
+ * holds a draft. `options` names what the input cannot say: a control, the
324
+ * words, the checks.
325
+ */
326
+ make: <const Name extends string, E extends AnyEntity, Fields extends Schema.Struct.Fields, Members extends { readonly [K in keyof Fields]: InputMember; }, R = never, const Nest extends NestedForms<Fields, Members, R> = {}>(name: Name, input: EntityInput<E, Fields, Members>, options?: FormOptions<Fields, Members, R, Nest>) => {
327
+ bundle: Bundle.Bundle<Name, void, FormModel<Fields, Members>, {
328
+ readonly _tag: "Changed";
329
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
330
+ readonly value: string | boolean | readonly string[];
331
+ } | {
332
+ readonly _tag: "Blurred";
333
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
334
+ } | {
335
+ readonly _tag: "Submitted";
336
+ } | {
337
+ readonly _tag: "Reset";
338
+ } | {
339
+ readonly _tag: "Checked";
340
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
341
+ readonly draft: string | boolean | readonly string[];
342
+ readonly error: string | null;
343
+ } | {
344
+ readonly _tag: "Refused";
345
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
346
+ readonly error: string;
347
+ } | {
348
+ readonly _tag: "About";
349
+ readonly subject: {
350
+ readonly [x: string]: string;
351
+ };
352
+ } | {
353
+ readonly _tag: "Searched";
354
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
355
+ readonly text: string;
356
+ } | {
357
+ readonly _tag: "Nested";
358
+ readonly key: string;
359
+ readonly row: string;
360
+ readonly message: unknown;
361
+ } | {
362
+ readonly _tag: "RowAdded";
363
+ readonly key: string;
364
+ } | {
365
+ readonly _tag: "RowRemoved";
366
+ readonly key: string;
367
+ readonly row: string;
368
+ }, Submitted<Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>>, R, never, void, {}, {
369
+ fill: (model: FormModel<Fields, Members>, values: Partial<Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>>) => {
370
+ readonly model: FormModel<Fields, Members>;
371
+ };
372
+ }>;
373
+ Message: import("foldkit/message").MessageUnion<{
374
+ readonly Changed: {
375
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
376
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean, Schema.$Array<Schema.String>]>;
377
+ };
378
+ /** Validates the key as it stands, so a required key left empty says so. */
379
+ readonly Blurred: {
380
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
381
+ };
382
+ readonly Submitted: {};
383
+ readonly Reset: {};
384
+ /** The answer of a check for the draft it was asked about; one for an older draft is dropped. */
385
+ readonly Checked: {
386
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
387
+ readonly draft: Schema.Union<readonly [Schema.String, Schema.Boolean, Schema.$Array<Schema.String>]>;
388
+ readonly error: Schema.NullOr<Schema.String>;
389
+ };
390
+ /**
391
+ * The outside world refused this key's value: a unique index, a rule only a
392
+ * server knows. The key reads invalid with that reason, keeping what was
393
+ * typed, until it is edited again. Unlike `Checked`, it answers no question
394
+ * the form asked, so it lands whatever state the key is in.
395
+ */
396
+ readonly Refused: {
397
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
398
+ readonly error: Schema.String;
399
+ };
400
+ /**
401
+ * What the form is editing, for the checks that need to know: a post's own
402
+ * row id, so "is this address taken?" can pass over the post's own address.
403
+ * It changes no draft and validates nothing; a form that creates something
404
+ * never sends it. See `FormModel.subject`.
405
+ */
406
+ readonly About: {
407
+ readonly subject: Schema.$Record<Schema.String, Schema.String>;
408
+ };
409
+ /** What was typed to find a choice for a relation key. It changes no draft and validates nothing. */
410
+ readonly Searched: {
411
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
412
+ readonly text: Schema.String;
413
+ };
414
+ /** A Message of the nested form in one row of a nested key. One that row does not take is dropped. */
415
+ readonly Nested: {
416
+ readonly key: Schema.String;
417
+ readonly row: Schema.String;
418
+ readonly message: Schema.Unknown;
419
+ };
420
+ /** A new, empty row. A `one` that already has its row takes no other. */
421
+ readonly RowAdded: {
422
+ readonly key: Schema.String;
423
+ };
424
+ /** Removes a row. A `one` that must be there stays. */
425
+ readonly RowRemoved: {
426
+ readonly key: Schema.String;
427
+ readonly row: Schema.String;
428
+ };
429
+ }>;
430
+ /** The reading the form was made from, for `Entity.selectFor` and `Entity.valuesFor`. */
431
+ input: EntityInput<E, Fields, Members>;
432
+ /** The `fill` helper as a plain function of the form's Model, for a package that wraps the form. */
433
+ fill: (model: FormModel<Fields, Members>, values: Partial<Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>>) => {
434
+ readonly model: FormModel<Fields, Members>;
435
+ };
436
+ /** The Model the form starts from and resets to: every key empty and not validated. */
437
+ initial: FormModel<Fields, Members>;
438
+ /** The keys in the input's order, each with its control, label, and member. */
439
+ controls: FormControl<keyof Fields & string>[];
440
+ /**
441
+ * One key's state with its draft as any `Draft`, for a view that walks
442
+ * `controls`. `model.fields.title` is the same value, typed to that key. A
443
+ * nested key has rows and no draft.
444
+ */
445
+ field: (model: FormModel<Fields, Members>, key: Exclude<keyof Fields & string, NestedKey<Members>>) => FieldValidation.Field<Draft>;
446
+ /** What was typed to find a choice for a relation key that searches; `''` until something is. */
447
+ search: (model: FormModel<Fields, Members>, key: Exclude<keyof Fields & string, NestedKey<Members>>) => string;
448
+ /** What the form is editing; `{}` while it creates. See `FormModel.subject`. */
449
+ subject: (model: FormModel<Fields, Members>) => Readonly<Record<string, string>>;
450
+ /**
451
+ * The form of each nested key, typed when it was given under `nested`: its
452
+ * `controls`, its `field`, its Messages.
453
+ */
454
+ nested: { readonly [K in Extract<keyof Fields & string, NestedKey<Members>>]: K extends keyof Nest ? NonNullable<Nest[K]> : NestedForm; };
455
+ /**
456
+ * One row of a nested key, addressed: `form.row('author', id).Changed({ key: 'name', value })`
457
+ * is this form's Message for that edit in that row.
458
+ */
459
+ row: <K extends Extract<keyof Fields & string, NestedKey<Members>>>(key: K, row: string) => RowHandle<K extends keyof Nest ? NonNullable<Nest[K]> : NestedForm, {
460
+ readonly _tag: "Changed";
461
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
462
+ readonly value: string | boolean | readonly string[];
463
+ } | {
464
+ readonly _tag: "Blurred";
465
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
466
+ } | {
467
+ readonly _tag: "Submitted";
468
+ } | {
469
+ readonly _tag: "Reset";
470
+ } | {
471
+ readonly _tag: "Checked";
472
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
473
+ readonly draft: string | boolean | readonly string[];
474
+ readonly error: string | null;
475
+ } | {
476
+ readonly _tag: "Refused";
477
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
478
+ readonly error: string;
479
+ } | {
480
+ readonly _tag: "About";
481
+ readonly subject: {
482
+ readonly [x: string]: string;
483
+ };
484
+ } | {
485
+ readonly _tag: "Searched";
486
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
487
+ readonly text: string;
488
+ } | {
489
+ readonly _tag: "Nested";
490
+ readonly key: string;
491
+ readonly row: string;
492
+ readonly message: unknown;
493
+ } | {
494
+ readonly _tag: "RowAdded";
495
+ readonly key: string;
496
+ } | {
497
+ readonly _tag: "RowRemoved";
498
+ readonly key: string;
499
+ readonly row: string;
500
+ }>;
501
+ /**
502
+ * Whether a key that follows another still does: `false` once the author has
503
+ * written it themselves. A view offers "regenerate" by sending the key an empty draft.
504
+ */
505
+ isFollowing: (model: FormModel<Fields, Members>, key: Exclude<keyof Fields & string, NestedKey<Members>>) => boolean;
506
+ /** The rows of a nested key, each a Model of `control.form`. */
507
+ rows: (model: FormModel<Fields, Members>, key: Extract<keyof Fields & string, NestedKey<Members>>) => { readonly [K in keyof Fields as K extends NestedKey<Members> ? K : never]: readonly FormRow<NestedModel<Members[K & keyof Members]>>[]; }[Extract<keyof Fields & string, NestedKey<Members>>];
508
+ /**
509
+ * Whether a submit now could go through: nothing is invalid. A check still
510
+ * running does not stop it; the submit waits for the answer.
511
+ */
512
+ canSubmit: (model: FormModel<Fields, Members>) => boolean;
513
+ /**
514
+ * The Model with nothing in flight, for one that was stored and is shown
515
+ * again: a check that was running when it was stored will never answer, so
516
+ * its key is not validated yet, and no submit is waiting. Rows too.
517
+ */
518
+ settled: (model: FormModel<Fields, Members>) => FormModel<Fields, Members>;
519
+ /**
520
+ * What of the form decodes as it stands, by key: the value, less every key
521
+ * that is not valid yet. For saving unfinished work, which `engine.value`
522
+ * cannot give. A nested key is there once each of its rows has a value.
523
+ */
524
+ partial: (model: FormModel<Fields, Members>) => Partial<Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>>;
525
+ /** The form as the form that nests it drives it. */
526
+ engine: {
527
+ submit: (model: FormModel<Fields, Members>) => {
528
+ model: FormModel<Fields, Members>;
529
+ commands: readonly Readonly<{
530
+ name: string;
531
+ args?: Record<string, unknown>;
532
+ key?: string;
533
+ effect: Effect.Effect<{
534
+ readonly _tag: "Changed";
535
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
536
+ readonly value: string | boolean | readonly string[];
537
+ } | {
538
+ readonly _tag: "Blurred";
539
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
540
+ } | {
541
+ readonly _tag: "Submitted";
542
+ } | {
543
+ readonly _tag: "Reset";
544
+ } | {
545
+ readonly _tag: "Checked";
546
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
547
+ readonly draft: string | boolean | readonly string[];
548
+ readonly error: string | null;
549
+ } | {
550
+ readonly _tag: "Refused";
551
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
552
+ readonly error: string;
553
+ } | {
554
+ readonly _tag: "About";
555
+ readonly subject: {
556
+ readonly [x: string]: string;
557
+ };
558
+ } | {
559
+ readonly _tag: "Searched";
560
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
561
+ readonly text: string;
562
+ } | {
563
+ readonly _tag: "Nested";
564
+ readonly key: string;
565
+ readonly row: string;
566
+ readonly message: unknown;
567
+ } | {
568
+ readonly _tag: "RowAdded";
569
+ readonly key: string;
570
+ } | {
571
+ readonly _tag: "RowRemoved";
572
+ readonly key: string;
573
+ readonly row: string;
574
+ }, never, R>;
575
+ }>[];
576
+ };
577
+ isValidating: (model: FormModel<Fields, Members>) => boolean;
578
+ /** The decoded input when every key and row is valid as it stands; validates nothing. */
579
+ value: (model: FormModel<Fields, Members>) => Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>> | undefined;
580
+ };
581
+ pipe<A>(this: A): A;
582
+ pipe<A, B = never>(this: A, ab: (_: A) => B): B;
583
+ pipe<A, B_1 = never, C = never>(this: A, ab: (_: A) => B_1, bc: (_: B_1) => C): C;
584
+ pipe<A, B_2 = never, C_1 = never, D = never>(this: A, ab: (_: A) => B_2, bc: (_: B_2) => C_1, cd: (_: C_1) => D): D;
585
+ pipe<A, B_3 = never, C_2 = never, D_1 = never, E_1 = never>(this: A, ab: (_: A) => B_3, bc: (_: B_3) => C_2, cd: (_: C_2) => D_1, de: (_: D_1) => E_1): E_1;
586
+ pipe<A, B_4 = never, C_3 = never, D_2 = never, E_2 = never, F = never>(this: A, ab: (_: A) => B_4, bc: (_: B_4) => C_3, cd: (_: C_3) => D_2, de: (_: D_2) => E_2, ef: (_: E_2) => F): F;
587
+ pipe<A, B_5 = never, C_4 = never, D_3 = never, E_3 = never, F_1 = never, G = never>(this: A, ab: (_: A) => B_5, bc: (_: B_5) => C_4, cd: (_: C_4) => D_3, de: (_: D_3) => E_3, ef: (_: E_3) => F_1, fg: (_: F_1) => G): G;
588
+ pipe<A, B_6 = never, C_5 = never, D_4 = never, E_4 = never, F_2 = never, G_1 = never, H = never>(this: A, ab: (_: A) => B_6, bc: (_: B_6) => C_5, cd: (_: C_5) => D_4, de: (_: D_4) => E_4, ef: (_: E_4) => F_2, fg: (_: F_2) => G_1, gh: (_: G_1) => H): H;
589
+ pipe<A, B_7 = never, C_6 = never, D_5 = never, E_5 = never, F_3 = never, G_2 = never, H_1 = never, I = never>(this: A, ab: (_: A) => B_7, bc: (_: B_7) => C_6, cd: (_: C_6) => D_5, de: (_: D_5) => E_5, ef: (_: E_5) => F_3, fg: (_: F_3) => G_2, gh: (_: G_2) => H_1, hi: (_: H_1) => I): I;
590
+ pipe<A, B_8 = never, C_7 = never, D_6 = never, E_6 = never, F_4 = never, G_3 = never, H_2 = never, I_1 = never, J = never>(this: A, ab: (_: A) => B_8, bc: (_: B_8) => C_7, cd: (_: C_7) => D_6, de: (_: D_6) => E_6, ef: (_: E_6) => F_4, fg: (_: F_4) => G_3, gh: (_: G_3) => H_2, hi: (_: H_2) => I_1, ij: (_: I_1) => J): J;
591
+ pipe<A, B_9 = never, C_8 = never, D_7 = never, E_7 = never, F_5 = never, G_4 = never, H_3 = never, I_2 = never, J_1 = never, K = never>(this: A, ab: (_: A) => B_9, bc: (_: B_9) => C_8, cd: (_: C_8) => D_7, de: (_: D_7) => E_7, ef: (_: E_7) => F_5, fg: (_: F_5) => G_4, gh: (_: G_4) => H_3, hi: (_: H_3) => I_2, ij: (_: I_2) => J_1, jk: (_: J_1) => K): K;
592
+ pipe<A, B_10 = never, C_9 = never, D_8 = never, E_8 = never, F_6 = never, G_5 = never, H_4 = never, I_3 = never, J_2 = never, K_1 = never, L = never>(this: A, ab: (_: A) => B_10, bc: (_: B_10) => C_9, cd: (_: C_9) => D_8, de: (_: D_8) => E_8, ef: (_: E_8) => F_6, fg: (_: F_6) => G_5, gh: (_: G_5) => H_4, hi: (_: H_4) => I_3, ij: (_: I_3) => J_2, jk: (_: J_2) => K_1, kl: (_: K_1) => L): L;
593
+ pipe<A, B_11 = never, C_10 = never, D_9 = never, E_9 = never, F_7 = never, G_6 = never, H_5 = never, I_4 = never, J_3 = never, K_2 = never, L_1 = never, M = never>(this: A, ab: (_: A) => B_11, bc: (_: B_11) => C_10, cd: (_: C_10) => D_9, de: (_: D_9) => E_9, ef: (_: E_9) => F_7, fg: (_: F_7) => G_6, gh: (_: G_6) => H_5, hi: (_: H_5) => I_4, ij: (_: I_4) => J_3, jk: (_: J_3) => K_2, kl: (_: K_2) => L_1, lm: (_: L_1) => M): M;
594
+ pipe<A, B_12 = never, C_11 = never, D_10 = never, E_10 = never, F_8 = never, G_7 = never, H_6 = never, I_5 = never, J_4 = never, K_3 = never, L_2 = never, M_1 = never, N = never>(this: A, ab: (_: A) => B_12, bc: (_: B_12) => C_11, cd: (_: C_11) => D_10, de: (_: D_10) => E_10, ef: (_: E_10) => F_8, fg: (_: F_8) => G_7, gh: (_: G_7) => H_6, hi: (_: H_6) => I_5, ij: (_: I_5) => J_4, jk: (_: J_4) => K_3, kl: (_: K_3) => L_2, lm: (_: L_2) => M_1, mn: (_: M_1) => N): N;
595
+ pipe<A, B_13 = never, C_12 = never, D_11 = never, E_11 = never, F_9 = never, G_8 = never, H_7 = never, I_6 = never, J_5 = never, K_4 = never, L_3 = never, M_2 = never, N_1 = never, O = never>(this: A, ab: (_: A) => B_13, bc: (_: B_13) => C_12, cd: (_: C_12) => D_11, de: (_: D_11) => E_11, ef: (_: E_11) => F_9, fg: (_: F_9) => G_8, gh: (_: G_8) => H_7, hi: (_: H_7) => I_6, ij: (_: I_6) => J_5, jk: (_: J_5) => K_4, kl: (_: K_4) => L_3, lm: (_: L_3) => M_2, mn: (_: M_2) => N_1, no: (_: N_1) => O): O;
596
+ pipe<A, B_14 = never, C_13 = never, D_12 = never, E_12 = never, F_10 = never, G_9 = never, H_8 = never, I_7 = never, J_6 = never, K_5 = never, L_4 = never, M_3 = never, N_2 = never, O_1 = never, P = never>(this: A, ab: (_: A) => B_14, bc: (_: B_14) => C_13, cd: (_: C_13) => D_12, de: (_: D_12) => E_12, ef: (_: E_12) => F_10, fg: (_: F_10) => G_9, gh: (_: G_9) => H_8, hi: (_: H_8) => I_7, ij: (_: I_7) => J_6, jk: (_: J_6) => K_5, kl: (_: K_5) => L_4, lm: (_: L_4) => M_3, mn: (_: M_3) => N_2, no: (_: N_2) => O_1, op: (_: O_1) => P): P;
597
+ pipe<A, B_15 = never, C_14 = never, D_13 = never, E_13 = never, F_11 = never, G_10 = never, H_9 = never, I_8 = never, J_7 = never, K_6 = never, L_5 = never, M_4 = never, N_3 = never, O_2 = never, P_1 = never, Q = never>(this: A, ab: (_: A) => B_15, bc: (_: B_15) => C_14, cd: (_: C_14) => D_13, de: (_: D_13) => E_13, ef: (_: E_13) => F_11, fg: (_: F_11) => G_10, gh: (_: G_10) => H_9, hi: (_: H_9) => I_8, ij: (_: I_8) => J_7, jk: (_: J_7) => K_6, kl: (_: K_6) => L_5, lm: (_: L_5) => M_4, mn: (_: M_4) => N_3, no: (_: N_3) => O_2, op: (_: O_2) => P_1, pq: (_: P_1) => Q): Q;
598
+ pipe<A, B_16 = never, C_15 = never, D_14 = never, E_14 = never, F_12 = never, G_11 = never, H_10 = never, I_9 = never, J_8 = never, K_7 = never, L_6 = never, M_5 = never, N_4 = never, O_3 = never, P_2 = never, Q_1 = never, R_1 = never>(this: A, ab: (_: A) => B_16, bc: (_: B_16) => C_15, cd: (_: C_15) => D_14, de: (_: D_14) => E_14, ef: (_: E_14) => F_12, fg: (_: F_12) => G_11, gh: (_: G_11) => H_10, hi: (_: H_10) => I_9, ij: (_: I_9) => J_8, jk: (_: J_8) => K_7, kl: (_: K_7) => L_6, lm: (_: L_6) => M_5, mn: (_: M_5) => N_4, no: (_: N_4) => O_3, op: (_: O_3) => P_2, pq: (_: P_2) => Q_1, qr: (_: Q_1) => R_1): R_1;
599
+ pipe<A, B_17 = never, C_16 = never, D_15 = never, E_15 = never, F_13 = never, G_12 = never, H_11 = never, I_10 = never, J_9 = never, K_8 = never, L_7 = never, M_6 = never, N_5 = never, O_4 = never, P_3 = never, Q_2 = never, R_2 = never, S = never>(this: A, ab: (_: A) => B_17, bc: (_: B_17) => C_16, cd: (_: C_16) => D_15, de: (_: D_15) => E_15, ef: (_: E_15) => F_13, fg: (_: F_13) => G_12, gh: (_: G_12) => H_11, hi: (_: H_11) => I_10, ij: (_: I_10) => J_9, jk: (_: J_9) => K_8, kl: (_: K_8) => L_7, lm: (_: L_7) => M_6, mn: (_: M_6) => N_5, no: (_: N_5) => O_4, op: (_: O_4) => P_3, pq: (_: P_3) => Q_2, qr: (_: Q_2) => R_2, rs: (_: R_2) => S): S;
600
+ pipe<A, B_18 = never, C_17 = never, D_16 = never, E_16 = never, F_14 = never, G_13 = never, H_12 = never, I_11 = never, J_10 = never, K_9 = never, L_8 = never, M_7 = never, N_6 = never, O_5 = never, P_4 = never, Q_3 = never, R_3 = never, S_1 = never, T = never>(this: A, ab: (_: A) => B_18, bc: (_: B_18) => C_17, cd: (_: C_17) => D_16, de: (_: D_16) => E_16, ef: (_: E_16) => F_14, fg: (_: F_14) => G_13, gh: (_: G_13) => H_12, hi: (_: H_12) => I_11, ij: (_: I_11) => J_10, jk: (_: J_10) => K_9, kl: (_: K_9) => L_8, lm: (_: L_8) => M_7, mn: (_: M_7) => N_6, no: (_: N_6) => O_5, op: (_: O_5) => P_4, pq: (_: P_4) => Q_3, qr: (_: Q_3) => R_3, rs: (_: R_3) => S_1, st: (_: S_1) => T): T;
601
+ pipe<A, B_19 = never, C_18 = never, D_17 = never, E_17 = never, F_15 = never, G_14 = never, H_13 = never, I_12 = never, J_11 = never, K_10 = never, L_9 = never, M_8 = never, N_7 = never, O_6 = never, P_5 = never, Q_4 = never, R_4 = never, S_2 = never, T_1 = never, U = never>(this: A, ab: (_: A) => B_19, bc: (_: B_19) => C_18, cd: (_: C_18) => D_17, de: (_: D_17) => E_17, ef: (_: E_17) => F_15, fg: (_: F_15) => G_14, gh: (_: G_14) => H_13, hi: (_: H_13) => I_12, ij: (_: I_12) => J_11, jk: (_: J_11) => K_10, kl: (_: K_10) => L_9, lm: (_: L_9) => M_8, mn: (_: M_8) => N_7, no: (_: N_7) => O_6, op: (_: O_6) => P_5, pq: (_: P_5) => Q_4, qr: (_: Q_4) => R_4, rs: (_: R_4) => S_2, st: (_: S_2) => T_1, tu: (_: T_1) => U): U;
602
+ pipe<A, B_20 = never, C_19 = never, D_18 = never, E_18 = never, F_16 = never, G_15 = never, H_14 = never, I_13 = never, J_12 = never, K_11 = never, L_10 = never, M_9 = never, N_8 = never, O_7 = never, P_6 = never, Q_5 = never, R_5 = never, S_3 = never, T_2 = never, U_1 = never>(this: A, ab: (_: A) => B_20, bc: (_: B_20) => C_19, cd: (_: C_19) => D_18, de: (_: D_18) => E_18, ef: (_: E_18) => F_16, fg: (_: F_16) => G_15, gh: (_: G_15) => H_14, hi: (_: H_14) => I_13, ij: (_: I_13) => J_12, jk: (_: J_12) => K_11, kl: (_: K_11) => L_10, lm: (_: L_10) => M_9, mn: (_: M_9) => N_8, no: (_: N_8) => O_7, op: (_: O_7) => P_6, pq: (_: P_6) => Q_5, qr: (_: Q_5) => R_5, rs: (_: R_5) => S_3, st: (_: S_3) => T_2, tu: (_: T_2) => U_1): U_1;
603
+ /** The name, input and options the form was made from: what a pipe step makes the next form from. */
604
+ name: Name;
605
+ options: FormOptions<Fields, Members, R, Nest>;
606
+ /** Type-only: the form's type parameters, for a pipe step to read. Never set. */
607
+ types: {
608
+ readonly Name: Name;
609
+ readonly E: E;
610
+ readonly Fields: Fields;
611
+ readonly Members: Members;
612
+ readonly R: R;
613
+ readonly Nest: Nest;
614
+ };
615
+ };
616
+ /**
617
+ * Entity metadata: the label of a member that has no schema to annotate (a
618
+ * relation, a derived member). A field is labelled on its schema, with
619
+ * `Schema.String.annotate({ title })`.
620
+ */
621
+ label: (label: string, description?: string) => Metadata;
622
+ /**
623
+ * What `Form.label` attached to an Entity member, for a package that labels
624
+ * the same member elsewhere, such as a table column.
625
+ */
626
+ labelOf: (member: {
627
+ readonly metadata: Metadata;
628
+ }) => string | undefined;
629
+ };
630
+ /** The type parameters a form was made with. */
631
+ interface FormTypes {
632
+ readonly Name: string;
633
+ readonly E: AnyEntity;
634
+ readonly Fields: Schema.Struct.Fields;
635
+ readonly Members: any;
636
+ readonly R: unknown;
637
+ readonly Nest: any;
638
+ }
639
+ /** A form as a pipe step takes it: what it was made from, and its type parameters. */
640
+ interface Remakeable<T extends FormTypes = FormTypes> {
641
+ readonly name: string;
642
+ readonly input: EntityInput<any, any, any>;
643
+ readonly options: object;
644
+ readonly types: T;
645
+ }
646
+ /** The form `Form.make` gives for these type parameters. */
647
+ type Made<T extends FormTypes> = ReturnType<typeof Core.make<T['Name'], T['E'], T['Fields'], T['Members'], T['R'], T['Nest']>>;
648
+ type OptionsOf<T extends FormTypes> = FormOptions<T['Fields'], T['Members'], T['R'], T['Nest']>;
173
649
  export declare const Form: {
650
+ /** Controls by key, beside the ones the form already names. */
651
+ inputs: <F extends Remakeable>(inputs: NonNullable<OptionsOf<F["types"]>["inputs"]>) => (form: F) => F;
652
+ /** The form's words, beside the ones it already has. */
653
+ messages: <F extends Remakeable>(messages: NonNullable<OptionsOf<F["types"]>["messages"]>) => (form: F) => F;
654
+ /** How long a key rests before its check runs. */
655
+ debounce: (debounce: Duration.Input) => <F extends Remakeable>(form: F) => F;
656
+ /**
657
+ * Checks by key, beside the ones the form already has. What they need (`R`) is
658
+ * added to what the form needs.
659
+ */
660
+ checks: <F extends Remakeable, const C extends ChecksFor<F>>(checks: C) => (form: F) => Made<{
661
+ readonly Name: F["types"]["Name"];
662
+ readonly E: F["types"]["E"];
663
+ readonly Fields: F["types"]["Fields"];
664
+ readonly Members: F["types"]["Members"];
665
+ readonly R: F["types"]["R"] | RequirementOf<C>;
666
+ readonly Nest: F["types"]["Nest"];
667
+ }>;
668
+ /** The forms of nested keys, beside the ones the form was already given. */
669
+ nested: <F extends Remakeable, const N extends NestedForms<F["types"]["Fields"], F["types"]["Members"], F["types"]["R"]>>(forms: N) => (form: F) => Made<{
670
+ readonly Name: F["types"]["Name"];
671
+ readonly E: F["types"]["E"];
672
+ readonly Fields: F["types"]["Fields"];
673
+ readonly Members: F["types"]["Members"];
674
+ readonly R: F["types"]["R"];
675
+ readonly Nest: F["types"]["Nest"] & N;
676
+ }>;
174
677
  /**
175
678
  * A form for one operation's input. A key mapped with `Relation.nested` holds
176
679
  * rows of a form of its own, built here from the nested input; every other key
177
680
  * holds a draft. `options` names what the input cannot say: a control, the
178
681
  * words, the checks.
179
682
  */
180
- make: <const Name extends string, E extends AnyEntity, Fields extends Schema.Struct.Fields, Members extends { readonly [K in keyof Fields]: InputMember; }, R = never>(name: Name, input: EntityInput<E, Fields, Members>, options?: FormOptions<Fields, Members, R>) => {
683
+ make: <const Name extends string, E extends AnyEntity, Fields extends Schema.Struct.Fields, Members extends { readonly [K in keyof Fields]: InputMember; }, R = never, const Nest extends NestedForms<Fields, Members, R> = {}>(name: Name, input: EntityInput<E, Fields, Members>, options?: FormOptions<Fields, Members, R, Nest>) => {
181
684
  bundle: Bundle.Bundle<Name, void, FormModel<Fields, Members>, {
182
685
  readonly _tag: "Changed";
183
686
  readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
@@ -194,6 +697,19 @@ export declare const Form: {
194
697
  readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
195
698
  readonly draft: string | boolean | readonly string[];
196
699
  readonly error: string | null;
700
+ } | {
701
+ readonly _tag: "Refused";
702
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
703
+ readonly error: string;
704
+ } | {
705
+ readonly _tag: "About";
706
+ readonly subject: {
707
+ readonly [x: string]: string;
708
+ };
709
+ } | {
710
+ readonly _tag: "Searched";
711
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
712
+ readonly text: string;
197
713
  } | {
198
714
  readonly _tag: "Nested";
199
715
  readonly key: string;
@@ -228,6 +744,30 @@ export declare const Form: {
228
744
  readonly draft: Schema.Union<readonly [Schema.String, Schema.Boolean, Schema.$Array<Schema.String>]>;
229
745
  readonly error: Schema.NullOr<Schema.String>;
230
746
  };
747
+ /**
748
+ * The outside world refused this key's value: a unique index, a rule only a
749
+ * server knows. The key reads invalid with that reason, keeping what was
750
+ * typed, until it is edited again. Unlike `Checked`, it answers no question
751
+ * the form asked, so it lands whatever state the key is in.
752
+ */
753
+ readonly Refused: {
754
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
755
+ readonly error: Schema.String;
756
+ };
757
+ /**
758
+ * What the form is editing, for the checks that need to know: a post's own
759
+ * row id, so "is this address taken?" can pass over the post's own address.
760
+ * It changes no draft and validates nothing; a form that creates something
761
+ * never sends it. See `FormModel.subject`.
762
+ */
763
+ readonly About: {
764
+ readonly subject: Schema.$Record<Schema.String, Schema.String>;
765
+ };
766
+ /** What was typed to find a choice for a relation key. It changes no draft and validates nothing. */
767
+ readonly Searched: {
768
+ readonly key: Schema.Literals<readonly [Exclude<keyof Fields & string, NestedKey<Members>>, ...Exclude<keyof Fields & string, NestedKey<Members>>[]]>;
769
+ readonly text: Schema.String;
770
+ };
231
771
  /** A Message of the nested form in one row of a nested key. One that row does not take is dropped. */
232
772
  readonly Nested: {
233
773
  readonly key: Schema.String;
@@ -260,6 +800,66 @@ export declare const Form: {
260
800
  * nested key has rows and no draft.
261
801
  */
262
802
  field: (model: FormModel<Fields, Members>, key: Exclude<keyof Fields & string, NestedKey<Members>>) => FieldValidation.Field<Draft>;
803
+ /** What was typed to find a choice for a relation key that searches; `''` until something is. */
804
+ search: (model: FormModel<Fields, Members>, key: Exclude<keyof Fields & string, NestedKey<Members>>) => string;
805
+ /** What the form is editing; `{}` while it creates. See `FormModel.subject`. */
806
+ subject: (model: FormModel<Fields, Members>) => Readonly<Record<string, string>>;
807
+ /**
808
+ * The form of each nested key, typed when it was given under `nested`: its
809
+ * `controls`, its `field`, its Messages.
810
+ */
811
+ nested: { readonly [K in Extract<keyof Fields & string, NestedKey<Members>>]: K extends keyof Nest ? NonNullable<Nest[K]> : NestedForm; };
812
+ /**
813
+ * One row of a nested key, addressed: `form.row('author', id).Changed({ key: 'name', value })`
814
+ * is this form's Message for that edit in that row.
815
+ */
816
+ row: <K extends Extract<keyof Fields & string, NestedKey<Members>>>(key: K, row: string) => RowHandle<K extends keyof Nest ? NonNullable<Nest[K]> : NestedForm, {
817
+ readonly _tag: "Changed";
818
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
819
+ readonly value: string | boolean | readonly string[];
820
+ } | {
821
+ readonly _tag: "Blurred";
822
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
823
+ } | {
824
+ readonly _tag: "Submitted";
825
+ } | {
826
+ readonly _tag: "Reset";
827
+ } | {
828
+ readonly _tag: "Checked";
829
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
830
+ readonly draft: string | boolean | readonly string[];
831
+ readonly error: string | null;
832
+ } | {
833
+ readonly _tag: "Refused";
834
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
835
+ readonly error: string;
836
+ } | {
837
+ readonly _tag: "About";
838
+ readonly subject: {
839
+ readonly [x: string]: string;
840
+ };
841
+ } | {
842
+ readonly _tag: "Searched";
843
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
844
+ readonly text: string;
845
+ } | {
846
+ readonly _tag: "Nested";
847
+ readonly key: string;
848
+ readonly row: string;
849
+ readonly message: unknown;
850
+ } | {
851
+ readonly _tag: "RowAdded";
852
+ readonly key: string;
853
+ } | {
854
+ readonly _tag: "RowRemoved";
855
+ readonly key: string;
856
+ readonly row: string;
857
+ }>;
858
+ /**
859
+ * Whether a key that follows another still does: `false` once the author has
860
+ * written it themselves. A view offers "regenerate" by sending the key an empty draft.
861
+ */
862
+ isFollowing: (model: FormModel<Fields, Members>, key: Exclude<keyof Fields & string, NestedKey<Members>>) => boolean;
263
863
  /** The rows of a nested key, each a Model of `control.form`. */
264
864
  rows: (model: FormModel<Fields, Members>, key: Extract<keyof Fields & string, NestedKey<Members>>) => { readonly [K in keyof Fields as K extends NestedKey<Members> ? K : never]: readonly FormRow<NestedModel<Members[K & keyof Members]>>[]; }[Extract<keyof Fields & string, NestedKey<Members>>];
265
865
  /**
@@ -267,6 +867,18 @@ export declare const Form: {
267
867
  * running does not stop it; the submit waits for the answer.
268
868
  */
269
869
  canSubmit: (model: FormModel<Fields, Members>) => boolean;
870
+ /**
871
+ * The Model with nothing in flight, for one that was stored and is shown
872
+ * again: a check that was running when it was stored will never answer, so
873
+ * its key is not validated yet, and no submit is waiting. Rows too.
874
+ */
875
+ settled: (model: FormModel<Fields, Members>) => FormModel<Fields, Members>;
876
+ /**
877
+ * What of the form decodes as it stands, by key: the value, less every key
878
+ * that is not valid yet. For saving unfinished work, which `engine.value`
879
+ * cannot give. A nested key is there once each of its rows has a value.
880
+ */
881
+ partial: (model: FormModel<Fields, Members>) => Partial<Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>>>;
270
882
  /** The form as the form that nests it drives it. */
271
883
  engine: {
272
884
  submit: (model: FormModel<Fields, Members>) => {
@@ -291,6 +903,19 @@ export declare const Form: {
291
903
  readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
292
904
  readonly draft: string | boolean | readonly string[];
293
905
  readonly error: string | null;
906
+ } | {
907
+ readonly _tag: "Refused";
908
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
909
+ readonly error: string;
910
+ } | {
911
+ readonly _tag: "About";
912
+ readonly subject: {
913
+ readonly [x: string]: string;
914
+ };
915
+ } | {
916
+ readonly _tag: "Searched";
917
+ readonly key: Exclude<keyof Fields & string, NestedKey<Members>>;
918
+ readonly text: string;
294
919
  } | {
295
920
  readonly _tag: "Nested";
296
921
  readonly key: string;
@@ -310,6 +935,40 @@ export declare const Form: {
310
935
  /** The decoded input when every key and row is valid as it stands; validates nothing. */
311
936
  value: (model: FormModel<Fields, Members>) => Schema.Struct.View<Fields, "Type", Schema.Struct.TypeOptionalKeys<Fields>, Schema.Struct.TypeMutableKeys<Fields>> | undefined;
312
937
  };
938
+ pipe<A>(this: A): A;
939
+ pipe<A, B = never>(this: A, ab: (_: A) => B): B;
940
+ pipe<A, B_1 = never, C = never>(this: A, ab: (_: A) => B_1, bc: (_: B_1) => C): C;
941
+ pipe<A, B_2 = never, C_1 = never, D = never>(this: A, ab: (_: A) => B_2, bc: (_: B_2) => C_1, cd: (_: C_1) => D): D;
942
+ pipe<A, B_3 = never, C_2 = never, D_1 = never, E_1 = never>(this: A, ab: (_: A) => B_3, bc: (_: B_3) => C_2, cd: (_: C_2) => D_1, de: (_: D_1) => E_1): E_1;
943
+ pipe<A, B_4 = never, C_3 = never, D_2 = never, E_2 = never, F = never>(this: A, ab: (_: A) => B_4, bc: (_: B_4) => C_3, cd: (_: C_3) => D_2, de: (_: D_2) => E_2, ef: (_: E_2) => F): F;
944
+ pipe<A, B_5 = never, C_4 = never, D_3 = never, E_3 = never, F_1 = never, G = never>(this: A, ab: (_: A) => B_5, bc: (_: B_5) => C_4, cd: (_: C_4) => D_3, de: (_: D_3) => E_3, ef: (_: E_3) => F_1, fg: (_: F_1) => G): G;
945
+ pipe<A, B_6 = never, C_5 = never, D_4 = never, E_4 = never, F_2 = never, G_1 = never, H = never>(this: A, ab: (_: A) => B_6, bc: (_: B_6) => C_5, cd: (_: C_5) => D_4, de: (_: D_4) => E_4, ef: (_: E_4) => F_2, fg: (_: F_2) => G_1, gh: (_: G_1) => H): H;
946
+ pipe<A, B_7 = never, C_6 = never, D_5 = never, E_5 = never, F_3 = never, G_2 = never, H_1 = never, I = never>(this: A, ab: (_: A) => B_7, bc: (_: B_7) => C_6, cd: (_: C_6) => D_5, de: (_: D_5) => E_5, ef: (_: E_5) => F_3, fg: (_: F_3) => G_2, gh: (_: G_2) => H_1, hi: (_: H_1) => I): I;
947
+ pipe<A, B_8 = never, C_7 = never, D_6 = never, E_6 = never, F_4 = never, G_3 = never, H_2 = never, I_1 = never, J = never>(this: A, ab: (_: A) => B_8, bc: (_: B_8) => C_7, cd: (_: C_7) => D_6, de: (_: D_6) => E_6, ef: (_: E_6) => F_4, fg: (_: F_4) => G_3, gh: (_: G_3) => H_2, hi: (_: H_2) => I_1, ij: (_: I_1) => J): J;
948
+ pipe<A, B_9 = never, C_8 = never, D_7 = never, E_7 = never, F_5 = never, G_4 = never, H_3 = never, I_2 = never, J_1 = never, K = never>(this: A, ab: (_: A) => B_9, bc: (_: B_9) => C_8, cd: (_: C_8) => D_7, de: (_: D_7) => E_7, ef: (_: E_7) => F_5, fg: (_: F_5) => G_4, gh: (_: G_4) => H_3, hi: (_: H_3) => I_2, ij: (_: I_2) => J_1, jk: (_: J_1) => K): K;
949
+ pipe<A, B_10 = never, C_9 = never, D_8 = never, E_8 = never, F_6 = never, G_5 = never, H_4 = never, I_3 = never, J_2 = never, K_1 = never, L = never>(this: A, ab: (_: A) => B_10, bc: (_: B_10) => C_9, cd: (_: C_9) => D_8, de: (_: D_8) => E_8, ef: (_: E_8) => F_6, fg: (_: F_6) => G_5, gh: (_: G_5) => H_4, hi: (_: H_4) => I_3, ij: (_: I_3) => J_2, jk: (_: J_2) => K_1, kl: (_: K_1) => L): L;
950
+ pipe<A, B_11 = never, C_10 = never, D_9 = never, E_9 = never, F_7 = never, G_6 = never, H_5 = never, I_4 = never, J_3 = never, K_2 = never, L_1 = never, M = never>(this: A, ab: (_: A) => B_11, bc: (_: B_11) => C_10, cd: (_: C_10) => D_9, de: (_: D_9) => E_9, ef: (_: E_9) => F_7, fg: (_: F_7) => G_6, gh: (_: G_6) => H_5, hi: (_: H_5) => I_4, ij: (_: I_4) => J_3, jk: (_: J_3) => K_2, kl: (_: K_2) => L_1, lm: (_: L_1) => M): M;
951
+ pipe<A, B_12 = never, C_11 = never, D_10 = never, E_10 = never, F_8 = never, G_7 = never, H_6 = never, I_5 = never, J_4 = never, K_3 = never, L_2 = never, M_1 = never, N = never>(this: A, ab: (_: A) => B_12, bc: (_: B_12) => C_11, cd: (_: C_11) => D_10, de: (_: D_10) => E_10, ef: (_: E_10) => F_8, fg: (_: F_8) => G_7, gh: (_: G_7) => H_6, hi: (_: H_6) => I_5, ij: (_: I_5) => J_4, jk: (_: J_4) => K_3, kl: (_: K_3) => L_2, lm: (_: L_2) => M_1, mn: (_: M_1) => N): N;
952
+ pipe<A, B_13 = never, C_12 = never, D_11 = never, E_11 = never, F_9 = never, G_8 = never, H_7 = never, I_6 = never, J_5 = never, K_4 = never, L_3 = never, M_2 = never, N_1 = never, O = never>(this: A, ab: (_: A) => B_13, bc: (_: B_13) => C_12, cd: (_: C_12) => D_11, de: (_: D_11) => E_11, ef: (_: E_11) => F_9, fg: (_: F_9) => G_8, gh: (_: G_8) => H_7, hi: (_: H_7) => I_6, ij: (_: I_6) => J_5, jk: (_: J_5) => K_4, kl: (_: K_4) => L_3, lm: (_: L_3) => M_2, mn: (_: M_2) => N_1, no: (_: N_1) => O): O;
953
+ pipe<A, B_14 = never, C_13 = never, D_12 = never, E_12 = never, F_10 = never, G_9 = never, H_8 = never, I_7 = never, J_6 = never, K_5 = never, L_4 = never, M_3 = never, N_2 = never, O_1 = never, P = never>(this: A, ab: (_: A) => B_14, bc: (_: B_14) => C_13, cd: (_: C_13) => D_12, de: (_: D_12) => E_12, ef: (_: E_12) => F_10, fg: (_: F_10) => G_9, gh: (_: G_9) => H_8, hi: (_: H_8) => I_7, ij: (_: I_7) => J_6, jk: (_: J_6) => K_5, kl: (_: K_5) => L_4, lm: (_: L_4) => M_3, mn: (_: M_3) => N_2, no: (_: N_2) => O_1, op: (_: O_1) => P): P;
954
+ pipe<A, B_15 = never, C_14 = never, D_13 = never, E_13 = never, F_11 = never, G_10 = never, H_9 = never, I_8 = never, J_7 = never, K_6 = never, L_5 = never, M_4 = never, N_3 = never, O_2 = never, P_1 = never, Q = never>(this: A, ab: (_: A) => B_15, bc: (_: B_15) => C_14, cd: (_: C_14) => D_13, de: (_: D_13) => E_13, ef: (_: E_13) => F_11, fg: (_: F_11) => G_10, gh: (_: G_10) => H_9, hi: (_: H_9) => I_8, ij: (_: I_8) => J_7, jk: (_: J_7) => K_6, kl: (_: K_6) => L_5, lm: (_: L_5) => M_4, mn: (_: M_4) => N_3, no: (_: N_3) => O_2, op: (_: O_2) => P_1, pq: (_: P_1) => Q): Q;
955
+ pipe<A, B_16 = never, C_15 = never, D_14 = never, E_14 = never, F_12 = never, G_11 = never, H_10 = never, I_9 = never, J_8 = never, K_7 = never, L_6 = never, M_5 = never, N_4 = never, O_3 = never, P_2 = never, Q_1 = never, R_1 = never>(this: A, ab: (_: A) => B_16, bc: (_: B_16) => C_15, cd: (_: C_15) => D_14, de: (_: D_14) => E_14, ef: (_: E_14) => F_12, fg: (_: F_12) => G_11, gh: (_: G_11) => H_10, hi: (_: H_10) => I_9, ij: (_: I_9) => J_8, jk: (_: J_8) => K_7, kl: (_: K_7) => L_6, lm: (_: L_6) => M_5, mn: (_: M_5) => N_4, no: (_: N_4) => O_3, op: (_: O_3) => P_2, pq: (_: P_2) => Q_1, qr: (_: Q_1) => R_1): R_1;
956
+ pipe<A, B_17 = never, C_16 = never, D_15 = never, E_15 = never, F_13 = never, G_12 = never, H_11 = never, I_10 = never, J_9 = never, K_8 = never, L_7 = never, M_6 = never, N_5 = never, O_4 = never, P_3 = never, Q_2 = never, R_2 = never, S = never>(this: A, ab: (_: A) => B_17, bc: (_: B_17) => C_16, cd: (_: C_16) => D_15, de: (_: D_15) => E_15, ef: (_: E_15) => F_13, fg: (_: F_13) => G_12, gh: (_: G_12) => H_11, hi: (_: H_11) => I_10, ij: (_: I_10) => J_9, jk: (_: J_9) => K_8, kl: (_: K_8) => L_7, lm: (_: L_7) => M_6, mn: (_: M_6) => N_5, no: (_: N_5) => O_4, op: (_: O_4) => P_3, pq: (_: P_3) => Q_2, qr: (_: Q_2) => R_2, rs: (_: R_2) => S): S;
957
+ pipe<A, B_18 = never, C_17 = never, D_16 = never, E_16 = never, F_14 = never, G_13 = never, H_12 = never, I_11 = never, J_10 = never, K_9 = never, L_8 = never, M_7 = never, N_6 = never, O_5 = never, P_4 = never, Q_3 = never, R_3 = never, S_1 = never, T = never>(this: A, ab: (_: A) => B_18, bc: (_: B_18) => C_17, cd: (_: C_17) => D_16, de: (_: D_16) => E_16, ef: (_: E_16) => F_14, fg: (_: F_14) => G_13, gh: (_: G_13) => H_12, hi: (_: H_12) => I_11, ij: (_: I_11) => J_10, jk: (_: J_10) => K_9, kl: (_: K_9) => L_8, lm: (_: L_8) => M_7, mn: (_: M_7) => N_6, no: (_: N_6) => O_5, op: (_: O_5) => P_4, pq: (_: P_4) => Q_3, qr: (_: Q_3) => R_3, rs: (_: R_3) => S_1, st: (_: S_1) => T): T;
958
+ pipe<A, B_19 = never, C_18 = never, D_17 = never, E_17 = never, F_15 = never, G_14 = never, H_13 = never, I_12 = never, J_11 = never, K_10 = never, L_9 = never, M_8 = never, N_7 = never, O_6 = never, P_5 = never, Q_4 = never, R_4 = never, S_2 = never, T_1 = never, U = never>(this: A, ab: (_: A) => B_19, bc: (_: B_19) => C_18, cd: (_: C_18) => D_17, de: (_: D_17) => E_17, ef: (_: E_17) => F_15, fg: (_: F_15) => G_14, gh: (_: G_14) => H_13, hi: (_: H_13) => I_12, ij: (_: I_12) => J_11, jk: (_: J_11) => K_10, kl: (_: K_10) => L_9, lm: (_: L_9) => M_8, mn: (_: M_8) => N_7, no: (_: N_7) => O_6, op: (_: O_6) => P_5, pq: (_: P_5) => Q_4, qr: (_: Q_4) => R_4, rs: (_: R_4) => S_2, st: (_: S_2) => T_1, tu: (_: T_1) => U): U;
959
+ pipe<A, B_20 = never, C_19 = never, D_18 = never, E_18 = never, F_16 = never, G_15 = never, H_14 = never, I_13 = never, J_12 = never, K_11 = never, L_10 = never, M_9 = never, N_8 = never, O_7 = never, P_6 = never, Q_5 = never, R_5 = never, S_3 = never, T_2 = never, U_1 = never>(this: A, ab: (_: A) => B_20, bc: (_: B_20) => C_19, cd: (_: C_19) => D_18, de: (_: D_18) => E_18, ef: (_: E_18) => F_16, fg: (_: F_16) => G_15, gh: (_: G_15) => H_14, hi: (_: H_14) => I_13, ij: (_: I_13) => J_12, jk: (_: J_12) => K_11, kl: (_: K_11) => L_10, lm: (_: L_10) => M_9, mn: (_: M_9) => N_8, no: (_: N_8) => O_7, op: (_: O_7) => P_6, pq: (_: P_6) => Q_5, qr: (_: Q_5) => R_5, rs: (_: R_5) => S_3, st: (_: S_3) => T_2, tu: (_: T_2) => U_1): U_1;
960
+ /** The name, input and options the form was made from: what a pipe step makes the next form from. */
961
+ name: Name;
962
+ options: FormOptions<Fields, Members, R, Nest>;
963
+ /** Type-only: the form's type parameters, for a pipe step to read. Never set. */
964
+ types: {
965
+ readonly Name: Name;
966
+ readonly E: E;
967
+ readonly Fields: Fields;
968
+ readonly Members: Members;
969
+ readonly R: R;
970
+ readonly Nest: Nest;
971
+ };
313
972
  };
314
973
  /**
315
974
  * Entity metadata: the label of a member that has no schema to annotate (a
@@ -326,5 +985,5 @@ export declare const Form: {
326
985
  }) => string | undefined;
327
986
  };
328
987
  //#endregion
329
- export type { Control, Draft, FormRow, NestedForm };
988
+ export type { Control, ControlChange, ControlKind, Draft, DraftKind, Follows, FormRow, NestedData, NestedForm, RelationData };
330
989
  //# sourceMappingURL=index.d.mts.map