@firebase/firestore 3.7.3 → 3.8.0-canary.06dc1364d

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.
Files changed (124) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/firestore/lite/index.d.ts +1 -1
  3. package/dist/firestore/src/api/filter.d.ts +1 -1
  4. package/dist/firestore/src/api/reference_impl.d.ts +2 -1
  5. package/dist/firestore/src/api.d.ts +1 -1
  6. package/dist/firestore/src/core/bound.d.ts +49 -0
  7. package/dist/firestore/src/core/filter.d.ts +134 -0
  8. package/dist/firestore/src/core/order_by.d.ts +35 -0
  9. package/dist/firestore/src/core/query.d.ts +5 -6
  10. package/dist/firestore/src/core/target.d.ts +4 -120
  11. package/dist/firestore/src/lite-api/query.d.ts +275 -66
  12. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
  13. package/dist/firestore/src/local/local_documents_view.d.ts +0 -2
  14. package/dist/firestore/src/model/document.d.ts +8 -1
  15. package/dist/firestore/src/protos/firestore_proto_api.d.ts +1 -1
  16. package/dist/firestore/src/remote/serializer.d.ts +10 -3
  17. package/dist/firestore/src/util/logic_utils.d.ts +52 -0
  18. package/dist/firestore/src/util/types.d.ts +1 -1
  19. package/dist/firestore/test/lite/helpers.d.ts +1 -1
  20. package/dist/firestore/test/unit/core/filter.test.d.ts +17 -0
  21. package/dist/firestore/test/unit/specs/spec_test_runner.d.ts +2 -1
  22. package/dist/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
  23. package/dist/firestore/test/util/helpers.d.ts +6 -2
  24. package/dist/firestore/test/util/test_platform.d.ts +2 -2
  25. package/dist/index.d.ts +140 -63
  26. package/dist/index.esm2017.js +4307 -3743
  27. package/dist/index.esm2017.js.map +1 -1
  28. package/dist/index.esm5.js +4994 -4410
  29. package/dist/index.esm5.js.map +1 -1
  30. package/dist/index.node.cjs.js +1670 -890
  31. package/dist/index.node.cjs.js.map +1 -1
  32. package/dist/index.node.mjs +1663 -891
  33. package/dist/index.node.mjs.map +1 -1
  34. package/dist/index.rn.js +4532 -3968
  35. package/dist/index.rn.js.map +1 -1
  36. package/dist/internal.d.ts +332 -69
  37. package/dist/lite/firestore/lite/index.d.ts +1 -1
  38. package/dist/lite/firestore/src/api/filter.d.ts +1 -1
  39. package/dist/lite/firestore/src/api/reference_impl.d.ts +2 -1
  40. package/dist/lite/firestore/src/api.d.ts +1 -1
  41. package/dist/lite/firestore/src/core/bound.d.ts +49 -0
  42. package/dist/lite/firestore/src/core/filter.d.ts +134 -0
  43. package/dist/lite/firestore/src/core/order_by.d.ts +35 -0
  44. package/dist/lite/firestore/src/core/query.d.ts +5 -6
  45. package/dist/lite/firestore/src/core/target.d.ts +4 -120
  46. package/dist/lite/firestore/src/lite-api/query.d.ts +275 -66
  47. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
  48. package/dist/lite/firestore/src/local/local_documents_view.d.ts +0 -2
  49. package/dist/lite/firestore/src/model/document.d.ts +8 -1
  50. package/dist/lite/firestore/src/protos/firestore_proto_api.d.ts +1 -1
  51. package/dist/lite/firestore/src/remote/serializer.d.ts +10 -3
  52. package/dist/lite/firestore/src/util/logic_utils.d.ts +52 -0
  53. package/dist/lite/firestore/src/util/types.d.ts +1 -1
  54. package/dist/lite/firestore/test/lite/helpers.d.ts +1 -1
  55. package/dist/lite/firestore/test/unit/core/filter.test.d.ts +17 -0
  56. package/dist/lite/firestore/test/unit/specs/spec_test_runner.d.ts +2 -1
  57. package/dist/lite/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
  58. package/dist/lite/firestore/test/util/helpers.d.ts +6 -2
  59. package/dist/lite/firestore/test/util/test_platform.d.ts +2 -2
  60. package/dist/lite/index.browser.esm2017.js +2093 -1793
  61. package/dist/lite/index.browser.esm2017.js.map +1 -1
  62. package/dist/lite/index.browser.esm5.js +2241 -2000
  63. package/dist/lite/index.browser.esm5.js.map +1 -1
  64. package/dist/lite/index.d.ts +138 -62
  65. package/dist/lite/index.node.cjs.js +2214 -1802
  66. package/dist/lite/index.node.cjs.js.map +1 -1
  67. package/dist/lite/index.node.mjs +2207 -1803
  68. package/dist/lite/index.node.mjs.map +1 -1
  69. package/dist/lite/index.rn.esm2017.js +2079 -1778
  70. package/dist/lite/index.rn.esm2017.js.map +1 -1
  71. package/dist/lite/internal.d.ts +330 -66
  72. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +324 -174
  73. package/dist/lite/packages/firestore/lite/index.d.ts +1 -1
  74. package/dist/lite/packages/firestore/rollup.config.debug.d.ts +1 -1
  75. package/dist/lite/packages/firestore/src/api/filter.d.ts +1 -1
  76. package/dist/lite/packages/firestore/src/api/reference_impl.d.ts +2 -1
  77. package/dist/lite/packages/firestore/src/api.d.ts +1 -1
  78. package/dist/lite/packages/firestore/src/core/bound.d.ts +49 -0
  79. package/dist/lite/packages/firestore/src/core/filter.d.ts +134 -0
  80. package/dist/lite/packages/firestore/src/core/order_by.d.ts +35 -0
  81. package/dist/lite/packages/firestore/src/core/query.d.ts +5 -6
  82. package/dist/lite/packages/firestore/src/core/target.d.ts +4 -120
  83. package/dist/lite/packages/firestore/src/lite-api/query.d.ts +275 -66
  84. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
  85. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +0 -2
  86. package/dist/lite/packages/firestore/src/model/document.d.ts +8 -1
  87. package/dist/lite/packages/firestore/src/protos/firestore_proto_api.d.ts +1 -1
  88. package/dist/lite/packages/firestore/src/remote/serializer.d.ts +10 -3
  89. package/dist/lite/packages/firestore/src/util/logic_utils.d.ts +52 -0
  90. package/dist/lite/packages/firestore/src/util/types.d.ts +1 -1
  91. package/dist/lite/packages/firestore/test/lite/helpers.d.ts +1 -1
  92. package/dist/lite/packages/firestore/test/unit/core/filter.test.d.ts +17 -0
  93. package/dist/lite/packages/firestore/test/unit/specs/spec_test_runner.d.ts +2 -1
  94. package/dist/lite/packages/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
  95. package/dist/lite/packages/firestore/test/util/helpers.d.ts +6 -2
  96. package/dist/lite/packages/firestore/test/util/test_platform.d.ts +2 -2
  97. package/dist/lite/private.d.ts +240 -66
  98. package/dist/packages/firestore/dist/index.esm2017.d.ts +373 -210
  99. package/dist/packages/firestore/lite/index.d.ts +1 -1
  100. package/dist/packages/firestore/rollup.config.debug.d.ts +1 -1
  101. package/dist/packages/firestore/src/api/filter.d.ts +1 -1
  102. package/dist/packages/firestore/src/api/reference_impl.d.ts +2 -1
  103. package/dist/packages/firestore/src/api.d.ts +1 -1
  104. package/dist/packages/firestore/src/core/bound.d.ts +49 -0
  105. package/dist/packages/firestore/src/core/filter.d.ts +134 -0
  106. package/dist/packages/firestore/src/core/order_by.d.ts +35 -0
  107. package/dist/packages/firestore/src/core/query.d.ts +5 -6
  108. package/dist/packages/firestore/src/core/target.d.ts +4 -120
  109. package/dist/packages/firestore/src/lite-api/query.d.ts +275 -66
  110. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +2 -0
  111. package/dist/packages/firestore/src/local/local_documents_view.d.ts +0 -2
  112. package/dist/packages/firestore/src/model/document.d.ts +8 -1
  113. package/dist/packages/firestore/src/protos/firestore_proto_api.d.ts +1 -1
  114. package/dist/packages/firestore/src/remote/serializer.d.ts +10 -3
  115. package/dist/packages/firestore/src/util/logic_utils.d.ts +52 -0
  116. package/dist/packages/firestore/src/util/types.d.ts +1 -1
  117. package/dist/packages/firestore/test/lite/helpers.d.ts +1 -1
  118. package/dist/packages/firestore/test/unit/core/filter.test.d.ts +17 -0
  119. package/dist/packages/firestore/test/unit/specs/spec_test_runner.d.ts +2 -1
  120. package/dist/packages/firestore/test/unit/util/logic_utils.test.d.ts +17 -0
  121. package/dist/packages/firestore/test/util/helpers.d.ts +6 -2
  122. package/dist/packages/firestore/test/util/test_platform.d.ts +2 -2
  123. package/dist/private.d.ts +242 -69
  124. package/package.json +14 -12
