@chtc/web-components 2.0.4 → 2.0.5
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/Release/utils/getReleases.d.ts +2 -2
- package/Release/utils/getReleases.d.ts.map +1 -1
- package/Release/utils/getReleases.js +19 -1
- package/Release/utils/getReleases.js.map +1 -1
- package/github/getAllPages.d.ts +17 -2
- package/github/getAllPages.d.ts.map +1 -1
- package/github/getAllPages.js +18 -5
- package/github/getAllPages.js.map +1 -1
- package/github/getRawFile.d.ts +3 -0
- package/github/getRawFile.d.ts.map +1 -1
- package/github/getRawFile.js +12 -4
- package/github/getRawFile.js.map +1 -1
- package/github/getTree.d.ts +3 -0
- package/github/getTree.d.ts.map +1 -1
- package/github/getTree.js +11 -3
- package/github/getTree.js.map +1 -1
- package/github/index.d.ts +2 -1
- package/github/index.d.ts.map +1 -1
- package/github/index.js +1 -1
- package/github/index.js.map +1 -1
- package/github/memo.d.ts +25 -0
- package/github/memo.d.ts.map +1 -0
- package/github/memo.js +49 -0
- package/github/memo.js.map +1 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GetAllPagesOptions } from "../../github/getAllPages";
|
|
2
2
|
import type { GitHubRelease } from "../types";
|
|
3
|
-
export interface GetReleasesOptions extends
|
|
3
|
+
export interface GetReleasesOptions extends GetAllPagesOptions {
|
|
4
4
|
/** Include release candidates and other prereleases. Defaults to false. */
|
|
5
5
|
includePrereleases?: boolean;
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getReleases.d.ts","sourceRoot":"","sources":["../../../src/Release/utils/getReleases.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"getReleases.d.ts","sourceRoot":"","sources":["../../../src/Release/utils/getReleases.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAqBD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,aAAa,EAAE,CAAC,CAe1B;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { getAllPages } from "../../github/getAllPages";
|
|
2
2
|
/** Tags like `v7.18.0-rc.0` that GitHub may or may not have flagged as prerelease. */
|
|
3
3
|
const RELEASE_CANDIDATE = /-rc(\.|\d|$)/i;
|
|
4
|
+
/**
|
|
5
|
+
* Releases per request.
|
|
6
|
+
*
|
|
7
|
+
* Release objects are far larger than they look: GitHub inlines the full asset
|
|
8
|
+
* list, and each asset carries a complete uploader object. For a project that
|
|
9
|
+
* ships a binary per platform that runs to roughly 80KB per release, so
|
|
10
|
+
* GitHub's maximum of 100 produces a 7MB response — well over the 2MB ceiling
|
|
11
|
+
* on Next.js's data cache, which means it is never cached and every page that
|
|
12
|
+
* lists releases re-downloads the lot.
|
|
13
|
+
*
|
|
14
|
+
* Fifteen holds the densest page near 1.2MB. That leaves room for the asset
|
|
15
|
+
* list to keep growing: at twenty, measured pages already reached 1.6MB, and
|
|
16
|
+
* crossing the ceiling again is silent — the only symptom is a slow build.
|
|
17
|
+
*/
|
|
18
|
+
const RELEASES_PER_PAGE = 15;
|
|
4
19
|
/**
|
|
5
20
|
* Every release of a repository, as GitHub orders them (newest first).
|
|
6
21
|
* Drafts are always dropped; prereleases are dropped unless asked for.
|
|
@@ -8,7 +23,10 @@ const RELEASE_CANDIDATE = /-rc(\.|\d|$)/i;
|
|
|
8
23
|
export async function getReleases(organization, repo, options = {}) {
|
|
9
24
|
const { includePrereleases = false, ...fetchOptions } = options;
|
|
10
25
|
const url = `https://api.github.com/repos/${organization}/${repo}/releases`;
|
|
11
|
-
const releases = await getAllPages(url,
|
|
26
|
+
const releases = await getAllPages(url, {
|
|
27
|
+
perPage: RELEASES_PER_PAGE,
|
|
28
|
+
...fetchOptions,
|
|
29
|
+
});
|
|
12
30
|
return releases.filter((release) => !release.draft &&
|
|
13
31
|
(includePrereleases ||
|
|
14
32
|
(!release.prerelease && !RELEASE_CANDIDATE.test(release.tag_name))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getReleases.js","sourceRoot":"","sources":["../../../src/Release/utils/getReleases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AASvD,sFAAsF;AACtF,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,YAAoB,EACpB,IAAY,EACZ,UAA8B,EAAE;IAEhC,MAAM,EAAE,kBAAkB,GAAG,KAAK,EAAE,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,GAAG,GAAG,gCAAgC,YAAY,IAAI,IAAI,WAAW,CAAC;IAE5E,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAgB,GAAG,EAAE,YAAY,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"getReleases.js","sourceRoot":"","sources":["../../../src/Release/utils/getReleases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AASvD,sFAAsF;AACtF,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,YAAoB,EACpB,IAAY,EACZ,UAA8B,EAAE;IAEhC,MAAM,EAAE,kBAAkB,GAAG,KAAK,EAAE,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,GAAG,GAAG,gCAAgC,YAAY,IAAI,IAAI,WAAW,CAAC;IAE5E,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAgB,GAAG,EAAE;QACrD,OAAO,EAAE,iBAAiB;QAC1B,GAAG,YAAY;KAChB,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,OAAO,EAAE,EAAE,CACV,CAAC,OAAO,CAAC,KAAK;QACd,CAAC,kBAAkB;YACjB,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CACxE,CAAC;AACJ,CAAC;AAED,eAAe,WAAW,CAAC"}
|
package/github/getAllPages.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import type { GitHubFetchOptions } from "./types";
|
|
2
|
+
/** GitHub's maximum, and the right default for endpoints with small items. */
|
|
3
|
+
export declare const DEFAULT_PER_PAGE = 100;
|
|
4
|
+
export interface GetAllPagesOptions extends GitHubFetchOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Items per request, up to GitHub's maximum of 100. Defaults to 100.
|
|
7
|
+
*
|
|
8
|
+
* Worth lowering for endpoints whose items are large: Next.js refuses to
|
|
9
|
+
* store any response over 2MB in its data cache, so a page that crosses
|
|
10
|
+
* that line is re-fetched by every route that asks for it. Smaller pages
|
|
11
|
+
* mean a few more requests on a cold cache and far fewer on a warm one.
|
|
12
|
+
*/
|
|
13
|
+
perPage?: number;
|
|
14
|
+
}
|
|
2
15
|
/**
|
|
3
16
|
* Follow a paginated GitHub API list endpoint to the end and return every
|
|
4
17
|
* item as one array.
|
|
5
18
|
*
|
|
6
19
|
* Pagination follows the `Link: <url>; rel="next"` response header, so any
|
|
7
|
-
* query parameters on `apiUrl` are preserved across pages.
|
|
20
|
+
* query parameters on `apiUrl` are preserved across pages. Results are
|
|
21
|
+
* memoized per process for the revalidate window; callers get a fresh array
|
|
22
|
+
* each time, so sorting or splicing it is safe.
|
|
8
23
|
*/
|
|
9
|
-
export declare function getAllPages<T = unknown>(apiUrl: string | URL, options?:
|
|
24
|
+
export declare function getAllPages<T = unknown>(apiUrl: string | URL, options?: GetAllPagesOptions): Promise<T[]>;
|
|
10
25
|
export default getAllPages;
|
|
11
26
|
//# sourceMappingURL=getAllPages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAllPages.d.ts","sourceRoot":"","sources":["../../src/github/getAllPages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getAllPages.d.ts","sourceRoot":"","sources":["../../src/github/getAllPages.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,OAAO,EAC3C,MAAM,EAAE,MAAM,GAAG,GAAG,EACpB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAiBd;AA4BD,eAAe,WAAW,CAAC"}
|
package/github/getAllPages.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
import { githubFetch } from "./githubFetch";
|
|
1
|
+
import { githubFetch, GITHUB_REVALIDATE } from "./githubFetch";
|
|
2
|
+
import { memoize } from "./memo";
|
|
3
|
+
/** GitHub's maximum, and the right default for endpoints with small items. */
|
|
4
|
+
export const DEFAULT_PER_PAGE = 100;
|
|
2
5
|
/**
|
|
3
6
|
* Follow a paginated GitHub API list endpoint to the end and return every
|
|
4
7
|
* item as one array.
|
|
5
8
|
*
|
|
6
9
|
* Pagination follows the `Link: <url>; rel="next"` response header, so any
|
|
7
|
-
* query parameters on `apiUrl` are preserved across pages.
|
|
10
|
+
* query parameters on `apiUrl` are preserved across pages. Results are
|
|
11
|
+
* memoized per process for the revalidate window; callers get a fresh array
|
|
12
|
+
* each time, so sorting or splicing it is safe.
|
|
8
13
|
*/
|
|
9
14
|
export async function getAllPages(apiUrl, options) {
|
|
10
|
-
|
|
15
|
+
var _a, _b;
|
|
11
16
|
const first = new URL(apiUrl);
|
|
12
17
|
if (!first.searchParams.has("per_page")) {
|
|
13
|
-
first.searchParams.set("per_page",
|
|
18
|
+
first.searchParams.set("per_page", String((_a = options === null || options === void 0 ? void 0 : options.perPage) !== null && _a !== void 0 ? _a : DEFAULT_PER_PAGE));
|
|
14
19
|
}
|
|
15
|
-
|
|
20
|
+
const url = first.toString();
|
|
21
|
+
const revalidate = (_b = options === null || options === void 0 ? void 0 : options.revalidate) !== null && _b !== void 0 ? _b : GITHUB_REVALIDATE;
|
|
22
|
+
const items = await memoize(`pages:${url}`, revalidate, () => collect(url, options));
|
|
23
|
+
return [...items];
|
|
24
|
+
}
|
|
25
|
+
/** Walk every page of a list endpoint, starting from a prepared URL. */
|
|
26
|
+
async function collect(start, options) {
|
|
27
|
+
const results = [];
|
|
28
|
+
let url = start;
|
|
16
29
|
while (url) {
|
|
17
30
|
const res = await githubFetch(url, options);
|
|
18
31
|
results.push(...(await res.json()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAllPages.js","sourceRoot":"","sources":["../../src/github/getAllPages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"getAllPages.js","sourceRoot":"","sources":["../../src/github/getAllPages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAcpC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAoB,EACpB,OAA4B;;IAE5B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QACxC,KAAK,CAAC,YAAY,CAAC,GAAG,CACpB,UAAU,EACV,MAAM,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,gBAAgB,CAAC,CAC7C,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,iBAAiB,CAAC;IAE5D,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,SAAS,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAC3D,OAAO,CAAI,GAAG,EAAE,OAAO,CAAC,CACzB,CAAC;IAEF,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,wEAAwE;AACxE,KAAK,UAAU,OAAO,CACpB,KAAa,EACb,OAA4B;IAE5B,MAAM,OAAO,GAAQ,EAAE,CAAC;IAExB,IAAI,GAAG,GAAuB,KAAK,CAAC;IACpC,OAAO,GAAG,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC5C,OAAO,CAAC,IAAI,CAAC,GAAI,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAS,CAAC,CAAC;QAC7C,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,qEAAqE;AACrE,SAAS,cAAc,CAAC,UAAyB;;IAC/C,IAAI,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IAClC,MAAM,IAAI,GAAG,UAAU;SACpB,KAAK,CAAC,GAAG,CAAC;SACV,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,OAAO,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAC,WAAW,CAAC,0CAAG,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,eAAe,WAAW,CAAC"}
|
package/github/getRawFile.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { GitHubFetchOptions } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* The text contents of one file in a branch.
|
|
4
|
+
*
|
|
5
|
+
* Memoized per process for the revalidate window: an index page and the detail
|
|
6
|
+
* page for the same article both read the same file.
|
|
4
7
|
*/
|
|
5
8
|
export declare function getRawFile(organization: string, repo: string, path: string, branch: string, options?: GitHubFetchOptions): Promise<string>;
|
|
6
9
|
export default getRawFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRawFile.d.ts","sourceRoot":"","sources":["../../src/github/getRawFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getRawFile.d.ts","sourceRoot":"","sources":["../../src/github/getRawFile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED,eAAe,UAAU,CAAC"}
|
package/github/getRawFile.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { githubFetch } from "./githubFetch";
|
|
1
|
+
import { githubFetch, GITHUB_REVALIDATE } from "./githubFetch";
|
|
2
|
+
import { memoize } from "./memo";
|
|
2
3
|
/**
|
|
3
4
|
* The text contents of one file in a branch.
|
|
5
|
+
*
|
|
6
|
+
* Memoized per process for the revalidate window: an index page and the detail
|
|
7
|
+
* page for the same article both read the same file.
|
|
4
8
|
*/
|
|
5
9
|
export async function getRawFile(organization, repo, path, branch, options) {
|
|
10
|
+
var _a;
|
|
6
11
|
const url = `https://raw.githubusercontent.com/${organization}/${repo}/${branch}/${path}`;
|
|
7
|
-
const
|
|
8
|
-
|
|
12
|
+
const revalidate = (_a = options === null || options === void 0 ? void 0 : options.revalidate) !== null && _a !== void 0 ? _a : GITHUB_REVALIDATE;
|
|
13
|
+
return memoize(`raw:${url}`, revalidate, async () => {
|
|
14
|
+
const res = await githubFetch(url, options, {
|
|
15
|
+
headers: { accept: "application/vnd.github.raw" },
|
|
16
|
+
});
|
|
17
|
+
return await res.text();
|
|
9
18
|
});
|
|
10
|
-
return await res.text();
|
|
11
19
|
}
|
|
12
20
|
export default getRawFile;
|
|
13
21
|
//# sourceMappingURL=getRawFile.js.map
|
package/github/getRawFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRawFile.js","sourceRoot":"","sources":["../../src/github/getRawFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"getRawFile.js","sourceRoot":"","sources":["../../src/github/getRawFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,YAAoB,EACpB,IAAY,EACZ,IAAY,EACZ,MAAc,EACd,OAA4B;;IAE5B,MAAM,GAAG,GAAG,qCAAqC,YAAY,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;IAC1F,MAAM,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,iBAAiB,CAAC;IAE5D,OAAO,OAAO,CAAC,OAAO,GAAG,EAAE,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE;YAC1C,OAAO,EAAE,EAAE,MAAM,EAAE,4BAA4B,EAAE;SAClD,CAAC,CAAC;QACH,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,eAAe,UAAU,CAAC"}
|
package/github/getTree.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { GitHubFetchOptions, GitTree } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* The full recursive file tree of a branch.
|
|
4
|
+
*
|
|
5
|
+
* Memoized per process for the revalidate window, since every page built from
|
|
6
|
+
* a content repo starts by asking for the same tree.
|
|
4
7
|
*/
|
|
5
8
|
export declare function getTree(organization: string, repo: string, branch: string, options?: GitHubFetchOptions): Promise<GitTree>;
|
|
6
9
|
export default getTree;
|
package/github/getTree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTree.d.ts","sourceRoot":"","sources":["../../src/github/getTree.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTree.d.ts","sourceRoot":"","sources":["../../src/github/getTree.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;;GAKG;AACH,wBAAsB,OAAO,CAC3B,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED,eAAe,OAAO,CAAC"}
|
package/github/getTree.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { githubFetch } from "./githubFetch";
|
|
1
|
+
import { githubFetch, GITHUB_REVALIDATE } from "./githubFetch";
|
|
2
|
+
import { memoize } from "./memo";
|
|
2
3
|
/**
|
|
3
4
|
* The full recursive file tree of a branch.
|
|
5
|
+
*
|
|
6
|
+
* Memoized per process for the revalidate window, since every page built from
|
|
7
|
+
* a content repo starts by asking for the same tree.
|
|
4
8
|
*/
|
|
5
9
|
export async function getTree(organization, repo, branch, options) {
|
|
10
|
+
var _a;
|
|
6
11
|
const url = `https://api.github.com/repos/${organization}/${repo}/git/trees/${branch}?recursive=1`;
|
|
7
|
-
const
|
|
8
|
-
return (
|
|
12
|
+
const revalidate = (_a = options === null || options === void 0 ? void 0 : options.revalidate) !== null && _a !== void 0 ? _a : GITHUB_REVALIDATE;
|
|
13
|
+
return memoize(`tree:${url}`, revalidate, async () => {
|
|
14
|
+
const res = await githubFetch(url, options);
|
|
15
|
+
return (await res.json());
|
|
16
|
+
});
|
|
9
17
|
}
|
|
10
18
|
export default getTree;
|
|
11
19
|
//# sourceMappingURL=getTree.js.map
|
package/github/getTree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTree.js","sourceRoot":"","sources":["../../src/github/getTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"getTree.js","sourceRoot":"","sources":["../../src/github/getTree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,YAAoB,EACpB,IAAY,EACZ,MAAc,EACd,OAA4B;;IAE5B,MAAM,GAAG,GAAG,gCAAgC,YAAY,IAAI,IAAI,cAAc,MAAM,cAAc,CAAC;IACnG,MAAM,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,iBAAiB,CAAC;IAE5D,OAAO,OAAO,CAAC,QAAQ,GAAG,EAAE,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE;QACnD,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC5C,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAY,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,eAAe,OAAO,CAAC"}
|
package/github/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ export { githubFetch, GITHUB_REVALIDATE } from "./githubFetch";
|
|
|
2
2
|
export { getTree } from "./getTree";
|
|
3
3
|
export { getRepoPaths } from "./getRepoPaths";
|
|
4
4
|
export { getRawFile } from "./getRawFile";
|
|
5
|
-
export { getAllPages } from "./getAllPages";
|
|
5
|
+
export { getAllPages, DEFAULT_PER_PAGE } from "./getAllPages";
|
|
6
|
+
export type { GetAllPagesOptions } from "./getAllPages";
|
|
6
7
|
export type { GitHubFetchOptions, GitTree, GitTreeItem } from "./types";
|
|
7
8
|
export * from "../Release";
|
|
8
9
|
export * from "../Security";
|
package/github/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/github/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/github/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9D,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
package/github/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { githubFetch, GITHUB_REVALIDATE } from "./githubFetch";
|
|
|
2
2
|
export { getTree } from "./getTree";
|
|
3
3
|
export { getRepoPaths } from "./getRepoPaths";
|
|
4
4
|
export { getRawFile } from "./getRawFile";
|
|
5
|
-
export { getAllPages } from "./getAllPages";
|
|
5
|
+
export { getAllPages, DEFAULT_PER_PAGE } from "./getAllPages";
|
|
6
6
|
export * from "../Release";
|
|
7
7
|
export * from "../Security";
|
|
8
8
|
export * from "../Milestone";
|
package/github/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/github/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/github/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAI9D,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
package/github/memo.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local memo for GitHub responses.
|
|
3
|
+
*
|
|
4
|
+
* Next.js's data cache already de-duplicates identical fetches, but it is
|
|
5
|
+
* skipped entirely for responses over 2MB. A static export that renders
|
|
6
|
+
* hundreds of pages from one large list endpoint therefore re-requests that
|
|
7
|
+
* endpoint once per page. This keeps a single in-flight promise per request
|
|
8
|
+
* for the length of the revalidate window, so each build makes the request
|
|
9
|
+
* once per worker process instead of once per page.
|
|
10
|
+
*
|
|
11
|
+
* Entries expire after `ttlSeconds` so a long-running `next dev` server still
|
|
12
|
+
* picks up new content on the same schedule as the data cache.
|
|
13
|
+
*
|
|
14
|
+
* Keys are the request URL only, so a process that talks to GitHub as more
|
|
15
|
+
* than one identity would share entries between them. Every getter in this
|
|
16
|
+
* library reads one token from the environment, so that does not arise here.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Run `load` once per `key` per TTL window, sharing the promise with every
|
|
20
|
+
* caller that asks in the meantime. A `ttlSeconds` of zero or less disables
|
|
21
|
+
* memoization, matching `revalidate: 0`'s "always fetch fresh".
|
|
22
|
+
*/
|
|
23
|
+
export declare function memoize<T>(key: string, ttlSeconds: number, load: () => Promise<T>): Promise<T>;
|
|
24
|
+
export default memoize;
|
|
25
|
+
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/github/memo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAgBH;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAiBZ;AAED,eAAe,OAAO,CAAC"}
|
package/github/memo.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local memo for GitHub responses.
|
|
3
|
+
*
|
|
4
|
+
* Next.js's data cache already de-duplicates identical fetches, but it is
|
|
5
|
+
* skipped entirely for responses over 2MB. A static export that renders
|
|
6
|
+
* hundreds of pages from one large list endpoint therefore re-requests that
|
|
7
|
+
* endpoint once per page. This keeps a single in-flight promise per request
|
|
8
|
+
* for the length of the revalidate window, so each build makes the request
|
|
9
|
+
* once per worker process instead of once per page.
|
|
10
|
+
*
|
|
11
|
+
* Entries expire after `ttlSeconds` so a long-running `next dev` server still
|
|
12
|
+
* picks up new content on the same schedule as the data cache.
|
|
13
|
+
*
|
|
14
|
+
* Keys are the request URL only, so a process that talks to GitHub as more
|
|
15
|
+
* than one identity would share entries between them. Every getter in this
|
|
16
|
+
* library reads one token from the environment, so that does not arise here.
|
|
17
|
+
*/
|
|
18
|
+
const entries = new Map();
|
|
19
|
+
/** Drop expired entries so a long dev session doesn't grow the map forever. */
|
|
20
|
+
function prune(now) {
|
|
21
|
+
for (const [key, entry] of entries) {
|
|
22
|
+
if (entry.expires <= now)
|
|
23
|
+
entries.delete(key);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Run `load` once per `key` per TTL window, sharing the promise with every
|
|
28
|
+
* caller that asks in the meantime. A `ttlSeconds` of zero or less disables
|
|
29
|
+
* memoization, matching `revalidate: 0`'s "always fetch fresh".
|
|
30
|
+
*/
|
|
31
|
+
export function memoize(key, ttlSeconds, load) {
|
|
32
|
+
if (ttlSeconds <= 0)
|
|
33
|
+
return load();
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
const hit = entries.get(key);
|
|
36
|
+
if (hit && hit.expires > now)
|
|
37
|
+
return hit.value;
|
|
38
|
+
// A rejected request must not be remembered, or one blip poisons the build.
|
|
39
|
+
const value = load().catch((error) => {
|
|
40
|
+
entries.delete(key);
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
if (entries.size > 256)
|
|
44
|
+
prune(now);
|
|
45
|
+
entries.set(key, { expires: now + ttlSeconds * 1000, value });
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
export default memoize;
|
|
49
|
+
//# sourceMappingURL=memo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memo.js","sourceRoot":"","sources":["../../src/github/memo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;AAEzC,+EAA+E;AAC/E,SAAS,KAAK,CAAC,GAAW;IACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,KAAK,CAAC,OAAO,IAAI,GAAG;YAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACrB,GAAW,EACX,UAAkB,EAClB,IAAsB;IAEtB,IAAI,UAAU,IAAI,CAAC;QAAE,OAAO,IAAI,EAAE,CAAC;IAEnC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,GAAG;QAAE,OAAO,GAAG,CAAC,KAAmB,CAAC;IAE7D,4EAA4E;IAC5E,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACnC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,IAAI,GAAG,GAAG;QAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,GAAG,UAAU,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAE9D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/types.ts","../src/charts/index.ts","../src/content/index.ts","../src/github/getAllPages.ts","../src/github/getRawFile.ts","../src/github/getRepoPaths.ts","../src/github/getTree.ts","../src/github/githubFetch.ts","../src/github/index.ts","../src/github/types.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/index.ts","../src/types.ts","../src/charts/index.ts","../src/content/index.ts","../src/github/getAllPages.ts","../src/github/getRawFile.ts","../src/github/getRepoPaths.ts","../src/github/getTree.ts","../src/github/githubFetch.ts","../src/github/index.ts","../src/github/memo.ts","../src/github/types.ts"],"version":"5.9.3"}
|