Schemas: Delete unused code from the previous refactors (#84254)
* Delete unused code from the previous refactors * Sort imports
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
|
||||
|
||||
//go:embed coremodel.cue
|
||||
var cueFS embed.FS
|
||||
|
||||
// The current version of the coremodel schema, as declared in coremodel.cue.
|
||||
// This version determines what schema version is returned from [Coremodel.CurrentSchema],
|
||||
// and which schema version is used for code generation within the grafana/grafana repository.
|
||||
//
|
||||
// The code generator ensures that this is always the latest Thema schema version.
|
||||
var currentVersion = thema.SV({{ .LatestSeqv }}, {{ .LatestSchv }})
|
||||
|
||||
// Lineage returns the Thema lineage representing a Grafana {{ .Name }}.
|
||||
//
|
||||
// The lineage is the canonical specification of the current {{ .Name }} schema,
|
||||
// all prior schema versions, and the mappings that allow migration between
|
||||
// schema versions.
|
||||
{{- if .IsComposed }}//
|
||||
// This is the base variant of the schema. It does not include any composed
|
||||
// plugin schemas.{{ end }}
|
||||
func Lineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("pkg", "coremodel", "{{ .Name }}"), cueFS, rt, opts...)
|
||||
}
|
||||
|
||||
var _ thema.LineageFactory = Lineage
|
||||
var _ coremodel.Interface = &Coremodel{}
|
||||
|
||||
// Coremodel contains the foundational schema declaration for {{ .Name }}s.
|
||||
// It implements coremodel.Interface.
|
||||
type Coremodel struct {
|
||||
lin thema.Lineage
|
||||
}
|
||||
|
||||
// Lineage returns the canonical {{ .Name }} Lineage.
|
||||
func (c *Coremodel) Lineage() thema.Lineage {
|
||||
return c.lin
|
||||
}
|
||||
|
||||
// CurrentSchema returns the current (latest) {{ .Name }} Thema schema.
|
||||
func (c *Coremodel) CurrentSchema() thema.Schema {
|
||||
return thema.SchemaP(c.lin, currentVersion)
|
||||
}
|
||||
|
||||
// GoType returns a pointer to an empty Go struct that corresponds to
|
||||
// the current Thema schema.
|
||||
func (c *Coremodel) GoType() interface{} {
|
||||
return &Model{}
|
||||
}
|
||||
|
||||
// New returns a new instance of the {{ .Name }} coremodel.
|
||||
//
|
||||
// Note that this function does not cache, and initially loading a Thema lineage
|
||||
// can be expensive. As such, the Grafana backend should prefer to access this
|
||||
// coremodel through a registry (pkg/framework/coremodel/registry), which does cache.
|
||||
func New(rt *thema.Runtime) (*Coremodel, error) {
|
||||
lin, err := Lineage(rt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Coremodel{
|
||||
lin: lin,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
{{ if .GenLicense -}}
|
||||
// Copyright {{ now.Year }} Grafana Labs
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
{{ end -}}
|
||||
// This file is autogenerated. DO NOT EDIT.
|
||||
{{- if ne .GeneratorPath "" }}
|
||||
//
|
||||
// Generated by {{ .GeneratorPath }}
|
||||
{{- end }}
|
||||
{{- if ne .LineagePath "" }}
|
||||
//
|
||||
// Derived from the Thema lineage declared in {{ .LineagePath }}{{ if ne .LineageCUEPath "" }} at CUE path "{{ .LineageCUEPath }}"{{ end }}
|
||||
{{- end }}
|
||||
//
|
||||
// Run `make gen-cue` from repository root to regenerate.
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package {{ .PackageName }}
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/grafana/grafana/pkg/cuectx"
|
||||
"github.com/grafana/grafana/pkg/framework/coremodel"
|
||||
"github.com/grafana/thema"
|
||||
)
|
||||
@@ -1,2 +0,0 @@
|
||||
{{ template "autogen_header.tmpl" .Header -}}
|
||||
{{ .Body }}
|
||||
@@ -1,12 +0,0 @@
|
||||
// The current version of the coremodel schema, as declared in coremodel.cue.
|
||||
// This version determines what schema version is returned from [Coremodel.CurrentSchema],
|
||||
// and which schema version is used for code generation within the grafana/grafana repository.
|
||||
//
|
||||
// The code generator ensures that this is always the latest Thema schema version.
|
||||
var currentVersion{{ .SlotName }} = thema.SV({{ .LatestSeqv }}, {{ .LatestSchv }})
|
||||
|
||||
// {{ .SlotName }}Lineage returns the Thema lineage for the {{ .PluginID }} {{ .PluginType }} plugin's
|
||||
// {{ .SlotName }} ["github.com/grafana/grafana/pkg/framework/coremodel".Slot] implementation.
|
||||
func {{ .SlotName }}Lineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("public", "app", "{{ .Name }}"), cueFS, rt, opts...)
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
{{ template "autogen_header.tmpl" .Header -}}
|
||||
package {{ .PackageName }}
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/grafana/thema"
|
||||
|
||||
"github.com/grafana/grafana/pkg/cuectx"
|
||||
"github.com/grafana/grafana/pkg/plugins/pfs"
|
||||
)
|
||||
|
||||
var parseOnce sync.Once
|
||||
var ptree *pfs.Tree
|
||||
|
||||
//go:embed plugin.{{ if .RootCUE }}cue{{ else }}json{{ end }}{{ if .HasModels }} models.cue{{ end }}
|
||||
var plugFS embed.FS
|
||||
|
||||
// PluginTree returns the plugin tree representing the statically analyzable contents of the {{ .PluginID }} plugin.
|
||||
func PluginTree(rt *thema.Runtime) *pfs.Tree {
|
||||
var err error
|
||||
if rt == nil || rt == cuectx.GrafanaThemaRuntime() {
|
||||
parseOnce.Do(func() {
|
||||
ptree, err = pfs.ParsePluginFS(plugFS, cuectx.GrafanaThemaRuntime())
|
||||
})
|
||||
} else {
|
||||
ptree, err = pfs.ParsePluginFS(plugFS, rt)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// Even the most rudimentary testing in CI ensures this is unreachable
|
||||
panic(fmt.Errorf("error parsing plugin fs tree: %w", err))
|
||||
}
|
||||
|
||||
return ptree
|
||||
}
|
||||
|
||||
{{ $pluginfo := . }}{{ range $slot := .SlotImpls }}
|
||||
// {{ .SlotName }}Lineage returns the Thema lineage for the {{ $pluginfo.PluginID }} {{ $pluginfo.PluginType }} plugin's
|
||||
// {{ .SlotName }} ["github.com/grafana/grafana/pkg/framework/coremodel".Slot] implementation.
|
||||
func {{ .SlotName }}Lineage(rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
t := PluginTree(rt)
|
||||
lin, has := t.RootPlugin().SlotImplementations()["{{ .SlotName }}"]
|
||||
if !has {
|
||||
panic("unreachable: lineage for {{ .SlotName }} does not exist, but code is only generated for existing lineages")
|
||||
}
|
||||
return lin, nil
|
||||
}
|
||||
|
||||
// The current schema version of the {{ .SlotName }} slot implementation.
|
||||
//
|
||||
// Code generation ensures that this is always the version number for the latest schema
|
||||
// in the {{ .SlotName }} Thema lineage.
|
||||
var currentVersion{{ .SlotName }} = thema.SV({{ .LatestMajv }}, {{ .LatestMinv }})
|
||||
|
||||
{{ end }}
|
||||
@@ -1,16 +0,0 @@
|
||||
{{ template "autogen_header.tmpl" .Header -}}
|
||||
package registry
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/plugins/pfs"
|
||||
"github.com/grafana/thema"
|
||||
{{ range .Plugins }}
|
||||
{{ if .NoAlias }}{{ .PkgName }} {{end}}"{{ .Path }}"{{ end }}
|
||||
)
|
||||
|
||||
func coreTreeLoaders() []func(*thema.Runtime) *pfs.Tree{
|
||||
return []func(*thema.Runtime) *pfs.Tree{
|
||||
{{- range .Plugins }}
|
||||
{{ .PkgName }}.PluginTree,{{ end }}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user