narou 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/index.browser.d.ts.map +1 -1
  2. package/dist/index.browser.js +5 -1
  3. package/dist/index.browser.js.map +1 -1
  4. package/dist/index.common.d.ts +7 -5
  5. package/dist/index.common.d.ts.map +1 -1
  6. package/dist/index.common.js +9 -3
  7. package/dist/index.common.js.map +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +5 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/narou-ranking-results.d.ts +4 -3
  12. package/dist/narou-ranking-results.d.ts.map +1 -1
  13. package/dist/narou-search-results.d.ts +49 -19
  14. package/dist/narou-search-results.d.ts.map +1 -1
  15. package/dist/narou-search-results.js +16 -2
  16. package/dist/narou-search-results.js.map +1 -1
  17. package/dist/narou.d.ts +4 -4
  18. package/dist/narou.d.ts.map +1 -1
  19. package/dist/narou.js.map +1 -1
  20. package/dist/params.d.ts +223 -171
  21. package/dist/params.d.ts.map +1 -1
  22. package/dist/params.js +206 -150
  23. package/dist/params.js.map +1 -1
  24. package/dist/ranking-history.d.ts +2 -2
  25. package/dist/ranking-history.d.ts.map +1 -1
  26. package/dist/ranking.d.ts +10 -12
  27. package/dist/ranking.d.ts.map +1 -1
  28. package/dist/ranking.js +7 -19
  29. package/dist/ranking.js.map +1 -1
  30. package/dist/search-builder-r18.d.ts +12 -6
  31. package/dist/search-builder-r18.d.ts.map +1 -1
  32. package/dist/search-builder-r18.js +13 -18
  33. package/dist/search-builder-r18.js.map +1 -1
  34. package/dist/search-builder.d.ts +52 -46
  35. package/dist/search-builder.d.ts.map +1 -1
  36. package/dist/search-builder.js +164 -138
  37. package/dist/search-builder.js.map +1 -1
  38. package/dist/util/jsonp.d.ts.map +1 -1
  39. package/dist/util/jsonp.js +2 -1
  40. package/dist/util/jsonp.js.map +1 -1
  41. package/dist/util/type.d.ts +4 -0
  42. package/dist/util/type.d.ts.map +1 -0
  43. package/dist/util/type.js +3 -0
  44. package/dist/util/type.js.map +1 -0
  45. package/dist/util/url.d.ts +1 -1
  46. package/dist.es2015/index.browser.js.map +1 -1
  47. package/dist.es2015/index.common.js +4 -3
  48. package/dist.es2015/index.common.js.map +1 -1
  49. package/dist.es2015/index.js.map +1 -1
  50. package/dist.es2015/narou-search-results.js +14 -1
  51. package/dist.es2015/narou-search-results.js.map +1 -1
  52. package/dist.es2015/narou.js.map +1 -1
  53. package/dist.es2015/params.js +204 -149
  54. package/dist.es2015/params.js.map +1 -1
  55. package/dist.es2015/ranking.js +3 -14
  56. package/dist.es2015/ranking.js.map +1 -1
  57. package/dist.es2015/search-builder-r18.js +14 -19
  58. package/dist.es2015/search-builder-r18.js.map +1 -1
  59. package/dist.es2015/search-builder.js +103 -99
  60. package/dist.es2015/search-builder.js.map +1 -1
  61. package/dist.es2015/util/jsonp.js +1 -0
  62. package/dist.es2015/util/jsonp.js.map +1 -1
  63. package/dist.es2015/util/type.js +2 -0
  64. package/dist.es2015/util/type.js.map +1 -0
  65. package/dist.esm/index.browser.js.map +1 -1
  66. package/dist.esm/index.common.js +4 -3
  67. package/dist.esm/index.common.js.map +1 -1
  68. package/dist.esm/index.js.map +1 -1
  69. package/dist.esm/narou-search-results.js +14 -1
  70. package/dist.esm/narou-search-results.js.map +1 -1
  71. package/dist.esm/narou.js.map +1 -1
  72. package/dist.esm/params.js +205 -149
  73. package/dist.esm/params.js.map +1 -1
  74. package/dist.esm/ranking.js +4 -15
  75. package/dist.esm/ranking.js.map +1 -1
  76. package/dist.esm/search-builder-r18.js +14 -19
  77. package/dist.esm/search-builder-r18.js.map +1 -1
  78. package/dist.esm/search-builder.js +163 -138
  79. package/dist.esm/search-builder.js.map +1 -1
  80. package/dist.esm/util/jsonp.js +2 -1
  81. package/dist.esm/util/jsonp.js.map +1 -1
  82. package/dist.esm/util/type.js +2 -0
  83. package/dist.esm/util/type.js.map +1 -0
  84. package/package.json +23 -46
  85. package/src/index.browser.ts +2 -2
  86. package/src/index.common.ts +18 -4
  87. package/src/index.ts +2 -2
  88. package/src/narou-ranking-results.ts +6 -2
  89. package/src/narou-search-results.ts +70 -20
  90. package/src/narou.ts +13 -6
  91. package/src/params.ts +277 -175
  92. package/src/ranking-history.ts +2 -2
  93. package/src/ranking.ts +47 -23
  94. package/src/search-builder-r18.ts +30 -20
  95. package/src/search-builder.ts +148 -124
  96. package/src/util/jsonp.ts +3 -0
  97. package/src/util/type.ts +3 -0
  98. package/package-lock.json +0 -3328
