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.node.cjs.js 36KB

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