typegen

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package typegen turns a realm's loaded config into TypeScript types: documents, queries, functions, configuration, templates and roles. Everything comes from the same registry the server enforces; nothing is enforced at runtime from the generated files.

Index

Constants

View Source
const (
	TypesFile = "types.d.ts"
	InfoFile  = "realm.json"
)

File names written by `backd types`.

View Source
const Version = "1"

Version is the generator's version: it changes when the output format does.

Variables

This section is empty.

Functions

func Diff

func Diff(old, now Info) []string

Diff lists the type-level differences between two generations, one line each, for pull request reviews: `+` something was added, `-` removed, `~` its type changed. Empty when the types are the same.

Types

type FunctionsOutput

type FunctionsOutput struct {
	Types    string
	Warnings []string
}

FunctionsOutput is a functions project's backd.d.ts.

func GenerateFunctions

func GenerateFunctions(reg *registry.Registry, realm, database, config string) (*FunctionsOutput, error)

GenerateFunctions produces the backd.d.ts of one database's functions project: the realm's types plus defineFunction and a context typed per function.

type Info

type Info struct {
	Generator string `json:"generator"`
	Realm     string `json:"realm"`
	// Fingerprint identifies the generated types (a hash of types.d.ts without its header):
	// what the JavaScript client sends to know whether its types are stale.
	Fingerprint string `json:"fingerprint"`
	// Config is the config directory's fingerprint, when a caller asks to record it; `backd types`
	// leaves it out, so unrelated changes to the config don't touch the committed realm.json.
	Config  string            `json:"config,omitempty"`
	Entries map[string]string `json:"entries"`
}

Info is realm.json: what the generated types were made from, and the type-level entries `--diff` compares.

type Options

type Options struct {
	Realm    string
	Database string // empty: every database of the realm
	// Config is registry.Fingerprint of the loaded config; recorded in realm.json.
	Config string
}

Options select what to generate.

type Output

type Output struct {
	Types    string   // contents of types.d.ts
	Info     Info     // contents of realm.json
	Warnings []string // things the generator couldn't express, with where
}

Output is what the generator produces for one realm.

func Generate

func Generate(reg *registry.Registry, o Options) (*Output, error)

Generate produces the types of one realm.

Jump to

Keyboard shortcuts

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