rules

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rules holds the small rules every thread.Storage backend must answer identically: the List limit, the metadata and title filters, the paging cursor, and the line discipline of a session's bytes. Memory and jsonl call these directly; a backend outside the thread module (sqlite) keeps its own copy, and the threadtest conformance table pins every copy to one answer.

The package imports nothing from thread — thread imports it — so the rules speak in plain values: maps, byte slices, times and ids.

Index

Constants

View Source
const (
	DefaultLimit = 50
	MaxLimit     = 500
)

The List page bounds: a zero or negative Query.Limit reads as DefaultLimit, and anything above MaxLimit clamps to it.

Variables

This section is empty.

Functions

func AfterCursor

func AfterCursor(created time.Time, id string, before time.Time, beforeID string) bool

AfterCursor reports whether a session (created, id) lies strictly after the paging cursor (before, beforeID) in List order — newest first by created, ties by id descending. A zero before is no cursor: everything is after it. With a cursor, a session qualifies when it was created strictly before the cursor's time, or at exactly that time with an id strictly below beforeID; an empty beforeID therefore admits nothing from the cursor's own instant.

func CloneMeta

func CloneMeta(kv map[string]string) map[string]string

CloneMeta copies a metadata map so a header never aliases the caller's; an empty map clones to nil.

func CompareNewestFirst

func CompareNewestFirst(aCreated time.Time, aID string, bCreated time.Time, bID string) int

CompareNewestFirst orders two sessions for List: newest first by created, ties by id descending.

func CompleteLen

func CompleteLen(b []byte) int

CompleteLen returns the length of b's complete prefix: everything up to and including the last newline, 0 when b holds none. Truncating to it is the torn-tail repair.

func InfoTitle

func InfoTitle(line []byte) string

InfoTitle returns the title one entry line sets: non-empty only for an info entry that carries one.

func LimitOf

func LimitOf(n int) int

LimitOf normalizes Query.Limit: zero and negatives mean DefaultLimit, values above MaxLimit clamp.

func MetaMatch

func MetaMatch(meta, want map[string]string) bool

MetaMatch reports whether meta holds every pair of want, exactly: a wanted key must be present and carry the wanted value. An empty want matches everything.

func SplitLines

func SplitLines(b []byte) [][]byte

SplitLines splits on '\n', complete lines only: the bytes after the last newline, if any, are a torn tail and are not returned. The lines alias b.

func TitleMatches

func TitleMatches(title, search string) bool

TitleMatches reports whether the title contains the search as a substring, folding case.

func TitleOf

func TitleOf(lines [][]byte) string

TitleOf returns a session's current title from its entry lines: the last info entry carrying a non-empty title — the rule Session.Title answers with — or "" when none ever did. A line that does not decode is not a title.

func Torn

func Torn(b []byte) bool

Torn reports whether the bytes end mid-line: a writer cut before its newline. Bytes ending in '\n' — and no bytes at all — are complete.

Types

This section is empty.

Jump to

Keyboard shortcuts

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