New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fastify-accepts-serializer

Package Overview
Dependencies
Maintainers
8
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.0.1 to 3.1.0

.github/dependabot.yml

8

index.js

@@ -9,2 +9,5 @@ 'use strict'

function acceptsSerializerPlugin (fastify, options, next) {
const serializerCache = {}
options.cache = serializerCache
const globalSerializerManager = SerializerManager.build(options)

@@ -21,6 +24,3 @@

if (!reply.serializer) {
reply.serializer = {}
}
reply.serializer.cache = serializerCache
reply.serializer.serializerManager = SerializerManager.expand(reply.serializer, globalSerializerManager)

@@ -27,0 +27,0 @@

{
"name": "fastify-accepts-serializer",
"version": "3.0.1",
"version": "3.1.0",
"description": "Serializer according to the accept header",

@@ -8,2 +8,3 @@ "main": "index.js",

"lint": "standard --verbose | snazzy",
"lint:fix": "standard --fix",
"unit": "tap test/test.js",

@@ -27,4 +28,4 @@ "test": "npm run lint && tap test/test.js"

"protobufjs": "^6.8.8",
"snazzy": "^8.0.0",
"standard": "^14.0.0",
"snazzy": "^9.0.0",
"standard": "^16.0.2",
"tap": "^14.10.7",

@@ -35,4 +36,4 @@ "yamljs": "^0.3.0"

"fastify-accepts": "^2.0.0",
"fastify-plugin": "^2.0.0"
"fastify-plugin": "^3.0.0"
}
}

@@ -17,3 +17,3 @@ 'use strict'

this.serializers = configuration.serializers
this.cache = {}
this.cache = configuration.cache
}

@@ -23,8 +23,9 @@

const cacheValue = this.cache[types]
if (cacheValue) return cacheValue
for (var i = 0; i < types.length; i++) {
for (let i = 0; i < types.length; i++) {
const type = types[i]
for (var j = 0; j < this.serializers.length; j++) {
for (let j = 0; j < this.serializers.length; j++) {
const serializer = this.serializers[j]

@@ -46,3 +47,2 @@ if (serializer.isAble(type)) {

SerializerManager.build = function (options) {
options = options || {}
options.serializers = options.serializers || []

@@ -53,3 +53,2 @@ return SerializerManager.expand(options, { serializers: [] })

SerializerManager.expand = function (options, fallbackSerializer) {
options = options || {}
options.serializers = options.serializers || []

@@ -59,3 +58,4 @@

return new SerializerManager({
serializers: serializers.concat(fallbackSerializer.serializers)
serializers: serializers.concat(fallbackSerializer.serializers),
cache: options.cache
})

@@ -62,0 +62,0 @@ }

@@ -368,1 +368,52 @@ 'use strict'

})
test('serializer cache', t => {
t.plan(1)
const fastify = Fastify()
fastify.register(plugin, {
serializers: [
{
regex: /^application\/cache$/,
serializer: (body) => body
}
]
})
t.test('it shoud populate cache', t => {
t.plan(8)
fastify.get('/request', function (req, reply) {
t.strictDeepEqual(Object.keys(reply.serializer.cache), ['application/cache'])
reply.send('cache')
})
fastify.inject({
method: 'GET',
url: '/request',
payload: {},
headers: {
accept: 'application/cache'
}
}, (err, res) => {
t.error(err)
t.strictDeepEqual(res.headers['content-type'], 'application/cache')
t.strictDeepEqual(res.payload, 'cache')
})
fastify.inject({
method: 'GET',
url: '/request',
payload: {},
headers: {
accept: 'application/cache'
}
}, (err, res) => {
t.error(err)
t.strictDeepEqual(res.headers['content-type'], 'application/cache')
t.strictDeepEqual(res.payload, 'cache')
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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