google-cloud-firestore 1.3.0 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,11 @@
7
7
  "INTERNAL",
8
8
  "UNAVAILABLE"
9
9
  ],
10
- "non_idempotent": []
10
+ "non_idempotent": [],
11
+ "idempotent2": [
12
+ "DEADLINE_EXCEEDED",
13
+ "UNAVAILABLE"
14
+ ]
11
15
  },
12
16
  "retry_params": {
13
17
  "default": {
@@ -21,47 +25,47 @@
21
25
  }
22
26
  },
23
27
  "methods": {
24
- "CreateIndex": {
25
- "timeout_millis": 60000,
26
- "retry_codes_name": "non_idempotent",
27
- "retry_params_name": "default"
28
- },
29
- "ListIndexes": {
28
+ "DeleteIndex": {
30
29
  "timeout_millis": 60000,
31
30
  "retry_codes_name": "idempotent",
32
31
  "retry_params_name": "default"
33
32
  },
34
- "GetIndex": {
33
+ "UpdateField": {
35
34
  "timeout_millis": 60000,
36
- "retry_codes_name": "idempotent",
35
+ "retry_codes_name": "non_idempotent",
37
36
  "retry_params_name": "default"
38
37
  },
39
- "DeleteIndex": {
38
+ "CreateIndex": {
40
39
  "timeout_millis": 60000,
41
- "retry_codes_name": "idempotent",
40
+ "retry_codes_name": "non_idempotent",
42
41
  "retry_params_name": "default"
43
42
  },
44
- "ImportDocuments": {
43
+ "ListIndexes": {
45
44
  "timeout_millis": 60000,
46
- "retry_codes_name": "non_idempotent",
45
+ "retry_codes_name": "idempotent2",
47
46
  "retry_params_name": "default"
48
47
  },
49
- "ExportDocuments": {
48
+ "GetIndex": {
50
49
  "timeout_millis": 60000,
51
- "retry_codes_name": "non_idempotent",
50
+ "retry_codes_name": "idempotent2",
52
51
  "retry_params_name": "default"
53
52
  },
54
53
  "GetField": {
55
54
  "timeout_millis": 60000,
56
- "retry_codes_name": "idempotent",
55
+ "retry_codes_name": "idempotent2",
57
56
  "retry_params_name": "default"
58
57
  },
59
58
  "ListFields": {
60
59
  "timeout_millis": 60000,
61
- "retry_codes_name": "idempotent",
60
+ "retry_codes_name": "idempotent2",
62
61
  "retry_params_name": "default"
63
62
  },
64
- "UpdateField": {
63
+ "ExportDocuments": {
64
+ "timeout_millis": 60000,
65
+ "retry_codes_name": "non_idempotent",
66
+ "retry_params_name": "default"
67
+ },
68
+ "ImportDocuments": {
65
69
  "timeout_millis": 60000,
66
70
  "retry_codes_name": "non_idempotent",
67
71
  "retry_params_name": "default"
@@ -71,7 +71,10 @@ module Google
71
71
  end
72
72
 
73
73
  def get_documents document_paths, mask: nil, transaction: nil
74
- batch_get_args = { mask: document_mask(mask) }
74
+ batch_get_args = {
75
+ documents: document_paths,
76
+ mask: document_mask(mask)
77
+ }
75
78
  if transaction.is_a? String
76
79
  batch_get_args[:transaction] = transaction
77
80
  elsif transaction
@@ -80,8 +83,7 @@ module Google
80
83
  batch_get_args[:options] = call_options parent: database_path
81
84
 
82
85
  execute do
83
- firestore.batch_get_documents database_path, document_paths,
84
- batch_get_args
86
+ firestore.batch_get_documents database_path, **batch_get_args
85
87
  end
86
88
  end
87
89
 
@@ -115,7 +117,7 @@ module Google
115
117
  list_args[:options] = call_options parent: database_path
116
118
 
117
119
  execute do
118
- firestore.list_collection_ids parent, list_args
120
+ firestore.list_collection_ids parent, **list_args
119
121
  end
120
122
  end
121
123
 
@@ -129,7 +131,7 @@ module Google
129
131
  run_query_args[:options] = call_options parent: database_path
130
132
 
131
133
  execute do
132
- firestore.run_query path, run_query_args
134
+ firestore.run_query path, **run_query_args
133
135
  end
134
136
  end
135
137
 
@@ -152,12 +154,14 @@ module Google
152
154
  end
153
155
 
154
156
  def commit writes, transaction: nil
155
- commit_args = {}
157
+ commit_args = {
158
+ writes: writes
159
+ }
156
160
  commit_args[:transaction] = transaction if transaction
157
161
  commit_args[:options] = call_options parent: database_path
158
162
 
159
163
  execute do
160
- firestore.commit database_path, writes, commit_args
164
+ firestore.commit database_path, **commit_args
161
165
  end
162
166
  end
163
167
 
@@ -170,11 +174,13 @@ module Google
170
174
  end
171
175
 
172
176
  def database_path project_id: project, database_id: "(default)"
173
- V1::FirestoreClient.database_root_path project_id, database_id
177
+ # Originally used V1::FirestoreClient.database_root_path until it was removed in #5405.
178
+ "projects/#{project_id}/databases/#{database_id}"
174
179
  end
175
180
 
176
181
  def documents_path project_id: project, database_id: "(default)"
177
- V1::FirestoreClient.document_root_path project_id, database_id
182
+ # Originally used V1::FirestoreClient.document_root_path until it was removed in #5405.
183
+ "projects/#{project_id}/databases/#{database_id}/documents"
178
184
  end
179
185
 
180
186
  def inspect
@@ -189,7 +195,7 @@ module Google
189
195
  end
190
196
 
191
197
  def call_options parent: nil, token: nil
192
- Google::Gax::CallOptions.new({
198
+ Google::Gax::CallOptions.new(**{
193
199
  metadata: default_headers(parent),
194
200
  page_token: token
195
201
  }.delete_if { |_, v| v.nil? })
@@ -80,80 +80,6 @@ module Google
80
80
  ].freeze
81
81
 
82
82
 
83
- ANY_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
84
- "projects/{project}/databases/{database}/documents/{document}/{any_path=**}"
85
- )
86
-
87
- private_constant :ANY_PATH_PATH_TEMPLATE
88
-
89
- DATABASE_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
90
- "projects/{project}/databases/{database}"
91
- )
92
-
93
- private_constant :DATABASE_ROOT_PATH_TEMPLATE
94
-
95
- DOCUMENT_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
96
- "projects/{project}/databases/{database}/documents/{document_path=**}"
97
- )
98
-
99
- private_constant :DOCUMENT_PATH_PATH_TEMPLATE
100
-
101
- DOCUMENT_ROOT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
102
- "projects/{project}/databases/{database}/documents"
103
- )
104
-
105
- private_constant :DOCUMENT_ROOT_PATH_TEMPLATE
106
-
107
- # Returns a fully-qualified any_path resource name string.
108
- # @param project [String]
109
- # @param database [String]
110
- # @param document [String]
111
- # @param any_path [String]
112
- # @return [String]
113
- def self.any_path_path project, database, document, any_path
114
- ANY_PATH_PATH_TEMPLATE.render(
115
- :"project" => project,
116
- :"database" => database,
117
- :"document" => document,
118
- :"any_path" => any_path
119
- )
120
- end
121
-
122
- # Returns a fully-qualified database_root resource name string.
123
- # @param project [String]
124
- # @param database [String]
125
- # @return [String]
126
- def self.database_root_path project, database
127
- DATABASE_ROOT_PATH_TEMPLATE.render(
128
- :"project" => project,
129
- :"database" => database
130
- )
131
- end
132
-
133
- # Returns a fully-qualified document_path resource name string.
134
- # @param project [String]
135
- # @param database [String]
136
- # @param document_path [String]
137
- # @return [String]
138
- def self.document_path_path project, database, document_path
139
- DOCUMENT_PATH_PATH_TEMPLATE.render(
140
- :"project" => project,
141
- :"database" => database,
142
- :"document_path" => document_path
143
- )
144
- end
145
-
146
- # Returns a fully-qualified document_root resource name string.
147
- # @param project [String]
148
- # @param database [String]
149
- # @return [String]
150
- def self.document_root_path project, database
151
- DOCUMENT_ROOT_PATH_TEMPLATE.render(
152
- :"project" => project,
153
- :"database" => database
154
- )
155
- end
156
-
157
83
  # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
158
84
  # Provides the means for authenticating requests made by the client. This parameter can
159
85
  # be many types.
@@ -231,6 +157,9 @@ module Google
231
157
  google_api_client.freeze
232
158
 
233
159
  headers = { :"x-goog-api-client" => google_api_client }
160
+ if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
161
+ headers[:"x-goog-user-project"] = credentials.quota_project_id
162
+ end
234
163
  headers.merge!(metadata) unless metadata.nil?
235
164
  client_config_file = Pathname.new(__dir__).join(
236
165
  "firestore_client_config.json"
@@ -390,8 +319,10 @@ module Google
390
319
  # require "google/cloud/firestore/v1"
391
320
  #
392
321
  # firestore_client = Google::Cloud::Firestore::V1.new
393
- # formatted_name = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
394
- # response = firestore_client.get_document(formatted_name)
322
+ #
323
+ # # TODO: Initialize `name`:
324
+ # name = ''
325
+ # response = firestore_client.get_document(name)
395
326
 
396
327
  def get_document \
397
328
  name,
@@ -468,18 +399,20 @@ module Google
468
399
  # require "google/cloud/firestore/v1"
469
400
  #
470
401
  # firestore_client = Google::Cloud::Firestore::V1.new
471
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
402
+ #
403
+ # # TODO: Initialize `parent`:
404
+ # parent = ''
472
405
  #
473
406
  # # TODO: Initialize `collection_id`:
474
407
  # collection_id = ''
475
408
  #
476
409
  # # Iterate over all results.
477
- # firestore_client.list_documents(formatted_parent, collection_id).each do |element|
410
+ # firestore_client.list_documents(parent, collection_id).each do |element|
478
411
  # # Process element.
479
412
  # end
480
413
  #
481
414
  # # Or iterate over results one page at a time.
482
- # firestore_client.list_documents(formatted_parent, collection_id).each_page do |page|
415
+ # firestore_client.list_documents(parent, collection_id).each_page do |page|
483
416
  # # Process each page at a time.
484
417
  # page.each do |element|
485
418
  # # Process element.
@@ -519,14 +452,14 @@ module Google
519
452
  # `projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
520
453
  # @param collection_id [String]
521
454
  # Required. The collection ID, relative to `parent`, to list. For example: `chatrooms`.
522
- # @param document_id [String]
523
- # The client-assigned document ID to use for this document.
524
- #
525
- # Optional. If not specified, an ID will be assigned by the service.
526
455
  # @param document [Google::Firestore::V1::Document | Hash]
527
456
  # Required. The document to create. `name` must not be set.
528
457
  # A hash of the same form as `Google::Firestore::V1::Document`
529
458
  # can also be provided.
459
+ # @param document_id [String]
460
+ # The client-assigned document ID to use for this document.
461
+ #
462
+ # Optional. If not specified, an ID will be assigned by the service.
530
463
  # @param mask [Google::Firestore::V1::DocumentMask | Hash]
531
464
  # The fields to return. If not set, returns all fields.
532
465
  #
@@ -546,31 +479,30 @@ module Google
546
479
  # require "google/cloud/firestore/v1"
547
480
  #
548
481
  # firestore_client = Google::Cloud::Firestore::V1.new
549
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
482
+ #
483
+ # # TODO: Initialize `parent`:
484
+ # parent = ''
550
485
  #
551
486
  # # TODO: Initialize `collection_id`:
552
487
  # collection_id = ''
553
488
  #
554
- # # TODO: Initialize `document_id`:
555
- # document_id = ''
556
- #
557
489
  # # TODO: Initialize `document`:
558
490
  # document = {}
559
- # response = firestore_client.create_document(formatted_parent, collection_id, document_id, document)
491
+ # response = firestore_client.create_document(parent, collection_id, document)
560
492
 
561
493
  def create_document \
562
494
  parent,
563
495
  collection_id,
564
- document_id,
565
496
  document,
497
+ document_id: nil,
566
498
  mask: nil,
567
499
  options: nil,
568
500
  &block
569
501
  req = {
570
502
  parent: parent,
571
503
  collection_id: collection_id,
572
- document_id: document_id,
573
504
  document: document,
505
+ document_id: document_id,
574
506
  mask: mask
575
507
  }.delete_if { |_, v| v.nil? }
576
508
  req = Google::Gax::to_proto(req, Google::Firestore::V1::CreateDocumentRequest)
@@ -621,14 +553,11 @@ module Google
621
553
  #
622
554
  # # TODO: Initialize `document`:
623
555
  # document = {}
624
- #
625
- # # TODO: Initialize `update_mask`:
626
- # update_mask = {}
627
- # response = firestore_client.update_document(document, update_mask)
556
+ # response = firestore_client.update_document(document)
628
557
 
629
558
  def update_document \
630
559
  document,
631
- update_mask,
560
+ update_mask: nil,
632
561
  mask: nil,
633
562
  current_document: nil,
634
563
  options: nil,
@@ -664,8 +593,10 @@ module Google
664
593
  # require "google/cloud/firestore/v1"
665
594
  #
666
595
  # firestore_client = Google::Cloud::Firestore::V1.new
667
- # formatted_name = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
668
- # firestore_client.delete_document(formatted_name)
596
+ #
597
+ # # TODO: Initialize `name`:
598
+ # name = ''
599
+ # firestore_client.delete_document(name)
669
600
 
670
601
  def delete_document \
671
602
  name,
@@ -726,17 +657,16 @@ module Google
726
657
  # require "google/cloud/firestore/v1"
727
658
  #
728
659
  # firestore_client = Google::Cloud::Firestore::V1.new
729
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
730
660
  #
731
- # # TODO: Initialize `documents`:
732
- # documents = []
733
- # firestore_client.batch_get_documents(formatted_database, documents).each do |element|
661
+ # # TODO: Initialize `database`:
662
+ # database = ''
663
+ # firestore_client.batch_get_documents(database).each do |element|
734
664
  # # Process element.
735
665
  # end
736
666
 
737
667
  def batch_get_documents \
738
668
  database,
739
- documents,
669
+ documents: nil,
740
670
  mask: nil,
741
671
  transaction: nil,
742
672
  new_transaction: nil,
@@ -776,8 +706,10 @@ module Google
776
706
  # require "google/cloud/firestore/v1"
777
707
  #
778
708
  # firestore_client = Google::Cloud::Firestore::V1.new
779
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
780
- # response = firestore_client.begin_transaction(formatted_database)
709
+ #
710
+ # # TODO: Initialize `database`:
711
+ # database = ''
712
+ # response = firestore_client.begin_transaction(database)
781
713
 
782
714
  def begin_transaction \
783
715
  database,
@@ -817,15 +749,14 @@ module Google
817
749
  # require "google/cloud/firestore/v1"
818
750
  #
819
751
  # firestore_client = Google::Cloud::Firestore::V1.new
820
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
821
752
  #
822
- # # TODO: Initialize `writes`:
823
- # writes = []
824
- # response = firestore_client.commit(formatted_database, writes)
753
+ # # TODO: Initialize `database`:
754
+ # database = ''
755
+ # response = firestore_client.commit(database)
825
756
 
826
757
  def commit \
827
758
  database,
828
- writes,
759
+ writes: nil,
829
760
  transaction: nil,
830
761
  options: nil,
831
762
  &block
@@ -856,11 +787,13 @@ module Google
856
787
  # require "google/cloud/firestore/v1"
857
788
  #
858
789
  # firestore_client = Google::Cloud::Firestore::V1.new
859
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
790
+ #
791
+ # # TODO: Initialize `database`:
792
+ # database = ''
860
793
  #
861
794
  # # TODO: Initialize `transaction`:
862
795
  # transaction = ''
863
- # firestore_client.rollback(formatted_database, transaction)
796
+ # firestore_client.rollback(database, transaction)
864
797
 
865
798
  def rollback \
866
799
  database,
@@ -914,8 +847,10 @@ module Google
914
847
  # require "google/cloud/firestore/v1"
915
848
  #
916
849
  # firestore_client = Google::Cloud::Firestore::V1.new
917
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
918
- # firestore_client.run_query(formatted_parent).each do |element|
850
+ #
851
+ # # TODO: Initialize `parent`:
852
+ # parent = ''
853
+ # firestore_client.run_query(parent).each do |element|
919
854
  # # Process element.
920
855
  # end
921
856
 
@@ -958,8 +893,10 @@ module Google
958
893
  # require "google/cloud/firestore/v1"
959
894
  #
960
895
  # firestore_client = Google::Cloud::Firestore::V1.new
961
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
962
- # request = { database: formatted_database }
896
+ #
897
+ # # TODO: Initialize `database`:
898
+ # database = ''
899
+ # request = { database: database }
963
900
  # requests = [request]
964
901
  # firestore_client.write(requests).each do |element|
965
902
  # # Process element.
@@ -993,8 +930,10 @@ module Google
993
930
  # require "google/cloud/firestore/v1"
994
931
  #
995
932
  # firestore_client = Google::Cloud::Firestore::V1.new
996
- # formatted_database = Google::Cloud::Firestore::V1::FirestoreClient.database_root_path("[PROJECT]", "[DATABASE]")
997
- # request = { database: formatted_database }
933
+ #
934
+ # # TODO: Initialize `database`:
935
+ # database = ''
936
+ # request = { database: database }
998
937
  # requests = [request]
999
938
  # firestore_client.listen(requests).each do |element|
1000
939
  # # Process element.
@@ -1036,15 +975,17 @@ module Google
1036
975
  # require "google/cloud/firestore/v1"
1037
976
  #
1038
977
  # firestore_client = Google::Cloud::Firestore::V1.new
1039
- # formatted_parent = Google::Cloud::Firestore::V1::FirestoreClient.any_path_path("[PROJECT]", "[DATABASE]", "[DOCUMENT]", "[ANY_PATH]")
978
+ #
979
+ # # TODO: Initialize `parent`:
980
+ # parent = ''
1040
981
  #
1041
982
  # # Iterate over all results.
1042
- # firestore_client.list_collection_ids(formatted_parent).each do |element|
983
+ # firestore_client.list_collection_ids(parent).each do |element|
1043
984
  # # Process element.
1044
985
  # end
1045
986
  #
1046
987
  # # Or iterate over results one page at a time.
1047
- # firestore_client.list_collection_ids(formatted_parent).each_page do |page|
988
+ # firestore_client.list_collection_ids(parent).each_page do |page|
1048
989
  # # Process each page at a time.
1049
990
  # page.each do |element|
1050
991
  # # Process element.