api

package
v0.0.0-...-c12e4a5 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: EUPL-1.2 Imports: 2 Imported by: 37

Documentation

Overview

Package api contains common definitions used for client and server.

Index

Constants

View Source
const (
	// System zettel
	ZidVersion              = ZettelID("00000000000001")
	ZidHost                 = ZettelID("00000000000002")
	ZidOperatingSystem      = ZettelID("00000000000003")
	ZidLicense              = ZettelID("00000000000004")
	ZidAuthors              = ZettelID("00000000000005")
	ZidDependencies         = ZettelID("00000000000006")
	ZidLog                  = ZettelID("00000000000007")
	ZidMemory               = ZettelID("00000000000008")
	ZidSx                   = ZettelID("00000000000009")
	ZidHTTP                 = ZettelID("00000000000010")
	ZidAPI                  = ZettelID("00000000000011")
	ZidWebUI                = ZettelID("00000000000012")
	ZidConsole              = ZettelID("00000000000013")
	ZidBoxManager           = ZettelID("00000000000020")
	ZidZettel               = ZettelID("00000000000021")
	ZidIndex                = ZettelID("00000000000022")
	ZidQuery                = ZettelID("00000000000023")
	ZidMetadataKey          = ZettelID("00000000000090")
	ZidParser               = ZettelID("00000000000092")
	ZidStartupConfiguration = ZettelID("00000000000096")
	ZidConfiguration        = ZettelID("00000000000100")
	ZidDirectory            = ZettelID("00000000000101")

	// WebUI HTML templates are in the range 10000..19999
	ZidBaseTemplate   = ZettelID("00000000010100")
	ZidLoginTemplate  = ZettelID("00000000010200")
	ZidListTemplate   = ZettelID("00000000010300")
	ZidZettelTemplate = ZettelID("00000000010401")
	ZidInfoTemplate   = ZettelID("00000000010402")
	ZidFormTemplate   = ZettelID("00000000010403")
	ZidDeleteTemplate = ZettelID("00000000010405")
	ZidErrorTemplate  = ZettelID("00000000010700")

	// WebUI sxn code zettel are in the range 19000..19999
	ZidSxnStart = ZettelID("00000000019000")
	ZidSxnBase  = ZettelID("00000000019990")

	// CSS-related zettel are in the range 20000..29999
	ZidBaseCSS = ZettelID("00000000020001")
	ZidUserCSS = ZettelID("00000000025001")

	// WebUI image zettel are in the range 40000..49999
	ZidEmoji = ZettelID("00000000040001")

	// Other sxn code zettel are in the range 50000..59999
	ZidSxnPrelude = ZettelID("00000000059900")

	// Predefined Zettelmarkup zettel are in the range 60000..69999
	ZidRoleZettelZettel        = ZettelID("00000000060010")
	ZidRoleConfigurationZettel = ZettelID("00000000060020")
	ZidRoleRoleZettel          = ZettelID("00000000060030")
	ZidRoleTagZettel           = ZettelID("00000000060040")

	// Range 80000...89999 is reserved for web ui menus
	ZidTOCListsMenu = ZettelID("00000000080001") // "Lists" menu

	// Range 90000...99999 is reserved for zettel templates
	ZidTOCNewTemplate    = ZettelID("00000000090000")
	ZidTemplateNewZettel = ZettelID("00000000090001")
	ZidTemplateNewRole   = ZettelID("00000000090004")
	ZidTemplateNewTag    = ZettelID("00000000090003")
	ZidTemplateNewUser   = ZettelID("00000000090002")

	// Range 00000999999900...00000999999999 are predefined zettel to be searched by content.
	ZidAppDirectory = ZettelID("00000999999999")

	// Default Home Zettel
	ZidDefaultHome = ZettelID("00010000000000")
)

Predefined zettel identifier.

See List of predefined zettel.

View Source
const (
	MetaCredential = "Credential"
	MetaEmpty      = "EString"
	MetaID         = "Identifier"
	MetaIDSet      = "IdentifierSet"
	MetaNumber     = "Number"
	MetaString     = "String"
	MetaTagSet     = "TagSet"
	MetaTimestamp  = "Timestamp"
	MetaURL        = "URL"
	MetaWord       = "Word"
)

Values of the metadata key/value types.

See Supported Key Types.

View Source
const (
	KeyID           = "id"
	KeyTitle        = "title"
	KeyRole         = "role"
	KeyTags         = "tags"
	KeySyntax       = "syntax"
	KeyAuthor       = "author"
	KeyBack         = "back"
	KeyBackward     = "backward"
	KeyBoxNumber    = "box-number"
	KeyCopyright    = "copyright"
	KeyCreated      = "created"
	KeyCredential   = "credential"
	KeyDead         = "dead"
	KeyExpire       = "expire"
	KeyFolge        = "folge"
	KeyFolgeRole    = "folge-role"
	KeyForward      = "forward"
	KeyLang         = "lang"
	KeyLicense      = "license"
	KeyModified     = "modified"
	KeyPrecursor    = "precursor"
	KeyPredecessor  = "predecessor"
	KeyPrequel      = "prequel"
	KeyPublished    = "published"
	KeyQuery        = "query"
	KeyReadOnly     = "read-only"
	KeySequel       = "sequel"
	KeySubordinates = "subordinates"
	KeySuccessors   = "successors"
	KeySummary      = "summary"
	KeySuperior     = "superior"
	KeyURL          = "url"
	KeyUselessFiles = "useless-files"
	KeyUserID       = "user-id"
	KeyUserRole     = "user-role"
	KeyVisibility   = "visibility"
)

Predefined / supported metadata keys.

See Supported Metadata Keys.

View Source
const (
	ValueFalse             = "false"
	ValueTrue              = "true"
	ValueLangEN            = "en"            // Default for "lang"
	ValueRoleConfiguration = "configuration" // A role for internal zettel
	ValueRoleTag           = "tag"           // A role for tag zettel
	ValueRoleRole          = "role"          // A role for role zettel
	ValueRoleZettel        = "zettel"        // A role for zettel
	ValueSyntaxCSS         = "css"           // Syntax: CSS
	ValueSyntaxDraw        = "draw"          // Syntax: Drawing
	ValueSyntaxGif         = "gif"           // Syntax GIF image
	ValueSyntaxHTML        = "html"          // Syntax: HTML
	ValueSyntaxMarkdown    = "markdown"      // Syntax: Markdown / CommonMark
	ValueSyntaxMD          = "md"            // Syntax: Markdown / CommonMark
	ValueSyntaxNone        = "none"          // Syntax: no syntax / content, just metadata
	ValueSyntaxSVG         = "svg"           // Syntax: SVG
	ValueSyntaxSxn         = "sxn"           // Syntax: S-Expression
	ValueSyntaxText        = "text"          // Syntax: plain text
	ValueSyntaxZmk         = "zmk"           // Syntax: Zettelmarkup
	ValueUserRoleCreator   = "creator"
	ValueUserRoleOwner     = "owner"
	ValueUserRoleReader    = "reader"
	ValueUserRoleWriter    = "writer"
	ValueVisibilityCreator = "creator"
	ValueVisibilityExpert  = "expert"
	ValueVisibilityLogin   = "login"
	ValueVisibilityOwner   = "owner"
	ValueVisibilityPublic  = "public"
)

Predefined metadata values.

View Source
const (
	HeaderAccept      = "Accept"
	HeaderContentType = "Content-Type"
	HeaderDestination = "Destination"
	HeaderLocation    = "Location"
)

Additional HTTP constants.

View Source
const (
	QueryKeyCommand   = "cmd"
	QueryKeyEncoding  = "enc"
	QueryKeyParseOnly = "parseonly"
	QueryKeyPart      = "part"
	QueryKeyPhrase    = "phrase"
	QueryKeyQuery     = "q"
	QueryKeyRole      = "role"
	QueryKeySeed      = "_seed"
	QueryKeyTag       = "tag"
)

