Skip to content

Commit

Permalink
Update coerce rows
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Rico <[email protected]>
  • Loading branch information
SferaDev committed Nov 27, 2023
1 parent 69f2be4 commit 5b21a82
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions packages/importer/src/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,12 @@ export const coerceRows = async <T extends Record<string, unknown>>(
columns: Schemas.Column[],
options?: ColumnOptions
): Promise<Record<string, CoercedValue>[]> => {
const columnValues = [];
for (const row of rows) {
for (const column of columns) {
columnValues.push(coerceValue(row[column.name], column, options));
}
}
const results = await Promise.allSettled(columnValues);
const mapped = [];
let index = 0;
for (const _row of rows) {
const mappedRow: Record<string, CoercedValue> = {};
for (const column of columns) {
const result = results[index];
if (result.status === 'fulfilled') {
mappedRow[column.name] = result.value;
}
index = index + 1;
}
mapped.push(mappedRow);
for (const row of rows) {
const entries = await Promise.all(
columns.map((column) => coerceValue(row[column.name], column, options).then((value) => [column.name, value]))
);
mapped.push(Object.fromEntries(entries));
}
return mapped;
};
Expand Down

0 comments on commit 5b21a82

Please sign in to comment.