record

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 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 record reads the JSONL record format used by tasks.

Index

Constants

View Source
const DelegationField = "delegation"
View Source
const LineKey = "line"

LineKey is the physical line number the parser stamps onto a record. It is bookkeeping, never part of the schema, so emission always drops it.

Variables

View Source
var DelegationKeyOrder = []string{"kind", "mode", "status", "assignee", "at", "work_ref"}
View Source
var KeyOrder = []string{
	"type", "id", "parent", "state", "priority", "title", "tags", "scheduled", "scheduled_time",
	"deadline", "deadline_time", "recur", "lead", "lead_skip", "delegation",
	"closed", "archived", "body", "updated",
}

KeyOrder is the canonical field order for a serialized record. A key present on a record but absent here is emitted after these, in the record's own source order, so a field a newer writer added survives a write by this one.

Functions

func Absent

func Absent(value json.RawMessage) bool

Absent is Delegation.absent?: nil, the empty string, the empty array and the empty object all mean "this field is not here".

func DecodeStrings

func DecodeStrings(raw json.RawMessage) []string

DecodeStrings reads a stored string array, skipping members that are not strings — which is what Ruby's tag handling does with a foreign writer's list.

func DelegationAgent

func DelegationAgent(value any) bool

func DelegationClaimed

func DelegationClaimed(value any) bool

func DelegationEmail

func DelegationEmail(value any) bool

DelegationEmail is Delegation.email? — an identifier that is also address-SHAPED, so a stray `@work` cannot become a person a task waits on.

func DelegationErrors

func DelegationErrors(value any) []string

DelegationErrors returns Ruby-compatible schema diagnostics for delegation.

func DelegationHuman

func DelegationHuman(value any) bool

func DelegationIdentifier

func DelegationIdentifier(value any) bool

DelegationIdentifier is Delegation.identifier?: real UTF-8, non-empty, bounded, no whitespace in any script, no control or escape characters.

func DelegationObject

func DelegationObject(value any) bool

func DelegationOrderedKeys

func DelegationOrderedKeys(value map[string]any, sourceOrder []string) []string

DelegationOrdered supplies the canonical key order plus unknowns in source order. Go maps cannot retain insertion order, so callers that need emission order should use DelegationOrderedKeys with the source-field order they already possess.

func DelegationReady

func DelegationReady(value any) bool

func DelegationStamp

func DelegationStamp(value time.Time) string

func DelegationTimestamp

func DelegationTimestamp(value any) bool

func DelegationUnknownKeys

func DelegationUnknownKeys(value any) []string

func DelegationValid

func DelegationValid(value any) bool

func DelegationWorkRefErrors

func DelegationWorkRefErrors(value any) []string

DelegationWorkRefErrors is Delegation.work_ref_errors for one reference. The work-ref writer validates BEFORE it builds a marker, so the user reads the reference's own problem rather than a whole-marker shape report.

func Dump

func Dump(records []Record) (string, error)

Dump serializes records to full file text: one record per line with a trailing newline at EOF. An empty list yields the empty string.

func DumpRecord

func DumpRecord(record Record) (string, error)

DumpRecord serializes one record to a single JSON line with no trailing newline. Known keys emit in KeyOrder, then unknown keys in source order. Null, the empty string, the empty array, and the empty object are omitted: they mean an absent field, not a present-but-empty one.

func EncodeJSON

func EncodeJSON(out *bytes.Buffer, raw json.RawMessage) error

EncodeJSON writes one already-parsed JSON value the way Ruby's JSON.generate writes it: no whitespace, object members in source order, and Ruby's escape set and number spellings. It is the seam the store's revision digests need — those digest `JSON.generate(...)` output, so a Go emitter that escaped `<` or reordered a nested object would compute a different token from identical bytes.

func EncodeString

func EncodeString(out *bytes.Buffer, value string)

EncodeString writes a Go string as a JSON string with Ruby's escape set.

func NestedCanonical

func NestedCanonical(key string, raw json.RawMessage) (string, error)

NestedCanonical renders one nested object — a delegation or a `*_time` value — in its canonical key order, exactly as Format.nested_object followed by JSON.generate does in Ruby. The merge needs those bytes as a total order over two delegation markers, which is what makes "exactly one worker holds a claim" survive a multi-device sync.

