1.0.1 • Published 9 months ago
surrealdb-valibot v1.0.1
How to use
Install it with:
# using npm
npm i surrealdb-valibot
# or using pnpm
pnpm i surrealdb-valibot
# or using yarn
yarn add surrealdb-valibot
Next, import the schema's, e.g.:
import { RecordIdSchema } from "surreal-valibot";
Use it as you would a normal valibot schema
e.g.:
import { RecordIdSchema, RecordIdSchemaOf } from "surreal-valibot";
import * as v from "valibot";
// `id` must be an instance of class `RecordId`
const PersonSchema = v.object({
id: RecordIdSchema,
});
// or
// `id` must be an instance of class `RecordId` and table must be "person"
const PersonSchema = v.object({
id: RecordIdSchemaOf("person"),
});
Important notes
- All schema names consist of
{ClassName}Schema
, e.g. forRecordId
it isRecordIdSchema
- If the class has optional generic types e.g.
RecordId
can beRecordId<"person">
naming will be{ClassName}SchemaOf
and will be a function
e.g. usage:const schema = RecordIdSchemaOf("person")
- Some types like
Range
have required generic types, these schema's are function and follow the following naming scheme:{ClassName}Schema
e.g.:RangeSchema(v.string(), v.string())
- Some schema function have props that are a
string
(e.g.RecordIdSchemaOf
) and some are any valibot schema (e.g.RangeSchema
)