@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.
@@ -8803,6 +8803,7 @@ const useListWatch = ({
8803
8803
  }) => {
8804
8804
  const resId = `${query.apiGroup ?? ""}|${query.apiVersion}|${query.plural}|${query.namespace ?? ""}|${query.fieldSelector ?? ""}|${query.labelSelector ?? ""}`;
8805
8805
  const resIdRef = useRef(resId);
8806
+ const [debugTick, bumpTick] = useReducer((x) => x + 1, 0);
8806
8807
  const [state, dispatch] = useReducer(reducer$1, { order: [], byKey: {} });
8807
8808
  const [contToken, setContToken] = useState();
8808
8809
  const [hasMore, setHasMore] = useState(false);
@@ -9050,6 +9051,7 @@ const useListWatch = ({
9050
9051
  }
9051
9052
  if (frame.type === "INITIAL") {
9052
9053
  dispatch({ type: "RESET", items: frame.items });
9054
+ bumpTick();
9053
9055
  setContToken(frame.continue);
9054
9056
  setHasMore(Boolean(frame.continue));
9055
9057
  setErrorSafe(void 0);
@@ -9065,6 +9067,7 @@ const useListWatch = ({
9065
9067
  }
9066
9068
  if (frame.type === "PAGE") {
9067
9069
  dispatch({ type: "APPEND_PAGE", items: frame.items });
9070
+ bumpTick();
9068
9071
  setContToken(frame.continue);
9069
9072
  setHasMore(Boolean(frame.continue));
9070
9073
  fetchingRef.current = false;
@@ -9087,9 +9090,11 @@ const useListWatch = ({
9087
9090
  }
9088
9091
  if (!pausedRef.current) {
9089
9092
  if (frame.type === "ADDED" || frame.type === "MODIFIED") {
9093
+ bumpTick();
9090
9094
  dispatch({ type: "UPSERT", item: frame.item });
9091
9095
  }
9092
9096
  if (!ignoreRemoveRef.current && frame.type === "DELETED") {
9097
+ bumpTick();
9093
9098
  dispatch({ type: "REMOVE", key: eventKey$1(frame.item) });
9094
9099
  }
9095
9100
  }
@@ -9230,7 +9235,8 @@ const useListWatch = ({
9230
9235
  drainAll,
9231
9236
  reconnect,
9232
9237
  setUrl,
9233
- setQuery
9238
+ setQuery,
9239
+ debugTick
9234
9240
  };
9235
9241
  };
9236
9242
 
@@ -9321,7 +9327,7 @@ const useK8sSmartResourceWithoutKinds = ({
9321
9327
  const watchEnabled = Boolean(
9322
9328
  cluster && cluster.length > 0 && isEnabled && canList && canWatch && !verbsLoading && !verbsIsError
9323
9329
  );
9324
- const { state, status, hasInitial, lastError } = useListWatch({
9330
+ const { state, status, hasInitial, lastError, debugTick } = useListWatch({
9325
9331
  wsUrl: `/api/clusters/${cluster}/openapi-bff-ws/listThenWatch/listWatchWs`,
9326
9332
  paused: false,
9327
9333
  ignoreRemove: false,
@@ -9353,7 +9359,7 @@ const useK8sSmartResourceWithoutKinds = ({
9353
9359
  else if (used === "list" && restIsError) error = restError;
9354
9360
  const isError = Boolean(error);
9355
9361
  const data = used === "watch" ? watchData : used === "list" ? restData : void 0;
9356
- return { data, isLoading, isError, error, _meta: { used } };
9362
+ return { data, isLoading, isError, error, _meta: { used }, debugTick };
9357
9363
  };
9358
9364
 
9359
9365
  const hasItemsArray = (value) => {
@@ -9440,22 +9446,98 @@ const useManyK8sSmartResource = (paramsList) => {
9440
9446
  return results;
9441
9447
  };
9442
9448
 
9449
+ const checkIfApiInstanceNamespaceScoped = async ({
9450
+ plural,
9451
+ apiGroup,
9452
+ apiVersion,
9453
+ cluster
9454
+ }) => {
9455
+ const payload = {
9456
+ plural,
9457
+ apiGroup,
9458
+ apiVersion,
9459
+ cluster
9460
+ };
9461
+ const { data } = await axios.post(
9462
+ `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfApiNamespaceScoped`,
9463
+ payload
9464
+ );
9465
+ return data;
9466
+ };
9467
+ const checkIfBuiltInInstanceNamespaceScoped = async ({
9468
+ plural,
9469
+ cluster
9470
+ }) => {
9471
+ const payload = {
9472
+ plural,
9473
+ cluster
9474
+ };
9475
+ const { data } = await axios.post(
9476
+ `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfBuiltInNamespaceScoped`,
9477
+ payload
9478
+ );
9479
+ return data;
9480
+ };
9481
+
9443
9482
  const useSmartResourceParams = ({ cluster, namespace }) => {
9444
9483
  const [searchParams] = useSearchParams();
9445
- return useMemo(() => {
9484
+ const rawEntries = useMemo(() => {
9446
9485
  const raw = searchParams.get("resources");
9447
9486
  if (!raw) return [];
9448
9487
  return raw.split(",").map((entry) => {
9449
- const [apiGroup = "", apiVersion = "", plural] = entry.split("/");
9488
+ const [apiGroup = "", apiVersion = "", plural = ""] = entry.split("/");
9489
+ const normalizedGroup = apiGroup === "builtin" || apiGroup === "" ? void 0 : apiGroup;
9450
9490
  return {
9451
9491
  cluster,
9452
- namespace,
9453
- apiGroup: apiGroup === "builtin" ? void 0 : apiGroup,
9454
- apiVersion,
9455
- plural
9492
+ plural,
9493
+ apiGroup: normalizedGroup,
9494
+ apiVersion
9495
+ };
9496
+ }).filter((e) => Boolean(e.plural));
9497
+ }, [searchParams, cluster]);
9498
+ const scopeQueries = useQueries({
9499
+ queries: rawEntries.map((e) => {
9500
+ const isApi = Boolean(e.apiGroup);
9501
+ return {
9502
+ queryKey: ["resource-scope", e.cluster, isApi ? e.apiGroup : "builtin", e.apiVersion ?? "", e.plural],
9503
+ enabled: Boolean(e.cluster && e.plural && (!isApi || e.apiVersion)),
9504
+ queryFn: () => {
9505
+ if (isApi) {
9506
+ return checkIfApiInstanceNamespaceScoped({
9507
+ plural: e.plural,
9508
+ apiGroup: e.apiGroup,
9509
+ apiVersion: e.apiVersion || "",
9510
+ cluster: e.cluster
9511
+ });
9512
+ }
9513
+ return checkIfBuiltInInstanceNamespaceScoped({
9514
+ plural: e.plural,
9515
+ cluster: e.cluster
9516
+ });
9517
+ },
9518
+ staleTime: 5 * 60 * 1e3
9519
+ };
9520
+ })
9521
+ });
9522
+ const scopesLoading = scopeQueries.some((q) => q.isLoading);
9523
+ const scopesError = scopeQueries.find((q) => q.error)?.error;
9524
+ const paramsList = useMemo(() => {
9525
+ return rawEntries.map((e, i) => {
9526
+ const isClusterWide = scopeQueries[i]?.data?.isNamespaceScoped === false;
9527
+ return {
9528
+ cluster: e.cluster,
9529
+ plural: e.plural,
9530
+ apiGroup: e.apiGroup,
9531
+ apiVersion: e.apiVersion || "",
9532
+ namespace: isClusterWide ? void 0 : namespace
9456
9533
  };
9457
9534
  });
9458
- }, [searchParams, cluster, namespace]);
9535
+ }, [rawEntries, scopeQueries, namespace]);
9536
+ return {
9537
+ paramsList,
9538
+ scopesLoading,
9539
+ scopesError
9540
+ };
9459
9541
  };
9460
9542
 
9461
9543
  const prepareTemplate = ({
@@ -34100,7 +34182,6 @@ const normalizeCoreUnit = (u) => {
34100
34182
  const key = String(u).trim().toLowerCase();
34101
34183
  const canon = CORE_ALIASES[key];
34102
34184
  if (!canon) {
34103
- console.error(`Unknown core unit: "${u}"`);
34104
34185
  return "core";
34105
34186
  }
34106
34187
  return canon;
@@ -54711,39 +54792,6 @@ const getSwagger = async ({ cluster }) => {
54711
54792
  return axios.get(`/api/clusters/${cluster}/openapi-bff/swagger/swagger/${cluster}`);
54712
54793
  };
54713
54794
 
54714
- const checkIfApiInstanceNamespaceScoped = async ({
54715
- plural,
54716
- apiGroup,
54717
- apiVersion,
54718
- cluster
54719
- }) => {
54720
- const payload = {
54721
- plural,
54722
- apiGroup,
54723
- apiVersion,
54724
- cluster
54725
- };
54726
- const { data } = await axios.post(
54727
- `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfApiNamespaceScoped`,
54728
- payload
54729
- );
54730
- return data;
54731
- };
54732
- const checkIfBuiltInInstanceNamespaceScoped = async ({
54733
- plural,
54734
- cluster
54735
- }) => {
54736
- const payload = {
54737
- plural,
54738
- cluster
54739
- };
54740
- const { data } = await axios.post(
54741
- `/api/clusters/${cluster}/openapi-bff/scopes/checkScopes/checkIfBuiltInNamespaceScoped`,
54742
- payload
54743
- );
54744
- return data;
54745
- };
54746
-
54747
54795
  const useClusterList = ({ refetchInterval }) => {
54748
54796
  return useQuery({
54749
54797
  queryKey: ["useClusterList"],
@@ -54999,5 +55047,26 @@ const useInfiniteSentinel = (sentinelRef, hasMore, onNeedMore) => {
54999
55047
  }, [sentinelRef, hasMore, onNeedMore]);
55000
55048
  };
55001
55049
 
55002
- export { BackToDefaultIcon, BlackholeForm, BlackholeFormProvider, ContentCard$1 as ContentCard, CursorDefaultDiv, CursorPointerTag, CursorPointerTagMinContent, CustomSelect$4 as CustomSelect, DeleteIcon, DeleteModal, DeleteModalMany, DownIcon, DynamicComponents, DynamicRenderer, DynamicRendererWithProviders, EarthIcon, EditIcon, EnrichedTable, EnrichedTableProvider, Events, FlexGrow, LockedIcon, LookingGlassIcon, ManageableBreadcrumbs, ManageableBreadcrumbsProvider, ManageableSidebar, ManageableSidebarProvider, MarketPlace, MarketplaceCard, MinusIcon, NodeTerminal, PaddingContainer, PauseCircleIcon, PlusIcon, PodLogs, PodLogsMonaco, PodTerminal, ProjectInfoCard, ResourceLink, ResumeCircleIcon, Search, Spacer$1 as Spacer, SuccessIcon, TreeWithSearch, UncontrolledSelect, UnlockedIcon, UpIcon, YamlEditorSingleton$1 as YamlEditorSingleton, checkIfApiInstanceNamespaceScoped, checkIfBuiltInInstanceNamespaceScoped, checkPermission, convertBytes, convertCompute, convertCores, convertStorage, createContextFactory, createNewEntry, deepMerge, deleteEntry, feedbackIcons, filterIfApiInstanceNamespaceScoped, filterIfBuiltInInstanceNamespaceScoped, filterSelectOptions, floorToDecimal, formatBytesAuto, formatCoresAuto, getAllPathsFromObj, getApiResourceSingle, getApiResourceTypes, getApiResourceTypesByApiGroup, getApiResources, getBuiltinResourceSingle, getBuiltinResourceTypes, getBuiltinResources, getBuiltinTreeData, getClusterList, getCrdData, getCrdResourceSingle, getCrdResources, getDirectUnknownResource, getEnrichedColumns, getEnrichedColumnsWithControls, getGroupsByCategory, getKinds, getLinkToApiForm, getLinkToBuiltinForm, getLinkToForm, getNamespaceLink, getObjectFormItemsDraft, getPrefixSubarrays, getResourceLink, getSortedKinds, getSortedKindsAll, getStringByName, getSwagger, getUppercase, groupsToTreeData, hslFromString, includesArray, isFlatObject, isMultilineFromYaml, isMultilineString, kindByGvr, namespacedByGvr, normalizeValuesForQuotasToNumber, parseCoresWithUnit, parseQuotaValue, parseQuotaValueCpu, parseQuotaValueMemoryAndStorage, parseValueWithUnit, pluralByKind, prepareDataForManageableBreadcrumbs, prepareDataForManageableSidebar, prepareTemplate, prepareUrlsToFetchForDynamicRenderer, toBytes, toCores, updateEntry, useApiResourceSingle, useApiResourceTypesByGroup, useApiResources, useApisResourceTypes, useBuiltinResourceSingle, useBuiltinResourceTypes, useBuiltinResources, useClusterList, useCrdData, useCrdResourceSingle, useCrdResources, useDirectUnknownResource, useInfiniteSentinel, useK8sSmartResource, useK8sVerbs, useListWatch, useManyK8sSmartResource, usePermissions, useSmartResourceParams };
55050
+ const useResourceScope = ({ plural, cluster, apiGroup, apiVersion }) => {
55051
+ const computedResourceType = apiGroup ? "api" : "builtin";
55052
+ const enabled = Boolean(cluster) && Boolean(plural) && (computedResourceType === "builtin" || Boolean(apiVersion));
55053
+ return useQuery({
55054
+ queryKey: ["resource-scope", computedResourceType, cluster, plural, apiGroup, apiVersion],
55055
+ enabled,
55056
+ queryFn: async () => {
55057
+ if (computedResourceType === "builtin") {
55058
+ return checkIfBuiltInInstanceNamespaceScoped({ plural, cluster });
55059
+ }
55060
+ return checkIfApiInstanceNamespaceScoped({
55061
+ plural,
55062
+ apiGroup: apiGroup || "",
55063
+ apiVersion: apiVersion || "",
55064
+ cluster
55065
+ });
55066
+ },
55067
+ staleTime: 5 * 60 * 1e3
55068
+ });
55069
+ };
55070
+
55071
+ export { BackToDefaultIcon, BlackholeForm, BlackholeFormProvider, ContentCard$1 as ContentCard, CursorDefaultDiv, CursorPointerTag, CursorPointerTagMinContent, CustomSelect$4 as CustomSelect, DeleteIcon, DeleteModal, DeleteModalMany, DownIcon, DynamicComponents, DynamicRenderer, DynamicRendererWithProviders, EarthIcon, EditIcon, EnrichedTable, EnrichedTableProvider, Events, FlexGrow, LockedIcon, LookingGlassIcon, ManageableBreadcrumbs, ManageableBreadcrumbsProvider, ManageableSidebar, ManageableSidebarProvider, MarketPlace, MarketplaceCard, MinusIcon, NodeTerminal, PaddingContainer, PauseCircleIcon, PlusIcon, PodLogs, PodLogsMonaco, PodTerminal, ProjectInfoCard, ResourceLink, ResumeCircleIcon, Search, Spacer$1 as Spacer, SuccessIcon, TreeWithSearch, UncontrolledSelect, UnlockedIcon, UpIcon, YamlEditorSingleton$1 as YamlEditorSingleton, checkIfApiInstanceNamespaceScoped, checkIfBuiltInInstanceNamespaceScoped, checkPermission, convertBytes, convertCompute, convertCores, convertStorage, createContextFactory, createNewEntry, deepMerge, deleteEntry, feedbackIcons, filterIfApiInstanceNamespaceScoped, filterIfBuiltInInstanceNamespaceScoped, filterSelectOptions, floorToDecimal, formatBytesAuto, formatCoresAuto, getAllPathsFromObj, getApiResourceSingle, getApiResourceTypes, getApiResourceTypesByApiGroup, getApiResources, getBuiltinResourceSingle, getBuiltinResourceTypes, getBuiltinResources, getBuiltinTreeData, getClusterList, getCrdData, getCrdResourceSingle, getCrdResources, getDirectUnknownResource, getEnrichedColumns, getEnrichedColumnsWithControls, getGroupsByCategory, getKinds, getLinkToApiForm, getLinkToBuiltinForm, getLinkToForm, getNamespaceLink, getObjectFormItemsDraft, getPrefixSubarrays, getResourceLink, getSortedKinds, getSortedKindsAll, getStringByName, getSwagger, getUppercase, groupsToTreeData, hslFromString, includesArray, isFlatObject, isMultilineFromYaml, isMultilineString, kindByGvr, namespacedByGvr, normalizeValuesForQuotasToNumber, parseCoresWithUnit, parseQuotaValue, parseQuotaValueCpu, parseQuotaValueMemoryAndStorage, parseValueWithUnit, pluralByKind, prepareDataForManageableBreadcrumbs, prepareDataForManageableSidebar, prepareTemplate, prepareUrlsToFetchForDynamicRenderer, toBytes, toCores, updateEntry, useApiResourceSingle, useApiResourceTypesByGroup, useApiResources, useApisResourceTypes, useBuiltinResourceSingle, useBuiltinResourceTypes, useBuiltinResources, useClusterList, useCrdData, useCrdResourceSingle, useCrdResources, useDirectUnknownResource, useInfiniteSentinel, useK8sSmartResource, useK8sVerbs, useListWatch, useManyK8sSmartResource, usePermissions, useResourceScope, useSmartResourceParams };
55003
55072
  //# sourceMappingURL=openapi-k8s-toolkit.es.js.map