api

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package api provides HTTP client access to the PowerSync service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchSchemaJSON

func FetchSchemaJSON(ctx context.Context, endpoint, token string) (string, error)

FetchSchemaJSON fetches the schema from the PowerSync service and returns it as JSON. The returned JSON is in the format expected by powersync_replace_schema().

Types

type BucketRequest

type BucketRequest struct {
	Name  string `json:"name"`
	After string `json:"after"`
}

BucketRequest specifies a bucket to sync and the last known checkpoint.

type Client

type Client interface {
	SyncStream(ctx context.Context, req *SyncStreamRequest, handler LineHandler) error
	GetWriteCheckpoint(ctx context.Context, clientID string) (string, error)
	SetToken(token string)
}

Client provides HTTP access to the PowerSync service.

func NewClient

func NewClient(endpoint string) Client

NewClient creates a new PowerSync client.

type Error

type Error struct {
	Kind       ErrorKind
	StatusCode int
	Message    string
	Err        error
}

Error represents an error from the PowerSync service.

func (*Error) Error

func (e *Error) Error() string

func (*Error) IsAuth

func (e *Error) IsAuth() bool

func (*Error) IsPermanent

func (e *Error) IsPermanent() bool

func (*Error) IsTransient

func (e *Error) IsTransient() bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind int

ErrorKind classifies client errors.

const (
	ErrorKindTransient ErrorKind = iota // Retry with backoff
	ErrorKindAuth                       // Refresh token and retry
	ErrorKindPermanent                  // Don't retry
)

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is the interface for making HTTP requests.

type LineHandler

type LineHandler func(line []byte) error

LineHandler is called for each line received from the sync stream.

type RequestedStreamSubscription

type RequestedStreamSubscription struct {
	Stream           string `json:"stream"`
	Parameters       string `json:"parameters,omitempty"`
	OverridePriority *int   `json:"override_priority,omitempty"`
}

RequestedStreamSubscription is a request to subscribe to a stream.

type SchemaColumn

type SchemaColumn struct {
	Name string `json:"name"`
	Type string `json:"type"` // "text", "integer", "real"
}

SchemaColumn represents a column in a PowerSync table.

type SchemaTable

type SchemaTable struct {
	Name    string         `json:"name"`
	Columns []SchemaColumn `json:"columns"`
}

SchemaTable represents a table in the PowerSync schema.

type StreamSubscription

type StreamSubscription struct {
	IncludeDefaults bool                          `json:"include_defaults"`
	Subscriptions   []RequestedStreamSubscription `json:"subscriptions"`
}

StreamSubscription defines stream subscription preferences.

type SyncStreamRequest

type SyncStreamRequest struct {
	Buckets         []BucketRequest     `json:"buckets"`
	IncludeChecksum bool                `json:"include_checksum"`
	RawData         bool                `json:"raw_data"`
	BinaryData      bool                `json:"binary_data"`
	ClientID        string              `json:"client_id"`
	Parameters      map[string]any      `json:"parameters,omitempty"`
	Streams         *StreamSubscription `json:"streams,omitempty"`
	AppMetadata     json.RawMessage     `json:"app_metadata,omitempty"`
}

SyncStreamRequest is the request body for the sync stream endpoint.

Directories

Path Synopsis
Package apitest provides test doubles for the powersync/api package.
Package apitest provides test doubles for the powersync/api package.

Jump to

Keyboard shortcuts

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