( id: string, isVariable: boolean, env: Env, ctx: ExecutionContext, )
| 6 | import { getAvailableVersions } from './util'; |
| 7 | |
| 8 | export 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 | |
| 39 | export const updatePackageStatAll = async (env: Env, ctx: ExecutionContext) => { |
| 40 | const [npmMonthlyResp, npmTotalResp, jsDelivrMonthlyResp, jsDelivrTotalResp] = |
no test coverage detected