Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: add missing field and `translateToNewRequest` for history (#6068)
Nivedin40d65dba49ac
diff --git a/packages/hoppscotch-common/src/newstore/history.ts b/packages/hoppscotch-common/src/newstore/history.tsindex a686d8ae0..8b3dc3909 100644--- a/packages/hoppscotch-common/src/newstore/history.ts+++ b/packages/hoppscotch-common/src/newstore/history.ts@@ -341,22 +341,14 @@ export function removeDuplicateGraphqlHistoryEntry(id: string) {// Listen to completed responses to add to historyexecutedResponses$.subscribe((res) => {+ // Spread to auto-capture any future fields, but omit _ref_id and id+ // since history entries are snapshots and shouldn't carry collection/firestore references+ // eslint-disable-next-line @typescript-eslint/no-unused-vars+ const { _ref_id, id, ...request } = res.req+addRESTHistoryEntry(makeRESTHistoryEntry({- request: {- auth: res.req.auth,- body: res.req.body,- endpoint: res.req.endpoint,- headers: res.req.headers,- method: res.req.method,- name: res.req.name,- params: res.req.params,- preRequestScript: res.req.preRequestScript,- testScript: res.req.testScript,- requestVariables: res.req.requestVariables,- v: res.req.v,- responses: res.req.responses,- },+ request,responseMeta: {duration: res.meta.responseDuration,statusCode: res.statusCode,diff --git a/packages/hoppscotch-selfhost-web/src/platform/history/desktop/index.ts b/packages/hoppscotch-selfhost-web/src/platform/history/desktop/index.tsindex fd79ac3ce..f36240d57 100644--- a/packages/hoppscotch-selfhost-web/src/platform/history/desktop/index.ts+++ b/packages/hoppscotch-selfhost-web/src/platform/history/desktop/index.ts@@ -15,6 +15,7 @@ import {deleteGraphqlHistoryEntry,clearGraphqlHistory,} from "@hoppscotch/common/newstore/history"+import { translateToNewRequest, translateToGQLRequest } from "@hoppscotch/data"import { HistoryPlatformDef } from "@hoppscotch/common/platform/history"import {getUserHistoryEntries,@@ -98,7 +99,7 @@ async function loadHistoryEntries() {const restHistoryEntries: RESTHistoryEntry[] = restEntries.map((entry) => ({v: 1,- request: JSON.parse(entry.request),+ request: translateToNewRequest(JSON.parse(entry.request)),responseMeta: JSON.parse(entry.responseMetadata),star: entry.isStarred,updatedOn: new Date(entry.executedOn),@@ -107,7 +108,7 @@ async function loadHistoryEntries() {const gqlHistoryEntries: GQLHistoryEntry[] = gqlEntries.map((entry) => ({v: 1,- request: JSON.parse(entry.request),+ request: translateToGQLRequest(JSON.parse(entry.request)),response: JSON.parse(entry.responseMetadata),star: entry.isStarred,updatedOn: new Date(entry.executedOn),@@ -165,7 +166,7 @@ function setupUserHistoryCreatedSubscription() {? addRESTHistoryEntry({v: 1,id,- request: JSON.parse(request),+ request: translateToNewRequest(JSON.parse(request)),responseMeta: JSON.parse(responseMetadata),star: isStarred,updatedOn: new Date(executedOn),@@ -173,7 +174,7 @@ function setupUserHistoryCreatedSubscription() {: addGraphqlHistoryEntry({v: 1,id,- request: JSON.parse(request),+ request: translateToGQLRequest(JSON.parse(request)),response: JSON.parse(responseMetadata),star: isStarred,updatedOn: new Date(executedOn),@@ -192,45 +193,31 @@ function setupUserHistoryUpdatedSubscription() {userHistoryUpdated$.subscribe((res) => {if (E.isRight(res)) {- const { id, executedOn, isStarred, request, responseMetadata, reqType } =- res.right.userHistoryUpdated+ const { id, reqType, isStarred } = res.right.userHistoryUpdatedif (reqType == ReqType.Rest) {- const updatedRestEntryIndex = restHistoryStore.value.state.findIndex(+ const existingEntry = restHistoryStore.value.state.find((entry) => entry.id == id)- if (updatedRestEntryIndex != -1) {+ // Only toggle if the store entry's star doesn't match the server state.+ // Without this guard, the subscription echo from the same client's own+ // toggle would cause a second toggle and revert the star.+ if (existingEntry && existingEntry.star !== isStarred) {runDispatchWithOutSyncing(() => {- toggleRESTHistoryEntryStar({- v: 1,- id,- request: JSON.parse(request),- responseMeta: JSON.parse(responseMetadata),- // because the star will be toggled in the store, we need to pass the opposite value- star: !isStarred,- updatedOn: new Date(executedOn),- })+ toggleRESTHistoryEntryStar(existingEntry)})}}if (reqType == ReqType.Gql) {- const updatedGQLEntryIndex = graphqlHistoryStore.value.state.findIndex(+ const existingEntry = graphqlHistoryStore.value.state.find((entry) => entry.id == id)- if (updatedGQLEntryIndex != -1) {+ if (existingEntry && existingEntry.star !== isStarred) {runDispatchWithOutSyncing(() => {- toggleGraphqlHistoryEntryStar({- v: 1,- id,- request: JSON.parse(request),- response: JSON.parse(responseMetadata),- // because the star will be toggled in the store, we need to pass the opposite value- star: !isStarred,- updatedOn: new Date(executedOn),- })+ toggleGraphqlHistoryEntryStar(existingEntry)})}}diff --git a/packages/hoppscotch-selfhost-web/src/platform/history/web/index.ts b/packages/hoppscotch-selfhost-web/src/platform/history/web/index.tsindex 03858cb21..64e1186c2 100644--- a/packages/hoppscotch-selfhost-web/src/platform/history/web/index.ts+++ b/packages/hoppscotch-selfhost-web/src/platform/history/web/index.ts@@ -15,6 +15,7 @@ import {deleteGraphqlHistoryEntry,clearGraphqlHistory,} from "@hoppscotch/common/newstore/history"+import { translateToNewRequest, translateToGQLRequest } from "@hoppscotch/data"import { HistoryPlatformDef } from "@hoppscotch/common/platform/history"import {getUserHistoryEntries,@@ -101,7 +102,7 @@ async function loadHistoryEntries() {const restHistoryEntries: RESTHistoryEntry[] = restEntries.map((entry) => ({v: 1,- request: JSON.parse(entry.request),+ request: translateToNewRequest(JSON.parse(entry.request)),responseMeta: JSON.parse(entry.responseMetadata),star: entry.isStarred,updatedOn: new Date(entry.executedOn),@@ -110,7 +111,7 @@ async function loadHistoryEntries() {const gqlHistoryEntries: GQLHistoryEntry[] = gqlEntries.map((entry) => ({v: 1,- request: JSON.parse(entry.request),+ request: translateToGQLRequest(JSON.parse(entry.request)),response: JSON.parse(entry.responseMetadata),star: entry.isStarred,updatedOn: new Date(entry.executedOn),@@ -168,7 +169,7 @@ function setupUserHistoryCreatedSubscription() {? addRESTHistoryEntry({v: 1,id,- request: JSON.parse(request),+ request: translateToNewRequest(JSON.parse(request)),responseMeta: JSON.parse(responseMetadata),star: isStarred,updatedOn: new Date(executedOn),@@ -176,7 +177,7 @@ function setupUserHistoryCreatedSubscription() {: addGraphqlHistoryEntry({v: 1,id,- request: JSON.parse(request),+ request: translateToGQLRequest(JSON.parse(request)),response: JSON.parse(responseMetadata),star: isStarred,updatedOn: new Date(executedOn),@@ -195,45 +196,31 @@ function setupUserHistoryUpdatedSubscription() {userHistoryUpdated$.subscribe((res) => {if (E.isRight(res)) {- const { id, executedOn, isStarred, request, responseMetadata, reqType } =- res.right.userHistoryUpdated+ const { id, reqType, isStarred } = res.right.userHistoryUpdatedif (reqType == ReqType.Rest) {- const updatedRestEntryIndex = restHistoryStore.value.state.findIndex(+ const existingEntry = restHistoryStore.value.state.find((entry) => entry.id == id)- if (updatedRestEntryIndex != -1) {+ // Only toggle if the store entry's star doesn't match the server state.+ // Without this guard, the subscription echo from the same client's own+ // toggle would cause a second toggle and revert the star.+ if (existingEntry && existingEntry.star !== isStarred) {runDispatchWithOutSyncing(() => {- toggleRESTHistoryEntryStar({- v: 1,- id,- request: JSON.parse(request),- responseMeta: JSON.parse(responseMetadata),- // because the star will be toggled in the store, we need to pass the opposite value- star: !isStarred,- updatedOn: new Date(executedOn),- })+ toggleRESTHistoryEntryStar(existingEntry)})}}if (reqType == ReqType.Gql) {- const updatedGQLEntryIndex = graphqlHistoryStore.value.state.findIndex(+ const existingEntry = graphqlHistoryStore.value.state.find((entry) => entry.id == id)- if (updatedGQLEntryIndex != -1) {+ if (existingEntry && existingEntry.star !== isStarred) {runDispatchWithOutSyncing(() => {- toggleGraphqlHistoryEntryStar({- v: 1,- id,- request: JSON.parse(request),- response: JSON.parse(responseMetadata),- // because the star will be toggled in the store, we need to pass the opposite value- star: !isStarred,- updatedOn: new Date(executedOn),- })+ toggleGraphqlHistoryEntryStar(existingEntry)})}}