docs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionName         = "docs"
	VersionsCollectionName = "doc_versions"
	PinsCollectionName     = "doc_pins"
	FoldersCollectionName  = "doc_folders"

	// KindMarkdown documents use the BlockNote editing flow; KindHTML
	// documents hold a self-contained HTML artifact rendered in a sandboxed
	// preview. The kind is fixed at creation: content mutations validate
	// against the stored kind, never against caller input.
	KindMarkdown = "markdown"
	KindHTML     = "html"
)
View Source
const (
	AssetsCollectionName = "doc_assets"
)
View Source
const (
	SharesCollectionName = "doc_shares"
)

Variables

View Source
var (
	ErrNotFound     = errors.New("document not found")
	ErrForbidden    = errors.New("document access denied")
	ErrConflict     = errors.New("document has a newer revision")
	ErrInvalidInput = errors.New("invalid document input")
	ErrPinLimit     = errors.New("you can pin at most 10 documents")
)
View Source
var ErrShareNotFound = errors.New("shared document not found")

ErrShareNotFound covers every reason a public link cannot be served: unknown slug, expired share, archived or deleted document, attachment outside the published snapshot. Public responses must not tell these apart.

Functions

func Delete

func Delete(ctx context.Context, app core.App, actorID, id string) error

func PublicAsset added in v0.1.0

func PublicAsset(ctx context.Context, app core.App, slug, assetID string) (*core.Record, error)

PublicAsset resolves an attachment referenced by a published snapshot. The content check keeps attachments uploaded after publishing out of the public link, the same way the pinned revision keeps later edits out.

func Register

func Register(app core.App)

func SetPinned

func SetPinned(ctx context.Context, app core.App, actorID, id string, pinned bool) error

func Unpublish added in v0.1.0

func Unpublish(ctx context.Context, app core.App, actorID, id string) error

Unpublish revokes the link by deleting the record, so publishing again issues a new slug instead of reviving the old one.

Types

type Asset added in v0.0.4

type Asset struct {
	ID        string `json:"id"`
	DocID     string `json:"docId"`
	Kind      string `json:"kind"`
	Name      string `json:"name"`
	MediaType string `json:"mediaType"`
	Size      int64  `json:"size"`
	URL       string `json:"url"`
}

func UploadAsset added in v0.0.4

func UploadAsset(ctx context.Context, app core.App, actorID, docID string, file *filesystem.File) (Asset, error)

type CreateInput

type CreateInput struct {
	Title     string `json:"title"`
	Kind      string `json:"kind"`
	Content   string `json:"content"`
	ProjectID string `json:"projectId"`
	FolderID  string `json:"folderId"`
	Source    string `json:"-"`
}

type Document

type Document struct {
	ID           string `json:"id"`
	Title        string `json:"title"`
	Kind         string `json:"kind"`
	Content      string `json:"content"`
	OwnerID      string `json:"ownerId"`
	ProjectID    string `json:"projectId,omitempty"`
	ProjectName  string `json:"projectName,omitempty"`
	FolderID     string `json:"folderId,omitempty"`
	FolderName   string `json:"folderName,omitempty"`
	Status       string `json:"status"`
	Revision     int    `json:"revision"`
	LastEditedBy string `json:"lastEditedBy"`
	Created      string `json:"created"`
	Updated      string `json:"updated"`
}

func Create

func Create(ctx context.Context, app core.App, actorID string, input CreateInput) (Document, error)

func Get

func Get(ctx context.Context, app core.App, actorID, id string) (Document, error)

func Move added in v0.0.8

func Move(ctx context.Context, app core.App, actorID, id string, input MoveInput) (Document, error)

func MoveToProject

func MoveToProject(ctx context.Context, app core.App, actorID, id, projectID string) (Document, error)

func Replace

func Replace(ctx context.Context, app core.App, actorID, id string, input ReplaceInput) (Document, int, bool, error)

func Restore

func Restore(ctx context.Context, app core.App, actorID, id string, revision, baseRevision int) (Document, error)
func Search(ctx context.Context, app core.App, actorID string, options SearchOptions) ([]Document, error)

func SetArchived

func SetArchived(ctx context.Context, app core.App, actorID, id string, archived bool) (Document, error)

func Update

func Update(ctx context.Context, app core.App, actorID, id string, input UpdateInput) (Document, bool, error)

func WriteChunk added in v0.0.6

func WriteChunk(ctx context.Context, app core.App, actorID string, input WriteChunkInput) (Document, error)

WriteChunk writes long content in pieces, for callers (mainly AI tools) whose single-call output is limited. Mode "replace" starts a new chunked write: it bumps the revision and records one version. Mode "append" extends the same write: it keeps the revision and syncs that version's snapshot, so a whole chunked session leaves exactly one version entry. Both modes require the caller's baseRevision to match, and each call returns the revision to pass next.

type DocumentSummary added in v0.0.7

