@perses-dev/core 0.37.2 → 0.39.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 (59) hide show
  1. package/dist/cjs/model/calculations.js +0 -2
  2. package/dist/cjs/model/index.js +1 -0
  3. package/dist/cjs/model/project.js +16 -0
  4. package/dist/cjs/model/units/bytes.js +13 -7
  5. package/dist/cjs/model/units/decimal.js +3 -3
  6. package/dist/cjs/model/units/percent.js +6 -5
  7. package/dist/cjs/model/units/time.js +57 -4
  8. package/dist/cjs/model/units/units.js +5 -5
  9. package/dist/cjs/utils/text.js +34 -6
  10. package/dist/model/calculations.d.ts +0 -1
  11. package/dist/model/calculations.d.ts.map +1 -1
  12. package/dist/model/calculations.js +0 -1
  13. package/dist/model/calculations.js.map +1 -1
  14. package/dist/model/datasource.d.ts +1 -1
  15. package/dist/model/datasource.js.map +1 -1
  16. package/dist/model/index.d.ts +1 -0
  17. package/dist/model/index.d.ts.map +1 -1
  18. package/dist/model/index.js +1 -0
  19. package/dist/model/index.js.map +1 -1
  20. package/dist/model/project.d.ts +6 -0
  21. package/dist/model/project.d.ts.map +1 -0
  22. package/dist/model/project.js +15 -0
  23. package/dist/model/project.js.map +1 -0
  24. package/dist/model/query.d.ts +13 -2
  25. package/dist/model/query.d.ts.map +1 -1
  26. package/dist/model/query.js.map +1 -1
  27. package/dist/model/time-series-data.d.ts +6 -0
  28. package/dist/model/time-series-data.d.ts.map +1 -1
  29. package/dist/model/time-series-data.js.map +1 -1
  30. package/dist/model/units/bytes.d.ts +1 -1
  31. package/dist/model/units/bytes.d.ts.map +1 -1
  32. package/dist/model/units/bytes.js +13 -7
  33. package/dist/model/units/bytes.js.map +1 -1
  34. package/dist/model/units/decimal.d.ts +1 -1
  35. package/dist/model/units/decimal.d.ts.map +1 -1
  36. package/dist/model/units/decimal.js +3 -3
  37. package/dist/model/units/decimal.js.map +1 -1
  38. package/dist/model/units/percent.d.ts.map +1 -1
  39. package/dist/model/units/percent.js +6 -5
  40. package/dist/model/units/percent.js.map +1 -1
  41. package/dist/model/units/time.d.ts.map +1 -1
  42. package/dist/model/units/time.js +57 -4
  43. package/dist/model/units/time.js.map +1 -1
  44. package/dist/model/units/units.d.ts +7 -0
  45. package/dist/model/units/units.d.ts.map +1 -1
  46. package/dist/model/units/units.js +15 -9
  47. package/dist/model/units/units.js.map +1 -1
  48. package/dist/model/variables.d.ts +10 -2
  49. package/dist/model/variables.d.ts.map +1 -1
  50. package/dist/model/variables.js.map +1 -1
  51. package/dist/utils/text.d.ts +37 -3
  52. package/dist/utils/text.d.ts.map +1 -1
  53. package/dist/utils/text.js +52 -4
  54. package/dist/utils/text.js.map +1 -1
  55. package/dist/utils/time-series-data.d.ts +1 -0
  56. package/dist/utils/time-series-data.d.ts.map +1 -1
  57. package/dist/utils/time-series-data.js +1 -0
  58. package/dist/utils/time-series-data.js.map +1 -1
  59. package/package.json +1 -1
@@ -23,7 +23,6 @@ function _export(target, all) {
23
23
  _export(exports, {
24
24
  CalculationsMap: ()=>CalculationsMap,
25
25
  CALCULATIONS_CONFIG: ()=>CALCULATIONS_CONFIG,
26
- DEFAULT_CALCULATION: ()=>DEFAULT_CALCULATION,
27
26
  getCalculations: ()=>getCalculations,
28
27
  getCalculation: ()=>getCalculation
29
28
  });
@@ -71,7 +70,6 @@ const CALCULATIONS_CONFIG = {
71
70
  description: 'Maximum value'
72
71
  }
73
72
  };
74
- const DEFAULT_CALCULATION = 'Sum';
75
73
  function getCalculations(values, includeCalculations) {
76
74
  const calculations = includeCalculations.reduce((initResult, calculation)=>{
77
75
  initResult[calculation] = undefined;
@@ -24,6 +24,7 @@ _exportStar(require("./layout"), exports);
24
24
  _exportStar(require("./legend"), exports);
25
25
  _exportStar(require("./notice"), exports);
26
26
  _exportStar(require("./panels"), exports);
27
+ _exportStar(require("./project"), exports);
27
28
  _exportStar(require("./query"), exports);
28
29
  _exportStar(require("./resource"), exports);
29
30
  _exportStar(require("./thresholds"), exports);
@@ -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
+ });
@@ -33,7 +33,13 @@ function _interopRequireDefault(obj) {
33
33
  default: obj
34
34
  };
35
35
  }
36
- const DEFAULT_NUMBRO_MANTISSA = 2;
36
+ /**
37
+ * We consider the units for bytes to be powers of 1000.
38
+ * In other words:
39
+ * 1 KB = 1000 bytes (1000^1 bytes)
40
+ * 1 MB = 1,000,000 bytes (1000^2 bytes)
41
+ * etc.
42
+ */ const DEFAULT_NUMBRO_MANTISSA = 2;
37
43
  const bytesUnitKinds = [
38
44
  'Bytes'
39
45
  ];
@@ -43,15 +49,13 @@ const BYTES_GROUP_CONFIG = {
43
49
  abbreviate: true
44
50
  };
45
51
  const BYTES_UNIT_CONFIG = {
46
- // These units are powers of 1000.
47
- // In other words, 1 KB = 1000 bytes.
48
52
  Bytes: {
49
53
  group: 'Bytes',
50
54
  label: 'Bytes'
51
55
  }
52
56
  };
53
- function formatBytes(bytes, options) {
54
- const { abbreviate , decimal_places } = options;
57
+ function formatBytes(bytes, { abbreviate , decimal_places }) {
58
+ // If we're showing the entire value, we can use Intl.NumberFormat.
55
59
  if (!(0, _utils.shouldAbbreviate)(abbreviate) || Math.abs(bytes) < 1000) {
56
60
  const formatterOptions = {
57
61
  style: 'unit',
@@ -68,9 +72,11 @@ function formatBytes(bytes, options) {
68
72
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
69
73
  }
70
74
  }
71
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
75
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
76
+ return formatter.format(bytes);
72
77
  }
73
- // numbro is able to add units like KB, MB, GB, etc. correctly
78
+ // If we're showing the "abbreviated" value, we use numbro.
79
+ // numbro is able to add units like KB, MB, GB, etc. correctly.
74
80
  return (0, _numbro.default)(bytes).format({
75
81
  output: 'byte',
76
82
  base: 'decimal',
@@ -41,8 +41,7 @@ const DECIMAL_UNIT_CONFIG = {
41
41
  label: 'Decimal'
42
42
  }
43
43
  };
44
- function formatDecimal(value, options) {
45
- const { abbreviate , decimal_places } = options;
44
+ function formatDecimal(value, { abbreviate , decimal_places }) {
46
45
  const formatterOptions = {
47
46
  style: 'decimal',
48
47
  useGrouping: true
@@ -58,5 +57,6 @@ function formatDecimal(value, options) {
58
57
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
59
58
  }
60
59
  }
61
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
60
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
61
+ return formatter.format(value);
62
62
  }
@@ -55,10 +55,6 @@ const PERCENT_UNIT_CONFIG = {
55
55
  }
56
56
  };
57
57
  function formatPercent(value, { kind , decimal_places }) {
58
- // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
59
- if (kind === 'Percent') {
60
- value = value / 100;
61
- }
62
58
  const formatterOptions = {
63
59
  style: 'percent',
64
60
  useGrouping: true
@@ -69,5 +65,10 @@ function formatPercent(value, { kind , decimal_places }) {
69
65
  } else {
70
66
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
71
67
  }
72
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
68
+ // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
69
+ if (kind === 'Percent') {
70
+ value = value / 100;
71
+ }
72
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
73
+ return formatter.format(value);
73
74
  }
@@ -88,12 +88,64 @@ var PersesTimeToIntlTime;
88
88
  PersesTimeToIntlTime["Months"] = 'month';
89
89
  PersesTimeToIntlTime["Years"] = 'year';
90
90
  })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
91
+ /**
92
+ * Note: This conversion will not be exactly accurate for months and years,
93
+ * due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).
94
+ * For precision with months and years, we would need more complex algorithms and/or external libraries.
95
+ * However, we expect that measurements in months and years will be rare.
96
+ */ const TIME_UNITS_IN_SECONDS = {
97
+ Years: 31536000,
98
+ Months: 2592000,
99
+ Weeks: 604800,
100
+ Days: 86400,
101
+ Hours: 3600,
102
+ Minutes: 60,
103
+ Seconds: 1,
104
+ Milliseconds: 0.001
105
+ };
106
+ const LARGEST_TO_SMALLEST_TIME_UNITS = [
107
+ 'Years',
108
+ 'Months',
109
+ 'Weeks',
110
+ 'Days',
111
+ 'Hours',
112
+ 'Minutes',
113
+ 'Seconds',
114
+ 'Milliseconds'
115
+ ];
116
+ /**
117
+ * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.
118
+ */ function getValueAndKindForNaturalNumbers(value, kind) {
119
+ const valueInSeconds = value * TIME_UNITS_IN_SECONDS[kind];
120
+ // Initialize for TS
121
+ const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'Years';
122
+ let timeUnit = largestTimeUnit;
123
+ let valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];
124
+ for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS){
125
+ valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];
126
+ if (valueInTimeUnit >= 1) {
127
+ return {
128
+ value: valueInTimeUnit,
129
+ kind: timeUnit
130
+ };
131
+ }
132
+ }
133
+ // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).
134
+ return {
135
+ value: valueInTimeUnit,
136
+ kind: timeUnit
137
+ };
138
+ }
139
+ function isMonthOrYear(kind) {
140
+ return kind === 'Months' || kind === 'Years';
141
+ }
91
142
  function formatTime(value, { kind , decimal_places }) {
92
- const isMonthOrYear = kind === 'Months' || kind === 'Years';
143
+ if (value === 0) return '0s';
144
+ const results = getValueAndKindForNaturalNumbers(value, kind);
93
145
  const formatterOptions = {
94
146
  style: 'unit',
95
- unit: PersesTimeToIntlTime[kind],
96
- unitDisplay: isMonthOrYear ? 'long' : 'narrow'
147
+ unit: PersesTimeToIntlTime[results.kind],
148
+ unitDisplay: isMonthOrYear(results.kind) ? 'long' : 'narrow'
97
149
  };
98
150
  if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
99
151
  formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
@@ -101,5 +153,6 @@ function formatTime(value, { kind , decimal_places }) {
101
153
  } else {
102
154
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
103
155
  }
104
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
156
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
157
+ return formatter.format(results.value);
105
158
  }
@@ -54,17 +54,17 @@ function formatValue(value, unitOptions) {
54
54
  if (unitOptions === undefined) {
55
55
  return value.toString();
56
56
  }
57
+ if (isBytesUnit(unitOptions)) {
58
+ return (0, _bytes.formatBytes)(value, unitOptions);
59
+ }
57
60
  if (isDecimalUnit(unitOptions)) {
58
61
  return (0, _decimal.formatDecimal)(value, unitOptions);
59
62
  }
60
- if (isTimeUnit(unitOptions)) {
61
- return (0, _time.formatTime)(value, unitOptions);
62
- }
63
63
  if (isPercentUnit(unitOptions)) {
64
64
  return (0, _percent.formatPercent)(value, unitOptions);
65
65
  }
66
- if (isBytesUnit(unitOptions)) {
67
- return (0, _bytes.formatBytes)(value, unitOptions);
66
+ if (isTimeUnit(unitOptions)) {
67
+ return (0, _time.formatTime)(value, unitOptions);
68
68
  }
69
69
  const exhaustive = unitOptions;
70
70
  throw new Error(`Unknown unit options ${exhaustive}`);
@@ -21,17 +21,45 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- dashboardDisplayName: ()=>dashboardDisplayName,
25
- dashboardExtendedDisplayName: ()=>dashboardExtendedDisplayName
24
+ getDashboardDisplayName: ()=>getDashboardDisplayName,
25
+ getVariableDisplayName: ()=>getVariableDisplayName,
26
+ getDatasourceDisplayName: ()=>getDatasourceDisplayName,
27
+ getDashboardExtendedDisplayName: ()=>getDashboardExtendedDisplayName,
28
+ getVariableExtendedDisplayName: ()=>getVariableExtendedDisplayName,
29
+ getDatasourceExtendedDisplayName: ()=>getDatasourceExtendedDisplayName
26
30
  });
