loopbackio / loopbackio/loopback-next
docs: Improve examples of Interceptors with more implementation details
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 5.1k
- Fork
- 1.1k
- Merge medio
- 2g 21h
- PR unite (30g)
- 27
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la documentazione di Interceptors nell’esempio collegato e rivedi le proprietà collegate dell’API InvocationContext, in particolare args. Chiarisci a cosa è associato l’interceptor, come gli argomenti del metodo intercettato vengono mappati su args[0], e aggiungi i dettagli di implementazione richiesti; i criteri di accettazione dovrebbero essere soddisfatti quando l’esempio è comprensibile senza queste domande senza risposta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100