@orkestrel/form 0.0.4 → 0.0.5
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/README.md +13 -13
- package/dist/src/core/index.cjs +284 -338
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +255 -168
- package/dist/src/core/index.d.ts +255 -168
- package/dist/src/core/index.js +281 -340
- package/dist/src/core/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -4,11 +4,11 @@ import { EmitterInterface } from '@orkestrel/emitter';
|
|
|
4
4
|
import { JSONRecord } from '@orkestrel/contract';
|
|
5
5
|
import { Result } from '@orkestrel/contract';
|
|
6
6
|
|
|
7
|
-
/**
|
|
7
|
+
/** Matches one or more ASCII letters or digits. */
|
|
8
8
|
export declare const ALPHANUMERIC_PATTERN: Readonly<RegExp>;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Checks whether a named rule applies to one field control.
|
|
12
12
|
*
|
|
13
13
|
* @remarks
|
|
14
14
|
* The runtime control-membership check keeps this boundary total for JavaScript callers that
|
|
@@ -16,12 +16,12 @@ export declare const ALPHANUMERIC_PATTERN: Readonly<RegExp>;
|
|
|
16
16
|
*
|
|
17
17
|
* @param control - The field control to inspect.
|
|
18
18
|
* @param rule - The named rule to inspect.
|
|
19
|
-
* @returns
|
|
19
|
+
* @returns True if the control evaluates that rule; false otherwise.
|
|
20
20
|
*/
|
|
21
21
|
export declare function appliesRule(control: FieldControl, rule: FieldRuleName): boolean;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Audits a structurally valid schema for domain invariants.
|
|
25
25
|
*
|
|
26
26
|
* @param schema - The form schema to audit.
|
|
27
27
|
* @returns Human-readable invariant violations, or an empty list when the schema is sound.
|
|
@@ -29,7 +29,7 @@ export declare function appliesRule(control: FieldControl, rule: FieldRuleName):
|
|
|
29
29
|
export declare function auditSchema(schema: FormSchema): readonly string[];
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Represents any number of choices out of a list, holding the checked values.
|
|
33
33
|
*
|
|
34
34
|
* @remarks
|
|
35
35
|
* A field offering one box that means yes or no is a {@link ConfirmField}, not a one-choice
|
|
@@ -41,11 +41,11 @@ export declare interface CheckboxField extends FieldBase {
|
|
|
41
41
|
readonly default?: readonly string[];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/**
|
|
44
|
+
/** Caps the number of choices one `select` or `checkbox` field may offer. */
|
|
45
45
|
export declare const CHOICE_LIMIT = 1024;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Clones a field's choices into an owned frozen snapshot.
|
|
49
49
|
*
|
|
50
50
|
* @param choices - The choices to own.
|
|
51
51
|
* @returns A frozen list of frozen choice records.
|
|
@@ -53,7 +53,7 @@ export declare const CHOICE_LIMIT = 1024;
|
|
|
53
53
|
export declare function cloneChoices(choices: readonly FieldChoice[]): readonly FieldChoice[];
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* Clones one form field into an owned frozen snapshot.
|
|
57
57
|
*
|
|
58
58
|
* @param field - The field to own.
|
|
59
59
|
* @returns A frozen field with every nested collection owned.
|
|
@@ -62,7 +62,7 @@ export declare function cloneChoices(choices: readonly FieldChoice[]): readonly
|
|
|
62
62
|
export declare function cloneFormField(field: FormField): FormField;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Clones a form schema into an owned frozen snapshot.
|
|
66
66
|
*
|
|
67
67
|
* @param schema - The schema to own.
|
|
68
68
|
* @returns A frozen schema with every nested record and list owned.
|
|
@@ -70,7 +70,7 @@ export declare function cloneFormField(field: FormField): FormField;
|
|
|
70
70
|
export declare function cloneFormSchema(schema: FormSchema): FormSchema;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Clones one form value into an owned frozen snapshot.
|
|
74
74
|
*
|
|
75
75
|
* @param value - The field value to own.
|
|
76
76
|
* @returns The scalar unchanged, or a frozen copy of the list.
|
|
@@ -79,31 +79,53 @@ export declare function cloneValue(value: readonly string[]): readonly string[];
|
|
|
79
79
|
|
|
80
80
|
export declare function cloneValue(value: FieldValue): FieldValue;
|
|
81
81
|
|
|
82
|
-
/**
|
|
82
|
+
/** Matches a six-digit hexadecimal color string. */
|
|
83
83
|
export declare const COLOR_PATTERN: Readonly<RegExp>;
|
|
84
84
|
|
|
85
|
-
/**
|
|
85
|
+
/** Represents a color, held as the control's own string. */
|
|
86
86
|
export declare interface ColorField extends FieldBase {
|
|
87
87
|
readonly control: 'color';
|
|
88
88
|
readonly default?: string;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* Computes the values explicitly seeded by a schema.
|
|
93
93
|
*
|
|
94
94
|
* @param schema - The schema whose defaults to collect.
|
|
95
95
|
* @returns A value record containing only fields with defaults.
|
|
96
96
|
*/
|
|
97
97
|
export declare function computeDefaults(schema: FormSchema): FormValues;
|
|
98
98
|
|
|
99
|
-
/**
|
|
99
|
+
/** Represents a single on/off box, holding a boolean. */
|
|
100
100
|
export declare interface ConfirmField extends FieldBase {
|
|
101
101
|
readonly control: 'confirm';
|
|
102
102
|
readonly default?: boolean;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Creates one named-rule failure against a field.
|
|
107
|
+
*
|
|
108
|
+
* @param field - The field the rule failed on.
|
|
109
|
+
* @param rule - The named rule that failed.
|
|
110
|
+
* @param limit - The rule's operand, substituted for `{limit}`, or absence when it carries none.
|
|
111
|
+
* @param messages - Optional rule-specific message replacements.
|
|
112
|
+
* @returns A frozen {@link FieldError} carrying the field's name, the resolved text, and the rule.
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* A `custom` validator and the form's `invalidate` method both report a message of their own
|
|
116
|
+
* under no rule name, so neither builds its failure here.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const field: FormField = { control: 'text', name: 'nickname', rule: { minimum: 3 } }
|
|
121
|
+
* const error = createFieldError(field, 'minimum', 3)
|
|
122
|
+
* error.message // 'Must be at least 3'
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function createFieldError(field: FormField, rule: FieldRuleName, limit: number | string | undefined, messages?: Readonly<Partial<Record<FieldRuleName, string>>>): FieldError;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Opens a form against a schema.
|
|
107
129
|
*
|
|
108
130
|
* @param schema - The form to ask. It is copied, and the copy is what the form asks.
|
|
109
131
|
* @param options - The form's settings.
|
|
@@ -130,59 +152,83 @@ export declare interface ConfirmField extends FieldBase {
|
|
|
130
152
|
*/
|
|
131
153
|
export declare function createForm(schema: FormSchema, options?: FormOptions): FormInterface;
|
|
132
154
|
|
|
133
|
-
/**
|
|
155
|
+
/** Matches an ISO calendar date string in `YYYY-MM-DD` form. */
|
|
134
156
|
export declare const DATE_PATTERN: Readonly<RegExp>;
|
|
135
157
|
|
|
136
|
-
/**
|
|
158
|
+
/** Represents a calendar date, held as the control's own string. */
|
|
137
159
|
export declare interface DateField extends FieldBase {
|
|
138
160
|
readonly control: 'date';
|
|
139
161
|
readonly default?: string;
|
|
140
162
|
}
|
|
141
163
|
|
|
142
|
-
/**
|
|
164
|
+
/** Matches an ISO local date and time string with optional seconds. */
|
|
143
165
|
export declare const DATETIME_PATTERN: Readonly<RegExp>;
|
|
144
166
|
|
|
145
|
-
/**
|
|
167
|
+
/** Represents a date and a time of day together, with no zone, held as the control's own string. */
|
|
146
168
|
export declare interface DatetimeField extends FieldBase {
|
|
147
169
|
readonly control: 'datetime';
|
|
148
170
|
readonly default?: string;
|
|
149
171
|
}
|
|
150
172
|
|
|
151
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Writes one own enumerable data property onto a record.
|
|
175
|
+
*
|
|
176
|
+
* @param target - The record to write into.
|
|
177
|
+
* @param name - The property name to write.
|
|
178
|
+
* @param value - The value to store.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* Plain assignment runs an inherited setter, so writing a `__proto__` key that way reaches
|
|
182
|
+
* `Object.prototype` and leaves the record without the entry. Defining the property writes the
|
|
183
|
+
* record itself, whatever the prototype chain declares. The entry stays writable and configurable.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* const values: Record<string, number> = {}
|
|
188
|
+
* defineEntry(values, '__proto__', 1)
|
|
189
|
+
* Object.hasOwn(values, '__proto__') // true
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function defineEntry<T>(target: Record<string, T>, name: string, value: T): void;
|
|
193
|
+
|
|
194
|
+
/** Represents text over many lines. */
|
|
152
195
|
export declare interface EditorField extends FieldBase {
|
|
153
196
|
readonly control: 'editor';
|
|
154
197
|
readonly default?: string;
|
|
155
198
|
readonly placeholder?: string;
|
|
156
199
|
}
|
|
157
200
|
|
|
158
|
-
/**
|
|
201
|
+
/** Matches a practical whole-address email shape. */
|
|
159
202
|
export declare const EMAIL_PATTERN: Readonly<RegExp>;
|
|
160
203
|
|
|
161
204
|
/**
|
|
162
|
-
*
|
|
205
|
+
* Evaluates one field rule against its current value.
|
|
163
206
|
*
|
|
164
207
|
* @param field - The field and rule to evaluate.
|
|
165
208
|
* @param value - The current value, or absence.
|
|
166
209
|
* @param values - Every value available to a custom rule.
|
|
167
210
|
* @param messages - Optional rule-specific message replacements.
|
|
168
211
|
* @returns Every failure in rule order.
|
|
212
|
+
* @throws Thrown when a {@link FieldValidator} supplied through {@link FieldRule.custom} throws:
|
|
213
|
+
* its own value escapes unchanged, because this helper adds no boundary around it.
|
|
169
214
|
*/
|
|
170
215
|
export declare function evaluateField(field: FormField, value: FieldValue | undefined, values: FormValues, messages?: Readonly<Partial<Record<FieldRuleName, string>>>): readonly FieldError[];
|
|
171
216
|
|
|
172
217
|
/**
|
|
173
|
-
*
|
|
218
|
+
* Evaluates every active field in schema order.
|
|
174
219
|
*
|
|
175
220
|
* @param schema - The form schema to evaluate.
|
|
176
221
|
* @param values - The values keyed by field name.
|
|
177
222
|
* @param options - Optional message replacements and the effective disabled field set.
|
|
178
223
|
* @returns Every field failure in schema and rule order.
|
|
224
|
+
* @throws Thrown when a {@link FieldValidator} supplied through {@link FieldRule.custom} throws:
|
|
225
|
+
* its own value escapes unchanged, because this helper adds no boundary around it.
|
|
179
226
|
*/
|
|
180
227
|
export declare function evaluateForm(schema: FormSchema, values: FormValues, options?: EvaluationOptions): readonly FieldError[];
|
|
181
228
|
|
|
182
229
|
/**
|
|
183
|
-
*
|
|
230
|
+
* Describes how to check a schema against a set of answers.
|
|
184
231
|
*
|
|
185
|
-
* @param options - The evaluation's settings.
|
|
186
232
|
* @remarks
|
|
187
233
|
* `messages` replaces the default message of a rule, keyed by {@link FieldRuleName}.
|
|
188
234
|
*
|
|
@@ -205,40 +251,49 @@ export declare interface EvaluationOptions {
|
|
|
205
251
|
}
|
|
206
252
|
|
|
207
253
|
/**
|
|
208
|
-
*
|
|
254
|
+
* Extracts the names whose answers differ between two form value records.
|
|
209
255
|
*
|
|
210
256
|
* @remarks
|
|
211
257
|
* Presence is compared in both directions before present values are compared through
|
|
212
258
|
* {@link matchesValue}. The returned set is a new snapshot, exposed as readonly because later
|
|
213
259
|
* changes to either input never alter its membership.
|
|
214
260
|
*
|
|
215
|
-
* @param current - The values
|
|
261
|
+
* @param current - The values the form holds.
|
|
216
262
|
* @param opened - The values held when the form opened.
|
|
217
263
|
* @returns A readonly snapshot of changed field names.
|
|
218
264
|
*/
|
|
219
265
|
export declare function extractChanges(current: FormValues, opened: FormValues): ReadonlySet<string>;
|
|
220
266
|
|
|
221
267
|
/**
|
|
222
|
-
*
|
|
268
|
+
* Selects referenced groups in first-reference field order.
|
|
223
269
|
*
|
|
224
270
|
* @param schema - The schema whose group references to resolve.
|
|
225
271
|
* @returns The referenced schema groups without duplicates.
|
|
226
272
|
*/
|
|
227
273
|
export declare function extractGroups(schema: FormSchema): readonly FormGroup[];
|
|
228
274
|
|
|
229
|
-
/**
|
|
275
|
+
/** Lists the members every field declares, whatever its control. */
|
|
276
|
+
export declare const FIELD_BASE_KEYS: readonly string[];
|
|
277
|
+
|
|
278
|
+
/** Lists every field control, in the order declared by the public contract. */
|
|
230
279
|
export declare const FIELD_CONTROLS: readonly FieldControl[];
|
|
231
280
|
|
|
232
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* Lists every member one field control permits, composed from {@link FIELD_BASE_KEYS} and the
|
|
283
|
+
* members the control's own interface adds.
|
|
284
|
+
*/
|
|
285
|
+
export declare const FIELD_KEYS: Readonly<Record<FieldControl, readonly string[]>>;
|
|
286
|
+
|
|
287
|
+
/** Caps the number of fields one schema may declare. */
|
|
233
288
|
export declare const FIELD_LIMIT = 512;
|
|
234
289
|
|
|
235
290
|
/**
|
|
236
|
-
*
|
|
291
|
+
* Declares what every field carries, whatever its control.
|
|
237
292
|
*
|
|
238
293
|
* @remarks
|
|
239
294
|
* `name` keys the field in {@link FormValues} and `group` names a {@link FormGroup}.
|
|
240
295
|
*
|
|
241
|
-
*
|
|
296
|
+
* `hidden`, `locked`, and `disabled` differ in what they remove. `hidden` keeps the field out of
|
|
242
297
|
* the rendered form, `locked` renders it unwritable, and both are still validated and still
|
|
243
298
|
* submitted. `disabled` takes the field out of the form entirely: it is neither validated nor
|
|
244
299
|
* submitted. It is the field's declared, opening state; {@link FormInterface.disabled} is the
|
|
@@ -261,7 +316,7 @@ export declare interface FieldBase {
|
|
|
261
316
|
}
|
|
262
317
|
|
|
263
318
|
/**
|
|
264
|
-
*
|
|
319
|
+
* Represents one option a `select` or `checkbox` field offers.
|
|
265
320
|
*
|
|
266
321
|
* @remarks
|
|
267
322
|
* `value` is what the form stores and `label` is what the person reads. `help` explains the
|
|
@@ -276,16 +331,16 @@ export declare interface FieldChoice {
|
|
|
276
331
|
}
|
|
277
332
|
|
|
278
333
|
/**
|
|
279
|
-
*
|
|
334
|
+
* Names the control a field presents to the person answering it.
|
|
280
335
|
*
|
|
281
336
|
* @remarks
|
|
282
337
|
* The control is the discriminant of every {@link FormField} variant, so choosing it fixes
|
|
283
338
|
* which options that field accepts and which {@link FieldValue} it holds.
|
|
284
339
|
*
|
|
285
|
-
*
|
|
286
|
-
* a lone browser checkbox is a `confirm`. `checkbox` is the
|
|
287
|
-
* checked values as a list, never a single box. `datetime` is the
|
|
288
|
-
* a wall-clock date and time carrying no zone.
|
|
340
|
+
* The `confirm`, `checkbox`, and `datetime` members need saying out loud. `confirm` is a single
|
|
341
|
+
* on/off box holding a boolean, so a lone browser checkbox is a `confirm`. `checkbox` is the
|
|
342
|
+
* multi-choice group holding the checked values as a list, never a single box. `datetime` is the
|
|
343
|
+
* browser's `datetime-local`: a wall-clock date and time carrying no zone.
|
|
289
344
|
*
|
|
290
345
|
* @example
|
|
291
346
|
* ```ts
|
|
@@ -295,7 +350,7 @@ export declare interface FieldChoice {
|
|
|
295
350
|
export declare type FieldControl = 'text' | 'editor' | 'password' | 'number' | 'date' | 'time' | 'datetime' | 'color' | 'confirm' | 'select' | 'checkbox' | 'file';
|
|
296
351
|
|
|
297
352
|
/**
|
|
298
|
-
*
|
|
353
|
+
* Represents one failed check against one field.
|
|
299
354
|
*
|
|
300
355
|
* @remarks
|
|
301
356
|
* `rule` names the constraint that failed. It is absent when the message came from a
|
|
@@ -309,7 +364,7 @@ export declare interface FieldError {
|
|
|
309
364
|
}
|
|
310
365
|
|
|
311
366
|
/**
|
|
312
|
-
*
|
|
367
|
+
* Represents the constraints one field's value must satisfy.
|
|
313
368
|
*
|
|
314
369
|
* @remarks
|
|
315
370
|
* `minimum` and `maximum` measure whatever the control makes countable: characters for
|
|
@@ -340,7 +395,7 @@ export declare interface FieldRule {
|
|
|
340
395
|
}
|
|
341
396
|
|
|
342
397
|
/**
|
|
343
|
-
*
|
|
398
|
+
* Lists every rule that reports its failure by name.
|
|
344
399
|
*
|
|
345
400
|
* @remarks
|
|
346
401
|
* `custom` is excluded because it supplies its own message, so nothing keyed by a rule name
|
|
@@ -349,20 +404,21 @@ export declare interface FieldRule {
|
|
|
349
404
|
export declare type FieldRuleName = Exclude<keyof FieldRule, 'custom'>;
|
|
350
405
|
|
|
351
406
|
/**
|
|
352
|
-
*
|
|
407
|
+
* Checks one value against the whole form.
|
|
353
408
|
*
|
|
354
409
|
* @remarks
|
|
355
410
|
* It runs after every named rule, and it runs on an absent value as well as a present one. That
|
|
356
411
|
* is what makes a rule such as "required once the sibling says yes" expressible, and it means an
|
|
357
412
|
* unanswered field can carry both a `required` message and this validator's own.
|
|
358
413
|
*
|
|
359
|
-
* @param value - The value the field
|
|
414
|
+
* @param value - The value the field holds, or `undefined` when nobody has answered it.
|
|
360
415
|
* @param values - Every answer the form holds, so a rule can read its siblings.
|
|
361
416
|
* @returns `true` when the value passes, or the message explaining why it failed.
|
|
362
|
-
* @throws
|
|
363
|
-
* mutation has already changed state, the throw leaves those
|
|
364
|
-
* from before that mutation. An invalidation can therefore be
|
|
365
|
-
* `errors`, and a clear can reset state without emitting `clear`.
|
|
417
|
+
* @throws Thrown when a {@link FieldValidator} throws; its own thrown value escapes the mutation
|
|
418
|
+
* call unchanged. When a form mutation has already changed state, the throw leaves those
|
|
419
|
+
* changes beside the error list from before that mutation. An invalidation can therefore be
|
|
420
|
+
* recorded without appearing in `errors`, and a clear can reset state without emitting `clear`.
|
|
421
|
+
* Form-owned refusals use
|
|
366
422
|
* {@link FormError} instead.
|
|
367
423
|
* @example
|
|
368
424
|
* ```ts
|
|
@@ -373,7 +429,7 @@ export declare type FieldRuleName = Exclude<keyof FieldRule, 'custom'>;
|
|
|
373
429
|
export declare type FieldValidator = (value: FieldValue | undefined, values: FormValues) => true | string;
|
|
374
430
|
|
|
375
431
|
/**
|
|
376
|
-
*
|
|
432
|
+
* Represents every value a field can hold.
|
|
377
433
|
*
|
|
378
434
|
* @remarks
|
|
379
435
|
* The variant follows the control: text-like controls hold a `string`, `number` holds a
|
|
@@ -383,7 +439,7 @@ export declare type FieldValidator = (value: FieldValue | undefined, values: For
|
|
|
383
439
|
export declare type FieldValue = string | number | boolean | readonly string[];
|
|
384
440
|
|
|
385
441
|
/**
|
|
386
|
-
*
|
|
442
|
+
* Represents one or more files.
|
|
387
443
|
*
|
|
388
444
|
* @remarks
|
|
389
445
|
* `accept` lists the media types and extensions the control offers, in the form the host
|
|
@@ -396,7 +452,7 @@ export declare interface FileField extends FieldBase {
|
|
|
396
452
|
}
|
|
397
453
|
|
|
398
454
|
/**
|
|
399
|
-
*
|
|
455
|
+
* Represents a form: a schema, the answers given against it, and the errors they carry.
|
|
400
456
|
*
|
|
401
457
|
* @remarks
|
|
402
458
|
* The form owns its schema, so a later edit to the schema the caller passed changes nothing here.
|
|
@@ -423,7 +479,7 @@ export declare interface FileField extends FieldBase {
|
|
|
423
479
|
export declare class Form implements FormInterface {
|
|
424
480
|
#private;
|
|
425
481
|
/**
|
|
426
|
-
*
|
|
482
|
+
* Opens a form against a schema.
|
|
427
483
|
*
|
|
428
484
|
* @param schema - The form to ask. It is copied, and the copy is what the form asks.
|
|
429
485
|
* @param options - The form's settings.
|
|
@@ -432,28 +488,28 @@ export declare class Form implements FormInterface {
|
|
|
432
488
|
* value is one its field's control cannot hold.
|
|
433
489
|
*/
|
|
434
490
|
constructor(schema: FormSchema, options?: FormOptions);
|
|
435
|
-
/**
|
|
491
|
+
/** Holds the form's event emitter. */
|
|
436
492
|
get emitter(): EmitterInterface<FormEventMap>;
|
|
437
|
-
/**
|
|
493
|
+
/** Holds the schema this form asks, owned and frozen. */
|
|
438
494
|
get schema(): FormSchema;
|
|
439
|
-
/**
|
|
495
|
+
/** Reports the answers the form holds. */
|
|
440
496
|
get values(): FormValues;
|
|
441
|
-
/**
|
|
497
|
+
/** Holds the answers the form opened with. */
|
|
442
498
|
get baseline(): FormValues;
|
|
443
|
-
/**
|
|
499
|
+
/** Holds every error the last completed evaluation produced. */
|
|
444
500
|
get errors(): readonly FieldError[];
|
|
445
|
-
/**
|
|
501
|
+
/** Lists the names of the fields somebody has visited. */
|
|
446
502
|
get touched(): ReadonlySet<string>;
|
|
447
|
-
/**
|
|
503
|
+
/** Lists the names of the fields that are out of the form. */
|
|
448
504
|
get disabled(): ReadonlySet<string>;
|
|
449
|
-
/**
|
|
505
|
+
/** Reports where the form sits in its life. */
|
|
450
506
|
get status(): FormStatus;
|
|
451
|
-
/**
|
|
507
|
+
/** Reports whether the last completed evaluation found no error. */
|
|
452
508
|
get valid(): boolean;
|
|
453
|
-
/**
|
|
509
|
+
/** Reports whether any answer has moved since the form opened. */
|
|
454
510
|
get dirty(): boolean;
|
|
455
511
|
/**
|
|
456
|
-
*
|
|
512
|
+
* Holds the answers after the form settles.
|
|
457
513
|
*
|
|
458
514
|
* @remarks
|
|
459
515
|
* It resolves with the submitted values on the first valid submit, and rejects with a
|
|
@@ -461,27 +517,27 @@ export declare class Form implements FormInterface {
|
|
|
461
517
|
*/
|
|
462
518
|
get answer(): Promise<FormValues>;
|
|
463
519
|
/**
|
|
464
|
-
*
|
|
520
|
+
* Finds one field by name.
|
|
465
521
|
*
|
|
466
522
|
* @param name - The field's name.
|
|
467
523
|
* @returns The field, or `undefined` when the schema declares no such name.
|
|
468
524
|
*/
|
|
469
525
|
field(name: string): FormField | undefined;
|
|
470
526
|
/**
|
|
471
|
-
*
|
|
527
|
+
* Answers several fields at once.
|
|
472
528
|
*
|
|
473
529
|
* @param values - The answers to write, each keyed by its field name.
|
|
474
530
|
*/
|
|
475
531
|
fill(values: FormValues): void;
|
|
476
532
|
/**
|
|
477
|
-
*
|
|
533
|
+
* Answers one field.
|
|
478
534
|
*
|
|
479
535
|
* @param name - The field's name.
|
|
480
536
|
* @param value - The answer to write, or `undefined` to clear it.
|
|
481
537
|
*/
|
|
482
538
|
fill(name: string, value: FieldValue | undefined): void;
|
|
483
539
|
/**
|
|
484
|
-
*
|
|
540
|
+
* Records that somebody has visited a field.
|
|
485
541
|
*
|
|
486
542
|
* @param name - The field's name.
|
|
487
543
|
* @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended, and
|
|
@@ -489,7 +545,7 @@ export declare class Form implements FormInterface {
|
|
|
489
545
|
*/
|
|
490
546
|
touch(name: string): void;
|
|
491
547
|
/**
|
|
492
|
-
*
|
|
548
|
+
* Fails a field from outside, for what the rules cannot see.
|
|
493
549
|
*
|
|
494
550
|
* @param name - The field's name.
|
|
495
551
|
* @param message - What to tell the person.
|
|
@@ -500,36 +556,36 @@ export declare class Form implements FormInterface {
|
|
|
500
556
|
* `FIELD` when the schema declares no such name.
|
|
501
557
|
*/
|
|
502
558
|
invalidate(name: string, message: string): void;
|
|
503
|
-
/**
|
|
559
|
+
/** Takes every field out of the form. */
|
|
504
560
|
disable(): void;
|
|
505
561
|
/**
|
|
506
|
-
*
|
|
562
|
+
* Takes one field out of the form.
|
|
507
563
|
*
|
|
508
564
|
* @param name - The field's name.
|
|
509
565
|
*/
|
|
510
566
|
disable(name: string): void;
|
|
511
567
|
/**
|
|
512
|
-
*
|
|
568
|
+
* Takes several fields out of the form.
|
|
513
569
|
*
|
|
514
570
|
* @param names - The field names.
|
|
515
571
|
*/
|
|
516
572
|
disable(names: readonly string[]): void;
|
|
517
|
-
/**
|
|
573
|
+
/** Puts every field back into the form. */
|
|
518
574
|
enable(): void;
|
|
519
575
|
/**
|
|
520
|
-
*
|
|
576
|
+
* Puts one field back into the form.
|
|
521
577
|
*
|
|
522
578
|
* @param name - The field's name.
|
|
523
579
|
*/
|
|
524
580
|
enable(name: string): void;
|
|
525
581
|
/**
|
|
526
|
-
*
|
|
582
|
+
* Puts several fields back into the form.
|
|
527
583
|
*
|
|
528
584
|
* @param names - The field names.
|
|
529
585
|
*/
|
|
530
586
|
enable(names: readonly string[]): void;
|
|
531
587
|
/**
|
|
532
|
-
*
|
|
588
|
+
* Checks every answer and settles the form when they all pass.
|
|
533
589
|
*
|
|
534
590
|
* @returns The values on success, or every error that stopped them.
|
|
535
591
|
* @remarks
|
|
@@ -546,14 +602,14 @@ export declare class Form implements FormInterface {
|
|
|
546
602
|
*/
|
|
547
603
|
submit(): FormResult;
|
|
548
604
|
/**
|
|
549
|
-
*
|
|
605
|
+
* Returns every answer to the ones the form opened with: the schema's defaults, overlaid with
|
|
550
606
|
* any seeded `values`. Reset the runtime disabled state to the schema's declarations.
|
|
551
607
|
*
|
|
552
608
|
* @throws A {@link FormError} coded `SETTLED` or `ABANDONED` when the form has ended.
|
|
553
609
|
*/
|
|
554
610
|
clear(): void;
|
|
555
611
|
/**
|
|
556
|
-
*
|
|
612
|
+
* Tears the form down, abandoning it when it has not settled.
|
|
557
613
|
*
|
|
558
614
|
* @remarks
|
|
559
615
|
* Destroying twice does nothing the second time. A settled form keeps its `settled` status and
|
|
@@ -564,11 +620,11 @@ export declare class Form implements FormInterface {
|
|
|
564
620
|
destroy(): void;
|
|
565
621
|
}
|
|
566
622
|
|
|
567
|
-
/**
|
|
623
|
+
/** Lists every form lifecycle status. */
|
|
568
624
|
export declare const FORM_STATUSES: readonly FormStatus[];
|
|
569
625
|
|
|
570
626
|
/**
|
|
571
|
-
*
|
|
627
|
+
* Resolves and interpolates one rule message.
|
|
572
628
|
*
|
|
573
629
|
* @param rule - The rule whose message to resolve.
|
|
574
630
|
* @param limit - The optional operand substituted for `{limit}`.
|
|
@@ -577,14 +633,26 @@ export declare const FORM_STATUSES: readonly FormStatus[];
|
|
|
577
633
|
*/
|
|
578
634
|
export declare function formatMessage(rule: FieldRuleName, limit?: number | string, messages?: Readonly<Partial<Record<FieldRuleName, string>>>): string;
|
|
579
635
|
|
|
580
|
-
/**
|
|
636
|
+
/**
|
|
637
|
+
* Represents an error raised by the form domain.
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```ts
|
|
641
|
+
* const error = new FormError('FIELD', 'The schema declares no field named "nickname"', {
|
|
642
|
+
* field: 'nickname',
|
|
643
|
+
* })
|
|
644
|
+
*
|
|
645
|
+
* error.code // 'FIELD'
|
|
646
|
+
* error.context // { field: 'nickname' }
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
581
649
|
export declare class FormError extends Error {
|
|
582
|
-
/**
|
|
650
|
+
/** Holds the machine-readable reason for this failure. */
|
|
583
651
|
readonly code: FormErrorCode;
|
|
584
|
-
/**
|
|
652
|
+
/** Holds structured values that locate or explain this failure. */
|
|
585
653
|
readonly context?: JSONRecord;
|
|
586
654
|
/**
|
|
587
|
-
*
|
|
655
|
+
* Creates a form error.
|
|
588
656
|
*
|
|
589
657
|
* @param code - The machine-readable reason.
|
|
590
658
|
* @param message - The human-readable failure text.
|
|
@@ -594,7 +662,7 @@ export declare class FormError extends Error {
|
|
|
594
662
|
}
|
|
595
663
|
|
|
596
664
|
/**
|
|
597
|
-
*
|
|
665
|
+
* Names the machine-readable code a form error carries.
|
|
598
666
|
*
|
|
599
667
|
* @remarks
|
|
600
668
|
* `SCHEMA` rejects a malformed schema. `FIELD` names a field the schema does not declare.
|
|
@@ -604,7 +672,7 @@ export declare class FormError extends Error {
|
|
|
604
672
|
export declare type FormErrorCode = 'SCHEMA' | 'FIELD' | 'CONTROL' | 'SETTLED' | 'ABANDONED';
|
|
605
673
|
|
|
606
674
|
/**
|
|
607
|
-
*
|
|
675
|
+
* Lists everything a form announces.
|
|
608
676
|
*
|
|
609
677
|
* @remarks
|
|
610
678
|
* `fill` carries the field that changed and its new value, where `undefined` is the value
|
|
@@ -624,7 +692,7 @@ export declare type FormEventMap = {
|
|
|
624
692
|
};
|
|
625
693
|
|
|
626
694
|
/**
|
|
627
|
-
*
|
|
695
|
+
* Represents any field a schema can declare.
|
|
628
696
|
*
|
|
629
697
|
* @remarks
|
|
630
698
|
* The union discriminates on `control`, so narrowing on that member reaches each variant's
|
|
@@ -640,7 +708,7 @@ export declare type FormEventMap = {
|
|
|
640
708
|
export declare type FormField = TextField | EditorField | PasswordField | NumberField | DateField | TimeField | DatetimeField | ColorField | ConfirmField | SelectField | CheckboxField | FileField;
|
|
641
709
|
|
|
642
710
|
/**
|
|
643
|
-
*
|
|
711
|
+
* Represents a named section of a form.
|
|
644
712
|
*
|
|
645
713
|
* @remarks
|
|
646
714
|
* A field joins a group through {@link FieldBase.group}. Grouping arranges the form and
|
|
@@ -653,7 +721,7 @@ export declare interface FormGroup {
|
|
|
653
721
|
}
|
|
654
722
|
|
|
655
723
|
/**
|
|
656
|
-
*
|
|
724
|
+
* Represents a form: a schema, the answers given against it, and the errors they carry.
|
|
657
725
|
*
|
|
658
726
|
* @remarks
|
|
659
727
|
* `valid` is true when the last completed evaluation found no error, and `dirty` is true once
|
|
@@ -670,26 +738,26 @@ export declare interface FormGroup {
|
|
|
670
738
|
* ```
|
|
671
739
|
*/
|
|
672
740
|
export declare interface FormInterface {
|
|
673
|
-
/**
|
|
741
|
+
/** Holds the form's event emitter. */
|
|
674
742
|
readonly emitter: EmitterInterface<FormEventMap>;
|
|
675
|
-
/**
|
|
743
|
+
/** Holds the schema this form asks. */
|
|
676
744
|
readonly schema: FormSchema;
|
|
677
|
-
/**
|
|
745
|
+
/** Reports the answers the form holds. */
|
|
678
746
|
readonly values: FormValues;
|
|
679
747
|
/**
|
|
680
|
-
*
|
|
748
|
+
* Holds the answers the form opened with: the schema's defaults, overlaid with any seeded values.
|
|
681
749
|
*
|
|
682
750
|
* @remarks
|
|
683
751
|
* It is fixed when the form opens and never moves again, so it is what `dirty` measures
|
|
684
752
|
* against and what {@link FormInterface.clear} returns to.
|
|
685
753
|
*/
|
|
686
754
|
readonly baseline: FormValues;
|
|
687
|
-
/**
|
|
755
|
+
/** Holds every error the last check produced. */
|
|
688
756
|
readonly errors: readonly FieldError[];
|
|
689
|
-
/**
|
|
757
|
+
/** Lists the names of the fields somebody has visited. */
|
|
690
758
|
readonly touched: ReadonlySet<string>;
|
|
691
759
|
/**
|
|
692
|
-
*
|
|
760
|
+
* Lists the names of the fields that are out of the form.
|
|
693
761
|
*
|
|
694
762
|
* @remarks
|
|
695
763
|
* It opens as the set the schema declares through {@link FieldBase.disabled} and moves with
|
|
@@ -697,14 +765,14 @@ export declare interface FormInterface {
|
|
|
697
765
|
* holds the declaration and this holds the current fact.
|
|
698
766
|
*/
|
|
699
767
|
readonly disabled: ReadonlySet<string>;
|
|
700
|
-
/**
|
|
768
|
+
/** Reports where the form sits in its life. */
|
|
701
769
|
readonly status: FormStatus;
|
|
702
|
-
/**
|
|
770
|
+
/** Reports whether the last completed evaluation found no error. */
|
|
703
771
|
readonly valid: boolean;
|
|
704
|
-
/**
|
|
772
|
+
/** Reports whether any answer has moved since the form opened. */
|
|
705
773
|
readonly dirty: boolean;
|
|
706
774
|
/**
|
|
707
|
-
*
|
|
775
|
+
* Holds the answers after the form settles.
|
|
708
776
|
*
|
|
709
777
|
* @remarks
|
|
710
778
|
* It resolves with the submitted values on the first valid submit, and rejects when teardown
|
|
@@ -712,40 +780,40 @@ export declare interface FormInterface {
|
|
|
712
780
|
*/
|
|
713
781
|
readonly answer: Promise<FormValues>;
|
|
714
782
|
/**
|
|
715
|
-
*
|
|
783
|
+
* Finds one field by name.
|
|
716
784
|
*
|
|
717
785
|
* @param name - The field's name.
|
|
718
786
|
* @returns The field, or `undefined` when the schema declares no such name.
|
|
719
787
|
*/
|
|
720
788
|
field(name: string): FormField | undefined;
|
|
721
789
|
/**
|
|
722
|
-
*
|
|
790
|
+
* Answers several fields at once.
|
|
723
791
|
*
|
|
724
792
|
* @param values - The answers to write, each keyed by its field name.
|
|
725
793
|
*/
|
|
726
794
|
fill(values: FormValues): void;
|
|
727
795
|
/**
|
|
728
|
-
*
|
|
796
|
+
* Answers one field.
|
|
729
797
|
*
|
|
730
798
|
* @param name - The field's name.
|
|
731
799
|
* @param value - The answer to write, or `undefined` to clear it.
|
|
732
800
|
*/
|
|
733
801
|
fill(name: string, value: FieldValue | undefined): void;
|
|
734
802
|
/**
|
|
735
|
-
*
|
|
803
|
+
* Records that somebody has visited a field.
|
|
736
804
|
*
|
|
737
805
|
* @param name - The field's name.
|
|
738
806
|
*/
|
|
739
807
|
touch(name: string): void;
|
|
740
808
|
/**
|
|
741
|
-
*
|
|
809
|
+
* Fails a field from outside, for what the rules cannot see.
|
|
742
810
|
*
|
|
743
811
|
* @param name - The field's name.
|
|
744
812
|
* @param message - What to tell the person.
|
|
745
813
|
*/
|
|
746
814
|
invalidate(name: string, message: string): void;
|
|
747
815
|
/**
|
|
748
|
-
*
|
|
816
|
+
* Takes every field out of the form.
|
|
749
817
|
*
|
|
750
818
|
* @remarks
|
|
751
819
|
* A disabled field is neither evaluated nor submitted. Its answer is kept, and so is any
|
|
@@ -756,14 +824,14 @@ export declare interface FormInterface {
|
|
|
756
824
|
*/
|
|
757
825
|
disable(): void;
|
|
758
826
|
/**
|
|
759
|
-
*
|
|
827
|
+
* Takes one field out of the form.
|
|
760
828
|
*
|
|
761
829
|
* @param name - The field's name.
|
|
762
830
|
* @throws A {@link FormError} coded `FIELD` when the schema declares no such name.
|
|
763
831
|
*/
|
|
764
832
|
disable(name: string): void;
|
|
765
833
|
/**
|
|
766
|
-
*
|
|
834
|
+
* Takes several fields out of the form.
|
|
767
835
|
*
|
|
768
836
|
* @param names - The field names.
|
|
769
837
|
* @throws A {@link FormError} coded `FIELD` when the schema declares no such name. Every name
|
|
@@ -771,7 +839,7 @@ export declare interface FormInterface {
|
|
|
771
839
|
*/
|
|
772
840
|
disable(names: readonly string[]): void;
|
|
773
841
|
/**
|
|
774
|
-
*
|
|
842
|
+
* Puts every field back into the form.
|
|
775
843
|
*
|
|
776
844
|
* @remarks
|
|
777
845
|
* An enabled field is evaluated and submitted again, and any invalidation held while it was
|
|
@@ -780,14 +848,14 @@ export declare interface FormInterface {
|
|
|
780
848
|
*/
|
|
781
849
|
enable(): void;
|
|
782
850
|
/**
|
|
783
|
-
*
|
|
851
|
+
* Puts one field back into the form.
|
|
784
852
|
*
|
|
785
853
|
* @param name - The field's name.
|
|
786
854
|
* @throws A {@link FormError} coded `FIELD` when the schema declares no such name.
|
|
787
855
|
*/
|
|
788
856
|
enable(name: string): void;
|
|
789
857
|
/**
|
|
790
|
-
*
|
|
858
|
+
* Puts several fields back into the form.
|
|
791
859
|
*
|
|
792
860
|
* @param names - The field names.
|
|
793
861
|
* @throws A {@link FormError} coded `FIELD` when the schema declares no such name. Every name
|
|
@@ -795,13 +863,13 @@ export declare interface FormInterface {
|
|
|
795
863
|
*/
|
|
796
864
|
enable(names: readonly string[]): void;
|
|
797
865
|
/**
|
|
798
|
-
*
|
|
866
|
+
* Checks every answer and settles the form when they all pass.
|
|
799
867
|
*
|
|
800
868
|
* @returns The values on success, or every error that stopped them.
|
|
801
869
|
*/
|
|
802
870
|
submit(): FormResult;
|
|
803
871
|
/**
|
|
804
|
-
*
|
|
872
|
+
* Returns every answer to {@link FormInterface.baseline}, the answers the form opened with.
|
|
805
873
|
*
|
|
806
874
|
* @remarks
|
|
807
875
|
* The runtime disabled overlay resets with them, so {@link FormInterface.disabled} reads the
|
|
@@ -809,7 +877,7 @@ export declare interface FormInterface {
|
|
|
809
877
|
*/
|
|
810
878
|
clear(): void;
|
|
811
879
|
/**
|
|
812
|
-
*
|
|
880
|
+
* Tears the form down, abandoning it when it has not settled.
|
|
813
881
|
*
|
|
814
882
|
* @remarks
|
|
815
883
|
* A request from inside a listener defers teardown until the outermost mutation batch closes,
|
|
@@ -819,9 +887,8 @@ export declare interface FormInterface {
|
|
|
819
887
|
}
|
|
820
888
|
|
|
821
889
|
/**
|
|
822
|
-
*
|
|
890
|
+
* Describes how to open a form.
|
|
823
891
|
*
|
|
824
|
-
* @param options - The form's settings.
|
|
825
892
|
* @remarks
|
|
826
893
|
* `on` wires listeners at construction and `error` receives any throw from one of them.
|
|
827
894
|
* `values` seeds the answers, overriding each field's declared default. `messages` replaces
|
|
@@ -844,7 +911,7 @@ export declare interface FormOptions {
|
|
|
844
911
|
}
|
|
845
912
|
|
|
846
913
|
/**
|
|
847
|
-
*
|
|
914
|
+
* Reports what a submit answers with: the values, or every error that stopped them.
|
|
848
915
|
*
|
|
849
916
|
* @example
|
|
850
917
|
* ```ts
|
|
@@ -855,7 +922,7 @@ export declare interface FormOptions {
|
|
|
855
922
|
export declare type FormResult = Result<FormValues, readonly FieldError[]>;
|
|
856
923
|
|
|
857
924
|
/**
|
|
858
|
-
*
|
|
925
|
+
* Describes everything a form asks.
|
|
859
926
|
*
|
|
860
927
|
* @remarks
|
|
861
928
|
* `fields` is the schema's only required member, and the order it declares is the order the
|
|
@@ -881,7 +948,7 @@ export declare interface FormSchema {
|
|
|
881
948
|
}
|
|
882
949
|
|
|
883
950
|
/**
|
|
884
|
-
*
|
|
951
|
+
* Represents where a form sits in its life.
|
|
885
952
|
*
|
|
886
953
|
* @remarks
|
|
887
954
|
* A form opens `editing`, turns `settled` on its first valid submit, and turns `abandoned`
|
|
@@ -895,7 +962,7 @@ export declare interface FormSchema {
|
|
|
895
962
|
export declare type FormStatus = 'editing' | 'settled' | 'abandoned';
|
|
896
963
|
|
|
897
964
|
/**
|
|
898
|
-
*
|
|
965
|
+
* Represents a form's answers, keyed by field name.
|
|
899
966
|
*
|
|
900
967
|
* @remarks
|
|
901
968
|
* A name with no key is a field nobody has answered. A disabled field's value may appear so a
|
|
@@ -908,62 +975,82 @@ export declare type FormStatus = 'editing' | 'settled' | 'abandoned';
|
|
|
908
975
|
*/
|
|
909
976
|
export declare type FormValues = Readonly<Record<string, FieldValue>>;
|
|
910
977
|
|
|
911
|
-
/**
|
|
978
|
+
/**
|
|
979
|
+
* Writes one own enumerable data property that cannot be rewritten or removed.
|
|
980
|
+
*
|
|
981
|
+
* @param target - The record to write into.
|
|
982
|
+
* @param name - The property name to write.
|
|
983
|
+
* @param value - The value to store.
|
|
984
|
+
*
|
|
985
|
+
* @remarks
|
|
986
|
+
* The prototype-safe write of {@link defineEntry}, frozen: the entry is neither writable nor
|
|
987
|
+
* configurable, so the record a parser hands back cannot be edited through the key it just filled.
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```ts
|
|
991
|
+
* const values: Record<string, number> = {}
|
|
992
|
+
* freezeEntry(values, '__proto__', 1)
|
|
993
|
+
* Object.getOwnPropertyDescriptor(values, '__proto__')?.writable // false
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
export declare function freezeEntry<T>(target: Record<string, T>, name: string, value: T): void;
|
|
997
|
+
|
|
998
|
+
/** Caps the number of groups one schema may declare. */
|
|
912
999
|
export declare const GROUP_LIMIT = 64;
|
|
913
1000
|
|
|
914
|
-
/**
|
|
1001
|
+
/** Matches a signed or unsigned base-ten integer string. */
|
|
915
1002
|
export declare const INTEGER_PATTERN: Readonly<RegExp>;
|
|
916
1003
|
|
|
917
1004
|
/**
|
|
918
|
-
*
|
|
1005
|
+
* Determines whether an unknown value is one exact field choice record.
|
|
919
1006
|
*
|
|
920
1007
|
* @param input - The value to inspect.
|
|
921
|
-
* @returns
|
|
1008
|
+
* @returns True if the value is a field choice; false otherwise.
|
|
922
1009
|
*/
|
|
923
1010
|
export declare function isFieldChoice(input: unknown): input is FieldChoice;
|
|
924
1011
|
|
|
925
1012
|
/**
|
|
926
|
-
*
|
|
1013
|
+
* Determines whether an unknown value is a declared field control.
|
|
927
1014
|
*
|
|
928
1015
|
* @param input - The value to inspect.
|
|
929
|
-
* @returns
|
|
1016
|
+
* @returns True if the value is a field control; false otherwise.
|
|
930
1017
|
*/
|
|
931
1018
|
export declare function isFieldControl(input: unknown): input is FieldControl;
|
|
932
1019
|
|
|
933
1020
|
/**
|
|
934
|
-
*
|
|
1021
|
+
* Determines whether an unknown value is one exact field error record.
|
|
935
1022
|
*
|
|
936
1023
|
* @param input - The value to inspect.
|
|
937
|
-
* @returns
|
|
1024
|
+
* @returns True if the value is a field error; false otherwise.
|
|
938
1025
|
*/
|
|
939
1026
|
export declare function isFieldError(input: unknown): input is FieldError;
|
|
940
1027
|
|
|
941
1028
|
/**
|
|
942
|
-
*
|
|
1029
|
+
* Determines whether an unknown value is one exact field rule record.
|
|
943
1030
|
*
|
|
944
1031
|
* @param input - The value to inspect.
|
|
945
|
-
* @returns
|
|
1032
|
+
* @returns True if the value is a structurally valid field rule; false otherwise.
|
|
946
1033
|
*/
|
|
947
1034
|
export declare function isFieldRule(input: unknown): input is FieldRule;
|
|
948
1035
|
|
|
949
1036
|
/**
|
|
950
|
-
*
|
|
1037
|
+
* Determines whether an unknown value has a form field value shape.
|
|
951
1038
|
*
|
|
952
1039
|
* @param input - The value to inspect.
|
|
953
|
-
* @returns
|
|
1040
|
+
* @returns True if the value is a field value; false otherwise.
|
|
954
1041
|
*/
|
|
955
1042
|
export declare function isFieldValue(input: unknown): input is FieldValue;
|
|
956
1043
|
|
|
957
1044
|
/**
|
|
958
|
-
*
|
|
1045
|
+
* Determines whether an unknown value is a form error.
|
|
959
1046
|
*
|
|
960
1047
|
* @param input - The value to inspect.
|
|
961
|
-
* @returns
|
|
1048
|
+
* @returns True if the value is a {@link FormError} instance; false otherwise.
|
|
962
1049
|
*/
|
|
963
1050
|
export declare function isFormError(input: unknown): input is FormError;
|
|
964
1051
|
|
|
965
1052
|
/**
|
|
966
|
-
*
|
|
1053
|
+
* Determines whether an unknown value is one exact discriminated form field.
|
|
967
1054
|
*
|
|
968
1055
|
* @remarks
|
|
969
1056
|
* Metadata is admitted structurally as bounded JSON. An accessor-bearing metadata record is
|
|
@@ -971,47 +1058,47 @@ export declare function isFormError(input: unknown): input is FormError;
|
|
|
971
1058
|
* data properties only.
|
|
972
1059
|
*
|
|
973
1060
|
* @param input - The value to inspect.
|
|
974
|
-
* @returns
|
|
1061
|
+
* @returns True if the value is a structurally valid form field; false otherwise.
|
|
975
1062
|
*/
|
|
976
1063
|
export declare function isFormField(input: unknown): input is FormField;
|
|
977
1064
|
|
|
978
1065
|
/**
|
|
979
|
-
*
|
|
1066
|
+
* Determines whether an unknown value is one exact form group record.
|
|
980
1067
|
*
|
|
981
1068
|
* @param input - The value to inspect.
|
|
982
|
-
* @returns
|
|
1069
|
+
* @returns True if the value is a form group; false otherwise.
|
|
983
1070
|
*/
|
|
984
1071
|
export declare function isFormGroup(input: unknown): input is FormGroup;
|
|
985
1072
|
|
|
986
1073
|
/**
|
|
987
|
-
*
|
|
1074
|
+
* Determines whether an unknown value is one exact structural form schema.
|
|
988
1075
|
*
|
|
989
1076
|
* @param input - The value to inspect.
|
|
990
|
-
* @returns
|
|
1077
|
+
* @returns True if the value is a structurally valid form schema; false otherwise.
|
|
991
1078
|
*/
|
|
992
1079
|
export declare function isFormSchema(input: unknown): input is FormSchema;
|
|
993
1080
|
|
|
994
1081
|
/**
|
|
995
|
-
*
|
|
1082
|
+
* Determines whether an unknown value is a form lifecycle status.
|
|
996
1083
|
*
|
|
997
1084
|
* @param input - The value to inspect.
|
|
998
|
-
* @returns
|
|
1085
|
+
* @returns True if the value is a form status; false otherwise.
|
|
999
1086
|
*/
|
|
1000
1087
|
export declare function isFormStatus(input: unknown): input is FormStatus;
|
|
1001
1088
|
|
|
1002
1089
|
/**
|
|
1003
|
-
*
|
|
1090
|
+
* Determines whether an unknown value is a record of field values.
|
|
1004
1091
|
*
|
|
1005
1092
|
* @param input - The value to inspect.
|
|
1006
|
-
* @returns
|
|
1093
|
+
* @returns True if the value is a form values record; false otherwise.
|
|
1007
1094
|
*/
|
|
1008
1095
|
export declare function isFormValues(input: unknown): input is FormValues;
|
|
1009
1096
|
|
|
1010
|
-
/**
|
|
1097
|
+
/** Caps the number of entries one list-valued answer may hold. */
|
|
1011
1098
|
export declare const LIST_LIMIT = 1024;
|
|
1012
1099
|
|
|
1013
1100
|
/**
|
|
1014
|
-
*
|
|
1101
|
+
* Decides whether a raw binding value projects to an answered field.
|
|
1015
1102
|
*
|
|
1016
1103
|
* @remarks
|
|
1017
1104
|
* Bind with `fill(name, matchesAnswer(raw) ? raw : undefined)`. This projection treats an absent
|
|
@@ -1020,44 +1107,44 @@ export declare const LIST_LIMIT = 1024;
|
|
|
1020
1107
|
* its `required` rule remains presence-only.
|
|
1021
1108
|
*
|
|
1022
1109
|
* @param value - The raw field value, or absence.
|
|
1023
|
-
* @returns
|
|
1110
|
+
* @returns True if the binding preserves the value as an answer; false otherwise.
|
|
1024
1111
|
*/
|
|
1025
1112
|
export declare function matchesAnswer(value: FieldValue | undefined): boolean;
|
|
1026
1113
|
|
|
1027
1114
|
/**
|
|
1028
|
-
*
|
|
1115
|
+
* Checks whether a value has the shape required by one field control.
|
|
1029
1116
|
*
|
|
1030
1117
|
* @param field - The field that owns the value.
|
|
1031
1118
|
* @param value - The unknown value to inspect.
|
|
1032
|
-
* @returns
|
|
1119
|
+
* @returns True if the control can hold the value; false otherwise.
|
|
1033
1120
|
*/
|
|
1034
1121
|
export declare function matchesField(field: FormField, value: unknown): value is FieldValue;
|
|
1035
1122
|
|
|
1036
1123
|
/**
|
|
1037
|
-
*
|
|
1124
|
+
* Compares two field values by scalar identity or ordered list content.
|
|
1038
1125
|
*
|
|
1039
1126
|
* @param a - The first field value.
|
|
1040
1127
|
* @param b - The second field value.
|
|
1041
|
-
* @returns
|
|
1128
|
+
* @returns True if both values contain the same answer; false otherwise.
|
|
1042
1129
|
*/
|
|
1043
1130
|
export declare function matchesValue(a: FieldValue, b: FieldValue): boolean;
|
|
1044
1131
|
|
|
1045
1132
|
/**
|
|
1046
|
-
*
|
|
1133
|
+
* Compares two form value records by keys and value content.
|
|
1047
1134
|
*
|
|
1048
1135
|
* @param a - The first value record.
|
|
1049
1136
|
* @param b - The second value record.
|
|
1050
|
-
* @returns
|
|
1137
|
+
* @returns True if both records contain the same answers; false otherwise.
|
|
1051
1138
|
*/
|
|
1052
1139
|
export declare function matchesValues(a: FormValues, b: FormValues): boolean;
|
|
1053
1140
|
|
|
1054
|
-
/**
|
|
1141
|
+
/** Caps the length, in UTF-16 code units, of a schema, group, or field name. */
|
|
1055
1142
|
export declare const NAME_LIMIT = 128;
|
|
1056
1143
|
|
|
1057
|
-
/**
|
|
1144
|
+
/** Caps the total number of records, arrays, and leaves one schema retains. */
|
|
1058
1145
|
export declare const NODE_LIMIT = 16384;
|
|
1059
1146
|
|
|
1060
|
-
/**
|
|
1147
|
+
/** Represents a number. */
|
|
1061
1148
|
export declare interface NumberField extends FieldBase {
|
|
1062
1149
|
readonly control: 'number';
|
|
1063
1150
|
readonly default?: number;
|
|
@@ -1065,7 +1152,7 @@ export declare interface NumberField extends FieldBase {
|
|
|
1065
1152
|
}
|
|
1066
1153
|
|
|
1067
1154
|
/**
|
|
1068
|
-
*
|
|
1155
|
+
* Parses unknown wire data into an owned, semantically sound form schema.
|
|
1069
1156
|
*
|
|
1070
1157
|
* @param input - The unknown schema value to parse.
|
|
1071
1158
|
* @returns An owned schema with custom rules removed, or `undefined` on refusal.
|
|
@@ -1073,7 +1160,7 @@ export declare interface NumberField extends FieldBase {
|
|
|
1073
1160
|
export declare function parseForm(input: unknown): FormSchema | undefined;
|
|
1074
1161
|
|
|
1075
1162
|
/**
|
|
1076
|
-
*
|
|
1163
|
+
* Parses one answer against its field control.
|
|
1077
1164
|
*
|
|
1078
1165
|
* @param field - The field that defines the accepted value.
|
|
1079
1166
|
* @param input - The unknown value to parse.
|
|
@@ -1082,7 +1169,7 @@ export declare function parseForm(input: unknown): FormSchema | undefined;
|
|
|
1082
1169
|
export declare function parseValue(field: FormField, input: unknown): FieldValue | undefined;
|
|
1083
1170
|
|
|
1084
1171
|
/**
|
|
1085
|
-
*
|
|
1172
|
+
* Parses a strict answer record against the fields declared by a schema.
|
|
1086
1173
|
*
|
|
1087
1174
|
* @param schema - The schema that owns the accepted field names and controls.
|
|
1088
1175
|
* @param input - The unknown answer record to parse.
|
|
@@ -1091,7 +1178,7 @@ export declare function parseValue(field: FormField, input: unknown): FieldValue
|
|
|
1091
1178
|
export declare function parseValues(schema: FormSchema, input: unknown): FormValues | undefined;
|
|
1092
1179
|
|
|
1093
1180
|
/**
|
|
1094
|
-
*
|
|
1181
|
+
* Represents a secret, obscured as it is typed.
|
|
1095
1182
|
*
|
|
1096
1183
|
* @remarks
|
|
1097
1184
|
* It carries no `default` deliberately: a seeded secret is a secret written down. `mask` is
|
|
@@ -1102,14 +1189,14 @@ export declare interface PasswordField extends FieldBase {
|
|
|
1102
1189
|
readonly mask?: string;
|
|
1103
1190
|
}
|
|
1104
1191
|
|
|
1105
|
-
/**
|
|
1192
|
+
/** Caps the accepted source length for an authored regular expression. */
|
|
1106
1193
|
export declare const PATTERN_LIMIT = 256;
|
|
1107
1194
|
|
|
1108
|
-
/**
|
|
1195
|
+
/** Holds the default failure copy for every named field rule. */
|
|
1109
1196
|
export declare const RULE_MESSAGES: Readonly<Record<FieldRuleName, string>>;
|
|
1110
1197
|
|
|
1111
1198
|
/**
|
|
1112
|
-
*
|
|
1199
|
+
* Represents one choice out of a list.
|
|
1113
1200
|
*
|
|
1114
1201
|
* @remarks
|
|
1115
1202
|
* `open` admits a value the list does not offer, which is what turns a closed menu into a
|
|
@@ -1123,7 +1210,7 @@ export declare interface SelectField extends FieldBase {
|
|
|
1123
1210
|
}
|
|
1124
1211
|
|
|
1125
1212
|
/**
|
|
1126
|
-
*
|
|
1213
|
+
* Projects a schema into JSON while removing custom validators and absent values.
|
|
1127
1214
|
*
|
|
1128
1215
|
* @param schema - The schema to project.
|
|
1129
1216
|
* @returns A deep JSON copy of the serializable schema.
|
|
@@ -1132,29 +1219,29 @@ export declare interface SelectField extends FieldBase {
|
|
|
1132
1219
|
*/
|
|
1133
1220
|
export declare function serializeForm(schema: FormSchema): JSONRecord;
|
|
1134
1221
|
|
|
1135
|
-
/**
|
|
1222
|
+
/** Caps the length, in UTF-16 code units, of any single retained string. */
|
|
1136
1223
|
export declare const STRING_LIMIT = 65536;
|
|
1137
1224
|
|
|
1138
|
-
/**
|
|
1225
|
+
/** Caps the total length, in UTF-16 code units, of every string one schema retains. */
|
|
1139
1226
|
export declare const TEXT_LIMIT = 1048576;
|
|
1140
1227
|
|
|
1141
|
-
/**
|
|
1228
|
+
/** Represents a single line of text. */
|
|
1142
1229
|
export declare interface TextField extends FieldBase {
|
|
1143
1230
|
readonly control: 'text';
|
|
1144
1231
|
readonly default?: string;
|
|
1145
1232
|
readonly placeholder?: string;
|
|
1146
1233
|
}
|
|
1147
1234
|
|
|
1148
|
-
/**
|
|
1235
|
+
/** Matches a 24-hour time string with optional seconds. */
|
|
1149
1236
|
export declare const TIME_PATTERN: Readonly<RegExp>;
|
|
1150
1237
|
|
|
1151
|
-
/**
|
|
1238
|
+
/** Represents a time of day, held as the control's own string. */
|
|
1152
1239
|
export declare interface TimeField extends FieldBase {
|
|
1153
1240
|
readonly control: 'time';
|
|
1154
1241
|
readonly default?: string;
|
|
1155
1242
|
}
|
|
1156
1243
|
|
|
1157
|
-
/**
|
|
1244
|
+
/** Matches an absolute HTTP or HTTPS URL shape. */
|
|
1158
1245
|
export declare const URL_PATTERN: Readonly<RegExp>;
|
|
1159
1246
|
|
|
1160
1247
|
export { }
|