refactor: move more things to handles instead of handleref

This commit is contained in:
Andrew Bastin
2024-05-08 22:59:03 +05:30
committed by jamesgeorge007
parent 2f2273ee2c
commit c8f0142b16
17 changed files with 398 additions and 372 deletions

View File

@@ -368,8 +368,10 @@ watch(
const newWorkspaceService = useService(NewWorkspaceService)
const activeWorkspaceName = computed(() => {
if (newWorkspaceService.activeWorkspaceHandle.value?.value.type === "ok") {
return newWorkspaceService.activeWorkspaceHandle.value?.value.data.name
const activeWorkspaceHandleRef = newWorkspaceService.activeWorkspaceHandle.value?.get()
if (activeWorkspaceHandleRef?.value.type === "ok") {
return activeWorkspaceHandleRef.value.data.name
}
return t("workspace.no_workspace")

View File

@@ -245,11 +245,6 @@ const saveRequestAs = async () => {
const collectionHandle = collectionHandleResult.right
if (collectionHandle.value.type === "invalid") {
// WORKSPACE_INVALIDATED
return
}
const requestHandleResult = await workspaceService.createRESTRequest(
collectionHandle,
updatedRequest

View File

@@ -20,8 +20,6 @@ import { useVModel } from "@vueuse/core"
import { cloneDeep, isEqual } from "lodash-es"
import { HoppTab } from "~/services/tab"
import { HoppRESTDocument } from "~/helpers/rest/document"
import { WorkspaceRequest } from "~/services/new-workspace/workspace"
import { HandleRef } from "~/services/new-workspace/handle"
// TODO: Move Response and Request execution code to over here
@@ -43,24 +41,23 @@ watch(
tab.value.document.saveContext?.originLocation ===
"workspace-user-collection"
) {
const requestHandle = tab.value.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandleRef =
tab.value.document.saveContext.requestHandle?.get()
if (!requestHandle || requestHandle.type === "invalid") {
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return
}
if (
!tab.value.document.isDirty &&
!isEqual(oldRequest, requestHandle?.data.request)
!isEqual(oldRequest, requestHandleRef?.value.data.request)
) {
tab.value.document.isDirty = true
}
if (
tab.value.document.isDirty &&
isEqual(oldRequest, requestHandle?.data.request)
isEqual(oldRequest, requestHandleRef?.value.data.request)
) {
tab.value.document.isDirty = false
}

View File

@@ -514,7 +514,7 @@ import { platform } from "~/platform"
import { NewWorkspaceService } from "~/services/new-workspace"
import { HandleRef } from "~/services/new-workspace/handle"
import { RESTCollectionViewRequest } from "~/services/new-workspace/view"
import { Workspace, WorkspaceRequest } from "~/services/new-workspace/workspace"
import { Workspace } from "~/services/new-workspace/workspace"
import { RESTTabService } from "~/services/tab/rest"
import IconImport from "~icons/lucide/folder-down"
import IconHelpCircle from "~icons/lucide/help-circle"
@@ -1110,12 +1110,7 @@ const selectRequest = async (requestIndexPath: string) => {
return
}
const collectionHandle = collectionHandleResult.right.get()
if (collectionHandle.value.type === "invalid") {
// WORKSPACE_INVALIDATED | INVALID_COLLECTION_HANDLE
return
}
const collectionHandle = collectionHandleResult.right
const requestHandleResult = await workspaceService.getRequestHandle(
props.workspaceHandle,
@@ -1127,12 +1122,7 @@ const selectRequest = async (requestIndexPath: string) => {
return
}
const requestHandle = requestHandleResult.right.get()
if (requestHandle.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
const requestHandle = requestHandleResult.right
const cascadingAuthHeadersHandleResult =
await workspaceService.getRESTCollectionLevelAuthHeadersView(
@@ -1163,9 +1153,11 @@ const selectRequest = async (requestIndexPath: string) => {
if (possibleTab) {
tabs.setActiveTab(possibleTab.value.id)
} else {
const requestHandleRef = requestHandle.get()
// If not, open the request in a new tab
tabs.createNewTab({
request: requestHandle.value.data.request,
request: requestHandleRef.value.data.request,
isDirty: false,
saveContext: {
originLocation: "workspace-user-collection",
@@ -1640,12 +1632,7 @@ const dropRequest = async (payload: {
return
}
const requestHandle = requestHandleResult.right.get()
if (requestHandle.value.type === "invalid") {
// COLLECTION_INVALIDATED
return
}
const requestHandle = requestHandleResult.right
const result = await workspaceService.moveRESTRequest(
requestHandle,
@@ -1667,12 +1654,7 @@ const dropRequest = async (payload: {
return
}
const collectionHandle = collectionHandleResult.right.get()
if (collectionHandle.value.type === "invalid") {
// WORKSPACE_INVALIDATED
return
}
const collectionHandle = collectionHandleResult.right
const cascadingAuthHeadersHandleResult =
await workspaceService.getRESTCollectionLevelAuthHeadersView(
@@ -2098,18 +2080,20 @@ const isActiveRequest = (requestView: RESTCollectionViewRequest) => {
return false
}
// TODO: Investigate why requestHandle is available unwrapped here
const requestHandle = tabs.currentActiveTab.value.document.saveContext
.requestHandle as HandleRef<WorkspaceRequest>["value"] | undefined
const requestHandle =
tabs.currentActiveTab.value.document.saveContext.requestHandle
if (!requestHandle) {
return false
}
if (requestHandle.type === "invalid") {
const requestHandleRef = requestHandle.get()
if (requestHandleRef.value.type === "invalid") {
return false
}
return requestHandle.data.requestID === requestView.requestID
return requestHandleRef.value.data.requestID === requestView.requestID
}
const onSelectPick = (payload: Picked | null) => {

View File

@@ -26,8 +26,10 @@ const workspaceService = useService(NewWorkspaceService)
const activeWorkspaceHandle = workspaceService.activeWorkspaceHandle
const workspaceName = computed(() => {
if (activeWorkspaceHandle.value?.value.type === "ok") {
return activeWorkspaceHandle.value.value.data.name
const activeWorkspaceHandleRef = activeWorkspaceHandle.value?.get()
if (activeWorkspaceHandleRef?.value.type === "ok") {
return activeWorkspaceHandleRef.value.data.name
}
return undefined

View File

@@ -34,12 +34,13 @@ const personalWorkspaceProviderService = useService(
)
const activeWorkspaceInfo = computed(() => {
const activeWorkspace = workspaceService.activeWorkspaceHandle.value
const activeWorkspaceHandleRef =
workspaceService.activeWorkspaceHandle.value?.get()
if (activeWorkspace?.value.type === "ok") {
if (activeWorkspaceHandleRef?.value.type === "ok") {
return {
provider: activeWorkspace.value.data.providerID,
workspaceID: activeWorkspace.value.data.workspaceID,
provider: activeWorkspaceHandleRef.value.data.providerID,
workspaceID: activeWorkspaceHandleRef.value.data.workspaceID,
}
}
@@ -48,6 +49,6 @@ const activeWorkspaceInfo = computed(() => {
function selectWorkspace() {
workspaceService.activeWorkspaceHandle.value =
personalWorkspaceProviderService.getPersonalWorkspaceHandle().get()
personalWorkspaceProviderService.getPersonalWorkspaceHandle()
}
</script>

View File

@@ -37,12 +37,13 @@ const testWorkspaceProviderService = useService(TestWorkspaceProviderService)
const candidates = testWorkspaceProviderService.getWorkspaceCandidates()
const activeWorkspaceInfo = computed(() => {
const activeWorkspace = workspaceService.activeWorkspaceHandle.value
const activeWorkspaceHandle = workspaceService.activeWorkspaceHandle.value
const activeWorkspaceHandleRef = activeWorkspaceHandle?.get()
if (activeWorkspace?.value.type === "ok") {
if (activeWorkspaceHandleRef?.value.type === "ok") {
return {
provider: activeWorkspace.value.data.providerID,
workspaceID: activeWorkspace.value.data.workspaceID,
provider: activeWorkspaceHandleRef.value.data.providerID,
workspaceID: activeWorkspaceHandleRef.value.data.workspaceID,
}
}
@@ -59,6 +60,6 @@ async function selectWorkspace(workspaceID: string) {
return
}
workspaceService.activeWorkspaceHandle.value = result.right.get()
workspaceService.activeWorkspaceHandle.value = result.right
}
</script>

View File

@@ -5,7 +5,7 @@ import {
import * as E from "fp-ts/Either"
import { Ref, ref, watchEffect } from "vue"
import { NewWorkspaceService } from "~/services/new-workspace"
import { HandleRef } from "~/services/new-workspace/handle"
import { Handle } from "~/services/new-workspace/handle"
import { RESTCollectionViewItem } from "~/services/new-workspace/view"
import { Workspace } from "~/services/new-workspace/workspace"
@@ -13,7 +13,7 @@ export class WorkspaceRESTCollectionTreeAdapter
implements SmartTreeAdapter<RESTCollectionViewItem>
{
constructor(
private workspaceHandle: HandleRef<Workspace>,
private workspaceHandle: Handle<Workspace>,
private workspaceService: NewWorkspaceService
) {}
@@ -21,7 +21,9 @@ export class WorkspaceRESTCollectionTreeAdapter
nodeID: string | null,
nodeType?: string
): Ref<ChildrenResult<RESTCollectionViewItem>> {
if (this.workspaceHandle.value.type !== "ok") {
const workspaceHandleRef = this.workspaceHandle.get()
if (workspaceHandleRef.value.type !== "ok") {
throw new Error("Cannot issue children with invalid workspace handle")
}
@@ -50,7 +52,7 @@ export class WorkspaceRESTCollectionTreeAdapter
throw new Error(JSON.stringify(collectionHandleResult.left.error))
}
const collectionHandle = collectionHandleResult.right.get()
const collectionHandle = collectionHandleResult.right
const collectionChildrenResult =
await this.workspaceService.getRESTCollectionChildrenView(

View File

@@ -9,8 +9,6 @@ import { runGQLQuery } from "../backend/GQLClient"
import { GetSingleRequestDocument } from "../backend/graphql"
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
import { getAffectedIndexes } from "./affectedIndex"
import { WorkspaceRequest } from "~/services/new-workspace/workspace"
import { HandleRef } from "~/services/new-workspace/handle"
/**
* Resolve save context on reorder
@@ -67,15 +65,13 @@ export function resolveSaveContextOnCollectionReorder(payload: {
return false
}
const requestHandle = tab.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandleRef = tab.document.saveContext.requestHandle?.get()
if (!requestHandle || requestHandle.type === "invalid") {
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return false
}
const { requestID } = requestHandle.data
const { requestID } = requestHandleRef.value.data
const collectionID = requestID.split("/").slice(0, -1).join("/")
@@ -97,15 +93,13 @@ export function resolveSaveContextOnCollectionReorder(payload: {
return false
}
const requestHandle = tab.value.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandleRef = tab.value.document.saveContext.requestHandle?.get()
if (!requestHandle || requestHandle.type === "invalid") {
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return false
}
const { requestID } = requestHandle.data
const { requestID } = requestHandleRef.value.data
const collectionID = requestID.split("/").slice(0, -1).join("/")
@@ -114,8 +108,8 @@ export function resolveSaveContextOnCollectionReorder(payload: {
requestID.split("/").slice(-1)[0]
}`
requestHandle.data = {
...requestHandle.data,
requestHandleRef.value.data = {
...requestHandleRef.value.data,
collectionID: newCollectionID!,
requestID: newRequestID,
}
@@ -159,15 +153,13 @@ export function updateSaveContextForAffectedRequests(
if (
tab.document.saveContext?.originLocation === "workspace-user-collection"
) {
const requestHandle = tab.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandleRef = tab.document.saveContext.requestHandle?.get()
if (!requestHandle || requestHandle.type === "invalid") {
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return false
}
const { requestID } = requestHandle.data
const { requestID } = requestHandleRef.value.data
const collectionID = requestID.split("/").slice(0, -1).join("/")
const requestIndex = requestID.split("/").slice(-1)[0]
@@ -184,8 +176,8 @@ export function updateSaveContextForAffectedRequests(
requestID: newRequestID,
}
requestHandle.data = {
...requestHandle.data,
requestHandleRef.value.data = {
...requestHandleRef.value.data,
collectionID: newCollectionID,
requestID: newRequestID,
}
@@ -268,7 +260,7 @@ export function updateInheritedPropertiesForAffectedRequests(
}
const collectionID = tab.document.saveContext?.requestID
.split("/")
?.split("/")
.slice(0, -1)
.join("/")
@@ -359,65 +351,6 @@ export function updateInheritedPropertiesForAffectedRequests(
})
}
function resetSaveContextForAffectedRequests(folderPath: string) {
const tabService = getService(RESTTabService)
const tabs = tabService.getTabsRefTo((tab) => {
if (tab.document.saveContext?.originLocation === "user-collection") {
return tab.document.saveContext.folderPath.startsWith(folderPath)
}
if (
tab.document.saveContext?.originLocation !== "workspace-user-collection"
) {
return false
}
const requestHandle = tab.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
if (!requestHandle || requestHandle.type === "invalid") {
return false
}
const { requestID } = requestHandle.data
const collectionID = requestID.split("/").slice(0, -1).join("/")
return collectionID.startsWith(folderPath)
})
for (const tab of tabs) {
if (tab.value.document.saveContext?.originLocation === "user-collection") {
tab.value.document.saveContext = null
tab.value.document.isDirty = true
return
}
if (
tab.value.document.saveContext?.originLocation ===
"workspace-user-collection"
) {
const requestHandle = tab.value.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
if (!requestHandle || requestHandle.type === "invalid") {
return
}
// @ts-expect-error - Removing the `data` property
delete requestHandle.data
// @ts-expect-error - Updating the type
requestHandle.type = "invalid"
// @ts-expect-error - Specifying the reason
requestHandle.reason = "REQUEST_INVALIDATED"
}
}
}
/**
* Reset save context to null if requests are deleted from the team collection or its folder
* only runs when collection or folder is deleted

View File

@@ -5,8 +5,6 @@ import {
} from "@hoppscotch/data"
import { getService } from "~/modules/dioc"
import { HandleRef } from "~/services/new-workspace/handle"
import { WorkspaceRequest } from "~/services/new-workspace/workspace"
import { RESTTabService } from "~/services/tab/rest"
import { getAffectedIndexes } from "./affectedIndex"
@@ -55,15 +53,13 @@ export function resolveSaveContextOnRequestReorder(payload: {
return false
}
const requestHandle = tab.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandleRef = tab.document.saveContext.requestHandle?.get()
if (!requestHandle || requestHandle.type === "invalid") {
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return false
}
const { requestID } = requestHandle.data
const { requestID } = requestHandleRef.value.data
const collectionID = requestID.split("/").slice(0, -1).join("/")
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
@@ -85,15 +81,13 @@ export function resolveSaveContextOnRequestReorder(payload: {
return
}
const requestHandle = tab.value.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandleRef = tab.value.document.saveContext.requestHandle?.get()
if (!requestHandle || requestHandle.type === "invalid") {
if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return
}
const { requestID } = requestHandle.data
const { requestID } = requestHandleRef.value.data
const requestIDArr = requestID.split("/")
const requestIndex = affectedIndices.get(
@@ -102,8 +96,10 @@ export function resolveSaveContextOnRequestReorder(payload: {
requestIDArr[requestIDArr.length - 1] = requestIndex.toString()
requestHandle.data.requestID = requestIDArr.join("/")
requestHandle.data.collectionID = requestIDArr.slice(0, -1).join("/")
requestHandleRef.value.data.requestID = requestIDArr.join("/")
requestHandleRef.value.data.collectionID = requestIDArr
.slice(0, -1)
.join("/")
}
}

View File

@@ -3,7 +3,7 @@ import { HoppRESTResponse } from "../types/HoppRESTResponse"
import { HoppTestResult } from "../types/HoppTestResult"
import { RESTOptionTabs } from "~/components/http/RequestOptions.vue"
import { HoppInheritedProperty } from "../types/HoppInheritedProperties"
import { HandleRef } from "~/services/new-workspace/handle"
import { Handle } from "~/services/new-workspace/handle"
import { WorkspaceRequest } from "~/services/new-workspace/workspace"
export type HoppRESTSaveContext =
@@ -31,7 +31,7 @@ export type HoppRESTSaveContext =
/**
* Handle to the request open in the tab
*/
requestHandle?: HandleRef<WorkspaceRequest>
requestHandle?: Handle<WorkspaceRequest>
}
| {
/**

View File

@@ -0,0 +1,17 @@
/**
* Create a function that will only run the given function once and caches the result.
*/
export function lazy<T>(fn: () => T): () => T {
let funcRan = false
let result: T | null = null
return () => {
if (!funcRan) {
result = fn()
funcRan = true
return result
}
return result!
}
}

View File

@@ -10,7 +10,7 @@ import {
shallowRef,
watch,
} from "vue"
import { Handle, HandleRef } from "./handle"
import { Handle } from "./handle"
import { WorkspaceProvider } from "./provider"
import {
RESTCollectionChildrenView,
@@ -32,16 +32,18 @@ export class NewWorkspaceService extends Service {
new Map<string, WorkspaceProvider>()
)
public activeWorkspaceHandle: Ref<HandleRef<Workspace> | undefined> =
public activeWorkspaceHandle: Ref<Handle<Workspace> | undefined> =
shallowRef()
public activeWorkspaceDecor = computed(() => {
if (this.activeWorkspaceHandle.value?.value.type !== "ok") {
const activeWorkspaceHandleRef = this.activeWorkspaceHandle.value?.get()
if (activeWorkspaceHandleRef?.value.type !== "ok") {
return undefined
}
return this.registeredProviders.get(
this.activeWorkspaceHandle.value.value.data.providerID
activeWorkspaceHandleRef.value.data.providerID
)!.workspaceDecor
})
@@ -73,14 +75,16 @@ export class NewWorkspaceService extends Service {
return this.activeWorkspaceHandle.value
? [
this.activeWorkspaceHandle.value,
this.activeWorkspaceHandle.value.value,
this.activeWorkspaceHandle.value?.get(),
]
: [this.activeWorkspaceHandle.value]
},
() => {
if (!this.activeWorkspaceHandle.value) return
if (this.activeWorkspaceHandle.value.value.type === "invalid") {
const activeWorkspaceHandleRef = this.activeWorkspaceHandle.value.get()
if (activeWorkspaceHandleRef.value.type === "invalid") {
this.activeWorkspaceHandle.value = undefined
}
},
@@ -110,7 +114,7 @@ export class NewWorkspaceService extends Service {
}
public async getCollectionHandle(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collectionID: string
): Promise<
E.Either<
@@ -118,12 +122,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -143,7 +149,7 @@ export class NewWorkspaceService extends Service {
}
public async getRequestHandle(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
requestID: string
): Promise<
E.Either<
@@ -151,12 +157,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceRequest>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -173,7 +181,7 @@ export class NewWorkspaceService extends Service {
}
public async createRESTRootCollection(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
newCollection: Partial<Exclude<HoppCollection, "id">> & { name: string }
): Promise<
E.Either<
@@ -181,12 +189,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -206,7 +216,7 @@ export class NewWorkspaceService extends Service {
}
public async createRESTChildCollection(
parentCollectionHandle: HandleRef<WorkspaceCollection>,
parentCollectionHandle: Handle<WorkspaceCollection>,
newChildCollection: Partial<HoppCollection> & { name: string }
): Promise<
E.Either<
@@ -214,12 +224,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection>
>
> {
if (parentCollectionHandle.value.type === "invalid") {
const parentCollectionHandleRef = parentCollectionHandle.get()
if (parentCollectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
parentCollectionHandle.value.data.providerID
parentCollectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -239,17 +251,19 @@ export class NewWorkspaceService extends Service {
}
public async updateRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
updatedCollection: Partial<HoppCollection>
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -269,16 +283,18 @@ export class NewWorkspaceService extends Service {
}
public async removeRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -295,7 +311,7 @@ export class NewWorkspaceService extends Service {
}
public async createRESTRequest(
parentCollectionHandle: HandleRef<WorkspaceCollection>,
parentCollectionHandle: Handle<WorkspaceCollection>,
newRequest: HoppRESTRequest
): Promise<
E.Either<
@@ -303,12 +319,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceRequest>
>
> {
if (parentCollectionHandle.value.type === "invalid") {
const parentCollectionHandleRef = parentCollectionHandle.get()
if (parentCollectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
parentCollectionHandle.value.data.providerID
parentCollectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -328,16 +346,18 @@ export class NewWorkspaceService extends Service {
}
public async removeRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>
requestHandle: Handle<WorkspaceRequest>
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (requestHandle.value.type === "invalid") {
const requestHandleRef = requestHandle.get()
if (requestHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
requestHandle.value.data.providerID
requestHandleRef.value.data.providerID
)
if (!provider) {
@@ -354,17 +374,19 @@ export class NewWorkspaceService extends Service {
}
public async updateRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
updatedRequest: Partial<HoppRESTRequest>
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (requestHandle.value.type === "invalid") {
const requestHandleRef = requestHandle.get()
if (requestHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
requestHandle.value.data.providerID
requestHandleRef.value.data.providerID
)
if (!provider) {
@@ -384,7 +406,7 @@ export class NewWorkspaceService extends Service {
}
public async importRESTCollections(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collections: HoppCollection[]
): Promise<
E.Either<
@@ -392,12 +414,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -417,17 +441,19 @@ export class NewWorkspaceService extends Service {
}
public async exportRESTCollections(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collections: HoppCollection[]
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -447,17 +473,19 @@ export class NewWorkspaceService extends Service {
}
public async exportRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
collection: HoppCollection
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -477,17 +505,19 @@ export class NewWorkspaceService extends Service {
}
public async reorderRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -507,17 +537,19 @@ export class NewWorkspaceService extends Service {
}
public async moveRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -537,18 +569,20 @@ export class NewWorkspaceService extends Service {
}
public async reorderRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string,
destinationRequestID: string | null
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (requestHandle.value.type === "invalid") {
const requestHandleRef = requestHandle.get()
if (requestHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
requestHandle.value.data.providerID
requestHandleRef.value.data.providerID
)
if (!provider) {
@@ -569,17 +603,19 @@ export class NewWorkspaceService extends Service {
}
public async moveRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string
): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
> {
if (requestHandle.value.type === "invalid") {
const requestHandleRef = requestHandle.get()
if (requestHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
requestHandle.value.data.providerID
requestHandleRef.value.data.providerID
)
if (!provider) {
@@ -599,19 +635,21 @@ export class NewWorkspaceService extends Service {
}
public async getRESTCollectionChildrenView(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RESTCollectionChildrenView>
>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -629,19 +667,21 @@ export class NewWorkspaceService extends Service {
}
public async getRESTRootCollectionView(
workspaceHandle: HandleRef<Workspace>
workspaceHandle: Handle<Workspace>
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RootRESTCollectionView>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -658,19 +698,21 @@ export class NewWorkspaceService extends Service {
}
public async getRESTCollectionLevelAuthHeadersView(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RESTCollectionLevelAuthHeadersView>
>
> {
if (collectionHandle.value.type === "invalid") {
const collectionHandleRef = collectionHandle.get()
if (collectionHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID
collectionHandleRef.value.data.providerID
)
if (!provider) {
@@ -688,7 +730,7 @@ export class NewWorkspaceService extends Service {
}
public async getRESTSearchResultsView(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
searchQuery: Ref<string>
): Promise<
E.Either<
@@ -696,12 +738,14 @@ export class NewWorkspaceService extends Service {
Handle<RESTSearchResultsView>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {
@@ -721,19 +765,21 @@ export class NewWorkspaceService extends Service {
}
public async getRESTCollectionJSONView(
workspaceHandle: HandleRef<Workspace>
workspaceHandle: Handle<Workspace>
): Promise<
E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RESTCollectionJSONView>
>
> {
if (workspaceHandle.value.type === "invalid") {
const workspaceHandleRef = workspaceHandle.get()
if (workspaceHandleRef.value.type === "invalid") {
return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
}
const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID
workspaceHandleRef.value.data.providerID
)
if (!provider) {

View File

@@ -1,7 +1,7 @@
import { Ref } from "vue"
import * as E from "fp-ts/Either"
import { Handle, HandleRef } from "./handle"
import { Handle } from "./handle"
import {
Workspace,
WorkspaceCollection,
@@ -26,86 +26,86 @@ export interface WorkspaceProvider {
workspaceID: string
): Promise<E.Either<unknown, Handle<Workspace>>>
getCollectionHandle(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collectionID: string
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>>
getRequestHandle(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
requestID: string
): Promise<E.Either<unknown, Handle<WorkspaceRequest>>>
getRESTRootCollectionView(
workspaceHandle: HandleRef<Workspace>
workspaceHandle: Handle<Workspace>
): Promise<E.Either<never, Handle<RootRESTCollectionView>>>
getRESTCollectionChildrenView(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<E.Either<never, Handle<RESTCollectionChildrenView>>>
getRESTCollectionLevelAuthHeadersView(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<E.Either<never, Handle<RESTCollectionLevelAuthHeadersView>>>
getRESTSearchResultsView(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
searchQuery: Ref<string>
): Promise<E.Either<never, Handle<RESTSearchResultsView>>>
getRESTCollectionJSONView(
workspaceHandle: HandleRef<Workspace>
workspaceHandle: Handle<Workspace>
): Promise<E.Either<never, Handle<RESTCollectionJSONView>>>
createRESTRootCollection(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
newCollection: Partial<Exclude<HoppCollection, "id">> & { name: string }
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>>
createRESTChildCollection(
parentCollectionHandle: HandleRef<WorkspaceCollection>,
parentCollectionHandle: Handle<WorkspaceCollection>,
newChildCollection: Partial<HoppCollection> & { name: string }
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>>
updateRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
updatedCollection: Partial<HoppCollection>
): Promise<E.Either<unknown, void>>
removeRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<E.Either<unknown, void>>
createRESTRequest(
parentCollectionHandle: HandleRef<WorkspaceCollection>,
parentCollectionHandle: Handle<WorkspaceCollection>,
newRequest: HoppRESTRequest
): Promise<E.Either<unknown, Handle<WorkspaceRequest>>>
updateRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
updatedRequest: Partial<HoppRESTRequest>
): Promise<E.Either<unknown, void>>
removeRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>
requestHandle: Handle<WorkspaceRequest>
): Promise<E.Either<unknown, void>>
importRESTCollections(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collections: HoppCollection[]
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>>
exportRESTCollections(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collections: HoppCollection[]
): Promise<E.Either<unknown, void>>
exportRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
collection: HoppCollection
): Promise<E.Either<unknown, void>>
reorderRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null
): Promise<E.Either<unknown, void>>
moveRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null
): Promise<E.Either<unknown, void>>
reorderRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string,
destinationRequestID: string | null
): Promise<E.Either<unknown, void>>
moveRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string
): Promise<E.Either<unknown, void>>
}

View File

@@ -80,6 +80,7 @@ import {
isValidRequestHandle,
isValidWorkspaceHandle,
} from "../helpers"
import { lazy } from "~/helpers/utils/lazy"
export class PersonalWorkspaceProviderService
extends Service
@@ -128,10 +129,14 @@ export class PersonalWorkspaceProviderService
}
public createRESTRootCollection(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
newCollection: Partial<Exclude<HoppCollection, "id">> & { name: string }
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
const workspaceHandleRef = workspaceHandle.get()
if (
!isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
}
@@ -160,11 +165,11 @@ export class PersonalWorkspaceProviderService
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidWorkspaceHandle(
workspaceHandle,
workspaceHandleRef,
this.providerID,
"personal"
)
@@ -179,23 +184,26 @@ export class PersonalWorkspaceProviderService
type: "ok",
data: {
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
workspaceID: workspaceHandleRef.value.data.workspaceID,
collectionID: newCollectionID,
name: newCollectionName,
},
}
}),
})
),
})
)
}
public createRESTChildCollection(
parentCollectionHandle: HandleRef<WorkspaceCollection>,
parentCollectionHandle: Handle<WorkspaceCollection>,
newChildCollection: Partial<HoppCollection> & { name: string }
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
const parentCollectionHandleRef = parentCollectionHandle.get()
if (
!isValidCollectionHandle(
parentCollectionHandle,
parentCollectionHandleRef,
this.providerID,
"personal"
)
@@ -204,7 +212,7 @@ export class PersonalWorkspaceProviderService
}
const { collectionID, providerID, workspaceID } =
parentCollectionHandle.value.data
parentCollectionHandleRef.value.data
const newCollectionName = newChildCollection.name
addRESTFolder(newCollectionName, collectionID)
@@ -218,11 +226,11 @@ export class PersonalWorkspaceProviderService
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidCollectionHandle(
parentCollectionHandle,
parentCollectionHandleRef,
this.providerID,
"personal"
)
@@ -242,22 +250,25 @@ export class PersonalWorkspaceProviderService
name: newCollectionName,
},
}
}),
})
),
})
)
}
public updateRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
updatedCollection: Partial<HoppCollection>
): Promise<E.Either<unknown, void>> {
const collectionHandleRef = collectionHandle.get()
if (
!isValidCollectionHandle(collectionHandle, this.providerID, "personal")
!isValidCollectionHandle(collectionHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
const { collectionID } = collectionHandle.value.data
const { collectionID } = collectionHandleRef.value.data
const collection = navigateToFolderWithIndexPath(
this.restCollectionState.value.state,
@@ -278,15 +289,17 @@ export class PersonalWorkspaceProviderService
}
public removeRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<E.Either<unknown, void>> {
const collectionHandleRef = collectionHandle.get()
if (
!isValidCollectionHandle(collectionHandle, this.providerID, "personal")
!isValidCollectionHandle(collectionHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
const { collectionID } = collectionHandle.value.data
const { collectionID } = collectionHandleRef.value.data
const isRootCollection = collectionID.split("/").length === 1
const collectionIndex = parseInt(collectionID)
@@ -355,12 +368,14 @@ export class PersonalWorkspaceProviderService
}
public createRESTRequest(
parentCollectionHandle: HandleRef<WorkspaceCollection>,
parentCollectionHandle: Handle<WorkspaceCollection>,
newRequest: HoppRESTRequest
): Promise<E.Either<unknown, Handle<WorkspaceRequest>>> {
const parentCollectionHandleRef = parentCollectionHandle.get()
if (
!isValidCollectionHandle(
parentCollectionHandle,
parentCollectionHandleRef,
this.providerID,
"personal"
)
@@ -369,7 +384,7 @@ export class PersonalWorkspaceProviderService
}
const { collectionID, providerID, workspaceID } =
parentCollectionHandle.value.data
parentCollectionHandleRef.value.data
const insertionIndex = saveRESTRequestAs(collectionID, newRequest)
@@ -396,7 +411,7 @@ export class PersonalWorkspaceProviderService
const handle: HandleRef<WorkspaceRequest> = computed(() => {
if (
!isValidCollectionHandle(
parentCollectionHandle,
parentCollectionHandleRef,
this.providerID,
"personal"
)
@@ -446,17 +461,19 @@ export class PersonalWorkspaceProviderService
this.issuedHandles.push(writableHandle)
}
return Promise.resolve(E.right({ get: () => handle }))
return Promise.resolve(E.right({ get: lazy(() => handle) }))
}
public removeRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>
requestHandle: Handle<WorkspaceRequest>
): Promise<E.Either<unknown, void>> {
if (!isValidRequestHandle(requestHandle, this.providerID, "personal")) {
const requestHandleRef = requestHandle.get()
if (!isValidRequestHandle(requestHandleRef, this.providerID, "personal")) {
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
}
const { collectionID, requestID } = requestHandle.value.data
const { collectionID, requestID } = requestHandleRef.value.data
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
const requestToRemove = navigateToFolderWithIndexPath(
@@ -495,16 +512,18 @@ export class PersonalWorkspaceProviderService
}
public updateRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
updatedRequest: Partial<HoppRESTRequest>
): Promise<E.Either<unknown, void>> {
if (!isValidRequestHandle(requestHandle, this.providerID, "personal")) {
const requestHandleRef = requestHandle.get()
if (!isValidRequestHandle(requestHandleRef, this.providerID, "personal")) {
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
}
delete updatedRequest.id
const { collectionID, requestID, request } = requestHandle.value.data
const { collectionID, requestID, request } = requestHandleRef.value.data
const newRequest: HoppRESTRequest = merge(request, updatedRequest)
const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
@@ -532,10 +551,13 @@ export class PersonalWorkspaceProviderService
}
public importRESTCollections(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collections: HoppCollection[]
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
const workspaceHandleRef = workspaceHandle.get()
if (
!isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
}
@@ -547,11 +569,11 @@ export class PersonalWorkspaceProviderService
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidWorkspaceHandle(
workspaceHandle,
workspaceHandleRef,
this.providerID,
"personal"
)
@@ -566,21 +588,26 @@ export class PersonalWorkspaceProviderService
type: "ok",
data: {
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
workspaceID: workspaceHandleRef.value.data.workspaceID,
collectionID: newCollectionID,
name: newCollectionName,
},
}
}),
})
),
})
)
}
public exportRESTCollections(
workspaceHandle: HandleRef<WorkspaceCollection>,
workspaceHandle: Handle<WorkspaceCollection>,
collections: HoppCollection[]
): Promise<E.Either<unknown, void>> {
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
const workspaceHandleRef = workspaceHandle.get()
if (
!isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
@@ -590,11 +617,13 @@ export class PersonalWorkspaceProviderService
}
public exportRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
collection: HoppCollection
): Promise<E.Either<unknown, void>> {
const collectionHandleRef = collectionHandle.get()
if (
!isValidCollectionHandle(collectionHandle, this.providerID, "personal")
!isValidCollectionHandle(collectionHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
@@ -605,16 +634,18 @@ export class PersonalWorkspaceProviderService
}
public reorderRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null
): Promise<E.Either<unknown, void>> {
const collectionHandleRef = collectionHandle.get()
if (
!isValidCollectionHandle(collectionHandle, this.providerID, "personal")
!isValidCollectionHandle(collectionHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
const draggedCollectionIndex = collectionHandle.value.data.collectionID
const draggedCollectionIndex = collectionHandleRef.value.data.collectionID
updateRESTCollectionOrder(draggedCollectionIndex, destinationCollectionID)
@@ -622,17 +653,19 @@ export class PersonalWorkspaceProviderService
}
public moveRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>,
collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null
): Promise<E.Either<unknown, void>> {
const collectionHandleRef = collectionHandle.get()
if (
!isValidCollectionHandle(collectionHandle, this.providerID, "personal")
!isValidCollectionHandle(collectionHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
moveRESTFolder(
collectionHandle.value.data.collectionID,
collectionHandleRef.value.data.collectionID,
destinationCollectionID
)
@@ -640,15 +673,17 @@ export class PersonalWorkspaceProviderService
}
public reorderRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string,
destinationRequestID: string | null
): Promise<E.Either<unknown, void>> {
if (!isValidRequestHandle(requestHandle, this.providerID, "personal")) {
const requestHandleRef = requestHandle.get()
if (!isValidRequestHandle(requestHandleRef, this.providerID, "personal")) {
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
}
const draggedRequestIndex = requestHandle.value.data.requestID
const draggedRequestIndex = requestHandleRef.value.data.requestID
updateRESTRequestOrder(
this.pathToLastIndex(draggedRequestIndex),
@@ -660,14 +695,16 @@ export class PersonalWorkspaceProviderService
}
public moveRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>,
requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string
): Promise<E.Either<unknown, void>> {
if (!isValidRequestHandle(requestHandle, this.providerID, "personal")) {
const requestHandleRef = requestHandle.get()
if (!isValidRequestHandle(requestHandleRef, this.providerID, "personal")) {
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
}
const { requestID: draggedRequestID } = requestHandle.value.data
const { requestID: draggedRequestID } = requestHandleRef.value.data
const sourceCollectionID = draggedRequestID
.split("/")
.slice(0, -1)
@@ -762,21 +799,21 @@ export class PersonalWorkspaceProviderService
handle.value.data.requestID.split("/").slice(-1)[0]
)
// @ts-expect-error - Updating the request ID
this.issuedHandles[handleIdx].value.data = {
...handle.value.data,
requestID: `${sourceCollectionID}/${reqIndexPos - 1}`,
}
handle.value.data.requestID = `${sourceCollectionID}/${reqIndexPos - 1}`
})
return Promise.resolve(E.right(undefined))
}
public getCollectionHandle(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
collectionID: string
): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
const workspaceHandleRef = workspaceHandle.get()
if (
!isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
}
@@ -793,15 +830,15 @@ export class PersonalWorkspaceProviderService
return Promise.resolve(E.left("COLLECTION_NOT_FOUND"))
}
const { providerID, workspaceID } = workspaceHandle.value.data
const { providerID, workspaceID } = workspaceHandleRef.value.data
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidWorkspaceHandle(
workspaceHandle,
workspaceHandleRef,
this.providerID,
"personal"
)
@@ -821,16 +858,21 @@ export class PersonalWorkspaceProviderService
name: collection.name,
},
}
}),
})
),
})
)
}
public getRequestHandle(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
requestID: string
): Promise<E.Either<unknown, Handle<WorkspaceRequest>>> {
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
const workspaceHandleRef = workspaceHandle.get()
if (
!isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal")
) {
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
}
@@ -838,7 +880,7 @@ export class PersonalWorkspaceProviderService
return Promise.resolve(E.left("INVALID_REQUEST_ID" as const))
}
const { providerID, workspaceID } = workspaceHandle.value.data
const { providerID, workspaceID } = workspaceHandleRef.value.data
const collectionID = requestID.split("/").slice(0, -1).join("/")
const requestIndexPath = requestID.split("/").slice(-1)[0]
@@ -877,7 +919,7 @@ export class PersonalWorkspaceProviderService
const handle: HandleRef<WorkspaceRequest> = computed(() => {
if (
!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")
!isValidWorkspaceHandle(workspaceHandleRef, this.providerID, "personal")
) {
return {
type: "invalid" as const,
@@ -924,19 +966,21 @@ export class PersonalWorkspaceProviderService
this.issuedHandles.push(writableHandle)
}
return Promise.resolve(E.right({ get: () => handle }))
return Promise.resolve(E.right({ get: lazy(() => handle) }))
}
public getRESTCollectionChildrenView(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<E.Either<never, Handle<RESTCollectionChildrenView>>> {
const collectionHandleRef = collectionHandle.get()
return Promise.resolve(
E.right({
get: () =>
computed(() => {
if (
!isValidCollectionHandle(
collectionHandle,
collectionHandleRef,
this.providerID,
"personal"
)
@@ -947,14 +991,14 @@ export class PersonalWorkspaceProviderService
}
}
const collectionID = collectionHandle.value.data.collectionID
const collectionID = collectionHandleRef.value.data.collectionID
return markRaw({
type: "ok" as const,
data: {
providerID: this.providerID,
workspaceID: collectionHandle.value.data.workspaceID,
collectionID: collectionHandle.value.data.collectionID,
workspaceID: collectionHandleRef.value.data.workspaceID,
collectionID: collectionHandleRef.value.data.collectionID,
loading: ref(false),
@@ -1012,15 +1056,17 @@ export class PersonalWorkspaceProviderService
}
public getRESTRootCollectionView(
workspaceHandle: HandleRef<Workspace>
workspaceHandle: Handle<Workspace>
): Promise<E.Either<never, Handle<RootRESTCollectionView>>> {
const workspaceHandleRef = workspaceHandle.get()
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidWorkspaceHandle(
workspaceHandle,
workspaceHandleRef,
this.providerID,
"personal"
)
@@ -1035,7 +1081,7 @@ export class PersonalWorkspaceProviderService
type: "ok" as const,
data: {
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
workspaceID: workspaceHandleRef.value.data.workspaceID,
loading: ref(false),
@@ -1055,21 +1101,24 @@ export class PersonalWorkspaceProviderService
}),
},
})
}),
})
),
})
)
}
public getRESTCollectionLevelAuthHeadersView(
collectionHandle: HandleRef<WorkspaceCollection>
collectionHandle: Handle<WorkspaceCollection>
): Promise<E.Either<never, Handle<RESTCollectionLevelAuthHeadersView>>> {
const collectionHandleRef = collectionHandle.get()
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidCollectionHandle(
collectionHandle,
collectionHandleRef,
this.providerID,
"personal"
)
@@ -1080,7 +1129,7 @@ export class PersonalWorkspaceProviderService
}
}
const { collectionID } = collectionHandle.value.data
const { collectionID } = collectionHandleRef.value.data
let auth: HoppInheritedProperty["auth"] = {
parentID: collectionID ?? "",
@@ -1167,13 +1216,14 @@ export class PersonalWorkspaceProviderService
}
return { type: "ok", data: { auth, headers } }
}),
})
),
})
)
}
public getRESTSearchResultsView(
workspaceHandle: HandleRef<Workspace>,
workspaceHandle: Handle<Workspace>,
searchQuery: Ref<string>
): Promise<E.Either<never, Handle<RESTSearchResultsView>>> {
const results = ref<HoppCollection[]>([])
@@ -1262,13 +1312,15 @@ export class PersonalWorkspaceProviderService
scopeHandle.stop()
}
const workspaceHandleRef = workspaceHandle.get()
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidWorkspaceHandle(
workspaceHandle,
workspaceHandleRef,
this.providerID,
"personal"
)
@@ -1283,7 +1335,7 @@ export class PersonalWorkspaceProviderService
type: "ok" as const,
data: {
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
workspaceID: workspaceHandleRef.value.data.workspaceID,
loading: ref(false),
@@ -1291,21 +1343,24 @@ export class PersonalWorkspaceProviderService
onSessionEnd,
},
})
}),
})
),
})
)
}
public getRESTCollectionJSONView(
workspaceHandle: HandleRef<Workspace>
workspaceHandle: Handle<Workspace>
): Promise<E.Either<never, Handle<RESTCollectionJSONView>>> {
const workspaceHandleRef = workspaceHandle.get()
return Promise.resolve(
E.right({
get: () =>
get: lazy(() =>
computed(() => {
if (
!isValidWorkspaceHandle(
workspaceHandle,
workspaceHandleRef,
this.providerID,
"personal"
)
@@ -1320,7 +1375,7 @@ export class PersonalWorkspaceProviderService
type: "ok" as const,
data: {
providerID: this.providerID,
workspaceID: workspaceHandle.value.data.workspaceID,
workspaceID: workspaceHandleRef.value.data.workspaceID,
content: JSON.stringify(
this.restCollectionState.value.state,
null,
@@ -1328,7 +1383,8 @@ export class PersonalWorkspaceProviderService
),
},
})
}),
})
),
})
)
}
@@ -1345,7 +1401,7 @@ export class PersonalWorkspaceProviderService
public getPersonalWorkspaceHandle(): Handle<Workspace> {
return {
get: () =>
get: lazy(() =>
shallowRef({
type: "ok" as const,
data: {
@@ -1354,7 +1410,8 @@ export class PersonalWorkspaceProviderService
name: "Personal Workspace",
},
}),
})
),
}
}
}

