@firebase/database 0.13.1 → 0.13.2-canary.b60cf76e1

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.
@@ -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.b60cf76e1";
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_;
@@ -3400,9 +3400,6 @@ var PersistentConnection = /** @class */ (function (_super) {
3400
3400
  onComplete: function (message) {
3401
3401
  var payload = message['d'];
3402
3402
  if (message['s'] === 'ok') {
3403
- _this.onDataUpdate_(request['p'], payload,
3404
- /*isMerge*/ false,
3405
- /*tag*/ null);
3406
3403
  deferred.resolve(payload);
3407
3404
  }
3408
3405
  else {
@@ -3442,7 +3439,7 @@ var PersistentConnection = /** @class */ (function (_super) {
3442
3439
  this.listens.set(pathString, new Map());
3443
3440
  }
3444
3441
  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.');
3442
+ util.assert(!this.listens.get(pathString).has(queryId), "listen() called twice for same path/queryId.");
3446
3443
  var listenSpec = {
3447
3444
  onComplete: onComplete,
3448
3445
  hashFn: currentHashFn,
@@ -10187,6 +10184,30 @@ function syncTreeRemoveEventRegistration(syncTree, query, eventRegistration, can
10187
10184
  }
10188
10185
  return cancelEvents;
10189
10186
  }
10187
+ /**
10188
+ * This function was added to support non-listener queries,
10189
+ * specifically for use in repoGetValue. It sets up all the same
10190
+ * local cache data-structures (SyncPoint + View) that are
10191
+ * needed for listeners without installing an event registration.
10192
+ * If `query` is not `loadsAllData`, it will also provision a tag for
10193
+ * the query so that query results can be merged into the sync
10194
+ * tree using existing logic for tagged listener queries.
10195
+ *
10196
+ * @param syncTree - Synctree to add the query to.
10197
+ * @param query - Query to register
10198
+ * @returns tag as a string if query is not a default query, null if query is not.
10199
+ */
10200
+ function syncTreeRegisterQuery(syncTree, query) {
10201
+ var _a = syncTreeRegisterSyncPoint(query, syncTree), syncPoint = _a.syncPoint, serverCache = _a.serverCache, writesCache = _a.writesCache, serverCacheComplete = _a.serverCacheComplete;
10202
+ var view = syncPointGetView(syncPoint, query, writesCache, serverCache, serverCacheComplete);
10203
+ if (!syncPoint.views.has(query._queryIdentifier)) {
10204
+ syncPoint.views.set(query._queryIdentifier, view);
10205
+ }
10206
+ if (!query._queryParams.loadsAllData()) {
10207
+ return syncTreeTagForQuery_(syncTree, query);
10208
+ }
10209
+ return null;
10210
+ }
10190
10211
  /**
10191
10212
  * Apply new server data for the specified tagged query.
10192
10213
  *
@@ -10227,11 +10248,11 @@ function syncTreeApplyTaggedQueryMerge(syncTree, path, changedChildren, tag) {
10227
10248
  }
10228
10249
  }
10229
10250
  /**
10230
- * Add an event callback for the specified query.
10231
- *
10232
- * @returns Events to raise.
10251
+ * Creates a new syncpoint for a query and creates a tag if the view doesn't exist.
10252
+ * Extracted from addEventRegistration to allow `repoGetValue` to properly set up the SyncTree
10253
+ * without actually listening on a query.
10233
10254
  */
10234
- function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
10255
+ function syncTreeRegisterSyncPoint(query, syncTree) {
10235
10256
  var path = query._path;
10236
10257
  var serverCache = null;
10237
10258
  var foundAncestorDefaultView = false;
@@ -10280,6 +10301,22 @@ function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
10280
10301
  syncTree.tagToQueryMap.set(tag, queryKey);
10281
10302
  }
10282
10303
  var writesCache = writeTreeChildWrites(syncTree.pendingWriteTree_, path);
10304
+ return {
10305
+ syncPoint: syncPoint,
10306
+ writesCache: writesCache,
10307
+ serverCache: serverCache,
10308
+ serverCacheComplete: serverCacheComplete,
10309
+ foundAncestorDefaultView: foundAncestorDefaultView,
10310
+ viewAlreadyExists: viewAlreadyExists
10311
+ };
10312
+ }
10313
+ /**
10314
+ * Add an event callback for the specified query.
10315
+ *
10316
+ * @returns Events to raise.
10317
+ */
10318
+ function syncTreeAddEventRegistration(syncTree, query, eventRegistration) {
10319
+ var _a = syncTreeRegisterSyncPoint(query, syncTree), syncPoint = _a.syncPoint, serverCache = _a.serverCache, writesCache = _a.writesCache, serverCacheComplete = _a.serverCacheComplete, viewAlreadyExists = _a.viewAlreadyExists, foundAncestorDefaultView = _a.foundAncestorDefaultView;
10283
10320
  var events = syncPointAddEventRegistration(syncPoint, query, eventRegistration, writesCache, serverCache, serverCacheComplete);
10284
10321
  if (!viewAlreadyExists && !foundAncestorDefaultView) {
10285
10322
  var view = syncPointViewForQuery(syncPoint, query);
@@ -11522,9 +11559,25 @@ function repoGetValue(repo, query) {
11522
11559
  }
11523
11560
  return repo.server_.get(query).then(function (payload) {
11524
11561
  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);
11562
+ // if this is a filtered query, then overwrite at path
11563
+ if (query._queryParams.loadsAllData()) {
11564
+ syncTreeApplyServerOverwrite(repo.serverSyncTree_, query._path, node);
11565
+ }
11566
+ else {
11567
+ // Simulate `syncTreeAddEventRegistration` without events/listener setup.
11568
+ // We do this (along with the syncTreeRemoveEventRegistration` below) so that
11569
+ // `repoGetValue` results have the same cache effects as initial listener(s)
11570
+ // updates.
11571
+ var tag = syncTreeRegisterQuery(repo.serverSyncTree_, query);
11572
+ syncTreeApplyTaggedQueryOverwrite(repo.serverSyncTree_, query._path, node, tag);
11573
+ // Call `syncTreeRemoveEventRegistration` with a null event registration, since there is none.
11574
+ // Note: The below code essentially unregisters the query and cleans up any views/syncpoints temporarily created above.
11575
+ }
11576
+ var cancels = syncTreeRemoveEventRegistration(repo.serverSyncTree_, query, null);
11577
+ if (cancels.length > 0) {
11578
+ repoLog(repo, 'unexpected cancel events in repoGetValue');
11579
+ }
11580
+ return node;
11528
11581
  }, function (err) {
11529
11582
  repoLog(repo, 'get for query ' + util.stringify(query) + ' failed: ' + err);
11530
11583
  return Promise.reject(new Error(err));