couchbase_core/
agent_ops.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use crate::agent::Agent;
20use crate::cbconfig::CollectionManifest;
21use crate::error::Result;
22use crate::features::BucketFeature;
23use crate::mgmtx::bucket_settings::BucketDef;
24use crate::mgmtx::responses::{
25    CreateCollectionResponse, CreateScopeResponse, DeleteCollectionResponse, DeleteScopeResponse,
26    UpdateCollectionResponse,
27};
28use crate::mgmtx::user::{Group, RoleAndDescription, UserAndMetadata};
29use crate::options::crud::{
30    AddOptions, AppendOptions, DecrementOptions, DeleteOptions, GetAndLockOptions,
31    GetAndTouchOptions, GetCollectionIdOptions, GetMetaOptions, GetOptions, IncrementOptions,
32    LookupInOptions, MutateInOptions, PrependOptions, ReplaceOptions, TouchOptions, UnlockOptions,
33    UpsertOptions,
34};
35use crate::options::diagnostics::DiagnosticsOptions;
36use crate::options::management::{
37    ChangePasswordOptions, CreateBucketOptions, CreateCollectionOptions, CreateScopeOptions,
38    DeleteBucketOptions, DeleteCollectionOptions, DeleteGroupOptions, DeleteScopeOptions,
39    DeleteUserOptions, EnsureBucketOptions, EnsureGroupOptions, EnsureManifestOptions,
40    EnsureUserOptions, FlushBucketOptions, GetAllBucketsOptions, GetAllGroupsOptions,
41    GetAllUsersOptions, GetBucketOptions, GetCollectionManifestOptions, GetGroupOptions,
42    GetRolesOptions, GetUserOptions, UpdateBucketOptions, UpdateCollectionOptions,
43    UpsertGroupOptions, UpsertUserOptions,
44};
45use crate::options::ping::PingOptions;
46use crate::options::query::{
47    BuildDeferredIndexesOptions, CreateIndexOptions, CreatePrimaryIndexOptions, DropIndexOptions,
48    DropPrimaryIndexOptions, EnsureIndexOptions, GetAllIndexesOptions, QueryOptions,
49    WatchIndexesOptions,
50};
51use crate::options::search::SearchOptions;
52use crate::options::search_management;
53use crate::options::search_management::{
54    AllowQueryingOptions, AnalyzeDocumentOptions, DeleteIndexOptions, DisallowQueryingOptions,
55    FreezePlanOptions, GetIndexOptions, GetIndexedDocumentsCountOptions, PauseIngestOptions,
56    ResumeIngestOptions, UnfreezePlanOptions, UpsertIndexOptions,
57};
58use crate::options::waituntilready::WaitUntilReadyOptions;
59use crate::queryx::index::Index;
60use crate::results::diagnostics::DiagnosticsResult;
61use crate::results::kv::{
62    AddResult, AppendResult, DecrementResult, DeleteResult, GetAndLockResult, GetAndTouchResult,
63    GetCollectionIdResult, GetMetaResult, GetResult, IncrementResult, LookupInResult,
64    MutateInResult, PrependResult, ReplaceResult, TouchResult, UnlockResult, UpsertResult,
65};
66use crate::results::pingreport::PingReport;
67use crate::results::query::QueryResultStream;
68use crate::results::search::SearchResultStream;
69use crate::searchx;
70use crate::searchx::document_analysis::DocumentAnalysis;
71
72impl Agent {
73    pub async fn bucket_features(&self) -> Result<Vec<BucketFeature>> {
74        self.inner.bucket_features().await
75    }
76
77    pub async fn upsert(&self, opts: UpsertOptions<'_>) -> Result<UpsertResult> {
78        self.inner.crud.upsert(opts).await
79    }
80
81    pub async fn get(&self, opts: GetOptions<'_>) -> Result<GetResult> {
82        self.inner.crud.get(opts).await
83    }
84
85    pub async fn get_meta(&self, opts: GetMetaOptions<'_>) -> Result<GetMetaResult> {
86        self.inner.crud.get_meta(opts).await
87    }
88
89    pub async fn delete(&self, opts: DeleteOptions<'_>) -> Result<DeleteResult> {
90        self.inner.crud.delete(opts).await
91    }
92
93    pub async fn get_and_lock(&self, opts: GetAndLockOptions<'_>) -> Result<GetAndLockResult> {
94        self.inner.crud.get_and_lock(opts).await
95    }
96
97    pub async fn get_and_touch(&self, opts: GetAndTouchOptions<'_>) -> Result<GetAndTouchResult> {
98        self.inner.crud.get_and_touch(opts).await
99    }
100
101    pub async fn unlock(&self, opts: UnlockOptions<'_>) -> Result<UnlockResult> {
102        self.inner.crud.unlock(opts).await
103    }
104
105    pub async fn touch(&self, opts: TouchOptions<'_>) -> Result<TouchResult> {
106        self.inner.crud.touch(opts).await
107    }
108
109    pub async fn add(&self, opts: AddOptions<'_>) -> Result<AddResult> {
110        self.inner.crud.add(opts).await
111    }
112
113    pub async fn replace(&self, opts: ReplaceOptions<'_>) -> Result<ReplaceResult> {
114        self.inner.crud.replace(opts).await
115    }
116
117    pub async fn append(&self, opts: AppendOptions<'_>) -> Result<AppendResult> {
118        self.inner.crud.append(opts).await
119    }
120
121    pub async fn prepend(&self, opts: PrependOptions<'_>) -> Result<PrependResult> {
122        self.inner.crud.prepend(opts).await
123    }
124
125    pub async fn increment(&self, opts: IncrementOptions<'_>) -> Result<IncrementResult> {
126        self.inner.crud.increment(opts).await
127    }
128
129    pub async fn decrement(&self, opts: DecrementOptions<'_>) -> Result<DecrementResult> {
130        self.inner.crud.decrement(opts).await
131    }
132
133    pub async fn get_collection_id(
134        &self,
135        opts: GetCollectionIdOptions<'_>,
136    ) -> Result<GetCollectionIdResult> {
137        self.inner.crud.get_collection_id(opts).await
138    }
139
140    pub async fn lookup_in(&self, opts: LookupInOptions<'_>) -> Result<LookupInResult> {
141        self.inner.crud.lookup_in(opts).await
142    }
143
144    pub async fn mutate_in(&self, opts: MutateInOptions<'_>) -> Result<MutateInResult> {
145        self.inner.crud.mutate_in(opts).await
146    }
147
148    pub async fn query(&self, opts: QueryOptions) -> Result<QueryResultStream> {
149        self.inner.query.query(opts).await
150    }
151
152    pub async fn prepared_query(&self, opts: QueryOptions) -> Result<QueryResultStream> {
153        self.inner.query.prepared_query(opts).await
154    }
155
156    pub async fn get_all_indexes(&self, opts: &GetAllIndexesOptions<'_>) -> Result<Vec<Index>> {
157        self.inner.query.get_all_indexes(opts).await
158    }
159
160    pub async fn create_primary_index(&self, opts: &CreatePrimaryIndexOptions<'_>) -> Result<()> {
161        self.inner.query.create_primary_index(opts).await
162    }
163
164    pub async fn create_index(&self, opts: &CreateIndexOptions<'_>) -> Result<()> {
165        self.inner.query.create_index(opts).await
166    }
167
168    pub async fn drop_primary_index(&self, opts: &DropPrimaryIndexOptions<'_>) -> Result<()> {
169        self.inner.query.drop_primary_index(opts).await
170    }
171
172    pub async fn drop_index(&self, opts: &DropIndexOptions<'_>) -> Result<()> {
173        self.inner.query.drop_index(opts).await
174    }
175
176    pub async fn build_deferred_indexes(
177        &self,
178        opts: &BuildDeferredIndexesOptions<'_>,
179    ) -> Result<()> {
180        self.inner.query.build_deferred_indexes(opts).await
181    }
182
183    pub async fn watch_indexes(&self, opts: &WatchIndexesOptions<'_>) -> Result<()> {
184        self.inner.query.watch_indexes(opts).await
185    }
186
187    pub async fn ensure_index(&self, opts: &EnsureIndexOptions<'_>) -> Result<()> {
188        self.inner.query.ensure_index(opts).await
189    }
190
191    pub async fn search(&self, opts: SearchOptions) -> Result<SearchResultStream> {
192        self.inner.search.query(opts).await
193    }
194
195    pub async fn get_search_index(
196        &self,
197        opts: &GetIndexOptions<'_>,
198    ) -> Result<searchx::index::Index> {
199        self.inner.search.get_index(opts).await
200    }
201
202    pub async fn upsert_search_index(&self, opts: &UpsertIndexOptions<'_>) -> Result<()> {
203        self.inner.search.upsert_index(opts).await
204    }
205
206    pub async fn delete_search_index(&self, opts: &DeleteIndexOptions<'_>) -> Result<()> {
207        self.inner.search.delete_index(opts).await
208    }
209
210    pub async fn get_all_search_indexes(
211        &self,
212        opts: &search_management::GetAllIndexesOptions<'_>,
213    ) -> Result<Vec<searchx::index::Index>> {
214        self.inner.search.get_all_indexes(opts).await
215    }
216
217    pub async fn analyze_search_document(
218        &self,
219        opts: &AnalyzeDocumentOptions<'_>,
220    ) -> Result<DocumentAnalysis> {
221        self.inner.search.analyze_document(opts).await
222    }
223
224    pub async fn get_search_indexed_documents_count(
225        &self,
226        opts: &GetIndexedDocumentsCountOptions<'_>,
227    ) -> Result<u64> {
228        self.inner.search.get_indexed_documents_count(opts).await
229    }
230
231    pub async fn pause_search_index_ingest(&self, opts: &PauseIngestOptions<'_>) -> Result<()> {
232        self.inner.search.pause_ingest(opts).await
233    }
234
235    pub async fn resume_search_index_ingest(&self, opts: &ResumeIngestOptions<'_>) -> Result<()> {
236        self.inner.search.resume_ingest(opts).await
237    }
238
239    pub async fn allow_search_index_querying(&self, opts: &AllowQueryingOptions<'_>) -> Result<()> {
240        self.inner.search.allow_querying(opts).await
241    }
242
243    pub async fn disallow_search_index_querying(
244        &self,
245        opts: &DisallowQueryingOptions<'_>,
246    ) -> Result<()> {
247        self.inner.search.disallow_querying(opts).await
248    }
249
250    pub async fn freeze_search_index_plan(&self, opts: &FreezePlanOptions<'_>) -> Result<()> {
251        self.inner.search.freeze_plan(opts).await
252    }
253
254    pub async fn unfreeze_search_index_plan(&self, opts: &UnfreezePlanOptions<'_>) -> Result<()> {
255        self.inner.search.unfreeze_plan(opts).await
256    }
257
258    pub async fn get_collection_manifest(
259        &self,
260        opts: &GetCollectionManifestOptions<'_>,
261    ) -> Result<CollectionManifest> {
262        self.inner.mgmt.get_collection_manifest(opts).await
263    }
264
265    pub async fn create_scope(&self, opts: &CreateScopeOptions<'_>) -> Result<CreateScopeResponse> {
266        self.inner.mgmt.create_scope(opts).await
267    }
268
269    pub async fn delete_scope(&self, opts: &DeleteScopeOptions<'_>) -> Result<DeleteScopeResponse> {
270        self.inner.mgmt.delete_scope(opts).await
271    }
272
273    pub async fn create_collection(
274        &self,
275        opts: &CreateCollectionOptions<'_>,
276    ) -> Result<CreateCollectionResponse> {
277        if opts.history_enabled.is_some() {
278            return self.run_with_bucket_feature_check(
279                BucketFeature::NonDedupedHistory,
280                || async {
281                    self.inner.mgmt.create_collection(opts).await
282                },
283                "History retention is not supported - note that the Magma storage engine must be used",
284            ).await;
285        }
286
287        self.inner.mgmt.create_collection(opts).await
288    }
289
290    pub async fn delete_collection(
291        &self,
292        opts: &DeleteCollectionOptions<'_>,
293    ) -> Result<DeleteCollectionResponse> {
294        self.inner.mgmt.delete_collection(opts).await
295    }
296
297    pub async fn update_collection(
298        &self,
299        opts: &UpdateCollectionOptions<'_>,
300    ) -> Result<UpdateCollectionResponse> {
301        if opts.history_enabled.is_some() {
302            return self.run_with_bucket_feature_check(
303                BucketFeature::NonDedupedHistory,
304                || async {
305                    self.inner.mgmt.update_collection(opts).await
306                },
307                "History retention is not supported - note that the Magma storage engine must be used",
308            )
309                .await;
310        }
311        self.inner.mgmt.update_collection(opts).await
312    }
313
314    pub async fn ensure_manifest(&self, opts: &EnsureManifestOptions<'_>) -> Result<()> {
315        self.inner.mgmt.ensure_manifest(opts).await
316    }
317
318    pub async fn get_all_buckets(&self, opts: &GetAllBucketsOptions<'_>) -> Result<Vec<BucketDef>> {
319        self.inner.mgmt.get_all_buckets(opts).await
320    }
321
322    pub async fn get_bucket(&self, opts: &GetBucketOptions<'_>) -> Result<BucketDef> {
323        self.inner.mgmt.get_bucket(opts).await
324    }
325
326    pub async fn create_bucket(&self, opts: &CreateBucketOptions<'_>) -> Result<()> {
327        self.inner.mgmt.create_bucket(opts).await
328    }
329
330    pub async fn update_bucket(&self, opts: &UpdateBucketOptions<'_>) -> Result<()> {
331        self.inner.mgmt.update_bucket(opts).await
332    }
333
334    pub async fn delete_bucket(&self, opts: &DeleteBucketOptions<'_>) -> Result<()> {
335        self.inner.mgmt.delete_bucket(opts).await
336    }
337
338    pub async fn flush_bucket(&self, opts: &FlushBucketOptions<'_>) -> Result<()> {
339        self.inner.mgmt.flush_bucket(opts).await
340    }
341
342    pub async fn get_user(&self, opts: &GetUserOptions<'_>) -> Result<UserAndMetadata> {
343        self.inner.mgmt.get_user(opts).await
344    }
345
346    pub async fn get_all_users(
347        &self,
348        opts: &GetAllUsersOptions<'_>,
349    ) -> Result<Vec<UserAndMetadata>> {
350        self.inner.mgmt.get_all_users(opts).await
351    }
352
353    pub async fn upsert_user(&self, opts: &UpsertUserOptions<'_>) -> Result<()> {
354        self.inner.mgmt.upsert_user(opts).await
355    }
356
357    pub async fn delete_user(&self, opts: &DeleteUserOptions<'_>) -> Result<()> {
358        self.inner.mgmt.delete_user(opts).await
359    }
360
361    pub async fn get_roles(&self, opts: &GetRolesOptions<'_>) -> Result<Vec<RoleAndDescription>> {
362        self.inner.mgmt.get_roles(opts).await
363    }
364
365    pub async fn get_group(&self, opts: &GetGroupOptions<'_>) -> Result<Group> {
366        self.inner.mgmt.get_group(opts).await
367    }
368
369    pub async fn get_all_groups(&self, opts: &GetAllGroupsOptions<'_>) -> Result<Vec<Group>> {
370        self.inner.mgmt.get_all_groups(opts).await
371    }
372
373    pub async fn upsert_group(&self, opts: &UpsertGroupOptions<'_>) -> Result<()> {
374        self.inner.mgmt.upsert_group(opts).await
375    }
376
377    pub async fn delete_group(&self, opts: &DeleteGroupOptions<'_>) -> Result<()> {
378        self.inner.mgmt.delete_group(opts).await
379    }
380
381    pub async fn change_password(&self, opts: &ChangePasswordOptions<'_>) -> Result<()> {
382        self.inner.mgmt.change_password(opts).await
383    }
384
385    pub async fn ping(&self, opts: &PingOptions) -> Result<PingReport> {
386        self.inner.diagnostics.ping(opts).await
387    }
388
389    pub async fn ensure_user(&self, opts: &EnsureUserOptions<'_>) -> Result<()> {
390        self.inner.mgmt.ensure_user(opts).await
391    }
392
393    pub async fn ensure_group(&self, opts: &EnsureGroupOptions<'_>) -> Result<()> {
394        self.inner.mgmt.ensure_group(opts).await
395    }
396
397    pub async fn ensure_bucket(&self, opts: &EnsureBucketOptions<'_>) -> Result<()> {
398        self.inner.mgmt.ensure_bucket(opts).await
399    }
400
401    pub async fn ensure_search_index(
402        &self,
403        opts: &search_management::EnsureIndexOptions<'_>,
404    ) -> Result<()> {
405        self.inner.search.ensure_index(opts).await
406    }
407
408    pub async fn wait_until_ready(&self, opts: &WaitUntilReadyOptions) -> Result<()> {
409        self.inner.diagnostics.wait_until_ready(opts).await
410    }
411
412    pub async fn diagnostics(&self, opts: &DiagnosticsOptions) -> Result<DiagnosticsResult> {
413        self.inner.diagnostics.diagnostics(opts).await
414    }
415}