27
- function dashboardDisplayName(dashboard) {
31
+ function getDashboardDisplayName(dashboard) {
28
32
  var ref;
29
- return ((ref = dashboard.spec.display) === null || ref === void 0 ? void 0 : ref.name) || dashboard.metadata.name;
33
+ var ref1;
34
+ return (ref1 = (ref = dashboard.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : dashboard.metadata.name;
30
35
  }
31
- function dashboardExtendedDisplayName(dashboard) {
36
+ function getVariableDisplayName(variable) {
37
+ var ref;
38
+ var ref1;
39
+ return (ref1 = (ref = variable.spec.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : variable.metadata.name;
40
+ }
41
+ function getDatasourceDisplayName(datasource) {
42
+ var ref;
43
+ return ((ref = datasource.spec.display) === null || ref === void 0 ? void 0 : ref.name) || datasource.metadata.name;
44
+ }
45
+ function getDashboardExtendedDisplayName(dashboard) {
32
46
  var ref;
33
47
  if ((ref = dashboard.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
34
- return `${dashboard.spec.display.name} (ID: ${dashboard.metadata.name})`;
48
+ return `${dashboard.spec.display.name} (Name: ${dashboard.metadata.name})`;
35
49
  }
36
50
  return dashboard.metadata.name;
37
51
  }
52
+ function getVariableExtendedDisplayName(variable) {
53
+ var ref;
54
+ if ((ref = variable.spec.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
55
+ return `${variable.spec.spec.display.name} (Name: ${variable.metadata.name})`;
56
+ }
57
+ return variable.metadata.name;
58
+ }
59
+ function getDatasourceExtendedDisplayName(datasource) {
60
+ var ref;
61
+ if ((ref = datasource.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
62
+ return `${datasource.spec.display.name} (ID: ${datasource.metadata.name})`;
63
+ }
64
+ return datasource.metadata.name;
65
+ }
@@ -15,7 +15,6 @@ export declare type CalculationConfig = {
15
15
  description: string;
16
16
  };
17
17
  export declare const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>>;
18
- export declare const DEFAULT_CALCULATION: CalculationType;
19
18
  declare type CalculationValue = number | null | undefined;
20
19
  /**
21
20
  * Calculate a multiple values for a set of time series data.
@@ -1 +1 @@
1
- {"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAiC3E,CAAC;AAEX,eAAO,MAAM,mBAAmB,EAAE,eAAuB,CAAC;AAE1D,aAAK,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,SAAS,eAAe,EAAE,EACpE,MAAM,EAAE,oBAAoB,EAAE,EAC9B,mBAAmB,EAAE,YAAY,GAChC,MAAM,CAGP,OAA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,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,SAAS,eAAe,EAAE,EACpE,MAAM,EAAE,oBAAoB,EAAE,EAC9B,mBAAmB,EAAE,YAAY,GAChC,MAAM,CAGP,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,EAC9C,gBAAgB,CACjB,CA2EA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,WAAW,EAAE,eAAe,oBAE1F;AAED,iBAAS,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE/D;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAErE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAEpE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D"}
@@ -54,7 +54,6 @@ export const CALCULATIONS_CONFIG = {
54
54
  description: 'Maximum value'
55
55
  }
56
56
  };
57
- export const DEFAULT_CALCULATION = 'Sum';
58
57
  /**
59
58
  * Calculate a multiple values for a set of time series data.
60
59
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","DEFAULT_CALCULATION","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"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;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,WAAW,EAAEC,WAAW;IACxBC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;CACT,CAAC;AASF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFhB,KAAK,EAAE;QACLiB,KAAK,EAAE,OAAO;QACdC,WAAW,EAAE,aAAa;KAC3B;IACDhB,IAAI,EAAE;QACJe,KAAK,EAAE,MAAM;QACbC,WAAW,EAAE,YAAY;KAC1B;IACDd,WAAW,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M,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
1
+ {"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"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;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,WAAW,EAAEC,WAAW;IACxBC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;CACT,CAAC;AASF,OAAO,MAAMC,mBAAmB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AASP,GAAG,CAACO,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED,SAASL,GAAG,CAACK,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
@@ -10,7 +10,7 @@ export interface GlobalDatasource {
10
10
  spec: DatasourceSpec;
11
11
  }
12
12
  /**
13
- * A Datasource that belongs to a project.
13
+ * A Datasource resource, that belongs to a project.
14
14
  */
15
15
  export interface Datasource {
16
16
  kind: 'Datasource';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/datasource.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 { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource that belongs to a project.\n */\nexport interface Datasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource. If name is omitted, it's assumed that you want the default\n * Datasource for the specified kind.\n */\nexport interface DatasourceSelector {\n kind: string;\n name?: string;\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,WAmCC"}
1
+ {"version":3,"sources":["../../src/model/datasource.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 { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource resource, that belongs to a project.\n */\nexport interface Datasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource. If name is omitted, it's assumed that you want the default\n * Datasource for the specified kind.\n */\nexport interface DatasourceSelector {\n kind: string;\n name?: string;\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,WAmCC"}
@@ -8,6 +8,7 @@ export * from './layout';
8
8
  export * from './legend';
9
9
  export * from './notice';
10
10
  export * from './panels';
11
+ export * from './project';
11
12
  export * from './query';
12
13
  export * from './resource';
13
14
  export * from './thresholds';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,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,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,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,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -20,6 +20,7 @@ export * from './layout';
20
20
  export * from './legend';
21
21
  export * from './notice';
22
22
  export * from './panels';
23
+ export * from './project';
23
24
  export * from './query';
24
25
  export * from './resource';
25
26
  export * from './thresholds';
@@ -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 './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './units';\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,gBAAgB,CAAC;AAC/B,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,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,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 './calculations';\nexport * from './dashboard';\nexport * from './datasource';\nexport * from './definitions';\nexport * from './display';\nexport * from './http';\nexport * from './layout';\nexport * from './legend';\nexport * from './notice';\nexport * from './panels';\nexport * from './project';\nexport * from './query';\nexport * from './resource';\nexport * from './thresholds';\nexport * from './time';\nexport * from './time-series-data';\nexport * from './time-series-queries';\nexport * from './units';\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,gBAAgB,CAAC;AAC/B,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,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Metadata } from './resource';
2
+ export interface ProjectResource {
3
+ kind: 'Project';
4
+ metadata: Metadata;
5
+ }
6
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/model/project.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,QAAQ,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=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/project.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 { Metadata } from './resource';\n\nexport interface ProjectResource {\n kind: 'Project';\n metadata: Metadata;\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,WAKC"}
@@ -1,14 +1,25 @@
1
1
  import { Definition, UnknownSpec } from './definitions';
2
+ import { TimeSeriesData } from './time-series-data';
2
3
  interface QuerySpec<PluginSpec> {
3
4
  plugin: Definition<PluginSpec>;
4
5
  }
5
6
  /**
6
7
  * A generic query definition interface that can be extended to support more than just TimeSeriesQuery
7
8
  */
8
- export interface QueryDefinition<Kind = QueryType, PluginSpec = UnknownSpec> {
9
+ export interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {
9
10
  kind: Kind;
10
11
  spec: QuerySpec<PluginSpec>;
11
12
  }
12
- export declare type QueryType = 'TimeSeriesQuery';
13
+ /**
14
+ * Mapping the query plugin to the data type it returns
15
+ */
16
+ export interface QueryType {
17
+ TimeSeriesQuery: TimeSeriesData;
18
+ }
19
+ /**
20
+ * Values of QueryType
21
+ * ex: 'TimeSeriesData'
22
+ */
23
+ export declare type QueryDataType = QueryType[keyof QueryType];
13
24
  export {};
14
25
  //# sourceMappingURL=query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/model/query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAExD,UAAU,SAAS,CAAC,UAAU;IAC5B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AACD;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,IAAI,GAAG,SAAS,EAAE,UAAU,GAAG,WAAW;IACzE,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED,oBAAY,SAAS,GAAG,iBAAiB,CAAC"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/model/query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,UAAU,SAAS,CAAC,UAAU;IAC5B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AACD;;GAEG;AAGH,MAAM,WAAW,eAAe,CAAC,IAAI,GAAG,GAAG,EAAE,UAAU,GAAG,WAAW;IACnE,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,EAAE,cAAc,CAAC;CAGjC;AAED;;;GAGG;AACH,oBAAY,aAAa,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/query.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 { Definition, UnknownSpec } from './definitions';\n\ninterface QuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n/**\n * A generic query definition interface that can be extended to support more than just TimeSeriesQuery\n */\nexport interface QueryDefinition<Kind = QueryType, PluginSpec = UnknownSpec> {\n kind: Kind;\n spec: QuerySpec<PluginSpec>;\n}\n\nexport type QueryType = 'TimeSeriesQuery';\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,WAa0C"}
1
+ {"version":3,"sources":["../../src/model/query.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 { Definition, UnknownSpec } from './definitions';\nimport { TimeSeriesData } from './time-series-data';\n\ninterface QuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n/**\n * A generic query definition interface that can be extended to support more than just TimeSeriesQuery\n */\n// Kind needs to be `any` because otherwise typescript will complain 'unknown' is not assignable to type '\"TimeSeriesQuery\"' in a few places\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {\n kind: Kind;\n spec: QuerySpec<PluginSpec>;\n}\n\n/**\n * Mapping the query plugin to the data type it returns\n */\nexport interface QueryType {\n TimeSeriesQuery: TimeSeriesData;\n // in the future we can add other query plugin and data types\n // for example: we can add something like `LogsQuery: LogsData;`\n}\n\n/**\n * Values of QueryType\n * ex: 'TimeSeriesData'\n */\nexport type QueryDataType = QueryType[keyof QueryType];\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,WA6BuD"}
@@ -21,5 +21,11 @@ export interface TimeSeries {
21
21
  }
22
22
  export interface TimeSeriesMetadata {
23
23
  notices?: Notice[];
24
+ /**
25
+ * The raw query that is executed to generate this data.
26
+ * Useful when needing to inspect the query that was executed
27
+ * after variables and other context modifications have been applied.
28
+ */
29
+ executedQueryString?: string;
24
30
  }
25
31
  //# sourceMappingURL=time-series-data.d.ts.map
@@ -1 +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;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;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"}
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;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;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;IAEnB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
@@ -1 +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 rangeMs: 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,WA2BC"}
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 rangeMs: 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 /**\n * The raw query that is executed to generate this data.\n * Useful when needing to inspect the query that was executed\n * after variables and other context modifications have been applied.\n */\n executedQueryString?: string;\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,WAkCC"}
@@ -8,6 +8,6 @@ export declare type BytesUnitOptions = {
8
8
  };
9
9
  export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
10
10
  export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
11
- export declare function formatBytes(bytes: number, options: BytesUnitOptions): string;
11
+ export declare function formatBytes(bytes: number, { abbreviate, decimal_places }: BytesUnitOptions): string;
12
12
  export {};
13
13
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAOzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,UAmCnE"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAatD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,gBAAgB,UAmC1F"}
@@ -13,7 +13,13 @@
13
13
  import numbro from 'numbro';
14
14
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
15
  import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
16
- const DEFAULT_NUMBRO_MANTISSA = 2;
16
+ /**
17
+ * We consider the units for bytes to be powers of 1000.
18
+ * In other words:
19
+ * 1 KB = 1000 bytes (1000^1 bytes)
20
+ * 1 MB = 1,000,000 bytes (1000^2 bytes)
21
+ * etc.
22
+ */ const DEFAULT_NUMBRO_MANTISSA = 2;
17
23
  const bytesUnitKinds = [
18
24
  'Bytes'
19
25
  ];
@@ -23,15 +29,13 @@ export const BYTES_GROUP_CONFIG = {
23
29
  abbreviate: true
24
30
  };
25
31
  export const BYTES_UNIT_CONFIG = {
26
- // These units are powers of 1000.
27
- // In other words, 1 KB = 1000 bytes.
28
32
  Bytes: {
29
33
  group: 'Bytes',
30
34
  label: 'Bytes'
31
35
  }
32
36
  };
33
- export function formatBytes(bytes, options) {
34
- const { abbreviate , decimal_places } = options;
37
+ export function formatBytes(bytes, { abbreviate , decimal_places }) {
38
+ // If we're showing the entire value, we can use Intl.NumberFormat.
35
39
  if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
36
40
  const formatterOptions = {
37
41
  style: 'unit',
@@ -48,9 +52,11 @@ export function formatBytes(bytes, options) {
48
52
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
49
53
  }
50
54
  }
51
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
55
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
56
+ return formatter.format(bytes);
52
57
  }
53
- // numbro is able to add units like KB, MB, GB, etc. correctly
58
+ // If we're showing the "abbreviated" value, we use numbro.
59
+ // numbro is able to add units like KB, MB, GB, etc. correctly.
54
60
  return numbro(bytes).format({
55
61
  output: 'byte',
56
62
  base: 'decimal',