Skip to content

Commit

Permalink
Add support for strictBooleanEnforced (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad authored Feb 19, 2024
1 parent 289233d commit be756e5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/fastifyAwilixPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type FastifyAwilixOptions = {
asyncInit?: boolean
asyncDispose?: boolean
eagerInject?: boolean
strictBooleanEnforced?: boolean
}

export const fastifyAwilixPlugin: FastifyPluginCallback<NonNullable<FastifyAwilixOptions>>
Expand Down
3 changes: 3 additions & 0 deletions lib/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ expectAssignable<FastifyAwilixOptions>({ asyncInit: false, asyncDispose: false }
expectAssignable<FastifyAwilixOptions>({ asyncInit: true, asyncDispose: true })
expectAssignable<FastifyAwilixOptions>({ eagerInject: true })

expectAssignable<FastifyAwilixOptions>({ strictBooleanEnforced: true })
expectAssignable<FastifyAwilixOptions>({ strictBooleanEnforced: false })

interface MailService {
greet(name: string): void
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit be756e5

Please sign in to comment.