First commit

This commit is contained in:
2026-01-12 13:12:46 +01:00
parent b2d9501f6d
commit a1fbd8acf5
4413 changed files with 1245183 additions and 0 deletions

2
node_modules/@fastify/error/.gitattributes generated vendored Normal file
View File

@@ -0,0 +1,2 @@
# Set default behavior to automatically convert line endings
* text=auto eol=lf

13
node_modules/@fastify/error/.github/dependabot.yml generated vendored Normal file
View File

@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
open-pull-requests-limit: 10
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10

23
node_modules/@fastify/error/.github/workflows/ci.yml generated vendored Normal file
View File

@@ -0,0 +1,23 @@
name: CI
on:
push:
branches:
- main
- master
- next
- 'v*'
paths-ignore:
- 'docs/**'
- '*.md'
pull_request:
paths-ignore:
- 'docs/**'
- '*.md'
jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
with:
license-check: true
lint: true

2
node_modules/@fastify/error/.taprc generated vendored Normal file
View File

@@ -0,0 +1,2 @@
files:
- test/**/*.test.js

21
node_modules/@fastify/error/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Fastify
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

62
node_modules/@fastify/error/README.md generated vendored Normal file
View File

@@ -0,0 +1,62 @@
# @fastify/error
![CI](https://github.com/fastify/fastify-error/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/@fastify/error.svg?style=flat)](https://www.npmjs.com/package/@fastify/error)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.
### Install
```
npm i @fastify/error
```
### Usage
The module exports a function that you can use for consistent error objects, it takes 4 parameters:
```
createError(code, message [, statusCode [, Base]])
```
- `code` (`string`, required) - The error code, you can access it later with `error.code`. For consistency, we recommend prefixing plugin error codes with `FST_`
- `message` (`string`, required) - The error message. You can also use interpolated strings for formatting the message.
- `statusCode` (`number`, optional) - The status code that Fastify will use if the error is sent via HTTP.
- `Base` (`ErrorConstructor`, optional) - The base error object that will be used. (eg `TypeError`, `RangeError`)
```js
const createError = require('@fastify/error')
const CustomError = createError('ERROR_CODE', 'Hello')
console.log(new CustomError()) // error.message => 'Hello'
```
How to use an interpolated string:
```js
const createError = require('@fastify/error')
const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world')) // error.message => 'Hello world'
```
How to add cause:
```js
const createError = require('@fastify/error')
const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world', {cause: new Error('cause')}))
// error.message => 'Hello world'
// error.cause => Error('cause')
```
### TypeScript
It is possible to limit your error constructor with a generic type using TypeScript:
```ts
const CustomError = createError<[string]>('ERROR_CODE', 'Hello %s')
new CustomError('world')
//@ts-expect-error
new CustomError(1)
```
## License
Licensed under [MIT](./LICENSE).

9
node_modules/@fastify/error/benchmarks/create.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
'use strict'
const benchmark = require('benchmark')
const createError = require('..')
new benchmark.Suite()
.add('create FastifyError', function () { createError('CODE', 'Not available') }, { minSamples: 100 })
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
.run({ async: false })

18
node_modules/@fastify/error/benchmarks/instantiate.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
'use strict'
const benchmark = require('benchmark')
const createError = require('..')
const FastifyError = createError('CODE', 'Not available')
const FastifyError1 = createError('CODE', 'Not %s available')
const FastifyError2 = createError('CODE', 'Not %s available %s')
const cause = new Error('cause')
new benchmark.Suite()
.add('instantiate Error', function () { new Error() }, { minSamples: 100 }) // eslint-disable-line no-new
.add('instantiate FastifyError', function () { new FastifyError() }, { minSamples: 100 }) // eslint-disable-line no-new
.add('instantiate FastifyError arg 1', function () { new FastifyError1('q') }, { minSamples: 100 }) // eslint-disable-line no-new
.add('instantiate FastifyError arg 2', function () { new FastifyError2('qq', 'ss') }, { minSamples: 100 }) // eslint-disable-line no-new
.add('instantiate FastifyError cause', function () { new FastifyError2({ cause }) }, { minSamples: 100 }) // eslint-disable-line no-new
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
.run({ async: false })

13
node_modules/@fastify/error/benchmarks/no-stack.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
'use strict'
const benchmark = require('benchmark')
const createError = require('..')
const FastifyError = createError('CODE', 'Not available')
Error.stackTraceLimit = 0
new benchmark.Suite()
.add('no-stack instantiate Error', function () { new Error() }, { minSamples: 100 }) // eslint-disable-line no-new
.add('no-stack instantiate FastifyError', function () { new FastifyError() }, { minSamples: 100 }) // eslint-disable-line no-new
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
.run({ async: false })

11
node_modules/@fastify/error/benchmarks/toString.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
'use strict'
const benchmark = require('benchmark')
const createError = require('..')
const FastifyError = createError('CODE', 'Not available')
new benchmark.Suite()
.add('FastifyError toString', function () { new FastifyError().toString() }, { minSamples: 100 })
.on('cycle', function onCycle (event) { console.log(String(event.target)) })
.run({ async: false })

53
node_modules/@fastify/error/index.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
'use strict'
const { format } = require('node:util')
function toString () {
return `${this.name} [${this.code}]: ${this.message}`
}
function createError (code, message, statusCode = 500, Base = Error) {
if (!code) throw new Error('Fastify error code must not be empty')
if (!message) throw new Error('Fastify error message must not be empty')
code = code.toUpperCase()
!statusCode && (statusCode = undefined)
function FastifyError (...args) {
if (!new.target) {
return new FastifyError(...args)
}
this.code = code
this.name = 'FastifyError'
this.statusCode = statusCode
const lastElement = args.length - 1
if (lastElement !== -1 && args[lastElement] && typeof args[lastElement] === 'object' && 'cause' in args[lastElement]) {
this.cause = args.pop().cause
}
this.message = format(message, ...args)
Error.stackTraceLimit !== 0 && Error.captureStackTrace(this, FastifyError)
}
FastifyError.prototype = Object.create(Base.prototype, {
constructor: {
value: FastifyError,
enumerable: false,
writable: true,
configurable: true
}
})
FastifyError.prototype[Symbol.toStringTag] = 'Error'
FastifyError.prototype.toString = toString
return FastifyError
}
module.exports = createError
module.exports.default = createError
module.exports.createError = createError

45
node_modules/@fastify/error/package.json generated vendored Normal file
View File

@@ -0,0 +1,45 @@
{
"name": "@fastify/error",
"version": "3.4.1",
"description": "A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.",
"main": "index.js",
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard",
"lint:fix": "standard --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:typescript": "tsd"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fastify/fastify-error.git"
},
"keywords": [
"fastify",
"error",
"utility",
"plugin"
],
"author": "Tomas Della Vedova",
"license": "MIT",
"bugs": {
"url": "https://github.com/fastify/fastify-error/issues"
},
"homepage": "https://github.com/fastify/fastify-error#readme",
"devDependencies": {
"benchmark": "^2.1.4",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.29.0"
},
"tsd": {
"compilerOptions": {
"esModuleInterop": true
}
},
"publishConfig": {
"access": "public"
}
}

