[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/flow](../../README) / [index](../README) / Synth

# Interface: Synth\<T\>

Defined in: [flow/src/synths/index.ts:26](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/synths/index.ts#L26)

A synthesizer ("synth") teaches flow how to send a non-JSON type across the
wire: it matches a live value, dehydrates it to a JSON-safe primitive plus
metadata for the snapshot, and hydrates it back on the other side.

## Remarks

This is the extension point behind first-class support for `Date`, `Carbon`,
ORM models, collections, and [TemporaryUploadedFile](../classes/TemporaryUploadedFile). During
serialization the registry tries each synth's [match](#match) in order; the first
match's [dehydrate](#dehydrate) produces the stored data and its [key](#key) is
written to `meta.s`. On the way back, [key](#key) selects the synth whose
[hydrate](#hydrate) reconstructs the value. `hydrate` may be async (e.g. a model
synth re-fetches by id). The pattern is lifted from Livewire v3's synthesizers.

## Type Parameters

### T

`T` = `unknown`

The live value type this synth handles.

## Properties

### key

> **key**: `string`

Defined in: [flow/src/synths/index.ts:28](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/synths/index.ts#L28)

Short tag stored as `meta.s` in the snapshot, e.g. `'cbn'`, `'mdl'`.

## Methods

### match()

> **match**(`value`): `value is T`

Defined in: [flow/src/synths/index.ts:30](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/synths/index.ts#L30)

Type guard: whether this synth handles `value` (checked in registration order).

#### Parameters

##### value

`unknown`

#### Returns

`value is T`

***

### dehydrate()

> **dehydrate**(`value`, `meta`): `unknown`

Defined in: [flow/src/synths/index.ts:32](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/synths/index.ts#L32)

Serialize `value` to a JSON-safe form; may mutate `meta` to stash extra fields for hydrate.

#### Parameters

##### value

`T`

##### meta

`Record`\<`string`, `unknown`\>

#### Returns

`unknown`

***

### hydrate()

> **hydrate**(`data`, `meta`): `T` \| `Promise`\<`T`\>

Defined in: [flow/src/synths/index.ts:34](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/flow/src/synths/index.ts#L34)

Reconstruct the live value from serialized `data` and its `meta` (may be async).

#### Parameters

##### data

`unknown`

##### meta

`Record`\<`string`, `unknown`\>

#### Returns

`T` \| `Promise`\<`T`\>
