box

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: EUPL-1.2 Imports: 12 Imported by: 0

Documentation

Overview

Package box provides a generic interface to zettel boxes.

Index

Constants

This section is empty.

Variables

View Source
var ErrCapacity = errors.New("capacity exceeded")

ErrCapacity is returned if a box has reached its capacity.

View Source
var ErrConflict = errors.New("conflict")

ErrConflict is returned if a box operation detected a conflict.. One example: if calculating a new zettel identifier takes too long.

View Source
var ErrReadOnly = errors.New("read-only box")

ErrReadOnly is returned if there is an attepmt to write to a read-only box.

View Source
var ErrStarted = errors.New("box is already started")

ErrStarted is returned when trying to start an already started box.

View Source
var ErrStopped = errors.New("box is stopped")

ErrStopped is returned if calling methods on a box that was not started.

Functions

func DoNotEnrich

func DoNotEnrich(ctx context.Context) bool

DoNotEnrich determines if the context is marked to not enrich metadata.

func GetNewZid

func GetNewZid(testZid func(id.Zid) (bool, error)) (id.Zid, error)

GetNewZid calculates a new and unused zettel identifier, based on the current date and time.

func GetQueryBool added in v0.5.0

func GetQueryBool(u *url.URL, key string) bool

GetQueryBool is a helper function to extract bool values from a box URI.

func GetQueryInt added in v0.5.0

func GetQueryInt(u *url.URL, key string, min, def, max int) int

GetQueryInt is a helper function to extract int values of a specified range from a box URI.

func NewErrNotAllowed

func NewErrNotAllowed(op string, user *meta.Meta, zid id.Zid) error

NewErrNotAllowed creates an new authorization error.

func NoEnrichContext

func NoEnrichContext(ctx context.Context) context.Context

NoEnrichContext will signal an enricher that nothing has to be done. This is useful for an Indexer, but also for some box.Box calls, when just the plain metadata is needed.

func NoEnrichQuery added in v0.9.0

func NoEnrichQuery(ctx context.Context, q *query.Query) context.Context

NoEnrichQuery provides a context that signals not to enrich, if the query does not need this.

Types

type BaseBox

type BaseBox interface {
	// Location returns some information where the box is located.
	// Format is dependent of the box.
	Location() string

	// GetZettel retrieves a specific zettel.
	GetZettel(ctx context.Context, zid id.Zid) (zettel.Zettel, error)

	// AllowRenameZettel returns true, if box will not disallow renaming the zettel.
	AllowRenameZettel(ctx context.Context, zid id.Zid) bool

	// RenameZettel changes the current Zid to a new Zid.
	RenameZettel(ctx context.Context, curZid, newZid id.Zid) error

	// CanDeleteZettel returns true, if box could possibly delete the given zettel.
	CanDeleteZettel(ctx context.Context, zid id.Zid) bool

	// DeleteZettel removes the zettel from the box.
	DeleteZettel(ctx context.Context, zid id.Zid) error
}

BaseBox is implemented by all Zettel boxes.

type Box

type Box interface {
	BaseBox
	WriteBox

	// FetchZids returns the set of all zettel identifer managed by the box.
	FetchZids(ctx context.Context) (id.Set, error)

	// GetMeta returns the metadata of the zettel with the given identifier.
	GetMeta(context.Context, id.Zid) (*meta.Meta, error)

	// SelectMeta returns a list of metadata that comply to the given selection criteria.
	// If `metaSeq` is `nil`, the box assumes metadata of all available zettel.
	SelectMeta(ctx context.Context, metaSeq []*meta.Meta, q *query.Query) ([]*meta.Meta, error)

	// GetAllZettel retrieves a specific zettel from all managed boxes.
	GetAllZettel(ctx context.Context, zid id.Zid) ([]zettel.Zettel, error)

	// Refresh the data from the box and from its managed sub-boxes.
	Refresh(context.Context) error

	// ReIndex one zettel to update its index data.
	ReIndex(context.Context, id.Zid) error
}

Box is to be used outside the box package and its descendants.

type Enricher

type Enricher interface {
	// Enrich computes additional properties and updates the given metadata.
	// It is typically called by zettel reading methods.
	Enrich(ctx context.Context, m *meta.Meta, boxNumber int)
}

Enricher is used to update metadata by adding new properties.

type ErrInvalidZid added in v0.14.0

type ErrInvalidZid struct{ Zid string }

ErrInvalidZid is returned if the zettel id is not appropriate for the box operation.

func (ErrInvalidZid) Error added in v0.14.0

func (err ErrInvalidZid) Error() string

type ErrNotAllowed

type ErrNotAllowed struct {
	Op   string
	User *meta.Meta
	Zid  id.Zid
}

ErrNotAllowed is returned if the caller is not allowed to perform the operation.

func (*ErrNotAllowed) Error

func (err *ErrNotAllowed) Error() string

func (*ErrNotAllowed) Is

func (*ErrNotAllowed) Is(error) bool

Is return true, if the error is of type ErrNotAllowed.

type ErrZettelNotFound added in v0.14.0

type ErrZettelNotFound struct{ Zid id.Zid }

ErrZettelNotFound is returned if a zettel was not found in the box.

func (ErrZettelNotFound) Error added in v0.14.0

func (eznf ErrZettelNotFound) Error() string

type ManagedBox

type ManagedBox interface {
	BaseBox

	// HasZettel returns true, if box conains zettel with given identifier.
	HasZettel(context.Context, id.Zid) bool

	// Apply identifier of every zettel to the given function, if predicate returns true.
	ApplyZid(context.Context, ZidFunc, query.RetrievePredicate) error

	// Apply metadata of every zettel to the given function, if predicate returns true.
	ApplyMeta(context.Context, MetaFunc, query.RetrievePredicate) error

	// ReadStats populates st with box statistics
	ReadStats(st *ManagedBoxStats)
}

ManagedBox is the interface of managed boxes.

type ManagedBoxStats

type ManagedBoxStats struct {
	// ReadOnly indicates that the content of a box cannot change.
	ReadOnly bool

	// Zettel is the number of zettel managed by the box.
	Zettel int
}

ManagedBoxStats records statistics about the box.

type Manager

type Manager interface {
	Box
	StartStopper
	Subject

	// ReadStats populates st with box statistics
	ReadStats(st *Stats)

	// Dump internal data to a Writer.
	Dump(w io.Writer)
}

Manager is a box-managing box.

type MetaFunc

type MetaFunc func(*meta.Meta)

MetaFunc is a function that processes metadata of a zettel.

type Refresher added in v0.2.1

type Refresher interface {
	// Refresh the box data.
	Refresh(context.Context)
}

Refresher allow to refresh their internal data.

type StartState added in v0.11.0

type StartState uint8

StartState enumerates the possible states of starting and stopping a box.

StartStateStopped -> StartStateStarting -> StartStateStarted -> StateStateStopping -> StartStateStopped.

Other transitions are also possible.

const (
	StartStateStopped StartState = iota
	StartStateStarting
	StartStateStarted
	StartStateStopping
)

Constant values of StartState

type StartStopper

type StartStopper interface {
	// State the current status of the box.
	State() StartState

	// Start the box. Now all other functions of the box are allowed.
	// Starting a box, which is not in state StartStateStopped is not allowed.
	Start(ctx context.Context) error

	// Stop the started box. Now only the Start() function is allowed.
	Stop(ctx context.Context)
}

StartStopper performs simple lifecycle management.

type Stats

type Stats struct {
	// ReadOnly indicates that boxes cannot be modified.
	ReadOnly bool

	// NumManagedBoxes is the number of boxes managed.
	NumManagedBoxes int

	// Zettel is the number of zettel managed by the box, including
	// duplicates across managed boxes.
	ZettelTotal int

	// LastReload stores the timestamp when a full re-index was done.
	LastReload time.Time

	// DurLastReload is the duration of the last full re-index run.
	DurLastReload time.Duration

	// IndexesSinceReload counts indexing a zettel since the full re-index.
	IndexesSinceReload uint64

	// ZettelIndexed is the number of zettel managed by the indexer.
	ZettelIndexed int

	// IndexUpdates count the number of metadata updates.
	IndexUpdates uint64

	// IndexedWords count the different words indexed.
	IndexedWords uint64

	// IndexedUrls count the different URLs indexed.
	IndexedUrls uint64
}

Stats record stattistics about a box.

type Subject

type Subject interface {
	// RegisterObserver registers an observer that will be notified
	// if one or all zettel are found to be changed.
	RegisterObserver(UpdateFunc)
}

Subject is a box that notifies observers about changes.

type UpdateFunc

type UpdateFunc func(UpdateInfo)

UpdateFunc is a function to be called when a change is detected.

type UpdateInfo

type UpdateInfo struct {
	Box    BaseBox
	Reason UpdateReason
	Zid    id.Zid
}

UpdateInfo contains all the data about a changed zettel.

type UpdateReason

type UpdateReason uint8

UpdateReason gives an indication, why the ObserverFunc was called.

const (
	OnReady  UpdateReason // Box is started and fully operational
	OnReload              // Box was reloaded
	OnZettel              // Something with a zettel happened
)

Values for Reason

type WriteBox added in v0.15.0

type WriteBox interface {
	// CanCreateZettel returns true, if box could possibly create a new zettel.
	CanCreateZettel(ctx context.Context) bool

	// CreateZettel creates a new zettel.
	// Returns the new zettel id (and an error indication).
	CreateZettel(ctx context.Context, zettel zettel.Zettel) (id.Zid, error)

	// CanUpdateZettel returns true, if box could possibly update the given zettel.
	CanUpdateZettel(ctx context.Context, zettel zettel.Zettel) bool

	// UpdateZettel updates an existing zettel.
	UpdateZettel(ctx context.Context, zettel zettel.Zettel) error
}

WriteBox is a box that can create / update zettel content.

type ZidFunc

type ZidFunc func(id.Zid)

ZidFunc is a function that processes identifier of a zettel.

Directories

Path Synopsis
Package compbox provides zettel that have computed content.
Package compbox provides zettel that have computed content.
Package constbox puts zettel inside the executable.
Package constbox puts zettel inside the executable.
Package dirbox provides a directory-based zettel box.
Package dirbox provides a directory-based zettel box.
Package filebox provides boxes that are stored in a file.
Package filebox provides boxes that are stored in a file.
Package manager coordinates the various boxes and indexes of a Zettelstore.
Package manager coordinates the various boxes and indexes of a Zettelstore.
mapstore
Package mapstore stored the index in main memory via a Go map.
Package mapstore stored the index in main memory via a Go map.
store
Package store contains general index data for storing a zettel index.
Package store contains general index data for storing a zettel index.
Package membox stores zettel volatile in main memory.
Package membox stores zettel volatile in main memory.
Package notify provides some notification services to be used by box services.
Package notify provides some notification services to be used by box services.

Jump to

Keyboard shortcuts

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