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 newWorkspaceService = useService(NewWorkspaceService)
const activeWorkspaceName = computed(() => { const activeWorkspaceName = computed(() => {
if (newWorkspaceService.activeWorkspaceHandle.value?.value.type === "ok") { const activeWorkspaceHandleRef = newWorkspaceService.activeWorkspaceHandle.value?.get()
return newWorkspaceService.activeWorkspaceHandle.value?.value.data.name
if (activeWorkspaceHandleRef?.value.type === "ok") {
return activeWorkspaceHandleRef.value.data.name
} }
return t("workspace.no_workspace") return t("workspace.no_workspace")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,8 +5,6 @@ import {
} from "@hoppscotch/data" } from "@hoppscotch/data"
import { getService } from "~/modules/dioc" 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 { RESTTabService } from "~/services/tab/rest"
import { getAffectedIndexes } from "./affectedIndex" import { getAffectedIndexes } from "./affectedIndex"
@@ -55,15 +53,13 @@ export function resolveSaveContextOnRequestReorder(payload: {
return false return false
} }
const requestHandle = tab.document.saveContext.requestHandle as const requestHandleRef = tab.document.saveContext.requestHandle?.get()
| HandleRef<WorkspaceRequest>["value"]
| undefined
if (!requestHandle || requestHandle.type === "invalid") { if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return false return false
} }
const { requestID } = requestHandle.data const { requestID } = requestHandleRef.value.data
const collectionID = requestID.split("/").slice(0, -1).join("/") const collectionID = requestID.split("/").slice(0, -1).join("/")
const requestIndex = parseInt(requestID.split("/").slice(-1)[0]) const requestIndex = parseInt(requestID.split("/").slice(-1)[0])
@@ -85,15 +81,13 @@ export function resolveSaveContextOnRequestReorder(payload: {
return return
} }
const requestHandle = tab.value.document.saveContext.requestHandle as const requestHandleRef = tab.value.document.saveContext.requestHandle?.get()
| HandleRef<WorkspaceRequest>["value"]
| undefined
if (!requestHandle || requestHandle.type === "invalid") { if (!requestHandleRef || requestHandleRef.value.type === "invalid") {
return return
} }
const { requestID } = requestHandle.data const { requestID } = requestHandleRef.value.data
const requestIDArr = requestID.split("/") const requestIDArr = requestID.split("/")
const requestIndex = affectedIndices.get( const requestIndex = affectedIndices.get(
@@ -102,8 +96,10 @@ export function resolveSaveContextOnRequestReorder(payload: {
requestIDArr[requestIDArr.length - 1] = requestIndex.toString() requestIDArr[requestIDArr.length - 1] = requestIndex.toString()
requestHandle.data.requestID = requestIDArr.join("/") requestHandleRef.value.data.requestID = requestIDArr.join("/")
requestHandle.data.collectionID = requestIDArr.slice(0, -1).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 { HoppTestResult } from "../types/HoppTestResult"
import { RESTOptionTabs } from "~/components/http/RequestOptions.vue" import { RESTOptionTabs } from "~/components/http/RequestOptions.vue"
import { HoppInheritedProperty } from "../types/HoppInheritedProperties" 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" import { WorkspaceRequest } from "~/services/new-workspace/workspace"
export type HoppRESTSaveContext = export type HoppRESTSaveContext =
@@ -31,7 +31,7 @@ export type HoppRESTSaveContext =
/** /**
* Handle to the request open in the tab * 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, shallowRef,
watch, watch,
} from "vue" } from "vue"
import { Handle, HandleRef } from "./handle" import { Handle } from "./handle"
import { WorkspaceProvider } from "./provider" import { WorkspaceProvider } from "./provider"
import { import {
RESTCollectionChildrenView, RESTCollectionChildrenView,
@@ -32,16 +32,18 @@ export class NewWorkspaceService extends Service {
new Map<string, WorkspaceProvider>() new Map<string, WorkspaceProvider>()
) )
public activeWorkspaceHandle: Ref<HandleRef<Workspace> | undefined> = public activeWorkspaceHandle: Ref<Handle<Workspace> | undefined> =
shallowRef() shallowRef()
public activeWorkspaceDecor = computed(() => { public activeWorkspaceDecor = computed(() => {
if (this.activeWorkspaceHandle.value?.value.type !== "ok") { const activeWorkspaceHandleRef = this.activeWorkspaceHandle.value?.get()
if (activeWorkspaceHandleRef?.value.type !== "ok") {
return undefined return undefined
} }
return this.registeredProviders.get( return this.registeredProviders.get(
this.activeWorkspaceHandle.value.value.data.providerID activeWorkspaceHandleRef.value.data.providerID
)!.workspaceDecor )!.workspaceDecor
}) })
@@ -73,14 +75,16 @@ export class NewWorkspaceService extends Service {
return this.activeWorkspaceHandle.value return this.activeWorkspaceHandle.value
? [ ? [
this.activeWorkspaceHandle.value, this.activeWorkspaceHandle.value,
this.activeWorkspaceHandle.value.value, this.activeWorkspaceHandle.value?.get(),
] ]
: [this.activeWorkspaceHandle.value] : [this.activeWorkspaceHandle.value]
}, },
() => { () => {
if (!this.activeWorkspaceHandle.value) return 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 this.activeWorkspaceHandle.value = undefined
} }
}, },
@@ -110,7 +114,7 @@ export class NewWorkspaceService extends Service {
} }
public async getCollectionHandle( public async getCollectionHandle(
workspaceHandle: HandleRef<Workspace>, workspaceHandle: Handle<Workspace>,
collectionID: string collectionID: string
): Promise< ): Promise<
E.Either< E.Either<
@@ -118,12 +122,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -143,7 +149,7 @@ export class NewWorkspaceService extends Service {
} }
public async getRequestHandle( public async getRequestHandle(
workspaceHandle: HandleRef<Workspace>, workspaceHandle: Handle<Workspace>,
requestID: string requestID: string
): Promise< ): Promise<
E.Either< E.Either<
@@ -151,12 +157,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceRequest> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -173,7 +181,7 @@ export class NewWorkspaceService extends Service {
} }
public async createRESTRootCollection( public async createRESTRootCollection(
workspaceHandle: HandleRef<Workspace>, workspaceHandle: Handle<Workspace>,
newCollection: Partial<Exclude<HoppCollection, "id">> & { name: string } newCollection: Partial<Exclude<HoppCollection, "id">> & { name: string }
): Promise< ): Promise<
E.Either< E.Either<
@@ -181,12 +189,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -206,7 +216,7 @@ export class NewWorkspaceService extends Service {
} }
public async createRESTChildCollection( public async createRESTChildCollection(
parentCollectionHandle: HandleRef<WorkspaceCollection>, parentCollectionHandle: Handle<WorkspaceCollection>,
newChildCollection: Partial<HoppCollection> & { name: string } newChildCollection: Partial<HoppCollection> & { name: string }
): Promise< ): Promise<
E.Either< E.Either<
@@ -214,12 +224,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
parentCollectionHandle.value.data.providerID parentCollectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -239,17 +251,19 @@ export class NewWorkspaceService extends Service {
} }
public async updateRESTCollection( public async updateRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>, collectionHandle: Handle<WorkspaceCollection>,
updatedCollection: Partial<HoppCollection> updatedCollection: Partial<HoppCollection>
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -269,16 +283,18 @@ export class NewWorkspaceService extends Service {
} }
public async removeRESTCollection( public async removeRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection> collectionHandle: Handle<WorkspaceCollection>
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -295,7 +311,7 @@ export class NewWorkspaceService extends Service {
} }
public async createRESTRequest( public async createRESTRequest(
parentCollectionHandle: HandleRef<WorkspaceCollection>, parentCollectionHandle: Handle<WorkspaceCollection>,
newRequest: HoppRESTRequest newRequest: HoppRESTRequest
): Promise< ): Promise<
E.Either< E.Either<
@@ -303,12 +319,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceRequest> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
parentCollectionHandle.value.data.providerID parentCollectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -328,16 +346,18 @@ export class NewWorkspaceService extends Service {
} }
public async removeRESTRequest( public async removeRESTRequest(
requestHandle: HandleRef<WorkspaceRequest> requestHandle: Handle<WorkspaceRequest>
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
requestHandle.value.data.providerID requestHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -354,17 +374,19 @@ export class NewWorkspaceService extends Service {
} }
public async updateRESTRequest( public async updateRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>, requestHandle: Handle<WorkspaceRequest>,
updatedRequest: Partial<HoppRESTRequest> updatedRequest: Partial<HoppRESTRequest>
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
requestHandle.value.data.providerID requestHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -384,7 +406,7 @@ export class NewWorkspaceService extends Service {
} }
public async importRESTCollections( public async importRESTCollections(
workspaceHandle: HandleRef<Workspace>, workspaceHandle: Handle<Workspace>,
collections: HoppCollection[] collections: HoppCollection[]
): Promise< ): Promise<
E.Either< E.Either<
@@ -392,12 +414,14 @@ export class NewWorkspaceService extends Service {
Handle<WorkspaceCollection> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -417,17 +441,19 @@ export class NewWorkspaceService extends Service {
} }
public async exportRESTCollections( public async exportRESTCollections(
workspaceHandle: HandleRef<Workspace>, workspaceHandle: Handle<Workspace>,
collections: HoppCollection[] collections: HoppCollection[]
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -447,17 +473,19 @@ export class NewWorkspaceService extends Service {
} }
public async exportRESTCollection( public async exportRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>, collectionHandle: Handle<WorkspaceCollection>,
collection: HoppCollection collection: HoppCollection
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -477,17 +505,19 @@ export class NewWorkspaceService extends Service {
} }
public async reorderRESTCollection( public async reorderRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>, collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null destinationCollectionID: string | null
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -507,17 +537,19 @@ export class NewWorkspaceService extends Service {
} }
public async moveRESTCollection( public async moveRESTCollection(
collectionHandle: HandleRef<WorkspaceCollection>, collectionHandle: Handle<WorkspaceCollection>,
destinationCollectionID: string | null destinationCollectionID: string | null
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -537,18 +569,20 @@ export class NewWorkspaceService extends Service {
} }
public async reorderRESTRequest( public async reorderRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>, requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string, destinationCollectionID: string,
destinationRequestID: string | null destinationRequestID: string | null
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
requestHandle.value.data.providerID requestHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -569,17 +603,19 @@ export class NewWorkspaceService extends Service {
} }
public async moveRESTRequest( public async moveRESTRequest(
requestHandle: HandleRef<WorkspaceRequest>, requestHandle: Handle<WorkspaceRequest>,
destinationCollectionID: string destinationCollectionID: string
): Promise< ): Promise<
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
requestHandle.value.data.providerID requestHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -599,19 +635,21 @@ export class NewWorkspaceService extends Service {
} }
public async getRESTCollectionChildrenView( public async getRESTCollectionChildrenView(
collectionHandle: HandleRef<WorkspaceCollection> collectionHandle: Handle<WorkspaceCollection>
): Promise< ): Promise<
E.Either< E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RESTCollectionChildrenView> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -629,19 +667,21 @@ export class NewWorkspaceService extends Service {
} }
public async getRESTRootCollectionView( public async getRESTRootCollectionView(
workspaceHandle: HandleRef<Workspace> workspaceHandle: Handle<Workspace>
): Promise< ): Promise<
E.Either< E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RootRESTCollectionView> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -658,19 +698,21 @@ export class NewWorkspaceService extends Service {
} }
public async getRESTCollectionLevelAuthHeadersView( public async getRESTCollectionLevelAuthHeadersView(
collectionHandle: HandleRef<WorkspaceCollection> collectionHandle: Handle<WorkspaceCollection>
): Promise< ): Promise<
E.Either< E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RESTCollectionLevelAuthHeadersView> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
collectionHandle.value.data.providerID collectionHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -688,7 +730,7 @@ export class NewWorkspaceService extends Service {
} }
public async getRESTSearchResultsView( public async getRESTSearchResultsView(
workspaceHandle: HandleRef<Workspace>, workspaceHandle: Handle<Workspace>,
searchQuery: Ref<string> searchQuery: Ref<string>
): Promise< ): Promise<
E.Either< E.Either<
@@ -696,12 +738,14 @@ export class NewWorkspaceService extends Service {
Handle<RESTSearchResultsView> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {
@@ -721,19 +765,21 @@ export class NewWorkspaceService extends Service {
} }
public async getRESTCollectionJSONView( public async getRESTCollectionJSONView(
workspaceHandle: HandleRef<Workspace> workspaceHandle: Handle<Workspace>
): Promise< ): Promise<
E.Either< E.Either<
WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">,
Handle<RESTCollectionJSONView> 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" }) return E.left({ type: "SERVICE_ERROR", error: "INVALID_HANDLE" })
} }
const provider = this.registeredProviders.get( const provider = this.registeredProviders.get(
workspaceHandle.value.data.providerID workspaceHandleRef.value.data.providerID
) )
if (!provider) { if (!provider) {

View File

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

View File

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

View File

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

View File

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