bindings

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModifierAbstract  = "AbstractKeyword"
	ModifierAccessor  = "AccessorKeyword"
	ModifierAsync     = "AsyncKeyword"
	ModifierConst     = "ConstKeyword"
	ModifierDeclare   = "DeclareKeyword"
	ModifierDefault   = "DefaultKeyword"
	ModifierExport    = "ExportKeyword"
	ModifierIn        = "InKeyword"
	ModifierPrivate   = "PrivateKeyword"
	ModifierProtected = "ProtectedKeyword"
	ModifierPublic    = "PublicKeyword"
	ModifierReadonly  = "ReadonlyKeyword"
	ModifierOut       = "OutKeyword"
	ModifierOverride  = "OverrideKeyword"
	ModifierStatic    = "StaticKeyword"
)
View Source
const (
	NodeFlagsConstant = 2
)

Variables

This section is empty.

Functions

func List

func List[F any, T any](list []F, convert func(F) T) []T

List is a helper function to reduce boilerplate when converting slices of database types to slices of codersdk types. Only works if the function takes a single argument.

func ListLazy

func ListLazy[F any, T any](convert func(F) T) func(list []F) []T

ListLazy returns the converter function for a list, but does not eval the input. Helpful for combining the Map and the List functions.

func ToInt

func ToInt[T ~int](a T) int

func ToStrings

func ToStrings[T ~string](a []T) []string

ToStrings works for any type where the base type is a string.

Types

type Alias

type Alias struct {
	Name       Identifier
	Modifiers  []Modifier
	Type       ExpressionType
	Parameters []*TypeParameter
	Source
}

func (Alias) String

func (a Alias) String() string

type ArrayLiteralType

type ArrayLiteralType struct {
	Elements []ExpressionType
}

func (ArrayLiteralType) String

func (a ArrayLiteralType) String() string

type ArrayType

type ArrayType struct {
	Node ExpressionType
}

func Array

func Array(node ExpressionType) *ArrayType

func (ArrayType) String

func (a ArrayType) String() string

type Bindings

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

func New

func New() (*Bindings, error)

func (*Bindings) Alias

func (b *Bindings) Alias(alias *Alias) (*goja.Object, error)

func (*Bindings) Array

func (b *Bindings) Array(arrType ExpressionType) (*goja.Object, error)

func (*Bindings) ArrayLiteral

func (b *Bindings) ArrayLiteral(value *ArrayLiteralType) (*goja.Object, error)

func (*Bindings) BooleanLiteral

func (b *Bindings) BooleanLiteral(value int) (*goja.Object, error)

func (*Bindings) Comment

func (b *Bindings) Comment(comment Comment) (*goja.Object, error)

func (*Bindings) FloatLiteral

func (b *Bindings) FloatLiteral(value float64) (*goja.Object, error)

func (*Bindings) HeritageClause

func (b *Bindings) HeritageClause(clause *HeritageClause) (*goja.Object, error)

func (*Bindings) Identifier

func (b *Bindings) Identifier(name string) (*goja.Object, error)

func (*Bindings) Interface

func (b *Bindings) Interface(ti *Interface) (*goja.Object, error)

func (*Bindings) LiteralKeyword

func (b *Bindings) LiteralKeyword(word *LiteralKeyword) (*goja.Object, error)

func (*Bindings) Modifier

func (b *Bindings) Modifier(name Modifier) (*goja.Object, error)

func (*Bindings) Null

func (b *Bindings) Null() (*goja.Object, error)

func (*Bindings) NumericLiteral

func (b *Bindings) NumericLiteral(value int64) (*goja.Object, error)

func (*Bindings) OperatorNode

func (b *Bindings) OperatorNode(value *OperatorNodeType) (*goja.Object, error)

func (*Bindings) PropertySignature

func (b *Bindings) PropertySignature(sig *PropertySignature) (*goja.Object, error)

func (*Bindings) Reference

func (b *Bindings) Reference(ref *ReferenceType) (*goja.Object, error)

func (*Bindings) SerializeToTypescript

func (b *Bindings) SerializeToTypescript(node *goja.Object) (string, error)

func (*Bindings) StringLiteral

func (b *Bindings) StringLiteral(value string) (*goja.Object, error)

func (*Bindings) ToTypescriptDeclarationNode

func (b *Bindings) ToTypescriptDeclarationNode(ety DeclarationType) (*goja.Object, error)

func (*Bindings) ToTypescriptExpressionNode

func (b *Bindings) ToTypescriptExpressionNode(ety ExpressionType) (*goja.Object, error)

func (*Bindings) ToTypescriptNode

func (b *Bindings) ToTypescriptNode(ety Node) (*goja.Object, error)

func (*Bindings) TypeParameter

func (b *Bindings) TypeParameter(ty *TypeParameter) (*goja.Object, error)

func (*Bindings) Union

func (b *Bindings) Union(ty *UnionType) (*goja.Object, error)

func (*Bindings) VariableDeclaration

func (b *Bindings) VariableDeclaration(decl *VariableDeclaration) (*goja.Object, error)

func (*Bindings) VariableDeclarationList

func (b *Bindings) VariableDeclarationList(list *VariableDeclarationList) (*goja.Object, error)

func (*Bindings) VariableStatement

func (b *Bindings) VariableStatement(stmt *VariableStatement) (*goja.Object, error)

type Comment

type Comment struct {
	// Single or multi-line comment
	SingleLine      bool
	Text            string
	TrailingNewLine bool

	Node *goja.Object
}

type DeclarationType

type DeclarationType interface {
	Node
	// contains filtered or unexported methods
}

DeclarationType is any type that can exist at the top level of a AST. Meaning it can be serialized into valid Typescript.

type ExpressionType

type ExpressionType interface {
	Node
	// contains filtered or unexported methods
}

ExpressionType

type ExpressionWithTypeArguments

type ExpressionWithTypeArguments struct {
	Expression ExpressionType
	Arguments  []ExpressionType
}

type HeritageClause

type HeritageClause struct {
	Token HeritageType
	Args  []ExpressionType
}

HeritageClause interface Foo extends Bar, Baz {}

func HeritageClauseExtends

func HeritageClauseExtends(args ...ExpressionType) *HeritageClause

type HeritageType

type HeritageType string
const (
	HeritageTypeExtends    HeritageType = "extends"
	HeritageTypeImplements HeritageType = "implements"
)

type Identifier

type Identifier struct {
	Name    string
	Package *types.Package
	Prefix  string
}

Identifier is a name given to a variable, function, class, etc. Identifiers should be unique within a package. Package information is included to help with disambiguation in the case of name collisions.

func (Identifier) GoName

func (i Identifier) GoName() string

GoName should be a unique name for the identifier across all Go packages.

func (Identifier) PkgName

func (i Identifier) PkgName() string

func (Identifier) Ref

func (i Identifier) Ref() string

Ref returns the identifier reference to be used in the generated code. This is the identifier to be used in typescript, since all generated code lands in the same namespace.

func (Identifier) String

func (i Identifier) String() string

type Interface

type Interface struct {
	Name       Identifier
	Modifiers  []Modifier
	Fields     []*PropertySignature
	Parameters []*TypeParameter
	Heritage   []*HeritageClause
	// Comments maybe should be its own AST node?
	Comments []string
	Source
}

func (Interface) String

func (i Interface) String() string

type LiteralKeyword

