Skip to content

EventDef

EventDef<TName, TType, TEncoded, TDerived> = object

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:30

Core type representing an event definition in LiveStore.

An EventDef defines the structure and behavior of an event type, including:

  • A unique name identifying the event type (conventionally versioned, e.g., v1.TodoCreated)
  • A schema for validating and encoding/decoding event arguments
  • Options controlling sync behavior and constraints

EventDefs are callable - invoking them creates a partial event object suitable for store.commit().

import { Events } from '@livestore/livestore'
import { Schema } from 'effect'
const todoCreated = Events.synced({
name: 'v1.TodoCreated',
schema: Schema.Struct({
id: Schema.String,
text: Schema.String,
}),
})
// Use the EventDef as a constructor
store.commit(todoCreated({ id: 'abc', text: 'Buy milk' }))

TName extends string

TType

TEncoded = TType

TDerived extends boolean = false

EventDef(args): object

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:53

Callable signature - creates a partial event with decoded arguments. The returned object can be passed directly to store.commit().

TType

object

args: TType

name: TName

encoded: (args) => object

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:61

Creates a partial event with pre-encoded arguments. Useful when working with already-serialized data.

TEncoded

object

args: TEncoded

name: TName


readonly Event: object

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:66

Type helper for accessing the event’s shape with name and decoded args.

args: TType

name: TName


name: TName

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:32

Unique identifier for this event type. Conventionally versioned (e.g., v1.TodoCreated).


options: object

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:35

clientOnly: boolean

When true, the event is only synced within the same client’s sessions (e.g., across tabs) but never sent to the sync backend. Useful for UI state like selected items or filters.

derived: TDerived

Whether this is a derived event. Derived events cannot have materializers.

facts: FactsCallback<TType> | undefined

Callback defining fact constraints for this event. This feature is not fully implemented yet.


schema: Schema.Schema<TType, TEncoded>

Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:34

Effect Schema used for validating and encoding/decoding event arguments.