@perses-dev/core 0.0.0-snapshot-scatterplot-fix-imports-95e1b59 → 0.0.0-snapshot-explorer-plugin-c4a7621
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/index.js +1 -0
- package/dist/cjs/model/calculations.js +1 -1
- package/dist/cjs/model/index.js +3 -0
- package/dist/cjs/model/query.js +12 -0
- package/dist/cjs/model/resource.js +14 -3
- package/dist/cjs/model/time.js +9 -11
- package/dist/cjs/model/trace-data.js +29 -1
- package/dist/cjs/model/transforms.js +28 -0
- package/dist/cjs/model/units/bytes.js +0 -3
- package/dist/cjs/model/units/decimal.js +0 -3
- package/dist/cjs/model/units/percent.js +0 -5
- package/dist/cjs/model/units/throughput.js +18 -12
- package/dist/cjs/model/units/time.js +0 -10
- package/dist/cjs/model/units/types.js +0 -13
- package/dist/cjs/model/units/units.js +1 -1
- package/dist/cjs/model/user.js +16 -0
- package/dist/cjs/model/value-mapping.js +16 -0
- package/dist/cjs/schema/datasource.js +85 -0
- package/dist/cjs/schema/display.js +27 -0
- package/dist/cjs/schema/duration.js +25 -0
- package/dist/cjs/schema/index.js +40 -0
- package/dist/cjs/schema/metadata.js +41 -0
- package/dist/cjs/schema/panel.js +106 -0
- package/dist/cjs/schema/plugin.js +27 -0
- package/dist/cjs/schema/role.js +86 -0
- package/dist/cjs/schema/rolebinding.js +65 -0
- package/dist/cjs/schema/secret.js +174 -0
- package/dist/cjs/schema/user.js +57 -0
- package/dist/cjs/schema/variable.js +171 -0
- package/dist/cjs/utils/fetch.js +14 -20
- package/dist/cjs/utils/index.js +3 -0
- package/dist/cjs/utils/memo.js +1 -2
- package/dist/cjs/utils/regexp.js +54 -0
- package/dist/cjs/utils/text.js +21 -46
- package/dist/cjs/utils/transform-data.js +167 -0
- package/dist/cjs/utils/value-mapping.js +105 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/calculations.d.ts +1 -1
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +1 -1
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +8 -8
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/http.d.ts +5 -0
- package/dist/model/http.d.ts.map +1 -1
- package/dist/model/http.js.map +1 -1
- package/dist/model/index.d.ts +3 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +3 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +3 -3
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/panels.d.ts +17 -1
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/project.d.ts +5 -0
- package/dist/model/project.d.ts.map +1 -1
- package/dist/model/project.js.map +1 -1
- package/dist/model/query.d.ts +10 -0
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js +8 -3
- package/dist/model/query.js.map +1 -1
- package/dist/model/resource.d.ts +7 -0
- package/dist/model/resource.d.ts.map +1 -1
- package/dist/model/resource.js +3 -0
- package/dist/model/resource.js.map +1 -1
- package/dist/model/time-series-data.d.ts +1 -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.d.ts.map +1 -1
- package/dist/model/time.js +9 -11
- package/dist/model/time.js.map +1 -1
- package/dist/model/trace-data.d.ts +80 -7
- package/dist/model/trace-data.d.ts.map +1 -1
- package/dist/model/trace-data.js +7 -3
- package/dist/model/trace-data.js.map +1 -1
- package/dist/model/transforms.d.ts +34 -0
- package/dist/model/transforms.d.ts.map +1 -0
- package/dist/model/transforms.js +21 -0
- package/dist/model/transforms.js.map +1 -0
- package/dist/model/units/bytes.d.ts +1 -2
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +0 -3
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/decimal.d.ts +1 -2
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +0 -3
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/percent.d.ts +1 -2
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +0 -5
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/throughput.d.ts +1 -2
- package/dist/model/units/throughput.d.ts.map +1 -1
- package/dist/model/units/throughput.js +18 -12
- package/dist/model/units/throughput.js.map +1 -1
- package/dist/model/units/time.d.ts +1 -2
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +0 -10
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +1 -2
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js +1 -7
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +2 -0
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +1 -1
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts.map +1 -1
- package/dist/model/units/utils.js.map +1 -1
- package/dist/model/user.d.ts +21 -0
- package/dist/model/user.d.ts.map +1 -0
- package/dist/model/user.js +15 -0
- package/dist/model/user.js.map +1 -0
- package/dist/model/value-mapping.d.ts +35 -0
- package/dist/model/value-mapping.d.ts.map +1 -0
- package/dist/model/value-mapping.js +15 -0
- package/dist/model/value-mapping.js.map +1 -0
- package/dist/model/variables.d.ts +9 -8
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js.map +1 -1
- package/dist/schema/datasource.d.ts +61 -0
- package/dist/schema/datasource.d.ts.map +1 -0
- package/dist/schema/datasource.js +54 -0
- package/dist/schema/datasource.js.map +1 -0
- package/dist/schema/display.d.ts +12 -0
- package/dist/schema/display.d.ts.map +1 -0
- package/dist/schema/display.js +19 -0
- package/dist/schema/display.js.map +1 -0
- package/dist/schema/duration.d.ts +3 -0
- package/dist/schema/duration.d.ts.map +1 -0
- package/dist/schema/duration.js +17 -0
- package/dist/schema/duration.js.map +1 -0
- package/dist/schema/index.d.ts +12 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/metadata.d.ts +21 -0
- package/dist/schema/metadata.d.ts.map +1 -0
- package/dist/schema/metadata.js +22 -0
- package/dist/schema/metadata.js.map +1 -0
- package/dist/schema/panel.d.ts +13 -0
- package/dist/schema/panel.d.ts.map +1 -0
- package/dist/schema/panel.js +69 -0
- package/dist/schema/panel.js.map +1 -0
- package/dist/schema/plugin.d.ts +14 -0
- package/dist/schema/plugin.d.ts.map +1 -0
- package/dist/schema/plugin.js +19 -0
- package/dist/schema/plugin.js.map +1 -0
- package/dist/schema/role.d.ts +58 -0
- package/dist/schema/role.d.ts.map +1 -0
- package/dist/schema/role.js +61 -0
- package/dist/schema/role.js.map +1 -0
- package/dist/schema/rolebinding.d.ts +58 -0
- package/dist/schema/rolebinding.d.ts.map +1 -0
- package/dist/schema/rolebinding.js +40 -0
- package/dist/schema/rolebinding.js.map +1 -0
- package/dist/schema/secret.d.ts +1140 -0
- package/dist/schema/secret.d.ts.map +1 -0
- package/dist/schema/secret.js +152 -0
- package/dist/schema/secret.js.map +1 -0
- package/dist/schema/user.d.ts +8 -0
- package/dist/schema/user.d.ts.map +1 -0
- package/dist/schema/user.js +36 -0
- package/dist/schema/user.js.map +1 -0
- package/dist/schema/variable.d.ts +92 -0
- package/dist/schema/variable.d.ts.map +1 -0
- package/dist/schema/variable.js +119 -0
- package/dist/schema/variable.js.map +1 -0
- package/dist/utils/fetch.d.ts +5 -2
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +15 -21
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-empty-object.d.ts.map +1 -1
- package/dist/utils/is-empty-object.js.map +1 -1
- package/dist/utils/memo.d.ts.map +1 -1
- package/dist/utils/memo.js +1 -2
- package/dist/utils/memo.js.map +1 -1
- package/dist/utils/panel-refs.d.ts +2 -2
- package/dist/utils/panel-refs.d.ts.map +1 -1
- package/dist/utils/panel-refs.js.map +1 -1
- package/dist/utils/regexp.d.ts +11 -0
- package/dist/utils/regexp.d.ts.map +1 -0
- package/dist/utils/regexp.js +42 -0
- package/dist/utils/regexp.js.map +1 -0
- package/dist/utils/text.d.ts +7 -33
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +21 -52
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/time-series-data.d.ts.map +1 -1
- package/dist/utils/time-series-data.js.map +1 -1
- package/dist/utils/transform-data.d.ts +8 -0
- package/dist/utils/transform-data.d.ts.map +1 -0
- package/dist/utils/transform-data.js +221 -0
- package/dist/utils/transform-data.js.map +1 -0
- package/dist/utils/value-mapping.d.ts +3 -0
- package/dist/utils/value-mapping.d.ts.map +1 -0
- package/dist/utils/value-mapping.js +97 -0
- package/dist/utils/value-mapping.js.map +1 -0
- package/package.json +1 -1
package/dist/cjs/utils/fetch.js
CHANGED
|
@@ -36,28 +36,22 @@ _export(exports, {
|
|
|
36
36
|
return fetchJson;
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
function _define_property(obj, key, value) {
|
|
40
|
-
if (key in obj) {
|
|
41
|
-
Object.defineProperty(obj, key, {
|
|
42
|
-
value: value,
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
obj[key] = value;
|
|
49
|
-
}
|
|
50
|
-
return obj;
|
|
51
|
-
}
|
|
52
39
|
async function fetch(...args) {
|
|
53
40
|
const response = await global.fetch(...args);
|
|
54
41
|
if (response.ok === false) {
|
|
55
|
-
const
|
|
56
|
-
if (json
|
|
57
|
-
|
|
42
|
+
const contentType = response.headers.get('content-type');
|
|
43
|
+
if (contentType?.includes('application/json')) {
|
|
44
|
+
const json = await response.json();
|
|
45
|
+
if (json.error) {
|
|
46
|
+
throw new UserFriendlyError(json.error, response.status);
|
|
47
|
+
}
|
|
48
|
+
if (json.message) {
|
|
49
|
+
throw new UserFriendlyError(json.message, response.status);
|
|
50
|
+
}
|
|
58
51
|
}
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
const text = await response.text();
|
|
53
|
+
if (text) {
|
|
54
|
+
throw new UserFriendlyError(text, response.status);
|
|
61
55
|
}
|
|
62
56
|
throw new FetchError(response);
|
|
63
57
|
}
|
|
@@ -69,17 +63,17 @@ async function fetchJson(...args) {
|
|
|
69
63
|
return json;
|
|
70
64
|
}
|
|
71
65
|
class FetchError extends Error {
|
|
66
|
+
status;
|
|
72
67
|
constructor(response){
|
|
73
68
|
super(`${response.status} ${response.statusText}`);
|
|
74
|
-
_define_property(this, "status", void 0);
|
|
75
69
|
this.status = response.status;
|
|
76
70
|
Object.setPrototypeOf(this, FetchError.prototype);
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
class UserFriendlyError extends Error {
|
|
74
|
+
status;
|
|
80
75
|
constructor(message, status){
|
|
81
76
|
super(message);
|
|
82
|
-
_define_property(this, "status", void 0);
|
|
83
77
|
this.status = status;
|
|
84
78
|
Object.setPrototypeOf(this, UserFriendlyError.prototype);
|
|
85
79
|
}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -21,7 +21,10 @@ _export_star(require("./memo"), exports);
|
|
|
21
21
|
_export_star(require("./panel-refs"), exports);
|
|
22
22
|
_export_star(require("./text"), exports);
|
|
23
23
|
_export_star(require("./time-series-data"), exports);
|
|
24
|
+
_export_star(require("./transform-data"), exports);
|
|
25
|
+
_export_star(require("./value-mapping"), exports);
|
|
24
26
|
_export_star(require("./types"), exports);
|
|
27
|
+
_export_star(require("./regexp"), exports);
|
|
25
28
|
function _export_star(from, to) {
|
|
26
29
|
Object.keys(from).forEach(function(k) {
|
|
27
30
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/utils/memo.js
CHANGED
|
@@ -39,8 +39,7 @@ function useMemoized(factory, deps) {
|
|
|
39
39
|
const ref = (0, _react.useRef)();
|
|
40
40
|
let areEqual = true;
|
|
41
41
|
for(let i = 0; i < deps.length; i++){
|
|
42
|
-
|
|
43
|
-
if (((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.deps[i]) !== deps[i]) {
|
|
42
|
+
if (ref.current?.deps[i] !== deps[i]) {
|
|
44
43
|
areEqual = false;
|
|
45
44
|
break;
|
|
46
45
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2024 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
|
+
/**
|
|
14
|
+
* Checks if a string is a regex pattern.
|
|
15
|
+
*/ "use strict";
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
function _export(target, all) {
|
|
20
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: all[name]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
_export(exports, {
|
|
26
|
+
createRegexFromString: function() {
|
|
27
|
+
return createRegexFromString;
|
|
28
|
+
},
|
|
29
|
+
isRegexPattern: function() {
|
|
30
|
+
return isRegexPattern;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
function isRegexPattern(input) {
|
|
34
|
+
return Boolean(input?.startsWith('/'));
|
|
35
|
+
}
|
|
36
|
+
function createRegexFromString(input) {
|
|
37
|
+
if (!input) {
|
|
38
|
+
throw new Error('Input string cannot be empty');
|
|
39
|
+
}
|
|
40
|
+
if (!isRegexPattern(input)) {
|
|
41
|
+
return new RegExp(`^${input}$`);
|
|
42
|
+
}
|
|
43
|
+
const regexPattern = /^\/(.+)\/([gimy]*)$/;
|
|
44
|
+
const matches = input.match(regexPattern);
|
|
45
|
+
if (!matches) {
|
|
46
|
+
throw new Error(`Invalid regular expression format: ${input}`);
|
|
47
|
+
}
|
|
48
|
+
const [, pattern = '', flags = ''] = matches;
|
|
49
|
+
try {
|
|
50
|
+
return new RegExp(pattern, flags);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error(`Failed to create RegExp ${error}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/cjs/utils/text.js
CHANGED
|
@@ -21,57 +21,32 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
|
|
25
|
-
return
|
|
24
|
+
getResourceDisplayName: function() {
|
|
25
|
+
return getResourceDisplayName;
|
|
26
26
|
},
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
},
|
|
30
|
-
getDatasourceDisplayName: function() {
|
|
31
|
-
return getDatasourceDisplayName;
|
|
32
|
-
},
|
|
33
|
-
getDatasourceExtendedDisplayName: function() {
|
|
34
|
-
return getDatasourceExtendedDisplayName;
|
|
35
|
-
},
|
|
36
|
-
getVariableDisplayName: function() {
|
|
37
|
-
return getVariableDisplayName;
|
|
38
|
-
},
|
|
39
|
-
getVariableExtendedDisplayName: function() {
|
|
40
|
-
return getVariableExtendedDisplayName;
|
|
27
|
+
getResourceExtendedDisplayName: function() {
|
|
28
|
+
return getResourceExtendedDisplayName;
|
|
41
29
|
}
|
|
42
30
|
});
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
function getVariableDisplayName(variable) {
|
|
49
|
-
var _variable_spec_spec_display;
|
|
50
|
-
var _variable_spec_spec_display_name;
|
|
51
|
-
return (_variable_spec_spec_display_name = (_variable_spec_spec_display = variable.spec.spec.display) === null || _variable_spec_spec_display === void 0 ? void 0 : _variable_spec_spec_display.name) !== null && _variable_spec_spec_display_name !== void 0 ? _variable_spec_spec_display_name : variable.metadata.name;
|
|
52
|
-
}
|
|
53
|
-
function getDatasourceDisplayName(datasource) {
|
|
54
|
-
var _datasource_spec_display;
|
|
55
|
-
return ((_datasource_spec_display = datasource.spec.display) === null || _datasource_spec_display === void 0 ? void 0 : _datasource_spec_display.name) || datasource.metadata.name;
|
|
56
|
-
}
|
|
57
|
-
function getDashboardExtendedDisplayName(dashboard) {
|
|
58
|
-
var _dashboard_spec_display;
|
|
59
|
-
if ((_dashboard_spec_display = dashboard.spec.display) === null || _dashboard_spec_display === void 0 ? void 0 : _dashboard_spec_display.name) {
|
|
60
|
-
return `${dashboard.spec.display.name} (Name: ${dashboard.metadata.name})`;
|
|
31
|
+
function getResourceDisplayName(resource) {
|
|
32
|
+
// Variables
|
|
33
|
+
if (resource.spec.spec?.display?.name) {
|
|
34
|
+
return resource.spec.spec.display.name;
|
|
61
35
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var _variable_spec_spec_display;
|
|
66
|
-
if ((_variable_spec_spec_display = variable.spec.spec.display) === null || _variable_spec_spec_display === void 0 ? void 0 : _variable_spec_spec_display.name) {
|
|
67
|
-
return `${variable.spec.spec.display.name} (Name: ${variable.metadata.name})`;
|
|
36
|
+
// Other resources with display
|
|
37
|
+
if (resource.spec.display?.name) {
|
|
38
|
+
return resource.spec.display.name;
|
|
68
39
|
}
|
|
69
|
-
return
|
|
40
|
+
return resource.metadata.name;
|
|
70
41
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
return `${
|
|
42
|
+
function getResourceExtendedDisplayName(resource) {
|
|
43
|
+
// Variables
|
|
44
|
+
if (resource.spec.spec?.display?.name) {
|
|
45
|
+
return `${resource.spec.spec.display.name} (ID: ${resource.metadata.name})`;
|
|
46
|
+
}
|
|
47
|
+
// Other resources with display
|
|
48
|
+
if (resource.spec.display?.name) {
|
|
49
|
+
return `${resource.spec.display.name} (ID: ${resource.metadata.name})`;
|
|
75
50
|
}
|
|
76
|
-
return
|
|
51
|
+
return resource.metadata.name;
|
|
77
52
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Copyright 2024 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
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
applyJoinTransform: function() {
|
|
25
|
+
return applyJoinTransform;
|
|
26
|
+
},
|
|
27
|
+
applyMergeColumnsTransform: function() {
|
|
28
|
+
return applyMergeColumnsTransform;
|
|
29
|
+
},
|
|
30
|
+
applyMergeIndexedColumnsTransform: function() {
|
|
31
|
+
return applyMergeIndexedColumnsTransform;
|
|
32
|
+
},
|
|
33
|
+
applyMergeSeriesTransform: function() {
|
|
34
|
+
return applyMergeSeriesTransform;
|
|
35
|
+
},
|
|
36
|
+
transformData: function() {
|
|
37
|
+
return transformData;
|
|
38
|
+
},
|
|
39
|
+
useTransformData: function() {
|
|
40
|
+
return useTransformData;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const _react = require("react");
|
|
44
|
+
function applyJoinTransform(data, columns) {
|
|
45
|
+
// If column is undefined or empty, return data as is
|
|
46
|
+
if (columns.length === 0) {
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
const rowHashed = {};
|
|
50
|
+
for (const row of data){
|
|
51
|
+
const rowHash = Object.keys(row).filter((k)=>columns.includes(k)).map((k)=>row[k]).join('|');
|
|
52
|
+
const rowHashedValue = rowHashed[rowHash];
|
|
53
|
+
if (rowHashedValue) {
|
|
54
|
+
rowHashed[rowHash] = {
|
|
55
|
+
...rowHashedValue,
|
|
56
|
+
...row
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
rowHashed[rowHash] = {
|
|
60
|
+
...row
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Object.values(rowHashed);
|
|
65
|
+
}
|
|
66
|
+
function applyMergeColumnsTransform(data, selectedColumns, outputName) {
|
|
67
|
+
const result = [];
|
|
68
|
+
for (const row of data){
|
|
69
|
+
const columns = Object.keys(row).filter((k)=>selectedColumns.includes(k));
|
|
70
|
+
const selectedColumnValues = {};
|
|
71
|
+
for (const column of columns){
|
|
72
|
+
selectedColumnValues[column] = row[column];
|
|
73
|
+
delete row[column];
|
|
74
|
+
}
|
|
75
|
+
for (const column of columns){
|
|
76
|
+
result.push({
|
|
77
|
+
...row,
|
|
78
|
+
[outputName]: selectedColumnValues[column]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (columns.length === 0) {
|
|
82
|
+
result.push(row);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
function applyMergeIndexedColumnsTransform(data, column) {
|
|
88
|
+
const result = [];
|
|
89
|
+
for (const entry of data){
|
|
90
|
+
const indexedColumns = Object.keys(entry).filter((k)=>new RegExp('^(' + column + ' #\\d+)|(' + column + ')$').test(k));
|
|
91
|
+
const indexedColumnValues = {};
|
|
92
|
+
for (const indexedColumn of indexedColumns){
|
|
93
|
+
indexedColumnValues[indexedColumn] = entry[indexedColumn];
|
|
94
|
+
delete entry[indexedColumn];
|
|
95
|
+
}
|
|
96
|
+
for (const indexedColumn of indexedColumns){
|
|
97
|
+
result.push({
|
|
98
|
+
...entry,
|
|
99
|
+
[column]: indexedColumnValues[indexedColumn]
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (indexedColumns.length === 0) {
|
|
103
|
+
result.push(entry);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
function applyMergeSeriesTransform(data) {
|
|
109
|
+
let result = [
|
|
110
|
+
...data
|
|
111
|
+
];
|
|
112
|
+
const labelColumns = Array.from(new Set(data.flatMap(Object.keys).map((label)=>label.replace(/ #\d+/, '')).filter((label)=>label !== 'value')));
|
|
113
|
+
for (const label of labelColumns){
|
|
114
|
+
result = applyMergeIndexedColumnsTransform(result, label);
|
|
115
|
+
}
|
|
116
|
+
result = applyJoinTransform(result, labelColumns);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function transformData(data, transforms) {
|
|
120
|
+
let result = data;
|
|
121
|
+
// Apply transforms by their orders
|
|
122
|
+
for (const transform of transforms ?? []){
|
|
123
|
+
if (transform.spec.disabled) continue;
|
|
124
|
+
switch(transform.kind){
|
|
125
|
+
case 'JoinByColumnValue':
|
|
126
|
+
{
|
|
127
|
+
if (transform.spec.columns && transform.spec.columns.length > 0) {
|
|
128
|
+
result = applyJoinTransform(result, transform.spec.columns);
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'MergeIndexedColumns':
|
|
133
|
+
{
|
|
134
|
+
if (transform.spec.column) {
|
|
135
|
+
result = applyMergeIndexedColumnsTransform(result, transform.spec.column);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case 'MergeColumns':
|
|
140
|
+
{
|
|
141
|
+
if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {
|
|
142
|
+
result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'MergeSeries':
|
|
147
|
+
{
|
|
148
|
+
result = applyMergeSeriesTransform(result);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Ordering data column alphabetically
|
|
154
|
+
result = result.map((row)=>{
|
|
155
|
+
return Object.keys(row).sort().reduce((obj, key)=>{
|
|
156
|
+
obj[key] = row[key];
|
|
157
|
+
return obj;
|
|
158
|
+
}, {});
|
|
159
|
+
});
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
function useTransformData(data, transforms) {
|
|
163
|
+
return (0, _react.useMemo)(()=>transformData(data, transforms), [
|
|
164
|
+
data,
|
|
165
|
+
transforms
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright 2024 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
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "applyValueMapping", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return applyValueMapping;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _regexp = require("./regexp");
|
|
24
|
+
function applyValueMapping(value, mappings = []) {
|
|
25
|
+
if (!mappings.length) {
|
|
26
|
+
return {
|
|
27
|
+
value
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const mappedItem = {
|
|
31
|
+
value
|
|
32
|
+
};
|
|
33
|
+
mappings.forEach((mapping)=>{
|
|
34
|
+
switch(mapping.kind){
|
|
35
|
+
case 'Value':
|
|
36
|
+
{
|
|
37
|
+
const valueOptions = mapping.spec;
|
|
38
|
+
if (String(valueOptions.value) === String(value)) {
|
|
39
|
+
mappedItem.value = valueOptions.result.value || mappedItem.value;
|
|
40
|
+
mappedItem.color = valueOptions.result.color;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case 'Range':
|
|
45
|
+
{
|
|
46
|
+
const rangeOptions = mapping.spec;
|
|
47
|
+
const newValue = value;
|
|
48
|
+
if (rangeOptions.from === undefined && rangeOptions.to === undefined) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
const from = rangeOptions.from !== undefined ? rangeOptions.from : -Infinity;
|
|
52
|
+
const to = rangeOptions.to !== undefined ? rangeOptions.to : Infinity;
|
|
53
|
+
if (newValue >= from && newValue <= to) {
|
|
54
|
+
mappedItem.value = rangeOptions.result.value || mappedItem.value;
|
|
55
|
+
mappedItem.color = rangeOptions.result.color;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 'Regex':
|
|
60
|
+
{
|
|
61
|
+
const regexOptions = mapping.spec;
|
|
62
|
+
const stringValue = value.toString();
|
|
63
|
+
if (!regexOptions.pattern) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const regex = (0, _regexp.createRegexFromString)(regexOptions.pattern);
|
|
67
|
+
if (stringValue.match(regex)) {
|
|
68
|
+
if (regexOptions.result.value !== null) {
|
|
69
|
+
mappedItem.value = stringValue.replace(regex, regexOptions.result.value.toString() || '') || mappedItem.value;
|
|
70
|
+
mappedItem.color = regexOptions.result.color;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'Misc':
|
|
76
|
+
{
|
|
77
|
+
const miscOptions = mapping.spec;
|
|
78
|
+
if (isMiscValueMatch(miscOptions.value, value)) {
|
|
79
|
+
mappedItem.value = miscOptions.result.value || mappedItem.value;
|
|
80
|
+
mappedItem.color = miscOptions.result.color;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return mappedItem;
|
|
89
|
+
}
|
|
90
|
+
function isMiscValueMatch(miscValue, value) {
|
|
91
|
+
switch(miscValue){
|
|
92
|
+
case 'empty':
|
|
93
|
+
return value === '';
|
|
94
|
+
case 'null':
|
|
95
|
+
return value === null || value === undefined;
|
|
96
|
+
case 'NaN':
|
|
97
|
+
return Number.isNaN(value);
|
|
98
|
+
case 'true':
|
|
99
|
+
return value === true;
|
|
100
|
+
case 'false':
|
|
101
|
+
return value === false;
|
|
102
|
+
default:
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
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,cAAc;AAC5B,cAAc,UAAU;AACxB,cAAc,UAAU"}
|
|
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 './schema';\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,WAAW;AACzB,cAAc,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,eAAO,MAAM,mBAAmB,EAAE,eAAwB,CAAC;AAE3D,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,MAAM,MAAM,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,KAAK,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,CA8EA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,WAAW,EAAE,eAAe,GAAG,gBAAgB,CAE7G;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,7 +10,7 @@
|
|
|
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
|
|
13
|
+
export const DEFAULT_CALCULATION = 'last'; // aligned with cue
|
|
14
14
|
export const CalculationsMap = {
|
|
15
15
|
first: first,
|
|
16
16
|
last: last,
|
|
@@ -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 '
|
|
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 './time-series-queries';\n\nexport const DEFAULT_CALCULATION: CalculationType = 'last'; // aligned with cue\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(\n (initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n },\n {} as Record<string, CalculationValue>\n );\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): CalculationValue {\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":"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"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Definition, UnknownSpec } from './definitions';
|
|
2
2
|
import { Metadata, ProjectMetadata } from './resource';
|
|
3
3
|
import { Display } from './display';
|
|
4
|
+
export interface DatasourceSpec<PluginSpec = UnknownSpec> {
|
|
5
|
+
display?: Display;
|
|
6
|
+
default: boolean;
|
|
7
|
+
plugin: Definition<PluginSpec>;
|
|
8
|
+
}
|
|
4
9
|
/**
|
|
5
10
|
* A Datasource that's available across all projects.
|
|
6
11
|
*/
|
|
7
|
-
export interface
|
|
12
|
+
export interface GlobalDatasourceResource {
|
|
8
13
|
kind: 'GlobalDatasource';
|
|
9
14
|
metadata: Metadata;
|
|
10
15
|
spec: DatasourceSpec;
|
|
@@ -12,17 +17,12 @@ export interface GlobalDatasource {
|
|
|
12
17
|
/**
|
|
13
18
|
* A Datasource resource, that belongs to a project.
|
|
14
19
|
*/
|
|
15
|
-
export interface
|
|
20
|
+
export interface DatasourceResource {
|
|
16
21
|
kind: 'Datasource';
|
|
17
22
|
metadata: ProjectMetadata;
|
|
18
23
|
spec: DatasourceSpec;
|
|
19
24
|
}
|
|
20
|
-
export type Datasource =
|
|
21
|
-
export interface DatasourceSpec<PluginSpec = UnknownSpec> {
|
|
22
|
-
display?: Display;
|
|
23
|
-
default: boolean;
|
|
24
|
-
plugin: Definition<PluginSpec>;
|
|
25
|
-
}
|
|
25
|
+
export type Datasource = DatasourceResource | GlobalDatasourceResource;
|
|
26
26
|
/**
|
|
27
27
|
* A selector for pointing at a specific Datasource.
|
|
28
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC
|
|
1
|
+
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,WAAW,cAAc,CAAC,UAAU,GAAG,WAAW;IACtD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,cAAc,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAAG,kBAAkB,GAAG,wBAAwB,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;CACtB"}
|