|
| 1 | +/** |
| 2 | + * Minimal Cloudflare Workers type stubs for cloud-artifacts Worker. |
| 3 | + * |
| 4 | + * The canonical types are in worker-configuration.d.ts (generated by `wrangler types`, |
| 5 | + * gitignored). This file provides just enough so `tsc --noEmit` passes even when that |
| 6 | + * generated file is absent (e.g. CI, fresh clone). |
| 7 | + */ |
| 8 | + |
| 9 | +// -- R2 types --------------------------------------------------------------- |
| 10 | + |
| 11 | +interface R2Checksums { |
| 12 | + readonly md5?: ArrayBuffer |
| 13 | + readonly sha1?: ArrayBuffer |
| 14 | + readonly sha256?: ArrayBuffer |
| 15 | + readonly sha384?: ArrayBuffer |
| 16 | + readonly sha512?: ArrayBuffer |
| 17 | +} |
| 18 | + |
| 19 | +interface R2HTTPMetadata { |
| 20 | + contentType?: string |
| 21 | + contentLanguage?: string |
| 22 | + contentDisposition?: string |
| 23 | + contentEncoding?: string |
| 24 | + cacheControl?: string |
| 25 | + cacheExpiry?: Date |
| 26 | +} |
| 27 | + |
| 28 | +interface R2Range { |
| 29 | + offset: number |
| 30 | + length?: number |
| 31 | +} |
| 32 | + |
| 33 | +declare abstract class R2Object { |
| 34 | + readonly key: string |
| 35 | + readonly version: string |
| 36 | + readonly size: number |
| 37 | + readonly etag: string |
| 38 | + readonly httpEtag: string |
| 39 | + readonly checksums: R2Checksums |
| 40 | + readonly uploaded: Date |
| 41 | + readonly httpMetadata?: R2HTTPMetadata |
| 42 | + readonly customMetadata?: Record<string, string> |
| 43 | + readonly range?: R2Range |
| 44 | + readonly storageClass: string |
| 45 | + readonly ssecKeyMd5?: string |
| 46 | + writeHttpMetadata(headers: Headers): void |
| 47 | +} |
| 48 | + |
| 49 | +interface R2ObjectBody extends R2Object { |
| 50 | + get body(): ReadableStream |
| 51 | + get bodyUsed(): boolean |
| 52 | +} |
| 53 | + |
| 54 | +interface R2PutOptions { |
| 55 | + httpMetadata?: R2HTTPMetadata | Headers |
| 56 | + customMetadata?: Record<string, string> |
| 57 | +} |
| 58 | + |
| 59 | +interface R2Bucket { |
| 60 | + head(key: string): Promise<R2Object | null> |
| 61 | + get(key: string, options?: R2GetOptions): Promise<R2ObjectBody | null> |
| 62 | + put( |
| 63 | + key: string, |
| 64 | + value: |
| 65 | + | ReadableStream |
| 66 | + | ArrayBuffer |
| 67 | + | ArrayBufferView |
| 68 | + | string |
| 69 | + | null |
| 70 | + | Blob, |
| 71 | + options?: R2PutOptions, |
| 72 | + ): Promise<R2Object> |
| 73 | + delete(keys: string | string[]): Promise<void> |
| 74 | +} |
| 75 | + |
| 76 | +// Empty placeholder — R2GetOptions is unused beyond an optional parameter |
| 77 | +type R2GetOptions = {} |
| 78 | + |
| 79 | +// -- ExportedHandler ------------------------------------------------------- |
| 80 | + |
| 81 | +interface ExportedHandler<Env = unknown> { |
| 82 | + fetch?: ( |
| 83 | + request: Request, |
| 84 | + env: Env, |
| 85 | + ctx: ExecutionContext, |
| 86 | + ) => Response | Promise<Response> |
| 87 | +} |
| 88 | + |
| 89 | +// -- Env ------------------------------------------------------------------- |
| 90 | +// Wrangler-generated worker-configuration.d.ts supplies TOKEN via `wrangler secret put`. |
| 91 | +// This declaration provides the R2 binding + wrangler vars so the Worker compiles |
| 92 | +// without the generated file. |
| 93 | + |
| 94 | +declare global { |
| 95 | + interface Env { |
| 96 | + BUCKET: R2Bucket |
| 97 | + TOKEN: string |
| 98 | + MAX_BYTES: string |
| 99 | + DEFAULT_TTL_DAYS: string |
| 100 | + PUBLIC_URL: string |
| 101 | + } |
| 102 | +} |
0 commit comments