refactor: update all hoppCollection type to remove generic pattern
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data";
|
||||
import { HoppCollection } from "@hoppscotch/data";
|
||||
import { HoppEnvs } from "./request";
|
||||
|
||||
export type CollectionRunnerParam = {
|
||||
collections: HoppCollection<HoppRESTRequest>[];
|
||||
collections: HoppCollection[];
|
||||
envs: HoppEnvs;
|
||||
delay?: number;
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ export type HoppEnvs = {
|
||||
|
||||
export type CollectionStack = {
|
||||
path: string;
|
||||
collection: HoppCollection<HoppRESTRequest>;
|
||||
collection: HoppCollection;
|
||||
};
|
||||
|
||||
export type RequestReport = {
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
HoppCollection,
|
||||
HoppRESTRequest,
|
||||
isHoppRESTRequest,
|
||||
} from "@hoppscotch/data";
|
||||
import { HoppCollection, isHoppRESTRequest } from "@hoppscotch/data";
|
||||
import * as A from "fp-ts/Array";
|
||||
import { CommanderError } from "commander";
|
||||
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;
|
||||
* False, otherwise.
|
||||
*/
|
||||
export const isRESTCollection = (
|
||||
param: unknown
|
||||
): param is HoppCollection<HoppRESTRequest> => {
|
||||
export const isRESTCollection = (param: unknown): param is HoppCollection => {
|
||||
if (!!param && typeof param === "object") {
|
||||
if (!hasProperty(param, "v") || typeof param.v !== "number") {
|
||||
return false;
|
||||
@@ -62,7 +56,6 @@ export const isRESTCollection = (
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Checks if given error data is of type HoppCLIError, based on existence
|
||||
* of code property.
|
||||
|
||||
@@ -3,7 +3,7 @@ import { pipe } from "fp-ts/function";
|
||||
import { bold } from "chalk";
|
||||
import { log } from "console";
|
||||
import round from "lodash/round";
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data";
|
||||
import { HoppCollection } from "@hoppscotch/data";
|
||||
import {
|
||||
HoppEnvs,
|
||||
CollectionStack,
|
||||
@@ -41,58 +41,58 @@ const { WARN, FAIL } = exceptionColors;
|
||||
* @param param Data of hopp-collection with hopp-requests, envs to be processed.
|
||||
* @returns List of report for each processed request.
|
||||
*/
|
||||
export const collectionsRunner =
|
||||
async (param: CollectionRunnerParam): Promise<RequestReport[]> =>
|
||||
{
|
||||
const envs: HoppEnvs = param.envs;
|
||||
const delay = param.delay ?? 0;
|
||||
const requestsReport: RequestReport[] = [];
|
||||
const collectionStack: CollectionStack[] = getCollectionStack(
|
||||
param.collections
|
||||
);
|
||||
export const collectionsRunner = async (
|
||||
param: CollectionRunnerParam
|
||||
): Promise<RequestReport[]> => {
|
||||
const envs: HoppEnvs = param.envs;
|
||||
const delay = param.delay ?? 0;
|
||||
const requestsReport: RequestReport[] = [];
|
||||
const collectionStack: CollectionStack[] = getCollectionStack(
|
||||
param.collections
|
||||
);
|
||||
|
||||
while (collectionStack.length) {
|
||||
// Pop out top-most collection from stack to be processed.
|
||||
const { collection, path } = <CollectionStack>collectionStack.pop();
|
||||
while (collectionStack.length) {
|
||||
// Pop out top-most collection from stack to be processed.
|
||||
const { collection, path } = <CollectionStack>collectionStack.pop();
|
||||
|
||||
// Processing each request in collection
|
||||
for (const request of collection.requests) {
|
||||
const _request = preProcessRequest(request);
|
||||
const requestPath = `${path}/${_request.name}`;
|
||||
const processRequestParams: ProcessRequestParams = {
|
||||
path: requestPath,
|
||||
request: _request,
|
||||
envs,
|
||||
delay,
|
||||
};
|
||||
// Processing each request in collection
|
||||
for (const request of collection.requests) {
|
||||
const _request = preProcessRequest(request);
|
||||
const requestPath = `${path}/${_request.name}`;
|
||||
const processRequestParams: ProcessRequestParams = {
|
||||
path: requestPath,
|
||||
request: _request,
|
||||
envs,
|
||||
delay,
|
||||
};
|
||||
|
||||
// Request processing initiated message.
|
||||
log(WARN(`\nRunning: ${bold(requestPath)}`));
|
||||
// Request processing initiated message.
|
||||
log(WARN(`\nRunning: ${bold(requestPath)}`));
|
||||
|
||||
// Processing current request.
|
||||
const result = await processRequest(processRequestParams)();
|
||||
// Processing current request.
|
||||
const result = await processRequest(processRequestParams)();
|
||||
|
||||
// Updating global & selected envs with new envs from processed-request output.
|
||||
const { global, selected } = result.envs;
|
||||
envs.global = global;
|
||||
envs.selected = selected;
|
||||
// Updating global & selected envs with new envs from processed-request output.
|
||||
const { global, selected } = result.envs;
|
||||
envs.global = global;
|
||||
envs.selected = selected;
|
||||
|
||||
// Storing current request's report.
|
||||
const requestReport = result.report;
|
||||
requestsReport.push(requestReport);
|
||||
}
|
||||
|
||||
// Pushing remaining folders realted collection to stack.
|
||||
for (const folder of collection.folders) {
|
||||
collectionStack.push({
|
||||
path: `${path}/${folder.name}`,
|
||||
collection: folder,
|
||||
});
|
||||
}
|
||||
// Storing current request's report.
|
||||
const requestReport = result.report;
|
||||
requestsReport.push(requestReport);
|
||||
}
|
||||
|
||||
return requestsReport;
|
||||
};
|
||||
// Pushing remaining folders realted collection to stack.
|
||||
for (const folder of collection.folders) {
|
||||
collectionStack.push({
|
||||
path: `${path}/${folder.name}`,
|
||||
collection: folder,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return requestsReport;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @returns Mapped collections to collection-stack.
|
||||
*/
|
||||
const getCollectionStack = (
|
||||
collections: HoppCollection<HoppRESTRequest>[]
|
||||
): CollectionStack[] =>
|
||||
const getCollectionStack = (collections: HoppCollection[]): CollectionStack[] =>
|
||||
pipe(
|
||||
collections,
|
||||
A.map(
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from "fs/promises";
|
||||
import { FormDataEntry } from "../types/request";
|
||||
import { error } from "../types/errors";
|
||||
import { isRESTCollection, isHoppErrnoException } from "./checks";
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data";
|
||||
import { HoppCollection } from "@hoppscotch/data";
|
||||
|
||||
/**
|
||||
* Parses array of FormDataEntry to FormData.
|
||||
@@ -35,20 +35,20 @@ export const parseErrorMessage = (e: unknown) => {
|
||||
};
|
||||
|
||||
export async function readJsonFile(path: string): Promise<unknown> {
|
||||
if(!path.endsWith('.json')) {
|
||||
throw error({ code: "INVALID_FILE_TYPE", data: path })
|
||||
if (!path.endsWith(".json")) {
|
||||
throw error({ code: "INVALID_FILE_TYPE", data: path });
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.access(path)
|
||||
await fs.access(path);
|
||||
} catch (e) {
|
||||
throw error({ code: "FILE_NOT_FOUND", path: path })
|
||||
throw error({ code: "FILE_NOT_FOUND", path: path });
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse((await fs.readFile(path)).toString())
|
||||
} catch(e) {
|
||||
throw error({ code: "UNKNOWN_ERROR", data: e })
|
||||
return JSON.parse((await fs.readFile(path)).toString());
|
||||
} catch (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
|
||||
* the parsed collectiona array.
|
||||
* @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(
|
||||
path: string
|
||||
): Promise<HoppCollection<HoppRESTRequest>[]> {
|
||||
let contents = await readJsonFile(path)
|
||||
): Promise<HoppCollection[]> {
|
||||
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({
|
||||
code: "MALFORMED_COLLECTION",
|
||||
path,
|
||||
data: "Please check the collection data.",
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return maybeArrayOfCollections as HoppCollection<HoppRESTRequest>[]
|
||||
};
|
||||
return maybeArrayOfCollections as HoppCollection[];
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { computed } from "vue"
|
||||
import { graphqlCollectionStore } from "~/newstore/collections"
|
||||
|
||||
@@ -28,7 +28,7 @@ const pathFolders = computed(() => {
|
||||
.slice(0, -1)
|
||||
.map((x) => parseInt(x))
|
||||
|
||||
const pathItems: HoppCollection<HoppGQLRequest>[] = []
|
||||
const pathItems: HoppCollection[] = []
|
||||
|
||||
let currentFolder =
|
||||
graphqlCollectionStore.value.state[folderIndicies.shift()!]
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { computed } from "vue"
|
||||
import { restCollectionStore } from "~/newstore/collections"
|
||||
import { getMethodLabelColorClassOf } from "~/helpers/rest/labelColoring"
|
||||
@@ -36,7 +36,7 @@ const pathFolders = computed(() => {
|
||||
.slice(0, -1)
|
||||
.map((x) => parseInt(x))
|
||||
|
||||
const pathItems: HoppCollection<HoppRESTRequest>[] = []
|
||||
const pathItems: HoppCollection[] = []
|
||||
|
||||
let currentFolder = restCollectionStore.value.state[folderIndicies.shift()!]
|
||||
pathItems.push(currentFolder)
|
||||
|
||||
@@ -208,7 +208,7 @@ import IconFolder from "~icons/lucide/folder"
|
||||
import IconFolderOpen from "~icons/lucide/folder-open"
|
||||
import IconSettings2 from "~icons/lucide/settings-2"
|
||||
import { ref, computed, watch } from "vue"
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { useI18n } from "@composables/i18n"
|
||||
import { TippyComponent } from "vue-tippy"
|
||||
import { TeamCollection } from "~/helpers/teams/TeamCollection"
|
||||
@@ -227,7 +227,7 @@ const props = withDefaults(
|
||||
defineProps<{
|
||||
id: string
|
||||
parentID?: string | null
|
||||
data: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
data: HoppCollection | TeamCollection
|
||||
/**
|
||||
* Collection component can be used for both collections and folders.
|
||||
* folderType is used to determine which one it is.
|
||||
@@ -310,8 +310,8 @@ const collectionIcon = computed(() => {
|
||||
})
|
||||
|
||||
const collectionName = computed(() => {
|
||||
if ((props.data as HoppCollection<HoppRESTRequest>).name)
|
||||
return (props.data as HoppCollection<HoppRESTRequest>).name
|
||||
if ((props.data as HoppCollection).name)
|
||||
return (props.data as HoppCollection).name
|
||||
return (props.data as TeamCollection).title
|
||||
})
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import { PropType, computed, ref } from "vue"
|
||||
import { useI18n } from "~/composables/i18n"
|
||||
import { useToast } from "~/composables/toast"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { appendRESTCollections, restCollections$ } from "~/newstore/collections"
|
||||
import MyCollectionImport from "~/components/importExport/ImportExportSteps/MyCollectionImport.vue"
|
||||
import { GetMyTeamsQuery } from "~/helpers/backend/graphql"
|
||||
@@ -88,9 +87,7 @@ const showImportFailedError = () => {
|
||||
toast.error(t("import.failed"))
|
||||
}
|
||||
|
||||
const handleImportToStore = async (
|
||||
collections: HoppCollection<HoppRESTRequest>[]
|
||||
) => {
|
||||
const handleImportToStore = async (collections: HoppCollection[]) => {
|
||||
const importResult =
|
||||
props.collectionsType.type === "my-collections"
|
||||
? await importToPersonalWorkspace(collections)
|
||||
@@ -104,18 +101,14 @@ const handleImportToStore = async (
|
||||
}
|
||||
}
|
||||
|
||||
const importToPersonalWorkspace = (
|
||||
collections: HoppCollection<HoppRESTRequest>[]
|
||||
) => {
|
||||
const importToPersonalWorkspace = (collections: HoppCollection[]) => {
|
||||
appendRESTCollections(collections)
|
||||
return E.right({
|
||||
success: true,
|
||||
})
|
||||
}
|
||||
|
||||
const importToTeamsWorkspace = async (
|
||||
collections: HoppCollection<HoppRESTRequest>[]
|
||||
) => {
|
||||
const importToTeamsWorkspace = async (collections: HoppCollection[]) => {
|
||||
if (!hasTeamWriteAccess.value || !selectedTeamID.value) {
|
||||
return E.left({
|
||||
success: false,
|
||||
|
||||
@@ -358,7 +358,7 @@ export type Collection = {
|
||||
isLastItem: boolean
|
||||
data: {
|
||||
parentIndex: null
|
||||
data: HoppCollection<HoppRESTRequest>
|
||||
data: HoppCollection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ type Folder = {
|
||||
isLastItem: boolean
|
||||
data: {
|
||||
parentIndex: string
|
||||
data: HoppCollection<HoppRESTRequest>
|
||||
data: HoppCollection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ type CollectionType =
|
||||
|
||||
const props = defineProps({
|
||||
filteredCollections: {
|
||||
type: Array as PropType<HoppCollection<HoppRESTRequest>[]>,
|
||||
type: Array as PropType<HoppCollection[]>,
|
||||
default: () => [],
|
||||
required: true,
|
||||
},
|
||||
@@ -426,35 +426,35 @@ const emit = defineEmits<{
|
||||
event: "add-request",
|
||||
payload: {
|
||||
path: string
|
||||
folder: HoppCollection<HoppRESTRequest>
|
||||
folder: HoppCollection
|
||||
}
|
||||
): void
|
||||
(
|
||||
event: "add-folder",
|
||||
payload: {
|
||||
path: string
|
||||
folder: HoppCollection<HoppRESTRequest>
|
||||
folder: HoppCollection
|
||||
}
|
||||
): void
|
||||
(
|
||||
event: "edit-collection",
|
||||
payload: {
|
||||
collectionIndex: string
|
||||
collection: HoppCollection<HoppRESTRequest>
|
||||
collection: HoppCollection
|
||||
}
|
||||
): void
|
||||
(
|
||||
event: "edit-folder",
|
||||
payload: {
|
||||
folderPath: string
|
||||
folder: HoppCollection<HoppRESTRequest>
|
||||
folder: HoppCollection
|
||||
}
|
||||
): void
|
||||
(
|
||||
event: "edit-properties",
|
||||
payload: {
|
||||
collectionIndex: string
|
||||
collection: HoppCollection<HoppRESTRequest>
|
||||
collection: HoppCollection
|
||||
}
|
||||
): void
|
||||
(
|
||||
@@ -472,7 +472,7 @@ const emit = defineEmits<{
|
||||
request: HoppRESTRequest
|
||||
}
|
||||
): void
|
||||
(event: "export-data", payload: HoppCollection<HoppRESTRequest>): void
|
||||
(event: "export-data", payload: HoppCollection): void
|
||||
(event: "remove-collection", payload: string): void
|
||||
(event: "remove-folder", payload: string): void
|
||||
(
|
||||
@@ -686,10 +686,10 @@ const updateCollectionOrder = (
|
||||
type MyCollectionNode = Collection | Folder | Requests
|
||||
|
||||
class MyCollectionsAdapter implements SmartTreeAdapter<MyCollectionNode> {
|
||||
constructor(public data: Ref<HoppCollection<HoppRESTRequest>[]>) {}
|
||||
constructor(public data: Ref<HoppCollection[]>) {}
|
||||
|
||||
navigateToFolderWithIndexPath(
|
||||
collections: HoppCollection<HoppRESTRequest>[],
|
||||
collections: HoppCollection[],
|
||||
indexPaths: number[]
|
||||
) {
|
||||
if (indexPaths.length === 0) return null
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
<script setup lang="ts">
|
||||
import { watch, ref } from "vue"
|
||||
import { useI18n } from "@composables/i18n"
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { RESTOptionTabs } from "../http/RequestOptions.vue"
|
||||
import { TeamCollection } from "~/helpers/teams/TeamCollection"
|
||||
import { clone } from "lodash-es"
|
||||
@@ -77,7 +77,7 @@ import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||
const t = useI18n()
|
||||
|
||||
type EditingProperties = {
|
||||
collection: HoppCollection<HoppRESTRequest> | TeamCollection | null
|
||||
collection: HoppCollection | TeamCollection | null
|
||||
isRootCollection: boolean
|
||||
path: string
|
||||
inheritedProperties: HoppInheritedProperty | undefined
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
import { ref } from "vue"
|
||||
import { useToast } from "@composables/toast"
|
||||
import { useI18n } from "@composables/i18n"
|
||||
import { HoppGQLRequest, makeCollection } from "@hoppscotch/data"
|
||||
import { makeCollection } from "@hoppscotch/data"
|
||||
import { addGraphqlCollection } from "~/newstore/collections"
|
||||
import { platform } from "~/platform"
|
||||
|
||||
@@ -60,7 +60,7 @@ const addNewCollection = () => {
|
||||
}
|
||||
|
||||
addGraphqlCollection(
|
||||
makeCollection<HoppGQLRequest>({
|
||||
makeCollection({
|
||||
name: name.value,
|
||||
folders: [],
|
||||
requests: [],
|
||||
|
||||
@@ -246,14 +246,14 @@ import { removeGraphqlCollection } from "~/newstore/collections"
|
||||
import { Picked } from "~/helpers/types/HoppPicked"
|
||||
import { useService } from "dioc/vue"
|
||||
import { GQLTabService } from "~/services/tab/graphql"
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
const props = defineProps<{
|
||||
picked: Picked | null
|
||||
// Whether the viewing context is related to picking (activates 'select' events)
|
||||
saveRequest: boolean
|
||||
collectionIndex: number | null
|
||||
collection: HoppCollection<HoppGQLRequest>
|
||||
collection: HoppCollection
|
||||
isFiltered: boolean
|
||||
}>()
|
||||
|
||||
@@ -275,7 +275,7 @@ const emit = defineEmits<{
|
||||
e: "edit-properties",
|
||||
payload: {
|
||||
collectionIndex: string | null
|
||||
collection: HoppCollection<HoppGQLRequest>
|
||||
collection: HoppCollection
|
||||
}
|
||||
): void
|
||||
(e: "edit-collection"): void
|
||||
|
||||
@@ -37,12 +37,12 @@ import { ref, watch } from "vue"
|
||||
import { editGraphqlCollection } from "~/newstore/collections"
|
||||
import { useToast } from "@composables/toast"
|
||||
import { useI18n } from "@composables/i18n"
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
const props = defineProps<{
|
||||
show: boolean
|
||||
editingCollectionIndex: number | null
|
||||
editingCollection: HoppCollection<HoppGQLRequest> | null
|
||||
editingCollection: HoppCollection | null
|
||||
editingCollectionName: string
|
||||
}>()
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ import { computed, ref } from "vue"
|
||||
import { useService } from "dioc/vue"
|
||||
import { GQLTabService } from "~/services/tab/graphql"
|
||||
import { Picked } from "~/helpers/types/HoppPicked"
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
const toast = useToast()
|
||||
const t = useI18n()
|
||||
@@ -242,7 +242,7 @@ const props = defineProps<{
|
||||
picked: Picked
|
||||
// Whether the request is in a selectable mode (activates 'select' event)
|
||||
saveRequest: boolean
|
||||
folder: HoppCollection<HoppGQLRequest>
|
||||
folder: HoppCollection
|
||||
folderIndex: number
|
||||
collectionIndex: number
|
||||
folderPath: string
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from "~/composables/i18n"
|
||||
import { useToast } from "~/composables/toast"
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { ImporterOrExporter } from "~/components/importExport/types"
|
||||
import { FileSource } from "~/helpers/import-export/import/import-sources/FileSource"
|
||||
import { GistSource } from "~/helpers/import-export/import/import-sources/GistSource"
|
||||
@@ -214,9 +214,7 @@ const showImportFailedError = () => {
|
||||
toast.error(t("import.failed"))
|
||||
}
|
||||
|
||||
const handleImportToStore = async (
|
||||
gqlCollections: HoppCollection<HoppGQLRequest>[]
|
||||
) => {
|
||||
const handleImportToStore = async (gqlCollections: HoppCollection[]) => {
|
||||
setGraphqlCollections(gqlCollections)
|
||||
toast.success(t("import.success"))
|
||||
}
|
||||
|
||||
@@ -209,9 +209,9 @@ const showModalEditFolder = ref(false)
|
||||
const showModalEditRequest = 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 editingFolder = ref<HoppCollection<HoppGQLRequest> | null>(null)
|
||||
const editingFolder = ref<HoppCollection | null>(null)
|
||||
const editingFolderName = ref("")
|
||||
const editingFolderIndex = ref<number | null>(null)
|
||||
const editingFolderPath = ref("")
|
||||
@@ -219,7 +219,7 @@ const editingRequest = ref<HoppGQLRequest | null>(null)
|
||||
const editingRequestIndex = ref<number | null>(null)
|
||||
|
||||
const editingProperties = ref<{
|
||||
collection: HoppCollection<HoppGQLRequest> | null
|
||||
collection: HoppCollection | null
|
||||
isRootCollection: boolean
|
||||
path: string
|
||||
inheritedProperties?: HoppInheritedProperty
|
||||
@@ -318,7 +318,7 @@ const displayModalEditProperties = (show: boolean) => {
|
||||
}
|
||||
|
||||
const editCollection = (
|
||||
collection: HoppCollection<HoppGQLRequest>,
|
||||
collection: HoppCollection,
|
||||
collectionIndex: number
|
||||
) => {
|
||||
editingCollection.value = collection
|
||||
@@ -404,7 +404,7 @@ const addFolder = (payload: { path: string }) => {
|
||||
}
|
||||
|
||||
const editFolder = (payload: {
|
||||
folder: HoppCollection<HoppGQLRequest>
|
||||
folder: HoppCollection
|
||||
folderPath: string
|
||||
}) => {
|
||||
const { folder, folderPath } = payload
|
||||
@@ -553,7 +553,7 @@ const editProperties = ({
|
||||
collection,
|
||||
}: {
|
||||
collectionIndex: string | null
|
||||
collection: HoppCollection<HoppGQLRequest> | null
|
||||
collection: HoppCollection | null
|
||||
}) => {
|
||||
if (collectionIndex === null || collection === null) return
|
||||
|
||||
@@ -583,7 +583,7 @@ const editProperties = ({
|
||||
}
|
||||
|
||||
const setCollectionProperties = (newCollection: {
|
||||
collection: HoppCollection<HoppGQLRequest>
|
||||
collection: HoppCollection
|
||||
path: string
|
||||
isRootCollection: boolean
|
||||
}) => {
|
||||
|
||||
@@ -277,15 +277,11 @@ const collectionsType = ref<CollectionType>({
|
||||
})
|
||||
|
||||
// Collection Data
|
||||
const editingCollection = ref<
|
||||
HoppCollection<HoppRESTRequest> | TeamCollection | null
|
||||
>(null)
|
||||
const editingCollection = ref<HoppCollection | TeamCollection | null>(null)
|
||||
const editingCollectionName = ref<string | null>(null)
|
||||
const editingCollectionIndex = ref<number | null>(null)
|
||||
const editingCollectionID = ref<string | null>(null)
|
||||
const editingFolder = ref<
|
||||
HoppCollection<HoppRESTRequest> | TeamCollection | null
|
||||
>(null)
|
||||
const editingFolder = ref<HoppCollection | TeamCollection | null>(null)
|
||||
const editingFolderName = ref<string | null>(null)
|
||||
const editingFolderPath = ref<string | 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 editingProperties = ref<{
|
||||
collection: HoppCollection<HoppRESTRequest> | TeamCollection | null
|
||||
collection: HoppCollection | TeamCollection | null
|
||||
isRootCollection: boolean
|
||||
path: string
|
||||
inheritedProperties?: HoppInheritedProperty
|
||||
@@ -660,7 +656,7 @@ const addNewRootCollection = (name: string) => {
|
||||
|
||||
const addRequest = (payload: {
|
||||
path: string
|
||||
folder: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
folder: HoppCollection | TeamCollection
|
||||
}) => {
|
||||
const { path, folder } = payload
|
||||
editingFolder.value = folder
|
||||
@@ -760,7 +756,7 @@ const onAddRequest = (requestName: string) => {
|
||||
|
||||
const addFolder = (payload: {
|
||||
path: string
|
||||
folder: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
folder: HoppCollection | TeamCollection
|
||||
}) => {
|
||||
const { path, folder } = payload
|
||||
editingFolder.value = folder
|
||||
@@ -819,15 +815,13 @@ const onAddFolder = (folderName: string) => {
|
||||
|
||||
const editCollection = (payload: {
|
||||
collectionIndex: string
|
||||
collection: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
collection: HoppCollection | TeamCollection
|
||||
}) => {
|
||||
const { collectionIndex, collection } = payload
|
||||
editingCollection.value = collection
|
||||
if (collectionsType.value.type === "my-collections") {
|
||||
editingCollectionIndex.value = parseInt(collectionIndex)
|
||||
editingCollectionName.value = (
|
||||
collection as HoppCollection<HoppRESTRequest>
|
||||
).name
|
||||
editingCollectionName.value = (collection as HoppCollection).name
|
||||
} else {
|
||||
editingCollectionName.value = (collection as TeamCollection).title
|
||||
}
|
||||
@@ -880,13 +874,13 @@ const updateEditingCollection = (newName: string) => {
|
||||
|
||||
const editFolder = (payload: {
|
||||
folderPath: string | undefined
|
||||
folder: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
folder: HoppCollection | TeamCollection
|
||||
}) => {
|
||||
const { folderPath, folder } = payload
|
||||
editingFolder.value = folder
|
||||
if (collectionsType.value.type === "my-collections" && folderPath) {
|
||||
editingFolderPath.value = folderPath
|
||||
editingFolderName.value = (folder as HoppCollection<HoppRESTRequest>).name
|
||||
editingFolderName.value = (folder as HoppCollection).name
|
||||
} else {
|
||||
editingFolderName.value = (folder as TeamCollection).title
|
||||
}
|
||||
@@ -900,7 +894,7 @@ const updateEditingFolder = (newName: string) => {
|
||||
if (!editingFolderPath.value) return
|
||||
|
||||
editRESTFolder(editingFolderPath.value, {
|
||||
...(editingFolder.value as HoppCollection<HoppRESTRequest>),
|
||||
...(editingFolder.value as HoppCollection),
|
||||
name: newName,
|
||||
})
|
||||
displayModalEditFolder(false)
|
||||
@@ -1958,13 +1952,11 @@ const initializeDownloadCollection = async (
|
||||
* Triggered by the export button in the tippy menu
|
||||
* @param collection - Collection or folder to be exported
|
||||
*/
|
||||
const exportData = async (
|
||||
collection: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
) => {
|
||||
const exportData = async (collection: HoppCollection | TeamCollection) => {
|
||||
if (collectionsType.value.type === "my-collections") {
|
||||
const collectionJSON = JSON.stringify(collection)
|
||||
|
||||
const name = (collection as HoppCollection<HoppRESTRequest>).name
|
||||
const name = (collection as HoppCollection).name
|
||||
|
||||
initializeDownloadCollection(collectionJSON, name)
|
||||
} else {
|
||||
@@ -2007,7 +1999,7 @@ const shareRequest = ({ request }: { request: HoppRESTRequest }) => {
|
||||
|
||||
const editProperties = (payload: {
|
||||
collectionIndex: string
|
||||
collection: HoppCollection<HoppRESTRequest> | TeamCollection
|
||||
collection: HoppCollection | TeamCollection
|
||||
}) => {
|
||||
const { collection, collectionIndex } = payload
|
||||
|
||||
@@ -2096,7 +2088,7 @@ const editProperties = (payload: {
|
||||
}
|
||||
|
||||
const setCollectionProperties = (newCollection: {
|
||||
collection: HoppCollection<HoppRESTRequest>
|
||||
collection: HoppCollection
|
||||
path: string
|
||||
isRootCollection: boolean
|
||||
}) => {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { computed, ref } from "vue"
|
||||
import { useI18n } from "~/composables/i18n"
|
||||
import { useReadonlyStream } from "~/composables/stream"
|
||||
@@ -48,7 +48,7 @@ const hasSelectedCollectionID = computed(() => {
|
||||
const myCollections = useReadonlyStream(restCollections$, [])
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "importFromMyCollection", content: HoppCollection<HoppRESTRequest>): void
|
||||
(e: "importFromMyCollection", content: HoppCollection): void
|
||||
}>()
|
||||
|
||||
const fetchCollectionFromMyCollections = async () => {
|
||||
|
||||
@@ -4,7 +4,6 @@ import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe, flow } from "fp-ts/function"
|
||||
import {
|
||||
HoppCollection,
|
||||
HoppRESTRequest,
|
||||
makeCollection,
|
||||
translateToNewRequest,
|
||||
} from "@hoppscotch/data"
|
||||
@@ -118,9 +117,7 @@ export const getCompleteCollectionTree = (
|
||||
)
|
||||
)
|
||||
|
||||
export const teamCollToHoppRESTColl = (
|
||||
coll: TeamCollection
|
||||
): HoppCollection<HoppRESTRequest> =>
|
||||
export const teamCollToHoppRESTColl = (coll: TeamCollection): HoppCollection =>
|
||||
makeCollection({
|
||||
name: coll.title,
|
||||
folders: coll.children?.map(teamCollToHoppRESTColl) ?? [],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { getAffectedIndexes } from "./affectedIndex"
|
||||
import { GetSingleRequestDocument } from "../backend/graphql"
|
||||
import { runGQLQuery } from "../backend/GQLClient"
|
||||
@@ -225,9 +225,9 @@ export async function resetTeamRequestsContext() {
|
||||
}
|
||||
|
||||
export function getFoldersByPath(
|
||||
collections: HoppCollection<HoppRESTRequest>[],
|
||||
collections: HoppCollection[],
|
||||
path: string
|
||||
): HoppCollection<HoppRESTRequest>[] {
|
||||
): HoppCollection[] {
|
||||
if (!path) return collections
|
||||
|
||||
// path will be like this "0/0/1" these are the indexes of the folders
|
||||
|
||||
@@ -57,7 +57,7 @@ export function resolveSaveContextOnRequestReorder(payload: {
|
||||
}
|
||||
|
||||
export function getRequestsByPath(
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
|
||||
collections: HoppCollection[],
|
||||
path: string
|
||||
): HoppRESTRequest[] | HoppGQLRequest[] {
|
||||
// path will be like this "0/0/1" these are the indexes of the folders
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
export const gqlCollectionsExporter = (
|
||||
gqlCollections: HoppCollection<HoppGQLRequest>[]
|
||||
) => {
|
||||
export const gqlCollectionsExporter = (gqlCollections: HoppCollection[]) => {
|
||||
return JSON.stringify(gqlCollections, null, 2)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
export const myCollectionsExporter = (
|
||||
myCollections: HoppCollection<HoppRESTRequest>[]
|
||||
) => {
|
||||
export const myCollectionsExporter = (myCollections: HoppCollection[]) => {
|
||||
return JSON.stringify(myCollections, null, 2)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { HoppCollection, HoppGQLRequest } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import * as E from "fp-ts/Either"
|
||||
|
||||
// TODO: add zod validation
|
||||
export const hoppGqlCollectionsImporter = (
|
||||
content: string
|
||||
): E.Either<"INVALID_JSON", HoppCollection<HoppGQLRequest>[]> => {
|
||||
): E.Either<"INVALID_JSON", HoppCollection[]> => {
|
||||
return E.tryCatch(
|
||||
() => JSON.parse(content) as HoppCollection<HoppGQLRequest>[],
|
||||
() => JSON.parse(content) as HoppCollection[],
|
||||
() => "INVALID_JSON"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ const getHoppRequest = (req: InsomniaRequestResource): HoppRESTRequest =>
|
||||
const getHoppFolder = (
|
||||
folderRes: InsomniaFolderResource,
|
||||
resources: InsomniaResource[]
|
||||
): HoppCollection<HoppRESTRequest> =>
|
||||
): HoppCollection =>
|
||||
makeCollection({
|
||||
name: folderRes.name ?? "",
|
||||
folders: getFoldersIn(folderRes, resources).map((f) =>
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
HoppRESTHeader,
|
||||
HoppRESTParam,
|
||||
HoppRESTReqBody,
|
||||
HoppRESTRequest,
|
||||
knownContentTypes,
|
||||
makeRESTRequest,
|
||||
HoppCollection,
|
||||
@@ -581,7 +580,7 @@ const convertPathToHoppReqs = (
|
||||
|
||||
const convertOpenApiDocToHopp = (
|
||||
doc: OpenAPI.Document
|
||||
): TE.TaskEither<never, HoppCollection<HoppRESTRequest>[]> => {
|
||||
): TE.TaskEither<never, HoppCollection[]> => {
|
||||
const name = doc.info.title
|
||||
|
||||
const paths = Object.entries(doc.paths ?? {})
|
||||
@@ -589,7 +588,7 @@ const convertOpenApiDocToHopp = (
|
||||
.flat()
|
||||
|
||||
return TE.of([
|
||||
makeCollection<HoppRESTRequest>({
|
||||
makeCollection({
|
||||
name,
|
||||
folders: [],
|
||||
requests: paths,
|
||||
|
||||
@@ -283,7 +283,7 @@ const getHoppRequest = (item: Item): HoppRESTRequest => {
|
||||
})
|
||||
}
|
||||
|
||||
const getHoppFolder = (ig: ItemGroup<Item>): HoppCollection<HoppRESTRequest> =>
|
||||
const getHoppFolder = (ig: ItemGroup<Item>): HoppCollection =>
|
||||
makeCollection({
|
||||
name: ig.name,
|
||||
folders: pipe(
|
||||
|
||||
@@ -1074,8 +1074,7 @@ export default class NewTeamCollectionAdapter {
|
||||
const parentFolderAuth = data.auth
|
||||
const parentFolderHeaders = data.headers
|
||||
|
||||
const isRootCollection = path.length === 1
|
||||
if (parentFolderAuth?.authType === "inherit" && isRootCollection) {
|
||||
if (parentFolderAuth?.authType === "inherit") {
|
||||
auth = {
|
||||
parentID: parentFolder.id ?? folderPath,
|
||||
parentName: parentFolder.title,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"
|
||||
|
||||
const defaultRESTCollectionState = {
|
||||
state: [
|
||||
makeCollection<HoppRESTRequest>({
|
||||
makeCollection({
|
||||
name: "My Collection",
|
||||
folders: [],
|
||||
requests: [],
|
||||
@@ -29,7 +29,7 @@ const defaultRESTCollectionState = {
|
||||
|
||||
const defaultGraphqlCollectionState = {
|
||||
state: [
|
||||
makeCollection<HoppGQLRequest>({
|
||||
makeCollection({
|
||||
name: "My GraphQL Collection",
|
||||
folders: [],
|
||||
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.
|
||||
*/
|
||||
export function navigateToFolderWithIndexPath(
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
|
||||
collections: HoppCollection[],
|
||||
indexPaths: number[]
|
||||
) {
|
||||
if (indexPaths.length === 0) return null
|
||||
@@ -79,7 +79,9 @@ export function cascadeParentCollectionForHeaderAuth(
|
||||
},
|
||||
}
|
||||
const headers: HoppInheritedProperty["headers"] = []
|
||||
|
||||
if (!folderPath) return { auth, headers }
|
||||
|
||||
const path = folderPath.split("/").map((i) => parseInt(i))
|
||||
|
||||
// Check if the path is empty or invalid
|
||||
@@ -104,9 +106,7 @@ export function cascadeParentCollectionForHeaderAuth(
|
||||
const parentFolderAuth = parentFolder.auth
|
||||
const parentFolderHeaders = parentFolder.headers
|
||||
|
||||
const isRootCollection = path.length === 1
|
||||
|
||||
if (parentFolderAuth?.authType === "inherit" && isRootCollection) {
|
||||
if (parentFolderAuth?.authType === "inherit") {
|
||||
auth = {
|
||||
parentID: folderPath,
|
||||
parentName: parentFolder.name,
|
||||
@@ -166,7 +166,7 @@ function reorderItems(array: unknown[], from: number, to: number) {
|
||||
const restCollectionDispatchers = defineDispatchers({
|
||||
setCollections(
|
||||
_: RESTCollectionStoreType,
|
||||
{ entries }: { entries: HoppCollection<HoppRESTRequest>[] }
|
||||
{ entries }: { entries: HoppCollection[] }
|
||||
) {
|
||||
return {
|
||||
state: entries,
|
||||
@@ -175,7 +175,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
|
||||
appendCollections(
|
||||
{ state }: RESTCollectionStoreType,
|
||||
{ entries }: { entries: HoppCollection<HoppRESTRequest>[] }
|
||||
{ entries }: { entries: HoppCollection[] }
|
||||
) {
|
||||
return {
|
||||
state: [...state, ...entries],
|
||||
@@ -184,7 +184,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
|
||||
addCollection(
|
||||
{ state }: RESTCollectionStoreType,
|
||||
{ collection }: { collection: HoppCollection<any> }
|
||||
{ collection }: { collection: HoppCollection }
|
||||
) {
|
||||
return {
|
||||
state: [...state, collection],
|
||||
@@ -214,7 +214,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
partialCollection,
|
||||
}: {
|
||||
collectionIndex: number
|
||||
partialCollection: Partial<HoppCollection<any>>
|
||||
partialCollection: Partial<HoppCollection>
|
||||
}
|
||||
) {
|
||||
return {
|
||||
@@ -230,7 +230,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
{ state }: RESTCollectionStoreType,
|
||||
{ name, path }: { name: string; path: string }
|
||||
) {
|
||||
const newFolder: HoppCollection<HoppRESTRequest> = makeCollection({
|
||||
const newFolder: HoppCollection = makeCollection({
|
||||
name,
|
||||
folders: [],
|
||||
requests: [],
|
||||
@@ -265,7 +265,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
folder,
|
||||
}: {
|
||||
path: string
|
||||
folder: Partial<HoppCollection<HoppRESTRequest>>
|
||||
folder: Partial<HoppCollection>
|
||||
}
|
||||
) {
|
||||
const newState = state
|
||||
@@ -356,7 +356,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
}
|
||||
|
||||
const theFolder = containingFolder.folders.splice(folderIndex, 1)
|
||||
newState.push(theFolder[0] as HoppCollection<HoppRESTRequest>)
|
||||
newState.push(theFolder[0] as HoppCollection)
|
||||
|
||||
return {
|
||||
state: newState,
|
||||
@@ -719,7 +719,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
type: "collection" | "request"
|
||||
}
|
||||
) {
|
||||
const after = removeDuplicateCollectionsFromPath<HoppRESTRequest>(
|
||||
const after = removeDuplicateCollectionsFromPath(
|
||||
id,
|
||||
collectionPath,
|
||||
state,
|
||||
@@ -735,7 +735,7 @@ const restCollectionDispatchers = defineDispatchers({
|
||||
const gqlCollectionDispatchers = defineDispatchers({
|
||||
setCollections(
|
||||
_: GraphqlCollectionStoreType,
|
||||
{ entries }: { entries: HoppCollection<any>[] }
|
||||
{ entries }: { entries: HoppCollection[] }
|
||||
) {
|
||||
return {
|
||||
state: entries,
|
||||
@@ -744,7 +744,7 @@ const gqlCollectionDispatchers = defineDispatchers({
|
||||
|
||||
appendCollections(
|
||||
{ state }: GraphqlCollectionStoreType,
|
||||
{ entries }: { entries: HoppCollection<any>[] }
|
||||
{ entries }: { entries: HoppCollection[] }
|
||||
) {
|
||||
return {
|
||||
state: [...state, ...entries],
|
||||
@@ -753,7 +753,7 @@ const gqlCollectionDispatchers = defineDispatchers({
|
||||
|
||||
addCollection(
|
||||
{ state }: GraphqlCollectionStoreType,
|
||||
{ collection }: { collection: HoppCollection<any> }
|
||||
{ collection }: { collection: HoppCollection }
|
||||
) {
|
||||
return {
|
||||
state: [...state, collection],
|
||||
@@ -780,7 +780,7 @@ const gqlCollectionDispatchers = defineDispatchers({
|
||||
{
|
||||
collectionIndex,
|
||||
collection,
|
||||
}: { collectionIndex: number; collection: Partial<HoppCollection<any>> }
|
||||
}: { collectionIndex: number; collection: Partial<HoppCollection> }
|
||||
) {
|
||||
return {
|
||||
state: state.map((col, index) =>
|
||||
@@ -793,7 +793,7 @@ const gqlCollectionDispatchers = defineDispatchers({
|
||||
{ state }: GraphqlCollectionStoreType,
|
||||
{ name, path }: { name: string; path: string }
|
||||
) {
|
||||
const newFolder: HoppCollection<HoppGQLRequest> = makeCollection({
|
||||
const newFolder: HoppCollection = makeCollection({
|
||||
name,
|
||||
folders: [],
|
||||
requests: [],
|
||||
@@ -822,10 +822,7 @@ const gqlCollectionDispatchers = defineDispatchers({
|
||||
|
||||
editFolder(
|
||||
{ state }: GraphqlCollectionStoreType,
|
||||
{
|
||||
path,
|
||||
folder,
|
||||
}: { path: string; folder: Partial<HoppCollection<HoppGQLRequest>> }
|
||||
{ path, folder }: { path: string; folder: Partial<HoppCollection> }
|
||||
) {
|
||||
const newState = state
|
||||
|
||||
@@ -1024,7 +1021,7 @@ const gqlCollectionDispatchers = defineDispatchers({
|
||||
type: "collection" | "request"
|
||||
}
|
||||
) {
|
||||
const after = removeDuplicateCollectionsFromPath<HoppGQLRequest>(
|
||||
const after = removeDuplicateCollectionsFromPath(
|
||||
id,
|
||||
collectionPath,
|
||||
state,
|
||||
@@ -1047,7 +1044,7 @@ export const graphqlCollectionStore = new DispatchingStore(
|
||||
gqlCollectionDispatchers
|
||||
)
|
||||
|
||||
export function setRESTCollections(entries: HoppCollection<HoppRESTRequest>[]) {
|
||||
export function setRESTCollections(entries: HoppCollection[]) {
|
||||
restCollectionStore.dispatch({
|
||||
dispatcher: "setCollections",
|
||||
payload: {
|
||||
@@ -1064,9 +1061,7 @@ export const graphqlCollections$ = graphqlCollectionStore.subject$.pipe(
|
||||
pluck("state")
|
||||
)
|
||||
|
||||
export function appendRESTCollections(
|
||||
entries: HoppCollection<HoppRESTRequest>[]
|
||||
) {
|
||||
export function appendRESTCollections(entries: HoppCollection[]) {
|
||||
restCollectionStore.dispatch({
|
||||
dispatcher: "appendCollections",
|
||||
payload: {
|
||||
@@ -1075,7 +1070,7 @@ export function appendRESTCollections(
|
||||
})
|
||||
}
|
||||
|
||||
export function addRESTCollection(collection: HoppCollection<HoppRESTRequest>) {
|
||||
export function addRESTCollection(collection: HoppCollection) {
|
||||
restCollectionStore.dispatch({
|
||||
dispatcher: "addCollection",
|
||||
payload: {
|
||||
@@ -1103,7 +1098,7 @@ export function getRESTCollection(collectionIndex: number) {
|
||||
|
||||
export function editRESTCollection(
|
||||
collectionIndex: number,
|
||||
partialCollection: Partial<HoppCollection<HoppRESTRequest>>
|
||||
partialCollection: Partial<HoppCollection>
|
||||
) {
|
||||
restCollectionStore.dispatch({
|
||||
dispatcher: "editCollection",
|
||||
@@ -1124,10 +1119,7 @@ export function addRESTFolder(name: string, path: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export function editRESTFolder(
|
||||
path: string,
|
||||
folder: Partial<HoppCollection<HoppRESTRequest>>
|
||||
) {
|
||||
export function editRESTFolder(path: string, folder: Partial<HoppCollection>) {
|
||||
restCollectionStore.dispatch({
|
||||
dispatcher: "editFolder",
|
||||
payload: {
|
||||
@@ -1271,9 +1263,7 @@ export function updateRESTCollectionOrder(
|
||||
})
|
||||
}
|
||||
|
||||
export function setGraphqlCollections(
|
||||
entries: HoppCollection<HoppGQLRequest>[]
|
||||
) {
|
||||
export function setGraphqlCollections(entries: HoppCollection[]) {
|
||||
graphqlCollectionStore.dispatch({
|
||||
dispatcher: "setCollections",
|
||||
payload: {
|
||||
@@ -1282,9 +1272,7 @@ export function setGraphqlCollections(
|
||||
})
|
||||
}
|
||||
|
||||
export function appendGraphqlCollections(
|
||||
entries: HoppCollection<HoppGQLRequest>[]
|
||||
) {
|
||||
export function appendGraphqlCollections(entries: HoppCollection[]) {
|
||||
graphqlCollectionStore.dispatch({
|
||||
dispatcher: "appendCollections",
|
||||
payload: {
|
||||
@@ -1293,9 +1281,7 @@ export function appendGraphqlCollections(
|
||||
})
|
||||
}
|
||||
|
||||
export function addGraphqlCollection(
|
||||
collection: HoppCollection<HoppGQLRequest>
|
||||
) {
|
||||
export function addGraphqlCollection(collection: HoppCollection) {
|
||||
graphqlCollectionStore.dispatch({
|
||||
dispatcher: "addCollection",
|
||||
payload: {
|
||||
@@ -1319,7 +1305,7 @@ export function removeGraphqlCollection(
|
||||
|
||||
export function editGraphqlCollection(
|
||||
collectionIndex: number,
|
||||
collection: Partial<HoppCollection<HoppGQLRequest>>
|
||||
collection: Partial<HoppCollection>
|
||||
) {
|
||||
graphqlCollectionStore.dispatch({
|
||||
dispatcher: "editCollection",
|
||||
@@ -1342,7 +1328,7 @@ export function addGraphqlFolder(name: string, path: string) {
|
||||
|
||||
export function editGraphqlFolder(
|
||||
path: string,
|
||||
folder: Partial<HoppCollection<HoppGQLRequest>>
|
||||
folder: Partial<HoppCollection>
|
||||
) {
|
||||
graphqlCollectionStore.dispatch({
|
||||
dispatcher: "editFolder",
|
||||
@@ -1433,14 +1419,12 @@ export function moveGraphqlRequest(
|
||||
})
|
||||
}
|
||||
|
||||
function removeDuplicateCollectionsFromPath<
|
||||
T extends HoppRESTRequest | HoppGQLRequest,
|
||||
>(
|
||||
function removeDuplicateCollectionsFromPath(
|
||||
idToRemove: string,
|
||||
collectionPath: string | null,
|
||||
collections: HoppCollection<T>[],
|
||||
collections: HoppCollection[],
|
||||
type: "collection" | "request"
|
||||
): HoppCollection<T>[] {
|
||||
): HoppCollection[] {
|
||||
const indexes = collectionPath?.split("/").map((x) => parseInt(x))
|
||||
indexes && indexes.pop()
|
||||
const parentPath = indexes?.join("/")
|
||||
|
||||
@@ -12,7 +12,7 @@ import { onMounted } from "vue"
|
||||
import { useRoute, useRouter } from "vue-router"
|
||||
import * as E from "fp-ts/Either"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { HoppRESTRequest, HoppCollection } from "@hoppscotch/data"
|
||||
import { HoppCollection } from "@hoppscotch/data"
|
||||
import { appendRESTCollections } from "~/newstore/collections"
|
||||
import { useI18n } from "@composables/i18n"
|
||||
import { useToast } from "@composables/toast"
|
||||
@@ -110,9 +110,7 @@ const handleImportFailure = (error: ImportCollectionsError) => {
|
||||
toast.error(t(IMPORT_ERROR_MAP[error]).toString())
|
||||
}
|
||||
|
||||
const handleImportSuccess = (
|
||||
collections: HoppCollection<HoppRESTRequest>[]
|
||||
) => {
|
||||
const handleImportSuccess = (collections: HoppCollection[]) => {
|
||||
appendRESTCollections(collections)
|
||||
toast.success(t("import.import_from_url_success").toString())
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
Environment,
|
||||
HoppCollection,
|
||||
HoppGQLRequest,
|
||||
HoppRESTRequest,
|
||||
} from "@hoppscotch/data"
|
||||
import { Environment, HoppCollection } from "@hoppscotch/data"
|
||||
|
||||
import { HoppGQLDocument } from "~/helpers/graphql/document"
|
||||
import { HoppRESTDocument } from "~/helpers/rest/document"
|
||||
@@ -14,15 +9,15 @@ import { PersistableTabState } from "~/services/tab"
|
||||
type VUEX_DATA = {
|
||||
postwoman: {
|
||||
settings?: SettingsDef
|
||||
collections?: HoppCollection<HoppRESTRequest>[]
|
||||
collectionsGraphql?: HoppCollection<HoppGQLRequest>[]
|
||||
collections?: HoppCollection[]
|
||||
collectionsGraphql?: HoppCollection[]
|
||||
environments?: Environment[]
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS = getDefaultSettings()
|
||||
|
||||
export const REST_COLLECTIONS_MOCK: HoppCollection<HoppRESTRequest>[] = [
|
||||
export const REST_COLLECTIONS_MOCK: HoppCollection[] = [
|
||||
{
|
||||
v: 1,
|
||||
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,
|
||||
name: "Echo",
|
||||
|
||||
@@ -101,7 +101,7 @@ type ExportedUserCollectionGQL = {
|
||||
function exportedCollectionToHoppCollection(
|
||||
collection: ExportedUserCollectionREST | ExportedUserCollectionGQL,
|
||||
collectionType: "REST" | "GQL"
|
||||
): HoppCollection<HoppRESTRequest | HoppGQLRequest> {
|
||||
): HoppCollection {
|
||||
if (collectionType == "REST") {
|
||||
const restCollection = collection as ExportedUserCollectionREST
|
||||
|
||||
@@ -186,7 +186,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
|
||||
exportedCollectionToHoppCollection(
|
||||
collection,
|
||||
"REST"
|
||||
) as HoppCollection<HoppRESTRequest>
|
||||
) as HoppCollection
|
||||
)
|
||||
)
|
||||
: setGraphqlCollections(
|
||||
@@ -195,7 +195,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
|
||||
exportedCollectionToHoppCollection(
|
||||
collection,
|
||||
"GQL"
|
||||
) as HoppCollection<HoppGQLRequest>
|
||||
) as HoppCollection
|
||||
)
|
||||
)
|
||||
})
|
||||
@@ -718,7 +718,7 @@ export const def: CollectionsPlatformDef = {
|
||||
|
||||
function getCollectionPathFromCollectionID(
|
||||
collectionID: string,
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
|
||||
collections: HoppCollection[],
|
||||
parentPath?: string
|
||||
): string | null {
|
||||
for (const collectionIndex in collections) {
|
||||
@@ -742,7 +742,7 @@ function getCollectionPathFromCollectionID(
|
||||
|
||||
function getRequestPathFromRequestID(
|
||||
requestID: string,
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
|
||||
collections: HoppCollection[],
|
||||
parentPath?: string
|
||||
): { collectionPath: string; requestIndex: number } | null {
|
||||
for (const collectionIndex in collections) {
|
||||
@@ -774,7 +774,7 @@ function getRequestPathFromRequestID(
|
||||
function getRequestIndex(
|
||||
requestID: string,
|
||||
parentCollectionPath: string,
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[]
|
||||
collections: HoppCollection[]
|
||||
) {
|
||||
const collection = navigateToFolderWithIndexPath(
|
||||
collections,
|
||||
|
||||
@@ -39,7 +39,7 @@ export const restRequestsMapper = createMapper<string, string>()
|
||||
// temp implementation untill the backend implements an endpoint that accepts an entire collection
|
||||
// TODO: use importCollectionsJSON to do this
|
||||
const recursivelySyncCollections = async (
|
||||
collection: HoppCollection<HoppRESTRequest>,
|
||||
collection: HoppCollection,
|
||||
collectionPath: string,
|
||||
parentUserCollectionID?: string
|
||||
) => {
|
||||
|
||||
@@ -36,7 +36,7 @@ export const gqlRequestsMapper = createMapper<string, string>()
|
||||
// temp implementation untill the backend implements an endpoint that accepts an entire collection
|
||||
// TODO: use importCollectionsJSON to do this
|
||||
const recursivelySyncCollections = async (
|
||||
collection: HoppCollection<HoppRESTRequest>,
|
||||
collection: HoppCollection,
|
||||
collectionPath: string,
|
||||
parentUserCollectionID?: string
|
||||
) => {
|
||||
|
||||
@@ -103,7 +103,7 @@ type ExportedUserCollectionGQL = {
|
||||
function exportedCollectionToHoppCollection(
|
||||
collection: ExportedUserCollectionREST | ExportedUserCollectionGQL,
|
||||
collectionType: "REST" | "GQL"
|
||||
): HoppCollection<HoppRESTRequest | HoppGQLRequest> {
|
||||
): HoppCollection {
|
||||
if (collectionType == "REST") {
|
||||
const restCollection = collection as ExportedUserCollectionREST
|
||||
const data =
|
||||
@@ -203,7 +203,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
|
||||
exportedCollectionToHoppCollection(
|
||||
collection,
|
||||
"REST"
|
||||
) as HoppCollection<HoppRESTRequest>
|
||||
) as HoppCollection
|
||||
)
|
||||
)
|
||||
: setGraphqlCollections(
|
||||
@@ -212,7 +212,7 @@ async function loadUserCollections(collectionType: "REST" | "GQL") {
|
||||
exportedCollectionToHoppCollection(
|
||||
collection,
|
||||
"GQL"
|
||||
) as HoppCollection<HoppGQLRequest>
|
||||
) as HoppCollection
|
||||
)
|
||||
)
|
||||
})
|
||||
@@ -748,7 +748,7 @@ export const def: CollectionsPlatformDef = {
|
||||
|
||||
function getCollectionPathFromCollectionID(
|
||||
collectionID: string,
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
|
||||
collections: HoppCollection[],
|
||||
parentPath?: string
|
||||
): string | null {
|
||||
for (const collectionIndex in collections) {
|
||||
@@ -772,7 +772,7 @@ function getCollectionPathFromCollectionID(
|
||||
|
||||
function getRequestPathFromRequestID(
|
||||
requestID: string,
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[],
|
||||
collections: HoppCollection[],
|
||||
parentPath?: string
|
||||
): { collectionPath: string; requestIndex: number } | null {
|
||||
for (const collectionIndex in collections) {
|
||||
@@ -804,7 +804,7 @@ function getRequestPathFromRequestID(
|
||||
function getRequestIndex(
|
||||
requestID: string,
|
||||
parentCollectionPath: string,
|
||||
collections: HoppCollection<HoppRESTRequest | HoppGQLRequest>[]
|
||||
collections: HoppCollection[]
|
||||
) {
|
||||
const collection = navigateToFolderWithIndexPath(
|
||||
collections,
|
||||
|
||||
@@ -39,7 +39,7 @@ export const restRequestsMapper = createMapper<string, string>()
|
||||
// temp implementation untill the backend implements an endpoint that accepts an entire collection
|
||||
// TODO: use importCollectionsJSON to do this
|
||||
const recursivelySyncCollections = async (
|
||||
collection: HoppCollection<HoppRESTRequest>,
|
||||
collection: HoppCollection,
|
||||
collectionPath: string,
|
||||
parentUserCollectionID?: string
|
||||
) => {
|
||||
|
||||
@@ -36,7 +36,7 @@ export const gqlRequestsMapper = createMapper<string, string>()
|
||||
// temp implementation untill the backend implements an endpoint that accepts an entire collection
|
||||
// TODO: use importCollectionsJSON to do this
|
||||
const recursivelySyncCollections = async (
|
||||
collection: HoppCollection<HoppRESTRequest>,
|
||||
collection: HoppCollection,
|
||||
collectionPath: string,
|
||||
parentUserCollectionID?: string
|
||||
) => {
|
||||
|
||||
Reference in New Issue
Block a user