Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
[submodule "code-repos/zenstackhq/v3-doc-orm-polymorphism"]
path = code-repos/zenstackhq/v3-doc-orm-polymorphism
url = https://github.com/zenstackhq/v3-doc-orm-polymorphism.git
[submodule "code-repos/zenstackhq/v3-doc-orm-validation"]
path = code-repos/zenstackhq/v3-doc-orm-validation
url = https://github.com/zenstackhq/v3-doc-orm-validation.git
[submodule "code-repos/zenstackhq/v3-doc-orm-policy"]
path = code-repos/zenstackhq/v3-doc-orm-policy
url = https://github.com/zenstackhq/v3-doc-orm-policy.git
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Website

This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
This website is built using [Docusaurus 3](https://docusaurus.io/), a modern static website generator.

### Installation

Expand All @@ -23,19 +23,3 @@ $ pnpm build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment

Using SSH:

```
$ USE_SSH=true pnpm deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> pnpm deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
1 change: 1 addition & 0 deletions code-repos/zenstackhq/v3-doc-orm-policy
Submodule v3-doc-orm-policy added at 898e2d
1 change: 1 addition & 0 deletions code-repos/zenstackhq/v3-doc-orm-validation
Submodule v3-doc-orm-validation added at c86439
2 changes: 1 addition & 1 deletion code-repos/zenstackhq/v3-doc-quick-start
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 1
description: Quick start guide
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 2
description: Using the CLI
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 3
description: Creating a database client
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 5
description: Query builder API
---

Expand Down
30 changes: 30 additions & 0 deletions versioned_docs/version-3.x/orm/09-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
description: Input validation in ZModel
---

import ZenStackVsPrisma from '../_components/ZenStackVsPrisma';
import StackBlitzGithub from '@site/src/components/StackBlitzGithub';

# Input Validation

<ZenStackVsPrisma>
Input validation is a ZModel feature and doesn't exist in Prisma.
</ZenStackVsPrisma>

:::warning
Input validation is only applied to the ORM APIs like `create`, `update`, etc. It's not enforced at the query builder level.
:::

When defining a model field in ZModel, you specify its type, which provides a basic level of runtime validation - when an incompatible value is passed to such field during creation or update, the underlying database will reject the operation.

However, oftentimes you want to expression more fine-grained validation rules, such as field length, string format, or numeric range, etc. ZModel provides a set of built-in field-level validation attributes, like `@length`, `@email`, etc. for this purpose. See [Input Validation](../reference/zmodel/input-validation.md) for more details.

To support more complex rules, a powerful `@@validate` model-level attribute is provided to allow expression rules using multiple fields and logical operators. Inside the `@@validate` attribute, functions like `length()`, `isEmail()` etc. are available for building up expressions. See [Input Validation](../reference/zmodel/input-validation.md) for the full list of available functions.

Arguments of mutation operations are validated before sending to the database. When a validation rule is violated, a `InputValidationError` exception is thrown, containing details about the violations.

Internally, ZenStack uses [Zod](https://zod.dev/) to perform validation. Most of the attributes and functions are 1:1 mapped to Zod APIs.

## Samples

<StackBlitzGithub repoPath="zenstackhq/v3-doc-orm-validation" codeFiles={['zenstack/schema.zmodel', 'main.ts']} />
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 10
description: Computed fields in ZModel
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 11
description: Polymorphic models
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 12
description: Strongly typed JSON fields
---

Expand All @@ -19,5 +18,4 @@ ZModel allows you to define custom types and use them to [type JSON fields](../m

## Samples


<StackBlitzGithub repoPath="zenstackhq/v3-doc-orm-typed-json" codeFiles={['zenstack/schema.zmodel', 'main.ts']} />
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 14
description: Setup logging
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sidebar_position: 15
description: TypeScript types derived from the ZModel schema
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
---
sidebar_position: 16
description: ORM Errors
---

# Errors

The ORM uses the following error classes from `@zenstackhq/runtime` to represent different types of failures:

## `ValidationError`
## `InputValidationError`

This error is thrown when the argument passed to the ORM methods is invalid, e.g., missing required fields, or containing unknown fields. The `cause` property is set to the original error thrown during validation.

If [input validation](../orm/Validation.md) is used, this error is also thrown when the validation rules are violated.

## `NotFoundError`

This error is thrown when a requested record is not found in the database, e.g., when calling `findUniqueOrThrow`, `update`, etc.

## `QueryError`

This error is used to encapsulate all other errors thrown from the underlying database driver. The `cause` property is set to the original error thrown.

## `RejectedByPolicyError`

This error is thrown when an operation is rejected by [access control policies](../orm/access-control/index.md).
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 17
description: Database schema migrations
---

# Database Migration
Expand Down
Loading