Files
grafana/pkg/kindsys/props.go
sam boyer 30b4205521 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
2023-01-31 19:40:15 -05:00

76 lines
2.5 KiB
Go

package kindsys
import "github.com/grafana/thema"
// CommonProperties contains the metadata common to all categories of kinds.
type CommonProperties struct {
Name string `json:"name"`
PluralName string `json:"pluralName"`
MachineName string `json:"machineName"`
PluralMachineName string `json:"pluralMachineName"`
LineageIsGroup bool `json:"lineageIsGroup"`
Maturity Maturity `json:"maturity"`
Description string `json:"description,omitempty"`
}
// CoreProperties represents the static properties in the definition of a
// Core kind that are representable with basic Go types. This
// excludes Thema schemas.
//
// When .cue file(s) containing a Core definition is loaded through the standard
// [LoadCoreKindDef], func, it is fully validated and populated according to all
// rules specified in CUE for Core kinds.
type CoreProperties struct {
CommonProperties
CurrentVersion thema.SyntacticVersion `json:"currentVersion"`
}
func (m CoreProperties) _private() {}
func (m CoreProperties) Common() CommonProperties {
return m.CommonProperties
}
// CustomProperties represents the static properties in the definition of a
// Custom kind that are representable with basic Go types. This
// excludes Thema schemas.
type CustomProperties struct {
CommonProperties
CurrentVersion thema.SyntacticVersion `json:"currentVersion"`
}
func (m CustomProperties) _private() {}
func (m CustomProperties) Common() CommonProperties {
return m.CommonProperties
}
// ComposableProperties represents the static properties in the definition of a
// Composable kind that are representable with basic Go types. This
// excludes Thema schemas.
type ComposableProperties struct {
CommonProperties
CurrentVersion thema.SyntacticVersion `json:"currentVersion"`
SchemaInterface string `json:"schemaInterface"`
}
func (m ComposableProperties) _private() {}
func (m ComposableProperties) Common() CommonProperties {
return m.CommonProperties
}
// SomeKindProperties is an interface type to abstract over the different kind
// property struct types: [CoreProperties], [CustomProperties],
// [ComposableProperties].
//
// It is the traditional interface counterpart to the generic type constraint
// KindProperties.
type SomeKindProperties interface {
_private()
Common() CommonProperties
}
// KindProperties is a type parameter that comprises the base possible set of
// kind metadata configurations.
type KindProperties interface {
CoreProperties | CustomProperties | ComposableProperties
}