mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
kindsys: Return Decl from Kinds (#59075)
* kindsys: Return Decl from Kinds * Add funcs to extract DeclForGen from kinds
This commit is contained in:
parent
57d6adbc7c
commit
6ac43c9cb4
@ -29,6 +29,29 @@ func ForGen(rt *thema.Runtime, decl *kindsys.SomeDecl) (*DeclForGen, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RawForGen produces a [DeclForGen] from a [kindsys.Raw] kind.
|
||||||
|
//
|
||||||
|
// Useful for grafana-external code generators, which depend on the Kind
|
||||||
|
// representation in registries produced by grafana core (such as
|
||||||
|
// ["github.com/grafana/grafana/pkg/registry/corekind".NewBase]).
|
||||||
|
func RawForGen(k kindsys.Raw) *DeclForGen {
|
||||||
|
return &DeclForGen{
|
||||||
|
SomeDecl: k.Decl().Some(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// StructuredForGen produces a [DeclForGen] from a [kindsys.Structured] kind.
|
||||||
|
//
|
||||||
|
// Useful for grafana-external code generators, which depend on the Kind
|
||||||
|
// representation in registries produced by grafana core (such as
|
||||||
|
// ["github.com/grafana/grafana/pkg/registry/corekind".NewBase]).
|
||||||
|
func StructuredForGen(k kindsys.Structured) *DeclForGen {
|
||||||
|
return &DeclForGen{
|
||||||
|
SomeDecl: k.Decl().Some(),
|
||||||
|
lin: k.Lineage(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DeclForGen wraps [kindsys.SomeDecl] to provide trivial caching of
|
// DeclForGen wraps [kindsys.SomeDecl] to provide trivial caching of
|
||||||
// the lineage declared by the kind (nil for raw kinds).
|
// the lineage declared by the kind (nil for raw kinds).
|
||||||
type DeclForGen struct {
|
type DeclForGen struct {
|
||||||
|
@ -90,6 +90,7 @@ func (k *Kind) Maturity() kindsys.Maturity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO standard generated docs
|
// TODO standard generated docs
|
||||||
func (k *Kind) Meta() kindsys.CoreStructuredMeta {
|
func (k *Kind) Decl() *kindsys.Decl[kindsys.CoreStructuredMeta] {
|
||||||
return k.decl.Meta
|
d := k.decl
|
||||||
|
return &d
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ func (k *Kind) Maturity() kindsys.Maturity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO standard generated docs
|
// TODO standard generated docs
|
||||||
func (k *Kind) Meta() kindsys.RawMeta {
|
func (k *Kind) Decl() *kindsys.Decl[kindsys.RawMeta] {
|
||||||
return k.decl.Meta
|
d := k.decl
|
||||||
|
return &d
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ func (k *Kind) Maturity() kindsys.Maturity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO standard generated docs
|
// TODO standard generated docs
|
||||||
func (k *Kind) Meta() kindsys.CoreStructuredMeta {
|
func (k *Kind) Decl() *kindsys.Decl[kindsys.CoreStructuredMeta] {
|
||||||
return k.decl.Meta
|
d := k.decl
|
||||||
|
return &d
|
||||||
}
|
}
|
||||||
|
@ -99,6 +99,7 @@ func (k *Kind) Maturity() kindsys.Maturity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO standard generated docs
|
// TODO standard generated docs
|
||||||
func (k *Kind) Meta() kindsys.CoreStructuredMeta {
|
func (k *Kind) Decl() *kindsys.Decl[kindsys.CoreStructuredMeta] {
|
||||||
return k.decl.Meta
|
d := k.decl
|
||||||
|
return &d
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ func (k *Kind) Maturity() kindsys.Maturity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO standard generated docs
|
// TODO standard generated docs
|
||||||
func (k *Kind) Meta() kindsys.RawMeta {
|
func (k *Kind) Decl() *kindsys.Decl[kindsys.RawMeta] {
|
||||||
return k.decl.Meta
|
d := k.decl
|
||||||
|
return &d
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ type Raw interface {
|
|||||||
Interface
|
Interface
|
||||||
|
|
||||||
// TODO docs
|
// TODO docs
|
||||||
Meta() RawMeta
|
Decl() *Decl[RawMeta]
|
||||||
}
|
}
|
||||||
|
|
||||||
type Structured interface {
|
type Structured interface {
|
||||||
@ -68,7 +68,7 @@ type Structured interface {
|
|||||||
Lineage() thema.Lineage
|
Lineage() thema.Lineage
|
||||||
|
|
||||||
// TODO docs
|
// TODO docs
|
||||||
Meta() CoreStructuredMeta // TODO figure out how to reconcile this interface with CustomStructuredMeta
|
Decl() *Decl[CoreStructuredMeta] // TODO figure out how to reconcile this interface with CustomStructuredMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
// type Composable interface {
|
// type Composable interface {
|
||||||
|
@ -2,7 +2,7 @@ package kindsys
|
|||||||
|
|
||||||
import "github.com/grafana/thema"
|
import "github.com/grafana/thema"
|
||||||
|
|
||||||
// CommonMeta contains the kind metadata common to all categories of kinds.
|
// CommonMeta contains the metadata common to all categories of kinds.
|
||||||
type CommonMeta struct {
|
type CommonMeta struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PluralName string `json:"pluralName"`
|
PluralName string `json:"pluralName"`
|
||||||
|
Loading…
Reference in New Issue
Block a user