feat: entity patch
Some checks failed
Build Test / test (pull_request) Successful in 30s
JS Unit Tests / test (pull_request) Failing after 30s
PHP Unit Tests / test (pull_request) Successful in 1m1s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-09 16:57:54 -04:00
parent 5794da2bf5
commit 23df5b1151
2 changed files with 188 additions and 62 deletions

View File

@@ -1017,6 +1017,21 @@ class Manager {
return $responseData;
}
/**
* Deletes entities
*
* @since 2026.04.01
*
* @param string $tenantId Tenant identifier
* @param string|null $userId User identifier for context
* @param ResourceIdentifiers $sources Source entities to delete
*
* @return array<string, array{
* disposition: 'moved'|'deleted'|'error',
* destination: ?CollectionIdentifier,
* mutation: EntityIdentifier
* }> Results keyed by source entity identifier
*/
public function entityDelete(string $tenantId, string $userId, ResourceIdentifiers $sources): array {
$operationOutcome = [];
@@ -1066,6 +1081,90 @@ class Manager {
return $operationOutcome;
}
/**
* Patches entities
*
* @since 2026.04.01
*
* @param string $tenantId Tenant identifier
* @param string|null $userId User identifier for context
* @param ResourceIdentifiers $sources Source entities to patch
* @param array $patchData Data to patch
*
* @return array<string, array{
* disposition: 'patched'|'error',
* error?: string
* }> Results keyed by source entity identifier
*/
public function entityPatch(string $tenantId, string $userId, ResourceIdentifiers $targets, array $patch): array {
$operationOutcome = [];
// Process targets grouped by provider and service to minimize redundant fetches and operations
foreach ($targets->providers() as $providerName) {
$providerTargets = $targets->byProvider($providerName);
$provider = $this->providerFetch($tenantId, $userId, $providerName);
// If provider is not found, mark all identifiers as failed and continue to next provider
if ($provider === null) {
foreach ($providerTargets->services() as $serviceName) {
$serviceTargets = $providerTargets->byService($serviceName);
foreach ($serviceTargets as $identifier) {
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'provider not found'];
}
}
continue;
}
foreach ($providerTargets->services() as $serviceName) {
$serviceTargets = $providerTargets->byService($serviceName);
$service = $this->serviceFetch($tenantId, $userId, $providerName, $serviceName);
// If service is not found, mark all identifiers as failed and continue to next service
if ($service === null) {
foreach ($serviceTargets as $identifier) {
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'service not found'];
}
continue;
}
// If service does not support entity mutation, mark all identifiers as failed and continue to next service
if (!($service instanceof ServiceEntityMutableInterface)) {
foreach ($serviceTargets as $identifier) {
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'entity mutations not supported'];
}
continue;
}
// If service does not support entity patching, mark all identifiers as failed and continue to next service
if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_PATCH)) {
foreach ($serviceTargets as $identifier) {
$operationOutcome[$identifier] = ['disposition' => 'error', 'error' => 'entity patching not supported'];
}
continue;
}
$properties = $service->entityFresh()->getProperties()->jsonDeserialize($patch);
return $service->entityPatch(...$serviceTargets->all(), patch: $patch);
}
}
return $operationOutcome;
}
/**
* Moves entities to another collection
*
* @since 2025.05.01
*
* @param string $tenantId Tenant identifier
* @param string|null $userId User identifier for context
* @param CollectionIdentifier $target Target collection identifier
* @param ResourceIdentifiers $sources Source entities to move
*
* @return array<string, array{
* disposition: 'moved'|'error',
* destination: ?CollectionIdentifier,
* mutation: EntityIdentifier
* }> Results keyed by source entity identifier
*/
public function entityMove(string $tenantId, string $userId, CollectionIdentifier $target, ResourceIdentifiers $sources): array {
$targetService = $this->serviceFetch($tenantId, $userId, $target->provider(), $target->service());