write.proto 11 KB

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