MCPcopy Index your code
hub / github.com/callstack/agent-device / readFieldInput

Function readFieldInput

src/commands/command-input.ts:245–267  ·  view source on GitHub ↗
(
  input: unknown,
  fields: TFields,
)

Source from the content-addressed store, hash-verified

243}
244
245export function readFieldInput<TFields extends CommandFieldMap>(
246 input: unknown,
247 fields: TFields,
248): InferCommandInput<TFields> {
249 const record = readInputRecord(input);
250 const commandOptions = Object.fromEntries(
251 Object.entries(fields).flatMap(([key, field]) => {
252 const value = field.read(record, key);
253 if (field.required && value === undefined) {
254 throw new Error(`Expected ${key} to be set.`);
255 }
256 return value === undefined ? [] : [[key, value]];
257 }),
258 );
259 const commonInput = readCommonInput(record, {
260 readTargetAlias: !Object.hasOwn(fields, 'target'),
261 });
262 return compactRecord({
263 ...commonInput,
264 ...commonToClientOptions(commonInput),
265 ...commandOptions,
266 }) as InferCommandInput<TFields>;
267}
268
269export function readInputRecord(input: unknown): Record<string, unknown> {
270 if (input === undefined || input === null) return {};

Callers 3

readBatchInputFunction · 0.90
metadata.tsFile · 0.90

Calls 4

readInputRecordFunction · 0.85
readCommonInputFunction · 0.85
compactRecordFunction · 0.85
commonToClientOptionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…