Skip to content

Commit ae0c590

Browse files
authored
refactor(forms): rename field to fieldTree in FieldContext and ValidationError
BREAKING CHANGE:
1 parent 2ccdf50 commit ae0c590

31 files changed

+300
-283
lines changed

goldens/public-api/forms/signals/compat/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class CompatValidationError<T = unknown> implements ValidationError {
4545
// (undocumented)
4646
readonly control: AbstractControl;
4747
// (undocumented)
48-
readonly field: FieldTree<unknown>;
48+
readonly fieldTree: FieldTree<unknown>;
4949
// (undocumented)
5050
readonly kind: string;
5151
// (undocumented)

goldens/public-api/forms/signals/index.api.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function customError<E extends Partial<ValidationError.WithField>>(obj?:
9999
export class CustomValidationError implements ValidationError {
100100
constructor(options?: ValidationErrorOptions);
101101
[key: PropertyKey]: unknown;
102-
readonly field: FieldTree<unknown>;
102+
readonly fieldTree: FieldTree<unknown>;
103103
readonly kind: string;
104104
readonly message?: string;
105105
}
@@ -115,7 +115,7 @@ export function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(pat
115115

116116
// @public
117117
export interface DisabledReason {
118-
readonly field: FieldTree<unknown>;
118+
readonly fieldTree: FieldTree<unknown>;
119119
readonly message?: string;
120120
}
121121

@@ -469,7 +469,7 @@ export class RequiredValidationError extends _NgValidationError {
469469

470470
// @public
471471
export interface RootFieldContext<TValue> {
472-
readonly field: FieldTree<TValue>;
472+
readonly fieldTree: FieldTree<TValue>;
473473
fieldTreeOf<PModel>(p: SchemaPathTree<PModel>): FieldTree<PModel>;
474474
readonly pathKeys: Signal<readonly string[]>;
475475
readonly state: FieldState<TValue>;
@@ -582,10 +582,10 @@ export interface ValidationError {
582582
// @public (undocumented)
583583
export namespace ValidationError {
584584
export interface WithField extends ValidationError {
585-
readonly field: FieldTree<unknown>;
585+
readonly fieldTree: FieldTree<unknown>;
586586
}
587587
export interface WithOptionalField extends ValidationError {
588-
readonly field?: FieldTree<unknown>;
588+
readonly fieldTree?: FieldTree<unknown>;
589589
}
590590
export interface WithoutField extends ValidationError {
591591
readonly field?: never;
@@ -603,17 +603,17 @@ export type Validator<TValue, TPathKind extends PathKind = PathKind.Root> = Logi
603603

604604
// @public
605605
export type WithField<T> = T & {
606-
field: FieldTree<unknown>;
606+
fieldTree: FieldTree<unknown>;
607607
};
608608

609609
// @public
610-
export type WithOptionalField<T> = Omit<T, 'field'> & {
611-
field?: FieldTree<unknown>;
610+
export type WithOptionalField<T> = Omit<T, 'fieldTree'> & {
611+
fieldTree?: FieldTree<unknown>;
612612
};
613613

614614
// @public
615615
export type WithoutField<T> = T & {
616-
field: never;
616+
fieldTree: never;
617617
};
618618

619619
// (No @packageDocumentation comment for this package)

packages/forms/signals/compat/src/api/compat_validation_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {FieldTree} from '../../../src/api/types';
1919
export class CompatValidationError<T = unknown> implements ValidationError {
2020
readonly kind: string = 'compat';
2121
readonly control: AbstractControl;
22-
readonly field!: FieldTree<unknown>;
22+
readonly fieldTree!: FieldTree<unknown>;
2323
readonly context: T;
2424
readonly message?: string;
2525

packages/forms/signals/src/api/rules/disabled.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(
3838
result = logic(ctx as FieldContext<TValue, TPathKind>);
3939
}
4040
if (typeof result === 'string') {
41-
return {field: ctx.field, message: result};
41+
return {fieldTree: ctx.fieldTree, message: result};
4242
}
43-
return result ? {field: ctx.field} : undefined;
43+
return result ? {fieldTree: ctx.fieldTree} : undefined;
4444
});
4545
}

packages/forms/signals/src/api/rules/validation/standard_schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ export function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProp
113113
/**
114114
* Converts a `StandardSchemaV1.Issue` to a `FormTreeError`.
115115
*
116-
* @param field The root field to which the issue's path is relative.
116+
* @param fieldTree The root field to which the issue's path is relative.
117117
* @param issue The `StandardSchemaV1.Issue` to convert.
118118
* @returns A `ValidationError` representing the issue.
119119
*/
120120
function standardIssueToFormTreeError(
121-
field: FieldTree<unknown>,
121+
fieldTree: FieldTree<unknown>,
122122
issue: StandardSchemaV1.Issue,
123123
): StandardSchemaValidationError {
124-
let target = field as FieldTree<Record<PropertyKey, unknown>>;
124+
let target = fieldTree as FieldTree<Record<PropertyKey, unknown>>;
125125
for (const pathPart of issue.path ?? []) {
126126
const pathKey = typeof pathPart === 'object' ? pathPart.key : pathPart;
127127
target = target[pathKey] as FieldTree<Record<PropertyKey, unknown>>;

packages/forms/signals/src/api/rules/validation/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function validate<TValue, TPathKind extends PathKind = PathKind.Root>(
3838
const pathNode = FieldPathNode.unwrapFieldPath(path);
3939
pathNode.builder.addSyncErrorRule((ctx) => {
4040
return ensureCustomValidationResult(
41-
addDefaultField(logic(ctx as FieldContext<TValue, TPathKind>), ctx.field),
41+
addDefaultField(logic(ctx as FieldContext<TValue, TPathKind>), ctx.fieldTree),
4242
);
4343
});
4444
}

packages/forms/signals/src/api/rules/validation/validate_async.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ export function validateAsync<TValue, TParams, TResult, TPathKind extends PathKi
143143
return undefined;
144144
}
145145
errors = opts.onSuccess(res.value()!, ctx as FieldContext<TValue, TPathKind>);
146-
return addDefaultField(errors, ctx.field);
146+
return addDefaultField(errors, ctx.fieldTree);
147147
case 'error':
148148
errors = opts.onError(res.error(), ctx as FieldContext<TValue, TPathKind>);
149-
return addDefaultField(errors, ctx.field);
149+
return addDefaultField(errors, ctx.fieldTree);
150150
}
151151
});
152152
}

packages/forms/signals/src/api/rules/validation/validate_tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>
3131

3232
const pathNode = FieldPathNode.unwrapFieldPath(path);
3333
pathNode.builder.addSyncTreeErrorRule((ctx) =>
34-
addDefaultField(logic(ctx as FieldContext<TValue, TPathKind>), ctx.field),
34+
addDefaultField(logic(ctx as FieldContext<TValue, TPathKind>), ctx.fieldTree),
3535
);
3636
}

packages/forms/signals/src/api/rules/validation/validation_errors.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ interface ValidationErrorOptions {
2323
*
2424
* @experimental 21.0.0
2525
*/
26-
export type WithField<T> = T & {field: FieldTree<unknown>};
26+
export type WithField<T> = T & {fieldTree: FieldTree<unknown>};
2727

2828
/**
2929
* A type that allows the given type `T` to optionally have a `field` property.
3030
* @template T The type to optionally add a `field` to.
3131
*
3232
* @experimental 21.0.0
3333
*/
34-
export type WithOptionalField<T> = Omit<T, 'field'> & {field?: FieldTree<unknown>};
34+
export type WithOptionalField<T> = Omit<T, 'fieldTree'> & {fieldTree?: FieldTree<unknown>};
3535

3636
/**
3737
* A type that ensures the given type `T` does not have a `field` property.
3838
* @template T The type to remove the `field` from.
3939
*
4040
* @experimental 21.0.0
4141
*/
42-
export type WithoutField<T> = T & {field: never};
42+
export type WithoutField<T> = T & {fieldTree: never};
4343

4444
/**
4545
* Create a required error associated with the target field
@@ -325,7 +325,7 @@ export declare namespace ValidationError {
325325
*/
326326
export interface WithField extends ValidationError {
327327
/** The field associated with this error. */
328-
readonly field: FieldTree<unknown>;
328+
readonly fieldTree: FieldTree<unknown>;
329329
}
330330

331331
/**
@@ -336,7 +336,7 @@ export declare namespace ValidationError {
336336
*/
337337
export interface WithOptionalField extends ValidationError {
338338
/** The field associated with this error. */
339-
readonly field?: FieldTree<unknown>;
339+
readonly fieldTree?: FieldTree<unknown>;
340340
}
341341

342342
/**
@@ -369,7 +369,7 @@ export class CustomValidationError implements ValidationError {
369369
readonly kind: string = '';
370370

371371
/** The field associated with this error. */
372-
readonly field!: FieldTree<unknown>;
372+
readonly fieldTree!: FieldTree<unknown>;
373373

374374
/** Human readable error message. */
375375
readonly message?: string;
@@ -395,7 +395,7 @@ abstract class _NgValidationError implements ValidationError {
395395
readonly kind: string = '';
396396

397397
/** The field associated with this error. */
398-
readonly field!: FieldTree<unknown>;
398+
readonly fieldTree!: FieldTree<unknown>;
399399

400400
/** Human readable error message. */
401401
readonly message?: string;

packages/forms/signals/src/api/structure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ function setServerErrors(
400400
const errorsByField = new Map<FieldNode, ValidationError.WithField[]>();
401401
for (const error of errors) {
402402
const errorWithField = addDefaultField(error, submittedField.fieldProxy);
403-
const field = errorWithField.field() as FieldNode;
403+
const field = errorWithField.fieldTree() as FieldNode;
404404
let fieldErrors = errorsByField.get(field);
405405
if (!fieldErrors) {
406406
fieldErrors = [];

0 commit comments

Comments
 (0)