anytype

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 1

README

Anytype-Go SDK

Go Report Card GoDoc

A Go SDK for interacting with the Anytype API to manage spaces, objects, and perform searches. This library provides a feature-rich, fluent interface to integrate Anytype functionality into your Go applications.

Table of Contents

📋 Overview

Anytype-Go provides a Go SDK for interacting with Anytype's local API. This SDK offers a clean, fluent interface for:

  • Managing spaces and their members
  • Creating, reading, updating, and deleting objects
  • Searching for objects using various filters
  • Exporting objects to different formats
  • Working with object types, templates, and properties

📥 Installation

go get github.com/epheo/anytype-go

Import both the main package and client implementation:

import (
    "github.com/epheo/anytype-go"
    _ "github.com/epheo/anytype-go/client" // Register client implementation
)

🚦 Quick Start

📁 More complete examples can be found in the examples directory, including full implementations of authentication, working with spaces, objects, and more.

Authentication

To use the Anytype API, you need to obtain an AppKey and SessionToken. Here's how to get them:

// Step 1: Initiate authentication and get challenge ID
authResponse, err := client.Auth().DisplayCode(ctx, "MyAnytypeApp")
if err != nil {
    log.Fatalf("Failed to initiate authentication: %v", err)
}
challengeID := authResponse.ChallengeID

// Step 2: User needs to enter the code shown in Anytype app
fmt.Println("Please enter the authentication code shown in Anytype:")
var code string
fmt.Scanln(&code)

// Step 3: Complete authentication and get tokens
tokenResponse, err := client.Auth().GetToken(ctx, challengeID, code)
if err != nil {
    log.Fatalf("Authentication failed: %v", err)
}

// Now you have your authentication tokens
appKey := tokenResponse.AppKey
sessionToken := tokenResponse.SessionToken

// Create authenticated client
client := anytype.NewClient(
    anytype.WithBaseURL("http://localhost:31009"), // Default Anytype local API URL
    anytype.WithAppKey(appKey),
    anytype.WithSessionToken(sessionToken),
)

Note: The authentication flow requires user interaction. When you call DisplayCode, Anytype will show a verification code that must be entered in your application.

Working with Spaces
// List all spaces
spaces, err := client.Spaces().List(ctx)

// Get a specific space
space, err := client.Space(spaceID).Get(ctx)

// Create a new space
newSpace, err := client.Spaces().Create(ctx, anytype.CreateSpaceRequest{
    Name:        "My New Workspace",
    Description: "Created via the Go SDK",
})
Working with Objects
// Get an object
object, err := client.Space(spaceID).Object(objectID).Get(ctx)

// Delete an object
err = client.Space(spaceID).Object(objectID).Delete(ctx)

// Export an object to markdown
exportResult, err := client.Space(spaceID).Object(objectID).Export(ctx, "markdown")

// Create a new object
newObject, err := client.Space(spaceID).Objects().Create(ctx, anytype.CreateObjectRequest{
    TypeKey:     "ot-page",
    Name:        "My New Page",
    Description: "Created via the Go SDK",
    Body:        "# This is a new page\n\nWith some content in markdown format.",
    Icon: &anytype.Icon{
        Type:  "emoji",
        Value: "📄",
    },
})
Searching
// Search within a specific space
results, err := client.Space(spaceID).Search(ctx, anytype.SearchRequest{
    Query: "important notes",
    Sort: anytype.SortOptions{
        Property:  anytype.SortPropertyLastModifiedDate,
        Direction: anytype.SortDirectionDesc,
    },
    Types: []string{"ot-note", "ot-page"}, // Filter by specific types
})

🔧 Advanced Examples

Working with Object Types and Templates
// List available object types in a space
objectTypes, err := client.Space(spaceID).Types().List(ctx)

// Get details of a specific object type
typeDetails, err := client.Space(spaceID).Type(typeID).Get(ctx)

// Create a new template based on an object type
newTemplate, err := client.Space(spaceID).Templates().Create(ctx, anytype.CreateTemplateRequest{
    Name:        "Project Template",
    Description: "Template for project documentation",
    TypeID:      typeID,
    Icon: &anytype.Icon{
        Type:  "emoji",
        Value: "📋",
    },
    DefaultProperties: []string{"name", "description", "status", "deadline"},
})

// Get a specific template
template, err := client.Space(spaceID).Template(templateID).Get(ctx)
Managing Object Properties
// Update object properties
err := client.Space(spaceID).Object(objectID).UpdateProperties(ctx, anytype.UpdatePropertiesRequest{
    Properties: map[string]interface{}{
        "name":        "Updated Title",
        "description": "Updated description",
        "status":      "In Progress",
        "priority":    "High",
        "deadline":    time.Now().AddDate(0, 0, 14).Format(time.RFC3339),
    },
})

// Add a relation to another object
err := client.Space(spaceID).Object(objectID).AddRelation(ctx, relatedObjectID, "related-to")
Working with Lists and Views
// Create a new list to organize objects
newList, err := client.Space(spaceID).Lists().Create(ctx, anytype.CreateListRequest{
    Name:        "Project Tasks",
    Description: "All tasks for our current project",
    Icon: &anytype.Icon{
        Type:  "emoji",
        Value: "📝",
    },
})

// Add objects to a list
err := client.Space(spaceID).List(listID).AddObjects(ctx, []string{objectID1, objectID2})

// Create a custom view for a list
newView, err := client.Space(spaceID).List(listID).Views().Create(ctx, anytype.CreateViewRequest{
    Name: "Priority View",
    Type: "board",
    GroupBy: []string{"priority"},
    SortBy: []anytype.SortOptions{
        {
            Property:  "deadline",
            Direction: anytype.SortDirectionAsc,
        },
    },
    Filters: []anytype.FilterCondition{
        {
            Property: "status",
            Operator: anytype.OperatorNotEquals,
            Value:    "Completed",
        },
    },
})

💡 Design Philosophy

The Anytype-Go SDK is built around three core design principles:

1. Fluent Interface Pattern
exportedMarkdown, err := client.
    Space(spaceID).
    Object(objectID).
    Export(ctx, "markdown")

Benefits:

  • Readable code that mirrors natural language
  • IDE autocomplete reveals available operations
  • Compile-time type safety
  • Reduced boilerplate code
2. Domain-Driven Design

The SDK is organized around Anytype's core concepts (spaces, objects, types) with interfaces that map directly to these concepts:

  • SpaceClient and SpaceContext for spaces
  • ObjectClient and ObjectContext for objects
  • TypeClient for object types
  • ListClient for lists and views
3. Naming Convention

The naming of interfaces and types in this library follows a clear and consistent pattern to improve code readability and API fluency:

  • <Entity>Client: Represents a client that operates on collections of entities (e.g., SpaceClient for working with multiple spaces, TypeClient for working with multiple object types). These clients handle operations like listing, searching, and creating new entities.
  • <Entity>Context: Represents a client that operates on a single, specific entity instance (e.g., SpaceContext for a single space, ObjectContext for a single object). These handle operations like getting details, updating, or deleting a specific entity.

This naming convention creates a fluent, chainable API where:

  1. Collection operations use the <Entity>Client pattern (e.g., client.Spaces().List())
  2. Instance operations use the <Entity>Context pattern (e.g., client.Space(spaceID).Get())
  3. Nested resources follow a natural hierarchy (e.g., client.Space(spaceID).Object(objectID).Export())

This design enables intuitive navigation through the API that mirrors natural language and domain concepts.

4. Middleware Architecture
HTTP Request → ValidationMiddleware → RetryMiddleware → DisconnectMiddleware → HTTP Client → API

Each middleware handles a specific concern:

  • Validation: Validates requests before sending
  • Retry: Handles transient errors with configurable policies
  • Disconnect: Manages network interruptions

📚 API Reference

For detailed API documentation, see GoDoc.

✅ Best Practices

  1. Reuse the client instance across your application
  2. Use context for cancellation to control timeouts
  3. Handle rate limiting with appropriate backoff strategies
  4. Validate inputs before making API calls
  5. Check for errors and handle them appropriately
  6. Use the fluent interface for cleaner, more readable code

🔧 Troubleshooting

  • Authentication Failures**: Verify your app key and session token
  • Connection Issues**: Ensure Anytype is running locally
  • Rate Limiting**: Implement backoff if making many requests

