Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/shiny-donuts-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/util-stream": patch
"@smithy/core": patch
---

prevent compilation from inserting Uint8Array type parameter
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test-types:
npx tsc -p tsconfig.test.json

test-integration:
node ./scripts/validation/no-generic-byte-arrays.js
make test-browser
yarn g:vitest run -c vitest.config.integ.mts
make test-types
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/submodules/cbor/cbor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { encode, resize, toUint8Array } from "./cbor-encode";
* @see https://github.com/kriszyp/cbor-x
*/
export const cbor = {
deserialize(payload: Uint8Array) {
deserialize(payload: Uint8Array): any {
setPayload(payload);
return decode(0, payload.length);
},
serialize(input: any) {
serialize(input: any): Uint8Array {
try {
encode(input);
return toUint8Array();
Expand Down
2 changes: 1 addition & 1 deletion packages/util-stream/src/ByteArrayCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ByteArrayCollector {
this.byteLength += byteArray.byteLength;
}

public flush() {
public flush(): Uint8Array {
if (this.byteArrays.length === 1) {
const bytes = this.byteArrays[0];
this.reset();
Expand Down
39 changes: 39 additions & 0 deletions scripts/validation/no-generic-byte-arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node

/**
* Runs after a full build to assert that Uint8Array was not generated with a type parameter
* by TypeScript, which is only compatible with TypeScript 5.7.
*/

const walk = require("../utils/walk");
const fs = require("node:fs");
const path = require("node:path");

const root = path.join(__dirname, "..", "..");

const packages = path.join(root, "packages");

(async () => {
const errors = [];
for (const folder of fs.readdirSync(packages)) {
const packagePath = path.join(packages, folder);
const distTypes = path.join(packagePath, "dist-types");
if (fs.existsSync(distTypes)) {
for await (const file of walk(distTypes)) {
const contents = fs.readFileSync(file, "utf-8");
if (contents.includes("Uint8Array<")) {
errors.push(file);
}
}
}
}
if (errors.length > 0) {
throw new Error(
`The following files used Uint8Array in a generic way, only compatible with TypeScript 5.7:\n\t${errors.join(
"\n\t"
)}`
);
} else {
console.log(`✅ No Uint8Arrays with type parameters.`);
}
})();
Loading