lex

package
v0.0.0-...-eab5204 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package lex generates Go code for lexicons.

(It is not a lexer.)

Index

Constants

View Source
const (
	EncodingCBOR  = "application/cbor"
	EncodingJSON  = "application/json"
	EncodingJSONL = "application/jsonl"
	EncodingCAR   = "application/vnd.ipld.car"
	EncodingMP4   = "video/mp4"
	EncodingANY   = "*/*"
)

Variables

This section is empty.

Functions

func BuildExtDefMap

func BuildExtDefMap(ss []*Schema, packages []Package) map[string]*ExtDef

Build total map of all types defined inside schemas. Return map from fully qualified type name to its *TypeSchema

func CreateHandlerStub

func CreateHandlerStub(pkg string, impmap map[string]string, dir string, schemas []*Schema, handlers bool) error

func FixRecordReferences

func FixRecordReferences(schemas []*Schema, defmap map[string]*ExtDef, prefix string)

TODO: this method is necessary because in lexicon there is no way to know if a type needs to be marshaled with a "$type" field up front, you can only know for sure by seeing where the type is used.

func GenCodeForSchema

func GenCodeForSchema(pkg Package, reqcode bool, s *Schema, packages []Package, defmap map[string]*ExtDef) error

func Run

func Run(schemas []*Schema, packages []Package) error

func WriteServerHandlers

func WriteServerHandlers(w io.Writer, schemas []*Schema, pkg string, impmap map[string]string) error

func WriteXrpcServer

func WriteXrpcServer(w io.Writer, schemas []*Schema, pkg string, impmap map[string]string) error

Types

type ExtDef

type ExtDef struct {
	Type *TypeSchema
}

type InputType

type InputType struct {
	Encoding string      `json:"encoding"`
	Schema   *TypeSchema `json:"schema"`
}

type OutputType

type OutputType struct {
	Encoding string      `json:"encoding"`
	Schema   *TypeSchema `json:"schema"`
}

type Package

type Package struct {
	GoPackage string `json:"package"`
	Prefix    string `json:"prefix"`
	Outdir    string `json:"outdir"`
	Import    string `json:"import"`
}

func ParsePackages

func ParsePackages(jsonBytes []byte) ([]Package, error)

ParsePackages reads a json blob which should be an array of Package{} objects.

type Schema

type Schema struct {

	// Lexicon version, e.g. 1
	Lexicon int                    `json:"lexicon"`
	ID      string                 `json:"id"`
	Defs    map[string]*TypeSchema `json:"defs"`
	// contains filtered or unexported fields
}

Schema is a lexicon json file e.g. atproto/lexicons/app/bsky/feed/post.json https://atproto.com/specs/lexicon

func ReadSchema

func ReadSchema(f string) (*Schema, error)

func (*Schema) AllTypes

func (s *Schema) AllTypes(prefix string, defMap map[string]*ExtDef) []outputType

func (*Schema) Name

func (s *Schema) Name() string

type TypeSchema

type TypeSchema struct {
	Type        string      `json:"type"`
	Key         string      `json:"key"`
	Description string      `json:"description"`
	Parameters  *TypeSchema `json:"parameters"`
	Input       *InputType  `json:"input"`
	Output      *OutputType `json:"output"`
	Record      *TypeSchema `json:"record"`

	Ref        string                 `json:"ref"`
	Refs       []string               `json:"refs"`
	Required   []string               `json:"required"`
	Nullable   []string               `json:"nullable"`
	Properties map[string]*TypeSchema `json:"properties"`
	MaxLength  int                    `json:"maxLength"`
	Items      *TypeSchema            `json:"items"`
	Const      any                    `json:"const"`
	Enum       []string               `json:"enum"`
	Closed     bool                   `json:"closed"`

	Default any `json:"default"`
	Minimum any `json:"minimum"`
	Maximum any `json:"maximum"`
	// contains filtered or unexported fields
}

TypeSchema is the content of a lexicon schema file "defs" section. https://atproto.com/specs/lexicon

func (*TypeSchema) TypeName

func (s *TypeSchema) TypeName() string

func (*TypeSchema) WriteHandlerStub

func (s *TypeSchema) WriteHandlerStub(w io.Writer, fname, shortname, impname string) error

func (*TypeSchema) WriteRPC

func (s *TypeSchema) WriteRPC(w io.Writer, typename, inputname string) error

func (*TypeSchema) WriteRPCHandler

func (s *TypeSchema) WriteRPCHandler(w io.Writer, fname, shortname, impname string) error

func (*TypeSchema) WriteType

func (ts *TypeSchema) WriteType(name string, w io.Writer) error

name is the top level type name from outputType WriteType is only called on a top level TypeSchema

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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