@prorobotech/openapi-k8s-toolkit 1.2.0-alpha.3 → 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.
@@ -44922,11 +44922,6 @@ const toBytes = (value, from) => {
44922
44922
  const factor = UNIT_FACTORS[canon];
44923
44923
  return value * factor;
44924
44924
  };
44925
- const convertStorage = (value, from, to, opts) => {
44926
- const bytes = toBytes(value, from);
44927
- if (bytes < 0) return -1;
44928
- return convertBytes(bytes, to, opts);
44929
- };
44930
44925
  const parseValueWithUnit = (input) => {
44931
44926
  const trimmed = input.trim();
44932
44927
  if (!trimmed) return null;
@@ -44967,30 +44962,67 @@ const ConverterBytes = ({ data }) => {
44967
44962
  /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
44968
44963
  ] });
44969
44964
  }
44970
- const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value2, index) => {
44971
- acc[index.toString()] = value2;
44965
+ const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
44966
+ acc[index.toString()] = value;
44972
44967
  return acc;
44973
44968
  }, {});
44974
- const parsedBytesValue = parseAll({ text: bytesValue, replaceValues, multiQueryData });
44975
- const parsedWithUnit = parseValueWithUnit(parsedBytesValue);
44976
- if (!parsedWithUnit) {
44977
- const fallbackNumber = Number(parsedBytesValue);
44978
- if (Number.isNaN(fallbackNumber)) {
44979
- return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
44980
- }
44981
- if (unit) {
44982
- const result3 = String(convertBytes(fallbackNumber, unit, { format, precision, locale }));
44969
+ const byteValueItems = Array.isArray(bytesValue) ? bytesValue : [bytesValue];
44970
+ const resolvedStrings = byteValueItems.map((text) => parseAll({ text, replaceValues, multiQueryData }));
44971
+ if (resolvedStrings.length === 0) {
44972
+ const targetUnit2 = toUnit || unit;
44973
+ if (targetUnit2) {
44974
+ const result3 = String(
44975
+ convertBytes(0, targetUnit2, {
44976
+ format,
44977
+ precision,
44978
+ locale
44979
+ })
44980
+ );
44983
44981
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result3 });
44984
44982
  }
44985
- const result2 = formatBytesAuto(fallbackNumber, { standard, precision, locale });
44983
+ const result2 = formatBytesAuto(0, { standard, precision, locale });
44986
44984
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result2 });
44987
44985
  }
44988
- const { value, unit: inlineUnit } = parsedWithUnit;
44989
- const effectiveFromUnit = fromUnit || inlineUnit;
44986
+ let totalBytes = 0;
44987
+ for (const s of resolvedStrings) {
44988
+ const parsed = parseValueWithUnit(s);
44989
+ let numericValue;
44990
+ let inlineUnit;
44991
+ if (parsed) {
44992
+ numericValue = parsed.value;
44993
+ inlineUnit = parsed.unit;
44994
+ } else {
44995
+ const fallbackNumber = Number(s);
44996
+ if (Number.isNaN(fallbackNumber)) {
44997
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
44998
+ }
44999
+ numericValue = fallbackNumber;
45000
+ inlineUnit = void 0;
45001
+ }
45002
+ const fromForThis = fromUnit || inlineUnit || "B";
45003
+ let bytesForThis;
45004
+ if (fromForThis === "B") {
45005
+ if (!Number.isFinite(numericValue)) {
45006
+ console.error("bytes must be a finite number");
45007
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45008
+ }
45009
+ if (numericValue < 0) {
45010
+ console.error("bytes must be >= 0");
45011
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45012
+ }
45013
+ bytesForThis = numericValue;
45014
+ } else {
45015
+ bytesForThis = toBytes(numericValue, fromForThis);
45016
+ if (bytesForThis < 0) {
45017
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45018
+ }
45019
+ }
45020
+ totalBytes += bytesForThis;
45021
+ }
44990
45022
  const targetUnit = toUnit || unit;
44991
- if (effectiveFromUnit && targetUnit) {
45023
+ if (targetUnit) {
44992
45024
  const result2 = String(
44993
- convertStorage(value, effectiveFromUnit, targetUnit, {
45025
+ convertBytes(totalBytes, targetUnit, {
44994
45026
  format,
44995
45027
  precision,
44996
45028
  locale
@@ -44998,19 +45030,203 @@ const ConverterBytes = ({ data }) => {
44998
45030
  );
44999
45031
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result2 });
45000
45032
  }
45001
- if (effectiveFromUnit && !targetUnit) {
45002
- const bytes = toBytes(value, effectiveFromUnit);
45003
- if (bytes < 0) {
45004
- return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45033
+ const result = formatBytesAuto(totalBytes, { standard, precision, locale });
45034
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result });
45035
+ };
45036
+
45037
+ const CORE_UNIT_FACTORS = {
45038
+ core: 1,
45039
+ mcore: 1e-3,
45040
+ ucore: 1e-6,
45041
+ ncore: 1e-9
45042
+ };
45043
+ const CORE_ALIASES = (() => {
45044
+ const corePairs = [
45045
+ // plain cores
45046
+ [["core", "cores", "c", "cpu", "cpus", "vcpu", "vcpus"], "core"],
45047
+ // millicores
45048
+ [["m", "mc", "mcore", "mcores", "millicore", "millicores", "millicpu", "millicpus"], "mcore"],
45049
+ // microcores
45050
+ [["u", "µ", "ucore", "ucores", "micro", "microcore", "microcores"], "ucore"],
45051
+ // nanocores
45052
+ [["n", "ncore", "ncores", "nano", "nanocore", "nanocores"], "ncore"]
45053
+ ];
45054
+ const entries = corePairs.flatMap(([keys, unit]) => keys.map((k) => [k.toLowerCase(), unit]));
45055
+ const canon = Object.keys(CORE_UNIT_FACTORS).map((u) => [u.toLowerCase(), u]);
45056
+ return Object.fromEntries([...entries, ...canon]);
45057
+ })();
45058
+ const normalizeCoreUnit = (u) => {
45059
+ const key = String(u).trim().toLowerCase();
45060
+ const canon = CORE_ALIASES[key];
45061
+ if (!canon) {
45062
+ console.error(`Unknown core unit: "${u}"`);
45063
+ return "core";
45064
+ }
45065
+ return canon;
45066
+ };
45067
+ const convertCores = (cores, unit, opts) => {
45068
+ if (!Number.isFinite(cores)) {
45069
+ console.error("cores must be a finite number");
45070
+ return -1;
45071
+ }
45072
+ if (cores < 0) {
45073
+ console.error("cores must be >= 0");
45074
+ return -1;
45075
+ }
45076
+ const canon = normalizeCoreUnit(unit);
45077
+ const factor = CORE_UNIT_FACTORS[canon];
45078
+ const value = cores / factor;
45079
+ if (!opts?.format) return value;
45080
+ return `${value.toLocaleString(opts.locale, {
45081
+ minimumFractionDigits: 0,
45082
+ maximumFractionDigits: opts?.precision ?? 2
45083
+ })} ${canon}`;
45084
+ };
45085
+ const formatCoresAuto = (cores, { precision = 2, locale } = {}) => {
45086
+ if (!Number.isFinite(cores)) {
45087
+ console.error("cores must be a finite number");
45088
+ return "infinite";
45089
+ }
45090
+ if (cores < 0) {
45091
+ console.error("cores must be >= 0");
45092
+ return "less then zero";
45093
+ }
45094
+ if (cores === 0) {
45095
+ return "0 core";
45096
+ }
45097
+ let targetUnit;
45098
+ if (cores >= 1) {
45099
+ targetUnit = "core";
45100
+ } else if (cores >= 1e-3) {
45101
+ targetUnit = "mcore";
45102
+ } else if (cores >= 1e-6) {
45103
+ targetUnit = "ucore";
45104
+ } else {
45105
+ targetUnit = "ncore";
45106
+ }
45107
+ return String(convertCores(cores, targetUnit, { format: true, precision, locale }));
45108
+ };
45109
+ const toCores = (value, from) => {
45110
+ if (!Number.isFinite(value)) {
45111
+ console.error("value must be a finite number");
45112
+ return -1;
45113
+ }
45114
+ if (value < 0) {
45115
+ console.error("value must be >= 0");
45116
+ return -1;
45117
+ }
45118
+ const canon = normalizeCoreUnit(from);
45119
+ const factor = CORE_UNIT_FACTORS[canon];
45120
+ return value * factor;
45121
+ };
45122
+ const parseCoresWithUnit = (input) => {
45123
+ const trimmed = input.trim();
45124
+ if (!trimmed) return null;
45125
+ const match = trimmed.match(/^([+-]?\d+(?:\.\d+)?)(?:\s*([a-zA-Zµ]+))?$/);
45126
+ if (!match) return null;
45127
+ const [, numPart, unitPart] = match;
45128
+ const value = Number(numPart);
45129
+ if (!Number.isFinite(value)) return null;
45130
+ if (unitPart) {
45131
+ return { value, unit: unitPart };
45132
+ }
45133
+ return { value };
45134
+ };
45135
+
45136
+ const ConverterCores = ({ data }) => {
45137
+ const {
45138
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45139
+ id,
45140
+ coresValue,
45141
+ unit,
45142
+ fromUnit,
45143
+ toUnit,
45144
+ format,
45145
+ precision,
45146
+ locale,
45147
+ notANumberText,
45148
+ style
45149
+ } = data;
45150
+ const { data: multiQueryData, isLoading, isError, errors } = useMultiQuery();
45151
+ const partsOfUrl = usePartsOfUrl();
45152
+ if (isLoading) {
45153
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading..." });
45154
+ }
45155
+ if (isError) {
45156
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
45157
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
45158
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
45159
+ ] });
45160
+ }
45161
+ const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
45162
+ acc[index.toString()] = value;
45163
+ return acc;
45164
+ }, {});
45165
+ const coreValueItems = Array.isArray(coresValue) ? coresValue : [coresValue];
45166
+ const resolvedStrings = coreValueItems.map((text) => parseAll({ text, replaceValues, multiQueryData }));
45167
+ if (resolvedStrings.length === 0) {
45168
+ const targetUnit2 = toUnit || unit;
45169
+ if (targetUnit2) {
45170
+ const result3 = String(
45171
+ convertCores(0, targetUnit2, {
45172
+ format,
45173
+ precision,
45174
+ locale
45175
+ })
45176
+ );
45177
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result3 });
45005
45178
  }
