@perses-dev/core 0.39.0 → 0.40.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 (119) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +6 -2
  2. package/dist/cjs/constants/dialog.js +3 -1
  3. package/dist/cjs/constants/index.js +11 -9
  4. package/dist/cjs/index.js +12 -10
  5. package/dist/cjs/model/calculations.js +61 -49
  6. package/dist/cjs/model/index.js +28 -26
  7. package/dist/cjs/model/legend.js +39 -19
  8. package/dist/cjs/model/resource.js +9 -0
  9. package/dist/cjs/model/time-series-queries.js +3 -1
  10. package/dist/cjs/model/time.js +147 -64
  11. package/dist/cjs/model/units/bytes.js +26 -20
  12. package/dist/cjs/model/units/constants.js +3 -1
  13. package/dist/cjs/model/units/decimal.js +20 -14
  14. package/dist/cjs/model/units/index.js +13 -11
  15. package/dist/cjs/model/units/percent.js +21 -15
  16. package/dist/cjs/model/units/time.js +68 -60
  17. package/dist/cjs/model/units/types.js +3 -1
  18. package/dist/cjs/model/units/units.js +67 -43
  19. package/dist/cjs/model/units/utils.js +13 -7
  20. package/dist/cjs/model/variables.js +16 -3
  21. package/dist/cjs/utils/event.js +3 -1
  22. package/dist/cjs/utils/fetch.js +12 -4
  23. package/dist/cjs/utils/index.js +17 -14
  24. package/dist/cjs/utils/is-empty-object.js +3 -1
  25. package/dist/cjs/utils/mathjs.js +3 -1
  26. package/dist/cjs/utils/memo.js +10 -6
  27. package/dist/cjs/utils/panel-refs.js +9 -3
  28. package/dist/cjs/utils/text.js +33 -21
  29. package/dist/cjs/utils/time-series-data.js +21 -11
  30. package/dist/cjs/utils/types.js +16 -0
  31. package/dist/constants/dashboard-defaults.js.map +1 -1
  32. package/dist/constants/dialog.js.map +1 -1
  33. package/dist/constants/index.js.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/model/calculations.d.ts +9 -8
  36. package/dist/model/calculations.d.ts.map +1 -1
  37. package/dist/model/calculations.js +46 -45
  38. package/dist/model/calculations.js.map +1 -1
  39. package/dist/model/datasource.d.ts +19 -3
  40. package/dist/model/datasource.d.ts.map +1 -1
  41. package/dist/model/datasource.js.map +1 -1
  42. package/dist/model/display.d.ts +1 -1
  43. package/dist/model/display.d.ts.map +1 -1
  44. package/dist/model/display.js.map +1 -1
  45. package/dist/model/index.js.map +1 -1
  46. package/dist/model/legend.d.ts +6 -6
  47. package/dist/model/legend.js +9 -9
  48. package/dist/model/legend.js.map +1 -1
  49. package/dist/model/panels.d.ts +5 -2
  50. package/dist/model/panels.d.ts.map +1 -1
  51. package/dist/model/panels.js.map +1 -1
  52. package/dist/model/resource.d.ts +3 -2
  53. package/dist/model/resource.d.ts.map +1 -1
  54. package/dist/model/resource.js +3 -1
  55. package/dist/model/resource.js.map +1 -1
  56. package/dist/model/thresholds.d.ts +2 -2
  57. package/dist/model/thresholds.d.ts.map +1 -1
  58. package/dist/model/thresholds.js.map +1 -1
  59. package/dist/model/time-series-queries.js.map +1 -1
  60. package/dist/model/time.d.ts +3 -0
  61. package/dist/model/time.d.ts.map +1 -1
  62. package/dist/model/time.js +115 -55
  63. package/dist/model/time.js.map +1 -1
  64. package/dist/model/units/bytes.d.ts +8 -8
  65. package/dist/model/units/bytes.d.ts.map +1 -1
  66. package/dist/model/units/bytes.js +16 -16
  67. package/dist/model/units/bytes.js.map +1 -1
  68. package/dist/model/units/constants.js.map +1 -1
  69. package/dist/model/units/decimal.d.ts +8 -8
  70. package/dist/model/units/decimal.d.ts.map +1 -1
  71. package/dist/model/units/decimal.js +12 -12
  72. package/dist/model/units/decimal.js.map +1 -1
  73. package/dist/model/units/index.js.map +1 -1
  74. package/dist/model/units/percent.d.ts +7 -7
  75. package/dist/model/units/percent.d.ts.map +1 -1
  76. package/dist/model/units/percent.js +12 -12
  77. package/dist/model/units/percent.js.map +1 -1
  78. package/dist/model/units/time.d.ts +15 -15
  79. package/dist/model/units/time.d.ts.map +1 -1
  80. package/dist/model/units/time.js +56 -56
  81. package/dist/model/units/time.js.map +1 -1
  82. package/dist/model/units/types.d.ts +14 -5
  83. package/dist/model/units/types.d.ts.map +1 -1
  84. package/dist/model/units/types.js.map +1 -1
  85. package/dist/model/units/units.d.ts +30 -30
  86. package/dist/model/units/units.d.ts.map +1 -1
  87. package/dist/model/units/units.js +31 -31
  88. package/dist/model/units/units.js.map +1 -1
  89. package/dist/model/units/utils.d.ts +2 -2
  90. package/dist/model/units/utils.d.ts.map +1 -1
  91. package/dist/model/units/utils.js +4 -4
  92. package/dist/model/units/utils.js.map +1 -1
  93. package/dist/model/variables.d.ts +25 -7
  94. package/dist/model/variables.d.ts.map +1 -1
  95. package/dist/model/variables.js +3 -0
  96. package/dist/model/variables.js.map +1 -1
  97. package/dist/test/setup-tests.js.map +1 -1
  98. package/dist/utils/event.js.map +1 -1
  99. package/dist/utils/fetch.js.map +1 -1
  100. package/dist/utils/index.d.ts +2 -1
  101. package/dist/utils/index.d.ts.map +1 -1
  102. package/dist/utils/index.js +2 -1
  103. package/dist/utils/index.js.map +1 -1
  104. package/dist/utils/is-empty-object.js.map +1 -1
  105. package/dist/utils/mathjs.js.map +1 -1
  106. package/dist/utils/memo.js +2 -2
  107. package/dist/utils/memo.js.map +1 -1
  108. package/dist/utils/panel-refs.js.map +1 -1
  109. package/dist/utils/text.d.ts +5 -5
  110. package/dist/utils/text.d.ts.map +1 -1
  111. package/dist/utils/text.js +17 -17
  112. package/dist/utils/text.js.map +1 -1
  113. package/dist/utils/time-series-data.js +6 -6
  114. package/dist/utils/time-series-data.js.map +1 -1
  115. package/dist/utils/types.d.ts +2 -0
  116. package/dist/utils/types.d.ts.map +1 -0
  117. package/dist/utils/types.js +15 -0
  118. package/dist/utils/types.js.map +1 -0
  119. package/package.json +5 -4
