diff --git a/src/lib/helpers/variables.ts b/src/lib/helpers/variables.ts new file mode 100644 index 000000000..c0a9c2ce0 --- /dev/null +++ b/src/lib/helpers/variables.ts @@ -0,0 +1,40 @@ +import type { Models } from '@appwrite.io/console'; + +export type DetectedVariable = { + key?: string; + name?: string; + value?: string; + secret?: boolean; +}; + +export function normalizeDetectedVariables(detected: DetectedVariable[] = []) { + const normalized: Partial[] = []; + detected.forEach((variable) => { + const key = variable.key ?? variable.name; + if (!key) { + return; + } + normalized.push({ + key, + value: variable.value ?? '', + secret: variable.secret ?? false + }); + }); + return normalized; +} + +export function mergeVariables( + existing: Partial[], + detected: Partial[] +) { + const map = new Map(existing.map((variable) => [variable.key, variable])); + detected.forEach((variable) => { + if (!variable.key) { + return; + } + if (!map.has(variable.key)) { + map.set(variable.key, variable); + } + }); + return Array.from(map.values()); +} diff --git a/src/routes/(console)/project-[region]-[project]/functions/create-function/repository-[repository]/+page.svelte b/src/routes/(console)/project-[region]-[project]/functions/create-function/repository-[repository]/+page.svelte index a9233a368..471095b7e 100644 --- a/src/routes/(console)/project-[region]-[project]/functions/create-function/repository-[repository]/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/functions/create-function/repository-[repository]/+page.svelte @@ -22,6 +22,7 @@ import RepoCard from './repoCard.svelte'; import { getIconFromRuntime } from '$lib/stores/runtimes'; import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store'; + import { normalizeDetectedVariables, mergeVariables } from '$lib/helpers/variables'; export let data; @@ -59,45 +60,6 @@ let detectingRuntime = true; - type DetectedVariable = { - key?: string; - name?: string; - value?: string; - secret?: boolean; - }; - - function normalizeDetectedVariables(detected: DetectedVariable[] = []) { - const normalized: Partial[] = []; - detected.forEach((variable) => { - const key = variable.key ?? variable.name; - if (!key) { - return; - } - normalized.push({ - key, - value: variable.value ?? '', - secret: variable.secret ?? false - }); - }); - return normalized; - } - - function mergeVariables( - existing: Partial[], - detected: Partial[] - ) { - const map = new Map(existing.map((variable) => [variable.key, variable])); - detected.forEach((variable) => { - if (!variable.key) { - return; - } - if (!map.has(variable.key)) { - map.set(variable.key, variable); - } - }); - return Array.from(map.values()); - } - onMount(async () => { installation.set(data.installation); repository.set(data.repository); diff --git a/src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.svelte b/src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.svelte index 5c34c5703..6be086393 100644 --- a/src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.svelte +++ b/src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.svelte @@ -27,6 +27,7 @@ import Configuration from '../../configuration.svelte'; import Domain from '../../domain.svelte'; import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store'; + import { normalizeDetectedVariables, mergeVariables } from '$lib/helpers/variables'; export let data; let showExitModal = false; @@ -49,45 +50,6 @@ let domainIsValid = true; let isVariablesLoading = true; - type DetectedVariable = { - key?: string; - name?: string; - value?: string; - secret?: boolean; - }; - - function normalizeDetectedVariables(detected: DetectedVariable[] = []) { - const normalized: Partial[] = []; - detected.forEach((variable) => { - const key = variable.key ?? variable.name; - if (!key) { - return; - } - normalized.push({ - key, - value: variable.value ?? '', - secret: variable.secret ?? false - }); - }); - return normalized; - } - - function mergeVariables( - existing: Partial[], - detected: Partial[] - ) { - const map = new Map(existing.map((variable) => [variable.key, variable])); - detected.forEach((variable) => { - if (!variable.key) { - return; - } - if (!map.has(variable.key)) { - map.set(variable.key, variable); - } - }); - return Array.from(map.values()); - } - onMount(async () => { installation.set(data.installation); repository.set(data.repository);