schema

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 10 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 schema infers a Sanity dataset's shape from sample documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CachePath

func CachePath(projectID, dataset string) (string, error)

CachePath returns the on-disk cache path for a given project+dataset pair.

func Save

func Save(doc *Doc) (string, error)

Save writes the schema doc to its on-disk cache, creating directories.

Types

type BlockSummary

type BlockSummary struct {
	Styles []string `json:"styles,omitempty"`
	Marks  []string `json:"marks,omitempty"`
}

BlockSummary aggregates the unique styles and marks observed in portable text.

type Doc

type Doc struct {
	ProjectID      string               `json:"project_id"`
	Dataset        string               `json:"dataset"`
	APIVersion     string               `json:"api_version"`
	Perspective    string               `json:"perspective"`
	IntrospectedAt string               `json:"introspected_at"`
	SampleSize     int                  `json:"sample_size"`
	MaxDepth       int                  `json:"max_depth"`
	Types          map[string]*TypeInfo `json:"types"`
}

Doc is the top-level introspected schema document.

func Introspect

func Introspect(ctx context.Context, client api.Client, inst *config.Instance, opts Options) (*Doc, error)

Introspect builds a schema document by querying the live dataset.

func Load

func Load(projectID, dataset string) (*Doc, string, error)

Load reads a previously cached schema doc.

type Field

type Field struct {
	Type       string            `json:"type"` // string|number|boolean|null|datetime|array|object|reference|asset|union
	Optional   bool              `json:"optional,omitempty"`
	Nullable   bool              `json:"nullable,omitempty"`
	Tag        string            `json:"tag,omitempty"`        // portableText|slug|geopoint|...
	AssetKind  string            `json:"asset_kind,omitempty"` // image|file
	To         []string          `json:"to,omitempty"`         // reference targets (best-effort)
	Unresolved bool              `json:"unresolved,omitempty"` // reference target unresolved
	Truncated  bool              `json:"truncated,omitempty"`  // hit max_depth
	Fields     map[string]*Field `json:"fields,omitempty"`     // for objects
	Of         []*Field          `json:"of,omitempty"`         // array element shapes (union)
	Blocks     *BlockSummary     `json:"blocks,omitempty"`     // for portable text
	Union      []string          `json:"union,omitempty"`      // observed type names when mixed
	// contains filtered or unexported fields
}

Field describes the inferred shape of a single field path.

type Options

type Options struct {
	SampleSize int
	MaxDepth   int
	// ResolveReferences, if true, runs a follow-up GROQ batch to resolve the
	// _type of every reference observed in samples.
	ResolveReferences bool
}

Options configures schema introspection.

type TypeInfo

type TypeInfo struct {
	Count      int               `json:"count,omitempty"`
	SampleSize int               `json:"sample_size"`
	Empty      bool              `json:"empty,omitempty"`
	Fields     map[string]*Field `json:"fields,omitempty"`
}

TypeInfo summarizes a single Sanity document type.

Jump to

Keyboard shortcuts

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