UNPKG

@scalar/api-client

Version:

the open source API testing client

147 lines (146 loc) 5.71 kB
import { defineComponent as B, computed as q, ref as i, onMounted as g, onBeforeUnmount as R, watch as C, createElementBlock as S, openBlock as U, createElementVNode as k, createVNode as o, withCtx as h, unref as a } from "vue"; import { AVAILABLE_CLIENTS as E } from "@scalar/types/snippetz"; import { useToasts as b } from "@scalar/use-toasts"; import V from "../../../components/ViewLayout/ViewLayout.vue.js"; import K from "../../../components/ViewLayout/ViewLayoutContent.vue.js"; import { ERRORS as O } from "../../../libs/errors.js"; import { createStoreEvents as w } from "../../../store/events.js"; import { buildRequest as P } from "./helpers/build-request.js"; import { sendRequest as M } from "./helpers/send-request.js"; import A from "./components/Header.vue.js"; import { generateClientOptions as L } from "../operation-code-sample/helpers/generate-client-options.js"; import T from "../request-block/RequestBlock.vue.js"; import N from "../response-block/ResponseBlock.vue.js"; const I = { class: "bg-b-1 flex h-full flex-col" }, $ = { class: "lg:min-h-header flex w-full flex-wrap items-center justify-center p-2 lg:p-0" }, j = { name: "OperationBlock" }, ee = /* @__PURE__ */ B({ ...j, props: { eventBus: {}, appVersion: {}, globalCookies: { default: () => [] }, path: {}, method: {}, httpClients: { default: () => E }, layout: {}, server: {}, selectedClient: {}, servers: {}, history: {}, totalPerformedRequests: {}, hideClientButton: { type: Boolean }, integration: {}, documentUrl: {}, source: {}, operation: {}, exampleKey: {}, authMeta: {}, securitySchemes: {}, selectedSecurity: {}, securityRequirements: {}, plugins: { default: () => [] }, environment: {}, proxyUrl: {} }, emits: ["update:servers"], setup(t, { emit: y }) { const p = y, f = q(() => L(t.httpClients)), { toast: m } = b(), d = i(null), s = i(null), l = i(null), c = () => d.value?.abort(O.REQUEST_ABORTED), r = async () => { const [e, n] = P({ environment: t.environment, exampleKey: t.exampleKey, globalCookies: t.globalCookies, method: t.method, operation: t.operation, path: t.path, securitySchemes: t.securitySchemes, selectedSecurity: t.selectedSecurity?.selectedSchemes ?? [], server: t.server, proxyUrl: t.proxyUrl }); if (e) { m(e.message, "error"); return; } d.value = n.controller, t.eventBus.emit("hooks:on:request:sent"); const [u, v] = await M({ isUsingProxy: n.isUsingProxy, operation: t.operation, plugins: t.plugins, request: n.request }); if (t.eventBus.emit("hooks:on:request:complete"), u) { m(u.message, "error"); return; } s.value = v.response, l.value = v.request; }; return g(() => { t.eventBus.on("operation:send:request:hotkey", r), t.eventBus.on("operation:cancel:request", c); }), R(() => { t.eventBus.off("operation:send:request:hotkey", r), t.eventBus.off("operation:cancel:request", c); }), C([() => t.path, () => t.method, () => t.exampleKey], () => { s.value = null, l.value = null; }), (e, n) => (U(), S("div", I, [ k("div", $, [ o(A, { documentUrl: e.documentUrl, environment: e.environment, eventBus: e.eventBus, hideClientButton: e.hideClientButton, history: e.history, integration: e.integration, layout: e.layout, method: e.method, path: e.path, server: e.server, servers: e.servers, source: e.source, onExecute: r, "onUpdate:servers": n[0] || (n[0] = (u) => p("update:servers")) }, null, 8, ["documentUrl", "environment", "eventBus", "hideClientButton", "history", "integration", "layout", "method", "path", "server", "servers", "source"]) ]), o(V, { class: "border-t" }, { default: h(() => [ o(K, { class: "flex-1" }, { default: h(() => [ o(a(T), { authMeta: e.authMeta, clientOptions: f.value, environment: e.environment, eventBus: e.eventBus, exampleKey: e.exampleKey, layout: e.layout, method: e.method, operation: e.operation, path: e.path, plugins: e.plugins, proxyUrl: e.proxyUrl, securityRequirements: e.securityRequirements, securitySchemes: e.securitySchemes, selectedClient: e.selectedClient, selectedSecurity: e.selectedSecurity, server: e.server }, null, 8, ["authMeta", "clientOptions", "environment", "eventBus", "exampleKey", "layout", "method", "operation", "path", "plugins", "proxyUrl", "securityRequirements", "securitySchemes", "selectedClient", "selectedSecurity", "server"]), o(a(N), { appVersion: e.appVersion, eventBus: e.eventBus, events: a(w)(), layout: e.layout, plugins: e.plugins, request: l.value, response: s.value, totalPerformedRequests: e.totalPerformedRequests, onSendRequest: r }, null, 8, ["appVersion", "eventBus", "events", "layout", "plugins", "request", "response", "totalPerformedRequests"]) ]), _: 1 }) ]), _: 1 }) ])); } }); export { ee as default };