couchbase 3.5.2-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
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,293 @@
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
+ class LookupInSpec
19
+ # Fetches the content from a field (if present) at the given path
20
+ #
21
+ # @param [String, Symbol] path the path identifying where to get the value. When path is a symbol, the library will try to expand it as
22
+ # macro.
23
+ # @return [LookupInSpec]
24
+ def self.get(path)
25
+ case path
26
+ when Symbol
27
+ new(:get, expand_macro(path))
28
+ when ""
29
+ new(:get_doc, "")
30
+ else
31
+ new(:get, path)
32
+ end
33
+ end
34
+
35
+ # Checks if a value at the given path exists in the document
36
+ #
37
+ # @param [String] path the path to check if the field exists
38
+ # @return [LookupInSpec]
39
+ def self.exists(path)
40
+ new(:exists, path)
41
+ end
42
+
43
+ # Counts the number of values at a given path in the document
44
+ #
45
+ # @param [String] path the path identifying where to count the values
46
+ # @return [LookupInSpec]
47
+ def self.count(path)
48
+ new(:count, path)
49
+ end
50
+
51
+ def xattr
52
+ @xattr = true
53
+ self
54
+ end
55
+
56
+ def xattr?
57
+ @xattr
58
+ end
59
+
60
+ attr_reader :type
61
+ attr_reader :path
62
+
63
+ # @api private
64
+ #
65
+ # @param [Symbol] macro
66
+ # @raise [Error::XattrUnknownMacro] if the macro cannot be expanded
67
+ def self.expand_macro(macro)
68
+ case macro
69
+ when :document
70
+ "$document"
71
+ when :expiry_time, :expiration_time
72
+ "$document.exptime"
73
+ when :cas
74
+ "$document.CAS"
75
+ when :seq_no, :sequence_number
76
+ "$document.seqno"
77
+ when :last_modified
78
+ "$document.last_modified"
79
+ when :is_deleted
80
+ "$document.deleted"
81
+ when :value_size_bytes
82
+ "$document.value_bytes"
83
+ when :rev_id, :revision_id
84
+ "$document.revid"
85
+ else
86
+ raise Error::XattrUnknownMacro, "unknown macro #{macro}"
87
+ end
88
+ end
89
+
90
+ private_class_method :expand_macro
91
+
92
+ private
93
+
94
+ # @param [:get_doc, :get, :exists, :count] type of the lookup
95
+ # @param [String] path
96
+ def initialize(type, path)
97
+ @xattr = false
98
+ @type = type
99
+ @path = path
100
+ end
101
+ end
102
+
103
+ class MutateInSpec
104
+ # Creates a command with the intention of replacing an existing value in a JSON document.
105
+ #
106
+ # If the path is empty (""), then the value will be used for the document's full body. Will
107
+ # error if the last element of the path does not exist.
108
+ #
109
+ # @param [String] path the path identifying where to replace the value.
110
+ # @param [Object, Symbol] value the value to replace with.
111
+ # When symbol specified and it is matches to known macro, it will be expanded
112
+ #
113
+ # @return [MutateInSpec]
114
+ def self.replace(path, value)
115
+ new(path.empty? ? :set_doc : :replace, path, value)
116
+ end
117
+
118
+ # Creates a command with the intention of inserting a new value in a JSON object.
119
+ #
120
+ # Will error if the last element of the path already exists.
121
+ #
122
+ # @param [String] path the path identifying where to insert the value.
123
+ # @param [Object, Symbol] value the value to insert.
124
+ # When symbol specified and it is matches to known macro, it will be expanded
125
+ #
126
+ # @return [MutateInSpec]
127
+ def self.insert(path, value)
128
+ new(:dict_add, path, value)
129
+ end
130
+
131
+ # Creates a command with the intention of removing an existing value in a JSON object.
132
+ #
133
+ # Will error if the path does not exist.
134
+ #
135
+ # @param path the path identifying what to remove.
136
+ #
137
+ # @return [MutateInSpec]
138
+ def self.remove(path)
139
+ new(path.empty? ? :remove_doc : :remove, path, nil)
140
+ end
141
+
142
+ # Creates a command with the intention of upserting a value in a JSON object.
143
+ #
144
+ # That is, the value will be replaced if the path already exists, or inserted if not.
145
+ #
146
+ # @param [String] path the path identifying where to upsert the value.
147
+ # @param [Object, Symbol] value the value to upsert.
148
+ # When symbol specified and it is matches to known macro, it will be expanded
149
+ #
150
+ # @return [MutateInSpec]
151
+ def self.upsert(path, value)
152
+ new(:dict_upsert, path, value)
153
+ end
154
+
155
+ # Creates a command with the intention of appending a value to an existing JSON array.
156
+ #
157
+ # Will error if the last element of the path does not exist or is not an array.
158
+ #
159
+ # @param [String] path the path identifying an array to which to append the value.
160
+ # @param [Array] values the value(s) to append.
161
+ #
162
+ # @return [MutateInSpec]
163
+ def self.array_append(path, values)
164
+ new(:array_push_last, path, values)
165
+ end
166
+
167
+ # Creates a command with the intention of prepending a value to an existing JSON array.
168
+ #
169
+ # Will error if the last element of the path does not exist or is not an array.
170
+ #
171
+ # @param [String] path the path identifying an array to which to append the value.
172
+ # @param [Array] values the value(s) to prepend.
173
+ #
174
+ # @return [MutateInSpec]
175
+ def self.array_prepend(path, values)
176
+ new(:array_push_first, path, values)
177
+ end
178
+
179
+ # Creates a command with the intention of inserting a value into an existing JSON array.
180
+ #
181
+ # Will error if the last element of the path does not exist or is not an array.
182
+ #
183
+ # @param [String] path the path identifying an array to which to append the value, and an index. E.g. "foo.bar[3]"
184
+ # @param [Array] values the value(s) to insert.
185
+ #
186
+ # @return [MutateInSpec]
187
+ def self.array_insert(path, values)
188
+ new(:array_insert, path, values)
189
+ end
190
+
191
+ # Creates a command with the intent of inserting a value into an existing JSON array, but only if the value
192
+ # is not already contained in the array (by way of string comparison).
193
+ #
194
+ # Will error if the last element of the path does not exist or is not an array.
195
+ #
196
+ # @param [String] path the path identifying an array to which to append the value, and an index. E.g. "foo.bar[3]"
197
+ # @param [Object, Symbol] value the value to insert.
198
+ #
199
+ # @return [MutateInSpec]
200
+ def self.array_add_unique(path, value)
201
+ new(:array_add_unique, path, value)
202
+ end
203
+
204
+ # Creates a command with the intent of incrementing a numerical field in a JSON object.
205
+ #
206
+ # If the field does not exist, then it is created and takes the value of +delta+
207
+ #
208
+ # @param [String] path the path identifying a numerical field to adjust or create
209
+ # @param [Integer] delta the value to increment the field by
210
+ #
211
+ # @return [MutateInSpec]
212
+ def self.increment(path, delta)
213
+ new(:counter, path, delta.abs)
214
+ end
215
+
216
+ # Creates a command with the intent of decrementing a numerical field in a JSON object.
217
+ #
218
+ # If the field does not exist, then it is created and takes the value of +delta+ * -1
219
+ #
220
+ # @param [String] path the path identifying a numerical field to adjust or create
221
+ # @param [Integer] delta the value to decrement the field by
222
+ #
223
+ # @return [MutateInSpec]
224
+ def self.decrement(path, delta)
225
+ new(:counter, path, -1 * delta.abs)
226
+ end
227
+
228
+ def xattr
229
+ @xattr = true
230
+ self
231
+ end
232
+
233
+ def create_path
234
+ @create_path = true
235
+ self
236
+ end
237
+
238
+ def xattr?
239
+ @xattr
240
+ end
241
+
242
+ def create_path?
243
+ @create_path
244
+ end
245
+
246
+ def expand_macros?
247
+ @expand_macros
248
+ end
249
+
250
+ CAS = "${Mutation.CAS}"
251
+ SEQ_NO = "${Mutation.seqno}"
252
+ VALUE_CRC32C = "${Mutation.value_crc32c}"
253
+
254
+ attr_reader :type
255
+ attr_reader :path
256
+ attr_reader :param
257
+
258
+ private
259
+
260
+ def initialize(type, path, param)
261
+ @create_path = false
262
+ @param = nil
263
+ @xattr = false
264
+ @type = type
265
+ @path = path
266
+ @param =
267
+ case param
268
+ when :cas
269
+ CAS
270
+ when :seq_no, :sequence_number
271
+ SEQ_NO
272
+ when :value_crc32c, :value_crc
273
+ VALUE_CRC32C
274
+ else
275
+ param
276
+ end
277
+ # Only set expand_macros when a the value is a symbol that matches one of the macros
278
+ @expand_macros = [:cas, :seq_no, :sequence_number, :value_crc, :value_crc32c].include?(param)
279
+ @xattr = true if @expand_macros
280
+ return if @param.nil?
281
+
282
+ @param =
283
+ case type
284
+ when :counter
285
+ @param.to_i
286
+ when :array_push_first, :array_push_last, :array_insert
287
+ @param.map { |entry| JSON.generate(entry) }.join(",")
288
+ else
289
+ JSON.generate(@param)
290
+ end
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,64 @@
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
+ # @api private
19
+ class TranscoderFlags
20
+ FORMAT_MAP = {
21
+ reserved: 0,
22
+ private: 1,
23
+ json: 2,
24
+ binary: 3,
25
+ string: 4,
26
+ }.freeze
27
+ INV_FORMAT_MAP = FORMAT_MAP.invert.freeze
28
+
29
+ COMPRESSION_MAP = {none: 0}.freeze
30
+ INV_COMPRESSION_MAP = COMPRESSION_MAP.invert
31
+
32
+ attr_reader :format
33
+ attr_reader :compression
34
+ attr_reader :lower_bits
35
+
36
+ def initialize(format:, compression: :none, lower_bits: 0)
37
+ @format = format
38
+ @compression = compression
39
+ @lower_bits = lower_bits
40
+ end
41
+
42
+ def self.decode(flags)
43
+ return TranscoderFlags.new(format: flags) if flags.is_a?(Symbol)
44
+
45
+ common_flags = flags >> 24
46
+ lower_bits = flags & 0x00ffff
47
+
48
+ return TranscoderFlags.new(format: nil, lower_bits: lower_bits) if common_flags.zero?
49
+
50
+ compression_bits = common_flags >> 5
51
+ format_bits = common_flags & 0x0f
52
+ TranscoderFlags.new(
53
+ format: INV_FORMAT_MAP[format_bits],
54
+ compression: INV_COMPRESSION_MAP[compression_bits],
55
+ lower_bits: lower_bits
56
+ )
57
+ end
58
+
59
+ def encode
60
+ common_flags = (COMPRESSION_MAP[@compression] << 5) | FORMAT_MAP[@format]
61
+ (common_flags << 24) | @lower_bits
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Couchbase, Inc.
4
+ # Copyright 2020-Present Couchbase, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require "time"
19
+
20
+ module Couchbase
21
+ module Utils
22
+ class GenericLoggerAdapter
23
+ DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%6N"
24
+
25
+ def initialize(logger, verbose: false)
26
+ @logger = logger
27
+ @verbose = verbose
28
+ end
29
+
30
+ def log(level, thread_id, seconds, nanoseconds, payload, filename, line, function)
31
+ return unless @logger.respond_to?(level)
32
+
33
+ progname = "cxxcbc##{thread_id}"
34
+ payload += " at #{filename}:#{line} #{function}" if @verbose && filename
35
+ @logger.send(level,
36
+ "[#{::Time.at(seconds, nanoseconds, :nanosecond).strftime(DATETIME_FORMAT)} #{progname}] #{level} -- #{payload}")
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Couchbase, Inc.
4
+ # Copyright 2020-Present Couchbase, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ require "logger"
19
+ require "time"
20
+
21
+ module Couchbase
22
+ module Utils
23
+ class StdlibLoggerAdapter
24
+ def initialize(logger, verbose: false)
25
+ raise ArgumentError, "logger argument must be or derive from stdlib Logger class" unless logger.is_a?(::Logger)
26
+
27
+ @logger = logger
28
+ @verbose = verbose
29
+ end
30
+
31
+ def log(level, thread_id, seconds, nanoseconds, payload, filename, line, function)
32
+ logdev = @logger.instance_variable_get(:@logdev)
33
+ return unless logdev
34
+
35
+ severity = map_spdlog_level(level)
36
+ return unless severity
37
+
38
+ progname = "cxxcbc##{thread_id}"
39
+ payload += " at #{filename}:#{line} #{function}" if @verbose && filename
40
+ logdev.write(
41
+ @logger.send(:format_message, @logger.send(:format_severity, severity), ::Time.at(seconds, nanoseconds, :nanosecond), progname,
42
+ payload)
43
+ )
44
+ end
45
+
46
+ private
47
+
48
+ def map_spdlog_level(level)
49
+ case level
50
+ when :trace, :debug
51
+ ::Logger::Severity::DEBUG
52
+ when :info
53
+ ::Logger::Severity::INFO
54
+ when :warn
55
+ ::Logger::Severity::WARN
56
+ when :error
57
+ ::Logger::Severity::ERROR
58
+ when :critical
59
+ ::Logger::Severity::FATAL
60
+ else # rubocop:disable Style/EmptyElse
61
+ # covers :off
62
+ nil
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,71 @@
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 "time"
18
+
19
+ module Couchbase
20
+ module Utils
21
+ # Various Time utilities
22
+ module Time
23
+ RELATIVE_EXPIRY_CUTOFF_SECONDS = 30 * 24 * 60 * 60
24
+ WORKAROUND_EXPIRY_CUTOFF_SECONDS = 50 * 365 * 24 * 60 * 60
25
+
26
+ module_function
27
+
28
+ # @param [Integer, #in_seconds, Time, nil] time_or_duration expiration time to associate with the document
29
+ def extract_expiry_time(time_or_duration)
30
+ if time_or_duration.respond_to?(:in_seconds) # Duration
31
+ [:duration, time_or_duration.in_seconds]
32
+ elsif time_or_duration.respond_to?(:tv_sec) # Time
33
+ [:time_point, time_or_duration.tv_sec]
34
+ elsif time_or_duration.is_a?(Integer)
35
+ if time_or_duration < RELATIVE_EXPIRY_CUTOFF_SECONDS
36
+ # looks like valid relative duration as specified in protocol (less than 30 days)
37
+ [:duration, time_or_duration]
38
+ elsif time_or_duration > WORKAROUND_EXPIRY_CUTOFF_SECONDS
39
+ effective_expiry = ::Time.at(time_or_duration).utc
40
+ warn "The specified expiry duration #{time_or_duration} is longer than 50 years. For bug-compatibility " \
41
+ "with previous versions of SDK 3.0.x, the number of seconds in the duration will be interpreted as " \
42
+ "the epoch second when the document should expire (#{effective_expiry}). Stuffing an epoch second " \
43
+ "into a Duration is deprecated and will no longer work in SDK 3.1. Consider using Time instance instead."
44
+ [:time_point, time_or_duration]
45
+ else
46
+ [:time_point, ::Time.now.tv_sec + time_or_duration]
47
+ end
48
+ else
49
+ [:duration, time_or_duration]
50
+ end
51
+ end
52
+
53
+ # This method converts its argument to milliseconds
54
+ #
55
+ # 1. Integer values are interpreted as a number of milliseconds
56
+ # 2. If the argument is a Duration-like object and responds to #in_milliseconds,
57
+ # then use it and convert result to Integer
58
+ # 3. Otherwise invoke #to_i on the argument and interpret it as a number of milliseconds
59
+ def extract_duration(number_or_duration)
60
+ return unless number_or_duration
61
+ return number_or_duration if number_or_duration.class == Integer # rubocop:disable Style/ClassEqualityComparison avoid overrides of #is_a?, #kind_of?
62
+
63
+ if number_or_duration.respond_to?(:in_milliseconds)
64
+ number_or_duration.in_milliseconds
65
+ else
66
+ number_or_duration
67
+ end.to_i
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,23 @@
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
+ # Module for internal tools, extensions and utilities
19
+ module Utils
20
+ end
21
+ end
22
+
23
+ require "couchbase/utils/time"
@@ -0,0 +1,25 @@
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
+ # Version of the library and all bundled dependencies
19
+ #
20
+ # @example Display version (+Couchbase::BUILD_INFO+ contains more details)
21
+ # $ ruby -rcouchbase -e 'pp Couchbase::VERSION'
22
+ # {:sdk=>"3.4.0", :ruby_abi=>"3.1.0", :revision=>"416fe68e6029ec8a4c40611cf6e6b30d3b90d20f"}
23
+ VERSION = {} unless defined?(VERSION) # rubocop:disable Style/MutableConstant
24
+ VERSION.update(:sdk => "3.5.2")
25
+ end
@@ -0,0 +1,67 @@
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
+ module Couchbase
20
+ class Bucket
21
+ class ViewRow
22
+ # @return [String]
23
+ attr_accessor :id
24
+
25
+ # @return [#to_json]
26
+ attr_accessor :key
27
+
28
+ # @return [#to_json]
29
+ attr_accessor :value
30
+
31
+ # @yieldparam [ViewRow] self
32
+ def initialize
33
+ yield self if block_given?
34
+ end
35
+ end
36
+
37
+ class ViewMetaData
38
+ # @return [Integer]
39
+ attr_accessor :total_rows
40
+
41
+ # @api private
42
+ attr_writer :debug_info
43
+
44
+ def debug
45
+ JSON.parse(@debug_info)
46
+ end
47
+
48
+ # @yieldparam [ViewMetaData] self
49
+ def initialize
50
+ yield self if block_given?
51
+ end
52
+ end
53
+
54
+ class ViewResult
55
+ # @return [ViewMetaData] returns object representing additional metadata associated with this query
56
+ attr_accessor :meta_data
57
+
58
+ # @return [Array<ViewRow>]
59
+ attr_accessor :rows
60
+
61
+ # @yieldparam [ViewResult] self
62
+ def initialize
63
+ yield self if block_given?
64
+ end
65
+ end
66
+ end
67
+ end
data/lib/couchbase.rb ADDED
@@ -0,0 +1,30 @@
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/version"
18
+ require "couchbase/libcouchbase"
19
+ require "couchbase/logger"
20
+ require "couchbase/cluster"
21
+
22
+ require "couchbase/railtie" if defined?(Rails)
23
+
24
+ # @!macro uncommitted
25
+ # @couchbase.stability
26
+ # Uncommitted: This API may change in the future.
27
+ #
28
+ # @!macro volatile
29
+ # @couchbase.stability
30
+ # Volatile: This API is subject to change at any time.