narou 0.6.0 → 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 (104) hide show
  1. package/dist/index.browser.d.ts +30 -0
  2. package/dist/index.browser.d.ts.map +1 -0
  3. package/dist/index.browser.js +123 -0
  4. package/dist/index.browser.js.map +1 -0
  5. package/dist/index.common.d.ts +10 -0
  6. package/dist/index.common.d.ts.map +1 -0
  7. package/dist/index.common.js +23 -0
  8. package/dist/index.common.js.map +1 -0
  9. package/dist/index.d.ts +2 -6
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +23 -17
  12. package/dist/index.js.map +1 -1
  13. package/dist/narou-ranking-results.d.ts +4 -3
  14. package/dist/narou-ranking-results.d.ts.map +1 -1
  15. package/dist/narou-search-results.d.ts +49 -19
  16. package/dist/narou-search-results.d.ts.map +1 -1
  17. package/dist/narou-search-results.js +16 -2
  18. package/dist/narou-search-results.js.map +1 -1
  19. package/dist/narou.d.ts +4 -4
  20. package/dist/narou.d.ts.map +1 -1
  21. package/dist/narou.js.map +1 -1
  22. package/dist/params.d.ts +223 -171
  23. package/dist/params.d.ts.map +1 -1
  24. package/dist/params.js +206 -150
  25. package/dist/params.js.map +1 -1
  26. package/dist/ranking-history.d.ts +2 -2
  27. package/dist/ranking-history.d.ts.map +1 -1
  28. package/dist/ranking.d.ts +13 -15
  29. package/dist/ranking.d.ts.map +1 -1
  30. package/dist/ranking.js +9 -23
  31. package/dist/ranking.js.map +1 -1
  32. package/dist/search-builder-r18.d.ts +12 -6
  33. package/dist/search-builder-r18.d.ts.map +1 -1
  34. package/dist/search-builder-r18.js +13 -18
  35. package/dist/search-builder-r18.js.map +1 -1
  36. package/dist/search-builder.d.ts +53 -47
  37. package/dist/search-builder.d.ts.map +1 -1
  38. package/dist/search-builder.js +164 -140
  39. package/dist/search-builder.js.map +1 -1
  40. package/dist/util/jsonp.d.ts.map +1 -1
  41. package/dist/util/jsonp.js +2 -1
  42. package/dist/util/jsonp.js.map +1 -1
  43. package/dist/util/type.d.ts +4 -0
  44. package/dist/util/type.d.ts.map +1 -0
  45. package/dist/util/type.js +3 -0
  46. package/dist/util/type.js.map +1 -0
  47. package/dist/util/url.d.ts +1 -1
  48. package/dist.es2015/index.browser.js +50 -0
  49. package/dist.es2015/index.browser.js.map +1 -0
  50. package/dist.es2015/index.common.js +6 -0
  51. package/dist.es2015/index.common.js.map +1 -0
  52. package/dist.es2015/index.js +7 -9
  53. package/dist.es2015/index.js.map +1 -1
  54. package/dist.es2015/narou-search-results.js +14 -1
  55. package/dist.es2015/narou-search-results.js.map +1 -1
  56. package/dist.es2015/narou.js.map +1 -1
  57. package/dist.es2015/params.js +204 -149
  58. package/dist.es2015/params.js.map +1 -1
  59. package/dist.es2015/ranking.js +6 -18
  60. package/dist.es2015/ranking.js.map +1 -1
  61. package/dist.es2015/search-builder-r18.js +14 -19
  62. package/dist.es2015/search-builder-r18.js.map +1 -1
  63. package/dist.es2015/search-builder.js +104 -101
  64. package/dist.es2015/search-builder.js.map +1 -1
  65. package/dist.es2015/util/jsonp.js +1 -0
  66. package/dist.es2015/util/jsonp.js.map +1 -1
  67. package/dist.es2015/util/type.js +2 -0
  68. package/dist.es2015/util/type.js.map +1 -0
  69. package/dist.esm/index.browser.js +102 -0
  70. package/dist.esm/index.browser.js.map +1 -0
  71. package/dist.esm/index.common.js +6 -0
  72. package/dist.esm/index.common.js.map +1 -0
  73. package/dist.esm/index.js +7 -6
  74. package/dist.esm/index.js.map +1 -1
  75. package/dist.esm/narou-search-results.js +14 -1
  76. package/dist.esm/narou-search-results.js.map +1 -1
  77. package/dist.esm/narou.js.map +1 -1
  78. package/dist.esm/params.js +205 -149
  79. package/dist.esm/params.js.map +1 -1
  80. package/dist.esm/ranking.js +6 -19
  81. package/dist.esm/ranking.js.map +1 -1
  82. package/dist.esm/search-builder-r18.js +14 -19
  83. package/dist.esm/search-builder-r18.js.map +1 -1
  84. package/dist.esm/search-builder.js +163 -140
  85. package/dist.esm/search-builder.js.map +1 -1
  86. package/dist.esm/util/jsonp.js +2 -1
  87. package/dist.esm/util/jsonp.js.map +1 -1
  88. package/dist.esm/util/type.js +2 -0
  89. package/dist.esm/util/type.js.map +1 -0
  90. package/package.json +22 -46
  91. package/src/index.browser.ts +63 -0
  92. package/src/index.common.ts +31 -0
  93. package/src/index.ts +12 -20
  94. package/src/narou-ranking-results.ts +6 -2
  95. package/src/narou-search-results.ts +70 -20
  96. package/src/narou.ts +13 -6
  97. package/src/params.ts +277 -175
  98. package/src/ranking-history.ts +2 -2
  99. package/src/ranking.ts +50 -26
  100. package/src/search-builder-r18.ts +30 -20
  101. package/src/search-builder.ts +149 -128
  102. package/src/util/jsonp.ts +3 -0
  103. package/src/util/type.ts +3 -0
  104. package/package-lock.json +0 -3328
@@ -1 +1 @@
1
- {"version":3,"file":"jsonp.js","sourceRoot":"","sources":["../../src/util/jsonp.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,OAAO,MAAM,OAAO,CAAC;AAE5B,kBAAkB;AAClB,IAAI,KAAK,GAAG,CAAC,CAAC;AAcd,IAAM,IAAI,GAAG,cAAa,CAAC,CAAC;AAE5B,MAAM,UAAU,KAAK,CACnB,GAAW,EACX,EAA0E;QAA1E,qBAAwE,EAAE,KAAA,EAAxE,cAAe,EAAf,MAAM,mBAAG,MAAM,KAAA,EAAE,aAAkB,EAAlB,KAAK,mBAAG,UAAU,KAAA,EAAE,eAAe,EAAf,OAAO,mBAAG,KAAK,KAAA;IAEtD,OAAO,IAAI,OAAO,CAAC,UAAU,OAAO,EAAE,MAAM;;QAC1C,IAAM,WAAW,GAAG,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpE,IAAM,MAAM,GAAG,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,mCAAI,QAAQ,CAAC,IAAI,CAAC;QAExD,IAAM,EAAE,GAAe,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AChB,CAAC,CAAC;QACF,MAAM,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;QAEtB,iBAAiB;QACjB,IAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAM,MAAM,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9C,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/util/type.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "narou",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Narou API Wrapper",
5
5
  "main": "dist/index.js",
6
+ "browser": "dist/index.browser.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "typings": "dist/index.d.ts",
8
9
  "module": "dist.esm/index.js",
@@ -23,28 +24,23 @@
23
24
  "date-fns": "^2.16.1"
24
25
  },
25
26
  "devDependencies": {
26
- "@types/chai": "^4.1.2",
27
- "@types/mocha": "^5.2.7",
27
+ "@types/jest": "^28.1.5",
28
28
  "@types/node": "^13.5.0",
29
29
  "@types/node-fetch": "^2.5.7",
30
- "chai": "^4.1.2",
31
- "mocha": "^9.1.3",
32
- "mocha-typescript": "^1.1.12",
30
+ "@typescript-eslint/eslint-plugin": "^5.30.6",
31
+ "@typescript-eslint/parser": "^5.30.6",
32
+ "eslint": "^8.19.0",
33
+ "eslint-config-prettier": "^8.5.0",
34
+ "eslint-plugin-prettier": "^4.2.1",
35
+ "jest": "^28.1.3",
36
+ "node-fetch": "^2.6.1",
33
37
  "npm-run-all": "^4.1.4",
34
- "nyc": "^15.0.0",
35
- "prettier": "^2.4.1",
36
- "rimraf": "^3.0.0",
37
- "touch": "^3.1.0",
38
- "ts-node": "^10.3.0",
39
- "tslint": "^6.0.0",
40
- "tslint-config-prettier": "^1.16.0",
41
- "tslint-plugin-prettier": "^2.0.1",
42
- "typedoc": "^0.22.5",
43
- "typescript": "^4.4.4",
44
- "node-fetch": "^2.6.1"
38
+ "prettier": "^2.7.1",
39
+ "ts-jest": "^28.0.6",
40
+ "typescript": "^4.7.4"
45
41
  },
46
- "peerDependencies": {
47
- "node-fetch": "^2.6.1"
42
+ "optionalDependencies": {
43
+ "node-fetch": "^2.6.7"
48
44
  },
49
45
  "scripts": {
50
46
  "build": "npm-run-all check clean build:tsc",
@@ -53,35 +49,15 @@
53
49
  "build:tsc:esm": "tsc -p ./tsconfig.esm.json",
54
50
  "build:tsc:es2017": "tsc -p ./tsconfig.es2017.json",
55
51
  "check": "npm-run-all --parallel check:lint check:build test",
56
- "check:lint": "tslint --project .",
52
+ "check:lint": "eslint src/** test/**",
57
53
  "check:build": "tsc --noEmit",
58
54
  "prepare": "npm-run-all format build",
59
- "format": "npm-run-all format:prettier format:tslint",
60
- "format:prettier": "prettier --write src/**/*.ts",
61
- "format:tslint": "tslint --project . --fix",
62
- "test": "mocha --recursive --require ts-node/register \"test/**/*.ts\"",
63
- "cover": "nyc mocha --recursive --require ts-node/register \"test/**/*.ts\"",
64
- "clean": "rimraf dist dist.*",
55
+ "format": "eslint --fix src/** test/**",
56
+ "test": "jest",
57
+ "clean": "npx rimraf dist dist.*",
65
58
  "docs": "npm-run-all docs:clean docs:typedoc docs:nojekyll",
66
- "docs:clean": "rimraf docs",
67
- "docs:typedoc": "typedoc --out ./docs src/index.ts",
68
- "docs:nojekyll": "nodetouch ./docs/.nojekyll"
69
- },
70
- "nyc": {
71
- "include": [
72
- "src/**/*.js"
73
- ],
74
- "extension": [
75
- ".ts"
76
- ],
77
- "require": [
78
- "ts-node/register"
79
- ],
80
- "reporter": [
81
- "json",
82
- "html",
83
- "text"
84
- ],
85
- "sourceMap": true
59
+ "docs:clean": "npx rimraf docs",
60
+ "docs:typedoc": "npx typedoc --out ./docs src/index.ts",
61
+ "docs:nojekyll": "npx touch ./docs/.nojekyll"
86
62
  }
87
63
  }
@@ -0,0 +1,63 @@
1
+ import NarouNovelJsonp from "./narou-jsonp";
2
+ import NarouNovel from "./narou";
3
+ import SearchBuilder from "./search-builder";
4
+ import SearchBuilderR18 from "./search-builder-r18";
5
+ import RankingBuilder from "./ranking";
6
+ import { formatRankingHistory, RankingHistoryResult } from "./ranking-history";
7
+
8
+ export * from "./index.common";
9
+ export { NarouNovelJsonp };
10
+
11
+ const narouNovelJsonp = new NarouNovelJsonp();
12
+
13
+ /**
14
+ * 検索
15
+ * @param {string} [word] - 検索ワード
16
+ * @returns {SearchBuilder}
17
+ */
18
+ export function search(
19
+ word = "",
20
+ api: NarouNovel = narouNovelJsonp
21
+ ): SearchBuilder {
22
+ const builder = new SearchBuilder({}, api);
23
+ if (word != "") builder.word(word);
24
+ return builder;
25
+ }
26
+
27
+ /**
28
+ * 検索
29
+ * @param {string} [word] - 検索ワード
30
+ * @returns {SearchBuilder}
31
+ */
32
+ export function searchR18(
33
+ word = "",
34
+ api: NarouNovel = narouNovelJsonp
35
+ ): SearchBuilderR18 {
36
+ const builder = new SearchBuilderR18({}, api);
37
+ if (word != "") builder.word(word);
38
+ return builder;
39
+ }
40
+
41
+ export function ranking(api: NarouNovel = narouNovelJsonp): RankingBuilder {
42
+ const builder = new RankingBuilder({}, api);
43
+ return builder;
44
+ }
45
+
46
+ export async function rankingHistory(
47
+ ncode: string,
48
+ api: NarouNovel = narouNovelJsonp
49
+ ): Promise<RankingHistoryResult[]> {
50
+ const result = await api.executeRankingHistory({ ncode });
51
+ if (Array.isArray(result)) {
52
+ return result.map(formatRankingHistory);
53
+ } else {
54
+ throw new Error(result);
55
+ }
56
+ }
57
+
58
+ export default {
59
+ search,
60
+ ranking,
61
+ searchR18,
62
+ rankingHistory,
63
+ };
@@ -0,0 +1,31 @@
1
+ import NarouNovel from "./narou";
2
+ import NarouSearchResults from "./narou-search-results";
3
+
4
+ export { NarouNovel, NarouSearchResults };
5
+
6
+ export { RankingHistoryResult } from "./ranking-history";
7
+ export {
8
+ RankingType,
9
+ Fields,
10
+ SearchResultFieldNames,
11
+ Order,
12
+ BigGenre,
13
+ BigGenreNotation,
14
+ Genre,
15
+ GenreNotation,
16
+ R18Site,
17
+ R18SiteNotation,
18
+ BooleanNumber,
19
+ } from "./params";
20
+ export {
21
+ NarouSearchResult,
22
+ PickedNarouSearchResult,
23
+ SearchResultFields,
24
+ SearchResultR18Fields,
25
+ PcOrK,
26
+ NovelType,
27
+ End,
28
+ } from "./narou-search-results";
29
+ export { NarouRankingResult, RankingResult } from "./narou-ranking-results";
30
+ export { DefaultSearchResultFields } from "./search-builder";
31
+ export { DefaultR18SearchResultFields } from "./search-builder-r18";
package/src/index.ts CHANGED
@@ -1,33 +1,25 @@
1
1
  import NarouNovel from "./narou";
2
2
  import NarouNovelFetch from "./narou-fetch";
3
+ import NarouNovelJsonp from "./narou-jsonp";
3
4
  import RankingBuilder from "./ranking";
4
5
  import { formatRankingHistory, RankingHistoryResult } from "./ranking-history";
5
6
  import SearchBuilder from "./search-builder";
6
7
  import SearchBuilderR18 from "./search-builder-r18";
7
- import NarouNovelJsonp from "./narou-jsonp";
8
8
 
9
- export { NarouNovel, RankingHistoryResult };
9
+ export * from "./index.common";
10
10
  export { NarouNovelFetch, NarouNovelJsonp };
11
- export { RankingType } from "./ranking";
12
- export {
13
- Fields,
14
- Order,
15
- BigGenre,
16
- BigGenreNotation,
17
- Genre,
18
- GenreNotation,
19
- R18Site,
20
- R18SiteNotation,
21
- } from "./params";
22
- export { NarouSearchResult } from "./narou-search-results";
23
- export { NarouRankingResult, RankingResult } from "./narou-ranking-results";
11
+
12
+ const narouNovelFetch = new NarouNovelFetch();
24
13
 
25
14
  /**
26
15
  * 検索
27
16
  * @param {string} [word] - 検索ワード
28
17
  * @returns {SearchBuilder}
29
18
  */
30
- export function search(word: string = "", api?: NarouNovel): SearchBuilder {
19
+ export function search(
20
+ word = "",
21
+ api: NarouNovel = narouNovelFetch
22
+ ): SearchBuilder {
31
23
  const builder = new SearchBuilder({}, api);
32
24
  if (word != "") builder.word(word);
33
25
  return builder;
@@ -39,22 +31,22 @@ export function search(word: string = "", api?: NarouNovel): SearchBuilder {
39
31
  * @returns {SearchBuilder}
40
32
  */
41
33
  export function searchR18(
42
- word: string = "",
43
- api?: NarouNovel
34
+ word = "",
35
+ api: NarouNovel = narouNovelFetch
44
36
  ): SearchBuilderR18 {
45
37
  const builder = new SearchBuilderR18({}, api);
46
38
  if (word != "") builder.word(word);
47
39
  return builder;
48
40
  }
49
41
 
50
- export function ranking(api?: NarouNovel): RankingBuilder {
42
+ export function ranking(api: NarouNovel = narouNovelFetch): RankingBuilder {
51
43
  const builder = new RankingBuilder({}, api);
52
44
  return builder;
53
45
  }
54
46
 
55
47
  export async function rankingHistory(
56
48
  ncode: string,
57
- api: NarouNovel = new NarouNovelFetch()
49
+ api: NarouNovel = narouNovelFetch
58
50
  ): Promise<RankingHistoryResult[]> {
59
51
  const result = await api.executeRankingHistory({ ncode });
60
52
  if (Array.isArray(result)) {
@@ -1,4 +1,6 @@
1
- import { NarouSearchResult } from "./narou-search-results";
1
+ import { PickedNarouSearchResult } from "./narou-search-results";
2
+ import { SearchResultFieldNames } from "./params";
3
+ import { DefaultSearchResultFields } from "./search-builder";
2
4
 
3
5
  export interface NarouRankingResult {
4
6
  ncode: string;
@@ -6,4 +8,6 @@ export interface NarouRankingResult {
6
8
  pt: number;
7
9
  }
8
10
 
9
- export interface RankingResult extends NarouSearchResult, NarouRankingResult {}
11
+ export type RankingResult<
12
+ T extends SearchResultFieldNames = DefaultSearchResultFields
13
+ > = Partial<PickedNarouSearchResult<T>> & NarouRankingResult;
@@ -1,24 +1,35 @@
1
+ import {
2
+ BooleanNumber as BooleanNumber,
3
+ Genre,
4
+ R18Site,
5
+ SearchParams,
6
+ Fields,
7
+ BigGenre,
8
+ R18Fields,
9
+ OptionalFields,
10
+ } from "./params";
11
+
1
12
  /**
2
13
  * なろう小説API検索結果
3
14
  * @class NarouSearchResults
4
15
  */
5
-
6
- import { booleanNumber, Genre, R18Site, SearchParams } from "./params";
7
-
8
- export default class NarouSearchResults {
16
+ export default class NarouSearchResults<T extends keyof NarouSearchResult> {
9
17
  allcount: number;
10
18
  limit: number;
11
19
  start: number;
12
20
  page: number;
13
21
  length: number;
14
- values: NarouSearchResult[];
22
+ values: PickedNarouSearchResult<T>[];
15
23
 
16
24
  /**
17
25
  * @constractor
18
26
  * @private
19
27
  */
20
28
  constructor(
21
- [header, ...result]: [{ allcount: number }, ...NarouSearchResult[]],
29
+ [header, ...result]: [
30
+ { allcount: number },
31
+ ...PickedNarouSearchResult<T>[]
32
+ ],
22
33
  params: SearchParams
23
34
  ) {
24
35
  const count = header.allcount;
@@ -52,7 +63,7 @@ export default class NarouSearchResults {
52
63
  this.length = result.length;
53
64
  /**
54
65
  * 検索結果
55
- * @type {NarouSearchResult[]}
66
+ * @type {PickedNarouSearchResult<T>[]}
56
67
  */
57
68
  this.values = result;
58
69
  }
@@ -70,7 +81,7 @@ export default class NarouSearchResults {
70
81
  * @property {string} general_firstup 初回掲載日 YYYY-MM-DD HH:MM:SSの形式
71
82
  * @property {string} general_lastup 最終掲載日 YYYY-MM-DD HH:MM:SSの形式
72
83
  * @property {number} noveltype 連載の場合は1、短編の場合は2
73
- * @property {number} end 連載の場合は1、短編の場合は2
84
+ * @property {number} end 短編小説と完結済小説は0となっています。連載中は1です。
74
85
  * @property {number} general_all_no 全掲載話数です。短編の場合は1です。
75
86
  * @property {number} length 全掲載話数です。短編の場合は1です。
76
87
  * @property {number} time 読了時間(分単位)です。読了時間は小説文字数÷500を切り上げした数値です。
@@ -94,24 +105,25 @@ export interface NarouSearchResult {
94
105
  writer: string;
95
106
  story: string;
96
107
  nocgenre: R18Site;
108
+ biggenre: BigGenre;
97
109
  genre: Genre;
98
110
  keyword: string;
99
111
  general_firstup: string;
100
112
  general_lastup: string;
101
113
  novel_type: number;
102
- noveltype: number;
103
- end: booleanNumber;
114
+ noveltype: NovelType;
115
+ end: End;
104
116
  general_all_no: number;
105
117
  length: number;
106
118
  time: number;
107
- isstop: booleanNumber;
108
- isr15: booleanNumber;
109
- isbl: booleanNumber;
110
- isgl: booleanNumber;
111
- iszankoku: booleanNumber;
112
- istensei: booleanNumber;
113
- istenni: booleanNumber;
114
- pc_or_k: number;
119
+ isstop: BooleanNumber;
120
+ isr15: BooleanNumber;
121
+ isbl: BooleanNumber;
122
+ isgl: BooleanNumber;
123
+ iszankoku: BooleanNumber;
124
+ istensei: BooleanNumber;
125
+ istenni: BooleanNumber;
126
+ pc_or_k: PcOrK;
115
127
  global_point: number;
116
128
  daily_point: number;
117
129
  weekly_point: number;
@@ -125,7 +137,45 @@ export interface NarouSearchResult {
125
137
  all_hyoka_cnt: number;
126
138
  sasie_cnt: number;
127
139
  kaiwaritu: number;
128
- novelupdated_at: number;
129
- update_at: number;
140
+ novelupdated_at: string;
141
+ updated_at: string;
130
142
  weekly_unique: number;
131
143
  }
144
+
145
+ export const PcOrK = {
146
+ Ketai: 1,
147
+ Pc: 2,
148
+ PcAndKetai: 3,
149
+ } as const;
150
+ export type PcOrK = typeof PcOrK[keyof typeof PcOrK];
151
+
152
+ export const NovelType = {
153
+ Rensai: 1,
154
+ Tanpen: 2,
155
+ } as const;
156
+ export type NovelType = typeof NovelType[keyof typeof NovelType];
157
+
158
+ export const End = {
159
+ KanketsuOrTanpen: 0,
160
+ Rensai: 1,
161
+ } as const;
162
+ export type End = typeof End[keyof typeof End];
163
+
164
+ export type SearchResultFields<T extends Fields> = {
165
+ [K in keyof typeof Fields]: typeof Fields[K] extends T ? K : never;
166
+ }[keyof typeof Fields];
167
+
168
+ export type SerachResultOptionalFields<T extends OptionalFields> = {
169
+ [K in keyof typeof OptionalFields]: typeof OptionalFields[K] extends T
170
+ ? K
171
+ : never;
172
+ }[keyof typeof OptionalFields];
173
+
174
+ export type SearchResultR18Fields<T extends R18Fields> = {
175
+ [K in keyof typeof R18Fields]: typeof R18Fields[K] extends T ? K : never;
176
+ }[keyof typeof R18Fields];
177
+
178
+ export type PickedNarouSearchResult<T extends keyof NarouSearchResult> = Pick<
179
+ NarouSearchResult,
180
+ T
181
+ >;
package/src/narou.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NarouRankingResult } from "./narou-ranking-results";
2
- import NarouSearchResults from "./narou-search-results";
2
+ import NarouSearchResults, { NarouSearchResult } from "./narou-search-results";
3
3
  import { RankingHistoryParams, RankingParams, SearchParams } from "./params";
4
4
  import { RankingHistoryRawResult } from "./ranking-history";
5
5
 
@@ -22,21 +22,28 @@ export default abstract class NarouNovel {
22
22
  endpoint: string
23
23
  ): Promise<T>;
24
24
 
25
- async executeSearch(
25
+ async executeSearch<T extends keyof NarouSearchResult>(
26
26
  params: NarouParams,
27
27
  endpoint = "http://api.syosetu.com/novelapi/api/"
28
- ): Promise<NarouSearchResults> {
29
- return new NarouSearchResults(await this.execute(params, endpoint), params);
28
+ ): Promise<NarouSearchResults<T>> {
29
+ return new NarouSearchResults<T>(
30
+ await this.execute(params, endpoint),
31
+ params
32
+ );
30
33
  }
31
34
 
32
- async executeNovel(params: SearchParams): Promise<NarouSearchResults> {
35
+ async executeNovel<T extends keyof NarouSearchResult>(
36
+ params: SearchParams
37
+ ): Promise<NarouSearchResults<T>> {
33
38
  return await this.executeSearch(
34
39
  params,
35
40
  "http://api.syosetu.com/novelapi/api/"
36
41
  );
37
42
  }
38
43
 
39
- async executeNovel18(params: SearchParams): Promise<NarouSearchResults> {
44
+ async executeNovel18<T extends keyof NarouSearchResult>(
45
+ params: SearchParams
46
+ ): Promise<NarouSearchResults<T>> {
40
47
  return await this.executeSearch(
41
48
  params,
42
49
  "http://api.syosetu.com/novel18api/api/"