@firebase/firestore 3.4.8 → 3.4.9-canary.0197076b8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/firestore/lite/index.d.ts +1 -0
  3. package/dist/firestore/src/api/transaction.d.ts +4 -1
  4. package/dist/firestore/src/api/transaction_options.d.ts +17 -0
  5. package/dist/firestore/src/api.d.ts +1 -0
  6. package/dist/firestore/src/core/firestore_client.d.ts +2 -1
  7. package/dist/firestore/src/core/query.d.ts +2 -4
  8. package/dist/firestore/src/core/target.d.ts +6 -4
  9. package/dist/firestore/src/core/transaction_options.d.ts +25 -0
  10. package/dist/firestore/src/core/transaction_runner.d.ts +3 -2
  11. package/dist/firestore/src/lite-api/transaction.d.ts +4 -1
  12. package/dist/firestore/src/lite-api/transaction_options.d.ts +23 -0
  13. package/dist/firestore/src/local/document_overlay_cache.d.ts +5 -0
  14. package/dist/firestore/src/local/index_manager.d.ts +24 -3
  15. package/dist/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -0
  16. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  17. package/dist/firestore/src/local/indexeddb_schema.d.ts +4 -2
  18. package/dist/firestore/src/local/indexeddb_schema_converter.d.ts +1 -0
  19. package/dist/firestore/src/local/indexeddb_sentinels.d.ts +1 -0
  20. package/dist/firestore/src/local/local_documents_view.d.ts +47 -8
  21. package/dist/firestore/src/local/memory_document_overlay_cache.d.ts +1 -0
  22. package/dist/firestore/src/local/memory_index_manager.d.ts +3 -2
  23. package/dist/firestore/src/local/overlayed_document.d.ts +36 -0
  24. package/dist/firestore/src/local/query_engine.d.ts +44 -5
  25. package/dist/firestore/src/model/collections.d.ts +3 -1
  26. package/dist/firestore/src/model/field_mask.d.ts +6 -0
  27. package/dist/firestore/src/model/mutation.d.ts +19 -1
  28. package/dist/firestore/src/model/mutation_batch.d.ts +9 -4
  29. package/dist/firestore/src/model/values.d.ts +14 -2
  30. package/dist/firestore/src/tsdoc-metadata.json +11 -11
  31. package/dist/firestore/src/util/misc.d.ts +3 -0
  32. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  33. package/dist/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -0
  34. package/dist/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  35. package/dist/firestore/test/util/helpers.d.ts +12 -0
  36. package/dist/index.d.ts +28 -3
  37. package/dist/index.esm2017.js +9384 -9023
  38. package/dist/index.esm2017.js.map +1 -1
  39. package/dist/index.esm5.js +7406 -7016
  40. package/dist/index.esm5.js.map +1 -1
  41. package/dist/index.node.cjs.js +5607 -5089
  42. package/dist/index.node.cjs.js.map +1 -1
  43. package/dist/index.node.mjs +5607 -5089
  44. package/dist/index.node.mjs.map +1 -1
  45. package/dist/index.rn.js +7162 -6801
  46. package/dist/index.rn.js.map +1 -1
  47. package/dist/internal.d.ts +6007 -5918
  48. package/dist/lite/firestore/lite/index.d.ts +1 -0
  49. package/dist/lite/firestore/src/api/transaction.d.ts +4 -1
  50. package/dist/lite/firestore/src/api/transaction_options.d.ts +17 -0
  51. package/dist/lite/firestore/src/api.d.ts +1 -0
  52. package/dist/lite/firestore/src/core/firestore_client.d.ts +2 -1
  53. package/dist/lite/firestore/src/core/query.d.ts +2 -4
  54. package/dist/lite/firestore/src/core/target.d.ts +6 -4
  55. package/dist/lite/firestore/src/core/transaction_options.d.ts +25 -0
  56. package/dist/lite/firestore/src/core/transaction_runner.d.ts +3 -2
  57. package/dist/lite/firestore/src/lite-api/transaction.d.ts +4 -1
  58. package/dist/lite/firestore/src/lite-api/transaction_options.d.ts +23 -0
  59. package/dist/lite/firestore/src/local/document_overlay_cache.d.ts +5 -0
  60. package/dist/lite/firestore/src/local/index_manager.d.ts +24 -3
  61. package/dist/lite/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -0
  62. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  63. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +4 -2
  64. package/dist/lite/firestore/src/local/indexeddb_schema_converter.d.ts +1 -0
  65. package/dist/lite/firestore/src/local/indexeddb_sentinels.d.ts +1 -0
  66. package/dist/lite/firestore/src/local/local_documents_view.d.ts +47 -8
  67. package/dist/lite/firestore/src/local/memory_document_overlay_cache.d.ts +1 -0
  68. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +3 -2
  69. package/dist/lite/firestore/src/local/overlayed_document.d.ts +36 -0
  70. package/dist/lite/firestore/src/local/query_engine.d.ts +44 -5
  71. package/dist/lite/firestore/src/model/collections.d.ts +3 -1
  72. package/dist/lite/firestore/src/model/field_mask.d.ts +6 -0
  73. package/dist/lite/firestore/src/model/mutation.d.ts +19 -1
  74. package/dist/lite/firestore/src/model/mutation_batch.d.ts +9 -4
  75. package/dist/lite/firestore/src/model/values.d.ts +14 -2
  76. package/dist/lite/firestore/src/util/misc.d.ts +3 -0
  77. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  78. package/dist/lite/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -0
  79. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  80. package/dist/lite/firestore/test/util/helpers.d.ts +12 -0
  81. package/dist/lite/index.browser.esm2017.js +1209 -698
  82. package/dist/lite/index.browser.esm2017.js.map +1 -1
  83. package/dist/lite/index.browser.esm5.js +1213 -813
  84. package/dist/lite/index.browser.esm5.js.map +1 -1
  85. package/dist/lite/index.d.ts +26 -1
  86. package/dist/lite/index.node.cjs.js +709 -15
  87. package/dist/lite/index.node.cjs.js.map +1 -1
  88. package/dist/lite/index.node.mjs +709 -15
  89. package/dist/lite/index.node.mjs.map +1 -1
  90. package/dist/lite/index.rn.esm2017.js +1828 -1317
  91. package/dist/lite/index.rn.esm2017.js.map +1 -1
  92. package/dist/lite/internal.d.ts +2912 -2874
  93. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +103 -101
  94. package/dist/lite/packages/firestore/lite/index.d.ts +1 -0
  95. package/dist/lite/packages/firestore/src/api/transaction.d.ts +4 -1
  96. package/dist/lite/packages/firestore/src/api/transaction_options.d.ts +17 -0
  97. package/dist/lite/packages/firestore/src/api.d.ts +1 -0
  98. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +2 -1
  99. package/dist/lite/packages/firestore/src/core/query.d.ts +2 -4
  100. package/dist/lite/packages/firestore/src/core/target.d.ts +6 -4
  101. package/dist/lite/packages/firestore/src/core/transaction_options.d.ts +25 -0
  102. package/dist/lite/packages/firestore/src/core/transaction_runner.d.ts +3 -2
  103. package/dist/lite/packages/firestore/src/lite-api/transaction.d.ts +4 -1
  104. package/dist/lite/packages/firestore/src/lite-api/transaction_options.d.ts +23 -0
  105. package/dist/lite/packages/firestore/src/local/document_overlay_cache.d.ts +5 -0
  106. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +24 -3
  107. package/dist/lite/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -0
  108. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  109. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +4 -2
  110. package/dist/lite/packages/firestore/src/local/indexeddb_schema_converter.d.ts +1 -0
  111. package/dist/lite/packages/firestore/src/local/indexeddb_sentinels.d.ts +1 -0
  112. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +47 -8
  113. package/dist/lite/packages/firestore/src/local/memory_document_overlay_cache.d.ts +1 -0
  114. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +3 -2
  115. package/dist/lite/packages/firestore/src/local/overlayed_document.d.ts +36 -0
  116. package/dist/lite/packages/firestore/src/local/query_engine.d.ts +44 -5
  117. package/dist/lite/packages/firestore/src/model/collections.d.ts +3 -1
  118. package/dist/lite/packages/firestore/src/model/field_mask.d.ts +6 -0
  119. package/dist/lite/packages/firestore/src/model/mutation.d.ts +19 -1
  120. package/dist/lite/packages/firestore/src/model/mutation_batch.d.ts +9 -4
  121. package/dist/lite/packages/firestore/src/model/values.d.ts +14 -2
  122. package/dist/lite/packages/firestore/src/util/misc.d.ts +3 -0
  123. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  124. package/dist/lite/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -0
  125. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  126. package/dist/lite/packages/firestore/test/util/helpers.d.ts +12 -0
  127. package/dist/lite/private.d.ts +2772 -2734
  128. package/dist/packages/firestore/dist/index.esm2017.d.ts +197 -194
  129. package/dist/packages/firestore/lite/index.d.ts +1 -0
  130. package/dist/packages/firestore/src/api/transaction.d.ts +4 -1
  131. package/dist/packages/firestore/src/api/transaction_options.d.ts +17 -0
  132. package/dist/packages/firestore/src/api.d.ts +1 -0
  133. package/dist/packages/firestore/src/core/firestore_client.d.ts +2 -1
  134. package/dist/packages/firestore/src/core/query.d.ts +2 -4
  135. package/dist/packages/firestore/src/core/target.d.ts +6 -4
  136. package/dist/packages/firestore/src/core/transaction_options.d.ts +25 -0
  137. package/dist/packages/firestore/src/core/transaction_runner.d.ts +3 -2
  138. package/dist/packages/firestore/src/lite-api/transaction.d.ts +4 -1
  139. package/dist/packages/firestore/src/lite-api/transaction_options.d.ts +23 -0
  140. package/dist/packages/firestore/src/local/document_overlay_cache.d.ts +5 -0
  141. package/dist/packages/firestore/src/local/index_manager.d.ts +24 -3
  142. package/dist/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +1 -0
  143. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  144. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +4 -2
  145. package/dist/packages/firestore/src/local/indexeddb_schema_converter.d.ts +1 -0
  146. package/dist/packages/firestore/src/local/indexeddb_sentinels.d.ts +1 -0
  147. package/dist/packages/firestore/src/local/local_documents_view.d.ts +47 -8
  148. package/dist/packages/firestore/src/local/memory_document_overlay_cache.d.ts +1 -0
  149. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +3 -2
  150. package/dist/packages/firestore/src/local/overlayed_document.d.ts +36 -0
  151. package/dist/packages/firestore/src/local/query_engine.d.ts +44 -5
  152. package/dist/packages/firestore/src/model/collections.d.ts +3 -1
  153. package/dist/packages/firestore/src/model/field_mask.d.ts +6 -0
  154. package/dist/packages/firestore/src/model/mutation.d.ts +19 -1
  155. package/dist/packages/firestore/src/model/mutation_batch.d.ts +9 -4
  156. package/dist/packages/firestore/src/model/values.d.ts +14 -2
  157. package/dist/packages/firestore/src/util/misc.d.ts +3 -0
  158. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  159. package/dist/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +1 -0
  160. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  161. package/dist/packages/firestore/test/util/helpers.d.ts +12 -0
  162. package/dist/private.d.ts +5715 -5626
  163. package/package.json +20 -18
