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,231 @@
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/collection"
18
+ require "couchbase/options"
19
+ require "couchbase/errors"
20
+
21
+ module Couchbase
22
+ module Datastructures
23
+ # A {CouchbaseMap} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
24
+ # a JSON array).
25
+ #
26
+ # Note that as such, a {CouchbaseMap} is restricted to the types that JSON array can contain.
27
+ class CouchbaseMap
28
+ include Enumerable
29
+
30
+ # Create a new Map, backed by the document identified by +id+ in +collection+.
31
+ #
32
+ # @param [String] id the id of the document to back the map.
33
+ # @param [Collection] collection the Couchbase collection through which to interact with the document.
34
+ # @param [Options::CouchbaseMap] options customization of the datastructure
35
+ def initialize(id, collection, options = Options::CouchbaseMap.new)
36
+ @id = id
37
+ @collection = collection
38
+ @options = options
39
+ @cas = 0
40
+ @observability = collection.instance_variable_get(:@observability)
41
+ @observability = Observability::Wrapper.new if @observability.nil?
42
+ end
43
+
44
+ # Calls the given block once for each element in the map, passing that element as a parameter.
45
+ #
46
+ # @yieldparam [Object] item
47
+ #
48
+ # @return [CouchbaseMap, Enumerable]
49
+ def each(parent_span: nil, &)
50
+ if block_given?
51
+ current =
52
+ @observability.record_operation(Observability::OP_MAP_EACH, parent_span, self) do |obs_handler|
53
+ options = @options.get_options.clone
54
+ options.parent_span = obs_handler.op_span
55
+ result = @collection.get(@id, options)
56
+ @cas = result.cas
57
+ result.content
58
+ rescue Error::DocumentNotFound
59
+ @cas = 0
60
+ []
61
+ end
62
+ current.each(&)
63
+ self
64
+ else
65
+ enum_for(:each, parent_span: parent_span)
66
+ end
67
+ end
68
+
69
+ # @return [Integer] returns the number of elements in the map.
70
+ def length(parent_span: nil)
71
+ @observability.record_operation(Observability::OP_MAP_LENGTH, parent_span, self) do |obs_handler|
72
+ options = @options.lookup_in_options.clone
73
+ options.parent_span = obs_handler.op_span
74
+ result = @collection.lookup_in(@id, [
75
+ LookupInSpec.count(""),
76
+ ], options)
77
+ result.content(0)
78
+ rescue Error::DocumentNotFound
79
+ 0
80
+ end
81
+ end
82
+
83
+ alias size length
84
+
85
+ # @return [Boolean] returns true if map is empty
86
+ def empty?(parent_span: nil)
87
+ size(parent_span: parent_span).zero?
88
+ end
89
+
90
+ # Removes all elements from the map
91
+ def clear(parent_span: nil)
92
+ @observability.record_operation(Observability::OP_MAP_CLEAR, parent_span, self) do |obs_handler|
93
+ options = @options.remove_options.clone
94
+ options.parent_span = obs_handler.op_span
95
+ @collection.remove(@id, options)
96
+ nil
97
+ rescue Error::DocumentNotFound
98
+ nil
99
+ end
100
+ end
101
+
102
+ # Returns a value from the map for the given key.
103
+ #
104
+ # If the key cannot be found, there are several options:
105
+ #
106
+ # * with no other arguments, it will raise a KeyError exception
107
+ # * if +default+ is given, then that will be returned
108
+ # * if the optional code +block+ is specified, then that will be run and its result returned
109
+ #
110
+ # @overload fetch(key)
111
+ # Gets the value, associated with the key, or raise KeyError if key could not be found
112
+ # @param key [String] key
113
+ #
114
+ # @overload fetch(key, default)
115
+ # Gets the value, associated with the key, or return +default+ if key could not be found
116
+ # @param key [String] key
117
+ #
118
+ # @overload fetch(key, &block)
119
+ # Gets the value, associated with the key, or invoke specified +block+ and propagate its return value
120
+ # if key could not be found
121
+ # @param key [String] key
122
+ # @yieldreturn [Object] the default value to return in case the key could not be found
123
+ #
124
+ # @return [Object]
125
+ def fetch(key, *rest, parent_span: nil)
126
+ @observability.record_operation(Observability::OP_MAP_FETCH, parent_span, self) do |obs_handler|
127
+ options = @options.lookup_in_options.clone
128
+ options.parent_span = obs_handler.op_span
129
+ result = @collection.lookup_in(@id, [
130
+ LookupInSpec.get(key),
131
+ ], options)
132
+ result.content(0)
133
+ rescue Error::DocumentNotFound, Error::PathNotFound
134
+ return yield if block_given?
135
+ return rest.first unless rest.empty?
136
+
137
+ raise KeyError, "key not found: #{key}"
138
+ end
139
+ end
140
+
141
+ # Returns a value from the map for the given key.
142
+ #
143
+ # If the key cannot be found, +nil+ will be returned.
144
+ #
145
+ # @param [String] key
146
+ #
147
+ # @return [Object, nil] value, associated with the key or +nil+
148
+ def [](key)
149
+ fetch(key, nil)
150
+ end
151
+
152
+ # Associate the value given by +value+ with the key given by +key+.
153
+ #
154
+ # @param [String] key
155
+ # @param [Object] value
156
+ #
157
+ # @return [void]
158
+ def store(key, value, parent_span: nil)
159
+ @observability.record_operation(Observability::OP_MAP_STORE, parent_span, self) do |obs_handler|
160
+ options = @options.mutate_in_options.clone
161
+ options.parent_span = obs_handler.op_span
162
+ @collection.mutate_in(@id, [
163
+ MutateInSpec.upsert(key, value),
164
+ ], options)
165
+ end
166
+ end
167
+
168
+ # Associate the value given by +value+ with the key given by +key+.
169
+ #
170
+ # @param [String] key
171
+ # @param [Object] value
172
+ #
173
+ # @return [void]
174
+ def []=(key, value)
175
+ store(key, value)
176
+ end
177
+
178
+ # Deletes the key-value pair from the map.
179
+ #
180
+ # @param [String] key
181
+ #
182
+ # @return void
183
+ def delete(key, parent_span: nil)
184
+ @observability.record_operation(Observability::OP_MAP_DELETE, parent_span, self) do |obs_handler|
185
+ @collection.mutate_in(@id, [
186
+ MutateInSpec.remove(key),
187
+ ], Options::MutateIn.new(parent_span: obs_handler.op_span))
188
+ rescue Error::DocumentNotFound, Error::PathNotFound
189
+ nil
190
+ end
191
+ end
192
+
193
+ # Returns +true+ if the given key is present
194
+ #
195
+ # @param [String] key
196
+ # @return [Boolean]
197
+ def key?(key, parent_span: nil)
198
+ @observability.record_operation(Observability::OP_MAP_KEY_EXISTS, parent_span, self) do |obs_handler|
199
+ options = @options.lookup_in_options.clone
200
+ options.parent_span = obs_handler.op_span
201
+ result = @collection.lookup_in(@id, [
202
+ LookupInSpec.exists(key),
203
+ ], options)
204
+ result.exists?(0)
205
+ rescue Error::DocumentNotFound, Error::PathNotFound
206
+ false
207
+ end
208
+ end
209
+
210
+ alias member? key?
211
+ alias include? key?
212
+
213
+ # Returns a new array populated with the keys from the map.
214
+ #
215
+ # @return [Array]
216
+ def keys
217
+ map { |key, _value| key }
218
+ end
219
+
220
+ # Returns a new array populated with the values from the map.
221
+ #
222
+ # @return [Array]
223
+ def values
224
+ map { |_key, value| value }
225
+ end
226
+ end
227
+
228
+ # @api private
229
+ CouchbaseMapOptions = ::Couchbase::Options::CouchbaseMap
230
+ end
231
+ end
@@ -0,0 +1,161 @@
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/collection"
18
+ require "couchbase/options"
19
+ require "couchbase/errors"
20
+
21
+ module Couchbase
22
+ module Datastructures
23
+ # A {CouchbaseQueue} is implements FIFO queue with +Enumerable+ interface and backed by {Collection} document
24
+ # (more specifically a JSON array).
25
+ #
26
+ # Note: sets are restricted to containing primitive types only due to server-side comparison restrictions.
27
+ class CouchbaseQueue
28
+ include Enumerable
29
+
30
+ # Create a new List, backed by the document identified by +id+ in +collection+.
31
+ #
32
+ # @param [String] id the id of the document to back the queue.
33
+ # @param [Collection] collection the collection through which to interact with the document.
34
+ # @param [Options::CouchbaseList] options customization of the datastructure
35
+ def initialize(id, collection, options = Options::CouchbaseQueue.new)
36
+ @id = id
37
+ @collection = collection
38
+ @options = options
39
+ @cas = 0
40
+ @observability = @collection.instance_variable_get(:@observability)
41
+ @observability = Observability::Wrapper.new if @observability.nil?
42
+ end
43
+
44
+ # Calls the given block once for each element in the queue, passing that element as a parameter.
45
+ #
46
+ # @yieldparam [Object] item
47
+ #
48
+ # @return [CouchbaseQueue, Enumerable]
49
+ def each(parent_span: nil, &)
50
+ if block_given?
51
+ current = @observability.record_operation(Observability::OP_QUEUE_EACH, parent_span, self) do |obs_handler|
52
+ options = @options.get_options.clone
53
+ options.parent_span = obs_handler.op_span
54
+ result = @collection.get(@id, options)
55
+ @cas = result.cas
56
+ result.content
57
+ rescue Error::DocumentNotFound
58
+ @cas = 0
59
+ []
60
+ end
61
+ current.each(&)
62
+ self
63
+ else
64
+ enum_for(:each, parent_span: parent_span)
65
+ end
66
+ end
67
+
68
+ # @return [Integer] returns the number of elements in the queue.
69
+ def length(parent_span: nil)
70
+ @observability.record_operation(Observability::OP_QUEUE_LENGTH, parent_span, self) do |obs_handler|
71
+ options = @options.lookup_in_options.clone
72
+ options.parent_span = obs_handler.op_span
73
+ result = @collection.lookup_in(@id, [
74
+ LookupInSpec.count(""),
75
+ ], options)
76
+ result.content(0)
77
+ rescue Error::DocumentNotFound
78
+ 0
79
+ end
80
+ end
81
+
82
+ alias size length
83
+
84
+ # @return [Boolean] returns true if queue is empty
85
+ def empty?(parent_span: nil)
86
+ size(parent_span: parent_span).zero?
87
+ end
88
+
89
+ # Removes all elements from the queue
90
+ def clear(parent_span: nil)
91
+ @observability.record_operation(Observability::OP_QUEUE_CLEAR, parent_span, self) do |obs_handler|
92
+ options = @options.remove_options.clone
93
+ options.parent_span = obs_handler.op_span
94
+ @collection.remove(@id, options)
95
+ nil
96
+ rescue Error::DocumentNotFound
97
+ nil
98
+ end
99
+ end
100
+
101
+ # Adds the given value to the queue
102
+ #
103
+ # @param [Object] obj
104
+ # @return [CouchbaseQueue]
105
+ def push(obj, parent_span: nil)
106
+ @observability.record_operation(Observability::OP_QUEUE_PUSH, parent_span, self) do |obs_handler|
107
+ options = @options.mutate_in_options.clone
108
+ options.parent_span = obs_handler.op_span
109
+ @collection.mutate_in(@id, [
110
+ MutateInSpec.array_prepend("", [obj]),
111
+ ], options)
112
+ rescue Error::PathExists
113
+ # ignore
114
+ end
115
+ self
116
+ end
117
+
118
+ alias enq push
119
+ alias << push
120
+
121
+ # Retrieves object from the queue
122
+ #
123
+ # @return [Object, nil] queue entry or nil
124
+ def pop(parent_span: nil)
125
+ @observability.record_operation(Observability::OP_QUEUE_POP, parent_span, self) do |obs_handler|
126
+ obj, cas = begin
127
+ options = @options.lookup_in_options.clone
128
+ options.parent_span = obs_handler.op_span
129
+ result = @collection.lookup_in(@id, [
130
+ LookupInSpec.get("[-1]"),
131
+ ], @options.lookup_in_options)
132
+ [
133
+ result.exists?(0) ? result.content(0) : nil,
134
+ result.cas,
135
+ ]
136
+ end
137
+ begin
138
+ options = Options::MutateIn.new(
139
+ parent_span: obs_handler.op_span,
140
+ cas: cas,
141
+ )
142
+ @collection.mutate_in(@id, [
143
+ MutateInSpec.remove("[-1]"),
144
+ ], options)
145
+ end
146
+ obj
147
+ rescue Error::CasMismatch
148
+ retry
149
+ rescue Error::DocumentNotFound, Error::PathNotFound
150
+ nil
151
+ end
152
+ end
153
+
154
+ alias deq pop
155
+ alias shift pop
156
+ end
157
+
158
+ # @api private
159
+ CouchbaseQueueOptions = ::Couchbase::Options::CouchbaseQueue
160
+ end
161
+ end
@@ -0,0 +1,145 @@
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/collection"
18
+ require "couchbase/options"
19
+ require "couchbase/errors"
20
+
21
+ module Couchbase
22
+ module Datastructures
23
+ # A {CouchbaseSet} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
24
+ # a JSON array).
25
+ #
26
+ # Note: sets are restricted to containing primitive types only due to server-side comparison restrictions.
27
+ class CouchbaseSet
28
+ include Enumerable
29
+
30
+ # Create a new List, backed by the document identified by +id+ in +collection+.
31
+ #
32
+ # @param [String] id the id of the document to back the set.
33
+ # @param [Collection] collection the collection through which to interact with the document.
34
+ # @param [Options::CouchbaseSet] options customization of the datastructure
35
+ def initialize(id, collection, options = Options::CouchbaseSet.new)
36
+ @id = id
37
+ @collection = collection
38
+ @options = options
39
+ @cas = 0
40
+ @observability = @collection.instance_variable_get(:@observability)
41
+ @observability = Observability::Wrapper.new if @observability.nil?
42
+ end
43
+
44
+ # Calls the given block once for each element in the set, passing that element as a parameter.
45
+ #
46
+ # @yieldparam [Object] item
47
+ #
48
+ # @return [CouchbaseSet, Enumerable]
49
+ def each(parent_span: nil, &)
50
+ if block_given?
51
+ current =
52
+ @observability.record_operation(Observability::OP_SET_EACH, parent_span, self) do |obs_handler|
53
+ options = @options.get_options.clone
54
+ options.parent_span = obs_handler.op_span
55
+ result = @collection.get(@id, options)
56
+ @cas = result.cas
57
+ result.content
58
+ rescue Error::DocumentNotFound
59
+ @cas = 0
60
+ []
61
+ end
62
+ current.each(&)
63
+ self
64
+ else
65
+ enum_for(:each, parent_span: parent_span)
66
+ end
67
+ end
68
+
69
+ # @return [Integer] returns the number of elements in the set.
70
+ def length(parent_span: nil)
71
+ @observability.record_operation(Observability::OP_SET_LENGTH, parent_span, self) do |obs_handler|
72
+ options = @options.lookup_in_options.clone
73
+ options.parent_span = obs_handler.op_span
74
+ result = @collection.lookup_in(@id, [
75
+ LookupInSpec.count(""),
76
+ ], options)
77
+ result.content(0)
78
+ rescue Error::DocumentNotFound
79
+ 0
80
+ end
81
+ end
82
+
83
+ alias size length
84
+
85
+ # @return [Boolean] returns true if set is empty
86
+ def empty?(parent_span: nil)
87
+ size(parent_span: parent_span).zero?
88
+ end
89
+
90
+ # Adds the given value to the set
91
+ #
92
+ # @param [Object] obj
93
+ # @return [CouchbaseSet]
94
+ def add(obj, parent_span: nil)
95
+ @observability.record_operation(Observability::OP_SET_ADD, parent_span, self) do |obs_handler|
96
+ options = @options.mutate_in_options.clone
97
+ options.parent_span = obs_handler.op_span
98
+ @collection.mutate_in(@id, [
99
+ MutateInSpec.array_add_unique("", obj),
100
+ ], options)
101
+ rescue Error::PathExists
102
+ # ignore
103
+ end
104
+ self
105
+ end
106
+
107
+ # Removes all elements from the set
108
+ def clear(parent_span: nil)
109
+ @observability.record_operation(Observability::OP_SET_CLEAR, parent_span, self) do |obs_handler|
110
+ options = @options.remove_options.clone
111
+ options.parent_span = obs_handler.op_span
112
+ @collection.remove(@id, options)
113
+ nil
114
+ rescue Error::DocumentNotFound
115
+ nil
116
+ end
117
+ end
118
+
119
+ # Deletes the given object from the set.
120
+ #
121
+ # @return [Boolean] true if the value has been removed
122
+ def delete(obj, parent_span: nil)
123
+ @observability.record_operation(Observability::OP_SET_DELETE, parent_span, self) do |obs_handler|
124
+ result = @collection.get(@id, Options::Get.new(parent_span: obs_handler.op_span))
125
+ idx = result.content.index(obj)
126
+ return false unless idx
127
+
128
+ options = Options::MutateIn.new(parent_span: obs_handler.op_span)
129
+ options.cas = result.cas
130
+ @collection.mutate_in(@id, [
131
+ MutateInSpec.remove("[#{idx}]"),
132
+ ], options)
133
+ true
134
+ rescue Error::CasMismatch
135
+ retry
136
+ rescue Error::DocumentNotFound
137
+ false
138
+ end
139
+ end
140
+ end
141
+
142
+ # @api private
143
+ CouchbaseSetOptions = ::Couchbase::Options::CouchbaseSet
144
+ end
145
+ end
@@ -0,0 +1,26 @@
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
+ module Couchbase
18
+ # This namespace includes easy-to-use wrappers for various concurrent data-structures.
19
+ module Datastructures
20
+ end
21
+ end
22
+
23
+ require "couchbase/datastructures/couchbase_list"
24
+ require "couchbase/datastructures/couchbase_set"
25
+ require "couchbase/datastructures/couchbase_queue"
26
+ require "couchbase/datastructures/couchbase_map"
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2025 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
+ module Couchbase
18
+ module Deprecations
19
+ def self.deprecate_constants(removed_in_version, parent, constants)
20
+ deprecator = Module.new do
21
+ define_method(:const_missing) do |old_name|
22
+ return super(old_name) unless constants.key?(old_name)
23
+
24
+ new_name = constants[old_name]
25
+
26
+ warn "NOTE: #{name}::#{old_name} is deprecated; use Couchbase::#{new_name} instead. " \
27
+ "It will be removed in version #{removed_in_version}."
28
+ Couchbase.const_get(new_name)
29
+ end
30
+ end
31
+ parent.singleton_class.prepend(deprecator)
32
+ end
33
+ end
34
+
35
+ Deprecations.deprecate_constants("3.6.0", Cluster,
36
+ AnalyticsOptions: "Options::Analytics",
37
+ ClusterOptions: "Options::Cluster",
38
+ DiagnosticsOptions: "Options::Diagnostics",
39
+ QueryOptions: "Options::Query",
40
+ SearchOptions: "Options::Search")
41
+
42
+ Deprecations.deprecate_constants("3.6.0", Bucket,
43
+ PingOptions: "Options::Ping",
44
+ ViewOptions: "Options::View")
45
+
46
+ Deprecations.deprecate_constants("3.6.0", Collection,
47
+ ExistsOptions: "Options::Exists",
48
+ GetAllReplicasOptions: "Options::GetAllReplicas",
49
+ GetAndLockOptions: "Options::GetAndLock",
50
+ GetAndTouchOptions: "Options::GetAndTouch",
51
+ GetAnyReplicaOptions: "Options::GetAnyReplica",
52
+ GetOptions: "Options::Get",
53
+ InsertOptions: "Options::Insert",
54
+ LookupInOptions: "Options::LookupIn",
55
+ MutateInOptions: "Options::MutateIn",
56
+ RemoveOptions: "Options::Remove",
57
+ ReplaceOptions: "Options::Replace",
58
+ TouchOptions: "Options::Touch",
59
+ UnlockOptions: "Options::Unlock",
60
+ UpsertOptions: "Options::Upsert")
61
+ end