From 3c11de5d99b25139175f657d116b3a8814dca848 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Jul 2022 00:56:47 +0000 Subject: [PATCH 01/58] build(deps-dev): bump tsd from 0.21.0 to 0.22.0 (#16) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.21.0 to 0.22.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.21.0...v0.22.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d52874a..0e3dc69 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "fastify": "^4.0.0", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.21.0" + "tsd": "^0.22.0" }, "dependencies": { "fast-json-stringify": "^5.0.0" From 09da8b039201d82c00e27dfca83414d37a01ceed Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 2 Aug 2022 09:10:22 +0100 Subject: [PATCH 02/58] ci: enable license checking (#17) --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b9855f..325921f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Continuous Integration +name: CI on: push: @@ -13,3 +13,5 @@ on: jobs: test: uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + with: + license-check: true From 032756e1fb6e68045ae76b6824197f45f7824d3d Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Tue, 23 Aug 2022 18:09:06 +0200 Subject: [PATCH 03/58] feat: standalone mode (#18) --- .github/workflows/ci.yml | 1 + README.md | 92 ++++++++++++++ index.d.ts | 24 +++- index.js | 3 + package.json | 8 +- standalone.js | 42 +++++++ test/plugin.test.js | 4 +- test/standalone.test.js | 213 ++++++++++++++++++++++++++++++++ test/types/index.test-d.ts | 16 +++ test/types/index.test.ts | 6 - test/types/standalone.test-d.ts | 21 ++++ 11 files changed, 416 insertions(+), 14 deletions(-) create mode 100644 standalone.js create mode 100644 test/standalone.test.js create mode 100644 test/types/index.test-d.ts delete mode 100644 test/types/index.test.ts create mode 100644 test/types/standalone.test-d.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 325921f..079a8f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,3 +15,4 @@ jobs: uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 with: license-check: true + lint: true diff --git a/README.md b/README.md index 6047f98..9f74dbd 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,98 @@ You can also override the default configuration by passing the [`serializerOpts` 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](https://www.fastify.io/docs/latest/Reference/Server/#schemacontroller). +### fast-json-stringify Standalone + +`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. + +To use this feature, you must be aware of the following: + +1. You must generate and save the application's compiled schemas. +2. Read the compiled schemas from the file and provide them back to your Fastify application. + + +#### Generate and save the compiled schemas + +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 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**. + + +```js +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 +}) +``` + +#### Read the compiled schemas functions + +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 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: + +- 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! +- 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. + +```js +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 }) +``` + ### How it works This module provide a factory function to produce [Serializer Compilers](https://www.fastify.io/docs/latest/Reference/Server/#serializercompiler) functions. diff --git a/index.d.ts b/index.d.ts index 31506ad..0d7ec24 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,12 +1,30 @@ import { Options as FJSOptions } from 'fast-json-stringify' +export type { Options } from 'fast-json-stringify' + export type SerializerCompiler = ( externalSchemas: unknown, options: FJSOptions ) => (doc: any) => string; -export declare function SerializerSelector(): SerializerCompiler; +export type RouteDefinition = { + method: string, + url: string, + httpStatus: string, + schema?: unknown, +} -export type { Options } from 'fast-json-stringify' +export interface StandaloneOptions { + readMode: Boolean, + storeFunction?(opts: RouteDefinition, schemaSerializationCode: string): void, + restoreFunction?(opts: RouteDefinition): void, +} + +declare function SerializerSelector(): SerializerCompiler; +declare function StandaloneSerializer(options: StandaloneOptions): SerializerCompiler; -export default SerializerSelector; \ No newline at end of file +export default SerializerSelector; +export { + SerializerSelector, + StandaloneSerializer, +}; diff --git a/index.js b/index.js index 836b4c7..a021ea1 100644 --- a/index.js +++ b/index.js @@ -18,3 +18,6 @@ function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ } module.exports = SerializerSelector +module.exports.default = SerializerSelector +module.exports.SerializerSelector = SerializerSelector +module.exports.StandaloneSerializer = require('./standalone') diff --git a/package.json b/package.json index 0e3dc69..f5f8b3b 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "main": "index.js", "types": "index.d.ts", "scripts": { + "lint": "standard", "lint:fix": "standard --fix", - "unit": "tap --100 test/**/*.test.js", - "test": "standard && npm run unit && npm run test:typescript", + "unit": "tap test/**/*.test.js", + "test": "npm run unit && npm run test:typescript", + "posttest": "rimraf test/fjs-generated*.js", "test:typescript": "tsd" }, "repository": { @@ -23,6 +25,8 @@ "homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", "devDependencies": { "fastify": "^4.0.0", + "rimraf": "^3.0.2", + "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", "tsd": "^0.22.0" diff --git a/standalone.js b/standalone.js new file mode 100644 index 0000000..39b4937 --- /dev/null +++ b/standalone.js @@ -0,0 +1,42 @@ +'use strict' + +const SerializerSelector = require('./index') + +function StandaloneSerializer (options = { readMode: true }) { + if (options.readMode === true && typeof options.restoreFunction !== 'function') { + throw new Error('You must provide a function for the restoreFunction-option when readMode ON') + } + + if (options.readMode !== true && typeof options.storeFunction !== 'function') { + throw new Error('You must provide a function for the storeFunction-option when readMode OFF') + } + + if (options.readMode === true) { + // READ MODE: it behalf only in the restore function provided by the user + return function wrapper () { + return function (opts) { + return options.restoreFunction(opts) + } + } + } + + // WRITE MODE: it behalf on the default SerializerSelector, wrapping the API to run the Ajv Standalone code generation + const factory = SerializerSelector() + return function wrapper (externalSchemas, serializerOpts = {}) { + // to generate the serialization source code, this option is mandatory + serializerOpts.mode = 'standalone' + + const compiler = factory(externalSchemas, serializerOpts) + return function (opts) { // { schema/*, method, url, httpPart */ } + const serializeFuncCode = compiler(opts) + + options.storeFunction(opts, serializeFuncCode) + + // eslint-disable-next-line no-new-func + return new Function(serializeFuncCode) + } + } +} + +module.exports = StandaloneSerializer +module.exports.default = StandaloneSerializer diff --git a/test/plugin.test.js b/test/plugin.test.js index d467720..df2582b 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -25,9 +25,7 @@ const externalSchemas2 = Object.freeze({ } }) -const fastifyFjsOptionsDefault = Object.freeze({ - customOptions: {} -}) +const fastifyFjsOptionsDefault = Object.freeze({}) t.test('basic usage', t => { t.plan(1) diff --git a/test/standalone.test.js b/test/standalone.test.js new file mode 100644 index 0000000..fa26e61 --- /dev/null +++ b/test/standalone.test.js @@ -0,0 +1,213 @@ +'use strict' + +const fs = require('fs') +const path = require('path') +const t = require('tap') +const fastify = require('fastify') +const sanitize = require('sanitize-filename') + +const { StandaloneSerializer: FjsStandaloneCompiler } = require('../') + +function generateFileName (routeOpts) { + return `/fjs-generated-${sanitize(routeOpts.schema.$id)}-${routeOpts.method}-${routeOpts.httpPart}-${sanitize(routeOpts.url)}.js` +} + +t.test('errors', t => { + t.plan(2) + t.throws(() => { + FjsStandaloneCompiler() + }, 'missing restoreFunction') + t.throws(() => { + FjsStandaloneCompiler({ readMode: false }) + }, 'missing storeFunction') +}) + +t.test('generate standalone code', t => { + t.plan(5) + + const base = { + $id: 'urn:schema:base', + definitions: { + hello: { type: 'string' } + }, + type: 'object', + properties: { + hello: { $ref: '#/definitions/hello' } + } + } + + const refSchema = { + $id: 'urn:schema:ref', + type: 'object', + properties: { + hello: { $ref: 'urn:schema:base#/definitions/hello' } + } + } + + const endpointSchema = { + schema: { + $id: 'urn:schema:endpoint', + $ref: 'urn:schema:ref' + } + } + + const schemaMap = { + [base.$id]: base, + [refSchema.$id]: refSchema + } + + const factory = FjsStandaloneCompiler({ + readMode: false, + storeFunction (routeOpts, schemaSerializerCode) { + t.same(routeOpts, endpointSchema) + t.type(schemaSerializerCode, 'string') + fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode) + t.pass('stored the serializer function') + } + }) + + const compiler = factory(schemaMap) + compiler(endpointSchema) + t.pass('compiled the endpoint schema') + + t.test('usage standalone code', t => { + t.plan(3) + const standaloneSerializer = require('./fjs-generated') + t.ok(standaloneSerializer) + + const valid = standaloneSerializer({ hello: 'world' }) + t.same(valid, JSON.stringify({ hello: 'world' })) + + const invalid = standaloneSerializer({ hello: [] }) + t.same(invalid, '{"hello":""}') + }) +}) + +t.test('fastify integration - writeMode', async t => { + t.plan(4) + + const factory = FjsStandaloneCompiler({ + readMode: false, + storeFunction (routeOpts, schemaSerializationCode) { + const fileName = generateFileName(routeOpts) + t.ok(routeOpts) + fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) + t.pass(`stored the serializer function ${fileName}`) + }, + restoreFunction () { + t.fail('write mode ON') + } + }) + + const app = buildApp(factory) + await app.ready() +}) + +t.test('fastify integration - writeMode forces standalone', async t => { + t.plan(4) + + const factory = FjsStandaloneCompiler({ + readMode: false, + storeFunction (routeOpts, schemaSerializationCode) { + const fileName = generateFileName(routeOpts) + t.ok(routeOpts) + fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) + t.pass(`stored the serializer function ${fileName}`) + }, + restoreFunction () { + t.fail('write mode ON') + } + }) + + const app = buildApp(factory, { + mode: 'not-standalone', + rounding: 'ceil' + }) + + await app.ready() +}) + +t.test('fastify integration - readMode', async t => { + t.plan(6) + + const factory = FjsStandaloneCompiler({ + readMode: true, + storeFunction () { + t.fail('read mode ON') + }, + restoreFunction (routeOpts) { + const fileName = generateFileName(routeOpts) + t.pass(`restore the serializer function ${fileName}}`) + return require(path.join(__dirname, fileName)) + } + }) + + const app = buildApp(factory) + await app.ready() + + let res = await app.inject({ + url: '/foo', + method: 'POST' + }) + t.equal(res.statusCode, 200) + t.equal(res.payload, JSON.stringify({ hello: 'world' })) + + res = await app.inject({ + url: '/bar?lang=it', + method: 'GET' + }) + t.equal(res.statusCode, 200) + t.equal(res.payload, JSON.stringify({ lang: 'en' })) +}) + +function buildApp (factory, serializerOpts) { + const app = fastify({ + exposeHeadRoutes: false, + jsonShorthand: false, + schemaController: { + compilersFactory: { + buildSerializer: factory + } + }, + serializerOpts + }) + + app.addSchema({ + $id: 'urn:schema:foo', + type: 'object', + properties: { + name: { type: 'string' }, + id: { type: 'integer' } + } + }) + + app.post('/foo', { + schema: { + response: { + 200: { + $id: 'urn:schema:response', + type: 'object', + properties: { + hello: { $ref: 'urn:schema:foo#/properties/name' } + } + } + } + } + }, () => { return { hello: 'world' } }) + + app.get('/bar', { + schema: { + response: { + 200: { + $id: 'urn:schema:response:bar', + type: 'object', + properties: { + lang: { type: 'string', enum: ['it', 'en'] } + } + } + } + } + }, () => { return { lang: 'en' } }) + + return app +} diff --git a/test/types/index.test-d.ts b/test/types/index.test-d.ts new file mode 100644 index 0000000..9980fc9 --- /dev/null +++ b/test/types/index.test-d.ts @@ -0,0 +1,16 @@ +import { expectType } from "tsd"; +import SerializerSelector, { + SerializerCompiler, + SerializerSelector as SerializerSelectorNamed, + StandaloneSerializer, +} from "../.."; + +{ + const compiler = SerializerSelector(); + expectType(compiler); +} + +{ + const compiler = SerializerSelectorNamed(); + expectType(compiler); +} \ No newline at end of file diff --git a/test/types/index.test.ts b/test/types/index.test.ts deleted file mode 100644 index 67caf0d..0000000 --- a/test/types/index.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; -import SerializerSelector, { SerializerCompiler } from "../.."; - -const compiler = SerializerSelector(); - -expectType(compiler); \ No newline at end of file diff --git a/test/types/standalone.test-d.ts b/test/types/standalone.test-d.ts new file mode 100644 index 0000000..789b40e --- /dev/null +++ b/test/types/standalone.test-d.ts @@ -0,0 +1,21 @@ +import { expectAssignable, expectType } from "tsd"; + +import { StandaloneSerializer, RouteDefinition } from "../../"; +import { SerializerCompiler } from "../.."; + +const reader = StandaloneSerializer({ + readMode: true, + restoreFunction: (route: RouteDefinition) => { + expectAssignable(route) + }, +}); +expectType(reader); + +const writer = StandaloneSerializer({ + readMode: false, + storeFunction: (route: RouteDefinition, code: string) => { + expectAssignable(route) + expectAssignable(code) + }, +}); +expectType(writer); \ No newline at end of file From a2ee2d3c05445c5a45ce193f014f3f77f52e3c0d Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 23 Aug 2022 19:01:28 +0200 Subject: [PATCH 04/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f74dbd..911f7e0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This package is responsible for compiling the application's `response` JSON sche | v1.x | v3.x | ^3.x | | v2.x | v3.x | ^4.x | | v3.x | v4.x | ^4.x | -| v3.x | v5.x | ^4.x | +| v4.x | v5.x | ^4.x | ### fast-json-stringify Configuration From be10a45f4b0f56b8114a8f3c491b57f2445de918 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Wed, 24 Aug 2022 07:48:18 +0200 Subject: [PATCH 05/58] Bumped v4.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f5f8b3b..44d925b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "4.0.0", + "version": "4.1.0", "main": "index.js", "types": "index.d.ts", "scripts": { From 945345f6736c83234473283c515cd853473db8c9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Aug 2022 01:11:47 +0000 Subject: [PATCH 06/58] build(deps-dev): bump tsd from 0.22.0 to 0.23.0 (#19) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.22.0 to 0.23.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.22.0...v0.23.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 44d925b..0c0cde8 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.22.0" + "tsd": "^0.23.0" }, "dependencies": { "fast-json-stringify": "^5.0.0" From 10acbf0569acc3b4005f502477d4082db67c0918 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Sep 2022 01:16:52 +0000 Subject: [PATCH 07/58] build(deps-dev): bump tsd from 0.23.0 to 0.24.1 (#20) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.23.0 to 0.24.1. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.23.0...v0.24.1) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c0cde8..d6a4120 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.23.0" + "tsd": "^0.24.1" }, "dependencies": { "fast-json-stringify": "^5.0.0" From 8c2194c41c1d69960f6533f002d8e25610d7eac5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Dec 2022 00:34:47 +0000 Subject: [PATCH 08/58] build(deps-dev): bump tsd from 0.24.1 to 0.25.0 (#21) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.24.1 to 0.25.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.24.1...v0.25.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d6a4120..c7047f7 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.24.1" + "tsd": "^0.25.0" }, "dependencies": { "fast-json-stringify": "^5.0.0" From ebe7c7d05a41d0bfbc2f2210a160fdca716731fb Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Mon, 5 Dec 2022 11:17:57 +0100 Subject: [PATCH 09/58] disable package-lock generation (#23) --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From b91042c7f4285659095ac8faae922aee7b509381 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Fri, 9 Dec 2022 14:39:40 +0100 Subject: [PATCH 10/58] nodenext compatibility, correct typings (#22) * nodenext compatibility * add missing function declaration * fix wrong typing * fix typings * fix optional readmode typing * Add missing EOF newline * restoreFunction needs to return Serializer --- index.d.ts | 30 ------- package.json | 5 +- test/types/index.test-d.ts | 16 ---- test/types/standalone.test-d.ts | 21 ----- types/index.d.ts | 45 ++++++++++ types/index.test-d.ts | 141 ++++++++++++++++++++++++++++++++ 6 files changed, 187 insertions(+), 71 deletions(-) delete mode 100644 index.d.ts delete mode 100644 test/types/index.test-d.ts delete mode 100644 test/types/standalone.test-d.ts create mode 100644 types/index.d.ts create mode 100644 types/index.test-d.ts diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 0d7ec24..0000000 --- a/index.d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Options as FJSOptions } from 'fast-json-stringify' - -export type { Options } from 'fast-json-stringify' - -export type SerializerCompiler = ( - externalSchemas: unknown, - options: FJSOptions -) => (doc: any) => string; - -export type RouteDefinition = { - method: string, - url: string, - httpStatus: string, - schema?: unknown, -} - -export interface StandaloneOptions { - readMode: Boolean, - storeFunction?(opts: RouteDefinition, schemaSerializationCode: string): void, - restoreFunction?(opts: RouteDefinition): void, -} - -declare function SerializerSelector(): SerializerCompiler; -declare function StandaloneSerializer(options: StandaloneOptions): SerializerCompiler; - -export default SerializerSelector; -export { - SerializerSelector, - StandaloneSerializer, -}; diff --git a/package.json b/package.json index c7047f7..dcfdb88 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Build and manage the fast-json-stringify instances for the fastify framework", "version": "4.1.0", "main": "index.js", - "types": "index.d.ts", + "types": "types/index.d.ts", "scripts": { "lint": "standard", "lint:fix": "standard --fix", @@ -33,8 +33,5 @@ }, "dependencies": { "fast-json-stringify": "^5.0.0" - }, - "tsd": { - "directory": "test/types" } } diff --git a/test/types/index.test-d.ts b/test/types/index.test-d.ts deleted file mode 100644 index 9980fc9..0000000 --- a/test/types/index.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expectType } from "tsd"; -import SerializerSelector, { - SerializerCompiler, - SerializerSelector as SerializerSelectorNamed, - StandaloneSerializer, -} from "../.."; - -{ - const compiler = SerializerSelector(); - expectType(compiler); -} - -{ - const compiler = SerializerSelectorNamed(); - expectType(compiler); -} \ No newline at end of file diff --git a/test/types/standalone.test-d.ts b/test/types/standalone.test-d.ts deleted file mode 100644 index 789b40e..0000000 --- a/test/types/standalone.test-d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expectAssignable, expectType } from "tsd"; - -import { StandaloneSerializer, RouteDefinition } from "../../"; -import { SerializerCompiler } from "../.."; - -const reader = StandaloneSerializer({ - readMode: true, - restoreFunction: (route: RouteDefinition) => { - expectAssignable(route) - }, -}); -expectType(reader); - -const writer = StandaloneSerializer({ - readMode: false, - storeFunction: (route: RouteDefinition, code: string) => { - expectAssignable(route) - expectAssignable(code) - }, -}); -expectType(writer); \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..26bbf1f --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,45 @@ +import { Options } from 'fast-json-stringify' + +type FastJsonStringifyFactory = () => SerializerSelector.SerializerFactory + +declare namespace SerializerSelector { + export type SerializerFactory = ( + externalSchemas?: unknown, + options?: Options + ) => SerializerCompiler; + + export type SerializerCompiler = ( + externalSchemas?: unknown, + options?: Options + ) => Serializer; + + export type Serializer = (doc: any) => string + + export type RouteDefinition = { + method: string; + url: string; + httpStatus: string; + schema?: unknown; + } + + export type StandaloneOptions = StandaloneOptionsReadModeOn | StandaloneOptionsReadModeOff + + export type StandaloneOptionsReadModeOn = { + readMode: true; + restoreFunction?(opts: RouteDefinition): Serializer; + } + + export type StandaloneOptionsReadModeOff = { + readMode?: false | undefined; + storeFunction?(opts: RouteDefinition, schemaSerializationCode: string): void; + } + + export type { Options } + export const SerializerSelector: FastJsonStringifyFactory; + export function StandaloneSerializer(options: StandaloneOptions): SerializerFactory; + + export { SerializerSelector as default } +} + +declare function SerializerSelector(...params: Parameters): ReturnType +export = SerializerSelector diff --git a/types/index.test-d.ts b/types/index.test-d.ts new file mode 100644 index 0000000..d1dbd85 --- /dev/null +++ b/types/index.test-d.ts @@ -0,0 +1,141 @@ +import { expectAssignable, expectError, expectType } from "tsd"; +import SerializerSelector, { + RouteDefinition, + Serializer, + SerializerCompiler, + SerializerFactory, + SerializerSelector as SerializerSelectorNamed, + StandaloneSerializer, +} from ".."; + +/** + * SerializerSelector + */ + +{ + const compiler = SerializerSelector(); + expectType(compiler); +} + +{ + const compiler = SerializerSelectorNamed(); + expectType(compiler); +} + +{ + { + const sampleSchema = { + $id: 'example1', + type: 'object', + properties: { + name: { type: 'string' } + } + } + + const externalSchemas1 = {} + + const factory = SerializerSelector() + expectType(factory); + const compiler = factory(externalSchemas1, {}) + expectType(compiler); + const serializeFunc = compiler({ schema: sampleSchema }) + expectType(serializeFunc); + + expectType(serializeFunc({ name: 'hello' })) + } +} + +/** + * StandaloneSerializer + */ + +const reader = StandaloneSerializer({ + readMode: true, + restoreFunction: (route: RouteDefinition) => { + expectAssignable(route) + return {} as Serializer + }, +}); +expectType(reader); + +const writer = StandaloneSerializer({ + readMode: false, + storeFunction: (route: RouteDefinition, code: string) => { + expectAssignable(route) + expectAssignable(code) + }, +}); +expectType(writer); + +{ + const base = { + $id: 'urn:schema:base', + definitions: { + hello: { type: 'string' } + }, + type: 'object', + properties: { + hello: { $ref: '#/definitions/hello' } + } + } + + const refSchema = { + $id: 'urn:schema:ref', + type: 'object', + properties: { + hello: { $ref: 'urn:schema:base#/definitions/hello' } + } + } + + const endpointSchema = { + schema: { + $id: 'urn:schema:endpoint', + $ref: 'urn:schema:ref' + } + } + + const schemaMap = { + [base.$id]: base, + [refSchema.$id]: refSchema + } + + expectError(StandaloneSerializer({ + readMode: true, + storeFunction () { } + })) + expectError(StandaloneSerializer({ + readMode: false, + restoreFunction () {} + })) + expectError(StandaloneSerializer({ + restoreFunction () {} + })) + + expectType(StandaloneSerializer({ + storeFunction (routeOpts, schemaSerializerCode) { + expectType(routeOpts) + expectType(schemaSerializerCode) + } + })) + + expectType(StandaloneSerializer({ + readMode: true, + restoreFunction (routeOpts) { + expectType(routeOpts) + return {} as Serializer + } + })) + + const factory = StandaloneSerializer({ + readMode: false, + storeFunction (routeOpts, schemaSerializerCode) { + expectType(routeOpts) + expectType(schemaSerializerCode) + } + }) + expectType(factory) + + const compiler = factory(schemaMap) + expectType(compiler) + expectType(compiler(endpointSchema)) +} From 99cec2271f56277b411d060e3396073c8a77bb15 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 15 Dec 2022 13:37:43 +0100 Subject: [PATCH 11/58] Bumped v4.2.0 Signed-off-by: Matteo Collina --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcfdb88..3dc6dc3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "4.1.0", + "version": "4.2.0", "main": "index.js", "types": "types/index.d.ts", "scripts": { From c1759168d1eba0ff25ca1fa751a90d792a8be1fa Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 6 Jan 2023 17:05:03 +0000 Subject: [PATCH 12/58] chore(.gitignore): add clinic (#24) --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c1b9a5c..8fda44a 100644 --- a/.gitignore +++ b/.gitignore @@ -135,6 +135,9 @@ dist # macOS files .DS_Store +# Clinic +.clinic + # lock files package-lock.json pnpm-lock.yaml @@ -142,4 +145,4 @@ yarn.lock # editor files .vscode -.idea \ No newline at end of file +.idea From a41ba246a1678c734812a8f0f96c052f083d7f0e Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Mon, 6 Feb 2023 17:15:37 +0100 Subject: [PATCH 13/58] add pre-commit (#29) --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 3dc6dc3..51883a6 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", "devDependencies": { + "@fastify/pre-commit": "^2.0.2", "fastify": "^4.0.0", "rimraf": "^3.0.2", "sanitize-filename": "^1.6.3", @@ -31,6 +32,10 @@ "tap": "^16.0.0", "tsd": "^0.25.0" }, + "pre-commit": [ + "lint", + "test" + ], "dependencies": { "fast-json-stringify": "^5.0.0" } From 6b8eeb1a30d7329ce4622e921426fbb41660292c Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Mon, 6 Feb 2023 19:06:38 +0100 Subject: [PATCH 14/58] remove rimraf (#28) --- package.json | 2 - test/standalone.test.js | 349 +++++++++++++++++++++------------------- 2 files changed, 183 insertions(+), 168 deletions(-) diff --git a/package.json b/package.json index 51883a6..fa32dbe 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "lint:fix": "standard --fix", "unit": "tap test/**/*.test.js", "test": "npm run unit && npm run test:typescript", - "posttest": "rimraf test/fjs-generated*.js", "test:typescript": "tsd" }, "repository": { @@ -26,7 +25,6 @@ "devDependencies": { "@fastify/pre-commit": "^2.0.2", "fastify": "^4.0.0", - "rimraf": "^3.0.2", "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", diff --git a/test/standalone.test.js b/test/standalone.test.js index fa26e61..51f773c 100644 --- a/test/standalone.test.js +++ b/test/standalone.test.js @@ -8,206 +8,223 @@ const sanitize = require('sanitize-filename') const { StandaloneSerializer: FjsStandaloneCompiler } = require('../') +const generatedFileNames = [] + function generateFileName (routeOpts) { - return `/fjs-generated-${sanitize(routeOpts.schema.$id)}-${routeOpts.method}-${routeOpts.httpPart}-${sanitize(routeOpts.url)}.js` + const fileName = `/fjs-generated-${sanitize(routeOpts.schema.$id)}-${routeOpts.method}-${routeOpts.httpPart}-${sanitize(routeOpts.url)}.js` + generatedFileNames.push(fileName) + return fileName } -t.test('errors', t => { - t.plan(2) - t.throws(() => { - FjsStandaloneCompiler() - }, 'missing restoreFunction') - t.throws(() => { - FjsStandaloneCompiler({ readMode: false }) - }, 'missing storeFunction') -}) - -t.test('generate standalone code', t => { +t.test('standalone', t => { t.plan(5) - const base = { - $id: 'urn:schema:base', - definitions: { - hello: { type: 'string' } - }, - type: 'object', - properties: { - hello: { $ref: '#/definitions/hello' } + t.teardown(async () => { + for (const fileName of generatedFileNames) { + try { + await fs.promises.unlink(path.join(__dirname, fileName)) + } catch (e) {} } - } + }) - const refSchema = { - $id: 'urn:schema:ref', - type: 'object', - properties: { - hello: { $ref: 'urn:schema:base#/definitions/hello' } - } - } + t.test('errors', t => { + t.plan(2) + t.throws(() => { + FjsStandaloneCompiler() + }, 'missing restoreFunction') + t.throws(() => { + FjsStandaloneCompiler({ readMode: false }) + }, 'missing storeFunction') + }) - const endpointSchema = { - schema: { - $id: 'urn:schema:endpoint', - $ref: 'urn:schema:ref' + t.test('generate standalone code', t => { + t.plan(5) + + const base = { + $id: 'urn:schema:base', + definitions: { + hello: { type: 'string' } + }, + type: 'object', + properties: { + hello: { $ref: '#/definitions/hello' } + } } - } - const schemaMap = { - [base.$id]: base, - [refSchema.$id]: refSchema - } - - const factory = FjsStandaloneCompiler({ - readMode: false, - storeFunction (routeOpts, schemaSerializerCode) { - t.same(routeOpts, endpointSchema) - t.type(schemaSerializerCode, 'string') - fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode) - t.pass('stored the serializer function') + const refSchema = { + $id: 'urn:schema:ref', + type: 'object', + properties: { + hello: { $ref: 'urn:schema:base#/definitions/hello' } + } } - }) - const compiler = factory(schemaMap) - compiler(endpointSchema) - t.pass('compiled the endpoint schema') - - t.test('usage standalone code', t => { - t.plan(3) - const standaloneSerializer = require('./fjs-generated') - t.ok(standaloneSerializer) + const endpointSchema = { + schema: { + $id: 'urn:schema:endpoint', + $ref: 'urn:schema:ref' + } + } - const valid = standaloneSerializer({ hello: 'world' }) - t.same(valid, JSON.stringify({ hello: 'world' })) + const schemaMap = { + [base.$id]: base, + [refSchema.$id]: refSchema + } - const invalid = standaloneSerializer({ hello: [] }) - t.same(invalid, '{"hello":""}') - }) -}) + const factory = FjsStandaloneCompiler({ + readMode: false, + storeFunction (routeOpts, schemaSerializerCode) { + t.same(routeOpts, endpointSchema) + t.type(schemaSerializerCode, 'string') + fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode) + generatedFileNames.push('/fjs-generated.js') + t.pass('stored the serializer function') + } + }) -t.test('fastify integration - writeMode', async t => { - t.plan(4) - - const factory = FjsStandaloneCompiler({ - readMode: false, - storeFunction (routeOpts, schemaSerializationCode) { - const fileName = generateFileName(routeOpts) - t.ok(routeOpts) - fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) - t.pass(`stored the serializer function ${fileName}`) - }, - restoreFunction () { - t.fail('write mode ON') - } - }) + const compiler = factory(schemaMap) + compiler(endpointSchema) + t.pass('compiled the endpoint schema') - const app = buildApp(factory) - await app.ready() -}) + t.test('usage standalone code', t => { + t.plan(3) + const standaloneSerializer = require('./fjs-generated') + t.ok(standaloneSerializer) -t.test('fastify integration - writeMode forces standalone', async t => { - t.plan(4) - - const factory = FjsStandaloneCompiler({ - readMode: false, - storeFunction (routeOpts, schemaSerializationCode) { - const fileName = generateFileName(routeOpts) - t.ok(routeOpts) - fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) - t.pass(`stored the serializer function ${fileName}`) - }, - restoreFunction () { - t.fail('write mode ON') - } - }) + const valid = standaloneSerializer({ hello: 'world' }) + t.same(valid, JSON.stringify({ hello: 'world' })) - const app = buildApp(factory, { - mode: 'not-standalone', - rounding: 'ceil' + const invalid = standaloneSerializer({ hello: [] }) + t.same(invalid, '{"hello":""}') + }) }) - await app.ready() -}) + t.test('fastify integration - writeMode', async t => { + t.plan(4) + + const factory = FjsStandaloneCompiler({ + readMode: false, + storeFunction (routeOpts, schemaSerializationCode) { + const fileName = generateFileName(routeOpts) + t.ok(routeOpts) + fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) + t.pass(`stored the serializer function ${fileName}`) + }, + restoreFunction () { + t.fail('write mode ON') + } + }) -t.test('fastify integration - readMode', async t => { - t.plan(6) - - const factory = FjsStandaloneCompiler({ - readMode: true, - storeFunction () { - t.fail('read mode ON') - }, - restoreFunction (routeOpts) { - const fileName = generateFileName(routeOpts) - t.pass(`restore the serializer function ${fileName}}`) - return require(path.join(__dirname, fileName)) - } + const app = buildApp(factory) + await app.ready() }) - const app = buildApp(factory) - await app.ready() + t.test('fastify integration - writeMode forces standalone', async t => { + t.plan(4) + + const factory = FjsStandaloneCompiler({ + readMode: false, + storeFunction (routeOpts, schemaSerializationCode) { + const fileName = generateFileName(routeOpts) + t.ok(routeOpts) + fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) + t.pass(`stored the serializer function ${fileName}`) + }, + restoreFunction () { + t.fail('write mode ON') + } + }) - let res = await app.inject({ - url: '/foo', - method: 'POST' - }) - t.equal(res.statusCode, 200) - t.equal(res.payload, JSON.stringify({ hello: 'world' })) + const app = buildApp(factory, { + mode: 'not-standalone', + rounding: 'ceil' + }) - res = await app.inject({ - url: '/bar?lang=it', - method: 'GET' + await app.ready() }) - t.equal(res.statusCode, 200) - t.equal(res.payload, JSON.stringify({ lang: 'en' })) -}) -function buildApp (factory, serializerOpts) { - const app = fastify({ - exposeHeadRoutes: false, - jsonShorthand: false, - schemaController: { - compilersFactory: { - buildSerializer: factory + t.test('fastify integration - readMode', async t => { + t.plan(6) + + const factory = FjsStandaloneCompiler({ + readMode: true, + storeFunction () { + t.fail('read mode ON') + }, + restoreFunction (routeOpts) { + const fileName = generateFileName(routeOpts) + t.pass(`restore the serializer function ${fileName}}`) + return require(path.join(__dirname, fileName)) } - }, - serializerOpts + }) + + const app = buildApp(factory) + await app.ready() + + let res = await app.inject({ + url: '/foo', + method: 'POST' + }) + t.equal(res.statusCode, 200) + t.equal(res.payload, JSON.stringify({ hello: 'world' })) + + res = await app.inject({ + url: '/bar?lang=it', + method: 'GET' + }) + t.equal(res.statusCode, 200) + t.equal(res.payload, JSON.stringify({ lang: 'en' })) }) - app.addSchema({ - $id: 'urn:schema:foo', - type: 'object', - properties: { - name: { type: 'string' }, - id: { type: 'integer' } - } - }) - - app.post('/foo', { - schema: { - response: { - 200: { - $id: 'urn:schema:response', - type: 'object', - properties: { - hello: { $ref: 'urn:schema:foo#/properties/name' } + function buildApp (factory, serializerOpts) { + const app = fastify({ + exposeHeadRoutes: false, + jsonShorthand: false, + schemaController: { + compilersFactory: { + buildSerializer: factory + } + }, + serializerOpts + }) + + app.addSchema({ + $id: 'urn:schema:foo', + type: 'object', + properties: { + name: { type: 'string' }, + id: { type: 'integer' } + } + }) + + app.post('/foo', { + schema: { + response: { + 200: { + $id: 'urn:schema:response', + type: 'object', + properties: { + hello: { $ref: 'urn:schema:foo#/properties/name' } + } } } } - } - }, () => { return { hello: 'world' } }) - - app.get('/bar', { - schema: { - response: { - 200: { - $id: 'urn:schema:response:bar', - type: 'object', - properties: { - lang: { type: 'string', enum: ['it', 'en'] } + }, () => { return { hello: 'world' } }) + + app.get('/bar', { + schema: { + response: { + 200: { + $id: 'urn:schema:response:bar', + type: 'object', + properties: { + lang: { type: 'string', enum: ['it', 'en'] } + } } } } - } - }, () => { return { lang: 'en' } }) + }, () => { return { lang: 'en' } }) - return app -} + return app + } +}) From 9847dde5ad502ca575a442385850fe537c2b080a Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 5 Mar 2023 10:25:17 +0000 Subject: [PATCH 15/58] chore(.gitignore): add bun lockfile (#30) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8fda44a..3c21249 100644 --- a/.gitignore +++ b/.gitignore @@ -139,6 +139,7 @@ dist .clinic # lock files +bun.lockb package-lock.json pnpm-lock.yaml yarn.lock From a068619bafa4e2e8c449e6056a20f28a7711b4cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Mar 2023 01:21:52 +0000 Subject: [PATCH 16/58] build(deps-dev): bump tsd from 0.25.0 to 0.27.0 (#31) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.25.0 to 0.27.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.25.0...v0.27.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fa32dbe..c9c6c6a 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.25.0" + "tsd": "^0.27.0" }, "pre-commit": [ "lint", From a50883dce068788846543f9251002a202e69b914 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Mar 2023 01:18:34 +0000 Subject: [PATCH 17/58] build(deps-dev): bump tsd from 0.27.0 to 0.28.0 (#32) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.27.0 to 0.28.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.27.0...v0.28.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c9c6c6a..db6f10d 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.27.0" + "tsd": "^0.28.0" }, "pre-commit": [ "lint", From 306798c02c5fb8d978e03c1ca1716daea347a484 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 26 Apr 2023 09:12:01 +0200 Subject: [PATCH 18/58] update fast-json-stringify to 5.7.0 Signed-off-by: Matteo Collina --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db6f10d..c390d89 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,6 @@ "test" ], "dependencies": { - "fast-json-stringify": "^5.0.0" + "fast-json-stringify": "^5.7.0" } } From 2030d2c1ef2ae5944f56e2bf141a5d5cd8781178 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 26 Apr 2023 09:12:24 +0200 Subject: [PATCH 19/58] Bumped v4.3.0 Signed-off-by: Matteo Collina --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c390d89..c9511bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "4.2.0", + "version": "4.3.0", "main": "index.js", "types": "types/index.d.ts", "scripts": { From 0c036869e35f854935bb658e5fb0cff5316a11b5 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 28 Apr 2023 18:46:05 +0100 Subject: [PATCH 20/58] ci: only trigger on pushes to main branches (#33) --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 079a8f0..7b00276 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,11 @@ name: CI on: push: + branches: + - main + - master + - next + - 'v*' paths-ignore: - 'docs/**' - '*.md' From e2f61ca0fcfe23f28e2c2e7ed767e3b93498c487 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 01:17:26 +0000 Subject: [PATCH 21/58] build(deps-dev): bump tsd from 0.28.1 to 0.29.0 (#34) Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.28.1 to 0.29.0. - [Release notes](https://github.com/SamVerschueren/tsd/releases) - [Commits](https://github.com/SamVerschueren/tsd/compare/v0.28.1...v0.29.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c9511bd..bc009a2 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.28.0" + "tsd": "^0.29.0" }, "pre-commit": [ "lint", From 5d651a7b11ee5554032c13005f2c2b91557c2546 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 10 Sep 2023 10:29:52 +0100 Subject: [PATCH 22/58] perf: use `node:` prefix to bypass require.cache call for builtins (#35) --- test/standalone.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/standalone.test.js b/test/standalone.test.js index 51f773c..d8c5162 100644 --- a/test/standalone.test.js +++ b/test/standalone.test.js @@ -1,7 +1,7 @@ 'use strict' -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const t = require('tap') const fastify = require('fastify') const sanitize = require('sanitize-filename') From 8105c0c18bdbf7d8ea09843e2298ac1d5321b889 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 6 Oct 2023 21:46:29 +0100 Subject: [PATCH 23/58] chore: add `.gitattributes` file (#37) --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a0e7df9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Set default behavior to automatically convert line endings +* text=auto eol=lf From e92acdbf23449fa594d0a79aebde1160cea02c19 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 27 Oct 2023 14:51:15 +0100 Subject: [PATCH 24/58] chore(package): explicitly declare js module type (#38) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index bc009a2..b3180cc 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "description": "Build and manage the fast-json-stringify instances for the fastify framework", "version": "4.3.0", "main": "index.js", + "type": "commonjs", "types": "types/index.d.ts", "scripts": { "lint": "standard", From ba88b8a4a2ae0fd760decb9b2ab4dbb975b5542f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 00:43:33 +0000 Subject: [PATCH 25/58] build(deps-dev): bump tsd from 0.29.0 to 0.30.3 (#41) Bumps [tsd](https://github.com/tsdjs/tsd) from 0.29.0 to 0.30.3. - [Release notes](https://github.com/tsdjs/tsd/releases) - [Commits](https://github.com/tsdjs/tsd/compare/v0.29.0...v0.30.3) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b3180cc..7e459eb 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.29.0" + "tsd": "^0.30.3" }, "pre-commit": [ "lint", From 08261139d2ee2583193bf839df63e2418b6e00ca Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 14 Jan 2024 10:14:48 +0000 Subject: [PATCH 26/58] docs(readme): replace `fastify.io` links with `fastify.dev` (#42) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 911f7e0..5d3630a 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,12 @@ This package is responsible for compiling the application's `response` JSON sche 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. -You can also override the default configuration by passing the [`serializerOpts`](https://www.fastify.io/docs/latest/Reference/Server/#serializeropts) configuration to the Fastify instance. +You can also override the default configuration by passing the [`serializerOpts`](https://fastify.dev/docs/latest/Reference/Server/#serializeropts) configuration to the Fastify instance. ## Usage 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](https://www.fastify.io/docs/latest/Reference/Server/#schemacontroller). +If you need to provide to your server instance a different version, refer to [the official doc](https://fastify.dev/docs/latest/Reference/Server/#schemacontroller). ### fast-json-stringify Standalone @@ -120,7 +120,7 @@ app.listen({ port: 3000 }) ### How it works -This module provide a factory function to produce [Serializer Compilers](https://www.fastify.io/docs/latest/Reference/Server/#serializercompiler) functions. +This module provide a factory function to produce [Serializer Compilers](https://fastify.dev/docs/latest/Reference/Server/#serializercompiler) functions. ## License From 6c937f5738bb1691e3b5295cc3c3e02f7ec78f71 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 16 Jan 2024 11:31:06 +0000 Subject: [PATCH 27/58] docs(readme): fix broken link (#43) Signed-off-by: Frazer Smith --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d3630a..a29ab65 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Build and manage the [`fast-json-stringify`](https://www.npmjs.com/package/fast- 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/) -[![Continuous Integration](https://github.com/fastify/fast-json-stringify-compiler/workflows/Continuous%20Integration/badge.svg)](https://github.com/fastify/fast-json-stringify-compiler/actions/workflows/ci.yml) +[![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) ## Versions From ffbc6b5a96be13b5c03286e9582ef3f758ec0645 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Thu, 8 Feb 2024 19:53:55 +0000 Subject: [PATCH 28/58] chore(.gitignore): add .tap/ dir (#44) --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3c21249..2b6aed4 100644 --- a/.gitignore +++ b/.gitignore @@ -147,3 +147,6 @@ yarn.lock # editor files .vscode .idea + +#tap files +.tap/ From 6e8d53ac23618cd06e2c3caf806778098d810b8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:40:52 +0000 Subject: [PATCH 29/58] build(deps-dev): bump tsd from 0.30.7 to 0.31.0 (#46) Bumps [tsd](https://github.com/tsdjs/tsd) from 0.30.7 to 0.31.0. - [Release notes](https://github.com/tsdjs/tsd/releases) - [Commits](https://github.com/tsdjs/tsd/compare/v0.30.7...v0.31.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e459eb..7a2fe7f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "sanitize-filename": "^1.6.3", "standard": "^17.0.0", "tap": "^16.0.0", - "tsd": "^0.30.3" + "tsd": "^0.31.0" }, "pre-commit": [ "lint", From 407382aab39557adc9790a587caff4d029f54427 Mon Sep 17 00:00:00 2001 From: James Sumners <321201+jsumners@users.noreply.github.com> Date: Sun, 16 Jun 2024 07:34:53 -0400 Subject: [PATCH 30/58] Merge `next` into `main` (#51) * chore: updating dependencies and ci workflow * chore: update `plugins-ci` to v4.2.1 Co-authored-by: Matteo Gesmundo <46707463+Gesma94@users.noreply.github.com> --- .github/workflows/ci.yml | 5 +++-- package.json | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b00276..af5918d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,8 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.2.1 with: - license-check: true lint: true + license-check: true + node-versions: '["16", "18", "20", "22"]' diff --git a/package.json b/package.json index 7a2fe7f..cb298c3 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,11 @@ }, "homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", "devDependencies": { - "@fastify/pre-commit": "^2.0.2", - "fastify": "^4.0.0", + "@fastify/pre-commit": "^2.1.0", + "fastify": "^4.26.2", "sanitize-filename": "^1.6.3", - "standard": "^17.0.0", - "tap": "^16.0.0", + "standard": "^17.1.0", + "tap": "^18.7.2", "tsd": "^0.31.0" }, "pre-commit": [ @@ -36,6 +36,6 @@ "test" ], "dependencies": { - "fast-json-stringify": "^5.7.0" + "fast-json-stringify": "^5.14.1" } } From 8593cd0ec23552f0430fe824f91d68f64ab5f3fc Mon Sep 17 00:00:00 2001 From: James Sumners Date: Sun, 16 Jun 2024 07:35:35 -0400 Subject: [PATCH 31/58] v5.0.0-pre.fv5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb298c3..10ab763 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "4.3.0", + "version": "5.0.0-pre.fv5.1", "main": "index.js", "type": "commonjs", "types": "types/index.d.ts", From 4f8393bf1055ce2009a30ff9e0aa73d0b9b7785a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 01:13:28 +0000 Subject: [PATCH 32/58] build(deps): bump fast-json-stringify from 5.16.1 to 6.0.0 (#52) Bumps [fast-json-stringify](https://github.com/fastify/fast-json-stringify) from 5.16.1 to 6.0.0. - [Release notes](https://github.com/fastify/fast-json-stringify/releases) - [Commits](https://github.com/fastify/fast-json-stringify/compare/v5.16.1...v6.0.0) --- updated-dependencies: - dependency-name: fast-json-stringify dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10ab763..a62f0c4 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,6 @@ "test" ], "dependencies": { - "fast-json-stringify": "^5.14.1" + "fast-json-stringify": "^6.0.0" } } From 44cd2367181447d5c751ff7c56a883071a98d50e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 00:08:19 +0000 Subject: [PATCH 33/58] build(deps): bump fastify/workflows from 4.2.1 to 5.0.0 (#53) Bumps [fastify/workflows](https://github.com/fastify/workflows) from 4.2.1 to 5.0.0. - [Release notes](https://github.com/fastify/workflows/releases) - [Commits](https://github.com/fastify/workflows/compare/v4.2.1...v5.0.0) --- updated-dependencies: - dependency-name: fastify/workflows dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af5918d..49cf6cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.2.1 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.0 with: lint: true license-check: true From 8d721e209719c9362d5e4e8df5dc0ed9b161a217 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 4 Sep 2024 07:52:36 +0200 Subject: [PATCH 34/58] Bumped v5.0.0 Signed-off-by: Matteo Collina --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a62f0c4..5543077 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "5.0.0-pre.fv5.1", + "version": "5.0.0", "main": "index.js", "type": "commonjs", "types": "types/index.d.ts", @@ -25,7 +25,7 @@ "homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", "devDependencies": { "@fastify/pre-commit": "^2.1.0", - "fastify": "^4.26.2", + "fastify": "^5.0.0-alpha.4", "sanitize-filename": "^1.6.3", "standard": "^17.1.0", "tap": "^18.7.2", From 20364af153b33545f97c8e0ea7ffdadb27d3011e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 4 Sep 2024 16:02:38 +0200 Subject: [PATCH 35/58] update ci script Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49cf6cc..c2227cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,4 +21,3 @@ jobs: with: lint: true license-check: true - node-versions: '["16", "18", "20", "22"]' From 739b0ea56e9ebcbeb236401cd2fcb8b519a1fc0d Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Thu, 19 Sep 2024 13:46:41 +0100 Subject: [PATCH 36/58] chore: update fastify to ^5.0.0 (#54) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5543077..889105e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", "devDependencies": { "@fastify/pre-commit": "^2.1.0", - "fastify": "^5.0.0-alpha.4", + "fastify": "^5.0.0", "sanitize-filename": "^1.6.3", "standard": "^17.1.0", "tap": "^18.7.2", From 8f9560bfea2805f1d1dc4b12faa75ca494d3d204 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sat, 21 Sep 2024 10:43:13 +0200 Subject: [PATCH 37/58] Bumped v5.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 889105e..dcd593f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "5.0.0", + "version": "5.0.1", "main": "index.js", "type": "commonjs", "types": "types/index.d.ts", From dbc8f494111b799b7d99f8afbf345cbef216b75a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 00:10:48 +0000 Subject: [PATCH 38/58] build(deps): bump fastify/workflows from 5.0.0 to 5.0.1 (#55) Bumps [fastify/workflows](https://github.com/fastify/workflows) from 5.0.0 to 5.0.1. - [Release notes](https://github.com/fastify/workflows/releases) - [Commits](https://github.com/fastify/workflows/compare/v5.0.0...v5.0.1) --- updated-dependencies: - dependency-name: fastify/workflows dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2227cf..331495d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.0 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.1 with: lint: true license-check: true From 6acfedd9efeefa9bab74361b7a0da8b17e398768 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 1 Nov 2024 10:39:03 +0000 Subject: [PATCH 39/58] ci: use major version of workflows --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 331495d..8ef7a89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.1 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 with: lint: true license-check: true From 3c9ebdbcebfe86d5f031b805c3b58039dc3b419f Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 15:24:01 +0000 Subject: [PATCH 40/58] build(deps-dev): replace standard with neostandard (#56) * build(deps-dev): replace standard with neostandard * chore: add eslint.config.js * fix linting --------- Co-authored-by: Aras Abbasi --- eslint.config.js | 6 ++++++ package.json | 6 +++--- types/index.d.ts | 10 ++++----- types/index.test-d.ts | 50 +++++++++++++++++++++---------------------- 4 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 eslint.config.js diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..89fd678 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = require('neostandard')({ + ignores: require('neostandard').resolveIgnoresFromGitignore(), + ts: true +}) diff --git a/package.json b/package.json index dcd593f..0cd4f0c 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "unit": "tap test/**/*.test.js", "test": "npm run unit && npm run test:typescript", "test:typescript": "tsd" @@ -26,8 +26,8 @@ "devDependencies": { "@fastify/pre-commit": "^2.1.0", "fastify": "^5.0.0", + "neostandard": "^0.11.9", "sanitize-filename": "^1.6.3", - "standard": "^17.1.0", "tap": "^18.7.2", "tsd": "^0.31.0" }, diff --git a/types/index.d.ts b/types/index.d.ts index 26bbf1f..9f4645f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -6,12 +6,12 @@ declare namespace SerializerSelector { export type SerializerFactory = ( externalSchemas?: unknown, options?: Options - ) => SerializerCompiler; + ) => SerializerCompiler export type SerializerCompiler = ( externalSchemas?: unknown, options?: Options - ) => Serializer; + ) => Serializer export type Serializer = (doc: any) => string @@ -35,11 +35,11 @@ declare namespace SerializerSelector { } export type { Options } - export const SerializerSelector: FastJsonStringifyFactory; - export function StandaloneSerializer(options: StandaloneOptions): SerializerFactory; + export const SerializerSelector: FastJsonStringifyFactory + export function StandaloneSerializer (options: StandaloneOptions): SerializerFactory export { SerializerSelector as default } } -declare function SerializerSelector(...params: Parameters): ReturnType +declare function SerializerSelector (...params: Parameters): ReturnType export = SerializerSelector diff --git a/types/index.test-d.ts b/types/index.test-d.ts index d1dbd85..641c476 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,4 +1,4 @@ -import { expectAssignable, expectError, expectType } from "tsd"; +import { expectAssignable, expectError, expectType } from 'tsd' import SerializerSelector, { RouteDefinition, Serializer, @@ -6,43 +6,41 @@ import SerializerSelector, { SerializerFactory, SerializerSelector as SerializerSelectorNamed, StandaloneSerializer, -} from ".."; +} from '..' /** * SerializerSelector */ { - const compiler = SerializerSelector(); - expectType(compiler); + const compiler = SerializerSelector() + expectType(compiler) } { - const compiler = SerializerSelectorNamed(); - expectType(compiler); + const compiler = SerializerSelectorNamed() + expectType(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(factory); - const compiler = factory(externalSchemas1, {}) - expectType(compiler); - const serializeFunc = compiler({ schema: sampleSchema }) - expectType(serializeFunc); + const factory = SerializerSelector() + expectType(factory) + const compiler = factory(externalSchemas1, {}) + expectType(compiler) + const serializeFunc = compiler({ schema: sampleSchema }) + expectType(serializeFunc) - expectType(serializeFunc({ name: 'hello' })) - } + expectType(serializeFunc({ name: 'hello' })) } /** @@ -55,8 +53,8 @@ const reader = StandaloneSerializer({ expectAssignable(route) return {} as Serializer }, -}); -expectType(reader); +}) +expectType(reader) const writer = StandaloneSerializer({ readMode: false, @@ -64,8 +62,8 @@ const writer = StandaloneSerializer({ expectAssignable(route) expectAssignable(code) }, -}); -expectType(writer); +}) +expectType(writer) { const base = { From 9b55cf44854460d269771f1febc4727fe9194601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Dewitte?= Date: Wed, 11 Dec 2024 09:35:34 +0100 Subject: [PATCH 41/58] Fix `SerializerCompiler` type (#48) * Fix SerializerCompiler type * fix linting --------- Signed-off-by: Aras Abbasi Co-authored-by: Aras Abbasi --- types/index.d.ts | 6 +----- types/index.test-d.ts | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 9f4645f..0546135 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,11 +8,7 @@ declare namespace SerializerSelector { options?: Options ) => SerializerCompiler - export type SerializerCompiler = ( - externalSchemas?: unknown, - options?: Options - ) => Serializer - + export type SerializerCompiler = (routeDef: RouteDefinition) => Serializer export type Serializer = (doc: any) => string export type RouteDefinition = { diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 641c476..018759a 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -37,7 +37,7 @@ import SerializerSelector, { expectType(factory) const compiler = factory(externalSchemas1, {}) expectType(compiler) - const serializeFunc = compiler({ schema: sampleSchema }) + const serializeFunc = compiler({ schema: sampleSchema, method: '', url: '', httpStatus: '' }) expectType(serializeFunc) expectType(serializeFunc({ name: 'hello' })) @@ -86,6 +86,9 @@ expectType(writer) } const endpointSchema = { + method: '', + url: '', + httpStatus: '', schema: { $id: 'urn:schema:endpoint', $ref: 'urn:schema:ref' From a11a40391c0435841a0b9b6db63471ebea5048e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 00:29:57 +0000 Subject: [PATCH 42/58] build(deps-dev): bump neostandard from 0.11.9 to 0.12.0 (#57) Bumps [neostandard](https://github.com/neostandard/neostandard) from 0.11.9 to 0.12.0. - [Release notes](https://github.com/neostandard/neostandard/releases) - [Changelog](https://github.com/neostandard/neostandard/blob/main/CHANGELOG.md) - [Commits](https://github.com/neostandard/neostandard/compare/v0.11.9...v0.12.0) --- updated-dependencies: - dependency-name: neostandard dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0cd4f0c..6fd5687 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "@fastify/pre-commit": "^2.1.0", "fastify": "^5.0.0", - "neostandard": "^0.11.9", + "neostandard": "^0.12.0", "sanitize-filename": "^1.6.3", "tap": "^18.7.2", "tsd": "^0.31.0" From 25fb0c4e4a90a95af2df488d1e528c18d1da63e2 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 16 Dec 2024 19:52:54 +0000 Subject: [PATCH 43/58] build(deps-dev): add eslint, peer dep of neostandard (#58) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6fd5687..b9af5b3 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "homepage": "https://github.com/fastify/fast-json-stringify-compiler#readme", "devDependencies": { "@fastify/pre-commit": "^2.1.0", + "eslint": "^9.17.0", "fastify": "^5.0.0", "neostandard": "^0.12.0", "sanitize-filename": "^1.6.3", From 9d8178323309c2ae8272f46d71bfdbacf8cf8a77 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 22 Dec 2024 12:02:20 +0000 Subject: [PATCH 44/58] chore(package): add contribs and funding (#59) Signed-off-by: Frazer Smith --- package.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/package.json b/package.json index b9af5b3..655ec1f 100644 --- a/package.json +++ b/package.json @@ -18,11 +18,40 @@ }, "keywords": [], "author": "Manuel Spigolon (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", "bugs": { "url": "https://github.com/fastify/fast-json-stringify-compiler/issues" }, "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", From 38d94f516f2095adaa35e9bb615a91ae30947eee Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 4 Jan 2025 18:55:01 +0000 Subject: [PATCH 45/58] test: prefix unused params with underscores (#60) --- test/plugin.test.js | 2 +- test/standalone.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/plugin.test.js b/test/plugin.test.js index df2582b..11e34d8 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -4,7 +4,7 @@ const t = require('tap') const fastify = require('fastify') const FjsCompiler = require('../index') -const echo = async (req, reply) => { return req.body } +const echo = async (req) => { return req.body } const sampleSchema = Object.freeze({ $id: 'example1', diff --git a/test/standalone.test.js b/test/standalone.test.js index d8c5162..ba11330 100644 --- a/test/standalone.test.js +++ b/test/standalone.test.js @@ -23,7 +23,7 @@ t.test('standalone', t => { for (const fileName of generatedFileNames) { try { await fs.promises.unlink(path.join(__dirname, fileName)) - } catch (e) {} + } catch {} } }) From 724c953b30dff02d96e5d55971093cbe1dd72cdd Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 4 Jan 2025 18:56:25 +0000 Subject: [PATCH 46/58] docs(readme): grammar fixes (#61) Signed-off-by: Frazer Smith --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a29ab65..a9bf8eb 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # @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. ## Versions @@ -17,7 +18,7 @@ This package is responsible for compiling the application's `response` JSON sche ### fast-json-stringify Configuration -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. You can also override the default configuration by passing the [`serializerOpts`](https://fastify.dev/docs/latest/Reference/Server/#serializeropts) configuration to the Fastify instance. @@ -28,7 +29,7 @@ If you need to provide to your server instance a different version, refer to [th ### fast-json-stringify Standalone -`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. To use this feature, you must be aware of the following: @@ -43,7 +44,7 @@ To accomplish this, you must use a new compiler: `@fastify/fast-json-stringify-c You must provide 2 parameters to this compiler: -- `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. When `readMode: false`, **the compiler is meant to be used in development ONLY**. @@ -84,7 +85,7 @@ app.ready().then(() => { 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 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. Important keep away before you continue reading the documentation: @@ -120,7 +121,7 @@ app.listen({ port: 3000 }) ### How it works -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. ## License From 1afe4c87b137245714945af79550f87826cdefc0 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sat, 4 Jan 2025 18:56:48 +0000 Subject: [PATCH 47/58] 5.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 655ec1f..c409304 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "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", "type": "commonjs", "types": "types/index.d.ts", From 8391f8e217a3cee6400627f68257e9d4a4d58793 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Wed, 15 Jan 2025 15:28:57 +0000 Subject: [PATCH 48/58] build(dependabot): reduce npm updates to monthly (#62) --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index dfa7fa6..35d66ca 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,5 +9,5 @@ updates: - package-ecosystem: "npm" directory: "/" schedule: - interval: "weekly" + interval: "monthly" open-pull-requests-limit: 10 From 0b0292ad1c006e1e2c5f39bc90f8b7481631161e Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 3 Feb 2025 09:57:27 +0000 Subject: [PATCH 49/58] ci: remove master branch support (#63) --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ef7a89..7ddf009 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - master - next - 'v*' paths-ignore: From eebe7d9aa32fdc89f283ae0f673f158d0dfec086 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sat, 1 Mar 2025 09:36:33 +0100 Subject: [PATCH 50/58] feat: migrate to node test runner (#64) --- package.json | 4 +-- test/duplicate-schema.test.js | 6 ++--- test/plugin.test.js | 12 ++++----- test/standalone.test.js | 46 +++++++++++++++++------------------ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index c409304..6dd335d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "lint": "eslint", "lint:fix": "eslint --fix", - "unit": "tap test/**/*.test.js", + "unit": "c8 --100 node --test", "test": "npm run unit && npm run test:typescript", "test:typescript": "tsd" }, @@ -54,11 +54,11 @@ ], "devDependencies": { "@fastify/pre-commit": "^2.1.0", + "c8": "^10.1.3", "eslint": "^9.17.0", "fastify": "^5.0.0", "neostandard": "^0.12.0", "sanitize-filename": "^1.6.3", - "tap": "^18.7.2", "tsd": "^0.31.0" }, "pre-commit": [ diff --git a/test/duplicate-schema.test.js b/test/duplicate-schema.test.js index d6904ed..2acaa24 100644 --- a/test/duplicate-schema.test.js +++ b/test/duplicate-schema.test.js @@ -1,9 +1,9 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const FjsCompiler = require('../index') -t.test('Use input schema duplicate in the externalSchemas', async t => { +test('Use input schema duplicate in the externalSchemas', async t => { t.plan(1) const externalSchemas = { schema1: { @@ -22,5 +22,5 @@ t.test('Use input schema duplicate in the externalSchemas', async t => { compiler({ schema: externalSchemas.schema1 }) compiler({ schema: externalSchemas.schema2 }) - t.pass() + t.assert.ok(true) }) diff --git a/test/plugin.test.js b/test/plugin.test.js index 11e34d8..26ca0f5 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -1,6 +1,6 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const FjsCompiler = require('../index') @@ -27,16 +27,16 @@ const externalSchemas2 = Object.freeze({ const fastifyFjsOptionsDefault = Object.freeze({}) -t.test('basic usage', t => { +test('basic usage', t => { t.plan(1) const factory = FjsCompiler() const compiler = factory(externalSchemas1, fastifyFjsOptionsDefault) const serializeFunc = compiler({ schema: sampleSchema }) const result = serializeFunc({ name: 'hello' }) - t.equal(result, '{"name":"hello"}') + t.assert.equal(result, '{"name":"hello"}') }) -t.test('fastify integration', async t => { +test('fastify integration', async t => { const factory = FjsCompiler() const app = fastify({ @@ -73,6 +73,6 @@ t.test('fastify integration', async t => { } }) - t.equal(res.statusCode, 200) - t.same(res.json(), { name: 'serialize me' }) + t.assert.equal(res.statusCode, 200) + t.assert.deepStrictEqual(res.json(), { name: 'serialize me' }) }) diff --git a/test/standalone.test.js b/test/standalone.test.js index ba11330..6ecdc17 100644 --- a/test/standalone.test.js +++ b/test/standalone.test.js @@ -2,7 +2,7 @@ const fs = require('node:fs') const path = require('node:path') -const t = require('tap') +const { test } = require('node:test') const fastify = require('fastify') const sanitize = require('sanitize-filename') @@ -16,10 +16,10 @@ function generateFileName (routeOpts) { return fileName } -t.test('standalone', t => { +test('standalone', async t => { t.plan(5) - t.teardown(async () => { + t.after(async () => { for (const fileName of generatedFileNames) { try { await fs.promises.unlink(path.join(__dirname, fileName)) @@ -29,10 +29,10 @@ t.test('standalone', t => { t.test('errors', t => { t.plan(2) - t.throws(() => { + t.assert.throws(() => { FjsStandaloneCompiler() }, 'missing restoreFunction') - t.throws(() => { + t.assert.throws(() => { FjsStandaloneCompiler({ readMode: false }) }, 'missing storeFunction') }) @@ -74,28 +74,28 @@ t.test('standalone', t => { const factory = FjsStandaloneCompiler({ readMode: false, storeFunction (routeOpts, schemaSerializerCode) { - t.same(routeOpts, endpointSchema) - t.type(schemaSerializerCode, 'string') + t.assert.deepStrictEqual(routeOpts, endpointSchema) + t.assert.ok(typeof schemaSerializerCode === 'string') fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode) generatedFileNames.push('/fjs-generated.js') - t.pass('stored the serializer function') + t.assert.ok('stored the serializer function') } }) const compiler = factory(schemaMap) compiler(endpointSchema) - t.pass('compiled the endpoint schema') + t.assert.ok('compiled the endpoint schema') t.test('usage standalone code', t => { t.plan(3) const standaloneSerializer = require('./fjs-generated') - t.ok(standaloneSerializer) + t.assert.ok(standaloneSerializer) const valid = standaloneSerializer({ hello: 'world' }) - t.same(valid, JSON.stringify({ hello: 'world' })) + t.assert.deepStrictEqual(valid, JSON.stringify({ hello: 'world' })) const invalid = standaloneSerializer({ hello: [] }) - t.same(invalid, '{"hello":""}') + t.assert.deepStrictEqual(invalid, '{"hello":""}') }) }) @@ -106,9 +106,9 @@ t.test('standalone', t => { readMode: false, storeFunction (routeOpts, schemaSerializationCode) { const fileName = generateFileName(routeOpts) - t.ok(routeOpts) + t.assert.ok(routeOpts) fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) - t.pass(`stored the serializer function ${fileName}`) + t.assert.ok(`stored the serializer function ${fileName}`) }, restoreFunction () { t.fail('write mode ON') @@ -119,16 +119,16 @@ t.test('standalone', t => { await app.ready() }) - t.test('fastify integration - writeMode forces standalone', async t => { + await t.test('fastify integration - writeMode forces standalone', async t => { t.plan(4) const factory = FjsStandaloneCompiler({ readMode: false, storeFunction (routeOpts, schemaSerializationCode) { const fileName = generateFileName(routeOpts) - t.ok(routeOpts) + t.assert.ok(routeOpts) fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode) - t.pass(`stored the serializer function ${fileName}`) + t.assert.ok(`stored the serializer function ${fileName}`) }, restoreFunction () { t.fail('write mode ON') @@ -143,7 +143,7 @@ t.test('standalone', t => { await app.ready() }) - t.test('fastify integration - readMode', async t => { + await t.test('fastify integration - readMode', async t => { t.plan(6) const factory = FjsStandaloneCompiler({ @@ -153,7 +153,7 @@ t.test('standalone', t => { }, restoreFunction (routeOpts) { const fileName = generateFileName(routeOpts) - t.pass(`restore the serializer function ${fileName}}`) + t.assert.ok(`restore the serializer function ${fileName}}`) return require(path.join(__dirname, fileName)) } }) @@ -165,15 +165,15 @@ t.test('standalone', t => { url: '/foo', method: 'POST' }) - t.equal(res.statusCode, 200) - t.equal(res.payload, JSON.stringify({ hello: 'world' })) + t.assert.equal(res.statusCode, 200) + t.assert.equal(res.payload, JSON.stringify({ hello: 'world' })) res = await app.inject({ url: '/bar?lang=it', method: 'GET' }) - t.equal(res.statusCode, 200) - t.equal(res.payload, JSON.stringify({ lang: 'en' })) + t.assert.equal(res.statusCode, 200) + t.assert.equal(res.payload, JSON.stringify({ lang: 'en' })) }) function buildApp (factory, serializerOpts) { From 8d874102a6b08f86d0cede9098b5923720e71c9c Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Sat, 1 Mar 2025 11:28:53 +0100 Subject: [PATCH 51/58] chore: fix doc support version (#65) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9bf8eb..dcc1ecd 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This package is responsible for compiling the application's `response` JSON sche | v1.x | v3.x | ^3.x | | v2.x | v3.x | ^4.x | | v3.x | v4.x | ^4.x | -| v4.x | v5.x | ^4.x | +| v4.x | v5.x | ^5.x | ### fast-json-stringify Configuration From fb165e6d80ed210de698ed49e24b93b1aa8e1cb4 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 7 Mar 2025 19:08:57 +0000 Subject: [PATCH 52/58] ci(ci): set job permissions (#66) --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ddf009..f9fae55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,10 @@ on: jobs: test: + permissions: + contents: write + pull-requests: write uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 with: - lint: true license-check: true + lint: true From 4e822331621b23378244a15b2c8215628ca7c188 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 30 Mar 2025 21:53:35 +0100 Subject: [PATCH 53/58] ci: set permissions at workflow level (#67) --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9fae55..d2a8b62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,11 +14,11 @@ on: - 'docs/**' - '*.md' +permissions: + contents: read + jobs: test: - permissions: - contents: write - pull-requests: write uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 with: license-check: true From a5a8fdfb9faf71115cd94248548963012f39c38b Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 30 Mar 2025 22:34:49 +0100 Subject: [PATCH 54/58] ci: restore job level permissions (#68) --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2a8b62..fd45202 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,9 @@ permissions: jobs: test: + permissions: + contents: write + pull-requests: write uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5 with: license-check: true From 1ee09838184fb227b99db7c3faa95de2c1539f42 Mon Sep 17 00:00:00 2001 From: Satana Charuwichitratana Date: Tue, 8 Apr 2025 15:05:32 +0700 Subject: [PATCH 55/58] fix: circular dependencies (#70) --- index.js | 19 ++----------------- standalone.js | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index a021ea1..9323c97 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,8 @@ 'use strict' -const fastJsonStringify = require('fast-json-stringify') - -function SerializerSelector () { - return function buildSerializerFactory (externalSchemas, serializerOpts) { - const fjsOpts = Object.assign({}, serializerOpts, { schema: externalSchemas }) - return responseSchemaCompiler.bind(null, fjsOpts) - } -} - -function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ }) { - if (fjsOpts.schema && schema.$id && fjsOpts.schema[schema.$id]) { - fjsOpts.schema = { ...fjsOpts.schema } - delete fjsOpts.schema[schema.$id] - } - return fastJsonStringify(schema, fjsOpts) -} +const { SerializerSelector, StandaloneSerializer } = require('./standalone') module.exports = SerializerSelector module.exports.default = SerializerSelector module.exports.SerializerSelector = SerializerSelector -module.exports.StandaloneSerializer = require('./standalone') +module.exports.StandaloneSerializer = StandaloneSerializer diff --git a/standalone.js b/standalone.js index 39b4937..7f0d40a 100644 --- a/standalone.js +++ b/standalone.js @@ -1,6 +1,21 @@ 'use strict' -const SerializerSelector = require('./index') +const fastJsonStringify = require('fast-json-stringify') + +function SerializerSelector () { + return function buildSerializerFactory (externalSchemas, serializerOpts) { + const fjsOpts = Object.assign({}, serializerOpts, { schema: externalSchemas }) + return responseSchemaCompiler.bind(null, fjsOpts) + } +} + +function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ }) { + if (fjsOpts.schema && schema.$id && fjsOpts.schema[schema.$id]) { + fjsOpts.schema = { ...fjsOpts.schema } + delete fjsOpts.schema[schema.$id] + } + return fastJsonStringify(schema, fjsOpts) +} function StandaloneSerializer (options = { readMode: true }) { if (options.readMode === true && typeof options.restoreFunction !== 'function') { @@ -38,5 +53,6 @@ function StandaloneSerializer (options = { readMode: true }) { } } -module.exports = StandaloneSerializer +module.exports.SerializerSelector = SerializerSelector +module.exports.StandaloneSerializer = StandaloneSerializer module.exports.default = StandaloneSerializer From 8ea011034b2880e994422fe61fe2c473cd4cbd49 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Tue, 8 Apr 2025 10:11:00 +0200 Subject: [PATCH 56/58] Bumped v5.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6dd335d..cc104b7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fastify/fast-json-stringify-compiler", "description": "Build and manage the fast-json-stringify instances for the fastify framework", - "version": "5.0.2", + "version": "5.0.3", "main": "index.js", "type": "commonjs", "types": "types/index.d.ts", From 9013cde7add9171e48caff49a715e73308334915 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 00:53:23 +0000 Subject: [PATCH 57/58] build(deps-dev): bump tsd from 0.31.2 to 0.32.0 (#71) Bumps [tsd](https://github.com/tsdjs/tsd) from 0.31.2 to 0.32.0. - [Release notes](https://github.com/tsdjs/tsd/releases) - [Commits](https://github.com/tsdjs/tsd/compare/v0.31.2...v0.32.0) --- updated-dependencies: - dependency-name: tsd dependency-version: 0.32.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc104b7..0215c45 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "fastify": "^5.0.0", "neostandard": "^0.12.0", "sanitize-filename": "^1.6.3", - "tsd": "^0.31.0" + "tsd": "^0.32.0" }, "pre-commit": [ "lint", From a9448017bb8cc5aceb8bd3cd96c9604cc127c789 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 23 Jun 2025 12:29:13 +0100 Subject: [PATCH 58/58] chore(license): update date ranges; standardise style (#72) --- LICENSE | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 5559f4f..1d7c1ee 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,8 @@ MIT License -Copyright (c) 2022 Fastify +Copyright (c) 2022-present The Fastify team + +The Fastify team members are listed at https://github.com/fastify/fastify#team. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal