Skip to content

Commit

Permalink
Bumped v4.6.0
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Sep 14, 2022
1 parent 94fafa0 commit 1237537
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
2 changes: 1 addition & 1 deletion fastify.js
@@ -1,6 +1,6 @@
'use strict'

const VERSION = '4.5.3'
const VERSION = '4.6.0'

const Avvio = require('avvio')
const http = require('http')
Expand Down
53 changes: 13 additions & 40 deletions lib/error-serializer.js
Expand Up @@ -23,14 +23,6 @@ class Serializer {
}
}

asAny (i) {
return JSON.stringify(i)
}

asNull () {
return 'null'
}

asInteger (i) {
if (typeof i === 'bigint') {
return i.toString()
Expand All @@ -47,10 +39,6 @@ class Serializer {
}
}

asIntegerNullable (i) {
return i === null ? 'null' : this.asInteger(i)
}

asNumber (i) {
const num = Number(i)
if (Number.isNaN(num)) {
Expand All @@ -62,54 +50,43 @@ class Serializer {
}
}

asNumberNullable (i) {
return i === null ? 'null' : this.asNumber(i)
}

asBoolean (bool) {
return bool && 'true' || 'false' // eslint-disable-line
}

asBooleanNullable (bool) {
return bool === null ? 'null' : this.asBoolean(bool)
}

asDateTime (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + date.toISOString() + '"'
}
if (typeof date === 'string') {
return '"' + date + '"'
}
throw new Error(`The value "${date}" cannot be converted to a date-time.`)
}

asDateTimeNullable (date) {
return date === null ? 'null' : this.asDateTime(date)
}

asDate (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0, 10) + '"'
}
if (typeof date === 'string') {
return '"' + date + '"'
}
throw new Error(`The value "${date}" cannot be converted to a date.`)
}

asDateNullable (date) {
return date === null ? 'null' : this.asDate(date)
}

asTime (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(11, 19) + '"'
}
if (typeof date === 'string') {
return '"' + date + '"'
}
throw new Error(`The value "${date}" cannot be converted to a time.`)
}

asTimeNullable (date) {
return date === null ? 'null' : this.asTime(date)
}

asString (str) {
const quotes = '"'
if (str instanceof Date) {
Expand All @@ -129,10 +106,6 @@ class Serializer {
}
}

asStringNullable (str) {
return str === null ? 'null' : this.asString(str)
}

// magically escape strings for json
// relying on their charCodeAt
// everything below 32 needs JSON.stringify()
Expand Down Expand Up @@ -200,7 +173,7 @@ class Serializer {
}

json += "\"statusCode\"" + ':'
json += serializer.asNumber.bind(serializer)(obj["statusCode"])
json += serializer.asNumber(obj["statusCode"])
}

if (obj["code"] !== undefined) {
Expand All @@ -212,7 +185,7 @@ class Serializer {
}

json += "\"code\"" + ':'
json += serializer.asString.bind(serializer)(obj["code"])
json += serializer.asString(obj["code"])
}

if (obj["error"] !== undefined) {
Expand All @@ -224,7 +197,7 @@ class Serializer {
}

json += "\"error\"" + ':'
json += serializer.asString.bind(serializer)(obj["error"])
json += serializer.asString(obj["error"])
}

if (obj["message"] !== undefined) {
Expand All @@ -236,7 +209,7 @@ class Serializer {
}

json += "\"message\"" + ':'
json += serializer.asString.bind(serializer)(obj["message"])
json += serializer.asString(obj["message"])
}

json += '}'
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fastify",
"version": "4.5.3",
"version": "4.6.0",
"description": "Fast and low overhead web framework, for Node.js",
"main": "fastify.js",
"type": "commonjs",
Expand Down

0 comments on commit 1237537

Please sign in to comment.