note

package
v0.0.0-...-e5515f0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: AGPL-3.0 Imports: 26 Imported by: 6

Documentation

Overview

Package note is the glue between the prosemirror models, the VFS, redis, the hub for realtime, etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSchema is used when the schema cannot be read by prosemirror.
	ErrInvalidSchema = errors.New("Invalid schema for prosemirror")
	// ErrInvalidFile is used when a file doesn't have the metadata to be used
	// as a note.
	ErrInvalidFile = errors.New("Invalid file, not a note")
	// ErrNoSteps is used when steps are expected, but there are none.
	ErrNoSteps = errors.New("No steps")
	// ErrInvalidSteps is used when prosemirror can't instantiate the steps.
	ErrInvalidSteps = errors.New("Invalid steps")
	// ErrCannotApply is used when trying to apply some steps, but it fails
	// because of a conflict. The client can try to rebase the steps.
	ErrCannotApply = errors.New("Cannot apply the steps")
	// ErrTooOld is used when the steps just after the given revision are no
	// longer available.
	ErrTooOld = errors.New("The revision is too old")
	// ErrMissingSessionID is used when a telepointer has no identifier.
	ErrMissingSessionID = errors.New("The session id is missing")
)

Functions

func ApplySteps

func ApplySteps(inst *instance.Instance, file *vfs.FileDoc, lastVersion string, steps []Step) (*vfs.FileDoc, error)

ApplySteps takes a note and some steps, and tries to apply them. It is an all or nothing change: if there is one error, the note won't be changed.

func Create

func Create(inst *instance.Instance, doc *Document) (*vfs.FileDoc, error)

Create the file in the VFS for this note.

func GetFile

func GetFile(inst *instance.Instance, file *vfs.FileDoc) (*vfs.FileDoc, error)

GetFile takes a file from the VFS as a note and returns its last version. It is useful when some changes have not yet been persisted to the VFS.

func List

func List(inst *instance.Instance, bookmark string) ([]*vfs.FileDoc, string, error)

List returns a list of notes sorted by descending updated_at. It uses pagination via a mango bookmark.

func PutTelepointer

func PutTelepointer(inst *instance.Instance, t Event) error

PutTelepointer sends the position of a pointer in the realtime hub.

func Update

func Update(inst *instance.Instance, fileID string) error

Update is used to persist changes on a note to its file in the VFS.

func UpdateMetadataFromCache

func UpdateMetadataFromCache(inst *instance.Instance, docs []*vfs.FileDoc)

UpdateMetadataFromCache update the metadata for a file/note with the information in cache.

func UpdateTitle

func UpdateTitle(inst *instance.Instance, file *vfs.FileDoc, title, sessionID string) (*vfs.FileDoc, error)

UpdateTitle changes the title of a note and renames the associated file.

Types

type DebounceMessage

type DebounceMessage struct {
	NoteID string `json:"note_id"`
}

DebounceMessage is used by the trigger for saving the note to the VFS with a debounce.

type Document

type Document struct {
	DocID      string                 `json:"_id"`
	DocRev     string                 `json:"_rev,omitempty"`
	CreatedBy  string                 `json:"-"`
	DirID      string                 `json:"dir_id,omitempty"` // Only used at creation
	Title      string                 `json:"title"`
	Version    int64                  `json:"version"`
	SchemaSpec map[string]interface{} `json:"schema"`
	RawContent map[string]interface{} `json:"content"`
	// contains filtered or unexported fields
}

Document is the note document in memory. It is persisted to the VFS as a file, but with a debounce: the intermediate states are saved in Redis.

func (*Document) Clone

func (d *Document) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (*Document) Content

func (d *Document) Content() (*model.Node, error)

Content returns the prosemirror content for this note.

func (*Document) DocType

func (d *Document) DocType() string

DocType returns the document type

func (*Document) GetDirID

func (d *Document) GetDirID(inst *instance.Instance) (string, error)

