couchbase 3.4.0-arm64-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) 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 +339 -0
  6. data/lib/couchbase/analytics_options.rb +107 -0
  7. data/lib/couchbase/authenticator.rb +65 -0
  8. data/lib/couchbase/binary_collection.rb +128 -0
  9. data/lib/couchbase/binary_collection_options.rb +24 -0
  10. data/lib/couchbase/bucket.rb +144 -0
  11. data/lib/couchbase/cluster.rb +439 -0
  12. data/lib/couchbase/cluster_registry.rb +44 -0
  13. data/lib/couchbase/collection.rb +589 -0
  14. data/lib/couchbase/collection_options.rb +300 -0
  15. data/lib/couchbase/config_profiles.rb +55 -0
  16. data/lib/couchbase/configuration.rb +57 -0
  17. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  18. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  19. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  20. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  21. data/lib/couchbase/datastructures.rb +24 -0
  22. data/lib/couchbase/diagnostics.rb +181 -0
  23. data/lib/couchbase/errors.rb +351 -0
  24. data/lib/couchbase/json_transcoder.rb +32 -0
  25. data/lib/couchbase/libcouchbase.bundle +0 -0
  26. data/lib/couchbase/logger.rb +85 -0
  27. data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
  28. data/lib/couchbase/management/bucket_manager.rb +436 -0
  29. data/lib/couchbase/management/collection_manager.rb +321 -0
  30. data/lib/couchbase/management/query_index_manager.rb +520 -0
  31. data/lib/couchbase/management/search_index_manager.rb +408 -0
  32. data/lib/couchbase/management/user_manager.rb +468 -0
  33. data/lib/couchbase/management/view_index_manager.rb +237 -0
  34. data/lib/couchbase/management.rb +27 -0
  35. data/lib/couchbase/mutation_state.rb +63 -0
  36. data/lib/couchbase/options.rb +2580 -0
  37. data/lib/couchbase/query_options.rb +120 -0
  38. data/lib/couchbase/railtie.rb +45 -0
  39. data/lib/couchbase/scope.rb +232 -0
  40. data/lib/couchbase/search_options.rb +1570 -0
  41. data/lib/couchbase/subdoc.rb +290 -0
  42. data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
  43. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  44. data/lib/couchbase/utils/time.rb +56 -0
  45. data/lib/couchbase/utils.rb +21 -0
  46. data/lib/couchbase/version.rb +23 -0
  47. data/lib/couchbase/view_options.rb +65 -0
  48. data/lib/couchbase.rb +20 -0
  49. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  50. metadata +101 -0