@@ -1,7 +1,7 @@
1
- import { BytesUnitOptions } from './bytes';
2
- import { DecimalUnitOptions } from './decimal';
3
- import { PercentUnitOptions } from './percent';
4
- import { TimeUnitOptions } from './time';
1
+ import { BytesFormatOptions as BytesFormatOptions } from './bytes';
2
+ import { DecimalFormatOptions as DecimalFormatOptions } from './decimal';
3
+ import { PercentFormatOptions as PercentFormatOptions } from './percent';
4
+ import { TimeFormatOptions as TimeFormatOptions } from './time';
5
5
  import { UnitGroup, UnitGroupConfig, UnitConfig } from './types';
6
6
  /**
7
7
  * Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.
@@ -12,36 +12,36 @@ import { UnitGroup, UnitGroupConfig, UnitConfig } from './types';
12
12
  */
13
13
  export declare const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>>;
14
14
  export declare const UNIT_CONFIG: {
15
- readonly Bytes: UnitConfig;
16
- readonly Decimal: UnitConfig;
17
- readonly Percent: UnitConfig;
18
- readonly PercentDecimal: UnitConfig;
15
+ readonly bytes: UnitConfig;
16
+ readonly decimal: UnitConfig;
17
+ readonly percent: UnitConfig;
18
+ readonly "percent-decimal": UnitConfig;
19
19
  readonly "%": UnitConfig;
20
- readonly Milliseconds: UnitConfig;
21
- readonly Seconds: UnitConfig;
22
- readonly Minutes: UnitConfig;
23
- readonly Hours: UnitConfig;
24
- readonly Days: UnitConfig;
25
- readonly Weeks: UnitConfig;
26
- readonly Months: UnitConfig;
27
- readonly Years: UnitConfig;
20
+ readonly milliseconds: UnitConfig;
21
+ readonly seconds: UnitConfig;
22
+ readonly minutes: UnitConfig;
23
+ readonly hours: UnitConfig;
24
+ readonly days: UnitConfig;
25
+ readonly weeks: UnitConfig;
26
+ readonly months: UnitConfig;
27
+ readonly years: UnitConfig;
28
28
  };
29
- export declare type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;
29
+ export declare type FormatOptions = TimeFormatOptions | PercentFormatOptions | DecimalFormatOptions | BytesFormatOptions;
30
30
  declare type HasDecimalPlaces<UnitOpt> = UnitOpt extends {
31
- decimal_places?: number;
31
+ decimalPlaces?: number;
32
32
  } ? UnitOpt : never;
33
- declare type HasAbbreviate<UnitOpt> = UnitOpt extends {
34
- abbreviate?: boolean;
33
+ declare type HasShortValues<UnitOpt> = UnitOpt extends {
34
+ shortValues?: boolean;
35
35
  } ? UnitOpt : never;
36
- export declare function formatValue(value: number, unitOptions?: UnitOptions): string;
37
- export declare function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig;
38
- export declare function getUnitGroup(unitOptions: UnitOptions): UnitGroup;
39
- export declare function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig;
40
- export declare function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions;
41
- export declare function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions;
42
- export declare function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions;
43
- export declare function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions;
44
- export declare function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions>;
45
- export declare function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions>;
36
+ export declare function formatValue(value: number, formatOptions?: FormatOptions): string;
37
+ export declare function getUnitConfig(formatOptions: FormatOptions): UnitConfig;
38
+ export declare function getUnitGroup(formatOptions: FormatOptions): UnitGroup;
39
+ export declare function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig;
40
+ export declare function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions;
41
+ export declare function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions;
42
+ export declare function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions;
43
+ export declare function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions;
44
+ export declare function isUnitWithDecimalPlaces(formatOptions: FormatOptions): formatOptions is HasDecimalPlaces<FormatOptions>;
45
+ export declare function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions>;
46
46
  export {};
47
47
  //# sourceMappingURL=units.d.ts.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IAAI,OAAO,SAAS;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAE3F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAuBhF;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,UAAU,CAEtE;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,CAEpE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,aAAa,GAAG,eAAe,CAGhF;AAGD,wBAAgB,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,iBAAiB,CAE3F;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,oBAAoB,CAEjG;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,oBAAoB,CAEjG;AAED,wBAAgB,WAAW,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,kBAAkB,CAE7F;AAED,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,aAAa,GAC3B,aAAa,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAIlD;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,cAAc,CAAC,aAAa,CAAC,CAIlH"}
@@ -32,55 +32,55 @@ export const UNIT_CONFIG = {
32
32
  ...DECIMAL_UNIT_CONFIG,
33
33
  ...BYTES_UNIT_CONFIG
34
34
  };
35
- export function formatValue(value, unitOptions) {
36
- if (unitOptions === undefined) {
35
+ export function formatValue(value, formatOptions) {
36
+ if (formatOptions === undefined) {
37
37
  return value.toString();
38
38
  }
39
- if (isBytesUnit(unitOptions)) {
40
- return formatBytes(value, unitOptions);
39
+ if (isBytesUnit(formatOptions)) {
40
+ return formatBytes(value, formatOptions);
41
41
  }
42
- if (isDecimalUnit(unitOptions)) {
43
- return formatDecimal(value, unitOptions);
42
+ if (isDecimalUnit(formatOptions)) {
43
+ return formatDecimal(value, formatOptions);
44
44
  }
45
- if (isPercentUnit(unitOptions)) {
46
- return formatPercent(value, unitOptions);
45
+ if (isPercentUnit(formatOptions)) {
46
+ return formatPercent(value, formatOptions);
47
47
  }
48
- if (isTimeUnit(unitOptions)) {
49
- return formatTime(value, unitOptions);
48
+ if (isTimeUnit(formatOptions)) {
49
+ return formatTime(value, formatOptions);
50
50
  }
51
- const exhaustive = unitOptions;
51
+ const exhaustive = formatOptions;
52
52
  throw new Error(`Unknown unit options ${exhaustive}`);
53
53
  }
54
- export function getUnitKindConfig(unitOptions) {
55
- return UNIT_CONFIG[unitOptions.kind];
54
+ export function getUnitConfig(formatOptions) {
55
+ return UNIT_CONFIG[formatOptions.unit];
56
56
  }
57
- export function getUnitGroup(unitOptions) {
58
- return getUnitKindConfig(unitOptions).group;
57
+ export function getUnitGroup(formatOptions) {
58
+ return getUnitConfig(formatOptions).group;
59
59
  }
60
- export function getUnitGroupConfig(unitOptions) {
61
- const unitConfig = getUnitKindConfig(unitOptions);
60
+ export function getUnitGroupConfig(formatOptions) {
61
+ const unitConfig = getUnitConfig(formatOptions);
62
62
  return UNIT_GROUP_CONFIG[unitConfig.group];
63
63
  }
64
64
  // Type guards
65
- export function isTimeUnit(unitOptions) {
66
- return getUnitGroup(unitOptions) === 'Time';
65
+ export function isTimeUnit(formatOptions) {
66
+ return getUnitGroup(formatOptions) === 'Time';
67
67
  }
68
- export function isPercentUnit(unitOptions) {
69
- return getUnitGroup(unitOptions) === 'Percent';
68
+ export function isPercentUnit(formatOptions) {
69
+ return getUnitGroup(formatOptions) === 'Percent';
70
70
  }
71
- export function isDecimalUnit(unitOptions) {
72
- return getUnitGroup(unitOptions) === 'Decimal';
71
+ export function isDecimalUnit(formatOptions) {
72
+ return getUnitGroup(formatOptions) === 'Decimal';
73
73
  }
74
- export function isBytesUnit(unitOptions) {
75
- return getUnitGroup(unitOptions) === 'Bytes';
74
+ export function isBytesUnit(formatOptions) {
75
+ return getUnitGroup(formatOptions) === 'Bytes';
76
76
  }
77
- export function isUnitWithDecimalPlaces(unitOptions) {
78
- const groupConfig = getUnitGroupConfig(unitOptions);
79
- return !!groupConfig.decimal_places;
77
+ export function isUnitWithDecimalPlaces(formatOptions) {
78
+ const groupConfig = getUnitGroupConfig(formatOptions);
79
+ return !!groupConfig.decimalPlaces;
80
80
  }
81
- export function isUnitWithAbbreviate(unitOptions) {
82
- const groupConfig = getUnitGroupConfig(unitOptions);
83
- return !!groupConfig.abbreviate;
81
+ export function isUnitWithShortValues(formatOptions) {
82
+ const groupConfig = getUnitGroupConfig(formatOptions);
83
+ return !!groupConfig.shortValues;
84
84
  }
85
85
 
86
86
  //# sourceMappingURL=units.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/units.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 { formatBytes, BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';\nimport { formatDecimal, DecimalUnitOptions, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from './decimal';\nimport { formatPercent, PercentUnitOptions, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from './percent';\nimport { formatTime, TimeUnitOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\n/**\n * Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.\n * Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.\n *\n * To format bytes, we also make use of the `numbro` package,\n * because it can handle adding units like KB, MB, GB, etc. correctly.\n */\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n} as const;\n\nexport type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimal_places?: number } ? UnitOpt : never;\ntype HasAbbreviate<UnitOpt> = UnitOpt extends { abbreviate?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, unitOptions?: UnitOptions): string {\n if (unitOptions === undefined) {\n return value.toString();\n }\n\n if (isBytesUnit(unitOptions)) {\n return formatBytes(value, unitOptions);\n }\n\n if (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n const exhaustive: never = unitOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig {\n return UNIT_CONFIG[unitOptions.kind];\n}\n\nexport function getUnitGroup(unitOptions: UnitOptions): UnitGroup {\n return getUnitKindConfig(unitOptions).group;\n}\n\nexport function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig {\n const unitConfig = getUnitKindConfig(unitOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group];\n}\n\n// Type guards\nexport function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions {\n return getUnitGroup(unitOptions) === 'Time';\n}\n\nexport function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions {\n return getUnitGroup(unitOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions {\n return getUnitGroup(unitOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions {\n return getUnitGroup(unitOptions) === 'Bytes';\n}\n\nexport function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.decimal_places;\n}\n\nexport function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.abbreviate;\n}\n"],"names":["formatBytes","BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","DECIMAL_UNIT_CONFIG","formatPercent","PERCENT_GROUP_CONFIG","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","unitOptions","undefined","toString","isBytesUnit","isDecimalUnit","isPercentUnit","isTimeUnit","exhaustive","Error","getUnitKindConfig","kind","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimal_places","isUnitWithAbbreviate","abbreviate"],"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,WAAW,EAAoBC,kBAAkB,EAAEC,iBAAiB,QAAQ,SAAS,CAAC;AAC/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C,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/units.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 { formatBytes, BytesFormatOptions as BytesFormatOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';\nimport {\n formatDecimal,\n DecimalFormatOptions as DecimalFormatOptions,\n DECIMAL_GROUP_CONFIG,\n DECIMAL_UNIT_CONFIG,\n} from './decimal';\nimport {\n formatPercent,\n PercentFormatOptions as PercentFormatOptions,\n PERCENT_GROUP_CONFIG,\n PERCENT_UNIT_CONFIG,\n} from './percent';\nimport { formatTime, TimeFormatOptions as TimeFormatOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\n/**\n * Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.\n * Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.\n *\n * To format bytes, we also make use of the `numbro` package,\n * because it can handle adding units like KB, MB, GB, etc. correctly.\n */\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n} as const;\n\nexport type FormatOptions = TimeFormatOptions | PercentFormatOptions | DecimalFormatOptions | BytesFormatOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimalPlaces?: number } ? UnitOpt : never;\ntype HasShortValues<UnitOpt> = UnitOpt extends { shortValues?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, formatOptions?: FormatOptions): string {\n if (formatOptions === undefined) {\n return value.toString();\n }\n\n if (isBytesUnit(formatOptions)) {\n return formatBytes(value, formatOptions);\n }\n\n if (isDecimalUnit(formatOptions)) {\n return formatDecimal(value, formatOptions);\n }\n\n if (isPercentUnit(formatOptions)) {\n return formatPercent(value, formatOptions);\n }\n\n if (isTimeUnit(formatOptions)) {\n return formatTime(value, formatOptions);\n }\n\n const exhaustive: never = formatOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitConfig(formatOptions: FormatOptions): UnitConfig {\n return UNIT_CONFIG[formatOptions.unit];\n}\n\nexport function getUnitGroup(formatOptions: FormatOptions): UnitGroup {\n return getUnitConfig(formatOptions).group;\n}\n\nexport function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig {\n const unitConfig = getUnitConfig(formatOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group];\n}\n\n// Type guards\nexport function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions {\n return getUnitGroup(formatOptions) === 'Time';\n}\n\nexport function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions {\n return getUnitGroup(formatOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions {\n return getUnitGroup(formatOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions {\n return getUnitGroup(formatOptions) === 'Bytes';\n}\n\nexport function isUnitWithDecimalPlaces(\n formatOptions: FormatOptions\n): formatOptions is HasDecimalPlaces<FormatOptions> {\n const groupConfig = getUnitGroupConfig(formatOptions);\n\n return !!groupConfig.decimalPlaces;\n}\n\nexport function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions> {\n const groupConfig = getUnitGroupConfig(formatOptions);\n\n return !!groupConfig.shortValues;\n}\n"],"names":["formatBytes","BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","DECIMAL_UNIT_CONFIG","formatPercent","PERCENT_GROUP_CONFIG","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","formatOptions","undefined","toString","isBytesUnit","isDecimalUnit","isPercentUnit","isTimeUnit","exhaustive","Error","getUnitConfig","unit","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimalPlaces","isUnitWithShortValues","shortValues"],"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,WAAW,EAA4CC,kBAAkB,EAAEC,iBAAiB,QAAQ,UAAU;AACvH,SACEC,aAAa,EAEbC,oBAAoB,EACpBC,mBAAmB,QACd,YAAY;AACnB,SACEC,aAAa,EAEbC,oBAAoB,EACpBC,mBAAmB,QACd,YAAY;AACnB,SAASC,UAAU,EAA0CC,iBAAiB,EAAEC,gBAAgB,QAAQ,SAAS;AAGjH;;;;;;CAMC,GAED,OAAO,MAAMC,oBAAkE;IAC7EC,MAAMH;IACNI,SAASP;IACTQ,SAASX;IACTY,OAAOf;AACT,EAAE;AACF,OAAO,MAAMgB,cAAc;IACzB,GAAGN,gBAAgB;IACnB,GAAGH,mBAAmB;IACtB,GAAGH,mBAAmB;IACtB,GAAGH,iBAAiB;AACtB,EAAW;AAOX,OAAO,SAASgB,YAAYC,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ean;
2
- export declare function hasDecimalPlaces(decimal_places?: number): boolean;
1
+ export declare function shouldShortenValues(shortValues?: boolean): boolean;
2
+ export declare function hasDecimalPlaces(decimalPlaces?: number): boolean;
3
3
  export declare function limitDecimalPlaces(num?: number): number | undefined;
4
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/model/units/utils.ts"],"names":[],"mappings":"AAaA,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,OAAO,WAEpD;AAED,wBAAgB,gBAAgB,CAAC,cAAc,CAAC,EAAE,MAAM,WAEvD;AAKD,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,sBAU9C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/model/units/utils.ts"],"names":[],"mappings":"AAaA,wBAAgB,mBAAmB,CAAC,WAAW,CAAC,EAAE,OAAO,WAExD;AAED,wBAAgB,gBAAgB,CAAC,aAAa,CAAC,EAAE,MAAM,WAEtD;AAKD,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,sBAU9C"}
@@ -10,11 +10,11 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export function shouldAbbreviate(abbreviate) {
14
- return abbreviate !== false;
13
+ export function shouldShortenValues(shortValues) {
14
+ return shortValues !== false;
15
15
  }
16
- export function hasDecimalPlaces(decimal_places) {
17
- return typeof decimal_places === 'number';
16
+ export function hasDecimalPlaces(decimalPlaces) {
17
+ return typeof decimalPlaces === 'number';
18
18
  }
19
19
  // Avoids maximumFractionDigits out-of-range error.
20
20
  // Allowed values are 0 to 20.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/utils.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 function shouldAbbreviate(abbreviate?: boolean) {\n return abbreviate !== false;\n}\n\nexport function hasDecimalPlaces(decimal_places?: number) {\n return typeof decimal_places === 'number';\n}\n\n// Avoids maximumFractionDigits out-of-range error.\n// Allowed values are 0 to 20.\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits\nexport function limitDecimalPlaces(num?: number) {\n if (!num) return num;\n\n if (num < 0) {\n num = 0;\n } else if (num > 20) {\n num = 20;\n }\n\n return num;\n}\n"],"names":["shouldAbbreviate","abbreviate","hasDecimalPlaces","decimal_places","limitDecimalPlaces","num"],"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,OAAO,SAASA,gBAAgB,CAACC,UAAoB,EAAE;IACrD,OAAOA,UAAU,KAAK,KAAK,CAAC;AAC9B,CAAC;AAED,OAAO,SAASC,gBAAgB,CAACC,cAAuB,EAAE;IACxD,OAAO,OAAOA,cAAc,KAAK,QAAQ,CAAC;AAC5C,CAAC;AAED,mDAAmD;AACnD,8BAA8B;AAC9B,wIAAwI;AACxI,OAAO,SAASC,kBAAkB,CAACC,GAAY,EAAE;IAC/C,IAAI,CAACA,GAAG,EAAE,OAAOA,GAAG,CAAC;IAErB,IAAIA,GAAG,GAAG,CAAC,EAAE;QACXA,GAAG,GAAG,CAAC,CAAC;IACV,OAAO,IAAIA,GAAG,GAAG,EAAE,EAAE;QACnBA,GAAG,GAAG,EAAE,CAAC;IACX,CAAC;IAED,OAAOA,GAAG,CAAC;AACb,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/utils.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 function shouldShortenValues(shortValues?: boolean) {\n return shortValues !== false;\n}\n\nexport function hasDecimalPlaces(decimalPlaces?: number) {\n return typeof decimalPlaces === 'number';\n}\n\n// Avoids maximumFractionDigits out-of-range error.\n// Allowed values are 0 to 20.\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits\nexport function limitDecimalPlaces(num?: number) {\n if (!num) return num;\n\n if (num < 0) {\n num = 0;\n } else if (num > 20) {\n num = 20;\n }\n\n return num;\n}\n"],"names":["shouldShortenValues","shortValues","hasDecimalPlaces","decimalPlaces","limitDecimalPlaces","num"],"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,OAAO,SAASA,oBAAoBC,WAAqB;IACvD,OAAOA,gBAAgB;AACzB;AAEA,OAAO,SAASC,iBAAiBC,aAAsB;IACrD,OAAO,OAAOA,kBAAkB;AAClC;AAEA,mDAAmD;AACnD,8BAA8B;AAC9B,wIAAwI;AACxI,OAAO,SAASC,mBAAmBC,GAAY;IAC7C,IAAI,CAACA,KAAK,OAAOA;IAEjB,IAAIA,MAAM,GAAG;QACXA,MAAM;IACR,OAAO,IAAIA,MAAM,IAAI;QACnBA,MAAM;IACR;IAEA,OAAOA;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { Definition, UnknownSpec } from './definitions';
2
2
  import { Display } from './display';
3
- import { ProjectMetadata } from './resource';
3
+ import { Metadata, ProjectMetadata } from './resource';
4
4
  export declare type VariableName = string;
5
5
  export declare type VariableValue = string | string[] | null;
6
6
  export interface VariableSpec {
@@ -14,19 +14,27 @@ export interface TextVariableDefinition extends Definition<TextVariableSpec> {
14
14
  }
15
15
  export interface TextVariableSpec extends VariableSpec {
16
16
  value: string;
17
+ constant?: boolean;
17
18
  }
18
19
  export interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {
19
20
  kind: 'ListVariable';
20
21
  }
21
22
  export interface ListVariableSpec<PluginSpec> extends VariableSpec {
22
- default_value?: VariableValue;
23
- allow_multiple?: boolean;
24
- allow_all_value?: boolean;
25
- custom_all_value?: string;
26
- capturing_regexp?: string;
23
+ defaultValue?: VariableValue;
24
+ allowMultiple?: boolean;
25
+ allowAllValue?: boolean;
26
+ customAllValue?: string;
27
+ capturingRegexp?: string;
27
28
  plugin: Definition<PluginSpec>;
28
29
  }
29
- export declare type VariableDefinition = TextVariableDefinition | ListVariableDefinition;
30
+ export interface BuiltinVariableDefinition extends Definition<BuiltinVariableSpec> {
31
+ kind: 'BuiltinVariable';
32
+ }
33
+ export interface BuiltinVariableSpec extends VariableSpec {
34
+ value: () => string;
35
+ source: string;
36
+ }
37
+ export declare type VariableDefinition = TextVariableDefinition | ListVariableDefinition | BuiltinVariableDefinition;
30
38
  /**
31
39
  * A variable that belongs to a project.
32
40
  */
@@ -35,5 +43,15 @@ export interface VariableResource {
35
43
  metadata: ProjectMetadata;
36
44
  spec: VariableDefinition;
37
45
  }
46
+ /**
47
+ * A global variable that doesn´t belong to a project.
48
+ */
49
+ export interface GlobalVariableResource {
50
+ kind: 'GlobalVariable';
51
+ metadata: Metadata;
52
+ spec: VariableDefinition;
53
+ }
54
+ export declare type Variable = VariableResource | GlobalVariableResource;
55
+ export declare function getVariableProject(variable: Variable): string | undefined;
38
56
  export declare const DEFAULT_ALL_VALUE: "$__all";
39
57
  //# sourceMappingURL=variables.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/model/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,oBAAY,aAAa,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;AAErD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,GAAG;QAClB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;CACH;AAED,MAAM,WAAW,sBAAuB,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IAC1E,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB,CAAC,UAAU,GAAG,WAAW,CAAE,SAAQ,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAChH,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB,CAAC,UAAU,CAAE,SAAQ,YAAY;IAChE,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE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Aa,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,yBAA0B,SAAQ,UAAU,CAAC,mBAAmB,CAAC;IAChF,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oBAAY,kBAAkB,GAAG,sBAAsB,GAAG,sBAAsB,GAAG,yBAAyB,CAAC;AAE7G;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED,oBAAY,QAAQ,GAAG,gBAAgB,GAAG,sBAAsB,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,sBAEpD;AAED,eAAO,MAAM,iBAAiB,UAAoB,CAAC"}
@@ -10,6 +10,9 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ export function getVariableProject(variable) {
14
+ return 'project' in variable.metadata ? variable.metadata.project : undefined;
15
+ }
13
16
  export const DEFAULT_ALL_VALUE = '$__all';
14
17
 
15
18
  //# sourceMappingURL=variables.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/variables.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 { Display } from './display';\nimport { ProjectMetadata } from './resource';\n\nexport type VariableName = string;\n\nexport type VariableValue = string | string[] | null;\n\nexport interface VariableSpec {\n name: VariableName;\n display?: Display & {\n hidden?: boolean;\n };\n}\n\nexport interface TextVariableDefinition extends Definition<TextVariableSpec> {\n kind: 'TextVariable';\n}\n\nexport interface TextVariableSpec extends VariableSpec {\n value: string;\n}\n\nexport interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {\n kind: 'ListVariable';\n}\n\nexport interface ListVariableSpec<PluginSpec> extends VariableSpec {\n default_value?: VariableValue;\n allow_multiple?: boolean;\n allow_all_value?: boolean;\n custom_all_value?: string;\n capturing_regexp?: string;\n plugin: Definition<PluginSpec>;\n}\n\nexport type VariableDefinition = TextVariableDefinition | ListVariableDefinition;\n\n/**\n * A variable that belongs to a project.\n */\nexport interface VariableResource {\n kind: 'Variable';\n metadata: ProjectMetadata;\n spec: VariableDefinition;\n}\n\nexport const DEFAULT_ALL_VALUE = '$__all' as const;\n"],"names":["DEFAULT_ALL_VALUE"],"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;AAiDjC,OAAO,MAAMA,iBAAiB,GAAG,QAAQ,AAAS,CAAC"}
1
+ {"version":3,"sources":["../../src/model/variables.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 { Display } from './display';\nimport { Metadata, ProjectMetadata } from './resource';\n\nexport type VariableName = string;\n\nexport type VariableValue = string | string[] | null;\n\nexport interface VariableSpec {\n name: VariableName;\n display?: Display & {\n hidden?: boolean;\n };\n}\n\nexport interface TextVariableDefinition extends Definition<TextVariableSpec> {\n kind: 'TextVariable';\n}\n\nexport interface TextVariableSpec extends VariableSpec {\n value: string;\n constant?: boolean;\n}\n\nexport interface ListVariableDefinition<PluginSpec = UnknownSpec> extends Definition<ListVariableSpec<PluginSpec>> {\n kind: 'ListVariable';\n}\n\nexport interface ListVariableSpec<PluginSpec> extends VariableSpec {\n defaultValue?: VariableValue;\n allowMultiple?: boolean;\n allowAllValue?: boolean;\n customAllValue?: string;\n capturingRegexp?: string;\n plugin: Definition<PluginSpec>;\n}\n\nexport interface BuiltinVariableDefinition extends Definition<BuiltinVariableSpec> {\n kind: 'BuiltinVariable';\n}\n\nexport interface BuiltinVariableSpec extends VariableSpec {\n value: () => string;\n source: string;\n}\n\nexport type VariableDefinition = TextVariableDefinition | ListVariableDefinition | BuiltinVariableDefinition;\n\n/**\n * A variable that belongs to a project.\n */\nexport interface VariableResource {\n kind: 'Variable';\n metadata: ProjectMetadata;\n spec: VariableDefinition;\n}\n\n/**\n * A global variable that doesn´t belong to a project.\n */\nexport interface GlobalVariableResource {\n kind: 'GlobalVariable';\n metadata: Metadata;\n spec: VariableDefinition;\n}\n\nexport type Variable = VariableResource | GlobalVariableResource;\n\nexport function getVariableProject(variable: Variable) {\n return 'project' in variable.metadata ? variable.metadata.project : undefined;\n}\n\nexport const DEFAULT_ALL_VALUE = '$__all' as const;\n"],"names":["getVariableProject","variable","metadata","project","undefined","DEFAULT_ALL_VALUE"],"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;AAsEjC,OAAO,SAASA,mBAAmBC,QAAkB;IACnD,OAAO,aAAaA,SAASC,WAAWD,SAASC,SAASC,UAAUC;AACtE;AAEA,OAAO,MAAMC,oBAAoB,SAAkB"}
@@ -1 +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"}
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,0CAA0C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/event.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 { useRef, useLayoutEffect, useCallback } from 'react';\n\n/**\n * A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.\n *\n * Typically useful for getting a stable reference to an \"event\" function (i.e. one that isn't called during render\n * but is called later in a useEffect or event handler) that accesses state or props.\n */\nexport function useEvent<T extends unknown[], U>(handler: (...args: T) => U): (...args: T) => U {\n const handlerRef = useRef(handler);\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback((...args) => handlerRef.current(...args), []);\n}\n"],"names":["useRef","useLayoutEffect","useCallback","useEvent","handler","handlerRef","current","args"],"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,MAAM,EAAEC,eAAe,EAAEC,WAAW,QAAQ,OAAO,CAAC;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,QAAQ,CAAyBC,OAA0B,EAAqB;IAC9F,MAAMC,UAAU,GAAGL,MAAM,CAACI,OAAO,CAAC,AAAC;IACnCH,eAAe,CAAC,IAAM;QACpBI,UAAU,CAACC,OAAO,GAAGF,OAAO,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,OAAOF,WAAW,CAAC,CAAIK,GAAAA,IAAI,GAAKF,UAAU,CAACC,OAAO,IAAIC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/event.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 { useRef, useLayoutEffect, useCallback } from 'react';\n\n/**\n * A (temporary) userland implementation of `useEvent` from this React RFC: https://github.com/reactjs/rfcs/pull/220.\n *\n * Typically useful for getting a stable reference to an \"event\" function (i.e. one that isn't called during render\n * but is called later in a useEffect or event handler) that accesses state or props.\n */\nexport function useEvent<T extends unknown[], U>(handler: (...args: T) => U): (...args: T) => U {\n const handlerRef = useRef(handler);\n useLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback((...args) => handlerRef.current(...args), []);\n}\n"],"names":["useRef","useLayoutEffect","useCallback","useEvent","handler","handlerRef","current","args"],"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,MAAM,EAAEC,eAAe,EAAEC,WAAW,QAAQ,QAAQ;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,SAAiCC,OAA0B;IACzE,MAAMC,aAAaL,OAAOI;IAC1BH,gBAAgB;QACdI,WAAWC,UAAUF;IACvB;IAEA,OAAOF,YAAY,CAAC,GAAGK,OAASF,WAAWC,WAAWC,OAAO,EAAE;AACjE"}
@@ -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` 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"}
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,MAAM,GAAGC,IAAqC;IAClE,MAAMC,WAAW,MAAMC,OAAOH,SAASC;IACvC,IAAIC,SAASE,OAAO,OAAO;QACzB,MAAMC,OAAO,MAAMH,SAASG;QAC5B,IAAIA,KAAKC,OAAO;YACd,MAAM,IAAIC,kBAAkBF,KAAKC;QACnC;QACA,IAAID,KAAKG,SAAS;YAChB,MAAM,IAAID,kBAAkBF,KAAKG;QACnC;QACA,MAAM,IAAIC,WAAWP;IACvB;IACA,OAAOA;AACT;AAEA;;;;CAIC,GACD,OAAO,eAAeQ,UAAa,GAAGT,IAAqC;IACzE,MAAMC,WAAW,MAAMF,SAASC;IAChC,MAAMI,OAAU,MAAMH,SAASG;IAC/B,OAAOA;AACT;AAEA;;CAEC,GACD,OAAO,MAAMI,mBAAmBE;IAC9BC,YAAYV,QAA4B,CAAE;QACxC,KAAK,CAAC,CAAC,EAAEA,SAASW,OAAO,CAAC,EAAEX,SAASY,WAAW,CAAC;QACjDC,OAAOC,eAAe,IAAI,EAAEP,WAAWQ;IACzC;AACF;AAEA;;CAEC,GACD,OAAO,MAAMV,0BAA0BI;IACrCC,YAAYJ,OAAe,CAAE;QAC3B,KAAK,CAACA;QACNO,OAAOC,eAAe,IAAI,EAAET,kBAAkBU;IAChD;AACF"}
@@ -3,6 +3,7 @@ export * from './fetch';
3
3
  export * from './is-empty-object';
4
4
  export * from './memo';
5
5
  export * from './panel-refs';
6
- export * from './time-series-data';
7
6
  export * from './text';
7
+ export * from './time-series-data';
8
+ export * from './types';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -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,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,QAAQ,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,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
@@ -15,7 +15,8 @@ export * from './fetch';
15
15
  export * from './is-empty-object';
16
16
  export * from './memo';
17
17
  export * from './panel-refs';
18
- export * from './time-series-data';
19
18
  export * from './text';
19
+ export * from './time-series-data';
20
+ export * from './types';
20
21
 
21
22
  //# sourceMappingURL=index.js.map
@@ -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 './is-empty-object';\nexport * from './memo';\nexport * from './panel-refs';\nexport * from './time-series-data';\nexport * from './text';\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;AACnC,cAAc,QAAQ,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 './text';\nexport * from './time-series-data';\nexport * from './types';\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,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,oBAAoB;AAClC,cAAc,SAAS;AACvB,cAAc,eAAe;AAC7B,cAAc,SAAS;AACvB,cAAc,qBAAqB;AACnC,cAAc,UAAU"}
@@ -1 +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"}
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,cAAcC,GAAW;IACvC,OAAOC,OAAOC,oBAAoBF,KAAKG,WAAW;AACpD"}
@@ -1 +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"}
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,SAAS;AAEjD,uHAAuH;AACvH,MAAM,EAAEC,IAAG,EAAE,GAAGD,OAAO;IAAED;AAAgB;AACzC,SAASE,GAAG,GAAG"}
@@ -20,8 +20,8 @@ import isEqual from 'lodash/isEqual';
20
20
  const ref = useRef();
21
21
  let areEqual = true;
22
22
  for(let i = 0; i < deps.length; i++){
23
- var ref1;
24
- if (((ref1 = ref.current) === null || ref1 === void 0 ? void 0 : ref1.deps[i]) !== deps[i]) {
23
+ var _ref_current;
24
+ if (((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.deps[i]) !== deps[i]) {
25
25
  areEqual = false;
26
26
  break;
27
27
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/memo.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 { useRef, DependencyList } from 'react';\nimport isEqual from 'lodash/isEqual';\n\ntype MemoRef<T> = {\n value: T;\n deps: DependencyList;\n};\n\n/**\n * Like React's useMemo, but guarantees the value will only be recalulated if\n * a dependency changes. Uses strict equality (===) for comparison. (React's\n * useMemo does not offer this guarantee, it's only a performance optimization).\n */\nexport function useMemoized<T>(factory: () => T, deps: DependencyList) {\n const ref = useRef<MemoRef<T>>();\n\n let areEqual = true;\n for (let i = 0; i < deps.length; i++) {\n if (ref.current?.deps[i] !== deps[i]) {\n areEqual = false;\n break;\n }\n }\n\n if (ref.current === undefined || areEqual === false) {\n ref.current = { value: factory(), deps: deps };\n }\n\n return ref.current.value;\n}\n\n/**\n * Like React's useMemo, except it does a deep equality comparison with lodash's\n * isEqual on the dependency list.\n */\nexport function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {\n ref.current = { value: factory(), deps };\n }\n return ref.current.value;\n}\n"],"names":["useRef","isEqual","useMemoized","factory","deps","ref","areEqual","i","length","current","undefined","value","useDeepMemo"],"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,MAAM,QAAwB,OAAO,CAAC;AAC/C,OAAOC,OAAO,MAAM,gBAAgB,CAAC;AAOrC;;;;CAIC,GACD,OAAO,SAASC,WAAW,CAAIC,OAAgB,EAAEC,IAAoB,EAAE;IACrE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IAEjC,IAAIM,QAAQ,GAAG,IAAI,AAAC;IACpB,IAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,CAAE;YAChCF,IAAW;QAAf,IAAIA,CAAAA,CAAAA,IAAW,GAAXA,GAAG,CAACI,OAAO,cAAXJ,IAAW,WAAM,GAAjBA,KAAAA,CAAiB,GAAjBA,IAAW,CAAED,IAAI,CAACG,CAAC,CAAC,MAAKH,IAAI,CAACG,CAAC,CAAC,EAAE;YACpCD,QAAQ,GAAG,KAAK,CAAC;YACjB,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAID,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIJ,QAAQ,KAAK,KAAK,EAAE;QACnDD,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI,EAAEA,IAAI;SAAE,CAAC;IACjD,CAAC;IAED,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,WAAW,CAAIT,OAAgB,EAAEC,IAAoB,EAAK;IACxE,MAAMC,GAAG,GAAGL,MAAM,EAAc,AAAC;IACjC,IAAIK,GAAG,CAACI,OAAO,KAAKC,SAAS,IAAIT,OAAO,CAACG,IAAI,EAAEC,GAAG,CAACI,OAAO,CAACL,IAAI,CAAC,KAAK,KAAK,EAAE;QAC1EC,GAAG,CAACI,OAAO,GAAG;YAAEE,KAAK,EAAER,OAAO,EAAE;YAAEC,IAAI;SAAE,CAAC;IAC3C,CAAC;IACD,OAAOC,GAAG,CAACI,OAAO,CAACE,KAAK,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/memo.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 { useRef, DependencyList } from 'react';\nimport isEqual from 'lodash/isEqual';\n\ntype MemoRef<T> = {\n value: T;\n deps: DependencyList;\n};\n\n/**\n * Like React's useMemo, but guarantees the value will only be recalulated if\n * a dependency changes. Uses strict equality (===) for comparison. (React's\n * useMemo does not offer this guarantee, it's only a performance optimization).\n */\nexport function useMemoized<T>(factory: () => T, deps: DependencyList) {\n const ref = useRef<MemoRef<T>>();\n\n let areEqual = true;\n for (let i = 0; i < deps.length; i++) {\n if (ref.current?.deps[i] !== deps[i]) {\n areEqual = false;\n break;\n }\n }\n\n if (ref.current === undefined || areEqual === false) {\n ref.current = { value: factory(), deps: deps };\n }\n\n return ref.current.value;\n}\n\n/**\n * Like React's useMemo, except it does a deep equality comparison with lodash's\n * isEqual on the dependency list.\n */\nexport function useDeepMemo<T>(factory: () => T, deps: DependencyList): T {\n const ref = useRef<MemoRef<T>>();\n if (ref.current === undefined || isEqual(deps, ref.current.deps) === false) {\n ref.current = { value: factory(), deps };\n }\n return ref.current.value;\n}\n"],"names":["useRef","isEqual","useMemoized","factory","deps","ref","areEqual","i","length","current","undefined","value","useDeepMemo"],"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,MAAM,QAAwB,QAAQ;AAC/C,OAAOC,aAAa,iBAAiB;AAOrC;;;;CAIC,GACD,OAAO,SAASC,YAAeC,OAAgB,EAAEC,IAAoB;IACnE,MAAMC,MAAML;IAEZ,IAAIM,WAAW;IACf,IAAK,IAAIC,IAAI,GAAGA,IAAIH,KAAKI,QAAQD,IAAK;YAChCF;QAAJ,IAAIA,CAAAA,CAAAA,eAAAA,IAAII,qBAAJJ,0BAAAA,KAAAA,IAAAA,aAAaD,IAAI,CAACG,EAAE,MAAKH,IAAI,CAACG,EAAE,EAAE;YACpCD,WAAW;YACX;QACF;IACF;IAEA,IAAID,IAAII,YAAYC,aAAaJ,aAAa,OAAO;QACnDD,IAAII,UAAU;YAAEE,OAAOR;YAAWC,MAAMA;QAAK;IAC/C;IAEA,OAAOC,IAAII,QAAQE;AACrB;AAEA;;;CAGC,GACD,OAAO,SAASC,YAAeT,OAAgB,EAAEC,IAAoB;IACnE,MAAMC,MAAML;IACZ,IAAIK,IAAII,YAAYC,aAAaT,QAAQG,MAAMC,IAAII,QAAQL,UAAU,OAAO;QAC1EC,IAAII,UAAU;YAAEE,OAAOR;YAAWC;QAAK;IACzC;IACA,OAAOC,IAAII,QAAQE;AACrB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/panel-refs.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 { DashboardSpec, PanelRef } from '../model';\n\n/**\n * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to\n * a PanelDefinition.\n */\nexport function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef) {\n const panelsKey = getPanelKeyFromRef(panelRef);\n const panelDefinition = spec.panels[panelsKey];\n if (panelDefinition === undefined) {\n throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);\n }\n return panelDefinition;\n}\n\n// Currently, panel refs are prefixed with `#/spec/panels/`. If that format changes, we'll definitely need to update\n// the code in here relying on it being that format.\nconst REF_PREFIX_LENGTH = 14;\n\n/**\n * Gets the unique key for a panel from a PanelRef.\n */\nexport function getPanelKeyFromRef(panelRef: PanelRef) {\n return panelRef.$ref.substring(REF_PREFIX_LENGTH);\n}\n\n/**\n * Creates a PanelRef for a panel with the given key.\n */\nexport function createPanelRef(panelKey: string): PanelRef {\n return { $ref: `#/spec/panels/${panelKey}` };\n}\n"],"names":["resolvePanelRef","spec","panelRef","panelsKey","getPanelKeyFromRef","panelDefinition","panels","undefined","Error","$ref","REF_PREFIX_LENGTH","substring","createPanelRef","panelKey"],"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;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAmB,EAAEC,QAAkB,EAAE;IACvE,MAAMC,SAAS,GAAGC,kBAAkB,CAACF,QAAQ,CAAC,AAAC;IAC/C,MAAMG,eAAe,GAAGJ,IAAI,CAACK,MAAM,CAACH,SAAS,CAAC,AAAC;IAC/C,IAAIE,eAAe,KAAKE,SAAS,EAAE;QACjC,MAAM,IAAIC,KAAK,CAAC,CAAC,mCAAmC,EAAEN,QAAQ,CAACO,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAOJ,eAAe,CAAC;AACzB,CAAC;AAED,oHAAoH;AACpH,oDAAoD;AACpD,MAAMK,iBAAiB,GAAG,EAAE,AAAC;AAE7B;;CAEC,GACD,OAAO,SAASN,kBAAkB,CAACF,QAAkB,EAAE;IACrD,OAAOA,QAAQ,CAACO,IAAI,CAACE,SAAS,CAACD,iBAAiB,CAAC,CAAC;AACpD,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,cAAc,CAACC,QAAgB,EAAY;IACzD,OAAO;QAAEJ,IAAI,EAAE,CAAC,cAAc,EAAEI,QAAQ,CAAC,CAAC;KAAE,CAAC;AAC/C,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/panel-refs.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 { DashboardSpec, PanelRef } from '../model';\n\n/**\n * Resolve a PanelRef (JSON reference) against the provided DashboardSpec to\n * a PanelDefinition.\n */\nexport function resolvePanelRef(spec: DashboardSpec, panelRef: PanelRef) {\n const panelsKey = getPanelKeyFromRef(panelRef);\n const panelDefinition = spec.panels[panelsKey];\n if (panelDefinition === undefined) {\n throw new Error(`Could not resolve panels reference ${panelRef.$ref}`);\n }\n return panelDefinition;\n}\n\n// Currently, panel refs are prefixed with `#/spec/panels/`. If that format changes, we'll definitely need to update\n// the code in here relying on it being that format.\nconst REF_PREFIX_LENGTH = 14;\n\n/**\n * Gets the unique key for a panel from a PanelRef.\n */\nexport function getPanelKeyFromRef(panelRef: PanelRef) {\n return panelRef.$ref.substring(REF_PREFIX_LENGTH);\n}\n\n/**\n * Creates a PanelRef for a panel with the given key.\n */\nexport function createPanelRef(panelKey: string): PanelRef {\n return { $ref: `#/spec/panels/${panelKey}` };\n}\n"],"names":["resolvePanelRef","spec","panelRef","panelsKey","getPanelKeyFromRef","panelDefinition","panels","undefined","Error","$ref","REF_PREFIX_LENGTH","substring","createPanelRef","panelKey"],"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;;;CAGC,GACD,OAAO,SAASA,gBAAgBC,IAAmB,EAAEC,QAAkB;IACrE,MAAMC,YAAYC,mBAAmBF;IACrC,MAAMG,kBAAkBJ,KAAKK,MAAM,CAACH,UAAU;IAC9C,IAAIE,oBAAoBE,WAAW;QACjC,MAAM,IAAIC,MAAM,CAAC,mCAAmC,EAAEN,SAASO,KAAK,CAAC;IACvE;IACA,OAAOJ;AACT;AAEA,oHAAoH;AACpH,oDAAoD;AACpD,MAAMK,oBAAoB;AAE1B;;CAEC,GACD,OAAO,SAASN,mBAAmBF,QAAkB;IACnD,OAAOA,SAASO,KAAKE,UAAUD;AACjC;AAEA;;CAEC,GACD,OAAO,SAASE,eAAeC,QAAgB;IAC7C,OAAO;QAAEJ,MAAM,CAAC,cAAc,EAAEI,SAAS,CAAC;IAAC;AAC7C"}
@@ -1,4 +1,4 @@
1
- import { Datasource, DashboardResource, VariableResource } from '../model';
1
+ import { DashboardResource, Variable, Datasource } from '../model';
2
2
  /**
3
3
  * If the dashboard has a display name, return the dashboard display name
4
4
  * Else, only return the dashboard name
@@ -10,11 +10,11 @@ export declare function getDashboardDisplayName(dashboard: DashboardResource): s
10
10
  * Else, only return the variable name
11
11
  * @param variable Project or Global variable
12
12
  */
13
- export declare function getVariableDisplayName(variable: VariableResource): string;
13
+ export declare function getVariableDisplayName(variable: Variable): string;
14
14
  /**
15
15
  * If the variable has a display name, return the datasource display name
16
16
  * Else, only return the datasource name
17
- * @param variable Project or Global datasource
17
+ * @param datasource Project or Global datasource
18
18
  */
19
19
  export declare function getDatasourceDisplayName(datasource: Datasource): string;
20
20
  /**
@@ -28,11 +28,11 @@ export declare function getDashboardExtendedDisplayName(dashboard: DashboardReso
28
28
  * Else, only return the variable name
29
29
  * @param variable Project or Global variable
30
30
  */
31
- export declare function getVariableExtendedDisplayName(variable: VariableResource): string;
31
+ export declare function getVariableExtendedDisplayName(variable: Variable): string;
32
32
  /**
33
33
  * If the datasource has a display name, return the datasource display name and the datasource name
34
34
  * Else, only return the datasource name
35
- * @param variable Project or Global datasource
35
+ * @param datasource Project or Global datasource
36
36
  */
37
37
  export declare function getDatasourceExtendedDisplayName(datasource: Datasource): string;
38
38
  //# sourceMappingURL=text.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,UAEnE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,UAEhE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,UAAU,UAE9D;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,iBAAiB,UAK3E;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB,UAKxE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,UAAU,UAKtE"}
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,UAEnE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,UAExD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,UAAU,UAE9D;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,iBAAiB,UAK3E;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,QAAQ,UAKhE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,UAAU,UAKtE"}