Skip to content

Instantly share code, notes, and snippets.

View sdboyer's full-sized avatar

sam boyer sdboyer

View GitHub Profile
@sdboyer
sdboyer / main.go
Last active May 18, 2022 16:35
Translate the dashboard lineage as OpenAPI
package main
import (
"fmt"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/pkg/encoding/yaml"
"github.com/grafana/grafana/pkg/coremodel/dashboard"
"github.com/grafana/thema"
"github.com/grafana/thema/encoding/openapi"
@sdboyer
sdboyer / inputs.cue
Last active January 18, 2023 13:37
CUE expression tree printer, currently squirreled away in grafana/cuetsy
node1: string @cuetsy(kind="type")
node2: string | *int @cuetsy(kind="type")
node3: *"foo" | "bar" | "baz" @cuetsy(kind="enum", memberNames="Foo|Bar|Baz")
node4: node3 | node2
node5: {
inner: string
n3: node3
} @cuetsy(kind="interface")
// Each other file in this gist corresponds to taking a field under ref here
@sdboyer
sdboyer / dashboard-jsonschema.json
Last active May 18, 2022 15:30
These files were autogenerated (LIKE A MOTHAFUCKA) from a Thema schema. Editing is futile.
{
"info": {
"title": "dashboard",
"version": "0.0"
},
"paths": {},
"components": {
"schemas": {
"dashboard": {
"type": "object",
@sdboyer
sdboyer / joinSchema.cue
Created January 17, 2022 20:11
joinSchema as open struct
// Core Thema definition
#Lin: {
joinSchema: _
sch: joinSchema
}
/////////////////////
// Lineage subtype def (proposed to be new core joinSchema def)
#B: #Lin & {
@sdboyer
sdboyer / input.go
Last active January 4, 2022 03:41
Thema input kernel handwavy code
package kernel
import (
"cuelang.org/go/cue"
"cuelang.org/go/encoding/gocode/gocodec"
"github.com/grafana/thema"
)
// An InputKernel accepts all the valid inputs for a given lineage, converges
// them onto a single statically-chosen schema version, and emits the result in
// Kubernetes
info: {
title: *"Kubernetes" | string
version: *"v1.23.0" | string
}
#SchemaMap: {
// CustomResourceColumnDefinition specifies a column for server
// side printing.
package schema
TableCellDisplayModeType: *"auto" | "color-text" | "color-background" | "color-background-solid" | "gradient-gauge" | "lcd-gauge" | "json-view" | "basic" | "image" @cuetsy(kind="enum",memberNames="Auto|ColorText|ColorBackground|ColorBackgroundSolid|GradientGauge|LcdGauge|JSONView|BasicGauge|Image")
TableFieldOptions: {
align: string
modeOptions: TableCellDisplayMode
hidden?: bool
minWidth?: number
width?: number
@sdboyer
sdboyer / simple_scuemata.cue
Last active October 14, 2021 23:55
Basic scuemata
import "github.com/grafana/scuemata"
// Make the whole file a scuemata.Family
scuemata.Family
lineages: [{
// Schema versions are implicitly defined by the schema's position in the arrays
schemas: [
{ // Schema 0.0
somefield: string
},
@sdboyer
sdboyer / scuemata_with_lens.cue
Last active October 15, 2021 04:35
Simple example scuemata
import "github.com/grafana/scuemata"
// Make the whole file a scuemata.Family
scuemata.Family
lineages: [{ // Lineage 0
schemas: [{ // Schema 0.0
boolish: "true" | "false" | bool | string
}]
},
{ // Lineage 1
@sdboyer
sdboyer / allcue.gen.ts
Created September 27, 2021 04:01
nearly there with CUE->TS codegen! this is gen results for *all* the CUE in grafana codebase so far
import * as ui from '@grafana-schema';
/////////////////////////////////////////////////////
// SOURCE CUE PATH packages/grafana-schema/src/schema/graph.cue
/////////////////////////////////////////////////////
export enum AxisPlacement {
Auto = 'auto',
Bottom = 'bottom',
Hidden = 'hidden',
Left = 'left',