syncano-server
Advanced tools
Comparing version 0.7.2-24 to 0.7.2-25
@@ -90,4 +90,6 @@ 'use strict'; | ||
return new Promise(function (resolve, reject) { | ||
request(_this2.url()); | ||
function request(url) { | ||
fetch(url).then(saveToResult).then(loadNextPage).then(resolveRelatedModels).then(resolveIfFinished).catch(function (err) { | ||
fetch(url).then(saveToResult).then(loadNextPage).then(resolveRelatedModels).then(replaceCustomTypesWithValue).then(resolveIfFinished).catch(function (err) { | ||
return reject(err); | ||
@@ -193,2 +195,26 @@ }); | ||
function replaceCustomTypesWithValue(shouldResolve) { | ||
if (shouldResolve === false) { | ||
return; | ||
} | ||
result = result.map(function (item) { | ||
Object.keys(item).forEach(function (key) { | ||
var value = item[key]; | ||
var isObject = value instanceof Object && !Array.isArray(value); | ||
var hasType = isObject && value.type !== undefined; | ||
var hasTarget = isObject && value.target !== undefined; | ||
var hasValue = isObject && value.value !== undefined; | ||
if (isObject && hasType && hasTarget && hasValue) { | ||
item[key] = value.value; | ||
} | ||
}); | ||
return item; | ||
}); | ||
return true; | ||
} | ||
function resolveIfFinished(shouldResolve) { | ||
@@ -203,4 +229,2 @@ if (shouldResolve) { | ||
} | ||
request(_this2.url()); | ||
}); | ||
@@ -207,0 +231,0 @@ } |
@@ -13,3 +13,7 @@ 'use strict'; | ||
return global.META ? global.META[metaVar] : fallback; | ||
try { | ||
return META[metaVar]; | ||
} catch (err) { | ||
return fallback; | ||
} | ||
} | ||
@@ -16,0 +20,0 @@ |
{ | ||
"name": "syncano-server", | ||
"version": "0.7.2-24", | ||
"version": "0.7.2-25", | ||
"description": "A library to intereact with the Syncano API on a server side", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -43,2 +43,4 @@ import querystring from 'querystring' | ||
return new Promise((resolve, reject) => { | ||
request(this.url()) | ||
function request(url) { | ||
@@ -49,2 +51,3 @@ fetch(url) | ||
.then(resolveRelatedModels) | ||
.then(replaceCustomTypesWithValue) | ||
.then(resolveIfFinished) | ||
@@ -146,2 +149,26 @@ .catch(err => reject(err)) | ||
function replaceCustomTypesWithValue(shouldResolve) { | ||
if (shouldResolve === false) { | ||
return | ||
} | ||
result = result.map(item => { | ||
Object.keys(item).forEach(key => { | ||
const value = item[key] | ||
const isObject = value instanceof Object && !Array.isArray(value) | ||
const hasType = isObject && value.type !== undefined | ||
const hasTarget = isObject && value.target !== undefined | ||
const hasValue = isObject && value.value !== undefined | ||
if (isObject && hasType && hasTarget && hasValue) { | ||
item[key] = value.value | ||
} | ||
}) | ||
return item | ||
}) | ||
return true | ||
} | ||
function resolveIfFinished(shouldResolve) { | ||
@@ -156,4 +183,2 @@ if (shouldResolve) { | ||
} | ||
request(this.url()) | ||
}) | ||
@@ -160,0 +185,0 @@ } |
@@ -6,3 +6,7 @@ function getMeta(envVar, metaVar, fallback = null) { | ||
return global.META ? global.META[metaVar] : fallback | ||
try { | ||
return META[metaVar] | ||
} catch (err) { | ||
return fallback | ||
} | ||
} | ||
@@ -9,0 +13,0 @@ |
Sorry, the diff of this file is not supported yet
530254
2065