couchbase 3.0.3-universal-darwin-20 → 3.1.1-universal-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/ext/CMakeLists.txt +4 -2
  4. data/ext/build_config.hxx.in +1 -1
  5. data/ext/build_version.hxx.in +2 -2
  6. data/ext/couchbase/bucket.hxx +1 -1
  7. data/ext/couchbase/capabilities.hxx +1 -1
  8. data/ext/couchbase/cluster.hxx +1 -1
  9. data/ext/couchbase/cluster_options.hxx +4 -1
  10. data/ext/couchbase/collections_manifest.hxx +1 -1
  11. data/ext/couchbase/configuration.hxx +1 -1
  12. data/ext/couchbase/couchbase.cxx +743 -927
  13. data/ext/couchbase/diagnostics.hxx +3 -3
  14. data/ext/couchbase/document_id.hxx +1 -1
  15. data/ext/couchbase/error_context/analytics.hxx +1 -1
  16. data/ext/couchbase/error_context/http.hxx +1 -1
  17. data/ext/couchbase/error_context/key_value.hxx +1 -1
  18. data/ext/couchbase/error_context/query.hxx +1 -1
  19. data/ext/couchbase/error_context/search.hxx +1 -1
  20. data/ext/couchbase/error_context/view.hxx +1 -1
  21. data/ext/couchbase/error_map.hxx +1 -1
  22. data/ext/couchbase/errors.hxx +1 -1
  23. data/ext/couchbase/io/dns_client.hxx +1 -1
  24. data/ext/couchbase/io/dns_codec.hxx +1 -1
  25. data/ext/couchbase/io/dns_config.hxx +1 -1
  26. data/ext/couchbase/io/dns_message.hxx +1 -1
  27. data/ext/couchbase/io/http_command.hxx +1 -1
  28. data/ext/couchbase/io/http_context.hxx +1 -1
  29. data/ext/couchbase/io/http_message.hxx +1 -1
  30. data/ext/couchbase/io/http_parser.hxx +1 -1
  31. data/ext/couchbase/io/http_session.hxx +1 -1
  32. data/ext/couchbase/io/http_session_manager.hxx +1 -1
  33. data/ext/couchbase/io/mcbp_command.hxx +1 -1
  34. data/ext/couchbase/io/mcbp_context.hxx +1 -1
  35. data/ext/couchbase/io/mcbp_message.hxx +1 -1
  36. data/ext/couchbase/io/mcbp_parser.hxx +1 -1
  37. data/ext/couchbase/io/mcbp_session.hxx +10 -1
  38. data/ext/couchbase/io/query_cache.hxx +1 -1
  39. data/ext/couchbase/io/retry_action.hxx +1 -1
  40. data/ext/couchbase/io/retry_context.hxx +1 -1
  41. data/ext/couchbase/io/retry_orchestrator.hxx +1 -1
  42. data/ext/couchbase/io/retry_reason.hxx +1 -1
  43. data/ext/couchbase/io/retry_strategy.hxx +1 -1
  44. data/ext/couchbase/io/streams.hxx +1 -1
  45. data/ext/couchbase/mutation_token.hxx +1 -1
  46. data/ext/couchbase/operations.hxx +1 -1
  47. data/ext/couchbase/operations/analytics_dataset_create.hxx +1 -1
  48. data/ext/couchbase/operations/analytics_dataset_drop.hxx +1 -1
  49. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +1 -1
  50. data/ext/couchbase/operations/analytics_dataverse_create.hxx +1 -1
  51. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +1 -1
  52. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +1 -1
  53. data/ext/couchbase/operations/analytics_index_create.hxx +1 -1
  54. data/ext/couchbase/operations/analytics_index_drop.hxx +1 -1
  55. data/ext/couchbase/operations/analytics_index_get_all.hxx +1 -1
  56. data/ext/couchbase/operations/analytics_link_connect.hxx +1 -1
  57. data/ext/couchbase/operations/analytics_link_disconnect.hxx +1 -1
  58. data/ext/couchbase/operations/bucket_create.hxx +1 -1
  59. data/ext/couchbase/operations/bucket_drop.hxx +1 -1
  60. data/ext/couchbase/operations/bucket_flush.hxx +1 -1
  61. data/ext/couchbase/operations/bucket_get.hxx +1 -1
  62. data/ext/couchbase/operations/bucket_get_all.hxx +1 -1
  63. data/ext/couchbase/operations/bucket_update.hxx +1 -1
  64. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +1 -1
  65. data/ext/couchbase/operations/collection_create.hxx +13 -9
  66. data/ext/couchbase/operations/collection_drop.hxx +11 -7
  67. data/ext/couchbase/operations/collections_manifest_get.hxx +1 -1
  68. data/ext/couchbase/operations/design_document.hxx +1 -1
  69. data/ext/couchbase/operations/document_analytics.hxx +1 -1
  70. data/ext/couchbase/operations/document_append.hxx +1 -1
  71. data/ext/couchbase/operations/document_decrement.hxx +5 -1
  72. data/ext/couchbase/operations/document_exists.hxx +1 -1
  73. data/ext/couchbase/operations/document_get.hxx +1 -1
  74. data/ext/couchbase/operations/document_get_and_lock.hxx +1 -1
  75. data/ext/couchbase/operations/document_get_and_touch.hxx +1 -1
  76. data/ext/couchbase/operations/document_get_projected.hxx +1 -1
  77. data/ext/couchbase/operations/document_increment.hxx +5 -1
  78. data/ext/couchbase/operations/document_insert.hxx +1 -1
  79. data/ext/couchbase/operations/document_lookup_in.hxx +1 -1
  80. data/ext/couchbase/operations/document_mutate_in.hxx +5 -1
  81. data/ext/couchbase/operations/document_prepend.hxx +1 -1
  82. data/ext/couchbase/operations/document_query.hxx +9 -1
  83. data/ext/couchbase/operations/document_remove.hxx +1 -1
  84. data/ext/couchbase/operations/document_replace.hxx +5 -1
  85. data/ext/couchbase/operations/document_search.hxx +1 -1
  86. data/ext/couchbase/operations/document_touch.hxx +1 -1
  87. data/ext/couchbase/operations/document_unlock.hxx +1 -1
  88. data/ext/couchbase/operations/document_upsert.hxx +5 -1
  89. data/ext/couchbase/operations/document_view.hxx +1 -1
  90. data/ext/couchbase/operations/group_drop.hxx +1 -1
  91. data/ext/couchbase/operations/group_get.hxx +1 -1
  92. data/ext/couchbase/operations/group_get_all.hxx +1 -1
  93. data/ext/couchbase/operations/group_upsert.hxx +1 -1
  94. data/ext/couchbase/operations/http_noop.hxx +1 -1
  95. data/ext/couchbase/operations/mcbp_noop.hxx +1 -1
  96. data/ext/couchbase/operations/query_index_build_deferred.hxx +1 -1
  97. data/ext/couchbase/operations/query_index_create.hxx +1 -1
  98. data/ext/couchbase/operations/query_index_drop.hxx +1 -1
  99. data/ext/couchbase/operations/query_index_get_all.hxx +1 -1
  100. data/ext/couchbase/operations/rbac.hxx +1 -1
  101. data/ext/couchbase/operations/role_get_all.hxx +1 -1
  102. data/ext/couchbase/operations/scope_create.hxx +9 -8
  103. data/ext/couchbase/operations/scope_drop.hxx +9 -6
  104. data/ext/couchbase/operations/scope_get_all.hxx +2 -2
  105. data/ext/couchbase/operations/search_get_stats.hxx +1 -1
  106. data/ext/couchbase/operations/search_index.hxx +1 -1
  107. data/ext/couchbase/operations/search_index_analyze_document.hxx +1 -1
  108. data/ext/couchbase/operations/search_index_control_ingest.hxx +1 -1
  109. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +1 -1
  110. data/ext/couchbase/operations/search_index_control_query.hxx +1 -1
  111. data/ext/couchbase/operations/search_index_drop.hxx +1 -1
  112. data/ext/couchbase/operations/search_index_get.hxx +1 -1
  113. data/ext/couchbase/operations/search_index_get_all.hxx +1 -1
  114. data/ext/couchbase/operations/search_index_get_documents_count.hxx +1 -1
  115. data/ext/couchbase/operations/search_index_get_stats.hxx +1 -1
  116. data/ext/couchbase/operations/search_index_upsert.hxx +1 -1
  117. data/ext/couchbase/operations/user_drop.hxx +1 -1
  118. data/ext/couchbase/operations/user_get.hxx +1 -1
  119. data/ext/couchbase/operations/user_get_all.hxx +1 -1
  120. data/ext/couchbase/operations/user_upsert.hxx +1 -1
  121. data/ext/couchbase/operations/view_index_drop.hxx +1 -1
  122. data/ext/couchbase/operations/view_index_get.hxx +1 -1
  123. data/ext/couchbase/operations/view_index_get_all.hxx +1 -1
  124. data/ext/couchbase/operations/view_index_upsert.hxx +1 -1
  125. data/ext/couchbase/origin.hxx +1 -1
  126. data/ext/couchbase/protocol/client_opcode.hxx +6 -1
  127. data/ext/couchbase/protocol/client_request.hxx +1 -1
  128. data/ext/couchbase/protocol/client_response.hxx +1 -1
  129. data/ext/couchbase/protocol/cmd_append.hxx +1 -1
  130. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +1 -1
  131. data/ext/couchbase/protocol/cmd_decrement.hxx +19 -9
  132. data/ext/couchbase/protocol/cmd_exists.hxx +1 -1
  133. data/ext/couchbase/protocol/cmd_get.hxx +1 -1
  134. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +1 -1
  135. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +1 -1
  136. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +1 -1
  137. data/ext/couchbase/protocol/cmd_get_collection_id.hxx +7 -7
  138. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +1 -1
  139. data/ext/couchbase/protocol/cmd_get_error_map.hxx +1 -1
  140. data/ext/couchbase/protocol/cmd_hello.hxx +17 -4
  141. data/ext/couchbase/protocol/cmd_increment.hxx +19 -9
  142. data/ext/couchbase/protocol/cmd_info.hxx +1 -1
  143. data/ext/couchbase/protocol/cmd_insert.hxx +1 -1
  144. data/ext/couchbase/protocol/cmd_lookup_in.hxx +1 -1
  145. data/ext/couchbase/protocol/cmd_mutate_in.hxx +18 -9
  146. data/ext/couchbase/protocol/cmd_noop.hxx +1 -1
  147. data/ext/couchbase/protocol/cmd_prepend.hxx +1 -1
  148. data/ext/couchbase/protocol/cmd_remove.hxx +1 -1
  149. data/ext/couchbase/protocol/cmd_replace.hxx +17 -8
  150. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +1 -1
  151. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +1 -1
  152. data/ext/couchbase/protocol/cmd_sasl_step.hxx +1 -1
  153. data/ext/couchbase/protocol/cmd_select_bucket.hxx +1 -1
  154. data/ext/couchbase/protocol/cmd_touch.hxx +1 -1
  155. data/ext/couchbase/protocol/cmd_unlock.hxx +1 -1
  156. data/ext/couchbase/protocol/cmd_upsert.hxx +17 -8
  157. data/ext/couchbase/protocol/datatype.hxx +1 -1
  158. data/ext/couchbase/protocol/durability_level.hxx +1 -1
  159. data/ext/couchbase/protocol/enhanced_error_info.hxx +1 -1
  160. data/ext/couchbase/protocol/frame_info_id.hxx +2 -2
  161. data/ext/couchbase/protocol/hello_feature.hxx +1 -1
  162. data/ext/couchbase/protocol/magic.hxx +1 -1
  163. data/ext/couchbase/protocol/server_opcode.hxx +1 -1
  164. data/ext/couchbase/protocol/server_request.hxx +1 -1
  165. data/ext/couchbase/protocol/status.hxx +1 -1
  166. data/ext/couchbase/service_type.hxx +1 -1
  167. data/ext/couchbase/timeout_defaults.hxx +1 -1
  168. data/ext/couchbase/utils/byteswap.hxx +1 -1
  169. data/ext/couchbase/utils/connection_string.hxx +28 -1
  170. data/ext/couchbase/version.hxx +2 -2
  171. data/ext/extconf.rb +1 -1
  172. data/ext/test/test_helper.hxx +1 -1
  173. data/ext/test/test_helper_native.hxx +1 -1
  174. data/ext/test/test_helper_ruby.hxx +1 -1
  175. data/ext/test/test_native_binary_operations.cxx +1 -1
  176. data/ext/test/test_native_diagnostics.cxx +1 -1
  177. data/ext/test/test_native_trivial_crud.cxx +1 -1
  178. data/ext/test/test_ruby_trivial_crud.cxx +1 -1
  179. data/ext/test/test_ruby_trivial_query.cxx +1 -1
  180. data/lib/active_support/cache/couchbase_store.rb +2 -1
  181. data/lib/couchbase.rb +1 -1
  182. data/lib/couchbase/analytics_options.rb +1 -1
  183. data/lib/couchbase/authenticator.rb +1 -1
  184. data/lib/couchbase/binary_collection.rb +1 -1
  185. data/lib/couchbase/binary_collection_options.rb +1 -1
  186. data/lib/couchbase/bucket.rb +1 -1
  187. data/lib/couchbase/cluster.rb +2 -2
  188. data/lib/couchbase/collection.rb +1 -1
  189. data/lib/couchbase/collection_options.rb +25 -19
  190. data/lib/couchbase/configuration.rb +1 -1
  191. data/lib/couchbase/datastructures.rb +1 -1
  192. data/lib/couchbase/datastructures/couchbase_list.rb +1 -1
  193. data/lib/couchbase/datastructures/couchbase_map.rb +1 -1
  194. data/lib/couchbase/datastructures/couchbase_queue.rb +1 -1
  195. data/lib/couchbase/datastructures/couchbase_set.rb +1 -1
  196. data/lib/couchbase/diagnostics.rb +1 -1
  197. data/lib/couchbase/errors.rb +1 -1
  198. data/lib/couchbase/json_transcoder.rb +1 -1
  199. data/lib/couchbase/libcouchbase.bundle +0 -0
  200. data/lib/couchbase/logger.rb +1 -1
  201. data/lib/couchbase/management.rb +1 -1
  202. data/lib/couchbase/management/analytics_index_manager.rb +1 -1
  203. data/lib/couchbase/management/bucket_manager.rb +1 -1
  204. data/lib/couchbase/management/collection_manager.rb +8 -1
  205. data/lib/couchbase/management/query_index_manager.rb +1 -1
  206. data/lib/couchbase/management/search_index_manager.rb +1 -1
  207. data/lib/couchbase/management/user_manager.rb +1 -1
  208. data/lib/couchbase/management/view_index_manager.rb +1 -1
  209. data/lib/couchbase/mutation_state.rb +1 -1
  210. data/lib/couchbase/options.rb +49 -4
  211. data/lib/couchbase/query_options.rb +1 -1
  212. data/lib/couchbase/railtie.rb +1 -1
  213. data/lib/couchbase/scope.rb +7 -6
  214. data/lib/couchbase/search_options.rb +1 -1
  215. data/lib/couchbase/subdoc.rb +2 -2
  216. data/lib/couchbase/utils.rb +1 -1
  217. data/lib/couchbase/utils/time.rb +1 -1
  218. data/lib/couchbase/version.rb +9 -9
  219. data/lib/couchbase/view_options.rb +1 -1
  220. data/lib/rails/generators/couchbase/config/config_generator.rb +1 -1
  221. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 504c56199418bf5f2127577257f9855fd7d0516499ab615faa32203bfb8fa61d
4
- data.tar.gz: b1805af047c5723b315b5fa264a0a03e6ea9880d2656cf146d7cfb7cb8419391
3
+ metadata.gz: 2ed2265468b3ab614f6e74a188015c2f96ce595116af1fc981ea30314e7d2ae3
4
+ data.tar.gz: bce8a86c7ea3f563e24b106dd981cace9bb558e9a6e70cb906e58df433b05201
5
5
  SHA512:
6
- metadata.gz: 701513fe89df673943185bbfe438c56b61a09aafb2bdc1532adc4576c62c91bf515f1f8633871d9642f7af0c5c7f7b8fe4b2c229cb2f3758bbc620b1e618020d
7
- data.tar.gz: 3176b8683d830413fcf59eebc7430055a896c3dd330cc1a39cefeb6c91334d2c5b91c1137989e1f3666dfbb6ab3a9df0c5c64d5b706b571bff073552731cfbb7
6
+ metadata.gz: 2a14b4867628eea0bb6a52c0eaf4e683b44261306b897f194de9f195c5aa2105ecb646c62c961ceeb903c7aa728342d130bfb15005bee07ecf9a3ebc8155c776
7
+ data.tar.gz: e31a897199cae23cd47c945f99353019cfa94e4a176a4a235de834143944b14b84aec84c5c0f99c12cce8a711155375e7525187d4c0b6b945ff1d5434750e44f
data/README.md CHANGED
@@ -5,7 +5,6 @@
5
5
  [![commits](https://img.shields.io/github/commits-since/couchbase/couchbase-ruby-client/latest?color=brightgreen)](https://github.com/couchbase/couchbase-ruby-client/commits/master)
6
6
  [![tests](https://img.shields.io/github/workflow/status/couchbase/couchbase-ruby-client/tests?label=tests)](https://github.com/couchbase/couchbase-ruby-client/actions?query=workflow%3Atests)
7
7
  [![linters](https://img.shields.io/github/workflow/status/couchbase/couchbase-ruby-client/linters?label=linters)](https://github.com/couchbase/couchbase-ruby-client/actions?query=workflow%3Alinters)
8
- [![jenkins](https://img.shields.io/jenkins/build?jobUrl=http%3A%2F%2Fsdk.jenkins.couchbase.com%2Fjob%2Fruby%2Fjob%2Fruby-nightly%2F&label=jenkins)](http://sdk.jenkins.couchbase.com/job/ruby/job/ruby-nightly/)
9
8
 
10
9
  This repository contains the third generation of the official Couchbase SDK for Ruby (aka. SDKv3)
11
10
 
@@ -25,7 +24,7 @@ The library tested with the MRI 2.5, 2.6, 2.7 and 3.0. Supported platforms are L
25
24
  Add this line to your application's Gemfile:
26
25
 
27
26
  ```ruby
28
- gem "couchbase", "3.0.3"
27
+ gem "couchbase", "3.1.1"
29
28
  ```
30
29
 
31
30
  And then execute:
@@ -116,7 +115,7 @@ Now the API reference is accessible using web browser (where `VERSION` is curren
116
115
 
117
116
  The gem is available as open source under the terms of the [Apache2 License](https://opensource.org/licenses/Apache-2.0).
118
117
 
119
- Copyright 2011-2020 Couchbase, Inc.
118
+ Copyright 2011-2021 Couchbase, Inc.
120
119
 
121
120
  Licensed under the Apache License, Version 2.0 (the "License");
122
121
  you may not use this file except in compliance with the License.
data/ext/CMakeLists.txt CHANGED
@@ -95,9 +95,11 @@ else()
95
95
  message(STATUS "RUBY_VERSION: ${RUBY_VERSION}")
96
96
  message(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}")
97
97
  endif()
98
- message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
99
98
  message(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}")
100
- include_directories(BEFORE SYSTEM "${RUBY_INCLUDE_DIR}")
99
+ if(RUBY_INCLUDE_DIR)
100
+ message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
101
+ include_directories(BEFORE SYSTEM "${RUBY_INCLUDE_DIR}")
102
+ endif()
101
103
 
102
104
  add_library(couchbase SHARED couchbase/couchbase.cxx)
103
105
  target_include_directories(couchbase PRIVATE ${PROJECT_BINARY_DIR}/generated)
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -26,5 +26,5 @@ constexpr auto BACKEND_CXX_COMPILER = "@CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPIL
26
26
  constexpr auto BACKEND_C_COMPILER = "@CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@";
27
27
  constexpr auto BACKEND_SYSTEM = "@CMAKE_SYSTEM@";
28
28
  constexpr auto BACKEND_SYSTEM_PROCESSOR = "@CMAKE_SYSTEM_PROCESSOR@";
29
- constexpr auto BACKEND_GIT_REVISION = "bcb5da39fd4dfd3bd7ce917abc89faf1fbcd7d5f";
29
+ constexpr auto BACKEND_GIT_REVISION = "a79d098eb238b3883e49e1738c35167642e8834f";
30
30
  } // namespace couchbase
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -40,6 +40,9 @@ struct cluster_options {
40
40
  bool force_ipv4{ false };
41
41
  bool enable_dns_srv{ true };
42
42
  bool show_queries{ false };
43
+ bool enable_unordered_execution{ true };
44
+ bool enable_clustermap_notification{ true };
45
+ bool enable_compression{ true };
43
46
  std::string network{ "auto" };
44
47
 
45
48
  std::chrono::milliseconds tcp_keep_alive_interval = timeout_defaults::tcp_keep_alive_interval;
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
22
22
  #include <openssl/crypto.h>
23
23
 
24
24
  #include <spdlog/spdlog.h>
25
+
25
26
  #include <spdlog/cfg/env.h>
26
27
 
27
28
  #include <http_parser.h>
@@ -40,15 +41,22 @@
40
41
  #if defined(HAVE_RUBY_VERSION_H)
41
42
  #include <ruby/version.h>
42
43
  #endif
44
+ #include <ruby/thread.h>
43
45
 
44
46
  #if defined(RB_METHOD_DEFINITION_DECL) || RUBY_API_VERSION_MAJOR == 3
45
- #define VALUE_FUNC(f) (f)
46
- #define INT_FUNC(f) (f)
47
+ #define VALUE_FUNC(f) f
48
+ #define INT_FUNC(f) f
47
49
  #else
48
50
  #define VALUE_FUNC(f) reinterpret_cast<VALUE (*)(ANYARGS)>(f)
49
51
  #define INT_FUNC(f) reinterpret_cast<int (*)(ANYARGS)>(f)
50
52
  #endif
51
53
 
54
+ static inline VALUE
55
+ cb_str_new(const std::string& str)
56
+ {
57
+ return rb_external_str_new(str.data(), static_cast<long>(str.size()));
58
+ }
59
+
52
60
  static void
53
61
  init_versions(VALUE mCouchbase)
54
62
  {
@@ -59,12 +67,10 @@ init_versions(VALUE mCouchbase)
59
67
  cb_Version = rb_hash_new();
60
68
  rb_const_set(mCouchbase, rb_intern("VERSION"), cb_Version);
61
69
  }
62
- #define VERSION_SPLIT_(VER) (VER) / 100000, (VER) / 100 % 1000, (VER) % 100
63
70
 
64
71
  std::string ver;
65
72
  ver = fmt::format("{}.{}.{}", couchbase::BACKEND_VERSION_MAJOR, couchbase::BACKEND_VERSION_MINOR, couchbase::BACKEND_VERSION_PATCH);
66
- rb_hash_aset(
67
- cb_Version, rb_id2sym(rb_intern("backend")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
73
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("backend")), rb_str_freeze(cb_str_new(ver)));
68
74
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("build_timestamp")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_BUILD_TIMESTAMP)));
69
75
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("revision")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_GIT_REVISION)));
70
76
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("platform")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_SYSTEM)));
@@ -73,19 +79,16 @@ init_versions(VALUE mCouchbase)
73
79
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("cxx")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_CXX_COMPILER)));
74
80
  #if defined(HAVE_RUBY_VERSION_H)
75
81
  ver = fmt::format("{}.{}.{}", RUBY_API_VERSION_MAJOR, RUBY_API_VERSION_MINOR, RUBY_API_VERSION_TEENY);
76
- rb_hash_aset(cb_Version, rb_id2sym(rb_intern("ruby")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
82
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("ruby")), rb_str_freeze(cb_str_new(ver)));
77
83
  #endif
78
84
  ver = fmt::format("{}.{}.{}", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
79
- rb_hash_aset(
80
- cb_Version, rb_id2sym(rb_intern("spdlog")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
81
- ver = fmt::format("{}.{}.{}", VERSION_SPLIT_(ASIO_VERSION));
82
- rb_hash_aset(cb_Version, rb_id2sym(rb_intern("asio")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
85
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("spdlog")), rb_str_freeze(cb_str_new(ver)));
86
+ ver = fmt::format("{}.{}.{}", ASIO_VERSION / 100'000, ASIO_VERSION / 100 % 1000, ASIO_VERSION % 100);
87
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("asio")), rb_str_freeze(cb_str_new(ver)));
83
88
  ver = fmt::format("{}.{}.{}", SNAPPY_MAJOR, SNAPPY_MINOR, SNAPPY_PATCHLEVEL);
84
- rb_hash_aset(
85
- cb_Version, rb_id2sym(rb_intern("snappy")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
89
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("snappy")), rb_str_freeze(cb_str_new(ver)));
86
90
  ver = fmt::format("{}.{}.{}", HTTP_PARSER_VERSION_MAJOR, HTTP_PARSER_VERSION_MINOR, HTTP_PARSER_VERSION_PATCH);
87
- rb_hash_aset(
88
- cb_Version, rb_id2sym(rb_intern("http_parser")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
91
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("http_parser")), rb_str_freeze(cb_str_new(ver)));
89
92
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("openssl_headers")), rb_str_freeze(rb_str_new_cstr(OPENSSL_VERSION_TEXT)));
90
93
  #if defined(OPENSSL_VERSION)
91
94
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("openssl_runtime")), rb_str_freeze(rb_str_new_cstr(OpenSSL_version(OPENSSL_VERSION))));
@@ -93,8 +96,6 @@ init_versions(VALUE mCouchbase)
93
96
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("openssl_runtime")), rb_str_freeze(rb_str_new_cstr(SSLeay_version(SSLEAY_VERSION))));
94
97
  #endif
95
98
 
96
- #undef VERSION_SPLIT_
97
-
98
99
  VALUE version_info = rb_inspect(cb_Version);
99
100
  spdlog::info("couchbase backend has been initialized: {}",
100
101
  std::string_view(RSTRING_PTR(version_info), static_cast<std::size_t>(RSTRING_LEN(version_info))));
@@ -133,7 +134,7 @@ struct cb_backend_data {
133
134
  };
134
135
 
135
136
  static void
136
- cb__backend_close(cb_backend_data* backend)
137
+ cb_backend_close(cb_backend_data* backend)
137
138
  {
138
139
  if (backend->cluster) {
139
140
  auto barrier = std::make_shared<std::promise<void>>();
@@ -156,15 +157,15 @@ cb_Backend_mark(void* /* ptr */)
156
157
  static void
157
158
  cb_Backend_free(void* ptr)
158
159
  {
159
- auto* backend = reinterpret_cast<cb_backend_data*>(ptr);
160
- cb__backend_close(backend);
160
+ auto* backend = static_cast<cb_backend_data*>(ptr);
161
+ cb_backend_close(backend);
161
162
  ruby_xfree(backend);
162
163
  }
163
164
 
164
165
  static size_t
165
166
  cb_Backend_memsize(const void* ptr)
166
167
  {
167
- const auto* backend = reinterpret_cast<const cb_backend_data*>(ptr);
168
+ const auto* backend = static_cast<const cb_backend_data*>(ptr);
168
169
  return sizeof(*backend) + sizeof(*backend->cluster);
169
170
  }
170
171
 
@@ -196,8 +197,6 @@ cb_Backend_allocate(VALUE klass)
196
197
  return obj;
197
198
  }
198
199
 
199
- static VALUE eCouchbaseError;
200
- static VALUE eTimeout;
201
200
  static VALUE eAmbiguousTimeout;
202
201
  static VALUE eAuthenticationFailure;
203
202
  static VALUE eBucketExists;
@@ -276,9 +275,9 @@ static void
276
275
  init_exceptions(VALUE mCouchbase)
277
276
  {
278
277
  VALUE mError = rb_define_module_under(mCouchbase, "Error");
279
- eCouchbaseError = rb_define_class_under(mError, "CouchbaseError", rb_eStandardError);
278
+ VALUE eCouchbaseError = rb_define_class_under(mError, "CouchbaseError", rb_eStandardError);
280
279
 
281
- eTimeout = rb_define_class_under(mError, "Timeout", eCouchbaseError);
280
+ VALUE eTimeout = rb_define_class_under(mError, "Timeout", eCouchbaseError);
282
281
 
283
282
  eAmbiguousTimeout = rb_define_class_under(mError, "AmbiguousTimeout", eTimeout);
284
283
  eAuthenticationFailure = rb_define_class_under(mError, "AuthenticationFailure", eCouchbaseError);
@@ -356,7 +355,7 @@ init_exceptions(VALUE mCouchbase)
356
355
  }
357
356
 
358
357
  static VALUE
359
- cb__map_error_code(std::error_code ec, const std::string& message)
358
+ cb_map_error_code(std::error_code ec, const std::string& message)
360
359
  {
361
360
  if (ec.category() == couchbase::error::detail::get_common_category()) {
362
361
  switch (static_cast<couchbase::error::common_errc>(ec.value())) {
@@ -589,44 +588,30 @@ cb__map_error_code(std::error_code ec, const std::string& message)
589
588
  }
590
589
 
591
590
  static VALUE
592
- cb__map_error_code(const couchbase::error_context::key_value& ctx, const std::string& message)
591
+ cb_map_error_code(const couchbase::error_context::key_value& ctx, const std::string& message)
593
592
  {
594
- VALUE exc = cb__map_error_code(ctx.ec, message);
593
+ VALUE exc = cb_map_error_code(ctx.ec, message);
595
594
  VALUE error_context = rb_hash_new();
596
595
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
597
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
598
- rb_hash_aset(error_context, rb_id2sym(rb_intern("id")), rb_external_str_new(ctx.id.key.data(), static_cast<long>(ctx.id.key.size())));
599
- rb_hash_aset(error_context,
600
- rb_id2sym(rb_intern("collection")),
601
- rb_external_str_new(ctx.id.collection.data(), static_cast<long>(ctx.id.collection.size())));
602
- rb_hash_aset(
603
- error_context, rb_id2sym(rb_intern("bucket")), rb_external_str_new(ctx.id.bucket.data(), static_cast<long>(ctx.id.bucket.size())));
596
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
597
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("id")), cb_str_new(ctx.id.key));
598
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("collection")), cb_str_new(ctx.id.collection));
599
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("bucket")), cb_str_new(ctx.id.bucket));
604
600
  rb_hash_aset(error_context, rb_id2sym(rb_intern("opaque")), ULONG2NUM(ctx.opaque));
605
601
  if (ctx.status_code) {
606
602
  std::string status(fmt::format("{}", ctx.status_code.value()));
607
- rb_hash_aset(error_context, rb_id2sym(rb_intern("status")), rb_external_str_new(status.data(), static_cast<long>(status.size())));
603
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("status")), cb_str_new(status));
608
604
  }
609
605
  if (ctx.error_map_info) {
610
606
  VALUE error_map_info = rb_hash_new();
611
- rb_hash_aset(error_map_info,
612
- rb_id2sym(rb_intern("name")),
613
- rb_external_str_new(ctx.error_map_info->name.data(), static_cast<long>(ctx.error_map_info->name.size())));
614
- rb_hash_aset(
615
- error_map_info,
616
- rb_id2sym(rb_intern("desc")),
617
- rb_external_str_new(ctx.error_map_info->description.data(), static_cast<long>(ctx.error_map_info->description.size())));
607
+ rb_hash_aset(error_map_info, rb_id2sym(rb_intern("name")), cb_str_new(ctx.error_map_info->name));
608
+ rb_hash_aset(error_map_info, rb_id2sym(rb_intern("desc")), cb_str_new(ctx.error_map_info->description));
618
609
  rb_hash_aset(error_context, rb_id2sym(rb_intern("error_map_info")), error_map_info);
619
610
  }
620
611
  if (ctx.enhanced_error_info) {
621
612
  VALUE enhanced_error_info = rb_hash_new();
622
- rb_hash_aset(
623
- enhanced_error_info,
624
- rb_id2sym(rb_intern("reference")),
625
- rb_external_str_new(ctx.enhanced_error_info->reference.data(), static_cast<long>(ctx.enhanced_error_info->reference.size())));
626
- rb_hash_aset(
627
- enhanced_error_info,
628
- rb_id2sym(rb_intern("context")),
629
- rb_external_str_new(ctx.enhanced_error_info->context.data(), static_cast<long>(ctx.enhanced_error_info->context.size())));
613
+ rb_hash_aset(enhanced_error_info, rb_id2sym(rb_intern("reference")), cb_str_new(ctx.enhanced_error_info->reference));
614
+ rb_hash_aset(enhanced_error_info, rb_id2sym(rb_intern("context")), cb_str_new(ctx.enhanced_error_info->context));
630
615
  rb_hash_aset(error_context, rb_id2sym(rb_intern("extended_error_info")), enhanced_error_info);
631
616
  }
632
617
  if (ctx.retry_attempts > 0) {
@@ -641,39 +626,29 @@ cb__map_error_code(const couchbase::error_context::key_value& ctx, const std::st
641
626
  }
642
627
  }