func RawInt

func RawInt(value int) json.RawMessage

RawInt encodes an integer.

func RawString

func RawString(value string) json.RawMessage

RawString encodes a Go string as a canonical JSON string, with Ruby's escape set rather than Go's — encoding/json is never the writer here.

func RawStrings

func RawStrings(values []string) json.RawMessage

RawStrings encodes a list of strings as a canonical JSON array.

func RubyInspect

func RubyInspect(value any) string

RubyInspect renders a value the way a Ruby diagnostic quotes it, which is what every delegation refusal's wording depends on.

Types

type Field

type Field struct {
	Key   string
	Value json.RawMessage
}

Field is one parsed object member. The parser retains source member order so a later canonical emitter can append forward-compatible keys in the same order Ruby's Hash preserves them.

func Fields

func Fields(raw json.RawMessage) ([]Field, error)

Fields parses a JSON object's members, retaining source order and each member's raw representation.

type GeneratorError

type GeneratorError struct {
	Key   string
	Value string
}

GeneratorError reports a value JSON cannot represent. Ruby's generator raises JSON::GeneratorError for a non-finite float; nothing else in the record format can reach this layer unrepresentable, because every value arrives from a successful parse.

func (*GeneratorError) Error

func (e *GeneratorError) Error() string

type ParseError

type ParseError struct {
	Line    int
	Message string
}

ParseError is a non-fatal defect in an input file. Parsing continues after per-line errors so callers can still inspect the records that were sound.

type Record

type Record struct {
	Fields []Field
	Line   int
}

Record is one parsed JSONL object. Fields retain JSON representations and source order so later validation and canonical emission can make their own type decisions. Line is physical and is never part of the persisted record schema.

func Clone

func Clone(r Record) Record

Clone is `duplicate_records`' per-record half: a detached copy whose fields can be replaced without disturbing the original. Values are json.RawMessage and are only ever replaced, never mutated in place, so copying the slice is a deep copy in practice.

func CloneAll

func CloneAll(records []Record) []Record

CloneAll is `duplicate_records`.

func (*Record) Delete

func (r *Record) Delete(key string)

Delete is `rec.delete(key)`, removing every occurrence.

func (Record) Get

func (r Record) Get(key string) (json.RawMessage, bool)

Get is `rec[key]`: the raw value, or ok=false when the key is absent. The FIRST occurrence wins, matching the parser's own duplicate-key handling.

func (Record) Has

func (r Record) Has(key string) bool

Has reports key presence, including a present-but-null key.

func (*Record) Set

func (r *Record) Set(key string, value json.RawMessage)

Set is `rec[key] = value`: an existing key keeps its position, a new one is appended.

func (*Record) SetDefault

func (r *Record) SetDefault(key string, value json.RawMessage)

SetDefault is Ruby's `rec[key] ||= value`: it writes only when the key is absent or holds nil/false.

func (*Record) SetOptional

func (r *Record) SetOptional(key string, value json.RawMessage)

SetOptional is Store#replace_optional: an absent, null or empty value deletes the key rather than writing a present-but-empty one, because the format reads those as the same thing and writing one would change the bytes for no semantic difference.

func (*Record) SetString

func (r *Record) SetString(key, value string)

SetString is Set for a plain string value.

func (Record) String

func (r Record) String(key string) string

String is `rec[key]` decoded as a String, or "" for absent and non-string values. Every caller here treats a non-string exactly as Ruby's `.to_s` on a nil would: as the empty string.

func (Record) Truthy

func (r Record) Truthy(key string) bool

Truthy is Ruby truthiness for a stored value: anything but absent, null and false.

type Result

type Result struct {
	Records []Record
	Errors  []ParseError
}

Result is the complete, non-failing outcome of parsing a JSONL file.

func Parse

func Parse(input []byte) Result

Parse reads JSONL leniently. A malformed or non-object line becomes an error, while valid records retain their physical one-based line number. Invalid UTF-8 is a whole-file error because Ruby rejects it before it can safely split the file into JSONL lines.

func (Result) OK

func (r Result) OK() bool

OK reports whether the input had no parse errors.

Jump to

Keyboard shortcuts

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