@firebase/firestore 3.4.4 → 3.4.5-2022116201138

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 (213) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/firestore/src/api/credentials.d.ts +1 -0
  3. package/dist/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  4. package/dist/firestore/src/api/snapshot.d.ts +1 -2
  5. package/dist/firestore/src/api.d.ts +1 -1
  6. package/dist/firestore/src/core/database_info.d.ts +1 -0
  7. package/dist/firestore/src/core/target.d.ts +34 -5
  8. package/dist/firestore/src/index/index_byte_encoder.d.ts +18 -1
  9. package/dist/firestore/src/index/index_entry.d.ts +26 -0
  10. package/dist/firestore/src/lite-api/query.d.ts +2 -2
  11. package/dist/firestore/src/local/document_overlay_cache.d.ts +72 -0
  12. package/dist/firestore/src/local/index_manager.d.ts +52 -0
  13. package/dist/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  14. package/dist/firestore/src/local/indexeddb_index_manager.d.ts +40 -2
  15. package/dist/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  16. package/dist/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  17. package/dist/firestore/src/local/indexeddb_schema.d.ts +195 -7
  18. package/dist/firestore/src/local/local_documents_view.d.ts +0 -1
  19. package/dist/firestore/src/local/local_serializer.d.ts +19 -3
  20. package/dist/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  21. package/dist/firestore/src/local/memory_index_manager.d.ts +11 -0
  22. package/dist/firestore/src/local/memory_persistence.d.ts +6 -2
  23. package/dist/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  24. package/dist/firestore/src/local/persistence.d.ts +8 -2
  25. package/dist/firestore/src/local/remote_document_cache.d.ts +7 -9
  26. package/dist/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  27. package/dist/firestore/src/local/simple_db.d.ts +1 -0
  28. package/dist/firestore/src/model/document.d.ts +7 -0
  29. package/dist/firestore/src/model/document_key.d.ts +6 -0
  30. package/dist/firestore/src/model/field_index.d.ts +87 -7
  31. package/dist/firestore/src/model/overlay.d.ts +32 -0
  32. package/dist/firestore/src/model/target_index_matcher.d.ts +70 -0
  33. package/dist/firestore/src/model/values.d.ts +7 -0
  34. package/dist/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  35. package/dist/firestore/src/platform/node/load_protos.d.ts +2 -2
  36. package/dist/firestore/src/util/sorted_set.d.ts +18 -0
  37. package/dist/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  38. package/dist/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  39. package/dist/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  40. package/dist/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  41. package/dist/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  42. package/dist/firestore/test/unit/local/test_remote_document_cache.d.ts +5 -3
  43. package/dist/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  44. package/dist/firestore/test/unit/model/field_index.test.d.ts +17 -0
  45. package/dist/firestore/test/unit/model/target.test.d.ts +17 -0
  46. package/dist/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  47. package/dist/firestore/test/util/helpers.d.ts +8 -2
  48. package/dist/index.d.ts +1 -2
  49. package/dist/index.esm2017.js +4815 -3708
  50. package/dist/index.esm2017.js.map +1 -1
  51. package/dist/index.esm5.js +4500 -3545
  52. package/dist/index.esm5.js.map +1 -1
  53. package/dist/index.node.cjs.js +2001 -389
  54. package/dist/index.node.cjs.js.map +1 -1
  55. package/dist/index.node.mjs +1981 -390
  56. package/dist/index.node.mjs.map +1 -1
  57. package/dist/index.rn.js +4798 -3733
  58. package/dist/index.rn.js.map +1 -1
  59. package/dist/internal.d.ts +265 -26
  60. package/dist/lite/firestore/src/api/credentials.d.ts +1 -0
  61. package/dist/lite/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  62. package/dist/lite/firestore/src/api/snapshot.d.ts +1 -2
  63. package/dist/lite/firestore/src/api.d.ts +1 -1
  64. package/dist/lite/firestore/src/core/database_info.d.ts +1 -0
  65. package/dist/lite/firestore/src/core/target.d.ts +34 -5
  66. package/dist/lite/firestore/src/index/index_byte_encoder.d.ts +18 -1
  67. package/dist/lite/firestore/src/index/index_entry.d.ts +26 -0
  68. package/dist/lite/firestore/src/lite-api/query.d.ts +2 -2
  69. package/dist/lite/firestore/src/local/document_overlay_cache.d.ts +72 -0
  70. package/dist/lite/firestore/src/local/index_manager.d.ts +52 -0
  71. package/dist/lite/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  72. package/dist/lite/firestore/src/local/indexeddb_index_manager.d.ts +40 -2
  73. package/dist/lite/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  74. package/dist/lite/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  75. package/dist/lite/firestore/src/local/indexeddb_schema.d.ts +195 -7
  76. package/dist/lite/firestore/src/local/local_documents_view.d.ts +0 -1
  77. package/dist/lite/firestore/src/local/local_serializer.d.ts +19 -3
  78. package/dist/lite/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  79. package/dist/lite/firestore/src/local/memory_index_manager.d.ts +11 -0
  80. package/dist/lite/firestore/src/local/memory_persistence.d.ts +6 -2
  81. package/dist/lite/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  82. package/dist/lite/firestore/src/local/persistence.d.ts +8 -2
  83. package/dist/lite/firestore/src/local/remote_document_cache.d.ts +7 -9
  84. package/dist/lite/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  85. package/dist/lite/firestore/src/local/simple_db.d.ts +1 -0
  86. package/dist/lite/firestore/src/model/document.d.ts +7 -0
  87. package/dist/lite/firestore/src/model/document_key.d.ts +6 -0
  88. package/dist/lite/firestore/src/model/field_index.d.ts +87 -7
  89. package/dist/lite/firestore/src/model/overlay.d.ts +32 -0
  90. package/dist/lite/firestore/src/model/target_index_matcher.d.ts +70 -0
  91. package/dist/lite/firestore/src/model/values.d.ts +7 -0
  92. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  93. package/dist/lite/firestore/src/platform/node/load_protos.d.ts +2 -2
  94. package/dist/lite/firestore/src/util/sorted_set.d.ts +18 -0
  95. package/dist/lite/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  96. package/dist/lite/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  97. package/dist/lite/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  98. package/dist/lite/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  99. package/dist/lite/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  100. package/dist/lite/firestore/test/unit/local/test_remote_document_cache.d.ts +5 -3
  101. package/dist/lite/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  102. package/dist/lite/firestore/test/unit/model/field_index.test.d.ts +17 -0
  103. package/dist/lite/firestore/test/unit/model/target.test.d.ts +17 -0
  104. package/dist/lite/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  105. package/dist/lite/firestore/test/util/helpers.d.ts +8 -2
  106. package/dist/lite/index.browser.esm2017.js +1166 -1143
  107. package/dist/lite/index.browser.esm2017.js.map +1 -1
  108. package/dist/lite/index.browser.esm5.js +357 -337
  109. package/dist/lite/index.browser.esm5.js.map +1 -1
  110. package/dist/lite/index.node.cjs.js +64 -34
  111. package/dist/lite/index.node.cjs.js.map +1 -1
  112. package/dist/lite/index.node.mjs +64 -34
  113. package/dist/lite/index.node.mjs.map +1 -1
  114. package/dist/lite/index.rn.esm2017.js +344 -321
  115. package/dist/lite/index.rn.esm2017.js.map +1 -1
  116. package/dist/lite/internal.d.ts +16 -2
  117. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +122 -121
  118. package/dist/lite/packages/firestore/src/api/credentials.d.ts +1 -0
  119. package/dist/lite/packages/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  120. package/dist/lite/packages/firestore/src/api/snapshot.d.ts +1 -2
  121. package/dist/lite/packages/firestore/src/api.d.ts +1 -1
  122. package/dist/lite/packages/firestore/src/core/database_info.d.ts +1 -0
  123. package/dist/lite/packages/firestore/src/core/target.d.ts +34 -5
  124. package/dist/lite/packages/firestore/src/index/index_byte_encoder.d.ts +18 -1
  125. package/dist/lite/packages/firestore/src/index/index_entry.d.ts +26 -0
  126. package/dist/lite/packages/firestore/src/lite-api/query.d.ts +2 -2
  127. package/dist/lite/packages/firestore/src/local/document_overlay_cache.d.ts +72 -0
  128. package/dist/lite/packages/firestore/src/local/index_manager.d.ts +52 -0
  129. package/dist/lite/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  130. package/dist/lite/packages/firestore/src/local/indexeddb_index_manager.d.ts +40 -2
  131. package/dist/lite/packages/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  132. package/dist/lite/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  133. package/dist/lite/packages/firestore/src/local/indexeddb_schema.d.ts +195 -7
  134. package/dist/lite/packages/firestore/src/local/local_documents_view.d.ts +0 -1
  135. package/dist/lite/packages/firestore/src/local/local_serializer.d.ts +19 -3
  136. package/dist/lite/packages/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  137. package/dist/lite/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  138. package/dist/lite/packages/firestore/src/local/memory_persistence.d.ts +6 -2
  139. package/dist/lite/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  140. package/dist/lite/packages/firestore/src/local/persistence.d.ts +8 -2
  141. package/dist/lite/packages/firestore/src/local/remote_document_cache.d.ts +7 -9
  142. package/dist/lite/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  143. package/dist/lite/packages/firestore/src/local/simple_db.d.ts +1 -0
  144. package/dist/lite/packages/firestore/src/model/document.d.ts +7 -0
  145. package/dist/lite/packages/firestore/src/model/document_key.d.ts +6 -0
  146. package/dist/lite/packages/firestore/src/model/field_index.d.ts +87 -7
  147. package/dist/lite/packages/firestore/src/model/overlay.d.ts +32 -0
  148. package/dist/lite/packages/firestore/src/model/target_index_matcher.d.ts +70 -0
  149. package/dist/lite/packages/firestore/src/model/values.d.ts +7 -0
  150. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  151. package/dist/lite/packages/firestore/src/platform/node/load_protos.d.ts +2 -2
  152. package/dist/lite/packages/firestore/src/util/sorted_set.d.ts +18 -0
  153. package/dist/lite/packages/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  154. package/dist/lite/packages/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  155. package/dist/lite/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  156. package/dist/lite/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  157. package/dist/lite/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  158. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +5 -3
  159. package/dist/lite/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  160. package/dist/lite/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
  161. package/dist/lite/packages/firestore/test/unit/model/target.test.d.ts +17 -0
  162. package/dist/lite/packages/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  163. package/dist/lite/packages/firestore/test/util/helpers.d.ts +8 -2
  164. package/dist/lite/private.d.ts +9 -2
  165. package/dist/packages/firestore/dist/index.esm2017.d.ts +199 -194
  166. package/dist/packages/firestore/src/api/credentials.d.ts +1 -0
  167. package/dist/packages/firestore/src/api/{query.d.ts → filter.d.ts} +0 -0
  168. package/dist/packages/firestore/src/api/snapshot.d.ts +1 -2
  169. package/dist/packages/firestore/src/api.d.ts +1 -1
  170. package/dist/packages/firestore/src/core/database_info.d.ts +1 -0
  171. package/dist/packages/firestore/src/core/target.d.ts +34 -5
  172. package/dist/packages/firestore/src/index/index_byte_encoder.d.ts +18 -1
  173. package/dist/packages/firestore/src/index/index_entry.d.ts +26 -0
  174. package/dist/packages/firestore/src/lite-api/query.d.ts +2 -2
  175. package/dist/packages/firestore/src/local/document_overlay_cache.d.ts +72 -0
  176. package/dist/packages/firestore/src/local/index_manager.d.ts +52 -0
  177. package/dist/packages/firestore/src/local/indexeddb_document_overlay_cache.d.ts +45 -0
  178. package/dist/packages/firestore/src/local/indexeddb_index_manager.d.ts +40 -2
  179. package/dist/packages/firestore/src/local/indexeddb_persistence.d.ts +6 -4
  180. package/dist/packages/firestore/src/local/indexeddb_remote_document_cache.d.ts +2 -8
  181. package/dist/packages/firestore/src/local/indexeddb_schema.d.ts +195 -7
  182. package/dist/packages/firestore/src/local/local_documents_view.d.ts +0 -1
  183. package/dist/packages/firestore/src/local/local_serializer.d.ts +19 -3
  184. package/dist/packages/firestore/src/local/memory_document_overlay_cache.d.ts +37 -0
  185. package/dist/packages/firestore/src/local/memory_index_manager.d.ts +11 -0
  186. package/dist/packages/firestore/src/local/memory_persistence.d.ts +6 -2
  187. package/dist/packages/firestore/src/local/memory_remote_document_cache.d.ts +1 -3
  188. package/dist/packages/firestore/src/local/persistence.d.ts +8 -2
  189. package/dist/packages/firestore/src/local/remote_document_cache.d.ts +7 -9
  190. package/dist/packages/firestore/src/local/remote_document_change_buffer.d.ts +3 -12
  191. package/dist/packages/firestore/src/local/simple_db.d.ts +1 -0
  192. package/dist/packages/firestore/src/model/document.d.ts +7 -0
  193. package/dist/packages/firestore/src/model/document_key.d.ts +6 -0
  194. package/dist/packages/firestore/src/model/field_index.d.ts +87 -7
  195. package/dist/packages/firestore/src/model/overlay.d.ts +32 -0
  196. package/dist/packages/firestore/src/model/target_index_matcher.d.ts +70 -0
  197. package/dist/packages/firestore/src/model/values.d.ts +7 -0
  198. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +2 -2
  199. package/dist/packages/firestore/src/platform/node/load_protos.d.ts +2 -2
  200. package/dist/packages/firestore/src/util/sorted_set.d.ts +18 -0
  201. package/dist/packages/firestore/test/unit/local/counting_query_engine.d.ts +3 -3
  202. package/dist/packages/firestore/test/unit/local/document_overlay_cache.test.d.ts +1 -0
  203. package/dist/packages/firestore/test/unit/local/persistence_test_helpers.d.ts +1 -0
  204. package/dist/packages/firestore/test/unit/local/test_document_overlay_cache.d.ts +38 -0
  205. package/dist/packages/firestore/test/unit/local/test_index_manager.d.ts +11 -0
  206. package/dist/packages/firestore/test/unit/local/test_remote_document_cache.d.ts +5 -3
  207. package/dist/packages/firestore/test/unit/local/test_remote_document_change_buffer.d.ts +1 -1
  208. package/dist/packages/firestore/test/unit/model/field_index.test.d.ts +17 -0
  209. package/dist/packages/firestore/test/unit/model/target.test.d.ts +17 -0
  210. package/dist/packages/firestore/test/unit/model/target_index_matcher.test.d.ts +17 -0
  211. package/dist/packages/firestore/test/util/helpers.d.ts +8 -2
  212. package/dist/private.d.ts +258 -26
  213. package/package.json +4 -4
