refactor: finalize API methods
This commit is contained in:
@@ -65,6 +65,7 @@ import {
|
|||||||
} from "@hoppscotch/data"
|
} from "@hoppscotch/data"
|
||||||
import { computedWithControl } from "@vueuse/core"
|
import { computedWithControl } from "@vueuse/core"
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
import * as TE from "fp-ts/TaskEither"
|
import * as TE from "fp-ts/TaskEither"
|
||||||
import { pipe } from "fp-ts/function"
|
import { pipe } from "fp-ts/function"
|
||||||
import { cloneDeep } from "lodash-es"
|
import { cloneDeep } from "lodash-es"
|
||||||
@@ -78,11 +79,10 @@ import { Picked } from "~/helpers/types/HoppPicked"
|
|||||||
import {
|
import {
|
||||||
cascadeParentCollectionForHeaderAuth,
|
cascadeParentCollectionForHeaderAuth,
|
||||||
editGraphqlRequest,
|
editGraphqlRequest,
|
||||||
editRESTRequest,
|
|
||||||
saveGraphqlRequestAs,
|
saveGraphqlRequestAs,
|
||||||
saveRESTRequestAs,
|
|
||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
import { platform } from "~/platform"
|
import { platform } from "~/platform"
|
||||||
|
import { NewWorkspaceService } from "~/services/new-workspace"
|
||||||
import { GQLTabService } from "~/services/tab/graphql"
|
import { GQLTabService } from "~/services/tab/graphql"
|
||||||
import { RESTTabService } from "~/services/tab/rest"
|
import { RESTTabService } from "~/services/tab/rest"
|
||||||
import { TeamWorkspace } from "~/services/workspace.service"
|
import { TeamWorkspace } from "~/services/workspace.service"
|
||||||
@@ -92,6 +92,7 @@ const toast = useToast()
|
|||||||
|
|
||||||
const RESTTabs = useService(RESTTabService)
|
const RESTTabs = useService(RESTTabService)
|
||||||
const GQLTabs = useService(GQLTabService)
|
const GQLTabs = useService(GQLTabService)
|
||||||
|
const workspaceService = useService(NewWorkspaceService)
|
||||||
|
|
||||||
type CollectionType =
|
type CollectionType =
|
||||||
| {
|
| {
|
||||||
@@ -212,99 +213,106 @@ const saveRequestAs = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdated =
|
const updatedRequest =
|
||||||
props.mode === "rest"
|
props.mode === "rest"
|
||||||
? cloneDeep(RESTTabs.currentActiveTab.value.document.request)
|
? cloneDeep(RESTTabs.currentActiveTab.value.document.request)
|
||||||
: cloneDeep(GQLTabs.currentActiveTab.value.document.request)
|
: cloneDeep(GQLTabs.currentActiveTab.value.document.request)
|
||||||
|
|
||||||
requestUpdated.name = requestName.value
|
updatedRequest.name = requestName.value
|
||||||
|
|
||||||
if (picked.value.pickedType === "my-collection") {
|
if (!workspaceService.activeWorkspaceHandle.value) {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
picked.value.pickedType === "my-collection" ||
|
||||||
|
picked.value.pickedType === "my-folder"
|
||||||
|
) {
|
||||||
|
if (!isHoppRESTRequest(updatedRequest))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
const insertionIndex = saveRESTRequestAs(
|
const collPathIndex =
|
||||||
`${picked.value.collectionIndex}`,
|
picked.value.pickedType === "my-collection"
|
||||||
requestUpdated
|
? picked.value.collectionIndex.toString()
|
||||||
|
: picked.value.folderPath
|
||||||
|
|
||||||
|
const collHandleResult = await workspaceService.getCollectionHandle(
|
||||||
|
workspaceService.activeWorkspaceHandle.value,
|
||||||
|
collPathIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
RESTTabs.currentActiveTab.value.document = {
|
if (E.isLeft(collHandleResult)) {
|
||||||
request: requestUpdated,
|
// INVALID_WORKSPACE_HANDLE
|
||||||
isDirty: false,
|
return
|
||||||
saveContext: {
|
|
||||||
originLocation: "user-collection",
|
|
||||||
folderPath: `${picked.value.collectionIndex}`,
|
|
||||||
requestIndex: insertionIndex,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
const collHandle = collHandleResult.right
|
||||||
`${picked.value.collectionIndex}`,
|
|
||||||
"rest"
|
if (collHandle.value.type === "invalid") {
|
||||||
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const resultHandle = await workspaceService.createRESTRequest(
|
||||||
|
collHandle,
|
||||||
|
updatedRequest.name,
|
||||||
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
RESTTabs.currentActiveTab.value.document.inheritedProperties = {
|
if (E.isLeft(resultHandle)) {
|
||||||
auth,
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
headers,
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
const result = resultHandle.right
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
if (result.value.type === "invalid") {
|
||||||
} else if (picked.value.pickedType === "my-folder") {
|
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
return
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
|
||||||
|
|
||||||
const insertionIndex = saveRESTRequestAs(
|
|
||||||
picked.value.folderPath,
|
|
||||||
requestUpdated
|
|
||||||
)
|
|
||||||
|
|
||||||
RESTTabs.currentActiveTab.value.document = {
|
|
||||||
request: requestUpdated,
|
|
||||||
isDirty: false,
|
|
||||||
saveContext: {
|
|
||||||
originLocation: "user-collection",
|
|
||||||
folderPath: picked.value.folderPath,
|
|
||||||
requestIndex: insertionIndex,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
|
||||||
picked.value.folderPath,
|
|
||||||
"rest"
|
|
||||||
)
|
|
||||||
|
|
||||||
RESTTabs.currentActiveTab.value.document.inheritedProperties = {
|
|
||||||
auth,
|
|
||||||
headers,
|
|
||||||
}
|
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: true,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "my-request") {
|
} else if (picked.value.pickedType === "my-request") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(updatedRequest))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
editRESTRequest(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
picked.value.folderPath,
|
workspaceService.activeWorkspaceHandle.value,
|
||||||
picked.value.requestIndex,
|
picked.value.folderPath
|
||||||
requestUpdated
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(requestHandleResult)) {
|
||||||
|
// INVALID_WORKSPACE_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestHandle = requestHandleResult.right
|
||||||
|
|
||||||
|
if (requestHandle.value.type === "invalid") {
|
||||||
|
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const resultHandle = await workspaceService.updateRESTRequest(
|
||||||
|
requestHandle,
|
||||||
|
updatedRequest
|
||||||
|
)
|
||||||
|
|
||||||
|
if (E.isLeft(resultHandle)) {
|
||||||
|
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = resultHandle.right
|
||||||
|
|
||||||
|
if (result.value.type === "invalid") {
|
||||||
|
// WORKSPACE_INVALIDATED | INVALID_REQUEST_HANDLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// These remain here in the component
|
||||||
RESTTabs.currentActiveTab.value.document = {
|
RESTTabs.currentActiveTab.value.document = {
|
||||||
request: requestUpdated,
|
request: updatedRequest,
|
||||||
isDirty: false,
|
isDirty: false,
|
||||||
saveContext: {
|
saveContext: {
|
||||||
originLocation: "user-collection",
|
originLocation: "user-collection",
|
||||||
@@ -323,19 +331,12 @@ const saveRequestAs = async () => {
|
|||||||
headers,
|
headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "HOPP_SAVE_REQUEST",
|
|
||||||
createdNow: false,
|
|
||||||
platform: "rest",
|
|
||||||
workspaceType: "personal",
|
|
||||||
})
|
|
||||||
|
|
||||||
requestSaved()
|
requestSaved()
|
||||||
} else if (picked.value.pickedType === "teams-collection") {
|
} else if (picked.value.pickedType === "teams-collection") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(updatedRequest))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
updateTeamCollectionOrFolder(picked.value.collectionID, requestUpdated)
|
updateTeamCollectionOrFolder(picked.value.collectionID, updatedRequest)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
type: "HOPP_SAVE_REQUEST",
|
type: "HOPP_SAVE_REQUEST",
|
||||||
@@ -344,10 +345,10 @@ const saveRequestAs = async () => {
|
|||||||
workspaceType: "team",
|
workspaceType: "team",
|
||||||
})
|
})
|
||||||
} else if (picked.value.pickedType === "teams-folder") {
|
} else if (picked.value.pickedType === "teams-folder") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(updatedRequest))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
updateTeamCollectionOrFolder(picked.value.folderID, requestUpdated)
|
updateTeamCollectionOrFolder(picked.value.folderID, updatedRequest)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
type: "HOPP_SAVE_REQUEST",
|
type: "HOPP_SAVE_REQUEST",
|
||||||
@@ -356,7 +357,7 @@ const saveRequestAs = async () => {
|
|||||||
workspaceType: "team",
|
workspaceType: "team",
|
||||||
})
|
})
|
||||||
} else if (picked.value.pickedType === "teams-request") {
|
} else if (picked.value.pickedType === "teams-request") {
|
||||||
if (!isHoppRESTRequest(requestUpdated))
|
if (!isHoppRESTRequest(updatedRequest))
|
||||||
throw new Error("requestUpdated is not a REST Request")
|
throw new Error("requestUpdated is not a REST Request")
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -368,8 +369,8 @@ const saveRequestAs = async () => {
|
|||||||
modalLoadingState.value = true
|
modalLoadingState.value = true
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
request: JSON.stringify(requestUpdated),
|
request: JSON.stringify(updatedRequest),
|
||||||
title: requestUpdated.name,
|
title: updatedRequest.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
@@ -397,7 +398,7 @@ const saveRequestAs = async () => {
|
|||||||
editGraphqlRequest(
|
editGraphqlRequest(
|
||||||
picked.value.folderPath,
|
picked.value.folderPath,
|
||||||
picked.value.requestIndex,
|
picked.value.requestIndex,
|
||||||
requestUpdated as HoppGQLRequest
|
updatedRequest as HoppGQLRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
@@ -422,7 +423,7 @@ const saveRequestAs = async () => {
|
|||||||
// TODO: Check for GQL request ?
|
// TODO: Check for GQL request ?
|
||||||
saveGraphqlRequestAs(
|
saveGraphqlRequestAs(
|
||||||
picked.value.folderPath,
|
picked.value.folderPath,
|
||||||
requestUpdated as HoppGQLRequest
|
updatedRequest as HoppGQLRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
@@ -447,7 +448,7 @@ const saveRequestAs = async () => {
|
|||||||
// TODO: Check for GQL request ?
|
// TODO: Check for GQL request ?
|
||||||
saveGraphqlRequestAs(
|
saveGraphqlRequestAs(
|
||||||
`${picked.value.collectionIndex}`,
|
`${picked.value.collectionIndex}`,
|
||||||
requestUpdated as HoppGQLRequest
|
updatedRequest as HoppGQLRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
:key="`method-${index}`"
|
:key="`method-${index}`"
|
||||||
:label="method"
|
:label="method"
|
||||||
:style="{
|
:style="{
|
||||||
color: getMethodLabelColorClassOf({ method }),
|
color: getMethodLabelColor(method),
|
||||||
}"
|
}"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
@@ -262,7 +262,7 @@ import { InterceptorService } from "~/services/interceptor.service"
|
|||||||
import { HoppTab } from "~/services/tab"
|
import { HoppTab } from "~/services/tab"
|
||||||
import { HoppRESTDocument } from "~/helpers/rest/document"
|
import { HoppRESTDocument } from "~/helpers/rest/document"
|
||||||
import { RESTTabService } from "~/services/tab/rest"
|
import { RESTTabService } from "~/services/tab/rest"
|
||||||
import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring"
|
import { getMethodLabelColor } from "~/helpers/rest/labelColoring"
|
||||||
import { WorkspaceService } from "~/services/workspace.service"
|
import { WorkspaceService } from "~/services/workspace.service"
|
||||||
import { NewWorkspaceService } from "~/services/new-workspace"
|
import { NewWorkspaceService } from "~/services/new-workspace"
|
||||||
|
|
||||||
@@ -539,7 +539,7 @@ const saveRequest = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const requestHandleResult = await newWorkspaceService.getRequestHandle(
|
const requestHandleResult = await newWorkspaceService.getRequestHandle(
|
||||||
collHandle,
|
newWorkspaceService.activeWorkspaceHandle.value,
|
||||||
`${saveCtx.folderPath}/${saveCtx.requestIndex.toString()}`
|
`${saveCtx.folderPath}/${saveCtx.requestIndex.toString()}`
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ const saveRequest = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedRequestResult = await newWorkspaceService.saveRESTRequest(
|
const updatedRequestResult = await newWorkspaceService.updateRESTRequest(
|
||||||
requestHandle,
|
requestHandle,
|
||||||
updatedRequest
|
updatedRequest
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -335,16 +335,17 @@ const onAddRequest = async (requestName: string) => {
|
|||||||
|
|
||||||
const result = await workspaceService.createRESTRequest(
|
const result = await workspaceService.createRESTRequest(
|
||||||
collHandle,
|
collHandle,
|
||||||
requestName
|
requestName,
|
||||||
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_WORKSPACE_HANDLE
|
// INVALID_COLLECTION_HANDLE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.right.value.type === "invalid") {
|
if (result.right.value.type === "invalid") {
|
||||||
// WORKSPACE_INVALIDATED
|
// COLLECTION_INVALIDATED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,28 +552,10 @@ const removeRequest = (requestIndexPath: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onRemoveRequest = async () => {
|
const onRemoveRequest = async () => {
|
||||||
const parentCollIndexPath = editingCollIndexPath.value
|
|
||||||
const requestIndexPath = editingRequestIndexPath.value
|
const requestIndexPath = editingRequestIndexPath.value
|
||||||
|
|
||||||
const parentCollHandleResult = await workspaceService.getCollectionHandle(
|
|
||||||
props.workspaceHandle,
|
|
||||||
parentCollIndexPath
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(parentCollHandleResult)) {
|
|
||||||
// INVALID_WORKSPACE_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentCollHandle = parentCollHandleResult.right
|
|
||||||
|
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
parentCollHandle,
|
props.workspaceHandle,
|
||||||
requestIndexPath
|
requestIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -607,25 +590,8 @@ const onRemoveRequest = async () => {
|
|||||||
const selectRequest = async (requestIndexPath: string) => {
|
const selectRequest = async (requestIndexPath: string) => {
|
||||||
const collIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collIndexPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
|
||||||
props.workspaceHandle,
|
|
||||||
collIndexPath
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
|
||||||
// INVALID_WORKSPACE_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
collHandle,
|
props.workspaceHandle,
|
||||||
requestIndexPath
|
requestIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -679,25 +645,8 @@ const selectRequest = async (requestIndexPath: string) => {
|
|||||||
const duplicateRequest = async (requestIndexPath: string) => {
|
const duplicateRequest = async (requestIndexPath: string) => {
|
||||||
const collPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
const collPath = requestIndexPath.split("/").slice(0, -1).join("/")
|
||||||
|
|
||||||
const collHandleResult = await workspaceService.getCollectionHandle(
|
|
||||||
props.workspaceHandle,
|
|
||||||
collPath
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(collHandleResult)) {
|
|
||||||
// INVALID_WORKSPACE_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const collHandle = collHandleResult.right
|
|
||||||
|
|
||||||
if (collHandle.value.type === "invalid") {
|
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
collHandle,
|
props.workspaceHandle,
|
||||||
requestIndexPath
|
requestIndexPath
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -742,28 +691,10 @@ const editRequest = (payload: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onEditRequest = async (newReqName: string) => {
|
const onEditRequest = async (newReqName: string) => {
|
||||||
const parentCollID = editingCollIndexPath.value
|
|
||||||
const requestID = editingRequestIndexPath.value
|
const requestID = editingRequestIndexPath.value
|
||||||
|
|
||||||
const parentCollHandleResult = await workspaceService.getCollectionHandle(
|
|
||||||
props.workspaceHandle,
|
|
||||||
parentCollID
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(parentCollHandleResult)) {
|
|
||||||
// INVALID_WORKSPACE_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const parentCollHandle = parentCollHandleResult.right
|
|
||||||
|
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
|
||||||
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestHandleResult = await workspaceService.getRequestHandle(
|
const requestHandleResult = await workspaceService.getRequestHandle(
|
||||||
parentCollHandle,
|
props.workspaceHandle,
|
||||||
requestID
|
requestID
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -779,9 +710,14 @@ const onEditRequest = async (newReqName: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await workspaceService.editRESTRequest(
|
const updatedRequest = {
|
||||||
|
...requestHandle.value.data.request,
|
||||||
|
name: newReqName,
|
||||||
|
} as HoppRESTRequest
|
||||||
|
|
||||||
|
const result = await workspaceService.updateRESTRequest(
|
||||||
requestHandle,
|
requestHandle,
|
||||||
newReqName
|
updatedRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -818,7 +754,7 @@ const editCollectionProperties = async (collIndexPath: string) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
} as HoppInheritedProperty
|
} as HoppInheritedProperty
|
||||||
|
// Have a provider level implementation that returns a view that says what the headesd and auth are
|
||||||
if (parentIndex) {
|
if (parentIndex) {
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||||
parentIndex,
|
parentIndex,
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getRequestHandle(
|
public async getRequestHandle(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
requestID: string
|
requestID: string
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
@@ -147,19 +147,19 @@ export class NewWorkspaceService extends Service {
|
|||||||
HandleRef<WorkspaceRequest>
|
HandleRef<WorkspaceRequest>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
if (workspaceHandle.value.type === "invalid") {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
const provider = this.registeredProviders.get(
|
||||||
parentCollHandle.value.data.providerID
|
workspaceHandle.value.data.providerID
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.getRequestHandle(parentCollHandle, requestID)
|
const result = await provider.getRequestHandle(workspaceHandle, requestID)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
@@ -240,7 +240,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceCollection>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collHandle.value.type === "invalid") {
|
||||||
@@ -273,7 +273,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceCollection>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collHandle.value.type === "invalid") {
|
||||||
@@ -306,7 +306,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceCollection>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collHandle.value.type === "invalid") {
|
||||||
@@ -338,7 +338,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceCollection>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (collHandle.value.type === "invalid") {
|
if (collHandle.value.type === "invalid") {
|
||||||
@@ -367,7 +367,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceCollection>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (parentCollHandle.value.type === "invalid") {
|
if (parentCollHandle.value.type === "invalid") {
|
||||||
@@ -393,7 +393,8 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
public async createRESTRequest(
|
public async createRESTRequest(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollHandle: HandleRef<WorkspaceCollection>,
|
||||||
requestName: string
|
requestName: string,
|
||||||
|
openInNewTab: boolean
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
@@ -414,7 +415,8 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
const result = await provider.createRESTRequest(
|
const result = await provider.createRESTRequest(
|
||||||
parentCollHandle,
|
parentCollHandle,
|
||||||
requestName
|
requestName,
|
||||||
|
openInNewTab
|
||||||
)
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
@@ -429,7 +431,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceRequest>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (requestHandle.value.type === "invalid") {
|
if (requestHandle.value.type === "invalid") {
|
||||||
@@ -453,43 +455,13 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.right(result.right)
|
return E.right(result.right)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async editRESTRequest(
|
public async updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
|
||||||
newRequestName: string
|
|
||||||
): Promise<
|
|
||||||
E.Either<
|
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
|
||||||
HandleRef<WorkspaceRequest>
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
if (requestHandle.value.type === "invalid") {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider = this.registeredProviders.get(
|
|
||||||
requestHandle.value.data.providerID
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!provider) {
|
|
||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await provider.editRESTRequest(requestHandle, newRequestName)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
|
||||||
}
|
|
||||||
|
|
||||||
return E.right(result.right)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async saveRESTRequest(
|
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: HoppRESTRequest
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<
|
E.Either<
|
||||||
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
|
||||||
HandleRef<WorkspaceRequest>
|
HandleRef<boolean>
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
if (requestHandle.value.type === "invalid") {
|
if (requestHandle.value.type === "invalid") {
|
||||||
@@ -504,7 +476,10 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.saveRESTRequest(requestHandle, updatedRequest)
|
const result = await provider.updateRESTRequest(
|
||||||
|
requestHandle,
|
||||||
|
updatedRequest
|
||||||
|
)
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ import {
|
|||||||
WorkspaceRequest,
|
WorkspaceRequest,
|
||||||
} from "./workspace"
|
} from "./workspace"
|
||||||
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
import { RESTCollectionChildrenView, RootRESTCollectionView } from "./view"
|
||||||
import { HoppRESTAuth, HoppRESTHeaders, HoppRESTRequest } from "@hoppscotch/data"
|
import {
|
||||||
|
HoppRESTAuth,
|
||||||
|
HoppRESTHeaders,
|
||||||
|
HoppRESTRequest,
|
||||||
|
} from "@hoppscotch/data"
|
||||||
|
|
||||||
export type UpdatedCollectionProperties = {
|
export type UpdatedCollectionProperties = {
|
||||||
auth: HoppRESTAuth
|
auth: HoppRESTAuth
|
||||||
@@ -28,7 +32,7 @@ export interface WorkspaceProvider {
|
|||||||
collectionID: string
|
collectionID: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
getRequestHandle(
|
getRequestHandle(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
requestID: string
|
requestID: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
||||||
|
|
||||||
@@ -38,6 +42,9 @@ export interface WorkspaceProvider {
|
|||||||
getRESTCollectionChildrenView(
|
getRESTCollectionChildrenView(
|
||||||
collectionHandle: HandleRef<WorkspaceCollection>
|
collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<RESTCollectionChildrenView>>>
|
): Promise<E.Either<unknown, HandleRef<RESTCollectionChildrenView>>>
|
||||||
|
// getRESTCollectionAuthHeaders(
|
||||||
|
// collectionHandle: HandleRef<WorkspaceCollection>
|
||||||
|
// ): Promise<E.Either<unknown, HandleRef<RESTCollectionAuthHeadersView>>>
|
||||||
|
|
||||||
createRESTRootCollection(
|
createRESTRootCollection(
|
||||||
workspaceHandle: HandleRef<Workspace>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
@@ -50,34 +57,31 @@ export interface WorkspaceProvider {
|
|||||||
editRESTRootCollection(
|
editRESTRootCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
newCollectionName: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
editRESTChildCollection(
|
editRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
newCollectionName: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
editRESTCollectionProperties(
|
editRESTCollectionProperties(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollHandle: HandleRef<WorkspaceCollection>,
|
||||||
updatedCollProps: UpdatedCollectionProperties
|
updatedCollProps: UpdatedCollectionProperties
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
removeRESTRootCollection(
|
removeRESTRootCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>
|
collHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
removeRESTChildCollection(
|
removeRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>
|
parentCollHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
createRESTRequest(
|
createRESTRequest(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollHandle: HandleRef<WorkspaceCollection>,
|
||||||
requestName: string
|
requestName: string,
|
||||||
|
openInNewTab: boolean
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>>
|
||||||
removeRESTRequest(
|
removeRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>
|
requestHandle: HandleRef<WorkspaceRequest>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
editRESTRequest(
|
updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
|
||||||
newRequestName: string
|
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
|
||||||
saveRESTRequest(
|
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: HoppRESTRequest
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>>
|
): Promise<E.Either<unknown, HandleRef<boolean>>>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { HoppCollection, makeCollection } from "@hoppscotch/data"
|
import {
|
||||||
|
HoppCollection,
|
||||||
|
isHoppRESTRequest,
|
||||||
|
makeCollection,
|
||||||
|
} from "@hoppscotch/data"
|
||||||
import { Service } from "dioc"
|
import { Service } from "dioc"
|
||||||
import * as E from "fp-ts/Either"
|
import * as E from "fp-ts/Either"
|
||||||
import { Ref, computed, markRaw, nextTick, ref, shallowRef } from "vue"
|
import { Ref, computed, markRaw, nextTick, ref, shallowRef } from "vue"
|
||||||
@@ -148,7 +152,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
data: {
|
data: {
|
||||||
providerID: this.providerID,
|
providerID: this.providerID,
|
||||||
workspaceID: workspaceHandle.value.data.workspaceID,
|
workspaceID: workspaceHandle.value.data.workspaceID,
|
||||||
collectionID: "",
|
collectionID: "", // Compute this and supply
|
||||||
collection: newRootCollection,
|
collection: newRootCollection,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -217,7 +221,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
public editRESTRootCollection(
|
public editRESTRootCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
newCollectionName: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
collHandle.value.type !== "ok" ||
|
collHandle.value.type !== "ok" ||
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
collHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -240,8 +244,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collection, collectionID, providerID, workspaceID } =
|
const { collection, collectionID } = collHandle.value.data
|
||||||
collHandle.value.data
|
|
||||||
|
|
||||||
const updatedCollection = {
|
const updatedCollection = {
|
||||||
...(collection as HoppCollection),
|
...(collection as HoppCollection),
|
||||||
@@ -253,12 +256,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
collection: updatedCollection,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -268,7 +266,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
public editRESTChildCollection(
|
public editRESTChildCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collHandle: HandleRef<WorkspaceCollection>,
|
||||||
newCollectionName: string
|
newCollectionName: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
collHandle.value.type !== "ok" ||
|
collHandle.value.type !== "ok" ||
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
collHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -291,8 +289,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collection, collectionID, providerID, workspaceID } =
|
const { collection, collectionID } = collHandle.value.data
|
||||||
collHandle.value.data
|
|
||||||
|
|
||||||
const updatedCollection = {
|
const updatedCollection = {
|
||||||
...(collection as HoppCollection),
|
...(collection as HoppCollection),
|
||||||
@@ -303,12 +300,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
collection: updatedCollection,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -318,7 +310,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
public editRESTCollectionProperties(
|
public editRESTCollectionProperties(
|
||||||
collHandle: HandleRef<WorkspaceCollection>,
|
collHandle: HandleRef<WorkspaceCollection>,
|
||||||
updatedCollProps: UpdatedCollectionProperties
|
updatedCollProps: UpdatedCollectionProperties
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
collHandle.value.type !== "ok" ||
|
collHandle.value.type !== "ok" ||
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
collHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -341,8 +333,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collection, collectionID, providerID, workspaceID } =
|
const { collection, collectionID } = collHandle.value.data
|
||||||
collHandle.value.data
|
|
||||||
|
|
||||||
const { auth, headers } = updatedCollProps
|
const { auth, headers } = updatedCollProps
|
||||||
|
|
||||||
@@ -376,12 +367,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
collection: updatedCollection,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -390,7 +376,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public removeRESTRootCollection(
|
public removeRESTRootCollection(
|
||||||
collHandle: HandleRef<WorkspaceCollection>
|
collHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
collHandle.value.type !== "ok" ||
|
collHandle.value.type !== "ok" ||
|
||||||
collHandle.value.data.providerID !== this.providerID ||
|
collHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -413,8 +399,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, workspaceID } =
|
const { collectionID } = collHandle.value.data
|
||||||
collHandle.value.data
|
|
||||||
|
|
||||||
const collectionIndex = parseInt(collectionID)
|
const collectionIndex = parseInt(collectionID)
|
||||||
|
|
||||||
@@ -437,12 +422,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
collection: null,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -451,7 +431,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public removeRESTChildCollection(
|
public removeRESTChildCollection(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>
|
parentCollHandle: HandleRef<WorkspaceCollection>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
parentCollHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
parentCollHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -474,8 +454,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, workspaceID } =
|
const { collectionID } = parentCollHandle.value.data
|
||||||
parentCollHandle.value.data
|
|
||||||
|
|
||||||
const folderToRemove = path
|
const folderToRemove = path
|
||||||
? navigateToFolderWithIndexPath(
|
? navigateToFolderWithIndexPath(
|
||||||
@@ -502,12 +481,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
collection: null,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -516,14 +490,15 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public createRESTRequest(
|
public createRESTRequest(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
parentCollHandle: HandleRef<WorkspaceCollection>,
|
||||||
requestName: string
|
requestName: string,
|
||||||
|
openInNewTab: boolean
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
parentCollHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
parentCollHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
parentCollHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
@@ -536,7 +511,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: "invalid" as const,
|
type: "invalid" as const,
|
||||||
reason: "WORKSPACE_INVALIDATED" as const,
|
reason: "COLLECTION_INVALIDATED" as const,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,24 +525,26 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
|
const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
|
||||||
|
|
||||||
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
if (openInNewTab) {
|
||||||
collectionID,
|
const { auth, headers } = cascadeParentCollectionForHeaderAuth(
|
||||||
"rest"
|
collectionID,
|
||||||
)
|
"rest"
|
||||||
|
)
|
||||||
|
|
||||||
this.tabs.createNewTab({
|
this.tabs.createNewTab({
|
||||||
request: newRequest,
|
request: newRequest,
|
||||||
isDirty: false,
|
isDirty: false,
|
||||||
saveContext: {
|
saveContext: {
|
||||||
originLocation: "user-collection",
|
originLocation: "user-collection",
|
||||||
folderPath: collectionID,
|
folderPath: collectionID,
|
||||||
requestIndex: insertionIndex,
|
requestIndex: insertionIndex,
|
||||||
},
|
},
|
||||||
inheritedProperties: {
|
inheritedProperties: {
|
||||||
auth,
|
auth,
|
||||||
headers,
|
headers,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
platform.analytics?.logEvent({
|
||||||
type: "HOPP_SAVE_REQUEST",
|
type: "HOPP_SAVE_REQUEST",
|
||||||
@@ -597,7 +574,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public removeRESTRequest(
|
public removeRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>
|
requestHandle: HandleRef<WorkspaceRequest>
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
requestHandle.value.type !== "ok" ||
|
requestHandle.value.type !== "ok" ||
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
requestHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -620,8 +597,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, requestID, workspaceID } =
|
const { collectionID, requestID } = requestHandle.value.data
|
||||||
requestHandle.value.data
|
|
||||||
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
|
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
|
||||||
|
|
||||||
const possibleTab = this.tabs.getTabRefWithSaveContext({
|
const possibleTab = this.tabs.getTabRefWithSaveContext({
|
||||||
@@ -656,90 +632,17 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
requestID,
|
|
||||||
request: null,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public editRESTRequest(
|
public updateRESTRequest(
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
|
||||||
newRequestName: string
|
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
|
||||||
if (
|
|
||||||
requestHandle.value.type !== "ok" ||
|
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
|
||||||
requestHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve(
|
|
||||||
E.right(
|
|
||||||
computed(() => {
|
|
||||||
if (
|
|
||||||
requestHandle.value.type !== "ok" ||
|
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
|
||||||
requestHandle.value.data.workspaceID !== "personal"
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
type: "invalid" as const,
|
|
||||||
reason: "REQUEST_INVALIDATED" as const,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const { collectionID, providerID, request, requestID, workspaceID } =
|
|
||||||
requestHandle.value.data
|
|
||||||
const requestIndexPath = requestID.split("/").slice(-1).join("")
|
|
||||||
|
|
||||||
const requestIndex = parseInt(requestIndexPath)
|
|
||||||
|
|
||||||
const updatedRequest = {
|
|
||||||
...request,
|
|
||||||
name: newRequestName || request?.name,
|
|
||||||
} as HoppRESTRequest
|
|
||||||
|
|
||||||
const possibleActiveTab = this.tabs.getTabRefWithSaveContext({
|
|
||||||
originLocation: "user-collection",
|
|
||||||
requestIndex,
|
|
||||||
folderPath: collectionID,
|
|
||||||
})
|
|
||||||
|
|
||||||
editRESTRequest(collectionID, requestIndex, updatedRequest)
|
|
||||||
|
|
||||||
if (possibleActiveTab) {
|
|
||||||
possibleActiveTab.value.document.request.name = updatedRequest.name
|
|
||||||
nextTick(() => {
|
|
||||||
possibleActiveTab.value.document.isDirty = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: "ok",
|
|
||||||
data: {
|
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
requestID,
|
|
||||||
request: updatedRequest,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public saveRESTRequest(
|
|
||||||
requestHandle: HandleRef<WorkspaceRequest>,
|
requestHandle: HandleRef<WorkspaceRequest>,
|
||||||
updatedRequest: HoppRESTRequest
|
updatedRequest: HoppRESTRequest
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
): Promise<E.Either<unknown, HandleRef<boolean>>> {
|
||||||
if (
|
if (
|
||||||
requestHandle.value.type !== "ok" ||
|
requestHandle.value.type !== "ok" ||
|
||||||
requestHandle.value.data.providerID !== this.providerID ||
|
requestHandle.value.data.providerID !== this.providerID ||
|
||||||
@@ -762,8 +665,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, requestID, workspaceID } =
|
const { collectionID, requestID } = requestHandle.value.data
|
||||||
requestHandle.value.data
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const requestIndex = parseInt(requestID)
|
const requestIndex = parseInt(requestID)
|
||||||
@@ -784,13 +686,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "ok",
|
type: "ok",
|
||||||
data: {
|
data: true,
|
||||||
providerID,
|
|
||||||
workspaceID,
|
|
||||||
collectionID,
|
|
||||||
requestID,
|
|
||||||
request: updatedRequest,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -859,13 +755,13 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getRequestHandle(
|
public getRequestHandle(
|
||||||
parentCollHandle: HandleRef<WorkspaceCollection>,
|
workspaceHandle: HandleRef<Workspace>,
|
||||||
requestID: string
|
requestID: string
|
||||||
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
workspaceHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
workspaceHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
workspaceHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||||
}
|
}
|
||||||
@@ -874,9 +770,9 @@ export class PersonalWorkspaceProviderService
|
|||||||
E.right(
|
E.right(
|
||||||
computed(() => {
|
computed(() => {
|
||||||
if (
|
if (
|
||||||
parentCollHandle.value.type !== "ok" ||
|
workspaceHandle.value.type !== "ok" ||
|
||||||
parentCollHandle.value.data.providerID !== this.providerID ||
|
workspaceHandle.value.data.providerID !== this.providerID ||
|
||||||
parentCollHandle.value.data.workspaceID !== "personal"
|
workspaceHandle.value.data.workspaceID !== "personal"
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: "invalid" as const,
|
type: "invalid" as const,
|
||||||
@@ -891,11 +787,12 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { collectionID, providerID, workspaceID } = parentCollHandle.value.data
|
const { providerID, workspaceID } = workspaceHandle.value.data
|
||||||
|
|
||||||
|
const collectionID = requestID.split("/").slice(0, -1).join("/")
|
||||||
const requestIndexPath = requestID.split("/").slice(-1)[0]
|
const requestIndexPath = requestID.split("/").slice(-1)[0]
|
||||||
|
|
||||||
if (!collectionID || !requestIndexPath) {
|
if (!requestIndexPath) {
|
||||||
return {
|
return {
|
||||||
type: "invalid" as const,
|
type: "invalid" as const,
|
||||||
reason: "INVALID_REQUEST_HANDLE" as const,
|
reason: "INVALID_REQUEST_HANDLE" as const,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Ref } from "vue"
|
|||||||
export type RESTCollectionViewCollection = {
|
export type RESTCollectionViewCollection = {
|
||||||
collectionID: string
|
collectionID: string
|
||||||
|
|
||||||
collection: HoppCollection
|
collection: HoppCollection // Should not store children including folders and requests
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RESTCollectionViewRequest = {
|
export type RESTCollectionViewRequest = {
|
||||||
|
|||||||
Reference in New Issue
Block a user