@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.
@@ -10,7 +10,7 @@ var util = require('@firebase/util');
10
10
  var bloomBlob = require('@firebase/webchannel-wrapper/bloom-blob');
11
11
  var crypto = require('crypto');
12
12
 
13
- const version$1 = "4.7.7-canary.3418ef807";
13
+ const version$1 = "4.7.7-canary.4d2fc6e82";
14
14
 
15
15
  /**
16
16
  * @license
@@ -63,7 +63,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
63
63
  User.FIRST_PARTY = new User('first-party-uid');
64
64
  User.MOCK_USER = new User('mock-user');
65
65
 
66
- const version = "11.3.0-canary.3418ef807";
66
+ const version = "11.3.0-canary.4d2fc6e82";
67
67
 
68
68
  /**
69
69
  * @license
@@ -703,6 +703,127 @@ function databaseIdFromApp(app, database) {
703
703
  return new DatabaseId(app.options.projectId, database);
704
704
  }
705
705
 
706
+ /**
707
+ * @license
708
+ * Copyright 2020 Google LLC
709
+ *
710
+ * Licensed under the Apache License, Version 2.0 (the "License");
711
+ * you may not use this file except in compliance with the License.
712
+ * You may obtain a copy of the License at
713
+ *
714
+ * http://www.apache.org/licenses/LICENSE-2.0
715
+ *
716
+ * Unless required by applicable law or agreed to in writing, software
717
+ * distributed under the License is distributed on an "AS IS" BASIS,
718
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
719
+ * See the License for the specific language governing permissions and
720
+ * limitations under the License.
721
+ */
722
+ /**
723
+ * Generates `nBytes` of random bytes.
724
+ *
725
+ * If `nBytes < 0` , an error will be thrown.
726
+ */
727
+ function randomBytes(nBytes) {
728
+ return crypto.randomBytes(nBytes);
729
+ }
730
+
731
+ /**
732
+ * @license
733
+ * Copyright 2023 Google LLC
734
+ *
735
+ * Licensed under the Apache License, Version 2.0 (the "License");
736
+ * you may not use this file except in compliance with the License.
737
+ * You may obtain a copy of the License at
738
+ *
739
+ * http://www.apache.org/licenses/LICENSE-2.0
740
+ *
741
+ * Unless required by applicable law or agreed to in writing, software
742
+ * distributed under the License is distributed on an "AS IS" BASIS,
743
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
744
+ * See the License for the specific language governing permissions and
745
+ * limitations under the License.
746
+ */
747
+ /**
748
+ * An instance of the Platform's 'TextEncoder' implementation.
749
+ */
750
+ function newTextEncoder() {
751
+ return new TextEncoder();
752
+ }
753
+
754
+ /**
755
+ * @license
756
+ * Copyright 2017 Google LLC
757
+ *
758
+ * Licensed under the Apache License, Version 2.0 (the "License");
759
+ * you may not use this file except in compliance with the License.
760
+ * You may obtain a copy of the License at
761
+ *
762
+ * http://www.apache.org/licenses/LICENSE-2.0
763
+ *
764
+ * Unless required by applicable law or agreed to in writing, software
765
+ * distributed under the License is distributed on an "AS IS" BASIS,
766
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
767
+ * See the License for the specific language governing permissions and
768
+ * limitations under the License.
769
+ */
770
+ /**
771
+ * A utility class for generating unique alphanumeric IDs of a specified length.
772
+ *
773
+ * @internal
774
+ * Exported internally for testing purposes.
775
+ */
776
+ class AutoId {
777
+ static newId() {
778
+ // Alphanumeric characters
779
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
780
+ // The largest byte value that is a multiple of `char.length`.
781
+ const maxMultiple = Math.floor(256 / chars.length) * chars.length;
782
+ let autoId = '';
783
+ const targetLength = 20;
784
+ while (autoId.length < targetLength) {
785
+ const bytes = randomBytes(40);
786
+ for (let i = 0; i < bytes.length; ++i) {
787
+ // Only accept values that are [0, maxMultiple), this ensures they can
788
+ // be evenly mapped to indices of `chars` via a modulo operation.
789
+ if (autoId.length < targetLength && bytes[i] < maxMultiple) {
790
+ autoId += chars.charAt(bytes[i] % chars.length);
791
+ }
792
+ }
793
+ }
794
+ return autoId;
795
+ }
796
+ }
797
+ function primitiveComparator(left, right) {
798
+ if (left < right) {
799
+ return -1;
800
+ }
801
+ if (left > right) {
802
+ return 1;
803
+ }
804
+ return 0;
805
+ }
806
+ /** Compare strings in UTF-8 encoded byte order */
807
+ function compareUtf8Strings(left, right) {
808
+ // Convert the string to UTF-8 encoded bytes
809
+ const encodedLeft = newTextEncoder().encode(left);
810
+ const encodedRight = newTextEncoder().encode(right);
811
+ for (let i = 0; i < Math.min(encodedLeft.length, encodedRight.length); i++) {
812
+ const comparison = primitiveComparator(encodedLeft[i], encodedRight[i]);
813
+ if (comparison !== 0) {
814
+ return comparison;
815
+ }
816
+ }
817
+ return primitiveComparator(encodedLeft.length, encodedRight.length);
818
+ }
819
+ /** Helper to compare arrays using isEqual(). */
820
+ function arrayEquals(left, right, comparator) {
821
+ if (left.length !== right.length) {
822
+ return false;
823
+ }
824
+ return left.every((value, index) => comparator(value, right[index]));
825
+ }
826
+
706
827
  /**
707
828
  * @license
708
829
  * Copyright 2017 Google LLC
@@ -825,7 +946,7 @@ class BasePath {
825
946
  return comparison;
826
947
  }
827
948
  }
828
- return Math.sign(p1.length - p2.length);
949
+ return primitiveComparator(p1.length, p2.length);
829
950
  }
830
951
  static compareSegments(lhs, rhs) {
831
952
  const isLhsNumeric = BasePath.isNumericId(lhs);
@@ -844,13 +965,7 @@ class BasePath {
844
965
  }
845
966
  else {
846
967
  // both non-numeric
847
- if (lhs < rhs) {
848
- return -1;
849
- }
850
- if (lhs > rhs) {
851
- return 1;
852
- }
853
- return 0;
968
+ return compareUtf8Strings(lhs, rhs);
854
969
  }
855
970
  }
856
971
  // Checks if a segment is a numeric ID (starts with "__id" and ends with "__").
@@ -1650,91 +1765,6 @@ function newConnection(databaseInfo) {
1650
1765
  return new FetchConnection(databaseInfo);
1651
1766
  }
1652
1767
 
1653
- /**
1654
- * @license
1655
- * Copyright 2020 Google LLC
1656
- *
1657
- * Licensed under the Apache License, Version 2.0 (the "License");
1658
- * you may not use this file except in compliance with the License.
1659
- * You may obtain a copy of the License at
1660
- *
1661
- * http://www.apache.org/licenses/LICENSE-2.0
1662
- *
1663
- * Unless required by applicable law or agreed to in writing, software
1664
- * distributed under the License is distributed on an "AS IS" BASIS,
1665
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1666
- * See the License for the specific language governing permissions and
1667
- * limitations under the License.
1668
- */
1669
- /**
1670
- * Generates `nBytes` of random bytes.
1671
- *
1672
- * If `nBytes < 0` , an error will be thrown.
1673
- */
1674
- function randomBytes(nBytes) {
1675
- return crypto.randomBytes(nBytes);
1676
- }
1677
-
1678
- /**
1679
- * @license
1680
- * Copyright 2017 Google LLC
1681
- *
1682
- * Licensed under the Apache License, Version 2.0 (the "License");
1683
- * you may not use this file except in compliance with the License.
1684
- * You may obtain a copy of the License at
1685
- *
1686
- * http://www.apache.org/licenses/LICENSE-2.0
1687
- *
1688
- * Unless required by applicable law or agreed to in writing, software
1689
- * distributed under the License is distributed on an "AS IS" BASIS,
1690
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1691
- * See the License for the specific language governing permissions and
1692
- * limitations under the License.
1693
- */
1694
- /**
1695
- * A utility class for generating unique alphanumeric IDs of a specified length.
1696
- *
1697
- * @internal
1698
- * Exported internally for testing purposes.
1699
- */
1700
- class AutoId {
1701
- static newId() {
1702
- // Alphanumeric characters
1703
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1704
- // The largest byte value that is a multiple of `char.length`.
1705
- const maxMultiple = Math.floor(256 / chars.length) * chars.length;
1706
- let autoId = '';
1707
- const targetLength = 20;
1708
- while (autoId.length < targetLength) {
1709
- const bytes = randomBytes(40);
1710
- for (let i = 0; i < bytes.length; ++i) {
1711
- // Only accept values that are [0, maxMultiple), this ensures they can
1712
- // be evenly mapped to indices of `chars` via a modulo operation.
1713
- if (autoId.length < targetLength && bytes[i] < maxMultiple) {
1714
- autoId += chars.charAt(bytes[i] % chars.length);
1715
- }
1716
- }
1717
- }
1718
- return autoId;
1719
- }
1720
- }
1721
- function primitiveComparator(left, right) {
1722
- if (left < right) {
1723
- return -1;
1724
- }
1725
- if (left > right) {
1726
- return 1;
1727
- }
1728
- return 0;
1729
- }
1730
- /** Helper to compare arrays using isEqual(). */
1731
- function arrayEquals(left, right, comparator) {
1732
- if (left.length !== right.length) {
1733
- return false;
1734
- }
1735
- return left.every((value, index) => comparator(value, right[index]));
1736
- }
1737
-
1738
1768
  /**
1739
1769
  * @license
1740
1770
  * Copyright 2017 Google LLC
@@ -2448,7 +2478,7 @@ function valueCompare(left, right) {
2448
2478
  case 4 /* TypeOrder.ServerTimestampValue */:
2449
2479
  return compareTimestamps(getLocalWriteTime(left), getLocalWriteTime(right));
2450
2480
  case 5 /* TypeOrder.StringValue */:
2451
- return primitiveComparator(left.stringValue, right.stringValue);
2481
+ return compareUtf8Strings(left.stringValue, right.stringValue);
2452
2482
  case 6 /* TypeOrder.BlobValue */:
2453
2483
  return compareBlobs(left.bytesValue, right.bytesValue);
2454
2484
  case 7 /* TypeOrder.RefValue */:
@@ -2569,7 +2599,7 @@ function compareMaps(left, right) {
2569
2599
  leftKeys.sort();
2570
2600
  rightKeys.sort();
2571
2601
  for (let i = 0; i < leftKeys.length && i < rightKeys.length; ++i) {
2572
- const keyCompare = primitiveComparator(leftKeys[i], rightKeys[i]);
2602
+ const keyCompare = compareUtf8Strings(leftKeys[i], rightKeys[i]);
2573
2603
  if (keyCompare !== 0) {
2574
2604
  return keyCompare;
2575
2605
  }