🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@fastify/fast-json-stringify-compiler

Package Overview
Dependencies
Maintainers
18
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/fast-json-stringify-compiler - npm Package Compare versions

Comparing version
5.0.3
to
5.1.0
+19
.github/workflows/lock-threads.yml
name: Lock Threads
on:
schedule:
- cron: '0 0 1 * *'
workflow_dispatch:
concurrency:
group: lock
permissions:
contents: read
jobs:
lock-threads:
permissions:
issues: write
pull-requests: write
uses: fastify/workflows/.github/workflows/lock-threads.yml@v6
import { expect } from 'tstyche'
import SerializerSelector, {
RouteDefinition,
Serializer,
SerializerCompiler,
SerializerFactory,
SerializerSelector as SerializerSelectorNamed,
StandaloneSerializer,
} from '..'
/**
* SerializerSelector
*/
{
const compiler = SerializerSelector()
expect(compiler).type.toBe<SerializerFactory>()
}
{
const compiler = SerializerSelectorNamed()
expect(compiler).type.toBe<SerializerFactory>()
}
{
const sampleSchema = {
$id: 'example1',
type: 'object',
properties: {
name: { type: 'string' }
}
}
const externalSchemas1 = {}
const factory = SerializerSelector()
expect(factory).type.toBe<SerializerFactory>()
const compiler = factory(externalSchemas1, {})
expect(compiler).type.toBe<SerializerCompiler>()
const serializeFunc = compiler({ schema: sampleSchema, method: '', url: '', httpStatus: '' })
expect(serializeFunc).type.toBe<Serializer>()
expect(serializeFunc({ name: 'hello' })).type.toBe<string>()
}
/**
* StandaloneSerializer
*/
const reader = StandaloneSerializer({
readMode: true,
restoreFunction: (route) => {
expect(route).type.toBe<RouteDefinition>()
return {} as Serializer
},
})
expect(reader).type.toBe<SerializerFactory>()
const writer = StandaloneSerializer({
readMode: false,
storeFunction: (route, code) => {
expect(route).type.toBe<RouteDefinition>()
expect(code).type.toBe<string>()
},
})
expect(writer).type.toBe<SerializerFactory>()
{
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 = {
method: '',
url: '',
httpStatus: '',
schema: {
$id: 'urn:schema:endpoint',
$ref: 'urn:schema:ref'
}
}
const schemaMap = {
[base.$id]: base,
[refSchema.$id]: refSchema
}
expect(StandaloneSerializer).type.not.toBeCallableWith({
readMode: true,
storeFunction () { }
})
expect(StandaloneSerializer).type.not.toBeCallableWith({
readMode: false,
restoreFunction () {}
})
expect(StandaloneSerializer).type.not.toBeCallableWith({
restoreFunction () {}
})
expect(StandaloneSerializer({
storeFunction (routeOpts, schemaSerializerCode) {
expect(routeOpts).type.toBe<RouteDefinition>()
expect(schemaSerializerCode).type.toBe<string>()
}
})).type.toBe<SerializerFactory>()
expect(StandaloneSerializer({
readMode: true,
restoreFunction (routeOpts) {
expect(routeOpts).type.toBe<RouteDefinition>()
return {} as Serializer
}
})).type.toBe<SerializerFactory>()
const factory = StandaloneSerializer({
readMode: false,
storeFunction (routeOpts, schemaSerializerCode) {
expect(routeOpts).type.toBe<RouteDefinition>()
expect(schemaSerializerCode).type.toBe<string>()
}
})
expect(factory).type.toBe<SerializerFactory>()
const compiler = factory(schemaMap)
expect(compiler).type.toBe<SerializerCompiler>()
expect(compiler(endpointSchema)).type.toBe<Serializer>()
}
+42
-2

@@ -5,4 +5,13 @@ version: 2

directory: "/"
commit-message:
# Prefix all commit messages with "chore: "
prefix: "chore"
schedule:
interval: "monthly"
interval: "weekly"
cooldown:
default-days: 7
allow:
- dependency-name: "*"
update-types:
- "version-update:semver-major"
open-pull-requests-limit: 10

@@ -12,4 +21,35 @@

directory: "/"
commit-message:
# Prefix all commit messages with "chore: "
prefix: "chore"
schedule:
interval: "monthly"
interval: "weekly"
cooldown:
default-days: 7
versioning-strategy: "increase-if-necessary"
allow:
- dependency-name: "*"
update-types:
- "version-update:semver-major"
ignore:
# TODO: remove ignore until neostandard support ESLint 10
- dependency-name: "eslint"
- dependency-name: "neostandard"
- dependency-name: "@stylistic/*"
open-pull-requests-limit: 10
groups:
# Production dependencies with breaking changes
dependencies:
dependency-type: "production"
# ESLint related dependencies
dev-dependencies-eslint:
patterns:
- "eslint"
- "neostandard"
- "@stylistic/*"
# TypeScript related dependencies
dev-dependencies-typescript:
patterns:
- "@types/*"
- "tstyche"
- "typescript"

@@ -17,2 +17,7 @@ name: CI

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true
permissions:

@@ -26,5 +31,5 @@ contents: read

pull-requests: write
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v6
with:
license-check: true
lint: true
+1
-1
MIT License
Copyright (c) 2022 Fastify
Copyright (c) 2022-present The Fastify team <https://github.com/fastify/fastify#team>

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "@fastify/fast-json-stringify-compiler",
"description": "Build and manage the fast-json-stringify instances for the fastify framework",
"version": "5.0.3",
"version": "5.1.0",
"main": "index.js",

@@ -13,3 +13,3 @@ "type": "commonjs",

"test": "npm run unit && npm run test:typescript",
"test:typescript": "tsd"
"test:typescript": "tstyche"
},

@@ -57,17 +57,12 @@ "repository": {

"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"c8": "^10.1.3",
"c8": "^11.0.0",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"neostandard": "^0.12.0",
"neostandard": "^0.13.0",
"sanitize-filename": "^1.6.3",
"tsd": "^0.31.0"
"tstyche": "^7.1.0"
},
"pre-commit": [
"lint",
"test"
],
"dependencies": {
"fast-json-stringify": "^6.0.0"
"fast-json-stringify": "^7.0.0"
}
}

@@ -32,3 +32,3 @@ # @fastify/fast-json-stringify-compiler

`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.
`fast-json-stringify@v4.1.0` introduces the [standalone feature](https://github.com/fastify/fast-json-stringify#standalone-mode) that lets you pre-compile your schemas and use them in your application for a faster startup.

@@ -35,0 +35,0 @@ To use this feature, you must be aware of the following:

{"extends": "standard"}
import { expectAssignable, expectError, expectType } from 'tsd'
import SerializerSelector, {
RouteDefinition,
Serializer,
SerializerCompiler,
SerializerFactory,
SerializerSelector as SerializerSelectorNamed,
StandaloneSerializer,
} from '..'
/**
* SerializerSelector
*/
{
const compiler = SerializerSelector()
expectType<SerializerFactory>(compiler)
}
{
const compiler = SerializerSelectorNamed()
expectType<SerializerFactory>(compiler)
}
{
const sampleSchema = {
$id: 'example1',
type: 'object',
properties: {
name: { type: 'string' }
}
}
const externalSchemas1 = {}
const factory = SerializerSelector()
expectType<SerializerFactory>(factory)
const compiler = factory(externalSchemas1, {})
expectType<SerializerCompiler>(compiler)
const serializeFunc = compiler({ schema: sampleSchema, method: '', url: '', httpStatus: '' })
expectType<Serializer>(serializeFunc)
expectType<string>(serializeFunc({ name: 'hello' }))
}
/**
* StandaloneSerializer
*/
const reader = StandaloneSerializer({
readMode: true,
restoreFunction: (route: RouteDefinition) => {
expectAssignable<RouteDefinition>(route)
return {} as Serializer
},
})
expectType<SerializerFactory>(reader)
const writer = StandaloneSerializer({
readMode: false,
storeFunction: (route: RouteDefinition, code: string) => {
expectAssignable<RouteDefinition>(route)
expectAssignable<string>(code)
},
})
expectType<SerializerFactory>(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 = {
method: '',
url: '',
httpStatus: '',
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<SerializerFactory>(StandaloneSerializer({
storeFunction (routeOpts, schemaSerializerCode) {
expectType<RouteDefinition>(routeOpts)
expectType<string>(schemaSerializerCode)
}
}))
expectType<SerializerFactory>(StandaloneSerializer({
readMode: true,
restoreFunction (routeOpts) {
expectType<RouteDefinition>(routeOpts)
return {} as Serializer
}
}))
const factory = StandaloneSerializer({
readMode: false,
storeFunction (routeOpts, schemaSerializerCode) {
expectType<RouteDefinition>(routeOpts)
expectType<string>(schemaSerializerCode)
}
})
expectType<SerializerFactory>(factory)
const compiler = factory(schemaMap)
expectType<SerializerCompiler>(compiler)
expectType<Serializer>(compiler(endpointSchema))
}