Documentation
¶
Index ¶
- func NaturalDecode(data any, es *entity.EncodedSchema) (*entity.Entity, error)
- func RenderCard(w io.Writer, doc *Document, opts RenderOptions)
- func RenderTable(w io.Writer, docs []*Document, columns []string, opts RenderOptions)
- func TableColumns(docs []*Document, filterKind string, explicit []string) []string
- type AttributeView
- type Document
- type Facet
- type Field
- type Options
- type ParsedFile
- type RenderOptions
- type SchemaValue
- type TextFormatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NaturalDecode ¶
func RenderCard ¶ added in v0.14.0
func RenderCard(w io.Writer, doc *Document, opts RenderOptions)
RenderCard writes the detail view of one entity: a header naming it and its facets, then one group per facet, then anything unclaimed.
func RenderTable ¶ added in v0.14.0
func RenderTable(w io.Writer, docs []*Document, columns []string, opts RenderOptions)
RenderTable writes a listing as one row per entity. It is the scanning view; RenderCard is the reading view.
func TableColumns ¶ added in v0.14.0
TableColumns decides what a listing's columns should be.
Columns cannot come from "the kind", because kinds compose and two entities in the same listing may carry different facets. They are derived from the facet the caller filtered on, which is the one thing every row shares, and only from its scalar single-valued fields: a component or a repeated field has no useful one-cell rendering.
explicit overrides the derivation entirely, for when the interesting field is not one of the first few.
Types ¶
type AttributeView ¶ added in v0.14.0
type AttributeView struct {
Type string `json:"type,omitempty"`
Cardinality string `json:"cardinality,omitempty"`
Unique string `json:"unique,omitempty"`
ElementType string `json:"element_type,omitempty"`
Doc string `json:"doc,omitempty"`
Indexed bool `json:"indexed,omitempty"`
Session bool `json:"session,omitempty"`
}
AttributeView renders the attribute definitions that make up the schema. They carry no kind, and a generic attribute dump buries what they actually say, so they get their own shape.
type Document ¶ added in v0.14.0
type Document struct {
Id string `json:"id"`
ShortId string `json:"short_id,omitempty"`
Revision int64 `json:"revision,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
// Kinds lists every facet the entity carries. Kinds compose: a scheduled
// sandbox holds compute/kind.sandbox, compute/kind.schedule and
// core/kind.metadata at once, and which facets are present is often the
// thing you are debugging.
Kinds []string `json:"kinds,omitempty"`
// Facets holds one entry per kind whose schema resolved, in Kinds order.
Facets []Facet `json:"facets,omitempty"`
// Unclaimed holds attributes that no facet's schema accounts for. Each
// facet only describes its own fields, so without this an attribute outside
// every schema would be invisible.
Unclaimed []Field `json:"unclaimed,omitempty"`
// Attribute is set for the kindless entities that make up the schema
// itself, where the db/* attributes are the content rather than bookkeeping.
Attribute *AttributeView `json:"attribute,omitempty"`
// Problems records facets and values that could not be rendered. A single
// broken facet costs you that facet, not the entity.
Problems []string `json:"problems,omitempty"`
}
Document is the presentation-ready view of a single entity.
The server builds it, the CLI renders it, and `--json` emits it verbatim, so the human and machine views are the same data and cannot drift. Values are natural JSON (strings, numbers, bools, arrays, objects) rather than a tagged union, so a consumer can reach straight for what it wants.
A Document is complete except for byte and string values, which the builder elides when Options.MaxValueLen says to. That only happens when a caller asks for it, so `--json` always carries the whole entity.
func BuildDocument ¶ added in v0.14.0
func BuildDocument(ctx context.Context, sc *entity.SchemaCache, ent *entity.Entity, opts Options) *Document
BuildDocument turns an entity into its presentation-ready form.
It never fails on a single bad facet: a kind whose schema will not resolve is recorded in Problems and its attributes fall through to Unclaimed, so a listing of thousands is not lost to one malformed entity.
type Facet ¶ added in v0.14.0
type Facet struct {
// Kind is the full entity kind id, e.g. dev.miren.compute/kind.sandbox.
Kind string `json:"kind"`
// Label is the short form used for display, e.g. compute/sandbox.
Label string `json:"label"`
Version string `json:"version,omitempty"`
Fields []Field `json:"fields"`
}
Facet is one kind's contribution to an entity.
type Field ¶ added in v0.14.0
type Field struct {
Name string `json:"name"`
// Type is the schema's name for this field ("string", "bytes", "component",
// ...), or empty for an attribute no schema describes. It lets a consumer
// tell a base64 blob from a short string without guessing at the value.
Type string `json:"type,omitempty"`
// Value is the natural representation: a scalar for simple fields, a slice
// for multi-valued ones, a map for components.
Value any `json:"value"`
// Truncated marks a value the builder shortened, and Size carries the real
// length in bytes so the elision is never ambiguous.
Truncated bool `json:"truncated,omitempty"`
Size int `json:"size,omitempty"`
}
Field is one named value within a facet, or one unclaimed attribute.
type Options ¶ added in v0.14.0
type Options struct {
// MaxValueLen elides rendered byte and string values longer than this many
// bytes, backing off to a rune boundary so the result stays valid UTF-8.
// Zero means no limit, which is what the JSON path uses.
MaxValueLen int
}
Options controls how much of an entity a Document carries.
type ParsedFile ¶
type RenderOptions ¶ added in v0.14.0
type RenderOptions struct {
// Expand renders multi-valued and component fields in full instead of
// collapsing them to a count. A sandbox carries its networks, ports,
// routes, volumes and containers as repeated components, so a listing is
// unreadable without this defaulting to off.
Expand bool
// Now is the clock used for relative timestamps. Zero means time.Now.
Now time.Time
}
RenderOptions controls the text presentation. It is pure display policy and lives on the client; the server only decides how much data to send.
type SchemaValue ¶
type SchemaValue struct {
Id string `json:"id,omitempty" yaml:"id,omitempty" cbor:"id,omitempty"`
Kind string `json:"kind" yaml:"kind" cbor:"kind"`
Version string `json:"version" yaml:"version" cbor:"version"`
Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty" cbor:"metadata,omitempty"`
Spec map[string]any `json:"spec" yaml:"spec" cbor:"spec"`
}
type TextFormatter ¶
type TextFormatter struct {
// contains filtered or unexported fields
}
func NewTextFormatter ¶
func NewTextFormatter(sc *entity.SchemaCache) (*TextFormatter, error)
func (*TextFormatter) Parse ¶
func (f *TextFormatter) Parse(ctx context.Context, data []byte) (*ParsedFile, error)