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