google-cloud-firestore 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,6 @@
4
4
  "retry_codes": {
5
5
  "idempotent": [
6
6
  "DEADLINE_EXCEEDED",
7
- "INTERNAL",
8
7
  "UNAVAILABLE"
9
8
  ],
10
9
  "non_idempotent": []
@@ -56,7 +55,7 @@
56
55
  "retry_params_name": "default"
57
56
  },
58
57
  "BatchGetDocuments": {
59
- "timeout_millis": 300000,
58
+ "timeout_millis": 60000,
60
59
  "retry_codes_name": "idempotent",
61
60
  "retry_params_name": "streaming"
62
61
  },
@@ -81,18 +80,18 @@
81
80
  "retry_params_name": "streaming"
82
81
  },
83
82
  "Write": {
84
- "timeout_millis": 86400000,
83
+ "timeout_millis": 60000,
85
84
  "retry_codes_name": "non_idempotent",
86
85
  "retry_params_name": "streaming"
87
86
  },
88
87
  "Listen": {
89
- "timeout_millis": 86400000,
88
+ "timeout_millis": 60000,
90
89
  "retry_codes_name": "idempotent",
91
90
  "retry_params_name": "streaming"
92
91
  },
93
92
  "ListCollectionIds": {
94
93
  "timeout_millis": 60000,
95
- "retry_codes_name": "idempotent",
94
+ "retry_codes_name": "non_idempotent",
96
95
  "retry_params_name": "default"
97
96
  }
98
97
  }
@@ -68,14 +68,14 @@ module Google
68
68
  DEFAULT_TIMEOUT = 30
69
69
 
70
70
  PAGE_DESCRIPTORS = {
71
- "list_documents" => Google::Gax::PageDescriptor.new(
71
+ "list_collection_ids" => Google::Gax::PageDescriptor.new(
72
72
  "page_token",
73
73
  "next_page_token",
74
- "documents"),
75
- "list_collection_ids" => Google::Gax::PageDescriptor.new(
74
+ "collection_ids"),
75
+ "list_documents" => Google::Gax::PageDescriptor.new(
76
76
  "page_token",
77
77
  "next_page_token",
78
- "collection_ids")
78
+ "documents")
79
79
  }.freeze
80
80
 
81
81
  private_constant :PAGE_DESCRIPTORS
@@ -88,80 +88,6 @@ module Google
88
88
  ].freeze
89
89
 
90
90
 
91
- ANY_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
92
- "projects/{project}/databases/{database}/documents/{document}/{any_path=**}"
93
- )
94
-
95
- private_constant :ANY_PATH_PATH_TEMPLATE
96
-
97
- DATABASE_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
98
- "projects/{project}/databases/{database}"
99
- )
100
-
101
- private_constant :DATABASE_ROOT_PATH_TEMPLATE
102
-
103
- DOCUMENT_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
104
- "projects/{project}/databases/{database}/documents/{document_path=**}"
105
- )
106
-
107
- private_constant :DOCUMENT_PATH_PATH_TEMPLATE
108
-
109
- DOCUMENT_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
110
- "projects/{project}/databases/{database}/documents"
111
- )
112
-
113
- private_constant :DOCUMENT_ROOT_PATH_TEMPLATE
114
-
115
- # Returns a fully-qualified any_path resource name string.
116
- # @param project [String]
117
- # @param database [String]
118
- # @param document [String]
119
- # @param any_path [String]
120
- # @return [String]
121
- def self.any_path_path project, database, document, any_path
122
- ANY_PATH_PATH_TEMPLATE.render(
123
- :"project" => project,
124
- :"database" => database,
125
- :"document" => document,
126
- :"any_path" => any_path
127
- )
128
- end
129
-
130
- # Returns a fully-qualified database_root resource name string.
131
- # @param project [String]
132
- # @param database [String]
133
- # @return [String]
134
- def self.database_root_path project, database
135
- DATABASE_ROOT_PATH_TEMPLATE.render(
136
- :"project" => project,
137
- :"database" => database
138
- )
139
- end
140
-
141
- # Returns a fully-qualified document_path resource name string.
142
- # @param project [String]
143
- # @param database [String]
144
- # @param document_path [String]
145
- # @return [String]
146
- def self.document_path_path project, database, document_path
147
- DOCUMENT_PATH_PATH_TEMPLATE.render(
148
- :"project" => project,
149
- :"database" => database,
150
- :"document_path" => document_path
151
- )
152
- end
153
-
154
- # Returns a fully-qualified document_root resource name string.
155
- # @param project [String]
156
- # @param database [String]
157
- # @return [String]
158
- def self.document_root_path project, database
159
- DOCUMENT_ROOT_PATH_TEMPLATE.render(
160
- :"project" => project,
161
- :"database" => database
162
- )
163
- end
164
-
165
91
  # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
166
92
  # Provides the means for authenticating requests made by the client. This parameter can
167
93
  # be many types.
@@ -274,32 +200,6 @@ module Google
274
200
  &Google::Firestore::V1beta1::Firestore::Stub.method(:new)
275
201
  )
276
202
 
277
- @get_document = Google::Gax.create_api_call(
278
- @firestore_stub.method(:get_document),
279
- defaults["get_document"],
280
- exception_transformer: exception_transformer,
281
- params_extractor: proc do |request|
282
- {'name' => request.name}
283
- end
284
- )
285
- @list_documents = Google::Gax.create_api_call(
286
- @firestore_stub.method(:list_documents),
287
- defaults["list_documents"],
288
- exception_transformer: exception_transformer
289
- )
290
- @create_document = Google::Gax.create_api_call(
291
- @firestore_stub.method(:create_document),
292
- defaults["create_document"],
293
- exception_transformer: exception_transformer
294
- )
295
- @update_document = Google::Gax.create_api_call(
296
- @firestore_stub.method(:update_document),
297
- defaults["update_document"],
298
- exception_transformer: exception_transformer,
299
- params_extractor: proc do |request|
300
- {'document.name' => request.document.name}
301
- end
302
- )
303
203
  @delete_document = Google::Gax.create_api_call(
304
204
  @firestore_stub.method(:delete_document),
305
205
  defaults["delete_document"],
@@ -324,14 +224,6 @@ module Google
324
224
  {'database' => request.database}
325
225
  end
326
226
  )
