First commit

This commit is contained in:
2025-10-08 11:12:59 -04:00
commit b0605a28a9
820 changed files with 100317 additions and 0 deletions

2
node_modules/process-warning/.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/process-warning/.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/process-warning/.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/process-warning/.taprc generated vendored Normal file
View File

@ -0,0 +1,2 @@
files:
- test/**/*[!jest].test.js

21
node_modules/process-warning/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 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.

105
node_modules/process-warning/README.md generated vendored Normal file
View File

@ -0,0 +1,105 @@
# process-warning
![CI](https://github.com/fastify/process-warning/workflows/CI/badge.svg)
[![NPM version](https://img.shields.io/npm/v/process-warning.svg?style=flat)](https://www.npmjs.com/package/process-warning)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
A small utility for generating consistent warning objects across your codebase.
It also exposes a utility for emitting those warnings, guaranteeing that they are issued only once (unless configured otherwise).
This module is used by the [Fastify](https://fastify.io) framework and it was called `fastify-warning` prior to version 1.0.0.
### Install
```
npm i process-warning
```
### Usage
The module exports a builder function that returns a utility for creating warnings and emitting them.
```js
const warning = require('process-warning')()
```
#### Methods
##### `warning.create(name, code, message[, options])`
- `name` (`string`, required) - The error name, you can access it later with
`error.name`. For consistency, we recommend prefixing module error names
with `{YourModule}Warning`
- `code` (`string`, required) - The warning code, you can access it later with
`error.code`. For consistency, we recommend prefixing plugin error codes with
`{ThreeLetterModuleName}_`, e.g. `FST_`. NOTE: codes should be all uppercase.
- `message` (`string`, required) - The warning message. You can also use
interpolated strings for formatting the message.
- `options` (`object`, optional) - Optional options with the following
properties:
+ `unlimited` (`boolean`, optional) - Should the warning be emitted more than
once? Defaults to `false`.
##### `warning.createDeprecation(code, message[, options])`
This is a wrapper for `warning.create`. It is equivalent to invoking
`warning.create` with the `name` parameter set to "DeprecationWarning".
Deprecation warnings have extended support for the Node.js CLI options:
`--throw-deprecation`, `--no-deprecation`, and `--trace-deprecation`.
##### `warning.emit(code [, a [, b [, c]]])`
The utility also contains an `emit` function that you can use for emitting the
warnings you have previously created by passing their respective code.
A warning is guaranteed to be emitted at least once.
- `code` (`string`, required) - The warning code you intend to emit.
- `[, a [, b [, c]]]` (`any`, optional) - Parameters for string interpolation.
```js
const warning = require('process-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'message')
warning.emit('FST_ERROR_CODE')
```
How to use an interpolated string:
```js
const warning = require('process-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')
warning.emit('FST_ERROR_CODE', 'world')
```
The module also exports an `warning.emitted` [Map](https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/Map), which contains all the warnings already emitted. Useful for testing.
```js
const warning = require('process-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')
console.log(warning.emitted.get('FST_ERROR_CODE')) // false
warning.emit('FST_ERROR_CODE', 'world')
console.log(warning.emitted.get('FST_ERROR_CODE')) // true
```
How to use an unlimited warning:
```js
const warning = require('process-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s', { unlimited: true })
warning.emit('FST_ERROR_CODE', 'world') // will be emitted
warning.emit('FST_ERROR_CODE', 'world') // will be emitted again
```
#### Suppressing warnings
It is possible to suppress warnings by utilizing one of node's built-in warning suppression mechanisms.
Warnings can be suppressed:
- by setting the `NODE_NO_WARNINGS` environment variable to `1`
- by passing the `--no-warnings` flag to the node process
- by setting 'no-warnings' in the `NODE_OPTIONS` environment variable
For more information see [node's documentation](https://nodejs.org/api/cli.html).
## License
Licensed under [MIT](./LICENSE).

17
node_modules/process-warning/benchmarks/warn.js generated vendored Normal file
View File

@ -0,0 +1,17 @@
'use strict'
const { Suite } = require('benchmark')
const warning = require('..')()
warning.create('FastifyWarning', 'FST_ERROR_CODE_1', 'message')
warning.create('FastifyWarning', 'FST_ERROR_CODE_2', 'message')
warning.create('FastifyWarning', 'FST_ERROR_CODE_3', 'message')
new Suite()
.add('warn', function () {
warning.emit('FST_ERROR_CODE_1')
warning.emit('FST_ERROR_CODE_3')
})
.on('cycle', function (event) {
console.log(String(event.target))
})
.run()

7
node_modules/process-warning/examples/example.js generated vendored Normal file
View File

@ -0,0 +1,7 @@
'use strict'
const warning = require('..')()
warning.create('DeprecationWarning', 'CUSTDEP001', 'This is a deprecation warning')
warning.emit('CUSTDEP001')

158
node_modules/process-warning/index.js generated vendored Normal file
View File

@ -0,0 +1,158 @@
'use strict'
const { format } = require('node:util')
/**
* An object that provides methods for creating process warning, emitting them,
* and inspecting/managing the emission state of warning.
*
* @typedef {object} ProcessWarningManager
*/
/**
* @typedef {object} CreateOptions
* @property {boolean} [unlimited=false] Indicates if the warning should be
* emitted every time (`true`) or only the first time (`false`).
*/
/**
* An error instance representing a process warning. This is what will be
* emitted to listeners when the warning is emitted.
*
* @typedef {Error} ProcessWarning
* @property {string} code
* @property {string} name
* @property {string} message
*/
/**
* A function used to create new {@link ProcessWarning} instances.
*
* @callback ProcessWarningBuilder
* @param {*} [param1] First possible string interpolation value.
* @param {*} [param2] Second possible string interpolation value.
* @param {*} [param3] Third possible string interpolation value.
* @returns ProcessWarning
*/
/**
* Factory that builds a new {@link ProcessWarningManager} and returns it.
*
* @returns ProcessWarningManager
*/
function processWarning () {
const codes = {}
const emitted = new Map()
const opts = Object.create(null)
/**
* Builds a new {@link ProcessWarning} and adds it to the
* {@link ProcessWarningManager} such that it can be emitted through the
* {@link ProcessWarningManager#emit} method.
*
* @memberof! ProcessWarningManager
* @instance
*
* @param {string} name Warning name, e.g. `'MyCustomWarning'`.
* @param {string} code A unique code for the warning, e.g. `'WARN_001'`.
* @param {string} message The body of the warning.
* @param {CreateOptions} [options]
* @returns {ProcessWarningBuilder}
*/
function create (name, code, message, { unlimited = false } = {}) {
if (!name) throw new Error('Warning name must not be empty')
if (!code) throw new Error('Warning code must not be empty')
if (!message) throw new Error('Warning message must not be empty')
if (typeof unlimited !== 'boolean') throw new Error('Warning opts.unlimited must be a boolean')
code = code.toUpperCase()
if (codes[code] !== undefined) {
throw new Error(`The code '${code}' already exist`)
}
function buildWarnOpts (a, b, c) {
// more performant than spread (...) operator
let formatted
if (a && b && c) {
formatted = format(message, a, b, c)
} else if (a && b) {
formatted = format(message, a, b)
} else if (a) {
formatted = format(message, a)
} else {
formatted = message
}
return {
code,
name,
message: formatted
}
}
Object.assign(opts, { unlimited })
emitted.set(code, unlimited)
codes[code] = buildWarnOpts
return codes[code]
}
/**
* A wrapper for {@link ProcessWarningManager#create} that builds a new
* deprecation warning. This method is equivalent to passing
* `name = 'DeprecationWarning'` to the create method.
*
* Deprecation warnings have extended support for the Node.js CLI options:
* `--throw-deprecation`, `--no-deprecation`, and `--trace-deprecation`.
*
* @memberof! ProcessWarningManager
* @instance
*
* @param {string} code
* @param {string} message
* @param {CreateOptions} opts
* @returns {ProcessWarningBuilder}
*/
function createDeprecation (code, message, opts = {}) {
return create('DeprecationWarning', code, message, opts)
}
/**
* Emits a registered warning associated with the given `code`. If the
* warning message has interpolation strings present, up to the first three
* of them can be supplied values with the optional interpolation value
* parameters.
*
* If a warning is set to `unlimited: false`, and has already been emitted
* once, invoking this method is a no-operation.
*
* @memberof! ProcessWarningManager
* @instance
*
* @param {string} code The code for the error to emit, e.g. `'WARN_001'`.
* This is the same code that was provided to {@link ProcessWarningManager#create}.
* @param {*} [a] Possible message interpolation value.
* @param {*} [b] Possible message interpolation value.
* @param {*} [c] Possible message interpolation value.
*/
function emit (code, a, b, c) {
if (emitted.get(code) === true && opts.unlimited === false) return
if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`)
emitted.set(code, true)
const warning = codes[code](a, b, c)
process.emitWarning(warning.message, warning.name, warning.code)
}
return {
create,
createDeprecation,
emit,
emitted
}
}
module.exports = processWarning
module.exports.default = processWarning
module.exports.processWarning = processWarning

42
node_modules/process-warning/package.json generated vendored Normal file
View File

@ -0,0 +1,42 @@
{
"name": "process-warning",
"version": "2.3.2",
"description": "A small utility for creating warnings and emitting them.",
"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:jest && npm run test:typescript",
"test:jest": "jest jest.test.js",
"test:unit": "tap",
"test:typescript": "tsd"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fastify/process-warning.git"
},
"keywords": [
"fastify",
"error",
"warning",
"utility",
"plugin",
"emit",
"once"
],
"author": "Tomas Della Vedova",
"license": "MIT",
"bugs": {
"url": "https://github.com/fastify/fastify-warning/issues"
},
"homepage": "https://github.com/fastify/fastify-warning#readme",
"devDependencies": {
"benchmark": "^2.1.4",
"jest": "^29.0.1",
"standard": "^17.0.0",
"tap": "^16.3.0",
"tsd": "^0.29.0"
}
}

View File

@ -0,0 +1,26 @@
'use strict'
const test = require('tap').test
const build = require('..')
test('emit with interpolated string', t => {
t.plan(4)
const { create, emit, emitted } = build()
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'FastifyDeprecation')
t.equal(warning.code, 'CODE')
t.equal(warning.message, 'Hello world')
t.ok(emitted.get('CODE'))
}
create('FastifyDeprecation', 'CODE', 'Hello %s')
emit('CODE', 'world')
emit('CODE', 'world')
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

View File

@ -0,0 +1,26 @@
'use strict'
const test = require('tap').test
const build = require('..')
test('emit should emit a given code only once', t => {
t.plan(4)
const { create, emit, emitted } = build()
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'FastifyDeprecation')
t.equal(warning.code, 'CODE')
t.equal(warning.message, 'Hello world')
t.ok(emitted.get('CODE'))
}
create('FastifyDeprecation', 'CODE', 'Hello world')
emit('CODE')
emit('CODE')
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

View File

@ -0,0 +1,34 @@
'use strict'
const test = require('tap').test
const build = require('..')
test('emit should emit a given code unlimited times', t => {
t.plan(50)
const { create, emit, emitted } = build()
let runs = 0
const expectedRun = []
const times = 10
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'FastifyDeprecation')
t.equal(warning.code, 'CODE')
t.equal(warning.message, 'Hello world')
t.ok(emitted.get('CODE'))
t.equal(runs++, expectedRun.shift())
}
create('FastifyDeprecation', 'CODE', 'Hello world', { unlimited: true })
for (let i = 0; i < times; i++) {
expectedRun.push(i)
emit('CODE')
}
setImmediate(() => {
process.removeListener('warning', onWarning)
t.end()
})
})

110
node_modules/process-warning/test/index.test.js generated vendored Normal file
View File

@ -0,0 +1,110 @@
'use strict'
const test = require('tap').test
const build = require('..')
process.removeAllListeners('warning')
test('Create warning with zero parameter', t => {
t.plan(3)
const { create } = build()
const buildWarnOpts = create('FastifyWarning', 'CODE', 'Not available')
const opts = buildWarnOpts()
t.equal(opts.name, 'FastifyWarning')
t.equal(opts.message, 'Not available')
t.equal(opts.code, 'CODE')
})
test('Create error with 1 parameter', t => {
t.plan(3)
const { create } = build()
const buildWarningOpts = create('FastifyWarning', 'CODE', 'hey %s')
const opts = buildWarningOpts('alice')
t.equal(opts.name, 'FastifyWarning')
t.equal(opts.message, 'hey alice')
t.equal(opts.code, 'CODE')
})
test('Create error with 2 parameters', t => {
t.plan(3)
const { create } = build()
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s')
const opts = buildWarnOpts('alice', 'attitude')
t.equal(opts.name, 'FastifyWarning')
t.equal(opts.message, 'hey alice, I like your attitude')
t.equal(opts.code, 'CODE')
})
test('Create error with 3 parameters', t => {
t.plan(3)
const { create } = build()
const buildWarnOpts = create('FastifyWarning', 'CODE', 'hey %s, I like your %s %s')
const opts = buildWarnOpts('alice', 'attitude', 'see you')
t.equal(opts.name, 'FastifyWarning')
t.equal(opts.message, 'hey alice, I like your attitude see you')
t.equal(opts.code, 'CODE')
})
test('Creates a deprecation warning', t => {
t.plan(3)
const manager = build()
const builder = manager.createDeprecation('CODE', 'hello %s')
const warning = builder('world')
t.equal(warning.name, 'DeprecationWarning')
t.equal(warning.message, 'hello world')
t.equal(warning.code, 'CODE')
})
test('Should throw when error code has no fastify name', t => {
t.plan(1)
const { create } = build()
t.throws(() => create(), new Error('Warning name must not be empty'))
})
test('Should throw when error has no code', t => {
t.plan(1)
const { create } = build()
t.throws(() => create('name'), new Error('Warning code must not be empty'))
})
test('Should throw when error has no message', t => {
t.plan(1)
const { create } = build()
t.throws(() => create('name', 'code'), new Error('Warning message must not be empty'))
})
test('Should throw if emit is called with unknown code ', t => {
t.plan(1)
const { emit } = build()
t.throws(() => emit('CODE'), new Error('The code \'CODE\' does not exist'))
})
test('Cannot reuse the same code more than once', t => {
t.plan(1)
const { create } = build()
create('FastifyWarning', 'CODE', 'Not available')
t.throws(() => create('FastifyWarning', 'CODE', 'Not available'), new Error("The code 'CODE' already exist"))
})
test('Cannot set unlimited other than boolean', t => {
t.plan(1)
const { create } = build()
t.throws(() => create('FastifyWarning', 'CODE', 'Msg', { unlimited: 42 }), new Error('Warning opts.unlimited must be a boolean'))
})

20
node_modules/process-warning/test/jest.test.js generated vendored Normal file
View File

@ -0,0 +1,20 @@
/* global test, expect */
'use strict'
const build = require('..')
test('works with jest', done => {
const { create, emit, emitted } = build()
create('FastifyDeprecation', 'CODE', 'Hello %s')
emit('CODE', 'world')
// we cannot actually listen to process warning event
// because jest messes with it (that's the point of this test)
// we can only test it was emitted indirectly
// and test no exception is raised
setImmediate(() => {
expect(emitted.get('CODE')).toBeTruthy()
done()
})
})

80
node_modules/process-warning/test/no-warnings.test.js generated vendored Normal file
View File

@ -0,0 +1,80 @@
'use strict'
const { test } = require('tap')
const { spawnSync } = require('child_process')
const { resolve } = require('path')
const entry = resolve(__dirname, '../examples', 'example.js')
test('--no-warnings is set in cli', t => {
t.plan(1)
const child = spawnSync(process.execPath, [
'--no-warnings',
entry
])
const stderr = child.stderr.toString()
t.equal(stderr, '')
})
test('--no-warnings is not set in cli', t => {
t.plan(1)
const child = spawnSync(process.execPath, [
entry
])
const stderr = child.stderr.toString()
t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
})
test('NODE_NO_WARNINGS is set to 1', t => {
t.plan(1)
const child = spawnSync(process.execPath, [
entry
], {
env: {
NODE_NO_WARNINGS: '1'
}
})
const stderr = child.stderr.toString()
t.equal(stderr, '')
})
test('NODE_NO_WARNINGS is set to 0', t => {
t.plan(1)
const child = spawnSync(process.execPath, [
entry
], {
env: {
NODE_NO_WARNINGS: '0'
}
})
const stderr = child.stderr.toString()
t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
})
test('NODE_NO_WARNINGS is not set', t => {
t.plan(1)
const child = spawnSync(process.execPath, [
entry
])
const stderr = child.stderr.toString()
t.match(stderr, /\[CUSTDEP001\] DeprecationWarning: This is a deprecation warning/)
})
test('NODE_Options contains --no-warnings', t => {
t.plan(1)
const child = spawnSync(process.execPath, [
entry
], {
env: {
NODE_OPTIONS: '--no-warnings'
}
})
const stderr = child.stderr.toString()
t.equal(stderr, '')
})

27
node_modules/process-warning/types/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,27 @@
type ProcessWarning = () => processWarning.Warning
declare namespace processWarning {
export interface Warning {
create(name: string, code: string, message: string, opts?: ProcessWarningOptions): BuildWarnOptsFn,
emit(cod: string, a?: any, b?: any, c?: any): void,
emitted: Map<string, boolean>
}
export type BuildWarnOptsFn = (a?: any, b?: any, c?: any) => WarnOpts
export type ProcessWarningOptions = {
unlimited?: boolean,
}
export interface WarnOpts {
code: string;
name: string;
message: string;
}
export const processWarning: ProcessWarning
export { processWarning as default }
}
declare function processWarning(...params: Parameters<ProcessWarning>): ReturnType<ProcessWarning>
export = processWarning

17
node_modules/process-warning/types/index.test-d.ts generated vendored Normal file
View File

@ -0,0 +1,17 @@
import { expectType } from 'tsd'
import Warinig, { BuildWarnOptsFn, WarnOpts } from '..'
const warning = Warinig()
const buildWarnOpts = warning.create('FastifyWarning', 'CODE', 'message')
expectType<BuildWarnOptsFn>(buildWarnOpts)
const opts = buildWarnOpts()
expectType<WarnOpts>(opts)
expectType<string>(opts.code)
expectType<string>(opts.message)
expectType<string>(opts.name)
expectType<void>(warning.emit('CODE'))
expectType<Map<string, boolean>>(warning.emitted)
const buildWarnUnlimited = warning.create('FastifyWarning', 'CODE', 'message', { unlimited: true })
expectType<BuildWarnOptsFn>(buildWarnUnlimited)