@firebase/database-compat 0.2.1 → 0.2.2-canary.13550089f

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @firebase/database-compat
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`578dc5836`](https://github.com/firebase/firebase-js-sdk/commit/578dc58365c6c71d8ad01dd8b9dbe829e76de068), [`efe2000fc`](https://github.com/firebase/firebase-js-sdk/commit/efe2000fc499e2c85c4e5e0fef6741ff3bad2eb0)]:
8
+ - @firebase/database@0.13.2
9
+ - @firebase/util@1.6.2
10
+ - @firebase/component@0.5.16
11
+ - @firebase/database-types@0.9.10
12
+
3
13
  ## 0.2.1
4
14
 
5
15
  ### Patch Changes
@@ -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 = "0.2.1";
8
+ const version = "0.2.2-canary.13550089f";
9
9
 
10
10
  /**
11
11
  * @license
@@ -6,7 +6,7 @@ import { __extends } from 'tslib';
6
6
  import { Logger } from '@firebase/logger';
7
7
 
8
8
  var name = "@firebase/database-compat";
9
- var version = "0.2.1";
9
+ var version = "0.2.2-canary.13550089f";
10
10
 
11
11
  /**
12
12
  * @license
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
12
  var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
13
13
 
14
14
  var name = "@firebase/database-compat";
15
- var version = "0.2.1";
15
+ var version = "0.2.2-canary.13550089f";
16
16
 
17
17
  /**
18
18
  * @license
@@ -4383,7 +4383,7 @@ var WebSocketConnection = /** @class */ (function () {
4383
4383
  if (util.isNodeSdk()) {
4384
4384
  var device = this.nodeAdmin ? 'AdminNode' : 'Node';
4385
4385
  // UA Format: Firebase/<wire_protocol>/<sdk_version>/<platform>/<device>
4386
- var options_1 = {
4386
+ options = {
4387
4387
  headers: {
4388
4388
  'User-Agent': "Firebase/" + PROTOCOL_VERSION + "/" + SDK_VERSION + "/" + process.platform + "/" + device,
4389
4389
  'X-Firebase-GMPID': this.applicationId || ''
@@ -4395,10 +4395,10 @@ var WebSocketConnection = /** @class */ (function () {
4395
4395
  // Note that this header is just used to bypass appcheck, and the token should still be sent
4396
4396
  // through the websocket connection once it is established.
4397
4397
  if (this.authToken) {
4398
- options_1.headers['Authorization'] = "Bearer " + this.authToken;
4398
+ options.headers['Authorization'] = "Bearer " + this.authToken;
4399
4399
  }
4400
4400
  if (this.appCheckToken) {
4401
- options_1.headers['X-Firebase-AppCheck'] = this.appCheckToken;
4401
+ options.headers['X-Firebase-AppCheck'] = this.appCheckToken;
4402
4402
  }
4403
4403
  // Plumb appropriate http_proxy environment variable into faye-websocket if it exists.
4404
4404
  var env = process['env'];
@@ -4406,7 +4406,7 @@ var WebSocketConnection = /** @class */ (function () {
4406
4406
  ? env['HTTPS_PROXY'] || env['https_proxy']
4407
4407
  : env['HTTP_PROXY'] || env['http_proxy'];
4408
4408
  if (proxy) {
4409
- options_1['proxy'] = { origin: proxy };
4409
+ options['proxy'] = { origin: proxy };
4410
4410
  }
4411
4411
  }
4412
4412
  this.mySock = new WebSocketImpl(this.connURL, [], options);
@@ -6475,7 +6475,7 @@ function pathEquals(path, other) {
6475
6475
  return true;
6476
6476
  }
6477
6477
  /**
6478
- * @returns True if this path is a parent (or the same as) other
6478
+ * @returns True if this path is a parent of (or the same as) other
6479
6479
  */
6480
6480
  function pathContains(path, other) {
6481
6481
  var i = path.pieceNum_;
@@ -6649,7 +6649,6 @@ var VisibilityMonitor = /** @class */ (function (_super) {
6649
6649
  */
6650
6650
  var RECONNECT_MIN_DELAY = 1000;
6651
6651
  var RECONNECT_MAX_DELAY_DEFAULT = 60 * 5 * 1000; // 5 minutes in milliseconds (Case: 1858)
6652
- var GET_CONNECT_TIMEOUT = 3 * 1000;
6653
6652
  var RECONNECT_MAX_DELAY_FOR_ADMINS = 30 * 1000; // 30 seconds for admin clients (likely to be a backend server)
6654
6653
  var RECONNECT_DELAY_MULTIPLIER = 1.3;
6655
6654
  var RECONNECT_DELAY_RESET_TIMEOUT = 30000; // Reset delay back to MIN_DELAY after being connected for 30sec.
@@ -6728,7 +6727,6 @@ var PersistentConnection = /** @class */ (function (_super) {
6728
6727
  }
6729
6728
  };
6730
6729
  PersistentConnection.prototype.get = function (query) {
6731
- var _this = this;
6732
6730
  this.initConnection_();
6733
6731
  var deferred = new util.Deferred();
6734
6732
  var request = {
@@ -6741,9 +6739,6 @@ var PersistentConnection = /** @class */ (function (_super) {
6741
6739
  onComplete: function (message) {
6742
6740
  var payload = message['d'];
6743
6741
  if (message['s'] === 'ok') {
6744
- _this.onDataUpdate_(request['p'], payload,
6745
- /*isMerge*/ false,
6746
- /*tag*/ null);
6747
6742
  deferred.resolve(payload);
6748
6743
  }
6749
6744
  else {
@@ -6754,21 +6749,6 @@ var PersistentConnection = /** @class */ (function (_super) {
6754
6749
  this.outstandingGets_.push(outstandingGet);
6755
6750
  this.outstandingGetCount_++;
6756
6751
  var index = this.outstandingGets_.length - 1;
6757
- if (!this.connected_) {
6758
- setTimeout(function () {
6759
- var get = _this.outstandingGets_[index];
6760
- if (get === undefined || outstandingGet !== get) {
6761
- return;
6762
- }
6763
- delete _this.outstandingGets_[index];
6764
- _this.outstandingGetCount_--;
6765
- if (_this.outstandingGetCount_ === 0) {
6766
- _this.outstandingGets_ = [];
6767
- }
6768
- _this.log_('get ' + index + ' timed out on connection');
6769
- deferred.reject(new Error('Client is offline.'));
6770
- }, GET_CONNECT_TIMEOUT);
6771
- }
6772
6752
  if (this.connected_) {
6773
6753
  this.sendGet_(index);
6774
6754
  }
@@ -6783,7 +6763,7 @@ var PersistentConnection = /** @class */ (function (_super) {
6783
6763
  this.listens.set(pathString, new Map());
6784
6764
  }
6785
6765
  util.assert(query._queryParams.isDefault() || !query._queryParams.loadsAllData(), 'listen() called for non-default but complete query');
6786
- util.assert(!this.listens.get(pathString).has(queryId), 'listen() called twice for same path/queryId.');
6766
+ util.assert(!this.listens.get(pathString).has(queryId), "listen() called twice for same path/queryId.");
6787
6767
  var listenSpec = {
6788
6768
  onComplete: onComplete,
6789
6769
  hashFn: currentHashFn,
@@ -13528,6 +13508,30 @@ function syncTreeRemoveEventRegistration(syncTree, query, eventRegistration, can
13528
13508
  }
13529
13509
  return cancelEvents;
13530
13510
  }
13511
+ /**
13512
+ * This function was added to support non-listener queries,
13513
+ * specifically for use in repoGetValue. It sets up all the same
13514
+ * local cache data-structures (SyncPoint + View) that are
13515
+ * needed for listeners without installing an event registration.
13516
+ * If `query` is not `loadsAllData`, it will also provision a tag for
13517
+ * the query so that query results can be merged into the sync
13518
+ * tree using existing logic for tagged listener queries.
13519
+ *
13520
+ * @param syncTree - Synctree to add the query to.
13521
+ * @param query - Query to register
13522
+ * @returns tag as a string if query is not a default query, null if query is not.
13523
+ */
13524
+ function syncTreeRegisterQuery(syncTree, query) {
13525
+ var _a = syncTreeRegisterSyncPoint(query, syncTree), syncPoint = _a.syncPoint, serverCache = _a.serverCache, writesCache = _a.writesCache, serverCacheComplete = _a.serverCacheComplete;
13526
+ var view = syncPointGetView(syncPoint, query, writesCache, serverCache, serverCacheComplete);
13527
+ if (!syncPoint.views.has(query._queryIdentifier)) {
13528
+ syncPoint.views.set(query._queryIdentifier, view);
13529
+ }
13530
+ if (!query._queryParams.loadsAllData()) {
13531
+ return syncTreeTagForQuery_(syncTree, query);
13532
+ }
13533
+ return null;
13534
+ }
13531
13535
  /**
13532
13536
  * Apply new server data for the specified tagged query.
13533
13537
  *
@@ -13568,11 +13572,11 @@ function syncTreeApplyTaggedQueryMerge(syncTree, path, changedChildren, tag) {
13568
13572
  }
13569
13573
  }
13570
13574
  /**
13571
- * Add an event callback for the specified query.
13572
- *
13573
- * @returns Events to raise.
13575
+ * Creates a new syncpoint for a query and creates a tag if the view doesn't exist.
13576
+ * Extracted from addEventRegistration to allow `repoGetValue` to properly set up the SyncTree
13577
+ * without actually listening on a query.
13574
13578
  */
13575
- function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
13579
+ function syncTreeRegisterSyncPoint(query, syncTree) {
13576
13580
  var path = query._path;
13577
13581
  var serverCache = null;
13578
13582
  var foundAncestorDefaultView = false;
@@ -13621,6 +13625,22 @@ function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
13621
13625
  syncTree.tagToQueryMap.set(tag, queryKey);
13622
13626
  }
13623
13627
  var writesCache = writeTreeChildWrites(syncTree.pendingWriteTree_, path);
13628
+ return {
13629
+ syncPoint: syncPoint,
13630
+ writesCache: writesCache,
13631
+ serverCache: serverCache,
13632
+ serverCacheComplete: serverCacheComplete,
13633
+ foundAncestorDefaultView: foundAncestorDefaultView,
13634
+ viewAlreadyExists: viewAlreadyExists
13635
+ };
13636
+ }
13637
+ /**
13638
+ * Add an event callback for the specified query.
13639
+ *
13640
+ * @returns Events to raise.
13641
+ */
13642
+ function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
13643
+ var _a = syncTreeRegisterSyncPoint(query, syncTree), syncPoint = _a.syncPoint, serverCache = _a.serverCache, writesCache = _a.writesCache, serverCacheComplete = _a.serverCacheComplete, viewAlreadyExists = _a.viewAlreadyExists, foundAncestorDefaultView = _a.foundAncestorDefaultView;
13624
13644
  var events = syncPointAddEventRegistration(syncPoint, query, eventRegistration, writesCache, serverCache, serverCacheComplete);
13625
13645
  if (!viewAlreadyExists && !foundAncestorDefaultView) {
13626
13646
  var view = syncPointViewForQuery(syncPoint, query);
@@ -14863,9 +14883,25 @@ function repoGetValue(repo, query) {
14863
14883
  }
14864
14884
  return repo.server_.get(query).then(function (payload) {
14865
14885
  var node = nodeFromJSON(payload).withIndex(query._queryParams.getIndex());
14866
- var events = syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
14867
- eventQueueRaiseEventsAtPath(repo.eventQueue_, query._path, events);
14868
- return Promise.resolve(node);
14886
+ // if this is a filtered query, then overwrite at path
14887
+ if (query._queryParams.loadsAllData()) {
14888
+ syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
14889
+ }
14890
+ else {
14891
+ // Simulate `syncTreeAddEventRegistration` without events/listener setup.
14892
+ // We do this (along with the syncTreeRemoveEventRegistration` below) so that
14893
+ // `repoGetValue` results have the same cache effects as initial listener(s)
14894
+ // updates.
14895
+ var tag = syncTreeRegisterQuery(repo.serverSyncTree_, query);
14896
+ syncTreeApplyTaggedQueryOverwrite(repo.serverSyncTree_, query._path, node, tag);
14897
+ // Call `syncTreeRemoveEventRegistration` with a null event registration, since there is none.
14898
+ // Note: The below code essentially unregisters the query and cleans up any views/syncpoints temporarily created above.
14899
+ }
14900
+ var cancels = syncTreeRemoveEventRegistration(repo.serverSyncTree_, query, null);
14901
+ if (cancels.length > 0) {
14902
+ repoLog(repo, 'unexpected cancel events in repoGetValue');
14903
+ }
14904
+ return node;
14869
14905
  }, function (err) {
14870
14906
  repoLog(repo, 'get for query ' + util.stringify(query) + ' failed: ' + err);
14871
14907
  return Promise.reject(new Error(err));