GetDirID returns the ID of the directory where the note will be created.

func (*Document) ID

func (d *Document) ID() string

ID returns the document qualified identifier

func (*Document) Markdown

func (d *Document) Markdown() ([]byte, error)

Markdown returns a markdown serialization of the content.

func (*Document) Metadata

func (d *Document) Metadata() map[string]interface{}

Metadata returns the file metadata for this note.

func (*Document) Rev

func (d *Document) Rev() string

Rev returns the document revision

func (*Document) Schema

func (d *Document) Schema() (*model.Schema, error)

Schema returns the prosemirror schema for this note

func (*Document) SetContent

func (d *Document) SetContent(content *model.Node)

SetContent updates the content of this note, and clears the cache.

func (*Document) SetID

func (d *Document) SetID(id string)

SetID changes the document qualified identifier

func (*Document) SetRev

func (d *Document) SetRev(rev string)

SetRev changes the document revision

type Event

type Event map[string]interface{}

Event is a realtime event for a note (like the update of the position of a pointer).

func (Event) Clone

func (e Event) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (Event) DocType

func (e Event) DocType() string

DocType returns the document type

func (Event) ID

func (e Event) ID() string

ID returns the event qualified identifier

func (Event) Included

func (e Event) Included() []jsonapi.Object

Included is part of the jsonapi.Object interface

func (e Event) Links() *jsonapi.LinksList

Links is part of the jsonapi.Object interface

func (Event) Relationships

func (e Event) Relationships() jsonapi.RelationshipMap

Relationships is part of the jsonapi.Object interface

func (Event) Rev

func (e Event) Rev() string

Rev returns the event revision

func (Event) SetID

func (e Event) SetID(id string)

SetID changes the event qualified identifier

func (Event) SetRev

func (e Event) SetRev(rev string)

SetRev changes the event revision

type Opener

type Opener struct {
	// contains filtered or unexported fields
}

Opener can be used to find the parameters for creating the URL where the note can be opened.

func Open

func Open(inst *instance.Instance, fileID string) (*Opener, error)

Open will return an Opener for the given file.

func (*Opener) AddShareByLinkCode

func (o *Opener) AddShareByLinkCode(code string)

AddShareByLinkCode can be used to give a sharecode that can be used to open the note, when the note is in a directory shared by link.

func (*Opener) CheckPermission

func (o *Opener) CheckPermission(pdoc *permission.Permission, sharingID string) error

CheckPermission takes the permission doc, and checks that the user has the right to open the note.

func (*Opener) GetResult

func (o *Opener) GetResult(memberIndex int, readOnly bool) (jsonapi.Object, error)

GetResult looks if the note can be opened locally or not, which code can be used in case of a shared note, and other parameters.. and returns the information.

type Step

type Step map[string]interface{}

Step is a patch to apply on a note.

func GetSteps

func GetSteps(inst *instance.Instance, fileID string, version int64) ([]Step, error)

GetSteps returns the steps for the given note, starting from the version.

func (Step) Clone

func (s Step) Clone() couchdb.Doc

Clone implements couchdb.Doc

func (Step) DocType

func (s Step) DocType() string

DocType returns the document type

func (Step) ID

func (s Step) ID() string

ID returns the step qualified identifier

func (Step) Included

func (s Step) Included() []jsonapi.Object

Included is part of the jsonapi.Object interface

func (s Step) Links() *jsonapi.LinksList

Links is part of the jsonapi.Object interface

func (Step) Relationships

func (s Step) Relationships() jsonapi.RelationshipMap

Relationships is part of the jsonapi.Object interface

func (Step) Rev

func (s Step) Rev() string

Rev returns the step revision

func (Step) SetID

func (s Step) SetID(id string)

SetID changes the step qualified identifier

func (Step) SetRev

func (s Step) SetRev(rev string)

SetRev changes the step revision

Jump to

Keyboard shortcuts

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