@@ -14,7 +14,15 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { SnapshotVersion } from '../core/snapshot_version';
18
+ import { Document } from './document';
19
+ import { DocumentKey } from './document_key';
17
20
  import { FieldPath } from './path';
21
+ /**
22
+ * The initial sequence number for each index. Gets updated during index
23
+ * backfill.
24
+ */
25
+ export declare const INITIAL_SEQUENCE_NUMBER = 0;
18
26
  /**
19
27
  * An index definition for field indexes in Firestore.
20
28
  *
@@ -35,9 +43,11 @@ export declare class FieldIndex {
35
43
  /** The collection ID this index applies to. */
36
44
  readonly collectionGroup: string;
37
45
  /** The field segments for this index. */
38
- readonly segments: Segment[];
46
+ readonly fields: IndexSegment[];
47
+ /** Shows how up-to-date the index is for the current user. */
48
+ readonly indexState: IndexState;
39
49
  /** An ID for an index that has not yet been added to persistence. */
40
- static UNKNOWN_ID: -1;
50
+ static UNKNOWN_ID: number;
41
51
  constructor(
42
52
  /**
43
53
  * The index ID. Returns -1 if the index ID is not available (e.g. the index
@@ -47,10 +57,21 @@ export declare class FieldIndex {
47
57
  /** The collection ID this index applies to. */
48
58
  collectionGroup: string,
49
59
  /** The field segments for this index. */
50
- segments: Segment[]);
60
+ fields: IndexSegment[],
61
+ /** Shows how up-to-date the index is for the current user. */
62
+ indexState: IndexState);
51
63
  }
