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

Function readRegistryView

api/worker/src/features/registry/handler.ts:70–91  ·  view source on GitHub ↗
(
	c: Context<AppEnv>,
	path: string,
	schema: z.ZodType<T>,
	notFoundMessage?: string,
)

Source from the content-addressed store, hash-verified

68};
69
70export 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
93export const getRegistrySource = async (
94 c: Context<AppEnv>,

Callers 1

getFontOpenGraphImageFunction · 0.90

Calls 6

notFoundFunction · 0.90
badGatewayFunction · 0.90
getCurrentRevisionFunction · 0.85
safeParseMethod · 0.80
getMethod · 0.65
jsonMethod · 0.65

Tested by

no test coverage detected