@perses-dev/components 0.54.0-beta.2 → 0.54.0-beta.4
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/utils/index.js +7 -0
- package/dist/cjs/utils/mathjs.js +14 -3
- package/dist/cjs/utils/regexp.js +54 -0
- package/dist/cjs/utils/request-interpolation.js +33 -1
- package/dist/cjs/utils/text.js +52 -0
- package/dist/cjs/utils/time-series-data.js +141 -0
- package/dist/cjs/utils/trace-data.js +25 -0
- package/dist/cjs/utils/transform-data.js +157 -0
- package/dist/cjs/utils/types.js +16 -0
- package/dist/cjs/utils/value-mapping.js +105 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mathjs.d.ts +8 -1
- package/dist/utils/mathjs.d.ts.map +1 -1
- package/dist/utils/mathjs.js +5 -2
- package/dist/utils/mathjs.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/request-interpolation.d.ts.map +1 -1
- package/dist/utils/request-interpolation.js +34 -2
- package/dist/utils/request-interpolation.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +39 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/time-series-data.d.ts +15 -0
- package/dist/utils/time-series-data.d.ts.map +1 -0
- package/dist/utils/time-series-data.js +130 -0
- package/dist/utils/time-series-data.js.map +1 -0
- package/dist/utils/trace-data.d.ts +37 -0
- package/dist/utils/trace-data.d.ts.map +1 -0
- package/dist/utils/trace-data.js +17 -0
- package/dist/utils/trace-data.js.map +1 -0
- package/dist/utils/transform-data.d.ts +7 -0
- package/dist/utils/transform-data.d.ts.map +1 -0
- package/dist/utils/transform-data.js +214 -0
- package/dist/utils/transform-data.js.map +1 -0
- 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/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 +2 -2
package/dist/cjs/utils/index.js
CHANGED
|
@@ -26,6 +26,13 @@ _export_star(require("./request-interpolation"), exports);
|
|
|
26
26
|
_export_star(require("./selection-interpolation"), exports);
|
|
27
27
|
_export_star(require("./theme-gen"), exports);
|
|
28
28
|
_export_star(require("./variable-interpolation"), exports);
|
|
29
|
+
_export_star(require("./value-mapping"), exports);
|
|
30
|
+
_export_star(require("./regexp"), exports);
|
|
31
|
+
_export_star(require("./transform-data"), exports);
|
|
32
|
+
_export_star(require("./time-series-data"), exports);
|
|
33
|
+
_export_star(require("./trace-data"), exports);
|
|
34
|
+
_export_star(require("./types"), exports);
|
|
35
|
+
_export_star(require("./text"), exports);
|
|
29
36
|
function _export_star(from, to) {
|
|
30
37
|
Object.keys(from).forEach(function(k) {
|
|
31
38
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/utils/mathjs.js
CHANGED
|
@@ -14,9 +14,17 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get gcd () {
|
|
25
|
+
return gcd;
|
|
26
|
+
},
|
|
27
|
+
get round () {
|
|
20
28
|
return round;
|
|
21
29
|
}
|
|
22
30
|
});
|
|
@@ -25,3 +33,6 @@ const _mathjs = require("mathjs");
|
|
|
25
33
|
const { round } = (0, _mathjs.create)({
|
|
26
34
|
roundDependencies: _mathjs.roundDependencies
|
|
27
35
|
});
|
|
36
|
+
const { gcd } = (0, _mathjs.create)({
|
|
37
|
+
gcdDependencies: _mathjs.gcdDependencies
|
|
38
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 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: Object.getOwnPropertyDescriptor(all, name).get
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
_export(exports, {
|
|
26
|
+
get createRegexFromString () {
|
|
27
|
+
return createRegexFromString;
|
|
28
|
+
},
|
|
29
|
+
get isRegexPattern () {
|
|
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
|
+
}
|
|
@@ -29,6 +29,38 @@ _export(exports, {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
const _variableinterpolation = require("./variable-interpolation");
|
|
32
|
+
function expandQueryParamValue(value, variableState) {
|
|
33
|
+
// If value is an array, process each element
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
return value.map((v)=>expandQueryParamValue(v, variableState));
|
|
36
|
+
}
|
|
37
|
+
// Now we know value is a string, so we can safely use string methods
|
|
38
|
+
const valueString = value;
|
|
39
|
+
const variablesMap = (0, _variableinterpolation.parseVariablesAndFormat)(valueString);
|
|
40
|
+
// Find the first multi-value variable that should expand to repeated keys
|
|
41
|
+
for (const [varName, format] of variablesMap){
|
|
42
|
+
const varState = variableState[varName];
|
|
43
|
+
if (!varState || !Array.isArray(varState.value)) continue;
|
|
44
|
+
// If format is queryparam or not specified (default for query params), expand to array
|
|
45
|
+
if (!format || format === _variableinterpolation.InterpolationFormat.QUERYPARAM) {
|
|
46
|
+
// Build syntax patterns for this variable reference
|
|
47
|
+
const simpleSyntax = '$' + varName;
|
|
48
|
+
const bracketSyntax = format ? '${' + varName + ':' + format + '}' : '${' + varName + '}';
|
|
49
|
+
return varState.value.map((singleValue)=>{
|
|
50
|
+
let text = valueString;
|
|
51
|
+
// Replace the variable reference with the raw value directly.
|
|
52
|
+
// We cannot use replaceVariables here because it would apply QUERYPARAM format
|
|
53
|
+
// to the single value, producing "varName=val" instead of just "val".
|
|
54
|
+
text = text.replaceAll(bracketSyntax, singleValue);
|
|
55
|
+
text = text.replaceAll(simpleSyntax, singleValue);
|
|
56
|
+
// Replace any remaining variables (other than the expanded one) using standard interpolation
|
|
57
|
+
return (0, _variableinterpolation.replaceVariables)(text, variableState);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// No multi-value expansion needed — use standard interpolation
|
|
62
|
+
return (0, _variableinterpolation.replaceVariables)(valueString, variableState);
|
|
63
|
+
}
|
|
32
64
|
function interpolateHeaders(headers, variableState) {
|
|
33
65
|
const result = {};
|
|
34
66
|
for (const [key, value] of Object.entries(headers)){
|
|
@@ -42,7 +74,7 @@ function interpolateQueryParams(queryParams, variableState) {
|
|
|
42
74
|
if (Array.isArray(value)) {
|
|
43
75
|
result[key] = value.map((v)=>(0, _variableinterpolation.replaceVariables)(v, variableState));
|
|
44
76
|
} else {
|
|
45
|
-
result[key] = (
|
|
77
|
+
result[key] = expandQueryParamValue(value, variableState);
|
|
46
78
|
}
|
|
47
79
|
}
|
|
48
80
|
return result;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 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: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get getResourceDisplayName () {
|
|
25
|
+
return getResourceDisplayName;
|
|
26
|
+
},
|
|
27
|
+
get getResourceExtendedDisplayName () {
|
|
28
|
+
return getResourceExtendedDisplayName;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
function getResourceDisplayName(resource) {
|
|
32
|
+
// Variables
|
|
33
|
+
if (resource.spec?.spec?.display?.name) {
|
|
34
|
+
return resource.spec.spec.display.name;
|
|
35
|
+
}
|
|
36
|
+
// Other resources with display
|
|
37
|
+
if (resource.spec?.display?.name) {
|
|
38
|
+
return resource.spec.display.name;
|
|
39
|
+
}
|
|
40
|
+
return resource.metadata.name;
|
|
41
|
+
}
|
|
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})`;
|
|
50
|
+
}
|
|
51
|
+
return resource.metadata.name;
|
|
52
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Copyright 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: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get MIN_STEP_INTERVAL_MS () {
|
|
25
|
+
return MIN_STEP_INTERVAL_MS;
|
|
26
|
+
},
|
|
27
|
+
get getCommonTimeScale () {
|
|
28
|
+
return getCommonTimeScale;
|
|
29
|
+
},
|
|
30
|
+
get getTimeSeriesValues () {
|
|
31
|
+
return getTimeSeriesValues;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const _mathjs = require("./mathjs");
|
|
35
|
+
const MIN_STEP_INTERVAL_MS = 10;
|
|
36
|
+
function getTimeSeriesValues(series, timeScale) {
|
|
37
|
+
let timestamp = timeScale.startMs;
|
|
38
|
+
const values = series.values;
|
|
39
|
+
const processedValues = [];
|
|
40
|
+
for (const valueTuple of values){
|
|
41
|
+
// Fill in values up to the current series value timestamp with nulls
|
|
42
|
+
while(timestamp < valueTuple[0]){
|
|
43
|
+
processedValues.push([
|
|
44
|
+
timestamp,
|
|
45
|
+
null
|
|
46
|
+
]);
|
|
47
|
+
timestamp += timeScale.stepMs;
|
|
48
|
+
}
|
|
49
|
+
// Now add the current value since timestamp should match
|
|
50
|
+
processedValues.push([
|
|
51
|
+
timestamp,
|
|
52
|
+
valueTuple[1]
|
|
53
|
+
]);
|
|
54
|
+
timestamp += timeScale.stepMs;
|
|
55
|
+
}
|
|
56
|
+
// Add null values at the end of the series if necessary
|
|
57
|
+
while(timestamp <= timeScale.endMs){
|
|
58
|
+
processedValues.push([
|
|
59
|
+
timestamp,
|
|
60
|
+
null
|
|
61
|
+
]);
|
|
62
|
+
timestamp += timeScale.stepMs;
|
|
63
|
+
}
|
|
64
|
+
return processedValues;
|
|
65
|
+
}
|
|
66
|
+
function getCommonTimeScale(seriesData) {
|
|
67
|
+
let timeRange = undefined;
|
|
68
|
+
const steps = [];
|
|
69
|
+
for (const data of seriesData){
|
|
70
|
+
if (data && 'timeRange' in data) {
|
|
71
|
+
if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
|
|
72
|
+
// Keep track of query steps so we can calculate a common one for the graph
|
|
73
|
+
steps.push(data.stepMs);
|
|
74
|
+
// If we don't have an overall time range yet, just start with this one
|
|
75
|
+
if (timeRange === undefined) {
|
|
76
|
+
timeRange = data.timeRange;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
// Otherwise, see if this query has a start or end outside of the current
|
|
80
|
+
// time range
|
|
81
|
+
if (data.timeRange.start < timeRange.start) {
|
|
82
|
+
timeRange.start = data.timeRange.start;
|
|
83
|
+
}
|
|
84
|
+
if (data.timeRange.end > timeRange.end) {
|
|
85
|
+
timeRange.end = data.timeRange.end;
|
|
86
|
+
}
|
|
87
|
+
} else if (data && 'values' in data) {
|
|
88
|
+
for(let i = 0; i < data.values.length; i++){
|
|
89
|
+
const values = data.values[i];
|
|
90
|
+
if (values === undefined) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const [timestamp] = values;
|
|
94
|
+
const start = new Date(timestamp);
|
|
95
|
+
const end = new Date(timestamp);
|
|
96
|
+
if (timeRange === undefined) {
|
|
97
|
+
timeRange = {
|
|
98
|
+
start,
|
|
99
|
+
end
|
|
100
|
+
};
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (start < timeRange.start) {
|
|
104
|
+
timeRange.start = start;
|
|
105
|
+
}
|
|
106
|
+
if (end > timeRange.end) {
|
|
107
|
+
timeRange.end = end;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (timeRange === undefined) return undefined;
|
|
111
|
+
const startMs = timeRange.start.valueOf();
|
|
112
|
+
const endMs = timeRange.end.valueOf();
|
|
113
|
+
const rangeMs = endMs - startMs;
|
|
114
|
+
return {
|
|
115
|
+
startMs,
|
|
116
|
+
endMs,
|
|
117
|
+
rangeMs,
|
|
118
|
+
stepMs: MIN_STEP_INTERVAL_MS
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (timeRange === undefined) return undefined;
|
|
123
|
+
// Use the greatest common divisor of all step values as the overall step
|
|
124
|
+
// for the x axis (or if only one query, just use that query's step value)
|
|
125
|
+
let stepMs;
|
|
126
|
+
if (steps.length === 1) {
|
|
127
|
+
stepMs = steps[0];
|
|
128
|
+
} else {
|
|
129
|
+
const calculatedStepMs = (0, _mathjs.gcd)(...steps);
|
|
130
|
+
stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
|
|
131
|
+
}
|
|
132
|
+
const startMs = timeRange.start.valueOf();
|
|
133
|
+
const endMs = timeRange.end.valueOf();
|
|
134
|
+
const rangeMs = endMs - startMs;
|
|
135
|
+
return {
|
|
136
|
+
startMs,
|
|
137
|
+
endMs,
|
|
138
|
+
stepMs,
|
|
139
|
+
rangeMs
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 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, "isValidTraceId", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return isValidTraceId;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
function isValidTraceId(traceId) {
|
|
24
|
+
return /^[0-9a-fA-F]+$/.test(traceId);
|
|
25
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Copyright 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: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get applyJoinTransform () {
|
|
25
|
+
return applyJoinTransform;
|
|
26
|
+
},
|
|
27
|
+
get applyMergeColumnsTransform () {
|
|
28
|
+
return applyMergeColumnsTransform;
|
|
29
|
+
},
|
|
30
|
+
get applyMergeIndexedColumnsTransform () {
|
|
31
|
+
return applyMergeIndexedColumnsTransform;
|
|
32
|
+
},
|
|
33
|
+
get applyMergeSeriesTransform () {
|
|
34
|
+
return applyMergeSeriesTransform;
|
|
35
|
+
},
|
|
36
|
+
get transformData () {
|
|
37
|
+
return transformData;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function applyJoinTransform(data, columns) {
|
|
41
|
+
// If column is undefined or empty, return data as is
|
|
42
|
+
if (columns.length === 0) {
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
const rowHashed = {};
|
|
46
|
+
for (const row of data){
|
|
47
|
+
const rowHash = Object.keys(row).filter((k)=>columns.includes(k)).map((k)=>row[k]).join('|');
|
|
48
|
+
const rowHashedValue = rowHashed[rowHash];
|
|
49
|
+
if (rowHashedValue) {
|
|
50
|
+
rowHashed[rowHash] = {
|
|
51
|
+
...rowHashedValue,
|
|
52
|
+
...row
|
|
53
|
+
};
|
|
54
|
+
} else {
|
|
55
|
+
rowHashed[rowHash] = {
|
|
56
|
+
...row
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return Object.values(rowHashed);
|
|
61
|
+
}
|
|
62
|
+
function applyMergeColumnsTransform(data, selectedColumns, outputName) {
|
|
63
|
+
const result = [];
|
|
64
|
+
for (const row of data){
|
|
65
|
+
const columns = Object.keys(row).filter((k)=>selectedColumns.includes(k));
|
|
66
|
+
const selectedColumnValues = {};
|
|
67
|
+
for (const column of columns){
|
|
68
|
+
selectedColumnValues[column] = row[column];
|
|
69
|
+
delete row[column];
|
|
70
|
+
}
|
|
71
|
+
for (const column of columns){
|
|
72
|
+
result.push({
|
|
73
|
+
...row,
|
|
74
|
+
[outputName]: selectedColumnValues[column]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (columns.length === 0) {
|
|
78
|
+
result.push(row);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
function applyMergeIndexedColumnsTransform(data, column) {
|
|
84
|
+
const result = [];
|
|
85
|
+
for (const entry of data){
|
|
86
|
+
const indexedColumns = Object.keys(entry).filter((k)=>new RegExp('^((' + column + ' #\\d+)|(' + column + '))$').test(k));
|
|
87
|
+
const indexedColumnValues = {};
|
|
88
|
+
for (const indexedColumn of indexedColumns){
|
|
89
|
+
indexedColumnValues[indexedColumn] = entry[indexedColumn];
|
|
90
|
+
delete entry[indexedColumn];
|
|
91
|
+
}
|
|
92
|
+
for (const indexedColumn of indexedColumns){
|
|
93
|
+
result.push({
|
|
94
|
+
...entry,
|
|
95
|
+
[column]: indexedColumnValues[indexedColumn]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (indexedColumns.length === 0) {
|
|
99
|
+
result.push(entry);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
function applyMergeSeriesTransform(data) {
|
|
105
|
+
let result = [
|
|
106
|
+
...data
|
|
107
|
+
];
|
|
108
|
+
const labelColumns = Array.from(new Set(data.flatMap(Object.keys).map((label)=>label.replace(/ #\d+/, '')).filter((label)=>label !== 'value')));
|
|
109
|
+
for (const label of labelColumns){
|
|
110
|
+
result = applyMergeIndexedColumnsTransform(result, label);
|
|
111
|
+
}
|
|
112
|
+
result = applyJoinTransform(result, labelColumns);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
function transformData(data, transforms) {
|
|
116
|
+
let result = data;
|
|
117
|
+
// Apply transforms by their orders
|
|
118
|
+
for (const transform of transforms ?? []){
|
|
119
|
+
if (transform.spec.disabled) continue;
|
|
120
|
+
switch(transform.kind){
|
|
121
|
+
case 'JoinByColumnValue':
|
|
122
|
+
{
|
|
123
|
+
if (transform.spec.columns && transform.spec.columns.length > 0) {
|
|
124
|
+
result = applyJoinTransform(result, transform.spec.columns);
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case 'MergeIndexedColumns':
|
|
129
|
+
{
|
|
130
|
+
if (transform.spec.column) {
|
|
131
|
+
result = applyMergeIndexedColumnsTransform(result, transform.spec.column);
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'MergeColumns':
|
|
136
|
+
{
|
|
137
|
+
if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {
|
|
138
|
+
result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case 'MergeSeries':
|
|
143
|
+
{
|
|
144
|
+
result = applyMergeSeriesTransform(result);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Ordering data column alphabetically
|
|
150
|
+
result = result.map((row)=>{
|
|
151
|
+
return Object.keys(row).sort().reduce((obj, key)=>{
|
|
152
|
+
obj[key] = row[key];
|
|
153
|
+
return obj;
|
|
154
|
+
}, {});
|
|
155
|
+
});
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 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
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright 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/utils/index.d.ts
CHANGED
|
@@ -10,4 +10,11 @@ export * from './request-interpolation';
|
|
|
10
10
|
export * from './selection-interpolation';
|
|
11
11
|
export * from './theme-gen';
|
|
12
12
|
export * from './variable-interpolation';
|
|
13
|
+
export * from './value-mapping';
|
|
14
|
+
export * from './regexp';
|
|
15
|
+
export * from './transform-data';
|
|
16
|
+
export * from './time-series-data';
|
|
17
|
+
export * from './trace-data';
|
|
18
|
+
export * from './types';
|
|
19
|
+
export * from './text';
|
|
13
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -22,5 +22,12 @@ export * from './request-interpolation';
|
|
|
22
22
|
export * from './selection-interpolation';
|
|
23
23
|
export * from './theme-gen';
|
|
24
24
|
export * from './variable-interpolation';
|
|
25
|
+
export * from './value-mapping';
|
|
26
|
+
export * from './regexp';
|
|
27
|
+
export * from './transform-data';
|
|
28
|
+
export * from './time-series-data';
|
|
29
|
+
export * from './trace-data';
|
|
30
|
+
export * from './types';
|
|
31
|
+
export * from './text';
|
|
25
32
|
|
|
26
33
|
//# sourceMappingURL=index.js.map
|