Files
supabase/apps/studio/components/ui/Forms/Form.constants.ts
T
Joshen LimandAlaister Young 38c5a38fa7 Chore/shift max auth db conns to auth advanced (#33729)
* Shift max auth db connections to auth advanced page

* Update URL for max auth db conns in empty state for auth settings

* Update check

* Fix

* fix form

* more fixes

* JESUS

* Add units

---------

Co-authored-by: Alaister Young <a@alaisteryoung.com>
2025-02-20 20:08:49 +08:00

25 lines
799 B
TypeScript

import * as z from 'zod'
// This validator validates a string to be a positive integer or if it's an empty string, transforms it to a null
export const StringToPositiveNumber = z.union([
// parse the value if it's a number
z.number().positive().int(),
// parse the value if it's a non-empty string
z.string().min(1).pipe(z.coerce.number().positive().int()),
// transform a non-empty string into a null value
z
.string()
.max(0, 'The field accepts only a number')
.transform((v) => null),
z.null(),
])
export const StringNumberOrNull = z
.string()
.transform((v) => (v === '' ? null : v))
.nullable()
.refine((value) => value === null || !isNaN(Number(value)), {
message: 'Invalid number',
})
.transform((value) => (value === null ? null : Number(value)))