Documentation
¶
Overview ¶
Package collab is Caster's "collab" namespace as Basalisk keeps it (contract collab/v1): what the owner and the agent work on together, drafts (code, content, plans), artifacts under review and diagrams. Each is a document caster://collab/<kind>.<slug>, Markdown with a YAML front matter, so every save is a revision and any two can be compared, with its marks beside it (caster://collab/<name>.marks, JSON). A mark is something pointed at plus a note.
A helper beside the contract, as tetherlink is: a module that keeps its documents in Caster uses this rather than its own client, so Desk and Basalisk read and write the same documents the same way. Ported from Basalisk (internal/collab), over module/tetherlink.
Index ¶
- Constants
- Variables
- func ValidName(name string) bool
- type Anchor
- type Conflict
- type Doc
- type Mark
- type Revision
- type Store
- func (s *Store) Create(ctx context.Context, d Doc, by string) (Doc, error)
- func (s *Store) Get(ctx context.Context, name string, rev int) (Doc, error)
- func (s *Store) List(ctx context.Context, kind string) ([]Doc, error)
- func (s *Store) Log(ctx context.Context, name string) ([]Revision, error)
- func (s *Store) MarkOp(ctx context.Context, name, op string, m Mark) ([]Mark, error)
- func (s *Store) Marks(ctx context.Context, name string) ([]Mark, error)
- func (s *Store) Save(ctx context.Context, name string, base int, title *string, body string, ...) (Doc, error)
- func (s *Store) SetDeleted(ctx context.Context, name string, base int, deleted bool, by string) (Doc, error)
- func (s *Store) Update(ctx context.Context, name string, base int, change func(*Doc), by string) (Doc, error)
Constants ¶
const ( KindDraft = "draft" KindArtifact = "artifact" KindDiagram = "diagram" )
Kinds of document.
const Namespace = "collab"
Namespace is where the documents live in Caster.
Variables ¶
var ErrNotFound = errors.New("no such document")
ErrNotFound means there is no such document; Conflict that it moved on since it was read.
var Tools = tetherlink.Allowed{"caster_get": true, "caster_put": true, "caster_ls": true, "caster_log": true}
Tools are the gateway tools a Store calls: give them to tetherlink.New's Allowed. Only caster_put writes.
Functions ¶
Types ¶
type Anchor ¶
type Anchor struct {
// Text: the passage, with a little of what is around it, and the lines it was on.
Quote string `json:"quote,omitempty"`
Prefix string `json:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty"`
LineStart int `json:"line_start,omitempty"`
LineEnd int `json:"line_end,omitempty"`
// A region of an image, a page or a mock, as fractions of its width and height.
X *float64 `json:"x,omitempty"`
Y *float64 `json:"y,omitempty"`
W *float64 `json:"w,omitempty"`
H *float64 `json:"h,omitempty"`
Page int `json:"page,omitempty"`
// A time in a video or a recording, in seconds.
Time *float64 `json:"time,omitempty"`
// A node or an edge of a diagram, by id.
Node string `json:"node,omitempty"`
Edge string `json:"edge,omitempty"`
// An element of a mock, by a CSS selector.
Selector string `json:"selector,omitempty"`
}
Anchor is what a mark points at. Which fields are set depends on the document.
type Conflict ¶
type Conflict struct{ Rev int }
Conflict is returned by a write when the document has a newer revision than the edit began on, or when someone else wrote between this read and this write (Caster's put takes no expected revision, so the revision it answers is checked: both writes stay in its history).
type Doc ¶
type Doc struct {
Deleted bool `json:"deleted,omitempty"`
Name string `json:"name"`
Kind string `json:"kind"`
Title string `json:"title"`
// Lang is what a draft is written in (markdown, go, typescript, text…).
Lang string `json:"lang,omitempty"`
Project string `json:"project,omitempty"`
// Ref is what an artifact points at: a file ("file:<root>:<path>"), a web address, a
// fragment ("fragment:<id>").
Ref string `json:"ref,omitempty"`
Created string `json:"created,omitempty"`
Rev int `json:"rev"`
Updated string `json:"updated,omitempty"`
// Body is the text of a draft, the JSON of a diagram, the notes of an artifact.
Body string `json:"body"`
}
Doc is one document at a revision.
type Mark ¶
type Mark struct {
ID string `json:"id"`
// Rev is the document's revision the mark was made on.
Rev int `json:"rev"`
Anchor Anchor `json:"anchor"`
// Kind: comment, suggestion (Replace is what to put instead of the quote), question.
Kind string `json:"kind"`
Text string `json:"text,omitempty"`
Replace string `json:"replace,omitempty"`
// By: "user" or "agent".
By string `json:"by"`
State string `json:"state"` // open | done | declined
At string `json:"at"`
Reply string `json:"reply,omitempty"`
}
Mark is a note on something pointed at.
type Store ¶
type Store struct {
Link func() (tetherlink.Caller, error)
Source string
}
Store reads and writes the documents through the Tether gateway. Nothing is kept here. Link is asked for the client at each call, so a module's settings are read at the moment of use. Source names the writer in Caster's revision log ("surface" by default): "<source>:owner" or "<source>:agent".
func (*Store) Create ¶
Create makes a new document and returns it. The name is made from the title: the slug, then slug-2 … slug-200 when it is taken. A name someone else took between the check and the write (Caster then answers a later revision than 1) is given up for the next.
func (*Store) Get ¶
Get is a document at a revision (0 = latest), with when that revision was written (from caster_log, which caster_get does not say).
func (*Store) List ¶
List is the documents of a kind ("" for all), most recently changed first, without bodies. It is one caster_ls: a document written here carries its kind, language, creation and whether it is hidden as tags. One without them has its front matter read (a small read); one that cannot be read is left out and logged, and the rest are listed.
func (*Store) MarkOp ¶
MarkOp changes a document's marks: "add" (the id and time are given here), "update" (the fields set in m replace those of the mark with its id) or "remove". The marks are read again immediately before writing, so two writers do not undo each other's.
func (*Store) Save ¶
func (s *Store) Save(ctx context.Context, name string, base int, title *string, body string, by string) (Doc, error)
Save writes a new revision of a document's body (and title, when given). base is the revision the edit began on: when the document has moved on since, nothing is written and a *Conflict says where it is now. base 0 is the revision read just before the write; a write by someone else between the two is still caught (putOver).
func (*Store) SetDeleted ¶
func (s *Store) SetDeleted(ctx context.Context, name string, base int, deleted bool, by string) (Doc, error)
SetDeleted hides or restores a document without erasing revisions or marks: in its front matter, as Basalisk does, and as the tag "deleted", so a list sees it without reading it. by is who did it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package collabtest is an in-memory Caster for tests of code that reads and writes Caster through module/tetherlink (module/collab, a module's own Caster sync).
|
Package collabtest is an in-memory Caster for tests of code that reads and writes Caster through module/tetherlink (module/collab, a module's own Caster sync). |