@firebase/firestore 4.7.9 → 4.7.10-20250318131644

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.
@@ -6,7 +6,7 @@ import { FirebaseError, getDefaultEmulatorHostnameAndPort, deepEqual, createMock
6
6
  import { Integer } from '@firebase/webchannel-wrapper/bloom-blob';
7
7
  import { randomBytes as randomBytes$1 } from 'crypto';
8
8
 
9
- const version$1 = "4.7.9";
9
+ const version$1 = "4.7.10-20250318131644";
10
10
 
11
11
  /**
12
12
  * @license
@@ -59,7 +59,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
59
59
  User.FIRST_PARTY = new User('first-party-uid');
60
60
  User.MOCK_USER = new User('mock-user');
61
61
 
62
- const version = "11.4.0";
62
+ const version = "11.5.0-20250318131644";
63
63
 
64
64
  /**
65
65
  * @license
@@ -699,6 +699,171 @@ function databaseIdFromApp(app, database) {
699
699
  return new DatabaseId(app.options.projectId, database);
700
700
  }
701
701
 
702
+ /**
703
+ * @license
704
+ * Copyright 2020 Google LLC
705
+ *
706
+ * Licensed under the Apache License, Version 2.0 (the "License");
707
+ * you may not use this file except in compliance with the License.
708
+ * You may obtain a copy of the License at
709
+ *
710
+ * http://www.apache.org/licenses/LICENSE-2.0
711
+ *
712
+ * Unless required by applicable law or agreed to in writing, software
713
+ * distributed under the License is distributed on an "AS IS" BASIS,
714
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
715
+ * See the License for the specific language governing permissions and
716
+ * limitations under the License.
717
+ */
718
+ /**
719
+ * Generates `nBytes` of random bytes.
720
+ *
721
+ * If `nBytes < 0` , an error will be thrown.
722
+ */
723
+ function randomBytes(nBytes) {
724
+ return randomBytes$1(nBytes);
725
+ }
726
+
727
+ /**
728
+ * @license
729
+ * Copyright 2023 Google LLC
730
+ *
731
+ * Licensed under the Apache License, Version 2.0 (the "License");
732
+ * you may not use this file except in compliance with the License.
733
+ * You may obtain a copy of the License at
734
+ *
735
+ * http://www.apache.org/licenses/LICENSE-2.0
736
+ *
737
+ * Unless required by applicable law or agreed to in writing, software
738
+ * distributed under the License is distributed on an "AS IS" BASIS,
739
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
740
+ * See the License for the specific language governing permissions and
741
+ * limitations under the License.
742
+ */
743
+ /**
744
+ * An instance of the Platform's 'TextEncoder' implementation.
745
+ */
746
+ function newTextEncoder() {
747
+ return new TextEncoder();
748
+ }
749
+
750
+ /**
751
+ * @license
752
+ * Copyright 2017 Google LLC
753
+ *
754
+ * Licensed under the Apache License, Version 2.0 (the "License");
755
+ * you may not use this file except in compliance with the License.
756
+ * You may obtain a copy of the License at
757
+ *
758
+ * http://www.apache.org/licenses/LICENSE-2.0
759
+ *
760
+ * Unless required by applicable law or agreed to in writing, software
761
+ * distributed under the License is distributed on an "AS IS" BASIS,
762
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
763
+ * See the License for the specific language governing permissions and
764
+ * limitations under the License.
765
+ */
766
+ /**
767
+ * A utility class for generating unique alphanumeric IDs of a specified length.
768
+ *
769
+ * @internal
770
+ * Exported internally for testing purposes.
771
+ */
772
+ class AutoId {
773
+ static newId() {
774
+ // Alphanumeric characters
775
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
776
+ // The largest byte value that is a multiple of `char.length`.
777
+ const maxMultiple = Math.floor(256 / chars.length) * chars.length;
778
+ let autoId = '';
779
+ const targetLength = 20;
780
+ while (autoId.length < targetLength) {
781
+ const bytes = randomBytes(40);
782
+ for (let i = 0; i < bytes.length; ++i) {
783
+ // Only accept values that are [0, maxMultiple), this ensures they can
784
+ // be evenly mapped to indices of `chars` via a modulo operation.
785
+ if (autoId.length < targetLength && bytes[i] < maxMultiple) {
786
+ autoId += chars.charAt(bytes[i] % chars.length);
787
+ }
788
+ }
789
+ }
790
+ return autoId;
791
+ }
792
+ }
793
+ function primitiveComparator(left, right) {
794
+ if (left < right) {
795
+ return -1;
796
+ }
797
+ if (left > right) {
798
+ return 1;
799
+ }
800
+ return 0;
801
+ }
802
+ /** Compare strings in UTF-8 encoded byte order */
803
+ function compareUtf8Strings(left, right) {
804
+ let i = 0;
805
+ while (i < left.length && i < right.length) {
806
+ const leftCodePoint = left.codePointAt(i);
807
+ const rightCodePoint = right.codePointAt(i);
808
+ if (leftCodePoint !== rightCodePoint) {
809
+ if (leftCodePoint < 128 && rightCodePoint < 128) {
810
+ // ASCII comparison
811
+ return primitiveComparator(leftCodePoint, rightCodePoint);
812
+ }
813
+ else {
814
+ // Lazy instantiate TextEncoder
815
+ const encoder = newTextEncoder();
816
+ // UTF-8 encode the character at index i for byte comparison.
817
+ const leftBytes = encoder.encode(getUtf8SafeSubstring(left, i));
818
+ const rightBytes = encoder.encode(getUtf8SafeSubstring(right, i));
819
+ const comp = compareByteArrays(leftBytes, rightBytes);
820
+ if (comp !== 0) {
821
+ return comp;
822
+ }
823
+ else {
824
+ // EXTREMELY RARE CASE: Code points differ, but their UTF-8 byte
825
+ // representations are identical. This can happen with malformed input
826
+ // (invalid surrogate pairs). The backend also actively prevents invalid
827
+ // surrogates as INVALID_ARGUMENT errors, so we almost never receive
828
+ // invalid strings from backend.
829
+ // Fallback to code point comparison for graceful handling.
830
+ return primitiveComparator(leftCodePoint, rightCodePoint);
831
+ }
832
+ }
833
+ }
834
+ // Increment by 2 for surrogate pairs, 1 otherwise
835
+ i += leftCodePoint > 0xffff ? 2 : 1;
836
+ }
837
+ // Compare lengths if all characters are equal
838
+ return primitiveComparator(left.length, right.length);
839
+ }
840
+ function getUtf8SafeSubstring(str, index) {
841
+ const firstCodePoint = str.codePointAt(index);
842
+ if (firstCodePoint > 0xffff) {
843
+ // It's a surrogate pair, return the whole pair
844
+ return str.substring(index, index + 2);
845
+ }
846
+ else {
847
+ // It's a single code point, return it
848
+ return str.substring(index, index + 1);
849
+ }
850
+ }
851
+ function compareByteArrays(left, right) {
852
+ for (let i = 0; i < left.length && i < right.length; ++i) {
853
+ if (left[i] !== right[i]) {
854
+ return primitiveComparator(left[i], right[i]);
855
+ }
856
+ }
857
+ return primitiveComparator(left.length, right.length);
858
+ }
859
+ /** Helper to compare arrays using isEqual(). */
860
+ function arrayEquals(left, right, comparator) {
861
+ if (left.length !== right.length) {
862
+ return false;
863
+ }
864
+ return left.every((value, index) => comparator(value, right[index]));
865
+ }
866
+
702
867
  /**
703
868
  * @license
704
869
  * Copyright 2017 Google LLC
@@ -821,7 +986,7 @@ class BasePath {
821
986
  return comparison;
822
987
  }
823
988
  }
824
- return Math.sign(p1.length - p2.length);
989
+ return primitiveComparator(p1.length, p2.length);
825
990
  }
826
991
  static compareSegments(lhs, rhs) {
827
992
  const isLhsNumeric = BasePath.isNumericId(lhs);
@@ -840,13 +1005,7 @@ class BasePath {
840
1005
  }
841
1006
  else {
842
1007
  // both non-numeric
843
- if (lhs < rhs) {
844
- return -1;
845
- }
846
- if (lhs > rhs) {
847
- return 1;
848
- }
849
- return 0;
1008
+ return compareUtf8Strings(lhs, rhs);
850
1009
  }
851
1010
  }
852
1011
  // Checks if a segment is a numeric ID (starts with "__id" and ends with "__").
@@ -1646,91 +1805,6 @@ function newConnection(databaseInfo) {
1646
1805
  return new FetchConnection(databaseInfo);
1647
1806
  }
1648
1807
 
1649
- /**
1650
- * @license
1651
- * Copyright 2020 Google LLC
1652
- *
1653
- * Licensed under the Apache License, Version 2.0 (the "License");
1654
- * you may not use this file except in compliance with the License.
1655
- * You may obtain a copy of the License at
1656
- *
1657
- * http://www.apache.org/licenses/LICENSE-2.0
1658
- *
1659
- * Unless required by applicable law or agreed to in writing, software
1660
- * distributed under the License is distributed on an "AS IS" BASIS,
1661
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1662
- * See the License for the specific language governing permissions and
1663
- * limitations under the License.
1664
- */
1665
- /**
1666
- * Generates `nBytes` of random bytes.
1667
- *
1668
- * If `nBytes < 0` , an error will be thrown.
1669
- */
1670
- function randomBytes(nBytes) {
1671
- return randomBytes$1(nBytes);
1672
- }
1673
-
1674
- /**
1675
- * @license
1676
- * Copyright 2017 Google LLC
1677
- *
1678
- * Licensed under the Apache License, Version 2.0 (the "License");
1679
- * you may not use this file except in compliance with the License.
1680
- * You may obtain a copy of the License at
1681
- *
1682
- * http://www.apache.org/licenses/LICENSE-2.0
1683
- *
1684
- * Unless required by applicable law or agreed to in writing, software
1685
- * distributed under the License is distributed on an "AS IS" BASIS,
1686
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1687
- * See the License for the specific language governing permissions and
1688
- * limitations under the License.
1689
- */
1690
- /**
1691
- * A utility class for generating unique alphanumeric IDs of a specified length.
1692
- *
1693
- * @internal
1694
- * Exported internally for testing purposes.
1695
- */
1696
- class AutoId {
1697
- static newId() {
1698
- // Alphanumeric characters
1699
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1700
- // The largest byte value that is a multiple of `char.length`.
1701
- const maxMultiple = Math.floor(256 / chars.length) * chars.length;
1702
- let autoId = '';
1703
- const targetLength = 20;
1704
- while (autoId.length < targetLength) {
1705
- const bytes = randomBytes(40);
1706
- for (let i = 0; i < bytes.length; ++i) {
1707
- // Only accept values that are [0, maxMultiple), this ensures they can
1708
- // be evenly mapped to indices of `chars` via a modulo operation.
1709
- if (autoId.length < targetLength && bytes[i] < maxMultiple) {
1710
- autoId += chars.charAt(bytes[i] % chars.length);
1711
- }
1712
- }
1713
- }
1714
- return autoId;
1715
- }
1716
- }
1717
- function primitiveComparator(left, right) {
1718
- if (left < right) {
1719
- return -1;
1720
- }
1721
- if (left > right) {
1722
- return 1;
1723
- }
1724
- return 0;
1725
- }
1726
- /** Helper to compare arrays using isEqual(). */
1727
- function arrayEquals(left, right, comparator) {
1728
- if (left.length !== right.length) {
1729
- return false;
1730
- }
1731
- return left.every((value, index) => comparator(value, right[index]));
1732
- }
1733
-
1734
1808
  /**
1735
1809
  * @license
1736
1810
  * Copyright 2017 Google LLC
@@ -2444,7 +2518,7 @@ function valueCompare(left, right) {
2444
2518
  case 4 /* TypeOrder.ServerTimestampValue */:
2445
2519
  return compareTimestamps(getLocalWriteTime(left), getLocalWriteTime(right));
2446
2520
  case 5 /* TypeOrder.StringValue */:
2447
- return primitiveComparator(left.stringValue, right.stringValue);
2521
+ return compareUtf8Strings(left.stringValue, right.stringValue);
2448
2522
  case 6 /* TypeOrder.BlobValue */:
2449
2523
  return compareBlobs(left.bytesValue, right.bytesValue);
2450
2524
  case 7 /* TypeOrder.RefValue */:
@@ -2565,7 +2639,7 @@ function compareMaps(left, right) {
2565
2639
  leftKeys.sort();
2566
2640
  rightKeys.sort();
2567
2641
  for (let i = 0; i < leftKeys.length && i < rightKeys.length; ++i) {
2568
- const keyCompare = primitiveComparator(leftKeys[i], rightKeys[i]);
2642
+ const keyCompare = compareUtf8Strings(leftKeys[i], rightKeys[i]);
2569
2643
  if (keyCompare !== 0) {
2570
2644
  return keyCompare;
2571
2645
  }