@perses-dev/core 0.25.0 → 0.26.1
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/model/index.js +1 -0
- package/dist/cjs/model/time-series-data.js +16 -0
- package/dist/cjs/test/setup-tests.js +18 -0
- package/dist/cjs/utils/fetch.js +16 -2
- package/dist/cjs/utils/index.js +2 -0
- package/dist/cjs/utils/is-empty-object.js +25 -0
- package/dist/cjs/utils/mathjs.js +25 -0
- package/dist/cjs/utils/time-series-data.js +98 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/time-series-data.d.ts +24 -0
- package/dist/model/time-series-data.d.ts.map +1 -0
- package/dist/model/time-series-data.js +15 -0
- package/dist/model/time-series-data.js.map +1 -0
- package/dist/test/setup-tests.d.ts +2 -0
- package/dist/test/setup-tests.d.ts.map +1 -0
- package/dist/test/setup-tests.js +16 -0
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/utils/fetch.d.ts +7 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +16 -1
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-empty-object.d.ts +5 -0
- package/dist/utils/is-empty-object.d.ts.map +1 -0
- package/dist/utils/is-empty-object.js +19 -0
- package/dist/utils/is-empty-object.js.map +1 -0
- package/dist/utils/mathjs.d.ts +9 -0
- package/dist/utils/mathjs.d.ts.map +1 -0
- package/dist/utils/mathjs.js +20 -0
- package/dist/utils/mathjs.js.map +1 -0
- package/dist/utils/time-series-data.d.ts +20 -0
- package/dist/utils/time-series-data.d.ts.map +1 -0
- package/dist/utils/time-series-data.js +95 -0
- package/dist/utils/time-series-data.js.map +1 -0
- package/package.json +5 -3
package/dist/cjs/model/index.js
CHANGED
|
@@ -25,6 +25,7 @@ _exportStar(require("./panels"), exports);
|
|
|
25
25
|
_exportStar(require("./resource"), exports);
|
|
26
26
|
_exportStar(require("./thresholds"), exports);
|
|
27
27
|
_exportStar(require("./time"), exports);
|
|
28
|
+
_exportStar(require("./time-series-data"), exports);
|
|
28
29
|
_exportStar(require("./time-series-queries"), exports);
|
|
29
30
|
_exportStar(require("./variables"), exports);
|
|
30
31
|
function _exportStar(from, to) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
// Add testing library assertions
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", {
|
|
16
|
+
value: true
|
|
17
|
+
});
|
|
18
|
+
require("@testing-library/jest-dom/extend-expect");
|
package/dist/cjs/utils/fetch.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
/**
|
|
14
|
-
* Calls `global.fetch
|
|
14
|
+
* Calls `global.fetch` and determines which type of error to show for non-200 responses.
|
|
15
15
|
*/ "use strict";
|
|
16
16
|
Object.defineProperty(exports, "__esModule", {
|
|
17
17
|
value: true
|
|
@@ -25,11 +25,19 @@ function _export(target, all) {
|
|
|
25
25
|
_export(exports, {
|
|
26
26
|
fetch: ()=>fetch,
|
|
27
27
|
fetchJson: ()=>fetchJson,
|
|
28
|
-
FetchError: ()=>FetchError
|
|
28
|
+
FetchError: ()=>FetchError,
|
|
29
|
+
UserFriendlyError: ()=>UserFriendlyError
|
|
29
30
|
});
|
|
30
31
|
async function fetch(...args) {
|
|
31
32
|
const response = await global.fetch(...args);
|
|
32
33
|
if (response.ok === false) {
|
|
34
|
+
const json = await response.json();
|
|
35
|
+
if (json.error) {
|
|
36
|
+
throw new UserFriendlyError(json.error);
|
|
37
|
+
}
|
|
38
|
+
if (json.message) {
|
|
39
|
+
throw new UserFriendlyError(json.message);
|
|
40
|
+
}
|
|
33
41
|
throw new FetchError(response);
|
|
34
42
|
}
|
|
35
43
|
return response;
|
|
@@ -45,3 +53,9 @@ class FetchError extends Error {
|
|
|
45
53
|
Object.setPrototypeOf(this, FetchError.prototype);
|
|
46
54
|
}
|
|
47
55
|
}
|
|
56
|
+
class UserFriendlyError extends Error {
|
|
57
|
+
constructor(message){
|
|
58
|
+
super(message);
|
|
59
|
+
Object.setPrototypeOf(this, UserFriendlyError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -16,8 +16,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./event"), exports);
|
|
18
18
|
_exportStar(require("./fetch"), exports);
|
|
19
|
+
_exportStar(require("./is-empty-object"), exports);
|
|
19
20
|
_exportStar(require("./memo"), exports);
|
|
20
21
|
_exportStar(require("./panel-refs"), exports);
|
|
22
|
+
_exportStar(require("./time-series-data"), exports);
|
|
21
23
|
function _exportStar(from, to) {
|
|
22
24
|
Object.keys(from).forEach(function(k) {
|
|
23
25
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Determines if an object is an empty object
|
|
15
|
+
*/ "use strict";
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "isEmptyObject", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: ()=>isEmptyObject
|
|
22
|
+
});
|
|
23
|
+
function isEmptyObject(obj) {
|
|
24
|
+
return Object.getOwnPropertyNames(obj).length === 0;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "gcd", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>gcd
|
|
20
|
+
});
|
|
21
|
+
const _mathjs = require("mathjs");
|
|
22
|
+
// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)
|
|
23
|
+
const { gcd } = (0, _mathjs.create)({
|
|
24
|
+
gcdDependencies: _mathjs.gcdDependencies
|
|
25
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
MIN_STEP_INTERVAL_MS: ()=>MIN_STEP_INTERVAL_MS,
|
|
25
|
+
getXValues: ()=>getXValues,
|
|
26
|
+
getYValues: ()=>getYValues,
|
|
27
|
+
getCommonTimeScale: ()=>getCommonTimeScale
|
|
28
|
+
});
|
|
29
|
+
const _mathjs = require("./mathjs");
|
|
30
|
+
const MIN_STEP_INTERVAL_MS = 10;
|
|
31
|
+
function getXValues(timeScale) {
|
|
32
|
+
const xValues = [];
|
|
33
|
+
let timestamp = timeScale.startMs;
|
|
34
|
+
while(timestamp <= timeScale.endMs){
|
|
35
|
+
xValues.push(timestamp);
|
|
36
|
+
timestamp += timeScale.stepMs;
|
|
37
|
+
}
|
|
38
|
+
return xValues;
|
|
39
|
+
}
|
|
40
|
+
function getYValues(series, timeScale) {
|
|
41
|
+
let timestamp = timeScale.startMs;
|
|
42
|
+
const yValues = [];
|
|
43
|
+
for (const valueTuple of series.values){
|
|
44
|
+
// Fill in values up to the current series value timestamp with nulls
|
|
45
|
+
while(timestamp < valueTuple[0]){
|
|
46
|
+
yValues.push(null);
|
|
47
|
+
timestamp += timeScale.stepMs;
|
|
48
|
+
}
|
|
49
|
+
// Now add the current value since timestamp should match
|
|
50
|
+
yValues.push(valueTuple[1]);
|
|
51
|
+
timestamp += timeScale.stepMs;
|
|
52
|
+
}
|
|
53
|
+
// Add null values at the end of the series if necessary
|
|
54
|
+
while(timestamp <= timeScale.endMs){
|
|
55
|
+
yValues.push(null);
|
|
56
|
+
timestamp += timeScale.stepMs;
|
|
57
|
+
}
|
|
58
|
+
return yValues;
|
|
59
|
+
}
|
|
60
|
+
function getCommonTimeScale(seriesData) {
|
|
61
|
+
let timeRange = undefined;
|
|
62
|
+
const steps = [];
|
|
63
|
+
for (const data of seriesData){
|
|
64
|
+
if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
|
|
65
|
+
// Keep track of query steps so we can calculate a common one for the graph
|
|
66
|
+
steps.push(data.stepMs);
|
|
67
|
+
// If we don't have an overall time range yet, just start with this one
|
|
68
|
+
if (timeRange === undefined) {
|
|
69
|
+
timeRange = data.timeRange;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Otherwise, see if this query has a start or end outside of the current
|
|
73
|
+
// time range
|
|
74
|
+
if (data.timeRange.start < timeRange.start) {
|
|
75
|
+
timeRange.start = data.timeRange.start;
|
|
76
|
+
}
|
|
77
|
+
if (data.timeRange.end > timeRange.end) {
|
|
78
|
+
timeRange.end = data.timeRange.end;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (timeRange === undefined) return undefined;
|
|
82
|
+
// Use the greatest common divisor of all step values as the overall step
|
|
83
|
+
// for the x axis (or if only one query, just use that query's step value)
|
|
84
|
+
let stepMs;
|
|
85
|
+
if (steps.length === 1) {
|
|
86
|
+
stepMs = steps[0];
|
|
87
|
+
} else {
|
|
88
|
+
const calculatedStepMs = (0, _mathjs.gcd)(...steps);
|
|
89
|
+
stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
|
|
90
|
+
}
|
|
91
|
+
const startMs = timeRange.start.valueOf();
|
|
92
|
+
const endMs = timeRange.end.valueOf();
|
|
93
|
+
return {
|
|
94
|
+
startMs,
|
|
95
|
+
endMs,
|
|
96
|
+
stepMs
|
|
97
|
+
};
|
|
98
|
+
}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './panels';
|
|
|
9
9
|
export * from './resource';
|
|
10
10
|
export * from './thresholds';
|
|
11
11
|
export * from './time';
|
|
12
|
+
export * from './time-series-data';
|
|
12
13
|
export * from './time-series-queries';
|
|
13
14
|
export * from './variables';
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
package/dist/model/index.js
CHANGED
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './notice';\nexport * from './panels';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-queries';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './notice';\nexport * from './panels';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Notice } from './notice';
|
|
2
|
+
import { AbsoluteTimeRange } from './time';
|
|
3
|
+
import { Labels, TimeSeriesValueTuple } from './time-series-queries';
|
|
4
|
+
export interface TimeScale {
|
|
5
|
+
startMs: number;
|
|
6
|
+
endMs: number;
|
|
7
|
+
stepMs: number;
|
|
8
|
+
}
|
|
9
|
+
export interface TimeSeriesData {
|
|
10
|
+
timeRange?: AbsoluteTimeRange;
|
|
11
|
+
stepMs?: number;
|
|
12
|
+
series: TimeSeries[];
|
|
13
|
+
metadata?: TimeSeriesMetadata;
|
|
14
|
+
}
|
|
15
|
+
export interface TimeSeries {
|
|
16
|
+
name: string;
|
|
17
|
+
values: TimeSeriesValueTuple[];
|
|
18
|
+
formattedName?: string;
|
|
19
|
+
labels?: Labels;
|
|
20
|
+
}
|
|
21
|
+
export interface TimeSeriesMetadata {
|
|
22
|
+
notices?: Notice[];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=time-series-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/model/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAErE,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=time-series-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice } from './notice';\nimport { AbsoluteTimeRange } from './time';\nimport { Labels, TimeSeriesValueTuple } from './time-series-queries';\n\nexport interface TimeScale {\n startMs: number;\n endMs: number;\n stepMs: number;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n metadata?: TimeSeriesMetadata;\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n labels?: Labels;\n}\n\nexport interface TimeSeriesMetadata {\n notices?: Notice[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA0BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-tests.d.ts","sourceRoot":"","sources":["../../src/test/setup-tests.ts"],"names":[],"mappings":"AAcA,OAAO,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
// Add testing library assertions
|
|
14
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=setup-tests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/test/setup-tests.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Add testing library assertions\nimport '@testing-library/jest-dom/extend-expect';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,iCAAiC;AACjC,OAAO,yCAAyC,CAAC"}
|
package/dist/utils/fetch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Calls `global.fetch
|
|
2
|
+
* Calls `global.fetch` and determines which type of error to show for non-200 responses.
|
|
3
3
|
*/
|
|
4
4
|
export declare function fetch(...args: Parameters<typeof global.fetch>): Promise<Response>;
|
|
5
5
|
/**
|
|
@@ -14,4 +14,10 @@ export declare function fetchJson<T>(...args: Parameters<typeof global.fetch>):
|
|
|
14
14
|
export declare class FetchError extends Error {
|
|
15
15
|
constructor(response: Readonly<Response>);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* General error type for an error that has a message that is OK to show to the end user.
|
|
19
|
+
*/
|
|
20
|
+
export declare class UserFriendlyError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
17
23
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,qBAanE;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,cAI1E;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;CAIzC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/utils/fetch.js
CHANGED
|
@@ -11,10 +11,17 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
/**
|
|
14
|
-
* Calls `global.fetch
|
|
14
|
+
* Calls `global.fetch` and determines which type of error to show for non-200 responses.
|
|
15
15
|
*/ export async function fetch(...args) {
|
|
16
16
|
const response = await global.fetch(...args);
|
|
17
17
|
if (response.ok === false) {
|
|
18
|
+
const json = await response.json();
|
|
19
|
+
if (json.error) {
|
|
20
|
+
throw new UserFriendlyError(json.error);
|
|
21
|
+
}
|
|
22
|
+
if (json.message) {
|
|
23
|
+
throw new UserFriendlyError(json.message);
|
|
24
|
+
}
|
|
18
25
|
throw new FetchError(response);
|
|
19
26
|
}
|
|
20
27
|
return response;
|
|
@@ -36,5 +43,13 @@
|
|
|
36
43
|
Object.setPrototypeOf(this, FetchError.prototype);
|
|
37
44
|
}
|
|
38
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* General error type for an error that has a message that is OK to show to the end user.
|
|
48
|
+
*/ export class UserFriendlyError extends Error {
|
|
49
|
+
constructor(message){
|
|
50
|
+
super(message);
|
|
51
|
+
Object.setPrototypeOf(this, UserFriendlyError.prototype);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
39
54
|
|
|
40
55
|
//# sourceMappingURL=fetch.js.map
|
package/dist/utils/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Calls `global.fetch
|
|
1
|
+
{"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Calls `global.fetch` and determines which type of error to show for non-200 responses.\n */\nexport async function fetch(...args: Parameters<typeof global.fetch>) {\n const response = await global.fetch(...args);\n if (response.ok === false) {\n const json = await response.json();\n if (json.error) {\n throw new UserFriendlyError(json.error);\n }\n if (json.message) {\n throw new UserFriendlyError(json.message);\n }\n throw new FetchError(response);\n }\n return response;\n}\n\n/**\n * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also\n * decodes the response body as JSON, casting it to type `T`. Returns the\n * decoded body.\n */\nexport async function fetchJson<T>(...args: Parameters<typeof global.fetch>) {\n const response = await fetch(...args);\n const json: T = await response.json();\n return json;\n}\n\n/**\n * Error thrown when fetch returns a non-200 response.\n */\nexport class FetchError extends Error {\n constructor(response: Readonly<Response>) {\n super(`${response.status} ${response.statusText}`);\n Object.setPrototypeOf(this, FetchError.prototype);\n }\n}\n\n/**\n * General error type for an error that has a message that is OK to show to the end user.\n */\nexport class UserFriendlyError extends Error {\n constructor(message: string) {\n super(message);\n Object.setPrototypeOf(this, UserFriendlyError.prototype);\n }\n}\n"],"names":["fetch","args","response","global","ok","json","error","UserFriendlyError","message","FetchError","fetchJson","Error","constructor","status","statusText","Object","setPrototypeOf","prototype"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,OAAO,eAAeA,KAAK,CAAC,GAAGC,IAAI,AAAiC,EAAE;IACpE,MAAMC,QAAQ,GAAG,MAAMC,MAAM,CAACH,KAAK,IAAIC,IAAI,CAAC,AAAC;IAC7C,IAAIC,QAAQ,CAACE,EAAE,KAAK,KAAK,EAAE;QACzB,MAAMC,IAAI,GAAG,MAAMH,QAAQ,CAACG,IAAI,EAAE,AAAC;QACnC,IAAIA,IAAI,CAACC,KAAK,EAAE;YACd,MAAM,IAAIC,iBAAiB,CAACF,IAAI,CAACC,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,IAAID,IAAI,CAACG,OAAO,EAAE;YAChB,MAAM,IAAID,iBAAiB,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,IAAIC,UAAU,CAACP,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,OAAOA,QAAQ,CAAC;AAClB,CAAC;AAED;;;;CAIC,GACD,OAAO,eAAeQ,SAAS,CAAI,GAAGT,IAAI,AAAiC,EAAE;IAC3E,MAAMC,QAAQ,GAAG,MAAMF,KAAK,IAAIC,IAAI,CAAC,AAAC;IACtC,MAAMI,IAAI,GAAM,MAAMH,QAAQ,CAACG,IAAI,EAAE,AAAC;IACtC,OAAOA,IAAI,CAAC;AACd,CAAC;AAED;;CAEC,GACD,OAAO,MAAMI,UAAU,SAASE,KAAK;IACnCC,YAAYV,QAA4B,CAAE;QACxC,KAAK,CAAC,CAAC,EAAEA,QAAQ,CAACW,MAAM,CAAC,CAAC,EAAEX,QAAQ,CAACY,UAAU,CAAC,CAAC,CAAC,CAAC;QACnDC,MAAM,CAACC,cAAc,CAAC,IAAI,EAAEP,UAAU,CAACQ,SAAS,CAAC,CAAC;IACpD;CACD;AAED;;CAEC,GACD,OAAO,MAAMV,iBAAiB,SAASI,KAAK;IAC1CC,YAAYJ,OAAe,CAAE;QAC3B,KAAK,CAACA,OAAO,CAAC,CAAC;QACfO,MAAM,CAACC,cAAc,CAAC,IAAI,EAAET,iBAAiB,CAACU,SAAS,CAAC,CAAC;IAC3D;CACD"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './event';
|
|
14
14
|
export * from './fetch';
|
|
15
|
+
export * from './is-empty-object';
|
|
15
16
|
export * from './memo';
|
|
16
17
|
export * from './panel-refs';
|
|
18
|
+
export * from './time-series-data';
|
|
17
19
|
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './event';\nexport * from './fetch';\nexport * from './memo';\nexport * from './panel-refs';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './event';\nexport * from './fetch';\nexport * from './is-empty-object';\nexport * from './memo';\nexport * from './panel-refs';\nexport * from './time-series-data';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty-object.d.ts","sourceRoot":"","sources":["../../src/utils/is-empty-object.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,WAExC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Determines if an object is an empty object
|
|
15
|
+
*/ export function isEmptyObject(obj) {
|
|
16
|
+
return Object.getOwnPropertyNames(obj).length === 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=is-empty-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/is-empty-object.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Determines if an object is an empty object\n */\nexport function isEmptyObject(obj: object) {\n return Object.getOwnPropertyNames(obj).length === 0;\n}\n"],"names":["isEmptyObject","obj","Object","getOwnPropertyNames","length"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;CAEC,GACD,OAAO,SAASA,aAAa,CAACC,GAAW,EAAE;IACzC,OAAOC,MAAM,CAACC,mBAAmB,CAACF,GAAG,CAAC,CAACG,MAAM,KAAK,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const gcd: {
|
|
2
|
+
(...args: number[]): number;
|
|
3
|
+
(...args: import("mathjs").BigNumber[]): import("mathjs").BigNumber;
|
|
4
|
+
(...args: import("mathjs").Fraction[]): import("mathjs").Fraction;
|
|
5
|
+
(...args: import("mathjs").MathArray[]): import("mathjs").MathArray;
|
|
6
|
+
(...args: import("mathjs").Matrix[]): import("mathjs").Matrix;
|
|
7
|
+
};
|
|
8
|
+
export { gcd };
|
|
9
|
+
//# sourceMappingURL=mathjs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mathjs.d.ts","sourceRoot":"","sources":["../../src/utils/mathjs.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAQ,GAAG;;;;;;CAAgC,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { gcdDependencies, create } from 'mathjs';
|
|
14
|
+
// This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)
|
|
15
|
+
const { gcd } = create({
|
|
16
|
+
gcdDependencies
|
|
17
|
+
});
|
|
18
|
+
export { gcd };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=mathjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/mathjs.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { 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 { gcd } = create({ gcdDependencies });\nexport { gcd };\n"],"names":["gcdDependencies","create","gcd"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,eAAe,EAAEC,MAAM,QAAQ,QAAQ,CAAC;AAEjD,uHAAuH;AACvH,MAAM,EAAEC,GAAG,CAAA,EAAE,GAAGD,MAAM,CAAC;IAAED,eAAe;CAAE,CAAC,AAAC;AAC5C,SAASE,GAAG,GAAG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TimeScale, TimeSeries, TimeSeriesData } from '../model';
|
|
2
|
+
export declare const MIN_STEP_INTERVAL_MS = 10;
|
|
3
|
+
/**
|
|
4
|
+
* Given a common time scale (see `getCommonTimeScale`), generates an array of
|
|
5
|
+
* timestamp values in ms for the x axis of a graph.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getXValues(timeScale: TimeScale): number[];
|
|
8
|
+
/**
|
|
9
|
+
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
10
|
+
* gets the values for the y axis of a graph, filling in any timestamps that are
|
|
11
|
+
* missing from the time series data with `null` values.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getYValues(series: TimeSeries, timeScale: TimeScale): Array<number | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Given a list of running queries, calculates a common time scale for use on
|
|
16
|
+
* the x axis (i.e. start/end dates and a step that is divisible into all of
|
|
17
|
+
* the queries' steps).
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCommonTimeScale(seriesData: Array<TimeSeriesData | undefined>): TimeScale | undefined;
|
|
20
|
+
//# 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,MAAM,UAAU,CAAC;AAGpF,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,CAQzD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAuBzF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,CAyCvG"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { gcd } from './mathjs';
|
|
14
|
+
export const MIN_STEP_INTERVAL_MS = 10;
|
|
15
|
+
/**
|
|
16
|
+
* Given a common time scale (see `getCommonTimeScale`), generates an array of
|
|
17
|
+
* timestamp values in ms for the x axis of a graph.
|
|
18
|
+
*/ export function getXValues(timeScale) {
|
|
19
|
+
const xValues = [];
|
|
20
|
+
let timestamp = timeScale.startMs;
|
|
21
|
+
while(timestamp <= timeScale.endMs){
|
|
22
|
+
xValues.push(timestamp);
|
|
23
|
+
timestamp += timeScale.stepMs;
|
|
24
|
+
}
|
|
25
|
+
return xValues;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
29
|
+
* gets the values for the y axis of a graph, filling in any timestamps that are
|
|
30
|
+
* missing from the time series data with `null` values.
|
|
31
|
+
*/ export function getYValues(series, timeScale) {
|
|
32
|
+
let timestamp = timeScale.startMs;
|
|
33
|
+
const yValues = [];
|
|
34
|
+
for (const valueTuple of series.values){
|
|
35
|
+
// Fill in values up to the current series value timestamp with nulls
|
|
36
|
+
while(timestamp < valueTuple[0]){
|
|
37
|
+
yValues.push(null);
|
|
38
|
+
timestamp += timeScale.stepMs;
|
|
39
|
+
}
|
|
40
|
+
// Now add the current value since timestamp should match
|
|
41
|
+
yValues.push(valueTuple[1]);
|
|
42
|
+
timestamp += timeScale.stepMs;
|
|
43
|
+
}
|
|
44
|
+
// Add null values at the end of the series if necessary
|
|
45
|
+
while(timestamp <= timeScale.endMs){
|
|
46
|
+
yValues.push(null);
|
|
47
|
+
timestamp += timeScale.stepMs;
|
|
48
|
+
}
|
|
49
|
+
return yValues;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Given a list of running queries, calculates a common time scale for use on
|
|
53
|
+
* the x axis (i.e. start/end dates and a step that is divisible into all of
|
|
54
|
+
* the queries' steps).
|
|
55
|
+
*/ export function getCommonTimeScale(seriesData) {
|
|
56
|
+
let timeRange = undefined;
|
|
57
|
+
const steps = [];
|
|
58
|
+
for (const data of seriesData){
|
|
59
|
+
if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;
|
|
60
|
+
// Keep track of query steps so we can calculate a common one for the graph
|
|
61
|
+
steps.push(data.stepMs);
|
|
62
|
+
// If we don't have an overall time range yet, just start with this one
|
|
63
|
+
if (timeRange === undefined) {
|
|
64
|
+
timeRange = data.timeRange;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// Otherwise, see if this query has a start or end outside of the current
|
|
68
|
+
// time range
|
|
69
|
+
if (data.timeRange.start < timeRange.start) {
|
|
70
|
+
timeRange.start = data.timeRange.start;
|
|
71
|
+
}
|
|
72
|
+
if (data.timeRange.end > timeRange.end) {
|
|
73
|
+
timeRange.end = data.timeRange.end;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (timeRange === undefined) return undefined;
|
|
77
|
+
// Use the greatest common divisor of all step values as the overall step
|
|
78
|
+
// for the x axis (or if only one query, just use that query's step value)
|
|
79
|
+
let stepMs;
|
|
80
|
+
if (steps.length === 1) {
|
|
81
|
+
stepMs = steps[0];
|
|
82
|
+
} else {
|
|
83
|
+
const calculatedStepMs = gcd(...steps);
|
|
84
|
+
stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
|
|
85
|
+
}
|
|
86
|
+
const startMs = timeRange.start.valueOf();
|
|
87
|
+
const endMs = timeRange.end.valueOf();
|
|
88
|
+
return {
|
|
89
|
+
startMs,
|
|
90
|
+
endMs,
|
|
91
|
+
stepMs
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=time-series-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData } from '../model';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a common time scale (see `getCommonTimeScale`), generates an array of\n * timestamp values in ms for the x axis of a graph.\n */\nexport function getXValues(timeScale: TimeScale): number[] {\n const xValues: number[] = [];\n let timestamp = timeScale.startMs;\n while (timestamp <= timeScale.endMs) {\n xValues.push(timestamp);\n timestamp += timeScale.stepMs;\n }\n return xValues;\n}\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * gets the values for the y axis of a graph, filling in any timestamps that are\n * missing from the time series data with `null` values.\n */\nexport function getYValues(series: TimeSeries, timeScale: TimeScale): Array<number | null> {\n let timestamp = timeScale.startMs;\n\n const yValues: Array<number | null> = [];\n for (const valueTuple of series.values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n yValues.push(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 yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n return yValues;\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(seriesData: Array<TimeSeriesData | undefined>): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n for (const data of seriesData) {\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 }\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\n return { startMs, endMs, stepMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getXValues","timeScale","xValues","timestamp","startMs","endMs","push","stepMs","getYValues","series","yValues","valueTuple","values","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end","length","calculatedStepMs","valueOf"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "Core functionality consumed by both the Perses UI and plugins",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -23,13 +23,15 @@
|
|
|
23
23
|
"build:types": "tsc --project tsconfig.build.json",
|
|
24
24
|
"type-check": "tsc --noEmit",
|
|
25
25
|
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
26
|
-
"test": "
|
|
26
|
+
"test": "TZ=UTC jest",
|
|
27
|
+
"test:watch": "TZ=UTC jest --watch",
|
|
27
28
|
"lint": "eslint src --ext .ts,.tsx",
|
|
28
29
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"date-fns": "^2.28.0",
|
|
32
|
-
"lodash-es": "^4.17.21"
|
|
33
|
+
"lodash-es": "^4.17.21",
|
|
34
|
+
"mathjs": "^10.6.4"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|
|
35
37
|
"react": "^17.0.2 || ^18.0.0",
|