@flanksource/clicky-ui
Version:
Flanksource Clicky UI — React component library built on shadcn/ui with light/dark and density theming.
32 lines (31 loc) • 938 B
JavaScript
import { useQuery } from "@tanstack/react-query";
function useOpenAPI(client) {
return useQuery({
queryKey: ["openapi-spec"],
queryFn: () => client.getOpenAPISpec(),
staleTime: 5 * 60 * 1e3
});
}
function useOperations(client) {
const { data: spec, ...rest } = useOpenAPI(client);
const operations = [];
if (spec) {
for (const [path, methods] of Object.entries(spec.paths)) {
for (const [method, operation] of Object.entries(methods)) {
operations.push({ path, method, operation });
}
}
}
return { operations, spec, ...rest };
}
function useOperationById(client, operationId) {
const { operations, ...rest } = useOperations(client);
const operation = operationId ? operations.find((op) => op.operation.operationId === operationId) : void 0;
return { operation, ...rest };
}
export {
useOpenAPI,
useOperationById,
useOperations
};
//# sourceMappingURL=useOperations.js.map