🧪 Testing

The SDK testing approach focuses on behavior verification using mock implementations:

Unit Tests with Mocks

tests: Tests ensure that client interfaces behave according to specifications using mock implementations to simulate API responses.

go test -v ./tests/...
API Coverage Tests

tests_api_coverage: Tests verify that all API endpoints are properly defined and can be called with appropriate parameters.

go test -v ./tests_api_coverage/...

The test infrastructure uses mock implementations (in tests/mocks) to simulate the Anytype API, allowing thorough testing without requiring a running Anytype instance.

👥 Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

📜 License

Apache License 2.0 - see LICENSE file for details.

Documentation

Overview

Package anytype provides a Go SDK for interacting with the Anytype API.

Index

Constants

View Source
const (
	// Member roles
	MemberRoleViewer MemberRole = "viewer"
	MemberRoleEditor MemberRole = "editor"
	MemberRoleOwner  MemberRole = "owner"

	// Member statuses
	MemberStatusJoining  MemberStatus = "joining"
	MemberStatusActive   MemberStatus = "active"
	MemberStatusRemoved  MemberStatus = "removed"
	MemberStatusDeclined MemberStatus = "declined"
	MemberStatusRemoving MemberStatus = "removing"
	MemberStatusCanceled MemberStatus = "canceled"
)
View Source
const (
	// Sort properties
	SortPropertyCreatedDate      SortProperty = "created_date"
	SortPropertyLastModifiedDate SortProperty = "last_modified_date"
	SortPropertyLastOpenedDate   SortProperty = "last_opened_date"
	SortPropertyName             SortProperty = "name"

	// Sort directions
	SortDirectionAsc  SortDirection = "asc"
	SortDirectionDesc SortDirection = "desc"
)
View Source
const (
	// Version is the current version of the anytype-go SDK.
	// This follows Semantic Versioning (https://semver.org/):
	// MAJOR.MINOR.PATCH where:
	// - MAJOR version changes with incompatible API changes
	// - MINOR version adds functionality in a backwards compatible manner
	// - PATCH version makes backwards compatible bug fixes
	Version = "0.3.2"
)

Version information

Variables

This section is empty.

Functions

func RegisterClientConstructor

func RegisterClientConstructor(constructor clientConstructor)

RegisterClientConstructor registers a constructor function for creating Client instances

Types

type AuthClient

type AuthClient interface {
	// DisplayCode initiates a secure authentication flow
	DisplayCode(ctx context.Context, appName string) (*DisplayCodeResponse, error)

	// GetToken completes the authentication flow by providing a code
	GetToken(ctx context.Context, challengeID string, code string) (*TokenResponse, error)
}

AuthClient provides operations for authentication

type Block

type Block struct {
	ID              string
	Text            *Text
	File            *File
	Property        *Property
	ChildrenIDs     []string `json:"children_ids"`
	Align           string
	VerticalAlign   string `json:"vertical_align"`
	BackgroundColor string `json:"background_color"`
}

Block represents a content block within an object

type BlockClient

type BlockClient interface {
	// List returns all blocks in the object
	List(ctx context.Context) ([]Block, error)

	// Get retrieves a specific block by ID
	Get(ctx context.Context, blockID string) (*Block, error)

	// Create creates a new block in the object
	Create(ctx context.Context, request CreateBlockRequest) (*Block, error)

	// Update updates a block in the object
	Update(ctx context.Context, blockID string, request UpdateBlockRequest) error

	// Delete deletes a block from the object
	Delete(ctx context.Context, blockID string) error
}

BlockClient provides operations on blocks within an object

type Client

type Client interface {
	// Auth returns an AuthClient for authentication operations
	Auth() AuthClient

	// Spaces returns a SpaceClient for working with spaces
	Spaces() SpaceClient

	// Space returns a specific SpaceContext for working with a given space
	Space(spaceID string) SpaceContext

	// Search returns a SearchClient for global search operations
	Search() SearchClient
}

Client is the main interface for interacting with the Anytype API

func NewClient

func NewClient(opts ...ClientOption) Client

NewClient creates a new Anytype API client with the given options

type ClientOption

type ClientOption func(*ClientOptions)

