Comparing version 0.1.3 to 0.1.4
48
index.js
@@ -71,2 +71,6 @@ 'use strict'; | ||
"transform": {}, | ||
"timeout": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"outputSchema": { | ||
@@ -108,5 +112,9 @@ "type": "object", | ||
TRANSFORM_ERROR: 'TRANSFORM_ERROR', | ||
TRANSFORM_EMPTY: 'TRANSFORM_EMPTY', | ||
TRANSFORM_TIMEOUT: 'TRANSFORM_TIMEOUT', | ||
ERROR: 'ERROR' | ||
}; | ||
var LOCAL_ERRORS = [JsonBeat.STATUS.TRANSFORM_TIMEOUT, JsonBeat.STATUS.TRANSFORM_EMPTY]; | ||
var private_push = function(params, context, data, opts, callback) { | ||
@@ -139,3 +147,4 @@ var self = this; | ||
name: params.name, | ||
skipHandlingTransformError: params.skipHandlingTransformError | ||
skipHandlingTransformError: params.skipHandlingTransformError, | ||
timeout: params.timeout | ||
}, data, params.transform).then(function(output) { | ||
@@ -242,6 +251,8 @@ if (output.status === JsonBeat.STATUS.OK) { | ||
if (fcall) { | ||
if (typeof(fcall) === 'object' && typeof(fcall.then) === 'function') { | ||
debug.enabled && debug('invokeTransform() - return a Promise'); | ||
} else { | ||
debug.enabled && debug('invokeTransform() - return a value'); | ||
if (debug.enabled) { | ||
if (typeof(fcall) === 'object' && typeof(fcall.then) === 'function') { | ||
debug.enabled && debug('invokeTransform() - return a Promise'); | ||
} else { | ||
debug.enabled && debug('invokeTransform() - return a value'); | ||
} | ||
} | ||
@@ -251,20 +262,18 @@ resolve(fcall); | ||
debug.enabled && debug('invokeTransform() - invalid async function'); | ||
reject({ message: 'transform() must have callback or return a value/promise' }); | ||
reject({ status: JsonBeat.STATUS.TRANSFORM_EMPTY }); | ||
} | ||
}); | ||
if (that.skipHandlingTransformError !== true) { | ||
if (that.timeout && that.timeout > 0) { | ||
fPromise = fPromise.timeout(that.timeout); | ||
} | ||
fPromise = fPromise.then(function(result) { | ||
return { | ||
name: that.name, | ||
status: JsonBeat.STATUS.OK, | ||
result: result | ||
} | ||
return { name: that.name, status: JsonBeat.STATUS.OK, result: result } | ||
}).catch(Promise.TimeoutError, function(error) { | ||
return Promise.reject({ status: JsonBeat.STATUS.TRANSFORM_TIMEOUT }); | ||
}).catch(function(error) { | ||
debug.enabled && debug('invokeTransform() - error: %s', JSON.stringify(error)); | ||
return { | ||
name: that.name, | ||
status: JsonBeat.STATUS.TRANSFORM_ERROR, | ||
data: data, | ||
error: error | ||
} | ||
var status = error && error.status; | ||
if (LOCAL_ERRORS.indexOf(status) < 0) status = JsonBeat.STATUS.TRANSFORM_ERROR; | ||
return { name: that.name, status: status, data: data, error: error } | ||
}); | ||
@@ -294,2 +303,7 @@ } | ||
} | ||
if (ret.status === JsonBeat.STATUS.OK && typeof(ret.result) === 'undefined') { | ||
delete ret.result; | ||
ret.status = JsonBeat.STATUS.TRANSFORM_EMPTY; | ||
ret.data = data; | ||
} | ||
return ret; | ||
@@ -296,0 +310,0 @@ } |
{ | ||
"name": "jsonbeat", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A step in JSON transforming flow", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13648
290
0