-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UpsertTypedSearchAttributes command
- Loading branch information
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Internal/Transport/Request/UpsertTypedSearchAttributes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Internal\Transport\Request; | ||
|
||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate; | ||
use Temporal\Common\SearchAttributes\SearchAttributeUpdate\ValueSet; | ||
use Temporal\Worker\Transport\Command\Client\Request; | ||
|
||
class UpsertTypedSearchAttributes extends Request | ||
{ | ||
public const NAME = 'UpsertWorkflowTypedSearchAttributes'; | ||
|
||
/** | ||
* @param list<SearchAttributeUpdate> $searchAttributes | ||
*/ | ||
public function __construct( | ||
private readonly array $searchAttributes, | ||
) { | ||
parent::__construct(self::NAME, ['searchAttributes' => $this->prepareSearchAttributes()]); | ||
} | ||
|
||
/** | ||
* @return list<SearchAttributeUpdate> | ||
*/ | ||
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters