model

package
v0.0.0-...-e4cf005 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package model provides a general model for software projects. It includes types for content like issues and comments (Post), as well as types for other aspects of a project, like users and bots (Identity.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content interface {
	ID() string     // universally unique ID, typically a URL
	Title_() string // empty if missing or not supported
	Body_() string  // text content; some day, a sequence of multimedia elements

	// These are zero if unknown.
	CreatedAt_() time.Time
	UpdatedAt_() time.Time
}

A Content is a piece of meaningful information. It may be a name, an email address, or an entire document. TODO: remove trailing underscores after renaming conflicting fields elsewhere.

type DBContent

type DBContent struct {
	DBTime  timed.DBTime
	Content Content
}

DBContent is a Content in a [storage.DB].

type Identity

type Identity struct {
	Realm Realm
	ID    string // unique for the realm
	Name  string // non-canonical display name, if known (e.g. "Pat Brown", "The Go Team")
}

An Identity is an entity that can interact with a project. It contains a unique identifier for a person, team or bot.

type Post

type Post interface {
	Content

	Project() string   // ID of project this belongs to
	Author() *Identity // nil if unknown or not supported
	CanEdit() bool     // can the content or metadata of this post be modified?

	CanHaveChildren() bool // can this kind of Post have children?
	ParentID() string      // the parent post's ID, empty if this is a root post

	Updates() PostUpdates // set changes on a PostUpdates, then pass to [Source.Update]
}

A Post is a piece of content that can be easily made public ("posted"). Examples are email messages, blog posts, and issue comments.

A Post may have children.

type PostUpdates

type PostUpdates interface {
	SetTitle(string) error // set the title
	SetBody(string) error  // set the body
}

PostUpdates holds updates to a Post.

type Realm

type Realm string

A Realm is a namespace for identity unique IDs.

const (
	// GitHub user/org names.
	GitHub Realm = "GitHub"
	// Gerrit user names.
	Gerrit Realm = "Gerrit"
	// Email addresses.
	Email Realm = "email"
)

type Source

type Source[T Content] interface {
	// A unique name for the source. For example, "GitHubIssues".
	Name() string

	// Download the current value for the ID from the external source.
	Read(ctx context.Context, id string) (T, error)

	// Update c by applying the given Updates.
	// Updates should describe how to modify c in a form that the Source
	// understands. For a [Post], call [Post.Update] to obtain such a value.
	Update(ctx context.Context, c T, u Updates) error

	// Create a new instance of T in the source, returning its unique ID.
	Create(context.Context, T) (id string, err error)

	// Delete the item with the given ID.
	// No error is returned if the ID is not found.
	// An error is returned if deletion is not unsupported or the item cannot be deleted.
	Delete(_ context.Context, id string) error
}

A Source allows direct access to an external system, or a part of a system.

type Updates

type Updates interface {
}

Updates contains changes to a value. It is used in conjunction with [Source.Update].

type Watcher

type Watcher[T any] interface {
	Recent() iter.Seq[T]
	Restart()
	MarkOld(timed.DBTime)
	Flush()
	Latest() timed.DBTime
}

A Watcher is a persistent, named cursor into a database. See timed.Watcher for an implementation (currently the only one) and for method documentation.

Jump to

Keyboard shortcuts

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