45006
- const result2 = formatBytesAuto(bytes, { standard, precision, locale });
45179
+ const result2 = formatCoresAuto(0, { precision, locale });
45007
45180
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result2 });
45008
45181
  }
45182
+ let totalCores = 0;
45183
+ for (const s of resolvedStrings) {
45184
+ const parsed = parseCoresWithUnit(s);
45185
+ let numericValue;
45186
+ let inlineUnit;
45187
+ if (parsed) {
45188
+ numericValue = parsed.value;
45189
+ inlineUnit = parsed.unit;
45190
+ } else {
45191
+ const fallbackNumber = Number(s);
45192
+ if (Number.isNaN(fallbackNumber)) {
45193
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45194
+ }
45195
+ numericValue = fallbackNumber;
45196
+ inlineUnit = void 0;
45197
+ }
45198
+ const fromForThis = fromUnit || inlineUnit || "core";
45199
+ let coresForThis;
45200
+ if (fromForThis === "core") {
45201
+ if (!Number.isFinite(numericValue)) {
45202
+ console.error("cores must be a finite number");
45203
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45204
+ }
45205
+ if (numericValue < 0) {
45206
+ console.error("cores must be >= 0");
45207
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45208
+ }
45209
+ coresForThis = numericValue;
45210
+ } else {
45211
+ coresForThis = toCores(numericValue, fromForThis);
45212
+ if (coresForThis < 0) {
45213
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: notANumberText || "Not a proper value" });
45214
+ }
45215
+ }
45216
+ totalCores += coresForThis;
45217
+ }
45218
+ const targetUnit = toUnit || unit;
45009
45219
  if (targetUnit) {
45010
- const result2 = String(convertBytes(value, targetUnit, { format, precision, locale }));
45220
+ const result2 = String(
45221
+ convertCores(totalCores, targetUnit, {
45222
+ format,
45223
+ precision,
45224
+ locale
45225
+ })
45226
+ );
45011
45227
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result2 });
45012
45228
  }
45013
- const result = formatBytesAuto(value, { standard, precision, locale });
45229
+ const result = formatCoresAuto(totalCores, { precision, locale });
45014
45230
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style, children: result });
45015
45231
  };
45016
45232
 
@@ -46649,6 +46865,7 @@ const DynamicComponents = {
46649
46865
  Tolerations,
46650
46866
  Annotations,
46651
46867
  ConverterBytes,
46868
+ ConverterCores,
46652
46869
  SecretBase64Plain,
46653
46870
  ResourceBadge,
46654
46871
  Events: Events$1,