Skip to content

Commit 09a307d

Browse files
authored
Migrate zod and associated dependencies to v4 (#193)
1 parent 63eb78a commit 09a307d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3096
-4061
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ __pycache__
143143
/playwright/.cache/
144144
dist_devel/
145145
!src/ui/pages/logs
146+
src/api/package.lambda.json

eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export default defineConfig([
7070
files: ["**/*.test.ts", "**/*.testdata.ts"],
7171
rules: { "@typescript-eslint/no-explicit-any": "off" },
7272
},
73+
{
74+
files: ["src/api/build.js"],
75+
rules: { "import/extensions": "off" },
76+
},
7377
{
7478
files: ["src/ui/*", "src/ui/**/*"],
7579
rules: {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"postinstall": "npm run setup",
1313
"setup": "git config blame.ignoreRevsFile .git-blame-ignore-revs",
1414
"build": "concurrently --names 'api,ui' 'yarn workspace infra-core-api run build' 'yarn workspace infra-core-ui run build'",
15-
"postbuild": "yarn lockfile-manage",
15+
"postbuild": "node src/api/createLambdaPackage.js && yarn lockfile-manage",
1616
"dev": "cross-env DISABLE_AUDIT_LOG=true concurrently --names 'api,ui' 'yarn workspace infra-core-api run dev' 'yarn workspace infra-core-ui run dev'",
1717
"lockfile-manage": "synp --with-workspace --source-file yarn.lock",
1818
"postlockfile-manage": "cp package-lock.json dist/lambda/ && cp package-lock.json dist/sqsConsumer/ && cp src/api/package.lambda.json dist/lambda/package.json && cp src/api/package.lambda.json dist/sqsConsumer/package.json && rm package-lock.json",
@@ -48,7 +48,7 @@
4848
"@typescript-eslint/eslint-plugin": "^8.0.1",
4949
"@typescript-eslint/parser": "^8.0.1",
5050
"@vitejs/plugin-react": "^4.3.1",
51-
"@vitest/coverage-istanbul": "3.1.2",
51+
"@vitest/coverage-istanbul": "^3.1.2",
5252
"@vitest/ui": "^3.1.2",
5353
"aws-sdk-client-mock": "^4.1.0",
5454
"concurrently": "^9.1.2",
@@ -86,10 +86,10 @@
8686
"typescript": "^5.8.3",
8787
"typescript-eslint": "^8.31.0",
8888
"vite-tsconfig-paths": "^5.0.1",
89-
"vitest": "^3.1.2",
89+
"vitest": "^3.2.4",
9090
"yarn-upgrade-all": "^0.7.5"
9191
},
9292
"resolutions": {
9393
"pdfjs-dist": "^4.8.69"
9494
}
95-
}
95+
}

src/api/build.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import esbuild from "esbuild";
22
import { resolve } from "path";
33
import { copy } from "esbuild-plugin-copy";
4+
import { packagesToTransfer } from "./createLambdaPackage.js";
45

56
const commonParams = {
67
bundle: true,
@@ -15,18 +16,7 @@ const commonParams = {
1516
target: "es2022", // Target ES2022
1617
sourcemap: false,
1718
platform: "node",
18-
external: [
19-
"aws-sdk",
20-
"moment-timezone",
21-
"passkit-generator",
22-
"fastify",
23-
"zod",
24-
"zod-openapi",
25-
"@fastify/swagger",
26-
"@fastify/swagger-ui",
27-
"argon2",
28-
"ioredis",
29-
],
19+
external: ["aws-sdk", ...packagesToTransfer],
3020
alias: {
3121
"moment-timezone": resolve(
3222
process.cwd(),
@@ -41,7 +31,6 @@ const commonParams = {
4131
const require = topLevelCreateRequire(import.meta.url);
4232
const __filename = fileURLToPath(import.meta.url);
4333
const __dirname = path.dirname(__filename);
44-
import "zod-openapi/extend";
4534
`.trim(),
4635
}, // Banner for compatibility with CommonJS
4736
plugins: [
@@ -60,7 +49,6 @@ const commonParams = {
6049
},
6150
}),
6251
],
63-
inject: [resolve(process.cwd(), "./zod-openapi-patch.js")],
6452
};
6553
esbuild
6654
.build({

src/api/components/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { AppRoles } from "common/roles.js";
22
import { FastifyZodOpenApiSchema } from "fastify-zod-openapi";
3-
import { z } from "zod";
3+
import * as z from "zod/v4";
44

55
export const ts = z.coerce
66
.number()
77
.min(0)
88
.optional()
9-
.openapi({ description: "Staleness bound", example: 0 });
10-
export const groupId = z.string().min(1).openapi({
9+
.meta({ description: "Staleness bound", example: 0 });
10+
export const groupId = z.string().min(1).meta({
1111
description: "Entra ID Group ID",
1212
example: "d8cbb7c9-2f6d-4b7e-8ba6-b54f8892003b",
1313
});

src/api/createLambdaPackage.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { readFile, writeFile } from "node:fs/promises";
2+
function getPath() {
3+
const result = new URL(import.meta.url);
4+
const pathname = result.pathname;
5+
const pathArray = pathname.split("/");
6+
const basename = pathArray.pop();
7+
const dirname = pathArray.join("/");
8+
9+
return { pathname, dirname, basename };
10+
}
11+
// These are packages not bundled into the JS file by esbuild
12+
export const packagesToTransfer = [
13+
"moment-timezone",
14+
"passkit-generator",
15+
"fastify",
16+
"@fastify/swagger",
17+
"@fastify/swagger-ui",
18+
"zod",
19+
"argon2",
20+
"ioredis",
21+
];
22+
const filePath = `${getPath().dirname}/package.json`;
23+
const writeFilePath = `${getPath().dirname}/package.lambda.json`;
24+
const packageJson = JSON.parse((await readFile(filePath)).toString());
25+
const basePackageJson = {
26+
name: "infra-core-api",
27+
version: "1.0.0",
28+
description: "",
29+
main: "index.js",
30+
author: "ACM@UIUC",
31+
license: "BSD-3-Clause",
32+
type: "module",
33+
dependencies: {},
34+
devDependencies: {},
35+
};
36+
for (const key in packageJson.dependencies) {
37+
if (packagesToTransfer.includes(key)) {
38+
const version = packageJson.dependencies[key];
39+
basePackageJson.dependencies[key] = version;
40+
}
41+
}
42+
const str = JSON.stringify(basePackageJson);
43+
await writeFile(writeFilePath, str);

src/api/esbuild.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const buildOptions = {
3535
const require = topLevelCreateRequire(import.meta.url);
3636
const __filename = fileURLToPath(import.meta.url);
3737
const __dirname = path.dirname(__filename);
38-
import "zod-openapi/extend";
3938
`.trim(),
4039
}, // Banner for compatibility with CommonJS
4140
plugins: [

src/api/functions/auditLog.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ function buildMarshalledAuditLogItem(entry: AuditLogEntry) {
2020
const expireAt =
2121
timestamp + Math.floor((RETENTION_DAYS * 24 * 60 * 60 * 1000) / 1000);
2222

23-
return marshall({
24-
...entry,
25-
createdAt: timestamp,
26-
expireAt,
27-
});
23+
return marshall(
24+
{
25+
...entry,
26+
createdAt: timestamp,
27+
expireAt,
28+
},
29+
{ removeUndefinedValues: true },
30+
);
2831
}
2932

3033
export async function createAuditLogEntry({

src/api/functions/ses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function generateMembershipEmailCommand(
1515
senderEmail: string,
1616
attachmentBuffer: ArrayBufferLike,
1717
): SendRawEmailCommand {
18-
const encodedAttachment = encode(attachmentBuffer);
18+
const encodedAttachment = encode(attachmentBuffer as ArrayBuffer);
1919
const boundary = "----BoundaryForEmail";
2020

2121
const emailTemplate = `
@@ -147,7 +147,7 @@ export function generateSalesEmail(
147147
senderEmail: string,
148148
imageBuffer: ArrayBufferLike,
149149
): SendRawEmailCommand {
150-
const encodedImage = encode(imageBuffer);
150+
const encodedImage = encode(imageBuffer as ArrayBuffer);
151151
const boundary = "----BoundaryForEmail";
152152

153153
const subject = `Your ${payload.type === "merch" ? "order" : "ticket"} has been confirmed!`;

src/api/functions/validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from "zod";
1+
import * as z from "zod/v4";
22

33
export function validateEmail(email: string): boolean {
44
const emailSchema = z.string().email();

0 commit comments

Comments
 (0)