Skip to content

Commit bed5f18

Browse files
committed
Review feedback
1 parent 2ca7928 commit bed5f18

File tree

2 files changed

+48
-37
lines changed

2 files changed

+48
-37
lines changed

packages/firestore/src/api/field_value.ts

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,40 @@ export class DeleteFieldValueImpl extends SerializableFieldValue {
8383
}
8484
}
8585

86+
/**
87+
* Creates a child context for parsing SerializableFieldValues.
88+
*
89+
* This is different than calling `ParseContext.contextWith` because it keeps
90+
* the fieldTransforms and fieldMask separate.
91+
*
92+
* The created context has its `dataSource` set to `UserDataSource.Argument`.
93+
* Although these values are used with writes, any elements in these FieldValues
94+
* are not considered writes since they cannot contain any FieldValue sentinels,
95+
* etc.
96+
*
97+
* @param fieldValue The sentinel FieldValue for which to create a child
98+
* context.
99+
* @param context The parent context.
100+
* @param arrayElement Whether or not the FieldValue has an array.
101+
*/
102+
function createSentinelChildContext(
103+
fieldValue: SerializableFieldValue,
104+
context: ParseContext,
105+
arrayElement: boolean
106+
): ParseContext {
107+
return new ParseContext(
108+
{
109+
dataSource: UserDataSource.Argument,
110+
targetDoc: context.settings.targetDoc,
111+
methodName: fieldValue._methodName,
112+
arrayElement
113+
},
114+
context.databaseId,
115+
context.serializer,
116+
context.ignoreUndefinedProperties
117+
);
118+
}
119+
86120
export class ServerTimestampFieldValueImpl extends SerializableFieldValue {
87121
constructor(readonly _methodName: string) {
88122
super();
@@ -106,19 +140,10 @@ export class ArrayUnionFieldValueImpl extends SerializableFieldValue {
106140
}
107141

108142
_toFieldTransform(context: ParseContext): FieldTransform {
109-
// Although array transforms are used with writes, the actual elements
110-
// being unioned or removed are not considered writes since they cannot
111-
// contain any FieldValue sentinels, etc.
112-
const parseContext = new ParseContext(
113-
{
114-
dataSource: UserDataSource.Argument,
115-
targetDoc: context.settings.targetDoc,
116-
methodName: this._methodName,
117-
arrayElement: true
118-
},
119-
context.databaseId,
120-
context.serializer,
121-
context.ignoreUndefinedProperties
143+
const parseContext = createSentinelChildContext(
144+
this,
145+
context,
146+
/*array=*/ true
122147
);
123148
const parsedElements = this._elements.map(
124149
element => parseData(element, parseContext)!
@@ -139,19 +164,10 @@ export class ArrayRemoveFieldValueImpl extends SerializableFieldValue {
139164
}
140165

141166
_toFieldTransform(context: ParseContext): FieldTransform {
142-
// Although array transforms are used with writes, the actual elements
143-
// being unioned or removed are not considered writes since they cannot
144-
// contain any FieldValue sentinels, etc.
145-
const parseContext = new ParseContext(
146-
{
147-
dataSource: UserDataSource.Argument,
148-
targetDoc: context.settings.targetDoc,
149-
methodName: this._methodName,
150-
arrayElement: true
151-
},
152-
context.databaseId,
153-
context.serializer,
154-
context.ignoreUndefinedProperties
167+
const parseContext = createSentinelChildContext(
168+
this,
169+
context,
170+
/*array=*/ true
155171
);
156172
const parsedElements = this._elements.map(
157173
element => parseData(element, parseContext)!
@@ -172,15 +188,10 @@ export class NumericIncrementFieldValueImpl extends SerializableFieldValue {
172188
}
173189

174190
_toFieldTransform(context: ParseContext): FieldTransform {
175-
const parseContext = new ParseContext(
176-
{
177-
dataSource: UserDataSource.Argument,
178-
targetDoc: context.settings.targetDoc,
179-
methodName: this._methodName
180-
},
181-
context.databaseId,
182-
context.serializer,
183-
context.ignoreUndefinedProperties
191+
const parseContext = createSentinelChildContext(
192+
this,
193+
context,
194+
/*array=*/ false
184195
);
185196
const operand = parseData(this._operand, parseContext)!;
186197
const numericIncrement = new NumericIncrementTransformOperation(

packages/firestore/src/api/user_data_reader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,10 @@ function createError(
804804
description += ' (found';
805805

806806
if (hasPath) {
807-
description += ` in field ${path!.toString()}`;
807+
description += ` in field ${path}`;
808808
}
809809
if (hasDocument) {
810-
description += ` in document ${targetDoc!.toString()}`;
810+
description += ` in document ${targetDoc}`;
811811
}
812812
description += ')';
813813
}

0 commit comments

Comments
 (0)