data

package
v0.0.0-...-e6cbd97 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetModuleName

func GetModuleName(packageName, fileName string) string

GetModuleName returns module name = package name + file name to be the unique identifier for source file in a ts file

func GetTSFileName

func GetTSFileName(fileName string) string

GetTSFileName gets the typescript filename out of the proto file name

Types

type Dependency

type Dependency struct {
	// ModuleIdentifier will be a concanation of package + file base name to make it
	// unnique inside the file. This will act as a name space for other file and
	// types inside other file can be referred to using .
	ModuleIdentifier string
	// Source file will be the file at the end of the import statement.
	SourceFile string
}

Dependency stores the information about dependencies.

type Enum

type Enum struct {
	// Name will be the package level unique name
	// Nested names will concat with their parent messages so that it will remain unique
	// This also means nested type might be a bit ugly in type script but whatever
	Name string
	// Due to the fact that Protos allows alias fields which is not a feature
	// in Typescript, it's better to use string representation of it.
	// So Values here will basically be the name of the field.
	Values []string
}

Enum is the data out to render Enums in a file Enums that nested inside messages will be pulled out to the top level Because the way it works in typescript

func NewEnum

func NewEnum() *Enum

NewEnum creates an enum instance.

type Field

type Field struct {
	Name string
	// Type will be similar to NestedEnum.Type. Where scalar type and types inside
	// the same file will be short type
	// external types will have fully-qualified name and translated during render time
	Type string
	// IsExternal tells whether the type of this field is an external dependency
	IsExternal bool
	// IsOneOfField tells whether this field is part of a one of field.
	// one of fields will have extra method clearXXX,
	// and the setter accessor will clear out other fields in the group on set
	IsOneOfField bool
	// Message is the reference back to the parent message
	Message *Message
	// OneOfIndex is the index in the one of fields
	OneOfIndex int32
	// IsRepeated indicates whether the field is a repeated field
	IsRepeated bool
}

Field stores the information about a field inside message

func (*Field) GetType

func (f *Field) GetType() *TypeInfo

GetType returns some information of the type to aid the rendering

func (*Field) SetExternal

func (f *Field) SetExternal(external bool)

SetExternal mutate the IsExternal attribute

type File

type File struct {
	// Dependencies is a list of dependencies for the file, which will be rendered at the top of the file as import statements
	Dependencies []*Dependency
	// Enums is a list of enums to render, due to the fact that there cannot be any enum defined nested in the class in Typescript.
	// All Enums will be rendered at the top level
	Enums []*Enum
	// Messages represents top level messages inside the file.
	Messages []*Message
	// ExternalDependingTypes stores the external dependenciees fully qualified name,
	ExternalDependingTypes []string
	// Services stores the information to render service
	Services Services
	// Name is the name of the file
	Name string
	// TSFileName is the name of the output file
	TSFileName string
	// PackageNonScalarType stores the type inside the same packages within the file, which will be used to figure out external dependencies inside the same package (different files)
	PackageNonScalarType []Type
	// EnableStylingCheck enables the styling check for the given file
	EnableStylingCheck bool
}

File store the information about rendering a file

func NewFile

func NewFile() *File

NewFile returns an initialised new file

func (*File) IsEmpty

func (f *File) IsEmpty() bool

func (*File) NeedsOneOfSupport

func (f *File) NeedsOneOfSupport() bool

NeedsOneOfSupport indicates the file needs one of support type utilities

func (*File) NeedsStructPBSupport

func (f *File) NeedsStructPBSupport() bool

func (*File) StableDependencies

func (f *File) StableDependencies() []*Dependency

StableDependencies are dependencies in a stable order.

func (*File) TrackPackageNonScalarType

func (f *File) TrackPackageNonScalarType(t Type)

TrackPackageNonScalarType tracks the supplied non scala type in the same package

type MapEntryType

type MapEntryType struct {
	// Type of the map entry
	Type string
	// IsExternal indicates the field typeis external to its own package
	IsExternal bool
}

MapEntryType is the generic entry type for both key and value

func (*MapEntryType) GetType

func (m *MapEntryType) GetType() *TypeInfo

GetType returns the type information for the type entry

func (*MapEntryType) SetExternal

func (m *MapEntryType) SetExternal(external bool)

