Comparing version 0.23.0 to 0.23.1
@@ -28,2 +28,3 @@ "use strict"; | ||
const targetIndex = {}, targetArrayIndex = {}, ids = []; | ||
let forcedIndex = 0; | ||
for (let entry of target) { | ||
@@ -33,8 +34,10 @@ const id = entry[this.sourceField]; | ||
if (Array.isArray(id)) { | ||
let index = 0; | ||
for (let _id of id) { | ||
if (targetArrayIndex[_id]) | ||
targetArrayIndex[_id].push(entry); | ||
targetArrayIndex[_id].push({ entry, index }); | ||
else | ||
targetArrayIndex[_id] = [entry]; | ||
targetArrayIndex[_id] = [{ entry, index }]; | ||
ids.push(_id); | ||
index++; | ||
} | ||
@@ -45,7 +48,8 @@ entry[this.sourceField] = []; | ||
if (targetArrayIndex[id]) | ||
targetArrayIndex[id].push(entry); | ||
targetArrayIndex[id].push({ entry, index: forcedIndex }); | ||
else | ||
targetArrayIndex[id] = [entry]; | ||
targetArrayIndex[id] = [{ entry, index: forcedIndex }]; | ||
ids.push(id); | ||
entry[this.targetField] = []; | ||
forcedIndex++; | ||
} | ||
@@ -78,4 +82,4 @@ else { | ||
if (targetArrayIndex[id]) { | ||
for (let subEntry of targetArrayIndex[id]) { | ||
subEntry[this.targetField].push(entry); | ||
for (let { entry: subEntry, index } of targetArrayIndex[id]) { | ||
subEntry[this.targetField][index] = entry; | ||
} | ||
@@ -82,0 +86,0 @@ } |
{ | ||
"name": "api-core", | ||
"version": "0.23.0", | ||
"version": "0.23.1", | ||
"description": "Model-based dynamic multi-level APIs for any provider, plus multiple consumption channels", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -60,5 +60,6 @@ import {ApiQuery, ApiQueryScope, QueryStep} from "./ApiQuery"; | ||
const targetIndex: { [key: string]: any[] } = {}, | ||
targetArrayIndex: { [key: string]: any[] } = {}, | ||
targetArrayIndex: { [key: string]: { entry: any, index: number }[] } = {}, | ||
ids: string[] = []; | ||
let forcedIndex = 0; | ||
for(let entry of target) { | ||
@@ -68,6 +69,8 @@ const id = entry[this.sourceField]; | ||
if(Array.isArray(id)) { | ||
let index = 0; | ||
for(let _id of id) { | ||
if (targetArrayIndex[_id]) targetArrayIndex[_id].push(entry); | ||
else targetArrayIndex[_id] = [entry]; | ||
if (targetArrayIndex[_id]) targetArrayIndex[_id].push({ entry, index }); | ||
else targetArrayIndex[_id] = [{entry, index}]; | ||
ids.push(_id); | ||
index++ | ||
} | ||
@@ -77,6 +80,7 @@ entry[this.sourceField] = []; | ||
else if(this.forceArray) { | ||
if (targetArrayIndex[id]) targetArrayIndex[id].push(entry); | ||
else targetArrayIndex[id] = [entry]; | ||
if (targetArrayIndex[id]) targetArrayIndex[id].push({ entry, index: forcedIndex }); | ||
else targetArrayIndex[id] = [{entry, index: forcedIndex }]; | ||
ids.push(id); | ||
entry[this.targetField] = []; | ||
forcedIndex++ | ||
} | ||
@@ -110,4 +114,4 @@ else { | ||
if(targetArrayIndex[id]) { | ||
for (let subEntry of targetArrayIndex[id]) { | ||
subEntry[this.targetField].push(entry); | ||
for (let { entry: subEntry, index } of targetArrayIndex[id]) { | ||
subEntry[this.targetField][index] = entry; | ||
} | ||
@@ -215,5 +219,5 @@ } | ||
}).catch((e) => { | ||
debug(`failed to execute ${this.method.name} method`, e); | ||
reject(e) | ||
}); | ||
debug(`failed to execute ${this.method.name} method`, e); | ||
reject(e) | ||
}); | ||
}) | ||
@@ -857,2 +861,2 @@ }; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
682111
8366