@perses-dev/core 0.52.0 → 0.53.0-beta.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.
- package/dist/cjs/model/units/bytes.js +19 -7
- package/dist/cjs/model/units/throughput.js +14 -2
- package/dist/cjs/utils/fetch.js +2 -2
- package/dist/model/units/bytes.d.ts +2 -2
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +19 -7
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/throughput.d.ts +1 -1
- package/dist/model/units/throughput.d.ts.map +1 -1
- package/dist/model/units/throughput.js +14 -2
- package/dist/model/units/throughput.js.map +1 -1
- package/dist/model/units/units.d.ts +2 -0
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/utils/fetch.d.ts +4 -4
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +3 -3
- package/dist/utils/fetch.js.map +1 -1
- package/package.json +1 -1
|
@@ -40,11 +40,17 @@ function _interop_require_default(obj) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* We
|
|
44
|
-
*
|
|
43
|
+
* We support both SI (decimal) and IEC (binary) units for bytes:
|
|
44
|
+
*
|
|
45
|
+
* SI/decimal (unit: 'decbytes'):
|
|
45
46
|
* 1 KB = 1000 bytes (1000^1 bytes)
|
|
46
47
|
* 1 MB = 1,000,000 bytes (1000^2 bytes)
|
|
47
48
|
* etc.
|
|
49
|
+
*
|
|
50
|
+
* IEC/binary (unit: 'bytes'):
|
|
51
|
+
* 1 KiB = 1024 bytes (1024^1 bytes)
|
|
52
|
+
* 1 MiB = 1,048,576 bytes (1024^2 bytes)
|
|
53
|
+
* etc.
|
|
48
54
|
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
49
55
|
const BYTES_GROUP_CONFIG = {
|
|
50
56
|
label: 'Bytes',
|
|
@@ -54,12 +60,18 @@ const BYTES_GROUP_CONFIG = {
|
|
|
54
60
|
const BYTES_UNIT_CONFIG = {
|
|
55
61
|
bytes: {
|
|
56
62
|
group: 'Bytes',
|
|
57
|
-
label: 'Bytes'
|
|
63
|
+
label: 'Bytes (IEC)'
|
|
64
|
+
},
|
|
65
|
+
decbytes: {
|
|
66
|
+
group: 'Bytes',
|
|
67
|
+
label: 'Bytes (SI)'
|
|
58
68
|
}
|
|
59
69
|
};
|
|
60
|
-
function formatBytes(bytes, { shortValues, decimalPlaces }) {
|
|
70
|
+
function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces }) {
|
|
71
|
+
const isDecimal = unit === 'decbytes';
|
|
72
|
+
const threshold = isDecimal ? 1000 : 1024;
|
|
61
73
|
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
62
|
-
if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bytes) <
|
|
74
|
+
if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bytes) < threshold) {
|
|
63
75
|
const formatterOptions = {
|
|
64
76
|
style: 'unit',
|
|
65
77
|
unit: 'byte',
|
|
@@ -70,7 +82,7 @@ function formatBytes(bytes, { shortValues, decimalPlaces }) {
|
|
|
70
82
|
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
|
|
71
83
|
formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
|
|
72
84
|
} else {
|
|
73
|
-
// This can happen if bytes is between -
|
|
85
|
+
// This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)
|
|
74
86
|
if ((0, _utils.shouldShortenValues)(shortValues)) {
|
|
75
87
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
76
88
|
}
|
|
@@ -82,7 +94,7 @@ function formatBytes(bytes, { shortValues, decimalPlaces }) {
|
|
|
82
94
|
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
83
95
|
return (0, _numbro.default)(bytes).format({
|
|
84
96
|
output: 'byte',
|
|
85
|
-
base: 'decimal',
|
|
97
|
+
base: isDecimal ? 'decimal' : 'binary',
|
|
86
98
|
spaceSeparated: true,
|
|
87
99
|
mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
|
|
88
100
|
// trimMantissa trims trailing 0s
|
|
@@ -46,7 +46,11 @@ const THROUGHPUT_UNIT_CONFIG = {
|
|
|
46
46
|
},
|
|
47
47
|
'bytes/sec': {
|
|
48
48
|
group: THROUGHPUT_GROUP,
|
|
49
|
-
label: 'Bytes/sec'
|
|
49
|
+
label: 'Bytes/sec (IEC)'
|
|
50
|
+
},
|
|
51
|
+
'decbytes/sec': {
|
|
52
|
+
group: THROUGHPUT_GROUP,
|
|
53
|
+
label: 'Bytes/sec (SI)'
|
|
50
54
|
},
|
|
51
55
|
'counts/sec': {
|
|
52
56
|
group: THROUGHPUT_GROUP,
|
|
@@ -91,8 +95,16 @@ const THROUGHPUT_UNIT_CONFIG = {
|
|
|
91
95
|
};
|
|
92
96
|
function formatThroughput(value, { unit, shortValues, decimalPlaces }) {
|
|
93
97
|
// special case for data throughput
|
|
94
|
-
if (unit === '
|
|
98
|
+
if (unit === 'decbytes/sec') {
|
|
95
99
|
const denominator = Math.abs(value) < 1000 ? 'sec' : 's';
|
|
100
|
+
return (0, _bytes.formatBytes)(value, {
|
|
101
|
+
unit: 'decbytes',
|
|
102
|
+
shortValues,
|
|
103
|
+
decimalPlaces
|
|
104
|
+
}) + '/' + denominator;
|
|
105
|
+
}
|
|
106
|
+
if (unit === 'bytes/sec') {
|
|
107
|
+
const denominator = Math.abs(value) < 1024 ? 'sec' : 's';
|
|
96
108
|
return (0, _bytes.formatBytes)(value, {
|
|
97
109
|
unit: 'bytes',
|
|
98
110
|
shortValues,
|
package/dist/cjs/utils/fetch.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
/**
|
|
14
|
-
* Calls `
|
|
14
|
+
* Calls `globalThis.fetch` and determines which type of error to show for non-200 responses.
|
|
15
15
|
*/ "use strict";
|
|
16
16
|
Object.defineProperty(exports, "__esModule", {
|
|
17
17
|
value: true
|
|
@@ -37,7 +37,7 @@ _export(exports, {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
async function fetch(...args) {
|
|
40
|
-
const response = await
|
|
40
|
+
const response = await globalThis.fetch(...args);
|
|
41
41
|
if (response.ok === false) {
|
|
42
42
|
const contentType = response.headers.get('content-type');
|
|
43
43
|
if (contentType?.includes('application/json')) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
-
type BytesUnit = 'bytes';
|
|
2
|
+
type BytesUnit = 'bytes' | 'decbytes';
|
|
3
3
|
export type BytesFormatOptions = {
|
|
4
4
|
unit?: BytesUnit;
|
|
5
5
|
decimalPlaces?: number;
|
|
@@ -7,6 +7,6 @@ export type BytesFormatOptions = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
9
9
|
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>>;
|
|
10
|
-
export declare function formatBytes(bytes: number, { shortValues, decimalPlaces }: BytesFormatOptions): string;
|
|
10
|
+
export declare function formatBytes(bytes: number, { unit, shortValues, decimalPlaces }: BytesFormatOptions): string;
|
|
11
11
|
export {};
|
|
12
12
|
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAmBtD,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CASrE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAc,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAsCrH"}
|
|
@@ -14,11 +14,17 @@ import numbro from 'numbro';
|
|
|
14
14
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
15
|
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
16
16
|
/**
|
|
17
|
-
* We
|
|
18
|
-
*
|
|
17
|
+
* We support both SI (decimal) and IEC (binary) units for bytes:
|
|
18
|
+
*
|
|
19
|
+
* SI/decimal (unit: 'decbytes'):
|
|
19
20
|
* 1 KB = 1000 bytes (1000^1 bytes)
|
|
20
21
|
* 1 MB = 1,000,000 bytes (1000^2 bytes)
|
|
21
22
|
* etc.
|
|
23
|
+
*
|
|
24
|
+
* IEC/binary (unit: 'bytes'):
|
|
25
|
+
* 1 KiB = 1024 bytes (1024^1 bytes)
|
|
26
|
+
* 1 MiB = 1,048,576 bytes (1024^2 bytes)
|
|
27
|
+
* etc.
|
|
22
28
|
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
23
29
|
export const BYTES_GROUP_CONFIG = {
|
|
24
30
|
label: 'Bytes',
|
|
@@ -28,12 +34,18 @@ export const BYTES_GROUP_CONFIG = {
|
|
|
28
34
|
export const BYTES_UNIT_CONFIG = {
|
|
29
35
|
bytes: {
|
|
30
36
|
group: 'Bytes',
|
|
31
|
-
label: 'Bytes'
|
|
37
|
+
label: 'Bytes (IEC)'
|
|
38
|
+
},
|
|
39
|
+
decbytes: {
|
|
40
|
+
group: 'Bytes',
|
|
41
|
+
label: 'Bytes (SI)'
|
|
32
42
|
}
|
|
33
43
|
};
|
|
34
|
-
export function formatBytes(bytes, { shortValues, decimalPlaces }) {
|
|
44
|
+
export function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces }) {
|
|
45
|
+
const isDecimal = unit === 'decbytes';
|
|
46
|
+
const threshold = isDecimal ? 1000 : 1024;
|
|
35
47
|
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
36
|
-
if (!shouldShortenValues(shortValues) || Math.abs(bytes) <
|
|
48
|
+
if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {
|
|
37
49
|
const formatterOptions = {
|
|
38
50
|
style: 'unit',
|
|
39
51
|
unit: 'byte',
|
|
@@ -44,7 +56,7 @@ export function formatBytes(bytes, { shortValues, decimalPlaces }) {
|
|
|
44
56
|
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
45
57
|
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
46
58
|
} else {
|
|
47
|
-
// This can happen if bytes is between -
|
|
59
|
+
// This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)
|
|
48
60
|
if (shouldShortenValues(shortValues)) {
|
|
49
61
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
50
62
|
}
|
|
@@ -56,7 +68,7 @@ export function formatBytes(bytes, { shortValues, decimalPlaces }) {
|
|
|
56
68
|
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
57
69
|
return numbro(bytes).format({
|
|
58
70
|
output: 'byte',
|
|
59
|
-
base: 'decimal',
|
|
71
|
+
base: isDecimal ? 'decimal' : 'binary',
|
|
60
72
|
spaceSeparated: true,
|
|
61
73
|
mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
|
|
62
74
|
// trimMantissa trims trailing 0s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/bytes.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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\n/**\n * We
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/bytes.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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bytes:\n *\n * SI/decimal (unit: 'decbytes'):\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n *\n * IEC/binary (unit: 'bytes'):\n * 1 KiB = 1024 bytes (1024^1 bytes)\n * 1 MiB = 1,048,576 bytes (1024^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BytesUnit = 'bytes' | 'decbytes';\n\nexport type BytesFormatOptions = {\n unit?: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes (IEC)',\n },\n decbytes: {\n group: 'Bytes',\n label: 'Bytes (SI)',\n },\n};\n\nexport function formatBytes(bytes: number, { unit = 'bytes', shortValues, decimalPlaces }: BytesFormatOptions): string {\n const isDecimal = unit === 'decbytes';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(bytes);\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like KB, MB, GB, etc. correctly.\n return numbro(bytes).format({\n output: 'byte',\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DEFAULT_NUMBRO_MANTISSA","BYTES_GROUP_CONFIG","label","decimalPlaces","shortValues","BYTES_UNIT_CONFIG","bytes","group","decbytes","formatBytes","unit","isDecimal","threshold","Math","abs","formatterOptions","style","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"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,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAShC,OAAO,MAAMC,qBAAsC;IACjDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,oBAA6D;IACxEC,OAAO;QACLC,OAAO;QACPL,OAAO;IACT;IACAM,UAAU;QACRD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,YAAYH,KAAa,EAAE,EAAEI,OAAO,OAAO,EAAEN,WAAW,EAAED,aAAa,EAAsB;IAC3G,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACZ,oBAAoBK,gBAAgBS,KAAKC,GAAG,CAACR,SAASM,WAAW;QACpE,MAAMG,mBAA6C;YACjDC,OAAO;YACPN,MAAM;YACNO,aAAa;YACbC,aAAa;QACf;QAEA,IAAIrB,iBAAiBM,gBAAgB;YACnCY,iBAAiBI,qBAAqB,GAAGrB,mBAAmBK;YAC5DY,iBAAiBK,qBAAqB,GAAGtB,mBAAmBK;QAC9D,OAAO;YACL,2FAA2F;YAC3F,IAAIJ,oBAAoBK,cAAc;gBACpCW,iBAAiBM,wBAAwB,GAAGzB;YAC9C;QACF;QACA,MAAM0B,YAAYC,KAAKC,YAAY,CAAC,SAAST;QAC7C,OAAOO,UAAUG,MAAM,CAACnB;IAC1B;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,OAAOX,OAAOW,OAAOmB,MAAM,CAAC;QAC1BC,QAAQ;QACRC,MAAMhB,YAAY,YAAY;QAC9BiB,gBAAgB;QAChBC,UAAUhC,iBAAiBM,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC8B,cAAc,CAACjC,iBAAiBM;QAChC,wEAAwE;QACxE4B,kBAAkB,CAAClC,iBAAiBM;IACtC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
-
type ThroughputUnit = 'bits/sec' | 'bytes/sec' | 'counts/sec' | 'events/sec' | 'messages/sec' | 'ops/sec' | 'packets/sec' | 'reads/sec' | 'records/sec' | 'requests/sec' | 'rows/sec' | 'writes/sec';
|
|
2
|
+
type ThroughputUnit = 'bits/sec' | 'bytes/sec' | 'decbytes/sec' | 'counts/sec' | 'events/sec' | 'messages/sec' | 'ops/sec' | 'packets/sec' | 'reads/sec' | 'records/sec' | 'requests/sec' | 'rows/sec' | 'writes/sec';
|
|
3
3
|
export type ThroughputFormatOptions = {
|
|
4
4
|
unit?: ThroughputUnit;
|
|
5
5
|
decimalPlaces?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throughput.d.ts","sourceRoot":"","sources":["../../../src/model/units/throughput.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,cAAc,GACf,UAAU,GACV,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,cAAc,GACd,SAAS,GACT,aAAa,GACb,WAAW,GACX,aAAa,GACb,cAAc,GACd,UAAU,GACV,YAAY,CAAC;AACjB,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,uBAAuB,EAAE,eAGrC,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"throughput.d.ts","sourceRoot":"","sources":["../../../src/model/units/throughput.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,cAAc,GACf,UAAU,GACV,WAAW,GACX,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,cAAc,GACd,SAAS,GACT,aAAa,GACb,WAAW,GACX,aAAa,GACb,cAAc,GACd,UAAU,GACV,YAAY,CAAC;AACjB,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,uBAAuB,EAAE,eAGrC,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CAsD/E,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAgCrH"}
|
|
@@ -25,7 +25,11 @@ export const THROUGHPUT_UNIT_CONFIG = {
|
|
|
25
25
|
},
|
|
26
26
|
'bytes/sec': {
|
|
27
27
|
group: THROUGHPUT_GROUP,
|
|
28
|
-
label: 'Bytes/sec'
|
|
28
|
+
label: 'Bytes/sec (IEC)'
|
|
29
|
+
},
|
|
30
|
+
'decbytes/sec': {
|
|
31
|
+
group: THROUGHPUT_GROUP,
|
|
32
|
+
label: 'Bytes/sec (SI)'
|
|
29
33
|
},
|
|
30
34
|
'counts/sec': {
|
|
31
35
|
group: THROUGHPUT_GROUP,
|
|
@@ -70,8 +74,16 @@ export const THROUGHPUT_UNIT_CONFIG = {
|
|
|
70
74
|
};
|
|
71
75
|
export function formatThroughput(value, { unit, shortValues, decimalPlaces }) {
|
|
72
76
|
// special case for data throughput
|
|
73
|
-
if (unit === '
|
|
77
|
+
if (unit === 'decbytes/sec') {
|
|
74
78
|
const denominator = Math.abs(value) < 1000 ? 'sec' : 's';
|
|
79
|
+
return formatBytes(value, {
|
|
80
|
+
unit: 'decbytes',
|
|
81
|
+
shortValues,
|
|
82
|
+
decimalPlaces
|
|
83
|
+
}) + '/' + denominator;
|
|
84
|
+
}
|
|
85
|
+
if (unit === 'bytes/sec') {
|
|
86
|
+
const denominator = Math.abs(value) < 1024 ? 'sec' : 's';
|
|
75
87
|
return formatBytes(value, {
|
|
76
88
|
unit: 'bytes',
|
|
77
89
|
shortValues,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/throughput.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 } from './bytes';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype ThroughputUnit =\n | 'bits/sec'\n | 'bytes/sec'\n | 'counts/sec'\n | 'events/sec'\n | 'messages/sec'\n | 'ops/sec'\n | 'packets/sec'\n | 'reads/sec'\n | 'records/sec'\n | 'requests/sec'\n | 'rows/sec'\n | 'writes/sec';\nexport type ThroughputFormatOptions = {\n unit?: ThroughputUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const THROUGHPUT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Throughput',\n decimalPlaces: true,\n};\nconst THROUGHPUT_GROUP = 'Throughput';\nexport const THROUGHPUT_UNIT_CONFIG: Readonly<Record<ThroughputUnit, UnitConfig>> = {\n 'bits/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bits/sec',\n },\n 'bytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec',\n },\n 'counts/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Counts/sec',\n },\n 'events/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Events/sec',\n },\n 'messages/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Messages/sec',\n },\n 'ops/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Ops/sec',\n },\n 'packets/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Packets/sec',\n },\n 'reads/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Reads/sec',\n },\n 'requests/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Requests/sec',\n },\n 'records/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Records/sec',\n },\n 'rows/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Rows/sec',\n },\n 'writes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Writes/sec',\n },\n};\n\nexport function formatThroughput(value: number, { unit, shortValues, decimalPlaces }: ThroughputFormatOptions): string {\n // special case for data throughput\n if (unit === '
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/throughput.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 } from './bytes';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype ThroughputUnit =\n | 'bits/sec'\n | 'bytes/sec'\n | 'decbytes/sec'\n | 'counts/sec'\n | 'events/sec'\n | 'messages/sec'\n | 'ops/sec'\n | 'packets/sec'\n | 'reads/sec'\n | 'records/sec'\n | 'requests/sec'\n | 'rows/sec'\n | 'writes/sec';\nexport type ThroughputFormatOptions = {\n unit?: ThroughputUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const THROUGHPUT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Throughput',\n decimalPlaces: true,\n};\nconst THROUGHPUT_GROUP = 'Throughput';\nexport const THROUGHPUT_UNIT_CONFIG: Readonly<Record<ThroughputUnit, UnitConfig>> = {\n 'bits/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bits/sec',\n },\n 'bytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec (IEC)',\n },\n 'decbytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec (SI)',\n },\n\n 'counts/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Counts/sec',\n },\n 'events/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Events/sec',\n },\n 'messages/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Messages/sec',\n },\n 'ops/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Ops/sec',\n },\n 'packets/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Packets/sec',\n },\n 'reads/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Reads/sec',\n },\n 'requests/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Requests/sec',\n },\n 'records/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Records/sec',\n },\n 'rows/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Rows/sec',\n },\n 'writes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Writes/sec',\n },\n};\n\nexport function formatThroughput(value: number, { unit, shortValues, decimalPlaces }: ThroughputFormatOptions): string {\n // special case for data throughput\n if (unit === 'decbytes/sec') {\n const denominator = Math.abs(value) < 1000 ? 'sec' : 's';\n return formatBytes(value, { unit: 'decbytes', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'bytes/sec') {\n const denominator = Math.abs(value) < 1024 ? 'sec' : 's';\n return formatBytes(value, { unit: 'bytes', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value) + ' ' + unit;\n}\n"],"names":["formatBytes","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","THROUGHPUT_GROUP_CONFIG","label","decimalPlaces","THROUGHPUT_GROUP","THROUGHPUT_UNIT_CONFIG","group","formatThroughput","value","unit","shortValues","denominator","Math","abs","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"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,QAAQ,UAAU;AACtC,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAqBpF,OAAO,MAAMC,0BAA2C;IACtDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,MAAMC,mBAAmB;AACzB,OAAO,MAAMC,yBAAuE;IAClF,YAAY;QACVC,OAAOF;QACPF,OAAO;IACT;IACA,aAAa;QACXI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IAEA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;IACA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IACA,WAAW;QACTI,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,aAAa;QACXI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,YAAY;QACVI,OAAOF;QACPF,OAAO;IACT;IACA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASK,iBAAiBC,KAAa,EAAE,EAAEC,IAAI,EAAEC,WAAW,EAAEP,aAAa,EAA2B;IAC3G,mCAAmC;IACnC,IAAIM,SAAS,gBAAgB;QAC3B,MAAME,cAAcC,KAAKC,GAAG,CAACL,SAAS,OAAO,QAAQ;QACrD,OAAOZ,YAAYY,OAAO;YAAEC,MAAM;YAAYC;YAAaP;QAAc,KAAK,MAAMQ;IACtF;IAEA,IAAIF,SAAS,aAAa;QACxB,MAAME,cAAcC,KAAKC,GAAG,CAACL,SAAS,OAAO,QAAQ;QACrD,OAAOZ,YAAYY,OAAO;YAAEC,MAAM;YAASC;YAAaP;QAAc,KAAK,MAAMQ;IACnF;IAEA,MAAMG,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIhB,oBAAoBU,cAAc;QACpCI,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAInB,iBAAiBK,gBAAgB;QACnCW,iBAAiBI,qBAAqB,GAAGnB,mBAAmBI;QAC5DW,iBAAiBK,qBAAqB,GAAGpB,mBAAmBI;IAC9D,OAAO;QACL,IAAIH,oBAAoBU,cAAc;YACpCI,iBAAiBM,wBAAwB,GAAGvB;QAC9C;IACF;IAEA,MAAMwB,YAAYC,KAAKC,YAAY,CAAC,SAAST;IAC7C,OAAOO,UAAUG,MAAM,CAAChB,SAAS,MAAMC;AACzC"}
|
|
@@ -31,6 +31,7 @@ export declare const UNIT_CONFIG: {
|
|
|
31
31
|
readonly usd: UnitConfig;
|
|
32
32
|
readonly "bits/sec": UnitConfig;
|
|
33
33
|
readonly "bytes/sec": UnitConfig;
|
|
34
|
+
readonly "decbytes/sec": UnitConfig;
|
|
34
35
|
readonly "counts/sec": UnitConfig;
|
|
35
36
|
readonly "events/sec": UnitConfig;
|
|
36
37
|
readonly "messages/sec": UnitConfig;
|
|
@@ -42,6 +43,7 @@ export declare const UNIT_CONFIG: {
|
|
|
42
43
|
readonly "rows/sec": UnitConfig;
|
|
43
44
|
readonly "writes/sec": UnitConfig;
|
|
44
45
|
readonly bytes: UnitConfig;
|
|
46
|
+
readonly decbytes: UnitConfig;
|
|
45
47
|
readonly decimal: UnitConfig;
|
|
46
48
|
readonly percent: UnitConfig;
|
|
47
49
|
readonly "percent-decimal": UnitConfig;
|
|
@@ -1 +1 @@
|
|
|
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;AACtB,OAAO,EAA+D,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEhH;;;;;;GAMG;AAEH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAO1E,CAAC;AACF,eAAO,MAAM,WAAW
|
|
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;AACtB,OAAO,EAA+D,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEhH;;;;;;GAMG;AAEH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAO1E,CAAC;AACF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOd,CAAC;AAEX,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,uBAAuB,GACvB,qBAAqB,CAAC;AAE1B,KAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAC9F,KAAK,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,CA+BhF;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,UAAU,CAGtE;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;AAED,wBAAgB,cAAc,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,qBAAqB,CAEnG"}
|
package/dist/utils/fetch.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Calls `
|
|
2
|
+
* Calls `globalThis.fetch` and determines which type of error to show for non-200 responses.
|
|
3
3
|
*/
|
|
4
|
-
export declare function fetch(...args: Parameters<typeof
|
|
4
|
+
export declare function fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response>;
|
|
5
5
|
/**
|
|
6
|
-
* Calls `
|
|
6
|
+
* Calls `globalThis.fetch` and throws a `FetchError` on non-200 responses, but also
|
|
7
7
|
* decodes the response body as JSON, casting it to type `T`. Returns the
|
|
8
8
|
* decoded body.
|
|
9
9
|
*/
|
|
10
|
-
export declare function fetchJson<T>(...args: Parameters<typeof
|
|
10
|
+
export declare function fetchJson<T>(...args: Parameters<typeof globalThis.fetch>): Promise<T>;
|
|
11
11
|
export interface StatusError extends Error {
|
|
12
12
|
status: number;
|
|
13
13
|
}
|
|
@@ -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,
|
|
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,UAAU,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAqB3F;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM3F;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAM,YAAW,WAAW;IAC1D,MAAM,EAAE,MAAM,CAAC;gBACH,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;CAKzC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAM,YAAW,WAAW;IACjE,MAAM,EAAE,MAAM,CAAC;gBACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK5C"}
|
package/dist/utils/fetch.js
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
/**
|
|
14
|
-
* Calls `
|
|
14
|
+
* Calls `globalThis.fetch` and determines which type of error to show for non-200 responses.
|
|
15
15
|
*/ export async function fetch(...args) {
|
|
16
|
-
const response = await
|
|
16
|
+
const response = await globalThis.fetch(...args);
|
|
17
17
|
if (response.ok === false) {
|
|
18
18
|
const contentType = response.headers.get('content-type');
|
|
19
19
|
if (contentType?.includes('application/json')) {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
return response;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Calls `
|
|
37
|
+
* Calls `globalThis.fetch` and throws a `FetchError` on non-200 responses, but also
|
|
38
38
|
* decodes the response body as JSON, casting it to type `T`. Returns the
|
|
39
39
|
* decoded body.
|
|
40
40
|
*/ export async function fetchJson(...args) {
|
package/dist/utils/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/fetch.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Calls `
|
|
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 `globalThis.fetch` and determines which type of error to show for non-200 responses.\n */\nexport async function fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response> {\n const response = await globalThis.fetch(...args);\n if (response.ok === false) {\n const contentType = response.headers.get('content-type');\n if (contentType?.includes('application/json')) {\n const json = await response.clone().json();\n if (json.error) {\n throw new UserFriendlyError(json.error, response.status);\n }\n if (json.message) {\n throw new UserFriendlyError(json.message, response.status);\n }\n }\n\n const text = await response.clone().text();\n if (text) {\n throw new UserFriendlyError(text, response.status);\n }\n throw new FetchError(response);\n }\n return response;\n}\n\n/**\n * Calls `globalThis.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 globalThis.fetch>): Promise<T> {\n const response = await fetch(...args);\n if (!response.ok) {\n throw new FetchError(response);\n }\n return await response.json();\n}\n\nexport interface StatusError extends Error {\n status: number;\n}\n\n/**\n * Error thrown when fetch returns a non-200 response.\n */\nexport class FetchError extends Error implements StatusError {\n status: number;\n constructor(response: Readonly<Response>) {\n super(`${response.status} ${response.statusText}`);\n this.status = response.status;\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 implements StatusError {\n status: number;\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n Object.setPrototypeOf(this, UserFriendlyError.prototype);\n }\n}\n"],"names":["fetch","args","response","globalThis","ok","contentType","headers","get","includes","json","clone","error","UserFriendlyError","status","message","text","FetchError","fetchJson","Error","constructor","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,IAAyC;IACtE,MAAMC,WAAW,MAAMC,WAAWH,KAAK,IAAIC;IAC3C,IAAIC,SAASE,EAAE,KAAK,OAAO;QACzB,MAAMC,cAAcH,SAASI,OAAO,CAACC,GAAG,CAAC;QACzC,IAAIF,aAAaG,SAAS,qBAAqB;YAC7C,MAAMC,OAAO,MAAMP,SAASQ,KAAK,GAAGD,IAAI;YACxC,IAAIA,KAAKE,KAAK,EAAE;gBACd,MAAM,IAAIC,kBAAkBH,KAAKE,KAAK,EAAET,SAASW,MAAM;YACzD;YACA,IAAIJ,KAAKK,OAAO,EAAE;gBAChB,MAAM,IAAIF,kBAAkBH,KAAKK,OAAO,EAAEZ,SAASW,MAAM;YAC3D;QACF;QAEA,MAAME,OAAO,MAAMb,SAASQ,KAAK,GAAGK,IAAI;QACxC,IAAIA,MAAM;YACR,MAAM,IAAIH,kBAAkBG,MAAMb,SAASW,MAAM;QACnD;QACA,MAAM,IAAIG,WAAWd;IACvB;IACA,OAAOA;AACT;AAEA;;;;CAIC,GACD,OAAO,eAAee,UAAa,GAAGhB,IAAyC;IAC7E,MAAMC,WAAW,MAAMF,SAASC;IAChC,IAAI,CAACC,SAASE,EAAE,EAAE;QAChB,MAAM,IAAIY,WAAWd;IACvB;IACA,OAAO,MAAMA,SAASO,IAAI;AAC5B;AAMA;;CAEC,GACD,OAAO,MAAMO,mBAAmBE;IAC9BL,OAAe;IACfM,YAAYjB,QAA4B,CAAE;QACxC,KAAK,CAAC,GAAGA,SAASW,MAAM,CAAC,CAAC,EAAEX,SAASkB,UAAU,EAAE;QACjD,IAAI,CAACP,MAAM,GAAGX,SAASW,MAAM;QAC7BQ,OAAOC,cAAc,CAAC,IAAI,EAAEN,WAAWO,SAAS;IAClD;AACF;AAEA;;CAEC,GACD,OAAO,MAAMX,0BAA0BM;IACrCL,OAAe;IACfM,YAAYL,OAAe,EAAED,MAAc,CAAE;QAC3C,KAAK,CAACC;QACN,IAAI,CAACD,MAAM,GAAGA;QACdQ,OAAOC,cAAc,CAAC,IAAI,EAAEV,kBAAkBW,SAAS;IACzD;AACF"}
|
package/package.json
CHANGED