write.proto 11 KB

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