-
-
Notifications
You must be signed in to change notification settings - Fork 37
doc: v3 access policy and input validation #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule v3-doc-orm-policy
added at
898e2d
Submodule v3-doc-orm-validation
added at
c86439
1 change: 0 additions & 1 deletion
1
...ioned_docs/version-3.x/orm/quick-start.md → ...ed_docs/version-3.x/orm/01-quick-start.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 1 | ||
| description: Quick start guide | ||
| --- | ||
|
|
||
|
|
||
1 change: 0 additions & 1 deletion
1
versioned_docs/version-3.x/orm/cli.md → versioned_docs/version-3.x/orm/02-cli.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 2 | ||
| description: Using the CLI | ||
| --- | ||
|
|
||
|
|
||
1 change: 0 additions & 1 deletion
1
versioned_docs/version-3.x/orm/client.md → versioned_docs/version-3.x/orm/03-client.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 3 | ||
| description: Creating a database client | ||
| --- | ||
|
|
||
|
|
||
1 change: 0 additions & 1 deletion
1
...ned_docs/version-3.x/orm/query-builder.md → ..._docs/version-3.x/orm/05-query-builder.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 5 | ||
| description: Query builder API | ||
| --- | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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']} /> | ||
1 change: 0 additions & 1 deletion
1
...d_docs/version-3.x/orm/computed-fields.md → ...ocs/version-3.x/orm/10-computed-fields.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 10 | ||
| description: Computed fields in ZModel | ||
| --- | ||
|
|
||
|
|
||
1 change: 0 additions & 1 deletion
1
...oned_docs/version-3.x/orm/polymorphism.md → ...d_docs/version-3.x/orm/11-polymorphism.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 11 | ||
| description: Polymorphic models | ||
| --- | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
versioned_docs/version-3.x/orm/logging.md → versioned_docs/version-3.x/orm/14-logging.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| --- | ||
| sidebar_position: 14 | ||
| description: Setup logging | ||
| --- | ||
|
|
||
|
|
||
1 change: 0 additions & 1 deletion
1
...ed_docs/version-3.x/orm/inferred-types.md → ...docs/version-3.x/orm/15-inferred-types.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| --- | ||
|
|
||
|
|
||
9 changes: 7 additions & 2 deletions
9
versioned_docs/version-3.x/orm/errors.md → versioned_docs/version-3.x/orm/16-errors.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
2 changes: 1 addition & 1 deletion
2
versioned_docs/version-3.x/orm/migration.md → ...oned_docs/version-3.x/orm/17-migration.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| --- | ||
| sidebar_position: 17 | ||
| description: Database schema migrations | ||
| --- | ||
|
|
||
| # Database Migration | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.