loopbackio / loopbackio/loopback-next
docs: Improve examples of Interceptors with more implementation details
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 5.1k
- フォーク
- 1.1k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 27
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた例の Interceptors ドキュメントから始め、リンクされた InvocationContext API のプロパティ、特に args を確認してください。interceptor が何にアタッチされているのか、インターセプトされたメソッドの引数がどのように args[0] にマッピングされるのかを明確にし、要求された実装の詳細を追加してください。これらの未回答の疑問がなくても例を理解できれば、受け入れ基準を満たすものとします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100