New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register plugin within namespace #5251
Comments
I love this idea It is doable, but:
|
I agree, it would simplify quite a lot of logic in some plugins. However this is quite tricky to implement due to how plugins work. This is usually one of the feature requests I would take to implement in avvio (given the fact that avvio is a mess), but I don't think I have the bandwidth. Moreover, it'd be a mess with TS, which has quite a lot of users and demand. |
@mcollina @Eomm A bit off-topic, but has the Fastify Org ever thought about applying to Google Code of Summer? This would be a good opportunity to implement such feature requests, which are likely to take quite a long time. |
But the decoration happens within I like @Eomm idea, potentially What's missed within |
I dont like this feature tbh. |
I change my mind 馃槃 Let's see this real example: test('plugin namespace', async t => {
t.plan(2)
const app = Fastify()
await app.register(async function plugin (app, opts) {
app.decorate('utility', function () {
return 'utility'
})
app.get('/', function (req, reply) {
// ! here the plugin would use app.utility()
// ! the plugin does not know about the namespace
reply.send({ utility: app.utility() })
})
}, { namepace: 'foo' })
// ! but outside the plugin the decorator would be app.foo.utility()
t.ok(app.foo.utility)
const res = await app.inject('/')
t.same(res.json(), { utility: 'utility' })
}) TLDR:
|
I think this is possible, even in v4. |
This is a widespread pattern: We are looking for a way to automate it and simplify its usage. |
Prerequisites
馃殌 Feature Proposal
In some situations, it would be helpful to register plugins within a namespace. This could be helpful in different situations when organising plugins. For example, when versioning plugins or grouping plugins that are related.
Motivation
See
Feature Proposal
but this feature could also work very well in combination with@fastify/autoload
. For example, if you use@fastify/basic-auth
and@fastify/jwt
in a project, it would be an improvement if both were under the namespaceauth
. The usage would then befastify.auth.sign({ payload } )
instead offastify.sign({ payload } )
respectivelyfastify.auth.basicAuth
instead offastify.basicAuth
.Example
The text was updated successfully, but these errors were encountered: