fastify 4.25.0 → 4.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/fastify.js +1 -1
- package/lib/pluginUtils.js +3 -3
- package/package.json +1 -1
- package/test/plugin.4.test.js +25 -6
- package/test/types/route.test-d.ts +6 -13
- package/types/route.d.ts +8 -2
package/README.md
CHANGED
|
@@ -377,10 +377,10 @@ to join this group by Lead Maintainers.
|
|
|
377
377
|
|
|
378
378
|
[<img
|
|
379
379
|
src="https://github.com/openjs-foundation/artwork/blob/main/openjs_foundation/openjs_foundation-logo-horizontal-color.png?raw=true"
|
|
380
|
-
width="250px;"/>](https://openjsf.org/projects
|
|
380
|
+
width="250px;"/>](https://openjsf.org/projects)
|
|
381
381
|
|
|
382
|
-
We are a [
|
|
383
|
-
Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#
|
|
382
|
+
We are a [At-Large
|
|
383
|
+
Project](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/PROJECT_PROGRESSION.md#at-large-projects)
|
|
384
384
|
in the [OpenJS Foundation](https://openjsf.org/).
|
|
385
385
|
|
|
386
386
|
## Acknowledgements
|
package/fastify.js
CHANGED
package/lib/pluginUtils.js
CHANGED
|
@@ -136,14 +136,14 @@ function registerPluginName (fn) {
|
|
|
136
136
|
return name
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
function checkPluginHealthiness (fn, pluginName
|
|
139
|
+
function checkPluginHealthiness (fn, pluginName) {
|
|
140
140
|
if (fn.constructor.name === 'AsyncFunction' && fn.length === 3) {
|
|
141
|
-
FSTWRN002(pluginName)
|
|
141
|
+
FSTWRN002(pluginName || 'anonymous')
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
function registerPlugin (fn) {
|
|
146
|
-
const pluginName = registerPluginName.call(this, fn)
|
|
146
|
+
const pluginName = registerPluginName.call(this, fn) || getPluginName(fn)
|
|
147
147
|
checkPluginHealthiness.call(this, fn, pluginName)
|
|
148
148
|
checkVersion.call(this, fn)
|
|
149
149
|
checkDecorators.call(this, fn)
|
package/package.json
CHANGED
package/test/plugin.4.test.js
CHANGED
|
@@ -416,20 +416,27 @@ test('hasPlugin returns true when using encapsulation', async t => {
|
|
|
416
416
|
})
|
|
417
417
|
|
|
418
418
|
test('registering plugins with mixed style should return a warning', async t => {
|
|
419
|
-
t.plan(
|
|
419
|
+
t.plan(12)
|
|
420
|
+
|
|
421
|
+
const pluginNames = ['error-plugin', 'anonymous', 'anotherPlugin', 'anotherPluginNamed']
|
|
420
422
|
|
|
423
|
+
const oldWarnings = process.listeners('warning')
|
|
424
|
+
process.removeAllListeners('warning')
|
|
421
425
|
process.on('warning', onWarning)
|
|
422
426
|
function onWarning (warning) {
|
|
427
|
+
t.match(warning.message, new RegExp(`.*${pluginNames.shift()} plugin being registered mixes async and callback styles.*`))
|
|
423
428
|
t.equal(warning.name, 'FastifyWarning')
|
|
424
429
|
t.equal(warning.code, 'FSTWRN002')
|
|
425
430
|
}
|
|
431
|
+
t.teardown(() => {
|
|
432
|
+
process.removeListener('warning', onWarning)
|
|
433
|
+
for (const warning of oldWarnings) {
|
|
434
|
+
process.on('warning', warning)
|
|
435
|
+
}
|
|
436
|
+
})
|
|
426
437
|
|
|
427
438
|
const fastify = Fastify()
|
|
428
439
|
|
|
429
|
-
const anonymousPlugin = async (app, opts, done) => {
|
|
430
|
-
done()
|
|
431
|
-
}
|
|
432
|
-
|
|
433
440
|
const pluginName = 'error-plugin'
|
|
434
441
|
const errorPlugin = async (app, opts, done) => {
|
|
435
442
|
done()
|
|
@@ -437,8 +444,20 @@ test('registering plugins with mixed style should return a warning', async t =>
|
|
|
437
444
|
|
|
438
445
|
const namedPlugin = fp(errorPlugin, { name: pluginName })
|
|
439
446
|
|
|
447
|
+
async function anotherPlugin (app, opts, done) {
|
|
448
|
+
done()
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const anotherPluginNamed = async function (app, opts, done) {
|
|
452
|
+
done()
|
|
453
|
+
}
|
|
454
|
+
|
|
440
455
|
fastify.register(namedPlugin)
|
|
441
|
-
fastify.register(
|
|
456
|
+
fastify.register(async (app, opts, done) => {
|
|
457
|
+
done()
|
|
458
|
+
})
|
|
459
|
+
fastify.register(anotherPlugin)
|
|
460
|
+
fastify.register(anotherPluginNamed)
|
|
442
461
|
|
|
443
462
|
await fastify.ready()
|
|
444
463
|
})
|
|
@@ -444,19 +444,12 @@ expectType<boolean>(fastify().hasRoute({
|
|
|
444
444
|
url: '/',
|
|
445
445
|
method: 'GET',
|
|
446
446
|
constraints: {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
},
|
|
454
|
-
set: (type, store) => {}
|
|
455
|
-
}
|
|
456
|
-
},
|
|
457
|
-
deriveConstraint: (req, ctx, done) => {},
|
|
458
|
-
mustMatchWhenDerived: true
|
|
459
|
-
}
|
|
447
|
+
// constraints value should accept any value
|
|
448
|
+
number: 12,
|
|
449
|
+
date: new Date(),
|
|
450
|
+
boolean: true,
|
|
451
|
+
function: () => {},
|
|
452
|
+
object: { foo: 'bar' }
|
|
460
453
|
}
|
|
461
454
|
}))
|
|
462
455
|
|
package/types/route.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FastifyError } from '@fastify/error'
|
|
2
|
+
import { ConstraintStrategy } from 'find-my-way'
|
|
2
3
|
import { FastifyRequestContext } from './context'
|
|
3
4
|
import { onErrorMetaHookHandler, onRequestAbortMetaHookHandler, onRequestMetaHookHandler, onResponseMetaHookHandler, onSendMetaHookHandler, onTimeoutMetaHookHandler, preHandlerMetaHookHandler, preParsingMetaHookHandler, preSerializationMetaHookHandler, preValidationMetaHookHandler } from './hooks'
|
|
4
5
|
import { FastifyInstance } from './instance'
|
|
@@ -12,7 +13,6 @@ import {
|
|
|
12
13
|
ResolveFastifyReplyReturnType
|
|
13
14
|
} from './type-provider'
|
|
14
15
|
import { ContextConfigDefault, HTTPMethods, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
|
|
15
|
-
import { ConstraintStrategy } from 'find-my-way'
|
|
16
16
|
|
|
17
17
|
export interface FastifyRouteConfig {
|
|
18
18
|
url: string;
|
|
@@ -25,6 +25,12 @@ export type RouteConstraintType = Omit<ConstraintStrategy<any>, 'deriveConstrain
|
|
|
25
25
|
deriveConstraint<Context>(req: RawRequestDefaultExpression<RawServerDefault>, ctx?: Context, done?: (err: Error, ...args: any) => any): any,
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export interface RouteConstraint {
|
|
29
|
+
version?: string
|
|
30
|
+
host?: RegExp | string
|
|
31
|
+
[name: string]: unknown
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* Route shorthand options for the various shorthand methods
|
|
30
36
|
*/
|
|
@@ -48,7 +54,7 @@ export interface RouteShorthandOptions<
|
|
|
48
54
|
logLevel?: LogLevel;
|
|
49
55
|
config?: Omit<FastifyRequestContext<ContextConfig>['config'], 'url' | 'method'>;
|
|
50
56
|
version?: string;
|
|
51
|
-
constraints?:
|
|
57
|
+
constraints?: RouteConstraint,
|
|
52
58
|
prefixTrailingSlash?: 'slash'|'no-slash'|'both';
|
|
53
59
|
errorHandler?: (
|
|
54
60
|
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|