FIRQuery.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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 "FIRQuery.h"
  17. #import "FIRDocumentReference+Internal.h"
  18. #import "FIRDocumentReference.h"
  19. #import "FIRDocumentSnapshot+Internal.h"
  20. #import "FIRFieldPath+Internal.h"
  21. #import "FIRFirestore+Internal.h"
  22. #import "FIRListenerRegistration+Internal.h"
  23. #import "FIRQuery+Internal.h"
  24. #import "FIRQuerySnapshot+Internal.h"
  25. #import "FIRQuery_Init.h"
  26. #import "FIRSnapshotMetadata+Internal.h"
  27. #import "FSTAssert.h"
  28. #import "FSTAsyncQueryListener.h"
  29. #import "FSTDocument.h"
  30. #import "FSTDocumentKey.h"
  31. #import "FSTEventManager.h"
  32. #import "FSTFieldValue.h"
  33. #import "FSTFirestoreClient.h"
  34. #import "FSTPath.h"
  35. #import "FSTQuery.h"
  36. #import "FSTUsageValidation.h"
  37. #import "FSTUserDataConverter.h"
  38. NS_ASSUME_NONNULL_BEGIN
  39. @interface FIRQueryListenOptions ()
  40. - (instancetype)initWithIncludeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges
  41. includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges
  42. NS_DESIGNATED_INITIALIZER;
  43. @end
  44. @implementation FIRQueryListenOptions
  45. + (instancetype)options {
  46. return [[FIRQueryListenOptions alloc] init];
  47. }
  48. - (instancetype)initWithIncludeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges
  49. includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges {
  50. if (self = [super init]) {
  51. _includeQueryMetadataChanges = includeQueryMetadataChanges;
  52. _includeDocumentMetadataChanges = includeDocumentMetadataChanges;
  53. }
  54. return self;
  55. }
  56. - (instancetype)init {
  57. return [self initWithIncludeQueryMetadataChanges:NO includeDocumentMetadataChanges:NO];
  58. }
  59. - (instancetype)includeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges {
  60. return [[FIRQueryListenOptions alloc]
  61. initWithIncludeQueryMetadataChanges:includeQueryMetadataChanges
  62. includeDocumentMetadataChanges:_includeDocumentMetadataChanges];
  63. }
  64. - (instancetype)includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges {
  65. return [[FIRQueryListenOptions alloc]
  66. initWithIncludeQueryMetadataChanges:_includeQueryMetadataChanges
  67. includeDocumentMetadataChanges:includeDocumentMetadataChanges];
  68. }
  69. @end
  70. @interface FIRQuery ()
  71. @property(nonatomic, strong, readonly) FSTQuery *query;
  72. @end
  73. @implementation FIRQuery (Internal)
  74. + (instancetype)referenceWithQuery:(FSTQuery *)query firestore:(FIRFirestore *)firestore {
  75. return [[FIRQuery alloc] initWithQuery:query firestore:firestore];
  76. }
  77. @end
  78. @implementation FIRQuery
  79. #pragma mark - Public Methods
  80. - (instancetype)initWithQuery:(FSTQuery *)query firestore:(FIRFirestore *)firestore {
  81. if (self = [super init]) {
  82. _query = query;
  83. _firestore = firestore;
  84. }
  85. return self;
  86. }
  87. - (void)getDocumentsWithCompletion:(void (^)(FIRQuerySnapshot *_Nullable snapshot,
  88. NSError *_Nullable error))completion {
  89. FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
  90. includeDocumentMetadataChanges:YES
  91. waitForSyncWhenOnline:YES];
  92. dispatch_semaphore_t registered = dispatch_semaphore_create(0);
  93. __block id<FIRListenerRegistration> listenerRegistration;
  94. FIRQuerySnapshotBlock listener = ^(FIRQuerySnapshot *snapshot, NSError *error) {
  95. if (error) {
  96. completion(nil, error);
  97. return;
  98. }
  99. // Remove query first before passing event to user to avoid user actions affecting the
  100. // now stale query.
  101. dispatch_semaphore_wait(registered, DISPATCH_TIME_FOREVER);
  102. [listenerRegistration remove];
  103. completion(snapshot, nil);
  104. };
  105. listenerRegistration = [self addSnapshotListenerInternalWithOptions:options listener:listener];
  106. dispatch_semaphore_signal(registered);
  107. }
  108. - (id<FIRListenerRegistration>)addSnapshotListener:(FIRQuerySnapshotBlock)listener {
  109. return [self addSnapshotListenerWithOptions:nil listener:listener];
  110. }
  111. - (id<FIRListenerRegistration>)addSnapshotListenerWithOptions:
  112. (nullable FIRQueryListenOptions *)options
  113. listener:(FIRQuerySnapshotBlock)listener {
  114. return [self addSnapshotListenerInternalWithOptions:[self internalOptions:options]
  115. listener:listener];
  116. }
  117. - (id<FIRListenerRegistration>)
  118. addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
  119. listener:(FIRQuerySnapshotBlock)listener {
  120. FIRFirestore *firestore = self.firestore;
  121. FSTQuery *query = self.query;
  122. FSTViewSnapshotHandler snapshotHandler = ^(FSTViewSnapshot *snapshot, NSError *error) {
  123. if (error) {
  124. listener(nil, error);
  125. return;
  126. }
  127. FIRSnapshotMetadata *metadata =
  128. [FIRSnapshotMetadata snapshotMetadataWithPendingWrites:snapshot.hasPendingWrites
  129. fromCache:snapshot.fromCache];
  130. listener([FIRQuerySnapshot snapshotWithFirestore:firestore
  131. originalQuery:query
  132. snapshot:snapshot
  133. metadata:metadata],
  134. nil);
  135. };
  136. FSTAsyncQueryListener *asyncListener =
  137. [[FSTAsyncQueryListener alloc] initWithDispatchQueue:self.firestore.client.userDispatchQueue
  138. snapshotHandler:snapshotHandler];
  139. FSTQueryListener *internalListener =
  140. [firestore.client listenToQuery:query
  141. options:internalOptions
  142. viewSnapshotHandler:[asyncListener asyncSnapshotHandler]];
  143. return [[FSTListenerRegistration alloc] initWithClient:self.firestore.client
  144. asyncListener:asyncListener
  145. internalListener:internalListener];
  146. }
  147. - (FIRQuery *)queryWhereField:(NSString *)field isEqualTo:(id)value {
  148. return [self queryWithFilterOperator:FSTRelationFilterOperatorEqual field:field value:value];
  149. }
  150. - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isEqualTo:(id)value {
  151. return [self queryWithFilterOperator:FSTRelationFilterOperatorEqual
  152. path:path.internalValue
  153. value:value];
  154. }
  155. - (FIRQuery *)queryWhereField:(NSString *)field isLessThan:(id)value {
  156. return [self queryWithFilterOperator:FSTRelationFilterOperatorLessThan field:field value:value];
  157. }
  158. - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isLessThan:(id)value {
  159. return [self queryWithFilterOperator:FSTRelationFilterOperatorLessThan
  160. path:path.internalValue
  161. value:value];
  162. }
  163. - (FIRQuery *)queryWhereField:(NSString *)field isLessThanOrEqualTo:(id)value {
  164. return [self queryWithFilterOperator:FSTRelationFilterOperatorLessThanOrEqual
  165. field:field
  166. value:value];
  167. }
  168. - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isLessThanOrEqualTo:(id)value {
  169. return [self queryWithFilterOperator:FSTRelationFilterOperatorLessThanOrEqual
  170. path:path.internalValue
  171. value:value];
  172. }
  173. - (FIRQuery *)queryWhereField:(NSString *)field isGreaterThan:(id)value {
  174. return
  175. [self queryWithFilterOperator:FSTRelationFilterOperatorGreaterThan field:field value:value];
  176. }
  177. - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isGreaterThan:(id)value {
  178. return [self queryWithFilterOperator:FSTRelationFilterOperatorGreaterThan
  179. path:path.internalValue
  180. value:value];
  181. }
  182. - (FIRQuery *)queryWhereField:(NSString *)field isGreaterThanOrEqualTo:(id)value {
  183. return [self queryWithFilterOperator:FSTRelationFilterOperatorGreaterThanOrEqual
  184. field:field
  185. value:value];
  186. }
  187. - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isGreaterThanOrEqualTo:(id)value {
  188. return [self queryWithFilterOperator:FSTRelationFilterOperatorGreaterThanOrEqual
  189. path:path.internalValue
  190. value:value];
  191. }
  192. - (FIRQuery *)queryOrderedByField:(NSString *)field {
  193. return
  194. [self queryOrderedByFieldPath:[FIRFieldPath pathWithDotSeparatedString:field] descending:NO];
  195. }
  196. - (FIRQuery *)queryOrderedByFieldPath:(FIRFieldPath *)fieldPath {
  197. return [self queryOrderedByFieldPath:fieldPath descending:NO];
  198. }
  199. - (FIRQuery *)queryOrderedByField:(NSString *)field descending:(BOOL)descending {
  200. return [self queryOrderedByFieldPath:[FIRFieldPath pathWithDotSeparatedString:field]
  201. descending:descending];
  202. }
  203. - (FIRQuery *)queryOrderedByFieldPath:(FIRFieldPath *)fieldPath descending:(BOOL)descending {
  204. [self validateNewOrderByPath:fieldPath.internalValue];
  205. if (self.query.startAt) {
  206. FSTThrowInvalidUsage(
  207. @"InvalidQueryException",
  208. @"Invalid query. You must not specify a starting point before specifying the order by.");
  209. }
  210. if (self.query.endAt) {
  211. FSTThrowInvalidUsage(
  212. @"InvalidQueryException",
  213. @"Invalid query. You must not specify an ending point before specifying the order by.");
  214. }
  215. FSTSortOrder *sortOrder =
  216. [FSTSortOrder sortOrderWithFieldPath:fieldPath.internalValue ascending:!descending];
  217. return [FIRQuery referenceWithQuery:[self.query queryByAddingSortOrder:sortOrder]
  218. firestore:self.firestore];
  219. }
  220. - (FIRQuery *)queryLimitedTo:(NSInteger)limit {
  221. if (limit <= 0) {
  222. FSTThrowInvalidArgument(@"Invalid Query. Query limit (%ld) is invalid. Limit must be positive.",
  223. (long)limit);
  224. }
  225. return [FIRQuery referenceWithQuery:[self.query queryBySettingLimit:limit] firestore:_firestore];
  226. }
  227. - (FIRQuery *)queryStartingAtDocument:(FIRDocumentSnapshot *)snapshot {
  228. FSTBound *bound = [self boundFromSnapshot:snapshot isBefore:YES];
  229. return [FIRQuery referenceWithQuery:[self.query queryByAddingStartAt:bound]
  230. firestore:self.firestore];
  231. }
  232. - (FIRQuery *)queryStartingAtValues:(NSArray *)fieldValues {
  233. FSTBound *bound = [self boundFromFieldValues:fieldValues isBefore:YES];
  234. return [FIRQuery referenceWithQuery:[self.query queryByAddingStartAt:bound]
  235. firestore:self.firestore];
  236. }
  237. - (FIRQuery *)queryStartingAfterDocument:(FIRDocumentSnapshot *)snapshot {
  238. FSTBound *bound = [self boundFromSnapshot:snapshot isBefore:NO];
  239. return [FIRQuery referenceWithQuery:[self.query queryByAddingStartAt:bound]
  240. firestore:self.firestore];
  241. }
  242. - (FIRQuery *)queryStartingAfterValues:(NSArray *)fieldValues {
  243. FSTBound *bound = [self boundFromFieldValues:fieldValues isBefore:NO];
  244. return [FIRQuery referenceWithQuery:[self.query queryByAddingStartAt:bound]
  245. firestore:self.firestore];
  246. }
  247. - (FIRQuery *)queryEndingBeforeDocument:(FIRDocumentSnapshot *)snapshot {
  248. FSTBound *bound = [self boundFromSnapshot:snapshot isBefore:YES];
  249. return
  250. [FIRQuery referenceWithQuery:[self.query queryByAddingEndAt:bound] firestore:self.firestore];
  251. }
  252. - (FIRQuery *)queryEndingBeforeValues:(NSArray *)fieldValues {
  253. FSTBound *bound = [self boundFromFieldValues:fieldValues isBefore:YES];
  254. return
  255. [FIRQuery referenceWithQuery:[self.query queryByAddingEndAt:bound] firestore:self.firestore];
  256. }
  257. - (FIRQuery *)queryEndingAtDocument:(FIRDocumentSnapshot *)snapshot {
  258. FSTBound *bound = [self boundFromSnapshot:snapshot isBefore:NO];
  259. return
  260. [FIRQuery referenceWithQuery:[self.query queryByAddingEndAt:bound] firestore:self.firestore];
  261. }
  262. - (FIRQuery *)queryEndingAtValues:(NSArray *)fieldValues {
  263. FSTBound *bound = [self boundFromFieldValues:fieldValues isBefore:NO];
  264. return
  265. [FIRQuery referenceWithQuery:[self.query queryByAddingEndAt:bound] firestore:self.firestore];
  266. }
  267. #pragma mark - Private Methods
  268. /** Private helper for all of the queryWhereField: methods. */
  269. - (FIRQuery *)queryWithFilterOperator:(FSTRelationFilterOperator)filterOperator
  270. field:(NSString *)field
  271. value:(id)value {
  272. return [self queryWithFilterOperator:filterOperator
  273. path:[FIRFieldPath pathWithDotSeparatedString:field].internalValue
  274. value:value];
  275. }
  276. - (FIRQuery *)queryWithFilterOperator:(FSTRelationFilterOperator)filterOperator
  277. path:(FSTFieldPath *)fieldPath
  278. value:(id)value {
  279. FSTFieldValue *fieldValue;
  280. if ([fieldPath isKeyFieldPath]) {
  281. if ([value isKindOfClass:[NSString class]]) {
  282. NSString *documentKey = (NSString *)value;
  283. if ([documentKey containsString:@"/"]) {
  284. FSTThrowInvalidArgument(
  285. @"Invalid query. When querying by document ID you must provide "
  286. "a valid document ID, but '%@' contains a '/' character.",
  287. documentKey);
  288. } else if (documentKey.length == 0) {
  289. FSTThrowInvalidArgument(
  290. @"Invalid query. When querying by document ID you must provide "
  291. "a valid document ID, but it was an empty string.");
  292. }
  293. FSTResourcePath *path = [self.query.path pathByAppendingSegment:documentKey];
  294. fieldValue = [FSTReferenceValue referenceValue:[FSTDocumentKey keyWithPath:path]
  295. databaseID:self.firestore.databaseID];
  296. } else if ([value isKindOfClass:[FIRDocumentReference class]]) {
  297. FIRDocumentReference *ref = (FIRDocumentReference *)value;
  298. fieldValue = [FSTReferenceValue referenceValue:ref.key databaseID:self.firestore.databaseID];
  299. } else {
  300. FSTThrowInvalidArgument(
  301. @"Invalid query. When querying by document ID you must provide a "
  302. "valid string or DocumentReference, but it was of type: %@",
  303. NSStringFromClass([value class]));
  304. }
  305. } else {
  306. fieldValue = [self.firestore.dataConverter parsedQueryValue:value];
  307. }
  308. id<FSTFilter> filter;
  309. if ([fieldValue isEqual:[FSTNullValue nullValue]]) {
  310. if (filterOperator != FSTRelationFilterOperatorEqual) {
  311. FSTThrowInvalidUsage(@"InvalidQueryException",
  312. @"Invalid Query. You can only perform equality comparisons on nil / "
  313. "NSNull.");
  314. }
  315. filter = [[FSTNullFilter alloc] initWithField:fieldPath];
  316. } else if ([fieldValue isEqual:[FSTDoubleValue nanValue]]) {
  317. if (filterOperator != FSTRelationFilterOperatorEqual) {
  318. FSTThrowInvalidUsage(@"InvalidQueryException",
  319. @"Invalid Query. You can only perform equality comparisons on NaN.");
  320. }
  321. filter = [[FSTNanFilter alloc] initWithField:fieldPath];
  322. } else {
  323. filter = [FSTRelationFilter filterWithField:fieldPath
  324. filterOperator:filterOperator
  325. value:fieldValue];
  326. [self validateNewRelationFilter:filter];
  327. }
  328. return [FIRQuery referenceWithQuery:[self.query queryByAddingFilter:filter]
  329. firestore:self.firestore];
  330. }
  331. - (void)validateNewRelationFilter:(FSTRelationFilter *)filter {
  332. if ([filter isInequality]) {
  333. FSTFieldPath *existingField = [self.query inequalityFilterField];
  334. if (existingField && ![existingField isEqual:filter.field]) {
  335. FSTThrowInvalidUsage(
  336. @"InvalidQueryException",
  337. @"Invalid Query. All where filters with an inequality "
  338. "(lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) must be on the same "
  339. "field. But you have inequality filters on '%@' and '%@'",
  340. existingField, filter.field);
  341. }
  342. FSTFieldPath *firstOrderByField = [self.query firstSortOrderField];
  343. if (firstOrderByField) {
  344. [self validateOrderByField:firstOrderByField matchesInequalityField:filter.field];
  345. }
  346. }
  347. }
  348. - (void)validateNewOrderByPath:(FSTFieldPath *)fieldPath {
  349. if (![self.query firstSortOrderField]) {
  350. // This is the first order by. It must match any inequality.
  351. FSTFieldPath *inequalityField = [self.query inequalityFilterField];
  352. if (inequalityField) {
  353. [self validateOrderByField:fieldPath matchesInequalityField:inequalityField];
  354. }
  355. }
  356. }
  357. - (void)validateOrderByField:(FSTFieldPath *)orderByField
  358. matchesInequalityField:(FSTFieldPath *)inequalityField {
  359. if (!([orderByField isEqual:inequalityField])) {
  360. FSTThrowInvalidUsage(
  361. @"InvalidQueryException",
  362. @"Invalid query. You have a where filter with an "
  363. "inequality (lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) on field '%@' "
  364. "and so you must also use '%@' as your first queryOrderedBy field, but your first "
  365. "queryOrderedBy is currently on field '%@' instead.",
  366. inequalityField, inequalityField, orderByField);
  367. }
  368. }
  369. /**
  370. * Create a FSTBound from a query given the document.
  371. *
  372. * Note that the FSTBound will always include the key of the document and the position will be
  373. * unambiguous.
  374. *
  375. * Will throw if the document does not contain all fields of the order by of the query.
  376. */
  377. - (FSTBound *)boundFromSnapshot:(FIRDocumentSnapshot *)snapshot isBefore:(BOOL)isBefore {
  378. if (![snapshot exists]) {
  379. FSTThrowInvalidUsage(@"InvalidQueryException",
  380. @"Invalid query. You are trying to start or end a query using a document "
  381. @"that doesn't exist.");
  382. }
  383. FSTDocument *document = snapshot.internalDocument;
  384. NSMutableArray<FSTFieldValue *> *components = [NSMutableArray array];
  385. // Because people expect to continue/end a query at the exact document provided, we need to
  386. // use the implicit sort order rather than the explicit sort order, because it's guaranteed to
  387. // contain the document key. That way the position becomes unambiguous and the query
  388. // continues/ends exactly at the provided document. Without the key (by using the explicit sort
  389. // orders), multiple documents could match the position, yielding duplicate results.
  390. for (FSTSortOrder *sortOrder in self.query.sortOrders) {
  391. if ([sortOrder.field isEqual:[FSTFieldPath keyFieldPath]]) {
  392. [components addObject:[FSTReferenceValue referenceValue:document.key
  393. databaseID:self.firestore.databaseID]];
  394. } else {
  395. FSTFieldValue *value = [document fieldForPath:sortOrder.field];
  396. if (value != nil) {
  397. [components addObject:value];
  398. } else {
  399. FSTThrowInvalidUsage(@"InvalidQueryException",
  400. @"Invalid query. You are trying to start or end a query using a "
  401. "document for which the field '%@' (used as the order by) "
  402. "does not exist.",
  403. sortOrder.field.canonicalString);
  404. }
  405. }
  406. }
  407. return [FSTBound boundWithPosition:components isBefore:isBefore];
  408. }
  409. /** Converts a list of field values to an FSTBound. */
  410. - (FSTBound *)boundFromFieldValues:(NSArray<id> *)fieldValues isBefore:(BOOL)isBefore {
  411. // Use explicit sort order because it has to match the query the user made
  412. NSArray<FSTSortOrder *> *explicitSortOrders = self.query.explicitSortOrders;
  413. if (fieldValues.count > explicitSortOrders.count) {
  414. FSTThrowInvalidUsage(@"InvalidQueryException",
  415. @"Invalid query. You are trying to start or end a query using more values "
  416. @"than were specified in the order by.");
  417. }
  418. NSMutableArray<FSTFieldValue *> *components = [NSMutableArray array];
  419. [fieldValues enumerateObjectsUsingBlock:^(id rawValue, NSUInteger idx, BOOL *stop) {
  420. FSTSortOrder *sortOrder = explicitSortOrders[idx];
  421. if ([sortOrder.field isEqual:[FSTFieldPath keyFieldPath]]) {
  422. if (![rawValue isKindOfClass:[NSString class]]) {
  423. FSTThrowInvalidUsage(@"InvalidQueryException",
  424. @"Invalid query. Expected a string for the document ID.");
  425. }
  426. NSString *documentID = (NSString *)rawValue;
  427. if ([documentID containsString:@"/"]) {
  428. FSTThrowInvalidUsage(@"InvalidQueryException",
  429. @"Invalid query. Document ID '%@' contains a slash.", documentID);
  430. }
  431. FSTDocumentKey *key =
  432. [FSTDocumentKey keyWithPath:[self.query.path pathByAppendingSegment:documentID]];
  433. [components
  434. addObject:[FSTReferenceValue referenceValue:key databaseID:self.firestore.databaseID]];
  435. } else {
  436. FSTFieldValue *fieldValue = [self.firestore.dataConverter parsedQueryValue:rawValue];
  437. [components addObject:fieldValue];
  438. }
  439. }];
  440. return [FSTBound boundWithPosition:components isBefore:isBefore];
  441. }
  442. /** Converts the public API options object to the internal options object. */
  443. - (FSTListenOptions *)internalOptions:(nullable FIRQueryListenOptions *)options {
  444. return [[FSTListenOptions alloc]
  445. initWithIncludeQueryMetadataChanges:options.includeQueryMetadataChanges
  446. includeDocumentMetadataChanges:options.includeDocumentMetadataChanges
  447. waitForSyncWhenOnline:NO];
  448. }
  449. @end
  450. NS_ASSUME_NONNULL_END