-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
ebd7c08
fb95eef
08b17c0
e00f739
6382816
fa4272b
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import type NarouNovel from "./narou.js"; | ||
| import type { ExecuteOptions } from "./narou.js"; | ||
| import NarouNovelFetch from "./narou-fetch.js"; | ||
| import NarouNovelJsonp from "./narou-jsonp.js"; | ||
| import RankingBuilder from "./ranking.js"; | ||
|
|
@@ -67,13 +68,16 @@ export function ranking(api: NarouNovel = narouNovelFetch): RankingBuilder { | |
| /** | ||
| * なろう殿堂入り API でランキング履歴を取得する | ||
| * @param {string} ncode 小説のNコード | ||
| * @param {ExecuteOptions} [options] 実行オプション | ||
| * @param {NarouNovel} [api] API実行クラスのインスタンス | ||
| * @see https://dev.syosetu.com/man/rankinapi/ | ||
| */ | ||
| export async function rankingHistory( | ||
| ncode: string, | ||
| options?: ExecuteOptions, | ||
| api: NarouNovel = narouNovelFetch | ||
| ): Promise<RankingHistoryResult[]> { | ||
|
Comment on lines
75
to
79
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.
The new Useful? React with 👍 / 👎. |
||
| const result = await api.executeRankingHistory({ ncode }); | ||
| const result = await api.executeRankingHistory({ ncode }, options); | ||
|
Comment on lines
75
to
+80
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.
The public Useful? React with 👍 / 👎.
Owner
Author
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. APIを破壊的な変更してるから次のリリースは2.0.0かな… |
||
| if (Array.isArray(result)) { | ||
| return result.map(formatRankingHistory); | ||
| } else { | ||
|
|
||
| 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"; | ||
|
|
||
|
|
@@ -108,21 +109,24 @@ export default class RankingBuilder { | |
| * 設定されたパラメータに基づき、なろう小説ランキングAPIへのリクエストを実行します。 | ||
| * | ||
| * 返される結果には、Nコード、ポイント、順位が含まれます。 | ||
| * @param options 実行オプション | ||
| * @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( | ||
| fields?: never[] | undefined, | ||
| opt?: never[] | undefined, | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<DefaultSearchResultFields>[]>; | ||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
| * | ||
|
|
@@ -131,7 +135,9 @@ export default class RankingBuilder { | |
| * @returns {Promise<RankingResult<SearchResultFields<TFields>>[]>} 詳細情報を含むランキング結果の配列 | ||
| */ | ||
| async executeWithFields<TFields extends Fields>( | ||
| fields: TFields | TFields[] | ||
| fields: TFields | TFields[], | ||
| opt?: never | never[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields>>[]>; | ||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
|
|
@@ -141,7 +147,8 @@ export default class RankingBuilder { | |
| */ | ||
| async executeWithFields( | ||
| fields: never[], | ||
| opt: OptionalFields | OptionalFields[] | ||
| opt: OptionalFields | OptionalFields[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>; | ||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
|
|
@@ -153,7 +160,8 @@ export default class RankingBuilder { | |
| */ | ||
| async executeWithFields<TFields extends Fields>( | ||
| fields: TFields | TFields[], | ||
| opt: OptionalFields | OptionalFields[] | ||
| opt: OptionalFields | OptionalFields[], | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields> | "weekly_unique">[]>; | ||
| /** | ||
| * ランキングAPIを実行し、取得したNコードを元になろう小説APIで詳細情報を取得して結合します。 | ||
|
|
@@ -169,9 +177,10 @@ export default class RankingBuilder { | |
| TOpt extends OptionalFields | undefined = undefined | ||
| >( | ||
| fields: TFields | TFields[] = [], | ||
| opt?: TOpt | ||
| opt?: TOpt, | ||
| options?: ExecuteOptions | ||
| ): Promise<RankingResult<SearchResultFields<TFields>>[]> { | ||
|
Comment on lines
179
to
182
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.
Overloads advertise Useful? React with 👍 / 👎. |
||
| const ranking = await this.execute(); | ||
| const ranking = await this.execute(options); | ||
| const fields$ = Array.isArray(fields) | ||
| ? fields.length == 0 | ||
| ? [] | ||
|
|
@@ -186,7 +195,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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||
| import type NarouNovel from "./narou.js"; | ||||||
| import type { ExecuteOptions } from "./narou.js"; | ||||||
| import type { | ||||||
| NarouSearchResult, | ||||||
| SearchResultFields, | ||||||
|
|
@@ -40,7 +41,7 @@ export abstract class SearchBuilderBase< | |||||
| constructor( | ||||||
| protected params: TParams = {} as TParams, | ||||||
| protected api: NarouNovel | ||||||
| ) {} | ||||||
| ) { } | ||||||
deflis marked this conversation as resolved.
Show resolved
Hide resolved
deflis marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| ) { } | |
| ) {} |
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
optionsbeforeapi, 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 parameterapilast is more conventional, so the recommended signature would be:(ncode: string, options?: ExecuteOptions, api?: NarouNovel).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.
これはAPIクライアントをできるだけ隠蔽したいのでこのまま