@@ -107,6 +107,23 @@ pub struct PreparedRecord {
107107 sealer : Sealer ,
108108}
109109
110+ pub struct PreparedDelete {
111+ primary_key : PreparedPrimaryKey ,
112+ protected_indexes : Cow < ' static , [ ( Cow < ' static , str > , IndexType ) ] > ,
113+ }
114+
115+ impl PreparedDelete {
116+ pub fn new < S : Searchable + Identifiable > ( k : impl Into < S :: PrimaryKey > ) -> Self {
117+ let primary_key = PreparedPrimaryKey :: new :: < S > ( k) ;
118+ let protected_indexes = S :: protected_indexes ( ) ;
119+
120+ Self {
121+ primary_key,
122+ protected_indexes,
123+ }
124+ }
125+ }
126+
110127impl PreparedRecord {
111128 pub ( crate ) fn new (
112129 protected_indexes : Cow < ' static , [ ( Cow < ' static , str > , IndexType ) ] > ,
@@ -264,14 +281,13 @@ impl<D> EncryptedTable<D> {
264281 Ok ( item. into_value ( ) ?)
265282 }
266283
267- pub async fn create_delete_patch < E : Searchable + Identifiable > (
284+ pub async fn create_delete_patch (
268285 & self ,
269- k : impl Into < E :: PrimaryKey > ,
286+ delete : PreparedDelete ,
270287 ) -> Result < DynamoRecordPatch , DeleteError > {
271- let PrimaryKeyParts { pk, sk } =
272- self . encrypt_primary_key_parts ( PreparedPrimaryKey :: new :: < E > ( k) ) ?;
288+ let PrimaryKeyParts { pk, sk } = self . encrypt_primary_key_parts ( delete. primary_key ) ?;
273289
274- let delete_records = all_index_keys ( & sk, E :: protected_indexes ( ) )
290+ let delete_records = all_index_keys ( & sk, delete . protected_indexes )
275291 . into_iter ( )
276292 . map ( |x| Ok :: < _ , DeleteError > ( b64_encode ( hmac ( & x, Some ( pk. as_str ( ) ) , & self . cipher ) ?) ) )
277293 . chain ( [ Ok ( sk) ] )
@@ -407,7 +423,7 @@ impl EncryptedTable<Dynamo> {
407423 k : impl Into < E :: PrimaryKey > ,
408424 ) -> Result < ( ) , DeleteError > {
409425 let transact_items = self
410- . create_delete_patch :: < E > ( k)
426+ . create_delete_patch ( PreparedDelete :: new :: < E > ( k) )
411427 . await ?
412428 . into_transact_write_items ( & self . db . table_name ) ?;
413429
0 commit comments