@@ -14,7 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
14
 
15
15
  var nodeFetch__default = /*#__PURE__*/_interopDefaultLegacy(nodeFetch);
16
16
 
17
- const version$1 = "3.4.8";
17
+ const version$1 = "3.4.9-canary.0197076b8";
18
18
 
19
19
  /**
20
20
  * @license
@@ -67,7 +67,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
67
67
  User.FIRST_PARTY = new User('first-party-uid');
68
68
  User.MOCK_USER = new User('mock-user');
69
69
 
70
- const version = "9.6.11";
70
+ const version = "9.8.2-canary.0197076b8";
71
71
 
72
72
  /**
73
73
  * @license
@@ -1824,6 +1824,627 @@ function isEmpty(obj) {
1824
1824
  return true;
1825
1825
  }
1826
1826
 
1827
+ /**
1828
+ * @license
1829
+ * Copyright 2017 Google LLC
1830
+ *
1831
+ * Licensed under the Apache License, Version 2.0 (the "License");
1832
+ * you may not use this file except in compliance with the License.
1833
+ * You may obtain a copy of the License at
1834
+ *
1835
+ * http://www.apache.org/licenses/LICENSE-2.0
1836
+ *
1837
+ * Unless required by applicable law or agreed to in writing, software
1838
+ * distributed under the License is distributed on an "AS IS" BASIS,
1839
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1840
+ * See the License for the specific language governing permissions and
1841
+ * limitations under the License.
1842
+ */
1843
+ // An immutable sorted map implementation, based on a Left-leaning Red-Black
1844
+ // tree.
1845
+ class SortedMap {
1846
+ constructor(comparator, root) {
1847
+ this.comparator = comparator;
1848
+ this.root = root ? root : LLRBNode.EMPTY;
1849
+ }
1850
+ // Returns a copy of the map, with the specified key/value added or replaced.
1851
+ insert(key, value) {
1852
+ return new SortedMap(this.comparator, this.root
1853
+ .insert(key, value, this.comparator)
1854
+ .copy(null, null, LLRBNode.BLACK, null, null));
1855
+ }
1856
+ // Returns a copy of the map, with the specified key removed.
1857
+ remove(key) {
1858
+ return new SortedMap(this.comparator, this.root
1859
+ .remove(key, this.comparator)
1860
+ .copy(null, null, LLRBNode.BLACK, null, null));
1861
+ }
1862
+ // Returns the value of the node with the given key, or null.
1863
+ get(key) {
1864
+ let node = this.root;
1865
+ while (!node.isEmpty()) {
1866
+ const cmp = this.comparator(key, node.key);
1867
+ if (cmp === 0) {
1868
+ return node.value;
1869
+ }
1870
+ else if (cmp < 0) {
1871
+ node = node.left;
1872
+ }
1873
+ else if (cmp > 0) {
1874
+ node = node.right;
1875
+ }
1876
+ }
1877
+ return null;
1878
+ }
1879
+ // Returns the index of the element in this sorted map, or -1 if it doesn't
1880
+ // exist.
1881
+ indexOf(key) {
1882
+ // Number of nodes that were pruned when descending right
1883
+ let prunedNodes = 0;
1884
+ let node = this.root;
1885
+ while (!node.isEmpty()) {
1886
+ const cmp = this.comparator(key, node.key);
1887
+ if (cmp === 0) {
1888
+ return prunedNodes + node.left.size;
1889
+ }
1890
+ else if (cmp < 0) {
1891
+ node = node.left;
1892
+ }
1893
+ else {
1894
+ // Count all nodes left of the node plus the node itself
1895
+ prunedNodes += node.left.size + 1;
1896
+ node = node.right;
1897
+ }
1898
+ }
1899
+ // Node not found
1900
+ return -1;
1901
+ }
1902
+ isEmpty() {
1903
+ return this.root.isEmpty();
1904
+ }
1905
+ // Returns the total number of nodes in the map.
1906
+ get size() {
1907
+ return this.root.size;
1908
+ }
1909
+ // Returns the minimum key in the map.
1910
+ minKey() {
1911
+ return this.root.minKey();
1912
+ }
1913
+ // Returns the maximum key in the map.
1914
+ maxKey() {
1915
+ return this.root.maxKey();
1916
+ }
1917
+ // Traverses the map in key order and calls the specified action function
1918
+ // for each key/value pair. If action returns true, traversal is aborted.
1919
+ // Returns the first truthy value returned by action, or the last falsey
1920
+ // value returned by action.
1921
+ inorderTraversal(action) {
1922
+ return this.root.inorderTraversal(action);
1923
+ }
1924
+ forEach(fn) {
1925
+ this.inorderTraversal((k, v) => {
1926
+ fn(k, v);
1927
+ return false;
1928
+ });
1929
+ }
1930
+ toString() {
1931
+ const descriptions = [];
1932
+ this.inorderTraversal((k, v) => {
1933
+ descriptions.push(`${k}:${v}`);
1934
+ return false;
1935
+ });
1936
+ return `{${descriptions.join(', ')}}`;
1937
+ }
1938
+ // Traverses the map in reverse key order and calls the specified action
1939
+ // function for each key/value pair. If action returns true, traversal is
1940
+ // aborted.
1941
+ // Returns the first truthy value returned by action, or the last falsey
1942
+ // value returned by action.
1943
+ reverseTraversal(action) {
1944
+ return this.root.reverseTraversal(action);
1945
+ }
1946
+ // Returns an iterator over the SortedMap.
1947
+ getIterator() {
1948
+ return new SortedMapIterator(this.root, null, this.comparator, false);
1949
+ }
1950
+ getIteratorFrom(key) {
1951
+ return new SortedMapIterator(this.root, key, this.comparator, false);
1952
+ }
1953
+ getReverseIterator() {
1954
+ return new SortedMapIterator(this.root, null, this.comparator, true);
1955
+ }
1956
+ getReverseIteratorFrom(key) {
1957
+ return new SortedMapIterator(this.root, key, this.comparator, true);
1958
+ }
1959
+ } // end SortedMap
1960
+ // An iterator over an LLRBNode.
1961
+ class SortedMapIterator {
1962
+ constructor(node, startKey, comparator, isReverse) {
1963
+ this.isReverse = isReverse;
1964
+ this.nodeStack = [];
1965
+ let cmp = 1;
1966
+ while (!node.isEmpty()) {
1967
+ cmp = startKey ? comparator(node.key, startKey) : 1;
1968
+ // flip the comparison if we're going in reverse
1969
+ if (startKey && isReverse) {
1970
+ cmp *= -1;
1971
+ }
1972
+ if (cmp < 0) {
1973
+ // This node is less than our start key. ignore it
1974
+ if (this.isReverse) {
1975
+ node = node.left;
1976
+ }
1977
+ else {
1978
+ node = node.right;
1979
+ }
1980
+ }
1981
+ else if (cmp === 0) {
1982
+ // This node is exactly equal to our start key. Push it on the stack,
1983
+ // but stop iterating;
1984
+ this.nodeStack.push(node);
1985
+ break;
1986
+ }
1987
+ else {
1988
+ // This node is greater than our start key, add it to the stack and move
1989
+ // to the next one
1990
+ this.nodeStack.push(node);
1991
+ if (this.isReverse) {
1992
+ node = node.right;
1993
+ }
1994
+ else {
1995
+ node = node.left;
1996
+ }
1997
+ }
1998
+ }
1999
+ }
2000
+ getNext() {
2001
+ let node = this.nodeStack.pop();
2002
+ const result = { key: node.key, value: node.value };
2003
+ if (this.isReverse) {
2004
+ node = node.left;
2005
+ while (!node.isEmpty()) {
2006
+ this.nodeStack.push(node);
2007
+ node = node.right;
2008
+ }
2009
+ }
2010
+ else {
2011
+ node = node.right;
2012
+ while (!node.isEmpty()) {
2013
+ this.nodeStack.push(node);
2014
+ node = node.left;
2015
+ }
2016
+ }
2017
+ return result;
2018
+ }
2019
+ hasNext() {
2020
+ return this.nodeStack.length > 0;
2021
+ }
2022
+ peek() {
2023
+ if (this.nodeStack.length === 0) {
2024
+ return null;
2025
+ }
2026
+ const node = this.nodeStack[this.nodeStack.length - 1];
2027
+ return { key: node.key, value: node.value };
2028
+ }
2029
+ } // end SortedMapIterator
2030
+ // Represents a node in a Left-leaning Red-Black tree.
2031
+ class LLRBNode {
2032
+ constructor(key, value, color, left, right) {
2033
+ this.key = key;
2034
+ this.value = value;
2035
+ this.color = color != null ? color : LLRBNode.RED;
2036
+ this.left = left != null ? left : LLRBNode.EMPTY;
2037
+ this.right = right != null ? right : LLRBNode.EMPTY;
2038
+ this.size = this.left.size + 1 + this.right.size;
2039
+ }
2040
+ // Returns a copy of the current node, optionally replacing pieces of it.
2041
+ copy(key, value, color, left, right) {
2042
+ return new LLRBNode(key != null ? key : this.key, value != null ? value : this.value, color != null ? color : this.color, left != null ? left : this.left, right != null ? right : this.right);
2043
+ }
2044
+ isEmpty() {
2045
+ return false;
2046
+ }
2047
+ // Traverses the tree in key order and calls the specified action function
2048
+ // for each node. If action returns true, traversal is aborted.
2049
+ // Returns the first truthy value returned by action, or the last falsey
2050
+ // value returned by action.
2051
+ inorderTraversal(action) {
2052
+ return (this.left.inorderTraversal(action) ||
2053
+ action(this.key, this.value) ||
2054
+ this.right.inorderTraversal(action));
2055
+ }
2056
+ // Traverses the tree in reverse key order and calls the specified action
2057
+ // function for each node. If action returns true, traversal is aborted.
2058
+ // Returns the first truthy value returned by action, or the last falsey
2059
+ // value returned by action.
2060
+ reverseTraversal(action) {
2061
+ return (this.right.reverseTraversal(action) ||
2062
+ action(this.key, this.value) ||
2063
+ this.left.reverseTraversal(action));
2064
+ }
2065
+ // Returns the minimum node in the tree.
2066
+ min() {
2067
+ if (this.left.isEmpty()) {
2068
+ return this;
2069
+ }
2070
+ else {
2071
+ return this.left.min();
2072
+ }
2073
+ }
2074
+ // Returns the maximum key in the tree.
2075
+ minKey() {
2076
+ return this.min().key;
2077
+ }
2078
+ // Returns the maximum key in the tree.
2079
+ maxKey() {
2080
+ if (this.right.isEmpty()) {
2081
+ return this.key;
2082
+ }
2083
+ else {
2084
+ return this.right.maxKey();
2085
+ }
2086
+ }
2087
+ // Returns new tree, with the key/value added.
2088
+ insert(key, value, comparator) {
2089
+ let n = this;
2090
+ const cmp = comparator(key, n.key);
2091
+ if (cmp < 0) {
2092
+ n = n.copy(null, null, null, n.left.insert(key, value, comparator), null);
2093
+ }
2094
+ else if (cmp === 0) {
2095
+ n = n.copy(null, value, null, null, null);
2096
+ }
2097
+ else {
2098
+ n = n.copy(null, null, null, null, n.right.insert(key, value, comparator));
2099
+ }
2100
+ return n.fixUp();
2101
+ }
2102
+ removeMin() {
2103
+ if (this.left.isEmpty()) {
2104
+ return LLRBNode.EMPTY;
2105
+ }
2106
+ let n = this;
2107
+ if (!n.left.isRed() && !n.left.left.isRed()) {
2108
+ n = n.moveRedLeft();
2109
+ }
2110
+ n = n.copy(null, null, null, n.left.removeMin(), null);
2111
+ return n.fixUp();
2112
+ }
2113
+ // Returns new tree, with the specified item removed.
2114
+ remove(key, comparator) {
2115
+ let smallest;
2116
+ let n = this;
2117
+ if (comparator(key, n.key) < 0) {
2118
+ if (!n.left.isEmpty() && !n.left.isRed() && !n.left.left.isRed()) {
2119
+ n = n.moveRedLeft();
2120
+ }
2121
+ n = n.copy(null, null, null, n.left.remove(key, comparator), null);
2122
+ }
2123
+ else {
2124
+ if (n.left.isRed()) {
2125
+ n = n.rotateRight();
2126
+ }
2127
+ if (!n.right.isEmpty() && !n.right.isRed() && !n.right.left.isRed()) {
2128
+ n = n.moveRedRight();
2129
+ }
2130
+ if (comparator(key, n.key) === 0) {
2131
+ if (n.right.isEmpty()) {
2132
+ return LLRBNode.EMPTY;
2133
+ }
2134
+ else {
2135
+ smallest = n.right.min();
2136
+ n = n.copy(smallest.key, smallest.value, null, null, n.right.removeMin());
2137
+ }
2138
+ }
2139
+ n = n.copy(null, null, null, null, n.right.remove(key, comparator));
2140
+ }
2141
+ return n.fixUp();
2142
+ }
2143
+ isRed() {
2144
+ return this.color;
2145
+ }
2146
+ // Returns new tree after performing any needed rotations.
2147
+ fixUp() {
2148
+ let n = this;
2149
+ if (n.right.isRed() && !n.left.isRed()) {
2150
+ n = n.rotateLeft();
2151
+ }
2152
+ if (n.left.isRed() && n.left.left.isRed()) {
2153
+ n = n.rotateRight();
2154
+ }
2155
+ if (n.left.isRed() && n.right.isRed()) {
2156
+ n = n.colorFlip();
2157
+ }
2158
+ return n;
2159
+ }
2160
+ moveRedLeft() {
2161
+ let n = this.colorFlip();
2162
+ if (n.right.left.isRed()) {
2163
+ n = n.copy(null, null, null, null, n.right.rotateRight());
2164
+ n = n.rotateLeft();
2165
+ n = n.colorFlip();
2166
+ }
2167
+ return n;
2168
+ }
2169
+ moveRedRight() {
2170
+ let n = this.colorFlip();
2171
+ if (n.left.left.isRed()) {
2172
+ n = n.rotateRight();
2173
+ n = n.colorFlip();
2174
+ }
2175
+ return n;
2176
+ }
2177
+ rotateLeft() {
2178
+ const nl = this.copy(null, null, LLRBNode.RED, null, this.right.left);
2179
+ return this.right.copy(null, null, this.color, nl, null);
2180
+ }
2181
+ rotateRight() {
2182
+ const nr = this.copy(null, null, LLRBNode.RED, this.left.right, null);
2183
+ return this.left.copy(null, null, this.color, null, nr);
2184
+ }
2185
+ colorFlip() {
2186
+ const left = this.left.copy(null, null, !this.left.color, null, null);
2187
+ const right = this.right.copy(null, null, !this.right.color, null, null);
2188
+ return this.copy(null, null, !this.color, left, right);
2189
+ }
2190
+ // For testing.
2191
+ checkMaxDepth() {
2192
+ const blackDepth = this.check();
2193
+ if (Math.pow(2.0, blackDepth) <= this.size + 1) {
2194
+ return true;
2195
+ }
2196
+ else {
2197
+ return false;
2198
+ }
2199
+ }
2200
+ // In a balanced RB tree, the black-depth (number of black nodes) from root to
2201
+ // leaves is equal on both sides. This function verifies that or asserts.
2202
+ check() {
2203
+ if (this.isRed() && this.left.isRed()) {
2204
+ throw fail();
2205
+ }
2206
+ if (this.right.isRed()) {
2207
+ throw fail();
2208
+ }
2209
+ const blackDepth = this.left.check();
2210
+ if (blackDepth !== this.right.check()) {
2211
+ throw fail();
2212
+ }
2213
+ else {
2214
+ return blackDepth + (this.isRed() ? 0 : 1);
2215
+ }
2216
+ }
2217
+ } // end LLRBNode
2218
+ // Empty node is shared between all LLRB trees.
2219
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2220
+ LLRBNode.EMPTY = null;
2221
+ LLRBNode.RED = true;
2222
+ LLRBNode.BLACK = false;
2223
+ // Represents an empty node (a leaf node in the Red-Black Tree).
2224
+ class LLRBEmptyNode {
2225
+ constructor() {
2226
+ this.size = 0;
2227
+ }
2228
+ get key() {
2229
+ throw fail();
2230
+ }
2231
+ get value() {
2232
+ throw fail();
2233
+ }
2234
+ get color() {
2235
+ throw fail();
2236
+ }
2237
+ get left() {
2238
+ throw fail();
2239
+ }
2240
+ get right() {
2241
+ throw fail();
2242
+ }
2243
+ // Returns a copy of the current node.
2244
+ copy(key, value, color, left, right) {
2245
+ return this;
2246
+ }
2247
+ // Returns a copy of the tree, with the specified key/value added.
2248
+ insert(key, value, comparator) {
2249
+ return new LLRBNode(key, value);
2250
+ }
2251
+ // Returns a copy of the tree, with the specified key removed.
2252
+ remove(key, comparator) {
2253
+ return this;
2254
+ }
2255
+ isEmpty() {
2256
+ return true;
2257
+ }
2258
+ inorderTraversal(action) {
2259
+ return false;
2260
+ }
2261
+ reverseTraversal(action) {
2262
+ return false;
2263
+ }
2264
+ minKey() {
2265
+ return null;
2266
+ }
2267
+ maxKey() {
2268
+ return null;
2269
+ }
2270
+ isRed() {
2271
+ return false;
2272
+ }
2273
+ // For testing.
2274
+ checkMaxDepth() {
2275
+ return true;
2276
+ }
2277
+ check() {
2278
+ return 0;
2279
+ }
2280
+ } // end LLRBEmptyNode
2281
+ LLRBNode.EMPTY = new LLRBEmptyNode();
2282
+
2283
+ /**
2284
+ * @license
2285
+ * Copyright 2017 Google LLC
2286
+ *
2287
+ * Licensed under the Apache License, Version 2.0 (the "License");
2288
+ * you may not use this file except in compliance with the License.
2289
+ * You may obtain a copy of the License at
2290
+ *
2291
+ * http://www.apache.org/licenses/LICENSE-2.0
2292
+ *
2293
+ * Unless required by applicable law or agreed to in writing, software
2294
+ * distributed under the License is distributed on an "AS IS" BASIS,
2295
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2296
+ * See the License for the specific language governing permissions and
2297
+ * limitations under the License.
2298
+ */
2299
+ /**
2300
+ * SortedSet is an immutable (copy-on-write) collection that holds elements
2301
+ * in order specified by the provided comparator.
2302
+ *
2303
+ * NOTE: if provided comparator returns 0 for two elements, we consider them to
2304
+ * be equal!
2305
+ */
2306
+ class SortedSet {
2307
+ constructor(comparator) {
2308
+ this.comparator = comparator;
2309
+ this.data = new SortedMap(this.comparator);
2310
+ }
2311
+ has(elem) {
2312
+ return this.data.get(elem) !== null;
2313
+ }
2314
+ first() {
2315
+ return this.data.minKey();
2316
+ }
2317
+ last() {
2318
+ return this.data.maxKey();
2319
+ }
2320
+ get size() {
2321
+ return this.data.size;
2322
+ }
2323
+ indexOf(elem) {
2324
+ return this.data.indexOf(elem);
2325
+ }
2326
+ /** Iterates elements in order defined by "comparator" */
2327
+ forEach(cb) {
2328
+ this.data.inorderTraversal((k, v) => {
2329
+ cb(k);
2330
+ return false;
2331
+ });
2332
+ }
2333
+ /** Iterates over `elem`s such that: range[0] &lt;= elem &lt; range[1]. */
2334
+ forEachInRange(range, cb) {
2335
+ const iter = this.data.getIteratorFrom(range[0]);
2336
+ while (iter.hasNext()) {
2337
+ const elem = iter.getNext();
2338
+ if (this.comparator(elem.key, range[1]) >= 0) {
2339
+ return;
2340
+ }
2341
+ cb(elem.key);
2342
+ }
2343
+ }
2344
+ /**
2345
+ * Iterates over `elem`s such that: start &lt;= elem until false is returned.
2346
+ */
2347
+ forEachWhile(cb, start) {
2348
+ let iter;
2349
+ if (start !== undefined) {
2350
+ iter = this.data.getIteratorFrom(start);
2351
+ }
2352
+ else {
2353
+ iter = this.data.getIterator();
2354
+ }
2355
+ while (iter.hasNext()) {
2356
+ const elem = iter.getNext();
2357
+ const result = cb(elem.key);
2358
+ if (!result) {
2359
+ return;
2360
+ }
2361
+ }
2362
+ }
2363
+ /** Finds the least element greater than or equal to `elem`. */
2364
+ firstAfterOrEqual(elem) {
2365
+ const iter = this.data.getIteratorFrom(elem);
2366
+ return iter.hasNext() ? iter.getNext().key : null;
2367
+ }
2368
+ getIterator() {
2369
+ return new SortedSetIterator(this.data.getIterator());
2370
+ }
2371
+ getIteratorFrom(key) {
2372
+ return new SortedSetIterator(this.data.getIteratorFrom(key));
2373
+ }
2374
+ /** Inserts or updates an element */
2375
+ add(elem) {
2376
+ return this.copy(this.data.remove(elem).insert(elem, true));
2377
+ }
2378
+ /** Deletes an element */
2379
+ delete(elem) {
2380
+ if (!this.has(elem)) {
2381
+ return this;
2382
+ }
2383
+ return this.copy(this.data.remove(elem));
2384
+ }
2385
+ isEmpty() {
2386
+ return this.data.isEmpty();
2387
+ }
2388
+ unionWith(other) {
2389
+ let result = this;
2390
+ // Make sure `result` always refers to the larger one of the two sets.
2391
+ if (result.size < other.size) {
2392
+ result = other;
2393
+ other = this;
2394
+ }
2395
+ other.forEach(elem => {
2396
+ result = result.add(elem);
2397
+ });
2398
+ return result;
2399
+ }
2400
+ isEqual(other) {
2401
+ if (!(other instanceof SortedSet)) {
2402
+ return false;
2403
+ }
2404
+ if (this.size !== other.size) {
2405
+ return false;
2406
+ }
2407
+ const thisIt = this.data.getIterator();
2408
+ const otherIt = other.data.getIterator();
2409
+ while (thisIt.hasNext()) {
2410
+ const thisElem = thisIt.getNext().key;
2411
+ const otherElem = otherIt.getNext().key;
2412
+ if (this.comparator(thisElem, otherElem) !== 0) {
2413
+ return false;
2414
+ }
2415
+ }
2416
+ return true;
2417
+ }
2418
+ toArray() {
2419
+ const res = [];
2420
+ this.forEach(targetId => {
2421
+ res.push(targetId);
2422
+ });
2423
+ return res;
2424
+ }
2425
+ toString() {
2426
+ const result = [];
2427
+ this.forEach(elem => result.push(elem));
2428
+ return 'SortedSet(' + result.toString() + ')';
2429
+ }
2430
+ copy(data) {
2431
+ const result = new SortedSet(this.comparator);
2432
+ result.data = data;
2433
+ return result;
2434
+ }
2435
+ }
2436
+ class SortedSetIterator {
2437
+ constructor(iter) {
2438
+ this.iter = iter;
2439
+ }
2440
+ getNext() {
2441
+ return this.iter.getNext().key;
2442
+ }
2443
+ hasNext() {
2444
+ return this.iter.hasNext();
2445
+ }
2446
+ }
2447
+
1827
2448
  /**
1828
2449
  * @license
1829
2450
  * Copyright 2020 Google LLC
@@ -1857,6 +2478,23 @@ class FieldMask {
1857
2478
  // Sort the field mask to support `FieldMask.isEqual()` and assert below.
1858
2479
  fields.sort(FieldPath$1.comparator);
1859
2480
  }
2481
+ static empty() {
2482
+ return new FieldMask([]);
2483
+ }
2484
+ /**
2485
+ * Returns a new FieldMask object that is the result of adding all the given
2486
+ * fields paths to this field mask.
2487
+ */
2488
+ unionWith(extraFields) {
2489
+ let mergedMaskSet = new SortedSet(FieldPath$1.comparator);
2490
+ for (const fieldPath of this.fields) {
2491
+ mergedMaskSet = mergedMaskSet.add(fieldPath);
2492
+ }
2493
+ for (const fieldPath of extraFields) {
2494
+ mergedMaskSet = mergedMaskSet.add(fieldPath);
2495
+ }
2496
+ return new FieldMask(mergedMaskSet.toArray());
2497
+ }
1860
2498
  /**
1861
2499
  * Verifies that `fieldPath` is included by at least one field in this field
1862
2500
  * mask.
@@ -2194,6 +2832,13 @@ function isSafeInteger(value) {
2194
2832
  * limitations under the License.
2195
2833
  */
