write.proto 11 KB

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