@prorobotech/openapi-k8s-toolkit 1.2.0-alpha.8 → 1.2.0-alpha.9

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.
@@ -8802,6 +8802,7 @@
8802
8802
  }) => {
8803
8803
  const resId = `${query.apiGroup ?? ""}|${query.apiVersion}|${query.plural}|${query.namespace ?? ""}|${query.fieldSelector ?? ""}|${query.labelSelector ?? ""}`;
8804
8804
  const resIdRef = K.useRef(resId);
8805
+ const [debugTick, bumpTick] = K.useReducer((x) => x + 1, 0);
8805
8806
  const [state, dispatch] = K.useReducer(reducer$1, { order: [], byKey: {} });
8806
8807
  const [contToken, setContToken] = K.useState();
8807
8808
  const [hasMore, setHasMore] = K.useState(false);
@@ -9049,6 +9050,7 @@
9049
9050
  }
9050
9051
  if (frame.type === "INITIAL") {
9051
9052
  dispatch({ type: "RESET", items: frame.items });
9053
+ bumpTick();
9052
9054
  setContToken(frame.continue);
9053
9055
  setHasMore(Boolean(frame.continue));
9054
9056
  setErrorSafe(void 0);
@@ -9064,6 +9066,7 @@
9064
9066
  }
9065
9067
  if (frame.type === "PAGE") {
9066
9068
  dispatch({ type: "APPEND_PAGE", items: frame.items });
9069
+ bumpTick();
9067
9070
  setContToken(frame.continue);
9068
9071
  setHasMore(Boolean(frame.continue));
9069
9072
  fetchingRef.current = false;
@@ -9086,9 +9089,11 @@
9086
9089
  }
9087
9090
  if (!pausedRef.current) {
9088
9091
  if (frame.type === "ADDED" || frame.type === "MODIFIED") {
9092
+ bumpTick();
9089
9093
  dispatch({ type: "UPSERT", item: frame.item });
9090
9094
  }
9091
9095
  if (!ignoreRemoveRef.current && frame.type === "DELETED") {
9096
+ bumpTick();
9092
9097
  dispatch({ type: "REMOVE", key: eventKey$1(frame.item) });
9093
9098
  }
9094
9099
  }
@@ -9229,7 +9234,8 @@
9229
9234
  drainAll,
9230
9235
  reconnect,
9231
9236
  setUrl,
9232
- setQuery
9237
+ setQuery,
9238
+ debugTick
9233
9239
  };
9234
9240
  };
9235
9241
 
@@ -9320,7 +9326,7 @@
9320
9326
  const watchEnabled = Boolean(
9321
9327
  cluster && cluster.length > 0 && isEnabled && canList && canWatch && !verbsLoading && !verbsIsError
9322
9328
  );
