tsutils

package
v1.0.29 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Definition_ProtobufES = "protobuf-es"
	Definition_TSProto    = "ts-proto"
)

Variables

This section is empty.

Functions

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.

Types

type Definition added in v1.0.26

type Definition interface {
	TSModule(file protoreflect.FileDescriptor) TSModule
	TSIdentMsg(msg *protogen.Message) TSIdent
	GetFieldSyntax(opt *TSOption, rootMsg *protogen.Message) func(rootVar, path string) string // text_name format path
	JsonFieldPath(opt *TSOption, rootMsg *protogen.Message) func(path string) string           // text_name format path to json_name format path
	MsgScalarable(msg *protogen.Message) bool                                                  // if the message type can be into json scalar
	MsgFromPartial(msg *protogen.Message) func(g *TSRegistry, in string) string
	MsgFromJson(msg *protogen.Message) func(g *TSRegistry, in string) string
	FieldToJson(field *protogen.Field) func(g *TSRegistry, in string) string
	// contains filtered or unexported methods
}

func DefinitionFromOpts added in v1.0.26

func DefinitionFromOpts(opts TSOption) Definition

type ProtobufESDefinition added in v1.0.26

type ProtobufESDefinition struct{}

func (ProtobufESDefinition) EnumToJson added in v1.0.26

func (d ProtobufESDefinition) EnumToJson(enum *protogen.Enum) func(g *TSRegistry, in string) string

func (ProtobufESDefinition) FieldToJson added in v1.0.26

func (d ProtobufESDefinition) FieldToJson(field *protogen.Field) func(g *TSRegistry, in string) string

func (ProtobufESDefinition) GetFieldSyntax added in v1.0.26

func (d ProtobufESDefinition) GetFieldSyntax(opt *TSOption, rootMsg *protogen.Message) func(rootVar, path string) string

func (ProtobufESDefinition) JsonFieldPath added in v1.0.26

func (d ProtobufESDefinition) JsonFieldPath(opt *TSOption, rootMsg *protogen.Message) func(path string) string

func (ProtobufESDefinition) MessageToJson added in v1.0.26

func (d ProtobufESDefinition) MessageToJson(msg *protogen.Message) func(g *TSRegistry, in string) string

func (ProtobufESDefinition) MsgFromJson added in v1.0.26

func (d ProtobufESDefinition) MsgFromJson(msg *protogen.Message) func(g *TSRegistry, in string) string

func (ProtobufESDefinition) MsgFromPartial added in v1.0.26

func (d ProtobufESDefinition) MsgFromPartial(msg *protogen.Message) func(g *TSRegistry, in string) string

func (ProtobufESDefinition) MsgScalarable added in v1.0.26

func (d ProtobufESDefinition) MsgScalarable(msg *protogen.Message) bool

func (ProtobufESDefinition) ScalarToJson added in v1.0.26

func (d ProtobufESDefinition) ScalarToJson() func(g *TSRegistry, in string) string

func (ProtobufESDefinition) TSIdentMsg added in v1.0.26

func (d ProtobufESDefinition) TSIdentMsg(msg *protogen.Message) TSIdent

func (ProtobufESDefinition) TSModule added in v1.0.26

type TSIdent

type TSIdent struct {
	TSModule
	Name string
}

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) Ident

func (m TSModule) Ident(name string) TSIdent

type TSOption

type TSOption struct {

	// use ts-proto or protobuf-es to generate typescript code
	TypeDefinition string
	// if TSProto `snakeToCamel` flags contains `key`
	TSProto_KeySnakeToCamel bool
	// if server marshal options has MarshalUseProtoNames set to true
	MarshalUseProtoNames bool
}

type TSProtoDefinition added in v1.0.26

type TSProtoDefinition struct{}

func (TSProtoDefinition) EnumToJson added in v1.0.26

func (d TSProtoDefinition) EnumToJson(enumTyp *protogen.Enum) func(g *TSRegistry, in string) string

func (TSProtoDefinition) FieldToJson added in v1.0.26

func (d TSProtoDefinition) FieldToJson(field *protogen.Field) func(g *TSRegistry, in string) string

func (TSProtoDefinition) GetFieldSyntax added in v1.0.26

func (d TSProtoDefinition) GetFieldSyntax(opt *TSOption, rootMsg *protogen.Message) func(rootVar string, path string) string

func (TSProtoDefinition) JsonFieldPath added in v1.0.26

func (d TSProtoDefinition) JsonFieldPath(opt *TSOption, rootMsg *protogen.Message) func(path string) string

func (TSProtoDefinition) MessageToJson added in v1.0.26

func (d TSProtoDefinition) MessageToJson(msgTyp *protogen.Message) func(g *TSRegistry, in string) string

func (TSProtoDefinition) MsgFromJson added in v1.0.26

func (d TSProtoDefinition) MsgFromJson(msg *protogen.Message) func(g *TSRegistry, in string) string

func (TSProtoDefinition) MsgFromPartial added in v1.0.26

func (d TSProtoDefinition) MsgFromPartial(msg *protogen.Message) func(g *TSRegistry, in string) string

func (TSProtoDefinition) MsgScalarable added in v1.0.26

func (d TSProtoDefinition) MsgScalarable(msg *protogen.Message) bool

func (TSProtoDefinition) ScalarToJson added in v1.0.26

func (d TSProtoDefinition) ScalarToJson() func(g *TSRegistry, in string) string

func (TSProtoDefinition) TSIdentMsg added in v1.0.26

func (d TSProtoDefinition) TSIdentMsg(msg *protogen.Message) TSIdent

func (TSProtoDefinition) TSModule added in v1.0.26

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) 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