response-objects
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -19,4 +19,5 @@ declare function R_(code: number, body?: any, headers?: any): ResponseObject; | ||
export declare type BodyCreator = (code: number, body?: any, headers?: object) => any; | ||
export declare const setBodyCreator: (fn: BodyCreator) => void; | ||
export declare const MARKER: symbol; | ||
declare const _setBodyCreator: (fn: BodyCreator) => void; | ||
declare const _MARKER: symbol; | ||
export { _MARKER as MARKER, _setBodyCreator as setBodyCreator }; | ||
export declare type RConstructor = (body?: any, headers?: object) => ResponseObject; | ||
@@ -149,2 +150,4 @@ export declare type RErrorConstructor = (body?: any, headers?: object) => ErrorResponseObject; | ||
const NetworkAuthenticationRequired: RErrorConstructor; | ||
const setBodyCreator: (fn: BodyCreator) => void; | ||
const MARKER: symbol; | ||
} |
@@ -12,9 +12,11 @@ "use strict"; | ||
let bodyCreator = (code, body) => body != null ? body : (status[code] || `Unknown status for ${code}`); | ||
exports.setBodyCreator = (fn) => { bodyCreator = fn; }; | ||
exports.MARKER = Symbol.for("@@response-objects/MARKER"); | ||
const proto = { toJSON, toString, status: 0, statusCode: 0, headers: {}, [exports.MARKER]: true }; | ||
const _setBodyCreator = (fn) => { bodyCreator = fn; }; | ||
exports.setBodyCreator = _setBodyCreator; | ||
const _MARKER = Symbol.for("@@response-objects/MARKER"); | ||
exports.MARKER = _MARKER; | ||
const proto = { toJSON, toString, status: 0, statusCode: 0, headers: {}, [_MARKER]: true }; | ||
function createResponse(code) { | ||
const name = getName(code); | ||
return _setName(function Response(body, headers) { | ||
if (body && body[exports.MARKER]) | ||
if (body && body[_MARKER]) | ||
throw new Error(`Object is already a response: ${JSON.stringify(body)}`); | ||
@@ -28,3 +30,3 @@ return _decorate(Object.create(proto), code, body, headers); | ||
return _setName(function ErrorResponse(body, headers) { | ||
if (body && body[exports.MARKER]) | ||
if (body && body[_MARKER]) | ||
throw new Error(`Object is already a response: ${JSON.stringify(body)}`); | ||
@@ -177,2 +179,4 @@ const err = Object.create(errProto); | ||
R_.NetworkAuthenticationRequired = createErrorResponse(511); | ||
R_.setBodyCreator = _setBodyCreator; | ||
R_.MARKER = _MARKER; | ||
})(R_ || (R_ = {})); | ||
@@ -179,0 +183,0 @@ function _decorate(resp, code, body, headers) { |
{ | ||
"name": "response-objects", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "simple value objects representing HTTP responses", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
70099
697