9323
- const { state, status, hasInitial, lastError } = useListWatch({
9329
+ const { state, status, hasInitial, lastError, debugTick } = useListWatch({
9324
9330
  wsUrl: `/api/clusters/${cluster}/openapi-bff-ws/listThenWatch/listWatchWs`,
9325
9331
  paused: false,
9326
9332
  ignoreRemove: false,
@@ -9352,7 +9358,7 @@
9352
9358
  else if (used === "list" && restIsError) error = restError;
9353
9359
  const isError = Boolean(error);
9354
9360
  const data = used === "watch" ? watchData : used === "list" ? restData : void 0;
9355
- return { data, isLoading, isError, error, _meta: { used } };
9361
+ return { data, isLoading, isError, error, _meta: { used }, debugTick };
9356
9362
  };
9357
9363
 
9358
9364
  const hasItemsArray = (value) => {
@@ -9439,22 +9445,98 @@
9439
9445
  return results;
9440
9446
  };
9441
9447
 
9448
+ const checkIfApiInstanceNamespaceScoped = async ({
9449
+ plural,
9450
+ apiGroup,
9451
+ apiVersion,
9452
+ cluster
9453
+ }) => {
9454
+ const payload = {
9455
+ plural,
9456
+ apiGroup,
9457
+ apiVersion,
9458
+ cluster
9459
+ };
9460
+ const { data } = await axios.post(
9461
+ `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfApiNamespaceScoped`,
9462
+ payload
9463
+ );
9464
+ return data;
9465
+ };
9466
+ const checkIfBuiltInInstanceNamespaceScoped = async ({
9467
+ plural,
9468
+ cluster
9469
+ }) => {
9470
+ const payload = {
9471
+ plural,
9472
+ cluster
9473
+ };
9474
+ const { data } = await axios.post(
9475
+ `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfBuiltInNamespaceScoped`,
9476
+ payload
9477
+ );
9478
+ return data;
9479
+ };
9480
+
9442
9481
  const useSmartResourceParams = ({ cluster, namespace }) => {
9443
9482
  const [searchParams] = reactRouterDom.useSearchParams();
9444
- return K.useMemo(() => {
9483
+ const rawEntries = K.useMemo(() => {
9445
9484
  const raw = searchParams.get("resources");
9446
9485
  if (!raw) return [];
9447
9486
  return raw.split(",").map((entry) => {
9448
- const [apiGroup = "", apiVersion = "", plural] = entry.split("/");
9487
+ const [apiGroup = "", apiVersion = "", plural = ""] = entry.split("/");
9488
+ const normalizedGroup = apiGroup === "builtin" || apiGroup === "" ? void 0 : apiGroup;
9449
9489
  return {
9450
9490
  cluster,
9451
- namespace,
9452
- apiGroup: apiGroup === "builtin" ? void 0 : apiGroup,
9453
- apiVersion,
9454
- plural
9491
+ plural,
9492
+ apiGroup: normalizedGroup,
9493
+ apiVersion
9494
+ };
9495
+ }).filter((e) => Boolean(e.plural));
9496
+ }, [searchParams, cluster]);
9497
+ const scopeQueries = reactQuery.useQueries({
9498
+ queries: rawEntries.map((e) => {
9499
+ const isApi = Boolean(e.apiGroup);
9500
+ return {
9501
+ queryKey: ["resource-scope", e.cluster, isApi ? e.apiGroup : "builtin", e.apiVersion ?? "", e.plural],
9502
+ enabled: Boolean(e.cluster && e.plural && (!isApi || e.apiVersion)),
9503
+ queryFn: () => {
9504
+ if (isApi) {
9505
+ return checkIfApiInstanceNamespaceScoped({
9506
+ plural: e.plural,
9507
+ apiGroup: e.apiGroup,
9508
+ apiVersion: e.apiVersion || "",
9509
+ cluster: e.cluster
9510
+ });
9511
+ }
9512
+ return checkIfBuiltInInstanceNamespaceScoped({
9513
+ plural: e.plural,
9514
+ cluster: e.cluster
9515
+ });
9516
+ },
9517
+ staleTime: 5 * 60 * 1e3
9518
+ };
9519
+ })
9520
+ });
9521
+ const scopesLoading = scopeQueries.some((q) => q.isLoading);
9522
+ const scopesError = scopeQueries.find((q) => q.error)?.error;
9523
+ const paramsList = K.useMemo(() => {
9524
+ return rawEntries.map((e, i) => {
9525
+ const isClusterWide = scopeQueries[i]?.data?.isNamespaceScoped === false;
9526
+ return {
9527
+ cluster: e.cluster,
9528
+ plural: e.plural,
9529
+ apiGroup: e.apiGroup,
9530
+ apiVersion: e.apiVersion || "",
9531
+ namespace: isClusterWide ? void 0 : namespace
9455
9532
  };
9456
9533
  });
9457
- }, [searchParams, cluster, namespace]);
9534
+ }, [rawEntries, scopeQueries, namespace]);
9535
+ return {
9536
+ paramsList,
9537
+ scopesLoading,
9538
+ scopesError
9539
+ };
9458
9540
  };
9459
9541
 
9460
9542
  const prepareTemplate = ({
@@ -34099,7 +34181,6 @@
34099
34181
  const key = String(u).trim().toLowerCase();
34100
34182
  const canon = CORE_ALIASES[key];
34101
34183
  if (!canon) {
34102
- console.error(`Unknown core unit: "${u}"`);
34103
34184
  return "core";
34104
34185
  }
34105
34186
  return canon;
@@ -54710,39 +54791,6 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
54710
54791
  return axios.get(`/api/clusters/${cluster}/openapi-bff/swagger/swagger/${cluster}`);
54711
54792
  };
54712
54793
 
54713
- const checkIfApiInstanceNamespaceScoped = async ({
54714
- plural,
54715
- apiGroup,
54716
- apiVersion,
54717
- cluster
54718
- }) => {
54719
- const payload = {
54720
- plural,
54721
- apiGroup,
54722
- apiVersion,
54723
- cluster
54724
- };
54725
- const { data } = await axios.post(
54726
- `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfApiNamespaceScoped`,
54727
- payload
54728
- );
54729
- return data;
54730
- };
54731
- const checkIfBuiltInInstanceNamespaceScoped = async ({
54732
- plural,
54733
- cluster
54734
- }) => {
54735
- const payload = {
54736
- plural,
54737
- cluster
54738
- };
54739
- const { data } = await axios.post(
54740
- `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfBuiltInNamespaceScoped`,
54741
- payload
54742
- );
54743
- return data;
54744
- };
54745
-
54746
54794
  const useClusterList = ({ refetchInterval }) => {
54747
54795
  return reactQuery.useQuery({
54748
54796
  queryKey: ["useClusterList"],
@@ -54998,6 +55046,27 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
54998
55046
  }, [sentinelRef, hasMore, onNeedMore]);
54999
55047
  };
55000
55048
 
55049
+ const useResourceScope = ({ plural, cluster, apiGroup, apiVersion }) => {
55050
+ const computedResourceType = apiGroup ? "api" : "builtin";
55051
+ const enabled = Boolean(cluster) && Boolean(plural) && (computedResourceType === "builtin" || Boolean(apiVersion));
55052
+ return reactQuery.useQuery({
55053
+ queryKey: ["resource-scope", computedResourceType, cluster, plural, apiGroup, apiVersion],
55054
+ enabled,
55055
+ queryFn: async () => {
55056
+ if (computedResourceType === "builtin") {
55057
+ return checkIfBuiltInInstanceNamespaceScoped({ plural, cluster });
55058
+ }
55059
+ return checkIfApiInstanceNamespaceScoped({
55060
+ plural,
55061
+ apiGroup: apiGroup || "",
55062
+ apiVersion: apiVersion || "",
55063
+ cluster
55064
+ });
55065
+ },
55066
+ staleTime: 5 * 60 * 1e3
55067
+ });
55068
+ };
55069
+
55001
55070
  exports.BackToDefaultIcon = BackToDefaultIcon;
55002
55071
  exports.BlackholeForm = BlackholeForm;
55003
55072
  exports.BlackholeFormProvider = BlackholeFormProvider;
@@ -55134,6 +55203,7 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
55134
55203
  exports.useListWatch = useListWatch;
55135
55204
  exports.useManyK8sSmartResource = useManyK8sSmartResource;
55136
55205
  exports.usePermissions = usePermissions;
55206
+ exports.useResourceScope = useResourceScope;
55137
55207
  exports.useSmartResourceParams = useSmartResourceParams;
55138
55208
 
55139
55209
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });