Skip to content

Commit a40013f

Browse files
authored
chore(scripts): validate no Uint8Array with type parameters are generated by compiler (#7355)
* chore(scripts): validate no Uint8Array with type parameters are generated by compiler * test: fix fixture import paths
1 parent 5a1cd73 commit a40013f

File tree

10 files changed

+71
-8
lines changed

10 files changed

+71
-8
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test-schema: bundles
3434

3535
test-integration: bundles
3636
rm -rf ./clients/client-sso/node_modules/\@smithy # todo(yarn) incompatible redundant nesting.
37+
node ./scripts/validation/no-generic-byte-arrays.js
3738
yarn g:vitest run -c vitest.config.integ.mts
3839
make test-protocols
3940
make test-types

packages/crc64-nvme-crt/src/CrtCrc64Nvme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class CrtCrc64Nvme implements Checksum {
99
this.checksum = checksums.crc64nvme(data, this.checksum);
1010
}
1111

12-
async digest() {
12+
async digest(): Promise<Uint8Array> {
1313
return toUint8Array(this.checksum);
1414
}
1515

packages/middleware-flexible-checksums/src/getCrc32ChecksumAlgorithmFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class NodeCrc32 implements Checksum {
1111
this.checksum = zlib.crc32(data, this.checksum);
1212
}
1313

14-
async digest() {
14+
async digest(): Promise<Uint8Array> {
1515
return numToUint8(this.checksum);
1616
}
1717

packages/middleware-flexible-checksums/src/stringHasher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { toUint8Array } from "@smithy/util-utf8";
44
/**
55
* A function that, given a hash constructor and a string, calculates the hash of the string.
66
*/
7-
export const stringHasher = (checksumAlgorithmFn: ChecksumConstructor | HashConstructor, body: any) => {
7+
export const stringHasher = (
8+
checksumAlgorithmFn: ChecksumConstructor | HashConstructor,
9+
body: any
10+
): Promise<Uint8Array> => {
811
const hash = new checksumAlgorithmFn();
912
hash.update(toUint8Array(body || ""));
1013
return hash.digest();

packages/middleware-sdk-ec2/src/fixture.ts renamed to packages/middleware-sdk-ec2/src/fixture.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { SourceData } from "@smithy/types";
2+
import { describe, test as it } from "vitest";
23

34
export class MockSha256 {
45
// eslint-disable-next-line @typescript-eslint/no-unused-vars
56
constructor(secret?: string | ArrayBuffer | ArrayBufferView) {}
7+
68
// eslint-disable-next-line @typescript-eslint/no-unused-vars
79
update(data?: SourceData) {}
8-
digest() {
10+
11+
digest(): Promise<Uint8Array> {
912
return Promise.resolve(new Uint8Array(5));
1013
}
1114
}
@@ -18,3 +21,7 @@ export const credentials = () =>
1821
secretAccessKey: "secret",
1922
sessionToken: "session",
2023
});
24+
25+
describe("placeholder", () => {
26+
it("placeholder for exports of testing constructs", () => {});
27+
});

packages/middleware-sdk-ec2/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HttpRequest } from "@smithy/protocol-http";
22
import { EndpointV2 } from "@smithy/types";
33
import { beforeEach, describe, expect, test as it, vi } from "vitest";
44

5-
import { credentials, MockSha256, region } from "./fixture";
5+
import { credentials, MockSha256, region } from "./fixture.spec";
66
import { copySnapshotPresignedUrlMiddleware } from "./index";
77

88
const nextHandler = vi.fn();

packages/middleware-sdk-rds/src/fixture.ts renamed to packages/middleware-sdk-rds/src/fixture.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { SourceData } from "@smithy/types";
2+
import { describe, test as it } from "vitest";
23

34
export class MockSha256 {
45
// eslint-disable-next-line @typescript-eslint/no-unused-vars
56
constructor(secret?: string | ArrayBuffer | ArrayBufferView) {}
67
// eslint-disable-next-line @typescript-eslint/no-unused-vars
78
update(data?: SourceData) {}
8-
digest() {
9+
digest(): Promise<Uint8Array> {
910
return Promise.resolve(new Uint8Array(5));
1011
}
1112
reset() {}
@@ -26,3 +27,7 @@ export const credentials = () =>
2627
secretAccessKey: "secret",
2728
sessionToken: "session",
2829
});
30+
31+
describe("placeholder", () => {
32+
it("placeholder for exports of testing constructs", () => {});
33+
});

packages/middleware-sdk-rds/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { beforeEach, describe, expect, test as it, vi } from "vitest";
22

33
import { crossRegionPresignedUrlMiddleware } from "./";
4-
import { credentials, endpoint, MockSha256, region } from "./fixture";
4+
import { credentials, endpoint, MockSha256, region } from "./fixture.spec";
55

66
const nextHandler = vi.fn();
77
const arn = "arn:aws:rds:src-region:000000000000:src-snapshot:dist-snapshot";

packages/middleware-signing/src/awsAuthConfiguration.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ describe("AuthConfig", () => {
118118
for (let i = 0; i < repeats; i++) {
119119
await signer.sign(request);
120120
}
121-
console.log("what is credentials", credentials);
121+
expect(await credentials()).toEqual({
122+
accessKeyId: "key",
123+
secretAccessKey: "secret",
124+
});
122125
expect(spy).toBeCalledTimes(2);
123126
});
124127
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Runs after a full build to assert that Uint8Array was not generated with a type parameter
5+
* by TypeScript, which is only compatible with TypeScript 5.7.
6+
*/
7+
8+
const walk = require("../utils/walk");
9+
const fs = require("node:fs");
10+
const path = require("node:path");
11+
12+
const root = path.join(__dirname, "..", "..");
13+
14+
const clients = path.join(root, "clients");
15+
const lib = path.join(root, "lib");
16+
const packages = path.join(root, "packages");
17+
const private = path.join(root, "private");
18+
19+
(async () => {
20+
const errors = [];
21+
for (const group of [clients, lib, packages, private]) {
22+
for (const folder of fs.readdirSync(group)) {
23+
const packagePath = path.join(group, folder);
24+
const distTypes = path.join(packagePath, "dist-types");
25+
if (fs.existsSync(distTypes)) {
26+
for await (const file of walk(distTypes)) {
27+
const contents = fs.readFileSync(file, "utf-8");
28+
if (contents.includes("Uint8Array<")) {
29+
errors.push(file);
30+
}
31+
}
32+
}
33+
}
34+
}
35+
if (errors.length > 0) {
36+
throw new Error(
37+
`The following files used Uint8Array in a generic way, only compatible with TypeScript 5.7:\n\t${errors.join(
38+
"\n\t"
39+
)}`
40+
);
41+
} else {
42+
console.log(`✅ No Uint8Arrays with type parameters.`);
43+
}
44+
})();

0 commit comments

Comments
 (0)