643
628
  if (ctx.last_dispatched_to) {
644
- rb_hash_aset(error_context,
645
- rb_id2sym(rb_intern("last_dispatched_to")),
646
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
629
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
647
630
  }
648
631
  if (ctx.last_dispatched_from) {
649
- rb_hash_aset(error_context,
650
- rb_id2sym(rb_intern("last_dispatched_from")),
651
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
632
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
652
633
  }
653
634
  rb_iv_set(exc, "@context", error_context);
654
635
  return exc;
655
636
  }
656
637
 
657
638
  static VALUE
658
- cb__map_error_code(const couchbase::error_context::query& ctx, const std::string& message)
639
+ cb_map_error_code(const couchbase::error_context::query& ctx, const std::string& message)
659
640
  {
660
- VALUE exc = cb__map_error_code(ctx.ec, message);
641
+ VALUE exc = cb_map_error_code(ctx.ec, message);
661
642
  VALUE error_context = rb_hash_new();
662
643
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
663
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
664
- rb_hash_aset(error_context,
665
- rb_id2sym(rb_intern("client_context_id")),
666
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
667
- rb_hash_aset(
668
- error_context, rb_id2sym(rb_intern("statement")), rb_external_str_new(ctx.statement.data(), static_cast<long>(ctx.statement.size())));
644
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
645
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
646
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("statement")), cb_str_new(ctx.statement));
669
647
  if (ctx.parameters) {
670
- rb_hash_aset(error_context,
671
- rb_id2sym(rb_intern("parameters")),
672
- rb_external_str_new(ctx.parameters->data(), static_cast<long>(ctx.parameters->size())));
648
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), cb_str_new(ctx.parameters.value()));
673
649
  }
674
650
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
675
- rb_hash_aset(
676
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
651
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
677
652
  if (ctx.retry_attempts > 0) {
678
653
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
679
654
  if (!ctx.retry_reasons.empty()) {
@@ -686,39 +661,29 @@ cb__map_error_code(const couchbase::error_context::query& ctx, const std::string
686
661
  }
687
662
  }
688
663
  if (ctx.last_dispatched_to) {
689
- rb_hash_aset(error_context,
690
- rb_id2sym(rb_intern("last_dispatched_to")),
691
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
664
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
692
665
  }
693
666
  if (ctx.last_dispatched_from) {
694
- rb_hash_aset(error_context,
695
- rb_id2sym(rb_intern("last_dispatched_from")),
696
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
667
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
697
668
  }
698
669
  rb_iv_set(exc, "@context", error_context);
699
670
  return exc;
700
671
  }
701
672
 
702
673
  static VALUE
703
- cb__map_error_code(const couchbase::error_context::analytics& ctx, const std::string& message)
674
+ cb_map_error_code(const couchbase::error_context::analytics& ctx, const std::string& message)
704
675
  {
705
- VALUE exc = cb__map_error_code(ctx.ec, message);
676
+ VALUE exc = cb_map_error_code(ctx.ec, message);
706
677
  VALUE error_context = rb_hash_new();
707
678
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
708
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
709
- rb_hash_aset(error_context,
710
- rb_id2sym(rb_intern("client_context_id")),
711
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
712
- rb_hash_aset(
713
- error_context, rb_id2sym(rb_intern("statement")), rb_external_str_new(ctx.statement.data(), static_cast<long>(ctx.statement.size())));
679
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
680
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
681
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("statement")), cb_str_new(ctx.statement));
714
682
  if (ctx.parameters) {
715
- rb_hash_aset(error_context,
716
- rb_id2sym(rb_intern("parameters")),
717
- rb_external_str_new(ctx.parameters->data(), static_cast<long>(ctx.parameters->size())));
683
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), cb_str_new(ctx.parameters.value()));
718
684
  }
719
685
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
720
- rb_hash_aset(
721
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
686
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
722
687
  if (ctx.retry_attempts > 0) {
723
688
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
724
689
  if (!ctx.retry_reasons.empty()) {
@@ -731,44 +696,34 @@ cb__map_error_code(const couchbase::error_context::analytics& ctx, const std::st
731
696
  }
732
697
  }
733
698
  if (ctx.last_dispatched_to) {
734
- rb_hash_aset(error_context,
735
- rb_id2sym(rb_intern("last_dispatched_to")),
736
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
699
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
737
700
  }
738
701
  if (ctx.last_dispatched_from) {
739
- rb_hash_aset(error_context,
740
- rb_id2sym(rb_intern("last_dispatched_from")),
741
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
702
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
742
703
  }
743
704
  rb_iv_set(exc, "@context", error_context);
744
705
  return exc;
745
706
  }
746
707
 
747
708
  static VALUE
748
- cb__map_error_code(const couchbase::error_context::view& ctx, const std::string& message)
709
+ cb_map_error_code(const couchbase::error_context::view& ctx, const std::string& message)
749
710
  {
750
- VALUE exc = cb__map_error_code(ctx.ec, message);
711
+ VALUE exc = cb_map_error_code(ctx.ec, message);
751
712
  VALUE error_context = rb_hash_new();
752
713
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
753
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
754
- rb_hash_aset(error_context,
755
- rb_id2sym(rb_intern("client_context_id")),
756
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
757
- rb_hash_aset(error_context,
758
- rb_id2sym(rb_intern("design_document_name")),
759
- rb_external_str_new(ctx.design_document_name.data(), static_cast<long>(ctx.design_document_name.size())));
760
- rb_hash_aset(
761
- error_context, rb_id2sym(rb_intern("view_name")), rb_external_str_new(ctx.view_name.data(), static_cast<long>(ctx.view_name.size())));
714
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
715
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
716
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("design_document_name")), cb_str_new(ctx.design_document_name));
717
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("view_name")), cb_str_new(ctx.view_name));
762
718
  if (!ctx.query_string.empty()) {
763
719
  VALUE parameters = rb_ary_new_capa(static_cast<long>(ctx.query_string.size()));
764
720
  for (const auto& param : ctx.query_string) {
765
- rb_ary_push(parameters, rb_external_str_new(param.data(), static_cast<long>(param.size())));
721
+ rb_ary_push(parameters, cb_str_new(param));
766
722
  }
767
723
  rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), parameters);
768
724
  }
769
725
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
770
- rb_hash_aset(
771
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
726
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
772
727
  if (ctx.retry_attempts > 0) {
773
728
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
774
729
  if (!ctx.retry_reasons.empty()) {
@@ -781,35 +736,27 @@ cb__map_error_code(const couchbase::error_context::view& ctx, const std::string&
781
736
  }
782
737
  }
783
738
  if (ctx.last_dispatched_to) {
784
- rb_hash_aset(error_context,
785
- rb_id2sym(rb_intern("last_dispatched_to")),
786
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
739
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
787
740
  }
788
741
  if (ctx.last_dispatched_from) {
789
- rb_hash_aset(error_context,
790
- rb_id2sym(rb_intern("last_dispatched_from")),
791
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
742
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
792
743
  }
793
744
  rb_iv_set(exc, "@context", error_context);
794
745
  return exc;
795
746
  }
796
747
 
797
748
  static VALUE
798
- cb__map_error_code(const couchbase::error_context::http& ctx, const std::string& message)
749
+ cb_map_error_code(const couchbase::error_context::http& ctx, const std::string& message)
799
750
  {
800
- VALUE exc = cb__map_error_code(ctx.ec, message);
751
+ VALUE exc = cb_map_error_code(ctx.ec, message);
801
752
  VALUE error_context = rb_hash_new();
802
753
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
803
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
804
- rb_hash_aset(error_context,
805
- rb_id2sym(rb_intern("client_context_id")),
806
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
807
- rb_hash_aset(
808
- error_context, rb_id2sym(rb_intern("method")), rb_external_str_new(ctx.method.data(), static_cast<long>(ctx.method.size())));
809
- rb_hash_aset(error_context, rb_id2sym(rb_intern("path")), rb_external_str_new(ctx.path.data(), static_cast<long>(ctx.path.size())));
754
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
755
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
756
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("method")), cb_str_new(ctx.method));
757
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("path")), cb_str_new(ctx.path));
810
758
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
811
- rb_hash_aset(
812
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
759
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
813
760
  if (ctx.retry_attempts > 0) {
814
761
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
815
762
  if (!ctx.retry_reasons.empty()) {
@@ -822,44 +769,32 @@ cb__map_error_code(const couchbase::error_context::http& ctx, const std::string&
822
769
  }
823
770
  }
824
771
  if (ctx.last_dispatched_to) {
825
- rb_hash_aset(error_context,
826
- rb_id2sym(rb_intern("last_dispatched_to")),
827
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
772
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
828
773
  }
829
774
  if (ctx.last_dispatched_from) {
830
- rb_hash_aset(error_context,
831
- rb_id2sym(rb_intern("last_dispatched_from")),
832
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
775
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
833
776
  }
834
777
  rb_iv_set(exc, "@context", error_context);
835
778
  return exc;
836
779
  }
837
780
 
838
781
  static VALUE
839
- cb__map_error_code(const couchbase::error_context::search& ctx, const std::string& message)
782
+ cb_map_error_code(const couchbase::error_context::search& ctx, const std::string& message)
840
783
  {
841
- VALUE exc = cb__map_error_code(ctx.ec, message);
784
+ VALUE exc = cb_map_error_code(ctx.ec, message);
842
785
  VALUE error_context = rb_hash_new();
843
786
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
844
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
845
- rb_hash_aset(error_context,
846
- rb_id2sym(rb_intern("client_context_id")),
847
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
848
- rb_hash_aset(error_context,
849
- rb_id2sym(rb_intern("index_name")),
850
- rb_external_str_new(ctx.index_name.data(), static_cast<long>(ctx.index_name.size())));
787
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
788
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
789
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("index_name")), cb_str_new(ctx.index_name));
851
790
  if (ctx.query) {
852
- rb_hash_aset(
853
- error_context, rb_id2sym(rb_intern("query")), rb_external_str_new(ctx.query->data(), static_cast<long>(ctx.query->size())));
791
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("query")), cb_str_new(ctx.query.value()));
854
792
  }
855
793
  if (ctx.parameters) {
856
- rb_hash_aset(error_context,
857
- rb_id2sym(rb_intern("parameters")),
858
- rb_external_str_new(ctx.parameters->data(), static_cast<long>(ctx.parameters->size())));
794
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), cb_str_new(ctx.parameters.value()));
859
795
  }
860
796
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
861
- rb_hash_aset(
862
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
797
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
863
798
  if (ctx.retry_attempts > 0) {
864
799
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
865
800
  if (!ctx.retry_reasons.empty()) {
@@ -872,19 +807,35 @@ cb__map_error_code(const couchbase::error_context::search& ctx, const std::strin
872
807
  }
873
808
  }
874
809
  if (ctx.last_dispatched_to) {
875
- rb_hash_aset(error_context,
876
- rb_id2sym(rb_intern("last_dispatched_to")),
877
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
810
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
878
811
  }
879
812
  if (ctx.last_dispatched_from) {
880
- rb_hash_aset(error_context,
881
- rb_id2sym(rb_intern("last_dispatched_from")),
882
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
813
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
883
814
  }
884
815
  rb_iv_set(exc, "@context", error_context);
885
816
  return exc;
886
817
  }
887
818
 
819
+ template<typename Future>
820
+ static auto
821
+ cb_wait_for_future(Future&& f) -> decltype(f.get())
822
+ {
823
+ struct arg_pack {
824
+ Future&& f;
825
+ decltype(f.get()) res{};
826
+ } arg{ f };
827
+ rb_thread_call_without_gvl(
828
+ [](void* param) -> void* {
829
+ auto* pack = static_cast<arg_pack*>(param);
830
+ pack->res = std::move(pack->f.get());
831
+ return nullptr;
832
+ },
833
+ &arg,
834
+ nullptr,
835
+ nullptr);
836
+ return std::move(arg.res);
837
+ }
838
+
888
839
  static VALUE
889
840
  cb_Backend_open(VALUE self, VALUE connection_string, VALUE credentials, VALUE options)
890
841
  {
@@ -961,8 +912,8 @@ cb_Backend_open(VALUE self, VALUE connection_string, VALUE credentials, VALUE op
961
912
  auto barrier = std::make_shared<std::promise<std::error_code>>();
962
913
  auto f = barrier->get_future();
963
914
  backend->cluster->open(origin, [barrier](std::error_code ec) mutable { barrier->set_value(ec); });
964
- if (auto ec = f.get()) {
965
- exc = cb__map_error_code(ec, fmt::format("unable open cluster at {}", origin.next_address().first));
915
+ if (auto ec = cb_wait_for_future(f)) {
916
+ exc = cb_map_error_code(ec, fmt::format("unable open cluster at {}", origin.next_address().first));
966
917
  }
967
918
  } while (false);
968
919
  if (!NIL_P(exc)) {
@@ -977,7 +928,7 @@ cb_Backend_close(VALUE self)
977
928
  {
978
929
  cb_backend_data* backend = nullptr;
979
930
  TypedData_Get_Struct(self, cb_backend_data, &cb_backend_type, backend);
980
- cb__backend_close(backend);
931
+ cb_backend_close(backend);
981
932
  return Qnil;
982
933
  }
983
934
 
@@ -1004,11 +955,11 @@ cb_Backend_diagnostics(VALUE self, VALUE report_id)
1004
955
  auto barrier = std::make_shared<std::promise<couchbase::diag::diagnostics_result>>();
1005
956
  auto f = barrier->get_future();
1006
957
  backend->cluster->diagnostics(id, [barrier](couchbase::diag::diagnostics_result&& resp) mutable { barrier->set_value(resp); });
1007
- auto resp = f.get();
958
+ auto resp = cb_wait_for_future(f);
1008
959
 
1009
960
  VALUE res = rb_hash_new();
1010
- rb_hash_aset(res, rb_id2sym(rb_intern("id")), rb_external_str_new(resp.id.data(), static_cast<long>(resp.id.size())));
1011
- rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), rb_external_str_new(resp.sdk.data(), static_cast<long>(resp.sdk.size())));
961
+ rb_hash_aset(res, rb_id2sym(rb_intern("id")), cb_str_new(resp.id));
962
+ rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), cb_str_new(resp.sdk));
1012
963
  rb_hash_aset(res, rb_id2sym(rb_intern("version")), INT2FIX(resp.version));
1013
964
  VALUE services = rb_hash_new();
1014
965
  rb_hash_aset(res, rb_id2sym(rb_intern("services")), services);
@@ -1041,11 +992,9 @@ cb_Backend_diagnostics(VALUE self, VALUE report_id)
1041
992
  if (svc.last_activity) {
1042
993
  rb_hash_aset(service, rb_id2sym(rb_intern("last_activity_us")), LL2NUM(svc.last_activity->count()));
1043
994
  }
1044
- rb_hash_aset(service, rb_id2sym(rb_intern("id")), rb_external_str_new(svc.id.data(), static_cast<long>(svc.id.size())));
1045
- rb_hash_aset(
1046
- service, rb_id2sym(rb_intern("remote")), rb_external_str_new(svc.remote.data(), static_cast<long>(svc.remote.size())));
1047
- rb_hash_aset(
1048
- service, rb_id2sym(rb_intern("local")), rb_external_str_new(svc.local.data(), static_cast<long>(svc.local.size())));
995
+ rb_hash_aset(service, rb_id2sym(rb_intern("id")), cb_str_new(svc.id));
996
+ rb_hash_aset(service, rb_id2sym(rb_intern("remote")), cb_str_new(svc.remote));
997
+ rb_hash_aset(service, rb_id2sym(rb_intern("local")), cb_str_new(svc.local));
1049
998
  VALUE state = Qnil;
1050
999
  switch (svc.state) {
1051
1000
  case couchbase::diag::endpoint_state::disconnected:
@@ -1062,9 +1011,7 @@ cb_Backend_diagnostics(VALUE self, VALUE report_id)
1062
1011
  break;
1063
1012
  }
1064
1013
  if (svc.details) {
1065
- rb_hash_aset(service,
1066
- rb_id2sym(rb_intern("details")),
1067
- rb_external_str_new(svc.details->data(), static_cast<long>(svc.details->size())));
1014
+ rb_hash_aset(service, rb_id2sym(rb_intern("details")), cb_str_new(svc.details.value()));
1068
1015
  }
1069
1016
  rb_hash_aset(service, rb_id2sym(rb_intern("state")), state);
1070
1017
  rb_ary_push(endpoints, service);
@@ -1098,11 +1045,11 @@ cb_Backend_open_bucket(VALUE self, VALUE bucket, VALUE wait_until_ready)
1098
1045
  auto barrier = std::make_shared<std::promise<std::error_code>>();
1099
1046
  auto f = barrier->get_future();
1100
1047
  backend->cluster->open_bucket(name, [barrier](std::error_code ec) mutable { barrier->set_value(ec); });
1101
- if (auto ec = f.get()) {
1102
- exc = cb__map_error_code(ec, fmt::format("unable open bucket \"{}\"", name));
1048
+ if (auto ec = cb_wait_for_future(f)) {
1049
+ exc = cb_map_error_code(ec, fmt::format("unable open bucket \"{}\"", name));
1103
1050
  }
1104
1051
  } else {
1105
- backend->cluster->open_bucket(name, [](std::error_code) {});
1052
+ backend->cluster->open_bucket(name, [](std::error_code /* ec */) {});
1106
1053
  }
1107
1054
  }
1108
1055
  if (!NIL_P(exc)) {
@@ -1114,12 +1061,12 @@ cb_Backend_open_bucket(VALUE self, VALUE bucket, VALUE wait_until_ready)
1114
1061
 
1115
1062
  template<typename Request>
1116
1063
  [[nodiscard]] VALUE
1117
- cb__extract_timeout(Request& req, VALUE options)
1064
+ cb_extract_timeout(Request& req, VALUE options)
1118
1065
  {
1119
1066
  if (!NIL_P(options)) {
1120
1067
  switch (TYPE(options)) {
1121
1068
  case T_HASH:
1122
- return cb__extract_timeout(req, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1069
+ return cb_extract_timeout(req, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1123
1070
  case T_FIXNUM:
1124
1071
  case T_BIGNUM:
1125
1072
  req.timeout = std::chrono::milliseconds(NUM2ULL(options));
@@ -1132,12 +1079,12 @@ cb__extract_timeout(Request& req, VALUE options)
1132
1079
  }
1133
1080
 
1134
1081
  [[nodiscard]] VALUE
1135
- cb__extract_timeout(std::chrono::milliseconds& timeout, VALUE options)
1082
+ cb_extract_timeout(std::chrono::milliseconds& timeout, VALUE options)
1136
1083
  {
1137
1084
  if (!NIL_P(options)) {
1138
1085
  switch (TYPE(options)) {
1139
1086
  case T_HASH:
1140
- return cb__extract_timeout(timeout, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1087
+ return cb_extract_timeout(timeout, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1141
1088
  case T_FIXNUM:
1142
1089
  case T_BIGNUM:
1143
1090
  timeout = std::chrono::milliseconds(NUM2ULL(options));
@@ -1150,7 +1097,7 @@ cb__extract_timeout(std::chrono::milliseconds& timeout, VALUE options)
1150
1097
  }
1151
1098
 
1152
1099
  [[nodiscard]] VALUE
1153
- cb__extract_option_bool(bool& field, VALUE options, const char* name)
1100
+ cb_extract_option_bool(bool& field, VALUE options, const char* name)
1154
1101
  {
1155
1102
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1156
1103
  VALUE val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1172,7 +1119,7 @@ cb__extract_option_bool(bool& field, VALUE options, const char* name)
1172
1119
  }
1173
1120
 
1174
1121
  [[nodiscard]] VALUE
1175
- cb__extract_option_array(VALUE& val, VALUE options, const char* name)
1122
+ cb_extract_option_array(VALUE& val, VALUE options, const char* name)
1176
1123
  {
1177
1124
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1178
1125
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1188,7 +1135,7 @@ cb__extract_option_array(VALUE& val, VALUE options, const char* name)
1188
1135
  }
1189
1136
 
1190
1137
  [[nodiscard]] VALUE
1191
- cb__extract_array_of_ids(std::vector<couchbase::document_id>& ids, VALUE arg)
1138
+ cb_extract_array_of_ids(std::vector<couchbase::document_id>& ids, VALUE arg)
1192
1139
  {
1193
1140
  if (TYPE(arg) != T_ARRAY) {
1194
1141
  return rb_exc_new_str(rb_eArgError, rb_sprintf("Type of IDs argument must be an Array, but given %+" PRIsVALUE, arg));
@@ -1227,7 +1174,7 @@ cb__extract_array_of_ids(std::vector<couchbase::document_id>& ids, VALUE arg)
1227
1174
  }
1228
1175
 
1229
1176
  [[nodiscard]] VALUE
1230
- cb__extract_array_of_id_content(std::vector<std::tuple<couchbase::document_id, std::string, std::uint32_t>>& id_content, VALUE arg)
1177
+ cb_extract_array_of_id_content(std::vector<std::tuple<couchbase::document_id, std::string, std::uint32_t>>& id_content, VALUE arg)
1231
1178
  {
1232
1179
  if (TYPE(arg) != T_ARRAY) {
1233
1180
  return rb_exc_new_str(rb_eArgError, rb_sprintf("Type of ID/content tuples must be an Array, but given %+" PRIsVALUE, arg));
@@ -1279,7 +1226,7 @@ cb__extract_array_of_id_content(std::vector<std::tuple<couchbase::document_id, s
1279
1226
  }
1280
1227
 
1281
1228
  [[nodiscard]] VALUE
1282
- cb__extract_array_of_id_cas(std::vector<std::pair<couchbase::document_id, std::uint64_t>>& id_cas, VALUE arg)
1229
+ cb_extract_array_of_id_cas(std::vector<std::pair<couchbase::document_id, std::uint64_t>>& id_cas, VALUE arg)
1283
1230
  {
1284
1231
  if (TYPE(arg) != T_ARRAY) {
1285
1232
  return rb_exc_new_str(rb_eArgError, rb_sprintf("Type of ID/CAS tuples must be an Array, but given %+" PRIsVALUE, arg));
@@ -1334,7 +1281,7 @@ cb__extract_array_of_id_cas(std::vector<std::pair<couchbase::document_id, std::u
1334
1281
  }
1335
1282
 
1336
1283
  [[nodiscard]] VALUE
1337
- cb__extract_option_symbol(VALUE& val, VALUE options, const char* name)
1284
+ cb_extract_option_symbol(VALUE& val, VALUE options, const char* name)
1338
1285
  {
1339
1286
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1340
1287
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1350,7 +1297,7 @@ cb__extract_option_symbol(VALUE& val, VALUE options, const char* name)
1350
1297
  }
1351
1298
 
1352
1299
  [[nodiscard]] VALUE
1353
- cb__extract_option_string(VALUE& val, VALUE options, const char* name)
1300
+ cb_extract_option_string(VALUE& val, VALUE options, const char* name)
1354
1301
  {
1355
1302
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1356
1303
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1366,7 +1313,7 @@ cb__extract_option_string(VALUE& val, VALUE options, const char* name)
1366
1313
  }
1367
1314
 
1368
1315
  [[nodiscard]] VALUE
1369
- cb__extract_option_fixnum(VALUE& val, VALUE options, const char* name)
1316
+ cb_extract_option_fixnum(VALUE& val, VALUE options, const char* name)
1370
1317
  {
1371
1318
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1372
1319
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1382,7 +1329,7 @@ cb__extract_option_fixnum(VALUE& val, VALUE options, const char* name)
1382
1329
  }
1383
1330
 
1384
1331
  [[nodiscard]] VALUE
1385
- cb__extract_option_bignum(VALUE& val, VALUE options, const char* name)
1332
+ cb_extract_option_bignum(VALUE& val, VALUE options, const char* name)
1386
1333
  {
1387
1334
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1388
1335
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1402,10 +1349,10 @@ cb__extract_option_bignum(VALUE& val, VALUE options, const char* name)
1402
1349
  }
1403
1350
 
1404
1351
  [[nodiscard]] VALUE
1405
- cb__extract_durability(couchbase::protocol::durability_level& output_level, std::optional<std::uint16_t>& output_timeout, VALUE options)
1352
+ cb_extract_durability(couchbase::protocol::durability_level& output_level, std::optional<std::uint16_t>& output_timeout, VALUE options)
1406
1353
  {
1407
1354
  VALUE durability_level = Qnil;
1408
- VALUE exc = cb__extract_option_symbol(durability_level, options, "durability_level");
1355
+ VALUE exc = cb_extract_option_symbol(durability_level, options, "durability_level");
1409
1356
  if (!NIL_P(exc)) {
1410
1357
  return exc;
1411
1358
  }
@@ -1423,7 +1370,7 @@ cb__extract_durability(couchbase::protocol::durability_level& output_level, std:
1423
1370
  return rb_exc_new_str(eInvalidArgument, rb_sprintf("unknown durability level: %+" PRIsVALUE, durability_level));
1424
1371
  }
1425
1372
  VALUE durability_timeout = Qnil;
1426
- exc = cb__extract_option_fixnum(durability_timeout, options, "durability_timeout");
1373
+ exc = cb_extract_option_fixnum(durability_timeout, options, "durability_timeout");
1427
1374
  if (!NIL_P(exc)) {
1428
1375
  return exc;
1429
1376
  }
@@ -1436,9 +1383,9 @@ cb__extract_durability(couchbase::protocol::durability_level& output_level, std:
1436
1383
 
1437
1384
  template<typename Request>
1438
1385
  [[nodiscard]] VALUE
1439
- cb__extract_durability(Request& req, VALUE options)
1386
+ cb_extract_durability(Request& req, VALUE options)
1440
1387
  {
1441
- return cb__extract_durability(req.durability_level, req.durability_timeout, options);
1388
+ return cb_extract_durability(req.durability_level, req.durability_timeout, options);
1442
1389
  }
1443
1390
 
1444
1391
  static VALUE
@@ -1462,7 +1409,7 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1462
1409
  VALUE exc = Qnil;
1463
1410
  do {
1464
1411
  VALUE id = Qnil;
1465
- exc = cb__extract_option_string(id, options, "report_id");
1412
+ exc = cb_extract_option_string(id, options, "report_id");
1466
1413
  if (!NIL_P(exc)) {
1467
1414
  break;
1468
1415
  }
@@ -1475,7 +1422,7 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1475
1422
  bucket_name.emplace(std::string(RSTRING_PTR(bucket), static_cast<size_t>(RSTRING_LEN(bucket))));
1476
1423
  }
1477
1424
  VALUE services = Qnil;
1478
- exc = cb__extract_option_array(services, options, "service_types");
1425
+ exc = cb_extract_option_array(services, options, "service_types");
1479
1426
  if (!NIL_P(exc)) {
1480
1427
  break;
1481
1428
  }
@@ -1501,11 +1448,11 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1501
1448
  auto f = barrier->get_future();
1502
1449
  backend->cluster->ping(
1503
1450
  report_id, bucket_name, selected_services, [barrier](couchbase::diag::ping_result&& resp) mutable { barrier->set_value(resp); });
1504
- auto resp = f.get();
1451
+ auto resp = cb_wait_for_future(f);
1505
1452
 
1506
1453
  VALUE res = rb_hash_new();
1507
- rb_hash_aset(res, rb_id2sym(rb_intern("id")), rb_external_str_new(resp.id.data(), static_cast<long>(resp.id.size())));
1508
- rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), rb_external_str_new(resp.sdk.data(), static_cast<long>(resp.sdk.size())));
1454
+ rb_hash_aset(res, rb_id2sym(rb_intern("id")), cb_str_new(resp.id));
1455
+ rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), cb_str_new(resp.sdk));
1509
1456
  rb_hash_aset(res, rb_id2sym(rb_intern("version")), INT2FIX(resp.version));
1510
1457
  services = rb_hash_new();
1511
1458
  rb_hash_aset(res, rb_id2sym(rb_intern("services")), services);
@@ -1536,11 +1483,9 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1536
1483
  for (const auto& svc : svcs.second) {
1537
1484
  VALUE service = rb_hash_new();
1538
1485
  rb_hash_aset(service, rb_id2sym(rb_intern("latency")), LL2NUM(svc.latency.count()));
1539
- rb_hash_aset(service, rb_id2sym(rb_intern("id")), rb_external_str_new(svc.id.data(), static_cast<long>(svc.id.size())));
1540
- rb_hash_aset(
1541
- service, rb_id2sym(rb_intern("remote")), rb_external_str_new(svc.remote.data(), static_cast<long>(svc.remote.size())));
1542
- rb_hash_aset(
1543
- service, rb_id2sym(rb_intern("local")), rb_external_str_new(svc.local.data(), static_cast<long>(svc.local.size())));
1486
+ rb_hash_aset(service, rb_id2sym(rb_intern("id")), cb_str_new(svc.id));
1487
+ rb_hash_aset(service, rb_id2sym(rb_intern("remote")), cb_str_new(svc.remote));
1488
+ rb_hash_aset(service, rb_id2sym(rb_intern("local")), cb_str_new(svc.local));
1544
1489
  VALUE state = Qnil;
1545
1490
  switch (svc.state) {
1546
1491
  case couchbase::diag::ping_state::ok:
@@ -1552,9 +1497,7 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1552
1497
  case couchbase::diag::ping_state::error:
1553
1498
  state = rb_id2sym(rb_intern("error"));
1554
1499
  if (svc.error) {
1555
- rb_hash_aset(service,
1556
- rb_id2sym(rb_intern("error")),
1557
- rb_external_str_new(svc.error->data(), static_cast<long>(svc.error->size())));
1500
+ rb_hash_aset(service, rb_id2sym(rb_intern("error")), cb_str_new(svc.error.value()));
1558
1501
  }
1559
1502
  break;
1560
1503
  }
@@ -1591,21 +1534,21 @@ cb_Backend_document_get(VALUE self, VALUE bucket, VALUE collection, VALUE id, VA
1591
1534
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1592
1535
 
1593
1536
  couchbase::operations::get_request req{ doc_id };
1594
- exc = cb__extract_timeout(req, options);
1537
+ exc = cb_extract_timeout(req, options);
1595
1538
  if (!NIL_P(exc)) {
1596
1539
  break;
1597
1540
  }
1598
1541
  auto barrier = std::make_shared<std::promise<couchbase::operations::get_response>>();
1599
1542
  auto f = barrier->get_future();
1600
1543
  backend->cluster->execute(req, [barrier](couchbase::operations::get_response&& resp) mutable { barrier->set_value(resp); });
1601
- auto resp = f.get();
1544
+ auto resp = cb_wait_for_future(f);
1602
1545
  if (resp.ctx.ec) {
1603
- exc = cb__map_error_code(resp.ctx, "unable to fetch document");
1546
+ exc = cb_map_error_code(resp.ctx, "unable to fetch document");
1604
1547
  break;
1605
1548
  }
1606
1549
 
1607
1550
  VALUE res = rb_hash_new();
1608
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1551
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1609
1552
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1610
1553
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1611
1554
  return res;
@@ -1628,13 +1571,13 @@ cb_Backend_document_get_multi(VALUE self, VALUE keys, VALUE options)
1628
1571
  VALUE exc = Qnil;
1629
1572
  do {
1630
1573
  std::chrono::milliseconds timeout{ 0 };
1631
- exc = cb__extract_timeout(timeout, options);
1574
+ exc = cb_extract_timeout(timeout, options);
1632
1575
  if (!NIL_P(exc)) {
1633
1576
  break;
1634
1577
  }
1635
1578
 
1636
1579
  std::vector<couchbase::document_id> ids{};
1637
- exc = cb__extract_array_of_ids(ids, keys);
1580
+ exc = cb_extract_array_of_ids(ids, keys);
1638
1581
  if (!NIL_P(exc)) {
1639
1582
  break;
1640
1583
  }
@@ -1658,10 +1601,9 @@ cb_Backend_document_get_multi(VALUE self, VALUE keys, VALUE options)
1658
1601
  auto resp = barrier->get_future().get();
1659
1602
  VALUE entry = rb_hash_new();
1660
1603
  if (resp.ctx.ec) {
1661
- rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb__map_error_code(resp.ctx, "unable to (multi)fetch document"));
1604
+ rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb_map_error_code(resp.ctx, "unable to (multi)fetch document"));
1662
1605
  }
1663
- rb_hash_aset(
1664
- entry, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1606
+ rb_hash_aset(entry, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1665
1607
  rb_hash_aset(entry, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1666
1608
  rb_hash_aset(entry, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1667
1609
  rb_ary_push(res, entry);
@@ -1698,20 +1640,20 @@ cb_Backend_document_get_projected(VALUE self, VALUE bucket, VALUE collection, VA
1698
1640
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1699
1641
 
1700
1642
  couchbase::operations::get_projected_request req{ doc_id };
1701
- exc = cb__extract_timeout(req, options);
1643
+ exc = cb_extract_timeout(req, options);
1702
1644
  if (!NIL_P(exc)) {
1703
1645
  break;
1704
1646
  }
1705
- exc = cb__extract_option_bool(req.with_expiry, options, "with_expiry");
1647
+ exc = cb_extract_option_bool(req.with_expiry, options, "with_expiry");
1706
1648
  if (!NIL_P(exc)) {
1707
1649
  break;
1708
1650
  }
1709
- exc = cb__extract_option_bool(req.preserve_array_indexes, options, "preserve_array_indexes");
1651
+ exc = cb_extract_option_bool(req.preserve_array_indexes, options, "preserve_array_indexes");
1710
1652
  if (!NIL_P(exc)) {
1711
1653
  break;
1712
1654
  }
1713
1655
  VALUE projections = Qnil;
1714
- exc = cb__extract_option_array(projections, options, "projections");
1656
+ exc = cb_extract_option_array(projections, options, "projections");
1715
1657
  if (!NIL_P(exc)) {
1716
1658
  break;
1717
1659
  }
@@ -1733,14 +1675,14 @@ cb_Backend_document_get_projected(VALUE self, VALUE bucket, VALUE collection, VA
1733
1675
  auto f = barrier->get_future();
1734
1676
  backend->cluster->execute(req,
1735
1677
  [barrier](couchbase::operations::get_projected_response&& resp) mutable { barrier->set_value(resp); });
1736
- auto resp = f.get();
1678
+ auto resp = cb_wait_for_future(f);
1737
1679
  if (resp.ctx.ec) {
1738
- exc = cb__map_error_code(resp.ctx, "unable fetch with projections");
1680
+ exc = cb_map_error_code(resp.ctx, "unable fetch with projections");
1739
1681
  break;
1740
1682
  }
1741
1683
 
1742
1684
  VALUE res = rb_hash_new();
1743
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1685
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1744
1686
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1745
1687
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1746
1688
  if (resp.expiry) {
@@ -1779,7 +1721,7 @@ cb_Backend_document_get_and_lock(VALUE self, VALUE bucket, VALUE collection, VAL
1779
1721
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1780
1722
 
1781
1723
  couchbase::operations::get_and_lock_request req{ doc_id };
1782
- exc = cb__extract_timeout(req, options);
1724
+ exc = cb_extract_timeout(req, options);
1783
1725
  if (!NIL_P(exc)) {
1784
1726
  break;
1785
1727
  }
@@ -1789,14 +1731,14 @@ cb_Backend_document_get_and_lock(VALUE self, VALUE bucket, VALUE collection, VAL
1789
1731
  auto f = barrier->get_future();
1790
1732
  backend->cluster->execute(req,
1791
1733
  [barrier](couchbase::operations::get_and_lock_response&& resp) mutable { barrier->set_value(resp); });
1792
- auto resp = f.get();
1734
+ auto resp = cb_wait_for_future(f);
1793
1735
  if (resp.ctx.ec) {
1794
- exc = cb__map_error_code(resp.ctx, "unable lock and fetch");
1736
+ exc = cb_map_error_code(resp.ctx, "unable lock and fetch");
1795
1737
  break;
1796
1738
  }
1797
1739
 
1798
1740
  VALUE res = rb_hash_new();
1799
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1741
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1800
1742
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1801
1743
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1802
1744
  return res;
@@ -1832,7 +1774,7 @@ cb_Backend_document_get_and_touch(VALUE self, VALUE bucket, VALUE collection, VA
1832
1774
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1833
1775
 
1834
1776
  couchbase::operations::get_and_touch_request req{ doc_id };
1835
- exc = cb__extract_timeout(req, options);
1777
+ exc = cb_extract_timeout(req, options);
1836
1778
  if (!NIL_P(exc)) {
1837
1779
  break;
1838
1780
  }
@@ -1842,14 +1784,14 @@ cb_Backend_document_get_and_touch(VALUE self, VALUE bucket, VALUE collection, VA
1842
1784
  auto f = barrier->get_future();
1843
1785
  backend->cluster->execute(req,
1844
1786
  [barrier](couchbase::operations::get_and_touch_response&& resp) mutable { barrier->set_value(resp); });
1845
- auto resp = f.get();
1787
+ auto resp = cb_wait_for_future(f);
1846
1788
  if (resp.ctx.ec) {
1847
- exc = cb__map_error_code(resp.ctx, "unable fetch and touch");
1789
+ exc = cb_map_error_code(resp.ctx, "unable fetch and touch");
1848
1790
  break;
1849
1791
  }
1850
1792
 
1851
1793
  VALUE res = rb_hash_new();
1852
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1794
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1853
1795
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1854
1796
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1855
1797
  return res;
@@ -1860,7 +1802,7 @@ cb_Backend_document_get_and_touch(VALUE self, VALUE bucket, VALUE collection, VA
1860
1802
 
1861
1803
  template<typename Response>
1862
1804
  static VALUE
1863
- cb__extract_mutation_result(Response resp)
1805
+ cb_extract_mutation_result(Response resp)
1864
1806
  {
1865
1807
  VALUE res = rb_hash_new();
1866
1808
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
@@ -1868,9 +1810,7 @@ cb__extract_mutation_result(Response resp)
1868
1810
  rb_hash_aset(token, rb_id2sym(rb_intern("partition_uuid")), ULL2NUM(resp.token.partition_uuid));
1869
1811
  rb_hash_aset(token, rb_id2sym(rb_intern("sequence_number")), ULL2NUM(resp.token.sequence_number));
1870
1812
  rb_hash_aset(token, rb_id2sym(rb_intern("partition_id")), UINT2NUM(resp.token.partition_id));
1871
- rb_hash_aset(token,
1872
- rb_id2sym(rb_intern("bucket_name")),
1873
- rb_external_str_new(resp.token.bucket_name.c_str(), static_cast<long>(resp.token.bucket_name.size())));
1813
+ rb_hash_aset(token, rb_id2sym(rb_intern("bucket_name")), cb_str_new(resp.token.bucket_name));
1874
1814
  rb_hash_aset(res, rb_id2sym(rb_intern("mutation_token")), token);
1875
1815
  return res;
1876
1816
  }
@@ -1902,7 +1842,7 @@ cb_Backend_document_touch(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1902
1842
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1903
1843
 
1904
1844
  couchbase::operations::touch_request req{ doc_id };
1905
- exc = cb__extract_timeout(req, options);
1845
+ exc = cb_extract_timeout(req, options);
1906
1846
  if (!NIL_P(exc)) {
1907
1847
  break;
1908
1848
  }
@@ -1911,9 +1851,9 @@ cb_Backend_document_touch(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1911
1851
  auto barrier = std::make_shared<std::promise<couchbase::operations::touch_response>>();
1912
1852
  auto f = barrier->get_future();
1913
1853
  backend->cluster->execute(req, [barrier](couchbase::operations::touch_response&& resp) mutable { barrier->set_value(resp); });
1914
- auto resp = f.get();
1854
+ auto resp = cb_wait_for_future(f);
1915
1855
  if (resp.ctx.ec) {
1916
- exc = cb__map_error_code(resp.ctx, "unable to touch");
1856
+ exc = cb_map_error_code(resp.ctx, "unable to touch");
1917
1857
  break;
1918
1858
  }
1919
1859
 
@@ -1951,7 +1891,7 @@ cb_Backend_document_exists(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1951
1891
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1952
1892
 
1953
1893
  couchbase::operations::exists_request req{ doc_id };
1954
- exc = cb__extract_timeout(req, options);
1894
+ exc = cb_extract_timeout(req, options);
1955
1895
  if (!NIL_P(exc)) {
1956
1896
  break;
1957
1897
  }
@@ -1959,9 +1899,9 @@ cb_Backend_document_exists(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1959
1899
  auto barrier = std::make_shared<std::promise<couchbase::operations::exists_response>>();
1960
1900
  auto f = barrier->get_future();
1961
1901
  backend->cluster->execute(req, [barrier](couchbase::operations::exists_response&& resp) mutable { barrier->set_value(resp); });
1962
- auto resp = f.get();
1902
+ auto resp = cb_wait_for_future(f);
1963
1903
  if (resp.ctx.ec) {
1964
- exc = cb__map_error_code(resp.ctx, "unable to exists");
1904
+ exc = cb_map_error_code(resp.ctx, "unable to exists");
1965
1905
  break;
1966
1906
  }
1967
1907
 
@@ -2017,7 +1957,7 @@ cb_Backend_document_unlock(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2017
1957
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2018
1958
 
2019
1959
  couchbase::operations::unlock_request req{ doc_id };
2020
- exc = cb__extract_timeout(req, options);
1960
+ exc = cb_extract_timeout(req, options);
2021
1961
  if (!NIL_P(exc)) {
2022
1962
  break;
2023
1963
  }
@@ -2036,9 +1976,9 @@ cb_Backend_document_unlock(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2036
1976
  auto barrier = std::make_shared<std::promise<couchbase::operations::unlock_response>>();
2037
1977
  auto f = barrier->get_future();
2038
1978
  backend->cluster->execute(req, [barrier](couchbase::operations::unlock_response&& resp) mutable { barrier->set_value(resp); });
2039
- auto resp = f.get();
1979
+ auto resp = cb_wait_for_future(f);
2040
1980
  if (resp.ctx.ec) {
2041
- exc = cb__map_error_code(resp.ctx, "unable to unlock");
1981
+ exc = cb_map_error_code(resp.ctx, "unable to unlock");
2042
1982
  break;
2043
1983
  }
2044
1984
 
@@ -2079,35 +2019,39 @@ cb_Backend_document_upsert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2079
2019
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2080
2020
 
2081
2021
  couchbase::operations::upsert_request req{ doc_id, value };
2082
- exc = cb__extract_timeout(req, options);
2022
+ exc = cb_extract_timeout(req, options);
2083
2023
  if (!NIL_P(exc)) {
2084
2024
  break;
2085
2025
  }
2086
2026
  req.flags = FIX2UINT(flags);
2087
2027
 
2088
- exc = cb__extract_durability(req, options);
2028
+ exc = cb_extract_durability(req, options);
2089
2029
  if (!NIL_P(exc)) {
2090
2030
  break;
2091
2031
  }
2092
2032
  VALUE expiry = Qnil;
2093
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2033
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2094
2034
  if (!NIL_P(exc)) {
2095
2035
  break;
2096
2036
  }
2097
2037
  if (!NIL_P(expiry)) {
2098
2038
  req.expiry = FIX2UINT(expiry);
2099
2039
  }
2040
+ exc = cb_extract_option_bool(req.preserve_expiry, options, "preserve_expiry");
2041
+ if (!NIL_P(exc)) {
2042
+ break;
2043
+ }
2100
2044
 
2101
2045
  auto barrier = std::make_shared<std::promise<couchbase::operations::upsert_response>>();
2102
2046
  auto f = barrier->get_future();
2103
2047
  backend->cluster->execute(req, [barrier](couchbase::operations::upsert_response&& resp) mutable { barrier->set_value(resp); });
2104
- auto resp = f.get();
2048
+ auto resp = cb_wait_for_future(f);
2105
2049
  if (resp.ctx.ec) {
2106
- exc = cb__map_error_code(resp.ctx, "unable to upsert");
2050
+ exc = cb_map_error_code(resp.ctx, "unable to upsert");
2107
2051
  break;
2108
2052
  }
2109
2053
 
2110
- return cb__extract_mutation_result(resp);
2054
+ return cb_extract_mutation_result(resp);
2111
2055
  } while (false);
2112
2056
  rb_exc_raise(exc);
2113
2057
  return Qnil;
@@ -2127,25 +2071,30 @@ cb_Backend_document_upsert_multi(VALUE self, VALUE id_content, VALUE options)
2127
2071
  VALUE exc = Qnil;
2128
2072
  do {
2129
2073
  std::chrono::milliseconds timeout{ 0 };
2130
- exc = cb__extract_timeout(timeout, options);
2074
+ exc = cb_extract_timeout(timeout, options);
2131
2075
  if (!NIL_P(exc)) {
2132
2076
  break;
2133
2077
  }
2134
2078
 
2135
2079
  couchbase::protocol::durability_level durability_level{ couchbase::protocol::durability_level::none };
2136
2080
  std::optional<std::uint16_t> durability_timeout{ std::nullopt };
2137
- exc = cb__extract_durability(durability_level, durability_timeout, options);
2081
+ exc = cb_extract_durability(durability_level, durability_timeout, options);
2138
2082
  if (!NIL_P(exc)) {
2139
2083
  break;
2140
2084
  }
2141
2085
  VALUE expiry = Qnil;
2142
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2086
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2087
+ if (!NIL_P(exc)) {
2088
+ break;
2089
+ }
2090
+ bool preserve_expiry{ false };
2091
+ exc = cb_extract_option_bool(preserve_expiry, options, "preserve_expiry");
2143
2092
  if (!NIL_P(exc)) {
2144
2093
  break;
2145
2094
  }
2146
2095
 
2147
2096
  std::vector<std::tuple<couchbase::document_id, std::string, std::uint32_t>> tuples{};
2148
- exc = cb__extract_array_of_id_content(tuples, id_content);
2097
+ exc = cb_extract_array_of_id_content(tuples, id_content);
2149
2098
  if (!NIL_P(exc)) {
2150
2099
  break;
2151
2100
  }
@@ -2165,6 +2114,7 @@ cb_Backend_document_upsert_multi(VALUE self, VALUE id_content, VALUE options)
2165
2114
  if (!NIL_P(expiry)) {
2166
2115
  req.expiry = FIX2UINT(expiry);
2167
2116
  }
2117
+ req.preserve_expiry = preserve_expiry;
2168
2118
  auto barrier = std::make_shared<std::promise<couchbase::operations::upsert_response>>();
2169
2119
  backend->cluster->execute(req, [barrier](couchbase::operations::upsert_response&& resp) mutable { barrier->set_value(resp); });
2170
2120
  barriers.emplace_back(barrier);
@@ -2173,9 +2123,9 @@ cb_Backend_document_upsert_multi(VALUE self, VALUE id_content, VALUE options)
2173
2123
  VALUE res = rb_ary_new_capa(static_cast<long>(num_of_tuples));
2174
2124
  for (auto& barrier : barriers) {
2175
2125
  auto resp = barrier->get_future().get();
2176
- VALUE entry = cb__extract_mutation_result(resp);
2126
+ VALUE entry = cb_extract_mutation_result(resp);
2177
2127
  if (resp.ctx.ec) {
2178
- rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb__map_error_code(resp.ctx, "unable (multi)upsert"));
2128
+ rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb_map_error_code(resp.ctx, "unable (multi)upsert"));
2179
2129
  }
2180
2130
  rb_ary_push(res, entry);
2181
2131
  }
@@ -2213,11 +2163,11 @@ cb_Backend_document_append(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2213
2163
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2214
2164
 
2215
2165
  couchbase::operations::append_request req{ doc_id, value };
2216
- exc = cb__extract_timeout(req, options);
2166
+ exc = cb_extract_timeout(req, options);
2217
2167
  if (!NIL_P(exc)) {
2218
2168
  break;
2219
2169
  }
2220
- exc = cb__extract_durability(req, options);
2170
+ exc = cb_extract_durability(req, options);
2221
2171
  if (!NIL_P(exc)) {
2222
2172
  break;
2223
2173
  }
@@ -2225,13 +2175,13 @@ cb_Backend_document_append(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2225
2175
  auto barrier = std::make_shared<std::promise<couchbase::operations::append_response>>();
2226
2176
  auto f = barrier->get_future();
2227
2177
  backend->cluster->execute(req, [barrier](couchbase::operations::append_response&& resp) mutable { barrier->set_value(resp); });
2228
- auto resp = f.get();
2178
+ auto resp = cb_wait_for_future(f);
2229
2179
  if (resp.ctx.ec) {
2230
- exc = cb__map_error_code(resp.ctx, "unable to append");
2180
+ exc = cb_map_error_code(resp.ctx, "unable to append");
2231
2181
  break;
2232
2182
  }
2233
2183
 
2234
- return cb__extract_mutation_result(resp);
2184
+ return cb_extract_mutation_result(resp);
2235
2185
  } while (false);
2236
2186
  rb_exc_raise(exc);
2237
2187
  return Qnil;
@@ -2265,11 +2215,11 @@ cb_Backend_document_prepend(VALUE self, VALUE bucket, VALUE collection, VALUE id
2265
2215
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2266
2216
 
2267
2217
  couchbase::operations::prepend_request req{ doc_id, value };
2268
- exc = cb__extract_timeout(req, options);
2218
+ exc = cb_extract_timeout(req, options);
2269
2219
  if (!NIL_P(exc)) {
2270
2220
  break;
2271
2221
  }
2272
- exc = cb__extract_durability(req, options);
2222
+ exc = cb_extract_durability(req, options);
2273
2223
  if (!NIL_P(exc)) {
2274
2224
  break;
2275
2225
  }
@@ -2277,13 +2227,13 @@ cb_Backend_document_prepend(VALUE self, VALUE bucket, VALUE collection, VALUE id
2277
2227
  auto barrier = std::make_shared<std::promise<couchbase::operations::prepend_response>>();
2278
2228
  auto f = barrier->get_future();
2279
2229
  backend->cluster->execute(req, [barrier](couchbase::operations::prepend_response&& resp) mutable { barrier->set_value(resp); });
2280
- auto resp = f.get();
2230
+ auto resp = cb_wait_for_future(f);
2281
2231
  if (resp.ctx.ec) {
2282
- exc = cb__map_error_code(resp.ctx, "unable to prepend");
2232
+ exc = cb_map_error_code(resp.ctx, "unable to prepend");
2283
2233
  break;
2284
2234
  }
2285
2235
 
2286
- return cb__extract_mutation_result(resp);
2236
+ return cb_extract_mutation_result(resp);
2287
2237
  } while (false);
2288
2238
  rb_exc_raise(exc);
2289
2239
  return Qnil;
@@ -2318,26 +2268,30 @@ cb_Backend_document_replace(VALUE self, VALUE bucket, VALUE collection, VALUE id
2318
2268
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2319
2269
 
2320
2270
  couchbase::operations::replace_request req{ doc_id, value };
2321
- exc = cb__extract_timeout(req, options);
2271
+ exc = cb_extract_timeout(req, options);
2322
2272
  if (!NIL_P(exc)) {
2323
2273
  break;
2324
2274
  }
2325
2275
  req.flags = FIX2UINT(flags);
2326
2276
 
2327
- exc = cb__extract_durability(req, options);
2277
+ exc = cb_extract_durability(req, options);
2328
2278
  if (!NIL_P(exc)) {
2329
2279
  break;
2330
2280
  }
2331
2281
  VALUE expiry = Qnil;
2332
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2282
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2333
2283
  if (!NIL_P(exc)) {
2334
2284
  break;
2335
2285
  }
2336
2286
  if (!NIL_P(expiry)) {
2337
2287
  req.expiry = FIX2UINT(expiry);
2338
2288
  }
2289
+ exc = cb_extract_option_bool(req.preserve_expiry, options, "preserve_expiry");
2290
+ if (!NIL_P(exc)) {
2291
+ break;
2292
+ }
2339
2293
  VALUE cas = Qnil;
2340
- exc = cb__extract_option_bignum(cas, options, "cas");
2294
+ exc = cb_extract_option_bignum(cas, options, "cas");
2341
2295
  if (!NIL_P(exc)) {
2342
2296
  break;
2343
2297
  }
@@ -2348,13 +2302,13 @@ cb_Backend_document_replace(VALUE self, VALUE bucket, VALUE collection, VALUE id
2348
2302
  auto barrier = std::make_shared<std::promise<couchbase::operations::replace_response>>();
2349
2303
  auto f = barrier->get_future();
2350
2304
  backend->cluster->execute(req, [barrier](couchbase::operations::replace_response&& resp) mutable { barrier->set_value(resp); });
2351
- auto resp = f.get();
2305
+ auto resp = cb_wait_for_future(f);
2352
2306
  if (resp.ctx.ec) {
2353
- exc = cb__map_error_code(resp.ctx, "unable to replace");
2307
+ exc = cb_map_error_code(resp.ctx, "unable to replace");
2354
2308
  break;
2355
2309
  }
2356
2310
 
2357
- return cb__extract_mutation_result(resp);
2311
+ return cb_extract_mutation_result(resp);
2358
2312
  } while (false);
2359
2313
  rb_exc_raise(exc);
2360
2314
  return Qnil;
@@ -2389,18 +2343,18 @@ cb_Backend_document_insert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2389
2343
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2390
2344
 
2391
2345
  couchbase::operations::insert_request req{ doc_id, value };
2392
- exc = cb__extract_timeout(req, options);
2346
+ exc = cb_extract_timeout(req, options);
2393
2347
  if (!NIL_P(exc)) {
2394
2348
  break;
2395
2349
  }
2396
2350
  req.flags = FIX2UINT(flags);
2397
2351
 
2398
- exc = cb__extract_durability(req, options);
2352
+ exc = cb_extract_durability(req, options);
2399
2353
  if (!NIL_P(exc)) {
2400
2354
  break;
2401
2355
  }
2402
2356
  VALUE expiry = Qnil;
2403
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2357
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2404
2358
  if (!NIL_P(exc)) {
2405
2359
  break;
2406
2360
  }
@@ -2411,13 +2365,13 @@ cb_Backend_document_insert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2411
2365
  auto barrier = std::make_shared<std::promise<couchbase::operations::insert_response>>();
2412
2366
  auto f = barrier->get_future();
2413
2367
  backend->cluster->execute(req, [barrier](couchbase::operations::insert_response&& resp) mutable { barrier->set_value(resp); });
2414
- auto resp = f.get();
2368
+ auto resp = cb_wait_for_future(f);
2415
2369
  if (resp.ctx.ec) {
2416
- exc = cb__map_error_code(resp.ctx, "unable to insert");
2370
+ exc = cb_map_error_code(resp.ctx, "unable to insert");
2417
2371
  break;
2418
2372
  }
2419
2373
 
2420
- return cb__extract_mutation_result(resp);
2374
+ return cb_extract_mutation_result(resp);
2421
2375
  } while (false);
2422
2376
  rb_exc_raise(exc);
2423
2377
  return Qnil;
@@ -2449,16 +2403,16 @@ cb_Backend_document_remove(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2449
2403
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2450
2404
 
2451
2405
  couchbase::operations::remove_request req{ doc_id };
2452
- exc = cb__extract_timeout(req, options);
2406
+ exc = cb_extract_timeout(req, options);
2453
2407
  if (!NIL_P(exc)) {
2454
2408
  break;
2455
2409
  }
2456
- exc = cb__extract_durability(req, options);
2410
+ exc = cb_extract_durability(req, options);
2457
2411
  if (!NIL_P(exc)) {
2458
2412
  break;
2459
2413
  }
2460
2414
  VALUE cas = Qnil;
2461
- exc = cb__extract_option_bignum(cas, options, "cas");
2415
+ exc = cb_extract_option_bignum(cas, options, "cas");
2462
2416
  if (!NIL_P(exc)) {
2463
2417
  break;
2464
2418
  }
@@ -2469,12 +2423,12 @@ cb_Backend_document_remove(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2469
2423
  auto barrier = std::make_shared<std::promise<couchbase::operations::remove_response>>();
2470
2424
  auto f = barrier->get_future();
2471
2425
  backend->cluster->execute(req, [barrier](couchbase::operations::remove_response&& resp) mutable { barrier->set_value(resp); });
2472
- auto resp = f.get();
2426
+ auto resp = cb_wait_for_future(f);
2473
2427
  if (resp.ctx.ec) {
2474
- exc = cb__map_error_code(resp.ctx, "unable to remove");
2428
+ exc = cb_map_error_code(resp.ctx, "unable to remove");
2475
2429
  break;
2476
2430
  }
2477
- return cb__extract_mutation_result(resp);
2431
+ return cb_extract_mutation_result(resp);
2478
2432
  } while (false);
2479
2433
  rb_exc_raise(exc);
2480
2434
  return Qnil;
@@ -2498,20 +2452,20 @@ cb_Backend_document_remove_multi(VALUE self, VALUE id_cas, VALUE options)
2498
2452
  VALUE exc = Qnil;
2499
2453
  do {
2500
2454
  std::chrono::milliseconds timeout{ 0 };
2501
- exc = cb__extract_timeout(timeout, options);
2455
+ exc = cb_extract_timeout(timeout, options);
2502
2456
  if (!NIL_P(exc)) {
2503
2457
  break;
2504
2458
  }
2505
2459
 
2506
2460
  couchbase::protocol::durability_level durability_level{ couchbase::protocol::durability_level::none };
2507
2461
  std::optional<std::uint16_t> durability_timeout{ std::nullopt };
2508
- exc = cb__extract_durability(durability_level, durability_timeout, options);
2462
+ exc = cb_extract_durability(durability_level, durability_timeout, options);
2509
2463
  if (!NIL_P(exc)) {
2510
2464
  break;
2511
2465
  }
2512
2466
 
2513
2467
  std::vector<std::pair<couchbase::document_id, std::uint64_t>> tuples{};
2514
- exc = cb__extract_array_of_id_cas(tuples, id_cas);
2468
+ exc = cb_extract_array_of_id_cas(tuples, id_cas);
2515
2469
  if (!NIL_P(exc)) {
2516
2470
  break;
2517
2471
  }
@@ -2536,9 +2490,9 @@ cb_Backend_document_remove_multi(VALUE self, VALUE id_cas, VALUE options)
2536
2490
  VALUE res = rb_ary_new_capa(static_cast<long>(num_of_tuples));
2537
2491
  for (auto& barrier : barriers) {
2538
2492
  auto resp = barrier->get_future().get();
2539
- VALUE entry = cb__extract_mutation_result(resp);
2493
+ VALUE entry = cb_extract_mutation_result(resp);
2540
2494
  if (resp.ctx.ec) {
2541
- rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb__map_error_code(resp.ctx, "unable (multi)remove"));
2495
+ rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb_map_error_code(resp.ctx, "unable (multi)remove"));
2542
2496
  }
2543
2497
  rb_ary_push(res, entry);
2544
2498
  }
@@ -2575,16 +2529,16 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2575
2529
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2576
2530
 
2577
2531
  couchbase::operations::increment_request req{ doc_id };
2578
- exc = cb__extract_timeout(req, options);
2532
+ exc = cb_extract_timeout(req, options);
2579
2533
  if (!NIL_P(exc)) {
2580
2534
  break;
2581
2535
  }
2582
- exc = cb__extract_durability(req, options);
2536
+ exc = cb_extract_durability(req, options);
2583
2537
  if (!NIL_P(exc)) {
2584
2538
  break;
2585
2539
  }
2586
2540
  VALUE delta = Qnil;
2587
- exc = cb__extract_option_bignum(delta, options, "delta");
2541
+ exc = cb_extract_option_bignum(delta, options, "delta");
2588
2542
  if (!NIL_P(exc)) {
2589
2543
  break;
2590
2544
  }
@@ -2592,7 +2546,7 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2592
2546
  req.delta = NUM2ULL(delta);
2593
2547
  }
2594
2548
  VALUE initial_value = Qnil;
2595
- exc = cb__extract_option_bignum(initial_value, options, "initial_value");
2549
+ exc = cb_extract_option_bignum(initial_value, options, "initial_value");
2596
2550
  if (!NIL_P(exc)) {
2597
2551
  break;
2598
2552
  }
@@ -2600,23 +2554,27 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2600
2554
  req.initial_value = NUM2ULL(initial_value);
2601
2555
  }
2602
2556
  VALUE expiry = Qnil;
2603
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2557
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2604
2558
  if (!NIL_P(exc)) {
2605
2559
  break;
2606
2560
  }
2607
2561
  if (!NIL_P(expiry)) {
2608
2562
  req.expiry = FIX2UINT(expiry);
2609
2563
  }
2564
+ exc = cb_extract_option_bool(req.preserve_expiry, options, "preserve_expiry");
2565
+ if (!NIL_P(exc)) {
2566
+ break;
2567
+ }
2610
2568
 
2611
2569
  auto barrier = std::make_shared<std::promise<couchbase::operations::increment_response>>();
2612
2570
  auto f = barrier->get_future();
2613
2571
  backend->cluster->execute(req, [barrier](couchbase::operations::increment_response&& resp) mutable { barrier->set_value(resp); });
2614
- auto resp = f.get();
2572
+ auto resp = cb_wait_for_future(f);
2615
2573
  if (resp.ctx.ec) {
2616
- exc = cb__map_error_code(resp.ctx.ec, fmt::format(R"(unable to increment by {})", req.delta));
2574
+ exc = cb_map_error_code(resp.ctx.ec, fmt::format(R"(unable to increment by {})", req.delta));
2617
2575
  break;
2618
2576
  }
2619
- VALUE res = cb__extract_mutation_result(resp);
2577
+ VALUE res = cb_extract_mutation_result(resp);
2620
2578
  rb_hash_aset(res, rb_id2sym(rb_intern("content")), ULL2NUM(resp.content));
2621
2579
  return res;
2622
2580
  } while (false);
@@ -2650,16 +2608,16 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2650
2608
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2651
2609
 
2652
2610
  couchbase::operations::decrement_request req{ doc_id };
2653
- exc = cb__extract_timeout(req, options);
2611
+ exc = cb_extract_timeout(req, options);
2654
2612
  if (!NIL_P(exc)) {
2655
2613
  break;
2656
2614
  }
2657
- exc = cb__extract_durability(req, options);
2615
+ exc = cb_extract_durability(req, options);
2658
2616
  if (!NIL_P(exc)) {
2659
2617
  break;
2660
2618
  }
2661
2619
  VALUE delta = Qnil;
2662
- exc = cb__extract_option_bignum(delta, options, "delta");
2620
+ exc = cb_extract_option_bignum(delta, options, "delta");
2663
2621
  if (!NIL_P(exc)) {
2664
2622
  break;
2665
2623
  }
@@ -2667,7 +2625,7 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2667
2625
  req.delta = NUM2ULL(delta);
2668
2626
  }
2669
2627
  VALUE initial_value = Qnil;
2670
- exc = cb__extract_option_bignum(initial_value, options, "initial_value");
2628
+ exc = cb_extract_option_bignum(initial_value, options, "initial_value");
2671
2629
  if (!NIL_P(exc)) {
2672
2630
  break;
2673
2631
  }
@@ -2675,23 +2633,27 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2675
2633
  req.initial_value = NUM2ULL(initial_value);
2676
2634
  }
2677
2635
  VALUE expiry = Qnil;
2678
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2636
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2679
2637
  if (!NIL_P(exc)) {
2680
2638
  break;
2681
2639
  }
2682
2640
  if (!NIL_P(expiry)) {
2683
2641
  req.expiry = FIX2UINT(expiry);
2684
2642
  }
2643
+ exc = cb_extract_option_bool(req.preserve_expiry, options, "preserve_expiry");
2644
+ if (!NIL_P(exc)) {
2645
+ break;
2646
+ }
2685
2647
 
2686
2648
  auto barrier = std::make_shared<std::promise<couchbase::operations::decrement_response>>();
2687
2649
  auto f = barrier->get_future();
2688
2650
  backend->cluster->execute(req, [barrier](couchbase::operations::decrement_response&& resp) mutable { barrier->set_value(resp); });
2689
- auto resp = f.get();
2651
+ auto resp = cb_wait_for_future(f);
2690
2652
  if (resp.ctx.ec) {
2691
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to decrement by {})", req.delta));
2653
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to decrement by {})", req.delta));
2692
2654
  break;
2693
2655
  }
2694
- VALUE res = cb__extract_mutation_result(resp);
2656
+ VALUE res = cb_extract_mutation_result(resp);
2695
2657
  rb_hash_aset(res, rb_id2sym(rb_intern("content")), ULL2NUM(resp.content));
2696
2658
  return res;
2697
2659
  } while (false);
@@ -2700,7 +2662,7 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2700
2662
  }
2701
2663
 
2702
2664
  static VALUE
2703
- cb__map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2665
+ cb_map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2704
2666
  {
2705
2667
  switch (opcode) {
2706
2668
  case couchbase::protocol::subdoc_opcode::get:
@@ -2745,6 +2707,9 @@ cb__map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2745
2707
  case couchbase::protocol::subdoc_opcode::set_doc:
2746
2708
  return rb_id2sym(rb_intern("set_doc"));
2747
2709
 
2710
+ case couchbase::protocol::subdoc_opcode::remove_doc:
2711
+ return rb_id2sym(rb_intern("remove_doc"));
2712
+
2748
2713
  case couchbase::protocol::subdoc_opcode::replace_body_with_xattr:
2749
2714
  return rb_id2sym(rb_intern("replace_body_with_xattr"));
2750
2715
  }
@@ -2752,7 +2717,7 @@ cb__map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2752
2717
  }
2753
2718
 
2754
2719
  static void
2755
- cb__map_subdoc_status(couchbase::protocol::status status, std::size_t index, const std::string& path, VALUE entry)
2720
+ cb_map_subdoc_status(couchbase::protocol::status status, std::size_t index, const std::string& path, VALUE entry)
2756
2721
  {
2757
2722
  switch (status) {
2758
2723
  case couchbase::protocol::status::success:
@@ -2867,7 +2832,7 @@ cb__map_subdoc_status(couchbase::protocol::status status, std::size_t index, con
2867
2832
  rb_hash_aset(
2868
2833
  entry,
2869
2834
  rb_id2sym(rb_intern("error")),
2870
- rb_exc_new_cstr(eCouchbaseError,
2835
+ rb_exc_new_cstr(eBackendError,
2871
2836
  fmt::format("unknown subdocument error status={}, index={}, path={}", status, index, path).c_str()));
2872
2837
  return;
2873
2838
  }
@@ -2904,11 +2869,11 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE collection, VALUE
2904
2869
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2905
2870
 
2906
2871
  couchbase::operations::lookup_in_request req{ doc_id };
2907
- exc = cb__extract_timeout(req, options);
2872
+ exc = cb_extract_timeout(req, options);
2908
2873
  if (!NIL_P(exc)) {
2909
2874
  break;
2910
2875
  }
2911
- exc = cb__extract_option_bool(req.access_deleted, options, "access_deleted");
2876
+ exc = cb_extract_option_bool(req.access_deleted, options, "access_deleted");
2912
2877
  if (!NIL_P(exc)) {
2913
2878
  break;
2914
2879
  }
@@ -2945,9 +2910,9 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE collection, VALUE
2945
2910
  auto barrier = std::make_shared<std::promise<couchbase::operations::lookup_in_response>>();
2946
2911
  auto f = barrier->get_future();
2947
2912
  backend->cluster->execute(req, [barrier](couchbase::operations::lookup_in_response&& resp) mutable { barrier->set_value(resp); });
2948
- auto resp = f.get();
2913
+ auto resp = cb_wait_for_future(f);
2949
2914
  if (resp.ctx.ec) {
2950
- exc = cb__map_error_code(resp.ctx, "unable fetch");
2915
+ exc = cb_map_error_code(resp.ctx, "unable fetch");
2951
2916
  break;
2952
2917
  }
2953
2918
 
@@ -2962,17 +2927,13 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE collection, VALUE
2962
2927
  VALUE entry = rb_hash_new();
2963
2928
  rb_hash_aset(entry, rb_id2sym(rb_intern("index")), ULL2NUM(i));
2964
2929
  rb_hash_aset(entry, rb_id2sym(rb_intern("exists")), resp.fields[i].exists ? Qtrue : Qfalse);
2965
- rb_hash_aset(entry,
2966
- rb_id2sym(rb_intern("path")),
2967
- rb_external_str_new(resp.fields[i].path.data(), static_cast<long>(resp.fields[i].path.size())));
2968
- rb_hash_aset(entry,
2969
- rb_id2sym(rb_intern("value")),
2970
- rb_external_str_new(resp.fields[i].value.data(), static_cast<long>(resp.fields[i].value.size())));
2971
- cb__map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
2930
+ rb_hash_aset(entry, rb_id2sym(rb_intern("path")), cb_str_new(resp.fields[i].path));
2931
+ rb_hash_aset(entry, rb_id2sym(rb_intern("value")), cb_str_new(resp.fields[i].value));
2932
+ cb_map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
2972
2933
  if (resp.fields[i].opcode == couchbase::protocol::subdoc_opcode::get && resp.fields[i].path.empty()) {
2973
2934
  rb_hash_aset(entry, rb_id2sym(rb_intern("type")), rb_id2sym(rb_intern("get_doc")));
2974
2935
  } else {
2975
- rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb__map_subdoc_opcode(resp.fields[i].opcode));
2936
+ rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb_map_subdoc_opcode(resp.fields[i].opcode));
2976
2937
  }
2977
2938
  rb_ary_store(fields, static_cast<long>(i), entry);
2978
2939
  }
@@ -3013,16 +2974,16 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3013
2974
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
3014
2975
 
3015
2976
  couchbase::operations::mutate_in_request req{ doc_id };
3016
- exc = cb__extract_timeout(req, options);
2977
+ exc = cb_extract_timeout(req, options);
3017
2978
  if (!NIL_P(exc)) {
3018
2979
  break;
3019
2980
  }
3020
- exc = cb__extract_durability(req, options);
2981
+ exc = cb_extract_durability(req, options);
3021
2982
  if (!NIL_P(exc)) {
3022
2983
  break;
3023
2984
  }
3024
2985
  VALUE cas = Qnil;
3025
- exc = cb__extract_option_bignum(cas, options, "cas");
2986
+ exc = cb_extract_option_bignum(cas, options, "cas");
3026
2987
  if (!NIL_P(exc)) {
3027
2988
  break;
3028
2989
  }
@@ -3030,23 +2991,27 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3030
2991
  req.cas = NUM2ULL(cas);
3031
2992
  }
3032
2993
  VALUE expiry = Qnil;
3033
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2994
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
3034
2995
  if (!NIL_P(exc)) {
3035
2996
  break;
3036
2997
  }
3037
2998
  if (!NIL_P(expiry)) {
3038
2999
  req.expiry = FIX2UINT(expiry);
3039
3000
  }
3040
- exc = cb__extract_option_bool(req.access_deleted, options, "access_deleted");
3001
+ exc = cb_extract_option_bool(req.preserve_expiry, options, "preserve_expiry");
3041
3002
  if (!NIL_P(exc)) {
3042
3003
  break;
3043
3004
  }
3044
- exc = cb__extract_option_bool(req.create_as_deleted, options, "create_as_deleted");
3005
+ exc = cb_extract_option_bool(req.access_deleted, options, "access_deleted");
3006
+ if (!NIL_P(exc)) {
3007
+ break;
3008
+ }
3009
+ exc = cb_extract_option_bool(req.create_as_deleted, options, "create_as_deleted");
3045
3010
  if (!NIL_P(exc)) {
3046
3011
  break;
3047
3012
  }
3048
3013
  VALUE store_semantics = Qnil;
3049
- exc = cb__extract_option_symbol(store_semantics, options, "store_semantics");
3014
+ exc = cb_extract_option_symbol(store_semantics, options, "store_semantics");
3050
3015
  if (!NIL_P(exc)) {
3051
3016
  break;
3052
3017
  }
@@ -3087,6 +3052,8 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3087
3052
  opcode = couchbase::protocol::subdoc_opcode::counter;
3088
3053
  } else if (operation_id == rb_intern("set_doc")) {
3089
3054
  opcode = couchbase::protocol::subdoc_opcode::set_doc;
3055
+ } else if (operation_id == rb_intern("remove_doc")) {
3056
+ opcode = couchbase::protocol::subdoc_opcode::remove_doc;
3090
3057
  } else {
3091
3058
  exc =
3092
3059
  rb_exc_new_str(eInvalidArgument, rb_sprintf("unsupported operation for subdocument mutation: %+" PRIsVALUE, operation));
@@ -3125,13 +3092,13 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3125
3092
  auto barrier = std::make_shared<std::promise<couchbase::operations::mutate_in_response>>();
3126
3093
  auto f = barrier->get_future();
3127
3094
  backend->cluster->execute(req, [barrier](couchbase::operations::mutate_in_response&& resp) mutable { barrier->set_value(resp); });
3128
- auto resp = f.get();
3095
+ auto resp = cb_wait_for_future(f);
3129
3096
  if (resp.ctx.ec) {
3130
- exc = cb__map_error_code(resp.ctx, "unable to mutate");
3097
+ exc = cb_map_error_code(resp.ctx, "unable to mutate");
3131
3098
  break;
3132
3099
  }
3133
3100
 
3134
- VALUE res = cb__extract_mutation_result(resp);
3101
+ VALUE res = cb_extract_mutation_result(resp);
3135
3102
  if (resp.first_error_index) {
3136
3103
  rb_hash_aset(res, rb_id2sym(rb_intern("first_error_index")), ULL2NUM(resp.first_error_index.value()));
3137
3104
  }
@@ -3143,9 +3110,7 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3143
3110
  for (size_t i = 0; i < resp.fields.size(); ++i) {
3144
3111
  VALUE entry = rb_hash_new();
3145
3112
  rb_hash_aset(entry, rb_id2sym(rb_intern("index")), ULL2NUM(i));
3146
- rb_hash_aset(entry,
3147
- rb_id2sym(rb_intern("path")),
3148
- rb_external_str_new(resp.fields[i].path.data(), static_cast<long>(resp.fields[i].path.size())));
3113
+ rb_hash_aset(entry, rb_id2sym(rb_intern("path")), cb_str_new(resp.fields[i].path));
3149
3114
  if (resp.fields[i].status == couchbase::protocol::status::success ||
3150
3115
  resp.fields[i].status == couchbase::protocol::status::subdoc_success_deleted) {
3151
3116
  if (resp.fields[i].opcode == couchbase::protocol::subdoc_opcode::counter) {
@@ -3153,13 +3118,11 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3153
3118
  rb_hash_aset(entry, rb_id2sym(rb_intern("value")), LL2NUM(std::stoll(resp.fields[i].value)));
3154
3119
  }
3155
3120
  } else {
3156
- rb_hash_aset(entry,
3157
- rb_id2sym(rb_intern("value")),
3158
- rb_external_str_new(resp.fields[i].value.data(), static_cast<long>(resp.fields[i].value.size())));
3121
+ rb_hash_aset(entry, rb_id2sym(rb_intern("value")), cb_str_new(resp.fields[i].value));
3159
3122
  }
3160
3123
  }
3161
- cb__map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
3162
- rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb__map_subdoc_opcode(resp.fields[i].opcode));
3124
+ cb_map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
3125
+ rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb_map_subdoc_opcode(resp.fields[i].opcode));
3163
3126
  rb_ary_store(fields, static_cast<long>(i), entry);
3164
3127
  }
3165
3128
  return res;
@@ -3169,7 +3132,7 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3169
3132
  }
3170
3133
 
3171
3134
  static int
3172
- cb__for_each_named_param(VALUE key, VALUE value, VALUE arg)
3135
+ cb_for_each_named_param(VALUE key, VALUE value, VALUE arg)
3173
3136
  {
3174
3137
  auto* preq = reinterpret_cast<couchbase::operations::query_request*>(arg);
3175
3138
  Check_Type(key, T_STRING);
@@ -3203,7 +3166,7 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3203
3166
  Check_Type(client_context_id, T_STRING);
3204
3167
  req.client_context_id.assign(RSTRING_PTR(client_context_id), static_cast<size_t>(RSTRING_LEN(client_context_id)));
3205
3168
  }
3206
- exc = cb__extract_timeout(req, options);
3169
+ exc = cb_extract_timeout(req, options);
3207
3170
  if (!NIL_P(exc)) {
3208
3171
  break;
3209
3172
  }
@@ -3286,7 +3249,7 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3286
3249
  VALUE named_params = rb_hash_aref(options, rb_id2sym(rb_intern("named_parameters")));
3287
3250
  if (!NIL_P(named_params)) {
3288
3251
  Check_Type(named_params, T_HASH);
3289
- rb_hash_foreach(named_params, INT_FUNC(cb__for_each_named_param), reinterpret_cast<VALUE>(&req));
3252
+ rb_hash_foreach(named_params, INT_FUNC(cb_for_each_named_param), reinterpret_cast<VALUE>(&req));
3290
3253
  }
3291
3254
  VALUE scan_consistency = rb_hash_aref(options, rb_id2sym(rb_intern("scan_consistency")));
3292
3255
  if (!NIL_P(scan_consistency)) {
@@ -3337,19 +3300,19 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3337
3300
  VALUE raw_params = rb_hash_aref(options, rb_id2sym(rb_intern("raw_parameters")));
3338
3301
  if (!NIL_P(raw_params)) {
3339
3302
  Check_Type(raw_params, T_HASH);
3340
- rb_hash_foreach(raw_params, INT_FUNC(cb__for_each_named_param), reinterpret_cast<VALUE>(&req));
3303
+ rb_hash_foreach(raw_params, INT_FUNC(cb_for_each_named_param), reinterpret_cast<VALUE>(&req));
3341
3304
  }
3342
3305
 
3343
3306
  auto barrier = std::make_shared<std::promise<couchbase::operations::query_response>>();
3344
3307
  auto f = barrier->get_future();
3345
3308
  backend->cluster->execute_http(req, [barrier](couchbase::operations::query_response&& resp) mutable { barrier->set_value(resp); });
3346
- auto resp = f.get();
3309
+ auto resp = cb_wait_for_future(f);
3347
3310
  if (resp.ctx.ec) {
3348
3311
  if (resp.payload.meta_data.errors && !resp.payload.meta_data.errors->empty()) {
3349
3312
  const auto& first_error = resp.payload.meta_data.errors->front();
3350
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to query ({}: {}))", first_error.code, first_error.message));
3313
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to query ({}: {}))", first_error.code, first_error.message));
3351
3314
  } else {
3352
- exc = cb__map_error_code(resp.ctx, "unable to query");
3315
+ exc = cb_map_error_code(resp.ctx, "unable to query");
3353
3316
  }
3354
3317
  break;
3355
3318
  }
@@ -3357,46 +3320,28 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3357
3320
  VALUE rows = rb_ary_new_capa(static_cast<long>(resp.payload.rows.size()));
3358
3321
  rb_hash_aset(res, rb_id2sym(rb_intern("rows")), rows);
3359
3322
  for (auto& row : resp.payload.rows) {
3360
- rb_ary_push(rows, rb_external_str_new(row.data(), static_cast<long>(row.size())));
3323
+ rb_ary_push(rows, cb_str_new(row));
3361
3324
  }
3362
3325
  VALUE meta = rb_hash_new();
3363
3326
  rb_hash_aset(res, rb_id2sym(rb_intern("meta")), meta);
3364
3327
  rb_hash_aset(meta,
3365
3328
  rb_id2sym(rb_intern("status")),
3366
3329
  rb_id2sym(rb_intern2(resp.payload.meta_data.status.data(), static_cast<long>(resp.payload.meta_data.status.size()))));
3367
- rb_hash_aset(
3368
- meta,
3369
- rb_id2sym(rb_intern("request_id")),
3370
- rb_external_str_new(resp.payload.meta_data.request_id.data(), static_cast<long>(resp.payload.meta_data.request_id.size())));
3371
- rb_hash_aset(meta,
3372
- rb_id2sym(rb_intern("client_context_id")),
3373
- rb_external_str_new(resp.payload.meta_data.client_context_id.data(),
3374
- static_cast<long>(resp.payload.meta_data.client_context_id.size())));
3330
+ rb_hash_aset(meta, rb_id2sym(rb_intern("request_id")), cb_str_new(resp.payload.meta_data.request_id));
3331
+ rb_hash_aset(meta, rb_id2sym(rb_intern("client_context_id")), cb_str_new(resp.payload.meta_data.client_context_id));
3375
3332
  if (resp.payload.meta_data.signature) {
3376
- rb_hash_aset(
3377
- meta,
3378
- rb_id2sym(rb_intern("signature")),
3379
- rb_external_str_new(resp.payload.meta_data.signature->data(), static_cast<long>(resp.payload.meta_data.signature->size())));
3333
+ rb_hash_aset(meta, rb_id2sym(rb_intern("signature")), cb_str_new(resp.payload.meta_data.signature.value()));
3380
3334
  }
3381
3335
  if (resp.payload.meta_data.profile) {
3382
- rb_hash_aset(
3383
- meta,
3384
- rb_id2sym(rb_intern("profile")),
3385
- rb_external_str_new(resp.payload.meta_data.profile->data(), static_cast<long>(resp.payload.meta_data.profile->size())));
3336
+ rb_hash_aset(meta, rb_id2sym(rb_intern("profile")), cb_str_new(resp.payload.meta_data.profile.value()));
3386
3337
  }
3387
3338
  metrics = rb_hash_new();
3388
3339
  rb_hash_aset(meta, rb_id2sym(rb_intern("metrics")), metrics);
3389
3340
  if (!resp.payload.meta_data.metrics.elapsed_time.empty()) {
3390
- rb_hash_aset(metrics,
3391
- rb_id2sym(rb_intern("elapsed_time")),
3392
- rb_external_str_new(resp.payload.meta_data.metrics.elapsed_time.data(),
3393
- static_cast<long>(resp.payload.meta_data.metrics.elapsed_time.size())));
3341
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("elapsed_time")), cb_str_new(resp.payload.meta_data.metrics.elapsed_time));
3394
3342
  }
3395
3343
  if (!resp.payload.meta_data.metrics.execution_time.empty()) {
3396
- rb_hash_aset(metrics,
3397
- rb_id2sym(rb_intern("execution_time")),
3398
- rb_external_str_new(resp.payload.meta_data.metrics.execution_time.data(),
3399
- static_cast<long>(resp.payload.meta_data.metrics.execution_time.size())));
3344
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("execution_time")), cb_str_new(resp.payload.meta_data.metrics.execution_time));
3400
3345
  }
3401
3346
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_count")), ULL2NUM(resp.payload.meta_data.metrics.result_count));
3402
3347
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_size")), ULL2NUM(resp.payload.meta_data.metrics.result_size));
@@ -3420,7 +3365,7 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3420
3365
  }
3421
3366
 
3422
3367
  static VALUE
3423
- cb__generate_bucket_settings(VALUE bucket, couchbase::operations::bucket_settings& entry, bool is_create)
3368
+ cb_generate_bucket_settings(VALUE bucket, couchbase::operations::bucket_settings& entry, bool is_create)
3424
3369
  {
3425
3370
  {
3426
3371
  VALUE bucket_type = rb_hash_aref(bucket, rb_id2sym(rb_intern("bucket_type")));
@@ -3586,11 +3531,11 @@ cb_Backend_bucket_create(VALUE self, VALUE bucket_settings, VALUE timeout)
3586
3531
  VALUE exc = Qnil;
3587
3532
  do {
3588
3533
  couchbase::operations::bucket_create_request req{};
3589
- exc = cb__extract_timeout(req, timeout);
3534
+ exc = cb_extract_timeout(req, timeout);
3590
3535
  if (!NIL_P(exc)) {
3591
3536
  break;
3592
3537
  }
3593
- exc = cb__generate_bucket_settings(bucket_settings, req.bucket, true);
3538
+ exc = cb_generate_bucket_settings(bucket_settings, req.bucket, true);
3594
3539
  if (!NIL_P(exc)) {
3595
3540
  break;
3596
3541
  }
@@ -3598,10 +3543,10 @@ cb_Backend_bucket_create(VALUE self, VALUE bucket_settings, VALUE timeout)
3598
3543
  auto f = barrier->get_future();
3599
3544
  backend->cluster->execute_http(
3600
3545
  req, [barrier](couchbase::operations::bucket_create_response&& resp) mutable { barrier->set_value(resp); });
3601
- auto resp = f.get();
3546
+ auto resp = cb_wait_for_future(f);
3602
3547
  if (resp.ctx.ec) {
3603
- exc = cb__map_error_code(
3604
- resp.ctx, fmt::format("unable to create bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3548
+ exc = cb_map_error_code(resp.ctx,
3549
+ fmt::format("unable to create bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3605
3550
  break;
3606
3551
  }
3607
3552
 
@@ -3626,11 +3571,11 @@ cb_Backend_bucket_update(VALUE self, VALUE bucket_settings, VALUE timeout)
3626
3571
  VALUE exc = Qnil;
3627
3572
  do {
3628
3573
  couchbase::operations::bucket_update_request req{};
3629
- exc = cb__extract_timeout(req, timeout);
3574
+ exc = cb_extract_timeout(req, timeout);
3630
3575
  if (!NIL_P(exc)) {
3631
3576
  break;
3632
3577
  }
3633
- exc = cb__generate_bucket_settings(bucket_settings, req.bucket, false);
3578
+ exc = cb_generate_bucket_settings(bucket_settings, req.bucket, false);
3634
3579
  if (!NIL_P(exc)) {
3635
3580
  break;
3636
3581
  }
@@ -3638,10 +3583,10 @@ cb_Backend_bucket_update(VALUE self, VALUE bucket_settings, VALUE timeout)
3638
3583
  auto f = barrier->get_future();
3639
3584
  backend->cluster->execute_http(
3640
3585
  req, [barrier](couchbase::operations::bucket_update_response&& resp) mutable { barrier->set_value(resp); });
3641
- auto resp = f.get();
3586
+ auto resp = cb_wait_for_future(f);
3642
3587
  if (resp.ctx.ec) {
3643
- exc = cb__map_error_code(
3644
- resp.ctx, fmt::format("unable to update bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3588
+ exc = cb_map_error_code(resp.ctx,
3589
+ fmt::format("unable to update bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3645
3590
  break;
3646
3591
  }
3647
3592
  return Qtrue;
@@ -3666,7 +3611,7 @@ cb_Backend_bucket_drop(VALUE self, VALUE bucket_name, VALUE timeout)
3666
3611
  VALUE exc = Qnil;
3667
3612
  do {
3668
3613
  couchbase::operations::bucket_drop_request req{};
3669
- exc = cb__extract_timeout(req, timeout);
3614
+ exc = cb_extract_timeout(req, timeout);
3670
3615
  if (!NIL_P(exc)) {
3671
3616
  break;
3672
3617
  }
@@ -3675,9 +3620,9 @@ cb_Backend_bucket_drop(VALUE self, VALUE bucket_name, VALUE timeout)
3675
3620
  auto f = barrier->get_future();
3676
3621
  backend->cluster->execute_http(req,
3677
3622
  [barrier](couchbase::operations::bucket_drop_response&& resp) mutable { barrier->set_value(resp); });
3678
- auto resp = f.get();
3623
+ auto resp = cb_wait_for_future(f);
3679
3624
  if (resp.ctx.ec) {
3680
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to remove bucket \"{}\" on the cluster", req.name));
3625
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to remove bucket \"{}\" on the cluster", req.name));
3681
3626
  break;
3682
3627
  }
3683
3628
  return Qtrue;
@@ -3702,7 +3647,7 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE timeout)
3702
3647
  VALUE exc = Qnil;
3703
3648
  do {
3704
3649
  couchbase::operations::bucket_flush_request req{};
3705
- exc = cb__extract_timeout(req, timeout);
3650
+ exc = cb_extract_timeout(req, timeout);
3706
3651
  if (!NIL_P(exc)) {
3707
3652
  break;
3708
3653
  }
@@ -3711,9 +3656,9 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE timeout)
3711
3656
  auto f = barrier->get_future();
3712
3657
  backend->cluster->execute_http(
3713
3658
  req, [barrier](couchbase::operations::bucket_flush_response&& resp) mutable { barrier->set_value(resp); });
3714
- auto resp = f.get();
3659
+ auto resp = cb_wait_for_future(f);
3715
3660
  if (resp.ctx.ec) {
3716
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to flush bucket \"{}\" on the cluster", req.name));
3661
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to flush bucket \"{}\" on the cluster", req.name));
3717
3662
  break;
3718
3663
  }
3719
3664
 
@@ -3724,7 +3669,7 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE timeout)
3724
3669
  }
3725
3670
 
3726
3671
  static void
3727
- cb__extract_bucket_settings(const couchbase::operations::bucket_settings& entry, VALUE bucket)
3672
+ cb_extract_bucket_settings(const couchbase::operations::bucket_settings& entry, VALUE bucket)
3728
3673
  {
3729
3674
  switch (entry.bucket_type) {
3730
3675
  case couchbase::operations::bucket_settings::bucket_type::couchbase:
@@ -3740,8 +3685,8 @@ cb__extract_bucket_settings(const couchbase::operations::bucket_settings& entry,
3740
3685
  rb_hash_aset(bucket, rb_id2sym(rb_intern("bucket_type")), Qnil);
3741
3686
  break;
3742
3687
  }
3743
- rb_hash_aset(bucket, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
3744
- rb_hash_aset(bucket, rb_id2sym(rb_intern("uuid")), rb_external_str_new(entry.uuid.data(), static_cast<long>(entry.uuid.size())));
3688
+ rb_hash_aset(bucket, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
3689
+ rb_hash_aset(bucket, rb_id2sym(rb_intern("uuid")), cb_str_new(entry.uuid));
3745
3690
  rb_hash_aset(bucket, rb_id2sym(rb_intern("ram_quota_mb")), ULL2NUM(entry.ram_quota_mb));
3746
3691
  rb_hash_aset(bucket, rb_id2sym(rb_intern("max_expiry")), ULONG2NUM(entry.max_expiry));
3747
3692
  switch (entry.compression_mode) {
@@ -3808,15 +3753,15 @@ cb__extract_bucket_settings(const couchbase::operations::bucket_settings& entry,
3808
3753
  }
3809
3754
  VALUE capabilities = rb_ary_new_capa(static_cast<long>(entry.capabilities.size()));
3810
3755
  for (const auto& capa : entry.capabilities) {
3811
- rb_ary_push(capabilities, rb_external_str_new(capa.data(), static_cast<long>(capa.size())));
3756
+ rb_ary_push(capabilities, cb_str_new(capa));
3812
3757
  }
3813
3758
  rb_hash_aset(bucket, rb_id2sym(rb_intern("capabilities")), capabilities);
3814
3759
  VALUE nodes = rb_ary_new_capa(static_cast<long>(entry.nodes.size()));
3815
3760
  for (const auto& n : entry.nodes) {
3816
3761
  VALUE node = rb_hash_new();
3817
- rb_hash_aset(node, rb_id2sym(rb_intern("status")), rb_external_str_new(n.status.data(), static_cast<long>(n.status.size())));
3818
- rb_hash_aset(node, rb_id2sym(rb_intern("hostname")), rb_external_str_new(n.hostname.data(), static_cast<long>(n.hostname.size())));
3819
- rb_hash_aset(node, rb_id2sym(rb_intern("version")), rb_external_str_new(n.version.data(), static_cast<long>(n.version.size())));
3762
+ rb_hash_aset(node, rb_id2sym(rb_intern("status")), cb_str_new(n.status));
3763
+ rb_hash_aset(node, rb_id2sym(rb_intern("hostname")), cb_str_new(n.hostname));
3764
+ rb_hash_aset(node, rb_id2sym(rb_intern("version")), cb_str_new(n.version));
3820
3765
  rb_ary_push(nodes, node);
3821
3766
  }
3822
3767
  rb_hash_aset(bucket, rb_id2sym(rb_intern("nodes")), nodes);
@@ -3836,7 +3781,7 @@ cb_Backend_bucket_get_all(VALUE self, VALUE timeout)
3836
3781
  VALUE exc = Qnil;
3837
3782
  do {
3838
3783
  couchbase::operations::bucket_get_all_request req{};
3839
- exc = cb__extract_timeout(req, timeout);
3784
+ exc = cb_extract_timeout(req, timeout);
3840
3785
  if (!NIL_P(exc)) {
3841
3786
  break;
3842
3787
  }
@@ -3844,16 +3789,16 @@ cb_Backend_bucket_get_all(VALUE self, VALUE timeout)
3844
3789
  auto f = barrier->get_future();
3845
3790
  backend->cluster->execute_http(
3846
3791
  req, [barrier](couchbase::operations::bucket_get_all_response&& resp) mutable { barrier->set_value(resp); });
3847
- auto resp = f.get();
3792
+ auto resp = cb_wait_for_future(f);
3848
3793
  if (resp.ctx.ec) {
3849
- exc = cb__map_error_code(resp.ctx, "unable to get list of the buckets of the cluster");
3794
+ exc = cb_map_error_code(resp.ctx, "unable to get list of the buckets of the cluster");
3850
3795
  break;
3851
3796
  }
3852
3797
 
3853
3798
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.buckets.size()));
3854
3799
  for (const auto& entry : resp.buckets) {
3855
3800
  VALUE bucket = rb_hash_new();
3856
- cb__extract_bucket_settings(entry, bucket);
3801
+ cb_extract_bucket_settings(entry, bucket);
3857
3802
  rb_ary_push(res, bucket);
3858
3803
  }
3859
3804
 
@@ -3879,7 +3824,7 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE timeout)
3879
3824
  VALUE exc = Qnil;
3880
3825
  do {
3881
3826
  couchbase::operations::bucket_get_request req{};
3882
- exc = cb__extract_timeout(req, timeout);
3827
+ exc = cb_extract_timeout(req, timeout);
3883
3828
  if (!NIL_P(exc)) {
3884
3829
  break;
3885
3830
  }
@@ -3888,14 +3833,14 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE timeout)
3888
3833
  auto f = barrier->get_future();
3889
3834
  backend->cluster->execute_http(req,
3890
3835
  [barrier](couchbase::operations::bucket_get_response&& resp) mutable { barrier->set_value(resp); });
3891
- auto resp = f.get();
3836
+ auto resp = cb_wait_for_future(f);
3892
3837
  if (resp.ctx.ec) {
3893
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to locate bucket \"{}\" on the cluster", req.name));
3838
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to locate bucket \"{}\" on the cluster", req.name));
3894
3839
  break;
3895
3840
  }
3896
3841
 
3897
3842
  VALUE res = rb_hash_new();
3898
- cb__extract_bucket_settings(resp.bucket, res);
3843
+ cb_extract_bucket_settings(resp.bucket, res);
3899
3844
 
3900
3845
  return res;
3901
3846
  } while (false);
@@ -3904,26 +3849,19 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE timeout)
3904
3849
  }
3905
3850
 
3906
3851
  static void
3907
- cb__extract_role(const couchbase::operations::rbac::role_and_description& entry, VALUE role)
3908
- {
3909
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
3910
- rb_hash_aset(role,
3911
- rb_id2sym(rb_intern("display_name")),
3912
- rb_external_str_new(entry.display_name.data(), static_cast<long>(entry.display_name.size())));
3913
- rb_hash_aset(role,
3914
- rb_id2sym(rb_intern("description")),
3915
- rb_external_str_new(entry.description.data(), static_cast<long>(entry.description.size())));
3852
+ cb_extract_role(const couchbase::operations::rbac::role_and_description& entry, VALUE role)
3853
+ {
3854
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
3855
+ rb_hash_aset(role, rb_id2sym(rb_intern("display_name")), cb_str_new(entry.display_name));
3856
+ rb_hash_aset(role, rb_id2sym(rb_intern("description")), cb_str_new(entry.description));
3916
3857
  if (entry.bucket) {
3917
- rb_hash_aset(
3918
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(entry.bucket->data(), static_cast<long>(entry.bucket->size())));
3858
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(entry.bucket.value()));
3919
3859
  }
3920
3860
  if (entry.scope) {
3921
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(entry.scope->data(), static_cast<long>(entry.scope->size())));
3861
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(entry.scope.value()));
3922
3862
  }
3923
3863
  if (entry.collection) {
3924
- rb_hash_aset(role,
3925
- rb_id2sym(rb_intern("collection")),
3926
- rb_external_str_new(entry.collection->data(), static_cast<long>(entry.collection->size())));
3864
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(entry.collection.value()));
3927
3865
  }
3928
3866
  }
3929
3867
 
@@ -3941,7 +3879,7 @@ cb_Backend_role_get_all(VALUE self, VALUE timeout)
3941
3879
  VALUE exc = Qnil;
3942
3880
  do {
3943
3881
  couchbase::operations::role_get_all_request req{};
3944
- exc = cb__extract_timeout(req, timeout);
3882
+ exc = cb_extract_timeout(req, timeout);
3945
3883
  if (!NIL_P(exc)) {
3946
3884
  break;
3947
3885
  }
@@ -3949,16 +3887,16 @@ cb_Backend_role_get_all(VALUE self, VALUE timeout)
3949
3887
  auto f = barrier->get_future();
3950
3888
  backend->cluster->execute_http(
3951
3889
  req, [barrier](couchbase::operations::role_get_all_response&& resp) mutable { barrier->set_value(resp); });
3952
- auto resp = f.get();
3890
+ auto resp = cb_wait_for_future(f);
3953
3891
  if (resp.ctx.ec) {
3954
- exc = cb__map_error_code(resp.ctx, "unable to fetch roles");
3892
+ exc = cb_map_error_code(resp.ctx, "unable to fetch roles");
3955
3893
  break;
3956
3894
  }
3957
3895
 
3958
3896
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.roles.size()));
3959
3897
  for (const auto& entry : resp.roles) {
3960
3898
  VALUE role = rb_hash_new();
3961
- cb__extract_role(entry, role);
3899
+ cb_extract_role(entry, role);
3962
3900
  rb_ary_push(res, role);
3963
3901
  }
3964
3902
  return res;
@@ -3968,10 +3906,9 @@ cb_Backend_role_get_all(VALUE self, VALUE timeout)
3968
3906
  }
3969
3907
 
3970
3908
  static void
3971
- cb__extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VALUE user)
3909
+ cb_extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VALUE user)
3972
3910
  {
3973
- rb_hash_aset(
3974
- user, rb_id2sym(rb_intern("username")), rb_external_str_new(entry.username.data(), static_cast<long>(entry.username.size())));
3911
+ rb_hash_aset(user, rb_id2sym(rb_intern("username")), cb_str_new(entry.username));
3975
3912
  switch (entry.domain) {
3976
3913
  case couchbase::operations::rbac::auth_domain::local:
3977
3914
  rb_hash_aset(user, rb_id2sym(rb_intern("domain")), rb_id2sym(rb_intern("local")));
@@ -3984,47 +3921,39 @@ cb__extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VA
3984
3921
  }
3985
3922
  VALUE external_groups = rb_ary_new_capa(static_cast<long>(entry.external_groups.size()));
3986
3923
  for (const auto& group : entry.external_groups) {
3987
- rb_ary_push(external_groups, rb_external_str_new(group.data(), static_cast<long>(group.size())));
3924
+ rb_ary_push(external_groups, cb_str_new(group));
3988
3925
  }
3989
3926
  rb_hash_aset(user, rb_id2sym(rb_intern("external_groups")), external_groups);
3990
3927
  VALUE groups = rb_ary_new_capa(static_cast<long>(entry.groups.size()));
3991
3928
  for (const auto& group : entry.groups) {
3992
- rb_ary_push(groups, rb_external_str_new(group.data(), static_cast<long>(group.size())));
3929
+ rb_ary_push(groups, cb_str_new(group));
3993
3930
  }
3994
3931
  rb_hash_aset(user, rb_id2sym(rb_intern("groups")), groups);
3995
3932
  if (entry.display_name) {
3996
- rb_hash_aset(user,
3997
- rb_id2sym(rb_intern("display_name")),
3998
- rb_external_str_new(entry.display_name->data(), static_cast<long>(entry.display_name->size())));
3933
+ rb_hash_aset(user, rb_id2sym(rb_intern("display_name")), cb_str_new(entry.display_name.value()));
3999
3934
  }
4000
3935
  if (entry.password_changed) {
4001
- rb_hash_aset(user,
4002
- rb_id2sym(rb_intern("password_changed")),
4003
- rb_external_str_new(entry.password_changed->data(), static_cast<long>(entry.password_changed->size())));
3936
+ rb_hash_aset(user, rb_id2sym(rb_intern("password_changed")), cb_str_new(entry.password_changed.value()));
4004
3937
  }
4005
3938
  VALUE effective_roles = rb_ary_new_capa(static_cast<long>(entry.effective_roles.size()));
4006
3939
  for (const auto& er : entry.effective_roles) {
4007
3940
  VALUE role = rb_hash_new();
4008
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(er.name.data(), static_cast<long>(er.name.size())));
3941
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(er.name));
4009
3942
  if (er.bucket) {
4010
- rb_hash_aset(
4011
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(er.bucket->data(), static_cast<long>(er.bucket->size())));
3943
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(er.bucket.value()));
4012
3944
  }
4013
3945
  if (er.scope) {
4014
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(er.scope->data(), static_cast<long>(er.scope->size())));
3946
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(er.scope.value()));
4015
3947
  }
