2023-01-06 03:57:45 -06:00
|
|
|
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
|
2022-12-01 10:08:54 -06:00
|
|
|
//
|
|
|
|
// Generated by:
|
|
|
|
// kinds/gen.go
|
|
|
|
// Using jennies:
|
2023-01-05 12:54:42 -06:00
|
|
|
// CoreKindJenny
|
2022-12-01 10:08:54 -06:00
|
|
|
//
|
|
|
|
// Run 'make gen-cue' from repository root to regenerate.
|
|
|
|
|
|
|
|
package team
|
|
|
|
|
|
|
|
import (
|
2023-03-15 11:04:28 -05:00
|
|
|
"github.com/grafana/kindsys"
|
2022-12-01 10:08:54 -06:00
|
|
|
"github.com/grafana/thema"
|
|
|
|
"github.com/grafana/thema/vmux"
|
2023-03-15 11:04:28 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/cuectx"
|
2022-12-01 10:08:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// rootrel is the relative path from the grafana repository root to the
|
2023-01-31 03:50:08 -06:00
|
|
|
// directory containing the .cue files in which this kind is defined. Necessary
|
|
|
|
// for runtime errors related to the definition and/or lineage to provide
|
2022-12-01 10:08:54 -06:00
|
|
|
// a real path to the correct .cue file.
|
2023-01-05 12:54:42 -06:00
|
|
|
const rootrel string = "kinds/team"
|
2022-12-01 10:08:54 -06:00
|
|
|
|
|
|
|
// TODO standard generated docs
|
|
|
|
type Kind struct {
|
2023-01-31 18:40:15 -06:00
|
|
|
kindsys.Core
|
2023-04-27 15:32:38 -05:00
|
|
|
lin thema.ConvergentLineage[*Resource]
|
2022-12-01 10:08:54 -06:00
|
|
|
jcodec vmux.Codec
|
2023-04-27 15:32:38 -05:00
|
|
|
valmux vmux.ValueMux[*Resource]
|
2022-12-01 10:08:54 -06:00
|
|
|
}
|
|
|
|
|
2023-01-31 18:40:15 -06:00
|
|
|
// type guard - ensure generated Kind type satisfies the kindsys.Core interface
|
2023-01-05 12:54:42 -06:00
|
|
|
var _ kindsys.Core = &Kind{}
|
2022-12-01 10:08:54 -06:00
|
|
|
|
|
|
|
// TODO standard generated docs
|
|
|
|
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
|
2023-03-15 11:04:28 -05:00
|
|
|
def, err := cuectx.LoadCoreKindDef(rootrel, rt.Context(), nil)
|
2022-12-01 10:08:54 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-01-31 18:40:15 -06:00
|
|
|
k := &Kind{}
|
|
|
|
k.Core, err = kindsys.BindCore(rt, def, opts...)
|
2022-12-01 10:08:54 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Get the thema.Schema that the meta says is in the current version (which
|
|
|
|
// codegen ensures is always the latest)
|
2023-01-31 18:40:15 -06:00
|
|
|
cursch := thema.SchemaP(k.Core.Lineage(), def.Properties.CurrentVersion)
|
2023-04-27 15:32:38 -05:00
|
|
|
tsch, err := thema.BindType(cursch, &Resource{})
|
2022-12-01 10:08:54 -06:00
|
|
|
if err != nil {
|
|
|
|
// Should be unreachable, modulo bugs in the Thema->Go code generator
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
k.jcodec = vmux.NewJSONCodec("team.json")
|
|
|
|
k.lin = tsch.ConvergentLineage()
|
|
|
|
k.valmux = vmux.NewValueMux(k.lin.TypedSchema(), k.jcodec)
|
|
|
|
return k, nil
|
|
|
|
}
|
|
|
|
|
2023-01-31 18:40:15 -06:00
|
|
|
// ConvergentLineage returns the same [thema.Lineage] as Lineage, but bound (see [thema.BindType])
|
2023-04-27 15:32:38 -05:00
|
|
|
// to the the Team [Resource] type generated from the current schema, v0.0.
|
|
|
|
func (k *Kind) ConvergentLineage() thema.ConvergentLineage[*Resource] {
|
2022-12-01 10:08:54 -06:00
|
|
|
return k.lin
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSONValueMux is a version multiplexer that maps a []byte containing JSON data
|
2023-04-27 15:32:38 -05:00
|
|
|
// at any schematized dashboard version to an instance of Team [Resource].
|
2022-12-01 10:08:54 -06:00
|
|
|
//
|
|
|
|
// Validation and translation errors emitted from this func will identify the
|
|
|
|
// input bytes as "dashboard.json".
|
|
|
|
//
|
|
|
|
// This is a thin wrapper around Thema's [vmux.ValueMux].
|
2023-04-27 15:32:38 -05:00
|
|
|
func (k *Kind) JSONValueMux(b []byte) (*Resource, thema.TranslationLacunas, error) {
|
2022-12-01 10:08:54 -06:00
|
|
|
return k.valmux(b)
|
|
|
|
}
|