@firebase/firestore 4.7.9-canary.a24a76aa2 → 4.7.9-canary.cf3c8fb2a

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.
@@ -9,7 +9,7 @@ import * as grpc from '@grpc/grpc-js';
9
9
  import * as protoLoader from '@grpc/proto-loader';
10
10
 
11
11
  const name = "@firebase/firestore";
12
- const version$1 = "4.7.9-canary.a24a76aa2";
12
+ const version$1 = "4.7.9-canary.cf3c8fb2a";
13
13
 
14
14
  /**
15
15
  * @license
@@ -62,7 +62,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
62
62
  User.FIRST_PARTY = new User('first-party-uid');
63
63
  User.MOCK_USER = new User('mock-user');
64
64
 
65
- const version = "11.4.0-canary.a24a76aa2";
65
+ const version = "11.4.0-canary.cf3c8fb2a";
66
66
 
67
67
  /**
68
68
  * @license
@@ -820,6 +820,35 @@ function randomBytes(nBytes) {
820
820
  return randomBytes$1(nBytes);
821
821
  }
822
822
 
823
+ /**
824
+ * @license
825
+ * Copyright 2023 Google LLC
826
+ *
827
+ * Licensed under the Apache License, Version 2.0 (the "License");
828
+ * you may not use this file except in compliance with the License.
829
+ * You may obtain a copy of the License at
830
+ *
831
+ * http://www.apache.org/licenses/LICENSE-2.0
832
+ *
833
+ * Unless required by applicable law or agreed to in writing, software
834
+ * distributed under the License is distributed on an "AS IS" BASIS,
835
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
836
+ * See the License for the specific language governing permissions and
837
+ * limitations under the License.
838
+ */
839
+ /**
840
+ * An instance of the Platform's 'TextEncoder' implementation.
841
+ */
842
+ function newTextEncoder() {
843
+ return new TextEncoder();
844
+ }
845
+ /**
846
+ * An instance of the Platform's 'TextDecoder' implementation.
847
+ */
848
+ function newTextDecoder() {
849
+ return new TextDecoder('utf-8');
850
+ }
851
+
823
852
  /**
824
853
  * @license
825
854
  * Copyright 2017 Google LLC
@@ -872,6 +901,63 @@ function primitiveComparator(left, right) {
872
901
  }
873
902
  return 0;
874
903
  }
904
+ /** Compare strings in UTF-8 encoded byte order */
905
+ function compareUtf8Strings(left, right) {
906
+ let i = 0;
907
+ while (i < left.length && i < right.length) {
908
+ const leftCodePoint = left.codePointAt(i);
909
+ const rightCodePoint = right.codePointAt(i);
910
+ if (leftCodePoint !== rightCodePoint) {
911
+ if (leftCodePoint < 128 && rightCodePoint < 128) {
912
+ // ASCII comparison
913
+ return primitiveComparator(leftCodePoint, rightCodePoint);
914
+ }
915
+ else {
916
+ // Lazy instantiate TextEncoder
917
+ const encoder = newTextEncoder();
918
+ // UTF-8 encode the character at index i for byte comparison.
919
+ const leftBytes = encoder.encode(getUtf8SafeSubstring(left, i));
920
+ const rightBytes = encoder.encode(getUtf8SafeSubstring(right, i));
921
+ const comp = compareByteArrays$1(leftBytes, rightBytes);
922
+ if (comp !== 0) {
923
+ return comp;
924
+ }
925
+ else {
926
+ // EXTREMELY RARE CASE: Code points differ, but their UTF-8 byte
927
+ // representations are identical. This can happen with malformed input
928
+ // (invalid surrogate pairs). The backend also actively prevents invalid
929
+ // surrogates as INVALID_ARGUMENT errors, so we almost never receive
930
+ // invalid strings from backend.
931
+ // Fallback to code point comparison for graceful handling.
932
+ return primitiveComparator(leftCodePoint, rightCodePoint);
933
+ }
934
+ }
935
+ }
936
+ // Increment by 2 for surrogate pairs, 1 otherwise
937
+ i += leftCodePoint > 0xffff ? 2 : 1;
938
+ }
939
+ // Compare lengths if all characters are equal
940
+ return primitiveComparator(left.length, right.length);
941
+ }
942
+ function getUtf8SafeSubstring(str, index) {
943
+ const firstCodePoint = str.codePointAt(index);
944
+ if (firstCodePoint > 0xffff) {
945
+ // It's a surrogate pair, return the whole pair
946
+ return str.substring(index, index + 2);
947
+ }
948
+ else {
949
+ // It's a single code point, return it
950
+ return str.substring(index, index + 1);
951
+ }
952
+ }
953
+ function compareByteArrays$1(left, right) {
954
+ for (let i = 0; i < left.length && i < right.length; ++i) {
955
+ if (left[i] !== right[i]) {
956
+ return primitiveComparator(left[i], right[i]);
957
+ }
958
+ }
959
+ return primitiveComparator(left.length, right.length);
960
+ }
875
961
  /** Helper to compare arrays using isEqual(). */
