1import type { AsyncWorkerEnv } from "./stack.ts";
2
3// Async (non-Effect) Worker handler that echoes its env bindings back as
4// JSON so the test can assert that every supported `WorkerBindingResource`
5// shape (string, number, boolean, null, array, object, Redacted<string>,
6// Redacted<Json>, Config<string>, Config<number>) round-trips end-to-end.
7export default {
8 fetch: async (_request: Request, env: AsyncWorkerEnv) => {
9 return new Response(
10 JSON.stringify({
11 STR: env.STR,
12 NUM: env.NUM,
13 BOOL: env.BOOL,
14 NULL: env.NULL,
15 OBJ: env.OBJ,
16 ARR: env.ARR,
17 OUTPUT_STR: env.OUTPUT_STR,
18 RANDOM_IS_HEX: /^[0-9a-f]{64}$/.test(env.RANDOM),
19 SECRET_STR: env.SECRET_STR,
20 // Redacted<Json> is JSON-stringified into secret_text on the way in,
21 // so the async runtime sees a string here. Parse it back so the
22 // test can compare the structured value.
23 SECRET_JSON:
24 typeof env.SECRET_JSON === "string"
25 ? JSON.parse(env.SECRET_JSON)
26 : env.SECRET_JSON,
27 CONFIG_STR: env.CONFIG_STR,
28 CONFIG_NUM: env.CONFIG_NUM,
29 CONFIG_REDACTED: env.CONFIG_REDACTED,
30 VERSION_METADATA: env.CF_VERSION_METADATA,
31 }),
32 { headers: { "content-type": "application/json" } },
33 );
34 },
35};