Skip to content

Commit 080499a

Browse files
committed
feat: US-180 - Add zod project-matrix fixture
1 parent bb2a9c0 commit 080499a

5 files changed

Lines changed: 90 additions & 0 deletions

File tree

docs/nodejs-compatibility.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The [project-matrix test suite](https://github.com/rivet-dev/secure-exec/tree/ma
7878
| [pg](https://npmjs.com/package/pg) | Database | PostgreSQL client, Pool/Client classes, type parsers |
7979
| [drizzle-orm](https://npmjs.com/package/drizzle-orm) | Database | ORM schema definition, query building, ESM module graph |
8080
| [ws](https://npmjs.com/package/ws) | Networking | WebSocket client/server, HTTP upgrade, events |
81+
| [zod](https://npmjs.com/package/zod) | Validation | Schema definition, parsing, safe parse, transforms |
8182
| [rivetkit](https://npmjs.com/package/rivetkit) | SDK | Local vendor package resolution |
8283
| crypto (builtin) | Crypto | `crypto.randomBytes`, `randomUUID`, `getRandomValues` |
8384
| fs-metadata-rename | Filesystem | `stat` metadata, `rename` semantics |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"entry": "src/index.js",
3+
"expectation": "pass"
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "project-matrix-zod-pass",
3+
"private": true,
4+
"type": "commonjs",
5+
"dependencies": {
6+
"zod": "3.24.2"
7+
}
8+
}

packages/secure-exec/tests/projects/zod-pass/pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"use strict";
2+
3+
const { z } = require("zod");
4+
5+
// Define schemas
6+
const userSchema = z.object({
7+
name: z.string().min(1),
8+
age: z.number().int().positive(),
9+
email: z.string().email(),
10+
tags: z.array(z.string()).optional(),
11+
});
12+
13+
const statusSchema = z.enum(["active", "inactive", "pending"]);
14+
15+
// Successful validation
16+
const validUser = userSchema.parse({
17+
name: "Alice",
18+
age: 30,
19+
email: "alice@example.com",
20+
tags: ["admin"],
21+
});
22+
23+
// Failed validation
24+
let validationError = null;
25+
try {
26+
userSchema.parse({ name: "", age: -1, email: "bad" });
27+
} catch (err) {
28+
validationError = {
29+
issueCount: err.issues.length,
30+
codes: err.issues.map((i) => i.code).sort(),
31+
};
32+
}
33+
34+
// Safe parse
35+
const safeResult = userSchema.safeParse({ name: "Bob", age: 25, email: "bob@test.com" });
36+
const safeFail = userSchema.safeParse({ name: 123 });
37+
38+
// Enum
39+
const enumResult = statusSchema.safeParse("active");
40+
const enumFail = statusSchema.safeParse("unknown");
41+
42+
// Transform and refine
43+
const doubled = z.number().transform((n) => n * 2).parse(5);
44+
45+
const result = {
46+
validUser: { name: validUser.name, age: validUser.age, hasTags: Array.isArray(validUser.tags) },
47+
validationError,
48+
safeParseSuccess: safeResult.success,
49+
safeParseFail: safeFail.success,
50+
enumSuccess: enumResult.success,
51+
enumFail: enumFail.success,
52+
transformed: doubled,
53+
};
54+
55+
console.log(JSON.stringify(result));

0 commit comments

Comments
 (0)