diff --git a/src/typesense/types/document.py b/src/typesense/types/document.py index a0b63b4..496432d 100644 --- a/src/typesense/types/document.py +++ b/src/typesense/types/document.py @@ -915,23 +915,42 @@ class DeleteSingleDocumentParameters(typing.TypedDict): ignore_not_found: typing.NotRequired[bool] -class DeleteQueryParameters(typing.TypedDict): +class TruncateDeleteParameters(typing.TypedDict): """ - Parameters for deleting documents. + Parameters for truncating a collection (deleting all documents, keeping schema). + + Attributes: + truncate (bool): Truncate the collection, keeping just the schema. + """ + + truncate: bool + + +class FilterDeleteParameters(typing.TypedDict): + """ + Parameters for deleting documents by filter. Attributes: - truncate (str): Truncate the collection, keeping just the schema. filter_by (str): Filter to apply to documents. batch_size (int): Batch size for deleting documents. ignore_not_found (bool): Ignore not found documents. """ - truncate: typing.NotRequired[bool] filter_by: str batch_size: typing.NotRequired[int] ignore_not_found: typing.NotRequired[bool] +DeleteQueryParameters = typing.Union[TruncateDeleteParameters, FilterDeleteParameters] +""" +Discriminated union of parameters for deleting documents. + +Either: + - TruncateDeleteParameters: Use truncate to delete all documents, keeping the schema. + - FilterDeleteParameters: Use filter_by (and optionally batch_size, ignore_not_found) to delete specific documents. +""" + + class DeleteResponse(typing.TypedDict): """ Response from deleting documents. diff --git a/tests/documents_test.py b/tests/documents_test.py index 9926798..994845a 100644 --- a/tests/documents_test.py +++ b/tests/documents_test.py @@ -206,6 +206,17 @@ def test_delete( assert response == {"num_deleted": 1} +def test_truncate( + actual_documents: Documents[Companies], + delete_all: None, + create_collection: None, + create_document: None, +) -> None: + """Test that the Documents object can delete a document from Typesense server.""" + response = actual_documents.delete({"truncate": True}) + assert response == {"num_deleted": 1} + + def test_delete_ignore_missing( actual_documents: Documents[Companies], delete_all: None,