327
- @commit = Google::Gax.create_api_call(
328
- @firestore_stub.method(:commit),
329
- defaults["commit"],
330
- exception_transformer: exception_transformer,
331
- params_extractor: proc do |request|
332
- {'database' => request.database}
333
- end
334
- )
335
227
  @rollback = Google::Gax.create_api_call(
336
228
  @firestore_stub.method(:rollback),
337
229
  defaults["rollback"],
@@ -366,351 +258,248 @@ module Google
366
258
  {'parent' => request.parent}
367
259
  end
368
260
  )
261
+ @get_document = Google::Gax.create_api_call(
262
+ @firestore_stub.method(:get_document),
263
+ defaults["get_document"],
264
+ exception_transformer: exception_transformer,
265
+ params_extractor: proc do |request|
266
+ {'name' => request.name}
267
+ end
268
+ )
269
+ @list_documents = Google::Gax.create_api_call(
270
+ @firestore_stub.method(:list_documents),
271
+ defaults["list_documents"],
272
+ exception_transformer: exception_transformer
273
+ )
274
+ @create_document = Google::Gax.create_api_call(
275
+ @firestore_stub.method(:create_document),
276
+ defaults["create_document"],
277
+ exception_transformer: exception_transformer
278
+ )
279
+ @update_document = Google::Gax.create_api_call(
280
+ @firestore_stub.method(:update_document),
281
+ defaults["update_document"],
282
+ exception_transformer: exception_transformer,
283
+ params_extractor: proc do |request|
284
+ {'document.name' => request.document.name}
285
+ end
286
+ )
287
+ @commit = Google::Gax.create_api_call(
288
+ @firestore_stub.method(:commit),
289
+ defaults["commit"],
290
+ exception_transformer: exception_transformer,
291
+ params_extractor: proc do |request|
292
+ {'database' => request.database}
293
+ end
294
+ )
369
295
  end
370
296
 
371
297
  # Service calls
372
298
 
373
- # Gets a single document.
299
+ # Deletes a document.
374
300
  #
375
301
  # @param name [String]
376
- # Required. The resource name of the Document to get. In the format:
302
+ # Required. The resource name of the Document to delete. In the format:
377
303
  # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
378
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
379
- # The fields to return. If not set, returns all fields.
380
- #
381
- # If the document has a field that is not present in this mask, that field
382
- # will not be returned in the response.
383
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
384
- # can also be provided.
385
- # @param transaction [String]
386
- # Reads the document in a transaction.
387
- # @param read_time [Google::Protobuf::Timestamp | Hash]
388
- # Reads the version of the document at the given time.
389
- # This may not be older than 60 seconds.
390
- # A hash of the same form as `Google::Protobuf::Timestamp`
304
+ # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
305
+ # An optional precondition on the document.
306
+ # The request will fail if this is set and not met by the target document.
307
+ # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
391
308
  # can also be provided.
392
309
  # @param options [Google::Gax::CallOptions]
393
310
  # Overrides the default settings for this call, e.g, timeout,
394
311
  # retries, etc.
395
312
  # @yield [result, operation] Access the result along with the RPC operation
396
- # @yieldparam result [Google::Firestore::V1beta1::Document]
313
+ # @yieldparam result []
397
314
  # @yieldparam operation [GRPC::ActiveCall::Operation]
398
- # @return [Google::Firestore::V1beta1::Document]
399
315
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
400
316
  # @example
401
317
  # require "google/cloud/firestore/v1beta1"
402
318
  #
403
319
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
404
- # formatted_name = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
405
- # response = firestore_client.get_document(formatted_name)
320
+ #
321
+ # # TODO: Initialize `name`:
322
+ # name = ''
323
+ # firestore_client.delete_document(name)
406
324
 
407
- def get_document \
325
+ def delete_document \
408
326
  name,
409
- mask: nil,
410
- transaction: nil,
411
- read_time: nil,
327
+ current_document: nil,
412
328
  options: nil,
413
329
  &block
414
330
  req = {
415
331
  name: name,
416
- mask: mask,
417
- transaction: transaction,
418
- read_time: read_time
332
+ current_document: current_document
419
333
  }.delete_if { |_, v| v.nil? }
420
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::GetDocumentRequest)
421
- @get_document.call(req, options, &block)
334
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::DeleteDocumentRequest)
335
+ @delete_document.call(req, options, &block)
336
+ nil
422
337
  end
423
338
 
424
- # Lists documents.
339
+ # Gets multiple documents.
425
340
  #
426
- # @param parent [String]
427
- # Required. The parent resource name. In the format:
428
- # `projects/{project_id}/databases/{database_id}/documents` or
341
+ # Documents returned by this method are not guaranteed to be returned in the
342
+ # same order that they were requested.
343
+ #
344
+ # @param database [String]
345
+ # Required. The database name. In the format:
346
+ # `projects/{project_id}/databases/{database_id}`.
347
+ # @param documents [Array<String>]
348
+ # The names of the documents to retrieve. In the format:
429
349
  # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
430
- # For example:
431
- # `projects/my-project/databases/my-database/documents` or
432
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
433
- # @param collection_id [String]
434
- # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`
435
- # or `messages`.
436
- # @param page_size [Integer]
437
- # The maximum number of resources contained in the underlying API
438
- # response. If page streaming is performed per-resource, this
439
- # parameter does not affect the return value. If page streaming is
440
- # performed per-page, this determines the maximum number of
441
- # resources in a page.
442
- # @param order_by [String]
443
- # The order to sort results by. For example: `priority desc, name`.
350
+ # The request will fail if any of the document is not a child resource of the
351
+ # given `database`. Duplicate names will be elided.
444
352
  # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
445
353
  # The fields to return. If not set, returns all fields.
446
354
  #
447
- # If a document has a field that is not present in this mask, that field
448
- # will not be returned in the response.
355
+ # If a document has a field that is not present in this mask, that field will
356
+ # not be returned in the response.
449
357
  # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
450
358
  # can also be provided.
451
359
  # @param transaction [String]
452
360
  # Reads documents in a transaction.
361
+ # @param new_transaction [Google::Firestore::V1beta1::TransactionOptions | Hash]
362
+ # Starts a new transaction and reads the documents.
363
+ # Defaults to a read-only transaction.
364
+ # The new transaction ID will be returned as the first response in the
365
+ # stream.
366
+ # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
367
+ # can also be provided.
453
368
  # @param read_time [Google::Protobuf::Timestamp | Hash]
454
369
  # Reads documents as they were at the given time.
455
370
  # This may not be older than 60 seconds.
456
371
  # A hash of the same form as `Google::Protobuf::Timestamp`
457
372
  # can also be provided.
