|
@@ -64,8 +64,13 @@ function setByPath(target, path, value) {
|
|
|
let cursor = target;
|
|
let cursor = target;
|
|
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
|
const key = keys[i];
|
|
const key = keys[i];
|
|
|
- if (cursor[key] === null || typeof cursor[key] !== 'object') {
|
|
|
|
|
|
|
+ const existing = cursor[key];
|
|
|
|
|
+ if (existing === undefined) {
|
|
|
cursor[key] = {};
|
|
cursor[key] = {};
|
|
|
|
|
+ } else if (existing === null || typeof existing !== 'object' || Array.isArray(existing)) {
|
|
|
|
|
+ const held = Array.isArray(existing) ? 'an array' : existing === null ? 'null' : 'a ' + typeof existing;
|
|
|
|
|
+ throw new Error('Cannot set "' + path + '": "' + keys.slice(0, i + 1).join('.') +
|
|
|
|
|
+ '" already holds ' + held + ', which would be overwritten');
|
|
|
}
|
|
}
|
|
|
cursor = cursor[key];
|
|
cursor = cursor[key];
|
|
|
}
|
|
}
|
|
@@ -98,9 +103,12 @@ async function execute(config, input, context) {
|
|
|
if (mode === 'only-set') {
|
|
if (mode === 'only-set') {
|
|
|
output = {};
|
|
output = {};
|
|
|
} else {
|
|
} else {
|
|
|
- output = source !== null && typeof source === 'object' && !Array.isArray(source)
|
|
|
|
|
- ? JSON.parse(JSON.stringify(source))
|
|
|
|
|
- : {};
|
|
|
|
|
|
|
+ if (source === null || typeof source !== 'object' || Array.isArray(source)) {
|
|
|
|
|
+ const got = Array.isArray(source) ? 'an array' : source === null ? 'null' : 'a ' + typeof source;
|
|
|
|
|
+ throw new Error('Set Fields: keep-all needs an object input, got ' + got +
|
|
|
|
|
+ '. Use only-set mode, or Split Out first.');
|
|
|
|
|
+ }
|
|
|
|
|
+ output = JSON.parse(JSON.stringify(source));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (const field of fields) {
|
|
for (const field of fields) {
|