Artifact 818a0657629e5c7c1b5acd0ac5a85b11d45b13a0a090bcfe0fea191dbf1240c3:
- File
internal/api/register.go
— part of check-in
[83db19e8c7]
at
2026-08-15 10:52:57
on branch trunk
— phase 1 tracer (minus NATS): index, watcher, timeline op + page
SQLite fold via ncruces driver; ingest.Sync with cursor-loss rebuild; serve --repo; harness wipe is now a real rm -rf + re-ingest. (user: dmestas, size: 2102) [annotate] [blame] [check-ins using]
// Package api owns RegisterAll โ the one explicit wiring point where every // op joins the registry (0003 ยง2: no init() magic; the wiring stays // greppable) โ plus the HTTP router that serves the registered ops. This // is the sanctioned place Run closures over the data planes are built; // the arch gate keeps every other consumer on the op side of the seam. package api import ( "context" "fmt" "craftdesign.group/quarry/internal/index" "craftdesign.group/quarry/internal/ops" ) // Deps carries what op implementations close over. Index may be nil (no // store configured โ `quarry spec` runs this way); ops that need it // answer with an error at run time, and the spec stays complete either // way. type Deps struct { Version string Index *index.Index } type versionIn struct{} type versionOut struct { Version string `json:"version"` } type timelineIn struct { Limit int `json:"limit" validate:"min=0,max=200"` } type timelineOut struct { Entries []index.TimelineEntry `json:"entries"` Count int `json:"count"` } // RegisterAll wires every op. func RegisterAll(r *ops.Registry, d Deps) error { if err := ops.Register(r, ops.Op[versionIn, versionOut]{ Name: "meta.version", Doc: "Report the quarry build version.", Kind: ops.Query, Auth: ops.Anonymous, Route: "GET /api/v1/version", Run: func(_ context.Context, _ versionIn) (versionOut, error) { return versionOut{Version: d.Version}, nil }, }); err != nil { return err } return ops.Register(r, ops.Op[timelineIn, timelineOut]{ Name: "timeline.list", Doc: "List check-ins, newest first.", Kind: ops.Query, Auth: ops.Anonymous, Route: "GET /api/v1/timeline", Run: func(_ context.Context, in timelineIn) (timelineOut, error) { if d.Index == nil { return timelineOut{}, fmt.Errorf("no store is being served") } limit := in.Limit if limit == 0 { limit = 50 } entries, err := d.Index.Timeline(limit) if err != nil { return timelineOut{}, err } return timelineOut{Entries: entries, Count: len(entries)}, nil }, }) }