876
962
  function arrayEquals(left, right, comparator) {
877
963
  if (left.length !== right.length) {
@@ -1233,7 +1319,7 @@ class BasePath {
1233
1319
  return comparison;
1234
1320
  }
1235
1321
  }
1236
- return Math.sign(p1.length - p2.length);
1322
+ return primitiveComparator(p1.length, p2.length);
1237
1323
  }
1238
1324
  static compareSegments(lhs, rhs) {
1239
1325
  const isLhsNumeric = BasePath.isNumericId(lhs);
@@ -1252,13 +1338,7 @@ class BasePath {
1252
1338
  }
1253
1339
  else {
1254
1340
  // both non-numeric
1255
- if (lhs < rhs) {
1256
- return -1;
1257
- }
1258
- if (lhs > rhs) {
1259
- return 1;
1260
- }
1261
- return 0;
1341
+ return compareUtf8Strings(lhs, rhs);
1262
1342
  }
1263
1343
  }
1264
1344
  // Checks if a segment is a numeric ID (starts with "__id" and ends with "__").
@@ -4675,7 +4755,7 @@ function valueCompare(left, right) {
4675
4755
  case 4 /* TypeOrder.ServerTimestampValue */:
4676
4756
  return compareTimestamps(getLocalWriteTime(left), getLocalWriteTime(right));
4677
4757
  case 5 /* TypeOrder.StringValue */:
4678
- return primitiveComparator(left.stringValue, right.stringValue);
4758
+ return compareUtf8Strings(left.stringValue, right.stringValue);
4679
4759
  case 6 /* TypeOrder.BlobValue */:
4680
4760
  return compareBlobs(left.bytesValue, right.bytesValue);
4681
4761
  case 7 /* TypeOrder.RefValue */:
@@ -4796,7 +4876,7 @@ function compareMaps(left, right) {
4796
4876
  leftKeys.sort();
4797
4877
  rightKeys.sort();
4798
4878
  for (let i = 0; i < leftKeys.length && i < rightKeys.length; ++i) {
4799
- const keyCompare = primitiveComparator(leftKeys[i], rightKeys[i]);
4879
+ const keyCompare = compareUtf8Strings(leftKeys[i], rightKeys[i]);
4800
4880
  if (keyCompare !== 0) {
4801
4881
  return keyCompare;
4802
4882
  }
@@ -7977,35 +8057,6 @@ function setTestingHooksSpi(instance) {
7977
8057
  testingHooksSpi = instance;
7978
8058
  }
7979
8059
 
7980
- /**
7981
- * @license
7982
- * Copyright 2023 Google LLC
7983
- *
7984
- * Licensed under the Apache License, Version 2.0 (the "License");
7985
- * you may not use this file except in compliance with the License.
7986
- * You may obtain a copy of the License at
7987
- *
7988
- * http://www.apache.org/licenses/LICENSE-2.0
7989
- *
7990
- * Unless required by applicable law or agreed to in writing, software
7991
- * distributed under the License is distributed on an "AS IS" BASIS,
7992
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7993
- * See the License for the specific language governing permissions and
7994
- * limitations under the License.
7995
- */
7996
- /**
7997
- * An instance of the Platform's 'TextEncoder' implementation.
7998
- */
7999
- function newTextEncoder() {
8000
- return new TextEncoder();
8001
- }
8002
- /**
8003
- * An instance of the Platform's 'TextDecoder' implementation.
8004
- */
8005
- function newTextDecoder() {
8006
- return new TextDecoder('utf-8');
8007
- }
8008
-
8009
8060
  /**
8010
8061
  * @license
8011
8062
  * Copyright 2022 Google LLC
@@ -14054,6 +14105,10 @@ function dbKeyComparator(l, r) {
14054
14105
  if (cmp) {
14055
14106
  return cmp;
14056
14107
  }
14108
+ // TODO(b/329441702): Document IDs should be sorted by UTF-8 encoded byte
14109
+ // order, but IndexedDB sorts strings lexicographically. Document ID
14110
+ // comparison here still relies on primitive comparison to avoid mismatches
14111
+ // observed in snapshot listeners with Unicode characters in documentIds
14057
14112
  return primitiveComparator(left[left.length - 1], right[right.length - 1]);
14058
14113
  }
14059
14114