@perses-dev/core 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/cjs/index.js +18 -19
  2. package/dist/cjs/model/dashboard.js +5 -3
  3. package/dist/cjs/model/datasource.js +5 -3
  4. package/dist/cjs/model/definitions.js +7 -3
  5. package/dist/cjs/model/index.js +25 -26
  6. package/dist/cjs/model/layout.js +5 -3
  7. package/dist/cjs/model/panels.js +5 -3
  8. package/dist/cjs/model/resource.js +5 -3
  9. package/dist/cjs/model/{http.js → time-series-queries.js} +5 -8
  10. package/dist/cjs/model/time.js +41 -50
  11. package/dist/cjs/model/variables.js +5 -5
  12. package/dist/cjs/utils/event.js +12 -14
  13. package/dist/cjs/utils/fetch.js +17 -17
  14. package/dist/cjs/utils/index.js +19 -20
  15. package/dist/cjs/utils/memo.js +31 -25
  16. package/dist/cjs/utils/panel-refs.js +13 -10
  17. package/dist/index.js +16 -1
  18. package/dist/index.js.map +1 -0
  19. package/dist/model/dashboard.d.ts +2 -6
  20. package/dist/model/dashboard.d.ts.map +1 -1
  21. package/dist/model/dashboard.js +15 -1
  22. package/dist/model/dashboard.js.map +1 -0
  23. package/dist/model/datasource.d.ts +28 -10
  24. package/dist/model/datasource.d.ts.map +1 -1
  25. package/dist/model/datasource.js +15 -1
  26. package/dist/model/datasource.js.map +1 -0
  27. package/dist/model/definitions.d.ts +2 -12
  28. package/dist/model/definitions.d.ts.map +1 -1
  29. package/dist/model/definitions.js +17 -1
  30. package/dist/model/definitions.js.map +1 -0
  31. package/dist/model/index.d.ts +1 -1
  32. package/dist/model/index.d.ts.map +1 -1
  33. package/dist/model/index.js +23 -1
  34. package/dist/model/index.js.map +1 -0
  35. package/dist/model/layout.js +15 -1
  36. package/dist/model/layout.js.map +1 -0
  37. package/dist/model/panels.d.ts +6 -5
  38. package/dist/model/panels.d.ts.map +1 -1
  39. package/dist/model/panels.js +15 -1
  40. package/dist/model/panels.js.map +1 -0
  41. package/dist/model/resource.d.ts +4 -8
  42. package/dist/model/resource.d.ts.map +1 -1
  43. package/dist/model/resource.js +15 -1
  44. package/dist/model/resource.js.map +1 -0
  45. package/dist/model/time-series-queries.d.ts +8 -0
  46. package/dist/model/time-series-queries.d.ts.map +1 -0
  47. package/dist/model/time-series-queries.js +15 -0
  48. package/dist/model/time-series-queries.js.map +1 -0
  49. package/dist/model/time.js +88 -1
  50. package/dist/model/time.js.map +1 -0
  51. package/dist/model/variables.d.ts +17 -29
  52. package/dist/model/variables.d.ts.map +1 -1
  53. package/dist/model/variables.js +15 -1
  54. package/dist/model/variables.js.map +1 -0
  55. package/dist/utils/event.js +27 -1
  56. package/dist/utils/event.js.map +1 -0
  57. package/dist/utils/fetch.js +41 -1
  58. package/dist/utils/fetch.js.map +1 -0
  59. package/dist/utils/index.js +18 -1
  60. package/dist/utils/index.js.map +1 -0
  61. package/dist/utils/memo.js +51 -1
  62. package/dist/utils/memo.js.map +1 -0
  63. package/dist/utils/panel-refs.d.ts +1 -1
  64. package/dist/utils/panel-refs.js +28 -1
  65. package/dist/utils/panel-refs.js.map +1 -0
  66. package/package.json +6 -3
  67. package/dist/model/http.d.ts +0 -19
  68. package/dist/model/http.d.ts.map +0 -1
  69. package/dist/model/http.js +0 -1
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,20 +10,20 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./model"), exports);
30
- __exportStar(require("./utils"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./model"), exports);
18
+ _exportStar(require("./utils"), exports);
19
+ function _exportStar(from, to) {
20
+ Object.keys(from).forEach(function(k) {
21
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ });
28
+ return from;
29
+ }
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,9 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ /**
14
+ * Base type for definitions in JSON config resources.
15
+ */ "use strict";
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,27 +10,27 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./dashboard"), exports);
30
- __exportStar(require("./datasource"), exports);
31
- __exportStar(require("./definitions"), exports);
32
- __exportStar(require("./http"), exports);
33
- __exportStar(require("./layout"), exports);
34
- __exportStar(require("./panels"), exports);
35
- __exportStar(require("./resource"), exports);
36
- __exportStar(require("./time"), exports);
37
- __exportStar(require("./variables"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./dashboard"), exports);
18
+ _exportStar(require("./datasource"), exports);
19
+ _exportStar(require("./definitions"), exports);
20
+ _exportStar(require("./layout"), exports);
21
+ _exportStar(require("./panels"), exports);
22
+ _exportStar(require("./resource"), exports);
23
+ _exportStar(require("./time"), exports);
24
+ _exportStar(require("./time-series-queries"), exports);
25
+ _exportStar(require("./variables"), exports);
26
+ function _exportStar(from, to) {
27
+ Object.keys(from).forEach(function(k) {
28
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
29
+ enumerable: true,
30
+ get: function() {
31
+ return from[k];
32
+ }
33
+ });
34
+ });
35
+ return from;
36
+ }
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,4 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,9 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.buildDatasourceURL = void 0;
16
- function buildDatasourceURL(datasourceName, config) {
17
- return config.access === 'server' ? `/proxy/globaldatasources/${datasourceName}` : config.url;
18
- }
19
- exports.buildDatasourceURL = buildDatasourceURL;
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,89 +10,81 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getDefaultTimeRange = exports.getSuggestedStepMs = exports.isDurationString = exports.parseDurationString = exports.toAbsoluteTimeRange = exports.isAbsoluteTimeRange = exports.isRelativeTimeRange = void 0;
16
- const date_fns_1 = require("date-fns");
17
- /**
18
- * Determine whether a given time range is relative
19
- */
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
+ isRelativeTimeRange: ()=>isRelativeTimeRange,
25
+ isAbsoluteTimeRange: ()=>isAbsoluteTimeRange,
26
+ toAbsoluteTimeRange: ()=>toAbsoluteTimeRange,
27
+ parseDurationString: ()=>parseDurationString,
28
+ isDurationString: ()=>isDurationString,
29
+ getSuggestedStepMs: ()=>getSuggestedStepMs,
30
+ getDefaultTimeRange: ()=>getDefaultTimeRange
31
+ });
32
+ const _dateFns = require("date-fns");
20
33
  function isRelativeTimeRange(timeRange) {
21
34
  return timeRange.pastDuration !== undefined;
22
35
  }
23
- exports.isRelativeTimeRange = isRelativeTimeRange;
24
- /**
25
- * Determine whether a given time range is absolute
26
- */
27
36
  function isAbsoluteTimeRange(timeRange) {
28
37
  return timeRange.start !== undefined && timeRange.end !== undefined;
29
38
  }
30
- exports.isAbsoluteTimeRange = isAbsoluteTimeRange;
31
- /**
32
- * Returns an absolute time range from a RelativeTimeRange.
33
- */
34
39
  function toAbsoluteTimeRange(timeRange) {
35
- var _a;
36
- const end = (_a = timeRange.end) !== null && _a !== void 0 ? _a : new Date();
40
+ var _end;
41
+ const end = (_end = timeRange.end) !== null && _end !== void 0 ? _end : new Date();
37
42
  return {
38
- start: (0, date_fns_1.sub)(end, parseDurationString(timeRange.pastDuration)),
39
- end,
43
+ start: (0, _dateFns.sub)(end, parseDurationString(timeRange.pastDuration)),
44
+ end
40
45
  };
41
46
  }
42
- exports.toAbsoluteTimeRange = toAbsoluteTimeRange;
43
47
  const DURATION_REGEX = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?(?:(\d+)ms)?$/;
44
- /**
45
- * Parses a DurationString into a Duration object with numeric values that can
46
- * be used to do Date math. Throws if not a valid duration string.
47
- */
48
48
  function parseDurationString(durationString) {
49
- var _a, _b, _c, _d, _e, _f, _g;
50
49
  const matches = DURATION_REGEX.exec(durationString);
51
50
  if (matches === null) {
52
51
  throw new Error(`Invalid duration string '${durationString}'`);
53
52
  }
53
+ var ref, ref1, ref2, ref3, ref4, ref5, ref6;
54
54
  return {
55
- years: parseInt((_a = matches[1]) !== null && _a !== void 0 ? _a : '0'),
55
+ years: parseInt((ref = matches[1]) !== null && ref !== void 0 ? ref : '0'),
56
56
  months: 0,
57
- weeks: parseInt((_b = matches[2]) !== null && _b !== void 0 ? _b : '0'),
58
- days: parseInt((_c = matches[3]) !== null && _c !== void 0 ? _c : '0'),
59
- hours: parseInt((_d = matches[4]) !== null && _d !== void 0 ? _d : '0'),
60
- minutes: parseInt((_e = matches[5]) !== null && _e !== void 0 ? _e : '0'),
61
- seconds: parseInt((_f = matches[6]) !== null && _f !== void 0 ? _f : '0') + parseInt((_g = matches[7]) !== null && _g !== void 0 ? _g : '0') / 1000,
57
+ weeks: parseInt((ref1 = matches[2]) !== null && ref1 !== void 0 ? ref1 : '0'),
58
+ days: parseInt((ref2 = matches[3]) !== null && ref2 !== void 0 ? ref2 : '0'),
59
+ hours: parseInt((ref3 = matches[4]) !== null && ref3 !== void 0 ? ref3 : '0'),
60
+ minutes: parseInt((ref4 = matches[5]) !== null && ref4 !== void 0 ? ref4 : '0'),
61
+ seconds: parseInt((ref5 = matches[6]) !== null && ref5 !== void 0 ? ref5 : '0') + parseInt((ref6 = matches[7]) !== null && ref6 !== void 0 ? ref6 : '0') / 1000
62
62
  };
63
63
  }
