-
-
Notifications
You must be signed in to change notification settings - Fork 55
Support $raw method to allow access to response headers #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors API method definitions to use a new Endpoint type utility instead of explicit method signatures. The change standardizes how API endpoints are typed across the accounts resource by introducing a generic type that handles optional parameters more elegantly and adds experimental $raw method support.
Key Changes
- Introduced a new
Endpoint<Params, Meta, Response>utility type that provides both standard and raw response methods - Converted all method signatures in
accounts.tsto use theEndpointtype - Added JSDoc comments and fixed indentation for some existing documentation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/mastodon/endpoint.ts | New file defining the Endpoint utility type with conditional typing for optional vs required parameters |
| src/mastodon/rest/v1/accounts.ts | Refactored all method signatures to use the new Endpoint type instead of explicit function signatures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/mastodon/endpoint.ts
Outdated
| @@ -0,0 +1,15 @@ | |||
| type OptionalRecord = { | |||
| [key in string]?: any; | |||
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using any defeats TypeScript's type safety. Consider using unknown instead, or if you need any indexable object, use [key: string]: unknown.
| [key in string]?: any; | |
| [key in string]?: unknown; |
| params?: FollowAccountParams, | ||
| meta?: HttpMetaParams<"json">, | ||
| ): Promise<Relationship>; | ||
| follow: Endpoint<FollowAccountParams, HttpMetaParams<"json">, Relationship>; |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FollowAccountParams interface contains only optional properties, which should make params optional in the resulting Endpoint signature. However, the Endpoint type's conditional logic requires Params extends OptionalRecord | undefined to make params optional. Since FollowAccountParams is not explicitly undefined, params will be required even though all properties are optional. Consider using Endpoint<FollowAccountParams | undefined, ...> or updating the Endpoint type to better handle interfaces with all-optional properties.
| params?: FollowAccountParams, | ||
| meta?: HttpMetaParams<"json">, | ||
| ): Promise<Relationship>; | ||
| unfollow: Endpoint<FollowAccountParams, HttpMetaParams<"json">, Relationship>; |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as follow: FollowAccountParams has all optional properties but will result in required params parameter. The original signature had params?: making it optional. Consider using Endpoint<FollowAccountParams | undefined, ...> to maintain the original API behavior.
| unfollow: Endpoint<FollowAccountParams, HttpMetaParams<"json">, Relationship>; | |
| unfollow: Endpoint<FollowAccountParams | undefined, HttpMetaParams<"json">, Relationship>; |
| params?: MuteAccountParams, | ||
| meta?: HttpMetaParams<"json">, | ||
| ): Promise<Relationship>; | ||
| mute: Endpoint<MuteAccountParams, HttpMetaParams<"json">, Relationship>; |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MuteAccountParams interface contains only optional properties, but will result in a required params parameter. The original signature had params?: making it optional. Consider using Endpoint<MuteAccountParams | undefined, ...> to maintain backward compatibility.
| mute: Endpoint<MuteAccountParams, HttpMetaParams<"json">, Relationship>; | |
| mute: Endpoint<MuteAccountParams | undefined, HttpMetaParams<"json">, Relationship>; |
6e444a2 to
422bc6a
Compare
Closes #684