@firebase/database-compat 2.0.2-canary.82373b372 → 2.0.2-canary.99766e0b8

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.
@@ -5,7 +5,7 @@ import { errorPrefix, validateArgCount, validateCallback, validateContextObject,
5
5
  import { Logger } from '@firebase/logger';
6
6
 
7
7
  const name = "@firebase/database-compat";
8
- const version = "2.0.2-canary.82373b372";
8
+ const version = "2.0.2-canary.99766e0b8";
9
9
 
10
10
  /**
11
11
  * @license
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
11
11
  var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
12
12
 
13
13
  const name = "@firebase/database-compat";
14
- const version = "2.0.2-canary.82373b372";
14
+ const version = "2.0.2-canary.99766e0b8";
15
15
 
16
16
  /**
17
17
  * @license
@@ -3710,7 +3710,7 @@ function isVersionServiceProvider(provider) {
3710
3710
  }
3711
3711
 
3712
3712
  const name$q = "@firebase/app";
3713
- const version$1 = "0.10.18-canary.82373b372";
3713
+ const version$1 = "0.10.18-canary.99766e0b8";
3714
3714
 
3715
3715
  /**
3716
3716
  * @license
@@ -3781,7 +3781,7 @@ const name$2 = "@firebase/vertexai";
3781
3781
  const name$1 = "@firebase/firestore-compat";
3782
3782
 
3783
3783
  const name = "firebase";
3784
- const version = "11.2.0-canary.82373b372";
3784
+ const version = "11.2.0-canary.99766e0b8";
3785
3785
 
3786
3786
  /**
3787
3787
  * @license
@@ -4562,7 +4562,8 @@ function computeKey(app) {
4562
4562
  * limitations under the License.
4563
4563
  */
4564
4564
  const MAX_HEADER_BYTES = 1024;
4565
- const MAX_NUM_STORED_HEARTBEATS = 30;
4565
+ // 30 days
4566
+ const STORED_HEARTBEAT_RETENTION_MAX_MILLIS = 30 * 24 * 60 * 60 * 1000;
4566
4567
  class HeartbeatServiceImpl {
4567
4568
  constructor(container) {
4568
4569
  this.container = container;
@@ -4616,13 +4617,14 @@ class HeartbeatServiceImpl {
4616
4617
  else {
4617
4618
  // There is no entry for this date. Create one.
4618
4619
  this._heartbeatsCache.heartbeats.push({ date, agent });
4619
- // If the number of stored heartbeats exceeds the maximum number of stored heartbeats, remove the heartbeat with the earliest date.
4620
- // Since this is executed each time a heartbeat is pushed, the limit can only be exceeded by one, so only one needs to be removed.
4621
- if (this._heartbeatsCache.heartbeats.length > MAX_NUM_STORED_HEARTBEATS) {
4622
- const earliestHeartbeatIdx = getEarliestHeartbeatIdx(this._heartbeatsCache.heartbeats);
4623
- this._heartbeatsCache.heartbeats.splice(earliestHeartbeatIdx, 1);
4624
- }
4625
4620
  }
4621
+ // Remove entries older than 30 days.
4622
+ this._heartbeatsCache.heartbeats =
4623
+ this._heartbeatsCache.heartbeats.filter(singleDateHeartbeat => {
4624
+ const hbTimestamp = new Date(singleDateHeartbeat.date).valueOf();
4625
+ const now = Date.now();
4626
+ return now - hbTimestamp <= STORED_HEARTBEAT_RETENTION_MAX_MILLIS;
4627
+ });
4626
4628
  return this._storage.overwrite(this._heartbeatsCache);
4627
4629
  }
4628
4630
  catch (e) {
@@ -4797,24 +4799,6 @@ function countBytes(heartbeatsCache) {
4797
4799
  // heartbeatsCache wrapper properties
4798
4800
  JSON.stringify({ version: 2, heartbeats: heartbeatsCache })).length;
4799
4801
  }
4800
- /**
4801
- * Returns the index of the heartbeat with the earliest date.
4802
- * If the heartbeats array is empty, -1 is returned.
4803
- */
4804
- function getEarliestHeartbeatIdx(heartbeats) {
4805
- if (heartbeats.length === 0) {
4806
- return -1;
4807
- }
4808
- let earliestHeartbeatIdx = 0;
4809
- let earliestHeartbeatDate = heartbeats[0].date;
4810
- for (let i = 1; i < heartbeats.length; i++) {
4811
- if (heartbeats[i].date < earliestHeartbeatDate) {
4812
- earliestHeartbeatDate = heartbeats[i].date;
4813
- earliestHeartbeatIdx = i;
4814
- }
4815
- }
4816
- return earliestHeartbeatIdx;
4817
- }
4818
4802
 
4819
4803
  /**
4820
4804
  * @license
@@ -8629,7 +8613,7 @@ class PersistentConnection extends ServerActions {
8629
8613
  }
8630
8614
  this.lastConnectionEstablishedTime_ = null;
8631
8615
  }
8632
- const timeSinceLastConnectAttempt = Math.max(0, new Date().getTime() - this.lastConnectionAttemptTime_);
8616
+ const timeSinceLastConnectAttempt = new Date().getTime() - this.lastConnectionAttemptTime_;
8633
8617
  let reconnectDelay = Math.max(0, this.reconnectDelay_ - timeSinceLastConnectAttempt);
8634
8618
  reconnectDelay = Math.random() * reconnectDelay;
8635
8619
  this.log_('Trying to reconnect in ' + reconnectDelay + 'ms');