4016
3948
  if (er.collection) {
4017
- rb_hash_aset(role,
4018
- rb_id2sym(rb_intern("collection")),
4019
- rb_external_str_new(er.collection->data(), static_cast<long>(er.collection->size())));
3949
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(er.collection.value()));
4020
3950
  }
4021
3951
  VALUE origins = rb_ary_new_capa(static_cast<long>(er.origins.size()));
4022
3952
  for (const auto& orig : er.origins) {
4023
3953
  VALUE origin = rb_hash_new();
4024
- rb_hash_aset(origin, rb_id2sym(rb_intern("type")), rb_external_str_new(orig.type.data(), static_cast<long>(orig.type.size())));
3954
+ rb_hash_aset(origin, rb_id2sym(rb_intern("type")), cb_str_new(orig.type));
4025
3955
  if (orig.name) {
4026
- rb_hash_aset(
4027
- origin, rb_id2sym(rb_intern("name")), rb_external_str_new(orig.name->data(), static_cast<long>(orig.name->size())));
3956
+ rb_hash_aset(origin, rb_id2sym(rb_intern("name")), cb_str_new(orig.name.value()));
4028
3957
  }
4029
3958
  rb_ary_push(origins, origin);
4030
3959
  }
@@ -4036,18 +3965,15 @@ cb__extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VA
4036
3965
  VALUE roles = rb_ary_new_capa(static_cast<long>(entry.roles.size()));
