Skip to content

Conversation

@deflis
Copy link
Owner

@deflis deflis commented Dec 9, 2025

Summary

  • add an ExecuteOptions bag to Narou client methods to pass fetch settings
  • propagate optional fetch options through builders and ranking helpers
  • cover fetch option forwarding with a new NarouNovelFetch test and export the type

Testing

  • pnpm vitest run test/narou-fetch.test.ts

Codex Task

Copilot AI review requested due to automatic review settings December 9, 2025 21:14
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines 173 to +177
fields: TFields | TFields[] = [],
opt?: TOpt
opt?: TOpt,
options?: ExecuteOptions
): Promise<RankingResult<SearchResultFields<TFields>>[]> {
const ranking = await this.execute();
const ranking = await this.execute(options);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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 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 ExecuteOptions type with optional fetchOptions property to wrap RequestInit
  • Threaded the options parameter through all execute methods in the base NarouNovel class 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.

Comment on lines +34 to +36
execute(
options?: ExecuteOptions
): Promise<NarouSearchResults<NarouSearchResult, T | TOpt>> {
Copy link

Copilot AI Dec 9, 2025

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>} 検索結果
 */

Copilot uses AI. Check for mistakes.
Comment on lines +108 to +110
execute(
options?: ExecuteOptions
): Promise<NarouSearchResults<UserSearchResult, TField>> {
Copy link

Copilot AI Dec 9, 2025

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 ランキング
 */

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +125
async executeWithFields(
options?: ExecuteOptions
): Promise<RankingResult<DefaultSearchResultFields>[]>;
Copy link

Copilot AI Dec 9, 2025

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オプションなど)
 */

Copilot uses AI. Check for mistakes.
Comment on lines 23 to +24

export type ExecuteOptions = {
Copy link

Copilot AI Dec 9, 2025

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;
};
Suggested change
export type ExecuteOptions = {
/**
* なろう小説APIの実行オプション
*/
export type ExecuteOptions = {
/**
* fetch APIに渡すオプション (Node.js環境でのみ使用可能)
*/

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +106
async executeRanking(
params: RankingParams,
options?: ExecuteOptions
): Promise<NarouRankingResult[]> {
Copy link

Copilot AI Dec 9, 2025

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オプションなど)

Copilot uses AI. Check for mistakes.
Comment on lines 133 to 136
async executeWithFields<TFields extends Fields>(
fields: TFields | TFields[]
fields: TFields | TFields[],
options?: ExecuteOptions
): Promise<RankingResult<SearchResultFields<TFields>>[]>;
Copy link

Copilot AI Dec 9, 2025

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オプションなど)

Copilot uses AI. Check for mistakes.
Comment on lines 143 to 147
async executeWithFields(
fields: never[],
opt: OptionalFields | OptionalFields[]
opt: OptionalFields | OptionalFields[],
options?: ExecuteOptions
): Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>;
Copy link

Copilot AI Dec 9, 2025

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オプションなど)

Copilot uses AI. Check for mistakes.
Comment on lines 69 to 72
async executeNovel<T extends keyof NarouSearchResult>(
params: SearchParams
params: SearchParams,
options?: ExecuteOptions
): Promise<NarouSearchResults<NarouSearchResult, T>> {
Copy link

Copilot AI Dec 9, 2025

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オプションなど)

Copilot uses AI. Check for mistakes.
Comment on lines +477 to +479
execute(options?: ExecuteOptions): Promise<
NarouSearchResults<NarouSearchResult, T>
> {
Copy link

Copilot AI Dec 9, 2025

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>} 検索結果
 */

Copilot uses AI. Check for mistakes.
Comment on lines 52 to 56
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>> {
Copy link

Copilot AI Dec 9, 2025

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 検索結果
 */

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants