loopbackio / loopbackio/loopback-next

docs: Improve examples of Interceptors with more implementation details

Đang mở
#4,450 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

developer-experience Docs good first issue IoC/Context
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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.