loopbackio / loopbackio/loopback-next
docs: Improve examples of Interceptors with more implementation details
Personne n'a encore pris cette issue.
- Langage dominant
- TypeScript
- Étoiles
- 5.1k
- Forks
- 1.1k
- Merge moyen
- 2 j 21 h
- PR mergées (30 j)
- 27
Description
In https://loopback.io/doc/en/lb4/Interceptors.html#example-interceptors
there are different examples of interceptors.
To understand the example implementations of these interceptors, let's
also show an example implementation of `what` they are intercepting.
For example:
```ts
/**
* A binding provider class to produce an interceptor that validates the
* `name` argument
*/
class NameValidator implements Provider {
constructor(@inject('valid-names') private validNames: string[]) {}
value() {
return this.intercept.bind(this);
}
// (doc improvement)
// This interceptor works as an authorizer for certain endpoints,
// which takes in the first argument as the name.
async intercept(
invocationCtx: InvocationContext,
next: () => ValueOrPromise,
) {
const name = invocationCtx.args[0];
if (!this.validNames.includes(name)) {
throw new Error(
`Name '${name}' is not on the list of '${this.validNames}`,
);
}
return next();
}
}
```
It is not clear what this interceptor is attached to. Is it a function, a class, a request?
How do we know that the `name` we need to validate is in args[0] of the invocation context?
Providing more implementation details would shed some light on how to use them.
_See [Reporting Issues](http://loopback.io/doc/en/contrib/Reporting-issues.html) for more tips on writing good issues_
## Acceptane Criteria
- [ ] Refine the docs to include more details described above.
- [ ] For the example snippet, it implies we need to add more details to `InvocationContext`'s properties, like `args`, see https://loopback.io/doc/en/lb4/apidocs.context.invocationcontext.html#properties
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la documentation d’Interceptors dans l’exemple lié et examinez les propriétés liées de l’API InvocationContext, en particulier args. Précisez à quoi l’interceptor est attaché, comment les arguments de la méthode interceptée correspondent à args[0], et ajoutez les détails d’implémentation demandés ; les critères d’acceptation devraient être satisfaits lorsque l’exemple est compréhensible sans ces questions restées sans réponse.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100