refactor: remove redundancy from provider API method signatures
This commit is contained in:
@@ -1452,18 +1452,10 @@ const exportCollection = async (collectionIndexPath: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const collection = navigateToFolderWithIndexPath(
|
const result = await workspaceService.exportRESTCollection(collectionHandle)
|
||||||
restCollectionState.value,
|
|
||||||
collectionIndexPath.split("/").map((id) => parseInt(id))
|
|
||||||
) as HoppCollection
|
|
||||||
|
|
||||||
const result = await workspaceService.exportRESTCollection(
|
|
||||||
collectionHandle,
|
|
||||||
collection
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
// INVALID_COLLECTION_HANDLE
|
// INVALID_COLLECTION_HANDLE | COLLECTION_NOT_FOUND
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1912,7 +1904,6 @@ const updateRequestOrder = async (
|
|||||||
|
|
||||||
const result = await workspaceService.reorderRESTRequest(
|
const result = await workspaceService.reorderRESTRequest(
|
||||||
requestHandle,
|
requestHandle,
|
||||||
destinationCollectionIndex,
|
|
||||||
destinationRequestIndex
|
destinationRequestIndex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -467,8 +467,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async exportRESTCollection(
|
public async exportRESTCollection(
|
||||||
collectionHandle: Handle<WorkspaceCollection>,
|
collectionHandle: Handle<WorkspaceCollection>
|
||||||
collection: HoppCollection
|
|
||||||
): Promise<
|
): Promise<
|
||||||
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
E.Either<WorkspaceError<"INVALID_HANDLE" | "INVALID_PROVIDER">, void>
|
||||||
> {
|
> {
|
||||||
@@ -486,10 +485,7 @@ export class NewWorkspaceService extends Service {
|
|||||||
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
return E.left({ type: "SERVICE_ERROR", error: "INVALID_PROVIDER" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await provider.exportRESTCollection(
|
const result = await provider.exportRESTCollection(collectionHandle)
|
||||||
collectionHandle,
|
|
||||||
collection
|
|
||||||
)
|
|
||||||
|
|
||||||
if (E.isLeft(result)) {
|
if (E.isLeft(result)) {
|
||||||
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
return E.left({ type: "PROVIDER_ERROR", error: result.left })
|
||||||
@@ -564,7 +560,6 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
public async reorderRESTRequest(
|
public async reorderRESTRequest(
|
||||||
requestHandle: Handle<WorkspaceRequest>,
|
requestHandle: Handle<WorkspaceRequest>,
|
||||||
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>
|
||||||
@@ -585,7 +580,6 @@ export class NewWorkspaceService extends Service {
|
|||||||
|
|
||||||
const result = await provider.reorderRESTRequest(
|
const result = await provider.reorderRESTRequest(
|
||||||
requestHandle,
|
requestHandle,
|
||||||
destinationCollectionID,
|
|
||||||
destinationRequestID
|
destinationRequestID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ export interface WorkspaceProvider {
|
|||||||
workspaceHandle: Handle<Workspace>
|
workspaceHandle: Handle<Workspace>
|
||||||
): Promise<E.Either<unknown, void>>
|
): Promise<E.Either<unknown, void>>
|
||||||
exportRESTCollection(
|
exportRESTCollection(
|
||||||
collectionHandle: Handle<WorkspaceCollection>,
|
collectionHandle: Handle<WorkspaceCollection>
|
||||||
collection: HoppCollection
|
|
||||||
): Promise<E.Either<unknown, void>>
|
): Promise<E.Either<unknown, void>>
|
||||||
|
|
||||||
reorderRESTCollection(
|
reorderRESTCollection(
|
||||||
@@ -100,7 +99,6 @@ export interface WorkspaceProvider {
|
|||||||
): Promise<E.Either<unknown, void>>
|
): Promise<E.Either<unknown, void>>
|
||||||
reorderRESTRequest(
|
reorderRESTRequest(
|
||||||
requestHandle: Handle<WorkspaceRequest>,
|
requestHandle: Handle<WorkspaceRequest>,
|
||||||
destinationCollectionID: string,
|
|
||||||
destinationRequestID: string | null
|
destinationRequestID: string | null
|
||||||
): Promise<E.Either<unknown, void>>
|
): Promise<E.Either<unknown, void>>
|
||||||
moveRESTRequest(
|
moveRESTRequest(
|
||||||
|
|||||||
@@ -225,13 +225,11 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
const destinationCollectionID = "1"
|
|
||||||
const destinationRequestID = "1/1"
|
const destinationRequestID = "1/1"
|
||||||
|
|
||||||
const moveRequestResult =
|
const moveRequestResult =
|
||||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||||
requestHandle,
|
requestHandle,
|
||||||
destinationCollectionID,
|
|
||||||
destinationRequestID
|
destinationRequestID
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -262,7 +260,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
// Request (req-0/0/0/7) dragged from `0/0/0/7` to `0/0/0/2`
|
// Request (req-0/0/0/7) dragged from `0/0/0/7` to `0/0/0/2`
|
||||||
const draggedRequestID = "0/0/0/7"
|
const draggedRequestID = "0/0/0/7"
|
||||||
const destinationCollectionID = "0/0/0"
|
|
||||||
const destinationRequestID = "0/0/0/2"
|
const destinationRequestID = "0/0/0/2"
|
||||||
|
|
||||||
const draggedRequestHandle =
|
const draggedRequestHandle =
|
||||||
@@ -277,7 +275,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||||
draggedRequestHandle.right,
|
draggedRequestHandle.right,
|
||||||
destinationCollectionID,
|
|
||||||
destinationRequestID
|
destinationRequestID
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -328,7 +325,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
// Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/0`
|
// Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/0`
|
||||||
const draggedRequestID = "0/0/0/5"
|
const draggedRequestID = "0/0/0/5"
|
||||||
const destinationCollectionID = "0/0/0"
|
|
||||||
const destinationRequestID = "0/0/0/0"
|
const destinationRequestID = "0/0/0/0"
|
||||||
|
|
||||||
const draggedRequestHandle =
|
const draggedRequestHandle =
|
||||||
@@ -343,7 +340,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||||
draggedRequestHandle.right,
|
draggedRequestHandle.right,
|
||||||
destinationCollectionID,
|
|
||||||
destinationRequestID
|
destinationRequestID
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -411,7 +407,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
// Request (req-0/0/0/3) dragged from `0/0/0/3` to `0/0/0/8`
|
// Request (req-0/0/0/3) dragged from `0/0/0/3` to `0/0/0/8`
|
||||||
const draggedRequestID = "0/0/0/3"
|
const draggedRequestID = "0/0/0/3"
|
||||||
const destinationCollectionID = "0/0/0"
|
|
||||||
const destinationRequestID = "0/0/0/8"
|
const destinationRequestID = "0/0/0/8"
|
||||||
|
|
||||||
const draggedRequestHandle =
|
const draggedRequestHandle =
|
||||||
@@ -426,7 +422,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||||
draggedRequestHandle.right,
|
draggedRequestHandle.right,
|
||||||
destinationCollectionID,
|
|
||||||
destinationRequestID
|
destinationRequestID
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -478,7 +473,7 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
// Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/9`
|
// Request (req-0/0/0/5) dragged from `0/0/0/5` to `0/0/0/9`
|
||||||
const draggedRequestID = "0/0/0/5"
|
const draggedRequestID = "0/0/0/5"
|
||||||
const destinationCollectionID = "0/0/0"
|
|
||||||
// Indicates move to the last position `0/0/0/9`
|
// Indicates move to the last position `0/0/0/9`
|
||||||
const destinationRequestID = null
|
const destinationRequestID = null
|
||||||
|
|
||||||
@@ -494,7 +489,6 @@ describe("PersonalWorkspaceProviderService", () => {
|
|||||||
|
|
||||||
await personalWorkspaceProviderService.reorderRESTRequest(
|
await personalWorkspaceProviderService.reorderRESTRequest(
|
||||||
draggedRequestHandle.right,
|
draggedRequestHandle.right,
|
||||||
destinationCollectionID,
|
|
||||||
destinationRequestID
|
destinationRequestID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -738,8 +738,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public exportRESTCollection(
|
public exportRESTCollection(
|
||||||
collectionHandle: Handle<WorkspaceCollection>,
|
collectionHandle: Handle<WorkspaceCollection>
|
||||||
collection: HoppCollection
|
|
||||||
): Promise<E.Either<unknown, void>> {
|
): Promise<E.Either<unknown, void>> {
|
||||||
const collectionHandleRef = collectionHandle.get()
|
const collectionHandleRef = collectionHandle.get()
|
||||||
|
|
||||||
@@ -749,6 +748,17 @@ export class PersonalWorkspaceProviderService
|
|||||||
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const collection = navigateToFolderWithIndexPath(
|
||||||
|
this.restCollectionState.value.state,
|
||||||
|
collectionHandleRef.value.data.collectionID
|
||||||
|
.split("/")
|
||||||
|
.map((id) => parseInt(id))
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!collection) {
|
||||||
|
return Promise.resolve(E.left("COLLECTION_NOT_FOUND" as const))
|
||||||
|
}
|
||||||
|
|
||||||
initializeDownloadFile(JSON.stringify(collection, null, 2), collection.name)
|
initializeDownloadFile(JSON.stringify(collection, null, 2), collection.name)
|
||||||
|
|
||||||
return Promise.resolve(E.right(undefined))
|
return Promise.resolve(E.right(undefined))
|
||||||
@@ -1098,7 +1108,6 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
public reorderRESTRequest(
|
public reorderRESTRequest(
|
||||||
requestHandle: Handle<WorkspaceRequest>,
|
requestHandle: Handle<WorkspaceRequest>,
|
||||||
destinationCollectionID: string,
|
|
||||||
destinationRequestID: string | null
|
destinationRequestID: string | null
|
||||||
): Promise<E.Either<unknown, void>> {
|
): Promise<E.Either<unknown, void>> {
|
||||||
const requestHandleRef = requestHandle.get()
|
const requestHandleRef = requestHandle.get()
|
||||||
@@ -1131,7 +1140,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
|
|
||||||
const resolvedDestinationRequestID =
|
const resolvedDestinationRequestID =
|
||||||
destinationRequestIndexPos > draggedRequestIndexPos
|
destinationRequestIndexPos > draggedRequestIndexPos
|
||||||
? `${destinationCollectionID}/${resolvedDestinationRequestIDPostfix}`
|
? `${collectionID}/${resolvedDestinationRequestIDPostfix}`
|
||||||
: destinationRequestID
|
: destinationRequestID
|
||||||
|
|
||||||
const resolvedDestinationRequestIndexPos =
|
const resolvedDestinationRequestIndexPos =
|
||||||
@@ -1175,7 +1184,7 @@ export class PersonalWorkspaceProviderService
|
|||||||
updateRESTRequestOrder(
|
updateRESTRequestOrder(
|
||||||
this.pathToLastIndex(draggedRequestID),
|
this.pathToLastIndex(draggedRequestID),
|
||||||
destinationRequestID ? destinationRequestIndexPos : null,
|
destinationRequestID ? destinationRequestIndexPos : null,
|
||||||
destinationCollectionID
|
collectionID
|
||||||
)
|
)
|
||||||
|
|
||||||
affectedRequestHandleUpdateInfo.forEach(
|
affectedRequestHandleUpdateInfo.forEach(
|
||||||
|
|||||||
Reference in New Issue
Block a user