ClientOption is a function type that modifies ClientOptions

func WithAppKey

func WithAppKey(appKey string) ClientOption

WithAppKey sets the app key for authentication

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets the base URL for API requests

func WithSessionToken

func WithSessionToken(token string) ClientOption

WithSessionToken sets the session token for authentication

type ClientOptions

type ClientOptions struct {
	BaseURL      string
	AppKey       string
	SessionToken string
}

ClientOptions contains configuration options for the Anytype client

type CreateBlockRequest

type CreateBlockRequest struct {
	Text           *Text
	File           *File
	Property       *Property
	ParentID       string `json:"parent_id"`
	TargetPosition int    `json:"target_position"`
}

CreateBlockRequest contains parameters for creating a new block

type CreateObjectRequest

type CreateObjectRequest struct {
	TypeKey     string `json:"type_key"`
	Name        string
	Description string
	Body        string
	Icon        *Icon
	TemplateID  string `json:"template_id,omitempty"`
	Source      string // Only applicable for bookmarks
}

CreateObjectRequest contains parameters for creating a new object

type CreateSpaceRequest

type CreateSpaceRequest struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Icon        *Icon  `json:"icon,omitempty"`
}

CreateSpaceRequest represents the request body for creating a new space

type CreateSpaceResponse

type CreateSpaceResponse struct {
	Space Space `json:"space"`
}

CreateSpaceResponse represents the response from Create space

type DisplayCodeResponse

type DisplayCodeResponse struct {
	ChallengeID string `json:"challenge_id"`
}

DisplayCodeResponse represents the response from the display_code endpoint

type ExportResult

type ExportResult struct {
	Markdown string `json:"markdown,omitempty"`
}

ExportResult represents the result of an object export operation

type File

type File struct {
	Name           string
	Hash           string
	Mime           string
	Size           int64
	Type           string
	State          string
	Style          string
	AddedAt        int64  `json:"added_at"`
	TargetObjectID string `json:"target_object_id"`
}

File represents a file reference

type Icon

type Icon struct {
	Format IconFormat `json:"format,omitempty"` // Type of icon: emoji, file, or icon
	Emoji  string     `json:"emoji,omitempty"`  // The emoji character if format is emoji
	File   string     `json:"file,omitempty"`   // The file URL if format is file
	Name   string     `json:"name,omitempty"`   // The name of the icon if format is icon
	Color  string     `json:"color,omitempty"`  // The color of the icon
}

Icon represents an object icon

type IconFormat

type IconFormat string

IconFormat represents the type of icon

const (
	// IconFormatEmoji represents an emoji icon
	IconFormatEmoji IconFormat = "emoji"
	// IconFormatFile represents a file icon
	IconFormatFile IconFormat = "file"
	// IconFormatIcon represents a named icon
	IconFormatIcon IconFormat = "icon"
)

type ListClient

type ListClient interface {
	// Add is used for adding objects to any list
	Add(ctx context.Context, objectIDs []string) error
}

ListClient provides operations on lists within a space

type ListContext

type ListContext interface {
	// Views returns a ViewClient for this list
	Views() ViewClient

	// View returns a ViewContext for a specific view in this list
	View(viewID string) ViewContext

	// Objects returns an ObjectListClient for this list
	Objects() ObjectListClient

	// Object returns an ObjectListContext for a specific object in this list
	Object(objectID string) ObjectListContext
}

ListContext provides operations on a specific list

type ListFilter

type ListFilter struct {
	ID          string `json:"id"`
	PropertyKey string `json:"property_key"`
	Format      string `json:"format"`
	Condition   string `json:"condition"`
	Value       string `json:"value"`
}

ListFilter represents a filter applied to a list view

type ListSort

type ListSort struct {
	ID          string `json:"id"`
	PropertyKey string `json:"property_key"`
	Format      string `json:"format"`
	SortType    string `json:"sort_type"`
}

ListSort represents a sort applied to a list view

type ListView

type ListView struct {
	ID      string       `json:"id"`
	Name    string       `json:"name"`
	Layout  string       `json:"layout"`
	Filters []ListFilter `json:"filters,omitempty"`
	Sorts   []ListSort   `json:"sorts,omitempty"`
}

