@fastify/fast-json-stringify-compiler
Advanced tools
Comparing version 5.0.1 to 5.0.2
{ | ||
"name": "@fastify/fast-json-stringify-compiler", | ||
"description": "Build and manage the fast-json-stringify instances for the fastify framework", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"main": "index.js", | ||
@@ -9,4 +9,4 @@ "type": "commonjs", | ||
"scripts": { | ||
"lint": "standard", | ||
"lint:fix": "standard --fix", | ||
"lint": "eslint", | ||
"lint:fix": "eslint --fix", | ||
"unit": "tap test/**/*.test.js", | ||
@@ -22,2 +22,21 @@ "test": "npm run unit && npm run test:typescript", | ||
"author": "Manuel Spigolon <manuel.spigolon@nearform.com> (https://github.com/Eomm)", | ||
"contributors": [ | ||
{ | ||
"name": "Matteo Collina", | ||
"email": "hello@matteocollina.com" | ||
}, | ||
{ | ||
"name": "Aras Abbasi", | ||
"email": "aras.abbasi@gmail.com" | ||
}, | ||
{ | ||
"name": "James Sumners", | ||
"url": "https://james.sumners.info" | ||
}, | ||
{ | ||
"name": "Frazer Smith", | ||
"email": "frazer.dev@icloud.com", | ||
"url": "https://github.com/fdawgs" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -28,7 +47,18 @@ "bugs": { | ||
"homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/fastify" | ||
}, | ||
{ | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/fastify" | ||
} | ||
], | ||
"devDependencies": { | ||
"@fastify/pre-commit": "^2.1.0", | ||
"eslint": "^9.17.0", | ||
"fastify": "^5.0.0", | ||
"neostandard": "^0.12.0", | ||
"sanitize-filename": "^1.6.3", | ||
"standard": "^17.1.0", | ||
"tap": "^18.7.2", | ||
@@ -35,0 +65,0 @@ "tsd": "^0.31.0" |
# @fastify/fast-json-stringify-compiler | ||
Build and manage the [`fast-json-stringify`](https://www.npmjs.com/package/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. | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) | ||
[![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) | ||
[![NPM version](https://img.shields.io/npm/v/@fastify/fast-json-stringify-compiler.svg?style=flat)](https://www.npmjs.com/package/@fastify/fast-json-stringify-compiler) | ||
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) | ||
Build and manage the [`fast-json-stringify`](https://www.npmjs.com/package/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. | ||
@@ -20,3 +21,3 @@ ## Versions | ||
The `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. | ||
The `fast-json-stringify` configuration is the default one. You can check the default settings in the [`fast-json-stringify` option](https://github.com/fastify/fast-json-stringify/#options) documentation. | ||
@@ -32,3 +33,3 @@ You can also override the default configuration by passing the [`serializerOpts`](https://fastify.dev/docs/latest/Reference/Server/#serializeropts) configuration to the Fastify instance. | ||
`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. | ||
`fast-json-stringify@v4.1.0` introduces the [standalone feature](https://github.com/fastify/fast-json-stringify#standalone) that lets you pre-compile your schemas and use them in your application for a faster startup. | ||
@@ -48,3 +49,3 @@ To use this feature, you must be aware of the following: | ||
- `readMode: false`: a boolean to indicate that you want generate the schemas functions string. | ||
- `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. | ||
@@ -90,3 +91,3 @@ | ||
- `readMode: true`: a boolean to indicate that you want read and use the schemas functions string. | ||
- `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. | ||
@@ -127,3 +128,3 @@ | ||
This module provide a factory function to produce [Serializer Compilers](https://fastify.dev/docs/latest/Reference/Server/#serializercompiler) functions. | ||
This module provides a factory function to produce [Serializer Compilers](https://fastify.dev/docs/latest/Reference/Server/#serializercompiler) functions. | ||
@@ -130,0 +131,0 @@ ## License |
@@ -7,3 +7,3 @@ 'use strict' | ||
const echo = async (req, reply) => { return req.body } | ||
const echo = async (req) => { return req.body } | ||
@@ -10,0 +10,0 @@ const sampleSchema = Object.freeze({ |
@@ -26,3 +26,3 @@ 'use strict' | ||
await fs.promises.unlink(path.join(__dirname, fileName)) | ||
} catch (e) {} | ||
} catch {} | ||
} | ||
@@ -29,0 +29,0 @@ }) |
@@ -9,9 +9,5 @@ import { Options } from 'fast-json-stringify' | ||
options?: Options | ||
) => SerializerCompiler; | ||
) => SerializerCompiler | ||
export type SerializerCompiler = ( | ||
externalSchemas?: unknown, | ||
options?: Options | ||
) => Serializer; | ||
export type SerializerCompiler = (routeDef: RouteDefinition) => Serializer | ||
export type Serializer = (doc: any) => string | ||
@@ -39,4 +35,4 @@ | ||
export type { Options } | ||
export const SerializerSelector: FastJsonStringifyFactory; | ||
export function StandaloneSerializer(options: StandaloneOptions): SerializerFactory; | ||
export const SerializerSelector: FastJsonStringifyFactory | ||
export function StandaloneSerializer (options: StandaloneOptions): SerializerFactory | ||
@@ -46,3 +42,3 @@ export { SerializerSelector as default } | ||
declare function SerializerSelector(...params: Parameters<FastJsonStringifyFactory>): ReturnType<FastJsonStringifyFactory> | ||
declare function SerializerSelector (...params: Parameters<FastJsonStringifyFactory>): ReturnType<FastJsonStringifyFactory> | ||
export = SerializerSelector |
@@ -1,2 +0,2 @@ | ||
import { expectAssignable, expectError, expectType } from "tsd"; | ||
import { expectAssignable, expectError, expectType } from 'tsd' | ||
import SerializerSelector, { | ||
@@ -9,3 +9,3 @@ RouteDefinition, | ||
StandaloneSerializer, | ||
} from ".."; | ||
} from '..' | ||
@@ -17,32 +17,30 @@ /** | ||
{ | ||
const compiler = SerializerSelector(); | ||
expectType<SerializerFactory>(compiler); | ||
const compiler = SerializerSelector() | ||
expectType<SerializerFactory>(compiler) | ||
} | ||
{ | ||
const compiler = SerializerSelectorNamed(); | ||
expectType<SerializerFactory>(compiler); | ||
const compiler = SerializerSelectorNamed() | ||
expectType<SerializerFactory>(compiler) | ||
} | ||
{ | ||
{ | ||
const sampleSchema = { | ||
$id: 'example1', | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' } | ||
} | ||
const sampleSchema = { | ||
$id: 'example1', | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' } | ||
} | ||
} | ||
const externalSchemas1 = {} | ||
const externalSchemas1 = {} | ||
const factory = SerializerSelector() | ||
expectType<SerializerFactory>(factory); | ||
const compiler = factory(externalSchemas1, {}) | ||
expectType<SerializerCompiler>(compiler); | ||
const serializeFunc = compiler({ schema: sampleSchema }) | ||
expectType<Serializer>(serializeFunc); | ||
const factory = SerializerSelector() | ||
expectType<SerializerFactory>(factory) | ||
const compiler = factory(externalSchemas1, {}) | ||
expectType<SerializerCompiler>(compiler) | ||
const serializeFunc = compiler({ schema: sampleSchema, method: '', url: '', httpStatus: '' }) | ||
expectType<Serializer>(serializeFunc) | ||
expectType<string>(serializeFunc({ name: 'hello' })) | ||
} | ||
expectType<string>(serializeFunc({ name: 'hello' })) | ||
} | ||
@@ -60,4 +58,4 @@ | ||
}, | ||
}); | ||
expectType<SerializerFactory>(reader); | ||
}) | ||
expectType<SerializerFactory>(reader) | ||
@@ -70,4 +68,4 @@ const writer = StandaloneSerializer({ | ||
}, | ||
}); | ||
expectType<SerializerFactory>(writer); | ||
}) | ||
expectType<SerializerFactory>(writer) | ||
@@ -95,2 +93,5 @@ { | ||
const endpointSchema = { | ||
method: '', | ||
url: '', | ||
httpStatus: '', | ||
schema: { | ||
@@ -97,0 +98,0 @@ $id: 'urn:schema:endpoint', |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23848
15
494
129
7
2