package/src/params.ts CHANGED
@@ -1,4 +1,13 @@
1
- export type booleanNumber = 0 | 1;
1
+ import { NarouSearchResult } from "./narou-search-results";
2
+ import { Join } from "./util/type";
3
+
4
+ export const RankingType = {
5
+ Daily: "d",
6
+ Weekly: "w",
7
+ Monthly: "m",
8
+ Quarterly: "q",
9
+ } as const;
10
+ export type RankingType = typeof RankingType[keyof typeof RankingType];
2
11
 
3
12
  /**
4
13
  * {@link SearchBuilder#Fields}メソッドにパラメータを指定する際のヘルパー。
@@ -39,40 +48,40 @@ export interface SearchParams {
39
48
 
40
49
  word?: string;
41
50
  notword?: string;
42
- title?: booleanNumber;
43
- ex?: booleanNumber;
44
- keyword?: booleanNumber;
45
- wname?: booleanNumber;
46
-
47
- biggenre?: string | BigGenre;
48
- notbiggenre?: string | BigGenre;
49
- genre?: string | Genre;
50
- notgenre?: string | Genre;
51
- userid?: string | number;
52
-
53
- nocgenre?: string | number;
54
- notnocgenre?: string | number;
55
- xid?: string | number;
56
-
57
- isr15?: booleanNumber;
58
- isbl?: booleanNumber;
59
- isgl?: booleanNumber;
60
- iszankoku?: booleanNumber;
61
- istensei?: booleanNumber;
62
- istenni?: booleanNumber;
63
- istt?: booleanNumber;
64
-
65
- notr15?: booleanNumber;
66
- notbl?: booleanNumber;
67
- notgl?: booleanNumber;
68
- notzankoku?: booleanNumber;
69
- nottensei?: booleanNumber;
70
- nottenni?: booleanNumber;
71
- nottt?: booleanNumber;
51
+ title?: BooleanNumber;
52
+ ex?: BooleanNumber;
53
+ keyword?: BooleanNumber;
54
+ wname?: BooleanNumber;
55
+
56
+ biggenre?: Join<BigGenre> | BigGenre;
57
+ notbiggenre?: Join<BigGenre> | BigGenre;
58
+ genre?: Join<Genre> | Genre;
59
+ notgenre?: Join<Genre> | Genre;
60
+ userid?: Join<number> | number;
61
+
62
+ nocgenre?: Join<R18Site> | R18Site;
63
+ notnocgenre?: Join<R18Site> | R18Site;
64
+ xid?: Join<number> | number;
65
+
66
+ isr15?: BooleanNumber;
67
+ isbl?: BooleanNumber;
68
+ isgl?: BooleanNumber;
69
+ iszankoku?: BooleanNumber;
70
+ istensei?: BooleanNumber;
71
+ istenni?: BooleanNumber;
72
+ istt?: BooleanNumber;
73
+
74
+ notr15?: BooleanNumber;
75
+ notbl?: BooleanNumber;
76
+ notgl?: BooleanNumber;
77
+ notzankoku?: BooleanNumber;
78
+ nottensei?: BooleanNumber;
79
+ nottenni?: BooleanNumber;
80
+ nottt?: BooleanNumber;
72
81
 
73
82
  minlen?: number;
74
83
  maxlen?: number;
75
- length?: number | string;
84
+ length?: number | Join<number>;
76
85
 
77
86
  kaiwaritu?: number | string;
78
87
  sasie?: number | string;
@@ -81,22 +90,22 @@ export interface SearchParams {
81
90
  maxtime?: number;
82
91
  time?: number | string;
83
92
 
84
- ncode?: string;
93
+ ncode?: string | Join<string>;
85
94
 
86
95
  type?: NovelType;
87
96
 
88
- buntai?: Buntai | string;
97
+ buntai?: Buntai | Join<Buntai>;
89
98
 
90
99
  stop?: Stop;
91
100
 
92
- ispickup?: booleanNumber;
101
+ ispickup?: BooleanNumber;
93
102
  lastup?: string;
94
103
 
95
- opt?: string;
104
+ opt?: Join<OptionalFields>;
96
105
  }
97
106
 
98
107
  export interface RankingParams {
99
- rtype: string;
108
+ rtype: `${string}-${RankingType}`;
100
109
  gzip?: GzipLevel;
101
110
  out?: "json";
102
111
  }
@@ -107,33 +116,114 @@ export interface RankingHistoryParams {
107
116
  out?: "json";
108
117
  }
109
118
 
110
- export enum Fields {
111
- title = "t",
112
- ncode = "n",
113
- userid = "u",
114
- writer = "w",
115
- story = "s",
116
- genre = "g",
117
- keyword = "k",
118
- general_firstup = "gf",
119
- general_lastup = "gl",
120
- noveltype = "nt",
121
- end = "e",
122
- general_all_no = "ga",
123
- length = "l",
124
- time = "ti",
125
- isstop = "i",
126
- pc_or_k = "p",
127
- global_point = "gp",
128
- fav_novel_cnt = "f",
129
- review_cnt = "r",
130
- all_point = "a",
131
- all_hyoka_cnt = "ah",
132
- sasie_cnt = "sa",
133
- kaiwaritu = "ka",
134
- novelupdated_at = "nu",
135
- updated_at = "ua",
136
- }
119
+ export const BooleanNumber = {
120
+ True: 1,
121
+ False: 0,
122
+ } as const;
123
+ export type BooleanNumber = typeof BooleanNumber[keyof typeof BooleanNumber];
124
+
125
+ export type SearchResultFieldNames = keyof NarouSearchResult;
126
+
127
+ export const Fields = {
128
+ title: "t",
129
+ ncode: "n",
130
+ userid: "u",
131
+ writer: "w",
132
+ story: "s",
133
+ biggenre: "bg",
134
+ genre: "g",
135
+ nocgenre: "ng",
136
+ keyword: "k",
137
+ general_firstup: "gf",
138
+ general_lastup: "gl",
139
+ noveltype: "nt",
140
+ end: "e",
141
+ general_all_no: "ga",
142
+ length: "l",
143
+ time: "ti",
144
+ isstop: "i",
145
+ isr15: "isr",
146
+ isbl: "ibl",
147
+ isgl: "igl",
148
+ iszankoku: "izk",
149
+ istensei: "its",
150
+ istenni: "iti",
151
+ pc_or_k: "p",
152
+ global_point: "gp",
153
+ daily_point: "dp",
154
+ weekly_point: "wp",
155
+ monthly_point: "mp",
156
+ quarter_point: "qp",
157
+ yearly_point: "yp",
158
+ fav_novel_cnt: "f",
159
+ impression_cnt: "imp",
160
+ review_cnt: "r",
161
+ all_point: "a",
162
+ all_hyoka_cnt: "ah",
163
+ sasie_cnt: "sa",
164
+ kaiwaritu: "ka",
165
+ novelupdated_at: "nu",
166
+ updated_at: "ua",
167
+ } as const;
168
+
169
+ export type Fields = typeof Fields[keyof Omit<
170
+ NarouSearchResult,
171
+ "novel_type" | "weekly_unique" | "nocgenre"
172
+ >];
173
+
174
+ export const R18Fields = {
175
+ title: "t",
176
+ ncode: "n",
177
+ userid: "u",
178
+ writer: "w",
179
+ story: "s",
180
+ nocgenre: "ng",
181
+ keyword: "k",
182
+ general_firstup: "gf",
183
+ general_lastup: "gl",
184
+ noveltype: "nt",
185
+ end: "e",
186
+ general_all_no: "ga",
187
+ length: "l",
188
+ time: "ti",
189
+ isstop: "i",
190
+ isr15: "isr",
191
+ isbl: "ibl",
192
+ isgl: "igl",
193
+ iszankoku: "izk",
194
+ istensei: "its",
195
+ istenni: "iti",
196
+ pc_or_k: "p",
197
+ global_point: "gp",
198
+ daily_point: "dp",
199
+ weekly_point: "wp",
200
+ monthly_point: "mp",
201
+ quarter_point: "qp",
202
+ yearly_point: "yp",
203
+ fav_novel_cnt: "f",
204
+ impression_cnt: "imp",
205
+ review_cnt: "r",
206
+ all_point: "a",
207
+ all_hyoka_cnt: "ah",
208
+ sasie_cnt: "sa",
209
+ kaiwaritu: "ka",
210
+ novelupdated_at: "nu",
211
+ updated_at: "ua",
212
+ } as const;
213
+
214
+ export type R18Fields = typeof R18Fields[keyof Omit<
215
+ NarouSearchResult,
216
+ "novel_type" | "weekly_unique" | "biggenre" | "genre"
217
+ >];
218
+
219
+ export const OptionalFields = {
220
+ weekly_unique: "weekly",
221
+ } as const;
222
+
223
+ export type OptionalFields = typeof OptionalFields[keyof Pick<
224
+ NarouSearchResult,
225
+ "weekly_unique"
226
+ >];
137
227
 
138
228
  /*
139
229
  * new 新着更新順
@@ -156,125 +246,137 @@ export enum Fields {
156
246
  * ncodedesc Nコードが新しい順
157
247
  * old 古い順
158
248
  */
