schemas/libraries/valibot/index.ts
schemas/libraries/valibot/index.ts
schemas/libraries/valibot/index.ts
import type { Satisfies } from "@schema-benchmarks/utils";
import * as v from "valibot";
import type { ProductData } from "#src";
export function getValibotSchema() {
const imageSchema = v.object({
id: v.number(),
created: v.date(),
title: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(100),
),
type: v.picklist(["jpg", "png"]),
size: v.number(),
url: v.pipe(v.string(), v.url()),
});
const ratingSchema = v.object({
id: v.number(),
stars: v.pipe(
v.number(),
v.minValue(1),
v.maxValue(5),
),
title: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(100),
),
text: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(1_000),
),
images: v.array(imageSchema),
});
return v.object({
id: v.number(),
created: v.date(),
title: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(100),
),
brand: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(30),
),
description: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(500),
),
price: v.pipe(
v.number(),
v.minValue(1),
v.maxValue(10_000),
),
discount: v.nullable(
v.pipe(
v.number(),
v.minValue(1),
v.maxValue(100),
),
),
quantity: v.pipe(
v.number(),
v.minValue(0),
v.maxValue(10),
),
tags: v.array(
v.pipe(
v.string(),
v.minLength(1),
v.maxLength(30),
),
),
images: v.array(imageSchema),
ratings: v.array(ratingSchema),
});
}
export type SatisfiesTest = Satisfies<
v.InferOutput<
ReturnType<typeof getValibotSchema>
>,
ProductData
>;
import type { Satisfies } from "@schema-benchmarks/utils";
import * as v from "valibot";
import type { ProductData } from "#src";
export function getValibotSchema() {
const imageSchema = v.object({
id: v.number(),
created: v.date(),
title: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(100),
),
type: v.picklist(["jpg", "png"]),
size: v.number(),
url: v.pipe(v.string(), v.url()),
});
const ratingSchema = v.object({
id: v.number(),
stars: v.pipe(v.number(), v.minValue(1), v.maxValue(5)),
title: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(100),
),
text: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(1_000),
),
images: v.array(imageSchema),
});
return v.object({
id: v.number(),
created: v.date(),
title: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(100),
),
brand: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(30),
),
description: v.pipe(
v.string(),
v.minLength(1),
v.maxLength(500),
),
price: v.pipe(
v.number(),
v.minValue(1),
v.maxValue(10_000),
),
discount: v.nullable(
v.pipe(v.number(), v.minValue(1), v.maxValue(100)),
),
quantity: v.pipe(
v.number(),
v.minValue(0),
v.maxValue(10),
),
tags: v.array(
v.pipe(v.string(), v.minLength(1), v.maxLength(30)),
),
images: v.array(imageSchema),
ratings: v.array(ratingSchema),
});
}
export type SatisfiesTest = Satisfies<
v.InferOutput<ReturnType<typeof getValibotSchema>>,
ProductData
>;
import type { Satisfies } from "@schema-benchmarks/utils";
import * as v from "valibot";
import type { ProductData } from "#src";
export function getValibotSchema() {
const imageSchema = v.object({
id: v.number(),
created: v.date(),
title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
type: v.picklist(["jpg", "png"]),
size: v.number(),
url: v.pipe(v.string(), v.url()),
});
const ratingSchema = v.object({
id: v.number(),
stars: v.pipe(v.number(), v.minValue(1), v.maxValue(5)),
title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
text: v.pipe(v.string(), v.minLength(1), v.maxLength(1_000)),
images: v.array(imageSchema),
});
return v.object({
id: v.number(),
created: v.date(),
title: v.pipe(v.string(), v.minLength(1), v.maxLength(100)),
brand: v.pipe(v.string(), v.minLength(1), v.maxLength(30)),
description: v.pipe(v.string(), v.minLength(1), v.maxLength(500)),
price: v.pipe(v.number(), v.minValue(1), v.maxValue(10_000)),
discount: v.nullable(v.pipe(v.number(), v.minValue(1), v.maxValue(100))),
quantity: v.pipe(v.number(), v.minValue(0), v.maxValue(10)),
tags: v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(30))),
images: v.array(imageSchema),
ratings: v.array(ratingSchema),
});
}
export type SatisfiesTest = Satisfies<
v.InferOutput<ReturnType<typeof getValibotSchema>>,
ProductData
>;