ListView represents a view configuration for a list

type Member

type Member struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	GlobalName string `json:"global_name"`
	Identity   string `json:"identity"`
	Role       string `json:"role"`
	Status     string `json:"status"`
	Icon       *Icon  `json:"icon,omitempty"`
}

Member represents a member of a space

type MemberClient

type MemberClient interface {
	// List retrieves all members of the space
	List(ctx context.Context) (*MemberListResponse, error)
}

MemberClient provides operations on space members

type MemberContext

type MemberContext interface {
	// Get retrieves details about this member
	Get(ctx context.Context) (*MemberResponse, error)
}

MemberContext provides operations on a specific member

type MemberListResponse

type MemberListResponse struct {
	Data []Member `json:"data"`
}

MemberListResponse represents the response from List members

type MemberResponse

type MemberResponse struct {
	Member Member `json:"member"`
}

MemberResponse represents the response from Get member

type MemberRole

type MemberRole string

MemberRole represents a role of a space member

type MemberStatus

type MemberStatus string

MemberStatus represents the status of a space member

type Object

type Object struct {
	ID         string
	Name       string
	SpaceID    string `json:"space_id"`
	TypeKey    string
	Layout     string
	Archived   bool
	Icon       *Icon
	Snippet    string
	Properties []Property
	Type       *Type `json:"type,omitempty"`
}

Object represents an Anytype object

type ObjectClient

type ObjectClient interface {
	// List returns all objects in the space
	List(ctx context.Context, opts ...options.ListOption) ([]Object, error)

	// Create creates a new object in the space
	Create(ctx context.Context, request CreateObjectRequest) (*ObjectResponse, error)
}

ObjectClient provides operations on objects within a space

type ObjectContext

type ObjectContext interface {
	// Get retrieves the object
	Get(ctx context.Context) (*ObjectResponse, error)

	// Delete deletes the object
	Delete(ctx context.Context) (*ObjectResponse, error)

	// Export exports the object in the specified format
	Export(ctx context.Context, format string) (*ExportResult, error)
}

ObjectContext provides operations on a specific object

type ObjectListClient

type ObjectListClient interface {
	// List returns all objects in the list
	List(ctx context.Context) (*ObjectListResponse, error)

	// Add adds objects to the list
	Add(ctx context.Context, objectIDs []string) error
}

ObjectListClient provides operations on objects within a list

type ObjectListContext

type ObjectListContext interface {
	// Remove removes the object from the list
	Remove(ctx context.Context) error
}

ObjectListContext provides operations on a specific object within a list

type ObjectListResponse

type ObjectListResponse struct {
	Data       []Object `json:"data"`
	Pagination struct {
		Limit   int  `json:"limit"`
		Offset  int  `json:"offset"`
		Total   int  `json:"total"`
		HasMore bool `json:"has_more"`
	} `json:"pagination"`
}

ObjectListResponse represents the paginated response for objects in a list

type ObjectResponse

type ObjectResponse struct {
	Object *Object `json:"object"`
}

ObjectResponse wraps an Object in a response according to the API specification

type ObjectViewClient

type ObjectViewClient interface {
	// List returns all objects in the view
	List(ctx context.Context) (*ObjectListResponse, error)
}

ObjectViewClient provides operations on objects within a view

type Property

type Property struct {
	ID          string
	Format      string
	Text        string
	Number      float64
	Checkbox    bool
	Date        string
	URL         string
	Email       string
	Phone       string
	File        []string
	Select      *Tag     `json:"select"`
	MultiSelect []Tag    `json:"multi_select"`
	ObjectLinks []string `json:"object"`
	Relations   []Relation
	Key         string
	Name        string
	Required    bool
}

Property represents an object property

type PropertyClient

type PropertyClient interface {
	// Get retrieves a specific property value
	Get(ctx context.Context, key string) (*Property, error)

	// Set sets a property value
	Set(ctx context.Context, key string, value interface{}) error

	// Delete removes a property
	Delete(ctx context.Context, key string) error

	// List returns all properties of the object
	List(ctx context.Context) ([]Property, error)
}

PropertyClient provides operations on properties of an object

type PropertyDefinition