type DocumentSummary struct {
	ID           string `json:"id"`
	Title        string `json:"title"`
	Kind         string `json:"kind"`
	OwnerID      string `json:"ownerId"`
	ProjectID    string `json:"projectId,omitempty"`
	ProjectName  string `json:"projectName,omitempty"`
	FolderID     string `json:"folderId,omitempty"`
	FolderName   string `json:"folderName,omitempty"`
	Status       string `json:"status"`
	Revision     int    `json:"revision"`
	LastEditedBy string `json:"lastEditedBy"`
	Created      string `json:"created"`
	Updated      string `json:"updated"`
}

func ListPinned

func ListPinned(ctx context.Context, app core.App, actorID, query string) ([]DocumentSummary, error)

type Folder added in v0.0.8

type Folder struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	OwnerID string `json:"ownerId"`
	Created string `json:"created"`
	Updated string `json:"updated"`
}

func EnsureFolder added in v0.0.9

func EnsureFolder(ctx context.Context, app core.App, actorID, name string) (Folder, bool, error)

EnsureFolder resolves a personal folder by name, creating it only when no folder of that name exists. Matching is case-insensitive so "Reviews" and "reviews" cannot both exist.

The idempotent shape is deliberate: the assistant would otherwise have to list, compare, and then create, and a retried or repeated run would leave duplicate folders behind. Returns whether a folder was created so callers can report the difference.

func ListFolders added in v0.0.8

func ListFolders(ctx context.Context, app core.App, actorID string) ([]Folder, error)

type MoveInput added in v0.0.8

type MoveInput struct {
	Destination   string `json:"destination"`
	DestinationID string `json:"destinationId"`
}

type PublicDocument added in v0.1.0

type PublicDocument struct {
	Title     string `json:"title"`
	Kind      string `json:"kind"`
	Content   string `json:"content"`
	Revision  int    `json:"revision"`
	Published string `json:"published"`
}

PublicDocument is everything an anonymous reader receives. Owner, project, folder, and editor identities stay out of it.

func PublicDoc added in v0.1.0

func PublicDoc(ctx context.Context, app core.App, slug string) (PublicDocument, error)

PublicDoc serves a shared document to an anonymous reader. It reads the pinned revision from doc_versions, so edits made after publishing stay private until the owner republishes.

type ReplaceInput

type ReplaceInput struct {
	ID           string `json:"id"`
	Find         string `json:"find"`
	Replace      string `json:"replace"`
	ReplaceAll   bool   `json:"replaceAll"`
	BaseRevision int    `json:"baseRevision"`
	Source       string `json:"-"`
}

type SearchOptions

type SearchOptions struct {
	Query     string
	Limit     int
	FolderID  string
	ProjectID string
	RootOnly  bool
}

type Share added in v0.1.0

type Share struct {
	DocID    string `json:"docId"`
	Slug     string `json:"slug"`
	Revision int    `json:"revision"`
	Expires  string `json:"expires,omitempty"`
	Created  string `json:"created"`
	Updated  string `json:"updated"`
}

func GetShare added in v0.1.0

func GetShare(ctx context.Context, app core.App, actorID, id string) (Share, error)

GetShare reports the current share of a document, or ErrShareNotFound when it is not shared.

func Publish added in v0.1.0

func Publish(ctx context.Context, app core.App, actorID, id string, input ShareInput) (Share, error)

Publish exposes the document's current revision under a public slug, and on an existing share updates its expiry and, when asked, its published revision. Only the owner can publish, matching archive and delete.

type ShareInput added in v0.1.0

type ShareInput struct {
	Expires string `json:"expires"`
	// Republish moves an existing share to the document's current revision.
	// Without it, changing the expiry of a share leaves the published
	// snapshot where it is, so adjusting a date can never leak an unfinished
	// draft.
	Republish bool `json:"republish"`
}

type UpdateInput

type UpdateInput struct {
	Title        string `json:"title"`
	Content      string `json:"content"`
	BaseRevision int    `json:"baseRevision"`
	Source       string `json:"-"`
}

type Version

type Version struct {
	ID        string `json:"id"`
	Revision  int    `json:"revision"`
	Title     string `json:"title"`
	Content   string `json:"content,omitempty"`
	CreatedBy string `json:"createdBy"`
	Source    string `json:"source"`
	Created   string `json:"created"`
}

func GetVersion

func GetVersion(ctx context.Context, app core.App, actorID, id string, revision int) (Version, error)

func ListVersions

func ListVersions(ctx context.Context, app core.App, actorID, id string) ([]Version, error)

type WriteChunkInput added in v0.0.6

type WriteChunkInput struct {
	ID           string `json:"id"`
	Content      string `json:"content"`
	Mode         string `json:"mode"`
	BaseRevision int    `json:"baseRevision"`
	Source       string `json:"-"`
}

Jump to

Keyboard shortcuts

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