@@ -0,0 +1,351 @@
1
+ # Copyright 2020-2021 Couchbase, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "json"
16
+
17
+ module Couchbase
18
+ # This namespace contains all error types that the library might raise.
19
+ module Error
20
+ class CouchbaseError < StandardError
21
+ # @return [Hash] attributes associated with the error
22
+ attr_reader :context
23
+
24
+ def to_s
25
+ defined?(@context) ? "#{super}, context=#{JSON.generate(@context)}" : super
26
+ end
27
+ end
28
+
29
+ class InvalidArgument < ArgumentError
30
+ # @return [Hash] attributes associated with the error
31
+ attr_reader :context
32
+
33
+ def to_s
34
+ defined?(@context) ? "#{super}, context=#{JSON.generate(@context)}" : super
35
+ end
36
+ end
37
+
38
+ # Common exceptions
39
+
40
+ class RequestCanceled < CouchbaseError
41
+ end
42
+
43
+ class ServiceNotAvailable < CouchbaseError
44
+ end
45
+
46
+ # Indicates an operation failed because there has been an internal error in the server.
47
+ class InternalServerFailure < CouchbaseError
48
+ end
49
+
50
+ # Every exception that has to do with authentication problems should either instantiate or subclass from this type.
51
+ class AuthenticationFailure < CouchbaseError
52
+ end
53
+
54
+ class TemporaryFailure < CouchbaseError
55
+ end
56
+
57
+ # Indicates an operation failed because parsing of the input returned with an error.
58
+ class ParsingFailure < CouchbaseError
59
+ end
60
+
61
+ # Indicates an optimistic locking failure.
62
+ #
63
+ # The operation failed because the specified compare and swap (CAS) value differs from the document's actual CAS
64
+ # value. This means the document was modified since the original CAS value was acquired.
65
+ #
66
+ # The application should usually respond by fetching a fresh version of the document and repeating the failed
67
+ # operation.
68
+ class CasMismatch < CouchbaseError
69
+ end
70
+
71
+ class BucketNotFound < CouchbaseError
72
+ end
73
+
74
+ class CollectionNotFound < CouchbaseError
75
+ end
76
+
77
+ class ScopeNotFound < CouchbaseError
78
+ end
79
+
80
+ class IndexNotFound < CouchbaseError
81
+ end
82
+
83
+ class IndexExists < CouchbaseError
84
+ end
85
+
86
+ # Raised when provided content could not be successfully encoded.
87
+ class EncodingFailure < CouchbaseError
88
+ end
89
+
90
+ # Raised when provided content could not be successfully decoded.
91
+ class DecodingFailure < CouchbaseError
92
+ end
93
+
94
+ class UnsupportedOperation < CouchbaseError
95
+ end
96
+
97
+ # The {Timeout} signals that an operation timed out before it could be completed.
98
+ #
99
+ # It is important to understand that the timeout itself is always just the effect an underlying cause, never the
100
+ # issue itself. The root cause might not even be on the application side, also the network and server need to be
101
+ # taken into account.
102
+ #
103
+ # Right now the SDK can throw two different implementations of this class:
104
+ #
105
+ # {AmbiguousTimeout}::
106
+ # The operation might have caused a side effect on the server and should not be retried without
107
+ # actions and checks.
108
+ #
109
+ # {UnambiguousTimeout}::
110
+ # The operation has not caused a side effect on the server and is safe to retry. This is always the case for
111
+ # idempotent operations. For non-idempotent operations it depends on the state the operation was in at the time of
112
+ # cancellation.
113
+ class Timeout < CouchbaseError
114
+ end
115
+
116
+ # This is a special case of the timeout exception, signaling that the timeout happened with an ambiguous cause.
117
+ class AmbiguousTimeout < Timeout
118
+ end
119
+
120
+ # This is a special case of the timeout exception, signaling that the timeout happened with no ambiguous cause.
121
+ class UnambiguousTimeout < Timeout
122
+ end
123
+
124
+ # Exception which states that the feature is not available.
125
+ class FeatureNotAvailable < CouchbaseError
126
+ end
127
+
128
+ # KeyValue exceptions
129
+
130
+ # Indicates an operation failed because the key does not exist.
131
+ class DocumentNotFound < CouchbaseError
132
+ end
133
+
134
+ # Indicates an operation completed but no successful document was retrievable.
135
+ class DocumentIrretrievable < CouchbaseError
136
+ end
137
+
138
+ # Thrown when the server reports a temporary failure that is very likely to be lock-related (like an already locked
139
+ # key or a bad cas used for unlock).
140
+ #
141
+ # See https://issues.couchbase.com/browse/MB-13087 for an explanation of why this is only _likely_ to be
142
+ # lock-related.
143
+ class DocumentLocked < CouchbaseError
144
+ end
145
+
146
+ # Thrown when the request is too big for some reason.
147
+ class ValueTooLarge < CouchbaseError
148
+ end
149
+
150
+ # Indicates an operation failed because the key already exists.
151
+ class DocumentExists < CouchbaseError
152
+ end
153
+
154
+ # This exception is raised when a durability level has been requested that is not available on the server.
155
+ class DurabilityLevelNotAvailable < CouchbaseError
156
+ end
157
+
158
+ # The given durability requirements are currently impossible to achieve, as not enough configured replicas are
159
+ # currently available.
160
+ class DurabilityImpossible < CouchbaseError
161
+ end
162
+
163
+ # The synchronous replication durability work can return an ambiguous error (or we timeout waiting for the response,
164
+ # which is effectively the same). Here we know the change is on a majority of replicas, or it's on none.
165
+ class DurabilityAmbiguous < CouchbaseError
166
+ end
167
+
168
+ # Returned if an attempt is made to mutate a key which already has a durable write pending.
169
+ class DurableWriteInProgress < CouchbaseError
170
+ end
171
+
172
+ # The requested key has a SyncWrite which is being re-committed.
173
+ class DurableWriteReCommitInProgress < CouchbaseError
174
+ end
175
+
176
+ # Subdocument exception thrown when a path does not exist in the document. The exact meaning of path existence
177
+ # depends on the operation and inputs.
178
+ class PathNotFound < CouchbaseError
179
+ end
180
+
181
+ # Subdocument exception thrown when the path structure conflicts with the document structure (for example, if a
182
+ # path mentions foo.bar[0].baz, but foo.bar is actually a JSON object).
183
+ class PathMismatch < CouchbaseError
184
+ end
185
+
186
+ # Subdocument exception thrown when path has a syntax error, or path syntax is incorrect for the operation (for
187
+ # example, if operation requires an array index).
188
+ class PathInvalid < CouchbaseError
189
+ end
190
+
191
+ # Subdocument exception thrown when path is too deep to parse. Depth of a path is determined by how many components
192
+ # (or levels) it contains.
193
+ #
194
+ # The current limitation is there to ensure a single parse does not consume too much memory (overloading the
195
+ # server). This error is similar to other TooDeep errors, which all relate to various validation stages to ensure
196
+ # the server does not consume too much memory when parsing a single document.
197
+ class PathTooDeep < CouchbaseError
198
+ end
199
+
200
+ class PathTooBig < CouchbaseError
201
+ end
202
+
203
+ # Subdocument exception thrown when proposed value would make the document too deep to parse.
204
+ #
205
+ # The current limitation is there to ensure a single parse does not consume too much memory (overloading the
206
+ # server). This error is similar to other TooDeep errors, which all relate to various validation stages to ensure
207
+ # the server does not consume too much memory when parsing a single document.
208
+ class ValueTooDeep < CouchbaseError
209
+ end
210
+
211
+ # Subdocument exception thrown when the provided value cannot be inserted at the given path.
212
+ #
213
+ # It is actually thrown when the delta in an counter operation is valid, but applying that delta would
214
+ # result in an out-of-range number (server interprets numbers as 64-bit integers).
215
+ class ValueInvalid < CouchbaseError
216
+ end
217
+
218
+ # Subdocument exception thrown when the targeted enclosing document itself is not JSON.
219
+ class DocumentNotJson < CouchbaseError
220
+ end
221
+
222
+ # Subdocument exception thrown when existing number value in document is too big.
223
+ #
224
+ # The value is interpreted as 64 bit on the server side.
225
+ class NumberTooBig < CouchbaseError
226
+ end
227
+
228
+ # Subdocument exception thrown when the delta in an arithmetic operation (eg counter) is invalid. In this SDK, this
229
+ # is equivalent to saying that the delta is zero.
230
+ #
231
+ # Note that the server also returns the corresponding error code when the delta value itself is too big, or not a
232
+ # number, but since the SDK enforces deltas to be of type long, these cases shouldn't come up.
233
+ class DeltaInvalid < CouchbaseError
234
+ end
235
+
236
+ # Subdocument exception thrown when a path already exists and it shouldn't
237
+ class PathExists < CouchbaseError
238
+ end
239
+
240
+ # Subdocument exception thrown when a macro has been requested which is not recognised by the server.
241
+ class XattrUnknownMacro < CouchbaseError
242
+ end
243
+
244
+ # Subdocument exception thrown when more than one xattr key has been requested.
245
+ class XattrInvalidKeyCombo < CouchbaseError
246
+ end
247
+
248
+ # Subdocument exception thrown when a virtual attribute has been requested which is not recognised by the server.
249
+ class XattrUnknownVirtualAttribute < CouchbaseError
250
+ end
251
+
252
+ # Subdocument exception thrown when the virtual attribute cannot be modified.
253
+ class XattrCannotModifyVirtualAttribute < CouchbaseError
254
+ end
255
+
256
+ # Query exceptions
257
+
258
+ # Indicates an operation failed because there has been an issue with the query planner.
259
+ class PlanningFailure < CouchbaseError
260
+ end
261
+
262
+ # Indicates an operation failed because there has been an issue with the query planner or similar.
263
+ class IndexFailure < CouchbaseError
264
+ end
265
+
266
+ # Indicates an operation failed because there has been an issue with query prepared statements.
267
+ class PreparedStatementFailure < CouchbaseError
268
+ end
269
+
270
+ # Analytics exceptions
271
+
272
+ # The analytics query failed to compile.
273
+ class CompilationFailure < CouchbaseError
274
+ end
275
+
276
+ # Indicates the analytics server job queue is full
277
+ class JobQueueFull < CouchbaseError
278
+ end
279
+
280
+ # The queried dataset is not found on the server.
281
+ class DatasetNotFound < CouchbaseError
282
+ end
283
+
284
+ class DatasetExists < CouchbaseError
285
+ end
286
+
287
+ class DataverseExists < CouchbaseError
288
+ end
289
+
290
+ class DataverseNotFound < CouchbaseError
291
+ end
292
+
293
+ class LinkNotFound < CouchbaseError
294
+ end
295
+
296
+ class LinkExists < CouchbaseError
297
+ end
298
+
299
+ # Search exceptions
300
+
301
+ class IndexNotReady < CouchbaseError
302
+ end
303
+
304
+ class ConsistencyMismatch < CouchbaseError
305
+ end
306
+
307
+ # View exceptions
308
+
309
+ class DesignDocumentNotFound < CouchbaseError
310
+ end
311
+
312
+ # The queried view is not found on the server
313
+ class ViewNotFound < CouchbaseError
314
+ end
315
+
316
+ # Management exceptions
317
+
318
+ class CollectionExists < CouchbaseError
319
+ end
320
+
321
+ class ScopeExists < CouchbaseError
322
+ end
323
+
324
+ class UserExists < CouchbaseError
325
+ end
326
+
327
+ class BucketExists < CouchbaseError
328
+ end
329
+
330
+ class BucketNotFlushable < CouchbaseError
331
+ end
332
+
333
+ class GroupNotFound < CouchbaseError
334
+ end
335
+
336
+ class UserNotFound < CouchbaseError
337
+ end
338
+
339
+ # Library-specific exceptions
340
+
341
+ class BackendError < CouchbaseError
342
+ end
343
+
344
+ # Environment name string cannot be determined
345
+ class NoEnvironment < CouchbaseError
346
+ end
347
+
348
+ class ClusterClosed < CouchbaseError
349
+ end
350
+ end
351
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright 2020-2021 Couchbase, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "json"
16
+
17
+ module Couchbase
18
+ class JsonTranscoder
19
+ # @param [Object] document
20
+ # @return [Array<String, Integer>] pair of encoded document and flags
21
+ def encode(document)
22
+ [JSON.generate(document), (0x02 << 24) | 0x06]
23
+ end
24
+
25
+ # @param [String, nil] blob string of bytes, containing encoded representation of the document
26
+ # @param [Integer, :json] _flags bit field, describing how the data encoded
27
+ # @return Object decoded document
28
+ def decode(blob, _flags)
29
+ JSON.parse(blob) unless blob&.empty?
30
+ end
31
+ end
32
+ end
Binary file
@@ -0,0 +1,85 @@
1
+ # Copyright 2020-Present Couchbase, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "logger"
16
+
17
+ module Couchbase
18
+ # Set log level
19
+ #
20
+ # @note The level might be also be set with environment variable +COUCHBASE_BACKEND_LOG_LEVEL+
21
+ #
22
+ # @param [Symbol] level new log level.
23
+ #
24
+ # Allowed levels (in order of decreasing verbosity):
25
+ # * +:trace+
26
+ # * +:debug+
27
+ # * +:info+ (default)
28
+ # * +:warn+
29
+ # * +:error+
30
+ # * +:critical+
31
+ # * +:off+
32
+ #
33
+ # @return [void]
34
+ def self.log_level=(level)
35
+ Backend.set_log_level(level)
36
+ end
37
+
38
+ # Get current log level
39
+ #
40
+ # @return [Symbol] current log level
41
+ def self.log_level
42
+ Backend.get_log_level
43
+ end
44
+
45
+ # Return logger associated with the library
46
+ def self.logger
47
+ @logger # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
48
+ end
49
+
50
+ # Associate logger with the library
51
+ #
52
+ # The log messages, that are generated by extension might come with out of order timestamps, in order to reduce number
53
+ # of switches between Ruby and Native code.
54
+ #
55
+ # @param [Logger] logger an object implementing logging interface, e.g. stdlib Logger, or something that responds to
56
+ # "level"-methods like +#debug+, +#error+, etc.
57
+ # @param [Class] adapter_class custom implementation of the logger adapter interface between extension and ruby code.
58
+ # See {Utils::StdlibLoggerAdapter} and {Utils::GenericLoggerAdapter}
59
+ # @param [Boolean] verbose if true, the message will also include source code location, where the message was
60
+ # generated (if available)
61
+ # @param [Symbol] level log level, see {::log_level=} for allowed values
62
+ #
63
+ # @example Specify custom logger and limit core messages to debug level
64
+ # Couchbase.set_logger(Logger.new(STDERR), level: :debug)
65
+ #
66
+ # @since 3.4.0
67
+ def self.set_logger(logger, adapter_class: nil, verbose: false, level: :info)
68
+ @logger = logger # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
69
+ if @logger.nil? # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
70
+ Backend.install_logger_shim(nil)
71
+ return
72
+ end
73
+ shim =
74
+ if adapter_class
75
+ adapter_class
76
+ elsif logger.is_a?(::Logger)
77
+ require "couchbase/utils/stdlib_logger_adapter"
78
+ Utils::StdlibLoggerAdapter
79
+ else
80
+ require "couchbase/utils/generic_logger_adapter"
81
+ Utils::GenericLoggerAdapter
82
+ end
83
+ Backend.install_logger_shim(shim.new(logger, verbose: verbose), level)
84
+ end
85
+ end