PHPackages                             genesisdb/neos-genesisdb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. genesisdb/neos-genesisdb

ActiveNeos-package[Database &amp; ORM](/categories/database)

genesisdb/neos-genesisdb
========================

A Neos Flow wrapper for the GenesisDB PHP SDK

1.0.3(2mo ago)02PHP

Since Jun 11Pushed 2mo agoCompare

[ Source](https://github.com/genesisdb-io/genesisdb-io-neos)[ Packagist](https://packagist.org/packages/genesisdb/neos-genesisdb)[ RSS](/packages/genesisdb-neos-genesisdb/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (9)Used By (0)

GenesisDB Neos Flow package
===========================

[](#genesisdb-neos-flow-package)

A package to enable the use of GenesisDB with Flow and Neos.

Installation
------------

[](#installation)

Just run:

```
composer require genesisdb/neos-genesisdb

```

Configuration
-------------

[](#configuration)

```
GenesisDB:
  Neos:
    GenesisDB:
      apiUrl: 'https://genesisdb.domain.tld'
      apiVersion: 'v1'
      authToken: '21add3d2-6efb-4589-9305-e55925e77c43'
```

Usage
-----

[](#usage)

```
use GenesisDB\Neos\GenesisDB\Service\EventStoreService;
use GenesisDB\GenesisDB\CommitEvent;
use GenesisDB\GenesisDB\CommitEventOptions;
use GenesisDB\GenesisDB\Precondition;
use GenesisDB\GenesisDB\StreamOptions;
use Neos\Flow\Annotations as Flow;

#[Flow\Inject]
protected EventStoreService $eventStoreService;
```

Streaming Events
----------------

[](#streaming-events)

### Basic Event Streaming

[](#basic-event-streaming)

```
// Stream all events for a subject
$events = $this->eventStoreService->streamEvents('/customer');
```

### Stream Events from Lower Bound

[](#stream-events-from-lower-bound)

```
$events = $this->eventStoreService->streamEvents('/customer', new StreamOptions(
    lowerBound: 'event-id-123',
    includeLowerBoundEvent: true
));
```

### Stream Events with Upper Bound

[](#stream-events-with-upper-bound)

```
$events = $this->eventStoreService->streamEvents('/customer', new StreamOptions(
    upperBound: '9f3e4141-7208-4fb2-905f-445730f4f3b1',
    includeUpperBoundEvent: false
));
```

### Stream Events with Both Lower and Upper Bounds

[](#stream-events-with-both-lower-and-upper-bounds)

```
$events = $this->eventStoreService->streamEvents('/customer', new StreamOptions(
    lowerBound: '2d6d4141-6107-4fb2-905f-445730f4f2a9',
    includeLowerBoundEvent: true,
    upperBound: '9f3e4141-7208-4fb2-905f-445730f4f3b1',
    includeUpperBoundEvent: false
));
```

### Stream Latest Events by Event Type

[](#stream-latest-events-by-event-type)

```
$latestEvents = $this->eventStoreService->streamEvents('/customer', new StreamOptions(
    latestByEventType: 'io.genesisdb.app.customer-updated'
));
```

Committing Events
-----------------

[](#committing-events)

### Basic Event Committing

[](#basic-event-committing)

```
$this->eventStoreService->commitEvents([
    new CommitEvent(
        source: 'io.genesisdb.app',
        subject: '/customer',
        type: 'io.genesisdb.app.customer-added',
        data: [
            'firstName' => 'Bruce',
            'lastName' => 'Wayne',
            'emailAddress' => 'bruce.wayne@enterprise.wayne'
        ]
    ),
    new CommitEvent(
        source: 'io.genesisdb.app',
        subject: '/customer',
        type: 'io.genesisdb.app.customer-added',
        data: [
            'firstName' => 'Alfred',
            'lastName' => 'Pennyworth',
            'emailAddress' => 'alfred.pennyworth@enterprise.wayne'
        ]
    ),
    new CommitEvent(
        source: 'io.genesisdb.store',
        subject: '/article',
        type: 'io.genesisdb.store.article-added',
        data: [
            'name' => 'Tumbler',
            'color' => 'black',
            'price' => 2990000.00
        ]
    ),
    new CommitEvent(
        source: 'io.genesisdb.app',
        subject: '/customer/fed2902d-0135-460d-8605-263a06308448',
        type: 'io.genesisdb.app.customer-personaldata-changed',
        data: [
            'firstName' => 'Angus',
            'lastName' => 'MacGyver',
            'emailAddress' => 'angus.macgyer@phoenix.foundation'
        ]
    )
]);
```

Preconditions
-------------

[](#preconditions)

Preconditions allow you to enforce certain checks on the server before committing events. GenesisDB supports multiple precondition types:

### isSubjectNew

[](#issubjectnew)

Ensures that a subject is new (has no existing events):

```
$this->eventStoreService->commitEvents([
    new CommitEvent(
        source: 'io.genesisdb.app',
        subject: '/user/456',
        type: 'io.genesisdb.app.user-created',
        data: [
            'firstName' => 'John',
            'lastName' => 'Doe',
            'email' => 'john.doe@example.com'
        ]
    )
], [
    Precondition::isSubjectNew('/user/456')
]);
```

### isSubjectExisting

[](#issubjectexisting)

Ensures that events exist for the specified subject:

```
$this->eventStoreService->commitEvents([
    new CommitEvent(
        source: 'io.genesisdb.app',
        subject: '/user/456',
        type: 'io.genesisdb.app.user-updated',
        data: [
            'firstName' => 'John',
            'lastName' => 'Doe',
            'email' => 'john.doe@example.com'
        ]
    )
], [
    Precondition::isSubjectExisting('/user/456')
]);
```

### isQueryResultTrue

[](#isqueryresulttrue)

Evaluates a query and ensures the result is truthy. Supports the full GDBQL feature set including complex WHERE clauses, aggregations, and calculated fields.

**Basic uniqueness check:**

```
$this->eventStoreService->commitEvents([
    new CommitEvent(
        source: 'io.genesisdb.app',
        subject: '/user/456',
        type: 'io.genesisdb.app.user-created',
        data: [
            'firstName' => 'John',
            'lastName' => 'Doe',
            'email' => 'john.doe@example.com'
        ]
    )
], [
    Precondition::isQueryResultTrue(
        "STREAM e FROM events WHERE e.data.email == 'john.doe@example.com' MAP COUNT() == 0"
    )
]);
```

**Business rule enforcement (transaction limits):**

```
$this->eventStoreService->commitEvents([
    new CommitEvent(
        source: 'io.genesisdb.banking',
        subject: '/user/123/transactions',
        type: 'io.genesisdb.banking.transaction-processed',
        data: [
            'amount' => 500.00,
            'currency' => 'EUR'
        ]
    )
], [
    Precondition::isQueryResultTrue(
        "STREAM e FROM events WHERE e.subject UNDER '/user/123' AND e.type == 'transaction-processed' AND e.time >= '2024-01-01T00:00:00Z' MAP SUM(e.data.amount) + 500
