5
5
use hmac:: { Hmac , Mac , NewMac } ;
6
6
use serde:: { Deserialize , Serialize } ;
7
7
use sha2:: Sha256 ;
8
+ use typesense_codegen:: models:: { ApiKey , ApiKeySchema , ApiKeysResponse } ;
8
9
9
10
use super :: Client ;
10
11
use crate :: transport:: HttpLowLevel ;
26
27
actions : Vec < Actions > ,
27
28
collections : Vec < String > ,
28
29
description : impl Into < Option < String > > ,
29
- expires_at : impl Into < Option < usize > > ,
30
- ) -> crate :: Result < ClientKeyCreate > {
31
- let create = Create {
30
+ expires_at : impl Into < Option < i64 > > ,
31
+ ) -> crate :: Result < ApiKey > {
32
+ let actions = actions
33
+ . into_iter ( )
34
+ . map ( |action| action. to_string ( ) )
35
+ . collect ( ) ;
36
+ let create = ApiKeySchema {
32
37
actions,
33
38
collections,
34
39
description : description. into ( ) ,
47
52
/// Retrieve (metadata about) a key.
48
53
///
49
54
/// More info [here](https://typesense.org/docs/0.20.0/api/api-keys.html#retrieve-an-api-key).
50
- pub async fn retrieve ( & self , n : usize ) -> crate :: Result < ClientKeyRetrieve > {
55
+ pub async fn retrieve ( & self , n : usize ) -> crate :: Result < ApiKey > {
51
56
let response = self . client . get ( format ! ( "/keys/{}" , n) . as_str ( ) ) . await ?;
52
57
53
58
let body = response. into_body ( ) ;
57
62
/// Retrieve (metadata about) all keys.
58
63
///
59
64
/// More info [here](https://typesense.org/docs/0.20.0/api/api-keys.html#list-all-keys).
60
- pub async fn retrieve_all ( & self ) -> crate :: Result < ClientKeyRetrieveAll > {
65
+ pub async fn retrieve_all ( & self ) -> crate :: Result < ApiKeysResponse > {
61
66
let response = self . client . get ( "/keys" ) . await ?;
62
67
63
68
let body = response. into_body ( ) ;
@@ -133,50 +138,18 @@ pub enum Actions {
133
138
#[ serde( rename = "*" ) ]
134
139
All ,
135
140
}
136
-
137
- /// Structure returned by [`ClientKeys::create`] function.
138
- #[ derive( Serialize , Deserialize ) ]
139
- pub struct ClientKeyCreate {
140
- /// Key ID
141
- pub id : usize ,
142
-
143
- /// Key Actions
144
- pub actions : Vec < Actions > ,
145
-
146
- /// Key Collections
147
- pub collections : Vec < String > ,
148
-
149
- /// Key Value
150
- pub value : String ,
151
-
152
- /// Key Description
153
- pub description : String ,
154
- }
155
-
156
- /// Structure returned by [`ClientKeys::retrieve`] function.
157
- #[ derive( Serialize , Deserialize ) ]
158
- pub struct ClientKeyRetrieve {
159
- /// Key Actions
160
- pub actions : Vec < Actions > ,
161
-
162
- /// Key Collections
163
- pub collections : Vec < String > ,
164
-
165
- /// Key Description
166
- pub description : String ,
167
-
168
- /// Key ID
169
- pub id : usize ,
170
-
171
- /// Key Value Prefix
172
- pub value_prefix : String ,
173
- }
174
-
175
- /// Structure returned by [`ClientKeys::retrieve_all`] function.
176
- #[ derive( Serialize , Deserialize ) ]
177
- pub struct ClientKeyRetrieveAll {
178
- /// Vector of all the Keys
179
- pub keys : Vec < ClientKeyRetrieve > ,
141
+ impl ToString for Actions {
142
+ fn to_string ( & self ) -> String {
143
+ match self {
144
+ Self :: DocumentsAll => "documents:*" . to_string ( ) ,
145
+ Self :: DocumentsSearch => "documents:search" . to_string ( ) ,
146
+ Self :: DocumentsGet => "documents:get" . to_string ( ) ,
147
+ Self :: CollectionsAll => "collections:*" . to_string ( ) ,
148
+ Self :: CollectionsDelete => "collections:delete" . to_string ( ) ,
149
+ Self :: CollectionsCreate => "collections:create" . to_string ( ) ,
150
+ Self :: All => "*" . to_string ( ) ,
151
+ }
152
+ }
180
153
}
181
154
182
155
/// Structure returned by [`ClientKeys::delete`] function.
@@ -186,14 +159,6 @@ pub struct ClientKeyDelete {
186
159
pub id : usize ,
187
160
}
188
161
189
- #[ derive( Serialize ) ]
190
- struct Create {
191
- actions : Vec < Actions > ,
192
- collections : Vec < String > ,
193
- description : Option < String > ,
194
- expires_at : Option < usize > ,
195
- }
196
-
197
162
#[ derive( Serialize ) ]
198
163
struct GenerateScopedSearchKey {
199
164
filter_by : String ,
0 commit comments