@flanksource/clicky-ui
Version:
Flanksource Clicky UI — React component library built on shadcn/ui with light/dark and density theming.
77 lines (76 loc) • 2.42 kB
JavaScript
import { isPositionalParam } from "./types.js";
function findListEndpoint(operations, entities) {
const wanted = new Set(entities.map((e) => `${e}_list`));
if (wanted.size === 0) return void 0;
return operations.find(
(op) => op.method === "get" && !!op.operation.operationId && wanted.has(op.operation.operationId)
);
}
function findDetailEndpoint(operations) {
return operations.find(
(op) => {
var _a;
return op.method === "get" && ((_a = op.operation.parameters) == null ? void 0 : _a.some((p) => p.in === "path" || isPositionalParam(p)));
}
);
}
function splitPath(path) {
return path.split("/").filter(Boolean);
}
function findDetailEndpointForList(operations, listEndpoint) {
if (!listEndpoint) {
return findDetailEndpoint(operations);
}
const baseSegments = splitPath(listEndpoint.path);
const candidates = operations.filter(
(op) => {
var _a;
return op.method === "get" && op.path !== listEndpoint.path && ((_a = op.operation.parameters) == null ? void 0 : _a.some((p) => p.in === "path" || isPositionalParam(p)));
}
);
const exactChild = candidates.find((op) => {
const segments = splitPath(op.path);
if (segments.length !== baseSegments.length + 1) {
return false;
}
return baseSegments.every((segment, index) => segments[index] === segment);
});
if (exactChild) {
return exactChild;
}
const descendant = candidates.find((op) => op.path.startsWith(`${listEndpoint.path}/`));
return descendant ?? findDetailEndpoint(operations);
}
function parseJsonBody(response) {
if (!response) return null;
const text = response.stdout || response.output || "";
if (!text.trim()) return null;
try {
return JSON.parse(text);
} catch {
return null;
}
}
function normalizeRows(data) {
if (Array.isArray(data)) return data;
if (data && typeof data === "object") {
for (const value of Object.values(data)) {
if (Array.isArray(value)) return value;
}
}
return [];
}
function filterOperationsByDomain(operations, entities) {
if (entities.length === 0) return [];
const wanted = new Set(entities);
return operations.filter((op) => (op.operation.tags ?? []).some((tag) => wanted.has(tag)));
}
export {
filterOperationsByDomain,
findDetailEndpoint,
findDetailEndpointForList,
findListEndpoint,
normalizeRows,
parseJsonBody
};
//# sourceMappingURL=classify.js.map