refactor: update all hoppCollection type to remove generic pattern

This commit is contained in:
nivedin
2023-12-11 17:41:02 +05:30
committed by Andrew Bastin
parent 9d2b7cc03f
commit 95953557de
38 changed files with 201 additions and 257 deletions

View File

@@ -1,8 +1,8 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"; import { HoppCollection } from "@hoppscotch/data";
import { HoppEnvs } from "./request"; import { HoppEnvs } from "./request";
export type CollectionRunnerParam = { export type CollectionRunnerParam = {
collections: HoppCollection<HoppRESTRequest>[]; collections: HoppCollection[];
envs: HoppEnvs; envs: HoppEnvs;
delay?: number; delay?: number;
}; };

View File

@@ -33,7 +33,7 @@ export type HoppEnvs = {
export type CollectionStack = { export type CollectionStack = {
path: string; path: string;
collection: HoppCollection<HoppRESTRequest>; collection: HoppCollection;
}; };
export type RequestReport = { export type RequestReport = {

View File

@@ -1,8 +1,4 @@
import { import { HoppCollection, isHoppRESTRequest } from "@hoppscotch/data";
HoppCollection,
HoppRESTRequest,
isHoppRESTRequest,
} from "@hoppscotch/data";
import * as A from "fp-ts/Array"; import * as A from "fp-ts/Array";
import { CommanderError } from "commander"; import { CommanderError } from "commander";
import { HoppCLIError, HoppErrnoException } from "../types/errors"; import { HoppCLIError, HoppErrnoException } from "../types/errors";
@@ -24,9 +20,7 @@ export const hasProperty = <P extends PropertyKey>(
* @returns True, if unknown parameter is valid Hoppscotch REST Collection; * @returns True, if unknown parameter is valid Hoppscotch REST Collection;
* False, otherwise. * False, otherwise.
*/ */
export const isRESTCollection = ( export const isRESTCollection = (param: unknown): param is HoppCollection => {
param: unknown
): param is HoppCollection<HoppRESTRequest> => {
if (!!param && typeof param === "object") { if (!!param && typeof param === "object") {
if (!hasProperty(param, "v") || typeof param.v !== "number") { if (!hasProperty(param, "v") || typeof param.v !== "number") {
return false; return false;
@@ -62,7 +56,6 @@ export const isRESTCollection = (
return false; return false;
}; };
/** /**
* Checks if given error data is of type HoppCLIError, based on existence * Checks if given error data is of type HoppCLIError, based on existence
* of code property. * of code property.

View File

@@ -3,7 +3,7 @@ import { pipe } from "fp-ts/function";
import { bold } from "chalk"; import { bold } from "chalk";
import { log } from "console"; import { log } from "console";
import round from "lodash/round"; import round from "lodash/round";
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"; import { HoppCollection } from "@hoppscotch/data";
import { import {
HoppEnvs, HoppEnvs,
CollectionStack, CollectionStack,
@@ -41,9 +41,9 @@ const { WARN, FAIL } = exceptionColors;
* @param param Data of hopp-collection with hopp-requests, envs to be processed. * @param param Data of hopp-collection with hopp-requests, envs to be processed.
* @returns List of report for each processed request. * @returns List of report for each processed request.
*/ */
export const collectionsRunner = export const collectionsRunner = async (
async (param: CollectionRunnerParam): Promise<RequestReport[]> => param: CollectionRunnerParam
{ ): Promise<RequestReport[]> => {
const envs: HoppEnvs = param.envs; const envs: HoppEnvs = param.envs;
const delay = param.delay ?? 0; const delay = param.delay ?? 0;
const requestsReport: RequestReport[] = []; const requestsReport: RequestReport[] = [];
@@ -92,7 +92,7 @@ export const collectionsRunner =
} }
return requestsReport; return requestsReport;
}; };
/** /**
* Transforms collections to generate collection-stack which describes each collection's * Transforms collections to generate collection-stack which describes each collection's
@@ -100,9 +100,7 @@ export const collectionsRunner =
* @param collections Hopp-collection objects to be mapped to collection-stack type. * @param collections Hopp-collection objects to be mapped to collection-stack type.
* @returns Mapped collections to collection-stack. * @returns Mapped collections to collection-stack.
*/ */
const getCollectionStack = ( const getCollectionStack = (collections: HoppCollection[]): CollectionStack[] =>
collections: HoppCollection<HoppRESTRequest>[]
): CollectionStack[] =>
pipe( pipe(
collections, collections,
A.map( A.map(

View File

@@ -2,7 +2,7 @@ import fs from "fs/promises";
import { FormDataEntry } from "../types/request"; import { FormDataEntry } from "../types/request";
import { error } from "../types/errors"; import { error } from "../types/errors";
import { isRESTCollection, isHoppErrnoException } from "./checks"; import { isRESTCollection, isHoppErrnoException } from "./checks";
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"; import { HoppCollection } from "@hoppscotch/data";
/** /**
* Parses array of FormDataEntry to FormData. * Parses array of FormDataEntry to FormData.
@@ -35,20 +35,20 @@ export const parseErrorMessage = (e: unknown) => {
}; };
export async function readJsonFile(path: string): Promise<unknown> { export async function readJsonFile(path: string): Promise<unknown> {
if(!path.endsWith('.json')) { if (!path.endsWith(".json")) {
throw error({ code: "INVALID_FILE_TYPE", data: path }) throw error({ code: "INVALID_FILE_TYPE", data: path });
} }
try { try {
await fs.access(path) await fs.access(path);
} catch (e) { } catch (e) {
throw error({ code: "FILE_NOT_FOUND", path: path }) throw error({ code: "FILE_NOT_FOUND", path: path });
} }
try { try {
return JSON.parse((await fs.readFile(path)).toString()) return JSON.parse((await fs.readFile(path)).toString());
} catch(e) { } catch (e) {
throw error({ code: "UNKNOWN_ERROR", data: e }) throw error({ code: "UNKNOWN_ERROR", data: e });
} }
} }
@@ -56,22 +56,24 @@ export async function readJsonFile(path: string): Promise<unknown> {
* Parses collection json file for given path:context.path, and validates * Parses collection json file for given path:context.path, and validates
* the parsed collectiona array. * the parsed collectiona array.
* @param path Collection json file path. * @param path Collection json file path.
* @returns For successful parsing we get array of HoppCollection<HoppRESTRequest>, * @returns For successful parsing we get array of HoppCollection,
*/ */
export async function parseCollectionData( export async function parseCollectionData(
path: string path: string
): Promise<HoppCollection<HoppRESTRequest>[]> { ): Promise<HoppCollection[]> {
let contents = await readJsonFile(path) let contents = await readJsonFile(path);
const maybeArrayOfCollections: unknown[] = Array.isArray(contents) ? contents : [contents] const maybeArrayOfCollections: unknown[] = Array.isArray(contents)
? contents
: [contents];
if(maybeArrayOfCollections.some((x) => !isRESTCollection(x))) { if (maybeArrayOfCollections.some((x) => !isRESTCollection(x))) {
throw error({ throw error({
code: "MALFORMED_COLLECTION", code: "MALFORMED_COLLECTION",
path, path,
data: "Please check the collection data.", data: "Please check the collection data.",
}) });
} }
return maybeArrayOfCollections as HoppCollection<HoppRESTRequest>[] return maybeArrayOfCollections as HoppCollection[];
}; }

View File

@@ -13,7 +13,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { computed } from "vue" import { computed } from "vue"
import { graphqlCollectionStore } from "~/newstore/collections" import { graphqlCollectionStore } from "~/newstore/collections"
@@ -28,7 +28,7 @@ const pathFolders = computed(() => {
.slice(0, -1) .slice(0, -1)
.map((x) => parseInt(x)) .map((x) => parseInt(x))
const pathItems: HoppCollection<HoppGQLRequest>[] = [] const pathItems: HoppCollection[] = []
let currentFolder = let currentFolder =
graphqlCollectionStore.value.state[folderIndicies.shift()!] graphqlCollectionStore.value.state[folderIndicies.shift()!]

View File

@@ -20,7 +20,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { computed } from "vue" import { computed } from "vue"
import { restCollectionStore } from "~/newstore/collections" import { restCollectionStore } from "~/newstore/collections"
import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring" import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring"
@@ -36,7 +36,7 @@ const pathFolders = computed(() => {
.slice(0, -1) .slice(0, -1)
.map((x) => parseInt(x)) .map((x) => parseInt(x))
const pathItems: HoppCollection<HoppRESTRequest>[] = [] const pathItems: HoppCollection[] = []
let currentFolder = restCollectionStore.value.state[folderIndicies.shift()!] let currentFolder = restCollectionStore.value.state[folderIndicies.shift()!]
pathItems.push(currentFolder) pathItems.push(currentFolder)

View File

@@ -208,7 +208,7 @@ import IconFolder from "~icons/lucide/folder"
import IconFolderOpen from "~icons/lucide/folder-open" import IconFolderOpen from "~icons/lucide/folder-open"
import IconSettings2 from "~icons/lucide/settings-2" import IconSettings2 from "~icons/lucide/settings-2"
import { ref, computed, watch } from "vue" import { ref, computed, watch } from "vue"
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { TippyComponent } from "vue-tippy" import { TippyComponent } from "vue-tippy"
import { TeamCollection } from "~/helpers/teams/TeamCollection" import { TeamCollection } from "~/helpers/teams/TeamCollection"
@@ -227,7 +227,7 @@ const props = withDefaults(
defineProps<{ defineProps<{
id: string id: string
parentID?: string | null parentID?: string | null
data: HoppCollection<HoppRESTRequest> | TeamCollection data: HoppCollection | TeamCollection
/** /**
* Collection component can be used for both collections and folders. * Collection component can be used for both collections and folders.
* folderType is used to determine which one it is. * folderType is used to determine which one it is.
@@ -310,8 +310,8 @@ const collectionIcon = computed(() => {
}) })
const collectionName = computed(() => { const collectionName = computed(() => {
if ((props.data as HoppCollection<HoppRESTRequest>).name) if ((props.data as HoppCollection).name)
return (props.data as HoppCollection<HoppRESTRequest>).name return (props.data as HoppCollection).name
return (props.data as TeamCollection).title return (props.data as TeamCollection).title
}) })

View File

@@ -29,7 +29,6 @@ import { PropType, computed, ref } from "vue"
import { useI18n } from "~/composables/i18n" import { useI18n } from "~/composables/i18n"
import { useToast } from "~/composables/toast" import { useToast } from "~/composables/toast"
import { HoppCollection } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { HoppRESTRequest } from "@hoppscotch/data"
import { appendRESTCollections, restCollections$ } from "~/newstore/collections" import { appendRESTCollections, restCollections$ } from "~/newstore/collections"
import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue" import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue"
import { GetMyTeamsQuery } from "~/helpers/backend/graphql" import { GetMyTeamsQuery } from "~/helpers/backend/graphql"
@@ -88,9 +87,7 @@ const showImportFailedError = () => {
toast.error(t("import.failed")) toast.error(t("import.failed"))
} }
const handleImportToStore = async ( const handleImportToStore = async (collections: HoppCollection[]) => {
collections: HoppCollection<HoppRESTRequest>[]
) => {
const importResult = const importResult =
props.collectionsType.type === "my-collections" props.collectionsType.type === "my-collections"
? await importToPersonalWorkspace(collections) ? await importToPersonalWorkspace(collections)
@@ -104,18 +101,14 @@ const handleImportToStore = async (
} }
} }
const importToPersonalWorkspace = ( const importToPersonalWorkspace = (collections: HoppCollection[]) => {
collections: HoppCollection<HoppRESTRequest>[]
) => {
appendRESTCollections(collections) appendRESTCollections(collections)
return E.right({ return E.right({
success: true, success: true,
}) })
} }
const importToTeamsWorkspace = async ( const importToTeamsWorkspace = async (collections: HoppCollection[]) => {
collections: HoppCollection<HoppRESTRequest>[]
) => {
if (!hasTeamWriteAccess.value || !selectedTeamID.value) { if (!hasTeamWriteAccess.value || !selectedTeamID.value) {
return E.left({ return E.left({
success: false, success: false,

View File

@@ -358,7 +358,7 @@ export type Collection = {
isLastItem: boolean isLastItem: boolean
data: { data: {
parentIndex: null parentIndex: null
data: HoppCollection<HoppRESTRequest> data: HoppCollection
} }
} }
@@ -367,7 +367,7 @@ type Folder = {
isLastItem: boolean isLastItem: boolean
data: { data: {
parentIndex: string parentIndex: string
data: HoppCollection<HoppRESTRequest> data: HoppCollection
} }
} }
@@ -394,7 +394,7 @@ type CollectionType =
const props = defineProps({ const props = defineProps({
filteredCollections: { filteredCollections: {
type: Array as PropType<HoppCollection<HoppRESTRequest>[]>, type: Array as PropType<HoppCollection[]>,
default: () => [], default: () => [],
required: true, required: true,
}, },
@@ -426,35 +426,35 @@ const emit = defineEmits<{
event: "add-request", event: "add-request",
payload: { payload: {
path: string path: string
folder: HoppCollection<HoppRESTRequest> folder: HoppCollection
} }
): void ): void
( (
event: "add-folder", event: "add-folder",
payload: { payload: {
path: string path: string
folder: HoppCollection<HoppRESTRequest> folder: HoppCollection
} }
): void ): void
( (
event: "edit-collection", event: "edit-collection",
payload: { payload: {
collectionIndex: string collectionIndex: string
collection: HoppCollection<HoppRESTRequest> collection: HoppCollection
} }
): void ): void
( (
event: "edit-folder", event: "edit-folder",
payload: { payload: {
folderPath: string folderPath: string
folder: HoppCollection<HoppRESTRequest> folder: HoppCollection
} }
): void ): void
( (
event: "edit-properties", event: "edit-properties",
payload: { payload: {
collectionIndex: string collectionIndex: string
collection: HoppCollection<HoppRESTRequest> collection: HoppCollection
} }
): void ): void
( (
@@ -472,7 +472,7 @@ const emit = defineEmits<{
request: HoppRESTRequest request: HoppRESTRequest
} }
): void ): void
(event: "export-data", payload: HoppCollection<HoppRESTRequest>): void (event: "export-data", payload: HoppCollection): void
(event: "remove-collection", payload: string): void (event: "remove-collection", payload: string): void
(event: "remove-folder", payload: string): void (event: "remove-folder", payload: string): void
( (
@@ -686,10 +686,10 @@ const updateCollectionOrder = (
type MyCollectionNode = Collection | Folder | Requests type MyCollectionNode = Collection | Folder | Requests
class MyCollectionsAdapter implements SmartTreeAdapter<MyCollectionNode> { class MyCollectionsAdapter implements SmartTreeAdapter<MyCollectionNode> {
constructor(public data: Ref<HoppCollection<HoppRESTRequest>[]>) {} constructor(public data: Ref<HoppCollection[]>) {}
navigateToFolderWithIndexPath( navigateToFolderWithIndexPath(
collections: HoppCollection<HoppRESTRequest>[], collections: HoppCollection[],
indexPaths: number[] indexPaths: number[]
) { ) {
if (indexPaths.length === 0) return null if (indexPaths.length === 0) return null

View File

@@ -68,7 +68,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { watch, ref } from "vue" import { watch, ref } from "vue"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { RESTOptionTabs } from "../http/RequestOptions.vue" import { RESTOptionTabs } from "../http/RequestOptions.vue"
import { TeamCollection } from "~/helpers/teams/TeamCollection" import { TeamCollection } from "~/helpers/teams/TeamCollection"
import { clone } from "lodash-es" import { clone } from "lodash-es"
@@ -77,7 +77,7 @@ import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
const t = useI18n() const t = useI18n()
type EditingProperties = { type EditingProperties = {
collection: HoppCollection<HoppRESTRequest> | TeamCollection | null collection: HoppCollection | TeamCollection | null
isRootCollection: boolean isRootCollection: boolean
path: string path: string
inheritedProperties: HoppInheritedProperty | undefined inheritedProperties: HoppInheritedProperty | undefined

View File

@@ -36,7 +36,7 @@
import { ref } from "vue" import { ref } from "vue"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { HoppGQLRequest, makeCollection } from "@hoppscotch/data" import { makeCollection } from "@hoppscotch/data"
import { addGraphqlCollection } from "~/newstore/collections" import { addGraphqlCollection } from "~/newstore/collections"
import { platform } from "~/platform" import { platform } from "~/platform"
@@ -60,7 +60,7 @@ const addNewCollection = () => {
} }
addGraphqlCollection( addGraphqlCollection(
makeCollection<HoppGQLRequest>({ makeCollection({
name: name.value, name: name.value,
folders: [], folders: [],
requests: [], requests: [],

View File

@@ -246,14 +246,14 @@ import { removeGraphqlCollection } from "~/newstore/collections"
import { Picked } from "~/helpers/types/HoppPicked" import { Picked } from "~/helpers/types/HoppPicked"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { GQLTabService } from "~/services/tab/graphql" import { GQLTabService } from "~/services/tab/graphql"
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
const props = defineProps<{ const props = defineProps<{
picked: Picked | null picked: Picked | null
// Whether the viewing context is related to picking (activates 'select' events) // Whether the viewing context is related to picking (activates 'select' events)
saveRequest: boolean saveRequest: boolean
collectionIndex: number | null collectionIndex: number | null
collection: HoppCollection<HoppGQLRequest> collection: HoppCollection
isFiltered: boolean isFiltered: boolean
}>() }>()
@@ -275,7 +275,7 @@ const emit = defineEmits<{
e: "edit-properties", e: "edit-properties",
payload: { payload: {
collectionIndex: string | null collectionIndex: string | null
collection: HoppCollection<HoppGQLRequest> collection: HoppCollection
} }
): void ): void
(e: "edit-collection"): void (e: "edit-collection"): void

View File

@@ -37,12 +37,12 @@ import { ref, watch } from "vue"
import { editGraphqlCollection } from "~/newstore/collections" import { editGraphqlCollection } from "~/newstore/collections"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
const props = defineProps<{ const props = defineProps<{
show: boolean show: boolean
editingCollectionIndex: number | null editingCollectionIndex: number | null
editingCollection: HoppCollection<HoppGQLRequest> | null editingCollection: HoppCollection | null
editingCollectionName: string editingCollectionName: string
}>() }>()

View File

@@ -230,7 +230,7 @@ import { computed, ref } from "vue"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { GQLTabService } from "~/services/tab/graphql" import { GQLTabService } from "~/services/tab/graphql"
import { Picked } from "~/helpers/types/HoppPicked" import { Picked } from "~/helpers/types/HoppPicked"
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
const toast = useToast() const toast = useToast()
const t = useI18n() const t = useI18n()
@@ -242,7 +242,7 @@ const props = defineProps<{
picked: Picked picked: Picked
// Whether the request is in a selectable mode (activates 'select' event) // Whether the request is in a selectable mode (activates 'select' event)
saveRequest: boolean saveRequest: boolean
folder: HoppCollection<HoppGQLRequest> folder: HoppCollection
folderIndex: number folderIndex: number
collectionIndex: number collectionIndex: number
folderPath: string folderPath: string

View File

@@ -11,7 +11,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useI18n } from "~/composables/i18n" import { useI18n } from "~/composables/i18n"
import { useToast } from "~/composables/toast" import { useToast } from "~/composables/toast"
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { ImporterOrExporter } from "~/components/importExport/types" import { ImporterOrExporter } from "~/components/importExport/types"
import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource" import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource"
import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource" import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource"
@@ -214,9 +214,7 @@ const showImportFailedError = () => {
toast.error(t("import.failed")) toast.error(t("import.failed"))
} }
const handleImportToStore = async ( const handleImportToStore = async (gqlCollections: HoppCollection[]) => {
gqlCollections: HoppCollection<HoppGQLRequest>[]
) => {
setGraphqlCollections(gqlCollections) setGraphqlCollections(gqlCollections)
toast.success(t("import.success")) toast.success(t("import.success"))
} }

View File

@@ -209,9 +209,9 @@ const showModalEditFolder = ref(false)
const showModalEditRequest = ref(false) const showModalEditRequest = ref(false)
const showModalEditProperties = ref(false) const showModalEditProperties = ref(false)
const editingCollection = ref<HoppCollection<HoppGQLRequest> | null>(null) const editingCollection = ref<HoppCollection | null>(null)
const editingCollectionIndex = ref<number | null>(null) const editingCollectionIndex = ref<number | null>(null)
const editingFolder = ref<HoppCollection<HoppGQLRequest> | null>(null) const editingFolder = ref<HoppCollection | null>(null)
const editingFolderName = ref("") const editingFolderName = ref("")
const editingFolderIndex = ref<number | null>(null) const editingFolderIndex = ref<number | null>(null)
const editingFolderPath = ref("") const editingFolderPath = ref("")
@@ -219,7 +219,7 @@ const editingRequest = ref<HoppGQLRequest | null>(null)
const editingRequestIndex = ref<number | null>(null) const editingRequestIndex = ref<number | null>(null)
const editingProperties = ref<{ const editingProperties = ref<{
collection: HoppCollection<HoppGQLRequest> | null collection: HoppCollection | null
isRootCollection: boolean isRootCollection: boolean
path: string path: string
inheritedProperties?: HoppInheritedProperty inheritedProperties?: HoppInheritedProperty
@@ -318,7 +318,7 @@ const displayModalEditProperties = (show: boolean) => {
} }
const editCollection = ( const editCollection = (
collection: HoppCollection<HoppGQLRequest>, collection: HoppCollection,
collectionIndex: number collectionIndex: number
) => { ) => {
editingCollection.value = collection editingCollection.value = collection
@@ -404,7 +404,7 @@ const addFolder = (payload: { path: string }) => {
} }
const editFolder = (payload: { const editFolder = (payload: {
folder: HoppCollection<HoppGQLRequest> folder: HoppCollection
folderPath: string folderPath: string
}) => { }) => {
const { folder, folderPath } = payload const { folder, folderPath } = payload
@@ -553,7 +553,7 @@ const editProperties = ({
collection, collection,
}: { }: {
collectionIndex: string | null collectionIndex: string | null
collection: HoppCollection<HoppGQLRequest> | null collection: HoppCollection | null
}) => { }) => {
if (collectionIndex === null || collection === null) return if (collectionIndex === null || collection === null) return
@@ -583,7 +583,7 @@ const editProperties = ({
} }
const setCollectionProperties = (newCollection: { const setCollectionProperties = (newCollection: {
collection: HoppCollection<HoppGQLRequest> collection: HoppCollection
path: string path: string
isRootCollection: boolean isRootCollection: boolean
}) => { }) => {

View File

@@ -277,15 +277,11 @@ const collectionsType = ref<CollectionType>({
}) })
// Collection Data // Collection Data
const editingCollection = ref< const editingCollection = ref<HoppCollection | TeamCollection | null>(null)
HoppCollection<HoppRESTRequest> | TeamCollection | null
>(null)
const editingCollectionName = ref<string | null>(null) const editingCollectionName = ref<string | null>(null)
const editingCollectionIndex = ref<number | null>(null) const editingCollectionIndex = ref<number | null>(null)
const editingCollectionID = ref<string | null>(null) const editingCollectionID = ref<string | null>(null)
const editingFolder = ref< const editingFolder = ref<HoppCollection | TeamCollection | null>(null)
HoppCollection<HoppRESTRequest> | TeamCollection | null
>(null)
const editingFolderName = ref<string | null>(null) const editingFolderName = ref<string | null>(null)
const editingFolderPath = ref<string | null>(null) const editingFolderPath = ref<string | null>(null)
const editingRequest = ref<HoppRESTRequest | null>(null) const editingRequest = ref<HoppRESTRequest | null>(null)
@@ -294,7 +290,7 @@ const editingRequestIndex = ref<number | null>(null)
const editingRequestID = ref<string | null>(null) const editingRequestID = ref<string | null>(null)
const editingProperties = ref<{ const editingProperties = ref<{
collection: HoppCollection<HoppRESTRequest> | TeamCollection | null collection: HoppCollection | TeamCollection | null
isRootCollection: boolean isRootCollection: boolean
path: string path: string
inheritedProperties?: HoppInheritedProperty inheritedProperties?: HoppInheritedProperty
@@ -660,7 +656,7 @@ const addNewRootCollection = (name: string) => {
const addRequest = (payload: { const addRequest = (payload: {
path: string path: string
folder: HoppCollection<HoppRESTRequest> | TeamCollection folder: HoppCollection | TeamCollection
}) => { }) => {
const { path, folder } = payload const { path, folder } = payload
editingFolder.value = folder editingFolder.value = folder
@@ -760,7 +756,7 @@ const onAddRequest = (requestName: string) => {
const addFolder = (payload: { const addFolder = (payload: {
path: string path: string
folder: HoppCollection<HoppRESTRequest> | TeamCollection folder: HoppCollection | TeamCollection
}) => { }) => {
const { path, folder } = payload const { path, folder } = payload
editingFolder.value = folder editingFolder.value = folder
@@ -819,15 +815,13 @@ const onAddFolder = (folderName: string) => {
const editCollection = (payload: { const editCollection = (payload: {
collectionIndex: string collectionIndex: string
collection: HoppCollection<HoppRESTRequest> | TeamCollection collection: HoppCollection | TeamCollection
}) => { }) => {
const { collectionIndex, collection } = payload const { collectionIndex, collection } = payload
editingCollection.value = collection editingCollection.value = collection
if (collectionsType.value.type === "my-collections") { if (collectionsType.value.type === "my-collections") {
editingCollectionIndex.value = parseInt(collectionIndex) editingCollectionIndex.value = parseInt(collectionIndex)
editingCollectionName.value = ( editingCollectionName.value = (collection as HoppCollection).name
collection as HoppCollection<HoppRESTRequest>
).name
} else { } else {
editingCollectionName.value = (collection as TeamCollection).title editingCollectionName.value = (collection as TeamCollection).title
} }
@@ -880,13 +874,13 @@ const updateEditingCollection = (newName: string) => {
const editFolder = (payload: { const editFolder = (payload: {
folderPath: string | undefined folderPath: string | undefined
folder: HoppCollection<HoppRESTRequest> | TeamCollection folder: HoppCollection | TeamCollection
}) => { }) => {
const { folderPath, folder } = payload const { folderPath, folder } = payload
editingFolder.value = folder editingFolder.value = folder
if (collectionsType.value.type === "my-collections" && folderPath) { if (collectionsType.value.type === "my-collections" && folderPath) {
editingFolderPath.value = folderPath editingFolderPath.value = folderPath
editingFolderName.value = (folder as HoppCollection<HoppRESTRequest>).name editingFolderName.value = (folder as HoppCollection).name
} else { } else {
editingFolderName.value = (folder as TeamCollection).title editingFolderName.value = (folder as TeamCollection).title
} }
@@ -900,7 +894,7 @@ const updateEditingFolder = (newName: string) => {
if (!editingFolderPath.value) return if (!editingFolderPath.value) return
editRESTFolder(editingFolderPath.value, { editRESTFolder(editingFolderPath.value, {
...(editingFolder.value as HoppCollection<HoppRESTRequest>), ...(editingFolder.value as HoppCollection),
name: newName, name: newName,
}) })
displayModalEditFolder(false) displayModalEditFolder(false)
@@ -1958,13 +1952,11 @@ const initializeDownloadCollection = async (
* Triggered by the export button in the tippy menu * Triggered by the export button in the tippy menu
* @param collection - Collection or folder to be exported * @param collection - Collection or folder to be exported
*/ */
const exportData = async ( const exportData = async (collection: HoppCollection | TeamCollection) => {
collection: HoppCollection<HoppRESTRequest> | TeamCollection
) => {
if (collectionsType.value.type === "my-collections") { if (collectionsType.value.type === "my-collections") {
const collectionJSON = JSON.stringify(collection) const collectionJSON = JSON.stringify(collection)
const name = (collection as HoppCollection<HoppRESTRequest>).name const name = (collection as HoppCollection).name
initializeDownloadCollection(collectionJSON, name) initializeDownloadCollection(collectionJSON, name)
} else { } else {
@@ -2007,7 +1999,7 @@ const shareRequest = ({ request }: { request: HoppRESTRequest }) => {
const editProperties = (payload: { const editProperties = (payload: {
collectionIndex: string collectionIndex: string
collection: HoppCollection<HoppRESTRequest> | TeamCollection collection: HoppCollection | TeamCollection
}) => { }) => {
const { collection, collectionIndex } = payload const { collection, collectionIndex } = payload
@@ -2096,7 +2088,7 @@ const editProperties = (payload: {
} }
const setCollectionProperties = (newCollection: { const setCollectionProperties = (newCollection: {
collection: HoppCollection<HoppRESTRequest> collection: HoppCollection
path: string path: string
isRootCollection: boolean isRootCollection: boolean
}) => { }) => {

View File

@@ -31,7 +31,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { computed, ref } from "vue" import { computed, ref } from "vue"
import { useI18n } from "~/composables/i18n" import { useI18n } from "~/composables/i18n"
import { useReadonlyStream } from "~/composables/stream" import { useReadonlyStream } from "~/composables/stream"
@@ -48,7 +48,7 @@ const hasSelectedCollectionID = computed(() => {
const myCollections = useReadonlyStream(restCollections$, []) const myCollections = useReadonlyStream(restCollections$, [])
const emit = defineEmits<{ const emit = defineEmits<{
(e: "importFromMyCollection", content: HoppCollection<HoppRESTRequest>): void (e: "importFromMyCollection", content: HoppCollection): void
}>() }>()
const fetchCollectionFromMyCollections = async () => { const fetchCollectionFromMyCollections = async () => {

View File

@@ -4,7 +4,6 @@ import * as TE from "fp-ts/TaskEither"
import { pipe, flow } from "fp-ts/function" import { pipe, flow } from "fp-ts/function"
import { import {
HoppCollection, HoppCollection,
HoppRESTRequest,
makeCollection, makeCollection,
translateToNewRequest, translateToNewRequest,
} from "@hoppscotch/data" } from "@hoppscotch/data"
@@ -118,9 +117,7 @@ export const getCompleteCollectionTree = (
) )
) )
export const teamCollToHoppRESTColl = ( export const teamCollToHoppRESTColl = (coll: TeamCollection): HoppCollection =>
coll: TeamCollection
): HoppCollection<HoppRESTRequest> =>
makeCollection({ makeCollection({
name: coll.title, name: coll.title,
folders: coll.children?.map(teamCollToHoppRESTColl) ?? [], folders: coll.children?.map(teamCollToHoppRESTColl) ?? [],

View File

@@ -1,4 +1,4 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { getAffectedIndexes } from "./affectedIndex" import { getAffectedIndexes } from "./affectedIndex"
import { GetSingleRequestDocument } from "../backend/graphql" import { GetSingleRequestDocument } from "../backend/graphql"
import { runGQLQuery } from "../backend/GQLClient" import { runGQLQuery } from "../backend/GQLClient"
@@ -225,9 +225,9 @@ export async function resetTeamRequestsContext() {
} }
export function getFoldersByPath( export function getFoldersByPath(
collections: HoppCollection<HoppRESTRequest>[], collections: HoppCollection[],
path: string path: string
): HoppCollection<HoppRESTRequest>[] { ): HoppCollection[] {
if (!path) return collections if (!path) return collections
// path will be like this "0/0/1" these are the indexes of the folders // path will be like this "0/0/1" these are the indexes of the folders

View File

@@ -57,7 +57,7 @@ export function resolveSaveContextOnRequestReorder(payload: {
} }
export function getRequestsByPath( export function getRequestsByPath(
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection[],
path: string path: string
): HoppRESTRequest[] | HoppGQLRequest[] { ): HoppRESTRequest[] | HoppGQLRequest[] {
// path will be like this "0/0/1" these are the indexes of the folders // path will be like this "0/0/1" these are the indexes of the folders

View File

@@ -1,7 +1,5 @@
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
export const gqlCollectionsExporter = ( export const gqlCollectionsExporter = (gqlCollections: HoppCollection[]) => {
gqlCollections: HoppCollection<HoppGQLRequest>[]
) => {
return JSON.stringify(gqlCollections, null, 2) return JSON.stringify(gqlCollections, null, 2)
} }

View File

@@ -1,7 +1,5 @@
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
export const myCollectionsExporter = ( export const myCollectionsExporter = (myCollections: HoppCollection[]) => {
myCollections: HoppCollection<HoppRESTRequest>[]
) => {
return JSON.stringify(myCollections, null, 2) return JSON.stringify(myCollections, null, 2)
} }

View File

@@ -1,12 +1,12 @@
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
// TODO: add zod validation // TODO: add zod validation
export const hoppGqlCollectionsImporter = ( export const hoppGqlCollectionsImporter = (
content: string content: string
): E.Either<"INVALID_JSON", HoppCollection<HoppGQLRequest>[]> => { ): E.Either<"INVALID_JSON", HoppCollection[]> => {
return E.tryCatch( return E.tryCatch(
() => JSON.parse(content) as HoppCollection<HoppGQLRequest>[], () => JSON.parse(content) as HoppCollection[],
() => "INVALID_JSON" () => "INVALID_JSON"
) )
} }

View File

@@ -192,7 +192,7 @@ const getHoppRequest = (req: InsomniaRequestResource): HoppRESTRequest =>
const getHoppFolder = ( const getHoppFolder = (
folderRes: InsomniaFolderResource, folderRes: InsomniaFolderResource,
resources: InsomniaResource[] resources: InsomniaResource[]
): HoppCollection<HoppRESTRequest> => ): HoppCollection =>
makeCollection({ makeCollection({
name: folderRes.name ?? "", name: folderRes.name ?? "",
folders: getFoldersIn(folderRes, resources).map((f) => folders: getFoldersIn(folderRes, resources).map((f) =>

View File

@@ -12,7 +12,6 @@ import {
HoppRESTHeader, HoppRESTHeader,
HoppRESTParam, HoppRESTParam,
HoppRESTReqBody, HoppRESTReqBody,
HoppRESTRequest,
knownContentTypes, knownContentTypes,
makeRESTRequest, makeRESTRequest,
HoppCollection, HoppCollection,
@@ -581,7 +580,7 @@ const convertPathToHoppReqs = (
const convertOpenApiDocToHopp = ( const convertOpenApiDocToHopp = (
doc: OpenAPI.Document doc: OpenAPI.Document
): TE.TaskEither<never, HoppCollection<HoppRESTRequest>[]> => { ): TE.TaskEither<never, HoppCollection[]> => {
const name = doc.info.title const name = doc.info.title
const paths = Object.entries(doc.paths ?? {}) const paths = Object.entries(doc.paths ?? {})
@@ -589,7 +588,7 @@ const convertOpenApiDocToHopp = (
.flat() .flat()
return TE.of([ return TE.of([
makeCollection<HoppRESTRequest>({ makeCollection({
name, name,
folders: [], folders: [],
requests: paths, requests: paths,

View File

@@ -283,7 +283,7 @@ const getHoppRequest = (item: Item): HoppRESTRequest => {
}) })
} }
const getHoppFolder = (ig: ItemGroup<Item>): HoppCollection<HoppRESTRequest> => const getHoppFolder = (ig: ItemGroup<Item>): HoppCollection =>
makeCollection({ makeCollection({
name: ig.name, name: ig.name,
folders: pipe( folders: pipe(

View File

@@ -1074,8 +1074,7 @@ export default class NewTeamCollectionAdapter {
const parentFolderAuth = data.auth const parentFolderAuth = data.auth
const parentFolderHeaders = data.headers const parentFolderHeaders = data.headers
const isRootCollection = path.length === 1 if (parentFolderAuth?.authType === "inherit") {
if (parentFolderAuth?.authType === "inherit" && isRootCollection) {
auth = { auth = {
parentID: parentFolder.id ?? folderPath, parentID: parentFolder.id ?? folderPath,
parentName: parentFolder.title, parentName: parentFolder.title,

View File

@@ -14,7 +14,7 @@ import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
const defaultRESTCollectionState = { const defaultRESTCollectionState = {
state: [ state: [
makeCollection<HoppRESTRequest>({ makeCollection({
name: "My Collection", name: "My Collection",
folders: [], folders: [],
requests: [], requests: [],
@@ -29,7 +29,7 @@ const defaultRESTCollectionState = {
const defaultGraphqlCollectionState = { const defaultGraphqlCollectionState = {
state: [ state: [
makeCollection<HoppGQLRequest>({ makeCollection({
name: "My GraphQL Collection", name: "My GraphQL Collection",
folders: [], folders: [],
requests: [], requests: [],
@@ -50,7 +50,7 @@ type GraphqlCollectionStoreType = typeof defaultGraphqlCollectionState
* Not removing this behaviour because i'm not sure if we utilize this behaviour anywhere and i found this on a tight time crunch. * Not removing this behaviour because i'm not sure if we utilize this behaviour anywhere and i found this on a tight time crunch.
*/ */
export function navigateToFolderWithIndexPath( export function navigateToFolderWithIndexPath(
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection[],
indexPaths: number[] indexPaths: number[]
) { ) {
if (indexPaths.length === 0) return null if (indexPaths.length === 0) return null
@@ -79,7 +79,9 @@ export function cascadeParentCollectionForHeaderAuth(
}, },
} }
const headers: HoppInheritedProperty["headers"] = [] const headers: HoppInheritedProperty["headers"] = []
if (!folderPath) return { auth, headers } if (!folderPath) return { auth, headers }
const path = folderPath.split("/").map((i) => parseInt(i)) const path = folderPath.split("/").map((i) => parseInt(i))
// Check if the path is empty or invalid // Check if the path is empty or invalid
@@ -104,9 +106,7 @@ export function cascadeParentCollectionForHeaderAuth(
const parentFolderAuth = parentFolder.auth const parentFolderAuth = parentFolder.auth
const parentFolderHeaders = parentFolder.headers const parentFolderHeaders = parentFolder.headers
const isRootCollection = path.length === 1 if (parentFolderAuth?.authType === "inherit") {
if (parentFolderAuth?.authType === "inherit" && isRootCollection) {
auth = { auth = {
parentID: folderPath, parentID: folderPath,
parentName: parentFolder.name, parentName: parentFolder.name,
@@ -166,7 +166,7 @@ function reorderItems(array: unknown[], from: number, to: number) {
const restCollectionDispatchers = defineDispatchers({ const restCollectionDispatchers = defineDispatchers({
setCollections( setCollections(
_: RESTCollectionStoreType, _: RESTCollectionStoreType,
{ entries }: { entries: HoppCollection<HoppRESTRequest>[] } { entries }: { entries: HoppCollection[] }
) { ) {
return { return {
state: entries, state: entries,
@@ -175,7 +175,7 @@ const restCollectionDispatchers = defineDispatchers({
appendCollections( appendCollections(
{ state }: RESTCollectionStoreType, { state }: RESTCollectionStoreType,
{ entries }: { entries: HoppCollection<HoppRESTRequest>[] } { entries }: { entries: HoppCollection[] }
) { ) {
return { return {
state: [...state, ...entries], state: [...state, ...entries],
@@ -184,7 +184,7 @@ const restCollectionDispatchers = defineDispatchers({
addCollection( addCollection(
{ state }: RESTCollectionStoreType, { state }: RESTCollectionStoreType,
{ collection }: { collection: HoppCollection<any> } { collection }: { collection: HoppCollection }
) { ) {
return { return {
state: [...state, collection], state: [...state, collection],
@@ -214,7 +214,7 @@ const restCollectionDispatchers = defineDispatchers({
partialCollection, partialCollection,
}: { }: {
collectionIndex: number collectionIndex: number
partialCollection: Partial<HoppCollection<any>> partialCollection: Partial<HoppCollection>
} }
) { ) {
return { return {
@@ -230,7 +230,7 @@ const restCollectionDispatchers = defineDispatchers({
{ state }: RESTCollectionStoreType, { state }: RESTCollectionStoreType,
{ name, path }: { name: string; path: string } { name, path }: { name: string; path: string }
) { ) {
const newFolder: HoppCollection<HoppRESTRequest> = makeCollection({ const newFolder: HoppCollection = makeCollection({
name, name,
folders: [], folders: [],
requests: [], requests: [],
@@ -265,7 +265,7 @@ const restCollectionDispatchers = defineDispatchers({
folder, folder,
}: { }: {
path: string path: string
folder: Partial<HoppCollection<HoppRESTRequest>> folder: Partial<HoppCollection>
} }
) { ) {
const newState = state const newState = state
@@ -356,7 +356,7 @@ const restCollectionDispatchers = defineDispatchers({
} }
const theFolder = containingFolder.folders.splice(folderIndex, 1) const theFolder = containingFolder.folders.splice(folderIndex, 1)
newState.push(theFolder[0] as HoppCollection<HoppRESTRequest>) newState.push(theFolder[0] as HoppCollection)
return { return {
state: newState, state: newState,
@@ -719,7 +719,7 @@ const restCollectionDispatchers = defineDispatchers({
type: "collection" | "request" type: "collection" | "request"
} }
) { ) {
const after = removeDuplicateCollectionsFromPath<HoppRESTRequest>( const after = removeDuplicateCollectionsFromPath(
id, id,
collectionPath, collectionPath,
state, state,
@@ -735,7 +735,7 @@ const restCollectionDispatchers = defineDispatchers({
const gqlCollectionDispatchers = defineDispatchers({ const gqlCollectionDispatchers = defineDispatchers({
setCollections( setCollections(
_: GraphqlCollectionStoreType, _: GraphqlCollectionStoreType,
{ entries }: { entries: HoppCollection<any>[] } { entries }: { entries: HoppCollection[] }
) { ) {
return { return {
state: entries, state: entries,
@@ -744,7 +744,7 @@ const gqlCollectionDispatchers = defineDispatchers({
appendCollections( appendCollections(
{ state }: GraphqlCollectionStoreType, { state }: GraphqlCollectionStoreType,
{ entries }: { entries: HoppCollection<any>[] } { entries }: { entries: HoppCollection[] }
) { ) {
return { return {
state: [...state, ...entries], state: [...state, ...entries],
@@ -753,7 +753,7 @@ const gqlCollectionDispatchers = defineDispatchers({
addCollection( addCollection(
{ state }: GraphqlCollectionStoreType, { state }: GraphqlCollectionStoreType,
{ collection }: { collection: HoppCollection<any> } { collection }: { collection: HoppCollection }
) { ) {
return { return {
state: [...state, collection], state: [...state, collection],
@@ -780,7 +780,7 @@ const gqlCollectionDispatchers = defineDispatchers({
{ {
collectionIndex, collectionIndex,
collection, collection,
}: { collectionIndex: number; collection: Partial<HoppCollection<any>> } }: { collectionIndex: number; collection: Partial<HoppCollection> }
) { ) {
return { return {
state: state.map((col, index) => state: state.map((col, index) =>
@@ -793,7 +793,7 @@ const gqlCollectionDispatchers = defineDispatchers({
{ state }: GraphqlCollectionStoreType, { state }: GraphqlCollectionStoreType,
{ name, path }: { name: string; path: string } { name, path }: { name: string; path: string }
) { ) {
const newFolder: HoppCollection<HoppGQLRequest> = makeCollection({ const newFolder: HoppCollection = makeCollection({
name, name,
folders: [], folders: [],
requests: [], requests: [],
@@ -822,10 +822,7 @@ const gqlCollectionDispatchers = defineDispatchers({
editFolder( editFolder(
{ state }: GraphqlCollectionStoreType, { state }: GraphqlCollectionStoreType,
{ { path, folder }: { path: string; folder: Partial<HoppCollection> }
path,
folder,
}: { path: string; folder: Partial<HoppCollection<HoppGQLRequest>> }
) { ) {
const newState = state const newState = state
@@ -1024,7 +1021,7 @@ const gqlCollectionDispatchers = defineDispatchers({
type: "collection" | "request" type: "collection" | "request"
} }
) { ) {
const after = removeDuplicateCollectionsFromPath<HoppGQLRequest>( const after = removeDuplicateCollectionsFromPath(
id, id,
collectionPath, collectionPath,
state, state,
@@ -1047,7 +1044,7 @@ export const graphqlCollectionStore = new DispatchingStore(
gqlCollectionDispatchers gqlCollectionDispatchers
) )
export function setRESTCollections(entries: HoppCollection<HoppRESTRequest>[]) { export function setRESTCollections(entries: HoppCollection[]) {
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "setCollections", dispatcher: "setCollections",
payload: { payload: {
@@ -1064,9 +1061,7 @@ export const graphqlCollections$ = graphqlCollectionStore.subject$.pipe(
pluck("state") pluck("state")
) )
export function appendRESTCollections( export function appendRESTCollections(entries: HoppCollection[]) {
entries: HoppCollection<HoppRESTRequest>[]
) {
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "appendCollections", dispatcher: "appendCollections",
payload: { payload: {
@@ -1075,7 +1070,7 @@ export function appendRESTCollections(
}) })
} }
export function addRESTCollection(collection: HoppCollection<HoppRESTRequest>) { export function addRESTCollection(collection: HoppCollection) {
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "addCollection", dispatcher: "addCollection",
payload: { payload: {
@@ -1103,7 +1098,7 @@ export function getRESTCollection(collectionIndex: number) {
export function editRESTCollection( export function editRESTCollection(
collectionIndex: number, collectionIndex: number,
partialCollection: Partial<HoppCollection<HoppRESTRequest>> partialCollection: Partial<HoppCollection>
) { ) {
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "editCollection", dispatcher: "editCollection",
@@ -1124,10 +1119,7 @@ export function addRESTFolder(name: string, path: string) {
}) })
} }
export function editRESTFolder( export function editRESTFolder(path: string, folder: Partial<HoppCollection>) {
path: string,
folder: Partial<HoppCollection<HoppRESTRequest>>
) {
restCollectionStore.dispatch({ restCollectionStore.dispatch({
dispatcher: "editFolder", dispatcher: "editFolder",
payload: { payload: {
@@ -1271,9 +1263,7 @@ export function updateRESTCollectionOrder(
}) })
} }
export function setGraphqlCollections( export function setGraphqlCollections(entries: HoppCollection[]) {
entries: HoppCollection<HoppGQLRequest>[]
) {
graphqlCollectionStore.dispatch({ graphqlCollectionStore.dispatch({
dispatcher: "setCollections", dispatcher: "setCollections",
payload: { payload: {
@@ -1282,9 +1272,7 @@ export function setGraphqlCollections(
}) })
} }
export function appendGraphqlCollections( export function appendGraphqlCollections(entries: HoppCollection[]) {
entries: HoppCollection<HoppGQLRequest>[]
) {
graphqlCollectionStore.dispatch({ graphqlCollectionStore.dispatch({
dispatcher: "appendCollections", dispatcher: "appendCollections",
payload: { payload: {
@@ -1293,9 +1281,7 @@ export function appendGraphqlCollections(
}) })
} }
export function addGraphqlCollection( export function addGraphqlCollection(collection: HoppCollection) {
collection: HoppCollection<HoppGQLRequest>
) {
graphqlCollectionStore.dispatch({ graphqlCollectionStore.dispatch({
dispatcher: "addCollection", dispatcher: "addCollection",
payload: { payload: {
@@ -1319,7 +1305,7 @@ export function removeGraphqlCollection(
export function editGraphqlCollection( export function editGraphqlCollection(
collectionIndex: number, collectionIndex: number,
collection: Partial<HoppCollection<HoppGQLRequest>> collection: Partial<HoppCollection>
) { ) {
graphqlCollectionStore.dispatch({ graphqlCollectionStore.dispatch({
dispatcher: "editCollection", dispatcher: "editCollection",
@@ -1342,7 +1328,7 @@ export function addGraphqlFolder(name: string, path: string) {
export function editGraphqlFolder( export function editGraphqlFolder(
path: string, path: string,
folder: Partial<HoppCollection<HoppGQLRequest>> folder: Partial<HoppCollection>
) { ) {
graphqlCollectionStore.dispatch({ graphqlCollectionStore.dispatch({
dispatcher: "editFolder", dispatcher: "editFolder",
@@ -1433,14 +1419,12 @@ export function moveGraphqlRequest(
}) })
} }
function removeDuplicateCollectionsFromPath< function removeDuplicateCollectionsFromPath(
T extends HoppRESTRequest | HoppGQLRequest,
>(
idToRemove: string, idToRemove: string,
collectionPath: string | null, collectionPath: string | null,
collections: HoppCollection<T>[], collections: HoppCollection[],
type: "collection" | "request" type: "collection" | "request"
): HoppCollection<T>[] { ): HoppCollection[] {
const indexes = collectionPath?.split("/").map((x) => parseInt(x)) const indexes = collectionPath?.split("/").map((x) => parseInt(x))
indexes && indexes.pop() indexes && indexes.pop()
const parentPath = indexes?.join("/") const parentPath = indexes?.join("/")

View File

@@ -12,7 +12,7 @@ import { onMounted } from "vue"
import { useRoute, useRouter } from "vue-router" import { useRoute, useRouter } from "vue-router"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { pipe } from "fp-ts/function" import { pipe } from "fp-ts/function"
import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data" import { HoppCollection } from "@hoppscotch/data"
import { appendRESTCollections } from "~/newstore/collections" import { appendRESTCollections } from "~/newstore/collections"
import { useI18n } from "@composables/i18n" import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast" import { useToast } from "@composables/toast"
@@ -110,9 +110,7 @@ const handleImportFailure = (error: ImportCollectionsError) => {
toast.error(t(IMPORT_ERROR_MAP[error]).toString()) toast.error(t(IMPORT_ERROR_MAP[error]).toString())
} }
const handleImportSuccess = ( const handleImportSuccess = (collections: HoppCollection[]) => {
collections: HoppCollection<HoppRESTRequest>[]
) => {
appendRESTCollections(collections) appendRESTCollections(collections)
toast.success(t("import.import_from_url_success").toString()) toast.success(t("import.import_from_url_success").toString())
} }

View File

@@ -1,9 +1,4 @@
import { import { Environment, HoppCollection } from "@hoppscotch/data"
Environment,
HoppCollection,
HoppGQLRequest,
HoppRESTRequest,
} from "@hoppscotch/data"
import { HoppGQLDocument } from "~/helpers/graphql/document" import { HoppGQLDocument } from "~/helpers/graphql/document"
import { HoppRESTDocument } from "~/helpers/rest/document" import { HoppRESTDocument } from "~/helpers/rest/document"
@@ -14,15 +9,15 @@ import { PersistableTabState } from "~/services/tab"
type VUEX_DATA = { type VUEX_DATA = {
postwoman: { postwoman: {
settings?: SettingsDef settings?: SettingsDef
collections?: HoppCollection<HoppRESTRequest>[] collections?: HoppCollection[]
collectionsGraphql?: HoppCollection<HoppGQLRequest>[] collectionsGraphql?: HoppCollection[]
environments?: Environment[] environments?: Environment[]
} }
} }
const DEFAULT_SETTINGS = getDefaultSettings() const DEFAULT_SETTINGS = getDefaultSettings()
export const REST_COLLECTIONS_MOCK: HoppCollection<HoppRESTRequest>[] = [ export const REST_COLLECTIONS_MOCK: HoppCollection[] = [
{ {
v: 1, v: 1,
name: "Echo", name: "Echo",
@@ -44,7 +39,7 @@ export const REST_COLLECTIONS_MOCK: HoppCollection<HoppRESTRequest>[] = [
}, },
] ]
export const GQL_COLLECTIONS_MOCK: HoppCollection<HoppGQLRequest>[] = [ export const GQL_COLLECTIONS_MOCK: HoppCollection[] = [
{ {
v: 1, v: 1,
name: "Echo", name: "Echo",

View File

@@ -101,7 +101,7 @@ type ExportedUserCollectionGQL = {
function exportedCollectionToHoppCollection( function exportedCollectionToHoppCollection(
collection: ExportedUserCollectionREST | ExportedUserCollectionGQL, collection: ExportedUserCollectionREST | ExportedUserCollectionGQL,
collectionType: "REST" | "GQL" collectionType: "REST" | "GQL"
): HoppCollection<HoppRESTRequest | HoppGQLRequest> { ): HoppCollection {
if (collectionType == "REST") { if (collectionType == "REST") {
const restCollection = collection as ExportedUserCollectionREST const restCollection = collection as ExportedUserCollectionREST
@@ -186,7 +186,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
exportedCollectionToHoppCollection( exportedCollectionToHoppCollection(
collection, collection,
"REST" "REST"
) as HoppCollection<HoppRESTRequest> ) as HoppCollection
) )
) )
: setGraphqlCollections( : setGraphqlCollections(
@@ -195,7 +195,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
exportedCollectionToHoppCollection( exportedCollectionToHoppCollection(
collection, collection,
"GQL" "GQL"
) as HoppCollection<HoppGQLRequest> ) as HoppCollection
) )
) )
}) })
@@ -718,7 +718,7 @@ export const def: CollectionsPlatformDef = {
function getCollectionPathFromCollectionID( function getCollectionPathFromCollectionID(
collectionID: string, collectionID: string,
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection[],
parentPath?: string parentPath?: string
): string | null { ): string | null {
for (const collectionIndex in collections) { for (const collectionIndex in collections) {
@@ -742,7 +742,7 @@ function getCollectionPathFromCollectionID(
function getRequestPathFromRequestID( function getRequestPathFromRequestID(
requestID: string, requestID: string,
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection[],
parentPath?: string parentPath?: string
): { collectionPath: string; requestIndex: number } | null { ): { collectionPath: string; requestIndex: number } | null {
for (const collectionIndex in collections) { for (const collectionIndex in collections) {
@@ -774,7 +774,7 @@ function getRequestPathFromRequestID(
function getRequestIndex( function getRequestIndex(
requestID: string, requestID: string,
parentCollectionPath: string, parentCollectionPath: string,
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[] collections: HoppCollection[]
) { ) {
const collection = navigateToFolderWithIndexPath( const collection = navigateToFolderWithIndexPath(
collections, collections,

View File

@@ -39,7 +39,7 @@ export const restRequestsMapper = createMapper<string, string>()
// temp implementation untill the backend implements an endpoint that accepts an entire collection // temp implementation untill the backend implements an endpoint that accepts an entire collection
// TODO: use importCollectionsJSON to do this // TODO: use importCollectionsJSON to do this
const recursivelySyncCollections = async ( const recursivelySyncCollections = async (
collection: HoppCollection<HoppRESTRequest>, collection: HoppCollection,
collectionPath: string, collectionPath: string,
parentUserCollectionID?: string parentUserCollectionID?: string
) => { ) => {

View File

@@ -36,7 +36,7 @@ export const gqlRequestsMapper = createMapper<string, string>()
// temp implementation untill the backend implements an endpoint that accepts an entire collection // temp implementation untill the backend implements an endpoint that accepts an entire collection
// TODO: use importCollectionsJSON to do this // TODO: use importCollectionsJSON to do this
const recursivelySyncCollections = async ( const recursivelySyncCollections = async (
collection: HoppCollection<HoppRESTRequest>, collection: HoppCollection,
collectionPath: string, collectionPath: string,
parentUserCollectionID?: string parentUserCollectionID?: string
) => { ) => {

View File

@@ -103,7 +103,7 @@ type ExportedUserCollectionGQL = {
function exportedCollectionToHoppCollection( function exportedCollectionToHoppCollection(
collection: ExportedUserCollectionREST | ExportedUserCollectionGQL, collection: ExportedUserCollectionREST | ExportedUserCollectionGQL,
collectionType: "REST" | "GQL" collectionType: "REST" | "GQL"
): HoppCollection<HoppRESTRequest | HoppGQLRequest> { ): HoppCollection {
if (collectionType == "REST") { if (collectionType == "REST") {
const restCollection = collection as ExportedUserCollectionREST const restCollection = collection as ExportedUserCollectionREST
const data = const data =
@@ -203,7 +203,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
exportedCollectionToHoppCollection( exportedCollectionToHoppCollection(
collection, collection,
"REST" "REST"
) as HoppCollection<HoppRESTRequest> ) as HoppCollection
) )
) )
: setGraphqlCollections( : setGraphqlCollections(
@@ -212,7 +212,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
exportedCollectionToHoppCollection( exportedCollectionToHoppCollection(
collection, collection,
"GQL" "GQL"
) as HoppCollection<HoppGQLRequest> ) as HoppCollection
) )
) )
}) })
@@ -748,7 +748,7 @@ export const def: CollectionsPlatformDef = {
function getCollectionPathFromCollectionID( function getCollectionPathFromCollectionID(
collectionID: string, collectionID: string,
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection[],
parentPath?: string parentPath?: string
): string | null { ): string | null {
for (const collectionIndex in collections) { for (const collectionIndex in collections) {
@@ -772,7 +772,7 @@ function getCollectionPathFromCollectionID(
function getRequestPathFromRequestID( function getRequestPathFromRequestID(
requestID: string, requestID: string,
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[], collections: HoppCollection[],
parentPath?: string parentPath?: string
): { collectionPath: string; requestIndex: number } | null { ): { collectionPath: string; requestIndex: number } | null {
for (const collectionIndex in collections) { for (const collectionIndex in collections) {
@@ -804,7 +804,7 @@ function getRequestPathFromRequestID(
function getRequestIndex( function getRequestIndex(
requestID: string, requestID: string,
parentCollectionPath: string, parentCollectionPath: string,
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[] collections: HoppCollection[]
) { ) {
const collection = navigateToFolderWithIndexPath( const collection = navigateToFolderWithIndexPath(
collections, collections,

View File

@@ -39,7 +39,7 @@ export const restRequestsMapper = createMapper<string, string>()
// temp implementation untill the backend implements an endpoint that accepts an entire collection // temp implementation untill the backend implements an endpoint that accepts an entire collection
// TODO: use importCollectionsJSON to do this // TODO: use importCollectionsJSON to do this
const recursivelySyncCollections = async ( const recursivelySyncCollections = async (
collection: HoppCollection<HoppRESTRequest>, collection: HoppCollection,
collectionPath: string, collectionPath: string,
parentUserCollectionID?: string parentUserCollectionID?: string
) => { ) => {

View File

@@ -36,7 +36,7 @@ export const gqlRequestsMapper = createMapper<string, string>()
// temp implementation untill the backend implements an endpoint that accepts an entire collection // temp implementation untill the backend implements an endpoint that accepts an entire collection
// TODO: use importCollectionsJSON to do this // TODO: use importCollectionsJSON to do this
const recursivelySyncCollections = async ( const recursivelySyncCollections = async (
collection: HoppCollection<HoppRESTRequest>, collection: HoppCollection,
collectionPath: string, collectionPath: string,
parentUserCollectionID?: string parentUserCollectionID?: string
) => { ) => {