Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@fastify/fast-json-stringify-compiler
Advanced tools
Build and manage the fast-json-stringify instances for the fastify framework
Build and manage the fast-json-stringify
instances for the Fastify framework.
This package is responsible for compiling the application's response
JSON schemas into optimized functions to speed up the response time.
@fastify/fast-json-stringify-compiler | fast-json-stringify | Supported fastify |
---|---|---|
v1.x | v3.x | ^3.x |
v2.x | v3.x | ^4.x |
v3.x | v4.x | ^4.x |
v4.x | v5.x | ^4.x |
The fast-json-stringify
configuration is the default one. You can check the default settings in the fast-json-stringify
option documentation.
You can also override the default configuration by passing the serializerOpts
configuration to the Fastify instance.
This module is already used as default by Fastify. If you need to provide to your server instance a different version, refer to the official doc.
fast-json-stringify@v4.1.0
introduces the standalone feature that lets you pre-compile your schemas and use them in your application for a faster startup.
To use this feature, you must be aware of the following:
Fastify helps you to generate the serialization schemas functions and it is your choice to save them where you want.
To accomplish this, you must use a new compiler: @fastify/fast-json-stringify-compiler/standalone
.
You must provide 2 parameters to this compiler:
readMode: false
: a boolean to indicate that you want to generate the schemas functions string.storeFunction
" a sync function that must store the source code of the schemas functions. You may provide an async function too, but you must manage errors.When readMode: false
, the compiler is meant to be used in development ONLY.
const { StandaloneSerializer } = require('@fastify/fast-json-stringify-compiler')
const factory = StandaloneSerializer({
readMode: false,
storeFunction (routeOpts, schemaSerializationCode) {
// routeOpts is like: { schema, method, url, httpStatus }
// schemaSerializationCode is a string source code that is the compiled schema function
const fileName = generateFileName(routeOpts)
fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
}
})
const app = fastify({
jsonShorthand: false,
schemaController: {
compilersFactory: {
buildSerializer: factory
}
}
})
// ... add all your routes with schemas ...
app.ready().then(() => {
// at this stage all your schemas are compiled and stored in the file system
// now it is important to turn off the readMode
})
At this stage, you should have a file for every route's schema.
To use them, you must use the @fastify/fast-json-stringify-compiler/standalone
with the parameters:
readMode: true
: a boolean to indicate that you want to read and use the schemas functions string.restoreFunction
" a sync function that must return a function to serialize the route's payload.Important keep away before you continue reading the documentation:
readMode: true
, the application schemas are not compiled (they are ignored). So, if you change your schemas, you must recompile them!routeOpts
object. You may use the routeOpts.schema.$id
field to do so, it is up to you to define a unique schema identifier.const { StandaloneSerializer } = require('@fastify/fast-json-stringify-compiler')
const factory = StandaloneSerializer({
readMode: true,
restoreFunction (routeOpts) {
// routeOpts is like: { schema, method, url, httpStatus }
const fileName = generateFileName(routeOpts)
return require(path.join(__dirname, fileName))
}
})
const app = fastify({
jsonShorthand: false,
schemaController: {
compilersFactory: {
buildSerializer: factory
}
}
})
// ... add all your routes with schemas as before...
app.listen({ port: 3000 })
This module provides a factory function to produce Serializer Compilers functions.
Licensed under MIT.
FAQs
Build and manage the fast-json-stringify instances for the fastify framework
The npm package @fastify/fast-json-stringify-compiler receives a total of 1,331,501 weekly downloads. As such, @fastify/fast-json-stringify-compiler popularity was classified as popular.
We found that @fastify/fast-json-stringify-compiler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.