Skip to content

Commit

Permalink
add stream store support in cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Jul 29, 2024
1 parent c36ff32 commit 3b73c0e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/Console/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Patchlevel\EventSourcing\Console\OutputStyle;
use Patchlevel\EventSourcing\Message\Serializer\HeadersSerializer;
use Patchlevel\EventSourcing\Serializer\EventSerializer;
use Patchlevel\EventSourcing\Store\Criteria\Criteria;
use Patchlevel\EventSourcing\Store\Criteria\StreamCriterion;
use Patchlevel\EventSourcing\Store\Store;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -41,6 +43,12 @@ protected function configure(): void
'How many messages should be displayed',
10,
)
->addOption(
'stream',
null,
InputOption::VALUE_REQUIRED,
'Show messages from a specific stream (e.g. "stream-*")',
)
->addOption(
'forward',
null,
Expand All @@ -53,11 +61,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$limit = InputHelper::positiveIntOrZero($input->getOption('limit'));
$forward = InputHelper::bool($input->getOption('forward'));
$stream = InputHelper::nullableString($input->getOption('stream'));

$console = new OutputStyle($input, $output);

$maxCount = $this->store->count();
$stream = $this->store->load(null, null, null, !$forward);
$criteria = null;

if ($stream) {

Check failure on line 70 in src/Console/Command/ShowCommand.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

RiskyTruthyFalsyComparison

src/Console/Command/ShowCommand.php:70:13: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
$criteria = new Criteria(new StreamCriterion($stream));
}

$maxCount = $this->store->count($criteria);
$stream = $this->store->load($criteria, null, null, !$forward);

$currentCount = 0;

Expand Down
21 changes: 19 additions & 2 deletions src/Console/Command/WatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@ protected function configure(): void
'How much time should elapse before the next job is executed in milliseconds',
1000,
)
->addOption(
'stream',
null,
InputOption::VALUE_REQUIRED,
'Watch messages from a specific stream (e.g. "stream-*")',
)
->addOption(
'aggregate',
null,
InputOption::VALUE_REQUIRED,
'filter aggregate name',
'Filter aggregate name',
)
->addOption(
'aggregate-id',
null,
InputOption::VALUE_REQUIRED,
'filter aggregate id',
'Filter aggregate id',
);
}

Expand All @@ -64,9 +70,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$console = new OutputStyle($input, $output);

$sleep = InputHelper::positiveIntOrZero($input->getOption('sleep'));
$stream = InputHelper::nullableString($input->getOption('stream'));
$aggregate = InputHelper::nullableString($input->getOption('aggregate'));
$aggregateId = InputHelper::nullableString($input->getOption('aggregate-id'));

if ($stream && ($aggregate || $aggregateId)) {

Check failure on line 77 in src/Console/Command/WatchCommand.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

RiskyTruthyFalsyComparison

src/Console/Command/WatchCommand.php:77:13: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 77 in src/Console/Command/WatchCommand.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

RiskyTruthyFalsyComparison

src/Console/Command/WatchCommand.php:77:25: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 77 in src/Console/Command/WatchCommand.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

RiskyTruthyFalsyComparison

src/Console/Command/WatchCommand.php:77:39: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
$console->error('You can only provide stream or aggregate and aggregate-id');

return 1;
}

$index = $this->currentIndex();

if ($this->store instanceof SubscriptionStore) {
Expand All @@ -75,6 +88,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$criteriaBuilder = new CriteriaBuilder();

if ($stream !== null) {
$criteriaBuilder->streamName($stream);
}

if ($this->store instanceof StreamStore) {
if ($aggregate !== null || $aggregateId !== null) {
if ($aggregate === null || $aggregateId === null) {
Expand Down

0 comments on commit 3b73c0e

Please sign in to comment.