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.esm5.js 45KB

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