Skip to content

Commit

Permalink
chore: add artefact metadata to the module (#3658)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Dec 6, 2024
1 parent f908729 commit 2d4dcd8
Show file tree
Hide file tree
Showing 14 changed files with 1,089 additions and 817 deletions.
1,560 changes: 838 additions & 722 deletions backend/protos/xyz/block/ftl/schema/v1/schema.pb.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions backend/protos/xyz/block/ftl/schema/v1/schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ message Map {
message Metadata {
oneof value {
MetadataAlias alias = 5;
MetadataArtefact artefact = 14;
MetadataCalls calls = 1;
MetadataConfig config = 10;
MetadataCronJob cron_job = 3;
Expand All @@ -197,6 +198,13 @@ message MetadataAlias {
string alias = 3;
}

message MetadataArtefact {
optional Position pos = 1;
string path = 2;
string digest = 3;
bool executable = 4;
}

message MetadataCalls {
optional Position pos = 1;
repeated Ref calls = 2;
Expand Down Expand Up @@ -271,6 +279,7 @@ message Module {
repeated string comments = 2;
bool builtin = 3;
string name = 4;
repeated Metadata metadata = 6;
repeated Decl decls = 5;
ModuleRuntime runtime = 31634;
}
Expand Down
68 changes: 68 additions & 0 deletions frontend/console/src/protos/xyz/block/ftl/schema/v1/schema_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/schema/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (d *Data) Monomorphise(ref *Ref) (*Data, error) {
*EnumVariant, Value, *IntValue, *StringValue, *TypeValue, Symbol,
Named, *TypeAlias, *Topic, *MetadataSubscriber, *MetadataTypeMap,
*MetadataEncoding, *MetadataPublisher, *MetadataSQLMigration, *DSNDatabaseConnector, *DatabaseRuntime,
DatabaseConnector, *AWSIAMAuthDatabaseConnector, *DatabaseRuntimeConnections:
DatabaseConnector, *AWSIAMAuthDatabaseConnector, *DatabaseRuntimeConnections, *MetadataArtefact:
}
return next()
})
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func nodeToJSSchema(node Node, refs map[RefKey]*Ref) *jsonschema.Schema {
*StringValue, *IntValue, *TypeValue, *Config, *Secret, Symbol, Named,
*MetadataRetry, *Topic, *MetadataSubscriber, *MetadataTypeMap,
*MetadataEncoding, *MetadataPublisher, *MetadataSQLMigration, *DSNDatabaseConnector, *DatabaseRuntime,
*AWSIAMAuthDatabaseConnector, DatabaseConnector, *DatabaseRuntimeConnections:
*AWSIAMAuthDatabaseConnector, DatabaseConnector, *DatabaseRuntimeConnections, *MetadataArtefact:
panic(fmt.Sprintf("unsupported node type %T", node))

default:
Expand Down
38 changes: 38 additions & 0 deletions internal/schema/metadataartefact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package schema

import (
"fmt"

"google.golang.org/protobuf/reflect/protoreflect"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/schema/v1"
)

//protobuf:14
type MetadataArtefact struct {
Pos Position `parser:"" protobuf:"1,optional"`

Path string `parser:"'+' 'artefact' Whitespace @String" protobuf:"2"`
Digest string `parser:"@String" protobuf:"3"`
Executable bool `parser:"@'executable'?" protobuf:"4"`
}

var _ Metadata = (*MetadataArtefact)(nil)

func (m *MetadataArtefact) Position() Position { return m.Pos }

func (m *MetadataArtefact) String() string {
return fmt.Sprintf("+artefact %q %q %t", m.Path, m.Digest, m.Executable)
}

func (m *MetadataArtefact) ToProto() protoreflect.ProtoMessage {
return &schemapb.MetadataArtefact{
Pos: posToProto(m.Pos),
Executable: m.Executable,
Path: m.Path,
Digest: m.Digest,
}
}

func (m *MetadataArtefact) schemaChildren() []Node { return nil }
func (m *MetadataArtefact) schemaMetadata() {}
11 changes: 7 additions & 4 deletions internal/schema/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
type Module struct {
Pos Position `parser:"" protobuf:"1,optional"`

Comments []string `parser:"@Comment*" protobuf:"2"`
Builtin bool `parser:"@'builtin'?" protobuf:"3"`
Name string `parser:"'module' @Ident '{'" protobuf:"4"`
Decls []Decl `parser:"@@* '}'" protobuf:"5"`
Comments []string `parser:"@Comment*" protobuf:"2"`
Builtin bool `parser:"@'builtin'?" protobuf:"3"`
Name string `parser:"'module' @Ident '{'" protobuf:"4"`
Metadata []Metadata `parser:"@@*" protobuf:"6"`
Decls []Decl `parser:"@@* '}'" protobuf:"5"`

Runtime *ModuleRuntime `protobuf:"31634" parser:""`
}
Expand Down Expand Up @@ -235,6 +236,7 @@ func (m *Module) ToProto() proto.Message {
Comments: m.Comments,
Decls: declListToProto(m.Decls),
Runtime: runtime,
Metadata: metadataListToProto(m.Metadata),
}
}

Expand All @@ -259,6 +261,7 @@ func ModuleFromProto(s *schemapb.Module) (*Module, error) {
Comments: s.Comments,
Decls: declListToSchema(s.Decls),
Runtime: ModuleRuntimeFromProto(s.Runtime),
Metadata: metadataListToSchema(s.Metadata),
}
return module, ValidateModule(module)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
}
metadataUnion = []Metadata{&MetadataCalls{}, &MetadataConfig{}, &MetadataIngress{}, &MetadataCronJob{},
&MetadataDatabases{}, &MetadataAlias{}, &MetadataRetry{}, &MetadataSecrets{}, &MetadataSubscriber{},
&MetadataTypeMap{}, &MetadataEncoding{}, &MetadataPublisher{}, &MetadataSQLMigration{}}
&MetadataTypeMap{}, &MetadataEncoding{}, &MetadataPublisher{}, &MetadataSQLMigration{}, &MetadataArtefact{}}
ingressUnion = []IngressPathComponent{&IngressPathLiteral{}, &IngressPathParameter{}}
valueUnion = []Value{&StringValue{}, &IntValue{}, &TypeValue{}}

Expand Down
8 changes: 8 additions & 0 deletions internal/schema/protobuf_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ func metadataToSchema(s *schemapb.Metadata) Metadata {
Digest: s.SqlMigration.Digest,
}

case *schemapb.Metadata_Artefact:
return &MetadataArtefact{
Pos: PosFromProto(s.Artefact.Pos),
Executable: s.Artefact.Executable,
Path: s.Artefact.Path,
Digest: s.Artefact.Digest,
}

default:
panic(fmt.Sprintf("unhandled metadata type: %T", s))
}
Expand Down
3 changes: 3 additions & 0 deletions internal/schema/protobuf_enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func metadataListToProto(nodes []Metadata) []*schemapb.Metadata {
case *MetadataSQLMigration:
v = &schemapb.Metadata_SqlMigration{SqlMigration: n.ToProto().(*schemapb.MetadataSQLMigration)}

case *MetadataArtefact:
v = &schemapb.Metadata_Artefact{Artefact: n.ToProto().(*schemapb.MetadataArtefact)}

default:
panic(fmt.Sprintf("unhandled metadata type %T", n))
}
Expand Down
5 changes: 5 additions & 0 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ func TestParsing(t *testing.T) {
{name: "TimeEcho",
input: `
module echo {
+artefact "echo" "asf4as1fdfa2"
data EchoRequest {
name String?
}
Expand Down Expand Up @@ -346,6 +348,9 @@ func TestParsing(t *testing.T) {
expected: &Schema{
Modules: []*Module{{
Name: "echo",
Metadata: []Metadata{
&MetadataArtefact{Path: "echo", Digest: "asf4as1fdfa2", Executable: false},
},
Decls: []Decl{
&Data{Name: "EchoRequest", Fields: []*Field{{Name: "name", Type: &Optional{Type: &String{}}}}},
&Data{Name: "EchoResponse", Fields: []*Field{{Name: "message", Type: &String{}}}},
Expand Down
12 changes: 8 additions & 4 deletions internal/schema/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func ValidateModuleInSchema(schema *Schema, m optional.Option[*Module]) (*Schema
validateRetries(module, md, optional.Some(n.Request), scopes, optional.Some(schema))

case *MetadataCronJob, *MetadataCalls, *MetadataConfig, *MetadataDatabases, *MetadataAlias, *MetadataTypeMap,
*MetadataEncoding, *MetadataSecrets, *MetadataPublisher, *MetadataSQLMigration, DatabaseConnector:
*MetadataEncoding, *MetadataSecrets, *MetadataPublisher, *MetadataSQLMigration, *MetadataArtefact, DatabaseConnector:
}
}
case *Database:
Expand Down Expand Up @@ -224,7 +224,7 @@ func ValidateModuleInSchema(schema *Schema, m optional.Option[*Module]) (*Schema
Value, *IntValue, *StringValue, *TypeValue, *Config, *Secret, Symbol, Named,
*MetadataSubscriber, *Topic, *MetadataTypeMap, *MetadataEncoding, *MetadataPublisher,
*MetadataSQLMigration, *DSNDatabaseConnector, *DatabaseRuntime, DatabaseConnector,
*AWSIAMAuthDatabaseConnector, *DatabaseRuntimeConnections:
*AWSIAMAuthDatabaseConnector, *DatabaseRuntimeConnections, *MetadataArtefact:
}
return next()
})
Expand Down Expand Up @@ -367,7 +367,7 @@ func ValidateModule(module *Module) error {
*Unit, *Any, *TypeParameter, *Enum, *EnumVariant, *IntValue, *StringValue, *TypeValue,
*Config, *Secret, *MetadataSubscriber, *MetadataTypeMap, *MetadataEncoding, *MetadataPublisher,
*MetadataSQLMigration, *DSNDatabaseConnector, *DatabaseRuntime, *AWSIAMAuthDatabaseConnector,
DatabaseConnector, *DatabaseRuntimeConnections:
*MetadataArtefact, DatabaseConnector, *DatabaseRuntimeConnections:

case Named, Symbol, Type, Metadata, Value, Decl: // Union types.
}
Expand Down Expand Up @@ -467,6 +467,8 @@ func sortMetadataType(md Metadata) {
sortRefs(m.Topics)
case *MetadataSQLMigration:
return
case *MetadataArtefact:
return
}
}

Expand Down Expand Up @@ -499,6 +501,8 @@ func getMetadataSortingPriority(metadata Metadata) int {
priority = 12
case *MetadataSQLMigration:
priority = 13
case *MetadataArtefact:
priority = 14
}
return priority
}
Expand Down Expand Up @@ -697,7 +701,7 @@ func validateVerbMetadata(scopes Scopes, module *Module, n *Verb) (merr []error)
subErrs := validateVerbSubscriptions(module, n, md, scopes)
merr = append(merr, subErrs...)
case *MetadataCalls, *MetadataConfig, *MetadataDatabases, *MetadataAlias, *MetadataTypeMap, *MetadataEncoding,
*MetadataSecrets, *MetadataPublisher, *MetadataSQLMigration:
*MetadataSecrets, *MetadataPublisher, *MetadataSQLMigration, *MetadataArtefact:
}
}
return
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 2d4dcd8

Please sign in to comment.