couchbase 3.9.0-aarch64-mingw-ucrt

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