report

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package report renders tabular results to HTML or PDF through facet.

facet is a TSX/React to Chromium print pipeline with no Go SDK, so a caller either POSTs to a `facet serve` instance or execs the CLI. The HTTP API is preferred whenever a facet URL or connection is configured: the server keeps a warm Chromium worker pool, which is the difference between a ~1.4s render and a ~11s one, and keeps ~1GB of Chromium out of this process.

Index

Constants

View Source
const (
	// PropertyURL names the facet server used when a report does not name one.
	PropertyURL = "facet.url"
	// PropertyConnection names the facet connection used when neither the
	// report nor facet.url names a server.
	PropertyConnection = "facet.connection"
)
View Source
const EntryFile = "QueryReport.tsx"

EntryFile is the TSX component the embedded template renders with.

Variables

View Source
var ErrRendererUnavailable = errors.New("facet renderer unavailable")

ErrRendererUnavailable is returned when no facet server is configured and the facet binary is not installed. It is a distinct error so a deployment missing its renderer fails with an install hint rather than opaquely on every run.

View Source
var SourceDir = os.Getenv("QUERY_REPORT_SOURCE_DIR")

SourceDir overrides the extracted template with a directory on disk, for developing the TSX without rebuilding the binary.

Functions

func BuildArchive

func BuildArchive(srcDir string) ([]byte, error)

BuildArchive tars and gzips a template directory for the facet server.

func Render

func Render(
	ctx context.Context,
	server Server,
	data any,
	format, srcDir, entryFile string,
) ([]byte, error)

Render sends the render to the configured server, falling back to the local binary only when none is configured.

func RenderCLI

func RenderCLI(
	ctx context.Context,
	data any,
	format, srcDir, entryFile string,
	timeout time.Duration,
) ([]byte, error)

RenderCLI renders through the local facet binary. It is the fallback for when no server is configured; prefer RenderHTTP, which does not pay the cold-start cost on every run.

func RenderHTTP

func RenderHTTP(
	ctx context.Context,
	server Server,
	data any,
	format, srcDir, entryFile string,
	options RenderOptions,
) ([]byte, error)

RenderHTTP renders data through a facet server. srcDir is the template directory; it is archived and sent with the request, so the server needs no prior knowledge of the template.

func TemplateDir

func TemplateDir() (string, error)

TemplateDir returns a directory holding the report template, extracting the embedded copy on first use.

The location is content-addressed by the template's own hash, so the pnpm install and Vite build cached under .facet/ survive across renders and across restarts — a cold render costs roughly ten times a warm one — while a change to the template lands in a different directory and is never served stale.

Types

type Column

type Column struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Unit string `json:"unit,omitempty"`
}

Column is one facet DynamicTable column. Type drives the cell renderer, and must be one of facet's own names.

type Options

type Options struct {
	Connection   string
	URL          string
	Timeout      time.Duration
	TimestampURL string
}

Options select the facet server for one render.

type Payload

type Payload struct {
	// Name is what facet writes the file as when the output path is a
	// directory, so it doubles as the report's slug.
	Name        string      `json:"name"`
	Title       string      `json:"title"`
	Subtitle    string      `json:"subtitle,omitempty"`
	GeneratedAt string      `json:"generatedAt"`
	RowCount    int         `json:"rowCount"`
	Truncated   bool        `json:"truncated,omitempty"`
	Columns     []Column    `json:"columns"`
	Rows        []query.Row `json:"rows"`
}

Payload is what the TSX template is called with. It mirrors ReportData in QueryReport.tsx.

func NewPayload

func NewPayload(title string, result *query.Result, columns []query.ColumnDef) Payload

NewPayload projects a result and its columns onto the template's props.

type RenderOptions

type RenderOptions struct {
	TimestampURL string
	Timeout      time.Duration
}

RenderOptions carry the per-render knobs the archive does not.

type Server

type Server struct {
	BaseURL      string
	Token        string
	TimestampURL string

	// Timeout bounds the render. Zero leaves it bounded by the facet server.
	Timeout time.Duration
}

Server is a facet render service. The zero value means none is configured and rendering falls back to the local binary.

func ResolveServer

func ResolveServer(ctx dbcontext.Context, options Options) (Server, error)

ResolveServer picks the facet render service, preferring what the report asks for and falling back to the facet.url and facet.connection properties. A zero Server means none is configured and the local binary is used.

func (Server) Configured

func (s Server) Configured() bool

Jump to

Keyboard shortcuts

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