couchbase 3.5.7-aarch64-linux

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