spark

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 11 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

spark

Package spark implements a simple pub/sub mechanism that allows clients to watch resources.

WebSocket

To watch resources, the client initiates a WebSocket connection to the group action:

wss://example.com/v1/api/watch

And then subscribes to streams:

{
  "subscribe": {
    "items": {
      "state": true
    } 
  }
}

The server then forwards matching events to the client:

{
  "items": {
    "5c880eb87b0a67df9a6a2efc": "created"
  } 
}

If necessary, the client can unsubscribe from streams:

{
  "unsubscribe": ["items"]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event added in v0.17.0

type Event struct {
	// Type specifies the event type.
	Type coal.Event

	// ID is the ID of the changed resource.
	ID coal.ID

	// Model is the changed model.
	//
	// Note: The model is unavailable for deleted events unless soft delete
	// has been enabled.
	Model coal.Model

	// Stream is the stream this event originated from.
	Stream *Stream
}

Event describes an event.

type Map added in v0.17.0

type Map map[string]interface{}

Map holds custom data for a subscription.

type State added in v0.35.1

type State interface {
	Update(*Event) error
}

State holds per-connection state. Update is called for every event observed by the watcher before subscriptions are evaluated.

type StateFactory added in v0.35.1

type StateFactory func(ctx *fire.Context) (State, error)

StateFactory constructs per-connection state.

type Stream added in v0.17.0

type Stream struct {
	// Model defines the model this stream is associated with.
	Model coal.Model

	// Store defines the store to use for opening the stream.
	Store *coal.Store

	// Validator is the callback used to validate subscriptions on the stream.
	Validator func(*Subscription) error

	// Selector is the callback used to decide which events are forwarded to
	// a subscription.
	Selector func(*Event, *Subscription) bool

	// SoftDelete can be set to true to support soft deleted documents.
	SoftDelete bool
	// contains filtered or unexported fields
}

Stream describes a single model stream and how clients can subscribe to it.

func (*Stream) Name added in v0.17.0

func (s *Stream) Name() string

Name returns the name of the stream.

type Subscription added in v0.17.0

type Subscription struct {
	// Context is the original context of the request.
	Context *fire.Context

	// Data is the user-defined data bag.
	Data Map

	// Stream is the subscribed stream.
	Stream *Stream

	// State is the per-connection state.
	State State
}

Subscription is a single subscription to a stream by a client.

type Watcher added in v0.17.0

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher will watch multiple collections and serve watch requests by clients.

func NewWatcher added in v0.17.0

func NewWatcher(factory StateFactory, reporter func(error)) *Watcher

NewWatcher creates and returns a new watcher.

func (*Watcher) Action added in v0.17.0

func (w *Watcher) Action() *fire.Action

Action returns an action that should be registered in the group under the "watch" name.

func (*Watcher) Add added in v0.17.0

func (w *Watcher) Add(stream *Stream)

Add will add a stream to the watcher.

func (*Watcher) Close added in v0.20.0

func (w *Watcher) Close()

Close will close the watcher and all opened streams.

Jump to

Keyboard shortcuts

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