Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mikilukasik committed Nov 7, 2024
1 parent 8fccd1f commit 3f8361e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dist/types/WorkspacePreset.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ export type FieldMappingRule = FieldSource & {
};
export type JsonInputConfig = ({
asJsonFile: true;
asJsonPayload: boolean;
asJsonPayload?: false;
} | {
asJsonFile: boolean;
asJsonPayload: true;
filenameSource: FieldSource;
savePayloadAsJsonFile: boolean;
}) & {
parsers: {
targetIndexName: string;
Expand Down
7 changes: 5 additions & 2 deletions dist/utils/mapObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const flattenObjOrArr = (obj, path, keys, separator) => {
const getSourceValue = (source, sourceConfig, targetField, mappedObject) => {
if ("method" in sourceConfig && sourceConfig.method) {
if (sourceConfig.method === "flattenObject") {
flattenObjOrArr(mappedObject, targetField, sourceConfig.keys, sourceConfig.separator);
flattenObjOrArr(mappedObject || {}, targetField, sourceConfig.keys, sourceConfig.separator);
return;
}
else if (sourceConfig.method === "concat") {
Expand All @@ -89,7 +89,10 @@ const getSourceValue = (source, sourceConfig, targetField, mappedObject) => {
throw new Error(`Method "${sourceConfig.method}" not found.`);
}
// Call method if it exists in the methods map
return methods[sourceConfig.method]({ targetField, mappedObject });
return methods[sourceConfig.method]({
targetField,
mappedObject: mappedObject || {},
});
}
//
}
Expand Down
4 changes: 3 additions & 1 deletion src/types/WorkspacePreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ export type FieldMappingRule = FieldSource & {
export type JsonInputConfig = (
| {
asJsonFile: true;
asJsonPayload: boolean;
asJsonPayload?: false;
}
| {
asJsonFile: boolean;
asJsonPayload: true;
filenameSource: FieldSource;
savePayloadAsJsonFile: boolean;
}
) & {
parsers: {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/mapObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const getSourceValue = (
if ("method" in sourceConfig && sourceConfig.method) {
if (sourceConfig.method === "flattenObject") {
flattenObjOrArr(
mappedObject!,
mappedObject || {},
targetField!,
sourceConfig.keys,
sourceConfig.separator
Expand All @@ -133,7 +133,10 @@ export const getSourceValue = (
}

// Call method if it exists in the methods map
return methods[sourceConfig.method]({ targetField, mappedObject });
return methods[sourceConfig.method]({
targetField,
mappedObject: mappedObject || {},
});
}
//
} else if ("sourceField" in sourceConfig) {
Expand Down

0 comments on commit 3f8361e

Please sign in to comment.