serializerCodec
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
serializerCodec<
T>(serializer,name?):Codec<T>
Defined in: src/persistence/migration/Codec.ts:166
Adapt a byte-native Serializer into a Codec<T> (#73), so a binary
format reaches the migration layer at the granularity the migration
layer actually works at.
Why this exists next to withSerializer. A store’s serializer
option applies to the whole store — one format for every payload it
writes. The SchemaRegistry holds a codec per (manifest, version),
which is the only place a v1 written in Avro and a v2 written in
Protobuf can coexist in one stream. Wrapping the serializer keeps a
single implementation of each format instead of one Serializer plus a
near-identical Codec:
registry.register('BankAccount.Deposited', 1, { codec: serializerCodec(avroSerializer),});registry.register('BankAccount.Deposited', 2, { codec: serializerCodec(protobufSerializer), upcastFromPrev: (v1: DepositedV1): DepositedV2 => ({ ...v1, currency: 'USD' }),});Wire shape. encode returns a SerializedValue — {serializerId, manifest, bytes} — and stops there. The bytes are NOT base64’d here:
the journal’s PayloadCodec already round-trips a Uint8Array through
the tagged-JSON __bytes__ form, so encoding them again would cost a
second base64 expansion for nothing. serializerId travels with the
payload so a row written by one serializer and read back by another
fails with a named error instead of decoding into garbage — Avro in
particular carries no field tags, so wrong bytes decode “successfully”.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”serializer
Section titled “serializer”Serializer<T>
string
Returns
Section titled “Returns”Codec<T>
