( c: Context<AppEnv>, path: string, schema: z.ZodType<T>, notFoundMessage?: string, )
| 68 | }; |
| 69 | |
| 70 | export const readRegistryView = async <T>( |
| 71 | c: Context<AppEnv>, |
| 72 | path: string, |
| 73 | schema: z.ZodType<T>, |
| 74 | notFoundMessage?: string, |
| 75 | ): Promise<T> => { |
| 76 | const revision = await getCurrentRevision(c); |
| 77 | const object = await c.env.REGISTRY.get(`snapshots/${revision}/api/${path}`); |
| 78 | if (!object) { |
| 79 | if (notFoundMessage) { |
| 80 | throw notFound(notFoundMessage); |
| 81 | } |
| 82 | throw badGateway('Bad Gateway. Registry snapshot is incomplete.'); |
| 83 | } |
| 84 | |
| 85 | const parsed = schema.safeParse(await object.json()); |
| 86 | if (!parsed.success) { |
| 87 | throw badGateway('Bad Gateway. Registry snapshot view is invalid.'); |
| 88 | } |
| 89 | |
| 90 | return parsed.data; |
| 91 | }; |
| 92 | |
| 93 | export const getRegistrySource = async ( |
| 94 | c: Context<AppEnv>, |
no test coverage detected