458
- # @param show_missing [true, false]
459
- # If the list should show missing documents. A missing document is a
460
- # document that does not exist but has sub-documents. These documents will
461
- # be returned with a key but will not have fields, {Google::Firestore::V1beta1::Document#create_time Document#create_time},
462
- # or {Google::Firestore::V1beta1::Document#update_time Document#update_time} set.
463
- #
464
- # Requests with `show_missing` may not specify `where` or
465
- # `order_by`.
466
373
  # @param options [Google::Gax::CallOptions]
467
374
  # Overrides the default settings for this call, e.g, timeout,
468
375
  # retries, etc.
469
- # @yield [result, operation] Access the result along with the RPC operation
470
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
471
- # @yieldparam operation [GRPC::ActiveCall::Operation]
472
- # @return [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
473
- # An enumerable of Google::Firestore::V1beta1::Document instances.
474
- # See Google::Gax::PagedEnumerable documentation for other
475
- # operations such as per-page iteration or access to the response
476
- # object.
376
+ # @return [Enumerable<Google::Firestore::V1beta1::BatchGetDocumentsResponse>]
377
+ # An enumerable of Google::Firestore::V1beta1::BatchGetDocumentsResponse instances.
378
+ #
477
379
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
478
380
  # @example
479
381
  # require "google/cloud/firestore/v1beta1"
480
382
  #
481
383
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
482
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
483
- #
484
- # # TODO: Initialize `collection_id`:
485
- # collection_id = ''
486
384
  #
487
- # # Iterate over all results.
488
- # firestore_client.list_documents(formatted_parent, collection_id).each do |element|
385
+ # # TODO: Initialize `database`:
386
+ # database = ''
387
+ # firestore_client.batch_get_documents(database).each do |element|
489
388
  # # Process element.
490
389
  # end
491
- #
492
- # # Or iterate over results one page at a time.
493
- # firestore_client.list_documents(formatted_parent, collection_id).each_page do |page|
494
- # # Process each page at a time.
495
- # page.each do |element|
496
- # # Process element.
497
- # end
498
- # end
499
390
 
500
- def list_documents \
501
- parent,
502
- collection_id,
503
- page_size: nil,
504
- order_by: nil,
391
+ def batch_get_documents \
392
+ database,
393
+ documents: nil,
505
394
  mask: nil,
506
395
  transaction: nil,
396
+ new_transaction: nil,
507
397
  read_time: nil,
508
- show_missing: nil,
509
- options: nil,
510
- &block
398
+ options: nil
511
399
  req = {
512
- parent: parent,
513
- collection_id: collection_id,
514
- page_size: page_size,
515
- order_by: order_by,
400
+ database: database,
401
+ documents: documents,
516
402
  mask: mask,
517
403
  transaction: transaction,
518
- read_time: read_time,
519
- show_missing: show_missing
404
+ new_transaction: new_transaction,
405
+ read_time: read_time
520
406
  }.delete_if { |_, v| v.nil? }
521
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListDocumentsRequest)
522
- @list_documents.call(req, options, &block)
407
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BatchGetDocumentsRequest)
408
+ @batch_get_documents.call(req, options)
523
409
  end
524
410
 
525
- # Creates a new document.
526
- #
527
- # @param parent [String]
528
- # Required. The parent resource. For example:
529
- # `projects/{project_id}/databases/{database_id}/documents` or
530
- # `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
531
- # @param collection_id [String]
532
- # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`.
533
- # @param document_id [String]
534
- # The client-assigned document ID to use for this document.
411
+ # Starts a new transaction.
535
412
  #
536
- # Optional. If not specified, an ID will be assigned by the service.
537
- # @param document [Google::Firestore::V1beta1::Document | Hash]
538
- # Required. The document to create. `name` must not be set.
539
- # A hash of the same form as `Google::Firestore::V1beta1::Document`
540
- # can also be provided.
541
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
542
- # The fields to return. If not set, returns all fields.
543
- #
544
- # If the document has a field that is not present in this mask, that field
545
- # will not be returned in the response.
546
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
413
+ # @param database [String]
414
+ # Required. The database name. In the format:
415
+ # `projects/{project_id}/databases/{database_id}`.
416
+ # @param options_ [Google::Firestore::V1beta1::TransactionOptions | Hash]
417
+ # The options for the transaction.
418
+ # Defaults to a read-write transaction.
419
+ # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
547
420
  # can also be provided.
548
421
  # @param options [Google::Gax::CallOptions]
549
422
  # Overrides the default settings for this call, e.g, timeout,
550
423
  # retries, etc.
551
424
  # @yield [result, operation] Access the result along with the RPC operation
552
- # @yieldparam result [Google::Firestore::V1beta1::Document]
425
+ # @yieldparam result [Google::Firestore::V1beta1::BeginTransactionResponse]
553
426
  # @yieldparam operation [GRPC::ActiveCall::Operation]
554
- # @return [Google::Firestore::V1beta1::Document]
427
+ # @return [Google::Firestore::V1beta1::BeginTransactionResponse]
555
428
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
556
429
  # @example
557
430
  # require "google/cloud/firestore/v1beta1"
558
431
  #
559
432
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
560
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
561
- #
562
- # # TODO: Initialize `collection_id`:
563
- # collection_id = ''
564
433
  #
565
- # # TODO: Initialize `document_id`:
566
- # document_id = ''
567
- #
568
- # # TODO: Initialize `document`:
569
- # document = {}
570
- # response = firestore_client.create_document(formatted_parent, collection_id, document_id, document)
434
+ # # TODO: Initialize `database`:
435
+ # database = ''
436
+ # response = firestore_client.begin_transaction(database)
571
437
 
572
- def create_document \
573
- parent,
574
- collection_id,
575
- document_id,
576
- document,
577
- mask: nil,
438
+ def begin_transaction \
439
+ database,
440
+ options_: nil,
578
441
  options: nil,
579
442
  &block
580
443
  req = {
581
- parent: parent,
582
- collection_id: collection_id,
583
- document_id: document_id,
584
- document: document,
585
- mask: mask
444
+ database: database,
445
+ options: options_
586
446
  }.delete_if { |_, v| v.nil? }
587
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CreateDocumentRequest)
588
- @create_document.call(req, options, &block)
447
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BeginTransactionRequest)
448
+ @begin_transaction.call(req, options, &block)
589
449
  end
590
450
 