64
+ /** Returns the ArrayContains/ArrayContainsAny segment for this index. */
65
+ export declare function fieldIndexGetArraySegment(fieldIndex: FieldIndex): IndexSegment | undefined;
66
+ /** Returns all directional (ascending/descending) segments for this index. */
67
+ export declare function fieldIndexGetDirectionalSegments(fieldIndex: FieldIndex): IndexSegment[];
68
+ /**
69
+ * Compares indexes by collection group and segments. Ignores update time and
70
+ * index ID.
71
+ */
72
+ export declare function fieldIndexSemanticComparator(left: FieldIndex, right: FieldIndex): number;
52
73
  /** The type of the index, e.g. for which type of query it can be used. */
53
- export declare const enum Kind {
74
+ export declare const enum IndexKind {
54
75
  /**
55
76
  * Ordered index. Can be used for <, <=, ==, >=, >, !=, IN and NOT IN queries.
56
77
  */
@@ -63,14 +84,73 @@ export declare const enum Kind {
63
84
  CONTAINS = 2
64
85
  }
65
86
  /** An index component consisting of field path and index type. */
66
- export declare class Segment {
87
+ export declare class IndexSegment {
67
88
  /** The field path of the component. */
68
89
  readonly fieldPath: FieldPath;
69
90
  /** The fields sorting order. */
70
- readonly kind: Kind;
91
+ readonly kind: IndexKind;
71
92
  constructor(
72
93
  /** The field path of the component. */
73
94
  fieldPath: FieldPath,
74
95
  /** The fields sorting order. */
75
- kind: Kind);
96
+ kind: IndexKind);
97
+ }
98
+ /**
99
+ * Stores the "high water mark" that indicates how updated the Index is for the
100
+ * current user.
101
+ */
102
+ export declare class IndexState {
103
+ /**
104
+ * Indicates when the index was last updated (relative to other indexes).
105
+ */
106
+ readonly sequenceNumber: number;
107
+ /** The the latest indexed read time, document and batch id. */
108
+ readonly offset: IndexOffset;
109
+ constructor(
110
+ /**
111
+ * Indicates when the index was last updated (relative to other indexes).
112
+ */
113
+ sequenceNumber: number,
114
+ /** The the latest indexed read time, document and batch id. */
115
+ offset: IndexOffset);
116
+ /** The state of an index that has not yet been backfilled. */
117
+ static empty(): IndexState;
118
+ }
119
+ /**
120
+ * Creates an offset that matches all documents with a read time higher than
121
+ * `readTime`.
122
+ */
123
+ export declare function newIndexOffsetSuccessorFromReadTime(readTime: SnapshotVersion, largestBatchId: number): IndexOffset;
124
+ /** Creates a new offset based on the provided document. */
125
+ export declare function newIndexOffsetFromDocument(document: Document): IndexOffset;
126
+ /**
127
+ * Stores the latest read time, document and batch ID that were processed for an
128
+ * index.
129
+ */
130
+ export declare class IndexOffset {
131
+ /**
132
+ * The latest read time version that has been indexed by Firestore for this
133
+ * field index.
134
+ */
135
+ readonly readTime: SnapshotVersion;
136
+ /**
137
+ * The key of the last document that was indexed for this query. Use
138
+ * `DocumentKey.empty()` if no document has been indexed.
139
+ */
140
+ readonly documentKey: DocumentKey;
141
+ readonly largestBatchId: number;
142
+ constructor(
143
+ /**
144
+ * The latest read time version that has been indexed by Firestore for this
145
+ * field index.
146
+ */
147
+ readTime: SnapshotVersion,
148
+ /**
149
+ * The key of the last document that was indexed for this query. Use
150
+ * `DocumentKey.empty()` if no document has been indexed.
151
+ */
152
+ documentKey: DocumentKey, largestBatchId: number);
153
+ /** The state of an index that has not yet been backfilled. */
154
+ static min(): IndexOffset;
76
155
  }
156
+ export declare function indexOffsetComparator(left: IndexOffset, right: IndexOffset): number;
@@ -0,0 +1,32 @@
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 { DocumentKey } from './document_key';
18
+ import { Mutation } from './mutation';
19
+ /**
20
+ * Representation of an overlay computed by Firestore.
21
+ *
22
+ * Holds information about a mutation and the largest batch id in Firestore when
23
+ * the mutation was created.
24
+ */
25
+ export declare class Overlay {
26
+ readonly largestBatchId: number;
27
+ readonly mutation: Mutation;
28
+ constructor(largestBatchId: number, mutation: Mutation);
29
+ getKey(): DocumentKey;
30
+ isEqual(other: Overlay | null): boolean;
31
+ toString(): string;
32
+ }
@@ -0,0 +1,70 @@
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 { Target } from '../core/target';
18
+ import { FieldIndex } from './field_index';
19
+ /**
20
+ * A light query planner for Firestore.
21
+ *
22
+ * This class matches a `FieldIndex` against a Firestore Query `Target`. It
23
+ * determines whether a given index can be used to serve the specified target.
24
+ *
25
+ * The following table showcases some possible index configurations:
26
+ *
27
+ * Query | Index
28
+ * -----------------------------------------------------------------------------
29
+ * where('a', '==', 'a').where('b', '==', 'b') | a ASC, b DESC
30
+ * where('a', '==', 'a').where('b', '==', 'b') | a ASC
31
+ * where('a', '==', 'a').where('b', '==', 'b') | b DESC
32
+ * where('a', '>=', 'a').orderBy('a') | a ASC
33
+ * where('a', '>=', 'a').orderBy('a', 'desc') | a DESC
34
+ * where('a', '>=', 'a').orderBy('a').orderBy('b') | a ASC, b ASC
35
+ * where('a', '>=', 'a').orderBy('a').orderBy('b') | a ASC
36
+ * where('a', 'array-contains', 'a').orderBy('b') | a CONTAINS, b ASCENDING
37
+ * where('a', 'array-contains', 'a').orderBy('b') | a CONTAINS
38
+ */
39
+ export declare class TargetIndexMatcher {
40
+ private readonly collectionId;
41
+ private readonly inequalityFilter?;
42
+ private readonly equalityFilters;
43
+ private readonly orderBys;
44
+ constructor(target: Target);
45
+ /**
46
+ * Returns whether the index can be used to serve the TargetIndexMatcher's
47
+ * target.
48
+ *
49
+ * An index is considered capable of serving the target when:
50
+ * - The target uses all index segments for its filters and orderBy clauses.
51
+ * The target can have additional filter and orderBy clauses, but not
52
+ * fewer.
53
+ * - If an ArrayContains/ArrayContainsAnyfilter is used, the index must also
54
+ * have a corresponding `CONTAINS` segment.
55
+ * - All directional index segments can be mapped to the target as a series of
56
+ * equality filters, a single inequality filter and a series of orderBy
57
+ * clauses.
58
+ * - The segments that represent the equality filters may appear out of order.
59
+ * - The optional segment for the inequality filter must appear after all
60
+ * equality segments.
61
+ * - The segments that represent that orderBy clause of the target must appear
62
+ * in order after all equality and inequality segments. Single orderBy
63
+ * clauses cannot be skipped, but a continuous orderBy suffix may be
64
+ * omitted.
65
+ */
66
+ servedByIndex(index: FieldIndex): boolean;
67
+ private hasMatchingEqualityFilter;
68
+ private matchesFilter;
69
+ private matchesOrderBy;
70
+ }
@@ -19,6 +19,7 @@ import { ArrayValue, MapValue, Value } from '../protos/firestore_proto_api';
19
19
  import { DocumentKey } from './document_key';
20
20
  import { TypeOrder } from './type_order';
21
21
  export declare const MAX_VALUE: Value;
22
+ export declare const MIN_VALUE: Value;
22
23
  /** Extracts the backend's type order for the provided value. */
23
24
  export declare function typeOrder(value: Value): TypeOrder;
24
25
  /** Tests `left` and `right` for equality based on the backend semantics. */
@@ -76,3 +77,9 @@ export declare function isMapValue(value?: Value | null): value is {
76
77
  export declare function deepClone(source: Value): Value;
77
78
  /** Returns true if the Value represents the canonical {@link #MAX_VALUE} . */
78
79
  export declare function isMaxValue(value: Value): boolean;
80
+ /** Returns the lowest value for the given value type (inclusive). */
81
+ export declare function valuesGetLowerBound(value: Value): Value;
82
+ /** Returns the largest value for the given value type (exclusive). */
83
+ export declare function valuesGetUpperBound(value: Value): Value;
84
+ export declare function valuesMax(left: Value | undefined, right: Value | undefined): Value | undefined;
85
+ export declare function valuesMin(left: Value | undefined, right: Value | undefined): Value | undefined;
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { GrpcObject } from '@grpc/grpc-js';
17
+ import * as grpc from '@grpc/grpc-js';
18
18
  import { Token } from '../../api/credentials';
19
19
  import { DatabaseInfo } from '../../core/database_info';
20
20
  import { Connection, Stream } from '../../remote/connection';
@@ -26,7 +26,7 @@ export declare class GrpcConnection implements Connection {
26
26
  private readonly databasePath;
27
27
  private readonly firestore;
28
28
  private cachedStub;
29
- constructor(protos: GrpcObject, databaseInfo: DatabaseInfo);
29
+ constructor(protos: grpc.GrpcObject, databaseInfo: DatabaseInfo);
30
30
  private ensureActiveStub;
31
31
  invokeRPC<Req, Resp>(rpcName: string, path: string, request: Req, authToken: Token | null, appCheckToken: Token | null): Promise<Resp>;
32
32
  invokeStreamingRPC<Req, Resp>(rpcName: string, path: string, request: Req, authToken: Token | null, appCheckToken: Token | null): Promise<Resp[]>;
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { GrpcObject } from '@grpc/grpc-js';
17
+ import * as grpc from '@grpc/grpc-js';
18
18
  import { IConversionOptions, Root } from 'protobufjs';
19
19
  /** Used by tests so we can match @grpc/proto-loader behavior. */
20
20
  export declare const protoLoaderOptions: IConversionOptions;
@@ -23,6 +23,6 @@ export declare const protoLoaderOptions: IConversionOptions;
23
23
  *
24
24
  * @returns The GrpcObject representing our protos.
25
25
  */
26
- export declare function loadProtos(): GrpcObject;
26
+ export declare function loadProtos(): grpc.GrpcObject;
27
27
  /** Used by tests so we can directly create ProtobufJS proto message objects from JSON protos. */
28
28
  export declare function loadRawProtos(): Root;
@@ -60,3 +60,21 @@ export declare class SortedSetIterator<T> {
60
60
  getNext(): T;
61
61
  hasNext(): boolean;
62
62
  }
63
+ /**
64
+ * Compares two sorted sets for equality using their natural ordering. The
65
+ * method computes the intersection and invokes `onAdd` for every element that
66
+ * is in `after` but not `before`. `onRemove` is invoked for every element in
67
+ * `before` but missing from `after`.
68
+ *
69
+ * The method creates a copy of both `before` and `after` and runs in O(n log
70
+ * n), where n is the size of the two lists.
71
+ *
72
+ * @param before - The elements that exist in the original set.
73
+ * @param after - The elements to diff against the original set.
74
+ * @param comparator - The comparator for the elements in before and after.
75
+ * @param onAdd - A function to invoke for every element that is part of `
76
+ * after` but not `before`.
77
+ * @param onRemove - A function to invoke for every element that is part of
78
+ * `before` but not `after`.
79
+ */
80
+ export declare function diffSortedSets<T>(before: SortedSet<T>, after: SortedSet<T>, comparator: (l: T, r: T) => number, onAdd: (entry: T) => void, onRemove: (entry: T) => void): void;
@@ -31,7 +31,7 @@ export declare class CountingQueryEngine extends QueryEngine {
31
31
  * `getAllMutationBatchesAffectingQuery()` API (since the last call to
32
32
  * `resetCounts()`)
33
33
  */
34
- mutationsReadByQuery: number;
34
+ mutationsReadByCollection: number;
35
35
  /**
36
36
  * The number of mutations returned by the MutationQueue's
37
37
  * `getAllMutationBatchesAffectingDocumentKey()` and
@@ -41,9 +41,9 @@ export declare class CountingQueryEngine extends QueryEngine {
41
41
  mutationsReadByKey: number;
42
42
  /**
43
43
  * The number of documents returned by the RemoteDocumentCache's
44
- * `getDocumentsMatchingQuery()` API (since the last call to `resetCounts()`)
44
+ * `getAll()` API (since the last call to `resetCounts()`)
45
45
  */
46
- documentsReadByQuery: number;
46
+ documentsReadByCollection: number;
47
47
  /**
48
48
  * The number of documents returned by the RemoteDocumentCache's `getEntry()`
49
49
  * and `getEntries()` APIs (since the last call to `resetCounts()`)
@@ -54,6 +54,7 @@ export declare function testIndexedDbPersistence(options?: {
54
54
  dontPurgeData?: boolean;
55
55
  synchronizeTabs?: boolean;
56
56
  queue?: AsyncQueue;
57
+ schemaVersion?: number;
57
58
  }, lruParams?: LruParams): Promise<IndexedDbPersistence>;
58
59
  /** Creates and starts a MemoryPersistence instance for testing. */
59
60
  export declare function testMemoryEagerPersistence(): Promise<MemoryPersistence>;
@@ -0,0 +1,38 @@
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 { DocumentOverlayCache } from '../../../src/local/document_overlay_cache';
18
+ import { Persistence } from '../../../src/local/persistence';
19
+ import { DocumentKeySet } from '../../../src/model/collections';
20
+ import { DocumentKey } from '../../../src/model/document_key';
21
+ import { Mutation } from '../../../src/model/mutation';
22
+ import { Overlay } from '../../../src/model/overlay';
23
+ import { ResourcePath } from '../../../src/model/path';
24
+ /**
25
+ * A wrapper around a DocumentOverlayCache that automatically creates a
26
+ * transaction around every operation to reduce test boilerplate.
27
+ */
28
+ export declare class TestDocumentOverlayCache {
29
+ private persistence;
30
+ private cache;
31
+ constructor(persistence: Persistence, cache: DocumentOverlayCache);
32
+ saveOverlays(largestBatch: number, data: Map<DocumentKey, Mutation>): Promise<void>;
33
+ getOverlay(key: DocumentKey): Promise<Overlay | null>;
34
+ getOverlayMutation(docKey: string): Promise<Mutation | null>;
35
+ getOverlaysForCollection(path: ResourcePath, sinceBatchId: number): Promise<Map<DocumentKey, Overlay>>;
36
+ getOverlaysForCollectionGroup(collectionGroup: string, sinceBatchId: number, count: number): Promise<Map<DocumentKey, Overlay>>;
37
+ removeOverlaysForBatchId(documentKeys: DocumentKeySet, batchId: number): Promise<void>;
38
+ }
@@ -14,8 +14,11 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { Target } from '../../../src/core/target';
17
18
  import { IndexManager } from '../../../src/local/index_manager';
18
19
  import { Persistence } from '../../../src/local/persistence';
20
+ import { DocumentKeySet, DocumentMap } from '../../../src/model/collections';
21
+ import { FieldIndex, IndexOffset } from '../../../src/model/field_index';
19
22
  import { ResourcePath } from '../../../src/model/path';
20
23
  /**
21
24
  * A wrapper around IndexManager that automatically creates a
@@ -27,4 +30,12 @@ export declare class TestIndexManager {
27
30
  constructor(persistence: Persistence, indexManager: IndexManager);
28
31
  addToCollectionParentIndex(collectionPath: ResourcePath): Promise<void>;
29
32
  getCollectionParents(collectionId: string): Promise<ResourcePath[]>;
33
+ addFieldIndex(index: FieldIndex): Promise<void>;
34
+ deleteFieldIndex(index: FieldIndex): Promise<void>;
35
+ getFieldIndexes(collectionGroup?: string): Promise<FieldIndex[]>;
36
+ getFieldIndex(target: Target): Promise<FieldIndex | null>;
37
+ getDocumentsMatchingTarget(fieldIndex: FieldIndex, target: Target): Promise<DocumentKeySet>;
38
+ getNextCollectionGroupToUpdate(): Promise<string | null>;
39
+ updateCollectionGroup(collectionGroup: string, offset: IndexOffset): Promise<void>;
40
+ updateIndexEntries(documents: DocumentMap): Promise<void>;
30
41
  }
@@ -14,13 +14,14 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Query } from '../../../src/core/query';
18
17
  import { SnapshotVersion } from '../../../src/core/snapshot_version';
18
+ import { IndexManager } from '../../../src/local/index_manager';
19
19
  import { Persistence } from '../../../src/local/persistence';
20
20
  import { RemoteDocumentChangeBuffer } from '../../../src/local/remote_document_change_buffer';
21
21
  import { DocumentKeySet, MutableDocumentMap } from '../../../src/model/collections';
22
22
  import { MutableDocument } from '../../../src/model/document';
23
23
  import { DocumentKey } from '../../../src/model/document_key';
24
+ import { ResourcePath } from '../../../src/model/path';
24
25
  /**
25
26
  * A wrapper around a RemoteDocumentCache that automatically creates a
26
27
  * transaction around every operation to reduce test boilerplate.
@@ -29,11 +30,12 @@ export declare class TestRemoteDocumentCache {
29
30
  private readonly persistence;
30
31
  private readonly cache;
31
32
  constructor(persistence: Persistence);
33
+ setIndexManager(indexManager: IndexManager): void;
32
34
  /**
33
35
  * Reads all of the documents first so we can safely add them and keep the size calculation in
34
36
  * sync.
35
37
  */
36
- addEntries(documents: MutableDocument[], readTime: SnapshotVersion): Promise<void>;
38
+ addEntries(documents: MutableDocument[]): Promise<void>;
37
39
  /**
38
40
  * Adds a single document using the document's version as its read time.
39
41
  * Reads the document first to track the document size internally.
@@ -42,7 +44,7 @@ export declare class TestRemoteDocumentCache {
42
44
  removeEntry(documentKey: DocumentKey, version?: SnapshotVersion): Promise<void>;
43
45
  getEntry(documentKey: DocumentKey): Promise<MutableDocument>;
44
46
  getEntries(documentKeys: DocumentKeySet): Promise<MutableDocumentMap>;
45
- getDocumentsMatchingQuery(query: Query, sinceReadTime: SnapshotVersion): Promise<MutableDocumentMap>;
47
+ getAll(collection: ResourcePath, sinceReadTime: SnapshotVersion): Promise<MutableDocumentMap>;
46
48
  getNewDocumentChanges(sinceReadTime: SnapshotVersion): Promise<{
47
49
  changedDocs: MutableDocumentMap;
48
50
  readTime: SnapshotVersion;
@@ -28,7 +28,7 @@ export declare class TestRemoteDocumentChangeBuffer {
28
28
  buffer: RemoteDocumentChangeBuffer;
29
29
  constructor(persistence: Persistence, buffer: RemoteDocumentChangeBuffer);
30
30
  addEntry(document: MutableDocument, readTime: SnapshotVersion): void;
31
- removeEntry(key: DocumentKey): void;
31
+ removeEntry(key: DocumentKey, readTime: SnapshotVersion): void;
32
32
  getEntry(documentKey: DocumentKey): Promise<MutableDocument>;
33
33
  apply(): Promise<void>;
34
34
  }
@@ -0,0 +1,17 @@
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
+ export {};
@@ -0,0 +1,17 @@
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
+ export {};
@@ -0,0 +1,17 @@
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
+ export {};
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Bytes, DocumentReference, OrderByDirection } from '../../src';
17
+ import { Bytes, DocumentReference } from '../../src';
18
18
  import { BundledDocuments } from '../../src/core/bundle';
19
19
  import { DatabaseId } from '../../src/core/database_info';
20
20
  import { Query } from '../../src/core/query';
@@ -30,6 +30,7 @@ import { Document, MutableDocument } from '../../src/model/document';
30
30
  import { DocumentComparator } from '../../src/model/document_comparator';
31
31
  import { DocumentKey } from '../../src/model/document_key';
32
32
  import { DocumentSet } from '../../src/model/document_set';
33
+ import { FieldIndex, IndexKind, IndexOffset } from '../../src/model/field_index';
33
34
  import { FieldMask } from '../../src/model/field_mask';
34
35
  import { DeleteMutation, MutationResult, PatchMutation, Precondition, SetMutation } from '../../src/model/mutation';
35
36
  import { JsonObject, ObjectValue } from '../../src/model/object_value';
@@ -58,6 +59,11 @@ export declare function key(path: string): DocumentKey;
58
59
  export declare function keys(...documents: Array<Document | string>): DocumentKeySet;
59
60
  export declare function path(path: string, offset?: number): ResourcePath;
60
61
  export declare function field(path: string): FieldPath;
62
+ export declare function fieldIndex(collectionGroup: string, options?: {
63
+ id?: number;
64
+ fields?: Array<[field: string, kind: IndexKind]>;
65
+ offset?: IndexOffset;
66
+ }): FieldIndex;
61
67
  export declare function mask(...paths: string[]): FieldMask;
62
68
  export declare function blob(...bytes: number[]): Bytes;
63
69
  export declare function filter(path: string, op: string, value: unknown): FieldFilter;
@@ -65,7 +71,7 @@ export declare function setMutation(keyStr: string, json: JsonObject<unknown>):
65
71
  export declare function patchMutation(keyStr: string, json: JsonObject<unknown>, precondition?: Precondition): PatchMutation;
66
72
  export declare function deleteMutation(keyStr: string): DeleteMutation;
67
73
  export declare function mutationResult(testVersion: TestSnapshotVersion): MutationResult;
68
- export declare function bound(values: Array<[string, {}, OrderByDirection]>, before: boolean): Bound;
74
+ export declare function bound(values: unknown[], inclusive: boolean): Bound;
69
75
  export declare function query(resourcePath: string, ...constraints: Array<OrderBy | Filter>): Query;
70
76
  export declare function targetData(targetId: TargetId, queryPurpose: TargetPurpose, path: string): TargetData;
71
77
  export declare function noChangeEvent(targetId: number, snapshotVersion: number, resumeToken?: ByteString): RemoteEvent;
@@ -177,8 +177,8 @@ declare abstract class BasePath<B extends BasePath<B>> {
177
177
  */
178
178
  declare class Bound {
179
179
  readonly position: Value[];
180
- readonly before: boolean;
181
- constructor(position: Value[], before: boolean);
180
+ readonly inclusive: boolean;
181
+ constructor(position: Value[], inclusive: boolean);
182
182
  }
183
183
 
184
184
  /**
@@ -545,6 +545,11 @@ declare interface Document_2 {
545
545
  * document was guaranteed to not exist.
546
546
  */
547
547
  readonly version: SnapshotVersion;
548
+ /**
549
+ * The timestamp at which this document was read from the remote server. Uses
550
+ * `SnapshotVersion.min()` for documents created by the user.
551
+ */
552
+ readonly readTime: SnapshotVersion;
548
553
  /** The underlying data of this document or an empty value if no data exists. */
549
554
  readonly data: ObjectValue;
550
555
  /** Returns whether local mutations were applied via the mutation queue. */
@@ -1507,6 +1512,7 @@ declare class MutableDocument implements Document_2 {
1507
1512
  readonly key: DocumentKey;
1508
1513
  private documentType;
1509
1514
  version: SnapshotVersion;
1515
+ readTime: SnapshotVersion;
1510
1516
  data: ObjectValue;
1511
1517
  private documentState;
1512
1518
  private constructor();
@@ -1546,6 +1552,7 @@ declare class MutableDocument implements Document_2 {
1546
1552
  convertToUnknownDocument(version: SnapshotVersion): MutableDocument;
1547
1553
  setHasCommittedMutations(): MutableDocument;
1548
1554
  setHasLocalMutations(): MutableDocument;
1555
+ setReadTime(readTime: SnapshotVersion): MutableDocument;
1549
1556
  get hasLocalMutations(): boolean;
1550
1557
  get hasCommittedMutations(): boolean;
1551
1558
  get hasPendingWrites(): boolean;