Skip to content

Metadata: what a command carries beside its payload that the domain doesn’t decide on, such as the version of the software that ran it, the user who sent it or the address it came from. It is a JSON object recorded on every event the command writes, and projections, view models and history can read it.

Like Causation, it travels in the fiber’s context rather than in payloads. A command records, key by key, from the lowest precedence:

  1. the metadata where its aggregate service was built, such as the software version provided once for the whole application with layer;
  2. the metadata where it runs, added with withMetadata;
  3. the metadata of a dispatch envelope.

A view model or saga reacting to an event doesn’t inherit that event’s metadata: its commands record their own. The causationId leads back to the event, and from there to its metadata.

Metadata = Schema.JsonObject

Defined in: src/Metadata.ts:24

A JSON object.

const CurrentMetadata: Reference<JsonObject>

Defined in: src/Metadata.ts:29

The metadata commands run in this fiber record, {} outside any.


Metadata: Codec<JsonObject, JsonObject, never, never>

Defined in: src/Metadata.ts:24


const withMetadata: {(metadata): <A, E, R>(effect) => Effect<A, E, R>; <A, E, R>(effect, metadata): Effect<A, E, R>; }

Defined in: src/Metadata.ts:34

Runs an effect whose commands record this metadata on top of the current one.

(metadata): <A, E, R>(effect) => Effect<A, E, R>

JsonObject

<A, E, R>(effect) => Effect<A, E, R>

<A, E, R>(effect, metadata): Effect<A, E, R>

A

E

R

Effect<A, E, R>

JsonObject

Effect<A, E, R>

layer(metadata): Layer<never>

Defined in: src/Metadata.ts:54

Provides metadata to everything built on top of this layer, for values that hold for the whole process such as the software version:

AppLayer.pipe(Layer.provide(Metadata.layer({ appVersion: "1.4.0" })))

Aggregate services remember it, so it is recorded even by commands run where the layer isn’t visible.

JsonObject

Layer<never>