Documentation
¶
Overview ¶
Package schema models the payload types that normalisers and protocols share. Types are declared in TypeScript, so scripts and the host use one definition.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProgramFiles ¶ added in v0.19.0
ProgramFiles places sources where FromProgram and TypeName expect them.
func PropertyName ¶ added in v0.21.0
PropertyName renders a JSON key as a TypeScript property name, quoting it unless it is an identifier.
Types ¶
type Config ¶ added in v0.12.0
type Config struct {
// SchemaDir holds TypeScript declaration files, each declaring ambient modules.
SchemaDir string `` /* 217-byte string literal not displayed */
}
Config selects the TypeScript declarations that make up the schema.
type Field ¶ added in v0.19.0
type Field struct {
// Name is the JSON key.
Name string
// Optional means the key may be absent. A present key never holds null.
Optional bool
// Value is the member's type.
Value Value
}
Field is one member of an object type.
type Kind ¶ added in v0.19.0
type Kind string
Kind is the JSON shape of a value.
const ( // KindString is a JSON string. KindString Kind = "string" // KindNumber is a JSON number, or one of its literals. KindNumber Kind = "number" // KindBoolean is a JSON boolean. KindBoolean Kind = "boolean" // KindEnum is a union of string literals. KindEnum Kind = "enum" // KindObject is a reference to a named object type. KindObject Kind = "object" // KindList is an array, written T[]. KindList Kind = "list" // KindMap is an object with arbitrary string keys, written Record<string, T>. KindMap Kind = "map" )
Kinds of the TypeScript type expressions in the supported subset.
type Operation ¶ added in v0.19.0
type Operation struct {
// Name is the service's type name followed by the method name.
Name string
// Request names the request object type.
Request TypeRef
// Response names the response object type.
Response TypeRef
}
Operation is one unary RPC method declared on a service interface.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema indexes types and operations whose references all resolve. Treat types and their fields as immutable after construction, as comparison plans share them.
func FromProgram ¶ added in v0.19.0
FromProgram reads the schema sources declare in a checked program built from ProgramFiles(sources). A type's name is its module name and namespace path.
func New ¶
New takes ownership of types and validates their references. It rejects duplicate names and references to undeclared types.
func Parse ¶ added in v0.19.0
Parse type-checks every .ts file in declarations and reads the schema they declare.
func ParseSources ¶ added in v0.19.0
ParseSources type-checks named sources on their own and reads the schema they declare.
func (*Schema) Operations ¶ added in v0.19.0
Operations returns every operation, sorted by name.
type Type ¶ added in v0.19.0
type Type struct {
// Name is the declaring module's name followed by the type's namespace path.
Name TypeRef
// Fields are in declaration order.
Fields []Field
}
Type is a named object type, declared as an interface or an object type alias.
type TypeRef ¶ added in v0.25.0
type TypeRef string
TypeRef names a schema type, e.g. "weather.service.GetWeatherRequest".
type Value ¶ added in v0.19.0
type Value struct {
// Kind is the value's JSON shape.
Kind Kind
// Literals are an enum's permitted strings, or strings a number also accepts, as
// in ProtoJSON's non-finite floats and open enums. Their order is not significant.
Literals []string
// Element is the element type of a list or the value type of a map, and None otherwise.
Element Option[*Value]
// Type names an object's type, or the alias a literal union was declared with, if any.
Type TypeRef
}
Value is one TypeScript type expression in the supported subset.
func (Value) Equal ¶ added in v0.19.0
Equal reports whether two values accept the same JSON. Enum alias names are ignored, but object types must have the same name.