notes

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 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.

Index

Constants

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

Variables

View Source
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

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

func (EmptyNote) GetID added in v0.0.3

func (x EmptyNote) GetID() ID

func (EmptyNote) GetValue

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

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) ([]GraphNote, error)
}

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.

func LoadOne

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

LoadOne is a convenience function for loading just one note.

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) ([]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.

func (Op) AffectsID added in v0.0.4

func (x Op) AffectsID(id ID) bool

AffectsID returns true if x could change a note with ID==id.

func (Op) GetID added in v0.0.4

func (x Op) GetID() ID

type OpAddContent added in v0.0.4

type OpAddContent struct {
	Op
	Add ID
}

OpAddContent appends Add to the end of a note's contents.

type OpInsertContent added in v0.0.4

type OpInsertContent struct {
	Op
	Content ID
	Index   int
}

OpInsertContent inserts Content at a Index within a note's contents.

type OpRemoveContent added in v0.0.4

type OpRemoveContent struct {
	Op
	Content ID
}

OpRemoveContent removes Content from a note's contents.

type OpSetValue added in v0.0.4

type OpSetValue struct {
	Op
	Lexical  string
	Datatype ID
}

OpSetValue sets the value and data type of a note to Lexical and Datatype.

type OpSetValueString added in v0.0.4

type OpSetValueString struct {
	Op
	Lexical string
}

OpSetValueString sets the value of a note to Lexical.

type OpSwapContent added in v0.0.4

type OpSwapContent struct {
	Op
	A, B int
}

OpSwapContent swaps the notes at indices A and B within a note's contents.

type Operation added in v0.0.3

type Operation interface {
	AffectsID(id ID) bool
}

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

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 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.

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() 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 GraphNote 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() ([]GraphNote, error)

func (*StageNote) GetID added in v0.0.3

func (x *StageNote) GetID() ID

func (*StageNote) GetValue

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

func (*StageNote) SetValue

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

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

type TruncatedNote added in v0.0.4

type TruncatedNote struct {
	ID          ID
	ValueString string
	ValueType   ID
	Contents    []ID
}

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.

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