From 0b021daa6e839a76e1a3d44cb0dbebaf37400503 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 31 Dec 2024 00:10:53 +0400 Subject: [PATCH] Add `Workflow::upsertTypedSearchAttributes()` helper --- .../Request/UpsertTypedSearchAttributes.php | 4 ++-- src/Internal/Workflow/ScopeContext.php | 4 +--- src/Workflow.php | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php b/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php index daa217c7..442e52a4 100644 --- a/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php +++ b/src/Internal/Transport/Request/UpsertTypedSearchAttributes.php @@ -13,7 +13,7 @@ class UpsertTypedSearchAttributes extends Request public const NAME = 'UpsertWorkflowTypedSearchAttributes'; /** - * @param list $searchAttributes + * @param array $searchAttributes */ public function __construct( private readonly array $searchAttributes, @@ -22,7 +22,7 @@ public function __construct( } /** - * @return list + * @return array */ public function getSearchAttributes(): array { diff --git a/src/Internal/Workflow/ScopeContext.php b/src/Internal/Workflow/ScopeContext.php index d293a3c1..2dd48653 100644 --- a/src/Internal/Workflow/ScopeContext.php +++ b/src/Internal/Workflow/ScopeContext.php @@ -113,9 +113,7 @@ public function upsertSearchAttributes(array $searchAttributes): void public function upsertTypedSearchAttributes(SearchAttributeUpdate ...$updates): void { - $this->request( - new UpsertTypedSearchAttributes($updates), - ); + $this->request(new UpsertTypedSearchAttributes($updates)); } #[\Override] diff --git a/src/Workflow.php b/src/Workflow.php index 8f4172ee..51c71ef7 100644 --- a/src/Workflow.php +++ b/src/Workflow.php @@ -16,6 +16,7 @@ use Temporal\Activity\ActivityOptions; use Temporal\Activity\ActivityOptionsInterface; use Temporal\Client\WorkflowStubInterface; +use Temporal\Common\SearchAttributes\SearchAttributeUpdate; use Temporal\DataConverter\Type; use Temporal\DataConverter\ValuesInterface; use Temporal\Exception\OutOfContextException; @@ -911,6 +912,21 @@ public static function upsertSearchAttributes(array $searchAttributes): void self::getCurrentContext()->upsertSearchAttributes($searchAttributes); } + /** + * Upsert typed Search Attributes + * + * ```php + * Workflow::upsertTypedSearchAttributes( + * SearchAttributeKey::forKeyword('CustomKeyword')->valueSet('CustomValue'), + * SearchAttributeKey::forInt('MyCounter')->valueSet(42), + * ); + * ``` + */ + public static function upsertTypedSearchAttributes(SearchAttributeUpdate ...$updates): void + { + self::getCurrentContext()->upsertTypedSearchAttributes(...$updates); + } + /** * Generate a UUID. *