couchbase 3.4.0-arm64-darwin-20

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +339 -0
  6. data/lib/couchbase/analytics_options.rb +107 -0
  7. data/lib/couchbase/authenticator.rb +65 -0
  8. data/lib/couchbase/binary_collection.rb +128 -0
  9. data/lib/couchbase/binary_collection_options.rb +24 -0
  10. data/lib/couchbase/bucket.rb +144 -0
  11. data/lib/couchbase/cluster.rb +439 -0
  12. data/lib/couchbase/cluster_registry.rb +44 -0
  13. data/lib/couchbase/collection.rb +589 -0
  14. data/lib/couchbase/collection_options.rb +300 -0
  15. data/lib/couchbase/config_profiles.rb +55 -0
  16. data/lib/couchbase/configuration.rb +57 -0
  17. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  18. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  19. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  20. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  21. data/lib/couchbase/datastructures.rb +24 -0
  22. data/lib/couchbase/diagnostics.rb +181 -0
  23. data/lib/couchbase/errors.rb +351 -0
  24. data/lib/couchbase/json_transcoder.rb +32 -0
  25. data/lib/couchbase/libcouchbase.bundle +0 -0
  26. data/lib/couchbase/logger.rb +85 -0
  27. data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
  28. data/lib/couchbase/management/bucket_manager.rb +436 -0
  29. data/lib/couchbase/management/collection_manager.rb +321 -0
  30. data/lib/couchbase/management/query_index_manager.rb +520 -0
  31. data/lib/couchbase/management/search_index_manager.rb +408 -0
  32. data/lib/couchbase/management/user_manager.rb +468 -0
  33. data/lib/couchbase/management/view_index_manager.rb +237 -0
  34. data/lib/couchbase/management.rb +27 -0
  35. data/lib/couchbase/mutation_state.rb +63 -0
  36. data/lib/couchbase/options.rb +2580 -0
  37. data/lib/couchbase/query_options.rb +120 -0
  38. data/lib/couchbase/railtie.rb +45 -0
  39. data/lib/couchbase/scope.rb +232 -0
  40. data/lib/couchbase/search_options.rb +1570 -0
  41. data/lib/couchbase/subdoc.rb +290 -0
  42. data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
  43. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  44. data/lib/couchbase/utils/time.rb +56 -0
  45. data/lib/couchbase/utils.rb +21 -0
  46. data/lib/couchbase/version.rb +23 -0
  47. data/lib/couchbase/view_options.rb +65 -0
  48. data/lib/couchbase.rb +20 -0
  49. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  50. metadata +101 -0
