MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / addFormValue

Function addFormValue

packages/core/src/v3/apiClient/core.ts:327–357  ·  view source on GitHub ↗
(form: FormData, key: string, value: unknown)

Source from the content-addressed store, hash-verified

325}
326
327const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
328 if (value === undefined) return;
329 if (value == null) {
330 throw new TypeError(
331 `Received null for "${key}"; to pass null in FormData, you must use the string 'null'`
332 );
333 }
334
335 // TODO: make nested formats configurable
336 if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
337 form.append(key, String(value));
338 } else if (
339 isUploadable(value) ||
340 isBlobLike(value) ||
341 value instanceof Buffer ||
342 value instanceof ArrayBuffer
343 ) {
344 const file = await toFile(value);
345 form.append(key, file as File);
346 } else if (Array.isArray(value)) {
347 await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry)));
348 } else if (typeof value === "object") {
349 await Promise.all(
350 Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop))
351 );
352 } else {
353 throw new TypeError(
354 `Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`
355 );
356 }
357};
358
359export type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
360

Callers 1

createFormFunction · 0.85

Calls 4

isUploadableFunction · 0.85
isBlobLikeFunction · 0.85
toFileFunction · 0.85
allMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…