shape

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 21 Imported by: 0

README

x/shape

Package provides representation of types.

It's use in mkunion for example to extract union types and generate TypeScript schema for them. Such schema generation is useful in building application that have end-to-end type safety.

Documentation

Overview

Code generated by mkunion. DO NOT EDIT.

Code generated by mkunion. DO NOT EDIT.

Code generated by mkunion. DO NOT EDIT.

Code generated by mkunion. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShapeNotFound = fmt.Errorf(`To register shape manually, use shape.Register(myShape) in your package init() function or, use shape.LookupShapeOnDisk(x) to scan your filesystem for shapes.`)
)
View Source
var TypeStringToNumberKindMap = map[string]NumberKind{
	"uint8":   &UInt8{},
	"uint16":  &UInt16{},
	"uint32":  &UInt32{},
	"uint64":  &UInt64{},
	"int8":    &Int8{},
	"int16":   &Int16{},
	"int32":   &Int32{},
	"int64":   &Int64{},
	"float32": &Float32{},
	"float64": &Float64{},
	"byte":    &UInt8{},
	"rune":    &Int32{},
}

Functions

func AliasLikeToJSON added in v1.20.2

func AliasLikeToJSON(x *AliasLike) ([]byte, error)

func AndGuardToJSON added in v1.20.0

func AndGuardToJSON(x *AndGuard) ([]byte, error)

func AnyToJSON added in v1.20.0

func AnyToJSON(x *Any) ([]byte, error)

func BooleanLikeToJSON added in v1.20.0

func BooleanLikeToJSON(x *BooleanLike) ([]byte, error)

func EnumToJSON added in v1.20.0

func EnumToJSON(x *Enum) ([]byte, error)

func ExtractDocumentTags added in v1.21.0

func ExtractDocumentTags(doc *ast.CommentGroup) map[string]Tag

func ExtractPkgImportNames added in v1.21.0

func ExtractPkgImportNames(x Shape) map[string]string

func ExtractTags added in v1.20.0

func ExtractTags(tag string) map[string]Tag

func Float32ToJSON added in v1.20.1

func Float32ToJSON(x *Float32) ([]byte, error)

func Float64ToJSON added in v1.20.1

func Float64ToJSON(x *Float64) ([]byte, error)

func GuardToJSON added in v1.20.0

func GuardToJSON(x Guard) ([]byte, error)

func GuessPkgName added in v1.21.0

func GuessPkgName(x reflect.Type) string

func GuessPkgNameFromPkgImportName added in v1.21.0

func GuessPkgNameFromPkgImportName(x string) string

func InjectPkgImportName added in v1.20.2

func InjectPkgImportName(pkgNameToImportName map[string]string) func(x Shape)

func InjectPkgName

func InjectPkgName(pkgName string) func(x Shape)

func Int16ToJSON added in v1.20.1

func Int16ToJSON(x *Int16) ([]byte, error)

func Int32ToJSON added in v1.20.1

func Int32ToJSON(x *Int32) ([]byte, error)

func Int64ToJSON added in v1.20.1

func Int64ToJSON(x *Int64) ([]byte, error)

func Int8ToJSON added in v1.20.1

func Int8ToJSON(x *Int8) ([]byte, error)

func IsAlias added in v1.20.2

func IsAlias(t *ast.TypeSpec) bool

func IsBinary added in v1.21.0

func IsBinary(x Shape) bool

func IsPointer added in v1.21.0

func IsPointer(x Shape) bool

func IsStarExpr added in v1.20.0

func IsStarExpr(x ast.Expr) bool

func IsString added in v1.21.0

func IsString(x Shape) bool

func ListLikeToJSON added in v1.20.0

func ListLikeToJSON(x *ListLike) ([]byte, error)

func MapLikeToJSON added in v1.20.0

func MapLikeToJSON(x *MapLike) ([]byte, error)

func MatchGuard

func MatchGuard[TOut any](
	x Guard,
	f1 func(x *Enum) TOut,
	f2 func(x *Required) TOut,
	f3 func(x *AndGuard) TOut,
	df func(x Guard) TOut,
) TOut

func MatchGuardR2

func MatchGuardR2[TOut1, TOut2 any](
	x Guard,
	f1 func(x *Enum) (TOut1, TOut2),
	f2 func(x *Required) (TOut1, TOut2),
	f3 func(x *AndGuard) (TOut1, TOut2),
	df func(x Guard) (TOut1, TOut2),
) (TOut1, TOut2)

func MatchNumberKind added in v1.20.1

func MatchNumberKind[TOut any](
	x NumberKind,
	f1 func(x *UInt8) TOut,
	f2 func(x *UInt16) TOut,
	f3 func(x *UInt32) TOut,
	f4 func(x *UInt64) TOut,
	f5 func(x *Int8) TOut,
	f6 func(x *Int16) TOut,
	f7 func(x *Int32) TOut,
	f8 func(x *Int64) TOut,
	f9 func(x *Float32) TOut,
	f10 func(x *Float64) TOut,
	df func(x NumberKind) TOut,
) TOut

func MatchNumberKindR2 added in v1.20.1

