grafana / cog

Code Generation with a human touch
Apache License 2.0
43 stars 2 forks source link

[Terraform] Scalar support for models and datasources #497

Open malcolmholmes opened 3 months ago

malcolmholmes commented 3 months ago

Aim: full working support for scalar values. All that remains is support for schemas, then this should be in place.

github-actions[bot] commented 3 months ago

Note: in addition to the changes introduced by this PR, the diff includes unreleased changes living in main.

### 🔎 Changes to `grafana-foundation-sdk@next+cog-v0.0.x` ```patch diff --git a/php/src/Azuremonitor/AzureMonitorQuery.php b/php/src/Azuremonitor/AzureMonitorQuery.php index 97b672d..b53d1c6 100644 --- a/php/src/Azuremonitor/AzureMonitorQuery.php +++ b/php/src/Azuremonitor/AzureMonitorQuery.php @@ -159,26 +159,26 @@ class AzureMonitorQuery implements \JsonSerializable, \Grafana\Foundation\Cog\Da \assert(is_array($input), 'expected disjunction value to be an array'); switch ($input["kind"]) { - case "MetricDefinitionsQuery": - return MetricDefinitionsQuery::fromArray($input); - case "AppInsightsGroupByQuery": - return AppInsightsGroupByQuery::fromArray($input); - case "ResourceGroupsQuery": - return ResourceGroupsQuery::fromArray($input); - case "WorkspacesQuery": - return WorkspacesQuery::fromArray($input); - case "SubscriptionsQuery": - return SubscriptionsQuery::fromArray($input); case "ResourceNamesQuery": return ResourceNamesQuery::fromArray($input); - case "AppInsightsMetricNameQuery": - return AppInsightsMetricNameQuery::fromArray($input); - case "MetricNamespaceQuery": - return MetricNamespaceQuery::fromArray($input); + case "WorkspacesQuery": + return WorkspacesQuery::fromArray($input); case "MetricNamesQuery": return MetricNamesQuery::fromArray($input); + case "SubscriptionsQuery": + return SubscriptionsQuery::fromArray($input); case "UnknownQuery": return UnknownQuery::fromArray($input); + case "AppInsightsGroupByQuery": + return AppInsightsGroupByQuery::fromArray($input); + case "ResourceGroupsQuery": + return ResourceGroupsQuery::fromArray($input); + case "MetricNamespaceQuery": + return MetricNamespaceQuery::fromArray($input); + case "AppInsightsMetricNameQuery": + return AppInsightsMetricNameQuery::fromArray($input); + case "MetricDefinitionsQuery": + return MetricDefinitionsQuery::fromArray($input); default: throw new \ValueError('can not parse disjunction from array'); } diff --git a/php/src/Common/TableFieldOptions.php b/php/src/Common/TableFieldOptions.php index 9d9d692..ba25627 100644 --- a/php/src/Common/TableFieldOptions.php +++ b/php/src/Common/TableFieldOptions.php @@ -78,12 +78,6 @@ class TableFieldOptions implements \JsonSerializable \assert(is_array($input), 'expected disjunction value to be an array'); switch ($input["type"]) { - case "image": - return TableImageCellOptions::fromArray($input); - case "data-links": - return TableDataLinksCellOptions::fromArray($input); - case "json-view": - return TableJsonViewCellOptions::fromArray($input); case "auto": return TableAutoCellOptions::fromArray($input); case "sparkline": @@ -94,6 +88,12 @@ class TableFieldOptions implements \JsonSerializable return TableColoredBackgroundCellOptions::fromArray($input); case "color-text": return TableColorTextCellOptions::fromArray($input); + case "image": + return TableImageCellOptions::fromArray($input); + case "data-links": + return TableDataLinksCellOptions::fromArray($input); + case "json-view": + return TableJsonViewCellOptions::fromArray($input); default: throw new \ValueError('can not parse disjunction from array'); } diff --git a/php/src/Dashboard/FieldConfig.php b/php/src/Dashboard/FieldConfig.php index b960b65..a02d949 100644 --- a/php/src/Dashboard/FieldConfig.php +++ b/php/src/Dashboard/FieldConfig.php @@ -170,14 +170,14 @@ class FieldConfig implements \JsonSerializable \assert(is_array($input), 'expected disjunction value to be an array'); switch ($input["type"]) { + case "regex": + return RegexMap::fromArray($input); case "special": return SpecialValueMap::fromArray($input); case "value": return ValueMap::fromArray($input); case "range": return RangeMap::fromArray($input); - case "regex": - return RegexMap::fromArray($input); default: throw new \ValueError('can not parse disjunction from array'); } diff --git a/php/src/Elasticsearch/Dataquery.php b/php/src/Elasticsearch/Dataquery.php index 6484d0c..5d9889c 100644 --- a/php/src/Elasticsearch/Dataquery.php +++ b/php/src/Elasticsearch/Dataquery.php @@ -97,6 +97,8 @@ class Dataquery implements \JsonSerializable, \Grafana\Foundation\Cog\Dataquery \assert(is_array($input), 'expected disjunction value to be an array'); switch ($input["type"]) { + case "terms": + return Terms::fromArray($input); case "filters": return Filters::fromArray($input); case "geohash_grid": @@ -107,8 +109,6 @@ class Dataquery implements \JsonSerializable, \Grafana\Foundation\Cog\Dataquery return DateHistogram::fromArray($input); case "histogram": return Histogram::fromArray($input); - case "terms": - return Terms::fromArray($input); default: throw new \ValueError('can not parse disjunction from array'); } @@ -117,42 +117,42 @@ class Dataquery implements \JsonSerializable, \Grafana\Foundation\Cog\Dataquery \assert(is_array($input), 'expected disjunction value to be an array'); switch ($input["type"]) { - case "percentiles": - return Percentiles::fromArray($input); - case "max": - return Max::fromArray($input); - case "moving_avg": - return MovingAverage::fromArray($input); - case "logs": - return Logs::fromArray($input); - case "bucket_script": - return BucketScript::fromArray($input); - case "min": - return Min::fromArray($input); - case "top_metrics": - return TopMetrics::fromArray($input); - case "count": - return Count::fromArray($input); case "derivative": return Derivative::fromArray($input); case "raw_document": return RawDocument::fromArray($input); + case "top_metrics": + return TopMetrics::fromArray($input); + case "min": + return Min::fromArray($input); + case "moving_avg": + return MovingAverage::fromArray($input); case "raw_data": return RawData::fromArray($input); - case "extended_stats": - return ExtendedStats::fromArray($input); - case "serial_diff": - return SerialDiff::fromArray($input); - case "avg": - return Average::fromArray($input); case "moving_fn": return MovingFunction::fromArray($input); - case "sum": - return Sum::fromArray($input); case "cardinality": return UniqueCount::fromArray($input); + case "percentiles": + return Percentiles::fromArray($input); + case "sum": + return Sum::fromArray($input); case "cumulative_sum": return CumulativeSum::fromArray($input); + case "bucket_script": + return BucketScript::fromArray($input); + case "count": + return Count::fromArray($input); + case "extended_stats": + return ExtendedStats::fromArray($input); + case "max": + return Max::fromArray($input); + case "logs": + return Logs::fromArray($input); + case "serial_diff": + return SerialDiff::fromArray($input); + case "avg": + return Average::fromArray($input); case "rate": return Rate::fromArray($input); default: diff --git a/python/grafana_foundation_sdk/cog/plugins.py b/python/grafana_foundation_sdk/cog/plugins.py index 9173245..fbaa019 100644 --- a/python/grafana_foundation_sdk/cog/plugins.py +++ b/python/grafana_foundation_sdk/cog/plugins.py @@ -1,39 +1,39 @@ # Code generated - EDITING IS FUTILE. DO NOT EDIT. -from ..models import gauge -from ..models import nodegraph -from ..models import statetimeline -from ..models import tempo -from ..models import expr -from ..models import cloudwatch -from ..models import debug -from ..models import googlecloudmonitoring -from ..models import parca -from ..models import stat -from ..models import statushistory -from ..models import table -from ..models import trend -from ..models import prometheus -from ..models import barchart -from ..models import dashboardlist -from ..models import grafanapyroscope -from ..models import news -from ..models import piechart from ..models import annotationslist -from ..models import datagrid from ..models import elasticsearch -from ..models import logs -from ..models import xychart -from ..models import bargauge +from ..models import news +from ..models import piechart +from ..models import prometheus +from ..models import table +from ..models import azuremonitor from ..models import canvas +from ..models import gauge +from ..models import grafanapyroscope from ..models import loki -from ..models import text +from ..models import stat +from ..models import dashboardlist +from ..models import debug +from ..models import googlecloudmonitoring +from ..models import heatmap from ..models import timeseries -from ..models import azuremonitor +from ..models import expr +from ..models import datagrid +from ..models import parca +from ..models import trend from ..models import candlestick +from ..models import tempo +from ..models import bargauge +from ..models import xychart +from ..models import nodegraph +from ..models import statetimeline +from ..models import barchart +from ..models import cloudwatch from ..models import geomap -from ..models import heatmap from ..models import histogram +from ..models import logs +from ..models import statushistory +from ..models import text from . import runtime as cogruntime diff --git a/python/grafana_foundation_sdk/models/cloudwatch.py b/python/grafana_foundation_sdk/models/cloudwatch.py index 8ef9b81..fac0fa9 100644 --- a/python/grafana_foundation_sdk/models/cloudwatch.py +++ b/python/grafana_foundation_sdk/models/cloudwatch.py @@ -332,7 +332,7 @@ class SQLExpression: if "select" in data: args["select"] = QueryEditorFunctionExpression.from_json(data["select"]) if "from" in data: - decoding_map: dict[str, typing.Union[typing.Type[QueryEditorFunctionExpression], typing.Type[QueryEditorPropertyExpression]]] = {"function": QueryEditorFunctionExpression, "property": QueryEditorPropertyExpression} + decoding_map: dict[str, typing.Union[typing.Type[QueryEditorPropertyExpression], typing.Type[QueryEditorFunctionExpression]]] = {"property": QueryEditorPropertyExpression, "function": QueryEditorFunctionExpression} args["from_val"] = decoding_map[data["from"]["type"]].from_json(data["from"]) if "where" in data: args["where"] = QueryEditorArrayExpression.from_json(data["where"]) diff --git a/python/grafana_foundation_sdk/models/expr.py b/python/grafana_foundation_sdk/models/expr.py index 5dd1737..6e1a9ac 100644 --- a/python/grafana_foundation_sdk/models/expr.py +++ b/python/grafana_foundation_sdk/models/expr.py @@ -9,7 +9,7 @@ Expr: typing.TypeAlias = typing.Union['TypeMath', 'TypeReduce', 'TypeResample', def variant_config() -> cogruntime.DataqueryConfig: - decoding_map: dict[str, typing.Union[typing.Type[TypeMath], typing.Type[TypeReduce], typing.Type[TypeResample], typing.Type[TypeClassicConditions], typing.Type[TypeThreshold], typing.Type[TypeSql]]] = {"math": TypeMath, "reduce": TypeReduce, "resample": TypeResample, "classic_conditions": TypeClassicConditions, "threshold": TypeThreshold, "sql": TypeSql} + decoding_map: dict[str, typing.Union[typing.Type[TypeThreshold], typing.Type[TypeSql], typing.Type[TypeMath], typing.Type[TypeReduce], typing.Type[TypeResample], typing.Type[TypeClassicConditions]]] = {"threshold": TypeThreshold, "sql": TypeSql, "math": TypeMath, "reduce": TypeReduce, "resample": TypeResample, "classic_conditions": TypeClassicConditions} return cogruntime.DataqueryConfig( identifier="__expr__", from_json_hook=lambda data: decoding_map[data["type"]].from_json(data), diff --git a/python/pyproject.toml b/python/pyproject.toml index 6b7fe61..cf1039a 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -13,7 +13,7 @@ keywords = [ "traces", "metrics" ] -version = "1719329203!next" +version = "1719845990!next" dependencies = [] requires-python = ">=3.11" classifiers = [ diff --git a/typescript/package.json b/typescript/package.json index eb652bd..cef80c4 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@grafana/grafana-foundation-sdk", - "version": "next-cogv0.0.x.1719329203", + "version": "next-cogv0.0.x.1719845990", "description": "A set of tools, types and libraries for building and manipulating Grafana objects.", "keywords": [ "observability", ```