shape

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 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.

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{
	"uint":    &UInt{},
	"uint8":   &UInt8{},
	"uint16":  &UInt16{},
	"uint32":  &UInt32{},
	"uint64":  &UInt64{},
	"int":     &Int{},
	"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 IntToJSON added in v1.23.0

func IntToJSON(x *Int) ([]byte, error)

func IsASTAlias added in v1.24.0

func IsASTAlias(t *ast.TypeSpec) bool

func IsBinary added in v1.21.0

func IsBinary(x Shape) bool

func IsNamedShape added in v1.24.0

func IsNamedShape(x Shape) bool

func IsPointer added in v1.21.0

func IsPointer(x Shape) bool

func IsRequired added in v1.22.0

func IsRequired(x Guard) 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 IsWeekAlias added in v1.24.0

func IsWeekAlias(x Shape) bool

IsWeekAlias returns true if given shape is an alias and it's week alias. example:

type A = string

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 MatchGuardR0 added in v1.22.0

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

func MatchGuardR1 added in v1.22.0

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

func MatchGuardR2

func MatchGuardR2[T0, T1 any](
	x Guard,
	f1 func(x *Enum) (T0, T1),
	f2 func(x *Required) (T0, T1),
	f3 func(x *AndGuard) (T0, T1),
) (T0, T1)

func MatchGuardR3 added in v1.22.0

func MatchGuardR3[T0, T1, T2 any](
	x Guard,
	f1 func(x *Enum) (T0, T1, T2),
	f2 func(x *Required) (T0, T1, T2),
	f3 func(x *AndGuard) (T0, T1, T2),
) (T0, T1, T2)

func MatchNumberKindR0 added in v1.22.0

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

func MatchNumberKindR1 added in v1.22.0

func MatchNumberKindR1[T0 any](
	x NumberKind,
	f1 func(x *UInt) T0,
	f2 func(x *UInt8) T0,
	f3 func(x *UInt16) T0,
	f4 func(x *UInt32) T0,
	f5 func(x *UInt64) T0,
	f6 func(x *Int) T0,
	f7 func(x *Int8) T0,
	f8 func(x *Int16) T0,
	f9 func(x *Int32) T0,
	f10 func(x *Int64) T0,
	f11 func(x *Float32) T0,
	f12 func(x *Float64) T0,
) T0

func MatchNumberKindR2 added in v1.20.1

func MatchNumberKindR2[T0, T1 any](
	x NumberKind,
	f1 func(x *UInt) (T0, T1),
	f2 func(x *UInt8) (T0, T1),
	f3 func(x *UInt16) (T0, T1),
	f4 func(x *UInt32) (T0, T1),
	f5 func(x *UInt64) (T0, T1),
	f6 func(x *Int) (T0, T1),
	f7 func(x *Int8) (T0, T1),
	f8 func(x *Int16) (T0, T1),
	f9 func(x *Int32) (T0, T1),
	f10 func(x *Int64) (T0, T1),
	f11 func(x *Float32) (T0, T1),
	f12 func(x *Float64) (T0, T1),
) (T0, T1)

func MatchNumberKindR3 added in v1.22.0

func MatchNumberKindR3[T0, T1, T2 any](
	x NumberKind,
	f1 func(x *UInt) (T0, T1, T2),
	f2 func(x *UInt8) (T0, T1, T2),
	f3 func(x *UInt16) (T0, T1, T2),
	f4 func(x *UInt32) (T0, T1, T2),
	f5 func(x *UInt64) (T0, T1, T2),
	f6 func(x *Int) (T0, T1, T2),
	f7 func(x *Int8) (T0, T1, T2),
	f8 func(x *Int16) (T0, T1, T2),
	f9 func(x *Int32) (T0, T1, T2),
	f10 func(x *Int64) (T0, T1, T2),
	f11 func(x *Float32) (T0, T1, T2),
	f12 func(x *Float64) (T0, T1, T2),
) (T0, T1, T2)

func MatchPrimitiveKindR0 added in v1.22.0

func MatchPrimitiveKindR0(
	x PrimitiveKind,
	f1 func(x *BooleanLike),
	f2 func(x *StringLike),
	f3 func(x *NumberLike),
)

func MatchPrimitiveKindR1 added in v1.22.0

func MatchPrimitiveKindR1[T0 any](
	x PrimitiveKind,
	f1 func(x *BooleanLike) T0,
	f2 func(x *StringLike) T0,
	f3 func(x *NumberLike) T0,
) T0

func MatchPrimitiveKindR2 added in v1.22.0

func MatchPrimitiveKindR2[T0, T1 any](
	x PrimitiveKind,
	f1 func(x *BooleanLike) (T0, T1),
	f2 func(x *StringLike) (T0, T1),
	f3 func(x *NumberLike) (T0, T1),
) (T0, T1)

func MatchPrimitiveKindR3 added in v1.22.0

func MatchPrimitiveKindR3[T0, T1, T2 any](
	x PrimitiveKind,
	f1 func(x *BooleanLike) (T0, T1, T2),
	f2 func(x *StringLike) (T0, T1, T2),
	f3 func(x *NumberLike) (T0, T1, T2),
) (T0, T1, T2)

func MatchShapeR0 added in v1.22.0

func MatchShapeR0(
	x Shape,
	f1 func(x *Any),
	f2 func(x *RefName),
	f3 func(x *PointerLike),
	f4 func(x *AliasLike),
	f5 func(x *PrimitiveLike),
	f6 func(x *ListLike),
	f7 func(x *MapLike),
	f8 func(x *StructLike),
	f9 func(x *UnionLike),
)

func MatchShapeR1 added in v1.22.0

func MatchShapeR1[T0 any](
	x Shape,
	f1 func(x *Any) T0,
	f2 func(x *RefName) T0,
	f3 func(x *PointerLike) T0,
	f4 func(x *AliasLike) T0,
	f5 func(x *PrimitiveLike) T0,
	f6 func(x *ListLike) T0,
	f7 func(x *MapLike) T0,
	f8 func(x *StructLike) T0,
	f9 func(x *UnionLike) T0,
) T0

func MatchShapeR2

func MatchShapeR2[T0, T1 any](
	x Shape,
	f1 func(x *Any) (T0, T1),
	f2 func(x *RefName) (T0, T1),
	f3 func(x *PointerLike) (T0, T1),
	f4 func(x *AliasLike) (T0, T1),
	f5 func(x *PrimitiveLike) (T0, T1),
	f6 func(x *ListLike) (T0, T1),
	f7 func(x *MapLike) (T0, T1),
	f8 func(x *StructLike) (T0, T1),
	f9 func(x *UnionLike) (T0, T1),
) (T0, T1)

func MatchShapeR3 added in v1.22.0

func MatchShapeR3[T0, T1, T2 any](
	x Shape,
	f1 func(x *Any) (T0, T1, T2),
	f2 func(x *RefName) (T0, T1, T2),
	f3 func(x *PointerLike) (T0, T1, T2),
	f4 func(x *AliasLike) (T0, T1, T2),
	f5 func(x *PrimitiveLike) (T0, T1, T2),
	f6 func(x *ListLike) (T0, T1, T2),
	f7 func(x *MapLike) (T0, T1, T2),
	f8 func(x *StructLike) (T0, T1, T2),
	f9 func(x *UnionLike) (T0, T1, T2),
) (T0, T1, T2)

func Name added in v1.24.0

func Name(x Shape) string

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 PointerLikeToJSON added in v1.22.0

func PointerLikeToJSON(x *PointerLike) ([]byte, error)

func PrimitiveKindToJSON added in v1.22.0

func PrimitiveKindToJSON(x PrimitiveKind) ([]byte, error)

func PrimitiveLikeToJSON added in v1.22.0

func PrimitiveLikeToJSON(x *PrimitiveLike) ([]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 UIntToJSON added in v1.23.0

func UIntToJSON(x *UInt) ([]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

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
}

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 (r *AliasLike) MarshalJSON() ([]byte, error)

func (*AliasLike) UnmarshalJSON added in v1.20.2

func (r *AliasLike) UnmarshalJSON(data []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 (r *AndGuard) MarshalJSON() ([]byte, error)

func (*AndGuard) UnmarshalJSON added in v1.20.0

func (r *AndGuard) UnmarshalJSON(data []byte) error

type Any

type Any struct{}

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 (r *Any) MarshalJSON() ([]byte, error)

func (*Any) UnmarshalJSON added in v1.20.0

func (r *Any) UnmarshalJSON(data []byte) error

type BooleanLike

type BooleanLike struct{}

func BooleanLikeFromJSON added in v1.20.0

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

func (*BooleanLike) AcceptPrimitiveKind added in v1.22.0

func (r *BooleanLike) AcceptPrimitiveKind(v PrimitiveKindVisitor) any

func (*BooleanLike) MarshalJSON added in v1.20.0

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

func (*BooleanLike) UnmarshalJSON added in v1.20.0

func (r *BooleanLike) UnmarshalJSON(data []byte) error

type Enum added in v1.20.0

type Enum struct {
	Val []string
}

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 (r *Enum) MarshalJSON() ([]byte, error)

func (*Enum) UnmarshalJSON added in v1.20.0

func (r *Enum) UnmarshalJSON(data []byte) error

type FieldLike

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

type Float32 added in v1.20.1

type Float32 struct{}

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 (r *Float32) MarshalJSON() ([]byte, error)

func (*Float32) UnmarshalJSON added in v1.20.1

func (r *Float32) UnmarshalJSON(data []byte) error

type Float64 added in v1.20.1

type Float64 struct{}

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 (r *Float64) MarshalJSON() ([]byte, error)

func (*Float64) UnmarshalJSON added in v1.20.1

func (r *Float64) UnmarshalJSON(data []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) RetrieveShapeFromRef added in v1.24.0

func (f *InferredInfo) RetrieveShapeFromRef(x *RefName) Shape

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 Int added in v1.23.0

type Int struct{}

func IntFromJSON added in v1.23.0

func IntFromJSON(x []byte) (*Int, error)

func (*Int) AcceptNumberKind added in v1.23.0

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

func (*Int) MarshalJSON added in v1.23.0

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

func (*Int) UnmarshalJSON added in v1.23.0

func (r *Int) UnmarshalJSON(data []byte) error

type Int16 added in v1.20.1

type Int16 struct{}

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 (r *Int16) MarshalJSON() ([]byte, error)

func (*Int16) UnmarshalJSON added in v1.20.1

func (r *Int16) UnmarshalJSON(data []byte) error

type Int32 added in v1.20.1

type Int32 struct{}

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 (r *Int32) MarshalJSON() ([]byte, error)

func (*Int32) UnmarshalJSON added in v1.20.1

func (r *Int32) UnmarshalJSON(data []byte) error

type Int64 added in v1.20.1

type Int64 struct{}

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 (r *Int64) MarshalJSON() ([]byte, error)

func (*Int64) UnmarshalJSON added in v1.20.1

func (r *Int64) UnmarshalJSON(data []byte) error

type Int8 added in v1.20.1

type Int8 struct{}

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 (r *Int8) MarshalJSON() ([]byte, error)

func (*Int8) UnmarshalJSON added in v1.20.1

func (r *Int8) UnmarshalJSON(data []byte) error

type ListLike

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

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 (r *ListLike) MarshalJSON() ([]byte, error)

func (*ListLike) UnmarshalJSON added in v1.20.0

func (r *ListLike) UnmarshalJSON(data []byte) error

type MapLike

type MapLike struct {
	//Extend *MapLike
	//Guard  Guard
	Key Shape
	Val 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 (r *MapLike) MarshalJSON() ([]byte, error)

func (*MapLike) UnmarshalJSON added in v1.20.0

func (r *MapLike) UnmarshalJSON(data []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"`
	UInt    json.RawMessage `json:"shape.UInt,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"`
	Int     json.RawMessage `json:"shape.Int,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 {
	VisitUInt(v *UInt) any
	VisitUInt8(v *UInt8) any
	VisitUInt16(v *UInt16) any
	VisitUInt32(v *UInt32) any
	VisitUInt64(v *UInt64) any
	VisitInt(v *Int) 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
}

func NumberLikeFromJSON added in v1.20.0

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

func (*NumberLike) AcceptPrimitiveKind added in v1.22.0

func (r *NumberLike) AcceptPrimitiveKind(v PrimitiveKindVisitor) any

func (*NumberLike) MarshalJSON added in v1.20.0

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

func (*NumberLike) UnmarshalJSON added in v1.20.0

func (r *NumberLike) UnmarshalJSON(data []byte) error

type PointerLike added in v1.22.0

type PointerLike struct {
	Type Shape
}

func PointerLikeFromJSON added in v1.22.0

func PointerLikeFromJSON(x []byte) (*PointerLike, error)

func (*PointerLike) AcceptShape added in v1.22.0

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

func (*PointerLike) MarshalJSON added in v1.22.0

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

func (*PointerLike) UnmarshalJSON added in v1.22.0

func (r *PointerLike) UnmarshalJSON(data []byte) error

type PrimitiveKind added in v1.22.0

type PrimitiveKind interface {
	AcceptPrimitiveKind(g PrimitiveKindVisitor) any
}

func PrimitiveKindFromJSON added in v1.22.0

func PrimitiveKindFromJSON(x []byte) (PrimitiveKind, error)

type PrimitiveKindUnionJSON added in v1.22.0

type PrimitiveKindUnionJSON struct {
	Type        string          `json:"$type,omitempty"`
	BooleanLike json.RawMessage `json:"shape.BooleanLike,omitempty"`
	StringLike  json.RawMessage `json:"shape.StringLike,omitempty"`
	NumberLike  json.RawMessage `json:"shape.NumberLike,omitempty"`
}

type PrimitiveKindVisitor added in v1.22.0

type PrimitiveKindVisitor interface {
	VisitBooleanLike(v *BooleanLike) any
	VisitStringLike(v *StringLike) any
	VisitNumberLike(v *NumberLike) any
}

type PrimitiveLike added in v1.22.0

type PrimitiveLike struct {
	Kind PrimitiveKind
}

func PrimitiveLikeFromJSON added in v1.22.0

func PrimitiveLikeFromJSON(x []byte) (*PrimitiveLike, error)

func (*PrimitiveLike) AcceptShape added in v1.22.0

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

func (*PrimitiveLike) MarshalJSON added in v1.22.0

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

func (*PrimitiveLike) UnmarshalJSON added in v1.22.0

func (r *PrimitiveLike) UnmarshalJSON(data []byte) error

type RefName

type RefName struct {
	Name          string
	PkgName       string
	PkgImportName string
	Indexed       []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 (r *RefName) MarshalJSON() ([]byte, error)

func (*RefName) UnmarshalJSON added in v1.20.0

func (r *RefName) UnmarshalJSON(data []byte) error

type Required added in v1.20.0

type Required struct{}

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 (r *Required) MarshalJSON() ([]byte, error)

func (*Required) UnmarshalJSON added in v1.20.0

func (r *Required) UnmarshalJSON(data []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 FieldLikeShape added in v1.24.0

func FieldLikeShape() 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 IntShape added in v1.23.0

func IntShape() 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 PointerLikeShape added in v1.22.0

func PointerLikeShape() Shape

func PrimitiveKindShape added in v1.22.0

func PrimitiveKindShape() Shape

func PrimitiveLikeShape added in v1.22.0

func PrimitiveLikeShape() 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 TagShape added in v1.24.0

func TagShape() 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 UIntShape added in v1.23.0

func UIntShape() 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"`
	PointerLike   json.RawMessage `json:"shape.PointerLike,omitempty"`
	AliasLike     json.RawMessage `json:"shape.AliasLike,omitempty"`
	PrimitiveLike json.RawMessage `json:"shape.PrimitiveLike,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
	VisitPointerLike(v *PointerLike) any
	VisitAliasLike(v *AliasLike) any
	VisitPrimitiveLike(v *PrimitiveLike) 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) AcceptPrimitiveKind added in v1.22.0

func (r *StringLike) AcceptPrimitiveKind(v PrimitiveKindVisitor) any

func (*StringLike) MarshalJSON added in v1.20.0

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

func (*StringLike) UnmarshalJSON added in v1.20.0

func (r *StringLike) UnmarshalJSON(data []byte) error

type StructLike

type StructLike struct {
	Name          string
	PkgName       string
	PkgImportName string
	TypeParams    []TypeParam
	Fields        []*FieldLike
	Tags          map[string]Tag
}

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 (r *StructLike) MarshalJSON() ([]byte, error)

func (*StructLike) UnmarshalJSON added in v1.20.0

func (r *StructLike) UnmarshalJSON(data []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(data []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 UInt added in v1.23.0

type UInt struct{}

func UIntFromJSON added in v1.23.0

func UIntFromJSON(x []byte) (*UInt, error)

func (*UInt) AcceptNumberKind added in v1.23.0

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

func (*UInt) MarshalJSON added in v1.23.0

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

func (*UInt) UnmarshalJSON added in v1.23.0

func (r *UInt) UnmarshalJSON(data []byte) error

type UInt16 added in v1.20.1

type UInt16 struct{}

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 (r *UInt16) MarshalJSON() ([]byte, error)

func (*UInt16) UnmarshalJSON added in v1.20.1

func (r *UInt16) UnmarshalJSON(data []byte) error

type UInt32 added in v1.20.1

type UInt32 struct{}

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 (r *UInt32) MarshalJSON() ([]byte, error)

func (*UInt32) UnmarshalJSON added in v1.20.1

func (r *UInt32) UnmarshalJSON(data []byte) error

type UInt64 added in v1.20.1

type UInt64 struct{}

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 (r *UInt64) MarshalJSON() ([]byte, error)

func (*UInt64) UnmarshalJSON added in v1.20.1

func (r *UInt64) UnmarshalJSON(data []byte) error

type UInt8 added in v1.20.1

type UInt8 struct{}

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 (r *UInt8) MarshalJSON() ([]byte, error)

func (*UInt8) UnmarshalJSON added in v1.20.1

func (r *UInt8) UnmarshalJSON(data []byte) error

type UnionLike

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

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 (r *UnionLike) MarshalJSON() ([]byte, error)

func (*UnionLike) UnmarshalJSON added in v1.20.0

func (r *UnionLike) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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