View File

@@ -3,8 +3,6 @@ import { isEqual } from "lodash-es"
import { computed } from "vue"
import { getDefaultRESTRequest } from "~/helpers/rest/default"
import { HoppRESTDocument, HoppRESTSaveContext } from "~/helpers/rest/document"
import { HandleRef } from "../new-workspace/handle"
import { WorkspaceRequest } from "../new-workspace/workspace"
import { TabService } from "./tab"
export class RESTTabService extends TabService<HoppRESTDocument> {
@@ -61,28 +59,29 @@ export class RESTTabService extends TabService<HoppRESTDocument> {
ctx?.originLocation === "workspace-user-collection" &&
tab.document.saveContext?.originLocation === "workspace-user-collection"
) {
const requestHandle = tab.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandle = tab.document.saveContext.requestHandle
if (!ctx.requestHandle || !requestHandle) {
return null
}
const tabRequestHandleRef = requestHandle.get()
const requestHandleRef = ctx.requestHandle.get()
if (
ctx.requestHandle.value.type === "invalid" ||
requestHandle.type === "invalid"
requestHandleRef.value.type === "invalid" ||
tabRequestHandleRef.value.type === "invalid"
) {
return null
}
if (
ctx.requestHandle.value.data.providerID ===
requestHandle.data.providerID &&
ctx.requestHandle.value.data.workspaceID ===
requestHandle.data.workspaceID &&
ctx.requestHandle.value.data.requestID ===
requestHandle.data.requestID
requestHandleRef.value.data.providerID ===
tabRequestHandleRef.value.data.providerID &&
requestHandleRef.value.data.workspaceID ===
tabRequestHandleRef.value.data.workspaceID &&
requestHandleRef.value.data.requestID ===
tabRequestHandleRef.value.data.requestID
) {
return this.getTabRef(tab.id)
}
@@ -104,11 +103,9 @@ export class RESTTabService extends TabService<HoppRESTDocument> {
if (
tab.document.saveContext?.originLocation === "workspace-user-collection"
) {
const requestHandle = tab.document.saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandle = tab.document.saveContext.requestHandle
if (requestHandle?.type === "invalid") {
if (requestHandle?.get().value.type === "invalid") {
count++
}
}

View File

@@ -19,7 +19,7 @@ import {
} from "."
import { NewWorkspaceService } from "../new-workspace"
import { Handle, HandleRef } from "../new-workspace/handle"
import { Handle } from "../new-workspace/handle"
import { WorkspaceRequest } from "../new-workspace/workspace"
export abstract class TabService<Doc>
@@ -121,11 +121,7 @@ export abstract class TabService<Doc>
continue
}
const workspaceHandle = workspaceHandleResult.right.get()
if (workspaceHandle.value.type === "invalid") {
continue
}
const workspaceHandle = workspaceHandleResult.right
const requestHandleResult =
await this.workspaceService.getRequestHandle(
@@ -249,15 +245,15 @@ export abstract class TabService<Doc>
}
// TODO: Investigate why requestHandle is available unwrapped here
const requestHandle = saveContext.requestHandle as
| HandleRef<WorkspaceRequest>["value"]
| undefined
const requestHandle = saveContext.requestHandle
if (!requestHandle) {
return tabDoc
}
if (requestHandle.type === "invalid") {
const requestHandleRef = requestHandle.get()
if (requestHandleRef.value.type === "invalid") {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { requestHandle, ...rest } = saveContext
@@ -268,7 +264,7 @@ export abstract class TabService<Doc>
}
}
const { providerID, workspaceID, requestID } = requestHandle.data
const { providerID, workspaceID, requestID } = requestHandleRef.value.data
// Return the document without the handle
return {