@@ -83,6 +83,40 @@ export class DeleteFieldValueImpl extends SerializableFieldValue {
83
83
}
84
84
}
85
85
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
+
86
120
export class ServerTimestampFieldValueImpl extends SerializableFieldValue {
87
121
constructor ( readonly _methodName : string ) {
88
122
super ( ) ;
@@ -106,19 +140,10 @@ export class ArrayUnionFieldValueImpl extends SerializableFieldValue {
106
140
}
107
141
108
142
_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
122
147
) ;
123
148
const parsedElements = this . _elements . map (
124
149
element => parseData ( element , parseContext ) !
@@ -139,19 +164,10 @@ export class ArrayRemoveFieldValueImpl extends SerializableFieldValue {
139
164
}
140
165
141
166
_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
155
171
) ;
156
172
const parsedElements = this . _elements . map (
157
173
element => parseData ( element , parseContext ) !
@@ -172,15 +188,10 @@ export class NumericIncrementFieldValueImpl extends SerializableFieldValue {
172
188
}
173
189
174
190
_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
184
195
) ;
185
196
const operand = parseData ( this . _operand , parseContext ) ! ;
186
197
const numericIncrement = new NumericIncrementTransformOperation (
0 commit comments