output

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMachineDocumentBytes = 4 << 20
View Source
const MaxSafeMachineInteger int64 = 9007199254740991
View Source
const MaxWatchLineBytes = 1 << 20

Variables

View Source
var ErrInvalidWatchDocument = errors.New("invalid watch document")
View Source
var ErrPartialWatchLine = errors.New("partial JSONL write; stream is no longer recoverable")
View Source
var ErrWatchOutput = errors.New("watch output unavailable")

Functions

func FormatMarkdown

func FormatMarkdown(outputs []MessageOutput, dates DateFormatter, options MarkdownOptions) string

FormatMarkdown renders already-presented values without further sanitizing them.

func FormatPretty

func FormatPretty(outputs []MessageOutput, dates DateFormatter, options PrettyOptions) string

FormatPretty renders already-presented values. It deliberately performs no sanitization or redaction of its own.

func FormatUnreadMarkdown

func FormatUnreadMarkdown(document UnreadEnvelope, peek []MessageOutput, dates DateFormatter, options MarkdownOptions) (string, error)

func FormatUnreadPretty

func FormatUnreadPretty(document UnreadEnvelope, peek []MessageOutput, dates DateFormatter, options PrettyOptions) (string, error)

func FormatWatchHumanLine

func FormatWatchHumanLine(timestamp time.Time, sender, message string, color bool) string

func ValidMachineSchema

func ValidMachineSchema(command, schema string) bool

func WriteBoundedJSON

func WriteBoundedJSON(w io.Writer, value any) (int, error)

WriteBoundedJSON emits canonical machine JSON using the same byte policy as WriteMachineJSON. It is for versioned machine documents whose concrete type is owned outside output's closed MachineDocument set.

func WriteMachineJSON

func WriteMachineJSON(w io.Writer, value MachineDocument) (int, error)

WriteMachineJSON encodes one bounded value, appends exactly one newline, and performs one write. A short or failed write is returned and never retried.

func WriteMarkdown

func WriteMarkdown(w io.Writer, outputs []MessageOutput, dates DateFormatter, options MarkdownOptions) (int, error)

WriteMarkdown renders and writes exactly once. It never retries an uncertain write.

func WritePretty

func WritePretty(w io.Writer, outputs []MessageOutput, dates DateFormatter, options PrettyOptions) (int, error)

WritePretty renders once and writes once. A short write is returned as io.ErrShortWrite and is never retried, since the writer's state is unknown.

func WriteWatchDocument

func WriteWatchDocument(writer io.Writer, document WatchDocument) error

Types

type Attachment

type Attachment struct {
	Fallback   string            `json:"fallback,omitempty"`
	Pretext    string            `json:"pretext,omitempty"`
	Title      string            `json:"title,omitempty"`
	TitleLink  string            `json:"titleLink,omitempty"`
	Text       string            `json:"text,omitempty"`
	Fields     []AttachmentField `json:"fields,omitempty"`
	Footer     string            `json:"footer,omitempty"`
	FooterIcon string            `json:"footerIcon,omitempty"`
	AuthorName string            `json:"authorName,omitempty"`
	AuthorLink string            `json:"authorLink,omitempty"`
	AuthorIcon string            `json:"authorIcon,omitempty"`
	Color      string            `json:"color,omitempty"`
	ImageURL   string            `json:"imageUrl,omitempty"`
	ThumbURL   string            `json:"thumbUrl,omitempty"`
	Timestamp  string            `json:"timestamp,omitempty"`
}

type AttachmentField

type AttachmentField struct {
	Title string `json:"title,omitempty"`
	Value string `json:"value,omitempty"`
	Short *bool  `json:"short,omitempty"`
}

type Channel

type Channel struct {
	ID             string `json:"id"`
	Type           string `json:"type"`
	Name           string `json:"name"`
	DisplayName    string `json:"displayName,omitempty"`
	MetadataStatus string `json:"metadataStatus"`
}

type ChannelEnvelope

type ChannelEnvelope struct {
	Schema string         `json:"schema"`
	Data   MachineHistory `json:"data"`
}

func NewChannelEnvelope

func NewChannelEnvelope(value MessageOutput, completeness MachineCompleteness) (ChannelEnvelope, error)

type ChannelItem

