|
@@ -42,7 +42,11 @@ import {
|
|
|
} from "~/newstore/collections"
|
|
|
import { platform } from "~/platform"
|
|
|
|
|
|
-import { HandleRef, WritableHandleRef } from "~/services/new-workspace/handle"
|
|
|
+import {
|
|
|
+ Handle,
|
|
|
+ HandleRef,
|
|
|
+ WritableHandleRef,
|
|
|
+} from "~/services/new-workspace/handle"
|
|
|
import { WorkspaceProvider } from "~/services/new-workspace/provider"
|
|
|
import {
|
|
|
RESTCollectionChildrenView,
|
|
@@ -59,7 +63,6 @@ import {
|
|
|
WorkspaceRequest,
|
|
|
} from "~/services/new-workspace/workspace"
|
|
|
|
|
|
-import { getAffectedIndexes } from "~/helpers/collection/affectedIndex"
|
|
|
import {
|
|
|
getFoldersByPath,
|
|
|
resolveSaveContextOnCollectionReorder,
|
|
@@ -127,7 +130,7 @@ export class PersonalWorkspaceProviderService
|
|
|
public createRESTRootCollection(
|
|
|
workspaceHandle: HandleRef<Workspace>,
|
|
|
newCollection: Partial<Exclude<HoppCollection, "id">> & { name: string }
|
|
|
- ): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
|
|
|
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
|
|
|
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
|
|
}
|
|
@@ -156,39 +159,40 @@ export class PersonalWorkspaceProviderService
|
|
|
})
|
|
|
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidWorkspaceHandle(
|
|
|
- workspaceHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "WORKSPACE_INVALIDATED" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidWorkspaceHandle(
|
|
|
+ workspaceHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "WORKSPACE_INVALIDATED" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return {
|
|
|
- type: "ok",
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
- collectionID: newCollectionID,
|
|
|
- name: newCollectionName,
|
|
|
- },
|
|
|
- }
|
|
|
- })
|
|
|
- )
|
|
|
+ return {
|
|
|
+ type: "ok",
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
+ collectionID: newCollectionID,
|
|
|
+ name: newCollectionName,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public createRESTChildCollection(
|
|
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
|
|
newChildCollection: Partial<HoppCollection> & { name: string }
|
|
|
- ): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
|
|
|
if (
|
|
|
!isValidCollectionHandle(
|
|
|
parentCollectionHandle,
|
|
@@ -213,32 +217,33 @@ export class PersonalWorkspaceProviderService
|
|
|
})
|
|
|
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidCollectionHandle(
|
|
|
- parentCollectionHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "COLLECTION_INVALIDATED" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidCollectionHandle(
|
|
|
+ parentCollectionHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "COLLECTION_INVALIDATED" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return {
|
|
|
- type: "ok",
|
|
|
- data: {
|
|
|
- providerID,
|
|
|
- workspaceID,
|
|
|
- collectionID,
|
|
|
- name: newCollectionName,
|
|
|
- },
|
|
|
- }
|
|
|
- })
|
|
|
- )
|
|
|
+ return {
|
|
|
+ type: "ok",
|
|
|
+ data: {
|
|
|
+ providerID,
|
|
|
+ workspaceID,
|
|
|
+ collectionID,
|
|
|
+ name: newCollectionName,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
@@ -352,7 +357,7 @@ export class PersonalWorkspaceProviderService
|
|
|
public createRESTRequest(
|
|
|
parentCollectionHandle: HandleRef<WorkspaceCollection>,
|
|
|
newRequest: HoppRESTRequest
|
|
|
- ): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<WorkspaceRequest>>> {
|
|
|
if (
|
|
|
!isValidCollectionHandle(
|
|
|
parentCollectionHandle,
|
|
@@ -441,7 +446,7 @@ export class PersonalWorkspaceProviderService
|
|
|
this.issuedHandles.push(writableHandle)
|
|
|
}
|
|
|
|
|
|
- return Promise.resolve(E.right(handle))
|
|
|
+ return Promise.resolve(E.right({ get: () => handle }))
|
|
|
}
|
|
|
|
|
|
public removeRESTRequest(
|
|
@@ -529,7 +534,7 @@ export class PersonalWorkspaceProviderService
|
|
|
public importRESTCollections(
|
|
|
workspaceHandle: HandleRef<Workspace>,
|
|
|
collections: HoppCollection[]
|
|
|
- ): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
|
|
|
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
|
|
|
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
|
|
}
|
|
@@ -541,32 +546,33 @@ export class PersonalWorkspaceProviderService
|
|
|
this.restCollectionState.value.state.length.toString()
|
|
|
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidWorkspaceHandle(
|
|
|
- workspaceHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "WORKSPACE_INVALIDATED" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidWorkspaceHandle(
|
|
|
+ workspaceHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "WORKSPACE_INVALIDATED" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return {
|
|
|
- type: "ok",
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
- collectionID: newCollectionID,
|
|
|
- name: newCollectionName,
|
|
|
- },
|
|
|
- }
|
|
|
- })
|
|
|
- )
|
|
|
+ return {
|
|
|
+ type: "ok",
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
+ collectionID: newCollectionID,
|
|
|
+ name: newCollectionName,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
@@ -769,7 +775,7 @@ export class PersonalWorkspaceProviderService
|
|
|
public getCollectionHandle(
|
|
|
workspaceHandle: HandleRef<Workspace>,
|
|
|
collectionID: string
|
|
|
- ): Promise<E.Either<unknown, HandleRef<WorkspaceCollection>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<WorkspaceCollection>>> {
|
|
|
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
|
|
|
return Promise.resolve(E.left("INVALID_WORKSPACE_HANDLE" as const))
|
|
|
}
|
|
@@ -790,39 +796,40 @@ export class PersonalWorkspaceProviderService
|
|
|
const { providerID, workspaceID } = workspaceHandle.value.data
|
|
|
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidWorkspaceHandle(
|
|
|
- workspaceHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "WORKSPACE_INVALIDATED" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidWorkspaceHandle(
|
|
|
+ workspaceHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "WORKSPACE_INVALIDATED" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return {
|
|
|
- type: "ok",
|
|
|
- data: {
|
|
|
- providerID,
|
|
|
- workspaceID,
|
|
|
- collectionID,
|
|
|
- name: collection.name,
|
|
|
- },
|
|
|
- }
|
|
|
- })
|
|
|
- )
|
|
|
+ return {
|
|
|
+ type: "ok",
|
|
|
+ data: {
|
|
|
+ providerID,
|
|
|
+ workspaceID,
|
|
|
+ collectionID,
|
|
|
+ name: collection.name,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public getRequestHandle(
|
|
|
workspaceHandle: HandleRef<Workspace>,
|
|
|
requestID: string
|
|
|
- ): Promise<E.Either<unknown, HandleRef<WorkspaceRequest>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<WorkspaceRequest>>> {
|
|
|
if (!isValidWorkspaceHandle(workspaceHandle, this.providerID, "personal")) {
|
|
|
return Promise.resolve(E.left("INVALID_COLLECTION_HANDLE" as const))
|
|
|
}
|
|
@@ -917,250 +924,258 @@ export class PersonalWorkspaceProviderService
|
|
|
this.issuedHandles.push(writableHandle)
|
|
|
}
|
|
|
|
|
|
- return Promise.resolve(E.right(handle))
|
|
|
+ return Promise.resolve(E.right({ get: () => handle }))
|
|
|
}
|
|
|
|
|
|
public getRESTCollectionChildrenView(
|
|
|
collectionHandle: HandleRef<WorkspaceCollection>
|
|
|
- ): Promise<E.Either<never, HandleRef<RESTCollectionChildrenView>>> {
|
|
|
+ ): Promise<E.Either<never, Handle<RESTCollectionChildrenView>>> {
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidCollectionHandle(
|
|
|
- collectionHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "INVALID_COLLECTION_HANDLE" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidCollectionHandle(
|
|
|
+ collectionHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "INVALID_COLLECTION_HANDLE" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- const collectionID = collectionHandle.value.data.collectionID
|
|
|
-
|
|
|
- return markRaw({
|
|
|
- type: "ok" as const,
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: collectionHandle.value.data.workspaceID,
|
|
|
- collectionID: collectionHandle.value.data.collectionID,
|
|
|
-
|
|
|
- loading: ref(false),
|
|
|
-
|
|
|
- content: computed(() => {
|
|
|
- const indexPath = collectionID
|
|
|
- .split("/")
|
|
|
- .map((x) => parseInt(x))
|
|
|
-
|
|
|
- const item = navigateToFolderWithIndexPath(
|
|
|
- this.restCollectionState.value.state,
|
|
|
- indexPath
|
|
|
- )
|
|
|
|
|
|
- if (item) {
|
|
|
- const collections = item.folders.map((childColl, id) => {
|
|
|
- return <RESTCollectionViewItem>{
|
|
|
- type: "collection",
|
|
|
- value: {
|
|
|
- collectionID: `${collectionID}/${id}`,
|
|
|
- isLastItem:
|
|
|
- item.folders?.length > 1
|
|
|
- ? id === item.folders.length - 1
|
|
|
- : false,
|
|
|
- name: childColl.name,
|
|
|
- parentCollectionID: collectionID,
|
|
|
- },
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- const requests = item.requests.map((req, id) => {
|
|
|
- // TODO: Replace `parentCollectionID` with `collectionID`
|
|
|
- return <RESTCollectionViewItem>{
|
|
|
- type: "request",
|
|
|
- value: {
|
|
|
- isLastItem:
|
|
|
- item.requests?.length > 1
|
|
|
- ? id === item.requests.length - 1
|
|
|
- : false,
|
|
|
- collectionID,
|
|
|
- requestID: `${collectionID}/${id}`,
|
|
|
- request: req,
|
|
|
- },
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- return [...collections, ...requests]
|
|
|
- }
|
|
|
- return []
|
|
|
- }),
|
|
|
- },
|
|
|
- })
|
|
|
- })
|
|
|
- )
|
|
|
+ const collectionID = collectionHandle.value.data.collectionID
|
|
|
+
|
|
|
+ return markRaw({
|
|
|
+ type: "ok" as const,
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: collectionHandle.value.data.workspaceID,
|
|
|
+ collectionID: collectionHandle.value.data.collectionID,
|
|
|
+
|
|
|
+ loading: ref(false),
|
|
|
+
|
|
|
+ content: computed(() => {
|
|
|
+ const indexPath = collectionID
|
|
|
+ .split("/")
|
|
|
+ .map((x) => parseInt(x))
|
|
|
+
|
|
|
+ const item = navigateToFolderWithIndexPath(
|
|
|
+ this.restCollectionState.value.state,
|
|
|
+ indexPath
|
|
|
+ )
|
|
|
+
|
|
|
+ if (item) {
|
|
|
+ const collections = item.folders.map((childColl, id) => {
|
|
|
+ return <RESTCollectionViewItem>{
|
|
|
+ type: "collection",
|
|
|
+ value: {
|
|
|
+ collectionID: `${collectionID}/${id}`,
|
|
|
+ isLastItem:
|
|
|
+ item.folders?.length > 1
|
|
|
+ ? id === item.folders.length - 1
|
|
|
+ : false,
|
|
|
+ name: childColl.name,
|
|
|
+ parentCollectionID: collectionID,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const requests = item.requests.map((req, id) => {
|
|
|
+ // TODO: Replace `parentCollectionID` with `collectionID`
|
|
|
+ return <RESTCollectionViewItem>{
|
|
|
+ type: "request",
|
|
|
+ value: {
|
|
|
+ isLastItem:
|
|
|
+ item.requests?.length > 1
|
|
|
+ ? id === item.requests.length - 1
|
|
|
+ : false,
|
|
|
+ collectionID,
|
|
|
+ requestID: `${collectionID}/${id}`,
|
|
|
+ request: req,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ return [...collections, ...requests]
|
|
|
+ }
|
|
|
+ return []
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public getRESTRootCollectionView(
|
|
|
workspaceHandle: HandleRef<Workspace>
|
|
|
- ): Promise<E.Either<never, HandleRef<RootRESTCollectionView>>> {
|
|
|
+ ): Promise<E.Either<never, Handle<RootRESTCollectionView>>> {
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidWorkspaceHandle(
|
|
|
- workspaceHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "INVALID_WORKSPACE_HANDLE" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidWorkspaceHandle(
|
|
|
+ workspaceHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "INVALID_WORKSPACE_HANDLE" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return markRaw({
|
|
|
- type: "ok" as const,
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
-
|
|
|
- loading: ref(false),
|
|
|
-
|
|
|
- collections: computed(() => {
|
|
|
- return this.restCollectionState.value.state.map((coll, id) => {
|
|
|
- return {
|
|
|
- collectionID: id.toString(),
|
|
|
- isLastItem:
|
|
|
- id === this.restCollectionState.value.state.length - 1,
|
|
|
- name: coll.name,
|
|
|
- parentCollectionID: null,
|
|
|
- }
|
|
|
- })
|
|
|
- }),
|
|
|
- },
|
|
|
- })
|
|
|
- })
|
|
|
- )
|
|
|
+ return markRaw({
|
|
|
+ type: "ok" as const,
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
+
|
|
|
+ loading: ref(false),
|
|
|
+
|
|
|
+ collections: computed(() => {
|
|
|
+ return this.restCollectionState.value.state.map(
|
|
|
+ (coll, id) => {
|
|
|
+ return {
|
|
|
+ collectionID: id.toString(),
|
|
|
+ isLastItem:
|
|
|
+ id ===
|
|
|
+ this.restCollectionState.value.state.length - 1,
|
|
|
+ name: coll.name,
|
|
|
+ parentCollectionID: null,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public getRESTCollectionLevelAuthHeadersView(
|
|
|
collectionHandle: HandleRef<WorkspaceCollection>
|
|
|
- ): Promise<E.Either<never, HandleRef<RESTCollectionLevelAuthHeadersView>>> {
|
|
|
+ ): Promise<E.Either<never, Handle<RESTCollectionLevelAuthHeadersView>>> {
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidCollectionHandle(
|
|
|
- collectionHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "INVALID_COLLECTION_HANDLE" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidCollectionHandle(
|
|
|
+ collectionHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "INVALID_COLLECTION_HANDLE" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- const { collectionID } = collectionHandle.value.data
|
|
|
+ const { collectionID } = collectionHandle.value.data
|
|
|
|
|
|
- let auth: HoppInheritedProperty["auth"] = {
|
|
|
- parentID: collectionID ?? "",
|
|
|
- parentName: "",
|
|
|
- inheritedAuth: {
|
|
|
- authType: "none",
|
|
|
- authActive: true,
|
|
|
- },
|
|
|
- }
|
|
|
- const headers: HoppInheritedProperty["headers"] = []
|
|
|
-
|
|
|
- if (!collectionID) return { type: "ok", data: { auth, headers } }
|
|
|
+ let auth: HoppInheritedProperty["auth"] = {
|
|
|
+ parentID: collectionID ?? "",
|
|
|
+ parentName: "",
|
|
|
+ inheritedAuth: {
|
|
|
+ authType: "none",
|
|
|
+ authActive: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ const headers: HoppInheritedProperty["headers"] = []
|
|
|
|
|
|
- const path = collectionID.split("/").map((i) => parseInt(i))
|
|
|
+ if (!collectionID) return { type: "ok", data: { auth, headers } }
|
|
|
|
|
|
- // Check if the path is empty or invalid
|
|
|
- if (!path || path.length === 0) {
|
|
|
- console.error("Invalid path:", collectionID)
|
|
|
- return { type: "ok", data: { auth, headers } }
|
|
|
- }
|
|
|
+ const path = collectionID.split("/").map((i) => parseInt(i))
|
|
|
|
|
|
- // Loop through the path and get the last parent folder with authType other than 'inherit'
|
|
|
- for (let i = 0; i < path.length; i++) {
|
|
|
- const parentFolder = navigateToFolderWithIndexPath(
|
|
|
- this.restCollectionState.value.state,
|
|
|
- [...path.slice(0, i + 1)] // Create a copy of the path array
|
|
|
- )
|
|
|
-
|
|
|
- // Check if parentFolder is undefined or null
|
|
|
- if (!parentFolder) {
|
|
|
- console.error("Parent folder not found for path:", path)
|
|
|
+ // Check if the path is empty or invalid
|
|
|
+ if (!path || path.length === 0) {
|
|
|
+ console.error("Invalid path:", collectionID)
|
|
|
return { type: "ok", data: { auth, headers } }
|
|
|
}
|
|
|
|
|
|
- const parentFolderAuth: HoppRESTAuth = parentFolder.auth
|
|
|
- const parentFolderHeaders: HoppRESTHeaders = parentFolder.headers
|
|
|
+ // Loop through the path and get the last parent folder with authType other than 'inherit'
|
|
|
+ for (let i = 0; i < path.length; i++) {
|
|
|
+ const parentFolder = navigateToFolderWithIndexPath(
|
|
|
+ this.restCollectionState.value.state,
|
|
|
+ [...path.slice(0, i + 1)] // Create a copy of the path array
|
|
|
+ )
|
|
|
|
|
|
- // check if the parent folder has authType 'inherit' and if it is the root folder
|
|
|
- if (
|
|
|
- parentFolderAuth?.authType === "inherit" &&
|
|
|
- [...path.slice(0, i + 1)].length === 1
|
|
|
- ) {
|
|
|
- auth = {
|
|
|
- parentID: [...path.slice(0, i + 1)].join("/"),
|
|
|
- parentName: parentFolder.name,
|
|
|
- inheritedAuth: auth.inheritedAuth,
|
|
|
+ // Check if parentFolder is undefined or null
|
|
|
+ if (!parentFolder) {
|
|
|
+ console.error("Parent folder not found for path:", path)
|
|
|
+ return { type: "ok", data: { auth, headers } }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (parentFolderAuth?.authType !== "inherit") {
|
|
|
- auth = {
|
|
|
- parentID: [...path.slice(0, i + 1)].join("/"),
|
|
|
- parentName: parentFolder.name,
|
|
|
- inheritedAuth: parentFolderAuth,
|
|
|
+ const parentFolderAuth: HoppRESTAuth = parentFolder.auth
|
|
|
+ const parentFolderHeaders: HoppRESTHeaders = parentFolder.headers
|
|
|
+
|
|
|
+ // check if the parent folder has authType 'inherit' and if it is the root folder
|
|
|
+ if (
|
|
|
+ parentFolderAuth?.authType === "inherit" &&
|
|
|
+ [...path.slice(0, i + 1)].length === 1
|
|
|
+ ) {
|
|
|
+ auth = {
|
|
|
+ parentID: [...path.slice(0, i + 1)].join("/"),
|
|
|
+ parentName: parentFolder.name,
|
|
|
+ inheritedAuth: auth.inheritedAuth,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parentFolderAuth?.authType !== "inherit") {
|
|
|
+ auth = {
|
|
|
+ parentID: [...path.slice(0, i + 1)].join("/"),
|
|
|
+ parentName: parentFolder.name,
|
|
|
+ inheritedAuth: parentFolderAuth,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // Update headers, overwriting duplicates by key
|
|
|
- if (parentFolderHeaders) {
|
|
|
- const activeHeaders = parentFolderHeaders.filter((h) => h.active)
|
|
|
- activeHeaders.forEach((header) => {
|
|
|
- const index = headers.findIndex(
|
|
|
- (h) => h.inheritedHeader?.key === header.key
|
|
|
+ // Update headers, overwriting duplicates by key
|
|
|
+ if (parentFolderHeaders) {
|
|
|
+ const activeHeaders = parentFolderHeaders.filter(
|
|
|
+ (h) => h.active
|
|
|
)
|
|
|
- const currentPath = [...path.slice(0, i + 1)].join("/")
|
|
|
- if (index !== -1) {
|
|
|
- // Replace the existing header with the same key
|
|
|
- headers[index] = {
|
|
|
- parentID: currentPath,
|
|
|
- parentName: parentFolder.name,
|
|
|
- inheritedHeader: header,
|
|
|
+ activeHeaders.forEach((header) => {
|
|
|
+ const index = headers.findIndex(
|
|
|
+ (h) => h.inheritedHeader?.key === header.key
|
|
|
+ )
|
|
|
+ const currentPath = [...path.slice(0, i + 1)].join("/")
|
|
|
+ if (index !== -1) {
|
|
|
+ // Replace the existing header with the same key
|
|
|
+ headers[index] = {
|
|
|
+ parentID: currentPath,
|
|
|
+ parentName: parentFolder.name,
|
|
|
+ inheritedHeader: header,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ headers.push({
|
|
|
+ parentID: currentPath,
|
|
|
+ parentName: parentFolder.name,
|
|
|
+ inheritedHeader: header,
|
|
|
+ })
|
|
|
}
|
|
|
- } else {
|
|
|
- headers.push({
|
|
|
- parentID: currentPath,
|
|
|
- parentName: parentFolder.name,
|
|
|
- inheritedHeader: header,
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return { type: "ok", data: { auth, headers } }
|
|
|
- })
|
|
|
- )
|
|
|
+ return { type: "ok", data: { auth, headers } }
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public getRESTSearchResultsView(
|
|
|
workspaceHandle: HandleRef<Workspace>,
|
|
|
searchQuery: Ref<string>
|
|
|
- ): Promise<E.Either<never, HandleRef<RESTSearchResultsView>>> {
|
|
|
+ ): Promise<E.Either<never, Handle<RESTSearchResultsView>>> {
|
|
|
const results = ref<HoppCollection[]>([])
|
|
|
|
|
|
const isMatch = (inputText: string, textToMatch: string) =>
|
|
@@ -1248,77 +1263,79 @@ export class PersonalWorkspaceProviderService
|
|
|
}
|
|
|
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidWorkspaceHandle(
|
|
|
- workspaceHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "INVALID_WORKSPACE_HANDLE" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidWorkspaceHandle(
|
|
|
+ workspaceHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "INVALID_WORKSPACE_HANDLE" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return markRaw({
|
|
|
- type: "ok" as const,
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
+ return markRaw({
|
|
|
+ type: "ok" as const,
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
|
|
|
- loading: ref(false),
|
|
|
+ loading: ref(false),
|
|
|
|
|
|
- results,
|
|
|
- onSessionEnd,
|
|
|
- },
|
|
|
- })
|
|
|
- })
|
|
|
- )
|
|
|
+ results,
|
|
|
+ onSessionEnd,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public getRESTCollectionJSONView(
|
|
|
workspaceHandle: HandleRef<Workspace>
|
|
|
- ): Promise<E.Either<never, HandleRef<RESTCollectionJSONView>>> {
|
|
|
+ ): Promise<E.Either<never, Handle<RESTCollectionJSONView>>> {
|
|
|
return Promise.resolve(
|
|
|
- E.right(
|
|
|
- computed(() => {
|
|
|
- if (
|
|
|
- !isValidWorkspaceHandle(
|
|
|
- workspaceHandle,
|
|
|
- this.providerID,
|
|
|
- "personal"
|
|
|
- )
|
|
|
- ) {
|
|
|
- return {
|
|
|
- type: "invalid" as const,
|
|
|
- reason: "INVALID_WORKSPACE_HANDLE" as const,
|
|
|
+ E.right({
|
|
|
+ get: () =>
|
|
|
+ computed(() => {
|
|
|
+ if (
|
|
|
+ !isValidWorkspaceHandle(
|
|
|
+ workspaceHandle,
|
|
|
+ this.providerID,
|
|
|
+ "personal"
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ return {
|
|
|
+ type: "invalid" as const,
|
|
|
+ reason: "INVALID_WORKSPACE_HANDLE" as const,
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return markRaw({
|
|
|
- type: "ok" as const,
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
- content: JSON.stringify(
|
|
|
- this.restCollectionState.value.state,
|
|
|
- null,
|
|
|
- 2
|
|
|
- ),
|
|
|
- },
|
|
|
- })
|
|
|
- })
|
|
|
- )
|
|
|
+ return markRaw({
|
|
|
+ type: "ok" as const,
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: workspaceHandle.value.data.workspaceID,
|
|
|
+ content: JSON.stringify(
|
|
|
+ this.restCollectionState.value.state,
|
|
|
+ null,
|
|
|
+ 2
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+ })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
public getWorkspaceHandle(
|
|
|
workspaceID: string
|
|
|
- ): Promise<E.Either<unknown, HandleRef<Workspace>>> {
|
|
|
+ ): Promise<E.Either<unknown, Handle<Workspace>>> {
|
|
|
if (workspaceID !== "personal") {
|
|
|
return Promise.resolve(E.left("INVALID_WORKSPACE_ID" as const))
|
|
|
}
|
|
@@ -1326,15 +1343,18 @@ export class PersonalWorkspaceProviderService
|
|
|
return Promise.resolve(E.right(this.getPersonalWorkspaceHandle()))
|
|
|
}
|
|
|
|
|
|
- public getPersonalWorkspaceHandle(): HandleRef<Workspace> {
|
|
|
- return shallowRef({
|
|
|
- type: "ok" as const,
|
|
|
- data: {
|
|
|
- providerID: this.providerID,
|
|
|
- workspaceID: "personal",
|
|
|
-
|
|
|
- name: "Personal Workspace",
|
|
|
- },
|
|
|
- })
|
|
|
+ public getPersonalWorkspaceHandle(): Handle<Workspace> {
|
|
|
+ return {
|
|
|
+ get: () =>
|
|
|
+ shallowRef({
|
|
|
+ type: "ok" as const,
|
|
|
+ data: {
|
|
|
+ providerID: this.providerID,
|
|
|
+ workspaceID: "personal",
|
|
|
+
|
|
|
+ name: "Personal Workspace",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ }
|
|
|
}
|
|
|
}
|