vacuumv1

import vacuumv1 "pocketone.dev/ext/contracts/vacuum/v1"

Package vacuumv1 is the vacuum/v1 contract: an app's databases are compacted (SQLite VACUUM) so space freed by deleted records goes back to the disk, and its admins can see when that last happened. On a single app the vacuum extension does it, on a schedule its admins set; a multisite host may provide it for its instances instead, compacting them on its own schedule, and then the app's admins see its status but have no setting.

A wire contract at /api/_c/vacuum/v1.

Source: ext/contracts/vacuum/v1.

Variables

var Contract = extkit.NewContract[Vacuum]("vacuum/v1", extkit.One).HostProvidable()

Contract is vacuum/v1.

var W = extkit.NewWire(Contract, "vacuum", func(inner Vacuum, g *extkit.Guard[Vacuum]) Vacuum {
	return &guardVacuum{inner, g}
},
	extkit.Op[Vacuum]{
		Name:   "status",
		Desc:   "Says who compacts the app's databases, whether and how often, and how the last run went.",
		Method: "GET",
		Path:   "",
		Scope:  "vacuum:read",
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Vacuum, a extkit.Auth, req extkit.OpRequest) (any, error) {
			return impl.Status(ctx, a)
		},
	},
)

W is vacuum/v1's wire side: routes at /api/_c/vacuum/v1/<op>, action hooks, MCP tools and the client.

Functions

OnStatus

func OnStatus(owner any, fn func(e *extkit.CallEvent) error)

OnStatus binds fn to status calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse.

Types

Client

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

Client is vacuum/v1 over HTTP, for the CLI and other apps. It implements Vacuum; the token it was made with is the credential, so the extkit.Auth argument is ignored.

NewClient

func NewClient(baseURL, token string, hc *http.Client) *Client

NewClient calls vacuum/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.Status

func (c *Client) Status(ctx context.Context, _ extkit.Auth) (Status, error)

Run

type Run struct {
	At      time.Time `json:"at"`
	Saved   int64     `json:"saved"`             // bytes given back to the disk
	Skipped []string  `json:"skipped,omitempty"` // databases with too little free space to be worth it
	Error   string    `json:"error,omitempty"`
}

Run is one pass over the app's databases.

Status

type Status struct {
	Provider string     `json:"provider"` // who compacts: "vacuum" (the app itself) or a host
	Enabled  bool       `json:"enabled"`
	Every    string     `json:"every,omitempty"` // how often, e.g. "168h"
	Last     *Run       `json:"last,omitempty"`
	Next     *time.Time `json:"next,omitempty"`
}

Status is the app's vacuum status.

Vacuum

type Vacuum interface {
	// Status says who compacts the app's databases, whether and how often, and how the last run went.
	//
	//op: GET / scope=vacuum:read
	Status(ctx context.Context, a extkit.Auth) (Status, error)
}

Vacuum reports on compacting the app's databases.