@firebase/firestore 4.7.9 → 4.7.10-20250318143520

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.9";
37
+ const version$1 = "4.7.10-20250318143520";
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.4.0";
90
+ const version = "11.5.0-20250318143520";
91
91
 
92
92
  /**
93
93
  * @license
@@ -845,6 +845,35 @@ function randomBytes(nBytes) {
845
845
  return crypto.randomBytes(nBytes);
846
846
  }
847
847
 
848
+ /**
849
+ * @license
850
+ * Copyright 2023 Google LLC
851
+ *
852
+ * Licensed under the Apache License, Version 2.0 (the "License");
853
+ * you may not use this file except in compliance with the License.
854
+ * You may obtain a copy of the License at
855
+ *
856
+ * http://www.apache.org/licenses/LICENSE-2.0
857
+ *
858
+ * Unless required by applicable law or agreed to in writing, software
859
+ * distributed under the License is distributed on an "AS IS" BASIS,
860
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
861
+ * See the License for the specific language governing permissions and
862
+ * limitations under the License.
863
+ */
864
+ /**
865
+ * An instance of the Platform's 'TextEncoder' implementation.
866
+ */
867
+ function newTextEncoder() {
868
+ return new util$1.TextEncoder();
869
+ }
870
+ /**
871
+ * An instance of the Platform's 'TextDecoder' implementation.
872
+ */
873
+ function newTextDecoder() {
874
+ return new util$1.TextDecoder('utf-8');
875
+ }
876
+
848
877
  /**
849
878
  * @license
850
879
  * Copyright 2017 Google LLC
@@ -897,6 +926,63 @@ function primitiveComparator(left, right) {
897
926
  }
898
927
  return 0;
899
928
  }
929
+ /** Compare strings in UTF-8 encoded byte order */
930
+ function compareUtf8Strings(left, right) {
931
+ let i = 0;
932
+ while (i < left.length && i < right.length) {
933
+ const leftCodePoint = left.codePointAt(i);
934
+ const rightCodePoint = right.codePointAt(i);
935
+ if (leftCodePoint !== rightCodePoint) {
936
+ if (leftCodePoint < 128 && rightCodePoint < 128) {
937
+ // ASCII comparison
938
+ return primitiveComparator(leftCodePoint, rightCodePoint);
939
+ }
940
+ else {
941
+ // Lazy instantiate TextEncoder
942
+ const encoder = newTextEncoder();
943
+ // UTF-8 encode the character at index i for byte comparison.
944
+ const leftBytes = encoder.encode(getUtf8SafeSubstring(left, i));
945
+ const rightBytes = encoder.encode(getUtf8SafeSubstring(right, i));
946
+ const comp = compareByteArrays$1(leftBytes, rightBytes);
947
+ if (comp !== 0) {
948
+ return comp;
949
+ }
950
+ else {
951
+ // EXTREMELY RARE CASE: Code points differ, but their UTF-8 byte
952
+ // representations are identical. This can happen with malformed input
953
+ // (invalid surrogate pairs). The backend also actively prevents invalid
954
+ // surrogates as INVALID_ARGUMENT errors, so we almost never receive
955
+ // invalid strings from backend.
956
+ // Fallback to code point comparison for graceful handling.
957
+ return primitiveComparator(leftCodePoint, rightCodePoint);
958
+ }
959
+ }
960
+ }
961
+ // Increment by 2 for surrogate pairs, 1 otherwise
962
+ i += leftCodePoint > 0xffff ? 2 : 1;
963
+ }
964
+ // Compare lengths if all characters are equal
965
+ return primitiveComparator(left.length, right.length);
966
+ }
967
+ function getUtf8SafeSubstring(str, index) {
968
+ const firstCodePoint = str.codePointAt(index);
969
+ if (firstCodePoint > 0xffff) {
970
+ // It's a surrogate pair, return the whole pair
971
+ return str.substring(index, index + 2);
972
+ }
973
+ else {
974
+ // It's a single code point, return it
975
+ return str.substring(index, index + 1);
976
+ }
977
+ }
978
+ function compareByteArrays$1(left, right) {
979
+ for (let i = 0; i < left.length && i < right.length; ++i) {
980
+ if (left[i] !== right[i]) {
981
+ return primitiveComparator(left[i], right[i]);
982
+ }
983
+ }
984
+ return primitiveComparator(left.length, right.length);
985
+ }
900
986
  /** Helper to compare arrays using isEqual(). */
