@prorobotech/openapi-k8s-toolkit 1.2.0-alpha.2 → 1.2.0-alpha.4

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.
@@ -1,5 +1,18 @@
1
1
  import { FC } from 'react';
2
2
  import { TDynamicComponentsAppTypeMap } from '../../types';
3
+ /**
4
+ * Idea (extended for arrays):
5
+ * 1. bytesValue may be:
6
+ * - "1234567890" → raw number (bytes)
7
+ * - "12312312Ki" → number + source unit
8
+ * - ["10GiB", "512Mi", "1024"] → array; all converted to bytes, summed, then formatted
9
+ * 2. Each entry is resolved via parseAll, then parsed with parseValueWithUnit.
10
+ * 3. Each value is converted to base bytes (respecting fromUnit override).
11
+ * 4. All bytes are summed into totalBytes.
12
+ * 5. Finally:
13
+ * - If there’s a target unit (unit or toUnit), we convert totalBytes to that.
14
+ * - If not, we auto-scale totalBytes with formatBytesAuto.
15
+ */
3
16
  export declare const ConverterBytes: FC<{
4
17
  data: TDynamicComponentsAppTypeMap['ConverterBytes'];
5
18
  }>;
@@ -1,5 +1,5 @@
1
1
  export type TCanonicalUnit = 'B' | 'kB' | 'MB' | 'GB' | 'TB' | 'PB' | 'EB' | 'KiB' | 'MiB' | 'GiB' | 'TiB' | 'PiB' | 'EiB';
2
- export type TUnitInput = TCanonicalUnit | 'k' | 'm' | 'g' | 't' | 'p' | 'e' | 'K' | 'M' | 'G' | 'T' | 'P' | 'E' | 'KB' | 'Mb' | 'MB' | 'Gb' | 'GB' | 'Tb' | 'TB' | 'Pb' | 'PB' | 'Eb' | 'EB' | 'Ki' | 'Mi' | 'Gi' | 'Ti' | 'Pi' | 'Ei' | 'KiB' | 'MiB' | 'GiB' | 'TiB' | 'PiB' | 'EiB';
2
+ export type TUnitInput = TCanonicalUnit | 'b' | 'byte' | 'bytes' | 'k' | 'm' | 'g' | 't' | 'p' | 'e' | 'K' | 'M' | 'G' | 'T' | 'P' | 'E' | 'kb' | 'KB' | 'mb' | 'Mb' | 'MB' | 'gb' | 'Gb' | 'GB' | 'tb' | 'Tb' | 'TB' | 'pb' | 'Pb' | 'PB' | 'eb' | 'Eb' | 'EB' | 'ki' | 'mi' | 'gi' | 'ti' | 'pi' | 'ei' | 'kib' | 'mib' | 'gib' | 'tib' | 'pib' | 'eib' | 'Ki' | 'Mi' | 'Gi' | 'Ti' | 'Pi' | 'Ei' | 'KiB' | 'MiB' | 'GiB' | 'TiB' | 'PiB' | 'EiB';
3
3
  export type TConvertOptions = {
4
4
  /** If true, returns "12.3 GiB" instead of just 12.3 */
5
5
  format?: boolean;
@@ -13,3 +13,20 @@ export declare const formatBytesAuto: (bytes: number, options?: {
13
13
  precision?: number;
14
14
  locale?: string;
15
15
  }) => string;
16
+ /** Internal helper: convert value in given unit -> bytes (number) */
17
+ export declare const toBytes: (value: number, from: TUnitInput) => number;
18
+ /**
19
+ * Generic helper: convert value in some unit -> target unit.
20
+ * Uses bytes as intermediate.
21
+ */
22
+ export declare const convertStorage: (value: number, from: TUnitInput, to: TUnitInput, opts?: TConvertOptions) => number | string;
23
+ /**
24
+ * Try to parse a string like:
25
+ * "12312312Ki"
26
+ * " 12.5 GiB"
27
+ * "1000" (no unit -> unit undefined)
28
+ */
29
+ export declare const parseValueWithUnit: (input: string) => {
30
+ value: number;
31
+ unit?: TUnitInput | undefined;
32
+ } | null;
@@ -0,0 +1,19 @@
1
+ import { FC } from 'react';
2
+ import { TDynamicComponentsAppTypeMap } from '../../types';
3
+ /**
4
+ * Idea (extended for arrays):
5
+ * 1. coresValue may be:
6
+ * - "0.5" → raw number (cores)
7
+ * - "500m" → number + source unit (millicores)
8
+ * - "2 vcpu" → number + alias for "core"
9
+ * - ["500m", "0.5 core", "1"] → array of such values
10
+ * 2. Each entry is resolved via parseAll, then parsed with parseCoresWithUnit.
11
+ * 3. Each value is converted to base "cores" (respecting fromUnit override).
12
+ * 4. All cores are summed into totalCores.
13
+ * 5. Finally:
14
+ * - If there’s a target unit (unit or toUnit), we convert totalCores to that.
15
+ * - Otherwise, we auto-scale totalCores with formatCoresAuto.
16
+ */
17
+ export declare const ConverterCores: FC<{
18
+ data: TDynamicComponentsAppTypeMap['ConverterCores'];
19
+ }>;
@@ -0,0 +1 @@
1
+ export { ConverterCores } from './ConverterCores';
@@ -0,0 +1,7 @@
1
+ export type TCoreCanonicalUnit = 'core' | 'mcore' | 'ucore' | 'ncore';
2
+ export type TCoreUnitInput = string | TCoreCanonicalUnit;
3
+ export type TCoreConvertOptions = {
4
+ format?: boolean;
5
+ precision?: number;
6
+ locale?: string;
7
+ };
@@ -0,0 +1,45 @@
1
+ import type { TCoreUnitInput, TCoreConvertOptions } from './types';
2
+ /**
3
+ * Convert cores -> target unit (core/mcore/ucore/ncore).
4
+ * The input `cores` is ALWAYS in **cores** (base unit).
5
+ *
6
+ * @returns number by default (e.g., 0.5 -> 500 when unit="mcore"),
7
+ * or "500 mcore" if format=true
8
+ */
9
+ export declare const convertCores: (cores: number, unit: TCoreUnitInput, opts?: TCoreConvertOptions) => number | string;
10
+ /**
11
+ * Auto-scale cores across core/mcore/ucore/ncore.
12
+ *
13
+ * - cores >= 1 -> core
14
+ * - 1e-3 <= cores < 1 -> mcore
15
+ * - 1e-6 <= cores < 1e-3 -> ucore
16
+ * - cores < 1e-6 -> ncore
17
+ */
18
+ export declare const formatCoresAuto: (cores: number, options?: {
19
+ precision?: number;
20
+ locale?: string;
21
+ }) => string;
22
+ /** Internal helper: convert value in given unit -> cores (number). */
23
+ export declare const toCores: (value: number, from: TCoreUnitInput) => number;
24
+ /**
25
+ * Generic helper: convert value in some unit -> target unit.
26
+ * Uses cores as intermediate.
27
+ *
28
+ * Examples:
29
+ * convertCompute(500, "m", "core") // 0.5
30
+ * convertCompute(2, "core", "m", {format: true}) // "2,000 mcore" (or locale variant)
31
+ * convertCompute(1_000_000, "n", "core") // 0.001
32
+ */
33
+ export declare const convertCompute: (value: number, from: TCoreUnitInput, to: TCoreUnitInput, opts?: TCoreConvertOptions) => number | string;
34
+ /**
35
+ * Try to parse a string like:
36
+ * "500m"
37
+ * " 0.5 core"
38
+ * "2 vcpu"
39
+ * "1000000n"
40
+ * "1.5" (no unit -> unit undefined, treated as raw number-of-cores upstream)
41
+ */
42
+ export declare const parseCoresWithUnit: (input: string) => {
43
+ value: number;
44
+ unit?: string | undefined;
45
+ } | null;
@@ -31,6 +31,7 @@ export { Taints } from './Taints';
31
31
  export { Tolerations } from './Tolerations';
32
32
  export { Annotations } from './Annotations';
33
33
  export { ConverterBytes } from './ConverterBytes';
34
+ export { ConverterCores } from './ConverterCores';
34
35
  export { SecretBase64Plain } from './SecretBase64Plain';
35
36
  export { ResourceBadge } from './ResourceBadge';
36
37
  export { Events } from './Events';
@@ -5,6 +5,7 @@ import type { LinkProps } from 'antd/es/typography/Link';
5
5
  import type { TContentCardProps, TSpacerProps } from '../../atoms';
6
6
  import type { TManageableSidebarProviderProps, TEnrichedTableProviderProps } from '../../molecules';
7
7
  import type { TUnitInput } from './molecules/ConverterBytes/types';
8
+ import type { TCoreUnitInput } from './molecules/ConverterCores/types';
8
9
  export type TDynamicComponentsAppTypeMap = {
9
10
  DefaultDiv: {
10
11
  id: number | string;
@@ -282,7 +283,7 @@ export type TDynamicComponentsAppTypeMap = {
282
283
  };
283
284
  ConverterBytes: {
284
285
  id: number | string;
285
- bytesValue: string;
286
+ bytesValue: string | string[];
286
287
  unit?: TUnitInput;
287
288
  /** If true, returns "12.3 GiB" instead of just 12.3 */
288
289
  format?: boolean;
@@ -293,6 +294,29 @@ export type TDynamicComponentsAppTypeMap = {
293
294
  standard?: 'si' | 'iec';
294
295
  notANumberText?: string;
295
296
  style?: CSSProperties;
297
+ /** If provided, value is in this unit instead of raw bytes */
298
+ fromUnit?: TUnitInput;
299
+ /** If provided, convert to this explicit unit */
300
+ toUnit?: TUnitInput;
301
+ };
302
+ ConverterCores: {
303
+ id: number | string;
304
+ /** Raw text that may contain a number or number+unit like "0.5", "500m", "2 vcpu" */
305
+ coresValue: string | string[];
306
+ /** Target unit; omit to auto format (core vs mcore) */
307
+ unit?: TCoreUnitInput;
308
+ /** If true, returns "500 mcore" instead of just 500 */
309
+ format?: boolean;
310
+ /** Max fraction digits when formatting (default 2) */
311
+ precision?: number;
312
+ /** Locale for number formatting (default: undefined => user agent) */
313
+ locale?: string;
314
+ notANumberText?: string;
315
+ style?: CSSProperties;
316
+ /** If provided, value is in this unit instead of raw "cores" */
317
+ fromUnit?: TCoreUnitInput;
318
+ /** If provided, convert to this explicit unit; omit for auto-format */
319
+ toUnit?: TCoreUnitInput;
296
320
  };
297
321
  SecretBase64Plain: {
298
322
  id: number | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prorobotech/openapi-k8s-toolkit",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0-alpha.4",
4
4
  "description": "ProRobotech OpenAPI k8s tools",
5
5
  "main": "dist/openapi-k8s-toolkit.cjs.js",
6
6
  "module": "dist/openapi-k8s-toolkit.es.js",