Files
zpan/server/platform/interface.ts
T
saltboandClaude Opus 4.7 bcb0b67872 feat(platform): add getBinding() for platform-native resources
Platform-native bindings (Cloudflare R2/D1/KV, Azure Storage contexts,
etc.) are not representable as strings, so getEnv() can't carry them.
Add a typed getBinding<T>() accessor: returns the binding on platforms
that support it, undefined on others.

Callers branch on the return — e.g. \`getBinding<R2Bucket>('PUBLIC_IMAGES')\`
will be defined on CF and undefined on Node/Docker, letting the same
code pick a runtime-appropriate path without platform-specific imports.

Used in the next commit to switch the public image upload flow to R2
binding on CF (zero-auth, zero-egress) while keeping the S3 fallback
for every other platform.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:56:35 -04:00

19 lines
820 B
TypeScript

import type { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'
import type * as authSchema from '../db/auth-schema'
import type * as appSchema from '../db/schema'
type FullSchema = typeof appSchema & typeof authSchema
// Use base type to unify BetterSQLite3 (sync) and D1 (async) drivers
// biome-ignore lint/suspicious/noExplicitAny: Drizzle drivers differ in result kind and run result types
export type Database = BaseSQLiteDatabase<any, any, FullSchema>
export interface Platform {
db: Database
getEnv(key: string): string | undefined
// Access platform-native bindings (e.g. CF R2 bucket, D1 database).
// Returns `undefined` on platforms without that binding, so callers branch
// on the return value to pick a runtime-appropriate code path.
getBinding<T = unknown>(key: string): T | undefined
}