Documentation ¶
Index ¶
- Constants
- Variables
- func Enum(vals map[string]int32, opts ...EnumOption) *enum
- func Field(num int, options ...FieldOption) schema.Annotation
- func Generate(g *gen.Graph) error
- func Hook() gen.Hookdeprecated
- func Message(opts ...MessageOption) schema.Annotation
- func NormalizeEnumIdentifier(s string) string
- func Service(opts ...ServiceOption) schema.Annotation
- func Skip() schema.Annotation
- func SkipGen() schema.Annotation
- type Adapter
- func (a *Adapter) AllFileDescriptors() map[string]*desc.FileDescriptor
- func (a *Adapter) FieldMap(schemaName string) (FieldMap, error)
- func (a *Adapter) GetFileDescriptor(schemaName string) (*desc.FileDescriptor, error)
- func (a *Adapter) GetMessageDescriptor(schemaName string) (*desc.MessageDescriptor, error)
- type EnumOption
- type Extension
- type ExtensionOption
- type FieldMap
- type FieldMappingDescriptor
- type FieldOption
- type MessageOption
- type Method
- type ServiceOption
Constants ¶
const ( DefaultProtoPackageName = "entpb" IDFieldNumber = 1 )
const ( ServiceAnnotation = "ProtoService" // MaxPageSize is the maximum page size that can be returned by a List call. Requesting page sizes larger than // this value will return, at most, MaxPageSize entries. MaxPageSize = 1000 // MaxBatchCreateSize is the maximum number of entries that can be created by a single BatchCreate call. Requests // exceeding this batch size will return an error. MaxBatchCreateSize = 1000 // MethodCreate generates a Create gRPC service method for the entproto.Service. MethodCreate Method = 1 << iota // MethodGet generates a Get gRPC service method for the entproto.Service. MethodGet // MethodUpdate generates an Update gRPC service method for the entproto.Service. MethodUpdate // MethodDelete generates a Delete gRPC service method for the entproto.Service. MethodDelete // MethodList generates a List gRPC service method for the entproto.Service. MethodList // MethodBatchCreate generates a Batch Create gRPC service method for the entproto.Service. MethodBatchCreate // MethodAll generates all service methods for the entproto.Service. This is the same behavior as not including entproto.Methods. MethodAll = MethodCreate | MethodGet | MethodUpdate | MethodDelete | MethodList | MethodBatchCreate )
const (
EnumAnnotation = "ProtoEnum"
)
const FieldAnnotation = "ProtoField"
const MessageAnnotation = "ProtoMessage"
const SkipAnnotation = "ProtoSkip"
Variables ¶
var (
ErrEnumFieldsNotAnnotated = errors.New("entproto: all Enum options must be covered with an entproto.Enum annotation")
)
var (
ErrSchemaSkipped = errors.New("entproto: schema not annotated with Generate=true")
)
Functions ¶
func Enum ¶
func Enum(vals map[string]int32, opts ...EnumOption) *enum
Enum configures the mapping between the ent Enum field and a protobuf Enum.
func Field ¶
func Field(num int, options ...FieldOption) schema.Annotation
func Generate ¶
Generate takes a *gen.Graph and creates .proto files. Next to each .proto file, Generate creates a generate.go file containing a //go:generate directive to invoke protoc and compile Go code from the protobuf definitions. If generate.go already exists next to the .proto file, this step is skipped.
func Message ¶
func Message(opts ...MessageOption) schema.Annotation
Message annotates an ent.Schema to specify that protobuf message generation is required for it.
func NormalizeEnumIdentifier ¶
NormalizeEnumIdentifier normalizes the identifier of an enum pbfield to match the Proto Style Guide.
func Service ¶
func Service(opts ...ServiceOption) schema.Annotation
Service annotates an ent.Schema to specify that protobuf service generation is required for it.
func Skip ¶
func Skip() schema.Annotation
Skip annotates an ent.Schema to specify that this field will be skipped during .proto generation.
func SkipGen ¶
func SkipGen() schema.Annotation
SkipGen annotates an ent.Schema to specify that protobuf message generation is not required for it. This is useful in cases where a schema ent.Mixin sets Generated to true and you want to specifically set it to false for this schema.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter facilitates the transformation of ent gen.Type to desc.FileDescriptors
func LoadAdapter ¶
LoadAdapter takes a *gen.Graph and parses it into protobuf file descriptors
func (*Adapter) AllFileDescriptors ¶
func (a *Adapter) AllFileDescriptors() map[string]*desc.FileDescriptor
AllFileDescriptors returns a file descriptor per proto package for each package that contains a successfully parsed ent.Schema
func (*Adapter) FieldMap ¶
FieldMap returns a FieldMap containing descriptors of all of the mappings between the ent schema field and the protobuf message's field descriptors.
func (*Adapter) GetFileDescriptor ¶
func (a *Adapter) GetFileDescriptor(schemaName string) (*desc.FileDescriptor, error)
GetFileDescriptor returns the proto file descriptor containing the transformed proto message descriptor for `schemaName` along with any other messages in the same protobuf package.
func (*Adapter) GetMessageDescriptor ¶
func (a *Adapter) GetMessageDescriptor(schemaName string) (*desc.MessageDescriptor, error)
GetMessageDescriptor retrieves the protobuf message descriptor for `schemaName`, if an error was returned while trying to parse that error they are returned
type EnumOption ¶
type EnumOption func(*enum)
func OmitFieldPrefix ¶
func OmitFieldPrefix() EnumOption
OmitFieldPrefix configures the Enum to omit the field name prefix from the enum labels on the generated protobuf message. Used for backwards compatibility with earlier versions of entproto where the field name wasn't prepended to the enum labels.
type Extension ¶
type Extension struct { entc.DefaultExtension // contains filtered or unexported fields }
Extension is an entc.Extension that generates .proto files from an ent schema. To use within an entc.go file:
func main() { if err := entc.Generate("./schema", &gen.Config{}, entc.Extensions( entproto.NewExtension(), ), ); err != nil { log.Fatal("running ent codegen:", err) } }
func NewExtension ¶
func NewExtension(opts ...ExtensionOption) (*Extension, error)
NewExtension returns a new Extension configured by opts.
type ExtensionOption ¶
type ExtensionOption func(*Extension)
ExtensionOption is an option for the entproto extension.
func WithProtoDir ¶
func WithProtoDir(dir string) ExtensionOption
WithProtoDir sets the directory where the generated .proto files will be written.
type FieldMap ¶
type FieldMap map[string]*FieldMappingDescriptor
FieldMap contains a mapping between the field's name in the ent schema and a FieldMappingDescriptor.
func (FieldMap) Edges ¶
func (m FieldMap) Edges() []*FieldMappingDescriptor
Edges returns the FieldMappingDescriptor for all of the edge fields of the schema. Items are sorted alphabetically on pb field name.
func (FieldMap) Enums ¶
func (m FieldMap) Enums() []*FieldMappingDescriptor
func (FieldMap) Fields ¶
func (m FieldMap) Fields() []*FieldMappingDescriptor
Fields returns the FieldMappingDescriptor for all of the fields of the schema. Items are sorted alphabetically on pb field name.
func (FieldMap) ID ¶
func (m FieldMap) ID() *FieldMappingDescriptor
ID returns the FieldMappingDescriptor for the ID field of the schema.
type FieldMappingDescriptor ¶
type FieldMappingDescriptor struct { EntField *gen.Field EntEdge *gen.Edge PbFieldDescriptor *desc.FieldDescriptor IsEdgeField bool IsIDField bool IsEnumField bool ReferencedPbType *desc.MessageDescriptor }
FieldMappingDescriptor describes the mapping from a protobuf field descriptor to an ent Schema field
func (*FieldMappingDescriptor) EdgeIDPbStructField ¶
func (d *FieldMappingDescriptor) EdgeIDPbStructField() string
EdgeIDPbStructField returns the name for the id field of the entity this edge refers to.
func (*FieldMappingDescriptor) EdgeIDPbStructFieldDesc ¶
func (d *FieldMappingDescriptor) EdgeIDPbStructFieldDesc() *desc.FieldDescriptor
EdgeIDPbStructFieldDesc returns the protobuf field descriptor for the id field of the entity this edge refers to.
func (*FieldMappingDescriptor) PbStructField ¶
func (d *FieldMappingDescriptor) PbStructField() string
PbStructField returns the protobuf field descriptor of this field.
type FieldOption ¶
type FieldOption func(*pbfield)
func Type ¶
func Type(typ descriptorpb.FieldDescriptorProto_Type) FieldOption
Type overrides the default mapping between ent types and protobuf types. Example:
field.Uint8("custom_pb"). Annotations( entproto.Field(2, entproto.Type(descriptorpb.FieldDescriptorProto_TYPE_UINT64), ), )
func TypeName ¶
func TypeName(n string) FieldOption
TypeName sets the pb descriptors type name, needed if the Type attribute is TYPE_ENUM or TYPE_MESSAGE.
type MessageOption ¶
type MessageOption func(msg *message)
MessageOption configures the entproto.Message annotation
func PackageName ¶
func PackageName(pkg string) MessageOption
PackageName modifies the generated message's protobuf package name
type ServiceOption ¶
type ServiceOption func(svc *service)
ServiceOption configures the entproto.Service annotation.
func Methods ¶
func Methods(methods Method) ServiceOption
Methods specifies the gRPC service methods to generate for the entproto.Service.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
internal
|
|
altdir/ent/v1/api/entpb
Code generated by protoc-gen-entgrpc.
|
Code generated by protoc-gen-entgrpc. |
todo/ent/proto/entpb
Code generated by protoc-gen-entgrpc.
|
Code generated by protoc-gen-entgrpc. |