@scalar/api-client
Version:
the open source API testing client
30 lines (29 loc) • 1.45 kB
JavaScript
import { isHttpMethod as u } from "@scalar/helpers/http/is-http-method";
import { getOperationEntries as l } from "@scalar/workspace-store/navigation";
const p = (t) => t.type === "example", a = (t) => t.store.workspace.documents[t.documentSlug ?? ""], f = (t, e) => e !== "default" || t.workspace.documents[e] !== void 0 ? e : t.workspace["x-scalar-active-document"] || Object.keys(t.workspace.documents)[0], h = (t, e) => {
const n = a(t);
if (n)
return e === "default" ? Object.keys(n.paths ?? {})[0] : e;
}, v = (t, e, n) => {
const o = a(t);
if (!(!o || !e))
return n === "default" ? Object.keys(o.paths?.[e] ?? {}).find(u) : u(n) ? n : void 0;
}, x = (t, e, n) => {
if (!a(t) || e?.type !== "operation")
return "default";
const c = e.children?.filter(p) ?? [], r = c.find((s) => s.name === n);
return r ? r.name : n === "default" ? c[0]?.name ?? "default" : "default";
}, y = (t, e) => {
const n = f(t, e.documentSlug), o = { store: t, documentSlug: n }, c = h(o, e.path), r = v(o, c, e.method), s = a(o)?.["x-scalar-navigation"];
if (!s)
return { documentSlug: n, path: c, method: r, example: "default" };
const i = l(s).get(`${c}|${r}`)?.find((m) => m.type === "operation"), d = x(o, i, e.example);
return { documentSlug: n, path: c, method: r, example: d };
};
export {
f as resolveDocumentSlug,
x as resolveExampleName,
v as resolveMethod,
h as resolvePath,
y as resolveRouteParameters
};