Skip to content

Commit f823f76

Browse files
committed
Moved deduplicateVariableArray to a separate file…
1 parent 345da55 commit f823f76

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { type EnvironmentVariable } from "./environmentVariables/repository";
2+
3+
/** Later variables override earlier ones */
4+
export function deduplicateVariableArray(variables: EnvironmentVariable[]) {
5+
const result: EnvironmentVariable[] = [];
6+
// Process array in reverse order so later variables override earlier ones
7+
for (const variable of [...variables].reverse()) {
8+
if (!result.some((v) => v.key === variable.key)) {
9+
result.push(variable);
10+
}
11+
}
12+
// Reverse back to maintain original order but with later variables taking precedence
13+
return result.reverse();
14+
}

apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
type Result,
1717
} from "./repository";
1818
import { removeBlacklistedVariables } from "../environmentVariableRules.server";
19+
import { deduplicateVariableArray } from "../deduplicateVariableArray.server";
1920

2021
function secretKeyProjectPrefix(projectId: string) {
2122
return `environmentvariable:${projectId}:`;
@@ -842,19 +843,6 @@ export async function resolveVariablesForEnvironment(
842843
]);
843844
}
844845

845-
/** Later variables override earlier ones */
846-
export function deduplicateVariableArray(variables: EnvironmentVariable[]) {
847-
const result: EnvironmentVariable[] = [];
848-
// Process array in reverse order so later variables override earlier ones
849-
for (const variable of [...variables].reverse()) {
850-
if (!result.some((v) => v.key === variable.key)) {
851-
result.push(variable);
852-
}
853-
}
854-
// Reverse back to maintain original order but with later variables taking precedence
855-
return result.reverse();
856-
}
857-
858846
async function resolveOverridableTriggerVariables(
859847
runtimeEnvironment: RuntimeEnvironmentForEnvRepo
860848
) {

apps/webapp/test/environmentVariableDeduplication.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
2-
import { deduplicateVariableArray } from "../app/v3/environmentVariables/environmentVariablesRepository.server";
32
import type { EnvironmentVariable } from "../app/v3/environmentVariables/repository";
3+
import { deduplicateVariableArray } from "~/v3/deduplicateVariableArray.server";
44

55
describe("Deduplicate variables", () => {
66
it("should keep later variables when there are duplicates", () => {

0 commit comments

Comments
 (0)