resource.cloudflare.ts 759 B

123456789101112131415161718192021222324
  1. import { env } from "cloudflare:workers"
  2. export { waitUntil } from "cloudflare:workers"
  3. export const Resource = new Proxy(
  4. {},
  5. {
  6. get(_target, prop: string) {
  7. if (`SST_RESOURCE_${prop}` in env) {
  8. // @ts-expect-error
  9. const value = env[`SST_RESOURCE_${prop}`]
  10. return typeof value === "string" ? JSON.parse(value) : value
  11. }
  12. if (prop in env) {
  13. // @ts-expect-error
  14. const value = env[prop]
  15. return typeof value === "string" ? JSON.parse(value) : value
  16. } else if (prop === "App") {
  17. // @ts-expect-error
  18. return JSON.parse(env.SST_RESOURCE_App)
  19. }
  20. throw new Error(`"${prop}" is not linked in your sst.config.ts (cloudflare)`)
  21. },
  22. },
  23. ) as Record<string, any>