github zenstackhq/zenstack v1.0.0-beta.3
ZenStack Release v1.0.0-beta.3

latest releases: v2.8.1, v2.8.0, v2.7.5...
16 months ago

New Features

  • [TRPC plugin] Improved typing for the generated routers #409
    The plugin can now generate extra helpers for improve typing of the trpc client side, so calling the CRUD routers now has the same experience as calling Prisma methods. E.g.:

    const post = trpc.post.findFirst({ include: { author: true } });

    The code above used to have a static typing of Post, although at runtime the data contains an author field. After applying the typing helper, the result is typed as Post & { author: User }.

    More details here: https://zenstack.dev/docs/reference/plugins/trpc#client-helpers

  • [Data Validation] Model-level validation rules #477

    A new model-level attribute @@validate is introduced to express more complex data validation rules. You can use it to write rules that involve multiple fields and combine boolean expressions. A set of validation functions are also added to support various kinds of field validation in a complex rule.

    model Model {
        x Int
        y String
        @@validate(x > 0 && contains(y, 'foo'), 'my custom condition')
    }

    Field-level validation attributes (like @email, etc.) are also extended with an optional error message parameter.

    More details here: https://zenstack.dev/docs/reference/zmodel-language#model-level-validation-attributes

  • [Zod Plugin] Generates zod schema for models, including validation rules #477

    In previous versions, @core/zod plugin only generated schemas for Prisma's CRUD input. It's got a renovation in this release and now generates three kinds of schemas:

    • models:
      Schemas for models, including flavors for full validation, create, and update. Data validation rules are included.
    • input:
      Schemas for Prisma CRUD method input. This is used by the trpc plugin to validate router input.
    • objects:
      Schemas for objects used by the "input" schemas. You usually don't need to use this.

    By default, the generated zod schemas are reexported through @zenstackhq/runtime/zod and can be directly imported and used.

    Error messages attached to validation rules are now carried over to the generated zod schemas. E.g.: email String @email('must be a valid email') is transformed to z.string().email('must be a valid email').

    Model-level validation rules written with @@validate are also supported and are transformed to z.refine. E.g., @@validate(x > 0 && contains(y, 'foo')) is transformed to z.object({...}).refine((value) => value.x > 0 && value.y?.includes('foo')).

Fixes and Improvements

  • Fixed the bug that SWR hooks call into wrong endpoint
  • tRPC plugin generated routers now support unchecked input types #499
  • Fixed incorrect policy code generation when a single boolean field is used as policy expression #509
  • Fixed issue about wrong reference resolution when there're enum fields with the same name #498
  • Fixed parser error when true or false are used as declaration name prefix #522
  • The REST API handler now returns the total count in the meta section for collection queries by @chemitaxis #527
  • Added contribution guide

New Contributors

Welcome @chemitaxis to the contributor family!

Full Changelog: v1.0.0-beta.1...v1.0.0-beta.3

Don't miss a new zenstack release

NewReleases is sending notifications on new releases.