@firebase/firestore 3.4.8 → 3.4.9

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 (118) 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 +2 -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 +2 -1
  12. package/dist/firestore/src/lite-api/transaction_options.d.ts +23 -0
  13. package/dist/firestore/src/local/index_manager.d.ts +24 -3
  14. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  15. package/dist/firestore/src/local/indexeddb_schema.d.ts +1 -0
  16. package/dist/firestore/src/local/local_documents_view.d.ts +1 -1
  17. package/dist/firestore/src/local/memory_index_manager.d.ts +3 -2
  18. package/dist/firestore/src/local/query_engine.d.ts +44 -5
  19. package/dist/firestore/src/model/collections.d.ts +1 -1
  20. package/dist/firestore/src/model/values.d.ts +14 -2
  21. package/dist/firestore/src/util/misc.d.ts +3 -0
  22. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  23. package/dist/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  24. package/dist/index.d.ts +24 -1
  25. package/dist/index.esm2017.js +4108 -3992
  26. package/dist/index.esm2017.js.map +1 -1
  27. package/dist/index.esm5.js +4198 -4087
  28. package/dist/index.esm5.js.map +1 -1
  29. package/dist/index.node.cjs.js +1711 -1565
  30. package/dist/index.node.cjs.js.map +1 -1
  31. package/dist/index.node.mjs +1711 -1565
  32. package/dist/index.node.mjs.map +1 -1
  33. package/dist/index.rn.js +4100 -3984
  34. package/dist/index.rn.js.map +1 -1
  35. package/dist/internal.d.ts +50 -4
  36. package/dist/lite/firestore/lite/index.d.ts +1 -0
  37. package/dist/lite/firestore/src/api/transaction.d.ts +2 -1
  38. package/dist/lite/firestore/src/api/transaction_options.d.ts +17 -0
  39. package/dist/lite/firestore/src/api.d.ts +1 -0
  40. package/dist/lite/firestore/src/core/firestore_client.d.ts +2 -1
  41. package/dist/lite/firestore/src/core/query.d.ts +2 -4
  42. package/dist/lite/firestore/src/core/target.d.ts +6 -4
  43. package/dist/lite/firestore/src/core/transaction_options.d.ts +25 -0
  44. package/dist/lite/firestore/src/core/transaction_runner.d.ts +3 -2
  45. package/dist/lite/firestore/src/lite-api/transaction.d.ts +2 -1
  46. package/dist/lite/firestore/src/lite-api/transaction_options.d.ts +23 -0
  47. package/dist/lite/firestore/src/local/index_manager.d.ts +24 -3
  48. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  49. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +1 -0
  50. package/dist/lite/firestore/src/local/local_documents_view.d.ts +1 -1
  51. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +3 -2
  52. package/dist/lite/firestore/src/local/query_engine.d.ts +44 -5
  53. package/dist/lite/firestore/src/model/collections.d.ts +1 -1
  54. package/dist/lite/firestore/src/model/values.d.ts +14 -2
  55. package/dist/lite/firestore/src/util/misc.d.ts +3 -0
  56. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  57. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  58. package/dist/lite/index.browser.esm2017.js +341 -312
  59. package/dist/lite/index.browser.esm2017.js.map +1 -1
  60. package/dist/lite/index.browser.esm5.js +299 -291
  61. package/dist/lite/index.browser.esm5.js.map +1 -1
  62. package/dist/lite/index.d.ts +24 -1
  63. package/dist/lite/index.node.cjs.js +56 -15
  64. package/dist/lite/index.node.cjs.js.map +1 -1
  65. package/dist/lite/index.node.mjs +56 -15
  66. package/dist/lite/index.node.mjs.map +1 -1
  67. package/dist/lite/index.rn.esm2017.js +1227 -1198
  68. package/dist/lite/index.rn.esm2017.js.map +1 -1
  69. package/dist/lite/internal.d.ts +25 -1
  70. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +28 -28
  71. package/dist/lite/packages/firestore/lite/index.d.ts +1 -0
  72. package/dist/lite/packages/firestore/src/api/transaction.d.ts +2 -1
  73. package/dist/lite/packages/firestore/src/api/transaction_options.d.ts +17 -0
  74. package/dist/lite/packages/firestore/src/api.d.ts +1 -0
  75. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +2 -1
  76. package/dist/lite/packages/firestore/src/core/query.d.ts +2 -4
  77. package/dist/lite/packages/firestore/src/core/target.d.ts +6 -4
  78. package/dist/lite/packages/firestore/src/core/transaction_options.d.ts +25 -0
  79. package/dist/lite/packages/firestore/src/core/transaction_runner.d.ts +3 -2
  80. package/dist/lite/packages/firestore/src/lite-api/transaction.d.ts +2 -1
  81. package/dist/lite/packages/firestore/src/lite-api/transaction_options.d.ts +23 -0
  82. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +24 -3
  83. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  84. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +1 -0
  85. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +1 -1
  86. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +3 -2
  87. package/dist/lite/packages/firestore/src/local/query_engine.d.ts +44 -5
  88. package/dist/lite/packages/firestore/src/model/collections.d.ts +1 -1
  89. package/dist/lite/packages/firestore/src/model/values.d.ts +14 -2
  90. package/dist/lite/packages/firestore/src/util/misc.d.ts +3 -0
  91. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  92. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  93. package/dist/lite/private.d.ts +25 -1
  94. package/dist/packages/firestore/dist/index.esm2017.d.ts +155 -154
  95. package/dist/packages/firestore/lite/index.d.ts +1 -0
  96. package/dist/packages/firestore/src/api/transaction.d.ts +2 -1
  97. package/dist/packages/firestore/src/api/transaction_options.d.ts +17 -0
  98. package/dist/packages/firestore/src/api.d.ts +1 -0
  99. package/dist/packages/firestore/src/core/firestore_client.d.ts +2 -1
  100. package/dist/packages/firestore/src/core/query.d.ts +2 -4
  101. package/dist/packages/firestore/src/core/target.d.ts +6 -4
  102. package/dist/packages/firestore/src/core/transaction_options.d.ts +25 -0
  103. package/dist/packages/firestore/src/core/transaction_runner.d.ts +3 -2
  104. package/dist/packages/firestore/src/lite-api/transaction.d.ts +2 -1
  105. package/dist/packages/firestore/src/lite-api/transaction_options.d.ts +23 -0
  106. package/dist/packages/firestore/src/local/index_manager.d.ts +24 -3
  107. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +4 -7
  108. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +1 -0
  109. package/dist/packages/firestore/src/local/local_documents_view.d.ts +1 -1
  110. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +3 -2
  111. package/dist/packages/firestore/src/local/query_engine.d.ts +44 -5
  112. package/dist/packages/firestore/src/model/collections.d.ts +1 -1
  113. package/dist/packages/firestore/src/model/values.d.ts +14 -2
  114. package/dist/packages/firestore/src/util/misc.d.ts +3 -0
  115. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +2 -1
  116. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +2 -2
  117. package/dist/private.d.ts +50 -4
  118. package/package.json +7 -7
