Implements PheroUnchecked - #138
Open
kamilafsar wants to merge 5 commits into
Open
Conversation
With the PheroUnchecked utility type, a user can tag a context member to denote that Phero should skip validation for input/output of the middleware/function.
nloomans
requested changes
Sep 27, 2024
nloomans
left a comment
Contributor
There was a problem hiding this comment.
Nice work! Looking forward to use PheroUnchecked
nloomans
requested changes
Oct 9, 2024
nloomans
left a comment
Contributor
There was a problem hiding this comment.
Small issue with the documentation, but otherwise LGTM
Comment on lines
+18
to
+32
| /** | ||
| * By default all middleware input is parsed by Phero. With PheroUnchecked<T> you can | ||
| * mark a property within your middleware context, so that Phero will skip it during | ||
| * the parsing step. E.g. | ||
| * @example | ||
| * ```typescript | ||
| * async function getArticle(ctx: PheroContext<{ db: PheroUnchecked<RealDB> }>): Promise<string> { | ||
| * return ctx.db.query() | ||
| * } | ||
| * | ||
| * async function myMiddleware(context: PheroContext, next: PheroNextFunction<{ db: PheroUnchecked<DBClient> }>) { | ||
| * await next({ db: new DBClient() }) | ||
| * } | ||
| * ``` | ||
| */ |
Contributor
There was a problem hiding this comment.
"so that Phero will skip it during the parsing step" sounds like Phero will just omit the type. I also don't think users will understand what the "parsing step" refers to.
The example also has issues. JSDoc isn't markdown, so the ```typescript prefix should be omitted. Also the example shows incorrect usage, since we are providing DBClient but asking for RealDB.
How about this?
/**
* PheroUnchecked<T> is a special type that tells Phero it should not check at
* runtime if the types actually match what we expect. It may only be used
* within {@link PheroContext}, and must be provided by a middleware. This is
* useful for putting types in {@link PheroContext} that would normally be
* unsupported, such as a classes.
*
* @example
* async function getArticle(ctx: PheroContext<{ db: PheroUnchecked<DBClient> }>): Promise<string> {
* return ctx.db.query()
* }
*
* async function myMiddleware(context: PheroContext, next: PheroNextFunction<{ db: PheroUnchecked<DBClient> }>) {
* await next({ db: new DBClient() })
* }
*/
Author
There was a problem hiding this comment.
remove the "at runtime" in case Phero will not complain if this does compile:
* async function getArticle(ctx: PheroContext<{ db: PheroUnchecked<RealDB> }>): Promise<string> {
* return ctx.db.query()
* }
*
* async function myMiddleware(context: PheroContext, next: PheroNextFunction<{ db: PheroUnchecked<DBClient> }>) {
* await next({ db: new DBClient() })
* }
Notice the RealDB/DBClient typo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the PheroUnchecked utility type, a user can tag a context member to denote that Phero should skip validation for input/output of the middleware/function.
Last 2 commits are random improvements to the codebase