From 69d6c7fd1a0f415ad9be1746a71c85ea8fcdde9f Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Thu, 7 May 2026 23:58:36 -0400 Subject: [PATCH] refactor: entity move and delete Signed-off-by: Sebastian Krupinski --- .../Service/ServiceEntityMutableInterface.php | 20 ++++++++++++++++--- .../Identifier/ResourceIdentifier.php | 4 ++++ .../ResourceIdentifierInterface.php | 7 ++++++- .../Identifier/ResourceIdentifiers.php | 7 +++++++ .../ResourceIdentifiersInterface.php | 7 ++++++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/shared/lib/Mail/Service/ServiceEntityMutableInterface.php b/shared/lib/Mail/Service/ServiceEntityMutableInterface.php index b50ac9f..243354a 100644 --- a/shared/lib/Mail/Service/ServiceEntityMutableInterface.php +++ b/shared/lib/Mail/Service/ServiceEntityMutableInterface.php @@ -11,6 +11,8 @@ namespace KTXF\Mail\Service; use KTXF\Mail\Entity\EntityBaseInterface; use KTXF\Mail\Entity\EntityMutableInterface; +use KTXF\Resource\Identifier\CollectionIdentifier; +use KTXF\Resource\Identifier\EntityIdentifier; /** * Mail Service Entity Mutable Interface @@ -70,7 +72,11 @@ interface ServiceEntityMutableInterface extends ServiceBaseInterface { * * @param EntityIdentifier ...$identifiers Source entities to delete * - * @return array Results keyed by entity identifier (true on success, error string on failure) + * @return array Results keyed by source entity identifier */ public function entityDelete(EntityIdentifier ...$identifiers): array; @@ -82,7 +88,11 @@ interface ServiceEntityMutableInterface extends ServiceBaseInterface { * @param CollectionIdentifier $target Target collection identifier * @param EntityIdentifier ...$identifiers Source entities to copy * - * @return array List of copied entity identifiers + * @return array Results keyed by source entity identifier */ public function entityCopy(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array; @@ -94,7 +104,11 @@ interface ServiceEntityMutableInterface extends ServiceBaseInterface { * @param CollectionIdentifier $target Target collection identifier * @param EntityIdentifier ...$identifiers Source entities to move * - * @return array List of moved entity identifiers + * @return array Results keyed by source entity identifier */ public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array; diff --git a/shared/lib/Resource/Identifier/ResourceIdentifier.php b/shared/lib/Resource/Identifier/ResourceIdentifier.php index edf929c..067e2e7 100644 --- a/shared/lib/Resource/Identifier/ResourceIdentifier.php +++ b/shared/lib/Resource/Identifier/ResourceIdentifier.php @@ -35,6 +35,10 @@ class ResourceIdentifier implements ResourceIdentifierInterface { return $this->provider; } + public function jsonSerialize(): string { + return (string) $this; + } + /** * Parse a colon-separated identifier string and return the appropriate level class * diff --git a/shared/lib/Resource/Identifier/ResourceIdentifierInterface.php b/shared/lib/Resource/Identifier/ResourceIdentifierInterface.php index ee5ddc7..b1425da 100644 --- a/shared/lib/Resource/Identifier/ResourceIdentifierInterface.php +++ b/shared/lib/Resource/Identifier/ResourceIdentifierInterface.php @@ -9,10 +9,12 @@ declare(strict_types=1); namespace KTXF\Resource\Identifier; +use KTXF\Json\JsonSerializable; + /** * Top-level identifier for resources (provider level) */ -interface ResourceIdentifierInterface extends \Stringable { +interface ResourceIdentifierInterface extends JsonSerializable, \Stringable { /** The provider segment (e.g. "imap") */ public function provider(): string; @@ -23,4 +25,7 @@ interface ResourceIdentifierInterface extends \Stringable { /** Canonical string form: provider[:service[:collection[:entity]]] */ public function __toString(): string; + /** Canonical JSON form: provider[:service[:collection[:entity]]] */ + public function jsonSerialize(): string; + } diff --git a/shared/lib/Resource/Identifier/ResourceIdentifiers.php b/shared/lib/Resource/Identifier/ResourceIdentifiers.php index e0c1c2a..5d94dc9 100644 --- a/shared/lib/Resource/Identifier/ResourceIdentifiers.php +++ b/shared/lib/Resource/Identifier/ResourceIdentifiers.php @@ -151,4 +151,11 @@ class ResourceIdentifiers implements ResourceIdentifiersInterface { return count($this->identifiers) === 0; } + public function jsonSerialize(): array { + return array_map( + static fn (ResourceIdentifierInterface $identifier): string => $identifier->jsonSerialize(), + $this->identifiers, + ); + } + } diff --git a/shared/lib/Resource/Identifier/ResourceIdentifiersInterface.php b/shared/lib/Resource/Identifier/ResourceIdentifiersInterface.php index c59c3dd..758eb94 100644 --- a/shared/lib/Resource/Identifier/ResourceIdentifiersInterface.php +++ b/shared/lib/Resource/Identifier/ResourceIdentifiersInterface.php @@ -9,10 +9,12 @@ declare(strict_types=1); namespace KTXF\Resource\Identifier; +use KTXF\Json\JsonSerializable; + /** * A typed collection of resource identifiers with search and filter capabilities */ -interface ResourceIdentifiersInterface extends \Countable, \IteratorAggregate { +interface ResourceIdentifiersInterface extends JsonSerializable, \Countable, \IteratorAggregate { /** Add an identifier to the collection */ public function add(ResourceIdentifierInterface $identifier): void; @@ -47,4 +49,7 @@ interface ResourceIdentifiersInterface extends \Countable, \IteratorAggregate { /** Get unique entity names */ public function entities(): array; + /** Serialize as an array of canonical identifier strings */ + public function jsonSerialize(): array; + }