Skip to content

Instantly share code, notes, and snippets.

View sdboyer's full-sized avatar

sam boyer sdboyer

View GitHub Profile
@sdboyer
sdboyer / lokicfg.cue
Last active October 3, 2022 14:56
rapidly prototyped demo of thema and codegen for loki config file
package lokicfg
import "github.com/grafana/thema"
// - MIGHT be helpful for them if there could be an init command that tries to start from Go structs
// - Probably need to generate YAML struct tags
thema.#Lineage
name: "lokicfg"
seqs: [
@sdboyer
sdboyer / _resolving.cue
Last active September 6, 2022 13:12
pseudoframework for variant object refs in schemas. NOTE, untested pseudocode
// Schema of our B type
#B: {
type: string
aFieldInB: string
}
// Schema of our A type
#A: {
// someB should ultimately be resolvable to a single instance of B,
// but instances of A are allowed to accept a B literal, constraint, or id
@sdboyer
sdboyer / models.cue
Last active August 23, 2022 20:06
Codegen output when prometheus gets a models.cue
package grafanaplugin
import "github.com/grafana/thema"
// Note - all fields in here SHOULD be well-commented.
Query: thema.#Lineage & {
name: "prometheus"
seqs: [
{
@sdboyer
sdboyer / models.cue
Last active August 3, 2022 01:05
Example grafana datasource plugin slot implementations (query and dsoptions) for prometheus datasource plugin
package dsschema
import "github.com/grafana/thema"
Query: thema.#Lineage & {
name: "prometheus"
seqs: [
{
schemas: [
{// 0.0
@sdboyer
sdboyer / coremodel.cue
Created July 12, 2022 20:08
shorty mcshorterface
package pluginmeta
import "github.com/grafana/thema"
thema.#Lineage
name: "pluginmeta"
seqs: [
{
schemas: [
{
@sdboyer
sdboyer / coremodel_to_kernel.go
Last active June 28, 2022 22:45
A function for getting a JSON kernel from a coremodel
package something
import (
"github.com/grafana/thema/kernel"
"github.com/grafana/grafana/pkg/framework/coremodel"
)
func JSONKernelFrom(cm coremodel.Interface) kernel.InputKernel {
k, _ := kernel.NewInputKernel(kernel.InputKernelConfig{
Typ: cm.GoType(),
@sdboyer
sdboyer / coremodel.cue
Created June 27, 2022 13:36
Succeeds incorrectly - no lenses are declared to map between schema versions
package foo
import "github.com/grafana/thema"
thema.#Lineage
name: "foo"
seqs: [
{
schemas: [
{// 0.0
@sdboyer
sdboyer / coremodel.cue
Last active June 27, 2022 13:33
Fails correctly - 0.1 is incompatible with 0.0
package foo
import "github.com/grafana/thema"
thema.#Lineage
name: "foo"
seqs: [
{
schemas: [
{// 0.0
@sdboyer
sdboyer / coremodel.cue
Last active June 27, 2022 13:31
Fails incorrectly - Thema needs a custom checker to make defaults sufficient for backwards compatibility
package foo
import "github.com/grafana/thema"
thema.#Lineage
name: "foo"
seqs: [
{
schemas: [
{// 0.0
@sdboyer
sdboyer / coremodel.cue
Last active June 27, 2022 13:19
Fails - 1.0 must be backwards incompatible with 0.0
package foo
import "github.com/grafana/thema"
thema.#Lineage
name: "foo"
seqs: [
{
schemas: [
{// 0.0