Skip to content

Commit

Permalink
chore: update process-warning (#5206)
Browse files Browse the repository at this point in the history
* chore: bump new process-warning

* test: update code
  • Loading branch information
Eomm authored Dec 12, 2023
1 parent cd84d13 commit 7c778af
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 146 deletions.
4 changes: 2 additions & 2 deletions fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const { buildRouting, validateBodyLimitOption } = require('./lib/route')
const build404 = require('./lib/fourOhFour')
const getSecuredInitialConfig = require('./lib/initialConfigValidation')
const override = require('./lib/pluginOverride')
const warning = require('./lib/warnings')
const { FSTDEP009 } = require('./lib/warnings')
const noopSet = require('./lib/noop-set')
const {
appendStackTrace,
Expand Down Expand Up @@ -152,7 +152,7 @@ function fastify (options) {

let constraints = options.constraints
if (options.versioning) {
warning.emit('FSTDEP009')
FSTDEP009()
constraints = {
...constraints,
version: {
Expand Down
4 changes: 2 additions & 2 deletions lib/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
FST_ERR_DEC_DEPENDENCY_INVALID_TYPE
} = require('./errors')

const warning = require('./warnings')
const { FSTDEP006 } = require('./warnings')

function decorate (instance, name, fn, dependencies) {
if (Object.prototype.hasOwnProperty.call(instance, name)) {
Expand Down Expand Up @@ -58,7 +58,7 @@ function decorateConstructor (konstructor, name, fn, dependencies) {

function checkReferenceType (name, fn) {
if (typeof fn === 'object' && fn && !(typeof fn.getter === 'function' || typeof fn.setter === 'function')) {
warning.emit('FSTDEP006', name)
FSTDEP006(name)
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
FST_ERR_PLUGIN_VERSION_MISMATCH,
FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE
} = require('./errors')
const warning = require('./warnings.js')
const { FSTWRN002 } = require('./warnings.js')

function getMeta (fn) {
return fn[Symbol.for('plugin-meta')]
Expand Down Expand Up @@ -138,7 +138,7 @@ function registerPluginName (fn) {

function checkPluginHealthiness (fn, pluginName = 'anonymous') {
if (fn.constructor.name === 'AsyncFunction' && fn.length === 3) {
warning.emit('FSTWRN002', pluginName)
FSTWRN002(pluginName)
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const {
FST_ERR_MISSING_SERIALIZATION_FN,
FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN
} = require('./errors')
const warning = require('./warnings')
const { FSTDEP010, FSTDEP013, FSTDEP019 } = require('./warnings')

function Reply (res, request, log) {
this.raw = res
Expand All @@ -80,7 +80,7 @@ Object.defineProperties(Reply.prototype, {
// Is temporary to avoid constant conflicts between `next` and `main`
context: {
get () {
warning.emit('FSTDEP019')
FSTDEP019()
return this.request[kRouteContext]
}
},
Expand All @@ -96,7 +96,7 @@ Object.defineProperties(Reply.prototype, {
return (this[kReplyHijacked] || this.raw.writableEnded) === true
},
set (value) {
warning.emit('FSTDEP010')
FSTDEP010()

if (value !== true) {
throw new FST_ERR_REP_SENT_VALUE()
Expand Down Expand Up @@ -748,7 +748,7 @@ function sendTrailer (payload, res, reply) {
result.then((v) => cb(null, v), cb)
} else if (result !== null && result !== undefined) {
// TODO: should be removed in fastify@5
warning.emit('FSTDEP013')
FSTDEP013()
cb(null, result)
}
}
Expand Down
21 changes: 14 additions & 7 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

const proxyAddr = require('proxy-addr')
const semver = require('semver')
const warning = require('./warnings')
const {
FSTDEP005,
FSTDEP012,
FSTDEP015,
FSTDEP016,
FSTDEP017,
FSTDEP018
} = require('./warnings')
const {
kHasBeenDecorated,
kSchemaBody,
Expand Down Expand Up @@ -166,13 +173,13 @@ Object.defineProperties(Request.prototype, {
},
context: {
get () {
warning.emit('FSTDEP012')
FSTDEP012()
return this[kRouteContext]
}
},
routerPath: {
get () {
warning.emit('FSTDEP017')
FSTDEP017()
return this[kRouteContext].config?.url
}
},
Expand Down Expand Up @@ -208,19 +215,19 @@ Object.defineProperties(Request.prototype, {
},
routerMethod: {
get () {
warning.emit('FSTDEP018')
FSTDEP018()
return this[kRouteContext].config?.method
}
},
routeConfig: {
get () {
warning.emit('FSTDEP016')
FSTDEP016()
return this[kRouteContext][kPublicRouteContext]?.config
}
},
routeSchema: {
get () {
warning.emit('FSTDEP015')
FSTDEP015()
return this[kRouteContext][kPublicRouteContext].schema
}
},
Expand All @@ -233,7 +240,7 @@ Object.defineProperties(Request.prototype, {
get () {
/* istanbul ignore next */
if (semver.gte(process.versions.node, '13.0.0')) {
warning.emit('FSTDEP005')
FSTDEP005()
}
return this.raw.connection
}
Expand Down
14 changes: 9 additions & 5 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const { onRequestAbortHookRunner, lifecycleHooks, preParsingHookRunner, onTimeou
const { supportedMethods } = require('./httpMethods')
const { normalizeSchema } = require('./schemas')
const { parseHeadOnSendHandlers } = require('./headRoute')
const warning = require('./warnings')
const {
FSTDEP007,
FSTDEP008,
FSTDEP014
} = require('./warnings')

const {
compileSchemasForValidation,
Expand Down Expand Up @@ -100,11 +104,11 @@ function buildRouting (options) {
hasRoute,
prepareRoute,
getDefaultRoute: function () {
warning.emit('FSTDEP014')
FSTDEP014()
return router.defaultRoute
},
setDefaultRoute: function (defaultRoute) {
warning.emit('FSTDEP014')
FSTDEP014()
if (typeof defaultRoute !== 'function') {
throw new FST_ERR_DEFAULT_ROUTE_INVALID_TYPE()
}
Expand Down Expand Up @@ -324,7 +328,7 @@ function buildRouting (options) {
})

if (opts.version) {
warning.emit('FSTDEP008')
FSTDEP008()
constraints.version = opts.version
}

Expand Down Expand Up @@ -417,7 +421,7 @@ function buildRouting (options) {
const onSendHandlers = parseHeadOnSendHandlers(headOpts.onSend)
prepareRoute.call(this, { method: 'HEAD', url: path, options: { ...headOpts, onSend: onSendHandlers }, isFastify: true })
} else if (hasHEADHandler && exposeHeadRoute) {
warning.emit('FSTDEP007')
FSTDEP007()
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const http = require('node:http')
const https = require('node:https')
const dns = require('node:dns')

const warnings = require('./warnings')
const { FSTDEP011 } = require('./warnings')
const { kState, kOptions, kServerBindings } = require('./symbols')
const { onListenHookRunner } = require('./hooks')
const {
Expand Down Expand Up @@ -36,12 +36,12 @@ function createServer (options, httpHandler) {
if (arguments.length === 0) {
listenOptions = normalizeListenArgs([])
} else if (arguments.length > 0 && (firstArgType !== '[object Object]' && firstArgType !== '[object Function]')) {
warnings.emit('FSTDEP011')
FSTDEP011()
listenOptions = normalizeListenArgs(Array.from(arguments))
cb = listenOptions.cb
} else if (args.length > 1) {
// `.listen(obj, a, ..., n, callback )`
warnings.emit('FSTDEP011')
FSTDEP011()
// Deal with `.listen(port, host, backlog, [cb])`
const hostPath = listenOptions.path ? [listenOptions.path] : [listenOptions.port ?? 0, listenOptions.host ?? 'localhost']
Object.assign(listenOptions, normalizeListenArgs([...hostPath, ...args]))
Expand Down
10 changes: 5 additions & 5 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX
} = require('./errors')

const warning = require('./warnings')
const { FSTWRN001 } = require('./warnings')

function compileSchemasForSerialization (context, compile) {
if (!context.schema || !context.schema.response) {
Expand Down Expand Up @@ -83,25 +83,25 @@ function compileSchemasForValidation (context, compile, isCustom) {
}
context[headersSchema] = compile({ schema: headersSchemaLowerCase, method, url, httpPart: 'headers' })
} else if (Object.prototype.hasOwnProperty.call(schema, 'headers')) {
warning.emit('FSTWRN001', 'headers', method, url)
FSTWRN001('headers', method, url)
}

if (schema.body) {
context[bodySchema] = compile({ schema: schema.body, method, url, httpPart: 'body' })
} else if (Object.prototype.hasOwnProperty.call(schema, 'body')) {
warning.emit('FSTWRN001', 'body', method, url)
FSTWRN001('body', method, url)
}

if (schema.querystring) {
context[querystringSchema] = compile({ schema: schema.querystring, method, url, httpPart: 'querystring' })
} else if (Object.prototype.hasOwnProperty.call(schema, 'querystring')) {
warning.emit('FSTWRN001', 'querystring', method, url)
FSTWRN001('querystring', method, url)
}

if (schema.params) {
context[paramsSchema] = compile({ schema: schema.params, method, url, httpPart: 'params' })
} else if (Object.prototype.hasOwnProperty.call(schema, 'params')) {
warning.emit('FSTWRN001', 'params', method, url)
FSTWRN001('params', method, url)
}
}

Expand Down
Loading

0 comments on commit 7c778af

Please sign in to comment.