@fleox-agent-crm/agentcrm 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/changelog.json +13 -0
- package/dist/admin/admin-files.json +7 -7
- package/dist/admin/assets/{chartsImpl-aBuZ1X4W.js → chartsImpl-zjsXDhuy.js} +1 -1
- package/dist/admin/assets/firebase-C3h9mF8O.js +2 -0
- package/dist/admin/assets/{gitJson-DzX3eZ2P.js → gitJson-nrOYgX0x.js} +1 -1
- package/dist/admin/assets/{index-DLy5RpPl.js → index-0ejjkW0z.js} +6 -6
- package/dist/admin/assets/{lucide-react.min-BgcmukkH.js → lucide-react.min-CI5dCsSm.js} +1 -1
- package/dist/admin/assets/{sdk-DtP9zqdi.js → sdk-mepKXtVl.js} +135 -120
- package/dist/admin/index.html +1 -1
- package/dist/agent/agentcrm.mjs +29 -16
- package/dist/agent/chunks/api-BEl_EKwf.mjs +79 -0
- package/dist/agent/chunks/{firebase-DWR0K1OC.mjs → firebase-Bknru2pE.mjs} +230 -53
- package/dist/agent/chunks/firebaseCache-sK4jA0ru.mjs +39 -0
- package/dist/agent/chunks/{firebaseRules-iori-s7U.mjs → firebaseRules-Jq85MBBN.mjs} +14 -3
- package/dist/agent/chunks/{hosting-Dnn1k3cV.mjs → hosting-C_UDyMkm.mjs} +1 -1
- package/dist/agent/chunks/{index-DtCezG4R.mjs → index-DWecFbTi.mjs} +1 -1
- package/dist/agent/chunks/{install-Bp-CwDVC.mjs → install-BLNflFes.mjs} +3 -3
- package/dist/agent/chunks/{sdk-CYgNyuoK.mjs → sdk-NYUHv7WG.mjs} +493 -214
- package/dist/version.json +1 -1
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/skills/agentcrm-admin/SKILL.md +67 -67
- package/plugin/skills/agentcrm-admin/references/records.md +5 -5
- package/plugin/skills/agentcrm-admin/references/schema.md +19 -19
- package/plugin/skills/agentcrm-extensions/SKILL.md +8 -8
- package/plugin/skills/agentcrm-extensions/references/module-recipes.md +2 -2
- package/plugin/skills/agentcrm-extensions/references/testing.md +14 -14
- package/plugin/skills/agentcrm-extensions/references/theme-recipes.md +3 -3
- package/plugin/skills/agentcrm-install/SKILL.md +13 -13
- package/plugin/skills/agentcrm-install/references/firebase.md +1 -1
- package/plugin/skills/agentcrm-install/references/github.md +1 -1
- package/plugin/skills/agentcrm-install/references/mcp.md +2 -2
- package/plugin/skills/agentcrm-install/references/plans.md +1 -1
- package/plugin/skills/agentcrm-install/references/s3.md +1 -1
- package/plugin/skills/agentcrm-manage/SKILL.md +15 -15
- package/plugin/skills/agentcrm-sales/SKILL.md +18 -18
- package/dist/admin/assets/firebase-BG1GpyBB.js +0 -2
- package/dist/agent/chunks/api-Dwb4xz1k.mjs +0 -27
|
@@ -21,7 +21,7 @@ import require$$3$1 from "http";
|
|
|
21
21
|
import require$$7 from "url";
|
|
22
22
|
import require$$1$3 from "dns";
|
|
23
23
|
import require$$0$7 from "zlib";
|
|
24
|
-
import { D as DELETE_FIELD } from "./api-
|
|
24
|
+
import { w as withChangeTracking, D as DELETE_FIELD, S as SERVER_TIMESTAMP, T as TS_FIELD, d as splitTs } from "./api-BEl_EKwf.mjs";
|
|
25
25
|
var name$2 = "firebase";
|
|
26
26
|
var version$3 = "11.10.0";
|
|
27
27
|
/**
|
|
@@ -21713,6 +21713,11 @@ function estimateMapByteSize(mapValue) {
|
|
|
21713
21713
|
function estimateArrayByteSize(arrayValue) {
|
|
21714
21714
|
return (arrayValue.values || []).reduce((previousSize, value) => previousSize + estimateByteSize(value), 0);
|
|
21715
21715
|
}
|
|
21716
|
+
function refValue(databaseId, key) {
|
|
21717
|
+
return {
|
|
21718
|
+
referenceValue: `projects/${databaseId.projectId}/databases/${databaseId.database}/documents/${key.path.canonicalString()}`
|
|
21719
|
+
};
|
|
21720
|
+
}
|
|
21716
21721
|
function isInteger(value) {
|
|
21717
21722
|
return !!value && "integerValue" in value;
|
|
21718
21723
|
}
|
|
@@ -22624,25 +22629,25 @@ function newQuery(path2, collectionGroup, explicitOrderBy, filters, limit, limit
|
|
|
22624
22629
|
function newQueryForPath(path2) {
|
|
22625
22630
|
return new QueryImpl(path2);
|
|
22626
22631
|
}
|
|
22627
|
-
function asCollectionQueryAtPath(
|
|
22632
|
+
function asCollectionQueryAtPath(query2, path2) {
|
|
22628
22633
|
return new QueryImpl(
|
|
22629
22634
|
path2,
|
|
22630
22635
|
/*collectionGroup=*/
|
|
22631
22636
|
null,
|
|
22632
|
-
|
|
22633
|
-
|
|
22634
|
-
|
|
22635
|
-
|
|
22636
|
-
|
|
22637
|
-
|
|
22637
|
+
query2.explicitOrderBy.slice(),
|
|
22638
|
+
query2.filters.slice(),
|
|
22639
|
+
query2.limit,
|
|
22640
|
+
query2.limitType,
|
|
22641
|
+
query2.startAt,
|
|
22642
|
+
query2.endAt
|
|
22638
22643
|
);
|
|
22639
22644
|
}
|
|
22640
|
-
function queryMatchesAllDocuments(
|
|
22641
|
-
return
|
|
22645
|
+
function queryMatchesAllDocuments(query2) {
|
|
22646
|
+
return query2.filters.length === 0 && query2.limit === null && query2.startAt == null && query2.endAt == null && (query2.explicitOrderBy.length === 0 || query2.explicitOrderBy.length === 1 && query2.explicitOrderBy[0].field.isKeyField());
|
|
22642
22647
|
}
|
|
22643
|
-
function getInequalityFilterFields(
|
|
22648
|
+
function getInequalityFilterFields(query2) {
|
|
22644
22649
|
let result = new SortedSet(FieldPath$1.comparator);
|
|
22645
|
-
|
|
22650
|
+
query2.filters.forEach((filter2) => {
|
|
22646
22651
|
const subFilters = filter2.getFlattenedFilters();
|
|
22647
22652
|
subFilters.forEach((filter3) => {
|
|
22648
22653
|
if (filter3.isInequality()) {
|
|
@@ -22652,14 +22657,14 @@ function getInequalityFilterFields(query) {
|
|
|
22652
22657
|
});
|
|
22653
22658
|
return result;
|
|
22654
22659
|
}
|
|
22655
|
-
function isDocumentQuery$1(
|
|
22656
|
-
return DocumentKey.isDocumentKey(
|
|
22660
|
+
function isDocumentQuery$1(query2) {
|
|
22661
|
+
return DocumentKey.isDocumentKey(query2.path) && query2.collectionGroup === null && query2.filters.length === 0;
|
|
22657
22662
|
}
|
|
22658
|
-
function isCollectionGroupQuery(
|
|
22659
|
-
return
|
|
22663
|
+
function isCollectionGroupQuery(query2) {
|
|
22664
|
+
return query2.collectionGroup !== null;
|
|
22660
22665
|
}
|
|
22661
|
-
function queryNormalizedOrderBy(
|
|
22662
|
-
const queryImpl = debugCast(
|
|
22666
|
+
function queryNormalizedOrderBy(query2) {
|
|
22667
|
+
const queryImpl = debugCast(query2);
|
|
22663
22668
|
if (queryImpl.memoizedNormalizedOrderBy === null) {
|
|
22664
22669
|
queryImpl.memoizedNormalizedOrderBy = [];
|
|
22665
22670
|
const fieldsNormalized = /* @__PURE__ */ new Set();
|
|
@@ -22680,10 +22685,10 @@ function queryNormalizedOrderBy(query) {
|
|
|
22680
22685
|
}
|
|
22681
22686
|
return queryImpl.memoizedNormalizedOrderBy;
|
|
22682
22687
|
}
|
|
22683
|
-
function queryToTarget(
|
|
22684
|
-
const queryImpl = debugCast(
|
|
22688
|
+
function queryToTarget(query2) {
|
|
22689
|
+
const queryImpl = debugCast(query2);
|
|
22685
22690
|
if (!queryImpl.memoizedTarget) {
|
|
22686
|
-
queryImpl.memoizedTarget = _queryToTarget(queryImpl, queryNormalizedOrderBy(
|
|
22691
|
+
queryImpl.memoizedTarget = _queryToTarget(queryImpl, queryNormalizedOrderBy(query2));
|
|
22687
22692
|
}
|
|
22688
22693
|
return queryImpl.memoizedTarget;
|
|
22689
22694
|
}
|
|
@@ -22700,63 +22705,67 @@ function _queryToTarget(queryImpl, orderBys) {
|
|
|
22700
22705
|
return newTarget(queryImpl.path, queryImpl.collectionGroup, orderBys, queryImpl.filters, queryImpl.limit, startAt, endAt);
|
|
22701
22706
|
}
|
|
22702
22707
|
}
|
|
22703
|
-
function
|
|
22704
|
-
|
|
22708
|
+
function queryWithAddedFilter(query2, filter2) {
|
|
22709
|
+
const newFilters = query2.filters.concat([filter2]);
|
|
22710
|
+
return new QueryImpl(query2.path, query2.collectionGroup, query2.explicitOrderBy.slice(), newFilters, query2.limit, query2.limitType, query2.startAt, query2.endAt);
|
|
22711
|
+
}
|
|
22712
|
+
function queryWithLimit(query2, limit, limitType) {
|
|
22713
|
+
return new QueryImpl(query2.path, query2.collectionGroup, query2.explicitOrderBy.slice(), query2.filters.slice(), limit, limitType, query2.startAt, query2.endAt);
|
|
22705
22714
|
}
|
|
22706
22715
|
function queryEquals(left, right) {
|
|
22707
22716
|
return targetEquals(queryToTarget(left), queryToTarget(right)) && left.limitType === right.limitType;
|
|
22708
22717
|
}
|
|
22709
|
-
function canonifyQuery(
|
|
22710
|
-
return `${canonifyTarget(queryToTarget(
|
|
22718
|
+
function canonifyQuery(query2) {
|
|
22719
|
+
return `${canonifyTarget(queryToTarget(query2))}|lt:${query2.limitType}`;
|
|
22711
22720
|
}
|
|
22712
|
-
function stringifyQuery(
|
|
22713
|
-
return `Query(target=${stringifyTarget(queryToTarget(
|
|
22721
|
+
function stringifyQuery(query2) {
|
|
22722
|
+
return `Query(target=${stringifyTarget(queryToTarget(query2))}; limitType=${query2.limitType})`;
|
|
22714
22723
|
}
|
|
22715
|
-
function queryMatches(
|
|
22716
|
-
return doc3.isFoundDocument() && queryMatchesPathAndCollectionGroup(
|
|
22724
|
+
function queryMatches(query2, doc3) {
|
|
22725
|
+
return doc3.isFoundDocument() && queryMatchesPathAndCollectionGroup(query2, doc3) && queryMatchesOrderBy(query2, doc3) && queryMatchesFilters(query2, doc3) && queryMatchesBounds(query2, doc3);
|
|
22717
22726
|
}
|
|
22718
|
-
function queryMatchesPathAndCollectionGroup(
|
|
22727
|
+
function queryMatchesPathAndCollectionGroup(query2, doc3) {
|
|
22719
22728
|
const docPath = doc3.key.path;
|
|
22720
|
-
if (
|
|
22721
|
-
return doc3.key.hasCollectionId(
|
|
22722
|
-
} else if (DocumentKey.isDocumentKey(
|
|
22723
|
-
return
|
|
22729
|
+
if (query2.collectionGroup !== null) {
|
|
22730
|
+
return doc3.key.hasCollectionId(query2.collectionGroup) && query2.path.isPrefixOf(docPath);
|
|
22731
|
+
} else if (DocumentKey.isDocumentKey(query2.path)) {
|
|
22732
|
+
return query2.path.isEqual(docPath);
|
|
22724
22733
|
} else {
|
|
22725
|
-
return
|
|
22734
|
+
return query2.path.isImmediateParentOf(docPath);
|
|
22726
22735
|
}
|
|
22727
22736
|
}
|
|
22728
|
-
function queryMatchesOrderBy(
|
|
22729
|
-
for (const orderBy of queryNormalizedOrderBy(
|
|
22737
|
+
function queryMatchesOrderBy(query2, doc3) {
|
|
22738
|
+
for (const orderBy of queryNormalizedOrderBy(query2)) {
|
|
22730
22739
|
if (!orderBy.field.isKeyField() && doc3.data.field(orderBy.field) === null) {
|
|
22731
22740
|
return false;
|
|
22732
22741
|
}
|
|
22733
22742
|
}
|
|
22734
22743
|
return true;
|
|
22735
22744
|
}
|
|
22736
|
-
function queryMatchesFilters(
|
|
22737
|
-
for (const filter2 of
|
|
22745
|
+
function queryMatchesFilters(query2, doc3) {
|
|
22746
|
+
for (const filter2 of query2.filters) {
|
|
22738
22747
|
if (!filter2.matches(doc3)) {
|
|
22739
22748
|
return false;
|
|
22740
22749
|
}
|
|
22741
22750
|
}
|
|
22742
22751
|
return true;
|
|
22743
22752
|
}
|
|
22744
|
-
function queryMatchesBounds(
|
|
22745
|
-
if (
|
|
22753
|
+
function queryMatchesBounds(query2, doc3) {
|
|
22754
|
+
if (query2.startAt && !boundSortsBeforeDocument(query2.startAt, queryNormalizedOrderBy(query2), doc3)) {
|
|
22746
22755
|
return false;
|
|
22747
22756
|
}
|
|
22748
|
-
if (
|
|
22757
|
+
if (query2.endAt && !boundSortsAfterDocument(query2.endAt, queryNormalizedOrderBy(query2), doc3)) {
|
|
22749
22758
|
return false;
|
|
22750
22759
|
}
|
|
22751
22760
|
return true;
|
|
22752
22761
|
}
|
|
22753
|
-
function queryCollectionGroup(
|
|
22754
|
-
return
|
|
22762
|
+
function queryCollectionGroup(query2) {
|
|
22763
|
+
return query2.collectionGroup || (query2.path.length % 2 === 1 ? query2.path.lastSegment() : query2.path.get(query2.path.length - 2));
|
|
22755
22764
|
}
|
|
22756
|
-
function newQueryComparator(
|
|
22765
|
+
function newQueryComparator(query2) {
|
|
22757
22766
|
return (d1, d2) => {
|
|
22758
22767
|
let comparedOnKeyField = false;
|
|
22759
|
-
for (const orderBy of queryNormalizedOrderBy(
|
|
22768
|
+
for (const orderBy of queryNormalizedOrderBy(query2)) {
|
|
22760
22769
|
const comp = compareDocs(orderBy, d1, d2);
|
|
22761
22770
|
if (comp !== 0) {
|
|
22762
22771
|
return comp;
|
|
@@ -23074,6 +23083,28 @@ function asNumber(value) {
|
|
|
23074
23083
|
function coercedFieldValuesArray(value) {
|
|
23075
23084
|
return isArray(value) && value.arrayValue.values ? value.arrayValue.values.slice() : [];
|
|
23076
23085
|
}
|
|
23086
|
+
/**
|
|
23087
|
+
* @license
|
|
23088
|
+
* Copyright 2017 Google LLC
|
|
23089
|
+
*
|
|
23090
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
23091
|
+
* you may not use this file except in compliance with the License.
|
|
23092
|
+
* You may obtain a copy of the License at
|
|
23093
|
+
*
|
|
23094
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
23095
|
+
*
|
|
23096
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
23097
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23098
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23099
|
+
* See the License for the specific language governing permissions and
|
|
23100
|
+
* limitations under the License.
|
|
23101
|
+
*/
|
|
23102
|
+
class FieldTransform {
|
|
23103
|
+
constructor(field2, transform) {
|
|
23104
|
+
this.field = field2;
|
|
23105
|
+
this.transform = transform;
|
|
23106
|
+
}
|
|
23107
|
+
}
|
|
23077
23108
|
function fieldTransformEquals(left, right) {
|
|
23078
23109
|
return left.field.isEqual(right.field) && transformOperationEquals(left.transform, right.transform);
|
|
23079
23110
|
}
|
|
@@ -24761,9 +24792,9 @@ function toQueryTarget(serializer, target) {
|
|
|
24761
24792
|
queryTarget.structuredQuery.from = [{ collectionId: path2.lastSegment() }];
|
|
24762
24793
|
}
|
|
24763
24794
|
queryTarget.parent = toQueryPath(serializer, parent);
|
|
24764
|
-
const
|
|
24765
|
-
if (
|
|
24766
|
-
queryTarget.structuredQuery.where =
|
|
24795
|
+
const where2 = toFilters(target.filters);
|
|
24796
|
+
if (where2) {
|
|
24797
|
+
queryTarget.structuredQuery.where = where2;
|
|
24767
24798
|
}
|
|
24768
24799
|
const orderBy = toOrder(target.orderBy);
|
|
24769
24800
|
if (orderBy) {
|
|
@@ -24783,12 +24814,12 @@ function toQueryTarget(serializer, target) {
|
|
|
24783
24814
|
}
|
|
24784
24815
|
function convertQueryTargetToQuery(target) {
|
|
24785
24816
|
let path2 = fromQueryPath(target.parent);
|
|
24786
|
-
const
|
|
24787
|
-
const fromCount =
|
|
24817
|
+
const query2 = target.structuredQuery;
|
|
24818
|
+
const fromCount = query2.from ? query2.from.length : 0;
|
|
24788
24819
|
let collectionGroup = null;
|
|
24789
24820
|
if (fromCount > 0) {
|
|
24790
24821
|
hardAssert(fromCount === 1, 65062);
|
|
24791
|
-
const from =
|
|
24822
|
+
const from = query2.from[0];
|
|
24792
24823
|
if (from.allDescendants) {
|
|
24793
24824
|
collectionGroup = from.collectionId;
|
|
24794
24825
|
} else {
|
|
@@ -24796,24 +24827,24 @@ function convertQueryTargetToQuery(target) {
|
|
|
24796
24827
|
}
|
|
24797
24828
|
}
|
|
24798
24829
|
let filterBy = [];
|
|
24799
|
-
if (
|
|
24800
|
-
filterBy = fromFilters(
|
|
24830
|
+
if (query2.where) {
|
|
24831
|
+
filterBy = fromFilters(query2.where);
|
|
24801
24832
|
}
|
|
24802
24833
|
let orderBy = [];
|
|
24803
|
-
if (
|
|
24804
|
-
orderBy = fromOrder(
|
|
24834
|
+
if (query2.orderBy) {
|
|
24835
|
+
orderBy = fromOrder(query2.orderBy);
|
|
24805
24836
|
}
|
|
24806
24837
|
let limit = null;
|
|
24807
|
-
if (
|
|
24808
|
-
limit = fromInt32Proto(
|
|
24838
|
+
if (query2.limit) {
|
|
24839
|
+
limit = fromInt32Proto(query2.limit);
|
|
24809
24840
|
}
|
|
24810
24841
|
let startAt = null;
|
|
24811
|
-
if (
|
|
24812
|
-
startAt = fromStartAtCursor(
|
|
24842
|
+
if (query2.startAt) {
|
|
24843
|
+
startAt = fromStartAtCursor(query2.startAt);
|
|
24813
24844
|
}
|
|
24814
24845
|
let endAt = null;
|
|
24815
|
-
if (
|
|
24816
|
-
endAt = fromEndAtCursor(
|
|
24846
|
+
if (query2.endAt) {
|
|
24847
|
+
endAt = fromEndAtCursor(query2.endAt);
|
|
24817
24848
|
}
|
|
24818
24849
|
return newQuery(path2, collectionGroup, orderBy, filterBy, limit, "F", startAt, endAt);
|
|
24819
24850
|
}
|
|
@@ -25187,19 +25218,19 @@ class LocalSerializer {
|
|
|
25187
25218
|
}
|
|
25188
25219
|
}
|
|
25189
25220
|
function fromBundledQuery(bundledQuery) {
|
|
25190
|
-
const
|
|
25221
|
+
const query2 = convertQueryTargetToQuery({
|
|
25191
25222
|
parent: bundledQuery.parent,
|
|
25192
25223
|
structuredQuery: bundledQuery.structuredQuery
|
|
25193
25224
|
});
|
|
25194
25225
|
if (bundledQuery.limitType === "LAST") {
|
|
25195
25226
|
return queryWithLimit(
|
|
25196
|
-
|
|
25197
|
-
|
|
25227
|
+
query2,
|
|
25228
|
+
query2.limit,
|
|
25198
25229
|
"L"
|
|
25199
25230
|
/* LimitType.Last */
|
|
25200
25231
|
);
|
|
25201
25232
|
}
|
|
25202
|
-
return
|
|
25233
|
+
return query2;
|
|
25203
25234
|
}
|
|
25204
25235
|
function fromProtoNamedQuery(namedQuery) {
|
|
25205
25236
|
return {
|
|
@@ -25852,13 +25883,13 @@ class LocalDocumentsView {
|
|
|
25852
25883
|
* @param context - A optional tracker to keep a record of important details
|
|
25853
25884
|
* during database local query execution.
|
|
25854
25885
|
*/
|
|
25855
|
-
getDocumentsMatchingQuery(transaction,
|
|
25856
|
-
if (isDocumentQuery$1(
|
|
25857
|
-
return this.getDocumentsMatchingDocumentQuery(transaction,
|
|
25858
|
-
} else if (isCollectionGroupQuery(
|
|
25859
|
-
return this.getDocumentsMatchingCollectionGroupQuery(transaction,
|
|
25886
|
+
getDocumentsMatchingQuery(transaction, query2, offset, context) {
|
|
25887
|
+
if (isDocumentQuery$1(query2)) {
|
|
25888
|
+
return this.getDocumentsMatchingDocumentQuery(transaction, query2.path);
|
|
25889
|
+
} else if (isCollectionGroupQuery(query2)) {
|
|
25890
|
+
return this.getDocumentsMatchingCollectionGroupQuery(transaction, query2, offset, context);
|
|
25860
25891
|
} else {
|
|
25861
|
-
return this.getDocumentsMatchingCollectionQuery(transaction,
|
|
25892
|
+
return this.getDocumentsMatchingCollectionQuery(transaction, query2, offset, context);
|
|
25862
25893
|
}
|
|
25863
25894
|
}
|
|
25864
25895
|
/**
|
|
@@ -25908,12 +25939,12 @@ class LocalDocumentsView {
|
|
|
25908
25939
|
return result;
|
|
25909
25940
|
});
|
|
25910
25941
|
}
|
|
25911
|
-
getDocumentsMatchingCollectionGroupQuery(transaction,
|
|
25912
|
-
const collectionId =
|
|
25942
|
+
getDocumentsMatchingCollectionGroupQuery(transaction, query2, offset, context) {
|
|
25943
|
+
const collectionId = query2.collectionGroup;
|
|
25913
25944
|
let results = documentMap();
|
|
25914
25945
|
return this.indexManager.getCollectionParents(transaction, collectionId).next((parents) => {
|
|
25915
25946
|
return PersistencePromise.forEach(parents, (parent) => {
|
|
25916
|
-
const collectionQuery = asCollectionQueryAtPath(
|
|
25947
|
+
const collectionQuery = asCollectionQueryAtPath(query2, parent.child(collectionId));
|
|
25917
25948
|
return this.getDocumentsMatchingCollectionQuery(transaction, collectionQuery, offset, context).next((r) => {
|
|
25918
25949
|
r.forEach((key, doc3) => {
|
|
25919
25950
|
results = results.insert(key, doc3);
|
|
@@ -25922,11 +25953,11 @@ class LocalDocumentsView {
|
|
|
25922
25953
|
}).next(() => results);
|
|
25923
25954
|
});
|
|
25924
25955
|
}
|
|
25925
|
-
getDocumentsMatchingCollectionQuery(transaction,
|
|
25956
|
+
getDocumentsMatchingCollectionQuery(transaction, query2, offset, context) {
|
|
25926
25957
|
let overlays;
|
|
25927
|
-
return this.documentOverlayCache.getOverlaysForCollection(transaction,
|
|
25958
|
+
return this.documentOverlayCache.getOverlaysForCollection(transaction, query2.path, offset.largestBatchId).next((result) => {
|
|
25928
25959
|
overlays = result;
|
|
25929
|
-
return this.remoteDocumentCache.getDocumentsMatchingQuery(transaction,
|
|
25960
|
+
return this.remoteDocumentCache.getDocumentsMatchingQuery(transaction, query2, offset, overlays, context);
|
|
25930
25961
|
}).next((remoteDocuments) => {
|
|
25931
25962
|
overlays.forEach((_, overlay) => {
|
|
25932
25963
|
const key = overlay.getKey();
|
|
@@ -25940,7 +25971,7 @@ class LocalDocumentsView {
|
|
|
25940
25971
|
if (overlay !== void 0) {
|
|
25941
25972
|
mutationApplyToLocalView(overlay.mutation, document, FieldMask.empty(), Timestamp.now());
|
|
25942
25973
|
}
|
|
25943
|
-
if (queryMatches(
|
|
25974
|
+
if (queryMatches(query2, document)) {
|
|
25944
25975
|
results = results.insert(key, document);
|
|
25945
25976
|
}
|
|
25946
25977
|
});
|
|
@@ -25980,8 +26011,8 @@ class MemoryBundleCache {
|
|
|
25980
26011
|
getNamedQuery(transaction, queryName) {
|
|
25981
26012
|
return PersistencePromise.resolve(this.namedQueries.get(queryName));
|
|
25982
26013
|
}
|
|
25983
|
-
saveNamedQuery(transaction,
|
|
25984
|
-
this.namedQueries.set(
|
|
26014
|
+
saveNamedQuery(transaction, query2) {
|
|
26015
|
+
this.namedQueries.set(query2.name, fromProtoNamedQuery(query2));
|
|
25985
26016
|
return PersistencePromise.resolve();
|
|
25986
26017
|
}
|
|
25987
26018
|
}
|
|
@@ -26302,8 +26333,8 @@ class MemoryMutationQueue {
|
|
|
26302
26333
|
});
|
|
26303
26334
|
return PersistencePromise.resolve(this.findMutationBatches(uniqueBatchIDs));
|
|
26304
26335
|
}
|
|
26305
|
-
getAllMutationBatchesAffectingQuery(transaction,
|
|
26306
|
-
const prefix =
|
|
26336
|
+
getAllMutationBatchesAffectingQuery(transaction, query2) {
|
|
26337
|
+
const prefix = query2.path;
|
|
26307
26338
|
const immediateChildrenPathLength = prefix.length + 1;
|
|
26308
26339
|
let startPath = prefix;
|
|
26309
26340
|
if (!DocumentKey.isDocumentKey(startPath)) {
|
|
@@ -26476,9 +26507,9 @@ class MemoryRemoteDocumentCacheImpl {
|
|
|
26476
26507
|
});
|
|
26477
26508
|
return PersistencePromise.resolve(results);
|
|
26478
26509
|
}
|
|
26479
|
-
getDocumentsMatchingQuery(transaction,
|
|
26510
|
+
getDocumentsMatchingQuery(transaction, query2, offset, mutatedDocs) {
|
|
26480
26511
|
let results = mutableDocumentMap();
|
|
26481
|
-
const collectionPath =
|
|
26512
|
+
const collectionPath = query2.path;
|
|
26482
26513
|
const prefix = new DocumentKey(collectionPath.child("__id" + MIN_LONG_VALUE + "__"));
|
|
26483
26514
|
const iterator = this.docs.getIteratorFrom(prefix);
|
|
26484
26515
|
while (iterator.hasNext()) {
|
|
@@ -26492,7 +26523,7 @@ class MemoryRemoteDocumentCacheImpl {
|
|
|
26492
26523
|
if (indexOffsetComparator(newIndexOffsetFromDocument(document), offset) <= 0) {
|
|
26493
26524
|
continue;
|
|
26494
26525
|
}
|
|
26495
|
-
if (!mutatedDocs.has(document.key) && !queryMatches(
|
|
26526
|
+
if (!mutatedDocs.has(document.key) && !queryMatches(query2, document)) {
|
|
26496
26527
|
continue;
|
|
26497
26528
|
}
|
|
26498
26529
|
results = results.insert(document.key, document.mutableCopy());
|
|
@@ -27281,7 +27312,7 @@ async function localStoreReleaseTarget(localStore, targetId, keepPersistedTarget
|
|
|
27281
27312
|
localStoreImpl.targetDataByTarget = localStoreImpl.targetDataByTarget.remove(targetId);
|
|
27282
27313
|
localStoreImpl.targetIdByTarget.delete(targetData.target);
|
|
27283
27314
|
}
|
|
27284
|
-
function localStoreExecuteQuery(localStore,
|
|
27315
|
+
function localStoreExecuteQuery(localStore, query2, usePreviousResults) {
|
|
27285
27316
|
const localStoreImpl = debugCast(localStore);
|
|
27286
27317
|
let lastLimboFreeSnapshotVersion = SnapshotVersion.min();
|
|
27287
27318
|
let remoteKeys = documentKeySet();
|
|
@@ -27291,15 +27322,15 @@ function localStoreExecuteQuery(localStore, query, usePreviousResults) {
|
|
|
27291
27322
|
// Use readwrite instead of readonly so indexes can be created
|
|
27292
27323
|
// Use readwrite instead of readonly so indexes can be created
|
|
27293
27324
|
(txn) => {
|
|
27294
|
-
return localStoreGetTargetData(localStoreImpl, txn, queryToTarget(
|
|
27325
|
+
return localStoreGetTargetData(localStoreImpl, txn, queryToTarget(query2)).next((targetData) => {
|
|
27295
27326
|
if (targetData) {
|
|
27296
27327
|
lastLimboFreeSnapshotVersion = targetData.lastLimboFreeSnapshotVersion;
|
|
27297
27328
|
return localStoreImpl.targetCache.getMatchingKeysForTargetId(txn, targetData.targetId).next((result) => {
|
|
27298
27329
|
remoteKeys = result;
|
|
27299
27330
|
});
|
|
27300
27331
|
}
|
|
27301
|
-
}).next(() => localStoreImpl.queryEngine.getDocumentsMatchingQuery(txn,
|
|
27302
|
-
setMaxReadTime(localStoreImpl, queryCollectionGroup(
|
|
27332
|
+
}).next(() => localStoreImpl.queryEngine.getDocumentsMatchingQuery(txn, query2, usePreviousResults ? lastLimboFreeSnapshotVersion : SnapshotVersion.min(), usePreviousResults ? remoteKeys : documentKeySet())).next((documents) => {
|
|
27333
|
+
setMaxReadTime(localStoreImpl, queryCollectionGroup(query2), documents);
|
|
27303
27334
|
return { documents, remoteKeys };
|
|
27304
27335
|
});
|
|
27305
27336
|
}
|
|
@@ -27400,15 +27431,15 @@ class QueryEngine {
|
|
|
27400
27431
|
this.initialized = true;
|
|
27401
27432
|
}
|
|
27402
27433
|
/** Returns all local documents matching the specified query. */
|
|
27403
|
-
getDocumentsMatchingQuery(transaction,
|
|
27434
|
+
getDocumentsMatchingQuery(transaction, query2, lastLimboFreeSnapshotVersion, remoteKeys) {
|
|
27404
27435
|
const queryResult = { result: null };
|
|
27405
|
-
return this.performQueryUsingIndex(transaction,
|
|
27436
|
+
return this.performQueryUsingIndex(transaction, query2).next((result) => {
|
|
27406
27437
|
queryResult.result = result;
|
|
27407
27438
|
}).next(() => {
|
|
27408
27439
|
if (queryResult.result) {
|
|
27409
27440
|
return;
|
|
27410
27441
|
}
|
|
27411
|
-
return this.performQueryUsingRemoteKeys(transaction,
|
|
27442
|
+
return this.performQueryUsingRemoteKeys(transaction, query2, remoteKeys, lastLimboFreeSnapshotVersion).next((result) => {
|
|
27412
27443
|
queryResult.result = result;
|
|
27413
27444
|
});
|
|
27414
27445
|
}).next(() => {
|
|
@@ -27416,29 +27447,29 @@ class QueryEngine {
|
|
|
27416
27447
|
return;
|
|
27417
27448
|
}
|
|
27418
27449
|
const context = new QueryContext();
|
|
27419
|
-
return this.executeFullCollectionScan(transaction,
|
|
27450
|
+
return this.executeFullCollectionScan(transaction, query2, context).next((result) => {
|
|
27420
27451
|
queryResult.result = result;
|
|
27421
27452
|
if (this.indexAutoCreationEnabled) {
|
|
27422
|
-
return this.createCacheIndexes(transaction,
|
|
27453
|
+
return this.createCacheIndexes(transaction, query2, context, result.size);
|
|
27423
27454
|
}
|
|
27424
27455
|
});
|
|
27425
27456
|
}).next(() => queryResult.result);
|
|
27426
27457
|
}
|
|
27427
|
-
createCacheIndexes(transaction,
|
|
27458
|
+
createCacheIndexes(transaction, query2, context, resultSize) {
|
|
27428
27459
|
if (context.documentReadCount < this.indexAutoCreationMinCollectionSize) {
|
|
27429
27460
|
if (getLogLevel() <= LogLevel.DEBUG) {
|
|
27430
|
-
logDebug("QueryEngine", "SDK will not create cache indexes for query:", stringifyQuery(
|
|
27461
|
+
logDebug("QueryEngine", "SDK will not create cache indexes for query:", stringifyQuery(query2), "since it only creates cache indexes for collection contains", "more than or equal to", this.indexAutoCreationMinCollectionSize, "documents");
|
|
27431
27462
|
}
|
|
27432
27463
|
return PersistencePromise.resolve();
|
|
27433
27464
|
}
|
|
27434
27465
|
if (getLogLevel() <= LogLevel.DEBUG) {
|
|
27435
|
-
logDebug("QueryEngine", "Query:", stringifyQuery(
|
|
27466
|
+
logDebug("QueryEngine", "Query:", stringifyQuery(query2), "scans", context.documentReadCount, "local documents and returns", resultSize, "documents as results.");
|
|
27436
27467
|
}
|
|
27437
27468
|
if (context.documentReadCount > this.relativeIndexReadCostPerDocument * resultSize) {
|
|
27438
27469
|
if (getLogLevel() <= LogLevel.DEBUG) {
|
|
27439
|
-
logDebug("QueryEngine", "The SDK decides to create cache indexes for query:", stringifyQuery(
|
|
27470
|
+
logDebug("QueryEngine", "The SDK decides to create cache indexes for query:", stringifyQuery(query2), "as using cache indexes may help improve performance.");
|
|
27440
27471
|
}
|
|
27441
|
-
return this.indexManager.createTargetIndexes(transaction, queryToTarget(
|
|
27472
|
+
return this.indexManager.createTargetIndexes(transaction, queryToTarget(query2));
|
|
27442
27473
|
}
|
|
27443
27474
|
return PersistencePromise.resolve();
|
|
27444
27475
|
}
|
|
@@ -27446,38 +27477,38 @@ class QueryEngine {
|
|
|
27446
27477
|
* Performs an indexed query that evaluates the query based on a collection's
|
|
27447
27478
|
* persisted index values. Returns `null` if an index is not available.
|
|
27448
27479
|
*/
|
|
27449
|
-
performQueryUsingIndex(transaction,
|
|
27450
|
-
if (queryMatchesAllDocuments(
|
|
27480
|
+
performQueryUsingIndex(transaction, query2) {
|
|
27481
|
+
if (queryMatchesAllDocuments(query2)) {
|
|
27451
27482
|
return PersistencePromise.resolve(null);
|
|
27452
27483
|
}
|
|
27453
|
-
let target = queryToTarget(
|
|
27484
|
+
let target = queryToTarget(query2);
|
|
27454
27485
|
return this.indexManager.getIndexType(transaction, target).next((indexType) => {
|
|
27455
27486
|
if (indexType === 0) {
|
|
27456
27487
|
return null;
|
|
27457
27488
|
}
|
|
27458
|
-
if (
|
|
27459
|
-
|
|
27460
|
-
|
|
27489
|
+
if (query2.limit !== null && indexType === 1) {
|
|
27490
|
+
query2 = queryWithLimit(
|
|
27491
|
+
query2,
|
|
27461
27492
|
null,
|
|
27462
27493
|
"F"
|
|
27463
27494
|
/* LimitType.First */
|
|
27464
27495
|
);
|
|
27465
|
-
target = queryToTarget(
|
|
27496
|
+
target = queryToTarget(query2);
|
|
27466
27497
|
}
|
|
27467
27498
|
return this.indexManager.getDocumentsMatchingTarget(transaction, target).next((keys) => {
|
|
27468
27499
|
const sortedKeys = documentKeySet(...keys);
|
|
27469
27500
|
return this.localDocumentsView.getDocuments(transaction, sortedKeys).next((indexedDocuments) => {
|
|
27470
27501
|
return this.indexManager.getMinOffset(transaction, target).next((offset) => {
|
|
27471
|
-
const previousResults = this.applyQuery(
|
|
27472
|
-
if (this.needsRefill(
|
|
27502
|
+
const previousResults = this.applyQuery(query2, indexedDocuments);
|
|
27503
|
+
if (this.needsRefill(query2, previousResults, sortedKeys, offset.readTime)) {
|
|
27473
27504
|
return this.performQueryUsingIndex(transaction, queryWithLimit(
|
|
27474
|
-
|
|
27505
|
+
query2,
|
|
27475
27506
|
null,
|
|
27476
27507
|
"F"
|
|
27477
27508
|
/* LimitType.First */
|
|
27478
27509
|
));
|
|
27479
27510
|
}
|
|
27480
|
-
return this.appendRemainingResults(transaction, previousResults,
|
|
27511
|
+
return this.appendRemainingResults(transaction, previousResults, query2, offset);
|
|
27481
27512
|
});
|
|
27482
27513
|
});
|
|
27483
27514
|
});
|
|
@@ -27487,29 +27518,29 @@ class QueryEngine {
|
|
|
27487
27518
|
* Performs a query based on the target's persisted query mapping. Returns
|
|
27488
27519
|
* `null` if the mapping is not available or cannot be used.
|
|
27489
27520
|
*/
|
|
27490
|
-
performQueryUsingRemoteKeys(transaction,
|
|
27491
|
-
if (queryMatchesAllDocuments(
|
|
27521
|
+
performQueryUsingRemoteKeys(transaction, query2, remoteKeys, lastLimboFreeSnapshotVersion) {
|
|
27522
|
+
if (queryMatchesAllDocuments(query2)) {
|
|
27492
27523
|
return PersistencePromise.resolve(null);
|
|
27493
27524
|
}
|
|
27494
27525
|
if (lastLimboFreeSnapshotVersion.isEqual(SnapshotVersion.min())) {
|
|
27495
27526
|
return PersistencePromise.resolve(null);
|
|
27496
27527
|
}
|
|
27497
27528
|
return this.localDocumentsView.getDocuments(transaction, remoteKeys).next((documents) => {
|
|
27498
|
-
const previousResults = this.applyQuery(
|
|
27499
|
-
if (this.needsRefill(
|
|
27529
|
+
const previousResults = this.applyQuery(query2, documents);
|
|
27530
|
+
if (this.needsRefill(query2, previousResults, remoteKeys, lastLimboFreeSnapshotVersion)) {
|
|
27500
27531
|
return PersistencePromise.resolve(null);
|
|
27501
27532
|
}
|
|
27502
27533
|
if (getLogLevel() <= LogLevel.DEBUG) {
|
|
27503
|
-
logDebug("QueryEngine", "Re-using previous result from %s to execute query: %s", lastLimboFreeSnapshotVersion.toString(), stringifyQuery(
|
|
27534
|
+
logDebug("QueryEngine", "Re-using previous result from %s to execute query: %s", lastLimboFreeSnapshotVersion.toString(), stringifyQuery(query2));
|
|
27504
27535
|
}
|
|
27505
|
-
return this.appendRemainingResults(transaction, previousResults,
|
|
27536
|
+
return this.appendRemainingResults(transaction, previousResults, query2, newIndexOffsetSuccessorFromReadTime(lastLimboFreeSnapshotVersion, INITIAL_LARGEST_BATCH_ID)).next((results) => results);
|
|
27506
27537
|
});
|
|
27507
27538
|
}
|
|
27508
27539
|
/** Applies the query filter and sorting to the provided documents. */
|
|
27509
|
-
applyQuery(
|
|
27510
|
-
let queryResults = new SortedSet(newQueryComparator(
|
|
27540
|
+
applyQuery(query2, documents) {
|
|
27541
|
+
let queryResults = new SortedSet(newQueryComparator(query2));
|
|
27511
27542
|
documents.forEach((_, maybeDoc) => {
|
|
27512
|
-
if (queryMatches(
|
|
27543
|
+
if (queryMatches(query2, maybeDoc)) {
|
|
27513
27544
|
queryResults = queryResults.add(maybeDoc);
|
|
27514
27545
|
}
|
|
27515
27546
|
});
|
|
@@ -27527,31 +27558,31 @@ class QueryEngine {
|
|
|
27527
27558
|
* @param limboFreeSnapshotVersion - The version of the snapshot when the
|
|
27528
27559
|
* query was last synchronized.
|
|
27529
27560
|
*/
|
|
27530
|
-
needsRefill(
|
|
27531
|
-
if (
|
|
27561
|
+
needsRefill(query2, sortedPreviousResults, remoteKeys, limboFreeSnapshotVersion) {
|
|
27562
|
+
if (query2.limit === null) {
|
|
27532
27563
|
return false;
|
|
27533
27564
|
}
|
|
27534
27565
|
if (remoteKeys.size !== sortedPreviousResults.size) {
|
|
27535
27566
|
return true;
|
|
27536
27567
|
}
|
|
27537
|
-
const docAtLimitEdge =
|
|
27568
|
+
const docAtLimitEdge = query2.limitType === "F" ? sortedPreviousResults.last() : sortedPreviousResults.first();
|
|
27538
27569
|
if (!docAtLimitEdge) {
|
|
27539
27570
|
return false;
|
|
27540
27571
|
}
|
|
27541
27572
|
return docAtLimitEdge.hasPendingWrites || docAtLimitEdge.version.compareTo(limboFreeSnapshotVersion) > 0;
|
|
27542
27573
|
}
|
|
27543
|
-
executeFullCollectionScan(transaction,
|
|
27574
|
+
executeFullCollectionScan(transaction, query2, context) {
|
|
27544
27575
|
if (getLogLevel() <= LogLevel.DEBUG) {
|
|
27545
|
-
logDebug("QueryEngine", "Using full collection scan to execute query:", stringifyQuery(
|
|
27576
|
+
logDebug("QueryEngine", "Using full collection scan to execute query:", stringifyQuery(query2));
|
|
27546
27577
|
}
|
|
27547
|
-
return this.localDocumentsView.getDocumentsMatchingQuery(transaction,
|
|
27578
|
+
return this.localDocumentsView.getDocumentsMatchingQuery(transaction, query2, IndexOffset.min(), context);
|
|
27548
27579
|
}
|
|
27549
27580
|
/**
|
|
27550
27581
|
* Combines the results from an indexed execution with the remaining documents
|
|
27551
27582
|
* that have not yet been indexed.
|
|
27552
27583
|
*/
|
|
27553
|
-
appendRemainingResults(transaction, indexedResults,
|
|
27554
|
-
return this.localDocumentsView.getDocumentsMatchingQuery(transaction,
|
|
27584
|
+
appendRemainingResults(transaction, indexedResults, query2, offset) {
|
|
27585
|
+
return this.localDocumentsView.getDocumentsMatchingQuery(transaction, query2, offset).next((remainingResults) => {
|
|
27555
27586
|
indexedResults.forEach((d) => {
|
|
27556
27587
|
remainingResults = remainingResults.insert(d.key, d);
|
|
27557
27588
|
});
|
|
@@ -32296,8 +32327,8 @@ class DocumentChangeSet {
|
|
|
32296
32327
|
}
|
|
32297
32328
|
}
|
|
32298
32329
|
class ViewSnapshot {
|
|
32299
|
-
constructor(
|
|
32300
|
-
this.query =
|
|
32330
|
+
constructor(query2, docs, oldDocs, docChanges, mutatedKeys, fromCache, syncStateChanged, excludesMetadataChanges, hasCachedResults) {
|
|
32331
|
+
this.query = query2;
|
|
32301
32332
|
this.docs = docs;
|
|
32302
32333
|
this.oldDocs = oldDocs;
|
|
32303
32334
|
this.docChanges = docChanges;
|
|
@@ -32308,13 +32339,13 @@ class ViewSnapshot {
|
|
|
32308
32339
|
this.hasCachedResults = hasCachedResults;
|
|
32309
32340
|
}
|
|
32310
32341
|
/** Returns a view snapshot as if all documents in the snapshot were added. */
|
|
32311
|
-
static fromInitialDocuments(
|
|
32342
|
+
static fromInitialDocuments(query2, documents, mutatedKeys, fromCache, hasCachedResults) {
|
|
32312
32343
|
const changes = [];
|
|
32313
32344
|
documents.forEach((doc3) => {
|
|
32314
32345
|
changes.push({ type: 0, doc: doc3 });
|
|
32315
32346
|
});
|
|
32316
32347
|
return new ViewSnapshot(
|
|
32317
|
-
|
|
32348
|
+
query2,
|
|
32318
32349
|
documents,
|
|
32319
32350
|
DocumentSet.emptySet(documents),
|
|
32320
32351
|
changes,
|
|
@@ -32392,8 +32423,8 @@ function newQueriesObjectMap() {
|
|
|
32392
32423
|
async function eventManagerListen(eventManager, listener) {
|
|
32393
32424
|
const eventManagerImpl = debugCast(eventManager);
|
|
32394
32425
|
let listenerAction = 3;
|
|
32395
|
-
const
|
|
32396
|
-
let queryInfo = eventManagerImpl.queries.get(
|
|
32426
|
+
const query2 = listener.query;
|
|
32427
|
+
let queryInfo = eventManagerImpl.queries.get(query2);
|
|
32397
32428
|
if (!queryInfo) {
|
|
32398
32429
|
queryInfo = new QueryListenersInfo();
|
|
32399
32430
|
listenerAction = listener.listensToRemoteStore() ? 0 : 1;
|
|
@@ -32404,20 +32435,20 @@ async function eventManagerListen(eventManager, listener) {
|
|
|
32404
32435
|
switch (listenerAction) {
|
|
32405
32436
|
case 0:
|
|
32406
32437
|
queryInfo.viewSnap = await eventManagerImpl.onListen(
|
|
32407
|
-
|
|
32438
|
+
query2,
|
|
32408
32439
|
/** enableRemoteListen= */
|
|
32409
32440
|
true
|
|
32410
32441
|
);
|
|
32411
32442
|
break;
|
|
32412
32443
|
case 1:
|
|
32413
32444
|
queryInfo.viewSnap = await eventManagerImpl.onListen(
|
|
32414
|
-
|
|
32445
|
+
query2,
|
|
32415
32446
|
/** enableRemoteListen= */
|
|
32416
32447
|
false
|
|
32417
32448
|
);
|
|
32418
32449
|
break;
|
|
32419
32450
|
case 2:
|
|
32420
|
-
await eventManagerImpl.onFirstRemoteStoreListen(
|
|
32451
|
+
await eventManagerImpl.onFirstRemoteStoreListen(query2);
|
|
32421
32452
|
break;
|
|
32422
32453
|
default:
|
|
32423
32454
|
break;
|
|
@@ -32427,7 +32458,7 @@ async function eventManagerListen(eventManager, listener) {
|
|
|
32427
32458
|
listener.onError(firestoreError);
|
|
32428
32459
|
return;
|
|
32429
32460
|
}
|
|
32430
|
-
eventManagerImpl.queries.set(
|
|
32461
|
+
eventManagerImpl.queries.set(query2, queryInfo);
|
|
32431
32462
|
queryInfo.listeners.push(listener);
|
|
32432
32463
|
listener.applyOnlineStateChange(eventManagerImpl.onlineState);
|
|
32433
32464
|
if (queryInfo.viewSnap) {
|
|
@@ -32439,9 +32470,9 @@ async function eventManagerListen(eventManager, listener) {
|
|
|
32439
32470
|
}
|
|
32440
32471
|
async function eventManagerUnlisten(eventManager, listener) {
|
|
32441
32472
|
const eventManagerImpl = debugCast(eventManager);
|
|
32442
|
-
const
|
|
32473
|
+
const query2 = listener.query;
|
|
32443
32474
|
let listenerAction = 3;
|
|
32444
|
-
const queryInfo = eventManagerImpl.queries.get(
|
|
32475
|
+
const queryInfo = eventManagerImpl.queries.get(query2);
|
|
32445
32476
|
if (queryInfo) {
|
|
32446
32477
|
const i = queryInfo.listeners.indexOf(listener);
|
|
32447
32478
|
if (i >= 0) {
|
|
@@ -32455,21 +32486,21 @@ async function eventManagerUnlisten(eventManager, listener) {
|
|
|
32455
32486
|
}
|
|
32456
32487
|
switch (listenerAction) {
|
|
32457
32488
|
case 0:
|
|
32458
|
-
eventManagerImpl.queries.delete(
|
|
32489
|
+
eventManagerImpl.queries.delete(query2);
|
|
32459
32490
|
return eventManagerImpl.onUnlisten(
|
|
32460
|
-
|
|
32491
|
+
query2,
|
|
32461
32492
|
/** disableRemoteListen= */
|
|
32462
32493
|
true
|
|
32463
32494
|
);
|
|
32464
32495
|
case 1:
|
|
32465
|
-
eventManagerImpl.queries.delete(
|
|
32496
|
+
eventManagerImpl.queries.delete(query2);
|
|
32466
32497
|
return eventManagerImpl.onUnlisten(
|
|
32467
|
-
|
|
32498
|
+
query2,
|
|
32468
32499
|
/** disableRemoteListen= */
|
|
32469
32500
|
false
|
|
32470
32501
|
);
|
|
32471
32502
|
case 2:
|
|
32472
|
-
return eventManagerImpl.onLastRemoteStoreUnlisten(
|
|
32503
|
+
return eventManagerImpl.onLastRemoteStoreUnlisten(query2);
|
|
32473
32504
|
default:
|
|
32474
32505
|
return;
|
|
32475
32506
|
}
|
|
@@ -32478,8 +32509,8 @@ function eventManagerOnWatchChange(eventManager, viewSnaps) {
|
|
|
32478
32509
|
const eventManagerImpl = debugCast(eventManager);
|
|
32479
32510
|
let raisedEvent = false;
|
|
32480
32511
|
for (const viewSnap of viewSnaps) {
|
|
32481
|
-
const
|
|
32482
|
-
const queryInfo = eventManagerImpl.queries.get(
|
|
32512
|
+
const query2 = viewSnap.query;
|
|
32513
|
+
const queryInfo = eventManagerImpl.queries.get(query2);
|
|
32483
32514
|
if (queryInfo) {
|
|
32484
32515
|
for (const listener of queryInfo.listeners) {
|
|
32485
32516
|
if (listener.onViewSnapshot(viewSnap)) {
|
|
@@ -32493,15 +32524,15 @@ function eventManagerOnWatchChange(eventManager, viewSnaps) {
|
|
|
32493
32524
|
raiseSnapshotsInSyncEvent(eventManagerImpl);
|
|
32494
32525
|
}
|
|
32495
32526
|
}
|
|
32496
|
-
function eventManagerOnWatchError(eventManager,
|
|
32527
|
+
function eventManagerOnWatchError(eventManager, query2, error2) {
|
|
32497
32528
|
const eventManagerImpl = debugCast(eventManager);
|
|
32498
|
-
const queryInfo = eventManagerImpl.queries.get(
|
|
32529
|
+
const queryInfo = eventManagerImpl.queries.get(query2);
|
|
32499
32530
|
if (queryInfo) {
|
|
32500
32531
|
for (const listener of queryInfo.listeners) {
|
|
32501
32532
|
listener.onError(error2);
|
|
32502
32533
|
}
|
|
32503
32534
|
}
|
|
32504
|
-
eventManagerImpl.queries.delete(
|
|
32535
|
+
eventManagerImpl.queries.delete(query2);
|
|
32505
32536
|
}
|
|
32506
32537
|
function eventManagerOnOnlineStateChange(eventManager, onlineState) {
|
|
32507
32538
|
const eventManagerImpl = debugCast(eventManager);
|
|
@@ -32539,8 +32570,8 @@ var ListenerDataSource;
|
|
|
32539
32570
|
ListenerDataSource2["Cache"] = "cache";
|
|
32540
32571
|
})(ListenerDataSource || (ListenerDataSource = {}));
|
|
32541
32572
|
class QueryListener {
|
|
32542
|
-
constructor(
|
|
32543
|
-
this.query =
|
|
32573
|
+
constructor(query2, queryObserver, options) {
|
|
32574
|
+
this.query = query2;
|
|
32544
32575
|
this.queryObserver = queryObserver;
|
|
32545
32576
|
this.raisedInitialEvent = false;
|
|
32546
32577
|
this.snap = null;
|
|
@@ -32698,15 +32729,15 @@ class RemovedLimboDocument {
|
|
|
32698
32729
|
}
|
|
32699
32730
|
}
|
|
32700
32731
|
class View {
|
|
32701
|
-
constructor(
|
|
32702
|
-
this.query =
|
|
32732
|
+
constructor(query2, _syncedDocuments) {
|
|
32733
|
+
this.query = query2;
|
|
32703
32734
|
this._syncedDocuments = _syncedDocuments;
|
|
32704
32735
|
this.syncState = null;
|
|
32705
32736
|
this.hasCachedResults = false;
|
|
32706
32737
|
this.current = false;
|
|
32707
32738
|
this.limboDocuments = documentKeySet();
|
|
32708
32739
|
this.mutatedKeys = documentKeySet();
|
|
32709
|
-
this.docComparator = newQueryComparator(
|
|
32740
|
+
this.docComparator = newQueryComparator(query2);
|
|
32710
32741
|
this.documentSet = new DocumentSet(this.docComparator);
|
|
32711
32742
|
}
|
|
32712
32743
|
/**
|
|
@@ -32999,8 +33030,8 @@ function compareChangeType(c1, c2) {
|
|
|
32999
33030
|
*/
|
|
33000
33031
|
const LOG_TAG$3 = "SyncEngine";
|
|
33001
33032
|
class QueryView {
|
|
33002
|
-
constructor(
|
|
33003
|
-
this.query =
|
|
33033
|
+
constructor(query2, targetId, view) {
|
|
33034
|
+
this.query = query2;
|
|
33004
33035
|
this.targetId = targetId;
|
|
33005
33036
|
this.view = view;
|
|
33006
33037
|
}
|
|
@@ -33043,17 +33074,17 @@ function newSyncEngine(localStore, remoteStore, eventManager, sharedClientState,
|
|
|
33043
33074
|
}
|
|
33044
33075
|
return syncEngine;
|
|
33045
33076
|
}
|
|
33046
|
-
async function syncEngineListen(syncEngine,
|
|
33077
|
+
async function syncEngineListen(syncEngine, query2, shouldListenToRemote = true) {
|
|
33047
33078
|
const syncEngineImpl = ensureWatchCallbacks(syncEngine);
|
|
33048
33079
|
let viewSnapshot;
|
|
33049
|
-
const queryView = syncEngineImpl.queryViewsByQuery.get(
|
|
33080
|
+
const queryView = syncEngineImpl.queryViewsByQuery.get(query2);
|
|
33050
33081
|
if (queryView) {
|
|
33051
33082
|
syncEngineImpl.sharedClientState.addLocalQueryTarget(queryView.targetId);
|
|
33052
33083
|
viewSnapshot = queryView.view.computeInitialSnapshot();
|
|
33053
33084
|
} else {
|
|
33054
33085
|
viewSnapshot = await allocateTargetAndMaybeListen(
|
|
33055
33086
|
syncEngineImpl,
|
|
33056
|
-
|
|
33087
|
+
query2,
|
|
33057
33088
|
shouldListenToRemote,
|
|
33058
33089
|
/** shouldInitializeView= */
|
|
33059
33090
|
true
|
|
@@ -33061,19 +33092,19 @@ async function syncEngineListen(syncEngine, query, shouldListenToRemote = true)
|
|
|
33061
33092
|
}
|
|
33062
33093
|
return viewSnapshot;
|
|
33063
33094
|
}
|
|
33064
|
-
async function triggerRemoteStoreListen(syncEngine,
|
|
33095
|
+
async function triggerRemoteStoreListen(syncEngine, query2) {
|
|
33065
33096
|
const syncEngineImpl = ensureWatchCallbacks(syncEngine);
|
|
33066
33097
|
await allocateTargetAndMaybeListen(
|
|
33067
33098
|
syncEngineImpl,
|
|
33068
|
-
|
|
33099
|
+
query2,
|
|
33069
33100
|
/** shouldListenToRemote= */
|
|
33070
33101
|
true,
|
|
33071
33102
|
/** shouldInitializeView= */
|
|
33072
33103
|
false
|
|
33073
33104
|
);
|
|
33074
33105
|
}
|
|
33075
|
-
async function allocateTargetAndMaybeListen(syncEngineImpl,
|
|
33076
|
-
const targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, queryToTarget(
|
|
33106
|
+
async function allocateTargetAndMaybeListen(syncEngineImpl, query2, shouldListenToRemote, shouldInitializeView) {
|
|
33107
|
+
const targetData = await localStoreAllocateTarget(syncEngineImpl.localStore, queryToTarget(query2));
|
|
33077
33108
|
const targetId = targetData.targetId;
|
|
33078
33109
|
const status = syncEngineImpl.sharedClientState.addLocalQueryTarget(
|
|
33079
33110
|
targetId,
|
|
@@ -33082,22 +33113,22 @@ async function allocateTargetAndMaybeListen(syncEngineImpl, query, shouldListenT
|
|
|
33082
33113
|
);
|
|
33083
33114
|
let viewSnapshot;
|
|
33084
33115
|
if (shouldInitializeView) {
|
|
33085
|
-
viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl,
|
|
33116
|
+
viewSnapshot = await initializeViewAndComputeSnapshot(syncEngineImpl, query2, targetId, status === "current", targetData.resumeToken);
|
|
33086
33117
|
}
|
|
33087
33118
|
if (syncEngineImpl.isPrimaryClient && shouldListenToRemote) {
|
|
33088
33119
|
remoteStoreListen(syncEngineImpl.remoteStore, targetData);
|
|
33089
33120
|
}
|
|
33090
33121
|
return viewSnapshot;
|
|
33091
33122
|
}
|
|
33092
|
-
async function initializeViewAndComputeSnapshot(syncEngineImpl,
|
|
33123
|
+
async function initializeViewAndComputeSnapshot(syncEngineImpl, query2, targetId, current, resumeToken) {
|
|
33093
33124
|
syncEngineImpl.applyDocChanges = (queryView, changes, remoteEvent) => applyDocChanges(syncEngineImpl, queryView, changes, remoteEvent);
|
|
33094
33125
|
const queryResult = await localStoreExecuteQuery(
|
|
33095
33126
|
syncEngineImpl.localStore,
|
|
33096
|
-
|
|
33127
|
+
query2,
|
|
33097
33128
|
/* usePreviousResults= */
|
|
33098
33129
|
true
|
|
33099
33130
|
);
|
|
33100
|
-
const view = new View(
|
|
33131
|
+
const view = new View(query2, queryResult.remoteKeys);
|
|
33101
33132
|
const viewDocChanges = view.computeDocChanges(queryResult.documents);
|
|
33102
33133
|
const synthesizedTargetChange = TargetChange.createSynthesizedTargetChangeForCurrentChange(targetId, current && syncEngineImpl.onlineState !== "Offline", resumeToken);
|
|
33103
33134
|
const viewChange = view.applyChanges(
|
|
@@ -33107,22 +33138,22 @@ async function initializeViewAndComputeSnapshot(syncEngineImpl, query, targetId,
|
|
|
33107
33138
|
synthesizedTargetChange
|
|
33108
33139
|
);
|
|
33109
33140
|
updateTrackedLimbos(syncEngineImpl, targetId, viewChange.limboChanges);
|
|
33110
|
-
const data = new QueryView(
|
|
33111
|
-
syncEngineImpl.queryViewsByQuery.set(
|
|
33141
|
+
const data = new QueryView(query2, targetId, view);
|
|
33142
|
+
syncEngineImpl.queryViewsByQuery.set(query2, data);
|
|
33112
33143
|
if (syncEngineImpl.queriesByTarget.has(targetId)) {
|
|
33113
|
-
syncEngineImpl.queriesByTarget.get(targetId).push(
|
|
33144
|
+
syncEngineImpl.queriesByTarget.get(targetId).push(query2);
|
|
33114
33145
|
} else {
|
|
33115
|
-
syncEngineImpl.queriesByTarget.set(targetId, [
|
|
33146
|
+
syncEngineImpl.queriesByTarget.set(targetId, [query2]);
|
|
33116
33147
|
}
|
|
33117
33148
|
return viewChange.snapshot;
|
|
33118
33149
|
}
|
|
33119
|
-
async function syncEngineUnlisten(syncEngine,
|
|
33150
|
+
async function syncEngineUnlisten(syncEngine, query2, shouldUnlistenToRemote) {
|
|
33120
33151
|
const syncEngineImpl = debugCast(syncEngine);
|
|
33121
|
-
const queryView = syncEngineImpl.queryViewsByQuery.get(
|
|
33152
|
+
const queryView = syncEngineImpl.queryViewsByQuery.get(query2);
|
|
33122
33153
|
const queries = syncEngineImpl.queriesByTarget.get(queryView.targetId);
|
|
33123
33154
|
if (queries.length > 1) {
|
|
33124
|
-
syncEngineImpl.queriesByTarget.set(queryView.targetId, queries.filter((q) => !queryEquals(q,
|
|
33125
|
-
syncEngineImpl.queryViewsByQuery.delete(
|
|
33155
|
+
syncEngineImpl.queriesByTarget.set(queryView.targetId, queries.filter((q) => !queryEquals(q, query2)));
|
|
33156
|
+
syncEngineImpl.queryViewsByQuery.delete(query2);
|
|
33126
33157
|
return;
|
|
33127
33158
|
}
|
|
33128
33159
|
if (syncEngineImpl.isPrimaryClient) {
|
|
@@ -33152,9 +33183,9 @@ async function syncEngineUnlisten(syncEngine, query, shouldUnlistenToRemote) {
|
|
|
33152
33183
|
);
|
|
33153
33184
|
}
|
|
33154
33185
|
}
|
|
33155
|
-
async function triggerRemoteStoreUnlisten(syncEngine,
|
|
33186
|
+
async function triggerRemoteStoreUnlisten(syncEngine, query2) {
|
|
33156
33187
|
const syncEngineImpl = debugCast(syncEngine);
|
|
33157
|
-
const queryView = syncEngineImpl.queryViewsByQuery.get(
|
|
33188
|
+
const queryView = syncEngineImpl.queryViewsByQuery.get(query2);
|
|
33158
33189
|
const queries = syncEngineImpl.queriesByTarget.get(queryView.targetId);
|
|
33159
33190
|
if (syncEngineImpl.isPrimaryClient && queries.length === 1) {
|
|
33160
33191
|
syncEngineImpl.sharedClientState.removeLocalQueryTarget(queryView.targetId);
|
|
@@ -33202,7 +33233,7 @@ function syncEngineApplyOnlineStateChange(syncEngine, onlineState, source) {
|
|
|
33202
33233
|
const syncEngineImpl = debugCast(syncEngine);
|
|
33203
33234
|
if (syncEngineImpl.isPrimaryClient && source === 0 || !syncEngineImpl.isPrimaryClient && source === 1) {
|
|
33204
33235
|
const newViewSnapshots = [];
|
|
33205
|
-
syncEngineImpl.queryViewsByQuery.forEach((
|
|
33236
|
+
syncEngineImpl.queryViewsByQuery.forEach((query2, queryView) => {
|
|
33206
33237
|
const viewChange = queryView.view.applyOnlineStateChange(onlineState);
|
|
33207
33238
|
if (viewChange.snapshot) {
|
|
33208
33239
|
newViewSnapshots.push(viewChange.snapshot);
|
|
@@ -33319,10 +33350,10 @@ function processUserCallback(syncEngine, batchId, error2) {
|
|
|
33319
33350
|
}
|
|
33320
33351
|
function removeAndCleanupTarget(syncEngineImpl, targetId, error2 = null) {
|
|
33321
33352
|
syncEngineImpl.sharedClientState.removeLocalQueryTarget(targetId);
|
|
33322
|
-
for (const
|
|
33323
|
-
syncEngineImpl.queryViewsByQuery.delete(
|
|
33353
|
+
for (const query2 of syncEngineImpl.queriesByTarget.get(targetId)) {
|
|
33354
|
+
syncEngineImpl.queryViewsByQuery.delete(query2);
|
|
33324
33355
|
if (error2) {
|
|
33325
|
-
syncEngineImpl.syncEngineListener.onWatchError(
|
|
33356
|
+
syncEngineImpl.syncEngineListener.onWatchError(query2, error2);
|
|
33326
33357
|
}
|
|
33327
33358
|
}
|
|
33328
33359
|
syncEngineImpl.queriesByTarget.delete(targetId);
|
|
@@ -33459,8 +33490,8 @@ function syncEngineGetRemoteKeysForTarget(syncEngine, targetId) {
|
|
|
33459
33490
|
if (!queries) {
|
|
33460
33491
|
return keySet;
|
|
33461
33492
|
}
|
|
33462
|
-
for (const
|
|
33463
|
-
const queryView = syncEngineImpl.queryViewsByQuery.get(
|
|
33493
|
+
for (const query2 of queries) {
|
|
33494
|
+
const queryView = syncEngineImpl.queryViewsByQuery.get(query2);
|
|
33464
33495
|
keySet = keySet.unionWith(queryView.view.syncedDocuments);
|
|
33465
33496
|
}
|
|
33466
33497
|
return keySet;
|
|
@@ -33827,9 +33858,9 @@ async function getEventManager(client2) {
|
|
|
33827
33858
|
eventManager.onLastRemoteStoreUnlisten = triggerRemoteStoreUnlisten.bind(null, onlineComponentProvider.syncEngine);
|
|
33828
33859
|
return eventManager;
|
|
33829
33860
|
}
|
|
33830
|
-
function firestoreClientListen(client2,
|
|
33861
|
+
function firestoreClientListen(client2, query2, options, observer) {
|
|
33831
33862
|
const wrappedObserver = new AsyncObserver(observer);
|
|
33832
|
-
const listener = new QueryListener(
|
|
33863
|
+
const listener = new QueryListener(query2, wrappedObserver, options);
|
|
33833
33864
|
client2.asyncQueue.enqueueAndForget(async () => {
|
|
33834
33865
|
const eventManager = await getEventManager(client2);
|
|
33835
33866
|
return eventManagerListen(eventManager, listener);
|
|
@@ -33850,11 +33881,11 @@ function firestoreClientGetDocumentViaSnapshotListener(client2, key, options = {
|
|
|
33850
33881
|
});
|
|
33851
33882
|
return deferred.promise;
|
|
33852
33883
|
}
|
|
33853
|
-
function firestoreClientGetDocumentsViaSnapshotListener(client2,
|
|
33884
|
+
function firestoreClientGetDocumentsViaSnapshotListener(client2, query2, options = {}) {
|
|
33854
33885
|
const deferred = new Deferred();
|
|
33855
33886
|
client2.asyncQueue.enqueueAndForget(async () => {
|
|
33856
33887
|
const eventManager = await getEventManager(client2);
|
|
33857
|
-
return executeQueryViaSnapshotListener(eventManager, client2.asyncQueue,
|
|
33888
|
+
return executeQueryViaSnapshotListener(eventManager, client2.asyncQueue, query2, options, deferred);
|
|
33858
33889
|
});
|
|
33859
33890
|
return deferred.promise;
|
|
33860
33891
|
}
|
|
@@ -33888,7 +33919,7 @@ function readDocumentViaSnapshotListener(eventManager, asyncQueue, key, options,
|
|
|
33888
33919
|
});
|
|
33889
33920
|
return eventManagerListen(eventManager, listener);
|
|
33890
33921
|
}
|
|
33891
|
-
function executeQueryViaSnapshotListener(eventManager, asyncQueue,
|
|
33922
|
+
function executeQueryViaSnapshotListener(eventManager, asyncQueue, query2, options, result) {
|
|
33892
33923
|
const wrappedObserver = new AsyncObserver({
|
|
33893
33924
|
next: (snapshot) => {
|
|
33894
33925
|
wrappedObserver.mute();
|
|
@@ -33901,7 +33932,7 @@ function executeQueryViaSnapshotListener(eventManager, asyncQueue, query, option
|
|
|
33901
33932
|
},
|
|
33902
33933
|
error: (e) => result.reject(e)
|
|
33903
33934
|
});
|
|
33904
|
-
const listener = new QueryListener(
|
|
33935
|
+
const listener = new QueryListener(query2, wrappedObserver, {
|
|
33905
33936
|
includeMetadataChanges: true,
|
|
33906
33937
|
waitForSyncWhenOnline: true
|
|
33907
33938
|
});
|
|
@@ -35218,6 +35249,14 @@ class DeleteFieldValueImpl extends FieldValue {
|
|
|
35218
35249
|
return other instanceof DeleteFieldValueImpl;
|
|
35219
35250
|
}
|
|
35220
35251
|
}
|
|
35252
|
+
class ServerTimestampFieldValueImpl extends FieldValue {
|
|
35253
|
+
_toFieldTransform(context) {
|
|
35254
|
+
return new FieldTransform(context.path, new ServerTimestampTransform());
|
|
35255
|
+
}
|
|
35256
|
+
isEqual(other) {
|
|
35257
|
+
return other instanceof ServerTimestampFieldValueImpl;
|
|
35258
|
+
}
|
|
35259
|
+
}
|
|
35221
35260
|
function parseUpdateData(userDataReader, methodName, targetDoc, input) {
|
|
35222
35261
|
const context = userDataReader.createContext(1, methodName, targetDoc);
|
|
35223
35262
|
validatePlainObject("Data must be an object, but it was:", context, input);
|
|
@@ -35273,6 +35312,11 @@ function parseUpdateVarargs(userDataReader, methodName, targetDoc, field2, value
|
|
|
35273
35312
|
const mask = new FieldMask(fieldMaskPaths);
|
|
35274
35313
|
return new ParsedUpdateData(updateData, mask, context.fieldTransforms);
|
|
35275
35314
|
}
|
|
35315
|
+
function parseQueryValue(userDataReader, methodName, input, allowArrays = false) {
|
|
35316
|
+
const context = userDataReader.createContext(allowArrays ? 4 : 3, methodName);
|
|
35317
|
+
const parsed = parseData(input, context);
|
|
35318
|
+
return parsed;
|
|
35319
|
+
}
|
|
35276
35320
|
function parseData(input, context) {
|
|
35277
35321
|
input = getModularInstance(input);
|
|
35278
35322
|
if (looksLikeJsonObject(input)) {
|
|
@@ -35614,11 +35658,210 @@ function fieldPathFromArgument(methodName, arg) {
|
|
|
35614
35658
|
* See the License for the specific language governing permissions and
|
|
35615
35659
|
* limitations under the License.
|
|
35616
35660
|
*/
|
|
35617
|
-
function validateHasExplicitOrderByForLimitToLast(
|
|
35618
|
-
if (
|
|
35661
|
+
function validateHasExplicitOrderByForLimitToLast(query2) {
|
|
35662
|
+
if (query2.limitType === "L" && query2.explicitOrderBy.length === 0) {
|
|
35619
35663
|
throw new FirestoreError(Code.UNIMPLEMENTED, "limitToLast() queries require specifying at least one orderBy() clause");
|
|
35620
35664
|
}
|
|
35621
35665
|
}
|
|
35666
|
+
class AppliableConstraint {
|
|
35667
|
+
}
|
|
35668
|
+
class QueryConstraint extends AppliableConstraint {
|
|
35669
|
+
}
|
|
35670
|
+
function query(query2, queryConstraint, ...additionalQueryConstraints) {
|
|
35671
|
+
let queryConstraints = [];
|
|
35672
|
+
if (queryConstraint instanceof AppliableConstraint) {
|
|
35673
|
+
queryConstraints.push(queryConstraint);
|
|
35674
|
+
}
|
|
35675
|
+
queryConstraints = queryConstraints.concat(additionalQueryConstraints);
|
|
35676
|
+
validateQueryConstraintArray(queryConstraints);
|
|
35677
|
+
for (const constraint of queryConstraints) {
|
|
35678
|
+
query2 = constraint._apply(query2);
|
|
35679
|
+
}
|
|
35680
|
+
return query2;
|
|
35681
|
+
}
|
|
35682
|
+
class QueryFieldFilterConstraint extends QueryConstraint {
|
|
35683
|
+
/**
|
|
35684
|
+
* @internal
|
|
35685
|
+
*/
|
|
35686
|
+
constructor(_field, _op, _value) {
|
|
35687
|
+
super();
|
|
35688
|
+
this._field = _field;
|
|
35689
|
+
this._op = _op;
|
|
35690
|
+
this._value = _value;
|
|
35691
|
+
this.type = "where";
|
|
35692
|
+
}
|
|
35693
|
+
static _create(_field, _op, _value) {
|
|
35694
|
+
return new QueryFieldFilterConstraint(_field, _op, _value);
|
|
35695
|
+
}
|
|
35696
|
+
_apply(query2) {
|
|
35697
|
+
const filter2 = this._parse(query2);
|
|
35698
|
+
validateNewFieldFilter(query2._query, filter2);
|
|
35699
|
+
return new Query(query2.firestore, query2.converter, queryWithAddedFilter(query2._query, filter2));
|
|
35700
|
+
}
|
|
35701
|
+
_parse(query2) {
|
|
35702
|
+
const reader2 = newUserDataReader(query2.firestore);
|
|
35703
|
+
const filter2 = newQueryFilter(query2._query, "where", reader2, query2.firestore._databaseId, this._field, this._op, this._value);
|
|
35704
|
+
return filter2;
|
|
35705
|
+
}
|
|
35706
|
+
}
|
|
35707
|
+
function where(fieldPath, opStr, value) {
|
|
35708
|
+
const op = opStr;
|
|
35709
|
+
const field2 = fieldPathFromArgument("where", fieldPath);
|
|
35710
|
+
return QueryFieldFilterConstraint._create(field2, op, value);
|
|
35711
|
+
}
|
|
35712
|
+
class QueryCompositeFilterConstraint extends AppliableConstraint {
|
|
35713
|
+
/**
|
|
35714
|
+
* @internal
|
|
35715
|
+
*/
|
|
35716
|
+
constructor(type2, _queryConstraints) {
|
|
35717
|
+
super();
|
|
35718
|
+
this.type = type2;
|
|
35719
|
+
this._queryConstraints = _queryConstraints;
|
|
35720
|
+
}
|
|
35721
|
+
static _create(type2, _queryConstraints) {
|
|
35722
|
+
return new QueryCompositeFilterConstraint(type2, _queryConstraints);
|
|
35723
|
+
}
|
|
35724
|
+
_parse(query2) {
|
|
35725
|
+
const parsedFilters = this._queryConstraints.map((queryConstraint) => {
|
|
35726
|
+
return queryConstraint._parse(query2);
|
|
35727
|
+
}).filter((parsedFilter) => parsedFilter.getFilters().length > 0);
|
|
35728
|
+
if (parsedFilters.length === 1) {
|
|
35729
|
+
return parsedFilters[0];
|
|
35730
|
+
}
|
|
35731
|
+
return CompositeFilter.create(parsedFilters, this._getOperator());
|
|
35732
|
+
}
|
|
35733
|
+
_apply(query2) {
|
|
35734
|
+
const parsedFilter = this._parse(query2);
|
|
35735
|
+
if (parsedFilter.getFilters().length === 0) {
|
|
35736
|
+
return query2;
|
|
35737
|
+
}
|
|
35738
|
+
validateNewFilter(query2._query, parsedFilter);
|
|
35739
|
+
return new Query(query2.firestore, query2.converter, queryWithAddedFilter(query2._query, parsedFilter));
|
|
35740
|
+
}
|
|
35741
|
+
_getQueryConstraints() {
|
|
35742
|
+
return this._queryConstraints;
|
|
35743
|
+
}
|
|
35744
|
+
_getOperator() {
|
|
35745
|
+
return this.type === "and" ? "and" : "or";
|
|
35746
|
+
}
|
|
35747
|
+
}
|
|
35748
|
+
function newQueryFilter(query2, methodName, dataReader, databaseId, fieldPath, op, value) {
|
|
35749
|
+
let fieldValue;
|
|
35750
|
+
if (fieldPath.isKeyField()) {
|
|
35751
|
+
if (op === "array-contains" || op === "array-contains-any") {
|
|
35752
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid Query. You can't perform '${op}' queries on documentId().`);
|
|
35753
|
+
} else if (op === "in" || op === "not-in") {
|
|
35754
|
+
validateDisjunctiveFilterElements(value, op);
|
|
35755
|
+
const referenceList = [];
|
|
35756
|
+
for (const arrayValue of value) {
|
|
35757
|
+
referenceList.push(parseDocumentIdValue(databaseId, query2, arrayValue));
|
|
35758
|
+
}
|
|
35759
|
+
fieldValue = { arrayValue: { values: referenceList } };
|
|
35760
|
+
} else {
|
|
35761
|
+
fieldValue = parseDocumentIdValue(databaseId, query2, value);
|
|
35762
|
+
}
|
|
35763
|
+
} else {
|
|
35764
|
+
if (op === "in" || op === "not-in" || op === "array-contains-any") {
|
|
35765
|
+
validateDisjunctiveFilterElements(value, op);
|
|
35766
|
+
}
|
|
35767
|
+
fieldValue = parseQueryValue(
|
|
35768
|
+
dataReader,
|
|
35769
|
+
methodName,
|
|
35770
|
+
value,
|
|
35771
|
+
/* allowArrays= */
|
|
35772
|
+
op === "in" || op === "not-in"
|
|
35773
|
+
/* Operator.NOT_IN */
|
|
35774
|
+
);
|
|
35775
|
+
}
|
|
35776
|
+
const filter2 = FieldFilter.create(fieldPath, op, fieldValue);
|
|
35777
|
+
return filter2;
|
|
35778
|
+
}
|
|
35779
|
+
function parseDocumentIdValue(databaseId, query2, documentIdValue) {
|
|
35780
|
+
documentIdValue = getModularInstance(documentIdValue);
|
|
35781
|
+
if (typeof documentIdValue === "string") {
|
|
35782
|
+
if (documentIdValue === "") {
|
|
35783
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, "Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");
|
|
35784
|
+
}
|
|
35785
|
+
if (!isCollectionGroupQuery(query2) && documentIdValue.indexOf("/") !== -1) {
|
|
35786
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${documentIdValue}' contains a '/' character.`);
|
|
35787
|
+
}
|
|
35788
|
+
const path2 = query2.path.child(ResourcePath.fromString(documentIdValue));
|
|
35789
|
+
if (!DocumentKey.isDocumentKey(path2)) {
|
|
35790
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${path2}' is not because it has an odd number of segments (${path2.length}).`);
|
|
35791
|
+
}
|
|
35792
|
+
return refValue(databaseId, new DocumentKey(path2));
|
|
35793
|
+
} else if (documentIdValue instanceof DocumentReference) {
|
|
35794
|
+
return refValue(databaseId, documentIdValue._key);
|
|
35795
|
+
} else {
|
|
35796
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${valueDescription(documentIdValue)}.`);
|
|
35797
|
+
}
|
|
35798
|
+
}
|
|
35799
|
+
function validateDisjunctiveFilterElements(value, operator) {
|
|
35800
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
35801
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid Query. A non-empty array is required for '${operator.toString()}' filters.`);
|
|
35802
|
+
}
|
|
35803
|
+
}
|
|
35804
|
+
function conflictingOps(op) {
|
|
35805
|
+
switch (op) {
|
|
35806
|
+
case "!=":
|
|
35807
|
+
return [
|
|
35808
|
+
"!=",
|
|
35809
|
+
"not-in"
|
|
35810
|
+
/* Operator.NOT_IN */
|
|
35811
|
+
];
|
|
35812
|
+
case "array-contains-any":
|
|
35813
|
+
case "in":
|
|
35814
|
+
return [
|
|
35815
|
+
"not-in"
|
|
35816
|
+
/* Operator.NOT_IN */
|
|
35817
|
+
];
|
|
35818
|
+
case "not-in":
|
|
35819
|
+
return [
|
|
35820
|
+
"array-contains-any",
|
|
35821
|
+
"in",
|
|
35822
|
+
"not-in",
|
|
35823
|
+
"!="
|
|
35824
|
+
/* Operator.NOT_EQUAL */
|
|
35825
|
+
];
|
|
35826
|
+
default:
|
|
35827
|
+
return [];
|
|
35828
|
+
}
|
|
35829
|
+
}
|
|
35830
|
+
function validateNewFieldFilter(query2, fieldFilter) {
|
|
35831
|
+
const conflictingOp = findOpInsideFilters(query2.filters, conflictingOps(fieldFilter.op));
|
|
35832
|
+
if (conflictingOp !== null) {
|
|
35833
|
+
if (conflictingOp === fieldFilter.op) {
|
|
35834
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. You cannot use more than one '${fieldFilter.op.toString()}' filter.`);
|
|
35835
|
+
} else {
|
|
35836
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, `Invalid query. You cannot use '${fieldFilter.op.toString()}' filters with '${conflictingOp.toString()}' filters.`);
|
|
35837
|
+
}
|
|
35838
|
+
}
|
|
35839
|
+
}
|
|
35840
|
+
function validateNewFilter(query2, filter2) {
|
|
35841
|
+
let testQuery = query2;
|
|
35842
|
+
const subFilters = filter2.getFlattenedFilters();
|
|
35843
|
+
for (const subFilter of subFilters) {
|
|
35844
|
+
validateNewFieldFilter(testQuery, subFilter);
|
|
35845
|
+
testQuery = queryWithAddedFilter(testQuery, subFilter);
|
|
35846
|
+
}
|
|
35847
|
+
}
|
|
35848
|
+
function findOpInsideFilters(filters, operators) {
|
|
35849
|
+
for (const filter2 of filters) {
|
|
35850
|
+
for (const fieldFilter of filter2.getFlattenedFilters()) {
|
|
35851
|
+
if (operators.indexOf(fieldFilter.op) >= 0) {
|
|
35852
|
+
return fieldFilter.op;
|
|
35853
|
+
}
|
|
35854
|
+
}
|
|
35855
|
+
}
|
|
35856
|
+
return null;
|
|
35857
|
+
}
|
|
35858
|
+
function validateQueryConstraintArray(queryConstraint) {
|
|
35859
|
+
const compositeFilterCount = queryConstraint.filter((filter2) => filter2 instanceof QueryCompositeFilterConstraint).length;
|
|
35860
|
+
const fieldFilterCount = queryConstraint.filter((filter2) => filter2 instanceof QueryFieldFilterConstraint).length;
|
|
35861
|
+
if (compositeFilterCount > 1 || compositeFilterCount > 0 && fieldFilterCount > 0) {
|
|
35862
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, "InvalidQuery. When using composite filters, you cannot use more than one filter at the top level. Consider nesting the multiple filters within an `and(...)` statement. For example: change `query(query, where(...), or(...))` to `query(query, and(where(...), or(...)))`.");
|
|
35863
|
+
}
|
|
35864
|
+
}
|
|
35622
35865
|
/**
|
|
35623
35866
|
* @license
|
|
35624
35867
|
* Copyright 2020 Google LLC
|
|
@@ -36056,14 +36299,14 @@ function buildDocumentSnapshotJsonBundle(db, document, docData, path2) {
|
|
|
36056
36299
|
builder.addBundleDocument(documentToDocumentSnapshotBundleData(path2, docData, document));
|
|
36057
36300
|
return builder.build();
|
|
36058
36301
|
}
|
|
36059
|
-
function buildQuerySnapshotJsonBundle(db,
|
|
36302
|
+
function buildQuerySnapshotJsonBundle(db, query2, bundleName, parent, paths, docs, documentData) {
|
|
36060
36303
|
const docBundleDataArray = [];
|
|
36061
36304
|
for (let i = 0; i < docs.length; i++) {
|
|
36062
36305
|
docBundleDataArray.push(documentToDocumentSnapshotBundleData(paths[i], documentData[i], docs[i]));
|
|
36063
36306
|
}
|
|
36064
36307
|
const bundleData = {
|
|
36065
36308
|
name: bundleName,
|
|
36066
|
-
query,
|
|
36309
|
+
query: query2,
|
|
36067
36310
|
parent,
|
|
36068
36311
|
docBundleDataArray
|
|
36069
36312
|
};
|
|
@@ -36222,12 +36465,12 @@ class QueryDocumentSnapshot extends DocumentSnapshot {
|
|
|
36222
36465
|
}
|
|
36223
36466
|
class QuerySnapshot {
|
|
36224
36467
|
/** @hideconstructor */
|
|
36225
|
-
constructor(_firestore, _userDataWriter,
|
|
36468
|
+
constructor(_firestore, _userDataWriter, query2, _snapshot) {
|
|
36226
36469
|
this._firestore = _firestore;
|
|
36227
36470
|
this._userDataWriter = _userDataWriter;
|
|
36228
36471
|
this._snapshot = _snapshot;
|
|
36229
36472
|
this.metadata = new SnapshotMetadata(_snapshot.hasPendingWrites, _snapshot.fromCache);
|
|
36230
|
-
this.query =
|
|
36473
|
+
this.query = query2;
|
|
36231
36474
|
}
|
|
36232
36475
|
/** An array of all the documents in the `QuerySnapshot`. */
|
|
36233
36476
|
get docs() {
|
|
@@ -36406,13 +36649,13 @@ class ExpUserDataWriter extends AbstractUserDataWriter {
|
|
|
36406
36649
|
);
|
|
36407
36650
|
}
|
|
36408
36651
|
}
|
|
36409
|
-
function getDocs(
|
|
36410
|
-
|
|
36411
|
-
const firestore = cast(
|
|
36652
|
+
function getDocs(query2) {
|
|
36653
|
+
query2 = cast(query2, Query);
|
|
36654
|
+
const firestore = cast(query2.firestore, Firestore);
|
|
36412
36655
|
const client2 = ensureFirestoreConfigured(firestore);
|
|
36413
36656
|
const userDataWriter = new ExpUserDataWriter(firestore);
|
|
36414
|
-
validateHasExplicitOrderByForLimitToLast(
|
|
36415
|
-
return firestoreClientGetDocumentsViaSnapshotListener(client2,
|
|
36657
|
+
validateHasExplicitOrderByForLimitToLast(query2._query);
|
|
36658
|
+
return firestoreClientGetDocumentsViaSnapshotListener(client2, query2._query).then((snapshot) => new QuerySnapshot(firestore, userDataWriter, query2, snapshot));
|
|
36416
36659
|
}
|
|
36417
36660
|
function onSnapshot(reference, ...args) {
|
|
36418
36661
|
var _a, _b, _c;
|
|
@@ -36451,14 +36694,14 @@ function onSnapshot(reference, ...args) {
|
|
|
36451
36694
|
complete: args[currArg + 2]
|
|
36452
36695
|
};
|
|
36453
36696
|
} else {
|
|
36454
|
-
const
|
|
36455
|
-
firestore = cast(
|
|
36456
|
-
internalQuery =
|
|
36697
|
+
const query2 = cast(reference, Query);
|
|
36698
|
+
firestore = cast(query2.firestore, Firestore);
|
|
36699
|
+
internalQuery = query2._query;
|
|
36457
36700
|
const userDataWriter = new ExpUserDataWriter(firestore);
|
|
36458
36701
|
observer = {
|
|
36459
36702
|
next: (snapshot) => {
|
|
36460
36703
|
if (args[currArg]) {
|
|
36461
|
-
args[currArg](new QuerySnapshot(firestore, userDataWriter,
|
|
36704
|
+
args[currArg](new QuerySnapshot(firestore, userDataWriter, query2, snapshot));
|
|
36462
36705
|
}
|
|
36463
36706
|
},
|
|
36464
36707
|
error: args[currArg + 1],
|
|
@@ -36589,6 +36832,9 @@ function validateReference(documentRef, firestore) {
|
|
|
36589
36832
|
function deleteField() {
|
|
36590
36833
|
return new DeleteFieldValueImpl("deleteField");
|
|
36591
36834
|
}
|
|
36835
|
+
function serverTimestamp() {
|
|
36836
|
+
return new ServerTimestampFieldValueImpl("serverTimestamp");
|
|
36837
|
+
}
|
|
36592
36838
|
/**
|
|
36593
36839
|
* @license
|
|
36594
36840
|
* Copyright 2020 Google LLC
|
|
@@ -36697,16 +36943,48 @@ function createSdkFirebaseApi(options) {
|
|
|
36697
36943
|
resolve();
|
|
36698
36944
|
});
|
|
36699
36945
|
});
|
|
36946
|
+
let reads = 0;
|
|
36947
|
+
const billed = (n) => reads += Math.max(n, 1);
|
|
36948
|
+
const toDoc = (id, raw) => splitTs(id, fromFirestore(raw));
|
|
36949
|
+
const since = (name2, ms) => query(collection(db, name2), where(TS_FIELD, ">", Timestamp.fromMillis(ms)));
|
|
36950
|
+
const writeValue = (v) => v === DELETE_FIELD ? deleteField() : v === SERVER_TIMESTAMP ? serverTimestamp() : v;
|
|
36700
36951
|
return {
|
|
36701
36952
|
...options.storageBucket ? { storage: sdkStorage(app) } : {},
|
|
36953
|
+
readCount: () => reads,
|
|
36702
36954
|
async listCollection(name2) {
|
|
36703
36955
|
const snap = await getDocs(collection(db, name2));
|
|
36704
|
-
|
|
36956
|
+
billed(snap.size);
|
|
36957
|
+
return snap.docs.map((d) => toDoc(d.id, d.data()));
|
|
36958
|
+
},
|
|
36959
|
+
async listSince(name2, ms) {
|
|
36960
|
+
const snap = await getDocs(since(name2, ms));
|
|
36961
|
+
billed(snap.size);
|
|
36962
|
+
return snap.docs.map((d) => toDoc(d.id, d.data()));
|
|
36705
36963
|
},
|
|
36706
36964
|
watchCollection(name2, onDocs, onError) {
|
|
36707
36965
|
return onSnapshot(
|
|
36708
36966
|
collection(db, name2),
|
|
36709
|
-
(snap) =>
|
|
36967
|
+
(snap) => {
|
|
36968
|
+
if (!snap.metadata.fromCache) billed(snap.docChanges().length);
|
|
36969
|
+
onDocs(snap.docs.map((d) => toDoc(d.id, d.data())));
|
|
36970
|
+
},
|
|
36971
|
+
onError
|
|
36972
|
+
);
|
|
36973
|
+
},
|
|
36974
|
+
watchSince(name2, ms, onChanges, onError) {
|
|
36975
|
+
return onSnapshot(
|
|
36976
|
+
since(name2, ms),
|
|
36977
|
+
(snap) => {
|
|
36978
|
+
if (!snap.metadata.fromCache) billed(snap.docChanges().length);
|
|
36979
|
+
const upserts = [];
|
|
36980
|
+
const removed = [];
|
|
36981
|
+
for (const ch of snap.docChanges()) {
|
|
36982
|
+
if (ch.doc.metadata.hasPendingWrites) continue;
|
|
36983
|
+
if (ch.type === "removed") removed.push(ch.doc.id);
|
|
36984
|
+
else upserts.push(toDoc(ch.doc.id, ch.doc.data()));
|
|
36985
|
+
}
|
|
36986
|
+
if (upserts.length || removed.length) onChanges({ upserts, removed });
|
|
36987
|
+
},
|
|
36710
36988
|
onError
|
|
36711
36989
|
);
|
|
36712
36990
|
},
|
|
@@ -36716,15 +36994,16 @@ function createSdkFirebaseApi(options) {
|
|
|
36716
36994
|
},
|
|
36717
36995
|
async commit(ops) {
|
|
36718
36996
|
const batch = writeBatch(db);
|
|
36719
|
-
for (const op of ops) {
|
|
36997
|
+
for (const op of withChangeTracking(ops)) {
|
|
36720
36998
|
const ref = doc(db, op.collection, op.id);
|
|
36721
|
-
if (op.type === "
|
|
36722
|
-
|
|
36723
|
-
|
|
36724
|
-
const data = {};
|
|
36725
|
-
for (const [k, v] of Object.entries(op.data)) data[k] = v === DELETE_FIELD ? deleteField() : v;
|
|
36726
|
-
batch.update(ref, data);
|
|
36999
|
+
if (op.type === "delete") {
|
|
37000
|
+
batch.delete(ref);
|
|
37001
|
+
continue;
|
|
36727
37002
|
}
|
|
37003
|
+
const data = {};
|
|
37004
|
+
for (const [k, v] of Object.entries(op.data)) data[k] = writeValue(v);
|
|
37005
|
+
if (op.type === "set") batch.set(ref, data);
|
|
37006
|
+
else batch.update(ref, data);
|
|
36728
37007
|
}
|
|
36729
37008
|
await batch.commit();
|
|
36730
37009
|
},
|