{"name":"@fastify/fast-json-stringify-compiler","version":"4.2.0","keywords":[],"author":{"url":"https://github.com/Eomm","name":"Manuel Spigolon","email":"manuel.spigolon@nearform.com"},"license":"MIT","_id":"@fastify/fast-json-stringify-compiler@4.2.0","maintainers":[{"name":"galvez","email":"jonasgalvez@gmail.com"},{"name":"simenb","email":"sbekkhus91@gmail.com"},{"name":"coopflow","email":"community@coopflow.com"},{"name":"simoneb","email":"simone.busoli@gmail.com"},{"name":"rafaelgss","email":"rafael.nunu@hotmail.com"},{"name":"starptech","email":"deusdustin@gmail.com"},{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"allevo","email":"tomallevi@gmail.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"zekth","email":"vince.legoff@gmail.com"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"fox1t","email":"maksim@sinik.it"},{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"},{"name":"airhorns","email":"harry@harry.me"},{"name":"kibertoad","email":"iselwin@gmail.com"},{"name":"climba03003","email":"kaka@kakawebsitedemo.com"}],"homepage":"https://github.com/fastify/fast-json-stringify-compiler#readme","bugs":{"url":"https://github.com/fastify/fast-json-stringify-compiler/issues"},"dist":{"shasum":"52d047fac76b0d75bd660f04a5dd606659f57c5a","tarball":"http://registry-npm.ywwl.com/@fastify/fast-json-stringify-compiler/download/@fastify/fast-json-stringify-compiler-4.2.0.tgz","fileCount":13,"integrity":"sha512-ypZynRvXA3dibfPykQN3RB5wBdEUgSGgny8Qc6k163wYPLD4mEGEDkACp+00YmqkGvIm8D/xYoHajwyEdWD/eg==","signatures":[{"sig":"MEUCIQCkcTwjwQ4o576IsckH0Sv9YpVQCDP8RDRR59UapRAMdwIgL9GWQcKaw3Odn4G0+QcT7oTmk31KFOb69+vM5HgT7n0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22016,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjmxUoACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp+/BAAgxJh6w2CEwRHvIBpGV/OTdWhqXOcbWjbFbR+fbamPOH2XhyQ\r\nMBBx4t9RNjIhG8xMvRrTztdvYH80elx9nbmp1ro9ELXGRNo5uhFGtV3l4cI/\r\nIM8lKxNFSMfl/PuXxYRXFV5BT4hZXG+6LXPDzY6fLkyT9J+6xdx5pxj4ewUu\r\nWlvDOUQaJB/pzEhg8QtkZX7FLXT78LHmN4ND++zy06A33oQpxK3vd24AgBbe\r\nLYTEoLNJjjgl2U9x5l6e5vcM228kxEPmGqqjvVYearjntY2Nd9jjOC6ZIDt/\r\nRrB+r6hnINobS7DRZSBsleqrgpLKy8OVi/bt4E3lLhExnPpa6Y/NwxI8yVgK\r\nMlBOkmSN/a9P92eFkz2fYceJsXLSLMEp+/XUlblIB8JJgRhIak4kmBqK2Pl6\r\nwhg40e/Cft8BJynpucBmeyJsRh+6J3JXMsPQg1REHfpRWZOfjkHLyfvxLh0v\r\nbUon0eDyuTzk0fTRUgziFnSqQb9+rYpV2Zufp8r8d7fjsiS87fEBOc4/++Yy\r\n/C+idQE/iaFVrEkYj+F42LKiZbiuIMk7cN8DVhyIim+B1bEvpjuTZ8rxXZC5\r\nqiuAYSEoFapmJuX6XOEWgLCL/likT/bwYv1sHoGyfkPJJpbjAL/Zxyzd8L8h\r\nyOikd6fD2IgI0yX6VZbySWylCWt69r3x4Jg=\r\n=fenv\r\n-----END PGP SIGNATURE-----\r\n","size":6194,"noattachment":false,"key":"/@fastify/fast-json-stringify-compiler/-/@fastify/fast-json-stringify-compiler-4.2.0.tgz"},"main":"index.js","types":"types/index.d.ts","gitHead":"99cec2271f56277b411d060e3396073c8a77bb15","scripts":{"lint":"standard","test":"npm run unit && npm run test:typescript","unit":"tap test/**/*.test.js","lint:fix":"standard --fix","posttest":"rimraf test/fjs-generated*.js","test:typescript":"tsd"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"repository":{"url":"git+https://github.com/fastify/fast-json-stringify-compiler.git","type":"git"},"_npmVersion":"9.1.2","description":"Build and manage the fast-json-stringify instances for the fastify framework","directories":{},"_nodeVersion":"16.17.0","dependencies":{"fast-json-stringify":"^5.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^16.0.0","tsd":"^0.25.0","rimraf":"^3.0.2","fastify":"^4.0.0","standard":"^17.0.0","sanitize-filename":"^1.6.3"},"_npmOperationalInternal":{"tmp":"tmp/fast-json-stringify-compiler_4.2.0_1671107880661_0.44891336154776296","host":"s3://npm-registry-packages"},"readme":"# @fastify/fast-json-stringify-compiler\nBuild and manage the [`fast-json-stringify`](https://www.npmjs.com/package/fast-json-stringify) instances for the fastify framework.\nThis package is responsible for compiling the application's `response` JSON schemas into optimized functions to speed up the response time.\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\n[![CI](https://github.com/fastify/fast-json-stringify-compiler/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fast-json-stringify-compiler/actions/workflows/ci.yml)\n\n\n## Versions\n\n| `@fastify/fast-json-stringify-compiler` | `fast-json-stringify` | Supported `fastify` |\n|----------------------------------------:|----------------------:|--------------------:|\n|                                    v1.x |                  v3.x |                ^3.x |\n|                                    v2.x |                  v3.x |                ^4.x |\n|                                    v3.x |                  v4.x |                ^4.x |\n|                                    v4.x |                  v5.x |                ^4.x |\n\n### fast-json-stringify Configuration\n\nThe `fast-json-stringify` configuration is the default one. You can check it the default settings in the [`fast-json-stringify` option](https://github.com/fastify/fast-json-stringify/#options) documentation.\n\nYou can also override the default configuration by passing the [`serializerOpts`](https://fastify.dev/docs/latest/Reference/Server/#serializeropts) configuration to the Fastify instance.\n\n## Usage\n\nThis module is already used as default by Fastify.\nIf you need to provide to your server instance a different version, refer to [the official doc](https://fastify.dev/docs/latest/Reference/Server/#schemacontroller).\n\n### fast-json-stringify Standalone\n\n`fast-json-stringify@v4.1.0` introduces the [standalone feature](https://github.com/fastify/fast-json-stringify#standalone) that let you to pre-compile your schemas and use them in your application for a faster startup.\n\nTo use this feature, you must be aware of the following:\n\n1. You must generate and save the application's compiled schemas.\n2. Read the compiled schemas from the file and provide them back to your Fastify application.\n\n\n#### Generate and save the compiled schemas\n\nFastify helps you to generate the serialization schemas functions and it is your choice to save them where you want.\nTo accomplish this, you must use a new compiler: `@fastify/fast-json-stringify-compiler/standalone`.\n\nYou must provide 2 parameters to this compiler:\n\n- `readMode: false`: a boolean to indicate that you want generate the schemas functions string.\n- `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.\n\nWhen `readMode: false`, **the compiler is meant to be used in development ONLY**.\n\n\n```js\nconst { StandaloneSerializer } = require('@fastify/fast-json-stringify-compiler')\n\nconst factory = StandaloneSerializer({\n  readMode: false,\n  storeFunction (routeOpts, schemaSerializationCode) {\n    // routeOpts is like: { schema, method, url, httpStatus }\n    // schemaSerializationCode is a string source code that is the compiled schema function\n    const fileName = generateFileName(routeOpts)\n    fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)\n  }\n})\n\nconst app = fastify({\n  jsonShorthand: false,\n  schemaController: {\n    compilersFactory: {\n      buildSerializer: factory\n    }\n  }\n})\n\n// ... add all your routes with schemas ...\n\napp.ready().then(() => {\n  // at this stage all your schemas are compiled and stored in the file system\n  // now it is important to turn off the readMode\n})\n```\n\n#### Read the compiled schemas functions\n\nAt this stage, you should have a file for every route's schema.\nTo use them, you must use the `@fastify/fast-json-stringify-compiler/standalone` with the parameters:\n\n- `readMode: true`: a boolean to indicate that you want read and use the schemas functions string.\n- `restoreFunction`\" a sync function that must return a function to serialize the route's payload.\n\nImportant keep away before you continue reading the documentation:\n\n- when you use the `readMode: true`, the application schemas are not compiled (they are ignored). So, if you change your schemas, you must recompile them!\n- as you can see, you must relate the route's schema to the file name using the `routeOpts` object. You may use the `routeOpts.schema.$id` field to do so, it is up to you to define a unique schema identifier.\n\n```js\nconst { StandaloneSerializer } = require('@fastify/fast-json-stringify-compiler')\n\nconst factory = StandaloneSerializer({\n  readMode: true,\n  restoreFunction (routeOpts) {\n    // routeOpts is like: { schema, method, url, httpStatus }\n    const fileName = generateFileName(routeOpts)\n    return require(path.join(__dirname, fileName))\n  }\n})\n\nconst app = fastify({\n  jsonShorthand: false,\n  schemaController: {\n    compilersFactory: {\n      buildSerializer: factory\n    }\n  }\n})\n\n// ... add all your routes with schemas as before...\n\napp.listen({ port: 3000 })\n```\n\n### How it works\n\nThis module provide a factory function to produce [Serializer Compilers](https://fastify.dev/docs/latest/Reference/Server/#serializercompiler) functions.\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","publish_time":1671107880813,"_cnpm_publish_time":1671107880813,"dist-tags":{"latest":"5.1.1","next":"5.0.0"}}