service

package
v0.25.5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const LatestWalSchemaID uint16 = 7

IMPORTANT: bump cloud version

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(wt WebTokenStore, args map[string]string) error

func BuildByteWal added in v0.25.3

func BuildByteWal(el []EventLog) (*bytes.Buffer, error)

func BuildWalFromPlainText

func BuildWalFromPlainText(ctx context.Context, wf WalFile, r io.Reader, isHidden bool) error

BuildWalFromPlainText accepts an io.Reader with line separated plain text, and generates a wal db file which is dumped in fzn root directory.

func GetCommonSearchPrefixAndFriends added in v0.22.0

func GetCommonSearchPrefixAndFriends(selectedItems map[string]ListItem) [][]rune

func GetNewLinePrefix

func GetNewLinePrefix(search [][]rune) string

func MatchFirstURL added in v0.22.0

func MatchFirstURL(line string, ensureScheme bool) string

func Min added in v0.22.0

func Min(a, b int) int

func ParseOperatorGroups added in v0.22.0

func ParseOperatorGroups(sub string) string

Types

type Client

type Client interface {
	HandleEvent(interface{}) error
	AwaitEvent() interface{}
}

type ClientBase added in v0.22.0

type ClientBase struct {
	Search [][]rune

	CurItem                               *ListItem // The currently selected item
	Editor                                string
	W, H                                  int
	ReservedTopLines, ReservedBottomLines int
	CurX, CurY                            int // Cur "screen" index, not related to matched item lists
	VertOffset                            int // The index of the first displayed item in the match set
	HorizOffset                           int // The index of the first displayed char in the curItem
	ShowHidden                            bool
	SelectedItems                         map[string]ListItem

	HiddenMatchPrefix string // The common string that we want to truncate from each line
	// contains filtered or unexported fields
}

ClientBase ...

func NewClientBase added in v0.22.0

func NewClientBase(db *DBListRepo, maxWidth int, maxHeight int, useClientSearch bool) *ClientBase

NewClientBase ...

func (*ClientBase) GetSearchGroupIdxAndOffset added in v0.22.0

func (t *ClientBase) GetSearchGroupIdxAndOffset() (int, int)

GetSearchGroupIdxAndOffset returns the group index and offset within that group, respectively. This might have unpredictable results if called on non-search lines (e.g. when CurY != 0)

func (*ClientBase) GetUnsearchedFriends added in v0.22.0

func (t *ClientBase) GetUnsearchedFriends(friends []string) []string

func (*ClientBase) HandleInteraction added in v0.22.0

func (t *ClientBase) HandleInteraction(ev InteractionEvent, search [][]rune, showHidden bool, bypassRefresh bool, limit int) ([]ListItem, bool, error)

TODO rename "t"

func (*ClientBase) TrimPrefix added in v0.22.0

func (t *ClientBase) TrimPrefix(line string) string

TrimPrefix ...

type DBListRepo

type DBListRepo struct {

	// TODO better naming convention
	LocalWalFile LocalWalFile
	// contains filtered or unexported fields
}

func NewDBListRepo

func NewDBListRepo(localWalFile LocalWalFile, webTokenStore WebTokenStore) *DBListRepo

NewDBListRepo returns a pointer to a new instance of DBListRepo

func (*DBListRepo) Add

func (r *DBListRepo) Add(line string, note []byte, childItem *ListItem) (string, error)

Add adds a new LineItem with string, note and a position to insert the item into the matched list It returns a string representing the unique key of the newly created item

func (*DBListRepo) AddWalFile added in v0.22.0

func (r *DBListRepo) AddWalFile(wf WalFile, hasFullAccess bool)

func (*DBListRepo) DebugWriteEventsToFile added in v0.22.0

func (r *DBListRepo) DebugWriteEventsToFile(filename string, key string)

DebugWriteEventsToFile is used for debug purposes. It prints all events for the given uuid/lamportTimestamp combination to file, for inspection

func (*DBListRepo) Delete

func (r *DBListRepo) Delete(item *ListItem) (string, error)

Delete will remove an existing ListItem

func (*DBListRepo) DeleteWalFile added in v0.22.0

func (r *DBListRepo) DeleteWalFile(name string)

func (*DBListRepo) EmitCursorMoveEvent added in v0.22.0

func (r *DBListRepo) EmitCursorMoveEvent(key string)

func (*DBListRepo) ExportToPlainText

