Kindsys: Replace DefForGen with kindsys.Kind (#62642)

* Kindsys: Replace DeclForGen with kindsys.Kind

DeclForGen was always unnecessary - it just wasn't obvious on initial
implementation, when we were focused on generating unique types for each
core kind. This removes it, considerably simplifying interactions with
kindsys - virtually everything now just relies on kindsys.Kind and its
derived interfaces.

* Removed unused jenny

* Rename params in jennies
This commit is contained in:
sam boyer
2023-01-31 19:40:15 -05:00
committed by GitHub
parent 0f0a53fbbb
commit 30b4205521
25 changed files with 273 additions and 543 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/grafana/codejen"
corecodegen "github.com/grafana/grafana/pkg/codegen"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/grafana/pkg/plugins/codegen"
"github.com/grafana/grafana/pkg/plugins/pfs"
)
@ -54,9 +55,9 @@ func main() {
codegen.PluginTreeListJenny(),
codegen.PluginGoTypesJenny("pkg/tsdb"),
codegen.PluginTSTypesJenny("public/app/plugins", adaptToPipeline(corecodegen.TSTypesJenny{})),
codegen.PluginDocsJenny(toDeclForGen(corecodegen.DocsJenny(
kind2pd(corecodegen.DocsJenny(
filepath.Join("docs", "sources", "developers", "kinds", "composable"),
))),
)),
)
pluginKindGen.AddPostprocessors(corecodegen.SlashHeaderMapper("public/app/plugins/gen.go"))
@ -91,11 +92,11 @@ func adaptToPipeline(j codejen.OneToOne[corecodegen.SchemaForGen]) codejen.OneTo
})
}
func toDeclForGen(j codejen.OneToOne[*corecodegen.DefForGen]) codejen.OneToOne[*pfs.PluginDecl] {
return codejen.AdaptOneToOne(j, func(pd *pfs.PluginDecl) *corecodegen.DefForGen {
kd, err := corecodegen.ForGen(pd.Lineage.Runtime(), pd.KindDecl.Some())
func kind2pd(j codejen.OneToOne[kindsys.Kind]) codejen.OneToOne[*pfs.PluginDecl] {
return codejen.AdaptOneToOne(j, func(pd *pfs.PluginDecl) kindsys.Kind {
kd, err := kindsys.BindComposable(nil, pd.KindDecl)
if err != nil {
panic("should be unreachable")
return nil
}
return kd
})