Versions in this module Expand all Collapse all v0 v0.1.2 Mar 15, 2026 v0.1.1 Mar 15, 2026 Changes in this version + const DefaultKindNone + const DefaultKindPortable + const DefaultKindServerOnly + const DefaultPullLimit + const DefaultSnapshotLimit + const MaxPullLimit + const MaxSnapshotLimit + const PushStatusApplied + const PushStatusConflict + const PushStatusRejectedRetryable + const PushStatusRejectedTerminal + const SnapshotReasonCheckpointBeforeLimit + const SnapshotReasonHistoryUnavailable + const SnapshotReasonInitialSyncRequired + var ErrClientNotRegistered = errors.New("synchro: client not registered") + var ErrConflict = errors.New("synchro: conflict") + var ErrCycleDetected = errors.New("synchro: cycle detected in parent chain") + var ErrInvalidBucketConfig = errors.New("synchro: invalid bucket configuration") + var ErrInvalidOperation = errors.New("synchro: invalid operation") + var ErrInvalidPushPolicy = errors.New("synchro: invalid push policy") + var ErrMissingOwnership = errors.New("synchro: pushable table has no ownership path") + var ErrMissingParentFKCol = errors.New("synchro: ParentTable set without ParentFKCol") + var ErrOrphanedChain = errors.New("synchro: orphaned parent chain") + var ErrOwnershipViolation = errors.New("synchro: ownership violation") + var ErrRecordNotFound = errors.New("synchro: record not found") + var ErrRedundantProtected = errors.New("synchro: redundant protected column") + var ErrSchemaMismatch = errors.New("synchro: schema mismatch") + var ErrSnapshotRequired = errors.New("synchro: snapshot required") + var ErrStaleClient = errors.New("synchro: stale client") + var ErrTableNotRegistered = errors.New("synchro: table not registered") + var ErrTableReadOnly = errors.New("synchro: table is read-only") + var ErrUnregisteredParent = errors.New("synchro: unregistered parent table") + var ErrUnsupportedSchemaFeature = errors.New("synchro: unsupported schema feature") + var ErrUpgradeRequired = errors.New("synchro: client upgrade required") + func CheckVersion(clientVersion, minVersion string) error + func GenerateRLSPolicies(registry *Registry) []string + func SetAuthContext(ctx context.Context, tx DB, userID string) error + type AcceptedRecord struct + ID string + Operation Operation + TableName string + type BucketUpdate struct + Added []string + Removed []string + type ChangelogEntry struct + BucketID string + CreatedAt time.Time + Operation Operation + RecordID string + Seq int64 + TableName string + type Client struct + AppVersion string + BucketSubs []string + ClientID string + ClientName *string + CreatedAt time.Time + ID string + IsActive bool + LastPullAt *time.Time + LastPullSeq *int64 + LastPushAt *time.Time + LastSyncAt *time.Time + Platform string + UpdatedAt time.Time + UserID string + type CompactResult struct + DeactivatedClients int64 + DeletedEntries int64 + SafeSeq int64 + type Compactor struct + func NewCompactor(cfg *CompactorConfig) *Compactor + func (c *Compactor) Compact(ctx context.Context, db DB, safeSeq int64) (int64, error) + func (c *Compactor) DeactivateStaleClients(ctx context.Context, db DB) (int64, error) + func (c *Compactor) RunCompaction(ctx context.Context, db DB) (CompactResult, error) + func (c *Compactor) SafeSeq(ctx context.Context, db DB) (int64, error) + type CompactorConfig struct + BatchSize int + Logger *slog.Logger + StaleThreshold time.Duration + type Config struct + ClockSkewTolerance time.Duration + Compactor *CompactorConfig + ConflictResolver ConflictResolver + DB *sql.DB + Hooks Hooks + Logger *slog.Logger + MinClientVersion string + Ownership OwnershipResolver + Registry *Registry + type Conflict struct + BaseVersion *time.Time + ClientData json.RawMessage + ClientID string + ClientTime time.Time + RecordID string + ServerData json.RawMessage + ServerTime time.Time + Table string + UserID string + type ConflictResolver interface + Resolve func(ctx context.Context, conflict Conflict) (Resolution, error) + type DB interface + ExecContext func(ctx context.Context, query string, args ...any) (sql.Result, error) + QueryContext func(ctx context.Context, query string, args ...any) (*sql.Rows, error) + QueryRowContext func(ctx context.Context, query string, args ...any) *sql.Row + type DeleteEntry struct + ID string + TableName string + type Engine struct + func NewEngine(cfg Config) (*Engine, error) + func (e *Engine) CurrentSchemaManifest(ctx context.Context) (int64, string, error) + func (e *Engine) Pull(ctx context.Context, userID string, req *PullRequest) (*PullResponse, error) + func (e *Engine) Push(ctx context.Context, userID string, req *PushRequest) (*PushResponse, error) + func (e *Engine) RegisterClient(ctx context.Context, userID string, req *RegisterRequest) (*RegisterResponse, error) + func (e *Engine) Registry() *Registry + func (e *Engine) RunCompaction(ctx context.Context) (CompactResult, error) + func (e *Engine) Schema(ctx context.Context) (*SchemaResponse, error) + func (e *Engine) SchemaManifestHistory(ctx context.Context, limit int) ([]SchemaManifestEntry, error) + func (e *Engine) Snapshot(ctx context.Context, userID string, req *SnapshotRequest) (*SnapshotResponse, error) + func (e *Engine) StartCompaction(ctx context.Context, interval time.Duration) + func (e *Engine) TableMetadata(ctx context.Context) (*TableMetaResponse, error) + type Hooks struct + OnCompaction func(ctx context.Context, result CompactResult) + OnConflict func(ctx context.Context, conflict Conflict, resolution Resolution) + OnPullComplete func(ctx context.Context, clientID string, checkpoint int64, count int) + OnPushAccepted func(ctx context.Context, tx *sql.Tx, accepted []AcceptedRecord) error + OnSchemaIncompatible func(ctx context.Context, clientID string, clientVer string, minVer string) + OnSnapshotRequired func(ctx context.Context, clientID string, checkpoint int64, minSeq int64, ...) + OnStaleClient func(ctx context.Context, clientID string, lastSync time.Time) bool + type JoinResolver struct + func NewJoinResolver(registry *Registry) *JoinResolver + func NewJoinResolverWithDB(registry *Registry, db DB) *JoinResolver + func (r *JoinResolver) AssignBuckets(ctx context.Context, table string, recordID string, _ Operation, ...) ([]string, error) + func (r *JoinResolver) ResolveOwner(ctx context.Context, db DB, table string, recordID string, data map[string]any) ([]string, error) + type LWWResolver struct + ClockSkewTolerance time.Duration + func (r *LWWResolver) Resolve(_ context.Context, c Conflict) (Resolution, error) + type Operation int + const OpDelete + const OpInsert + const OpUpdate + func ParseOperation(s string) (Operation, bool) + func (o Operation) String() string + type OwnershipResolver interface + ResolveOwner func(ctx context.Context, db DB, table string, recordID string, data map[string]any) ([]string, error) + type PullRequest struct + Checkpoint int64 + ClientID string + KnownBuckets []string + Limit int + SchemaHash string + SchemaVersion int64 + Tables []string + type PullResponse struct + BucketUpdates *BucketUpdate + Changes []Record + Checkpoint int64 + Deletes []DeleteEntry + HasMore bool + SchemaHash string + SchemaVersion int64 + SnapshotReason string + SnapshotRequired bool + type PushPolicy string + const PushPolicyDisabled + const PushPolicyOwnerOnly + type PushRecord struct + BaseUpdatedAt *time.Time + ClientUpdatedAt time.Time + Data json.RawMessage + ID string + Operation string + TableName string + type PushRequest struct + Changes []PushRecord + ClientID string + SchemaHash string + SchemaVersion int64 + type PushResponse struct + Accepted []PushResult + Checkpoint int64 + Rejected []PushResult + SchemaHash string + SchemaVersion int64 + ServerTime time.Time + type PushResult struct + ID string + Message string + Operation string + ReasonCode string + ServerDeletedAt *time.Time + ServerUpdatedAt *time.Time + ServerVersion *Record + Status string + TableName string + type Record struct + Data json.RawMessage + DeletedAt *time.Time + ID string + TableName string + UpdatedAt time.Time + type RegisterRequest struct + AppVersion string + ClientID string + ClientName *string + Platform string + SchemaHash string + SchemaVersion int64 + type RegisterResponse struct + Checkpoint int64 + ID string + LastSyncAt *time.Time + SchemaHash string + SchemaVersion int64 + ServerTime time.Time + type Registry struct + func NewRegistry() *Registry + func (r *Registry) All() []*TableConfig + func (r *Registry) Get(name string) *TableConfig + func (r *Registry) IsPushable(tableName string) bool + func (r *Registry) IsRegistered(tableName string) bool + func (r *Registry) Register(cfg *TableConfig) + func (r *Registry) TableNames() []string + func (r *Registry) Validate() error + type Resolution struct + Reason string + Winner string + type SQLBucketResolver struct + func NewSQLBucketResolver(cfg SQLBucketResolverConfig) (*SQLBucketResolver, error) + func (r *SQLBucketResolver) AssignBuckets(ctx context.Context, table string, recordID string, operation Operation, ...) ([]string, error) + type SQLBucketResolverConfig struct + DB DB + EnableGoFallback bool + GlobalFunction string + GoFallback OwnershipResolver + Logger *slog.Logger + MaxBucketsPerEvent int + Registry *Registry + type SchemaColumn struct + DBType string + DefaultKind string + DefaultSQL string + IsPrimaryKey bool + LogicalType string + Name string + Nullable bool + SQLiteDefaultSQL string + type SchemaManifestEntry struct + CreatedAt time.Time + SchemaHash string + SchemaVersion int64 + type SchemaResponse struct + SchemaHash string + SchemaVersion int64 + ServerTime time.Time + Tables []SchemaTable + type SchemaTable struct + AllowGlobalRead bool + BucketByColumn string + BucketFunction string + BucketPrefix string + Columns []SchemaColumn + DeletedAtColumn string + Dependencies []string + GlobalWhenBucketNull bool + ParentFKCol string + ParentTable string + PrimaryKey []string + PushPolicy string + TableName string + UpdatedAtColumn string + type ServerWinsResolver struct + func (r *ServerWinsResolver) Resolve(_ context.Context, _ Conflict) (Resolution, error) + type SnapshotCursor struct + AfterID string + Checkpoint int64 + TableIndex int + type SnapshotRequest struct + ClientID string + Cursor *SnapshotCursor + Limit int + SchemaHash string + SchemaVersion int64 + type SnapshotResponse struct + Checkpoint int64 + Cursor *SnapshotCursor + HasMore bool + Records []Record + SchemaHash string + SchemaVersion int64 + type TableConfig struct + AllowGlobalRead bool + BucketByColumn string + BucketFunction string + BucketPrefix string + DeletedAtColumn string + Dependencies []string + GlobalWhenBucketNull bool + IDColumn string + OwnerColumn string + ParentFKCol string + ParentTable string + ProtectedColumns []string + PushPolicy PushPolicy + SyncColumns []string + TableName string + UpdatedAtColumn string + func (c *TableConfig) AllowedInsertColumns(dataCols []string) []string + func (c *TableConfig) AllowedUpdateColumns(dataCols []string) []string + func (c *TableConfig) IsProtected(col string) bool + type TableMeta struct + AllowGlobalRead bool + BucketByColumn string + BucketFunction string + BucketPrefix string + DeletedAtColumn string + Dependencies []string + GlobalWhenBucketNull bool + ParentFKCol string + ParentTable string + PushPolicy string + TableName string + UpdatedAtColumn string + type TableMetaResponse struct + SchemaHash string + SchemaVersion int64 + ServerTime time.Time + Tables []TableMeta + type TxBeginner interface + BeginTx func(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)