64
- exports.parseDurationString = parseDurationString;
65
- /**
66
- * Returns true if the given string is a valid DurationString.
67
- */
68
64
  function isDurationString(maybeDuration) {
69
- if (maybeDuration === '')
70
- return false;
65
+ if (maybeDuration === '') return false;
71
66
  return DURATION_REGEX.test(maybeDuration);
72
67
  }
73
- exports.isDurationString = isDurationString;
74
- /**
75
- * Gets a suggested step/interval size for a time range based on the width of a visual component.
76
- */
77
68
  function getSuggestedStepMs(timeRange, width) {
78
69
  // TODO: Should we try to suggest more "rounded" step values based around
79
70
  // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)
80
71
  const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
81
72
  return Math.floor(queryRangeMs / width);
82
73
  }
83
- exports.getSuggestedStepMs = getSuggestedStepMs;
84
- /**
85
- * Gets the default time range taking into account URL params
86
- */
87
74
  function getDefaultTimeRange(dashboardDuration, queryString) {
88
75
  const startParam = queryString.get('start');
89
76
  const endParam = queryString.get('end');
90
77
  if (startParam === null) {
91
78
  // use relative time range from dashboard definition if start param is empty
92
- return { pastDuration: dashboardDuration };
79
+ return {
80
+ pastDuration: dashboardDuration
81
+ };
93
82
  }
94
83
  // convert query param format to RelativeTimeRange or AbsoluteTimeRange
95
- return isDurationString(startParam)
96
- ? { pastDuration: startParam }
97
- : { start: new Date(Number(startParam)), end: new Date(Number(endParam)) };
84
+ return isDurationString(startParam) ? {
85
+ pastDuration: startParam
86
+ } : {
87
+ start: new Date(Number(startParam)),
88
+ end: new Date(Number(endParam))
89
+ };
98
90
  }
99
- exports.getDefaultTimeRange = getDefaultTimeRange;
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,6 +10,7 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DEFAULT_ALL_VALUE = void 0;
16
- exports.DEFAULT_ALL_VALUE = '$__all';
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,20 +10,19 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useEvent = void 0;
16
- const react_1 = require("react");
17
- /**
18
- * A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.
19
- *
20
- * Typically useful for getting a stable reference to an "event" function (i.e. one that isn't called during render
21
- * but is called later in a useEffect or event handler) that accesses state or props.
22
- */
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "useEvent", {
18
+ enumerable: true,
19
+ get: ()=>useEvent
20
+ });
21
+ const _react = require("react");
23
22
  function useEvent(handler) {
24
- const handlerRef = (0, react_1.useRef)(handler);
25
- (0, react_1.useLayoutEffect)(() => {
23
+ const handlerRef = (0, _react.useRef)(handler);
24
+ (0, _react.useLayoutEffect)(()=>{
26
25
  handlerRef.current = handler;
27
26
  });
28
- return (0, react_1.useCallback)((...args) => handlerRef.current(...args), []);
27
+ return (0, _react.useCallback)((...args)=>handlerRef.current(...args), []);
29
28
  }
30
- exports.useEvent = useEvent;
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,11 +10,23 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.FetchError = exports.fetchJson = exports.fetch = void 0;
16
13
  /**
17
14
  * Calls `global.fetch`, but throws a `FetchError` for non-200 responses.
18
- */
15
+ */ "use strict";
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+ function _export(target, all) {
20
+ for(var name in all)Object.defineProperty(target, name, {
21
+ enumerable: true,
22
+ get: all[name]
23
+ });
24
+ }
25
+ _export(exports, {
26
+ fetch: ()=>fetch,
27
+ fetchJson: ()=>fetchJson,
28
+ FetchError: ()=>FetchError
29
+ });
19
30
  async function fetch(...args) {
20
31
  const response = await global.fetch(...args);
21
32
  if (response.ok === false) {
@@ -23,26 +34,15 @@ async function fetch(...args) {
23
34
  }
24
35
  return response;
25
36
  }
26
- exports.fetch = fetch;
27
- /**
28
- * Calls `global.fetch` and throws a `FetchError` on non-200 responses, but also
29
- * decodes the response body as JSON, casting it to type `T`. Returns the
30
- * decoded body.
31
- */
32
37
  async function fetchJson(...args) {
33
38
  const response = await fetch(...args);
34
39
  const json = await response.json();
35
40
  return json;
36
41
  }
37
- exports.fetchJson = fetchJson;
38
- /**
39
- * Error thrown when fetch returns a non-200 response.
40
- */
41
42
  class FetchError extends Error {
42
- constructor(response) {
43
+ constructor(response){
43
44
  super(`${response.status} ${response.statusText}`);
44
45
  this.response = response;
45
46
  Object.setPrototypeOf(this, FetchError.prototype);
46
47
  }
47
48
  }
48
- exports.FetchError = FetchError;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,22 +10,22 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./event"), exports);
30
- __exportStar(require("./fetch"), exports);
31
- __exportStar(require("./memo"), exports);
32
- __exportStar(require("./panel-refs"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./event"), exports);
18
+ _exportStar(require("./fetch"), exports);
19
+ _exportStar(require("./memo"), exports);
20
+ _exportStar(require("./panel-refs"), exports);
21
+ function _exportStar(from, to) {
22
+ Object.keys(from).forEach(function(k) {
23
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
24
+ enumerable: true,
25
+ get: function() {
26
+ return from[k];
27
+ }
28
+ });
29
+ });
30
+ return from;
31
+ }
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,40 +10,47 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useDeepMemo = exports.useMemoized = void 0;
16
- const react_1 = require("react");
17
- const lodash_es_1 = require("lodash-es");
18
- /**
19
- * Like React's useMemo, but guarantees the value will only be recalulated if
20
- * a dependency changes. Uses strict equality (===) for comparison. (React's
21
- * useMemo does not offer this guarantee, it's only a performance optimization).
22
- */
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
+ useMemoized: ()=>useMemoized,
25
+ useDeepMemo: ()=>useDeepMemo
26
+ });
27
+ const _react = require("react");
28
+ const _lodashEs = require("lodash-es");
23
29
  function useMemoized(factory, deps) {
24
- var _a;
25
- const ref = (0, react_1.useRef)();
30
+ const ref = (0, _react.useRef)();
26
31
  let areEqual = true;
27
- for (let i = 0; i < deps.length; i++) {
28
- if (((_a = ref.current) === null || _a === void 0 ? void 0 : _a.deps[i]) !== deps[i]) {
32
+ for(let i = 0; i < deps.length; i++){
33
+ var ref1;
34
+ if (((ref1 = ref.current) === null || ref1 === void 0 ? void 0 : ref1.deps[i]) !== deps[i]) {
29
35
  areEqual = false;
30
36
  break;
31
37
  }
32
38
  }
33
39
  if (ref.current === undefined || areEqual === false) {
34
- ref.current = { value: factory(), deps: deps };
40
+ ref.current = {
41
+ value: factory(),
42
+ deps: deps
43
+ };
35
44
  }
36
45
  return ref.current.value;
37
46
  }
38
- exports.useMemoized = useMemoized;
39
- /**
40
- * Like React's useMemo, except it does a deep equality comparison with lodash's
41
- * isEqual on the dependency list.
42
- */
43
47
  function useDeepMemo(factory, deps) {
44
- const ref = (0, react_1.useRef)();
45
- if (ref.current === undefined || (0, lodash_es_1.isEqual)(deps, ref.current.deps) === false) {
46
- ref.current = { value: factory(), deps };
48
+ const ref = (0, _react.useRef)();
49
+ if (ref.current === undefined || (0, _lodashEs.isEqual)(deps, ref.current.deps) === false) {
50
+ ref.current = {
51
+ value: factory(),
52
+ deps
53
+ };
47
54
  }
48
55
  return ref.current.value;
49
56
  }
50
- exports.useDeepMemo = useDeepMemo;
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
1
+ // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
5
4
  // You may obtain a copy of the License at
@@ -11,18 +10,22 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.resolvePanelRef = void 0;
16
- /**
17
- * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to
18
- * a PanelDefinition.
19
- */
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "resolvePanelRef", {
18
+ enumerable: true,
19
+ get: ()=>resolvePanelRef
20
+ });
20
21
  function resolvePanelRef(spec, panelRef) {
21
22
  const panelsKey = panelRef.$ref.substring(14);
22
23
  const panelDefinition = spec.panels[panelsKey];
23
24
  if (panelDefinition === undefined) {
24
25
  throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);
25
26
  }
26
- return { panelDefinition, panelsKey };
27
+ return {
28
+ panelDefinition,
29
+ panelsKey
30
+ };
27
31
  }
28
- exports.resolvePanelRef = resolvePanelRef;