couchbase 3.5.0-arm64-darwin-23

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,133 @@
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
+ # frozen_string_literal: true
16
+
17
+ require "couchbase/protostellar/generated/query/v1/query_pb"
18
+ require 'couchbase/protostellar/generated/kv/v1/kv_pb'
19
+ require "couchbase/protostellar/request"
20
+
21
+ require "google/protobuf/well_known_types"
22
+
23
+ module Couchbase
24
+ module Protostellar
25
+ module RequestGenerator
26
+ class Query
27
+ SCAN_CONSISTENCY_MAP = {
28
+ :not_bounded => :SCAN_CONSISTENCY_NOT_BOUNDED,
29
+ :request_plus => :SCAN_CONSISTENCY_REQUEST_PLUS,
30
+ }.freeze
31
+
32
+ PROFILE_MODE_MAP = {
33
+ :off => :PROFILE_MODE_OFF,
34
+ :phases => :PROFILE_MODE_PHASES,
35
+ :timings => :PROFILE_MODE_TIMINGS,
36
+ }.freeze
37
+
38
+ attr_reader :bucket_name
39
+ attr_reader :scope_name
40
+
41
+ def initialize(bucket_name: nil, scope_name: nil)
42
+ @bucket_name = bucket_name
43
+ @scope_name = scope_name
44
+ end
45
+
46
+ def query_request(statement, options)
47
+ proto_opts = {}
48
+
49
+ bucket_name = @bucket_name
50
+ scope_name = @scope_name
51
+ unless options.scope_qualifier.nil?
52
+ if options.scope_qualifier.include? ":"
53
+ bucket_name, scope_name = options.scope_qualifier.split(":")[1].split(".")
54
+ else
55
+ bucket_name, scope_name = options.scope_qualifier.split(".")
56
+ end
57
+ end
58
+ proto_opts[:scope_name] = scope_name unless scope_name.nil?
59
+ proto_opts[:bucket_name] = bucket_name unless bucket_name.nil?
60
+
61
+ proto_opts[:read_only] = options.readonly unless options.readonly.nil?
62
+ proto_opts[:prepared] = !options.adhoc
63
+
64
+ tuning_opts = create_tuning_options(options)
65
+ proto_opts[:tuning_options] = tuning_opts unless tuning_opts.nil?
66
+
67
+ proto_opts[:client_context_id] = options.client_context_id unless options.client_context_id.nil?
68
+ unless options.instance_variable_get(:@scan_consistency).nil?
69
+ proto_opts[:scan_consistency] =
70
+ SCAN_CONSISTENCY_MAP[options.instance_variable_get(:@scan_consistency)]
71
+ end
72
+ proto_opts[:positional_parameters] = options.export_positional_parameters unless options.export_positional_parameters.nil?
73
+ proto_opts[:named_parameters] = options.export_named_parameters unless options.export_named_parameters.nil?
74
+ proto_opts[:flex_index] = options.flex_index unless options.flex_index.nil?
75
+ proto_opts[:preserve_expiry] = options.preserve_expiry unless options.preserve_expiry.nil?
76
+ proto_opts[:consistent_with] = get_consistent_with(options) unless options.mutation_state.nil?
77
+ proto_opts[:profile_mode] = PROFILE_MODE_MAP[options.profile]
78
+
79
+ proto_req = Generated::Query::V1::QueryRequest.new(
80
+ statement: statement,
81
+ **proto_opts
82
+ )
83
+
84
+ create_query_request(proto_req, :query, options, idempotent: options.readonly && true)
85
+ end
86
+
87
+ private
88
+
89
+ def create_query_request(proto_request, rpc, options, idempotent: false)
90
+ Request.new(
91
+ service: :query,
92
+ rpc: rpc,
93
+ proto_request: proto_request,
94
+ timeout: options.timeout,
95
+ idempotent: idempotent
96
+ )
97
+ end
98
+
99
+ def create_tuning_options(options)
100
+ tuning_opts = {}
101
+ tuning_opts[:max_parallelism] = options.max_parallelism unless options.max_parallelism.nil?
102
+ tuning_opts[:pipeline_batch] = options.pipeline_batch unless options.pipeline_batch.nil?
103
+ tuning_opts[:pipeline_cap] = options.pipeline_cap unless options.pipeline_cap.nil?
104
+ unless options.scan_wait.nil?
105
+ duration_millis = Utils::Time.extract_duration(options.scan_wait)
106
+ tuning_opts[:scan_wait] = Google::Protobuf::Duration.new(
107
+ seconds: duration_millis / 1000,
108
+ nanos: (duration_millis % 1000) * (10**6)
109
+ )
110
+ end
111
+ tuning_opts[:scan_cap] = options.scan_cap unless options.scan_cap.nil?
112
+ tuning_opts[:disable_metrics] = options.metrics.nil? || !options.metrics
113
+ if tuning_opts.empty?
114
+ nil
115
+ else
116
+ Generated::Query::V1::QueryRequest::TuningOptions.new(**tuning_opts)
117
+ end
118
+ end
119
+
120
+ def get_consistent_with(options)
121
+ options.mutation_state.tokens.map do |t|
122
+ Generated::KV::V1::MutationToken.new(
123
+ bucket_name: t.bucket_name,
124
+ vbucket_id: t.partition_id,
125
+ vbucket_uuid: t.partition_uuid,
126
+ seq_no: t.sequence_number
127
+ )
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,387 @@
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
+ # frozen_string_literal: true
16
+
17
+ require "google/protobuf/well_known_types"
18
+
19
+ require "couchbase/search_options"
20
+
21
+ require "couchbase/protostellar/generated/search/v1/search_pb"
22
+ require "couchbase/protostellar/request"
23
+
24
+ module Couchbase
25
+ module Protostellar
26
+ module RequestGenerator
27
+ class Search
28
+ HIGHLIGHT_STYLE_MAP = {
29
+ :html => :HIGHLIGHT_STYLE_HTML,
30
+ :ansi => :HIGHLIGHT_STYLE_ANSI,
31
+ nil => :HIGHLIGHT_STYLE_DEFAULT,
32
+ }.freeze
33
+
34
+ MATCH_QUERY_OPERATOR_MAP = {
35
+ :or => :OPERATOR_OR,
36
+ :and => :OPERATOR_AND,
37
+ }.freeze
38
+
39
+ SCAN_CONSISTENCY_MAP = {
40
+ :not_bounded => :SCAN_CONSISTENCY_NOT_BOUNDED,
41
+ }.freeze
42
+
43
+ DEFAULT_LIMIT = 10
44
+ DEFAULT_SKIP = 0
45
+
46
+ def search_query_request(index_name, query, options)
47
+ proto_opts = {
48
+ scan_consistency: SCAN_CONSISTENCY_MAP[options.scan_consistency],
49
+ include_explanation: options.explain,
50
+ highlight_style: HIGHLIGHT_STYLE_MAP[options.highlight_style],
51
+ disable_scoring: options.disable_scoring,
52
+ include_locations: options.include_locations,
53
+ }
54
+
55
+ proto_opts[:highlight_fields] = options.highlight_fields unless options.highlight_fields.nil?
56
+ proto_opts[:fields] = options.fields unless options.fields.nil?
57
+ proto_opts[:sort] = get_sort(options) unless options.sort.nil?
58
+ proto_opts[:limit] = options.limit || DEFAULT_LIMIT
59
+ proto_opts[:skip] = options.skip || DEFAULT_SKIP
60
+ proto_opts[:collections] = options.collections unless options.collections.nil?
61
+
62
+ proto_req = Generated::Search::V1::SearchQueryRequest.new(
63
+ query: create_query(query),
64
+ index_name: index_name,
65
+ **proto_opts
66
+ )
67
+
68
+ # Set the search facets in the request
69
+ get_facets(options).each do |key, facet|
70
+ proto_req.facets[key] = facet
71
+ end
72
+
73
+ create_search_request(proto_req, :search_query, options)
74
+ end
75
+
76
+ private
77
+
78
+ def create_search_request(proto_request, rpc, options, idempotent: false)
79
+ Request.new(
80
+ service: :search,
81
+ rpc: rpc,
82
+ proto_request: proto_request,
83
+ timeout: options.timeout,
84
+ idempotent: idempotent
85
+ )
86
+ end
87
+
88
+ def create_query(query)
89
+ sq = Couchbase::Cluster::SearchQuery
90
+ res = Generated::Search::V1::Query.new
91
+
92
+ case query
93
+ when sq::BooleanFieldQuery
94
+ res.boolean_field_query = create_boolean_field_query(query)
95
+ when sq::BooleanQuery
96
+ res.boolean_query = create_boolean_query(query)
97
+ when sq::ConjunctionQuery
98
+ res.conjunction_query = create_conjunction_query(query)
99
+ when sq::DateRangeQuery
100
+ res.date_range_query = create_date_range_query(query)
101
+ when sq::DisjunctionQuery
102
+ res.disjunction_query = create_disjunction_query(query)
103
+ when sq::DocIdQuery
104
+ res.doc_id_query = create_doc_id_query(query)
105
+ when sq::GeoBoundingBoxQuery
106
+ res.geo_bounding_box_query = create_geo_bounding_box_query(query)
107
+ when sq::GeoDistanceQuery
108
+ res.geo_distance_query = create_geo_distance_query(query)
109
+ when sq::GeoPolygonQuery
110
+ res.geo_polygon_query = create_geo_polygon_query(query)
111
+ when sq::MatchAllQuery
112
+ res.match_all_query = create_match_all_query(query)
113
+ when sq::MatchNoneQuery
114
+ res.match_none_query = create_match_none_query(query)
115
+ when sq::MatchPhraseQuery
116
+ res.match_phrase_query = create_match_phrase_query(query)
117
+ when sq::MatchQuery
118
+ res.match_query = create_match_query(query)
119
+ when sq::NumericRangeQuery
120
+ res.numeric_range_query = create_numeric_range_query(query)
121
+ when sq::PhraseQuery
122
+ res.phrase_query = create_phrase_query(query)
123
+ when sq::PrefixQuery
124
+ res.prefix_query = create_prefix_query(query)
125
+ when sq::QueryStringQuery
126
+ res.query_string_query = create_query_string_query(query)
127
+ when sq::RegexpQuery
128
+ res.regexp_query = create_regexp_query(query)
129
+ when sq::TermQuery
130
+ res.term_query = create_term_query(query)
131
+ when sq::TermRangeQuery
132
+ res.term_range_query = create_term_range_query(query)
133
+ when sq::WildcardQuery
134
+ res.wildcard_query = create_wildcard_query(query)
135
+ else
136
+ raise Couchbase::Error::CouchbaseError, "Unexpected search query type #{query.class}"
137
+ end
138
+ res
139
+ end
140
+
141
+ def create_boolean_field_query(query)
142
+ query_attrs = query.to_h
143
+ query_attrs[:value] = query_attrs.delete(:bool)
144
+
145
+ Generated::Search::V1::BooleanFieldQuery.new(query_attrs)
146
+ end
147
+
148
+ def create_boolean_query(query)
149
+ query_attrs = {
150
+ boost: query.boost,
151
+ must: create_conjunction_query(query.instance_variable_get(:@must)),
152
+ must_not: create_disjunction_query(query.instance_variable_get(:@must_not)),
153
+ should: create_disjunction_query(query.instance_variable_get(:@should)),
154
+ }
155
+ Generated::Search::V1::BooleanQuery.new(query_attrs)
156
+ end
157
+
158
+ def create_conjunction_query(query)
159
+ query_attrs = {
160
+ boost: query.boost,
161
+ queries: query.instance_variable_get(:@queries).uniq.map(&:create_query),
162
+ }
163
+ Generated::Search::V1::ConjunctionQuery.new(query_attrs)
164
+ end
165
+
166
+ def create_date_range_query(query)
167
+ query_attrs = query.to_h
168
+ query_attrs[:start_date] = query_attrs.delete(:start)
169
+ query_attrs[:end_date] = query_attrs.delete(:end)
170
+
171
+ Generated::Search::V1::DateRangeQuery.new(query_attrs)
172
+ end
173
+
174
+ def create_disjunction_query(query)
175
+ query_attrs = {
176
+ boost: query.boost,
177
+ queries: query.instance_variable_get(:@queries).uniq.map(&:create_query),
178
+ minimum: query.min,
179
+ }
180
+ Generated::Search::V1::DisjunctionQuery.new(query_attrs)
181
+ end
182
+
183
+ def create_doc_id_query(query)
184
+ Generated::Search::V1::DocIdQuery.new(query.to_h)
185
+ end
186
+
187
+ def create_geo_bounding_box_query(query)
188
+ query_attrs = query.to_h
189
+ query_attrs[:top_left] = Generated::Search::V1::LatLng.new(
190
+ longitude: query_attrs[:top_left][0],
191
+ latitude: query_attrs[:top_left][1]
192
+ )
193
+ query_attrs[:bottom_right] = Generated::Search::V1::LatLng.new(
194
+ longitude: query_attrs[:bottom_right][0],
195
+ latitude: query_attrs[:bottom_right][1]
196
+ )
197
+ Generated::Search::V1::GeoBoundingBoxQuery.new(query_attrs)
198
+ end
199
+
200
+ def create_geo_distance_query(query)
201
+ query_attrs = query.to_h
202
+ longitude, latitude = query_attrs.delete(:location)
203
+ query_attrs[:center] = Generated::Search::V1::LatLng.new(
204
+ longitude: longitude,
205
+ latitude: latitude
206
+ )
207
+ Generated::Search::V1::GeoDistanceQuery.new(query_attrs)
208
+ end
209
+
210
+ def create_geo_polygon_query(query)
211
+ query_attrs = query.to_h
212
+ polygon_points = query_attrs.delete(:polygon_points)
213
+ query_attrs[:vertices] = polygon_points.map do |lon, lat|
214
+ Generated::Search::V1::LatLng.new(
215
+ longitude: lon,
216
+ latitude: lat
217
+ )
218
+ end
219
+ Generated::Search::V1::GeoPolygonQuery.new(query_attrs)
220
+ end
221
+
222
+ def create_match_all_query(_query)
223
+ Generated::Search::V1::MatchAllQuery.new
224
+ end
225
+
226
+ def create_match_none_query(_query)
227
+ Generated::Search::V1::MatchNoneQuery.new
228
+ end
229
+
230
+ def create_match_phrase_query(query)
231
+ query_attrs = query.to_h
232
+ query_attrs[:phrase] = query_attrs.delete(:match_phrase)
233
+
234
+ Generated::Search::V1::MatchPhraseQuery.new(query_attrs)
235
+ end
236
+
237
+ def create_match_query(query)
238
+ query_attrs = query.to_h
239
+ query_attrs[:value] = query_attrs.delete(:match)
240
+ query_attrs[:operator] = MATCH_QUERY_OPERATOR_MAP[query_attrs[:operator]] if query_attrs.include?(:operator)
241
+
242
+ Generated::Search::V1::MatchQuery.new(query_attrs)
243
+ end
244
+
245
+ def create_numeric_range_query(query)
246
+ Generated::Search::V1::NumericRangeQuery.new(query.to_h)
247
+ end
248
+
249
+ def create_phrase_query(query)
250
+ Generated::Search::V1::PhraseQuery.new(query.to_h)
251
+ end
252
+
253
+ def create_prefix_query(query)
254
+ Generated::Search::V1::PrefixQuery.new(query.to_h)
255
+ end
256
+
257
+ def create_query_string_query(query)
258
+ query_attrs = query.to_h
259
+ query_attrs[:query_string] = query_attrs.delete(:query)
260
+
261
+ Generated::Search::V1::QueryStringQuery.new(query_attrs)
262
+ end
263
+
264
+ def create_regexp_query(query)
265
+ Generated::Search::V1::RegexpQuery.new(query.to_h)
266
+ end
267
+
268
+ def create_term_query(query)
269
+ Generated::Search::V1::TermQuery.new(query.to_h)
270
+ end
271
+
272
+ def create_term_range_query(query)
273
+ Generated::Search::V1::TermRangeQuery.new(query.to_h)
274
+ end
275
+
276
+ def create_wildcard_query(query)
277
+ Generated::Search::V1::WildcardQuery.new(query.to_h)
278
+ end
279
+
280
+ def get_sort(options)
281
+ options.sort.map do |s|
282
+ case s
283
+ when Couchbase::Cluster::SearchSort::SearchSortField
284
+ # TODO: missing, type and mode could change to Enums
285
+ Generated::Search::V1::Sorting.new(
286
+ field_sorting: Generated::Search::V1::FieldSorting.new(
287
+ field: s.field,
288
+ descending: s.desc,
289
+ missing: s.missing.to_s,
290
+ mode: s.mode.to_s,
291
+ type: s.type.to_s
292
+ )
293
+ )
294
+ when Couchbase::Cluster::SearchSort::SearchSortId
295
+ Generated::Search::V1::Sorting.new(
296
+ id_sorting: Generated::Search::V1::IdSorting.new(
297
+ descending: s.desc
298
+ )
299
+ )
300
+ when Couchbase::Cluster::SearchSort::SearchSortScore
301
+ Generated::Search::V1::Sorting.new(
302
+ score_sorting: Generated::Search::V1::ScoreSorting.new(
303
+ descending: s.desc
304
+ )
305
+ )
306
+ when Couchbase::Cluster::SearchSort::SearchSortGeoDistance
307
+ Generated::Search::V1::Sorting.new(
308
+ geo_distance_sorting: Generated::Search::V1::GeoDistanceSorting.new(
309
+ field: s.field,
310
+ descending: s.desc,
311
+ center: Generated::Search::V1::LatLng.new(
312
+ latitude: s.latitude,
313
+ longitude: s.longitude
314
+ ),
315
+ unit: s.unit.to_s
316
+ )
317
+ )
318
+ when String
319
+ if s[0] == "-"
320
+ desc = true
321
+ field = s[1..]
322
+ else
323
+ desc = false
324
+ field = s
325
+ end
326
+ if field == "_score"
327
+ Generated::Search::V1::Sorting.new(
328
+ score_sorting: Generated::Search::V1::ScoreSorting.new(
329
+ descending: desc
330
+ )
331
+ )
332
+ else
333
+ Generated::Search::V1::Sorting.new(
334
+ # TODO: What to do with the rest of the FieldSorting attributes?
335
+ core_sorting: Generated::Search::V1::FieldSorting.new(
336
+ field: field,
337
+ descending: desc
338
+ )
339
+ )
340
+ end
341
+ else
342
+ raise Couchbase::Error::CouchbaseError, "Unrecognised search sort type"
343
+ end
344
+ end
345
+ end
346
+
347
+ def get_facets(options)
348
+ return {} if options.facets.nil?
349
+
350
+ options.facets.transform_values do |facet|
351
+ case facet
352
+ when Couchbase::Cluster::SearchFacet::SearchFacetTerm
353
+ Generated::Search::V1::Facet.new(
354
+ term_facet: Generated::Search::V1::TermFacet.new(
355
+ field: facet.field,
356
+ size: facet.size
357
+ )
358
+ )
359
+ when Couchbase::Cluster::SearchFacet::SearchFacetNumericRange
360
+ Generated::Search::V1::Facet.new(
361
+ numeric_range_facet: Generated::Search::V1::NumericRangeFacet.new(
362
+ field: facet.field,
363
+ size: facet.size,
364
+ numeric_ranges: facet.instance_variable_get(:@ranges).map do |r|
365
+ Generated::Search::V1::NumericRange(name: r[:name], min: r[:min], max: r[:max])
366
+ end
367
+ )
368
+ )
369
+ when Couchbase::Cluster::SearchFacet::SearchFacetDateRange
370
+ Generated::Search::V1::Facet.new(
371
+ date_range_facet: Generated::Search::V1::DateRangeFacet.new(
372
+ field: facet.field,
373
+ size: facet.size,
374
+ date_ranges: facet.instance_variable_get(:@ranges).map do |r|
375
+ Generated::Search::V1::DateRange(name: r[:name], start: r[:start], end: r[:end])
376
+ end
377
+ )
378
+ )
379
+ else
380
+ raise Couchbase::Error::CouchbaseError, "Unrecognised search facet type"
381
+ end
382
+ end
383
+ end
384
+ end
385
+ end
386
+ end
387
+ end
@@ -0,0 +1,26 @@
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
+ # frozen_string_literal: true
16
+
17
+ require_relative "request_generator/kv"
18
+ require_relative "request_generator/query"
19
+
20
+ module Couchbase
21
+ module Protostellar
22
+ # @api private
23
+ module RequestGenerator
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,55 @@
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
+ # frozen_string_literal: true
16
+
17
+ require "couchbase/management/bucket_manager"
18
+
19
+ require_relative "../../request_generator/admin/bucket"
20
+
21
+ module Couchbase
22
+ module Protostellar
23
+ module ResponseConverter
24
+ module Admin
25
+ class Bucket
26
+ BUCKET_TYPE_MAP = RequestGenerator::Admin::Bucket::BUCKET_TYPE_MAP.invert.freeze
27
+ EVICTION_MODE_MAP = RequestGenerator::Admin::Bucket::EVICTION_MODE_MAP.invert.freeze
28
+ COMPRESSION_MODE_MAP = RequestGenerator::Admin::Bucket::COMPRESSION_MODE_MAP.invert.freeze
29
+ STORAGE_BACKEND_MAP = RequestGenerator::Admin::Bucket::STORAGE_BACKEND_MAP.invert.freeze
30
+ CONFLICT_RESOLUTION_TYPE_MAP = RequestGenerator::Admin::Bucket::CONFLICT_RESOLUTION_TYPE_MAP.invert.freeze
31
+ DURABILITY_LEVEL_MAP = RequestGenerator::Admin::Bucket::DURABILITY_LEVEL_MAP.invert.freeze
32
+
33
+ def self.to_bucket_settings_array(resp)
34
+ resp.buckets.map do |r|
35
+ Couchbase::Management::BucketSettings.new do |b|
36
+ b.name = r.bucket_name
37
+ b.flush_enabled = r.flush_enabled
38
+ b.ram_quota_mb = r.ram_quota_mb
39
+ b.num_replicas = r.num_replicas
40
+ b.replica_indexes = r.replica_indexes
41
+ b.bucket_type = BUCKET_TYPE_MAP[r.bucket_type]
42
+ b.max_expiry = r.max_expiry_secs
43
+ b.eviction_policy = EVICTION_MODE_MAP[r.eviction_mode]
44
+ b.minimum_durability_level = DURABILITY_LEVEL_MAP[r.minimum_durability_level]
45
+ b.compression_mode = COMPRESSION_MODE_MAP[r.compression_mode]
46
+ b.conflict_resolution_type = CONFLICT_RESOLUTION_TYPE_MAP[r.conflict_resolution_type]
47
+ b.storage_backend = STORAGE_BACKEND_MAP[r.storage_backend]
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,42 @@
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
+ # frozen_string_literal: true
16
+
17
+ require "couchbase/management/collection_manager"
18
+
19
+ module Couchbase
20
+ module Protostellar
21
+ module ResponseConverter
22
+ module Admin
23
+ class Collection
24
+ def self.to_scope_spec_array(resp)
25
+ resp.scopes.map do |s|
26
+ Couchbase::Management::ScopeSpec.new do |scope_spec|
27
+ scope_spec.name = s.name
28
+ scope_spec.collections = s.collections.map do |c|
29
+ Couchbase::Management::CollectionSpec.new do |coll_spec|
30
+ coll_spec.name = c.name
31
+ coll_spec.scope_name = s.name
32
+ coll_spec.max_expiry = c.max_expiry_secs if c.has_max_expiry_secs?
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end