2196
2834
  const MAX_VALUE_TYPE = '__max__';
2835
+ const MAX_VALUE = {
2836
+ mapValue: {
2837
+ fields: {
2838
+ '__type__': { stringValue: MAX_VALUE_TYPE }
2839
+ }
2840
+ }
2841
+ };
2197
2842
  /** Extracts the backend's type order for the provided value. */
2198
2843
  function typeOrder(value) {
2199
2844
  if ('nullValue' in value) {
@@ -2228,7 +2873,7 @@ function typeOrder(value) {
2228
2873
  return 4 /* ServerTimestampValue */;
2229
2874
  }
2230
2875
  else if (isMaxValue(value)) {
2231
- return 9 /* ArrayValue */;
2876
+ return 9007199254740991 /* MaxValue */;
2232
2877
  }
2233
2878
  return 10 /* ObjectValue */;
2234
2879
  }
@@ -2440,6 +3085,15 @@ function compareArrays(left, right) {
2440
3085
  return primitiveComparator(leftArray.length, rightArray.length);
2441
3086
  }
2442
3087
  function compareMaps(left, right) {
3088
+ if (left === MAX_VALUE.mapValue && right === MAX_VALUE.mapValue) {
3089
+ return 0;
3090
+ }
3091
+ else if (left === MAX_VALUE.mapValue) {
3092
+ return 1;
3093
+ }
3094
+ else if (right === MAX_VALUE.mapValue) {
3095
+ return -1;
3096
+ }
2443
3097
  const leftMap = left.fields || {};
2444
3098
  const leftKeys = Object.keys(leftMap);
2445
3099
  const rightMap = right.fields || {};
@@ -2752,6 +3406,7 @@ class MutableDocument {
2752
3406
  }
2753
3407
  setHasLocalMutations() {
2754
3408
  this.documentState = 1 /* HAS_LOCAL_MUTATIONS */;
3409
+ this.version = SnapshotVersion.min();
2755
3410
  return this;
2756
3411
  }
2757
3412
  setReadTime(readTime) {
@@ -3140,9 +3795,6 @@ class QueryImpl {
3140
3795
  function newQueryForPath(path) {
3141
3796
  return new QueryImpl(path);
3142
3797
  }
3143
- function hasLimitToLast(query) {
3144
- return !isNullOrUndefined(query.limit) && query.limitType === "L" /* Last */;
3145
- }
3146
3798
  function getFirstOrderByField(query) {
3147
3799
  return query.explicitOrderBy.length > 0
3148
3800
  ? query.explicitOrderBy[0].field
@@ -3243,10 +3895,10 @@ function queryToTarget(query) {
3243
3895
  }
3244
3896
  // We need to swap the cursors to match the now-flipped query ordering.
3245
3897
  const startAt = queryImpl.endAt
3246
- ? new Bound(queryImpl.endAt.position, !queryImpl.endAt.inclusive)
3898
+ ? new Bound(queryImpl.endAt.position, queryImpl.endAt.inclusive)
3247
3899
  : null;
3248
3900
  const endAt = queryImpl.startAt
3249
- ? new Bound(queryImpl.startAt.position, !queryImpl.startAt.inclusive)
3901
+ ? new Bound(queryImpl.startAt.position, queryImpl.startAt.inclusive)
3250
3902
  : null;
3251
3903
  // Now return as a LimitType.First query.
3252
3904
  queryImpl.memoizedTarget = newTarget(queryImpl.path, queryImpl.collectionGroup, orderBys, queryImpl.filters, queryImpl.limit, startAt, endAt);
@@ -3496,6 +4148,9 @@ class SetMutation extends Mutation {
3496
4148
  this.fieldTransforms = fieldTransforms;
3497
4149
  this.type = 0 /* Set */;
3498
4150
  }
4151
+ getFieldMask() {
4152
+ return null;
4153
+ }
3499
4154
  }
3500
4155
  /**
3501
4156
  * A mutation that modifies fields of the document at the given key with the
@@ -3520,6 +4175,9 @@ class PatchMutation extends Mutation {
3520
4175
  this.fieldTransforms = fieldTransforms;
3521
4176
  this.type = 1 /* Patch */;
3522
4177
  }
4178
+ getFieldMask() {
4179
+ return this.fieldMask;
4180
+ }
3523
4181
  }
3524
4182
  /** A mutation that deletes the document at the given key. */
3525
4183
  class DeleteMutation extends Mutation {
@@ -3530,6 +4188,9 @@ class DeleteMutation extends Mutation {
3530
4188
  this.type = 2 /* Delete */;
3531
4189
  this.fieldTransforms = [];
3532
4190
  }
4191
+ getFieldMask() {
4192
+ return null;
4193
+ }
3533
4194
  }
3534
4195
  /**
3535
4196
  * A mutation that verifies the existence of the document at the given key with
@@ -3546,6 +4207,9 @@ class VerifyMutation extends Mutation {
3546
4207
  this.type = 3 /* Verify */;
3547
4208
  this.fieldTransforms = [];
3548
4209
  }
4210
+ getFieldMask() {
4211
+ return null;
4212
+ }
3549
4213
  }
3550
4214
 
3551
4215
  /**
@@ -6064,7 +6728,8 @@ function fieldPathFromArgument(methodName, arg) {
6064
6728
  * limitations under the License.
6065
6729
  */
6066
6730
  function validateHasExplicitOrderByForLimitToLast(query) {
6067
- if (hasLimitToLast(query) && query.explicitOrderBy.length === 0) {
6731
+ if (query.limitType === "L" /* Last */ &&
6732
+ query.explicitOrderBy.length === 0) {
6068
6733
  throw new FirestoreError(Code.UNIMPLEMENTED, 'limitToLast() queries require specifying at least one orderBy() clause');
6069
6734
  }
6070
6735
  }
@@ -6704,7 +7369,7 @@ function getDocs(query) {
6704
7369
  const userDataWriter = new LiteUserDataWriter(query.firestore);
6705
7370
  return invokeRunQueryRpc(datastore, query._query).then(result => {
6706
7371
  const docs = result.map(doc => new QueryDocumentSnapshot(query.firestore, userDataWriter, doc.key, doc, query.converter));
6707
- if (hasLimitToLast(query._query)) {
7372
+ if (query._query.limitType === "L" /* Last */) {
6708
7373
  // Limit to last queries reverse the orderBy constraint that was
6709
7374
  // specified by the user. As such, we need to reverse the order of the
6710
7375
  // results to return the documents in the expected order.
@@ -6999,6 +7664,31 @@ function writeBatch(firestore) {
6999
7664
  return new WriteBatch(firestore, writes => invokeCommitRpc(datastore, writes));
7000
7665
  }
7001
7666
 
7667
+ /**
7668
+ * @license
7669
+ * Copyright 2022 Google LLC
7670
+ *
7671
+ * Licensed under the Apache License, Version 2.0 (the "License");
7672
+ * you may not use this file except in compliance with the License.
7673
+ * You may obtain a copy of the License at
7674
+ *
7675
+ * http://www.apache.org/licenses/LICENSE-2.0
7676
+ *
7677
+ * Unless required by applicable law or agreed to in writing, software
7678
+ * distributed under the License is distributed on an "AS IS" BASIS,
7679
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7680
+ * See the License for the specific language governing permissions and
7681
+ * limitations under the License.
7682
+ */
7683
+ const DEFAULT_TRANSACTION_OPTIONS = {
7684
+ maxAttempts: 5
7685
+ };
7686
+ function validateTransactionOptions(options) {
7687
+ if (options.maxAttempts < 1) {
7688
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'Max attempts must be at least 1');
7689
+ }
7690
+ }
7691
+
7002
7692
  /**
7003
7693
  * @license
7004
7694
  * Copyright 2017 Google LLC
@@ -7173,18 +7863,18 @@ class Transaction$1 {
7173
7863
  * See the License for the specific language governing permissions and
7174
7864
  * limitations under the License.
7175
7865
  */
7176
- const DEFAULT_MAX_ATTEMPTS_COUNT = 5;
7177
7866
  /**
7178
7867
  * TransactionRunner encapsulates the logic needed to run and retry transactions
7179
7868
  * with backoff.
7180
7869
  */
7181
7870
  class TransactionRunner {
7182
- constructor(asyncQueue, datastore, updateFunction, deferred) {
7871
+ constructor(asyncQueue, datastore, options, updateFunction, deferred) {
7183
7872
  this.asyncQueue = asyncQueue;
7184
7873
  this.datastore = datastore;
7874
+ this.options = options;
7185
7875
  this.updateFunction = updateFunction;
7186
7876
  this.deferred = deferred;
7187
- this.attemptsRemaining = DEFAULT_MAX_ATTEMPTS_COUNT;
7877
+ this.attemptsRemaining = options.maxAttempts;
7188
7878
  this.backoff = new ExponentialBackoff(this.asyncQueue, "transaction_retry" /* TransactionRetry */);
7189
7879
  }
7190
7880
  /** Runs the transaction and sets the result on deferred. */
@@ -7723,16 +8413,20 @@ class Transaction {
7723
8413
  * transaction against.
7724
8414
  * @param updateFunction - The function to execute within the transaction
7725
8415
  * context.
8416
+ * @param options - An options object to configure maximum number of attempts to
8417
+ * commit.
7726
8418
  * @returns If the transaction completed successfully or was explicitly aborted
7727
8419
  * (the `updateFunction` returned a failed promise), the promise returned by the
7728
8420
  * `updateFunction `is returned here. Otherwise, if the transaction failed, a
7729
8421
  * rejected promise with the corresponding failure error is returned.
7730
8422
  */
7731
- function runTransaction(firestore, updateFunction) {
8423
+ function runTransaction(firestore, updateFunction, options) {
7732
8424
  firestore = cast(firestore, Firestore);
7733
8425
  const datastore = getDatastore(firestore);
8426
+ const optionsWithDefaults = Object.assign(Object.assign({}, DEFAULT_TRANSACTION_OPTIONS), options);
8427
+ validateTransactionOptions(optionsWithDefaults);
7734
8428
  const deferred = new Deferred();
7735
- new TransactionRunner(newAsyncQueue(), datastore, internalTransaction => updateFunction(new Transaction(firestore, internalTransaction)), deferred).run();
8429
+ new TransactionRunner(newAsyncQueue(), datastore, optionsWithDefaults, internalTransaction => updateFunction(new Transaction(firestore, internalTransaction)), deferred).run();
7736
8430
  return deferred.promise;
7737
8431
  }
7738
8432