events

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events appends and filters the project event stream under .devsys/events/<YYYY-MM>.jsonl (方案 §4.6, 实施计划 M1.3). One event is one JSONL line; the shard follows the event time in UTC, and comment events carry a one-level reply_to.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInitialized   = storage.ErrNotInitialized
	ErrIncompleteTail   = storage.ErrIncompleteTail
	ErrReplyNotFound    = errors.New("reply_to does not reference a comment of the same subject")
	ErrReplyNotOneLevel = errors.New("reply_to must reference a top-level comment")
	ErrBadTime          = errors.New("event time must be a valid UTC time")
)

Errors reported to callers.

Functions

func AppendBatchTx

func AppendBatchTx(tx *storage.Tx, evs []*domain.Event) error

AppendBatchTx stages several events into one transaction. The transaction contract stages each JSONL file once, so events sharing a month shard are concatenated into a single append; events of different shards keep their own append. This keeps a completion (status change plus propagation events) atomic.

func AppendTx

func AppendTx(tx *storage.Tx, ev *domain.Event) error

AppendTx stages one event into an existing storage transaction. supplies its own tx (already holding the project lock). ev.ID is assigned from ev.Time if empty; ev.Time is set to UTC now if zero. ev.SchemaVersion is set to domain.SchemaVersion if zero. Use this instead of reaching into tx.AppendJSONL directly: it centralises shard-path derivation and ID generation so callers don't reinvent the rules.

func ShardRel

func ShardRel(t time.Time) string

ShardRel maps a UTC time to its managed file, relative to .devsys.

Types

type CommentThread

type CommentThread struct {
	Comment *domain.Event
	Replies []*domain.Event
}

CommentThread is one top-level comment with its one-level replies, ordered by time.

type Filter

type Filter struct {
	// From and FromExclusive bound Time: inclusive and exclusive lower edge.
	From          time.Time
	FromExclusive time.Time
	// To bounds Time inclusively.
	To time.Time
	// Subject keeps events whose subject matches both fields.
	Subject *domain.Reference
	// Type keeps only events of this type.
	Type string
}

Filter describes which events a reader wants. Zero fields match anything.

type Store

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

Store binds event operations to a project root.

func New

func New(root string) *Store

New binds the event stream to a project root (the directory containing .devsys, which must exist).

func (*Store) Append

func (s *Store) Append(ctx context.Context, ev *domain.Event) error

Append validates and writes one event. The shard follows the event's own time, so a December event written on January 1st still lands in the December file. The write is a JSONL append inside a storage transaction, so interrupted runs are recovered before the append is retried.

func (*Store) Comments

func (s *Store) Comments(ctx context.Context, subject domain.Reference) ([]*CommentThread, error)

Comments aggregates the comment events of a subject into threads. A reply must reference a comment of the same subject; deeper nesting (a reply to a reply) is rejected, so the thread tree is always two levels deep.

func (*Store) Read

func (s *Store) Read(ctx context.Context, f Filter) ([]*domain.Event, error)

Read returns the events of the stream in time order, filtered by f. Live shards and archived shards (M8.3) are both covered: an archived shard holds the segment as of archival, later events land on the live shard of the same month, so both are read and merged by event time.

Jump to

Keyboard shortcuts

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