@scalar/api-client
Version:
the open source API testing client
74 lines (73 loc) • 2.07 kB
JavaScript
import { collectionSchema as E } from "@scalar/oas-utils/entities/spec";
import { LS_KEYS as h } from "@scalar/helpers/object/local-storage";
import { mutationFactory as x } from "@scalar/object-utils/mutator-record";
import { reactive as f } from "vue";
function D(s) {
const r = f({}), a = x(r, f({}), s && h.COLLECTION);
return {
collections: r,
collectionMutators: a
};
}
function F({
requests: s,
requestMutators: r,
requestExamples: a,
requestExampleMutators: m,
workspaces: u,
workspaceMutators: d,
collections: i,
collectionMutators: c,
tagMutators: v,
serverMutators: C
}) {
return {
addCollection: (t, o) => {
const e = E.parse(t), n = u[o];
return n && d.edit(o, "collections", [...n.collections, e.uid]), c.add(e), e;
},
deleteCollection: (t, o) => {
if (o.uid) {
if (i[t.uid]?.info?.title === "Drafts") {
console.warn("The drafts collection cannot be deleted");
return;
}
if (Object.values(i).length === 1) {
console.warn("You must have at least one collection");
return;
}
t.tags.forEach((e) => v.delete(e)), t.requests.forEach((e) => {
const n = s[e];
n && (r.delete(e), n.examples.forEach((l) => a[l] && m.delete(l)));
}), t.servers.forEach((e) => {
e && C.delete(e);
}), d.edit(
o.uid,
"collections",
o.collections.filter((e) => e !== t.uid)
), c.delete(t.uid);
}
},
addCollectionEnvironment: (t, o, e) => {
const n = i[e];
if (n) {
const l = n["x-scalar-environments"] || {};
c.edit(e, "x-scalar-environments", {
...l,
[t]: o
});
}
},
removeCollectionEnvironment: (t, o) => {
const e = i[o];
if (e) {
const n = e["x-scalar-environments"] || {};
t in n && (delete n[t], c.edit(o, "x-scalar-environments", n));
}
}
};
}
export {
D as createStoreCollections,
F as extendedCollectionDataFactory
};