Documentation
¶
Overview ¶
Package api provides the Logseq HTTP API client and graph-opening utilities.
Index ¶
- Variables
- func BuildRefLookup(tasks []TaskJSON) map[int]string
- func BuildTaskListQuery(tags []string, includeCanceled, includeDone bool) string
- func EnrichTasksWithAncestorTags(tasks []TaskJSON, refLookup map[int]string) map[string]string
- func OpenGraphFromPath(path string) *logseq.Graph
- func OpenPage(graph *logseq.Graph, pageTitle string) logseq.Page
- func SortTasksByDate(tasks []TaskJSON)
- func TaskDoing(t TaskJSON) bool
- func TaskFutureScheduled(t TaskJSON, currentTime func() time.Time) bool
- func TaskOverdue(t TaskJSON, currentTime func() time.Time) bool
- type BlockQueryInfo
- type CategorizedTasks
- type LogseqAPI
- type PageJSON
- type RefJSON
- type TaskJSON
- type TaskUUID
Constants ¶
This section is empty.
Variables ¶
var ErrBlockNotFoundViaAPI = errors.New("block not found via API")
ErrBlockNotFoundViaAPI is returned when a block UUID query returns no results from the Logseq API.
var ErrFailedOpenGraph = errors.New("failed to open graph")
ErrFailedOpenGraph is returned when the graph cannot be opened.
var ErrInvalidResponseStatus = errors.New("invalid response status")
ErrInvalidResponseStatus is returned when the Logseq API returns a non-200 status code.
var ErrMissingConfig = errors.New("LOGSEQ_API_TOKEN and LOGSEQ_HOST_URL must be set")
ErrMissingConfig is returned when the Logseq API token or host URL is not set.
Functions ¶
func BuildRefLookup ¶
BuildRefLookup builds a mapping from Logseq ref ID to human-readable name.
func BuildTaskListQuery ¶
BuildTaskListQuery assembles the Logseq Datalog query for listing tasks. It matches the Python `lqdpy tasks` query format exactly.
func EnrichTasksWithAncestorTags ¶
EnrichTasksWithAncestorTags adds inherited tags from pathRefs to each task's tag set.
func OpenGraphFromPath ¶
OpenGraphFromPath opens a Logseq graph from the given directory path. Delegates to logseqext.OpenGraphFromPath.
func SortTasksByDate ¶
func SortTasksByDate(tasks []TaskJSON)
SortTasksByDate sorts tasks in place by (JournalDay, Content) ascending, matching Python's Block.sort_by_date behavior.
func TaskFutureScheduled ¶
TaskFutureScheduled checks if the task is scheduled for the future (tomorrow onwards) and it's not overdue.
Types ¶
type BlockQueryInfo ¶
BlockQueryInfo holds the result of a UUID lookup via Logseq API.
func FindBlockByUUID ¶
func FindBlockByUUID(api LogseqAPI, uuid string) (*BlockQueryInfo, error)
FindBlockByUUID queries the Logseq HTTP API to find a block by UUID. Uses PostDatascriptQuery (logseq.db.datascriptQuery) because the pull syntax required here is not supported by logseq.db.q (PostQuery). The nested {:block/page [*]} expands page attributes; without it, page is just {id: N}.
type CategorizedTasks ¶
type CategorizedTasks struct {
All *set.Set[TaskUUID]
Overdue *set.Set[TaskUUID]
Doing *set.Set[TaskUUID]
FutureScheduled *set.Set[TaskUUID]
TaskLookup map[TaskUUID]TaskJSON
}
CategorizedTasks holds sets of task UUIDs grouped by category.
func NewCategorizedTasks ¶
func NewCategorizedTasks() CategorizedTasks
NewCategorizedTasks creates a new CategorizedTasks with initialized sets.
type LogseqAPI ¶
type LogseqAPI interface {
PostQuery(query string) (string, error)
PostDatascriptQuery(query string) (string, error)
// UpsertBlockProperty sets a block property via the Logseq Editor API.
// This causes Logseq to write the property to the .md file immediately,
// which is useful to force the id:: property onto disk for blocks that
// Logseq has tracked internally but not yet written back.
UpsertBlockProperty(uuid, key, value string) error
}
LogseqAPI is the interface for communicating with a running Logseq instance via its HTTP API.
func NewLogseqAPI ¶
NewLogseqAPI creates a new LogseqAPI instance.
type PageJSON ¶
type PageJSON struct {
ID int `json:"id"`
JournalDay int `json:"journalDay"`
Name string `json:"name"`
OriginalName string `json:"originalName"`
}
PageJSON holds page-level metadata from the Logseq API.
type TaskJSON ¶
type TaskJSON struct {
UUID TaskUUID `json:"uuid"`
Marker string `json:"marker"`
Content string `json:"content"`
Page PageJSON `json:"page"`
Deadline int `json:"deadline"`
Scheduled int `json:"scheduled"`
Refs []RefJSON `json:"refs"`
PathRefs []RefJSON `json:"pathRefs"`
PropertiesTextValues map[string]string `json:"propertiesTextValues"`
}
TaskJSON represents a task block from the Logseq HTTP API.
func ExtractTasksFromJSON ¶
ExtractTasksFromJSON parses a JSON string into a slice of TaskJSON.