type PropertyDefinition struct {
	Key      string
	Name     string
	Format   string
	Required bool
	Options  []PropertyOption
}

PropertyDefinition defines a property that can be used with a type

type PropertyOption

type PropertyOption struct {
	ID    string
	Value string
	Color string
}

PropertyOption represents an option for select/multi-select properties

type PropertyUpdateRequest

type PropertyUpdateRequest struct {
	Key   string
	Value interface{}
}

PropertyUpdateRequest contains parameters for updating a property

type Relation

type Relation struct {
	ID       string
	Type     string
	Format   string
	ObjectID string `json:"object_id"`
}

Relation represents a relation within a property

type SearchClient

type SearchClient interface {
	// Search searches for objects across all spaces
	Search(ctx context.Context, request SearchRequest) (*SearchResponse, error)
}

SearchClient provides global search operations across all spaces

type SearchRequest

type SearchRequest struct {
	Query string       `json:"query"`
	Types []string     `json:"types,omitempty"` // Object type keys or IDs to filter by
	Sort  *SortOptions `json:"sort,omitempty"`  // Use pointer so it's omitted when nil
}

SearchRequest represents a search query

type SearchResponse

type SearchResponse struct {
	Data []Object `json:"data"`
}

SearchResponse represents the response from a search operation

type SortDirection

type SortDirection string

SortDirection represents the direction to sort search results

type SortOptions

type SortOptions struct {
	Property  SortProperty  `json:"property"`
	Direction SortDirection `json:"direction"`
}

SortOptions represents sorting options for search results

type SortProperty

type SortProperty string

SortProperty represents the property to sort search results by

type Space

type Space struct {
	ID           string
	Name         string
	Description  string
	Icon         *Icon
	HomeID       string `json:"home_id"`
	ArchiveID    string `json:"archive_id"`
	ProfileID    string `json:"profile_id"`
	CreatedAt    int64  `json:"created_at"`
	LastOpenedAt int64  `json:"last_opened_at"`
}

Space represents an Anytype workspace/space

type SpaceClient

type SpaceClient interface {
	// List returns all spaces accessible to the user
	List(ctx context.Context) (*SpaceListResponse, error)

	// Create creates a new space
	Create(ctx context.Context, request CreateSpaceRequest) (*CreateSpaceResponse, error)
}

SpaceClient provides operations on spaces

type SpaceContext

type SpaceContext interface {
	// Get retrieves information about this space
	Get(ctx context.Context) (*SpaceResponse, error)

	// Objects returns an ObjectClient for this space
	Objects() ObjectClient

	// Object returns an ObjectContext for a specific object in this space
	Object(objectID string) ObjectContext

	// Types returns a TypeClient for this space
	Types() TypeClient

	// Type returns a TypeContext for a specific type in this space
	Type(typeID string) TypeContext

	// Search searches for objects within this space
	Search(ctx context.Context, request SearchRequest) (*SearchResponse, error)

	// Lists returns a ListClient for this space
	Lists() ListClient

	// List returns a ListContext for a specific list in this space
	List(listID string) ListContext

	// Members returns a MemberClient for this space
	Members() MemberClient

	// Member returns a MemberContext for a specific member in this space
	Member(memberID string) MemberContext
}

SpaceContext provides operations within a specific space

type SpaceListResponse

type SpaceListResponse struct {
	Data []Space `json:"data"`
}

SpaceListResponse represents the response from List spaces

type SpaceResponse

type SpaceResponse struct {
	Space Space `json:"space"`
}

SpaceResponse represents the response from Get space

type Tag

