@stats-forge/github-stats-forge-core 0.0.2 → 0.2.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 (249) hide show
  1. package/README.md +0 -10
  2. package/build/api/api-result.d.ts +6 -7
  3. package/build/api/api-result.d.ts.map +1 -1
  4. package/build/api/api-result.js +4 -5
  5. package/build/api/contributed-to.d.ts +23 -0
  6. package/build/api/contributed-to.d.ts.map +1 -0
  7. package/build/api/contributed-to.js +43 -0
  8. package/build/api/gist.d.ts +8 -22
  9. package/build/api/gist.d.ts.map +1 -1
  10. package/build/api/gist.js +14 -36
  11. package/build/api/handler.d.ts +16 -0
  12. package/build/api/handler.d.ts.map +1 -0
  13. package/build/api/handler.js +29 -0
  14. package/build/api/index.d.ts +13 -12
  15. package/build/api/index.d.ts.map +1 -1
  16. package/build/api/index.js +1 -0
  17. package/build/api/params.d.ts +21 -12
  18. package/build/api/params.d.ts.map +1 -1
  19. package/build/api/params.js +41 -19
  20. package/build/api/pin.d.ts +11 -31
  21. package/build/api/pin.d.ts.map +1 -1
  22. package/build/api/pin.js +35 -63
  23. package/build/api/stats.d.ts +15 -16
  24. package/build/api/stats.d.ts.map +1 -1
  25. package/build/api/stats.js +60 -99
  26. package/build/api/top-langs.d.ts +13 -18
  27. package/build/api/top-langs.d.ts.map +1 -1
  28. package/build/api/top-langs.js +35 -72
  29. package/build/api/wakatime.d.ts +11 -17
  30. package/build/api/wakatime.d.ts.map +1 -1
  31. package/build/api/wakatime.js +27 -64
  32. package/build/calculateRank.d.ts +0 -9
  33. package/build/calculateRank.d.ts.map +1 -1
  34. package/build/calculateRank.js +12 -17
  35. package/build/cards/contributed-to.d.ts +19 -0
  36. package/build/cards/contributed-to.d.ts.map +1 -0
  37. package/build/cards/contributed-to.js +242 -0
  38. package/build/cards/gist.d.ts +3 -4
  39. package/build/cards/gist.d.ts.map +1 -1
  40. package/build/cards/gist.js +38 -43
  41. package/build/cards/options.d.ts +1 -1
  42. package/build/cards/repo.d.ts +14 -5
  43. package/build/cards/repo.d.ts.map +1 -1
  44. package/build/cards/repo.js +93 -103
  45. package/build/cards/stats.d.ts +18 -11
  46. package/build/cards/stats.d.ts.map +1 -1
  47. package/build/cards/stats.js +191 -222
  48. package/build/cards/top-languages.d.ts +18 -33
  49. package/build/cards/top-languages.d.ts.map +1 -1
  50. package/build/cards/top-languages.js +196 -387
  51. package/build/cards/wakatime.d.ts +17 -8
  52. package/build/cards/wakatime.d.ts.map +1 -1
  53. package/build/cards/wakatime.js +133 -187
  54. package/build/common/Card.d.ts +20 -59
  55. package/build/common/Card.d.ts.map +1 -1
  56. package/build/common/Card.js +131 -198
  57. package/build/common/I18n.d.ts +1 -7
  58. package/build/common/I18n.d.ts.map +1 -1
  59. package/build/common/I18n.js +7 -8
  60. package/build/common/brand.d.ts +76 -0
  61. package/build/common/brand.d.ts.map +1 -0
  62. package/build/common/brand.js +73 -0
  63. package/build/common/color.d.ts +4 -17
  64. package/build/common/color.d.ts.map +1 -1
  65. package/build/common/color.js +67 -49
  66. package/build/common/config.d.ts +4 -14
  67. package/build/common/config.d.ts.map +1 -1
  68. package/build/common/config.js +3 -16
  69. package/build/common/constants.d.ts +6 -2
  70. package/build/common/constants.d.ts.map +1 -1
  71. package/build/common/constants.js +5 -1
  72. package/build/common/date.d.ts +50 -5
  73. package/build/common/date.d.ts.map +1 -1
  74. package/build/common/date.js +104 -4
  75. package/build/common/emojiMap.d.ts +8 -0
  76. package/build/common/emojiMap.d.ts.map +1 -0
  77. package/build/common/emojiMap.js +10 -0
  78. package/build/common/emojiMap.json +1915 -0
  79. package/build/common/error.d.ts +1 -10
  80. package/build/common/error.d.ts.map +1 -1
  81. package/build/common/error.js +1 -10
  82. package/build/common/fmt.d.ts +3 -15
  83. package/build/common/fmt.d.ts.map +1 -1
  84. package/build/common/fmt.js +7 -35
  85. package/build/common/http.d.ts +2 -7
  86. package/build/common/http.d.ts.map +1 -1
  87. package/build/common/http.js +8 -17
  88. package/build/common/icons.d.ts +20 -20
  89. package/build/common/icons.d.ts.map +1 -1
  90. package/build/common/icons.js +108 -67
  91. package/build/common/languageColors.d.ts +0 -1
  92. package/build/common/languageColors.d.ts.map +1 -1
  93. package/build/common/languageColors.js +1 -4
  94. package/build/common/languageColors.json +18 -2
  95. package/build/common/ops.d.ts +11 -17
  96. package/build/common/ops.d.ts.map +1 -1
  97. package/build/common/ops.js +22 -39
  98. package/build/common/render.d.ts +34 -82
  99. package/build/common/render.d.ts.map +1 -1
  100. package/build/common/render.js +225 -259
  101. package/build/common/retryer.d.ts +2 -7
  102. package/build/common/retryer.d.ts.map +1 -1
  103. package/build/common/retryer.js +4 -11
  104. package/build/fetchers/contributed-to.d.ts +62 -0
  105. package/build/fetchers/contributed-to.d.ts.map +1 -0
  106. package/build/fetchers/contributed-to.js +184 -0
  107. package/build/fetchers/gist.d.ts +2 -5
  108. package/build/fetchers/gist.d.ts.map +1 -1
  109. package/build/fetchers/gist.js +1 -5
  110. package/build/fetchers/graphql-error.d.ts +13 -0
  111. package/build/fetchers/graphql-error.d.ts.map +1 -0
  112. package/build/fetchers/graphql-error.js +29 -0
  113. package/build/fetchers/index.d.ts +13 -12
  114. package/build/fetchers/index.d.ts.map +1 -1
  115. package/build/fetchers/index.js +1 -0
  116. package/build/fetchers/repo.d.ts +2 -11
  117. package/build/fetchers/repo.d.ts.map +1 -1
  118. package/build/fetchers/repo.js +20 -33
  119. package/build/fetchers/stats.d.ts +16 -40
  120. package/build/fetchers/stats.d.ts.map +1 -1
  121. package/build/fetchers/stats.js +89 -271
  122. package/build/fetchers/top-languages.d.ts +2 -9
  123. package/build/fetchers/top-languages.d.ts.map +1 -1
  124. package/build/fetchers/top-languages.js +16 -47
  125. package/build/fetchers/types.d.ts +25 -1
  126. package/build/fetchers/types.d.ts.map +1 -1
  127. package/build/fetchers/wakatime.d.ts +2 -6
  128. package/build/fetchers/wakatime.d.ts.map +1 -1
  129. package/build/fetchers/wakatime.js +1 -5
  130. package/build/graphql/contributionsCollection.d.ts +9 -0
  131. package/build/graphql/contributionsCollection.d.ts.map +1 -0
  132. package/build/graphql/contributionsCollection.js +12 -0
  133. package/build/graphql/contributionsDocument.d.ts +6 -6
  134. package/build/graphql/contributionsDocument.d.ts.map +1 -1
  135. package/build/graphql/contributionsDocument.js +8 -16
  136. package/build/graphql/generated/contributed-to.d.ts +22 -0
  137. package/build/graphql/generated/contributed-to.d.ts.map +1 -0
  138. package/build/graphql/generated/contributed-to.js +11 -0
  139. package/build/graphql/generated/gist.d.ts +1 -1
  140. package/build/graphql/generated/repo.d.ts +1 -1
  141. package/build/graphql/generated/stats.d.ts +16 -4
  142. package/build/graphql/generated/stats.d.ts.map +1 -1
  143. package/build/graphql/generated/stats.js +2 -2
  144. package/build/graphql/generated/top-languages.d.ts +2 -2
  145. package/build/graphql/graphqlDocument.d.ts +1 -2
  146. package/build/graphql/graphqlDocument.d.ts.map +1 -1
  147. package/build/graphql/graphqlDocument.js +0 -1
  148. package/build/graphql/reposContributedToDocument.d.ts +4 -5
  149. package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
  150. package/build/graphql/reposContributedToDocument.js +11 -7
  151. package/build/markup/css.d.ts +35 -0
  152. package/build/markup/css.d.ts.map +1 -0
  153. package/build/markup/css.js +64 -0
  154. package/build/markup/element.d.ts +41 -0
  155. package/build/markup/element.d.ts.map +1 -0
  156. package/build/markup/element.js +127 -0
  157. package/build/markup/html.d.ts +13 -0
  158. package/build/markup/html.d.ts.map +1 -0
  159. package/build/markup/html.js +27 -0
  160. package/build/markup/index.d.ts +9 -0
  161. package/build/markup/index.d.ts.map +1 -0
  162. package/build/markup/index.js +6 -0
  163. package/build/markup/serialize.d.ts +16 -0
  164. package/build/markup/serialize.d.ts.map +1 -0
  165. package/build/markup/serialize.js +17 -0
  166. package/build/themes/index.d.ts +332 -333
  167. package/build/themes/index.d.ts.map +1 -1
  168. package/build/themes/index.js +1 -1
  169. package/build/translations.d.ts +66 -7
  170. package/build/translations.d.ts.map +1 -1
  171. package/build/translations.js +686 -629
  172. package/package.json +17 -26
  173. package/src/api/api-result.ts +10 -9
  174. package/src/api/contributed-to.ts +84 -0
  175. package/src/api/gist.ts +22 -46
  176. package/src/api/handler.ts +42 -0
  177. package/src/api/index.ts +13 -12
  178. package/src/api/params.ts +74 -29
  179. package/src/api/pin.ts +38 -65
  180. package/src/api/stats.ts +81 -118
  181. package/src/api/top-langs.ts +38 -80
  182. package/src/api/wakatime.ts +35 -73
  183. package/src/calculateRank.ts +12 -23
  184. package/src/cards/contributed-to.ts +373 -0
  185. package/src/cards/gist.ts +55 -49
  186. package/src/cards/options.ts +1 -1
  187. package/src/cards/repo.ts +134 -120
  188. package/src/cards/stats.ts +262 -252
  189. package/src/cards/top-languages.ts +315 -422
  190. package/src/cards/wakatime.ts +207 -225
  191. package/src/common/Card.ts +207 -214
  192. package/src/common/I18n.ts +7 -8
  193. package/src/common/brand.ts +109 -0
  194. package/src/common/color.ts +80 -57
  195. package/src/common/config.ts +5 -18
  196. package/src/common/constants.ts +8 -2
  197. package/src/common/date.ts +135 -5
  198. package/src/common/emojiMap.json +1915 -0
  199. package/src/common/emojiMap.ts +13 -0
  200. package/src/common/error.ts +2 -11
  201. package/src/common/fmt.ts +7 -44
  202. package/src/common/http.ts +9 -15
  203. package/src/common/icons.ts +122 -42
  204. package/src/common/languageColors.json +18 -2
  205. package/src/common/languageColors.ts +1 -4
  206. package/src/common/ops.ts +31 -48
  207. package/src/common/render.ts +334 -284
  208. package/src/common/retryer.ts +8 -15
  209. package/src/fetchers/contributed-to.ts +271 -0
  210. package/src/fetchers/gist.ts +8 -12
  211. package/src/fetchers/graphql-error.ts +36 -0
  212. package/src/fetchers/index.ts +15 -12
  213. package/src/fetchers/repo.ts +27 -40
  214. package/src/fetchers/stats.ts +157 -366
  215. package/src/fetchers/top-languages.ts +27 -55
  216. package/src/fetchers/types.ts +27 -1
  217. package/src/fetchers/wakatime.ts +5 -9
  218. package/src/graphql/contributionsCollection.ts +18 -0
  219. package/src/graphql/contributionsDocument.ts +14 -19
  220. package/src/graphql/generated/contributed-to.ts +25 -0
  221. package/src/graphql/generated/gist.ts +1 -1
  222. package/src/graphql/generated/repo.ts +1 -1
  223. package/src/graphql/generated/stats.ts +21 -8
  224. package/src/graphql/generated/top-languages.ts +2 -2
  225. package/src/graphql/graphqlDocument.ts +1 -2
  226. package/src/graphql/queries/contributed-to.graphql +8 -0
  227. package/src/graphql/queries/stats.graphql +14 -2
  228. package/src/graphql/reposContributedToDocument.ts +16 -15
  229. package/src/markup/css.ts +118 -0
  230. package/src/markup/element.ts +246 -0
  231. package/src/markup/html.ts +34 -0
  232. package/src/markup/index.ts +9 -0
  233. package/src/markup/serialize.ts +27 -0
  234. package/src/themes/index.ts +1 -1
  235. package/src/translations.ts +699 -629
  236. package/build/cards/index.d.ts +0 -11
  237. package/build/cards/index.d.ts.map +0 -1
  238. package/build/cards/index.js +0 -7
  239. package/build/common/html.d.ts +0 -8
  240. package/build/common/html.d.ts.map +0 -1
  241. package/build/common/html.js +0 -14
  242. package/build/index.d.ts +0 -15
  243. package/build/index.d.ts.map +0 -1
  244. package/build/index.js +0 -10
  245. package/src/_emoji-name-map.d.ts +0 -10
  246. package/src/_github-username-regex.d.ts +0 -4
  247. package/src/cards/index.ts +0 -21
  248. package/src/common/html.ts +0 -17
  249. package/src/index.ts +0 -18
package/src/api/pin.ts CHANGED
@@ -1,27 +1,23 @@
1
1
  import * as z from 'zod/mini';
2
2
 
3
- import { renderRepoCard } from '../cards/repo.js';
4
- import type { CardConfig } from '../common/config.js';
5
- import { fetchRepo } from '../fetchers/repo.js';
3
+ import { renderRepoCard } from '../cards/repo.ts';
4
+ import { fetchRepo } from '../fetchers/repo.ts';
6
5
 
7
- import type { ApiResult } from './api-result.js';
8
- import { errorResult } from './api-result.js';
9
- import type { ApiQuery } from './params.js';
6
+ import { cardHandler } from './handler.ts';
10
7
  import {
11
8
  booleanParam,
12
9
  listParam,
13
10
  localeParam,
14
11
  looseIntParam,
15
12
  numberParam,
16
- parseColorParams,
17
- parseParams,
18
13
  rawParam,
19
14
  safeParam,
20
- } from './params.js';
15
+ usernameParam,
16
+ } from './params.ts';
21
17
 
22
18
  /** What the pin endpoint accepts, on top of the shared color params. */
23
19
  const pinQuery = z.object({
24
- username: safeParam,
20
+ username: usernameParam,
25
21
  repo: safeParam,
26
22
  hide_border: booleanParam,
27
23
  card_width: looseIntParam,
@@ -37,41 +33,15 @@ const pinQuery = z.object({
37
33
  description_lines_count: looseIntParam,
38
34
  });
39
35
 
40
- /** The query this endpoint accepts, checked against the schema above. */
41
- type PinApiQuery = ApiQuery<typeof pinQuery>;
42
-
43
36
  /**
44
37
  * Render the repository card for a set of query params.
45
38
  *
46
- * @param query Raw query params, plus any of the shared color params.
47
- * @param query.username GitHub username the repository belongs to.
48
- * @param query.repo Repository name.
49
- * @param query.hide_border Whether to hide the card border.
50
- * @param query.card_width Card width.
51
- * @param query.show_owner Whether to show the repository owner.
52
- * @param query.browser_rendering Whether the browser wraps the description text.
53
- * @param query.show Comma-separated extra stats to show.
54
- * @param query.show_icons Whether to show the stat icons.
55
- * @param query.number_format How numbers are abbreviated.
56
- * @param query.text_bold Whether the stat values are bold.
57
- * @param query.line_height Line height between the stats.
58
- * @param query.locale Language the card is rendered in.
59
- * @param query.border_radius Card border radius.
60
- * @param query.description_lines_count Lines the description is wrapped to.
61
- * @param config Deployment config supplying the PAT pool.
62
39
  * @returns The rendered card, or a rendered error.
63
40
  */
64
- export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiResult> => {
65
- let colors;
66
- try {
67
- colors = parseColorParams(query);
68
- } catch (err) {
69
- // A rejected color cannot be used to draw its own error card.
70
- return errorResult(err);
71
- }
72
-
73
- try {
74
- const {
41
+ const renderPin = cardHandler(
42
+ pinQuery,
43
+ async (
44
+ {
75
45
  username,
76
46
  repo,
77
47
  hide_border,
@@ -86,8 +56,10 @@ export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiRe
86
56
  locale,
87
57
  border_radius,
88
58
  description_lines_count,
89
- } = parseParams(pinQuery, query);
90
-
59
+ },
60
+ colors,
61
+ config,
62
+ ) => {
91
63
  const repoData = await fetchRepo(
92
64
  {
93
65
  username,
@@ -101,26 +73,27 @@ export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiRe
101
73
  config,
102
74
  );
103
75
 
104
- return {
105
- status: 'success',
106
- content: renderRepoCard(repoData, {
107
- ...colors,
108
- hide_border,
109
- border_radius,
110
- card_width_input: card_width,
111
- show_owner,
112
- browser_rendering,
113
- show,
114
- show_icons,
115
- number_format,
116
- text_bold,
117
- line_height,
118
- username,
119
- locale,
120
- description_lines_count,
121
- }),
122
- };
123
- } catch (err) {
124
- return errorResult(err, colors);
125
- }
126
- };
76
+ return renderRepoCard(repoData, {
77
+ ...colors,
78
+ hide_border,
79
+ border_radius,
80
+ card_width_input: card_width,
81
+ show_owner,
82
+ browser_rendering,
83
+ show,
84
+ show_icons,
85
+ number_format,
86
+ text_bold,
87
+ line_height,
88
+ username,
89
+ locale,
90
+ description_lines_count,
91
+ });
92
+ },
93
+ );
94
+
95
+ /**
96
+ * The card, and the values each of its options accepts, keyed by the option's own name.
97
+ * A UI reads them off the function it calls: `pin.OPTIONS.show`.
98
+ */
99
+ export const pin = Object.assign(renderPin, { OPTIONS: renderRepoCard.OPTIONS });
package/src/api/stats.ts CHANGED
@@ -1,100 +1,65 @@
1
1
  import * as z from 'zod/mini';
2
2
 
3
- import { RANK_ICONS, renderStatsCard } from '../cards/stats.js';
4
- import type { CardConfig } from '../common/config.js';
5
- import { fetchStats } from '../fetchers/stats.js';
3
+ import { renderStatsCard } from '../cards/stats.ts';
4
+ import { OWNER_AFFILIATIONS } from '../common/constants.ts';
5
+ import { fetchStats } from '../fetchers/stats.ts';
6
6
 
7
- import type { ApiResult } from './api-result.js';
8
- import { errorResult } from './api-result.js';
9
- import type { ApiQuery } from './params.js';
7
+ import { cardHandler } from './handler.ts';
10
8
  import {
11
9
  booleanParam,
12
10
  enumParam,
11
+ fromParam,
13
12
  listParam,
14
13
  localeParam,
15
14
  looseIntParam,
16
15
  numberParam,
17
- parseColorParams,
18
- parseParams,
16
+ ORDERED_RANGE,
19
17
  rawParam,
20
18
  safeListParam,
21
- safeParam,
22
- yearParam,
23
- } from './params.js';
19
+ toParam,
20
+ usernameParam,
21
+ } from './params.ts';
24
22
 
25
23
  /** What the stats endpoint accepts, on top of the shared color params. */
26
- const statsQuery = z.object({
27
- username: safeParam,
28
- repo: safeListParam,
29
- owner: safeListParam,
30
- hide: listParam,
31
- hide_title: booleanParam,
32
- hide_border: booleanParam,
33
- card_width: looseIntParam,
34
- hide_rank: booleanParam,
35
- show_icons: booleanParam,
36
- include_all_commits: booleanParam,
37
- commits_year: yearParam,
38
- line_height: rawParam,
39
- text_bold: booleanParam,
40
- exclude_repo: listParam,
41
- custom_title: rawParam,
42
- locale: localeParam,
43
- disable_animations: booleanParam,
44
- border_radius: numberParam,
45
- number_format: rawParam,
46
- role: listParam,
47
- number_precision: looseIntParam,
48
- rank_icon: enumParam(RANK_ICONS),
49
- show: listParam,
50
- contribs_include_own_repos: booleanParam,
51
- });
52
-
53
- /** The query this endpoint accepts, checked against the schema above. */
54
- type StatsApiQuery = ApiQuery<typeof statsQuery>;
24
+ const statsQuery = z
25
+ .object({
26
+ username: usernameParam,
27
+ repo: safeListParam,
28
+ owner: safeListParam,
29
+ hide: listParam,
30
+ hide_title: booleanParam,
31
+ hide_border: booleanParam,
32
+ card_width: looseIntParam,
33
+ hide_rank: booleanParam,
34
+ show_icons: booleanParam,
35
+ include_all_commits: booleanParam,
36
+ from: fromParam,
37
+ to: toParam,
38
+ line_height: rawParam,
39
+ text_bold: booleanParam,
40
+ exclude_repo: listParam,
41
+ custom_title: rawParam,
42
+ locale: localeParam,
43
+ disable_animations: booleanParam,
44
+ border_radius: numberParam,
45
+ number_format: rawParam,
46
+ role: listParam,
47
+ number_precision: looseIntParam,
48
+ rank_icon: enumParam(renderStatsCard.OPTIONS.rank_icon),
49
+ show: listParam,
50
+ contribs_include_own_repos: booleanParam,
51
+ })
52
+ .check(ORDERED_RANGE);
55
53
 
56
54
  /**
57
55
  * Render the stats card for a set of query params.
58
56
  *
59
- * @param query Raw query params, plus any of the shared color params.
60
- * @param query.username GitHub username.
61
- * @param query.repo Comma-separated repositories the search-based stats are scoped to.
62
- * @param query.owner Comma-separated owners the search-based stats are scoped to.
63
- * @param query.hide Comma-separated stats to hide.
64
- * @param query.hide_title Whether to hide the card title.
65
- * @param query.hide_border Whether to hide the card border.
66
- * @param query.card_width Card width.
67
- * @param query.hide_rank Whether to hide the rank circle.
68
- * @param query.show_icons Whether to show the stat icons.
69
- * @param query.include_all_commits Whether to count commits of all time.
70
- * @param query.commits_year Year the commits are counted for.
71
- * @param query.line_height Line height between the stats.
72
- * @param query.text_bold Whether the stat values are bold.
73
- * @param query.exclude_repo Comma-separated repositories to exclude.
74
- * @param query.custom_title Card title.
75
- * @param query.locale Language the card is rendered in.
76
- * @param query.disable_animations Whether to disable the card animations.
77
- * @param query.border_radius Card border radius.
78
- * @param query.number_format How numbers are abbreviated.
79
- * @param query.role Comma-separated owner affiliations to include.
80
- * @param query.number_precision Decimals kept when a number is abbreviated.
81
- * @param query.rank_icon Which rank indicator to draw.
82
- * @param query.show Comma-separated extra stats to show.
83
- * @param query.contribs_include_own_repos Whether the contributed-to counts include the user's own repositories.
84
- * @param config Deployment config supplying the PAT pool.
85
57
  * @returns The rendered card, or a rendered error.
86
58
  */
87
- const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<ApiResult> => {
88
- let colors;
89
- try {
90
- colors = parseColorParams(query);
91
- } catch (err) {
92
- // A rejected color cannot be used to draw its own error card.
93
- return errorResult(err);
94
- }
95
-
96
- try {
97
- const {
59
+ const renderStats = cardHandler(
60
+ statsQuery,
61
+ async (
62
+ {
98
63
  username,
99
64
  repo,
100
65
  owner,
@@ -105,7 +70,8 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
105
70
  hide_rank,
106
71
  show_icons,
107
72
  include_all_commits,
108
- commits_year,
73
+ from,
74
+ to,
109
75
  line_height,
110
76
  text_bold,
111
77
  exclude_repo,
@@ -119,8 +85,10 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
119
85
  rank_icon,
120
86
  show,
121
87
  contribs_include_own_repos,
122
- } = parseParams(statsQuery, query);
123
-
88
+ },
89
+ colors,
90
+ config,
91
+ ) => {
124
92
  // A bare repo name is scoped to the user whose card this is.
125
93
  const repository = repo.map((name) =>
126
94
  name.includes('/') ? name : `${username ?? ''}/${name}`,
@@ -135,7 +103,8 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
135
103
  show.includes('prs_merged') || show.includes('prs_merged_percentage'),
136
104
  include_discussions: show.includes('discussions_started'),
137
105
  include_discussions_answers: show.includes('discussions_answered'),
138
- commits_year,
106
+ from,
107
+ to,
139
108
  repo: repository,
140
109
  owner,
141
110
  include_prs_authored: show.includes('prs_authored'),
@@ -151,45 +120,39 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
151
120
  config,
152
121
  );
153
122
 
154
- return {
155
- status: 'success',
156
- content: renderStatsCard(
157
- stats,
158
- {
159
- ...colors,
160
- hide,
161
- show_icons,
162
- hide_title,
163
- hide_border,
164
- card_width,
165
- hide_rank,
166
- include_all_commits,
167
- commits_year,
168
- line_height,
169
- text_bold,
170
- custom_title,
171
- border_radius,
172
- number_format,
173
- number_precision,
174
- locale,
175
- disable_animations,
176
- rank_icon,
177
- show,
178
- },
179
- username,
180
- repository,
181
- owner,
182
- ),
183
- };
184
- } catch (err) {
185
- return errorResult(err, colors);
186
- }
187
- };
123
+ return renderStatsCard(
124
+ stats,
125
+ {
126
+ ...colors,
127
+ hide,
128
+ show_icons,
129
+ hide_title,
130
+ hide_border,
131
+ card_width,
132
+ hide_rank,
133
+ include_all_commits,
134
+ line_height,
135
+ text_bold,
136
+ custom_title,
137
+ border_radius,
138
+ number_format,
139
+ number_precision,
140
+ locale,
141
+ disable_animations,
142
+ rank_icon,
143
+ show,
144
+ },
145
+ username,
146
+ repository,
147
+ owner,
148
+ );
149
+ },
150
+ );
188
151
 
189
152
  /**
190
- * The card, with the values its enum params accept.
191
- * A UI reads them off the function it calls, e.g. `stats.LAYOUTS`.
153
+ * The card, and the values each of its options accepts, keyed by the option's own name.
154
+ * A UI reads them off the function it calls: `stats.OPTIONS.rank_icon`.
192
155
  */
193
156
  export const stats = Object.assign(renderStats, {
194
- RANK_ICONS,
157
+ OPTIONS: { ...renderStatsCard.OPTIONS, role: OWNER_AFFILIATIONS },
195
158
  });
@@ -1,16 +1,10 @@
1
1
  import * as z from 'zod/mini';
2
2
 
3
- import {
4
- TOP_LANG_LAYOUTS,
5
- TOP_LANG_STATS_FORMATS,
6
- renderTopLanguages,
7
- } from '../cards/top-languages.js';
8
- import type { CardConfig } from '../common/config.js';
9
- import { fetchTopLanguages } from '../fetchers/top-languages.js';
3
+ import { renderTopLanguages } from '../cards/top-languages.ts';
4
+ import { OWNER_AFFILIATIONS } from '../common/constants.ts';
5
+ import { fetchTopLanguages } from '../fetchers/top-languages.ts';
10
6
 
11
- import type { ApiResult } from './api-result.js';
12
- import { errorResult } from './api-result.js';
13
- import type { ApiQuery } from './params.js';
7
+ import { cardHandler } from './handler.ts';
14
8
  import {
15
9
  booleanParam,
16
10
  enumParam,
@@ -18,20 +12,18 @@ import {
18
12
  localeParam,
19
13
  looseIntParam,
20
14
  numberParam,
21
- parseColorParams,
22
- parseParams,
23
15
  rawParam,
24
- safeParam,
25
- } from './params.js';
16
+ usernameParam,
17
+ } from './params.ts';
26
18
 
27
19
  /** What the top-languages endpoint accepts, on top of the shared color params. */
28
20
  const topLangsQuery = z.object({
29
- username: safeParam,
21
+ username: usernameParam,
30
22
  hide: listParam,
31
23
  hide_title: booleanParam,
32
24
  hide_border: booleanParam,
33
25
  card_width: looseIntParam,
34
- layout: enumParam(TOP_LANG_LAYOUTS),
26
+ layout: enumParam(renderTopLanguages.OPTIONS.layout),
35
27
  langs_count: looseIntParam,
36
28
  exclude_repo: listParam,
37
29
  size_weight: numberParam,
@@ -43,48 +35,18 @@ const topLangsQuery = z.object({
43
35
  disable_animations: booleanParam,
44
36
  hide_progress: booleanParam,
45
37
  hide_values: booleanParam,
46
- stats_format: enumParam(TOP_LANG_STATS_FORMATS),
38
+ stats_format: enumParam(renderTopLanguages.OPTIONS.stats_format),
47
39
  });
48
40
 
49
- /** The query this endpoint accepts, checked against the schema above. */
50
- type TopLangsApiQuery = ApiQuery<typeof topLangsQuery>;
51
-
52
41
  /**
53
42
  * Render the top languages card for a set of query params.
54
43
  *
55
- * @param query Raw query params, plus any of the shared color params.
56
- * @param query.username GitHub username.
57
- * @param query.hide Comma-separated languages to hide.
58
- * @param query.hide_title Whether to hide the card title.
59
- * @param query.hide_border Whether to hide the card border.
60
- * @param query.card_width Card width.
61
- * @param query.layout How the languages are laid out.
62
- * @param query.langs_count Number of languages to show.
63
- * @param query.exclude_repo Comma-separated repositories to exclude.
64
- * @param query.size_weight Weight given to a language's size.
65
- * @param query.count_weight Weight given to a language's repository count.
66
- * @param query.custom_title Card title.
67
- * @param query.locale Language the card is rendered in.
68
- * @param query.border_radius Card border radius.
69
- * @param query.role Comma-separated owner affiliations to include.
70
- * @param query.disable_animations Whether to disable the card animations.
71
- * @param query.hide_progress Whether to hide the progress bars.
72
- * @param query.hide_values Whether to hide the language values.
73
- * @param query.stats_format Whether values are shown as bytes or percentages.
74
- * @param config Deployment config supplying the PAT pool.
75
44
  * @returns The rendered card, or a rendered error.
76
45
  */
77
- const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Promise<ApiResult> => {
78
- let colors;
79
- try {
80
- colors = parseColorParams(query);
81
- } catch (err) {
82
- // A rejected color cannot be used to draw its own error card.
83
- return errorResult(err);
84
- }
85
-
86
- try {
87
- const {
46
+ const renderTopLangs = cardHandler(
47
+ topLangsQuery,
48
+ async (
49
+ {
88
50
  username,
89
51
  hide,
90
52
  hide_title,
@@ -103,8 +65,10 @@ const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Prom
103
65
  hide_progress,
104
66
  hide_values,
105
67
  stats_format,
106
- } = parseParams(topLangsQuery, query);
107
-
68
+ },
69
+ colors,
70
+ config,
71
+ ) => {
108
72
  const topLangs = await fetchTopLanguages(
109
73
  {
110
74
  username,
@@ -116,35 +80,29 @@ const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Prom
116
80
  config,
117
81
  );
118
82
 
119
- return {
120
- status: 'success',
121
- content: renderTopLanguages(topLangs, {
122
- ...colors,
123
- custom_title,
124
- hide_title,
125
- hide_border,
126
- card_width,
127
- hide,
128
- layout,
129
- langs_count,
130
- border_radius,
131
- locale,
132
- disable_animations,
133
- hide_progress,
134
- hide_values,
135
- stats_format,
136
- }),
137
- };
138
- } catch (err) {
139
- return errorResult(err, colors);
140
- }
141
- };
83
+ return renderTopLanguages(topLangs, {
84
+ ...colors,
85
+ custom_title,
86
+ hide_title,
87
+ hide_border,
88
+ card_width,
89
+ hide,
90
+ layout,
91
+ langs_count,
92
+ border_radius,
93
+ locale,
94
+ disable_animations,
95
+ hide_progress,
96
+ hide_values,
97
+ stats_format,
98
+ });
99
+ },
100
+ );
142
101
 
143
102
  /**
144
- * The card, with the values its enum params accept.
145
- * A UI reads them off the function it calls, e.g. `topLangs.LAYOUTS`.
103
+ * The card, and the values each of its options accepts, keyed by the option's own name.
104
+ * A UI reads them off the function it calls: `topLangs.OPTIONS.layout`.
146
105
  */
147
106
  export const topLangs = Object.assign(renderTopLangs, {
148
- LAYOUTS: TOP_LANG_LAYOUTS,
149
- STATS_FORMATS: TOP_LANG_STATS_FORMATS,
107
+ OPTIONS: { ...renderTopLanguages.OPTIONS, role: OWNER_AFFILIATIONS },
150
108
  });