tsutils

package
v1.0.25 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldName

func FieldName(opt *TSOption) func(name string) string

func FunctionCase_TSProto

func FunctionCase_TSProto(s string) string

TSProto Function Case

func GetModuleName

func GetModuleName(file protoreflect.FileDescriptor) string

GetModuleName returns module name = package name + base file name to be the unique identifier for source file in a ts file. Package name and base file name are converted to camel case, special characters like dot, dash and underscore are removed. packageName: memos.api.v1 fileName: memos.proto

func JSONCamelCase

func JSONCamelCase(s string) string

JSONCamelCase converts a snake_case identifier to a camelCase identifier, according to the protobuf JSON specification.

Copied from: google.golang.org/protobuf/internal/strs.

func JsonFieldName added in v1.0.24

func JsonFieldName(opt *TSOption) func(name string) string

func TSProtoEnumToJson

func TSProtoEnumToJson(enumTyp *protogen.Enum) func(g *TSRegistry, in string) string

func TSProtoFieldMaskToJson

func TSProtoFieldMaskToJson(msgTyp *protogen.Message) func(g *TSRegistry, in string) string

func TSProtoFieldToJson

func TSProtoFieldToJson(field *protogen.Field) func(g *TSRegistry, in string) string

func TSProtoMessageToJson

func TSProtoMessageToJson(msgTyp *protogen.Message) func(g *TSRegistry, in string) string

func TSProtoScalarToJson

func TSProtoScalarToJson() func(g *TSRegistry, in string) string

func TSProtoTimestampToJson

func TSProtoTimestampToJson() func(g *TSRegistry, in string) string

func TSProto_EnumToJSONFuncName

func TSProto_EnumToJSONFuncName(g *TSRegistry, enum protoreflect.EnumDescriptor) string

Types

type TSIdent

type TSIdent struct {
	TSModule
	Name string
}

func TSIdent_TSProto_Message

func TSIdent_TSProto_Message(msg *protogen.Message) TSIdent

type TSModule

type TSModule struct {
	ModuleName string
	Path       string // path relative to the generate root, or the absolute path
	Relative   bool   // whether the path is relative to the current file
}

func TSModule_TSProto

func TSModule_TSProto(file protoreflect.FileDescriptor) TSModule

func (TSModule) Ident

func (m TSModule) Ident(name string) TSIdent

type TSOption

type TSOption struct {

	// if TSProto `snakeToCamel` flags contains `key`
	TSProto_KeySnakeToCamel bool
	// if server marshal options has MarshalUseProtoNames set to true
	MarshalUseProtoNames bool
}

type TSRegistry

type TSRegistry struct {
	GenOpts      pluginutils.GenerateOptions
	ImportIdents map[string][]TSIdent // map<module_path, TSIdent>
	// contains filtered or unexported fields
}

func NewTSRegistry

func NewTSRegistry(opts pluginutils.GenerateOptions) *TSRegistry

func (*TSRegistry) Apply

func (g *TSRegistry) Apply(w io.Writer) error

func (*TSRegistry) ImportSegments

func (g *TSRegistry) ImportSegments() string

func (*TSRegistry) P

func (g *TSRegistry) P(v ...any)

func (*TSRegistry) PComment

func (opt *TSRegistry) PComment(comments ...string)

PComment allows multiple lines string as comment.

func (*TSRegistry) PCommentf

func (opt *TSRegistry) PCommentf(format string, args ...interface{})

PCommentf allows formatted string as comment.

func (*TSRegistry) PTmpl

func (opt *TSRegistry) PTmpl(tmpl *template.Template, data interface{}, funcs ...template.FuncMap)

func (*TSRegistry) PTmplStr

func (opt *TSRegistry) PTmplStr(tmpl string, data interface{}, funcs ...template.FuncMap)

func (*TSRegistry) Pf

func (opt *TSRegistry) Pf(format string, v ...any)

Pf is same as P, but with formatted string.

func (*TSRegistry) QualifiedTSIdent

func (r *TSRegistry) QualifiedTSIdent(ident TSIdent) string

func (*TSRegistry) ServiceFmap

func (r *TSRegistry) ServiceFmap() template.FuncMap

ServiceTemplate gets the template for the primary typescript file.

func (*TSRegistry) TsType

func (r *TSRegistry) TsType(def *protogen.Message, location protogen.Location) string

location: the location of the field or method that references the type

func (*TSRegistry) Write

func (g *TSRegistry) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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