mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 02:10:45 -06:00
8745d7ef1b
* extract kindsys * reinstate kindsys report This may end up living somewhere else (or not! who knows!), but the important part is that I don't get rid of it right now :) I hate the package layout (kindsysreport/codegen) for the main function and will take pretty much any alternative suggestion, but we can change also change it later. Note that the generated report.json is in a different location - anything using this (ops something) needs to be updated. * kindsysreport in codeowners
61 lines
2.3 KiB
Go
61 lines
2.3 KiB
Go
// Package cuectx provides a single, central ["cuelang.org/go/cue".Context] and
|
|
// ["github.com/grafana/thema".Runtime] that can be used uniformly across
|
|
// Grafana, and related helper functions for loading Thema lineages.
|
|
|
|
package cuectx
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"cuelang.org/go/cue"
|
|
"cuelang.org/go/cue/cuecontext"
|
|
"github.com/grafana/thema"
|
|
"github.com/grafana/thema/vmux"
|
|
)
|
|
|
|
// CoreDefParentPath is the path, relative to the repository root, where
|
|
// each child directory is expected to contain .cue files defining one
|
|
// Core kind.
|
|
var CoreDefParentPath = "kinds"
|
|
|
|
// GoCoreKindParentPath is the path, relative to the repository root, to the directory
|
|
// containing one directory per kind, full of generated Go kind output: types and bindings.
|
|
var GoCoreKindParentPath = filepath.Join("pkg", "kinds")
|
|
|
|
// TSCoreKindParentPath is the path, relative to the repository root, to the directory that
|
|
// contains one directory per kind, full of generated TS kind output: types and default consts.
|
|
var TSCoreKindParentPath = filepath.Join("packages", "grafana-schema", "src", "raw")
|
|
|
|
var ctx = cuecontext.New()
|
|
var rt = thema.NewRuntime(ctx)
|
|
|
|
// GrafanaCUEContext returns Grafana's singleton instance of [cue.Context].
|
|
//
|
|
// All code within grafana/grafana that needs a *cue.Context should get it
|
|
// from this function, when one was not otherwise provided.
|
|
func GrafanaCUEContext() *cue.Context {
|
|
return ctx
|
|
}
|
|
|
|
// GrafanaThemaRuntime returns Grafana's singleton instance of [thema.Runtime].
|
|
//
|
|
// All code within grafana/grafana that needs a *thema.Runtime should get it
|
|
// from this function, when one was not otherwise provided.
|
|
func GrafanaThemaRuntime() *thema.Runtime {
|
|
return rt
|
|
}
|
|
|
|
// JSONtoCUE attempts to decode the given []byte into a cue.Value, relying on
|
|
// the central Grafana cue.Context provided in this package.
|
|
//
|
|
// The provided path argument determines the name given to the input bytes if
|
|
// later CUE operations (e.g. Thema validation) produce errors related to the
|
|
// returned cue.Value.
|
|
//
|
|
// This is a convenience function for one-off JSON decoding. It's wasteful to
|
|
// call it repeatedly. Most use cases should probably prefer making
|
|
// their own Thema/CUE decoders.
|
|
func JSONtoCUE(path string, b []byte) (cue.Value, error) {
|
|
return vmux.NewJSONCodec(path).Decode(ctx, b)
|
|
}
|