Documentation
¶
Index ¶
- Constants
- Variables
- func BlindTags(ctx context.Context, values []string) ([]string, error)
- func FileURL(id string) string
- func FolderNameTaken(err error) bool
- func Live[T any](tree Tree, rows []T, id func(T) string, first func(a, b T) int) []T
- func OpenTags(sealed []string) ([]string, error)
- func Page[T any](rows []T, limit, offset int) []T
- func Paths(ctx context.Context, db bun.IDB) (map[string]string, error)
- func PlanFeatures(plan string) []string
- func RegisterModels(db *bun.DB)
- func SealTitle(ctx context.Context, title string) (secret.Text, string, error)
- func SortFold[T any](items []T, key func(T) string, first func(a, b T) int)
- func Titles(ctx context.Context, db bun.IDB) (map[string]string, error)
- func Unlocked(feature, plan string) bool
- func UserID(ctx context.Context) string
- func WithUser(ctx context.Context, userID string) context.Context
- type APIToken
- type File
- type GraphLayout
- type Invite
- type Item
- type Kind
- type Metadata
- type MetadataFolder
- type MetadataNote
- type NoteFile
- type NoteLink
- type NoteTag
- type NoteVersion
- type SavedSearch
- type SavedSearches
- type Session
- type SidebarSection
- type Snippet
- type Snippets
- type Tag
- type Tree
- type User
- type Versioned
Constants ¶
const FolderNameIndex = "ux_folders_user_parent_title_hash"
FolderNameIndex keeps two live folders of one folder (or of an account's root) from sharing a name, whatever its case.
Variables ¶
var ( TagModes = []string{"any", "all"} FolderModes = []string{"include", "exclude"} )
TagModes and FolderModes are the choices of SavedSearch, the first one its default.
var ( Themes = []string{"notes", "dracula", "catppuccin", "nord", "gruvbox", "everforest", "tokyo", "vue"} ColorModes = []string{"system", "light", "dark"} Views = []string{"list", "grid"} Plans = []string{"base", "pro", "ultra"} )
Themes, ColorModes, Views and Plans are the other settings of the web app, the first one by default. Themes repeats the ids of notes-app/app/utils/themes.ts and Plans the plans of notes-app/app/utils/features.ts, users_test.go checks they match.
var AddUserModes = []string{"invitation", "public"}
AddUserModes are the ways an account is created on a server, the first one by default: by invitation of an admin only, or by anyone reaching the web app.
var ErrFolderExists = errors.New("a folder with this name already exists here")
var ErrNoUser = errors.New("not logged in")
var Features = map[string]string{
"graph": "base",
"focusMode": "pro",
"contextPanel": "pro",
"settingsNav": "pro",
"slashCommands": "pro",
"tables": "pro",
"codeHighlight": "base",
"callouts": "pro",
"wordCount": "pro",
"contextMenu": "pro",
"paletteActions": "pro",
"sourceMode": "base",
"noteLock": "base",
"noteHistory": "pro",
"brokenLinks": "pro",
"storageFiles": "pro",
"wikiLinks": "base",
"linkSuggestions": "pro",
"noteEmbeds": "base",
"images": "base",
"attachments": "base",
"linkCards": "base",
"tagSuggestions": "base",
"snippets": "base",
"savedSearches": "pro",
"sidebarOrder": "pro",
"hideFolders": "ultra",
"replaceEverywhere": "ultra",
"search": "base",
"favorites": "base",
"backlinks": "base",
"themes": "base",
"importExport": "base",
"trash": "base",
"storageUsage": "base",
}
Features are the plan each feature of the web app comes from, each plan including those before it, "off" for no one (unfinished, withdrawn): the one list of them. The API refuses the routes of a feature to the plans without it, and gives each account its features (User.Features) and each plan its own (GET /api/plans) for the app to show.
var FilePattern = regexp.MustCompile(`/api/files/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})`)
FilePattern finds the files a note cites: the uuid is its first group.
var FileTypes = map[string]string{
"image/png": ".png",
"image/jpeg": ".jpg",
"image/gif": ".gif",
"image/webp": ".webp",
"application/pdf": ".pdf",
"application/zip": ".zip",
"application/ogg": ".ogg",
"audio/mpeg": ".mp3",
"audio/wave": ".wav",
"video/mp4": ".mp4",
"video/webm": ".webm",
}
FileTypes are the files accepted, as http.DetectContentType names them, with the extension of their export. Not SVG nor HTML: they can hold scripts. A zip also holds the Office documents.
var Locales = []string{"fr", "en"}
Locales are the languages of the web app, the first one by default.
var NeighborsLimits = []int{50, 20, 100, 0}
NeighborsLimits are the choices of User.NeighborsLimit, the first one by default; 0 shows them all.
var SidebarSectionIDs = []string{"favorites", "pinned", "recent", "folders", "savedSearches", "tags"}
SidebarSectionIDs are the lists of the sidebar, in their default order: notes-app/app/utils/sidebar.ts repeats them, users_test.go checks they match.
Functions ¶
func BlindTags ¶
BlindTags gives the value_hash of each value: tags are found by it, whatever their case.
func FolderNameTaken ¶
FolderNameTaken tells whether err is FolderNameIndex refusing a folder: created, renamed, moved or restored next to one of the same name.
func Live ¶
Live keeps the rows whose item (id gives it) is live, sorted by first then by path, as SortFold does: what every list of notes shows. The rows only need their ids: the titles and paths come from the tree, nothing is opened.
func OpenTags ¶
OpenTags opens the tag values a query gave sealed (an array_agg), ordered whatever their case.
func PlanFeatures ¶
PlanFeatures are the features of plan, sorted.
func RegisterModels ¶
RegisterModels must run before any query on MetadataNote.Tags (bun m2m requirement).
func SealTitle ¶
SealTitle gives a title sealed, and its blind for title_hash: both "" for an untitled note, written NULL.
func SortFold ¶
SortFold is fold.Sort, for the processes: the CLI sorts the same way without the models.
func Unlocked ¶
Unlocked tells whether an account of plan has feature; an unknown plan has the base features.
Types ¶
type APIToken ¶
type APIToken struct {
bun.BaseModel `bun:"table:api_tokens,alias:at" json:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id"`
UserID string `bun:",notnull,type:uuid" json:"-"`
Name secret.Text `bun:",type:text,notnull" json:"name" swaggertype:"string"` // sealed: a stolen base does not tell what the tokens are for
TokenHash string `bun:",notnull,unique" json:"-"`
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"created_at"`
LastUsedAt time.Time `bun:",nullzero" json:"last_used_at,omitzero" binding:"optional"` // never used when absent
ExpiresAt time.Time `bun:",nullzero" json:"expires_at,omitzero" binding:"optional"` // no limit when absent
}
APIToken lets a script or an agent act for the account without a login: notes, folders, tags and files, never the account itself (auth refuses it there). The client keeps the token, the base only its hash.
type File ¶
type File struct {
bun.BaseModel `bun:"table:files,alias:f" json:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id"`
UserID string `bun:",type:uuid,notnull,nullzero" json:"-"`
Name secret.Text `bun:",type:text" json:"name" swaggertype:"string"` // "" (NULL) for the images uploaded before names were sealed
ContentType string `bun:",notnull" json:"content_type"`
Size int64 `bun:",notnull" json:"size"`
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"created_at"`
OrphanedAt time.Time `bun:",nullzero" json:"-"` // since no note cites it; purgefiles sets it
}
File is an image or an attachment of a note: its bytes are in Silo under Key(), the notes cite it as FileURL(ID).
type GraphLayout ¶
type GraphLayout struct {
bun.BaseModel `bun:"table:graph_layouts,alias:gl" json:"-"`
UserID string `bun:",pk,type:uuid"`
Data []byte `bun:",notnull,type:bytea"`
}
GraphLayout is the settled layout of the whole graph of an account, computed by the server and shared by its devices. Data is sealed (secret.SealBytes): the tags are nodes by name, and the signature is a hash of them.
type Invite ¶
type Invite struct {
bun.BaseModel `bun:"table:invites,alias:iv" json:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id"`
TokenHash string `bun:",notnull,unique" json:"-"`
// The token itself, sealed with the key of the admin who made it, so the admin panel shows the link again:
// "" (NULL) for the invitations made before it was kept. The sign-up still finds an invitation by TokenHash.
Token secret.Text `bun:",type:text" json:"token" swaggertype:"string"`
UserID string `bun:",notnull,type:uuid" json:"created_by"` // the admin who made it
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"created_at"`
ExpiresAt time.Time `bun:",notnull" json:"expires_at"`
UsedAt time.Time `bun:",nullzero" json:"-"` // set when it created an account, so a link serves once
}
Invite is a link an admin hands out so someone creates their own account: the base keeps the hash of its token, and the token sealed, which only the admin panel reads back.
type Item ¶
type Item struct {
bun.BaseModel `bun:"table:items,alias:i" json:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id"`
UserID string `bun:",type:uuid,notnull,nullzero" json:"-"`
ParentID *string `bun:",type:uuid,nullzero" json:"parent_id" binding:"optional"`
Parent *Item `bun:"rel:belongs-to,join:parent_id=id" json:"-"`
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"created_at"`
UpdatedAt time.Time `bun:",nullzero" json:"updated_at,omitzero" binding:"optional"`
DeletedAt time.Time `bun:",soft_delete,nullzero" json:"-"`
Kind Kind `bun:",notnull" json:"kind"`
Title secret.Text `bun:",type:text,nullzero" json:"title" swaggertype:"string"` // NULL = untitled note (--no-title)
TitleHash string `bun:",nullzero" json:"-"` // its Blind: unique folder names, [[links]] by title
Readonly bool `bun:",scanonly" json:"readonly,omitempty" binding:"optional"` // a locked note, read by listitems from metadata_notes
HasFolders bool `bun:",scanonly" json:"has_folders,omitempty" binding:"optional"` // a folder with subfolders, read by listitems
}
type MetadataFolder ¶
type MetadataNote ¶
type MetadataNote struct {
bun.BaseModel `bun:"table:metadata_notes,alias:mn"`
Metadata `bun:",inline"`
Content secret.Text `bun:",type:text"`
Readonly bool `bun:",notnull"`
Pinned bool `bun:",notnull"`
Grams []int16 `bun:",array,type:smallint[]"` // noteindex: blinds of its grams, NULL until noteindex.Fill
Waiting []string `bun:",array,type:text[]"` // noteindex: blinds of the titles its [[links]] wait for
Linked bool // noteindex: its text has a link or a file listbrokenlinks checks, NULL until noteindex.Fill
// A fork: the note it was made from, which mergefork brings its changes back into; NULL for any other note.
ForkOf string `bun:",type:uuid,nullzero"`
// The fork's text, sealed, at the fork then at each merge: the base of the next three-way merge.
ForkBase secret.Text `bun:",type:text,nullzero"`
Headings []int16 `bun:",array,type:smallint[]"` // noteindex: blinds of the grams of its headings
HeadingNames []string `bun:",array,type:text[]"` // noteindex: blind of each heading's noteindex.HeadingName
Tags []Tag `bun:"m2m:notes_on_tags,join:Note=Tag"`
}
type NoteFile ¶
type NoteFile struct {
bun.BaseModel `bun:"table:notes_on_files,alias:nf"`
NoteID string `bun:",pk,type:uuid"`
FileID string `bun:",pk,type:uuid"`
}
NoteFile is an image a note cites: purgefiles reads it, the text of the note being sealed.
type NoteLink ¶
type NoteLink struct {
bun.BaseModel `bun:"table:notes_on_links,alias:nl"`
SourceID string `bun:",pk,type:uuid"`
TargetID string `bun:",pk,type:uuid"`
}
NoteLink is a [[link]] of a note's text that names another note, resolved to its id.
type NoteVersion ¶
type NoteVersion struct {
bun.BaseModel `bun:"table:note_versions,alias:nv" json:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id"`
ItemID string `bun:",type:uuid,notnull" json:"-"`
Content secret.Text `bun:",type:text,notnull" json:"content,omitempty" swaggertype:"string" binding:"optional"` // left out of a list
FileIDs []string `bun:"file_ids,array,type:uuid[]" json:"-"` // the images Content cites, in clear: purgefiles keeps them
Conflict bool `bun:",notnull,default:false" json:"conflict"` // a text refused by a 409, kept so it is not lost (#78)
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"created_at"`
}
NoteVersion is a text a note had before an edit replaced it, kept by patchnote (#61). Deleted with its note.
func NewNoteVersion ¶
func NewNoteVersion(ctx context.Context, itemID, text string) (NoteVersion, error)
NewNoteVersion seals text for the account of ctx and notes the images it cites.
type SavedSearch ¶
type SavedSearch struct {
ID string `json:"id"`
Name string `json:"name"`
TagIDs []string `json:"tag_ids,omitempty" binding:"optional"`
TagMode string `json:"tag_mode,omitempty" binding:"optional"` // "any" (default) or "all", one of TagModes
FolderIDs []string `json:"folder_ids,omitempty" binding:"optional"`
FolderMode string `json:"folder_mode,omitempty" binding:"optional"` // "include" or "exclude", one of FolderModes
CreatedFrom *time.Time `json:"created_from,omitempty" binding:"optional"`
CreatedTo *time.Time `json:"created_to,omitempty" binding:"optional"`
EditedFrom *time.Time `json:"edited_from,omitempty" binding:"optional"`
EditedTo *time.Time `json:"edited_to,omitempty" binding:"optional"`
Text string `json:"text,omitempty" binding:"optional"`
}
SavedSearch is a smart folder: the criteria are replayed by runsavedsearch, never stored as a result.
type SavedSearches ¶
type SavedSearches []SavedSearch
SavedSearches are kept sealed, as one JSON string in their jsonb column: write Seal's.
func (*SavedSearches) Scan ¶
func (s *SavedSearches) Scan(src any) error
Scan also reads a JSON array in clear: the column's default, [].
type Session ¶
type Session struct {
bun.BaseModel `bun:"table:sessions,alias:s"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()"`
UserID string `bun:",notnull,type:uuid"`
TokenHash string `bun:",notnull,unique"`
CreatedAt time.Time `bun:",notnull,default:current_timestamp"`
ExpiresAt time.Time `bun:",notnull"`
}
Session is a login of a device: the client keeps the token, the base only its hash.
type SidebarSection ¶
SidebarSection is a list of the web app's sidebar, one of SidebarSectionIDs, shown or hidden.
type Snippet ¶
Snippet is a piece of markdown of the account, inserted while typing or starting a new note; its #tags become tags of that note.
type Snippets ¶
type Snippets []Snippet
Snippets are kept sealed, as one JSON string in their jsonb column: write Seal's.
type Tag ¶
type Tag struct {
bun.BaseModel `bun:"table:tags,alias:t" json:"-" yaml:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id" yaml:"id"`
UserID string `bun:",type:uuid,notnull,nullzero" json:"-" yaml:"-"`
Value secret.Text `bun:",type:text,notnull" json:"value" yaml:"value" swaggertype:"string"`
ValueHash string `bun:",notnull" json:"-" yaml:"-"` // its Blind, unique per account, see createschema
}
type Tree ¶
Tree is every live item of an account, by id: its path from its root (/Projects/Go/Ideas) and its title in clear. A trashed folder hides its whole subtree, so an id missing from it is not live. Shared, do not modify it.
func LoadTree ¶
LoadTree gives the Tree of the account of ctx. Titles are sealed: paths are made here, not in SQL. Cached (one query, not 75 ms of decryption at 50,000 items): reading it opens nothing. TODO: the read after a write opens every title again, 100 ms at 50,000 items, once per write (measured, #155); only the rows changed since the cached version if writes ever come by hundreds.
type User ¶
type User struct {
bun.BaseModel `bun:"table:users,alias:u" json:"-"`
ID string `bun:",pk,type:uuid,default:gen_random_uuid()" json:"id"`
Name string `bun:",notnull" json:"name"` // unique case-insensitive, see createschema
PasswordHash string `bun:",notnull" json:"-"`
DataKey string `bun:",nullzero" json:"-"` // the key of its notes sealed by NOTES_SECRET, see services/secret
Locale string `bun:",notnull,default:'fr'" json:"locale"` // the language of the web app, one of Locales
Theme string `bun:",notnull,default:'notes'" json:"theme"` // the colors of the web app, one of Themes
ColorMode string `bun:",notnull,default:'system'" json:"color_mode"` // light or dark, one of ColorModes
View string `bun:",notnull,default:'list'" json:"view"` // how the web app lists items, one of Views
Plan string `bun:",notnull,default:'base'" json:"plan"` // the features of the web app, one of Plans
Admin bool `bun:",notnull,default:false" json:"admin"` // may create, invite and delete accounts; the first account of the base gets it
// Days before the trash is purged, 0 to never purge. An insert of 0 gets the default: only an update sets it.
TrashRetentionDays int `bun:",notnull,default:30" json:"trash_retention_days"`
// The most notes sharing a tag that a note shows around it, one of NeighborsLimits, 0 for all of them.
// An insert of 0 gets the default: only an update sets it.
NeighborsLimit int `bun:",notnull,default:50" json:"neighbors_limit"`
Avatar string `bun:",type:uuid,nullzero" json:"avatar,omitempty"` // the id of a File of the account, purgefiles keeps it
Snippets Snippets `bun:",type:jsonb,notnull,default:'[]'" json:"snippets"`
SavedSearches SavedSearches `bun:",type:jsonb,notnull,default:'[]'" json:"saved_searches"`
// The order of the sidebar lists and which ones show, [] for the app's default.
SidebarSections []SidebarSection `bun:",type:jsonb,notnull,default:'[]'" json:"sidebar_sections"`
CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"created_at"`
// Bumped by the triggers of createschema at every write that changes a path, from any process: Paths reads it to
// know its cache is still right. From a sequence, so a rolled-back write never hands its number to another.
ItemsVersion int64 `bun:",notnull,default:0" json:"-"`
// The features of its plan, what the web app shows: not stored, filled from Plan at every read.
Features []string `bun:"-" json:"features"`
}
User is an account: every item and tag belongs to one.
type Versioned ¶
type Versioned[T any] struct { // contains filtered or unexported fields }
Versioned keeps one value per account while its users.items_version stays the same: built again after a write that adds, removes, renames, moves, trashes or restores an item, whoever made it. In memory only, never written.