docprovider

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docprovider is the contract of the documents and boards service behind the runtime's document reader: list, read, publish a new version, rights (public link, grants), comments (list, reply, close) and the address to embed. The built-in artifacts catalog and boards server (internal/integrations, RUNTIME_ARTIFACTS_URL, RUNTIME_BOARDS_URL) are the default implementation and nothing changes without an adapter. A corporate service connects as an adapter of the extension frame (internal/hub/ext), protocol harnessly.docs/v1 (docs/doc-adapters.md).

Index

Constants

View Source
const (
	ReprMarkdown    = "markdown"
	ReprStructured  = "structured"
	ReprBoard       = "board"
	ReprUnsupported = "unsupported"
)

Representations a document read may answer with.

View Source
const (
	MaxBlocks       = 5000
	MaxBlockText    = 64 << 10
	MaxMarkdown     = 2 << 20
	MaxSceneObjects = 500
	MaxSceneText    = 8 << 10
	MaxPoints       = 64
	MaxAsset        = 8 << 20
)

Limits of one native answer; what goes over is cut, not passed on.

View Source
const BindingsFile = "doc-bindings.json"

BindingsFile is the store's file in the runtime's data directory.

View Source
const MaxExternalID = 72

MaxExternalID is the longest external ID that has an alias (its alias stays within the runtime's slug limit).

View Source
const Protocol = "harnessly.docs/v1"

Protocol is what a documents adapter speaks. The adapter is an HTTP service of the extension frame (internal/hub/ext): GET /v1/describe, then POST calls with a JSON body, as the connection and memory adapters.

capability read      POST /v1/list {limit} -> {docs: [Summary]}        POST /v1/get {slug} -> Summary
                     POST /v1/read {slug, version} -> Content         POST /v1/versions {slug} -> {versions}
                     POST /v1/diff {slug, from, to} -> Diff            POST /v1/embed {slug} -> Embed
capability publish   POST /v1/publish PublishRequest -> Published
capability access    POST /v1/access {slug} -> Access                 POST /v1/access/set {slug, public?, grants?} -> Access
capability comments  POST /v1/threads {slug} -> {threads}             POST /v1/threads/create {slug, anchor, body, author} -> Thread
                     POST /v1/threads/reply {slug, threadId, body, author} -> Thread
                     POST /v1/threads/status {slug, threadId, status} -> Thread
                     POST /v1/threads/read {person, slug} -> {}
capability resolve   POST /v1/resolve {url} -> {kind: "document"|"board", id, embed?} (404: not this service's address)
capability native    POST /v1/native {slug, version, accept} -> Native (markdown | structured | unsupported)
                     POST /v1/native/board {slug, cursor, limit} -> Native (board: scene page, or unsupported)
capability native-assets  POST /v1/native/asset {slug, asset} -> {contentType, data (base64)}
capability boards         POST /v1/boards {} -> {boards: [Board]}
capability boards-search  POST /v1/boards/search {query, limit} -> {boards: [Board]}

`read` is required; a call of a capability that is not listed is not sent. A document and a board are named by the adapter's own ID; the runtime shows it as an alias (Alias) and sends the ID back. An answer bigger than the client takes (1 MiB unless the spec's maxAnswerBytes raises it), or a 413 / `too_large`, is ErrTooLarge.

Variables

View Source
var (
	// ErrUnsupported: the provider does not do this (a built-in catalog asked to publish, an adapter without comments).
	ErrUnsupported = errors.New("docprovider: not supported")
	// ErrTooLarge: the document (or the answer about it) is bigger than the runtime takes from the provider.
	ErrTooLarge = errors.New("docprovider: too large")
	// ErrSearchRequired: the provider finds boards only by a query and has no list of them.
	ErrSearchRequired = errors.New("docprovider: boards are found by a query only")
)

Errors a provider answers besides the reader's own (not found, denied, unreachable).

Functions

func Alias

func Alias(id string) string

Alias is the runtime's name of an external ID, "" when the ID is empty or too long to have one.

func AssetTypeOK

func AssetTypeOK(t string) bool

AssetTypeOK says whether an image type may be handed to the page (no SVG: it can carry script).

func ConversationDocuments

func ConversationDocuments(ctx context.Context, p Provider, store *Bindings, conversation string) ([]integrations.Document, error)

ConversationDocuments is what a conversation published, newest first: the provider's own list when it keeps one, else the runtime's bindings with this provider, each refreshed from the provider when it answers (a document the provider no longer has is left out; one it cannot be asked about now is shown as bound).

func Declared

func Declared() bool

Declared says whether a provider other than the built-in one is in use (an adapter of the file, or a pinned one).

func ExternalID

func ExternalID(alias string) (string, bool)

ExternalID is the adapter's ID of an alias; ok is false for a string that is no alias (the caller answers not found).

func Pin

func Pin(p Provider) (restore func())

Pin makes For answer p in this process until the returned function is called: the seam a test or an embedding program uses instead of a declared adapter file.

Types

type Access

type Access struct {
	Public    bool    `json:"public"`
	PublicURL *string `json:"publicUrl"`
	Grants    []Grant `json:"grants,omitempty"`
}

Access is who can reach a document.

type AccessChange

type AccessChange struct {
	Public *bool    `json:"public,omitempty"`
	Grants *[]Grant `json:"grants,omitempty"`
}

AccessChange changes it: a field left nil stays as it was.

type Anchor

type Anchor = integrations.DocAnchor

The shapes are the ones the page's reader already reads.

type Asset

type Asset struct {
	ContentType string `json:"contentType"`
	// Data is the bytes, base64 on the wire.
	Data []byte `json:"data"`
}

Asset is an image of a board.

type Author

type Author = integrations.DocAuthor

The shapes are the ones the page's reader already reads.

type BindError

type BindError struct {
	Published Published
	Err       error
}

BindError: the document was published but the binding was not saved. A repeat with the same key binds it without publishing again.

func (*BindError) Error

func (e *BindError) Error() string

func (*BindError) Unwrap

func (e *BindError) Unwrap() error

type Binding

type Binding struct {
	ID           string    `json:"id"`
	Conversation string    `json:"conversation"`
	Provider     string    `json:"provider"`
	Slug         string    `json:"slug"`
	ExternalID   string    `json:"externalId"`
	ViewURL      string    `json:"viewUrl,omitempty"`
	Title        string    `json:"title"`
	Version      int       `json:"version"`
	Key          string    `json:"key,omitempty"`
	BoundAt      time.Time `json:"boundAt"`
	UpdatedAt    time.Time `json:"updatedAt"`
}

Binding is one document of one conversation.

func PublishToConversation

func PublishToConversation(ctx context.Context, p Provider, store *Bindings, req PublishRequest, key string) (Binding, error)

PublishToConversation publishes req through p and binds the document to req.Conversation. key makes a repeat the same operation (empty: every call publishes).

type Bindings

type Bindings struct {
	Path string
	// contains filtered or unexported fields
}

Bindings is the store. One per data directory in a process (BindingsAt), so the routes that publish and the routes that list share it.

func BindingsAt

func BindingsAt(dataDir string) *Bindings

BindingsAt is the store of a data directory.

func (*Bindings) Of

func (b *Bindings) Of(conversation, provider string) ([]Binding, error)

Of is the bindings of a conversation with one provider, the newest first.

type Block

type Block struct {
	Type  string   `json:"type"`
	Level int      `json:"level,omitempty"`
	Text  string   `json:"text,omitempty"`
	Items []string `json:"items,omitempty"`
	Lang  string   `json:"lang,omitempty"`
}

Block is one piece of a structured document. Type is paragraph, heading (Level 1-6), quote, code, list (Items) or rule. Text is plain.

type Board

type Board = integrations.Board

The shapes are the ones the page's reader already reads.

type Builtin

type Builtin struct {
	Cfg   integrations.Config
	Store *integrations.Threads
}

Builtin is the default provider: the artifacts catalog and the boards server of the deployment, and the comment threads the runtime keeps in its data directory. It is the code the reader used before the contract existed. Publishing goes through the platform agent (internal/docshare), not through this contract, and reading the text goes through the embedded frame, so both answer ErrUnsupported here.

func (Builtin) Access

func (b Builtin) Access(ctx context.Context, slug string) (Access, error)

func (Builtin) Boards

func (b Builtin) Boards(ctx context.Context) ([]Board, error)

func (Builtin) Capabilities

func (b Builtin) Capabilities() Capabilities

func (Builtin) ConversationDocuments

func (b Builtin) ConversationDocuments(ctx context.Context, conversation string) ([]integrations.Document, error)

ConversationDocuments is the catalog's own list by session: the catalog binds what the platform agent published.

func (Builtin) Counts

func (b Builtin) Counts(_ context.Context, person string) (Counts, error)

func (Builtin) CreateThread

func (b Builtin) CreateThread(_ context.Context, slug string, a Anchor, body string, by Author) (Thread, error)

func (Builtin) Diff

func (b Builtin) Diff(ctx context.Context, slug, from, to string) (Diff, error)

func (Builtin) Embed

func (b Builtin) Embed(ctx context.Context, slug string) (Embed, error)

func (Builtin) Get

func (b Builtin) Get(ctx context.Context, slug string) (Summary, error)

func (Builtin) List

func (b Builtin) List(ctx context.Context, limit int) ([]Summary, error)

func (Builtin) MarkRead

func (b Builtin) MarkRead(_ context.Context, person, slug string) error

func (Builtin) Publish

func (Builtin) Read

func (Builtin) Reply

func (b Builtin) Reply(_ context.Context, slug, id, body string, by Author) (Thread, error)

func (Builtin) SearchBoards

func (b Builtin) SearchBoards(ctx context.Context, query string) ([]Board, error)

SearchBoards filters the list by the title: the boards server has no search of its own.

func (Builtin) SetAccess

func (b Builtin) SetAccess(ctx context.Context, slug string, ch AccessChange) (Access, error)

func (Builtin) SetStatus

func (b Builtin) SetStatus(_ context.Context, slug, id, status string) (Thread, error)

func (Builtin) Threads

func (b Builtin) Threads(_ context.Context, slug string) ([]Thread, error)

func (Builtin) Versions

func (b Builtin) Versions(ctx context.Context, slug string) ([]Version, error)

type Capabilities

type Capabilities struct {
	// Provider is the adapter's name, "builtin" for the built-in catalog.
	Provider string `json:"provider"`
	Publish  bool   `json:"publish"`
	Access   bool   `json:"access"`
	Comments bool   `json:"comments"`
	// Boards: there is a list of boards. BoardsSearch: boards can be found by a query (without Boards, only so).
	Boards       bool `json:"boards"`
	BoardsSearch bool `json:"boardsSearch"`
	// ProviderEmbed: documents and boards are framed through Embed, never through their viewer address.
	ProviderEmbed bool `json:"providerEmbed"`
	// Native: documents and boards can be read as text and scene objects without a frame (NativeReader).
	// NativeAssets: the images of a board can be read too.
	Native       bool `json:"native,omitempty"`
	NativeAssets bool `json:"nativeAssets,omitempty"`
	// MaxAnswerBytes is the biggest answer taken from the provider, 0 when there is no such limit.
	MaxAnswerBytes int64 `json:"maxAnswerBytes,omitempty"`
}

Capabilities is what a provider does, for the routes and the page to ask before they call.

type Content

type Content struct {
	// Format is "md" or "html".
	Format  string `json:"format"`
	Content string `json:"content"`
	Version string `json:"version"`
}

Content is a document's text at one version.

type ConversationLister

type ConversationLister interface {
	ConversationDocuments(ctx context.Context, conversation string) ([]integrations.Document, error)
}

ConversationLister is a provider that knows by itself which documents a conversation published (the built-in catalog lists by session).

type Counts

type Counts struct {
	Open   map[string]int
	Unread map[string]int
	Last   map[string]string
}

Counts are the open threads, the unread ones and the last activity of each document, by slug, for one person.

type Diff

type Diff = integrations.DocDiff

The shapes are the ones the page's reader already reads.

type Embed

type Embed struct {
	URL       string    `json:"url"`
	ExpiresAt time.Time `json:"expiresAt,omitempty"`
}

Embed is an address for a frame or a widget; it may expire.

type ExtProvider

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

ExtProvider is a Provider backed by an adapter.

func Adapters

func Adapters() []*ExtProvider

Adapters are the documents adapters the file RUNTIME_DOC_ADAPTERS_FILE declares, loaded once per process. Without the variable there are none and the documents are the built-in catalog, as they always were. An adapter that does not answer is told on stderr; the built-in catalog goes on.

func LoadAdapters

func LoadAdapters(ctx context.Context, path string) ([]*ExtProvider, []error)

LoadAdapters makes a provider of every documents adapter the file declares (ext.Spec, kind "docs"). Entries of other protocols are skipped; one that does not answer is an error and the rest go on.

func NewExtProvider

func NewExtProvider(c *ext.Client, d ext.Description) (*ExtProvider, error)

NewExtProvider is the provider of an adapter that has described itself.

func Register

func Register(ctx context.Context, c *ext.Client) (*ExtProvider, error)

Register asks the adapter to describe itself and, when it speaks the protocol, makes a provider of it.

func (*ExtProvider) Access

func (p *ExtProvider) Access(ctx context.Context, slug string) (Access, error)

func (*ExtProvider) Boards

func (p *ExtProvider) Boards(ctx context.Context) ([]Board, error)

Boards is the adapter's list; an adapter that only searches answers ErrSearchRequired.

func (*ExtProvider) Capabilities

func (p *ExtProvider) Capabilities() Capabilities

Capabilities are the ones the adapter described.

func (*ExtProvider) Counts

func (p *ExtProvider) Counts(context.Context, string) (Counts, error)

Counts are in the list the adapter gives (openThreads, unread), so there is nothing to add.

func (*ExtProvider) CreateThread

func (p *ExtProvider) CreateThread(ctx context.Context, slug string, a Anchor, body string, by Author) (Thread, error)

func (*ExtProvider) Diff

func (p *ExtProvider) Diff(ctx context.Context, slug, from, to string) (Diff, error)

func (*ExtProvider) Embed

func (p *ExtProvider) Embed(ctx context.Context, slug string) (Embed, error)

func (*ExtProvider) Get

func (p *ExtProvider) Get(ctx context.Context, slug string) (Summary, error)

func (*ExtProvider) List

func (p *ExtProvider) List(ctx context.Context, limit int) ([]Summary, error)

func (*ExtProvider) MarkRead

func (p *ExtProvider) MarkRead(ctx context.Context, person, slug string) error

func (*ExtProvider) Name

func (p *ExtProvider) Name() string

Name is the adapter's name.

func (*ExtProvider) NativeAsset

func (p *ExtProvider) NativeAsset(ctx context.Context, slug, asset string) (Asset, error)

NativeAsset reads an image of a board; only the image types of AssetTypeOK pass.

func (*ExtProvider) NativeRead

func (p *ExtProvider) NativeRead(ctx context.Context, slug, version string, board bool, cursor string, limit int) (Native, error)

NativeRead asks the adapter for a native representation. An adapter without the `native` capability, or one that answers 501, gives an explicit unsupported answer; an unknown representation is unsupported too (Sanitize).

func (*ExtProvider) Publish

func (p *ExtProvider) Publish(ctx context.Context, req PublishRequest) (Published, error)

func (*ExtProvider) Read

func (p *ExtProvider) Read(ctx context.Context, slug, version string) (Content, error)

func (*ExtProvider) Reply

func (p *ExtProvider) Reply(ctx context.Context, slug, threadID, body string, by Author) (Thread, error)

func (*ExtProvider) Resolve

func (p *ExtProvider) Resolve(ctx context.Context, address string) (Resolved, bool, error)

Resolve asks the adapter which document or board an address names. An adapter without the `resolve` capability claims nothing (ok is false and no call is sent), so the address keeps the pane's own rules.

func (*ExtProvider) SearchBoards

func (p *ExtProvider) SearchBoards(ctx context.Context, query string) ([]Board, error)

SearchBoards asks the adapter's search, or filters its list when it has no search.

func (*ExtProvider) SetAccess

func (p *ExtProvider) SetAccess(ctx context.Context, slug string, ch AccessChange) (Access, error)

func (*ExtProvider) SetStatus

func (p *ExtProvider) SetStatus(ctx context.Context, slug, threadID, status string) (Thread, error)

func (*ExtProvider) Threads

func (p *ExtProvider) Threads(ctx context.Context, slug string) ([]Thread, error)

func (*ExtProvider) Versions

func (p *ExtProvider) Versions(ctx context.Context, slug string) ([]Version, error)

Versions is the history; an adapter that keeps none (501 on /v1/versions) has an empty one, not an error.

type Grant

type Grant struct {
	Subject string `json:"subject"`
	// Role is "viewer", "commenter" or "editor".
	Role string `json:"role"`
}

Grant gives a person or a group a role on a document.

type Native

type Native struct {
	// Representation is one of the Repr constants.
	Representation string  `json:"representation"`
	Version        string  `json:"version,omitempty"`
	Markdown       string  `json:"markdown,omitempty"`
	Blocks         []Block `json:"blocks,omitempty"`
	Scene          *Scene  `json:"scene,omitempty"`
	// Assets: the board's images can be read (NativeAsset).
	Assets bool `json:"assets,omitempty"`
	// Reason says, for an unsupported representation, why in the provider's words.
	Reason string `json:"reason,omitempty"`
}

Native is the answer of a native read of one object.

func Sanitize

func Sanitize(n Native) Native

Sanitize makes a native answer safe to hand to the page: unknown representations and object types are dropped or turned into unsupported, texts and counts are bounded, numbers are finite. It never invents content.

func Unsupported

func Unsupported(reason string) Native

Unsupported is the answer for a provider that has no native representation.

type NativeReader

type NativeReader interface {
	// NativeRead reads a document ("" version is the current one) or, for a board, one page of its scene (cursor "").
	NativeRead(ctx context.Context, slug, version string, board bool, cursor string, limit int) (Native, error)
	// NativeAsset reads one image of a board with the person's own authorization at the provider.
	NativeAsset(ctx context.Context, slug, asset string) (Asset, error)
}

NativeReader is a Provider that can hand an object over without a frame. It is optional: a provider without it (the built-in catalog, an adapter that does not list `native`) answers every native read as unsupported and shows as before.

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Point is a place on a board.

type Provider

type Provider interface {
	List(ctx context.Context, limit int) ([]Summary, error)
	Get(ctx context.Context, slug string) (Summary, error)
	// Read is the text of a version ("" is the current one).
	Read(ctx context.Context, slug, version string) (Content, error)
	Versions(ctx context.Context, slug string) ([]Version, error)
	Diff(ctx context.Context, slug, from, to string) (Diff, error)
	Publish(ctx context.Context, req PublishRequest) (Published, error)
	Embed(ctx context.Context, slug string) (Embed, error)
	Access(ctx context.Context, slug string) (Access, error)
	SetAccess(ctx context.Context, slug string, change AccessChange) (Access, error)
	Threads(ctx context.Context, slug string) ([]Thread, error)
	CreateThread(ctx context.Context, slug string, anchor Anchor, body string, by Author) (Thread, error)
	Reply(ctx context.Context, slug, threadID, body string, by Author) (Thread, error)
	// SetStatus opens or closes ("open", "resolved") a thread.
	SetStatus(ctx context.Context, slug, threadID, status string) (Thread, error)
	// Boards is the list of boards; ErrSearchRequired when the provider only finds them by a query.
	Boards(ctx context.Context) ([]Board, error)
	// SearchBoards finds boards by a query.
	SearchBoards(ctx context.Context, query string) ([]Board, error)
	Capabilities() Capabilities
	Counts(ctx context.Context, person string) (Counts, error)
	MarkRead(ctx context.Context, person, slug string) error
}

Provider is the documents and boards contract.

func For

For is the provider of a runtime: the declared adapter (the first of the file) when there is one, the built-in catalog otherwise.

type PublishError

type PublishError struct{ Err error }

PublishError: the provider did not publish; nothing was made and nothing was bound.

func (*PublishError) Error

func (e *PublishError) Error() string

func (*PublishError) Unwrap

func (e *PublishError) Unwrap() error

type PublishRequest

type PublishRequest struct {
	Title   string `json:"title"`
	Format  string `json:"format"`
	Content string `json:"content"`
	Slug    string `json:"slug,omitempty"`
	// Visibility is "private" (default) or "public".
	Visibility string `json:"visibility,omitempty"`
	Note       string `json:"note,omitempty"`
	// Conversation is the chat that published it.
	Conversation string `json:"conversation,omitempty"`
}

PublishRequest is a new document or a new version of one (Slug set).

type Published

type Published struct {
	// Slug is the runtime's name of the document; ExternalID the provider's own (they differ for an adapter's ID that
	// is not a slug, see Alias).
	Slug       string `json:"slug"`
	ExternalID string `json:"externalId,omitempty"`
	Version    int    `json:"version"`
	URL        string `json:"url,omitempty"`
}

Published is what a publish made.

type Resolved

type Resolved struct {
	// Kind is "document" or "board".
	Kind string `json:"kind"`
	ID   string `json:"id"`
	// Embed is false when the provider's service cannot be shown in a frame; the address then opens only as a link.
	Embed *bool `json:"embed,omitempty"`
}

Resolved is what an address of the provider's service names (the optional `resolve` capability): a document or a board, by the provider's own ID. ID keeps its case and its hyphens as the provider wrote them; nothing is derived from the address.

func (Resolved) Embeddable

func (r Resolved) Embeddable() bool

Embeddable says whether the provider frames what the address names (an adapter that says nothing does).

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, address string) (r Resolved, ok bool, err error)
}

