| 81 | } |
| 82 | |
| 83 | function createFormData( |
| 84 | file: File, |
| 85 | options?: { |
| 86 | workspaceId?: string | null |
| 87 | mode?: string | null |
| 88 | mapping?: unknown |
| 89 | createColumns?: unknown |
| 90 | } |
| 91 | ): FormData { |
| 92 | // Text fields must precede the file part for the streaming parser. |
| 93 | const form = new FormData() |
| 94 | if (options?.workspaceId !== null) { |
| 95 | form.append('workspaceId', options?.workspaceId ?? 'workspace-1') |
| 96 | } |
| 97 | if (options?.mode !== null) { |
| 98 | form.append('mode', options?.mode ?? 'append') |
| 99 | } |
| 100 | if (options?.mapping !== undefined) { |
| 101 | form.append( |
| 102 | 'mapping', |
| 103 | typeof options.mapping === 'string' ? options.mapping : JSON.stringify(options.mapping) |
| 104 | ) |
| 105 | } |
| 106 | if (options?.createColumns !== undefined) { |
| 107 | form.append( |
| 108 | 'createColumns', |
| 109 | typeof options.createColumns === 'string' |
| 110 | ? options.createColumns |
| 111 | : JSON.stringify(options.createColumns) |
| 112 | ) |
| 113 | } |
| 114 | form.append('file', file) |
| 115 | return form |
| 116 | } |
| 117 | |
| 118 | function buildTable(overrides: Partial<TableDefinition> = {}): TableDefinition { |
| 119 | return { |