184
node_modules/@fastify/error/test/index.test.js generated vendored Normal file
View File

@@ -0,0 +1,184 @@
'use strict'
const { test } = require('tap')
const createError = require('..')
test('Create error with zero parameter', t => {
t.plan(6)
const NewError = createError('CODE', 'Not available')
const err = new NewError()
t.ok(err instanceof Error)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'Not available')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create error with 1 parameter', t => {
t.plan(6)
const NewError = createError('CODE', 'hey %s')
const err = new NewError('alice')
t.ok(err instanceof Error)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'hey alice')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create error with 1 parameter set to undefined', t => {
t.plan(1)
const NewError = createError('CODE', 'hey %s')
const err = new NewError(undefined)
t.equal(err.message, 'hey undefined')
})
test('Create error with 2 parameters', (t) => {
t.plan(6)
const NewError = createError('CODE', 'hey %s, I like your %s')
const err = new NewError('alice', 'attitude')
t.ok(err instanceof Error)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'hey alice, I like your attitude')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create error with 2 parameters set to undefined', t => {
t.plan(1)
const NewError = createError('CODE', 'hey %s, I like your %s')
const err = new NewError(undefined, undefined)
t.equal(err.message, 'hey undefined, I like your undefined')
})
test('Create error with 3 parameters', t => {
t.plan(6)
const NewError = createError('CODE', 'hey %s, I like your %s %s')
const err = new NewError('alice', 'attitude', 'see you')
t.ok(err instanceof Error)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'hey alice, I like your attitude see you')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create error with 3 parameters set to undefined', t => {
t.plan(4)
const NewError = createError('CODE', 'hey %s, I like your %s %s')
const err = new NewError(undefined, undefined, undefined)
t.equal(err.message, 'hey undefined, I like your undefined undefined')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create error with 4 parameters set to undefined', t => {
t.plan(4)
const NewError = createError('CODE', 'hey %s, I like your %s %s and %s')
const err = new NewError(undefined, undefined, undefined, undefined)
t.equal(err.message, 'hey undefined, I like your undefined undefined and undefined')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create error with no statusCode property', t => {
t.plan(6)
const NewError = createError('CODE', 'hey %s', 0)
const err = new NewError('dude')
t.ok(err instanceof Error)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'hey dude')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, undefined)
t.ok(err.stack)
})
test('Should throw when error code has no fastify code', t => {
t.plan(1)
t.throws(() => createError(), new Error('Fastify error code must not be empty'))
})
test('Should throw when error code has no message', t => {
t.plan(1)
t.throws(() => createError('code'), new Error('Fastify error message must not be empty'))
})
test('Create error with different base', t => {
t.plan(7)
const NewError = createError('CODE', 'hey %s', 500, TypeError)
const err = new NewError('dude')
t.ok(err instanceof Error)
t.ok(err instanceof TypeError)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'hey dude')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('FastifyError.toString returns code', t => {
t.plan(1)
const NewError = createError('CODE', 'foo')
const err = new NewError()
t.equal(err.toString(), 'FastifyError [CODE]: foo')
})
test('Create the error without the new keyword', t => {
t.plan(6)
const NewError = createError('CODE', 'Not available')
const err = NewError()
t.ok(err instanceof Error)
t.equal(err.name, 'FastifyError')
t.equal(err.message, 'Not available')
t.equal(err.code, 'CODE')
t.equal(err.statusCode, 500)
t.ok(err.stack)
})
test('Create an error with cause', t => {
t.plan(2)
const cause = new Error('HEY')
const NewError = createError('CODE', 'Not available')
const err = NewError({ cause })
t.ok(err instanceof Error)
t.equal(err.cause, cause)
})
test('Create an error with cause and message', t => {
t.plan(2)
const cause = new Error('HEY')
const NewError = createError('CODE', 'Not available: %s')
const err = NewError('foo', { cause })
t.ok(err instanceof Error)
t.equal(err.cause, cause)
})
test('Create an error with last argument null', t => {
t.plan(2)
const cause = new Error('HEY')
const NewError = createError('CODE', 'Not available')
const err = NewError({ cause }, null)
t.ok(err instanceof Error)
t.notOk(err.cause)
})

44
node_modules/@fastify/error/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
declare function createError<C extends string, SC extends number, Arg extends unknown[] = [any?, any?, any?]> (
code: C,
message: string,
statusCode: SC,
Base?: ErrorConstructor
): createError.FastifyErrorConstructor<{ code: C, statusCode: SC }, Arg>
declare function createError<C extends string, Arg extends unknown[] = [any?, any?, any?]> (
code: C,
message: string,
statusCode?: number,
Base?: ErrorConstructor
): createError.FastifyErrorConstructor<{ code: C }, Arg>
declare function createError<Arg extends unknown[] = [any?, any?, any?]> (
code: string,
message: string,
statusCode?: number,
Base?: ErrorConstructor
): createError.FastifyErrorConstructor<{ code: string }, Arg>
type CreateError = typeof createError
declare namespace createError {
export interface FastifyError extends Error {
code: string
name: string
statusCode?: number
}
export interface FastifyErrorConstructor<
E extends { code: string, statusCode?: number } = { code: string, statusCode?: number },
T extends unknown[] = [any?, any?, any?]
> {
new(...arg: T): FastifyError & E
(...arg: T): FastifyError & E
readonly prototype: FastifyError & E
}
export const createError: CreateError
export { createError as default }
}
export = createError

72
node_modules/@fastify/error/types/index.test-d.ts generated vendored Normal file
View File

@@ -0,0 +1,72 @@
import createError, { FastifyError, FastifyErrorConstructor } from '..'
import { expectType, expectError } from 'tsd'
const CustomError = createError('ERROR_CODE', 'message')
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomError)
const err = new CustomError()
expectType<FastifyError & { code: 'ERROR_CODE' }>(err)
expectType<'ERROR_CODE'>(err.code)
expectType<string>(err.message)
expectType<number | undefined>(err.statusCode)
const CustomTypedError = createError('OTHER_CODE', 'message', 400)
expectType<FastifyErrorConstructor<{ code: 'OTHER_CODE', statusCode: 400 }>>(CustomTypedError)
const typed = new CustomTypedError()
expectType<FastifyError & { code: 'OTHER_CODE', statusCode: 400 }>(typed)
expectType<'OTHER_CODE'>(typed.code)
expectType<string>(typed.message)
expectType<400>(typed.statusCode)
/* eslint-disable no-new */
const CustomTypedArgError = createError<[string]>('OTHER_CODE', 'expect %s message', 400)
CustomTypedArgError('a')
expectError(CustomTypedArgError('a', 'b'))
expectError(new CustomTypedArgError('a', 'b'))
expectError(CustomTypedArgError(1))
expectError(new CustomTypedArgError(1))
const CustomTypedArgError2 = createError<string, number, [string]>('OTHER_CODE', 'expect %s message', 400)
CustomTypedArgError2('a')
expectError(CustomTypedArgError2('a', 'b'))
expectError(new CustomTypedArgError2('a', 'b'))
expectError(CustomTypedArgError2(1))
expectError(new CustomTypedArgError2(1))
const CustomTypedArgError3 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
expectError(CustomTypedArgError3('a'))
CustomTypedArgError3('a', 'b')
new CustomTypedArgError3('a', 'b')
expectError(CustomTypedArgError3(1))
expectError(new CustomTypedArgError3(1))
expectError(new CustomTypedArgError3(1, 2))
expectError(new CustomTypedArgError3('1', 2))
expectError(new CustomTypedArgError3(1, '2'))
const CustomTypedArgError4 = createError<string, number, [string, string]>('OTHER_CODE', 'expect %s message but got %s', 400)
expectError(CustomTypedArgError4('a'))
CustomTypedArgError4('a', 'b')
new CustomTypedArgError4('a', 'b')
expectError(CustomTypedArgError4(1))
expectError(new CustomTypedArgError4(1))
expectError(new CustomTypedArgError4(1, 2))
expectError(new CustomTypedArgError4('1', 2))
expectError(new CustomTypedArgError4(1, '2'))
const CustomTypedArgError5 = createError<[string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
expectError(CustomTypedArgError5('a'))
expectError(new CustomTypedArgError5('a', 'b'))
expectError(new CustomTypedArgError5('a', 'b', 'c'))
CustomTypedArgError5('a', 'b', 'c', 'd')
expectError(new CustomTypedArgError5('a', 'b', 'c', 'd', 'e'))
const CustomTypedArgError6 = createError<string, number, [string, string, string, string]>('OTHER_CODE', 'expect %s message but got %s. Please contact %s by emailing to %s', 400)
expectError(CustomTypedArgError6('a'))
expectError(new CustomTypedArgError6('a', 'b'))
expectError(new CustomTypedArgError6('a', 'b', 'c'))
CustomTypedArgError6('a', 'b', 'c', 'd')
expectError(new CustomTypedArgError6('a', 'b', 'c', 'd', 'e'))
const CustomErrorWithErrorConstructor = createError('ERROR_CODE', 'message', 500, TypeError)
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE', statusCode: 500 }>>(CustomErrorWithErrorConstructor)
CustomErrorWithErrorConstructor({cause: new Error('Error')})