@firebase/firestore 4.7.14 → 4.7.15

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.
@@ -34,7 +34,7 @@ var grpc__namespace = /*#__PURE__*/_interopNamespace(grpc);
34
34
  var protoLoader__namespace = /*#__PURE__*/_interopNamespace(protoLoader);
35
35
 
36
36
  const name = "@firebase/firestore";
37
- const version$1 = "4.7.14";
37
+ const version$1 = "4.7.15";
38
38
 
39
39
  /**
40
40
  * @license
@@ -87,7 +87,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
87
87
  User.FIRST_PARTY = new User('first-party-uid');
88
88
  User.MOCK_USER = new User('mock-user');
89
89
 
90
- const version = "11.7.3";
90
+ const version = "11.8.0";
91
91
 
92
92
  /**
93
93
  * @license
@@ -3345,9 +3345,13 @@ const V15_STORES = [
3345
3345
  ];
3346
3346
  const V16_STORES = V15_STORES;
3347
3347
  const V17_STORES = [...V15_STORES, DbGlobalsStore];
3348
+ const V18_STORES = V17_STORES;
3348
3349
  /** Returns the object stores for the provided schema. */
3349
3350
  function getObjectStores(schemaVersion) {
3350
- if (schemaVersion === 17) {
3351
+ if (schemaVersion === 18) {
3352
+ return V18_STORES;
3353
+ }
3354
+ else if (schemaVersion === 17) {
3351
3355
  return V17_STORES;
3352
3356
  }
3353
3357
  else if (schemaVersion === 16) {
@@ -11208,46 +11212,69 @@ class IndexByteEncoder {
11208
11212
  */
11209
11213
  /** Represents an index entry saved by the SDK in persisted storage. */
11210
11214
  class IndexEntry {
11211
- constructor(indexId, documentKey, arrayValue, directionalValue) {
11212
- this.indexId = indexId;
11213
- this.documentKey = documentKey;
11214
- this.arrayValue = arrayValue;
11215
- this.directionalValue = directionalValue;
11215
+ constructor(_indexId, _documentKey, _arrayValue, _directionalValue) {
11216
+ this._indexId = _indexId;
11217
+ this._documentKey = _documentKey;
11218
+ this._arrayValue = _arrayValue;
11219
+ this._directionalValue = _directionalValue;
11216
11220
  }
11217
11221
  /**
11218
11222
  * Returns an IndexEntry entry that sorts immediately after the current
11219
11223
  * directional value.
11220
11224
  */
11221
11225
  successor() {
11222
- const currentLength = this.directionalValue.length;
11223
- const newLength = currentLength === 0 || this.directionalValue[currentLength - 1] === 255
11226
+ const currentLength = this._directionalValue.length;
11227
+ const newLength = currentLength === 0 || this._directionalValue[currentLength - 1] === 255
11224
11228
  ? currentLength + 1
11225
11229
  : currentLength;
11226
11230
  const successor = new Uint8Array(newLength);
11227
- successor.set(this.directionalValue, 0);
11231
+ successor.set(this._directionalValue, 0);
11228
11232
  if (newLength !== currentLength) {
11229
- successor.set([0], this.directionalValue.length);
11233
+ successor.set([0], this._directionalValue.length);
11230
11234
  }
11231
11235
  else {
11232
11236
  ++successor[successor.length - 1];
11233
11237
  }
11234
- return new IndexEntry(this.indexId, this.documentKey, this.arrayValue, successor);
11238
+ return new IndexEntry(this._indexId, this._documentKey, this._arrayValue, successor);
11239
+ }
11240
+ // Create a representation of the Index Entry as a DbIndexEntry
11241
+ dbIndexEntry(uid, orderedDocumentKey, documentKey) {
11242
+ return {
11243
+ indexId: this._indexId,
11244
+ uid,
11245
+ arrayValue: encodeKeySafeBytes(this._arrayValue),
11246
+ directionalValue: encodeKeySafeBytes(this._directionalValue),
11247
+ orderedDocumentKey: encodeKeySafeBytes(orderedDocumentKey),
11248
+ documentKey: documentKey.path.toArray()
11249
+ };
11250
+ }
11251
+ // Create a representation of the Index Entry as a DbIndexEntryKey
11252
+ dbIndexEntryKey(uid, orderedDocumentKey, documentKey) {
11253
+ const entry = this.dbIndexEntry(uid, orderedDocumentKey, documentKey);
11254
+ return [
11255
+ entry.indexId,
11256
+ entry.uid,
11257
+ entry.arrayValue,
11258
+ entry.directionalValue,
11259
+ entry.orderedDocumentKey,
11260
+ entry.documentKey
11261
+ ];
11235
11262
  }
11236
11263
  }
11237
11264
  function indexEntryComparator(left, right) {
11238
- let cmp = left.indexId - right.indexId;
11265
+ let cmp = left._indexId - right._indexId;
11239
11266
  if (cmp !== 0) {
11240
11267
  return cmp;
11241
11268
  }
11242
- cmp = compareByteArrays(left.arrayValue, right.arrayValue);
11269
+ cmp = compareByteArrays(left._arrayValue, right._arrayValue);
11243
11270
  if (cmp !== 0) {
11244
11271
  return cmp;
11245
11272
  }
11246
- cmp = compareByteArrays(left.directionalValue, right.directionalValue);
11273
+ cmp = compareByteArrays(left._directionalValue, right._directionalValue);
11247
11274
  if (cmp !== 0) {
11248
11275
  return cmp;
11249
11276
  }
11250
- return DocumentKey.comparator(left.documentKey, right.documentKey);
11277
+ return DocumentKey.comparator(left._documentKey, right._documentKey);
11251
11278
  }
11252
11279
  function compareByteArrays(left, right) {
11253
11280
  for (let i = 0; i < left.length && i < right.length; ++i) {
@@ -11258,6 +11285,53 @@ function compareByteArrays(left, right) {
11258
11285
  }
11259
11286
  return left.length - right.length;
11260
11287
  }
11288
+ /**
11289
+ * Workaround for WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=292721
11290
+ * Create a key safe representation of Uint8Array values.
11291
+ * If the browser is detected as Safari or WebKit, then
11292
+ * the input array will be converted to "sortable byte string".
11293
+ * Otherwise, the input array will be returned in its original type.
11294
+ */
11295
+ function encodeKeySafeBytes(array) {
11296
+ if (util.isSafariOrWebkit()) {
11297
+ return encodeUint8ArrayToSortableString(array);
11298
+ }
11299
+ return array;
11300
+ }
11301
+ /**
11302
+ * Reverts the key safe representation of Uint8Array (created by
11303
+ * encodeKeySafeBytes) to a normal Uint8Array.
11304
+ */
11305
+ function decodeKeySafeBytes(input) {
11306
+ if (typeof input !== 'string') {
11307
+ return input;
11308
+ }
11309
+ return decodeSortableStringToUint8Array(input);
11310
+ }
11311
+ /**
11312
+ * Encodes a Uint8Array into a "sortable byte string".
11313
+ * A "sortable byte string" sorts in the same order as the Uint8Array.
11314
+ * This works because JS string comparison sorts strings based on code points.
11315
+ */
11316
+ function encodeUint8ArrayToSortableString(array) {
11317
+ let byteString = '';
11318
+ for (let i = 0; i < array.length; i++) {
11319
+ byteString += String.fromCharCode(array[i]);
11320
+ }
11321
+ return byteString;
11322
+ }
11323
+ /**
11324
+ * Decodes a "sortable byte string" back into a Uint8Array.
11325
+ * A "sortable byte string" is assumed to be created where each character's
11326
+ * Unicode code point directly corresponds to a single byte value (0-255).
11327
+ */
11328
+ function decodeSortableStringToUint8Array(byteString) {
11329
+ const uint8array = new Uint8Array(byteString.length);
11330
+ for (let i = 0; i < byteString.length; i++) {
11331
+ uint8array[i] = byteString.charCodeAt(i);
11332
+ }
11333
+ return uint8array;
11334
+ }
11261
11335
 
11262
11336
  /**
11263
11337
  * @license
@@ -12280,25 +12354,11 @@ class IndexedDbIndexManager {
12280
12354
  }
12281
12355
  addIndexEntry(transaction, document, fieldIndex, indexEntry) {
12282
12356
  const indexEntries = indexEntriesStore(transaction);
12283
- return indexEntries.put({
12284
- indexId: indexEntry.indexId,
12285
- uid: this.uid,
12286
- arrayValue: indexEntry.arrayValue,
12287
- directionalValue: indexEntry.directionalValue,
12288
- orderedDocumentKey: this.encodeDirectionalKey(fieldIndex, document.key),
12289
- documentKey: document.key.path.toArray()
12290
- });
12357
+ return indexEntries.put(indexEntry.dbIndexEntry(this.uid, this.encodeDirectionalKey(fieldIndex, document.key), document.key));
12291
12358
  }
12292
12359
  deleteIndexEntry(transaction, document, fieldIndex, indexEntry) {
12293
12360
  const indexEntries = indexEntriesStore(transaction);
12294
- return indexEntries.delete([
12295
- indexEntry.indexId,
12296
- this.uid,
12297
- indexEntry.arrayValue,
12298
- indexEntry.directionalValue,
12299
- this.encodeDirectionalKey(fieldIndex, document.key),
12300
- document.key.path.toArray()
12301
- ]);
12361
+ return indexEntries.delete(indexEntry.dbIndexEntryKey(this.uid, this.encodeDirectionalKey(fieldIndex, document.key), document.key));
12302
12362
  }
12303
12363
  getExistingIndexEntries(transaction, documentKey, fieldIndex) {
12304
12364
  const indexEntries = indexEntriesStore(transaction);
@@ -12309,10 +12369,10 @@ class IndexedDbIndexManager {
12309
12369
  range: IDBKeyRange.only([
12310
12370
  fieldIndex.indexId,
12311
12371
  this.uid,
12312
- this.encodeDirectionalKey(fieldIndex, documentKey)
12372
+ encodeKeySafeBytes(this.encodeDirectionalKey(fieldIndex, documentKey))
12313
12373
  ])
12314
12374
  }, (_, entry) => {
12315
- results = results.add(new IndexEntry(fieldIndex.indexId, documentKey, entry.arrayValue, entry.directionalValue));
12375
+ results = results.add(new IndexEntry(fieldIndex.indexId, documentKey, decodeKeySafeBytes(entry.arrayValue), decodeKeySafeBytes(entry.directionalValue)));
12316
12376
  })
12317
12377
  .next(() => results);
12318
12378
  }
@@ -12407,22 +12467,8 @@ class IndexedDbIndexManager {
12407
12467
  if (this.isRangeMatchable(bounds[i], bounds[i + 1])) {
12408
12468
  return [];
12409
12469
  }
12410
- const lowerBound = [
12411
- bounds[i].indexId,
12412
- this.uid,
12413
- bounds[i].arrayValue,
12414
- bounds[i].directionalValue,
12415
- EMPTY_VALUE,
12416
- []
12417
- ];
12418
- const upperBound = [
12419
- bounds[i + 1].indexId,
12420
- this.uid,
12421
- bounds[i + 1].arrayValue,
12422
- bounds[i + 1].directionalValue,
12423
- EMPTY_VALUE,
12424
- []
12425
- ];
12470
+ const lowerBound = bounds[i].dbIndexEntryKey(this.uid, EMPTY_VALUE, DocumentKey.empty());
12471
+ const upperBound = bounds[i + 1].dbIndexEntryKey(this.uid, EMPTY_VALUE, DocumentKey.empty());
12426
12472
  ranges.push(IDBKeyRange.bound(lowerBound, upperBound));
12427
12473
  }
12428
12474
  return ranges;
@@ -14256,8 +14302,10 @@ function dbKeyComparator(l, r) {
14256
14302
  * 14. Add overlays.
14257
14303
  * 15. Add indexing support.
14258
14304
  * 16. Parse timestamp strings before creating index entries.
14305
+ * 17. TODO(tomandersen)
14306
+ * 18. Encode key safe representations of IndexEntry in DbIndexEntryStore.
14259
14307
  */
14260
- const SCHEMA_VERSION = 17;
14308
+ const SCHEMA_VERSION = 18;
14261
14309
 
14262
14310
  /**
14263
14311
  * @license
@@ -15913,6 +15961,21 @@ class SchemaConverter {
15913
15961
  createGlobalsStore(db);
15914
15962
  });
15915
15963
  }
15964
+ if (fromVersion < 18 && toVersion >= 18) {
15965
+ // Clear the IndexEntryStores on WebKit and Safari to remove possibly
15966
+ // corrupted index entries
15967
+ if (util.isSafariOrWebkit()) {
15968
+ p = p
15969
+ .next(() => {
15970
+ const indexStateStore = txn.objectStore(DbIndexStateStore);
15971
+ indexStateStore.clear();
15972
+ })
15973
+ .next(() => {
15974
+ const indexEntryStore = txn.objectStore(DbIndexEntryStore);
15975
+ indexEntryStore.clear();
15976
+ });
15977
+ }
15978
+ }
15916
15979
  return p;
15917
15980
  }
15918
15981
  addDocumentGlobal(txn) {