func MatchNumberKindR2[TOut1, TOut2 any](
	x NumberKind,
	f1 func(x *UInt8) (TOut1, TOut2),
	f2 func(x *UInt16) (TOut1, TOut2),
	f3 func(x *UInt32) (TOut1, TOut2),
	f4 func(x *UInt64) (TOut1, TOut2),
	f5 func(x *Int8) (TOut1, TOut2),
	f6 func(x *Int16) (TOut1, TOut2),
	f7 func(x *Int32) (TOut1, TOut2),
	f8 func(x *Int64) (TOut1, TOut2),
	f9 func(x *Float32) (TOut1, TOut2),
	f10 func(x *Float64) (TOut1, TOut2),
	df func(x NumberKind) (TOut1, TOut2),
) (TOut1, TOut2)

func MatchShape

func MatchShape[TOut any](
	x Shape,
	f1 func(x *Any) TOut,
	f2 func(x *RefName) TOut,
	f3 func(x *AliasLike) TOut,
	f4 func(x *BooleanLike) TOut,
	f5 func(x *StringLike) TOut,
	f6 func(x *NumberLike) TOut,
	f7 func(x *ListLike) TOut,
	f8 func(x *MapLike) TOut,
	f9 func(x *StructLike) TOut,
	f10 func(x *UnionLike) TOut,
	df func(x Shape) TOut,
) TOut

func MatchShapeR2

func MatchShapeR2[TOut1, TOut2 any](
	x Shape,
	f1 func(x *Any) (TOut1, TOut2),
	f2 func(x *RefName) (TOut1, TOut2),
	f3 func(x *AliasLike) (TOut1, TOut2),
	f4 func(x *BooleanLike) (TOut1, TOut2),
	f5 func(x *StringLike) (TOut1, TOut2),
	f6 func(x *NumberLike) (TOut1, TOut2),
	f7 func(x *ListLike) (TOut1, TOut2),
	f8 func(x *MapLike) (TOut1, TOut2),
	f9 func(x *StructLike) (TOut1, TOut2),
	f10 func(x *UnionLike) (TOut1, TOut2),
	df func(x Shape) (TOut1, TOut2),
) (TOut1, TOut2)

func MustMatchGuard

func MustMatchGuard[TOut any](
	x Guard,
	f1 func(x *Enum) TOut,
	f2 func(x *Required) TOut,
	f3 func(x *AndGuard) TOut,
) TOut

func MustMatchGuardR0

func MustMatchGuardR0(
	x Guard,
	f1 func(x *Enum),
	f2 func(x *Required),
	f3 func(x *AndGuard),
)

func MustMatchGuardR2

func MustMatchGuardR2[TOut1, TOut2 any](
	x Guard,
	f1 func(x *Enum) (TOut1, TOut2),
	f2 func(x *Required) (TOut1, TOut2),
	f3 func(x *AndGuard) (TOut1, TOut2),
) (TOut1, TOut2)

func MustMatchNumberKind added in v1.20.1

func MustMatchNumberKind[TOut any](
	x NumberKind,
	f1 func(x *UInt8) TOut,
	f2 func(x *UInt16) TOut,
	f3 func(x *UInt32) TOut,
	f4 func(x *UInt64) TOut,
	f5 func(x *Int8) TOut,
	f6 func(x *Int16) TOut,
	f7 func(x *Int32) TOut,
	f8 func(x *Int64) TOut,
	f9 func(x *Float32) TOut,
	f10 func(x *Float64) TOut,
) TOut

func MustMatchNumberKindR0 added in v1.20.1

func MustMatchNumberKindR0(
	x NumberKind,
	f1 func(x *UInt8),
	f2 func(x *UInt16),
	f3 func(x *UInt32),
	f4 func(x *UInt64),
	f5 func(x *Int8),
	f6 func(x *Int16),
	f7 func(x *Int32),
	f8 func(x *Int64),
	f9 func(x *Float32),
	f10 func(x *Float64),
)

func MustMatchNumberKindR2 added in v1.20.1

func MustMatchNumberKindR2[TOut1, TOut2 any](
	x NumberKind,
	f1 func(x *UInt8) (TOut1, TOut2),
	f2 func(x *UInt16) (TOut1, TOut2),
	f3 func(x *UInt32) (TOut1, TOut2),
	f4 func(x *UInt64) (TOut1, TOut2),
	f5 func(x *Int8) (TOut1, TOut2),
	f6 func(x *Int16) (TOut1, TOut2),
	f7 func(x *Int32) (TOut1, TOut2),
	f8 func(x *Int64) (TOut1, TOut2),
	f9 func(x *Float32) (TOut1, TOut2),
	f10 func(x *Float64) (TOut1, TOut2),
) (TOut1, TOut2)

func MustMatchShape

func MustMatchShape[TOut any](
	x Shape,
	f1 func(x *Any) TOut,
	f2 func(x *RefName) TOut,
	f3 func(x *AliasLike) TOut,
	f4 func(x *BooleanLike) TOut,
	f5 func(x *StringLike) TOut,
	f6 func(x *NumberLike) TOut,
	f7 func(x *ListLike) TOut,
	f8 func(x *MapLike) TOut,
	f9 func(x *StructLike) TOut,
	f10 func(x *UnionLike) TOut,
) TOut

