-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ export type NarouParams = | |
| | RankingHistoryParams | ||
| | UserSearchParams; | ||
|
|
||
| export type ExecuteOptions = { | ||
| fetchOptions?: RequestInit; | ||
| }; | ||
|
|
||
| /** | ||
| * なろう小説APIへのリクエストを実行する | ||
| * @class NarouNovel | ||
|
|
@@ -35,7 +39,8 @@ export default abstract class NarouNovel { | |
| */ | ||
| protected abstract execute<T>( | ||
| params: NarouParams, | ||
| endpoint: string | ||
| endpoint: string, | ||
| options?: ExecuteOptions | ||
| ): Promise<T>; | ||
|
Comment on lines
40
to
44
|
||
|
|
||
| /** | ||
|
|
@@ -46,9 +51,13 @@ export default abstract class NarouNovel { | |
| */ | ||
| 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>> { | ||
|
Comment on lines
52
to
56
|
||
| return new NarouSearchResults(await this.execute(params, endpoint), params); | ||
| return new NarouSearchResults( | ||
| await this.execute(params, endpoint, options), | ||
| params | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -58,11 +67,13 @@ export default abstract class NarouNovel { | |
| * @see https://dev.syosetu.com/man/api/ | ||
| */ | ||
| async executeNovel<T extends keyof NarouSearchResult>( | ||
| params: SearchParams | ||
| params: SearchParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<NarouSearchResult, T>> { | ||
|
Comment on lines
69
to
72
|
||
| return await this.executeSearch( | ||
| params, | ||
| "https://api.syosetu.com/novelapi/api/" | ||
| "https://api.syosetu.com/novelapi/api/", | ||
| options | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -73,11 +84,13 @@ export default abstract class NarouNovel { | |
| * @see https://dev.syosetu.com/xman/api/ | ||
| */ | ||
| async executeNovel18<T extends keyof NarouSearchResult>( | ||
| params: SearchParams | ||
| params: SearchParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<NarouSearchResult, T>> { | ||
|
Comment on lines
86
to
89
|
||
| return await this.executeSearch( | ||
| params, | ||
| "https://api.syosetu.com/novel18api/api/" | ||
| "https://api.syosetu.com/novel18api/api/", | ||
| options | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -87,8 +100,15 @@ export default abstract class NarouNovel { | |
| * @returns ランキング結果 | ||
| * @see https://dev.syosetu.com/man/rankapi/ | ||
| */ | ||
| async executeRanking(params: RankingParams): Promise<NarouRankingResult[]> { | ||
| return await this.execute(params, "https://api.syosetu.com/rank/rankget/"); | ||
| async executeRanking( | ||
| params: RankingParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouRankingResult[]> { | ||
|
Comment on lines
+103
to
+106
|
||
| return await this.execute( | ||
| params, | ||
| "https://api.syosetu.com/rank/rankget/", | ||
| options | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -98,9 +118,14 @@ export default abstract class NarouNovel { | |
| * @see https://dev.syosetu.com/man/rankinapi/ | ||
| */ | ||
| async executeRankingHistory( | ||
| params: RankingHistoryParams | ||
| params: RankingHistoryParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingHistoryRawResult[]> { | ||
|
Comment on lines
120
to
123
|
||
| return await this.execute(params, "https://api.syosetu.com/rank/rankin/"); | ||
| return await this.execute( | ||
| params, | ||
| "https://api.syosetu.com/rank/rankin/", | ||
| options | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -110,10 +135,15 @@ export default abstract class NarouNovel { | |
| * @see https://dev.syosetu.com/man/userapi/ | ||
| */ | ||
| async executeUserSearch<T extends keyof UserSearchResult>( | ||
| params: UserSearchParams | ||
| params: UserSearchParams, | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<UserSearchResult, T>> { | ||
|
Comment on lines
137
to
140
|
||
| return new NarouSearchResults<UserSearchResult, T>( | ||
| await this.execute(params, "https://api.syosetu.com/userapi/api/"), | ||
| await this.execute( | ||
| params, | ||
| "https://api.syosetu.com/userapi/api/", | ||
| options | ||
| ), | ||
| params | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { | |
| Fields, | ||
| } from "./params.js"; | ||
| import type NarouNovel from "./narou.js"; | ||
| import type { ExecuteOptions } from "./narou.js"; | ||
| import type { SearchResultFields } from "./narou-search-results.js"; | ||
| import { addDays, formatDate } from "./util/date.js"; | ||
|
|
||
|
|
@@ -111,18 +112,18 @@ export default class RankingBuilder { | |
| * @returns {Promise<NarouRankingResult[]>} ランキング結果の配列 | ||
| * @see https://dev.syosetu.com/man/rankapi/#output | ||
| */ | ||
| execute(): Promise<NarouRankingResult[]> { | ||
| execute(options?: ExecuteOptions): Promise<NarouRankingResult[]> { | ||
|
||
| const date = formatDate(this.date$); | ||
| this.set({ rtype: `${date}-${this.type$}` }); | ||
| return this.api.executeRanking(this.params as RankingParams); | ||
| return this.api.executeRanking(this.params as RankingParams, options); | ||
| } | ||
|
|
||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
| */ | ||
| async executeWithFields(): Promise< | ||
| RankingResult<DefaultSearchResultFields>[] | ||
| >; | ||
| async executeWithFields( | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<DefaultSearchResultFields>[]>; | ||
|
Comment on lines
+124
to
+126
|
||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
| * | ||
|
|
@@ -131,7 +132,8 @@ export default class RankingBuilder { | |
| * @returns {Promise<RankingResult<SearchResultFields<TFields>>[]>} 詳細情報を含むランキング結果の配列 | ||
| */ | ||
| async executeWithFields<TFields extends Fields>( | ||
| fields: TFields | TFields[] | ||
| fields: TFields | TFields[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields>>[]>; | ||
|
Comment on lines
134
to
137
|
||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
|
|
@@ -141,7 +143,8 @@ export default class RankingBuilder { | |
| */ | ||
| async executeWithFields( | ||
| fields: never[], | ||
| opt: OptionalFields | OptionalFields[] | ||
| opt: OptionalFields | OptionalFields[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>; | ||
|
Comment on lines
144
to
148
|
||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
|
|
@@ -169,9 +172,10 @@ export default class RankingBuilder { | |
| TOpt extends OptionalFields | undefined = undefined | ||
| >( | ||
| fields: TFields | TFields[] = [], | ||
| opt?: TOpt | ||
| opt?: TOpt, | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields>>[]> { | ||
| const ranking = await this.execute(); | ||
| const ranking = await this.execute(options); | ||
|
Comment on lines
174
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 Useful? React with 👍 / 👎. |
||
| const fields$ = Array.isArray(fields) | ||
| ? fields.length == 0 | ||
| ? [] | ||
|
|
@@ -186,7 +190,7 @@ export default class RankingBuilder { | |
| } | ||
| builder.ncode(rankingNcodes); | ||
| builder.limit(ranking.length); | ||
| const result = await builder.execute(); | ||
| const result = await builder.execute(options); | ||
|
|
||
| return ranking.map< | ||
| RankingResult< | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import type { | |
| SearchResultR18Fields, | ||
| SearchResultOptionalFields, | ||
| } from "./narou-search-results.js"; | ||
| import type { ExecuteOptions } from "./narou.js"; | ||
| import type { | ||
| R18Site, | ||
| SearchResultFieldNames, | ||
|
|
@@ -30,8 +31,10 @@ export default class SearchBuilderR18< | |
| * @override | ||
| * @returns {Promise<NarouSearchResults>} 検索結果 | ||
| */ | ||
| execute(): Promise<NarouSearchResults<NarouSearchResult, T | TOpt>> { | ||
| return this.api.executeNovel18(this.params); | ||
| execute( | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<NarouSearchResult, T | TOpt>> { | ||
|
Comment on lines
+34
to
+36
|
||
| return this.api.executeNovel18(this.params, options); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import type NarouNovel from "./narou.js"; | ||
| import type { ExecuteOptions } from "./narou.js"; | ||
| import type { | ||
| NarouSearchResult, | ||
| SearchResultFields, | ||
|
|
@@ -474,8 +475,10 @@ export abstract class NovelSearchBuilderBase< | |
| * なろう小説APIへの検索リクエストを実行する | ||
| * @returns {Promise<NarouSearchResults>} 検索結果 | ||
| */ | ||
| execute(): Promise<NarouSearchResults<NarouSearchResult, T>> { | ||
| return this.api.executeNovel(this.params); | ||
| execute(options?: ExecuteOptions): Promise< | ||
| NarouSearchResults<NarouSearchResult, T> | ||
| > { | ||
|
Comment on lines
+478
to
+480
|
||
| return this.api.executeNovel(this.params, options); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import type { | |
| } from "./narou-search-results.js"; | ||
| import type { UserFields, UserOrder, UserSearchParams } from "./params.js"; | ||
| import { SearchBuilderBase } from "./search-builder.js"; | ||
| import type { ExecuteOptions } from "./narou.js"; | ||
|
|
||
| /** | ||
| * なろうユーザ検索API | ||
|
|
@@ -104,7 +105,12 @@ export default class UserSearchBuilder< | |
| * なろう小説APIへのリクエストを実行する | ||
| * @returns ランキング | ||
| */ | ||
| execute(): Promise<NarouSearchResults<UserSearchResult, TField>> { | ||
| return this.api.executeUserSearch(this.params as UserSearchParams); | ||
| execute( | ||
| options?: ExecuteOptions | ||
| ): Promise<NarouSearchResults<UserSearchResult, TField>> { | ||
|
Comment on lines
+108
to
+110
|
||
| return this.api.executeUserSearch( | ||
| this.params as UserSearchParams, | ||
| 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.
Missing JSDoc documentation for the
ExecuteOptionstype. As a public API type that's exported inindex.common.ts, it should have documentation explaining its purpose and usage.Add JSDoc: