couchbase 3.5.2-x86_64-darwin

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