@@ -0,0 +1,2580 @@
1
+ # Copyright 2020-2021 Couchbase, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "couchbase/utils/time"
16
+ require "couchbase/config_profiles"
17
+
18
+ module Couchbase
19
+ # Definition of the Option classes for data APIs
20
+ module Options # rubocop:disable Metrics/ModuleLength
21
+ # Base class for most of the options
22
+ class Base
23
+ attr_accessor :timeout # @return [Integer, #in_milliseconds, nil]
24
+ attr_accessor :retry_strategy # @return [Proc, nil]
25
+ attr_accessor :client_context # @return [Hash, nil]
26
+ attr_accessor :parent_span # @return [Span, nil]
27
+
28
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
29
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
30
+ # @param [Hash, nil] client_context the client context data, if set
31
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
32
+ #
33
+ # @yieldparam [Base]
34
+ def initialize(timeout: nil,
35
+ retry_strategy: nil,
36
+ client_context: nil,
37
+ parent_span: nil)
38
+ @timeout = timeout
39
+ @retry_strategy = retry_strategy
40
+ @client_context = client_context
41
+ @parent_span = parent_span
42
+ yield self if block_given?
43
+ end
44
+
45
+ # @api private
46
+ def to_backend
47
+ {
48
+ timeout: Utils::Time.extract_duration(@timeout),
49
+ }
50
+ end
51
+ end
52
+
53
+ # Options for {Collection#get}
54
+ class Get < Base
55
+ attr_accessor :with_expiry # @return [Boolean]
56
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String, Integer)]
57
+
58
+ # Creates an instance of options for {Collection#get}
59
+ #
60
+ # @param [Array<String>] projections a list of paths that should be loaded if present.
61
+ # @param [Boolean] with_expiry if +true+ the expiration will be also fetched with {Collection#get}
62
+ # @param [JsonTranscoder, #decode(String, Integer)] transcoder used for decoding
63
+ #
64
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
65
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
66
+ # @param [Hash, nil] client_context the client context data, if set
67
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
68
+ #
69
+ # @yieldparam [Get] self
70
+ def initialize(projections: [],
71
+ with_expiry: false,
72
+ transcoder: JsonTranscoder.new,
73
+ timeout: nil,
74
+ retry_strategy: nil,
75
+ client_context: nil,
76
+ parent_span: nil)
77
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
78
+ @projections = projections
79
+ @with_expiry = with_expiry
80
+ @transcoder = transcoder
81
+ @preserve_array_indexes = false
82
+ yield self if block_given?
83
+ end
84
+
85
+ # Allows to specify a custom list paths to fetch from the document instead of the whole.
86
+ #
87
+ # Note that a maximum of 16 individual paths can be projected at a time due to a server limitation. If you need
88
+ # more than that, think about fetching less-generic paths or the full document straight away.
89
+ #
90
+ # @param [String, Array<String>] paths a path that should be loaded if present.
91
+ def project(*paths)
92
+ @projections ||= []
93
+ @projections |= paths.flatten # union with current projections
94
+ end
95
+
96
+ # @api private
97
+ # @return [Boolean] whether to use sparse arrays (default +false+)
98
+ attr_accessor :preserve_array_indexes
99
+
100
+ # @api private
101
+ # @return [Array<String>] list of paths to project
102
+ attr_accessor :projections
103
+
104
+ # @api private
105
+ # @return [Boolean]
106
+ def need_projected_get?
107
+ @with_expiry || !@projections&.empty?
108
+ end
109
+
110
+ # @api private
111
+ def to_backend
112
+ options = {
113
+ timeout: Utils::Time.extract_duration(@timeout),
114
+ }
115
+ options.update(with_expiry: true) if @with_expiry
116
+ unless @projections&.empty?
117
+ options.update({
118
+ projections: @projections,
119
+ preserve_array_indexes: @preserve_array_indexes,
120
+ })
121
+ end
122
+ options
123
+ end
124
+
125
+ # @api private
126
+ DEFAULT = Get.new.freeze
127
+ end
128
+
129
+ # Options for {Collection#get_multi}
130
+ class GetMulti < Base
131
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String, Integer)]
132
+
133
+ # Creates an instance of options for {Collection#get_multi}
134
+ #
135
+ # @param [JsonTranscoder, #decode(String, Integer)] transcoder used for decoding
136
+ #
137
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
138
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
139
+ # @param [Hash, nil] client_context the client context data, if set
140
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
141
+ #
142
+ # @yieldparam [GetMulti] self
143
+ def initialize(transcoder: JsonTranscoder.new,
144
+ timeout: nil,
145
+ retry_strategy: nil,
146
+ client_context: nil,
147
+ parent_span: nil)
148
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
149
+ @transcoder = transcoder
150
+ yield self if block_given?
151
+ end
152
+
153
+ # @api private
154
+ def to_backend
155
+ {
156
+ timeout: Utils::Time.extract_duration(@timeout),
157
+ }
158
+ end
159
+
160
+ # @api private
161
+ DEFAULT = GetMulti.new.freeze
162
+ end
163
+
164
+ # Options for {Collection#get_and_lock}
165
+ class GetAndLock < Base
166
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String, Integer)]
167
+
168
+ # Creates an instance of options for {Collection#get_and_lock}
169
+ #
170
+ # @param [JsonTranscoder, #decode(String, Integer)] transcoder used for decoding
171
+ #
172
+ # @param [Integer, #in_milliseconds, nil] timeout
173
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
174
+ # @param [Hash, nil] client_context the client context data, if set
175
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
176
+ #
177
+ # @yieldparam [GetAndLock] self
178
+ def initialize(transcoder: JsonTranscoder.new,
179
+ timeout: nil,
180
+ retry_strategy: nil,
181
+ client_context: nil,
182
+ parent_span: nil)
183
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
184
+ @transcoder = transcoder
185
+ yield self if block_given?
186
+ end
187
+
188
+ # @api private
189
+ def to_backend
190
+ {
191
+ timeout: Utils::Time.extract_duration(@timeout),
192
+ }
193
+ end
194
+
195
+ # @api private
196
+ DEFAULT = GetAndLock.new.freeze
197
+ end
198
+
199
+ # Options for {Collection#get_and_touch}
200
+ class GetAndTouch < Base
201
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String, Integer)]
202
+
203
+ # Creates an instance of options for {Collection#get_and_touch}
204
+ #
205
+ # @param [JsonTranscoder, #decode(String, Integer)] transcoder used for decoding
206
+ #
207
+ # @param [Integer, #in_milliseconds, nil] timeout
208
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
209
+ # @param [Hash, nil] client_context the client context data, if set
210
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
211
+ #
212
+ # @yieldparam [GetAndTouch] self
213
+ def initialize(transcoder: JsonTranscoder.new,
214
+ timeout: nil,
215
+ retry_strategy: nil,
216
+ client_context: nil,
217
+ parent_span: nil)
218
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
219
+ @transcoder = transcoder
220
+ yield self if block_given?
221
+ end
222
+
223
+ # @api private
224
+ def to_backend
225
+ {
226
+ timeout: Utils::Time.extract_duration(@timeout),
227
+ }
228
+ end
229
+
230
+ # @api private
231
+ DEFAULT = GetAndTouch.new.freeze
232
+ end
233
+
234
+ # Options for {Collection#get_all_replicas}
235
+ class GetAllReplicas < Base
236
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String, Integer)]
237
+
238
+ # Creates an instance of options for {Collection#get_all_replicas}
239
+ #
240
+ # @param [JsonTranscoder, #decode(String, Integer)] transcoder used for decoding
241
+ #
242
+ # @param [Integer, #in_milliseconds, nil] timeout
243
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
244
+ # @param [Hash, nil] client_context the client context data, if set
245
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
246
+ #
247
+ # @yieldparam [GetAllReplicas] self
248
+ def initialize(transcoder: JsonTranscoder.new,
249
+ timeout: nil,
250
+ retry_strategy: nil,
251
+ client_context: nil,
252
+ parent_span: nil)
253
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
254
+ @transcoder = transcoder
255
+ yield self if block_given?
256
+ end
257
+
258
+ # @api private
259
+ def to_backend
260
+ {
261
+ timeout: Utils::Time.extract_duration(@timeout),
262
+ }
263
+ end
264
+
265
+ # @api private
266
+ DEFAULT = GetAllReplicas.new.freeze
267
+ end
268
+
269
+ # Options for {Collection#get_any_replica}
270
+ class GetAnyReplica < Base
271
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String, Integer)]
272
+
273
+ # Creates an instance of options for {Collection#get_any_replica}
274
+ #
275
+ # @param [JsonTranscoder, #decode(String, Integer)] transcoder used for decoding
276
+ #
277
+ # @param [Integer, #in_milliseconds, nil] timeout
278
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
279
+ # @param [Hash, nil] client_context the client context data, if set
280
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
281
+ #
282
+ # @yieldparam [GetAnyReplica] self
283
+ def initialize(transcoder: JsonTranscoder.new,
284
+ timeout: nil,
285
+ retry_strategy: nil,
286
+ client_context: nil,
287
+ parent_span: nil)
288
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
289
+ @transcoder = transcoder
290
+ yield self if block_given?
291
+ end
292
+
293
+ # @api private
294
+ def to_backend
295
+ {
296
+ timeout: Utils::Time.extract_duration(@timeout),
297
+ }
298
+ end
299
+
300
+ # @api private
301
+ DEFAULT = GetAnyReplica.new.freeze
302
+ end
303
+
304
+ # Options for {Collection#exists}
305
+ class Exists < Base
306
+ # Creates an instance of options for {Collection#exists}
307
+ #
308
+ # @param [Integer, #in_milliseconds, nil] timeout
309
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
310
+ # @param [Hash, nil] client_context the client context data, if set
311
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
312
+ #
313
+ # @yieldparam [Exists self
314
+ def initialize(timeout: nil,
315
+ retry_strategy: nil,
316
+ client_context: nil,
317
+ parent_span: nil)
318
+ super
319
+ yield self if block_given?
320
+ end
321
+
322
+ # @api private
323
+ def to_backend
324
+ {
325
+ timeout: Utils::Time.extract_duration(@timeout),
326
+ }
327
+ end
328
+
329
+ # @api private
330
+ DEFAULT = Exists.new.freeze
331
+ end
332
+
333
+ # Options for {Collection#touch}
334
+ class Touch < Base
335
+ # Creates an instance of options for {Collection#touch}
336
+ #
337
+ # @param [Integer, #in_milliseconds, nil] timeout
338
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
339
+ # @param [Hash, nil] client_context the client context data, if set
340
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
341
+ #
342
+ # @yieldparam [TouchOptions] self
343
+ def initialize(timeout: nil,
344
+ retry_strategy: nil,
345
+ client_context: nil,
346
+ parent_span: nil)
347
+ super
348
+ yield self if block_given?
349
+ end
350
+
351
+ # @api private
352
+ def to_backend
353
+ {
354
+ timeout: Utils::Time.extract_duration(@timeout),
355
+ }
356
+ end
357
+
358
+ # @api private
359
+ DEFAULT = Touch.new.freeze
360
+ end
361
+
362
+ # Options for {Collection#unlock}
363
+ class Unlock < Base
364
+ # Creates an instance of options for {Collection#unlock}
365
+ #
366
+ # @param [Integer, #in_milliseconds, nil] timeout
367
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
368
+ # @param [Hash, nil] client_context the client context data, if set
369
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
370
+ #
371
+ # @yieldparam [Unlock] self
372
+ def initialize(timeout: nil,
373
+ retry_strategy: nil,
374
+ client_context: nil,
375
+ parent_span: nil)
376
+ super
377
+ yield self if block_given?
378
+ end
379
+
380
+ # @api private
381
+ def to_backend
382
+ {
383
+ timeout: Utils::Time.extract_duration(@timeout),
384
+ }
385
+ end
386
+
387
+ # @api private
388
+ DEFAULT = Unlock.new.freeze
389
+ end
390
+
391
+ # Options for {Collection#remove}
392
+ class Remove < Base
393
+ attr_accessor :cas # @return [Integer, nil]
394
+ attr_accessor :durability_level # @return [Symbol]
395
+
396
+ # Creates an instance of options for {Collection#remove}
397
+ #
398
+ # @param [Integer, nil] cas CAS value for optimistic locking
399
+ # @param [Symbol] durability_level level of durability
400
+ # +:none+::
401
+ # no enhanced durability required for the mutation
402
+ # +:majority+::
403
+ # the mutation must be replicated to a majority of the Data Service nodes
404
+ # (that is, held in the memory allocated to the bucket)
405
+ # +:majority_and_persist_to_active+::
406
+ # The mutation must be replicated to a majority of the Data Service nodes.
407
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
408
+ # node hosting the active partition (vBucket) for the data.
409
+ # +:persist_to_majority+::
410
+ # The mutation must be persisted to a majority of the Data Service nodes.
411
+ # Accordingly, it will be written to disk on those nodes.
412
+ # @param [Symbol] replicate_to number of nodes to replicate
413
+ # +:none+:: do not apply any replication requirements.
414
+ # +:one+:: wait for replication to at least one node.
415
+ # +:two+:: wait for replication to at least two nodes.
416
+ # +:three+:: wait for replication to at least three nodes.
417
+ # @param [Symbol] persist_to number of nodes to persist
418
+ # +:none+:: do not apply any persistence requirements.
419
+ # +:active+:: wait for persistence to active node
420
+ # +:one+:: wait for persistence to at least one node.
421
+ # +:two+:: wait for persistence to at least two nodes.
422
+ # +:three+:: wait for persistence to at least three nodes.
423
+ # +:four+:: wait for persistence to four nodes (active and replicas).
424
+ #
425
+ # @param [Integer, #in_milliseconds, nil] timeout
426
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
427
+ # @param [Hash, nil] client_context the client context data, if set
428
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
429
+ #
430
+ # @yieldparam [Remove]
431
+ def initialize(cas: nil,
432
+ durability_level: :none,
433
+ replicate_to: :none,
434
+ persist_to: :none,
435
+ timeout: nil,
436
+ retry_strategy: nil,
437
+ client_context: nil,
438
+ parent_span: nil)
439
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
440
+ @cas = cas
441
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
442
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
443
+ end
444
+
445
+ @persist_to = persist_to
446
+ @replicate_to = replicate_to
447
+ @durability_level = durability_level
448
+ yield self if block_given?
449
+ end
450
+
451
+ # @api private
452
+ def to_backend
453
+ {
454
+ timeout: Utils::Time.extract_duration(@timeout),
455
+ durability_level: @durability_level,
456
+ persist_to: @persist_to,
457
+ replicate_to: @replicate_to,
458
+ cas: @cas,
459
+ }
460
+ end
461
+
462
+ # @api private
463
+ DEFAULT = Remove.new.freeze
464
+ end
465
+
466
+ # Options for {Collection#remove_multi}
467
+ class RemoveMulti < Base
468
+ attr_accessor :durability_level # @return [Symbol]
469
+
470
+ # Creates an instance of options for {Collection#remove}
471
+ #
472
+ # @param [Symbol] durability_level level of durability
473
+ # +:none+::
474
+ # no enhanced durability required for the mutation
475
+ # +:majority+::
476
+ # the mutation must be replicated to a majority of the Data Service nodes
477
+ # (that is, held in the memory allocated to the bucket)
478
+ # +:majority_and_persist_to_active+::
479
+ # The mutation must be replicated to a majority of the Data Service nodes.
480
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
481
+ # node hosting the active partition (vBucket) for the data.
482
+ # +:persist_to_majority+::
483
+ # The mutation must be persisted to a majority of the Data Service nodes.
484
+ # Accordingly, it will be written to disk on those nodes.
485
+ # @param [Symbol] replicate_to number of nodes to replicate
486
+ # +:none+:: do not apply any replication requirements.
487
+ # +:one+:: wait for replication to at least one node.
488
+ # +:two+:: wait for replication to at least two nodes.
489
+ # +:three+:: wait for replication to at least three nodes.
490
+ # @param [Symbol] persist_to number of nodes to persist
491
+ # +:none+:: do not apply any persistence requirements.
492
+ # +:active+:: wait for persistence to active node
493
+ # +:one+:: wait for persistence to at least one node.
494
+ # +:two+:: wait for persistence to at least two nodes.
495
+ # +:three+:: wait for persistence to at least three nodes.
496
+ # +:four+:: wait for persistence to four nodes (active and replicas).
497
+ #
498
+ # @param [Integer, #in_milliseconds, nil] timeout
499
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
500
+ # @param [Hash, nil] client_context the client context data, if set
501
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
502
+ #
503
+ # @yieldparam [Remove]
504
+ def initialize(durability_level: :none,
505
+ replicate_to: :none,
506
+ persist_to: :none,
507
+ timeout: nil,
508
+ retry_strategy: nil,
509
+ client_context: nil,
510
+ parent_span: nil)
511
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
512
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
513
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
514
+ end
515
+
516
+ @persist_to = persist_to
517
+ @replicate_to = replicate_to
518
+ @durability_level = durability_level
519
+ yield self if block_given?
520
+ end
521
+
522
+ # @api private
523
+ def to_backend
524
+ {
525
+ timeout: Utils::Time.extract_duration(@timeout),
526
+ durability_level: @durability_level,
527
+ persist_to: @persist_to,
528
+ replicate_to: @replicate_to,
529
+ }
530
+ end
531
+
532
+ # @api private
533
+ DEFAULT = RemoveMulti.new.freeze
534
+ end
535
+
536
+ # Options for {Collection#insert}
537
+ class Insert < Base
538
+ attr_accessor :expiry # @return [Integer, #in_seconds, nil]
539
+ attr_accessor :transcoder # @return [JsonTranscoder, #encode(Object)]
540
+ attr_accessor :durability_level # @return [Symbol]
541
+
542
+ # Creates an instance of options for {Collection#insert}
543
+ #
544
+ # @param [Integer, #in_seconds, Time, nil] expiry expiration time to associate with the document
545
+ # @param [JsonTranscoder, #encode(Object)] transcoder used for encoding
546
+ # @param [Symbol] durability_level level of durability
547
+ # +:none+::
548
+ # no enhanced durability required for the mutation
549
+ # +:majority+::
550
+ # the mutation must be replicated to a majority of the Data Service nodes
551
+ # (that is, held in the memory allocated to the bucket)
552
+ # +:majority_and_persist_to_active+::
553
+ # The mutation must be replicated to a majority of the Data Service nodes.
554
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
555
+ # node hosting the active partition (vBucket) for the data.
556
+ # +:persist_to_majority+::
557
+ # The mutation must be persisted to a majority of the Data Service nodes.
558
+ # Accordingly, it will be written to disk on those nodes.
559
+ # @param [Symbol] replicate_to number of nodes to replicate
560
+ # +:none+:: do not apply any replication requirements.
561
+ # +:one+:: wait for replication to at least one node.
562
+ # +:two+:: wait for replication to at least two nodes.
563
+ # +:three+:: wait for replication to at least three nodes.
564
+ # @param [Symbol] persist_to number of nodes to persist
565
+ # +:none+:: do not apply any persistence requirements.
566
+ # +:active+:: wait for persistence to active node
567
+ # +:one+:: wait for persistence to at least one node.
568
+ # +:two+:: wait for persistence to at least two nodes.
569
+ # +:three+:: wait for persistence to at least three nodes.
570
+ # +:four+:: wait for persistence to four nodes (active and replicas).
571
+ #
572
+ # @param [Integer, #in_milliseconds, nil] timeout
573
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
574
+ # @param [Hash, nil] client_context the client context data, if set
575
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
576
+ #
577
+ # @yieldparam [Insert]
578
+ def initialize(expiry: nil,
579
+ transcoder: JsonTranscoder.new,
580
+ durability_level: :none,
581
+ replicate_to: :none,
582
+ persist_to: :none,
583
+ timeout: nil,
584
+ retry_strategy: nil,
585
+ client_context: nil,
586
+ parent_span: nil)
587
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
588
+ @expiry = Utils::Time.extract_expiry_time(expiry)
589
+ @transcoder = transcoder
590
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
591
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
592
+ end
593
+
594
+ @persist_to = persist_to
595
+ @replicate_to = replicate_to
596
+ @durability_level = durability_level
597
+ yield self if block_given?
598
+ end
599
+
600
+ # @api private
601
+ def to_backend
602
+ {
603
+ timeout: Utils::Time.extract_duration(@timeout),
604
+ expiry: @expiry,
605
+ durability_level: @durability_level,
606
+ persist_to: @persist_to,
607
+ replicate_to: @replicate_to,
608
+ }
609
+ end
610
+
611
+ # @api private
612
+ DEFAULT = Insert.new.freeze
613
+ end
614
+
615
+ # Options for {Collection#upsert}
616
+ class Upsert < Base
617
+ attr_accessor :expiry # @return [Integer, #in_seconds, nil]
618
+ attr_accessor :transcoder # @return [JsonTranscoder, #encode(Object)]
619
+ attr_accessor :durability_level # @return [Symbol]
620
+ attr_accessor :preserve_expiry # @return [Boolean]
621
+
622
+ # Creates an instance of options for {Collection#upsert}
623
+ #
624
+ # @param [Integer, #in_seconds, Time, nil] expiry expiration time to associate with the document
625
+ # @param [Boolean] preserve_expiry if true and the document exists, the server will preserve current expiration
626
+ # for the document, otherwise will use {expiry} from the operation.
627
+ # @param [JsonTranscoder, #encode(Object)] transcoder used for encoding
628
+ # @param [Symbol] durability_level level of durability
629
+ # +:none+::
630
+ # no enhanced durability required for the mutation
631
+ # +:majority+::
632
+ # the mutation must be replicated to a majority of the Data Service nodes
633
+ # (that is, held in the memory allocated to the bucket)
634
+ # +:majority_and_persist_to_active+::
635
+ # The mutation must be replicated to a majority of the Data Service nodes.
636
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
637
+ # node hosting the active partition (vBucket) for the data.
638
+ # +:persist_to_majority+::
639
+ # The mutation must be persisted to a majority of the Data Service nodes.
640
+ # Accordingly, it will be written to disk on those nodes.
641
+ # @param [Symbol] replicate_to number of nodes to replicate
642
+ # +:none+:: do not apply any replication requirements.
643
+ # +:one+:: wait for replication to at least one node.
644
+ # +:two+:: wait for replication to at least two nodes.
645
+ # +:three+:: wait for replication to at least three nodes.
646
+ # @param [Symbol] persist_to number of nodes to persist
647
+ # +:none+:: do not apply any persistence requirements.
648
+ # +:active+:: wait for persistence to active node
649
+ # +:one+:: wait for persistence to at least one node.
650
+ # +:two+:: wait for persistence to at least two nodes.
651
+ # +:three+:: wait for persistence to at least three nodes.
652
+ # +:four+:: wait for persistence to four nodes (active and replicas).
653
+ #
654
+ # @param [Integer, #in_milliseconds, nil] timeout
655
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
656
+ # @param [Hash, nil] client_context the client context data, if set
657
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
658
+ #
659
+ # @yieldparam [Upsert]
660
+ def initialize(expiry: nil,
661
+ preserve_expiry: false,
662
+ transcoder: JsonTranscoder.new,
663
+ durability_level: :none,
664
+ replicate_to: :none,
665
+ persist_to: :none,
666
+ timeout: nil,
667
+ retry_strategy: nil,
668
+ client_context: nil,
669
+ parent_span: nil)
670
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
671
+ @expiry = Utils::Time.extract_expiry_time(expiry)
672
+ @preserve_expiry = preserve_expiry
673
+ @transcoder = transcoder
674
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
675
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
676
+ end
677
+
678
+ @persist_to = persist_to
679
+ @replicate_to = replicate_to
680
+ @durability_level = durability_level
681
+ yield self if block_given?
682
+ end
683
+
684
+ def to_backend
685
+ {
686
+ timeout: Utils::Time.extract_duration(@timeout),
687
+ expiry: @expiry,
688
+ preserve_expiry: @preserve_expiry,
689
+ durability_level: @durability_level,
690
+ persist_to: @persist_to,
691
+ replicate_to: @replicate_to,
692
+ }
693
+ end
694
+
695
+ # @api private
696
+ DEFAULT = Upsert.new.freeze
697
+ end
698
+
699
+ # Options for {Collection#upsert_multi}
700
+ class UpsertMulti < Base
701
+ attr_accessor :expiry # @return [Integer, #in_seconds, nil]
702
+ attr_accessor :transcoder # @return [JsonTranscoder, #encode(Object)]
703
+ attr_accessor :durability_level # @return [Symbol]
704
+ attr_accessor :preserve_expiry # @return [Boolean]
705
+
706
+ # Creates an instance of options for {Collection#upsert}
707
+ #
708
+ # @param [Integer, #in_seconds, Time, nil] expiry expiration time to associate with the document
709
+ # @param [Boolean] preserve_expiry if true and the document exists, the server will preserve current expiration
710
+ # for the document, otherwise will use {expiry} from the operation.
711
+ # @param [JsonTranscoder, #encode(Object)] transcoder used for encoding
712
+ # @param [Symbol] durability_level level of durability
713
+ # +:none+::
714
+ # no enhanced durability required for the mutation
715
+ # +:majority+::
716
+ # the mutation must be replicated to a majority of the Data Service nodes
717
+ # (that is, held in the memory allocated to the bucket)
718
+ # +:majority_and_persist_to_active+::
719
+ # The mutation must be replicated to a majority of the Data Service nodes.
720
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
721
+ # node hosting the active partition (vBucket) for the data.
722
+ # +:persist_to_majority+::
723
+ # The mutation must be persisted to a majority of the Data Service nodes.
724
+ # Accordingly, it will be written to disk on those nodes.
725
+ # @param [Symbol] replicate_to number of nodes to replicate
726
+ # +:none+:: do not apply any replication requirements.
727
+ # +:one+:: wait for replication to at least one node.
728
+ # +:two+:: wait for replication to at least two nodes.
729
+ # +:three+:: wait for replication to at least three nodes.
730
+ # @param [Symbol] persist_to number of nodes to persist
731
+ # +:none+:: do not apply any persistence requirements.
732
+ # +:active+:: wait for persistence to active node
733
+ # +:one+:: wait for persistence to at least one node.
734
+ # +:two+:: wait for persistence to at least two nodes.
735
+ # +:three+:: wait for persistence to at least three nodes.
736
+ # +:four+:: wait for persistence to four nodes (active and replicas).
737
+ #
738
+ # @param [Integer, #in_milliseconds, nil] timeout
739
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
740
+ # @param [Hash, nil] client_context the client context data, if set
741
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
742
+ #
743
+ # @yieldparam [Upsert]
744
+ def initialize(expiry: nil,
745
+ preserve_expiry: false,
746
+ transcoder: JsonTranscoder.new,
747
+ durability_level: :none,
748
+ replicate_to: :none,
749
+ persist_to: :none,
750
+ timeout: nil,
751
+ retry_strategy: nil,
752
+ client_context: nil,
753
+ parent_span: nil)
754
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
755
+ @expiry = Utils::Time.extract_expiry_time(expiry)
756
+ @preserve_expiry = preserve_expiry
757
+ @transcoder = transcoder
758
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
759
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
760
+ end
761
+
762
+ @persist_to = persist_to
763
+ @replicate_to = replicate_to
764
+ @durability_level = durability_level
765
+ yield self if block_given?
766
+ end
767
+
768
+ def to_backend
769
+ {
770
+ timeout: Utils::Time.extract_duration(@timeout),
771
+ expiry: @expiry,
772
+ preserve_expiry: @preserve_expiry,
773
+ durability_level: @durability_level,
774
+ persist_to: @persist_to,
775
+ replicate_to: @replicate_to,
776
+ }
777
+ end
778
+
779
+ # @api private
780
+ DEFAULT = UpsertMulti.new.freeze
781
+ end
782
+
783
+ # Options for {Collection#replace}
784
+ class Replace < Base
785
+ attr_accessor :expiry # @return [Integer, #in_seconds, nil]
786
+ attr_accessor :transcoder # @return [JsonTranscoder, #encode(Object)]
787
+ attr_accessor :cas # @return [Integer, nil]
788
+ attr_accessor :durability_level # @return [Symbol]
789
+ attr_accessor :preserve_expiry # @return [Boolean]
790
+
791
+ # Creates an instance of options for {Collection#replace}
792
+ #
793
+ # @param [Integer, #in_seconds, nil] expiry expiration time to associate with the document
794
+ # @param [Boolean] preserve_expiry if true and the document exists, the server will preserve current expiration
795
+ # for the document, otherwise will use {expiry} from the operation.
796
+ # @param [JsonTranscoder, #encode(Object)] transcoder used for encoding
797
+ # @param [Integer, nil] cas a CAS value that will be taken into account on the server side for optimistic concurrency
798
+ # @param [Symbol] durability_level level of durability
799
+ # +:none+::
800
+ # no enhanced durability required for the mutation
801
+ # +:majority+::
802
+ # the mutation must be replicated to a majority of the Data Service nodes
803
+ # (that is, held in the memory allocated to the bucket)
804
+ # +:majority_and_persist_to_active+::
805
+ # The mutation must be replicated to a majority of the Data Service nodes.
806
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
807
+ # node hosting the active partition (vBucket) for the data.
808
+ # +:persist_to_majority+::
809
+ # The mutation must be persisted to a majority of the Data Service nodes.
810
+ # Accordingly, it will be written to disk on those nodes.
811
+ # @param [Symbol] replicate_to number of nodes to replicate
812
+ # +:none+:: do not apply any replication requirements.
813
+ # +:one+:: wait for replication to at least one node.
814
+ # +:two+:: wait for replication to at least two nodes.
815
+ # +:three+:: wait for replication to at least three nodes.
816
+ # @param [Symbol] persist_to number of nodes to persist
817
+ # +:none+:: do not apply any persistence requirements.
818
+ # +:active+:: wait for persistence to active node
819
+ # +:one+:: wait for persistence to at least one node.
820
+ # +:two+:: wait for persistence to at least two nodes.
821
+ # +:three+:: wait for persistence to at least three nodes.
822
+ # +:four+:: wait for persistence to four nodes (active and replicas).
823
+ #
824
+ # @param [Integer, #in_milliseconds, nil] timeout
825
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
826
+ # @param [Hash, nil] client_context the client context data, if set
827
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
828
+ #
829
+ # @yieldparam [Replace]
830
+ def initialize(expiry: nil,
831
+ preserve_expiry: false,
832
+ transcoder: JsonTranscoder.new,
833
+ cas: nil,
834
+ durability_level: :none,
835
+ replicate_to: :none,
836
+ persist_to: :none,
837
+ timeout: nil,
838
+ retry_strategy: nil,
839
+ client_context: nil,
840
+ parent_span: nil)
841
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
842
+ @expiry = Utils::Time.extract_expiry_time(expiry)
843
+ @preserve_expiry = preserve_expiry
844
+ @transcoder = transcoder
845
+ @cas = cas
846
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
847
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
848
+ end
849
+
850
+ @persist_to = persist_to
851
+ @replicate_to = replicate_to
852
+ @durability_level = durability_level
853
+ yield self if block_given?
854
+ end
855
+
856
+ def to_backend
857
+ {
858
+ timeout: Utils::Time.extract_duration(@timeout),
859
+ expiry: @expiry,
860
+ preserve_expiry: @preserve_expiry,
861
+ durability_level: @durability_level,
862
+ persist_to: @persist_to,
863
+ replicate_to: @replicate_to,
864
+ cas: @cas,
865
+ }
866
+ end
867
+
868
+ # @api private
869
+ DEFAULT = Replace.new.freeze
870
+ end
871
+
872
+ # Options for {Collection#mutate_in}
873
+ class MutateIn < Base
874
+ attr_accessor :expiry # @return [Integer, #in_seconds, nil]
875
+ attr_accessor :store_semantics # @return [Symbol]
876
+ attr_accessor :cas # @return [Integer, nil]
877
+ attr_accessor :durability_level # @return [Symbol]
878
+ attr_accessor :transcoder # @return [JsonTranscoder, #encode(Object)]
879
+ attr_accessor :preserve_expiry # @return [Boolean]
880
+
881
+ # Creates an instance of options for {Collection#mutate_in}
882
+ #
883
+ # @param [Integer, #in_seconds, Time, nil] expiry expiration time to associate with the document
884
+ # @param [Boolean] preserve_expiry if true and the document exists, the server will preserve current expiration
885
+ # for the document, otherwise will use {expiry} from the operation.
886
+ # @param [Symbol] store_semantics describes how the outer document store semantics on subdoc should act
887
+ # +:replace+:: replace the document, fail if it does not exist. This is the default
888
+ # +:upsert+:: replace the document or create if it does not exist
889
+ # +:insert+:: create the document, fail if it exists
890
+ # @param [Integer, nil] cas a CAS value that will be taken into account on the server side for optimistic concurrency
891
+ # @param [Boolean] access_deleted for internal use only: allows access to deleted documents that are in "tombstone" form
892
+ # @param [Boolean] create_as_deleted for internal use only: allows creating documents in "tombstone" form
893
+ # @param [Symbol] durability_level level of durability
894
+ # +:none+::
895
+ # no enhanced durability required for the mutation
896
+ # +:majority+::
897
+ # the mutation must be replicated to a majority of the Data Service nodes
898
+ # (that is, held in the memory allocated to the bucket)
899
+ # +:majority_and_persist_to_active+::
900
+ # The mutation must be replicated to a majority of the Data Service nodes.
901
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
902
+ # node hosting the active partition (vBucket) for the data.
903
+ # +:persist_to_majority+::
904
+ # The mutation must be persisted to a majority of the Data Service nodes.
905
+ # Accordingly, it will be written to disk on those nodes.
906
+ # @param [Symbol] replicate_to number of nodes to replicate
907
+ # +:none+:: do not apply any replication requirements.
908
+ # +:one+:: wait for replication to at least one node.
909
+ # +:two+:: wait for replication to at least two nodes.
910
+ # +:three+:: wait for replication to at least three nodes.
911
+ # @param [Symbol] persist_to number of nodes to persist
912
+ # +:none+:: do not apply any persistence requirements.
913
+ # +:active+:: wait for persistence to active node
914
+ # +:one+:: wait for persistence to at least one node.
915
+ # +:two+:: wait for persistence to at least two nodes.
916
+ # +:three+:: wait for persistence to at least three nodes.
917
+ # +:four+:: wait for persistence to four nodes (active and replicas).
918
+ # @param [JsonTranscoder, #encode(Object)] transcoder used for encoding
919
+ #
920
+ # @param [Integer, #in_milliseconds, nil] timeout
921
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
922
+ # @param [Hash, nil] client_context the client context data, if set
923
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
924
+ #
925
+ # @yieldparam [MutateIn]
926
+ def initialize(expiry: nil,
927
+ preserve_expiry: false,
928
+ store_semantics: :replace,
929
+ cas: nil,
930
+ access_deleted: false,
931
+ create_as_deleted: false,
932
+ durability_level: :none,
933
+ replicate_to: :none,
934
+ persist_to: :none,
935
+ transcoder: JsonTranscoder.new,
936
+ timeout: nil,
937
+ retry_strategy: nil,
938
+ client_context: nil,
939
+ parent_span: nil)
940
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
941
+ @expiry = Utils::Time.extract_expiry_time(expiry)
942
+ @preserve_expiry = preserve_expiry
943
+ @store_semantics = store_semantics
944
+ @cas = cas
945
+ @access_deleted = access_deleted
946
+ @create_as_deleted = create_as_deleted
947
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
948
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
949
+ end
950
+
951
+ @persist_to = persist_to
952
+ @replicate_to = replicate_to
953
+ @durability_level = durability_level
954
+ @transcoder = transcoder
955
+ yield self if block_given?
956
+ end
957
+
958
+ # @api private
959
+ def to_backend
960
+ {
961
+ timeout: Utils::Time.extract_duration(@timeout),
962
+ expiry: @expiry,
963
+ preserve_expiry: @preserve_expiry,
964
+ durability_level: @durability_level,
965
+ persist_to: @persist_to,
966
+ replicate_to: @replicate_to,
967
+ cas: @cas,
968
+ store_semantics: @store_semantics,
969
+ access_deleted: @access_deleted,
970
+ create_as_deleted: @create_as_deleted,
971
+ }
972
+ end
973
+
974
+ # @api private
975
+ # @return [Boolean]
976
+ attr_accessor :access_deleted
977
+
978
+ # @api private
979
+ # @return [Boolean]
980
+ attr_accessor :create_as_deleted
981
+
982
+ # @api private
983
+ DEFAULT = MutateIn.new.freeze
984
+ end
985
+
986
+ # Options for {Collection#lookup_in}
987
+ class LookupIn < Base
988
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
989
+
990
+ # Creates an instance of options for {Collection#lookup_in}
991
+ #
992
+ # @param [Boolean] access_deleted for internal use only: allows access to deleted documents that are in "tombstone" form
993
+ # @param [JsonTranscoder, #decode(String)] transcoder used for encoding
994
+ #
995
+ # @param [Integer, #in_milliseconds, nil] timeout
996
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
997
+ # @param [Hash, nil] client_context the client context data, if set
998
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
999
+ #
1000
+ # @yieldparam [LookupIn] self
1001
+ def initialize(access_deleted: false,
1002
+ transcoder: JsonTranscoder.new,
1003
+ timeout: nil,
1004
+ retry_strategy: nil,
1005
+ client_context: nil,
1006
+ parent_span: nil)
1007
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1008
+ @access_deleted = access_deleted
1009
+ @transcoder = transcoder
1010
+ yield self if block_given?
1011
+ end
1012
+
1013
+ # @api private
1014
+ def to_backend
1015
+ {
1016
+ timeout: Utils::Time.extract_duration(@timeout),
1017
+ access_deleted: @access_deleted,
1018
+ }
1019
+ end
1020
+
1021
+ # @api private
1022
+ # @return [Boolean]
1023
+ attr_accessor :access_deleted
1024
+
1025
+ # @api private
1026
+ DEFAULT = LookupIn.new.freeze
1027
+ end
1028
+
1029
+ # Options for {BinaryCollection#append}
1030
+ class Append < Base
1031
+ attr_accessor :cas # @return [Integer]
1032
+
1033
+ # Creates an instance of options for {BinaryCollection#append}
1034
+ #
1035
+ # @param [Integer] cas The default CAS used (0 means no CAS in this context)
1036
+ #
1037
+ # @param [Integer, #in_milliseconds, nil] timeout
1038
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1039
+ # @param [Hash, nil] client_context the client context data, if set
1040
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1041
+ #
1042
+ # @yieldparam [Append] self
1043
+ def initialize(cas: nil,
1044
+ timeout: nil,
1045
+ retry_strategy: nil,
1046
+ client_context: nil,
1047
+ parent_span: nil)
1048
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1049
+ @cas = cas
1050
+ yield self if block_given?
1051
+ end
1052
+
1053
+ # @api private
1054
+ def to_backend
1055
+ {
1056
+ timeout: Utils::Time.extract_duration(@timeout),
1057
+ cas: @cas,
1058
+ }
1059
+ end
1060
+
1061
+ # @api private
1062
+ DEFAULT = Append.new.freeze
1063
+ end
1064
+
1065
+ # Options for {BinaryCollection#prepend}
1066
+ class Prepend < Base
1067
+ # @return [Integer] The default CAS used (0 means no CAS in this context)
1068
+ attr_accessor :cas
1069
+
1070
+ # Creates an instance of options for {BinaryCollection#prepend}
1071
+ #
1072
+ # @param [Integer] cas The default CAS used (0 means no CAS in this context)
1073
+ #
1074
+ # @param [Integer, #in_milliseconds, nil] timeout
1075
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1076
+ # @param [Hash, nil] client_context the client context data, if set
1077
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1078
+ #
1079
+ # @yieldparam [Prepend] self
1080
+ def initialize(cas: nil,
1081
+ timeout: nil,
1082
+ retry_strategy: nil,
1083
+ client_context: nil,
1084
+ parent_span: nil)
1085
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1086
+ @cas = cas
1087
+ yield self if block_given?
1088
+ end
1089
+
1090
+ # @api private
1091
+ def to_backend
1092
+ {
1093
+ timeout: Utils::Time.extract_duration(@timeout),
1094
+ cas: @cas,
1095
+ }
1096
+ end
1097
+
1098
+ # @api private
1099
+ DEFAULT = Prepend.new.freeze
1100
+ end
1101
+
1102
+ # Options for {BinaryCollection#increment}
1103
+ class Increment < Base
1104
+ attr_reader :delta # @return [Integer]
1105
+ attr_accessor :initial # @return [Integer]
1106
+ attr_accessor :expiry # @return [Integer, #in_seconds]
1107
+ attr_accessor :durability_level # @return [Symbol]
1108
+
1109
+ # Creates an instance of options for {BinaryCollection#increment}
1110
+ #
1111
+ # @param [Integer] delta the delta for the operation
1112
+ # @param [Integer] initial if present, holds the initial value
1113
+ # @param [Integer, #in_seconds, Time, nil] expiry if set, holds the expiration for the operation
1114
+ # @param [Symbol] durability_level level of durability
1115
+ # +:none+::
1116
+ # no enhanced durability required for the mutation
1117
+ # +:majority+::
1118
+ # the mutation must be replicated to a majority of the Data Service nodes
1119
+ # (that is, held in the memory allocated to the bucket)
1120
+ # +:majority_and_persist_to_active+::
1121
+ # The mutation must be replicated to a majority of the Data Service nodes.
1122
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
1123
+ # node hosting the active partition (vBucket) for the data.
1124
+ # +:persist_to_majority+::
1125
+ # The mutation must be persisted to a majority of the Data Service nodes.
1126
+ # Accordingly, it will be written to disk on those nodes.
1127
+ # @param [Symbol] replicate_to number of nodes to replicate
1128
+ # +:none+:: do not apply any replication requirements.
1129
+ # +:one+:: wait for replication to at least one node.
1130
+ # +:two+:: wait for replication to at least two nodes.
1131
+ # +:three+:: wait for replication to at least three nodes.
1132
+ # @param [Symbol] persist_to number of nodes to persist
1133
+ # +:none+:: do not apply any persistence requirements.
1134
+ # +:active+:: wait for persistence to active node
1135
+ # +:one+:: wait for persistence to at least one node.
1136
+ # +:two+:: wait for persistence to at least two nodes.
1137
+ # +:three+:: wait for persistence to at least three nodes.
1138
+ # +:four+:: wait for persistence to four nodes (active and replicas).
1139
+ #
1140
+ # @param [Integer, #in_milliseconds, nil] timeout
1141
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1142
+ # @param [Hash, nil] client_context the client context data, if set
1143
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1144
+ #
1145
+ # @yieldparam [Increment] self
1146
+ def initialize(delta: 1,
1147
+ initial: nil,
1148
+ expiry: nil,
1149
+ durability_level: :none,
1150
+ replicate_to: :none,
1151
+ persist_to: :none,
1152
+ timeout: nil,
1153
+ retry_strategy: nil,
1154
+ client_context: nil,
1155
+ parent_span: nil)
1156
+ raise ArgumentError, "the delta cannot be less than 0" if delta.negative?
1157
+
1158
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1159
+ @delta = delta
1160
+ @initial = initial
1161
+ @expiry = Utils::Time.extract_expiry_time(expiry)
1162
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
1163
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
1164
+ end
1165
+
1166
+ @persist_to = persist_to
1167
+ @replicate_to = replicate_to
1168
+ @durability_level = durability_level
1169
+ yield self if block_given?
1170
+ end
1171
+
1172
+ # @param [Integer] value delta for the operation
1173
+ def delta=(value)
1174
+ raise ArgumentError, "the delta cannot be less than 0" if delta.negative?
1175
+
1176
+ @delta = value
1177
+ end
1178
+
1179
+ # @api private
1180
+ def to_backend
1181
+ {
1182
+ timeout: Utils::Time.extract_duration(@timeout),
1183
+ delta: @delta,
1184
+ initial_value: @initial,
1185
+ expiry: @expiry,
1186
+ durability_level: @durability_level,
1187
+ persist_to: @persist_to,
1188
+ replicate_to: @replicate_to,
1189
+ }
1190
+ end
1191
+
1192
+ # @api private
1193
+ DEFAULT = Increment.new.freeze
1194
+ end
1195
+
1196
+ # Options for {BinaryCollection#decrement}
1197
+ class Decrement < Base
1198
+ attr_reader :delta # @return [Integer]
1199
+ attr_accessor :initial # @return [Integer]
1200
+ attr_accessor :expiry # @return [Integer, #in_seconds]
1201
+ attr_accessor :durability_level # @return [Symbol]
1202
+
1203
+ # Creates an instance of options for {BinaryCollection#decrement}
1204
+ #
1205
+ # @param [Integer] delta the delta for the operation
1206
+ # @param [Integer] initial if present, holds the initial value
1207
+ # @param [Integer, #in_seconds, Time, nil] expiry if set, holds the expiration for the operation
1208
+ # @param [Symbol] durability_level level of durability
1209
+ # +:none+::
1210
+ # no enhanced durability required for the mutation
1211
+ # +:majority+::
1212
+ # the mutation must be replicated to a majority of the Data Service nodes
1213
+ # (that is, held in the memory allocated to the bucket)
1214
+ # +:majority_and_persist_to_active+::
1215
+ # The mutation must be replicated to a majority of the Data Service nodes.
1216
+ # Additionally, it must be persisted (that is, written and synchronised to disk) on the
1217
+ # node hosting the active partition (vBucket) for the data.
1218
+ # +:persist_to_majority+::
1219
+ # The mutation must be persisted to a majority of the Data Service nodes.
1220
+ # Accordingly, it will be written to disk on those nodes.
1221
+ # @param [Symbol] replicate_to number of nodes to replicate
1222
+ # +:none+:: do not apply any replication requirements.
1223
+ # +:one+:: wait for replication to at least one node.
1224
+ # +:two+:: wait for replication to at least two nodes.
1225
+ # +:three+:: wait for replication to at least three nodes.
1226
+ # @param [Symbol] persist_to number of nodes to persist
1227
+ # +:none+:: do not apply any persistence requirements.
1228
+ # +:active+:: wait for persistence to active node
1229
+ # +:one+:: wait for persistence to at least one node.
1230
+ # +:two+:: wait for persistence to at least two nodes.
1231
+ # +:three+:: wait for persistence to at least three nodes.
1232
+ # +:four+:: wait for persistence to four nodes (active and replicas).
1233
+ #
1234
+ # @param [Integer, #in_milliseconds, nil] timeout
1235
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1236
+ # @param [Hash, nil] client_context the client context data, if set
1237
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1238
+ #
1239
+ # @yieldparam [Decrement] self
1240
+ def initialize(delta: 1,
1241
+ initial: nil,
1242
+ expiry: nil,
1243
+ durability_level: :none,
1244
+ replicate_to: :none,
1245
+ persist_to: :none,
1246
+ timeout: nil,
1247
+ retry_strategy: nil,
1248
+ client_context: nil,
1249
+ parent_span: nil)
1250
+ raise ArgumentError, "the delta cannot be less than 0" if delta.negative?
1251
+
1252
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1253
+ @delta = delta
1254
+ @initial = initial
1255
+ @expiry = Utils::Time.extract_expiry_time(expiry)
1256
+ if durability_level != :none && (replicate_to != :none || persist_to != :none)
1257
+ raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
1258
+ end
1259
+
1260
+ @persist_to = persist_to
1261
+ @replicate_to = replicate_to
1262
+ @durability_level = durability_level
1263
+ yield self if block_given?
1264
+ end
1265
+
1266
+ # @param [Integer] value delta for the operation
1267
+ def delta=(value)
1268
+ raise ArgumentError, "the delta cannot be less than 0" if delta.negative?
1269
+
1270
+ @delta = value
1271
+ end
1272
+
1273
+ # @api private
1274
+ def to_backend
1275
+ {
1276
+ timeout: Utils::Time.extract_duration(@timeout),
1277
+ delta: @delta,
1278
+ initial_value: @initial,
1279
+ expiry: @expiry,
1280
+ durability_level: @durability_level,
1281
+ persist_to: @persist_to,
1282
+ replicate_to: @replicate_to,
1283
+ }
1284
+ end
1285
+
1286
+ # @api private
1287
+ DEFAULT = Decrement.new.freeze
1288
+ end
1289
+
1290
+ # Options for {Datastructures::CouchbaseList#initialize}
1291
+ class CouchbaseList
1292
+ attr_accessor :get_options # @return [Get]
1293
+ attr_accessor :remove_options # @return [Remove]
1294
+ attr_accessor :lookup_in_options # @return [LookupIn]
1295
+ attr_accessor :mutate_in_options # @return [MutateIn]
1296
+
1297
+ # Creates an instance of options for {CouchbaseList#initialize}
1298
+ #
1299
+ # @param [Get] get_options
1300
+ # @param [Remove] remove_options
1301
+ # @param [LookupIn] lookup_in_options
1302
+ # @param [MutateIn] mutate_in_options
1303
+ #
1304
+ # @yieldparam [CouchbaseList]
1305
+ def initialize(get_options: Get.new,
1306
+ remove_options: Remove.new,
1307
+ lookup_in_options: LookupIn.new,
1308
+ mutate_in_options: MutateIn.new(store_semantics: :upsert))
1309
+ @get_options = get_options
1310
+ @remove_options = remove_options
1311
+ @lookup_in_options = lookup_in_options
1312
+ @mutate_in_options = mutate_in_options
1313
+ yield self if block_given?
1314
+ end
1315
+ end
1316
+
1317
+ # Options for {Datastructures::CouchbaseMap#initialize}
1318
+ class CouchbaseMap
1319
+ attr_accessor :get_options # @return [Get]
1320
+ attr_accessor :remove_options # @return [Remove]
1321
+ attr_accessor :lookup_in_options # @return [LookupIn]
1322
+ attr_accessor :mutate_in_options # @return [MutateIn]
1323
+
1324
+ # Creates an instance of options for {CouchbaseMap#initialize}
1325
+ #
1326
+ # @param [Get] get_options
1327
+ # @param [Remove] remove_options
1328
+ # @param [LookupIn] lookup_in_options
1329
+ # @param [MutateIn] mutate_in_options
1330
+ #
1331
+ # @yieldparam [CouchbaseMap]
1332
+ def initialize(get_options: Get.new,
1333
+ remove_options: Remove.new,
1334
+ lookup_in_options: LookupIn.new,
1335
+ mutate_in_options: MutateIn.new(store_semantics: :upsert))
1336
+ @get_options = get_options
1337
+ @remove_options = remove_options
1338
+ @lookup_in_options = lookup_in_options
1339
+ @mutate_in_options = mutate_in_options
1340
+ yield self if block_given?
1341
+ end
1342
+ end
1343
+
1344
+ # Options for {Datastructures::CouchbaseQueue#initialize}
1345
+ class CouchbaseQueue
1346
+ attr_accessor :get_options # @return [Get]
1347
+ attr_accessor :remove_options # @return [Remove]
1348
+ attr_accessor :lookup_in_options # @return [LookupIn]
1349
+ attr_accessor :mutate_in_options # @return [MutateIn]
1350
+
1351
+ # Creates an instance of options for {CouchbaseQueue#initialize}
1352
+ #
1353
+ # @param [Get] get_options
1354
+ # @param [Remove] remove_options
1355
+ # @param [LookupIn] lookup_in_options
1356
+ # @param [MutateIn] mutate_in_options
1357
+ #
1358
+ # @yieldparam [CouchbaseQueue]
1359
+ def initialize(get_options: Get.new,
1360
+ remove_options: Remove.new,
1361
+ lookup_in_options: LookupIn.new,
1362
+ mutate_in_options: MutateIn.new(store_semantics: :upsert))
1363
+ @get_options = get_options
1364
+ @remove_options = remove_options
1365
+ @lookup_in_options = lookup_in_options
1366
+ @mutate_in_options = mutate_in_options
1367
+ yield self if block_given?
1368
+ end
1369
+ end
1370
+
1371
+ # Options for {Datastructures::CouchbaseSet#initialize}
1372
+ class CouchbaseSet
1373
+ attr_accessor :get_options # @return [Get]
1374
+ attr_accessor :remove_options # @return [Remove]
1375
+ attr_accessor :lookup_in_options # @return [LookupIn]
1376
+ attr_accessor :mutate_in_options # @return [MutateIn]
1377
+
1378
+ # Creates an instance of options for {CouchbaseSet#initialize}
1379
+ #
1380
+ # @param [Get] get_options
1381
+ # @param [Remove] remove_options
1382
+ # @param [LookupIn] lookup_in_options
1383
+ # @param [MutateIn] mutate_in_options
1384
+ #
1385
+ # @yieldparam [CouchbaseSet]
1386
+ def initialize(get_options: Get.new,
1387
+ remove_options: Remove.new,
1388
+ lookup_in_options: LookupIn.new,
1389
+ mutate_in_options: MutateIn.new(store_semantics: :upsert))
1390
+ @get_options = get_options
1391
+ @remove_options = remove_options
1392
+ @lookup_in_options = lookup_in_options
1393
+ @mutate_in_options = mutate_in_options
1394
+ yield self if block_given?
1395
+ end
1396
+ end
1397
+
1398
+ # Options for {Couchbase::Cluster.connect}
1399
+ #
1400
+ # @example Pass authenticator object to Options
1401
+ # Cluster.connect("couchbase://localhost",
1402
+ # Options::Cluster(authenticator: PasswordAuthenticator.new("Administrator", "password")))
1403
+ #
1404
+ # @example Shorter version, more useful for interactive sessions
1405
+ # Cluster.connect("couchbase://localhost", "Administrator", "password")
1406
+ #
1407
+ # @example Authentication with TLS client certificate (note +couchbases://+ schema)
1408
+ # Cluster.connect("couchbases://localhost?trust_certificate=/tmp/ca.pem",
1409
+ # Options::Cluster(authenticator: CertificateAuthenticator.new("/tmp/certificate.pem", "/tmp/private.key")))
1410
+ #
1411
+ # @see https://docs.couchbase.com/server/current/manage/manage-security/configure-client-certificates.html
1412
+ #
1413
+ # @see .Cluster
1414
+ #
1415
+ class Cluster
1416
+ attr_accessor :authenticator # @return [PasswordAuthenticator, CertificateAuthenticator]
1417
+
1418
+ attr_accessor :enable_metrics # @return [Boolean]
1419
+ attr_accessor :metrics_emit_interval # @return [nil, Integer, #in_milliseconds]
1420
+ attr_accessor :enable_tracing # @return [Boolean]
1421
+ attr_accessor :orphaned_emit_interval # @return [nil, Integer, #in_milliseconds]
1422
+ attr_accessor :orphaned_sample_size # @return [nil, Integer]
1423
+ attr_accessor :threshold_emit_interval # @return [nil, Integer, #in_milliseconds]
1424
+ attr_accessor :threshold_sample_size # @return [nil, Integer]
1425
+ attr_accessor :key_value_threshold # @return [nil, Integer, #in_milliseconds]
1426
+ attr_accessor :query_threshold # @return [nil, Integer, #in_milliseconds]
1427
+ attr_accessor :view_threshold # @return [nil, Integer, #in_milliseconds]
1428
+ attr_accessor :search_threshold # @return [nil, Integer, #in_milliseconds]
1429
+ attr_accessor :analytics_threshold # @return [nil, Integer, #in_milliseconds]
1430
+ attr_accessor :management_threshold # @return [nil, Integer, #in_milliseconds]
1431
+
1432
+ attr_accessor :bootstrap_timeout # @return [nil, Integer, #in_milliseconds]
1433
+ attr_accessor :resolve_timeout # @return [nil, Integer, #in_milliseconds]
1434
+ attr_accessor :connect_timeout # @return [nil, Integer, #in_milliseconds]
1435
+ attr_accessor :key_value_timeout # @return [nil, Integer, #in_milliseconds]
1436
+ attr_accessor :view_timeout # @return [nil, Integer, #in_milliseconds]
1437
+ attr_accessor :query_timeout # @return [nil, Integer, #in_milliseconds]
1438
+ attr_accessor :analytics_timeout # @return [nil, Integer, #in_milliseconds]
1439
+ attr_accessor :search_timeout # @return [nil, Integer, #in_milliseconds]
1440
+ attr_accessor :management_timeout # @return [nil, Integer, #in_milliseconds]
1441
+ attr_accessor :dns_srv_timeout # @return [nil, Integer, #in_milliseconds]
1442
+ attr_accessor :tcp_keep_alive_interval # @return [nil, Integer, #in_milliseconds]
1443
+ attr_accessor :config_poll_interval # @return [nil, Integer, #in_milliseconds]
1444
+ attr_accessor :config_poll_floor # @return [nil, Integer, #in_milliseconds]
1445
+ attr_accessor :config_idle_redial_timeout # @return [nil, Integer, #in_milliseconds]
1446
+ attr_accessor :idle_http_connection_timeout # @return [nil, Integer, #in_milliseconds]
1447
+
1448
+ # Creates an instance of options for {Couchbase::Cluster.connect}
1449
+ #
1450
+ # @param [PasswordAuthenticator, CertificateAuthenticator] authenticator
1451
+ # @param [nil, Integer, #in_milliseconds] key_value_timeout default timeout for Key/Value operations, e.g. {Collection#get}
1452
+ # @param [nil, Integer, #in_milliseconds] view_timeout default timeout for View query
1453
+ # @param [nil, Integer, #in_milliseconds] query_timeout default timeout for N1QL query
1454
+ # @param [nil, Integer, #in_milliseconds] analytics_timeout default timeout for Analytics query
1455
+ # @param [nil, Integer, #in_milliseconds] search_timeout default timeout for Search query
1456
+ # @param [nil, Integer, #in_milliseconds] management_timeout default timeout for management operations
1457
+ #
1458
+ # @see .Cluster
1459
+ #
1460
+ # @yieldparam [Cluster] self
1461
+ def initialize(authenticator: nil,
1462
+ enable_metrics: nil,
1463
+ metrics_emit_interval: nil,
1464
+ enable_tracing: nil,
1465
+ orphaned_emit_interval: nil,
1466
+ orphaned_sample_size: nil,
1467
+ threshold_emit_interval: nil,
1468
+ threshold_sample_size: nil,
1469
+ key_value_threshold: nil,
1470
+ query_threshold: nil,
1471
+ view_threshold: nil,
1472
+ search_threshold: nil,
1473
+ analytics_threshold: nil,
1474
+ management_threshold: nil,
1475
+ bootstrap_timeout: nil,
1476
+ resolve_timeout: nil,
1477
+ connect_timeout: nil,
1478
+ key_value_timeout: nil,
1479
+ view_timeout: nil,
1480
+ query_timeout: nil,
1481
+ analytics_timeout: nil,
1482
+ search_timeout: nil,
1483
+ management_timeout: nil,
1484
+ dns_srv_timeout: nil,
1485
+ tcp_keep_alive_interval: nil,
1486
+ config_poll_interval: nil,
1487
+ config_poll_floor: nil,
1488
+ config_idle_redial_timeout: nil,
1489
+ idle_http_connection_timeout: nil)
1490
+ @authenticator = authenticator
1491
+ @enable_metrics = enable_metrics
1492
+ @metrics_emit_interval = metrics_emit_interval
1493
+ @enable_tracing = enable_tracing
1494
+ @orphaned_emit_interval = orphaned_emit_interval
1495
+ @orphaned_sample_size = orphaned_sample_size
1496
+ @threshold_emit_interval = threshold_emit_interval
1497
+ @threshold_sample_size = threshold_sample_size
1498
+ @key_value_threshold = key_value_threshold
1499
+ @query_threshold = query_threshold
1500
+ @view_threshold = view_threshold
1501
+ @search_threshold = search_threshold
1502
+ @analytics_threshold = analytics_threshold
1503
+ @management_threshold = management_threshold
1504
+ @bootstrap_timeout = bootstrap_timeout
1505
+ @resolve_timeout = resolve_timeout
1506
+ @connect_timeout = connect_timeout
1507
+ @key_value_timeout = key_value_timeout
1508
+ @view_timeout = view_timeout
1509
+ @query_timeout = query_timeout
1510
+ @analytics_timeout = analytics_timeout
1511
+ @search_timeout = search_timeout
1512
+ @management_timeout = management_timeout
1513
+ @dns_srv_timeout = dns_srv_timeout
1514
+ @tcp_keep_alive_interval = tcp_keep_alive_interval
1515
+ @config_poll_interval = config_poll_interval
1516
+ @config_poll_floor = config_poll_floor
1517
+ @config_idle_redial_timeout = config_idle_redial_timeout
1518
+ @idle_http_connection_timeout = idle_http_connection_timeout
1519
+ yield self if block_given?
1520
+ end
1521
+
1522
+ # @param [String] username
1523
+ # @param [String] password
1524
+ def authenticate(username, password)
1525
+ @authenticator = PasswordAuthenticator.new(username, password)
1526
+ end
1527
+
1528
+ # @param [String] profile_name The name of the configuration profile to apply (e.g. "wan_development")
1529
+ def apply_profile(profile_name)
1530
+ ConfigProfiles::KNOWN_PROFILES.apply(profile_name, self)
1531
+ end
1532
+
1533
+ # @api private
1534
+ def to_backend
1535
+ {
1536
+ enable_metrics: @enable_metrics,
1537
+ metrics_emit_interval: Utils::Time.extract_duration(@metrics_emit_interval),
1538
+ enable_tracing: @enable_tracing,
1539
+ orphaned_emit_interval: Utils::Time.extract_duration(@orphaned_emit_interval),
1540
+ orphaned_sample_size: @orphaned_sample_size,
1541
+ threshold_emit_interval: Utils::Time.extract_duration(@threshold_emit_interval),
1542
+ threshold_sample_size: @threshold_sample_size,
1543
+ key_value_threshold: Utils::Time.extract_duration(@key_value_threshold),
1544
+ query_threshold: Utils::Time.extract_duration(@query_threshold),
1545
+ view_threshold: Utils::Time.extract_duration(@view_threshold),
1546
+ search_threshold: Utils::Time.extract_duration(@search_threshold),
1547
+ analytics_threshold: Utils::Time.extract_duration(@analytics_threshold),
1548
+ management_threshold: Utils::Time.extract_duration(@management_threshold),
1549
+ bootstrap_timeout: Utils::Time.extract_duration(@bootstrap_timeout),
1550
+ resolve_timeout: Utils::Time.extract_duration(@resolve_timeout),
1551
+ connect_timeout: Utils::Time.extract_duration(@connect_timeout),
1552
+ key_value_timeout: Utils::Time.extract_duration(@key_value_timeout),
1553
+ view_timeout: Utils::Time.extract_duration(@view_timeout),
1554
+ query_timeout: Utils::Time.extract_duration(@query_timeout),
1555
+ analytics_timeout: Utils::Time.extract_duration(@analytics_timeout),
1556
+ search_timeout: Utils::Time.extract_duration(@search_timeout),
1557
+ management_timeout: Utils::Time.extract_duration(@management_timeout),
1558
+ dns_srv_timeout: Utils::Time.extract_duration(@dns_srv_timeout),
1559
+ tcp_keep_alive_interval: Utils::Time.extract_duration(@tcp_keep_alive_interval),
1560
+ config_poll_interval: Utils::Time.extract_duration(@config_poll_interval),
1561
+ config_poll_floor: Utils::Time.extract_duration(@config_poll_floor),
1562
+ config_idle_redial_timeout: Utils::Time.extract_duration(@config_idle_redial_timeout),
1563
+ idle_http_connection_timeout: Utils::Time.extract_duration(@idle_http_connection_timeout),
1564
+ }
1565
+ end
1566
+ end
1567
+
1568
+ # Options for {Couchbase::Cluster#diagnostics}
1569
+ class Diagnostics
1570
+ attr_accessor :report_id # @return [String]
1571
+
1572
+ # Creates an instance of options for {Couchbase::Cluster#diagnostics}
1573
+ #
1574
+ # @param [String] report_id Holds custom report ID.
1575
+ #
1576
+ # @yieldparam [Diagnostics] self
1577
+ def initialize(report_id: nil)
1578
+ @report_id = report_id
1579
+ yield self if block_given?
1580
+ end
1581
+
1582
+ # @api private
1583
+ DEFAULT = Diagnostics.new.freeze
1584
+ end
1585
+
1586
+ # Options for {Couchbase::Bucket#ping}
1587
+ class Ping
1588
+ attr_accessor :report_id # @return [String]
1589
+ attr_accessor :service_types # @return [Array<Symbol>]
1590
+ attr_accessor :timeout # @return [Integer, #in_milliseconds]
1591
+
1592
+ # Creates an instance of options for {Couchbase::Bucket#ping}
1593
+ #
1594
+ # @param [String] report_id Holds custom report id.
1595
+ # @@param [Array<Symbol>] service_types The service types to limit this diagnostics request
1596
+ # @param [Integer, #in_milliseconds] timeout
1597
+ #
1598
+ # @yieldparam [Ping] self
1599
+ def initialize(report_id: nil,
1600
+ service_types: [:kv, :query, :analytics, :search, :views, :management],
1601
+ timeout: nil)
1602
+ @report_id = report_id
1603
+ @service_types = service_types
1604
+ @timeout = timeout
1605
+ yield self if block_given?
1606
+ end
1607
+
1608
+ # @api private
1609
+ def to_backend
1610
+ {
1611
+ timeout: Utils::Time.extract_duration(@timeout),
1612
+ service_types: @service_types,
1613
+ report_id: @report_id,
1614
+ }
1615
+ end
1616
+
1617
+ # @api private
1618
+ DEFAULT = Ping.new.freeze
1619
+ end
1620
+
1621
+ # Options for {Couchbase::Cluster#analytics_query}
1622
+ class Analytics < Base
1623
+ attr_accessor :client_context_id # @return [String]
1624
+ attr_accessor :scan_consistency # @return [Symbol]
1625
+ attr_accessor :readonly # @return [Boolean]
1626
+ attr_accessor :priority # @return [Boolean]
1627
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1628
+ attr_accessor :scope_qualifier # @return [String]
1629
+
1630
+ # Creates new instance of options for {Couchbase::Cluster#analytics_query}
1631
+ #
1632
+ # @param [String] client_context_id provides a custom client context ID for this query
1633
+ # @param [Symbol] scan_consistency specifies level of consistency for the query
1634
+ # +:not_bounded+::
1635
+ # The index will return whatever state it has to the analytics query engine at the time of query.
1636
+ #
1637
+ # This is the default (for single-statement requests). No timestamp vector is used in the index scan.
1638
+ # This is also the fastest mode, because we avoid the cost of obtaining the vector, and we also avoid
1639
+ # any wait for the index
1640
+ # +:request_plus+::
1641
+ # The index will wait until all mutations have been processed at the time of request before being processed
1642
+ # in the analytics query engine.
1643
+ #
1644
+ # This implements strong consistency per request. Before processing the request, a current vector is obtained.
1645
+ # The vector is used as a lower bound for the statements in the request.
1646
+ # @param [Boolean] readonly allows explicitly marking a query as being readonly and not mutating any documents on
1647
+ # the server side.
1648
+ # @param [Boolean] priority allows to give certain requests higher priority than others
1649
+ # @param [JsonTranscoder] transcoder to decode rows
1650
+ # @param [Array<#to_json>, nil] positional_parameters parameters to be used as substitution for numbered macros
1651
+ # like +$1+, +$2+ in query string
1652
+ # @param [Hash<String => #to_json>, nil] named_parameters parameters to be used as substitution for named macros
1653
+ # like +$name+ in query string
1654
+ # @param [String, nil] scope_qualifier Associate scope qualifier (also known as +query_context+) with the query.
1655
+ # The qualifier must be in form +{bucket_name}.{scope_name}+ or +default:{bucket_name}.{scope_name}+.
1656
+ #
1657
+ # @param [Integer, #in_milliseconds, nil] timeout
1658
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1659
+ # @param [Hash, nil] client_context the client context data, if set
1660
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1661
+ #
1662
+ # @note Either +positional_parameters+ or +named_parameters+ may be specified.
1663
+ #
1664
+ # @yieldparam [Analytics] self
1665
+ def initialize(client_context_id: nil,
1666
+ scan_consistency: nil,
1667
+ readonly: false,
1668
+ priority: nil,
1669
+ transcoder: JsonTranscoder.new,
1670
+ positional_parameters: nil,
1671
+ named_parameters: nil,
1672
+ scope_qualifier: nil,
1673
+ timeout: nil,
1674
+ retry_strategy: nil,
1675
+ client_context: nil,
1676
+ parent_span: nil)
1677
+ raise ArgumentError, "Cannot pass positional and named parameters at the same time" if positional_parameters && named_parameters
1678
+
1679
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1680
+ @client_context_id = client_context_id
1681
+ @scan_consistency = scan_consistency
1682
+ @readonly = readonly
1683
+ @priority = priority
1684
+ @transcoder = transcoder
1685
+ @positional_parameters = positional_parameters
1686
+ @named_parameters = named_parameters
1687
+ @scope_qualifier = scope_qualifier
1688
+ @raw_parameters = {}
1689
+ yield self if block_given?
1690
+ end
1691
+
1692
+ # Sets positional parameters for the query
1693
+ #
1694
+ # @param [Array] positional the list of parameters that have to be substituted in the statement
1695
+ def positional_parameters(positional)
1696
+ @positional_parameters = positional
1697
+ @named_parameters = nil
1698
+ end
1699
+
1700
+ # Sets named parameters for the query
1701
+ #
1702
+ # @param [Hash] named the key/value map of the parameters to substitute in the statement
1703
+ def named_parameters(named)
1704
+ @named_parameters = named
1705
+ @positional_parameters = nil
1706
+ end
1707
+
1708
+ # Allows providing custom JSON key/value pairs for advanced usage
1709
+ #
1710
+ # @param [String] key the parameter name (key of the JSON property)
1711
+ # @param [Object] value the parameter value (value of the JSON property)
1712
+ def raw(key, value)
1713
+ @raw_parameters[key] = JSON.generate(value)
1714
+ end
1715
+
1716
+ # @api private
1717
+ def to_backend(scope_name: nil, bucket_name: nil)
1718
+ {
1719
+ timeout: Utils::Time.extract_duration(@timeout),
1720
+ client_context_id: @client_context_id,
1721
+ scan_consistency: @scan_consistency,
1722
+ readonly: @readonly,
1723
+ priority: @priority,
1724
+ positional_parameters: export_positional_parameters,
1725
+ named_parameters: export_named_parameters,
1726
+ raw_parameters: @raw_parameters,
1727
+ scope_qualifier: @scope_qualifier,
1728
+ scope_name: scope_name,
1729
+ bucket_name: bucket_name,
1730
+ }
1731
+ end
1732
+
1733
+ # @api private
1734
+ DEFAULT = Analytics.new.freeze
1735
+
1736
+ private
1737
+
1738
+ # @api private
1739
+ # @return [Array<String>, nil]
1740
+ def export_positional_parameters
1741
+ @positional_parameters&.map { |p| JSON.dump(p) }
1742
+ end
1743
+
1744
+ # @api private
1745
+ # @return [Hash<String => String>, nil]
1746
+ def export_named_parameters
1747
+ @named_parameters&.each_with_object({}) { |(n, v), o| o[n.to_s] = JSON.dump(v) }
1748
+ end
1749
+
1750
+ # @api private
1751
+ # @return [Hash<String => #to_json>]
1752
+ attr_reader :raw_parameters
1753
+ end
1754
+
1755
+ # Options for {Couchbase::Cluster#query}
1756
+ class Query < Base
1757
+ attr_accessor :adhoc # @return [Boolean]
1758
+ attr_accessor :client_context_id # @return [String]
1759
+ attr_accessor :max_parallelism # @return [Integer]
1760
+ attr_accessor :readonly # @return [Boolean]
1761
+ attr_accessor :scan_wait # @return [Integer, #in_milliseconds]
1762
+ attr_accessor :scan_cap # @return [Integer]
1763
+ attr_accessor :pipeline_batch # @return [Integer]
1764
+ attr_accessor :pipeline_cap # @return [Integer]
1765
+ attr_accessor :metrics # @return [Boolean]
1766
+ attr_accessor :profile # @return [Symbol]
1767
+ attr_accessor :flex_index # @return [Boolean]
1768
+ attr_accessor :preserve_expiry # @return [Boolean]
1769
+ attr_accessor :scope_qualifier # @return [String]
1770
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1771
+
1772
+ # Creates new instance of options for {Couchbase::Cluster#query}
1773
+ #
1774
+ # @param [Boolean] adhoc allows turning this request into a prepared statement query
1775
+ # @param [String, nil] client_context_id provides a custom client context ID for this query
1776
+ # @param [Integer, nil] max_parallelism allows overriding the default maximum parallelism for the query execution
1777
+ # on the server side.
1778
+ # @param [Boolean, nil] readonly allows explicitly marking a query as being readonly and not mutating any
1779
+ # documents on the server side.
1780
+ # @param [Integer, #in_milliseconds, nil] scan_wait The maximum duration (in milliseconds) the query engine
1781
+ # is willing to wait before failing. Allows customizing how long (in milliseconds) the query engine is willing
1782
+ # to wait until the index catches up to whatever scan consistency is asked for in this query. Note that if
1783
+ # +:not_bounded+ consistency level is used, this method doesn't do anything at all. If no value is provided to
1784
+ # this method, the server default is used.
1785
+ # @param [Integer, nil] scan_cap customize the maximum buffered channel size between the indexer and the query
1786
+ # service
1787
+ # @param [Integer, nil] pipeline_cap customize the number of items execution operators can batch for fetch
1788
+ # from the Key Value layer on the server.
1789
+ # @param [Integer, nil] pipeline_batch customize the maximum number of items each execution operator can buffer
1790
+ # between various operators on the server.
1791
+ # @param [Boolean, nil] metrics enables per-request metrics in the trailing section of the query
1792
+ # @param [Symbol] profile customize server profile level for this query
1793
+ # +:off+::
1794
+ # No profiling information is added to the query response
1795
+ # +:phases+::
1796
+ # The query response includes a profile section with stats and details about various phases of the query plan
1797
+ # and execution. Three phase times will be included in the +system:active_requests+ and
1798
+ # +system:completed_requests+ monitoring keyspaces.
1799
+ # +:timings+::
1800
+ # Besides the phase times, the profile section of the query response document will include a full query plan
1801
+ # with timing and information about the number of processed documents at each phase. This information will be
1802
+ # included in the system:active_requests and system:completed_requests keyspaces.
1803
+ # @param [Symbol, nil] scan_consistency Sets the mutation tokens this query should be consistent with. Overrides
1804
+ # +mutation_state+.
1805
+ # +:not_bounded+::
1806
+ # The indexer will return whatever state it has to the query engine at the time of query. This is the default
1807
+ # (for single-statement requests).
1808
+ # +:request_plus+::
1809
+ # The indexer will wait until all mutations have been processed at the time of request before returning to
1810
+ # the query engine.
1811
+ # @param [Boolean, nil] flex_index Tells the query engine to use a flex index (utilizing the search service)
1812
+ # @param [Boolean, nil] preserve_expiry Tells the query engine to preserve expiration values set on any documents
1813
+ # modified by this query.
1814
+ # @param [String, nil] scope_qualifier Associate scope qualifier (also known as +query_context+) with the query.
1815
+ # The qualifier must be in form +{bucket_name}.{scope_name}+ or +default:{bucket_name}.{scope_name}+.
1816
+ # @param [JsonTranscoder] transcoder to decode rows
1817
+ # @param [Array<#to_json>, nil] positional_parameters parameters to be used as substitution for numbered macros
1818
+ # like +$1+, +$2+ in query string
1819
+ # @param [Hash<String => #to_json>, nil] named_parameters parameters to be used as substitution for named macros
1820
+ # like +$name+ in query string.
1821
+ #
1822
+ # @param [MutationState, nil] mutation_state Sets the mutation tokens this query should be consistent with.
1823
+ # Overrides +scan_consistency+.
1824
+ #
1825
+ # @param [Integer, #in_milliseconds, nil] timeout
1826
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
1827
+ # @param [Hash, nil] client_context the client context data, if set
1828
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
1829
+ #
1830
+ # @note Either +positional_parameters+ or +named_parameters+ may be specified.
1831
+ #
1832
+ # @yieldparam [Query] self
1833
+ def initialize(adhoc: true,
1834
+ client_context_id: nil,
1835
+ max_parallelism: nil,
1836
+ readonly: false,
1837
+ scan_wait: nil,
1838
+ scan_cap: nil,
1839
+ pipeline_cap: nil,
1840
+ pipeline_batch: nil,
1841
+ metrics: nil,
1842
+ profile: :off,
1843
+ flex_index: nil,
1844
+ preserve_expiry: nil,
1845
+ scope_qualifier: nil,
1846
+ scan_consistency: :not_bounded,
1847
+ mutation_state: nil,
1848
+ transcoder: JsonTranscoder.new,
1849
+ positional_parameters: nil,
1850
+ named_parameters: nil,
1851
+ timeout: nil,
1852
+ retry_strategy: nil,
1853
+ client_context: nil,
1854
+ parent_span: nil)
1855
+ raise ArgumentError, "Cannot pass positional and named parameters at the same time" if positional_parameters && named_parameters
1856
+
1857
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
1858
+ @adhoc = adhoc
1859
+ @client_context_id = client_context_id
1860
+ @max_parallelism = max_parallelism
1861
+ @readonly = readonly
1862
+ @scan_wait = scan_wait
1863
+ @scan_cap = scan_cap
1864
+ @pipeline_cap = pipeline_cap
1865
+ @pipeline_batch = pipeline_batch
1866
+ @metrics = metrics
1867
+ @profile = profile
1868
+ @flex_index = flex_index
1869
+ @preserve_expiry = preserve_expiry
1870
+ @scope_qualifier = scope_qualifier
1871
+ @scan_consistency = scan_consistency
1872
+ @mutation_state = mutation_state
1873
+ @transcoder = transcoder
1874
+ @positional_parameters = positional_parameters
1875
+ @named_parameters = named_parameters
1876
+ @raw_parameters = {}
1877
+ yield self if block_given?
1878
+ end
1879
+
1880
+ # Allows providing custom JSON key/value pairs for advanced usage
1881
+ #
1882
+ # @param [String] key the parameter name (key of the JSON property)
1883
+ # @param [Object] value the parameter value (value of the JSON property)
1884
+ def raw(key, value)
1885
+ @raw_parameters[key] = JSON.generate(value)
1886
+ end
1887
+
1888
+ # Customizes the consistency guarantees for this query
1889
+ #
1890
+ # @note overrides consistency level set by {#consistent_with}
1891
+ #
1892
+ # [+:not_bounded+] The indexer will return whatever state it has to the query engine at the time of query. This is the default (for
1893
+ # single-statement requests).
1894
+ #
1895
+ # [+:request_plus+] The indexer will wait until all mutations have been processed at the time of request before returning to the query
1896
+ # engine.
1897
+ #
1898
+ # @param [:not_bounded, :request_plus] level the index scan consistency to be used for this query
1899
+ def scan_consistency=(level)
1900
+ @mutation_state = nil if @mutation_state
1901
+ @scan_consistency = level
1902
+ end
1903
+
1904
+ # Sets the mutation tokens this query should be consistent with
1905
+ #
1906
+ # @note overrides consistency level set by {#scan_consistency=}
1907
+ #
1908
+ # @param [MutationState] mutation_state the mutation state containing the mutation tokens
1909
+ def consistent_with(mutation_state)
1910
+ @scan_consistency = nil if @scan_consistency
1911
+ @mutation_state = mutation_state
1912
+ end
1913
+
1914
+ # Sets positional parameters for the query
1915
+ #
1916
+ # @param [Array] positional the list of parameters that have to be substituted in the statement
1917
+ def positional_parameters(positional)
1918
+ @positional_parameters = positional
1919
+ @named_parameters = nil
1920
+ end
1921
+
1922
+ # @api private
1923
+ # @return [Array<String>, nil]
1924
+ def export_positional_parameters
1925
+ @positional_parameters&.map { |p| JSON.dump(p) }
1926
+ end
1927
+
1928
+ # Sets named parameters for the query
1929
+ #
1930
+ # @param [Hash] named the key/value map of the parameters to substitute in the statement
1931
+ def named_parameters(named)
1932
+ @named_parameters = named
1933
+ @positional_parameters = nil
1934
+ end
1935
+
1936
+ # @api private
1937
+ # @return [Hash<String => String>, nil]
1938
+ def export_named_parameters
1939
+ @named_parameters&.each_with_object({}) { |(n, v), o| o[n.to_s] = JSON.dump(v) }
1940
+ end
1941
+
1942
+ # @api private
1943
+ # @return [MutationState]
1944
+ attr_reader :mutation_state
1945
+
1946
+ # @api private
1947
+ # @return [Hash<String => #to_json>]
1948
+ attr_reader :raw_parameters
1949
+
1950
+ # @api private
1951
+ def to_backend(scope_name: nil, bucket_name: nil)
1952
+ if scope_name && bucket_name
1953
+ default_query_context = format("default:`%<bucket>s`.`%<scope>s`", bucket: bucket_name, scope: scope_name)
1954
+ end
1955
+ {
1956
+ timeout: Utils::Time.extract_duration(@timeout),
1957
+ adhoc: @adhoc,
1958
+ client_context_id: @client_context_id,
1959
+ max_parallelism: @max_parallelism,
1960
+ readonly: @readonly,
1961
+ flex_index: @flex_index,
1962
+ preserve_expiry: @preserve_expiry,
1963
+ scan_wait: Utils::Time.extract_duration(@scan_wait),
1964
+ scan_cap: @scan_cap,
1965
+ pipeline_batch: @pipeline_batch,
1966
+ pipeline_cap: @pipeline_cap,
1967
+ metrics: @metrics,
1968
+ profile: @profile,
1969
+ positional_parameters: export_positional_parameters,
1970
+ named_parameters: export_named_parameters,
1971
+ raw_parameters: @raw_parameters,
1972
+ scan_consistency: @scan_consistency,
1973
+ mutation_state: @mutation_state&.to_a,
1974
+ query_context: @scope_qualifier || default_query_context,
1975
+ }
1976
+ end
1977
+
1978
+ # @api private
1979
+ DEFAULT = Query.new.freeze
1980
+ end
1981
+
1982
+ # Options for {Couchbase::Cluster#search_query}
1983
+ class Search < Base
1984
+ attr_accessor :limit # @return [Integer]
1985
+ attr_accessor :skip # @return [Integer]
1986
+ attr_accessor :explain # @return [Boolean]
1987
+ attr_accessor :highlight_style # @return [Symbol]
1988
+ attr_accessor :highlight_fields # @return [Array<String>]
1989
+ attr_accessor :fields # @return [Array<String>]
1990
+ attr_accessor :disable_scoring # @return [Boolean]
1991
+ attr_accessor :include_locations # @return [Boolean]
1992
+ attr_accessor :collections # @return [Array<String>, nil]
1993
+ attr_accessor :sort # @return [Array<String, Cluster::SearchSort>]
1994
+ attr_accessor :facets # @return [Hash<String => Cluster::SearchFacet>]
1995
+ attr_accessor :transcoder # @return [JsonTranscoder, #decode(String)]
1996
+
1997
+ # @param [Integer] limit limits the number of matches returned from the complete result set.
1998
+ # @param [Integer] skip indicates how many matches are skipped on the result set before starting to return the
1999
+ # matches
2000
+ # @param [Boolean] explain triggers inclusion of additional search result score explanations.
2001
+ # @param [:html, :ansi, nil] highlight_style the style of highlighting in the result excerpts (if not specified,
2002
+ # the server default will be used)
2003
+ # @param [Array<String>] highlight_fields list of the fields to highlight
2004
+ # @param [Array<String>] fields list of field values which should be retrieved for result documents, provided they
2005
+ # were stored while indexing
2006
+ # @param [MutationState] mutation_state the mutation tokens this query should be consistent with
2007
+ # @param [Boolean] disable_scoring If set to true, the server will not perform any scoring on the hits
2008
+ # @param [Boolean] include_locations UNCOMMITTED: If set to true, will include the vector of search_location in rows
2009
+ # @param [Array<String>, nil] collections list of collections by which to filter the results
2010
+ # @param [Array<String, Cluster::SearchSort>] sort Ordering rules to apply to the results. The list might contain
2011
+ # either strings or special objects, that derive from {Cluster::SearchSort}. In case of String, the value
2012
+ # represents the name of the field with optional +-+ in front of the name, which will turn on descending mode
2013
+ # for this field. One field is special is +"_score"+ which will sort results by their score. When nothing
2014
+ # specified, the Server will order results by their score descending, which is equivalent of +"-_score"+.
2015
+ # @param [Hash<String => Cluster::SearchFacet>] facets facets allow to aggregate information collected on a
2016
+ # particular result set
2017
+ # @param [JsonTranscoder, #decode(String)] transcoder to use for the results
2018
+ #
2019
+ # @param [Integer, #in_milliseconds, nil] timeout
2020
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
2021
+ # @param [Hash, nil] client_context the client context data, if set
2022
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
2023
+ #
2024
+ # @yieldparam [Search] self
2025
+ def initialize(limit: nil,
2026
+ skip: nil,
2027
+ explain: false,
2028
+ highlight_style: nil,
2029
+ highlight_fields: nil,
2030
+ fields: nil,
2031
+ mutation_state: nil,
2032
+ disable_scoring: false,
2033
+ include_locations: false,
2034
+ collections: nil,
2035
+ sort: nil,
2036
+ facets: nil,
2037
+ transcoder: JsonTranscoder.new,
2038
+ timeout: nil,
2039
+ retry_strategy: nil,
2040
+ client_context: nil,
2041
+ parent_span: nil)
2042
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
2043
+ @limit = limit
2044
+ @skip = skip
2045
+ @explain = explain
2046
+ @highlight_style = highlight_style
2047
+ @highlight_fields = highlight_fields
2048
+ @fields = fields
2049
+ @disable_scoring = disable_scoring
2050
+ @include_locations = include_locations
2051
+ @collections = collections
2052
+ @sort = sort
2053
+ @facets = facets
2054
+ @transcoder = transcoder
2055
+ @scan_consistency = :not_bounded
2056
+ @mutation_state = mutation_state
2057
+ yield self if block_given?
2058
+ end
2059
+
2060
+ # Sets the mutation tokens this query should be consistent with
2061
+ #
2062
+ # @note overrides consistency level set by {#scan_consistency=}
2063
+ #
2064
+ # @param [MutationState] mutation_state the mutation state containing the mutation tokens
2065
+ #
2066
+ # @return [void]
2067
+ def consistent_with(mutation_state)
2068
+ @scan_consistency = nil if @scan_consistency
2069
+ @mutation_state = mutation_state
2070
+ end
2071
+
2072
+ # Customizes the consistency guarantees for this query
2073
+ #
2074
+ # @note overrides consistency level set by {#consistent_with}
2075
+ #
2076
+ # @param [:not_bounded] level the scan consistency to be used for this query
2077
+ # +:not_bounded+:: The engine will return whatever state it has at the time of query
2078
+ #
2079
+ # @return [void]
2080
+ def scan_consistency=(level)
2081
+ @mutation_state = nil if @mutation_state
2082
+ @scan_consistency = level
2083
+ end
2084
+
2085
+ # @api private
2086
+ # @return [MutationState]
2087
+ attr_reader :mutation_state
2088
+
2089
+ # @api private
2090
+ # @return [Symbol
2091
+ attr_reader :scan_consistency
2092
+
2093
+ # @api private
2094
+ def to_backend(scope_name: nil)
2095
+ {
2096
+ timeout: Utils::Time.extract_duration(@timeout),
2097
+ limit: @limit,
2098
+ skip: @skip,
2099
+ explain: @explain,
2100
+ disable_scoring: @disable_scoring,
2101
+ include_locations: @include_locations,
2102
+ scope: scope_name,
2103
+ collections: scope_name ? @collections : nil,
2104
+ highlight_style: @highlight_style,
2105
+ highlight_fields: @highlight_fields,
2106
+ fields: @fields,
2107
+ sort: @sort&.map { |v| JSON.generate(v) },
2108
+ facets: @facets&.map { |(k, v)| [k, JSON.generate(v)] },
2109
+ scan_consistency: @scan_consistency,
2110
+ mutation_state: @mutation_state&.to_a,
2111
+ }
2112
+ end
2113
+
2114
+ # @api private
2115
+ DEFAULT = Search.new.freeze
2116
+ end
2117
+
2118
+ # Options for {Couchbase::Cluster#view_query}
2119
+ class View < Base
2120
+ attr_accessor :scan_consistency # @return [Symbol]
2121
+ attr_accessor :namespace # @return [Symbol]
2122
+ attr_accessor :skip # @return [Integer]
2123
+ attr_accessor :limit # @return [Integer]
2124
+ attr_accessor :start_key # @return [#to_json, nil]
2125
+ attr_accessor :end_key # @return [#to_json, nil]
2126
+ attr_accessor :start_key_doc_id # @return [String, nil]
2127
+ attr_accessor :end_key_doc_id # @return [String, nil]
2128
+ attr_accessor :inclusive_end # @return [Boolean, nil]
2129
+ attr_accessor :group # @return [Boolean, nil]
2130
+ attr_accessor :group_level # @return [Integer, nil]
2131
+ attr_accessor :key # @return [#to_json, nil]
2132
+ attr_accessor :keys # @return [Array<#to_json>, nil]
2133
+ attr_accessor :order # @return [Symbol, nil]
2134
+ attr_accessor :reduce # @return [Boolean, nil]
2135
+ attr_accessor :on_error # @return [Symbol, nil]
2136
+ attr_accessor :debug # @return [Boolean, nil]
2137
+
2138
+ # @param [:not_bounded, :request_plus, :update_after] scan_consistency Specifies the level of consistency for the query
2139
+ # @param [:production, :development] namespace
2140
+ # @param [Integer, nil] skip Specifies the number of results to skip from the start of the result set
2141
+ # @param [Integer, nil] limit Specifies the maximum number of results to return
2142
+ # @param [#to_json, nil] start_key Specifies the key, to which the engine has to skip before result generation
2143
+ # @param [#to_json, nil] end_key Specifies the key, at which the result generation has to be stopped
2144
+ # @param [String, nil] start_key_doc_id Specifies the document id in case {#start_key} gives multiple results within the index
2145
+ # @param [String, nil] end_key_doc_id Specifies the document id in case {#end_key} gives multiple results within the index
2146
+ # @param [Boolean, nil] inclusive_end Specifies whether the {#end_key}/#{#end_key_doc_id} values should be inclusive
2147
+ # @param [Boolean, nil] group Specifies whether to enable grouping of the results
2148
+ # @param [Integer, nil] group_level Specifies the depth within the key to group the results
2149
+ # @param [#to_json, nil] key Specifies the key to fetch from the index
2150
+ # @param [Array<#to_json>, nil] keys Specifies set of the keys to fetch from the index
2151
+ # @param [:ascending, :descending, nil] order Specifies the order of the results that should be returned
2152
+ # @param [Boolean, nil] reduce Specifies whether to enable the reduction function associated with this particular
2153
+ # view index
2154
+ # @param [:stop, :continue, nil] on_error Specifies the behaviour of the view engine should an error occur during
2155
+ # the gathering of view index results which would result in only partial results being available
2156
+ # @param [Boolean, nil] debug allows to return debug information as part of the view response
2157
+ #
2158
+ # @param [Integer, #in_milliseconds, nil] timeout
2159
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
2160
+ # @param [Hash, nil] client_context the client context data, if set
2161
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
2162
+ #
2163
+ # @yieldparam [View] self
2164
+ def initialize(scan_consistency: :not_bounded,
2165
+ namespace: :production,
2166
+ skip: nil,
2167
+ limit: nil,
2168
+ start_key: nil,
2169
+ end_key: nil,
2170
+ start_key_doc_id: nil,
2171
+ end_key_doc_id: nil,
2172
+ inclusive_end: nil,
2173
+ group: nil,
2174
+ group_level: nil,
2175
+ key: nil,
2176
+ keys: nil,
2177
+ order: nil,
2178
+ reduce: nil,
2179
+ on_error: nil,
2180
+ debug: false,
2181
+ timeout: nil,
2182
+ retry_strategy: nil,
2183
+ client_context: nil,
2184
+ parent_span: nil)
2185
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
2186
+
2187
+ @scan_consistency = scan_consistency
2188
+ @namespace = namespace
2189
+ @skip = skip
2190
+ @limit = limit
2191
+ @start_key = start_key
2192
+ @end_key = end_key
2193
+ @start_key_doc_id = start_key_doc_id
2194
+ @end_key_doc_id = end_key_doc_id
2195
+ @inclusive_end = inclusive_end
2196
+ @group = group
2197
+ @group_level = group_level
2198
+ @key = key
2199
+ @keys = keys
2200
+ @order = order
2201
+ @reduce = reduce
2202
+ @on_error = on_error
2203
+ @debug = debug
2204
+ yield self if block_given?
2205
+ end
2206
+
2207
+ # Allows providing custom JSON key/value pairs for advanced usage
2208
+ #
2209
+ # @param [String] key the parameter name (key of the JSON property)
2210
+ # @param [Object] value the parameter value (value of the JSON property)
2211
+ def raw(key, value)
2212
+ @raw_parameters[key] = JSON.generate(value)
2213
+ end
2214
+
2215
+ # @api private
2216
+ def to_backend
2217
+ {
2218
+ timeout: Utils::Time.extract_duration(@timeout),
2219
+ scan_consistency: @scan_consistency,
2220
+ skip: @skip,
2221
+ limit: @limit,
2222
+ start_key: (JSON.generate(@start_key) unless @start_key.nil?),
2223
+ end_key: (JSON.generate(@end_key) unless @end_key.nil?),
2224
+ start_key_doc_id: @start_key_doc_id,
2225
+ end_key_doc_id: @end_key_doc_id,
2226
+ inclusive_end: @inclusive_end,
2227
+ group: @group,
2228
+ group_level: @group_level,
2229
+ key: (JSON.generate(@key) unless @key.nil?),
2230
+ keys: @keys&.map { |key| JSON.generate(key) },
2231
+ order: @order,
2232
+ reduce: @reduce,
2233
+ on_error: @on_error,
2234
+ debug: @debug,
2235
+ }
2236
+ end
2237
+
2238
+ # @api private
2239
+ DEFAULT = View.new.freeze
2240
+ end
2241
+
2242
+ # @api private
2243
+ # TODO: deprecate in 3.1
2244
+ CommonOptions = ::Couchbase::Options::Base
2245
+
2246
+ # rubocop:disable Naming/MethodName constructor shortcuts
2247
+ module_function
2248
+
2249
+ # Construct {Get} options for {Collection#get}
2250
+ #
2251
+ # @example Get partial document using projections
2252
+ # res = collection.get("customer123", Options::Get(projections: ["name", "addresses.billing"]))
2253
+ # res.content
2254
+ #
2255
+ # # {"addresses"=>
2256
+ # # {"billing"=>
2257
+ # # {"country"=>"United Kingdom",
2258
+ # # "line1"=>"123 Any Street",
2259
+ # # "line2"=>"Anytown"}},
2260
+ # # "name"=>"Douglas Reynholm"}
2261
+ #
2262
+ # @return [Get]
2263
+ def Get(**args)
2264
+ Get.new(**args)
2265
+ end
2266
+
2267
+ # Construct {GetMulti} options for {Collection#get_multi}
2268
+ #
2269
+ # @example Fetch "foo" and "bar" in a batch
2270
+ # res = collection.get(["foo", "bar"], Options::GetMulti(timeout: 3_000))
2271
+ # res[0].content #=> content of "foo"
2272
+ # res[1].content #=> content of "bar"
2273
+ #
2274
+ # @return [GetMulti]
2275
+ def GetMulti(**args)
2276
+ GetMulti.new(**args)
2277
+ end
2278
+
2279
+ # Construct {GetAndLock} options for {Collection#get_and_lock}
2280
+ #
2281
+ # @example Retrieve document and lock for 10 seconds
2282
+ # collection.get_and_lock("customer123", 10, Options::GetAndLock(timeout: 3_000))
2283
+ #
2284
+ # @return [GetAndLock]
2285
+ def GetAndLock(**args)
2286
+ GetAndLock.new(**args)
2287
+ end
2288
+
2289
+ # Construct {GetAndTouch} options for {Collection#get_and_touch}
2290
+ #
2291
+ # @example Retrieve document and prolong its expiration for 10 seconds
2292
+ # collection.get_and_touch("customer123", 10, Options::GetAndTouch(timeout: 3_000))
2293
+ #
2294
+ # @return [GetAndTouch]
2295
+ def GetAndTouch(**args)
2296
+ GetAndTouch.new(**args)
2297
+ end
2298
+
2299
+ # Construct {GetAllReplicas} options for {Collection#get_any_replica}
2300
+ #
2301
+ # @return [GetAllReplicas]
2302
+ def GetAllReplicas(**args)
2303
+ GetAllReplicas.new(**args)
2304
+ end
2305
+
2306
+ # Construct {GetAnyReplica} options for {Collection#get_all_replicas}
2307
+ #
2308
+ # @return [GetAnyReplica]
2309
+ def GetAnyReplica(**args)
2310
+ GetAnyReplica.new(**args)
2311
+ end
2312
+
2313
+ # Construct {Exists} options for {Collection#exists}
2314
+ #
2315
+ # @example Check if the document exists without fetching its contents
2316
+ # res = collection.exists("customer123", Options::Exists(timeout: 3_000))
2317
+ # res.exists? #=> true
2318
+ #
2319
+ # @return [Exists]
2320
+ def Exists(**args)
2321
+ Exists.new(**args)
2322
+ end
2323
+
2324
+ # Construct {Touch} options for {Collection#touch}
2325
+ #
2326
+ # @example Reset expiration timer for document to 30 seconds (and use custom operation timeout)
2327
+ # res = collection.touch("customer123", 30, Options::Touch(timeout: 3_000))
2328
+ #
2329
+ # @return [Touch]
2330
+ def Touch(**args)
2331
+ Touch.new(**args)
2332
+ end
2333
+
2334
+ # Construct {Unlock} options for {Collection#touch}
2335
+ #
2336
+ # @example Lock (pessimistically) and unlock document
2337
+ # res = collection.get_and_lock("customer123", 10, Options::Unlock(timeout: 3_000))
2338
+ # collection.unlock("customer123", res.cas)
2339
+ #
2340
+ # @return [Unlock]
2341
+ def Unlock(**args)
2342
+ Unlock.new(**args)
2343
+ end
2344
+
2345
+ # Construct {Remove} options for {Collection#remove}
2346
+ #
2347
+ # @example Remove the document in collection, but apply optimistic lock
2348
+ # res = collection.upsert("mydoc", {"foo" => 42})
2349
+ # res.cas #=> 7751414725654
2350
+ #
2351
+ # begin
2352
+ # res = collection.remove("customer123", Options::Remove(cas: 3735928559))
2353
+ # rescue Error::CasMismatch
2354
+ # puts "Failed to remove the document, it might be changed by other application"
2355
+ # end
2356
+ #
2357
+ # @return [Remove]
2358
+ def Remove(**args)
2359
+ Remove.new(**args)
2360
+ end
2361
+
2362
+ # Construct {RemoveMulti} options for {Collection#remove_multi}
2363
+ #
2364
+ # @example Remove two documents in collection. For "mydoc" apply optimistic lock
2365
+ # res = collection.upsert("mydoc", {"foo" => 42})
2366
+ # res.cas #=> 7751414725654
2367
+ #
2368
+ # res = collection.remove_multi(["foo", ["mydoc", res.cas]], Options::RemoveMulti(timeout: 3_000))
2369
+ # if res[1].error.is_a?(Error::CasMismatch)
2370
+ # puts "Failed to remove the document, it might be changed by other application"
2371
+ # end
2372
+ #
2373
+ # @return [RemoveMulti]
2374
+ def RemoveMulti(**args)
2375
+ RemoveMulti.new(**args)
2376
+ end
2377
+
2378
+ # Construct {Insert} options for {Collection#insert}
2379
+ #
2380
+ # @example Insert new document in collection
2381
+ # res = collection.insert("mydoc", {"foo" => 42}, Options::Insert(expiry: 20))
2382
+ # res.cas #=> 242287264414742
2383
+ #
2384
+ # @return [Insert]
2385
+ def Insert(**args)
2386
+ Insert.new(**args)
2387
+ end
2388
+
2389
+ # Construct {Upsert} options for {Collection#upsert}
2390
+ #
2391
+ # @example Upsert new document in collection
2392
+ # res = collection.upsert("mydoc", {"foo" => 42}, Options::Upsert(expiry: 20))
2393
+ # res.cas #=> 242287264414742
2394
+ #
2395
+ # @return [Upsert]
2396
+ def Upsert(**args)
2397
+ Upsert.new(**args)
2398
+ end
2399
+
2400
+ # Construct {UpsertMulti} options for {Collection#upsert_multi}
2401
+ #
2402
+ # @example Upsert two documents with IDs "foo" and "bar" into a collection with expiration 20 seconds.
2403
+ # res = collection.upsert_multi([
2404
+ # "foo", {"foo" => 42},
2405
+ # "bar", {"bar" => "some value"}
2406
+ # ], Options::UpsertMulti(expiry: 20))
2407
+ # res[0].cas #=> 7751414725654
2408
+ # res[1].cas #=> 7751418925851
2409
+ #
2410
+ # @return [UpsertMulti]
2411
+ def UpsertMulti(**args)
2412
+ UpsertMulti.new(**args)
2413
+ end
2414
+
2415
+ # Construct {Replace} options for {Collection#replace}
2416
+ #
2417
+ # @example Replace new document in collection with optimistic locking
2418
+ # res = collection.get("mydoc")
2419
+ # res = collection.replace("mydoc", {"foo" => 42}, Options::Replace(cas: res.cas))
2420
+ # res.cas #=> 242287264414742
2421
+ #
2422
+ # @return [Replace]
2423
+ def Replace(**args)
2424
+ Replace.new(**args)
2425
+ end
2426
+
2427
+ # Construct {MutateIn} options for {Collection#mutate_in}
2428
+ #
2429
+ # @example Append number into subarray of the document
2430
+ # mutation_specs = [
2431
+ # MutateInSpec::array_append("purchases.complete", [42])
2432
+ # ]
2433
+ # collection.mutate_in("customer123", mutation_specs, Options::MutateIn(expiry: 10))
2434
+ #
2435
+ # @return [MutateIn]
2436
+ def MutateIn(**args)
2437
+ MutateIn.new(**args)
2438
+ end
2439
+
2440
+ # Construct {LookupIn} options for {Collection#lookup_in}
2441
+ #
2442
+ # @example Get list of IDs of completed purchases
2443
+ # lookup_specs = [
2444
+ # LookupInSpec::get("purchases.complete")
2445
+ # ]
2446
+ # collection.lookup_in("customer123", lookup_specs, Options::LookupIn(timeout: 3_000))
2447
+ #
2448
+ # @return [LookupIn]
2449
+ def LookupIn(**args)
2450
+ LookupIn.new(**args)
2451
+ end
2452
+
2453
+ # Construct {Append} options for {BinaryCollection#append}
2454
+ #
2455
+ # @example Append "bar" to the content of the existing document
2456
+ # collection.upsert("mydoc", "foo")
2457
+ # collection.binary.append("mydoc", "bar", Options::Append(timeout: 3_000))
2458
+ # collection.get("mydoc", Options::Get(transcoder: nil)).content #=> "foobar"
2459
+ #
2460
+ # @return [Append]
2461
+ def Append(**args)
2462
+ Append.new(**args)
2463
+ end
2464
+
2465
+ # Construct {Prepend} options for {BinaryCollection#prepend}
2466
+ #
2467
+ # @example Prepend "bar" to the content of the existing document
2468
+ # collection.upsert("mydoc", "foo")
2469
+ # collection.binary.prepend("mydoc", "bar", Options::Prepend(timeout: 3_000))
2470
+ # collection.get("mydoc", Options::Get(transcoder: nil)).content #=> "barfoo"
2471
+ #
2472
+ # @return [Prepend]
2473
+ def Prepend(**args)
2474
+ Prepend.new(**args)
2475
+ end
2476
+
2477
+ # Construct {Diagnostics} options for {Cluster#diagnostics}
2478
+ #
2479
+ # @return [Diagnostics]
2480
+ def Diagnostics(**args)
2481
+ Diagnostics.new(**args)
2482
+ end
2483
+
2484
+ # Construct {Ping} options for {Bucket#ping}
2485
+ #
2486
+ # @return [Ping]
2487
+ def Ping(**args)
2488
+ Ping.new(**args)
2489
+ end
2490
+
2491
+ # Construct {Cluster} options for {Cluster.connect}
2492
+ #
2493
+ # It forwards all its arguments to {Cluster#initialize}
2494
+ #
2495
+ # @return [Cluster]
2496
+ def Cluster(**args)
2497
+ Cluster.new(**args)
2498
+ end
2499
+
2500
+ # Construct {Increment} options for {BinaryCollection#increment}
2501
+ #
2502
+ # @example Increment value by 10, and initialize to 0 if it does not exist
2503
+ # res = collection.binary.increment("raw_counter", Options::Increment(delta: 10, initial: 0))
2504
+ # res.content #=> 0
2505
+ # res = collection.binary.increment("raw_counter", Options::Increment(delta: 10, initial: 0))
2506
+ # res.content #=> 10
2507
+ #
2508
+ # @return [Increment]
2509
+ def Increment(**args)
2510
+ Increment.new(**args)
2511
+ end
2512
+
2513
+ # Construct {Decrement} options for {BinaryCollection#decrement}
2514
+ #
2515
+ # @example Decrement value by 2, and initialize to 100 if it does not exist
2516
+ # res = collection.binary.decrement("raw_counter", Options::Decrement(delta: 2, initial: 100))
2517
+ # res.value #=> 100
2518
+ # res = collection.binary.decrement("raw_counter", Options::Decrement(delta: 2, initial: 100))
2519
+ # res.value #=> 98
2520
+ #
2521
+ # @return [Decrement]
2522
+ def Decrement(**args)
2523
+ Decrement.new(**args)
2524
+ end
2525
+
2526
+ # Construct {Analytics} options for {Cluster#analytics_query}
2527
+ #
2528
+ # @example Select name of the given user
2529
+ # cluster.analytics_query("SELECT u.name AS uname FROM GleambookUsers u WHERE u.id = $user_id ",
2530
+ # Options::Analytics(named_parameters: {user_id: 2}))
2531
+ #
2532
+ # @return [Analytics]
2533
+ def Analytics(**args)
2534
+ Analytics.new(**args)
2535
+ end
2536
+
2537
+ # Construct {Query} options for {Cluster#query}
2538
+ #
2539
+ # @example Select first ten hotels from travel sample dataset
2540
+ # cluster.query("SELECT * FROM `travel-sample` WHERE type = $type LIMIT 10",
2541
+ # Options::Query(named_parameters: {type: "hotel"}, metrics: true))
2542
+ #
2543
+ # @return [Query]
2544
+ def Query(**args)
2545
+ Query.new(**args)
2546
+ end
2547
+
2548
+ # Construct {Search} options for {Cluster#search_query}
2549
+ #
2550
+ # @example Return first 10 results of "hop beer" query and request highlighting
2551
+ # cluster.search_query("beer_index", Cluster::SearchQuery.match_phrase("hop beer"),
2552
+ # Options::Search(
2553
+ # limit: 10,
2554
+ # fields: %w[name],
2555
+ # highlight_style: :html,
2556
+ # highlight_fields: %w[name description]
2557
+ # ))
2558
+ #
2559
+ # @return [Search]
2560
+ def Search(**args)
2561
+ Search.new(**args)
2562
+ end
2563
+
2564
+ # Construct {View} options for {Bucket#view_query}
2565
+ #
2566
+ # @example Make sure the view engine catch up with all mutations and return keys starting from +["random_brewery:"]+
2567
+ # bucket.view_query("beer", "brewery_beers",
2568
+ # Options::View(
2569
+ # start_key: ["random_brewery:"],
2570
+ # scan_consistency: :request_plus
2571
+ # ))
2572
+ #
2573
+ # @return [View]
2574
+ def View(**args)
2575
+ View.new(**args)
2576
+ end
2577
+
2578
+ # rubocop:enable Naming/MethodName
2579
+ end
2580
+ end