Search by

adachsoft / event-journal-contracts

Arkadiusz Adach

Framework-agnostic contracts and value objects for recording and querying operational events.

Package info

gitlab.com/a.adach/event-journal-contracts

Issues

pkg:composer/adachsoft/event-journal-contracts

Statistics

Installs: 10

Dependents: 2

Suggesters: 0

Stars: 0

v0.1.0 2026-11-23 14:13 UTC

This package is auto-updated.

Last update: 2026-11-23 13:13:42 UTC


README

A framework-agnostic contract library for recording and querying operational events and problems. Applications can use it for worker errors, offline devices, failed actions, HTTP 5xx responses, and other incidents without coupling the journal model to a specific host or persistence engine.

This package defines value objects, DTOs, repository and service ports, and reusable repository contract tests. It does not provide a production persistence adapter or an event journal service implementation.

Installation

composer require adachsoft/event-journal-contracts

The only production dependency is adachsoft/reference-contracts, which supplies PrincipalReference for acknowledgement data.

Requirements

  • PHP 8.3 or later.
  • Composer for dependency installation.

Example

See Recording an Event for a minimal integration example using EventJournalInterface.

Model

  • EntryId is a non-empty identifier of up to 64 ASCII characters using letters, digits, underscores, dots, colons, and hyphens.
  • JournalLevelEnum provides ordered info, notice, warning, error, and critical severities.
  • SubjectReference identifies the optional object an event concerns, such as a device or schedule.
  • JournalEventDto is the input to EventJournalInterface::record(). Its source is non-empty, its code uses lowercase letters, digits, underscores, dots, or hyphens, and its context contains JSON-compatible values.
  • JournalEntryDto is the stored immutable representation. It retains the highest observed level, the latest message and context, the first and last occurrence times, an occurrence count, and optional acknowledgement data.
  • JournalEntryCollection is an immutable, typed iterable collection of stored entries.
  • JournalQueryDto supports minimum severity, source and code lists, subject, inclusive lastOccurredAt date bounds, acknowledgement state, and pagination. Values within a source list or code list match with OR; distinct filters are combined with AND. Repository results are ordered by newest lastOccurredAt first.

Ports

  • JournalEntryRepositoryInterface defines persistence, fingerprint lookup, filtering, counting, removal, and pruning.
  • EventJournalInterface defines recording and acknowledgement operations.
  • JournalListenerInterface observes recorded and acknowledged entries. Listener failures during recording must be isolated and must not make recording fail.

Deduplication

An event fingerprint is source|code|subject type|subject id; when there is no subject, the final two parts are empty. A journal implementation applies its configured deduplication window to an unacknowledged entry with the same fingerprint. When the prior entry is within that window, the implementation increments occurrences, preserves the first occurrence and identifier, updates the latest message, context, and occurrence time, and retains the more severe level. Otherwise, it creates a new entry. Acknowledged entries are not eligible for deduplication.

The contracts intentionally leave the deduplication window configuration to the service implementation.

Repository contract tests

The package ships AdachSoft\EventJournalContracts\Testing\AbstractJournalEntryRepositoryContractTest and InMemoryJournalEntryRepository through its Composer autoload mapping. PHPUnit is suggested, but is not a production dependency.

Extend the contract test and return the repository implementation being tested:

use AdachSoft\EventJournalContracts\Repository\JournalEntryRepositoryInterface;
use AdachSoft\EventJournalContracts\Testing\AbstractJournalEntryRepositoryContractTest;

final class MyJournalEntryRepositoryContractTest extends AbstractJournalEntryRepositoryContractTest
{
    protected function createRepository(): JournalEntryRepositoryInterface
    {
        return new MyJournalEntryRepository(/* test configuration */);
    }
}

Run that test with PHPUnit alongside the implementation's other tests. The shared suite verifies saving and replacing, lookup of the latest unacknowledged fingerprint match, all query filters and pagination, count without pagination, removal, and pruning. InMemoryJournalEntryRepository is a small example implementation for tests, not a production storage recommendation.