core

package
v0.140.7 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DetailCurrentRevision = "current_revision"
	DetailLatestSnapshot  = "latest_snapshot"
	DetailIdempotencyKey  = "idempotency_key"
)

Variables

This section is empty.

Functions

func HasCode

func HasCode(err error, code ErrorCode) bool

HasCode reports whether err is a canonical sync error with the provided code.

Types

type ErrorCode

type ErrorCode string

ErrorCode is the stable text code exposed across transports.

const (
	CodeNotFound             ErrorCode = "NOT_FOUND"
	CodeStaleRevision        ErrorCode = "STALE_REVISION"
	CodeIdempotencyReplay    ErrorCode = "IDEMPOTENCY_REPLAY"
	CodeInvalidMutation      ErrorCode = "INVALID_MUTATION"
	CodeTransportUnavailable ErrorCode = "TRANSPORT_UNAVAILABLE"
	CodeRateLimited          ErrorCode = "RATE_LIMITED"
	CodeTemporaryFailure     ErrorCode = "TEMPORARY_FAILURE"
)

func ErrorCodeOf

func ErrorCodeOf(err error) (ErrorCode, bool)

ErrorCodeOf extracts the canonical sync error code when available.

type MutationInput

type MutationInput struct {
	ResourceRef      ResourceRef `json:"resource_ref"`
	Operation        string      `json:"operation"`
	Payload          []byte      `json:"payload"`
	ExpectedRevision int64       `json:"expected_revision"`
	IdempotencyKey   string      `json:"idempotency_key,omitempty"`
	// ActorID is required when IdempotencyKey is set so replay scope remains actor-isolated.
	ActorID       string         `json:"actor_id,omitempty"`
	ClientID      string         `json:"client_id,omitempty"`
	CorrelationID string         `json:"correlation_id,omitempty"`
	Metadata      map[string]any `json:"metadata,omitempty"`
}

MutationInput is a single revision-aware write intent.

type MutationResult

type MutationResult struct {
	Snapshot Snapshot `json:"snapshot"`
	Applied  bool     `json:"applied"`
	Replay   bool     `json:"replay"`
}

MutationResult captures the authoritative outcome of a mutation attempt.

type ResourceRef

type ResourceRef struct {
	Kind  string            `json:"kind"`
	ID    string            `json:"id"`
	Scope map[string]string `json:"scope,omitempty"`
}

ResourceRef identifies a single mutable resource within a logical scope.

type Snapshot

type Snapshot struct {
	ResourceRef ResourceRef    `json:"resource_ref"`
	Data        []byte         `json:"data"`
	Revision    int64          `json:"revision"`
	UpdatedAt   time.Time      `json:"updated_at"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

Snapshot is the latest known server-authored view of a resource.

func StaleRevisionDetails

func StaleRevisionDetails(err error) (int64, *Snapshot, bool)

StaleRevisionDetails extracts stale-revision details from canonical sync errors.

type SyncError

type SyncError struct {
	Code    ErrorCode      `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
	Err     error          `json:"-"`
}

SyncError is the canonical domain error shape used before transport mapping.

func NewError

func NewError(code ErrorCode, message string, details map[string]any) *SyncError

NewError builds a canonical sync error with stable code + message.

func NewStaleRevisionError

func NewStaleRevisionError(currentRevision int64, latest *Snapshot) *SyncError

NewStaleRevisionError builds the canonical stale-revision error shape.

func NewWrappedError

func NewWrappedError(code ErrorCode, message string, details map[string]any, err error) *SyncError

NewWrappedError builds a canonical sync error that retains the original cause.

func (*SyncError) Error

func (e *SyncError) Error() string

func (*SyncError) Unwrap

func (e *SyncError) Unwrap() error

Unwrap returns the wrapped lower-level error when present.

type SyncService

type SyncService interface {
	Get(ctx context.Context, ref ResourceRef) (Snapshot, error)
	Mutate(ctx context.Context, input MutationInput) (MutationResult, error)
}

SyncService is the backend orchestration contract for revisioned resources.

Jump to

Keyboard shortcuts

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