25 lines
569 B
TypeScript
25 lines
569 B
TypeScript
import * as z from "zod"
|
|
|
|
const urlSchema = z.url({
|
|
protocol: /^https?$/,
|
|
hostname: z.regexes.domain,
|
|
})
|
|
export const shortIdSchema = z.string().length(6)
|
|
const aliasSchema = z
|
|
.string()
|
|
.max(30)
|
|
.optional()
|
|
.nullable()
|
|
.refine((val) => {
|
|
if (val === null || val === undefined) return true
|
|
return /^[a-zA-Z0-9]+$/.test(val)
|
|
}, "Alias can only contain alphanumeric characters")
|
|
|
|
export const urlShortenerSchema = z.object({
|
|
url: urlSchema,
|
|
shortId: shortIdSchema,
|
|
alias: aliasSchema,
|
|
})
|
|
|
|
export type UrlShortenerInput = z.infer<typeof urlShortenerSchema>
|