@@ -162,7 +162,7 @@ private static Task<ItemResult> AddItemAsync(Container container, ExpandoObject
162162 return t . Result ;
163163 }
164164
165- return new ItemResult ( null , HttpStatusCode . InternalServerError ) ;
165+ return new ItemResult ( null , mode , HttpStatusCode . InternalServerError ) ;
166166 } , cancellationToken ) ;
167167 return task ;
168168 }
@@ -190,14 +190,24 @@ private static async Task<ItemResult> PopulateItem(Container container, ExpandoO
190190 var upsertResponse = await container . UpsertItemAsync ( item , cancellationToken : cancellationToken ) ;
191191 statusCode = upsertResponse . StatusCode ;
192192 break ;
193+ case DataWriteMode . DeleteStream :
194+ ArgumentNullException . ThrowIfNull ( partitionKeyPath , nameof ( partitionKeyPath ) ) ;
195+ var deleteMessage = await container . DeleteItemStreamAsync ( itemId , new PartitionKey ( GetPropertyValue ( item , partitionKeyPath . TrimStart ( '/' ) ) ) , cancellationToken : cancellationToken ) ;
196+ statusCode = deleteMessage . StatusCode ;
197+ break ;
198+ case DataWriteMode . Delete :
199+ ArgumentNullException . ThrowIfNull ( partitionKeyPath , nameof ( partitionKeyPath ) ) ;
200+ var deleteResponse = await container . DeleteItemAsync < ExpandoObject > ( itemId , new PartitionKey ( GetPropertyValue ( item , partitionKeyPath . TrimStart ( '/' ) ) ) , cancellationToken : cancellationToken ) ;
201+ statusCode = deleteResponse . StatusCode ;
202+ break ;
193203 }
194204
195205 if ( statusCode == null )
196206 {
197207 throw new ArgumentOutOfRangeException ( nameof ( mode ) , $ "Invalid data write mode specified: { mode } ") ;
198208 }
199209
200- return new ItemResult ( itemId , statusCode . Value ) ;
210+ return new ItemResult ( itemId , mode , statusCode . Value ) ;
201211 }
202212
203213 private static MemoryStream CreateItemStream ( ExpandoObject item )
@@ -216,9 +226,10 @@ public IEnumerable<IDataExtensionSettings> GetSettings()
216226 yield return new CosmosSinkSettings ( ) ;
217227 }
218228
219- public record ItemResult ( string ? Id , HttpStatusCode StatusCode )
229+ public record ItemResult ( string ? Id , DataWriteMode DataWriteMode , HttpStatusCode StatusCode )
220230 {
221- public bool IsSuccess => StatusCode is HttpStatusCode . OK or HttpStatusCode . Created ;
231+ public bool IsSuccess => StatusCode is HttpStatusCode . OK or HttpStatusCode . Created ||
232+ ( StatusCode is HttpStatusCode . NoContent or HttpStatusCode . NotFound && DataWriteMode is DataWriteMode . Delete or DataWriteMode . DeleteStream ) ;
222233 public int ItemCount => IsSuccess ? 1 : 0 ;
223234 }
224235 }
0 commit comments