159
- export enum Order {
160
- FavoriteNovelCount = "favnovelcnt",
161
- ReviewCount = "favnovelcnt",
162
- HyokaDesc = "hyoka",
163
- HyokaAsc = "hyokaasc",
164
- ImpressionCount = "impressioncnt",
165
- HyokaCountDesc = "hyokacnt",
166
- HyokaCountAsc = "hyokacntasc",
167
- Weekly = "weekly",
168
- LengthDesc = "lengthdesc",
169
- LengthAsc = "lengthasc",
170
- NCodeDesc = "ncodedesc",
171
- New = "new",
172
- Old = "old",
173
- DailyPoint = "dailypoint",
174
- WeeklyPoint = "weeklypoint",
175
- MonthlyPoint = "monthlypoint",
176
- QuarterPoint = "quarterpoint",
177
- YearlyPoint = "yearlypoint",
178
- }
249
+ export const Order = {
250
+ FavoriteNovelCount: "favnovelcnt",
251
+ ReviewCount: "favnovelcnt",
252
+ HyokaDesc: "hyoka",
253
+ HyokaAsc: "hyokaasc",
254
+ ImpressionCount: "impressioncnt",
255
+ HyokaCountDesc: "hyokacnt",
256
+ HyokaCountAsc: "hyokacntasc",
257
+ Weekly: "weekly",
258
+ LengthDesc: "lengthdesc",
259
+ LengthAsc: "lengthasc",
260
+ NCodeDesc: "ncodedesc",
261
+ New: "new",
262
+ Old: "old",
263
+ DailyPoint: "dailypoint",
264
+ WeeklyPoint: "weeklypoint",
265
+ MonthlyPoint: "monthlypoint",
266
+ QuarterPoint: "quarterpoint",
267
+ YearlyPoint: "yearlypoint",
268
+ };
179
269
 