@@ -928,7 +928,7 @@ export declare function refEqual<T>(left: DocumentReference<T> | CollectionRefer
928
928
  * `updateFunction `is returned here. Otherwise, if the transaction failed, a
929
929
  * rejected promise with the corresponding failure error is returned.
930
930
  */
931
- export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>): Promise<T>;
931
+ export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
932
932
  /**
933
933
  * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
934
934
  * include a server-generated timestamp in the written data.
@@ -1283,6 +1283,29 @@ export declare class Transaction {
1283
1283
  */
1284
1284
  delete(documentRef: DocumentReference<unknown>): this;
1285
1285
  }
1286
+ /**
1287
+ * @license
1288
+ * Copyright 2022 Google LLC
1289
+ *
1290
+ * Licensed under the Apache License, Version 2.0 (the "License");
1291
+ * you may not use this file except in compliance with the License.
1292
+ * You may obtain a copy of the License at
1293
+ *
1294
+ * http://www.apache.org/licenses/LICENSE-2.0
1295
+ *
1296
+ * Unless required by applicable law or agreed to in writing, software
1297
+ * distributed under the License is distributed on an "AS IS" BASIS,
1298
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1299
+ * See the License for the specific language governing permissions and
1300
+ * limitations under the License.
1301
+ */
1302
+ /**
1303
+ * Options to customize transaction behavior.
1304
+ */
1305
+ export declare interface TransactionOptions {
1306
+ /** Maximum number of attempts to commit, after which transaction fails. Default is 5. */
1307
+ readonly maxAttempts?: number;
1308
+ }
1286
1309
  /**
1287
1310
  * Given a union type `U = T1 | T2 | ...`, returns an intersected type
1288
1311
  * `(T1 & T2 & ...)`.
@@ -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";
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.0";
71
71
 
72
72
  /**
73
73
  * @license
@@ -2194,6 +2194,13 @@ function isSafeInteger(value) {
2194
2194
  * limitations under the License.
2195
2195
  */
