Skip to content

Commit 92dbdc9

Browse files
committed
Deduplicate removeUndefined helper
1 parent b7954e9 commit 92dbdc9

2 files changed

Lines changed: 2 additions & 20 deletions

File tree

src/mcp/tools/session-management/session_set_defaults.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as z from 'zod';
22
import { persistSessionDefaultsPatch } from '../../../utils/config-store.ts';
3+
import { removeUndefined } from '../../../utils/remove-undefined.ts';
34
import { sessionStore, type SessionDefaults } from '../../../utils/session-store.ts';
45
import { sessionDefaultsSchema } from '../../../utils/session-defaults-schema.ts';
56
import { createTypedToolWithContext } from '../../../utils/typed-tool-factory.ts';
@@ -16,16 +17,6 @@ type Params = z.infer<typeof schemaObj>;
1617

1718
type SessionSetDefaultsContext = Record<string, never>;
1819

19-
function removeUndefined<T extends Record<string, unknown>>(input: T): Partial<T> {
20-
const result: Partial<T> = {};
21-
for (const [key, value] of Object.entries(input)) {
22-
if (value !== undefined) {
23-
result[key as keyof T] = value as T[keyof T];
24-
}
25-
}
26-
return result;
27-
}
28-
2920
export async function sessionSetDefaultsLogic(
3021
params: Params,
3122
neverContext: SessionSetDefaultsContext,

src/utils/project-config.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
33
import type { FileSystemExecutor } from './FileSystemExecutor.ts';
44
import type { SessionDefaults } from './session-store.ts';
55
import { log } from './logger.ts';
6+
import { removeUndefined } from './remove-undefined.ts';
67
import { runtimeConfigFileSchema, type RuntimeConfigFile } from './runtime-config-schema.ts';
78

89
const CONFIG_DIR = '.xcodebuildmcp';
@@ -49,16 +50,6 @@ function toError(value: unknown): Error {
4950
return value instanceof Error ? value : new Error(String(value));
5051
}
5152

52-
function removeUndefined<T extends Record<string, unknown>>(input: T): Partial<T> {
53-
const result: Partial<T> = {};
54-
for (const [key, value] of Object.entries(input)) {
55-
if (value !== undefined) {
56-
result[key as keyof T] = value as T[keyof T];
57-
}
58-
}
59-
return result;
60-
}
61-
6253
function hasValue<T extends Record<string, unknown>>(defaults: T, key: keyof T): boolean {
6354
return Object.prototype.hasOwnProperty.call(defaults, key) && defaults[key] !== undefined;
6455
}

0 commit comments

Comments
 (0)