loopbackio / loopbackio/loopback-next
docs: Improve examples of Interceptors with more implementation details
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- TypeScript
- Estrellas
- 5.1k
- Forks
- 1.1k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 27
Descripción
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:
/**
* A binding provider class to produce an interceptor that validates the
* `name` argument
*/
class NameValidator implements Provider<Interceptor> {
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<T>(
invocationCtx: InvocationContext,
next: () => ValueOrPromise<T>,
) {
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 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, likeargs, see https://loopback.io/doc/en/lb4/apidocs.context.invocationcontext.html#properties
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la documentación de Interceptors en el ejemplo enlazado y revisa las propiedades enlazadas de la API InvocationContext, especialmente args. Aclara a qué está asociado el interceptor, cómo los argumentos del método interceptado se asignan a args[0], y añade los detalles de implementación solicitados; los criterios de aceptación deben cumplirse cuando el ejemplo sea comprensible sin estas preguntas sin respuesta.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100