opencode/packages/console/resource/resource.cloudflare.ts

25 lines
759 B
TypeScript
Raw Permalink Normal View History

2025-08-30 12:58:22 +08:00
import { env } from "cloudflare:workers"
2025-11-24 04:21:47 +08:00
export { waitUntil } from "cloudflare:workers"
2025-08-30 07:34:56 +08:00
export const Resource = new Proxy(
{},
{
get(_target, prop: string) {
2026-05-22 04:20:33 +08:00
if (`SST_RESOURCE_${prop}` in env) {
2025-08-30 12:58:22 +08:00
// @ts-expect-error
2026-05-22 04:11:41 +08:00
const value = env[`SST_RESOURCE_${prop}`]
2025-08-30 12:58:22 +08:00
return typeof value === "string" ? JSON.parse(value) : value
2026-05-22 07:11:33 +08:00
}
if (prop in env) {
// @ts-expect-error
const value = env[prop]
return typeof value === "string" ? JSON.parse(value) : value
2025-09-10 03:47:24 +08:00
} else if (prop === "App") {
// @ts-expect-error
return JSON.parse(env.SST_RESOURCE_App)
2025-08-30 07:34:56 +08:00
}
2025-08-30 12:58:22 +08:00
throw new Error(`"${prop}" is not linked in your sst.config.ts (cloudflare)`)
2025-08-30 07:34:56 +08:00
},
2025-08-30 12:58:22 +08:00
},
) as Record<string, any>