cloud

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCloudURL is the default ticks.sh WebSocket endpoint.
	DefaultCloudURL = "wss://ticks.sh/api/projects"

	// EnvToken is the environment variable for the cloud token.
	EnvToken = "TICKS_TOKEN"

	// EnvCloudURL is the environment variable to override the cloud URL.
	EnvCloudURL = "TICKS_URL"

	// ConfigFileName is the name of the config file in user's home directory.
	ConfigFileName = ".ticksrc"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// Callback for remote changes (optional)
	OnRemoteChange func(t tick.Tick)

	// State change callback (optional)
	OnStateChange func(state SyncState)
	// contains filtered or unexported fields
}

Client manages the connection to ticks.sh cloud using sync mode. Sync mode provides real-time tick synchronization via Durable Objects.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient creates a new cloud client with the given configuration.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the cloud with a proper WebSocket close handshake.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes the WebSocket connection to the cloud.

func (*Client) GetLastSync added in v0.7.0

func (c *Client) GetLastSync() time.Time

GetLastSync returns the time of the last successful sync.

func (*Client) GetSyncState added in v0.7.0

func (c *Client) GetSyncState() SyncState

GetSyncState returns the current sync state.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client is currently connected.

func (*Client) PendingCount added in v0.7.0

func (c *Client) PendingCount() int

PendingCount returns the number of queued messages waiting to be sent.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run connects to the cloud and handles messages until context is cancelled. It automatically reconnects with exponential backoff on disconnection.

func (*Client) Stop

func (c *Client) Stop()

Stop signals the client to stop and close.

func (*Client) SyncDelete added in v0.7.0

func (c *Client) SyncDelete(id string) error

SyncDelete notifies the DO of a tick deletion.

func (*Client) SyncFullState added in v0.7.0

func (c *Client) SyncFullState(ticks map[string]tick.Tick) error

SyncFullState sends all ticks to the DO for initial sync.

func (*Client) SyncTick added in v0.7.0

func (c *Client) SyncTick(t tick.Tick) error

SyncTick sends a tick update to the DO.

type Config

type Config struct {
	Token     string
	CloudURL  string
	BoardName string
	TickDir   string // path to .tick directory (required)
}

Config holds the cloud client configuration.

func LoadConfig

func LoadConfig(tickDir string) *Config

LoadConfig loads the cloud configuration from environment and config file. Returns nil config if no token is configured (cloud is optional).

type StateFullMessage added in v0.7.0

type StateFullMessage struct {
	Type  string               `json:"type"` // "state_full"
	Ticks map[string]tick.Tick `json:"ticks"`
}

StateFullMessage is received from DO with full tick state.

type SyncFullMessage added in v0.7.0

type SyncFullMessage struct {
	Type  string               `json:"type"` // "sync_full"
	Ticks map[string]tick.Tick `json:"ticks"`
}

SyncFullMessage sends all ticks to the DO for initial sync.

type SyncState added in v0.7.0

type SyncState int

SyncState represents the connection state for sync mode.

const (
	// SyncDisconnected means not connected to the cloud.
	SyncDisconnected SyncState = iota
	// SyncConnecting means attempting to connect.
	SyncConnecting
	// SyncConnected means connected and syncing.
	SyncConnected
	// SyncError means last connection attempt failed.
	SyncError
)

func (SyncState) String added in v0.7.0

func (s SyncState) String() string

type TickDeleteMessage added in v0.7.0

type TickDeleteMessage struct {
	Type string `json:"type"` // "tick_delete"
	ID   string `json:"id"`
}

TickDeleteMessage notifies DO of tick deletion.

type TickDeletedMessage added in v0.7.0

type TickDeletedMessage struct {
	Type string `json:"type"` // "tick_deleted"
	ID   string `json:"id"`
}

TickDeletedMessage is received from DO when a tick is deleted.

type TickOperationRequest added in v0.8.0

type TickOperationRequest struct {
	Type      string `json:"type"`            // "tick_operation"
	RequestID string `json:"requestId"`       // Unique ID to correlate response
	Operation string `json:"operation"`       // "add_note", "approve", "reject", "close", "reopen"
	TickID    string `json:"tickId"`          // ID of the tick to operate on
	Actor     string `json:"actor,omitempty"` // Authenticated session user id (opaque, not an email) of the requester
	Payload   struct {
		Message string `json:"message,omitempty"` // For add_note
		Reason  string `json:"reason,omitempty"`  // For reject, close
	} `json:"payload,omitempty"`
}

TickOperationRequest is received from DO when cloud UI wants to perform an operation.

type TickOperationResponse added in v0.8.0

type TickOperationResponse struct {
	Type      string     `json:"type"`            // "tick_operation_response"
	RequestID string     `json:"requestId"`       // Matches the request ID
	Success   bool       `json:"success"`         // Whether the operation succeeded
	Tick      *tick.Tick `json:"tick,omitempty"`  // Updated tick on success
	Error     string     `json:"error,omitempty"` // Error message on failure
}

TickOperationResponse is sent back to DO after performing an operation.

type TickUpdateMessage added in v0.7.0

type TickUpdateMessage struct {
	Type string    `json:"type"` // "tick_update" or "tick_create"
	Tick tick.Tick `json:"tick"`
}

TickUpdateMessage sends a single tick update to the DO.

type TickUpdatedMessage added in v0.7.0

type TickUpdatedMessage struct {
	Type string    `json:"type"` // "tick_updated" or "tick_created"
	Tick tick.Tick `json:"tick"`
}

TickUpdatedMessage is received from DO when a tick is updated.

Jump to

Keyboard shortcuts

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