client

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client communicates with the Logseq HTTP API.

func New

func New(apiURL, token string) *Client

New creates a new Logseq API client. If apiURL is empty, it reads LOGSEQ_API_URL from the environment, defaulting to "http://127.0.0.1:12315". If token is empty, it reads LOGSEQ_API_TOKEN from the environment.

Returns a ready-to-use client with a 10-second HTTP timeout. The client retries server errors up to 3 times with exponential backoff.

func (*Client) AppendBlockInPage

func (c *Client) AppendBlockInPage(ctx context.Context, page string, content string) (*types.BlockEntity, error)

AppendBlockInPage adds a block with the given content at the end of the named page. Returns the created block entity. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) CreatePage

func (c *Client) CreatePage(ctx context.Context, name string, properties map[string]any, opts map[string]any) (*types.PageEntity, error)

CreatePage creates a new page with the given name and optional properties and options. Returns the created page entity. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) DSLQuery

func (c *Client) DSLQuery(ctx context.Context, dsl string) (json.RawMessage, error)

DSLQuery executes a Logseq DSL query string. Returns the raw JSON response. Returns an error if the API call fails.

func (*Client) DatascriptQuery

func (c *Client) DatascriptQuery(ctx context.Context, query string, inputs ...any) (json.RawMessage, error)

DatascriptQuery executes a Datalog query against the Logseq database. Returns the raw JSON response. Returns an error if the API call fails.

func (*Client) DeletePage

func (c *Client) DeletePage(ctx context.Context, name string) error

DeletePage removes a page by name. Returns an error if the API call fails.

func (*Client) GetAllPages

func (c *Client) GetAllPages(ctx context.Context) ([]types.PageEntity, error)

GetAllPages returns all pages in the Logseq graph as a slice of types.PageEntity. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetAllTags

func (c *Client) GetAllTags(ctx context.Context) ([]types.PageEntity, error)

GetAllTags returns all tags in the graph as page entities. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetBlock

func (c *Client) GetBlock(ctx context.Context, uuid string, opts ...map[string]any) (*types.BlockEntity, error)

GetBlock returns a block by its UUID with optional query options. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetBlockProperties

func (c *Client) GetBlockProperties(ctx context.Context, uuid string) (map[string]any, error)

GetBlockProperties returns all properties for a block identified by UUID. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetCurrentGraph

func (c *Client) GetCurrentGraph(ctx context.Context) (*GraphInfo, error)

GetCurrentGraph returns the name and filesystem path of the current Logseq graph. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetPage

func (c *Client) GetPage(ctx context.Context, nameOrID any) (*types.PageEntity, error)

GetPage returns a page by name (string) or numeric ID. Returns nil if the page does not exist. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetPageBlocksTree

func (c *Client) GetPageBlocksTree(ctx context.Context, nameOrID any) ([]types.BlockEntity, error)

GetPageBlocksTree returns the full hierarchical block tree for a page, identified by name (string) or numeric ID. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetPageLinkedReferences

func (c *Client) GetPageLinkedReferences(ctx context.Context, nameOrID any) (json.RawMessage, error)

GetPageLinkedReferences returns pages that link to this page, with the blocks containing the links. Returns the raw JSON response from the Logseq API. Returns an error if the API call fails.

func (*Client) GetPageProperties

func (c *Client) GetPageProperties(ctx context.Context, nameOrID any) (map[string]any, error)

GetPageProperties returns all properties for a page identified by name (string) or numeric ID. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) GetPagesFromNamespace

func (c *Client) GetPagesFromNamespace(ctx context.Context, namespace string) ([]types.PageEntity, error)

GetPagesFromNamespace returns all pages in the given namespace. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) HasDataScript

func (c *Client) HasDataScript()

HasDataScript marks the Logseq client as supporting DataScript queries. Implements backend.HasDataScript.

func (*Client) InsertBatchBlock

func (c *Client) InsertBatchBlock(ctx context.Context, srcBlock any, batch []map[string]any, opts map[string]any) ([]types.BlockEntity, error)

InsertBatchBlock inserts multiple blocks at once relative to the source block. Returns the created block entities. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) InsertBlock

func (c *Client) InsertBlock(ctx context.Context, srcBlock any, content string, opts map[string]any) (*types.BlockEntity, error)

InsertBlock inserts a block with the given content relative to the source block (by UUID or page name). Returns the created block entity. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) MoveBlock

func (c *Client) MoveBlock(ctx context.Context, uuid string, targetUUID string, opts map[string]any) error

MoveBlock moves a block identified by uuid to a new location relative to targetUUID. Returns an error if the API call fails.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks if the Logseq API is reachable by calling getCurrentPage. Returns nil if the API responds successfully. Returns an error if the API is unreachable or returns an error status.

func (*Client) PrependBlockInPage

func (c *Client) PrependBlockInPage(ctx context.Context, page string, content string) (*types.BlockEntity, error)

PrependBlockInPage adds a block with the given content at the start of the named page. Returns the created block entity. Returns an error if the API call fails or the response cannot be parsed.

func (*Client) RemoveBlock

func (c *Client) RemoveBlock(ctx context.Context, uuid string) error

RemoveBlock deletes a block by UUID. Returns an error if the API call fails.

func (*Client) RenamePage

func (c *Client) RenamePage(ctx context.Context, oldName, newName string) error

RenamePage renames a page from oldName to newName. Logseq handles link updates automatically. Returns an error if the API call fails.

func (*Client) UpdateBlock

func (c *Client) UpdateBlock(ctx context.Context, uuid string, content string, opts ...map[string]any) error

UpdateBlock modifies a block's content identified by UUID. Returns an error if the API call fails.

type GraphInfo

type GraphInfo struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

GraphInfo represents the current graph's metadata.

Jump to

Keyboard shortcuts

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