diff --git a/supabase/functions/edifice-map-generator/index.ts b/supabase/functions/edifice-map-generator/index.ts index 95ced7f..e2c4866 100644 --- a/supabase/functions/edifice-map-generator/index.ts +++ b/supabase/functions/edifice-map-generator/index.ts @@ -304,18 +304,30 @@ function crc32(data: Uint8Array): number { return (c ^ 0xFFFFFFFF) >>> 0; } -async function zlibDecompress(data: Uint8Array): Promise { +async function zlibDecompress(data: Uint8Array): Promise> { return streamTransform(new DecompressionStream("deflate"), data); } -async function zlibCompress(data: Uint8Array): Promise { +async function zlibCompress(data: Uint8Array): Promise> { return streamTransform(new CompressionStream("deflate"), data); } +// Two type facts drive these signatures under Deno 2.x / TypeScript 5.7, and neither is +// cosmetic: +// 1. CompressionStream and DecompressionStream declare `writable: WritableStream`, +// which is wider than Uint8Array — so a `TransformStream` +// parameter asked for something narrower than either class provides. +// 2. Since TS 5.7 typed arrays are generic over their backing buffer: bare `Uint8Array` +// means `Uint8Array`, which admits SharedArrayBuffer, while +// `BufferSource` requires `ArrayBufferView`. So a bare Uint8Array is not +// writable to these streams. +// Hence `Uint8Array` throughout the PNG codec path: it states that these buffers +// are never shared, which is already true — every one of them comes from `new Uint8Array(n)` +// or a `Response.arrayBuffer()`. A cast would have silenced the checker without saying so. async function streamTransform( - xform: TransformStream, - data: Uint8Array, -): Promise { + xform: TransformStream, + data: Uint8Array, +): Promise> { const writer = xform.writable.getWriter(); const reader = xform.readable.getReader(); const chunks: Uint8Array[] = [];