@firebase/database 0.13.1 → 0.13.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.
@@ -1039,7 +1039,7 @@ var WebSocketConnection = /** @class */ (function () {
1039
1039
  if (util.isNodeSdk()) {
1040
1040
  var device = this.nodeAdmin ? 'AdminNode' : 'Node';
1041
1041
  // UA Format: Firebase/<wire_protocol>/<sdk_version>/<platform>/<device>
1042
- var options_1 = {
1042
+ options = {
1043
1043
  headers: {
1044
1044
  'User-Agent': "Firebase/" + PROTOCOL_VERSION + "/" + SDK_VERSION + "/" + process.platform + "/" + device,
1045
1045
  'X-Firebase-GMPID': this.applicationId || ''
@@ -1051,10 +1051,10 @@ var WebSocketConnection = /** @class */ (function () {
1051
1051
  // Note that this header is just used to bypass appcheck, and the token should still be sent
1052
1052
  // through the websocket connection once it is established.
1053
1053
  if (this.authToken) {
1054
- options_1.headers['Authorization'] = "Bearer " + this.authToken;
1054
+ options.headers['Authorization'] = "Bearer " + this.authToken;
1055
1055
  }
1056
1056
  if (this.appCheckToken) {
1057
- options_1.headers['X-Firebase-AppCheck'] = this.appCheckToken;
1057
+ options.headers['X-Firebase-AppCheck'] = this.appCheckToken;
1058
1058
  }
1059
1059
  // Plumb appropriate http_proxy environment variable into faye-websocket if it exists.
1060
1060
  var env = process['env'];
@@ -1062,7 +1062,7 @@ var WebSocketConnection = /** @class */ (function () {
1062
1062
  ? env['HTTPS_PROXY'] || env['https_proxy']
1063
1063
  : env['HTTP_PROXY'] || env['http_proxy'];
1064
1064
  if (proxy) {
1065
- options_1['proxy'] = { origin: proxy };
1065
+ options['proxy'] = { origin: proxy };
1066
1066
  }
1067
1067
  }
1068
1068
  this.mySock = new WebSocketImpl(this.connURL, [], options);
@@ -1289,7 +1289,7 @@ var WebSocketConnection = /** @class */ (function () {
1289
1289
  }());
1290
1290
 
1291
1291
  var name = "@firebase/database";
1292
- var version = "0.13.1";
1292
+ var version = "0.13.2-canary.13550089f";
1293
1293
 
1294
1294
  /**
1295
1295
  * @license
@@ -3134,7 +3134,7 @@ function pathEquals(path, other) {
3134
3134
  return true;
3135
3135
  }
3136
3136
  /**
3137
- * @returns True if this path is a parent (or the same as) other
3137
+ * @returns True if this path is a parent of (or the same as) other
3138
3138
  */
3139
3139
  function pathContains(path, other) {
3140
3140
  var i = path.pieceNum_;
@@ -3308,7 +3308,6 @@ var VisibilityMonitor = /** @class */ (function (_super) {
3308
3308
  */
3309
3309
  var RECONNECT_MIN_DELAY = 1000;
3310
3310
  var RECONNECT_MAX_DELAY_DEFAULT = 60 * 5 * 1000; // 5 minutes in milliseconds (Case: 1858)
3311
- var GET_CONNECT_TIMEOUT = 3 * 1000;
3312
3311
  var RECONNECT_MAX_DELAY_FOR_ADMINS = 30 * 1000; // 30 seconds for admin clients (likely to be a backend server)
3313
3312
  var RECONNECT_DELAY_MULTIPLIER = 1.3;
3314
3313
  var RECONNECT_DELAY_RESET_TIMEOUT = 30000; // Reset delay back to MIN_DELAY after being connected for 30sec.
@@ -3387,7 +3386,6 @@ var PersistentConnection = /** @class */ (function (_super) {
3387
3386
  }
3388
3387
  };
3389
3388
  PersistentConnection.prototype.get = function (query) {
3390
- var _this = this;
3391
3389
  this.initConnection_();
3392
3390
  var deferred = new util.Deferred();
3393
3391
  var request = {
@@ -3400,9 +3398,6 @@ var PersistentConnection = /** @class */ (function (_super) {
3400
3398
  onComplete: function (message) {
3401
3399
  var payload = message['d'];
3402
3400
  if (message['s'] === 'ok') {
3403
- _this.onDataUpdate_(request['p'], payload,
3404
- /*isMerge*/ false,
3405
- /*tag*/ null);
3406
3401
  deferred.resolve(payload);
3407
3402
  }
3408
3403
  else {
@@ -3413,21 +3408,6 @@ var PersistentConnection = /** @class */ (function (_super) {
3413
3408
  this.outstandingGets_.push(outstandingGet);
3414
3409
  this.outstandingGetCount_++;
3415
3410
  var index = this.outstandingGets_.length - 1;
3416
- if (!this.connected_) {
3417
- setTimeout(function () {
3418
- var get = _this.outstandingGets_[index];
3419
- if (get === undefined || outstandingGet !== get) {
3420
- return;
3421
- }
3422
- delete _this.outstandingGets_[index];
3423
- _this.outstandingGetCount_--;
3424
- if (_this.outstandingGetCount_ === 0) {
3425
- _this.outstandingGets_ = [];
3426
- }
3427
- _this.log_('get ' + index + ' timed out on connection');
3428
- deferred.reject(new Error('Client is offline.'));
3429
- }, GET_CONNECT_TIMEOUT);
3430
- }
3431
3411
  if (this.connected_) {
3432
3412
  this.sendGet_(index);
3433
3413
  }
@@ -3442,7 +3422,7 @@ var PersistentConnection = /** @class */ (function (_super) {
3442
3422
  this.listens.set(pathString, new Map());
3443
3423
  }
3444
3424
  util.assert(query._queryParams.isDefault() || !query._queryParams.loadsAllData(), 'listen() called for non-default but complete query');
3445
- util.assert(!this.listens.get(pathString).has(queryId), 'listen() called twice for same path/queryId.');
3425
+ util.assert(!this.listens.get(pathString).has(queryId), "listen() called twice for same path/queryId.");
3446
3426
  var listenSpec = {
3447
3427
  onComplete: onComplete,
3448
3428
  hashFn: currentHashFn,
@@ -10187,6 +10167,30 @@ function syncTreeRemoveEventRegistration(syncTree, query, eventRegistration, can
10187
10167
  }
10188
10168
  return cancelEvents;
10189
10169
  }
10170
+ /**
10171
+ * This function was added to support non-listener queries,
10172
+ * specifically for use in repoGetValue. It sets up all the same
10173
+ * local cache data-structures (SyncPoint + View) that are
10174
+ * needed for listeners without installing an event registration.
10175
+ * If `query` is not `loadsAllData`, it will also provision a tag for
10176
+ * the query so that query results can be merged into the sync
10177
+ * tree using existing logic for tagged listener queries.
10178
+ *
10179
+ * @param syncTree - Synctree to add the query to.
10180
+ * @param query - Query to register
10181
+ * @returns tag as a string if query is not a default query, null if query is not.
10182
+ */
10183
+ function syncTreeRegisterQuery(syncTree, query) {
10184
+ var _a = syncTreeRegisterSyncPoint(query, syncTree), syncPoint = _a.syncPoint, serverCache = _a.serverCache, writesCache = _a.writesCache, serverCacheComplete = _a.serverCacheComplete;
10185
+ var view = syncPointGetView(syncPoint, query, writesCache, serverCache, serverCacheComplete);
10186
+ if (!syncPoint.views.has(query._queryIdentifier)) {
10187
+ syncPoint.views.set(query._queryIdentifier, view);
10188
+ }
10189
+ if (!query._queryParams.loadsAllData()) {
10190
+ return syncTreeTagForQuery_(syncTree, query);
10191
+ }
10192
+ return null;
10193
+ }
10190
10194
  /**
10191
10195
  * Apply new server data for the specified tagged query.
10192
10196
  *
@@ -10227,11 +10231,11 @@ function syncTreeApplyTaggedQueryMerge(syncTree, path, changedChildren, tag) {
10227
10231
  }
10228
10232
  }
10229
10233
  /**
10230
- * Add an event callback for the specified query.
10231
- *
10232
- * @returns Events to raise.
10234
+ * Creates a new syncpoint for a query and creates a tag if the view doesn't exist.
10235
+ * Extracted from addEventRegistration to allow `repoGetValue` to properly set up the SyncTree
10236
+ * without actually listening on a query.
10233
10237
  */
10234
- function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
10238
+ function syncTreeRegisterSyncPoint(query, syncTree) {
10235
10239
  var path = query._path;
10236
10240
  var serverCache = null;
10237
10241
  var foundAncestorDefaultView = false;
@@ -10280,6 +10284,22 @@ function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
10280
10284
  syncTree.tagToQueryMap.set(tag, queryKey);
10281
10285
  }
10282
10286
  var writesCache = writeTreeChildWrites(syncTree.pendingWriteTree_, path);
10287
+ return {
10288
+ syncPoint: syncPoint,
10289
+ writesCache: writesCache,
10290
+ serverCache: serverCache,
10291
+ serverCacheComplete: serverCacheComplete,
10292
+ foundAncestorDefaultView: foundAncestorDefaultView,
10293
+ viewAlreadyExists: viewAlreadyExists
10294
+ };
10295
+ }
10296
+ /**
10297
+ * Add an event callback for the specified query.
10298
+ *
10299
+ * @returns Events to raise.
10300
+ */
10301
+ function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
10302
+ var _a = syncTreeRegisterSyncPoint(query, syncTree), syncPoint = _a.syncPoint, serverCache = _a.serverCache, writesCache = _a.writesCache, serverCacheComplete = _a.serverCacheComplete, viewAlreadyExists = _a.viewAlreadyExists, foundAncestorDefaultView = _a.foundAncestorDefaultView;
10283
10303
  var events = syncPointAddEventRegistration(syncPoint, query, eventRegistration, writesCache, serverCache, serverCacheComplete);
10284
10304
  if (!viewAlreadyExists && !foundAncestorDefaultView) {
10285
10305
  var view = syncPointViewForQuery(syncPoint, query);
@@ -11522,9 +11542,25 @@ function repoGetValue(repo, query) {
11522
11542
  }
11523
11543
  return repo.server_.get(query).then(function (payload) {
11524
11544
  var node = nodeFromJSON(payload).withIndex(query._queryParams.getIndex());
11525
- var events = syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
11526
- eventQueueRaiseEventsAtPath(repo.eventQueue_, query._path, events);
11527
- return Promise.resolve(node);
11545
+ // if this is a filtered query, then overwrite at path
11546
+ if (query._queryParams.loadsAllData()) {
11547
+ syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
11548
+ }
11549
+ else {
11550
+ // Simulate `syncTreeAddEventRegistration` without events/listener setup.
11551
+ // We do this (along with the syncTreeRemoveEventRegistration` below) so that
11552
+ // `repoGetValue` results have the same cache effects as initial listener(s)
11553
+ // updates.
11554
+ var tag = syncTreeRegisterQuery(repo.serverSyncTree_, query);
11555
+ syncTreeApplyTaggedQueryOverwrite(repo.serverSyncTree_, query._path, node, tag);
11556
+ // Call `syncTreeRemoveEventRegistration` with a null event registration, since there is none.
11557
+ // Note: The below code essentially unregisters the query and cleans up any views/syncpoints temporarily created above.
11558
+ }
11559
+ var cancels = syncTreeRemoveEventRegistration(repo.serverSyncTree_, query, null);
11560
+ if (cancels.length > 0) {
11561
+ repoLog(repo, 'unexpected cancel events in repoGetValue');
11562
+ }
11563
+ return node;
11528
11564
  }, function (err) {
11529
11565
  repoLog(repo, 'get for query ' + util.stringify(query) + ' failed: ' + err);
11530
11566
  return Promise.reject(new Error(err));