feat: collection runner (#3600)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
@@ -48,6 +48,7 @@ import {
|
||||
updateRESTRequestOrder,
|
||||
} from "@hoppscotch/common/newstore/collections"
|
||||
import {
|
||||
generateUniqueRefId,
|
||||
GQLHeader,
|
||||
HoppCollection,
|
||||
HoppGQLRequest,
|
||||
@@ -70,6 +71,7 @@ function initCollectionsSync() {
|
||||
|
||||
gqlCollectionsSyncer.startStoreSync()
|
||||
|
||||
// TODO: fix collection schema transformation on backend maybe?
|
||||
loadUserCollections("REST")
|
||||
loadUserCollections("GQL")
|
||||
|
||||
@@ -94,6 +96,7 @@ function initCollectionsSync() {
|
||||
|
||||
type ExportedUserCollectionREST = {
|
||||
id?: string
|
||||
_ref_id?: string
|
||||
folders: ExportedUserCollectionREST[]
|
||||
requests: Array<HoppRESTRequest & { id: string }>
|
||||
name: string
|
||||
@@ -102,6 +105,7 @@ type ExportedUserCollectionREST = {
|
||||
|
||||
type ExportedUserCollectionGQL = {
|
||||
id?: string
|
||||
_ref_id?: string
|
||||
folders: ExportedUserCollectionGQL[]
|
||||
requests: Array<HoppGQLRequest & { id: string }>
|
||||
name: string
|
||||
@@ -130,11 +134,13 @@ function exportedCollectionToHoppCollection(
|
||||
: {
|
||||
auth: { authType: "inherit", authActive: false },
|
||||
headers: [],
|
||||
_ref_id: generateUniqueRefId("coll"),
|
||||
}
|
||||
|
||||
return {
|
||||
id: restCollection.id,
|
||||
v: 4,
|
||||
_ref_id: data._ref_id ?? generateUniqueRefId("coll"),
|
||||
v: 5,
|
||||
name: restCollection.name,
|
||||
folders: restCollection.folders.map((folder) =>
|
||||
exportedCollectionToHoppCollection(folder, collectionType)
|
||||
@@ -192,11 +198,13 @@ function exportedCollectionToHoppCollection(
|
||||
: {
|
||||
auth: { authType: "inherit", authActive: false },
|
||||
headers: [],
|
||||
_ref_id: generateUniqueRefId("coll"),
|
||||
}
|
||||
|
||||
return {
|
||||
id: gqlCollection.id,
|
||||
v: 4,
|
||||
_ref_id: data._ref_id ?? generateUniqueRefId("coll"),
|
||||
v: 5,
|
||||
name: gqlCollection.name,
|
||||
folders: gqlCollection.folders.map((folder) =>
|
||||
exportedCollectionToHoppCollection(folder, collectionType)
|
||||
@@ -366,6 +374,7 @@ function setupUserCollectionCreatedSubscription() {
|
||||
: {
|
||||
auth: { authType: "inherit", authActive: false },
|
||||
headers: [],
|
||||
_ref_id: generateUniqueRefId("coll"),
|
||||
}
|
||||
|
||||
runDispatchWithOutSyncing(() => {
|
||||
@@ -374,7 +383,8 @@ function setupUserCollectionCreatedSubscription() {
|
||||
name: res.right.userCollectionCreated.title,
|
||||
folders: [],
|
||||
requests: [],
|
||||
v: 4,
|
||||
v: 5,
|
||||
_ref_id: data._ref_id,
|
||||
auth: data.auth,
|
||||
headers: addDescriptionField(data.headers),
|
||||
})
|
||||
@@ -382,7 +392,8 @@ function setupUserCollectionCreatedSubscription() {
|
||||
name: res.right.userCollectionCreated.title,
|
||||
folders: [],
|
||||
requests: [],
|
||||
v: 4,
|
||||
v: 5,
|
||||
_ref_id: data._ref_id,
|
||||
auth: data.auth,
|
||||
headers: addDescriptionField(data.headers),
|
||||
})
|
||||
@@ -587,12 +598,13 @@ function setupUserCollectionDuplicatedSubscription() {
|
||||
)
|
||||
|
||||
// Incoming data transformed to the respective internal representations
|
||||
const { auth, headers } =
|
||||
const { auth, headers, _ref_id } =
|
||||
data && data != "null"
|
||||
? JSON.parse(data)
|
||||
: {
|
||||
auth: { authType: "inherit", authActive: false },
|
||||
headers: [],
|
||||
_ref_id: generateUniqueRefId("coll"),
|
||||
}
|
||||
|
||||
const folders = transformDuplicatedCollections(childCollectionsJSONStr)
|
||||
@@ -607,7 +619,8 @@ function setupUserCollectionDuplicatedSubscription() {
|
||||
name,
|
||||
folders,
|
||||
requests,
|
||||
v: 3,
|
||||
v: 5,
|
||||
_ref_id,
|
||||
auth,
|
||||
headers: addDescriptionField(headers),
|
||||
}
|
||||
@@ -1037,7 +1050,7 @@ function transformDuplicatedCollections(
|
||||
name,
|
||||
folders,
|
||||
requests,
|
||||
v: 3,
|
||||
v: 5,
|
||||
auth,
|
||||
headers: addDescriptionField(headers),
|
||||
}
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
settingsStore,
|
||||
} from "@hoppscotch/common/newstore/settings"
|
||||
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import {
|
||||
generateUniqueRefId,
|
||||
HoppCollection,
|
||||
HoppRESTRequest,
|
||||
} from "@hoppscotch/data"
|
||||
|
||||
import { getSyncInitFunction, StoreSyncDefinitionOf } from "../../lib/sync"
|
||||
import { createMapper } from "../../lib/sync/mapper"
|
||||
@@ -53,6 +57,7 @@ const recursivelySyncCollections = async (
|
||||
authActive: true,
|
||||
},
|
||||
headers: collection.headers ?? [],
|
||||
_ref_id: collection._ref_id,
|
||||
}
|
||||
const res = await createRESTRootUserCollection(
|
||||
collection.name,
|
||||
@@ -69,9 +74,11 @@ const recursivelySyncCollections = async (
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
_ref_id: generateUniqueRefId("coll"),
|
||||
}
|
||||
|
||||
collection.id = parentCollectionID
|
||||
collection._ref_id = returnedData._ref_id ?? generateUniqueRefId("coll")
|
||||
collection.auth = returnedData.auth
|
||||
collection.headers = returnedData.headers
|
||||
removeDuplicateRESTCollectionOrFolder(parentCollectionID, collectionPath)
|
||||
@@ -86,6 +93,7 @@ const recursivelySyncCollections = async (
|
||||
authActive: true,
|
||||
},
|
||||
headers: collection.headers ?? [],
|
||||
_ref_id: collection._ref_id,
|
||||
}
|
||||
|
||||
const res = await createRESTChildUserCollection(
|
||||
@@ -105,9 +113,11 @@ const recursivelySyncCollections = async (
|
||||
authActive: true,
|
||||
},
|
||||
headers: [],
|
||||
_ref_id: generateUniqueRefId("coll"),
|
||||
}
|
||||
|
||||
collection.id = childCollectionId
|
||||
collection._ref_id = returnedData._ref_id ?? generateUniqueRefId("coll")
|
||||
collection.auth = returnedData.auth
|
||||
collection.headers = returnedData.headers
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { PersistableTabState } from "@hoppscotch/common/services/tab"
|
||||
import { HoppTabDocument } from "@hoppscotch/common/helpers/rest/document"
|
||||
import { HoppUser } from "@hoppscotch/common/platform/auth"
|
||||
import { TabStatePlatformDef } from "@hoppscotch/common/platform/tab"
|
||||
import { def as platformAuth } from "@platform/auth"
|
||||
import { getCurrentRestSession, updateUserSession } from "./tabState.api"
|
||||
import { SessionType } from "../../api/generated/graphql"
|
||||
import * as E from "fp-ts/Either"
|
||||
|
||||
async function writeCurrentTabState(
|
||||
_: HoppUser,
|
||||
persistableTabState: PersistableTabState<HoppTabDocument>
|
||||
) {
|
||||
await updateUserSession(JSON.stringify(persistableTabState), SessionType.Rest)
|
||||
}
|
||||
|
||||
async function loadTabStateFromSync(): Promise<PersistableTabState<HoppTabDocument> | null> {
|
||||
const currentUser = platformAuth.getCurrentUser()
|
||||
|
||||
if (!currentUser)
|
||||
throw new Error("Cannot load request from sync without login")
|
||||
|
||||
const res = await getCurrentRestSession()
|
||||
|
||||
if (E.isRight(res)) {
|
||||
const currentRESTSession = res.right.me.currentRESTSession
|
||||
|
||||
return currentRESTSession ? JSON.parse(currentRESTSession) : null
|
||||
} else {
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export const def: TabStatePlatformDef = {
|
||||
loadTabStateFromSync,
|
||||
writeCurrentTabState,
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export default {
|
||||
upperSecondaryStickyFold: "var(--upper-secondary-sticky-fold)",
|
||||
upperTertiaryStickyFold: "var(--upper-tertiary-sticky-fold)",
|
||||
upperFourthStickyFold: "var(--upper-fourth-sticky-fold)",
|
||||
upperRunnerStickyFold: "var(--upper-runner-sticky-fold)",
|
||||
upperMobilePrimaryStickyFold: "var(--upper-mobile-primary-sticky-fold)",
|
||||
upperMobileSecondaryStickyFold:
|
||||
"var(--upper-mobile-secondary-sticky-fold)",
|
||||
|
||||
Reference in New Issue
Block a user