591
- # Updates or inserts a document.
592
- #
593
- # @param document [Google::Firestore::V1beta1::Document | Hash]
594
- # Required. The updated document.
595
- # Creates the document if it does not already exist.
596
- # A hash of the same form as `Google::Firestore::V1beta1::Document`
597
- # can also be provided.
598
- # @param update_mask [Google::Firestore::V1beta1::DocumentMask | Hash]
599
- # The fields to update.
600
- # None of the field paths in the mask may contain a reserved name.
601
- #
602
- # If the document exists on the server and has fields not referenced in the
603
- # mask, they are left unchanged.
604
- # Fields referenced in the mask, but not present in the input document, are
605
- # deleted from the document on the server.
606
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
607
- # can also be provided.
608
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
609
- # The fields to return. If not set, returns all fields.
451
+ # Rolls back a transaction.
610
452
  #
611
- # If the document has a field that is not present in this mask, that field
612
- # will not be returned in the response.
613
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
614
- # can also be provided.
615
- # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
616
- # An optional precondition on the document.
617
- # The request will fail if this is set and not met by the target document.
618
- # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
619
- # can also be provided.
453
+ # @param database [String]
454
+ # Required. The database name. In the format:
455
+ # `projects/{project_id}/databases/{database_id}`.
456
+ # @param transaction [String]
457
+ # Required. The transaction to roll back.
620
458
  # @param options [Google::Gax::CallOptions]
621
459
  # Overrides the default settings for this call, e.g, timeout,
622
460
  # retries, etc.
623
461
  # @yield [result, operation] Access the result along with the RPC operation
624
- # @yieldparam result [Google::Firestore::V1beta1::Document]
462
+ # @yieldparam result []
625
463
  # @yieldparam operation [GRPC::ActiveCall::Operation]
626
- # @return [Google::Firestore::V1beta1::Document]
627
464
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
628
465
  # @example
629
466
  # require "google/cloud/firestore/v1beta1"
630
467
  #
631
468
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
632
469
  #
633
- # # TODO: Initialize `document`:
634
- # document = {}
635
- #
636
- # # TODO: Initialize `update_mask`:
637
- # update_mask = {}
638
- # response = firestore_client.update_document(document, update_mask)
639
-
640
- def update_document \
641
- document,
642
- update_mask,
643
- mask: nil,
644
- current_document: nil,
645
- options: nil,
646
- &block
647
- req = {
648
- document: document,
649
- update_mask: update_mask,
650
- mask: mask,
651
- current_document: current_document
652
- }.delete_if { |_, v| v.nil? }
653
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::UpdateDocumentRequest)
654
- @update_document.call(req, options, &block)
655
- end
656
-
657
- # Deletes a document.
658
- #
659
- # @param name [String]
660
- # Required. The resource name of the Document to delete. In the format:
661
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
662
- # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
663
- # An optional precondition on the document.
664
- # The request will fail if this is set and not met by the target document.
665
- # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
666
- # can also be provided.
667
- # @param options [Google::Gax::CallOptions]
668
- # Overrides the default settings for this call, e.g, timeout,
669
- # retries, etc.
670
- # @yield [result, operation] Access the result along with the RPC operation
671
- # @yieldparam result []
672
- # @yieldparam operation [GRPC::ActiveCall::Operation]
673
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
674
- # @example
675
- # require "google/cloud/firestore/v1beta1"
470
+ # # TODO: Initialize `database`:
471
+ # database = ''
676
472
  #
677
- # firestore_client = Google::Cloud::Firestore::V1beta1.new
678
- # formatted_name = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
679
- # firestore_client.delete_document(formatted_name)
473
+ # # TODO: Initialize `transaction`:
474
+ # transaction = ''
475
+ # firestore_client.rollback(database, transaction)
680
476
 
681
- def delete_document \
682
- name,
683
- current_document: nil,
477
+ def rollback \
478
+ database,
479
+ transaction,
684
480
  options: nil,
685
481
  &block
686
482
  req = {
687
- name: name,
688
- current_document: current_document
483
+ database: database,
484
+ transaction: transaction
689
485
  }.delete_if { |_, v| v.nil? }
690
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::DeleteDocumentRequest)
691
- @delete_document.call(req, options, &block)
486
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RollbackRequest)
487
+ @rollback.call(req, options, &block)
692
488
  nil
693
489
  end
694
490
 
695
- # Gets multiple documents.
696
- #
697
- # Documents returned by this method are not guaranteed to be returned in the
698
- # same order that they were requested.
491
+ # Runs a query.
699
492
  #
700
- # @param database [String]
701
- # Required. The database name. In the format:
702
- # `projects/{project_id}/databases/{database_id}`.
703
- # @param documents [Array<String>]
704
- # The names of the documents to retrieve. In the format:
493
+ # @param parent [String]
494
+ # Required. The parent resource name. In the format:
495
+ # `projects/{project_id}/databases/{database_id}/documents` or
705
496
  # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
706
- # The request will fail if any of the document is not a child resource of the
707
- # given `database`. Duplicate names will be elided.
708
- # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
709
- # The fields to return. If not set, returns all fields.
710
- #
711
- # If a document has a field that is not present in this mask, that field will
712
- # not be returned in the response.
713
- # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
497
+ # For example:
498
+ # `projects/my-project/databases/my-database/documents` or
499
+ # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
500
+ # @param structured_query [Google::Firestore::V1beta1::StructuredQuery | Hash]
501
+ # A structured query.
502
+ # A hash of the same form as `Google::Firestore::V1beta1::StructuredQuery`
714
503
  # can also be provided.
715
504
  # @param transaction [String]
716
505
  # Reads documents in a transaction.
@@ -729,165 +518,226 @@ module Google
729
518
  # @param options [Google::Gax::CallOptions]
730
519
  # Overrides the default settings for this call, e.g, timeout,
731
520
  # retries, etc.
732
- # @return [Enumerable<Google::Firestore::V1beta1::BatchGetDocumentsResponse>]
733
- # An enumerable of Google::Firestore::V1beta1::BatchGetDocumentsResponse instances.
521
+ # @return [Enumerable<Google::Firestore::V1beta1::RunQueryResponse>]
522
+ # An enumerable of Google::Firestore::V1beta1::RunQueryResponse instances.
734
523
  #
735
524
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
736
525
  # @example
737
526
  # require "google/cloud/firestore/v1beta1"
738
527
  #
739
528
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
740
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
741
529
  #
742
- # # TODO: Initialize `documents`:
743
- # documents = []
744
- # firestore_client.batch_get_documents(formatted_database, documents).each do |element|
530
+ # # TODO: Initialize `parent`:
531
+ # parent = ''
532
+ # firestore_client.run_query(parent).each do |element|
745
533
  # # Process element.
746
534
  # end
747
535
 
