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

Function updateVersion

api/metadata/src/stats/update.ts:8–37  ·  view source on GitHub ↗
(
	id: string,
	isVariable: boolean,
	env: Env,
	ctx: ExecutionContext,
)

Source from the content-addressed store, hash-verified

6import { getAvailableVersions } from './util';
7
8export const updateVersion = async (
9 id: string,
10 isVariable: boolean,
11 env: Env,
12 ctx: ExecutionContext,
13) => {
14 const [staticVal, variable] = await Promise.all([
15 getAvailableVersions(id),
16 isVariable ? getAvailableVersions(id, isVariable) : undefined,
17 ]);
18
19 if (!staticVal || staticVal.length === 0) {
20 throw new StatusError(404, `Not found. No versions found for ${id}.`);
21 }
22
23 const resp: VersionResponse = {
24 latest: staticVal[0],
25 static: staticVal,
26 ...(variable && { latestVariable: variable[0], variable }),
27 };
28
29 // Add to KV cache
30 ctx.waitUntil(
31 env.VERSIONS.put(METADATA_KEYS.version(id), JSON.stringify(resp), {
32 expirationTtl: KV_TTL, // We want to expire these as we can't cron trigger these yet
33 }),
34 );
35
36 return resp;
37};
38
39export const updatePackageStatAll = async (env: Env, ctx: ExecutionContext) => {
40 const [npmMonthlyResp, npmTotalResp, jsDelivrMonthlyResp, jsDelivrTotalResp] =

Callers 1

getVersionFunction · 0.90

Calls 3

getAvailableVersionsFunction · 0.90
waitUntilMethod · 0.65
putMethod · 0.65

Tested by

no test coverage detected