Coverage for src/fluree_py/http/mixin/insert.py: 100%
11 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 03:03 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 03:03 +0000
1"""Mixin for handling data insertion operations in Fluree."""
3from typing import Generic, TypeVar, cast
5from fluree_py.http.mixin.utils import resolve_base_class_reference
6from fluree_py.http.protocol.mixin import HasInsertData
7from fluree_py.types.common import JsonArray, JsonObject
10T = TypeVar("T", bound="HasInsertData")
13class WithInsertMixin(Generic[T]):
14 """Provides data insertion capabilities for Fluree operations."""
16 def with_insert(self, data: JsonObject | JsonArray) -> T:
17 """Updates the operation with new data to be inserted.
19 Exceptions:
20 TypeError: If the type parameter cannot be resolved.
21 """
22 resolved_type = resolve_base_class_reference(self.__class__, "WithInsertMixin")
24 # Create a new instance of the resolved type
25 updated_fields = self.__dict__.copy()
26 updated_fields["data"] = data
27 return cast(T, resolved_type(**updated_fields))