@@ -262,13 +262,13 @@ def _process_completed_arc_tasks(
262262 async def _submit_arcs_parallel (
263263 self ,
264264 harvest_id : str ,
265- arcs : "AsyncGenerator[ARC | dict[str, Any], None] | AsyncIterator[ARC | dict[str, Any]]" ,
265+ arcs : "AsyncGenerator[ARC | dict[str, Any] | str , None] | AsyncIterator[ARC | dict[str, Any] | str ]" ,
266266 ) -> int :
267267 """Submit all ARCs in bounded parallelism and return number of skipped ARC submissions."""
268268 pending_tasks : set [asyncio .Task [None ]] = set ()
269269 failed_submissions = 0
270270
271- async def submit_one (arc_item : "ARC | dict[str, Any]" ) -> None :
271+ async def submit_one (arc_item : "ARC | dict[str, Any] | str " ) -> None :
272272 await self .submit_arc_in_harvest (harvest_id , arc_item )
273273
274274 async for arc in arcs :
@@ -446,10 +446,18 @@ async def _delete(self, path: str) -> None:
446446 # ------------------------------------------------------------------
447447
448448 @classmethod
449- def _serialize_arc (cls , arc : "ARC | dict[str, Any]" ) -> dict [str , Any ]:
450- """Serialize an ARC object to a plain RO-Crate JSON dict."""
449+ def _serialize_arc (cls , arc : "ARC | dict[str, Any] | str " ) -> dict [str , Any ]:
450+ """Serialize an ARC object, dict, or JSON string to a plain RO-Crate JSON dict."""
451451 if isinstance (arc , dict ):
452452 return arc
453+ if isinstance (arc , str ):
454+ try :
455+ data = json .loads (arc )
456+ if not isinstance (data , dict ):
457+ raise ApiClientError (f"JSON string must represent a dictionary, got { type (data ).__name__ } " )
458+ return cast (dict [str , Any ], data )
459+ except json .JSONDecodeError as e :
460+ raise ApiClientError (f"Invalid JSON string provided for ARC: { e } " ) from e
453461 return cast (dict [str , Any ], json .loads (arc .ToROCrateJsonString ()))
454462
455463 @classmethod
@@ -473,7 +481,7 @@ def _parse_harvest_response(cls, data: Any) -> HarvestResult:
473481 async def create_or_update_arc (
474482 self ,
475483 rdi : str ,
476- arc : "ARC | dict[str, Any]" ,
484+ arc : "ARC | dict[str, Any] | str " ,
477485 ) -> ArcResult :
478486 """Create or update an ARC.
479487
@@ -483,7 +491,7 @@ async def create_or_update_arc(
483491
484492 Args:
485493 rdi: RDI identifier.
486- arc: ARC object or a pre-serialised RO-Crate JSON dict.
494+ arc: ARC object, a pre-serialised RO-Crate JSON dict, or a JSON string .
487495
488496 Returns:
489497 :class:`ArcResult` with the result of the operation.
@@ -579,7 +587,7 @@ async def cancel_harvest(self, harvest_id: str) -> None:
579587 async def submit_arc_in_harvest (
580588 self ,
581589 harvest_id : str ,
582- arc : "ARC | dict[str, Any]" ,
590+ arc : "ARC | dict[str, Any] | str " ,
583591 ) -> ArcResult :
584592 """Submit an ARC within an active harvest run.
585593
@@ -588,7 +596,7 @@ async def submit_arc_in_harvest(
588596
589597 Args:
590598 harvest_id: Harvest identifier.
591- arc: ARC object or a pre-serialised RO-Crate JSON dict.
599+ arc: ARC object, a pre-serialised RO-Crate JSON dict, or a JSON string .
592600
593601 Returns:
594602 :class:`ArcResult` with the result of the operation.
@@ -601,7 +609,7 @@ async def submit_arc_in_harvest(
601609 async def harvest_arcs (
602610 self ,
603611 rdi : str ,
604- arcs : "AsyncGenerator[ARC | dict[str, Any], None] | AsyncIterator[ARC | dict[str, Any]]" ,
612+ arcs : "AsyncGenerator[ARC | dict[str, Any] | str , None] | AsyncIterator[ARC | dict[str, Any] | str ]" ,
605613 expected_datasets : int | None = None ,
606614 ) -> HarvestResult :
607615 """Create a harvest, upload all ARCs from an async generator, then complete it.
@@ -618,8 +626,8 @@ async def harvest_arcs(
618626
619627 Args:
620628 rdi: RDI identifier for the harvest.
621- arcs: Async generator or async iterator yielding ARC objects or
622- pre-serialised RO-Crate dicts.
629+ arcs: Async generator or async iterator yielding ARC objects,
630+ pre-serialised RO-Crate dicts, or JSON strings .
623631 expected_datasets: Optional hint about the total number of ARCs.
624632
625633 Returns:
@@ -631,7 +639,7 @@ async def harvest_arcs(
631639
632640 Example::
633641
634- async def my_arcs() -> AsyncGenerator[dict, None]:
642+ async def my_arcs() -> AsyncGenerator[dict | str , None]:
635643 for arc in source:
636644 yield arc
637645
0 commit comments