diff --git a/src/Common/SearchAttributes/SearchAttributeUpdate.php b/src/Common/SearchAttributes/SearchAttributeUpdate.php index 774fef5d..bb25c8e7 100644 --- a/src/Common/SearchAttributes/SearchAttributeUpdate.php +++ b/src/Common/SearchAttributes/SearchAttributeUpdate.php @@ -14,10 +14,10 @@ abstract class SearchAttributeUpdate { /** - * @param non-empty-string $key + * @param non-empty-string $name */ protected function __construct( - public readonly string $key, + public readonly string $name, public readonly ValueType $type, ) {} diff --git a/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php b/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php new file mode 100644 index 00000000..c3918216 --- /dev/null +++ b/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php @@ -0,0 +1,50 @@ + $searchAttributes + */ + public function __construct( + private readonly array $searchAttributes, + ) { + parent::__construct(self::NAME, ['searchAttributes' => $this->prepareSearchAttributes()]); + } + + /** + * @return list + */ + public function getSearchAttributes(): array + { + return $this->searchAttributes; + } + + private function prepareSearchAttributes(): array { + $result = []; + foreach ($this->searchAttributes as $attr) { + $result[$attr->name] = $attr instanceof ValueSet + ? [ + 'type' => $attr->type->value, + 'operation' => 'set', + 'value' => $attr->value, + ] + : [ + 'type' => $attr->type->value, + 'operation' => 'unset', + ]; + } + + return $result; + } + +} diff --git a/src/Internal/Workflow/ScopeContext.php b/src/Internal/Workflow/ScopeContext.php index a611aa24..d293a3c1 100644 --- a/src/Internal/Workflow/ScopeContext.php +++ b/src/Internal/Workflow/ScopeContext.php @@ -13,8 +13,10 @@ use React\Promise\Deferred; use React\Promise\PromiseInterface; +use Temporal\Common\SearchAttributes\SearchAttributeUpdate; use Temporal\Exception\Failure\CanceledFailure; use Temporal\Internal\Transport\CompletableResult; +use Temporal\Internal\Transport\Request\UpsertTypedSearchAttributes; use Temporal\Internal\Workflow\Process\Scope; use Temporal\Worker\Transport\Command\RequestInterface; use Temporal\Workflow\CancellationScopeInterface; @@ -109,6 +111,13 @@ public function upsertSearchAttributes(array $searchAttributes): void ); } + public function upsertTypedSearchAttributes(SearchAttributeUpdate ...$updates): void + { + $this->request( + new UpsertTypedSearchAttributes($updates), + ); + } + #[\Override] public function destroy(): void {