diff --git a/README.md b/README.md index bf0698d..1d89c35 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,11 @@ const { fastifyAwilixPlugin } = require('@fastify/awilix') const fastify = require('fastify') app = fastify({ logger: true }) -app.register(fastifyAwilixPlugin, { disposeOnClose: true, disposeOnResponse: true }) +app.register(fastifyAwilixPlugin, { + disposeOnClose: true, + disposeOnResponse: true, + strictBooleanEnforced: true +}) ``` Then, register some modules for injection: @@ -99,6 +103,9 @@ Default value is `false` `eagerInject` - whether to process `eagerInject` fields in DI resolver configuration, which instantiates and caches module immediately. Disabling this will make app startup slightly faster. Default value is `false` +`strictBooleanEnforced` - whether to throw an error if `enabled` field in a resolver configuration is set with unsupported value (anything different from `true` and `false`). It is recommended to set this to `true`, which will be a default value in the next semver major release. +Default value is `false` + ## Defining classes All dependency modules are resolved using either the constructor injection (for `asClass`) or the function argument (for `asFunction`), by passing the aggregated dependencies object, where keys diff --git a/lib/fastifyAwilixPlugin.js b/lib/fastifyAwilixPlugin.js index ee62073..005b3f0 100644 --- a/lib/fastifyAwilixPlugin.js +++ b/lib/fastifyAwilixPlugin.js @@ -32,6 +32,7 @@ function plugin(fastify, opts, next) { asyncDispose: opts.asyncDispose, asyncInit: opts.asyncInit, eagerInject: opts.eagerInject, + strictBooleanEnforced: opts.strictBooleanEnforced, }) const disposeOnResponse = opts.disposeOnResponse === true || opts.disposeOnResponse === undefined const disposeOnClose = opts.disposeOnClose === true || opts.disposeOnClose === undefined diff --git a/lib/index.d.ts b/lib/index.d.ts index c05f4ad..3827595 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -25,6 +25,7 @@ export type FastifyAwilixOptions = { asyncInit?: boolean asyncDispose?: boolean eagerInject?: boolean + strictBooleanEnforced?: boolean } export const fastifyAwilixPlugin: FastifyPluginCallback> diff --git a/lib/index.test-d.ts b/lib/index.test-d.ts index 36c2729..fc6358a 100644 --- a/lib/index.test-d.ts +++ b/lib/index.test-d.ts @@ -16,6 +16,9 @@ expectAssignable({ asyncInit: false, asyncDispose: false } expectAssignable({ asyncInit: true, asyncDispose: true }) expectAssignable({ eagerInject: true }) +expectAssignable({ strictBooleanEnforced: true }) +expectAssignable({ strictBooleanEnforced: false }) + interface MailService { greet(name: string): void } diff --git a/package.json b/package.json index d8c7563..48785d2 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "prettier": "prettier --write \"{lib,test}/**/*.js\" lib/index.js lib/index.d.ts" }, "dependencies": { - "awilix-manager": "^5.0.1", + "awilix-manager": "^5.1.0", "fastify-plugin": "^4.5.1" }, "peerDependencies": {