Resolver is a Provider that tells which document or board an address of its service names. It is optional: a provider without it (the built-in catalog, an adapter that does not list `resolve`) keeps the rules of the pane as they are. ok is false for an address the provider does not claim; the error is a refusal (denied) or an unreachable provider.

type Scene

type Scene struct {
	Objects []SceneObject `json:"objects"`
	Next    string        `json:"next,omitempty"`
}

Scene is one page of a board's objects. Next is the cursor of the following page, "" at the end.

type SceneObject

type SceneObject struct {
	ID     string  `json:"id"`
	Type   string  `json:"type"`
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	W      float64 `json:"w,omitempty"`
	H      float64 `json:"h,omitempty"`
	Text   string  `json:"text,omitempty"`
	From   string  `json:"from,omitempty"`
	To     string  `json:"to,omitempty"`
	Points []Point `json:"points,omitempty"`
	Asset  string  `json:"asset,omitempty"`
}

SceneObject is one thing on a board. Type is shape, text, image, sticky or connector; a connector joins the objects From and To (their IDs) and may carry its own Points. Asset names an image to read through NativeAsset.

type Summary

type Summary = integrations.DocSummary

The shapes are the ones the page's reader already reads.

type Thread

type Thread = integrations.DocThread

The shapes are the ones the page's reader already reads.

type Version

type Version = integrations.DocVersion

The shapes are the ones the page's reader already reads.

Jump to

Keyboard shortcuts

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