Values for HTTP query parameter.

View Source
const (
	EncodingHTML  = "html"  // Plain HTML
	EncodingMD    = "md"    // Markdown
	EncodingSHTML = "shtml" // SxHTML
	EncodingSz    = "sz"    // Structure of zettel, encoded a an S-expression
	EncodingText  = "text"  // plain text content
	EncodingZMK   = "zmk"   // Zettelmarkup

	EncodingPlain = "plain" // Plain zettel, no processing
	EncodingData  = "data"  // Plain zettel, metadata as S-Expression
)

Supported encoding values.

View Source
const (
	PartMeta    = "meta"
	PartContent = "content"
	PartZettel  = "zettel"
)

Supported part values.

View Source
const (
	CommandAuthenticated = Command("authenticated")
	CommandRefresh       = Command("refresh")
)

Supported command values.

View Source
const (
	BackwardDirective = "BACKWARD" // Backward-only context
	ContextDirective  = "CONTEXT"  // Context directive
	CostDirective     = "COST"     // Maximum cost of a context operation
	ForwardDirective  = "FORWARD"  // Forward-only context
	FullDirective     = "FULL"     // Include tags in context
	IdentDirective    = "IDENT"    // Use only specified zettel
	ItemsDirective    = "ITEMS"    // Select list elements in a zettel
	MaxDirective      = "MAX"      // Maximum number of context results
	LimitDirective    = "LIMIT"    // Maximum number of zettel
	OffsetDirective   = "OFFSET"   // Offset to start returned zettel list
	OrDirective       = "OR"       // Combine several search expression with an "or"
	OrderDirective    = "ORDER"    // Specify metadata keys for the order of returned list
	PhraseDirective   = "PHRASE"   // Only unlinked zettel with given phrase
	PickDirective     = "PICK"     // Pick some random zettel
	RandomDirective   = "RANDOM"   // Order zettel list randomly
	ReverseDirective  = "REVERSE"  // Reverse the order of a zettel list
	UnlinkedDirective = "UNLINKED" // Search for zettel that contain a phase(s) but do not link

	ActionSeparator = "|" // Separates action list of previous elements of query expression

	KeysAction     = "KEYS"     // Provide metadata key used
	MinAction      = "MIN"      // Return only those values with a minimum amount of zettel
	MaxAction      = "MAX"      // Return only those values with a maximum amount of zettel
	NumberedAction = "NUMBERED" // Return a numbered list
	RedirectAction = "REDIRECT" // Return the first zettel in list
	ReIndexAction  = "REINDEX"  // Ensure that zettel is/are indexed.

	ExistOperator    = "?"  // Does zettel have metadata with given key?
	ExistNotOperator = "!?" // True id zettel does not have metadata with given key.

	SearchOperatorNot        = "!"
	SearchOperatorEqual      = "="  // True if values are equal
	SearchOperatorNotEqual   = "!=" // False if values are equal
	SearchOperatorHas        = ":"  // True if values are equal/included
	SearchOperatorHasNot     = "!:" // False if values are equal/included
	SearchOperatorPrefix     = "["  // True if value is prefix of the other
	SearchOperatorNoPrefix   = "![" // False if value is prefix of the other
	SearchOperatorSuffix     = "]"  // True if value is suffix of other
	SearchOperatorNoSuffix   = "!]" // False if value is suffix of other
	SearchOperatorMatch      = "~"  // True if value is included in other
	SearchOperatorNoMatch    = "!~" // False if value is included in other
	SearchOperatorLess       = "<"  // True if value is smaller than other
	SearchOperatorNotLess    = "!<" // False if value is smaller than other
	SearchOperatorGreater    = ">"  // True if value is greater than other
	SearchOperatorNotGreater = "!>" // False if value is greater than other
)

Supported search operator representations.

View Source
const InvalidZID = ""

InvalidZID is an invalid zettel identifier

View Source
const LengthZid = len(ZidDefaultHome)

LengthZid factors the constant length of a zettel identifier

View Source
const QueryPrefix = "query:"

