scriptout

package
v1.135.1 Latest Latest
Warning

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

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

Documentation

Overview

Package scriptout is the one serializer for a managed script's outputs: the bytes platform.export and platform.publish_data write, the ceiling they are held to, and the media type and file extension they are stored under.

It is one package because both runs of a script go through it. A platform run persists exactly these bytes and a draft run measures them, so an output too large or malformed to write is refused while the author is still iterating rather than at the first scheduled fire. It was extracted from internal/platform/scriptrun, which composes these arms by the shape of the export request, when the xlsx arm (#1849) arrived.

Index

Constants

View Source
const FormatXLSX = "xlsx"

FormatXLSX is the export format that writes an Excel workbook (#1849). Its body is neither rows nor a string: it is a dict describing the sheets.

View Source
const MaxBytes = 100 << 20

MaxBytes caps one serialized output. It matches the ceiling the portal export path applies, so a script cannot write an asset a human could not have exported by hand.

Variables

View Source
var AppendFormats = []string{formatCSV, formatJSONL}

AppendFormats lists the formats Spool accepts, for the refusal that names them.

Functions

func DataPayload

func DataPayload(name string, data any) ([]byte, error)

DataPayload serializes one publish_data payload as the JSON the data region will hold, checked against the same ceiling every export is.

It is the single serializer for the payload -- a draft measures exactly the bytes a platform run splices -- and it keeps encoding/json's default escaping, which writes <, > and & as \u escapes, so no string in the payload can ever terminate the <script> element it lands inside. Go serializes map keys in sorted order, so the bytes are deterministic for a given payload. The indentation is for the reader of a version diff: a refreshed dashboard's history should read field by field, not as one replaced line.

func SheetsValue

func SheetsValue(shapes []tablexlsx.SheetShape) *starlark.List

SheetsValue renders a workbook's shape as the list an export record hands the script: one {"name": ..., "rows": ...} dict per sheet, in order.

func WorkbookArg

func WorkbookArg(v starlark.Value) (*tablexlsx.Workbook, error)

WorkbookArg reads platform.export's body for the xlsx format, a dict {"sheets": [...]}, into a checked workbook.

A sheet that names no "columns" takes them from its rows' keys, in the order the script wrote them: the Starlark dicts still hold that order, and the Go maps they convert to do not, so it is read here, before conversion.

Types

type Identity

type Identity struct {
	ContentType string
	Extension   string
}

Identity is how one output is stored: the media type it carries and the file extension its object keys take. It is a value rather than the formatter that produced the bytes, because the bytes are already serialized when a serializer here returns -- nothing downstream may re-serialize, and a document has no serializer to hand back.

func Document

func Document(name, format, body string) ([]byte, Identity, error)

Document passes a string body through as the output's bytes, checked against the same ceiling a tabular output is. Verbatim is the contract: what the script composed is what the portal stores or the bucket receives, byte for byte, so a draft's measurement and a real run's write cannot differ.

The format is checked here as well as at the argument edge: this is the serializer both runs share, and a request some other constructor built with a body under csv or json must be refused rather than written verbatim as a "well-formed by construction" feed.

func Rows

func Rows(name, format string, columns []string, rows []any) ([]byte, Identity, error)

Rows serializes row dicts in a tabular format, projected onto columns, and checks the result against the ceiling.

func Workbook

func Workbook(name string, book *tablexlsx.Workbook) ([]byte, Identity, error)

Workbook writes an xlsx workbook, checked against the ceiling (#1849).

type Spool added in v1.135.1

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

Spool is one output a run appends to across platform.export calls (#1861): each page is serialized as it arrives and only the bytes are kept, so a script can page an API or a warehouse into one file, and one table, without holding every page as Starlark values -- which cost roughly seventy times their serialized size. The output is written once, when the run finishes.

func NewSpool added in v1.135.1

func NewSpool(name, format string) (*Spool, error)

NewSpool starts an appended output in format, refusing a format whose pages cannot be joined as bytes.

func (*Spool) Append added in v1.135.1

func (s *Spool) Append(columns []string, rows []any) error

Append serializes one page of rows, projected onto columns, onto the output.

func (*Spool) Bytes added in v1.135.1

func (s *Spool) Bytes() int

Bytes is the output's size so far.

func (*Spool) Data added in v1.135.1

func (s *Spool) Data() ([]byte, Identity, error)

Data is the whole output and the identity it is stored under. A spool that was appended nothing is an empty file in its format.

func (*Spool) Rows added in v1.135.1

func (s *Spool) Rows() int

Rows is how many rows the output holds so far.

Directories

Path Synopsis
Package exportmeta reads platform.export's tags= and metadata= arguments (#1848): what identifies a portal output beyond its name, so an application finds the reports it generated again.
Package exportmeta reads platform.export's tags= and metadata= arguments (#1848): what identifies a portal output beyond its name, so an application finds the reports it generated again.
Package exportrecord is what one platform.export call did, as a managed script's run records it and as the script is handed it back: the output's name, format, size and where it landed, and, for an output appended to across calls (#1861), how much it holds so far.
Package exportrecord is what one platform.export call did, as a managed script's run records it and as the script is handed it back: the output's name, format, size and where it landed, and, for an output appended to across calls (#1861), how much it holds so far.

Jump to

Keyboard shortcuts

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