748
- def batch_get_documents \
749
- database,
750
- documents,
751
- mask: nil,
536
+ def run_query \
537
+ parent,
538
+ structured_query: nil,
752
539
  transaction: nil,
753
540
  new_transaction: nil,
754
541
  read_time: nil,
755
542
  options: nil
756
543
  req = {
757
- database: database,
758
- documents: documents,
759
- mask: mask,
544
+ parent: parent,
545
+ structured_query: structured_query,
760
546
  transaction: transaction,
761
547
  new_transaction: new_transaction,
762
548
  read_time: read_time
763
549
  }.delete_if { |_, v| v.nil? }
764
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BatchGetDocumentsRequest)
765
- @batch_get_documents.call(req, options)
550
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RunQueryRequest)
551
+ @run_query.call(req, options)
766
552
  end
767
553
 
768
- # Starts a new transaction.
554
+ # Streams batches of document updates and deletes, in order.
769
555
  #
770
- # @param database [String]
771
- # Required. The database name. In the format:
772
- # `projects/{project_id}/databases/{database_id}`.
773
- # @param options_ [Google::Firestore::V1beta1::TransactionOptions | Hash]
774
- # The options for the transaction.
775
- # Defaults to a read-write transaction.
776
- # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
777
- # can also be provided.
556
+ # @param reqs [Enumerable<Google::Firestore::V1beta1::WriteRequest>]
557
+ # The input requests.
778
558
  # @param options [Google::Gax::CallOptions]
779
559
  # Overrides the default settings for this call, e.g, timeout,
780
560
  # retries, etc.
781
- # @yield [result, operation] Access the result along with the RPC operation
782
- # @yieldparam result [Google::Firestore::V1beta1::BeginTransactionResponse]
783
- # @yieldparam operation [GRPC::ActiveCall::Operation]
784
- # @return [Google::Firestore::V1beta1::BeginTransactionResponse]
561
+ # @return [Enumerable<Google::Firestore::V1beta1::WriteResponse>]
562
+ # An enumerable of Google::Firestore::V1beta1::WriteResponse instances.
563
+ #
785
564
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
565
+ #
566
+ # @note
567
+ # EXPERIMENTAL:
568
+ # Streaming requests are still undergoing review.
569
+ # This method interface might change in the future.
570
+ #
786
571
  # @example
787
572
  # require "google/cloud/firestore/v1beta1"
788
573
  #
789
574
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
790
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
791
- # response = firestore_client.begin_transaction(formatted_database)
575
+ #
576
+ # # TODO: Initialize `database`:
577
+ # database = ''
578
+ # request = { database: database }
579
+ # requests = [request]
580
+ # firestore_client.write(requests).each do |element|
581
+ # # Process element.
582
+ # end
792
583
 
793
- def begin_transaction \
794
- database,
795
- options_: nil,
796
- options: nil,
797
- &block
798
- req = {
799
- database: database,
800
- options: options_
801
- }.delete_if { |_, v| v.nil? }
802
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::BeginTransactionRequest)
803
- @begin_transaction.call(req, options, &block)
584
+ def write reqs, options: nil
585
+ request_protos = reqs.lazy.map do |req|
586
+ Google::Gax::to_proto(req, Google::Firestore::V1beta1::WriteRequest)
587
+ end
588
+ @write.call(request_protos, options)
804
589
  end
805
590
 
806
- # Commits a transaction, while optionally updating documents.
807
- #
808
- # @param database [String]
809
- # Required. The database name. In the format:
810
- # `projects/{project_id}/databases/{database_id}`.
811
- # @param writes [Array<Google::Firestore::V1beta1::Write | Hash>]
812
- # The writes to apply.
591
+ # Listens to changes.
813
592
  #
814
- # Always executed atomically and in order.
815
- # A hash of the same form as `Google::Firestore::V1beta1::Write`
816
- # can also be provided.
817
- # @param transaction [String]
818
- # If set, applies all writes in this transaction, and commits it.
593
+ # @param reqs [Enumerable<Google::Firestore::V1beta1::ListenRequest>]
594
+ # The input requests.
819
595
  # @param options [Google::Gax::CallOptions]
820
596
  # Overrides the default settings for this call, e.g, timeout,
821
597
  # retries, etc.
822
- # @yield [result, operation] Access the result along with the RPC operation
823
- # @yieldparam result [Google::Firestore::V1beta1::CommitResponse]
824
- # @yieldparam operation [GRPC::ActiveCall::Operation]
825
- # @return [Google::Firestore::V1beta1::CommitResponse]
598
+ # @return [Enumerable<Google::Firestore::V1beta1::ListenResponse>]
599
+ # An enumerable of Google::Firestore::V1beta1::ListenResponse instances.
600
+ #
826
601
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
602
+ #
603
+ # @note
604
+ # EXPERIMENTAL:
605
+ # Streaming requests are still undergoing review.
606
+ # This method interface might change in the future.
607
+ #
827
608
  # @example
828
609
  # require "google/cloud/firestore/v1beta1"
829
610
  #
830
611
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
831
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
832
612
  #
833
- # # TODO: Initialize `writes`:
834
- # writes = []
835
- # response = firestore_client.commit(formatted_database, writes)
613
+ # # TODO: Initialize `database`:
614
+ # database = ''
615
+ # request = { database: database }
616
+ # requests = [request]
617
+ # firestore_client.listen(requests).each do |element|
618
+ # # Process element.
619
+ # end
836
620
 
