2022-06-15 09:47:04 -04:00
|
|
|
package registry
|
|
|
|
|
|
|
|
|
|
import (
|
2022-08-03 16:04:54 -04:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"github.com/google/wire"
|
|
|
|
|
"github.com/grafana/grafana/pkg/cuectx"
|
|
|
|
|
"github.com/grafana/grafana/pkg/framework/coremodel"
|
2022-06-15 09:47:04 -04:00
|
|
|
"github.com/grafana/thema"
|
|
|
|
|
)
|
|
|
|
|
|
2022-08-03 16:04:54 -04:00
|
|
|
// CoremodelSet contains all of the wire-style providers related to coremodels.
|
|
|
|
|
var CoremodelSet = wire.NewSet(
|
|
|
|
|
NewBase,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
baseOnce sync.Once
|
|
|
|
|
defaultBase *Base
|
|
|
|
|
)
|
|
|
|
|
|
2022-10-11 05:39:29 -04:00
|
|
|
// NewBase provides a registry of all coremodels, without any composition of
|
|
|
|
|
// plugin-defined schemas.
|
|
|
|
|
//
|
|
|
|
|
// All calling code within grafana/grafana is expected to use Grafana's
|
|
|
|
|
// singleton [thema.Runtime], returned from [cuectx.GrafanaThemaRuntime]. If nil
|
|
|
|
|
// is passed, the singleton will be used.
|
|
|
|
|
func NewBase(rt *thema.Runtime) *Base {
|
|
|
|
|
allrt := cuectx.GrafanaThemaRuntime()
|
|
|
|
|
if rt == nil || rt == allrt {
|
2022-08-03 16:04:54 -04:00
|
|
|
baseOnce.Do(func() {
|
2022-10-11 05:39:29 -04:00
|
|
|
defaultBase = doProvideBase(allrt)
|
2022-08-03 16:04:54 -04:00
|
|
|
})
|
|
|
|
|
return defaultBase
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 04:45:07 -04:00
|
|
|
return doProvideBase(rt)
|
2022-06-15 09:47:04 -04:00
|
|
|
}
|
|
|
|
|
|
2022-08-03 16:04:54 -04:00
|
|
|
// All returns a slice of all registered coremodels.
|
|
|
|
|
//
|
|
|
|
|
// Prefer this method when operating generically across all coremodels.
|
|
|
|
|
//
|
|
|
|
|
// The returned slice is sorted lexicographically by coremodel name. It should
|
|
|
|
|
// not be modified.
|
2022-09-14 10:15:09 -04:00
|
|
|
func (b *Base) All() []coremodel.Interface {
|
|
|
|
|
return b.all
|
2022-08-03 16:04:54 -04:00
|
|
|
}
|