@perses-dev/components 0.54.0-beta.2 → 0.54.0-beta.3

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.
@@ -26,6 +26,10 @@ _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);
29
33
  function _export_star(from, to) {
30
34
  Object.keys(from).forEach(function(k) {
31
35
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -14,9 +14,17 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "round", {
18
- enumerable: true,
19
- get: function() {
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
+ }
@@ -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,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,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
+ }
@@ -10,4 +10,8 @@ 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';
13
17
  //# 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"}
@@ -22,5 +22,9 @@ 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';
25
29
 
26
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 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 './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './memo';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS;AACvB,cAAc,oBAAoB;AAClC,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,0BAA0B;AACxC,cAAc,4BAA4B;AAC1C,cAAc,cAAc;AAC5B,cAAc,2BAA2B"}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 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 './axis';\nexport * from './browser-storage';\nexport * from './chart-actions';\nexport * from './combine-sx';\nexport * from './component-ids';\nexport * from './data-field-interpolation';\nexport * from './format';\nexport * from './memo';\nexport * from './request-interpolation';\nexport * from './selection-interpolation';\nexport * from './theme-gen';\nexport * from './variable-interpolation';\nexport * from './value-mapping';\nexport * from './regexp';\nexport * from './transform-data';\nexport * from './time-series-data';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS;AACvB,cAAc,oBAAoB;AAClC,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,0BAA0B;AACxC,cAAc,4BAA4B;AAC1C,cAAc,cAAc;AAC5B,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,WAAW;AACzB,cAAc,mBAAmB;AACjC,cAAc,qBAAqB"}
@@ -2,5 +2,12 @@ declare const round: {
2
2
  <T extends import("mathjs").MathNumericType | import("mathjs").MathCollection>(x: T, n?: number | import("mathjs").BigNumber | undefined): T extends number ? number : T extends string ? string : T extends boolean ? boolean : T;
3
3
  <U extends import("mathjs").MathCollection>(x: import("mathjs").MathNumericType, n: U): U;
4
4
  };
5
- export { round };
5
+ declare const gcd: {
6
+ (...args: number[]): number;
7
+ (...args: import("mathjs").BigNumber[]): import("mathjs").BigNumber;
8
+ (...args: import("mathjs").Fraction[]): import("mathjs").Fraction;
9
+ (...args: import("mathjs").MathArray[]): import("mathjs").MathArray;
10
+ (...args: import("mathjs").Matrix[]): import("mathjs").Matrix;
11
+ };
12
+ export { round, gcd };
6
13
  //# sourceMappingURL=mathjs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mathjs.d.ts","sourceRoot":"","sources":["../../src/utils/mathjs.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAQ,KAAK;;;CAAkC,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"mathjs.d.ts","sourceRoot":"","sources":["../../src/utils/mathjs.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAQ,KAAK;;;CAAkC,CAAC;AAChD,QAAA,MAAQ,GAAG;;;;;;CAAgC,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC"}
@@ -10,11 +10,14 @@
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
- import { roundDependencies, create } from 'mathjs';
13
+ import { roundDependencies, gcdDependencies, create } from 'mathjs';
14
14
  // This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)
15
15
  const { round } = create({
16
16
  roundDependencies
17
17
  });
18
- export { round };
18
+ const { gcd } = create({
19
+ gcdDependencies
20
+ });
21
+ export { round, gcd };
19
22
 
20
23
  //# sourceMappingURL=mathjs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/mathjs.ts"],"sourcesContent":["// Copyright 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 { roundDependencies, create } from 'mathjs';\n\n// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)\nconst { round } = create({ roundDependencies });\nexport { round };\n"],"names":["roundDependencies","create","round"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,EAAEC,MAAM,QAAQ,SAAS;AAEnD,uHAAuH;AACvH,MAAM,EAAEC,KAAK,EAAE,GAAGD,OAAO;IAAED;AAAkB;AAC7C,SAASE,KAAK,GAAG"}
1
+ {"version":3,"sources":["../../src/utils/mathjs.ts"],"sourcesContent":["// Copyright 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 { roundDependencies, gcdDependencies, create } from 'mathjs';\n\n// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)\nconst { round } = create({ roundDependencies });\nconst { gcd } = create({ gcdDependencies });\nexport { round, gcd };\n"],"names":["roundDependencies","gcdDependencies","create","round","gcd"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,MAAM,QAAQ,SAAS;AAEpE,uHAAuH;AACvH,MAAM,EAAEC,KAAK,EAAE,GAAGD,OAAO;IAAEF;AAAkB;AAC7C,MAAM,EAAEI,GAAG,EAAE,GAAGF,OAAO;IAAED;AAAgB;AACzC,SAASE,KAAK,EAAEC,GAAG,GAAG"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks if a string is a regex pattern.
3
+ */
4
+ export declare function isRegexPattern(input: string | null | undefined): boolean;
5
+ /**
6
+ * Converts a string to RegExp. Handles both regular strings and regex patterns.
7
+ * For regular strings, creates exact match regex.
8
+ * For patterns like "/pattern/flags", creates corresponding RegExp.
9
+ */
10
+ export declare function createRegexFromString(input: string): RegExp;
11
+ //# sourceMappingURL=regexp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../src/utils/regexp.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAExE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAuB3D"}
@@ -0,0 +1,42 @@
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
+ */ export function isRegexPattern(input) {
16
+ return Boolean(input?.startsWith('/'));
17
+ }
18
+ /**
19
+ * Converts a string to RegExp. Handles both regular strings and regex patterns.
20
+ * For regular strings, creates exact match regex.
21
+ * For patterns like "/pattern/flags", creates corresponding RegExp.
22
+ */ export function createRegexFromString(input) {
23
+ if (!input) {
24
+ throw new Error('Input string cannot be empty');
25
+ }
26
+ if (!isRegexPattern(input)) {
27
+ return new RegExp(`^${input}$`);
28
+ }
29
+ const regexPattern = /^\/(.+)\/([gimy]*)$/;
30
+ const matches = input.match(regexPattern);
31
+ if (!matches) {
32
+ throw new Error(`Invalid regular expression format: ${input}`);
33
+ }
34
+ const [, pattern = '', flags = ''] = matches;
35
+ try {
36
+ return new RegExp(pattern, flags);
37
+ } catch (error) {
38
+ throw new Error(`Failed to create RegExp ${error}`);
39
+ }
40
+ }
41
+
42
+ //# sourceMappingURL=regexp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/regexp.ts"],"sourcesContent":["// Copyright 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/**\n * Checks if a string is a regex pattern.\n */\nexport function isRegexPattern(input: string | null | undefined): boolean {\n return Boolean(input?.startsWith('/'));\n}\n\n/**\n * Converts a string to RegExp. Handles both regular strings and regex patterns.\n * For regular strings, creates exact match regex.\n * For patterns like \"/pattern/flags\", creates corresponding RegExp.\n */\nexport function createRegexFromString(input: string): RegExp {\n if (!input) {\n throw new Error('Input string cannot be empty');\n }\n\n if (!isRegexPattern(input)) {\n return new RegExp(`^${input}$`);\n }\n\n const regexPattern = /^\\/(.+)\\/([gimy]*)$/;\n const matches = input.match(regexPattern);\n\n if (!matches) {\n throw new Error(`Invalid regular expression format: ${input}`);\n }\n\n const [, pattern = '', flags = ''] = matches;\n\n try {\n return new RegExp(pattern, flags);\n } catch (error) {\n throw new Error(`Failed to create RegExp ${error}`);\n }\n}\n"],"names":["isRegexPattern","input","Boolean","startsWith","createRegexFromString","Error","RegExp","regexPattern","matches","match","pattern","flags","error"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,OAAO,SAASA,eAAeC,KAAgC;IAC7D,OAAOC,QAAQD,OAAOE,WAAW;AACnC;AAEA;;;;CAIC,GACD,OAAO,SAASC,sBAAsBH,KAAa;IACjD,IAAI,CAACA,OAAO;QACV,MAAM,IAAII,MAAM;IAClB;IAEA,IAAI,CAACL,eAAeC,QAAQ;QAC1B,OAAO,IAAIK,OAAO,CAAC,CAAC,EAAEL,MAAM,CAAC,CAAC;IAChC;IAEA,MAAMM,eAAe;IACrB,MAAMC,UAAUP,MAAMQ,KAAK,CAACF;IAE5B,IAAI,CAACC,SAAS;QACZ,MAAM,IAAIH,MAAM,CAAC,mCAAmC,EAAEJ,OAAO;IAC/D;IAEA,MAAM,GAAGS,UAAU,EAAE,EAAEC,QAAQ,EAAE,CAAC,GAAGH;IAErC,IAAI;QACF,OAAO,IAAIF,OAAOI,SAASC;IAC7B,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIP,MAAM,CAAC,wBAAwB,EAAEO,OAAO;IACpD;AACF"}
@@ -0,0 +1,15 @@
1
+ import { TimeScale, TimeSeries, TimeSeriesData, TimeSeriesValueTuple } from '@perses-dev/spec';
2
+ export declare const MIN_STEP_INTERVAL_MS = 10;
3
+ /**
4
+ * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
5
+ * processes the time series values, filling in any timestamps that are missing
6
+ * from the time series data with `null` values.
7
+ */
8
+ export declare function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale): TimeSeriesValueTuple[];
9
+ /**
10
+ * Given a list of running queries, calculates a common time scale for use on
11
+ * the x axis (i.e. start/end dates and a step that is divisible into all of
12
+ * the queries' steps).
13
+ */
14
+ export declare function getCommonTimeScale(seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>): TimeScale | undefined;
15
+ //# sourceMappingURL=time-series-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGlH,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,oBAAoB,EAAE,CAyBpG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,GACzE,SAAS,GAAG,SAAS,CAgFvB"}
@@ -0,0 +1,130 @@
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
+ import { gcd } from './mathjs';
14
+ export const MIN_STEP_INTERVAL_MS = 10;
15
+ /**
16
+ * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
17
+ * processes the time series values, filling in any timestamps that are missing
18
+ * from the time series data with `null` values.
19
+ */ export function getTimeSeriesValues(series, timeScale) {
20
+ let timestamp = timeScale.startMs;
21
+ const values = series.values;
22
+ const processedValues = [];
23
+ for (const valueTuple of values){
24
+ // Fill in values up to the current series value timestamp with nulls
25
+ while(timestamp < valueTuple[0]){
26
+ processedValues.push([
27
+ timestamp,
28
+ null
29
+ ]);
30
+ timestamp += timeScale.stepMs;
31
+ }
32
+ // Now add the current value since timestamp should match
33
+ processedValues.push([
34
+ timestamp,
35
+ valueTuple[1]
36
+ ]);
37
+ timestamp += timeScale.stepMs;
38
+ }
39
+ // Add null values at the end of the series if necessary
40
+ while(timestamp <= timeScale.endMs){
41
+ processedValues.push([
42
+ timestamp,
43
+ null
44
+ ]);
45
+ timestamp += timeScale.stepMs;
46
+ }
47
+ return processedValues;
48
+ }
49
+ /**
50
+ * Given a list of running queries, calculates a common time scale for use on
51
+ * the x axis (i.e. start/end dates and a step that is divisible into all of
52
+ * the queries' steps).
53
+ */ export function getCommonTimeScale(seriesData) {
54
+ let timeRange = undefined;
55
+ const steps = [];
56
+ for (const data of seriesData){
57
+ if (data && 'timeRange' in data) {
58
+ if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
59
+ // Keep track of query steps so we can calculate a common one for the graph
60
+ steps.push(data.stepMs);
61
+ // If we don't have an overall time range yet, just start with this one
62
+ if (timeRange === undefined) {
63
+ timeRange = data.timeRange;
64
+ continue;
65
+ }
66
+ // Otherwise, see if this query has a start or end outside of the current
67
+ // time range
68
+ if (data.timeRange.start < timeRange.start) {
69
+ timeRange.start = data.timeRange.start;
70
+ }
71
+ if (data.timeRange.end > timeRange.end) {
72
+ timeRange.end = data.timeRange.end;
73
+ }
74
+ } else if (data && 'values' in data) {
75
+ for(let i = 0; i < data.values.length; i++){
76
+ const values = data.values[i];
77
+ if (values === undefined) {
78
+ continue;
79
+ }
80
+ const [timestamp] = values;
81
+ const start = new Date(timestamp);
82
+ const end = new Date(timestamp);
83
+ if (timeRange === undefined) {
84
+ timeRange = {
85
+ start,
86
+ end
87
+ };
88
+ continue;
89
+ }
90
+ if (start < timeRange.start) {
91
+ timeRange.start = start;
92
+ }
93
+ if (end > timeRange.end) {
94
+ timeRange.end = end;
95
+ }
96
+ }
97
+ if (timeRange === undefined) return undefined;
98
+ const startMs = timeRange.start.valueOf();
99
+ const endMs = timeRange.end.valueOf();
100
+ const rangeMs = endMs - startMs;
101
+ return {
102
+ startMs,
103
+ endMs,
104
+ rangeMs,
105
+ stepMs: MIN_STEP_INTERVAL_MS
106
+ };
107
+ }
108
+ }
109
+ if (timeRange === undefined) return undefined;
110
+ // Use the greatest common divisor of all step values as the overall step
111
+ // for the x axis (or if only one query, just use that query's step value)
112
+ let stepMs;
113
+ if (steps.length === 1) {
114
+ stepMs = steps[0];
115
+ } else {
116
+ const calculatedStepMs = gcd(...steps);
117
+ stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
118
+ }
119
+ const startMs = timeRange.start.valueOf();
120
+ const endMs = timeRange.end.valueOf();
121
+ const rangeMs = endMs - startMs;
122
+ return {
123
+ startMs,
124
+ endMs,
125
+ stepMs,
126
+ rangeMs
127
+ };
128
+ }
129
+
130
+ //# sourceMappingURL=time-series-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright 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 { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData, TimeSeriesValueTuple } from '@perses-dev/spec';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * processes the time series values, filling in any timestamps that are missing\n * from the time series data with `null` values.\n */\nexport function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale): TimeSeriesValueTuple[] {\n let timestamp = timeScale.startMs;\n\n const values = series.values;\n const processedValues: TimeSeriesValueTuple[] = [];\n\n for (const valueTuple of values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n processedValues.push([timestamp, valueTuple[1]]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n return processedValues;\n}\n\n/**\n * Given a list of running queries, calculates a common time scale for use on\n * the x axis (i.e. start/end dates and a step that is divisible into all of\n * the queries' steps).\n */\nexport function getCommonTimeScale(\n seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>\n): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n\n for (const data of seriesData) {\n if (data && 'timeRange' in data) {\n if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;\n\n // Keep track of query steps so we can calculate a common one for the graph\n steps.push(data.stepMs);\n\n // If we don't have an overall time range yet, just start with this one\n if (timeRange === undefined) {\n timeRange = data.timeRange;\n continue;\n }\n\n // Otherwise, see if this query has a start or end outside of the current\n // time range\n if (data.timeRange.start < timeRange.start) {\n timeRange.start = data.timeRange.start;\n }\n if (data.timeRange.end > timeRange.end) {\n timeRange.end = data.timeRange.end;\n }\n } else if (data && 'values' in data) {\n for (let i = 0; i < data.values.length; i++) {\n const values = data.values[i];\n if (values === undefined) {\n continue;\n }\n\n const [timestamp] = values;\n const start = new Date(timestamp);\n const end = new Date(timestamp);\n\n if (timeRange === undefined) {\n timeRange = {\n start,\n end,\n };\n continue;\n }\n\n if (start < timeRange.start) {\n timeRange.start = start;\n }\n\n if (end > timeRange.end) {\n timeRange.end = end;\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, rangeMs, stepMs: MIN_STEP_INTERVAL_MS };\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n // Use the greatest common divisor of all step values as the overall step\n // for the x axis (or if only one query, just use that query's step value)\n let stepMs: number;\n if (steps.length === 1) {\n stepMs = steps[0] as number;\n } else {\n const calculatedStepMs = gcd(...steps);\n stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;\n }\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, stepMs, rangeMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getTimeSeriesValues","series","timeScale","timestamp","startMs","values","processedValues","valueTuple","push","stepMs","endMs","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end","i","length","Date","valueOf","rangeMs","calculatedStepMs"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,GAAG,QAAQ,WAAW;AAE/B,OAAO,MAAMC,uBAAuB,GAAG;AAEvC;;;;CAIC,GACD,OAAO,SAASC,oBAAoBC,MAAkB,EAAEC,SAAoB;IAC1E,IAAIC,YAAYD,UAAUE,OAAO;IAEjC,MAAMC,SAASJ,OAAOI,MAAM;IAC5B,MAAMC,kBAA0C,EAAE;IAElD,KAAK,MAAMC,cAAcF,OAAQ;QAC/B,qEAAqE;QACrE,MAAOF,YAAYI,UAAU,CAAC,EAAE,CAAE;YAChCD,gBAAgBE,IAAI,CAAC;gBAACL;gBAAW;aAAK;YACtCA,aAAaD,UAAUO,MAAM;QAC/B;QAEA,yDAAyD;QACzDH,gBAAgBE,IAAI,CAAC;YAACL;YAAWI,UAAU,CAAC,EAAE;SAAC;QAC/CJ,aAAaD,UAAUO,MAAM;IAC/B;IAEA,wDAAwD;IACxD,MAAON,aAAaD,UAAUQ,KAAK,CAAE;QACnCJ,gBAAgBE,IAAI,CAAC;YAACL;YAAW;SAAK;QACtCA,aAAaD,UAAUO,MAAM;IAC/B;IAEA,OAAOH;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASK,mBACdC,UAA0E;IAE1E,IAAIC,YAA2CC;IAC/C,MAAMC,QAAkB,EAAE;IAE1B,KAAK,MAAMC,QAAQJ,WAAY;QAC7B,IAAII,QAAQ,eAAeA,MAAM;YAC/B,IAAIA,SAASF,aAAaE,KAAKH,SAAS,KAAKC,aAAaE,KAAKP,MAAM,KAAKK,WAAW;YAErF,2EAA2E;YA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IAC1E,IAAIL;IACJ,IAAIM,MAAMK,MAAM,KAAK,GAAG;QACtBX,SAASM,KAAK,CAAC,EAAE;IACnB,OAAO;QACL,MAAMS,mBAAmB1B,OAAOiB;QAChCN,SAASe,mBAAmBzB,uBAAuBA,uBAAuByB;IAC5E;IAEA,MAAMpB,UAAUS,UAAUI,KAAK,CAACK,OAAO;IACvC,MAAMZ,QAAQG,UAAUK,GAAG,CAACI,OAAO;IACnC,MAAMC,UAAUb,QAAQN;IAExB,OAAO;QAAEA;QAASM;QAAOD;QAAQc;IAAQ;AAC3C"}
@@ -0,0 +1,7 @@
1
+ import { Transform } from '../model';
2
+ export declare function applyJoinTransform(data: Array<Record<string, unknown>>, columns: string[]): Array<Record<string, unknown>>;
3
+ export declare function applyMergeColumnsTransform(data: Array<Record<string, unknown>>, selectedColumns: string[], outputName: string): Array<Record<string, unknown>>;
4
+ export declare function applyMergeIndexedColumnsTransform(data: Array<Record<string, unknown>>, column: string): Array<Record<string, unknown>>;
5
+ export declare function applyMergeSeriesTransform(data: Array<Record<string, unknown>>): Array<Record<string, unknown>>;
6
+ export declare function transformData(data: Array<Record<string, unknown>>, transforms: Transform[]): Array<Record<string, unknown>>;
7
+ //# sourceMappingURL=transform-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data.d.ts","sourceRoot":"","sources":["../../src/utils/transform-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAqBrC,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,OAAO,EAAE,MAAM,EAAE,GAChB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsBhC;AA0BD,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,eAAe,EAAE,MAAM,EAAE,EACzB,UAAU,EAAE,MAAM,GACjB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAuBhC;AA0BD,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,MAAM,EAAE,MAAM,GACb,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAwBhC;AAmBD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAmB9G;AAKD,wBAAgB,aAAa,CAC3B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACpC,UAAU,EAAE,SAAS,EAAE,GACtB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA2ChC"}
@@ -0,0 +1,214 @@
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
+ * Join: Regroup rows with equal cell value in a column.
15
+ * If there are multiple line with same value, next row values override the current one
16
+ *
17
+ * Example: Join on 'mount' column
18
+ * INPUT:
19
+ * | timestamp | value #1 | value #3 | mount |
20
+ * |------------|----------|----------|-----------|
21
+ * | 1630000000 | 1 | | / |
22
+ * | 1630000000 | 2 | | /boot/efi |
23
+ * | 1630000000 | | 3 | / |
24
+ * | 1630000000 | | 4 | /boot/efi |
25
+ *
26
+ * OUTPUT:
27
+ * | timestamp | value #1 | value #3 | mount |
28
+ * |------------|----------|----------|-----------|
29
+ * | 1630000000 | 1 | 3 | / |
30
+ * | 1630000000 | 2 | 4 | /boot/efi |
31
+ */ export function applyJoinTransform(data, columns) {
32
+ // If column is undefined or empty, return data as is
33
+ if (columns.length === 0) {
34
+ return data;
35
+ }
36
+ const rowHashed = {};
37
+ for (const row of data){
38
+ const rowHash = Object.keys(row).filter((k)=>columns.includes(k)).map((k)=>row[k]).join('|');
39
+ const rowHashedValue = rowHashed[rowHash];
40
+ if (rowHashedValue) {
41
+ rowHashed[rowHash] = {
42
+ ...rowHashedValue,
43
+ ...row
44
+ };
45
+ } else {
46
+ rowHashed[rowHash] = {
47
+ ...row
48
+ };
49
+ }
50
+ }
51
+ return Object.values(rowHashed);
52
+ }
53
+ /*
54
+ * Merges selected columns into a single column.
55
+ *
56
+ * Example: Merge columns 'value #1' and 'value #2' into a single column 'MERGED'
57
+ * INPUT:
58
+ * +------------+----------+----------+-----------+-----------+
59
+ * | timestamp | value #1 | value #2 | mount #1 | mount #2 |
60
+ * +------------+----------+----------+-----------+-----------+
61
+ * | 1630000000 | 1 | | / | |
62
+ * | 1630000000 | 2 | | /boot/efi | |
63
+ * | 1630000000 | | 3 | | / |
64
+ * | 1630000000 | | 4 | | /boot/efi |
65
+ * +------------+----------+----------+-----------+-----------+
66
+ *
67
+ * OUTPUT:
68
+ * +------------+--------+-----------+-----------+
69
+ * | timestamp | MERGED | mount #1 | mount #2 |
70
+ * +------------+--------+-----------+-----------+
71
+ * | 1630000000 | 1 | / | |
72
+ * | 1630000000 | 2 | /boot/efi | |
73
+ * | 1630000000 | 2 | | / |
74
+ * | 1630000000 | 3 | | /boot/efi |
75
+ * +------------+--------+-----------+-----------+
76
+ */ export function applyMergeColumnsTransform(data, selectedColumns, outputName) {
77
+ const result = [];
78
+ for (const row of data){
79
+ const columns = Object.keys(row).filter((k)=>selectedColumns.includes(k));
80
+ const selectedColumnValues = {};
81
+ for (const column of columns){
82
+ selectedColumnValues[column] = row[column];
83
+ delete row[column];
84
+ }
85
+ for (const column of columns){
86
+ result.push({
87
+ ...row,
88
+ [outputName]: selectedColumnValues[column]
89
+ });
90
+ }
91
+ if (columns.length === 0) {
92
+ result.push(row);
93
+ }
94
+ }
95
+ return result;
96
+ }
97
+ /*
98
+ * Merge Indexed Columns: All indexed columns are merged to one column
99
+ *
100
+ * Example: Join on 'value' column
101
+ * INPUT:
102
+ * | timestamp #1 | timestamp #2 | value #1 | value #2 | instance #1 | instance #2 |
103
+ * |--------------|--------------|----------|----------|-------------|-------------|
104
+ * | 1630000000 | | 55 | | toto | |
105
+ * | 1630000000 | | 33 | | toto | |
106
+ * | 1630000000 | | 45 | | toto | |
107
+ * | | 1630000000 | | 112 | | titi |
108
+ * | | 1630000000 | | 20 | | titi |
109
+ * | | 1630000000 | | 10 | | titi |
110
+ *
111
+ * OUTPUT:
112
+ * | timestamp #1 | timestamp #2 | value | instance #1 | instance #2 |
113
+ * |--------------|--------------|-------|-------------|-------------|
114
+ * | 1630000000 | | 55 | toto | |
115
+ * | 1630000000 | | 33 | toto | |
116
+ * | 1630000000 | | 45 | toto | |
117
+ * | | 1630000000 | 112 | | titi |
118
+ * | | 1630000000 | 20 | | titi |
119
+ * | | 1630000000 | 10 | | titi |
120
+ */ export function applyMergeIndexedColumnsTransform(data, column) {
121
+ const result = [];
122
+ for (const entry of data){
123
+ const indexedColumns = Object.keys(entry).filter((k)=>new RegExp('^((' + column + ' #\\d+)|(' + column + '))$').test(k));
124
+ const indexedColumnValues = {};
125
+ for (const indexedColumn of indexedColumns){
126
+ indexedColumnValues[indexedColumn] = entry[indexedColumn];
127
+ delete entry[indexedColumn];
128
+ }
129
+ for (const indexedColumn of indexedColumns){
130
+ result.push({
131
+ ...entry,
132
+ [column]: indexedColumnValues[indexedColumn]
133
+ });
134
+ }
135
+ if (indexedColumns.length === 0) {
136
+ result.push(entry);
137
+ }
138
+ }
139
+ return result;
140
+ }
141
+ /*
142
+ * Merge Indexed Columns: All indexed columns are merged to one column
143
+ *
144
+ * INPUT:
145
+ * | timestamp | value #1 | value #2 | mount #1 | mount #2 | instance #1 | instance #2 | env #1 | env #2 |
146
+ * |------------|----------|----------|-----------|-----------|-------------|-------------|--------|--------|
147
+ * | 1630000000 | 1 | | / | | test:44 | | prd | |
148
+ * | 1630000000 | 2 | | /boot/efi | | test:44 | | prd | |
149
+ * | 1630000000 | | 5 | | / | | test:44 | | prd |
150
+ * | 1630000000 | | 6 | | /boot/efi | | test:44 | | prd |
151
+ *
152
+ * OUTPUT:
153
+ * | timestamp | value #1 | value #2 | mount | instance | env |
154
+ * |------------|----------|----------|-----------|----------|-----|
155
+ * | 1630000000 | 1 | 5 | / | test:44 | prd |
156
+ * | 1630000000 | 2 | 6 | /boot/efi | test:44 | prd |
157
+ */ export function applyMergeSeriesTransform(data) {
158
+ let result = [
159
+ ...data
160
+ ];
161
+ const labelColumns = Array.from(new Set(data.flatMap(Object.keys).map((label)=>label.replace(/ #\d+/, '')).filter((label)=>label !== 'value')));
162
+ for (const label of labelColumns){
163
+ result = applyMergeIndexedColumnsTransform(result, label);
164
+ }
165
+ result = applyJoinTransform(result, labelColumns);
166
+ return result;
167
+ }
168
+ /*
169
+ * Transforms query data with the given transforms
170
+ */ export function transformData(data, transforms) {
171
+ let result = data;
172
+ // Apply transforms by their orders
173
+ for (const transform of transforms ?? []){
174
+ if (transform.spec.disabled) continue;
175
+ switch(transform.kind){
176
+ case 'JoinByColumnValue':
177
+ {
178
+ if (transform.spec.columns && transform.spec.columns.length > 0) {
179
+ result = applyJoinTransform(result, transform.spec.columns);
180
+ }
181
+ break;
182
+ }
183
+ case 'MergeIndexedColumns':
184
+ {
185
+ if (transform.spec.column) {
186
+ result = applyMergeIndexedColumnsTransform(result, transform.spec.column);
187
+ }
188
+ break;
189
+ }
190
+ case 'MergeColumns':
191
+ {
192
+ if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {
193
+ result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);
194
+ }
195
+ break;
196
+ }
197
+ case 'MergeSeries':
198
+ {
199
+ result = applyMergeSeriesTransform(result);
200
+ break;
201
+ }
202
+ }
203
+ }
204
+ // Ordering data column alphabetically
205
+ result = result.map((row)=>{
206
+ return Object.keys(row).sort().reduce((obj, key)=>{
207
+ obj[key] = row[key];
208
+ return obj;
209
+ }, {});
210
+ });
211
+ return result;
212
+ }
213
+
214
+ //# sourceMappingURL=transform-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/transform-data.ts"],"sourcesContent":["// Copyright 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 { Transform } from '../model';\n\n/*\n * Join: Regroup rows with equal cell value in a column.\n * If there are multiple line with same value, next row values override the current one\n *\n * Example: Join on 'mount' column\n * INPUT:\n * | timestamp | value #1 | value #3 | mount |\n * |------------|----------|----------|-----------|\n * | 1630000000 | 1 | | / |\n * | 1630000000 | 2 | | /boot/efi |\n * | 1630000000 | | 3 | / |\n * | 1630000000 | | 4 | /boot/efi |\n *\n * OUTPUT:\n * | timestamp | value #1 | value #3 | mount |\n * |------------|----------|----------|-----------|\n * | 1630000000 | 1 | 3 | / |\n * | 1630000000 | 2 | 4 | /boot/efi |\n */\nexport function applyJoinTransform(\n data: Array<Record<string, unknown>>,\n columns: string[]\n): Array<Record<string, unknown>> {\n // If column is undefined or empty, return data as is\n if (columns.length === 0) {\n return data;\n }\n\n const rowHashed: { [key: string]: Record<string, unknown> } = {};\n\n for (const row of data) {\n const rowHash = Object.keys(row)\n .filter((k) => columns.includes(k))\n .map((k) => row[k])\n .join('|');\n\n const rowHashedValue = rowHashed[rowHash];\n if (rowHashedValue) {\n rowHashed[rowHash] = { ...rowHashedValue, ...row };\n } else {\n rowHashed[rowHash] = { ...row };\n }\n }\n return Object.values(rowHashed);\n}\n\n/*\n * Merges selected columns into a single column.\n *\n * Example: Merge columns 'value #1' and 'value #2' into a single column 'MERGED'\n * INPUT:\n * +------------+----------+----------+-----------+-----------+\n * | timestamp | value #1 | value #2 | mount #1 | mount #2 |\n * +------------+----------+----------+-----------+-----------+\n * | 1630000000 | 1 | | / | |\n * | 1630000000 | 2 | | /boot/efi | |\n * | 1630000000 | | 3 | | / |\n * | 1630000000 | | 4 | | /boot/efi |\n * +------------+----------+----------+-----------+-----------+\n *\n * OUTPUT:\n * +------------+--------+-----------+-----------+\n * | timestamp | MERGED | mount #1 | mount #2 |\n * +------------+--------+-----------+-----------+\n * | 1630000000 | 1 | / | |\n * | 1630000000 | 2 | /boot/efi | |\n * | 1630000000 | 2 | | / |\n * | 1630000000 | 3 | | /boot/efi |\n * +------------+--------+-----------+-----------+\n */\nexport function applyMergeColumnsTransform(\n data: Array<Record<string, unknown>>,\n selectedColumns: string[],\n outputName: string\n): Array<Record<string, unknown>> {\n const result: Array<Record<string, unknown>> = [];\n\n for (const row of data) {\n const columns = Object.keys(row).filter((k) => selectedColumns.includes(k));\n\n const selectedColumnValues: Record<string, unknown> = {};\n\n for (const column of columns) {\n selectedColumnValues[column] = row[column];\n delete row[column];\n }\n\n for (const column of columns) {\n result.push({ ...row, [outputName]: selectedColumnValues[column] });\n }\n\n if (columns.length === 0) {\n result.push(row);\n }\n }\n\n return result;\n}\n\n/*\n * Merge Indexed Columns: All indexed columns are merged to one column\n *\n * Example: Join on 'value' column\n * INPUT:\n * | timestamp #1 | timestamp #2 | value #1 | value #2 | instance #1 | instance #2 |\n * |--------------|--------------|----------|----------|-------------|-------------|\n * | 1630000000 | | 55 | | toto | |\n * | 1630000000 | | 33 | | toto | |\n * | 1630000000 | | 45 | | toto | |\n * | | 1630000000 | | 112 | | titi |\n * | | 1630000000 | | 20 | | titi |\n * | | 1630000000 | | 10 | | titi |\n *\n * OUTPUT:\n * | timestamp #1 | timestamp #2 | value | instance #1 | instance #2 |\n * |--------------|--------------|-------|-------------|-------------|\n * | 1630000000 | | 55 | toto | |\n * | 1630000000 | | 33 | toto | |\n * | 1630000000 | | 45 | toto | |\n * | | 1630000000 | 112 | | titi |\n * | | 1630000000 | 20 | | titi |\n * | | 1630000000 | 10 | | titi |\n */\nexport function applyMergeIndexedColumnsTransform(\n data: Array<Record<string, unknown>>,\n column: string\n): Array<Record<string, unknown>> {\n const result: Array<Record<string, unknown>> = [];\n\n for (const entry of data) {\n const indexedColumns = Object.keys(entry).filter((k) =>\n new RegExp('^((' + column + ' #\\\\d+)|(' + column + '))$').test(k)\n );\n const indexedColumnValues: Record<string, unknown> = {};\n\n for (const indexedColumn of indexedColumns) {\n indexedColumnValues[indexedColumn] = entry[indexedColumn];\n delete entry[indexedColumn];\n }\n\n for (const indexedColumn of indexedColumns) {\n result.push({ ...entry, [column]: indexedColumnValues[indexedColumn] });\n }\n\n if (indexedColumns.length === 0) {\n result.push(entry);\n }\n }\n\n return result;\n}\n\n/*\n * Merge Indexed Columns: All indexed columns are merged to one column\n *\n * INPUT:\n * | timestamp | value #1 | value #2 | mount #1 | mount #2 | instance #1 | instance #2 | env #1 | env #2 |\n * |------------|----------|----------|-----------|-----------|-------------|-------------|--------|--------|\n * | 1630000000 | 1 | | / | | test:44 | | prd | |\n * | 1630000000 | 2 | | /boot/efi | | test:44 | | prd | |\n * | 1630000000 | | 5 | | / | | test:44 | | prd |\n * | 1630000000 | | 6 | | /boot/efi | | test:44 | | prd |\n *\n * OUTPUT:\n * | timestamp | value #1 | value #2 | mount | instance | env |\n * |------------|----------|----------|-----------|----------|-----|\n * | 1630000000 | 1 | 5 | / | test:44 | prd |\n * | 1630000000 | 2 | 6 | /boot/efi | test:44 | prd |\n */\nexport function applyMergeSeriesTransform(data: Array<Record<string, unknown>>): Array<Record<string, unknown>> {\n let result: Array<Record<string, unknown>> = [...data];\n\n const labelColumns = Array.from(\n new Set(\n data\n .flatMap(Object.keys)\n .map((label) => label.replace(/ #\\d+/, ''))\n .filter((label) => label !== 'value')\n )\n );\n\n for (const label of labelColumns) {\n result = applyMergeIndexedColumnsTransform(result, label);\n }\n\n result = applyJoinTransform(result, labelColumns);\n\n return result;\n}\n\n/*\n * Transforms query data with the given transforms\n */\nexport function transformData(\n data: Array<Record<string, unknown>>,\n transforms: Transform[]\n): Array<Record<string, unknown>> {\n let result: Array<Record<string, unknown>> = data;\n\n // Apply transforms by their orders\n for (const transform of transforms ?? []) {\n if (transform.spec.disabled) continue;\n\n switch (transform.kind) {\n case 'JoinByColumnValue': {\n if (transform.spec.columns && transform.spec.columns.length > 0) {\n result = applyJoinTransform(result, transform.spec.columns);\n }\n break;\n }\n case 'MergeIndexedColumns': {\n if (transform.spec.column) {\n result = applyMergeIndexedColumnsTransform(result, transform.spec.column);\n }\n break;\n }\n case 'MergeColumns': {\n if (transform.spec.columns && transform.spec.columns.length > 0 && transform.spec.name) {\n result = applyMergeColumnsTransform(result, transform.spec.columns, transform.spec.name);\n }\n break;\n }\n case 'MergeSeries': {\n result = applyMergeSeriesTransform(result);\n break;\n }\n }\n }\n\n // Ordering data column alphabetically\n result = result.map((row) => {\n return Object.keys(row)\n .sort()\n .reduce((obj: Record<string, unknown>, key: string) => {\n obj[key] = row[key];\n return obj;\n }, {});\n });\n return result;\n}\n"],"names":["applyJoinTransform","data","columns","length","rowHashed","row","rowHash","Object","keys","filter","k","includes","map","join","rowHashedValue","values","applyMergeColumnsTransform","selectedColumns","outputName","result","selectedColumnValues","column","push","applyMergeIndexedColumnsTransform","entry","indexedColumns","RegExp","test","indexedColumnValues","indexedColumn","applyMergeSeriesTransform","labelColumns","Array","from","Set","flatMap","label","replace","transformData","transforms","transform","spec","disabled","kind","name","sort","reduce","obj","key"],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AAG,CAAC;IACR;IACA,OAAO5B;AACT"}
@@ -0,0 +1,3 @@
1
+ import { MappedValue, ValueMapping } from '../model';
2
+ export declare function applyValueMapping(value: number | string, mappings?: ValueMapping[]): MappedValue;
3
+ //# sourceMappingURL=value-mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-mapping.d.ts","sourceRoot":"","sources":["../../src/utils/value-mapping.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGrD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAE,YAAY,EAAO,GAAG,WAAW,CAkEpG"}
@@ -0,0 +1,97 @@
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
+ import { createRegexFromString } from './regexp';
14
+ export function applyValueMapping(value, mappings = []) {
15
+ if (!mappings.length) {
16
+ return {
17
+ value
18
+ };
19
+ }
20
+ const mappedItem = {
21
+ value
22
+ };
23
+ mappings.forEach((mapping)=>{
24
+ switch(mapping.kind){
25
+ case 'Value':
26
+ {
27
+ const valueOptions = mapping.spec;
28
+ if (String(valueOptions.value) === String(value)) {
29
+ mappedItem.value = valueOptions.result.value || mappedItem.value;
30
+ mappedItem.color = valueOptions.result.color;
31
+ }
32
+ break;
33
+ }
34
+ case 'Range':
35
+ {
36
+ const rangeOptions = mapping.spec;
37
+ const newValue = value;
38
+ if (rangeOptions.from === undefined && rangeOptions.to === undefined) {
39
+ break;
40
+ }
41
+ const from = rangeOptions.from !== undefined ? rangeOptions.from : -Infinity;
42
+ const to = rangeOptions.to !== undefined ? rangeOptions.to : Infinity;
43
+ if (newValue >= from && newValue <= to) {
44
+ mappedItem.value = rangeOptions.result.value || mappedItem.value;
45
+ mappedItem.color = rangeOptions.result.color;
46
+ }
47
+ break;
48
+ }
49
+ case 'Regex':
50
+ {
51
+ const regexOptions = mapping.spec;
52
+ const stringValue = value.toString();
53
+ if (!regexOptions.pattern) {
54
+ break;
55
+ }
56
+ const regex = createRegexFromString(regexOptions.pattern);
57
+ if (stringValue.match(regex)) {
58
+ if (regexOptions.result.value !== null) {
59
+ mappedItem.value = stringValue.replace(regex, regexOptions.result.value.toString() || '') || mappedItem.value;
60
+ mappedItem.color = regexOptions.result.color;
61
+ }
62
+ }
63
+ break;
64
+ }
65
+ case 'Misc':
66
+ {
67
+ const miscOptions = mapping.spec;
68
+ if (isMiscValueMatch(miscOptions.value, value)) {
69
+ mappedItem.value = miscOptions.result.value || mappedItem.value;
70
+ mappedItem.color = miscOptions.result.color;
71
+ }
72
+ break;
73
+ }
74
+ default:
75
+ break;
76
+ }
77
+ });
78
+ return mappedItem;
79
+ }
80
+ function isMiscValueMatch(miscValue, value) {
81
+ switch(miscValue){
82
+ case 'empty':
83
+ return value === '';
84
+ case 'null':
85
+ return value === null || value === undefined;
86
+ case 'NaN':
87
+ return Number.isNaN(value);
88
+ case 'true':
89
+ return value === true;
90
+ case 'false':
91
+ return value === false;
92
+ default:
93
+ return false;
94
+ }
95
+ }
96
+
97
+ //# sourceMappingURL=value-mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/value-mapping.ts"],"sourcesContent":["// Copyright 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 { MappedValue, ValueMapping } from '../model';\nimport { createRegexFromString } from './regexp';\n\nexport function applyValueMapping(value: number | string, mappings: ValueMapping[] = []): MappedValue {\n if (!mappings.length) {\n return { value };\n }\n\n const mappedItem: MappedValue = { value };\n\n mappings.forEach((mapping) => {\n switch (mapping.kind) {\n case 'Value': {\n const valueOptions = mapping.spec;\n\n if (String(valueOptions.value) === String(value)) {\n mappedItem.value = valueOptions.result.value || mappedItem.value;\n mappedItem.color = valueOptions.result.color;\n }\n break;\n }\n case 'Range': {\n const rangeOptions = mapping.spec;\n const newValue = value as number;\n\n if (rangeOptions.from === undefined && rangeOptions.to === undefined) {\n break;\n }\n\n const from = rangeOptions.from !== undefined ? rangeOptions.from : -Infinity;\n const to = rangeOptions.to !== undefined ? rangeOptions.to : Infinity;\n if (newValue >= from && newValue <= to) {\n mappedItem.value = rangeOptions.result.value || mappedItem.value;\n mappedItem.color = rangeOptions.result.color;\n }\n break;\n }\n case 'Regex': {\n const regexOptions = mapping.spec;\n const stringValue = value.toString();\n\n if (!regexOptions.pattern) {\n break;\n }\n\n const regex = createRegexFromString(regexOptions.pattern);\n\n if (stringValue.match(regex)) {\n if (regexOptions.result.value !== null) {\n mappedItem.value =\n stringValue.replace(regex, regexOptions.result.value.toString() || '') || mappedItem.value;\n mappedItem.color = regexOptions.result.color;\n }\n }\n break;\n }\n case 'Misc': {\n const miscOptions = mapping.spec;\n if (isMiscValueMatch(miscOptions.value, value)) {\n mappedItem.value = miscOptions.result.value || mappedItem.value;\n mappedItem.color = miscOptions.result.color;\n }\n break;\n }\n default:\n break;\n }\n });\n return mappedItem;\n}\n\nfunction isMiscValueMatch(miscValue: string, value: number | string | boolean): boolean {\n switch (miscValue) {\n case 'empty':\n return value === '';\n case 'null':\n return value === null || value === undefined;\n case 'NaN':\n return Number.isNaN(value);\n case 'true':\n return value === true;\n case 'false':\n return value === false;\n default:\n return false;\n }\n}\n"],"names":["createRegexFromString","applyValueMapping","value","mappings","length","mappedItem","forEach","mapping","kind","valueOptions","spec","String","result","color","rangeOptions","newValue","from","undefined","to","Infinity","regexOptions","stringValue","toString","pattern","regex","match","replace","miscOptions","isMiscValueMatch","miscValue","Number","isNaN"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,qBAAqB,QAAQ,WAAW;AAEjD,OAAO,SAASC,kBAAkBC,KAAsB,EAAEC,WAA2B,EAAE;IACrF,IAAI,CAACA,SAASC,MAAM,EAAE;QACpB,OAAO;YAAEF;QAAM;IACjB;IAEA,MAAMG,aAA0B;QAAEH;IAAM;IAExCC,SAASG,OAAO,CAAC,CAACC;QAChB,OAAQA,QAAQC,IAAI;YAClB,KAAK;gBAAS;oBACZ,MAAMC,eAAeF,QAAQG,IAAI;oBAEjC,IAAIC,OAAOF,aAAaP,KAAK,MAAMS,OAAOT,QAAQ;wBAChDG,WAAWH,KAAK,GAAGO,aAAaG,MAAM,CAACV,KAAK,IAAIG,WAAWH,KAAK;wBAChEG,WAAWQ,KAAK,GAAGJ,aAAaG,MAAM,CAACC,KAAK;oBAC9C;oBACA;gBACF;YACA,KAAK;gBAAS;oBACZ,MAAMC,eAAeP,QAAQG,IAAI;oBACjC,MAAMK,WAAWb;oBAEjB,IAAIY,aAAaE,IAAI,KAAKC,aAAaH,aAAaI,EAAE,KAAKD,WAAW;wBACpE;oBACF;oBAEA,MAAMD,OAAOF,aAAaE,IAAI,KAAKC,YAAYH,aAAaE,IAAI,GAAG,CAACG;oBACpE,MAAMD,KAAKJ,aAAaI,EAAE,KAAKD,YAAYH,aAAaI,EAAE,GAAGC;oBAC7D,IAAIJ,YAAYC,QAAQD,YAAYG,IAAI;wBACtC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+1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.54.0-beta.2",
3
+ "version": "0.54.0-beta.3",
4
4
  "description": "Common UI components used across Perses features",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -35,7 +35,7 @@
35
35
  "@fontsource/inter": "^5.0.0",
36
36
  "@mui/x-date-pickers": "^7.23.1",
37
37
  "@perses-dev/spec": "0.2.0-beta.0",
38
- "@perses-dev/client": "0.54.0-beta.2",
38
+ "@perses-dev/client": "0.54.0-beta.3",
39
39
  "numbro": "^2.3.6",
40
40
  "@tanstack/match-sorter-utils": "^8.19.4",
41
41
  "@tanstack/react-table": "^8.20.5",