-
Notifications
You must be signed in to change notification settings - Fork 1
fetchのパラメータを指定できるようにする。 #213
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
base: master
Are you sure you want to change the base?
Conversation
- ExecuteOptionsインターフェースを追加 - 各API実行メソッドにoptions引数を追加 - NarouNovelFetchのfetchメソッドにfetchOptionsを渡すテストを追加
- ranking-history.test.tsにfetchOptionsを渡すテストを追加 - ranking.test.tsにfetchOptionsを渡すテストを追加 - search-builder-r18.test.tsにfetchOptionsを渡すテストを追加 - search-builder.test.tsにfetchOptionsを渡すテストを追加 - user-search.test.tsにfetchOptionsを渡すテストを追加
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 adds support for passing fetch options to the Narou API client, addressing the issue where Cloudflare Workers' fetch doesn't include a User-Agent by default. The implementation introduces an ExecuteOptions interface that allows users to specify custom fetch parameters (like headers) when making API requests.
Key changes:
- Added
ExecuteOptionsinterface with optionalfetchOptionsproperty for passing RequestInit parameters - Propagated the options parameter through all API execution methods (search, ranking, user search, and ranking history)
- Added comprehensive test coverage to verify that custom fetch options are properly passed to requests
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/narou.ts | Defines ExecuteOptions interface and adds options parameter to all abstract and concrete execute methods |
| src/narou-fetch.ts | Implements options forwarding by passing fetchOptions to the fetch call |
| src/narou-jsonp.ts | Accepts but ignores options parameter (JSONP doesn't support custom fetch options) |
| src/search-builder.ts | Adds options parameter to execute() method in base and novel search builder classes, includes minor whitespace change |
| src/search-builder-r18.ts | Adds options parameter to R18 search builder's execute() method |
| src/user-search.ts | Adds options parameter to user search builder's execute() method |
| src/ranking.ts | Adds options parameter to execute() and all executeWithFields() overloads |
| src/index.ts | Adds options parameter to rankingHistory() function with updated JSDoc |
| test/search-builder.test.ts | Tests that fetchOptions are properly passed for regular novel searches |
| test/search-builder-r18.test.ts | Tests that fetchOptions are properly passed for R18 novel searches |
| test/user-search.test.ts | Tests that fetchOptions are properly passed for user searches |
| test/ranking.test.ts | Tests that fetchOptions are properly passed for ranking requests |
| test/ranking-history.test.ts | Tests that fetchOptions are properly passed for ranking history requests, adds test infrastructure setup |
| test/narou-fetch.test.ts | Tests that fetchOptions are correctly forwarded to the underlying fetch call |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export async function rankingHistory( | ||
| ncode: string, | ||
| options?: ExecuteOptions, | ||
| api: NarouNovel = narouNovelFetch | ||
| ): Promise<RankingHistoryResult[]> { |
Copilot
AI
Jan 1, 2026
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 parameter order places options before api, which is inconsistent with common JavaScript/TypeScript patterns where optional configuration parameters typically come last. Consider reordering parameters to (ncode: string, api?: NarouNovel, options?: ExecuteOptions) or making options the last parameter as (ncode: string, options?: ExecuteOptions, api?: NarouNovel). However, placing the optional override parameter api last is more conventional, so the recommended signature would be: (ncode: string, options?: ExecuteOptions, api?: NarouNovel).
| protected params: TParams = {} as TParams, | ||
| protected api: NarouNovel | ||
| ) {} | ||
| ) { } |
Copilot
AI
Jan 1, 2026
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.
Unnecessary whitespace change. The constructor body should remain as {} instead of { } to maintain consistency with the existing code style.
| ) { } | |
| ) {} |
Cloudflare WorkersのfetchではUserAgentが付かないのでfetchのパラメータを指定できるようにしたい。
追加パラメータでfetchのオプションをいい感じに指定できるようにする。