4037
3966
  for (const auto& er : entry.roles) {
4038
3967
  VALUE role = rb_hash_new();
4039
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(er.name.data(), static_cast<long>(er.name.size())));
3968
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(er.name));
4040
3969
  if (er.bucket) {
4041
- rb_hash_aset(
4042
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(er.bucket->data(), static_cast<long>(er.bucket->size())));
3970
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(er.bucket.value()));
4043
3971
  }
4044
3972
  if (er.scope) {
4045
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(er.scope->data(), static_cast<long>(er.scope->size())));
3973
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(er.scope.value()));
4046
3974
  }
4047
3975
  if (er.collection) {
4048
- rb_hash_aset(role,
4049
- rb_id2sym(rb_intern("collection")),
4050
- rb_external_str_new(er.collection->data(), static_cast<long>(er.collection->size())));
3976
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(er.collection.value()));
4051
3977
  }
4052
3978
  rb_ary_push(roles, role);
4053
3979
  }
@@ -4070,7 +3996,7 @@ cb_Backend_user_get_all(VALUE self, VALUE domain, VALUE timeout)
4070
3996
  VALUE exc = Qnil;
4071
3997
  do {
4072
3998
  couchbase::operations::user_get_all_request req{};
4073
- exc = cb__extract_timeout(req, timeout);
3999
+ exc = cb_extract_timeout(req, timeout);
4074
4000
  if (!NIL_P(exc)) {
4075
4001
  break;
4076
4002
  }
@@ -4086,16 +4012,16 @@ cb_Backend_user_get_all(VALUE self, VALUE domain, VALUE timeout)
4086
4012
  auto f = barrier->get_future();
4087
4013
  backend->cluster->execute_http(
4088
4014
  req, [barrier](couchbase::operations::user_get_all_response&& resp) mutable { barrier->set_value(resp); });
4089
- auto resp = f.get();
4015
+ auto resp = cb_wait_for_future(f);
4090
4016
  if (resp.ctx.ec) {
4091
- exc = cb__map_error_code(resp.ctx, "unable to fetch users");
4017
+ exc = cb_map_error_code(resp.ctx, "unable to fetch users");
4092
4018
  break;
4093
4019
  }
4094
4020
 
4095
4021
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.users.size()));
4096
4022
  for (const auto& entry : resp.users) {
4097
4023
  VALUE user = rb_hash_new();
4098
- cb__extract_user(entry, user);
4024
+ cb_extract_user(entry, user);
4099
4025
  rb_ary_push(res, user);
4100
4026
  }
4101
4027
  return res;
@@ -4121,7 +4047,7 @@ cb_Backend_user_get(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4121
4047
  VALUE exc = Qnil;
4122
4048
  do {
4123
4049
  couchbase::operations::user_get_request req{};
4124
- exc = cb__extract_timeout(req, timeout);
4050
+ exc = cb_extract_timeout(req, timeout);
4125
4051
  if (!NIL_P(exc)) {
4126
4052
  break;
4127
4053
  }
@@ -4138,14 +4064,14 @@ cb_Backend_user_get(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4138
4064
  auto f = barrier->get_future();
4139
4065
  backend->cluster->execute_http(req,
4140
4066
  [barrier](couchbase::operations::user_get_response&& resp) mutable { barrier->set_value(resp); });
4141
- auto resp = f.get();
4067
+ auto resp = cb_wait_for_future(f);
4142
4068
  if (resp.ctx.ec) {
4143
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4069
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4144
4070
  break;
4145
4071
  }
4146
4072
 
4147
4073
  VALUE res = rb_hash_new();
4148
- cb__extract_user(resp.user, res);
4074
+ cb_extract_user(resp.user, res);
4149
4075
  return res;
4150
4076
  } while (false);
4151
4077
  rb_exc_raise(exc);
@@ -4169,7 +4095,7 @@ cb_Backend_user_drop(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4169
4095
  VALUE exc = Qnil;
4170
4096
  do {
4171
4097
  couchbase::operations::user_drop_request req{};
4172
- exc = cb__extract_timeout(req, timeout);
4098
+ exc = cb_extract_timeout(req, timeout);
4173
4099
  if (!NIL_P(exc)) {
4174
4100
  break;
4175
4101
  }
@@ -4186,9 +4112,9 @@ cb_Backend_user_drop(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4186
4112
  auto f = barrier->get_future();
4187
4113
  backend->cluster->execute_http(req,
4188
4114
  [barrier](couchbase::operations::user_drop_response&& resp) mutable { barrier->set_value(resp); });
4189
- auto resp = f.get();
4115
+ auto resp = cb_wait_for_future(f);
4190
4116
  if (resp.ctx.ec) {
4191
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4117
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4192
4118
  break;
4193
4119
  }
4194
4120
 
@@ -4215,7 +4141,7 @@ cb_Backend_user_upsert(VALUE self, VALUE domain, VALUE user, VALUE timeout)
4215
4141
  VALUE exc = Qnil;
4216
4142
  do {
4217
4143
  couchbase::operations::user_upsert_request req{};
4218
- exc = cb__extract_timeout(req, timeout);
4144
+ exc = cb_extract_timeout(req, timeout);
4219
4145
  if (!NIL_P(exc)) {
4220
4146
  break;
4221
4147
  }
@@ -4282,10 +4208,10 @@ cb_Backend_user_upsert(VALUE self, VALUE domain, VALUE user, VALUE timeout)
4282
4208
  auto f = barrier->get_future();
4283
4209
  backend->cluster->execute_http(req,
4284
4210
  [barrier](couchbase::operations::user_upsert_response&& resp) mutable { barrier->set_value(resp); });
4285
- auto resp = f.get();
4211
+ auto resp = cb_wait_for_future(f);
4286
4212
  if (resp.ctx.ec) {
4287
- exc = cb__map_error_code(resp.ctx,
4288
- fmt::format(R"(unable to upsert user "{}" ({}))", req.user.username, fmt::join(resp.errors, ", ")));
4213
+ exc = cb_map_error_code(resp.ctx,
4214
+ fmt::format(R"(unable to upsert user "{}" ({}))", req.user.username, fmt::join(resp.errors, ", ")));
4289
4215
  break;
4290
4216
  }
4291
4217
 
@@ -4296,34 +4222,27 @@ cb_Backend_user_upsert(VALUE self, VALUE domain, VALUE user, VALUE timeout)
4296
4222
  }
4297
4223
 
4298
4224
  static void
4299
- cb__extract_group(const couchbase::operations::rbac::group& entry, VALUE group)
4225
+ cb_extract_group(const couchbase::operations::rbac::group& entry, VALUE group)
4300
4226
  {
4301
- rb_hash_aset(group, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
4227
+ rb_hash_aset(group, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
4302
4228
  if (entry.description) {
4303
- rb_hash_aset(group,
4304
- rb_id2sym(rb_intern("description")),
4305
- rb_external_str_new(entry.description->data(), static_cast<long>(entry.description->size())));
4229
+ rb_hash_aset(group, rb_id2sym(rb_intern("description")), cb_str_new(entry.description.value()));
4306
4230
  }
4307
4231
  if (entry.ldap_group_reference) {
4308
- rb_hash_aset(group,
4309
- rb_id2sym(rb_intern("ldap_group_reference")),
4310
- rb_external_str_new(entry.ldap_group_reference->data(), static_cast<long>(entry.ldap_group_reference->size())));
4232
+ rb_hash_aset(group, rb_id2sym(rb_intern("ldap_group_reference")), cb_str_new(entry.ldap_group_reference.value()));
4311
4233
  }
4312
4234
  VALUE roles = rb_ary_new_capa(static_cast<long>(entry.roles.size()));
4313
4235
  for (const auto& er : entry.roles) {
4314
4236
  VALUE role = rb_hash_new();
4315
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(er.name.data(), static_cast<long>(er.name.size())));
4237
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(er.name));
4316
4238
  if (er.bucket) {
4317
- rb_hash_aset(
4318
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(er.bucket->data(), static_cast<long>(er.bucket->size())));
4239
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(er.bucket.value()));
4319
4240
  }
4320
4241
  if (er.scope) {
4321
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(er.scope->data(), static_cast<long>(er.scope->size())));
4242
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(er.scope.value()));
4322
4243
  }
4323
4244
  if (er.collection) {
4324
- rb_hash_aset(role,
4325
- rb_id2sym(rb_intern("collection")),
4326
- rb_external_str_new(er.collection->data(), static_cast<long>(er.collection->size())));
4245
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(er.collection.value()));
4327
4246
  }
4328
4247
  rb_ary_push(roles, role);
4329
4248
  }
@@ -4344,7 +4263,7 @@ cb_Backend_group_get_all(VALUE self, VALUE timeout)
4344
4263
  VALUE exc = Qnil;
4345
4264
  do {
4346
4265
  couchbase::operations::group_get_all_request req{};
4347
- exc = cb__extract_timeout(req, timeout);
4266
+ exc = cb_extract_timeout(req, timeout);
4348
4267
  if (!NIL_P(exc)) {
4349
4268
  break;
4350
4269
  }
@@ -4352,16 +4271,16 @@ cb_Backend_group_get_all(VALUE self, VALUE timeout)
4352
4271
  auto f = barrier->get_future();
4353
4272
  backend->cluster->execute_http(
4354
4273
  req, [barrier](couchbase::operations::group_get_all_response&& resp) mutable { barrier->set_value(resp); });
4355
- auto resp = f.get();
4274
+ auto resp = cb_wait_for_future(f);
4356
4275
  if (resp.ctx.ec) {
4357
- exc = cb__map_error_code(resp.ctx, "unable to fetch groups");
4276
+ exc = cb_map_error_code(resp.ctx, "unable to fetch groups");
4358
4277
  break;
4359
4278
  }
4360
4279
 
4361
4280
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.groups.size()));
4362
4281
  for (const auto& entry : resp.groups) {
4363
4282
  VALUE group = rb_hash_new();
4364
- cb__extract_group(entry, group);
4283
+ cb_extract_group(entry, group);
4365
4284
  rb_ary_push(res, group);
4366
4285
  }
4367
4286
  return res;
@@ -4386,7 +4305,7 @@ cb_Backend_group_get(VALUE self, VALUE name, VALUE timeout)
4386
4305
  VALUE exc = Qnil;
4387
4306
  do {
4388
4307
  couchbase::operations::group_get_request req{};
4389
- exc = cb__extract_timeout(req, timeout);
4308
+ exc = cb_extract_timeout(req, timeout);
4390
4309
  if (!NIL_P(exc)) {
4391
4310
  break;
4392
4311
  }
@@ -4395,14 +4314,14 @@ cb_Backend_group_get(VALUE self, VALUE name, VALUE timeout)
4395
4314
  auto f = barrier->get_future();
4396
4315
  backend->cluster->execute_http(req,
4397
4316
  [barrier](couchbase::operations::group_get_response&& resp) mutable { barrier->set_value(resp); });
4398
- auto resp = f.get();
4317
+ auto resp = cb_wait_for_future(f);
4399
4318
  if (resp.ctx.ec) {
4400
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to fetch group "{}")", req.name));
4319
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to fetch group "{}")", req.name));
4401
4320
  break;
4402
4321
  }
4403
4322
 
4404
4323
  VALUE res = rb_hash_new();
4405
- cb__extract_group(resp.group, res);
4324
+ cb_extract_group(resp.group, res);
4406
4325
  return res;
4407
4326
  } while (false);
4408
4327
  rb_exc_raise(exc);
@@ -4425,7 +4344,7 @@ cb_Backend_group_drop(VALUE self, VALUE name, VALUE timeout)
4425
4344
  VALUE exc = Qnil;
4426
4345
  do {
4427
4346
  couchbase::operations::group_drop_request req{};
4428
- exc = cb__extract_timeout(req, timeout);
4347
+ exc = cb_extract_timeout(req, timeout);
4429
4348
  if (!NIL_P(exc)) {
4430
4349
  break;
4431
4350
  }
@@ -4434,9 +4353,9 @@ cb_Backend_group_drop(VALUE self, VALUE name, VALUE timeout)
4434
4353
  auto f = barrier->get_future();
4435
4354
  backend->cluster->execute_http(req,
4436
4355
  [barrier](couchbase::operations::group_drop_response&& resp) mutable { barrier->set_value(resp); });
4437
- auto resp = f.get();
4356
+ auto resp = cb_wait_for_future(f);
4438
4357
  if (resp.ctx.ec) {
4439
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to drop group "{}")", req.name));
4358
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to drop group "{}")", req.name));
4440
4359
  break;
4441
4360
  }
4442
4361
 
@@ -4462,7 +4381,7 @@ cb_Backend_group_upsert(VALUE self, VALUE group, VALUE timeout)
4462
4381
  VALUE exc = Qnil;
4463
4382
  do {
4464
4383
  couchbase::operations::group_upsert_request req{};
4465
- exc = cb__extract_timeout(req, timeout);
4384
+ exc = cb_extract_timeout(req, timeout);
4466
4385
  if (!NIL_P(exc)) {
4467
4386
  break;
4468
4387
  }
@@ -4510,10 +4429,10 @@ cb_Backend_group_upsert(VALUE self, VALUE group, VALUE timeout)
4510
4429
  auto f = barrier->get_future();
4511
4430
  backend->cluster->execute_http(
4512
4431
  req, [barrier](couchbase::operations::group_upsert_response&& resp) mutable { barrier->set_value(resp); });
4513
- auto resp = f.get();
4432
+ auto resp = cb_wait_for_future(f);
4514
4433
  if (resp.ctx.ec) {
4515
- exc = cb__map_error_code(resp.ctx,
4516
- fmt::format(R"(unable to upsert group "{}" ({}))", req.group.name, fmt::join(resp.errors, ", ")));
4434
+ exc =
4435
+ cb_map_error_code(resp.ctx, fmt::format(R"(unable to upsert group "{}" ({}))", req.group.name, fmt::join(resp.errors, ", ")));
4517
4436
  break;
4518
4437
  }
4519
4438
 
@@ -4541,9 +4460,9 @@ cb_Backend_cluster_enable_developer_preview(VALUE self)
4541
4460
  auto f = barrier->get_future();
4542
4461
  backend->cluster->execute_http(
4543
4462
  req, [barrier](couchbase::operations::cluster_developer_preview_enable_response&& resp) mutable { barrier->set_value(resp); });
4544
- auto resp = f.get();
4463
+ auto resp = cb_wait_for_future(f);
4545
4464
  if (resp.ctx.ec) {
4546
- exc = cb__map_error_code(resp.ctx, "unable to enable developer preview for this cluster");
4465
+ exc = cb_map_error_code(resp.ctx, "unable to enable developer preview for this cluster");
4547
4466
  break;
4548
4467
  }
4549
4468
  spdlog::critical(
@@ -4571,7 +4490,7 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4571
4490
  VALUE exc = Qnil;
4572
4491
  do {
4573
4492
  couchbase::operations::scope_get_all_request req{};
4574
- exc = cb__extract_timeout(req, timeout);
4493
+ exc = cb_extract_timeout(req, timeout);
4575
4494
  if (!NIL_P(exc)) {
4576
4495
  break;
4577
4496
  }
@@ -4580,9 +4499,9 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4580
4499
  auto f = barrier->get_future();
4581
4500
  backend->cluster->execute_http(
4582
4501
  req, [barrier](couchbase::operations::scope_get_all_response&& resp) mutable { barrier->set_value(resp); });
4583
- auto resp = f.get();
4502
+ auto resp = cb_wait_for_future(f);
4584
4503
  if (resp.ctx.ec) {
4585
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get list of the scopes of the bucket \"{}\"", req.bucket_name));
4504
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get list of the scopes of the bucket \"{}\"", req.bucket_name));
4586
4505
  break;
4587
4506
  }
4588
4507
 
@@ -4592,13 +4511,12 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4592
4511
  for (const auto& s : resp.manifest.scopes) {
4593
4512
  VALUE scope = rb_hash_new();
4594
4513
  rb_hash_aset(scope, rb_id2sym(rb_intern("uid")), ULL2NUM(s.uid));
4595
- rb_hash_aset(scope, rb_id2sym(rb_intern("name")), rb_external_str_new(s.name.data(), static_cast<long>(s.name.size())));
4514
+ rb_hash_aset(scope, rb_id2sym(rb_intern("name")), cb_str_new(s.name));
4596
4515
  VALUE collections = rb_ary_new_capa(static_cast<long>(s.collections.size()));
4597
4516
  for (const auto& c : s.collections) {
4598
4517
  VALUE collection = rb_hash_new();
4599
4518
  rb_hash_aset(collection, rb_id2sym(rb_intern("uid")), ULL2NUM(c.uid));
4600
- rb_hash_aset(
4601
- collection, rb_id2sym(rb_intern("name")), rb_external_str_new(c.name.data(), static_cast<long>(c.name.size())));
4519
+ rb_hash_aset(collection, rb_id2sym(rb_intern("name")), cb_str_new(c.name));
4602
4520
  rb_ary_push(collections, collection);
4603
4521
  }
4604
4522
  rb_hash_aset(scope, rb_id2sym(rb_intern("collections")), collections);
@@ -4628,7 +4546,7 @@ cb_Backend_collections_manifest_get(VALUE self, VALUE bucket_name, VALUE timeout
4628
4546
  VALUE exc = Qnil;
4629
4547
  do {
4630
4548
  couchbase::operations::collections_manifest_get_request req{};
4631
- exc = cb__extract_timeout(req, timeout);
4549
+ exc = cb_extract_timeout(req, timeout);
4632
4550
  if (!NIL_P(exc)) {
4633
4551
  break;
4634
4552
  }
@@ -4637,9 +4555,9 @@ cb_Backend_collections_manifest_get(VALUE self, VALUE bucket_name, VALUE timeout
4637
4555
  auto f = barrier->get_future();
4638
4556
  backend->cluster->execute(
4639
4557
  req, [barrier](couchbase::operations::collections_manifest_get_response&& resp) mutable { barrier->set_value(resp); });
4640
- auto resp = f.get();
4558
+ auto resp = cb_wait_for_future(f);
4641
4559
  if (resp.ctx.ec) {
4642
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get collections manifest of the bucket \"{}\"", req.id.bucket));
4560
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get collections manifest of the bucket \"{}\"", req.id.bucket));
4643
4561
  break;
4644
4562
  }
4645
4563
 
