firestore.proto 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. // Copyright 2022 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/api/annotations.proto";
  17. import "google/api/client.proto";
  18. import "google/api/field_behavior.proto";
  19. import "google/firestore/v1/aggregation_result.proto";
  20. import "google/firestore/v1/common.proto";
  21. import "google/firestore/v1/document.proto";
  22. import "google/firestore/v1/query.proto";
  23. import "google/firestore/v1/write.proto";
  24. import "google/protobuf/empty.proto";
  25. import "google/protobuf/timestamp.proto";
  26. import "google/rpc/status.proto";
  27. option csharp_namespace = "Google.Cloud.Firestore.V1";
  28. option go_package = "google.golang.org/genproto/googleapis/firestore/v1;firestore";
  29. option java_multiple_files = true;
  30. option java_outer_classname = "FirestoreProto";
  31. option java_package = "com.google.firestore.v1";
  32. option php_namespace = "Google\\Cloud\\Firestore\\V1";
  33. option ruby_package = "Google::Cloud::Firestore::V1";
  34. // Specification of the Firestore API.
  35. // The Cloud Firestore service.
  36. //
  37. // Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL
  38. // document database that simplifies storing, syncing, and querying data for
  39. // your mobile, web, and IoT apps at global scale. Its client libraries provide
  40. // live synchronization and offline support, while its security features and
  41. // integrations with Firebase and Google Cloud Platform (GCP) accelerate
  42. // building truly serverless apps.
  43. service Firestore {
  44. option (google.api.default_host) = "firestore.googleapis.com";
  45. option (google.api.oauth_scopes) =
  46. "https://www.googleapis.com/auth/cloud-platform,"
  47. "https://www.googleapis.com/auth/datastore";
  48. // Gets a single document.
  49. rpc GetDocument(GetDocumentRequest) returns (Document) {
  50. option (google.api.http) = {
  51. get: "/v1/{name=projects/*/databases/*/documents/*/**}"
  52. };
  53. }
  54. // Lists documents.
  55. rpc ListDocuments(ListDocumentsRequest) returns (ListDocumentsResponse) {
  56. option (google.api.http) = {
  57. get: "/v1/{parent=projects/*/databases/*/documents/*/**}/{collection_id}"
  58. additional_bindings {
  59. get: "/v1/{parent=projects/*/databases/*/documents}/{collection_id}"
  60. }
  61. };
  62. }
  63. // Updates or inserts a document.
  64. rpc UpdateDocument(UpdateDocumentRequest) returns (Document) {
  65. option (google.api.http) = {
  66. patch: "/v1/{document.name=projects/*/databases/*/documents/*/**}"
  67. body: "document"
  68. };
  69. option (google.api.method_signature) = "document,update_mask";
  70. }
  71. // Deletes a document.
  72. rpc DeleteDocument(DeleteDocumentRequest) returns (google.protobuf.Empty) {
  73. option (google.api.http) = {
  74. delete: "/v1/{name=projects/*/databases/*/documents/*/**}"
  75. };
  76. option (google.api.method_signature) = "name";
  77. }
  78. // Gets multiple documents.
  79. //
  80. // Documents returned by this method are not guaranteed to be returned in the
  81. // same order that they were requested.
  82. rpc BatchGetDocuments(BatchGetDocumentsRequest) returns (stream BatchGetDocumentsResponse) {
  83. option (google.api.http) = {
  84. post: "/v1/{database=projects/*/databases/*}/documents:batchGet"
  85. body: "*"
  86. };
  87. }
  88. // Starts a new transaction.
  89. rpc BeginTransaction(BeginTransactionRequest) returns (BeginTransactionResponse) {
  90. option (google.api.http) = {
  91. post: "/v1/{database=projects/*/databases/*}/documents:beginTransaction"
  92. body: "*"
  93. };
  94. option (google.api.method_signature) = "database";
  95. }
  96. // Commits a transaction, while optionally updating documents.
  97. rpc Commit(CommitRequest) returns (CommitResponse) {
  98. option (google.api.http) = {
  99. post: "/v1/{database=projects/*/databases/*}/documents:commit"
  100. body: "*"
  101. };
  102. option (google.api.method_signature) = "database,writes";
  103. }
  104. // Rolls back a transaction.
  105. rpc Rollback(RollbackRequest) returns (google.protobuf.Empty) {
  106. option (google.api.http) = {
  107. post: "/v1/{database=projects/*/databases/*}/documents:rollback"
  108. body: "*"
  109. };
  110. option (google.api.method_signature) = "database,transaction";
  111. }
  112. // Runs a query.
  113. rpc RunQuery(RunQueryRequest) returns (stream RunQueryResponse) {
  114. option (google.api.http) = {
  115. post: "/v1/{parent=projects/*/databases/*/documents}:runQuery"
  116. body: "*"
  117. additional_bindings {
  118. post: "/v1/{parent=projects/*/databases/*/documents/*/**}:runQuery"
  119. body: "*"
  120. }
  121. };
  122. }
  123. // Runs an aggregation query.
  124. //
  125. // Rather than producing [Document][google.firestore.v1.Document] results like [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery],
  126. // this API allows running an aggregation to produce a series of
  127. // [AggregationResult][google.firestore.v1.AggregationResult] server-side.
  128. //
  129. // High-Level Example:
  130. //
  131. // ```
  132. // -- Return the number of documents in table given a filter.
  133. // SELECT COUNT(*) FROM ( SELECT * FROM k where a = true );
  134. // ```
  135. rpc RunAggregationQuery(RunAggregationQueryRequest) returns (stream RunAggregationQueryResponse) {
  136. option (google.api.http) = {
  137. post: "/v1/{parent=projects/*/databases/*/documents}:runAggregationQuery"
  138. body: "*"
  139. additional_bindings {
  140. post: "/v1/{parent=projects/*/databases/*/documents/*/**}:runAggregationQuery"
  141. body: "*"
  142. }
  143. };
  144. }
  145. // Partitions a query by returning partition cursors that can be used to run
  146. // the query in parallel. The returned partition cursors are split points that
  147. // can be used by RunQuery as starting/end points for the query results.
  148. rpc PartitionQuery(PartitionQueryRequest) returns (PartitionQueryResponse) {
  149. option (google.api.http) = {
  150. post: "/v1/{parent=projects/*/databases/*/documents}:partitionQuery"
  151. body: "*"
  152. additional_bindings {
  153. post: "/v1/{parent=projects/*/databases/*/documents/*/**}:partitionQuery"
  154. body: "*"
  155. }
  156. };
  157. }
  158. // Streams batches of document updates and deletes, in order.
  159. rpc Write(stream WriteRequest) returns (stream WriteResponse) {
  160. option (google.api.http) = {
  161. post: "/v1/{database=projects/*/databases/*}/documents:write"
  162. body: "*"
  163. };
  164. }
  165. // Listens to changes.
  166. rpc Listen(stream ListenRequest) returns (stream ListenResponse) {
  167. option (google.api.http) = {
  168. post: "/v1/{database=projects/*/databases/*}/documents:listen"
  169. body: "*"
  170. };
  171. }
  172. // Lists all the collection IDs underneath a document.
  173. rpc ListCollectionIds(ListCollectionIdsRequest) returns (ListCollectionIdsResponse) {
  174. option (google.api.http) = {
  175. post: "/v1/{parent=projects/*/databases/*/documents}:listCollectionIds"
  176. body: "*"
  177. additional_bindings {
  178. post: "/v1/{parent=projects/*/databases/*/documents/*/**}:listCollectionIds"
  179. body: "*"
  180. }
  181. };
  182. option (google.api.method_signature) = "parent";
  183. }
  184. // Applies a batch of write operations.
  185. //
  186. // The BatchWrite method does not apply the write operations atomically
  187. // and can apply them out of order. Method does not allow more than one write
  188. // per document. Each write succeeds or fails independently. See the
  189. // [BatchWriteResponse][google.firestore.v1.BatchWriteResponse] for the success status of each write.
  190. //
  191. // If you require an atomically applied set of writes, use
  192. // [Commit][google.firestore.v1.Firestore.Commit] instead.
  193. rpc BatchWrite(BatchWriteRequest) returns (BatchWriteResponse) {
  194. option (google.api.http) = {
  195. post: "/v1/{database=projects/*/databases/*}/documents:batchWrite"
  196. body: "*"
  197. };
  198. }
  199. // Creates a new document.
  200. rpc CreateDocument(CreateDocumentRequest) returns (Document) {
  201. option (google.api.http) = {
  202. post: "/v1/{parent=projects/*/databases/*/documents/**}/{collection_id}"
  203. body: "document"
  204. };
  205. }
  206. }
  207. // The request for [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument].
  208. message GetDocumentRequest {
  209. // Required. The resource name of the Document to get. In the format:
  210. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  211. string name = 1 [(google.api.field_behavior) = REQUIRED];
  212. // The fields to return. If not set, returns all fields.
  213. //
  214. // If the document has a field that is not present in this mask, that field
  215. // will not be returned in the response.
  216. DocumentMask mask = 2;
  217. // The consistency mode for this transaction.
  218. // If not set, defaults to strong consistency.
  219. oneof consistency_selector {
  220. // Reads the document in a transaction.
  221. bytes transaction = 3;
  222. // Reads the version of the document at the given time.
  223. // This may not be older than 270 seconds.
  224. google.protobuf.Timestamp read_time = 5;
  225. }
  226. }
  227. // The request for [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments].
  228. message ListDocumentsRequest {
  229. // Required. The parent resource name. In the format:
  230. // `projects/{project_id}/databases/{database_id}/documents` or
  231. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  232. // For example:
  233. // `projects/my-project/databases/my-database/documents` or
  234. // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
  235. string parent = 1 [(google.api.field_behavior) = REQUIRED];
  236. // Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`
  237. // or `messages`.
  238. string collection_id = 2 [(google.api.field_behavior) = REQUIRED];
  239. // The maximum number of documents to return.
  240. int32 page_size = 3;
  241. // The `next_page_token` value returned from a previous List request, if any.
  242. string page_token = 4;
  243. // The order to sort results by. For example: `priority desc, name`.
  244. string order_by = 6;
  245. // The fields to return. If not set, returns all fields.
  246. //
  247. // If a document has a field that is not present in this mask, that field
  248. // will not be returned in the response.
  249. DocumentMask mask = 7;
  250. // The consistency mode for this transaction.
  251. // If not set, defaults to strong consistency.
  252. oneof consistency_selector {
  253. // Reads documents in a transaction.
  254. bytes transaction = 8;
  255. // Reads documents as they were at the given time.
  256. // This may not be older than 270 seconds.
  257. google.protobuf.Timestamp read_time = 10;
  258. }
  259. // If the list should show missing documents. A missing document is a
  260. // document that does not exist but has sub-documents. These documents will
  261. // be returned with a key but will not have fields, [Document.create_time][google.firestore.v1.Document.create_time],
  262. // or [Document.update_time][google.firestore.v1.Document.update_time] set.
  263. //
  264. // Requests with `show_missing` may not specify `where` or
  265. // `order_by`.
  266. bool show_missing = 12;
  267. }
  268. // The response for [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments].
  269. message ListDocumentsResponse {
  270. // The Documents found.
  271. repeated Document documents = 1;
  272. // The next page token.
  273. string next_page_token = 2;
  274. }
  275. // The request for [Firestore.CreateDocument][google.firestore.v1.Firestore.CreateDocument].
  276. message CreateDocumentRequest {
  277. // Required. The parent resource. For example:
  278. // `projects/{project_id}/databases/{database_id}/documents` or
  279. // `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
  280. string parent = 1 [(google.api.field_behavior) = REQUIRED];
  281. // Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`.
  282. string collection_id = 2 [(google.api.field_behavior) = REQUIRED];
  283. // The client-assigned document ID to use for this document.
  284. //
  285. // Optional. If not specified, an ID will be assigned by the service.
  286. string document_id = 3;
  287. // Required. The document to create. `name` must not be set.
  288. Document document = 4 [(google.api.field_behavior) = REQUIRED];
  289. // The fields to return. If not set, returns all fields.
  290. //
  291. // If the document has a field that is not present in this mask, that field
  292. // will not be returned in the response.
  293. DocumentMask mask = 5;
  294. }
  295. // The request for [Firestore.UpdateDocument][google.firestore.v1.Firestore.UpdateDocument].
  296. message UpdateDocumentRequest {
  297. // Required. The updated document.
  298. // Creates the document if it does not already exist.
  299. Document document = 1 [(google.api.field_behavior) = REQUIRED];
  300. // The fields to update.
  301. // None of the field paths in the mask may contain a reserved name.
  302. //
  303. // If the document exists on the server and has fields not referenced in the
  304. // mask, they are left unchanged.
  305. // Fields referenced in the mask, but not present in the input document, are
  306. // deleted from the document on the server.
  307. DocumentMask update_mask = 2;
  308. // The fields to return. If not set, returns all fields.
  309. //
  310. // If the document has a field that is not present in this mask, that field
  311. // will not be returned in the response.
  312. DocumentMask mask = 3;
  313. // An optional precondition on the document.
  314. // The request will fail if this is set and not met by the target document.
  315. Precondition current_document = 4;
  316. }
  317. // The request for [Firestore.DeleteDocument][google.firestore.v1.Firestore.DeleteDocument].
  318. message DeleteDocumentRequest {
  319. // Required. The resource name of the Document to delete. In the format:
  320. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  321. string name = 1 [(google.api.field_behavior) = REQUIRED];
  322. // An optional precondition on the document.
  323. // The request will fail if this is set and not met by the target document.
  324. Precondition current_document = 2;
  325. }
  326. // The request for [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments].
  327. message BatchGetDocumentsRequest {
  328. // Required. The database name. In the format:
  329. // `projects/{project_id}/databases/{database_id}`.
  330. string database = 1 [(google.api.field_behavior) = REQUIRED];
  331. // The names of the documents to retrieve. In the format:
  332. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  333. // The request will fail if any of the document is not a child resource of the
  334. // given `database`. Duplicate names will be elided.
  335. repeated string documents = 2;
  336. // The fields to return. If not set, returns all fields.
  337. //
  338. // If a document has a field that is not present in this mask, that field will
  339. // not be returned in the response.
  340. DocumentMask mask = 3;
  341. // The consistency mode for this transaction.
  342. // If not set, defaults to strong consistency.
  343. oneof consistency_selector {
  344. // Reads documents in a transaction.
  345. bytes transaction = 4;
  346. // Starts a new transaction and reads the documents.
  347. // Defaults to a read-only transaction.
  348. // The new transaction ID will be returned as the first response in the
  349. // stream.
  350. TransactionOptions new_transaction = 5;
  351. // Reads documents as they were at the given time.
  352. // This may not be older than 270 seconds.
  353. google.protobuf.Timestamp read_time = 7;
  354. }
  355. }
  356. // The streamed response for [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments].
  357. message BatchGetDocumentsResponse {
  358. // A single result.
  359. // This can be empty if the server is just returning a transaction.
  360. oneof result {
  361. // A document that was requested.
  362. Document found = 1;
  363. // A document name that was requested but does not exist. In the format:
  364. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  365. string missing = 2;
  366. }
  367. // The transaction that was started as part of this request.
  368. // Will only be set in the first response, and only if
  369. // [BatchGetDocumentsRequest.new_transaction][google.firestore.v1.BatchGetDocumentsRequest.new_transaction] was set in the request.
  370. bytes transaction = 3;
  371. // The time at which the document was read.
  372. // This may be monotically increasing, in this case the previous documents in
  373. // the result stream are guaranteed not to have changed between their
  374. // read_time and this one.
  375. google.protobuf.Timestamp read_time = 4;
  376. }
  377. // The request for [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction].
  378. message BeginTransactionRequest {
  379. // Required. The database name. In the format:
  380. // `projects/{project_id}/databases/{database_id}`.
  381. string database = 1 [(google.api.field_behavior) = REQUIRED];
  382. // The options for the transaction.
  383. // Defaults to a read-write transaction.
  384. TransactionOptions options = 2;
  385. }
  386. // The response for [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction].
  387. message BeginTransactionResponse {
  388. // The transaction that was started.
  389. bytes transaction = 1;
  390. }
  391. // The request for [Firestore.Commit][google.firestore.v1.Firestore.Commit].
  392. message CommitRequest {
  393. // Required. The database name. In the format:
  394. // `projects/{project_id}/databases/{database_id}`.
  395. string database = 1 [(google.api.field_behavior) = REQUIRED];
  396. // The writes to apply.
  397. //
  398. // Always executed atomically and in order.
  399. repeated Write writes = 2;
  400. // If set, applies all writes in this transaction, and commits it.
  401. bytes transaction = 3;
  402. }
  403. // The response for [Firestore.Commit][google.firestore.v1.Firestore.Commit].
  404. message CommitResponse {
  405. // The result of applying the writes.
  406. //
  407. // This i-th write result corresponds to the i-th write in the
  408. // request.
  409. repeated WriteResult write_results = 1;
  410. // The time at which the commit occurred. Any read with an equal or greater
  411. // `read_time` is guaranteed to see the effects of the commit.
  412. google.protobuf.Timestamp commit_time = 2;
  413. }
  414. // The request for [Firestore.Rollback][google.firestore.v1.Firestore.Rollback].
  415. message RollbackRequest {
  416. // Required. The database name. In the format:
  417. // `projects/{project_id}/databases/{database_id}`.
  418. string database = 1 [(google.api.field_behavior) = REQUIRED];
  419. // Required. The transaction to roll back.
  420. bytes transaction = 2 [(google.api.field_behavior) = REQUIRED];
  421. }
  422. // The request for [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery].
  423. message RunQueryRequest {
  424. // Required. The parent resource name. In the format:
  425. // `projects/{project_id}/databases/{database_id}/documents` or
  426. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  427. // For example:
  428. // `projects/my-project/databases/my-database/documents` or
  429. // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
  430. string parent = 1 [(google.api.field_behavior) = REQUIRED];
  431. // The query to run.
  432. oneof query_type {
  433. // A structured query.
  434. StructuredQuery structured_query = 2;
  435. }
  436. // The consistency mode for this transaction.
  437. // If not set, defaults to strong consistency.
  438. oneof consistency_selector {
  439. // Run the query within an already active transaction.
  440. //
  441. // The value here is the opaque transaction ID to execute the query in.
  442. bytes transaction = 5;
  443. // Starts a new transaction and reads the documents.
  444. // Defaults to a read-only transaction.
  445. // The new transaction ID will be returned as the first response in the
  446. // stream.
  447. TransactionOptions new_transaction = 6;
  448. // Reads documents as they were at the given time.
  449. // This may not be older than 270 seconds.
  450. google.protobuf.Timestamp read_time = 7;
  451. }
  452. }
  453. // The response for [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery].
  454. message RunQueryResponse {
  455. // The transaction that was started as part of this request.
  456. // Can only be set in the first response, and only if
  457. // [RunQueryRequest.new_transaction][google.firestore.v1.RunQueryRequest.new_transaction] was set in the request.
  458. // If set, no other fields will be set in this response.
  459. bytes transaction = 2;
  460. // A query result, not set when reporting partial progress.
  461. Document document = 1;
  462. // The time at which the document was read. This may be monotonically
  463. // increasing; in this case, the previous documents in the result stream are
  464. // guaranteed not to have changed between their `read_time` and this one.
  465. //
  466. // If the query returns no results, a response with `read_time` and no
  467. // `document` will be sent, and this represents the time at which the query
  468. // was run.
  469. google.protobuf.Timestamp read_time = 3;
  470. // The number of results that have been skipped due to an offset between
  471. // the last response and the current response.
  472. int32 skipped_results = 4;
  473. // The continuation mode for the query. If present, it indicates the current
  474. // query response stream has finished. This can be set with or without a
  475. // `document` present, but when set, no more results are returned.
  476. oneof continuation_selector {
  477. // If present, Firestore has completely finished the request and no more
  478. // documents will be returned.
  479. bool done = 6;
  480. }
  481. }
  482. // The request for [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
  483. message RunAggregationQueryRequest {
  484. // Required. The parent resource name. In the format:
  485. // `projects/{project_id}/databases/{database_id}/documents` or
  486. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  487. // For example:
  488. // `projects/my-project/databases/my-database/documents` or
  489. // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
  490. string parent = 1 [(google.api.field_behavior) = REQUIRED];
  491. // The query to run.
  492. oneof query_type {
  493. // An aggregation query.
  494. StructuredAggregationQuery structured_aggregation_query = 2;
  495. }
  496. // The consistency mode for the query, defaults to strong consistency.
  497. oneof consistency_selector {
  498. // Run the aggregation within an already active transaction.
  499. //
  500. // The value here is the opaque transaction ID to execute the query in.
  501. bytes transaction = 4;
  502. // Starts a new transaction as part of the query, defaulting to read-only.
  503. //
  504. // The new transaction ID will be returned as the first response in the
  505. // stream.
  506. TransactionOptions new_transaction = 5;
  507. // Executes the query at the given timestamp.
  508. //
  509. // Requires:
  510. //
  511. // * Cannot be more than 270 seconds in the past.
  512. google.protobuf.Timestamp read_time = 6;
  513. }
  514. }
  515. // The response for [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery].
  516. message RunAggregationQueryResponse {
  517. // A single aggregation result.
  518. //
  519. // Not present when reporting partial progress.
  520. AggregationResult result = 1;
  521. // The transaction that was started as part of this request.
  522. //
  523. // Only present on the first response when the request requested to start
  524. // a new transaction.
  525. bytes transaction = 2;
  526. // The time at which the aggregate value is valid for.
  527. google.protobuf.Timestamp read_time = 3;
  528. }
  529. // The request for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
  530. message PartitionQueryRequest {
  531. // Required. The parent resource name. In the format:
  532. // `projects/{project_id}/databases/{database_id}/documents`.
  533. // Document resource names are not supported; only database resource names
  534. // can be specified.
  535. string parent = 1 [(google.api.field_behavior) = REQUIRED];
  536. // The query to partition.
  537. oneof query_type {
  538. // A structured query.
  539. // Query must specify collection with all descendants and be ordered by name
  540. // ascending. Other filters, order bys, limits, offsets, and start/end
  541. // cursors are not supported.
  542. StructuredQuery structured_query = 2;
  543. }
  544. // The desired maximum number of partition points.
  545. // The partitions may be returned across multiple pages of results.
  546. // The number must be positive. The actual number of partitions
  547. // returned may be fewer.
  548. //
  549. // For example, this may be set to one fewer than the number of parallel
  550. // queries to be run, or in running a data pipeline job, one fewer than the
  551. // number of workers or compute instances available.
  552. int64 partition_count = 3;
  553. // The `next_page_token` value returned from a previous call to
  554. // PartitionQuery that may be used to get an additional set of results.
  555. // There are no ordering guarantees between sets of results. Thus, using
  556. // multiple sets of results will require merging the different result sets.
  557. //
  558. // For example, two subsequent calls using a page_token may return:
  559. //
  560. // * cursor B, cursor M, cursor Q
  561. // * cursor A, cursor U, cursor W
  562. //
  563. // To obtain a complete result set ordered with respect to the results of the
  564. // query supplied to PartitionQuery, the results sets should be merged:
  565. // cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W
  566. string page_token = 4;
  567. // The maximum number of partitions to return in this call, subject to
  568. // `partition_count`.
  569. //
  570. // For example, if `partition_count` = 10 and `page_size` = 8, the first call
  571. // to PartitionQuery will return up to 8 partitions and a `next_page_token`
  572. // if more results exist. A second call to PartitionQuery will return up to
  573. // 2 partitions, to complete the total of 10 specified in `partition_count`.
  574. int32 page_size = 5;
  575. // The consistency mode for this request.
  576. // If not set, defaults to strong consistency.
  577. oneof consistency_selector {
  578. // Reads documents as they were at the given time.
  579. // This may not be older than 270 seconds.
  580. google.protobuf.Timestamp read_time = 6;
  581. }
  582. }
  583. // The response for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery].
  584. message PartitionQueryResponse {
  585. // Partition results.
  586. // Each partition is a split point that can be used by RunQuery as a starting
  587. // or end point for the query results. The RunQuery requests must be made with
  588. // the same query supplied to this PartitionQuery request. The partition
  589. // cursors will be ordered according to same ordering as the results of the
  590. // query supplied to PartitionQuery.
  591. //
  592. // For example, if a PartitionQuery request returns partition cursors A and B,
  593. // running the following three queries will return the entire result set of
  594. // the original query:
  595. //
  596. // * query, end_at A
  597. // * query, start_at A, end_at B
  598. // * query, start_at B
  599. //
  600. // An empty result may indicate that the query has too few results to be
  601. // partitioned.
  602. repeated Cursor partitions = 1;
  603. // A page token that may be used to request an additional set of results, up
  604. // to the number specified by `partition_count` in the PartitionQuery request.
  605. // If blank, there are no more results.
  606. string next_page_token = 2;
  607. }
  608. // The request for [Firestore.Write][google.firestore.v1.Firestore.Write].
  609. //
  610. // The first request creates a stream, or resumes an existing one from a token.
  611. //
  612. // When creating a new stream, the server replies with a response containing
  613. // only an ID and a token, to use in the next request.
  614. //
  615. // When resuming a stream, the server first streams any responses later than the
  616. // given token, then a response containing only an up-to-date token, to use in
  617. // the next request.
  618. message WriteRequest {
  619. // Required. The database name. In the format:
  620. // `projects/{project_id}/databases/{database_id}`.
  621. // This is only required in the first message.
  622. string database = 1 [(google.api.field_behavior) = REQUIRED];
  623. // The ID of the write stream to resume.
  624. // This may only be set in the first message. When left empty, a new write
  625. // stream will be created.
  626. string stream_id = 2;
  627. // The writes to apply.
  628. //
  629. // Always executed atomically and in order.
  630. // This must be empty on the first request.
  631. // This may be empty on the last request.
  632. // This must not be empty on all other requests.
  633. repeated Write writes = 3;
  634. // A stream token that was previously sent by the server.
  635. //
  636. // The client should set this field to the token from the most recent
  637. // [WriteResponse][google.firestore.v1.WriteResponse] it has received. This acknowledges that the client has
  638. // received responses up to this token. After sending this token, earlier
  639. // tokens may not be used anymore.
  640. //
  641. // The server may close the stream if there are too many unacknowledged
  642. // responses.
  643. //
  644. // Leave this field unset when creating a new stream. To resume a stream at
  645. // a specific point, set this field and the `stream_id` field.
  646. //
  647. // Leave this field unset when creating a new stream.
  648. bytes stream_token = 4;
  649. // Labels associated with this write request.
  650. map<string, string> labels = 5;
  651. }
  652. // The response for [Firestore.Write][google.firestore.v1.Firestore.Write].
  653. message WriteResponse {
  654. // The ID of the stream.
  655. // Only set on the first message, when a new stream was created.
  656. string stream_id = 1;
  657. // A token that represents the position of this response in the stream.
  658. // This can be used by a client to resume the stream at this point.
  659. //
  660. // This field is always set.
  661. bytes stream_token = 2;
  662. // The result of applying the writes.
  663. //
  664. // This i-th write result corresponds to the i-th write in the
  665. // request.
  666. repeated WriteResult write_results = 3;
  667. // The time at which the commit occurred. Any read with an equal or greater
  668. // `read_time` is guaranteed to see the effects of the write.
  669. google.protobuf.Timestamp commit_time = 4;
  670. }
  671. // A request for [Firestore.Listen][google.firestore.v1.Firestore.Listen]
  672. message ListenRequest {
  673. // Required. The database name. In the format:
  674. // `projects/{project_id}/databases/{database_id}`.
  675. string database = 1 [(google.api.field_behavior) = REQUIRED];
  676. // The supported target changes.
  677. oneof target_change {
  678. // A target to add to this stream.
  679. Target add_target = 2;
  680. // The ID of a target to remove from this stream.
  681. int32 remove_target = 3;
  682. }
  683. // Labels associated with this target change.
  684. map<string, string> labels = 4;
  685. }
  686. // The response for [Firestore.Listen][google.firestore.v1.Firestore.Listen].
  687. message ListenResponse {
  688. // The supported responses.
  689. oneof response_type {
  690. // Targets have changed.
  691. TargetChange target_change = 2;
  692. // A [Document][google.firestore.v1.Document] has changed.
  693. DocumentChange document_change = 3;
  694. // A [Document][google.firestore.v1.Document] has been deleted.
  695. DocumentDelete document_delete = 4;
  696. // A [Document][google.firestore.v1.Document] has been removed from a target (because it is no longer
  697. // relevant to that target).
  698. DocumentRemove document_remove = 6;
  699. // A filter to apply to the set of documents previously returned for the
  700. // given target.
  701. //
  702. // Returned when documents may have been removed from the given target, but
  703. // the exact documents are unknown.
  704. ExistenceFilter filter = 5;
  705. }
  706. }
  707. // A specification of a set of documents to listen to.
  708. message Target {
  709. // A target specified by a set of documents names.
  710. message DocumentsTarget {
  711. // The names of the documents to retrieve. In the format:
  712. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  713. // The request will fail if any of the document is not a child resource of
  714. // the given `database`. Duplicate names will be elided.
  715. repeated string documents = 2;
  716. }
  717. // A target specified by a query.
  718. message QueryTarget {
  719. // The parent resource name. In the format:
  720. // `projects/{project_id}/databases/{database_id}/documents` or
  721. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  722. // For example:
  723. // `projects/my-project/databases/my-database/documents` or
  724. // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
  725. string parent = 1;
  726. // The query to run.
  727. oneof query_type {
  728. // A structured query.
  729. StructuredQuery structured_query = 2;
  730. }
  731. }
  732. // The type of target to listen to.
  733. oneof target_type {
  734. // A target specified by a query.
  735. QueryTarget query = 2;
  736. // A target specified by a set of document names.
  737. DocumentsTarget documents = 3;
  738. }
  739. // When to start listening.
  740. //
  741. // If not specified, all matching Documents are returned before any
  742. // subsequent changes.
  743. oneof resume_type {
  744. // A resume token from a prior [TargetChange][google.firestore.v1.TargetChange] for an identical target.
  745. //
  746. // Using a resume token with a different target is unsupported and may fail.
  747. bytes resume_token = 4;
  748. // Start listening after a specific `read_time`.
  749. //
  750. // The client must know the state of matching documents at this time.
  751. google.protobuf.Timestamp read_time = 11;
  752. }
  753. // The target ID that identifies the target on the stream. Must be a positive
  754. // number and non-zero.
  755. int32 target_id = 5;
  756. // If the target should be removed once it is current and consistent.
  757. bool once = 6;
  758. }
  759. // Targets being watched have changed.
  760. message TargetChange {
  761. // The type of change.
  762. enum TargetChangeType {
  763. // No change has occurred. Used only to send an updated `resume_token`.
  764. NO_CHANGE = 0;
  765. // The targets have been added.
  766. ADD = 1;
  767. // The targets have been removed.
  768. REMOVE = 2;
  769. // The targets reflect all changes committed before the targets were added
  770. // to the stream.
  771. //
  772. // This will be sent after or with a `read_time` that is greater than or
  773. // equal to the time at which the targets were added.
  774. //
  775. // Listeners can wait for this change if read-after-write semantics
  776. // are desired.
  777. CURRENT = 3;
  778. // The targets have been reset, and a new initial state for the targets
  779. // will be returned in subsequent changes.
  780. //
  781. // After the initial state is complete, `CURRENT` will be returned even
  782. // if the target was previously indicated to be `CURRENT`.
  783. RESET = 4;
  784. }
  785. // The type of change that occurred.
  786. TargetChangeType target_change_type = 1;
  787. // The target IDs of targets that have changed.
  788. //
  789. // If empty, the change applies to all targets.
  790. //
  791. // The order of the target IDs is not defined.
  792. repeated int32 target_ids = 2;
  793. // The error that resulted in this change, if applicable.
  794. google.rpc.Status cause = 3;
  795. // A token that can be used to resume the stream for the given `target_ids`,
  796. // or all targets if `target_ids` is empty.
  797. //
  798. // Not set on every target change.
  799. bytes resume_token = 4;
  800. // The consistent `read_time` for the given `target_ids` (omitted when the
  801. // target_ids are not at a consistent snapshot).
  802. //
  803. // The stream is guaranteed to send a `read_time` with `target_ids` empty
  804. // whenever the entire stream reaches a new consistent snapshot. ADD,
  805. // CURRENT, and RESET messages are guaranteed to (eventually) result in a
  806. // new consistent snapshot (while NO_CHANGE and REMOVE messages are not).
  807. //
  808. // For a given stream, `read_time` is guaranteed to be monotonically
  809. // increasing.
  810. google.protobuf.Timestamp read_time = 6;
  811. }
  812. // The request for [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds].
  813. message ListCollectionIdsRequest {
  814. // Required. The parent document. In the format:
  815. // `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
  816. // For example:
  817. // `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
  818. string parent = 1 [(google.api.field_behavior) = REQUIRED];
  819. // The maximum number of results to return.
  820. int32 page_size = 2;
  821. // A page token. Must be a value from
  822. // [ListCollectionIdsResponse][google.firestore.v1.ListCollectionIdsResponse].
  823. string page_token = 3;
  824. // The consistency mode for this request.
  825. // If not set, defaults to strong consistency.
  826. oneof consistency_selector {
  827. // Reads documents as they were at the given time.
  828. // This may not be older than 270 seconds.
  829. google.protobuf.Timestamp read_time = 4;
  830. }
  831. }
  832. // The response from [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds].
  833. message ListCollectionIdsResponse {
  834. // The collection ids.
  835. repeated string collection_ids = 1;
  836. // A page token that may be used to continue the list.
  837. string next_page_token = 2;
  838. }
  839. // The request for [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
  840. message BatchWriteRequest {
  841. // Required. The database name. In the format:
  842. // `projects/{project_id}/databases/{database_id}`.
  843. string database = 1 [(google.api.field_behavior) = REQUIRED];
  844. // The writes to apply.
  845. //
  846. // Method does not apply writes atomically and does not guarantee ordering.
  847. // Each write succeeds or fails independently. You cannot write to the same
  848. // document more than once per request.
  849. repeated Write writes = 2;
  850. // Labels associated with this batch write.
  851. map<string, string> labels = 3;
  852. }
  853. // The response from [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite].
  854. message BatchWriteResponse {
  855. // The result of applying the writes.
  856. //
  857. // This i-th write result corresponds to the i-th write in the
  858. // request.
  859. repeated WriteResult write_results = 1;
  860. // The status of applying the writes.
  861. //
  862. // This i-th write status corresponds to the i-th write in the
  863. // request.
  864. repeated google.rpc.Status status = 2;
  865. }