couchbase 3.9.0-aarch64-linux-musl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +407 -0
  6. data/lib/couchbase/3.2/libcouchbase.so +0 -0
  7. data/lib/couchbase/3.3/libcouchbase.so +0 -0
  8. data/lib/couchbase/3.4/libcouchbase.so +0 -0
  9. data/lib/couchbase/4.0/libcouchbase.so +0 -0
  10. data/lib/couchbase/analytics_options.rb +109 -0
  11. data/lib/couchbase/authenticator.rb +80 -0
  12. data/lib/couchbase/binary_collection.rb +145 -0
  13. data/lib/couchbase/binary_collection_options.rb +26 -0
  14. data/lib/couchbase/bucket.rb +173 -0
  15. data/lib/couchbase/cluster.rb +555 -0
  16. data/lib/couchbase/cluster_registry.rb +49 -0
  17. data/lib/couchbase/collection.rb +770 -0
  18. data/lib/couchbase/collection_options.rb +401 -0
  19. data/lib/couchbase/config_profiles.rb +57 -0
  20. data/lib/couchbase/configuration.rb +58 -0
  21. data/lib/couchbase/datastructures/couchbase_list.rb +192 -0
  22. data/lib/couchbase/datastructures/couchbase_map.rb +231 -0
  23. data/lib/couchbase/datastructures/couchbase_queue.rb +161 -0
  24. data/lib/couchbase/datastructures/couchbase_set.rb +145 -0
  25. data/lib/couchbase/datastructures.rb +26 -0
  26. data/lib/couchbase/deprecations.rb +61 -0
  27. data/lib/couchbase/diagnostics.rb +183 -0
  28. data/lib/couchbase/errors.rb +438 -0
  29. data/lib/couchbase/fork_hooks.rb +41 -0
  30. data/lib/couchbase/get_replica_strategy.rb +89 -0
  31. data/lib/couchbase/json_transcoder.rb +41 -0
  32. data/lib/couchbase/key_value_scan.rb +119 -0
  33. data/lib/couchbase/libcouchbase.rb +6 -0
  34. data/lib/couchbase/logger.rb +87 -0
  35. data/lib/couchbase/management/analytics_index_manager.rb +1160 -0
  36. data/lib/couchbase/management/bucket_manager.rb +479 -0
  37. data/lib/couchbase/management/collection_manager.rb +515 -0
  38. data/lib/couchbase/management/collection_query_index_manager.rb +247 -0
  39. data/lib/couchbase/management/query_index_manager.rb +671 -0
  40. data/lib/couchbase/management/scope_search_index_manager.rb +267 -0
  41. data/lib/couchbase/management/search_index_manager.rb +649 -0
  42. data/lib/couchbase/management/user_manager.rb +639 -0
  43. data/lib/couchbase/management/view_index_manager.rb +332 -0
  44. data/lib/couchbase/management.rb +31 -0
  45. data/lib/couchbase/metrics/logging_meter.rb +108 -0
  46. data/lib/couchbase/metrics/logging_value_recorder.rb +50 -0
  47. data/lib/couchbase/metrics/meter.rb +27 -0
  48. data/lib/couchbase/metrics/noop_meter.rb +30 -0
  49. data/lib/couchbase/metrics/noop_value_recorder.rb +27 -0
  50. data/lib/couchbase/metrics/value_recorder.rb +25 -0
  51. data/lib/couchbase/mutation_state.rb +65 -0
  52. data/lib/couchbase/options.rb +3097 -0
  53. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  54. data/lib/couchbase/protostellar/bucket.rb +59 -0
  55. data/lib/couchbase/protostellar/client.rb +97 -0
  56. data/lib/couchbase/protostellar/cluster.rb +182 -0
  57. data/lib/couchbase/protostellar/collection.rb +156 -0
  58. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  59. data/lib/couchbase/protostellar/error_handling.rb +204 -0
  60. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
  61. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
  62. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +42 -0
  63. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +51 -0
  64. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +38 -0
  65. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +52 -0
  66. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +42 -0
  67. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +55 -0
  68. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +51 -0
  69. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +67 -0
  70. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +31 -0
  71. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +40 -0
  72. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +51 -0
  73. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +54 -0
  74. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
  75. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
  76. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +74 -0
  77. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +93 -0
  78. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +35 -0
  79. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +40 -0
  80. data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
  81. data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
  82. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +78 -0
  83. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +41 -0
  84. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +36 -0
  85. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +66 -0
  86. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +30 -0
  87. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +39 -0
  88. data/lib/couchbase/protostellar/generated.rb +9 -0
  89. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  90. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  91. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  92. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  93. data/lib/couchbase/protostellar/management.rb +24 -0
  94. data/lib/couchbase/protostellar/request.rb +79 -0
  95. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  96. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  97. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +96 -0
  98. data/lib/couchbase/protostellar/request_generator/admin/query.rb +132 -0
  99. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  100. data/lib/couchbase/protostellar/request_generator/kv.rb +488 -0
  101. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  102. data/lib/couchbase/protostellar/request_generator/search.rb +403 -0
  103. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  104. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  105. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  106. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  107. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  108. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  109. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  110. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  111. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  112. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  113. data/lib/couchbase/protostellar/retry/orchestrator.rb +61 -0
  114. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  115. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  116. data/lib/couchbase/protostellar/retry/strategies/fail_fast.rb +33 -0
  117. data/lib/couchbase/protostellar/retry/strategies.rb +27 -0
  118. data/lib/couchbase/protostellar/retry.rb +28 -0
  119. data/lib/couchbase/protostellar/scope.rb +61 -0
  120. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  121. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  122. data/lib/couchbase/protostellar.rb +29 -0
  123. data/lib/couchbase/query_options.rb +122 -0
  124. data/lib/couchbase/railtie.rb +47 -0
  125. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  126. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  127. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  128. data/lib/couchbase/scope.rb +272 -0
  129. data/lib/couchbase/search_options.rb +1744 -0
  130. data/lib/couchbase/subdoc.rb +293 -0
  131. data/lib/couchbase/tracing/noop_span.rb +29 -0
  132. data/lib/couchbase/tracing/noop_tracer.rb +29 -0
  133. data/lib/couchbase/tracing/request_span.rb +34 -0
  134. data/lib/couchbase/tracing/request_tracer.rb +28 -0
  135. data/lib/couchbase/tracing/threshold_logging_span.rb +112 -0
  136. data/lib/couchbase/tracing/threshold_logging_tracer.rb +231 -0
  137. data/lib/couchbase/transcoder_flags.rb +64 -0
  138. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  139. data/lib/couchbase/utils/hdr_histogram.rb +55 -0
  140. data/lib/couchbase/utils/observability.rb +263 -0
  141. data/lib/couchbase/utils/observability_constants.rb +200 -0
  142. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  143. data/lib/couchbase/utils/time.rb +71 -0
  144. data/lib/couchbase/utils.rb +23 -0
  145. data/lib/couchbase/version.rb +25 -0
  146. data/lib/couchbase/view_options.rb +67 -0
  147. data/lib/couchbase.rb +32 -0
  148. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  149. metadata +228 -0