type Tag struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`
}

Tag represents a select or multi-select value option

type Template

type Template struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Icon     *Icon  `json:"icon,omitempty"`
	Archived bool   `json:"archived"`
}

Template represents a template for creating objects

type TemplateClient

type TemplateClient interface {
	// List retrieves all templates for a type
	List(ctx context.Context) ([]Template, error)

	// Get retrieves a specific template by ID
	Get(ctx context.Context, templateID string) (*Template, error)
}

TemplateClient provides operations on templates for a specific type

type TemplateContext

type TemplateContext interface {
	// Get retrieves details of this specific template
	Get(ctx context.Context) (*TemplateResponse, error)
}

TemplateContext provides operations on a specific template

type TemplateResponse

type TemplateResponse struct {
	Template Template `json:"template"`
}

TemplateResponse represents the response from a Get call on a template

type Text

type Text struct {
	Content  string
	Style    string
	Markdown string
}

Text represents text content within a block

type TokenResponse

type TokenResponse struct {
	AppKey       string `json:"app_key"`
	SessionToken string `json:"session_token"`
}

TokenResponse represents the response from the token endpoint

type Type

type Type struct {
	Key               string
	Name              string
	Description       string
	Icon              *Icon
	Layout            string
	RecommendedLayout string `json:"recommended_layout"`
	IsArchived        bool   `json:"is_archived"`
	IsHidden          bool   `json:"is_hidden"`

	// Available property definitions for this type
	PropertyDefinitions []PropertyDefinition `json:"property_definitions"`
}

Type represents an object type in Anytype

type TypeClient

type TypeClient interface {
	// List returns all available object types in the space
	List(ctx context.Context) ([]Type, error)

	// Get retrieves details of a specific type by key
	Get(ctx context.Context, typeKey string) (*Type, error)

	// GetKeyByName looks up a type key by its name
	GetKeyByName(ctx context.Context, name string) (string, error)

	// Type returns a TypeContext for a specific type in this space
	Type(typeID string) TypeContext
}

TypeClient provides operations on object types within a space

type TypeContext

type TypeContext interface {
	// Get retrieves details of this specific type
	Get(ctx context.Context) (*TypeResponse, error)

	// Templates returns a TemplateClient for this type
	Templates() TemplateClient

	// Template returns a TemplateContext for a specific template of this type
	Template(templateID string) TemplateContext
}

TypeContext provides operations on a specific object type

type TypeResponse

type TypeResponse struct {
	Type Type `json:"type"`
}

TypeResponse represents the response from a Get call on a type

type UpdateBlockRequest

type UpdateBlockRequest struct {
	Text            *Text
	File            *File
	Property        *Property
	Align           string
	VerticalAlign   string `json:"vertical_align"`
	BackgroundColor string `json:"background_color"`
}

UpdateBlockRequest contains parameters for updating a block

type UpdateObjectRequest

type UpdateObjectRequest struct {
	Name        string
	Description string
	Icon        *Icon
	Properties  []PropertyUpdateRequest
}

UpdateObjectRequest contains parameters for updating an object

type UpdateSpaceRequest

type UpdateSpaceRequest struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
	Icon        *Icon   `json:"icon,omitempty"`
}

UpdateSpaceRequest represents the request body for updating a space

type VersionInfo

type VersionInfo struct {
	// Version is the semantic version of the SDK
	Version string `json:"version"`
	// APIVersion is the Anytype API version this client works with
	APIVersion string `json:"api_version"`
}

VersionInfo holds detailed version information

func GetVersionInfo

func GetVersionInfo() VersionInfo

GetVersionInfo returns version information for the SDK

type ViewClient

type ViewClient interface {
	// List retrieves all views for the list
	List(ctx context.Context) (*ViewListResponse, error)
}

ViewClient provides operations on views within a list

type ViewContext

type ViewContext interface {
	// Objects returns an ObjectViewClient for this view
	Objects() ObjectViewClient
}

ViewContext provides operations on a specific view

type ViewListResponse

type ViewListResponse struct {
	Data       []ListView `json:"data"`
	Pagination struct {
		Limit   int  `json:"limit"`
		Offset  int  `json:"offset"`
		Total   int  `json:"total"`
		HasMore bool `json:"has_more"`
	} `json:"pagination"`
}

ViewListResponse represents the paginated response for list views

Directories

Path Synopsis
filepath: /home/epheo/dev/anytype-go/pkg/anytype/client/auth.go
filepath: /home/epheo/dev/anytype-go/pkg/anytype/client/auth.go
Package middleware provides HTTP middleware components for the anytype client
Package middleware provides HTTP middleware components for the anytype client
filepath: /home/epheo/dev/anytype-go/pkg/anytype/options/list.go
filepath: /home/epheo/dev/anytype-go/pkg/anytype/options/list.go

Jump to

Keyboard shortcuts

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