MCPcopy Create free account
hub / github.com/fontsource/fontsource / updatePackageStatAll

Function updatePackageStatAll

api/metadata/src/stats/update.ts:39–182  ·  view source on GitHub ↗
(env: Env, ctx: ExecutionContext)

Source from the content-addressed store, hash-verified

37};
38
39export const updatePackageStatAll = async (env: Env, ctx: ExecutionContext) => {
40 const [npmMonthlyResp, npmTotalResp, jsDelivrMonthlyResp, jsDelivrTotalResp] =
41 await Promise.all([
42 fetch(
43 'https://raw.githubusercontent.com/fontsource/download-stat-aggregator/main/data/lastMonthPopular.json',
44 ),
45 fetch(
46 'https://raw.githubusercontent.com/fontsource/download-stat-aggregator/main/data/totalPopular.json',
47 ),
48 fetch(
49 'https://raw.githubusercontent.com/fontsource/download-stat-aggregator/main/data/jsDelivrMonthPopular.json',
50 ),
51 fetch(
52 'https://raw.githubusercontent.com/fontsource/download-stat-aggregator/main/data/jsDelivrTotalPopular.json',
53 ),
54 ]);
55
56 const [npmMonthData, npmTotalData, jsDelivrMonthData, jsDelivrTotalData] =
57 (await Promise.all([
58 npmMonthlyResp.json(),
59 npmTotalResp.json(),
60 jsDelivrMonthlyResp.json(),
61 jsDelivrTotalResp.json(),
62 ])) as [
63 Record<string, number>,
64 Record<string, number>,
65 Record<string, number>,
66 Record<string, number>,
67 ];
68
69 const stats: StatsResponseAllRecord = {};
70
71 for (const packageName of Object.keys(npmMonthData)) {
72 // Check for scoped packages
73 if (packageName.startsWith('@')) {
74 const [type, id] = packageName.split('/');
75 const isVariable = type === '@fontsource-variable';
76
77 // Initialise stats object
78 stats[id] = stats[id] || {
79 total: {
80 npmDownloadMonthly: 0,
81 npmDownloadTotal: 0,
82 jsDelivrHitsMonthly: 0,
83 jsDelivrHitsTotal: 0,
84 },
85 static: {
86 npmDownloadMonthly: 0,
87 npmDownloadTotal: 0,
88 jsDelivrHitsMonthly: 0,
89 jsDelivrHitsTotal: 0,
90 },
91 variable: isVariable
92 ? {
93 npmDownloadMonthly: 0,
94 npmDownloadTotal: 0,
95 jsDelivrHitsMonthly: 0,
96 jsDelivrHitsTotal: 0,

Callers 2

scheduledFunction · 0.90
getPackageStatAllFunction · 0.90

Calls 5

jsonMethod · 0.80
replaceMethod · 0.65
waitUntilMethod · 0.65
putMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected