marks

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package marks is frostmarks' app core: bookmarks and the folders that hold them, stored in SQLite, with 2 capabilities (marks:read and marks:write) on the folder selector.

The service writes each change and its event in 1 SQLite transaction (hearth's outbox), and it wakes the relay after the commit, so that no change is published without its event, and no event without its change. The permission checks are hearth's: the generated check of every RPC, the generated hook of each RPC that runs on an id, and the grant filter of the app's lists (see authorize.go).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, path string) (*sql.DB, error)

Open opens the app's database at path, it makes the schema, and it makes the outbox's table.

The database holds 1 connection: SQLite writes 1 at a time, so the app's transactions and the relay's deletes wait for each other, and they never fail with a lock. Foreign keys are on, so a deleted bookmark takes its tags with it, and a busy database waits up to 5 s before it reports a lock.

A second Open of the same database is a no-op: PRAGMA user_version tells it that the schema is there.

Types

type Service

type Service struct {
	// DB is the app's database, from Open.
	DB *sql.DB
	// Notify wakes the outbox relay after a change that wrote 1 event. nil is
	// no wake.
	Notify func()
	// Now is the clock of a bookmark's create_time and update_time. nil is
	// time.Now.
	Now func() time.Time
	// NewID makes 1 bookmark's id: a UUIDv7. nil is uuid.NewV7.
	NewID func() (string, error)
}

Service is frostmarks' app core: the database, the clock and the id source of its changes, and the wake of the outbox relay.

func (*Service) API

func (s *Service) API() marksv1.MarksAPI

API returns the app's API with the generated permission check of every RPC.

func (*Service) AuthorizeDeleteBookmark

func (s *Service) AuthorizeDeleteBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, req *marksv1.DeleteBookmarkRequest) error

AuthorizeDeleteBookmark checks marks:write on the folder that 1 stored bookmark is filed in, before the call deletes it.

func (*Service) AuthorizeGetBookmark

func (s *Service) AuthorizeGetBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, req *marksv1.GetBookmarkRequest) error

AuthorizeGetBookmark checks marks:read on the folder that 1 stored bookmark is filed in, before the call reads it.

func (*Service) AuthorizeMoveBookmark

func (s *Service) AuthorizeMoveBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, req *marksv1.MoveBookmarkRequest) error

AuthorizeMoveBookmark checks marks:write on the folder that 1 stored bookmark is filed in, before the call moves it. The generated check has already checked the folder that the request moves the bookmark to.

func (*Service) AuthorizeUpdateBookmark

func (s *Service) AuthorizeUpdateBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, req *marksv1.UpdateBookmarkRequest) error

AuthorizeUpdateBookmark checks marks:write on the folder that 1 stored bookmark is filed in, before the call changes it.

func (*Service) CreateBookmark

CreateBookmark saves 1 URL in 1 folder, and it publishes the bookmark's created event, in 1 transaction.

The folder must exist. The URL is canonicalized (see normalizedURL), and the tags are canonicalized and sorted. The same URL in the same folder is already_exists, with the id of the bookmark that holds it; the same URL in another folder is allowed.

func (*Service) CreateFolder

CreateFolder makes 1 folder. The root path always exists, so it is not created, and the parent of the new folder must exist.

func (*Service) DeleteBookmark

DeleteBookmark deletes 1 bookmark with its tags and its search row, and it publishes the bookmark's deleted event on the folder it was filed in.

func (*Service) DeleteFolder

DeleteFolder deletes 1 folder that holds no bookmark and no folder.

The root path is never deleted. A folder that holds anything is failed_precondition: its contents must move away first.

func (*Service) GetBookmark

GetBookmark reads 1 bookmark, in the transaction that the generated hook of the RPC opened.

func (*Service) ListBookmarks

ListBookmarks lists the bookmarks of 1 folder, and, with recursive, of every folder below it, optionally only those with 1 tag. The folder must exist.

The order is the folder, then the creation time, then the id. The list holds only the bookmarks whose folder the caller's grant covers.

func (*Service) ListFolders

ListFolders lists the folders in 1 folder, or, with recursive, every folder below it, sorted by path. The folder must exist, and the list holds only the folders that the caller's grant covers.

func (*Service) MoveBookmark

MoveBookmark files 1 bookmark in another folder, and it publishes the bookmark's moved_out event on the folder it leaves, and then its moved_in event on the folder it arrives in.

The destination must exist. A move to the folder the bookmark is in changes nothing and publishes no event.

func (*Service) RenameFolder

RenameFolder gives 1 folder a new path, with every folder below it and every bookmark in them, in 1 transaction.

Neither path is the root, and the new path is neither the folder's path nor below it. The folder must exist, the new path's parent must exist, and the new path must not exist. For each moved bookmark, in id order, the call publishes the bookmark's moved_out event on the folder it leaves and its moved_in event on the folder it arrives in.

func (*Service) SearchBookmarks

SearchBookmarks finds the bookmarks whose title, URL, notes or tags hold every word of the query, in 1 folder and every folder below it, best match first.

The search is SQLite's FTS5, kept in step with every change. The folder must exist, and the result holds only the bookmarks whose folder the caller's grant covers, at most maxSearchResults of them.

func (*Service) UpdateBookmark

UpdateBookmark changes the fields that the request sets, and it keeps the others: the URL, the title, the notes, and the tags it adds and removes.

A change sets update_time and publishes the updated event. A call that changes nothing publishes no event and keeps update_time.

Jump to

Keyboard shortcuts

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