# Metadata

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](https://effect-cqrs.dambox.ch/reference/api/metadata/#layer);
2. the metadata where it runs, added with [withMetadata](https://effect-cqrs.dambox.ch/reference/api/metadata/#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.

## Type Aliases

### Metadata

> **Metadata** = `Schema.JsonObject`

Defined in: [src/Metadata.ts:24](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Metadata.ts#L24)

A JSON object.

## Variables

### CurrentMetadata

> `const` **CurrentMetadata**: `Reference`<`JsonObject`>

Defined in: [src/Metadata.ts:29](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Metadata.ts#L29)

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

***

### Metadata

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

Defined in: [src/Metadata.ts:24](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Metadata.ts#L24)

***

### withMetadata

> `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](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Metadata.ts#L34)

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

#### Call Signature

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

##### Parameters

###### metadata

`JsonObject`

##### Returns

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

#### Call Signature

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

##### Type Parameters

###### A

`A`

###### E

`E`

###### R

`R`

##### Parameters

###### effect

`Effect`<`A`, `E`, `R`>

###### metadata

`JsonObject`

##### Returns

`Effect`<`A`, `E`, `R`>

## Functions

### layer()

> **layer**(`metadata`): `Layer`<`never`>

Defined in: [src/Metadata.ts:54](https://github.com/davidnussio/effect-cqrs/blob/9d66af7141782f3f89655e6868abe3f141c97632/src/Metadata.ts#L54)

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

```ts
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.

#### Parameters

##### metadata

`JsonObject`

#### Returns

`Layer`<`never`>
