diff --git a/src/typebox_utils.ts b/src/typebox_utils.ts new file mode 100644 index 0000000..1dee374 --- /dev/null +++ b/src/typebox_utils.ts @@ -0,0 +1,13 @@ +import { TSchema, Type } from "./deps/typebox.ts"; + +export const NonEmptyString = (props?: Parameters[0]) => Type.String({ minLength: 1, ...props }); + +export const PosInt = (props?: Parameters[0]) => + Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, ...props }); + +export const NonNegInt = (props?: Parameters[0]) => + Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, ...props }); + +export const Maybe = (schema: T) => Type.Union([schema, Type.Undefined()]); + +export const Nullable = (schema: T) => Type.Union([schema, Type.Null()]);