func (r *DBListRepo) ExportToPlainText(matchKeys [][]rune, showHidden bool) error

func (*DBListRepo) ForceTriggerFlush added in v0.23.0

func (r *DBListRepo) ForceTriggerFlush()

ForceTriggerFlush will zero the flush timer, and block til completion. E.g. this is a synchronous flush

func (*DBListRepo) GetCollabPositions

func (r *DBListRepo) GetCollabPositions() map[string][]string

GetCollabPositions returns a map of listItemKeys against all collaborators currently on that listItem

func (*DBListRepo) GetFriendFromConfig added in v0.24.0

func (r *DBListRepo) GetFriendFromConfig(item ListItem) (string, bool)

func (*DBListRepo) GetFriendState added in v0.24.0

func (r *DBListRepo) GetFriendState(f string) FriendState

func (*DBListRepo) GetListItem added in v0.22.0

func (r *DBListRepo) GetListItem(key string) (ListItem, bool)

func (*DBListRepo) GetListItemNote added in v0.22.0

func (r *DBListRepo) GetListItemNote(key string) []byte

func (*DBListRepo) GetSyncState added in v0.24.0

func (r *DBListRepo) GetSyncState() SyncState

func (*DBListRepo) IsSynced added in v0.23.0

func (r *DBListRepo) IsSynced() bool

IsSynced is a boolean value defining whether or now there are currently events held in memory that are yet to be flushed to local storage

func (*DBListRepo) Match

func (r *DBListRepo) Match(keys [][]rune, showHidden bool, curKey string, offset int, limit int) ([]ListItem, int, error)

Match takes a set of search groups and applies each to all ListItems, returning those that fulfil all rules. `showHidden` dictates whether or not hidden items are returned. `curKey` is used to identify the currently selected item. `offset` and `limit` can be passed to paginate over the match-set, if `limit==0`, all matches from `offset` will be returned (e.g. no limit will be applied).

func (*DBListRepo) MoveDown

func (r *DBListRepo) MoveDown(item *ListItem) error

MoveDown will swop a ListItem with the ListItem directly below it, taking visibility and current matches into account.

func (*DBListRepo) MoveUp

func (r *DBListRepo) MoveUp(item *ListItem) error

MoveUp will swop a ListItem with the ListItem directly above it, taking visibility and current matches into account.

func (*DBListRepo) Redo

func (r *DBListRepo) Redo() (string, error)

func (*DBListRepo) Replay

func (r *DBListRepo) Replay(partialWal []EventLog) error

Replay updates listItems based on the current state of the local WAL logs. It generates or updates the linked list which is attached to DBListRepo.Root

func (*DBListRepo) SaveListItemNote added in v0.22.0

func (r *DBListRepo) SaveListItemNote(key string, note []byte)

func (*DBListRepo) SetCollabPosition

func (r *DBListRepo) SetCollabPosition(ev cursorMoveEvent) bool

func (*DBListRepo) Start

func (r *DBListRepo) Start(client Client) error

Start begins push/pull for all WalFiles

func (*DBListRepo) TestPullLocal added in v0.25.0

func (r *DBListRepo) TestPullLocal(c chan namedWal) error

func (*DBListRepo) ToggleVisibility

func (r *DBListRepo) ToggleVisibility(item *ListItem) (string, error)

ToggleVisibility will toggle an item to be visible or invisible

func (*DBListRepo) Undo

func (r *DBListRepo) Undo() (string, error)

func (*DBListRepo) Update

func (r *DBListRepo) Update(line string, item *ListItem) error

Update will update the line or note of an existing ListItem

func (*DBListRepo) UpdateNote added in v0.25.0

func (r *DBListRepo) UpdateNote(note []byte, item *ListItem) error

TODO rethink this interface

type DbEventLogger

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

DbEventLogger is used for in-mem undo/redo mechanism

func NewDbEventLogger

func NewDbEventLogger() *DbEventLogger

NewDbEventLogger Returns a new instance of DbEventLogger

type EventLog

type EventLog struct {
	UUID                           uuid // origin UUID
	LamportTimestamp               int64
	EventType                      EventType
	ListItemKey, TargetListItemKey string
	Line                           string
	Note                           []byte
	IsHidden                       bool
	Friends                        LineFriends
	// contains filtered or unexported fields
}

func BuildFromFileTreeSchema added in v0.25.3

func BuildFromFileTreeSchema(walSchemaVersionID uint16, raw io.Reader) ([]EventLog, uint16, error)

BuildFromFileTreeSchema parses wals with schema v7 or higher

type EventLogSchema4 added in v0.22.0

type EventLogSchema4 struct {
	UUID, TargetUUID           uuid
	ListItemCreationTime       int64
	TargetListItemCreationTime int64
	UnixNanoTime               int64
	EventType                  EventType
	Line                       string
	Note                       []byte
	Friends                    LineFriendsSchema4
	// contains filtered or unexported fields
}

type EventLogSchema5 added in v0.22.0

type EventLogSchema5 struct {
	UUID, TargetUUID           uuid
	ListItemCreationTime       int64
	TargetListItemCreationTime int64
	UnixNanoTime               int64
	EventType                  EventType
	Line                       string
	Note                       []byte
	Friends                    LineFriends
	// contains filtered or unexported fields
}

type EventLogSchema6 added in v0.25.0

type EventLogSchema6 struct {
	UUID                           uuid // origin UUID
	LamportTimestamp               int64
	EventType                      EventType
	ListItemKey, TargetListItemKey string
	Line                           string
	Note                           []byte
	Friends                        LineFriends
	// contains filtered or unexported fields
}

type EventType

type EventType uint16
const (
	NullEvent EventType = iota
	AddEvent
	UpdateEvent
	MoveUpEvent
	MoveDownEvent
	ShowEvent
	HideEvent
	DeleteEvent
	PositionEvent
)

Ordering of these enums are VERY IMPORTANT as they're used for comparisons when resolving WAL merge conflicts

type FileWebTokenStore

type FileWebTokenStore struct {
	User    string `yaml:"user"`
	Refresh string `yaml:"refreshToken"`
	ID      string `yaml:"idToken"`
	// contains filtered or unexported fields
}

func NewFileWebTokenStore

func NewFileWebTokenStore(root string) *FileWebTokenStore

func (*FileWebTokenStore) Email added in v0.22.0

func (wt *FileWebTokenStore) Email() string

func (*FileWebTokenStore) Flush

func (wt *FileWebTokenStore) Flush()

func (*FileWebTokenStore) IDToken

func (wt *FileWebTokenStore) IDToken() string

func (*FileWebTokenStore) RefreshToken

func (wt *FileWebTokenStore) RefreshToken() string

func (*FileWebTokenStore) SetEmail added in v0.22.0

func (wt *FileWebTokenStore) SetEmail(s string)

TODO reconsider this interface...

func (*FileWebTokenStore) SetIDToken

func (wt *FileWebTokenStore) SetIDToken(s string)

func (*FileWebTokenStore) SetRefreshToken

func (wt *FileWebTokenStore) SetRefreshToken(s string)

type FinishWithPurgeError added in v0.23.0

type FinishWithPurgeError struct{}

func (FinishWithPurgeError) Error added in v0.23.0

func (e FinishWithPurgeError) Error() string

type FriendState added in v0.24.0

type FriendState int
const (
	FriendNull FriendState = iota
	FriendPending
	FriendActive
)

type InteractionEvent added in v0.22.0

type InteractionEvent struct {
	T   InteractionEventType
	Key string
	R   []rune
}

InteractionEvent ...

type InteractionEventType added in v0.22.0

type InteractionEventType uint32

InteractionEventType ...

const (
	KeyNull InteractionEventType = iota
	KeyEscape
	KeyEnter
	KeyDeleteItem
	KeyOpenNote
	KeyGotoStart
	KeyGotoEnd
	KeyVisibility
	KeyUndo
	KeyRedo
	KeyCopy
	KeyPaste
	KeyOpenURL
	KeyExport
	KeySelect
	KeyAddSearchGroup
	KeyBackspace
	KeyDelete
	KeyMoveItemUp
	KeyMoveItemDown
	KeyCursorDown
	KeyCursorUp
	KeyCursorRight
	KeyCursorLeft
	KeyRune

	SetText
)

type LegacyListItem added in v0.25.0

type LegacyListItem struct {
	Note []byte

	IsHidden bool
	// contains filtered or unexported fields
}

type LineFriends added in v0.22.0

type LineFriends struct {
	IsProcessed bool
	Offset      int
	Emails      []string
	// contains filtered or unexported fields
}

type LineFriendsSchema4 added in v0.22.0

type LineFriendsSchema4 struct {
	IsProcessed bool
	Offset      int
	Emails      map[string]struct{}
}

type ListItem

type ListItem struct {
	Note     []byte // TODO make private
	IsHidden bool
	// contains filtered or unexported fields
}

ListItem is a mergeable data structure which represents a single item in the main list. It maintains record of the last update lamport times

func (*ListItem) Friends added in v0.22.0

func (i *ListItem) Friends() []string

func (*ListItem) Key

func (i *ListItem) Key() string

TODO make attribute public directly??

func (*ListItem) Line

func (i *ListItem) Line() string

Line returns a post-processed rawLine, with any matched collaborators omitted

type LocalFileWalFile

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

func NewLocalFileWalFile

func NewLocalFileWalFile(rootDir string) *LocalFileWalFile

func (*LocalFileWalFile) Flush

func (wf *LocalFileWalFile) Flush(ctx context.Context, b *bytes.Buffer, randomUUID string) error

func (*LocalFileWalFile) GetMatchingWals

func (wf *LocalFileWalFile) GetMatchingWals(ctx context.Context, matchPattern string) ([]string, error)

func (*LocalFileWalFile) GetRoot

func (wf *LocalFileWalFile) GetRoot() string

func (*LocalFileWalFile) GetUUID

func (wf *LocalFileWalFile) GetUUID() string

func (*LocalFileWalFile) GetWalBytes

func (wf *LocalFileWalFile) GetWalBytes(ctx context.Context, w io.Writer, fileName string) error

func (*LocalFileWalFile) Purge

func (wf *LocalFileWalFile) Purge()

func (*LocalFileWalFile) RemoveWals

func (wf *LocalFileWalFile) RemoveWals(ctx context.Context, fileNames []string) error

type LocalWalFile

type LocalWalFile interface {
	Purge()

	WalFile
}

type MatchPattern added in v0.22.0

type MatchPattern int
const (
	FullMatchPattern MatchPattern = iota
	InverseMatchPattern
	FuzzyMatchPattern
	NoMatchPattern
)

func GetMatchPattern

func GetMatchPattern(sub []rune) (MatchPattern, int)

GetMatchPattern will return the MatchPattern of a given string, if any, plus the number of chars that can be omitted to leave only the relevant text

type RefreshKey added in v0.24.0

type RefreshKey struct {
	AllowOverride bool
	ChangedKeys   map[string]struct{}
}

type SyncEvent added in v0.24.0

type SyncEvent struct{}

type SyncState added in v0.24.0

type SyncState int
const (
	SyncOffline SyncState = iota
	SyncSyncing
	SyncSynced
)

type WalFile

type WalFile interface {
	GetUUID() string
	GetRoot() string
	GetMatchingWals(context.Context, string) ([]string, error)
	GetWalBytes(context.Context, io.Writer, string) error
	RemoveWals(context.Context, []string) error
	Flush(context.Context, *bytes.Buffer, string) error
}

WalFile offers a generic interface into local or remote filesystems

type Web

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

func NewWeb

func NewWeb(webTokens WebTokenStore) *Web

func (*Web) CallWithReAuth

func (w *Web) CallWithReAuth(req *http.Request) (*http.Response, error)

CallWithReAuth accepts a pre-built request, attempts to call it, and if it fails authorisation due to an expired IDToken, will reauth, and then retry the original function.

type WebRemote

type WebRemote struct {
	Emails       []string
	DTLastChange int64
}

type WebTokenStore

type WebTokenStore interface {
	SetEmail(string)
	SetRefreshToken(string)
	SetIDToken(string)
	Email() string
	RefreshToken() string
	IDToken() string
	Flush()
}

type WebWalFile

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

func (*WebWalFile) Flush

func (wf *WebWalFile) Flush(ctx context.Context, b *bytes.Buffer, checksum string) error

func (*WebWalFile) GetMatchingWals

func (wf *WebWalFile) GetMatchingWals(ctx context.Context, pattern string) ([]string, error)

func (*WebWalFile) GetRoot

func (wf *WebWalFile) GetRoot() string

func (*WebWalFile) GetUUID

func (wf *WebWalFile) GetUUID() string

func (*WebWalFile) GetWalBytes

func (wf *WebWalFile) GetWalBytes(ctx context.Context, w io.Writer, fileName string) error

func (*WebWalFile) RemoveWals

func (wf *WebWalFile) RemoveWals(ctx context.Context, fileNames []string) error

Jump to

Keyboard shortcuts

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