SetExternal mutate the IsExternal attribute inside

type Message

type Message struct {
	// Nested shows whether this message is a nested message and needs to be exported
	Nested bool
	// Name is the name of the Message
	Name string
	//FQType is the fully qualified type name for the message itself
	FQType string
	// Enums is a list of NestedEnums inside
	Enums []*NestedEnum
	// Fields is a list of fields to render
	Fields []*Field
	// NonOneOfFields contains a subset of fields that are not in the one-of groups
	NonOneOfFields []*Field
	// Message is the nested messages defined inside the message
	Messages []*Message
	// OneOfFieldsGroups is the grouped list of one of fields with same index. so that renderer can render the clearing of other fields on set.
	OneOfFieldsGroups map[int32][]*Field
	// OneOfFieldNames is the names of one of fields with same index. so that renderer can render the clearing of other fields on set.
	OneOfFieldsNames map[int32]string
}

Message stores the rendering information about message

func NewMessage

func NewMessage() *Message

NewMessage initialises and return a Message

func (*Message) HasOneOfFields

func (m *Message) HasOneOfFields() bool

HasOneOfFields returns true when the message has a one of field.

func (*Message) HasStructPBFields

func (m *Message) HasStructPBFields() bool

type Method

type Method struct {
	// Name is the name of the method
	Name string
	// URL is the method url path to invoke from client side
	URL string
	// Input is the input argument
	Input *MethodArgument
	// Output is the output argument
	Output *MethodArgument
	// ServerStreaming indicates the RPC call is a server streaming call
	ServerStreaming bool
	// ClientStreaming indicates the RPC call is a client streaming call, which will not be supported by GRPC Gateway
	ClientStreaming bool
	// HTTPMethod indicates the http method for this function
	HTTPMethod string
	// HTTPBody is the path for request body in the body's payload
	HTTPRequestBody *string
}

Method represents the rpc calls in protobuf service

type MethodArgument

type MethodArgument struct {
	// Type is the type of the argument
	Type string
	// IsExternal indicate if this type is an external dependency
	IsExternal bool
	// IsRepeated indicates whether the field is a repeated field
	IsRepeated bool
}

MethodArgument stores the type information about method argument

func (*MethodArgument) GetType

func (m *MethodArgument) GetType() *TypeInfo

GetType returns some information of the type to aid the rendering

func (*MethodArgument) SetExternal

func (m *MethodArgument) SetExternal(external bool)

SetExternal mutates the IsExternal attribute of the type

type NestedEnum

type NestedEnum struct {
	// Name of the Enum inside the class, which will be identical to the name
	// defined inside the message
	Name string
	// Type will have two types of value, and the difference can be told by
	// IsExternal attribute.
	// For external one, because during analysis stage there might not be a full map
	// of the types inside Registry. So the actual translation of this will
	// be left in the render time
	// If it is only types inside the file, it will be filled with the unique type name defined
	// up at the top level
	Type string
}

NestedEnum stores the information of enums defined inside a message

type Service

type Service struct {
	// Name is the name of the Service
	Name string
	// Methods is a list of methods data
	Methods []*Method
}

Service is the data representation of Service in proto

func NewService

func NewService() *Service

NewService returns an initialised service

type Services

type Services []*Service

Services is an alias of Service array

func (Services) HasServerStreamingMethod

func (s Services) HasServerStreamingMethod() bool

HasServerStreamingMethod indicates whether there is server side streaming calls inside any of the services

func (Services) HasUnaryCallMethod

func (s Services) HasUnaryCallMethod() bool

HasUnaryCallMethod indicates whether there is unary methods inside any of the services

func (Services) NeedsFetchModule

func (s Services) NeedsFetchModule() bool

NeedsFetchModule returns whether the given services needs fetch module support

type Type

type Type interface {
	// GetType returns some information of the type to aid the rendering
	GetType() *TypeInfo
	// SetExternal changes the external field inside the data structure
	SetExternal(bool)
}

Type is an interface to get type out of field and method arguments

type TypeInfo

type TypeInfo struct {
	// Type
	Type string
	// IsRepeated indicates whether this field is a repeated field
	IsRepeated bool
	// IsExternal indicates whether this type is external
	IsExternal bool
}

TypeInfo stores some common type information for rendering

Jump to

Keyboard shortcuts

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