Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 77d3044

Browse files
author
James Berry
committed
docs/add preprocess input to examples
1 parent be83a43 commit 77d3044

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

examples/with-express/src/database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type User = {
22
id: string;
33
email: string;
4-
passcode: string;
4+
passcode: number;
55
name: string;
66
};
77

@@ -16,19 +16,19 @@ export const database: { users: User[]; posts: Post[] } = {
1616
{
1717
id: '3dcb4a1f-0c91-42c5-834f-26d227c532e2',
1818
19-
passcode: '1234',
19+
passcode: 1234,
2020
name: 'James',
2121
},
2222
{
2323
id: 'ea120573-2eb4-495e-be48-1b2debac2640',
2424
25-
passcode: '9876',
25+
passcode: 9876,
2626
name: 'Alex',
2727
},
2828
{
2929
id: '2ee1c07c-7537-48f5-b5d8-8740e165cd62',
3030
31-
passcode: '1234',
31+
passcode: 5678,
3232
name: 'Sachin',
3333
},
3434
],

examples/with-express/src/router.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ const authRouter = createRouter()
6969
},
7070
input: z.object({
7171
email: z.string().email(),
72-
passcode: z.string().regex(/^[0-9]{4}$/),
72+
passcode: z.preprocess(
73+
(arg) => (typeof arg === 'string' ? parseInt(arg) : arg),
74+
z.number().min(1000).max(9999),
75+
),
7376
name: z.string().min(3),
7477
}),
7578
output: z.object({
@@ -113,7 +116,10 @@ const authRouter = createRouter()
113116
},
114117
input: z.object({
115118
email: z.string().email(),
116-
passcode: z.string().regex(/^[0-9]{4}$/),
119+
passcode: z.preprocess(
120+
(arg) => (typeof arg === 'string' ? parseInt(arg) : arg),
121+
z.number().min(1000).max(9999),
122+
),
117123
}),
118124
output: z.object({
119125
token: z.string(),

examples/with-nextjs/src/server/database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type User = {
22
id: string;
33
email: string;
4-
passcode: string;
4+
passcode: number;
55
name: string;
66
};
77

@@ -16,19 +16,19 @@ export const database: { users: User[]; posts: Post[] } = {
1616
{
1717
id: '3dcb4a1f-0c91-42c5-834f-26d227c532e2',
1818
19-
passcode: '1234',
19+
passcode: 1234,
2020
name: 'James',
2121
},
2222
{
2323
id: 'ea120573-2eb4-495e-be48-1b2debac2640',
2424
25-
passcode: '9876',
25+
passcode: 9876,
2626
name: 'Alex',
2727
},
2828
{
2929
id: '2ee1c07c-7537-48f5-b5d8-8740e165cd62',
3030
31-
passcode: '1234',
31+
passcode: 5678,
3232
name: 'Sachin',
3333
},
3434
],

examples/with-nextjs/src/server/router.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ const authRouter = createRouter()
6666
},
6767
input: z.object({
6868
email: z.string().email(),
69-
passcode: z.string().regex(/^[0-9]{4}$/),
69+
passcode: z.preprocess(
70+
(arg) => (typeof arg === 'string' ? parseInt(arg) : arg),
71+
z.number().min(1000).max(9999),
72+
),
7073
name: z.string().min(3),
7174
}),
7275
output: z.object({
@@ -110,7 +113,10 @@ const authRouter = createRouter()
110113
},
111114
input: z.object({
112115
email: z.string().email(),
113-
passcode: z.string().regex(/^[0-9]{4}$/),
116+
passcode: z.preprocess(
117+
(arg) => (typeof arg === 'string' ? parseInt(arg) : arg),
118+
z.number().min(1000).max(9999),
119+
),
114120
}),
115121
output: z.object({
116122
token: z.string(),

0 commit comments

Comments
 (0)