type ChannelItem struct {
	ID           string       `json:"id"`
	Type         string       `json:"type"`
	Name         string       `json:"name"`
	DisplayName  *string      `json:"displayName"`
	Team         *ChannelTeam `json:"team"`
	LastPost     *MillisTime  `json:"lastPost"`
	MessageCount int64        `json:"messageCount"`
}

type ChannelTeam

type ChannelTeam struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	DisplayName *string `json:"displayName"`
}

type ChannelsEnvelope

type ChannelsEnvelope struct {
	Schema   string        `json:"schema"`
	Channels []ChannelItem `json:"channels"`
	// contains filtered or unexported fields
}

func NewChannelsEnvelope

func NewChannelsEnvelope(raw []RawChannel, options presentation.Options) (ChannelsEnvelope, error)

type ConfigEnvelope

type ConfigEnvelope struct {
	Schema                 string  `json:"schema"`
	Action                 string  `json:"action"`
	SelectedPath           string  `json:"selectedPath"`
	ReadPath               *string `json:"readPath"`
	Migration              *string `json:"migration"`
	Exists                 *bool   `json:"exists"`
	URLConfigured          *bool   `json:"urlConfigured"`
	TokenConfigured        *bool   `json:"tokenConfigured"`
	StageTTLSeconds        *int64  `json:"stageTtlSeconds"`
	StagePruneAfterSeconds *int64  `json:"stagePruneAfterSeconds"`
	Permissions            *string `json:"permissions"`
	ReadStatus             *string `json:"readStatus"`
	ParseStatus            *string `json:"parseStatus"`
	UnsafeReason           *string `json:"unsafeReason"`
	Created                *bool   `json:"created"`
	Warning                *string `json:"warning"`
}

type DMSEnvelope

type DMSEnvelope struct {
	Schema   string           `json:"schema"`
	Channels []MachineHistory `json:"channels"`
}

func NewDMSEnvelope

func NewDMSEnvelope(values []MessageOutput, completeness MachineCompleteness) (DMSEnvelope, error)

type DateFormatter

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

func NewDateFormatter

func NewDateFormatter(now func() time.Time, location *time.Location) DateFormatter

func (DateFormatter) DateGroupLabel

func (f DateFormatter) DateGroupLabel(date time.Time) string

func (DateFormatter) FormatDate

func (f DateFormatter) FormatDate(date time.Time, includeYear bool) string

func (DateFormatter) FormatDateLong

func (f DateFormatter) FormatDateLong(date time.Time) string

func (DateFormatter) FormatRelativeTime

func (f DateFormatter) FormatRelativeTime(date time.Time) string

func (DateFormatter) FormatTime

func (f DateFormatter) FormatTime(date time.Time) string

type DoctorCheck

type DoctorCheck struct {
	Name    string         `json:"name"`
	Status  string         `json:"status"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
}

type DoctorEnvelope

type DoctorEnvelope struct {
	Schema string        `json:"schema"`
	OK     bool          `json:"ok"`
	Checks []DoctorCheck `json:"checks"`
}

func NewDoctorEnvelope

func NewDoctorEnvelope(ok bool, checks []DoctorCheck) (DoctorEnvelope, error)

type ErrorEnvelope

type ErrorEnvelope struct {
	Schema   string `json:"schema"`
	Code     string `json:"code"`
	Message  string `json:"message"`
	ExitCode int    `json:"exitCode"`
	StageRef string `json:"stageRef,omitempty"`
	Recovery string `json:"recovery"`
}

type File

type File struct {
	ID        string `json:"id"`
	Name      string `json:"name,omitempty"`
	MIME      string `json:"mime,omitempty"`
	Size      *int64 `json:"size,omitempty"`
	Extension string `json:"extension,omitempty"`
}

type FileDownloadEnvelope added in v2.1.0

type FileDownloadEnvelope struct {
	Schema    string `json:"schema"`
	FileID    string `json:"fileId"`
	Name      string `json:"name"`
	MIMEType  string `json:"mimeType"`
	SizeBytes int64  `json:"sizeBytes"`
	SHA256    string `json:"sha256"`
	Path      string `json:"path"`
	Temporary bool   `json:"temporary"`
}

func NewFileDownloadEnvelope added in v2.1.0

func NewFileDownloadEnvelope(fileID, name, mimeType string, sizeBytes int64, sha256, path string, temporary bool) (FileDownloadEnvelope, error)

type GroupDMSEnvelope

type GroupDMSEnvelope struct {
	Schema   string           `json:"schema"`
	Channels []MachineHistory `json:"channels"`
}

func NewGroupDMSEnvelope

func NewGroupDMSEnvelope(values []MessageOutput, completeness MachineCompleteness) (GroupDMSEnvelope, error)

type Identity

type Identity struct {
	ID          string   `json:"id"`
	Username    string   `json:"username"`
	DisplayName *string  `json:"displayName"`
	Nickname    *string  `json:"nickname"`
	Roles       []string `json:"roles"`
}

type JSONLWatchSink

type JSONLWatchSink struct {
	Events, Diagnostics io.Writer
	DisableHeuristics   bool
}

func (JSONLWatchSink) Diagnostic

func (sink JSONLWatchSink) Diagnostic(value mattermost.WatchDiagnostic) error

func (JSONLWatchSink) Post

func (sink JSONLWatchSink) Post(post mattermost.WatchPost, sequence mattermost.Sequence) error

type MachineChannel

type MachineChannel struct {
	ID             string `json:"id"`
	Type           string `json:"type"`
	Name           string `json:"name"`
	DisplayName    string `json:"displayName"`
	MetadataStatus string `json:"metadataStatus"`
}

type MachineCompleteness

type MachineCompleteness string
const (
	MachineComplete  MachineCompleteness = "complete"
	MachineTruncated MachineCompleteness = "truncated"
	MachineUnknown   MachineCompleteness = "unknown"
)

type MachineDocument

type MachineDocument interface {
	// contains filtered or unexported methods
}

type MachineHistory

type MachineHistory struct {
	Channel    MachineChannel   `json:"channel"`
	Messages   []MachineMessage `json:"messages"`
	Redactions []Redaction      `json:"redactions"`
	Metadata   MachineMetadata  `json:"metadata"`
}

func MachineHistoryFromOutput

func MachineHistoryFromOutput(value MessageOutput, completeness MachineCompleteness) (MachineHistory, error)

MachineHistoryFromOutput converts one independently headed output section.

type MachineMessage

type MachineMessage struct {
	ID          string           `json:"id"`
	Permalink   string           `json:"permalink"`
	User        string           `json:"user"`
	UserID      string           `json:"userId"`
	Text        string           `json:"text"`
	Timestamp   MillisTime       `json:"timestamp"`
	UpdatedAt   MillisTime       `json:"updatedAt"`
	EditedAt    *MillisTime      `json:"editedAt"`
	DeletedAt   *MillisTime      `json:"deletedAt"`
	IsDeleted   bool             `json:"isDeleted"`
	PostType    string           `json:"postType"`
	IsSystem    bool             `json:"isSystem"`
	IsPinned    bool             `json:"isPinned"`
	RootID      *string          `json:"rootId"`
	ReplyCount  *int             `json:"replyCount"`
	Files       []string         `json:"files"`
	FileDetails []File           `json:"fileDetails"`
	Attachments []Attachment     `json:"attachments"`
	Reactions   []Reaction       `json:"reactions"`
	Replies     []MachineMessage `json:"replies"`
}

func MachineMessageFromMessage

func MachineMessageFromMessage(message Message) MachineMessage

MachineMessageFromMessage losslessly copies a presentation message into its machine representation. Timestamps retain their instant and are normalized to UTC; collection and pointer fields do not alias the input.

type MachineMetadata

type MachineMetadata struct {
	Completeness         MachineCompleteness `json:"completeness"`
	Selection            Selection           `json:"selection"`
	VisibleThreads       VisibleThreads      `json:"visibleThreads"`
	VisiblePostCount     int                 `json:"visiblePostCount"`
	DeletedPostsIncluded bool                `json:"deletedPostsIncluded"`
}

MachineMetadata preserves the distinction between false/empty and unknown. Pointer fields are always encoded: nil is the machine contract's explicit null.

type MarkdownOptions

type MarkdownOptions struct {
	Relative bool
}

type MentionsEnvelope

type MentionsEnvelope struct {
	Schema  string           `json:"schema"`
	Results []MachineHistory `json:"results"`
}

func NewMentionsEnvelope

func NewMentionsEnvelope(values []MessageOutput, completeness MachineCompleteness) (MentionsEnvelope, error)

type Message

type Message struct {
	ID          string       `json:"id"`
	Permalink   string       `json:"permalink"`
	User        string       `json:"user"`
	UserID      string       `json:"userId"`
	Text        string       `json:"text"`
	Timestamp   time.Time    `json:"timestamp"`
	UpdatedAt   time.Time    `json:"updatedAt"`
	EditedAt    *time.Time   `json:"editedAt,omitempty"`
	DeletedAt   *time.Time   `json:"deletedAt,omitempty"`
	IsDeleted   bool         `json:"isDeleted"`
	PostType    string       `json:"postType"`
	IsSystem    bool         `json:"isSystem"`
	IsPinned    bool         `json:"isPinned"`
	Files       []string     `json:"files"`
	FileDetails []File       `json:"fileDetails"`
	Attachments []Attachment `json:"attachments"`
	Reactions   []Reaction   `json:"reactions"`
	RootID      string       `json:"rootId,omitempty"`
	ReplyCount  *int         `json:"replyCount,omitempty"`
	Replies     []Message    `json:"replies,omitempty"`

	// Canonical identities are unsanitized internal values. They drive
	// ordering and grouping but are never serialized.
	CanonicalID               string `json:"-"`
	CanonicalRootID           string `json:"-"`
	CanonicalThreadShapeKnown *bool  `json:"-"`
}

func GroupIntoThreads

func GroupIntoThreads(messages []Message) []Message

type MessageOutput

type MessageOutput struct {
	Channel    Channel
	Messages   []Message
	Redactions []Redaction
	Retrieval  Retrieval
}

MessageOutput is one independently headed channel section.

type MillisTime

type MillisTime struct{ time.Time }

func (MillisTime) MarshalJSON

func (value MillisTime) MarshalJSON() ([]byte, error)

type PrettyOptions

type PrettyOptions struct {
	Color    bool
	Relative bool
}

type RawChannel

type RawChannel struct {
	ID, Type, Name, DisplayName, DirectUsername, TeamID string
	Team                                                *RawTeam
	LastPostAt, TotalMsgCount                           int64
}

type RawIdentity

type RawIdentity struct {
	ID, Username, DisplayName, Nickname string
	Roles                               []string
}

type RawTeam

type RawTeam struct{ ID, Name, DisplayName, Type string }

type RawUnreadItem

type RawUnreadItem struct {
	Channel      RawChannel
	UnreadCount  int64
	MentionCount int64
	LastViewedAt int64
}

type RawUser

type RawUser struct{ ID, Username, DisplayName, Nickname string }

type Reaction

type Reaction struct {
	Emoji  string          `json:"emoji"`
	Count  int             `json:"count"`
	Actors []ReactionActor `json:"actors"`
}

type ReactionActor

type ReactionActor struct {
	ID       string `json:"id"`
	Username string `json:"username,omitempty"`
}

type Redaction

type Redaction = presentation.Redaction

Redaction is presentation-owned because its Position is a UTF-16 code-unit offset into the final sanitized text. Output models must not recompute it.

type Retrieval

type Retrieval struct {
	Selection            Selection      `json:"selection"`
	VisibleThreads       VisibleThreads `json:"visibleThreads"`
	VisiblePostCount     int            `json:"visiblePostCount"`
	DeletedPostsIncluded bool           `json:"deletedPostsIncluded"`
}

type SearchEnvelope

type SearchEnvelope struct {
	Schema  string           `json:"schema"`
	Results []MachineHistory `json:"results"`
}

func NewSearchEnvelope

func NewSearchEnvelope(values []MessageOutput, completeness MachineCompleteness) (SearchEnvelope, error)

type Selection

type Selection struct {
	Source         string  `json:"source"`
	SelectedCount  int     `json:"selectedCount"`
	RequestedLimit *int    `json:"requestedLimit"`
	Since          *string `json:"since"`
	QueryTruncated *bool   `json:"queryTruncated"`
	InputCursor    *string `json:"inputCursor"`
	NextCursor     *string `json:"nextCursor"`
}

type TeamItem

type TeamItem struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	DisplayName *string `json:"displayName"`
	Type        string  `json:"type"`
}

type TeamsEnvelope

type TeamsEnvelope struct {
	Schema string     `json:"schema"`
	Teams  []TeamItem `json:"teams"`
	// contains filtered or unexported fields
}

func NewTeamsEnvelope

func NewTeamsEnvelope(raw []RawTeam, options presentation.Options) (TeamsEnvelope, error)

type ThreadData

type ThreadData struct {
	Channel      MachineChannel   `json:"channel"`
	Root         *MachineMessage  `json:"root"`
	UnboundPosts []MachineMessage `json:"unboundPosts"`
	Redactions   []Redaction      `json:"redactions"`
	Metadata     MachineMetadata  `json:"metadata"`
}

type ThreadEnvelope

type ThreadEnvelope struct {
	Schema string     `json:"schema"`
	Data   ThreadData `json:"data"`
}

func NewThreadEnvelope

func NewThreadEnvelope(value MessageOutput, completeness MachineCompleteness) (ThreadEnvelope, error)

NewThreadEnvelope preserves a proven root when available and carries rootless partial posts separately. It never promotes unknown shape to root.

type UnreadData

type UnreadData struct {
	Unread []UnreadItem     `json:"unread"`
	Peek   []MachineHistory `json:"peek"`
}

type UnreadEnvelope

type UnreadEnvelope struct {
	Schema string     `json:"schema"`
	Data   UnreadData `json:"data"`
	// contains filtered or unexported fields
}

func NewUnreadEnvelope

func NewUnreadEnvelope(raw []RawUnreadItem, peek []MessageOutput, proof UnreadProof, options presentation.Options) (UnreadEnvelope, error)

type UnreadItem

type UnreadItem struct {
	Channel      ChannelItem `json:"channel"`
	UnreadCount  int64       `json:"unreadCount"`
	MentionCount int64       `json:"mentionCount"`
	LastViewedAt *MillisTime `json:"lastViewedAt"`
}

type UnreadProof

type UnreadProof struct {
	// PeekLimit is nil when peek was not requested. A non-nil value requires
	// one full history per unread summary channel, including confirmed empties.
	PeekLimit *int
}

type UserItem

type UserItem struct {
	ID          string  `json:"id"`
	Username    string  `json:"username"`
	DisplayName *string `json:"displayName"`
	Nickname    *string `json:"nickname"`
}

type UsersEnvelope

type UsersEnvelope struct {
	Schema    string         `json:"schema"`
	Users     []UserItem     `json:"users"`
	Retrieval UsersRetrieval `json:"retrieval"`
	// contains filtered or unexported fields
}

func NewUsersEnvelope

func NewUsersEnvelope(raw []RawUser, proof UsersRetrievalProof, options presentation.Options) (UsersEnvelope, error)

type UsersRetrieval

type UsersRetrieval struct {
	SelectedCount  int64   `json:"selectedCount"`
	RequestedLimit int64   `json:"requestedLimit"`
	Query          *string `json:"query"`
	TeamID         *string `json:"teamId"`
	Truncated      *bool   `json:"truncated"`
}

type UsersRetrievalProof

type UsersRetrievalProof struct {
	RequestedLimit, ProbeCount int64
	Query, TeamID              string
}

type VisibleThreads

type VisibleThreads struct {
	Status            string   `json:"status"`
	HydratedRootCount int      `json:"hydratedRootCount"`
	FailedRootIDs     []string `json:"failedRootIds"`
}

type WatchDocument

type WatchDocument interface {
	// contains filtered or unexported methods
}

func NewWatchDiagnostic

func NewWatchDiagnostic(value mattermost.WatchDiagnostic) (WatchDocument, error)

func NewWatchEvent

func NewWatchEvent(post mattermost.WatchPost, sequence mattermost.Sequence, disableHeuristics bool) (WatchDocument, error)

type WatchSequence

type WatchSequence struct {
	ConnectionID string `json:"connectionId"`
	Number       int64  `json:"number"`
}

type WhoAmIEnvelope

type WhoAmIEnvelope struct {
	Schema string   `json:"schema"`
	Data   Identity `json:"data"`
	// contains filtered or unexported fields
}

func NewWhoAmIEnvelope

func NewWhoAmIEnvelope(raw RawIdentity, options presentation.Options) (WhoAmIEnvelope, error)

Jump to

Keyboard shortcuts

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