180
- export enum R18Site {
181
- Nocturne = 1,
182
- MoonLight = 2,
183
- MoonLightBL = 3,
184
- Midnight = 4,
185
- }
270
+ export type Order = typeof Order[keyof typeof Order];
186
271
 
187
- export enum R18SiteNotation {
188
- "ノクターンノベルズ(男性向け)" = R18Site.Nocturne,
189
- "ムーンライトノベルズ(女性向け)" = R18Site.MoonLight,
190
- "ムーンライトノベルズ(BL)" = R18Site.MoonLightBL,
191
- "ミッドナイトノベルズ(大人向け)" = R18Site.Midnight,
192
- }
272
+ export const R18Site = {
273
+ Nocturne: 1,
274
+ MoonLight: 2,
275
+ MoonLightBL: 3,
276
+ Midnight: 4,
277
+ } as const;
193
278
 
194
- export enum BigGenre {
195
- Renai = 1,
196
- Fantasy = 2,
197
- Bungei = 3,
198
- Sf = 4,
199
- Sonota = 99,
200
- NonGenre = 98,
201
- }
279
+ export type R18Site = typeof R18Site[keyof typeof R18Site];
202
280
 
203
- export enum BigGenreNotation {
204
- "恋愛" = BigGenre.Renai,
205
- "ファンタジー" = BigGenre.Fantasy,
206
- "文芸" = BigGenre.Bungei,
207
- "SF" = BigGenre.Sf,
208
- "その他" = BigGenre.Sonota,
209
- "ノンジャンル" = BigGenre.NonGenre,
210
- }
281
+ export const R18SiteNotation: { readonly [K in R18Site]: string } = {
282
+ [R18Site.Nocturne]: "ノクターンノベルズ(男性向け)",
283
+ [R18Site.MoonLight]: "ムーンライトノベルズ(女性向け)",
284
+ [R18Site.MoonLightBL]: "ムーンライトノベルズ(BL)",
285
+ [R18Site.Midnight]: "ミッドナイトノベルズ(大人向け)",
286
+ } as const;
211
287
 
212
- export enum Genre {
213
- RenaiIsekai = 101,
214
- RenaiGenjitsusekai = 102,
215
- FantasyHigh = 201,
216
- FantasyLow = 202,
217
- BungeiJyunbungei = 301,
218
- BungeiHumanDrama = 302,
219
- BungeiHistory = 303,
220
- BungeiSuiri = 304,
221
- BungeiHorror = 305,
222
- BungeiAction = 306,
223
- BungeiComedy = 307,
224
- SfVrgame = 401,
225
- SfSpace = 402,
226
- SfKuusoukagaku = 403,
227
- SfPanic = 404,
228
- SonotaDouwa = 9901,
229
- SonotaShi = 9902,
230
- SonotaEssei = 9903,
231
- SonotaReplay = 9904,
232
- SonotaSonota = 9999,
233
- NonGenre = 9801,
234
- }
288
+ export const BigGenre = {
289
+ Renai: 1,
290
+ Fantasy: 2,
291
+ Bungei: 3,
292
+ Sf: 4,
293
+ Sonota: 99,
294
+ NonGenre: 98,
295
+ } as const;
235
296
 
236
- export enum GenreNotation {
237
- "異世界〔恋愛〕" = Genre.RenaiIsekai,
238
- "現実世界〔恋愛〕" = Genre.RenaiGenjitsusekai,
239
- "ハイファンタジー〔ファンタジー〕" = Genre.FantasyHigh,
240
- "ローファンタジー〔ファンタジー〕" = Genre.FantasyLow,
241
- "純文学〔文芸〕" = Genre.BungeiJyunbungei,
242
- "ヒューマンドラマ〔文芸〕" = Genre.BungeiHumanDrama,
243
- "歴史〔文芸〕" = Genre.BungeiHistory,
244
- "推理〔文芸〕" = Genre.BungeiSuiri,
245
- "ホラー〔文芸〕" = Genre.BungeiHorror,
246
- "アクション〔文芸〕" = Genre.BungeiAction,
247
- "コメディー〔文芸〕" = Genre.BungeiComedy,
248
- "VRゲーム〔SF〕" = Genre.SfVrgame,
249
- "宇宙〔SF〕" = Genre.SfSpace,
250
- "空想科学〔SF〕" = Genre.SfKuusoukagaku,
251
- "パニック〔SF〕" = Genre.SfPanic,
252
- "童話〔その他〕" = Genre.SonotaDouwa,
253
- "詩〔その他〕" = Genre.SonotaShi,
254
- "エッセイ〔その他〕" = Genre.SonotaEssei,
255
- "リプレイ〔その他〕" = Genre.SonotaReplay,
256
- "その他〔その他〕" = Genre.SonotaSonota,
257
- "ノンジャンル〔ノンジャンル〕" = Genre.NonGenre,
258
- }
297
+ export type BigGenre = typeof BigGenre[keyof typeof BigGenre];
259
298
 
260
- export enum Buntai {
261
- NoJisageKaigyouOoi = 1,
262
- NoJisageKaigyoHutsuu = 2,
263
- JisageKaigyoOoi = 4,
264
- JisageKaigyoHutsuu = 6,
265
- }
299
+ export const BigGenreNotation: { readonly [K in BigGenre]: string } = {
300
+ [BigGenre.Renai]: "恋愛",
301
+ [BigGenre.Fantasy]: "ファンタジー",
302
+ [BigGenre.Bungei]: "文芸",
303
+ [BigGenre.Sf]: "SF",
304
+ [BigGenre.Sonota]: "その他",
305
+ [BigGenre.NonGenre]: "ノンジャンル",
306
+ } as const;
266
307
 
267
- export enum Stop {
268
- NoStopping = 1,
269
- Stopping = 2,
270
- }
308
+ export const Genre = {
309
+ RenaiIsekai: 101,
310
+ RenaiGenjitsusekai: 102,
311
+ FantasyHigh: 201,
312
+ FantasyLow: 202,
313
+ BungeiJyunbungei: 301,
314
+ BungeiHumanDrama: 302,
315
+ BungeiHistory: 303,
316
+ BungeiSuiri: 304,
317
+ BungeiHorror: 305,
318
+ BungeiAction: 306,
319
+ BungeiComedy: 307,
320
+ SfVrgame: 401,
321
+ SfSpace: 402,
322
+ SfKuusoukagaku: 403,
323
+ SfPanic: 404,
324
+ SonotaDouwa: 9901,
325
+ SonotaShi: 9902,
326
+ SonotaEssei: 9903,
327
+ SonotaReplay: 9904,
328
+ SonotaSonota: 9999,
329
+ NonGenre: 9801,
330
+ } as const;
331
+ export type Genre = typeof Genre[keyof typeof Genre];
271
332
 
272
- export enum NovelType {
273
- Short = "t",
274
- RensaiNow = "r",
275
- RensaiEnd = "er",
276
- Rensai = "re",
277
- ShortAndRensai = "ter",
278
- }
333
+ export const GenreNotation: { readonly [K in Genre]: string } = {
334
+ [Genre.RenaiIsekai]: "異世界〔恋愛〕",
335
+ [Genre.RenaiGenjitsusekai]: "現実世界〔恋愛〕",
336
+ [Genre.FantasyHigh]: "ハイファンタジー〔ファンタジー〕",
337
+ [Genre.FantasyLow]: "ローファンタジー〔ファンタジー〕",
338
+ [Genre.BungeiJyunbungei]: "純文学〔文芸〕",
339
+ [Genre.BungeiHumanDrama]: "ヒューマンドラマ〔文芸〕",
340
+ [Genre.BungeiHistory]: "歴史〔文芸〕",
341
+ [Genre.BungeiSuiri]: "推理〔文芸〕",
342
+ [Genre.BungeiHorror]: "ホラー〔文芸〕",
343
+ [Genre.BungeiAction]: "アクション〔文芸〕",
344
+ [Genre.BungeiComedy]: "コメディー〔文芸〕",
345
+ [Genre.SfVrgame]: "VRゲーム〔SF〕",
346
+ [Genre.SfSpace]: "宇宙〔SF〕",
347
+ [Genre.SfKuusoukagaku]: "空想科学〔SF〕",
348
+ [Genre.SfPanic]: "パニック〔SF〕",
349
+ [Genre.SonotaDouwa]: "童話〔その他〕",
350
+ [Genre.SonotaShi]: "詩〔その他〕",
351
+ [Genre.SonotaEssei]: "エッセイ〔その他〕",
352
+ [Genre.SonotaReplay]: "リプレイ〔その他〕",
353
+ [Genre.SonotaSonota]: "その他〔その他〕",
354
+ [Genre.NonGenre]: "ノンジャンル〔ノンジャンル〕",
355
+ } as const;
356
+
357
+ export const Buntai = {
358
+ NoJisageKaigyouOoi: 1,
359
+ NoJisageKaigyoHutsuu: 2,
360
+ JisageKaigyoOoi: 4,
361
+ JisageKaigyoHutsuu: 6,
362
+ } as const;
363
+
364
+ export type Buntai = typeof Buntai[keyof typeof Buntai];
365
+
366
+ export const Stop = {
367
+ NoStopping: 1,
368
+ Stopping: 2,
369
+ } as const;
370
+
371
+ export type Stop = typeof Stop[keyof typeof Stop];
372
+
373
+ export const NovelType = {
374
+ Short: "t",
375
+ RensaiNow: "r",
376
+ RensaiEnd: "er",
377
+ Rensai: "re",
378
+ ShortAndRensai: "ter",
379
+ };
380
+ export type NovelType = typeof NovelType[keyof typeof NovelType];
279
381
 
280
382
  export type GzipLevel = 0 | 1 | 2 | 3 | 4 | 5;
@@ -1,10 +1,10 @@
1
1
  import { parse } from "date-fns";
2
- import { RankingType } from "./ranking";
2
+ import { RankingType } from "./params";
3
3
 
4
4
  const dateFormat = "yyyyMMdd";
5
5
 
6
6
  export interface RankingHistoryRawResult {
7
- rtype: string;
7
+ rtype: `${string}-${RankingType}`;
8
8
  pt: number;
9
9
  rank: number;
10
10
  }
package/src/ranking.ts CHANGED
@@ -1,17 +1,15 @@
1
1
  import { NarouRankingResult, RankingResult } from "./narou-ranking-results";
2
- import { Fields } from "./index";
3
- import SearchBuilder from "./search-builder";
2
+ import SearchBuilder, { DefaultSearchResultFields } from "./search-builder";
4
3
  import { addDays, format } from "date-fns";
5
- import { RankingParams } from "./params";
4
+ import {
5
+ Fields,
6
+ GzipLevel,
7
+ OptionalFields,
8
+ RankingParams,
9
+ RankingType,
10
+ } from "./params";
6
11
  import NarouNovel from "./narou";
7
- import NarouNovelFetch from "./narou-fetch";
8
-
9
- export enum RankingType {
10
- Daily = "d",
11
- Weekly = "w",
12
- Monthly = "m",
13
- Quarterly = "q",
14
- }
12
+ import { SearchResultFields } from "./narou-search-results";
15
13
 
16
14
  const dateFormat = "yyyyMMdd";
17
15
 
@@ -53,10 +51,10 @@ export default class RankingBuilder {
53
51
  * gzip圧縮する。
54
52
  *
55
53
  * 転送量上限を減らすためにも推奨
56
- * @param {number} level gzip圧縮レベル(1~5)
54
+ * @param {GzipLevel} level gzip圧縮レベル(1~5)
57
55
  * @return {RankingBuilder} this
58
56
  */
59
- gzip(level: number) {
57
+ gzip(level: GzipLevel) {
60
58
  this.set({ gzip: level });
61
59
  return this;
62
60
  }
@@ -66,7 +64,7 @@ export default class RankingBuilder {
66
64
  * @private
67
65
  * @return {RankingBuilder} this
68
66
  */
69
- protected set(obj: any) {
67
+ protected set(obj: Partial<RankingParams>) {
70
68
  Object.assign(this.params, obj);
71
69
  return this;
72
70
  }
@@ -81,16 +79,37 @@ export default class RankingBuilder {
81
79
  return this.api.executeRanking(this.params as RankingParams);
82
80
  }
83
81
 
82
+ async executeWithFields(): Promise<
83
+ RankingResult<DefaultSearchResultFields>[]
84
+ >;
85
+
86
+ async executeWithFields<TFields extends Fields>(
87
+ fields: TFields | TFields[]
88
+ ): Promise<RankingResult<SearchResultFields<TFields>>[]>;
89
+
84
90
  async executeWithFields(
85
- fields: Fields | Fields[] = [],
86
- opt?: "weekly"
87
- ): Promise<RankingResult[]> {
91
+ fields: never[],
92
+ opt: OptionalFields | OptionalFields[]
93
+ ): Promise<RankingResult<DefaultSearchResultFields | "weekly_unique">[]>;
94
+
95
+ async executeWithFields<TFields extends Fields>(
96
+ fields: TFields | TFields[],
97
+ opt: OptionalFields | OptionalFields[]
98
+ ): Promise<RankingResult<SearchResultFields<TFields> | "weekly_unique">[]>;
99
+
100
+ async executeWithFields<
101
+ TFields extends Fields,
102
+ TOpt extends OptionalFields | undefined = undefined
103
+ >(
104
+ fields: TFields | TFields[] = [],
105
+ opt?: TOpt
106
+ ): Promise<RankingResult<SearchResultFields<TFields>>[]> {
88
107
  const ranking = await this.execute();
89
- const fields$: Fields[] = Array.isArray(fields)
108
+ const fields$ = Array.isArray(fields)
90
109
  ? fields.length == 0
91
110
  ? []
92
- : [...fields, Fields.ncode]
93
- : [fields, Fields.ncode];
111
+ : ([...fields, Fields.ncode] as const)
112
+ : ([fields, Fields.ncode] as const);
94
113
 
95
114
  const rankingNcodes = ranking.map(({ ncode }) => ncode);
96
115
  const builder = new SearchBuilder({}, this.api);
@@ -102,10 +121,15 @@ export default class RankingBuilder {
102
121
  builder.limit(ranking.length);
103
122
  const result = await builder.execute();
104
123
 
105
- // TODO: 型的にはNull許容ではないが許容しているのでなんとかする(削除されている小説がある)
106
- return ranking.map<RankingResult>((r) => ({
124
+ return ranking.map<
125
+ RankingResult<
126
+ | SearchResultFields<TFields>
127
+ | (TOpt extends "weekly" ? "weekly_unique" : never)
128
+ >
129
+ >((r) => ({
107
130
  ...r,
108
- ...(result.values.find((novel) => novel.ncode == r.ncode) ?? ({} as any)),
131
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
+ ...(result.values.find((novel) => novel.ncode == r.ncode) as any),
109
133
  }));
110
134
  }
111
135
  }