FSTUserDataConverter.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FSTUserDataConverter.h"
  17. #import "FIRDocumentReference+Internal.h"
  18. #import "FIRFieldPath+Internal.h"
  19. #import "FIRFieldValue+Internal.h"
  20. #import "FIRFirestore+Internal.h"
  21. #import "FIRGeoPoint.h"
  22. #import "FIRSetOptions+Internal.h"
  23. #import "FSTAssert.h"
  24. #import "FSTDatabaseID.h"
  25. #import "FSTDocumentKey.h"
  26. #import "FSTFieldValue.h"
  27. #import "FSTMutation.h"
  28. #import "FSTPath.h"
  29. #import "FSTTimestamp.h"
  30. #import "FSTUsageValidation.h"
  31. NS_ASSUME_NONNULL_BEGIN
  32. static NSString *const RESERVED_FIELD_DESIGNATOR = @"__";
  33. #pragma mark - FSTParsedSetData
  34. @implementation FSTParsedSetData
  35. - (instancetype)initWithData:(FSTObjectValue *)data
  36. fieldMask:(nullable FSTFieldMask *)fieldMask
  37. fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms {
  38. self = [super init];
  39. if (self) {
  40. _data = data;
  41. _fieldMask = fieldMask;
  42. _fieldTransforms = fieldTransforms;
  43. }
  44. return self;
  45. }
  46. - (NSArray<FSTMutation *> *)mutationsWithKey:(FSTDocumentKey *)key
  47. precondition:(FSTPrecondition *)precondition {
  48. NSMutableArray<FSTMutation *> *mutations = [NSMutableArray array];
  49. if (self.fieldMask) {
  50. [mutations addObject:[[FSTPatchMutation alloc] initWithKey:key
  51. fieldMask:self.fieldMask
  52. value:self.data
  53. precondition:precondition]];
  54. } else {
  55. [mutations addObject:[[FSTSetMutation alloc] initWithKey:key
  56. value:self.data
  57. precondition:precondition]];
  58. }
  59. if (self.fieldTransforms.count > 0) {
  60. [mutations addObject:[[FSTTransformMutation alloc] initWithKey:key
  61. fieldTransforms:self.fieldTransforms]];
  62. }
  63. return mutations;
  64. }
  65. @end
  66. #pragma mark - FSTParsedUpdateData
  67. @implementation FSTParsedUpdateData
  68. - (instancetype)initWithData:(FSTObjectValue *)data
  69. fieldMask:(FSTFieldMask *)fieldMask
  70. fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms {
  71. self = [super init];
  72. if (self) {
  73. _data = data;
  74. _fieldMask = fieldMask;
  75. _fieldTransforms = fieldTransforms;
  76. }
  77. return self;
  78. }
  79. - (NSArray<FSTMutation *> *)mutationsWithKey:(FSTDocumentKey *)key
  80. precondition:(FSTPrecondition *)precondition {
  81. NSMutableArray<FSTMutation *> *mutations = [NSMutableArray array];
  82. [mutations addObject:[[FSTPatchMutation alloc] initWithKey:key
  83. fieldMask:self.fieldMask
  84. value:self.data
  85. precondition:precondition]];
  86. if (self.fieldTransforms.count > 0) {
  87. [mutations addObject:[[FSTTransformMutation alloc] initWithKey:key
  88. fieldTransforms:self.fieldTransforms]];
  89. }
  90. return mutations;
  91. }
  92. @end
  93. /**
  94. * Represents what type of API method provided the data being parsed; useful for determining which
  95. * error conditions apply during parsing and providing better error messages.
  96. */
  97. typedef NS_ENUM(NSInteger, FSTUserDataSource) {
  98. FSTUserDataSourceSet,
  99. FSTUserDataSourceUpdate,
  100. FSTUserDataSourceQueryValue, // from a where clause or cursor bound.
  101. };
  102. #pragma mark - FSTParseContext
  103. /**
  104. * A "context" object passed around while parsing user data.
  105. */
  106. @interface FSTParseContext : NSObject
  107. /** The current path being parsed. */
  108. // TODO(b/34871131): path should never be nil, but we don't support array paths right now.
  109. @property(strong, nonatomic, readonly, nullable) FSTFieldPath *path;
  110. /**
  111. * What type of API method provided the data being parsed; useful for determining which error
  112. * conditions apply during parsing and providing better error messages.
  113. */
  114. @property(nonatomic, assign) FSTUserDataSource dataSource;
  115. @property(nonatomic, strong, readonly) NSMutableArray<FSTFieldTransform *> *fieldTransforms;
  116. @property(nonatomic, strong, readonly) NSMutableArray<FSTFieldPath *> *fieldMask;
  117. - (instancetype)init NS_UNAVAILABLE;
  118. /**
  119. * Initializes a FSTParseContext with the given source and path.
  120. *
  121. * @param dataSource Indicates what kind of API method this data came from.
  122. * @param path A path within the object being parsed. This could be an empty path (in which case
  123. * the context represents the root of the data being parsed), or a nonempty path (indicating the
  124. * context represents a nested location within the data).
  125. *
  126. * TODO(b/34871131): We don't support array paths right now, so path can be nil to indicate
  127. * the context represents any location within an array (in which case certain features will not work
  128. * and errors will be somewhat compromised).
  129. */
  130. - (instancetype)initWithSource:(FSTUserDataSource)dataSource
  131. path:(nullable FSTFieldPath *)path
  132. fieldTransforms:(NSMutableArray<FSTFieldTransform *> *)fieldTransforms
  133. fieldMask:(NSMutableArray<FSTFieldPath *> *)fieldMask
  134. NS_DESIGNATED_INITIALIZER;
  135. // Helpers to get a FSTParseContext for a child field.
  136. - (instancetype)contextForField:(NSString *)fieldName;
  137. - (instancetype)contextForFieldPath:(FSTFieldPath *)fieldPath;
  138. - (instancetype)contextForArrayIndex:(NSUInteger)index;
  139. @end
  140. @implementation FSTParseContext
  141. + (instancetype)contextWithSource:(FSTUserDataSource)dataSource path:(nullable FSTFieldPath *)path {
  142. FSTParseContext *context = [[FSTParseContext alloc] initWithSource:dataSource
  143. path:path
  144. fieldTransforms:[NSMutableArray array]
  145. fieldMask:[NSMutableArray array]];
  146. [context validatePath];
  147. return context;
  148. }
  149. - (instancetype)initWithSource:(FSTUserDataSource)dataSource
  150. path:(nullable FSTFieldPath *)path
  151. fieldTransforms:(NSMutableArray<FSTFieldTransform *> *)fieldTransforms
  152. fieldMask:(NSMutableArray<FSTFieldPath *> *)fieldMask {
  153. if (self = [super init]) {
  154. _dataSource = dataSource;
  155. _path = path;
  156. _fieldTransforms = fieldTransforms;
  157. _fieldMask = fieldMask;
  158. }
  159. return self;
  160. }
  161. - (instancetype)contextForField:(NSString *)fieldName {
  162. FSTParseContext *context =
  163. [[FSTParseContext alloc] initWithSource:self.dataSource
  164. path:[self.path pathByAppendingSegment:fieldName]
  165. fieldTransforms:self.fieldTransforms
  166. fieldMask:self.fieldMask];
  167. [context validatePathSegment:fieldName];
  168. return context;
  169. }
  170. - (instancetype)contextForFieldPath:(FSTFieldPath *)fieldPath {
  171. FSTParseContext *context =
  172. [[FSTParseContext alloc] initWithSource:self.dataSource
  173. path:[self.path pathByAppendingPath:fieldPath]
  174. fieldTransforms:self.fieldTransforms
  175. fieldMask:self.fieldMask];
  176. [context validatePath];
  177. return context;
  178. }
  179. - (instancetype)contextForArrayIndex:(NSUInteger)index {
  180. // TODO(b/34871131): We don't support array paths right now; so make path nil.
  181. return [[FSTParseContext alloc] initWithSource:self.dataSource
  182. path:nil
  183. fieldTransforms:self.fieldTransforms
  184. fieldMask:self.fieldMask];
  185. }
  186. /**
  187. * Returns a string that can be appended to error messages indicating what field caused the error.
  188. */
  189. - (NSString *)fieldDescription {
  190. // TODO(b/34871131): Remove nil check once we have proper paths for fields within arrays.
  191. if (!self.path || self.path.empty) {
  192. return @"";
  193. } else {
  194. return [NSString stringWithFormat:@" (found in field %@)", self.path];
  195. }
  196. }
  197. - (BOOL)isWrite {
  198. return _dataSource == FSTUserDataSourceSet || _dataSource == FSTUserDataSourceUpdate;
  199. }
  200. - (void)validatePath {
  201. // TODO(b/34871131): Remove nil check once we have proper paths for fields within arrays.
  202. if (self.path == nil) {
  203. return;
  204. }
  205. for (int i = 0; i < self.path.length; i++) {
  206. [self validatePathSegment:[self.path segmentAtIndex:i]];
  207. }
  208. }
  209. - (void)validatePathSegment:(NSString *)segment {
  210. if ([self isWrite] && [segment hasPrefix:RESERVED_FIELD_DESIGNATOR] &&
  211. [segment hasSuffix:RESERVED_FIELD_DESIGNATOR]) {
  212. FSTThrowInvalidArgument(@"Document fields cannot begin and end with %@%@",
  213. RESERVED_FIELD_DESIGNATOR, [self fieldDescription]);
  214. }
  215. }
  216. @end
  217. #pragma mark - FSTDocumentKeyReference
  218. @implementation FSTDocumentKeyReference
  219. - (instancetype)initWithKey:(FSTDocumentKey *)key databaseID:(FSTDatabaseID *)databaseID {
  220. self = [super init];
  221. if (self) {
  222. _key = key;
  223. _databaseID = databaseID;
  224. }
  225. return self;
  226. }
  227. @end
  228. #pragma mark - FSTUserDataConverter
  229. @interface FSTUserDataConverter ()
  230. @property(strong, nonatomic, readonly) FSTDatabaseID *databaseID;
  231. @property(strong, nonatomic, readonly) FSTPreConverterBlock preConverter;
  232. @end
  233. @implementation FSTUserDataConverter
  234. - (instancetype)initWithDatabaseID:(FSTDatabaseID *)databaseID
  235. preConverter:(FSTPreConverterBlock)preConverter {
  236. self = [super init];
  237. if (self) {
  238. _databaseID = databaseID;
  239. _preConverter = preConverter;
  240. }
  241. return self;
  242. }
  243. - (FSTParsedSetData *)parsedSetData:(id)input options:(FIRSetOptions *)options {
  244. // NOTE: The public API is typed as NSDictionary but we type 'input' as 'id' since we can't trust
  245. // Obj-C to verify the type for us.
  246. if (![input isKindOfClass:[NSDictionary class]]) {
  247. FSTThrowInvalidArgument(@"Data to be written must be an NSDictionary.");
  248. }
  249. FSTParseContext *context =
  250. [FSTParseContext contextWithSource:FSTUserDataSourceSet path:[FSTFieldPath emptyPath]];
  251. __block FSTObjectValue *updateData = [FSTObjectValue objectValue];
  252. [input enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
  253. // Treat key as a complete field name (don't split on dots, etc.)
  254. FSTFieldPath *path = [[FIRFieldPath alloc] initWithFields:@[ key ]].internalValue;
  255. value = self.preConverter(value);
  256. FSTFieldValue *_Nullable parsedValue =
  257. [self parseData:value context:[context contextForFieldPath:path]];
  258. if (parsedValue) {
  259. updateData = [updateData objectBySettingValue:parsedValue forPath:path];
  260. }
  261. }];
  262. return [[FSTParsedSetData alloc]
  263. initWithData:updateData
  264. fieldMask:options.merge ? [[FSTFieldMask alloc] initWithFields:context.fieldMask] : nil
  265. fieldTransforms:context.fieldTransforms];
  266. }
  267. - (FSTParsedUpdateData *)parsedUpdateData:(id)input {
  268. // NOTE: The public API is typed as NSDictionary but we type 'input' as 'id' since we can't trust
  269. // Obj-C to verify the type for us.
  270. if (![input isKindOfClass:[NSDictionary class]]) {
  271. FSTThrowInvalidArgument(@"Data to be written must be an NSDictionary.");
  272. }
  273. NSDictionary *dict = input;
  274. NSMutableArray<FSTFieldPath *> *fieldMaskPaths = [NSMutableArray array];
  275. __block FSTObjectValue *updateData = [FSTObjectValue objectValue];
  276. FSTParseContext *context =
  277. [FSTParseContext contextWithSource:FSTUserDataSourceUpdate path:[FSTFieldPath emptyPath]];
  278. [dict enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
  279. FSTFieldPath *path;
  280. if ([key isKindOfClass:[NSString class]]) {
  281. path = [FIRFieldPath pathWithDotSeparatedString:key].internalValue;
  282. } else if ([key isKindOfClass:[FIRFieldPath class]]) {
  283. path = ((FIRFieldPath *)key).internalValue;
  284. } else {
  285. FSTThrowInvalidArgument(
  286. @"Dictionary keys in updateData: must be NSStrings or FIRFieldPaths.");
  287. }
  288. value = self.preConverter(value);
  289. if ([value isKindOfClass:[FSTDeleteFieldValue class]]) {
  290. // Add it to the field mask, but don't add anything to updateData.
  291. [fieldMaskPaths addObject:path];
  292. } else {
  293. FSTFieldValue *_Nullable parsedValue =
  294. [self parseData:value context:[context contextForFieldPath:path]];
  295. if (parsedValue) {
  296. [fieldMaskPaths addObject:path];
  297. updateData = [updateData objectBySettingValue:parsedValue forPath:path];
  298. }
  299. }
  300. }];
  301. FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:fieldMaskPaths];
  302. return [[FSTParsedUpdateData alloc] initWithData:updateData
  303. fieldMask:mask
  304. fieldTransforms:context.fieldTransforms];
  305. }
  306. - (FSTFieldValue *)parsedQueryValue:(id)input {
  307. FSTParseContext *context =
  308. [FSTParseContext contextWithSource:FSTUserDataSourceQueryValue path:[FSTFieldPath emptyPath]];
  309. FSTFieldValue *_Nullable parsed = [self parseData:input context:context];
  310. FSTAssert(parsed, @"Parsed data should not be nil.");
  311. FSTAssert(context.fieldTransforms.count == 0, @"Field transforms should have been disallowed.");
  312. return parsed;
  313. }
  314. /**
  315. * Internal helper for parsing user data.
  316. *
  317. * @param input Data to be parsed.
  318. * @param context A context object representing the current path being parsed, the source of the
  319. * data being parsed, etc.
  320. *
  321. * @return The parsed value, or nil if the value was a FieldValue sentinel that should not be
  322. * included in the resulting parsed data.
  323. */
  324. - (nullable FSTFieldValue *)parseData:(id)input context:(FSTParseContext *)context {
  325. input = self.preConverter(input);
  326. if ([input isKindOfClass:[NSArray class]]) {
  327. // TODO(b/34871131): We may need a different way to detect nested arrays once we support array
  328. // paths (at which point we should include the path containing the array in the error message).
  329. if (!context.path) {
  330. FSTThrowInvalidArgument(@"Nested arrays are not supported");
  331. }
  332. NSArray *array = input;
  333. NSMutableArray<FSTFieldValue *> *result = [NSMutableArray arrayWithCapacity:array.count];
  334. [array enumerateObjectsUsingBlock:^(id entry, NSUInteger idx, BOOL *stop) {
  335. FSTFieldValue *_Nullable parsedEntry =
  336. [self parseData:entry context:[context contextForArrayIndex:idx]];
  337. if (!parsedEntry) {
  338. // Just include nulls in the array for fields being replaced with a sentinel.
  339. parsedEntry = [FSTNullValue nullValue];
  340. }
  341. [result addObject:parsedEntry];
  342. }];
  343. // We don't support field mask paths more granular than the top-level array.
  344. [context.fieldMask addObject:context.path];
  345. return [[FSTArrayValue alloc] initWithValueNoCopy:result];
  346. } else if ([input isKindOfClass:[NSDictionary class]]) {
  347. NSDictionary *dict = input;
  348. NSMutableDictionary<NSString *, FSTFieldValue *> *result =
  349. [NSMutableDictionary dictionaryWithCapacity:dict.count];
  350. [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
  351. FSTFieldValue *_Nullable parsedValue =
  352. [self parseData:value context:[context contextForField:key]];
  353. if (parsedValue) {
  354. result[key] = parsedValue;
  355. }
  356. }];
  357. return [[FSTObjectValue alloc] initWithDictionary:result];
  358. } else {
  359. // If context.path is null, we are inside an array and we should have already added the root of
  360. // the array to the field mask.
  361. if (context.path) {
  362. [context.fieldMask addObject:context.path];
  363. }
  364. return [self parseScalarValue:input context:context];
  365. }
  366. }
  367. /**
  368. * Helper to parse a scalar value (i.e. not an NSDictionary or NSArray).
  369. *
  370. * Note that it handles all NSNumber values that are encodable as int64_t or doubles
  371. * (depending on the underlying type of the NSNumber). Unsigned integer values are handled though
  372. * any value outside what is representable by int64_t (a signed 64-bit value) will throw an
  373. * exception.
  374. *
  375. * @return The parsed value, or nil if the value was a FieldValue sentinel that should not be
  376. * included in the resulting parsed data.
  377. */
  378. - (nullable FSTFieldValue *)parseScalarValue:(nullable id)input context:(FSTParseContext *)context {
  379. if (!input || [input isMemberOfClass:[NSNull class]]) {
  380. return [FSTNullValue nullValue];
  381. } else if ([input isKindOfClass:[NSNumber class]]) {
  382. // Recover the underlying type of the number, using the method described here:
  383. // http://stackoverflow.com/questions/2518761/get-type-of-nsnumber
  384. const char *cType = [input objCType];
  385. // Type Encoding values taken from
  386. // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/
  387. // Articles/ocrtTypeEncodings.html
  388. switch (cType[0]) {
  389. case 'q':
  390. return [FSTIntegerValue integerValue:[input longLongValue]];
  391. case 'i': // Falls through.
  392. case 's': // Falls through.
  393. case 'l': // Falls through.
  394. case 'I': // Falls through.
  395. case 'S':
  396. // Coerce integer values that aren't long long. Allow unsigned integer types that are
  397. // guaranteed small enough to skip a length check.
  398. return [FSTIntegerValue integerValue:[input longLongValue]];
  399. case 'L': // Falls through.
  400. case 'Q':
  401. // Unsigned integers that could be too large. Note that the 'L' (long) case is handled here
  402. // because when compiled for LP64, unsigned long is 64 bits and could overflow int64_t.
  403. {
  404. unsigned long long extended = [input unsignedLongLongValue];
  405. if (extended > LLONG_MAX) {
  406. FSTThrowInvalidArgument(@"NSNumber (%llu) is too large%@",
  407. [input unsignedLongLongValue], [context fieldDescription]);
  408. } else {
  409. return [FSTIntegerValue integerValue:(int64_t)extended];
  410. }
  411. }
  412. case 'f':
  413. return [FSTDoubleValue doubleValue:[input doubleValue]];
  414. case 'd':
  415. // Double values are already the right type, so just reuse the existing boxed double.
  416. //
  417. // Note that NSNumber already performs NaN normalization to a single shared instance
  418. // so there's no need to treat NaN specially here.
  419. return [FSTDoubleValue doubleValue:[input doubleValue]];
  420. case 'B': // Falls through.
  421. case 'c': // Falls through.
  422. case 'C':
  423. // Boolean values are weird.
  424. //
  425. // On arm64, objCType of a BOOL-valued NSNumber will be "c", even though @encode(BOOL)
  426. // returns "B". "c" is the same as @encode(signed char). Unfortunately this means that
  427. // legitimate usage of signed chars is impossible, but this should be rare.
  428. //
  429. // Additionally, for consistency, map unsigned chars to bools in the same way.
  430. return [FSTBooleanValue booleanValue:[input boolValue]];
  431. default:
  432. // All documented codes should be handled above, so this shouldn't happen.
  433. FSTCFail(@"Unknown NSNumber objCType %s on %@", cType, input);
  434. }
  435. } else if ([input isKindOfClass:[NSString class]]) {
  436. return [FSTStringValue stringValue:input];
  437. } else if ([input isKindOfClass:[NSDate class]]) {
  438. return [FSTTimestampValue timestampValue:[FSTTimestamp timestampWithDate:input]];
  439. } else if ([input isKindOfClass:[FIRGeoPoint class]]) {
  440. return [FSTGeoPointValue geoPointValue:input];
  441. } else if ([input isKindOfClass:[NSData class]]) {
  442. return [FSTBlobValue blobValue:input];
  443. } else if ([input isKindOfClass:[FSTDocumentKeyReference class]]) {
  444. FSTDocumentKeyReference *reference = input;
  445. if (![reference.databaseID isEqual:self.databaseID]) {
  446. FSTDatabaseID *other = reference.databaseID;
  447. FSTThrowInvalidArgument(
  448. @"Document Reference is for database %@/%@ but should be for database %@/%@%@",
  449. other.projectID, other.databaseID, self.databaseID.projectID, self.databaseID.databaseID,
  450. [context fieldDescription]);
  451. }
  452. return [FSTReferenceValue referenceValue:reference.key databaseID:self.databaseID];
  453. } else if ([input isKindOfClass:[FIRFieldValue class]]) {
  454. if ([input isKindOfClass:[FSTDeleteFieldValue class]]) {
  455. // We shouldn't encounter delete sentinels here. Provide a good error.
  456. if (context.dataSource != FSTUserDataSourceUpdate) {
  457. FSTThrowInvalidArgument(@"FieldValue.delete() can only be used with updateData().");
  458. } else {
  459. FSTAssert(context.path.length > 0,
  460. @"FieldValue.delete() at the top level should have already been handled.");
  461. FSTThrowInvalidArgument(
  462. @"FieldValue.delete() can only appear at the top level of your "
  463. "update data%@",
  464. [context fieldDescription]);
  465. }
  466. } else if ([input isKindOfClass:[FSTServerTimestampFieldValue class]]) {
  467. if (context.dataSource != FSTUserDataSourceSet &&
  468. context.dataSource != FSTUserDataSourceUpdate) {
  469. FSTThrowInvalidArgument(
  470. @"FieldValue.serverTimestamp() can only be used with setData() and updateData().");
  471. }
  472. if (!context.path) {
  473. FSTThrowInvalidArgument(
  474. @"FieldValue.serverTimestamp() is not currently supported inside arrays%@",
  475. [context fieldDescription]);
  476. }
  477. [context.fieldTransforms
  478. addObject:[[FSTFieldTransform alloc]
  479. initWithPath:context.path
  480. transform:[FSTServerTimestampTransform serverTimestampTransform]]];
  481. // Return nil so this value is omitted from the parsed result.
  482. return nil;
  483. } else {
  484. FSTFail(@"Unknown FIRFieldValue type: %@", NSStringFromClass([input class]));
  485. }
  486. } else {
  487. FSTThrowInvalidArgument(@"Unsupported type: %@%@", NSStringFromClass([input class]),
  488. [context fieldDescription]);
  489. }
  490. }
  491. @end
  492. NS_ASSUME_NONNULL_END