Skip to content

Describes what an aggregate writes and accepts, for consumers outside the process, and guards stored events against schema changes that would break them.

  • events and commands give the JSON Schema of every event, in every version declared with EventVersions, and of every command payload.
  • document lists them for several aggregates in an AsyncAPI 3 document.
  • captureSamples takes a few stored payloads of each event and version, saveSamples keeps them in a JSON file, and checkCompatibility fails when one of them no longer decodes with the current aggregate.

JSON Schema describes the JSON form of a schema, as Schema.toCodecJson encodes it. Personal fields, see PersonalData, are described in plaintext: in the store they are encrypted.

Defined in: src/EventCatalog.ts:230

  • object & YieldableError<this>

new IncompatibleSamples(…args): IncompatibleSamples

Defined in: node_modules/.pnpm/effect@4.0.6/node_modules/effect/dist/Schema.d.ts:10979

…[props: object, options?: MakeOptions]

IncompatibleSamples

Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).constructor

readonly aggregateName: string = Schema.String

Defined in: src/EventCatalog.ts:231

Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).aggregateName

readonly failures: readonly object[]

Defined in: src/EventCatalog.ts:232

Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).failures

get message(): string

Defined in: src/EventCatalog.ts:238

string

Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).message

Defined in: src/EventCatalog.ts:106

An AsyncAPI 3.0 document, with JSON Schema draft-07 payloads as AsyncAPI expects.

readonly asyncapi: "3.0.0"

Defined in: src/EventCatalog.ts:107

readonly channels: Record<string, unknown>

Defined in: src/EventCatalog.ts:109

readonly components: object

Defined in: src/EventCatalog.ts:111

readonly messages: Record<string, unknown>

readonly schemas: Record<string, JsonSchema.JsonSchema>

readonly info: object

Defined in: src/EventCatalog.ts:108

readonly optional description?: string

readonly title: string

readonly version: string

readonly operations: Record<string, unknown>

Defined in: src/EventCatalog.ts:110


Defined in: src/EventCatalog.ts:47

readonly aggregate: string

Defined in: src/EventCatalog.ts:48

readonly name: string

Defined in: src/EventCatalog.ts:49

readonly payload: JsonSchema

Defined in: src/EventCatalog.ts:51

A JSON Schema draft 2020-12 of the payload.


Defined in: src/EventCatalog.ts:99

readonly optional description?: string

Defined in: src/EventCatalog.ts:102

readonly title: string

Defined in: src/EventCatalog.ts:100

readonly version: string

Defined in: src/EventCatalog.ts:101


Defined in: src/EventCatalog.ts:36

readonly aggregate: string

Defined in: src/EventCatalog.ts:37

readonly personalFields: readonly string[]

Defined in: src/EventCatalog.ts:44

Paths of the personal fields in the current version, encrypted in the store.

readonly schemaVersion: number

Defined in: src/EventCatalog.ts:40

The version new events are written in, the last of versions.

readonly type: string

Defined in: src/EventCatalog.ts:38

readonly versions: readonly EventVersion[]

Defined in: src/EventCatalog.ts:42

Oldest first. Events written before versions were declared are version 1.


Defined in: src/EventCatalog.ts:30

readonly schema: JsonSchema

Defined in: src/EventCatalog.ts:33

A JSON Schema draft 2020-12 of the payload in this version.

readonly schemaVersion: number

Defined in: src/EventCatalog.ts:31

Sample = typeof Sample.Type

Defined in: src/EventCatalog.ts:220

A payload as the store keeps it, to check that the current aggregate still reads it.

const Sample: Struct<{ aggregateName: String; payload: Codec<Json, Json, never, never>; schemaVersion: Int; type: String; }>

Defined in: src/EventCatalog.ts:220

A payload as the store keeps it, to check that the current aggregate still reads it.

captureSamples(aggregates, options?): Effect<readonly object[], EventStoreError, EventStore>

Defined in: src/EventCatalog.ts:281

Reads the store and keeps the last perVersion payloads, one by default, of every event type and schema version of the given aggregates.

Personal fields are replaced by the value they read as once their subject is forgotten, so samples hold no personal data and can be committed, and checking them needs no keys. The rest of the payload is kept as it was stored.

readonly Any[]

number

Effect<readonly object[], EventStoreError, EventStore>


checkCompatibility(aggregate, samples): Effect<number, IncompatibleSamples>

Defined in: src/EventCatalog.ts:340

Decodes every sample of the aggregate with its current schemas and upcasts, as a store read would, and fails with IncompatibleSamples listing the ones that no longer decode. Returns how many samples were checked.

Personal fields in samples are expected in plaintext, as captureSamples leaves them, so no keys are needed.

Any

readonly object[]

Effect<number, IncompatibleSamples>


commands(aggregate): readonly CommandEntry[]

Defined in: src/EventCatalog.ts:88

The JSON Schema of the payload of every command of an aggregate.

Any

readonly CommandEntry[]


document(aggregates, options): AsyncApiDocument

Defined in: src/EventCatalog.ts:138

Lists the events and commands of some aggregates in an AsyncAPI 3.0 document. Each aggregate has a channel of events it sends and a channel of commands it receives. Older versions of an event are under the message’s x-versions, and its personal fields under x-personal-fields.

readonly Any[]

DocumentOptions

AsyncApiDocument


events(aggregate): readonly EventEntry[]

Defined in: src/EventCatalog.ts:75

The JSON Schema of every event of an aggregate, in every version it declares.

Any

readonly EventEntry[]


readSamples(path): Effect<readonly object[], PlatformError | SchemaError, FileSystem>

Defined in: src/EventCatalog.ts:311

Reads samples written by saveSamples.

string

Effect<readonly object[], PlatformError | SchemaError, FileSystem>


saveSamples(path, samples): Effect<object[], PlatformError | SchemaError, FileSystem>

Defined in: src/EventCatalog.ts:322

Adds samples to a JSON file, creating it if needed. Samples of an event type and version already in the file are left as they are, so the file keeps the shapes the store held over time, also after those events are gone from it.

string

readonly object[]

Effect<object[], PlatformError | SchemaError, FileSystem>