xref: /aosp_15_r20/external/googleapis/google/firestore/v1beta1/write.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2021 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.v1beta1;
18
19import "google/firestore/v1beta1/common.proto";
20import "google/firestore/v1beta1/document.proto";
21import "google/protobuf/timestamp.proto";
22
23option csharp_namespace = "Google.Cloud.Firestore.V1Beta1";
24option go_package = "cloud.google.com/go/firestore/apiv1beta1/firestorepb;firestorepb";
25option java_multiple_files = true;
26option java_outer_classname = "WriteProto";
27option java_package = "com.google.firestore.v1beta1";
28option objc_class_prefix = "GCFS";
29option php_namespace = "Google\\Cloud\\Firestore\\V1beta1";
30option ruby_package = "Google::Cloud::Firestore::V1beta1";
31
32// A write on a document.
33message Write {
34  // The operation to execute.
35  oneof operation {
36    // A document to write.
37    Document update = 1;
38
39    // A document name to delete. In the format:
40    // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
41    string delete = 2;
42
43    // Applies a transformation to a document.
44    DocumentTransform transform = 6;
45  }
46
47  // The fields to update in this write.
48  //
49  // This field can be set only when the operation is `update`.
50  // If the mask is not set for an `update` and the document exists, any
51  // existing data will be overwritten.
52  // If the mask is set and the document on the server has fields not covered by
53  // the mask, they are left unchanged.
54  // Fields referenced in the mask, but not present in the input document, are
55  // deleted from the document on the server.
56  // The field paths in this mask must not contain a reserved field name.
57  DocumentMask update_mask = 3;
58
59  // The transforms to perform after update.
60  //
61  // This field can be set only when the operation is `update`. If present, this
62  // write is equivalent to performing `update` and `transform` to the same
63  // document atomically and in order.
64  repeated DocumentTransform.FieldTransform update_transforms = 7;
65
66  // An optional precondition on the document.
67  //
68  // The write will fail if this is set and not met by the target document.
69  Precondition current_document = 4;
70}
71
72// A transformation of a document.
73message DocumentTransform {
74  // A transformation of a field of the document.
75  message FieldTransform {
76    // A value that is calculated by the server.
77    enum ServerValue {
78      // Unspecified. This value must not be used.
79      SERVER_VALUE_UNSPECIFIED = 0;
80
81      // The time at which the server processed the request, with millisecond
82      // precision. If used on multiple fields (same or different documents) in
83      // a transaction, all the fields will get the same server timestamp.
84      REQUEST_TIME = 1;
85    }
86
87    // The path of the field. See [Document.fields][google.firestore.v1beta1.Document.fields] for the field path syntax
88    // reference.
89    string field_path = 1;
90
91    // The transformation to apply on the field.
92    oneof transform_type {
93      // Sets the field to the given server value.
94      ServerValue set_to_server_value = 2;
95
96      // Adds the given value to the field's current value.
97      //
98      // This must be an integer or a double value.
99      // If the field is not an integer or double, or if the field does not yet
100      // exist, the transformation will set the field to the given value.
101      // If either of the given value or the current field value are doubles,
102      // both values will be interpreted as doubles. Double arithmetic and
103      // representation of double values follow IEEE 754 semantics.
104      // If there is positive/negative integer overflow, the field is resolved
105      // to the largest magnitude positive/negative integer.
106      Value increment = 3;
107
108      // Sets the field to the maximum of its current value and the given value.
109      //
110      // This must be an integer or a double value.
111      // If the field is not an integer or double, or if the field does not yet
112      // exist, the transformation will set the field to the given value.
113      // If a maximum operation is applied where the field and the input value
114      // are of mixed types (that is - one is an integer and one is a double)
115      // the field takes on the type of the larger operand. If the operands are
116      // equivalent (e.g. 3 and 3.0), the field does not change.
117      // 0, 0.0, and -0.0 are all zero. The maximum of a zero stored value and
118      // zero input value is always the stored value.
119      // The maximum of any numeric value x and NaN is NaN.
120      Value maximum = 4;
121
122      // Sets the field to the minimum of its current value and the given value.
123      //
124      // This must be an integer or a double value.
125      // If the field is not an integer or double, or if the field does not yet
126      // exist, the transformation will set the field to the input value.
127      // If a minimum operation is applied where the field and the input value
128      // are of mixed types (that is - one is an integer and one is a double)
129      // the field takes on the type of the smaller operand. If the operands are
130      // equivalent (e.g. 3 and 3.0), the field does not change.
131      // 0, 0.0, and -0.0 are all zero. The minimum of a zero stored value and
132      // zero input value is always the stored value.
133      // The minimum of any numeric value x and NaN is NaN.
134      Value minimum = 5;
135
136      // Append the given elements in order if they are not already present in
137      // the current field value.
138      // If the field is not an array, or if the field does not yet exist, it is
139      // first set to the empty array.
140      //
141      // Equivalent numbers of different types (e.g. 3L and 3.0) are
142      // considered equal when checking if a value is missing.
143      // NaN is equal to NaN, and Null is equal to Null.
144      // If the input contains multiple equivalent values, only the first will
145      // be considered.
146      //
147      // The corresponding transform_result will be the null value.
148      ArrayValue append_missing_elements = 6;
149
150      // Remove all of the given elements from the array in the field.
151      // If the field is not an array, or if the field does not yet exist, it is
152      // set to the empty array.
153      //
154      // Equivalent numbers of the different types (e.g. 3L and 3.0) are
155      // considered equal when deciding whether an element should be removed.
156      // NaN is equal to NaN, and Null is equal to Null.
157      // This will remove all equivalent values if there are duplicates.
158      //
159      // The corresponding transform_result will be the null value.
160      ArrayValue remove_all_from_array = 7;
161    }
162  }
163
164  // The name of the document to transform.
165  string document = 1;
166
167  // The list of transformations to apply to the fields of the document, in
168  // order.
169  // This must not be empty.
170  repeated FieldTransform field_transforms = 2;
171}
172
173// The result of applying a write.
174message WriteResult {
175  // The last update time of the document after applying the write. Not set
176  // after a `delete`.
177  //
178  // If the write did not actually change the document, this will be the
179  // previous update_time.
180  google.protobuf.Timestamp update_time = 1;
181
182  // The results of applying each [DocumentTransform.FieldTransform][google.firestore.v1beta1.DocumentTransform.FieldTransform], in the
183  // same order.
184  repeated Value transform_results = 2;
185}
186
187// A [Document][google.firestore.v1beta1.Document] has changed.
188//
189// May be the result of multiple [writes][google.firestore.v1beta1.Write], including deletes, that
190// ultimately resulted in a new value for the [Document][google.firestore.v1beta1.Document].
191//
192// Multiple [DocumentChange][google.firestore.v1beta1.DocumentChange] messages may be returned for the same logical
193// change, if multiple targets are affected.
194message DocumentChange {
195  // The new state of the [Document][google.firestore.v1beta1.Document].
196  //
197  // If `mask` is set, contains only fields that were updated or added.
198  Document document = 1;
199
200  // A set of target IDs of targets that match this document.
201  repeated int32 target_ids = 5;
202
203  // A set of target IDs for targets that no longer match this document.
204  repeated int32 removed_target_ids = 6;
205}
206
207// A [Document][google.firestore.v1beta1.Document] has been deleted.
208//
209// May be the result of multiple [writes][google.firestore.v1beta1.Write], including updates, the
210// last of which deleted the [Document][google.firestore.v1beta1.Document].
211//
212// Multiple [DocumentDelete][google.firestore.v1beta1.DocumentDelete] messages may be returned for the same logical
213// delete, if multiple targets are affected.
214message DocumentDelete {
215  // The resource name of the [Document][google.firestore.v1beta1.Document] that was deleted.
216  string document = 1;
217
218  // A set of target IDs for targets that previously matched this entity.
219  repeated int32 removed_target_ids = 6;
220
221  // The read timestamp at which the delete was observed.
222  //
223  // Greater or equal to the `commit_time` of the delete.
224  google.protobuf.Timestamp read_time = 4;
225}
226
227// A [Document][google.firestore.v1beta1.Document] has been removed from the view of the targets.
228//
229// Sent if the document is no longer relevant to a target and is out of view.
230// Can be sent instead of a DocumentDelete or a DocumentChange if the server
231// can not send the new value of the document.
232//
233// Multiple [DocumentRemove][google.firestore.v1beta1.DocumentRemove] messages may be returned for the same logical
234// write or delete, if multiple targets are affected.
235message DocumentRemove {
236  // The resource name of the [Document][google.firestore.v1beta1.Document] that has gone out of view.
237  string document = 1;
238
239  // A set of target IDs for targets that previously matched this document.
240  repeated int32 removed_target_ids = 2;
241
242  // The read timestamp at which the remove was observed.
243  //
244  // Greater or equal to the `commit_time` of the change/delete/remove.
245  google.protobuf.Timestamp read_time = 4;
246}
247
248// A digest of all the documents that match a given target.
249message ExistenceFilter {
250  // The target ID to which this filter applies.
251  int32 target_id = 1;
252
253  // The total count of documents that match [target_id][google.firestore.v1beta1.ExistenceFilter.target_id].
254  //
255  // If different from the count of documents in the client that match, the
256  // client must manually determine which documents no longer match the target.
257  int32 count = 2;
258}
259