@prorobotech/openapi-k8s-toolkit 1.1.0-alpha.2 → 1.1.0-alpha.3

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.
@@ -33608,49 +33608,95 @@
33608
33608
  };
33609
33609
 
33610
33610
  const MultiQueryContext = K.createContext(void 0);
33611
- const MultiQueryProvider = ({ urls, dataToApplyToContext, children }) => {
33612
- const queries = reactQuery.useQueries({
33613
- queries: urls.map((url, index) => ({
33614
- queryKey: ["multi", index, url],
33611
+ const makeEmptyEntry = () => ({
33612
+ data: void 0,
33613
+ isLoading: false,
33614
+ isError: false,
33615
+ error: null
33616
+ });
33617
+ const aggReducer = (state, action) => {
33618
+ switch (action.type) {
33619
+ case "RESET":
33620
+ return { entries: Array.from({ length: action.total }, makeEmptyEntry) };
33621
+ case "SET_ENTRY": {
33622
+ const entries = state.entries.slice();
33623
+ entries[action.index] = action.entry;
33624
+ return { entries };
33625
+ }
33626
+ default:
33627
+ return state;
33628
+ }
33629
+ };
33630
+ const K8sFetcher = ({ index, params, dispatch }) => {
33631
+ const res = useK8sSmartResource(params);
33632
+ K.useEffect(() => {
33633
+ dispatch({
33634
+ type: "SET_ENTRY",
33635
+ index,
33636
+ entry: {
33637
+ data: res.data,
33638
+ isLoading: res.isLoading,
33639
+ isError: res.isError,
33640
+ error: res.error ?? null
33641
+ }
33642
+ });
33643
+ }, [index, res.data, res.isLoading, res.isError, res.error, dispatch]);
33644
+ return null;
33645
+ };
33646
+ const MultiQueryProvider = ({ items, dataToApplyToContext, children }) => {
33647
+ const k8sItems = K.useMemo(
33648
+ () => items.filter((x) => typeof x !== "string"),
33649
+ [items]
33650
+ );
33651
+ const urlItems = K.useMemo(() => items.filter((x) => typeof x === "string"), [items]);
33652
+ const k8sCount = k8sItems.length;
33653
+ const urlCount = urlItems.length;
33654
+ const [state, dispatch] = K.useReducer(aggReducer, { entries: Array.from({ length: k8sCount }, makeEmptyEntry) });
33655
+ K.useEffect(() => {
33656
+ dispatch({ type: "RESET", total: k8sCount });
33657
+ }, [k8sCount]);
33658
+ const urlQueries = reactQuery.useQueries({
33659
+ queries: urlItems.map((url, i) => ({
33660
+ queryKey: ["multi-url", i, url],
33615
33661
  queryFn: async () => {
33616
- const response = await axios.get(url);
33617
- return response.data;
33662
+ const res = await axios.get(url);
33663
+ return res.data;
33618
33664
  }
33619
33665
  }))
33620
33666
  });
33621
- const data = {};
33622
- const errors = [];
33623
- let isLoading;
33624
- let isError;
33625
- if (!dataToApplyToContext) {
33626
- queries.forEach((q, i) => {
33627
- data[`req${i}`] = q.data;
33628
- errors[i] = q.error ?? null;
33629
- });
33630
- isLoading = queries.some((q) => q.isLoading);
33631
- isError = queries.some((q) => q.isError);
33632
- } else {
33633
- data.req0 = dataToApplyToContext;
33634
- isLoading = false;
33635
- isError = false;
33636
- }
33637
- const value = K.useMemo(
33638
- () => ({ data, isLoading, isError, errors }),
33639
- /*
33640
- We use JSON.stringify(data) and JSON.stringify(errors) as dependencies to safely memoize when values deeply change (since data is a new object every render).
33641
- Alternatively, you could use a deep comparison hook or lodash.isEqual if needed.
33642
- */
33643
- // eslint-disable-next-line react-hooks/exhaustive-deps
33644
- [JSON.stringify(data), isLoading, isError, JSON.stringify(errors)]
33645
- );
33646
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MultiQueryContext.Provider, { value, children });
33667
+ const value = K.useMemo(() => {
33668
+ if (typeof dataToApplyToContext !== "undefined") {
33669
+ return { data: { req0: dataToApplyToContext }, isLoading: false, isError: false, errors: [] };
33670
+ }
33671
+ const data = {};
33672
+ const errors = [];
33673
+ for (let i = 0; i < k8sCount; i++) {
33674
+ const e = state.entries[i] ?? makeEmptyEntry();
33675
+ data[`req${i}`] = e.data;
33676
+ errors[i] = e.isError ? e.error : null;
33677
+ }
33678
+ for (let i = 0; i < urlCount; i++) {
33679
+ const q = urlQueries[i];
33680
+ const idx = k8sCount + i;
33681
+ data[`req${idx}`] = q?.data;
33682
+ errors[idx] = q?.isError ? q.error ?? null : null;
33683
+ }
33684
+ const isLoading = state.entries.some((e) => e.isLoading) || urlQueries.some((q) => q.isLoading);
33685
+ const isError = state.entries.some((e) => e.isError) || urlQueries.some((q) => q.isError);
33686
+ return { data, isLoading, isError, errors };
33687
+ }, [dataToApplyToContext, k8sCount, urlCount, state.entries, urlQueries]);
33688
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(MultiQueryContext.Provider, { value, children: [
33689
+ k8sItems.map((params, i) => (
33690
+ // eslint-disable-next-line react/no-array-index-key
33691
+ /* @__PURE__ */ jsxRuntimeExports.jsx(K8sFetcher, { index: i, params, dispatch }, i)
33692
+ )),
33693
+ children
33694
+ ] });
33647
33695
  };
33648
33696
  const useMultiQuery = () => {
33649
- const context = K.useContext(MultiQueryContext);
33650
- if (!context) {
33651
- throw new Error("useMultiQuery must be used within a MultiQueryProvider");
33652
- }
33653
- return context;
33697
+ const ctx = K.useContext(MultiQueryContext);
33698
+ if (!ctx) throw new Error("useMultiQuery must be used within a MultiQueryProvider");
33699
+ return ctx;
33654
33700
  };
33655
33701
 
33656
33702
  const createContextFactory = () => {
@@ -33878,7 +33924,7 @@
33878
33924
  if (isError) {
33879
33925
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
33880
33926
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
33881
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
33927
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
33882
33928
  ] });
33883
33929
  }
33884
33930
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: preparedText });
@@ -33908,7 +33954,7 @@
33908
33954
  if (isError) {
33909
33955
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
33910
33956
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
33911
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
33957
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
33912
33958
  ] });
33913
33959
  }
33914
33960
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -33945,7 +33991,7 @@
33945
33991
  if (isError) {
33946
33992
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
33947
33993
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
33948
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
33994
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
33949
33995
  ] });
33950
33996
  }
33951
33997
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ProjectInfoCard, { clusterName, namespace, accessGroups: parsedAccessGroups, ...props, children });
@@ -34062,7 +34108,7 @@
34062
34108
  if (isError) {
34063
34109
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34064
34110
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34065
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34111
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34066
34112
  ] });
34067
34113
  }
34068
34114
  const { type, text } = getResult({
@@ -34767,7 +34813,7 @@
34767
34813
  if (isMultiQueryErrors) {
34768
34814
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34769
34815
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34770
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34816
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34771
34817
  ] });
34772
34818
  }
34773
34819
  const jsonRoot = multiQueryData[`req${reqIndex}`];
@@ -34834,7 +34880,7 @@
34834
34880
  if (isMultiQueryErrors) {
34835
34881
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34836
34882
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34837
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34883
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34838
34884
  ] });
34839
34885
  }
34840
34886
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -34891,7 +34937,7 @@
34891
34937
  if (isMultiQueryErrors) {
34892
34938
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34893
34939
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34894
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34940
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34895
34941
  ] });
34896
34942
  }
34897
34943
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -35276,7 +35322,7 @@
35276
35322
  if (isMultiQueryErrors) {
35277
35323
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35278
35324
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
35279
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
35325
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
35280
35326
  ] });
35281
35327
  }
35282
35328
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -35551,7 +35597,7 @@
35551
35597
  if (isMultiQueryErrors) {
35552
35598
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35553
35599
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
35554
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
35600
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
35555
35601
  ] });
35556
35602
  }
35557
35603
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -35820,7 +35866,7 @@
35820
35866
  if (isMultiQueryErrors) {
35821
35867
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35822
35868
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
35823
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
35869
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
35824
35870
  ] });
35825
35871
  }
35826
35872
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -36193,7 +36239,7 @@
36193
36239
  if (isMultiQueryErrors) {
36194
36240
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
36195
36241
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
36196
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
36242
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
36197
36243
  ] });
36198
36244
  }
36199
36245
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -36474,7 +36520,7 @@
36474
36520
  if (isMultiQueryErrors) {
36475
36521
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
36476
36522
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
36477
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
36523
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
36478
36524
  ] });
36479
36525
  }
36480
36526
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -36692,7 +36738,7 @@
36692
36738
  if (isError) {
36693
36739
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
36694
36740
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
36695
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
36741
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
36696
36742
  ] });
36697
36743
  }
36698
36744
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -37509,7 +37555,7 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
37509
37555
  if (isError) {
37510
37556
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
37511
37557
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
37512
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
37558
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
37513
37559
  ] });
37514
37560
  }
37515
37561
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -37641,7 +37687,7 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
37641
37687
  if (isError) {
37642
37688
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
37643
37689
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
37644
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
37690
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
37645
37691
  ] });
37646
37692
  }
37647
37693
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value2, index) => {
@@ -37822,13 +37868,30 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
37822
37868
  );
37823
37869
  };
37824
37870
 
37871
+ const STRING_KEYS = ["cluster", "group", "version", "plural", "namespace", "fieldSelector", "labelSelector"];
37825
37872
  const DynamicRendererWithProviders = (props) => {
37826
37873
  const location = reactRouterDom.useLocation();
37827
37874
  const { urlsToFetch, dataToApplyToContext, theme, nodeTerminalDefaultProfile, disableEventBubbling } = props;
37875
+ const directUrls = urlsToFetch.filter((el) => typeof el === "string");
37876
+ const k8sResourcesUrls = urlsToFetch.filter((el) => typeof el !== "string");
37828
37877
  const preparedUrlsToFetch = prepareUrlsToFetchForDynamicRenderer({
37829
- urls: urlsToFetch,
37878
+ urls: directUrls,
37830
37879
  locationPathname: location.pathname
37831
37880
  });
37881
+ const preparedK8sResoucesUrls = k8sResourcesUrls.map((res) => {
37882
+ let next = { ...res };
37883
+ for (const key of STRING_KEYS) {
37884
+ const val = next[key];
37885
+ if (typeof val === "string" && val.length > 0) {
37886
+ const prepared = prepareUrlsToFetchForDynamicRenderer({
37887
+ urls: [val],
37888
+ locationPathname: location.pathname
37889
+ });
37890
+ next = { ...next, [key]: prepared[0] ?? val };
37891
+ }
37892
+ }
37893
+ return next;
37894
+ });
37832
37895
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
37833
37896
  CursorDefaultDiv,
37834
37897
  {
@@ -37838,7 +37901,14 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
37838
37901
  e.stopPropagation();
37839
37902
  }
37840
37903
  },
37841
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FactoryConfigContextProvider, { value: { nodeTerminalDefaultProfile }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PartsOfUrlProvider, { value: { partsOfUrl: location.pathname.split("/") }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(MultiQueryProvider, { urls: preparedUrlsToFetch, dataToApplyToContext, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DynamicRenderer, { ...props }) }) }) }) })
37904
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FactoryConfigContextProvider, { value: { nodeTerminalDefaultProfile }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PartsOfUrlProvider, { value: { partsOfUrl: location.pathname.split("/") }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
37905
+ MultiQueryProvider,
37906
+ {
37907
+ items: [...preparedK8sResoucesUrls, ...preparedUrlsToFetch],
37908
+ dataToApplyToContext,
37909
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(DynamicRenderer, { ...props })
37910
+ }
37911
+ ) }) }) })
37842
37912
  }
37843
37913
  );
37844
37914
  };