Skip to content

Commit 91c77dd

Browse files
authored
fix: set character limit in schemas as DB limit (25 instead of 20) (#23)
* fix: set character limit in schemas as DB limit (25 instead of 20) * fix: typo
1 parent 768f73a commit 91c77dd

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@
6666
"tw-animate-css": "^1.3.8",
6767
"typescript": "^5"
6868
},
69-
"packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34"
69+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
7070
}

src/lib/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const URLRecord = z.object({
44
id: z.coerce.number(),
55
is_custom: z.boolean(),
66
original_url: z.string().url(),
7-
short_code: z.string().max(20),
7+
short_code: z.string().max(25),
88
created_at: z.coerce.date(),
99
updated_at: z.coerce.date(),
1010
click_count: z.number().int().nonnegative(),

src/lib/validations.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import { z } from "zod"
22

3-
export const createUrlSchema = z.object({
3+
export const editUrlSchema = z.object({
44
url: z.string().url("Invalid URL format"),
55
shortCode: z
66
.string()
7-
.min(2, "Short code must be at least 3 characters")
8-
.max(20, "Short code must be at most 20 characters")
7+
.min(2, "Short code must be at least 2 characters")
8+
.max(25, "Short code must be at most 25 characters")
99
.regex(
1010
/^[a-zA-Z0-9_-]+$/,
1111
"Short code can only contain letters, numbers, hyphens and underscores"
12-
)
13-
.optional(),
12+
),
1413
})
1514

16-
export type CreateUrlInput = z.infer<typeof createUrlSchema>
17-
18-
export const editUrlSchema = createUrlSchema.extend({
19-
shortCode: z
20-
.string()
21-
.min(2)
22-
.max(20)
23-
.regex(/^[a-zA-Z0-9_-]+$/),
15+
export const createUrlSchema = editUrlSchema.extend({
16+
shortCode: editUrlSchema.shape.shortCode.optional(),
2417
})

0 commit comments

Comments
 (0)