[PR #4216] [MERGED] refactor: make global environment a versioned entity #4709

Closed
opened 2026-03-17 02:13:13 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/4216
Author: @ipalakchopra
Created: 7/28/2024
Status: Merged
Merged: 9/23/2024
Merged by: @AndrewBastin

Base: nextHead: main


📝 Commits (4)

  • cd6a24e refactor: created versioned entities for global environments
  • ed00739 chore: schema updates and extend consumption
  • fea2dc7 refactor: update global environment format kept in store
  • 9349cd6 chore: cleanup

📊 Changes

17 files changed (+336 additions, -137 deletions)

View changed files

📝 packages/hoppscotch-common/src/components/environments/Selector.vue (+21 -19)
📝 packages/hoppscotch-common/src/components/environments/index.vue (+5 -5)
📝 packages/hoppscotch-common/src/components/environments/my/Details.vue (+36 -22)
📝 packages/hoppscotch-common/src/components/http/TestResult.vue (+12 -15)
📝 packages/hoppscotch-common/src/helpers/RequestRunner.ts (+8 -5)
📝 packages/hoppscotch-common/src/newstore/environments.ts (+49 -22)
📝 packages/hoppscotch-common/src/services/persistence/__tests__/__mocks__/index.ts (+5 -3)
📝 packages/hoppscotch-common/src/services/persistence/__tests__/index.spec.ts (+1 -1)
📝 packages/hoppscotch-common/src/services/persistence/index.ts (+11 -11)
📝 packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts (+0 -2)
packages/hoppscotch-data/src/global-environment/index.ts (+33 -0)
packages/hoppscotch-data/src/global-environment/v/0.ts (+25 -0)
packages/hoppscotch-data/src/global-environment/v/1.ts (+46 -0)
📝 packages/hoppscotch-data/src/index.ts (+1 -0)
📝 packages/hoppscotch-selfhost-web/package.json (+1 -0)
📝 packages/hoppscotch-selfhost-web/src/platform/environments/environments.platform.ts (+15 -4)
📝 pnpm-lock.yaml (+67 -28)

📄 Description

This PR introduces a new versioned entity for the global environment.
Partly addresses #4160.

Closes HFE-429.

import { GlobalEnvironment } from "@hoppscotch/data"

const result = GlobalEnvironment.safeParse(globalEnvData)
 
if (result.type === "ok") {
  // ...
} else {
  // ...
}

Schema reference

const V0_SCHEMA = z.array(
  z.union([
    z.object({
      key: z.string(),
      value: z.string(),
      secret: z.literal(false),
    }),
    z.object({
      key: z.string(),
      secret: z.literal(true),
    }),
    z.object({
      key: z.string(),
      value: z.string(),
    }),
  ])
)
const V1_SCHEMA = z.object({
  v: z.literal(1),
  variables: z.array(
    z.union([
      z.object({
        key: z.string(),
        secret: z.literal(true),
      }),
      z.object({
        key: z.string(),
        value: z.string(),
        secret: z.literal(false),
      }),
    ])
  ),
})

What's changed

  • Introduce schema definitions and related updates to represent the global environment as a versioned entity compiled under a new global-environment directory within hoppscotch-data.
  • Update the usage across to consume the versioned entity and perform the necessary migration ensuring the latest version is dealt with, syncing context, for instance.
  • Adds verzod as a dependency under hoppscotch-selfhost-web.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/4216 **Author:** [@ipalakchopra](https://github.com/ipalakchopra) **Created:** 7/28/2024 **Status:** ✅ Merged **Merged:** 9/23/2024 **Merged by:** [@AndrewBastin](https://github.com/AndrewBastin) **Base:** `next` ← **Head:** `main` --- ### 📝 Commits (4) - [`cd6a24e`](https://github.com/hoppscotch/hoppscotch/commit/cd6a24e512911741f4f4a1ee7ac466a0e1f65a2f) refactor: created versioned entities for global environments - [`ed00739`](https://github.com/hoppscotch/hoppscotch/commit/ed00739090dca8bcb90cdccc4aaf750d57552550) chore: schema updates and extend consumption - [`fea2dc7`](https://github.com/hoppscotch/hoppscotch/commit/fea2dc7b8f2a945a157463c2e91e4fe3ae4036c5) refactor: update global environment format kept in store - [`9349cd6`](https://github.com/hoppscotch/hoppscotch/commit/9349cd64d7d784cb9d057dfe3800df7372ab1fb9) chore: cleanup ### 📊 Changes **17 files changed** (+336 additions, -137 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/components/environments/Selector.vue` (+21 -19) 📝 `packages/hoppscotch-common/src/components/environments/index.vue` (+5 -5) 📝 `packages/hoppscotch-common/src/components/environments/my/Details.vue` (+36 -22) 📝 `packages/hoppscotch-common/src/components/http/TestResult.vue` (+12 -15) 📝 `packages/hoppscotch-common/src/helpers/RequestRunner.ts` (+8 -5) 📝 `packages/hoppscotch-common/src/newstore/environments.ts` (+49 -22) 📝 `packages/hoppscotch-common/src/services/persistence/__tests__/__mocks__/index.ts` (+5 -3) 📝 `packages/hoppscotch-common/src/services/persistence/__tests__/index.spec.ts` (+1 -1) 📝 `packages/hoppscotch-common/src/services/persistence/index.ts` (+11 -11) 📝 `packages/hoppscotch-common/src/services/persistence/validation-schemas/index.ts` (+0 -2) ➕ `packages/hoppscotch-data/src/global-environment/index.ts` (+33 -0) ➕ `packages/hoppscotch-data/src/global-environment/v/0.ts` (+25 -0) ➕ `packages/hoppscotch-data/src/global-environment/v/1.ts` (+46 -0) 📝 `packages/hoppscotch-data/src/index.ts` (+1 -0) 📝 `packages/hoppscotch-selfhost-web/package.json` (+1 -0) 📝 `packages/hoppscotch-selfhost-web/src/platform/environments/environments.platform.ts` (+15 -4) 📝 `pnpm-lock.yaml` (+67 -28) </details> ### 📄 Description This PR introduces a new versioned entity for the global environment. Partly addresses #4160. Closes HFE-429. ```ts import { GlobalEnvironment } from "@hoppscotch/data" const result = GlobalEnvironment.safeParse(globalEnvData) if (result.type === "ok") { // ... } else { // ... } ``` ### Schema reference ```ts const V0_SCHEMA = z.array( z.union([ z.object({ key: z.string(), value: z.string(), secret: z.literal(false), }), z.object({ key: z.string(), secret: z.literal(true), }), z.object({ key: z.string(), value: z.string(), }), ]) ) ``` ```ts const V1_SCHEMA = z.object({ v: z.literal(1), variables: z.array( z.union([ z.object({ key: z.string(), secret: z.literal(true), }), z.object({ key: z.string(), value: z.string(), secret: z.literal(false), }), ]) ), }) ``` ### What's changed - Introduce schema definitions and related updates to represent the global environment as a versioned entity compiled under a new `global-environment` directory within `hoppscotch-data`. - Update the usage across to consume the versioned entity and perform the necessary migration ensuring the latest version is dealt with, syncing context, for instance. - Adds `verzod` as a dependency under `hoppscotch-selfhost-web`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:13:13 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#4709
No description provided.