Documentation
¶
Overview ¶
Package backend is the seam that lets every zn command and the terminal UI work against a vault on this machine or one behind a self-hosted ZenNotes server: the same operations, bound either to a root on disk or to a server over HTTP.
Index ¶
- Constants
- Variables
- func LooksLikeServerURL(value string) bool
- func RememberTarget(t Target) error
- func ResolveAuthToken(flagToken, profileToken string) string
- func ResolveAuthTokenFor(baseURL, flagToken, profileToken string) string
- func ResolveAuthTokenForSource(baseURL, flagToken, profileToken, source string) string
- func ResolveWorkspaceSource(source string) (string, error)
- func RewriteNote(ctx context.Context, b Backend, rel string, ...) (vault.NoteMeta, bool, error)
- func SameServer(a, b Target) bool
- func SameVault(a, b Target) bool
- func TemplateFolder(ctx context.Context, b Backend) string
- func UpdateTask(ctx context.Context, b Backend, in UpdateTaskInput) (*vault.Task, error)
- type AddCommentInput
- type AssetLinkRewriter
- type AssetManager
- type Backend
- type CommentThreadView
- func AddComment(ctx context.Context, b Backend, in AddCommentInput) (CommentThreadView, error)
- func ListCommentThreads(ctx context.Context, b Backend, rel string, includeResolved bool) ([]CommentThreadView, error)
- func ReplyToComment(ctx context.Context, b Backend, in ReplyInput) (CommentThreadView, error)
- func ResolveComment(ctx context.Context, b Backend, rel, id string, resolved bool) (CommentThreadView, error)
- type CommentView
- type Description
- type Kind
- type Local
- func (l *Local) AppendToNote(_ context.Context, rel, text string) (vault.NoteMeta, error)
- func (l *Local) ArchiveNote(_ context.Context, rel string) (vault.NoteMeta, error)
- func (l *Local) Backlinks(_ context.Context, rel string) ([]vault.NoteMeta, error)
- func (l *Local) CreateFolder(_ context.Context, folder vault.NoteFolder, subpath string) error
- func (l *Local) CreateNote(_ context.Context, folder vault.NoteFolder, title, subpath string, ...) (vault.NoteMeta, error)
- func (l *Local) DatabaseOps() *database.Ops
- func (l *Local) DeleteAsset(_ context.Context, p string) (vault.DeletedAsset, error)
- func (l *Local) DeleteFolder(_ context.Context, folder vault.NoteFolder, subpath string) error
- func (l *Local) DeleteNote(_ context.Context, rel string) error
- func (l *Local) DeleteTemplate(_ context.Context, sourcePath string) error
- func (l *Local) Describe(context.Context) (Description, error)
- func (l *Local) DuplicateAsset(_ context.Context, p string) (vault.AssetMeta, error)
- func (l *Local) DuplicateNote(_ context.Context, rel string) (vault.NoteMeta, error)
- func (l *Local) EmptyTrash(context.Context) error
- func (l *Local) ImportAsset(_ context.Context, note, name string, r io.Reader) (vault.ImportedAsset, error)
- func (l *Local) InsertAtLine(_ context.Context, rel string, lineNumber int, text string) (vault.NoteMeta, error)
- func (l *Local) Kind() Kind
- func (l *Local) Label() string
- func (l *Local) LinkedSystemFolders(context.Context) ([]string, error)
- func (l *Local) ListAssets(context.Context) ([]vault.AssetMeta, error)
- func (l *Local) ListComments(_ context.Context, rel string) ([]vault.NoteComment, error)
- func (l *Local) ListDatabaseDirs(context.Context) ([]vault.FolderEntry, error)
- func (l *Local) ListDeletedAssets(_ context.Context) ([]vault.DeletedAsset, error)
- func (l *Local) ListFolders(context.Context) ([]vault.FolderEntry, error)
- func (l *Local) ListNotes(context.Context) ([]vault.NoteMeta, error)
- func (l *Local) ListTemplates(context.Context) ([]vault.CustomTemplateFile, error)
- func (l *Local) MoveAsset(_ context.Context, p, dir string) (vault.AssetMeta, error)
- func (l *Local) MoveAssetRewritingLinksIn(_ context.Context, p, dir string, rewrite func(path string) bool) (vault.AssetMeta, error)
- func (l *Local) MoveNote(_ context.Context, rel string, folder vault.NoteFolder, subpath string) (vault.NoteMeta, error)
- func (l *Local) MoveToTrash(_ context.Context, rel string) (vault.NoteMeta, error)
- func (l *Local) PrependToNote(_ context.Context, rel, text string) (vault.NoteMeta, error)
- func (l *Local) ReadAsset(_ context.Context, rel string) ([]byte, error)
- func (l *Local) ReadNote(_ context.Context, rel string) (vault.NoteContent, error)
- func (l *Local) RenameAsset(_ context.Context, p, n string) (vault.AssetMeta, error)
- func (l *Local) RenameAssetRewritingLinksIn(_ context.Context, p, n string, rewrite func(path string) bool) (vault.AssetMeta, error)
- func (l *Local) RenameFolder(_ context.Context, folder vault.NoteFolder, oldSubpath, newSubpath string) (string, error)
- func (l *Local) RenameNote(ctx context.Context, rel, nextTitle string) (vault.NoteMeta, error)
- func (l *Local) RenameNoteRewritingLinksIn(_ context.Context, rel, nextTitle string, rewrite func(path string) bool) (vault.NoteMeta, error)
- func (l *Local) ReplaceInNote(_ context.Context, rel, find, replace string, all bool) (vault.NoteMeta, int, error)
- func (l *Local) RestoreDeletedAsset(_ context.Context, d vault.DeletedAsset) (vault.AssetMeta, error)
- func (l *Local) RestoreFromTrash(_ context.Context, rel string) (vault.NoteMeta, error)
- func (l *Local) Root() string
- func (l *Local) ScanTasks(_ context.Context, opts vault.ParseTasksOptions) ([]vault.Task, error)
- func (l *Local) ScanTasksForPath(_ context.Context, rel string, opts vault.ParseTasksOptions) ([]vault.Task, error)
- func (l *Local) SearchText(_ context.Context, query string, limit int) ([]vault.TextSearchMatch, error)
- func (l *Local) ToggleTask(_ context.Context, taskID string, dialect vault.TaskDialect) (*vault.Task, error)
- func (l *Local) UnarchiveNote(_ context.Context, rel string) (vault.NoteMeta, error)
- func (l *Local) UpdateVaultSettings(_ context.Context, patch func(raw map[string]any)) error
- func (l *Local) Vault() *vault.Vault
- func (l *Local) VaultSettings(context.Context) (vault.VaultSettings, error)
- func (l *Local) WriteComments(_ context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
- func (l *Local) WriteNote(_ context.Context, rel, body string) (vault.NoteMeta, error)
- func (l *Local) WriteNoteIfUnchanged(_ context.Context, rel, body, _ string) (vault.NoteMeta, error)
- func (l *Local) WriteTemplate(_ context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
- type Options
- type Remote
- func (r *Remote) AppendToNote(ctx context.Context, rel, text string) (vault.NoteMeta, error)
- func (r *Remote) ArchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (r *Remote) Backlinks(ctx context.Context, rel string) ([]vault.NoteMeta, error)
- func (r *Remote) Capabilities(ctx context.Context) (map[string]any, error)
- func (r *Remote) Client() *remote.Client
- func (r *Remote) CreateFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error
- func (r *Remote) CreateNote(ctx context.Context, folder vault.NoteFolder, title, subpath string, ...) (vault.NoteMeta, error)
- func (r *Remote) DatabaseOps() *database.Ops
- func (r *Remote) DeleteAsset(ctx context.Context, p string) (vault.DeletedAsset, error)
- func (r *Remote) DeleteFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error
- func (r *Remote) DeleteNote(ctx context.Context, rel string) error
- func (r *Remote) DeleteTemplate(ctx context.Context, sourcePath string) error
- func (r *Remote) Describe(ctx context.Context) (Description, error)
- func (r *Remote) DuplicateAsset(ctx context.Context, p string) (vault.AssetMeta, error)
- func (r *Remote) DuplicateNote(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (r *Remote) EmptyTrash(ctx context.Context) error
- func (r *Remote) ImportAsset(ctx context.Context, note, name string, body io.Reader) (vault.ImportedAsset, error)
- func (r *Remote) InsertAtLine(ctx context.Context, rel string, lineNumber int, text string) (vault.NoteMeta, error)
- func (r *Remote) Kind() Kind
- func (r *Remote) Label() string
- func (r *Remote) LinkedSystemFolders(ctx context.Context) ([]string, error)
- func (r *Remote) ListAssets(ctx context.Context) ([]vault.AssetMeta, error)
- func (r *Remote) ListComments(ctx context.Context, rel string) ([]vault.NoteComment, error)
- func (r *Remote) ListDeletedAssets(ctx context.Context) ([]vault.DeletedAsset, error)
- func (r *Remote) ListFolders(ctx context.Context) ([]vault.FolderEntry, error)
- func (r *Remote) ListNotes(ctx context.Context) ([]vault.NoteMeta, error)
- func (r *Remote) ListTemplates(ctx context.Context) ([]vault.CustomTemplateFile, error)
- func (r *Remote) MoveAsset(ctx context.Context, p, dir string) (vault.AssetMeta, error)
- func (r *Remote) MoveNote(ctx context.Context, rel string, folder vault.NoteFolder, subpath string) (vault.NoteMeta, error)
- func (r *Remote) MoveToTrash(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (r *Remote) PrependToNote(ctx context.Context, rel, text string) (vault.NoteMeta, error)
- func (r *Remote) ReadAsset(ctx context.Context, rel string) ([]byte, error)
- func (r *Remote) ReadNote(ctx context.Context, rel string) (vault.NoteContent, error)
- func (r *Remote) RenameAsset(ctx context.Context, p, n string) (vault.AssetMeta, error)
- func (r *Remote) RenameFolder(ctx context.Context, folder vault.NoteFolder, oldSubpath, newSubpath string) (string, error)
- func (r *Remote) RenameNote(ctx context.Context, rel, nextTitle string) (vault.NoteMeta, error)
- func (r *Remote) ReplaceInNote(ctx context.Context, rel, find, replace string, all bool) (vault.NoteMeta, int, error)
- func (r *Remote) RestoreDeletedAsset(ctx context.Context, d vault.DeletedAsset) (vault.AssetMeta, error)
- func (r *Remote) RestoreFromTrash(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (r *Remote) Root() string
- func (r *Remote) ScanTasks(ctx context.Context, opts vault.ParseTasksOptions) ([]vault.Task, error)
- func (r *Remote) ScanTasksForPath(ctx context.Context, rel string, opts vault.ParseTasksOptions) ([]vault.Task, error)
- func (r *Remote) SearchText(ctx context.Context, query string, limit int) ([]vault.TextSearchMatch, error)
- func (r *Remote) ToggleTask(ctx context.Context, taskID string, dialect vault.TaskDialect) (*vault.Task, error)
- func (r *Remote) UnarchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (r *Remote) UpdateVaultSettings(ctx context.Context, patch func(raw map[string]any)) error
- func (r *Remote) VaultSettings(ctx context.Context) (vault.VaultSettings, error)
- func (r *Remote) WriteComments(ctx context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
- func (r *Remote) WriteNote(ctx context.Context, rel, body string) (vault.NoteMeta, error)
- func (r *Remote) WriteNoteIfUnchanged(ctx context.Context, rel, body, baseSha256 string) (vault.NoteMeta, error)
- func (r *Remote) WriteTemplate(ctx context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
- type ReplyInput
- type Target
- func ResolveDefaultTarget(flagToken string) (Target, error)
- func ResolveServerTarget(selector, flagToken string) (Target, error)
- func ResolveTarget(vaultSelector, serverSelector, flagToken string) (Target, error)
- func ResolveTargetWithSource(vaultSelector, serverSelector, flagToken, source string) (Target, error)
- func ResolveVaultTarget(selector, flagToken string) (Target, error)
- func Served(ctx context.Context, t Target) (Target, error)
- func TargetForWorkspace(ws config.Workspaces, name, flagToken string) (Target, bool)
- type UpdateTaskInput
Constants ¶
const RemoteTokenEnv = "ZENNOTES_REMOTE_TOKEN"
RemoteTokenEnv carries a server token for CI and headless use.
const RewriteAttempts = 3
RewriteAttempts is how many times RewriteNote reads and writes a note before it gives up on a server where the note keeps changing. The desktop's rewriteNoteOnServer stops at the same count.
Variables ¶
var ErrLinkedFoldersUnknown = errors.New("the server does not report linked system folders")
ErrLinkedFoldersUnknown says a server does not report which system folders are links. A current one always sends the list, empty when there are none.
Functions ¶
func LooksLikeServerURL ¶
LooksLikeServerURL is true for a bare URL rather than a profile name: it has a scheme, or looks like `host:port`.
func RememberTarget ¶
RememberTarget makes a target zn's default for next time, saving a path or URL that was typed rather than picked from the list.
func ResolveAuthToken ¶
ResolveAuthToken picks the token, loudest first: an explicit `--token`, then the environment, then whatever the saved profile carries.
func ResolveAuthTokenFor ¶
ResolveAuthTokenFor is ResolveAuthToken with zn's own credential store in the chain: flag, environment, the token `zn connect` saved for the URL, then the desktop profile's token.
func ResolveAuthTokenForSource ¶ added in v0.2.0
ResolveAuthTokenForSource is the token for a server the given source picked. Both sources take `--token`, then the environment. Terminal mode then prefers the token `zn connect` saved for the URL over the desktop profile's. App mode keeps the desktop profile's token first and falls back to the saved one, because the app keeps its own copy in the OS secret store, where zn cannot read it: without the fallback, a desktop-managed zn and its `zn mcp` cannot reach the server the app is connected to at all. The saved token is looked up by the URL the app chose, so it can only authenticate that server, never pick a different one.
func ResolveWorkspaceSource ¶ added in v0.2.0
ResolveWorkspaceSource returns app or terminal, applying the environment default.
func RewriteNote ¶ added in v0.18.2
func RewriteNote(ctx context.Context, b Backend, rel string, edit func(note vault.NoteContent) (string, bool, error)) (vault.NoteMeta, bool, error)
RewriteNote reads a note, changes it with edit and writes the result back on the version it read (ZenNotes/zennotes#1108). Against a server with conditional writes the write names the read's sha256, so a save another device made in between is never written over: the server refuses, and the note is read again and edit applied to the newer text, since an edit here is a function of the body (append a line, replace a word, toggle a task). A few refusals in a row end in a remote.NoteChangedError with nothing written.
edit returns false to write nothing; RewriteNote then returns false too. It may run more than once, so whatever it records for its caller (a count, an id) is from the attempt that was written. A local vault or an older server hands out no hash, so the write is unconditional, exactly as before.
func SameServer ¶ added in v0.16.0
SameServer says two targets are the same server, whichever vault it serves.
func SameVault ¶ added in v0.4.1
SameVault says two targets reach the same vault: the same server serving the same path as far as Served knows, or the same directory however its path is spelled. Tokens and names do not matter: a vault's display name can change in its settings, and it stays that vault.
func TemplateFolder ¶ added in v0.13.1
TemplateFolder is the vault's template folder (ZenNotes/zennotes#1024), "" when it has none or its settings cannot be read. A note inside it contributes no tags, so the tag list and every tag search leave it out (vault.IsPathInTemplateFolder). A server vault reports the folder in its settings like a local one, and the tag list is counted here from the note listing for both, so the same rule covers both.
func UpdateTask ¶ added in v0.16.0
UpdateTask edits one task through the backend's own read and write, so it takes a scope and a server the way any other edit does. It returns the task as it now reads, or nil when the id no longer matches one.
The edit is applied to the task's line on its own: list_tasks numbers tasks by the scan that produced the id (a server's own parser, or the CLI dialect), and the line setters count with the editor's, which reads an unusual fence differently. Editing the line a scan pointed at cannot land on another task.
Types ¶
type AddCommentInput ¶
AddCommentInput starts a thread.
type AssetLinkRewriter ¶ added in v0.16.0
type AssetLinkRewriter interface {
RenameAssetRewritingLinksIn(ctx context.Context, rel, name string, rewrite func(path string) bool) (vault.AssetMeta, error)
MoveAssetRewritingLinksIn(ctx context.Context, rel, targetDir string, rewrite func(path string) bool) (vault.AssetMeta, error)
}
AssetLinkRewriter is a backend whose asset renames and moves can re-target the notes that reference the file, limited to the notes rewrite accepts (nil: every note). A server rewrites every note itself, so it is not one.
type AssetManager ¶ added in v0.5.0
type AssetManager interface {
ImportAsset(context.Context, string, string, io.Reader) (vault.ImportedAsset, error)
RenameAsset(context.Context, string, string) (vault.AssetMeta, error)
MoveAsset(context.Context, string, string) (vault.AssetMeta, error)
DuplicateAsset(context.Context, string) (vault.AssetMeta, error)
DeleteAsset(context.Context, string) (vault.DeletedAsset, error)
ListDeletedAssets(context.Context) ([]vault.DeletedAsset, error)
RestoreDeletedAsset(context.Context, vault.DeletedAsset) (vault.AssetMeta, error)
}
AssetManager is optional so older backend adapters remain usable for reading.
type Backend ¶
type Backend interface {
Kind() Kind
// LinkedSystemFolders names the system folders with a symbolic link on the
// way to them, which neither the listings nor a read show.
LinkedSystemFolders(ctx context.Context) ([]string, error)
// Label names the vault in output and errors.
Label() string
// Root is the vault directory on disk; empty for a server.
Root() string
Describe(ctx context.Context) (Description, error)
ListNotes(ctx context.Context) ([]vault.NoteMeta, error)
ListAssets(ctx context.Context) ([]vault.AssetMeta, error)
// ReadAsset returns an attachment's bytes by vault-relative path.
ReadAsset(ctx context.Context, rel string) ([]byte, error)
ListFolders(ctx context.Context) ([]vault.FolderEntry, error)
ReadNote(ctx context.Context, rel string) (vault.NoteContent, error)
WriteNote(ctx context.Context, rel, body string) (vault.NoteMeta, error)
// WriteNoteIfUnchanged writes only if the note is still the version
// baseSha256 names (NoteMeta.Sha256 from a read or a write of it), else
// fails with a remote.NoteChangedError and writes nothing. An empty base
// is WriteNote. Only a server hands out a hash, so a local vault, whose
// reads carry none, writes as WriteNote.
WriteNoteIfUnchanged(ctx context.Context, rel, body, baseSha256 string) (vault.NoteMeta, error)
CreateNote(ctx context.Context, folder vault.NoteFolder, title, subpath string, body *string) (vault.NoteMeta, error)
AppendToNote(ctx context.Context, rel, text string) (vault.NoteMeta, error)
PrependToNote(ctx context.Context, rel, text string) (vault.NoteMeta, error)
RenameNote(ctx context.Context, rel, nextTitle string) (vault.NoteMeta, error)
MoveNote(ctx context.Context, rel string, folder vault.NoteFolder, subpath string) (vault.NoteMeta, error)
ArchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)
UnarchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)
MoveToTrash(ctx context.Context, rel string) (vault.NoteMeta, error)
RestoreFromTrash(ctx context.Context, rel string) (vault.NoteMeta, error)
DuplicateNote(ctx context.Context, rel string) (vault.NoteMeta, error)
DeleteNote(ctx context.Context, rel string) error
EmptyTrash(ctx context.Context) error
InsertAtLine(ctx context.Context, rel string, lineNumber int, text string) (vault.NoteMeta, error)
ReplaceInNote(ctx context.Context, rel, find, replace string, all bool) (vault.NoteMeta, int, error)
CreateFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error
RenameFolder(ctx context.Context, folder vault.NoteFolder, oldSubpath, newSubpath string) (string, error)
DeleteFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error
SearchText(ctx context.Context, query string, limit int) ([]vault.TextSearchMatch, error)
Backlinks(ctx context.Context, rel string) ([]vault.NoteMeta, error)
ScanTasks(ctx context.Context, opts vault.ParseTasksOptions) ([]vault.Task, error)
ScanTasksForPath(ctx context.Context, rel string, opts vault.ParseTasksOptions) ([]vault.Task, error)
ToggleTask(ctx context.Context, taskID string, dialect vault.TaskDialect) (*vault.Task, error)
// DatabaseOps composes the CSV database operations over this backend's
// file IO, so `zn base` writes the identical on-disk format everywhere.
DatabaseOps() *database.Ops
// ListComments and WriteComments are a note's comment sidecar as stored;
// WriteComments replaces the list.
ListComments(ctx context.Context, rel string) ([]vault.NoteComment, error)
WriteComments(ctx context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
ListTemplates(ctx context.Context) ([]vault.CustomTemplateFile, error)
WriteTemplate(ctx context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
DeleteTemplate(ctx context.Context, sourcePath string) error
VaultSettings(ctx context.Context) (vault.VaultSettings, error)
UpdateVaultSettings(ctx context.Context, patch func(raw map[string]any)) error
}
Backend is the set of operations every command is written against.
type CommentThreadView ¶
type CommentThreadView struct {
CommentView
AnchorText string `json:"anchorText"`
Line int `json:"line"`
Resolved bool `json:"resolved"`
ResolvedAt *int64 `json:"resolvedAt"`
Replies []CommentView `json:"replies"`
}
CommentThreadView is a top-level comment with its replies.
func AddComment ¶
func AddComment(ctx context.Context, b Backend, in AddCommentInput) (CommentThreadView, error)
AddComment starts a thread, anchored to text from the note when given.
func ListCommentThreads ¶
func ListCommentThreads(ctx context.Context, b Backend, rel string, includeResolved bool) ([]CommentThreadView, error)
ListCommentThreads reads a note's threads, unresolved ones unless includeResolved.
func ReplyToComment ¶
func ReplyToComment(ctx context.Context, b Backend, in ReplyInput) (CommentThreadView, error)
ReplyToComment answers a thread; id may be the thread or any reply in it.
func ResolveComment ¶
func ResolveComment(ctx context.Context, b Backend, rel, id string, resolved bool) (CommentThreadView, error)
ResolveComment marks a thread resolved, or reopens it.
type CommentView ¶
type CommentView struct {
ID string `json:"id"`
Author *string `json:"author"`
Body string `json:"body"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
}
CommentView is one comment or reply as tools and commands present it.
type Description ¶
type Description struct {
Kind Kind
// Root is the local vault directory.
Root string
// BaseURL and Name describe a server; VaultPath and VaultName are the
// vault it serves, as it reports them.
BaseURL string
Name string
VaultPath string
VaultName string
PrimaryNotesLocation vault.PrimaryNotesLocation
// AuthConfigured says whether this process holds a token at all.
AuthConfigured bool
}
Description is where a vault lives and how it is laid out.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local is a vault on this machine: every method is the vault engine bound to one root.
func (*Local) AppendToNote ¶
func (*Local) ArchiveNote ¶
func (*Local) CreateFolder ¶
func (*Local) CreateNote ¶
func (*Local) DatabaseOps ¶
func (*Local) DeleteAsset ¶ added in v0.5.0
func (*Local) DeleteFolder ¶
func (*Local) DeleteTemplate ¶
func (*Local) DuplicateAsset ¶ added in v0.16.0
func (*Local) DuplicateNote ¶
func (*Local) ImportAsset ¶ added in v0.5.0
func (*Local) InsertAtLine ¶
func (*Local) LinkedSystemFolders ¶ added in v0.16.0
LinkedSystemFolders names the system folders that are symbolic links.
func (*Local) ListComments ¶
func (*Local) ListDatabaseDirs ¶ added in v0.17.1
ListDatabaseDirs names the database folders, which a folder listing here leaves out.
func (*Local) ListDeletedAssets ¶ added in v0.5.0
func (*Local) ListFolders ¶
func (*Local) ListTemplates ¶
func (*Local) MoveAssetRewritingLinksIn ¶ added in v0.16.0
func (*Local) MoveToTrash ¶
func (*Local) PrependToNote ¶
func (*Local) RenameAsset ¶ added in v0.5.0
func (*Local) RenameAssetRewritingLinksIn ¶ added in v0.16.0
func (*Local) RenameFolder ¶
func (*Local) RenameNote ¶
func (*Local) RenameNoteRewritingLinksIn ¶ added in v0.13.0
func (l *Local) RenameNoteRewritingLinksIn(_ context.Context, rel, nextTitle string, rewrite func(path string) bool) (vault.NoteMeta, error)
RenameNoteRewritingLinksIn renames a note but rewrites inbound links only in the notes rewrite accepts (nil: every note).
func (*Local) ReplaceInNote ¶
func (*Local) RestoreDeletedAsset ¶ added in v0.5.0
func (*Local) RestoreFromTrash ¶
func (*Local) ScanTasksForPath ¶
func (*Local) SearchText ¶
func (*Local) ToggleTask ¶
func (*Local) UnarchiveNote ¶
func (*Local) UpdateVaultSettings ¶
func (*Local) VaultSettings ¶
func (*Local) WriteComments ¶
func (l *Local) WriteComments(_ context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
func (*Local) WriteNoteIfUnchanged ¶ added in v0.18.2
func (*Local) WriteTemplate ¶
func (l *Local) WriteTemplate(_ context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
type Options ¶
type Options struct {
// SyncTitleHeading is the desktop's "Sync title heading on rename"
// preference, applied by the local backend.
SyncTitleHeading bool
}
Options tune a backend.
type Remote ¶
type Remote struct {
// contains filtered or unexported fields
}
Remote is a vault behind a self-hosted server, reached over the same HTTP API the desktop and web clients use. Where the server has no route for something (there is no task-toggle route, and note creation takes no body), the operation is composed from the routes that do exist.
func NewRemoteWithClient ¶ added in v0.17.0
NewRemoteWithClient is a backend on an existing client, for a server that reaches its own API without the network (mcpserver).
func (*Remote) AppendToNote ¶
func (*Remote) ArchiveNote ¶
func (*Remote) Capabilities ¶ added in v0.16.0
Capabilities is what the server says it supports.
func (*Remote) CreateFolder ¶
func (*Remote) CreateNote ¶
func (r *Remote) CreateNote(ctx context.Context, folder vault.NoteFolder, title, subpath string, body *string) (vault.NoteMeta, error)
CreateNote takes two round trips: the server's create route takes no body, so a note with content is created and then written, on the version the create returned when the server names one.
func (*Remote) DatabaseOps ¶
DatabaseOps reads through /notes/read, which serves any vault file; a 404 means absent, anything else is a real failure (the absence reader settles servers that answer 500 for both).
func (*Remote) DeleteAsset ¶ added in v0.5.0
func (*Remote) DeleteFolder ¶
func (*Remote) DeleteTemplate ¶
func (*Remote) Describe ¶
func (r *Remote) Describe(ctx context.Context) (Description, error)
Describe takes two reads: the vault the server is serving and its layout settings. A 401 here is the first thing an unauthenticated session hits.
func (*Remote) DuplicateAsset ¶ added in v0.16.0
func (*Remote) DuplicateNote ¶
func (*Remote) ImportAsset ¶ added in v0.5.0
func (*Remote) InsertAtLine ¶
func (*Remote) LinkedSystemFolders ¶ added in v0.16.0
LinkedSystemFolders names the system folders the server reports as links.
func (*Remote) ListAssets ¶
func (*Remote) ListComments ¶
func (*Remote) ListDeletedAssets ¶ added in v0.5.0
func (*Remote) ListFolders ¶
func (*Remote) ListTemplates ¶
func (*Remote) MoveToTrash ¶
func (*Remote) PrependToNote ¶
func (*Remote) RenameAsset ¶ added in v0.5.0
func (*Remote) RenameFolder ¶
func (*Remote) RenameNote ¶
func (*Remote) ReplaceInNote ¶
func (r *Remote) ReplaceInNote(ctx context.Context, rel, find, replace string, all bool) (vault.NoteMeta, int, error)
ReplaceInNote: no match means no write, so the receipt comes from the listing instead of a round trip that would re-save identical bytes.
func (*Remote) RestoreDeletedAsset ¶ added in v0.5.0
func (*Remote) RestoreFromTrash ¶
func (*Remote) ScanTasks ¶
The server parses with its own grammar; the dialect only shapes the toggle transform applied to the body it hands back.
func (*Remote) ScanTasksForPath ¶
func (*Remote) SearchText ¶
func (r *Remote) SearchText(ctx context.Context, query string, limit int) ([]vault.TextSearchMatch, error)
SearchText: the server's search route has no limit parameter, so the cap is applied here. It runs the server's own engine, so ordering can differ from a local vault.
func (*Remote) ToggleTask ¶
func (r *Remote) ToggleTask(ctx context.Context, taskID string, dialect vault.TaskDialect) (*vault.Task, error)
ToggleTask: no task-toggle endpoint exists, so the note is read, the same transform a local toggle applies is applied here, and the server re-parses the result.
func (*Remote) UnarchiveNote ¶
func (*Remote) UpdateVaultSettings ¶
func (*Remote) VaultSettings ¶
func (*Remote) WriteComments ¶
func (r *Remote) WriteComments(ctx context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
func (*Remote) WriteNoteIfUnchanged ¶ added in v0.18.2
func (*Remote) WriteTemplate ¶
func (r *Remote) WriteTemplate(ctx context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
type ReplyInput ¶
ReplyInput answers in a thread.
type Target ¶
type Target struct {
Kind Kind
// Root is the local vault directory.
Root string
// Name is the saved server profile's name, "" for a bare URL.
Name string
BaseURL string
AuthToken string
// VaultPath and VaultName are the vault the server said it is serving,
// from Served. A server can change its vault with nothing changing here,
// so a target resolved from flags or config leaves them empty.
VaultPath string
VaultName string
}
Target is which vault a command is about.
func ResolveDefaultTarget ¶
ResolveDefaultTarget is the target when nothing named one: ZENNOTES_SERVER, then ZENNOTES_VAULT, then the selected source's default. Terminal mode prefers its saved default before falling back to the desktop workspace.
func ResolveServerTarget ¶
ResolveServerTarget resolves `--server <name|url>`.
func ResolveTarget ¶
ResolveTarget is the target for one invocation. `--server` wins over `--vault`; with neither, the environment and selected workspace source decide.
func ResolveTargetWithSource ¶ added in v0.2.0
func ResolveTargetWithSource(vaultSelector, serverSelector, flagToken, source string) (Target, error)
ResolveTargetWithSource keeps desktop commands attached to the desktop even when the terminal UI remembers a different workspace. Flags and environment vault overrides still win. Empty source reads ZENNOTES_WORKSPACE_SOURCE.
func ResolveVaultTarget ¶
ResolveVaultTarget resolves `--vault <name|path>`: a local vault name, then a server profile name, then a directory path.
func Served ¶ added in v0.16.0
Served is the target with the vault its server is serving right now filled in, one request. A local target comes back as it is.
func TargetForWorkspace ¶
func TargetForWorkspace(ws config.Workspaces, name, flagToken string) (Target, bool)
TargetForWorkspace resolves one of zn's own saved workspaces by name.
type UpdateTaskInput ¶ added in v0.16.0
type UpdateTaskInput struct {
ID string
// Due is YYYY-MM-DD; "" clears it.
Due *string
// Priority is high, med or low; "" clears it.
Priority *string
Waiting *bool
// State is open, done, in-progress or cancelled.
State *string
// Status is the Kanban column (`@status:` on a line, `status:` on a task
// note); "" clears it.
Status *string
// Text replaces everything after a line's checkbox, tokens included.
Text *string
// ExpectedText is the task's content as the caller last saw it. An id counts
// the task's position, so after an edit above it the id names another task;
// when this no longer matches, nothing changes and the call fails.
ExpectedText *string
}
UpdateTaskInput is what to change on one task; a nil field stays as it is.