types

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package types defines core interfaces and types for the sync kit.

It includes interfaces for Event, Version, Store, and Transport—the fundamental abstractions used throughout the framework.

See also:

Package types: interface surface for synckit implementors.

This file centralizes the stable EventStore and Transport interfaces so that implementors can depend on a single location without import cycles.

Implementors: add compile-time checks in your packages:

var _ types.EventStore = (*MyStore)(nil)
var _ types.Transport = (*MyTransport)(nil)

Package types contains shared types used across the synckit ecosystem. This package exists to prevent import cycles between synckit and its subpackages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conflict added in v0.18.0

type Conflict struct {
	EventType     string
	AggregateID   string
	ChangedFields []string
	Metadata      map[string]interface{}

	Local  EventWithVersion
	Remote EventWithVersion
}

Conflict carries the context needed to resolve a detected conflict between local and remote changes. Domain-agnostic by design.

type ConflictResolver added in v0.18.0

type ConflictResolver interface {
	Resolve(ctx context.Context, c Conflict) (ResolvedConflict, error)
}

ConflictResolver is the Strategy interface for conflict resolution.

type Event

type Event interface {
	// ID returns a unique identifier for this event
	ID() string

	// Type returns the event type (e.g., "UserCreated", "OrderUpdated")
	Type() string

	// AggregateID returns the ID of the aggregate this event belongs to
	AggregateID() string

	// Data returns the event payload
	Data() interface{}

	// Metadata returns additional event metadata
	Metadata() map[string]interface{}
}

Event represents a syncable event in the system.

type EventHandler added in v0.23.0

type EventHandler = func([]EventWithVersion) error

EventHandler handles batches of events delivered by a Transport subscription. It is an alias for the function type used by Subscribe and kept here to allow documentation and consistent type naming without changing the method signature.

type EventStore added in v0.23.0

type EventStore interface {
	// Store persists an event with the provided version (version may be ignored
	// by implementations that auto-generate versions, but must not fail).
	Store(ctx context.Context, event Event, version Version) error

	// Load retrieves all events strictly after the provided version.
	// Optional filters can be provided for type, tenant, aggregate_id, etc.
	// Variadic filters parameter is backward compatible - existing calls work unchanged.
	Load(ctx context.Context, since Version, filters ...Filter) ([]EventWithVersion, error)

	// LoadByAggregate retrieves events for a specific aggregate after the version.
	// Optional filters can be provided for type, tenant, etc.
	// Variadic filters parameter is backward compatible - existing calls work unchanged.
	LoadByAggregate(ctx context.Context, aggregateID string, since Version, filters ...Filter) ([]EventWithVersion, error)

	// LatestVersion returns the latest version in the store.
	LatestVersion(ctx context.Context) (Version, error)

	// ParseVersion converts a string representation into a Version implementation.
	ParseVersion(ctx context.Context, versionStr string) (Version, error)

	// Close releases resources.
	Close() error
}

EventStore provides persistence for events.

Implementors should document version encoding/decoding behavior and ensure: - LatestVersion returns a valid non-zero version when events exist - ParseVersion accepts serialized forms used by transports/APIs - All methods are context-aware and cancel promptly

Implementors:

var _ EventStore = (*MyStore)(nil)

type EventWithVersion

type EventWithVersion struct {
	Event   Event
	Version Version
}

EventWithVersion pairs an event with its version information.

type Filter added in v0.23.0

type Filter struct{ Key, Value string }

Filter is an intentionally simple key/value pair used for forward-compatible filtering across Store/Transport operations. Implementations may choose to support a subset (e.g., tenant, type, tag).

Common filter keys:

  • "type": Filter by event type
  • "tenant": Filter by tenant ID (from metadata)
  • "aggregate_id": Filter by aggregate ID

type ResolvedConflict added in v0.18.0

type ResolvedConflict struct {
	ResolvedEvents []EventWithVersion
	Decision       string
	Reasons        []string
}

ResolvedConflict captures the decision and any follow-up data.

type Transport added in v0.23.0

type Transport interface {
	// Push sends a batch of events to the remote endpoint.
	Push(ctx context.Context, events []EventWithVersion) error

	// Pull retrieves events from the remote endpoint strictly after the version.
	Pull(ctx context.Context, since Version) ([]EventWithVersion, error)

	// GetLatestVersion efficiently retrieves the latest remote version without pulling events.
	GetLatestVersion(ctx context.Context) (Version, error)

	// Subscribe listens for real-time updates. Implementations may be streaming
	// or event-based callbacks. Handler should be invoked with batches.
	Subscribe(ctx context.Context, handler EventHandler) error

	// Close closes the transport connection and releases resources.
	Close() error
}

Transport handles communication with a remote endpoint.

Implementors should document ordering, delivery guarantees, and any authorization/error semantics.

Implementors:

var _ Transport = (*MyTransport)(nil)

type Version

type Version interface {
	// Compare returns -1 if this version is before other, 0 if equal, 1 if after
	Compare(other Version) int

	// String returns a string representation of the version
	String() string

	// IsZero returns true if this is the zero/initial version
	IsZero() bool
}

Version represents a point-in-time snapshot for sync operations. Users can implement different versioning strategies (timestamps, hashes, vector clocks).

Jump to

Keyboard shortcuts

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