From 1900f199115a8ea5bd55162f6cbc18dc27366531 Mon Sep 17 00:00:00 2001 From: apoddubn Date: Fri, 19 Jul 2024 18:02:49 +0200 Subject: [PATCH 1/5] fix: normalize extracted column keys --- utils/extractor/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/extractor/src/index.ts b/utils/extractor/src/index.ts index 61b2a7ac2..8112b74f5 100644 --- a/utils/extractor/src/index.ts +++ b/utils/extractor/src/index.ts @@ -200,6 +200,10 @@ function getSheetConfig( } } +function normalizeKey(key: string): string { + return key.trim().replace('%', '_PERCENT_').replace('$', '_DOLLAR_') +} + export function keysToFields({ keys, descriptions = {}, @@ -230,7 +234,7 @@ export function keysToFields({ return Object.entries(countOfKeys) .sort((a, b) => a[1].index - b[1].index) .map(([key, _]) => ({ - key, + key: normalizeKey(key), label: key, description: descriptions?.[key] || '', type: 'string', From 6d767498fc5e55877107b7001302f5bb90e8d4e1 Mon Sep 17 00:00:00 2001 From: apoddubn Date: Thu, 25 Jul 2024 19:11:28 +0200 Subject: [PATCH 2/5] fix: normalize records keys along with the sheet fields --- utils/extractor/src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/extractor/src/index.ts b/utils/extractor/src/index.ts index 8112b74f5..d531e2417 100644 --- a/utils/extractor/src/index.ts +++ b/utils/extractor/src/index.ts @@ -105,7 +105,7 @@ export const Extractor = ( continue } await asyncBatch( - capture[sheet.name].data, + capture[sheet.name].data.map(normalizeRecordKeys), async (chunk) => { await api.records.insert(sheet.id, chunk, { compressRequestBody: true, @@ -204,6 +204,15 @@ function normalizeKey(key: string): string { return key.trim().replace('%', '_PERCENT_').replace('$', '_DOLLAR_') } +function normalizeRecordKeys(record: Flatfile.RecordData): Flatfile.RecordData { + return Object.fromEntries( + Object.entries(record).map(([key, value]) => [ + normalizeKey(key), + value, + ]) + ) +} + export function keysToFields({ keys, descriptions = {}, From 125ff6189276c5aebee60dc14b77da4a07d3edab Mon Sep 17 00:00:00 2001 From: apoddubn Date: Thu, 25 Jul 2024 20:03:20 +0200 Subject: [PATCH 3/5] chore: rewrite with a reduce --- utils/extractor/src/index.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/utils/extractor/src/index.ts b/utils/extractor/src/index.ts index d531e2417..c4b44c9b5 100644 --- a/utils/extractor/src/index.ts +++ b/utils/extractor/src/index.ts @@ -205,12 +205,10 @@ function normalizeKey(key: string): string { } function normalizeRecordKeys(record: Flatfile.RecordData): Flatfile.RecordData { - return Object.fromEntries( - Object.entries(record).map(([key, value]) => [ - normalizeKey(key), - value, - ]) - ) + return Object.entries(record).reduce((acc, [key, value]) => { + acc[normalizeKey(key)] = value + return acc + }, {} as Flatfile.RecordData) } export function keysToFields({ From 8defedfacb8e4a07c3ca0e377314516bd9692ee4 Mon Sep 17 00:00:00 2001 From: apoddubn Date: Thu, 25 Jul 2024 20:53:47 +0200 Subject: [PATCH 4/5] chore: rewrite with for-in loop --- utils/extractor/src/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/extractor/src/index.ts b/utils/extractor/src/index.ts index c4b44c9b5..3d616339a 100644 --- a/utils/extractor/src/index.ts +++ b/utils/extractor/src/index.ts @@ -205,10 +205,13 @@ function normalizeKey(key: string): string { } function normalizeRecordKeys(record: Flatfile.RecordData): Flatfile.RecordData { - return Object.entries(record).reduce((acc, [key, value]) => { - acc[normalizeKey(key)] = value - return acc - }, {} as Flatfile.RecordData) + const normalizedRecord = {} as Flatfile.RecordData + for (const key in record) { + if (record.hasOwnProperty(key)) { + normalizedRecord[normalizeKey(key)] = record[key] + } + } + return normalizedRecord } export function keysToFields({ From 0e7330aa45ce54ede01bb9a4c6bc2f81e2fb5b23 Mon Sep 17 00:00:00 2001 From: apoddubn Date: Thu, 25 Jul 2024 21:15:58 +0200 Subject: [PATCH 5/5] fix merge --- utils/extractor/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/extractor/src/index.ts b/utils/extractor/src/index.ts index 3d616339a..923049b0a 100644 --- a/utils/extractor/src/index.ts +++ b/utils/extractor/src/index.ts @@ -201,7 +201,7 @@ function getSheetConfig( } function normalizeKey(key: string): string { - return key.trim().replace('%', '_PERCENT_').replace('$', '_DOLLAR_') + return key.trim().replace(/%/g, '_PERCENT_').replace(/\$/g, '_DOLLAR_') } function normalizeRecordKeys(record: Flatfile.RecordData): Flatfile.RecordData {