xref: /aosp_15_r20/external/googleapis/google/firestore/v1/firestore.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.firestore.v1;
18
19import "google/api/annotations.proto";
20import "google/api/client.proto";
21import "google/api/field_behavior.proto";
22import "google/firestore/v1/aggregation_result.proto";
23import "google/firestore/v1/common.proto";
24import "google/firestore/v1/document.proto";
25import "google/firestore/v1/query.proto";
26import "google/firestore/v1/query_profile.proto";
27import "google/firestore/v1/write.proto";
28import "google/protobuf/empty.proto";
29import "google/protobuf/timestamp.proto";
30import "google/protobuf/wrappers.proto";
31import "google/rpc/status.proto";
32
33option csharp_namespace = "Google.Cloud.Firestore.V1";
34option go_package = "cloud.google.com/go/firestore/apiv1/firestorepb;firestorepb";
35option java_multiple_files = true;
36option java_outer_classname = "FirestoreProto";
37option java_package = "com.google.firestore.v1";
38option php_namespace = "Google\\Cloud\\Firestore\\V1";
39option ruby_package = "Google::Cloud::Firestore::V1";
40
41// Specification of the Firestore API.
42
43// The Cloud Firestore service.
44//
45// Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL
46// document database that simplifies storing, syncing, and querying data for
47// your mobile, web, and IoT apps at global scale. Its client libraries provide
48// live synchronization and offline support, while its security features and
49// integrations with Firebase and Google Cloud Platform accelerate building
50// truly serverless apps.
51service Firestore {
52  option (google.api.default_host) = "firestore.googleapis.com";
53  option (google.api.oauth_scopes) =
54      "https://www.googleapis.com/auth/cloud-platform,"
55      "https://www.googleapis.com/auth/datastore";
56
57  // Gets a single document.
58  rpc GetDocument(GetDocumentRequest) returns (Document) {
59    option (google.api.http) = {
60      get: "/v1/{name=projects/*/databases/*/documents/*/**}"
61    };
62  }
63
64  // Lists documents.
65  rpc ListDocuments(ListDocumentsRequest) returns (ListDocumentsResponse) {
66    option (google.api.http) = {
67      get: "/v1/{parent=projects/*/databases/*/documents/*/**}/{collection_id}"
68      additional_bindings {
69        get: "/v1/{parent=projects/*/databases/*/documents}/{collection_id}"
70      }
71    };
72  }
73
74  // Updates or inserts a document.
75  rpc UpdateDocument(UpdateDocumentRequest) returns (Document) {
76    option (google.api.http) = {
77      patch: "/v1/{document.name=projects/*/databases/*/documents/*/**}"
78      body: "document"
79    };
80    option (google.api.method_signature) = "document,update_mask";
81  }
82
83  // Deletes a document.
84  rpc DeleteDocument(DeleteDocumentRequest) returns (google.protobuf.Empty) {
85    option (google.api.http) = {
86      delete: "/v1/{name=projects/*/databases/*/documents/*/**}"
87    };
88    option (google.api.method_signature) = "name";
89  }
90
91  // Gets multiple documents.
92  //
93  // Documents returned by this method are not guaranteed to be returned in the
94  // same order that they were requested.
95  rpc BatchGetDocuments(BatchGetDocumentsRequest)
96      returns (stream BatchGetDocumentsResponse) {
97    option (google.api.http) = {
98      post: "/v1/{database=projects/*/databases/*}/documents:batchGet"
99      body: "*"
100    };
101  }
102
103  // Starts a new transaction.
104  rpc BeginTransaction(BeginTransactionRequest)
105      returns (BeginTransactionResponse) {
106    option (google.api.http) = {
107      post: "/v1/{database=projects/*/databases/*}/documents:beginTransaction"
108      body: "*"
109    };
110    option (google.api.method_signature) = "database";
111  }
112
113  // Commits a transaction, while optionally updating documents.
114  rpc Commit(CommitRequest) returns (CommitResponse) {
115    option (google.api.http) = {
116      post: "/v1/{database=projects/*/databases/*}/documents:commit"
117      body: "*"
118    };
119    option (google.api.method_signature) = "database,writes";
120  }
121
122  // Rolls back a transaction.
123  rpc Rollback(RollbackRequest) returns (google.protobuf.Empty) {
124    option (google.api.http) = {
125      post: "/v1/{database=projects/*/databases/*}/documents:rollback"
126      body: "*"
127    };
128    option (google.api.method_signature) = "database,transaction";
129  }
130
131  // Runs a query.
132  rpc RunQuery(RunQueryRequest) returns (stream RunQueryResponse) {
133    option (google.api.http) = {
134      post: "/v1/{parent=projects/*/databases/*/documents}:runQuery"
135      body: "*"
136      additional_bindings {
137        post: "/v1/{parent=projects/*/databases/*/documents/*/**}:runQuery"
138        body: "*"
139      }
140    };
141  }
142
143  // Runs an aggregation query.
144  //
145  // Rather than producing [Document][google.firestore.v1.Document] results like
146  // [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery], this API
147  // allows running an aggregation to produce a series of
148  // [AggregationResult][google.firestore.v1.AggregationResult] server-side.
149  //
150  // High-Level Example:
151  //
152  // ```
153  // -- Return the number of documents in table given a filter.
154  // SELECT COUNT(*) FROM ( SELECT * FROM k where a = true );
155  // ```
156  rpc RunAggregationQuery(RunAggregationQueryRequest)
157      returns (stream RunAggregationQueryResponse) {
158    option (google.api.http) = {
159      post: "/v1/{parent=projects/*/databases/*/documents}:runAggregationQuery"
160      body: "*"
161      additional_bindings {
162        post: "/v1/{parent=projects/*/databases/*/documents/*/**}:runAggregationQuery"
163        body: "*"
164      }
165    };
166  }
167
168  // Partitions a query by returning partition cursors that can be used to run
169  // the query in parallel. The returned partition cursors are split points that
170  // can be used by RunQuery as starting/end points for the query results.
171  rpc PartitionQuery(PartitionQueryRequest) returns (PartitionQueryResponse) {
172    option (google.api.http) = {
173      post: "/v1/{parent=projects/*/databases/*/documents}:partitionQuery"
174      body: "*"
175      additional_bindings {
176        post: "/v1/{parent=projects/*/databases/*/documents/*/**}:partitionQuery"
177        body: "*"
178      }
179    };
180  }
181
182  // Streams batches of document updates and deletes, in order. This method is
183  // only available via gRPC or WebChannel (not REST).
184  rpc Write(stream WriteRequest) returns (stream WriteResponse) {
185    option (google.api.http) = {
186      post: "/v1/{database=projects/*/databases/*}/documents:write"
187      body: "*"
188    };
189  }
190
191  // Listens to changes. This method is only available via gRPC or WebChannel
192  // (not REST).
193  rpc Listen(stream ListenRequest) returns (stream ListenResponse) {
194    option (google.api.http) = {
195      post: "/v1/{database=projects/*/databases/*}/documents:listen"
196      body: "*"
197    };
198  }
199
200  // Lists all the collection IDs underneath a document.
201  rpc ListCollectionIds(ListCollectionIdsRequest)
202      returns (ListCollectionIdsResponse) {
203    option (google.api.http) = {
204      post: "/v1/{parent=projects/*/databases/*/documents}:listCollectionIds"
205      body: "*"
206      additional_bindings {
207        post: "/v1/{parent=projects/*/databases/*/documents/*/**}:listCollectionIds"
208        body: "*"
209      }
210    };
211    option (google.api.method_signature) = "parent";
212  }
213
214  // Applies a batch of write operations.
215  //
216  // The BatchWrite method does not apply the write operations atomically
217  // and can apply them out of order. Method does not allow more than one write
218  // per document. Each write succeeds or fails independently. See the
219  // [BatchWriteResponse][google.firestore.v1.BatchWriteResponse] for the
220  // success status of each write.
221  //
222  // If you require an atomically applied set of writes, use
223  // [Commit][google.firestore.v1.Firestore.Commit] instead.
224  rpc BatchWrite(BatchWriteRequest) returns (BatchWriteResponse) {
225    option (google.api.http) = {
226      post: "/v1/{database=projects/*/databases/*}/documents:batchWrite"
227      body: "*"
228    };
229  }
230
231  // Creates a new document.
232  rpc CreateDocument(CreateDocumentRequest) returns (Document) {
233    option (google.api.http) = {
234      post: "/v1/{parent=projects/*/databases/*/documents/**}/{collection_id}"
235      body: "document"
236    };
237  }
238}
239
240// The request for
241// [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument].
242message GetDocumentRequest {
243  // Required. The resource name of the Document to get. In the format:
244  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
245  string name = 1 [(google.api.field_behavior) = REQUIRED];
246
247  // The fields to return. If not set, returns all fields.
248  //
249  // If the document has a field that is not present in this mask, that field
250  // will not be returned in the response.
251  DocumentMask mask = 2;
252
253  // The consistency mode for this transaction.
254  // If not set, defaults to strong consistency.
255  oneof consistency_selector {
256    // Reads the document in a transaction.
257    bytes transaction = 3;
258
259    // Reads the version of the document at the given time.
260    //
261    // This must be a microsecond precision timestamp within the past one hour,
262    // or if Point-in-Time Recovery is enabled, can additionally be a whole
263    // minute timestamp within the past 7 days.
264    google.protobuf.Timestamp read_time = 5;
265  }
266}
267
268// The request for
269// [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments].
270message ListDocumentsRequest {
271  // Required. The parent resource name. In the format:
272  // `projects/{project_id}/databases/{database_id}/documents` or
273  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
274  //
275  // For example:
276  // `projects/my-project/databases/my-database/documents` or
277  // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
278  string parent = 1 [(google.api.field_behavior) = REQUIRED];
279
280  // Optional. The collection ID, relative to `parent`, to list.
281  //
282  // For example: `chatrooms` or `messages`.
283  //
284  // This is optional, and when not provided, Firestore will list documents
285  // from all collections under the provided `parent`.
286  string collection_id = 2 [(google.api.field_behavior) = OPTIONAL];
287
288  // Optional. The maximum number of documents to return in a single response.
289  //
290  // Firestore may return fewer than this value.
291  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];
292
293  // Optional. A page token, received from a previous `ListDocuments` response.
294  //
295  // Provide this to retrieve the subsequent page. When paginating, all other
296  // parameters (with the exception of `page_size`) must match the values set
297  // in the request that generated the page token.
298  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];
299
300  // Optional. The optional ordering of the documents to return.
301  //
302  // For example: `priority desc, __name__ desc`.
303  //
304  // This mirrors the [`ORDER BY`][google.firestore.v1.StructuredQuery.order_by]
305  // used in Firestore queries but in a string representation. When absent,
306  // documents are ordered based on `__name__ ASC`.
307  string order_by = 6 [(google.api.field_behavior) = OPTIONAL];
308
309  // Optional. The fields to return. If not set, returns all fields.
310  //
311  // If a document has a field that is not present in this mask, that field
312  // will not be returned in the response.
313  DocumentMask mask = 7 [(google.api.field_behavior) = OPTIONAL];
314
315  // The consistency mode for this transaction.
316  // If not set, defaults to strong consistency.
317  oneof consistency_selector {
318    // Perform the read as part of an already active transaction.
319    bytes transaction = 8;
320
321    // Perform the read at the provided time.
322    //
323    // This must be a microsecond precision timestamp within the past one hour,
324    // or if Point-in-Time Recovery is enabled, can additionally be a whole
325    // minute timestamp within the past 7 days.
326    google.protobuf.Timestamp read_time = 10;
327  }
328
329  // If the list should show missing documents.
330  //
331  // A document is missing if it does not exist, but there are sub-documents
332  // nested underneath it. When true, such missing documents will be returned
333  // with a key but will not have fields,
334  // [`create_time`][google.firestore.v1.Document.create_time], or
335  // [`update_time`][google.firestore.v1.Document.update_time] set.
336  //
337  // Requests with `show_missing` may not specify `where` or `order_by`.
338  bool show_missing = 12;
339}
340
341// The response for
342// [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments].
343message ListDocumentsResponse {
344  // The Documents found.
345  repeated Document documents = 1;
346
347  // A token to retrieve the next page of documents.
348  //
349  // If this field is omitted, there are no subsequent pages.
350  string next_page_token = 2;
351}
352
353// The request for
354// [Firestore.CreateDocument][google.firestore.v1.Firestore.CreateDocument].
355message CreateDocumentRequest {
356  // Required. The parent resource. For example:
357  // `projects/{project_id}/databases/{database_id}/documents` or
358  // `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
359  string parent = 1 [(google.api.field_behavior) = REQUIRED];
360
361  // Required. The collection ID, relative to `parent`, to list. For example:
362  // `chatrooms`.
363  string collection_id = 2 [(google.api.field_behavior) = REQUIRED];
364
365  // The client-assigned document ID to use for this document.
366  //
367  // Optional. If not specified, an ID will be assigned by the service.
368  string document_id = 3;
369
370  // Required. The document to create. `name` must not be set.
371  Document document = 4 [(google.api.field_behavior) = REQUIRED];
372
373  // The fields to return. If not set, returns all fields.
374  //
375  // If the document has a field that is not present in this mask, that field
376  // will not be returned in the response.
377  DocumentMask mask = 5;
378}
379
380// The request for
381// [Firestore.UpdateDocument][google.firestore.v1.Firestore.UpdateDocument].
382message UpdateDocumentRequest {
383  // Required. The updated document.
384  // Creates the document if it does not already exist.
385  Document document = 1 [(google.api.field_behavior) = REQUIRED];
386
387  // The fields to update.
388  // None of the field paths in the mask may contain a reserved name.
389  //
390  // If the document exists on the server and has fields not referenced in the
391  // mask, they are left unchanged.
392  // Fields referenced in the mask, but not present in the input document, are
393  // deleted from the document on the server.
394  DocumentMask update_mask = 2;
395
396  // The fields to return. If not set, returns all fields.
397  //
398  // If the document has a field that is not present in this mask, that field
399  // will not be returned in the response.
400  DocumentMask mask = 3;
401
402  // An optional precondition on the document.
403  // The request will fail if this is set and not met by the target document.
404  Precondition current_document = 4;
405}
406
407// The request for
408// [Firestore.DeleteDocument][google.firestore.v1.Firestore.DeleteDocument].
409message DeleteDocumentRequest {
410  // Required. The resource name of the Document to delete. In the format:
411  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
412  string name = 1 [(google.api.field_behavior) = REQUIRED];
413
414  // An optional precondition on the document.
415  // The request will fail if this is set and not met by the target document.
416  Precondition current_document = 2;
417}
418
419// The request for
420// [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments].
421message BatchGetDocumentsRequest {
422  // Required. The database name. In the format:
423  // `projects/{project_id}/databases/{database_id}`.
424  string database = 1 [(google.api.field_behavior) = REQUIRED];
425
426  // The names of the documents to retrieve. In the format:
427  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
428  // The request will fail if any of the document is not a child resource of the
429  // given `database`. Duplicate names will be elided.
430  repeated string documents = 2;
431
432  // The fields to return. If not set, returns all fields.
433  //
434  // If a document has a field that is not present in this mask, that field will
435  // not be returned in the response.
436  DocumentMask mask = 3;
437
438  // The consistency mode for this transaction.
439  // If not set, defaults to strong consistency.
440  oneof consistency_selector {
441    // Reads documents in a transaction.
442    bytes transaction = 4;
443
444    // Starts a new transaction and reads the documents.
445    // Defaults to a read-only transaction.
446    // The new transaction ID will be returned as the first response in the
447    // stream.
448    TransactionOptions new_transaction = 5;
449
450    // Reads documents as they were at the given time.
451    //
452    // This must be a microsecond precision timestamp within the past one hour,
453    // or if Point-in-Time Recovery is enabled, can additionally be a whole
454    // minute timestamp within the past 7 days.
455    google.protobuf.Timestamp read_time = 7;
456  }
457}
458
459// The streamed response for
460// [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments].
461message BatchGetDocumentsResponse {
462  // A single result.
463  // This can be empty if the server is just returning a transaction.
464  oneof result {
465    // A document that was requested.
466    Document found = 1;
467
468    // A document name that was requested but does not exist. In the format:
469    // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
470    string missing = 2;
471  }
472
473  // The transaction that was started as part of this request.
474  // Will only be set in the first response, and only if
475  // [BatchGetDocumentsRequest.new_transaction][google.firestore.v1.BatchGetDocumentsRequest.new_transaction]
476  // was set in the request.
477  bytes transaction = 3;
478
479  // The time at which the document was read.
480  // This may be monotically increasing, in this case the previous documents in
481  // the result stream are guaranteed not to have changed between their
482  // read_time and this one.
483  google.protobuf.Timestamp read_time = 4;
484}
485
486// The request for
487// [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction].
488message BeginTransactionRequest {
489  // Required. The database name. In the format:
490  // `projects/{project_id}/databases/{database_id}`.
491  string database = 1 [(google.api.field_behavior) = REQUIRED];
492
493  // The options for the transaction.
494  // Defaults to a read-write transaction.
495  TransactionOptions options = 2;
496}
497
498// The response for
499// [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction].
500message BeginTransactionResponse {
501  // The transaction that was started.
502  bytes transaction = 1;
503}
504
505// The request for [Firestore.Commit][google.firestore.v1.Firestore.Commit].
506message CommitRequest {
507  // Required. The database name. In the format:
508  // `projects/{project_id}/databases/{database_id}`.
509  string database = 1 [(google.api.field_behavior) = REQUIRED];
510
511  // The writes to apply.
512  //
513  // Always executed atomically and in order.
514  repeated Write writes = 2;
515
516  // If set, applies all writes in this transaction, and commits it.
517  bytes transaction = 3;
518}
519
520// The response for [Firestore.Commit][google.firestore.v1.Firestore.Commit].
521message CommitResponse {
522  // The result of applying the writes.
523  //
524  // This i-th write result corresponds to the i-th write in the
525  // request.
526  repeated WriteResult write_results = 1;
527
528  // The time at which the commit occurred. Any read with an equal or greater
529  // `read_time` is guaranteed to see the effects of the commit.
530  google.protobuf.Timestamp commit_time = 2;
531}
532
533// The request for [Firestore.Rollback][google.firestore.v1.Firestore.Rollback].
534message RollbackRequest {
535  // Required. The database name. In the format:
536  // `projects/{project_id}/databases/{database_id}`.
537  string database = 1 [(google.api.field_behavior) = REQUIRED];
538
539  // Required. The transaction to roll back.
540  bytes transaction = 2 [(google.api.field_behavior) = REQUIRED];
541}
542
543// The request for [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery].
544message RunQueryRequest {
545  // Required. The parent resource name. In the format:
546  // `projects/{project_id}/databases/{database_id}/documents` or
547  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
548  // For example:
549  // `projects/my-project/databases/my-database/documents` or
550  // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
551  string parent = 1 [(google.api.field_behavior) = REQUIRED];
552
553  // The query to run.
554  oneof query_type {
555    // A structured query.
556    StructuredQuery structured_query = 2;
557  }
558
559  // The consistency mode for this transaction.
560  // If not set, defaults to strong consistency.
561  oneof consistency_selector {
562    // Run the query within an already active transaction.
563    //
564    // The value here is the opaque transaction ID to execute the query in.
565    bytes transaction = 5;
566
567    // Starts a new transaction and reads the documents.
568    // Defaults to a read-only transaction.
569    // The new transaction ID will be returned as the first response in the
570    // stream.
571    TransactionOptions new_transaction = 6;
572
573    // Reads documents as they were at the given time.
574    //
575    // This must be a microsecond precision timestamp within the past one hour,
576    // or if Point-in-Time Recovery is enabled, can additionally be a whole
577    // minute timestamp within the past 7 days.
578    google.protobuf.Timestamp read_time = 7;
579  }
580
581  // Optional. Explain options for the query. If set, additional query
582  // statistics will be returned. If not, only query results will be returned.
583  ExplainOptions explain_options = 10 [(google.api.field_behavior) = OPTIONAL];
584}
585
586// The response for
587// [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery].
588message RunQueryResponse {
589  // The transaction that was started as part of this request.
590  // Can only be set in the first response, and only if
591  // [RunQueryRequest.new_transaction][google.firestore.v1.RunQueryRequest.new_transaction]
592  // was set in the request. If set, no other fields will be set in this
593  // response.
594  bytes transaction = 2;
595
596  // A query result, not set when reporting partial progress.
597  Document document = 1;
598
599  // The time at which the document was read. This may be monotonically
600  // increasing; in this case, the previous documents in the result stream are
601  // guaranteed not to have changed between their `read_time` and this one.
602  //
603  // If the query returns no results, a response with `read_time` and no
604  // `document` will be sent, and this represents the time at which the query
605  // was run.
606  google.protobuf.Timestamp read_time = 3;
607
608  // The number of results that have been skipped due to an offset between
609  // the last response and the current response.
610  int32 skipped_results = 4;
611
612  // The continuation mode for the query. If present, it indicates the current
613  // query response stream has finished. This can be set with or without a
614  // `document` present, but when set, no more results are returned.
615  oneof continuation_selector {
616    // If present, Firestore has completely finished the request and no more
617    // documents will be returned.
618    bool done = 6;
619  }
620
621  // Query explain metrics. This is only present when the
622  // [RunQueryRequest.explain_options][google.firestore.v1.RunQueryRequest.explain_options]
623  // is provided, and it is sent only once with the last response in the stream.
624  ExplainMetrics explain_metrics = 11;
625}
626
627// The request for
628// [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
629message RunAggregationQueryRequest {
630  // Required. The parent resource name. In the format:
631  // `projects/{project_id}/databases/{database_id}/documents` or
632  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
633  // For example:
634  // `projects/my-project/databases/my-database/documents` or
635  // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
636  string parent = 1 [(google.api.field_behavior) = REQUIRED];
637
638  // The query to run.
639  oneof query_type {
640    // An aggregation query.
641    StructuredAggregationQuery structured_aggregation_query = 2;
642  }
643
644  // The consistency mode for the query, defaults to strong consistency.
645  oneof consistency_selector {
646    // Run the aggregation within an already active transaction.
647    //
648    // The value here is the opaque transaction ID to execute the query in.
649    bytes transaction = 4;
650
651    // Starts a new transaction as part of the query, defaulting to read-only.
652    //
653    // The new transaction ID will be returned as the first response in the
654    // stream.
655    TransactionOptions new_transaction = 5;
656
657    // Executes the query at the given timestamp.
658    //
659    // This must be a microsecond precision timestamp within the past one hour,
660    // or if Point-in-Time Recovery is enabled, can additionally be a whole
661    // minute timestamp within the past 7 days.
662    google.protobuf.Timestamp read_time = 6;
663  }
664
665  // Optional. Explain options for the query. If set, additional query
666  // statistics will be returned. If not, only query results will be returned.
667  ExplainOptions explain_options = 8 [(google.api.field_behavior) = OPTIONAL];
668}
669
670// The response for
671// [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
672message RunAggregationQueryResponse {
673  // A single aggregation result.
674  //
675  // Not present when reporting partial progress.
676  AggregationResult result = 1;
677
678  // The transaction that was started as part of this request.
679  //
680  // Only present on the first response when the request requested to start
681  // a new transaction.
682  bytes transaction = 2;
683
684  // The time at which the aggregate result was computed. This is always
685  // monotonically increasing; in this case, the previous AggregationResult in
686  // the result stream are guaranteed not to have changed between their
687  // `read_time` and this one.
688  //
689  // If the query returns no results, a response with `read_time` and no
690  // `result` will be sent, and this represents the time at which the query
691  // was run.
692  google.protobuf.Timestamp read_time = 3;
693
694  // Query explain metrics. This is only present when the
695  // [RunAggregationQueryRequest.explain_options][google.firestore.v1.RunAggregationQueryRequest.explain_options]
696  // is provided, and it is sent only once with the last response in the stream.
697  ExplainMetrics explain_metrics = 10;
698}
699
700// The request for
701// [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
702message PartitionQueryRequest {
703  // Required. The parent resource name. In the format:
704  // `projects/{project_id}/databases/{database_id}/documents`.
705  // Document resource names are not supported; only database resource names
706  // can be specified.
707  string parent = 1 [(google.api.field_behavior) = REQUIRED];
708
709  // The query to partition.
710  oneof query_type {
711    // A structured query.
712    // Query must specify collection with all descendants and be ordered by name
713    // ascending. Other filters, order bys, limits, offsets, and start/end
714    // cursors are not supported.
715    StructuredQuery structured_query = 2;
716  }
717
718  // The desired maximum number of partition points.
719  // The partitions may be returned across multiple pages of results.
720  // The number must be positive. The actual number of partitions
721  // returned may be fewer.
722  //
723  // For example, this may be set to one fewer than the number of parallel
724  // queries to be run, or in running a data pipeline job, one fewer than the
725  // number of workers or compute instances available.
726  int64 partition_count = 3;
727
728  // The `next_page_token` value returned from a previous call to
729  // PartitionQuery that may be used to get an additional set of results.
730  // There are no ordering guarantees between sets of results. Thus, using
731  // multiple sets of results will require merging the different result sets.
732  //
733  // For example, two subsequent calls using a page_token may return:
734  //
735  //  * cursor B, cursor M, cursor Q
736  //  * cursor A, cursor U, cursor W
737  //
738  // To obtain a complete result set ordered with respect to the results of the
739  // query supplied to PartitionQuery, the results sets should be merged:
740  // cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W
741  string page_token = 4;
742
743  // The maximum number of partitions to return in this call, subject to
744  // `partition_count`.
745  //
746  // For example, if `partition_count` = 10 and `page_size` = 8, the first call
747  // to PartitionQuery will return up to 8 partitions and a `next_page_token`
748  // if more results exist. A second call to PartitionQuery will return up to
749  // 2 partitions, to complete the total of 10 specified in `partition_count`.
750  int32 page_size = 5;
751
752  // The consistency mode for this request.
753  // If not set, defaults to strong consistency.
754  oneof consistency_selector {
755    // Reads documents as they were at the given time.
756    //
757    // This must be a microsecond precision timestamp within the past one hour,
758    // or if Point-in-Time Recovery is enabled, can additionally be a whole
759    // minute timestamp within the past 7 days.
760    google.protobuf.Timestamp read_time = 6;
761  }
762}
763
764// The response for
765// [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
766message PartitionQueryResponse {
767  // Partition results.
768  // Each partition is a split point that can be used by RunQuery as a starting
769  // or end point for the query results. The RunQuery requests must be made with
770  // the same query supplied to this PartitionQuery request. The partition
771  // cursors will be ordered according to same ordering as the results of the
772  // query supplied to PartitionQuery.
773  //
774  // For example, if a PartitionQuery request returns partition cursors A and B,
775  // running the following three queries will return the entire result set of
776  // the original query:
777  //
778  //  * query, end_at A
779  //  * query, start_at A, end_at B
780  //  * query, start_at B
781  //
782  // An empty result may indicate that the query has too few results to be
783  // partitioned, or that the query is not yet supported for partitioning.
784  repeated Cursor partitions = 1;
785
786  // A page token that may be used to request an additional set of results, up
787  // to the number specified by `partition_count` in the PartitionQuery request.
788  // If blank, there are no more results.
789  string next_page_token = 2;
790}
791
792// The request for [Firestore.Write][google.firestore.v1.Firestore.Write].
793//
794// The first request creates a stream, or resumes an existing one from a token.
795//
796// When creating a new stream, the server replies with a response containing
797// only an ID and a token, to use in the next request.
798//
799// When resuming a stream, the server first streams any responses later than the
800// given token, then a response containing only an up-to-date token, to use in
801// the next request.
802message WriteRequest {
803  // Required. The database name. In the format:
804  // `projects/{project_id}/databases/{database_id}`.
805  // This is only required in the first message.
806  string database = 1 [(google.api.field_behavior) = REQUIRED];
807
808  // The ID of the write stream to resume.
809  // This may only be set in the first message. When left empty, a new write
810  // stream will be created.
811  string stream_id = 2;
812
813  // The writes to apply.
814  //
815  // Always executed atomically and in order.
816  // This must be empty on the first request.
817  // This may be empty on the last request.
818  // This must not be empty on all other requests.
819  repeated Write writes = 3;
820
821  // A stream token that was previously sent by the server.
822  //
823  // The client should set this field to the token from the most recent
824  // [WriteResponse][google.firestore.v1.WriteResponse] it has received. This
825  // acknowledges that the client has received responses up to this token. After
826  // sending this token, earlier tokens may not be used anymore.
827  //
828  // The server may close the stream if there are too many unacknowledged
829  // responses.
830  //
831  // Leave this field unset when creating a new stream. To resume a stream at
832  // a specific point, set this field and the `stream_id` field.
833  //
834  // Leave this field unset when creating a new stream.
835  bytes stream_token = 4;
836
837  // Labels associated with this write request.
838  map<string, string> labels = 5;
839}
840
841// The response for [Firestore.Write][google.firestore.v1.Firestore.Write].
842message WriteResponse {
843  // The ID of the stream.
844  // Only set on the first message, when a new stream was created.
845  string stream_id = 1;
846
847  // A token that represents the position of this response in the stream.
848  // This can be used by a client to resume the stream at this point.
849  //
850  // This field is always set.
851  bytes stream_token = 2;
852
853  // The result of applying the writes.
854  //
855  // This i-th write result corresponds to the i-th write in the
856  // request.
857  repeated WriteResult write_results = 3;
858
859  // The time at which the commit occurred. Any read with an equal or greater
860  // `read_time` is guaranteed to see the effects of the write.
861  google.protobuf.Timestamp commit_time = 4;
862}
863
864// A request for [Firestore.Listen][google.firestore.v1.Firestore.Listen]
865message ListenRequest {
866  // Required. The database name. In the format:
867  // `projects/{project_id}/databases/{database_id}`.
868  string database = 1 [(google.api.field_behavior) = REQUIRED];
869
870  // The supported target changes.
871  oneof target_change {
872    // A target to add to this stream.
873    Target add_target = 2;
874
875    // The ID of a target to remove from this stream.
876    int32 remove_target = 3;
877  }
878
879  // Labels associated with this target change.
880  map<string, string> labels = 4;
881}
882
883// The response for [Firestore.Listen][google.firestore.v1.Firestore.Listen].
884message ListenResponse {
885  // The supported responses.
886  oneof response_type {
887    // Targets have changed.
888    TargetChange target_change = 2;
889
890    // A [Document][google.firestore.v1.Document] has changed.
891    DocumentChange document_change = 3;
892
893    // A [Document][google.firestore.v1.Document] has been deleted.
894    DocumentDelete document_delete = 4;
895
896    // A [Document][google.firestore.v1.Document] has been removed from a target
897    // (because it is no longer relevant to that target).
898    DocumentRemove document_remove = 6;
899
900    // A filter to apply to the set of documents previously returned for the
901    // given target.
902    //
903    // Returned when documents may have been removed from the given target, but
904    // the exact documents are unknown.
905    ExistenceFilter filter = 5;
906  }
907}
908
909// A specification of a set of documents to listen to.
910message Target {
911  // A target specified by a set of documents names.
912  message DocumentsTarget {
913    // The names of the documents to retrieve. In the format:
914    // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
915    // The request will fail if any of the document is not a child resource of
916    // the given `database`. Duplicate names will be elided.
917    repeated string documents = 2;
918  }
919
920  // A target specified by a query.
921  message QueryTarget {
922    // The parent resource name. In the format:
923    // `projects/{project_id}/databases/{database_id}/documents` or
924    // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
925    // For example:
926    // `projects/my-project/databases/my-database/documents` or
927    // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
928    string parent = 1;
929
930    // The query to run.
931    oneof query_type {
932      // A structured query.
933      StructuredQuery structured_query = 2;
934    }
935  }
936
937  // The type of target to listen to.
938  oneof target_type {
939    // A target specified by a query.
940    QueryTarget query = 2;
941
942    // A target specified by a set of document names.
943    DocumentsTarget documents = 3;
944  }
945
946  // When to start listening.
947  //
948  // If specified, only the matching Documents that have been updated AFTER the
949  // `resume_token` or `read_time` will be returned. Otherwise, all matching
950  // Documents are returned before any subsequent changes.
951  oneof resume_type {
952    // A resume token from a prior
953    // [TargetChange][google.firestore.v1.TargetChange] for an identical target.
954    //
955    // Using a resume token with a different target is unsupported and may fail.
956    bytes resume_token = 4;
957
958    // Start listening after a specific `read_time`.
959    //
960    // The client must know the state of matching documents at this time.
961    google.protobuf.Timestamp read_time = 11;
962  }
963
964  // The target ID that identifies the target on the stream. Must be a positive
965  // number and non-zero.
966  //
967  // If `target_id` is 0 (or unspecified), the server will assign an ID for this
968  // target and return that in a `TargetChange::ADD` event. Once a target with
969  // `target_id=0` is added, all subsequent targets must also have
970  // `target_id=0`. If an `AddTarget` request with `target_id != 0` is
971  // sent to the server after a target with `target_id=0` is added, the server
972  // will immediately send a response with a `TargetChange::Remove` event.
973  //
974  // Note that if the client sends multiple `AddTarget` requests
975  // without an ID, the order of IDs returned in `TargetChage.target_ids` are
976  // undefined. Therefore, clients should provide a target ID instead of relying
977  // on the server to assign one.
978  //
979  // If `target_id` is non-zero, there must not be an existing active target on
980  // this stream with the same ID.
981  int32 target_id = 5;
982
983  // If the target should be removed once it is current and consistent.
984  bool once = 6;
985
986  // The number of documents that last matched the query at the resume token or
987  // read time.
988  //
989  // This value is only relevant when a `resume_type` is provided. This value
990  // being present and greater than zero signals that the client wants
991  // `ExistenceFilter.unchanged_names` to be included in the response.
992  google.protobuf.Int32Value expected_count = 12;
993}
994
995// Targets being watched have changed.
996message TargetChange {
997  // The type of change.
998  enum TargetChangeType {
999    // No change has occurred. Used only to send an updated `resume_token`.
1000    NO_CHANGE = 0;
1001
1002    // The targets have been added.
1003    ADD = 1;
1004
1005    // The targets have been removed.
1006    REMOVE = 2;
1007
1008    // The targets reflect all changes committed before the targets were added
1009    // to the stream.
1010    //
1011    // This will be sent after or with a `read_time` that is greater than or
1012    // equal to the time at which the targets were added.
1013    //
1014    // Listeners can wait for this change if read-after-write semantics
1015    // are desired.
1016    CURRENT = 3;
1017
1018    // The targets have been reset, and a new initial state for the targets
1019    // will be returned in subsequent changes.
1020    //
1021    // After the initial state is complete, `CURRENT` will be returned even
1022    // if the target was previously indicated to be `CURRENT`.
1023    RESET = 4;
1024  }
1025
1026  // The type of change that occurred.
1027  TargetChangeType target_change_type = 1;
1028
1029  // The target IDs of targets that have changed.
1030  //
1031  // If empty, the change applies to all targets.
1032  //
1033  // The order of the target IDs is not defined.
1034  repeated int32 target_ids = 2;
1035
1036  // The error that resulted in this change, if applicable.
1037  google.rpc.Status cause = 3;
1038
1039  // A token that can be used to resume the stream for the given `target_ids`,
1040  // or all targets if `target_ids` is empty.
1041  //
1042  // Not set on every target change.
1043  bytes resume_token = 4;
1044
1045  // The consistent `read_time` for the given `target_ids` (omitted when the
1046  // target_ids are not at a consistent snapshot).
1047  //
1048  // The stream is guaranteed to send a `read_time` with `target_ids` empty
1049  // whenever the entire stream reaches a new consistent snapshot. ADD,
1050  // CURRENT, and RESET messages are guaranteed to (eventually) result in a
1051  // new consistent snapshot (while NO_CHANGE and REMOVE messages are not).
1052  //
1053  // For a given stream, `read_time` is guaranteed to be monotonically
1054  // increasing.
1055  google.protobuf.Timestamp read_time = 6;
1056}
1057
1058// The request for
1059// [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds].
1060message ListCollectionIdsRequest {
1061  // Required. The parent document. In the format:
1062  // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
1063  // For example:
1064  // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
1065  string parent = 1 [(google.api.field_behavior) = REQUIRED];
1066
1067  // The maximum number of results to return.
1068  int32 page_size = 2;
1069
1070  // A page token. Must be a value from
1071  // [ListCollectionIdsResponse][google.firestore.v1.ListCollectionIdsResponse].
1072  string page_token = 3;
1073
1074  // The consistency mode for this request.
1075  // If not set, defaults to strong consistency.
1076  oneof consistency_selector {
1077    // Reads documents as they were at the given time.
1078    //
1079    // This must be a microsecond precision timestamp within the past one hour,
1080    // or if Point-in-Time Recovery is enabled, can additionally be a whole
1081    // minute timestamp within the past 7 days.
1082    google.protobuf.Timestamp read_time = 4;
1083  }
1084}
1085
1086// The response from
1087// [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds].
1088message ListCollectionIdsResponse {
1089  // The collection ids.
1090  repeated string collection_ids = 1;
1091
1092  // A page token that may be used to continue the list.
1093  string next_page_token = 2;
1094}
1095
1096// The request for
1097// [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
1098message BatchWriteRequest {
1099  // Required. The database name. In the format:
1100  // `projects/{project_id}/databases/{database_id}`.
1101  string database = 1 [(google.api.field_behavior) = REQUIRED];
1102
1103  // The writes to apply.
1104  //
1105  // Method does not apply writes atomically and does not guarantee ordering.
1106  // Each write succeeds or fails independently. You cannot write to the same
1107  // document more than once per request.
1108  repeated Write writes = 2;
1109
1110  // Labels associated with this batch write.
1111  map<string, string> labels = 3;
1112}
1113
1114// The response from
1115// [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
1116message BatchWriteResponse {
1117  // The result of applying the writes.
1118  //
1119  // This i-th write result corresponds to the i-th write in the
1120  // request.
1121  repeated WriteResult write_results = 1;
1122
1123  // The status of applying the writes.
1124  //
1125  // This i-th write status corresponds to the i-th write in the
1126  // request.
1127  repeated google.rpc.Status status = 2;
1128}
1129