couchbase 3.5.0-arm64-darwin-22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) 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/3.0/libcouchbase.bundle +0 -0
  7. data/lib/couchbase/3.1/libcouchbase.bundle +0 -0
  8. data/lib/couchbase/3.2/libcouchbase.bundle +0 -0
  9. data/lib/couchbase/3.3/libcouchbase.bundle +0 -0
  10. data/lib/couchbase/analytics_options.rb +107 -0
  11. data/lib/couchbase/authenticator.rb +64 -0
  12. data/lib/couchbase/binary_collection.rb +128 -0
  13. data/lib/couchbase/binary_collection_options.rb +24 -0
  14. data/lib/couchbase/bucket.rb +144 -0
  15. data/lib/couchbase/cluster.rb +460 -0
  16. data/lib/couchbase/cluster_registry.rb +49 -0
  17. data/lib/couchbase/collection.rb +705 -0
  18. data/lib/couchbase/collection_options.rb +399 -0
  19. data/lib/couchbase/config_profiles.rb +55 -0
  20. data/lib/couchbase/configuration.rb +56 -0
  21. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  22. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  23. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  24. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  25. data/lib/couchbase/datastructures.rb +24 -0
  26. data/lib/couchbase/diagnostics.rb +181 -0
  27. data/lib/couchbase/errors.rb +376 -0
  28. data/lib/couchbase/json_transcoder.rb +39 -0
  29. data/lib/couchbase/key_value_scan.rb +117 -0
  30. data/lib/couchbase/libcouchbase.rb +6 -0
  31. data/lib/couchbase/logger.rb +85 -0
  32. data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
  33. data/lib/couchbase/management/bucket_manager.rb +443 -0
  34. data/lib/couchbase/management/collection_manager.rb +470 -0
  35. data/lib/couchbase/management/collection_query_index_manager.rb +222 -0
  36. data/lib/couchbase/management/query_index_manager.rb +617 -0
  37. data/lib/couchbase/management/scope_search_index_manager.rb +198 -0
  38. data/lib/couchbase/management/search_index_manager.rb +424 -0
  39. data/lib/couchbase/management/user_manager.rb +468 -0
  40. data/lib/couchbase/management/view_index_manager.rb +237 -0
  41. data/lib/couchbase/management.rb +29 -0
  42. data/lib/couchbase/mutation_state.rb +63 -0
  43. data/lib/couchbase/options.rb +2837 -0
  44. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  45. data/lib/couchbase/protostellar/bucket.rb +51 -0
  46. data/lib/couchbase/protostellar/client.rb +99 -0
  47. data/lib/couchbase/protostellar/cluster.rb +163 -0
  48. data/lib/couchbase/protostellar/collection.rb +152 -0
  49. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  50. data/lib/couchbase/protostellar/error_handling.rb +203 -0
  51. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +61 -0
  52. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +35 -0
  53. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +57 -0
  54. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +36 -0
  55. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +61 -0
  56. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +37 -0
  57. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +72 -0
  58. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +44 -0
  59. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +52 -0
  60. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +30 -0
  61. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +70 -0
  62. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +36 -0
  63. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +97 -0
  64. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +46 -0
  65. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +57 -0
  66. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +30 -0
  67. data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +52 -0
  68. data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +30 -0
  69. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +99 -0
  70. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +30 -0
  71. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +57 -0
  72. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +36 -0
  73. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +51 -0
  74. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +30 -0
  75. data/lib/couchbase/protostellar/generated.rb +9 -0
  76. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  77. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  78. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  79. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  80. data/lib/couchbase/protostellar/management.rb +24 -0
  81. data/lib/couchbase/protostellar/request.rb +78 -0
  82. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  83. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  84. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +94 -0
  85. data/lib/couchbase/protostellar/request_generator/admin/query.rb +130 -0
  86. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  87. data/lib/couchbase/protostellar/request_generator/kv.rb +474 -0
  88. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  89. data/lib/couchbase/protostellar/request_generator/search.rb +387 -0
  90. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  91. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  92. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  93. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  94. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  95. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  96. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  97. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  98. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  99. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  100. data/lib/couchbase/protostellar/retry/orchestrator.rb +60 -0
  101. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  102. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  103. data/lib/couchbase/protostellar/retry/strategies.rb +26 -0
  104. data/lib/couchbase/protostellar/retry.rb +28 -0
  105. data/lib/couchbase/protostellar/scope.rb +57 -0
  106. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  107. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  108. data/lib/couchbase/protostellar.rb +29 -0
  109. data/lib/couchbase/query_options.rb +120 -0
  110. data/lib/couchbase/railtie.rb +45 -0
  111. data/lib/couchbase/raw_binary_transcoder.rb +37 -0
  112. data/lib/couchbase/raw_json_transcoder.rb +38 -0
  113. data/lib/couchbase/raw_string_transcoder.rb +40 -0
  114. data/lib/couchbase/scope.rb +256 -0
  115. data/lib/couchbase/search_options.rb +1622 -0
  116. data/lib/couchbase/subdoc.rb +290 -0
  117. data/lib/couchbase/transcoder_flags.rb +62 -0
  118. data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
  119. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  120. data/lib/couchbase/utils/time.rb +69 -0
  121. data/lib/couchbase/utils.rb +21 -0
  122. data/lib/couchbase/version.rb +23 -0
  123. data/lib/couchbase/view_options.rb +65 -0
  124. data/lib/couchbase.rb +28 -0
  125. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  126. metadata +191 -0
