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.
Index ¶
- Constants
- Variables
- func Patch(a *TruncatedNote, ops []Operation) error
- type EmptyNote
- type FindLoadPatcher
- type FindLoader
- type Finder
- type GraphNote
- type ID
- type IsolatedReadWriteCloser
- type IsolatedReader
- type IsolatedWriter
- type Loader
- type Op
- type OpAddContent
- type OpInsertContent
- type OpRemoveContent
- type OpSetValue
- type OpSetValueString
- type OpSwapContent
- type Operation
- type OperationSlice
- func (os OperationSlice) AddContent(id ID, cs ...ID) OperationSlice
- func (os OperationSlice) InsertContent(id ID, index int, cs ...ID) OperationSlice
- func (os OperationSlice) RemoveContent(id ID, cs ...ID) OperationSlice
- func (os OperationSlice) SetValue(id ID, vs string, vt ID) OperationSlice
- func (os OperationSlice) SetValueString(id ID, vs string) OperationSlice
- func (os OperationSlice) SwapContent(id ID, a, b int) OperationSlice
- type Patcher
- type Query
- type Stage
- type StageNote
- type TruncatedNote
Constants ¶
const ( // EmptyLoader implements the Loader interface for a note map that is // always empty. EmptyLoader emptyLoader = 0 )
Variables ¶
var (
InvalidID = errors.New("invalid note id")
)
Functions ¶
func Patch ¶ added in v0.0.4
func Patch(a *TruncatedNote, ops []Operation) error
Patch applies a set of operations to a.
Types ¶
type EmptyNote ¶
type EmptyNote ID
EmptyNote is simply an empty GraphNote with nothing more than an ID.
func (EmptyNote) GetContents ¶
type FindLoadPatcher ¶ added in v0.0.3
FindLoadPatcher combines the Finder, Loader, and Patcher interfaces.
type FindLoader ¶ added in v0.0.3
FindLoader combines the Finder and Loader interfaces.
type Finder ¶
Finder can be implemented to support finding notes in a note map according to a query.
type GraphNote ¶ added in v0.0.4
type GraphNote interface {
GetID() ID
GetValue() (string, GraphNote, error)
GetContents() ([]GraphNote, error)
}
GraphNote 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 ExpandNote ¶ added in v0.0.4
func ExpandNote(tn TruncatedNote, l Loader) GraphNote
ExpandNote uses tn and l to provide a full GraphNote implementation.
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.
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) ([]GraphNote, error)
}
Loader can be implemented to support loading notes by id.
type Op ¶ added in v0.0.4
type Op ID
Op is a minimal implementation of Operation meant to be used as a mixin for operations that affect only one note.
type OpAddContent ¶ added in v0.0.4
OpAddContent appends Add to the end of a note's contents.
type OpInsertContent ¶ added in v0.0.4
OpInsertContent inserts Content at a Index within a note's contents.
type OpRemoveContent ¶ added in v0.0.4
OpRemoveContent removes Content from a note's contents.
type OpSetValue ¶ added in v0.0.4
OpSetValue sets the value and data type of a note to Lexical and Datatype.
type OpSetValueString ¶ added in v0.0.4
OpSetValueString sets the value of a note to Lexical.
type OpSwapContent ¶ added in v0.0.4
OpSwapContent swaps the notes at indices A and B within a note's contents.
type Operation ¶ added in v0.0.3
Operation is implemented by types that can describe changes that might be made to a note map.
func Diff ¶ added in v0.0.4
func Diff(a, b TruncatedNote) []Operation
Diff produces a set of operations that if applied to a would make it match b.
Differences in ID are not considered: a and b are not required to have the same ID, and applying the operations to a will not cause it to have the same ID as b.
type OperationSlice ¶ added in v0.0.4
type OperationSlice []Operation
func (OperationSlice) AddContent ¶ added in v0.0.4
func (os OperationSlice) AddContent(id ID, cs ...ID) OperationSlice
AddContent returns a new OperationSlice that also appends cs to the contents of note id.
func (OperationSlice) InsertContent ¶ added in v0.0.4
func (os OperationSlice) InsertContent(id ID, index int, cs ...ID) OperationSlice
InsertContent returns a new OperationSlice that also inserts cs to the contents of note id at index.
func (OperationSlice) RemoveContent ¶ added in v0.0.4
func (os OperationSlice) RemoveContent(id ID, cs ...ID) OperationSlice
RemoveContent returns a new OperationSlice that also removes cs from the contents of note id.
func (OperationSlice) SetValue ¶ added in v0.0.4
func (os OperationSlice) SetValue(id ID, vs string, vt ID) OperationSlice
SetValue returns a new OperationSlice that also sets the value and type of note id to vs and vt.
func (OperationSlice) SetValueString ¶ added in v0.0.4
func (os OperationSlice) SetValueString(id ID, vs string) OperationSlice
SetValue returns a new OperationSlice that also sets the value of note id to vs.
func (OperationSlice) SwapContent ¶ added in v0.0.4
func (os OperationSlice) SwapContent(id ID, a, b int) OperationSlice
SwapContent returns a new OperationSlice that also swaps the contents of note id and indices a and b.
type Patcher ¶
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 Stage ¶
type Stage struct {
Ops OperationSlice
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.
type StageNote ¶
StageNote supports updating the content of a note within a batch, and also implements the GraphNote interface to read the hypothetical state of a note with the batch applied.
func (*StageNote) AddContent ¶
AddContent expands the staged operations to add content to this note.
func (*StageNote) GetContents ¶
type TruncatedNote ¶ added in v0.0.4
TruncatedNote is a minimal representation of a note intended for storage integrations and for algorithms that don't need to traverse a graph of notes.
func TruncateNote ¶ added in v0.0.4
func TruncateNote(n GraphNote) (TruncatedNote, error)
TruncateNote returns a TruncatedNote representation of n.
func (TruncatedNote) Equals ¶ added in v0.0.4
func (x TruncatedNote) Equals(y TruncatedNote) bool
Equals return true if and only if x is deeply equal to y.