FIRFirestore.mm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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 "FIRFirestore+Internal.h"
  17. #include <memory>
  18. #include <string>
  19. #include <utility>
  20. #import "FIRFirestoreSettings+Internal.h"
  21. #import "FIRTransactionOptions+Internal.h"
  22. #import "FIRTransactionOptions.h"
  23. #import "FirebaseCore/Extension/FIRAppInternal.h"
  24. #import "FirebaseCore/Extension/FIRComponentContainer.h"
  25. #import "FirebaseCore/Extension/FIRComponentType.h"
  26. #import "Firestore/Source/API/FIRCollectionReference+Internal.h"
  27. #import "Firestore/Source/API/FIRDocumentReference+Internal.h"
  28. #import "Firestore/Source/API/FIRListenerRegistration+Internal.h"
  29. #import "Firestore/Source/API/FIRLoadBundleTask+Internal.h"
  30. #import "Firestore/Source/API/FIRQuery+Internal.h"
  31. #import "Firestore/Source/API/FIRTransaction+Internal.h"
  32. #import "Firestore/Source/API/FIRWriteBatch+Internal.h"
  33. #import "Firestore/Source/API/FSTFirestoreComponent.h"
  34. #import "Firestore/Source/API/FSTUserDataReader.h"
  35. #include "Firestore/core/src/api/collection_reference.h"
  36. #include "Firestore/core/src/api/document_reference.h"
  37. #include "Firestore/core/src/api/firestore.h"
  38. #include "Firestore/core/src/api/write_batch.h"
  39. #include "Firestore/core/src/core/database_info.h"
  40. #include "Firestore/core/src/core/event_listener.h"
  41. #include "Firestore/core/src/core/transaction.h"
  42. #include "Firestore/core/src/credentials/credentials_provider.h"
  43. #include "Firestore/core/src/model/database_id.h"
  44. #include "Firestore/core/src/remote/firebase_metadata_provider.h"
  45. #include "Firestore/core/src/util/async_queue.h"
  46. #include "Firestore/core/src/util/byte_stream_apple.h"
  47. #include "Firestore/core/src/util/config.h"
  48. #include "Firestore/core/src/util/empty.h"
  49. #include "Firestore/core/src/util/error_apple.h"
  50. #include "Firestore/core/src/util/exception.h"
  51. #include "Firestore/core/src/util/exception_apple.h"
  52. #include "Firestore/core/src/util/executor_libdispatch.h"
  53. #include "Firestore/core/src/util/hard_assert.h"
  54. #include "Firestore/core/src/util/log.h"
  55. #include "Firestore/core/src/util/status.h"
  56. #include "Firestore/core/src/util/statusor.h"
  57. #include "Firestore/core/src/util/string_apple.h"
  58. #include "absl/memory/memory.h"
  59. using firebase::firestore::api::DocumentReference;
  60. using firebase::firestore::api::Firestore;
  61. using firebase::firestore::api::ListenerRegistration;
  62. using firebase::firestore::core::EventListener;
  63. using firebase::firestore::credentials::AuthCredentialsProvider;
  64. using firebase::firestore::model::DatabaseId;
  65. using firebase::firestore::remote::FirebaseMetadataProvider;
  66. using firebase::firestore::util::AsyncQueue;
  67. using firebase::firestore::util::ByteStreamApple;
  68. using firebase::firestore::util::Empty;
  69. using firebase::firestore::util::Executor;
  70. using firebase::firestore::util::ExecutorLibdispatch;
  71. using firebase::firestore::util::kLogLevelDebug;
  72. using firebase::firestore::util::kLogLevelNotice;
  73. using firebase::firestore::util::LogSetLevel;
  74. using firebase::firestore::util::MakeCallback;
  75. using firebase::firestore::util::MakeNSError;
  76. using firebase::firestore::util::MakeNSString;
  77. using firebase::firestore::util::MakeString;
  78. using firebase::firestore::util::ObjcThrowHandler;
  79. using firebase::firestore::util::SetThrowHandler;
  80. using firebase::firestore::util::Status;
  81. using firebase::firestore::util::StatusOr;
  82. using firebase::firestore::util::StreamReadResult;
  83. using firebase::firestore::util::ThrowIllegalState;
  84. using firebase::firestore::util::ThrowInvalidArgument;
  85. using UserUpdateBlock = id _Nullable (^)(FIRTransaction *, NSError **);
  86. using UserTransactionCompletion = void (^)(id _Nullable, NSError *_Nullable);
  87. NS_ASSUME_NONNULL_BEGIN
  88. #pragma mark - FIRFirestore
  89. @interface FIRFirestore ()
  90. @property(nonatomic, strong, readonly) FSTUserDataReader *dataReader;
  91. @end
  92. @implementation FIRFirestore {
  93. std::shared_ptr<Firestore> _firestore;
  94. FIRFirestoreSettings *_settings;
  95. __weak id<FSTFirestoreInstanceRegistry> _registry;
  96. }
  97. + (void)initialize {
  98. if (self == [FIRFirestore class]) {
  99. SetThrowHandler(ObjcThrowHandler);
  100. Firestore::SetClientLanguage("gl-objc/");
  101. }
  102. }
  103. + (instancetype)firestore {
  104. FIRApp *app = [FIRApp defaultApp];
  105. if (!app) {
  106. ThrowIllegalState("Failed to get FirebaseApp instance. Please call FirebaseApp.configure() "
  107. "before using Firestore");
  108. }
  109. return [self firestoreForApp:app database:MakeNSString(DatabaseId::kDefault)];
  110. }
  111. + (instancetype)firestoreForApp:(FIRApp *)app {
  112. return [self firestoreForApp:app database:MakeNSString(DatabaseId::kDefault)];
  113. }
  114. - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID
  115. persistenceKey:(std::string)persistenceKey
  116. authCredentialsProvider:
  117. (std::shared_ptr<credentials::AuthCredentialsProvider>)authCredentialsProvider
  118. appCheckCredentialsProvider:
  119. (std::shared_ptr<credentials::AppCheckCredentialsProvider>)appCheckCredentialsProvider
  120. workerQueue:(std::shared_ptr<AsyncQueue>)workerQueue
  121. firebaseMetadataProvider:
  122. (std::unique_ptr<FirebaseMetadataProvider>)firebaseMetadataProvider
  123. firebaseApp:(FIRApp *)app
  124. instanceRegistry:(nullable id<FSTFirestoreInstanceRegistry>)registry {
  125. if (self = [super init]) {
  126. _firestore = std::make_shared<Firestore>(
  127. std::move(databaseID), std::move(persistenceKey), std::move(authCredentialsProvider),
  128. std::move(appCheckCredentialsProvider), std::move(workerQueue),
  129. std::move(firebaseMetadataProvider), (__bridge void *)self);
  130. _app = app;
  131. _registry = registry;
  132. FSTPreConverterBlock block = ^id _Nullable(id _Nullable input) {
  133. if ([input isKindOfClass:[FIRDocumentReference class]]) {
  134. auto documentReference = (FIRDocumentReference *)input;
  135. return [[FSTDocumentKeyReference alloc] initWithKey:documentReference.key
  136. databaseID:documentReference.firestore.databaseID];
  137. } else {
  138. return input;
  139. }
  140. };
  141. _dataReader = [[FSTUserDataReader alloc] initWithDatabaseID:_firestore->database_id()
  142. preConverter:block];
  143. // Use the property setter so the default settings get plumbed into _firestoreClient.
  144. self.settings = [[FIRFirestoreSettings alloc] init];
  145. }
  146. return self;
  147. }
  148. - (FIRFirestoreSettings *)settings {
  149. // Disallow mutation of our internal settings
  150. return [_settings copy];
  151. }
  152. - (void)setSettings:(FIRFirestoreSettings *)settings {
  153. if (![settings isEqual:_settings]) {
  154. _settings = settings;
  155. _firestore->set_settings([settings internalSettings]);
  156. #if HAVE_LIBDISPATCH
  157. std::unique_ptr<Executor> user_executor =
  158. absl::make_unique<ExecutorLibdispatch>(settings.dispatchQueue);
  159. #else
  160. // It's possible to build without libdispatch on macOS for testing purposes.
  161. // In this case, avoid breaking the build.
  162. std::unique_ptr<Executor> user_executor =
  163. Executor::CreateSerial("com.google.firebase.firestore.user");
  164. #endif // HAVE_LIBDISPATCH
  165. _firestore->set_user_executor(std::move(user_executor));
  166. }
  167. }
  168. - (void)setIndexConfigurationFromJSON:(NSString *)json
  169. completion:(nullable void (^)(NSError *_Nullable error))completion {
  170. _firestore->SetIndexConfiguration(MakeString(json), MakeCallback(completion));
  171. }
  172. - (void)setIndexConfigurationFromStream:(NSInputStream *)stream
  173. completion:(nullable void (^)(NSError *_Nullable error))completion {
  174. auto input = absl::make_unique<ByteStreamApple>(stream);
  175. auto callback = MakeCallback(completion);
  176. std::string json;
  177. bool eof = false;
  178. while (!eof) {
  179. StreamReadResult result = input->Read(1024ul);
  180. if (!result.ok()) {
  181. callback(result.status());
  182. return;
  183. }
  184. eof = result.eof();
  185. json.append(std::move(result).ValueOrDie());
  186. }
  187. _firestore->SetIndexConfiguration(json, callback);
  188. }
  189. - (FIRCollectionReference *)collectionWithPath:(NSString *)collectionPath {
  190. if (!collectionPath) {
  191. ThrowInvalidArgument("Collection path cannot be nil.");
  192. }
  193. if (!collectionPath.length) {
  194. ThrowInvalidArgument("Collection path cannot be empty.");
  195. }
  196. if ([collectionPath containsString:@"//"]) {
  197. ThrowInvalidArgument("Invalid path (%s). Paths must not contain // in them.", collectionPath);
  198. }
  199. return [[FIRCollectionReference alloc]
  200. initWithReference:_firestore->GetCollection(MakeString(collectionPath))];
  201. }
  202. - (FIRDocumentReference *)documentWithPath:(NSString *)documentPath {
  203. if (!documentPath) {
  204. ThrowInvalidArgument("Document path cannot be nil.");
  205. }
  206. if (!documentPath.length) {
  207. ThrowInvalidArgument("Document path cannot be empty.");
  208. }
  209. if ([documentPath containsString:@"//"]) {
  210. ThrowInvalidArgument("Invalid path (%s). Paths must not contain // in them.", documentPath);
  211. }
  212. DocumentReference documentReference = _firestore->GetDocument(MakeString(documentPath));
  213. return [[FIRDocumentReference alloc] initWithReference:std::move(documentReference)];
  214. }
  215. - (FIRQuery *)collectionGroupWithID:(NSString *)collectionID {
  216. if (!collectionID) {
  217. ThrowInvalidArgument("Collection ID cannot be nil.");
  218. }
  219. if (!collectionID.length) {
  220. ThrowInvalidArgument("Collection ID cannot be empty.");
  221. }
  222. if ([collectionID containsString:@"/"]) {
  223. ThrowInvalidArgument("Invalid collection ID (%s). Collection IDs must not contain / in them.",
  224. collectionID);
  225. }
  226. auto query = _firestore->GetCollectionGroup(MakeString(collectionID));
  227. return [[FIRQuery alloc] initWithQuery:std::move(query) firestore:_firestore];
  228. }
  229. - (FIRWriteBatch *)batch {
  230. return [FIRWriteBatch writeBatchWithDataReader:self.dataReader writeBatch:_firestore->GetBatch()];
  231. }
  232. - (void)runTransactionWithOptions:(FIRTransactionOptions *_Nullable)options
  233. block:(UserUpdateBlock)updateBlock
  234. dispatchQueue:(dispatch_queue_t)queue
  235. completion:(UserTransactionCompletion)completion {
  236. if (!updateBlock) {
  237. ThrowInvalidArgument("Transaction block cannot be nil.");
  238. }
  239. if (!completion) {
  240. ThrowInvalidArgument("Transaction completion block cannot be nil.");
  241. }
  242. class TransactionResult {
  243. public:
  244. TransactionResult(FIRFirestore *firestore,
  245. UserUpdateBlock update_block,
  246. dispatch_queue_t queue,
  247. UserTransactionCompletion completion)
  248. : firestore_(firestore),
  249. user_update_block_(update_block),
  250. queue_(queue),
  251. user_completion_(completion) {
  252. }
  253. void RunUpdateBlock(std::shared_ptr<core::Transaction> internalTransaction,
  254. core::TransactionResultCallback internalCallback) {
  255. dispatch_async(queue_, ^{
  256. auto transaction = [FIRTransaction transactionWithInternalTransaction:internalTransaction
  257. firestore:firestore_];
  258. NSError *_Nullable error = nil;
  259. user_result_ = user_update_block_(transaction, &error);
  260. // If the user set an error, disregard the result.
  261. if (error) {
  262. // If the error is a user error, set flag to not retry the transaction.
  263. if (error.domain != FIRFirestoreErrorDomain) {
  264. internalTransaction->MarkPermanentlyFailed();
  265. }
  266. internalCallback(Status::FromNSError(error));
  267. } else {
  268. internalCallback(Status::OK());
  269. }
  270. });
  271. }
  272. void HandleFinalStatus(const Status &status) {
  273. if (!status.ok()) {
  274. user_completion_(nil, MakeNSError(status));
  275. return;
  276. }
  277. user_completion_(user_result_, nil);
  278. }
  279. private:
  280. FIRFirestore *firestore_;
  281. UserUpdateBlock user_update_block_;
  282. dispatch_queue_t queue_;
  283. UserTransactionCompletion user_completion_;
  284. id _Nullable user_result_;
  285. };
  286. auto result_capture = std::make_shared<TransactionResult>(self, updateBlock, queue, completion);
  287. // Wrap the user-supplied updateBlock in a core C++ compatible callback. Wrap the result of the
  288. // updateBlock invocation up in a TransactionResult for tunneling through the internals of the
  289. // system.
  290. auto internalUpdateBlock = [result_capture](
  291. std::shared_ptr<core::Transaction> internalTransaction,
  292. core::TransactionResultCallback internalCallback) {
  293. result_capture->RunUpdateBlock(internalTransaction, internalCallback);
  294. };
  295. // Unpacks the TransactionResult value and calls the user completion handler.
  296. //
  297. // PORTING NOTE: Other platforms where the user return value is internally representable don't
  298. // need this wrapper.
  299. auto objcTranslator = [result_capture](const Status &status) {
  300. result_capture->HandleFinalStatus(status);
  301. };
  302. int max_attempts = [FIRTransactionOptions defaultMaxAttempts];
  303. if (options) {
  304. // Note: The cast of `maxAttempts` from `NSInteger` to `int` is safe (i.e. lossless) because
  305. // `FIRTransactionOptions` does not allow values greater than `INT32_MAX` to be set.
  306. max_attempts = static_cast<int>(options.maxAttempts);
  307. }
  308. _firestore->RunTransaction(std::move(internalUpdateBlock), std::move(objcTranslator),
  309. max_attempts);
  310. }
  311. - (void)runTransactionWithBlock:(id _Nullable (^)(FIRTransaction *, NSError **error))updateBlock
  312. completion:
  313. (void (^)(id _Nullable result, NSError *_Nullable error))completion {
  314. [self runTransactionWithOptions:nil block:updateBlock completion:completion];
  315. }
  316. - (void)runTransactionWithOptions:(FIRTransactionOptions *_Nullable)options
  317. block:(id _Nullable (^)(FIRTransaction *, NSError **))updateBlock
  318. completion:
  319. (void (^)(id _Nullable result, NSError *_Nullable error))completion {
  320. static dispatch_queue_t transactionDispatchQueue;
  321. static dispatch_once_t onceToken;
  322. dispatch_once(&onceToken, ^{
  323. transactionDispatchQueue = dispatch_queue_create("com.google.firebase.firestore.transaction",
  324. DISPATCH_QUEUE_CONCURRENT);
  325. });
  326. [self runTransactionWithOptions:options
  327. block:updateBlock
  328. dispatchQueue:transactionDispatchQueue
  329. completion:completion];
  330. }
  331. + (void)enableLogging:(BOOL)logging {
  332. LogSetLevel(logging ? kLogLevelDebug : kLogLevelNotice);
  333. }
  334. - (void)useEmulatorWithHost:(NSString *)host port:(NSInteger)port {
  335. if (!host.length) {
  336. ThrowInvalidArgument("Host cannot be nil or empty.");
  337. }
  338. if (!_settings.isUsingDefaultHost) {
  339. LOG_WARN("Overriding previously-set host value: %@", _settings.host);
  340. }
  341. // Use a new settings so the new settings are automatically plumbed
  342. // to the underlying Firestore objects.
  343. NSString *settingsHost = [NSString stringWithFormat:@"%@:%li", host, (long)port];
  344. FIRFirestoreSettings *newSettings = [_settings copy];
  345. newSettings.host = settingsHost;
  346. self.settings = newSettings;
  347. }
  348. - (void)enableNetworkWithCompletion:(nullable void (^)(NSError *_Nullable error))completion {
  349. _firestore->EnableNetwork(MakeCallback(completion));
  350. }
  351. - (void)disableNetworkWithCompletion:(nullable void (^)(NSError *_Nullable))completion {
  352. _firestore->DisableNetwork(MakeCallback(completion));
  353. }
  354. - (void)clearPersistenceWithCompletion:(nullable void (^)(NSError *_Nullable error))completion {
  355. _firestore->ClearPersistence(MakeCallback(completion));
  356. }
  357. - (void)waitForPendingWritesWithCompletion:(void (^)(NSError *_Nullable error))completion {
  358. _firestore->WaitForPendingWrites(MakeCallback(completion));
  359. }
  360. - (void)terminateWithCompletion:(nullable void (^)(NSError *_Nullable error))completion {
  361. id<FSTFirestoreInstanceRegistry> strongRegistry = _registry;
  362. if (strongRegistry) {
  363. [strongRegistry
  364. removeInstanceWithDatabase:MakeNSString(_firestore->database_id().database_id())];
  365. }
  366. [self terminateInternalWithCompletion:completion];
  367. }
  368. - (id<FIRListenerRegistration>)addSnapshotsInSyncListener:(void (^)(void))listener {
  369. std::unique_ptr<core::EventListener<Empty>> eventListener =
  370. core::EventListener<Empty>::Create([listener](const StatusOr<Empty> &) { listener(); });
  371. std::unique_ptr<ListenerRegistration> result =
  372. _firestore->AddSnapshotsInSyncListener(std::move(eventListener));
  373. return [[FSTListenerRegistration alloc] initWithRegistration:std::move(result)];
  374. }
  375. - (FIRLoadBundleTask *)loadBundle:(nonnull NSData *)bundleData {
  376. auto stream = absl::make_unique<ByteStreamApple>([[NSInputStream alloc] initWithData:bundleData]);
  377. return [self loadBundleStream:[[NSInputStream alloc] initWithData:bundleData] completion:nil];
  378. }
  379. - (FIRLoadBundleTask *)loadBundle:(NSData *)bundleData
  380. completion:(nullable void (^)(FIRLoadBundleTaskProgress *_Nullable progress,
  381. NSError *_Nullable error))completion {
  382. return [self loadBundleStream:[[NSInputStream alloc] initWithData:bundleData]
  383. completion:completion];
  384. }
  385. - (FIRLoadBundleTask *)loadBundleStream:(NSInputStream *)bundleStream {
  386. return [self loadBundleStream:bundleStream completion:nil];
  387. }
  388. - (FIRLoadBundleTask *)loadBundleStream:(NSInputStream *)bundleStream
  389. completion:
  390. (nullable void (^)(FIRLoadBundleTaskProgress *_Nullable progress,
  391. NSError *_Nullable error))completion {
  392. auto stream = absl::make_unique<ByteStreamApple>(bundleStream);
  393. std::shared_ptr<api::LoadBundleTask> task = _firestore->LoadBundle(std::move(stream));
  394. auto callback = [completion](api::LoadBundleTaskProgress progress) {
  395. if (!completion) {
  396. return;
  397. }
  398. // Ignoring `kInProgress` because we are setting up for completion callback.
  399. if (progress.state() == api::LoadBundleTaskState::kSuccess) {
  400. completion([[FIRLoadBundleTaskProgress alloc] initWithInternal:progress], nil);
  401. } else if (progress.state() == api::LoadBundleTaskState::kError) {
  402. NSError *error = nil;
  403. if (!progress.error_status().ok()) {
  404. LOG_WARN("Progress set to Error, but error_status() is ok()");
  405. error = MakeNSError(firebase::firestore::Error::kErrorUnknown,
  406. "Loading bundle failed with unknown error");
  407. } else {
  408. error = MakeNSError(progress.error_status());
  409. }
  410. completion([[FIRLoadBundleTaskProgress alloc] initWithInternal:progress], error);
  411. }
  412. };
  413. task->SetLastObserver(callback);
  414. return [[FIRLoadBundleTask alloc] initWithTask:task];
  415. }
  416. - (void)getQueryNamed:(NSString *)name completion:(void (^)(FIRQuery *_Nullable query))completion {
  417. auto firestore = _firestore;
  418. auto callback = [completion, firestore](core::Query query, bool found) {
  419. if (!completion) {
  420. return;
  421. }
  422. if (found) {
  423. FIRQuery *firQuery = [[FIRQuery alloc] initWithQuery:std::move(query) firestore:firestore];
  424. completion(firQuery);
  425. } else {
  426. completion(nil);
  427. }
  428. };
  429. _firestore->GetNamedQuery(MakeString(name), callback);
  430. }
  431. @end
  432. @implementation FIRFirestore (Internal)
  433. - (std::shared_ptr<Firestore>)wrapped {
  434. return _firestore;
  435. }
  436. - (const std::shared_ptr<AsyncQueue> &)workerQueue {
  437. return _firestore->worker_queue();
  438. }
  439. - (const DatabaseId &)databaseID {
  440. return _firestore->database_id();
  441. }
  442. + (instancetype)firestoreForApp:(FIRApp *)app database:(NSString *)database {
  443. if (!app) {
  444. ThrowInvalidArgument("FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like "
  445. "to use the default FirebaseApp instance.");
  446. }
  447. if (!database) {
  448. ThrowInvalidArgument("Database identifier may not be nil. Use '%s' if you want the default "
  449. "database",
  450. DatabaseId::kDefault);
  451. }
  452. id<FSTFirestoreMultiDBProvider> provider =
  453. FIR_COMPONENT(FSTFirestoreMultiDBProvider, app.container);
  454. return [provider firestoreForDatabase:database];
  455. }
  456. + (instancetype)firestoreForDatabase:(NSString *)database {
  457. FIRApp *app = [FIRApp defaultApp];
  458. if (!app) {
  459. ThrowIllegalState("Failed to get FirebaseApp instance. Please call FirebaseApp.configure() "
  460. "before using Firestore");
  461. }
  462. return [self firestoreForApp:app database:database];
  463. }
  464. + (FIRFirestore *)recoverFromFirestore:(std::shared_ptr<Firestore>)firestore {
  465. return (__bridge FIRFirestore *)firestore->extension();
  466. }
  467. - (void)terminateInternalWithCompletion:(nullable void (^)(NSError *_Nullable error))completion {
  468. _firestore->Terminate(MakeCallback(completion));
  469. }
  470. #pragma mark - Force Link Unreferenced Symbols
  471. extern void FSTIncludeFSTFirestoreComponent(void);
  472. /// This method forces the linker to include all the Analytics categories without requiring app
  473. /// developers to include the '-ObjC' linker flag in their projects. DO NOT CALL THIS METHOD.
  474. + (void)notCalled {
  475. NSAssert(NO, @"+notCalled should never be called");
  476. FSTIncludeFSTFirestoreComponent();
  477. }
  478. @end
  479. NS_ASSUME_NONNULL_END