Codec
How log values become stored bytes and back. A payload is encoded in the binary format
SchemaBinary.toCodec derives from its schema, makeForSchema, or as the UTF-8 bytes of its JSON,
makeJsonForSchema, for a schema the binary format cannot lay out; either is a persistence
contract: stored bytes must stay readable when dependencies change. An ordinary log stores its
whole value through makeEntryCodec; a log whose entries carry a name or subject beside the
payload, which storage indexes, gives Log.open an entry codec of its own.
Since v0.2.0
Constructors
Section titled “Constructors”makeEntryCodec
Section titled “makeEntryCodec”The entry codec of an ordinary log: the whole value is the payload, encoded with payload,
makeForSchema(schema) unless given, and an entry has neither name nor subject. Decoding an
entry that has either fails, so a log whose entries carry them is never misread through this
codec.
Signature
declare const makeEntryCodec: <S extends Schema.Constraint>(schema: S, payload?: PayloadCodec<S>) => EntryCodec<S>Since v0.2.0
makeForSchema
Section titled “makeForSchema”The binary payload codec of payload, from SchemaBinary.toCodec, keeping the services the
schema needs to encode and decode. Encoding returns a copy, so stored bytes never share the
encoder’s buffer.
Signature
declare const makeForSchema: <S extends Schema.Constraint>(payload: S) => PayloadCodec<S>Since v0.2.0
makeJsonForSchema
Section titled “makeJsonForSchema”Encodes one schema’s values as the UTF-8 bytes of their JSON, through Schema.toCodecJson: for a
schema the binary format cannot lay out, such as a union whose members it cannot tell apart, as
many of Effect AI’s are. Decoding checks the JSON against the schema.
Signature
declare const makeJsonForSchema: <S extends Schema.Constraint>(payload: S) => PayloadCodec<S>Since v0.2.0
Models
Section titled “Models”EntryCodec (interface)
Section titled “EntryCodec (interface)”How one log’s values map to the Store.Content storage keeps, and back, with the services its
schema needs to encode and decode. Log.open takes one, and defaults to makeEntryCodec.
Signature
export interface EntryCodec<S extends Schema.Constraint> { readonly encode: (value: S["Type"]) => Effect.Effect<Store.Content, Schema.SchemaError, S["EncodingServices"]> readonly decode: (entry: Store.Content) => Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"]>}Since v0.2.0
PayloadCodec (interface)
Section titled “PayloadCodec (interface)”Encodes one schema’s values to bytes and decodes them back, in the binary format every log’s payloads share.
Signature
export interface PayloadCodec<S extends Schema.Constraint> { /** Produces an independently owned byte buffer for storage. */ readonly encode: ( payload: S["Type"] ) => Effect.Effect<Uint8Array<ArrayBuffer>, Schema.SchemaError, S["EncodingServices"]> /** Validates stored bytes and reconstructs the decoded value. */ readonly decode: (bytes: Uint8Array) => Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"]>}Since v0.2.0