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 ¶
- func Open(ctx context.Context, path string) (*sql.DB, error)
- type Service
- func (s *Service) API() marksv1.MarksAPI
- func (s *Service) AuthorizeDeleteBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, ...) error
- func (s *Service) AuthorizeGetBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, ...) error
- func (s *Service) AuthorizeMoveBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, ...) error
- func (s *Service) AuthorizeUpdateBookmark(ctx context.Context, tx *sql.Tx, grant authz.Grant, ...) error
- func (s *Service) CreateBookmark(ctx context.Context, req *marksv1.CreateBookmarkRequest) (*marksv1.CreateBookmarkResponse, error)
- func (s *Service) CreateFolder(ctx context.Context, req *marksv1.CreateFolderRequest) (*marksv1.CreateFolderResponse, error)
- func (s *Service) DeleteBookmark(ctx context.Context, req *marksv1.DeleteBookmarkRequest) (*marksv1.DeleteBookmarkResponse, error)
- func (s *Service) DeleteFolder(ctx context.Context, req *marksv1.DeleteFolderRequest) (*marksv1.DeleteFolderResponse, error)
- func (s *Service) GetBookmark(ctx context.Context, req *marksv1.GetBookmarkRequest) (*marksv1.GetBookmarkResponse, error)
- func (s *Service) ListBookmarks(ctx context.Context, req *marksv1.ListBookmarksRequest) (*marksv1.ListBookmarksResponse, error)
- func (s *Service) ListFolders(ctx context.Context, req *marksv1.ListFoldersRequest) (*marksv1.ListFoldersResponse, error)
- func (s *Service) MoveBookmark(ctx context.Context, req *marksv1.MoveBookmarkRequest) (*marksv1.MoveBookmarkResponse, error)
- func (s *Service) RenameFolder(ctx context.Context, req *marksv1.RenameFolderRequest) (*marksv1.RenameFolderResponse, error)
- func (s *Service) SearchBookmarks(ctx context.Context, req *marksv1.SearchBookmarksRequest) (*marksv1.SearchBookmarksResponse, error)
- func (s *Service) UpdateBookmark(ctx context.Context, req *marksv1.UpdateBookmarkRequest) (*marksv1.UpdateBookmarkResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
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) 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 ¶
func (s *Service) CreateBookmark(ctx context.Context, req *marksv1.CreateBookmarkRequest) (*marksv1.CreateBookmarkResponse, error)
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 ¶
func (s *Service) CreateFolder(ctx context.Context, req *marksv1.CreateFolderRequest) (*marksv1.CreateFolderResponse, error)
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 ¶
func (s *Service) DeleteBookmark(ctx context.Context, req *marksv1.DeleteBookmarkRequest) (*marksv1.DeleteBookmarkResponse, error)
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 ¶
func (s *Service) DeleteFolder(ctx context.Context, req *marksv1.DeleteFolderRequest) (*marksv1.DeleteFolderResponse, error)
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 ¶
func (s *Service) GetBookmark(ctx context.Context, req *marksv1.GetBookmarkRequest) (*marksv1.GetBookmarkResponse, error)
GetBookmark reads 1 bookmark, in the transaction that the generated hook of the RPC opened.
func (*Service) ListBookmarks ¶
func (s *Service) ListBookmarks(ctx context.Context, req *marksv1.ListBookmarksRequest) (*marksv1.ListBookmarksResponse, error)
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 ¶
func (s *Service) ListFolders(ctx context.Context, req *marksv1.ListFoldersRequest) (*marksv1.ListFoldersResponse, error)
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 ¶
func (s *Service) MoveBookmark(ctx context.Context, req *marksv1.MoveBookmarkRequest) (*marksv1.MoveBookmarkResponse, error)
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 ¶
func (s *Service) RenameFolder(ctx context.Context, req *marksv1.RenameFolderRequest) (*marksv1.RenameFolderResponse, error)
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 ¶
func (s *Service) SearchBookmarks(ctx context.Context, req *marksv1.SearchBookmarksRequest) (*marksv1.SearchBookmarksResponse, error)
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 ¶
func (s *Service) UpdateBookmark(ctx context.Context, req *marksv1.UpdateBookmarkRequest) (*marksv1.UpdateBookmarkResponse, error)
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.