@@ -0,0 +1,515 @@
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 "rubygems/deprecate"
18
+
19
+ require "couchbase/errors"
20
+ require "couchbase/options"
21
+
22
+ module Couchbase
23
+ module Management
24
+ module Options
25
+ module Collection
26
+ # Options for {CollectionManager#get_all_scopes}
27
+ class GetAllScopes < ::Couchbase::Options::Base
28
+ # Creates an instance of options for {CollectionManager#get_all_scopes}
29
+ #
30
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
31
+ # @param [Symbol, nil] retry_strategy ignored by this operation
32
+ # @param [Hash, nil] client_context the client context data, if set
33
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
34
+ #
35
+ # @yieldparam [GetAllScopes] self
36
+ def initialize(timeout: nil,
37
+ retry_strategy: nil,
38
+ client_context: nil,
39
+ parent_span: nil)
40
+ super
41
+ yield self if block_given?
42
+ end
43
+
44
+ DEFAULT = GetAllScopes.new.freeze
45
+ end
46
+
47
+ # Options for {CollectionManager#create_scope}
48
+ class CreateScope < ::Couchbase::Options::Base
49
+ # Creates an instance of options for {CollectionManager#create_scope}
50
+ #
51
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
52
+ # @param [Symbol, nil] retry_strategy ignored by this operation
53
+ # @param [Hash, nil] client_context the client context data, if set
54
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
55
+ #
56
+ # @yieldparam [CreateScope] self
57
+ def initialize(timeout: nil,
58
+ retry_strategy: nil,
59
+ client_context: nil,
60
+ parent_span: nil)
61
+ super
62
+ yield self if block_given?
63
+ end
64
+
65
+ DEFAULT = CreateScope.new.freeze
66
+ end
67
+
68
+ # Options for {CollectionManager#drop_scope}
69
+ class DropScope < ::Couchbase::Options::Base
70
+ # Creates an instance of options for {CollectionManager#drop_scope}
71
+ #
72
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
73
+ # @param [Symbol, nil] retry_strategy ignored by this operation
74
+ # @param [Hash, nil] client_context the client context data, if set
75
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
76
+ #
77
+ # @yieldparam [DropScope] self
78
+ def initialize(timeout: nil,
79
+ retry_strategy: nil,
80
+ client_context: nil,
81
+ parent_span: nil)
82
+ super
83
+ yield self if block_given?
84
+ end
85
+
86
+ DEFAULT = DropScope.new.freeze
87
+ end
88
+
89
+ # Options for {CollectionManager#create_collection}
90
+ class CreateCollection < ::Couchbase::Options::Base
91
+ # Creates an instance of options for {CollectionManager#create_collection}
92
+ #
93
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
94
+ # @param [Symbol, nil] retry_strategy ignored by this operation
95
+ # @param [Hash, nil] client_context the client context data, if set
96
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
97
+ #
98
+ # @yieldparam [CreateCollection] self
99
+ def initialize(timeout: nil,
100
+ retry_strategy: nil,
101
+ client_context: nil,
102
+ parent_span: nil)
103
+ super
104
+ yield self if block_given?
105
+ end
106
+
107
+ DEFAULT = CreateCollection.new.freeze
108
+ end
109
+
110
+ # Options for {CollectionManager#update_collection}
111
+ class UpdateCollection < ::Couchbase::Options::Base
112
+ # Creates an instance of options for {CollectionManager#update_collection}
113
+ #
114
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
115
+ # @param [Symbol, nil] retry_strategy ignored by this operation
116
+ # @param [Hash, nil] client_context the client context data, if set
117
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
118
+ #
119
+ # @yieldparam [UpdateCollection] self
120
+ def initialize(timeout: nil,
121
+ retry_strategy: nil,
122
+ client_context: nil,
123
+ parent_span: nil)
124
+ super
125
+ yield self if block_given?
126
+ end
127
+
128
+ DEFAULT = UpdateCollection.new.freeze
129
+ end
130
+
131
+ # Options for {CollectionManager#drop_collection}
132
+ class DropCollection < ::Couchbase::Options::Base
133
+ # Creates an instance of options for {CollectionManager#drop_collection}
134
+ #
135
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
136
+ # @param [Symbol, nil] retry_strategy ignored by this operation
137
+ # @param [Hash, nil] client_context the client context data, if set
138
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
139
+ #
140
+ # @yieldparam [DropCollection] self
141
+ def initialize(timeout: nil,
142
+ retry_strategy: nil,
143
+ client_context: nil,
144
+ parent_span: nil)
145
+ super
146
+ yield self if block_given?
147
+ end
148
+
149
+ DEFAULT = DropCollection.new.freeze
150
+ end
151
+
152
+ # rubocop:disable Naming/MethodName -- constructor shortcuts
153
+ module_function
154
+
155
+ # Construct {GetAllScopes} options for {CollectionManager#get_all_scopes}
156
+ #
157
+ # @return [GetAllScopes]
158
+ def GetAllScopes(**args)
159
+ GetAllScopes.new(**args)
160
+ end
161
+
162
+ # Construct {CreateScope} options for {CollectionManager#create_scope}
163
+ #
164
+ # @return [CreateScope]
165
+ def CreateScope(**args)
166
+ CreateScope.new(**args)
167
+ end
168
+
169
+ # Construct {DropScope} options for {CollectionManager#drop_scope}
170
+ #
171
+ # @return [DropScope]
172
+ def DropScope(**args)
173
+ DropScope.new(**args)
174
+ end
175
+
176
+ # Construct {CreateCollection} options for {CollectionManager#create_collection}
177
+ #
178
+ # @return [CreateCollection]
179
+ def CreateCollection(**args)
180
+ CreateCollection.new(**args)
181
+ end
182
+
183
+ # Construct {DropCollection} options for {CollectionManager#drop_collection}
184
+ #
185
+ # @return [DropCollection]
186
+ def DropCollection(**args)
187
+ DropCollection.new(**args)
188
+ end
189
+
190
+ # rubocop:enable Naming/MethodName
191
+ end
192
+ end
193
+
194
+ class CollectionManager
195
+ extend Gem::Deprecate
196
+
197
+ alias inspect to_s
198
+
199
+ # @param [Couchbase::Backend] backend
200
+ # @param [String] bucket_name
201
+ # @param [Observability::Wrapper] observability wrapper
202
+ #
203
+ # @api private
204
+ def initialize(backend, bucket_name, observability)
205
+ @backend = backend
206
+ @bucket_name = bucket_name
207
+ @observability = observability
208
+ end
209
+
210
+ # Get all scopes
211
+ #
212
+ # @param [Options::Collection::GetAllScopes] options
213
+ #
214
+ # @return [Array<ScopeSpec>]
215
+ def get_all_scopes(options = Options::Collection::GetAllScopes.new)
216
+ @observability.record_operation(Observability::OP_CM_GET_ALL_SCOPES, options.parent_span, self, :management) do |obs_handler|
217
+ res = @backend.scope_get_all(@bucket_name, options.to_backend, obs_handler)
218
+ res[:scopes].map do |s|
219
+ ScopeSpec.new do |scope|
220
+ scope.name = s[:name]
221
+ scope.collections = s[:collections].map do |c|
222
+ CollectionSpec.new do |collection|
223
+ collection.name = c[:name]
224
+ collection.scope_name = s[:name]
225
+ collection.max_expiry = c[:max_expiry]
226
+ collection.history = c[:history]
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end
233
+
234
+ # Get a scope by name
235
+ #
236
+ # @param [String] scope_name name of the scope
237
+ # @param [GetScopeOptions] options
238
+ #
239
+ # @deprecated Use {#get_all_scopes} with filter by name
240
+ #
241
+ # @return [ScopeSpec]
242
+ #
243
+ # @raise [Error::ScopeNotFound]
244
+ def get_scope(scope_name, options = GetScopeOptions.new)
245
+ @observability.record_operation(Observability::OP_CM_GET_SCOPE, options.parent_span, self, :management) do |obs_handler|
246
+ obs_handler.add_scope_name(scope_name)
247
+
248
+ get_all_scopes(Options::Collection::GetAllScopes(timeout: options.timeout, parent_span: obs_handler.op_span))
249
+ .find { |scope| scope.name == scope_name } or raise Error::ScopeNotFound, "unable to find scope #{scope_name}"
250
+ end
251
+ end
252
+
253
+ deprecate :get_scope, :get_all_scopes, 2021, 6
254
+
255
+ # Creates a new scope
256
+ #
257
+ # @param [String] scope_name name of the scope
258
+ # @param [Options::Collection::CreateScope] options
259
+ #
260
+ # @return void
261
+ #
262
+ # @raise [ArgumentError]
263
+ def create_scope(scope_name, options = Options::Collection::CreateScope.new)
264
+ @observability.record_operation(Observability::OP_CM_CREATE_SCOPE, options.parent_span, self, :management) do |obs_handler|
265
+ obs_handler.add_scope_name(scope_name)
266
+
267
+ @backend.scope_create(@bucket_name, scope_name, options.to_backend, obs_handler)
268
+ end
269
+ end
270
+
271
+ # Removes a scope
272
+ #
273
+ # @param [String] scope_name name of the scope
274
+ # @param [Options::Collection::DropScope] options
275
+ #
276
+ # @return void
277
+ #
278
+ # @raise [Error::ScopeNotFound]
279
+ def drop_scope(scope_name, options = Options::Collection::DropScope.new)
280
+ @observability.record_operation(Observability::OP_CM_DROP_SCOPE, options.parent_span, self, :management) do |obs_handler|
281
+ obs_handler.add_scope_name(scope_name)
282
+
283
+ @backend.scope_drop(@bucket_name, scope_name, options.to_backend, obs_handler)
284
+ end
285
+ end
286
+
287
+ # Creates a new collection
288
+ # @overload create_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT,
289
+ # options = Options::Collection::CreateCollection::DEFAULT)
290
+ # @param [String] scope_name the name of the scope the collection will be created in
291
+ # @param [String] collection_name the name of the collection to be created
292
+ # @param [CreateCollectionSettings] settings settings for the new collection
293
+ # @param [Options::Collection::CreateCollection] options
294
+ #
295
+ # @overload create_collection(collection, options = Options::Collection::CreateCollection)
296
+ # @param [CollectionSpec] collection specification of the collection
297
+ # @param [Options::Collection::CreateCollection] options
298
+ #
299
+ # @deprecated Use +#create_collection(scope_name, collection_name, settings, options)+ instead
300
+ #
301
+ # @return void
302
+ #
303
+ # @raise [ArgumentError]
304
+ # @raise [Error::CollectionExists]
305
+ # @raise [Error::ScopeNotFound]
306
+ def create_collection(*args)
307
+ scope_name, collection_name, settings, options =
308
+ if args[0].is_a?(CollectionSpec)
309
+ warn "Calling create_collection with a CollectionSpec object has been deprecated, supply scope name, " \
310
+ "collection name and optionally a CreateCollectionSettings instance"
311
+ collection = args[0]
312
+ [
313
+ collection.scope_name,
314
+ collection.name,
315
+ CreateCollectionSettings.new(max_expiry: collection.max_expiry, history: collection.history),
316
+ args[1] || Options::Collection::CreateCollection::DEFAULT,
317
+ ]
318
+ else
319
+ [
320
+ args[0],
321
+ args[1],
322
+ args[2] || CreateCollectionSettings::DEFAULT,
323
+ args[3] || Options::Collection::CreateCollection::DEFAULT,
324
+ ]
325
+ end
326
+
327
+ @observability.record_operation(Observability::OP_CM_CREATE_COLLECTION, options.parent_span, self, :management) do |obs_handler|
328
+ obs_handler.add_scope_name(scope_name)
329
+ obs_handler.add_collection_name(collection_name)
330
+
331
+ @backend.collection_create(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend, obs_handler)
332
+ end
333
+ end
334
+
335
+ # Updates the settings of an existing collection
336
+ #
337
+ # @param [String] scope_name the name of the scope the collection is in
338
+ # @param [String] collection_name the name of the collection to be updated
339
+ # @param [UpdateCollectionSettings] settings the settings that should be updated
340
+ #
341
+ # @raise [ArgumentError]
342
+ # @raise [Error::CollectionNotFound]
343
+ # @raise [Error::ScopeNotFound]
344
+ def update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT,
345
+ options = Options::Collection::UpdateCollection::DEFAULT)
346
+ @observability.record_operation(Observability::OP_CM_UPDATE_COLLECTION, options.parent_span, self, :management) do |obs_handler|
347
+ obs_handler.add_scope_name(scope_name)
348
+ obs_handler.add_collection_name(collection_name)
349
+
350
+ @backend.collection_update(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend, obs_handler)
351
+ end
352
+ end
353
+
354
+ # Removes a collection
355
+ # @overload drop_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT,
356
+ # options = Options::Collection::CreateCollection::DEFAULT)
357
+ # @param [String] scope_name the name of the scope the collection is in
358
+ # @param [String] collection_name the name of the collection to be removed
359
+ #
360
+ # @overload drop_collection(collection, options = Options::Collection::CreateCollection)
361
+ # @param [CollectionSpec] collection specification of the collection
362
+ # @param [Options::Collection::CreateCollection] options
363
+ #
364
+ # @deprecated Use +#drop_collection(scope_name, collection_name, options)+ instead
365
+ #
366
+ # @return void
367
+ #
368
+ # @raise [ArgumentError]
369
+ # @raise [Error::CollectionNotFound]
370
+ # @raise [Error::ScopeNotFound]
371
+ def drop_collection(*args)
372
+ scope_name, collection_name, options =
373
+ if args[0].is_a?(CollectionSpec)
374
+ warn "Calling drop_collection with a CollectionSpec object has been deprecated, supply scope name and collection name"
375
+ collection = args[0]
376
+ [
377
+ collection.scope_name,
378
+ collection.name,
379
+ args[1] || Options::Collection::CreateCollection::DEFAULT,
380
+ ]
381
+ else
382
+ [
383
+ args[0],
384
+ args[1],
385
+ args[2] || Options::Collection::CreateCollection::DEFAULT,
386
+ ]
387
+ end
388
+
389
+ @observability.record_operation(Observability::OP_CM_DROP_COLLECTION, options.parent_span, self, :management) do |obs_handler|
390
+ obs_handler.add_scope_name(scope_name)
391
+ obs_handler.add_collection_name(collection_name)
392
+
393
+ @backend.collection_drop(@bucket_name, scope_name, collection_name, options.to_backend, obs_handler)
394
+ end
395
+ end
396
+
397
+ # @deprecated use {CollectionManager#get_all_scopes} instead
398
+ class GetScopeOptions
399
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
400
+ attr_accessor :timeout
401
+
402
+ # @yieldparam [GetScopeOptions] self
403
+ def initialize
404
+ yield self if block_given?
405
+ end
406
+ end
407
+
408
+ # @api private
409
+ # TODO: deprecate after 3.2
410
+ GetAllScopesOptions = ::Couchbase::Management::Options::Collection::GetAllScopes
411
+
412
+ # @api private
413
+ # TODO: deprecate after 3.2
414
+ CreateScopeOptions = ::Couchbase::Management::Options::Collection::CreateScope
415
+
416
+ # @api private
417
+ # TODO: deprecate after 3.2
418
+ DropScopeOptions = ::Couchbase::Management::Options::Collection::DropScope
419
+
420
+ # @api private
421
+ # TODO: deprecate after 3.2
422
+ CreateCollectionOptions = ::Couchbase::Management::Options::Collection::CreateCollection
423
+
424
+ # @api private
425
+ # TODO: deprecate after 3.2
426
+ DropCollectionOptions = ::Couchbase::Management::Options::Collection::DropCollection
427
+ end
428
+
429
+ class CreateCollectionSettings
430
+ # @return [Integer, nil] time in seconds of the maximum expiration time for new documents in the collection
431
+ # (set to +nil+ to use the bucket-level setting, and to +-1+ set it to no-expiry)
432
+ attr_accessor :max_expiry
433
+
434
+ # @return [Boolean, nil] whether history retention override should be enabled in the collection (set to +nil+ to
435
+ # default to the bucket-level setting)
436
+ attr_accessor :history
437
+
438
+ def initialize(max_expiry: nil, history: nil)
439
+ @max_expiry = max_expiry
440
+ @history = history
441
+
442
+ yield self if block_given?
443
+ end
444
+
445
+ # @api private
446
+ def to_backend
447
+ {
448
+ max_expiry: @max_expiry,
449
+ history: @history,
450
+ }
451
+ end
452
+
453
+ DEFAULT = CreateCollectionSettings.new.freeze
454
+ end
455
+
456
+ class UpdateCollectionSettings
457
+ # @return [Integer, nil] time in seconds of the maximum expiration time for new documents in the collection
458
+ # (set to +nil+ to not update it, and to +-1+ set it to no-expiry)
459
+ attr_accessor :max_expiry
460
+
461
+ # @return [Boolean, nil] whether history retention override should be enabled in the collection (set to +nil+ to
462
+ # not update it)
463
+ attr_accessor :history
464
+
465
+ def initialize(max_expiry: nil, history: nil)
466
+ @max_expiry = max_expiry
467
+ @history = history
468
+
469
+ yield self if block_given?
470
+ end
471
+
472
+ # @api private
473
+ def to_backend
474
+ {
475
+ max_expiry: @max_expiry,
476
+ history: @history,
477
+ }
478
+ end
479
+
480
+ DEFAULT = UpdateCollectionSettings.new.freeze
481
+ end
482
+
483
+ class ScopeSpec
484
+ # @return [String] name of the scope
485
+ attr_accessor :name
486
+
487
+ # @return [Array<CollectionSpec>] list of collections associated with the scope
488
+ attr_accessor :collections
489
+
490
+ # @yieldparam [ScopeSpec] self
491
+ def initialize
492
+ yield self if block_given?
493
+ end
494
+ end
495
+
496
+ class CollectionSpec
497
+ # @return [String] name of the collection
498
+ attr_accessor :name
499
+
500
+ # @return [String] name of the scope
501
+ attr_accessor :scope_name
502
+
503
+ # @return [Integer] time in seconds of the expiration for new documents in the collection (set to +nil+ to disable it)
504
+ attr_accessor :max_expiry
505
+
506
+ # @return [Boolean, nil] whether history retention is enabled for this collection
507
+ attr_accessor :history
508
+
509
+ # @yieldparam [CollectionSpec] self
510
+ def initialize
511
+ yield self if block_given?
512
+ end
513
+ end
514
+ end
515
+ end