From 96f6bd8eb742b860ff4bd03cc37ce7852ff16703 Mon Sep 17 00:00:00 2001 From: Safeer Jiwan Date: Mon, 12 Aug 2024 12:11:36 -0700 Subject: [PATCH 1/3] fix!: require lowerCamel topic names instead of lower_snake --- backend/controller/cronjobs/sql/db.go | 2 +- backend/controller/cronjobs/sql/models.go | 2 +- backend/controller/cronjobs/sql/querier.go | 2 +- backend/controller/cronjobs/sql/queries.sql.go | 2 +- .../controller/pubsub/testdata/go/publisher/publisher.go | 4 ++-- backend/controller/sql/db.go | 2 +- backend/controller/sql/models.go | 2 +- backend/controller/sql/querier.go | 2 +- backend/controller/sql/queries.sql.go | 2 +- common/configuration/sql/db.go | 2 +- common/configuration/sql/models.go | 2 +- common/configuration/sql/querier.go | 2 +- common/configuration/sql/queries.sql.go | 2 +- .../go/modules/{{ .Module.Name }}/external_module.go.tmpl | 2 +- go-runtime/schema/schema_fuzz_test.go | 2 +- go-runtime/schema/schema_test.go | 8 ++++---- go-runtime/schema/testdata/pubsub/pubsub.go | 4 ++-- go-runtime/schema/topic/analyzer.go | 6 +++--- 18 files changed, 25 insertions(+), 25 deletions(-) diff --git a/backend/controller/cronjobs/sql/db.go b/backend/controller/cronjobs/sql/db.go index 8a1e45d05..0e0973111 100644 --- a/backend/controller/cronjobs/sql/db.go +++ b/backend/controller/cronjobs/sql/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/backend/controller/cronjobs/sql/models.go b/backend/controller/cronjobs/sql/models.go index c5bddc7eb..5b5c1c76e 100644 --- a/backend/controller/cronjobs/sql/models.go +++ b/backend/controller/cronjobs/sql/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/backend/controller/cronjobs/sql/querier.go b/backend/controller/cronjobs/sql/querier.go index 319aa22a6..2bfa01098 100644 --- a/backend/controller/cronjobs/sql/querier.go +++ b/backend/controller/cronjobs/sql/querier.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/backend/controller/cronjobs/sql/queries.sql.go b/backend/controller/cronjobs/sql/queries.sql.go index fe741663d..1064924f5 100644 --- a/backend/controller/cronjobs/sql/queries.sql.go +++ b/backend/controller/cronjobs/sql/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: queries.sql package sql diff --git a/backend/controller/pubsub/testdata/go/publisher/publisher.go b/backend/controller/pubsub/testdata/go/publisher/publisher.go index 38af05f98..e74ecdf19 100644 --- a/backend/controller/pubsub/testdata/go/publisher/publisher.go +++ b/backend/controller/pubsub/testdata/go/publisher/publisher.go @@ -9,7 +9,7 @@ import ( ) //ftl:export -var TestTopic = ftl.Topic[PubSubEvent]("test_topic") +var TestTopic = ftl.Topic[PubSubEvent]("testTopic") type PubSubEvent struct { Time time.Time @@ -38,7 +38,7 @@ func PublishOne(ctx context.Context) error { } //ftl:export -var Topic2 = ftl.Topic[PubSubEvent]("topic_2") +var Topic2 = ftl.Topic[PubSubEvent]("topic2") //ftl:verb func PublishOneToTopic2(ctx context.Context) error { diff --git a/backend/controller/sql/db.go b/backend/controller/sql/db.go index 8a1e45d05..0e0973111 100644 --- a/backend/controller/sql/db.go +++ b/backend/controller/sql/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/backend/controller/sql/models.go b/backend/controller/sql/models.go index c5bddc7eb..5b5c1c76e 100644 --- a/backend/controller/sql/models.go +++ b/backend/controller/sql/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/backend/controller/sql/querier.go b/backend/controller/sql/querier.go index f34f4c44e..42fc740ff 100644 --- a/backend/controller/sql/querier.go +++ b/backend/controller/sql/querier.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/backend/controller/sql/queries.sql.go b/backend/controller/sql/queries.sql.go index 224402327..3ab857107 100644 --- a/backend/controller/sql/queries.sql.go +++ b/backend/controller/sql/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: queries.sql package sql diff --git a/common/configuration/sql/db.go b/common/configuration/sql/db.go index 8a1e45d05..0e0973111 100644 --- a/common/configuration/sql/db.go +++ b/common/configuration/sql/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/common/configuration/sql/models.go b/common/configuration/sql/models.go index c5bddc7eb..5b5c1c76e 100644 --- a/common/configuration/sql/models.go +++ b/common/configuration/sql/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/common/configuration/sql/querier.go b/common/configuration/sql/querier.go index b3e7b2224..ac45674c2 100644 --- a/common/configuration/sql/querier.go +++ b/common/configuration/sql/querier.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package sql diff --git a/common/configuration/sql/queries.sql.go b/common/configuration/sql/queries.sql.go index b20dc48fc..51c86f611 100644 --- a/common/configuration/sql/queries.sql.go +++ b/common/configuration/sql/queries.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: queries.sql package sql diff --git a/go-runtime/compile/external-module-template/.ftl/go/modules/{{ .Module.Name }}/external_module.go.tmpl b/go-runtime/compile/external-module-template/.ftl/go/modules/{{ .Module.Name }}/external_module.go.tmpl index 7288d73a1..bff5bbb2f 100644 --- a/go-runtime/compile/external-module-template/.ftl/go/modules/{{ .Module.Name }}/external_module.go.tmpl +++ b/go-runtime/compile/external-module-template/.ftl/go/modules/{{ .Module.Name }}/external_module.go.tmpl @@ -23,7 +23,7 @@ var _ = context.Background // {{- end}} {{- if is "Topic" .}} -var {{.Name|strippedCamel}} = ftl.Topic[{{type $.Module .Event}}]("{{.Name}}") +var {{.Name|title}} = ftl.Topic[{{type $.Module .Event}}]("{{.Name}}") {{- else if and (is "Enum" .) .IsValueEnum}} {{- $enumName := .Name}} //ftl:enum diff --git a/go-runtime/schema/schema_fuzz_test.go b/go-runtime/schema/schema_fuzz_test.go index ff504be41..e2a95327f 100644 --- a/go-runtime/schema/schema_fuzz_test.go +++ b/go-runtime/schema/schema_fuzz_test.go @@ -192,7 +192,7 @@ func (ExportedVariant) exportedTag() {} var Topic = ftl.Topic[` + symbol + `]("topic") //ftl:export -var ExportedTopic = ftl.Topic[` + symbol + `]("exported_topic") +var ExportedTopic = ftl.Topic[` + symbol + `]("exportedTopic") var _ = ftl.Subscription(Topic, "subscription") diff --git a/go-runtime/schema/schema_test.go b/go-runtime/schema/schema_test.go index 6e33bdaa9..48d59a95e 100644 --- a/go-runtime/schema/schema_test.go +++ b/go-runtime/schema/schema_test.go @@ -434,10 +434,10 @@ func TestExtractModulePubSub(t *testing.T) { actual := schema.Normalise(r.Module) expected := `module pubsub { topic payins pubsub.PayinEvent - // public_broadcast is a topic that broadcasts payin events to the public. + // publicBroadcast is a topic that broadcasts payin events to the public. // out of order with subscription registration to test ordering doesn't matter. - export topic public_broadcast pubsub.PayinEvent - subscription broadcastSubscription pubsub.public_broadcast + export topic publicBroadcast pubsub.PayinEvent + subscription broadcastSubscription pubsub.publicBroadcast subscription paymentProcessing pubsub.payins export data PayinEvent { @@ -469,7 +469,7 @@ func TestExtractModuleSubscriber(t *testing.T) { assert.Equal(t, nil, r.Errors, "expected no schema errors") actual := schema.Normalise(r.Module) expected := `module subscriber { - subscription subscriptionToExternalTopic pubsub.public_broadcast + subscription subscriptionToExternalTopic pubsub.publicBroadcast verb consumesSubscriptionFromExternalTopic(pubsub.PayinEvent) Unit +subscribe subscriptionToExternalTopic diff --git a/go-runtime/schema/testdata/pubsub/pubsub.go b/go-runtime/schema/testdata/pubsub/pubsub.go index 2a729f402..d2775b4d2 100644 --- a/go-runtime/schema/testdata/pubsub/pubsub.go +++ b/go-runtime/schema/testdata/pubsub/pubsub.go @@ -32,11 +32,11 @@ var Payins = ftl.Topic[PayinEvent]("payins") var _ = ftl.Subscription(PublicBroadcast, "broadcastSubscription") -// public_broadcast is a topic that broadcasts payin events to the public. +// publicBroadcast is a topic that broadcasts payin events to the public. // out of order with subscription registration to test ordering doesn't matter. // //ftl:export -var PublicBroadcast = ftl.Topic[PayinEvent]("public_broadcast") +var PublicBroadcast = ftl.Topic[PayinEvent]("publicBroadcast") //ftl:verb export func Broadcast(ctx context.Context) error { diff --git a/go-runtime/schema/topic/analyzer.go b/go-runtime/schema/topic/analyzer.go index ef87d9db1..aa6303635 100644 --- a/go-runtime/schema/topic/analyzer.go +++ b/go-runtime/schema/topic/analyzer.go @@ -19,7 +19,7 @@ const ( // Extractor extracts topics. var Extractor = common.NewCallDeclExtractor[*schema.Topic]("topic", Extract, ftlTopicFuncPath) -// expects: var NameLiteral = ftl.Topic[EventType]("name_literal") +// Extract expects: var NameLiteral = ftl.Topic[EventType]("nameLiteral") func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr *ast.CallExpr, callPath string) optional.Option[*schema.Topic] { indexExpr, ok := callExpr.Fun.(*ast.IndexExpr) @@ -34,7 +34,7 @@ func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr } topicName := common.ExtractStringLiteralArg(pass, callExpr, 0) - expTopicName := strcase.ToLowerSnake(topicName) + expTopicName := strcase.ToLowerCamel(strcase.ToUpperStrippedCamel(topicName)) if topicName != expTopicName { common.Errorf(pass, node, "unsupported topic name %q, did you mean to use %q?", topicName, expTopicName) return optional.None[*schema.Topic]() @@ -43,7 +43,7 @@ func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr if len(node.Specs) > 0 { if t, ok := node.Specs[0].(*ast.ValueSpec); ok { varName := t.Names[0].Name - expVarName := strcase.ToUpperStrippedCamel(topicName) + expVarName := strcase.ToUpperCamel(topicName) if varName != expVarName { common.Errorf(pass, node, "unexpected topic variable name %q, did you mean %q?", varName, expVarName) return optional.None[*schema.Topic]() From 1693fe1ed56ec2ce735a2265fef0fb427a92c8b5 Mon Sep 17 00:00:00 2001 From: Safeer Jiwan Date: Tue, 13 Aug 2024 09:17:45 -0700 Subject: [PATCH 2/3] generate lowerCamel instead of lower_snake in subscription analyzer --- go-runtime/schema/subscription/analyzer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-runtime/schema/subscription/analyzer.go b/go-runtime/schema/subscription/analyzer.go index ec5c4617e..d4c4472be 100644 --- a/go-runtime/schema/subscription/analyzer.go +++ b/go-runtime/schema/subscription/analyzer.go @@ -63,7 +63,7 @@ func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr common.Errorf(pass, callExpr, "subscription registration must have a topic") return optional.None[*schema.Subscription]() } - name := strcase.ToLowerSnake(varName) + name := strcase.ToLowerCamel(varName) topicRef = &schema.Ref{ Module: moduleIdent.Name, Name: name, From 9931c1e3e46ee5769dd8e8e2279692b4c4bda390 Mon Sep 17 00:00:00 2001 From: Safeer Jiwan Date: Tue, 13 Aug 2024 09:30:22 -0700 Subject: [PATCH 3/3] fix schema fuzz test --- go-runtime/schema/schema_fuzz_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-runtime/schema/schema_fuzz_test.go b/go-runtime/schema/schema_fuzz_test.go index e2a95327f..7283d5aac 100644 --- a/go-runtime/schema/schema_fuzz_test.go +++ b/go-runtime/schema/schema_fuzz_test.go @@ -334,7 +334,7 @@ module test { database postgres testDb - export topic exported_topic {{.TypeName}} + export topic exportedTopic {{.TypeName}} topic topic {{.TypeName}} subscription subscription test.topic