Skip to content

Conversation

@deflis
Copy link
Owner

@deflis deflis commented Jan 1, 2026

Cloudflare WorkersのfetchではUserAgentが付かないのでfetchのパラメータを指定できるようにしたい。

追加パラメータでfetchのオプションをいい感じに指定できるようにする。

- 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を渡すテストを追加
Copilot AI review requested due to automatic review settings January 1, 2026 13:14
Copy link
Contributor

Copilot AI left a 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 ExecuteOptions interface with optional fetchOptions property 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.

Comment on lines 75 to 79
export async function rankingHistory(
ncode: string,
options?: ExecuteOptions,
api: NarouNovel = narouNovelFetch
): Promise<RankingHistoryResult[]> {
Copy link

Copilot AI Jan 1, 2026

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).

Copilot uses AI. Check for mistakes.
protected params: TParams = {} as TParams,
protected api: NarouNovel
) {}
) { }
Copy link

Copilot AI Jan 1, 2026

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.

Suggested change
) { }
) {}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants