EventCatalog
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.
Classes
Section titled “Classes”IncompatibleSamples
Section titled “IncompatibleSamples”Defined in: src/EventCatalog.ts:230
Extends
Section titled “Extends”object&YieldableError<this>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new IncompatibleSamples(…
args):IncompatibleSamples
Defined in: node_modules/.pnpm/effect@4.0.6/node_modules/effect/dist/Schema.d.ts:10979
Parameters
Section titled “Parameters”…[props: object, options?: MakeOptions]
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).constructor
Properties
Section titled “Properties”aggregateName
Section titled “aggregateName”
readonlyaggregateName:string=Schema.String
Defined in: src/EventCatalog.ts:231
Inherited from
Section titled “Inherited from”Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).aggregateName
failures
Section titled “failures”
readonlyfailures: readonlyobject[]
Defined in: src/EventCatalog.ts:232
Inherited from
Section titled “Inherited from”Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).failures
Accessors
Section titled “Accessors”message
Section titled “message”Get Signature
Section titled “Get Signature”get message():
string
Defined in: src/EventCatalog.ts:238
Returns
Section titled “Returns”string
Overrides
Section titled “Overrides”Schema.TaggedError<IncompatibleSamples>()("IncompatibleSamples", { aggregateName: Schema.String, failures: Schema.Array(Schema.Struct({ type: Schema.String, schemaVersion: Schema.Int, message: Schema.String })) }).message
Interfaces
Section titled “Interfaces”AsyncApiDocument
Section titled “AsyncApiDocument”Defined in: src/EventCatalog.ts:106
An AsyncAPI 3.0 document, with JSON Schema draft-07 payloads as AsyncAPI expects.
Properties
Section titled “Properties”asyncapi
Section titled “asyncapi”
readonlyasyncapi:"3.0.0"
Defined in: src/EventCatalog.ts:107
channels
Section titled “channels”
readonlychannels:Record<string,unknown>
Defined in: src/EventCatalog.ts:109
components
Section titled “components”
readonlycomponents:object
Defined in: src/EventCatalog.ts:111
messages
Section titled “messages”
readonlymessages:Record<string,unknown>
schemas
Section titled “schemas”
readonlyschemas:Record<string,JsonSchema.JsonSchema>
readonlyinfo:object
Defined in: src/EventCatalog.ts:108
description?
Section titled “description?”
readonlyoptionaldescription?:string
readonlytitle:string
version
Section titled “version”
readonlyversion:string
operations
Section titled “operations”
readonlyoperations:Record<string,unknown>
Defined in: src/EventCatalog.ts:110
CommandEntry
Section titled “CommandEntry”Defined in: src/EventCatalog.ts:47
Properties
Section titled “Properties”aggregate
Section titled “aggregate”
readonlyaggregate:string
Defined in: src/EventCatalog.ts:48
readonlyname:string
Defined in: src/EventCatalog.ts:49
payload
Section titled “payload”
readonlypayload:JsonSchema
Defined in: src/EventCatalog.ts:51
A JSON Schema draft 2020-12 of the payload.
DocumentOptions
Section titled “DocumentOptions”Defined in: src/EventCatalog.ts:99
Properties
Section titled “Properties”description?
Section titled “description?”
readonlyoptionaldescription?:string
Defined in: src/EventCatalog.ts:102
readonlytitle:string
Defined in: src/EventCatalog.ts:100
version
Section titled “version”
readonlyversion:string
Defined in: src/EventCatalog.ts:101
EventEntry
Section titled “EventEntry”Defined in: src/EventCatalog.ts:36
Properties
Section titled “Properties”aggregate
Section titled “aggregate”
readonlyaggregate:string
Defined in: src/EventCatalog.ts:37
personalFields
Section titled “personalFields”
readonlypersonalFields: readonlystring[]
Defined in: src/EventCatalog.ts:44
Paths of the personal fields in the current version, encrypted in the store.
schemaVersion
Section titled “schemaVersion”
readonlyschemaVersion:number
Defined in: src/EventCatalog.ts:40
The version new events are written in, the last of versions.
readonlytype:string
Defined in: src/EventCatalog.ts:38
versions
Section titled “versions”
readonlyversions: readonlyEventVersion[]
Defined in: src/EventCatalog.ts:42
Oldest first. Events written before versions were declared are version 1.
EventVersion
Section titled “EventVersion”Defined in: src/EventCatalog.ts:30
Properties
Section titled “Properties”schema
Section titled “schema”
readonlyschema:JsonSchema
Defined in: src/EventCatalog.ts:33
A JSON Schema draft 2020-12 of the payload in this version.
schemaVersion
Section titled “schemaVersion”
readonlyschemaVersion:number
Defined in: src/EventCatalog.ts:31
Type Aliases
Section titled “Type Aliases”Sample
Section titled “Sample”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.
Variables
Section titled “Variables”Sample
Section titled “Sample”
constSample: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.
Functions
Section titled “Functions”captureSamples()
Section titled “captureSamples()”captureSamples(
aggregates,options?):Effect<readonlyobject[],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.
Parameters
Section titled “Parameters”aggregates
Section titled “aggregates”readonly Any[]
options?
Section titled “options?”perVersion?
Section titled “perVersion?”number
Returns
Section titled “Returns”Effect<readonly object[], EventStoreError, EventStore>
checkCompatibility()
Section titled “checkCompatibility()”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.
Parameters
Section titled “Parameters”aggregate
Section titled “aggregate”samples
Section titled “samples”readonly object[]
Returns
Section titled “Returns”Effect<number, IncompatibleSamples>
commands()
Section titled “commands()”commands(
aggregate): readonlyCommandEntry[]
Defined in: src/EventCatalog.ts:88
The JSON Schema of the payload of every command of an aggregate.
Parameters
Section titled “Parameters”aggregate
Section titled “aggregate”Returns
Section titled “Returns”readonly CommandEntry[]
document()
Section titled “document()”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.
Parameters
Section titled “Parameters”aggregates
Section titled “aggregates”readonly Any[]
options
Section titled “options”Returns
Section titled “Returns”events()
Section titled “events()”events(
aggregate): readonlyEventEntry[]
Defined in: src/EventCatalog.ts:75
The JSON Schema of every event of an aggregate, in every version it declares.
Parameters
Section titled “Parameters”aggregate
Section titled “aggregate”Returns
Section titled “Returns”readonly EventEntry[]
readSamples()
Section titled “readSamples()”readSamples(
path):Effect<readonlyobject[],PlatformError|SchemaError,FileSystem>
Defined in: src/EventCatalog.ts:311
Reads samples written by saveSamples.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Effect<readonly object[], PlatformError | SchemaError, FileSystem>
saveSamples()
Section titled “saveSamples()”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.
Parameters
Section titled “Parameters”string
samples
Section titled “samples”readonly object[]
Returns
Section titled “Returns”Effect<object[], PlatformError | SchemaError, FileSystem>