response-objects
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "response-objects", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "simple value objects representing HTTP responses", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -30,11 +30,13 @@ import status = require("statuses"); | ||
let bodyCreator: BodyCreator = (code, body) => body != null ? body : (status[code] || `Unknown status for ${code}`) | ||
export const setBodyCreator = (fn: BodyCreator) => { bodyCreator = fn; } | ||
const _setBodyCreator = (fn: BodyCreator) => { bodyCreator = fn; } | ||
export const MARKER = Symbol.for("@@response-objects/MARKER"); | ||
const _MARKER = Symbol.for("@@response-objects/MARKER"); | ||
const proto: ResponseObject = { toJSON, toString, status: 0, statusCode: 0, headers: {}, [MARKER]: true }; | ||
export { _MARKER as MARKER, _setBodyCreator as setBodyCreator } | ||
const proto: ResponseObject = { toJSON, toString, status: 0, statusCode: 0, headers: {}, [_MARKER]: true }; | ||
function createResponse (code: number): RConstructor { | ||
const name = getName(code) | ||
return _setName(function Response (body?: any, headers?: object) { | ||
if (body && body[MARKER]) throw new Error(`Object is already a response: ${JSON.stringify(body)}`); | ||
if (body && body[_MARKER]) throw new Error(`Object is already a response: ${JSON.stringify(body)}`); | ||
return _decorate(Object.create(proto), code, body, headers); | ||
@@ -48,3 +50,3 @@ }, name); | ||
return _setName(function ErrorResponse (body?: any, headers?: object) { | ||
if (body && body[MARKER]) throw new Error(`Object is already a response: ${JSON.stringify(body)}`); | ||
if (body && body[_MARKER]) throw new Error(`Object is already a response: ${JSON.stringify(body)}`); | ||
const err = Object.create(errProto); | ||
@@ -210,2 +212,5 @@ _decorate(err, code, body, headers); | ||
export const NetworkAuthenticationRequired = createErrorResponse(511) | ||
export const setBodyCreator = _setBodyCreator | ||
export const MARKER = _MARKER | ||
} | ||
@@ -212,0 +217,0 @@ |
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
69856
690
0