syncano-server
Advanced tools
Comparing version 0.8.2-2 to 0.8.2-3
@@ -180,4 +180,2 @@ 'use strict'; | ||
function resolveRelatedModels(shouldResolve) { | ||
var _this3 = this; | ||
if (shouldResolve === false) { | ||
@@ -221,3 +219,3 @@ return; | ||
var load = new Data(); | ||
var load = new Data(self.instance); | ||
var ids = references.map(function (item) { | ||
@@ -230,3 +228,3 @@ return item.value; | ||
if (target === 'user') { | ||
load._url = _this3._getInstanceURL(instance.instanceName) + '/users/'; | ||
load._url = self._getInstanceURL(instance.instanceName) + '/users/'; | ||
} | ||
@@ -361,6 +359,6 @@ | ||
value: function firstOrFail() { | ||
var _this4 = this; | ||
var _this3 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this4.first().then(function (object) { | ||
_this3.first().then(function (object) { | ||
return object ? resolve(object) : reject(new _errors.NotFoundError()); | ||
@@ -384,3 +382,3 @@ }).catch(function () { | ||
value: function firstOrCreate(attributes) { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -392,3 +390,3 @@ var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return this.where(query).firstOrFail().catch(function () { | ||
return _this5.create((0, _lodash6.default)(attributes, values)); | ||
return _this4.create((0, _lodash6.default)(attributes, values)); | ||
}); | ||
@@ -408,3 +406,3 @@ } | ||
value: function updateOrCreate(attributes) { | ||
var _this6 = this; | ||
var _this5 = this; | ||
@@ -416,5 +414,5 @@ var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return this.where(query).firstOrFail().then(function (res) { | ||
return _this6.update(res.id, values); | ||
return _this5.update(res.id, values); | ||
}).catch(function () { | ||
return _this6.create((0, _lodash6.default)(attributes, values)); | ||
return _this5.create((0, _lodash6.default)(attributes, values)); | ||
}); | ||
@@ -468,6 +466,6 @@ } | ||
value: function findOrFail(ids) { | ||
var _this7 = this; | ||
var _this6 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this7.find(ids).then(function (response) { | ||
_this6.find(ids).then(function (response) { | ||
var shouldThrow = Array.isArray(ids) ? response.length !== ids.length : response === null; | ||
@@ -539,3 +537,3 @@ | ||
value: function where(column, operator, value) { | ||
var _this8 = this; | ||
var _this7 = this; | ||
@@ -549,3 +547,3 @@ if (Array.isArray(column)) { | ||
return _this8.where(itemColumn, itemOperator, itemValue); | ||
return _this7.where(itemColumn, itemOperator, itemValue); | ||
}); | ||
@@ -738,3 +736,3 @@ | ||
value: function update(id, body) { | ||
var _this9 = this; | ||
var _this8 = this; | ||
@@ -754,5 +752,5 @@ var isQueryUpdate = (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id !== null && !Array.isArray(id); | ||
fetchObject = _this9._batchFetchObject(ids); | ||
fetchObject = _this8._batchFetchObject(ids); | ||
return _this9.fetch(fetchObject.url, fetchObject); | ||
return _this8.fetch(fetchObject.url, fetchObject); | ||
}); | ||
@@ -783,3 +781,3 @@ } | ||
value: function _delete(id) { | ||
var _this10 = this; | ||
var _this9 = this; | ||
@@ -798,5 +796,5 @@ var isQueryDelete = id === undefined; | ||
fetchObject = _this10._batchFetchObject(ids); | ||
fetchObject = _this9._batchFetchObject(ids); | ||
return _this10.fetch(fetchObject.url, fetchObject); | ||
return _this9.fetch(fetchObject.url, fetchObject); | ||
}); | ||
@@ -803,0 +801,0 @@ } |
@@ -28,3 +28,4 @@ 'use strict'; | ||
callback = _ref.callback, | ||
levels = _ref.levels; | ||
levels = _ref.levels, | ||
config = _ref.config; | ||
@@ -37,2 +38,4 @@ _classCallCheck(this, Logger); | ||
this.config = config; | ||
levels.forEach(function (level) { | ||
@@ -82,15 +85,20 @@ _this[level] = _this._makePrinter.bind(_this, level); | ||
console.log(level + ':', time, this._scope, args, diff, 'ms'); | ||
if (this.config !== false) { | ||
console.log(level + ':', time, this._scope, args, diff, 'ms'); | ||
} | ||
return now; | ||
} | ||
// TODO: this is not used anyhow right now | ||
}, { | ||
key: '_shouldLog', | ||
value: function _shouldLog(scope) { | ||
if (ARGS && ARGS.DEBUG) { | ||
if (typeof ARGS.DEBUG === 'boolean') { | ||
return ARGS.DEBUG; | ||
if (this.config) { | ||
if (typeof this.config === 'boolean') { | ||
return this.config; | ||
} | ||
var vars = ARGS.DEBUG.split(','); | ||
var vars = this.config.split(','); | ||
var excluded = vars.filter(function (item) { | ||
@@ -148,2 +156,3 @@ return item.startsWith('-'); | ||
scope: scope, | ||
config: logger.config, | ||
callback: logger._callback, | ||
@@ -150,0 +159,0 @@ levels: logger._levels || LEVELS |
@@ -71,2 +71,4 @@ 'use strict'; | ||
_logger2.default.config = ctx.meta ? ctx.meta.debug : ''; | ||
return { | ||
@@ -73,0 +75,0 @@ _class: _class, |
{ | ||
"name": "syncano-server", | ||
"version": "0.8.2-2", | ||
"version": "0.8.2-3", | ||
"description": "A library to intereact with the Syncano API on a server side", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -155,3 +155,3 @@ import querystring from 'querystring' | ||
const {target} = references[0] | ||
const load = new Data() | ||
const load = new Data(self.instance) | ||
let ids = references.map(item => item.value) | ||
@@ -162,3 +162,3 @@ | ||
if (target === 'user') { | ||
load._url = `${this._getInstanceURL(instance.instanceName)}/users/` | ||
load._url = `${self._getInstanceURL(instance.instanceName)}/users/` | ||
} | ||
@@ -165,0 +165,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
class Logger { | ||
constructor ({scope, callback, levels}) { | ||
constructor ({scope, callback, levels, config}) { | ||
this._start = null | ||
@@ -17,2 +17,4 @@ this._scope = scope | ||
this.config = config | ||
levels.forEach(level => { | ||
@@ -52,3 +54,5 @@ this[level] = this._makePrinter.bind(this, level) | ||
console.log(`${level}:`, time, this._scope, args, diff, 'ms') | ||
if (this.config !== false) { | ||
console.log(`${level}:`, time, this._scope, args, diff, 'ms') | ||
} | ||
@@ -58,9 +62,10 @@ return now | ||
// TODO: this is not used anyhow right now | ||
_shouldLog (scope) { | ||
if (ARGS && ARGS.DEBUG) { | ||
if (typeof ARGS.DEBUG === 'boolean') { | ||
return ARGS.DEBUG | ||
if (this.config) { | ||
if (typeof this.config === 'boolean') { | ||
return this.config | ||
} | ||
const vars = ARGS.DEBUG.split(',') | ||
const vars = this.config.split(',') | ||
const excluded = vars | ||
@@ -111,2 +116,3 @@ .filter(item => item.startsWith('-')) | ||
scope, | ||
config: logger.config, | ||
callback: logger._callback, | ||
@@ -113,0 +119,0 @@ levels: logger._levels || LEVELS |
@@ -27,2 +27,4 @@ import Data from './data' | ||
Logger.config = ctx.meta ? ctx.meta.debug : '' | ||
return { | ||
@@ -29,0 +31,0 @@ _class, |
Sorry, the diff of this file is not supported yet
889258
3746