2196
2196
  const MAX_VALUE_TYPE = '__max__';
2197
+ const MAX_VALUE = {
2198
+ mapValue: {
2199
+ fields: {
2200
+ '__type__': { stringValue: MAX_VALUE_TYPE }
2201
+ }
2202
+ }
2203
+ };
2197
2204
  /** Extracts the backend's type order for the provided value. */
2198
2205
  function typeOrder(value) {
2199
2206
  if ('nullValue' in value) {
@@ -2228,7 +2235,7 @@ function typeOrder(value) {
2228
2235
  return 4 /* ServerTimestampValue */;
2229
2236
  }
2230
2237
  else if (isMaxValue(value)) {
2231
- return 9 /* ArrayValue */;
2238
+ return 9007199254740991 /* MaxValue */;
2232
2239
  }
2233
2240
  return 10 /* ObjectValue */;
2234
2241
  }
@@ -2440,6 +2447,15 @@ function compareArrays(left, right) {
2440
2447
  return primitiveComparator(leftArray.length, rightArray.length);
2441
2448
  }
2442
2449
  function compareMaps(left, right) {
2450
+ if (left === MAX_VALUE.mapValue && right === MAX_VALUE.mapValue) {
2451
+ return 0;
2452
+ }
2453
+ else if (left === MAX_VALUE.mapValue) {
2454
+ return 1;
2455
+ }
2456
+ else if (right === MAX_VALUE.mapValue) {
2457
+ return -1;
2458
+ }
2443
2459
  const leftMap = left.fields || {};
2444
2460
  const leftKeys = Object.keys(leftMap);
2445
2461
  const rightMap = right.fields || {};
@@ -3140,9 +3156,6 @@ class QueryImpl {
3140
3156
  function newQueryForPath(path) {
3141
3157
  return new QueryImpl(path);
3142
3158
  }
3143
- function hasLimitToLast(query) {
3144
- return !isNullOrUndefined(query.limit) && query.limitType === "L" /* Last */;
3145
- }
3146
3159
  function getFirstOrderByField(query) {
3147
3160
  return query.explicitOrderBy.length > 0
3148
3161
  ? query.explicitOrderBy[0].field
@@ -3243,10 +3256,10 @@ function queryToTarget(query) {
3243
3256
  }
3244
3257
  // We need to swap the cursors to match the now-flipped query ordering.
3245
3258
  const startAt = queryImpl.endAt
3246
- ? new Bound(queryImpl.endAt.position, !queryImpl.endAt.inclusive)
3259
+ ? new Bound(queryImpl.endAt.position, queryImpl.endAt.inclusive)
3247
3260
  : null;
3248
3261
  const endAt = queryImpl.startAt
3249
- ? new Bound(queryImpl.startAt.position, !queryImpl.startAt.inclusive)
3262
+ ? new Bound(queryImpl.startAt.position, queryImpl.startAt.inclusive)
3250
3263
  : null;
3251
3264
  // Now return as a LimitType.First query.
3252
3265
  queryImpl.memoizedTarget = newTarget(queryImpl.path, queryImpl.collectionGroup, orderBys, queryImpl.filters, queryImpl.limit, startAt, endAt);
@@ -6064,7 +6077,8 @@ function fieldPathFromArgument(methodName, arg) {
6064
6077
  * limitations under the License.
6065
6078
  */
6066
6079
  function validateHasExplicitOrderByForLimitToLast(query) {
6067
- if (hasLimitToLast(query) && query.explicitOrderBy.length === 0) {
6080
+ if (query.limitType === "L" /* Last */ &&
6081
+ query.explicitOrderBy.length === 0) {
6068
6082
  throw new FirestoreError(Code.UNIMPLEMENTED, 'limitToLast() queries require specifying at least one orderBy() clause');
6069
6083
  }
6070
6084
  }
@@ -6704,7 +6718,7 @@ function getDocs(query) {
6704
6718
  const userDataWriter = new LiteUserDataWriter(query.firestore);
6705
6719
  return invokeRunQueryRpc(datastore, query._query).then(result => {
6706
6720
  const docs = result.map(doc => new QueryDocumentSnapshot(query.firestore, userDataWriter, doc.key, doc, query.converter));
6707
- if (hasLimitToLast(query._query)) {
6721
+ if (query._query.limitType === "L" /* Last */) {
6708
6722
  // Limit to last queries reverse the orderBy constraint that was
6709
6723
  // specified by the user. As such, we need to reverse the order of the
6710
6724
  // results to return the documents in the expected order.
@@ -6999,6 +7013,31 @@ function writeBatch(firestore) {
6999
7013
  return new WriteBatch(firestore, writes => invokeCommitRpc(datastore, writes));
7000
7014
  }
7001
7015
 
7016
+ /**
7017
+ * @license
7018
+ * Copyright 2022 Google LLC
7019
+ *
7020
+ * Licensed under the Apache License, Version 2.0 (the "License");
7021
+ * you may not use this file except in compliance with the License.
7022
+ * You may obtain a copy of the License at
7023
+ *
7024
+ * http://www.apache.org/licenses/LICENSE-2.0
7025
+ *
7026
+ * Unless required by applicable law or agreed to in writing, software
7027
+ * distributed under the License is distributed on an "AS IS" BASIS,
7028
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7029
+ * See the License for the specific language governing permissions and
7030
+ * limitations under the License.
7031
+ */
7032
+ const DEFAULT_TRANSACTION_OPTIONS = {
7033
+ maxAttempts: 5
7034
+ };
7035
+ function validateTransactionOptions(options) {
7036
+ if (options.maxAttempts < 1) {
7037
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'Max attempts must be at least 1');
7038
+ }
7039
+ }
7040
+
7002
7041
  /**
7003
7042
  * @license
7004
7043
  * Copyright 2017 Google LLC
@@ -7173,18 +7212,18 @@ class Transaction$1 {
7173
7212
  * See the License for the specific language governing permissions and
7174
7213
  * limitations under the License.
7175
7214
  */
7176
- const DEFAULT_MAX_ATTEMPTS_COUNT = 5;
7177
7215
  /**
7178
7216
  * TransactionRunner encapsulates the logic needed to run and retry transactions
7179
7217
  * with backoff.
7180
7218
  */
7181
7219
  class TransactionRunner {
7182
- constructor(asyncQueue, datastore, updateFunction, deferred) {
7220
+ constructor(asyncQueue, datastore, options, updateFunction, deferred) {
7183
7221
  this.asyncQueue = asyncQueue;
7184
7222
  this.datastore = datastore;
7223
+ this.options = options;
7185
7224
  this.updateFunction = updateFunction;
7186
7225
  this.deferred = deferred;
7187
- this.attemptsRemaining = DEFAULT_MAX_ATTEMPTS_COUNT;
7226
+ this.attemptsRemaining = options.maxAttempts;
7188
7227
  this.backoff = new ExponentialBackoff(this.asyncQueue, "transaction_retry" /* TransactionRetry */);
7189
7228
  }
7190
7229
  /** Runs the transaction and sets the result on deferred. */
@@ -7728,11 +7767,13 @@ class Transaction {
7728
7767
  * `updateFunction `is returned here. Otherwise, if the transaction failed, a
7729
7768
  * rejected promise with the corresponding failure error is returned.
7730
7769
  */
7731
- function runTransaction(firestore, updateFunction) {
7770
+ function runTransaction(firestore, updateFunction, options) {
7732
7771
  firestore = cast(firestore, Firestore);
7733
7772
  const datastore = getDatastore(firestore);
7773
+ const optionsWithDefaults = Object.assign(Object.assign({}, DEFAULT_TRANSACTION_OPTIONS), options);
7774
+ validateTransactionOptions(optionsWithDefaults);
7734
7775
  const deferred = new Deferred();
7735
- new TransactionRunner(newAsyncQueue(), datastore, internalTransaction => updateFunction(new Transaction(firestore, internalTransaction)), deferred).run();
7776
+ new TransactionRunner(newAsyncQueue(), datastore, optionsWithDefaults, internalTransaction => updateFunction(new Transaction(firestore, internalTransaction)), deferred).run();
7736
7777
  return deferred.promise;
7737
7778
  }
7738
7779