diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 2ef4532b9..f8d2b40fe 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,7 +1,7 @@ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs -name: Build Test CI +name: CI on: push: diff --git a/README.md b/README.md index f85a92c39..b0fd9ef25 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ + diff --git a/docs/get-started/learning-the-zmodel-language.md b/docs/get-started/learning-the-zmodel-language.md index 43a55bb9b..1850d3216 100644 --- a/docs/get-started/learning-the-zmodel-language.md +++ b/docs/get-started/learning-the-zmodel-language.md @@ -188,9 +188,11 @@ model User { ``` +This document serves as a quick overview for starting with the ZModel language. For more thorough explanations about data modeling, please check out [Prisma's schema references](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference). + ## Access policies -Access policies use `@@allow` and `@@deny` rules to specify the eligibility of an operation over a model entity. The signatures of the attributes are: +Access policies express authorization logic in a declarative way. They use `@@allow` and `@@deny` rules to specify the eligibility of an operation over a model entity. The signatures of the attributes are: ```prisma @@allow(operation, condition) @@ -374,6 +376,70 @@ In this example, `user` refers to `user` field of `Membership` model because `sp Please check out the [Collaborative Todo](../../samples/todo) for a complete example on using access policies. -## Summary +## Field constraints -This document serves as a quick overview for starting with the ZModel language. For more thorough explanations about data modeling, please check out [Prisma's schema references](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference). +Field constraints are used for attaching constraints to field values. Unlike access policies, field constraints only apply on individual fields, and are only checked for 'create' and 'update' operations. + +Internally ZenStack uses [zod](https://github.com/colinhacks/zod) for validation. The checks are run in both the server-side CURD services and the clent-side React hooks. For the server side, upon validation error, HTTP 400 is returned with a body containing a `message` field for details. For the client side, a `ValidationError` is thrown. + +The following attributes can be used to attach field constraints: + +### String: + +- `@length(_ min: Int?, _ max: Int?)` + + Validates length of a string field. + +- `@startsWith(_ text: String)` + + Validates a string field value starts with the given text. + +- `@endsWith(_ text: String)` + + Validates a string field value ends with the given text. + +- `@email()` + + Validates a string field value is a valid email address. + +- `@url()` + + Validates a string field value is a valid url. + +- `@datetime()` + + Validates a string field value is a valid ISO datetime. + +- `@regex(_ regex: String)` + + Validates a string field value matches a regex. + +### Number: + +- `@gt(_ value: Int)` + + Validates a number field is greater than the given value. + +- `@gte(_ value: Int)` + + Validates a number field is greater than or equal to the given value. + +- `@lt(_ value: Int)` + + Validates a number field is less than the given value. + +- `@lte(_ value: Int)` + + Validates a number field is less than or equal to the given value. + +### Sample usage + +```prisma +model User { + id String @id + handle String @regex("^[0-9a-zA-Z]{4,16}$") + email String @email @endsWith("@myorg.com") + profileImage String? @url + age Int @gt(0) +} +``` diff --git a/docs/get-started/next-js.md b/docs/get-started/next-js.md index 0471c6a88..9057c12c0 100644 --- a/docs/get-started/next-js.md +++ b/docs/get-started/next-js.md @@ -11,7 +11,7 @@ Here we demonstrate the process with a simple Blog starter using [Next-Auth](htt 2. Create a new Next.js project from the ZenStack starter ```bash -npx create-next-app [project name] --use-npm -e https://github.com/zenstackhq/nextjs-auth-starter +npx create-next-app --use-npm -e https://github.com/zenstackhq/nextjs-auth-starter [project name] cd [project name] ```