@perses-dev/core 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants/dashboard-defaults.js +6 -2
- package/dist/cjs/constants/dialog.js +3 -1
- package/dist/cjs/constants/index.js +11 -9
- package/dist/cjs/index.js +12 -10
- package/dist/cjs/model/calculations.js +61 -51
- package/dist/cjs/model/index.js +28 -26
- package/dist/cjs/model/legend.js +39 -19
- package/dist/cjs/model/resource.js +9 -0
- package/dist/cjs/model/time-series-queries.js +3 -1
- package/dist/cjs/model/time.js +147 -64
- package/dist/cjs/model/units/bytes.js +37 -25
- package/dist/cjs/model/units/constants.js +3 -1
- package/dist/cjs/model/units/decimal.js +22 -16
- package/dist/cjs/model/units/index.js +13 -11
- package/dist/cjs/model/units/percent.js +26 -19
- package/dist/cjs/model/units/time.js +99 -38
- package/dist/cjs/model/units/types.js +3 -1
- package/dist/cjs/model/units/units.js +67 -43
- package/dist/cjs/model/units/utils.js +13 -7
- package/dist/cjs/model/variables.js +16 -3
- package/dist/cjs/utils/event.js +3 -1
- package/dist/cjs/utils/fetch.js +12 -4
- package/dist/cjs/utils/index.js +17 -14
- package/dist/cjs/utils/is-empty-object.js +3 -1
- package/dist/cjs/utils/mathjs.js +3 -1
- package/dist/cjs/utils/memo.js +10 -6
- package/dist/cjs/utils/panel-refs.js +9 -3
- package/dist/cjs/utils/text.js +39 -14
- package/dist/cjs/utils/time-series-data.js +21 -11
- package/dist/cjs/utils/types.js +16 -0
- package/dist/constants/dashboard-defaults.js.map +1 -1
- package/dist/constants/dialog.js.map +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/calculations.d.ts +9 -9
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +46 -46
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +20 -4
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/display.d.ts +1 -1
- package/dist/model/display.d.ts.map +1 -1
- package/dist/model/display.js.map +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +6 -6
- package/dist/model/legend.js +9 -9
- package/dist/model/legend.js.map +1 -1
- package/dist/model/panels.d.ts +5 -2
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/query.d.ts +13 -2
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js.map +1 -1
- package/dist/model/resource.d.ts +3 -2
- package/dist/model/resource.d.ts.map +1 -1
- package/dist/model/resource.js +3 -1
- package/dist/model/resource.js.map +1 -1
- package/dist/model/thresholds.d.ts +2 -2
- package/dist/model/thresholds.d.ts.map +1 -1
- package/dist/model/thresholds.js.map +1 -1
- package/dist/model/time-series-data.d.ts +6 -0
- package/dist/model/time-series-data.d.ts.map +1 -1
- package/dist/model/time-series-data.js.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/time.d.ts +3 -0
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +115 -55
- package/dist/model/time.js.map +1 -1
- package/dist/model/units/bytes.d.ts +8 -8
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +27 -21
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +8 -8
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +14 -14
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/index.js.map +1 -1
- package/dist/model/units/percent.d.ts +7 -7
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +17 -16
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +15 -15
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +87 -34
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +14 -5
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +37 -30
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +41 -35
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts +2 -2
- package/dist/model/units/utils.d.ts.map +1 -1
- package/dist/model/units/utils.js +4 -4
- package/dist/model/units/utils.js.map +1 -1
- package/dist/model/variables.d.ts +25 -7
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +3 -0
- package/dist/model/variables.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/event.js.map +1 -1
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-empty-object.js.map +1 -1
- package/dist/utils/mathjs.js.map +1 -1
- package/dist/utils/memo.js +2 -2
- package/dist/utils/memo.js.map +1 -1
- package/dist/utils/panel-refs.js.map +1 -1
- package/dist/utils/text.d.ts +15 -3
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +29 -10
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/time-series-data.d.ts +1 -1
- package/dist/utils/time-series-data.d.ts.map +1 -1
- package/dist/utils/time-series-data.js +7 -7
- package/dist/utils/time-series-data.js.map +1 -1
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +15 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants/dashboard-defaults.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '../model';\n\nexport const DEFAULT_DASHBOARD_DURATION: DurationString = '1h';\n\nexport const DEFAULT_REFRESH_INTERVAL: DurationString = '0s';\n"],"names":["DEFAULT_DASHBOARD_DURATION","DEFAULT_REFRESH_INTERVAL"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,
|
|
1
|
+
{"version":3,"sources":["../../src/constants/dashboard-defaults.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '../model';\n\nexport const DEFAULT_DASHBOARD_DURATION: DurationString = '1h';\n\nexport const DEFAULT_REFRESH_INTERVAL: DurationString = '0s';\n"],"names":["DEFAULT_DASHBOARD_DURATION","DEFAULT_REFRESH_INTERVAL"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,6BAA6C,KAAK;AAE/D,OAAO,MAAMC,2BAA2C,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants/dialog.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport const SAVE_DEFAULTS_DIALOG_TEXT =\n 'You have made changes to the time range or the variables values. Would you like to save these as defaults?';\n"],"names":["SAVE_DEFAULTS_DIALOG_TEXT"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,MAAMA,
|
|
1
|
+
{"version":3,"sources":["../../src/constants/dialog.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport const SAVE_DEFAULTS_DIALOG_TEXT =\n 'You have made changes to the time range or the variables values. Would you like to save these as defaults?';\n"],"names":["SAVE_DEFAULTS_DIALOG_TEXT"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,MAAMA,4BACX,6GAA6G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-defaults';\nexport * from './dialog';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard-defaults';\nexport * from './dialog';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB;AACrC,cAAc,WAAW"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './constants';\nexport * from './model';\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './constants';\nexport * from './model';\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,UAAU"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { TimeSeriesValueTuple } from '@perses-dev/core';
|
|
2
|
+
export declare const DEFAULT_CALCULATION: CalculationType;
|
|
2
3
|
export declare const CalculationsMap: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
first: typeof first;
|
|
5
|
+
last: typeof last;
|
|
6
|
+
'first-number': typeof firstNumber;
|
|
7
|
+
'last-number': typeof lastNumber;
|
|
8
|
+
mean: typeof mean;
|
|
9
|
+
sum: typeof sum;
|
|
10
|
+
min: typeof min;
|
|
11
|
+
max: typeof max;
|
|
11
12
|
};
|
|
12
13
|
export declare type CalculationType = keyof typeof CalculationsMap;
|
|
13
14
|
export declare type CalculationConfig = {
|
|
@@ -15,7 +16,6 @@ export declare type CalculationConfig = {
|
|
|
15
16
|
description: string;
|
|
16
17
|
};
|
|
17
18
|
export declare const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>>;
|
|
18
|
-
export declare const DEFAULT_CALCULATION: CalculationType;
|
|
19
19
|
declare type CalculationValue = number | null | undefined;
|
|
20
20
|
/**
|
|
21
21
|
* Calculate a multiple values for a set of time series data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAiC3E,CAAC;AAEX,
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,mBAAmB,EAAE,eAA+B,CAAC;AAElE,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAiC3E,CAAC;AAEX,aAAK,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,SAAS,eAAe,EAAE,EACpE,MAAM,EAAE,oBAAoB,EAAE,EAC9B,mBAAmB,EAAE,YAAY,GAChC,MAAM,CAGP,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,EAC9C,gBAAgB,CACjB,CA2EA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,WAAW,EAAE,eAAe,oBAE1F;AAED,iBAAS,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE/D;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAErE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAEpE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D"}
|
|
@@ -10,51 +10,51 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
export const DEFAULT_CALCULATION = 'last-number';
|
|
13
14
|
export const CalculationsMap = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
first: first,
|
|
16
|
+
last: last,
|
|
17
|
+
'first-number': firstNumber,
|
|
18
|
+
'last-number': lastNumber,
|
|
19
|
+
mean: mean,
|
|
20
|
+
sum: sum,
|
|
21
|
+
min: min,
|
|
22
|
+
max: max
|
|
22
23
|
};
|
|
23
24
|
export const CALCULATIONS_CONFIG = {
|
|
24
|
-
|
|
25
|
+
first: {
|
|
25
26
|
label: 'First',
|
|
26
27
|
description: 'First value'
|
|
27
28
|
},
|
|
28
|
-
|
|
29
|
+
last: {
|
|
29
30
|
label: 'Last',
|
|
30
31
|
description: 'Last value'
|
|
31
32
|
},
|
|
32
|
-
|
|
33
|
+
'first-number': {
|
|
33
34
|
label: 'First *',
|
|
34
35
|
description: 'First numeric value'
|
|
35
36
|
},
|
|
36
|
-
|
|
37
|
+
'last-number': {
|
|
37
38
|
label: 'Last *',
|
|
38
39
|
description: 'Last numeric value'
|
|
39
40
|
},
|
|
40
|
-
|
|
41
|
+
mean: {
|
|
41
42
|
label: 'Avg',
|
|
42
43
|
description: 'Average value excluding nulls'
|
|
43
44
|
},
|
|
44
|
-
|
|
45
|
+
sum: {
|
|
45
46
|
label: 'Sum',
|
|
46
47
|
description: 'The sum of all values'
|
|
47
48
|
},
|
|
48
|
-
|
|
49
|
+
min: {
|
|
49
50
|
label: 'Min',
|
|
50
51
|
description: 'Minimum value'
|
|
51
52
|
},
|
|
52
|
-
|
|
53
|
+
max: {
|
|
53
54
|
label: 'Max',
|
|
54
55
|
description: 'Maximum value'
|
|
55
56
|
}
|
|
56
57
|
};
|
|
57
|
-
export const DEFAULT_CALCULATION = 'Sum';
|
|
58
58
|
/**
|
|
59
59
|
* Calculate a multiple values for a set of time series data.
|
|
60
60
|
*
|
|
@@ -73,55 +73,55 @@ export const DEFAULT_CALCULATION = 'Sum';
|
|
|
73
73
|
// in a single iteration of the data to minimize the performance impact of
|
|
74
74
|
// generating multiple calculations for large timeseries values. This is
|
|
75
75
|
// less optimized for certain single calculations when done in isolation (e.g.
|
|
76
|
-
// `
|
|
76
|
+
// `last`), but will be more performant in the more expensive cases where
|
|
77
77
|
// multiple values are being used (e.g. table legend).
|
|
78
78
|
values.forEach((tuple, i)=>{
|
|
79
79
|
const value = tuple[1];
|
|
80
|
-
if (i === 0 && '
|
|
81
|
-
calculations.
|
|
80
|
+
if (i === 0 && 'first' in calculations) {
|
|
81
|
+
calculations.first = value;
|
|
82
82
|
}
|
|
83
|
-
if (i === values.length - 1 && '
|
|
84
|
-
calculations.
|
|
83
|
+
if (i === values.length - 1 && 'last' in calculations) {
|
|
84
|
+
calculations.last = value;
|
|
85
85
|
}
|
|
86
86
|
// Handling specific to non-null values.
|
|
87
87
|
if (typeof value === 'number') {
|
|
88
88
|
nonNullCount += 1;
|
|
89
89
|
sum += value;
|
|
90
|
-
if ('
|
|
90
|
+
if ('first-number' in calculations && calculations['first-number'] === undefined) {
|
|
91
91
|
// Save the first number we see.
|
|
92
|
-
calculations
|
|
92
|
+
calculations['first-number'] = value;
|
|
93
93
|
}
|
|
94
|
-
if ('
|
|
94
|
+
if ('last-number' in calculations) {
|
|
95
95
|
// Keep setting the numbers we see, which will eventually be set to the
|
|
96
96
|
// last number when finished iterating.
|
|
97
|
-
calculations
|
|
97
|
+
calculations['last-number'] = value;
|
|
98
98
|
}
|
|
99
|
-
if ('
|
|
100
|
-
if (typeof calculations.
|
|
99
|
+
if ('min' in calculations) {
|
|
100
|
+
if (typeof calculations.min !== 'number') {
|
|
101
101
|
// Init the first time we see a number
|
|
102
|
-
calculations.
|
|
102
|
+
calculations.min = value;
|
|
103
103
|
} else {
|
|
104
104
|
// Use lowest value once initialized
|
|
105
|
-
calculations.
|
|
105
|
+
calculations.min = Math.min(calculations.min, value);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
if ('
|
|
109
|
-
if (typeof calculations.
|
|
108
|
+
if ('max' in calculations) {
|
|
109
|
+
if (typeof calculations.max !== 'number') {
|
|
110
110
|
// Init the first time we see a number
|
|
111
|
-
calculations.
|
|
111
|
+
calculations.max = value;
|
|
112
112
|
} else {
|
|
113
113
|
// Use highest value once initialized
|
|
114
|
-
calculations.
|
|
114
|
+
calculations.max = Math.max(calculations.max, value);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
// Set calculations that require iterating over all values.
|
|
120
|
-
if (nonNullCount > 0 && '
|
|
121
|
-
calculations.
|
|
120
|
+
if (nonNullCount > 0 && 'sum' in calculations) {
|
|
121
|
+
calculations.sum = sum;
|
|
122
122
|
}
|
|
123
|
-
if (nonNullCount > 0 && '
|
|
124
|
-
calculations.
|
|
123
|
+
if (nonNullCount > 0 && 'mean' in calculations) {
|
|
124
|
+
calculations.mean = sum / nonNullCount;
|
|
125
125
|
}
|
|
126
126
|
return calculations;
|
|
127
127
|
}
|
|
@@ -138,28 +138,28 @@ export const DEFAULT_CALCULATION = 'Sum';
|
|
|
138
138
|
])[calculation];
|
|
139
139
|
}
|
|
140
140
|
function first(values) {
|
|
141
|
-
return getCalculation(values, '
|
|
141
|
+
return getCalculation(values, 'first');
|
|
142
142
|
}
|
|
143
143
|
function last(values) {
|
|
144
|
-
return getCalculation(values, '
|
|
144
|
+
return getCalculation(values, 'last');
|
|
145
145
|
}
|
|
146
146
|
function firstNumber(values) {
|
|
147
|
-
return getCalculation(values, '
|
|
147
|
+
return getCalculation(values, 'first-number');
|
|
148
148
|
}
|
|
149
149
|
function lastNumber(values) {
|
|
150
|
-
return getCalculation(values, '
|
|
150
|
+
return getCalculation(values, 'last-number');
|
|
151
151
|
}
|
|
152
152
|
function mean(values) {
|
|
153
|
-
return getCalculation(values, '
|
|
153
|
+
return getCalculation(values, 'mean');
|
|
154
154
|
}
|
|
155
155
|
function sum(values) {
|
|
156
|
-
return getCalculation(values, '
|
|
156
|
+
return getCalculation(values, 'sum');
|
|
157
157
|
}
|
|
158
158
|
function min(values) {
|
|
159
|
-
return getCalculation(values, '
|
|
159
|
+
return getCalculation(values, 'min');
|
|
160
160
|
}
|
|
161
161
|
function max(values) {
|
|
162
|
-
return getCalculation(values, '
|
|
162
|
+
return getCalculation(values, 'max');
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
//# sourceMappingURL=calculations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","DEFAULT_CALCULATION","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,WAAW,EAAEC,WAAW;IACxBC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;CACT,CAAC;AASF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFhB,KAAK,EAAE;QACLiB,KAAK,E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;AAED,SAASR,GAAG,CAACQ,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASN,GAAG,CAACM,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const DEFAULT_CALCULATION: CalculationType = 'last-number';\n\nexport const CalculationsMap = {\n first: first,\n last: last,\n 'first-number': firstNumber,\n 'last-number': lastNumber,\n mean: mean,\n sum: sum,\n min: min,\n max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n first: {\n label: 'First',\n description: 'First value',\n },\n last: {\n label: 'Last',\n description: 'Last value',\n },\n 'first-number': {\n label: 'First *',\n description: 'First numeric value',\n },\n 'last-number': {\n label: 'Last *',\n description: 'Last numeric value',\n },\n mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n min: {\n label: 'Min',\n description: 'Minimum value',\n },\n max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'first' in calculations) {\n calculations.first = value;\n }\n if (i === values.length - 1 && 'last' in calculations) {\n calculations.last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('first-number' in calculations && calculations['first-number'] === undefined) {\n // Save the first number we see.\n calculations['first-number'] = value;\n }\n\n if ('last-number' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations['last-number'] = value;\n }\n\n if ('min' in calculations) {\n if (typeof calculations.min !== 'number') {\n // Init the first time we see a number\n calculations.min = value;\n } else {\n // Use lowest value once initialized\n calculations.min = Math.min(calculations.min, value);\n }\n }\n\n if ('max' in calculations) {\n if (typeof calculations.max !== 'number') {\n // Init the first time we see a number\n calculations.max = value;\n } else {\n // Use highest value once initialized\n calculations.max = Math.max(calculations.max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'sum' in calculations) {\n calculations.sum = sum;\n }\n\n if (nonNullCount > 0 && 'mean' in calculations) {\n calculations.mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'first');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'first-number');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'last-number');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'max');\n}\n"],"names":["DEFAULT_CALCULATION","CalculationsMap","first","last","firstNumber","lastNumber","mean","sum","min","max","CALCULATIONS_CONFIG","label","description","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,sBAAuC,cAAc;AAElE,OAAO,MAAMC,kBAAkB;IAC7BC,OAAOA;IACPC,MAAMA;IACN,gBAAgBC;IAChB,eAAeC;IACfC,MAAMA;IACNC,KAAKA;IACLC,KAAKA;IACLC,KAAKA;AACP,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asource {
|
|
|
10
10
|
spec: DatasourceSpec;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* A Datasource that belongs to a project.
|
|
13
|
+
* A Datasource resource, that belongs to a project.
|
|
14
14
|
*/
|
|
15
|
-
export interface
|
|
15
|
+
export interface ProjectDatasource {
|
|
16
16
|
kind: 'Datasource';
|
|
17
17
|
metadata: ProjectMetadata;
|
|
18
18
|
spec: DatasourceSpec;
|
|
19
19
|
}
|
|
20
|
+
export declare type Datasource = ProjectDatasource | GlobalDatasource;
|
|
20
21
|
export interface DatasourceSpec<PluginSpec = UnknownSpec> {
|
|
21
22
|
display?: Display;
|
|
22
23
|
default: boolean;
|
|
23
24
|
plugin: Definition<PluginSpec>;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
* A selector for pointing at a specific Datasource.
|
|
27
|
-
* Datasource for the specified kind.
|
|
27
|
+
* A selector for pointing at a specific Datasource.
|
|
28
28
|
*/
|
|
29
29
|
export interface DatasourceSelector {
|
|
30
|
+
/**
|
|
31
|
+
* Kind of the datasource.
|
|
32
|
+
*/
|
|
30
33
|
kind: string;
|
|
34
|
+
/**
|
|
35
|
+
* Group of the datasource.
|
|
36
|
+
* Omit it if you don't store datasource by group.
|
|
37
|
+
* TODO: This group field is fairly ignored by the backend data model.
|
|
38
|
+
* We need to decouple properly the backend and frontend data models.
|
|
39
|
+
* A Zustand store would certainly help here to decouple definition from the backend and state from the UI.
|
|
40
|
+
* => See Variable Store
|
|
41
|
+
*/
|
|
42
|
+
group?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Name of the datasource.
|
|
45
|
+
* If omitted, it's assumed that you target the default datasource for the specified kind (and group, if set)
|
|
46
|
+
*/
|
|
31
47
|
name?: string;
|
|
32
48
|
}
|
|
33
49
|
//# sourceMappingURL=datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"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OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/datasource.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource that belongs to a project.\n */\nexport interface
|
|
1
|
+
{"version":3,"sources":["../../src/model/datasource.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource resource, that belongs to a project.\n */\nexport interface ProjectDatasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport type Datasource = ProjectDatasource | GlobalDatasource;\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource.\n */\nexport interface DatasourceSelector {\n /**\n * Kind of the datasource.\n */\n kind: string;\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n * TODO: This group field is fairly ignored by the backend data model.\n * We need to decouple properly the backend and frontend data models.\n * A Zustand store would certainly help here to decouple definition from the backend and state from the UI.\n * => See Variable Store\n */\n group?: string;\n /**\n * Name of the datasource.\n * If omitted, it's assumed that you target the default datasource for the specified kind (and group, if set)\n */\n name?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAoDC"}
|
package/dist/model/display.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../src/model/display.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../src/model/display.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/display.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface Display {\n name
|
|
1
|
+
{"version":3,"sources":["../../src/model/display.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface Display {\n name?: string;\n description?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAGC"}
|
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './project';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './units';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './project';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './units';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,iBAAiB;AAC/B,cAAc,cAAc;AAC5B,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,WAAW;AACzB,cAAc,WAAW;AACzB,cAAc,WAAW;AACzB,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,UAAU;AACxB,cAAc,aAAa;AAC3B,cAAc,eAAe;AAC7B,cAAc,SAAS;AACvB,cAAc,qBAAqB;AACnC,cAAc,wBAAwB;AACtC,cAAc,UAAU;AACxB,cAAc,cAAc"}
|
package/dist/model/legend.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare const legendPositions: readonly ["
|
|
1
|
+
export declare const legendPositions: readonly ["bottom", "right"];
|
|
2
2
|
export declare type LegendPositions = (typeof legendPositions)[number];
|
|
3
|
-
export declare const legendModes: readonly ["
|
|
3
|
+
export declare const legendModes: readonly ["list", "table"];
|
|
4
4
|
export declare type LegendMode = (typeof legendModes)[number];
|
|
5
|
-
export declare const legendSizes: readonly ["
|
|
5
|
+
export declare const legendSizes: readonly ["small", "medium"];
|
|
6
6
|
export declare type LegendSize = (typeof legendSizes)[number];
|
|
7
7
|
export interface LegendOptionsBase {
|
|
8
8
|
position: LegendPositions;
|
|
@@ -13,7 +13,7 @@ export declare function isValidLegendPosition(position: LegendPositions): boolea
|
|
|
13
13
|
export declare function isValidLegendMode(mode: LegendMode): boolean;
|
|
14
14
|
export declare function isValidLegendSize(size: LegendSize): boolean;
|
|
15
15
|
export declare const DEFAULT_LEGEND: Required<LegendOptionsBase>;
|
|
16
|
-
export declare function getLegendPosition(position?: LegendPositions): "
|
|
17
|
-
export declare function getLegendMode(mode?: LegendMode): "
|
|
18
|
-
export declare function getLegendSize(size?: LegendSize): "
|
|
16
|
+
export declare function getLegendPosition(position?: LegendPositions): "bottom" | "right";
|
|
17
|
+
export declare function getLegendMode(mode?: LegendMode): "list" | "table";
|
|
18
|
+
export declare function getLegendSize(size?: LegendSize): "small" | "medium";
|
|
19
19
|
//# sourceMappingURL=legend.d.ts.map
|
package/dist/model/legend.js
CHANGED
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
// component and the `plugin-system` package for legend model code specific to
|
|
16
16
|
// panel plugin specs.
|
|
17
17
|
export const legendPositions = [
|
|
18
|
-
'
|
|
19
|
-
'
|
|
18
|
+
'bottom',
|
|
19
|
+
'right'
|
|
20
20
|
];
|
|
21
21
|
export const legendModes = [
|
|
22
|
-
'
|
|
23
|
-
'
|
|
22
|
+
'list',
|
|
23
|
+
'table'
|
|
24
24
|
];
|
|
25
25
|
export const legendSizes = [
|
|
26
|
-
'
|
|
27
|
-
'
|
|
26
|
+
'small',
|
|
27
|
+
'medium'
|
|
28
28
|
];
|
|
29
29
|
export function isValidLegendPosition(position) {
|
|
30
30
|
return legendPositions.includes(position);
|
|
@@ -36,9 +36,9 @@ export function isValidLegendSize(size) {
|
|
|
36
36
|
return legendSizes.includes(size);
|
|
37
37
|
}
|
|
38
38
|
export const DEFAULT_LEGEND = {
|
|
39
|
-
position: '
|
|
40
|
-
mode: '
|
|
41
|
-
size: '
|
|
39
|
+
position: 'bottom',
|
|
40
|
+
mode: 'list',
|
|
41
|
+
size: 'medium'
|
|
42
42
|
};
|
|
43
43
|
export function getLegendPosition(position) {
|
|
44
44
|
if (position === undefined) {
|
package/dist/model/legend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This file contains common/shared legend model code.\n// See the `components` package for legend model code specific to the Legend\n// component and the `plugin-system` package for legend model code specific to\n// panel plugin specs.\n\nexport const legendPositions = ['
|
|
1
|
+
{"version":3,"sources":["../../src/model/legend.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This file contains common/shared legend model code.\n// See the `components` package for legend model code specific to the Legend\n// component and the `plugin-system` package for legend model code specific to\n// panel plugin specs.\n\nexport const legendPositions = ['bottom', 'right'] as const;\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport const legendModes = ['list', 'table'] as const;\nexport type LegendMode = (typeof legendModes)[number];\n\nexport const legendSizes = ['small', 'medium'] as const;\nexport type LegendSize = (typeof legendSizes)[number];\n\n// Common legend options used across some UI components and panel specifications\nexport interface LegendOptionsBase {\n position: LegendPositions;\n mode?: LegendMode;\n size?: LegendSize;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function isValidLegendMode(mode: LegendMode) {\n return (legendModes as readonly string[]).includes(mode);\n}\n\nexport function isValidLegendSize(size: LegendSize) {\n return (legendSizes as readonly string[]).includes(size);\n}\n\nexport const DEFAULT_LEGEND: Required<LegendOptionsBase> = {\n position: 'bottom',\n mode: 'list',\n size: 'medium',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function getLegendMode(mode?: LegendMode) {\n if (!mode || !isValidLegendMode(mode)) {\n return DEFAULT_LEGEND.mode;\n }\n\n return mode;\n}\n\nexport function getLegendSize(size?: LegendSize) {\n if (!size || !isValidLegendSize(size)) {\n return DEFAULT_LEGEND.size;\n }\n\n return size;\n}\n"],"names":["legendPositions","legendModes","legendSizes","isValidLegendPosition","position","includes","isValidLegendMode","mode","isValidLegendSize","size","DEFAULT_LEGEND","getLegendPosition","undefined","getLegendMode","getLegendSize"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,sDAAsD;AACtD,4EAA4E;AAC5E,+EAA+E;AAC/E,sBAAsB;AAEtB,OAAO,MAAMA,kBAAkB;IAAC;IAAU;CAAQ,CAAU;AAG5D,OAAO,MAAMC,cAAc;IAAC;IAAQ;CAAQ,CAAU;AAGtD,OAAO,MAAMC,cAAc;IAAC;IAAS;CAAS,CAAU;AAUxD,OAAO,SAASC,sBAAsBC,QAAyB;IAC7D,OAAO,AAACJ,gBAAsCK,SAASD;AACzD;AAEA,OAAO,SAASE,kBAAkBC,IAAgB;IAChD,OAAO,AAACN,YAAkCI,SAASE;AACrD;AAEA,OAAO,SAASC,kBAAkBC,IAAgB;IAChD,OAAO,AAACP,YAAkCG,SAASI;AACrD;AAEA,OAAO,MAAMC,iBAA8C;IACzDN,UAAU;IACVG,MAAM;IACNE,MAAM;AACR,EAAE;AAEF,OAAO,SAASE,kBAAkBP,QAA0B;IAC1D,IAAIA,aAAaQ,WAAW;QAC1B,OAAOF,eAAeN;IACxB;IACA,IAAID,sBAAsBC,WAAW;QACnC,OAAOA;IACT;IACA,OAAOM,eAAeN;AACxB;AAEA,OAAO,SAASS,cAAcN,IAAiB;IAC7C,IAAI,CAACA,QAAQ,CAACD,kBAAkBC,OAAO;QACrC,OAAOG,eAAeH;IACxB;IAEA,OAAOA;AACT;AAEA,OAAO,SAASO,cAAcL,IAAiB;IAC7C,IAAI,CAACA,QAAQ,CAACD,kBAAkBC,OAAO;QACrC,OAAOC,eAAeD;IACxB;IAEA,OAAOA;AACT"}
|
package/dist/model/panels.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Definition, UnknownSpec } from './definitions';
|
|
2
|
-
import { Display } from './display';
|
|
3
2
|
import { QueryDefinition } from './query';
|
|
3
|
+
export interface PanelDisplay {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
}
|
|
4
7
|
export interface PanelDefinition<PluginSpec = UnknownSpec> extends Definition<PanelSpec<PluginSpec>> {
|
|
5
8
|
kind: 'Panel';
|
|
6
9
|
}
|
|
7
10
|
export interface PanelSpec<PluginSpec> {
|
|
8
|
-
display:
|
|
11
|
+
display: PanelDisplay;
|
|
9
12
|
plugin: Definition<PluginSpec>;
|
|
10
13
|
queries?: QueryDefinition[];
|
|
11
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/model/panels.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/model/panels.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe,CAAC,UAAU,GAAG,WAAW,CAAE,SAAQ,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAClG,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,SAAS,CAAC,UAAU;IACnC,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,iBAAiB,MAAM,EAAE,CAAC;CACjC"}
|
package/dist/model/panels.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/panels.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/model/panels.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { QueryDefinition } from './query';\n\nexport interface PanelDisplay {\n name: string;\n description?: string;\n}\n\nexport interface PanelDefinition<PluginSpec = UnknownSpec> extends Definition<PanelSpec<PluginSpec>> {\n kind: 'Panel';\n}\n\nexport interface PanelSpec<PluginSpec> {\n display: PanelDisplay;\n plugin: Definition<PluginSpec>;\n queries?: QueryDefinition[];\n}\n\n/**\n * A reference to a panel defined in the DashboardSpec.\n */\nexport interface PanelRef {\n $ref: `#/spec/panels/${string}`;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuBC"}
|
package/dist/model/query.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { Definition, UnknownSpec } from './definitions';
|
|
2
|
+
import { TimeSeriesData } from './time-series-data';
|
|
2
3
|
interface QuerySpec<PluginSpec> {
|
|
3
4
|
plugin: Definition<PluginSpec>;
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* A generic query definition interface that can be extended to support more than just TimeSeriesQuery
|
|
7
8
|
*/
|
|
8
|
-
export interface QueryDefinition<Kind =
|
|
9
|
+
export interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {
|
|
9
10
|
kind: Kind;
|
|
10
11
|
spec: QuerySpec<PluginSpec>;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Mapping the query plugin to the data type it returns
|
|
15
|
+
*/
|
|
16
|
+
export interface QueryType {
|
|
17
|
+
TimeSeriesQuery: TimeSeriesData;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Values of QueryType
|
|
21
|
+
* ex: 'TimeSeriesData'
|
|
22
|
+
*/
|
|
23
|
+
export declare type QueryDataType = QueryType[keyof QueryType];
|
|
13
24
|
export {};
|
|
14
25
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/model/query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/model/query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,UAAU,SAAS,CAAC,UAAU;IAC5B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AACD;;GAEG;AAGH,MAAM,WAAW,eAAe,CAAC,IAAI,GAAG,GAAG,EAAE,UAAU,GAAG,WAAW;IACnE,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,EAAE,cAAc,CAAC;CAGjC;AAED;;;GAGG;AACH,oBAAY,aAAa,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC"}
|
package/dist/model/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/query.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\n\ninterface QuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n/**\n * A generic query definition interface that can be extended to support more than just TimeSeriesQuery\n */\nexport interface QueryDefinition<Kind =
|
|
1
|
+
{"version":3,"sources":["../../src/model/query.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { TimeSeriesData } from './time-series-data';\n\ninterface QuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n/**\n * A generic query definition interface that can be extended to support more than just TimeSeriesQuery\n */\n// Kind needs to be `any` because otherwise typescript will complain 'unknown' is not assignable to type '\"TimeSeriesQuery\"' in a few places\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {\n kind: Kind;\n spec: QuerySpec<PluginSpec>;\n}\n\n/**\n * Mapping the query plugin to the data type it returns\n */\nexport interface QueryType {\n TimeSeriesQuery: TimeSeriesData;\n // in the future we can add other query plugin and data types\n // for example: we can add something like `LogsQuery: LogsData;`\n}\n\n/**\n * Values of QueryType\n * ex: 'TimeSeriesData'\n */\nexport type QueryDataType = QueryType[keyof QueryType];\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA6BuD"}
|