loopbackio / loopbackio/loopback-next
docs: Improve examples of Interceptors with more implementation details
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 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:
/**
* 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Interceptors documentation at the linked example and review the linked InvocationContext API properties, especially args. Clarify what the interceptor is attached to, how the intercepted method's arguments map to args[0], and add the requested implementation details; the acceptance criteria should be satisfied when the example is understandable without these unanswered questions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100