Skip to content

Commit

Permalink
chore: make schema.posFromProto public (#2939)
Browse files Browse the repository at this point in the history
This is in preparation of language proto’s owning build errors, which
use schema.Pos
  • Loading branch information
matt2e authored Oct 1, 2024
1 parent d55777e commit 0b7e64d
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion backend/schema/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (a *Array) ToProto() proto.Message {

func arrayToSchema(s *schemapb.Array) *Array {
return &Array{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Element: TypeFromProto(s.Element),
}
}
2 changes: 1 addition & 1 deletion backend/schema/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Config) schemaSymbol() {}

func ConfigFromProto(p *schemapb.Config) *Config {
return &Config{
Pos: posFromProto(p.Pos),
Pos: PosFromProto(p.Pos),
Comments: p.Comments,
Name: p.Name,
Type: TypeFromProto(p.Type),
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (d *Data) ToProto() proto.Message {

func DataFromProto(s *schemapb.Data) *Data {
return &Data{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),

Name: s.Name,
Export: s.Export,
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (d *Database) IsExported() bool { return false }

func DatabaseFromProto(s *schemapb.Database) *Database {
return &Database{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Comments: s.Comments,
Name: s.Name,
Type: s.Type,
Expand Down
4 changes: 2 additions & 2 deletions backend/schema/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (e *Enum) IsExported() bool { return e.Export }

func EnumFromProto(s *schemapb.Enum) *Enum {
e := &Enum{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Name: s.Name,
Export: s.Export,
Comments: s.Comments,
Expand Down Expand Up @@ -145,7 +145,7 @@ func enumVariantListToSchema(e []*schemapb.EnumVariant) []*EnumVariant {

func enumVariantToSchema(v *schemapb.EnumVariant) *EnumVariant {
return &EnumVariant{
Pos: posFromProto(v.Pos),
Pos: PosFromProto(v.Pos),
Name: v.Name,
Value: valueToSchema(v.Value),
}
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (e Error) Error() string { return fmt.Sprintf("%s-%d: %s", e.Pos, e.EndColu

func errorFromProto(e *schemapb.Error) *Error {
return &Error{
Pos: posFromProto(e.Pos),
Pos: PosFromProto(e.Pos),
Msg: e.Msg,
EndColumn: int(e.EndColumn),
Level: levelFromProto(e.Level),
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func fieldListToSchema(s []*schemapb.Field) []*Field {

func fieldToSchema(s *schemapb.Field) *Field {
return &Field{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Name: s.Name,
Comments: s.Comments,
Type: TypeFromProto(s.Type),
Expand Down
4 changes: 2 additions & 2 deletions backend/schema/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type FSM struct {

func FSMFromProto(pb *schemapb.FSM) *FSM {
return &FSM{
Pos: posFromProto(pb.Pos),
Pos: PosFromProto(pb.Pos),
Name: pb.Name,
Start: slices.Map(pb.Start, RefFromProto),
Transitions: slices.Map(pb.Transitions, FSMTransitionFromProto),
Expand Down Expand Up @@ -156,7 +156,7 @@ type FSMTransition struct {

func FSMTransitionFromProto(pb *schemapb.FSMTransition) *FSMTransition {
return &FSMTransition{
Pos: posFromProto(pb.Pos),
Pos: PosFromProto(pb.Pos),
From: RefFromProto(pb.From),
To: RefFromProto(pb.To),
}
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (m *Map) ToProto() proto.Message {

func mapToSchema(s *schemapb.Map) *Map {
return &Map{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Key: TypeFromProto(s.Key),
Value: TypeFromProto(s.Value),
}
Expand Down
4 changes: 2 additions & 2 deletions backend/schema/metadataingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func ingressPathComponentListToSchema(s []*schemapb.IngressPathComponent) []Ingr
switch n := n.Value.(type) {
case *schemapb.IngressPathComponent_IngressPathLiteral:
out = append(out, &IngressPathLiteral{
Pos: posFromProto(n.IngressPathLiteral.Pos),
Pos: PosFromProto(n.IngressPathLiteral.Pos),
Text: n.IngressPathLiteral.Text,
})
case *schemapb.IngressPathComponent_IngressPathParameter:
out = append(out, &IngressPathParameter{
Pos: posFromProto(n.IngressPathParameter.Pos),
Pos: PosFromProto(n.IngressPathParameter.Pos),
Name: n.IngressPathParameter.Name,
})
}
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func ModuleFromProtoFile(filename string) (*Module, error) {
// ModuleFromProto converts a protobuf Module to a Module and validates it.
func ModuleFromProto(s *schemapb.Module) (*Module, error) {
module := &Module{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Builtin: s.Builtin,
Name: s.Name,
Comments: s.Comments,
Expand Down
44 changes: 22 additions & 22 deletions backend/schema/protobuf_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)

func posFromProto(pos *schemapb.Position) Position {
func PosFromProto(pos *schemapb.Position) Position {
if pos == nil {
return Position{}
}
Expand Down Expand Up @@ -63,27 +63,27 @@ func TypeFromProto(s *schemapb.Type) Type {
case *schemapb.Type_Ref:
return RefFromProto(s.Ref)
case *schemapb.Type_Int:
return &Int{Pos: posFromProto(s.Int.Pos)}
return &Int{Pos: PosFromProto(s.Int.Pos)}
case *schemapb.Type_Float:
return &Float{Pos: posFromProto(s.Float.Pos)}
return &Float{Pos: PosFromProto(s.Float.Pos)}
case *schemapb.Type_String_:
return &String{Pos: posFromProto(s.String_.Pos)}
return &String{Pos: PosFromProto(s.String_.Pos)}
case *schemapb.Type_Bytes:
return &Bytes{Pos: posFromProto(s.Bytes.Pos)}
return &Bytes{Pos: PosFromProto(s.Bytes.Pos)}
case *schemapb.Type_Time:
return &Time{Pos: posFromProto(s.Time.Pos)}
return &Time{Pos: PosFromProto(s.Time.Pos)}
case *schemapb.Type_Bool:
return &Bool{Pos: posFromProto(s.Bool.Pos)}
return &Bool{Pos: PosFromProto(s.Bool.Pos)}
case *schemapb.Type_Array:
return arrayToSchema(s.Array)
case *schemapb.Type_Map:
return mapToSchema(s.Map)
case *schemapb.Type_Optional:
return &Optional{Pos: posFromProto(s.Optional.Pos), Type: TypeFromProto(s.Optional.Type)}
return &Optional{Pos: PosFromProto(s.Optional.Pos), Type: TypeFromProto(s.Optional.Type)}
case *schemapb.Type_Unit:
return &Unit{Pos: posFromProto(s.Unit.Pos)}
return &Unit{Pos: PosFromProto(s.Unit.Pos)}
case *schemapb.Type_Any:
return &Any{Pos: posFromProto(s.Any.Pos)}
return &Any{Pos: PosFromProto(s.Any.Pos)}
}
panic(fmt.Sprintf("unhandled type: %T", s.Value))
}
Expand All @@ -92,17 +92,17 @@ func valueToSchema(v *schemapb.Value) Value {
switch s := v.Value.(type) {
case *schemapb.Value_IntValue:
return &IntValue{
Pos: posFromProto(s.IntValue.Pos),
Pos: PosFromProto(s.IntValue.Pos),
Value: int(s.IntValue.Value),
}
case *schemapb.Value_StringValue:
return &StringValue{
Pos: posFromProto(s.StringValue.Pos),
Pos: PosFromProto(s.StringValue.Pos),
Value: s.StringValue.GetValue(),
}
case *schemapb.Value_TypeValue:
return &TypeValue{
Pos: posFromProto(s.TypeValue.Pos),
Pos: PosFromProto(s.TypeValue.Pos),
Value: TypeFromProto(s.TypeValue.Value),
}
}
Expand All @@ -121,33 +121,33 @@ func metadataToSchema(s *schemapb.Metadata) Metadata {
switch s := s.Value.(type) {
case *schemapb.Metadata_Calls:
return &MetadataCalls{
Pos: posFromProto(s.Calls.Pos),
Pos: PosFromProto(s.Calls.Pos),
Calls: refListToSchema(s.Calls.Calls),
}

case *schemapb.Metadata_Databases:
return &MetadataDatabases{
Pos: posFromProto(s.Databases.Pos),
Pos: PosFromProto(s.Databases.Pos),
Calls: refListToSchema(s.Databases.Calls),
}

case *schemapb.Metadata_Ingress:
return &MetadataIngress{
Pos: posFromProto(s.Ingress.Pos),
Pos: PosFromProto(s.Ingress.Pos),
Type: s.Ingress.Type,
Method: s.Ingress.Method,
Path: ingressPathComponentListToSchema(s.Ingress.Path),
}

case *schemapb.Metadata_CronJob:
return &MetadataCronJob{
Pos: posFromProto(s.CronJob.Pos),
Pos: PosFromProto(s.CronJob.Pos),
Cron: s.CronJob.Cron,
}

case *schemapb.Metadata_Alias:
return &MetadataAlias{
Pos: posFromProto(s.Alias.Pos),
Pos: PosFromProto(s.Alias.Pos),
Kind: AliasKind(s.Alias.Kind),
Alias: s.Alias.Alias,
}
Expand All @@ -163,7 +163,7 @@ func metadataToSchema(s *schemapb.Metadata) Metadata {
catch = RefFromProto(s.Retry.Catch)
}
return &MetadataRetry{
Pos: posFromProto(s.Retry.Pos),
Pos: PosFromProto(s.Retry.Pos),
Count: count,
MinBackoff: s.Retry.MinBackoff,
MaxBackoff: s.Retry.MaxBackoff,
Expand All @@ -172,20 +172,20 @@ func metadataToSchema(s *schemapb.Metadata) Metadata {

case *schemapb.Metadata_Subscriber:
return &MetadataSubscriber{
Pos: posFromProto(s.Subscriber.Pos),
Pos: PosFromProto(s.Subscriber.Pos),
Name: s.Subscriber.Name,
}

case *schemapb.Metadata_TypeMap:
return &MetadataTypeMap{
Pos: posFromProto(s.TypeMap.Pos),
Pos: PosFromProto(s.TypeMap.Pos),
Runtime: s.TypeMap.Runtime,
NativeName: s.TypeMap.NativeName,
}

case *schemapb.Metadata_Encoding:
return &MetadataEncoding{
Pos: posFromProto(s.Encoding.Pos),
Pos: PosFromProto(s.Encoding.Pos),
Lenient: s.Encoding.Lenient,
}

Expand Down
2 changes: 1 addition & 1 deletion backend/schema/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (r *Ref) String() string {

func RefFromProto(s *schemapb.Ref) *Ref {
return &Ref{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Name: s.Name,
Module: s.Module,
TypeParameters: slices.Map(s.TypeParameters, TypeFromProto),
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Secret) schemaSymbol() {}

func SecretFromProto(s *schemapb.Secret) *Secret {
return &Secret{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Name: s.Name,
Comments: s.Comments,
Type: TypeFromProto(s.Type),
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *Subscription) ToProto() proto.Message {

func SubscriptionFromProto(s *schemapb.Subscription) *Subscription {
return &Subscription{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),

Name: s.Name,
Topic: RefFromProto(s.Topic),
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (t *Topic) ToProto() proto.Message {

func TopicFromProto(t *schemapb.Topic) *Topic {
return &Topic{
Pos: posFromProto(t.Pos),
Pos: PosFromProto(t.Pos),

Name: t.Name,
Export: t.Export,
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/typealias.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (t *TypeAlias) IsExported() bool { return t.Export }

func TypeAliasFromProto(s *schemapb.TypeAlias) *TypeAlias {
return &TypeAlias{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Name: s.Name,
Export: s.Export,
Comments: s.Comments,
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/typeparameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func typeParametersToSchema(s []*schemapb.TypeParameter) []*TypeParameter {
var out []*TypeParameter
for _, n := range s {
out = append(out, &TypeParameter{
Pos: posFromProto(n.Pos),
Pos: PosFromProto(n.Pos),
Name: n.Name,
})
}
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/verb.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (v *Verb) ToProto() proto.Message {

func VerbFromProto(s *schemapb.Verb) *Verb {
return &Verb{
Pos: posFromProto(s.Pos),
Pos: PosFromProto(s.Pos),
Export: s.Export,
Name: s.Name,
Comments: s.Comments,
Expand Down

0 comments on commit 0b7e64d

Please sign in to comment.