Documentation
¶
Index ¶
- type Client
- func (c *Client) AppendBlockInPage(ctx context.Context, page string, content string) (*types.BlockEntity, error)
- func (c *Client) CreatePage(ctx context.Context, name string, properties map[string]any, ...) (*types.PageEntity, error)
- func (c *Client) DSLQuery(ctx context.Context, dsl string) (json.RawMessage, error)
- func (c *Client) DatascriptQuery(ctx context.Context, query string, inputs ...any) (json.RawMessage, error)
- func (c *Client) DeletePage(ctx context.Context, name string) error
- func (c *Client) GetAllPages(ctx context.Context) ([]types.PageEntity, error)
- func (c *Client) GetAllTags(ctx context.Context) ([]types.PageEntity, error)
- func (c *Client) GetBlock(ctx context.Context, uuid string, opts ...map[string]any) (*types.BlockEntity, error)
- func (c *Client) GetBlockProperties(ctx context.Context, uuid string) (map[string]any, error)
- func (c *Client) GetCurrentGraph(ctx context.Context) (*GraphInfo, error)
- func (c *Client) GetPage(ctx context.Context, nameOrID any) (*types.PageEntity, error)
- func (c *Client) GetPageBlocksTree(ctx context.Context, nameOrID any) ([]types.BlockEntity, error)
- func (c *Client) GetPageLinkedReferences(ctx context.Context, nameOrID any) (json.RawMessage, error)
- func (c *Client) GetPageProperties(ctx context.Context, nameOrID any) (map[string]any, error)
- func (c *Client) GetPagesFromNamespace(ctx context.Context, namespace string) ([]types.PageEntity, error)
- func (c *Client) HasDataScript()
- func (c *Client) InsertBatchBlock(ctx context.Context, srcBlock any, batch []map[string]any, opts map[string]any) ([]types.BlockEntity, error)
- func (c *Client) InsertBlock(ctx context.Context, srcBlock any, content string, opts map[string]any) (*types.BlockEntity, error)
- func (c *Client) MoveBlock(ctx context.Context, uuid string, targetUUID string, opts map[string]any) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) PrependBlockInPage(ctx context.Context, page string, content string) (*types.BlockEntity, error)
- func (c *Client) RemoveBlock(ctx context.Context, uuid string) error
- func (c *Client) RenamePage(ctx context.Context, oldName, newName string) error
- func (c *Client) UpdateBlock(ctx context.Context, uuid string, content string, opts ...map[string]any) error
- type GraphInfo
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 ¶
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 ¶
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 ¶
DeletePage removes a page by name. Returns an error if the API call fails.
func (*Client) GetAllPages ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
RemoveBlock deletes a block by UUID. Returns an error if the API call fails.
func (*Client) RenamePage ¶
RenamePage renames a page from oldName to newName. Logseq handles link updates automatically. Returns an error if the API call fails.