Documentation / @zerotal/flow / index / Synth
Interface: Synth<T>
Defined in: flow/src/synths/index.ts:26
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. During
serialization the registry tries each synth's match in order; the first
match's dehydrate produces the stored data and its key is
written to meta.s. On the way back, key selects the synth whose
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
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
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
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
Reconstruct the live value from serialized data and its meta (may be async).
Parameters
data
unknown
meta
Record<string, unknown>
Returns
T | Promise<T>