https://github.com/ShadowWolf308/surrealdb-valibot
Re-useable valibot schema's for use with SurrealDB sdk
https://github.com/ShadowWolf308/surrealdb-valibot
Last synced: 3 months ago
JSON representation
Re-useable valibot schema's for use with SurrealDB sdk
- Host: GitHub
- URL: https://github.com/ShadowWolf308/surrealdb-valibot
- Owner: ShadowWolf308
- License: mit
- Created: 2024-10-15T14:26:37.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T07:11:35.000Z (8 months ago)
- Last Synced: 2025-02-22T06:46:13.586Z (3 months ago)
- Language: TypeScript
- Size: 103 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-surreal - surrealdb-valibot - Re-usable valibot schema's for use with the JavaScript SDK. (Libraries)
README
![]()
surrealdb-valibot
Re-useable valibot schema's for use with SurrealDB sdk.
## How to use
Install it with:```sh
# 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.:
```ts
import { RecordIdSchema } from "surreal-valibot";
```Use it as you would a normal valibot schema
e.g.:
```ts
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. for `RecordId` it is `RecordIdSchema`
* If the class has optional generic types e.g. `RecordId` can be `RecordId<"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`)## References
* [valibot docs](https://valibot.dev/)
* [valibot npm package ](https://www.npmjs.com/package/valibot)
* [SurrealDB docs](https://surrealdb.com/)
* [SurrealDB npm package](https://www.npmjs.com/package/surrealdb)