Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/test-suite-plain-event-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@codeforbreakfast/eventsourcing-aggregates': patch
'@codeforbreakfast/eventsourcing-store': patch
---

The event store test suite and the command processing example now pass lint under typescript-eslint 8.71.2. Their example events are plain types rather than types derived from schemas that were never used at runtime. Nothing changes in what either package exports or does.
15 changes: 3 additions & 12 deletions packages/eventsourcing-aggregates/src/lib/aggregate-load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,9 @@ interface TestAggregateState {
readonly count: number;
}

const TestEventCreated = Schema.Struct({
type: Schema.Literal('TestCreated'),
data: Schema.Struct({ value: Schema.String }),
});

const TestEventIncremented = Schema.Struct({
type: Schema.Literal('TestIncremented'),
data: Schema.Struct({}),
});

const TestEvent = Schema.Union(TestEventCreated, TestEventIncremented);
type TestEvent = Schema.Schema.Type<typeof TestEvent>;
type TestEvent =
| { readonly type: 'TestCreated'; readonly data: { readonly value: string } }
| { readonly type: 'TestIncremented'; readonly data: Readonly<Record<string, never>> };

const applyTestEvent =
(state: Readonly<Option.Option<TestAggregateState>>) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Effect, Layer, pipe, Schema, Context } from 'effect';
import { Effect, Layer, pipe, Context } from 'effect';
import type { ReadonlyDeep } from 'type-fest';
import {
CommandProcessingService,
Expand All @@ -20,24 +20,12 @@ import {
// ============================================================================

// Example: Define your domain-specific events
const UserCreated = Schema.Struct({
type: Schema.Literal('UserCreated'),
data: Schema.Struct({
name: Schema.String,
email: Schema.String,
}),
});

const UserUpdated = Schema.Struct({
type: Schema.Literal('UserUpdated'),
data: Schema.Struct({
name: Schema.String,
}),
});

// Example: Union of all user events
const UserEvent = Schema.Union(UserCreated, UserUpdated);
type UserEvent = typeof UserEvent.Type;
type UserEvent =
| {
readonly type: 'UserCreated';
readonly data: { readonly name: string; readonly email: string };
}
| { readonly type: 'UserUpdated'; readonly data: { readonly name: string } };

// Example: Create a domain-specific event store tag
const UserEventStore = Context.GenericTag<EventStore<UserEvent>, EventStore<UserEvent>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,12 @@ const isUnknownError: (
) => error is Extract<CommandFailure['error'], { readonly _tag: 'UnknownError' }> =
Schema.is(UnknownErrorSchema);

const UserCreated = Schema.Struct({
type: Schema.Literal('UserCreated'),
data: Schema.Struct({
name: Schema.String,
email: Schema.String,
}),
});

const OrderCreated = Schema.Struct({
type: Schema.Literal('OrderCreated'),
data: Schema.Struct({
orderId: Schema.String,
}),
});

const TestEvent = Schema.Union(UserCreated, OrderCreated);
type TestEvent = typeof TestEvent.Type;
type TestEvent =
| {
readonly type: 'UserCreated';
readonly data: { readonly name: string; readonly email: string };
}
| { readonly type: 'OrderCreated'; readonly data: { readonly orderId: string } };

const TestEventStore = Context.GenericTag<EventStore<TestEvent>, EventStore<TestEvent>>(
'TestEventStore'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const Id = {
export const newEventStreamId = () =>
pipe(`stream_${Id.randomPart()}`, Schema.decode(EventStreamId));

const FooEvent = Schema.Struct({ bar: Schema.String });
type FooEvent = typeof FooEvent.Type;
type FooEvent = { readonly bar: string };

const readStreamFromBeginning =
(streamId: Effect.Effect<EventStreamId, ParseResult.ParseError, never>) =>
Expand Down
Loading