Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 47 additions & 49 deletions backend/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

adminpb "github.com/block/ftl/backend/protos/xyz/block/ftl/admin/v1"
"github.com/block/ftl/common/schema"
"github.com/block/ftl/common/schema/builder"
"github.com/block/ftl/internal/configuration"
"github.com/block/ftl/internal/configuration/manager"
"github.com/block/ftl/internal/configuration/providers"
Expand Down Expand Up @@ -141,58 +142,55 @@ func testAdminSecrets(
}
}

var testSchema = schema.MustValidate(&schema.Schema{
Realms: []*schema.Realm{{
Modules: []*schema.Module{
{
Name: "batmobile",
Comments: []string{"A batmobile comment"},
Decls: []schema.Decl{
&schema.Secret{
Comments: []string{"top secret"},
Name: "owner",
Type: &schema.String{},
},
&schema.Secret{
Comments: []string{"ultra secret"},
Name: "horsepower",
Type: &schema.Int{},
},
&schema.Config{
Comments: []string{"car color"},
Name: "color",
Type: &schema.Ref{Module: "batmobile", Name: "Color"},
},
&schema.Config{
Comments: []string{"car capacity"},
Name: "capacity",
Type: &schema.Ref{Module: "batmobile", Name: "Capacity"},
},
&schema.Enum{
Comments: []string{"Car colors"},
Name: "Color",
Type: &schema.String{},
Variants: []*schema.EnumVariant{
{Name: "Black", Value: &schema.StringValue{Value: "Black"}},
{Name: "Blue", Value: &schema.StringValue{Value: "Blue"}},
{Name: "Green", Value: &schema.StringValue{Value: "Green"}},
},
var testSchema = builder.Schema(
builder.Realm("test").Module(
builder.Module("batmobile").
Comment("A batmobile comment").
Decl(
&schema.Secret{
Comments: []string{"top secret"},
Name: "owner",
Type: &schema.String{},
},
&schema.Secret{
Comments: []string{"ultra secret"},
Name: "horsepower",
Type: &schema.Int{},
},
&schema.Config{
Comments: []string{"car color"},
Name: "color",
Type: &schema.Ref{Module: "batmobile", Name: "Color"},
},
&schema.Config{
Comments: []string{"car capacity"},
Name: "capacity",
Type: &schema.Ref{Module: "batmobile", Name: "Capacity"},
},
&schema.Enum{
Comments: []string{"Car colors"},
Name: "Color",
Type: &schema.String{},
Variants: []*schema.EnumVariant{
{Name: "Black", Value: &schema.StringValue{Value: "Black"}},
{Name: "Blue", Value: &schema.StringValue{Value: "Blue"}},
{Name: "Green", Value: &schema.StringValue{Value: "Green"}},
},
&schema.Enum{
Comments: []string{"Car capacities"},
Name: "Capacity",
Type: &schema.Int{},
Variants: []*schema.EnumVariant{
{Name: "One", Value: &schema.IntValue{Value: int(1)}},
{Name: "Two", Value: &schema.IntValue{Value: int(2)}},
{Name: "Four", Value: &schema.IntValue{Value: int(4)}},
},
},
&schema.Enum{
Comments: []string{"Car capacities"},
Name: "Capacity",
Type: &schema.Int{},
Variants: []*schema.EnumVariant{
{Name: "One", Value: &schema.IntValue{Value: int(1)}},
{Name: "Two", Value: &schema.IntValue{Value: int(2)}},
{Name: "Four", Value: &schema.IntValue{Value: int(4)}},
},
},
},
}},
},
})
).
MustBuild(),
).MustBuild(),
).MustBuild()

type mockSchemaRetriever struct {
}
Expand Down
16 changes: 9 additions & 7 deletions backend/admin/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/alecthomas/types/either"

"github.com/block/ftl/common/schema"
"github.com/block/ftl/common/schema/builder"
cf "github.com/block/ftl/internal/configuration"
"github.com/block/ftl/internal/configuration/manager"
"github.com/block/ftl/internal/projectconfig"
Expand Down Expand Up @@ -46,17 +47,14 @@ func (s *diskSchemaRetriever) GetSchema(ctx context.Context) (*schema.Schema, er
moduleSchemas <- either.LeftOf[error](module)
}()
}
realm := &schema.Realm{
Name: s.projConfig.Name,
Modules: []*schema.Module{},
}
sch := &schema.Schema{Realms: []*schema.Realm{realm}}
sch := builder.Schema()
realmBuilder := builder.Realm(s.projConfig.Name)
errs := []error{}
for range len(modules) {
result := <-moduleSchemas
switch result := result.(type) {
case either.Left[*schema.Module, error]:
realm.Upsert(result.Get())
realmBuilder = realmBuilder.Module(result.Get())
case either.Right[*schema.Module, error]:
errs = append(errs, result.Get())
default:
Expand All @@ -66,5 +64,9 @@ func (s *diskSchemaRetriever) GetSchema(ctx context.Context) (*schema.Schema, er
if len(errs) > 0 {
return nil, errors.WithStack(errors.Join(errs...))
}
return sch, nil
realm, err := realmBuilder.Build()
if err != nil {
return nil, errors.WithStack(err)
}
return errors.WithStack2(sch.Realm(realm).Build())
}
3 changes: 2 additions & 1 deletion backend/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/block/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
schemapb "github.com/block/ftl/common/protos/xyz/block/ftl/schema/v1"
"github.com/block/ftl/common/schema"
"github.com/block/ftl/common/schema/builder"
"github.com/block/ftl/common/sha256"
islices "github.com/block/ftl/common/slices"
"github.com/block/ftl/internal/channels"
Expand Down Expand Up @@ -75,7 +76,7 @@ type streamSchemaRetriever struct {

func (c *streamSchemaRetriever) GetSchema(ctx context.Context) (*schema.Schema, error) {
view := c.source.CanonicalView()
return &schema.Schema{Realms: view.Realms}, nil
return errors.WithStack2(builder.Schema(view.Realms...).Build())
}

// NewAdminService creates a new Service.
Expand Down
16 changes: 10 additions & 6 deletions backend/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
ftlv1 "github.com/block/ftl/backend/protos/xyz/block/ftl/v1"
schemapb "github.com/block/ftl/common/protos/xyz/block/ftl/schema/v1"
"github.com/block/ftl/common/schema"
"github.com/block/ftl/common/schema/builder"
frontend "github.com/block/ftl/frontend/console"
"github.com/block/ftl/internal/buildengine"
"github.com/block/ftl/internal/channels"
Expand Down Expand Up @@ -428,14 +429,17 @@ func (s *Service) sendStreamModulesResp(stream *connect.ServerStream[consolepb.S

realms := []*schema.Realm{}
for _, realm := range unfilteredSchema.Realms {
realms = append(realms, &schema.Realm{
External: realm.External,
Name: realm.Name,
Modules: s.filterDeployments(realm),
})
filteredRealm, err := builder.Realm(realm.Name).
External(realm.External).
Module(s.filterDeployments(realm)...).
Build()
if err != nil {
return errors.Wrap(err, "failed to build filtered realm")
}
realms = append(realms, filteredRealm)
}

sch := &schema.Schema{Realms: realms}
sch := &schema.Schema{Pos: schema.Position{}, Realms: realms}
builtin := schema.Builtins()
for _, realm := range sch.InternalRealms() {
realm.Modules = append(realm.Modules, builtin)
Expand Down
Loading
Loading