api

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package api provides the Logseq HTTP API client and graph-opening utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockNotFoundViaAPI = errors.New("block not found via API")

ErrBlockNotFoundViaAPI is returned when a block UUID query returns no results from the Logseq API.

View Source
var ErrFailedOpenGraph = errors.New("failed to open graph")

ErrFailedOpenGraph is returned when the graph cannot be opened.

View Source
var ErrInvalidResponseStatus = errors.New("invalid response status")

ErrInvalidResponseStatus is returned when the Logseq API returns a non-200 status code.

View Source
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

func BuildRefLookup(tasks []TaskJSON) map[int]string

BuildRefLookup builds a mapping from Logseq ref ID to human-readable name.

func BuildTaskListQuery

func BuildTaskListQuery(tags []string, includeCanceled, includeDone bool) string

BuildTaskListQuery assembles the Logseq Datalog query for listing tasks. It matches the Python `lqdpy tasks` query format exactly.

func EnrichTasksWithAncestorTags

func EnrichTasksWithAncestorTags(tasks []TaskJSON, refLookup map[int]string) map[string]string

EnrichTasksWithAncestorTags adds inherited tags from pathRefs to each task's tag set.

func OpenGraphFromPath

func OpenGraphFromPath(path string) *logseq.Graph

OpenGraphFromPath opens a Logseq graph from the given directory path. Delegates to logseqext.OpenGraphFromPath.

func OpenPage

func OpenPage(graph *logseq.Graph, pageTitle string) logseq.Page

OpenPage opens a page in the Logseq graph. Delegates to logseqext.OpenPage.

func SortTasksByDate

func SortTasksByDate(tasks []TaskJSON)

SortTasksByDate sorts tasks in place by (JournalDay, Content) ascending, matching Python's Block.sort_by_date behavior.

func TaskDoing

func TaskDoing(t TaskJSON) bool

TaskDoing checks if the task has the DOING marker.

func TaskFutureScheduled

func TaskFutureScheduled(t TaskJSON, currentTime func() time.Time) bool

TaskFutureScheduled checks if the task is scheduled for the future (tomorrow onwards) and it's not overdue.

func TaskOverdue

func TaskOverdue(t TaskJSON, currentTime func() time.Time) bool

TaskOverdue checks if the task is overdue based on deadline or scheduled date.

Types

type BlockQueryInfo

type BlockQueryInfo struct {
	PageName    string
	JournalDate time.Time
	IsJournal   bool
}

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

func NewLogseqAPI(path, hostURL, apiToken string) LogseqAPI

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 RefJSON

type RefJSON struct {
	ID   int    `json:"id"`
	Name string `json:"name,omitempty"`
}

RefJSON represents a reference entry from the Logseq API response.

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

func ExtractTasksFromJSON(jsonStr string) ([]TaskJSON, error)

ExtractTasksFromJSON parses a JSON string into a slice of TaskJSON.

type TaskUUID

type TaskUUID = string

TaskUUID is a type alias for task block UUIDs, making it clear when a string represents a Logseq block UUID.

Jump to

Keyboard shortcuts

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