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

25 lines
759 B
TypeScript
Raw Permalink Normal View History

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