@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.
- package/README.md +0 -10
- package/build/api/api-result.d.ts +6 -7
- package/build/api/api-result.d.ts.map +1 -1
- package/build/api/api-result.js +4 -5
- package/build/api/contributed-to.d.ts +23 -0
- package/build/api/contributed-to.d.ts.map +1 -0
- package/build/api/contributed-to.js +43 -0
- package/build/api/gist.d.ts +8 -22
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +14 -36
- package/build/api/handler.d.ts +16 -0
- package/build/api/handler.d.ts.map +1 -0
- package/build/api/handler.js +29 -0
- package/build/api/index.d.ts +13 -12
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +1 -0
- package/build/api/params.d.ts +21 -12
- package/build/api/params.d.ts.map +1 -1
- package/build/api/params.js +41 -19
- package/build/api/pin.d.ts +11 -31
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +35 -63
- package/build/api/stats.d.ts +15 -16
- package/build/api/stats.d.ts.map +1 -1
- package/build/api/stats.js +60 -99
- package/build/api/top-langs.d.ts +13 -18
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +35 -72
- package/build/api/wakatime.d.ts +11 -17
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +27 -64
- package/build/calculateRank.d.ts +0 -9
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +12 -17
- package/build/cards/contributed-to.d.ts +19 -0
- package/build/cards/contributed-to.d.ts.map +1 -0
- package/build/cards/contributed-to.js +242 -0
- package/build/cards/gist.d.ts +3 -4
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +38 -43
- package/build/cards/options.d.ts +1 -1
- package/build/cards/repo.d.ts +14 -5
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +93 -103
- package/build/cards/stats.d.ts +18 -11
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +191 -222
- package/build/cards/top-languages.d.ts +18 -33
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +196 -387
- package/build/cards/wakatime.d.ts +17 -8
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +133 -187
- package/build/common/Card.d.ts +20 -59
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +131 -198
- package/build/common/I18n.d.ts +1 -7
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +7 -8
- package/build/common/brand.d.ts +76 -0
- package/build/common/brand.d.ts.map +1 -0
- package/build/common/brand.js +73 -0
- package/build/common/color.d.ts +4 -17
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +67 -49
- package/build/common/config.d.ts +4 -14
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +3 -16
- package/build/common/constants.d.ts +6 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +5 -1
- package/build/common/date.d.ts +50 -5
- package/build/common/date.d.ts.map +1 -1
- package/build/common/date.js +104 -4
- package/build/common/emojiMap.d.ts +8 -0
- package/build/common/emojiMap.d.ts.map +1 -0
- package/build/common/emojiMap.js +10 -0
- package/build/common/emojiMap.json +1915 -0
- package/build/common/error.d.ts +1 -10
- package/build/common/error.d.ts.map +1 -1
- package/build/common/error.js +1 -10
- package/build/common/fmt.d.ts +3 -15
- package/build/common/fmt.d.ts.map +1 -1
- package/build/common/fmt.js +7 -35
- package/build/common/http.d.ts +2 -7
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +8 -17
- package/build/common/icons.d.ts +20 -20
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +108 -67
- package/build/common/languageColors.d.ts +0 -1
- package/build/common/languageColors.d.ts.map +1 -1
- package/build/common/languageColors.js +1 -4
- package/build/common/languageColors.json +18 -2
- package/build/common/ops.d.ts +11 -17
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +22 -39
- package/build/common/render.d.ts +34 -82
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +225 -259
- package/build/common/retryer.d.ts +2 -7
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +4 -11
- package/build/fetchers/contributed-to.d.ts +62 -0
- package/build/fetchers/contributed-to.d.ts.map +1 -0
- package/build/fetchers/contributed-to.js +184 -0
- package/build/fetchers/gist.d.ts +2 -5
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +1 -5
- package/build/fetchers/graphql-error.d.ts +13 -0
- package/build/fetchers/graphql-error.d.ts.map +1 -0
- package/build/fetchers/graphql-error.js +29 -0
- package/build/fetchers/index.d.ts +13 -12
- package/build/fetchers/index.d.ts.map +1 -1
- package/build/fetchers/index.js +1 -0
- package/build/fetchers/repo.d.ts +2 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +20 -33
- package/build/fetchers/stats.d.ts +16 -40
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +89 -271
- package/build/fetchers/top-languages.d.ts +2 -9
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +16 -47
- package/build/fetchers/types.d.ts +25 -1
- package/build/fetchers/types.d.ts.map +1 -1
- package/build/fetchers/wakatime.d.ts +2 -6
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +1 -5
- package/build/graphql/contributionsCollection.d.ts +9 -0
- package/build/graphql/contributionsCollection.d.ts.map +1 -0
- package/build/graphql/contributionsCollection.js +12 -0
- package/build/graphql/contributionsDocument.d.ts +6 -6
- package/build/graphql/contributionsDocument.d.ts.map +1 -1
- package/build/graphql/contributionsDocument.js +8 -16
- package/build/graphql/generated/contributed-to.d.ts +22 -0
- package/build/graphql/generated/contributed-to.d.ts.map +1 -0
- package/build/graphql/generated/contributed-to.js +11 -0
- package/build/graphql/generated/gist.d.ts +1 -1
- package/build/graphql/generated/repo.d.ts +1 -1
- package/build/graphql/generated/stats.d.ts +16 -4
- package/build/graphql/generated/stats.d.ts.map +1 -1
- package/build/graphql/generated/stats.js +2 -2
- package/build/graphql/generated/top-languages.d.ts +2 -2
- package/build/graphql/graphqlDocument.d.ts +1 -2
- package/build/graphql/graphqlDocument.d.ts.map +1 -1
- package/build/graphql/graphqlDocument.js +0 -1
- package/build/graphql/reposContributedToDocument.d.ts +4 -5
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
- package/build/graphql/reposContributedToDocument.js +11 -7
- package/build/markup/css.d.ts +35 -0
- package/build/markup/css.d.ts.map +1 -0
- package/build/markup/css.js +64 -0
- package/build/markup/element.d.ts +41 -0
- package/build/markup/element.d.ts.map +1 -0
- package/build/markup/element.js +127 -0
- package/build/markup/html.d.ts +13 -0
- package/build/markup/html.d.ts.map +1 -0
- package/build/markup/html.js +27 -0
- package/build/markup/index.d.ts +9 -0
- package/build/markup/index.d.ts.map +1 -0
- package/build/markup/index.js +6 -0
- package/build/markup/serialize.d.ts +16 -0
- package/build/markup/serialize.d.ts.map +1 -0
- package/build/markup/serialize.js +17 -0
- package/build/themes/index.d.ts +332 -333
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +1 -1
- package/build/translations.d.ts +66 -7
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +686 -629
- package/package.json +17 -26
- package/src/api/api-result.ts +10 -9
- package/src/api/contributed-to.ts +84 -0
- package/src/api/gist.ts +22 -46
- package/src/api/handler.ts +42 -0
- package/src/api/index.ts +13 -12
- package/src/api/params.ts +74 -29
- package/src/api/pin.ts +38 -65
- package/src/api/stats.ts +81 -118
- package/src/api/top-langs.ts +38 -80
- package/src/api/wakatime.ts +35 -73
- package/src/calculateRank.ts +12 -23
- package/src/cards/contributed-to.ts +373 -0
- package/src/cards/gist.ts +55 -49
- package/src/cards/options.ts +1 -1
- package/src/cards/repo.ts +134 -120
- package/src/cards/stats.ts +262 -252
- package/src/cards/top-languages.ts +315 -422
- package/src/cards/wakatime.ts +207 -225
- package/src/common/Card.ts +207 -214
- package/src/common/I18n.ts +7 -8
- package/src/common/brand.ts +109 -0
- package/src/common/color.ts +80 -57
- package/src/common/config.ts +5 -18
- package/src/common/constants.ts +8 -2
- package/src/common/date.ts +135 -5
- package/src/common/emojiMap.json +1915 -0
- package/src/common/emojiMap.ts +13 -0
- package/src/common/error.ts +2 -11
- package/src/common/fmt.ts +7 -44
- package/src/common/http.ts +9 -15
- package/src/common/icons.ts +122 -42
- package/src/common/languageColors.json +18 -2
- package/src/common/languageColors.ts +1 -4
- package/src/common/ops.ts +31 -48
- package/src/common/render.ts +334 -284
- package/src/common/retryer.ts +8 -15
- package/src/fetchers/contributed-to.ts +271 -0
- package/src/fetchers/gist.ts +8 -12
- package/src/fetchers/graphql-error.ts +36 -0
- package/src/fetchers/index.ts +15 -12
- package/src/fetchers/repo.ts +27 -40
- package/src/fetchers/stats.ts +157 -366
- package/src/fetchers/top-languages.ts +27 -55
- package/src/fetchers/types.ts +27 -1
- package/src/fetchers/wakatime.ts +5 -9
- package/src/graphql/contributionsCollection.ts +18 -0
- package/src/graphql/contributionsDocument.ts +14 -19
- package/src/graphql/generated/contributed-to.ts +25 -0
- package/src/graphql/generated/gist.ts +1 -1
- package/src/graphql/generated/repo.ts +1 -1
- package/src/graphql/generated/stats.ts +21 -8
- package/src/graphql/generated/top-languages.ts +2 -2
- package/src/graphql/graphqlDocument.ts +1 -2
- package/src/graphql/queries/contributed-to.graphql +8 -0
- package/src/graphql/queries/stats.graphql +14 -2
- package/src/graphql/reposContributedToDocument.ts +16 -15
- package/src/markup/css.ts +118 -0
- package/src/markup/element.ts +246 -0
- package/src/markup/html.ts +34 -0
- package/src/markup/index.ts +9 -0
- package/src/markup/serialize.ts +27 -0
- package/src/themes/index.ts +1 -1
- package/src/translations.ts +699 -629
- package/build/cards/index.d.ts +0 -11
- package/build/cards/index.d.ts.map +0 -1
- package/build/cards/index.js +0 -7
- package/build/common/html.d.ts +0 -8
- package/build/common/html.d.ts.map +0 -1
- package/build/common/html.js +0 -14
- package/build/index.d.ts +0 -15
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -10
- package/src/_emoji-name-map.d.ts +0 -10
- package/src/_github-username-regex.d.ts +0 -4
- package/src/cards/index.ts +0 -21
- package/src/common/html.ts +0 -17
- package/src/index.ts +0 -18
package/README.md
CHANGED
|
@@ -100,16 +100,6 @@ const config = new CardConfig({
|
|
|
100
100
|
});
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
## Rendering from data you already hold
|
|
104
|
-
|
|
105
|
-
If you cache stats yourself, skip the fetchers and render directly:
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
import { renderStatsCard } from '@stats-forge/github-stats-forge-core/cards';
|
|
109
|
-
|
|
110
|
-
const svg = renderStatsCard(myStats, { theme: 'dracula', hide_rank: true });
|
|
111
|
-
```
|
|
112
|
-
|
|
113
103
|
Every card is labelled for screen readers: the SVG carries `role="img"` with a `<title>`
|
|
114
104
|
and `<desc>` describing what it shows, since assistive technology cannot reach the text
|
|
115
105
|
inside an image role.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ColorParams } from '../common/color.
|
|
2
|
-
import type { ErrorCode } from '../common/error.
|
|
1
|
+
import type { ColorParams } from '../common/color.ts';
|
|
2
|
+
import type { ErrorCode } from '../common/error.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Why a card could not be rendered, in a form a host can act on.
|
|
5
5
|
* The same failure is also drawn onto the result's `content`,
|
|
@@ -33,12 +33,11 @@ export type ApiResult = {
|
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Turns anything a handler threw into the one shape it answers with.
|
|
36
|
+
* Anything that is not a `CardError` is treated as upstream's.
|
|
36
37
|
*
|
|
37
|
-
* @param err The failure.
|
|
38
|
-
* Anything that is not a `CardError` is treated as upstream's.
|
|
39
|
-
* @param renderOptions Colors the error card is drawn with;
|
|
40
|
-
* omitted when it was a color that was rejected.
|
|
41
38
|
* @returns The rendered error.
|
|
42
39
|
*/
|
|
43
|
-
export declare const errorResult: (err: unknown,
|
|
40
|
+
export declare const errorResult: (err: unknown,
|
|
41
|
+
/** omitted when it was a color that was rejected, which cannot draw its own error card */
|
|
42
|
+
renderOptions?: ColorParams) => ApiResult;
|
|
44
43
|
//# sourceMappingURL=api-result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-result.d.ts","sourceRoot":"","sources":["../../src/api/api-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,qBAAqB;IACrB,IAAI,EAAE,SAAS,CAAC;IAChB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC;;;;OAIG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GACjB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtC;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,QAAQ,CAAC;IAChB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN
|
|
1
|
+
{"version":3,"file":"api-result.d.ts","sourceRoot":"","sources":["../../src/api/api-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,qBAAqB;IACrB,IAAI,EAAE,SAAS,CAAC;IAChB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC;;;;OAIG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GACjB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtC;IACE,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,QAAQ,CAAC;IAChB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QACjB,OAAO;AACZ,0FAA0F;gBAC1E,WAAW,KAC1B,SAsBF,CAAC"}
|
package/build/api/api-result.js
CHANGED
|
@@ -2,14 +2,13 @@ import { CardError } from '../common/error.js';
|
|
|
2
2
|
import { renderError } from '../common/render.js';
|
|
3
3
|
/**
|
|
4
4
|
* Turns anything a handler threw into the one shape it answers with.
|
|
5
|
+
* Anything that is not a `CardError` is treated as upstream's.
|
|
5
6
|
*
|
|
6
|
-
* @param err The failure.
|
|
7
|
-
* Anything that is not a `CardError` is treated as upstream's.
|
|
8
|
-
* @param renderOptions Colors the error card is drawn with;
|
|
9
|
-
* omitted when it was a color that was rejected.
|
|
10
7
|
* @returns The rendered error.
|
|
11
8
|
*/
|
|
12
|
-
export const errorResult = (err,
|
|
9
|
+
export const errorResult = (err,
|
|
10
|
+
/** omitted when it was a color that was rejected, which cannot draw its own error card */
|
|
11
|
+
renderOptions) => {
|
|
13
12
|
const error = CardError.from(err);
|
|
14
13
|
return {
|
|
15
14
|
status: 'error',
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
/**
|
|
3
|
+
* Render the contributed-to card for a set of query params.
|
|
4
|
+
*
|
|
5
|
+
* @returns The rendered card, or a rendered error.
|
|
6
|
+
*/
|
|
7
|
+
export declare const contributedTo: (query: import("./params.ts").ApiQuery<z.ZodMiniObject<{
|
|
8
|
+
username: z.ZodMiniType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
|
|
9
|
+
locale: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<string | undefined, string | undefined>>;
|
|
10
|
+
repos_count: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<number | undefined, string | undefined>>;
|
|
11
|
+
include_own_repos: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
12
|
+
exclude_repo: z.ZodMiniType<string[], string | undefined, z.core.$ZodTypeInternals<string[], string | undefined>>;
|
|
13
|
+
from: z.ZodMiniType<Date | undefined, string | undefined, z.core.$ZodTypeInternals<Date | undefined, string | undefined>>;
|
|
14
|
+
to: z.ZodMiniType<Date | undefined, string | undefined, z.core.$ZodTypeInternals<Date | undefined, string | undefined>>;
|
|
15
|
+
hide_years: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
16
|
+
hide_title: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
17
|
+
hide_border: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
18
|
+
card_width: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<number | undefined, string | undefined>>;
|
|
19
|
+
custom_title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
20
|
+
border_radius: z.ZodMiniType<number | undefined, string | undefined, z.core.$ZodTypeInternals<number | undefined, string | undefined>>;
|
|
21
|
+
disable_animations: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
22
|
+
}, z.core.$strip>>, config: import("./index.ts").CardConfig) => Promise<import("./api-result.ts").ApiResult>;
|
|
23
|
+
//# sourceMappingURL=contributed-to.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contributed-to.d.ts","sourceRoot":"","sources":["../../src/api/contributed-to.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAuC9B;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;4GAuCzB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
import { renderContributedToCard } from '../cards/contributed-to.js';
|
|
3
|
+
import { fetchContributedTo } from '../fetchers/contributed-to.js';
|
|
4
|
+
import { cardHandler } from './handler.js';
|
|
5
|
+
import { booleanParam, fromParam, localeParam, looseIntParam, numberParam, ORDERED_RANGE, rawParam, safeListParam, toParam, usernameParam, } from './params.js';
|
|
6
|
+
/** What the contributed-to endpoint accepts, on top of the shared color params. */
|
|
7
|
+
const contributedToQuery = z
|
|
8
|
+
.object({
|
|
9
|
+
username: usernameParam,
|
|
10
|
+
locale: localeParam,
|
|
11
|
+
repos_count: looseIntParam,
|
|
12
|
+
include_own_repos: booleanParam,
|
|
13
|
+
exclude_repo: safeListParam,
|
|
14
|
+
from: fromParam,
|
|
15
|
+
to: toParam,
|
|
16
|
+
hide_years: booleanParam,
|
|
17
|
+
hide_title: booleanParam,
|
|
18
|
+
hide_border: booleanParam,
|
|
19
|
+
card_width: looseIntParam,
|
|
20
|
+
custom_title: rawParam,
|
|
21
|
+
border_radius: numberParam,
|
|
22
|
+
disable_animations: booleanParam,
|
|
23
|
+
})
|
|
24
|
+
.check(ORDERED_RANGE);
|
|
25
|
+
/**
|
|
26
|
+
* Render the contributed-to card for a set of query params.
|
|
27
|
+
*
|
|
28
|
+
* @returns The rendered card, or a rendered error.
|
|
29
|
+
*/
|
|
30
|
+
export const contributedTo = cardHandler(contributedToQuery, async ({ username, locale, repos_count, include_own_repos, exclude_repo, from, to, hide_years, hide_title, hide_border, card_width, custom_title, border_radius, disable_animations, }, colors, config) => {
|
|
31
|
+
const data = await fetchContributedTo({ username, include_own_repos, repos_count, exclude_repo, from, to }, config);
|
|
32
|
+
return renderContributedToCard(data, {
|
|
33
|
+
...colors,
|
|
34
|
+
locale,
|
|
35
|
+
hide_years,
|
|
36
|
+
hide_title,
|
|
37
|
+
hide_border,
|
|
38
|
+
card_width,
|
|
39
|
+
custom_title,
|
|
40
|
+
border_radius,
|
|
41
|
+
disable_animations,
|
|
42
|
+
});
|
|
43
|
+
});
|
package/build/api/gist.d.ts
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
|
-
import type { CardConfig } from '../common/config.js';
|
|
3
|
-
import type { ApiResult } from './api-result.js';
|
|
4
|
-
import type { ApiQuery } from './params.js';
|
|
5
|
-
/** What the gist endpoint accepts, on top of the shared color params. */
|
|
6
|
-
declare const gistQuery: z.ZodMiniObject<{
|
|
7
|
-
id: z.ZodMiniType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
|
|
8
|
-
border_radius: z.ZodMiniType<number | undefined, string | undefined, z.core.$ZodTypeInternals<number | undefined, string | undefined>>;
|
|
9
|
-
show_owner: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
10
|
-
browser_rendering: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
11
|
-
hide_border: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
12
|
-
}, z.core.$strip>;
|
|
13
|
-
/** The query this endpoint accepts, checked against the schema above. */
|
|
14
|
-
type GistApiQuery = ApiQuery<typeof gistQuery>;
|
|
15
2
|
/**
|
|
16
3
|
* Render the gist card for a set of query params.
|
|
17
4
|
*
|
|
18
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
19
|
-
* @param query.id GitHub gist ID.
|
|
20
|
-
* @param query.border_radius Card border radius.
|
|
21
|
-
* @param query.show_owner Whether to show the gist owner.
|
|
22
|
-
* @param query.browser_rendering Whether the browser wraps the description text.
|
|
23
|
-
* @param query.hide_border Whether to hide the card border.
|
|
24
|
-
* @param config Deployment config supplying the PAT pool.
|
|
25
5
|
* @returns The rendered card, or a rendered error.
|
|
26
6
|
*/
|
|
27
|
-
export declare const gist: (query:
|
|
28
|
-
|
|
7
|
+
export declare const gist: (query: import("./params.ts").ApiQuery<z.ZodMiniObject<{
|
|
8
|
+
id: z.ZodMiniType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
|
|
9
|
+
locale: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<string | undefined, string | undefined>>;
|
|
10
|
+
border_radius: z.ZodMiniType<number | undefined, string | undefined, z.core.$ZodTypeInternals<number | undefined, string | undefined>>;
|
|
11
|
+
show_owner: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
12
|
+
browser_rendering: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
13
|
+
hide_border: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
14
|
+
}, z.core.$strip>>, config: import("./index.ts").CardConfig) => Promise<import("./api-result.ts").ApiResult>;
|
|
29
15
|
//# sourceMappingURL=gist.d.ts.map
|
package/build/api/gist.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gist.d.ts","sourceRoot":"","sources":["../../src/api/gist.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"gist.d.ts","sourceRoot":"","sources":["../../src/api/gist.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAkB9B;;;;GAIG;AACH,eAAO,MAAM,IAAI;;;;;;;4GAkBhB,CAAC"}
|
package/build/api/gist.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
import { renderGistCard } from '../cards/gist.js';
|
|
3
3
|
import { fetchGist } from '../fetchers/gist.js';
|
|
4
|
-
import {
|
|
5
|
-
import { booleanParam,
|
|
4
|
+
import { cardHandler } from './handler.js';
|
|
5
|
+
import { booleanParam, localeParam, numberParam, safeParam } from './params.js';
|
|
6
6
|
/** What the gist endpoint accepts, on top of the shared color params. */
|
|
7
7
|
const gistQuery = z.object({
|
|
8
8
|
id: safeParam,
|
|
9
|
+
locale: localeParam,
|
|
9
10
|
border_radius: numberParam,
|
|
10
11
|
show_owner: booleanParam,
|
|
11
12
|
browser_rendering: booleanParam,
|
|
@@ -14,39 +15,16 @@ const gistQuery = z.object({
|
|
|
14
15
|
/**
|
|
15
16
|
* Render the gist card for a set of query params.
|
|
16
17
|
*
|
|
17
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
18
|
-
* @param query.id GitHub gist ID.
|
|
19
|
-
* @param query.border_radius Card border radius.
|
|
20
|
-
* @param query.show_owner Whether to show the gist owner.
|
|
21
|
-
* @param query.browser_rendering Whether the browser wraps the description text.
|
|
22
|
-
* @param query.hide_border Whether to hide the card border.
|
|
23
|
-
* @param config Deployment config supplying the PAT pool.
|
|
24
18
|
* @returns The rendered card, or a rendered error.
|
|
25
19
|
*/
|
|
26
|
-
export const gist = async (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
colors
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const gistData = await fetchGist({ id }, config);
|
|
38
|
-
return {
|
|
39
|
-
status: 'success',
|
|
40
|
-
content: renderGistCard(gistData, {
|
|
41
|
-
...colors,
|
|
42
|
-
border_radius,
|
|
43
|
-
show_owner,
|
|
44
|
-
browser_rendering,
|
|
45
|
-
hide_border,
|
|
46
|
-
}),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
return errorResult(err, colors);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
20
|
+
export const gist = cardHandler(gistQuery, async ({ id, locale, border_radius, show_owner, browser_rendering, hide_border }, colors, config) => {
|
|
21
|
+
const gistData = await fetchGist({ id }, config);
|
|
22
|
+
return renderGistCard(gistData, {
|
|
23
|
+
...colors,
|
|
24
|
+
locale,
|
|
25
|
+
border_radius,
|
|
26
|
+
show_owner,
|
|
27
|
+
browser_rendering,
|
|
28
|
+
hide_border,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as z from 'zod/mini';
|
|
2
|
+
import type { ColorParams } from '../common/color.ts';
|
|
3
|
+
import type { CardConfig } from '../common/config.ts';
|
|
4
|
+
import type { ApiResult } from './api-result.ts';
|
|
5
|
+
import type { ApiQuery } from './params.ts';
|
|
6
|
+
/**
|
|
7
|
+
* An endpoint: the schema it accepts, and what it draws from the parsed params.
|
|
8
|
+
*
|
|
9
|
+
* Colors parse first and on their own, because a rejected color cannot be used to draw its own error card.
|
|
10
|
+
* Parsing throws, fetching throws, and one `catch` turns whatever was thrown into the answer.
|
|
11
|
+
*
|
|
12
|
+
* @returns The handler, taking the query the schema describes.
|
|
13
|
+
*/
|
|
14
|
+
declare const cardHandler: <TSchema extends z.ZodMiniType>(schema: TSchema, render: (params: z.output<TSchema>, colors: ColorParams, config: CardConfig) => Promise<string>) => (query: ApiQuery<TSchema>, config: CardConfig) => Promise<ApiResult>;
|
|
15
|
+
export { cardHandler };
|
|
16
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/api/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C;;;;;;;GAOG;AACH,QAAA,MAAM,WAAW,GACd,OAAO,SAAS,CAAC,CAAC,WAAW,UACpB,OAAO,UACP,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,MAAM,CAAC,aAEnF,QAAQ,CAAC,OAAO,CAAC,UAAU,UAAU,KAAG,OAAO,CAAC,SAAS,CAgBtE,CAAC;AAEJ,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { errorResult } from './api-result.js';
|
|
2
|
+
import { parseColorParams, parseParams } from './params.js';
|
|
3
|
+
/**
|
|
4
|
+
* An endpoint: the schema it accepts, and what it draws from the parsed params.
|
|
5
|
+
*
|
|
6
|
+
* Colors parse first and on their own, because a rejected color cannot be used to draw its own error card.
|
|
7
|
+
* Parsing throws, fetching throws, and one `catch` turns whatever was thrown into the answer.
|
|
8
|
+
*
|
|
9
|
+
* @returns The handler, taking the query the schema describes.
|
|
10
|
+
*/
|
|
11
|
+
const cardHandler = (schema, render) => async (query, config) => {
|
|
12
|
+
let colors;
|
|
13
|
+
try {
|
|
14
|
+
colors = parseColorParams(query);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return errorResult(error);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return {
|
|
21
|
+
status: 'success',
|
|
22
|
+
content: await render(parseParams(schema, query), colors, config),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return errorResult(error, colors);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export { cardHandler };
|
package/build/api/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export type {
|
|
10
|
-
export type {
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
1
|
+
export { contributedTo } from './contributed-to.ts';
|
|
2
|
+
export { gist } from './gist.ts';
|
|
3
|
+
export { pin } from './pin.ts';
|
|
4
|
+
export { stats } from './stats.ts';
|
|
5
|
+
export { topLangs } from './top-langs.ts';
|
|
6
|
+
export { wakatime } from './wakatime.ts';
|
|
7
|
+
export type { ApiError, ApiResult } from './api-result.ts';
|
|
8
|
+
export { CardConfig } from '../common/config.ts';
|
|
9
|
+
export type { CardConfigInit, PersonalAccessToken } from '../common/config.ts';
|
|
10
|
+
export type { FetchLike } from '../common/http.ts';
|
|
11
|
+
export type { ErrorCode } from '../common/error.ts';
|
|
12
|
+
export { themes } from '../themes/index.ts';
|
|
13
|
+
export type { ThemeName } from '../themes/index.ts';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
package/build/api/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC"}
|
package/build/api/index.js
CHANGED
package/build/api/params.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
|
-
import type { ColorParams } from '../common/color.
|
|
2
|
+
import type { ColorParams } from '../common/color.ts';
|
|
3
3
|
/**
|
|
4
4
|
* @file The api layer is the trust boundary:
|
|
5
5
|
* a query string arrives as strings, and each endpoint declares what it accepts as a schema over them.
|
|
@@ -31,17 +31,28 @@ declare const numberParam: z.ZodMiniType<number | undefined, string | undefined>
|
|
|
31
31
|
* `NaN` reaches the renderer, which answers it with its own default.
|
|
32
32
|
*/
|
|
33
33
|
declare const looseIntParam: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<number | undefined, string | undefined>>;
|
|
34
|
+
/** The start of a card's range; see {@link rangeParam}. */
|
|
35
|
+
declare const fromParam: z.ZodMiniType<Date | undefined, string | undefined, z.core.$ZodTypeInternals<Date | undefined, string | undefined>>;
|
|
36
|
+
/** The end of a card's range; see {@link rangeParam}. */
|
|
37
|
+
declare const toParam: z.ZodMiniType<Date | undefined, string | undefined, z.core.$ZodTypeInternals<Date | undefined, string | undefined>>;
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Yields the year, or `undefined` when the param is absent.
|
|
39
|
+
* The pair-level rule the two ends cannot see on their own.
|
|
40
|
+
* Every endpoint taking a range applies it, so an order no card could draw is rejected once.
|
|
38
41
|
*/
|
|
39
|
-
declare const
|
|
42
|
+
declare const ORDERED_RANGE: z.core.$ZodCheck<{
|
|
43
|
+
from?: Date | undefined;
|
|
44
|
+
to?: Date | undefined;
|
|
45
|
+
}>;
|
|
40
46
|
/**
|
|
41
47
|
* An id the fetchers put in a URL.
|
|
42
48
|
* Rejected before any request is made, and yielded unchanged otherwise.
|
|
43
49
|
*/
|
|
44
50
|
declare const safeParam: z.ZodMiniType<string | undefined, string | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* A GitHub login, stricter than `safeParam`: no leading, trailing or doubled hyphen.
|
|
53
|
+
* Rejected here so a malformed one is a permanent error rather than the NOT_FOUND GitHub answers.
|
|
54
|
+
*/
|
|
55
|
+
declare const usernameParam: z.ZodMiniType<string | undefined, string | undefined>;
|
|
45
56
|
/**
|
|
46
57
|
* A comma-separated list of ids, checked before it is split.
|
|
47
58
|
* The safe pattern allows the commas, so one check covers the whole list.
|
|
@@ -57,7 +68,6 @@ declare const localeParam: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<strin
|
|
|
57
68
|
/**
|
|
58
69
|
* A param the card only renders as one of a fixed set of values.
|
|
59
70
|
*
|
|
60
|
-
* @param values The accepted values, as the card that renders them declares them.
|
|
61
71
|
* @returns Schema yielding one of `values`, or `undefined` when absent.
|
|
62
72
|
*/
|
|
63
73
|
declare const enumParam: <const T extends ReadonlyArray<string>>(values: T) => z.ZodMiniType<T[number] | undefined, string | undefined>;
|
|
@@ -73,21 +83,20 @@ type ApiQuery<TSchema extends z.ZodMiniType> = Partial<z.input<TSchema>> & Color
|
|
|
73
83
|
* Only the first rejection is reported:
|
|
74
84
|
* the error card has room for one line.
|
|
75
85
|
*
|
|
76
|
-
* @param schema The endpoint's schema.
|
|
77
|
-
* @param query Raw query params.
|
|
78
|
-
* @returns The parsed params.
|
|
79
86
|
* @throws {CardError} When the schema rejects a param.
|
|
87
|
+
*
|
|
88
|
+
* @returns The parsed params.
|
|
80
89
|
*/
|
|
81
90
|
declare const parseParams: <TSchema extends z.ZodMiniType>(schema: TSchema, query: unknown) => z.output<TSchema>;
|
|
82
91
|
/**
|
|
83
92
|
* The color params, validated.
|
|
84
93
|
* Split from the endpoint's own schema because a rejected color cannot then be used to render its own error card.
|
|
85
94
|
*
|
|
86
|
-
* @param query Raw query params.
|
|
87
|
-
* @returns The color params.
|
|
88
95
|
* @throws {CardError} When a param does not hold a color or a gradient.
|
|
96
|
+
*
|
|
97
|
+
* @returns The color params.
|
|
89
98
|
*/
|
|
90
99
|
declare const parseColorParams: (query: unknown) => ColorParams;
|
|
91
100
|
export type { ApiQuery };
|
|
92
|
-
export { booleanParam, enumParam, listParam, localeParam, looseIntParam, numberParam, parseColorParams, parseParams, rawParam, safeListParam, safeParam,
|
|
101
|
+
export { booleanParam, enumParam, fromParam, listParam, ORDERED_RANGE, localeParam, looseIntParam, numberParam, parseColorParams, parseParams, rawParam, safeListParam, safeParam, toParam, usernameParam, };
|
|
93
102
|
//# sourceMappingURL=params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/api/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/api/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAQtD;;;;;;;;GAQG;AAEH,sDAAsD;AACtD,QAAA,MAAM,QAAQ,4CAAyB,CAAC;AA4CxC;;;GAGG;AACH,QAAA,MAAM,YAAY,wHAIjB,CAAC;AAEF,8DAA8D;AAC9D,QAAA,MAAM,SAAS,6GAA4C,CAAC;AAE5D;;;;;;GAMG;AACH,QAAA,MAAM,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAGtE,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,aAAa,uHAGlB,CAAC;AAsBF,2DAA2D;AAC3D,QAAA,MAAM,SAAS,qHAAqB,CAAC;AAErC,yDAAyD;AACzD,QAAA,MAAM,OAAO,qHAAmB,CAAC;AAEjC;;;GAGG;AACH,QAAA,MAAM,aAAa;WAAqB,IAAI,GAAG,SAAS;SAAO,IAAI,GAAG,SAAS;EAG9E,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAEpE,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,aAAa,EAAE,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAExE,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,aAAa,EAAE,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAGnE,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,WAAW,uHAGhB,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,SAAS,GAAI,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,UAC9C,CAAC,KACR,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CACqC,CAAC;AAmBhG;;;;GAIG;AACH,KAAK,QAAQ,CAAC,OAAO,SAAS,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,WAAW,CAAC;AAcvF;;;;;;;;;GASG;AACH,QAAA,MAAM,WAAW,GAAI,OAAO,SAAS,CAAC,CAAC,WAAW,UACxC,OAAO,SACR,OAAO,KACb,CAAC,CAAC,MAAM,CAAC,OAAO,CAMlB,CAAC;AAEF;;;;;;;GAOG;AACH,QAAA,MAAM,gBAAgB,UAAW,OAAO,KAAG,WAAoD,CAAC;AAEhG,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,SAAS,EACT,OAAO,EACP,aAAa,GACd,CAAC"}
|
package/build/api/params.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
import { COLOR_PARAM_KEYS, THEME_PARAM_KEYS, isValidColorInput } from '../common/color.js';
|
|
3
|
+
import { GITHUB_USERNAME_PATTERN } from '../common/constants.js';
|
|
4
|
+
import { getWidestRange, parseRangeDate } from '../common/date.js';
|
|
3
5
|
import { CardError } from '../common/error.js';
|
|
4
6
|
import { parseArray, parseBoolean } from '../common/ops.js';
|
|
5
7
|
import { isLocaleAvailable } from '../translations.js';
|
|
@@ -14,7 +16,7 @@ import { isLocaleAvailable } from '../translations.js';
|
|
|
14
16
|
*/
|
|
15
17
|
/** Every param arrives as a string, or not at all. */
|
|
16
18
|
const rawParam = z.optional(z.string());
|
|
17
|
-
/** Characters a
|
|
19
|
+
/** Characters a repository, owner or gist id may contain. */
|
|
18
20
|
const SAFE_PATTERN = /^[-\w/.,]+$/;
|
|
19
21
|
/**
|
|
20
22
|
* Every rejection the api can put on an error card, in one place.
|
|
@@ -22,8 +24,11 @@ const SAFE_PATTERN = /^[-\w/.,]+$/;
|
|
|
22
24
|
*/
|
|
23
25
|
const REJECTION_MESSAGES = {
|
|
24
26
|
number: (param) => `Invalid number input for parameter "${param}"`,
|
|
25
|
-
|
|
27
|
+
date: (param) => `Invalid date input for parameter "${param}"`,
|
|
28
|
+
out_of_range: (param) => `Out of range date for parameter "${param}"`,
|
|
29
|
+
inverted_range: () => 'Range "from" is after "to"',
|
|
26
30
|
unsafe: (param) => `Parameter "${param}" contains unsafe characters`,
|
|
31
|
+
username: (param) => `Invalid username input for parameter "${param}"`,
|
|
27
32
|
locale: () => 'Locale not found',
|
|
28
33
|
enum: (param) => `Incorrect ${param} input`,
|
|
29
34
|
color: (param) => `Invalid color input for parameter "${param}"`,
|
|
@@ -32,8 +37,6 @@ const REJECTION_MESSAGES = {
|
|
|
32
37
|
* A check that words its own rejection:
|
|
33
38
|
* the message is built from the kind and the param's path rather than passed in.
|
|
34
39
|
*
|
|
35
|
-
* @param kind What the check rejects the param for.
|
|
36
|
-
* @param passes Whether a value is acceptable.
|
|
37
40
|
* @returns The check, ready for `.check()`.
|
|
38
41
|
*/
|
|
39
42
|
const rejects = (kind, passes) => z.refine((value) => typeof value !== 'string' || passes(value), {
|
|
@@ -55,23 +58,45 @@ const listParam = z.pipe(rawParam, z.transform(parseArray));
|
|
|
55
58
|
* `parseFloat`, matching the coercion `Card` performs internally, so `?border_radius=10px` still renders `rx="10"`.
|
|
56
59
|
* Yields the parsed number, or `undefined` when the param is absent.
|
|
57
60
|
*/
|
|
58
|
-
const numberParam = z.pipe(rawParam.check(rejects('number', (value) => Number.isFinite(parseFloat(value)))), z.transform((value) => (value === undefined ? undefined : parseFloat(value))));
|
|
61
|
+
const numberParam = z.pipe(rawParam.check(rejects('number', (value) => Number.isFinite(Number.parseFloat(value)))), z.transform((value) => (value === undefined ? undefined : Number.parseFloat(value))));
|
|
59
62
|
/**
|
|
60
63
|
* A number the card already falls back from — widths, counts, line heights:
|
|
61
64
|
* `NaN` reaches the renderer, which answers it with its own default.
|
|
62
65
|
*/
|
|
63
|
-
const looseIntParam = z.pipe(rawParam, z.transform((value) => (value === undefined ? undefined : parseInt(value, 10))));
|
|
66
|
+
const looseIntParam = z.pipe(rawParam, z.transform((value) => (value === undefined ? undefined : Number.parseInt(value, 10))));
|
|
64
67
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
+
* One end of the range a card counts within, written as `2024`, `2024-03` or `2024-03-15`.
|
|
69
|
+
*
|
|
70
|
+
* @returns Schema yielding the instant, or `undefined` when the param is absent.
|
|
71
|
+
*/
|
|
72
|
+
const rangeParam = (end) => {
|
|
73
|
+
const parse = (value) => parseRangeDate(value, end);
|
|
74
|
+
return z.pipe(rawParam.check(rejects('date', (value) => parse(value) !== undefined)).check(rejects('out_of_range', (value) => {
|
|
75
|
+
const date = parse(value);
|
|
76
|
+
const widest = getWidestRange();
|
|
77
|
+
// a bad shape is already reported by the check above
|
|
78
|
+
return date === undefined || (date >= widest.from && date <= widest.to);
|
|
79
|
+
})), z.transform((value) => (value === undefined ? undefined : parse(value))));
|
|
80
|
+
};
|
|
81
|
+
/** The start of a card's range; see {@link rangeParam}. */
|
|
82
|
+
const fromParam = rangeParam('from');
|
|
83
|
+
/** The end of a card's range; see {@link rangeParam}. */
|
|
84
|
+
const toParam = rangeParam('to');
|
|
85
|
+
/**
|
|
86
|
+
* The pair-level rule the two ends cannot see on their own.
|
|
87
|
+
* Every endpoint taking a range applies it, so an order no card could draw is rejected once.
|
|
68
88
|
*/
|
|
69
|
-
const
|
|
89
|
+
const ORDERED_RANGE = z.refine(({ from, to }) => from === undefined || to === undefined || from <= to, { error: REJECTION_MESSAGES.inverted_range('from'), path: ['from'] });
|
|
70
90
|
/**
|
|
71
91
|
* An id the fetchers put in a URL.
|
|
72
92
|
* Rejected before any request is made, and yielded unchanged otherwise.
|
|
73
93
|
*/
|
|
74
94
|
const safeParam = rawParam.check(rejects('unsafe', (value) => !value || SAFE_PATTERN.test(value)));
|
|
95
|
+
/**
|
|
96
|
+
* A GitHub login, stricter than `safeParam`: no leading, trailing or doubled hyphen.
|
|
97
|
+
* Rejected here so a malformed one is a permanent error rather than the NOT_FOUND GitHub answers.
|
|
98
|
+
*/
|
|
99
|
+
const usernameParam = rawParam.check(rejects('username', (value) => !value || GITHUB_USERNAME_PATTERN.test(value)));
|
|
75
100
|
/**
|
|
76
101
|
* A comma-separated list of ids, checked before it is split.
|
|
77
102
|
* The safe pattern allows the commas, so one check covers the whole list.
|
|
@@ -87,7 +112,6 @@ const localeParam = z.pipe(rawParam.check(rejects('locale', (value) => !value ||
|
|
|
87
112
|
/**
|
|
88
113
|
* A param the card only renders as one of a fixed set of values.
|
|
89
114
|
*
|
|
90
|
-
* @param values The accepted values, as the card that renders them declares them.
|
|
91
115
|
* @returns Schema yielding one of `values`, or `undefined` when absent.
|
|
92
116
|
*/
|
|
93
117
|
const enumParam = (values) => rawParam.check(rejects('enum', (value) => values.includes(value)));
|
|
@@ -108,11 +132,10 @@ const colorParamsSchema = z.object(Object.fromEntries(COLOR_PARAM_KEYS.map((key)
|
|
|
108
132
|
* Every rejection is the query's fault, so they share one code
|
|
109
133
|
* and differ only in the message the check already worded.
|
|
110
134
|
*
|
|
111
|
-
* @param error What the schema rejected.
|
|
112
135
|
* @returns The failure, ready to render.
|
|
113
136
|
*/
|
|
114
137
|
const toCardError = (error) => {
|
|
115
|
-
const issue = error.issues
|
|
138
|
+
const [issue] = error.issues;
|
|
116
139
|
return CardError.invalidParam(String(issue?.path[0] ?? ''), issue?.message ?? 'Invalid input');
|
|
117
140
|
};
|
|
118
141
|
/**
|
|
@@ -121,10 +144,9 @@ const toCardError = (error) => {
|
|
|
121
144
|
* Only the first rejection is reported:
|
|
122
145
|
* the error card has room for one line.
|
|
123
146
|
*
|
|
124
|
-
* @param schema The endpoint's schema.
|
|
125
|
-
* @param query Raw query params.
|
|
126
|
-
* @returns The parsed params.
|
|
127
147
|
* @throws {CardError} When the schema rejects a param.
|
|
148
|
+
*
|
|
149
|
+
* @returns The parsed params.
|
|
128
150
|
*/
|
|
129
151
|
const parseParams = (schema, query) => {
|
|
130
152
|
const result = z.safeParse(schema, query);
|
|
@@ -137,9 +159,9 @@ const parseParams = (schema, query) => {
|
|
|
137
159
|
* The color params, validated.
|
|
138
160
|
* Split from the endpoint's own schema because a rejected color cannot then be used to render its own error card.
|
|
139
161
|
*
|
|
140
|
-
* @param query Raw query params.
|
|
141
|
-
* @returns The color params.
|
|
142
162
|
* @throws {CardError} When a param does not hold a color or a gradient.
|
|
163
|
+
*
|
|
164
|
+
* @returns The color params.
|
|
143
165
|
*/
|
|
144
166
|
const parseColorParams = (query) => parseParams(colorParamsSchema, query);
|
|
145
|
-
export { booleanParam, enumParam, listParam, localeParam, looseIntParam, numberParam, parseColorParams, parseParams, rawParam, safeListParam, safeParam,
|
|
167
|
+
export { booleanParam, enumParam, fromParam, listParam, ORDERED_RANGE, localeParam, looseIntParam, numberParam, parseColorParams, parseParams, rawParam, safeListParam, safeParam, toParam, usernameParam, };
|
package/build/api/pin.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const
|
|
2
|
+
/**
|
|
3
|
+
* The card, and the values each of its options accepts, keyed by the option's own name.
|
|
4
|
+
* A UI reads them off the function it calls: `pin.OPTIONS.show`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const pin: ((query: import("./params.ts").ApiQuery<z.ZodMiniObject<{
|
|
7
7
|
username: z.ZodMiniType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
|
|
8
8
|
repo: z.ZodMiniType<string | undefined, string | undefined, z.core.$ZodTypeInternals<string | undefined, string | undefined>>;
|
|
9
9
|
hide_border: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<boolean | undefined, string | undefined>>;
|
|
@@ -18,30 +18,10 @@ declare const pinQuery: z.ZodMiniObject<{
|
|
|
18
18
|
locale: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<string | undefined, string | undefined>>;
|
|
19
19
|
border_radius: z.ZodMiniType<number | undefined, string | undefined, z.core.$ZodTypeInternals<number | undefined, string | undefined>>;
|
|
20
20
|
description_lines_count: z.ZodMiniPipe<z.ZodMiniOptional<z.ZodMiniString<string>>, z.ZodMiniTransform<number | undefined, string | undefined>>;
|
|
21
|
-
}, z.core.$strip
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
28
|
-
* @param query.username GitHub username the repository belongs to.
|
|
29
|
-
* @param query.repo Repository name.
|
|
30
|
-
* @param query.hide_border Whether to hide the card border.
|
|
31
|
-
* @param query.card_width Card width.
|
|
32
|
-
* @param query.show_owner Whether to show the repository owner.
|
|
33
|
-
* @param query.browser_rendering Whether the browser wraps the description text.
|
|
34
|
-
* @param query.show Comma-separated extra stats to show.
|
|
35
|
-
* @param query.show_icons Whether to show the stat icons.
|
|
36
|
-
* @param query.number_format How numbers are abbreviated.
|
|
37
|
-
* @param query.text_bold Whether the stat values are bold.
|
|
38
|
-
* @param query.line_height Line height between the stats.
|
|
39
|
-
* @param query.locale Language the card is rendered in.
|
|
40
|
-
* @param query.border_radius Card border radius.
|
|
41
|
-
* @param query.description_lines_count Lines the description is wrapped to.
|
|
42
|
-
* @param config Deployment config supplying the PAT pool.
|
|
43
|
-
* @returns The rendered card, or a rendered error.
|
|
44
|
-
*/
|
|
45
|
-
export declare const pin: (query: PinApiQuery, config: CardConfig) => Promise<ApiResult>;
|
|
46
|
-
export {};
|
|
21
|
+
}, z.core.$strip>>, config: import("./index.ts").CardConfig) => Promise<import("./api-result.ts").ApiResult>) & {
|
|
22
|
+
OPTIONS: {
|
|
23
|
+
show: readonly ["prs_authored", "prs_commented", "prs_reviewed", "issues_authored", "issues_commented"];
|
|
24
|
+
number_format: readonly ["short", "long"];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
47
27
|
//# sourceMappingURL=pin.d.ts.map
|
package/build/api/pin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pin.d.ts","sourceRoot":"","sources":["../../src/api/pin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"pin.d.ts","sourceRoot":"","sources":["../../src/api/pin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AA8F9B;;;GAGG;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;CAAgE,CAAC"}
|