appstore

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

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.

Documentation

Overview

Package appstore is the storage of an app's views (hl.storage.<scope>) without the rest of the apps: the areas, their limits, the versions of their keys (ifVersion) and where an area's file lives. The runtime keeps the install's area on its disk and, under a hub, every other area in the hub's store, so the data of an app is the same on every machine of a space and is there with the machines off; the hub answers a view it serves with the same code. It imports nothing of the runtime or the hub.

Index

Constants

View Source
const HostKeyPrefix = "__hl_"

HostKeyPrefix begins the keys the host keeps in an app's areas (VersionsKey, the workflow of a document): a view neither reads nor writes them as keys.

View Source
const MaxAreaBytes = 10 << 20

MaxAreaBytes is the largest area of any scope.

View Source
const MaxKeyBytes = 256

MaxKeyBytes is the longest key.

View Source
const StorePrefix = "storage/"

StorePrefix is the folder of the apps' areas in a space's apps collection of the store: storage/<Path>.

View Source
const VersionsKey = "__hl_versions"

VersionsKey is where an area's file keeps the version of each key, next to the values. A key's version is a counter that only grows: a write adds one, a delete adds one too and keeps the number, so a key made anew never repeats a version a reader holds. A key with no version (data written before versions) is at 0. The name is not a key a caller can use.

Variables

View Source
var (
	// ErrQuota: the write would take the area past its limit.
	ErrQuota = errors.New("apps: the storage area is full")
	// ErrArgs: a scope, owner or key that is not one.
	ErrArgs = errors.New("apps: bad storage arguments")
	// ErrConflict: a write that named the version it read (ifVersion) found the key moved on. The error is a
	// *ConflictError, which carries the version the key has now.
	ErrConflict = errors.New("apps: the key changed since it was read")
	// ErrMoved: an area's file is no longer at the revision a write was made on (another machine wrote it); the
	// write is made again on top of the new one.
	ErrMoved = errors.New("apps: the area changed under the write")
)
View Source
var Limit = map[Scope]int{
	ScopeInstall: 5 << 20,
	ScopeUser:    1 << 20,
	ScopeChat:    256 << 10,
	ScopeSpace:   10 << 20,
	ScopeDoc:     100 << 10,
}

Limit is the most one area may hold, in bytes of its JSON file.

View Source
var Total = map[Scope]int64{
	ScopeInstall: 5 << 20,
	ScopeUser:    1 << 20,
	ScopeChat:    20 << 20,
	ScopeSpace:   10 << 20,
	ScopeDoc:     20 << 20,
}

Total is the most all the areas of one scope of one app may hold together, so many chats or documents cannot add up past what the scope is meant to cost.

Functions

func CheckKey

func CheckKey(key string) error

CheckKey refuses a key a caller may not use.

func Path

func Path(app string, scope Scope, name string) (string, error)

Path is where an area's file is, relative to the storage's root: <app>/<scope>/<name>.json. name is the chat or document for a scope per owner, and "area" for the others; in the hub's store a user area is named by the person and a chat's by the person and the chat (<person>.<chat>), so the hub shows them only to that person's machines.

func ValidApp

func ValidApp(app string) bool

ValidApp says whether a text is an app's id.

func ValidOwner

func ValidOwner(owner string) bool

ValidOwner says whether a text can name the chat or document an area belongs to.

func WriteFileAtomic

func WriteFileAtomic(file string, data []byte) error

WriteFileAtomic writes a file through a temporary one beside it, so a reader never sees half of it.

Types

type Area

type Area struct {
	Values   map[string]json.RawMessage
	Versions map[string]int64
}

Area is an area as its file holds it: the values and the version of each key.

func Parse

func Parse(raw []byte) (*Area, error)

Parse reads an area's file; nil or empty is an empty area.

func Read

func Read(ctx context.Context, f Files, rel string) (*Area, error)

Read is an area as its file has it now.

func Update

func Update(ctx context.Context, f Files, scope Scope, rel string, quota bool, change func(*Area) (bool, error)) (*Area, error)

Update changes an area: change gets the area as it is and says whether it changed it (or refuses with an error); the file is written only then, and only inside the scope's limits (quota false: a delete, which never needs room). A write that finds the area moved on runs change again on the new one. It answers the area as written.

func (*Area) Keys

func (a *Area) Keys() []string

Keys are the area's keys, sorted.

func (*Area) Marshal

func (a *Area) Marshal() ([]byte, error)

Marshal is the area's file.

type Client

type Client interface {
	Current(ctx context.Context, path string) (*filestore.Entry, error)
	GetBlob(ctx context.Context, sha string, w io.Writer) error
	PutBlob(ctx context.Context, sha string, data []byte) error
	Commit(ctx context.Context, req filestore.CommitRequest) (filestore.CommitResponse, error)
	Snapshot(ctx context.Context, prefix string, at int64) (filestore.Snapshot, error)
}

Client is the store's API as a machine speaks it (filesync.Client).

type ConflictError

type ConflictError struct{ Current int64 }

ConflictError is the refusal of a write whose ifVersion is not the key's version; Current is the version it has.

func (*ConflictError) Error

func (e *ConflictError) Error() string

func (*ConflictError) Is

func (e *ConflictError) Is(target error) bool

type Files

type Files interface {
	// Read is a file and the revision it is at; nil and the revision of its deletion (0 when it never was) when
	// there is none.
	Read(ctx context.Context, rel string) (data []byte, rev int64, err error)
	// Write puts a file (nil deletes it) on top of the revision base Read gave; ErrMoved when it is no longer there.
	Write(ctx context.Context, rel string, base int64, data []byte) error
	// Weigh is what the files under a folder (rel, no slash at the end) weigh together.
	Weigh(ctx context.Context, dir string) (int64, error)
}

Files is where areas' files are kept: a folder on the machine, or a room of the hub's store.

func ClientFiles

func ClientFiles(c Client, author string) Files

ClientFiles is areas' files in the hub's store, as a machine reaches them; author names the writer of a revision.

func RoomFiles

func RoomFiles(r Room, machine, author string) Files

RoomFiles is areas' files in a room of the hub's store, as the hub reaches them; machine is what its revisions are recorded under.

type Folder

type Folder string

Folder is areas' files in a folder of the machine. Its revisions are all 0: the writers of one folder are one process, which holds its own lock around a read and the write after it.

func (Folder) Read

func (d Folder) Read(_ context.Context, rel string) ([]byte, int64, error)

func (Folder) Weigh

func (d Folder) Weigh(_ context.Context, dir string) (int64, error)

func (Folder) Write

func (d Folder) Write(_ context.Context, rel string, _ int64, data []byte) error

type Room

type Room interface {
	Current(ctx context.Context, path string) (*filestore.Entry, error)
	OpenBlob(ctx context.Context, sha string) (io.ReadCloser, error)
	PutBlob(ctx context.Context, sha string, r io.Reader) error
	Commit(ctx context.Context, req filestore.CommitRequest, machine string) (*filestore.Entry, bool, error)
	Snapshot(ctx context.Context, prefix string, at int64) (filestore.Snapshot, error)
}

Room is a room of the store as the hub reads it itself (filestore.Store).

type Scope

type Scope string

Scope is an area of the storage.

const (
	ScopeInstall Scope = "install"
	ScopeUser    Scope = "user"
	ScopeChat    Scope = "chat"
	ScopeSpace   Scope = "space"
	ScopeDoc     Scope = "doc"
)

func (Scope) Known

func (s Scope) Known() bool

Known tells a scope from a text that is not one.

func (Scope) PerOwner

func (s Scope) PerOwner() bool

PerOwner are the scopes whose area belongs to a chat or a document.

Jump to

Keyboard shortcuts

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