type LiteralKeyword string
const (
	KeywordVoid      LiteralKeyword = "VoidKeyword"
	KeywordAny       LiteralKeyword = "AnyKeyword"
	KeywordBoolean   LiteralKeyword = "BooleanKeyword"
	KeywordIntrinsic LiteralKeyword = "IntrinsicKeyword"
	KeywordNever     LiteralKeyword = "NeverKeyword"
	KeywordNumber    LiteralKeyword = "NumberKeyword"
	KeywordObject    LiteralKeyword = "ObjectKeyword"
	KeywordString    LiteralKeyword = "StringKeyword"
	KeywordSymbol    LiteralKeyword = "SymbolKeyword"
	KeywordUndefined LiteralKeyword = "UndefinedKeyword"
	KeywordUnknown   LiteralKeyword = "UnknownKeyword"
	KeywordBigInt    LiteralKeyword = "BigIntKeyword"
	KeywordReadonly  LiteralKeyword = "ReadonlyKeyword"
	KeywordUnique    LiteralKeyword = "UniqueKeyword"
	KeywordKeyOf     LiteralKeyword = "KeyOfKeyword"
)

func ToTypescriptLiteralKeyword

func ToTypescriptLiteralKeyword(word string) (LiteralKeyword, error)

func (LiteralKeyword) String

func (k LiteralKeyword) String() string

type LiteralType

type LiteralType struct {
	Value any // should be some constant value
}

type Modifier

type Modifier string

type Node

type Node interface {
	// contains filtered or unexported methods
}

type NodeFlags

type NodeFlags int

type Null

type Null struct {
}

type OperatorNodeType

type OperatorNodeType struct {
	Keyword LiteralKeyword
	Type    ExpressionType
}

func OperatorNode

func OperatorNode(keyword LiteralKeyword, node ExpressionType) *OperatorNodeType

OperatorNode allows adding a keyword to a type Keyword must be "KeyOfKeyword" | "UniqueKeyword" | "ReadonlyKeyword"

func (OperatorNodeType) String

func (o OperatorNodeType) String() string

type PropertySignature

type PropertySignature struct {
	// Name is the field name
	Name          string
	Modifiers     []Modifier
	QuestionToken bool
	Type          ExpressionType
	// FieldComments maybe should be its own AST node?
	FieldComments []string
}

PropertySignature is a field in an interface

func (PropertySignature) String

func (f PropertySignature) String() string

type ReferenceType

type ReferenceType struct {
	Name Identifier `json:"name"`
	// TODO: Generics
	Arguments []ExpressionType `json:"arguments"`
}

ReferenceType can be used to reference another type by name

func Reference

func Reference(name Identifier, args ...ExpressionType) *ReferenceType

func (ReferenceType) String

func (r ReferenceType) String() string

type Source

type Source struct {
	File     string
	Position token.Position
}

Source is the golang file that an entity is sourced from.

func (Source) Comment

func (s Source) Comment(n *goja.Object) Comment

type TypeParameter

type TypeParameter struct {
	Name      Identifier
	Modifiers []Modifier
	Type      ExpressionType
	// DefaultType does not map to any Golang concepts and will never be
	// used.
	DefaultType ExpressionType
}

TypeParameter are generics in Go Foo[T comparable] -> - name: T - Modifiers: [] - Type: Comparable - DefaultType: nil

func Simplify

func Simplify(p []*TypeParameter) ([]*TypeParameter, error)

Simplify removes duplicate type parameters

func (TypeParameter) String

func (p TypeParameter) String() string

type UnionType

type UnionType struct {
	Types []ExpressionType
}

func Union

func Union(types ...ExpressionType) *UnionType

func (UnionType) String

func (r UnionType) String() string

type VariableDeclaration

type VariableDeclaration struct {
	Name            Identifier
	ExclamationMark bool
	Type            ExpressionType
	Initializer     ExpressionType
}

func (VariableDeclaration) String

func (v VariableDeclaration) String() string

type VariableDeclarationList

type VariableDeclarationList struct {
	Declarations []*VariableDeclaration
	Flags        NodeFlags
}

type VariableStatement

type VariableStatement struct {
	Modifiers    []Modifier
	Declarations *VariableDeclarationList
	Source
}

VariableStatement is a top level declaration of a variable var foo: string = "bar" const foo: string = "bar"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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