@firebase/firestore 4.7.16 → 4.7.17
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/dist/firestore/src/platform/browser/webchannel_connection.d.ts +17 -0
- package/dist/index.cjs.js +640 -618
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +640 -618
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.node.cjs.js +2 -2
- package/dist/index.node.mjs +2 -2
- package/dist/index.rn.js +596 -574
- package/dist/index.rn.js.map +1 -1
- package/dist/lite/firestore/src/platform/browser/webchannel_connection.d.ts +17 -0
- package/dist/lite/index.browser.esm2017.js +2 -2
- package/dist/lite/index.cjs.js +2 -2
- package/dist/lite/index.node.cjs.js +2 -2
- package/dist/lite/index.node.mjs +2 -2
- package/dist/lite/index.rn.esm2017.js +2 -2
- package/package.json +3 -3
package/dist/index.esm2017.js
CHANGED
|
@@ -5,7 +5,7 @@ import { FirebaseError, isCloudWorkstation, pingServer, updateEmulatorBanner, de
|
|
|
5
5
|
import { Integer, Md5 } from '@firebase/webchannel-wrapper/bloom-blob';
|
|
6
6
|
import { XhrIo, EventType, ErrorCode, createWebChannelTransport, getStatEventTarget, WebChannel, Event, Stat } from '@firebase/webchannel-wrapper/webchannel-blob';
|
|
7
7
|
|
|
8
|
-
const F = "@firebase/firestore", M = "4.7.
|
|
8
|
+
const F = "@firebase/firestore", M = "4.7.17";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @license
|
|
@@ -67,7 +67,7 @@ User.MOCK_USER = new User("mock-user");
|
|
|
67
67
|
* See the License for the specific language governing permissions and
|
|
68
68
|
* limitations under the License.
|
|
69
69
|
*/
|
|
70
|
-
let x = "11.
|
|
70
|
+
let x = "11.9.0";
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* @license
|
|
@@ -2434,7 +2434,7 @@ function __PRIVATE_newDbDocumentMutationPrefixForPath(e, t) {
|
|
|
2434
2434
|
* there is no useful information to store as the value. The raw (unencoded)
|
|
2435
2435
|
* path cannot be stored because IndexedDb doesn't store prototype
|
|
2436
2436
|
* information.
|
|
2437
|
-
*/ const re = {}, ie = "documentMutations", se = "remoteDocumentsV14", oe = [ "prefixPath", "collectionGroup", "readTime", "documentId" ], _e = "documentKeyIndex", ae = [ "prefixPath", "collectionGroup", "documentId" ], ue = "collectionGroupIndex", ce = [ "collectionGroup", "readTime", "prefixPath", "documentId" ], le = "remoteDocumentGlobal", he = "remoteDocumentGlobalKey", Pe = "targets", Te = "queryTargetsIndex", Ie = [ "canonicalId", "targetId" ], Ee = "targetDocuments", de = [ "targetId", "path" ], Ae = "documentTargetsIndex", Re = [ "path", "targetId" ], Ve = "targetGlobalKey", me = "targetGlobal", fe = "collectionParents", ge = [ "collectionId", "parent" ], pe = "clientMetadata", ye = "clientId", we = "bundles",
|
|
2437
|
+
*/ const re = {}, ie = "documentMutations", se = "remoteDocumentsV14", oe = [ "prefixPath", "collectionGroup", "readTime", "documentId" ], _e = "documentKeyIndex", ae = [ "prefixPath", "collectionGroup", "documentId" ], ue = "collectionGroupIndex", ce = [ "collectionGroup", "readTime", "prefixPath", "documentId" ], le = "remoteDocumentGlobal", he = "remoteDocumentGlobalKey", Pe = "targets", Te = "queryTargetsIndex", Ie = [ "canonicalId", "targetId" ], Ee = "targetDocuments", de = [ "targetId", "path" ], Ae = "documentTargetsIndex", Re = [ "path", "targetId" ], Ve = "targetGlobalKey", me = "targetGlobal", fe = "collectionParents", ge = [ "collectionId", "parent" ], pe = "clientMetadata", ye = "clientId", we = "bundles", be = "bundleId", Se = "namedQueries", De = "name", ve = "indexConfiguration", Ce = "indexId", Fe = "collectionGroupIndex", Me = "collectionGroup", xe = "indexState", Oe = [ "indexId", "uid" ], Ne = "sequenceNumberIndex", Be = [ "uid", "sequenceNumber" ], Le = "indexEntries", ke = [ "indexId", "uid", "arrayValue", "directionalValue", "orderedDocumentKey", "documentKey" ], qe = "documentKeyIndex", Qe = [ "indexId", "uid", "orderedDocumentKey" ], $e = "documentOverlays", Ue = [ "userId", "collectionPath", "documentId" ], Ke = "collectionPathOverlayIndex", We = [ "userId", "collectionPath", "largestBatchId" ], Ge = "collectionGroupOverlayIndex", ze = [ "userId", "collectionGroup", "largestBatchId" ], je = "globals", He = "name", Je = [ ...[ ...[ ...[ ...[ Y, X, ie, j, Pe, H, me, Ee ], pe ], le ], fe ], we, Se ], Ye = [ ...Je, $e ], Ze = [ Y, X, ie, se, Pe, H, me, Ee, pe, le, fe, we, Se, $e ], Xe = Ze, et = [ ...Xe, ve, xe, Le ], tt = et, nt = [ ...et, je ], rt = nt;
|
|
2438
2438
|
|
|
2439
2439
|
/**
|
|
2440
2440
|
* @license
|
|
@@ -6047,7 +6047,7 @@ class BloomFilter {
|
|
|
6047
6047
|
r.modulo(this.ye).toNumber();
|
|
6048
6048
|
}
|
|
6049
6049
|
// Return whether the bit on the given index in the bitmap is set to 1.
|
|
6050
|
-
|
|
6050
|
+
be(e) {
|
|
6051
6051
|
return !!(this.bitmap[Math.floor(e / 8)] & 1 << e % 8);
|
|
6052
6052
|
}
|
|
6053
6053
|
mightContain(e) {
|
|
@@ -6056,7 +6056,7 @@ class BloomFilter {
|
|
|
6056
6056
|
const t = __PRIVATE_getMd5HashValue(e), [n, r] = __PRIVATE_get64BitUints(t);
|
|
6057
6057
|
for (let e = 0; e < this.hashCount; e++) {
|
|
6058
6058
|
const t = this.we(n, r, e);
|
|
6059
|
-
if (!this.
|
|
6059
|
+
if (!this.be(t)) return !1;
|
|
6060
6060
|
}
|
|
6061
6061
|
return !0;
|
|
6062
6062
|
}
|
|
@@ -6069,10 +6069,10 @@ class BloomFilter {
|
|
|
6069
6069
|
const t = __PRIVATE_getMd5HashValue(e), [n, r] = __PRIVATE_get64BitUints(t);
|
|
6070
6070
|
for (let e = 0; e < this.hashCount; e++) {
|
|
6071
6071
|
const t = this.we(n, r, e);
|
|
6072
|
-
this.
|
|
6072
|
+
this.Se(t);
|
|
6073
6073
|
}
|
|
6074
6074
|
}
|
|
6075
|
-
|
|
6075
|
+
Se(e) {
|
|
6076
6076
|
const t = Math.floor(e / 8), n = e % 8;
|
|
6077
6077
|
this.bitmap[t] |= 1 << n;
|
|
6078
6078
|
}
|
|
@@ -6699,7 +6699,7 @@ const wt = (() => {
|
|
|
6699
6699
|
desc: "DESCENDING"
|
|
6700
6700
|
};
|
|
6701
6701
|
return e;
|
|
6702
|
-
})(),
|
|
6702
|
+
})(), bt = (() => {
|
|
6703
6703
|
const e = {
|
|
6704
6704
|
"<": "LESS_THAN",
|
|
6705
6705
|
"<=": "LESS_THAN_OR_EQUAL",
|
|
@@ -6713,7 +6713,7 @@ const wt = (() => {
|
|
|
6713
6713
|
"array-contains-any": "ARRAY_CONTAINS_ANY"
|
|
6714
6714
|
};
|
|
6715
6715
|
return e;
|
|
6716
|
-
})(),
|
|
6716
|
+
})(), St = (() => {
|
|
6717
6717
|
const e = {
|
|
6718
6718
|
and: "AND",
|
|
6719
6719
|
or: "OR"
|
|
@@ -7318,11 +7318,11 @@ function __PRIVATE_toDirection(e) {
|
|
|
7318
7318
|
}
|
|
7319
7319
|
|
|
7320
7320
|
function __PRIVATE_toOperatorName(e) {
|
|
7321
|
-
return
|
|
7321
|
+
return bt[e];
|
|
7322
7322
|
}
|
|
7323
7323
|
|
|
7324
7324
|
function __PRIVATE_toCompositeOperatorName(e) {
|
|
7325
|
-
return
|
|
7325
|
+
return St[e];
|
|
7326
7326
|
}
|
|
7327
7327
|
|
|
7328
7328
|
function __PRIVATE_toFieldPathReference(e) {
|
|
@@ -7733,7 +7733,7 @@ function __PRIVATE_toDbIndexState(e, t, n, r) {
|
|
|
7733
7733
|
/**
|
|
7734
7734
|
* Helper to get a typed SimpleDbStore for the namedQueries object store.
|
|
7735
7735
|
*/ function __PRIVATE_namedQueriesStore(e) {
|
|
7736
|
-
return __PRIVATE_getStore(e,
|
|
7736
|
+
return __PRIVATE_getStore(e, Se);
|
|
7737
7737
|
}
|
|
7738
7738
|
|
|
7739
7739
|
/**
|
|
@@ -7762,7 +7762,7 @@ function __PRIVATE_toDbIndexState(e, t, n, r) {
|
|
|
7762
7762
|
constructor(e, t) {
|
|
7763
7763
|
this.serializer = e, this.userId = t;
|
|
7764
7764
|
}
|
|
7765
|
-
static
|
|
7765
|
+
static bt(e, t) {
|
|
7766
7766
|
const n = t.uid || "";
|
|
7767
7767
|
return new __PRIVATE_IndexedDbDocumentOverlayCache(e, n);
|
|
7768
7768
|
}
|
|
@@ -7779,7 +7779,7 @@ function __PRIVATE_toDbIndexState(e, t, n, r) {
|
|
|
7779
7779
|
const r = [];
|
|
7780
7780
|
return n.forEach(((n, i) => {
|
|
7781
7781
|
const s = new Overlay(t, i);
|
|
7782
|
-
r.push(this.
|
|
7782
|
+
r.push(this.St(e, s));
|
|
7783
7783
|
})), PersistencePromise.waitFor(r);
|
|
7784
7784
|
}
|
|
7785
7785
|
removeOverlaysForBatchId(e, t, n) {
|
|
@@ -7824,7 +7824,7 @@ function __PRIVATE_toDbIndexState(e, t, n, r) {
|
|
|
7824
7824
|
i.size() < r || o.largestBatchId === s ? (i.set(o.getKey(), o), s = o.largestBatchId) : n.done();
|
|
7825
7825
|
})).next((() => i));
|
|
7826
7826
|
}
|
|
7827
|
-
|
|
7827
|
+
St(e, t) {
|
|
7828
7828
|
return __PRIVATE_documentOverlayStore(e).put(function __PRIVATE_toDbDocumentOverlay(e, t, n) {
|
|
7829
7829
|
const [r, i, s] = __PRIVATE_toDbDocumentOverlayKey(t, n.mutation.key);
|
|
7830
7830
|
return {
|
|
@@ -8402,11 +8402,11 @@ class __PRIVATE_TargetIndexMatcher {
|
|
|
8402
8402
|
return !1;
|
|
8403
8403
|
// If there is an array element, find a matching filter.
|
|
8404
8404
|
const t = __PRIVATE_fieldIndexGetArraySegment(e);
|
|
8405
|
-
if (void 0 !== t && !this.
|
|
8405
|
+
if (void 0 !== t && !this.bn(t)) return !1;
|
|
8406
8406
|
const n = __PRIVATE_fieldIndexGetDirectionalSegments(e);
|
|
8407
8407
|
let r = new Set, i = 0, s = 0;
|
|
8408
8408
|
// Process all equalities first. Equalities can appear out of order.
|
|
8409
|
-
for (;i < n.length && this.
|
|
8409
|
+
for (;i < n.length && this.bn(n[i]); ++i) r = r.add(n[i].fieldPath.canonicalString());
|
|
8410
8410
|
// If we already have processed all segments, all segments are used to serve
|
|
8411
8411
|
// the equality filters and we do not need to map any segments to the
|
|
8412
8412
|
// target's inequality and orderBy clauses.
|
|
@@ -8419,7 +8419,7 @@ class __PRIVATE_TargetIndexMatcher {
|
|
|
8419
8419
|
// and the first orderBy clause.
|
|
8420
8420
|
if (!r.has(e.field.canonicalString())) {
|
|
8421
8421
|
const t = n[i];
|
|
8422
|
-
if (!this.
|
|
8422
|
+
if (!this.Sn(e, t) || !this.Dn(this.gn[s++], t)) return !1;
|
|
8423
8423
|
}
|
|
8424
8424
|
++i;
|
|
8425
8425
|
}
|
|
@@ -8461,11 +8461,11 @@ class __PRIVATE_TargetIndexMatcher {
|
|
|
8461
8461
|
n.field.isKeyField() || e.has(n.field) || (e = e.add(n.field), t.push(new IndexSegment(n.field, "asc" /* Direction.ASCENDING */ === n.dir ? 0 /* IndexKind.ASCENDING */ : 1 /* IndexKind.DESCENDING */)));
|
|
8462
8462
|
return new FieldIndex(FieldIndex.UNKNOWN_ID, this.collectionId, t, IndexState.empty());
|
|
8463
8463
|
}
|
|
8464
|
-
|
|
8465
|
-
for (const t of this.pn) if (this.
|
|
8464
|
+
bn(e) {
|
|
8465
|
+
for (const t of this.pn) if (this.Sn(t, e)) return !0;
|
|
8466
8466
|
return !1;
|
|
8467
8467
|
}
|
|
8468
|
-
|
|
8468
|
+
Sn(e, t) {
|
|
8469
8469
|
if (void 0 === e || !e.field.isEqual(t.fieldPath)) return !1;
|
|
8470
8470
|
const n = "array-contains" /* Operator.ARRAY_CONTAINS */ === e.op || "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ === e.op;
|
|
8471
8471
|
return 2 /* IndexKind.CONTAINS */ === t.kind === n;
|
|
@@ -9435,7 +9435,7 @@ class __PRIVATE_IndexedDbMutationQueue {
|
|
|
9435
9435
|
* Creates a new mutation queue for the given user.
|
|
9436
9436
|
* @param user - The user for which to create a mutation queue.
|
|
9437
9437
|
* @param serializer - The serializer to use when persisting to IndexedDb.
|
|
9438
|
-
*/ static
|
|
9438
|
+
*/ static bt(e, t, n, r) {
|
|
9439
9439
|
// TODO(mcg): Figure out what constraints there are on userIDs
|
|
9440
9440
|
// In particular, are there any reserved characters? are empty ids allowed?
|
|
9441
9441
|
// For the moment store these together in the same mutations table assuming
|
|
@@ -10119,10 +10119,10 @@ function __PRIVATE_newLruGarbageCollector(e, t) {
|
|
|
10119
10119
|
this.db = e, this.garbageCollector = __PRIVATE_newLruGarbageCollector(this, t);
|
|
10120
10120
|
}
|
|
10121
10121
|
pr(e) {
|
|
10122
|
-
const t = this.
|
|
10122
|
+
const t = this.br(e);
|
|
10123
10123
|
return this.db.getTargetCache().getTargetCount(e).next((e => t.next((t => e + t))));
|
|
10124
10124
|
}
|
|
10125
|
-
|
|
10125
|
+
br(e) {
|
|
10126
10126
|
let t = 0;
|
|
10127
10127
|
return this.yr(e, (e => {
|
|
10128
10128
|
t++;
|
|
@@ -10132,7 +10132,7 @@ function __PRIVATE_newLruGarbageCollector(e, t) {
|
|
|
10132
10132
|
return this.db.getTargetCache().forEachTarget(e, t);
|
|
10133
10133
|
}
|
|
10134
10134
|
yr(e, t) {
|
|
10135
|
-
return this.
|
|
10135
|
+
return this.Sr(e, ((e, n) => t(n)));
|
|
10136
10136
|
}
|
|
10137
10137
|
addReference(e, t, n) {
|
|
10138
10138
|
return __PRIVATE_writeSentinelKey(e, n);
|
|
@@ -10161,7 +10161,7 @@ function __PRIVATE_newLruGarbageCollector(e, t) {
|
|
|
10161
10161
|
removeOrphanedDocuments(e, t) {
|
|
10162
10162
|
const n = this.db.getRemoteDocumentCache().newChangeBuffer(), r = [];
|
|
10163
10163
|
let i = 0;
|
|
10164
|
-
return this.
|
|
10164
|
+
return this.Sr(e, ((s, o) => {
|
|
10165
10165
|
if (o <= t) {
|
|
10166
10166
|
const t = this.Dr(e, s).next((t => {
|
|
10167
10167
|
if (!t)
|
|
@@ -10192,7 +10192,7 @@ function __PRIVATE_newLruGarbageCollector(e, t) {
|
|
|
10192
10192
|
* means not a part of any target, so the only entry in the target-document index for
|
|
10193
10193
|
* that document will be the sentinel row (targetId 0), which will also have the sequence
|
|
10194
10194
|
* number for the last time the document was accessed.
|
|
10195
|
-
*/
|
|
10195
|
+
*/ Sr(e, t) {
|
|
10196
10196
|
const n = __PRIVATE_documentTargetStore(e);
|
|
10197
10197
|
let r, i = __PRIVATE_ListenSequence.le;
|
|
10198
10198
|
return n.te({
|
|
@@ -11028,7 +11028,7 @@ class OverlayedDocument {
|
|
|
11028
11028
|
}
|
|
11029
11029
|
saveOverlays(e, t, n) {
|
|
11030
11030
|
return n.forEach(((n, r) => {
|
|
11031
|
-
this.
|
|
11031
|
+
this.St(e, t, r);
|
|
11032
11032
|
})), PersistencePromise.resolve();
|
|
11033
11033
|
}
|
|
11034
11034
|
removeOverlaysForBatchId(e, t, n) {
|
|
@@ -11063,7 +11063,7 @@ class OverlayedDocument {
|
|
|
11063
11063
|
}
|
|
11064
11064
|
return PersistencePromise.resolve(o);
|
|
11065
11065
|
}
|
|
11066
|
-
|
|
11066
|
+
St(e, t, n) {
|
|
11067
11067
|
// Remove the association of the overlay to its batch id.
|
|
11068
11068
|
const r = this.overlays.get(n.key);
|
|
11069
11069
|
if (null !== r) {
|
|
@@ -11776,10 +11776,10 @@ class __PRIVATE_MemoryLruDelegate {
|
|
|
11776
11776
|
return this.persistence.getTargetCache().forEachTarget(e, t);
|
|
11777
11777
|
}
|
|
11778
11778
|
pr(e) {
|
|
11779
|
-
const t = this.
|
|
11779
|
+
const t = this.br(e);
|
|
11780
11780
|
return this.persistence.getTargetCache().getTargetCount(e).next((e => t.next((t => e + t))));
|
|
11781
11781
|
}
|
|
11782
|
-
|
|
11782
|
+
br(e) {
|
|
11783
11783
|
let t = 0;
|
|
11784
11784
|
return this.yr(e, (e => {
|
|
11785
11785
|
t++;
|
|
@@ -11927,7 +11927,7 @@ class __PRIVATE_MemoryLruDelegate {
|
|
|
11927
11927
|
}(e);
|
|
11928
11928
|
}))), n < 5 && r >= 5 && (s = s.next((() => this.wi(i)))), n < 6 && r >= 6 && (s = s.next((() => (function __PRIVATE_createDocumentGlobalStore(e) {
|
|
11929
11929
|
e.createObjectStore(le);
|
|
11930
|
-
}(e), this.
|
|
11930
|
+
}(e), this.bi(i))))), n < 7 && r >= 7 && (s = s.next((() => this.Si(i)))), n < 8 && r >= 8 && (s = s.next((() => this.Di(e, i)))),
|
|
11931
11931
|
n < 9 && r >= 9 && (s = s.next((() => {
|
|
11932
11932
|
// Multi-Tab used to manage its own changelog, but this has been moved
|
|
11933
11933
|
// to the DbRemoteDocument object store itself. Since the previous change
|
|
@@ -11940,10 +11940,10 @@ class __PRIVATE_MemoryLruDelegate {
|
|
|
11940
11940
|
}))), n < 10 && r >= 10 && (s = s.next((() => this.Ci(i)))), n < 11 && r >= 11 && (s = s.next((() => {
|
|
11941
11941
|
!function __PRIVATE_createBundlesStore(e) {
|
|
11942
11942
|
e.createObjectStore(we, {
|
|
11943
|
-
keyPath:
|
|
11943
|
+
keyPath: be
|
|
11944
11944
|
});
|
|
11945
11945
|
}(e), function __PRIVATE_createNamedQueriesStore(e) {
|
|
11946
|
-
e.createObjectStore(
|
|
11946
|
+
e.createObjectStore(Se, {
|
|
11947
11947
|
keyPath: De
|
|
11948
11948
|
});
|
|
11949
11949
|
}(e);
|
|
@@ -12002,7 +12002,7 @@ class __PRIVATE_MemoryLruDelegate {
|
|
|
12002
12002
|
t.objectStore(Le).clear();
|
|
12003
12003
|
}))), s;
|
|
12004
12004
|
}
|
|
12005
|
-
|
|
12005
|
+
bi(e) {
|
|
12006
12006
|
let t = 0;
|
|
12007
12007
|
return e.store(j).te(((e, n) => {
|
|
12008
12008
|
t += __PRIVATE_dbDocumentSize(n);
|
|
@@ -12029,7 +12029,7 @@ class __PRIVATE_MemoryLruDelegate {
|
|
|
12029
12029
|
/**
|
|
12030
12030
|
* Ensures that every document in the remote document cache has a corresponding sentinel row
|
|
12031
12031
|
* with a sequence number. Missing rows are given the most recently used sequence number.
|
|
12032
|
-
*/
|
|
12032
|
+
*/ Si(e) {
|
|
12033
12033
|
const t = e.store(Ee), n = e.store(j);
|
|
12034
12034
|
return e.store(me).get(Ve).next((e => {
|
|
12035
12035
|
const r = [];
|
|
@@ -12124,7 +12124,7 @@ class __PRIVATE_MemoryLruDelegate {
|
|
|
12124
12124
|
__PRIVATE_fromDbMutationBatch(this.serializer, e).keys().forEach((e => r = r.add(e))),
|
|
12125
12125
|
n.set(e.userId, r);
|
|
12126
12126
|
})), PersistencePromise.forEach(n, ((e, n) => {
|
|
12127
|
-
const s = new User(n), o = __PRIVATE_IndexedDbDocumentOverlayCache.
|
|
12127
|
+
const s = new User(n), o = __PRIVATE_IndexedDbDocumentOverlayCache.bt(this.serializer, s), _ = i.getIndexManager(s), a = __PRIVATE_IndexedDbMutationQueue.bt(s, this.serializer, _, i.referenceDelegate);
|
|
12128
12128
|
return new LocalDocumentsView(r, a, o, _).recalculateAndSaveOverlaysForDocumentKeys(new __PRIVATE_IndexedDbTransaction(t, __PRIVATE_ListenSequence.le), e).next();
|
|
12129
12129
|
}));
|
|
12130
12130
|
}));
|
|
@@ -12433,7 +12433,7 @@ class __PRIVATE_IndexedDbPersistence {
|
|
|
12433
12433
|
return this.Pi;
|
|
12434
12434
|
}
|
|
12435
12435
|
getMutationQueue(e, t) {
|
|
12436
|
-
return __PRIVATE_IndexedDbMutationQueue.
|
|
12436
|
+
return __PRIVATE_IndexedDbMutationQueue.bt(e, this.serializer, t, this.referenceDelegate);
|
|
12437
12437
|
}
|
|
12438
12438
|
getTargetCache() {
|
|
12439
12439
|
return this.Ti;
|
|
@@ -12445,7 +12445,7 @@ class __PRIVATE_IndexedDbPersistence {
|
|
|
12445
12445
|
return new __PRIVATE_IndexedDbIndexManager(e, this.serializer.wt.databaseId);
|
|
12446
12446
|
}
|
|
12447
12447
|
getDocumentOverlayCache(e) {
|
|
12448
|
-
return __PRIVATE_IndexedDbDocumentOverlayCache.
|
|
12448
|
+
return __PRIVATE_IndexedDbDocumentOverlayCache.bt(this.serializer, e);
|
|
12449
12449
|
}
|
|
12450
12450
|
getBundleCache() {
|
|
12451
12451
|
return this.Ei;
|
|
@@ -12765,13 +12765,13 @@ class __PRIVATE_QueryEngine {
|
|
|
12765
12765
|
return this.ws(e, t).next((e => {
|
|
12766
12766
|
i.result = e;
|
|
12767
12767
|
})).next((() => {
|
|
12768
|
-
if (!i.result) return this.
|
|
12768
|
+
if (!i.result) return this.bs(e, t, r, n).next((e => {
|
|
12769
12769
|
i.result = e;
|
|
12770
12770
|
}));
|
|
12771
12771
|
})).next((() => {
|
|
12772
12772
|
if (i.result) return;
|
|
12773
12773
|
const n = new QueryContext;
|
|
12774
|
-
return this.
|
|
12774
|
+
return this.Ss(e, t, n).next((r => {
|
|
12775
12775
|
if (i.result = r, this.fs) return this.Ds(e, t, n, r.size);
|
|
12776
12776
|
}));
|
|
12777
12777
|
})).next((() => i.result));
|
|
@@ -12812,7 +12812,7 @@ class __PRIVATE_QueryEngine {
|
|
|
12812
12812
|
/**
|
|
12813
12813
|
* Performs a query based on the target's persisted query mapping. Returns
|
|
12814
12814
|
* `null` if the mapping is not available or cannot be used.
|
|
12815
|
-
*/
|
|
12815
|
+
*/ bs(e, t, n, r) {
|
|
12816
12816
|
return __PRIVATE_queryMatchesAllDocuments(t) || r.isEqual(SnapshotVersion.min()) ? PersistencePromise.resolve(null) : this.ys.getDocuments(e, n).next((i => {
|
|
12817
12817
|
const s = this.vs(t, i);
|
|
12818
12818
|
return this.Cs(t, s, n, r) ? PersistencePromise.resolve(null) : (__PRIVATE_getLogLevel() <= LogLevel.DEBUG && __PRIVATE_logDebug("QueryEngine", "Re-using previous result from %s to execute query: %s", r.toString(), __PRIVATE_stringifyQuery(t)),
|
|
@@ -12859,7 +12859,7 @@ class __PRIVATE_QueryEngine {
|
|
|
12859
12859
|
const i = "F" /* LimitType.First */ === e.limitType ? t.last() : t.first();
|
|
12860
12860
|
return !!i && (i.hasPendingWrites || i.version.compareTo(r) > 0);
|
|
12861
12861
|
}
|
|
12862
|
-
|
|
12862
|
+
Ss(e, t, n) {
|
|
12863
12863
|
return __PRIVATE_getLogLevel() <= LogLevel.DEBUG && __PRIVATE_logDebug("QueryEngine", "Using full collection scan to execute query:", __PRIVATE_stringifyQuery(t)),
|
|
12864
12864
|
this.ys.getDocumentsMatchingQuery(e, t, IndexOffset.min(), n);
|
|
12865
12865
|
}
|
|
@@ -13735,7 +13735,7 @@ class __PRIVATE_LocalClientState {
|
|
|
13735
13735
|
} else if (this.oo.test(t.key)) {
|
|
13736
13736
|
if (null !== t.newValue) {
|
|
13737
13737
|
const e = this.wo(t.key, t.newValue);
|
|
13738
|
-
if (e) return this.
|
|
13738
|
+
if (e) return this.bo(e);
|
|
13739
13739
|
}
|
|
13740
13740
|
} else if (t.key === this._o) {
|
|
13741
13741
|
if (null !== t.newValue) {
|
|
@@ -13748,7 +13748,7 @@ class __PRIVATE_LocalClientState {
|
|
|
13748
13748
|
if (null != e) try {
|
|
13749
13749
|
const n = JSON.parse(e);
|
|
13750
13750
|
__PRIVATE_hardAssert("number" == typeof n, 30636, {
|
|
13751
|
-
|
|
13751
|
+
So: e
|
|
13752
13752
|
}), t = n;
|
|
13753
13753
|
} catch (e) {
|
|
13754
13754
|
__PRIVATE_logError(Gt, "Failed to read sequence number from WebStorage", e);
|
|
@@ -13839,7 +13839,7 @@ class __PRIVATE_LocalClientState {
|
|
|
13839
13839
|
if (e.user.uid === this.currentUser.uid) return this.syncEngine.Co(e.batchId, e.state, e.error);
|
|
13840
13840
|
__PRIVATE_logDebug(Gt, `Ignoring mutation for non-active user ${e.user.uid}`);
|
|
13841
13841
|
}
|
|
13842
|
-
|
|
13842
|
+
bo(e) {
|
|
13843
13843
|
return this.syncEngine.Fo(e.targetId, e.state, e.error);
|
|
13844
13844
|
}
|
|
13845
13845
|
mo(e, t) {
|
|
@@ -14206,7 +14206,9 @@ class __PRIVATE_RestConnection {
|
|
|
14206
14206
|
|
|
14207
14207
|
class __PRIVATE_WebChannelConnection extends __PRIVATE_RestConnection {
|
|
14208
14208
|
constructor(e) {
|
|
14209
|
-
super(e),
|
|
14209
|
+
super(e),
|
|
14210
|
+
/** A collection of open WebChannel instances */
|
|
14211
|
+
this.l_ = [], this.forceLongPolling = e.forceLongPolling, this.autoDetectLongPolling = e.autoDetectLongPolling,
|
|
14210
14212
|
this.useFetchStreams = e.useFetchStreams, this.longPollingOptions = e.longPollingOptions;
|
|
14211
14213
|
}
|
|
14212
14214
|
Jo(e, t, n, r, i) {
|
|
@@ -14248,10 +14250,10 @@ class __PRIVATE_WebChannelConnection extends __PRIVATE_RestConnection {
|
|
|
14248
14250
|
|
|
14249
14251
|
default:
|
|
14250
14252
|
fail(9055, {
|
|
14251
|
-
|
|
14253
|
+
h_: e,
|
|
14252
14254
|
streamId: s,
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
+
P_: _.getLastErrorCode(),
|
|
14256
|
+
T_: _.getLastError()
|
|
14255
14257
|
});
|
|
14256
14258
|
}
|
|
14257
14259
|
} finally {
|
|
@@ -14262,7 +14264,7 @@ class __PRIVATE_WebChannelConnection extends __PRIVATE_RestConnection {
|
|
|
14262
14264
|
__PRIVATE_logDebug(Yt, `RPC '${e}' ${s} sending request:`, r), _.send(t, "POST", a, n, 15);
|
|
14263
14265
|
}));
|
|
14264
14266
|
}
|
|
14265
|
-
|
|
14267
|
+
I_(e, t, n) {
|
|
14266
14268
|
const r = __PRIVATE_generateUniqueDebugId(), i = [ this.Ko, "/", "google.firestore.v1.Firestore", "/", e, "/channel" ], s = createWebChannelTransport(), o = getStatEventTarget(), _ = {
|
|
14267
14269
|
// Required for backend stickiness, routing behavior is based on this
|
|
14268
14270
|
// parameter.
|
|
@@ -14302,12 +14304,13 @@ class __PRIVATE_WebChannelConnection extends __PRIVATE_RestConnection {
|
|
|
14302
14304
|
const u = i.join("");
|
|
14303
14305
|
__PRIVATE_logDebug(Yt, `Creating RPC '${e}' stream ${r}: ${u}`, _);
|
|
14304
14306
|
const c = s.createWebChannel(u, _);
|
|
14307
|
+
this.E_(c);
|
|
14305
14308
|
// WebChannel supports sending the first message with the handshake - saving
|
|
14306
14309
|
// a network round trip. However, it will have to call send in the same
|
|
14307
14310
|
// JS event loop as open. In order to enforce this, we delay actually
|
|
14308
14311
|
// opening the WebChannel until send is called. Whether we have called
|
|
14309
14312
|
// open is tracked with this variable.
|
|
14310
|
-
|
|
14313
|
+
let l = !1, h = !1;
|
|
14311
14314
|
// A flag to determine whether the stream was closed (by us or through an
|
|
14312
14315
|
// error/close event) to avoid delivering multiple close events or sending
|
|
14313
14316
|
// on a closed stream
|
|
@@ -14339,7 +14342,7 @@ class __PRIVATE_WebChannelConnection extends __PRIVATE_RestConnection {
|
|
|
14339
14342
|
h || (__PRIVATE_logDebug(Yt, `RPC '${e}' stream ${r} transport opened.`), P.__());
|
|
14340
14343
|
})), __PRIVATE_unguardedEventListen(c, WebChannel.EventType.CLOSE, (() => {
|
|
14341
14344
|
h || (h = !0, __PRIVATE_logDebug(Yt, `RPC '${e}' stream ${r} transport closed`),
|
|
14342
|
-
P.u_());
|
|
14345
|
+
P.u_(), this.d_(c));
|
|
14343
14346
|
})), __PRIVATE_unguardedEventListen(c, WebChannel.EventType.ERROR, (t => {
|
|
14344
14347
|
h || (h = !0, __PRIVATE_logWarn(Yt, `RPC '${e}' stream ${r} transport errored. Name:`, t.name, "Message:", t.message),
|
|
14345
14348
|
P.u_(new FirestoreError(N.UNAVAILABLE, "The operation could not be completed")));
|
|
@@ -14386,6 +14389,25 @@ class __PRIVATE_WebChannelConnection extends __PRIVATE_RestConnection {
|
|
|
14386
14389
|
P.a_();
|
|
14387
14390
|
}), 0), P;
|
|
14388
14391
|
}
|
|
14392
|
+
/**
|
|
14393
|
+
* Closes and cleans up any resources associated with the connection.
|
|
14394
|
+
*/ terminate() {
|
|
14395
|
+
// If the Firestore instance is terminated, we will explicitly
|
|
14396
|
+
// close any remaining open WebChannel instances.
|
|
14397
|
+
this.l_.forEach((e => e.close())), this.l_ = [];
|
|
14398
|
+
}
|
|
14399
|
+
/**
|
|
14400
|
+
* Add a WebChannel instance to the collection of open instances.
|
|
14401
|
+
* @param webChannel
|
|
14402
|
+
*/ E_(e) {
|
|
14403
|
+
this.l_.push(e);
|
|
14404
|
+
}
|
|
14405
|
+
/**
|
|
14406
|
+
* Remove a WebChannel instance from the collection of open instances.
|
|
14407
|
+
* @param webChannel
|
|
14408
|
+
*/ d_(e) {
|
|
14409
|
+
this.l_ = this.l_.filter((t => t === e));
|
|
14410
|
+
}
|
|
14389
14411
|
}
|
|
14390
14412
|
|
|
14391
14413
|
/**
|
|
@@ -14503,10 +14525,10 @@ class __PRIVATE_ExponentialBackoff {
|
|
|
14503
14525
|
* Note that jitter will still be applied, so the actual delay could be as
|
|
14504
14526
|
* much as 1.5*maxDelayMs.
|
|
14505
14527
|
*/ , i = 6e4) {
|
|
14506
|
-
this.xi = e, this.timerId = t, this.
|
|
14507
|
-
this.
|
|
14528
|
+
this.xi = e, this.timerId = t, this.A_ = n, this.R_ = r, this.V_ = i, this.m_ = 0,
|
|
14529
|
+
this.f_ = null,
|
|
14508
14530
|
/** The last backoff attempt, as epoch milliseconds. */
|
|
14509
|
-
this.
|
|
14531
|
+
this.g_ = Date.now(), this.reset();
|
|
14510
14532
|
}
|
|
14511
14533
|
/**
|
|
14512
14534
|
* Resets the backoff delay.
|
|
@@ -14515,40 +14537,40 @@ class __PRIVATE_ExponentialBackoff {
|
|
|
14515
14537
|
* (i.e. due to an error), initialDelayMs (plus jitter) will be used, and
|
|
14516
14538
|
* subsequent ones will increase according to the backoffFactor.
|
|
14517
14539
|
*/ reset() {
|
|
14518
|
-
this.
|
|
14540
|
+
this.m_ = 0;
|
|
14519
14541
|
}
|
|
14520
14542
|
/**
|
|
14521
14543
|
* Resets the backoff delay to the maximum delay (e.g. for use after a
|
|
14522
14544
|
* RESOURCE_EXHAUSTED error).
|
|
14523
|
-
*/
|
|
14524
|
-
this.
|
|
14545
|
+
*/ p_() {
|
|
14546
|
+
this.m_ = this.V_;
|
|
14525
14547
|
}
|
|
14526
14548
|
/**
|
|
14527
14549
|
* Returns a promise that resolves after currentDelayMs, and increases the
|
|
14528
14550
|
* delay for any subsequent attempts. If there was a pending backoff operation
|
|
14529
14551
|
* already, it will be canceled.
|
|
14530
|
-
*/
|
|
14552
|
+
*/ y_(e) {
|
|
14531
14553
|
// Cancel any pending backoff operation.
|
|
14532
14554
|
this.cancel();
|
|
14533
14555
|
// First schedule using the current base (which may be 0 and should be
|
|
14534
14556
|
// honored as such).
|
|
14535
|
-
const t = Math.floor(this.
|
|
14557
|
+
const t = Math.floor(this.m_ + this.w_()), n = Math.max(0, Date.now() - this.g_), r = Math.max(0, t - n);
|
|
14536
14558
|
// Guard against lastAttemptTime being in the future due to a clock change.
|
|
14537
|
-
r > 0 && __PRIVATE_logDebug("ExponentialBackoff", `Backing off for ${r} ms (base delay: ${this.
|
|
14538
|
-
this.
|
|
14559
|
+
r > 0 && __PRIVATE_logDebug("ExponentialBackoff", `Backing off for ${r} ms (base delay: ${this.m_} ms, delay with jitter: ${t} ms, last attempt: ${n} ms ago)`),
|
|
14560
|
+
this.f_ = this.xi.enqueueAfterDelay(this.timerId, r, (() => (this.g_ = Date.now(),
|
|
14539
14561
|
e()))),
|
|
14540
14562
|
// Apply backoff factor to determine next delay and ensure it is within
|
|
14541
14563
|
// bounds.
|
|
14542
|
-
this.
|
|
14564
|
+
this.m_ *= this.R_, this.m_ < this.A_ && (this.m_ = this.A_), this.m_ > this.V_ && (this.m_ = this.V_);
|
|
14543
14565
|
}
|
|
14544
|
-
|
|
14545
|
-
null !== this.
|
|
14566
|
+
b_() {
|
|
14567
|
+
null !== this.f_ && (this.f_.skipDelay(), this.f_ = null);
|
|
14546
14568
|
}
|
|
14547
14569
|
cancel() {
|
|
14548
|
-
null !== this.
|
|
14570
|
+
null !== this.f_ && (this.f_.cancel(), this.f_ = null);
|
|
14549
14571
|
}
|
|
14550
|
-
/** Returns a random value in the range [-currentBaseMs/2, currentBaseMs/2] */
|
|
14551
|
-
return (Math.random() - .5) * this.
|
|
14572
|
+
/** Returns a random value in the range [-currentBaseMs/2, currentBaseMs/2] */ w_() {
|
|
14573
|
+
return (Math.random() - .5) * this.m_;
|
|
14552
14574
|
}
|
|
14553
14575
|
}
|
|
14554
14576
|
|
|
@@ -14604,18 +14626,18 @@ class __PRIVATE_ExponentialBackoff {
|
|
|
14604
14626
|
*/
|
|
14605
14627
|
class __PRIVATE_PersistentStream {
|
|
14606
14628
|
constructor(e, t, n, r, i, s, o, _) {
|
|
14607
|
-
this.xi = e, this.
|
|
14629
|
+
this.xi = e, this.S_ = n, this.D_ = r, this.connection = i, this.authCredentialsProvider = s,
|
|
14608
14630
|
this.appCheckCredentialsProvider = o, this.listener = _, this.state = 0 /* PersistentStreamState.Initial */ ,
|
|
14609
14631
|
/**
|
|
14610
14632
|
* A close count that's incremented every time the stream is closed; used by
|
|
14611
14633
|
* getCloseGuardedDispatcher() to invalidate callbacks that happen after
|
|
14612
14634
|
* close.
|
|
14613
14635
|
*/
|
|
14614
|
-
this.
|
|
14636
|
+
this.v_ = 0, this.C_ = null, this.F_ = null, this.stream = null,
|
|
14615
14637
|
/**
|
|
14616
14638
|
* Count of response messages received.
|
|
14617
14639
|
*/
|
|
14618
|
-
this.
|
|
14640
|
+
this.M_ = 0, this.x_ = new __PRIVATE_ExponentialBackoff(e, t);
|
|
14619
14641
|
}
|
|
14620
14642
|
/**
|
|
14621
14643
|
* Returns true if start() has been called and no error has occurred. True
|
|
@@ -14623,13 +14645,13 @@ class __PRIVATE_PersistentStream {
|
|
|
14623
14645
|
* encompasses respecting backoff, getting auth tokens, and starting the
|
|
14624
14646
|
* actual RPC). Use isOpen() to determine if the stream is open and ready for
|
|
14625
14647
|
* outbound requests.
|
|
14626
|
-
*/
|
|
14627
|
-
return 1 /* PersistentStreamState.Starting */ === this.state || 5 /* PersistentStreamState.Backoff */ === this.state || this.
|
|
14648
|
+
*/ O_() {
|
|
14649
|
+
return 1 /* PersistentStreamState.Starting */ === this.state || 5 /* PersistentStreamState.Backoff */ === this.state || this.N_();
|
|
14628
14650
|
}
|
|
14629
14651
|
/**
|
|
14630
14652
|
* Returns true if the underlying RPC is open (the onOpen() listener has been
|
|
14631
14653
|
* called) and the stream is ready for outbound requests.
|
|
14632
|
-
*/
|
|
14654
|
+
*/ N_() {
|
|
14633
14655
|
return 2 /* PersistentStreamState.Open */ === this.state || 3 /* PersistentStreamState.Healthy */ === this.state;
|
|
14634
14656
|
}
|
|
14635
14657
|
/**
|
|
@@ -14639,7 +14661,7 @@ class __PRIVATE_PersistentStream {
|
|
|
14639
14661
|
*
|
|
14640
14662
|
* When start returns, isStarted() will return true.
|
|
14641
14663
|
*/ start() {
|
|
14642
|
-
this.
|
|
14664
|
+
this.M_ = 0, 4 /* PersistentStreamState.Error */ !== this.state ? this.auth() : this.B_();
|
|
14643
14665
|
}
|
|
14644
14666
|
/**
|
|
14645
14667
|
* Stops the RPC. This call is idempotent and allowed regardless of the
|
|
@@ -14647,7 +14669,7 @@ class __PRIVATE_PersistentStream {
|
|
|
14647
14669
|
*
|
|
14648
14670
|
* When stop returns, isStarted() and isOpen() will both return false.
|
|
14649
14671
|
*/ async stop() {
|
|
14650
|
-
this.
|
|
14672
|
+
this.O_() && await this.close(0 /* PersistentStreamState.Initial */);
|
|
14651
14673
|
}
|
|
14652
14674
|
/**
|
|
14653
14675
|
* After an error the stream will usually back off on the next attempt to
|
|
@@ -14656,8 +14678,8 @@ class __PRIVATE_PersistentStream {
|
|
|
14656
14678
|
*
|
|
14657
14679
|
* Each error will call the onClose() listener. That function can decide to
|
|
14658
14680
|
* inhibit backoff if required.
|
|
14659
|
-
*/
|
|
14660
|
-
this.state = 0 /* PersistentStreamState.Initial */ , this.
|
|
14681
|
+
*/ L_() {
|
|
14682
|
+
this.state = 0 /* PersistentStreamState.Initial */ , this.x_.reset();
|
|
14661
14683
|
}
|
|
14662
14684
|
/**
|
|
14663
14685
|
* Marks this stream as idle. If no further actions are performed on the
|
|
@@ -14668,25 +14690,25 @@ class __PRIVATE_PersistentStream {
|
|
|
14668
14690
|
*
|
|
14669
14691
|
* Only streams that are in state 'Open' can be marked idle, as all other
|
|
14670
14692
|
* states imply pending network operations.
|
|
14671
|
-
*/
|
|
14693
|
+
*/ k_() {
|
|
14672
14694
|
// Starts the idle time if we are in state 'Open' and are not yet already
|
|
14673
14695
|
// running a timer (in which case the previous idle timeout still applies).
|
|
14674
|
-
this.
|
|
14696
|
+
this.N_() && null === this.C_ && (this.C_ = this.xi.enqueueAfterDelay(this.S_, 6e4, (() => this.q_())));
|
|
14675
14697
|
}
|
|
14676
|
-
/** Sends a message to the underlying stream. */
|
|
14677
|
-
this.
|
|
14698
|
+
/** Sends a message to the underlying stream. */ Q_(e) {
|
|
14699
|
+
this.U_(), this.stream.send(e);
|
|
14678
14700
|
}
|
|
14679
|
-
/** Called by the idle timer when the stream should close due to inactivity. */ async
|
|
14680
|
-
if (this.
|
|
14701
|
+
/** Called by the idle timer when the stream should close due to inactivity. */ async q_() {
|
|
14702
|
+
if (this.N_())
|
|
14681
14703
|
// When timing out an idle stream there's no reason to force the stream into backoff when
|
|
14682
14704
|
// it restarts so set the stream state to Initial instead of Error.
|
|
14683
14705
|
return this.close(0 /* PersistentStreamState.Initial */);
|
|
14684
14706
|
}
|
|
14685
|
-
/** Marks the stream as active again. */
|
|
14686
|
-
this.
|
|
14707
|
+
/** Marks the stream as active again. */ U_() {
|
|
14708
|
+
this.C_ && (this.C_.cancel(), this.C_ = null);
|
|
14687
14709
|
}
|
|
14688
|
-
/** Cancels the health check delayed operation. */
|
|
14689
|
-
this.
|
|
14710
|
+
/** Cancels the health check delayed operation. */ K_() {
|
|
14711
|
+
this.F_ && (this.F_.cancel(), this.F_ = null);
|
|
14690
14712
|
}
|
|
14691
14713
|
/**
|
|
14692
14714
|
* Closes the stream and cleans up as necessary:
|
|
@@ -14702,15 +14724,15 @@ class __PRIVATE_PersistentStream {
|
|
|
14702
14724
|
* @param error - the error the connection was closed with.
|
|
14703
14725
|
*/ async close(e, t) {
|
|
14704
14726
|
// Cancel any outstanding timers (they're guaranteed not to execute).
|
|
14705
|
-
this.
|
|
14727
|
+
this.U_(), this.K_(), this.x_.cancel(),
|
|
14706
14728
|
// Invalidates any stream-related callbacks (e.g. from auth or the
|
|
14707
14729
|
// underlying stream), guaranteeing they won't execute.
|
|
14708
|
-
this.
|
|
14730
|
+
this.v_++, 4 /* PersistentStreamState.Error */ !== e ?
|
|
14709
14731
|
// If this is an intentional close ensure we don't delay our next connection attempt.
|
|
14710
|
-
this.
|
|
14732
|
+
this.x_.reset() : t && t.code === N.RESOURCE_EXHAUSTED ? (
|
|
14711
14733
|
// Log the error. (Probably either 'quota exceeded' or 'max queue length reached'.)
|
|
14712
14734
|
__PRIVATE_logError(t.toString()), __PRIVATE_logError("Using maximum backoff delay to prevent overloading the backend."),
|
|
14713
|
-
this.
|
|
14735
|
+
this.x_.p_()) : t && t.code === N.UNAUTHENTICATED && 3 /* PersistentStreamState.Healthy */ !== this.state && (
|
|
14714
14736
|
// "unauthenticated" error means the token was rejected. This should rarely
|
|
14715
14737
|
// happen since both Auth and AppCheck ensure a sufficient TTL when we
|
|
14716
14738
|
// request a token. If a user manually resets their system clock this can
|
|
@@ -14719,7 +14741,7 @@ class __PRIVATE_PersistentStream {
|
|
|
14719
14741
|
// to ensure that we fetch a new token.
|
|
14720
14742
|
this.authCredentialsProvider.invalidateToken(), this.appCheckCredentialsProvider.invalidateToken()),
|
|
14721
14743
|
// Clean up the underlying stream because we are no longer interested in events.
|
|
14722
|
-
null !== this.stream && (this.
|
|
14744
|
+
null !== this.stream && (this.W_(), this.stream.close(), this.stream = null),
|
|
14723
14745
|
// This state must be assigned before calling onClose() to allow the callback to
|
|
14724
14746
|
// inhibit backoff or otherwise manipulate the state in its non-started state.
|
|
14725
14747
|
this.state = e,
|
|
@@ -14729,48 +14751,48 @@ class __PRIVATE_PersistentStream {
|
|
|
14729
14751
|
/**
|
|
14730
14752
|
* Can be overridden to perform additional cleanup before the stream is closed.
|
|
14731
14753
|
* Calling super.tearDown() is not required.
|
|
14732
|
-
*/
|
|
14754
|
+
*/ W_() {}
|
|
14733
14755
|
auth() {
|
|
14734
14756
|
this.state = 1 /* PersistentStreamState.Starting */;
|
|
14735
|
-
const e = this.
|
|
14757
|
+
const e = this.G_(this.v_), t = this.v_;
|
|
14736
14758
|
// TODO(mikelehen): Just use dispatchIfNotClosed, but see TODO below.
|
|
14737
14759
|
Promise.all([ this.authCredentialsProvider.getToken(), this.appCheckCredentialsProvider.getToken() ]).then((([e, n]) => {
|
|
14738
14760
|
// Stream can be stopped while waiting for authentication.
|
|
14739
14761
|
// TODO(mikelehen): We really should just use dispatchIfNotClosed
|
|
14740
14762
|
// and let this dispatch onto the queue, but that opened a spec test can
|
|
14741
14763
|
// of worms that I don't want to deal with in this PR.
|
|
14742
|
-
this.
|
|
14764
|
+
this.v_ === t &&
|
|
14743
14765
|
// Normally we'd have to schedule the callback on the AsyncQueue.
|
|
14744
14766
|
// However, the following calls are safe to be called outside the
|
|
14745
14767
|
// AsyncQueue since they don't chain asynchronous calls
|
|
14746
|
-
this.
|
|
14768
|
+
this.z_(e, n);
|
|
14747
14769
|
}), (t => {
|
|
14748
14770
|
e((() => {
|
|
14749
14771
|
const e = new FirestoreError(N.UNKNOWN, "Fetching auth token failed: " + t.message);
|
|
14750
|
-
return this.
|
|
14772
|
+
return this.j_(e);
|
|
14751
14773
|
}));
|
|
14752
14774
|
}));
|
|
14753
14775
|
}
|
|
14754
|
-
|
|
14755
|
-
const n = this.
|
|
14756
|
-
this.stream = this.
|
|
14776
|
+
z_(e, t) {
|
|
14777
|
+
const n = this.G_(this.v_);
|
|
14778
|
+
this.stream = this.H_(e, t), this.stream.e_((() => {
|
|
14757
14779
|
n((() => this.listener.e_()));
|
|
14758
14780
|
})), this.stream.n_((() => {
|
|
14759
|
-
n((() => (this.state = 2 /* PersistentStreamState.Open */ , this.
|
|
14781
|
+
n((() => (this.state = 2 /* PersistentStreamState.Open */ , this.F_ = this.xi.enqueueAfterDelay(this.D_, 1e4, (() => (this.N_() && (this.state = 3 /* PersistentStreamState.Healthy */),
|
|
14760
14782
|
Promise.resolve()))), this.listener.n_())));
|
|
14761
14783
|
})), this.stream.i_((e => {
|
|
14762
|
-
n((() => this.
|
|
14784
|
+
n((() => this.j_(e)));
|
|
14763
14785
|
})), this.stream.onMessage((e => {
|
|
14764
|
-
n((() => 1 == ++this.
|
|
14786
|
+
n((() => 1 == ++this.M_ ? this.J_(e) : this.onNext(e)));
|
|
14765
14787
|
}));
|
|
14766
14788
|
}
|
|
14767
|
-
|
|
14768
|
-
this.state = 5 /* PersistentStreamState.Backoff */ , this.
|
|
14789
|
+
B_() {
|
|
14790
|
+
this.state = 5 /* PersistentStreamState.Backoff */ , this.x_.y_((async () => {
|
|
14769
14791
|
this.state = 0 /* PersistentStreamState.Initial */ , this.start();
|
|
14770
14792
|
}));
|
|
14771
14793
|
}
|
|
14772
14794
|
// Visible for tests
|
|
14773
|
-
|
|
14795
|
+
j_(e) {
|
|
14774
14796
|
// In theory the stream could close cleanly, however, in our current model
|
|
14775
14797
|
// we never expect this to happen because if we stop a stream ourselves,
|
|
14776
14798
|
// this callback will never be called. To prevent cases where we retry
|
|
@@ -14782,9 +14804,9 @@ class __PRIVATE_PersistentStream {
|
|
|
14782
14804
|
* AsyncQueue but only runs them if closeCount remains unchanged. This allows
|
|
14783
14805
|
* us to turn auth / stream callbacks into no-ops if the stream is closed /
|
|
14784
14806
|
* re-opened, etc.
|
|
14785
|
-
*/
|
|
14807
|
+
*/ G_(e) {
|
|
14786
14808
|
return t => {
|
|
14787
|
-
this.xi.enqueueAndForget((() => this.
|
|
14809
|
+
this.xi.enqueueAndForget((() => this.v_ === e ? t() : (__PRIVATE_logDebug(Zt, "stream callback skipped by getCloseGuardedDispatcher."),
|
|
14788
14810
|
Promise.resolve())));
|
|
14789
14811
|
};
|
|
14790
14812
|
}
|
|
@@ -14801,15 +14823,15 @@ class __PRIVATE_PersistentStream {
|
|
|
14801
14823
|
super(e, "listen_stream_connection_backoff" /* TimerId.ListenStreamConnectionBackoff */ , "listen_stream_idle" /* TimerId.ListenStreamIdle */ , "health_check_timeout" /* TimerId.HealthCheckTimeout */ , t, n, r, s),
|
|
14802
14824
|
this.serializer = i;
|
|
14803
14825
|
}
|
|
14804
|
-
|
|
14805
|
-
return this.connection.
|
|
14826
|
+
H_(e, t) {
|
|
14827
|
+
return this.connection.I_("Listen", e, t);
|
|
14806
14828
|
}
|
|
14807
|
-
|
|
14829
|
+
J_(e) {
|
|
14808
14830
|
return this.onNext(e);
|
|
14809
14831
|
}
|
|
14810
14832
|
onNext(e) {
|
|
14811
14833
|
// A successful response means the stream is healthy
|
|
14812
|
-
this.
|
|
14834
|
+
this.x_.reset();
|
|
14813
14835
|
const t = __PRIVATE_fromWatchChange(this.serializer, e), n = function __PRIVATE_versionFromListenResponse(e) {
|
|
14814
14836
|
// We have only reached a consistent snapshot for the entire stream if there
|
|
14815
14837
|
// is a read_time set and it applies to all targets (i.e. the list of
|
|
@@ -14818,14 +14840,14 @@ class __PRIVATE_PersistentStream {
|
|
|
14818
14840
|
const t = e.targetChange;
|
|
14819
14841
|
return t.targetIds && t.targetIds.length ? SnapshotVersion.min() : t.readTime ? __PRIVATE_fromVersion(t.readTime) : SnapshotVersion.min();
|
|
14820
14842
|
}(e);
|
|
14821
|
-
return this.listener.
|
|
14843
|
+
return this.listener.Y_(t, n);
|
|
14822
14844
|
}
|
|
14823
14845
|
/**
|
|
14824
14846
|
* Registers interest in the results of the given target. If the target
|
|
14825
14847
|
* includes a resumeToken it will be included in the request. Results that
|
|
14826
14848
|
* affect the target will be streamed back as WatchChange messages that
|
|
14827
14849
|
* reference the targetId.
|
|
14828
|
-
*/
|
|
14850
|
+
*/ Z_(e) {
|
|
14829
14851
|
const t = {};
|
|
14830
14852
|
t.database = __PRIVATE_getEncodedDatabaseId(this.serializer), t.addTarget = function __PRIVATE_toTarget(e, t) {
|
|
14831
14853
|
let n;
|
|
@@ -14849,15 +14871,15 @@ class __PRIVATE_PersistentStream {
|
|
|
14849
14871
|
return n;
|
|
14850
14872
|
}(this.serializer, e);
|
|
14851
14873
|
const n = __PRIVATE_toListenRequestLabels(this.serializer, e);
|
|
14852
|
-
n && (t.labels = n), this.
|
|
14874
|
+
n && (t.labels = n), this.Q_(t);
|
|
14853
14875
|
}
|
|
14854
14876
|
/**
|
|
14855
14877
|
* Unregisters interest in the results of the target associated with the
|
|
14856
14878
|
* given targetId.
|
|
14857
|
-
*/
|
|
14879
|
+
*/ X_(e) {
|
|
14858
14880
|
const t = {};
|
|
14859
14881
|
t.database = __PRIVATE_getEncodedDatabaseId(this.serializer), t.removeTarget = e,
|
|
14860
|
-
this.
|
|
14882
|
+
this.Q_(t);
|
|
14861
14883
|
}
|
|
14862
14884
|
}
|
|
14863
14885
|
|
|
@@ -14885,24 +14907,24 @@ class __PRIVATE_PersistentStream {
|
|
|
14885
14907
|
/**
|
|
14886
14908
|
* Tracks whether or not a handshake has been successfully exchanged and
|
|
14887
14909
|
* the stream is ready to accept mutations.
|
|
14888
|
-
*/ get
|
|
14889
|
-
return this.
|
|
14910
|
+
*/ get ea() {
|
|
14911
|
+
return this.M_ > 0;
|
|
14890
14912
|
}
|
|
14891
14913
|
// Override of PersistentStream.start
|
|
14892
14914
|
start() {
|
|
14893
14915
|
this.lastStreamToken = void 0, super.start();
|
|
14894
14916
|
}
|
|
14895
|
-
|
|
14896
|
-
this.
|
|
14917
|
+
W_() {
|
|
14918
|
+
this.ea && this.ta([]);
|
|
14897
14919
|
}
|
|
14898
|
-
|
|
14899
|
-
return this.connection.
|
|
14920
|
+
H_(e, t) {
|
|
14921
|
+
return this.connection.I_("Write", e, t);
|
|
14900
14922
|
}
|
|
14901
|
-
|
|
14923
|
+
J_(e) {
|
|
14902
14924
|
// Always capture the last stream token.
|
|
14903
14925
|
return __PRIVATE_hardAssert(!!e.streamToken, 31322), this.lastStreamToken = e.streamToken,
|
|
14904
14926
|
// The first response is always the handshake response
|
|
14905
|
-
__PRIVATE_hardAssert(!e.writeResults || 0 === e.writeResults.length, 55816), this.listener.
|
|
14927
|
+
__PRIVATE_hardAssert(!e.writeResults || 0 === e.writeResults.length, 55816), this.listener.na();
|
|
14906
14928
|
}
|
|
14907
14929
|
onNext(e) {
|
|
14908
14930
|
// Always capture the last stream token.
|
|
@@ -14910,26 +14932,26 @@ class __PRIVATE_PersistentStream {
|
|
|
14910
14932
|
// A successful first write response means the stream is healthy,
|
|
14911
14933
|
// Note, that we could consider a successful handshake healthy, however,
|
|
14912
14934
|
// the write itself might be causing an error we want to back off from.
|
|
14913
|
-
this.
|
|
14935
|
+
this.x_.reset();
|
|
14914
14936
|
const t = __PRIVATE_fromWriteResults(e.writeResults, e.commitTime), n = __PRIVATE_fromVersion(e.commitTime);
|
|
14915
|
-
return this.listener.
|
|
14937
|
+
return this.listener.ra(n, t);
|
|
14916
14938
|
}
|
|
14917
14939
|
/**
|
|
14918
14940
|
* Sends an initial streamToken to the server, performing the handshake
|
|
14919
14941
|
* required to make the StreamingWrite RPC work. Subsequent
|
|
14920
14942
|
* calls should wait until onHandshakeComplete was called.
|
|
14921
|
-
*/
|
|
14943
|
+
*/ ia() {
|
|
14922
14944
|
// TODO(dimond): Support stream resumption. We intentionally do not set the
|
|
14923
14945
|
// stream token on the handshake, ignoring any stream token we might have.
|
|
14924
14946
|
const e = {};
|
|
14925
|
-
e.database = __PRIVATE_getEncodedDatabaseId(this.serializer), this.
|
|
14947
|
+
e.database = __PRIVATE_getEncodedDatabaseId(this.serializer), this.Q_(e);
|
|
14926
14948
|
}
|
|
14927
|
-
/** Sends a group of mutations to the Firestore backend to apply. */
|
|
14949
|
+
/** Sends a group of mutations to the Firestore backend to apply. */ ta(e) {
|
|
14928
14950
|
const t = {
|
|
14929
14951
|
streamToken: this.lastStreamToken,
|
|
14930
14952
|
writes: e.map((e => toMutation(this.serializer, e)))
|
|
14931
14953
|
};
|
|
14932
|
-
this.
|
|
14954
|
+
this.Q_(t);
|
|
14933
14955
|
}
|
|
14934
14956
|
}
|
|
14935
14957
|
|
|
@@ -14961,25 +14983,25 @@ class __PRIVATE_PersistentStream {
|
|
|
14961
14983
|
*/ class __PRIVATE_DatastoreImpl extends Datastore {
|
|
14962
14984
|
constructor(e, t, n, r) {
|
|
14963
14985
|
super(), this.authCredentials = e, this.appCheckCredentials = t, this.connection = n,
|
|
14964
|
-
this.serializer = r, this.
|
|
14986
|
+
this.serializer = r, this.sa = !1;
|
|
14965
14987
|
}
|
|
14966
|
-
|
|
14967
|
-
if (this.
|
|
14988
|
+
oa() {
|
|
14989
|
+
if (this.sa) throw new FirestoreError(N.FAILED_PRECONDITION, "The client has already been terminated.");
|
|
14968
14990
|
}
|
|
14969
14991
|
/** Invokes the provided RPC with auth and AppCheck tokens. */ zo(e, t, n, r) {
|
|
14970
|
-
return this.
|
|
14992
|
+
return this.oa(), Promise.all([ this.authCredentials.getToken(), this.appCheckCredentials.getToken() ]).then((([i, s]) => this.connection.zo(e, __PRIVATE_toResourcePath(t, n), r, i, s))).catch((e => {
|
|
14971
14993
|
throw "FirebaseError" === e.name ? (e.code === N.UNAUTHENTICATED && (this.authCredentials.invalidateToken(),
|
|
14972
14994
|
this.appCheckCredentials.invalidateToken()), e) : new FirestoreError(N.UNKNOWN, e.toString());
|
|
14973
14995
|
}));
|
|
14974
14996
|
}
|
|
14975
14997
|
/** Invokes the provided RPC with streamed results with auth and AppCheck tokens. */ Yo(e, t, n, r, i) {
|
|
14976
|
-
return this.
|
|
14998
|
+
return this.oa(), Promise.all([ this.authCredentials.getToken(), this.appCheckCredentials.getToken() ]).then((([s, o]) => this.connection.Yo(e, __PRIVATE_toResourcePath(t, n), r, s, o, i))).catch((e => {
|
|
14977
14999
|
throw "FirebaseError" === e.name ? (e.code === N.UNAUTHENTICATED && (this.authCredentials.invalidateToken(),
|
|
14978
15000
|
this.appCheckCredentials.invalidateToken()), e) : new FirestoreError(N.UNKNOWN, e.toString());
|
|
14979
15001
|
}));
|
|
14980
15002
|
}
|
|
14981
15003
|
terminate() {
|
|
14982
|
-
this.
|
|
15004
|
+
this.sa = !0, this.connection.terminate();
|
|
14983
15005
|
}
|
|
14984
15006
|
}
|
|
14985
15007
|
|
|
@@ -15006,19 +15028,19 @@ class __PRIVATE_OnlineStateTracker {
|
|
|
15006
15028
|
* maximum defined by MAX_WATCH_STREAM_FAILURES, we'll set the OnlineState to
|
|
15007
15029
|
* Offline.
|
|
15008
15030
|
*/
|
|
15009
|
-
this.
|
|
15031
|
+
this._a = 0,
|
|
15010
15032
|
/**
|
|
15011
15033
|
* A timer that elapses after ONLINE_STATE_TIMEOUT_MS, at which point we
|
|
15012
15034
|
* transition from OnlineState.Unknown to OnlineState.Offline without waiting
|
|
15013
15035
|
* for the stream to actually fail (MAX_WATCH_STREAM_FAILURES times).
|
|
15014
15036
|
*/
|
|
15015
|
-
this.
|
|
15037
|
+
this.aa = null,
|
|
15016
15038
|
/**
|
|
15017
15039
|
* Whether the client should log a warning message if it fails to connect to
|
|
15018
15040
|
* the backend (initially true, cleared after a successful stream, or if we've
|
|
15019
15041
|
* logged the message already).
|
|
15020
15042
|
*/
|
|
15021
|
-
this.
|
|
15043
|
+
this.ua = !0;
|
|
15022
15044
|
}
|
|
15023
15045
|
/**
|
|
15024
15046
|
* Called by RemoteStore when a watch stream is started (including on each
|
|
@@ -15026,9 +15048,9 @@ class __PRIVATE_OnlineStateTracker {
|
|
|
15026
15048
|
*
|
|
15027
15049
|
* If this is the first attempt, it sets the OnlineState to Unknown and starts
|
|
15028
15050
|
* the onlineStateTimer.
|
|
15029
|
-
*/
|
|
15030
|
-
0 === this.
|
|
15031
|
-
this.
|
|
15051
|
+
*/ ca() {
|
|
15052
|
+
0 === this._a && (this.la("Unknown" /* OnlineState.Unknown */), this.aa = this.asyncQueue.enqueueAfterDelay("online_state_timeout" /* TimerId.OnlineStateTimeout */ , 1e4, (() => (this.aa = null,
|
|
15053
|
+
this.ha("Backend didn't respond within 10 seconds."), this.la("Offline" /* OnlineState.Offline */),
|
|
15032
15054
|
Promise.resolve()))));
|
|
15033
15055
|
}
|
|
15034
15056
|
/**
|
|
@@ -15036,10 +15058,10 @@ class __PRIVATE_OnlineStateTracker {
|
|
|
15036
15058
|
* failure. The first failure moves us to the 'Unknown' state. We then may
|
|
15037
15059
|
* allow multiple failures (based on MAX_WATCH_STREAM_FAILURES) before we
|
|
15038
15060
|
* actually transition to the 'Offline' state.
|
|
15039
|
-
*/
|
|
15040
|
-
"Online" /* OnlineState.Online */ === this.state ? this.
|
|
15041
|
-
this.
|
|
15042
|
-
this.
|
|
15061
|
+
*/ Pa(e) {
|
|
15062
|
+
"Online" /* OnlineState.Online */ === this.state ? this.la("Unknown" /* OnlineState.Unknown */) : (this._a++,
|
|
15063
|
+
this._a >= 1 && (this.Ta(), this.ha(`Connection failed 1 times. Most recent error: ${e.toString()}`),
|
|
15064
|
+
this.la("Offline" /* OnlineState.Offline */)));
|
|
15043
15065
|
}
|
|
15044
15066
|
/**
|
|
15045
15067
|
* Explicitly sets the OnlineState to the specified state.
|
|
@@ -15048,20 +15070,20 @@ class __PRIVATE_OnlineStateTracker {
|
|
|
15048
15070
|
* Offline heuristics, so must not be used in place of
|
|
15049
15071
|
* handleWatchStreamStart() and handleWatchStreamFailure().
|
|
15050
15072
|
*/ set(e) {
|
|
15051
|
-
this.
|
|
15073
|
+
this.Ta(), this._a = 0, "Online" /* OnlineState.Online */ === e && (
|
|
15052
15074
|
// We've connected to watch at least once. Don't warn the developer
|
|
15053
15075
|
// about being offline going forward.
|
|
15054
|
-
this.
|
|
15076
|
+
this.ua = !1), this.la(e);
|
|
15055
15077
|
}
|
|
15056
|
-
|
|
15078
|
+
la(e) {
|
|
15057
15079
|
e !== this.state && (this.state = e, this.onlineStateHandler(e));
|
|
15058
15080
|
}
|
|
15059
|
-
|
|
15081
|
+
ha(e) {
|
|
15060
15082
|
const t = `Could not reach Cloud Firestore backend. ${e}\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.`;
|
|
15061
|
-
this.
|
|
15083
|
+
this.ua ? (__PRIVATE_logError(t), this.ua = !1) : __PRIVATE_logDebug("OnlineStateTracker", t);
|
|
15062
15084
|
}
|
|
15063
|
-
|
|
15064
|
-
null !== this.
|
|
15085
|
+
Ta() {
|
|
15086
|
+
null !== this.aa && (this.aa.cancel(), this.aa = null);
|
|
15065
15087
|
}
|
|
15066
15088
|
}
|
|
15067
15089
|
|
|
@@ -15109,7 +15131,7 @@ class __PRIVATE_RemoteStoreImpl {
|
|
|
15109
15131
|
* purely based on order, and so we can just shift() writes from the front of
|
|
15110
15132
|
* the writePipeline as we receive responses.
|
|
15111
15133
|
*/
|
|
15112
|
-
this.
|
|
15134
|
+
this.Ia = [],
|
|
15113
15135
|
/**
|
|
15114
15136
|
* A mapping of watched targets that the client cares about tracking and the
|
|
15115
15137
|
* user has explicitly called a 'listen' for this target.
|
|
@@ -15119,12 +15141,12 @@ class __PRIVATE_RemoteStoreImpl {
|
|
|
15119
15141
|
* to the server. The targets removed with unlistens are removed eagerly
|
|
15120
15142
|
* without waiting for confirmation from the listen stream.
|
|
15121
15143
|
*/
|
|
15122
|
-
this.
|
|
15144
|
+
this.Ea = new Map,
|
|
15123
15145
|
/**
|
|
15124
15146
|
* A set of reasons for why the RemoteStore may be offline. If empty, the
|
|
15125
15147
|
* RemoteStore may start its network connections.
|
|
15126
15148
|
*/
|
|
15127
|
-
this.
|
|
15149
|
+
this.da = new Set,
|
|
15128
15150
|
/**
|
|
15129
15151
|
* Event handlers that get called when the network is disabled or enabled.
|
|
15130
15152
|
*
|
|
@@ -15132,7 +15154,7 @@ class __PRIVATE_RemoteStoreImpl {
|
|
|
15132
15154
|
* underlying streams (to support tree-shakeable streams). On Android and iOS,
|
|
15133
15155
|
* the streams are created during construction of RemoteStore.
|
|
15134
15156
|
*/
|
|
15135
|
-
this.
|
|
15157
|
+
this.Aa = [], this.Ra = i, this.Ra.No((e => {
|
|
15136
15158
|
n.enqueueAndForget((async () => {
|
|
15137
15159
|
// Porting Note: Unlike iOS, `restartNetwork()` is called even when the
|
|
15138
15160
|
// network becomes unreachable as we don't have any other way to tear
|
|
@@ -15140,24 +15162,24 @@ class __PRIVATE_RemoteStoreImpl {
|
|
|
15140
15162
|
__PRIVATE_canUseNetwork(this) && (__PRIVATE_logDebug(Xt, "Restarting streams for network reachability change."),
|
|
15141
15163
|
await async function __PRIVATE_restartNetwork(e) {
|
|
15142
15164
|
const t = __PRIVATE_debugCast(e);
|
|
15143
|
-
t.
|
|
15144
|
-
t.
|
|
15165
|
+
t.da.add(4 /* OfflineCause.ConnectivityChange */), await __PRIVATE_disableNetworkInternal(t),
|
|
15166
|
+
t.Va.set("Unknown" /* OnlineState.Unknown */), t.da.delete(4 /* OfflineCause.ConnectivityChange */),
|
|
15145
15167
|
await __PRIVATE_enableNetworkInternal(t);
|
|
15146
15168
|
}(this));
|
|
15147
15169
|
}));
|
|
15148
|
-
})), this.
|
|
15170
|
+
})), this.Va = new __PRIVATE_OnlineStateTracker(n, r);
|
|
15149
15171
|
}
|
|
15150
15172
|
}
|
|
15151
15173
|
|
|
15152
15174
|
async function __PRIVATE_enableNetworkInternal(e) {
|
|
15153
|
-
if (__PRIVATE_canUseNetwork(e)) for (const t of e.
|
|
15175
|
+
if (__PRIVATE_canUseNetwork(e)) for (const t of e.Aa) await t(/* enabled= */ !0);
|
|
15154
15176
|
}
|
|
15155
15177
|
|
|
15156
15178
|
/**
|
|
15157
15179
|
* Temporarily disables the network. The network can be re-enabled using
|
|
15158
15180
|
* enableNetwork().
|
|
15159
15181
|
*/ async function __PRIVATE_disableNetworkInternal(e) {
|
|
15160
|
-
for (const t of e.
|
|
15182
|
+
for (const t of e.Aa) await t(/* enabled= */ !1);
|
|
15161
15183
|
}
|
|
15162
15184
|
|
|
15163
15185
|
/**
|
|
@@ -15166,11 +15188,11 @@ async function __PRIVATE_enableNetworkInternal(e) {
|
|
|
15166
15188
|
*/
|
|
15167
15189
|
function __PRIVATE_remoteStoreListen(e, t) {
|
|
15168
15190
|
const n = __PRIVATE_debugCast(e);
|
|
15169
|
-
n.
|
|
15191
|
+
n.Ea.has(t.targetId) || (
|
|
15170
15192
|
// Mark this as something the client is currently listening for.
|
|
15171
|
-
n.
|
|
15193
|
+
n.Ea.set(t.targetId, t), __PRIVATE_shouldStartWatchStream(n) ?
|
|
15172
15194
|
// The listen will be sent in onWatchStreamOpen
|
|
15173
|
-
__PRIVATE_startWatchStream(n) : __PRIVATE_ensureWatchStream(n).
|
|
15195
|
+
__PRIVATE_startWatchStream(n) : __PRIVATE_ensureWatchStream(n).N_() && __PRIVATE_sendWatchRequest(n, t));
|
|
15174
15196
|
}
|
|
15175
15197
|
|
|
15176
15198
|
/**
|
|
@@ -15178,22 +15200,22 @@ function __PRIVATE_remoteStoreListen(e, t) {
|
|
|
15178
15200
|
* not being listened to.
|
|
15179
15201
|
*/ function __PRIVATE_remoteStoreUnlisten(e, t) {
|
|
15180
15202
|
const n = __PRIVATE_debugCast(e), r = __PRIVATE_ensureWatchStream(n);
|
|
15181
|
-
n.
|
|
15203
|
+
n.Ea.delete(t), r.N_() && __PRIVATE_sendUnwatchRequest(n, t), 0 === n.Ea.size && (r.N_() ? r.k_() : __PRIVATE_canUseNetwork(n) &&
|
|
15182
15204
|
// Revert to OnlineState.Unknown if the watch stream is not open and we
|
|
15183
15205
|
// have no listeners, since without any listens to send we cannot
|
|
15184
15206
|
// confirm if the stream is healthy and upgrade to OnlineState.Online.
|
|
15185
|
-
n.
|
|
15207
|
+
n.Va.set("Unknown" /* OnlineState.Unknown */));
|
|
15186
15208
|
}
|
|
15187
15209
|
|
|
15188
15210
|
/**
|
|
15189
15211
|
* We need to increment the expected number of pending responses we're due
|
|
15190
15212
|
* from watch so we wait for the ack to process any messages from this target.
|
|
15191
15213
|
*/ function __PRIVATE_sendWatchRequest(e, t) {
|
|
15192
|
-
if (e.
|
|
15214
|
+
if (e.ma.Ke(t.targetId), t.resumeToken.approximateByteSize() > 0 || t.snapshotVersion.compareTo(SnapshotVersion.min()) > 0) {
|
|
15193
15215
|
const n = e.remoteSyncer.getRemoteKeysForTarget(t.targetId).size;
|
|
15194
15216
|
t = t.withExpectedCount(n);
|
|
15195
15217
|
}
|
|
15196
|
-
__PRIVATE_ensureWatchStream(e).
|
|
15218
|
+
__PRIVATE_ensureWatchStream(e).Z_(t);
|
|
15197
15219
|
}
|
|
15198
15220
|
|
|
15199
15221
|
/**
|
|
@@ -15201,39 +15223,39 @@ function __PRIVATE_remoteStoreListen(e, t) {
|
|
|
15201
15223
|
* from watch so we wait for the removal on the server before we process any
|
|
15202
15224
|
* messages from this target.
|
|
15203
15225
|
*/ function __PRIVATE_sendUnwatchRequest(e, t) {
|
|
15204
|
-
e.
|
|
15226
|
+
e.ma.Ke(t), __PRIVATE_ensureWatchStream(e).X_(t);
|
|
15205
15227
|
}
|
|
15206
15228
|
|
|
15207
15229
|
function __PRIVATE_startWatchStream(e) {
|
|
15208
|
-
e.
|
|
15230
|
+
e.ma = new __PRIVATE_WatchChangeAggregator({
|
|
15209
15231
|
getRemoteKeysForTarget: t => e.remoteSyncer.getRemoteKeysForTarget(t),
|
|
15210
|
-
Rt: t => e.
|
|
15232
|
+
Rt: t => e.Ea.get(t) || null,
|
|
15211
15233
|
Pt: () => e.datastore.serializer.databaseId
|
|
15212
|
-
}), __PRIVATE_ensureWatchStream(e).start(), e.
|
|
15234
|
+
}), __PRIVATE_ensureWatchStream(e).start(), e.Va.ca();
|
|
15213
15235
|
}
|
|
15214
15236
|
|
|
15215
15237
|
/**
|
|
15216
15238
|
* Returns whether the watch stream should be started because it's necessary
|
|
15217
15239
|
* and has not yet been started.
|
|
15218
15240
|
*/ function __PRIVATE_shouldStartWatchStream(e) {
|
|
15219
|
-
return __PRIVATE_canUseNetwork(e) && !__PRIVATE_ensureWatchStream(e).
|
|
15241
|
+
return __PRIVATE_canUseNetwork(e) && !__PRIVATE_ensureWatchStream(e).O_() && e.Ea.size > 0;
|
|
15220
15242
|
}
|
|
15221
15243
|
|
|
15222
15244
|
function __PRIVATE_canUseNetwork(e) {
|
|
15223
|
-
return 0 === __PRIVATE_debugCast(e).
|
|
15245
|
+
return 0 === __PRIVATE_debugCast(e).da.size;
|
|
15224
15246
|
}
|
|
15225
15247
|
|
|
15226
15248
|
function __PRIVATE_cleanUpWatchStreamState(e) {
|
|
15227
|
-
e.
|
|
15249
|
+
e.ma = void 0;
|
|
15228
15250
|
}
|
|
15229
15251
|
|
|
15230
15252
|
async function __PRIVATE_onWatchStreamConnected(e) {
|
|
15231
15253
|
// Mark the client as online since we got a "connected" notification.
|
|
15232
|
-
e.
|
|
15254
|
+
e.Va.set("Online" /* OnlineState.Online */);
|
|
15233
15255
|
}
|
|
15234
15256
|
|
|
15235
15257
|
async function __PRIVATE_onWatchStreamOpen(e) {
|
|
15236
|
-
e.
|
|
15258
|
+
e.Ea.forEach(((t, n) => {
|
|
15237
15259
|
__PRIVATE_sendWatchRequest(e, t);
|
|
15238
15260
|
}));
|
|
15239
15261
|
}
|
|
@@ -15241,17 +15263,17 @@ async function __PRIVATE_onWatchStreamOpen(e) {
|
|
|
15241
15263
|
async function __PRIVATE_onWatchStreamClose(e, t) {
|
|
15242
15264
|
__PRIVATE_cleanUpWatchStreamState(e),
|
|
15243
15265
|
// If we still need the watch stream, retry the connection.
|
|
15244
|
-
__PRIVATE_shouldStartWatchStream(e) ? (e.
|
|
15266
|
+
__PRIVATE_shouldStartWatchStream(e) ? (e.Va.Pa(t), __PRIVATE_startWatchStream(e)) :
|
|
15245
15267
|
// No need to restart watch stream because there are no active targets.
|
|
15246
15268
|
// The online state is set to unknown because there is no active attempt
|
|
15247
15269
|
// at establishing a connection
|
|
15248
|
-
e.
|
|
15270
|
+
e.Va.set("Unknown" /* OnlineState.Unknown */);
|
|
15249
15271
|
}
|
|
15250
15272
|
|
|
15251
15273
|
async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
15252
15274
|
if (
|
|
15253
15275
|
// Mark the client as online since we got a message from the server
|
|
15254
|
-
e.
|
|
15276
|
+
e.Va.set("Online" /* OnlineState.Online */), t instanceof __PRIVATE_WatchTargetChange && 2 /* WatchTargetChangeState.Removed */ === t.state && t.cause)
|
|
15255
15277
|
// There was an error on a target, don't wait for a consistent snapshot
|
|
15256
15278
|
// to raise events
|
|
15257
15279
|
try {
|
|
@@ -15260,7 +15282,7 @@ async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
|
15260
15282
|
const n = t.cause;
|
|
15261
15283
|
for (const r of t.targetIds)
|
|
15262
15284
|
// A watched target might have been removed already.
|
|
15263
|
-
e.
|
|
15285
|
+
e.Ea.has(r) && (await e.remoteSyncer.rejectListen(r, n), e.Ea.delete(r), e.ma.removeTarget(r));
|
|
15264
15286
|
}
|
|
15265
15287
|
/**
|
|
15266
15288
|
* Attempts to fill our write pipeline with writes from the LocalStore.
|
|
@@ -15273,7 +15295,7 @@ async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
|
15273
15295
|
} catch (n) {
|
|
15274
15296
|
__PRIVATE_logDebug(Xt, "Failed to remove targets %s: %s ", t.targetIds.join(","), n),
|
|
15275
15297
|
await __PRIVATE_disableNetworkUntilRecovery(e, n);
|
|
15276
|
-
} else if (t instanceof __PRIVATE_DocumentWatchChange ? e.
|
|
15298
|
+
} else if (t instanceof __PRIVATE_DocumentWatchChange ? e.ma.Xe(t) : t instanceof __PRIVATE_ExistenceFilterChange ? e.ma.ot(t) : e.ma.nt(t),
|
|
15277
15299
|
!n.isEqual(SnapshotVersion.min())) try {
|
|
15278
15300
|
const t = await __PRIVATE_localStoreGetLastRemoteSnapshotVersion(e.localStore);
|
|
15279
15301
|
n.compareTo(t) >= 0 &&
|
|
@@ -15285,26 +15307,26 @@ async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
|
15285
15307
|
* SyncEngine.
|
|
15286
15308
|
*/
|
|
15287
15309
|
await function __PRIVATE_raiseWatchSnapshot(e, t) {
|
|
15288
|
-
const n = e.
|
|
15310
|
+
const n = e.ma.It(t);
|
|
15289
15311
|
// Update in-memory resume tokens. LocalStore will update the
|
|
15290
15312
|
// persistent view of these when applying the completed RemoteEvent.
|
|
15291
15313
|
return n.targetChanges.forEach(((n, r) => {
|
|
15292
15314
|
if (n.resumeToken.approximateByteSize() > 0) {
|
|
15293
|
-
const i = e.
|
|
15315
|
+
const i = e.Ea.get(r);
|
|
15294
15316
|
// A watched target might have been removed already.
|
|
15295
|
-
i && e.
|
|
15317
|
+
i && e.Ea.set(r, i.withResumeToken(n.resumeToken, t));
|
|
15296
15318
|
}
|
|
15297
15319
|
})),
|
|
15298
15320
|
// Re-establish listens for the targets that have been invalidated by
|
|
15299
15321
|
// existence filter mismatches.
|
|
15300
15322
|
n.targetMismatches.forEach(((t, n) => {
|
|
15301
|
-
const r = e.
|
|
15323
|
+
const r = e.Ea.get(t);
|
|
15302
15324
|
if (!r)
|
|
15303
15325
|
// A watched target might have been removed already.
|
|
15304
15326
|
return;
|
|
15305
15327
|
// Clear the resume token for the target, since we're in a known mismatch
|
|
15306
15328
|
// state.
|
|
15307
|
-
e.
|
|
15329
|
+
e.Ea.set(t, r.withResumeToken(ByteString.EMPTY_BYTE_STRING, r.snapshotVersion)),
|
|
15308
15330
|
// Cause a hard reset by unwatching and rewatching immediately, but
|
|
15309
15331
|
// deliberately don't send a resume token so that we get a full update.
|
|
15310
15332
|
__PRIVATE_sendUnwatchRequest(e, t);
|
|
@@ -15331,9 +15353,9 @@ async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
|
15331
15353
|
* any retry attempt.
|
|
15332
15354
|
*/ async function __PRIVATE_disableNetworkUntilRecovery(e, t, n) {
|
|
15333
15355
|
if (!__PRIVATE_isIndexedDbTransactionError(t)) throw t;
|
|
15334
|
-
e.
|
|
15356
|
+
e.da.add(1 /* OfflineCause.IndexedDbFailed */),
|
|
15335
15357
|
// Disable network and raise offline snapshots
|
|
15336
|
-
await __PRIVATE_disableNetworkInternal(e), e.
|
|
15358
|
+
await __PRIVATE_disableNetworkInternal(e), e.Va.set("Offline" /* OnlineState.Offline */),
|
|
15337
15359
|
n || (
|
|
15338
15360
|
// Use a simple read operation to determine if IndexedDB recovered.
|
|
15339
15361
|
// Ideally, we would expose a health check directly on SimpleDb, but
|
|
@@ -15341,7 +15363,7 @@ async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
|
15341
15363
|
n = () => __PRIVATE_localStoreGetLastRemoteSnapshotVersion(e.localStore)),
|
|
15342
15364
|
// Probe IndexedDB periodically and re-enable network
|
|
15343
15365
|
e.asyncQueue.enqueueRetryable((async () => {
|
|
15344
|
-
__PRIVATE_logDebug(Xt, "Retrying IndexedDB access"), await n(), e.
|
|
15366
|
+
__PRIVATE_logDebug(Xt, "Retrying IndexedDB access"), await n(), e.da.delete(1 /* OfflineCause.IndexedDbFailed */),
|
|
15345
15367
|
await __PRIVATE_enableNetworkInternal(e);
|
|
15346
15368
|
}));
|
|
15347
15369
|
}
|
|
@@ -15355,11 +15377,11 @@ async function __PRIVATE_onWatchStreamChange(e, t, n) {
|
|
|
15355
15377
|
|
|
15356
15378
|
async function __PRIVATE_fillWritePipeline(e) {
|
|
15357
15379
|
const t = __PRIVATE_debugCast(e), n = __PRIVATE_ensureWriteStream(t);
|
|
15358
|
-
let r = t.
|
|
15380
|
+
let r = t.Ia.length > 0 ? t.Ia[t.Ia.length - 1].batchId : G;
|
|
15359
15381
|
for (;__PRIVATE_canAddToWritePipeline(t); ) try {
|
|
15360
15382
|
const e = await __PRIVATE_localStoreGetNextMutationBatch(t.localStore, r);
|
|
15361
15383
|
if (null === e) {
|
|
15362
|
-
0 === t.
|
|
15384
|
+
0 === t.Ia.length && n.k_();
|
|
15363
15385
|
break;
|
|
15364
15386
|
}
|
|
15365
15387
|
r = e.batchId, __PRIVATE_addToWritePipeline(t, e);
|
|
@@ -15373,20 +15395,20 @@ async function __PRIVATE_fillWritePipeline(e) {
|
|
|
15373
15395
|
* Returns true if we can add to the write pipeline (i.e. the network is
|
|
15374
15396
|
* enabled and the write pipeline is not full).
|
|
15375
15397
|
*/ function __PRIVATE_canAddToWritePipeline(e) {
|
|
15376
|
-
return __PRIVATE_canUseNetwork(e) && e.
|
|
15398
|
+
return __PRIVATE_canUseNetwork(e) && e.Ia.length < 10;
|
|
15377
15399
|
}
|
|
15378
15400
|
|
|
15379
15401
|
/**
|
|
15380
15402
|
* Queues additional writes to be sent to the write stream, sending them
|
|
15381
15403
|
* immediately if the write stream is established.
|
|
15382
15404
|
*/ function __PRIVATE_addToWritePipeline(e, t) {
|
|
15383
|
-
e.
|
|
15405
|
+
e.Ia.push(t);
|
|
15384
15406
|
const n = __PRIVATE_ensureWriteStream(e);
|
|
15385
|
-
n.
|
|
15407
|
+
n.N_() && n.ea && n.ta(t.mutations);
|
|
15386
15408
|
}
|
|
15387
15409
|
|
|
15388
15410
|
function __PRIVATE_shouldStartWriteStream(e) {
|
|
15389
|
-
return __PRIVATE_canUseNetwork(e) && !__PRIVATE_ensureWriteStream(e).
|
|
15411
|
+
return __PRIVATE_canUseNetwork(e) && !__PRIVATE_ensureWriteStream(e).O_() && e.Ia.length > 0;
|
|
15390
15412
|
}
|
|
15391
15413
|
|
|
15392
15414
|
function __PRIVATE_startWriteStream(e) {
|
|
@@ -15394,17 +15416,17 @@ function __PRIVATE_startWriteStream(e) {
|
|
|
15394
15416
|
}
|
|
15395
15417
|
|
|
15396
15418
|
async function __PRIVATE_onWriteStreamOpen(e) {
|
|
15397
|
-
__PRIVATE_ensureWriteStream(e).
|
|
15419
|
+
__PRIVATE_ensureWriteStream(e).ia();
|
|
15398
15420
|
}
|
|
15399
15421
|
|
|
15400
15422
|
async function __PRIVATE_onWriteHandshakeComplete(e) {
|
|
15401
15423
|
const t = __PRIVATE_ensureWriteStream(e);
|
|
15402
15424
|
// Send the write pipeline now that the stream is established.
|
|
15403
|
-
for (const n of e.
|
|
15425
|
+
for (const n of e.Ia) t.ta(n.mutations);
|
|
15404
15426
|
}
|
|
15405
15427
|
|
|
15406
15428
|
async function __PRIVATE_onMutationResult(e, t, n) {
|
|
15407
|
-
const r = e.
|
|
15429
|
+
const r = e.Ia.shift(), i = MutationBatchResult.from(r, t, n);
|
|
15408
15430
|
await __PRIVATE_executeWithRecovery(e, (() => e.remoteSyncer.applySuccessfulWrite(i))),
|
|
15409
15431
|
// It's possible that with the completion of this mutation another
|
|
15410
15432
|
// slot has freed up.
|
|
@@ -15414,7 +15436,7 @@ async function __PRIVATE_onMutationResult(e, t, n) {
|
|
|
15414
15436
|
async function __PRIVATE_onWriteStreamClose(e, t) {
|
|
15415
15437
|
// If the write stream closed after the write handshake completes, a write
|
|
15416
15438
|
// operation failed and we fail the pending operation.
|
|
15417
|
-
t && __PRIVATE_ensureWriteStream(e).
|
|
15439
|
+
t && __PRIVATE_ensureWriteStream(e).ea &&
|
|
15418
15440
|
// This error affects the actual write.
|
|
15419
15441
|
await async function __PRIVATE_handleWriteError(e, t) {
|
|
15420
15442
|
// Only handle permanent errors here. If it's transient, just let the retry
|
|
@@ -15424,11 +15446,11 @@ async function __PRIVATE_onWriteStreamClose(e, t) {
|
|
|
15424
15446
|
}(t.code)) {
|
|
15425
15447
|
// This was a permanent error, the request itself was the problem
|
|
15426
15448
|
// so it's not going to succeed if we resend it.
|
|
15427
|
-
const n = e.
|
|
15449
|
+
const n = e.Ia.shift();
|
|
15428
15450
|
// In this case it's also unlikely that the server itself is melting
|
|
15429
15451
|
// down -- this was just a bad request so inhibit backoff on the next
|
|
15430
15452
|
// restart.
|
|
15431
|
-
__PRIVATE_ensureWriteStream(e).
|
|
15453
|
+
__PRIVATE_ensureWriteStream(e).L_(), await __PRIVATE_executeWithRecovery(e, (() => e.remoteSyncer.rejectFailedWrite(n.batchId, t))),
|
|
15432
15454
|
// It's possible that with the completion of this mutation
|
|
15433
15455
|
// another slot has freed up.
|
|
15434
15456
|
await __PRIVATE_fillWritePipeline(e);
|
|
@@ -15446,19 +15468,19 @@ async function __PRIVATE_remoteStoreHandleCredentialChange(e, t) {
|
|
|
15446
15468
|
// Tear down and re-create our network streams. This will ensure we get a
|
|
15447
15469
|
// fresh auth token for the new user and re-fill the write pipeline with
|
|
15448
15470
|
// new mutations from the LocalStore (since mutations are per-user).
|
|
15449
|
-
n.
|
|
15471
|
+
n.da.add(3 /* OfflineCause.CredentialChange */), await __PRIVATE_disableNetworkInternal(n),
|
|
15450
15472
|
r &&
|
|
15451
15473
|
// Don't set the network status to Unknown if we are offline.
|
|
15452
|
-
n.
|
|
15453
|
-
n.
|
|
15474
|
+
n.Va.set("Unknown" /* OnlineState.Unknown */), await n.remoteSyncer.handleCredentialChange(t),
|
|
15475
|
+
n.da.delete(3 /* OfflineCause.CredentialChange */), await __PRIVATE_enableNetworkInternal(n);
|
|
15454
15476
|
}
|
|
15455
15477
|
|
|
15456
15478
|
/**
|
|
15457
15479
|
* Toggles the network state when the client gains or loses its primary lease.
|
|
15458
15480
|
*/ async function __PRIVATE_remoteStoreApplyPrimaryState(e, t) {
|
|
15459
15481
|
const n = __PRIVATE_debugCast(e);
|
|
15460
|
-
t ? (n.
|
|
15461
|
-
await __PRIVATE_disableNetworkInternal(n), n.
|
|
15482
|
+
t ? (n.da.delete(2 /* OfflineCause.IsSecondary */), await __PRIVATE_enableNetworkInternal(n)) : t || (n.da.add(2 /* OfflineCause.IsSecondary */),
|
|
15483
|
+
await __PRIVATE_disableNetworkInternal(n), n.Va.set("Unknown" /* OnlineState.Unknown */));
|
|
15462
15484
|
}
|
|
15463
15485
|
|
|
15464
15486
|
/**
|
|
@@ -15469,11 +15491,11 @@ async function __PRIVATE_remoteStoreHandleCredentialChange(e, t) {
|
|
|
15469
15491
|
* PORTING NOTE: On iOS and Android, the WatchStream gets registered on startup.
|
|
15470
15492
|
* This is not done on Web to allow it to be tree-shaken.
|
|
15471
15493
|
*/ function __PRIVATE_ensureWatchStream(e) {
|
|
15472
|
-
return e.
|
|
15494
|
+
return e.fa || (
|
|
15473
15495
|
// Create stream (but note that it is not started yet).
|
|
15474
|
-
e.
|
|
15496
|
+
e.fa = function __PRIVATE_newPersistentWatchStream(e, t, n) {
|
|
15475
15497
|
const r = __PRIVATE_debugCast(e);
|
|
15476
|
-
return r.
|
|
15498
|
+
return r.oa(), new __PRIVATE_PersistentListenStream(t, r.connection, r.authCredentials, r.appCheckCredentials, r.serializer, n);
|
|
15477
15499
|
}
|
|
15478
15500
|
/**
|
|
15479
15501
|
* @license
|
|
@@ -15494,11 +15516,11 @@ async function __PRIVATE_remoteStoreHandleCredentialChange(e, t) {
|
|
|
15494
15516
|
e_: __PRIVATE_onWatchStreamConnected.bind(null, e),
|
|
15495
15517
|
n_: __PRIVATE_onWatchStreamOpen.bind(null, e),
|
|
15496
15518
|
i_: __PRIVATE_onWatchStreamClose.bind(null, e),
|
|
15497
|
-
|
|
15498
|
-
}), e.
|
|
15499
|
-
t ? (e.
|
|
15519
|
+
Y_: __PRIVATE_onWatchStreamChange.bind(null, e)
|
|
15520
|
+
}), e.Aa.push((async t => {
|
|
15521
|
+
t ? (e.fa.L_(), __PRIVATE_shouldStartWatchStream(e) ? __PRIVATE_startWatchStream(e) : e.Va.set("Unknown" /* OnlineState.Unknown */)) : (await e.fa.stop(),
|
|
15500
15522
|
__PRIVATE_cleanUpWatchStreamState(e));
|
|
15501
|
-
}))), e.
|
|
15523
|
+
}))), e.fa;
|
|
15502
15524
|
}
|
|
15503
15525
|
|
|
15504
15526
|
/**
|
|
@@ -15509,23 +15531,23 @@ async function __PRIVATE_remoteStoreHandleCredentialChange(e, t) {
|
|
|
15509
15531
|
* PORTING NOTE: On iOS and Android, the WriteStream gets registered on startup.
|
|
15510
15532
|
* This is not done on Web to allow it to be tree-shaken.
|
|
15511
15533
|
*/ function __PRIVATE_ensureWriteStream(e) {
|
|
15512
|
-
return e.
|
|
15534
|
+
return e.ga || (
|
|
15513
15535
|
// Create stream (but note that it is not started yet).
|
|
15514
|
-
e.
|
|
15536
|
+
e.ga = function __PRIVATE_newPersistentWriteStream(e, t, n) {
|
|
15515
15537
|
const r = __PRIVATE_debugCast(e);
|
|
15516
|
-
return r.
|
|
15538
|
+
return r.oa(), new __PRIVATE_PersistentWriteStream(t, r.connection, r.authCredentials, r.appCheckCredentials, r.serializer, n);
|
|
15517
15539
|
}(e.datastore, e.asyncQueue, {
|
|
15518
15540
|
e_: () => Promise.resolve(),
|
|
15519
15541
|
n_: __PRIVATE_onWriteStreamOpen.bind(null, e),
|
|
15520
15542
|
i_: __PRIVATE_onWriteStreamClose.bind(null, e),
|
|
15521
|
-
|
|
15522
|
-
|
|
15523
|
-
}), e.
|
|
15524
|
-
t ? (e.
|
|
15543
|
+
na: __PRIVATE_onWriteHandshakeComplete.bind(null, e),
|
|
15544
|
+
ra: __PRIVATE_onMutationResult.bind(null, e)
|
|
15545
|
+
}), e.Aa.push((async t => {
|
|
15546
|
+
t ? (e.ga.L_(),
|
|
15525
15547
|
// This will start the write stream if necessary.
|
|
15526
|
-
await __PRIVATE_fillWritePipeline(e)) : (await e.
|
|
15527
|
-
e.
|
|
15528
|
-
}))), e.
|
|
15548
|
+
await __PRIVATE_fillWritePipeline(e)) : (await e.ga.stop(), e.Ia.length > 0 && (__PRIVATE_logDebug(Xt, `Stopping write stream with ${e.Ia.length} pending writes`),
|
|
15549
|
+
e.Ia = []));
|
|
15550
|
+
}))), e.ga;
|
|
15529
15551
|
}
|
|
15530
15552
|
|
|
15531
15553
|
/**
|
|
@@ -15738,25 +15760,25 @@ class DelayedOperation {
|
|
|
15738
15760
|
* duplicate events for the same doc.
|
|
15739
15761
|
*/ class __PRIVATE_DocumentChangeSet {
|
|
15740
15762
|
constructor() {
|
|
15741
|
-
this.
|
|
15763
|
+
this.pa = new SortedMap(DocumentKey.comparator);
|
|
15742
15764
|
}
|
|
15743
15765
|
track(e) {
|
|
15744
|
-
const t = e.doc.key, n = this.
|
|
15766
|
+
const t = e.doc.key, n = this.pa.get(t);
|
|
15745
15767
|
n ?
|
|
15746
15768
|
// Merge the new change with the existing change.
|
|
15747
|
-
0 /* ChangeType.Added */ !== e.type && 3 /* ChangeType.Metadata */ === n.type ? this.
|
|
15769
|
+
0 /* ChangeType.Added */ !== e.type && 3 /* ChangeType.Metadata */ === n.type ? this.pa = this.pa.insert(t, e) : 3 /* ChangeType.Metadata */ === e.type && 1 /* ChangeType.Removed */ !== n.type ? this.pa = this.pa.insert(t, {
|
|
15748
15770
|
type: n.type,
|
|
15749
15771
|
doc: e.doc
|
|
15750
|
-
}) : 2 /* ChangeType.Modified */ === e.type && 2 /* ChangeType.Modified */ === n.type ? this.
|
|
15772
|
+
}) : 2 /* ChangeType.Modified */ === e.type && 2 /* ChangeType.Modified */ === n.type ? this.pa = this.pa.insert(t, {
|
|
15751
15773
|
type: 2 /* ChangeType.Modified */ ,
|
|
15752
15774
|
doc: e.doc
|
|
15753
|
-
}) : 2 /* ChangeType.Modified */ === e.type && 0 /* ChangeType.Added */ === n.type ? this.
|
|
15775
|
+
}) : 2 /* ChangeType.Modified */ === e.type && 0 /* ChangeType.Added */ === n.type ? this.pa = this.pa.insert(t, {
|
|
15754
15776
|
type: 0 /* ChangeType.Added */ ,
|
|
15755
15777
|
doc: e.doc
|
|
15756
|
-
}) : 1 /* ChangeType.Removed */ === e.type && 0 /* ChangeType.Added */ === n.type ? this.
|
|
15778
|
+
}) : 1 /* ChangeType.Removed */ === e.type && 0 /* ChangeType.Added */ === n.type ? this.pa = this.pa.remove(t) : 1 /* ChangeType.Removed */ === e.type && 2 /* ChangeType.Modified */ === n.type ? this.pa = this.pa.insert(t, {
|
|
15757
15779
|
type: 1 /* ChangeType.Removed */ ,
|
|
15758
15780
|
doc: n.doc
|
|
15759
|
-
}) : 0 /* ChangeType.Added */ === e.type && 1 /* ChangeType.Removed */ === n.type ? this.
|
|
15781
|
+
}) : 0 /* ChangeType.Added */ === e.type && 1 /* ChangeType.Removed */ === n.type ? this.pa = this.pa.insert(t, {
|
|
15760
15782
|
type: 2 /* ChangeType.Modified */ ,
|
|
15761
15783
|
doc: e.doc
|
|
15762
15784
|
}) :
|
|
@@ -15769,12 +15791,12 @@ class DelayedOperation {
|
|
|
15769
15791
|
// Removed->Metadata
|
|
15770
15792
|
fail(63341, {
|
|
15771
15793
|
Vt: e,
|
|
15772
|
-
|
|
15773
|
-
}) : this.
|
|
15794
|
+
ya: n
|
|
15795
|
+
}) : this.pa = this.pa.insert(t, e);
|
|
15774
15796
|
}
|
|
15775
|
-
|
|
15797
|
+
wa() {
|
|
15776
15798
|
const e = [];
|
|
15777
|
-
return this.
|
|
15799
|
+
return this.pa.inorderTraversal(((t, n) => {
|
|
15778
15800
|
e.push(n);
|
|
15779
15801
|
})), e;
|
|
15780
15802
|
}
|
|
@@ -15830,25 +15852,25 @@ class ViewSnapshot {
|
|
|
15830
15852
|
* tracked by EventManager.
|
|
15831
15853
|
*/ class __PRIVATE_QueryListenersInfo {
|
|
15832
15854
|
constructor() {
|
|
15833
|
-
this.
|
|
15855
|
+
this.ba = void 0, this.Sa = [];
|
|
15834
15856
|
}
|
|
15835
15857
|
// Helper methods that checks if the query has listeners that listening to remote store
|
|
15836
|
-
|
|
15837
|
-
return this.
|
|
15858
|
+
Da() {
|
|
15859
|
+
return this.Sa.some((e => e.va()));
|
|
15838
15860
|
}
|
|
15839
15861
|
}
|
|
15840
15862
|
|
|
15841
15863
|
class __PRIVATE_EventManagerImpl {
|
|
15842
15864
|
constructor() {
|
|
15843
15865
|
this.queries = __PRIVATE_newQueriesObjectMap(), this.onlineState = "Unknown" /* OnlineState.Unknown */ ,
|
|
15844
|
-
this.
|
|
15866
|
+
this.Ca = new Set;
|
|
15845
15867
|
}
|
|
15846
15868
|
terminate() {
|
|
15847
15869
|
!function __PRIVATE_errorAllTargets(e, t) {
|
|
15848
15870
|
const n = __PRIVATE_debugCast(e), r = n.queries;
|
|
15849
15871
|
// Prevent further access by clearing ObjectMap.
|
|
15850
15872
|
n.queries = __PRIVATE_newQueriesObjectMap(), r.forEach(((e, n) => {
|
|
15851
|
-
for (const e of n.
|
|
15873
|
+
for (const e of n.Sa) e.onError(t);
|
|
15852
15874
|
}));
|
|
15853
15875
|
}
|
|
15854
15876
|
// Call all global snapshot listeners that have been set.
|
|
@@ -15865,19 +15887,19 @@ async function __PRIVATE_eventManagerListen(e, t) {
|
|
|
15865
15887
|
let r = 3 /* ListenerSetupAction.NoActionRequired */;
|
|
15866
15888
|
const i = t.query;
|
|
15867
15889
|
let s = n.queries.get(i);
|
|
15868
|
-
s ? !s.
|
|
15890
|
+
s ? !s.Da() && t.va() && (
|
|
15869
15891
|
// Query has been listening to local cache, and tries to add a new listener sourced from watch.
|
|
15870
15892
|
r = 2 /* ListenerSetupAction.RequireWatchConnectionOnly */) : (s = new __PRIVATE_QueryListenersInfo,
|
|
15871
|
-
r = t.
|
|
15893
|
+
r = t.va() ? 0 /* ListenerSetupAction.InitializeLocalListenAndRequireWatchConnection */ : 1 /* ListenerSetupAction.InitializeLocalListenOnly */);
|
|
15872
15894
|
try {
|
|
15873
15895
|
switch (r) {
|
|
15874
15896
|
case 0 /* ListenerSetupAction.InitializeLocalListenAndRequireWatchConnection */ :
|
|
15875
|
-
s.
|
|
15897
|
+
s.ba = await n.onListen(i,
|
|
15876
15898
|
/** enableRemoteListen= */ !0);
|
|
15877
15899
|
break;
|
|
15878
15900
|
|
|
15879
15901
|
case 1 /* ListenerSetupAction.InitializeLocalListenOnly */ :
|
|
15880
|
-
s.
|
|
15902
|
+
s.ba = await n.onListen(i,
|
|
15881
15903
|
/** enableRemoteListen= */ !1);
|
|
15882
15904
|
break;
|
|
15883
15905
|
|
|
@@ -15888,10 +15910,10 @@ async function __PRIVATE_eventManagerListen(e, t) {
|
|
|
15888
15910
|
const n = __PRIVATE_wrapInUserErrorIfRecoverable(e, `Initialization of query '${__PRIVATE_stringifyQuery(t.query)}' failed`);
|
|
15889
15911
|
return void t.onError(n);
|
|
15890
15912
|
}
|
|
15891
|
-
if (n.queries.set(i, s), s.
|
|
15913
|
+
if (n.queries.set(i, s), s.Sa.push(t),
|
|
15892
15914
|
// Run global snapshot listeners if a consistent snapshot has been emitted.
|
|
15893
|
-
t.
|
|
15894
|
-
t.
|
|
15915
|
+
t.Fa(n.onlineState), s.ba) {
|
|
15916
|
+
t.Ma(s.ba) && __PRIVATE_raiseSnapshotsInSyncEvent(n);
|
|
15895
15917
|
}
|
|
15896
15918
|
}
|
|
15897
15919
|
|
|
@@ -15900,8 +15922,8 @@ async function __PRIVATE_eventManagerUnlisten(e, t) {
|
|
|
15900
15922
|
let i = 3 /* ListenerRemovalAction.NoActionRequired */;
|
|
15901
15923
|
const s = n.queries.get(r);
|
|
15902
15924
|
if (s) {
|
|
15903
|
-
const e = s.
|
|
15904
|
-
e >= 0 && (s.
|
|
15925
|
+
const e = s.Sa.indexOf(t);
|
|
15926
|
+
e >= 0 && (s.Sa.splice(e, 1), 0 === s.Sa.length ? i = t.va() ? 0 /* ListenerRemovalAction.TerminateLocalListenAndRequireWatchDisconnection */ : 1 /* ListenerRemovalAction.TerminateLocalListenOnly */ : !s.Da() && t.va() && (
|
|
15905
15927
|
// The removed listener is the last one that sourced from watch.
|
|
15906
15928
|
i = 2 /* ListenerRemovalAction.RequireWatchDisconnectionOnly */));
|
|
15907
15929
|
}
|
|
@@ -15928,8 +15950,8 @@ function __PRIVATE_eventManagerOnWatchChange(e, t) {
|
|
|
15928
15950
|
for (const e of t) {
|
|
15929
15951
|
const t = e.query, i = n.queries.get(t);
|
|
15930
15952
|
if (i) {
|
|
15931
|
-
for (const t of i.
|
|
15932
|
-
i.
|
|
15953
|
+
for (const t of i.Sa) t.Ma(e) && (r = !0);
|
|
15954
|
+
i.ba = e;
|
|
15933
15955
|
}
|
|
15934
15956
|
}
|
|
15935
15957
|
r && __PRIVATE_raiseSnapshotsInSyncEvent(n);
|
|
@@ -15937,14 +15959,14 @@ function __PRIVATE_eventManagerOnWatchChange(e, t) {
|
|
|
15937
15959
|
|
|
15938
15960
|
function __PRIVATE_eventManagerOnWatchError(e, t, n) {
|
|
15939
15961
|
const r = __PRIVATE_debugCast(e), i = r.queries.get(t);
|
|
15940
|
-
if (i) for (const e of i.
|
|
15962
|
+
if (i) for (const e of i.Sa) e.onError(n);
|
|
15941
15963
|
// Remove all listeners. NOTE: We don't need to call syncEngine.unlisten()
|
|
15942
15964
|
// after an error.
|
|
15943
15965
|
r.queries.delete(t);
|
|
15944
15966
|
}
|
|
15945
15967
|
|
|
15946
15968
|
function __PRIVATE_raiseSnapshotsInSyncEvent(e) {
|
|
15947
|
-
e.
|
|
15969
|
+
e.Ca.forEach((e => {
|
|
15948
15970
|
e.next();
|
|
15949
15971
|
}));
|
|
15950
15972
|
}
|
|
@@ -15952,7 +15974,7 @@ function __PRIVATE_raiseSnapshotsInSyncEvent(e) {
|
|
|
15952
15974
|
var en, tn;
|
|
15953
15975
|
|
|
15954
15976
|
/** Listen to both cache and server changes */
|
|
15955
|
-
(tn = en || (en = {})).
|
|
15977
|
+
(tn = en || (en = {})).xa = "default",
|
|
15956
15978
|
/** Listen to changes in cache only */
|
|
15957
15979
|
tn.Cache = "cache";
|
|
15958
15980
|
|
|
@@ -15964,12 +15986,12 @@ tn.Cache = "cache";
|
|
|
15964
15986
|
*/
|
|
15965
15987
|
class __PRIVATE_QueryListener {
|
|
15966
15988
|
constructor(e, t, n) {
|
|
15967
|
-
this.query = e, this.
|
|
15989
|
+
this.query = e, this.Oa = t,
|
|
15968
15990
|
/**
|
|
15969
15991
|
* Initial snapshots (e.g. from cache) may not be propagated to the wrapped
|
|
15970
15992
|
* observer. This flag is set to true once we've actually raised an event.
|
|
15971
15993
|
*/
|
|
15972
|
-
this.
|
|
15994
|
+
this.Na = !1, this.Ba = null, this.onlineState = "Unknown" /* OnlineState.Unknown */ ,
|
|
15973
15995
|
this.options = n || {};
|
|
15974
15996
|
}
|
|
15975
15997
|
/**
|
|
@@ -15977,7 +15999,7 @@ class __PRIVATE_QueryListener {
|
|
|
15977
15999
|
* if applicable (depending on what changed, whether the user has opted into
|
|
15978
16000
|
* metadata-only changes, etc.). Returns true if a user-facing event was
|
|
15979
16001
|
* indeed raised.
|
|
15980
|
-
*/
|
|
16002
|
+
*/ Ma(e) {
|
|
15981
16003
|
if (!this.options.includeMetadataChanges) {
|
|
15982
16004
|
// Remove the metadata only changes.
|
|
15983
16005
|
const t = [];
|
|
@@ -15986,49 +16008,49 @@ class __PRIVATE_QueryListener {
|
|
|
15986
16008
|
/* excludesMetadataChanges= */ !0, e.hasCachedResults);
|
|
15987
16009
|
}
|
|
15988
16010
|
let t = !1;
|
|
15989
|
-
return this.
|
|
15990
|
-
t = !0), this.
|
|
16011
|
+
return this.Na ? this.La(e) && (this.Oa.next(e), t = !0) : this.ka(e, this.onlineState) && (this.qa(e),
|
|
16012
|
+
t = !0), this.Ba = e, t;
|
|
15991
16013
|
}
|
|
15992
16014
|
onError(e) {
|
|
15993
|
-
this.
|
|
16015
|
+
this.Oa.error(e);
|
|
15994
16016
|
}
|
|
15995
|
-
/** Returns whether a snapshot was raised. */
|
|
16017
|
+
/** Returns whether a snapshot was raised. */ Fa(e) {
|
|
15996
16018
|
this.onlineState = e;
|
|
15997
16019
|
let t = !1;
|
|
15998
|
-
return this.
|
|
16020
|
+
return this.Ba && !this.Na && this.ka(this.Ba, e) && (this.qa(this.Ba), t = !0),
|
|
15999
16021
|
t;
|
|
16000
16022
|
}
|
|
16001
|
-
|
|
16023
|
+
ka(e, t) {
|
|
16002
16024
|
// Always raise the first event when we're synced
|
|
16003
16025
|
if (!e.fromCache) return !0;
|
|
16004
16026
|
// Always raise event if listening to cache
|
|
16005
|
-
if (!this.
|
|
16027
|
+
if (!this.va()) return !0;
|
|
16006
16028
|
// NOTE: We consider OnlineState.Unknown as online (it should become Offline
|
|
16007
16029
|
// or Online if we wait long enough).
|
|
16008
16030
|
const n = "Offline" /* OnlineState.Offline */ !== t;
|
|
16009
16031
|
// Don't raise the event if we're online, aren't synced yet (checked
|
|
16010
16032
|
// above) and are waiting for a sync.
|
|
16011
|
-
return (!this.options.
|
|
16033
|
+
return (!this.options.Qa || !n) && (!e.docs.isEmpty() || e.hasCachedResults || "Offline" /* OnlineState.Offline */ === t);
|
|
16012
16034
|
// Raise data from cache if we have any documents, have cached results before,
|
|
16013
16035
|
// or we are offline.
|
|
16014
16036
|
}
|
|
16015
|
-
|
|
16037
|
+
La(e) {
|
|
16016
16038
|
// We don't need to handle includeDocumentMetadataChanges here because
|
|
16017
16039
|
// the Metadata only changes have already been stripped out if needed.
|
|
16018
16040
|
// At this point the only changes we will see are the ones we should
|
|
16019
16041
|
// propagate.
|
|
16020
16042
|
if (e.docChanges.length > 0) return !0;
|
|
16021
|
-
const t = this.
|
|
16043
|
+
const t = this.Ba && this.Ba.hasPendingWrites !== e.hasPendingWrites;
|
|
16022
16044
|
return !(!e.syncStateChanged && !t) && !0 === this.options.includeMetadataChanges;
|
|
16023
16045
|
// Generally we should have hit one of the cases above, but it's possible
|
|
16024
16046
|
// to get here if there were only metadata docChanges and they got
|
|
16025
16047
|
// stripped out.
|
|
16026
16048
|
}
|
|
16027
|
-
|
|
16049
|
+
qa(e) {
|
|
16028
16050
|
e = ViewSnapshot.fromInitialDocuments(e.query, e.docs, e.mutatedKeys, e.fromCache, e.hasCachedResults),
|
|
16029
|
-
this.
|
|
16051
|
+
this.Na = !0, this.Oa.next(e);
|
|
16030
16052
|
}
|
|
16031
|
-
|
|
16053
|
+
va() {
|
|
16032
16054
|
return this.options.source !== en.Cache;
|
|
16033
16055
|
}
|
|
16034
16056
|
}
|
|
@@ -16056,10 +16078,10 @@ class __PRIVATE_QueryListener {
|
|
|
16056
16078
|
constructor(e,
|
|
16057
16079
|
// How many bytes this element takes to store in the bundle.
|
|
16058
16080
|
t) {
|
|
16059
|
-
this
|
|
16081
|
+
this.$a = e, this.byteLength = t;
|
|
16060
16082
|
}
|
|
16061
|
-
|
|
16062
|
-
return "metadata" in this
|
|
16083
|
+
Ua() {
|
|
16084
|
+
return "metadata" in this.$a;
|
|
16063
16085
|
}
|
|
16064
16086
|
}
|
|
16065
16087
|
|
|
@@ -16103,7 +16125,7 @@ class __PRIVATE_QueryListener {
|
|
|
16103
16125
|
* storage and provide progress update while loading.
|
|
16104
16126
|
*/ class __PRIVATE_BundleLoader {
|
|
16105
16127
|
constructor(e, t, n) {
|
|
16106
|
-
this.
|
|
16128
|
+
this.Ka = e, this.localStore = t, this.serializer = n,
|
|
16107
16129
|
/** Batched queries to be saved into storage */
|
|
16108
16130
|
this.queries = [],
|
|
16109
16131
|
/** Batched documents to be saved into storage */
|
|
@@ -16116,21 +16138,21 @@ class __PRIVATE_QueryListener {
|
|
|
16116
16138
|
*
|
|
16117
16139
|
* Returns a new progress if adding the element leads to a new progress,
|
|
16118
16140
|
* otherwise returns null.
|
|
16119
|
-
*/
|
|
16141
|
+
*/ Wa(e) {
|
|
16120
16142
|
this.progress.bytesLoaded += e.byteLength;
|
|
16121
16143
|
let t = this.progress.documentsLoaded;
|
|
16122
|
-
if (e.
|
|
16144
|
+
if (e.$a.namedQuery) this.queries.push(e.$a.namedQuery); else if (e.$a.documentMetadata) {
|
|
16123
16145
|
this.documents.push({
|
|
16124
|
-
metadata: e.
|
|
16125
|
-
}), e.
|
|
16126
|
-
const n = ResourcePath.fromString(e.
|
|
16146
|
+
metadata: e.$a.documentMetadata
|
|
16147
|
+
}), e.$a.documentMetadata.exists || ++t;
|
|
16148
|
+
const n = ResourcePath.fromString(e.$a.documentMetadata.name);
|
|
16127
16149
|
this.collectionGroups.add(n.get(n.length - 2));
|
|
16128
|
-
} else e.
|
|
16150
|
+
} else e.$a.document && (this.documents[this.documents.length - 1].document = e.$a.document,
|
|
16129
16151
|
++t);
|
|
16130
16152
|
return t !== this.progress.documentsLoaded ? (this.progress.documentsLoaded = t,
|
|
16131
16153
|
Object.assign({}, this.progress)) : null;
|
|
16132
16154
|
}
|
|
16133
|
-
|
|
16155
|
+
Ga(e) {
|
|
16134
16156
|
const t = new Map, n = new __PRIVATE_BundleConverterImpl(this.serializer);
|
|
16135
16157
|
for (const r of e) if (r.metadata.queries) {
|
|
16136
16158
|
const e = n.Us(r.metadata.name);
|
|
@@ -16144,12 +16166,12 @@ class __PRIVATE_QueryListener {
|
|
|
16144
16166
|
/**
|
|
16145
16167
|
* Update the progress to 'Success' and return the updated progress.
|
|
16146
16168
|
*/ async complete() {
|
|
16147
|
-
const e = await __PRIVATE_localStoreApplyBundledDocuments(this.localStore, new __PRIVATE_BundleConverterImpl(this.serializer), this.documents, this.
|
|
16169
|
+
const e = await __PRIVATE_localStoreApplyBundledDocuments(this.localStore, new __PRIVATE_BundleConverterImpl(this.serializer), this.documents, this.Ka.id), t = this.Ga(this.documents);
|
|
16148
16170
|
for (const e of this.queries) await __PRIVATE_localStoreSaveNamedQuery(this.localStore, e, t.get(e.name));
|
|
16149
16171
|
return this.progress.taskState = "Success", {
|
|
16150
16172
|
progress: this.progress,
|
|
16151
|
-
|
|
16152
|
-
|
|
16173
|
+
za: this.collectionGroups,
|
|
16174
|
+
ja: e
|
|
16153
16175
|
};
|
|
16154
16176
|
}
|
|
16155
16177
|
}
|
|
@@ -16207,7 +16229,7 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16207
16229
|
constructor(e,
|
|
16208
16230
|
/** Documents included in the remote target */
|
|
16209
16231
|
t) {
|
|
16210
|
-
this.query = e, this.
|
|
16232
|
+
this.query = e, this.Ha = t, this.Ja = null, this.hasCachedResults = !1,
|
|
16211
16233
|
/**
|
|
16212
16234
|
* A flag whether the view is current with the backend. A view is considered
|
|
16213
16235
|
* current after it has seen the current flag from the backend and did not
|
|
@@ -16216,16 +16238,16 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16216
16238
|
*/
|
|
16217
16239
|
this.current = !1,
|
|
16218
16240
|
/** Documents in the view but not in the remote target */
|
|
16219
|
-
this.
|
|
16241
|
+
this.Ya = __PRIVATE_documentKeySet(),
|
|
16220
16242
|
/** Document Keys that have local changes */
|
|
16221
|
-
this.mutatedKeys = __PRIVATE_documentKeySet(), this.
|
|
16222
|
-
this.
|
|
16243
|
+
this.mutatedKeys = __PRIVATE_documentKeySet(), this.Za = __PRIVATE_newQueryComparator(e),
|
|
16244
|
+
this.Xa = new DocumentSet(this.Za);
|
|
16223
16245
|
}
|
|
16224
16246
|
/**
|
|
16225
16247
|
* The set of remote documents that the server has told us belongs to the target associated with
|
|
16226
16248
|
* this view.
|
|
16227
|
-
*/ get
|
|
16228
|
-
return this.
|
|
16249
|
+
*/ get eu() {
|
|
16250
|
+
return this.Ha;
|
|
16229
16251
|
}
|
|
16230
16252
|
/**
|
|
16231
16253
|
* Iterates over a set of doc changes, applies the query limit, and computes
|
|
@@ -16236,8 +16258,8 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16236
16258
|
* @param previousChanges - If this is being called with a refill, then start
|
|
16237
16259
|
* with this set of docs and changes instead of the current view.
|
|
16238
16260
|
* @returns a new set of docs, changes, and refill flag.
|
|
16239
|
-
*/
|
|
16240
|
-
const n = t ? t.
|
|
16261
|
+
*/ tu(e, t) {
|
|
16262
|
+
const n = t ? t.nu : new __PRIVATE_DocumentChangeSet, r = t ? t.Xa : this.Xa;
|
|
16241
16263
|
let i = t ? t.mutatedKeys : this.mutatedKeys, s = r, o = !1;
|
|
16242
16264
|
// Track the last doc in a (full) limit. This is necessary, because some
|
|
16243
16265
|
// update (a delete, or an update moving a doc past the old limit) might
|
|
@@ -16260,10 +16282,10 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16260
16282
|
u.data.isEqual(c.data) ? l !== h && (n.track({
|
|
16261
16283
|
type: 3 /* ChangeType.Metadata */ ,
|
|
16262
16284
|
doc: c
|
|
16263
|
-
}), P = !0) : this.
|
|
16285
|
+
}), P = !0) : this.ru(u, c) || (n.track({
|
|
16264
16286
|
type: 2 /* ChangeType.Modified */ ,
|
|
16265
16287
|
doc: c
|
|
16266
|
-
}), P = !0, (_ && this.
|
|
16288
|
+
}), P = !0, (_ && this.Za(c, _) > 0 || a && this.Za(c, a) < 0) && (
|
|
16267
16289
|
// This doc moved from inside the limit to outside the limit.
|
|
16268
16290
|
// That means there may be some other doc in the local cache
|
|
16269
16291
|
// that should be included instead.
|
|
@@ -16288,13 +16310,13 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16288
16310
|
});
|
|
16289
16311
|
}
|
|
16290
16312
|
return {
|
|
16291
|
-
|
|
16292
|
-
|
|
16313
|
+
Xa: s,
|
|
16314
|
+
nu: n,
|
|
16293
16315
|
Cs: o,
|
|
16294
16316
|
mutatedKeys: i
|
|
16295
16317
|
};
|
|
16296
16318
|
}
|
|
16297
|
-
|
|
16319
|
+
ru(e, t) {
|
|
16298
16320
|
// We suppress the initial change event for documents that were modified as
|
|
16299
16321
|
// part of a write acknowledgment (e.g. when the value of a server transform
|
|
16300
16322
|
// is applied) as Watch will send us the same document again.
|
|
@@ -16319,10 +16341,10 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16319
16341
|
*/
|
|
16320
16342
|
// PORTING NOTE: The iOS/Android clients always compute limbo document changes.
|
|
16321
16343
|
applyChanges(e, t, n, r) {
|
|
16322
|
-
const i = this.
|
|
16323
|
-
this.
|
|
16344
|
+
const i = this.Xa;
|
|
16345
|
+
this.Xa = e.Xa, this.mutatedKeys = e.mutatedKeys;
|
|
16324
16346
|
// Sort changes based on type and query comparator
|
|
16325
|
-
const s = e.
|
|
16347
|
+
const s = e.nu.wa();
|
|
16326
16348
|
s.sort(((e, t) => function __PRIVATE_compareChangeType(e, t) {
|
|
16327
16349
|
const order = e => {
|
|
16328
16350
|
switch (e) {
|
|
@@ -16362,70 +16384,70 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16362
16384
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16363
16385
|
* See the License for the specific language governing permissions and
|
|
16364
16386
|
* limitations under the License.
|
|
16365
|
-
*/ (e.type, t.type) || this.
|
|
16366
|
-
const o = t && !r ? this.
|
|
16387
|
+
*/ (e.type, t.type) || this.Za(e.doc, t.doc))), this.iu(n), r = null != r && r;
|
|
16388
|
+
const o = t && !r ? this.su() : [], _ = 0 === this.Ya.size && this.current && !r ? 1 /* SyncState.Synced */ : 0 /* SyncState.Local */ , a = _ !== this.Ja;
|
|
16367
16389
|
// We are at synced state if there is no limbo docs are waiting to be resolved, view is current
|
|
16368
16390
|
// with the backend, and the query is not pending to reset due to existence filter mismatch.
|
|
16369
|
-
if (this.
|
|
16391
|
+
if (this.Ja = _, 0 !== s.length || a) {
|
|
16370
16392
|
return {
|
|
16371
|
-
snapshot: new ViewSnapshot(this.query, e.
|
|
16393
|
+
snapshot: new ViewSnapshot(this.query, e.Xa, i, s, e.mutatedKeys, 0 /* SyncState.Local */ === _, a,
|
|
16372
16394
|
/* excludesMetadataChanges= */ !1, !!n && n.resumeToken.approximateByteSize() > 0),
|
|
16373
|
-
|
|
16395
|
+
ou: o
|
|
16374
16396
|
};
|
|
16375
16397
|
}
|
|
16376
16398
|
// no changes
|
|
16377
16399
|
return {
|
|
16378
|
-
|
|
16400
|
+
ou: o
|
|
16379
16401
|
};
|
|
16380
16402
|
}
|
|
16381
16403
|
/**
|
|
16382
16404
|
* Applies an OnlineState change to the view, potentially generating a
|
|
16383
16405
|
* ViewChange if the view's syncState changes as a result.
|
|
16384
|
-
*/
|
|
16406
|
+
*/ Fa(e) {
|
|
16385
16407
|
return this.current && "Offline" /* OnlineState.Offline */ === e ? (
|
|
16386
16408
|
// If we're offline, set `current` to false and then call applyChanges()
|
|
16387
16409
|
// to refresh our syncState and generate a ViewChange as appropriate. We
|
|
16388
16410
|
// are guaranteed to get a new TargetChange that sets `current` back to
|
|
16389
16411
|
// true once the client is back online.
|
|
16390
16412
|
this.current = !1, this.applyChanges({
|
|
16391
|
-
|
|
16392
|
-
|
|
16413
|
+
Xa: this.Xa,
|
|
16414
|
+
nu: new __PRIVATE_DocumentChangeSet,
|
|
16393
16415
|
mutatedKeys: this.mutatedKeys,
|
|
16394
16416
|
Cs: !1
|
|
16395
16417
|
},
|
|
16396
16418
|
/* limboResolutionEnabled= */ !1)) : {
|
|
16397
|
-
|
|
16419
|
+
ou: []
|
|
16398
16420
|
};
|
|
16399
16421
|
}
|
|
16400
16422
|
/**
|
|
16401
16423
|
* Returns whether the doc for the given key should be in limbo.
|
|
16402
|
-
*/
|
|
16424
|
+
*/ _u(e) {
|
|
16403
16425
|
// If the remote end says it's part of this query, it's not in limbo.
|
|
16404
|
-
return !this.
|
|
16426
|
+
return !this.Ha.has(e) && (
|
|
16405
16427
|
// The local store doesn't think it's a result, so it shouldn't be in limbo.
|
|
16406
|
-
!!this.
|
|
16428
|
+
!!this.Xa.has(e) && !this.Xa.get(e).hasLocalMutations);
|
|
16407
16429
|
}
|
|
16408
16430
|
/**
|
|
16409
16431
|
* Updates syncedDocuments, current, and limbo docs based on the given change.
|
|
16410
16432
|
* Returns the list of changes to which docs are in limbo.
|
|
16411
|
-
*/
|
|
16412
|
-
e && (e.addedDocuments.forEach((e => this.
|
|
16413
|
-
e.removedDocuments.forEach((e => this.
|
|
16433
|
+
*/ iu(e) {
|
|
16434
|
+
e && (e.addedDocuments.forEach((e => this.Ha = this.Ha.add(e))), e.modifiedDocuments.forEach((e => {})),
|
|
16435
|
+
e.removedDocuments.forEach((e => this.Ha = this.Ha.delete(e))), this.current = e.current);
|
|
16414
16436
|
}
|
|
16415
|
-
|
|
16437
|
+
su() {
|
|
16416
16438
|
// We can only determine limbo documents when we're in-sync with the server.
|
|
16417
16439
|
if (!this.current) return [];
|
|
16418
16440
|
// TODO(klimt): Do this incrementally so that it's not quadratic when
|
|
16419
16441
|
// updating many documents.
|
|
16420
|
-
const e = this.
|
|
16421
|
-
this.
|
|
16422
|
-
this.
|
|
16442
|
+
const e = this.Ya;
|
|
16443
|
+
this.Ya = __PRIVATE_documentKeySet(), this.Xa.forEach((e => {
|
|
16444
|
+
this._u(e.key) && (this.Ya = this.Ya.add(e.key));
|
|
16423
16445
|
}));
|
|
16424
16446
|
// Diff the new limbo docs with the old limbo docs.
|
|
16425
16447
|
const t = [];
|
|
16426
16448
|
return e.forEach((e => {
|
|
16427
|
-
this.
|
|
16428
|
-
})), this.
|
|
16449
|
+
this.Ya.has(e) || t.push(new __PRIVATE_RemovedLimboDocument(e));
|
|
16450
|
+
})), this.Ya.forEach((n => {
|
|
16429
16451
|
e.has(n) || t.push(new __PRIVATE_AddedLimboDocument(n));
|
|
16430
16452
|
})), t;
|
|
16431
16453
|
}
|
|
@@ -16449,9 +16471,9 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16449
16471
|
* @returns The ViewChange that resulted from this synchronization.
|
|
16450
16472
|
*/
|
|
16451
16473
|
// PORTING NOTE: Multi-tab only.
|
|
16452
|
-
|
|
16453
|
-
this.
|
|
16454
|
-
const t = this.
|
|
16474
|
+
au(e) {
|
|
16475
|
+
this.Ha = e.$s, this.Ya = __PRIVATE_documentKeySet();
|
|
16476
|
+
const t = this.tu(e.documents);
|
|
16455
16477
|
return this.applyChanges(t, /* limboResolutionEnabled= */ !0);
|
|
16456
16478
|
}
|
|
16457
16479
|
/**
|
|
@@ -16460,8 +16482,8 @@ class __PRIVATE_RemovedLimboDocument {
|
|
|
16460
16482
|
* `hasPendingWrites` status of the already established view.
|
|
16461
16483
|
*/
|
|
16462
16484
|
// PORTING NOTE: Multi-tab only.
|
|
16463
|
-
|
|
16464
|
-
return ViewSnapshot.fromInitialDocuments(this.query, this.
|
|
16485
|
+
uu() {
|
|
16486
|
+
return ViewSnapshot.fromInitialDocuments(this.query, this.Xa, this.mutatedKeys, 0 /* SyncState.Local */ === this.Ja, this.hasCachedResults);
|
|
16465
16487
|
}
|
|
16466
16488
|
}
|
|
16467
16489
|
|
|
@@ -16501,7 +16523,7 @@ const nn = "SyncEngine";
|
|
|
16501
16523
|
* decide whether it needs to manufacture a delete event for the target once
|
|
16502
16524
|
* the target is CURRENT.
|
|
16503
16525
|
*/
|
|
16504
|
-
this.
|
|
16526
|
+
this.cu = !1;
|
|
16505
16527
|
}
|
|
16506
16528
|
}
|
|
16507
16529
|
|
|
@@ -16522,8 +16544,8 @@ const nn = "SyncEngine";
|
|
|
16522
16544
|
// PORTING NOTE: Manages state synchronization in multi-tab environments.
|
|
16523
16545
|
r, i, s) {
|
|
16524
16546
|
this.localStore = e, this.remoteStore = t, this.eventManager = n, this.sharedClientState = r,
|
|
16525
|
-
this.currentUser = i, this.maxConcurrentLimboResolutions = s, this.
|
|
16526
|
-
this.
|
|
16547
|
+
this.currentUser = i, this.maxConcurrentLimboResolutions = s, this.lu = {}, this.hu = new ObjectMap((e => __PRIVATE_canonifyQuery(e)), __PRIVATE_queryEquals),
|
|
16548
|
+
this.Pu = new Map,
|
|
16527
16549
|
/**
|
|
16528
16550
|
* The keys of documents that are in limbo for which we haven't yet started a
|
|
16529
16551
|
* limbo resolution query. The strings in this set are the result of calling
|
|
@@ -16533,28 +16555,28 @@ const nn = "SyncEngine";
|
|
|
16533
16555
|
* of arbitrary elements and it also maintains insertion order, providing the
|
|
16534
16556
|
* desired queue-like FIFO semantics.
|
|
16535
16557
|
*/
|
|
16536
|
-
this.
|
|
16558
|
+
this.Tu = new Set,
|
|
16537
16559
|
/**
|
|
16538
16560
|
* Keeps track of the target ID for each document that is in limbo with an
|
|
16539
16561
|
* active target.
|
|
16540
16562
|
*/
|
|
16541
|
-
this.
|
|
16563
|
+
this.Iu = new SortedMap(DocumentKey.comparator),
|
|
16542
16564
|
/**
|
|
16543
16565
|
* Keeps track of the information about an active limbo resolution for each
|
|
16544
16566
|
* active target ID that was started for the purpose of limbo resolution.
|
|
16545
16567
|
*/
|
|
16546
|
-
this.
|
|
16568
|
+
this.Eu = new Map, this.du = new __PRIVATE_ReferenceSet,
|
|
16547
16569
|
/** Stores user completion handlers, indexed by User and BatchId. */
|
|
16548
|
-
this.
|
|
16570
|
+
this.Au = {},
|
|
16549
16571
|
/** Stores user callbacks waiting for all pending writes to be acknowledged. */
|
|
16550
|
-
this.
|
|
16572
|
+
this.Ru = new Map, this.Vu = __PRIVATE_TargetIdGenerator.lr(), this.onlineState = "Unknown" /* OnlineState.Unknown */ ,
|
|
16551
16573
|
// The primary state is set to `true` or `false` immediately after Firestore
|
|
16552
16574
|
// startup. In the interim, a client should only be considered primary if
|
|
16553
16575
|
// `isPrimary` is true.
|
|
16554
|
-
this.
|
|
16576
|
+
this.mu = void 0;
|
|
16555
16577
|
}
|
|
16556
16578
|
get isPrimaryClient() {
|
|
16557
|
-
return !0 === this.
|
|
16579
|
+
return !0 === this.mu;
|
|
16558
16580
|
}
|
|
16559
16581
|
}
|
|
16560
16582
|
|
|
@@ -16566,7 +16588,7 @@ const nn = "SyncEngine";
|
|
|
16566
16588
|
async function __PRIVATE_syncEngineListen(e, t, n = !0) {
|
|
16567
16589
|
const r = __PRIVATE_ensureWatchCallbacks(e);
|
|
16568
16590
|
let i;
|
|
16569
|
-
const s = r.
|
|
16591
|
+
const s = r.hu.get(t);
|
|
16570
16592
|
return s ? (
|
|
16571
16593
|
// PORTING NOTE: With Multi-Tab Web, it is possible that a query view
|
|
16572
16594
|
// already exists when EventManager calls us for the first time. This
|
|
@@ -16574,7 +16596,7 @@ async function __PRIVATE_syncEngineListen(e, t, n = !0) {
|
|
|
16574
16596
|
// behalf of another tab and the user of the primary also starts listening
|
|
16575
16597
|
// to the query. EventManager will not have an assigned target ID in this
|
|
16576
16598
|
// case and calls `listen` to obtain this ID.
|
|
16577
|
-
r.sharedClientState.addLocalQueryTarget(s.targetId), i = s.view.
|
|
16599
|
+
r.sharedClientState.addLocalQueryTarget(s.targetId), i = s.view.uu()) : i = await __PRIVATE_allocateTargetAndMaybeListen(r, t, n,
|
|
16578
16600
|
/** shouldInitializeView= */ !0), i;
|
|
16579
16601
|
}
|
|
16580
16602
|
|
|
@@ -16599,30 +16621,30 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16599
16621
|
// PORTING NOTE: On Web only, we inject the code that registers new Limbo
|
|
16600
16622
|
// targets based on view changes. This allows us to only depend on Limbo
|
|
16601
16623
|
// changes when user code includes queries.
|
|
16602
|
-
e.
|
|
16603
|
-
let i = t.view.
|
|
16624
|
+
e.fu = (t, n, r) => async function __PRIVATE_applyDocChanges(e, t, n, r) {
|
|
16625
|
+
let i = t.view.tu(n);
|
|
16604
16626
|
i.Cs && (
|
|
16605
16627
|
// The query has a limit and some docs were removed, so we need
|
|
16606
16628
|
// to re-run the query against the local store to make sure we
|
|
16607
16629
|
// didn't lose any good docs that had been past the limit.
|
|
16608
16630
|
i = await __PRIVATE_localStoreExecuteQuery(e.localStore, t.query,
|
|
16609
|
-
/* usePreviousResults= */ !1).then((({documents: e}) => t.view.
|
|
16631
|
+
/* usePreviousResults= */ !1).then((({documents: e}) => t.view.tu(e, i))));
|
|
16610
16632
|
const s = r && r.targetChanges.get(t.targetId), o = r && null != r.targetMismatches.get(t.targetId), _ = t.view.applyChanges(i,
|
|
16611
16633
|
/* limboResolutionEnabled= */ e.isPrimaryClient, s, o);
|
|
16612
|
-
return __PRIVATE_updateTrackedLimbos(e, t.targetId, _.
|
|
16634
|
+
return __PRIVATE_updateTrackedLimbos(e, t.targetId, _.ou), _.snapshot;
|
|
16613
16635
|
}(e, t, n, r);
|
|
16614
16636
|
const s = await __PRIVATE_localStoreExecuteQuery(e.localStore, t,
|
|
16615
|
-
/* usePreviousResults= */ !0), o = new __PRIVATE_View(t, s.$s), _ = o.
|
|
16637
|
+
/* usePreviousResults= */ !0), o = new __PRIVATE_View(t, s.$s), _ = o.tu(s.documents), a = TargetChange.createSynthesizedTargetChangeForCurrentChange(n, r && "Offline" /* OnlineState.Offline */ !== e.onlineState, i), u = o.applyChanges(_,
|
|
16616
16638
|
/* limboResolutionEnabled= */ e.isPrimaryClient, a);
|
|
16617
|
-
__PRIVATE_updateTrackedLimbos(e, n, u.
|
|
16639
|
+
__PRIVATE_updateTrackedLimbos(e, n, u.ou);
|
|
16618
16640
|
const c = new __PRIVATE_QueryView(t, n, o);
|
|
16619
|
-
return e.
|
|
16641
|
+
return e.hu.set(t, c), e.Pu.has(n) ? e.Pu.get(n).push(t) : e.Pu.set(n, [ t ]), u.snapshot;
|
|
16620
16642
|
}
|
|
16621
16643
|
|
|
16622
16644
|
/** Stops listening to the query. */ async function __PRIVATE_syncEngineUnlisten(e, t, n) {
|
|
16623
|
-
const r = __PRIVATE_debugCast(e), i = r.
|
|
16624
|
-
if (s.length > 1) return r.
|
|
16625
|
-
void r.
|
|
16645
|
+
const r = __PRIVATE_debugCast(e), i = r.hu.get(t), s = r.Pu.get(i.targetId);
|
|
16646
|
+
if (s.length > 1) return r.Pu.set(i.targetId, s.filter((e => !__PRIVATE_queryEquals(e, t)))),
|
|
16647
|
+
void r.hu.delete(t);
|
|
16626
16648
|
// No other queries are mapped to the target, clean up the query and the target.
|
|
16627
16649
|
if (r.isPrimaryClient) {
|
|
16628
16650
|
// We need to remove the local query target first to allow us to verify
|
|
@@ -16638,7 +16660,7 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16638
16660
|
}
|
|
16639
16661
|
|
|
16640
16662
|
/** Unlistens to the remote store while still listening to the cache. */ async function __PRIVATE_triggerRemoteStoreUnlisten(e, t) {
|
|
16641
|
-
const n = __PRIVATE_debugCast(e), r = n.
|
|
16663
|
+
const n = __PRIVATE_debugCast(e), r = n.hu.get(t), i = n.Pu.get(r.targetId);
|
|
16642
16664
|
n.isPrimaryClient && 1 === i.length && (
|
|
16643
16665
|
// PORTING NOTE: Unregister the target ID with local Firestore client as
|
|
16644
16666
|
// watch target.
|
|
@@ -16700,9 +16722,9 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16700
16722
|
})));
|
|
16701
16723
|
}(r.localStore, t);
|
|
16702
16724
|
r.sharedClientState.addPendingMutation(e.batchId), function __PRIVATE_addMutationCallback(e, t, n) {
|
|
16703
|
-
let r = e.
|
|
16725
|
+
let r = e.Au[e.currentUser.toKey()];
|
|
16704
16726
|
r || (r = new SortedMap(__PRIVATE_primitiveComparator));
|
|
16705
|
-
r = r.insert(t, n), e.
|
|
16727
|
+
r = r.insert(t, n), e.Au[e.currentUser.toKey()] = r;
|
|
16706
16728
|
}
|
|
16707
16729
|
/**
|
|
16708
16730
|
* Resolves or rejects the user callback for the given batch and then discards
|
|
@@ -16727,13 +16749,13 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16727
16749
|
const e = await __PRIVATE_localStoreApplyRemoteEventToLocalCache(n.localStore, t);
|
|
16728
16750
|
// Update `receivedDocument` as appropriate for any limbo targets.
|
|
16729
16751
|
t.targetChanges.forEach(((e, t) => {
|
|
16730
|
-
const r = n.
|
|
16752
|
+
const r = n.Eu.get(t);
|
|
16731
16753
|
r && (
|
|
16732
16754
|
// Since this is a limbo resolution lookup, it's for a single document
|
|
16733
16755
|
// and it could be added, modified, or removed, but not a combination.
|
|
16734
16756
|
__PRIVATE_hardAssert(e.addedDocuments.size + e.modifiedDocuments.size + e.removedDocuments.size <= 1, 22616),
|
|
16735
|
-
e.addedDocuments.size > 0 ? r.
|
|
16736
|
-
r.
|
|
16757
|
+
e.addedDocuments.size > 0 ? r.cu = !0 : e.modifiedDocuments.size > 0 ? __PRIVATE_hardAssert(r.cu, 14607) : e.removedDocuments.size > 0 && (__PRIVATE_hardAssert(r.cu, 42227),
|
|
16758
|
+
r.cu = !1));
|
|
16737
16759
|
})), await __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(n, e, t);
|
|
16738
16760
|
} catch (e) {
|
|
16739
16761
|
await __PRIVATE_ignoreIfPrimaryLeaseLoss(e);
|
|
@@ -16751,19 +16773,19 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16751
16773
|
// SharedClientState.
|
|
16752
16774
|
if (r.isPrimaryClient && 0 /* OnlineStateSource.RemoteStore */ === n || !r.isPrimaryClient && 1 /* OnlineStateSource.SharedClientState */ === n) {
|
|
16753
16775
|
const e = [];
|
|
16754
|
-
r.
|
|
16755
|
-
const i = r.view.
|
|
16776
|
+
r.hu.forEach(((n, r) => {
|
|
16777
|
+
const i = r.view.Fa(t);
|
|
16756
16778
|
i.snapshot && e.push(i.snapshot);
|
|
16757
16779
|
})), function __PRIVATE_eventManagerOnOnlineStateChange(e, t) {
|
|
16758
16780
|
const n = __PRIVATE_debugCast(e);
|
|
16759
16781
|
n.onlineState = t;
|
|
16760
16782
|
let r = !1;
|
|
16761
16783
|
n.queries.forEach(((e, n) => {
|
|
16762
|
-
for (const e of n.
|
|
16784
|
+
for (const e of n.Sa)
|
|
16763
16785
|
// Run global snapshot listeners if a consistent snapshot has been emitted.
|
|
16764
|
-
e.
|
|
16786
|
+
e.Fa(t) && (r = !0);
|
|
16765
16787
|
})), r && __PRIVATE_raiseSnapshotsInSyncEvent(n);
|
|
16766
|
-
}(r.eventManager, t), e.length && r.
|
|
16788
|
+
}(r.eventManager, t), e.length && r.lu.Y_(e), r.onlineState = t, r.isPrimaryClient && r.sharedClientState.setOnlineState(t);
|
|
16767
16789
|
}
|
|
16768
16790
|
}
|
|
16769
16791
|
|
|
@@ -16781,7 +16803,7 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16781
16803
|
const r = __PRIVATE_debugCast(e);
|
|
16782
16804
|
// PORTING NOTE: Multi-tab only.
|
|
16783
16805
|
r.sharedClientState.updateQueryState(t, "rejected", n);
|
|
16784
|
-
const i = r.
|
|
16806
|
+
const i = r.Eu.get(t), s = i && i.key;
|
|
16785
16807
|
if (s) {
|
|
16786
16808
|
// TODO(klimt): We really only should do the following on permission
|
|
16787
16809
|
// denied errors, but we don't have the cause code here.
|
|
@@ -16803,7 +16825,7 @@ async function __PRIVATE_allocateTargetAndMaybeListen(e, t, n, r) {
|
|
|
16803
16825
|
// RemoteEvent. If `applyRemoteEvent()` throws, we want to re-listen to
|
|
16804
16826
|
// this query when the RemoteStore restarts the Watch stream, which should
|
|
16805
16827
|
// re-trigger the target failure.
|
|
16806
|
-
r.
|
|
16828
|
+
r.Iu = r.Iu.remove(s), r.Eu.delete(t), __PRIVATE_pumpEnqueuedLimboResolutions(r);
|
|
16807
16829
|
} else await __PRIVATE_localStoreReleaseTarget(r.localStore, t,
|
|
16808
16830
|
/* keepPersistedTargetData */ !1).then((() => __PRIVATE_removeAndCleanupTarget(r, t, n))).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss);
|
|
16809
16831
|
}
|
|
@@ -16865,8 +16887,8 @@ async function __PRIVATE_syncEngineRejectFailedWrite(e, t, n) {
|
|
|
16865
16887
|
if (e === G)
|
|
16866
16888
|
// Trigger the callback right away if there is no pending writes at the moment.
|
|
16867
16889
|
return void t.resolve();
|
|
16868
|
-
const r = n.
|
|
16869
|
-
r.push(t), n.
|
|
16890
|
+
const r = n.Ru.get(e) || [];
|
|
16891
|
+
r.push(t), n.Ru.set(e, r);
|
|
16870
16892
|
} catch (e) {
|
|
16871
16893
|
const n = __PRIVATE_wrapInUserErrorIfRecoverable(e, "Initialization of waitForPendingWrites() operation failed");
|
|
16872
16894
|
t.reject(n);
|
|
@@ -16877,28 +16899,28 @@ async function __PRIVATE_syncEngineRejectFailedWrite(e, t, n) {
|
|
|
16877
16899
|
* Triggers the callbacks that are waiting for this batch id to get acknowledged by server,
|
|
16878
16900
|
* if there are any.
|
|
16879
16901
|
*/ function __PRIVATE_triggerPendingWritesCallbacks(e, t) {
|
|
16880
|
-
(e.
|
|
16902
|
+
(e.Ru.get(t) || []).forEach((e => {
|
|
16881
16903
|
e.resolve();
|
|
16882
|
-
})), e.
|
|
16904
|
+
})), e.Ru.delete(t);
|
|
16883
16905
|
}
|
|
16884
16906
|
|
|
16885
16907
|
/** Reject all outstanding callbacks waiting for pending writes to complete. */ function __PRIVATE_processUserCallback(e, t, n) {
|
|
16886
16908
|
const r = __PRIVATE_debugCast(e);
|
|
16887
|
-
let i = r.
|
|
16909
|
+
let i = r.Au[r.currentUser.toKey()];
|
|
16888
16910
|
// NOTE: Mutations restored from persistence won't have callbacks, so it's
|
|
16889
16911
|
// okay for there to be no callback for this ID.
|
|
16890
16912
|
if (i) {
|
|
16891
16913
|
const e = i.get(t);
|
|
16892
|
-
e && (n ? e.reject(n) : e.resolve(), i = i.remove(t)), r.
|
|
16914
|
+
e && (n ? e.reject(n) : e.resolve(), i = i.remove(t)), r.Au[r.currentUser.toKey()] = i;
|
|
16893
16915
|
}
|
|
16894
16916
|
}
|
|
16895
16917
|
|
|
16896
16918
|
function __PRIVATE_removeAndCleanupTarget(e, t, n = null) {
|
|
16897
16919
|
e.sharedClientState.removeLocalQueryTarget(t);
|
|
16898
|
-
for (const r of e.
|
|
16899
|
-
if (e.
|
|
16900
|
-
e.
|
|
16901
|
-
e.
|
|
16920
|
+
for (const r of e.Pu.get(t)) e.hu.delete(r), n && e.lu.gu(r, n);
|
|
16921
|
+
if (e.Pu.delete(t), e.isPrimaryClient) {
|
|
16922
|
+
e.du.Hr(t).forEach((t => {
|
|
16923
|
+
e.du.containsKey(t) ||
|
|
16902
16924
|
// We removed the last reference for this key
|
|
16903
16925
|
__PRIVATE_removeLimboTarget(e, t);
|
|
16904
16926
|
}));
|
|
@@ -16906,30 +16928,30 @@ function __PRIVATE_removeAndCleanupTarget(e, t, n = null) {
|
|
|
16906
16928
|
}
|
|
16907
16929
|
|
|
16908
16930
|
function __PRIVATE_removeLimboTarget(e, t) {
|
|
16909
|
-
e.
|
|
16931
|
+
e.Tu.delete(t.path.canonicalString());
|
|
16910
16932
|
// It's possible that the target already got removed because the query failed. In that case,
|
|
16911
16933
|
// the key won't exist in `limboTargetsByKey`. Only do the cleanup if we still have the target.
|
|
16912
|
-
const n = e.
|
|
16913
|
-
null !== n && (__PRIVATE_remoteStoreUnlisten(e.remoteStore, n), e.
|
|
16914
|
-
e.
|
|
16934
|
+
const n = e.Iu.get(t);
|
|
16935
|
+
null !== n && (__PRIVATE_remoteStoreUnlisten(e.remoteStore, n), e.Iu = e.Iu.remove(t),
|
|
16936
|
+
e.Eu.delete(n), __PRIVATE_pumpEnqueuedLimboResolutions(e));
|
|
16915
16937
|
}
|
|
16916
16938
|
|
|
16917
16939
|
function __PRIVATE_updateTrackedLimbos(e, t, n) {
|
|
16918
|
-
for (const r of n) if (r instanceof __PRIVATE_AddedLimboDocument) e.
|
|
16940
|
+
for (const r of n) if (r instanceof __PRIVATE_AddedLimboDocument) e.du.addReference(r.key, t),
|
|
16919
16941
|
__PRIVATE_trackLimboChange(e, r); else if (r instanceof __PRIVATE_RemovedLimboDocument) {
|
|
16920
|
-
__PRIVATE_logDebug(nn, "Document no longer in limbo: " + r.key), e.
|
|
16921
|
-
e.
|
|
16942
|
+
__PRIVATE_logDebug(nn, "Document no longer in limbo: " + r.key), e.du.removeReference(r.key, t);
|
|
16943
|
+
e.du.containsKey(r.key) ||
|
|
16922
16944
|
// We removed the last reference for this key
|
|
16923
16945
|
__PRIVATE_removeLimboTarget(e, r.key);
|
|
16924
16946
|
} else fail(19791, {
|
|
16925
|
-
|
|
16947
|
+
pu: r
|
|
16926
16948
|
});
|
|
16927
16949
|
}
|
|
16928
16950
|
|
|
16929
16951
|
function __PRIVATE_trackLimboChange(e, t) {
|
|
16930
16952
|
const n = t.key, r = n.path.canonicalString();
|
|
16931
|
-
e.
|
|
16932
|
-
e.
|
|
16953
|
+
e.Iu.get(n) || e.Tu.has(r) || (__PRIVATE_logDebug(nn, "New document in limbo: " + n),
|
|
16954
|
+
e.Tu.add(r), __PRIVATE_pumpEnqueuedLimboResolutions(e));
|
|
16933
16955
|
}
|
|
16934
16956
|
|
|
16935
16957
|
/**
|
|
@@ -16940,18 +16962,18 @@ function __PRIVATE_trackLimboChange(e, t) {
|
|
|
16940
16962
|
* with "resource exhausted" errors which can lead to pathological client
|
|
16941
16963
|
* behavior as seen in https://github.com/firebase/firebase-js-sdk/issues/2683.
|
|
16942
16964
|
*/ function __PRIVATE_pumpEnqueuedLimboResolutions(e) {
|
|
16943
|
-
for (;e.
|
|
16944
|
-
const t = e.
|
|
16945
|
-
e.
|
|
16946
|
-
const n = new DocumentKey(ResourcePath.fromString(t)), r = e.
|
|
16947
|
-
e.
|
|
16965
|
+
for (;e.Tu.size > 0 && e.Iu.size < e.maxConcurrentLimboResolutions; ) {
|
|
16966
|
+
const t = e.Tu.values().next().value;
|
|
16967
|
+
e.Tu.delete(t);
|
|
16968
|
+
const n = new DocumentKey(ResourcePath.fromString(t)), r = e.Vu.next();
|
|
16969
|
+
e.Eu.set(r, new LimboResolution(n)), e.Iu = e.Iu.insert(n, r), __PRIVATE_remoteStoreListen(e.remoteStore, new TargetData(__PRIVATE_queryToTarget(__PRIVATE_newQueryForPath(n.path)), r, "TargetPurposeLimboResolution" /* TargetPurpose.LimboResolution */ , __PRIVATE_ListenSequence.le));
|
|
16948
16970
|
}
|
|
16949
16971
|
}
|
|
16950
16972
|
|
|
16951
16973
|
async function __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(e, t, n) {
|
|
16952
16974
|
const r = __PRIVATE_debugCast(e), i = [], s = [], o = [];
|
|
16953
|
-
r.
|
|
16954
|
-
o.push(r.
|
|
16975
|
+
r.hu.isEmpty() || (r.hu.forEach(((e, _) => {
|
|
16976
|
+
o.push(r.fu(_, t, n).then((e => {
|
|
16955
16977
|
var t;
|
|
16956
16978
|
// If there are changes, or we are handling a global snapshot, notify
|
|
16957
16979
|
// secondary clients to update query state.
|
|
@@ -16969,7 +16991,7 @@ async function __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(e, t, n) {
|
|
|
16969
16991
|
s.push(t);
|
|
16970
16992
|
}
|
|
16971
16993
|
})));
|
|
16972
|
-
})), await Promise.all(o), r.
|
|
16994
|
+
})), await Promise.all(o), r.lu.Y_(i), await async function __PRIVATE_localStoreNotifyLocalViewChanges(e, t) {
|
|
16973
16995
|
const n = __PRIVATE_debugCast(e);
|
|
16974
16996
|
try {
|
|
16975
16997
|
await n.persistence.runTransaction("notifyLocalViewChanges", "readwrite", (e => PersistencePromise.forEach(t, (t => PersistencePromise.forEach(t.ds, (r => n.persistence.referenceDelegate.addReference(e, t.targetId, r))).next((() => PersistencePromise.forEach(t.As, (r => n.persistence.referenceDelegate.removeReference(e, t.targetId, r)))))))));
|
|
@@ -17000,11 +17022,11 @@ async function __PRIVATE_syncEngineHandleCredentialChange(e, t) {
|
|
|
17000
17022
|
n.currentUser = t,
|
|
17001
17023
|
// Fails tasks waiting for pending writes requested by previous user.
|
|
17002
17024
|
function __PRIVATE_rejectOutstandingPendingWritesCallbacks(e, t) {
|
|
17003
|
-
e.
|
|
17025
|
+
e.Ru.forEach((e => {
|
|
17004
17026
|
e.forEach((e => {
|
|
17005
17027
|
e.reject(new FirestoreError(N.CANCELLED, t));
|
|
17006
17028
|
}));
|
|
17007
|
-
})), e.
|
|
17029
|
+
})), e.Ru.clear();
|
|
17008
17030
|
}(n, "'waitForPendingWrites' promise is rejected due to a user change."),
|
|
17009
17031
|
// TODO(b/114226417): Consider calling this only in the primary tab.
|
|
17010
17032
|
n.sharedClientState.handleUserChange(t, e.removedBatchIds, e.addedBatchIds), await __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(n, e.ks);
|
|
@@ -17012,15 +17034,15 @@ async function __PRIVATE_syncEngineHandleCredentialChange(e, t) {
|
|
|
17012
17034
|
}
|
|
17013
17035
|
|
|
17014
17036
|
function __PRIVATE_syncEngineGetRemoteKeysForTarget(e, t) {
|
|
17015
|
-
const n = __PRIVATE_debugCast(e), r = n.
|
|
17016
|
-
if (r && r.
|
|
17037
|
+
const n = __PRIVATE_debugCast(e), r = n.Eu.get(t);
|
|
17038
|
+
if (r && r.cu) return __PRIVATE_documentKeySet().add(r.key);
|
|
17017
17039
|
{
|
|
17018
17040
|
let e = __PRIVATE_documentKeySet();
|
|
17019
|
-
const r = n.
|
|
17041
|
+
const r = n.Pu.get(t);
|
|
17020
17042
|
if (!r) return e;
|
|
17021
17043
|
for (const t of r) {
|
|
17022
|
-
const r = n.
|
|
17023
|
-
e = e.unionWith(r.view.
|
|
17044
|
+
const r = n.hu.get(t);
|
|
17045
|
+
e = e.unionWith(r.view.eu);
|
|
17024
17046
|
}
|
|
17025
17047
|
return e;
|
|
17026
17048
|
}
|
|
@@ -17031,8 +17053,8 @@ function __PRIVATE_syncEngineGetRemoteKeysForTarget(e, t) {
|
|
|
17031
17053
|
* from persistence.
|
|
17032
17054
|
*/ async function __PRIVATE_synchronizeViewAndComputeSnapshot(e, t) {
|
|
17033
17055
|
const n = __PRIVATE_debugCast(e), r = await __PRIVATE_localStoreExecuteQuery(n.localStore, t.query,
|
|
17034
|
-
/* usePreviousResults= */ !0), i = t.view.
|
|
17035
|
-
return n.isPrimaryClient && __PRIVATE_updateTrackedLimbos(n, t.targetId, i.
|
|
17056
|
+
/* usePreviousResults= */ !0), i = t.view.au(r);
|
|
17057
|
+
return n.isPrimaryClient && __PRIVATE_updateTrackedLimbos(n, t.targetId, i.ou),
|
|
17036
17058
|
i;
|
|
17037
17059
|
}
|
|
17038
17060
|
|
|
@@ -17068,7 +17090,7 @@ async function __PRIVATE_syncEngineApplyBatchState(e, t, n, r) {
|
|
|
17068
17090
|
}
|
|
17069
17091
|
// PORTING NOTE: Multi-Tab only.
|
|
17070
17092
|
(i.localStore, t)) : fail(6720, "Unknown batchState", {
|
|
17071
|
-
|
|
17093
|
+
yu: n
|
|
17072
17094
|
}), await __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(i, s)) :
|
|
17073
17095
|
// A throttled tab may not have seen the mutation before it was completed
|
|
17074
17096
|
// and removed from the mutation queue, in which case we won't have cached
|
|
@@ -17085,7 +17107,7 @@ async function __PRIVATE_syncEngineApplyBatchState(e, t, n, r) {
|
|
|
17085
17107
|
async function __PRIVATE_syncEngineApplyPrimaryState(e, t) {
|
|
17086
17108
|
const n = __PRIVATE_debugCast(e);
|
|
17087
17109
|
if (__PRIVATE_ensureWatchCallbacks(n), __PRIVATE_syncEngineEnsureWriteCallbacks(n),
|
|
17088
|
-
!0 === t && !0 !== n.
|
|
17110
|
+
!0 === t && !0 !== n.mu) {
|
|
17089
17111
|
// Secondary tabs only maintain Views for their local listeners and the
|
|
17090
17112
|
// Views internal state may not be 100% populated (in particular
|
|
17091
17113
|
// secondary tabs don't track syncedDocuments, the set of documents the
|
|
@@ -17093,12 +17115,12 @@ async function __PRIVATE_syncEngineApplyPrimaryState(e, t) {
|
|
|
17093
17115
|
// primary, we need to need to make sure that all views for all targets
|
|
17094
17116
|
// match the state on disk.
|
|
17095
17117
|
const e = n.sharedClientState.getAllActiveQueryTargets(), t = await __PRIVATE_synchronizeQueryViewsAndRaiseSnapshots(n, e.toArray());
|
|
17096
|
-
n.
|
|
17118
|
+
n.mu = !0, await __PRIVATE_remoteStoreApplyPrimaryState(n.remoteStore, !0);
|
|
17097
17119
|
for (const e of t) __PRIVATE_remoteStoreListen(n.remoteStore, e);
|
|
17098
|
-
} else if (!1 === t && !1 !== n.
|
|
17120
|
+
} else if (!1 === t && !1 !== n.mu) {
|
|
17099
17121
|
const e = [];
|
|
17100
17122
|
let t = Promise.resolve();
|
|
17101
|
-
n.
|
|
17123
|
+
n.Pu.forEach(((r, i) => {
|
|
17102
17124
|
n.sharedClientState.isLocalQueryTarget(i) ? e.push(i) : t = t.then((() => (__PRIVATE_removeAndCleanupTarget(n, i),
|
|
17103
17125
|
__PRIVATE_localStoreReleaseTarget(n.localStore, i,
|
|
17104
17126
|
/*keepPersistedTargetData=*/ !0)))), __PRIVATE_remoteStoreUnlisten(n.remoteStore, i);
|
|
@@ -17106,9 +17128,9 @@ async function __PRIVATE_syncEngineApplyPrimaryState(e, t) {
|
|
|
17106
17128
|
// PORTING NOTE: Multi-Tab only.
|
|
17107
17129
|
function __PRIVATE_resetLimboDocuments(e) {
|
|
17108
17130
|
const t = __PRIVATE_debugCast(e);
|
|
17109
|
-
t.
|
|
17131
|
+
t.Eu.forEach(((e, n) => {
|
|
17110
17132
|
__PRIVATE_remoteStoreUnlisten(t.remoteStore, n);
|
|
17111
|
-
})), t.
|
|
17133
|
+
})), t.du.Jr(), t.Eu = new Map, t.Iu = new SortedMap(DocumentKey.comparator);
|
|
17112
17134
|
}
|
|
17113
17135
|
/**
|
|
17114
17136
|
* Reconcile the query views of the provided query targets with the state from
|
|
@@ -17121,7 +17143,7 @@ async function __PRIVATE_syncEngineApplyPrimaryState(e, t) {
|
|
|
17121
17143
|
* tab to a primary tab
|
|
17122
17144
|
*/
|
|
17123
17145
|
// PORTING NOTE: Multi-Tab only.
|
|
17124
|
-
(n), n.
|
|
17146
|
+
(n), n.mu = !1, await __PRIVATE_remoteStoreApplyPrimaryState(n.remoteStore, !1);
|
|
17125
17147
|
}
|
|
17126
17148
|
}
|
|
17127
17149
|
|
|
@@ -17129,7 +17151,7 @@ async function __PRIVATE_synchronizeQueryViewsAndRaiseSnapshots(e, t, n) {
|
|
|
17129
17151
|
const r = __PRIVATE_debugCast(e), i = [], s = [];
|
|
17130
17152
|
for (const e of t) {
|
|
17131
17153
|
let t;
|
|
17132
|
-
const n = r.
|
|
17154
|
+
const n = r.Pu.get(e);
|
|
17133
17155
|
if (n && 0 !== n.length) {
|
|
17134
17156
|
// For queries that have a local View, we fetch their current state
|
|
17135
17157
|
// from LocalStore (as the resume token and the snapshot version
|
|
@@ -17137,7 +17159,7 @@ async function __PRIVATE_synchronizeQueryViewsAndRaiseSnapshots(e, t, n) {
|
|
|
17137
17159
|
// state (the list of syncedDocuments may have gotten out of sync).
|
|
17138
17160
|
t = await __PRIVATE_localStoreAllocateTarget(r.localStore, __PRIVATE_queryToTarget(n[0]));
|
|
17139
17161
|
for (const e of n) {
|
|
17140
|
-
const t = r.
|
|
17162
|
+
const t = r.hu.get(e), n = await __PRIVATE_synchronizeViewAndComputeSnapshot(r, t);
|
|
17141
17163
|
n.snapshot && s.push(n.snapshot);
|
|
17142
17164
|
}
|
|
17143
17165
|
} else {
|
|
@@ -17149,7 +17171,7 @@ async function __PRIVATE_synchronizeQueryViewsAndRaiseSnapshots(e, t, n) {
|
|
|
17149
17171
|
}
|
|
17150
17172
|
i.push(t);
|
|
17151
17173
|
}
|
|
17152
|
-
return r.
|
|
17174
|
+
return r.lu.Y_(s), i;
|
|
17153
17175
|
}
|
|
17154
17176
|
|
|
17155
17177
|
/**
|
|
@@ -17179,11 +17201,11 @@ function __PRIVATE_syncEngineGetActiveClients(e) {
|
|
|
17179
17201
|
// PORTING NOTE: Multi-Tab only.
|
|
17180
17202
|
async function __PRIVATE_syncEngineApplyTargetState(e, t, n, r) {
|
|
17181
17203
|
const i = __PRIVATE_debugCast(e);
|
|
17182
|
-
if (i.
|
|
17204
|
+
if (i.mu)
|
|
17183
17205
|
// If we receive a target state notification via WebStorage, we are
|
|
17184
17206
|
// either already secondary or another tab has taken the primary lease.
|
|
17185
17207
|
return void __PRIVATE_logDebug(nn, "Ignoring unexpected query state notification.");
|
|
17186
|
-
const s = i.
|
|
17208
|
+
const s = i.Pu.get(t);
|
|
17187
17209
|
if (s && s.length > 0) switch (n) {
|
|
17188
17210
|
case "current":
|
|
17189
17211
|
case "not-current":
|
|
@@ -17205,9 +17227,9 @@ async function __PRIVATE_syncEngineApplyTargetState(e, t, n, r) {
|
|
|
17205
17227
|
|
|
17206
17228
|
/** Adds or removes Watch targets for queries from different tabs. */ async function __PRIVATE_syncEngineApplyActiveTargetsChange(e, t, n) {
|
|
17207
17229
|
const r = __PRIVATE_ensureWatchCallbacks(e);
|
|
17208
|
-
if (r.
|
|
17230
|
+
if (r.mu) {
|
|
17209
17231
|
for (const e of t) {
|
|
17210
|
-
if (r.
|
|
17232
|
+
if (r.Pu.has(e) && r.sharedClientState.isActiveQueryTarget(e)) {
|
|
17211
17233
|
__PRIVATE_logDebug(nn, "Adding an already active target " + e);
|
|
17212
17234
|
continue;
|
|
17213
17235
|
}
|
|
@@ -17218,7 +17240,7 @@ async function __PRIVATE_syncEngineApplyTargetState(e, t, n, r) {
|
|
|
17218
17240
|
for (const e of n)
|
|
17219
17241
|
// Check that the target is still active since the target might have been
|
|
17220
17242
|
// removed if it has been rejected by the backend.
|
|
17221
|
-
r.
|
|
17243
|
+
r.Pu.has(e) &&
|
|
17222
17244
|
// Release queries that are still active.
|
|
17223
17245
|
await __PRIVATE_localStoreReleaseTarget(r.localStore, e,
|
|
17224
17246
|
/* keepPersistedTargetData */ !1).then((() => {
|
|
@@ -17232,7 +17254,7 @@ function __PRIVATE_ensureWatchCallbacks(e) {
|
|
|
17232
17254
|
return t.remoteStore.remoteSyncer.applyRemoteEvent = __PRIVATE_syncEngineApplyRemoteEvent.bind(null, t),
|
|
17233
17255
|
t.remoteStore.remoteSyncer.getRemoteKeysForTarget = __PRIVATE_syncEngineGetRemoteKeysForTarget.bind(null, t),
|
|
17234
17256
|
t.remoteStore.remoteSyncer.rejectListen = __PRIVATE_syncEngineRejectListen.bind(null, t),
|
|
17235
|
-
t.
|
|
17257
|
+
t.lu.Y_ = __PRIVATE_eventManagerOnWatchChange.bind(null, t.eventManager), t.lu.gu = __PRIVATE_eventManagerOnWatchError.bind(null, t.eventManager),
|
|
17236
17258
|
t;
|
|
17237
17259
|
}
|
|
17238
17260
|
|
|
@@ -17275,13 +17297,13 @@ function __PRIVATE_syncEngineEnsureWriteCallbacks(e) {
|
|
|
17275
17297
|
}(r)), Promise.resolve(new Set);
|
|
17276
17298
|
n._updateProgress(__PRIVATE_bundleInitialProgress(r));
|
|
17277
17299
|
const i = new __PRIVATE_BundleLoader(r, e.localStore, t.serializer);
|
|
17278
|
-
let s = await t.
|
|
17300
|
+
let s = await t.wu();
|
|
17279
17301
|
for (;s; ) {
|
|
17280
|
-
const e = await i
|
|
17281
|
-
e && n._updateProgress(e), s = await t.
|
|
17302
|
+
const e = await i.Wa(s);
|
|
17303
|
+
e && n._updateProgress(e), s = await t.wu();
|
|
17282
17304
|
}
|
|
17283
17305
|
const o = await i.complete();
|
|
17284
|
-
return await __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(e, o.
|
|
17306
|
+
return await __PRIVATE_syncEngineEmitNewSnapsAndNotifyLocalStore(e, o.ja,
|
|
17285
17307
|
/* remoteEvent */ void 0),
|
|
17286
17308
|
// Save metadata, so loading the same bundle will skip.
|
|
17287
17309
|
await function __PRIVATE_localStoreSaveBundle(e, t) {
|
|
@@ -17291,7 +17313,7 @@ function __PRIVATE_syncEngineEnsureWriteCallbacks(e) {
|
|
|
17291
17313
|
/**
|
|
17292
17314
|
* Returns a promise of a `NamedQuery` associated with given query name. Promise
|
|
17293
17315
|
* resolves to undefined if no persisted data can be found.
|
|
17294
|
-
*/ (e.localStore, r), n._completeWith(o.progress), Promise.resolve(o.
|
|
17316
|
+
*/ (e.localStore, r), n._completeWith(o.progress), Promise.resolve(o.za);
|
|
17295
17317
|
} catch (e) {
|
|
17296
17318
|
return __PRIVATE_logWarn(nn, `Loading bundle failed with ${e}`), n._failWith(e),
|
|
17297
17319
|
Promise.resolve(new Set);
|
|
@@ -17326,23 +17348,23 @@ class __PRIVATE_MemoryOfflineComponentProvider {
|
|
|
17326
17348
|
this.kind = "memory", this.synchronizeTabs = !1;
|
|
17327
17349
|
}
|
|
17328
17350
|
async initialize(e) {
|
|
17329
|
-
this.serializer = __PRIVATE_newSerializer(e.databaseInfo.databaseId), this.sharedClientState = this.
|
|
17330
|
-
this.persistence = this.
|
|
17331
|
-
this.gcScheduler = this.
|
|
17351
|
+
this.serializer = __PRIVATE_newSerializer(e.databaseInfo.databaseId), this.sharedClientState = this.bu(e),
|
|
17352
|
+
this.persistence = this.Su(e), await this.persistence.start(), this.localStore = this.Du(e),
|
|
17353
|
+
this.gcScheduler = this.vu(e, this.localStore), this.indexBackfillerScheduler = this.Cu(e, this.localStore);
|
|
17332
17354
|
}
|
|
17333
|
-
|
|
17355
|
+
vu(e, t) {
|
|
17334
17356
|
return null;
|
|
17335
17357
|
}
|
|
17336
|
-
|
|
17358
|
+
Cu(e, t) {
|
|
17337
17359
|
return null;
|
|
17338
17360
|
}
|
|
17339
|
-
|
|
17361
|
+
Du(e) {
|
|
17340
17362
|
return __PRIVATE_newLocalStore(this.persistence, new __PRIVATE_QueryEngine, e.initialUser, this.serializer);
|
|
17341
17363
|
}
|
|
17342
|
-
|
|
17364
|
+
Su(e) {
|
|
17343
17365
|
return new __PRIVATE_MemoryPersistence(__PRIVATE_MemoryEagerDelegate.fi, this.serializer);
|
|
17344
17366
|
}
|
|
17345
|
-
|
|
17367
|
+
bu(e) {
|
|
17346
17368
|
return new __PRIVATE_MemorySharedClientState;
|
|
17347
17369
|
}
|
|
17348
17370
|
async terminate() {
|
|
@@ -17360,12 +17382,12 @@ class __PRIVATE_LruGcMemoryOfflineComponentProvider extends __PRIVATE_MemoryOffl
|
|
|
17360
17382
|
constructor(e) {
|
|
17361
17383
|
super(), this.cacheSizeBytes = e;
|
|
17362
17384
|
}
|
|
17363
|
-
|
|
17385
|
+
vu(e, t) {
|
|
17364
17386
|
__PRIVATE_hardAssert(this.persistence.referenceDelegate instanceof __PRIVATE_MemoryLruDelegate, 46915);
|
|
17365
17387
|
const n = this.persistence.referenceDelegate.garbageCollector;
|
|
17366
17388
|
return new __PRIVATE_LruScheduler(n, e.asyncQueue, t);
|
|
17367
17389
|
}
|
|
17368
|
-
|
|
17390
|
+
Su(e) {
|
|
17369
17391
|
const t = void 0 !== this.cacheSizeBytes ? LruParams.withCacheSize(this.cacheSizeBytes) : LruParams.DEFAULT;
|
|
17370
17392
|
return new __PRIVATE_MemoryPersistence((e => __PRIVATE_MemoryLruDelegate.fi(e, t)), this.serializer);
|
|
17371
17393
|
}
|
|
@@ -17375,35 +17397,35 @@ class __PRIVATE_LruGcMemoryOfflineComponentProvider extends __PRIVATE_MemoryOffl
|
|
|
17375
17397
|
* Provides all components needed for Firestore with IndexedDB persistence.
|
|
17376
17398
|
*/ class __PRIVATE_IndexedDbOfflineComponentProvider extends __PRIVATE_MemoryOfflineComponentProvider {
|
|
17377
17399
|
constructor(e, t, n) {
|
|
17378
|
-
super(), this.
|
|
17400
|
+
super(), this.Fu = e, this.cacheSizeBytes = t, this.forceOwnership = n, this.kind = "persistent",
|
|
17379
17401
|
this.synchronizeTabs = !1;
|
|
17380
17402
|
}
|
|
17381
17403
|
async initialize(e) {
|
|
17382
|
-
await super.initialize(e), await this.
|
|
17404
|
+
await super.initialize(e), await this.Fu.initialize(this, e),
|
|
17383
17405
|
// Enqueue writes from a previous session
|
|
17384
|
-
await __PRIVATE_syncEngineEnsureWriteCallbacks(this.
|
|
17406
|
+
await __PRIVATE_syncEngineEnsureWriteCallbacks(this.Fu.syncEngine), await __PRIVATE_fillWritePipeline(this.Fu.remoteStore),
|
|
17385
17407
|
// NOTE: This will immediately call the listener, so we make sure to
|
|
17386
17408
|
// set it after localStore / remoteStore are started.
|
|
17387
17409
|
await this.persistence.Ji((() => (this.gcScheduler && !this.gcScheduler.started && this.gcScheduler.start(),
|
|
17388
17410
|
this.indexBackfillerScheduler && !this.indexBackfillerScheduler.started && this.indexBackfillerScheduler.start(),
|
|
17389
17411
|
Promise.resolve())));
|
|
17390
17412
|
}
|
|
17391
|
-
|
|
17413
|
+
Du(e) {
|
|
17392
17414
|
return __PRIVATE_newLocalStore(this.persistence, new __PRIVATE_QueryEngine, e.initialUser, this.serializer);
|
|
17393
17415
|
}
|
|
17394
|
-
|
|
17416
|
+
vu(e, t) {
|
|
17395
17417
|
const n = this.persistence.referenceDelegate.garbageCollector;
|
|
17396
17418
|
return new __PRIVATE_LruScheduler(n, e.asyncQueue, t);
|
|
17397
17419
|
}
|
|
17398
|
-
|
|
17420
|
+
Cu(e, t) {
|
|
17399
17421
|
const n = new __PRIVATE_IndexBackfiller(t, this.persistence);
|
|
17400
17422
|
return new __PRIVATE_IndexBackfillerScheduler(e.asyncQueue, n);
|
|
17401
17423
|
}
|
|
17402
|
-
|
|
17424
|
+
Su(e) {
|
|
17403
17425
|
const t = __PRIVATE_indexedDbStoragePrefix(e.databaseInfo.databaseId, e.databaseInfo.persistenceKey), n = void 0 !== this.cacheSizeBytes ? LruParams.withCacheSize(this.cacheSizeBytes) : LruParams.DEFAULT;
|
|
17404
17426
|
return new __PRIVATE_IndexedDbPersistence(this.synchronizeTabs, t, e.clientId, n, e.asyncQueue, __PRIVATE_getWindow(), getDocument(), this.serializer, this.sharedClientState, !!this.forceOwnership);
|
|
17405
17427
|
}
|
|
17406
|
-
|
|
17428
|
+
bu(e) {
|
|
17407
17429
|
return new __PRIVATE_MemorySharedClientState;
|
|
17408
17430
|
}
|
|
17409
17431
|
}
|
|
@@ -17417,11 +17439,11 @@ class __PRIVATE_LruGcMemoryOfflineComponentProvider extends __PRIVATE_MemoryOffl
|
|
|
17417
17439
|
* `synchronizeTabs` will be enabled.
|
|
17418
17440
|
*/ class __PRIVATE_MultiTabOfflineComponentProvider extends __PRIVATE_IndexedDbOfflineComponentProvider {
|
|
17419
17441
|
constructor(e, t) {
|
|
17420
|
-
super(e, t, /* forceOwnership= */ !1), this.
|
|
17442
|
+
super(e, t, /* forceOwnership= */ !1), this.Fu = e, this.cacheSizeBytes = t, this.synchronizeTabs = !0;
|
|
17421
17443
|
}
|
|
17422
17444
|
async initialize(e) {
|
|
17423
17445
|
await super.initialize(e);
|
|
17424
|
-
const t = this.
|
|
17446
|
+
const t = this.Fu.syncEngine;
|
|
17425
17447
|
this.sharedClientState instanceof __PRIVATE_WebStorageSharedClientState && (this.sharedClientState.syncEngine = {
|
|
17426
17448
|
Co: __PRIVATE_syncEngineApplyBatchState.bind(null, t),
|
|
17427
17449
|
Fo: __PRIVATE_syncEngineApplyTargetState.bind(null, t),
|
|
@@ -17432,11 +17454,11 @@ class __PRIVATE_LruGcMemoryOfflineComponentProvider extends __PRIVATE_MemoryOffl
|
|
|
17432
17454
|
// NOTE: This will immediately call the listener, so we make sure to
|
|
17433
17455
|
// set it after localStore / remoteStore are started.
|
|
17434
17456
|
await this.persistence.Ji((async e => {
|
|
17435
|
-
await __PRIVATE_syncEngineApplyPrimaryState(this.
|
|
17457
|
+
await __PRIVATE_syncEngineApplyPrimaryState(this.Fu.syncEngine, e), this.gcScheduler && (e && !this.gcScheduler.started ? this.gcScheduler.start() : e || this.gcScheduler.stop()),
|
|
17436
17458
|
this.indexBackfillerScheduler && (e && !this.indexBackfillerScheduler.started ? this.indexBackfillerScheduler.start() : e || this.indexBackfillerScheduler.stop());
|
|
17437
17459
|
}));
|
|
17438
17460
|
}
|
|
17439
|
-
|
|
17461
|
+
bu(e) {
|
|
17440
17462
|
const t = __PRIVATE_getWindow();
|
|
17441
17463
|
if (!__PRIVATE_WebStorageSharedClientState.C(t)) throw new FirestoreError(N.UNIMPLEMENTED, "IndexedDB persistence is only available on platforms that support LocalStorage.");
|
|
17442
17464
|
const n = __PRIVATE_indexedDbStoragePrefix(e.databaseInfo.databaseId, e.databaseInfo.persistenceKey);
|
|
@@ -17483,18 +17505,18 @@ class __PRIVATE_LruGcMemoryOfflineComponentProvider extends __PRIVATE_MemoryOffl
|
|
|
17483
17505
|
// PORTING NOTE: Manages state synchronization in multi-tab environments.
|
|
17484
17506
|
r, i, s, o) {
|
|
17485
17507
|
const _ = new __PRIVATE_SyncEngineImpl(e, t, n, r, i, s);
|
|
17486
|
-
return o && (_.
|
|
17508
|
+
return o && (_.mu = !0), _;
|
|
17487
17509
|
}(this.localStore, this.remoteStore, this.eventManager, this.sharedClientState, e.initialUser, e.maxConcurrentLimboResolutions, t);
|
|
17488
17510
|
}
|
|
17489
17511
|
async terminate() {
|
|
17490
17512
|
var e, t;
|
|
17491
17513
|
await async function __PRIVATE_remoteStoreShutdown(e) {
|
|
17492
17514
|
const t = __PRIVATE_debugCast(e);
|
|
17493
|
-
__PRIVATE_logDebug(Xt, "RemoteStore shutting down."), t.
|
|
17494
|
-
await __PRIVATE_disableNetworkInternal(t), t.
|
|
17515
|
+
__PRIVATE_logDebug(Xt, "RemoteStore shutting down."), t.da.add(5 /* OfflineCause.Shutdown */),
|
|
17516
|
+
await __PRIVATE_disableNetworkInternal(t), t.Ra.shutdown(),
|
|
17495
17517
|
// Set the OnlineState to Unknown (rather than Offline) to avoid potentially
|
|
17496
17518
|
// triggering spurious listener events with cached data, etc.
|
|
17497
|
-
t.
|
|
17519
|
+
t.Va.set("Unknown" /* OnlineState.Unknown */);
|
|
17498
17520
|
}(this.remoteStore), null === (e = this.datastore) || void 0 === e || e.terminate(),
|
|
17499
17521
|
null === (t = this.eventManager) || void 0 === t || t.terminate();
|
|
17500
17522
|
}
|
|
@@ -17586,15 +17608,15 @@ class __PRIVATE_AsyncObserver {
|
|
|
17586
17608
|
this.muted = !1;
|
|
17587
17609
|
}
|
|
17588
17610
|
next(e) {
|
|
17589
|
-
this.muted || this.observer.next && this.
|
|
17611
|
+
this.muted || this.observer.next && this.Mu(this.observer.next, e);
|
|
17590
17612
|
}
|
|
17591
17613
|
error(e) {
|
|
17592
|
-
this.muted || (this.observer.error ? this.
|
|
17614
|
+
this.muted || (this.observer.error ? this.Mu(this.observer.error, e) : __PRIVATE_logError("Uncaught Error in snapshot listener:", e.toString()));
|
|
17593
17615
|
}
|
|
17594
|
-
|
|
17616
|
+
xu() {
|
|
17595
17617
|
this.muted = !0;
|
|
17596
17618
|
}
|
|
17597
|
-
|
|
17619
|
+
Mu(e, t) {
|
|
17598
17620
|
setTimeout((() => {
|
|
17599
17621
|
this.muted || e(t);
|
|
17600
17622
|
}), 0);
|
|
@@ -17626,30 +17648,30 @@ class __PRIVATE_AsyncObserver {
|
|
|
17626
17648
|
constructor(
|
|
17627
17649
|
/** The reader to read from underlying binary bundle data source. */
|
|
17628
17650
|
e, t) {
|
|
17629
|
-
this.
|
|
17651
|
+
this.Ou = e, this.serializer = t,
|
|
17630
17652
|
/** Cached bundle metadata. */
|
|
17631
17653
|
this.metadata = new __PRIVATE_Deferred,
|
|
17632
17654
|
/**
|
|
17633
17655
|
* Internal buffer to hold bundle content, accumulating incomplete element
|
|
17634
17656
|
* content.
|
|
17635
17657
|
*/
|
|
17636
|
-
this.buffer = new Uint8Array, this.
|
|
17658
|
+
this.buffer = new Uint8Array, this.Nu = function __PRIVATE_newTextDecoder() {
|
|
17637
17659
|
return new TextDecoder("utf-8");
|
|
17638
17660
|
}(),
|
|
17639
17661
|
// Read the metadata (which is the first element).
|
|
17640
|
-
this.
|
|
17641
|
-
e && e.
|
|
17662
|
+
this.Bu().then((e => {
|
|
17663
|
+
e && e.Ua() ? this.metadata.resolve(e.$a.metadata) : this.metadata.reject(new Error(`The first element of the bundle is not a metadata, it is\n ${JSON.stringify(null == e ? void 0 : e.$a)}`));
|
|
17642
17664
|
}), (e => this.metadata.reject(e)));
|
|
17643
17665
|
}
|
|
17644
17666
|
close() {
|
|
17645
|
-
return this.
|
|
17667
|
+
return this.Ou.cancel();
|
|
17646
17668
|
}
|
|
17647
17669
|
async getMetadata() {
|
|
17648
17670
|
return this.metadata.promise;
|
|
17649
17671
|
}
|
|
17650
|
-
async
|
|
17672
|
+
async wu() {
|
|
17651
17673
|
// Makes sure metadata is read before proceeding.
|
|
17652
|
-
return await this.getMetadata(), this.
|
|
17674
|
+
return await this.getMetadata(), this.Bu();
|
|
17653
17675
|
}
|
|
17654
17676
|
/**
|
|
17655
17677
|
* Reads from the head of internal buffer, and pulling more data from
|
|
@@ -17660,15 +17682,15 @@ class __PRIVATE_AsyncObserver {
|
|
|
17660
17682
|
*
|
|
17661
17683
|
* Returns either the bundled element, or null if we have reached the end of
|
|
17662
17684
|
* the stream.
|
|
17663
|
-
*/ async
|
|
17664
|
-
const e = await this.
|
|
17685
|
+
*/ async Bu() {
|
|
17686
|
+
const e = await this.Lu();
|
|
17665
17687
|
if (null === e) return null;
|
|
17666
|
-
const t = this.
|
|
17667
|
-
isNaN(n) && this.
|
|
17668
|
-
const r = await this.
|
|
17688
|
+
const t = this.Nu.decode(e), n = Number(t);
|
|
17689
|
+
isNaN(n) && this.ku(`length string (${t}) is not valid number`);
|
|
17690
|
+
const r = await this.qu(n);
|
|
17669
17691
|
return new __PRIVATE_SizedBundleElement(JSON.parse(r), e.length + n);
|
|
17670
17692
|
}
|
|
17671
|
-
/** First index of '{' from the underlying buffer. */
|
|
17693
|
+
/** First index of '{' from the underlying buffer. */ Qu() {
|
|
17672
17694
|
return this.buffer.findIndex((e => e === "{".charCodeAt(0)));
|
|
17673
17695
|
}
|
|
17674
17696
|
/**
|
|
@@ -17676,17 +17698,17 @@ class __PRIVATE_AsyncObserver {
|
|
|
17676
17698
|
* return the content.
|
|
17677
17699
|
*
|
|
17678
17700
|
* If reached end of the stream, returns a null.
|
|
17679
|
-
*/ async
|
|
17680
|
-
for (;this.
|
|
17681
|
-
if (await this
|
|
17701
|
+
*/ async Lu() {
|
|
17702
|
+
for (;this.Qu() < 0; ) {
|
|
17703
|
+
if (await this.$u()) break;
|
|
17682
17704
|
}
|
|
17683
17705
|
// Broke out of the loop because underlying stream is closed, and there
|
|
17684
17706
|
// happens to be no more data to process.
|
|
17685
17707
|
if (0 === this.buffer.length) return null;
|
|
17686
|
-
const e = this.
|
|
17708
|
+
const e = this.Qu();
|
|
17687
17709
|
// Broke out of the loop because underlying stream is closed, but still
|
|
17688
17710
|
// cannot find an open bracket.
|
|
17689
|
-
e < 0 && this.
|
|
17711
|
+
e < 0 && this.ku("Reached the end of bundle when a length string is expected.");
|
|
17690
17712
|
const t = this.buffer.slice(0, e);
|
|
17691
17713
|
// Update the internal buffer to drop the read length.
|
|
17692
17714
|
return this.buffer = this.buffer.slice(e), t;
|
|
@@ -17696,23 +17718,23 @@ class __PRIVATE_AsyncObserver {
|
|
|
17696
17718
|
* number of bytes, pulling more data from the underlying stream if needed.
|
|
17697
17719
|
*
|
|
17698
17720
|
* Returns a string decoded from the read bytes.
|
|
17699
|
-
*/ async
|
|
17721
|
+
*/ async qu(e) {
|
|
17700
17722
|
for (;this.buffer.length < e; ) {
|
|
17701
|
-
await this
|
|
17723
|
+
await this.$u() && this.ku("Reached the end of bundle when more is expected.");
|
|
17702
17724
|
}
|
|
17703
|
-
const t = this.
|
|
17725
|
+
const t = this.Nu.decode(this.buffer.slice(0, e));
|
|
17704
17726
|
// Update the internal buffer to drop the read json string.
|
|
17705
17727
|
return this.buffer = this.buffer.slice(e), t;
|
|
17706
17728
|
}
|
|
17707
|
-
|
|
17729
|
+
ku(e) {
|
|
17708
17730
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
17709
|
-
throw this.
|
|
17731
|
+
throw this.Ou.cancel(), new Error(`Invalid bundle format: ${e}`);
|
|
17710
17732
|
}
|
|
17711
17733
|
/**
|
|
17712
17734
|
* Pulls more data from underlying stream to internal buffer.
|
|
17713
17735
|
* Returns a boolean indicating whether the stream is finished.
|
|
17714
|
-
*/ async
|
|
17715
|
-
const e = await this.
|
|
17736
|
+
*/ async $u() {
|
|
17737
|
+
const e = await this.Ou.read();
|
|
17716
17738
|
if (!e.done) {
|
|
17717
17739
|
const t = new Uint8Array(this.buffer.length + e.value.length);
|
|
17718
17740
|
t.set(this.buffer), t.set(e.value, this.buffer.length), this.buffer = t;
|
|
@@ -17817,7 +17839,7 @@ class Transaction$2 {
|
|
|
17817
17839
|
let t;
|
|
17818
17840
|
if (e.isFoundDocument()) t = e.version; else {
|
|
17819
17841
|
if (!e.isNoDocument()) throw fail(50498, {
|
|
17820
|
-
|
|
17842
|
+
Uu: e.constructor.name
|
|
17821
17843
|
});
|
|
17822
17844
|
// Represent a deleted doc using SnapshotVersion.min().
|
|
17823
17845
|
t = SnapshotVersion.min();
|
|
@@ -17889,26 +17911,26 @@ class Transaction$2 {
|
|
|
17889
17911
|
*/ class __PRIVATE_TransactionRunner {
|
|
17890
17912
|
constructor(e, t, n, r, i) {
|
|
17891
17913
|
this.asyncQueue = e, this.datastore = t, this.options = n, this.updateFunction = r,
|
|
17892
|
-
this.deferred = i, this.
|
|
17914
|
+
this.deferred = i, this.Ku = n.maxAttempts, this.x_ = new __PRIVATE_ExponentialBackoff(this.asyncQueue, "transaction_retry" /* TimerId.TransactionRetry */);
|
|
17893
17915
|
}
|
|
17894
|
-
/** Runs the transaction and sets the result on deferred. */
|
|
17895
|
-
this.
|
|
17916
|
+
/** Runs the transaction and sets the result on deferred. */ Wu() {
|
|
17917
|
+
this.Ku -= 1, this.Gu();
|
|
17896
17918
|
}
|
|
17897
|
-
|
|
17898
|
-
this.
|
|
17899
|
-
const e = new Transaction$2(this.datastore), t = this.
|
|
17919
|
+
Gu() {
|
|
17920
|
+
this.x_.y_((async () => {
|
|
17921
|
+
const e = new Transaction$2(this.datastore), t = this.zu(e);
|
|
17900
17922
|
t && t.then((t => {
|
|
17901
17923
|
this.asyncQueue.enqueueAndForget((() => e.commit().then((() => {
|
|
17902
17924
|
this.deferred.resolve(t);
|
|
17903
17925
|
})).catch((e => {
|
|
17904
|
-
this.
|
|
17926
|
+
this.ju(e);
|
|
17905
17927
|
}))));
|
|
17906
17928
|
})).catch((e => {
|
|
17907
|
-
this.
|
|
17929
|
+
this.ju(e);
|
|
17908
17930
|
}));
|
|
17909
17931
|
}));
|
|
17910
17932
|
}
|
|
17911
|
-
|
|
17933
|
+
zu(e) {
|
|
17912
17934
|
try {
|
|
17913
17935
|
const t = this.updateFunction(e);
|
|
17914
17936
|
return !__PRIVATE_isNullOrUndefined(t) && t.catch && t.then ? t : (this.deferred.reject(Error("Transaction callback must return a Promise")),
|
|
@@ -17918,11 +17940,11 @@ class Transaction$2 {
|
|
|
17918
17940
|
return this.deferred.reject(e), null;
|
|
17919
17941
|
}
|
|
17920
17942
|
}
|
|
17921
|
-
|
|
17922
|
-
this.
|
|
17943
|
+
ju(e) {
|
|
17944
|
+
this.Ku > 0 && this.Hu(e) ? (this.Ku -= 1, this.asyncQueue.enqueueAndForget((() => (this.Gu(),
|
|
17923
17945
|
Promise.resolve())))) : this.deferred.reject(e);
|
|
17924
17946
|
}
|
|
17925
|
-
|
|
17947
|
+
Hu(e) {
|
|
17926
17948
|
if ("FirebaseError" === e.name) {
|
|
17927
17949
|
// In transactions, the backend will fail outdated reads with FAILED_PRECONDITION and
|
|
17928
17950
|
// non-matching document versions with ABORTED. These errors should be retried.
|
|
@@ -18100,7 +18122,7 @@ async function __PRIVATE_getEventManager(e) {
|
|
|
18100
18122
|
const t = await __PRIVATE_getPersistence(e), n = await __PRIVATE_getRemoteStore(e);
|
|
18101
18123
|
return t.setNetworkEnabled(!0), function __PRIVATE_remoteStoreEnableNetwork(e) {
|
|
18102
18124
|
const t = __PRIVATE_debugCast(e);
|
|
18103
|
-
return t.
|
|
18125
|
+
return t.da.delete(0 /* OfflineCause.UserDisabled */), __PRIVATE_enableNetworkInternal(t);
|
|
18104
18126
|
}(n);
|
|
18105
18127
|
}));
|
|
18106
18128
|
}
|
|
@@ -18110,9 +18132,9 @@ async function __PRIVATE_getEventManager(e) {
|
|
|
18110
18132
|
const t = await __PRIVATE_getPersistence(e), n = await __PRIVATE_getRemoteStore(e);
|
|
18111
18133
|
return t.setNetworkEnabled(!1), async function __PRIVATE_remoteStoreDisableNetwork(e) {
|
|
18112
18134
|
const t = __PRIVATE_debugCast(e);
|
|
18113
|
-
t.
|
|
18135
|
+
t.da.add(0 /* OfflineCause.UserDisabled */), await __PRIVATE_disableNetworkInternal(t),
|
|
18114
18136
|
// Set the OnlineState to Offline so get()s return from cache, etc.
|
|
18115
|
-
t.
|
|
18137
|
+
t.Va.set("Offline" /* OnlineState.Offline */);
|
|
18116
18138
|
}(n);
|
|
18117
18139
|
}));
|
|
18118
18140
|
}
|
|
@@ -18148,7 +18170,7 @@ function __PRIVATE_firestoreClientGetDocumentViaSnapshotListener(e, t, n = {}) {
|
|
|
18148
18170
|
next: _ => {
|
|
18149
18171
|
// Mute and remove query first before passing event to user to avoid
|
|
18150
18172
|
// user actions affecting the now stale query.
|
|
18151
|
-
s.
|
|
18173
|
+
s.xu(), t.enqueueAndForget((() => __PRIVATE_eventManagerUnlisten(e, o)));
|
|
18152
18174
|
const a = _.docs.has(n);
|
|
18153
18175
|
!a && _.fromCache ?
|
|
18154
18176
|
// TODO(dimond): If we're online and the document doesn't
|
|
@@ -18163,7 +18185,7 @@ function __PRIVATE_firestoreClientGetDocumentViaSnapshotListener(e, t, n = {}) {
|
|
|
18163
18185
|
error: e => i.reject(e)
|
|
18164
18186
|
}), o = new __PRIVATE_QueryListener(__PRIVATE_newQueryForPath(n.path), s, {
|
|
18165
18187
|
includeMetadataChanges: !0,
|
|
18166
|
-
|
|
18188
|
+
Qa: !0
|
|
18167
18189
|
});
|
|
18168
18190
|
return __PRIVATE_eventManagerListen(e, o);
|
|
18169
18191
|
}(await __PRIVATE_getEventManager(e), e.asyncQueue, t, n, r))), r.promise;
|
|
@@ -18174,7 +18196,7 @@ function __PRIVATE_firestoreClientGetDocumentsFromLocalCache(e, t) {
|
|
|
18174
18196
|
return e.asyncQueue.enqueueAndForget((async () => async function __PRIVATE_executeQueryFromCache(e, t, n) {
|
|
18175
18197
|
try {
|
|
18176
18198
|
const r = await __PRIVATE_localStoreExecuteQuery(e, t,
|
|
18177
|
-
/* usePreviousResults= */ !0), i = new __PRIVATE_View(t, r.$s), s = i.
|
|
18199
|
+
/* usePreviousResults= */ !0), i = new __PRIVATE_View(t, r.$s), s = i.tu(r.documents), o = i.applyChanges(s,
|
|
18178
18200
|
/* limboResolutionEnabled= */ !1);
|
|
18179
18201
|
n.resolve(o.snapshot);
|
|
18180
18202
|
} catch (e) {
|
|
@@ -18195,12 +18217,12 @@ function __PRIVATE_firestoreClientGetDocumentsViaSnapshotListener(e, t, n = {})
|
|
|
18195
18217
|
next: n => {
|
|
18196
18218
|
// Mute and remove query first before passing event to user to avoid
|
|
18197
18219
|
// user actions affecting the now stale query.
|
|
18198
|
-
s.
|
|
18220
|
+
s.xu(), t.enqueueAndForget((() => __PRIVATE_eventManagerUnlisten(e, o))), n.fromCache && "server" === r.source ? i.reject(new FirestoreError(N.UNAVAILABLE, 'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')) : i.resolve(n);
|
|
18199
18221
|
},
|
|
18200
18222
|
error: e => i.reject(e)
|
|
18201
18223
|
}), o = new __PRIVATE_QueryListener(n, s, {
|
|
18202
18224
|
includeMetadataChanges: !0,
|
|
18203
|
-
|
|
18225
|
+
Qa: !0
|
|
18204
18226
|
});
|
|
18205
18227
|
return __PRIVATE_eventManagerListen(e, o);
|
|
18206
18228
|
}(await __PRIVATE_getEventManager(e), e.asyncQueue, t, n, r))), r.promise;
|
|
@@ -18238,13 +18260,13 @@ function __PRIVATE_firestoreClientRunAggregateQuery(e, t, n) {
|
|
|
18238
18260
|
function __PRIVATE_firestoreClientAddSnapshotsInSyncListener(e, t) {
|
|
18239
18261
|
const n = new __PRIVATE_AsyncObserver(t);
|
|
18240
18262
|
return e.asyncQueue.enqueueAndForget((async () => function __PRIVATE_addSnapshotsInSyncListener(e, t) {
|
|
18241
|
-
__PRIVATE_debugCast(e).
|
|
18263
|
+
__PRIVATE_debugCast(e).Ca.add(t),
|
|
18242
18264
|
// Immediately fire an initial event, indicating all existing listeners
|
|
18243
18265
|
// are in-sync.
|
|
18244
18266
|
t.next();
|
|
18245
18267
|
}(await __PRIVATE_getEventManager(e), n))), () => {
|
|
18246
|
-
n.
|
|
18247
|
-
__PRIVATE_debugCast(e).
|
|
18268
|
+
n.xu(), e.asyncQueue.enqueueAndForget((async () => function __PRIVATE_removeSnapshotsInSyncListener(e, t) {
|
|
18269
|
+
__PRIVATE_debugCast(e).Ca.delete(t);
|
|
18248
18270
|
}(await __PRIVATE_getEventManager(e), n)));
|
|
18249
18271
|
};
|
|
18250
18272
|
}
|
|
@@ -18932,37 +18954,37 @@ class __PRIVATE_AsyncQueueImpl {
|
|
|
18932
18954
|
constructor(e = Promise.resolve()) {
|
|
18933
18955
|
// A list of retryable operations. Retryable operations are run in order and
|
|
18934
18956
|
// retried with backoff.
|
|
18935
|
-
this.
|
|
18957
|
+
this.Ju = [],
|
|
18936
18958
|
// Is this AsyncQueue being shut down? Once it is set to true, it will not
|
|
18937
18959
|
// be changed again.
|
|
18938
|
-
this.
|
|
18960
|
+
this.Yu = !1,
|
|
18939
18961
|
// Operations scheduled to be queued in the future. Operations are
|
|
18940
18962
|
// automatically removed after they are run or canceled.
|
|
18941
|
-
this.
|
|
18963
|
+
this.Zu = [],
|
|
18942
18964
|
// visible for testing
|
|
18943
|
-
this.
|
|
18965
|
+
this.Xu = null,
|
|
18944
18966
|
// Flag set while there's an outstanding AsyncQueue operation, used for
|
|
18945
18967
|
// assertion sanity-checks.
|
|
18946
|
-
this.
|
|
18968
|
+
this.ec = !1,
|
|
18947
18969
|
// Enabled during shutdown on Safari to prevent future access to IndexedDB.
|
|
18948
|
-
this.
|
|
18970
|
+
this.tc = !1,
|
|
18949
18971
|
// List of TimerIds to fast-forward delays for.
|
|
18950
|
-
this.
|
|
18972
|
+
this.nc = [],
|
|
18951
18973
|
// Backoff timer used to schedule retries for retryable operations
|
|
18952
|
-
this.
|
|
18974
|
+
this.x_ = new __PRIVATE_ExponentialBackoff(this, "async_queue_retry" /* TimerId.AsyncQueueRetry */),
|
|
18953
18975
|
// Visibility handler that triggers an immediate retry of all retryable
|
|
18954
18976
|
// operations. Meant to speed up recovery when we regain file system access
|
|
18955
18977
|
// after page comes into foreground.
|
|
18956
|
-
this.
|
|
18978
|
+
this.rc = () => {
|
|
18957
18979
|
const e = getDocument();
|
|
18958
18980
|
e && __PRIVATE_logDebug(an, "Visibility state changed to " + e.visibilityState),
|
|
18959
|
-
this.
|
|
18960
|
-
}, this.
|
|
18981
|
+
this.x_.b_();
|
|
18982
|
+
}, this.sc = e;
|
|
18961
18983
|
const t = getDocument();
|
|
18962
|
-
t && "function" == typeof t.addEventListener && t.addEventListener("visibilitychange", this.
|
|
18984
|
+
t && "function" == typeof t.addEventListener && t.addEventListener("visibilitychange", this.rc);
|
|
18963
18985
|
}
|
|
18964
18986
|
get isShuttingDown() {
|
|
18965
|
-
return this.
|
|
18987
|
+
return this.Yu;
|
|
18966
18988
|
}
|
|
18967
18989
|
/**
|
|
18968
18990
|
* Adds a new operation to the queue without waiting for it to complete (i.e.
|
|
@@ -18972,44 +18994,44 @@ class __PRIVATE_AsyncQueueImpl {
|
|
|
18972
18994
|
this.enqueue(e);
|
|
18973
18995
|
}
|
|
18974
18996
|
enqueueAndForgetEvenWhileRestricted(e) {
|
|
18975
|
-
this.
|
|
18997
|
+
this.oc(),
|
|
18976
18998
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
18977
|
-
this.
|
|
18999
|
+
this._c(e);
|
|
18978
19000
|
}
|
|
18979
19001
|
enterRestrictedMode(e) {
|
|
18980
|
-
if (!this.
|
|
18981
|
-
this.
|
|
19002
|
+
if (!this.Yu) {
|
|
19003
|
+
this.Yu = !0, this.tc = e || !1;
|
|
18982
19004
|
const t = getDocument();
|
|
18983
|
-
t && "function" == typeof t.removeEventListener && t.removeEventListener("visibilitychange", this.
|
|
19005
|
+
t && "function" == typeof t.removeEventListener && t.removeEventListener("visibilitychange", this.rc);
|
|
18984
19006
|
}
|
|
18985
19007
|
}
|
|
18986
19008
|
enqueue(e) {
|
|
18987
|
-
if (this.
|
|
19009
|
+
if (this.oc(), this.Yu)
|
|
18988
19010
|
// Return a Promise which never resolves.
|
|
18989
19011
|
return new Promise((() => {}));
|
|
18990
19012
|
// Create a deferred Promise that we can return to the callee. This
|
|
18991
19013
|
// allows us to return a "hanging Promise" only to the callee and still
|
|
18992
19014
|
// advance the queue even when the operation is not run.
|
|
18993
19015
|
const t = new __PRIVATE_Deferred;
|
|
18994
|
-
return this.
|
|
19016
|
+
return this._c((() => this.Yu && this.tc ? Promise.resolve() : (e().then(t.resolve, t.reject),
|
|
18995
19017
|
t.promise))).then((() => t.promise));
|
|
18996
19018
|
}
|
|
18997
19019
|
enqueueRetryable(e) {
|
|
18998
|
-
this.enqueueAndForget((() => (this.
|
|
19020
|
+
this.enqueueAndForget((() => (this.Ju.push(e), this.ac())));
|
|
18999
19021
|
}
|
|
19000
19022
|
/**
|
|
19001
19023
|
* Runs the next operation from the retryable queue. If the operation fails,
|
|
19002
19024
|
* reschedules with backoff.
|
|
19003
|
-
*/ async
|
|
19004
|
-
if (0 !== this.
|
|
19025
|
+
*/ async ac() {
|
|
19026
|
+
if (0 !== this.Ju.length) {
|
|
19005
19027
|
try {
|
|
19006
|
-
await this.
|
|
19028
|
+
await this.Ju[0](), this.Ju.shift(), this.x_.reset();
|
|
19007
19029
|
} catch (e) {
|
|
19008
19030
|
if (!__PRIVATE_isIndexedDbTransactionError(e)) throw e;
|
|
19009
19031
|
// Failure will be handled by AsyncQueue
|
|
19010
19032
|
__PRIVATE_logDebug(an, "Operation failed with retryable error: " + e);
|
|
19011
19033
|
}
|
|
19012
|
-
this.
|
|
19034
|
+
this.Ju.length > 0 &&
|
|
19013
19035
|
// If there are additional operations, we re-schedule `retryNextOp()`.
|
|
19014
19036
|
// This is necessary to run retryable operations that failed during
|
|
19015
19037
|
// their initial attempt since we don't know whether they are already
|
|
@@ -19020,51 +19042,51 @@ class __PRIVATE_AsyncQueueImpl {
|
|
|
19020
19042
|
// Since `backoffAndRun()` cancels an existing backoff and schedules a
|
|
19021
19043
|
// new backoff on every call, there is only ever a single additional
|
|
19022
19044
|
// operation in the queue.
|
|
19023
|
-
this.
|
|
19045
|
+
this.x_.y_((() => this.ac()));
|
|
19024
19046
|
}
|
|
19025
19047
|
}
|
|
19026
|
-
|
|
19027
|
-
const t = this.
|
|
19028
|
-
this.
|
|
19048
|
+
_c(e) {
|
|
19049
|
+
const t = this.sc.then((() => (this.ec = !0, e().catch((e => {
|
|
19050
|
+
this.Xu = e, this.ec = !1;
|
|
19029
19051
|
// Re-throw the error so that this.tail becomes a rejected Promise and
|
|
19030
19052
|
// all further attempts to chain (via .then) will just short-circuit
|
|
19031
19053
|
// and return the rejected Promise.
|
|
19032
19054
|
throw __PRIVATE_logError("INTERNAL UNHANDLED ERROR: ", __PRIVATE_getMessageOrStack(e)),
|
|
19033
19055
|
e;
|
|
19034
|
-
})).then((e => (this.
|
|
19035
|
-
return this.
|
|
19056
|
+
})).then((e => (this.ec = !1, e))))));
|
|
19057
|
+
return this.sc = t, t;
|
|
19036
19058
|
}
|
|
19037
19059
|
enqueueAfterDelay(e, t, n) {
|
|
19038
|
-
this.
|
|
19060
|
+
this.oc(),
|
|
19039
19061
|
// Fast-forward delays for timerIds that have been overridden.
|
|
19040
|
-
this.
|
|
19041
|
-
const r = DelayedOperation.createAndSchedule(this, e, t, n, (e => this.
|
|
19042
|
-
return this.
|
|
19062
|
+
this.nc.indexOf(e) > -1 && (t = 0);
|
|
19063
|
+
const r = DelayedOperation.createAndSchedule(this, e, t, n, (e => this.uc(e)));
|
|
19064
|
+
return this.Zu.push(r), r;
|
|
19043
19065
|
}
|
|
19044
|
-
|
|
19045
|
-
this.
|
|
19046
|
-
|
|
19066
|
+
oc() {
|
|
19067
|
+
this.Xu && fail(47125, {
|
|
19068
|
+
cc: __PRIVATE_getMessageOrStack(this.Xu)
|
|
19047
19069
|
});
|
|
19048
19070
|
}
|
|
19049
19071
|
verifyOperationInProgress() {}
|
|
19050
19072
|
/**
|
|
19051
19073
|
* Waits until all currently queued tasks are finished executing. Delayed
|
|
19052
19074
|
* operations are not run.
|
|
19053
|
-
*/ async
|
|
19075
|
+
*/ async lc() {
|
|
19054
19076
|
// Operations in the queue prior to draining may have enqueued additional
|
|
19055
19077
|
// operations. Keep draining the queue until the tail is no longer advanced,
|
|
19056
19078
|
// which indicates that no more new operations were enqueued and that all
|
|
19057
19079
|
// operations were executed.
|
|
19058
19080
|
let e;
|
|
19059
19081
|
do {
|
|
19060
|
-
e = this.
|
|
19061
|
-
} while (e !== this.
|
|
19082
|
+
e = this.sc, await e;
|
|
19083
|
+
} while (e !== this.sc);
|
|
19062
19084
|
}
|
|
19063
19085
|
/**
|
|
19064
19086
|
* For Tests: Determine if a delayed operation with a particular TimerId
|
|
19065
19087
|
* exists.
|
|
19066
|
-
*/
|
|
19067
|
-
for (const t of this.
|
|
19088
|
+
*/ hc(e) {
|
|
19089
|
+
for (const t of this.Zu) if (t.timerId === e) return !0;
|
|
19068
19090
|
return !1;
|
|
19069
19091
|
}
|
|
19070
19092
|
/**
|
|
@@ -19073,25 +19095,25 @@ class __PRIVATE_AsyncQueueImpl {
|
|
|
19073
19095
|
* @param lastTimerId - Delayed operations up to and including this TimerId
|
|
19074
19096
|
* will be drained. Pass TimerId.All to run all delayed operations.
|
|
19075
19097
|
* @returns a Promise that resolves once all operations have been run.
|
|
19076
|
-
*/
|
|
19098
|
+
*/ Pc(e) {
|
|
19077
19099
|
// Note that draining may generate more delayed ops, so we do that first.
|
|
19078
|
-
return this.
|
|
19100
|
+
return this.lc().then((() => {
|
|
19079
19101
|
// Run ops in the same order they'd run if they ran naturally.
|
|
19080
19102
|
/* eslint-disable-next-line @typescript-eslint/no-floating-promises */
|
|
19081
|
-
this.
|
|
19082
|
-
for (const t of this.
|
|
19083
|
-
return this.
|
|
19103
|
+
this.Zu.sort(((e, t) => e.targetTimeMs - t.targetTimeMs));
|
|
19104
|
+
for (const t of this.Zu) if (t.skipDelay(), "all" /* TimerId.All */ !== e && t.timerId === e) break;
|
|
19105
|
+
return this.lc();
|
|
19084
19106
|
}));
|
|
19085
19107
|
}
|
|
19086
19108
|
/**
|
|
19087
19109
|
* For Tests: Skip all subsequent delays for a timer id.
|
|
19088
|
-
*/
|
|
19089
|
-
this.
|
|
19110
|
+
*/ Tc(e) {
|
|
19111
|
+
this.nc.push(e);
|
|
19090
19112
|
}
|
|
19091
|
-
/** Called once a DelayedOperation is run or canceled. */
|
|
19113
|
+
/** Called once a DelayedOperation is run or canceled. */ uc(e) {
|
|
19092
19114
|
// NOTE: indexOf / slice are O(n), but delayedOperations is expected to be small.
|
|
19093
|
-
const t = this.
|
|
19094
|
-
/* eslint-disable-next-line @typescript-eslint/no-floating-promises */ this.
|
|
19115
|
+
const t = this.Zu.indexOf(e);
|
|
19116
|
+
/* eslint-disable-next-line @typescript-eslint/no-floating-promises */ this.Zu.splice(t, 1);
|
|
19095
19117
|
}
|
|
19096
19118
|
}
|
|
19097
19119
|
|
|
@@ -19942,7 +19964,7 @@ function __PRIVATE_isWrite(e) {
|
|
|
19942
19964
|
|
|
19943
19965
|
default:
|
|
19944
19966
|
throw fail(40011, {
|
|
19945
|
-
|
|
19967
|
+
Ic: e
|
|
19946
19968
|
});
|
|
19947
19969
|
}
|
|
19948
19970
|
}
|
|
@@ -19970,55 +19992,55 @@ function __PRIVATE_isWrite(e) {
|
|
|
19970
19992
|
this.settings = e, this.databaseId = t, this.serializer = n, this.ignoreUndefinedProperties = r,
|
|
19971
19993
|
// Minor hack: If fieldTransforms is undefined, we assume this is an
|
|
19972
19994
|
// external call and we need to validate the entire path.
|
|
19973
|
-
void 0 === i && this.
|
|
19995
|
+
void 0 === i && this.Ec(), this.fieldTransforms = i || [], this.fieldMask = s || [];
|
|
19974
19996
|
}
|
|
19975
19997
|
get path() {
|
|
19976
19998
|
return this.settings.path;
|
|
19977
19999
|
}
|
|
19978
|
-
get
|
|
19979
|
-
return this.settings.
|
|
20000
|
+
get Ic() {
|
|
20001
|
+
return this.settings.Ic;
|
|
19980
20002
|
}
|
|
19981
|
-
/** Returns a new context with the specified settings overwritten. */
|
|
20003
|
+
/** Returns a new context with the specified settings overwritten. */ dc(e) {
|
|
19982
20004
|
return new __PRIVATE_ParseContextImpl(Object.assign(Object.assign({}, this.settings), e), this.databaseId, this.serializer, this.ignoreUndefinedProperties, this.fieldTransforms, this.fieldMask);
|
|
19983
20005
|
}
|
|
19984
|
-
|
|
20006
|
+
Ac(e) {
|
|
19985
20007
|
var t;
|
|
19986
|
-
const n = null === (t = this.path) || void 0 === t ? void 0 : t.child(e), r = this.
|
|
20008
|
+
const n = null === (t = this.path) || void 0 === t ? void 0 : t.child(e), r = this.dc({
|
|
19987
20009
|
path: n,
|
|
19988
|
-
|
|
20010
|
+
Rc: !1
|
|
19989
20011
|
});
|
|
19990
|
-
return r.
|
|
20012
|
+
return r.Vc(e), r;
|
|
19991
20013
|
}
|
|
19992
|
-
|
|
20014
|
+
mc(e) {
|
|
19993
20015
|
var t;
|
|
19994
|
-
const n = null === (t = this.path) || void 0 === t ? void 0 : t.child(e), r = this.
|
|
20016
|
+
const n = null === (t = this.path) || void 0 === t ? void 0 : t.child(e), r = this.dc({
|
|
19995
20017
|
path: n,
|
|
19996
|
-
|
|
20018
|
+
Rc: !1
|
|
19997
20019
|
});
|
|
19998
|
-
return r.
|
|
20020
|
+
return r.Ec(), r;
|
|
19999
20021
|
}
|
|
20000
|
-
|
|
20022
|
+
fc(e) {
|
|
20001
20023
|
// TODO(b/34871131): We don't support array paths right now; so make path
|
|
20002
20024
|
// undefined.
|
|
20003
|
-
return this.
|
|
20025
|
+
return this.dc({
|
|
20004
20026
|
path: void 0,
|
|
20005
|
-
|
|
20027
|
+
Rc: !0
|
|
20006
20028
|
});
|
|
20007
20029
|
}
|
|
20008
|
-
|
|
20009
|
-
return __PRIVATE_createError(e, this.settings.methodName, this.settings.
|
|
20030
|
+
gc(e) {
|
|
20031
|
+
return __PRIVATE_createError(e, this.settings.methodName, this.settings.yc || !1, this.path, this.settings.wc);
|
|
20010
20032
|
}
|
|
20011
20033
|
/** Returns 'true' if 'fieldPath' was traversed when creating this context. */ contains(e) {
|
|
20012
20034
|
return void 0 !== this.fieldMask.find((t => e.isPrefixOf(t))) || void 0 !== this.fieldTransforms.find((t => e.isPrefixOf(t.field)));
|
|
20013
20035
|
}
|
|
20014
|
-
|
|
20036
|
+
Ec() {
|
|
20015
20037
|
// TODO(b/34871131): Remove null check once we have proper paths for fields
|
|
20016
20038
|
// within arrays.
|
|
20017
|
-
if (this.path) for (let e = 0; e < this.path.length; e++) this.
|
|
20039
|
+
if (this.path) for (let e = 0; e < this.path.length; e++) this.Vc(this.path.get(e));
|
|
20018
20040
|
}
|
|
20019
|
-
|
|
20020
|
-
if (0 === e.length) throw this.
|
|
20021
|
-
if (__PRIVATE_isWrite(this.
|
|
20041
|
+
Vc(e) {
|
|
20042
|
+
if (0 === e.length) throw this.gc("Document fields must not be empty");
|
|
20043
|
+
if (__PRIVATE_isWrite(this.Ic) && cn.test(e)) throw this.gc('Document fields cannot begin and end with "__"');
|
|
20022
20044
|
}
|
|
20023
20045
|
}
|
|
20024
20046
|
|
|
@@ -20029,14 +20051,14 @@ function __PRIVATE_isWrite(e) {
|
|
|
20029
20051
|
constructor(e, t, n) {
|
|
20030
20052
|
this.databaseId = e, this.ignoreUndefinedProperties = t, this.serializer = n || __PRIVATE_newSerializer(e);
|
|
20031
20053
|
}
|
|
20032
|
-
/** Creates a new top-level parse context. */
|
|
20054
|
+
/** Creates a new top-level parse context. */ bc(e, t, n, r = !1) {
|
|
20033
20055
|
return new __PRIVATE_ParseContextImpl({
|
|
20034
|
-
|
|
20056
|
+
Ic: e,
|
|
20035
20057
|
methodName: t,
|
|
20036
|
-
|
|
20058
|
+
wc: n,
|
|
20037
20059
|
path: FieldPath$1.emptyPath(),
|
|
20038
|
-
|
|
20039
|
-
|
|
20060
|
+
Rc: !1,
|
|
20061
|
+
yc: r
|
|
20040
20062
|
}, this.databaseId, this.serializer, this.ignoreUndefinedProperties);
|
|
20041
20063
|
}
|
|
20042
20064
|
}
|
|
@@ -20047,7 +20069,7 @@ function __PRIVATE_newUserDataReader(e) {
|
|
|
20047
20069
|
}
|
|
20048
20070
|
|
|
20049
20071
|
/** Parse document data from a set() call. */ function __PRIVATE_parseSetData(e, t, n, r, i, s = {}) {
|
|
20050
|
-
const o = e.
|
|
20072
|
+
const o = e.bc(s.merge || s.mergeFields ? 2 /* UserDataSource.MergeSet */ : 0 /* UserDataSource.Set */ , t, n, i);
|
|
20051
20073
|
__PRIVATE_validatePlainObject("Data must be an object, but it was:", o, r);
|
|
20052
20074
|
const _ = __PRIVATE_parseObject(r, o);
|
|
20053
20075
|
let a, u;
|
|
@@ -20065,7 +20087,7 @@ function __PRIVATE_newUserDataReader(e) {
|
|
|
20065
20087
|
|
|
20066
20088
|
class __PRIVATE_DeleteFieldValueImpl extends FieldValue {
|
|
20067
20089
|
_toFieldTransform(e) {
|
|
20068
|
-
if (2 /* UserDataSource.MergeSet */ !== e.
|
|
20090
|
+
if (2 /* UserDataSource.MergeSet */ !== e.Ic) throw 1 /* UserDataSource.Update */ === e.Ic ? e.gc(`${this._methodName}() can only appear at the top level of your update data`) : e.gc(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);
|
|
20069
20091
|
// No transform to add for a delete, but we need to add it to our
|
|
20070
20092
|
// fieldMask so it gets deleted.
|
|
20071
20093
|
return e.fieldMask.push(e.path), null;
|
|
@@ -20092,10 +20114,10 @@ class __PRIVATE_DeleteFieldValueImpl extends FieldValue {
|
|
|
20092
20114
|
* @param arrayElement - Whether or not the FieldValue has an array.
|
|
20093
20115
|
*/ function __PRIVATE_createSentinelChildContext(e, t, n) {
|
|
20094
20116
|
return new __PRIVATE_ParseContextImpl({
|
|
20095
|
-
|
|
20096
|
-
|
|
20117
|
+
Ic: 3 /* UserDataSource.Argument */ ,
|
|
20118
|
+
wc: t.settings.wc,
|
|
20097
20119
|
methodName: e._methodName,
|
|
20098
|
-
|
|
20120
|
+
Rc: n
|
|
20099
20121
|
}, t.databaseId, t.serializer, t.ignoreUndefinedProperties);
|
|
20100
20122
|
}
|
|
20101
20123
|
|
|
@@ -20110,47 +20132,47 @@ class __PRIVATE_ServerTimestampFieldValueImpl extends FieldValue {
|
|
|
20110
20132
|
|
|
20111
20133
|
class __PRIVATE_ArrayUnionFieldValueImpl extends FieldValue {
|
|
20112
20134
|
constructor(e, t) {
|
|
20113
|
-
super(e), this.
|
|
20135
|
+
super(e), this.Sc = t;
|
|
20114
20136
|
}
|
|
20115
20137
|
_toFieldTransform(e) {
|
|
20116
20138
|
const t = __PRIVATE_createSentinelChildContext(this, e,
|
|
20117
|
-
/*array=*/ !0), n = this.
|
|
20139
|
+
/*array=*/ !0), n = this.Sc.map((e => __PRIVATE_parseData(e, t))), r = new __PRIVATE_ArrayUnionTransformOperation(n);
|
|
20118
20140
|
return new FieldTransform(e.path, r);
|
|
20119
20141
|
}
|
|
20120
20142
|
isEqual(e) {
|
|
20121
|
-
return e instanceof __PRIVATE_ArrayUnionFieldValueImpl && deepEqual(this.
|
|
20143
|
+
return e instanceof __PRIVATE_ArrayUnionFieldValueImpl && deepEqual(this.Sc, e.Sc);
|
|
20122
20144
|
}
|
|
20123
20145
|
}
|
|
20124
20146
|
|
|
20125
20147
|
class __PRIVATE_ArrayRemoveFieldValueImpl extends FieldValue {
|
|
20126
20148
|
constructor(e, t) {
|
|
20127
|
-
super(e), this.
|
|
20149
|
+
super(e), this.Sc = t;
|
|
20128
20150
|
}
|
|
20129
20151
|
_toFieldTransform(e) {
|
|
20130
20152
|
const t = __PRIVATE_createSentinelChildContext(this, e,
|
|
20131
|
-
/*array=*/ !0), n = this.
|
|
20153
|
+
/*array=*/ !0), n = this.Sc.map((e => __PRIVATE_parseData(e, t))), r = new __PRIVATE_ArrayRemoveTransformOperation(n);
|
|
20132
20154
|
return new FieldTransform(e.path, r);
|
|
20133
20155
|
}
|
|
20134
20156
|
isEqual(e) {
|
|
20135
|
-
return e instanceof __PRIVATE_ArrayRemoveFieldValueImpl && deepEqual(this.
|
|
20157
|
+
return e instanceof __PRIVATE_ArrayRemoveFieldValueImpl && deepEqual(this.Sc, e.Sc);
|
|
20136
20158
|
}
|
|
20137
20159
|
}
|
|
20138
20160
|
|
|
20139
20161
|
class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
20140
20162
|
constructor(e, t) {
|
|
20141
|
-
super(e), this.
|
|
20163
|
+
super(e), this.Dc = t;
|
|
20142
20164
|
}
|
|
20143
20165
|
_toFieldTransform(e) {
|
|
20144
|
-
const t = new __PRIVATE_NumericIncrementTransformOperation(e.serializer, toNumber(e.serializer, this.
|
|
20166
|
+
const t = new __PRIVATE_NumericIncrementTransformOperation(e.serializer, toNumber(e.serializer, this.Dc));
|
|
20145
20167
|
return new FieldTransform(e.path, t);
|
|
20146
20168
|
}
|
|
20147
20169
|
isEqual(e) {
|
|
20148
|
-
return e instanceof __PRIVATE_NumericIncrementFieldValueImpl && this.
|
|
20170
|
+
return e instanceof __PRIVATE_NumericIncrementFieldValueImpl && this.Dc === e.Dc;
|
|
20149
20171
|
}
|
|
20150
20172
|
}
|
|
20151
20173
|
|
|
20152
20174
|
/** Parse update data from an update() call. */ function __PRIVATE_parseUpdateData(e, t, n, r) {
|
|
20153
|
-
const i = e.
|
|
20175
|
+
const i = e.bc(1 /* UserDataSource.Update */ , t, n);
|
|
20154
20176
|
__PRIVATE_validatePlainObject("Data must be an object, but it was:", i, r);
|
|
20155
20177
|
const s = [], o = ObjectValue.empty();
|
|
20156
20178
|
forEach(r, ((e, r) => {
|
|
@@ -20158,7 +20180,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20158
20180
|
// For Compat types, we have to "extract" the underlying types before
|
|
20159
20181
|
// performing validation.
|
|
20160
20182
|
r = getModularInstance(r);
|
|
20161
|
-
const a = i.
|
|
20183
|
+
const a = i.mc(_);
|
|
20162
20184
|
if (r instanceof __PRIVATE_DeleteFieldValueImpl)
|
|
20163
20185
|
// Add it to the field mask, but don't add anything to updateData.
|
|
20164
20186
|
s.push(_); else {
|
|
@@ -20171,7 +20193,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20171
20193
|
}
|
|
20172
20194
|
|
|
20173
20195
|
/** Parse update data from a list of field/value arguments. */ function __PRIVATE_parseUpdateVarargs(e, t, n, r, i, s) {
|
|
20174
|
-
const o = e.
|
|
20196
|
+
const o = e.bc(1 /* UserDataSource.Update */ , t, n), _ = [ __PRIVATE_fieldPathFromArgument$1(t, r, n) ], a = [ i ];
|
|
20175
20197
|
if (s.length % 2 != 0) throw new FirestoreError(N.INVALID_ARGUMENT, `Function ${t}() needs to be called with an even number of arguments that alternate between field names and values.`);
|
|
20176
20198
|
for (let e = 0; e < s.length; e += 2) _.push(__PRIVATE_fieldPathFromArgument$1(t, s[e])),
|
|
20177
20199
|
a.push(s[e + 1]);
|
|
@@ -20184,7 +20206,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20184
20206
|
// For Compat types, we have to "extract" the underlying types before
|
|
20185
20207
|
// performing validation.
|
|
20186
20208
|
n = getModularInstance(n);
|
|
20187
|
-
const r = o.
|
|
20209
|
+
const r = o.mc(t);
|
|
20188
20210
|
if (n instanceof __PRIVATE_DeleteFieldValueImpl)
|
|
20189
20211
|
// Add it to the field mask, but don't add anything to updateData.
|
|
20190
20212
|
u.push(t); else {
|
|
@@ -20203,7 +20225,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20203
20225
|
* @param allowArrays - Whether the query value is an array that may directly
|
|
20204
20226
|
* contain additional arrays (e.g. the operand of an `in` query).
|
|
20205
20227
|
*/ function __PRIVATE_parseQueryValue(e, t, n, r = !1) {
|
|
20206
|
-
return __PRIVATE_parseData(n, e.
|
|
20228
|
+
return __PRIVATE_parseData(n, e.bc(r ? 4 /* UserDataSource.ArrayArgument */ : 3 /* UserDataSource.Argument */ , t));
|
|
20207
20229
|
}
|
|
20208
20230
|
|
|
20209
20231
|
/**
|
|
@@ -20232,8 +20254,8 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20232
20254
|
*/
|
|
20233
20255
|
return function __PRIVATE_parseSentinelFieldValue(e, t) {
|
|
20234
20256
|
// Sentinels are only supported with writes, and not within arrays.
|
|
20235
|
-
if (!__PRIVATE_isWrite(t.
|
|
20236
|
-
if (!t.path) throw t.
|
|
20257
|
+
if (!__PRIVATE_isWrite(t.Ic)) throw t.gc(`${e._methodName}() can only be used with update() and set()`);
|
|
20258
|
+
if (!t.path) throw t.gc(`${e._methodName}() is not currently supported inside arrays`);
|
|
20237
20259
|
const n = e._toFieldTransform(t);
|
|
20238
20260
|
n && t.fieldTransforms.push(n);
|
|
20239
20261
|
}
|
|
@@ -20257,12 +20279,12 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20257
20279
|
// the set of values to be included for the IN query) that may directly
|
|
20258
20280
|
// contain additional arrays (each representing an individual field
|
|
20259
20281
|
// value), so we disable this validation.
|
|
20260
|
-
if (t.settings.
|
|
20282
|
+
if (t.settings.Rc && 4 /* UserDataSource.ArrayArgument */ !== t.Ic) throw t.gc("Nested arrays are not supported");
|
|
20261
20283
|
return function __PRIVATE_parseArray(e, t) {
|
|
20262
20284
|
const n = [];
|
|
20263
20285
|
let r = 0;
|
|
20264
20286
|
for (const i of e) {
|
|
20265
|
-
let e = __PRIVATE_parseData(i, t.
|
|
20287
|
+
let e = __PRIVATE_parseData(i, t.fc(r));
|
|
20266
20288
|
null == e && (
|
|
20267
20289
|
// Just include nulls in the array for fields being replaced with a
|
|
20268
20290
|
// sentinel.
|
|
@@ -20314,7 +20336,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20314
20336
|
};
|
|
20315
20337
|
if (e instanceof DocumentReference) {
|
|
20316
20338
|
const n = t.databaseId, r = e.firestore._databaseId;
|
|
20317
|
-
if (!r.isEqual(n)) throw t.
|
|
20339
|
+
if (!r.isEqual(n)) throw t.gc(`Document reference is for database ${r.projectId}/${r.database} but should be for database ${n.projectId}/${n.database}`);
|
|
20318
20340
|
return {
|
|
20319
20341
|
referenceValue: __PRIVATE_toResourceName(e.firestore._databaseId || t.databaseId, e._key.path)
|
|
20320
20342
|
};
|
|
@@ -20332,7 +20354,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20332
20354
|
[Tt]: {
|
|
20333
20355
|
arrayValue: {
|
|
20334
20356
|
values: e.toArray().map((e => {
|
|
20335
|
-
if ("number" != typeof e) throw t.
|
|
20357
|
+
if ("number" != typeof e) throw t.gc("VectorValues must only contain numeric values.");
|
|
20336
20358
|
return __PRIVATE_toDouble(t.serializer, e);
|
|
20337
20359
|
}))
|
|
20338
20360
|
}
|
|
@@ -20350,7 +20372,7 @@ class __PRIVATE_NumericIncrementFieldValueImpl extends FieldValue {
|
|
|
20350
20372
|
* GeoPoints, etc. are not considered to look like JSON objects since they map
|
|
20351
20373
|
* to specific FieldValue types other than ObjectValue.
|
|
20352
20374
|
*/ (e, t);
|
|
20353
|
-
throw t.
|
|
20375
|
+
throw t.gc(`Unsupported field value: ${__PRIVATE_valueDescription(e)}`);
|
|
20354
20376
|
}(e, t);
|
|
20355
20377
|
}
|
|
20356
20378
|
|
|
@@ -20360,7 +20382,7 @@ function __PRIVATE_parseObject(e, t) {
|
|
|
20360
20382
|
// If we encounter an empty object, we explicitly add it to the update
|
|
20361
20383
|
// mask to ensure that the server creates a map entry.
|
|
20362
20384
|
t.path && t.path.length > 0 && t.fieldMask.push(t.path) : forEach(e, ((e, r) => {
|
|
20363
|
-
const i = __PRIVATE_parseData(r, t.
|
|
20385
|
+
const i = __PRIVATE_parseData(r, t.Ac(e));
|
|
20364
20386
|
null != i && (n[e] = i);
|
|
20365
20387
|
})), {
|
|
20366
20388
|
mapValue: {
|
|
@@ -20378,7 +20400,7 @@ function __PRIVATE_validatePlainObject(e, t, n) {
|
|
|
20378
20400
|
return "object" == typeof e && null !== e && (Object.getPrototypeOf(e) === Object.prototype || null === Object.getPrototypeOf(e));
|
|
20379
20401
|
}(n)) {
|
|
20380
20402
|
const r = __PRIVATE_valueDescription(n);
|
|
20381
|
-
throw "an object" === r ? t.
|
|
20403
|
+
throw "an object" === r ? t.gc(e + " a custom object") : t.gc(e + " " + r);
|
|
20382
20404
|
}
|
|
20383
20405
|
}
|
|
20384
20406
|
|
|
@@ -21683,7 +21705,7 @@ function onSnapshot(e, ...t) {
|
|
|
21683
21705
|
const i = new __PRIVATE_AsyncObserver(r), s = new __PRIVATE_QueryListener(t, i, n);
|
|
21684
21706
|
return e.asyncQueue.enqueueAndForget((async () => __PRIVATE_eventManagerListen(await __PRIVATE_getEventManager(e), s))),
|
|
21685
21707
|
() => {
|
|
21686
|
-
i.
|
|
21708
|
+
i.xu(), e.asyncQueue.enqueueAndForget((async () => __PRIVATE_eventManagerUnlisten(await __PRIVATE_getEventManager(e), s)));
|
|
21687
21709
|
};
|
|
21688
21710
|
}(ensureFirestoreConfigured(u), c, _, a);
|
|
21689
21711
|
}
|
|
@@ -22192,7 +22214,7 @@ function __PRIVATE_validateReference(e, t) {
|
|
|
22192
22214
|
const r = new __PRIVATE_Deferred;
|
|
22193
22215
|
return e.asyncQueue.enqueueAndForget((async () => {
|
|
22194
22216
|
const i = await __PRIVATE_getDatastore(e);
|
|
22195
|
-
new __PRIVATE_TransactionRunner(e.asyncQueue, i, n, t, r)
|
|
22217
|
+
new __PRIVATE_TransactionRunner(e.asyncQueue, i, n, t, r).Wu();
|
|
22196
22218
|
})), r.promise;
|
|
22197
22219
|
}(ensureFirestoreConfigured(e), (n => t(new Transaction(e, n))), r);
|
|
22198
22220
|
}
|
|
@@ -22559,7 +22581,7 @@ function _internalQueryToProtoQueryTarget(e) {
|
|
|
22559
22581
|
* The implementation of `TestingHooksSpi`.
|
|
22560
22582
|
*/ class __PRIVATE_TestingHooksSpiImpl {
|
|
22561
22583
|
constructor() {
|
|
22562
|
-
this.
|
|
22584
|
+
this.vc = new Map;
|
|
22563
22585
|
}
|
|
22564
22586
|
static get instance() {
|
|
22565
22587
|
return Tn || (Tn = new __PRIVATE_TestingHooksSpiImpl, function __PRIVATE_setTestingHooksSpi(e) {
|
|
@@ -22568,10 +22590,10 @@ function _internalQueryToProtoQueryTarget(e) {
|
|
|
22568
22590
|
}(Tn)), Tn;
|
|
22569
22591
|
}
|
|
22570
22592
|
ht(e) {
|
|
22571
|
-
this.
|
|
22593
|
+
this.vc.forEach((t => t(e)));
|
|
22572
22594
|
}
|
|
22573
22595
|
onExistenceFilterMismatch(e) {
|
|
22574
|
-
const t = Symbol(), n = this.
|
|
22596
|
+
const t = Symbol(), n = this.vc;
|
|
22575
22597
|
return n.set(t, e), () => n.delete(t);
|
|
22576
22598
|
}
|
|
22577
22599
|
}
|