@firebase/database 0.13.10 → 0.14.0

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.
@@ -321,7 +321,7 @@ var logWrapper = function (prefix) {
321
321
  for (var _i = 0; _i < arguments.length; _i++) {
322
322
  varArgs[_i] = arguments[_i];
323
323
  }
324
- log.apply(void 0, tslib.__spreadArray([prefix], tslib.__read(varArgs)));
324
+ log.apply(void 0, tslib.__spreadArray([prefix], tslib.__read(varArgs), false));
325
325
  };
326
326
  };
327
327
  var error = function () {
@@ -329,7 +329,7 @@ var error = function () {
329
329
  for (var _i = 0; _i < arguments.length; _i++) {
330
330
  varArgs[_i] = arguments[_i];
331
331
  }
332
- var message = 'FIREBASE INTERNAL ERROR: ' + buildLogMessage_.apply(void 0, tslib.__spreadArray([], tslib.__read(varArgs)));
332
+ var message = 'FIREBASE INTERNAL ERROR: ' + buildLogMessage_.apply(void 0, tslib.__spreadArray([], tslib.__read(varArgs), false));
333
333
  logClient.error(message);
334
334
  };
335
335
  var fatal = function () {
@@ -337,7 +337,7 @@ var fatal = function () {
337
337
  for (var _i = 0; _i < arguments.length; _i++) {
338
338
  varArgs[_i] = arguments[_i];
339
339
  }
340
- var message = "FIREBASE FATAL ERROR: " + buildLogMessage_.apply(void 0, tslib.__spreadArray([], tslib.__read(varArgs)));
340
+ var message = "FIREBASE FATAL ERROR: ".concat(buildLogMessage_.apply(void 0, tslib.__spreadArray([], tslib.__read(varArgs), false)));
341
341
  logClient.error(message);
342
342
  throw new Error(message);
343
343
  };
@@ -346,7 +346,7 @@ var warn = function () {
346
346
  for (var _i = 0; _i < arguments.length; _i++) {
347
347
  varArgs[_i] = arguments[_i];
348
348
  }
349
- var message = 'FIREBASE WARNING: ' + buildLogMessage_.apply(void 0, tslib.__spreadArray([], tslib.__read(varArgs)));
349
+ var message = 'FIREBASE WARNING: ' + buildLogMessage_.apply(void 0, tslib.__spreadArray([], tslib.__read(varArgs), false));
350
350
  logClient.warn(message);
351
351
  };
352
352
  /**
@@ -803,9 +803,9 @@ var RepoInfo = /** @class */ (function () {
803
803
  RepoInfo.prototype.toURLString = function () {
804
804
  var protocol = this.secure ? 'https://' : 'http://';
805
805
  var query = this.includeNamespaceInQueryParams
806
- ? "?ns=" + this.namespace
806
+ ? "?ns=".concat(this.namespace)
807
807
  : '';
808
- return "" + protocol + this.host + "/" + query;
808
+ return "".concat(protocol).concat(this.host, "/").concat(query);
809
809
  };
810
810
  return RepoInfo;
811
811
  }());
@@ -1050,7 +1050,7 @@ var WebSocketConnection = /** @class */ (function () {
1050
1050
  // UA Format: Firebase/<wire_protocol>/<sdk_version>/<platform>/<device>
1051
1051
  options = {
1052
1052
  headers: {
1053
- 'User-Agent': "Firebase/" + PROTOCOL_VERSION + "/" + SDK_VERSION + "/" + process.platform + "/" + device,
1053
+ 'User-Agent': "Firebase/".concat(PROTOCOL_VERSION, "/").concat(SDK_VERSION, "/").concat(process.platform, "/").concat(device),
1054
1054
  'X-Firebase-GMPID': this.applicationId || ''
1055
1055
  }
1056
1056
  };
@@ -1060,7 +1060,7 @@ var WebSocketConnection = /** @class */ (function () {
1060
1060
  // Note that this header is just used to bypass appcheck, and the token should still be sent
1061
1061
  // through the websocket connection once it is established.
1062
1062
  if (this.authToken) {
1063
- options.headers['Authorization'] = "Bearer " + this.authToken;
1063
+ options.headers['Authorization'] = "Bearer ".concat(this.authToken);
1064
1064
  }
1065
1065
  if (this.appCheckToken) {
1066
1066
  options.headers['X-Firebase-AppCheck'] = this.appCheckToken;
@@ -1298,7 +1298,7 @@ var WebSocketConnection = /** @class */ (function () {
1298
1298
  }());
1299
1299
 
1300
1300
  var name = "@firebase/database";
1301
- var version = "0.13.10";
1301
+ var version = "0.14.0";
1302
1302
 
1303
1303
  /**
1304
1304
  * @license
@@ -1354,7 +1354,7 @@ var AppCheckTokenProvider = /** @class */ (function () {
1354
1354
  (_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(function (appCheck) { return appCheck.addTokenListener(listener); });
1355
1355
  };
1356
1356
  AppCheckTokenProvider.prototype.notifyForInvalidToken = function () {
1357
- warn("Provided AppCheck credentials for the app named \"" + this.appName_ + "\" " +
1357
+ warn("Provided AppCheck credentials for the app named \"".concat(this.appName_, "\" ") +
1358
1358
  'are invalid. This usually indicates your app was not initialized correctly.');
1359
1359
  };
1360
1360
  return AppCheckTokenProvider;
@@ -2367,7 +2367,7 @@ var Connection = /** @class */ (function () {
2367
2367
  this.lastSessionId = lastSessionId;
2368
2368
  this.connectionCount = 0;
2369
2369
  this.pendingDataMessages = [];
2370
- this.state_ = 0 /* CONNECTING */;
2370
+ this.state_ = 0 /* RealtimeState.CONNECTING */;
2371
2371
  this.log_ = logWrapper('c:' + this.id + ':');
2372
2372
  this.transportManager_ = new TransportManager(repoInfo_);
2373
2373
  this.log_('Connection created');
@@ -2450,7 +2450,7 @@ var Connection = /** @class */ (function () {
2450
2450
  Connection.prototype.connReceiver_ = function (conn) {
2451
2451
  var _this = this;
2452
2452
  return function (message) {
2453
- if (_this.state_ !== 2 /* DISCONNECTED */) {
2453
+ if (_this.state_ !== 2 /* RealtimeState.DISCONNECTED */) {
2454
2454
  if (conn === _this.rx_) {
2455
2455
  _this.onPrimaryMessageReceived_(message);
2456
2456
  }
@@ -2616,7 +2616,7 @@ var Connection = /** @class */ (function () {
2616
2616
  this.sessionId = handshake.s;
2617
2617
  this.repoInfo_.host = host;
2618
2618
  // if we've already closed the connection, then don't bother trying to progress further
2619
- if (this.state_ === 0 /* CONNECTING */) {
2619
+ if (this.state_ === 0 /* RealtimeState.CONNECTING */) {
2620
2620
  this.conn_.start();
2621
2621
  this.onConnectionEstablished_(this.conn_, timestamp);
2622
2622
  if (PROTOCOL_VERSION !== version) {
@@ -2655,7 +2655,7 @@ var Connection = /** @class */ (function () {
2655
2655
  this.repoInfo_.host = host;
2656
2656
  // TODO: if we're already "connected", we need to trigger a disconnect at the next layer up.
2657
2657
  // We don't currently support resets after the connection has already been established
2658
- if (this.state_ === 1 /* CONNECTED */) {
2658
+ if (this.state_ === 1 /* RealtimeState.CONNECTED */) {
2659
2659
  this.close();
2660
2660
  }
2661
2661
  else {
@@ -2668,7 +2668,7 @@ var Connection = /** @class */ (function () {
2668
2668
  var _this = this;
2669
2669
  this.log_('Realtime connection established.');
2670
2670
  this.conn_ = conn;
2671
- this.state_ = 1 /* CONNECTED */;
2671
+ this.state_ = 1 /* RealtimeState.CONNECTED */;
2672
2672
  if (this.onReady_) {
2673
2673
  this.onReady_(timestamp, this.sessionId);
2674
2674
  this.onReady_ = null;
@@ -2687,7 +2687,7 @@ var Connection = /** @class */ (function () {
2687
2687
  };
2688
2688
  Connection.prototype.sendPingOnPrimaryIfNecessary_ = function () {
2689
2689
  // If the connection isn't considered healthy yet, we'll send a noop ping packet request.
2690
- if (!this.isHealthy_ && this.state_ === 1 /* CONNECTED */) {
2690
+ if (!this.isHealthy_ && this.state_ === 1 /* RealtimeState.CONNECTED */) {
2691
2691
  this.log_('sending ping on primary.');
2692
2692
  this.sendData_({ t: 'c', d: { t: PING, d: {} } });
2693
2693
  }
@@ -2708,7 +2708,7 @@ var Connection = /** @class */ (function () {
2708
2708
  this.conn_ = null;
2709
2709
  // NOTE: IF you're seeing a Firefox error for this line, I think it might be because it's getting
2710
2710
  // called on window close and RealtimeState.CONNECTING is no longer defined. Just a guess.
2711
- if (!everConnected && this.state_ === 0 /* CONNECTING */) {
2711
+ if (!everConnected && this.state_ === 0 /* RealtimeState.CONNECTING */) {
2712
2712
  this.log_('Realtime connection failed.');
2713
2713
  // Since we failed to connect at all, clear any cached entry for this namespace in case the machine went away
2714
2714
  if (this.repoInfo_.isCacheableHost()) {
@@ -2717,7 +2717,7 @@ var Connection = /** @class */ (function () {
2717
2717
  this.repoInfo_.internalHost = this.repoInfo_.host;
2718
2718
  }
2719
2719
  }
2720
- else if (this.state_ === 1 /* CONNECTED */) {
2720
+ else if (this.state_ === 1 /* RealtimeState.CONNECTED */) {
2721
2721
  this.log_('Realtime connection lost.');
2722
2722
  }
2723
2723
  this.close();
@@ -2734,7 +2734,7 @@ var Connection = /** @class */ (function () {
2734
2734
  this.close();
2735
2735
  };
2736
2736
  Connection.prototype.sendData_ = function (data) {
2737
- if (this.state_ !== 1 /* CONNECTED */) {
2737
+ if (this.state_ !== 1 /* RealtimeState.CONNECTED */) {
2738
2738
  throw 'Connection is not connected';
2739
2739
  }
2740
2740
  else {
@@ -2745,9 +2745,9 @@ var Connection = /** @class */ (function () {
2745
2745
  * Cleans up this connection, calling the appropriate callbacks
2746
2746
  */
2747
2747
  Connection.prototype.close = function () {
2748
- if (this.state_ !== 2 /* DISCONNECTED */) {
2748
+ if (this.state_ !== 2 /* RealtimeState.DISCONNECTED */) {
2749
2749
  this.log_('Closing realtime connection.');
2750
- this.state_ = 2 /* DISCONNECTED */;
2750
+ this.state_ = 2 /* RealtimeState.DISCONNECTED */;
2751
2751
  this.closeConnections_();
2752
2752
  if (this.onDisconnect_) {
2753
2753
  this.onDisconnect_();
@@ -2853,7 +2853,7 @@ var EventEmitter = /** @class */ (function () {
2853
2853
  }
2854
2854
  if (Array.isArray(this.listeners_[eventType])) {
2855
2855
  // Clone the list, since callbacks could add/remove listeners.
2856
- var listeners = tslib.__spreadArray([], tslib.__read(this.listeners_[eventType]));
2856
+ var listeners = tslib.__spreadArray([], tslib.__read(this.listeners_[eventType]), false);
2857
2857
  for (var i = 0; i < listeners.length; i++) {
2858
2858
  listeners[i].callback.apply(listeners[i].context, varArgs);
2859
2859
  }
@@ -3498,8 +3498,8 @@ var PersistentConnection = /** @class */ (function (_super) {
3498
3498
  var indexSpec = '".indexOn": "' + query._queryParams.getIndex().toString() + '"';
3499
3499
  var indexPath = query._path.toString();
3500
3500
  warn("Using an unspecified index. Your data will be downloaded and " +
3501
- ("filtered on the client. Consider adding " + indexSpec + " at ") +
3502
- (indexPath + " to your security rules for better performance."));
3501
+ "filtered on the client. Consider adding ".concat(indexSpec, " at ") +
3502
+ "".concat(indexPath, " to your security rules for better performance."));
3503
3503
  }
3504
3504
  }
3505
3505
  };
@@ -6178,153 +6178,6 @@ var ValueIndex = /** @class */ (function (_super) {
6178
6178
  }(Index));
6179
6179
  var VALUE_INDEX = new ValueIndex();
6180
6180
 
6181
- /**
6182
- * @license
6183
- * Copyright 2017 Google LLC
6184
- *
6185
- * Licensed under the Apache License, Version 2.0 (the "License");
6186
- * you may not use this file except in compliance with the License.
6187
- * You may obtain a copy of the License at
6188
- *
6189
- * http://www.apache.org/licenses/LICENSE-2.0
6190
- *
6191
- * Unless required by applicable law or agreed to in writing, software
6192
- * distributed under the License is distributed on an "AS IS" BASIS,
6193
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6194
- * See the License for the specific language governing permissions and
6195
- * limitations under the License.
6196
- */
6197
- // Modeled after base64 web-safe chars, but ordered by ASCII.
6198
- var PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
6199
- var MIN_PUSH_CHAR = '-';
6200
- var MAX_PUSH_CHAR = 'z';
6201
- var MAX_KEY_LEN = 786;
6202
- /**
6203
- * Fancy ID generator that creates 20-character string identifiers with the
6204
- * following properties:
6205
- *
6206
- * 1. They're based on timestamp so that they sort *after* any existing ids.
6207
- * 2. They contain 72-bits of random data after the timestamp so that IDs won't
6208
- * collide with other clients' IDs.
6209
- * 3. They sort *lexicographically* (so the timestamp is converted to characters
6210
- * that will sort properly).
6211
- * 4. They're monotonically increasing. Even if you generate more than one in
6212
- * the same timestamp, the latter ones will sort after the former ones. We do
6213
- * this by using the previous random bits but "incrementing" them by 1 (only
6214
- * in the case of a timestamp collision).
6215
- */
6216
- var nextPushId = (function () {
6217
- // Timestamp of last push, used to prevent local collisions if you push twice
6218
- // in one ms.
6219
- var lastPushTime = 0;
6220
- // We generate 72-bits of randomness which get turned into 12 characters and
6221
- // appended to the timestamp to prevent collisions with other clients. We
6222
- // store the last characters we generated because in the event of a collision,
6223
- // we'll use those same characters except "incremented" by one.
6224
- var lastRandChars = [];
6225
- return function (now) {
6226
- var duplicateTime = now === lastPushTime;
6227
- lastPushTime = now;
6228
- var i;
6229
- var timeStampChars = new Array(8);
6230
- for (i = 7; i >= 0; i--) {
6231
- timeStampChars[i] = PUSH_CHARS.charAt(now % 64);
6232
- // NOTE: Can't use << here because javascript will convert to int and lose
6233
- // the upper bits.
6234
- now = Math.floor(now / 64);
6235
- }
6236
- util.assert(now === 0, 'Cannot push at time == 0');
6237
- var id = timeStampChars.join('');
6238
- if (!duplicateTime) {
6239
- for (i = 0; i < 12; i++) {
6240
- lastRandChars[i] = Math.floor(Math.random() * 64);
6241
- }
6242
- }
6243
- else {
6244
- // If the timestamp hasn't changed since last push, use the same random
6245
- // number, except incremented by 1.
6246
- for (i = 11; i >= 0 && lastRandChars[i] === 63; i--) {
6247
- lastRandChars[i] = 0;
6248
- }
6249
- lastRandChars[i]++;
6250
- }
6251
- for (i = 0; i < 12; i++) {
6252
- id += PUSH_CHARS.charAt(lastRandChars[i]);
6253
- }
6254
- util.assert(id.length === 20, 'nextPushId: Length should be 20.');
6255
- return id;
6256
- };
6257
- })();
6258
- var successor = function (key) {
6259
- if (key === '' + INTEGER_32_MAX) {
6260
- // See https://firebase.google.com/docs/database/web/lists-of-data#data-order
6261
- return MIN_PUSH_CHAR;
6262
- }
6263
- var keyAsInt = tryParseInt(key);
6264
- if (keyAsInt != null) {
6265
- return '' + (keyAsInt + 1);
6266
- }
6267
- var next = new Array(key.length);
6268
- for (var i_1 = 0; i_1 < next.length; i_1++) {
6269
- next[i_1] = key.charAt(i_1);
6270
- }
6271
- if (next.length < MAX_KEY_LEN) {
6272
- next.push(MIN_PUSH_CHAR);
6273
- return next.join('');
6274
- }
6275
- var i = next.length - 1;
6276
- while (i >= 0 && next[i] === MAX_PUSH_CHAR) {
6277
- i--;
6278
- }
6279
- // `successor` was called on the largest possible key, so return the
6280
- // MAX_NAME, which sorts larger than all keys.
6281
- if (i === -1) {
6282
- return MAX_NAME;
6283
- }
6284
- var source = next[i];
6285
- var sourcePlusOne = PUSH_CHARS.charAt(PUSH_CHARS.indexOf(source) + 1);
6286
- next[i] = sourcePlusOne;
6287
- return next.slice(0, i + 1).join('');
6288
- };
6289
- // `key` is assumed to be non-empty.
6290
- var predecessor = function (key) {
6291
- if (key === '' + INTEGER_32_MIN) {
6292
- return MIN_NAME;
6293
- }
6294
- var keyAsInt = tryParseInt(key);
6295
- if (keyAsInt != null) {
6296
- return '' + (keyAsInt - 1);
6297
- }
6298
- var next = new Array(key.length);
6299
- for (var i = 0; i < next.length; i++) {
6300
- next[i] = key.charAt(i);
6301
- }
6302
- // If `key` ends in `MIN_PUSH_CHAR`, the largest key lexicographically
6303
- // smaller than `key`, is `key[0:key.length - 1]`. The next key smaller
6304
- // than that, `predecessor(predecessor(key))`, is
6305
- //
6306
- // `key[0:key.length - 2] + (key[key.length - 1] - 1) + \
6307
- // { MAX_PUSH_CHAR repeated MAX_KEY_LEN - (key.length - 1) times }
6308
- //
6309
- // analogous to increment/decrement for base-10 integers.
6310
- //
6311
- // This works because lexigographic comparison works character-by-character,
6312
- // using length as a tie-breaker if one key is a prefix of the other.
6313
- if (next[next.length - 1] === MIN_PUSH_CHAR) {
6314
- if (next.length === 1) {
6315
- // See https://firebase.google.com/docs/database/web/lists-of-data#orderbykey
6316
- return '' + INTEGER_32_MAX;
6317
- }
6318
- delete next[next.length - 1];
6319
- return next.join('');
6320
- }
6321
- // Replace the last character with it's immediate predecessor, and
6322
- // fill the suffix of the key with MAX_PUSH_CHAR. This is the
6323
- // lexicographically largest possible key smaller than `key`.
6324
- next[next.length - 1] = PUSH_CHARS.charAt(PUSH_CHARS.indexOf(next[next.length - 1]) - 1);
6325
- return next.join('') + MAX_PUSH_CHAR.repeat(MAX_KEY_LEN - next.length);
6326
- };
6327
-
6328
6181
  /**
6329
6182
  * @license
6330
6183
  * Copyright 2017 Google LLC
@@ -6342,24 +6195,24 @@ var predecessor = function (key) {
6342
6195
  * limitations under the License.
6343
6196
  */
6344
6197
  function changeValue(snapshotNode) {
6345
- return { type: "value" /* VALUE */, snapshotNode: snapshotNode };
6198
+ return { type: "value" /* ChangeType.VALUE */, snapshotNode: snapshotNode };
6346
6199
  }
6347
6200
  function changeChildAdded(childName, snapshotNode) {
6348
- return { type: "child_added" /* CHILD_ADDED */, snapshotNode: snapshotNode, childName: childName };
6201
+ return { type: "child_added" /* ChangeType.CHILD_ADDED */, snapshotNode: snapshotNode, childName: childName };
6349
6202
  }
6350
6203
  function changeChildRemoved(childName, snapshotNode) {
6351
- return { type: "child_removed" /* CHILD_REMOVED */, snapshotNode: snapshotNode, childName: childName };
6204
+ return { type: "child_removed" /* ChangeType.CHILD_REMOVED */, snapshotNode: snapshotNode, childName: childName };
6352
6205
  }
6353
6206
  function changeChildChanged(childName, snapshotNode, oldSnap) {
6354
6207
  return {
6355
- type: "child_changed" /* CHILD_CHANGED */,
6208
+ type: "child_changed" /* ChangeType.CHILD_CHANGED */,
6356
6209
  snapshotNode: snapshotNode,
6357
6210
  childName: childName,
6358
6211
  oldSnap: oldSnap
6359
6212
  };
6360
6213
  }
6361
6214
  function changeChildMoved(childName, snapshotNode) {
6362
- return { type: "child_moved" /* CHILD_MOVED */, snapshotNode: snapshotNode, childName: childName };
6215
+ return { type: "child_moved" /* ChangeType.CHILD_MOVED */, snapshotNode: snapshotNode, childName: childName };
6363
6216
  }
6364
6217
 
6365
6218
  /**
@@ -6494,6 +6347,8 @@ var RangedFilter = /** @class */ (function () {
6494
6347
  this.index_ = params.getIndex();
6495
6348
  this.startPost_ = RangedFilter.getStartPost_(params);
6496
6349
  this.endPost_ = RangedFilter.getEndPost_(params);
6350
+ this.startIsInclusive_ = !params.startAfterSet_;
6351
+ this.endIsInclusive_ = !params.endBeforeSet_;
6497
6352
  }
6498
6353
  RangedFilter.prototype.getStartPost = function () {
6499
6354
  return this.startPost_;
@@ -6502,8 +6357,13 @@ var RangedFilter = /** @class */ (function () {
6502
6357
  return this.endPost_;
6503
6358
  };
6504
6359
  RangedFilter.prototype.matches = function (node) {
6505
- return (this.index_.compare(this.getStartPost(), node) <= 0 &&
6506
- this.index_.compare(node, this.getEndPost()) <= 0);
6360
+ var isWithinStart = this.startIsInclusive_
6361
+ ? this.index_.compare(this.getStartPost(), node) <= 0
6362
+ : this.index_.compare(this.getStartPost(), node) < 0;
6363
+ var isWithinEnd = this.endIsInclusive_
6364
+ ? this.index_.compare(node, this.getEndPost()) <= 0
6365
+ : this.index_.compare(node, this.getEndPost()) < 0;
6366
+ return isWithinStart && isWithinEnd;
6507
6367
  };
6508
6368
  RangedFilter.prototype.updateChild = function (snap, key, newChild, affectedPath, source, optChangeAccumulator) {
6509
6369
  if (!this.matches(new NamedNode(key, newChild))) {
@@ -6582,10 +6442,27 @@ var RangedFilter = /** @class */ (function () {
6582
6442
  */
6583
6443
  var LimitedFilter = /** @class */ (function () {
6584
6444
  function LimitedFilter(params) {
6445
+ var _this = this;
6446
+ this.withinDirectionalStart = function (node) {
6447
+ return _this.reverse_ ? _this.withinEndPost(node) : _this.withinStartPost(node);
6448
+ };
6449
+ this.withinDirectionalEnd = function (node) {
6450
+ return _this.reverse_ ? _this.withinStartPost(node) : _this.withinEndPost(node);
6451
+ };
6452
+ this.withinStartPost = function (node) {
6453
+ var compareRes = _this.index_.compare(_this.rangedFilter_.getStartPost(), node);
6454
+ return _this.startIsInclusive_ ? compareRes <= 0 : compareRes < 0;
6455
+ };
6456
+ this.withinEndPost = function (node) {
6457
+ var compareRes = _this.index_.compare(node, _this.rangedFilter_.getEndPost());
6458
+ return _this.endIsInclusive_ ? compareRes <= 0 : compareRes < 0;
6459
+ };
6585
6460
  this.rangedFilter_ = new RangedFilter(params);
6586
6461
  this.index_ = params.getIndex();
6587
6462
  this.limit_ = params.getLimit();
6588
6463
  this.reverse_ = !params.isViewFromLeft();
6464
+ this.startIsInclusive_ = !params.startAfterSet_;
6465
+ this.endIsInclusive_ = !params.endBeforeSet_;
6589
6466
  }
6590
6467
  LimitedFilter.prototype.updateChild = function (snap, key, newChild, affectedPath, source, optChangeAccumulator) {
6591
6468
  if (!this.rangedFilter_.matches(new NamedNode(key, newChild))) {
@@ -6626,23 +6503,18 @@ var LimitedFilter = /** @class */ (function () {
6626
6503
  var count = 0;
6627
6504
  while (iterator.hasNext() && count < this.limit_) {
6628
6505
  var next = iterator.getNext();
6629
- var inRange = void 0;
6630
- if (this.reverse_) {
6631
- inRange =
6632
- this.index_.compare(this.rangedFilter_.getStartPost(), next) <= 0;
6506
+ if (!this.withinDirectionalStart(next)) {
6507
+ // if we have not reached the start, skip to the next element
6508
+ continue;
6633
6509
  }
6634
- else {
6635
- inRange =
6636
- this.index_.compare(next, this.rangedFilter_.getEndPost()) <= 0;
6510
+ else if (!this.withinDirectionalEnd(next)) {
6511
+ // if we have reached the end, stop adding elements
6512
+ break;
6637
6513
  }
6638
- if (inRange) {
6514
+ else {
6639
6515
  filtered = filtered.updateImmediateChild(next.name, next.node);
6640
6516
  count++;
6641
6517
  }
6642
- else {
6643
- // if we have reached the end post, we cannot keep adding elemments
6644
- break;
6645
- }
6646
6518
  }
6647
6519
  }
6648
6520
  else {
@@ -6650,32 +6522,19 @@ var LimitedFilter = /** @class */ (function () {
6650
6522
  filtered = newSnap.withIndex(this.index_);
6651
6523
  // Don't support priorities on queries
6652
6524
  filtered = filtered.updatePriority(ChildrenNode.EMPTY_NODE);
6653
- var startPost = void 0;
6654
- var endPost = void 0;
6655
- var cmp = void 0;
6656
6525
  var iterator = void 0;
6657
6526
  if (this.reverse_) {
6658
6527
  iterator = filtered.getReverseIterator(this.index_);
6659
- startPost = this.rangedFilter_.getEndPost();
6660
- endPost = this.rangedFilter_.getStartPost();
6661
- var indexCompare_1 = this.index_.getCompare();
6662
- cmp = function (a, b) { return indexCompare_1(b, a); };
6663
6528
  }
6664
6529
  else {
6665
6530
  iterator = filtered.getIterator(this.index_);
6666
- startPost = this.rangedFilter_.getStartPost();
6667
- endPost = this.rangedFilter_.getEndPost();
6668
- cmp = this.index_.getCompare();
6669
6531
  }
6670
6532
  var count = 0;
6671
- var foundStartPost = false;
6672
6533
  while (iterator.hasNext()) {
6673
6534
  var next = iterator.getNext();
6674
- if (!foundStartPost && cmp(startPost, next) <= 0) {
6675
- // start adding
6676
- foundStartPost = true;
6677
- }
6678
- var inRange = foundStartPost && count < this.limit_ && cmp(next, endPost) <= 0;
6535
+ var inRange = count < this.limit_ &&
6536
+ this.withinDirectionalStart(next) &&
6537
+ this.withinDirectionalEnd(next);
6679
6538
  if (inRange) {
6680
6539
  count++;
6681
6540
  }
@@ -6807,10 +6666,10 @@ var QueryParams = /** @class */ (function () {
6807
6666
  this.limitSet_ = false;
6808
6667
  this.startSet_ = false;
6809
6668
  this.startNameSet_ = false;
6810
- this.startAfterSet_ = false;
6669
+ this.startAfterSet_ = false; // can only be true if startSet_ is true
6811
6670
  this.endSet_ = false;
6812
6671
  this.endNameSet_ = false;
6813
- this.endBeforeSet_ = false;
6672
+ this.endBeforeSet_ = false; // can only be true if endSet_ is true
6814
6673
  this.limit_ = 0;
6815
6674
  this.viewFrom_ = '';
6816
6675
  this.indexStartValue_ = null;
@@ -6822,12 +6681,6 @@ var QueryParams = /** @class */ (function () {
6822
6681
  QueryParams.prototype.hasStart = function () {
6823
6682
  return this.startSet_;
6824
6683
  };
6825
- QueryParams.prototype.hasStartAfter = function () {
6826
- return this.startAfterSet_;
6827
- };
6828
- QueryParams.prototype.hasEndBefore = function () {
6829
- return this.endBeforeSet_;
6830
- };
6831
6684
  /**
6832
6685
  * @returns True if it would return from left.
6833
6686
  */
@@ -6840,7 +6693,7 @@ var QueryParams = /** @class */ (function () {
6840
6693
  return this.startSet_;
6841
6694
  }
6842
6695
  else {
6843
- return this.viewFrom_ === "l" /* VIEW_FROM_LEFT */;
6696
+ return this.viewFrom_ === "l" /* WIRE_PROTOCOL_CONSTANTS.VIEW_FROM_LEFT */;
6844
6697
  }
6845
6698
  };
6846
6699
  /**
@@ -6916,10 +6769,12 @@ var QueryParams = /** @class */ (function () {
6916
6769
  copy.limitSet_ = this.limitSet_;
6917
6770
  copy.limit_ = this.limit_;
6918
6771
  copy.startSet_ = this.startSet_;
6772
+ copy.startAfterSet_ = this.startAfterSet_;
6919
6773
  copy.indexStartValue_ = this.indexStartValue_;
6920
6774
  copy.startNameSet_ = this.startNameSet_;
6921
6775
  copy.indexStartName_ = this.indexStartName_;
6922
6776
  copy.endSet_ = this.endSet_;
6777
+ copy.endBeforeSet_ = this.endBeforeSet_;
6923
6778
  copy.indexEndValue_ = this.indexEndValue_;
6924
6779
  copy.endNameSet_ = this.endNameSet_;
6925
6780
  copy.indexEndName_ = this.indexEndName_;
@@ -6944,14 +6799,14 @@ function queryParamsLimitToFirst(queryParams, newLimit) {
6944
6799
  var newParams = queryParams.copy();
6945
6800
  newParams.limitSet_ = true;
6946
6801
  newParams.limit_ = newLimit;
6947
- newParams.viewFrom_ = "l" /* VIEW_FROM_LEFT */;
6802
+ newParams.viewFrom_ = "l" /* WIRE_PROTOCOL_CONSTANTS.VIEW_FROM_LEFT */;
6948
6803
  return newParams;
6949
6804
  }
6950
6805
  function queryParamsLimitToLast(queryParams, newLimit) {
6951
6806
  var newParams = queryParams.copy();
6952
6807
  newParams.limitSet_ = true;
6953
6808
  newParams.limit_ = newLimit;
6954
- newParams.viewFrom_ = "r" /* VIEW_FROM_RIGHT */;
6809
+ newParams.viewFrom_ = "r" /* WIRE_PROTOCOL_CONSTANTS.VIEW_FROM_RIGHT */;
6955
6810
  return newParams;
6956
6811
  }
6957
6812
  function queryParamsStartAt(queryParams, indexValue, key) {
@@ -6973,21 +6828,11 @@ function queryParamsStartAt(queryParams, indexValue, key) {
6973
6828
  }
6974
6829
  function queryParamsStartAfter(queryParams, indexValue, key) {
6975
6830
  var params;
6976
- if (queryParams.index_ === KEY_INDEX) {
6977
- if (typeof indexValue === 'string') {
6978
- indexValue = successor(indexValue);
6979
- }
6831
+ if (queryParams.index_ === KEY_INDEX || !!key) {
6980
6832
  params = queryParamsStartAt(queryParams, indexValue, key);
6981
6833
  }
6982
6834
  else {
6983
- var childKey = void 0;
6984
- if (key == null) {
6985
- childKey = MAX_NAME;
6986
- }
6987
- else {
6988
- childKey = successor(key);
6989
- }
6990
- params = queryParamsStartAt(queryParams, indexValue, childKey);
6835
+ params = queryParamsStartAt(queryParams, indexValue, MAX_NAME);
6991
6836
  }
6992
6837
  params.startAfterSet_ = true;
6993
6838
  return params;
@@ -7010,22 +6855,12 @@ function queryParamsEndAt(queryParams, indexValue, key) {
7010
6855
  return newParams;
7011
6856
  }
7012
6857
  function queryParamsEndBefore(queryParams, indexValue, key) {
7013
- var childKey;
7014
6858
  var params;
7015
- if (queryParams.index_ === KEY_INDEX) {
7016
- if (typeof indexValue === 'string') {
7017
- indexValue = predecessor(indexValue);
7018
- }
6859
+ if (queryParams.index_ === KEY_INDEX || !!key) {
7019
6860
  params = queryParamsEndAt(queryParams, indexValue, key);
7020
6861
  }
7021
6862
  else {
7022
- if (key == null) {
7023
- childKey = MIN_NAME;
7024
- }
7025
- else {
7026
- childKey = predecessor(key);
7027
- }
7028
- params = queryParamsEndAt(queryParams, indexValue, childKey);
6863
+ params = queryParamsEndAt(queryParams, indexValue, MIN_NAME);
7029
6864
  }
7030
6865
  params.endBeforeSet_ = true;
7031
6866
  return params;
@@ -7047,39 +6882,43 @@ function queryParamsToRestQueryStringParameters(queryParams) {
7047
6882
  }
7048
6883
  var orderBy;
7049
6884
  if (queryParams.index_ === PRIORITY_INDEX) {
7050
- orderBy = "$priority" /* PRIORITY_INDEX */;
6885
+ orderBy = "$priority" /* REST_QUERY_CONSTANTS.PRIORITY_INDEX */;
7051
6886
  }
7052
6887
  else if (queryParams.index_ === VALUE_INDEX) {
7053
- orderBy = "$value" /* VALUE_INDEX */;
6888
+ orderBy = "$value" /* REST_QUERY_CONSTANTS.VALUE_INDEX */;
7054
6889
  }
7055
6890
  else if (queryParams.index_ === KEY_INDEX) {
7056
- orderBy = "$key" /* KEY_INDEX */;
6891
+ orderBy = "$key" /* REST_QUERY_CONSTANTS.KEY_INDEX */;
7057
6892
  }
7058
6893
  else {
7059
6894
  util.assert(queryParams.index_ instanceof PathIndex, 'Unrecognized index type!');
7060
6895
  orderBy = queryParams.index_.toString();
7061
6896
  }
7062
- qs["orderBy" /* ORDER_BY */] = util.stringify(orderBy);
6897
+ qs["orderBy" /* REST_QUERY_CONSTANTS.ORDER_BY */] = util.stringify(orderBy);
7063
6898
  if (queryParams.startSet_) {
7064
- qs["startAt" /* START_AT */] = util.stringify(queryParams.indexStartValue_);
6899
+ var startParam = queryParams.startAfterSet_
6900
+ ? "startAfter" /* REST_QUERY_CONSTANTS.START_AFTER */
6901
+ : "startAt" /* REST_QUERY_CONSTANTS.START_AT */;
6902
+ qs[startParam] = util.stringify(queryParams.indexStartValue_);
7065
6903
  if (queryParams.startNameSet_) {
7066
- qs["startAt" /* START_AT */] +=
7067
- ',' + util.stringify(queryParams.indexStartName_);
6904
+ qs[startParam] += ',' + util.stringify(queryParams.indexStartName_);
7068
6905
  }
7069
6906
  }
7070
6907
  if (queryParams.endSet_) {
7071
- qs["endAt" /* END_AT */] = util.stringify(queryParams.indexEndValue_);
6908
+ var endParam = queryParams.endBeforeSet_
6909
+ ? "endBefore" /* REST_QUERY_CONSTANTS.END_BEFORE */
6910
+ : "endAt" /* REST_QUERY_CONSTANTS.END_AT */;
6911
+ qs[endParam] = util.stringify(queryParams.indexEndValue_);
7072
6912
  if (queryParams.endNameSet_) {
7073
- qs["endAt" /* END_AT */] +=
7074
- ',' + util.stringify(queryParams.indexEndName_);
6913
+ qs[endParam] += ',' + util.stringify(queryParams.indexEndName_);
7075
6914
  }
7076
6915
  }
7077
6916
  if (queryParams.limitSet_) {
7078
6917
  if (queryParams.isViewFromLeft()) {
7079
- qs["limitToFirst" /* LIMIT_TO_FIRST */] = queryParams.limit_;
6918
+ qs["limitToFirst" /* REST_QUERY_CONSTANTS.LIMIT_TO_FIRST */] = queryParams.limit_;
7080
6919
  }
7081
6920
  else {
7082
- qs["limitToLast" /* LIMIT_TO_LAST */] = queryParams.limit_;
6921
+ qs["limitToLast" /* REST_QUERY_CONSTANTS.LIMIT_TO_LAST */] = queryParams.limit_;
7083
6922
  }
7084
6923
  }
7085
6924
  return qs;
@@ -7087,35 +6926,39 @@ function queryParamsToRestQueryStringParameters(queryParams) {
7087
6926
  function queryParamsGetQueryObject(queryParams) {
7088
6927
  var obj = {};
7089
6928
  if (queryParams.startSet_) {
7090
- obj["sp" /* INDEX_START_VALUE */] =
6929
+ obj["sp" /* WIRE_PROTOCOL_CONSTANTS.INDEX_START_VALUE */] =
7091
6930
  queryParams.indexStartValue_;
7092
6931
  if (queryParams.startNameSet_) {
7093
- obj["sn" /* INDEX_START_NAME */] =
6932
+ obj["sn" /* WIRE_PROTOCOL_CONSTANTS.INDEX_START_NAME */] =
7094
6933
  queryParams.indexStartName_;
7095
6934
  }
6935
+ obj["sin" /* WIRE_PROTOCOL_CONSTANTS.INDEX_START_IS_INCLUSIVE */] =
6936
+ !queryParams.startAfterSet_;
7096
6937
  }
7097
6938
  if (queryParams.endSet_) {
7098
- obj["ep" /* INDEX_END_VALUE */] = queryParams.indexEndValue_;
6939
+ obj["ep" /* WIRE_PROTOCOL_CONSTANTS.INDEX_END_VALUE */] = queryParams.indexEndValue_;
7099
6940
  if (queryParams.endNameSet_) {
7100
- obj["en" /* INDEX_END_NAME */] = queryParams.indexEndName_;
6941
+ obj["en" /* WIRE_PROTOCOL_CONSTANTS.INDEX_END_NAME */] = queryParams.indexEndName_;
7101
6942
  }
6943
+ obj["ein" /* WIRE_PROTOCOL_CONSTANTS.INDEX_END_IS_INCLUSIVE */] =
6944
+ !queryParams.endBeforeSet_;
7102
6945
  }
7103
6946
  if (queryParams.limitSet_) {
7104
- obj["l" /* LIMIT */] = queryParams.limit_;
6947
+ obj["l" /* WIRE_PROTOCOL_CONSTANTS.LIMIT */] = queryParams.limit_;
7105
6948
  var viewFrom = queryParams.viewFrom_;
7106
6949
  if (viewFrom === '') {
7107
6950
  if (queryParams.isViewFromLeft()) {
7108
- viewFrom = "l" /* VIEW_FROM_LEFT */;
6951
+ viewFrom = "l" /* WIRE_PROTOCOL_CONSTANTS.VIEW_FROM_LEFT */;
7109
6952
  }
7110
6953
  else {
7111
- viewFrom = "r" /* VIEW_FROM_RIGHT */;
6954
+ viewFrom = "r" /* WIRE_PROTOCOL_CONSTANTS.VIEW_FROM_RIGHT */;
7112
6955
  }
7113
6956
  }
7114
- obj["vf" /* VIEW_FROM */] = viewFrom;
6957
+ obj["vf" /* WIRE_PROTOCOL_CONSTANTS.VIEW_FROM */] = viewFrom;
7115
6958
  }
7116
6959
  // For now, priority index is the default, so we only specify if it's some other index
7117
6960
  if (queryParams.index_ !== PRIORITY_INDEX) {
7118
- obj["i" /* INDEX */] = queryParams.index_.toString();
6961
+ obj["i" /* WIRE_PROTOCOL_CONSTANTS.INDEX */] = queryParams.index_.toString();
7119
6962
  }
7120
6963
  return obj;
7121
6964
  }
@@ -7877,16 +7720,16 @@ function eventGeneratorGenerateEventsForChanges(eventGenerator, changes, eventCa
7877
7720
  var events = [];
7878
7721
  var moves = [];
7879
7722
  changes.forEach(function (change) {
7880
- if (change.type === "child_changed" /* CHILD_CHANGED */ &&
7723
+ if (change.type === "child_changed" /* ChangeType.CHILD_CHANGED */ &&
7881
7724
  eventGenerator.index_.indexedValueChanged(change.oldSnap, change.snapshotNode)) {
7882
7725
  moves.push(changeChildMoved(change.childName, change.snapshotNode));
7883
7726
  }
7884
7727
  });
7885
- eventGeneratorGenerateEventsForType(eventGenerator, events, "child_removed" /* CHILD_REMOVED */, changes, eventRegistrations, eventCache);
7886
- eventGeneratorGenerateEventsForType(eventGenerator, events, "child_added" /* CHILD_ADDED */, changes, eventRegistrations, eventCache);
7887
- eventGeneratorGenerateEventsForType(eventGenerator, events, "child_moved" /* CHILD_MOVED */, moves, eventRegistrations, eventCache);
7888
- eventGeneratorGenerateEventsForType(eventGenerator, events, "child_changed" /* CHILD_CHANGED */, changes, eventRegistrations, eventCache);
7889
- eventGeneratorGenerateEventsForType(eventGenerator, events, "value" /* VALUE */, changes, eventRegistrations, eventCache);
7728
+ eventGeneratorGenerateEventsForType(eventGenerator, events, "child_removed" /* ChangeType.CHILD_REMOVED */, changes, eventRegistrations, eventCache);
7729
+ eventGeneratorGenerateEventsForType(eventGenerator, events, "child_added" /* ChangeType.CHILD_ADDED */, changes, eventRegistrations, eventCache);
7730
+ eventGeneratorGenerateEventsForType(eventGenerator, events, "child_moved" /* ChangeType.CHILD_MOVED */, moves, eventRegistrations, eventCache);
7731
+ eventGeneratorGenerateEventsForType(eventGenerator, events, "child_changed" /* ChangeType.CHILD_CHANGED */, changes, eventRegistrations, eventCache);
7732
+ eventGeneratorGenerateEventsForType(eventGenerator, events, "value" /* ChangeType.VALUE */, changes, eventRegistrations, eventCache);
7890
7733
  return events;
7891
7734
  }
7892
7735
  /**
@@ -8972,31 +8815,31 @@ var ChildChangeAccumulator = /** @class */ (function () {
8972
8815
  ChildChangeAccumulator.prototype.trackChildChange = function (change) {
8973
8816
  var type = change.type;
8974
8817
  var childKey = change.childName;
8975
- util.assert(type === "child_added" /* CHILD_ADDED */ ||
8976
- type === "child_changed" /* CHILD_CHANGED */ ||
8977
- type === "child_removed" /* CHILD_REMOVED */, 'Only child changes supported for tracking');
8818
+ util.assert(type === "child_added" /* ChangeType.CHILD_ADDED */ ||
8819
+ type === "child_changed" /* ChangeType.CHILD_CHANGED */ ||
8820
+ type === "child_removed" /* ChangeType.CHILD_REMOVED */, 'Only child changes supported for tracking');
8978
8821
  util.assert(childKey !== '.priority', 'Only non-priority child changes can be tracked.');
8979
8822
  var oldChange = this.changeMap.get(childKey);
8980
8823
  if (oldChange) {
8981
8824
  var oldType = oldChange.type;
8982
- if (type === "child_added" /* CHILD_ADDED */ &&
8983
- oldType === "child_removed" /* CHILD_REMOVED */) {
8825
+ if (type === "child_added" /* ChangeType.CHILD_ADDED */ &&
8826
+ oldType === "child_removed" /* ChangeType.CHILD_REMOVED */) {
8984
8827
  this.changeMap.set(childKey, changeChildChanged(childKey, change.snapshotNode, oldChange.snapshotNode));
8985
8828
  }
8986
- else if (type === "child_removed" /* CHILD_REMOVED */ &&
8987
- oldType === "child_added" /* CHILD_ADDED */) {
8829
+ else if (type === "child_removed" /* ChangeType.CHILD_REMOVED */ &&
8830
+ oldType === "child_added" /* ChangeType.CHILD_ADDED */) {
8988
8831
  this.changeMap.delete(childKey);
8989
8832
  }
8990
- else if (type === "child_removed" /* CHILD_REMOVED */ &&
8991
- oldType === "child_changed" /* CHILD_CHANGED */) {
8833
+ else if (type === "child_removed" /* ChangeType.CHILD_REMOVED */ &&
8834
+ oldType === "child_changed" /* ChangeType.CHILD_CHANGED */) {
8992
8835
  this.changeMap.set(childKey, changeChildRemoved(childKey, oldChange.oldSnap));
8993
8836
  }
8994
- else if (type === "child_changed" /* CHILD_CHANGED */ &&
8995
- oldType === "child_added" /* CHILD_ADDED */) {
8837
+ else if (type === "child_changed" /* ChangeType.CHILD_CHANGED */ &&
8838
+ oldType === "child_added" /* ChangeType.CHILD_ADDED */) {
8996
8839
  this.changeMap.set(childKey, changeChildAdded(childKey, change.snapshotNode));
8997
8840
  }
8998
- else if (type === "child_changed" /* CHILD_CHANGED */ &&
8999
- oldType === "child_changed" /* CHILD_CHANGED */) {
8841
+ else if (type === "child_changed" /* ChangeType.CHILD_CHANGED */ &&
8842
+ oldType === "child_changed" /* ChangeType.CHILD_CHANGED */) {
9000
8843
  this.changeMap.set(childKey, changeChildChanged(childKey, change.snapshotNode, oldChange.oldSnap));
9001
8844
  }
9002
8845
  else {
@@ -11721,7 +11564,7 @@ function repoLog(repo) {
11721
11564
  if (repo.persistentConnection_) {
11722
11565
  prefix = repo.persistentConnection_.id + ':';
11723
11566
  }
11724
- log.apply(void 0, tslib.__spreadArray([prefix], tslib.__read(varArgs)));
11567
+ log.apply(void 0, tslib.__spreadArray([prefix], tslib.__read(varArgs), false));
11725
11568
  }
11726
11569
  function repoCallOnCompleteCallback(repo, callback, status, errorReason) {
11727
11570
  if (callback) {
@@ -11795,7 +11638,7 @@ function repoStartTransaction(repo, path, transactionUpdate, onComplete, unwatch
11795
11638
  else {
11796
11639
  validateFirebaseData('transaction failed: Data returned ', newVal, transaction.path);
11797
11640
  // Mark as run and add to our queue.
11798
- transaction.status = 0 /* RUN */;
11641
+ transaction.status = 0 /* TransactionStatus.RUN */;
11799
11642
  var queueNode = treeSubTree(repo.transactionQueueTree_, path);
11800
11643
  var nodeQueue = treeGetValue(queueNode) || [];
11801
11644
  nodeQueue.push(transaction);
@@ -11854,7 +11697,7 @@ function repoSendReadyTransactions(repo, node) {
11854
11697
  if (treeGetValue(node)) {
11855
11698
  var queue = repoBuildTransactionQueue(repo, node);
11856
11699
  util.assert(queue.length > 0, 'Sending zero length transaction queue');
11857
- var allRun = queue.every(function (transaction) { return transaction.status === 0 /* RUN */; });
11700
+ var allRun = queue.every(function (transaction) { return transaction.status === 0 /* TransactionStatus.RUN */; });
11858
11701
  // If they're all run (and not sent), we can send them. Else, we must wait.
11859
11702
  if (allRun) {
11860
11703
  repoSendTransactionQueue(repo, treeGetPath(node), queue);
@@ -11883,8 +11726,8 @@ function repoSendTransactionQueue(repo, path, queue) {
11883
11726
  var latestHash = latestState.hash();
11884
11727
  for (var i = 0; i < queue.length; i++) {
11885
11728
  var txn = queue[i];
11886
- util.assert(txn.status === 0 /* RUN */, 'tryToSendTransactionQueue_: items in queue should all be run.');
11887
- txn.status = 1 /* SENT */;
11729
+ util.assert(txn.status === 0 /* TransactionStatus.RUN */, 'tryToSendTransactionQueue_: items in queue should all be run.');
11730
+ txn.status = 1 /* TransactionStatus.SENT */;
11888
11731
  txn.retryCount++;
11889
11732
  var relativePath = newRelativePath(path, txn.path);
11890
11733
  // If we've gotten to this point, the output snapshot must be defined.
@@ -11905,7 +11748,7 @@ function repoSendTransactionQueue(repo, path, queue) {
11905
11748
  // transactions or sets.
11906
11749
  var callbacks = [];
11907
11750
  var _loop_1 = function (i) {
11908
- queue[i].status = 2 /* COMPLETED */;
11751
+ queue[i].status = 2 /* TransactionStatus.COMPLETED */;
11909
11752
  events = events.concat(syncTreeAckUserWrite(repo.serverSyncTree_, queue[i].currentWriteId));
11910
11753
  if (queue[i].onComplete) {
11911
11754
  // We never unset the output snapshot, and given that this
@@ -11933,18 +11776,18 @@ function repoSendTransactionQueue(repo, path, queue) {
11933
11776
  // transactions are no longer sent. Update their status appropriately.
11934
11777
  if (status === 'datastale') {
11935
11778
  for (var i = 0; i < queue.length; i++) {
11936
- if (queue[i].status === 3 /* SENT_NEEDS_ABORT */) {
11937
- queue[i].status = 4 /* NEEDS_ABORT */;
11779
+ if (queue[i].status === 3 /* TransactionStatus.SENT_NEEDS_ABORT */) {
11780
+ queue[i].status = 4 /* TransactionStatus.NEEDS_ABORT */;
11938
11781
  }
11939
11782
  else {
11940
- queue[i].status = 0 /* RUN */;
11783
+ queue[i].status = 0 /* TransactionStatus.RUN */;
11941
11784
  }
11942
11785
  }
11943
11786
  }
11944
11787
  else {
11945
11788
  warn('transaction at ' + pathToSend.toString() + ' failed: ' + status);
11946
11789
  for (var i = 0; i < queue.length; i++) {
11947
- queue[i].status = 4 /* NEEDS_ABORT */;
11790
+ queue[i].status = 4 /* TransactionStatus.NEEDS_ABORT */;
11948
11791
  queue[i].abortReason = status;
11949
11792
  }
11950
11793
  }
@@ -11988,7 +11831,7 @@ function repoRerunTransactionQueue(repo, queue, path) {
11988
11831
  var events = [];
11989
11832
  // Ignore all of the sets we're going to re-run.
11990
11833
  var txnsToRerun = queue.filter(function (q) {
11991
- return q.status === 0 /* RUN */;
11834
+ return q.status === 0 /* TransactionStatus.RUN */;
11992
11835
  });
11993
11836
  var setsToIgnore = txnsToRerun.map(function (q) {
11994
11837
  return q.currentWriteId;
@@ -11998,12 +11841,12 @@ function repoRerunTransactionQueue(repo, queue, path) {
11998
11841
  var relativePath = newRelativePath(path, transaction.path);
11999
11842
  var abortTransaction = false, abortReason;
12000
11843
  util.assert(relativePath !== null, 'rerunTransactionsUnderNode_: relativePath should not be null.');
12001
- if (transaction.status === 4 /* NEEDS_ABORT */) {
11844
+ if (transaction.status === 4 /* TransactionStatus.NEEDS_ABORT */) {
12002
11845
  abortTransaction = true;
12003
11846
  abortReason = transaction.abortReason;
12004
11847
  events = events.concat(syncTreeAckUserWrite(repo.serverSyncTree_, transaction.currentWriteId, true));
12005
11848
  }
12006
- else if (transaction.status === 0 /* RUN */) {
11849
+ else if (transaction.status === 0 /* TransactionStatus.RUN */) {
12007
11850
  if (transaction.retryCount >= MAX_TRANSACTION_RETRIES) {
12008
11851
  abortTransaction = true;
12009
11852
  abortReason = 'maxretry';
@@ -12046,7 +11889,7 @@ function repoRerunTransactionQueue(repo, queue, path) {
12046
11889
  events = [];
12047
11890
  if (abortTransaction) {
12048
11891
  // Abort.
12049
- queue[i].status = 2 /* COMPLETED */;
11892
+ queue[i].status = 2 /* TransactionStatus.COMPLETED */;
12050
11893
  // Removing a listener can trigger pruning which can muck with
12051
11894
  // mergedData/visibleData (as it prunes data). So defer the unwatcher
12052
11895
  // until we're done.
@@ -12134,7 +11977,7 @@ function repoPruneCompletedTransactionsBelowNode(repo, node) {
12134
11977
  if (queue) {
12135
11978
  var to = 0;
12136
11979
  for (var from = 0; from < queue.length; from++) {
12137
- if (queue[from].status !== 2 /* COMPLETED */) {
11980
+ if (queue[from].status !== 2 /* TransactionStatus.COMPLETED */) {
12138
11981
  queue[to] = queue[from];
12139
11982
  to++;
12140
11983
  }
@@ -12182,16 +12025,16 @@ function repoAbortTransactionsOnNode(repo, node) {
12182
12025
  var events = [];
12183
12026
  var lastSent = -1;
12184
12027
  for (var i = 0; i < queue.length; i++) {
12185
- if (queue[i].status === 3 /* SENT_NEEDS_ABORT */) ;
12186
- else if (queue[i].status === 1 /* SENT */) {
12028
+ if (queue[i].status === 3 /* TransactionStatus.SENT_NEEDS_ABORT */) ;
12029
+ else if (queue[i].status === 1 /* TransactionStatus.SENT */) {
12187
12030
  util.assert(lastSent === i - 1, 'All SENT items should be at beginning of queue.');
12188
12031
  lastSent = i;
12189
12032
  // Mark transaction for abort when it comes back.
12190
- queue[i].status = 3 /* SENT_NEEDS_ABORT */;
12033
+ queue[i].status = 3 /* TransactionStatus.SENT_NEEDS_ABORT */;
12191
12034
  queue[i].abortReason = 'set';
12192
12035
  }
12193
12036
  else {
12194
- util.assert(queue[i].status === 0 /* RUN */, 'Unexpected transaction status in abort');
12037
+ util.assert(queue[i].status === 0 /* TransactionStatus.RUN */, 'Unexpected transaction status in abort');
12195
12038
  // We can abort it immediately.
12196
12039
  queue[i].unwatcher();
12197
12040
  events = events.concat(syncTreeAckUserWrite(repo.serverSyncTree_, queue[i].currentWriteId, true));
@@ -12267,7 +12110,7 @@ function decodeQuery(queryString) {
12267
12110
  results[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]);
12268
12111
  }
12269
12112
  else {
12270
- warn("Invalid query segment '" + segment + "' in query '" + queryString + "'");
12113
+ warn("Invalid query segment '".concat(segment, "' in query '").concat(queryString, "'"));
12271
12114
  }
12272
12115
  }
12273
12116
  }
@@ -12372,6 +12215,81 @@ var parseDatabaseURL = function (dataURL) {
12372
12215
  };
12373
12216
  };
12374
12217
 
12218
+ /**
12219
+ * @license
12220
+ * Copyright 2017 Google LLC
12221
+ *
12222
+ * Licensed under the Apache License, Version 2.0 (the "License");
12223
+ * you may not use this file except in compliance with the License.
12224
+ * You may obtain a copy of the License at
12225
+ *
12226
+ * http://www.apache.org/licenses/LICENSE-2.0
12227
+ *
12228
+ * Unless required by applicable law or agreed to in writing, software
12229
+ * distributed under the License is distributed on an "AS IS" BASIS,
12230
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12231
+ * See the License for the specific language governing permissions and
12232
+ * limitations under the License.
12233
+ */
12234
+ // Modeled after base64 web-safe chars, but ordered by ASCII.
12235
+ var PUSH_CHARS = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
12236
+ /**
12237
+ * Fancy ID generator that creates 20-character string identifiers with the
12238
+ * following properties:
12239
+ *
12240
+ * 1. They're based on timestamp so that they sort *after* any existing ids.
12241
+ * 2. They contain 72-bits of random data after the timestamp so that IDs won't
12242
+ * collide with other clients' IDs.
12243
+ * 3. They sort *lexicographically* (so the timestamp is converted to characters
12244
+ * that will sort properly).
12245
+ * 4. They're monotonically increasing. Even if you generate more than one in
12246
+ * the same timestamp, the latter ones will sort after the former ones. We do
12247
+ * this by using the previous random bits but "incrementing" them by 1 (only
12248
+ * in the case of a timestamp collision).
12249
+ */
12250
+ var nextPushId = (function () {
12251
+ // Timestamp of last push, used to prevent local collisions if you push twice
12252
+ // in one ms.
12253
+ var lastPushTime = 0;
12254
+ // We generate 72-bits of randomness which get turned into 12 characters and
12255
+ // appended to the timestamp to prevent collisions with other clients. We
12256
+ // store the last characters we generated because in the event of a collision,
12257
+ // we'll use those same characters except "incremented" by one.
12258
+ var lastRandChars = [];
12259
+ return function (now) {
12260
+ var duplicateTime = now === lastPushTime;
12261
+ lastPushTime = now;
12262
+ var i;
12263
+ var timeStampChars = new Array(8);
12264
+ for (i = 7; i >= 0; i--) {
12265
+ timeStampChars[i] = PUSH_CHARS.charAt(now % 64);
12266
+ // NOTE: Can't use << here because javascript will convert to int and lose
12267
+ // the upper bits.
12268
+ now = Math.floor(now / 64);
12269
+ }
12270
+ util.assert(now === 0, 'Cannot push at time == 0');
12271
+ var id = timeStampChars.join('');
12272
+ if (!duplicateTime) {
12273
+ for (i = 0; i < 12; i++) {
12274
+ lastRandChars[i] = Math.floor(Math.random() * 64);
12275
+ }
12276
+ }
12277
+ else {
12278
+ // If the timestamp hasn't changed since last push, use the same random
12279
+ // number, except incremented by 1.
12280
+ for (i = 11; i >= 0 && lastRandChars[i] === 63; i--) {
12281
+ lastRandChars[i] = 0;
12282
+ }
12283
+ lastRandChars[i]++;
12284
+ }
12285
+ for (i = 0; i < 12; i++) {
12286
+ id += PUSH_CHARS.charAt(lastRandChars[i]);
12287
+ }
12288
+ util.assert(id.length === 20, 'nextPushId: Length should be 20.');
12289
+ return id;
12290
+ };
12291
+ })();
12292
+
12375
12293
  /**
12376
12294
  * @license
12377
12295
  * Copyright 2017 Google LLC
@@ -14009,7 +13927,7 @@ var useRestClient = false;
14009
13927
  * Update an existing `Repo` in place to point to a new host/port.
14010
13928
  */
14011
13929
  function repoManagerApplyEmulatorSettings(repo, host, port, tokenProvider) {
14012
- repo.repoInfo_ = new RepoInfo(host + ":" + port,
13930
+ repo.repoInfo_ = new RepoInfo("".concat(host, ":").concat(port),
14013
13931
  /* secure= */ false, repo.repoInfo_.namespace, repo.repoInfo_.webSocketOnly, repo.repoInfo_.nodeAdmin, repo.repoInfo_.persistenceKey, repo.repoInfo_.includeNamespaceInQueryParams);
14014
13932
  if (tokenProvider) {
14015
13933
  repo.authTokenProvider_ = tokenProvider;
@@ -14027,7 +13945,7 @@ function repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url, no
14027
13945
  ' a Project ID when calling firebase.initializeApp().');
14028
13946
  }
14029
13947
  log('Using default host for project ', app.options.projectId);
14030
- dbUrl = app.options.projectId + "-default-rtdb.firebaseio.com";
13948
+ dbUrl = "".concat(app.options.projectId, "-default-rtdb.firebaseio.com");
14031
13949
  }
14032
13950
  var parsedUrl = parseRepoInfo(dbUrl, nodeAdmin);
14033
13951
  var repoInfo = parsedUrl.repoInfo;
@@ -14038,7 +13956,7 @@ function repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url, no
14038
13956
  }
14039
13957
  if (dbEmulatorHost) {
14040
13958
  isEmulator = true;
14041
- dbUrl = "http://" + dbEmulatorHost + "?ns=" + repoInfo.namespace;
13959
+ dbUrl = "http://".concat(dbEmulatorHost, "?ns=").concat(repoInfo.namespace);
14042
13960
  parsedUrl = parseRepoInfo(dbUrl, nodeAdmin);
14043
13961
  repoInfo = parsedUrl.repoInfo;
14044
13962
  }
@@ -14064,7 +13982,7 @@ function repoManagerDeleteRepo(repo, appName) {
14064
13982
  var appRepos = repos[appName];
14065
13983
  // This should never happen...
14066
13984
  if (!appRepos || appRepos[repo.key] !== repo) {
14067
- fatal("Database " + appName + "(" + repo.repoInfo_ + ") has already been deleted.");
13985
+ fatal("Database ".concat(appName, "(").concat(repo.repoInfo_, ") has already been deleted."));
14068
13986
  }
14069
13987
  repoInterrupt(repo);
14070
13988
  delete appRepos[repo.key];
@@ -14186,7 +14104,7 @@ function getDatabase(app$1, url) {
14186
14104
  });
14187
14105
  var emulator = util.getDefaultEmulatorHostnameAndPort('database');
14188
14106
  if (emulator) {
14189
- connectDatabaseEmulator.apply(void 0, tslib.__spreadArray([db], tslib.__read(emulator)));
14107
+ connectDatabaseEmulator.apply(void 0, tslib.__spreadArray([db], tslib.__read(emulator), false));
14190
14108
  }
14191
14109
  return db;
14192
14110
  }
@@ -14295,7 +14213,7 @@ function registerDatabase(variant) {
14295
14213
  var authProvider = container.getProvider('auth-internal');
14296
14214
  var appCheckProvider = container.getProvider('app-check-internal');
14297
14215
  return repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url);
14298
- }, "PUBLIC" /* PUBLIC */).setMultipleInstances(true));
14216
+ }, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
14299
14217
  app.registerVersion(name, version, variant);
14300
14218
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
14301
14219
  app.registerVersion(name, version, 'cjs5');