events

package
v0.0.0-...-4422134 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type         EventType      `json:"type"`
	InstanceID   string         `json:"instanceID"`
	Source       EventSource    `json:"source"` // Where this event originated
	Timestamp    time.Time      `json:"timestamp"`
	Collection   string         `json:"collection"`
	RecordID     string         `json:"recordID,omitempty"`
	RecordData   map[string]any `json:"recordData,omitempty"`   // For create/update
	SchemaData   map[string]any `json:"schemaData,omitempty"`   // For collection create/update
	RealtimeData map[string]any `json:"realtimeData,omitempty"` // For realtime events (resourceID, etc.)
}

Event represents a database change event

func NewCollectionCreateEvent

func NewCollectionCreateEvent(instanceID string, collectionName string, schemaData map[string]any) *Event

NewCollectionCreateEvent creates a new collection creation event

func NewCollectionDeleteEvent

func NewCollectionDeleteEvent(instanceID string, collectionName string) *Event

NewCollectionDeleteEvent creates a new collection deletion event

func NewCollectionUpdateEvent

func NewCollectionUpdateEvent(instanceID string, collectionName string, schemaData map[string]any) *Event

NewCollectionUpdateEvent creates a new collection update event

func NewCreateEvent

func NewCreateEvent(instanceID string, collection string, recordID string, recordData map[string]any) *Event

NewCreateEvent creates a new record creation event

func NewDeleteEvent

func NewDeleteEvent(instanceID string, collection string, recordID string) *Event

NewDeleteEvent creates a new record deletion event

func NewRealtimeHeartbeatEvent

func NewRealtimeHeartbeatEvent(instanceID string, resourceID string, activeConnections int, leaseExpires time.Time) *Event

NewRealtimeHeartbeatEvent creates a new realtime heartbeat event

func NewRealtimeSubscribeEvent

func NewRealtimeSubscribeEvent(instanceID string, resourceID string, activeConnections int, leaseExpires time.Time) *Event

NewRealtimeSubscribeEvent creates a new realtime subscription event

func NewRealtimeUnsubscribeEvent

func NewRealtimeUnsubscribeEvent(instanceID string, resourceID string) *Event

NewRealtimeUnsubscribeEvent creates a new realtime unsubscription event

func NewRepublishedEvent

func NewRepublishedEvent(originalEvent *Event) *Event

NewRepublishedEvent creates a republished version of an existing event

func NewUpdateEvent

func NewUpdateEvent(instanceID string, collection string, recordID string, recordData map[string]any) *Event

NewUpdateEvent creates a new record update event

func (*Event) MarkAsRemote

func (e *Event) MarkAsRemote() *Event

MarkAsRemote marks an event as coming from a remote instance

func (*Event) Marshal

func (e *Event) Marshal() ([]byte, error)

Marshal serializes the event to JSON

func (*Event) Unmarshal

func (e *Event) Unmarshal(data []byte) error

Unmarshal deserializes the event from JSON

type EventSource

type EventSource string

EventSource represents where the event originated

const (
	EventSourceLocal       EventSource = "local"       // Event originated from this instance
	EventSourceRemote      EventSource = "remote"      // Event originated from another instance
	EventSourceRepublished EventSource = "republished" // Event is being republished by this instance
)

type EventType

type EventType string

EventType represents the type of database operation

const (
	EventTypeCreate              EventType = "create"
	EventTypeUpdate              EventType = "update"
	EventTypeDelete              EventType = "delete"
	EventTypeCollectionCreate    EventType = "collection_create"
	EventTypeCollectionUpdate    EventType = "collection_update"
	EventTypeCollectionDelete    EventType = "collection_delete"
	EventTypeRealtimeSubscribe   EventType = "realtime_subscribe"
	EventTypeRealtimeUnsubscribe EventType = "realtime_unsubscribe"
	EventTypeRealtimeHeartbeat   EventType = "realtime_heartbeat"
)

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor handles processing incoming events and applying changes

func NewProcessor

func NewProcessor(app *pocketsync.PocketBase, instanceID string) *Processor

NewProcessor creates a new event processor

func (*Processor) ApplyEvent

func (p *Processor) ApplyEvent(event *Event) error

ApplyEvent applies an event to the local PocketBase instance using the SDK This is a public method that can be called directly to avoid recursion in handlers

func (*Processor) Process

func (p *Processor) Process(event *Event) error

Process processes an incoming event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL