loopbackio / loopbackio/loopback-next
docs: Improve examples of Interceptors with more implementation details
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 5.1k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 27
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với tài liệu Interceptors trong ví dụ được liên kết và xem lại các thuộc tính API InvocationContext được liên kết, đặc biệt là args. Làm rõ interceptor được gắn vào đâu, các đối số của phương thức bị interceptor chặn được ánh xạ tới args[0] như thế nào, và bổ sung các chi tiết triển khai được yêu cầu; các tiêu chí chấp nhận phải được đáp ứng khi có thể hiểu ví dụ mà không còn những câu hỏi chưa được giải đáp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- documentation
- Loại issue
- Tài liệu
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100