notes

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package notes provides types and functions for interacting with a note maps data storage system.

Package notes provides types and functions for interacting with a note maps data storage system.

Package notes provides types and functions for interacting with a note maps data storage system.

Package notes provides types and functions for interacting with a note maps data storage system.

Index

Constants

View Source
const (
	// EmptyLoader implements the Loader interface for a note map that is
	// always empty.
	EmptyLoader emptyLoader = 0
)

Variables

This section is empty.

Functions

func DebugDiff

func DebugDiff(a, b Note) (string, interface{}, interface{}, error)

func Equal

func Equal(a, b Note) (bool, error)

Types

type AddContent added in v0.0.3

type AddContent struct {
	ID  ID
	Add ID
}

func (AddContent) AffectsID added in v0.0.3

func (x AddContent) AffectsID(id ID) bool

type EmptyNote

type EmptyNote ID

EmptyNote is simply an empty Note with nothing more than an ID.

func (EmptyNote) GetContents

func (x EmptyNote) GetContents() ([]Note, error)

func (EmptyNote) GetID added in v0.0.3

func (x EmptyNote) GetID() ID

func (EmptyNote) GetValue

func (x EmptyNote) GetValue() (string, Note, error)

type Error

type Error int
const (
	InvalidID Error = iota
)

func (Error) Error

func (e Error) Error() string

type FindLoadPatcher added in v0.0.3

type FindLoadPatcher interface {
	Finder
	Loader
	Patcher
}

FindLoadPatcher combines the Finder, Loader, and Patcher interfaces.

type FindLoader added in v0.0.3

type FindLoader interface {
	Finder
	Loader
}

FindLoader combines the Finder and Loader interfaces.

type Finder

type Finder interface {
	Find(*Query) ([]Note, error)
}

Finder can be implemented to support finding notes in a note map according to a query.

type ID added in v0.0.3

type ID string

ID is the type of values that identify notes.

const EmptyID ID = ""

EmptyID is the zero or nil value for note identifiers, and never identifies a valid note.

EmptyID exists only to make code that specifies the zero value for Note identifiers a bit more readable.

func (ID) Empty added in v0.0.3

func (id ID) Empty() bool

type IsolatedReadWriteCloser added in v0.0.3

type IsolatedReadWriteCloser interface {
	IsolatedReader
	IsolatedWriter
	io.Closer
}

IsolatedReadWriteCloser provides atomic isolated read and write operations over a note map.

An instance of IsolatedReadWriteCloser should be closed when it is no longer needed.

type IsolatedReader added in v0.0.3

type IsolatedReader interface {
	// IsolatedRead invokes f with a FindLoader that will read from an
	// unchanging version of the note map.
	IsolatedRead(f func(r FindLoader) error) error
}

IsolatedReader provides isolated read operations over a note map.

type IsolatedWriter added in v0.0.3

type IsolatedWriter interface {
	// IsolatedWrite invokes f with an isolated FindLoadPatcher that can read and
	// change a note map.
	//
	// If f returns an error, none of the changes will be saved. Implementations
	// should return an error in any case when changes are not saved.
	IsolatedWrite(f func(rw FindLoadPatcher) error) error
}

IsolatedWriter provides atomic isolated write operations over a note map.

type Loader

type Loader interface {
	// Load returns a slice of all found notes.
	//
	// All notes exist implicitly, even if they are empty. An error indicates
	// something actually went wrong.
	Load(ids []ID) ([]Note, error)
}

Loader can be implemented to support loading notes by id.

type Note

type Note interface {
	GetID() ID
	GetValue() (string, Note, error)
	GetContents() ([]Note, error)
}

Note is a graph-like interface to a note in a note map.

Since traversing from note to note in a note map may require fragile operations like loading query results from a storage backend, most methods can return an error instead of the requested data.

func LoadOne

func LoadOne(l Loader, id ID) (Note, error)

LoadOne is a convenience function for loading just one note.

type Operation added in v0.0.3

type Operation interface {
	AffectsID(id ID) bool
}

type Patcher

type Patcher interface {
	Patch(ops []Operation) error
}

Patcher can be implemented to support making changes to notes in a note map by applying a set of differences to them.

type Query

type Query struct {
}

Query limits the notes that will be found when loading information from a graph.

The default query matches all notes.

type SetValue added in v0.0.3

type SetValue struct {
	ID       ID
	Lexical  string
	Datatype ID
}

func (SetValue) AffectsID added in v0.0.3

func (x SetValue) AffectsID(id ID) bool

type Stage

type Stage struct {
	Ops  []Operation
	Base Loader
}

Stage describes a set of changes that might be made to a note map.

The default stage describes an empty set of changes to be made to an empty note map.

A default Stage{} is an empty set of changes made to an empty note map.

func (*Stage) Add

func (x *Stage) Add(o Operation) *Stage

Add simply appends o to the set of operations described by x.

func (*Stage) GetBase

func (x *Stage) GetBase(defaultEmpty bool) Loader

GetBase returns a non-nil Loader derived from x.Base.

func (*Stage) Note

func (x *Stage) Note(id ID) *StageNote

Note returns a note-specific StageNote focused on note with id.

type StageNote

type StageNote struct {
	Stage *Stage
	ID    ID
}

StageNote supports updating the content of a note within a batch, and also implements the Note interface to read the hypothetical state of a note with the batch applied.

func (*StageNote) AddContent

func (x *StageNote) AddContent(id ID) *StageNote

AddContent expands the staged operations to add content to this note.

func (*StageNote) GetContents

func (x *StageNote) GetContents() ([]Note, error)

func (*StageNote) GetID added in v0.0.3

func (x *StageNote) GetID() ID

func (*StageNote) GetValue

func (x *StageNote) GetValue() (string, Note, error)

func (*StageNote) SetValue

func (x *StageNote) SetValue(lexical string, datatype ID)

SetValue expands the staged operations to update the value of this note.

Directories

Path Synopsis
Package textile uses Textileio ThreadsDB to implement the github.com/google/note-maps/notes interfaces.
Package textile uses Textileio ThreadsDB to implement the github.com/google/note-maps/notes interfaces.

Jump to

Keyboard shortcuts

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