func MustMatchShapeR0

func MustMatchShapeR0(
	x Shape,
	f1 func(x *Any),
	f2 func(x *RefName),
	f3 func(x *AliasLike),
	f4 func(x *BooleanLike),
	f5 func(x *StringLike),
	f6 func(x *NumberLike),
	f7 func(x *ListLike),
	f8 func(x *MapLike),
	f9 func(x *StructLike),
	f10 func(x *UnionLike),
)

func MustMatchShapeR2

func MustMatchShapeR2[TOut1, TOut2 any](
	x Shape,
	f1 func(x *Any) (TOut1, TOut2),
	f2 func(x *RefName) (TOut1, TOut2),
	f3 func(x *AliasLike) (TOut1, TOut2),
	f4 func(x *BooleanLike) (TOut1, TOut2),
	f5 func(x *StringLike) (TOut1, TOut2),
	f6 func(x *NumberLike) (TOut1, TOut2),
	f7 func(x *ListLike) (TOut1, TOut2),
	f8 func(x *MapLike) (TOut1, TOut2),
	f9 func(x *StructLike) (TOut1, TOut2),
	f10 func(x *UnionLike) (TOut1, TOut2),
) (TOut1, TOut2)

func NumberKindToGoName added in v1.21.0

func NumberKindToGoName(x NumberKind) string

func NumberKindToJSON added in v1.20.1

func NumberKindToJSON(x NumberKind) ([]byte, error)

func NumberLikeToJSON added in v1.20.0

func NumberLikeToJSON(x *NumberLike) ([]byte, error)

func Ptr added in v1.21.0

func Ptr[A any](x A) *A

func RefNameToJSON added in v1.20.0

func RefNameToJSON(x *RefName) ([]byte, error)

func Register added in v1.21.0

func Register(x Shape)

func RequiredToJSON added in v1.20.0

func RequiredToJSON(x *Required) ([]byte, error)

func ShapeToJSON added in v1.20.0

func ShapeToJSON(x Shape) ([]byte, error)

func StringLikeToJSON added in v1.20.0

func StringLikeToJSON(x *StringLike) ([]byte, error)

func StructLikeToJSON added in v1.20.0

func StructLikeToJSON(x *StructLike) ([]byte, error)

func TagGetValue added in v1.21.0

func TagGetValue(x map[string]Tag, tag, defaults string) string

func Tags added in v1.21.0

func Tags(x Shape) map[string]Tag

func TagsToDesc added in v1.20.0

func TagsToDesc(tags map[string]Tag) *string

func ToGoFullTypeNameFromReflect added in v1.21.0

func ToGoFullTypeNameFromReflect(x reflect.Type) string

ToGoFullTypeNameFromReflect returns full type name with package name example:

	github.com/widmogrod/mkunion/x/schema.Any
 string

func ToGoPkgImportName added in v1.21.0

func ToGoPkgImportName(x Shape) string

func ToGoPkgName added in v1.21.0

func ToGoPkgName(x Shape) string

func ToGoTypeName added in v1.21.0

func ToGoTypeName(x Shape, options ...ToGoTypeNameOption) string

func ToGoTypeNameFromReflect added in v1.21.0

func ToGoTypeNameFromReflect(x reflect.Type) string

ToGoTypeNameFromReflect returns type name without package name example:

	schema.Any
 string

func ToGoTypeParamsNames added in v1.21.0

func ToGoTypeParamsNames(x Shape) []string

func ToJsonSchema added in v1.20.0

func ToJsonSchema(s Shape) string

ToJsonSchema converts a Shape to a JSON Schema following specification https://json-schema.org/specification

func ToOpenAIFunctionDefinition added in v1.20.0

func ToOpenAIFunctionDefinition(name, desc string, in Shape) openai.FunctionDefinition

func ToStr

func ToStr(x Shape) string

func ToTypeScript

func ToTypeScript(x Shape, option *TypeScriptOptions) string

func UInt16ToJSON added in v1.20.1

func UInt16ToJSON(x *UInt16) ([]byte, error)

func UInt32ToJSON added in v1.20.1

func UInt32ToJSON(x *UInt32) ([]byte, error)

func UInt64ToJSON added in v1.20.1

func UInt64ToJSON(x *UInt64) ([]byte, error)

func UInt8ToJSON added in v1.20.1

func UInt8ToJSON(x *UInt8) ([]byte, error)

func UnionLikeToJSON added in v1.20.0

func UnionLikeToJSON(x *UnionLike) ([]byte, error)

func UnwrapPointer added in v1.21.0

func UnwrapPointer(x string) string

func WrapPointerIf added in v1.21.0

func WrapPointerIf(name string, isPointer bool) string

func WrapPointerIf2 added in v1.21.0

func WrapPointerIf2(name string, isPointer bool, x Shape) string

func WrapPointerIfField added in v1.21.0

func WrapPointerIfField(name string, field *FieldLike) string

Types

type AliasLike added in v1.20.2

