Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-accepts-serializer

Package Overview
Dependencies
Maintainers
10
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-accepts-serializer - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

14

index.js

@@ -23,4 +23,14 @@ 'use strict'

reply.serializer.cache = serializerCache
reply.serializer.serializerManager = SerializerManager.expand(reply.serializer, globalSerializerManager)
if (reply.context.config.serializers) {
// keep route level cache in config to prevent messing with global cache
reply.context.config.serializers.cache = Object.assign({}, reply.context.config.serializers.cache)
reply.serializer.serializerManager = SerializerManager.expand({
serializers: reply.context.config.serializers,
cache: reply.context.config.serializers.cache
}, globalSerializerManager)
} else {
// use global serializer
reply.serializer.cache = serializerCache
reply.serializer.serializerManager = SerializerManager.expand(reply.serializer, globalSerializerManager)
}

@@ -27,0 +37,0 @@ const serializerManager = reply.serializer.serializerManager

6

package.json
{
"name": "fastify-accepts-serializer",
"version": "3.1.0",
"version": "3.2.0",
"description": "Serializer according to the accept header",

@@ -24,5 +24,5 @@ "main": "index.js",

"fastify": "^3.0.0",
"msgpack5": "^4.2.1",
"msgpack5": "^4.3.0",
"pre-commit": "^1.2.2",
"protobufjs": "^6.8.8",
"protobufjs": "^6.10.2",
"snazzy": "^9.0.0",

@@ -29,0 +29,0 @@ "standard": "^16.0.2",

@@ -45,10 +45,8 @@ # fastify-accepts-serializer

const config = {
serializer: {
serializers: [
{
regex: /^application\/x-protobuf$/,
serializer: body => AwesomeMessage.encode(AwesomeMessage.create(body)).finish()
}
]
}
serializers: [
{
regex: /^application\/x-protobuf$/,
serializer: body => AwesomeMessage.encode(AwesomeMessage.create(body)).finish()
}
]
}

@@ -59,3 +57,2 @@

})
```

@@ -62,0 +59,0 @@ ## Behaviour

@@ -318,2 +318,91 @@ 'use strict'

test('serializer per route through route option', t => {
t.plan(3)
const fastify = Fastify()
fastify.register(plugin, {
serializers: [
{
regex: /^application\/yaml$/,
serializer: body => YAML.stringify(body)
}
],
default: 'application/yaml'
})
const config = {
serializers: [
{
regex: /^application\/x-protobuf$/,
serializer: body => AwesomeMessage.encode(AwesomeMessage.create(body)).finish()
}
]
}
fastify.get('/request', { config }, function (req, reply) {
reply.send({ pippo: 'pluto' })
})
fastify.get('/request2', function (req, reply) {
reply.send('my-custom-string')
})
fastify.get('/request3', function (req, reply) {
reply
.serializer(_ => 'foo-bar-baz')
.send({ pippo: 'pluto' })
})
t.test('application/x-protobuf -> protobuf', t => {
t.plan(3)
fastify.inject({
method: 'GET',
url: '/request',
payload: {},
headers: {
accept: 'application/x-protobuf'
}
}, (err, res) => {
t.error(err)
t.strictDeepEqual(res.headers['content-type'], 'application/x-protobuf')
t.strictDeepEqual(res.payload, AwesomeMessage.encode(AwesomeMessage.create({ pippo: 'pluto' })).finish().toString())
})
})
t.test('route level should not pullute global cache', t => {
t.plan(3)
fastify.inject({
method: 'GET',
url: '/request2',
payload: {},
headers: {
accept: 'application/yaml'
}
}, (err, res) => {
t.error(err)
t.strictDeepEqual(res.headers['content-type'], 'application/yaml')
t.strictDeepEqual(res.payload, 'my-custom-string')
})
})
t.test('overwrite by fastify reply', t => {
t.plan(3)
fastify.inject({
method: 'GET',
url: '/request3',
payload: {},
headers: {
accept: 'application/yaml'
}
}, (err, res) => {
t.error(err)
t.strictDeepEqual(res.headers['content-type'], 'application/yaml')
t.strictDeepEqual(res.payload, 'foo-bar-baz')
})
})
})
test('serializer without conf', t => {

@@ -320,0 +409,0 @@ t.plan(2)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc