Skip to content

Commit f78a1c3

Browse files
committed
z.number().int() -> z.int().
1 parent 5b38f5b commit f78a1c3

8 files changed

Lines changed: 21 additions & 42 deletions

File tree

example/endpoints/accept-raw.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const rawAcceptingEndpoint = defaultEndpointsFactory.build({
77
input: ez.raw({
88
/* the place for additional inputs, like route params, if needed */
99
}),
10-
output: z.object({ length: z.number().int().nonnegative() }),
10+
output: z.object({ length: z.int().nonnegative() }),
1111
handler: async ({ input: { raw } }) => ({
1212
length: raw.length, // input.raw is populated automatically by the corresponding parser
1313
}),

example/endpoints/create-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const createUserEndpoint = statusDependingFactory.build({
1111
name: z.string().nonempty(),
1212
}),
1313
output: z.object({
14-
id: z.number().int().positive(),
14+
id: z.int().positive(),
1515
}),
1616
handler: async ({ input: { name } }) => {
1717
assert(name !== "Gimme Jimmy", createHttpError(500, "That went wrong"));

example/endpoints/retrieve-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const retrieveUserEndpoint = defaultEndpointsFactory
2727
.describe("a numeric string containing the id of the user"),
2828
}),
2929
output: z.object({
30-
id: z.number().int().nonnegative(),
30+
id: z.int().nonnegative(),
3131
name: z.string(),
3232
features: feature.array(),
3333
}),

example/endpoints/submit-feedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const submitFeedbackEndpoint = defaultEndpointsFactory.build({
1010
message: z.string().min(1),
1111
}),
1212
output: z.object({
13-
crc: z.number().int().positive(),
13+
crc: z.int().positive(),
1414
}),
1515
handler: async ({ input: { name, email, message } }) => ({
1616
crc: [name, email, message].reduce((acc, { length }) => acc + length, 0),

example/endpoints/upload-avatar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const uploadAvatarEndpoint = defaultEndpointsFactory.build({
1111
}),
1212
output: z.object({
1313
name: z.string(),
14-
size: z.number().int().nonnegative(),
14+
size: z.int().nonnegative(),
1515
mime: z.string(),
1616
hash: z.string(),
1717
otherInputs: z.record(z.string(), z.any()),

example/factories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ export const noContentFactory = new EndpointsFactory(
107107

108108
/** @desc This factory is for producing event streams of server-sent events (SSE) */
109109
export const eventsFactory = new EventStreamFactory({
110-
time: z.number().int().positive(),
110+
time: z.int().positive(),
111111
});

express-zod-api/src/sse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const makeEventSchema = (event: string, data: z.ZodType) =>
2525
data,
2626
event: z.literal(event),
2727
id: z.string().optional(),
28-
retry: z.number().int().positive().optional(),
28+
retry: z.int().positive().optional(),
2929
});
3030

3131
export const formatEvent = <E extends EventsMap>(

express-zod-api/tests/documentation.spec.ts

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("Documentation", () => {
5454
v1: {
5555
getSomething: defaultEndpointsFactory.build({
5656
input: z.object({
57-
array: z.array(z.number().int().positive()).min(1).max(3),
57+
array: z.array(z.int().positive()).min(1).max(3),
5858
unlimited: z.array(z.boolean()),
5959
transformer: z.string().transform((str) => str.length),
6060
}),
@@ -86,7 +86,7 @@ describe("Documentation", () => {
8686
optional: z.string().optional(),
8787
optDefault: z.string().optional().default("test"),
8888
nullish: z.boolean().nullish(),
89-
nuDefault: z.number().int().positive().nullish().default(123),
89+
nuDefault: z.int().positive().nullish().default(123),
9090
}),
9191
output: z.object({
9292
nullable: z.string().nullable(),
@@ -124,14 +124,8 @@ describe("Documentation", () => {
124124
}),
125125
output: z.object({
126126
and: z
127-
.object({
128-
five: z.number().int().gte(0),
129-
})
130-
.and(
131-
z.object({
132-
six: z.string(),
133-
}),
134-
),
127+
.object({ five: z.int().gte(0) })
128+
.and(z.object({ six: z.string() })),
135129
}),
136130
handler: async () => ({
137131
and: {
@@ -158,19 +152,11 @@ describe("Documentation", () => {
158152
method: "post",
159153
input: z.object({
160154
union: z.union([
161-
z.object({
162-
one: z.string(),
163-
two: z.number().int().positive(),
164-
}),
165-
z.object({
166-
two: z.number().int().negative(),
167-
three: z.string(),
168-
}),
155+
z.object({ one: z.string(), two: z.int().positive() }),
156+
z.object({ two: z.int().negative(), three: z.string() }),
169157
]),
170158
}),
171-
output: z.object({
172-
or: z.string().or(z.number().int().positive()),
173-
}),
159+
output: z.object({ or: z.string().or(z.int().positive()) }),
174160
handler: async () => ({
175161
or: 554,
176162
}),
@@ -223,10 +209,7 @@ describe("Documentation", () => {
223209
v1: {
224210
getSomething: defaultEndpointsFactory.build({
225211
method: "post",
226-
input: z.object({
227-
one: z.string(),
228-
two: z.number().int().positive(),
229-
}),
212+
input: z.object({ one: z.string(), two: z.int().positive() }),
230213
output: z.object({
231214
transform: z.string().transform((str) => str.length),
232215
}),
@@ -338,10 +321,10 @@ describe("Documentation", () => {
338321
doubleNegative: z.number().negative(),
339322
doubleLimited: z.number().min(-0.5).max(0.5),
340323
int: z.int(),
341-
intPositive: z.number().int().positive(),
342-
intNegative: z.number().int().negative(),
343-
intLimited: z.number().int().min(-100).max(100),
344-
zero: z.number().int().nonnegative().nonpositive().optional(),
324+
intPositive: z.int().positive(),
325+
intNegative: z.int().negative(),
326+
intLimited: z.int().min(-100).max(100),
327+
zero: z.int().nonnegative().nonpositive().optional(),
345328
}),
346329
output: z.object({
347330
bigint: z.bigint(),
@@ -406,11 +389,7 @@ describe("Documentation", () => {
406389
input: z.object({
407390
ofOne: z.tuple([z.boolean()]),
408391
ofStrings: z.tuple([z.string(), z.string().nullable()]),
409-
complex: z.tuple([
410-
z.boolean(),
411-
z.string(),
412-
z.number().int().positive(),
413-
]),
392+
complex: z.tuple([z.boolean(), z.string(), z.int().positive()]),
414393
}),
415394
output: z.object({
416395
empty: z.tuple([]),
@@ -456,7 +435,7 @@ describe("Documentation", () => {
456435
const string = z.preprocess((arg) => String(arg), z.string());
457436
const number = z.preprocess(
458437
(arg) => parseInt(String(arg), 16),
459-
z.number().int().nonnegative(),
438+
z.int().nonnegative(),
460439
);
461440
const boolean = z.preprocess((arg) => !!arg, z.boolean());
462441
const spec = new Documentation({

0 commit comments

Comments
 (0)