QueryPrefix is the prefix that denotes a query expression within a reference.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate map[string][]ZettelID

Aggregate maps metadata keys to list of zettel identifier.

type Command

type Command string

Command to be executed atthe Zettelstore

type EncodingEnum

type EncodingEnum uint8

EncodingEnum lists all valid encoder keys.

const (
	EncoderUnknown EncodingEnum = iota
	EncoderHTML
	EncoderMD
	EncoderSHTML
	EncoderSz
	EncoderText
	EncoderZmk

	EncoderPlain
	EncoderData
)

Values for EncoderEnum

func Encoder

func Encoder(encoding string) EncodingEnum

Encoder returns the internal encoder code for the given encoding string.

func (EncodingEnum) String

func (e EncodingEnum) String() string

String representation of an encoder key.

type MetaRights

type MetaRights struct {
	Meta   ZettelMeta
	Rights ZettelRights
}

MetaRights contains the metadata of a zettel, and its rights.

type URLBuilder

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

URLBuilder should be used to create zettelstore URLs.

func NewURLBuilder

func NewURLBuilder(prefix string, key byte) *URLBuilder

NewURLBuilder creates a new URL builder with the given prefix and key.

func (*URLBuilder) AppendKVQuery

func (ub *URLBuilder) AppendKVQuery(key, value string) *URLBuilder

AppendKVQuery adds a new key/value query parameter.

func (*URLBuilder) AppendPath

func (ub *URLBuilder) AppendPath(p string) *URLBuilder

AppendPath adds a new path element.

func (*URLBuilder) AppendQuery

func (ub *URLBuilder) AppendQuery(value string) *URLBuilder

AppendQuery adds a new query.

Basically the same as URLBuilder.AppendKVQuery(api.QueryKeyQuery, value)

func (*URLBuilder) ClearQuery

func (ub *URLBuilder) ClearQuery() *URLBuilder

ClearQuery removes all query parameters.

func (*URLBuilder) Clone

func (ub *URLBuilder) Clone() *URLBuilder

Clone an URLBuilder.

func (*URLBuilder) SetFragment

func (ub *URLBuilder) SetFragment(s string) *URLBuilder

SetFragment sets the fragment.

func (*URLBuilder) SetZid

func (ub *URLBuilder) SetZid(zid ZettelID) *URLBuilder

SetZid sets the zettel identifier.

func (*URLBuilder) String

func (ub *URLBuilder) String() string

String produces a string value.

type ZettelData

type ZettelData struct {
	Meta     ZettelMeta
	Rights   ZettelRights
	Encoding string
	Content  string // raw, uninterpreted zettel content
}

ZettelData contains all data for a zettel.

  • Meta is a map containing the metadata of the zettel.
  • Rights is an integer specifying the access rights.
  • Encoding is a string specifying the encoding of the zettel content.
  • Content is the zettel content itself.

type ZettelID

type ZettelID string

ZettelID contains the identifier of a zettel. It is a string with 14 digits.

func (ZettelID) IsValid

func (zid ZettelID) IsValid() bool

IsValid returns true, if the idenfifier contains 14 digits.

type ZettelMeta

type ZettelMeta map[string]string

ZettelMeta is a map containg the normalized metadata of a zettel.

type ZettelRights

type ZettelRights uint8

ZettelRights is an integer that encode access rights for a zettel.

const (
	ZettelCanNone   ZettelRights = 1 << iota
	ZettelCanCreate              // Current user is allowed to create a new zettel
	ZettelCanRead                // Requesting user is allowed to read the zettel
	ZettelCanWrite               // Requesting user is allowed to update the zettel

	ZettelCanDelete // Requesting user is allowed to delete the zettel
	ZettelMaxRight  // Sentinel value
)

Values for ZettelRights, can be or-ed

type ZidMetaRights

type ZidMetaRights struct {
	ID     ZettelID
	Meta   ZettelMeta
	Rights ZettelRights
}

ZidMetaRights contains the identifier, the metadata of a zettel, and its rights.

Jump to

Keyboard shortcuts

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