@@ -4649,13 +4567,12 @@ cb_Backend_collections_manifest_get(VALUE self, VALUE bucket_name, VALUE timeout
4649
4567
  for (const auto& s : resp.manifest.scopes) {
4650
4568
  VALUE scope = rb_hash_new();
4651
4569
  rb_hash_aset(scope, rb_id2sym(rb_intern("uid")), ULL2NUM(s.uid));
4652
- rb_hash_aset(scope, rb_id2sym(rb_intern("name")), rb_external_str_new(s.name.data(), static_cast<long>(s.name.size())));
4570
+ rb_hash_aset(scope, rb_id2sym(rb_intern("name")), cb_str_new(s.name));
4653
4571
  VALUE collections = rb_ary_new_capa(static_cast<long>(s.collections.size()));
4654
4572
  for (const auto& c : s.collections) {
4655
4573
  VALUE collection = rb_hash_new();
4656
4574
  rb_hash_aset(collection, rb_id2sym(rb_intern("uid")), ULL2NUM(c.uid));
4657
- rb_hash_aset(
4658
- collection, rb_id2sym(rb_intern("name")), rb_external_str_new(c.name.data(), static_cast<long>(c.name.size())));
4575
+ rb_hash_aset(collection, rb_id2sym(rb_intern("name")), cb_str_new(c.name));
4659
4576
  rb_ary_push(collections, collection);
4660
4577
  }
4661
4578
  rb_hash_aset(scope, rb_id2sym(rb_intern("collections")), collections);
@@ -4686,7 +4603,7 @@ cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE t
4686
4603
  VALUE exc = Qnil;
4687
4604
  do {
4688
4605
  couchbase::operations::scope_create_request req{};
4689
- exc = cb__extract_timeout(req, timeout);
4606
+ exc = cb_extract_timeout(req, timeout);
4690
4607
  if (!NIL_P(exc)) {
4691
4608
  break;
4692
4609
  }
@@ -4696,10 +4613,10 @@ cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE t
4696
4613
  auto f = barrier->get_future();
4697
4614
  backend->cluster->execute_http(
4698
4615
  req, [barrier](couchbase::operations::scope_create_response&& resp) mutable { barrier->set_value(resp); });
4699
- auto resp = f.get();
4616
+ auto resp = cb_wait_for_future(f);
4700
4617
  if (resp.ctx.ec) {
4701
- exc = cb__map_error_code(resp.ctx,
4702
- fmt::format(R"(unable to create the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4618
+ exc = cb_map_error_code(resp.ctx,
4619
+ fmt::format(R"(unable to create the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4703
4620
  break;
4704
4621
  }
4705
4622
  return ULL2NUM(resp.uid);
@@ -4725,7 +4642,7 @@ cb_Backend_scope_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE tim
4725
4642
  VALUE exc = Qnil;
4726
4643
  do {
4727
4644
  couchbase::operations::scope_drop_request req{};
4728
- exc = cb__extract_timeout(req, timeout);
4645
+ exc = cb_extract_timeout(req, timeout);
4729
4646
  if (!NIL_P(exc)) {
4730
4647
  break;
4731
4648
  }
@@ -4735,10 +4652,10 @@ cb_Backend_scope_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE tim
4735
4652
  auto f = barrier->get_future();
4736
4653
  backend->cluster->execute_http(req,
4737
4654
  [barrier](couchbase::operations::scope_drop_response&& resp) mutable { barrier->set_value(resp); });
4738
- auto resp = f.get();
4655
+ auto resp = cb_wait_for_future(f);
4739
4656
  if (resp.ctx.ec) {
4740
- exc = cb__map_error_code(resp.ctx,
4741
- fmt::format(R"(unable to drop the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4657
+ exc = cb_map_error_code(resp.ctx,
4658
+ fmt::format(R"(unable to drop the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4742
4659
  break;
4743
4660
  }
4744
4661
  return ULL2NUM(resp.uid);
@@ -4765,7 +4682,7 @@ cb_Backend_collection_create(VALUE self, VALUE bucket_name, VALUE scope_name, VA
4765
4682
  VALUE exc = Qnil;
4766
4683
  do {
4767
4684
  couchbase::operations::collection_create_request req{};
4768
- exc = cb__extract_timeout(req, timeout);
4685
+ exc = cb_extract_timeout(req, timeout);
4769
4686
  if (!NIL_P(exc)) {
4770
4687
  break;
4771
4688
  }
@@ -4781,9 +4698,9 @@ cb_Backend_collection_create(VALUE self, VALUE bucket_name, VALUE scope_name, VA
4781
4698
  auto f = barrier->get_future();
4782
4699
  backend->cluster->execute_http(
4783
4700
  req, [barrier](couchbase::operations::collection_create_response&& resp) mutable { barrier->set_value(resp); });
4784
- auto resp = f.get();
4701
+ auto resp = cb_wait_for_future(f);
4785
4702
  if (resp.ctx.ec) {
4786
- exc = cb__map_error_code(
4703
+ exc = cb_map_error_code(
4787
4704
  resp.ctx,
4788
4705
  fmt::format(
4789
4706
  R"(unable create the collection "{}.{}" on the bucket "{}")", req.scope_name, req.collection_name, req.bucket_name));
@@ -4813,7 +4730,7 @@ cb_Backend_collection_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALU
4813
4730
  VALUE exc = Qnil;
4814
4731
  do {
4815
4732
  couchbase::operations::collection_drop_request req{};
4816
- exc = cb__extract_timeout(req, timeout);
4733
+ exc = cb_extract_timeout(req, timeout);
4817
4734
  if (!NIL_P(exc)) {
4818
4735
  break;
4819
4736
  }
@@ -4825,9 +4742,9 @@ cb_Backend_collection_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALU
4825
4742
  auto f = barrier->get_future();
4826
4743
  backend->cluster->execute_http(
4827
4744
  req, [barrier](couchbase::operations::collection_drop_response&& resp) mutable { barrier->set_value(resp); });
4828
- auto resp = f.get();
4745
+ auto resp = cb_wait_for_future(f);
4829
4746
  if (resp.ctx.ec) {
4830
- exc = cb__map_error_code(
4747
+ exc = cb_map_error_code(
4831
4748
  resp.ctx,
4832
4749
  fmt::format(
4833
4750
  R"(unable to drop the collection "{}.{}" on the bucket "{}")", req.scope_name, req.collection_name, req.bucket_name));
@@ -4855,7 +4772,7 @@ cb_Backend_query_index_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4855
4772
  VALUE exc = Qnil;
4856
4773
  do {
4857
4774
  couchbase::operations::query_index_get_all_request req{};
4858
- exc = cb__extract_timeout(req, timeout);
4775
+ exc = cb_extract_timeout(req, timeout);
4859
4776
  if (!NIL_P(exc)) {
4860
4777
  break;
4861
4778
  }
@@ -4864,50 +4781,38 @@ cb_Backend_query_index_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4864
4781
  auto f = barrier->get_future();
4865
4782
  backend->cluster->execute_http(
4866
4783
  req, [barrier](couchbase::operations::query_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
4867
- auto resp = f.get();
4784
+ auto resp = cb_wait_for_future(f);
4868
4785
  if (resp.ctx.ec) {
4869
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get list of the indexes of the bucket \"{}\"", req.bucket_name));
4786
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get list of the indexes of the bucket \"{}\"", req.bucket_name));
4870
4787
  break;
4871
4788
  }
4872
4789
 
4873
4790
  VALUE res = rb_hash_new();
4874
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
4791
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
4875
4792
  VALUE indexes = rb_ary_new_capa(static_cast<long>(resp.indexes.size()));
4876
4793
  for (const auto& idx : resp.indexes) {
4877
4794
  VALUE index = rb_hash_new();
4878
- rb_hash_aset(index, rb_id2sym(rb_intern("id")), rb_external_str_new(idx.id.data(), static_cast<long>(idx.id.size())));
4879
- rb_hash_aset(index, rb_id2sym(rb_intern("state")), rb_external_str_new(idx.state.data(), static_cast<long>(idx.state.size())));
4880
- rb_hash_aset(index, rb_id2sym(rb_intern("name")), rb_external_str_new(idx.name.data(), static_cast<long>(idx.name.size())));
4881
- rb_hash_aset(index,
4882
- rb_id2sym(rb_intern("datastore_id")),
4883
- rb_external_str_new(idx.datastore_id.data(), static_cast<long>(idx.datastore_id.size())));
4884
- rb_hash_aset(index,
4885
- rb_id2sym(rb_intern("keyspace_id")),
4886
- rb_external_str_new(idx.keyspace_id.data(), static_cast<long>(idx.keyspace_id.size())));
4887
- rb_hash_aset(index,
4888
- rb_id2sym(rb_intern("namespace_id")),
4889
- rb_external_str_new(idx.namespace_id.data(), static_cast<long>(idx.namespace_id.size())));
4890
- rb_hash_aset(index, rb_id2sym(rb_intern("type")), rb_external_str_new(idx.type.data(), static_cast<long>(idx.type.size())));
4795
+ rb_hash_aset(index, rb_id2sym(rb_intern("id")), cb_str_new(idx.id));
4796
+ rb_hash_aset(index, rb_id2sym(rb_intern("state")), cb_str_new(idx.state));
4797
+ rb_hash_aset(index, rb_id2sym(rb_intern("name")), cb_str_new(idx.name));
4798
+ rb_hash_aset(index, rb_id2sym(rb_intern("datastore_id")), cb_str_new(idx.datastore_id));
4799
+ rb_hash_aset(index, rb_id2sym(rb_intern("keyspace_id")), cb_str_new(idx.keyspace_id));
4800
+ rb_hash_aset(index, rb_id2sym(rb_intern("namespace_id")), cb_str_new(idx.namespace_id));
4801
+ rb_hash_aset(index, rb_id2sym(rb_intern("type")), cb_str_new(idx.type));
4891
4802
  rb_hash_aset(index, rb_id2sym(rb_intern("is_primary")), idx.is_primary ? Qtrue : Qfalse);
4892
4803
  VALUE index_key = rb_ary_new_capa(static_cast<long>(idx.index_key.size()));
4893
4804
  for (const auto& key : idx.index_key) {
4894
- rb_ary_push(index_key, rb_external_str_new(key.data(), static_cast<long>(key.size())));
4805
+ rb_ary_push(index_key, cb_str_new(key));
4895
4806
  }
4896
4807
  rb_hash_aset(index, rb_id2sym(rb_intern("index_key")), index_key);
4897
4808
  if (idx.scope_id) {
4898
- rb_hash_aset(index,
4899
- rb_id2sym(rb_intern("scope_id")),
4900
- rb_external_str_new(idx.scope_id->data(), static_cast<long>(idx.scope_id->size())));
4809
+ rb_hash_aset(index, rb_id2sym(rb_intern("scope_id")), cb_str_new(idx.scope_id.value()));
4901
4810
  }
4902
4811
  if (idx.bucket_id) {
4903
- rb_hash_aset(index,
4904
- rb_id2sym(rb_intern("bucket_id")),
4905
- rb_external_str_new(idx.bucket_id->data(), static_cast<long>(idx.bucket_id->size())));
4812
+ rb_hash_aset(index, rb_id2sym(rb_intern("bucket_id")), cb_str_new(idx.bucket_id.value()));
4906
4813
  }
4907
4814
  if (idx.condition) {
4908
- rb_hash_aset(index,
4909
- rb_id2sym(rb_intern("condition")),
4910
- rb_external_str_new(idx.condition->data(), static_cast<long>(idx.condition->size())));
4815
+ rb_hash_aset(index, rb_id2sym(rb_intern("condition")), cb_str_new(idx.condition.value()));
4911
4816
  }
4912
4817
  rb_ary_push(indexes, index);
4913
4818
  }
@@ -4938,7 +4843,7 @@ cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, V
4938
4843
  VALUE exc = Qnil;
4939
4844
  do {
4940
4845
  couchbase::operations::query_index_create_request req{};
4941
- exc = cb__extract_timeout(req, timeout);
4846
+ exc = cb_extract_timeout(req, timeout);
4942
4847
  if (!NIL_P(exc)) {
4943
4848
  break;
4944
4849
  }
@@ -4987,31 +4892,30 @@ cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, V
4987
4892
  auto f = barrier->get_future();
4988
4893
  backend->cluster->execute_http(
4989
4894
  req, [barrier](couchbase::operations::query_index_create_response&& resp) mutable { barrier->set_value(resp); });
4990
- auto resp = f.get();
4895
+ auto resp = cb_wait_for_future(f);
4991
4896
  if (resp.ctx.ec) {
4992
4897
  if (!resp.errors.empty()) {
4993
4898
  const auto& first_error = resp.errors.front();
4994
- exc = cb__map_error_code(resp.ctx,
4995
- fmt::format(R"(unable to create index "{}" on the bucket "{}" ({}: {}))",
4996
- req.index_name,
4997
- req.bucket_name,
4998
- first_error.code,
4999
- first_error.message));
4899
+ exc = cb_map_error_code(resp.ctx,
4900
+ fmt::format(R"(unable to create index "{}" on the bucket "{}" ({}: {}))",
4901
+ req.index_name,
4902
+ req.bucket_name,
4903
+ first_error.code,
4904
+ first_error.message));
5000
4905
  } else {
5001
- exc = cb__map_error_code(resp.ctx,
5002
- fmt::format(R"(unable to create index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
4906
+ exc = cb_map_error_code(resp.ctx,
4907
+ fmt::format(R"(unable to create index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
5003
4908
  }
5004
4909
  break;
5005
4910
  }
5006
4911
  VALUE res = rb_hash_new();
5007
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
4912
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5008
4913
  if (!resp.errors.empty()) {
5009
4914
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5010
4915
  for (const auto& err : resp.errors) {
5011
4916
  VALUE error = rb_hash_new();
5012
4917
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5013
- rb_hash_aset(
5014
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
4918
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5015
4919
  rb_ary_push(errors, error);
5016
4920
  }
5017
4921
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5039,7 +4943,7 @@ cb_Backend_query_index_drop(VALUE self, VALUE bucket_name, VALUE index_name, VAL
5039
4943
  VALUE exc = Qnil;
5040
4944
  do {
5041
4945
  couchbase::operations::query_index_drop_request req{};
5042
- exc = cb__extract_timeout(req, timeout);
4946
+ exc = cb_extract_timeout(req, timeout);
5043
4947
  if (!NIL_P(exc)) {
5044
4948
  break;
5045
4949
  }
@@ -5067,31 +4971,30 @@ cb_Backend_query_index_drop(VALUE self, VALUE bucket_name, VALUE index_name, VAL
5067
4971
  auto f = barrier->get_future();
5068
4972
  backend->cluster->execute_http(
5069
4973
  req, [barrier](couchbase::operations::query_index_drop_response&& resp) mutable { barrier->set_value(resp); });
5070
- auto resp = f.get();
4974
+ auto resp = cb_wait_for_future(f);
5071
4975
  if (resp.ctx.ec) {
5072
4976
  if (!resp.errors.empty()) {
5073
4977
  const auto& first_error = resp.errors.front();
5074
- exc = cb__map_error_code(resp.ctx,
5075
- fmt::format(R"(unable to drop index "{}" on the bucket "{}" ({}: {}))",
5076
- req.index_name,
5077
- req.bucket_name,
5078
- first_error.code,
5079
- first_error.message));
4978
+ exc = cb_map_error_code(resp.ctx,
4979
+ fmt::format(R"(unable to drop index "{}" on the bucket "{}" ({}: {}))",
4980
+ req.index_name,
4981
+ req.bucket_name,
4982
+ first_error.code,
4983
+ first_error.message));
5080
4984
  } else {
5081
- exc = cb__map_error_code(resp.ctx,
5082
- fmt::format(R"(unable to drop index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
4985
+ exc = cb_map_error_code(resp.ctx,
4986
+ fmt::format(R"(unable to drop index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
5083
4987
  }
5084
4988
  break;
5085
4989
  }
5086
4990
  VALUE res = rb_hash_new();
5087
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
4991
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5088
4992
  if (!resp.errors.empty()) {
5089
4993
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5090
4994
  for (const auto& err : resp.errors) {
5091
4995
  VALUE error = rb_hash_new();
5092
4996
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5093
- rb_hash_aset(
5094
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
4997
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5095
4998
  rb_ary_push(errors, error);
5096
4999
  }
5097
5000
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5121,7 +5024,7 @@ cb_Backend_query_index_create_primary(VALUE self, VALUE bucket_name, VALUE optio
5121
5024
  VALUE exc = Qnil;
5122
5025
  do {
5123
5026
  couchbase::operations::query_index_create_request req{};
5124
- exc = cb__extract_timeout(req, timeout);
5027
+ exc = cb_extract_timeout(req, timeout);
5125
5028
  if (!NIL_P(exc)) {
5126
5029
  break;
5127
5030
  }
@@ -5163,30 +5066,29 @@ cb_Backend_query_index_create_primary(VALUE self, VALUE bucket_name, VALUE optio
5163
5066
  auto f = barrier->get_future();
5164
5067
  backend->cluster->execute_http(
5165
5068
  req, [barrier](couchbase::operations::query_index_create_response&& resp) mutable { barrier->set_value(resp); });
5166
- auto resp = f.get();
5069
+ auto resp = cb_wait_for_future(f);
5167
5070
  if (resp.ctx.ec) {
5168
5071
  if (!resp.errors.empty()) {
5169
5072
  const auto& first_error = resp.errors.front();
5170
- exc = cb__map_error_code(resp.ctx,
5171
- fmt::format(R"(unable to create primary index on the bucket "{}" ({}: {}))",
5172
- req.bucket_name,
5173
- first_error.code,
5174
- first_error.message));
5073
+ exc = cb_map_error_code(resp.ctx,
5074
+ fmt::format(R"(unable to create primary index on the bucket "{}" ({}: {}))",
5075
+ req.bucket_name,
5076
+ first_error.code,
5077
+ first_error.message));
5175
5078
  } else {
5176
- exc = cb__map_error_code(
5079
+ exc = cb_map_error_code(
5177
5080
  resp.ctx, fmt::format(R"(unable to create primary index on the bucket "{}")", req.index_name, req.bucket_name));
5178
5081
  }
5179
5082
  break;
5180
5083
  }
5181
5084
  VALUE res = rb_hash_new();
5182
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5085
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5183
5086
  if (!resp.errors.empty()) {
5184
5087
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5185
5088
  for (const auto& err : resp.errors) {
5186
5089
  VALUE error = rb_hash_new();
5187
5090
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5188
- rb_hash_aset(
5189
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
5091
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5190
5092
  rb_ary_push(errors, error);
5191
5093
  }
5192
5094
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5213,7 +5115,7 @@ cb_Backend_query_index_drop_primary(VALUE self, VALUE bucket_name, VALUE options
5213
5115
  VALUE exc = Qnil;
5214
5116
  do {
5215
5117
  couchbase::operations::query_index_drop_request req{};
5216
- exc = cb__extract_timeout(req, timeout);
5118
+ exc = cb_extract_timeout(req, timeout);
5217
5119
  if (!NIL_P(exc)) {
5218
5120
  break;
5219
5121
  }
@@ -5247,28 +5149,27 @@ cb_Backend_query_index_drop_primary(VALUE self, VALUE bucket_name, VALUE options
5247
5149
  auto f = barrier->get_future();
5248
5150
  backend->cluster->execute_http(
5249
5151
  req, [barrier](couchbase::operations::query_index_drop_response&& resp) mutable { barrier->set_value(resp); });
5250
- auto resp = f.get();
5152
+ auto resp = cb_wait_for_future(f);
5251
5153
  if (resp.ctx.ec) {
5252
5154
  if (!resp.errors.empty()) {
5253
5155
  const auto& first_error = resp.errors.front();
5254
- exc = cb__map_error_code(
5156
+ exc = cb_map_error_code(
5255
5157
  resp.ctx,
5256
5158
  fmt::format(
5257
5159
  R"(unable to drop primary index on the bucket "{}" ({}: {}))", req.bucket_name, first_error.code, first_error.message));
5258
5160
  } else {
5259
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to drop primary index on the bucket "{}")", req.bucket_name));
5161
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to drop primary index on the bucket "{}")", req.bucket_name));
5260
5162
  }
5261
5163
  break;
5262
5164
  }
5263
5165
  VALUE res = rb_hash_new();
5264
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5166
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5265
5167
  if (!resp.errors.empty()) {
5266
5168
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5267
5169
  for (const auto& err : resp.errors) {
5268
5170
  VALUE error = rb_hash_new();
5269
5171
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5270
- rb_hash_aset(
5271
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
5172
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5272
5173
  rb_ary_push(errors, error);
5273
5174
  }
5274
5175
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5295,7 +5196,7 @@ cb_Backend_query_index_build_deferred(VALUE self, VALUE bucket_name, VALUE timeo
5295
5196
  VALUE exc = Qnil;
5296
5197
  do {
5297
5198
  couchbase::operations::query_index_build_deferred_request req{};
5298
- exc = cb__extract_timeout(req, timeout);
5199
+ exc = cb_extract_timeout(req, timeout);
5299
5200
  if (!NIL_P(exc)) {
5300
5201
  break;
5301
5202
  }
@@ -5304,18 +5205,18 @@ cb_Backend_query_index_build_deferred(VALUE self, VALUE bucket_name, VALUE timeo
5304
5205
  auto f = barrier->get_future();
5305
5206
  backend->cluster->execute_http(
5306
5207
  req, [barrier](couchbase::operations::query_index_build_deferred_response&& resp) mutable { barrier->set_value(resp); });
5307
- auto resp = f.get();
5208
+ auto resp = cb_wait_for_future(f);
5308
5209
  if (resp.ctx.ec) {
5309
5210
  if (!resp.errors.empty()) {
5310
5211
  const auto& first_error = resp.errors.front();
5311
- exc = cb__map_error_code(
5212
+ exc = cb_map_error_code(
5312
5213
  resp.ctx,
5313
5214
  fmt::format(
5314
5215
  R"(unable to drop primary index on the bucket "{}" ({}: {}))", req.bucket_name, first_error.code, first_error.message));
5315
5216
 
5316
5217
  } else {
5317
- exc = cb__map_error_code(
5318
- resp.ctx, fmt::format("unable to trigger build for deferred indexes for the bucket \"{}\"", req.bucket_name));
5218
+ exc = cb_map_error_code(resp.ctx,
5219
+ fmt::format("unable to trigger build for deferred indexes for the bucket \"{}\"", req.bucket_name));
5319
5220
  }
5320
5221
  break;
5321
5222
  }
@@ -5347,37 +5248,27 @@ cb_Backend_query_index_watch(VALUE self, VALUE bucket_name, VALUE index_names, V
5347
5248
  }
5348
5249
 
5349
5250
  static void
5350
- cb__extract_search_index(VALUE index, const couchbase::operations::search_index& idx)
5251
+ cb_extract_search_index(VALUE index, const couchbase::operations::search_index& idx)
5351
5252
  {
5352
- rb_hash_aset(index, rb_id2sym(rb_intern("uuid")), rb_external_str_new(idx.uuid.data(), static_cast<long>(idx.uuid.size())));
5353
- rb_hash_aset(index, rb_id2sym(rb_intern("name")), rb_external_str_new(idx.name.data(), static_cast<long>(idx.name.size())));
5354
- rb_hash_aset(index, rb_id2sym(rb_intern("type")), rb_external_str_new(idx.type.data(), static_cast<long>(idx.type.size())));
5253
+ rb_hash_aset(index, rb_id2sym(rb_intern("uuid")), cb_str_new(idx.uuid));
5254
+ rb_hash_aset(index, rb_id2sym(rb_intern("name")), cb_str_new(idx.name));
5255
+ rb_hash_aset(index, rb_id2sym(rb_intern("type")), cb_str_new(idx.type));
5355
5256
  if (!idx.params_json.empty()) {
5356
- rb_hash_aset(
5357
- index, rb_id2sym(rb_intern("params")), rb_external_str_new(idx.params_json.data(), static_cast<long>(idx.params_json.size())));
5257
+ rb_hash_aset(index, rb_id2sym(rb_intern("params")), cb_str_new(idx.params_json));
5358
5258
  }
5359
5259
 
5360
5260
  if (!idx.source_uuid.empty()) {
5361
- rb_hash_aset(index,
5362
- rb_id2sym(rb_intern("source_uuid")),
5363
- rb_external_str_new(idx.source_uuid.data(), static_cast<long>(idx.source_uuid.size())));
5261
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_uuid")), cb_str_new(idx.source_uuid));
5364
5262
  }
5365
5263
  if (!idx.source_name.empty()) {
5366
- rb_hash_aset(index,
5367
- rb_id2sym(rb_intern("source_name")),
5368
- rb_external_str_new(idx.source_name.data(), static_cast<long>(idx.source_name.size())));
5264
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_name")), cb_str_new(idx.source_name));
5369
5265
  }
5370
- rb_hash_aset(
5371
- index, rb_id2sym(rb_intern("source_type")), rb_external_str_new(idx.source_type.data(), static_cast<long>(idx.source_type.size())));
5266
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_type")), cb_str_new(idx.source_type));
5372
5267
  if (!idx.source_params_json.empty()) {
5373
- rb_hash_aset(index,
5374
- rb_id2sym(rb_intern("source_params")),
5375
- rb_external_str_new(idx.source_params_json.data(), static_cast<long>(idx.source_params_json.size())));
5268
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_params")), cb_str_new(idx.source_params_json));
5376
5269
  }
5377
5270
  if (!idx.plan_params_json.empty()) {
5378
- rb_hash_aset(index,
5379
- rb_id2sym(rb_intern("plan_params")),
5380
- rb_external_str_new(idx.plan_params_json.data(), static_cast<long>(idx.plan_params_json.size())));
5271
+ rb_hash_aset(index, rb_id2sym(rb_intern("plan_params")), cb_str_new(idx.plan_params_json));
5381
5272
  }
5382
5273
  }
5383
5274
 
@@ -5395,7 +5286,7 @@ cb_Backend_search_index_get_all(VALUE self, VALUE timeout)
5395
5286
  VALUE exc = Qnil;
5396
5287
  do {
5397
5288
  couchbase::operations::search_index_get_all_request req{};
5398
- exc = cb__extract_timeout(req, timeout);
5289
+ exc = cb_extract_timeout(req, timeout);
5399
5290
  if (!NIL_P(exc)) {
5400
5291
  break;
5401
5292
  }
@@ -5403,20 +5294,18 @@ cb_Backend_search_index_get_all(VALUE self, VALUE timeout)
5403
5294
  auto f = barrier->get_future();
5404
5295
  backend->cluster->execute_http(
5405
5296
  req, [barrier](couchbase::operations::search_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
5406
- auto resp = f.get();
5297
+ auto resp = cb_wait_for_future(f);
5407
5298
  if (resp.ctx.ec) {
5408
- exc = cb__map_error_code(resp.ctx, "unable to get list of the search indexes");
5299
+ exc = cb_map_error_code(resp.ctx, "unable to get list of the search indexes");
5409
5300
  break;
5410
5301
  }
5411
5302
  VALUE res = rb_hash_new();
5412
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5413
- rb_hash_aset(res,
5414
- rb_id2sym(rb_intern("impl_version")),
5415
- rb_external_str_new(resp.impl_version.data(), static_cast<long>(resp.impl_version.size())));
5303
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5304
+ rb_hash_aset(res, rb_id2sym(rb_intern("impl_version")), cb_str_new(resp.impl_version));
5416
5305
  VALUE indexes = rb_ary_new_capa(static_cast<long>(resp.indexes.size()));
5417
5306
  for (const auto& idx : resp.indexes) {
5418
5307
  VALUE index = rb_hash_new();
5419
- cb__extract_search_index(index, idx);
5308
+ cb_extract_search_index(index, idx);
5420
5309
  rb_ary_push(indexes, index);
5421
5310
  }
5422
5311
  rb_hash_aset(res, rb_id2sym(rb_intern("indexes")), indexes);
@@ -5441,7 +5330,7 @@ cb_Backend_search_index_get(VALUE self, VALUE index_name, VALUE timeout)
5441
5330
  VALUE exc = Qnil;
5442
5331
  do {
5443
5332
  couchbase::operations::search_index_get_request req{};
5444
- exc = cb__extract_timeout(req, timeout);
5333
+ exc = cb_extract_timeout(req, timeout);
5445
5334
  if (!NIL_P(exc)) {
5446
5335
  break;
5447
5336
  }
@@ -5450,17 +5339,17 @@ cb_Backend_search_index_get(VALUE self, VALUE index_name, VALUE timeout)
5450
5339
  auto f = barrier->get_future();
5451
5340
  backend->cluster->execute_http(
5452
5341
  req, [barrier](couchbase::operations::search_index_get_response&& resp) mutable { barrier->set_value(resp); });
5453
- auto resp = f.get();
5342
+ auto resp = cb_wait_for_future(f);
5454
5343
  if (resp.ctx.ec) {
5455
5344
  if (resp.error.empty()) {
5456
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\"", req.index_name));
5345
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\"", req.index_name));
5457
5346
  } else {
5458
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\": {}", req.index_name, resp.error));
5347
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\": {}", req.index_name, resp.error));
5459
5348
  }
5460
5349
  break;
5461
5350
  }
5462
5351
  VALUE res = rb_hash_new();
5463
- cb__extract_search_index(res, resp.index);
5352
+ cb_extract_search_index(res, resp.index);
5464
5353
  return res;
5465
5354
  } while (false);
5466
5355
  rb_exc_raise(exc);
@@ -5482,7 +5371,7 @@ cb_Backend_search_index_upsert(VALUE self, VALUE index_definition, VALUE timeout
5482
5371
  VALUE exc = Qnil;
5483
5372
  do {
5484
5373
  couchbase::operations::search_index_upsert_request req{};
5485
- exc = cb__extract_timeout(req, timeout);
5374
+ exc = cb_extract_timeout(req, timeout);
5486
5375
  if (!NIL_P(exc)) {
5487
5376
  break;
5488
5377
  }
@@ -5539,17 +5428,17 @@ cb_Backend_search_index_upsert(VALUE self, VALUE index_definition, VALUE timeout
5539
5428
  auto f = barrier->get_future();
5540
5429
  backend->cluster->execute_http(
5541
5430
  req, [barrier](couchbase::operations::search_index_upsert_response&& resp) mutable { barrier->set_value(resp); });
5542
- auto resp = f.get();
5431
+ auto resp = cb_wait_for_future(f);
5543
5432
  if (resp.ctx.ec) {
5544
5433
  if (resp.error.empty()) {
5545
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\"", req.index.name));
5434
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\"", req.index.name));
5546
5435
  } else {
5547
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\": {}", req.index.name, resp.error));
5436
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\": {}", req.index.name, resp.error));
5548
5437
  }
5549
5438
  break;
5550
5439
  }
5551
5440
  VALUE res = rb_hash_new();
5552
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5441
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5553
5442
  return res;
5554
5443
  } while (false);
5555
5444
  rb_exc_raise(exc);
@@ -5571,7 +5460,7 @@ cb_Backend_search_index_drop(VALUE self, VALUE index_name, VALUE timeout)
5571
5460
  VALUE exc = Qnil;
5572
5461
  do {
5573
5462
  couchbase::operations::search_index_drop_request req{};
5574
- exc = cb__extract_timeout(req, timeout);
5463
+ exc = cb_extract_timeout(req, timeout);
5575
5464
  if (!NIL_P(exc)) {
5576
5465
  break;
5577
5466
  }
@@ -5580,17 +5469,17 @@ cb_Backend_search_index_drop(VALUE self, VALUE index_name, VALUE timeout)
5580
5469
  auto f = barrier->get_future();
5581
5470
  backend->cluster->execute_http(
5582
5471
  req, [barrier](couchbase::operations::search_index_drop_response&& resp) mutable { barrier->set_value(resp); });
5583
- auto resp = f.get();
5472
+ auto resp = cb_wait_for_future(f);
5584
5473
  if (resp.ctx.ec) {
5585
5474
  if (resp.error.empty()) {
5586
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\"", req.index_name));
5475
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\"", req.index_name));
5587
5476
  } else {
5588
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\": {}", req.index_name, resp.error));
5477
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\": {}", req.index_name, resp.error));
5589
5478
  }
5590
5479
  break;
5591
5480
  }
5592
5481
  VALUE res = rb_hash_new();
5593
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5482
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5594
5483
  return res;
5595
5484
  } while (false);
5596
5485
  rb_exc_raise(exc);
@@ -5612,7 +5501,7 @@ cb_Backend_search_index_get_documents_count(VALUE self, VALUE index_name, VALUE
5612
5501
  VALUE exc = Qnil;
5613
5502
  do {
5614
5503
  couchbase::operations::search_index_get_documents_count_request req{};
5615
- exc = cb__extract_timeout(req, timeout);
5504
+ exc = cb_extract_timeout(req, timeout);
5616
5505
  if (!NIL_P(exc)) {
5617
5506
  break;
5618
5507
  }
@@ -5621,20 +5510,20 @@ cb_Backend_search_index_get_documents_count(VALUE self, VALUE index_name, VALUE
5621
5510
  auto f = barrier->get_future();
5622
5511
  backend->cluster->execute_http(
5623
5512
  req, [barrier](couchbase::operations::search_index_get_documents_count_response&& resp) mutable { barrier->set_value(resp); });
5624
- auto resp = f.get();
5513
+ auto resp = cb_wait_for_future(f);
5625
5514
  if (resp.ctx.ec) {
5626
5515
  if (resp.error.empty()) {
5627
- exc = cb__map_error_code(
5516
+ exc = cb_map_error_code(
5628
5517
  resp.ctx, fmt::format("unable to get number of the indexed documents for the search index \"{}\"", req.index_name));
5629
5518
  } else {
5630
- exc = cb__map_error_code(
5519
+ exc = cb_map_error_code(
5631
5520
  resp.ctx,
5632
5521
  fmt::format("unable to get number of the indexed documents for the search index \"{}\": {}", req.index_name, resp.error));
5633
5522
  }
5634
5523
  break;
5635
5524
  }
5636
5525
  VALUE res = rb_hash_new();
5637
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5526
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5638
5527
  rb_hash_aset(res, rb_id2sym(rb_intern("count")), ULL2NUM(resp.count));
5639
5528
  return res;
5640
5529
  } while (false);
@@ -5657,7 +5546,7 @@ cb_Backend_search_index_get_stats(VALUE self, VALUE index_name, VALUE timeout)
5657
5546
  VALUE exc = Qnil;
5658
5547
  do {
5659
5548
  couchbase::operations::search_index_get_stats_request req{};
5660
- exc = cb__extract_timeout(req, timeout);
5549
+ exc = cb_extract_timeout(req, timeout);
5661
5550
  if (!NIL_P(exc)) {
5662
5551
  break;
5663
5552
  }
@@ -5666,17 +5555,17 @@ cb_Backend_search_index_get_stats(VALUE self, VALUE index_name, VALUE timeout)
5666
5555
  auto f = barrier->get_future();
5667
5556
  backend->cluster->execute_http(
5668
5557
  req, [barrier](couchbase::operations::search_index_get_stats_response&& resp) mutable { barrier->set_value(resp); });
5669
- auto resp = f.get();
5558
+ auto resp = cb_wait_for_future(f);
5670
5559
  if (resp.ctx.ec) {
5671
5560
  if (resp.error.empty()) {
5672
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get stats for the search index \"{}\"", req.index_name));
5561
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get stats for the search index \"{}\"", req.index_name));
5673
5562
  } else {
5674
- exc = cb__map_error_code(resp.ctx,
5675
- fmt::format("unable to get stats for the search index \"{}\": {}", req.index_name, resp.error));
5563
+ exc = cb_map_error_code(resp.ctx,
5564
+ fmt::format("unable to get stats for the search index \"{}\": {}", req.index_name, resp.error));
5676
5565
  }
5677
5566
  break;
5678
5567
  }
5679
- return rb_external_str_new(resp.stats.data(), static_cast<long>(resp.stats.size()));
5568
+ return cb_str_new(resp.stats);
5680
5569
  } while (false);
5681
5570
  rb_exc_raise(exc);
5682
5571
  return Qnil;
@@ -5696,7 +5585,7 @@ cb_Backend_search_get_stats(VALUE self, VALUE timeout)
5696
5585
  VALUE exc = Qnil;
5697
5586
  do {
5698
5587
  couchbase::operations::search_index_stats_request req{};
5699
- exc = cb__extract_timeout(req, timeout);
5588
+ exc = cb_extract_timeout(req, timeout);
5700
5589
  if (!NIL_P(exc)) {
5701
5590
  break;
5702
5591
  }
@@ -5704,12 +5593,12 @@ cb_Backend_search_get_stats(VALUE self, VALUE timeout)
5704
5593
  auto f = barrier->get_future();
5705
5594
  backend->cluster->execute_http(
5706
5595
  req, [barrier](couchbase::operations::search_index_stats_response&& resp) mutable { barrier->set_value(resp); });
5707
- auto resp = f.get();
5596
+ auto resp = cb_wait_for_future(f);
5708
5597
  if (resp.ctx.ec) {
5709
- exc = cb__map_error_code(resp.ctx, "unable to get stats for the search service");
5598
+ exc = cb_map_error_code(resp.ctx, "unable to get stats for the search service");
5710
5599
  break;
5711
5600
  }
5712
- return rb_external_str_new(resp.stats.data(), static_cast<long>(resp.stats.size()));
5601
+ return cb_str_new(resp.stats);
5713
5602
  } while (false);
5714
5603
  rb_exc_raise(exc);
5715
5604
  return Qnil;
@@ -5730,7 +5619,7 @@ cb_Backend_search_index_pause_ingest(VALUE self, VALUE index_name, VALUE timeout
5730
5619
  VALUE exc = Qnil;
5731
5620
  do {
5732
5621
  couchbase::operations::search_index_control_ingest_request req{};
5733
- exc = cb__extract_timeout(req, timeout);
5622
+ exc = cb_extract_timeout(req, timeout);
5734
5623
  if (!NIL_P(exc)) {
5735
5624
  break;
5736
5625
  }
@@ -5740,18 +5629,18 @@ cb_Backend_search_index_pause_ingest(VALUE self, VALUE index_name, VALUE timeout
5740
5629
  auto f = barrier->get_future();
5741
5630
  backend->cluster->execute_http(
5742
5631
  req, [barrier](couchbase::operations::search_index_control_ingest_response&& resp) mutable { barrier->set_value(resp); });
5743
- auto resp = f.get();
5632
+ auto resp = cb_wait_for_future(f);
5744
5633
  if (resp.ctx.ec) {
5745
5634
  if (resp.error.empty()) {
5746
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to pause ingest for the search index \"{}\"", req.index_name));
5635
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to pause ingest for the search index \"{}\"", req.index_name));
5747
5636
  } else {
5748
- exc = cb__map_error_code(resp.ctx,
5749
- fmt::format("unable to pause ingest for the search index \"{}\": {}", req.index_name, resp.error));
5637
+ exc = cb_map_error_code(resp.ctx,
5638
+ fmt::format("unable to pause ingest for the search index \"{}\": {}", req.index_name, resp.error));
5750
5639
  }
5751
5640
  break;
5752
5641
  }
5753
5642
  VALUE res = rb_hash_new();
5754
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5643
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5755
5644
  return res;
5756
5645
  } while (false);
5757
5646
  rb_exc_raise(exc);
@@ -5773,7 +5662,7 @@ cb_Backend_search_index_resume_ingest(VALUE self, VALUE index_name, VALUE timeou
5773
5662
  VALUE exc = Qnil;
5774
5663
  do {
5775
5664
  couchbase::operations::search_index_control_ingest_request req{};
5776
- exc = cb__extract_timeout(req, timeout);
5665
+ exc = cb_extract_timeout(req, timeout);
5777
5666
  if (!NIL_P(exc)) {
5778
5667
  break;
5779
5668
  }
@@ -5783,18 +5672,18 @@ cb_Backend_search_index_resume_ingest(VALUE self, VALUE index_name, VALUE timeou
5783
5672
  auto f = barrier->get_future();
5784
5673
  backend->cluster->execute_http(
5785
5674
  req, [barrier](couchbase::operations::search_index_control_ingest_response&& resp) mutable { barrier->set_value(resp); });
5786
- auto resp = f.get();
5675
+ auto resp = cb_wait_for_future(f);
5787
5676
  if (resp.ctx.ec) {
5788
5677
  if (resp.error.empty()) {
5789
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to resume ingest for the search index \"{}\"", req.index_name));
5678
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to resume ingest for the search index \"{}\"", req.index_name));
5790
5679
  } else {
5791
- exc = cb__map_error_code(
5792
- resp.ctx, fmt::format("unable to resume ingest for the search index \"{}\": {}", req.index_name, resp.error));
5680
+ exc = cb_map_error_code(resp.ctx,
5681
+ fmt::format("unable to resume ingest for the search index \"{}\": {}", req.index_name, resp.error));
5793
5682
  }
5794
5683
  break;
5795
5684
  }
5796
5685
  VALUE res = rb_hash_new();
5797
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5686
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5798
5687
  return res;
5799
5688
  } while (false);
5800
5689
  rb_exc_raise(exc);
@@ -5816,7 +5705,7 @@ cb_Backend_search_index_allow_querying(VALUE self, VALUE index_name, VALUE timeo
5816
5705
  VALUE exc = Qnil;
5817
5706
  do {
5818
5707
  couchbase::operations::search_index_control_query_request req{};
5819
- exc = cb__extract_timeout(req, timeout);
5708
+ exc = cb_extract_timeout(req, timeout);
5820
5709
  if (!NIL_P(exc)) {
5821
5710
  break;
5822
5711
  }
@@ -5826,18 +5715,18 @@ cb_Backend_search_index_allow_querying(VALUE self, VALUE index_name, VALUE timeo
5826
5715
  auto f = barrier->get_future();
5827
5716
  backend->cluster->execute_http(
5828
5717
  req, [barrier](couchbase::operations::search_index_control_query_response&& resp) mutable { barrier->set_value(resp); });
5829
- auto resp = f.get();
5718
+ auto resp = cb_wait_for_future(f);
5830
5719
  if (resp.ctx.ec) {
5831
5720
  if (resp.error.empty()) {
5832
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to allow querying for the search index \"{}\"", req.index_name));
5721
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to allow querying for the search index \"{}\"", req.index_name));
5833
5722
  } else {
5834
- exc = cb__map_error_code(
5723
+ exc = cb_map_error_code(
5835
5724
  resp.ctx, fmt::format("unable to allow querying for the search index \"{}\": {}", req.index_name, resp.error));
5836
5725
  }
5837
5726
  break;
5838
5727
  }
5839
5728
  VALUE res = rb_hash_new();
5840
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5729
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5841
5730
  return res;
5842
5731
  } while (false);
5843
5732
  rb_exc_raise(exc);
@@ -5859,7 +5748,7 @@ cb_Backend_search_index_disallow_querying(VALUE self, VALUE index_name, VALUE ti
5859
5748
  VALUE exc = Qnil;
5860
5749
  do {
5861
5750
  couchbase::operations::search_index_control_query_request req{};
5862
- exc = cb__extract_timeout(req, timeout);
5751
+ exc = cb_extract_timeout(req, timeout);
5863
5752
  if (!NIL_P(exc)) {
5864
5753
  break;
5865
5754
  }
@@ -5869,18 +5758,18 @@ cb_Backend_search_index_disallow_querying(VALUE self, VALUE index_name, VALUE ti
5869
5758
  auto f = barrier->get_future();
5870
5759
  backend->cluster->execute_http(
5871
5760
  req, [barrier](couchbase::operations::search_index_control_query_response&& resp) mutable { barrier->set_value(resp); });
5872
- auto resp = f.get();
5761
+ auto resp = cb_wait_for_future(f);
5873
5762
  if (resp.ctx.ec) {
5874
5763
  if (resp.error.empty()) {
5875
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to disallow querying for the search index \"{}\"", req.index_name));
5764
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to disallow querying for the search index \"{}\"", req.index_name));
5876
5765
  } else {
5877
- exc = cb__map_error_code(
5766
+ exc = cb_map_error_code(
5878
5767
  resp.ctx, fmt::format("unable to disallow querying for the search index \"{}\": {}", req.index_name, resp.error));
5879
5768
  }
5880
5769
  break;
5881
5770
  }
5882
5771
  VALUE res = rb_hash_new();
5883
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5772
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5884
5773
  return res;
5885
5774
  } while (false);
5886
5775
  rb_exc_raise(exc);
@@ -5902,7 +5791,7 @@ cb_Backend_search_index_freeze_plan(VALUE self, VALUE index_name, VALUE timeout)
5902
5791
  VALUE exc = Qnil;
5903
5792
  do {
5904
5793
  couchbase::operations::search_index_control_plan_freeze_request req{};
5905
- exc = cb__extract_timeout(req, timeout);
5794
+ exc = cb_extract_timeout(req, timeout);
5906
5795
  if (!NIL_P(exc)) {
5907
5796
  break;
5908
5797
  }
@@ -5912,18 +5801,18 @@ cb_Backend_search_index_freeze_plan(VALUE self, VALUE index_name, VALUE timeout)
5912
5801
  auto f = barrier->get_future();
5913
5802
  backend->cluster->execute_http(
5914
5803
  req, [barrier](couchbase::operations::search_index_control_plan_freeze_response&& resp) mutable { barrier->set_value(resp); });
5915
- auto resp = f.get();
5804
+ auto resp = cb_wait_for_future(f);
5916
5805
  if (resp.ctx.ec) {
5917
5806
  if (resp.error.empty()) {
5918
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\"", req.index_name));
5807
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\"", req.index_name));
5919
5808
  } else {
5920
5809
  exc =
5921
- cb__map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\": {}", req.index_name, resp.error));
5810
+ cb_map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\": {}", req.index_name, resp.error));
5922
5811
  }
5923
5812
  break;
5924
5813
  }
5925
5814
  VALUE res = rb_hash_new();
5926
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5815
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5927
5816
  return res;
5928
5817
  } while (false);
5929
5818
  rb_exc_raise(exc);
@@ -5945,7 +5834,7 @@ cb_Backend_search_index_unfreeze_plan(VALUE self, VALUE index_name, VALUE timeou
5945
5834
  VALUE exc = Qnil;
5946
5835
  do {
5947
5836
  couchbase::operations::search_index_control_plan_freeze_request req{};
5948
- exc = cb__extract_timeout(req, timeout);
5837
+ exc = cb_extract_timeout(req, timeout);
5949
5838
  if (!NIL_P(exc)) {
5950
5839
  break;
5951
5840
  }
@@ -5955,18 +5844,18 @@ cb_Backend_search_index_unfreeze_plan(VALUE self, VALUE index_name, VALUE timeou
5955
5844
  auto f = barrier->get_future();
5956
5845
  backend->cluster->execute_http(
5957
5846
  req, [barrier](couchbase::operations::search_index_control_plan_freeze_response&& resp) mutable { barrier->set_value(resp); });
5958
- auto resp = f.get();
5847
+ auto resp = cb_wait_for_future(f);
5959
5848
  if (resp.ctx.ec) {
5960
5849
  if (resp.error.empty()) {
5961
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to unfreeze plan for the search index \"{}\"", req.index_name));
5850
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to unfreeze plan for the search index \"{}\"", req.index_name));
5962
5851
  } else {
5963
- exc = cb__map_error_code(resp.ctx,
5964
- fmt::format("unable to unfreeze for the search index \"{}\": {}", req.index_name, resp.error));
5852
+ exc = cb_map_error_code(resp.ctx,
5853
+ fmt::format("unable to unfreeze for the search index \"{}\": {}", req.index_name, resp.error));
5965
5854
  }
5966
5855
  break;
5967
5856
  }
5968
5857
  VALUE res = rb_hash_new();
5969
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5858
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5970
5859
  return res;
5971
5860
  } while (false);
5972
5861
  rb_exc_raise(exc);
@@ -5989,7 +5878,7 @@ cb_Backend_search_index_analyze_document(VALUE self, VALUE index_name, VALUE enc
5989
5878
  VALUE exc = Qnil;
5990
5879
  do {
5991
5880
  couchbase::operations::search_index_analyze_document_request req{};
5992
- exc = cb__extract_timeout(req, timeout);
5881
+ exc = cb_extract_timeout(req, timeout);
5993
5882
  if (!NIL_P(exc)) {
5994
5883
  break;
5995
5884
  }
@@ -6001,20 +5890,19 @@ cb_Backend_search_index_analyze_document(VALUE self, VALUE index_name, VALUE enc
6001
5890
  auto f = barrier->get_future();
6002
5891
  backend->cluster->execute_http(
6003
5892
  req, [barrier](couchbase::operations::search_index_analyze_document_response&& resp) mutable { barrier->set_value(resp); });
6004
- auto resp = f.get();
5893
+ auto resp = cb_wait_for_future(f);
6005
5894
  if (resp.ctx.ec) {
6006
5895
  if (resp.error.empty()) {
6007
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to analyze document using the search index \"{}\"", req.index_name));
5896
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to analyze document using the search index \"{}\"", req.index_name));
6008
5897
  } else {
6009
- exc = cb__map_error_code(
5898
+ exc = cb_map_error_code(
6010
5899
  resp.ctx, fmt::format("unable to analyze document using the search index \"{}\": {}", req.index_name, resp.error));
6011
5900
  }
6012
5901
  break;
6013
5902
  }
6014
5903
  VALUE res = rb_hash_new();
6015
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
6016
- rb_hash_aset(
6017
- res, rb_id2sym(rb_intern("analysis")), rb_external_str_new(resp.analysis.data(), static_cast<long>(resp.analysis.size())));
5904
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5905
+ rb_hash_aset(res, rb_id2sym(rb_intern("analysis")), cb_str_new(resp.analysis));
6018
5906
  return res;
6019
5907
  } while (false);
6020
5908
  rb_exc_raise(exc);
@@ -6044,7 +5932,7 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6044
5932
  Check_Type(client_context_id, T_STRING);
6045
5933
  req.client_context_id.assign(RSTRING_PTR(client_context_id), static_cast<size_t>(RSTRING_LEN(client_context_id)));
6046
5934
  }
6047
- exc = cb__extract_timeout(req, options);
5935
+ exc = cb_extract_timeout(req, options);
6048
5936
  if (!NIL_P(exc)) {
6049
5937
  break;
6050
5938
  }
@@ -6182,25 +6070,22 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6182
6070
  VALUE raw_params = rb_hash_aref(options, rb_id2sym(rb_intern("raw_parameters")));
6183
6071
  if (!NIL_P(raw_params)) {
6184
6072
  Check_Type(raw_params, T_HASH);
6185
- rb_hash_foreach(raw_params, INT_FUNC(cb__for_each_named_param), reinterpret_cast<VALUE>(&req));
6073
+ rb_hash_foreach(raw_params, INT_FUNC(cb_for_each_named_param), reinterpret_cast<VALUE>(&req));
6186
6074
  }
6187
6075
 
6188
6076
  auto barrier = std::make_shared<std::promise<couchbase::operations::search_response>>();
6189
6077
  auto f = barrier->get_future();
6190
6078
  backend->cluster->execute_http(req, [barrier](couchbase::operations::search_response&& resp) mutable { barrier->set_value(resp); });
6191
- auto resp = f.get();
6079
+ auto resp = cb_wait_for_future(f);
6192
6080
  if (resp.ctx.ec) {
6193
6081
  exc =
6194
- cb__map_error_code(resp.ctx, fmt::format("unable to perform search query for index \"{}\": {}", req.index_name, resp.error));
6082
+ cb_map_error_code(resp.ctx, fmt::format("unable to perform search query for index \"{}\": {}", req.index_name, resp.error));
6195
6083
  break;
6196
6084
  }
6197
6085
  VALUE res = rb_hash_new();
6198
6086
 
6199
6087
  VALUE meta_data = rb_hash_new();
6200
- rb_hash_aset(
6201
- meta_data,
6202
- rb_id2sym(rb_intern("client_context_id")),
6203
- rb_external_str_new(resp.meta_data.client_context_id.data(), static_cast<long>(resp.meta_data.client_context_id.size())));
6088
+ rb_hash_aset(meta_data, rb_id2sym(rb_intern("client_context_id")), cb_str_new(resp.meta_data.client_context_id));
6204
6089
 
6205
6090
  VALUE metrics = rb_hash_new();
6206
6091
  rb_hash_aset(metrics,
@@ -6214,10 +6099,8 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6214
6099
 
6215
6100
  if (!resp.meta_data.errors.empty()) {
6216
6101
  VALUE errors = rb_hash_new();
6217
- for (auto err : resp.meta_data.errors) {
6218
- rb_hash_aset(errors,
6219
- rb_external_str_new(err.first.data(), static_cast<long>(err.first.size())),
6220
- rb_external_str_new(err.second.data(), static_cast<long>(err.second.size())));
6102
+ for (const auto& err : resp.meta_data.errors) {
6103
+ rb_hash_aset(errors, cb_str_new(err.first), cb_str_new(err.second));
6221
6104
  }
6222
6105
  rb_hash_aset(meta_data, rb_id2sym(rb_intern("errors")), errors);
6223
6106
  }
@@ -6227,16 +6110,14 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6227
6110
  VALUE rows = rb_ary_new_capa(static_cast<long>(resp.rows.size()));
6228
6111
  for (const auto& entry : resp.rows) {
6229
6112
  VALUE row = rb_hash_new();
6230
- rb_hash_aset(
6231
- row, rb_id2sym(rb_intern("index")), rb_external_str_new(entry.index.data(), static_cast<long>(entry.index.size())));
6232
- rb_hash_aset(row, rb_id2sym(rb_intern("id")), rb_external_str_new(entry.id.data(), static_cast<long>(entry.id.size())));
6113
+ rb_hash_aset(row, rb_id2sym(rb_intern("index")), cb_str_new(entry.index));
6114
+ rb_hash_aset(row, rb_id2sym(rb_intern("id")), cb_str_new(entry.id));
6233
6115
  rb_hash_aset(row, rb_id2sym(rb_intern("score")), DBL2NUM(entry.score));
6234
6116
  VALUE locations = rb_ary_new_capa(static_cast<long>(entry.locations.size()));
6235
6117
  for (const auto& loc : entry.locations) {
6236
6118
  VALUE location = rb_hash_new();
6237
- rb_hash_aset(
6238
- row, rb_id2sym(rb_intern("field")), rb_external_str_new(loc.field.data(), static_cast<long>(loc.field.size())));
6239
- rb_hash_aset(row, rb_id2sym(rb_intern("term")), rb_external_str_new(loc.term.data(), static_cast<long>(loc.term.size())));
6119
+ rb_hash_aset(row, rb_id2sym(rb_intern("field")), cb_str_new(loc.field));
6120
+ rb_hash_aset(row, rb_id2sym(rb_intern("term")), cb_str_new(loc.term));
6240
6121
  rb_hash_aset(row, rb_id2sym(rb_intern("pos")), ULL2NUM(loc.position));
6241
6122
  rb_hash_aset(row, rb_id2sym(rb_intern("start_offset")), ULL2NUM(loc.start_offset));
6242
6123
  rb_hash_aset(row, rb_id2sym(rb_intern("end_offset")), ULL2NUM(loc.end_offset));
@@ -6255,22 +6136,17 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6255
6136
  for (const auto& field_fragments : entry.fragments) {
6256
6137
  VALUE fragments_list = rb_ary_new_capa(static_cast<long>(field_fragments.second.size()));
6257
6138
  for (const auto& fragment : field_fragments.second) {
6258
- rb_ary_push(fragments_list, rb_external_str_new(fragment.data(), static_cast<long>(fragment.size())));
6139
+ rb_ary_push(fragments_list, cb_str_new(fragment));
6259
6140
  }
6260
- rb_hash_aset(fragments,
6261
- rb_external_str_new(field_fragments.first.data(), static_cast<long>(field_fragments.first.size())),
6262
- fragments_list);
6141
+ rb_hash_aset(fragments, cb_str_new(field_fragments.first), fragments_list);
6263
6142
  }
6264
6143
  rb_hash_aset(row, rb_id2sym(rb_intern("fragments")), fragments);
6265
6144
  }
6266
6145
  if (!entry.fields.empty()) {
6267
- rb_hash_aset(
6268
- row, rb_id2sym(rb_intern("fields")), rb_external_str_new(entry.fields.data(), static_cast<long>(entry.fields.size())));
6146
+ rb_hash_aset(row, rb_id2sym(rb_intern("fields")), cb_str_new(entry.fields));
6269
6147
  }
6270
6148
  if (!entry.explanation.empty()) {
6271
- rb_hash_aset(row,
6272
- rb_id2sym(rb_intern("explanation")),
6273
- rb_external_str_new(entry.explanation.data(), static_cast<long>(entry.explanation.size())));
6149
+ rb_hash_aset(row, rb_id2sym(rb_intern("explanation")), cb_str_new(entry.explanation));
6274
6150
  }
6275
6151
  rb_ary_push(rows, row);
6276
6152
  }
@@ -6280,10 +6156,9 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6280
6156
  VALUE result_facets = rb_hash_new();
6281
6157
  for (const auto& entry : resp.facets) {
6282
6158
  VALUE facet = rb_hash_new();
6283
- VALUE facet_name = rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size()));
6159
+ VALUE facet_name = cb_str_new(entry.name);
6284
6160
  rb_hash_aset(facet, rb_id2sym(rb_intern("name")), facet_name);
6285
- rb_hash_aset(
6286
- facet, rb_id2sym(rb_intern("field")), rb_external_str_new(entry.field.data(), static_cast<long>(entry.field.size())));
6161
+ rb_hash_aset(facet, rb_id2sym(rb_intern("field")), cb_str_new(entry.field));
6287
6162
  rb_hash_aset(facet, rb_id2sym(rb_intern("total")), ULL2NUM(entry.total));
6288
6163
  rb_hash_aset(facet, rb_id2sym(rb_intern("missing")), ULL2NUM(entry.missing));
6289
6164
  rb_hash_aset(facet, rb_id2sym(rb_intern("other")), ULL2NUM(entry.other));
@@ -6291,8 +6166,7 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6291
6166
  VALUE terms = rb_ary_new_capa(static_cast<long>(entry.terms.size()));
6292
6167
  for (const auto& item : entry.terms) {
6293
6168
  VALUE term = rb_hash_new();
6294
- rb_hash_aset(
6295
- term, rb_id2sym(rb_intern("term")), rb_external_str_new(item.term.data(), static_cast<long>(item.term.size())));
6169
+ rb_hash_aset(term, rb_id2sym(rb_intern("term")), cb_str_new(item.term));
6296
6170
  rb_hash_aset(term, rb_id2sym(rb_intern("count")), ULL2NUM(item.count));
6297
6171
  rb_ary_push(terms, term);
6298
6172
  }
@@ -6301,19 +6175,13 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6301
6175
  VALUE date_ranges = rb_ary_new_capa(static_cast<long>(entry.date_ranges.size()));
6302
6176
  for (const auto& item : entry.date_ranges) {
6303
6177
  VALUE date_range = rb_hash_new();
6304
- rb_hash_aset(date_range,
6305
- rb_id2sym(rb_intern("name")),
6306
- rb_external_str_new(item.name.data(), static_cast<long>(item.name.size())));
6178
+ rb_hash_aset(date_range, rb_id2sym(rb_intern("name")), cb_str_new(item.name));
6307
6179
  rb_hash_aset(date_range, rb_id2sym(rb_intern("count")), ULL2NUM(item.count));
6308
6180
  if (item.start) {
6309
- rb_hash_aset(date_range,
6310
- rb_id2sym(rb_intern("start_time")),
6311
- rb_external_str_new(item.start->data(), static_cast<long>(item.start->size())));
6181
+ rb_hash_aset(date_range, rb_id2sym(rb_intern("start_time")), cb_str_new(item.start.value()));
6312
6182
  }
6313
6183
  if (item.end) {
6314
- rb_hash_aset(date_range,
6315
- rb_id2sym(rb_intern("end_time")),
6316
- rb_external_str_new(item.end->data(), static_cast<long>(item.end->size())));
6184
+ rb_hash_aset(date_range, rb_id2sym(rb_intern("end_time")), cb_str_new(item.end.value()));
6317
6185
  }
6318
6186
  rb_ary_push(date_ranges, date_range);
6319
6187
  }
@@ -6322,9 +6190,7 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6322
6190
  VALUE numeric_ranges = rb_ary_new_capa(static_cast<long>(entry.numeric_ranges.size()));
6323
6191
  for (const auto& item : entry.numeric_ranges) {
6324
6192
  VALUE numeric_range = rb_hash_new();
6325
- rb_hash_aset(numeric_range,
6326
- rb_id2sym(rb_intern("name")),
6327
- rb_external_str_new(item.name.data(), static_cast<long>(item.name.size())));
6193
+ rb_hash_aset(numeric_range, rb_id2sym(rb_intern("name")), cb_str_new(item.name));
6328
6194
  rb_hash_aset(numeric_range, rb_id2sym(rb_intern("count")), ULL2NUM(item.count));
6329
6195
  if (std::holds_alternative<double>(item.min)) {
6330
6196
  rb_hash_aset(numeric_range, rb_id2sym(rb_intern("min")), DBL2NUM(std::get<double>(item.min)));
@@ -6385,18 +6251,16 @@ cb_Backend_dns_srv(VALUE self, VALUE hostname, VALUE service)
6385
6251
  barrier->set_value(resp);
6386
6252
  });
6387
6253
  ctx.run();
6388
- auto resp = f.get();
6254
+ auto resp = cb_wait_for_future(f);
6389
6255
  if (resp.ec) {
6390
- exc = cb__map_error_code(resp.ec, fmt::format("DNS SRV query failure for name \"{}\" (service: {})", host_name, service_name));
6256
+ exc = cb_map_error_code(resp.ec, fmt::format("DNS SRV query failure for name \"{}\" (service: {})", host_name, service_name));
6391
6257
  break;
6392
6258
  }
6393
6259
 
6394
6260
  VALUE res = rb_ary_new();
6395
6261
  for (const auto& target : resp.targets) {
6396
6262
  VALUE addr = rb_hash_new();
6397
- rb_hash_aset(addr,
6398
- rb_id2sym(rb_intern("hostname")),
6399
- rb_external_str_new(target.hostname.data(), static_cast<long>(target.hostname.size())));
6263
+ rb_hash_aset(addr, rb_id2sym(rb_intern("hostname")), cb_str_new(target.hostname));
6400
6264
  rb_hash_aset(addr, rb_id2sym(rb_intern("port")), UINT2NUM(target.port));
6401
6265
  rb_ary_push(res, addr);
6402
6266
  }
@@ -6420,7 +6284,7 @@ cb_Backend_analytics_get_pending_mutations(VALUE self, VALUE timeout)
6420
6284
  VALUE exc = Qnil;
6421
6285
  do {
6422
6286
  couchbase::operations::analytics_get_pending_mutations_request req{};
6423
- exc = cb__extract_timeout(req, timeout);
6287
+ exc = cb_extract_timeout(req, timeout);
6424
6288
  if (!NIL_P(exc)) {
6425
6289
  break;
6426
6290
  }
@@ -6428,13 +6292,13 @@ cb_Backend_analytics_get_pending_mutations(VALUE self, VALUE timeout)
6428
6292
  auto f = barrier->get_future();
6429
6293
  backend->cluster->execute_http(
6430
6294
  req, [barrier](couchbase::operations::analytics_get_pending_mutations_response&& resp) mutable { barrier->set_value(resp); });
6431
- auto resp = f.get();
6295
+ auto resp = cb_wait_for_future(f);
6432
6296
  if (resp.ctx.ec) {
6433
6297
  if (resp.errors.empty()) {
6434
- exc = cb__map_error_code(resp.ctx, "unable to get pending mutations for the analytics service");
6298
+ exc = cb_map_error_code(resp.ctx, "unable to get pending mutations for the analytics service");
6435
6299
  } else {
6436
6300
  const auto& first_error = resp.errors.front();
6437
- exc = cb__map_error_code(
6301
+ exc = cb_map_error_code(
6438
6302
  resp.ctx,
6439
6303
  fmt::format("unable to get pending mutations for the analytics service ({}: {})", first_error.code, first_error.message));
6440
6304
  }
@@ -6442,7 +6306,7 @@ cb_Backend_analytics_get_pending_mutations(VALUE self, VALUE timeout)
6442
6306
  }
6443
6307
  VALUE res = rb_hash_new();
6444
6308
  for (const auto& entry : resp.stats) {
6445
- rb_hash_aset(res, rb_external_str_new(entry.first.data(), static_cast<long>(entry.first.size())), ULL2NUM(entry.second));
6309
+ rb_hash_aset(res, cb_str_new(entry.first), ULL2NUM(entry.second));
6446
6310
  }
6447
6311
  return res;
6448
6312
  } while (false);
@@ -6464,7 +6328,7 @@ cb_Backend_analytics_dataset_get_all(VALUE self, VALUE timeout)
6464
6328
  VALUE exc = Qnil;
6465
6329
  do {
6466
6330
  couchbase::operations::analytics_dataset_get_all_request req{};
6467
- exc = cb__extract_timeout(req, timeout);
6331
+ exc = cb_extract_timeout(req, timeout);
6468
6332
  if (!NIL_P(exc)) {
6469
6333
  break;
6470
6334
  }
@@ -6472,29 +6336,24 @@ cb_Backend_analytics_dataset_get_all(VALUE self, VALUE timeout)
6472
6336
  auto f = barrier->get_future();
6473
6337
  backend->cluster->execute_http(
6474
6338
  req, [barrier](couchbase::operations::analytics_dataset_get_all_response&& resp) mutable { barrier->set_value(resp); });
6475
- auto resp = f.get();
6339
+ auto resp = cb_wait_for_future(f);
6476
6340
  if (resp.ctx.ec) {
6477
6341
  if (resp.errors.empty()) {
6478
- exc = cb__map_error_code(resp.ctx, "unable to fetch all datasets");
6342
+ exc = cb_map_error_code(resp.ctx, "unable to fetch all datasets");
6479
6343
  } else {
6480
6344
  const auto& first_error = resp.errors.front();
6481
6345
  exc =
6482
- cb__map_error_code(resp.ctx, fmt::format("unable to fetch all datasets ({}: {})", first_error.code, first_error.message));
6346
+ cb_map_error_code(resp.ctx, fmt::format("unable to fetch all datasets ({}: {})", first_error.code, first_error.message));
6483
6347
  }
6484
6348
  break;
6485
6349
  }
6486
6350
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.datasets.size()));
6487
6351
  for (const auto& ds : resp.datasets) {
6488
6352
  VALUE dataset = rb_hash_new();
6489
- rb_hash_aset(dataset, rb_id2sym(rb_intern("name")), rb_external_str_new(ds.name.data(), static_cast<long>(ds.name.size())));
6490
- rb_hash_aset(dataset,
6491
- rb_id2sym(rb_intern("dataverse_name")),
6492
- rb_external_str_new(ds.dataverse_name.data(), static_cast<long>(ds.dataverse_name.size())));
6493
- rb_hash_aset(
6494
- dataset, rb_id2sym(rb_intern("link_name")), rb_external_str_new(ds.link_name.data(), static_cast<long>(ds.link_name.size())));
6495
- rb_hash_aset(dataset,
6496
- rb_id2sym(rb_intern("bucket_name")),
6497
- rb_external_str_new(ds.bucket_name.data(), static_cast<long>(ds.bucket_name.size())));
6353
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("name")), cb_str_new(ds.name));
6354
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("dataverse_name")), cb_str_new(ds.dataverse_name));
6355
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("link_name")), cb_str_new(ds.link_name));
6356
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("bucket_name")), cb_str_new(ds.bucket_name));
6498
6357
  rb_ary_push(res, dataset);
6499
6358
  }
6500
6359
  return res;
@@ -6522,7 +6381,7 @@ cb_Backend_analytics_dataset_drop(VALUE self, VALUE dataset_name, VALUE datavers
6522
6381
  VALUE exc = Qnil;
6523
6382
  do {
6524
6383
  couchbase::operations::analytics_dataset_drop_request req{};
6525
- exc = cb__extract_timeout(req, timeout);
6384
+ exc = cb_extract_timeout(req, timeout);
6526
6385
  if (!NIL_P(exc)) {
6527
6386
  break;
6528
6387
  }
@@ -6537,18 +6396,18 @@ cb_Backend_analytics_dataset_drop(VALUE self, VALUE dataset_name, VALUE datavers
6537
6396
  auto f = barrier->get_future();
6538
6397
  backend->cluster->execute_http(
6539
6398
  req, [barrier](couchbase::operations::analytics_dataset_drop_response&& resp) mutable { barrier->set_value(resp); });
6540
- auto resp = f.get();
6399
+ auto resp = cb_wait_for_future(f);
6541
6400
  if (resp.ctx.ec) {
6542
6401
  if (resp.errors.empty()) {
6543
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6402
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6544
6403
  } else {
6545
6404
  const auto& first_error = resp.errors.front();
6546
- exc = cb__map_error_code(resp.ctx,
6547
- fmt::format("unable to drop dataset `{}`.`{}` ({}: {})",
6548
- req.dataverse_name,
6549
- req.dataset_name,
6550
- first_error.code,
6551
- first_error.message));
6405
+ exc = cb_map_error_code(resp.ctx,
6406
+ fmt::format("unable to drop dataset `{}`.`{}` ({}: {})",
6407
+ req.dataverse_name,
6408
+ req.dataset_name,
6409
+ first_error.code,
6410
+ first_error.message));
6552
6411
  }
6553
6412
  break;
6554
6413
  }
@@ -6587,7 +6446,7 @@ cb_Backend_analytics_dataset_create(VALUE self,
6587
6446
  VALUE exc = Qnil;
6588
6447
  do {
6589
6448
  couchbase::operations::analytics_dataset_create_request req{};
6590
- exc = cb__extract_timeout(req, timeout);
6449
+ exc = cb_extract_timeout(req, timeout);
6591
6450
  if (!NIL_P(exc)) {
6592
6451
  break;
6593
6452
  }
@@ -6606,18 +6465,18 @@ cb_Backend_analytics_dataset_create(VALUE self,
6606
6465
  auto f = barrier->get_future();
6607
6466
  backend->cluster->execute_http(
6608
6467
  req, [barrier](couchbase::operations::analytics_dataset_create_response&& resp) mutable { barrier->set_value(resp); });
6609
- auto resp = f.get();
6468
+ auto resp = cb_wait_for_future(f);
6610
6469
  if (resp.ctx.ec) {
6611
6470
  if (resp.errors.empty()) {
6612
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to create dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6471
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to create dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6613
6472
  } else {
6614
6473
  const auto& first_error = resp.errors.front();
6615
- exc = cb__map_error_code(resp.ctx,
6616
- fmt::format("unable to create dataset `{}`.`{}` ({}: {})",
6617
- req.dataverse_name,
6618
- req.dataset_name,
6619
- first_error.code,
6620
- first_error.message));
6474
+ exc = cb_map_error_code(resp.ctx,
6475
+ fmt::format("unable to create dataset `{}`.`{}` ({}: {})",
6476
+ req.dataverse_name,
6477
+ req.dataset_name,
6478
+ first_error.code,
6479
+ first_error.message));
6621
6480
  }
6622
6481
  break;
6623
6482
  }
@@ -6643,7 +6502,7 @@ cb_Backend_analytics_dataverse_drop(VALUE self, VALUE dataverse_name, VALUE igno
6643
6502
  VALUE exc = Qnil;
6644
6503
  do {
6645
6504
  couchbase::operations::analytics_dataverse_drop_request req{};
6646
- exc = cb__extract_timeout(req, timeout);
6505
+ exc = cb_extract_timeout(req, timeout);
6647
6506
  if (!NIL_P(exc)) {
6648
6507
  break;
6649
6508
  }
@@ -6655,13 +6514,13 @@ cb_Backend_analytics_dataverse_drop(VALUE self, VALUE dataverse_name, VALUE igno
6655
6514
  auto f = barrier->get_future();
6656
6515
  backend->cluster->execute_http(
6657
6516
  req, [barrier](couchbase::operations::analytics_dataverse_drop_response&& resp) mutable { barrier->set_value(resp); });
6658
- auto resp = f.get();
6517
+ auto resp = cb_wait_for_future(f);
6659
6518
  if (resp.ctx.ec) {
6660
6519
  if (resp.errors.empty()) {
6661
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop dataverse `{}`", req.dataverse_name));
6520
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop dataverse `{}`", req.dataverse_name));
6662
6521
  } else {
6663
6522
  const auto& first_error = resp.errors.front();
6664
- exc = cb__map_error_code(
6523
+ exc = cb_map_error_code(
6665
6524
  resp.ctx,
6666
6525
  fmt::format("unable to drop dataverse `{}` ({}: {})", req.dataverse_name, first_error.code, first_error.message));
6667
6526
  }
@@ -6692,7 +6551,7 @@ cb_Backend_analytics_dataverse_create(VALUE self, VALUE dataverse_name, VALUE ig
6692
6551
  VALUE exc = Qnil;
6693
6552
  do {
6694
6553
  couchbase::operations::analytics_dataverse_create_request req{};
6695
- exc = cb__extract_timeout(req, timeout);
6554
+ exc = cb_extract_timeout(req, timeout);
6696
6555
  if (!NIL_P(exc)) {
6697
6556
  break;
6698
6557
  }
@@ -6704,13 +6563,13 @@ cb_Backend_analytics_dataverse_create(VALUE self, VALUE dataverse_name, VALUE ig
6704
6563
  auto f = barrier->get_future();
6705
6564
  backend->cluster->execute_http(
6706
6565
  req, [barrier](couchbase::operations::analytics_dataverse_create_response&& resp) mutable { barrier->set_value(resp); });
6707
- auto resp = f.get();
6566
+ auto resp = cb_wait_for_future(f);
6708
6567
  if (resp.ctx.ec) {
6709
6568
  if (resp.errors.empty()) {
6710
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to create dataverse `{}`", req.dataverse_name));
6569
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to create dataverse `{}`", req.dataverse_name));
6711
6570
  } else {
6712
6571
  const auto& first_error = resp.errors.front();
6713
- exc = cb__map_error_code(
6572
+ exc = cb_map_error_code(
6714
6573
  resp.ctx,
6715
6574
  fmt::format("unable to create dataverse `{}` ({}: {})", req.dataverse_name, first_error.code, first_error.message));
6716
6575
  }
@@ -6736,7 +6595,7 @@ cb_Backend_analytics_index_get_all(VALUE self, VALUE timeout)
6736
6595
  VALUE exc = Qnil;
6737
6596
  do {
6738
6597
  couchbase::operations::analytics_index_get_all_request req{};
6739
- exc = cb__extract_timeout(req, timeout);
6598
+ exc = cb_extract_timeout(req, timeout);
6740
6599
  if (!NIL_P(exc)) {
6741
6600
  break;
6742
6601
  }
@@ -6744,27 +6603,23 @@ cb_Backend_analytics_index_get_all(VALUE self, VALUE timeout)
6744
6603
  auto f = barrier->get_future();
6745
6604
  backend->cluster->execute_http(
6746
6605
  req, [barrier](couchbase::operations::analytics_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
6747
- auto resp = f.get();
6606
+ auto resp = cb_wait_for_future(f);
6748
6607
  if (resp.ctx.ec) {
6749
6608
  if (resp.errors.empty()) {
6750
- exc = cb__map_error_code(resp.ctx, "unable to fetch all indexes");
6609
+ exc = cb_map_error_code(resp.ctx, "unable to fetch all indexes");
6751
6610
  } else {
6752
6611
  const auto& first_error = resp.errors.front();
6753
6612
  exc =
6754
- cb__map_error_code(resp.ctx, fmt::format("unable to fetch all indexes ({}: {})", first_error.code, first_error.message));
6613
+ cb_map_error_code(resp.ctx, fmt::format("unable to fetch all indexes ({}: {})", first_error.code, first_error.message));
6755
6614
  }
6756
6615
  break;
6757
6616
  }
6758
6617
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.indexes.size()));
6759
6618
  for (const auto& idx : resp.indexes) {
6760
6619
  VALUE index = rb_hash_new();
6761
- rb_hash_aset(index, rb_id2sym(rb_intern("name")), rb_external_str_new(idx.name.data(), static_cast<long>(idx.name.size())));
6762
- rb_hash_aset(index,
6763
- rb_id2sym(rb_intern("dataset_name")),
6764
- rb_external_str_new(idx.dataset_name.data(), static_cast<long>(idx.dataset_name.size())));
6765
- rb_hash_aset(index,
6766
- rb_id2sym(rb_intern("dataverse_name")),
6767
- rb_external_str_new(idx.dataverse_name.data(), static_cast<long>(idx.dataverse_name.size())));
6620
+ rb_hash_aset(index, rb_id2sym(rb_intern("name")), cb_str_new(idx.name));
6621
+ rb_hash_aset(index, rb_id2sym(rb_intern("dataset_name")), cb_str_new(idx.dataset_name));
6622
+ rb_hash_aset(index, rb_id2sym(rb_intern("dataverse_name")), cb_str_new(idx.dataverse_name));
6768
6623
  rb_hash_aset(index, rb_id2sym(rb_intern("is_primary")), idx.is_primary ? Qtrue : Qfalse);
6769
6624
  rb_ary_push(res, index);
6770
6625
  }
@@ -6801,7 +6656,7 @@ cb_Backend_analytics_index_create(VALUE self,
6801
6656
  VALUE exc = Qnil;
6802
6657
  do {
6803
6658
  couchbase::operations::analytics_index_create_request req{};
6804
- exc = cb__extract_timeout(req, timeout);
6659
+ exc = cb_extract_timeout(req, timeout);
6805
6660
  if (!NIL_P(exc)) {
6806
6661
  break;
6807
6662
  }
@@ -6828,20 +6683,20 @@ cb_Backend_analytics_index_create(VALUE self,
6828
6683
  auto f = barrier->get_future();
6829
6684
  backend->cluster->execute_http(
6830
6685
  req, [barrier](couchbase::operations::analytics_index_create_response&& resp) mutable { barrier->set_value(resp); });
6831
- auto resp = f.get();
6686
+ auto resp = cb_wait_for_future(f);
6832
6687
  if (resp.ctx.ec) {
6833
6688
  if (resp.errors.empty()) {
6834
- exc = cb__map_error_code(
6689
+ exc = cb_map_error_code(
6835
6690
  resp.ctx, fmt::format("unable to create index `{}` on `{}`.`{}`", req.index_name, req.dataverse_name, req.dataset_name));
6836
6691
  } else {
6837
6692
  const auto& first_error = resp.errors.front();
6838
- exc = cb__map_error_code(resp.ctx,
6839
- fmt::format("unable to create index `{}` on `{}`.`{}` ({}: {})",
6840
- req.index_name,
6841
- req.dataverse_name,
6842
- req.dataset_name,
6843
- first_error.code,
6844
- first_error.message));
6693
+ exc = cb_map_error_code(resp.ctx,
6694
+ fmt::format("unable to create index `{}` on `{}`.`{}` ({}: {})",
6695
+ req.index_name,
6696
+ req.dataverse_name,
6697
+ req.dataset_name,
6698
+ first_error.code,
6699
+ first_error.message));
6845
6700
  }
6846
6701
  break;
6847
6702
  }
@@ -6876,7 +6731,7 @@ cb_Backend_analytics_index_drop(VALUE self,
6876
6731
  VALUE exc = Qnil;
6877
6732
  do {
6878
6733
  couchbase::operations::analytics_index_drop_request req{};
6879
- exc = cb__extract_timeout(req, timeout);
6734
+ exc = cb_extract_timeout(req, timeout);
6880
6735
  if (!NIL_P(exc)) {
6881
6736
  break;
6882
6737
  }
@@ -6892,20 +6747,20 @@ cb_Backend_analytics_index_drop(VALUE self,
6892
6747
  auto f = barrier->get_future();
6893
6748
  backend->cluster->execute_http(
6894
6749
  req, [barrier](couchbase::operations::analytics_index_drop_response&& resp) mutable { barrier->set_value(resp); });
6895
- auto resp = f.get();
6750
+ auto resp = cb_wait_for_future(f);
6896
6751
  if (resp.ctx.ec) {
6897
6752
  if (resp.errors.empty()) {
6898
- exc = cb__map_error_code(
6753
+ exc = cb_map_error_code(
6899
6754
  resp.ctx, fmt::format("unable to drop index `{}`.`{}`.`{}`", req.dataverse_name, req.dataset_name, req.index_name));
6900
6755
  } else {
6901
6756
  const auto& first_error = resp.errors.front();
6902
- exc = cb__map_error_code(resp.ctx,
6903
- fmt::format("unable to drop index `{}`.`{}`.`{}` ({}: {})",
6904
- req.dataverse_name,
6905
- req.dataset_name,
6906
- req.index_name,
6907
- first_error.code,
6908
- first_error.message));
6757
+ exc = cb_map_error_code(resp.ctx,
6758
+ fmt::format("unable to drop index `{}`.`{}`.`{}` ({}: {})",
6759
+ req.dataverse_name,
6760
+ req.dataset_name,
6761
+ req.index_name,
6762
+ first_error.code,
6763
+ first_error.message));
6909
6764
  }
6910
6765
  break;
6911
6766
  }
@@ -6934,7 +6789,7 @@ cb_Backend_analytics_link_connect(VALUE self, VALUE link_name, VALUE force, VALU
6934
6789
  VALUE exc = Qnil;
6935
6790
  do {
6936
6791
  couchbase::operations::analytics_link_connect_request req{};
6937
- exc = cb__extract_timeout(req, timeout);
6792
+ exc = cb_extract_timeout(req, timeout);
6938
6793
  if (!NIL_P(exc)) {
6939
6794
  break;
6940
6795
  }
@@ -6949,18 +6804,18 @@ cb_Backend_analytics_link_connect(VALUE self, VALUE link_name, VALUE force, VALU
6949
6804
  auto f = barrier->get_future();
6950
6805
  backend->cluster->execute_http(
6951
6806
  req, [barrier](couchbase::operations::analytics_link_connect_response&& resp) mutable { barrier->set_value(resp); });
6952
- auto resp = f.get();
6807
+ auto resp = cb_wait_for_future(f);
6953
6808
  if (resp.ctx.ec) {
6954
6809
  if (resp.errors.empty()) {
6955
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to connect link `{}` on `{}`", req.link_name, req.dataverse_name));
6810
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to connect link `{}` on `{}`", req.link_name, req.dataverse_name));
6956
6811
  } else {
6957
6812
  const auto& first_error = resp.errors.front();
6958
- exc = cb__map_error_code(resp.ctx,
6959
- fmt::format("unable to connect link `{}` on `{}` ({}: {})",
6960
- req.link_name,
6961
- req.dataverse_name,
6962
- first_error.code,
6963
- first_error.message));
6813
+ exc = cb_map_error_code(resp.ctx,
6814
+ fmt::format("unable to connect link `{}` on `{}` ({}: {})",
6815
+ req.link_name,
6816
+ req.dataverse_name,
6817
+ first_error.code,
6818
+ first_error.message));
6964
6819
  }
6965
6820
  break;
6966
6821
  }
@@ -6989,7 +6844,7 @@ cb_Backend_analytics_link_disconnect(VALUE self, VALUE link_name, VALUE datavers
6989
6844
  VALUE exc = Qnil;
6990
6845
  do {
6991
6846
  couchbase::operations::analytics_link_disconnect_request req{};
6992
- exc = cb__extract_timeout(req, timeout);
6847
+ exc = cb_extract_timeout(req, timeout);
6993
6848
  if (!NIL_P(exc)) {
6994
6849
  break;
6995
6850
  }
@@ -7001,19 +6856,18 @@ cb_Backend_analytics_link_disconnect(VALUE self, VALUE link_name, VALUE datavers
7001
6856
  auto f = barrier->get_future();
7002
6857
  backend->cluster->execute_http(
7003
6858
  req, [barrier](couchbase::operations::analytics_link_disconnect_response&& resp) mutable { barrier->set_value(resp); });
7004
- auto resp = f.get();
6859
+ auto resp = cb_wait_for_future(f);
7005
6860
  if (resp.ctx.ec) {
7006
6861
  if (resp.errors.empty()) {
7007
- exc =
7008
- cb__map_error_code(resp.ctx, fmt::format("unable to disconnect link `{}` on `{}`", req.link_name, req.dataverse_name));
6862
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to disconnect link `{}` on `{}`", req.link_name, req.dataverse_name));
7009
6863
  } else {
7010
6864
  const auto& first_error = resp.errors.front();
7011
- exc = cb__map_error_code(resp.ctx,
7012
- fmt::format("unable to disconnect link `{}` on `{}` ({}: {})",
7013
- req.link_name,
7014
- req.dataverse_name,
7015
- first_error.code,
7016
- first_error.message));
6865
+ exc = cb_map_error_code(resp.ctx,
6866
+ fmt::format("unable to disconnect link `{}` on `{}` ({}: {})",
6867
+ req.link_name,
6868
+ req.dataverse_name,
6869
+ first_error.code,
6870
+ first_error.message));
7017
6871
  }
7018
6872
  break;
7019
6873
  }
@@ -7024,7 +6878,7 @@ cb_Backend_analytics_link_disconnect(VALUE self, VALUE link_name, VALUE datavers
7024
6878
  }
7025
6879
 
7026
6880
  static int
7027
- cb__for_each_named_param__analytics(VALUE key, VALUE value, VALUE arg)
6881
+ cb_for_each_named_param_analytics(VALUE key, VALUE value, VALUE arg)
7028
6882
  {
7029
6883
  auto* preq = reinterpret_cast<couchbase::operations::analytics_request*>(arg);
7030
6884
  Check_Type(key, T_STRING);
@@ -7058,7 +6912,7 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7058
6912
  Check_Type(client_context_id, T_STRING);
7059
6913
  req.client_context_id.assign(RSTRING_PTR(client_context_id), static_cast<size_t>(RSTRING_LEN(client_context_id)));
7060
6914
  }
7061
- exc = cb__extract_timeout(req, options);
6915
+ exc = cb_extract_timeout(req, options);
7062
6916
  if (!NIL_P(exc)) {
7063
6917
  break;
7064
6918
  }
@@ -7085,7 +6939,7 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7085
6939
  VALUE named_params = rb_hash_aref(options, rb_id2sym(rb_intern("named_parameters")));
7086
6940
  if (!NIL_P(named_params)) {
7087
6941
  Check_Type(named_params, T_HASH);
7088
- rb_hash_foreach(named_params, INT_FUNC(cb__for_each_named_param__analytics), reinterpret_cast<VALUE>(&req));
6942
+ rb_hash_foreach(named_params, INT_FUNC(cb_for_each_named_param_analytics), reinterpret_cast<VALUE>(&req));
7089
6943
  }
7090
6944
  VALUE scan_consistency = rb_hash_aref(options, rb_id2sym(rb_intern("scan_consistency")));
7091
6945
  if (!NIL_P(scan_consistency)) {
@@ -7118,21 +6972,21 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7118
6972
  VALUE raw_params = rb_hash_aref(options, rb_id2sym(rb_intern("raw_parameters")));
7119
6973
  if (!NIL_P(raw_params)) {
7120
6974
  Check_Type(raw_params, T_HASH);
7121
- rb_hash_foreach(raw_params, INT_FUNC(cb__for_each_named_param__analytics), reinterpret_cast<VALUE>(&req));
6975
+ rb_hash_foreach(raw_params, INT_FUNC(cb_for_each_named_param_analytics), reinterpret_cast<VALUE>(&req));
7122
6976
  }
7123
6977
 
7124
6978
  auto barrier = std::make_shared<std::promise<couchbase::operations::analytics_response>>();
7125
6979
  auto f = barrier->get_future();
7126
6980
  backend->cluster->execute_http(req,
7127
6981
  [barrier](couchbase::operations::analytics_response&& resp) mutable { barrier->set_value(resp); });
7128
- auto resp = f.get();
6982
+ auto resp = cb_wait_for_future(f);
7129
6983
  if (resp.ctx.ec) {
7130
6984
  if (resp.payload.meta_data.errors && !resp.payload.meta_data.errors->empty()) {
7131
6985
  const auto& first_error = resp.payload.meta_data.errors->front();
7132
- exc = cb__map_error_code(resp.ctx,
7133
- fmt::format("unable to execute analytics query ({}: {})", first_error.code, first_error.message));
6986
+ exc = cb_map_error_code(resp.ctx,
6987
+ fmt::format("unable to execute analytics query ({}: {})", first_error.code, first_error.message));
7134
6988
  } else {
7135
- exc = cb__map_error_code(resp.ctx, "unable to execute analytics query");
6989
+ exc = cb_map_error_code(resp.ctx, "unable to execute analytics query");
7136
6990
  }
7137
6991
  break;
7138
6992
  }
@@ -7140,43 +6994,25 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7140
6994
  VALUE rows = rb_ary_new_capa(static_cast<long>(resp.payload.rows.size()));
7141
6995
  rb_hash_aset(res, rb_id2sym(rb_intern("rows")), rows);
7142
6996
  for (auto& row : resp.payload.rows) {
7143
- rb_ary_push(rows, rb_external_str_new(row.data(), static_cast<long>(row.size())));
6997
+ rb_ary_push(rows, cb_str_new(row));
7144
6998
  }
7145
6999
  VALUE meta = rb_hash_new();
7146
7000
  rb_hash_aset(res, rb_id2sym(rb_intern("meta")), meta);
7147
7001
  rb_hash_aset(meta,
7148
7002
  rb_id2sym(rb_intern("status")),
7149
7003
  rb_id2sym(rb_intern2(resp.payload.meta_data.status.data(), static_cast<long>(resp.payload.meta_data.status.size()))));
7150
- rb_hash_aset(
7151
- meta,
7152
- rb_id2sym(rb_intern("request_id")),
7153
- rb_external_str_new(resp.payload.meta_data.request_id.data(), static_cast<long>(resp.payload.meta_data.request_id.size())));
7154
- rb_hash_aset(meta,
7155
- rb_id2sym(rb_intern("client_context_id")),
7156
- rb_external_str_new(resp.payload.meta_data.client_context_id.data(),
7157
- static_cast<long>(resp.payload.meta_data.client_context_id.size())));
7004
+ rb_hash_aset(meta, rb_id2sym(rb_intern("request_id")), cb_str_new(resp.payload.meta_data.request_id));
7005
+ rb_hash_aset(meta, rb_id2sym(rb_intern("client_context_id")), cb_str_new(resp.payload.meta_data.client_context_id));
7158
7006
  if (resp.payload.meta_data.signature) {
7159
- rb_hash_aset(
7160
- meta,
7161
- rb_id2sym(rb_intern("signature")),
7162
- rb_external_str_new(resp.payload.meta_data.signature->data(), static_cast<long>(resp.payload.meta_data.signature->size())));
7007
+ rb_hash_aset(meta, rb_id2sym(rb_intern("signature")), cb_str_new(resp.payload.meta_data.signature.value()));
7163
7008
  }
7164
7009
  if (resp.payload.meta_data.profile) {
7165
- rb_hash_aset(
7166
- meta,
7167
- rb_id2sym(rb_intern("profile")),
7168
- rb_external_str_new(resp.payload.meta_data.profile->data(), static_cast<long>(resp.payload.meta_data.profile->size())));
7010
+ rb_hash_aset(meta, rb_id2sym(rb_intern("profile")), cb_str_new(resp.payload.meta_data.profile.value()));
7169
7011
  }
7170
7012
  VALUE metrics = rb_hash_new();
7171
7013
  rb_hash_aset(meta, rb_id2sym(rb_intern("metrics")), metrics);
7172
- rb_hash_aset(metrics,
7173
- rb_id2sym(rb_intern("elapsed_time")),
7174
- rb_external_str_new(resp.payload.meta_data.metrics.elapsed_time.data(),
7175
- static_cast<long>(resp.payload.meta_data.metrics.elapsed_time.size())));
7176
- rb_hash_aset(metrics,
7177
- rb_id2sym(rb_intern("execution_time")),
7178
- rb_external_str_new(resp.payload.meta_data.metrics.execution_time.data(),
7179
- static_cast<long>(resp.payload.meta_data.metrics.execution_time.size())));
7014
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("elapsed_time")), cb_str_new(resp.payload.meta_data.metrics.elapsed_time));
7015
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("execution_time")), cb_str_new(resp.payload.meta_data.metrics.execution_time));
7180
7016
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_count")), ULL2NUM(resp.payload.meta_data.metrics.result_count));
7181
7017
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_size")), ULL2NUM(resp.payload.meta_data.metrics.result_count));
7182
7018
  if (resp.payload.meta_data.metrics.sort_count) {
@@ -7209,16 +7045,14 @@ cb_Backend_parse_connection_string(VALUE self, VALUE connection_string)
7209
7045
 
7210
7046
  VALUE res = rb_hash_new();
7211
7047
  if (!connstr.scheme.empty()) {
7212
- rb_hash_aset(
7213
- res, rb_id2sym(rb_intern("scheme")), rb_external_str_new(connstr.scheme.data(), static_cast<long>(connstr.scheme.size())));
7048
+ rb_hash_aset(res, rb_id2sym(rb_intern("scheme")), cb_str_new(connstr.scheme));
7214
7049
  rb_hash_aset(res, rb_id2sym(rb_intern("tls")), connstr.tls ? Qtrue : Qfalse);
7215
7050
  }
7216
7051
 
7217
7052
  VALUE nodes = rb_ary_new_capa(static_cast<long>(connstr.bootstrap_nodes.size()));
7218
7053
  for (const auto& entry : connstr.bootstrap_nodes) {
7219
7054
  VALUE node = rb_hash_new();
7220
- rb_hash_aset(
7221
- node, rb_id2sym(rb_intern("address")), rb_external_str_new(entry.address.data(), static_cast<long>(entry.address.size())));
7055
+ rb_hash_aset(node, rb_id2sym(rb_intern("address")), cb_str_new(entry.address));
7222
7056
  if (entry.port > 0) {
7223
7057
  rb_hash_aset(node, rb_id2sym(rb_intern("port")), UINT2NUM(entry.port));
7224
7058
  }
@@ -7249,16 +7083,12 @@ cb_Backend_parse_connection_string(VALUE self, VALUE connection_string)
7249
7083
 
7250
7084
  VALUE params = rb_hash_new();
7251
7085
  for (const auto& param : connstr.params) {
7252
- rb_hash_aset(params,
7253
- rb_external_str_new(param.first.data(), static_cast<long>(param.first.size())),
7254
- rb_external_str_new(param.second.data(), static_cast<long>(param.second.size())));
7086
+ rb_hash_aset(params, cb_str_new(param.first), cb_str_new(param.second));
7255
7087
  }
7256
7088
  rb_hash_aset(res, rb_id2sym(rb_intern("params")), params);
7257
7089
 
7258
7090
  if (connstr.default_bucket_name) {
7259
- rb_hash_aset(res,
7260
- rb_id2sym(rb_intern("default_bucket_name")),
7261
- rb_external_str_new(connstr.default_bucket_name->data(), static_cast<long>(connstr.default_bucket_name->size())));
7091
+ rb_hash_aset(res, rb_id2sym(rb_intern("default_bucket_name")), cb_str_new(connstr.default_bucket_name.value()));
7262
7092
  }
7263
7093
  if (connstr.default_port > 0) {
7264
7094
  rb_hash_aset(res, rb_id2sym(rb_intern("default_port")), UINT2NUM(connstr.default_port));
@@ -7274,8 +7104,7 @@ cb_Backend_parse_connection_string(VALUE self, VALUE connection_string)
7274
7104
  break;
7275
7105
  }
7276
7106
  if (connstr.error) {
7277
- rb_hash_aset(
7278
- res, rb_id2sym(rb_intern("error")), rb_external_str_new(connstr.error->data(), static_cast<long>(connstr.error->size())));
7107
+ rb_hash_aset(res, rb_id2sym(rb_intern("error")), cb_str_new(connstr.error.value()));
7279
7108
  }
7280
7109
  return res;
7281
7110
  }
@@ -7310,7 +7139,7 @@ cb_Backend_view_index_get_all(VALUE self, VALUE bucket_name, VALUE name_space, V
7310
7139
  couchbase::operations::view_index_get_all_request req{};
7311
7140
  req.bucket_name.assign(RSTRING_PTR(bucket_name), static_cast<size_t>(RSTRING_LEN(bucket_name)));
7312
7141
  req.name_space = ns;
7313
- exc = cb__extract_timeout(req, timeout);
7142
+ exc = cb_extract_timeout(req, timeout);
7314
7143
  if (!NIL_P(exc)) {
7315
7144
  break;
7316
7145
  }
@@ -7318,16 +7147,16 @@ cb_Backend_view_index_get_all(VALUE self, VALUE bucket_name, VALUE name_space, V
7318
7147
  auto f = barrier->get_future();
7319
7148
  backend->cluster->execute_http(
7320
7149
  req, [barrier](couchbase::operations::view_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
7321
- auto resp = f.get();
7150
+ auto resp = cb_wait_for_future(f);
7322
7151
  if (resp.ctx.ec) {
7323
- exc = cb__map_error_code(resp.ctx, "unable to get list of the design documents");
7152
+ exc = cb_map_error_code(resp.ctx, "unable to get list of the design documents");
7324
7153
  break;
7325
7154
  }
7326
7155
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.design_documents.size()));
7327
7156
  for (const auto& entry : resp.design_documents) {
7328
7157
  VALUE dd = rb_hash_new();
7329
- rb_hash_aset(dd, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
7330
- rb_hash_aset(dd, rb_id2sym(rb_intern("rev")), rb_external_str_new(entry.rev.data(), static_cast<long>(entry.rev.size())));
7158
+ rb_hash_aset(dd, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
7159
+ rb_hash_aset(dd, rb_id2sym(rb_intern("rev")), cb_str_new(entry.rev));
7331
7160
  switch (entry.ns) {
7332
7161
  case couchbase::operations::design_document::name_space::development:
7333
7162
  rb_hash_aset(dd, rb_id2sym(rb_intern("namespace")), rb_id2sym(rb_intern("development")));
@@ -7338,19 +7167,14 @@ cb_Backend_view_index_get_all(VALUE self, VALUE bucket_name, VALUE name_space, V
7338
7167
  }
7339
7168
  VALUE views = rb_hash_new();
7340
7169
  for (const auto& view_entry : entry.views) {
7341
- VALUE view_name = rb_external_str_new(view_entry.first.data(), static_cast<long>(view_entry.first.size()));
7170
+ VALUE view_name = cb_str_new(view_entry.first);
7342
7171
  VALUE view = rb_hash_new();
7343
7172
  rb_hash_aset(view, rb_id2sym(rb_intern("name")), view_name);
7344
7173
  if (view_entry.second.map) {
7345
- rb_hash_aset(view,
7346
- rb_id2sym(rb_intern("map")),
7347
- rb_external_str_new(view_entry.second.map->data(), static_cast<long>(view_entry.second.map->size())));
7174
+ rb_hash_aset(view, rb_id2sym(rb_intern("map")), cb_str_new(view_entry.second.map.value()));
7348
7175
  }
7349
7176
  if (view_entry.second.reduce) {
7350
- rb_hash_aset(
7351
- view,
7352
- rb_id2sym(rb_intern("reduce")),
7353
- rb_external_str_new(view_entry.second.reduce->data(), static_cast<long>(view_entry.second.reduce->size())));
7177
+ rb_hash_aset(view, rb_id2sym(rb_intern("reduce")), cb_str_new(view_entry.second.reduce.value()));
7354
7178
  }
7355
7179
  rb_hash_aset(views, view_name, view);
7356
7180
  }
@@ -7395,7 +7219,7 @@ cb_Backend_view_index_get(VALUE self, VALUE bucket_name, VALUE document_name, VA
7395
7219
  req.bucket_name.assign(RSTRING_PTR(bucket_name), static_cast<size_t>(RSTRING_LEN(bucket_name)));
7396
7220
  req.document_name.assign(RSTRING_PTR(document_name), static_cast<size_t>(RSTRING_LEN(document_name)));
7397
7221
  req.name_space = ns;
7398
- exc = cb__extract_timeout(req, timeout);
7222
+ exc = cb_extract_timeout(req, timeout);
7399
7223
  if (!NIL_P(exc)) {
7400
7224
  break;
7401
7225
  }
@@ -7403,18 +7227,16 @@ cb_Backend_view_index_get(VALUE self, VALUE bucket_name, VALUE document_name, VA
7403
7227
  auto f = barrier->get_future();
7404
7228
  backend->cluster->execute_http(
7405
7229
  req, [barrier](couchbase::operations::view_index_get_response&& resp) mutable { barrier->set_value(resp); });
7406
- auto resp = f.get();
7230
+ auto resp = cb_wait_for_future(f);
7407
7231
  if (resp.ctx.ec) {
7408
- exc = cb__map_error_code(
7232
+ exc = cb_map_error_code(
7409
7233
  resp.ctx,
7410
7234
  fmt::format(R"(unable to get design document "{}" ({}) on bucket "{}")", req.document_name, req.name_space, req.bucket_name));
7411
7235
  break;
7412
7236
  }
7413
7237
  VALUE res = rb_hash_new();
7414
- rb_hash_aset(
7415
- res, rb_id2sym(rb_intern("name")), rb_external_str_new(resp.document.name.data(), static_cast<long>(resp.document.name.size())));
7416
- rb_hash_aset(
7417
- res, rb_id2sym(rb_intern("rev")), rb_external_str_new(resp.document.rev.data(), static_cast<long>(resp.document.rev.size())));
7238
+ rb_hash_aset(res, rb_id2sym(rb_intern("name")), cb_str_new(resp.document.name));
7239
+ rb_hash_aset(res, rb_id2sym(rb_intern("rev")), cb_str_new(resp.document.rev));
7418
7240
  switch (resp.document.ns) {
7419
7241
  case couchbase::operations::design_document::name_space::development:
7420
7242
  rb_hash_aset(res, rb_id2sym(rb_intern("namespace")), rb_id2sym(rb_intern("development")));
@@ -7425,18 +7247,14 @@ cb_Backend_view_index_get(VALUE self, VALUE bucket_name, VALUE document_name, VA
7425
7247
  }
7426
7248
  VALUE views = rb_hash_new();
7427
7249
  for (const auto& view_entry : resp.document.views) {
7428
- VALUE view_name = rb_external_str_new(view_entry.first.data(), static_cast<long>(view_entry.first.size()));
7250
+ VALUE view_name = cb_str_new(view_entry.first);
7429
7251
  VALUE view = rb_hash_new();
7430
7252
  rb_hash_aset(view, rb_id2sym(rb_intern("name")), view_name);
7431
7253
  if (view_entry.second.map) {
7432
- rb_hash_aset(view,
7433
- rb_id2sym(rb_intern("map")),
7434
- rb_external_str_new(view_entry.second.map->data(), static_cast<long>(view_entry.second.map->size())));
7254
+ rb_hash_aset(view, rb_id2sym(rb_intern("map")), cb_str_new(view_entry.second.map.value()));
7435
7255
  }
7436
7256
  if (view_entry.second.reduce) {
7437
- rb_hash_aset(view,
7438
- rb_id2sym(rb_intern("reduce")),
7439
- rb_external_str_new(view_entry.second.reduce->data(), static_cast<long>(view_entry.second.reduce->size())));
7257
+ rb_hash_aset(view, rb_id2sym(rb_intern("reduce")), cb_str_new(view_entry.second.reduce.value()));
7440
7258
  }
7441
7259
  rb_hash_aset(views, view_name, view);
7442
7260
  }
@@ -7479,7 +7297,7 @@ cb_Backend_view_index_drop(VALUE self, VALUE bucket_name, VALUE document_name, V
7479
7297
  req.bucket_name.assign(RSTRING_PTR(bucket_name), static_cast<size_t>(RSTRING_LEN(bucket_name)));
7480
7298
  req.document_name.assign(RSTRING_PTR(document_name), static_cast<size_t>(RSTRING_LEN(document_name)));
7481
7299
  req.name_space = ns;
7482
- exc = cb__extract_timeout(req, timeout);
7300
+ exc = cb_extract_timeout(req, timeout);
7483
7301
  if (!NIL_P(exc)) {
7484
7302
  break;
7485
7303
  }
@@ -7487,9 +7305,9 @@ cb_Backend_view_index_drop(VALUE self, VALUE bucket_name, VALUE document_name, V
7487
7305
  auto f = barrier->get_future();
7488
7306
  backend->cluster->execute_http(
7489
7307
  req, [barrier](couchbase::operations::view_index_drop_response&& resp) mutable { barrier->set_value(resp); });
7490
- auto resp = f.get();
7308
+ auto resp = cb_wait_for_future(f);
7491
7309
  if (resp.ctx.ec) {
7492
- exc = cb__map_error_code(
7310
+ exc = cb_map_error_code(
7493
7311
  resp.ctx,
7494
7312
  fmt::format(
7495
7313
  R"(unable to drop design document "{}" ({}) on bucket "{}")", req.document_name, req.name_space, req.bucket_name));
@@ -7560,7 +7378,7 @@ cb_Backend_view_index_upsert(VALUE self, VALUE bucket_name, VALUE document, VALU
7560
7378
  }
7561
7379
  }
7562
7380
 
7563
- exc = cb__extract_timeout(req, timeout);
7381
+ exc = cb_extract_timeout(req, timeout);
7564
7382
  if (!NIL_P(exc)) {
7565
7383
  break;
7566
7384
  }
@@ -7568,9 +7386,9 @@ cb_Backend_view_index_upsert(VALUE self, VALUE bucket_name, VALUE document, VALU
7568
7386
  auto f = barrier->get_future();
7569
7387
  backend->cluster->execute_http(
7570
7388
  req, [barrier](couchbase::operations::view_index_upsert_response&& resp) mutable { barrier->set_value(resp); });
7571
- auto resp = f.get();
7389
+ auto resp = cb_wait_for_future(f);
7572
7390
  if (resp.ctx.ec) {
7573
- exc = cb__map_error_code(
7391
+ exc = cb_map_error_code(
7574
7392
  resp.ctx,
7575
7393
  fmt::format(
7576
7394
  R"(unable to store design document "{}" ({}) on bucket "{}")", req.document.name, req.document.ns, req.bucket_name));
@@ -7618,7 +7436,7 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7618
7436
  req.document_name.assign(RSTRING_PTR(design_document_name), static_cast<size_t>(RSTRING_LEN(design_document_name)));
7619
7437
  req.view_name.assign(RSTRING_PTR(view_name), static_cast<size_t>(RSTRING_LEN(view_name)));
7620
7438
  req.name_space = ns;
7621
- exc = cb__extract_timeout(req, options);
7439
+ exc = cb_extract_timeout(req, options);
7622
7440
  if (!NIL_P(exc)) {
7623
7441
  break;
7624
7442
  }
@@ -7718,13 +7536,13 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7718
7536
  auto f = barrier->get_future();
7719
7537
  backend->cluster->execute_http(
7720
7538
  req, [barrier](couchbase::operations::document_view_response&& resp) mutable { barrier->set_value(resp); });
7721
- auto resp = f.get();
7539
+ auto resp = cb_wait_for_future(f);
7722
7540
  if (resp.ctx.ec) {
7723
7541
  if (resp.error) {
7724
- exc = cb__map_error_code(resp.ctx,
7725
- fmt::format(R"(unable to execute view query {} ({}))", resp.error->code, resp.error->message));
7542
+ exc = cb_map_error_code(resp.ctx,
7543
+ fmt::format(R"(unable to execute view query {} ({}))", resp.error->code, resp.error->message));
7726
7544
  } else {
7727
- exc = cb__map_error_code(resp.ctx, "unable to execute view query");
7545
+ exc = cb_map_error_code(resp.ctx, "unable to execute view query");
7728
7546
  }
7729
7547
  break;
7730
7548
  }
@@ -7735,9 +7553,7 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7735
7553
  rb_hash_aset(meta, rb_id2sym(rb_intern("total_rows")), ULL2NUM(*resp.meta_data.total_rows));
7736
7554
  }
7737
7555
  if (resp.meta_data.debug_info) {
7738
- rb_hash_aset(meta,
7739
- rb_id2sym(rb_intern("debug_info")),
7740
- rb_external_str_new(resp.meta_data.debug_info->data(), static_cast<long>(resp.meta_data.debug_info->size())));
7556
+ rb_hash_aset(meta, rb_id2sym(rb_intern("debug_info")), cb_str_new(resp.meta_data.debug_info.value()));
7741
7557
  }
7742
7558
  rb_hash_aset(res, rb_id2sym(rb_intern("meta")), meta);
7743
7559
 
@@ -7745,11 +7561,10 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7745
7561
  for (const auto& entry : resp.rows) {
7746
7562
  VALUE row = rb_hash_new();
7747
7563
  if (entry.id) {
7748
- rb_hash_aset(row, rb_id2sym(rb_intern("id")), rb_external_str_new(entry.id->data(), static_cast<long>(entry.id->size())));
7564
+ rb_hash_aset(row, rb_id2sym(rb_intern("id")), cb_str_new(entry.id.value()));
7749
7565
  }
7750
- rb_hash_aset(row, rb_id2sym(rb_intern("key")), rb_external_str_new(entry.key.data(), static_cast<long>(entry.key.size())));
7751
- rb_hash_aset(
7752
- row, rb_id2sym(rb_intern("value")), rb_external_str_new(entry.value.data(), static_cast<long>(entry.value.size())));
7566
+ rb_hash_aset(row, rb_id2sym(rb_intern("key")), cb_str_new(entry.key));
7567
+ rb_hash_aset(row, rb_id2sym(rb_intern("value")), cb_str_new(entry.value));
7753
7568
  rb_ary_push(rows, row);
7754
7569
  }
7755
7570
  rb_hash_aset(res, rb_id2sym(rb_intern("rows")), rows);
@@ -7820,6 +7635,7 @@ cb_Backend_snappy_compress(VALUE self, VALUE data)
7820
7635
 
7821
7636
  std::string compressed{};
7822
7637
  std::size_t compressed_size = snappy::Compress(RSTRING_PTR(data), static_cast<std::size_t>(RSTRING_LEN(data)), &compressed);
7638
+
7823
7639
  return rb_external_str_new(compressed.data(), static_cast<long>(compressed_size));
7824
7640
  }
7825
7641
 
@@ -7832,7 +7648,7 @@ cb_Backend_snappy_uncompress(VALUE self, VALUE data)
7832
7648
  std::string uncompressed{};
7833
7649
  bool success = snappy::Uncompress(RSTRING_PTR(data), static_cast<std::size_t>(RSTRING_LEN(data)), &uncompressed);
7834
7650
  if (success) {
7835
- return rb_external_str_new(uncompressed.data(), static_cast<long>(uncompressed.size()));
7651
+ return cb_str_new(uncompressed);
7836
7652
  }
7837
7653
  rb_raise(rb_eArgError, "Unable to decompress buffer");
7838
7654
  return Qnil;
@@ -7851,7 +7667,7 @@ cb_Backend_leb128_encode(VALUE self, VALUE number)
7851
7667
  }
7852
7668
  couchbase::protocol::unsigned_leb128<std::uint64_t> encoded(NUM2ULL(number));
7853
7669
  std::string buf = encoded.get();
7854
- return rb_external_str_new(buf.data(), static_cast<long>(buf.size()));
7670
+ return cb_str_new(buf);
7855
7671
  }
7856
7672
 
7857
7673
  static VALUE