google-cloud-datastore-v1 0.9.0 → 0.11.0

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.
@@ -0,0 +1,963 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/datastore/v1/datastore_pb"
21
+ require "google/cloud/datastore/v1/datastore/rest/service_stub"
22
+
23
+ module Google
24
+ module Cloud
25
+ module Datastore
26
+ module V1
27
+ module Datastore
28
+ module Rest
29
+ ##
30
+ # REST client for the Datastore service.
31
+ #
32
+ # Each RPC normalizes the partition IDs of the keys in its input entities,
33
+ # and always returns entities with keys with normalized partition IDs.
34
+ # This applies to all keys and entities, including those in values, except keys
35
+ # with both an empty path and an empty or unset partition ID. Normalization of
36
+ # input keys sets the project ID (if not already set) to the project ID from
37
+ # the request.
38
+ #
39
+ class Client
40
+ # @private
41
+ attr_reader :datastore_stub
42
+
43
+ ##
44
+ # Configure the Datastore Client class.
45
+ #
46
+ # See {::Google::Cloud::Datastore::V1::Datastore::Rest::Client::Configuration}
47
+ # for a description of the configuration fields.
48
+ #
49
+ # @example
50
+ #
51
+ # # Modify the configuration for all Datastore clients
52
+ # ::Google::Cloud::Datastore::V1::Datastore::Rest::Client.configure do |config|
53
+ # config.timeout = 10.0
54
+ # end
55
+ #
56
+ # @yield [config] Configure the Client client.
57
+ # @yieldparam config [Client::Configuration]
58
+ #
59
+ # @return [Client::Configuration]
60
+ #
61
+ def self.configure
62
+ @configure ||= begin
63
+ namespace = ["Google", "Cloud", "Datastore", "V1"]
64
+ parent_config = while namespace.any?
65
+ parent_name = namespace.join "::"
66
+ parent_const = const_get parent_name
67
+ break parent_const.configure if parent_const.respond_to? :configure
68
+ namespace.pop
69
+ end
70
+ default_config = Client::Configuration.new parent_config
71
+
72
+ default_config.rpcs.lookup.timeout = 60.0
73
+ default_config.rpcs.lookup.retry_policy = {
74
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
75
+ }
76
+
77
+ default_config.rpcs.run_query.timeout = 60.0
78
+ default_config.rpcs.run_query.retry_policy = {
79
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
80
+ }
81
+
82
+ default_config.rpcs.run_aggregation_query.timeout = 60.0
83
+ default_config.rpcs.run_aggregation_query.retry_policy = {
84
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
85
+ }
86
+
87
+ default_config.rpcs.begin_transaction.timeout = 60.0
88
+
89
+ default_config.rpcs.commit.timeout = 60.0
90
+
91
+ default_config.rpcs.rollback.timeout = 60.0
92
+
93
+ default_config.rpcs.allocate_ids.timeout = 60.0
94
+
95
+ default_config.rpcs.reserve_ids.timeout = 60.0
96
+ default_config.rpcs.reserve_ids.retry_policy = {
97
+ initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [14, 4]
98
+ }
99
+
100
+ default_config
101
+ end
102
+ yield @configure if block_given?
103
+ @configure
104
+ end
105
+
106
+ ##
107
+ # Configure the Datastore Client instance.
108
+ #
109
+ # The configuration is set to the derived mode, meaning that values can be changed,
110
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
111
+ # should be made on {Client.configure}.
112
+ #
113
+ # See {::Google::Cloud::Datastore::V1::Datastore::Rest::Client::Configuration}
114
+ # for a description of the configuration fields.
115
+ #
116
+ # @yield [config] Configure the Client client.
117
+ # @yieldparam config [Client::Configuration]
118
+ #
119
+ # @return [Client::Configuration]
120
+ #
121
+ def configure
122
+ yield @config if block_given?
123
+ @config
124
+ end
125
+
126
+ ##
127
+ # Create a new Datastore REST client object.
128
+ #
129
+ # @example
130
+ #
131
+ # # Create a client using the default configuration
132
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Rest::Client.new
133
+ #
134
+ # # Create a client using a custom configuration
135
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Rest::Client.new do |config|
136
+ # config.timeout = 10.0
137
+ # end
138
+ #
139
+ # @yield [config] Configure the Datastore client.
140
+ # @yieldparam config [Client::Configuration]
141
+ #
142
+ def initialize
143
+ # Create the configuration object
144
+ @config = Configuration.new Client.configure
145
+
146
+ # Yield the configuration if needed
147
+ yield @config if block_given?
148
+
149
+ # Create credentials
150
+ credentials = @config.credentials
151
+ # Use self-signed JWT if the endpoint is unchanged from default,
152
+ # but only if the default endpoint does not have a region prefix.
153
+ enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
154
+ !@config.endpoint.split(".").first.include?("-")
155
+ credentials ||= Credentials.default scope: @config.scope,
156
+ enable_self_signed_jwt: enable_self_signed_jwt
157
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
158
+ credentials = Credentials.new credentials, scope: @config.scope
159
+ end
160
+
161
+ @quota_project_id = @config.quota_project
162
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
163
+
164
+ @datastore_stub = ::Google::Cloud::Datastore::V1::Datastore::Rest::ServiceStub.new endpoint: @config.endpoint, credentials: credentials
165
+ end
166
+
167
+ # Service calls
168
+
169
+ ##
170
+ # Looks up entities by key.
171
+ #
172
+ # @overload lookup(request, options = nil)
173
+ # Pass arguments to `lookup` via a request object, either of type
174
+ # {::Google::Cloud::Datastore::V1::LookupRequest} or an equivalent Hash.
175
+ #
176
+ # @param request [::Google::Cloud::Datastore::V1::LookupRequest, ::Hash]
177
+ # A request object representing the call parameters. Required. To specify no
178
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
179
+ # @param options [::Gapic::CallOptions, ::Hash]
180
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
181
+ #
182
+ # @overload lookup(project_id: nil, database_id: nil, read_options: nil, keys: nil)
183
+ # Pass arguments to `lookup` via keyword arguments. Note that at
184
+ # least one keyword argument is required. To specify no parameters, or to keep all
185
+ # the default parameter values, pass an empty Hash as a request object (see above).
186
+ #
187
+ # @param project_id [::String]
188
+ # Required. The ID of the project against which to make the request.
189
+ # @param database_id [::String]
190
+ # The ID of the database against which to make the request.
191
+ #
192
+ # '(default)' is not allowed; please use empty string '' to refer the default
193
+ # database.
194
+ # @param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
195
+ # The options for this lookup request.
196
+ # @param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
197
+ # Required. Keys of entities to look up.
198
+ # @yield [result, operation] Access the result along with the TransportOperation object
199
+ # @yieldparam result [::Google::Cloud::Datastore::V1::LookupResponse]
200
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
201
+ #
202
+ # @return [::Google::Cloud::Datastore::V1::LookupResponse]
203
+ #
204
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
205
+ def lookup request, options = nil
206
+ raise ::ArgumentError, "request must be provided" if request.nil?
207
+
208
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::LookupRequest
209
+
210
+ # Converts hash and nil to an options object
211
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
212
+
213
+ # Customize the options with defaults
214
+ call_metadata = @config.rpcs.lookup.metadata.to_h
215
+
216
+ # Set x-goog-api-client and x-goog-user-project headers
217
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
218
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
219
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
220
+ transports_version_send: [:rest]
221
+
222
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
223
+
224
+ options.apply_defaults timeout: @config.rpcs.lookup.timeout,
225
+ metadata: call_metadata,
226
+ retry_policy: @config.rpcs.lookup.retry_policy
227
+
228
+ options.apply_defaults timeout: @config.timeout,
229
+ metadata: @config.metadata,
230
+ retry_policy: @config.retry_policy
231
+
232
+ @datastore_stub.lookup request, options do |result, operation|
233
+ yield result, operation if block_given?
234
+ return result
235
+ end
236
+ rescue ::Gapic::Rest::Error => e
237
+ raise ::Google::Cloud::Error.from_error(e)
238
+ end
239
+
240
+ ##
241
+ # Queries for entities.
242
+ #
243
+ # @overload run_query(request, options = nil)
244
+ # Pass arguments to `run_query` via a request object, either of type
245
+ # {::Google::Cloud::Datastore::V1::RunQueryRequest} or an equivalent Hash.
246
+ #
247
+ # @param request [::Google::Cloud::Datastore::V1::RunQueryRequest, ::Hash]
248
+ # A request object representing the call parameters. Required. To specify no
249
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
250
+ # @param options [::Gapic::CallOptions, ::Hash]
251
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
252
+ #
253
+ # @overload run_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, query: nil, gql_query: nil)
254
+ # Pass arguments to `run_query` via keyword arguments. Note that at
255
+ # least one keyword argument is required. To specify no parameters, or to keep all
256
+ # the default parameter values, pass an empty Hash as a request object (see above).
257
+ #
258
+ # @param project_id [::String]
259
+ # Required. The ID of the project against which to make the request.
260
+ # @param database_id [::String]
261
+ # The ID of the database against which to make the request.
262
+ #
263
+ # '(default)' is not allowed; please use empty string '' to refer the default
264
+ # database.
265
+ # @param partition_id [::Google::Cloud::Datastore::V1::PartitionId, ::Hash]
266
+ # Entities are partitioned into subsets, identified by a partition ID.
267
+ # Queries are scoped to a single partition.
268
+ # This partition ID is normalized with the standard default context
269
+ # partition ID.
270
+ # @param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
271
+ # The options for this query.
272
+ # @param query [::Google::Cloud::Datastore::V1::Query, ::Hash]
273
+ # The query to run.
274
+ # @param gql_query [::Google::Cloud::Datastore::V1::GqlQuery, ::Hash]
275
+ # The GQL query to run. This query must be a non-aggregation query.
276
+ # @yield [result, operation] Access the result along with the TransportOperation object
277
+ # @yieldparam result [::Google::Cloud::Datastore::V1::RunQueryResponse]
278
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
279
+ #
280
+ # @return [::Google::Cloud::Datastore::V1::RunQueryResponse]
281
+ #
282
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
283
+ def run_query request, options = nil
284
+ raise ::ArgumentError, "request must be provided" if request.nil?
285
+
286
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunQueryRequest
287
+
288
+ # Converts hash and nil to an options object
289
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
290
+
291
+ # Customize the options with defaults
292
+ call_metadata = @config.rpcs.run_query.metadata.to_h
293
+
294
+ # Set x-goog-api-client and x-goog-user-project headers
295
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
296
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
297
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
298
+ transports_version_send: [:rest]
299
+
300
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
301
+
302
+ options.apply_defaults timeout: @config.rpcs.run_query.timeout,
303
+ metadata: call_metadata,
304
+ retry_policy: @config.rpcs.run_query.retry_policy
305
+
306
+ options.apply_defaults timeout: @config.timeout,
307
+ metadata: @config.metadata,
308
+ retry_policy: @config.retry_policy
309
+
310
+ @datastore_stub.run_query request, options do |result, operation|
311
+ yield result, operation if block_given?
312
+ return result
313
+ end
314
+ rescue ::Gapic::Rest::Error => e
315
+ raise ::Google::Cloud::Error.from_error(e)
316
+ end
317
+
318
+ ##
319
+ # Runs an aggregation query.
320
+ #
321
+ # @overload run_aggregation_query(request, options = nil)
322
+ # Pass arguments to `run_aggregation_query` via a request object, either of type
323
+ # {::Google::Cloud::Datastore::V1::RunAggregationQueryRequest} or an equivalent Hash.
324
+ #
325
+ # @param request [::Google::Cloud::Datastore::V1::RunAggregationQueryRequest, ::Hash]
326
+ # A request object representing the call parameters. Required. To specify no
327
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
328
+ # @param options [::Gapic::CallOptions, ::Hash]
329
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
330
+ #
331
+ # @overload run_aggregation_query(project_id: nil, database_id: nil, partition_id: nil, read_options: nil, aggregation_query: nil, gql_query: nil)
332
+ # Pass arguments to `run_aggregation_query` via keyword arguments. Note that at
333
+ # least one keyword argument is required. To specify no parameters, or to keep all
334
+ # the default parameter values, pass an empty Hash as a request object (see above).
335
+ #
336
+ # @param project_id [::String]
337
+ # Required. The ID of the project against which to make the request.
338
+ # @param database_id [::String]
339
+ # The ID of the database against which to make the request.
340
+ #
341
+ # '(default)' is not allowed; please use empty string '' to refer the default
342
+ # database.
343
+ # @param partition_id [::Google::Cloud::Datastore::V1::PartitionId, ::Hash]
344
+ # Entities are partitioned into subsets, identified by a partition ID.
345
+ # Queries are scoped to a single partition.
346
+ # This partition ID is normalized with the standard default context
347
+ # partition ID.
348
+ # @param read_options [::Google::Cloud::Datastore::V1::ReadOptions, ::Hash]
349
+ # The options for this query.
350
+ # @param aggregation_query [::Google::Cloud::Datastore::V1::AggregationQuery, ::Hash]
351
+ # The query to run.
352
+ # @param gql_query [::Google::Cloud::Datastore::V1::GqlQuery, ::Hash]
353
+ # The GQL query to run. This query must be an aggregation query.
354
+ # @yield [result, operation] Access the result along with the TransportOperation object
355
+ # @yieldparam result [::Google::Cloud::Datastore::V1::RunAggregationQueryResponse]
356
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
357
+ #
358
+ # @return [::Google::Cloud::Datastore::V1::RunAggregationQueryResponse]
359
+ #
360
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
361
+ def run_aggregation_query request, options = nil
362
+ raise ::ArgumentError, "request must be provided" if request.nil?
363
+
364
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RunAggregationQueryRequest
365
+
366
+ # Converts hash and nil to an options object
367
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
368
+
369
+ # Customize the options with defaults
370
+ call_metadata = @config.rpcs.run_aggregation_query.metadata.to_h
371
+
372
+ # Set x-goog-api-client and x-goog-user-project headers
373
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
374
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
375
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
376
+ transports_version_send: [:rest]
377
+
378
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
379
+
380
+ options.apply_defaults timeout: @config.rpcs.run_aggregation_query.timeout,
381
+ metadata: call_metadata,
382
+ retry_policy: @config.rpcs.run_aggregation_query.retry_policy
383
+
384
+ options.apply_defaults timeout: @config.timeout,
385
+ metadata: @config.metadata,
386
+ retry_policy: @config.retry_policy
387
+
388
+ @datastore_stub.run_aggregation_query request, options do |result, operation|
389
+ yield result, operation if block_given?
390
+ return result
391
+ end
392
+ rescue ::Gapic::Rest::Error => e
393
+ raise ::Google::Cloud::Error.from_error(e)
394
+ end
395
+
396
+ ##
397
+ # Begins a new transaction.
398
+ #
399
+ # @overload begin_transaction(request, options = nil)
400
+ # Pass arguments to `begin_transaction` via a request object, either of type
401
+ # {::Google::Cloud::Datastore::V1::BeginTransactionRequest} or an equivalent Hash.
402
+ #
403
+ # @param request [::Google::Cloud::Datastore::V1::BeginTransactionRequest, ::Hash]
404
+ # A request object representing the call parameters. Required. To specify no
405
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
406
+ # @param options [::Gapic::CallOptions, ::Hash]
407
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
408
+ #
409
+ # @overload begin_transaction(project_id: nil, database_id: nil, transaction_options: nil)
410
+ # Pass arguments to `begin_transaction` via keyword arguments. Note that at
411
+ # least one keyword argument is required. To specify no parameters, or to keep all
412
+ # the default parameter values, pass an empty Hash as a request object (see above).
413
+ #
414
+ # @param project_id [::String]
415
+ # Required. The ID of the project against which to make the request.
416
+ # @param database_id [::String]
417
+ # The ID of the database against which to make the request.
418
+ #
419
+ # '(default)' is not allowed; please use empty string '' to refer the default
420
+ # database.
421
+ # @param transaction_options [::Google::Cloud::Datastore::V1::TransactionOptions, ::Hash]
422
+ # Options for a new transaction.
423
+ # @yield [result, operation] Access the result along with the TransportOperation object
424
+ # @yieldparam result [::Google::Cloud::Datastore::V1::BeginTransactionResponse]
425
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
426
+ #
427
+ # @return [::Google::Cloud::Datastore::V1::BeginTransactionResponse]
428
+ #
429
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
430
+ def begin_transaction request, options = nil
431
+ raise ::ArgumentError, "request must be provided" if request.nil?
432
+
433
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::BeginTransactionRequest
434
+
435
+ # Converts hash and nil to an options object
436
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
437
+
438
+ # Customize the options with defaults
439
+ call_metadata = @config.rpcs.begin_transaction.metadata.to_h
440
+
441
+ # Set x-goog-api-client and x-goog-user-project headers
442
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
443
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
444
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
445
+ transports_version_send: [:rest]
446
+
447
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
448
+
449
+ options.apply_defaults timeout: @config.rpcs.begin_transaction.timeout,
450
+ metadata: call_metadata,
451
+ retry_policy: @config.rpcs.begin_transaction.retry_policy
452
+
453
+ options.apply_defaults timeout: @config.timeout,
454
+ metadata: @config.metadata,
455
+ retry_policy: @config.retry_policy
456
+
457
+ @datastore_stub.begin_transaction request, options do |result, operation|
458
+ yield result, operation if block_given?
459
+ return result
460
+ end
461
+ rescue ::Gapic::Rest::Error => e
462
+ raise ::Google::Cloud::Error.from_error(e)
463
+ end
464
+
465
+ ##
466
+ # Commits a transaction, optionally creating, deleting or modifying some
467
+ # entities.
468
+ #
469
+ # @overload commit(request, options = nil)
470
+ # Pass arguments to `commit` via a request object, either of type
471
+ # {::Google::Cloud::Datastore::V1::CommitRequest} or an equivalent Hash.
472
+ #
473
+ # @param request [::Google::Cloud::Datastore::V1::CommitRequest, ::Hash]
474
+ # A request object representing the call parameters. Required. To specify no
475
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
476
+ # @param options [::Gapic::CallOptions, ::Hash]
477
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
478
+ #
479
+ # @overload commit(project_id: nil, database_id: nil, mode: nil, transaction: nil, single_use_transaction: nil, mutations: nil)
480
+ # Pass arguments to `commit` via keyword arguments. Note that at
481
+ # least one keyword argument is required. To specify no parameters, or to keep all
482
+ # the default parameter values, pass an empty Hash as a request object (see above).
483
+ #
484
+ # @param project_id [::String]
485
+ # Required. The ID of the project against which to make the request.
486
+ # @param database_id [::String]
487
+ # The ID of the database against which to make the request.
488
+ #
489
+ # '(default)' is not allowed; please use empty string '' to refer the default
490
+ # database.
491
+ # @param mode [::Google::Cloud::Datastore::V1::CommitRequest::Mode]
492
+ # The type of commit to perform. Defaults to `TRANSACTIONAL`.
493
+ # @param transaction [::String]
494
+ # The identifier of the transaction associated with the commit. A
495
+ # transaction identifier is returned by a call to
496
+ # {::Google::Cloud::Datastore::V1::Datastore::Rest::Client#begin_transaction Datastore.BeginTransaction}.
497
+ # @param single_use_transaction [::Google::Cloud::Datastore::V1::TransactionOptions, ::Hash]
498
+ # Options for beginning a new transaction for this request.
499
+ # The transaction is committed when the request completes. If specified,
500
+ # {::Google::Cloud::Datastore::V1::TransactionOptions TransactionOptions.mode} must be
501
+ # {::Google::Cloud::Datastore::V1::TransactionOptions::ReadWrite TransactionOptions.ReadWrite}.
502
+ # @param mutations [::Array<::Google::Cloud::Datastore::V1::Mutation, ::Hash>]
503
+ # The mutations to perform.
504
+ #
505
+ # When mode is `TRANSACTIONAL`, mutations affecting a single entity are
506
+ # applied in order. The following sequences of mutations affecting a single
507
+ # entity are not permitted in a single `Commit` request:
508
+ #
509
+ # - `insert` followed by `insert`
510
+ # - `update` followed by `insert`
511
+ # - `upsert` followed by `insert`
512
+ # - `delete` followed by `update`
513
+ #
514
+ # When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single
515
+ # entity.
516
+ # @yield [result, operation] Access the result along with the TransportOperation object
517
+ # @yieldparam result [::Google::Cloud::Datastore::V1::CommitResponse]
518
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
519
+ #
520
+ # @return [::Google::Cloud::Datastore::V1::CommitResponse]
521
+ #
522
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
523
+ def commit request, options = nil
524
+ raise ::ArgumentError, "request must be provided" if request.nil?
525
+
526
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::CommitRequest
527
+
528
+ # Converts hash and nil to an options object
529
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
530
+
531
+ # Customize the options with defaults
532
+ call_metadata = @config.rpcs.commit.metadata.to_h
533
+
534
+ # Set x-goog-api-client and x-goog-user-project headers
535
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
536
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
537
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
538
+ transports_version_send: [:rest]
539
+
540
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
541
+
542
+ options.apply_defaults timeout: @config.rpcs.commit.timeout,
543
+ metadata: call_metadata,
544
+ retry_policy: @config.rpcs.commit.retry_policy
545
+
546
+ options.apply_defaults timeout: @config.timeout,
547
+ metadata: @config.metadata,
548
+ retry_policy: @config.retry_policy
549
+
550
+ @datastore_stub.commit request, options do |result, operation|
551
+ yield result, operation if block_given?
552
+ return result
553
+ end
554
+ rescue ::Gapic::Rest::Error => e
555
+ raise ::Google::Cloud::Error.from_error(e)
556
+ end
557
+
558
+ ##
559
+ # Rolls back a transaction.
560
+ #
561
+ # @overload rollback(request, options = nil)
562
+ # Pass arguments to `rollback` via a request object, either of type
563
+ # {::Google::Cloud::Datastore::V1::RollbackRequest} or an equivalent Hash.
564
+ #
565
+ # @param request [::Google::Cloud::Datastore::V1::RollbackRequest, ::Hash]
566
+ # A request object representing the call parameters. Required. To specify no
567
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
568
+ # @param options [::Gapic::CallOptions, ::Hash]
569
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
570
+ #
571
+ # @overload rollback(project_id: nil, database_id: nil, transaction: nil)
572
+ # Pass arguments to `rollback` via keyword arguments. Note that at
573
+ # least one keyword argument is required. To specify no parameters, or to keep all
574
+ # the default parameter values, pass an empty Hash as a request object (see above).
575
+ #
576
+ # @param project_id [::String]
577
+ # Required. The ID of the project against which to make the request.
578
+ # @param database_id [::String]
579
+ # The ID of the database against which to make the request.
580
+ #
581
+ # '(default)' is not allowed; please use empty string '' to refer the default
582
+ # database.
583
+ # @param transaction [::String]
584
+ # Required. The transaction identifier, returned by a call to
585
+ # {::Google::Cloud::Datastore::V1::Datastore::Rest::Client#begin_transaction Datastore.BeginTransaction}.
586
+ # @yield [result, operation] Access the result along with the TransportOperation object
587
+ # @yieldparam result [::Google::Cloud::Datastore::V1::RollbackResponse]
588
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
589
+ #
590
+ # @return [::Google::Cloud::Datastore::V1::RollbackResponse]
591
+ #
592
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
593
+ def rollback request, options = nil
594
+ raise ::ArgumentError, "request must be provided" if request.nil?
595
+
596
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::RollbackRequest
597
+
598
+ # Converts hash and nil to an options object
599
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
600
+
601
+ # Customize the options with defaults
602
+ call_metadata = @config.rpcs.rollback.metadata.to_h
603
+
604
+ # Set x-goog-api-client and x-goog-user-project headers
605
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
606
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
607
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
608
+ transports_version_send: [:rest]
609
+
610
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
611
+
612
+ options.apply_defaults timeout: @config.rpcs.rollback.timeout,
613
+ metadata: call_metadata,
614
+ retry_policy: @config.rpcs.rollback.retry_policy
615
+
616
+ options.apply_defaults timeout: @config.timeout,
617
+ metadata: @config.metadata,
618
+ retry_policy: @config.retry_policy
619
+
620
+ @datastore_stub.rollback request, options do |result, operation|
621
+ yield result, operation if block_given?
622
+ return result
623
+ end
624
+ rescue ::Gapic::Rest::Error => e
625
+ raise ::Google::Cloud::Error.from_error(e)
626
+ end
627
+
628
+ ##
629
+ # Allocates IDs for the given keys, which is useful for referencing an entity
630
+ # before it is inserted.
631
+ #
632
+ # @overload allocate_ids(request, options = nil)
633
+ # Pass arguments to `allocate_ids` via a request object, either of type
634
+ # {::Google::Cloud::Datastore::V1::AllocateIdsRequest} or an equivalent Hash.
635
+ #
636
+ # @param request [::Google::Cloud::Datastore::V1::AllocateIdsRequest, ::Hash]
637
+ # A request object representing the call parameters. Required. To specify no
638
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
639
+ # @param options [::Gapic::CallOptions, ::Hash]
640
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
641
+ #
642
+ # @overload allocate_ids(project_id: nil, database_id: nil, keys: nil)
643
+ # Pass arguments to `allocate_ids` via keyword arguments. Note that at
644
+ # least one keyword argument is required. To specify no parameters, or to keep all
645
+ # the default parameter values, pass an empty Hash as a request object (see above).
646
+ #
647
+ # @param project_id [::String]
648
+ # Required. The ID of the project against which to make the request.
649
+ # @param database_id [::String]
650
+ # The ID of the database against which to make the request.
651
+ #
652
+ # '(default)' is not allowed; please use empty string '' to refer the default
653
+ # database.
654
+ # @param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
655
+ # Required. A list of keys with incomplete key paths for which to allocate
656
+ # IDs. No key may be reserved/read-only.
657
+ # @yield [result, operation] Access the result along with the TransportOperation object
658
+ # @yieldparam result [::Google::Cloud::Datastore::V1::AllocateIdsResponse]
659
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
660
+ #
661
+ # @return [::Google::Cloud::Datastore::V1::AllocateIdsResponse]
662
+ #
663
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
664
+ def allocate_ids request, options = nil
665
+ raise ::ArgumentError, "request must be provided" if request.nil?
666
+
667
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::AllocateIdsRequest
668
+
669
+ # Converts hash and nil to an options object
670
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
671
+
672
+ # Customize the options with defaults
673
+ call_metadata = @config.rpcs.allocate_ids.metadata.to_h
674
+
675
+ # Set x-goog-api-client and x-goog-user-project headers
676
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
677
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
678
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
679
+ transports_version_send: [:rest]
680
+
681
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
682
+
683
+ options.apply_defaults timeout: @config.rpcs.allocate_ids.timeout,
684
+ metadata: call_metadata,
685
+ retry_policy: @config.rpcs.allocate_ids.retry_policy
686
+
687
+ options.apply_defaults timeout: @config.timeout,
688
+ metadata: @config.metadata,
689
+ retry_policy: @config.retry_policy
690
+
691
+ @datastore_stub.allocate_ids request, options do |result, operation|
692
+ yield result, operation if block_given?
693
+ return result
694
+ end
695
+ rescue ::Gapic::Rest::Error => e
696
+ raise ::Google::Cloud::Error.from_error(e)
697
+ end
698
+
699
+ ##
700
+ # Prevents the supplied keys' IDs from being auto-allocated by Cloud
701
+ # Datastore.
702
+ #
703
+ # @overload reserve_ids(request, options = nil)
704
+ # Pass arguments to `reserve_ids` via a request object, either of type
705
+ # {::Google::Cloud::Datastore::V1::ReserveIdsRequest} or an equivalent Hash.
706
+ #
707
+ # @param request [::Google::Cloud::Datastore::V1::ReserveIdsRequest, ::Hash]
708
+ # A request object representing the call parameters. Required. To specify no
709
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
710
+ # @param options [::Gapic::CallOptions, ::Hash]
711
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
712
+ #
713
+ # @overload reserve_ids(project_id: nil, database_id: nil, keys: nil)
714
+ # Pass arguments to `reserve_ids` via keyword arguments. Note that at
715
+ # least one keyword argument is required. To specify no parameters, or to keep all
716
+ # the default parameter values, pass an empty Hash as a request object (see above).
717
+ #
718
+ # @param project_id [::String]
719
+ # Required. The ID of the project against which to make the request.
720
+ # @param database_id [::String]
721
+ # The ID of the database against which to make the request.
722
+ #
723
+ # '(default)' is not allowed; please use empty string '' to refer the default
724
+ # database.
725
+ # @param keys [::Array<::Google::Cloud::Datastore::V1::Key, ::Hash>]
726
+ # Required. A list of keys with complete key paths whose numeric IDs should
727
+ # not be auto-allocated.
728
+ # @yield [result, operation] Access the result along with the TransportOperation object
729
+ # @yieldparam result [::Google::Cloud::Datastore::V1::ReserveIdsResponse]
730
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
731
+ #
732
+ # @return [::Google::Cloud::Datastore::V1::ReserveIdsResponse]
733
+ #
734
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
735
+ def reserve_ids request, options = nil
736
+ raise ::ArgumentError, "request must be provided" if request.nil?
737
+
738
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Datastore::V1::ReserveIdsRequest
739
+
740
+ # Converts hash and nil to an options object
741
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
742
+
743
+ # Customize the options with defaults
744
+ call_metadata = @config.rpcs.reserve_ids.metadata.to_h
745
+
746
+ # Set x-goog-api-client and x-goog-user-project headers
747
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
748
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
749
+ gapic_version: ::Google::Cloud::Datastore::V1::VERSION,
750
+ transports_version_send: [:rest]
751
+
752
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
753
+
754
+ options.apply_defaults timeout: @config.rpcs.reserve_ids.timeout,
755
+ metadata: call_metadata,
756
+ retry_policy: @config.rpcs.reserve_ids.retry_policy
757
+
758
+ options.apply_defaults timeout: @config.timeout,
759
+ metadata: @config.metadata,
760
+ retry_policy: @config.retry_policy
761
+
762
+ @datastore_stub.reserve_ids request, options do |result, operation|
763
+ yield result, operation if block_given?
764
+ return result
765
+ end
766
+ rescue ::Gapic::Rest::Error => e
767
+ raise ::Google::Cloud::Error.from_error(e)
768
+ end
769
+
770
+ ##
771
+ # Configuration class for the Datastore REST API.
772
+ #
773
+ # This class represents the configuration for Datastore REST,
774
+ # providing control over timeouts, retry behavior, logging, transport
775
+ # parameters, and other low-level controls. Certain parameters can also be
776
+ # applied individually to specific RPCs. See
777
+ # {::Google::Cloud::Datastore::V1::Datastore::Rest::Client::Configuration::Rpcs}
778
+ # for a list of RPCs that can be configured independently.
779
+ #
780
+ # Configuration can be applied globally to all clients, or to a single client
781
+ # on construction.
782
+ #
783
+ # @example
784
+ #
785
+ # # Modify the global config, setting the timeout for
786
+ # # lookup to 20 seconds,
787
+ # # and all remaining timeouts to 10 seconds.
788
+ # ::Google::Cloud::Datastore::V1::Datastore::Rest::Client.configure do |config|
789
+ # config.timeout = 10.0
790
+ # config.rpcs.lookup.timeout = 20.0
791
+ # end
792
+ #
793
+ # # Apply the above configuration only to a new client.
794
+ # client = ::Google::Cloud::Datastore::V1::Datastore::Rest::Client.new do |config|
795
+ # config.timeout = 10.0
796
+ # config.rpcs.lookup.timeout = 20.0
797
+ # end
798
+ #
799
+ # @!attribute [rw] endpoint
800
+ # The hostname or hostname:port of the service endpoint.
801
+ # Defaults to `"datastore.googleapis.com"`.
802
+ # @return [::String]
803
+ # @!attribute [rw] credentials
804
+ # Credentials to send with calls. You may provide any of the following types:
805
+ # * (`String`) The path to a service account key file in JSON format
806
+ # * (`Hash`) A service account key as a Hash
807
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
808
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
809
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
810
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
811
+ # * (`nil`) indicating no credentials
812
+ # @return [::Object]
813
+ # @!attribute [rw] scope
814
+ # The OAuth scopes
815
+ # @return [::Array<::String>]
816
+ # @!attribute [rw] lib_name
817
+ # The library name as recorded in instrumentation and logging
818
+ # @return [::String]
819
+ # @!attribute [rw] lib_version
820
+ # The library version as recorded in instrumentation and logging
821
+ # @return [::String]
822
+ # @!attribute [rw] timeout
823
+ # The call timeout in seconds.
824
+ # @return [::Numeric]
825
+ # @!attribute [rw] metadata
826
+ # Additional headers to be sent with the call.
827
+ # @return [::Hash{::Symbol=>::String}]
828
+ # @!attribute [rw] retry_policy
829
+ # The retry policy. The value is a hash with the following keys:
830
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
831
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
832
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
833
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
834
+ # trigger a retry.
835
+ # @return [::Hash]
836
+ # @!attribute [rw] quota_project
837
+ # A separate project against which to charge quota.
838
+ # @return [::String]
839
+ #
840
+ class Configuration
841
+ extend ::Gapic::Config
842
+
843
+ config_attr :endpoint, "datastore.googleapis.com", ::String
844
+ config_attr :credentials, nil do |value|
845
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
846
+ allowed.any? { |klass| klass === value }
847
+ end
848
+ config_attr :scope, nil, ::String, ::Array, nil
849
+ config_attr :lib_name, nil, ::String, nil
850
+ config_attr :lib_version, nil, ::String, nil
851
+ config_attr :timeout, nil, ::Numeric, nil
852
+ config_attr :metadata, nil, ::Hash, nil
853
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
854
+ config_attr :quota_project, nil, ::String, nil
855
+
856
+ # @private
857
+ def initialize parent_config = nil
858
+ @parent_config = parent_config unless parent_config.nil?
859
+
860
+ yield self if block_given?
861
+ end
862
+
863
+ ##
864
+ # Configurations for individual RPCs
865
+ # @return [Rpcs]
866
+ #
867
+ def rpcs
868
+ @rpcs ||= begin
869
+ parent_rpcs = nil
870
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
871
+ Rpcs.new parent_rpcs
872
+ end
873
+ end
874
+
875
+ ##
876
+ # Configuration RPC class for the Datastore API.
877
+ #
878
+ # Includes fields providing the configuration for each RPC in this service.
879
+ # Each configuration object is of type `Gapic::Config::Method` and includes
880
+ # the following configuration fields:
881
+ #
882
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
883
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
884
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
885
+ # include the following keys:
886
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
887
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
888
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
889
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
890
+ # trigger a retry.
891
+ #
892
+ class Rpcs
893
+ ##
894
+ # RPC-specific configuration for `lookup`
895
+ # @return [::Gapic::Config::Method]
896
+ #
897
+ attr_reader :lookup
898
+ ##
899
+ # RPC-specific configuration for `run_query`
900
+ # @return [::Gapic::Config::Method]
901
+ #
902
+ attr_reader :run_query
903
+ ##
904
+ # RPC-specific configuration for `run_aggregation_query`
905
+ # @return [::Gapic::Config::Method]
906
+ #
907
+ attr_reader :run_aggregation_query
908
+ ##
909
+ # RPC-specific configuration for `begin_transaction`
910
+ # @return [::Gapic::Config::Method]
911
+ #
912
+ attr_reader :begin_transaction
913
+ ##
914
+ # RPC-specific configuration for `commit`
915
+ # @return [::Gapic::Config::Method]
916
+ #
917
+ attr_reader :commit
918
+ ##
919
+ # RPC-specific configuration for `rollback`
920
+ # @return [::Gapic::Config::Method]
921
+ #
922
+ attr_reader :rollback
923
+ ##
924
+ # RPC-specific configuration for `allocate_ids`
925
+ # @return [::Gapic::Config::Method]
926
+ #
927
+ attr_reader :allocate_ids
928
+ ##
929
+ # RPC-specific configuration for `reserve_ids`
930
+ # @return [::Gapic::Config::Method]
931
+ #
932
+ attr_reader :reserve_ids
933
+
934
+ # @private
935
+ def initialize parent_rpcs = nil
936
+ lookup_config = parent_rpcs.lookup if parent_rpcs.respond_to? :lookup
937
+ @lookup = ::Gapic::Config::Method.new lookup_config
938
+ run_query_config = parent_rpcs.run_query if parent_rpcs.respond_to? :run_query
939
+ @run_query = ::Gapic::Config::Method.new run_query_config
940
+ run_aggregation_query_config = parent_rpcs.run_aggregation_query if parent_rpcs.respond_to? :run_aggregation_query
941
+ @run_aggregation_query = ::Gapic::Config::Method.new run_aggregation_query_config
942
+ begin_transaction_config = parent_rpcs.begin_transaction if parent_rpcs.respond_to? :begin_transaction
943
+ @begin_transaction = ::Gapic::Config::Method.new begin_transaction_config
944
+ commit_config = parent_rpcs.commit if parent_rpcs.respond_to? :commit
945
+ @commit = ::Gapic::Config::Method.new commit_config
946
+ rollback_config = parent_rpcs.rollback if parent_rpcs.respond_to? :rollback
947
+ @rollback = ::Gapic::Config::Method.new rollback_config
948
+ allocate_ids_config = parent_rpcs.allocate_ids if parent_rpcs.respond_to? :allocate_ids
949
+ @allocate_ids = ::Gapic::Config::Method.new allocate_ids_config
950
+ reserve_ids_config = parent_rpcs.reserve_ids if parent_rpcs.respond_to? :reserve_ids
951
+ @reserve_ids = ::Gapic::Config::Method.new reserve_ids_config
952
+
953
+ yield self if block_given?
954
+ end
955
+ end
956
+ end
957
+ end
958
+ end
959
+ end
960
+ end
961
+ end
962
+ end
963
+ end