(function(){
var STATUS_CODES, Readable, Promise, Result;
STATUS_CODES = require('http').STATUS_CODES;
Readable = require('stream').Readable;
require('fantasy-streams');
Promise = require('fantasy-promises');
module.exports = Result = (function(){
Result.displayName = 'Result';
var prototype = Result.prototype, constructor = Result;
function Result(body, statusCode, status, headers){
var this$ = this instanceof ctor$ ? this : new ctor$;
this$.body = body;
this$.statusCode = statusCode;
this$.status = status;
this$.headers = headers;
return this$;
} function ctor$(){} ctor$.prototype = prototype;
Result.simple = curry$(function(code, body){
return Result(Readable.of(body), code, STATUS_CODES[code], {
'content-length': body.length,
'content-type': 'text/plain'
});
});
Result.ok = function(){
return Promise.of(this.simple(200).apply(this, arguments));
};
Result.notFound = function(){
return Promise.of(this.simple(404).apply(this, arguments));
};
Result.error = function(){
return Promise.of(this.simple(500).apply(this, arguments));
};
Result.redirect = function(url, code){
code == null && (code = 302);
return Promise.of(Result(Readable.empty(), code, null, {
location: url
}));
};
prototype.withHeaders = function(more){
import$(this.headers, more);
return this;
};
return Result;
}());
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();
}
function import$(obj, src){
var own = {}.hasOwnProperty;
for (var key in src) Eif (own.call(src, key)) obj[key] = src[key];
return obj;
}
}).call(this);
|