@@ -0,0 +1,376 @@
1
+ # Copyright 2020-2023 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 initialize(msg = nil, context = nil)
25
+ @context = context unless context.nil?
26
+ super(msg)
27
+ end
28
+
29
+ def to_s
30
+ defined?(@context) ? "#{super}, context=#{JSON.generate(@context)}" : super
31
+ end
32
+ end
33
+
34
+ class InvalidArgument < ArgumentError
35
+ # @return [Hash] attributes associated with the error
36
+ attr_reader :context
37
+
38
+ def initialize(msg = nil, context = nil)
39
+ @context = context unless context.nil?
40
+ super(msg)
41
+ end
42
+
43
+ def to_s
44
+ defined?(@context) ? "#{super}, context=#{JSON.generate(@context)}" : super
45
+ end
46
+ end
47
+
48
+ # Common exceptions
49
+
50
+ class RequestCanceled < CouchbaseError
51
+ end
52
+
53
+ class ServiceNotAvailable < CouchbaseError
54
+ end
55
+
56
+ # Indicates an operation failed because there has been an internal error in the server.
57
+ class InternalServerFailure < CouchbaseError
58
+ end
59
+
60
+ # Every exception that has to do with authentication problems should either instantiate or subclass from this type.
61
+ class AuthenticationFailure < CouchbaseError
62
+ end
63
+
64
+ # Indicates that the user has insufficient permissions to perform the operation
65
+ #
66
+ # @!macro uncommitted
67
+ class PermissionDenied < CouchbaseError
68
+ end
69
+
70
+ class TemporaryFailure < CouchbaseError
71
+ end
72
+
73
+ # Indicates an operation failed because parsing of the input returned with an error.
74
+ class ParsingFailure < CouchbaseError
75
+ end
76
+
77
+ # Indicates an optimistic locking failure.
78
+ #
79
+ # The operation failed because the specified compare and swap (CAS) value differs from the document's actual CAS
80
+ # value. This means the document was modified since the original CAS value was acquired.
81
+ #
82
+ # The application should usually respond by fetching a fresh version of the document and repeating the failed
83
+ # operation.
84
+ class CasMismatch < CouchbaseError
85
+ end
86
+
87
+ class BucketNotFound < CouchbaseError
88
+ end
89
+
90
+ class CollectionNotFound < CouchbaseError
91
+ end
92
+
93
+ class ScopeNotFound < CouchbaseError
94
+ end
95
+
96
+ class IndexNotFound < CouchbaseError
97
+ end
98
+
99
+ class IndexExists < CouchbaseError
100
+ end
101
+
102
+ # Raised when provided content could not be successfully encoded.
103
+ class EncodingFailure < CouchbaseError
104
+ end
105
+
106
+ # Raised when provided content could not be successfully decoded.
107
+ class DecodingFailure < CouchbaseError
108
+ end
109
+
110
+ class UnsupportedOperation < CouchbaseError
111
+ end
112
+
113
+ # The {Timeout} signals that an operation timed out before it could be completed.
114
+ #
115
+ # It is important to understand that the timeout itself is always just the effect an underlying cause, never the
116
+ # issue itself. The root cause might not even be on the application side, also the network and server need to be
117
+ # taken into account.
118
+ #
119
+ # Right now the SDK can throw two different implementations of this class:
120
+ #
121
+ # {AmbiguousTimeout}::
122
+ # The operation might have caused a side effect on the server and should not be retried without
123
+ # actions and checks.
124
+ #
125
+ # {UnambiguousTimeout}::
126
+ # The operation has not caused a side effect on the server and is safe to retry. This is always the case for
127
+ # idempotent operations. For non-idempotent operations it depends on the state the operation was in at the time of
128
+ # cancellation.
129
+ class Timeout < CouchbaseError
130
+ end
131
+
132
+ # This is a special case of the timeout exception, signaling that the timeout happened with an ambiguous cause.
133
+ class AmbiguousTimeout < Timeout
134
+ end
135
+
136
+ # This is a special case of the timeout exception, signaling that the timeout happened with no ambiguous cause.
137
+ class UnambiguousTimeout < Timeout
138
+ end
139
+
140
+ # Exception which states that the feature is not available.
141
+ class FeatureNotAvailable < CouchbaseError
142
+ end
143
+
144
+ # KeyValue exceptions
145
+
146
+ # Indicates an operation failed because the key does not exist.
147
+ class DocumentNotFound < CouchbaseError
148
+ end
149
+
150
+ # Indicates an operation completed but no successful document was retrievable.
151
+ class DocumentIrretrievable < CouchbaseError
152
+ end
153
+
154
+ # Thrown when the server reports a temporary failure that is very likely to be lock-related (like an already locked
155
+ # key or a bad cas used for unlock).
156
+ #
157
+ # See https://issues.couchbase.com/browse/MB-13087 for an explanation of why this is only _likely_ to be
158
+ # lock-related.
159
+ class DocumentLocked < CouchbaseError
160
+ end
161
+
162
+ # Thrown when the server reports that the document is not locked when an unlocking operation is being performed.
163
+ class DocumentNotLocked < CouchbaseError
164
+ end
165
+
166
+ # Thrown when the request is too big for some reason.
167
+ class ValueTooLarge < CouchbaseError
168
+ end
169
+
170
+ # Indicates an operation failed because the key already exists.
171
+ class DocumentExists < CouchbaseError
172
+ end
173
+
174
+ # This exception is raised when a durability level has been requested that is not available on the server.
175
+ class DurabilityLevelNotAvailable < CouchbaseError
176
+ end
177
+
178
+ # The given durability requirements are currently impossible to achieve, as not enough configured replicas are
179
+ # currently available.
180
+ class DurabilityImpossible < CouchbaseError
181
+ end
182
+
183
+ # The synchronous replication durability work can return an ambiguous error (or we timeout waiting for the response,
184
+ # which is effectively the same). Here we know the change is on a majority of replicas, or it's on none.
185
+ class DurabilityAmbiguous < CouchbaseError
186
+ end
187
+
188
+ # Returned if an attempt is made to mutate a key which already has a durable write pending.
189
+ class DurableWriteInProgress < CouchbaseError
190
+ end
191
+
192
+ # The requested key has a SyncWrite which is being re-committed.
193
+ class DurableWriteReCommitInProgress < CouchbaseError
194
+ end
195
+
196
+ # Happens when consistency requirements are specified but the partition uuid of the requirements do not align
197
+ # with the server
198
+ class MutationTokenOutdated < CouchbaseError
199
+ end
200
+
201
+ # Subdocument exception thrown when a path does not exist in the document. The exact meaning of path existence
202
+ # depends on the operation and inputs.
203
+ class PathNotFound < CouchbaseError
204
+ end
205
+
206
+ # Subdocument exception thrown when the path structure conflicts with the document structure (for example, if a
207
+ # path mentions foo.bar[0].baz, but foo.bar is actually a JSON object).
208
+ class PathMismatch < CouchbaseError
209
+ end
210
+
211
+ # Subdocument exception thrown when path has a syntax error, or path syntax is incorrect for the operation (for
212
+ # example, if operation requires an array index).
213
+ class PathInvalid < CouchbaseError
214
+ end
215
+
216
+ # Subdocument exception thrown when path is too deep to parse. Depth of a path is determined by how many components
217
+ # (or levels) it contains.
218
+ #
219
+ # The current limitation is there to ensure a single parse does not consume too much memory (overloading the
220
+ # server). This error is similar to other TooDeep errors, which all relate to various validation stages to ensure
221
+ # the server does not consume too much memory when parsing a single document.
222
+ class PathTooDeep < CouchbaseError
223
+ end
224
+
225
+ class PathTooBig < CouchbaseError
226
+ end
227
+
228
+ # Subdocument exception thrown when proposed value would make the document too deep to parse.
229
+ #
230
+ # The current limitation is there to ensure a single parse does not consume too much memory (overloading the
231
+ # server). This error is similar to other TooDeep errors, which all relate to various validation stages to ensure
232
+ # the server does not consume too much memory when parsing a single document.
233
+ class ValueTooDeep < CouchbaseError
234
+ end
235
+
236
+ # Subdocument exception thrown when the provided value cannot be inserted at the given path.
237
+ #
238
+ # It is actually thrown when the delta in an counter operation is valid, but applying that delta would
239
+ # result in an out-of-range number (server interprets numbers as 64-bit integers).
240
+ class ValueInvalid < CouchbaseError
241
+ end
242
+
243
+ # Subdocument exception thrown when the targeted enclosing document itself is not JSON.
244
+ class DocumentNotJson < CouchbaseError
245
+ end
246
+
247
+ # Subdocument exception thrown when existing number value in document is too big.
248
+ #
249
+ # The value is interpreted as 64 bit on the server side.
250
+ class NumberTooBig < CouchbaseError
251
+ end
252
+
253
+ # Subdocument exception thrown when the delta in an arithmetic operation (eg counter) is invalid. In this SDK, this
254
+ # is equivalent to saying that the delta is zero.
255
+ #
256
+ # Note that the server also returns the corresponding error code when the delta value itself is too big, or not a
257
+ # number, but since the SDK enforces deltas to be of type long, these cases shouldn't come up.
258
+ class DeltaInvalid < CouchbaseError
259
+ end
260
+
261
+ # Subdocument exception thrown when a path already exists and it shouldn't
262
+ class PathExists < CouchbaseError
263
+ end
264
+
265
+ # Subdocument exception thrown when a macro has been requested which is not recognised by the server.
266
+ class XattrUnknownMacro < CouchbaseError
267
+ end
268
+
269
+ # Subdocument exception thrown when more than one xattr key has been requested.
270
+ class XattrInvalidKeyCombo < CouchbaseError
271
+ end
272
+
273
+ # Subdocument exception thrown when a virtual attribute has been requested which is not recognised by the server.
274
+ class XattrUnknownVirtualAttribute < CouchbaseError
275
+ end
276
+
277
+ # Subdocument exception thrown when the virtual attribute cannot be modified.
278
+ class XattrCannotModifyVirtualAttribute < CouchbaseError
279
+ end
280
+
281
+ # Query exceptions
282
+
283
+ # Indicates an operation failed because there has been an issue with the query planner.
284
+ class PlanningFailure < CouchbaseError
285
+ end
286
+
287
+ # Indicates an operation failed because there has been an issue with the query planner or similar.
288
+ class IndexFailure < CouchbaseError
289
+ end
290
+
291
+ # Indicates an operation failed because there has been an issue with query prepared statements.
292
+ class PreparedStatementFailure < CouchbaseError
293
+ end
294
+
295
+ # Analytics exceptions
296
+
297
+ # The analytics query failed to compile.
298
+ class CompilationFailure < CouchbaseError
299
+ end
300
+
301
+ # Indicates the analytics server job queue is full
302
+ class JobQueueFull < CouchbaseError
303
+ end
304
+
305
+ # The queried dataset is not found on the server.
306
+ class DatasetNotFound < CouchbaseError
307
+ end
308
+
309
+ class DatasetExists < CouchbaseError
310
+ end
311
+
312
+ class DataverseExists < CouchbaseError
313
+ end
314
+
315
+ class DataverseNotFound < CouchbaseError
316
+ end
317
+
318
+ class LinkNotFound < CouchbaseError
319
+ end
320
+
321
+ class LinkExists < CouchbaseError
322
+ end
323
+
324
+ # Search exceptions
325
+
326
+ class IndexNotReady < CouchbaseError
327
+ end
328
+
329
+ class ConsistencyMismatch < CouchbaseError
330
+ end
331
+
332
+ # View exceptions
333
+
334
+ class DesignDocumentNotFound < CouchbaseError
335
+ end
336
+
337
+ # The queried view is not found on the server
338
+ class ViewNotFound < CouchbaseError
339
+ end
340
+
341
+ # Management exceptions
342
+
343
+ class CollectionExists < CouchbaseError
344
+ end
345
+
346
+ class ScopeExists < CouchbaseError
347
+ end
348
+
349
+ class UserExists < CouchbaseError
350
+ end
351
+
352
+ class BucketExists < CouchbaseError
353
+ end
354
+
355
+ class BucketNotFlushable < CouchbaseError
356
+ end
357
+
358
+ class GroupNotFound < CouchbaseError
359
+ end
360
+
361
+ class UserNotFound < CouchbaseError
362
+ end
363
+
364
+ # Library-specific exceptions
365
+
366
+ class BackendError < CouchbaseError
367
+ end
368
+
369
+ # Environment name string cannot be determined
370
+ class NoEnvironment < CouchbaseError
371
+ end
372
+
373
+ class ClusterClosed < CouchbaseError
374
+ end
375
+ end
376
+ end
@@ -0,0 +1,39 @@
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
+ require "couchbase/transcoder_flags"
18
+
19
+ module Couchbase
20
+ class JsonTranscoder
21
+ # @param [Object] document
22
+ # @return [Array<String, Integer>] pair of encoded document and flags
23
+ def encode(document)
24
+ raise Error::EncodingFailure, "The JsonTranscoder does not support binary data" if document.is_a?(String) && !document.valid_encoding?
25
+
26
+ [JSON.generate(document), TranscoderFlags.new(format: :json, lower_bits: 6).encode]
27
+ end
28
+
29
+ # @param [String] blob string of bytes, containing encoded representation of the document
30
+ # @param [Integer, :json] flags bit field, describing how the data encoded
31
+ # @return [Object] decoded document
32
+ def decode(blob, flags)
33
+ format = TranscoderFlags.decode(flags).format
34
+ raise Error::DecodingFailure, "Unable to decode #{format} with the JsonTranscoder" unless format == :json || format.nil?
35
+
36
+ JSON.parse(blob) unless blob&.empty?
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,117 @@
1
+ # Copyright 2023. 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
+ module Couchbase
16
+ # A scan term used to specify the bounds of a range scan
17
+ class ScanTerm
18
+ attr_accessor :term # @return [ScanTerm]
19
+ attr_accessor :exclusive # @return [Boolean]
20
+
21
+ # Creates an instance of a ScanTerm
22
+ #
23
+ # @param [String] term the key pattern of this term
24
+ # @param [Boolean] exclusive specifies if this term is excluded while scanning, the bounds are included by default
25
+ def initialize(term, exclusive: false)
26
+ @term = term
27
+ @exclusive = exclusive
28
+ end
29
+
30
+ # @api private
31
+ def to_backend
32
+ {
33
+ term: @term,
34
+ exclusive: @exclusive,
35
+ }
36
+ end
37
+ end
38
+
39
+ # A range scan performs a scan on a range of keys
40
+ class RangeScan
41
+ attr_accessor :from # @return [ScanTerm, nil]
42
+ attr_accessor :to # @return [ScanTerm, nil]
43
+
44
+ # Creates an instance of a RangeScan scan type
45
+ #
46
+ # @param [ScanTerm, String, nil] from the lower bound of the range, if set
47
+ # @param [ScanTerm, String, nil] to the upper bound of the range, if set
48
+ def initialize(from: nil, to: nil)
49
+ @from =
50
+ if from.nil? || from.instance_of?(ScanTerm)
51
+ from
52
+ else
53
+ ScanTerm(from)
54
+ end
55
+ @to =
56
+ if to.nil? || to.instance_of?(ScanTerm)
57
+ to
58
+ else
59
+ ScanTerm(to)
60
+ end
61
+ end
62
+
63
+ # @api private
64
+ def to_backend
65
+ {
66
+ scan_type: :range,
67
+ from: @from&.to_backend,
68
+ to: @to&.to_backend,
69
+ }
70
+ end
71
+ end
72
+
73
+ # A prefix scan performs a scan that includes all documents whose keys start with the given prefix
74
+ class PrefixScan
75
+ attr_accessor :prefix # @return [String]
76
+
77
+ # Creates an instance of a PrefixScan scan type
78
+ #
79
+ # @param [String, nil] prefix the prefix all document keys should start with
80
+ def initialize(prefix)
81
+ @prefix = prefix
82
+ end
83
+
84
+ # @api private
85
+ def to_backend
86
+ {
87
+ scan_type: :prefix,
88
+ prefix: @prefix,
89
+ }
90
+ end
91
+ end
92
+
93
+ # A sampling scan performs a scan that randomly selects documents up to a configured limit
94
+ class SamplingScan
95
+ attr_accessor :limit # @return [Integer]
96
+ attr_accessor :seed # @return [Integer, nil]
97
+
98
+ # Creates an instance of a SamplingScan scan type
99
+ #
100
+ # @param [Integer] limit the maximum number of documents the sampling scan can return
101
+ # @param [Integer, nil] seed the seed used for the random number generator that selects the documents. If not set,
102
+ # a seed is generated at random
103
+ def initialize(limit, seed = nil)
104
+ @limit = limit
105
+ @seed = seed
106
+ end
107
+
108
+ # @api private
109
+ def to_backend
110
+ {
111
+ scan_type: :sampling,
112
+ limit: @limit,
113
+ seed: @seed,
114
+ }
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,6 @@
1
+ begin
2
+ require_relative "#{RUBY_VERSION[/(\d+\.\d+)/]}/libcouchbase"
3
+ rescue LoadError
4
+ raise LoadError, "unable to load couchbase extension for Ruby #{RUBY_VERSION}. Only available for 3.0, 3.1, 3.2, 3.3. " \
5
+ "Try to install couchbase from sources with 'gem install --platform ruby couchbase'"
6
+ end
@@ -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