UNPKG

@scalar/api-client

Version:

the open source API testing client

82 lines (81 loc) 2.36 kB
import { createWorkspaceStore as l } from "@scalar/workspace-store/client"; import { generateUniqueValue as W } from "@scalar/workspace-store/helpers/generate-unique-value"; import { createWorkspaceStorePersistence as v } from "@scalar/workspace-store/persistence"; import { persistencePlugin as D } from "@scalar/workspace-store/plugins/client"; import { ref as i } from "vue"; import { useRouter as g } from "vue-router"; import { slugify as y } from "../../../helpers/slugify.js"; const S = 1e3, R = { name: "Default Workspace", id: "default" }, h = { openapi: "3.1.0", info: { title: "Drafts", version: "1.0.0" }, paths: { "/": { get: {} } }, "x-scalar-original-document-hash": "drafts", "x-scalar-icon": "interface-edit-tool-pencil" }, A = async ({ workspaceId: r }) => l({ plugins: [await D({ workspaceId: r, debounceDelay: S })] }), _ = () => { const r = i(null), c = i([]), n = i(null), o = v(), w = g(), m = async (e) => { const a = await (await o).workspace.getItem(e); if (!a) return { success: !1 }; const s = await A({ workspaceId: e }); return s.loadWorkspace(a.workspace), r.value = { id: e, name: a.name }, n.value = s, { success: !0, workspace: s }; }, k = async ({ id: e, name: t }) => { const a = l(); await a.addDocument({ name: "drafts", document: h }), await (await o).workspace.setItem(e, { name: t, workspace: a.exportWorkspace() }), c.value.push({ id: e, name: t }); }, p = async (e) => { await w.push({ name: "workspace.environment", params: { workspaceSlug: e } }); }, f = async ({ id: e, name: t }) => { n.value = null; const a = await o, s = await W({ defaultValue: e ?? t, // Use the provided id if it exists, otherwise use the name validation: async (d) => !await a.workspace.has(d), maxRetries: 100, transformation: y }); if (!s) return; const u = { id: s, name: t }; return await k(u), await p(s), u; }; return (async () => { const t = await (await o).workspace.getAll(); c.value = t; })(), { store: n, activeWorkspace: r, workspaces: c, setWorkspaceId: p, createWorkspace: f, loadWorkspace: m }; }; export { R as DEFAULT_WORKSPACE, _ as useWorkspaceSelector };