Skip to content

Commit

Permalink
[general] Testing fixes (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 25, 2024
1 parent 68392fe commit 45d15a4
Show file tree
Hide file tree
Showing 52 changed files with 1,922 additions and 925 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 150
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]

steps:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]

steps:
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]

steps:
Expand Down Expand Up @@ -318,7 +318,7 @@ jobs:

strategy:
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "wiki"

on:
push:
branches:
- "main"

jobs:
deploy:
name: "Deploy docs to wiki"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Deploy to Wiki"
uses: "SwiftDocOrg/github-wiki-publish-action@v1"
with:
path: "docs"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,34 @@
## What is Redis DB plugin?

Redis DB plugin is extension for [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) ecosystem
which is implementing [Redis](https://redis.io) PubSub exchange and states manager for reading
and setting application state.
which is implementing [Redis](https://redis.io) Publish & Subscribe data exchange used by other modules of [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things)
ecosystem and also a states manager for reading and storing application states.

### Features

- Built-in server command for running standalone exchange client
- Application state management for reading and storing states in Redis database
- Implemented sync and async Redis client
- Redis DB pub/sub exchange client
- Synchronous and asynchronous application state management for reading and storing states in Redis database
- Synchronous and asynchronous exchange for data communication
- Redis clients with basic CRUD operations

Redis DB plugin is an [Apache2 licensed](http://www.apache.org/licenses/LICENSE-2.0) distributed extension, developed
in [PHP](https://www.php.net) on top of the [Nette framework](https://nette.org) and [Symfony framework](https://symfony.com).

## Requirements

Application library is tested against PHP 8.2.

## Installation

The best way to install **fastybird/redisdb-plugin** is using [Composer](http://getcomposer.org/):
This extension is part of the [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) ecosystem and is installed by default.
In case you want to create you own distribution of [FastyBird](https://www.fastybird.com) [IoT](https://en.wikipedia.org/wiki/Internet_of_things) ecosystem you could install this extension with [Composer](http://getcomposer.org/):

```sh
composer require fastybird/redisdb-plugin
```

## Documentation

Learn how to read & write states and consume & publish messages
in [documentation](https://github.com/FastyBird/redisdb-plugin/blob/main/docs/index.md).
:book: Learn how to read & write states and consume & publish messages in [documentation](https://github.com/FastyBird/redisdb-plugin/wiki).

# FastyBird

Expand All @@ -55,17 +58,17 @@ FastyBird is an Open Source IOT solution built from decoupled components with po

## Documentation

Documentation is available on [docs.fastybird.com](https://docs.fastybird.com).
:book: Documentation is available on [docs.fastybird.com](https://docs.fastybird.com).

## Contributing

The sources of this package are contained in the [FastyBird monorepo](https://github.com/FastyBird/fastybird). We welcome contributions for this package on [FastyBird/fastybird](https://github.com/FastyBird/).
The sources of this package are contained in the [FastyBird monorepo](https://github.com/FastyBird/fastybird). We welcome
contributions for this package on [FastyBird/fastybird](https://github.com/FastyBird/).

## Feedback

Use the [issue tracker](https://github.com/FastyBird/fastybird/issues) for bugs
or [mail](mailto:code@fastybird.com) or [Tweet](https://twitter.com/fastybird) us for any idea that can improve the
project.
Use the [issue tracker](https://github.com/FastyBird/fastybird/issues) for bugs reporting or send an [mail](mailto:code@fastybird.com)
to us or you could reach us on [X newtwork](https://x.com/fastybird) for any idea that can improve the project.

Thank you for testing, reporting and contributing.

Expand Down
33 changes: 14 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "fastybird/redisdb-plugin",
"type": "fastybird-plugin",
"description": "FastyBird IoT data storage & exchange plugin for Redis database",
"description": "FastyBird IoT application data storage & exchange plugin for Redis database",
"keywords": [
"state",
"state-management",
"exchange",
"pubsub",
"redis-client",
"fastybird",
"fb",
"plugin",
"redis",
"php",
"iot",
"state-management",
"redis",
"nette",
"state",
"pubsub",
"exchange",
"redis-client"
"plugin",
"php"
],
"homepage": "https://www.fastybird.com",
"license": "Apache-2.0",
Expand All @@ -35,16 +35,16 @@
"source": "https://github.com/FastyBird/redisdb-plugin"
},
"require": {
"php": ">=8.1.0",
"php": ">=8.2.0",
"clue/redis-react": "^3@dev",
"cweagans/composer-patches": "^1.7",
"evenement/evenement": "^3.0",
"fastybird/bootstrap-library": "dev-main",
"fastybird/application-library": "dev-main",
"fastybird/datetime-factory": "^0.6",
"fastybird/exchange-library": "dev-main",
"fastybird/metadata-library": "dev-main",
"nette/di": "^3.0",
"nette/utils": "^3.2",
"orisai/object-mapper": "^0.1",
"predis/predis": "^1.1",
"psr/event-dispatcher": "^1.0",
"psr/log": "^3.0",
Expand Down Expand Up @@ -81,7 +81,8 @@
"autoload-dev": {
"psr-4": {
"FastyBird\\Plugin\\RedisDb\\Tests\\Cases\\Unit\\": "tests/cases/unit",
"FastyBird\\Plugin\\RedisDb\\Tests\\Fixtures\\": "tests/fixtures"
"FastyBird\\Plugin\\RedisDb\\Tests\\Fixtures\\": "tests/fixtures",
"FastyBird\\Plugin\\RedisDb\\Tests\\Fixtures\\Dummy\\": "tests/fixtures/dummy"
}
},
"config": {
Expand All @@ -104,12 +105,6 @@
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mathsolver/mathsolver.git"
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
185 changes: 185 additions & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<p align="center">
<img src="https://github.com/fastybird/.github/blob/main/assets/repo_title.png?raw=true" alt="FastyBird"/>
</p>

> [!IMPORTANT]
> This documentation is meant to be used by developers or users which has basic programming skills. If you are regular user
> please use FastyBird IoT documentation which is available on [docs.fastybird.com](https://docs.fastybird.com).
# About Plugin

This library has some services divided into namespaces. All services are preconfigured and imported into application
container automatically.

```
\FastyBird\Plugin\RedisDb
\Clients - Services which manage connections to Redis database
\Exchange - Services related to exchange bus
\Models - Services for creating, reading, updating and deleting states in Redis database
\Publishers - Services responsible for publishing messages to Redis PubSub
```

All services, helpers, etc. are written to be self-descriptive :wink:.

## Using Plugin

The plugin is ready to be used as is. Has configured all services in application container and there is no need to develop
some other services or bridges.

## Plugin Configuration

This plugin is preconfigured with default values. If you want to change its configuration, you will have to provide configuration
via Nette DI services configuration which is usually done via Neon configuration file.

```neon
fbRedisDbPlugin: # Plugin extension name
client:
host: 127.0.0.1
port: 6379
username: username # Username and password could be left blank if connection to Redis is not secured
password: username_secret
exchange:
channel: fb_exchange # Exchange name/channel which will be used for publishing messages
```

## Storing States in Redis Database

If some service needs to store some data in Redis database, model services could be used for this. This plugin has two
services, repository for reading data by identifier and manager for creating, updating and deleting data.

This plugin is equiped with automatic `entity` factory, so each data which will be returned from repository or manager
will be transformed to entity: `\FastyBird\Plugin\RedisDb\States\State`

```php
namespace Your\CoolApp\Actions;

use FastyBird\Plugin\RedisDb\Models\States\StatesRepository;
use FastyBird\Plugin\RedisDb\Models\States\StatesManager;
use FastyBird\Plugin\RedisDb\States\State;
use Nette\Utils\ArrayHash;
use Ramsey\Uuid\Uuid;

class SomeService
{

private StatesRepository $repository;

private StatesManager $manager;

public function __construct(
StatesRepository $repository,
StatesManager $manager,
) {
$this->publisher = $publisher;
}

public function readStatus(Uuid $id)
{
// Your interesting logic here...

$state = $this->repository->find($id);
assert($state instanceof State);
}

public function writeStatus(Uuid $id, ArrayHash $data)
{
// Your interesting logic here...

$state = $this->manager->create($id, $data);
assert($state instanceof State);
}

}
```

### Using Custom State Entity

Because basic state entity has only identifier, it is necessary to define your custom state entity which will extend
this basic state entity.

What you have to have on your mind is to define `getCreateFields` and `getUpdateFields` methods and add entity attributes to them

- `getCreateFields` is used to provide field names which will manager search in provided data. It is possible to define which attribute is require and which not.
- `getUpdateFields` is used to provide field names which could be updated by manager. If some attribute is not provided, it will not be updated.

```php
namespace Your\CoolApp\States;

use Orisai\ObjectMapper;

class CustomState extends States\State
{

public function __construct(
Uuid\UuidInterface $id,
#[ObjectMapper\Rules\AnyOf([
new ObjectMapper\Rules\StringValue(notEmpty: true),
new ObjectMapper\Rules\NullValue(castEmptyString: true),
])]
private readonly string|null $value = null,
#[ObjectMapper\Rules\AnyOf([
new ObjectMapper\Rules\StringValue(notEmpty: true),
new ObjectMapper\Rules\NullValue(castEmptyString: true),
])]
private readonly string|null $camelCased = null,
#[ObjectMapper\Rules\AnyOf([
new ObjectMapper\Rules\DateTimeValue(format: DateTimeInterface::ATOM),
new ObjectMapper\Rules\NullValue(castEmptyString: true),
])]
#[ObjectMapper\Modifiers\FieldName(self::CREATED_AT_FIELD)]
private readonly DateTimeInterface|null $createdAt = null,
#[ObjectMapper\Rules\AnyOf([
new ObjectMapper\Rules\DateTimeValue(format: DateTimeInterface::ATOM),
new ObjectMapper\Rules\NullValue(castEmptyString: true),
])]
#[ObjectMapper\Modifiers\FieldName(self::UPDATED_AT_FIELD)]
private readonly DateTimeInterface|null $updatedAt = null,
)
{
parent::__construct($id);
}

public static function getCreateFields(): array
{
return [
0 => 'id',
1 => 'value', // Required attribute
self::CREATED_AT_FIELD => null, // Optional attribute witch default value null
self::UPDATED_AT_FIELD => null, // Optional attribute witch default value null
];
}

public static function getUpdateFields(): array
{
return [
'value', // Editable attribute
self::UPDATED_AT_FIELD,
];
}

public function getValue(): string|null
{
return $this->value;
}

public function getCreated(): DateTimeInterface|null
{
return $this->createdAt;
}

public function getUpdated(): DateTimeInterface|null
{
return $this->updatedAt;
}

public function toArray(): array
{
return array_merge([
'value' => $this->getValue(),
'created_at' => $this->getCreated()?->format(DateTimeInterface::ATOM),
'updated_at' => $this->getUpdated()?->format(DateTimeInterface::ATOM),
], parent::toArray());
}

}
```
Loading

0 comments on commit 45d15a4

Please sign in to comment.