@firebase/firestore 4.7.7-canary.3418ef807 → 4.7.7-canary.4d2fc6e82

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, createMockUserToken,
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.7-canary.3418ef807";
9
+ const version$1 = "4.7.7-canary.4d2fc6e82";
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.3.0-canary.3418ef807";
62
+ const version = "11.3.0-canary.4d2fc6e82";
63
63
 
64
64
  /**
65
65
  * @license
@@ -699,6 +699,127 @@ 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
+ // Convert the string to UTF-8 encoded bytes
805
+ const encodedLeft = newTextEncoder().encode(left);
806
+ const encodedRight = newTextEncoder().encode(right);
807
+ for (let i = 0; i < Math.min(encodedLeft.length, encodedRight.length); i++) {
808
+ const comparison = primitiveComparator(encodedLeft[i], encodedRight[i]);
809
+ if (comparison !== 0) {
810
+ return comparison;
811
+ }
812
+ }
813
+ return primitiveComparator(encodedLeft.length, encodedRight.length);
814
+ }
815
+ /** Helper to compare arrays using isEqual(). */
816
+ function arrayEquals(left, right, comparator) {
817
+ if (left.length !== right.length) {
818
+ return false;
819
+ }
820
+ return left.every((value, index) => comparator(value, right[index]));
821
+ }
822
+
702
823
  /**
703
824
  * @license
704
825
  * Copyright 2017 Google LLC
@@ -821,7 +942,7 @@ class BasePath {
821
942
  return comparison;
822
943
  }
823
944
  }
824
- return Math.sign(p1.length - p2.length);
945
+ return primitiveComparator(p1.length, p2.length);
825
946
  }
826
947
  static compareSegments(lhs, rhs) {
827
948
  const isLhsNumeric = BasePath.isNumericId(lhs);
@@ -840,13 +961,7 @@ class BasePath {
840
961
  }
841
962
  else {
842
963
  // both non-numeric
843
- if (lhs < rhs) {
844
- return -1;
845
- }
846
- if (lhs > rhs) {
847
- return 1;
848
- }
849
- return 0;
964
+ return compareUtf8Strings(lhs, rhs);
850
965
  }
851
966
  }
852
967
  // Checks if a segment is a numeric ID (starts with "__id" and ends with "__").
@@ -1646,91 +1761,6 @@ function newConnection(databaseInfo) {
1646
1761
  return new FetchConnection(databaseInfo);
1647
1762
  }
1648
1763
 
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
1764
  /**
1735
1765
  * @license
1736
1766
  * Copyright 2017 Google LLC
@@ -2444,7 +2474,7 @@ function valueCompare(left, right) {
2444
2474
  case 4 /* TypeOrder.ServerTimestampValue */:
2445
2475
  return compareTimestamps(getLocalWriteTime(left), getLocalWriteTime(right));
2446
2476
  case 5 /* TypeOrder.StringValue */:
2447
- return primitiveComparator(left.stringValue, right.stringValue);
2477
+ return compareUtf8Strings(left.stringValue, right.stringValue);
2448
2478
  case 6 /* TypeOrder.BlobValue */:
2449
2479
  return compareBlobs(left.bytesValue, right.bytesValue);
2450
2480
  case 7 /* TypeOrder.RefValue */:
@@ -2565,7 +2595,7 @@ function compareMaps(left, right) {
2565
2595
  leftKeys.sort();
2566
2596
  rightKeys.sort();
2567
2597
  for (let i = 0; i < leftKeys.length && i < rightKeys.length; ++i) {
2568
- const keyCompare = primitiveComparator(leftKeys[i], rightKeys[i]);
2598
+ const keyCompare = compareUtf8Strings(leftKeys[i], rightKeys[i]);
2569
2599
  if (keyCompare !== 0) {
2570
2600
  return keyCompare;
2571
2601
  }