837
- def commit \
838
- database,
839
- writes,
840
- transaction: nil,
841
- options: nil,
842
- &block
621
+ def listen reqs, options: nil
622
+ request_protos = reqs.lazy.map do |req|
623
+ Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListenRequest)
624
+ end
625
+ @listen.call(request_protos, options)
626
+ end
627
+
628
+ # Lists all the collection IDs underneath a document.
629
+ #
630
+ # @param parent [String]
631
+ # Required. The parent document. In the format:
632
+ # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
633
+ # For example:
634
+ # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
635
+ # @param page_size [Integer]
636
+ # The maximum number of resources contained in the underlying API
637
+ # response. If page streaming is performed per-resource, this
638
+ # parameter does not affect the return value. If page streaming is
639
+ # performed per-page, this determines the maximum number of
640
+ # resources in a page.
641
+ # @param options [Google::Gax::CallOptions]
642
+ # Overrides the default settings for this call, e.g, timeout,
643
+ # retries, etc.
644
+ # @yield [result, operation] Access the result along with the RPC operation
645
+ # @yieldparam result [Google::Gax::PagedEnumerable<String>]
646
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
647
+ # @return [Google::Gax::PagedEnumerable<String>]
648
+ # An enumerable of String instances.
649
+ # See Google::Gax::PagedEnumerable documentation for other
650
+ # operations such as per-page iteration or access to the response
651
+ # object.
652
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
653
+ # @example
654
+ # require "google/cloud/firestore/v1beta1"
655
+ #
656
+ # firestore_client = Google::Cloud::Firestore::V1beta1.new
657
+ #
658
+ # # TODO: Initialize `parent`:
659
+ # parent = ''
660
+ #
661
+ # # Iterate over all results.
662
+ # firestore_client.list_collection_ids(parent).each do |element|
663
+ # # Process element.
664
+ # end
665
+ #
666
+ # # Or iterate over results one page at a time.
667
+ # firestore_client.list_collection_ids(parent).each_page do |page|
668
+ # # Process each page at a time.
669
+ # page.each do |element|
670
+ # # Process element.
671
+ # end
672
+ # end
673
+
674
+ def list_collection_ids \
675
+ parent,
676
+ page_size: nil,
677
+ options: nil,
678
+ &block
843
679
  req = {
844
- database: database,
845
- writes: writes,
846
- transaction: transaction
680
+ parent: parent,
681
+ page_size: page_size
847
682
  }.delete_if { |_, v| v.nil? }
848
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CommitRequest)
849
- @commit.call(req, options, &block)
683
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListCollectionIdsRequest)
684
+ @list_collection_ids.call(req, options, &block)
850
685
  end
851
686
 
852
- # Rolls back a transaction.
687
+ # Gets a single document.
853
688
  #
854
- # @param database [String]
855
- # Required. The database name. In the format:
856
- # `projects/{project_id}/databases/{database_id}`.
689
+ # @param name [String]
690
+ # Required. The resource name of the Document to get. In the format:
691
+ # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
692
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
693
+ # The fields to return. If not set, returns all fields.
694
+ #
695
+ # If the document has a field that is not present in this mask, that field
696
+ # will not be returned in the response.
697
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
698
+ # can also be provided.
857
699
  # @param transaction [String]
858
- # Required. The transaction to roll back.
700
+ # Reads the document in a transaction.
701
+ # @param read_time [Google::Protobuf::Timestamp | Hash]
702
+ # Reads the version of the document at the given time.
703
+ # This may not be older than 60 seconds.
704
+ # A hash of the same form as `Google::Protobuf::Timestamp`
705
+ # can also be provided.
859
706
  # @param options [Google::Gax::CallOptions]
860
707
  # Overrides the default settings for this call, e.g, timeout,
861
708
  # retries, etc.
862
709
  # @yield [result, operation] Access the result along with the RPC operation
863
- # @yieldparam result []
710
+ # @yieldparam result [Google::Firestore::V1beta1::Document]
864
711
  # @yieldparam operation [GRPC::ActiveCall::Operation]
712
+ # @return [Google::Firestore::V1beta1::Document]
865
713
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
866
714
  # @example
867
715
  # require "google/cloud/firestore/v1beta1"
868
716
  #
869
717
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
870
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
871
718
  #
872
- # # TODO: Initialize `transaction`:
873
- # transaction = ''
874
- # firestore_client.rollback(formatted_database, transaction)
719
+ # # TODO: Initialize `name`:
720
+ # name = ''
721
+ # response = firestore_client.get_document(name)
875
722
 
876
- def rollback \
877
- database,
878
- transaction,
723
+ def get_document \
724
+ name,
725
+ mask: nil,
726
+ transaction: nil,
727
+ read_time: nil,
879
728
  options: nil,
880
729
  &block
881
730
  req = {
882
- database: database,
883
- transaction: transaction
731
+ name: name,
732
+ mask: mask,
733
+ transaction: transaction,
734
+ read_time: read_time
884
735
  }.delete_if { |_, v| v.nil? }
885
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RollbackRequest)
886
- @rollback.call(req, options, &block)
887
- nil
736
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::GetDocumentRequest)
737
+ @get_document.call(req, options, &block)
888
738
  end
889
739
 
890
- # Runs a query.
740
+ # Lists documents.
891
741
  #
892
742
  # @param parent [String]
893
743
  # Required. The parent resource name. In the format:
@@ -896,183 +746,271 @@ module Google
896
746
  # For example:
897
747
  # `projects/my-project/databases/my-database/documents` or
898
748
  # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
899
- # @param structured_query [Google::Firestore::V1beta1::StructuredQuery | Hash]
900
- # A structured query.
901
- # A hash of the same form as `Google::Firestore::V1beta1::StructuredQuery`
749
+ # @param collection_id [String]
750
+ # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`
751
+ # or `messages`.
752
+ # @param page_size [Integer]
753
+ # The maximum number of resources contained in the underlying API
754
+ # response. If page streaming is performed per-resource, this
755
+ # parameter does not affect the return value. If page streaming is
756
+ # performed per-page, this determines the maximum number of
757
+ # resources in a page.
758
+ # @param order_by [String]
759
+ # The order to sort results by. For example: `priority desc, name`.
760
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
761
+ # The fields to return. If not set, returns all fields.
762
+ #
763
+ # If a document has a field that is not present in this mask, that field
764
+ # will not be returned in the response.
765
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
902
766
  # can also be provided.
903
767
  # @param transaction [String]
904
768
  # Reads documents in a transaction.
905
- # @param new_transaction [Google::Firestore::V1beta1::TransactionOptions | Hash]
906
- # Starts a new transaction and reads the documents.
907
- # Defaults to a read-only transaction.
908
- # The new transaction ID will be returned as the first response in the
909
- # stream.
910
- # A hash of the same form as `Google::Firestore::V1beta1::TransactionOptions`
911
- # can also be provided.
912
769
  # @param read_time [Google::Protobuf::Timestamp | Hash]
913
770
  # Reads documents as they were at the given time.
914
771
  # This may not be older than 60 seconds.
915
772
  # A hash of the same form as `Google::Protobuf::Timestamp`
916
773
  # can also be provided.
774
+ # @param show_missing [true, false]
775
+ # If the list should show missing documents. A missing document is a
776
+ # document that does not exist but has sub-documents. These documents will
777
+ # be returned with a key but will not have fields, {Google::Firestore::V1beta1::Document#create_time Document#create_time},
778
+ # or {Google::Firestore::V1beta1::Document#update_time Document#update_time} set.
779
+ #
780
+ # Requests with `show_missing` may not specify `where` or
781
+ # `order_by`.
917
782
  # @param options [Google::Gax::CallOptions]
