@perses-dev/core 0.0.0-snapshot-panel-extra-content-2-2767e21 → 0.0.0-snapshot-scatter-chart-embed-8efdfab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants/dashboard-defaults.js +6 -2
- package/dist/cjs/constants/dialog.js +3 -1
- package/dist/cjs/constants/index.js +11 -9
- package/dist/cjs/index.js +12 -10
- package/dist/cjs/model/calculations.js +61 -51
- package/dist/cjs/model/http-proxy.js +16 -0
- package/dist/cjs/model/index.js +34 -26
- package/dist/cjs/model/kind.js +38 -0
- package/dist/cjs/model/legend.js +39 -19
- package/dist/cjs/model/resource.js +9 -0
- package/dist/cjs/model/rolebindings.js +16 -0
- package/dist/cjs/model/roles.js +59 -0
- package/dist/cjs/model/secrets.js +16 -0
- package/dist/cjs/model/time-series-queries.js +3 -1
- package/dist/cjs/model/time.js +147 -64
- package/dist/cjs/model/trace-data.js +16 -0
- package/dist/cjs/model/units/bytes.js +37 -25
- package/dist/cjs/model/units/constants.js +3 -1
- package/dist/cjs/model/units/decimal.js +22 -16
- package/dist/cjs/model/units/index.js +13 -11
- package/dist/cjs/model/units/percent.js +26 -19
- package/dist/cjs/model/units/throughput.js +113 -0
- package/dist/cjs/model/units/time.js +99 -38
- package/dist/cjs/model/units/types.js +5 -2
- package/dist/cjs/model/units/units.js +81 -45
- package/dist/cjs/model/units/utils.js +13 -7
- package/dist/cjs/model/variables.js +16 -3
- package/dist/cjs/utils/event.js +3 -1
- package/dist/cjs/utils/fetch.js +32 -7
- package/dist/cjs/utils/index.js +17 -14
- package/dist/cjs/utils/is-empty-object.js +3 -1
- package/dist/cjs/utils/mathjs.js +3 -1
- package/dist/cjs/utils/memo.js +10 -6
- package/dist/cjs/utils/panel-refs.js +9 -3
- package/dist/cjs/utils/text.js +39 -14
- package/dist/cjs/utils/time-series-data.js +21 -11
- package/dist/cjs/utils/types.js +16 -0
- package/dist/constants/dashboard-defaults.js.map +1 -1
- package/dist/constants/dialog.js.map +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/calculations.d.ts +9 -9
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +46 -46
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +11 -4
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/display.d.ts +1 -1
- package/dist/model/display.d.ts.map +1 -1
- package/dist/model/display.js.map +1 -1
- package/dist/model/http-proxy.d.ts +16 -0
- package/dist/model/http-proxy.d.ts.map +1 -0
- package/dist/model/http-proxy.js +15 -0
- package/dist/model/http-proxy.js.map +1 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +6 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/kind.d.ts +3 -0
- package/dist/model/kind.d.ts.map +1 -0
- package/dist/model/kind.js +30 -0
- package/dist/model/kind.js.map +1 -0
- package/dist/model/legend.d.ts +6 -6
- package/dist/model/legend.js +9 -9
- package/dist/model/legend.js.map +1 -1
- package/dist/model/panels.d.ts +5 -2
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/query.d.ts +15 -2
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js.map +1 -1
- package/dist/model/resource.d.ts +3 -2
- package/dist/model/resource.d.ts.map +1 -1
- package/dist/model/resource.js +3 -1
- package/dist/model/resource.js.map +1 -1
- package/dist/model/rolebindings.d.ts +27 -0
- package/dist/model/rolebindings.d.ts.map +1 -0
- package/dist/model/rolebindings.js +15 -0
- package/dist/model/rolebindings.js.map +1 -0
- package/dist/model/roles.d.ts +32 -0
- package/dist/model/roles.d.ts.map +1 -0
- package/dist/model/roles.js +40 -0
- package/dist/model/roles.js.map +1 -0
- package/dist/model/secrets.d.ts +44 -0
- package/dist/model/secrets.d.ts.map +1 -0
- package/dist/model/secrets.js +15 -0
- package/dist/model/secrets.js.map +1 -0
- package/dist/model/thresholds.d.ts +2 -2
- package/dist/model/thresholds.d.ts.map +1 -1
- package/dist/model/thresholds.js.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/time.d.ts +3 -0
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +115 -55
- package/dist/model/time.js.map +1 -1
- package/dist/model/trace-data.d.ts +20 -0
- package/dist/model/trace-data.d.ts.map +1 -0
- package/dist/model/trace-data.js +15 -0
- package/dist/model/trace-data.js.map +1 -0
- package/dist/model/units/bytes.d.ts +8 -8
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +27 -21
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +8 -8
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +14 -14
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/index.js.map +1 -1
- package/dist/model/units/percent.d.ts +7 -7
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +17 -16
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/throughput.d.ts +13 -0
- package/dist/model/units/throughput.d.ts.map +1 -0
- package/dist/model/units/throughput.js +94 -0
- package/dist/model/units/throughput.js.map +1 -0
- package/dist/model/units/time.d.ts +15 -15
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +87 -34
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +15 -6
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js +2 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +49 -30
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +52 -37
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts +2 -2
- package/dist/model/units/utils.d.ts.map +1 -1
- package/dist/model/units/utils.js +4 -4
- package/dist/model/units/utils.js.map +1 -1
- package/dist/model/variables.d.ts +26 -7
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +3 -0
- package/dist/model/variables.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/event.js.map +1 -1
- package/dist/utils/fetch.d.ts +3 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +21 -4
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-empty-object.js.map +1 -1
- package/dist/utils/mathjs.js.map +1 -1
- package/dist/utils/memo.js +2 -2
- package/dist/utils/memo.js.map +1 -1
- package/dist/utils/panel-refs.js.map +1 -1
- package/dist/utils/text.d.ts +15 -3
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +29 -10
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/time-series-data.d.ts +1 -1
- package/dist/utils/time-series-data.d.ts.map +1 -1
- package/dist/utils/time-series-data.js +7 -7
- package/dist/utils/time-series-data.js.map +1 -1
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +15 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +5 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AbsoluteTimeRange, DurationString } from '../time';
|
|
2
|
+
import { FormatOptions } from './units';
|
|
3
|
+
export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes", "Throughput"];
|
|
3
4
|
export declare type UnitGroup = (typeof UNIT_GROUPS)[number];
|
|
4
5
|
/**
|
|
5
6
|
* Configuration for rendering units that are part of a group.
|
|
@@ -12,11 +13,11 @@ export declare type UnitGroupConfig = {
|
|
|
12
13
|
/**
|
|
13
14
|
* When true, the unit group supports setting decimal places.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
decimalPlaces?: boolean;
|
|
16
17
|
/**
|
|
17
|
-
* When true, the unit group supports enabling
|
|
18
|
+
* When true, the unit group supports enabling shortValues.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
shortValues?: boolean;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Configuration for rendering a specific unit.
|
|
@@ -41,7 +42,15 @@ export declare type UnitConfig = {
|
|
|
41
42
|
*/
|
|
42
43
|
export interface UnitTestCase {
|
|
43
44
|
value: number;
|
|
44
|
-
|
|
45
|
+
format: FormatOptions;
|
|
45
46
|
expected: string;
|
|
46
47
|
}
|
|
48
|
+
export interface IntervalTestCase {
|
|
49
|
+
timeRange: AbsoluteTimeRange;
|
|
50
|
+
expected: Duration;
|
|
51
|
+
}
|
|
52
|
+
export interface FormatTestCase {
|
|
53
|
+
duration: Duration;
|
|
54
|
+
expected: DurationString;
|
|
55
|
+
}
|
|
47
56
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,WAAW,gEAAiE,CAAC;AAC1F,oBAAY,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/types.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// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/types.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// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport { AbsoluteTimeRange, DurationString } from '../time';\nimport { FormatOptions } from './units';\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes', 'Throughput'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimalPlaces?: boolean;\n /**\n * When true, the unit group supports enabling shortValues.\n */\n shortValues?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n\n/**\n * Used in the tests for each type of unit.\n */\nexport interface UnitTestCase {\n value: number;\n format: FormatOptions;\n expected: string;\n}\n\nexport interface IntervalTestCase {\n timeRange: AbsoluteTimeRange;\n expected: Duration;\n}\n\nexport interface FormatTestCase {\n duration: Duration;\n expected: DurationString;\n}\n"],"names":["UNIT_GROUPS"],"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,6EAA6E;AAC7E,SAAS;AAKT,OAAO,MAAMA,cAAc;IAAC;IAAQ;IAAW;IAAW;IAAS;CAAa,CAAU"}
|
|
@@ -1,40 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
+
import { ThroughputFormatOptions } from './throughput';
|
|
7
|
+
/**
|
|
8
|
+
* Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.
|
|
9
|
+
* Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.
|
|
10
|
+
*
|
|
11
|
+
* To format bytes, we also make use of the `numbro` package,
|
|
12
|
+
* because it can handle adding units like KB, MB, GB, etc. correctly.
|
|
13
|
+
*/
|
|
6
14
|
export declare const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>>;
|
|
7
15
|
export declare const UNIT_CONFIG: {
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
16
|
+
readonly "counts/sec": UnitConfig;
|
|
17
|
+
readonly "events/sec": UnitConfig;
|
|
18
|
+
readonly "messages/sec": UnitConfig;
|
|
19
|
+
readonly "ops/sec": UnitConfig;
|
|
20
|
+
readonly "packets/sec": UnitConfig;
|
|
21
|
+
readonly "reads/sec": UnitConfig;
|
|
22
|
+
readonly "records/sec": UnitConfig;
|
|
23
|
+
readonly "requests/sec": UnitConfig;
|
|
24
|
+
readonly "rows/sec": UnitConfig;
|
|
25
|
+
readonly "writes/sec": UnitConfig;
|
|
26
|
+
readonly bytes: UnitConfig;
|
|
27
|
+
readonly decimal: UnitConfig;
|
|
28
|
+
readonly percent: UnitConfig;
|
|
29
|
+
readonly "percent-decimal": UnitConfig;
|
|
12
30
|
readonly "%": UnitConfig;
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
31
|
+
readonly milliseconds: UnitConfig;
|
|
32
|
+
readonly seconds: UnitConfig;
|
|
33
|
+
readonly minutes: UnitConfig;
|
|
34
|
+
readonly hours: UnitConfig;
|
|
35
|
+
readonly days: UnitConfig;
|
|
36
|
+
readonly weeks: UnitConfig;
|
|
37
|
+
readonly months: UnitConfig;
|
|
38
|
+
readonly years: UnitConfig;
|
|
21
39
|
};
|
|
22
|
-
export declare type
|
|
40
|
+
export declare type FormatOptions = TimeFormatOptions | PercentFormatOptions | DecimalFormatOptions | BytesFormatOptions | ThroughputFormatOptions;
|
|
23
41
|
declare type HasDecimalPlaces<UnitOpt> = UnitOpt extends {
|
|
24
|
-
|
|
42
|
+
decimalPlaces?: number;
|
|
25
43
|
} ? UnitOpt : never;
|
|
26
|
-
declare type
|
|
27
|
-
|
|
44
|
+
declare type HasShortValues<UnitOpt> = UnitOpt extends {
|
|
45
|
+
shortValues?: boolean;
|
|
28
46
|
} ? UnitOpt : never;
|
|
29
|
-
export declare function formatValue(value: number,
|
|
30
|
-
export declare function
|
|
31
|
-
export declare function getUnitGroup(
|
|
32
|
-
export declare function getUnitGroupConfig(
|
|
33
|
-
export declare function isTimeUnit(
|
|
34
|
-
export declare function isPercentUnit(
|
|
35
|
-
export declare function isDecimalUnit(
|
|
36
|
-
export declare function isBytesUnit(
|
|
37
|
-
export declare function isUnitWithDecimalPlaces(
|
|
38
|
-
export declare function
|
|
47
|
+
export declare function formatValue(value: number, formatOptions?: FormatOptions): string;
|
|
48
|
+
export declare function getUnitConfig(formatOptions: FormatOptions): UnitConfig;
|
|
49
|
+
export declare function getUnitGroup(formatOptions: FormatOptions): UnitGroup;
|
|
50
|
+
export declare function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig;
|
|
51
|
+
export declare function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions;
|
|
52
|
+
export declare function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions;
|
|
53
|
+
export declare function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions;
|
|
54
|
+
export declare function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions;
|
|
55
|
+
export declare function isUnitWithDecimalPlaces(formatOptions: FormatOptions): formatOptions is HasDecimalPlaces<FormatOptions>;
|
|
56
|
+
export declare function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions>;
|
|
57
|
+
export declare function isThroughputUnit(formatOptions: FormatOptions): formatOptions is ThroughputFormatOptions;
|
|
39
58
|
export {};
|
|
40
59
|
//# sourceMappingURL=units.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,kBAAkB,IAAI,kBAAkB,EAAyC,MAAM,SAAS,CAAC;AACvH,OAAO,EAEL,oBAAoB,IAAI,oBAAoB,EAG7C,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,oBAAoB,IAAI,oBAAoB,EAG7C,MAAM,WAAW,CAAC;AACnB,OAAO,EAAc,iBAAiB,IAAI,iBAAiB,EAAuC,MAAM,QAAQ,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAIL,uBAAuB,EACxB,MAAM,cAAc,CAAC;AAEtB;;;;;;GAMG;AAEH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAM1E,CAAC;AACF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;CAMd,CAAC;AAEX,oBAAY,aAAa,GACrB,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,uBAAuB,CAAC;AAE5B,aAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAC9F,aAAK,cAAc,CAAC,OAAO,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,CA2BhF;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;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,uBAAuB,CAEvG"}
|
|
@@ -10,71 +10,86 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
13
|
+
import { formatBytes, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';
|
|
14
|
+
import { formatDecimal, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from './decimal';
|
|
15
|
+
import { formatPercent, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from './percent';
|
|
16
16
|
import { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';
|
|
17
|
-
|
|
17
|
+
import { formatThroughput, THROUGHPUT_GROUP_CONFIG, THROUGHPUT_UNIT_CONFIG } from './throughput';
|
|
18
|
+
/**
|
|
19
|
+
* Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.
|
|
20
|
+
* Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.
|
|
21
|
+
*
|
|
22
|
+
* To format bytes, we also make use of the `numbro` package,
|
|
23
|
+
* because it can handle adding units like KB, MB, GB, etc. correctly.
|
|
24
|
+
*/ export const UNIT_GROUP_CONFIG = {
|
|
18
25
|
Time: TIME_GROUP_CONFIG,
|
|
19
26
|
Percent: PERCENT_GROUP_CONFIG,
|
|
20
27
|
Decimal: DECIMAL_GROUP_CONFIG,
|
|
21
|
-
Bytes: BYTES_GROUP_CONFIG
|
|
28
|
+
Bytes: BYTES_GROUP_CONFIG,
|
|
29
|
+
Throughput: THROUGHPUT_GROUP_CONFIG
|
|
22
30
|
};
|
|
23
31
|
export const UNIT_CONFIG = {
|
|
24
32
|
...TIME_UNIT_CONFIG,
|
|
25
33
|
...PERCENT_UNIT_CONFIG,
|
|
26
34
|
...DECIMAL_UNIT_CONFIG,
|
|
27
|
-
...BYTES_UNIT_CONFIG
|
|
35
|
+
...BYTES_UNIT_CONFIG,
|
|
36
|
+
...THROUGHPUT_UNIT_CONFIG
|
|
28
37
|
};
|
|
29
|
-
export function formatValue(value,
|
|
30
|
-
if (
|
|
38
|
+
export function formatValue(value, formatOptions) {
|
|
39
|
+
if (formatOptions === undefined) {
|
|
31
40
|
return value.toString();
|
|
32
41
|
}
|
|
33
|
-
if (
|
|
34
|
-
return
|
|
42
|
+
if (isBytesUnit(formatOptions)) {
|
|
43
|
+
return formatBytes(value, formatOptions);
|
|
35
44
|
}
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
45
|
+
if (isDecimalUnit(formatOptions)) {
|
|
46
|
+
return formatDecimal(value, formatOptions);
|
|
38
47
|
}
|
|
39
|
-
if (isPercentUnit(
|
|
40
|
-
return formatPercent(value,
|
|
48
|
+
if (isPercentUnit(formatOptions)) {
|
|
49
|
+
return formatPercent(value, formatOptions);
|
|
41
50
|
}
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
51
|
+
if (isTimeUnit(formatOptions)) {
|
|
52
|
+
return formatTime(value, formatOptions);
|
|
44
53
|
}
|
|
45
|
-
|
|
54
|
+
if (isThroughputUnit(formatOptions)) {
|
|
55
|
+
return formatThroughput(value, formatOptions);
|
|
56
|
+
}
|
|
57
|
+
const exhaustive = formatOptions;
|
|
46
58
|
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
47
59
|
}
|
|
48
|
-
export function
|
|
49
|
-
return UNIT_CONFIG[
|
|
60
|
+
export function getUnitConfig(formatOptions) {
|
|
61
|
+
return UNIT_CONFIG[formatOptions.unit];
|
|
50
62
|
}
|
|
51
|
-
export function getUnitGroup(
|
|
52
|
-
return
|
|
63
|
+
export function getUnitGroup(formatOptions) {
|
|
64
|
+
return getUnitConfig(formatOptions).group;
|
|
53
65
|
}
|
|
54
|
-
export function getUnitGroupConfig(
|
|
55
|
-
const unitConfig =
|
|
66
|
+
export function getUnitGroupConfig(formatOptions) {
|
|
67
|
+
const unitConfig = getUnitConfig(formatOptions);
|
|
56
68
|
return UNIT_GROUP_CONFIG[unitConfig.group];
|
|
57
69
|
}
|
|
58
70
|
// Type guards
|
|
59
|
-
export function isTimeUnit(
|
|
60
|
-
return getUnitGroup(
|
|
71
|
+
export function isTimeUnit(formatOptions) {
|
|
72
|
+
return getUnitGroup(formatOptions) === 'Time';
|
|
73
|
+
}
|
|
74
|
+
export function isPercentUnit(formatOptions) {
|
|
75
|
+
return getUnitGroup(formatOptions) === 'Percent';
|
|
61
76
|
}
|
|
62
|
-
export function
|
|
63
|
-
return getUnitGroup(
|
|
77
|
+
export function isDecimalUnit(formatOptions) {
|
|
78
|
+
return getUnitGroup(formatOptions) === 'Decimal';
|
|
64
79
|
}
|
|
65
|
-
export function
|
|
66
|
-
return getUnitGroup(
|
|
80
|
+
export function isBytesUnit(formatOptions) {
|
|
81
|
+
return getUnitGroup(formatOptions) === 'Bytes';
|
|
67
82
|
}
|
|
68
|
-
export function
|
|
69
|
-
|
|
83
|
+
export function isUnitWithDecimalPlaces(formatOptions) {
|
|
84
|
+
const groupConfig = getUnitGroupConfig(formatOptions);
|
|
85
|
+
return !!groupConfig.decimalPlaces;
|
|
70
86
|
}
|
|
71
|
-
export function
|
|
72
|
-
const groupConfig = getUnitGroupConfig(
|
|
73
|
-
return !!groupConfig.
|
|
87
|
+
export function isUnitWithShortValues(formatOptions) {
|
|
88
|
+
const groupConfig = getUnitGroupConfig(formatOptions);
|
|
89
|
+
return !!groupConfig.shortValues;
|
|
74
90
|
}
|
|
75
|
-
export function
|
|
76
|
-
|
|
77
|
-
return !!groupConfig.abbreviate;
|
|
91
|
+
export function isThroughputUnit(formatOptions) {
|
|
92
|
+
return getUnitGroup(formatOptions) == 'Throughput';
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
//# 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 {
|
|
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';\nimport {\n formatThroughput,\n THROUGHPUT_GROUP_CONFIG,\n THROUGHPUT_UNIT_CONFIG,\n ThroughputFormatOptions,\n} from './throughput';\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 Throughput: THROUGHPUT_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n ...THROUGHPUT_UNIT_CONFIG,\n} as const;\n\nexport type FormatOptions =\n | TimeFormatOptions\n | PercentFormatOptions\n | DecimalFormatOptions\n | BytesFormatOptions\n | ThroughputFormatOptions;\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 if (isThroughputUnit(formatOptions)) {\n return formatThroughput(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\nexport function isThroughputUnit(formatOptions: FormatOptions): formatOptions is ThroughputFormatOptions {\n return getUnitGroup(formatOptions) == 'Throughput';\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","formatThroughput","THROUGHPUT_GROUP_CONFIG","THROUGHPUT_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","Throughput","UNIT_CONFIG","formatValue","value","formatOptions","undefined","toString","isBytesUnit","isDecimalUnit","isPercentUnit","isTimeUnit","isThroughputUnit","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;AAEjH,SACEC,gBAAgB,EAChBC,uBAAuB,EACvBC,sBAAsB,QAEjB,eAAe;AAEtB;;;;;;CAMC,GAED,OAAO,MAAMC,oBAAkE;IAC7EC,MAAMN;IACNO,SAASV;IACTW,SAASd;IACTe,OAAOlB;IACPmB,YAAYP;AACd,EAAE;AACF,OAAO,MAAMQ,cAAc;IACzB,GAAGV,gBAAgB;IACnB,GAAGH,mBAAmB;IACtB,GAAGH,mBAAmB;IACtB,GAAGH,iBAAiB;IACpB,GAAGY,sBAAsB;AAC3B,EAAW;AAYX,OAAO,SAASQ,YAAYC,KAAa,EAAEC,aAA6B;IACtE,IAAIA,kBAAkBC,WAAW;QAC/B,OAAOF,MAAMG;IACf;IAEA,IAAIC,YAAYH,gBAAgB;QAC9B,OAAOxB,YAAYuB,OAAOC;IAC5B;IAEA,IAAII,cAAcJ,gBAAgB;QAChC,OAAOrB,cAAcoB,OAAOC;IAC9B;IAEA,IAAIK,cAAcL,gBAAgB;QAChC,OAAOlB,cAAciB,OAAOC;IAC9B;IAEA,IAAIM,WAAWN,gBAAgB;QAC7B,OAAOf,WAAWc,OAAOC;IAC3B;IAEA,IAAIO,iBAAiBP,gBAAgB;QACnC,OAAOZ,iBAAiBW,OAAOC;IACjC;IAEA,MAAMQ,aAAoBR;IAC1B,MAAM,IAAIS,MAAM,CAAC,qBAAqB,EAAED,WAAW,CAAC;AACtD;AAEA,OAAO,SAASE,cAAcV,aAA4B;IACxD,OAAOH,WAAW,CAACG,cAAcW,KAAK;AACxC;AAEA,OAAO,SAASC,aAAaZ,aAA4B;IACvD,OAAOU,cAAcV,eAAea;AACtC;AAEA,OAAO,SAASC,mBAAmBd,aAA4B;IAC7D,MAAMe,aAAaL,cAAcV;IACjC,OAAOT,iBAAiB,CAACwB,WAAWF,MAAM;AAC5C;AAEA,cAAc;AACd,OAAO,SAASP,WAAWN,aAA4B;IACrD,OAAOY,aAAaZ,mBAAmB;AACzC;AAEA,OAAO,SAASK,cAAcL,aAA4B;IACxD,OAAOY,aAAaZ,mBAAmB;AACzC;AAEA,OAAO,SAASI,cAAcJ,aAA4B;IACxD,OAAOY,aAAaZ,mBAAmB;AACzC;AAEA,OAAO,SAASG,YAAYH,aAA4B;IACtD,OAAOY,aAAaZ,mBAAmB;AACzC;AAEA,OAAO,SAASgB,wBACdhB,aAA4B;IAE5B,MAAMiB,cAAcH,mBAAmBd;IAEvC,OAAO,CAAC,CAACiB,YAAYC;AACvB;AAEA,OAAO,SAASC,sBAAsBnB,aAA4B;IAChE,MAAMiB,cAAcH,mBAAmBd;IAEvC,OAAO,CAAC,CAACiB,YAAYG;AACvB;AAEA,OAAO,SAASb,iBAAiBP,aAA4B;IAC3D,OAAOY,aAAaZ,kBAAkB;AACxC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
2
|
-
export declare function hasDecimalPlaces(
|
|
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,
|
|
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
|
|
14
|
-
return
|
|
13
|
+
export function shouldShortenValues(shortValues) {
|
|
14
|
+
return shortValues !== false;
|
|
15
15
|
}
|
|
16
|
-
export function hasDecimalPlaces(
|
|
17
|
-
return typeof
|
|
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
|
|
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,28 @@ 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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
defaultValue?: VariableValue;
|
|
24
|
+
allowMultiple?: boolean;
|
|
25
|
+
allowAllValue?: boolean;
|
|
26
|
+
customAllValue?: string;
|
|
27
|
+
capturingRegexp?: string;
|
|
28
|
+
sort?: string;
|
|
27
29
|
plugin: Definition<PluginSpec>;
|
|
28
30
|
}
|
|
29
|
-
export
|
|
31
|
+
export interface BuiltinVariableDefinition extends Definition<BuiltinVariableSpec> {
|
|
32
|
+
kind: 'BuiltinVariable';
|
|
33
|
+
}
|
|
34
|
+
export interface BuiltinVariableSpec extends VariableSpec {
|
|
35
|
+
value: () => string;
|
|
36
|
+
source: string;
|
|
37
|
+
}
|
|
38
|
+
export declare type VariableDefinition = TextVariableDefinition | ListVariableDefinition | BuiltinVariableDefinition;
|
|
30
39
|
/**
|
|
31
40
|
* A variable that belongs to a project.
|
|
32
41
|
*/
|
|
@@ -35,5 +44,15 @@ export interface VariableResource {
|
|
|
35
44
|
metadata: ProjectMetadata;
|
|
36
45
|
spec: VariableDefinition;
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* A global variable that doesn´t belong to a project.
|
|
49
|
+
*/
|
|
50
|
+
export interface GlobalVariableResource {
|
|
51
|
+
kind: 'GlobalVariable';
|
|
52
|
+
metadata: Metadata;
|
|
53
|
+
spec: VariableDefinition;
|
|
54
|
+
}
|
|
55
|
+
export declare type Variable = VariableResource | GlobalVariableResource;
|
|
56
|
+
export declare function getVariableProject(variable: Variable): string | undefined;
|
|
38
57
|
export declare const DEFAULT_ALL_VALUE: "$__all";
|
|
39
58
|
//# 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;
|
|
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,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvD,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;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;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,YAAY,CAAC,EAAE,aAAa,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,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,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"}
|
package/dist/model/variables.js
CHANGED
|
@@ -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
|
|
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 sort?: 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;AAuEjC,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,
|
|
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"}
|
package/dist/utils/event.js.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/utils/fetch.d.ts
CHANGED
|
@@ -12,12 +12,14 @@ export declare function fetchJson<T>(...args: Parameters<typeof global.fetch>):
|
|
|
12
12
|
* Error thrown when fetch returns a non-200 response.
|
|
13
13
|
*/
|
|
14
14
|
export declare class FetchError extends Error {
|
|
15
|
+
status: number;
|
|
15
16
|
constructor(response: Readonly<Response>);
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* General error type for an error that has a message that is OK to show to the end user.
|
|
19
20
|
*/
|
|
20
21
|
export declare class UserFriendlyError extends Error {
|
|
21
|
-
|
|
22
|
+
status: number;
|
|
23
|
+
constructor(message: string, status: number);
|
|
22
24
|
}
|
|
23
25
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,qBAanE;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,cAI1E;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,wBAAsB,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,qBAanE;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,cAI1E;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,MAAM,EAAE,MAAM,CAAC;gBACH,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;CAKzC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,EAAE,MAAM,CAAC;gBACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK5C"}
|
package/dist/utils/fetch.js
CHANGED
|
@@ -12,15 +12,28 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
/**
|
|
14
14
|
* Calls `global.fetch` and determines which type of error to show for non-200 responses.
|
|
15
|
-
*/
|
|
15
|
+
*/ function _define_property(obj, key, value) {
|
|
16
|
+
if (key in obj) {
|
|
17
|
+
Object.defineProperty(obj, key, {
|
|
18
|
+
value: value,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
obj[key] = value;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
export async function fetch(...args) {
|
|
16
29
|
const response = await global.fetch(...args);
|
|
17
30
|
if (response.ok === false) {
|
|
18
31
|
const json = await response.json();
|
|
19
32
|
if (json.error) {
|
|
20
|
-
throw new UserFriendlyError(json.error);
|
|
33
|
+
throw new UserFriendlyError(json.error, response.status);
|
|
21
34
|
}
|
|
22
35
|
if (json.message) {
|
|
23
|
-
throw new UserFriendlyError(json.message);
|
|
36
|
+
throw new UserFriendlyError(json.message, response.status);
|
|
24
37
|
}
|
|
25
38
|
throw new FetchError(response);
|
|
26
39
|
}
|
|
@@ -40,14 +53,18 @@
|
|
|
40
53
|
*/ export class FetchError extends Error {
|
|
41
54
|
constructor(response){
|
|
42
55
|
super(`${response.status} ${response.statusText}`);
|
|
56
|
+
_define_property(this, "status", void 0);
|
|
57
|
+
this.status = response.status;
|
|
43
58
|
Object.setPrototypeOf(this, FetchError.prototype);
|
|
44
59
|
}
|
|
45
60
|
}
|
|
46
61
|
/**
|
|
47
62
|
* General error type for an error that has a message that is OK to show to the end user.
|
|
48
63
|
*/ export class UserFriendlyError extends Error {
|
|
49
|
-
constructor(message){
|
|
64
|
+
constructor(message, status){
|
|
50
65
|
super(message);
|
|
66
|
+
_define_property(this, "status", void 0);
|
|
67
|
+
this.status = status;
|
|
51
68
|
Object.setPrototypeOf(this, UserFriendlyError.prototype);
|
|
52
69
|
}
|
|
53
70
|
}
|