UNPKG

@scalar/api-client

Version:

the open source API testing client

240 lines (239 loc) 8.57 kB
import { generateClientMutators as i } from "@scalar/workspace-store/mutators"; import { computed as p } from "vue"; const r = (a, c, t) => async (o) => { const n = await t[a]?.onBeforeExecute?.(o) ?? o; return await c(n), await t[a]?.onAfterExecute?.(n), n; }; function l({ eventBus: a, store: c, hooks: t }) { const o = p(() => i(c.value)), n = ({ collectionType: e }) => e === "document" ? o.value.active() : o.value.workspace(); a.on( "workspace:update:active-proxy", (e) => r("workspace:update:active-proxy", o.value.workspace().workspace.updateActiveProxy, t)(e) ), a.on( "workspace:update:color-mode", (e) => r("workspace:update:color-mode", o.value.workspace().workspace.updateColorMode, t)(e) ), a.on( "workspace:update:theme", (e) => r("workspace:update:theme", o.value.workspace().workspace.updateTheme, t)(e) ), a.on( "workspace:update:selected-client", (e) => r( "workspace:update:selected-client", o.value.workspace().workspace.updateSelectedClient, t )(e) ), a.on( "workspace:update:active-environment", (e) => r( "workspace:update:active-environment", o.value.workspace().workspace.updateActiveEnvironment, t )(e) ), a.on( "document:update:icon", (e) => r("document:update:icon", o.value.active().document.updateDocumentIcon, t)(e) ), a.on( "document:update:info", (e) => r("document:update:info", o.value.active().document.updateDocumentInfo, t)(e) ), a.on( "document:toggle:security", (e) => r("document:toggle:security", o.value.active().document.toggleSecurity, t)(e) ), a.on( "document:update:watch-mode", (e) => r("document:update:watch-mode", o.value.active().document.updateWatchMode, t)(e) ), a.on( "document:create:empty-document", (e) => r("document:create:empty-document", o.value.active().document.createEmptyDocument, t)(e) ), a.on( "document:delete:document", (e) => r("document:delete:document", o.value.active().document.deleteDocument, t)(e) ), a.on( "environment:upsert:environment", (e) => r("environment:upsert:environment", n(e).environment.upsertEnvironment, t)(e) ), a.on( "environment:delete:environment", (e) => r("environment:delete:environment", n(e).environment.deleteEnvironment, t)(e) ), a.on( "environment:upsert:environment-variable", (e) => r( "environment:upsert:environment-variable", n(e).environment.upsertEnvironmentVariable, t )(e) ), a.on( "environment:delete:environment-variable", (e) => r( "environment:delete:environment-variable", n(e).environment.deleteEnvironmentVariable, t )(e) ), a.on("cookie:upsert:cookie", async (e) => { await r("cookie:upsert:cookie", n(e).cookie.upsertCookie, t)(e); }), a.on("cookie:delete:cookie", async (e) => { await r("cookie:delete:cookie", n(e).cookie.deleteCookie, t)(e); }), a.on( "auth:delete:security-scheme", (e) => r("auth:delete:security-scheme", o.value.active().auth.deleteSecurityScheme, t)(e) ), a.on( "auth:update:active-index", (e) => r("auth:update:active-index", o.value.active().auth.updateSelectedAuthTab, t)(e) ), a.on( "auth:update:security-scheme", (e) => r("auth:update:security-scheme", o.value.active().auth.updateSecurityScheme, t)(e) ), a.on( "auth:update:selected-scopes", (e) => r("auth:update:selected-scopes", o.value.active().auth.updateSelectedScopes, t)(e) ), a.on( "auth:update:selected-security-schemes", (e) => r( "auth:update:selected-security-schemes", o.value.active().auth.updateSelectedSecuritySchemes, t )(e) ), a.on( "auth:update:security-scheme-secrets", (e) => r( "auth:update:security-scheme-secrets", o.value.active().auth.updateSecuritySchemeSecrets, t )(e) ), a.on( "auth:clear:security-scheme-secrets", (e) => r( "auth:clear:security-scheme-secrets", o.value.active().auth.clearSecuritySchemeSecrets, t )(e) ), a.on( "server:add:server", (e) => r("server:add:server", o.value.active().server.addServer, t)(e) ), a.on( "server:update:server", (e) => r("server:update:server", o.value.active().server.updateServer, t)(e) ), a.on( "server:delete:server", (e) => r("server:delete:server", o.value.active().server.deleteServer, t)(e) ), a.on( "server:update:variables", (e) => r("server:update:variables", o.value.active().server.updateServerVariables, t)(e) ), a.on( "server:update:selected", (e) => r("server:update:selected", o.value.active().server.updateSelectedServer, t)(e) ), a.on( "operation:create:operation", (e) => r("operation:create:operation", o.value.active().operation.createOperation, t)(e) ), a.on( "operation:update:pathMethod", (e) => r( "operation:update:pathMethod", o.value.active().operation.updateOperationPathMethod, t )(e) ), a.on( "operation:update:summary", (e) => r("operation:update:summary", o.value.active().operation.updateOperationSummary, t)(e) ), a.on( "operation:delete:operation", (e) => r("operation:delete:operation", o.value.active().operation.deleteOperation, t)(e) ), a.on( "operation:create:draft-example", (e) => r( "operation:create:draft-example", o.value.active().operation.createOperationDraftExample, t )(e) ), a.on( "operation:delete:example", (e) => r("operation:delete:example", o.value.active().operation.deleteOperationExample, t)(e) ), a.on( "operation:upsert:parameter", (e) => r("operation:upsert:parameter", o.value.active().operation.upsertOperationParameter, t)(e) ), a.on( "operation:update:extra-parameters", (e) => r( "operation:update:extra-parameters", o.value.active().operation.updateOperationExtraParameters, t )(e) ), a.on( "operation:delete:parameter", (e) => r("operation:delete:parameter", o.value.active().operation.deleteOperationParameter, t)(e) ), a.on( "operation:delete-all:parameters", (e) => r( "operation:delete-all:parameters", o.value.active().operation.deleteAllOperationParameters, t )(e) ), a.on( "operation:update:extension", (e) => r("operation:update:extension", o.value.active().operation.updateOperationExtension, t)(e) ), a.on( "operation:update:requestBody:contentType", (e) => r( "operation:update:requestBody:contentType", o.value.active().operation.updateOperationRequestBodyContentType, t )(e) ), a.on( "operation:update:requestBody:value", (e) => r( "operation:update:requestBody:value", o.value.active().operation.updateOperationRequestBodyExample, t )(e) ), a.on( "operation:update:requestBody:formValue", (e) => r( "operation:update:requestBody:formValue", o.value.active().operation.updateOperationRequestBodyFormValue, t )(e) ), a.on( "operation:reload:history", (e) => r("operation:reload:history", o.value.active().operation.reloadOperationHistory, t)(e) ), a.on( "tag:create:tag", (e) => r("tag:create:tag", o.value.active().tag.createTag, t)(e) ), a.on( "tag:edit:tag", (e) => r("tag:edit:tag", o.value.active().tag.editTag, t)(e) ), a.on( "tag:delete:tag", (e) => r("tag:delete:tag", o.value.active().tag.deleteTag, t)(e) ), a.on( "tabs:add:tab", (e) => r("tabs:add:tab", o.value.workspace().tabs.addTab, t)(e) ), a.on( "tabs:close:tab", (e) => r("tabs:close:tab", o.value.workspace().tabs.closeTab, t)(e) ), a.on( "tabs:close:other-tabs", (e) => r("tabs:close:other-tabs", o.value.workspace().tabs.closeOtherTabs, t)(e) ), a.on( "tabs:focus:tab", (e) => r("tabs:focus:tab", o.value.workspace().tabs.focusTab, t)(e) ), a.on( "tabs:focus:tab-last", (e) => r("tabs:focus:tab-last", o.value.workspace().tabs.focusLastTab, t)(e) ), a.on( "tabs:navigate:previous", (e) => r("tabs:navigate:previous", o.value.workspace().tabs.navigatePreviousTab, t)(e) ), a.on( "tabs:navigate:next", (e) => r("tabs:navigate:next", o.value.workspace().tabs.navigateNextTab, t)(e) ), a.on( "tabs:update:tabs", (e) => r("tabs:update:tabs", o.value.workspace().tabs.updateTabs, t)(e) ), a.on( "hooks:on:request:complete", (e) => r("hooks:on:request:complete", o.value.active().operation.addResponseToHistory, t)(e) ); } export { l as initializeWorkspaceEventHandlers };