918
783
  # Overrides the default settings for this call, e.g, timeout,
919
784
  # retries, etc.
920
- # @return [Enumerable<Google::Firestore::V1beta1::RunQueryResponse>]
921
- # An enumerable of Google::Firestore::V1beta1::RunQueryResponse instances.
922
- #
785
+ # @yield [result, operation] Access the result along with the RPC operation
786
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
787
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
788
+ # @return [Google::Gax::PagedEnumerable<Google::Firestore::V1beta1::Document>]
789
+ # An enumerable of Google::Firestore::V1beta1::Document instances.
790
+ # See Google::Gax::PagedEnumerable documentation for other
791
+ # operations such as per-page iteration or access to the response
792
+ # object.
923
793
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
924
794
  # @example
925
795
  # require "google/cloud/firestore/v1beta1"
926
796
  #
927
797
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
928
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
929
- # firestore_client.run_query(formatted_parent).each do |element|
798
+ #
799
+ # # TODO: Initialize `parent`:
800
+ # parent = ''
801
+ #
802
+ # # TODO: Initialize `collection_id`:
803
+ # collection_id = ''
804
+ #
805
+ # # Iterate over all results.
806
+ # firestore_client.list_documents(parent, collection_id).each do |element|
930
807
  # # Process element.
931
808
  # end
809
+ #
810
+ # # Or iterate over results one page at a time.
811
+ # firestore_client.list_documents(parent, collection_id).each_page do |page|
812
+ # # Process each page at a time.
813
+ # page.each do |element|
814
+ # # Process element.
815
+ # end
816
+ # end
932
817
 
933
- def run_query \
818
+ def list_documents \
934
819
  parent,
935
- structured_query: nil,
820
+ collection_id,
821
+ page_size: nil,
822
+ order_by: nil,
823
+ mask: nil,
936
824
  transaction: nil,
937
- new_transaction: nil,
938
825
  read_time: nil,
939
- options: nil
826
+ show_missing: nil,
827
+ options: nil,
828
+ &block
940
829
  req = {
941
830
  parent: parent,
942
- structured_query: structured_query,
831
+ collection_id: collection_id,
832
+ page_size: page_size,
833
+ order_by: order_by,
834
+ mask: mask,
943
835
  transaction: transaction,
944
- new_transaction: new_transaction,
945
- read_time: read_time
836
+ read_time: read_time,
837
+ show_missing: show_missing
946
838
  }.delete_if { |_, v| v.nil? }
947
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::RunQueryRequest)
948
- @run_query.call(req, options)
839
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListDocumentsRequest)
840
+ @list_documents.call(req, options, &block)
949
841
  end
950
842
 
951
- # Streams batches of document updates and deletes, in order.
843
+ # Creates a new document.
952
844
  #
953
- # @param reqs [Enumerable<Google::Firestore::V1beta1::WriteRequest>]
954
- # The input requests.
845
+ # @param parent [String]
846
+ # Required. The parent resource. For example:
847
+ # `projects/{project_id}/databases/{database_id}/documents` or
848
+ # `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
849
+ # @param collection_id [String]
850
+ # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`.
851
+ # @param document [Google::Firestore::V1beta1::Document | Hash]
852
+ # Required. The document to create. `name` must not be set.
853
+ # A hash of the same form as `Google::Firestore::V1beta1::Document`
854
+ # can also be provided.
855
+ # @param document_id [String]
856
+ # The client-assigned document ID to use for this document.
857
+ #
858
+ # Optional. If not specified, an ID will be assigned by the service.
859
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
860
+ # The fields to return. If not set, returns all fields.
861
+ #
862
+ # If the document has a field that is not present in this mask, that field
863
+ # will not be returned in the response.
864
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
865
+ # can also be provided.
955
866
  # @param options [Google::Gax::CallOptions]
956
867
  # Overrides the default settings for this call, e.g, timeout,
957
868
  # retries, etc.
958
- # @return [Enumerable<Google::Firestore::V1beta1::WriteResponse>]
959
- # An enumerable of Google::Firestore::V1beta1::WriteResponse instances.
960
- #
869
+ # @yield [result, operation] Access the result along with the RPC operation
870
+ # @yieldparam result [Google::Firestore::V1beta1::Document]
871
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
872
+ # @return [Google::Firestore::V1beta1::Document]
961
873
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
962
- #
963
- # @note
964
- # EXPERIMENTAL:
965
- # Streaming requests are still undergoing review.
966
- # This method interface might change in the future.
967
- #
968
874
  # @example
969
875
  # require "google/cloud/firestore/v1beta1"
970
876
  #
971
877
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
972
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
973
- # request = { database: formatted_database }
974
- # requests = [request]
975
- # firestore_client.write(requests).each do |element|
976
- # # Process element.
977
- # end
878
+ #
879
+ # # TODO: Initialize `parent`:
880
+ # parent = ''
881
+ #
882
+ # # TODO: Initialize `collection_id`:
883
+ # collection_id = ''
884
+ #
885
+ # # TODO: Initialize `document`:
886
+ # document = {}
887
+ # response = firestore_client.create_document(parent, collection_id, document)
978
888
 
979
- def write reqs, options: nil
980
- request_protos = reqs.lazy.map do |req|
981
- Google::Gax::to_proto(req, Google::Firestore::V1beta1::WriteRequest)
982
- end
983
- @write.call(request_protos, options)
889
+ def create_document \
890
+ parent,
891
+ collection_id,
892
+ document,
893
+ document_id: nil,
894
+ mask: nil,
895
+ options: nil,
896
+ &block
897
+ req = {
898
+ parent: parent,
899
+ collection_id: collection_id,
900
+ document: document,
901
+ document_id: document_id,
902
+ mask: mask
903
+ }.delete_if { |_, v| v.nil? }
904
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CreateDocumentRequest)
905
+ @create_document.call(req, options, &block)
984
906
  end
985
907
 
986
- # Listens to changes.
908
+ # Updates or inserts a document.
987
909
  #
988
- # @param reqs [Enumerable<Google::Firestore::V1beta1::ListenRequest>]
989
- # The input requests.
910
+ # @param document [Google::Firestore::V1beta1::Document | Hash]
911
+ # Required. The updated document.
912
+ # Creates the document if it does not already exist.
913
+ # A hash of the same form as `Google::Firestore::V1beta1::Document`
914
+ # can also be provided.
915
+ # @param update_mask [Google::Firestore::V1beta1::DocumentMask | Hash]
916
+ # The fields to update.
917
+ # None of the field paths in the mask may contain a reserved name.
918
+ #
919
+ # If the document exists on the server and has fields not referenced in the
920
+ # mask, they are left unchanged.
921
+ # Fields referenced in the mask, but not present in the input document, are
922
+ # deleted from the document on the server.
923
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
924
+ # can also be provided.
925
+ # @param mask [Google::Firestore::V1beta1::DocumentMask | Hash]
926
+ # The fields to return. If not set, returns all fields.
927
+ #
928
+ # If the document has a field that is not present in this mask, that field
929
+ # will not be returned in the response.
930
+ # A hash of the same form as `Google::Firestore::V1beta1::DocumentMask`
931
+ # can also be provided.
932
+ # @param current_document [Google::Firestore::V1beta1::Precondition | Hash]
933
+ # An optional precondition on the document.
934
+ # The request will fail if this is set and not met by the target document.
935
+ # A hash of the same form as `Google::Firestore::V1beta1::Precondition`
936
+ # can also be provided.
990
937
  # @param options [Google::Gax::CallOptions]
991
938
  # Overrides the default settings for this call, e.g, timeout,
992
939
  # retries, etc.
993
- # @return [Enumerable<Google::Firestore::V1beta1::ListenResponse>]
994
- # An enumerable of Google::Firestore::V1beta1::ListenResponse instances.
995
- #
940
+ # @yield [result, operation] Access the result along with the RPC operation
941
+ # @yieldparam result [Google::Firestore::V1beta1::Document]
942
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
943
+ # @return [Google::Firestore::V1beta1::Document]
996
944
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
997
- #
998
- # @note
999
- # EXPERIMENTAL:
1000
- # Streaming requests are still undergoing review.
1001
- # This method interface might change in the future.
1002
- #
1003
945
  # @example
1004
946
  # require "google/cloud/firestore/v1beta1"
1005
947
  #
1006
948
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
1007
- # formatted_database = Google::Cloud::Firestore::V1beta1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
1008
- # request = { database: formatted_database }
1009
- # requests = [request]
1010
- # firestore_client.listen(requests).each do |element|
1011
- # # Process element.
1012
- # end
949
+ #
950
+ # # TODO: Initialize `document`:
951
+ # document = {}
952
+ # response = firestore_client.update_document(document)
1013
953
 
1014
- def listen reqs, options: nil
1015
- request_protos = reqs.lazy.map do |req|
1016
- Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListenRequest)
1017
- end
1018
- @listen.call(request_protos, options)
954
+ def update_document \
955
+ document,
956
+ update_mask: nil,
957
+ mask: nil,
958
+ current_document: nil,
959
+ options: nil,
960
+ &block
961
+ req = {
962
+ document: document,
963
+ update_mask: update_mask,
964
+ mask: mask,
965
+ current_document: current_document
966
+ }.delete_if { |_, v| v.nil? }
967
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::UpdateDocumentRequest)
968
+ @update_document.call(req, options, &block)
1019
969
  end
1020
970
 
1021
- # Lists all the collection IDs underneath a document.
971
+ # Commits a transaction, while optionally updating documents.
1022
972
  #
1023
- # @param parent [String]
1024
- # Required. The parent document. In the format:
1025
- # `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
1026
- # For example:
1027
- # `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
1028
- # @param page_size [Integer]
1029
- # The maximum number of resources contained in the underlying API
1030
- # response. If page streaming is performed per-resource, this
1031
- # parameter does not affect the return value. If page streaming is
1032
- # performed per-page, this determines the maximum number of
1033
- # resources in a page.
973
+ # @param database [String]
974
+ # Required. The database name. In the format:
975
+ # `projects/{project_id}/databases/{database_id}`.
976
+ # @param writes [Array<Google::Firestore::V1beta1::Write | Hash>]
977
+ # The writes to apply.
978
+ #
979
+ # Always executed atomically and in order.
980
+ # A hash of the same form as `Google::Firestore::V1beta1::Write`
981
+ # can also be provided.
982
+ # @param transaction [String]
983
+ # If set, applies all writes in this transaction, and commits it.
1034
984
  # @param options [Google::Gax::CallOptions]
1035
985
  # Overrides the default settings for this call, e.g, timeout,
1036
986
  # retries, etc.
1037
987
  # @yield [result, operation] Access the result along with the RPC operation
1038
- # @yieldparam result [Google::Gax::PagedEnumerable<String>]
988
+ # @yieldparam result [Google::Firestore::V1beta1::CommitResponse]
1039
989
  # @yieldparam operation [GRPC::ActiveCall::Operation]
1040
- # @return [Google::Gax::PagedEnumerable<String>]
1041
- # An enumerable of String instances.
1042
- # See Google::Gax::PagedEnumerable documentation for other
1043
- # operations such as per-page iteration or access to the response
1044
- # object.
990
+ # @return [Google::Firestore::V1beta1::CommitResponse]
1045
991
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
1046
992
  # @example
1047
993
  # require "google/cloud/firestore/v1beta1"
1048
994
  #
1049
995
  # firestore_client = Google::Cloud::Firestore::V1beta1.new
1050
- # formatted_parent = Google::Cloud::Firestore::V1beta1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
1051
996
  #
1052
- # # Iterate over all results.
1053
- # firestore_client.list_collection_ids(formatted_parent).each do |element|
1054
- # # Process element.
1055
- # end
1056
- #
1057
- # # Or iterate over results one page at a time.
1058
- # firestore_client.list_collection_ids(formatted_parent).each_page do |page|
1059
- # # Process each page at a time.
1060
- # page.each do |element|
1061
- # # Process element.
1062
- # end
1063
- # end
997
+ # # TODO: Initialize `database`:
998
+ # database = ''
999
+ # response = firestore_client.commit(database)
1064
1000
 
1065
- def list_collection_ids \
1066
- parent,
1067
- page_size: nil,
1001
+ def commit \
1002
+ database,
1003
+ writes: nil,
1004
+ transaction: nil,
1068
1005
  options: nil,
1069
1006
  &block
1070
1007
  req = {
1071
- parent: parent,
1072
- page_size: page_size
1008
+ database: database,
1009
+ writes: writes,
1010
+ transaction: transaction
1073
1011
  }.delete_if { |_, v| v.nil? }
1074
- req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::ListCollectionIdsRequest)
1075
- @list_collection_ids.call(req, options, &block)
1012
+ req = Google::Gax::to_proto(req, Google::Firestore::V1beta1::CommitRequest)
1013
+ @commit.call(req, options, &block)
1076
1014
  end
1077
1015
  end
1078
1016
  end