-
Notifications
You must be signed in to change notification settings - Fork 0
Add fetch options support via execute options bag #208
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
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fields: TFields | TFields[] = [], | ||
| opt?: TOpt | ||
| opt?: TOpt, | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields>>[]> { | ||
| const ranking = await this.execute(); | ||
| const ranking = await this.execute(options); |
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.
executeWithFields drops ExecuteOptions
executeWithFields advertises overloads that accept an ExecuteOptions bag either as the only argument or as the second argument, but the implementation still treats the second parameter as opt and only forwards the third parameter to execute. If a caller passes ExecuteOptions (with fetchOptions) to rank-with-fields—e.g., executeWithFields(options) or executeWithFields(fields, options)—the options object is instead consumed as fields/opt (polluting the query) and never reaches execute or builder.execute, so the new fetch options support is broken for this helper.
Useful? React with 👍 / 👎.
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 by introducing an ExecuteOptions bag pattern. This enables users to customize fetch behavior (headers, method, etc.) when making API requests in Node.js environments.
Key Changes
- Introduced
ExecuteOptionstype with optionalfetchOptionsproperty to wrapRequestInit - Threaded the options parameter through all execute methods in the base
NarouNovelclass and concrete implementations - Propagated options through all builder classes (search, R18, user, ranking) to maintain the fluent API
- Added test coverage for fetch option forwarding with a custom fetch mock
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/narou.ts | Added ExecuteOptions type and threaded options parameter through all execute methods |
| src/narou-fetch.ts | Updated to pass options?.fetchOptions to the fetch implementation |
| src/narou-jsonp.ts | Added _options parameter (intentionally unused for JSONP) for signature compatibility |
| src/search-builder.ts | Updated execute() to accept and forward options |
| src/search-builder-r18.ts | Updated execute() to accept and forward options |
| src/user-search.ts | Updated execute() to accept and forward options |
| src/ranking.ts | Updated execute() and executeWithFields() overloads to accept and forward options |
| src/index.common.ts | Exported ExecuteOptions type for public API consumers |
| test/narou-fetch.test.ts | Added test verifying fetch options are correctly passed to fetch implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| execute( | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<NarouSearchResult, T | TOpt>> { |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Update the JSDoc to:
/**
* なろう小説APIへの検索リクエストを実行する
* @override
* @param options 実行オプション(fetchオプションなど)
* @returns {Promise<NarouSearchResults>} 検索結果
*/| execute( | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<UserSearchResult, TField>> { |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Update the JSDoc to:
/**
* なろう小説APIへのリクエストを実行する
* @param options 実行オプション(fetchオプションなど)
* @returns ランキング
*/| async executeWithFields( | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<DefaultSearchResultFields>[]>; |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. While this is an overload signature without a body, it should still document the parameter for API consumers.
Add @param documentation:
/**
* ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。
* @param options 実行オプション(fetchオプションなど)
*/|
|
||
| export type ExecuteOptions = { |
Copilot
AI
Dec 9, 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.
Missing JSDoc documentation for the ExecuteOptions type. As a public API type that's exported in index.common.ts, it should have documentation explaining its purpose and usage.
Add JSDoc:
/**
* なろう小説APIの実行オプション
*/
export type ExecuteOptions = {
/**
* fetch APIに渡すオプション (Node.js環境でのみ使用可能)
*/
fetchOptions?: RequestInit;
};| export type ExecuteOptions = { | |
| /** | |
| * なろう小説APIの実行オプション | |
| */ | |
| export type ExecuteOptions = { | |
| /** | |
| * fetch APIに渡すオプション (Node.js環境でのみ使用可能) | |
| */ |
| async executeRanking( | ||
| params: RankingParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouRankingResult[]> { |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Add after the @param params line:
* @param options 実行オプション(fetchオプションなど)| async executeWithFields<TFields extends Fields>( | ||
| fields: TFields | TFields[] | ||
| fields: TFields | TFields[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields>>[]>; |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Add @param documentation after the @param fields line:
* @param options 実行オプション(fetchオプションなど)| async executeWithFields( | ||
| fields: never[], | ||
| opt: OptionalFields | OptionalFields[] | ||
| opt: OptionalFields | OptionalFields[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>; |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Add @param documentation after the @param opt line:
* @param options 実行オプション(fetchオプションなど)| async executeNovel<T extends keyof NarouSearchResult>( | ||
| params: SearchParams | ||
| params: SearchParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<NarouSearchResult, T>> { |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Add after the @param params line:
* @param options 実行オプション(fetchオプションなど)| execute(options?: ExecuteOptions): Promise< | ||
| NarouSearchResults<NarouSearchResult, T> | ||
| > { |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Update the JSDoc to:
/**
* なろう小説APIへの検索リクエストを実行する
* @param options 実行オプション(fetchオプションなど)
* @returns {Promise<NarouSearchResults>} 検索結果
*/| protected async executeSearch<T extends keyof NarouSearchResult>( | ||
| params: SearchParams, | ||
| endpoint = "https://api.syosetu.com/novelapi/api/" | ||
| endpoint = "https://api.syosetu.com/novelapi/api/", | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<NarouSearchResult, T>> { |
Copilot
AI
Dec 9, 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.
Missing JSDoc @param documentation for the new options parameter. The JSDoc should be updated to document this parameter.
Add:
/**
* APIへの検索リクエストを実行する
* @param params クエリパラメータ
* @param endpoint APIエンドポイント
* @param options 実行オプション(fetchオプションなど)
* @returns 検索結果
*/
Summary
Testing
Codex Task