@@ -14,9 +14,11 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { Bound } from '../core/bound';
17
18
  import { DatabaseId } from '../core/database_info';
18
- import { Query as InternalQuery } from '../core/query';
19
- import { Bound, Direction, FieldFilter, Operator, OrderBy } from '../core/target';
19
+ import { CompositeOperator, FieldFilter, Filter, Operator } from '../core/filter';
20
+ import { Direction, OrderBy } from '../core/order_by';
21
+ import { LimitType, Query as InternalQuery } from '../core/query';
20
22
  import { Document } from '../model/document';
21
23
  import { FieldPath as InternalFieldPath } from '../model/path';
22
24
  import { FieldPath } from './field_path';
@@ -26,33 +28,82 @@ import { UserDataReader } from './user_data_reader';
26
28
  export declare function validateHasExplicitOrderByForLimitToLast(query: InternalQuery): void;
27
29
  /** Describes the different query constraints available in this SDK. */
28
30
  export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';
31
+ /**
32
+ * An `AppliableConstraint` is an abstraction of a constraint that can be applied
33
+ * to a Firestore query.
34
+ */
35
+ export declare abstract class AppliableConstraint {
36
+ /**
37
+ * Takes the provided {@link Query} and returns a copy of the {@link Query} with this
38
+ * {@link AppliableConstraint} applied.
39
+ */
40
+ abstract _apply<T>(query: Query<T>): Query<T>;
41
+ }
29
42
  /**
30
43
  * A `QueryConstraint` is used to narrow the set of documents returned by a
31
44
  * Firestore query. `QueryConstraint`s are created by invoking {@link where},
32
- * {@link orderBy}, {@link (startAt:1)}, {@link (startAfter:1)}, {@link
33
- * endBefore:1}, {@link (endAt:1)}, {@link limit} or {@link limitToLast} and
45
+ * {@link orderBy}, {@link startAt}, {@link startAfter}, {@link
46
+ * endBefore}, {@link endAt}, {@link limit}, {@link limitToLast} and
34
47
  * can then be passed to {@link query} to create a new query instance that
35
48
  * also contains this `QueryConstraint`.
36
49
  */
37
- export declare abstract class QueryConstraint {
38
- /** The type of this query constraints */
50
+ export declare abstract class QueryConstraint extends AppliableConstraint {
51
+ /** The type of this query constraint */
39
52
  abstract readonly type: QueryConstraintType;
40
53
  /**
41
54
  * Takes the provided {@link Query} and returns a copy of the {@link Query} with this
42
- * {@link QueryConstraint} applied.
55
+ * {@link AppliableConstraint} applied.
43
56
  */
44
57
  abstract _apply<T>(query: Query<T>): Query<T>;
45
58
  }
46
59
  /**
47
- * Creates a new immutable instance of {@link Query} that is extended to also include
48
- * additional query constraints.
60
+ * Creates a new immutable instance of {@link Query} that is extended to also
61
+ * include additional query constraints.
62
+ *
63
+ * @param query - The {@link Query} instance to use as a base for the new
64
+ * constraints.
65
+ * @param compositeFilter - The {@link QueryCompositeFilterConstraint} to
66
+ * apply. Create {@link QueryCompositeFilterConstraint} using {@link and} or
67
+ * {@link or}.
68
+ * @param queryConstraints - Additional {@link QueryNonFilterConstraint}s to
69
+ * apply (e.g. {@link orderBy}, {@link limit}).
70
+ * @throws if any of the provided query constraints cannot be combined with the
71
+ * existing or new constraints.
72
+ * @internal TODO remove this internal tag with OR Query support in the server
73
+ */
74
+ export declare function query<T>(query: Query<T>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<T>;
75
+ /**
76
+ * Creates a new immutable instance of {@link Query} that is extended to also
77
+ * include additional query constraints.
49
78
  *
50
- * @param query - The {@link Query} instance to use as a base for the new constraints.
79
+ * @param query - The {@link Query} instance to use as a base for the new
80
+ * constraints.
51
81
  * @param queryConstraints - The list of {@link QueryConstraint}s to apply.
52
82
  * @throws if any of the provided query constraints cannot be combined with the
53
83
  * existing or new constraints.
54
84
  */
55
85
  export declare function query<T>(query: Query<T>, ...queryConstraints: QueryConstraint[]): Query<T>;
86
+ /**
87
+ * A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
88
+ * a Firestore query by filtering on one or more document fields.
89
+ * `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
90
+ * be passed to {@link query} to create a new query instance that also contains
91
+ * this `QueryFieldFilterConstraint`.
92
+ */
93
+ export declare class QueryFieldFilterConstraint extends QueryConstraint {
94
+ private readonly _field;
95
+ private _op;
96
+ private _value;
97
+ /** The type of this query constraint */
98
+ readonly type = "where";
99
+ /**
100
+ * @internal
101
+ */
102
+ protected constructor(_field: InternalFieldPath, _op: Operator, _value: unknown);
103
+ static _create(_field: InternalFieldPath, _op: Operator, _value: unknown): QueryFieldFilterConstraint;
104
+ _apply<T>(query: Query<T>): Query<T>;
105
+ _parse<T>(query: Query<T>): FieldFilter;
106
+ }
56
107
  /**
57
108
  * Filter conditions in a {@link where} clause are specified using the
58
109
  * strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in',
@@ -60,129 +111,286 @@ export declare function query<T>(query: Query<T>, ...queryConstraints: QueryCons
60
111
  */
61
112
  export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';
62
113
  /**
63
- * Creates a {@link QueryConstraint} that enforces that documents must contain the
64
- * specified field and that the value should satisfy the relation constraint
65
- * provided.
114
+ * Creates a {@link QueryFieldFilterConstraint} that enforces that documents
115
+ * must contain the specified field and that the value should satisfy the
116
+ * relation constraint provided.
66
117
  *
67
118
  * @param fieldPath - The path to compare
68
119
  * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
69
120
  * "&lt;=", "!=").
70
121
  * @param value - The value for comparison
71
- * @returns The created {@link Query}.
122
+ * @returns The created {@link QueryFieldFilterConstraint}.
123
+ */
124
+ export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;
125
+ /**
126
+ * A `QueryCompositeFilterConstraint` is used to narrow the set of documents
127
+ * returned by a Firestore query by performing the logical OR or AND of multiple
128
+ * {@link QueryFieldFilterConstraint}s or {@link QueryCompositeFilterConstraint}s.
129
+ * `QueryCompositeFilterConstraint`s are created by invoking {@link or} or
130
+ * {@link and} and can then be passed to {@link query} to create a new query
131
+ * instance that also contains the `QueryCompositeFilterConstraint`.
132
+ * @internal TODO remove this internal tag with OR Query support in the server
133
+ */
134
+ export declare class QueryCompositeFilterConstraint extends AppliableConstraint {
135
+ /** The type of this query constraint */
136
+ readonly type: 'or' | 'and';
137
+ private readonly _queryConstraints;
138
+ /**
139
+ * @internal
140
+ */
141
+ protected constructor(
142
+ /** The type of this query constraint */
143
+ type: 'or' | 'and', _queryConstraints: QueryFilterConstraint[]);
144
+ static _create(type: 'or' | 'and', _queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
145
+ _parse<T>(query: Query<T>): Filter;
146
+ _apply<T>(query: Query<T>): Query<T>;
147
+ _getQueryConstraints(): readonly AppliableConstraint[];
148
+ _getOperator(): CompositeOperator;
149
+ }
150
+ /**
151
+ * `QueryNonFilterConstraint` is a helper union type that represents
152
+ * QueryConstraints which are used to narrow or order the set of documents,
153
+ * but that do not explicitly filter on a document field.
154
+ * `QueryNonFilterConstraint`s are created by invoking {@link orderBy},
155
+ * {@link startAt}, {@link startAfter}, {@link endBefore}, {@link endAt},
156
+ * {@link limit} or {@link limitToLast} and can then be passed to {@link query}
157
+ * to create a new query instance that also contains the `QueryConstraint`.
158
+ */
159
+ export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;
160
+ /**
161
+ * `QueryFilterConstraint` is a helper union type that represents
162
+ * {@link QueryFieldFilterConstraint} and {@link QueryCompositeFilterConstraint}.
163
+ * `QueryFilterConstraint`s are created by invoking {@link or} or {@link and}
164
+ * and can then be passed to {@link query} to create a new query instance that
165
+ * also contains the `QueryConstraint`.
166
+ * @internal TODO remove this internal tag with OR Query support in the server
167
+ */
168
+ export declare type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;
169
+ /**
170
+ * Creates a new {@link QueryCompositeFilterConstraint} that is a disjunction of
171
+ * the given filter constraints. A disjunction filter includes a document if it
172
+ * satisfies any of the given filters.
173
+ *
174
+ * @param queryConstraints - Optional. The list of
175
+ * {@link QueryFilterConstraint}s to perform a disjunction for. These must be
176
+ * created with calls to {@link where}, {@link or}, or {@link and}.
177
+ * @returns The newly created {@link QueryCompositeFilterConstraint}.
178
+ * @internal TODO remove this internal tag with OR Query support in the server
179
+ */
180
+ export declare function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
181
+ /**
182
+ * Creates a new {@link QueryCompositeFilterConstraint} that is a conjunction of
183
+ * the given filter constraints. A conjunction filter includes a document if it
184
+ * satisfies all of the given filters.
185
+ *
186
+ * @param queryConstraints - Optional. The list of
187
+ * {@link QueryFilterConstraint}s to perform a conjunction for. These must be
188
+ * created with calls to {@link where}, {@link or}, or {@link and}.
189
+ * @returns The newly created {@link QueryCompositeFilterConstraint}.
190
+ * @internal TODO remove this internal tag with OR Query support in the server
191
+ */
192
+ export declare function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;
193
+ /**
194
+ * A `QueryOrderByConstraint` is used to sort the set of documents returned by a
195
+ * Firestore query. `QueryOrderByConstraint`s are created by invoking
196
+ * {@link orderBy} and can then be passed to {@link query} to create a new query
197
+ * instance that also contains this `QueryOrderByConstraint`.
198
+ *
199
+ * Note: Documents that do not contain the orderBy field will not be present in
200
+ * the query result.
72
201
  */
73
- export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryConstraint;
202
+ export declare class QueryOrderByConstraint extends QueryConstraint {
203
+ private readonly _field;
204
+ private _direction;
205
+ /** The type of this query constraint */
206
+ readonly type = "orderBy";
207
+ /**
208
+ * @internal
209
+ */
210
+ protected constructor(_field: InternalFieldPath, _direction: Direction);
211
+ static _create(_field: InternalFieldPath, _direction: Direction): QueryOrderByConstraint;
212
+ _apply<T>(query: Query<T>): Query<T>;
213
+ }
74
214
  /**
75
215
  * The direction of a {@link orderBy} clause is specified as 'desc' or 'asc'
76
216
  * (descending or ascending).
77
217
  */
78
218
  export declare type OrderByDirection = 'desc' | 'asc';
79
219
  /**
80
- * Creates a {@link QueryConstraint} that sorts the query result by the
220
+ * Creates a {@link QueryOrderByConstraint} that sorts the query result by the
81
221
  * specified field, optionally in descending order instead of ascending.
82
222
  *
223
+ * Note: Documents that do not contain the specified field will not be present
224
+ * in the query result.
225
+ *
83
226
  * @param fieldPath - The field to sort by.
84
227
  * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
85
228
  * not specified, order will be ascending.
86
- * @returns The created {@link Query}.
229
+ * @returns The created {@link QueryOrderByConstraint}.
87
230
  */
88
- export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryConstraint;
231
+ export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;
89
232
  /**
90
- * Creates a {@link QueryConstraint} that only returns the first matching documents.
233
+ * A `QueryLimitConstraint` is used to limit the number of documents returned by
234
+ * a Firestore query.
235
+ * `QueryLimitConstraint`s are created by invoking {@link limit} or
236
+ * {@link limitToLast} and can then be passed to {@link query} to create a new
237
+ * query instance that also contains this `QueryLimitConstraint`.
238
+ */
239
+ export declare class QueryLimitConstraint extends QueryConstraint {
240
+ /** The type of this query constraint */
241
+ readonly type: 'limit' | 'limitToLast';
242
+ private readonly _limit;
243
+ private readonly _limitType;
244
+ /**
245
+ * @internal
246
+ */
247
+ protected constructor(
248
+ /** The type of this query constraint */
249
+ type: 'limit' | 'limitToLast', _limit: number, _limitType: LimitType);
250
+ static _create(type: 'limit' | 'limitToLast', _limit: number, _limitType: LimitType): QueryLimitConstraint;
251
+ _apply<T>(query: Query<T>): Query<T>;
252
+ }
253
+ /**
254
+ * Creates a {@link QueryLimitConstraint} that only returns the first matching
255
+ * documents.
91
256
  *
92
257
  * @param limit - The maximum number of items to return.
93
- * @returns The created {@link Query}.
258
+ * @returns The created {@link QueryLimitConstraint}.
94
259
  */
95
- export declare function limit(limit: number): QueryConstraint;
260
+ export declare function limit(limit: number): QueryLimitConstraint;
96
261
  /**
97
- * Creates a {@link QueryConstraint} that only returns the last matching documents.
262
+ * Creates a {@link QueryLimitConstraint} that only returns the last matching
263
+ * documents.
98
264
  *
99
265
  * You must specify at least one `orderBy` clause for `limitToLast` queries,
100
266
  * otherwise an exception will be thrown during execution.
101
267
  *
102
268
  * @param limit - The maximum number of items to return.
103
- * @returns The created {@link Query}.
269
+ * @returns The created {@link QueryLimitConstraint}.
104
270
  */
105
- export declare function limitToLast(limit: number): QueryConstraint;
271
+ export declare function limitToLast(limit: number): QueryLimitConstraint;
106
272
  /**
107
- * Creates a {@link QueryConstraint} that modifies the result set to start at the
108
- * provided document (inclusive). The starting position is relative to the order
109
- * of the query. The document must contain all of the fields provided in the
110
- * `orderBy` of this query.
273
+ * A `QueryStartAtConstraint` is used to exclude documents from the start of a
274
+ * result set returned by a Firestore query.
275
+ * `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
276
+ * {@link (startAfter:1)} and can then be passed to {@link query} to create a
277
+ * new query instance that also contains this `QueryStartAtConstraint`.
278
+ */
279
+ export declare class QueryStartAtConstraint extends QueryConstraint {
280
+ /** The type of this query constraint */
281
+ readonly type: 'startAt' | 'startAfter';
282
+ private readonly _docOrFields;
283
+ private readonly _inclusive;
284
+ /**
285
+ * @internal
286
+ */
287
+ protected constructor(
288
+ /** The type of this query constraint */
289
+ type: 'startAt' | 'startAfter', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean);
290
+ static _create(type: 'startAt' | 'startAfter', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean): QueryStartAtConstraint;
291
+ _apply<T>(query: Query<T>): Query<T>;
292
+ }
293
+ /**
294
+ * Creates a {@link QueryStartAtConstraint} that modifies the result set to
295
+ * start at the provided document (inclusive). The starting position is relative
296
+ * to the order of the query. The document must contain all of the fields
297
+ * provided in the `orderBy` of this query.
111
298
  *
112
299
  * @param snapshot - The snapshot of the document to start at.
113
- * @returns A {@link QueryConstraint} to pass to `query()`.
300
+ * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
114
301
  */
115
- export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
302
+ export declare function startAt(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
116
303
  /**
117
- * Creates a {@link QueryConstraint} that modifies the result set to start at the
118
- * provided fields relative to the order of the query. The order of the field
119
- * values must match the order of the order by clauses of the query.
304
+ * Creates a {@link QueryStartAtConstraint} that modifies the result set to
305
+ * start at the provided fields relative to the order of the query. The order of
306
+ * the field values must match the order of the order by clauses of the query.
120
307
  *
121
308
  * @param fieldValues - The field values to start this query at, in order
122
309
  * of the query's order by.
123
- * @returns A {@link QueryConstraint} to pass to `query()`.
310
+ * @returns A {@link QueryStartAtConstraint} to pass to `query()`.
124
311
  */
125
- export declare function startAt(...fieldValues: unknown[]): QueryConstraint;
312
+ export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;
126
313
  /**
127
- * Creates a {@link QueryConstraint} that modifies the result set to start after the
128
- * provided document (exclusive). The starting position is relative to the order
129
- * of the query. The document must contain all of the fields provided in the
130
- * orderBy of the query.
314
+ * Creates a {@link QueryStartAtConstraint} that modifies the result set to
315
+ * start after the provided document (exclusive). The starting position is
316
+ * relative to the order of the query. The document must contain all of the
317
+ * fields provided in the orderBy of the query.
131
318
  *
132
319
  * @param snapshot - The snapshot of the document to start after.
133
- * @returns A {@link QueryConstraint} to pass to `query()`
320
+ * @returns A {@link QueryStartAtConstraint} to pass to `query()`
134
321
  */
135
- export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
322
+ export declare function startAfter(snapshot: DocumentSnapshot<unknown>): QueryStartAtConstraint;
136
323
  /**
137
- * Creates a {@link QueryConstraint} that modifies the result set to start after the
138
- * provided fields relative to the order of the query. The order of the field
139
- * values must match the order of the order by clauses of the query.
324
+ * Creates a {@link QueryStartAtConstraint} that modifies the result set to
325
+ * start after the provided fields relative to the order of the query. The order
326
+ * of the field values must match the order of the order by clauses of the query.
140
327
  *
141
328
  * @param fieldValues - The field values to start this query after, in order
142
329
  * of the query's order by.
143
- * @returns A {@link QueryConstraint} to pass to `query()`
330
+ * @returns A {@link QueryStartAtConstraint} to pass to `query()`
144
331
  */
145
- export declare function startAfter(...fieldValues: unknown[]): QueryConstraint;
332
+ export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;
146
333
  /**
147
- * Creates a {@link QueryConstraint} that modifies the result set to end before the
148
- * provided document (exclusive). The end position is relative to the order of
149
- * the query. The document must contain all of the fields provided in the
150
- * orderBy of the query.
334
+ * A `QueryEndAtConstraint` is used to exclude documents from the end of a
335
+ * result set returned by a Firestore query.
336
+ * `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
337
+ * {@link (endBefore:1)} and can then be passed to {@link query} to create a new
338
+ * query instance that also contains this `QueryEndAtConstraint`.
339
+ */
340
+ export declare class QueryEndAtConstraint extends QueryConstraint {
341
+ /** The type of this query constraint */
342
+ readonly type: 'endBefore' | 'endAt';
343
+ private readonly _docOrFields;
344
+ private readonly _inclusive;
345
+ /**
346
+ * @internal
347
+ */
348
+ protected constructor(
349
+ /** The type of this query constraint */
350
+ type: 'endBefore' | 'endAt', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean);
351
+ static _create(type: 'endBefore' | 'endAt', _docOrFields: Array<unknown | DocumentSnapshot<unknown>>, _inclusive: boolean): QueryEndAtConstraint;
352
+ _apply<T>(query: Query<T>): Query<T>;
353
+ }
354
+ /**
355
+ * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
356
+ * before the provided document (exclusive). The end position is relative to the
357
+ * order of the query. The document must contain all of the fields provided in
358
+ * the orderBy of the query.
151
359
  *
152
360
  * @param snapshot - The snapshot of the document to end before.
153
- * @returns A {@link QueryConstraint} to pass to `query()`
361
+ * @returns A {@link QueryEndAtConstraint} to pass to `query()`
154
362
  */
155
- export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
363
+ export declare function endBefore(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
156
364
  /**
157
- * Creates a {@link QueryConstraint} that modifies the result set to end before the
158
- * provided fields relative to the order of the query. The order of the field
159
- * values must match the order of the order by clauses of the query.
365
+ * Creates a {@link QueryEndAtConstraint} that modifies the result set to end
366
+ * before the provided fields relative to the order of the query. The order of
367
+ * the field values must match the order of the order by clauses of the query.
160
368
  *
161
369
  * @param fieldValues - The field values to end this query before, in order
162
370
  * of the query's order by.
163
- * @returns A {@link QueryConstraint} to pass to `query()`
371
+ * @returns A {@link QueryEndAtConstraint} to pass to `query()`
164
372
  */
165
- export declare function endBefore(...fieldValues: unknown[]): QueryConstraint;
373
+ export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;
166
374
  /**
167
- * Creates a {@link QueryConstraint} that modifies the result set to end at the
168
- * provided document (inclusive). The end position is relative to the order of
169
- * the query. The document must contain all of the fields provided in the
375
+ * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
376
+ * the provided document (inclusive). The end position is relative to the order
377
+ * of the query. The document must contain all of the fields provided in the
170
378
  * orderBy of the query.
171
379
  *
172
380
  * @param snapshot - The snapshot of the document to end at.
173
- * @returns A {@link QueryConstraint} to pass to `query()`
381
+ * @returns A {@link QueryEndAtConstraint} to pass to `query()`
174
382
  */
175
- export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryConstraint;
383
+ export declare function endAt(snapshot: DocumentSnapshot<unknown>): QueryEndAtConstraint;
176
384
  /**
177
- * Creates a {@link QueryConstraint} that modifies the result set to end at the
178
- * provided fields relative to the order of the query. The order of the field
385
+ * Creates a {@link QueryEndAtConstraint} that modifies the result set to end at
386
+ * the provided fields relative to the order of the query. The order of the field
179
387
  * values must match the order of the order by clauses of the query.
180
388
  *
181
389
  * @param fieldValues - The field values to end this query at, in order
182
390
  * of the query's order by.
183
- * @returns A {@link QueryConstraint} to pass to `query()`
391
+ * @returns A {@link QueryEndAtConstraint} to pass to `query()`
184
392
  */
185
- export declare function endAt(...fieldValues: unknown[]): QueryConstraint;
393
+ export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;
186
394
  export declare function newQueryFilter(query: InternalQuery, methodName: string, dataReader: UserDataReader, databaseId: DatabaseId, fieldPath: InternalFieldPath, op: Operator, value: unknown): FieldFilter;
187
395
  export declare function newQueryOrderBy(query: InternalQuery, fieldPath: InternalFieldPath, direction: Direction): OrderBy;
188
396
  /**
@@ -201,3 +409,4 @@ export declare function newQueryBoundFromDocument(query: InternalQuery, database
201
409
  * Converts a list of field values to a `Bound` for the given query.
202
410
  */
203
411
  export declare function newQueryBoundFromFields(query: InternalQuery, databaseId: DatabaseId, dataReader: UserDataReader, methodName: string, values: unknown[], inclusive: boolean): Bound;
412
+ export declare function validateQueryFilterConstraint(functionName: string, queryConstraint: AppliableConstraint): void;
@@ -17,6 +17,7 @@
17
17
  import { User } from '../auth/user';
18
18
  import { DatabaseId } from '../core/database_info';
19
19
  import { Target } from '../core/target';
20
+ import { IndexEntry } from '../index/index_entry';
20
21
  import { DocumentMap } from '../model/collections';
21
22
  import { DocumentKey } from '../model/document_key';
22
23
  import { FieldIndex, IndexOffset } from '../model/field_index';
@@ -128,6 +129,7 @@ export declare class IndexedDbIndexManager implements IndexManager {
128
129
  * '[foo > 2 && foo != 3]` becomes `[foo > 2 && < 3, foo > 3]`.
129
130
  */
130
131
  private createRange;
132
+ isRangeMatchable(lowerBound: IndexEntry, upperBound: IndexEntry): boolean;
131
133
  getMinOffsetFromCollectionGroup(transaction: PersistenceTransaction, collectionGroup: string): PersistencePromise<IndexOffset>;
132
134
  getMinOffset(transaction: PersistenceTransaction, target: Target): PersistencePromise<IndexOffset>;
133
135
  }
@@ -121,6 +121,4 @@ export declare class LocalDocumentsView {
121
121
  private getDocumentsMatchingDocumentQuery;
122
122
  private getDocumentsMatchingCollectionGroupQuery;
123
123
  private getDocumentsMatchingCollectionQuery;
124
- /** Returns a base document that can be used to apply `overlay`. */
125
- private getBaseDocument;
126
124
  }
@@ -35,6 +35,12 @@ export interface Document {
35
35
  * `SnapshotVersion.min()` for documents created by the user.
36
36
  */
37
37
  readonly readTime: SnapshotVersion;
38
+ /**
39
+ * The timestamp at which the document was created. This value increases
40
+ * monotonically when a document is deleted then recreated. It can also be
41
+ * compared to `createTime` of other documents and the `readTime` of a query.
42
+ */
43
+ readonly createTime: SnapshotVersion;
38
44
  /** The underlying data of this document or an empty value if no data exists. */
39
45
  readonly data: ObjectValue;
40
46
  /** Returns whether local mutations were applied via the mutation queue. */
@@ -85,6 +91,7 @@ export declare class MutableDocument implements Document {
85
91
  private documentType;
86
92
  version: SnapshotVersion;
87
93
  readTime: SnapshotVersion;
94
+ createTime: SnapshotVersion;
88
95
  data: ObjectValue;
89
96
  private documentState;
90
97
  private constructor();
@@ -97,7 +104,7 @@ export declare class MutableDocument implements Document {
97
104
  * Creates a new document that is known to exist with the given data at the
98
105
  * given version.
99
106
  */
100
- static newFoundDocument(documentKey: DocumentKey, version: SnapshotVersion, value: ObjectValue): MutableDocument;
107
+ static newFoundDocument(documentKey: DocumentKey, version: SnapshotVersion, createTime: SnapshotVersion, value: ObjectValue): MutableDocument;
101
108
  /** Creates a new document that is known to not exist at the given version. */
102
109
  static newNoDocument(documentKey: DocumentKey, version: SnapshotVersion): MutableDocument;
103
110
  /**
@@ -23,7 +23,7 @@ export declare type Timestamp = string | {
23
23
  seconds?: string | number;
24
24
  nanos?: number;
25
25
  };
26
- export declare type CompositeFilterOp = 'OPERATOR_UNSPECIFIED' | 'AND';
26
+ export declare type CompositeFilterOp = 'OPERATOR_UNSPECIFIED' | 'AND' | 'OR';
27
27
  export interface ICompositeFilterOpEnum {
28
28
  OPERATOR_UNSPECIFIED: CompositeFilterOp;
29
29
  AND: CompositeFilterOp;
@@ -15,9 +15,11 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { DatabaseId } from '../core/database_info';
18
+ import { CompositeFilter, CompositeOperator, FieldFilter, Filter, Operator } from '../core/filter';
19
+ import { Direction, OrderBy } from '../core/order_by';
18
20
  import { Query } from '../core/query';
19
21
  import { SnapshotVersion } from '../core/snapshot_version';
20
- import { Direction, FieldFilter, Filter, Operator, OrderBy, Target } from '../core/target';
22
+ import { Target } from '../core/target';
21
23
  import { Timestamp } from '../lite-api/timestamp';
22
24
  import { TargetData } from '../local/target_data';
23
25
  import { MutableDocument } from '../model/document';
@@ -26,7 +28,7 @@ import { FieldMask } from '../model/field_mask';
26
28
  import { Mutation, MutationResult } from '../model/mutation';
27
29
  import { ObjectValue } from '../model/object_value';
28
30
  import { FieldPath, ResourcePath } from '../model/path';
29
- import { ApiClientObjectMap as ProtoApiClientObjectMap, BatchGetDocumentsResponse as ProtoBatchGetDocumentsResponse, Document as ProtoDocument, DocumentMask as ProtoDocumentMask, DocumentsTarget as ProtoDocumentsTarget, FieldFilterOp as ProtoFieldFilterOp, FieldReference as ProtoFieldReference, Filter as ProtoFilter, ListenResponse as ProtoListenResponse, Order as ProtoOrder, OrderDirection as ProtoOrderDirection, QueryTarget as ProtoQueryTarget, RunAggregationQueryRequest as ProtoRunAggregationQueryRequest, Target as ProtoTarget, Timestamp as ProtoTimestamp, Write as ProtoWrite, WriteResult as ProtoWriteResult } from '../protos/firestore_proto_api';
31
+ import { ApiClientObjectMap as ProtoApiClientObjectMap, BatchGetDocumentsResponse as ProtoBatchGetDocumentsResponse, CompositeFilterOp as ProtoCompositeFilterOp, Document as ProtoDocument, DocumentMask as ProtoDocumentMask, DocumentsTarget as ProtoDocumentsTarget, FieldFilterOp as ProtoFieldFilterOp, FieldReference as ProtoFieldReference, Filter as ProtoFilter, ListenResponse as ProtoListenResponse, Order as ProtoOrder, OrderDirection as ProtoOrderDirection, QueryTarget as ProtoQueryTarget, RunAggregationQueryRequest as ProtoRunAggregationQueryRequest, Target as ProtoTarget, Timestamp as ProtoTimestamp, Write as ProtoWrite, WriteResult as ProtoWriteResult } from '../protos/firestore_proto_api';
30
32
  import { ByteString } from '../util/byte_string';
31
33
  import { Serializer } from './number_serializer';
32
34
  import { WatchChange } from './watch_change';
@@ -90,14 +92,19 @@ export declare function toTarget(serializer: JsonProtoSerializer, targetData: Ta
90
92
  export declare function toDirection(dir: Direction): ProtoOrderDirection;
91
93
  export declare function fromDirection(dir: ProtoOrderDirection | undefined): Direction | undefined;
92
94
  export declare function toOperatorName(op: Operator): ProtoFieldFilterOp;
95
+ export declare function toCompositeOperatorName(op: CompositeOperator): ProtoCompositeFilterOp;
93
96
  export declare function fromOperatorName(op: ProtoFieldFilterOp): Operator;
97
+ export declare function fromCompositeOperatorName(op: ProtoCompositeFilterOp): CompositeOperator;
94
98
  export declare function toFieldPathReference(path: FieldPath): ProtoFieldReference;
95
99
  export declare function fromFieldPathReference(fieldReference: ProtoFieldReference): FieldPath;
96
100
  export declare function toPropertyOrder(orderBy: OrderBy): ProtoOrder;
97
101
  export declare function fromPropertyOrder(orderBy: ProtoOrder): OrderBy;
98
- export declare function fromFieldFilter(filter: ProtoFilter): Filter;
102
+ export declare function toFilter(filter: Filter): ProtoFilter;
103
+ export declare function toCompositeFilter(filter: CompositeFilter): ProtoFilter;
99
104
  export declare function toUnaryOrFieldFilter(filter: FieldFilter): ProtoFilter;
100
105
  export declare function fromUnaryFilter(filter: ProtoFilter): Filter;
106
+ export declare function fromFieldFilter(filter: ProtoFilter): FieldFilter;
107
+ export declare function fromCompositeFilter(filter: ProtoFilter): CompositeFilter;
101
108
  export declare function toDocumentMask(fieldMask: FieldMask): ProtoDocumentMask;
102
109
  export declare function fromDocumentMask(proto: ProtoDocumentMask): FieldMask;
103
110
  export declare function isValidResourceName(path: ResourcePath): boolean;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { CompositeFilter, Filter } from '../core/filter';
18
+ /**
19
+ * Provides utility functions that help with boolean logic transformations needed for handling
20
+ * complex filters used in queries.
21
+ */
22
+ /**
23
+ * The `in` filter is only a syntactic sugar over a disjunction of equalities. For instance: `a in
24
+ * [1,2,3]` is in fact `a==1 || a==2 || a==3`. This method expands any `in` filter in the given
25
+ * input into a disjunction of equality filters and returns the expanded filter.
26
+ */
27
+ export declare function computeInExpansion(filter: Filter): Filter;
28
+ /**
29
+ * Given a composite filter, returns the list of terms in its disjunctive normal form.
30
+ *
31
+ * <p>Each element in the return value is one term of the resulting DNF. For instance: For the
32
+ * input: (A || B) && C, the DNF form is: (A && C) || (B && C), and the return value is a list
33
+ * with two elements: a composite filter that performs (A && C), and a composite filter that
34
+ * performs (B && C).
35
+ *
36
+ * @param filter the composite filter to calculate DNF transform for.
37
+ * @return the terms in the DNF transform.
38
+ */
39
+ export declare function getDnfTerms(filter: CompositeFilter): Filter[];
40
+ export declare function computeDistributedNormalForm(filter: Filter): Filter;
41
+ export declare function applyDistribution(lhs: Filter, rhs: Filter): Filter;
42
+ /**
43
+ * Applies the associativity property to the given filter and returns the resulting filter.
44
+ *
45
+ * <ul>
46
+ * <li>A | (B | C) == (A | B) | C == (A | B | C)
47
+ * <li>A & (B & C) == (A & B) & C == (A & B & C)
48
+ * </ul>
49
+ *
50
+ * <p>For more info, visit: https://en.wikipedia.org/wiki/Associative_property#Propositional_logic
51
+ */
52
+ export declare function applyAssociation(filter: Filter): Filter;
@@ -39,7 +39,7 @@ export interface WindowLike {
39
39
  }
40
40
  /** The subset of the browser's Document interface used by the SDK. */
41
41
  export interface DocumentLike {
42
- readonly visibilityState: VisibilityState;
42
+ readonly visibilityState: DocumentVisibilityState;
43
43
  addEventListener(type: string, listener: EventListener): void;
44
44
  removeEventListener(type: string, listener: EventListener): void;
45
45
  }
@@ -36,6 +36,6 @@ export declare const postConverter: {
36
36
  fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>): Post;
37
37
  };
38
38
  export declare const postConverterMerge: {
39
- toFirestore(post: PartialWithFieldValue<Post>, options?: SetOptions | undefined): DocumentData;
39
+ toFirestore(post: PartialWithFieldValue<Post>, options?: SetOptions): DocumentData;
40
40
  fromFirestore(snapshot: QueryDocumentSnapshot<DocumentData>): Post;
41
41
  };