Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Standardized way of renaming third party plugin-scoped stuff #83

Closed
bogeychan opened this issue Aug 6, 2023 · 1 comment
Assignees

Comments

@bogeychan
Copy link
Contributor

@LoganArnett mentioned in a PR the idea of renaming derived or decorated properties of plugins when they are included in an actual application. This could prevent naming collisions in the future and give users the freedom to name things as they wish.

It would be nice to do this standardized via Elysia itself, such as:

import { Elysia } from 'elysia';

// this would be a plugin provided by a third party
const myPlugin = (app: Elysia) => app.decorate('myProperty', 42);

new Elysia()
  .use(
    myPlugin
      .mapContext({
        myProperty: 'prop' // rename derived or decorated properties one by one
      })
      .prefixAll('my-') // and/or apply a prefix to all
  )
  .get('/', (ctx) => ctx['my-prop'])
  .listen(8080);

In the logger plugin it is currently implemented as follows:

const app = new Elysia()
  .use(
    logger({
      contextKeyName: 'myLogger'
    })
  )
  .get('/', (ctx) => {
    // property "myLogger" is available instead of "log"
    ctx.myLogger.info(ctx.request, 'Request');

    return 'Hello World';
  })
  .listen(8080);
@SaltyAom SaltyAom self-assigned this Aug 28, 2023
@SaltyAom SaltyAom mentioned this issue Sep 6, 2023
87 tasks
@SaltyAom
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants