Support importing local cue modules when generating TS types with cog (#96876)

* Support importing local cue modules when generating TS types with cog

* Generate enums as unions of values instead of an actual `enum` statement

* Update transformers to use the new TS enums

* Update go workspaces

---------

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
This commit is contained in:
Kévin Gomez
2024-11-28 10:45:31 +01:00
committed by GitHub
co-authored by Ivan Ortega
parent c8caf787d4
commit c8d3ea58f8
31 changed files with 280 additions and 415 deletions
@@ -1,5 +1,8 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
import * as common from '@grafana/schema';
export interface DashboardV2Spec {
// Unique numeric identifier for the dashboard.
// `id` is internal to a specific Grafana instance. `uid` should be used to identify a dashboard across Grafana instances.
@@ -42,7 +45,7 @@ export interface DashboardV2Spec {
export const defaultDashboardV2Spec = (): DashboardV2Spec => ({
title: "",
cursorSync: DashboardCursorSync.Off,
cursorSync: "Off",
preload: false,
editable: true,
links: [],
@@ -69,13 +72,9 @@ export const defaultAnnotationPanelFilter = (): AnnotationPanelFilter => ({
// "Off" for no shared crosshair or tooltip (default).
// "Crosshair" for shared crosshair.
// "Tooltip" for shared crosshair AND shared tooltip.
export enum DashboardCursorSync {
Off = "Off",
Crosshair = "Crosshair",
Tooltip = "Tooltip",
}
export type DashboardCursorSync = "Off" | "Crosshair" | "Tooltip";
export const defaultDashboardCursorSync = (): DashboardCursorSync => (DashboardCursorSync.Off);
export const defaultDashboardCursorSync = (): DashboardCursorSync => ("Off");
// Links with references to other dashboards or external resources
export interface DashboardLink {
@@ -104,7 +103,7 @@ export interface DashboardLink {
export const defaultDashboardLink = (): DashboardLink => ({
title: "",
type: DashboardLinkType.Link,
type: "link",
icon: "",
tooltip: "",
tags: [],
@@ -124,14 +123,6 @@ export interface DataSourceRef {
export const defaultDataSourceRef = (): DataSourceRef => ({
});
export enum DataTopic {
AlertStates = "alertStates",
Annotations = "annotations",
Series = "series",
}
export const defaultDataTopic = (): DataTopic => (DataTopic.AlertStates);
// Transformations allow to manipulate data returned by a query before the system applies a visualization.
// Using transformations you can: rename fields, join time series data, perform mathematical operations across queries,
// use the output of one transformation as the input to another transformation, etc.
@@ -143,7 +134,7 @@ export interface DataTransformerConfig {
// Optional frame matcher. When missing it will be applied to all results
filter?: MatcherConfig;
// Where to pull DataFrames from as input to transformation
topic?: DataTopic;
topic?: common.DataTopic;
// Options to be passed to the transformer
// Valid options depend on the transformer id
options: any;
@@ -263,12 +254,9 @@ export const defaultThreshold = (): Threshold => ({
color: "",
});
export enum ThresholdsMode {
Absolute = "absolute",
Percentage = "percentage",
}
export type ThresholdsMode = "absolute" | "percentage";
export const defaultThresholdsMode = (): ThresholdsMode => (ThresholdsMode.Absolute);
export const defaultThresholdsMode = (): ThresholdsMode => ("absolute");
export interface ThresholdsConfig {
mode: ThresholdsMode;
@@ -276,7 +264,7 @@ export interface ThresholdsConfig {
}
export const defaultThresholdsConfig = (): ThresholdsConfig => ({
mode: ThresholdsMode.Absolute,
mode: "absolute",
steps: [],
});
@@ -289,14 +277,9 @@ export const defaultValueMapping = (): ValueMapping => (defaultValueMap());
// `range`: Maps numerical ranges to a display text and color. For example, if a value is within a certain range, you can configure a range value mapping to display Low or High rather than the number.
// `regex`: Maps regular expressions to replacement text and a color. For example, if a value is www.example.com, you can configure a regex value mapping so that Grafana displays www and truncates the domain.
// `special`: Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color. See SpecialValueMatch to see the list of special values. For example, you can configure a special value mapping so that null values appear as N/A.
export enum MappingType {
ValueToText = "value",
RangeToText = "range",
RegexToText = "regex",
SpecialValue = "special",
}
export type MappingType = "value" | "range" | "regex" | "special";
export const defaultMappingType = (): MappingType => (MappingType.ValueToText);
export const defaultMappingType = (): MappingType => ("value");
// Maps text values to a color or different display text and color.
// For example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number.
@@ -372,22 +355,15 @@ export interface SpecialValueMap {
export const defaultSpecialValueMap = (): SpecialValueMap => ({
type: "special",
options: {
match: SpecialValueMatch.True,
match: "true",
result: defaultValueMappingResult(),
},
});
// Special value types supported by the `SpecialValueMap`
export enum SpecialValueMatch {
True = "true",
False = "false",
Null = "null",
NotANumber = "nan",
NullAndNaN = "null+nan",
Empty = "empty",
}
export type SpecialValueMatch = "true" | "false" | "null" | "nan" | "null+nan" | "empty";
export const defaultSpecialValueMatch = (): SpecialValueMatch => (SpecialValueMatch.True);
export const defaultSpecialValueMatch = (): SpecialValueMatch => ("true");
// Result used as replacement with text and color when the value matches
export interface ValueMappingResult {
@@ -422,34 +398,14 @@ export const defaultValueMappingResult = (): ValueMappingResult => ({
// `continuous-purples`: Continuous Purple palette mode
// `shades`: Shades of a single color. Specify a single color, useful in an override rule.
// `fixed`: Fixed color mode. Specify a single color, useful in an override rule.
export enum FieldColorModeId {
Thresholds = "thresholds",
PaletteClassic = "palette-classic",
PaletteClassicByName = "palette-classic-by-name",
ContinuousGrYlRd = "continuous-GrYlRd",
ContinuousRdYlGr = "continuous-RdYlGr",
ContinuousBlYlRd = "continuous-BlYlRd",
ContinuousYlRd = "continuous-YlRd",
ContinuousBlPu = "continuous-BlPu",
ContinuousYlBl = "continuous-YlBl",
ContinuousBlues = "continuous-blues",
ContinuousReds = "continuous-reds",
ContinuousGreens = "continuous-greens",
ContinuousPurples = "continuous-purples",
Fixed = "fixed",
Shades = "shades",
}
export type FieldColorModeId = "thresholds" | "palette-classic" | "palette-classic-by-name" | "continuous-GrYlRd" | "continuous-RdYlGr" | "continuous-BlYlRd" | "continuous-YlRd" | "continuous-BlPu" | "continuous-YlBl" | "continuous-blues" | "continuous-reds" | "continuous-greens" | "continuous-purples" | "fixed" | "shades";
export const defaultFieldColorModeId = (): FieldColorModeId => (FieldColorModeId.Thresholds);
export const defaultFieldColorModeId = (): FieldColorModeId => ("thresholds");
// Defines how to assign a series color from "by value" color schemes. For example for an aggregated data points like a timeseries, the color can be assigned by the min, max or last value.
export enum FieldColorSeriesByMode {
Min = "min",
Max = "max",
Last = "last",
}
export type FieldColorSeriesByMode = "min" | "max" | "last";
export const defaultFieldColorSeriesByMode = (): FieldColorSeriesByMode => (FieldColorSeriesByMode.Min);
export const defaultFieldColorSeriesByMode = (): FieldColorSeriesByMode => ("min");
// Map a field to a color.
export interface FieldColor {
@@ -462,16 +418,13 @@ export interface FieldColor {
}
export const defaultFieldColor = (): FieldColor => ({
mode: FieldColorModeId.Thresholds,
mode: "thresholds",
});
// Dashboard Link type. Accepted values are dashboards (to refer to another dashboard) and link (to refer to an external resource)
export enum DashboardLinkType {
Link = "link",
Dashboards = "dashboards",
}
export type DashboardLinkType = "link" | "dashboards";
export const defaultDashboardLinkType = (): DashboardLinkType => (DashboardLinkType.Link);
export const defaultDashboardLinkType = (): DashboardLinkType => ("link");
// --- Common types ---
export interface Kind {
@@ -790,7 +743,7 @@ export interface CustomFormatterVariable {
export const defaultCustomFormatterVariable = (): CustomFormatterVariable => ({
name: "",
type: VariableType.Query,
type: "query",
multi: false,
includeAll: false,
});
@@ -821,7 +774,7 @@ export const defaultVariableCustomFormatterFn = (): VariableCustomFormatterFn =>
value: {},
legacyVariableModel: {
name: "",
type: VariableType.Query,
type: "query",
multi: false,
includeAll: false,
},
@@ -836,20 +789,9 @@ export const defaultVariableCustomFormatterFn = (): VariableCustomFormatterFn =>
// `textbox`: Display a free text input field with an optional default value.
// `custom`: Define the variable options manually using a comma-separated list.
// `system`: Variables defined by Grafana. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables
export enum VariableType {
Query = "query",
Adhoc = "adhoc",
Groupby = "groupby",
Constant = "constant",
Datasource = "datasource",
Interval = "interval",
Textbox = "textbox",
Custom = "custom",
System = "system",
Snapshot = "snapshot",
}
export type VariableType = "query" | "adhoc" | "groupby" | "constant" | "datasource" | "interval" | "textbox" | "custom" | "system" | "snapshot";
export const defaultVariableType = (): VariableType => (VariableType.Query);
export const defaultVariableType = (): VariableType => ("query");
// Sort variable options
// Accepted values are:
@@ -863,41 +805,23 @@ export const defaultVariableType = (): VariableType => (VariableType.Query);
// `naturalAsc`: Natural ASC
// `naturalDesc`: Natural DESC
// VariableSort enum with default value
export enum VariableSort {
Disabled = "disabled",
AlphabeticalAsc = "alphabeticalAsc",
AlphabeticalDesc = "alphabeticalDesc",
NumericalAsc = "numericalAsc",
NumericalDesc = "numericalDesc",
AlphabeticalCaseInsensitiveAsc = "alphabeticalCaseInsensitiveAsc",
AlphabeticalCaseInsensitiveDesc = "alphabeticalCaseInsensitiveDesc",
NaturalAsc = "naturalAsc",
NaturalDesc = "naturalDesc",
}
export type VariableSort = "disabled" | "alphabeticalAsc" | "alphabeticalDesc" | "numericalAsc" | "numericalDesc" | "alphabeticalCaseInsensitiveAsc" | "alphabeticalCaseInsensitiveDesc" | "naturalAsc" | "naturalDesc";
export const defaultVariableSort = (): VariableSort => (VariableSort.Disabled);
export const defaultVariableSort = (): VariableSort => ("disabled");
// Options to config when to refresh a variable
// `never`: Never refresh the variable
// `onDashboardLoad`: Queries the data source every time the dashboard loads.
// `onTimeRangeChanged`: Queries the data source when the dashboard time range changes.
export enum VariableRefresh {
Never = "never",
OnDashboardLoad = "onDashboardLoad",
OnTimeRangeChanged = "onTimeRangeChanged",
}
export type VariableRefresh = "never" | "onDashboardLoad" | "onTimeRangeChanged";
export const defaultVariableRefresh = (): VariableRefresh => (VariableRefresh.Never);
export const defaultVariableRefresh = (): VariableRefresh => ("never");
// Determine if the variable shows on dashboard
// Accepted values are `dontHide` (show label and value), `hideLabel` (show value only), `hideVariable` (show nothing).
export enum VariableHide {
DontHide = "dontHide",
HideLabel = "hideLabel",
HideVariable = "hideVariable",
}
export type VariableHide = "dontHide" | "hideLabel" | "hideVariable";
export const defaultVariableHide = (): VariableHide => (VariableHide.DontHide);
export const defaultVariableHide = (): VariableHide => ("dontHide");
// FIXME: should we introduce this? --- Variable value option
export interface VariableValueOption {
@@ -950,13 +874,13 @@ export interface QueryVariableSpec {
export const defaultQueryVariableSpec = (): QueryVariableSpec => ({
name: "",
current: { text: "", value: "", },
hide: VariableHide.DontHide,
refresh: VariableRefresh.Never,
hide: "dontHide",
refresh: "never",
skipUrlSync: false,
datasource: defaultDataSourceRef(),
query: "",
regex: "",
sort: VariableSort.Disabled,
sort: "disabled",
options: [],
multi: false,
includeAll: false,
@@ -988,7 +912,7 @@ export const defaultTextVariableSpec = (): TextVariableSpec => ({
name: "",
current: { text: "", value: "", },
query: "",
hide: VariableHide.DontHide,
hide: "dontHide",
skipUrlSync: false,
});
@@ -1018,7 +942,7 @@ export const defaultConstantVariableSpec = (): ConstantVariableSpec => ({
name: "",
query: "",
current: { text: "", value: "", },
hide: VariableHide.DontHide,
hide: "dontHide",
skipUrlSync: false,
});
@@ -1054,14 +978,14 @@ export interface DatasourceVariableSpec {
export const defaultDatasourceVariableSpec = (): DatasourceVariableSpec => ({
name: "",
pluginId: "",
refresh: VariableRefresh.Never,
refresh: "never",
regex: "",
current: { text: "", value: "", },
defaultOptionEnabled: false,
options: [],
multi: false,
includeAll: false,
hide: VariableHide.DontHide,
hide: "dontHide",
skipUrlSync: false,
});
@@ -1100,8 +1024,8 @@ export const defaultIntervalVariableSpec = (): IntervalVariableSpec => ({
auto: false,
auto_min: "",
auto_count: 0,
refresh: VariableRefresh.Never,
hide: VariableHide.DontHide,
refresh: "never",
hide: "dontHide",
skipUrlSync: false,
});
@@ -1138,7 +1062,7 @@ export const defaultCustomVariableSpec = (): CustomVariableSpec => ({
options: [],
multi: false,
includeAll: false,
hide: VariableHide.DontHide,
hide: "dontHide",
skipUrlSync: false,
});
@@ -1175,7 +1099,7 @@ export const defaultGroupByVariableSpec = (): GroupByVariableSpec => ({
options: [],
multi: false,
includeAll: false,
hide: VariableHide.DontHide,
hide: "dontHide",
skipUrlSync: false,
});
@@ -1209,7 +1133,7 @@ export const defaultAdhocVariableSpec = (): AdhocVariableSpec => ({
baseFilters: [],
filters: [],
defaultKeys: [],
hide: VariableHide.DontHide,
hide: "dontHide",
skipUrlSync: false,
});
@@ -1,4 +1,8 @@
package dashboard
package v2alpha0
import (
"github.com/grafana/grafana/packages/grafana-schema/src/common"
)
DashboardV2Spec: {
// Unique numeric identifier for the dashboard.
@@ -102,8 +106,6 @@ DataSourceRef: {
uid?: string
}
DataTopic: "alertStates" | "annotations" | "series"
// Transformations allow to manipulate data returned by a query before the system applies a visualization.
// Using transformations you can: rename fields, join time series data, perform mathematical operations across queries,
// use the output of one transformation as the input to another transformation, etc.
@@ -115,7 +117,7 @@ DataTransformerConfig: {
// Optional frame matcher. When missing it will be applied to all results
filter?: MatcherConfig
// Where to pull DataFrames from as input to transformation
topic?: DataTopic
topic?: common.DataTopic
// Options to be passed to the transformer
// Valid options depend on the transformer id
options: _
@@ -1,21 +1,15 @@
import {
DashboardCursorSync,
DashboardLinkType,
DashboardV2Spec,
VariableHide,
VariableRefresh,
VariableSort,
} from './dashboard.gen';
import { DashboardV2Spec } from './dashboard.gen';
export const handyTestingSchema: DashboardV2Spec = {
title: 'Test Dashboard',
description: 'Test Description',
id: 1,
title: 'Default Dashboard',
description: 'This is a default dashboard',
cursorSync: 'Off',
liveNow: false,
preload: false,
editable: true,
preload: true,
schemaVersion: 40,
tags: ['tag1', 'tag2'],
liveNow: true,
cursorSync: DashboardCursorSync.Crosshair,
timeSettings: {
autoRefresh: '5s',
autoRefreshIntervals: ['5s', '10s', '30s'],
@@ -132,7 +126,7 @@ export const handyTestingSchema: DashboardV2Spec = {
targetBlank: false,
title: 'Test Link',
tooltip: '',
type: DashboardLinkType.Dashboards,
type: 'dashboards',
url: 'http://test.com',
},
],
@@ -152,17 +146,17 @@ export const handyTestingSchema: DashboardV2Spec = {
},
definition: 'definition1',
description: 'A query variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
includeAll: true,
label: 'Query Variable',
multi: true,
name: 'queryVar',
options: [],
query: 'query1',
refresh: VariableRefresh.OnDashboardLoad,
refresh: 'onDashboardLoad',
regex: 'regex1',
skipUrlSync: false,
sort: VariableSort.Disabled,
sort: 'disabled',
},
},
{
@@ -174,7 +168,7 @@ export const handyTestingSchema: DashboardV2Spec = {
value: 'option1',
},
description: 'A custom variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
includeAll: true,
label: 'Custom Variable',
multi: true,
@@ -205,14 +199,14 @@ export const handyTestingSchema: DashboardV2Spec = {
},
defaultOptionEnabled: true,
description: 'A datasource variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
includeAll: false,
label: 'Datasource Variable',
multi: false,
name: 'datasourceVar',
options: [],
pluginId: 'datasource1',
refresh: VariableRefresh.OnDashboardLoad,
refresh: 'onDashboardLoad',
regex: 'regex1',
skipUrlSync: false,
},
@@ -225,7 +219,7 @@ export const handyTestingSchema: DashboardV2Spec = {
value: 'value4',
},
description: 'A constant variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
label: 'Constant Variable',
name: 'constantVar',
query: 'value4',
@@ -243,7 +237,7 @@ export const handyTestingSchema: DashboardV2Spec = {
value: '1m',
},
description: 'An interval variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
label: 'Interval Variable',
name: 'intervalVar',
options: [
@@ -264,7 +258,7 @@ export const handyTestingSchema: DashboardV2Spec = {
},
],
query: '1m,5m,10m',
refresh: VariableRefresh.OnDashboardLoad,
refresh: 'onDashboardLoad',
skipUrlSync: false,
},
},
@@ -276,7 +270,7 @@ export const handyTestingSchema: DashboardV2Spec = {
value: 'value6',
},
description: 'A text variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
label: 'Text Variable',
name: 'textVar',
query: 'value6',
@@ -295,7 +289,7 @@ export const handyTestingSchema: DashboardV2Spec = {
uid: 'datasource2',
},
description: 'A group by variable',
hide: VariableHide.DontHide,
hide: 'dontHide',
includeAll: false,
label: 'Group By Variable',
multi: false,
@@ -351,7 +345,7 @@ export const handyTestingSchema: DashboardV2Spec = {
value: 'value3',
},
],
hide: VariableHide.DontHide,
hide: 'dontHide',
label: 'Adhoc Variable',
name: 'adhocVar',
skipUrlSync: false,