@@ -10,8 +10,9 @@ use crate::{
10
10
ItemOptions , PartitionKey , Query , QueryPartitionStrategy ,
11
11
} ;
12
12
13
- use azure_core:: { Context , Request , Response } ;
14
- use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
13
+ use azure_core:: { Context , Pager , Request , Response } ;
14
+ use serde:: { de:: DeserializeOwned , Serialize } ;
15
+ use typespec_client_core:: http:: PagerResult ;
15
16
use url:: Url ;
16
17
17
18
#[ cfg( doc) ]
@@ -44,13 +45,13 @@ pub trait ContainerClientMethods {
44
45
async fn read (
45
46
& self ,
46
47
options : Option < ReadContainerOptions > ,
47
- ) -> azure_core:: Result < azure_core :: Response < ContainerProperties > > ;
48
+ ) -> azure_core:: Result < Response < ContainerProperties > > ;
48
49
49
50
/// Creates a new item in the container.
50
51
///
51
52
/// # Arguments
52
53
/// * `partition_key` - The partition key of the new item.
53
- /// * `item` - The item to create. The type must implement [`Serialize`] and [`Deserialize`]
54
+ /// * `item` - The item to create. The type must implement [`Serialize`] and [`Deserialize`](serde::Deserialize)
54
55
/// * `options` - Optional parameters for the request
55
56
///
56
57
/// # Examples
@@ -87,14 +88,14 @@ pub trait ContainerClientMethods {
87
88
partition_key : impl Into < PartitionKey > ,
88
89
item : T ,
89
90
options : Option < ItemOptions > ,
90
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > ;
91
+ ) -> azure_core:: Result < Response < Item < T > > > ;
91
92
92
93
/// Replaces an existing item in the container.
93
94
///
94
95
/// # Arguments
95
96
/// * `partition_key` - The partition key of the item to replace.
96
97
/// * `item_id` - The id of the item to replace.
97
- /// * `item` - The item to create. The type must implement [`Serialize`] and [`Deserialize`]
98
+ /// * `item` - The item to create. The type must implement [`Serialize`] and [`Deserialize`](serde::Deserialize)
98
99
/// * `options` - Optional parameters for the request
99
100
///
100
101
/// # Examples
@@ -132,7 +133,7 @@ pub trait ContainerClientMethods {
132
133
item_id : impl AsRef < str > ,
133
134
item : T ,
134
135
options : Option < ItemOptions > ,
135
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > ;
136
+ ) -> azure_core:: Result < Response < Item < T > > > ;
136
137
137
138
/// Creates or replaces an item in the container.
138
139
///
@@ -141,7 +142,7 @@ pub trait ContainerClientMethods {
141
142
///
142
143
/// # Arguments
143
144
/// * `partition_key` - The partition key of the item to create or replace.
144
- /// * `item` - The item to create. The type must implement [`Serialize`] and [`Deserialize`]
145
+ /// * `item` - The item to create. The type must implement [`Serialize`] and [`Deserialize`](serde::Deserialize)
145
146
/// * `options` - Optional parameters for the request
146
147
///
147
148
/// # Examples
@@ -178,7 +179,7 @@ pub trait ContainerClientMethods {
178
179
partition_key : impl Into < PartitionKey > ,
179
180
item : T ,
180
181
options : Option < ItemOptions > ,
181
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > ;
182
+ ) -> azure_core:: Result < Response < Item < T > > > ;
182
183
183
184
/// Reads a specific item from the container.
184
185
///
@@ -216,7 +217,7 @@ pub trait ContainerClientMethods {
216
217
partition_key : impl Into < PartitionKey > ,
217
218
item_id : impl AsRef < str > ,
218
219
options : Option < ItemOptions > ,
219
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > ;
220
+ ) -> azure_core:: Result < Response < Item < T > > > ;
220
221
221
222
/// Deletes an item from the container.
222
223
///
@@ -243,7 +244,7 @@ pub trait ContainerClientMethods {
243
244
partition_key : impl Into < PartitionKey > ,
244
245
item_id : impl AsRef < str > ,
245
246
options : Option < ItemOptions > ,
246
- ) -> azure_core:: Result < azure_core :: Response > ;
247
+ ) -> azure_core:: Result < Response > ;
247
248
248
249
/// Executes a single-partition query against items in the container.
249
250
///
@@ -304,7 +305,7 @@ pub trait ContainerClientMethods {
304
305
query : impl Into < Query > ,
305
306
partition_key : impl Into < QueryPartitionStrategy > ,
306
307
options : Option < QueryOptions > ,
307
- ) -> azure_core:: Result < azure_core :: Pageable < QueryResults < T > , azure_core :: Error > > ;
308
+ ) -> azure_core:: Result < Pager < QueryResults < T > > > ;
308
309
}
309
310
310
311
/// A client for working with a specific container in a Cosmos DB account.
@@ -333,7 +334,7 @@ impl ContainerClientMethods for ContainerClient {
333
334
#[ allow( unused_variables) ]
334
335
// REASON: This is a documented public API so prefixing with '_' is undesirable.
335
336
options : Option < ReadContainerOptions > ,
336
- ) -> azure_core:: Result < azure_core :: Response < ContainerProperties > > {
337
+ ) -> azure_core:: Result < Response < ContainerProperties > > {
337
338
let mut req = Request :: new ( self . container_url . clone ( ) , azure_core:: Method :: Get ) ;
338
339
self . pipeline
339
340
. send ( Context :: new ( ) , & mut req, ResourceType :: Containers )
@@ -348,7 +349,7 @@ impl ContainerClientMethods for ContainerClient {
348
349
#[ allow( unused_variables) ]
349
350
// REASON: This is a documented public API so prefixing with '_' is undesirable.
350
351
options : Option < ItemOptions > ,
351
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > {
352
+ ) -> azure_core:: Result < Response < Item < T > > > {
352
353
let url = self . container_url . with_path_segments ( [ "docs" ] ) ;
353
354
let mut req = Request :: new ( url, azure_core:: Method :: Post ) ;
354
355
req. insert_headers ( & partition_key. into ( ) ) ?;
@@ -367,7 +368,7 @@ impl ContainerClientMethods for ContainerClient {
367
368
#[ allow( unused_variables) ]
368
369
// REASON: This is a documented public API so prefixing with '_' is undesirable.
369
370
options : Option < ItemOptions > ,
370
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > {
371
+ ) -> azure_core:: Result < Response < Item < T > > > {
371
372
let url = self
372
373
. container_url
373
374
. with_path_segments ( [ "docs" , item_id. as_ref ( ) ] ) ;
@@ -387,7 +388,7 @@ impl ContainerClientMethods for ContainerClient {
387
388
#[ allow( unused_variables) ]
388
389
// REASON: This is a documented public API so prefixing with '_' is undesirable.
389
390
options : Option < ItemOptions > ,
390
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > {
391
+ ) -> azure_core:: Result < Response < Item < T > > > {
391
392
let url = self . container_url . with_path_segments ( [ "docs" ] ) ;
392
393
let mut req = Request :: new ( url, azure_core:: Method :: Post ) ;
393
394
req. insert_header ( constants:: IS_UPSERT , "true" ) ;
@@ -406,7 +407,7 @@ impl ContainerClientMethods for ContainerClient {
406
407
#[ allow( unused_variables) ]
407
408
// REASON: This is a documented public API so prefixing with '_' is undesirable.
408
409
options : Option < ItemOptions > ,
409
- ) -> azure_core:: Result < azure_core :: Response < Item < T > > > {
410
+ ) -> azure_core:: Result < Response < Item < T > > > {
410
411
let url = self
411
412
. container_url
412
413
. with_path_segments ( [ "docs" , item_id. as_ref ( ) ] ) ;
@@ -425,7 +426,7 @@ impl ContainerClientMethods for ContainerClient {
425
426
#[ allow( unused_variables) ]
426
427
// REASON: This is a documented public API so prefixing with '_' is undesirable.
427
428
options : Option < ItemOptions > ,
428
- ) -> azure_core:: Result < azure_core :: Response > {
429
+ ) -> azure_core:: Result < Response > {
429
430
let url = self
430
431
. container_url
431
432
. with_path_segments ( [ "docs" , item_id. as_ref ( ) ] ) ;
@@ -444,26 +445,9 @@ impl ContainerClientMethods for ContainerClient {
444
445
#[ allow( unused_variables) ]
445
446
// REASON: This is a documented public API so prefixing with '_' is undesirable.
446
447
options : Option < QueryOptions > ,
447
- ) -> azure_core:: Result < azure_core:: Pageable < QueryResults < T > , azure_core:: Error > > {
448
- // Represents the raw response model from the server.
449
- // We'll use this to deserialize the response body and then convert it to a more user-friendly model.
450
- #[ derive( Deserialize ) ]
451
- struct QueryResponseModel < M > {
452
- #[ serde( rename = "Documents" ) ]
453
- documents : Vec < M > ,
454
- }
455
-
456
- // We have to manually implement Model, because the derive macro doesn't support auto-inferring type and lifetime bounds.
457
- // See https://github.com/Azure/azure-sdk-for-rust/issues/1803
458
- impl < M : DeserializeOwned > azure_core:: Model for QueryResponseModel < M > {
459
- async fn from_response_body (
460
- body : azure_core:: ResponseBody ,
461
- ) -> typespec_client_core:: Result < Self > {
462
- body. json ( ) . await
463
- }
464
- }
465
-
466
- let url = self . container_url . with_path_segments ( [ "docs" ] ) ;
448
+ ) -> azure_core:: Result < Pager < QueryResults < T > > > {
449
+ let mut url = self . container_url . clone ( ) ;
450
+ url. append_path_segments ( [ "docs" ] ) ;
467
451
let mut base_req = Request :: new ( url, azure_core:: Method :: Post ) ;
468
452
469
453
base_req. insert_header ( constants:: QUERY , "True" ) ;
@@ -477,7 +461,7 @@ impl ContainerClientMethods for ContainerClient {
477
461
// We have to double-clone here.
478
462
// First we clone the pipeline to pass it in to the closure
479
463
let pipeline = self . pipeline . clone ( ) ;
480
- Ok ( azure_core :: Pageable :: new ( move |continuation| {
464
+ Ok ( Pager :: from_callback ( move |continuation| {
481
465
// Then we have to clone it again to pass it in to the async block.
482
466
// This is because Pageable can't borrow any data, it has to own it all.
483
467
// That's probably good, because it means a Pageable can outlive the client that produced it, but it requires some extra cloning.
@@ -488,29 +472,13 @@ impl ContainerClientMethods for ContainerClient {
488
472
req. insert_header ( constants:: CONTINUATION , continuation) ;
489
473
}
490
474
491
- let resp : Response < QueryResponseModel < T > > = pipeline
475
+ let response = pipeline
492
476
. send ( Context :: new ( ) , & mut req, ResourceType :: Items )
493
477
. await ?;
494
-
495
- let query_metrics = resp
496
- . headers ( )
497
- . get_optional_string ( & constants:: QUERY_METRICS ) ;
498
- let index_metrics = resp
499
- . headers ( )
500
- . get_optional_string ( & constants:: INDEX_METRICS ) ;
501
- let continuation_token =
502
- resp. headers ( ) . get_optional_string ( & constants:: CONTINUATION ) ;
503
-
504
- let query_response: QueryResponseModel < T > = resp. deserialize_body ( ) . await ?;
505
-
506
- let query_results = QueryResults {
507
- items : query_response. documents ,
508
- query_metrics,
509
- index_metrics,
510
- continuation_token,
511
- } ;
512
-
513
- Ok ( query_results)
478
+ Ok ( PagerResult :: from_response_header (
479
+ response,
480
+ & constants:: CONTINUATION ,
481
+ ) )
514
482
}
515
483
} ) )
516
484
}
0 commit comments