(function(){
var async, getBody, ref$, EitherT, Left, Promise, EitherPromise, bodyParams, out$ = typeof exports != 'undefined' && exports || this;
async = require('fantasy-async');
getBody = async(require('raw-body'));
ref$ = require('fantasy-eithers'), EitherT = ref$.EitherT, Left = ref$.Left;
Promise = require('fantasy-promises');
EitherPromise = EitherT(Promise);
out$.bodyParams = bodyParams = curry$(function(parser, req){
var err;
try {
return getBody(req, {
length: req.headers['content-length'],
encoding: 'utf8',
limit: '1mb'
}).map(parser);
} catch (e$) {
err = e$;
return EitherPromise(new Promise((function(it){
return it(Left(err));
})));
}
});
function curry$(f, bound){
var context,
_curry = function(args) {
return f.length > 1 ? function(){
var params = args ? args.concat() : [];
context = bound ? context || this : this;
return params.push.apply(params, arguments) <
f.length && arguments.length ?
_curry.call(context, params) : f.apply(context, params);
} : f;
};
return _curry();
}
}).call(this);
|