44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
|
|
/**
|
||
|
|
* Consumer-strict smoke for `@shade/files`.
|
||
|
|
*
|
||
|
|
* Compiled with `lib: ["ES2022", "DOM"]` + `exactOptionalPropertyTypes` +
|
||
|
|
* `skipLibCheck: false` to mimic a downstream consumer like Dispatch.
|
||
|
|
* Catches the class of bug where our internal narrower types (e.g. a
|
||
|
|
* locally-defined `MinimalReader`) reject native browser types
|
||
|
|
* (e.g. `ReadableStreamDefaultReader`) the consumer would naturally
|
||
|
|
* pass in.
|
||
|
|
*
|
||
|
|
* If this file fails to compile, the published packages will fail in
|
||
|
|
* any consumer's strict tsc — pre-publish gate must catch it.
|
||
|
|
*/
|
||
|
|
import { decideInline, type WriteSource } from '@shade/files';
|
||
|
|
|
||
|
|
declare const blob: Blob;
|
||
|
|
declare const stream: ReadableStream<Uint8Array>;
|
||
|
|
declare const bytes: Uint8Array;
|
||
|
|
|
||
|
|
async function smoke(): Promise<void> {
|
||
|
|
// Each branch of WriteSource must round-trip through decideInline()
|
||
|
|
// when given the natively-typed inputs a browser app would supply.
|
||
|
|
const sources: WriteSource[] = [
|
||
|
|
bytes,
|
||
|
|
blob,
|
||
|
|
stream,
|
||
|
|
{ stream, size: 1024 },
|
||
|
|
{ stream, size: 1024, contentType: 'image/png' },
|
||
|
|
];
|
||
|
|
for (const src of sources) {
|
||
|
|
const decision = await decideInline(src);
|
||
|
|
if (decision.kind === 'streams') {
|
||
|
|
const reader = decision.stream.getReader();
|
||
|
|
const { value, done } = await reader.read();
|
||
|
|
if (!done && value !== undefined) {
|
||
|
|
void value.byteLength;
|
||
|
|
}
|
||
|
|
reader.releaseLock();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void smoke;
|