@scalar/api-client
Version:
the open source API testing client
34 lines (33 loc) • 967 B
JavaScript
import { generateUniqueSlug as u } from "./generate-unique-slug.js";
const m = async ({
workspaceStore: t,
workspaceState: o,
name: n
}) => {
if (!t)
return { ok: !1, error: "Workspace store is not available" };
const r = o.documents[n];
if (!r)
return { ok: !1, error: "Importing document not found in workspace state" };
const i = new Set(Object.keys(t.workspace.documents)), e = await u(r.info.title || "default", i);
return e ? (t.loadWorkspace({
meta: {},
documents: {
[e]: r
},
intermediateDocuments: {
[e]: o.intermediateDocuments[n] ?? {}
},
originalDocuments: {
[e]: o.originalDocuments[n] ?? {}
},
overrides: {
[e]: o.overrides[n] ?? {}
},
history: {},
auth: {}
}), t.buildSidebar(e), await t.saveDocument(e), { ok: !0, slug: e }) : { ok: !1, error: "Failed to generate a unique slug for the importing document" };
};
export {
m as importDocumentToWorkspace
};