Documentation
¶
Overview ¶
Package api defines Taskronin's HTTP wire types and codecs.
Index ¶
- Constants
- func AggregateETag(body []byte) string
- func FormatETag(gen domain.Generation, v domain.Version) string
- func NewIdempotencyKey() string
- func ParseETag(s string) (domain.Expect, error)
- func ValidIdempotencyKey(k string) bool
- type AIChanges
- type AcceptNewRequest
- type AddEntryRequest
- type AddPlacement
- type AddTaskRequest
- type BackupHealth
- type BackupStatus
- type Banner
- type Block
- type BlockRequest
- type Clock
- type CompleteRequest
- type Conflict
- type Conv
- func (c Conv) Block(v domain.BlockView) Block
- func (c Conv) ETag(v domain.Version) string
- func (c Conv) Entry(v domain.EntryView) Entry
- func (c Conv) Interruption(i domain.Interruption) Interruption
- func (c Conv) LogEntry(e domain.LogEntry, taskTitle string) Entry
- func (c Conv) OptTime(t sql.Null[time.Time]) *Time
- func (c Conv) Task(v domain.TaskView) Task
- func (c Conv) TaskDetail(v domain.TaskDetail) TaskDetail
- func (c Conv) Time(t time.Time) Time
- func (c Conv) Token(t domain.Token) TokenInfo
- type CreateTokenRequest
- type Day
- type DeferRequest
- type DueRequest
- type Effect
- type Entry
- type EventView
- type FieldError
- type FocusRequest
- type Interruption
- type Moment
- type OpDetail
- type OpResponse
- type OpSummary
- type Opt
- type OutcomeRequest
- type Page
- type PasswordRequest
- type PlaceRequest
- type Problem
- type Reason
- type ReblockRequest
- type RelinkRequest
- type ReopenRequest
- type Report
- type ReportDay
- type ReportLine
- type ReportTask
- type ReportTodo
- type ReviewRequest
- type SearchHit
- type Settings
- type SettingsRequest
- type Slips
- type Snapshot
- type Status
- type StatusBlock
- type StatusTask
- type TagCount
- type Task
- type TaskDetail
- type Time
- type Today
- type TokenCreated
- type TokenInfo
- type Upcoming
- type UpdateEntryRequest
- type UpdateTaskRequest
- type WhoAmI
Constants ¶
const ( HeaderIdempotencyKey = "Idempotency-Key" HeaderGeneration = "Taskronin-Generation" HeaderChannel = "X-Taskronin-Channel" HeaderVersion = "X-Taskronin-Version" HeaderRequestID = "X-Request-ID" ContentTypeJSON = "application/json" ContentTypeProblem = "application/problem+json" MaxBodyBytes = 1 << 20 DefaultLimit = 100 MaxLimit = 500 ProblemTypePrefix = "urn:taskronin:problem:" )
Protocol headers, media types, limits, and problem type namespace.
Variables ¶
This section is empty.
Functions ¶
func AggregateETag ¶
AggregateETag returns a quoted ETag using the first 16 hex digits of SHA-256(body).
func FormatETag ¶
func FormatETag(gen domain.Generation, v domain.Version) string
FormatETag returns the quoted strong entity ETag for gen and v.
func NewIdempotencyKey ¶
func NewIdempotencyKey() string
NewIdempotencyKey returns a cryptographically random 32-character lowercase hex key.
func ValidIdempotencyKey ¶
ValidIdempotencyKey reports whether k is 16..128 ASCII letters, digits, '_' or '-'.
Types ¶
type AIChanges ¶
type AIChanges struct {
ReviewedThrough int64 `json:"reviewed_through"`
Unreviewed int `json:"unreviewed"`
Ops []OpSummary `json:"ops"`
NextCursor *string `json:"next_cursor"`
}
AIChanges contains review progress and operations by non-owner tokens.
type AcceptNewRequest ¶
type AcceptNewRequest struct {
Items []struct {
ID int64 `json:"id"`
ETag string `json:"etag"`
} `json:"items"`
}
AcceptNewRequest identifies new tasks to accept with their preconditions.
type AddEntryRequest ¶
type AddEntryRequest struct {
TaskID Opt[int64] `json:"task_id"` // MUST be present: number or null (D§5.2)
Title string `json:"title"`
Notes string `json:"notes,omitempty"`
WorkDate *civil.Date `json:"work_date,omitempty"`
Time *civil.Minute `json:"time,omitempty"`
}
AddEntryRequest supplies a work entry with an explicit task or null.
type AddPlacement ¶
type AddPlacement struct {
How string `json:"how"` // top|bottom|before|after|defer|block|now
Ref int64 `json:"ref,omitempty"` // before/after
Defer *Moment `json:"defer,omitempty"`
Block *BlockRequest `json:"block,omitempty"`
}
AddPlacement specifies the placement of a new task.
type AddTaskRequest ¶
type AddTaskRequest struct {
Title string `json:"title"`
Notes string `json:"notes,omitempty"`
Due *Moment `json:"due,omitempty"`
Tags []string `json:"tags,omitempty"`
Project string `json:"project,omitempty"`
Priority string `json:"priority,omitempty"`
Place *AddPlacement `json:"place,omitempty"`
}
AddTaskRequest supplies a new task and optional placement.
type BackupHealth ¶
type BackupHealth struct {
LastSuccessAt *Time `json:"last_success_at"`
LastError string `json:"last_error"`
Healthy bool `json:"healthy"`
}
BackupHealth summarizes the most recent backup attempt.
type BackupStatus ¶
type BackupStatus struct {
BackupHealth
Dir string `json:"dir"`
Snapshots []Snapshot `json:"snapshots"`
}
BackupStatus contains backup health and available snapshots.
type Banner ¶
type Banner struct{ Kind, Message string } // kinds: backup_failed, backup_stale, ai_changes, purge_incomplete, purge_ledger_damaged, tz_changed
Banner describes a notice displayed by clients.
type Block ¶
type Block struct {
ID int64 `json:"id"`
TaskID int64 `json:"task_id"`
TaskTitle string `json:"task_title"`
TaskETag string `json:"task_etag"` // send as ReblockRequest.task_etag / web `task_etag`
Date civil.Date `json:"date"`
Start civil.Minute `json:"start"`
End civil.EndMinute `json:"end"`
Status string `json:"status"`
OutcomeSource *string `json:"outcome_source"`
CancelReason *string `json:"cancel_reason"`
Slipped bool `json:"slipped"`
SlippedAt *Time `json:"slipped_at"`
Current bool `json:"current"`
Started bool `json:"started"`
Ended bool `json:"ended"`
NeedsReblock bool `json:"needs_reblock"`
CreatedAt Time `json:"created_at"`
ResolvedAt *Time `json:"resolved_at"`
Version int64 `json:"version"`
ETag string `json:"etag"`
}
Block is a scheduled interval with task and outcome metadata.
type BlockRequest ¶
type BlockRequest struct {
Date civil.Date `json:"date"`
Start civil.Minute `json:"start"`
End civil.EndMinute `json:"end"`
}
BlockRequest specifies a scheduled civil interval.
type Clock ¶
type Clock struct {
Now Time `json:"now"`
Today civil.Date `json:"today"`
Timezone string `json:"timezone"`
WeekStart string `json:"week_start"`
DueSoonDays int `json:"due_soon_days"`
ServerVersion string `json:"server_version"`
Generation string `json:"generation"` // db_generation; send as Taskronin-Generation
}
Clock contains the server clock and instance settings.
type CompleteRequest ¶
type CompleteRequest struct {
As *string `json:"as,omitempty"`
Date *civil.Date `json:"date,omitempty"`
Log string `json:"log,omitempty"`
Notes string `json:"notes,omitempty"`
}
CompleteRequest supplies optional completion details.
type Conflict ¶
type Conflict struct {
OpID string `json:"op_id"`
Kind string `json:"kind"`
Actor string `json:"actor"`
At Time `json:"at"`
Entity string `json:"entity"`
EntityID int64 `json:"entity_id"`
}
Conflict identifies an operation and entity that prevent a revert.
type Conv ¶
type Conv struct {
Gen domain.Generation
Loc *time.Location
}
Conv converts domain values using the instance generation and server location. Loc must be supplied by the caller; conversion performs no I/O.
func (Conv) Interruption ¶
func (c Conv) Interruption(i domain.Interruption) Interruption
Interruption converts a focus switch and its optional source IDs.
func (Conv) TaskDetail ¶
func (c Conv) TaskDetail(v domain.TaskDetail) TaskDetail
TaskDetail converts a task and its associated records, including empty arrays.
type CreateTokenRequest ¶
type CreateTokenRequest struct {
Name string `json:"name"`
Scopes string `json:"scopes"`
ExpiresAt Opt[Time] `json:"expires_at"` // key required; null = never (explicit choice, D§10.3)
MutationsPerHour int `json:"mutations_per_hour"`
}
CreateTokenRequest supplies token metadata and an explicit expiry choice.
type Day ¶
type Day struct {
Date civil.Date `json:"date"`
Blocks []Block `json:"blocks"`
Entries []Entry `json:"entries"`
Unlinked []Entry `json:"unlinked"`
Interruptions []Interruption `json:"interruptions"`
}
Day groups scheduled and recorded activity for a civil date.
type DeferRequest ¶
type DeferRequest struct {
Until Opt[Moment] `json:"until"`
} // key required; null clears the defer
DeferRequest sets or clears a task deferral.
type DueRequest ¶
DueRequest sets or clears a task due moment.
type Effect ¶
type Effect struct {
Kind string `json:"kind"`
TaskID int64 `json:"task_id,omitempty"`
BlockID int64 `json:"block_id,omitempty"`
EntryID int64 `json:"entry_id,omitempty"`
Reason string `json:"reason,omitempty"`
Via string `json:"via,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
Effect describes an observable consequence of an operation.
type Entry ¶
type Entry struct {
ID int64 `json:"id"`
TaskID *int64 `json:"task_id"`
TaskTitle *string `json:"task_title"`
Kind string `json:"kind"`
Title string `json:"title"`
Notes string `json:"notes"`
WorkDate civil.Date `json:"work_date"`
Time *civil.Minute `json:"time"`
Reopened bool `json:"reopened"`
CreatedAt Time `json:"created_at"`
UpdatedAt Time `json:"updated_at"`
DeletedAt *Time `json:"deleted_at"`
Version int64 `json:"version"`
ETag string `json:"etag"`
}
Entry is a work or completion entry with optional linked task metadata.
type EventView ¶
type EventView struct {
ID int64 `json:"id"`
Op OpSummary `json:"op"` // Effects omitted
Entity string `json:"entity"`
EntityID int64 `json:"entity_id"`
Action string `json:"action"`
Before json.RawMessage `json:"before"`
After json.RawMessage `json:"after"`
}
EventView contains an entity change and its operation metadata.
type FieldError ¶
FieldError describes a validation failure for a request field.
type FocusRequest ¶
type FocusRequest struct {
TaskID Opt[int64] `json:"task_id"`
Interrupt bool `json:"interrupt,omitempty"`
}
FocusRequest sets or clears focus and optionally records an interruption.
type Interruption ¶
type Interruption struct {
ID int64 `json:"id"`
At Time `json:"at"`
Date civil.Date `json:"date"`
FromTaskID *int64 `json:"from_task_id"`
FromBlockID *int64 `json:"from_block_id"`
ToTaskID int64 `json:"to_task_id"`
}
Interruption records a switch of focus to another task.
type OpResponse ¶
type OpResponse struct {
OpID *string `json:"op_id"`
Replayed bool `json:"replayed"`
Task *Task `json:"task,omitempty"`
Entry *Entry `json:"entry,omitempty"`
Block *Block `json:"block,omitempty"`
Tasks []Task `json:"tasks,omitempty"`
Effects []Effect `json:"effects"`
Warnings []string `json:"warnings"`
}
OpResponse contains an operation result and its current entity representations.
type OpSummary ¶
type OpSummary struct {
Seq int64 `json:"seq"`
OpID string `json:"op_id"`
Kind string `json:"kind"`
Actor string `json:"actor"`
Channel string `json:"channel"`
At Time `json:"at"`
State string `json:"state"`
Revertible bool `json:"revertible"`
Via *string `json:"via"`
TaskIDs []int64 `json:"task_ids"`
Effects []Effect `json:"effects"`
}
OpSummary describes an operation and its effects.
type Opt ¶
Opt distinguishes an absent field, an explicit null, and a value.
func (Opt[T]) MarshalJSON ¶
MarshalJSON emits null for unset or explicitly null fields, otherwise V.
func (*Opt[T]) UnmarshalJSON ¶
UnmarshalJSON marks a present field as either null or a decoded value.
type OutcomeRequest ¶
type OutcomeRequest struct {
Outcome string `json:"outcome"`
} // worked|missed|auto
OutcomeRequest selects a block outcome policy.
type PasswordRequest ¶
PasswordRequest supplies current and replacement passwords.
func (PasswordRequest) LogValue ¶
func (PasswordRequest) LogValue() slog.Value
LogValue redacts all password request fields. AIDEV-NOTE: Use a value receiver so both values and pointers are redacted by slog. Password-bearing requests must never be idempotency-hashed or persisted.
type PlaceRequest ¶
PlaceRequest specifies a task position.
type Problem ¶
type Problem struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail"`
Code string `json:"code"`
RequestID string `json:"request_id"`
Errors []FieldError `json:"errors,omitempty"`
Conflicts []Conflict `json:"conflicts,omitempty"`
Current json.RawMessage `json:"current,omitempty"`
RetryAfter int `json:"retry_after,omitempty"`
}
Problem is the API's RFC 9457 error representation.
type ReblockRequest ¶
type ReblockRequest struct {
BlockRequest
TaskETag string `json:"task_etag"`
}
ReblockRequest reschedules a block with a task precondition.
type RelinkRequest ¶
RelinkRequest links an entry to a task or makes it standalone.
type ReopenRequest ¶
type ReopenRequest struct {
RemoveEntry bool `json:"remove_entry"`
}
ReopenRequest controls whether reopening removes the completion entry.
type Report ¶
type Report struct {
From civil.Date `json:"from"`
To civil.Date `json:"to"`
Tag *string `json:"tag"`
Project *string `json:"project"`
Days []ReportDay `json:"days"` // ascending; days without entries omitted
Tasks map[string]ReportTask `json:"tasks"` // key = task id
Todo *ReportTodo `json:"todo,omitempty"`
Upcoming []Task `json:"upcoming,omitempty"`
}
Report contains work over a date range and optional task lists.
type ReportDay ¶
type ReportDay struct {
Date civil.Date `json:"date"`
Lines []ReportLine `json:"lines"`
}
ReportDay groups report lines by civil date.
type ReportLine ¶
type ReportLine struct {
EntryID int64 `json:"entry_id"`
Kind string `json:"kind"`
Title string `json:"title"`
Notes string `json:"notes"`
TaskID *int64 `json:"task_id"`
Time *civil.Minute `json:"time"`
Reopened bool `json:"reopened"`
}
ReportLine is one work or completion entry in a report.
type ReportTask ¶
type ReportTask struct {
Title string `json:"title"`
Status string `json:"status"`
Deleted bool `json:"deleted"`
}
ReportTask contains task metadata referenced by report lines.
type ReportTodo ¶
ReportTodo contains the current triage and backlog lists.
type ReviewRequest ¶
type ReviewRequest struct {
ThroughSeq int64 `json:"through_seq"`
}
ReviewRequest acknowledges AI changes through an operation sequence.
type SearchHit ¶
type SearchHit struct {
Kind string `json:"kind"` // task|entry
ID int64 `json:"id"`
TaskID *int64 `json:"task_id"`
Title string `json:"title"`
Snippet string `json:"snippet"`
Status string `json:"status,omitempty"`
WorkDate *civil.Date `json:"work_date,omitempty"`
}
SearchHit identifies a matching task or entry.
type Settings ¶
type Settings struct {
BackupKeepDaily int `json:"backup_keep_daily"`
BackupKeepWeekly int `json:"backup_keep_weekly"`
}
Settings contains mutable instance settings.
type SettingsRequest ¶
type SettingsRequest struct {
BackupKeepDaily *int `json:"backup_keep_daily,omitempty"`
BackupKeepWeekly *int `json:"backup_keep_weekly,omitempty"`
Password string `json:"password,omitempty"`
}
SettingsRequest supplies settings changes and optional password verification.
func (SettingsRequest) LogValue ¶
func (SettingsRequest) LogValue() slog.Value
LogValue redacts settings requests, which may carry a password.
type Snapshot ¶
type Snapshot struct {
Name string `json:"name"`
Path string `json:"path"`
Kind string `json:"kind"`
At Time `json:"at"`
Size int64 `json:"size"`
SchemaVersion int `json:"schema_version"`
}
Snapshot describes a backup snapshot.
type Status ¶
type Status struct {
Focus *StatusTask `json:"focus"` // {id, title}
CurrentBlock *StatusBlock `json:"current_block"` // {id, task_id, title, end}
Triage int `json:"triage"`
Due int `json:"due"` // due-phase + overdue open tasks
AI int `json:"ai"`
BackupWarn bool `json:"backup_warning"`
PurgeWarning bool `json:"purge_warning"` // purge_incomplete or purge_ledger_damaged
}
Status contains the compact current status view.
type StatusBlock ¶
type StatusBlock struct {
ID int64 `json:"id"`
TaskID int64 `json:"task_id"`
Title string `json:"title"`
End civil.EndMinute `json:"end"`
}
StatusBlock identifies the current block and its end time.
type StatusTask ¶
StatusTask identifies the focused task.
type TagCount ¶
type TagCount struct {
Name string `json:"name"`
Count int `json:"count"`
} // open, non-deleted tasks
TagCount counts open, non-deleted tasks for a tag.
type Task ¶
type Task struct {
ID int64 `json:"id"`
Title string `json:"title"`
Notes string `json:"notes"`
Status string `json:"status"`
View string `json:"view"`
Reasons []Reason `json:"reasons"`
Defer *Moment `json:"defer"`
Deferred bool `json:"deferred"`
Due *Moment `json:"due"`
DuePhase string `json:"due_phase"`
DueSoon bool `json:"due_soon"`
Project *string `json:"project"`
Tags []string `json:"tags"`
Priority *string `json:"priority"`
Origin string `json:"origin"`
Slips Slips `json:"slips"`
LastPlacedAt *Time `json:"last_placed_at"`
CompletedAt *Time `json:"completed_at"`
CompletedDate *civil.Date `json:"completed_date"`
CreatedAt Time `json:"created_at"`
UpdatedAt Time `json:"updated_at"`
DeletedAt *Time `json:"deleted_at"`
Version int64 `json:"version"`
ETag string `json:"etag"`
}
Task is the wire representation of a task and its derived state.
type TaskDetail ¶
type TaskDetail struct {
Task
Entries []Entry `json:"entries"`
Blocks []Block `json:"blocks"`
Interruptions []Interruption `json:"interruptions"`
}
TaskDetail includes a task and its associated entries, blocks and interruptions.
type Time ¶
Time encodes an instant with millisecond precision in its existing location.
func (Time) MarshalJSON ¶
MarshalJSON retains the instant's zone offset and always emits three fractional digits.
type Today ¶
type Today struct {
Clock Clock `json:"clock"`
Focus *Task `json:"focus"`
CurrentBlock *Block `json:"current_block"`
Blocks []Block `json:"blocks"`
TriageCount int `json:"triage_count"`
TriageTop []Task `json:"triage_top"` // first 5 in triage order
Overdue []Task `json:"overdue"`
DueSoon []Task `json:"due_soon"`
Entries []Entry `json:"entries"`
Interruptions []Interruption `json:"interruptions"`
AIChanges int `json:"ai_changes"`
Backup BackupHealth `json:"backup"`
Banners []Banner `json:"banners"`
}
Today contains the current dashboard view.
type TokenCreated ¶
type TokenCreated struct {
Token TokenInfo `json:"token"`
Secret string `json:"secret"`
} // shown once
TokenCreated returns a newly created token with its one-time secret.
type TokenInfo ¶
type TokenInfo struct {
ID int64 `json:"id"`
Name string `json:"name"`
Scopes string `json:"scopes"`
Owner bool `json:"owner"`
MutationsPerHour int `json:"mutations_per_hour"`
CreatedAt Time `json:"created_at"`
ExpiresAt *Time `json:"expires_at"`
LastUsedAt *Time `json:"last_used_at"`
RevokedAt *Time `json:"revoked_at"`
}
TokenInfo contains token metadata without a secret or secret hash.
type UpdateEntryRequest ¶
type UpdateEntryRequest struct {
Title Opt[string] `json:"title,omitzero"`
Notes Opt[string] `json:"notes,omitzero"`
WorkDate Opt[civil.Date] `json:"work_date,omitzero"`
Time Opt[civil.Minute] `json:"time,omitzero"` // null clears
}
UpdateEntryRequest supplies optional entry changes.
type UpdateTaskRequest ¶
type UpdateTaskRequest struct {
Title Opt[string] `json:"title,omitzero"` // null rejected
Notes Opt[string] `json:"notes,omitzero"` // null rejected
Project Opt[string] `json:"project,omitzero"` // null clears
Priority Opt[string] `json:"priority,omitzero"` // null clears
TagsAdd []string `json:"tags_add,omitempty"`
TagsRemove []string `json:"tags_remove,omitempty"`
}
UpdateTaskRequest supplies optional task changes.