Skip to content

Commit

Permalink
add indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
mmasiukevich committed Feb 5, 2019
1 parent c2865e2 commit 8d4810c
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/EventStream/Store/EventStreamStore.php
Expand Up @@ -26,7 +26,7 @@ interface EventStreamStore
*
* @param StoredAggregateEventStream $aggregateEventStream
*
* @return Promise It does not return any result
* @return Promise It doesn't return any result
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
Expand All @@ -40,7 +40,7 @@ public function save(StoredAggregateEventStream $aggregateEventStream): Promise;
*
* @param StoredAggregateEventStream $aggregateEventStream
*
* @return Promise It does not return any result
* @return Promise It doesn't return any result
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
Expand Down Expand Up @@ -88,7 +88,7 @@ public function close(AggregateId $id): Promise;
* @param int $toVersion
* @param bool $force Delete all events after the specified version
*
* @return Promise It does not return any result
* @return Promise It doesn't return any result
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
Expand Down
21 changes: 21 additions & 0 deletions src/Indexes/Exceptions/EmptyValuesNotAllowed.php
@@ -0,0 +1,21 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes\Exceptions;

/**
*
*/
final class EmptyValuesNotAllowed extends \InvalidArgumentException
{

}
21 changes: 21 additions & 0 deletions src/Indexes/Exceptions/IndexNameCantBeEmpty.php
@@ -0,0 +1,21 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes\Exceptions;

/**
*
*/
final class IndexNameCantBeEmpty extends \InvalidArgumentException
{

}
21 changes: 21 additions & 0 deletions src/Indexes/Exceptions/InvalidValueType.php
@@ -0,0 +1,21 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes\Exceptions;

/**
*
*/
final class InvalidValueType extends \InvalidArgumentException
{

}
21 changes: 21 additions & 0 deletions src/Indexes/Exceptions/ValueKeyCantBeEmpty.php
@@ -0,0 +1,21 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes\Exceptions;

/**
*
*/
final class ValueKeyCantBeEmpty extends \InvalidArgumentException
{

}
92 changes: 92 additions & 0 deletions src/Indexes/IndexKey.php
@@ -0,0 +1,92 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes;

use ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty;
use ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty;

/**
* The key for the value stored in the index
*
* @property-read string $indexName
* @property-read string $valueKey
*/
final class IndexKey
{
/**
* @var string
*/
public $indexName;

/**
* @var string
*/
public $valueKey;

/**
* @param string $indexName
* @param string $valueKey
*
* @return self
*
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty
*/
public static function create(string $indexName, string $valueKey): self
{
self::assertIndexNameIsNotEmpty($indexName);
self::assertValueKeyIsNotEmpty($valueKey);

return new self($indexName, $valueKey);
}

/**
* @param string $indexName
*
* @return void
*
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty
*/
private static function assertIndexNameIsNotEmpty(string $indexName): void
{
if('' === $indexName)
{
throw new IndexNameCantBeEmpty('Index name can\'t be empty');
}
}

/**
* @param string $valueKey
*
* @return void
*
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty
*/
private static function assertValueKeyIsNotEmpty(string $valueKey): void
{
if('' === $valueKey)
{
throw new ValueKeyCantBeEmpty('Value key can\'t be empty');
}
}

/**
* @param string $indexName
* @param string $valueKey
*/
private function __construct(string $indexName, string $valueKey)
{
$this->indexName = $indexName;
$this->valueKey = $valueKey;
}
}
85 changes: 85 additions & 0 deletions src/Indexes/IndexValue.php
@@ -0,0 +1,85 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes;

use ServiceBus\EventSourcing\Indexes\Exceptions\EmptyValuesNotAllowed;
use ServiceBus\EventSourcing\Indexes\Exceptions\InvalidValueType;

/**
* The value stored in the index
*
* @property-read mixed $value
*/
final class IndexValue
{
/**
* @var mixed
*/
public $value;

/**
* @param mixed $value
*
* @return self
*
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\InvalidValueType
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\EmptyValuesNotAllowed
*/
public static function create($value): self
{
self::assertIsScalar($value);
self::assertNotEmpty($value);

return new self($value);
}

/**
* @param mixed $value
*
* @return void
*
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\EmptyValuesNotAllowed
*/
private static function assertNotEmpty($value): void
{
if('' === (string) $value)
{
throw new EmptyValuesNotAllowed('Value can not be empty');
}
}

/**
* @param mixed $value
*
* @return void
*
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\InvalidValueType
*/
private static function assertIsScalar($value): void
{
if(false === \is_scalar($value))
{
throw new InvalidValueType(
\sprintf('The value must be of type "scalar". "%s" passed', \gettype($value))
);
}
}

/**
* @param mixed $value
*/
private function __construct($value)
{
$this->value = $value;
}
}
76 changes: 76 additions & 0 deletions src/Indexes/Store/IndexStore.php
@@ -0,0 +1,76 @@
<?php

/**
* Event Sourcing implementation
*
* @author Maksim Masiukevich <dev@async-php.com>
* @license MIT
* @license https://opensource.org/licenses/MIT
*/

declare(strict_types = 1);

namespace ServiceBus\EventSourcing\Indexes\Store;

use Amp\Promise;
use ServiceBus\EventSourcing\Indexes\IndexKey;
use ServiceBus\EventSourcing\Indexes\IndexValue;

/**
*
*/
interface IndexStore
{
/**
* Find stored value
*
* @param IndexKey $indexKey
*
* @return Promise<\ServiceBus\EventSourcing\Indexes\IndexValue|null>
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions
*/
public function find(IndexKey $indexKey): Promise;

/**
* Add a new value
*
* @param IndexKey $indexKey
* @param IndexValue $value $value
*
* @return Promise<int> Returns the number of added records
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions
* @throws \ServiceBus\Storage\Common\Exceptions\UniqueConstraintViolationCheckFailed
*/
public function add(IndexKey $indexKey, IndexValue $value): Promise;

/**
* @param IndexKey $indexKey
*
* @return Promise It doesn't return any result
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions
*/
public function delete(IndexKey $indexKey): Promise;

/**
* Update existent value
*
* @param IndexKey $indexKey
* @param IndexValue $value
*
* @return Promise<int> Returns the number of updated records
*
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions
*/
public function update(IndexKey $indexKey, IndexValue $value): Promise;
}

0 comments on commit 8d4810c

Please sign in to comment.