couchbase 3.5.3-arm64-darwin

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