901
987
  function arrayEquals(left, right, comparator) {
902
988
  if (left.length !== right.length) {
@@ -1258,7 +1344,7 @@ class BasePath {
1258
1344
  return comparison;
1259
1345
  }
1260
1346
  }
1261
- return Math.sign(p1.length - p2.length);
1347
+ return primitiveComparator(p1.length, p2.length);
1262
1348
  }
1263
1349
  static compareSegments(lhs, rhs) {
1264
1350
  const isLhsNumeric = BasePath.isNumericId(lhs);
@@ -1277,13 +1363,7 @@ class BasePath {
1277
1363
  }
1278
1364
  else {
1279
1365
  // both non-numeric
1280
- if (lhs < rhs) {
1281
- return -1;
1282
- }
1283
- if (lhs > rhs) {
1284
- return 1;
1285
- }
1286
- return 0;
1366
+ return compareUtf8Strings(lhs, rhs);
1287
1367
  }
1288
1368
  }
1289
1369
  // Checks if a segment is a numeric ID (starts with "__id" and ends with "__").
@@ -4700,7 +4780,7 @@ function valueCompare(left, right) {
4700
4780
  case 4 /* TypeOrder.ServerTimestampValue */:
4701
4781
  return compareTimestamps(getLocalWriteTime(left), getLocalWriteTime(right));
4702
4782
  case 5 /* TypeOrder.StringValue */:
4703
- return primitiveComparator(left.stringValue, right.stringValue);
4783
+ return compareUtf8Strings(left.stringValue, right.stringValue);
4704
4784
  case 6 /* TypeOrder.BlobValue */:
4705
4785
  return compareBlobs(left.bytesValue, right.bytesValue);
4706
4786
  case 7 /* TypeOrder.RefValue */:
@@ -4821,7 +4901,7 @@ function compareMaps(left, right) {
4821
4901
  leftKeys.sort();
4822
4902
  rightKeys.sort();
4823
4903
  for (let i = 0; i < leftKeys.length && i < rightKeys.length; ++i) {
4824
- const keyCompare = primitiveComparator(leftKeys[i], rightKeys[i]);
4904
+ const keyCompare = compareUtf8Strings(leftKeys[i], rightKeys[i]);
4825
4905
  if (keyCompare !== 0) {
4826
4906
  return keyCompare;
4827
4907
  }
@@ -8002,35 +8082,6 @@ function setTestingHooksSpi(instance) {
8002
8082
  testingHooksSpi = instance;
8003
8083
  }
8004
8084
 
8005
- /**
8006
- * @license
8007
- * Copyright 2023 Google LLC
8008
- *
8009
- * Licensed under the Apache License, Version 2.0 (the "License");
8010
- * you may not use this file except in compliance with the License.
8011
- * You may obtain a copy of the License at
8012
- *
8013
- * http://www.apache.org/licenses/LICENSE-2.0
8014
- *
8015
- * Unless required by applicable law or agreed to in writing, software
8016
- * distributed under the License is distributed on an "AS IS" BASIS,
8017
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8018
- * See the License for the specific language governing permissions and
8019
- * limitations under the License.
8020
- */
8021
- /**
8022
- * An instance of the Platform's 'TextEncoder' implementation.
8023
- */
8024
- function newTextEncoder() {
8025
- return new util$1.TextEncoder();
8026
- }
8027
- /**
8028
- * An instance of the Platform's 'TextDecoder' implementation.
8029
- */
8030
- function newTextDecoder() {
8031
- return new util$1.TextDecoder('utf-8');
8032
- }
8033
-
8034
8085
  /**
8035
8086
  * @license
8036
8087
  * Copyright 2022 Google LLC
@@ -14079,6 +14130,10 @@ function dbKeyComparator(l, r) {
14079
14130
  if (cmp) {
14080
14131
  return cmp;
14081
14132
  }
14133
+ // TODO(b/329441702): Document IDs should be sorted by UTF-8 encoded byte
14134
+ // order, but IndexedDB sorts strings lexicographically. Document ID
14135
+ // comparison here still relies on primitive comparison to avoid mismatches
14136
+ // observed in snapshot listeners with Unicode characters in documentIds
14082
14137
  return primitiveComparator(left[left.length - 1], right[right.length - 1]);
14083
14138
  }
14084
14139