No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.rn.js 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. import firebase from '@firebase/app-compat';
  2. import { FirestoreError, Bytes, _isBase64Available, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, clearIndexedDbPersistence, _DatabaseId, _logWarn, connectFirestoreEmulator, enableNetwork, disableNetwork, _validateIsNotUsedTogether, waitForPendingWrites, onSnapshotsInSync, collection, doc, collectionGroup, runTransaction, ensureFirestoreConfigured, WriteBatch as WriteBatch$1, executeWrite, loadBundle, namedQuery, DocumentSnapshot as DocumentSnapshot$1, DocumentReference as DocumentReference$1, _DocumentKey, refEqual, setDoc, updateDoc, deleteDoc, onSnapshot, getDocFromCache, getDocFromServer, getDoc, snapshotEqual, query, where, orderBy, limit, limitToLast, startAt, startAfter, endBefore, endAt, queryEqual, getDocsFromCache, getDocsFromServer, getDocs, QuerySnapshot as QuerySnapshot$1, addDoc, _cast, AbstractUserDataWriter, setLogLevel as setLogLevel$1, QueryDocumentSnapshot as QueryDocumentSnapshot$1, _debugAssert, FieldPath as FieldPath$1, _FieldPath, serverTimestamp, deleteField, arrayUnion, arrayRemove, increment, GeoPoint, Timestamp, CACHE_SIZE_UNLIMITED } from '@firebase/firestore';
  3. import { getModularInstance } from '@firebase/util';
  4. import { Component } from '@firebase/component';
  5. const name = "@firebase/firestore-compat";
  6. const version = "0.3.1";
  7. /**
  8. * @license
  9. * Copyright 2021 Google LLC
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. function validateSetOptions(methodName, options) {
  24. if (options === undefined) {
  25. return {
  26. merge: false
  27. };
  28. }
  29. if (options.mergeFields !== undefined && options.merge !== undefined) {
  30. throw new FirestoreError('invalid-argument', `Invalid options passed to function ${methodName}(): You cannot ` +
  31. 'specify both "merge" and "mergeFields".');
  32. }
  33. return options;
  34. }
  35. /**
  36. * @license
  37. * Copyright 2017 Google LLC
  38. *
  39. * Licensed under the Apache License, Version 2.0 (the "License");
  40. * you may not use this file except in compliance with the License.
  41. * You may obtain a copy of the License at
  42. *
  43. * http://www.apache.org/licenses/LICENSE-2.0
  44. *
  45. * Unless required by applicable law or agreed to in writing, software
  46. * distributed under the License is distributed on an "AS IS" BASIS,
  47. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  48. * See the License for the specific language governing permissions and
  49. * limitations under the License.
  50. */
  51. /** Helper function to assert Uint8Array is available at runtime. */
  52. function assertUint8ArrayAvailable() {
  53. if (typeof Uint8Array === 'undefined') {
  54. throw new FirestoreError('unimplemented', 'Uint8Arrays are not available in this environment.');
  55. }
  56. }
  57. /** Helper function to assert Base64 functions are available at runtime. */
  58. function assertBase64Available() {
  59. if (!_isBase64Available()) {
  60. throw new FirestoreError('unimplemented', 'Blobs are unavailable in Firestore in this environment.');
  61. }
  62. }
  63. /** Immutable class holding a blob (binary data) */
  64. class Blob {
  65. constructor(_delegate) {
  66. this._delegate = _delegate;
  67. }
  68. static fromBase64String(base64) {
  69. assertBase64Available();
  70. return new Blob(Bytes.fromBase64String(base64));
  71. }
  72. static fromUint8Array(array) {
  73. assertUint8ArrayAvailable();
  74. return new Blob(Bytes.fromUint8Array(array));
  75. }
  76. toBase64() {
  77. assertBase64Available();
  78. return this._delegate.toBase64();
  79. }
  80. toUint8Array() {
  81. assertUint8ArrayAvailable();
  82. return this._delegate.toUint8Array();
  83. }
  84. isEqual(other) {
  85. return this._delegate.isEqual(other._delegate);
  86. }
  87. toString() {
  88. return 'Blob(base64: ' + this.toBase64() + ')';
  89. }
  90. }
  91. /**
  92. * @license
  93. * Copyright 2017 Google LLC
  94. *
  95. * Licensed under the Apache License, Version 2.0 (the "License");
  96. * you may not use this file except in compliance with the License.
  97. * You may obtain a copy of the License at
  98. *
  99. * http://www.apache.org/licenses/LICENSE-2.0
  100. *
  101. * Unless required by applicable law or agreed to in writing, software
  102. * distributed under the License is distributed on an "AS IS" BASIS,
  103. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  104. * See the License for the specific language governing permissions and
  105. * limitations under the License.
  106. */
  107. function isPartialObserver(obj) {
  108. return implementsAnyMethods(obj, ['next', 'error', 'complete']);
  109. }
  110. /**
  111. * Returns true if obj is an object and contains at least one of the specified
  112. * methods.
  113. */
  114. function implementsAnyMethods(obj, methods) {
  115. if (typeof obj !== 'object' || obj === null) {
  116. return false;
  117. }
  118. const object = obj;
  119. for (const method of methods) {
  120. if (method in object && typeof object[method] === 'function') {
  121. return true;
  122. }
  123. }
  124. return false;
  125. }
  126. /**
  127. * @license
  128. * Copyright 2017 Google LLC
  129. *
  130. * Licensed under the Apache License, Version 2.0 (the "License");
  131. * you may not use this file except in compliance with the License.
  132. * You may obtain a copy of the License at
  133. *
  134. * http://www.apache.org/licenses/LICENSE-2.0
  135. *
  136. * Unless required by applicable law or agreed to in writing, software
  137. * distributed under the License is distributed on an "AS IS" BASIS,
  138. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  139. * See the License for the specific language governing permissions and
  140. * limitations under the License.
  141. */
  142. /**
  143. * The persistence provider included with the full Firestore SDK.
  144. */
  145. class IndexedDbPersistenceProvider {
  146. enableIndexedDbPersistence(firestore, forceOwnership) {
  147. return enableIndexedDbPersistence(firestore._delegate, { forceOwnership });
  148. }
  149. enableMultiTabIndexedDbPersistence(firestore) {
  150. return enableMultiTabIndexedDbPersistence(firestore._delegate);
  151. }
  152. clearIndexedDbPersistence(firestore) {
  153. return clearIndexedDbPersistence(firestore._delegate);
  154. }
  155. }
  156. /**
  157. * Compat class for Firestore. Exposes Firestore Legacy API, but delegates
  158. * to the functional API of firestore-exp.
  159. */
  160. class Firestore {
  161. constructor(databaseIdOrApp, _delegate, _persistenceProvider) {
  162. this._delegate = _delegate;
  163. this._persistenceProvider = _persistenceProvider;
  164. this.INTERNAL = {
  165. delete: () => this.terminate()
  166. };
  167. if (!(databaseIdOrApp instanceof _DatabaseId)) {
  168. this._appCompat = databaseIdOrApp;
  169. }
  170. }
  171. get _databaseId() {
  172. return this._delegate._databaseId;
  173. }
  174. settings(settingsLiteral) {
  175. const currentSettings = this._delegate._getSettings();
  176. if (!settingsLiteral.merge &&
  177. currentSettings.host !== settingsLiteral.host) {
  178. _logWarn('You are overriding the original host. If you did not intend ' +
  179. 'to override your settings, use {merge: true}.');
  180. }
  181. if (settingsLiteral.merge) {
  182. settingsLiteral = Object.assign(Object.assign({}, currentSettings), settingsLiteral);
  183. // Remove the property from the settings once the merge is completed
  184. delete settingsLiteral.merge;
  185. }
  186. this._delegate._setSettings(settingsLiteral);
  187. }
  188. useEmulator(host, port, options = {}) {
  189. connectFirestoreEmulator(this._delegate, host, port, options);
  190. }
  191. enableNetwork() {
  192. return enableNetwork(this._delegate);
  193. }
  194. disableNetwork() {
  195. return disableNetwork(this._delegate);
  196. }
  197. enablePersistence(settings) {
  198. let synchronizeTabs = false;
  199. let experimentalForceOwningTab = false;
  200. if (settings) {
  201. synchronizeTabs = !!settings.synchronizeTabs;
  202. experimentalForceOwningTab = !!settings.experimentalForceOwningTab;
  203. _validateIsNotUsedTogether('synchronizeTabs', synchronizeTabs, 'experimentalForceOwningTab', experimentalForceOwningTab);
  204. }
  205. return synchronizeTabs
  206. ? this._persistenceProvider.enableMultiTabIndexedDbPersistence(this)
  207. : this._persistenceProvider.enableIndexedDbPersistence(this, experimentalForceOwningTab);
  208. }
  209. clearPersistence() {
  210. return this._persistenceProvider.clearIndexedDbPersistence(this);
  211. }
  212. terminate() {
  213. if (this._appCompat) {
  214. this._appCompat._removeServiceInstance('firestore-compat');
  215. this._appCompat._removeServiceInstance('firestore');
  216. }
  217. return this._delegate._delete();
  218. }
  219. waitForPendingWrites() {
  220. return waitForPendingWrites(this._delegate);
  221. }
  222. onSnapshotsInSync(arg) {
  223. return onSnapshotsInSync(this._delegate, arg);
  224. }
  225. get app() {
  226. if (!this._appCompat) {
  227. throw new FirestoreError('failed-precondition', "Firestore was not initialized using the Firebase SDK. 'app' is " +
  228. 'not available');
  229. }
  230. return this._appCompat;
  231. }
  232. collection(pathString) {
  233. try {
  234. return new CollectionReference(this, collection(this._delegate, pathString));
  235. }
  236. catch (e) {
  237. throw replaceFunctionName(e, 'collection()', 'Firestore.collection()');
  238. }
  239. }
  240. doc(pathString) {
  241. try {
  242. return new DocumentReference(this, doc(this._delegate, pathString));
  243. }
  244. catch (e) {
  245. throw replaceFunctionName(e, 'doc()', 'Firestore.doc()');
  246. }
  247. }
  248. collectionGroup(collectionId) {
  249. try {
  250. return new Query(this, collectionGroup(this._delegate, collectionId));
  251. }
  252. catch (e) {
  253. throw replaceFunctionName(e, 'collectionGroup()', 'Firestore.collectionGroup()');
  254. }
  255. }
  256. runTransaction(updateFunction) {
  257. return runTransaction(this._delegate, transaction => updateFunction(new Transaction(this, transaction)));
  258. }
  259. batch() {
  260. ensureFirestoreConfigured(this._delegate);
  261. return new WriteBatch(new WriteBatch$1(this._delegate, mutations => executeWrite(this._delegate, mutations)));
  262. }
  263. loadBundle(bundleData) {
  264. return loadBundle(this._delegate, bundleData);
  265. }
  266. namedQuery(name) {
  267. return namedQuery(this._delegate, name).then(expQuery => {
  268. if (!expQuery) {
  269. return null;
  270. }
  271. return new Query(this,
  272. // We can pass `expQuery` here directly since named queries don't have a UserDataConverter.
  273. // Otherwise, we would have to create a new ExpQuery and pass the old UserDataConverter.
  274. expQuery);
  275. });
  276. }
  277. }
  278. class UserDataWriter extends AbstractUserDataWriter {
  279. constructor(firestore) {
  280. super();
  281. this.firestore = firestore;
  282. }
  283. convertBytes(bytes) {
  284. return new Blob(new Bytes(bytes));
  285. }
  286. convertReference(name) {
  287. const key = this.convertDocumentKey(name, this.firestore._databaseId);
  288. return DocumentReference.forKey(key, this.firestore, /* converter= */ null);
  289. }
  290. }
  291. function setLogLevel(level) {
  292. setLogLevel$1(level);
  293. }
  294. /**
  295. * A reference to a transaction.
  296. */
  297. class Transaction {
  298. constructor(_firestore, _delegate) {
  299. this._firestore = _firestore;
  300. this._delegate = _delegate;
  301. this._userDataWriter = new UserDataWriter(_firestore);
  302. }
  303. get(documentRef) {
  304. const ref = castReference(documentRef);
  305. return this._delegate
  306. .get(ref)
  307. .then(result => new DocumentSnapshot(this._firestore, new DocumentSnapshot$1(this._firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, ref.converter)));
  308. }
  309. set(documentRef, data, options) {
  310. const ref = castReference(documentRef);
  311. if (options) {
  312. validateSetOptions('Transaction.set', options);
  313. this._delegate.set(ref, data, options);
  314. }
  315. else {
  316. this._delegate.set(ref, data);
  317. }
  318. return this;
  319. }
  320. update(documentRef, dataOrField, value, ...moreFieldsAndValues) {
  321. const ref = castReference(documentRef);
  322. if (arguments.length === 2) {
  323. this._delegate.update(ref, dataOrField);
  324. }
  325. else {
  326. this._delegate.update(ref, dataOrField, value, ...moreFieldsAndValues);
  327. }
  328. return this;
  329. }
  330. delete(documentRef) {
  331. const ref = castReference(documentRef);
  332. this._delegate.delete(ref);
  333. return this;
  334. }
  335. }
  336. class WriteBatch {
  337. constructor(_delegate) {
  338. this._delegate = _delegate;
  339. }
  340. set(documentRef, data, options) {
  341. const ref = castReference(documentRef);
  342. if (options) {
  343. validateSetOptions('WriteBatch.set', options);
  344. this._delegate.set(ref, data, options);
  345. }
  346. else {
  347. this._delegate.set(ref, data);
  348. }
  349. return this;
  350. }
  351. update(documentRef, dataOrField, value, ...moreFieldsAndValues) {
  352. const ref = castReference(documentRef);
  353. if (arguments.length === 2) {
  354. this._delegate.update(ref, dataOrField);
  355. }
  356. else {
  357. this._delegate.update(ref, dataOrField, value, ...moreFieldsAndValues);
  358. }
  359. return this;
  360. }
  361. delete(documentRef) {
  362. const ref = castReference(documentRef);
  363. this._delegate.delete(ref);
  364. return this;
  365. }
  366. commit() {
  367. return this._delegate.commit();
  368. }
  369. }
  370. /**
  371. * Wraps a `PublicFirestoreDataConverter` translating the types from the
  372. * experimental SDK into corresponding types from the Classic SDK before passing
  373. * them to the wrapped converter.
  374. */
  375. class FirestoreDataConverter {
  376. constructor(_firestore, _userDataWriter, _delegate) {
  377. this._firestore = _firestore;
  378. this._userDataWriter = _userDataWriter;
  379. this._delegate = _delegate;
  380. }
  381. fromFirestore(snapshot, options) {
  382. const expSnapshot = new QueryDocumentSnapshot$1(this._firestore._delegate, this._userDataWriter, snapshot._key, snapshot._document, snapshot.metadata,
  383. /* converter= */ null);
  384. return this._delegate.fromFirestore(new QueryDocumentSnapshot(this._firestore, expSnapshot), options !== null && options !== void 0 ? options : {});
  385. }
  386. toFirestore(modelObject, options) {
  387. if (!options) {
  388. return this._delegate.toFirestore(modelObject);
  389. }
  390. else {
  391. return this._delegate.toFirestore(modelObject, options);
  392. }
  393. }
  394. // Use the same instance of `FirestoreDataConverter` for the given instances
  395. // of `Firestore` and `PublicFirestoreDataConverter` so that isEqual() will
  396. // compare equal for two objects created with the same converter instance.
  397. static getInstance(firestore, converter) {
  398. const converterMapByFirestore = FirestoreDataConverter.INSTANCES;
  399. let untypedConverterByConverter = converterMapByFirestore.get(firestore);
  400. if (!untypedConverterByConverter) {
  401. untypedConverterByConverter = new WeakMap();
  402. converterMapByFirestore.set(firestore, untypedConverterByConverter);
  403. }
  404. let instance = untypedConverterByConverter.get(converter);
  405. if (!instance) {
  406. instance = new FirestoreDataConverter(firestore, new UserDataWriter(firestore), converter);
  407. untypedConverterByConverter.set(converter, instance);
  408. }
  409. return instance;
  410. }
  411. }
  412. FirestoreDataConverter.INSTANCES = new WeakMap();
  413. /**
  414. * A reference to a particular document in a collection in the database.
  415. */
  416. class DocumentReference {
  417. constructor(firestore, _delegate) {
  418. this.firestore = firestore;
  419. this._delegate = _delegate;
  420. this._userDataWriter = new UserDataWriter(firestore);
  421. }
  422. static forPath(path, firestore, converter) {
  423. if (path.length % 2 !== 0) {
  424. throw new FirestoreError('invalid-argument', 'Invalid document reference. Document ' +
  425. 'references must have an even number of segments, but ' +
  426. `${path.canonicalString()} has ${path.length}`);
  427. }
  428. return new DocumentReference(firestore, new DocumentReference$1(firestore._delegate, converter, new _DocumentKey(path)));
  429. }
  430. static forKey(key, firestore, converter) {
  431. return new DocumentReference(firestore, new DocumentReference$1(firestore._delegate, converter, key));
  432. }
  433. get id() {
  434. return this._delegate.id;
  435. }
  436. get parent() {
  437. return new CollectionReference(this.firestore, this._delegate.parent);
  438. }
  439. get path() {
  440. return this._delegate.path;
  441. }
  442. collection(pathString) {
  443. try {
  444. return new CollectionReference(this.firestore, collection(this._delegate, pathString));
  445. }
  446. catch (e) {
  447. throw replaceFunctionName(e, 'collection()', 'DocumentReference.collection()');
  448. }
  449. }
  450. isEqual(other) {
  451. other = getModularInstance(other);
  452. if (!(other instanceof DocumentReference$1)) {
  453. return false;
  454. }
  455. return refEqual(this._delegate, other);
  456. }
  457. set(value, options) {
  458. options = validateSetOptions('DocumentReference.set', options);
  459. try {
  460. if (options) {
  461. return setDoc(this._delegate, value, options);
  462. }
  463. else {
  464. return setDoc(this._delegate, value);
  465. }
  466. }
  467. catch (e) {
  468. throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()');
  469. }
  470. }
  471. update(fieldOrUpdateData, value, ...moreFieldsAndValues) {
  472. try {
  473. if (arguments.length === 1) {
  474. return updateDoc(this._delegate, fieldOrUpdateData);
  475. }
  476. else {
  477. return updateDoc(this._delegate, fieldOrUpdateData, value, ...moreFieldsAndValues);
  478. }
  479. }
  480. catch (e) {
  481. throw replaceFunctionName(e, 'updateDoc()', 'DocumentReference.update()');
  482. }
  483. }
  484. delete() {
  485. return deleteDoc(this._delegate);
  486. }
  487. onSnapshot(...args) {
  488. const options = extractSnapshotOptions(args);
  489. const observer = wrapObserver(args, result => new DocumentSnapshot(this.firestore, new DocumentSnapshot$1(this.firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, this._delegate.converter)));
  490. return onSnapshot(this._delegate, options, observer);
  491. }
  492. get(options) {
  493. let snap;
  494. if ((options === null || options === void 0 ? void 0 : options.source) === 'cache') {
  495. snap = getDocFromCache(this._delegate);
  496. }
  497. else if ((options === null || options === void 0 ? void 0 : options.source) === 'server') {
  498. snap = getDocFromServer(this._delegate);
  499. }
  500. else {
  501. snap = getDoc(this._delegate);
  502. }
  503. return snap.then(result => new DocumentSnapshot(this.firestore, new DocumentSnapshot$1(this.firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, this._delegate.converter)));
  504. }
  505. withConverter(converter) {
  506. return new DocumentReference(this.firestore, converter
  507. ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
  508. : this._delegate.withConverter(null));
  509. }
  510. }
  511. /**
  512. * Replaces the function name in an error thrown by the firestore-exp API
  513. * with the function names used in the classic API.
  514. */
  515. function replaceFunctionName(e, original, updated) {
  516. e.message = e.message.replace(original, updated);
  517. return e;
  518. }
  519. /**
  520. * Iterates the list of arguments from an `onSnapshot` call and returns the
  521. * first argument that may be an `SnapshotListenOptions` object. Returns an
  522. * empty object if none is found.
  523. */
  524. function extractSnapshotOptions(args) {
  525. for (const arg of args) {
  526. if (typeof arg === 'object' && !isPartialObserver(arg)) {
  527. return arg;
  528. }
  529. }
  530. return {};
  531. }
  532. /**
  533. * Creates an observer that can be passed to the firestore-exp SDK. The
  534. * observer converts all observed values into the format expected by the classic
  535. * SDK.
  536. *
  537. * @param args - The list of arguments from an `onSnapshot` call.
  538. * @param wrapper - The function that converts the firestore-exp type into the
  539. * type used by this shim.
  540. */
  541. function wrapObserver(args, wrapper) {
  542. var _a, _b;
  543. let userObserver;
  544. if (isPartialObserver(args[0])) {
  545. userObserver = args[0];
  546. }
  547. else if (isPartialObserver(args[1])) {
  548. userObserver = args[1];
  549. }
  550. else if (typeof args[0] === 'function') {
  551. userObserver = {
  552. next: args[0],
  553. error: args[1],
  554. complete: args[2]
  555. };
  556. }
  557. else {
  558. userObserver = {
  559. next: args[1],
  560. error: args[2],
  561. complete: args[3]
  562. };
  563. }
  564. return {
  565. next: val => {
  566. if (userObserver.next) {
  567. userObserver.next(wrapper(val));
  568. }
  569. },
  570. error: (_a = userObserver.error) === null || _a === void 0 ? void 0 : _a.bind(userObserver),
  571. complete: (_b = userObserver.complete) === null || _b === void 0 ? void 0 : _b.bind(userObserver)
  572. };
  573. }
  574. class DocumentSnapshot {
  575. constructor(_firestore, _delegate) {
  576. this._firestore = _firestore;
  577. this._delegate = _delegate;
  578. }
  579. get ref() {
  580. return new DocumentReference(this._firestore, this._delegate.ref);
  581. }
  582. get id() {
  583. return this._delegate.id;
  584. }
  585. get metadata() {
  586. return this._delegate.metadata;
  587. }
  588. get exists() {
  589. return this._delegate.exists();
  590. }
  591. data(options) {
  592. return this._delegate.data(options);
  593. }
  594. get(fieldPath, options
  595. // We are using `any` here to avoid an explicit cast by our users.
  596. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  597. ) {
  598. return this._delegate.get(fieldPath, options);
  599. }
  600. isEqual(other) {
  601. return snapshotEqual(this._delegate, other._delegate);
  602. }
  603. }
  604. class QueryDocumentSnapshot extends DocumentSnapshot {
  605. data(options) {
  606. const data = this._delegate.data(options);
  607. _debugAssert(data !== undefined, 'Document in a QueryDocumentSnapshot should exist');
  608. return data;
  609. }
  610. }
  611. class Query {
  612. constructor(firestore, _delegate) {
  613. this.firestore = firestore;
  614. this._delegate = _delegate;
  615. this._userDataWriter = new UserDataWriter(firestore);
  616. }
  617. where(fieldPath, opStr, value) {
  618. try {
  619. // The "as string" cast is a little bit of a hack. `where` accepts the
  620. // FieldPath Compat type as input, but is not typed as such in order to
  621. // not expose this via our public typings file.
  622. return new Query(this.firestore, query(this._delegate, where(fieldPath, opStr, value)));
  623. }
  624. catch (e) {
  625. throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
  626. }
  627. }
  628. orderBy(fieldPath, directionStr) {
  629. try {
  630. // The "as string" cast is a little bit of a hack. `orderBy` accepts the
  631. // FieldPath Compat type as input, but is not typed as such in order to
  632. // not expose this via our public typings file.
  633. return new Query(this.firestore, query(this._delegate, orderBy(fieldPath, directionStr)));
  634. }
  635. catch (e) {
  636. throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
  637. }
  638. }
  639. limit(n) {
  640. try {
  641. return new Query(this.firestore, query(this._delegate, limit(n)));
  642. }
  643. catch (e) {
  644. throw replaceFunctionName(e, 'limit()', 'Query.limit()');
  645. }
  646. }
  647. limitToLast(n) {
  648. try {
  649. return new Query(this.firestore, query(this._delegate, limitToLast(n)));
  650. }
  651. catch (e) {
  652. throw replaceFunctionName(e, 'limitToLast()', 'Query.limitToLast()');
  653. }
  654. }
  655. startAt(...args) {
  656. try {
  657. return new Query(this.firestore, query(this._delegate, startAt(...args)));
  658. }
  659. catch (e) {
  660. throw replaceFunctionName(e, 'startAt()', 'Query.startAt()');
  661. }
  662. }
  663. startAfter(...args) {
  664. try {
  665. return new Query(this.firestore, query(this._delegate, startAfter(...args)));
  666. }
  667. catch (e) {
  668. throw replaceFunctionName(e, 'startAfter()', 'Query.startAfter()');
  669. }
  670. }
  671. endBefore(...args) {
  672. try {
  673. return new Query(this.firestore, query(this._delegate, endBefore(...args)));
  674. }
  675. catch (e) {
  676. throw replaceFunctionName(e, 'endBefore()', 'Query.endBefore()');
  677. }
  678. }
  679. endAt(...args) {
  680. try {
  681. return new Query(this.firestore, query(this._delegate, endAt(...args)));
  682. }
  683. catch (e) {
  684. throw replaceFunctionName(e, 'endAt()', 'Query.endAt()');
  685. }
  686. }
  687. isEqual(other) {
  688. return queryEqual(this._delegate, other._delegate);
  689. }
  690. get(options) {
  691. let query;
  692. if ((options === null || options === void 0 ? void 0 : options.source) === 'cache') {
  693. query = getDocsFromCache(this._delegate);
  694. }
  695. else if ((options === null || options === void 0 ? void 0 : options.source) === 'server') {
  696. query = getDocsFromServer(this._delegate);
  697. }
  698. else {
  699. query = getDocs(this._delegate);
  700. }
  701. return query.then(result => new QuerySnapshot(this.firestore, new QuerySnapshot$1(this.firestore._delegate, this._userDataWriter, this._delegate, result._snapshot)));
  702. }
  703. onSnapshot(...args) {
  704. const options = extractSnapshotOptions(args);
  705. const observer = wrapObserver(args, snap => new QuerySnapshot(this.firestore, new QuerySnapshot$1(this.firestore._delegate, this._userDataWriter, this._delegate, snap._snapshot)));
  706. return onSnapshot(this._delegate, options, observer);
  707. }
  708. withConverter(converter) {
  709. return new Query(this.firestore, converter
  710. ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
  711. : this._delegate.withConverter(null));
  712. }
  713. }
  714. class DocumentChange {
  715. constructor(_firestore, _delegate) {
  716. this._firestore = _firestore;
  717. this._delegate = _delegate;
  718. }
  719. get type() {
  720. return this._delegate.type;
  721. }
  722. get doc() {
  723. return new QueryDocumentSnapshot(this._firestore, this._delegate.doc);
  724. }
  725. get oldIndex() {
  726. return this._delegate.oldIndex;
  727. }
  728. get newIndex() {
  729. return this._delegate.newIndex;
  730. }
  731. }
  732. class QuerySnapshot {
  733. constructor(_firestore, _delegate) {
  734. this._firestore = _firestore;
  735. this._delegate = _delegate;
  736. }
  737. get query() {
  738. return new Query(this._firestore, this._delegate.query);
  739. }
  740. get metadata() {
  741. return this._delegate.metadata;
  742. }
  743. get size() {
  744. return this._delegate.size;
  745. }
  746. get empty() {
  747. return this._delegate.empty;
  748. }
  749. get docs() {
  750. return this._delegate.docs.map(doc => new QueryDocumentSnapshot(this._firestore, doc));
  751. }
  752. docChanges(options) {
  753. return this._delegate
  754. .docChanges(options)
  755. .map(docChange => new DocumentChange(this._firestore, docChange));
  756. }
  757. forEach(callback, thisArg) {
  758. this._delegate.forEach(snapshot => {
  759. callback.call(thisArg, new QueryDocumentSnapshot(this._firestore, snapshot));
  760. });
  761. }
  762. isEqual(other) {
  763. return snapshotEqual(this._delegate, other._delegate);
  764. }
  765. }
  766. class CollectionReference extends Query {
  767. constructor(firestore, _delegate) {
  768. super(firestore, _delegate);
  769. this.firestore = firestore;
  770. this._delegate = _delegate;
  771. }
  772. get id() {
  773. return this._delegate.id;
  774. }
  775. get path() {
  776. return this._delegate.path;
  777. }
  778. get parent() {
  779. const docRef = this._delegate.parent;
  780. return docRef ? new DocumentReference(this.firestore, docRef) : null;
  781. }
  782. doc(documentPath) {
  783. try {
  784. if (documentPath === undefined) {
  785. // Call `doc` without `documentPath` if `documentPath` is `undefined`
  786. // as `doc` validates the number of arguments to prevent users from
  787. // accidentally passing `undefined`.
  788. return new DocumentReference(this.firestore, doc(this._delegate));
  789. }
  790. else {
  791. return new DocumentReference(this.firestore, doc(this._delegate, documentPath));
  792. }
  793. }
  794. catch (e) {
  795. throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
  796. }
  797. }
  798. add(data) {
  799. return addDoc(this._delegate, data).then(docRef => new DocumentReference(this.firestore, docRef));
  800. }
  801. isEqual(other) {
  802. return refEqual(this._delegate, other._delegate);
  803. }
  804. withConverter(converter) {
  805. return new CollectionReference(this.firestore, converter
  806. ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
  807. : this._delegate.withConverter(null));
  808. }
  809. }
  810. function castReference(documentRef) {
  811. return _cast(documentRef, DocumentReference$1);
  812. }
  813. /**
  814. * @license
  815. * Copyright 2017 Google LLC
  816. *
  817. * Licensed under the Apache License, Version 2.0 (the "License");
  818. * you may not use this file except in compliance with the License.
  819. * You may obtain a copy of the License at
  820. *
  821. * http://www.apache.org/licenses/LICENSE-2.0
  822. *
  823. * Unless required by applicable law or agreed to in writing, software
  824. * distributed under the License is distributed on an "AS IS" BASIS,
  825. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  826. * See the License for the specific language governing permissions and
  827. * limitations under the License.
  828. */
  829. // The objects that are a part of this API are exposed to third-parties as
  830. // compiled javascript so we want to flag our private members with a leading
  831. // underscore to discourage their use.
  832. /**
  833. * A `FieldPath` refers to a field in a document. The path may consist of a
  834. * single field name (referring to a top-level field in the document), or a list
  835. * of field names (referring to a nested field in the document).
  836. */
  837. class FieldPath {
  838. /**
  839. * Creates a FieldPath from the provided field names. If more than one field
  840. * name is provided, the path will point to a nested field in a document.
  841. *
  842. * @param fieldNames - A list of field names.
  843. */
  844. constructor(...fieldNames) {
  845. this._delegate = new FieldPath$1(...fieldNames);
  846. }
  847. static documentId() {
  848. /**
  849. * Internal Note: The backend doesn't technically support querying by
  850. * document ID. Instead it queries by the entire document name (full path
  851. * included), but in the cases we currently support documentId(), the net
  852. * effect is the same.
  853. */
  854. return new FieldPath(_FieldPath.keyField().canonicalString());
  855. }
  856. isEqual(other) {
  857. other = getModularInstance(other);
  858. if (!(other instanceof FieldPath$1)) {
  859. return false;
  860. }
  861. return this._delegate._internalPath.isEqual(other._internalPath);
  862. }
  863. }
  864. /**
  865. * @license
  866. * Copyright 2017 Google LLC
  867. *
  868. * Licensed under the Apache License, Version 2.0 (the "License");
  869. * you may not use this file except in compliance with the License.
  870. * You may obtain a copy of the License at
  871. *
  872. * http://www.apache.org/licenses/LICENSE-2.0
  873. *
  874. * Unless required by applicable law or agreed to in writing, software
  875. * distributed under the License is distributed on an "AS IS" BASIS,
  876. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  877. * See the License for the specific language governing permissions and
  878. * limitations under the License.
  879. */
  880. class FieldValue {
  881. constructor(_delegate) {
  882. this._delegate = _delegate;
  883. }
  884. static serverTimestamp() {
  885. const delegate = serverTimestamp();
  886. delegate._methodName = 'FieldValue.serverTimestamp';
  887. return new FieldValue(delegate);
  888. }
  889. static delete() {
  890. const delegate = deleteField();
  891. delegate._methodName = 'FieldValue.delete';
  892. return new FieldValue(delegate);
  893. }
  894. static arrayUnion(...elements) {
  895. const delegate = arrayUnion(...elements);
  896. delegate._methodName = 'FieldValue.arrayUnion';
  897. return new FieldValue(delegate);
  898. }
  899. static arrayRemove(...elements) {
  900. const delegate = arrayRemove(...elements);
  901. delegate._methodName = 'FieldValue.arrayRemove';
  902. return new FieldValue(delegate);
  903. }
  904. static increment(n) {
  905. const delegate = increment(n);
  906. delegate._methodName = 'FieldValue.increment';
  907. return new FieldValue(delegate);
  908. }
  909. isEqual(other) {
  910. return this._delegate.isEqual(other._delegate);
  911. }
  912. }
  913. /**
  914. * @license
  915. * Copyright 2021 Google LLC
  916. *
  917. * Licensed under the Apache License, Version 2.0 (the "License");
  918. * you may not use this file except in compliance with the License.
  919. * You may obtain a copy of the License at
  920. *
  921. * http://www.apache.org/licenses/LICENSE-2.0
  922. *
  923. * Unless required by applicable law or agreed to in writing, software
  924. * distributed under the License is distributed on an "AS IS" BASIS,
  925. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  926. * See the License for the specific language governing permissions and
  927. * limitations under the License.
  928. */
  929. const firestoreNamespace = {
  930. Firestore,
  931. GeoPoint,
  932. Timestamp,
  933. Blob,
  934. Transaction,
  935. WriteBatch,
  936. DocumentReference,
  937. DocumentSnapshot,
  938. Query,
  939. QueryDocumentSnapshot,
  940. QuerySnapshot,
  941. CollectionReference,
  942. FieldPath,
  943. FieldValue,
  944. setLogLevel,
  945. CACHE_SIZE_UNLIMITED
  946. };
  947. /**
  948. * Configures Firestore as part of the Firebase SDK by calling registerComponent.
  949. *
  950. * @param firebase - The FirebaseNamespace to register Firestore with
  951. * @param firestoreFactory - A factory function that returns a new Firestore
  952. * instance.
  953. */
  954. function configureForFirebase(firebase, firestoreFactory) {
  955. firebase.INTERNAL.registerComponent(new Component('firestore-compat', container => {
  956. const app = container.getProvider('app-compat').getImmediate();
  957. const firestoreExp = container.getProvider('firestore').getImmediate();
  958. return firestoreFactory(app, firestoreExp);
  959. }, 'PUBLIC').setServiceProps(Object.assign({}, firestoreNamespace)));
  960. }
  961. /**
  962. * @license
  963. * Copyright 2020 Google LLC
  964. *
  965. * Licensed under the Apache License, Version 2.0 (the "License");
  966. * you may not use this file except in compliance with the License.
  967. * You may obtain a copy of the License at
  968. *
  969. * http://www.apache.org/licenses/LICENSE-2.0
  970. *
  971. * Unless required by applicable law or agreed to in writing, software
  972. * distributed under the License is distributed on an "AS IS" BASIS,
  973. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  974. * See the License for the specific language governing permissions and
  975. * limitations under the License.
  976. */
  977. /**
  978. * Registers the main Firestore ReactNative build with the components framework.
  979. * Persistence can be enabled via `firebase.firestore().enablePersistence()`.
  980. */
  981. function registerFirestore(instance) {
  982. configureForFirebase(instance, (app, firestoreExp) => new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider()));
  983. instance.registerVersion(name, version, 'rn');
  984. }
  985. registerFirestore(firebase);
  986. export { registerFirestore };
  987. //# sourceMappingURL=index.rn.js.map