type AliasLike struct {
	Name          string
	PkgName       string
	PkgImportName string
	IsAlias       bool
	Type          Shape
	Tags          map[string]Tag
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func AliasLikeFromJSON added in v1.20.2

func AliasLikeFromJSON(x []byte) (*AliasLike, error)

func (*AliasLike) AcceptShape added in v1.20.2

func (r *AliasLike) AcceptShape(v ShapeVisitor) any

func (*AliasLike) MarshalJSON added in v1.20.2

func (self *AliasLike) MarshalJSON() ([]byte, error)

func (*AliasLike) UnmarshalJSON added in v1.20.2

func (self *AliasLike) UnmarshalJSON(x []byte) error

type AndGuard

type AndGuard struct {
	L []Guard
}
Regexp   struct {
	Regexp string
}
Between struct {
	Min int
	Max int
}

func AndGuardFromJSON added in v1.20.0

func AndGuardFromJSON(x []byte) (*AndGuard, error)

func (*AndGuard) AcceptGuard

func (r *AndGuard) AcceptGuard(v GuardVisitor) any

func (*AndGuard) MarshalJSON added in v1.20.0

func (self *AndGuard) MarshalJSON() ([]byte, error)

func (*AndGuard) UnmarshalJSON added in v1.20.0

func (self *AndGuard) UnmarshalJSON(x []byte) error

type Any

type Any struct{}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func AnyFromJSON added in v1.20.0

func AnyFromJSON(x []byte) (*Any, error)

func (*Any) AcceptShape

func (r *Any) AcceptShape(v ShapeVisitor) any

func (*Any) MarshalJSON added in v1.20.0

func (self *Any) MarshalJSON() ([]byte, error)

func (*Any) UnmarshalJSON added in v1.20.0

func (self *Any) UnmarshalJSON(x []byte) error

type BooleanLike

type BooleanLike struct{}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func BooleanLikeFromJSON added in v1.20.0

func BooleanLikeFromJSON(x []byte) (*BooleanLike, error)

func (*BooleanLike) AcceptShape

func (r *BooleanLike) AcceptShape(v ShapeVisitor) any

func (*BooleanLike) MarshalJSON added in v1.20.0

func (self *BooleanLike) MarshalJSON() ([]byte, error)

func (*BooleanLike) UnmarshalJSON added in v1.20.0

func (self *BooleanLike) UnmarshalJSON(x []byte) error

type Enum added in v1.20.0

type Enum struct {
	Val []string
}

go:generate go run ../../cmd/mkunion/main.go -name=Guard

func EnumFromJSON added in v1.20.0

func EnumFromJSON(x []byte) (*Enum, error)

func (*Enum) AcceptGuard added in v1.20.0

func (r *Enum) AcceptGuard(v GuardVisitor) any

func (*Enum) MarshalJSON added in v1.20.0

func (self *Enum) MarshalJSON() ([]byte, error)

func (*Enum) UnmarshalJSON added in v1.20.0

func (self *Enum) UnmarshalJSON(x []byte) error

type FieldLike

type FieldLike struct {
	Name      string
	Type      Shape
	Desc      *string
	Guard     Guard
	IsPointer bool
	Tags      map[string]Tag
}

type Float32 added in v1.20.1

type Float32 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func Float32FromJSON added in v1.20.1

func Float32FromJSON(x []byte) (*Float32, error)

func (*Float32) AcceptNumberKind added in v1.20.1

func (r *Float32) AcceptNumberKind(v NumberKindVisitor) any

func (*Float32) MarshalJSON added in v1.20.1

func (self *Float32) MarshalJSON() ([]byte, error)

func (*Float32) UnmarshalJSON added in v1.20.1

func (self *Float32) UnmarshalJSON(x []byte) error

type Float64 added in v1.20.1

type Float64 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func Float64FromJSON added in v1.20.1

func Float64FromJSON(x []byte) (*Float64, error)

func (*Float64) AcceptNumberKind added in v1.20.1

func (r *Float64) AcceptNumberKind(v NumberKindVisitor) any

func (*Float64) MarshalJSON added in v1.20.1

func (self *Float64) MarshalJSON() ([]byte, error)

func (*Float64) UnmarshalJSON added in v1.20.1

func (self *Float64) UnmarshalJSON(x []byte) error

type FromASTOption added in v1.20.2

type FromASTOption func(x Shape)

type Guard

type Guard interface {
	AcceptGuard(g GuardVisitor) any
}

func ConcatGuard added in v1.20.0

func ConcatGuard(a, b Guard) Guard

func GuardFromJSON added in v1.20.0

func GuardFromJSON(x []byte) (Guard, error)

func TagsToGuard added in v1.20.0

func TagsToGuard(tags map[string]Tag) Guard

type GuardUnionJSON added in v1.20.0

type GuardUnionJSON struct {
	Type     string          `json:"$type,omitempty"`
	Enum     json.RawMessage `json:"shape.Enum,omitempty"`
	Required json.RawMessage `json:"shape.Required,omitempty"`
	AndGuard json.RawMessage `json:"shape.AndGuard,omitempty"`
}

type GuardVisitor

type GuardVisitor interface {
	VisitEnum(v *Enum) any
	VisitRequired(v *Required) any
	VisitAndGuard(v *AndGuard) any
}

type InferredInfo added in v1.20.0

type InferredInfo struct {
	// contains filtered or unexported fields
}

func InferFromFile added in v1.20.0

func InferFromFile(filename string) (*InferredInfo, error)

func (*InferredInfo) PackageImportName added in v1.21.0

func (f *InferredInfo) PackageImportName() string

func (*InferredInfo) PackageName added in v1.20.0

func (f *InferredInfo) PackageName() string

func (*InferredInfo) RetrieveShapeNamedAs added in v1.21.0

func (f *InferredInfo) RetrieveShapeNamedAs(name string) Shape

func (*InferredInfo) RetrieveShapes added in v1.21.0

func (f *InferredInfo) RetrieveShapes() []Shape

func (*InferredInfo) RetrieveShapesTaggedAs added in v1.21.0

func (f *InferredInfo) RetrieveShapesTaggedAs(tagName string) []Shape

func (*InferredInfo) RetrieveStruct added in v1.20.0

func (f *InferredInfo) RetrieveStruct(name string) *StructLike

func (*InferredInfo) RetrieveStructs added in v1.20.2

func (f *InferredInfo) RetrieveStructs() []*StructLike

func (*InferredInfo) RetrieveUnion added in v1.20.0

func (f *InferredInfo) RetrieveUnion(name string) *UnionLike

func (*InferredInfo) RetrieveUnions added in v1.20.0

func (f *InferredInfo) RetrieveUnions() []*UnionLike

func (*InferredInfo) Visit added in v1.20.0

func (f *InferredInfo) Visit(n ast.Node) ast.Visitor

type Int16 added in v1.20.1

type Int16 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func Int16FromJSON added in v1.20.1

func Int16FromJSON(x []byte) (*Int16, error)

func (*Int16) AcceptNumberKind added in v1.20.1

func (r *Int16) AcceptNumberKind(v NumberKindVisitor) any

func (*Int16) MarshalJSON added in v1.20.1

func (self *Int16) MarshalJSON() ([]byte, error)

func (*Int16) UnmarshalJSON added in v1.20.1

func (self *Int16) UnmarshalJSON(x []byte) error

type Int32 added in v1.20.1

type Int32 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func Int32FromJSON added in v1.20.1

func Int32FromJSON(x []byte) (*Int32, error)

func (*Int32) AcceptNumberKind added in v1.20.1

func (r *Int32) AcceptNumberKind(v NumberKindVisitor) any

func (*Int32) MarshalJSON added in v1.20.1

func (self *Int32) MarshalJSON() ([]byte, error)

func (*Int32) UnmarshalJSON added in v1.20.1

func (self *Int32) UnmarshalJSON(x []byte) error

type Int64 added in v1.20.1

type Int64 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func Int64FromJSON added in v1.20.1

func Int64FromJSON(x []byte) (*Int64, error)

func (*Int64) AcceptNumberKind added in v1.20.1

func (r *Int64) AcceptNumberKind(v NumberKindVisitor) any

func (*Int64) MarshalJSON added in v1.20.1

func (self *Int64) MarshalJSON() ([]byte, error)

func (*Int64) UnmarshalJSON added in v1.20.1

func (self *Int64) UnmarshalJSON(x []byte) error

type Int8 added in v1.20.1

type Int8 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func Int8FromJSON added in v1.20.1

func Int8FromJSON(x []byte) (*Int8, error)

func (*Int8) AcceptNumberKind added in v1.20.1

func (r *Int8) AcceptNumberKind(v NumberKindVisitor) any

func (*Int8) MarshalJSON added in v1.20.1

func (self *Int8) MarshalJSON() ([]byte, error)

func (*Int8) UnmarshalJSON added in v1.20.1

func (self *Int8) UnmarshalJSON(x []byte) error

type ListLike

type ListLike struct {
	//Extend *ListLike
	//Guard  Guard
	Element          Shape
	ElementIsPointer bool
	// ArrayLen is a pointer to int, when it's nil, it means it's a slice.
	ArrayLen *int
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func ListLikeFromJSON added in v1.20.0

func ListLikeFromJSON(x []byte) (*ListLike, error)

func (*ListLike) AcceptShape

func (r *ListLike) AcceptShape(v ShapeVisitor) any

func (*ListLike) MarshalJSON added in v1.20.0

func (self *ListLike) MarshalJSON() ([]byte, error)

func (*ListLike) UnmarshalJSON added in v1.20.0

func (self *ListLike) UnmarshalJSON(x []byte) error

type MapLike

type MapLike struct {
	//Extend *MapLike
	//Guard  Guard
	Key          Shape
	Val          Shape
	KeyIsPointer bool
	ValIsPointer bool
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func MapLikeFromJSON added in v1.20.0

func MapLikeFromJSON(x []byte) (*MapLike, error)

func (*MapLike) AcceptShape

func (r *MapLike) AcceptShape(v ShapeVisitor) any

func (*MapLike) MarshalJSON added in v1.20.0

func (self *MapLike) MarshalJSON() ([]byte, error)

func (*MapLike) UnmarshalJSON added in v1.20.0

func (self *MapLike) UnmarshalJSON(x []byte) error

type NumberKind added in v1.20.1

type NumberKind interface {
	AcceptNumberKind(g NumberKindVisitor) any
}

func NumberKindFromJSON added in v1.20.1

func NumberKindFromJSON(x []byte) (NumberKind, error)

type NumberKindUnionJSON added in v1.20.1

type NumberKindUnionJSON struct {
	Type    string          `json:"$type,omitempty"`
	UInt8   json.RawMessage `json:"shape.UInt8,omitempty"`
	UInt16  json.RawMessage `json:"shape.UInt16,omitempty"`
	UInt32  json.RawMessage `json:"shape.UInt32,omitempty"`
	UInt64  json.RawMessage `json:"shape.UInt64,omitempty"`
	Int8    json.RawMessage `json:"shape.Int8,omitempty"`
	Int16   json.RawMessage `json:"shape.Int16,omitempty"`
	Int32   json.RawMessage `json:"shape.Int32,omitempty"`
	Int64   json.RawMessage `json:"shape.Int64,omitempty"`
	Float32 json.RawMessage `json:"shape.Float32,omitempty"`
	Float64 json.RawMessage `json:"shape.Float64,omitempty"`
}

type NumberKindVisitor added in v1.20.1

type NumberKindVisitor interface {
	VisitUInt8(v *UInt8) any
	VisitUInt16(v *UInt16) any
	VisitUInt32(v *UInt32) any
	VisitUInt64(v *UInt64) any
	VisitInt8(v *Int8) any
	VisitInt16(v *Int16) any
	VisitInt32(v *Int32) any
	VisitInt64(v *Int64) any
	VisitFloat32(v *Float32) any
	VisitFloat64(v *Float64) any
}

type NumberLike

type NumberLike struct {
	Kind NumberKind
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func NumberLikeFromJSON added in v1.20.0

func NumberLikeFromJSON(x []byte) (*NumberLike, error)

func (*NumberLike) AcceptShape

func (r *NumberLike) AcceptShape(v ShapeVisitor) any

func (*NumberLike) MarshalJSON added in v1.20.0

func (self *NumberLike) MarshalJSON() ([]byte, error)

func (*NumberLike) UnmarshalJSON added in v1.20.0

func (self *NumberLike) UnmarshalJSON(x []byte) error

type RefName

type RefName struct {
	Name          string
	PkgName       string
	PkgImportName string
	IsPointer     bool
	Indexed       []Shape
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func ExtractRefs added in v1.21.0

func ExtractRefs(x Shape) []*RefName

func MkRefNameFromReflect added in v1.21.0

func MkRefNameFromReflect(x reflect.Type) *RefName

func MkRefNameFromString added in v1.21.0

func MkRefNameFromString(x string) *RefName

func RefNameFromJSON added in v1.20.0

func RefNameFromJSON(x []byte) (*RefName, error)

func (*RefName) AcceptShape

func (r *RefName) AcceptShape(v ShapeVisitor) any

func (*RefName) MarshalJSON added in v1.20.0

func (self *RefName) MarshalJSON() ([]byte, error)

func (*RefName) UnmarshalJSON added in v1.20.0

func (self *RefName) UnmarshalJSON(x []byte) error

type Required added in v1.20.0

type Required struct{}

go:generate go run ../../cmd/mkunion/main.go -name=Guard

func RequiredFromJSON added in v1.20.0

func RequiredFromJSON(x []byte) (*Required, error)

func (*Required) AcceptGuard added in v1.20.0

func (r *Required) AcceptGuard(v GuardVisitor) any

func (*Required) MarshalJSON added in v1.20.0

func (self *Required) MarshalJSON() ([]byte, error)

func (*Required) UnmarshalJSON added in v1.20.0

func (self *Required) UnmarshalJSON(x []byte) error

type Shape

type Shape interface {
	AcceptShape(g ShapeVisitor) any
}

func AliasLikeShape added in v1.20.2

func AliasLikeShape() Shape

func AndGuardShape added in v1.20.0

func AndGuardShape() Shape

func AnyShape added in v1.20.0

func AnyShape() Shape

func BooleanLikeShape added in v1.20.0

func BooleanLikeShape() Shape

func CleanTypeThatAreOvershadowByTypeParam added in v1.21.0

func CleanTypeThatAreOvershadowByTypeParam(typ Shape, params []TypeParam) Shape

func EnumShape added in v1.20.0

func EnumShape() Shape

func Float32Shape added in v1.20.1

func Float32Shape() Shape

func Float64Shape added in v1.20.1

func Float64Shape() Shape

func FromAST added in v1.20.2

func FromAST(x any, fx ...FromASTOption) Shape

func FromGo

func FromGo(x any) Shape

func FromGoReflect

func FromGoReflect(x reflect.Type, infiniteRecursionFix map[string]Shape) Shape

func GuardShape added in v1.20.0

func GuardShape() Shape

func IndexWith added in v1.21.0

func IndexWith(y Shape, ref *RefName) Shape

func InstantiateTypeThatAreOvershadowByTypeParam added in v1.21.0

func InstantiateTypeThatAreOvershadowByTypeParam(typ Shape, replacement map[string]Shape) Shape

func Int16Shape added in v1.20.1

func Int16Shape() Shape

func Int32Shape added in v1.20.1

func Int32Shape() Shape

func Int64Shape added in v1.20.1

func Int64Shape() Shape

func Int8Shape added in v1.20.1

func Int8Shape() Shape

func ListLikeShape added in v1.20.0

func ListLikeShape() Shape

func LookupPkgShapeOnDisk added in v1.21.0

func LookupPkgShapeOnDisk(pkgImportName string) []Shape

LookupPkgShapeOnDisk scans filesystem for all shapes in pkgImportName. it's suited for generators, that parse AST

func LookupShape added in v1.20.0

func LookupShape(x *RefName) (Shape, bool)

LookupShape scans registry for shapes. it's suited for runtime and compiled code

func LookupShapeOnDisk added in v1.21.0

func LookupShapeOnDisk(x *RefName) (Shape, bool)

LookupShapeOnDisk scans filesystem for shapes. it's suited for generators, that parse AST

func LookupShapeReflectAndIndex added in v1.21.0

func LookupShapeReflectAndIndex[A any]() (Shape, bool)

func MapLikeShape added in v1.20.0

func MapLikeShape() Shape

func NumberKindShape added in v1.20.1

func NumberKindShape() Shape

func NumberLikeShape added in v1.20.0

func NumberLikeShape() Shape

func RefNameShape added in v1.20.0

func RefNameShape() Shape

func RequiredShape added in v1.20.0

func RequiredShape() Shape

func ShapeFromJSON added in v1.20.0

func ShapeFromJSON(x []byte) (Shape, error)

func ShapeShape added in v1.20.0

func ShapeShape() Shape

func StringLikeShape added in v1.20.0

func StringLikeShape() Shape

func StructLikeShape added in v1.20.0

func StructLikeShape() Shape

func ToGoTypeParamsTypes added in v1.21.0

func ToGoTypeParamsTypes(x Shape) []Shape

func ToTypeScriptOptimisation added in v1.20.1

func ToTypeScriptOptimisation(x Shape) Shape

func TypeParamShape added in v1.21.0

func TypeParamShape() Shape

func UInt16Shape added in v1.20.1

func UInt16Shape() Shape

func UInt32Shape added in v1.20.1

func UInt32Shape() Shape

func UInt64Shape added in v1.20.1

func UInt64Shape() Shape

func UInt8Shape added in v1.20.1

func UInt8Shape() Shape

func UnionLikeShape added in v1.20.0

func UnionLikeShape() Shape

type ShapeUnionJSON added in v1.20.0

type ShapeUnionJSON struct {
	Type        string          `json:"$type,omitempty"`
	Any         json.RawMessage `json:"shape.Any,omitempty"`
	RefName     json.RawMessage `json:"shape.RefName,omitempty"`
	AliasLike   json.RawMessage `json:"shape.AliasLike,omitempty"`
	BooleanLike json.RawMessage `json:"shape.BooleanLike,omitempty"`
	StringLike  json.RawMessage `json:"shape.StringLike,omitempty"`
	NumberLike  json.RawMessage `json:"shape.NumberLike,omitempty"`
	ListLike    json.RawMessage `json:"shape.ListLike,omitempty"`
	MapLike     json.RawMessage `json:"shape.MapLike,omitempty"`
	StructLike  json.RawMessage `json:"shape.StructLike,omitempty"`
	UnionLike   json.RawMessage `json:"shape.UnionLike,omitempty"`
}

type ShapeVisitor

type ShapeVisitor interface {
	VisitAny(v *Any) any
	VisitRefName(v *RefName) any
	VisitAliasLike(v *AliasLike) any
	VisitBooleanLike(v *BooleanLike) any
	VisitStringLike(v *StringLike) any
	VisitNumberLike(v *NumberLike) any
	VisitListLike(v *ListLike) any
	VisitMapLike(v *MapLike) any
	VisitStructLike(v *StructLike) any
	VisitUnionLike(v *UnionLike) any
}

type StringLike

type StringLike struct {
}

StringLike is a string type, and when it has name, it means it named type. For example:

type C string

func StringLikeFromJSON added in v1.20.0

func StringLikeFromJSON(x []byte) (*StringLike, error)

func (*StringLike) AcceptShape

func (r *StringLike) AcceptShape(v ShapeVisitor) any

func (*StringLike) MarshalJSON added in v1.20.0

func (self *StringLike) MarshalJSON() ([]byte, error)

func (*StringLike) UnmarshalJSON added in v1.20.0

func (self *StringLike) UnmarshalJSON(x []byte) error

type StructLike

type StructLike struct {
	Name          string
	PkgName       string
	PkgImportName string
	TypeParams    []TypeParam
	Fields        []*FieldLike
	Tags          map[string]Tag
	// this refers when struct is instantiated
	IsPointer bool
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func StructLikeFromJSON added in v1.20.0

func StructLikeFromJSON(x []byte) (*StructLike, error)

func (*StructLike) AcceptShape

func (r *StructLike) AcceptShape(v ShapeVisitor) any

func (*StructLike) MarshalJSON added in v1.20.0

func (self *StructLike) MarshalJSON() ([]byte, error)

func (*StructLike) UnmarshalJSON added in v1.20.0

func (self *StructLike) UnmarshalJSON(x []byte) error

type Tag added in v1.21.0

type Tag struct {
	Value   string
	Options []string
}

type ToGoTypeNameOption added in v1.21.0

type ToGoTypeNameOption string

func WithInstantiation added in v1.21.0

func WithInstantiation() ToGoTypeNameOption

func WithPkgImportName added in v1.21.0

func WithPkgImportName() ToGoTypeNameOption

func WithRootPackage added in v1.21.0

func WithRootPackage(pkgName string) ToGoTypeNameOption

type TypeParam added in v1.20.2

type TypeParam struct {
	Name string
	Type Shape
}

func (*TypeParam) MarshalJSON added in v1.21.0

func (r *TypeParam) MarshalJSON() ([]byte, error)

func (*TypeParam) UnmarshalJSON added in v1.21.0

func (r *TypeParam) UnmarshalJSON(bytes []byte) error

type TypeScriptOptions

type TypeScriptOptions struct {
	// contains filtered or unexported fields
}

func (*TypeScriptOptions) IsCurrentPkgName

func (o *TypeScriptOptions) IsCurrentPkgName(pkgName string) bool

func (*TypeScriptOptions) NeedsToImportPkgName

func (o *TypeScriptOptions) NeedsToImportPkgName(pkg packageName, imp packageImportName)

type TypeScriptRenderer

type TypeScriptRenderer struct {
	// contains filtered or unexported fields
}

func NewTypeScriptRenderer

func NewTypeScriptRenderer() *TypeScriptRenderer

func (*TypeScriptRenderer) AddShape added in v1.21.0

func (r *TypeScriptRenderer) AddShape(x Shape)

func (*TypeScriptRenderer) FollowImports added in v1.21.0

func (r *TypeScriptRenderer) FollowImports()

func (*TypeScriptRenderer) FollowRef added in v1.21.0

func (r *TypeScriptRenderer) FollowRef(x Shape)

func (*TypeScriptRenderer) WriteToDir

func (r *TypeScriptRenderer) WriteToDir(dir string) error

type UInt16 added in v1.20.1

type UInt16 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func UInt16FromJSON added in v1.20.1

func UInt16FromJSON(x []byte) (*UInt16, error)

func (*UInt16) AcceptNumberKind added in v1.20.1

func (r *UInt16) AcceptNumberKind(v NumberKindVisitor) any

func (*UInt16) MarshalJSON added in v1.20.1

func (self *UInt16) MarshalJSON() ([]byte, error)

func (*UInt16) UnmarshalJSON added in v1.20.1

func (self *UInt16) UnmarshalJSON(x []byte) error

type UInt32 added in v1.20.1

type UInt32 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func UInt32FromJSON added in v1.20.1

func UInt32FromJSON(x []byte) (*UInt32, error)

func (*UInt32) AcceptNumberKind added in v1.20.1

func (r *UInt32) AcceptNumberKind(v NumberKindVisitor) any

func (*UInt32) MarshalJSON added in v1.20.1

func (self *UInt32) MarshalJSON() ([]byte, error)

func (*UInt32) UnmarshalJSON added in v1.20.1

func (self *UInt32) UnmarshalJSON(x []byte) error

type UInt64 added in v1.20.1

type UInt64 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func UInt64FromJSON added in v1.20.1

func UInt64FromJSON(x []byte) (*UInt64, error)

func (*UInt64) AcceptNumberKind added in v1.20.1

func (r *UInt64) AcceptNumberKind(v NumberKindVisitor) any

func (*UInt64) MarshalJSON added in v1.20.1

func (self *UInt64) MarshalJSON() ([]byte, error)

func (*UInt64) UnmarshalJSON added in v1.20.1

func (self *UInt64) UnmarshalJSON(x []byte) error

type UInt8 added in v1.20.1

type UInt8 struct{}

go:generate go run ../../cmd/mkunion/main.go -name=NumberKind

func UInt8FromJSON added in v1.20.1

func UInt8FromJSON(x []byte) (*UInt8, error)

func (*UInt8) AcceptNumberKind added in v1.20.1

func (r *UInt8) AcceptNumberKind(v NumberKindVisitor) any

func (*UInt8) MarshalJSON added in v1.20.1

func (self *UInt8) MarshalJSON() ([]byte, error)

func (*UInt8) UnmarshalJSON added in v1.20.1

func (self *UInt8) UnmarshalJSON(x []byte) error

type UnionLike

type UnionLike struct {
	Name          string
	PkgName       string
	PkgImportName string
	Variant       []Shape
	Tags          map[string]Tag
}

go:generate go run ../../cmd/mkunion/main.go -name=Shape

func UnionLikeFromJSON added in v1.20.0

func UnionLikeFromJSON(x []byte) (*UnionLike, error)

func (*UnionLike) AcceptShape

func (r *UnionLike) AcceptShape(v ShapeVisitor) any

func (*UnionLike) MarshalJSON added in v1.20.0

func (self *UnionLike) MarshalJSON() ([]byte, error)

func (*UnionLike) UnmarshalJSON added in v1.20.0

func (self *UnionLike) UnmarshalJSON(x []byte) error

Directories

Path Synopsis
Code generated by mkunion.
Code generated by mkunion.

Jump to

Keyboard shortcuts

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