@whaly/connector-sdk 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +31 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12724,6 +12724,31 @@ function fieldTypeToJsonSchema(fieldType) {
|
|
|
12724
12724
|
return { type: ["null", "string"] };
|
|
12725
12725
|
}
|
|
12726
12726
|
}
|
|
12727
|
+
function coerceCellValue(value, fieldType) {
|
|
12728
|
+
if (value === null || value === void 0) {
|
|
12729
|
+
return null;
|
|
12730
|
+
}
|
|
12731
|
+
switch (fieldType) {
|
|
12732
|
+
case "STRING":
|
|
12733
|
+
return String(value);
|
|
12734
|
+
case "FLOAT": {
|
|
12735
|
+
if (typeof value === "number") return value;
|
|
12736
|
+
if (typeof value === "boolean") return value ? 1 : 0;
|
|
12737
|
+
if (typeof value === "string") {
|
|
12738
|
+
const parsed = Number(value);
|
|
12739
|
+
return isNaN(parsed) ? null : parsed;
|
|
12740
|
+
}
|
|
12741
|
+
return null;
|
|
12742
|
+
}
|
|
12743
|
+
case "TIMESTAMP": {
|
|
12744
|
+
if (value instanceof Date) return value.toISOString();
|
|
12745
|
+
if (typeof value === "string") return value === "" ? null : value;
|
|
12746
|
+
return String(value);
|
|
12747
|
+
}
|
|
12748
|
+
default:
|
|
12749
|
+
return String(value);
|
|
12750
|
+
}
|
|
12751
|
+
}
|
|
12727
12752
|
function excelFieldsToJsonSchema(fields) {
|
|
12728
12753
|
const properties = {};
|
|
12729
12754
|
for (const [key, field] of Object.entries(fields)) {
|
|
@@ -12851,10 +12876,10 @@ var extractSingleSheetRows = async (fileName, conf) => {
|
|
|
12851
12876
|
if (!variables) {
|
|
12852
12877
|
throw new Error(`No variables extracted from filename, cannot extract derived field ${key}`);
|
|
12853
12878
|
}
|
|
12854
|
-
acc[key] = variables[column.variableName]
|
|
12879
|
+
acc[key] = variables[column.variableName] ?? null;
|
|
12855
12880
|
} else {
|
|
12856
12881
|
const colIndex = excelColumnToIndex(column.column);
|
|
12857
|
-
acc[key] = row[colIndex]?.v
|
|
12882
|
+
acc[key] = coerceCellValue(row[colIndex]?.v, column.type);
|
|
12858
12883
|
}
|
|
12859
12884
|
return acc;
|
|
12860
12885
|
}, {});
|
|
@@ -13079,7 +13104,7 @@ async function* rowGeneratorFromCsv(path8, fileConfig) {
|
|
|
13079
13104
|
const keyGenerator = fileConfig.fields[key.trim()];
|
|
13080
13105
|
if (!keyGenerator) continue;
|
|
13081
13106
|
const rawValue = keyGenerator.valueTransformer ? keyGenerator.valueTransformer(row[key]) : row[key];
|
|
13082
|
-
rowData[keyGenerator.key] = rawValue === "" ? null : rawValue;
|
|
13107
|
+
rowData[keyGenerator.key] = rawValue === "" ? null : coerceCellValue(rawValue, keyGenerator.type);
|
|
13083
13108
|
}
|
|
13084
13109
|
yield rowData;
|
|
13085
13110
|
} else {
|
|
@@ -13089,7 +13114,7 @@ async function* rowGeneratorFromCsv(path8, fileConfig) {
|
|
|
13089
13114
|
const keyGenerator = fileConfig.fields[i];
|
|
13090
13115
|
if (!keyGenerator) continue;
|
|
13091
13116
|
const rawValue = keyGenerator.valueTransformer ? keyGenerator.valueTransformer(row[i]) : row[i];
|
|
13092
|
-
rowData[keyGenerator.key] = rawValue === "" ? null : rawValue;
|
|
13117
|
+
rowData[keyGenerator.key] = rawValue === "" ? null : coerceCellValue(rawValue, keyGenerator.type);
|
|
13093
13118
|
}
|
|
13094
13119
|
yield rowData;
|
|
13095
13120
|
}
|
|
@@ -15418,6 +15443,7 @@ export {
|
|
|
15418
15443
|
addDocumentSummaries,
|
|
15419
15444
|
addWhalyFields,
|
|
15420
15445
|
checkCsvHeaderRow,
|
|
15446
|
+
coerceCellValue,
|
|
15421
15447
|
collectPaginated,
|
|
15422
15448
|
countCsvLines,
|
|
15423
15449
|
createCellReference,
|