write.proto 11 KB

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