Releases: zenstackhq/zenstack
ZenStack Release v2.3.3
ZenStack Release v2.3.2
ZenStack Release v2.3.1
What's Changed
- Fixed incorrect prisma query executed when
count
uses a where filter involving a polymorphic base field #1585 - Fixed over-strict typing generated for
auth()
access #1589 - Fixed compatibility issue between
createManyAndReturn
and polymorphism #1576 - Fixed the issue that field-level override rules don't work with non-optional to-one relations #1574
Full Changelog: v2.3.0...v2.3.1
ZenStack Release v2.3.0
New Features
-
The new
check()
policy function that allows you to delegate a models' permission checking to its relations. #276model Todo { ... list List @relation(fields: [listId], references: [id]) // if the parent list is readable, grant full access to this Todo entity @@allow('all', check(list, 'read')) }
You can use this feature to remove duplicated policy rules and keep the schema DRY. See a full guide here.
-
Prisma 5.16.x is now supported. The new Prisma version introduced a typing breaking change. An adaptation is added in this version of ZenStack.
Documentation
- New guide for integrating with Lucia Auth!
Fixes and Improvements
- Runtime error with disconnecting a self-relation #1530
- Incorrect query result when using
Prisma.DbNull
to filter JSON fields #1533 - Fixed the issue that using
@length
on a@password
field checks the length of hash password rather than the original value #1502 - Typing conflict with Prisma client extension (with polymorphism or
auth()
in@default()
is used) #1493 - IDE formatting issue when
Unsupported
type is used #1517 - Runtime error when creating a polymorphic model that inherits from an abstract model #1560
- Set timeout for checking newer versions when running CLI to avoid hangs under unstable network #1529
- Typing issue in generated hooks for vue-query #1564
- Excluded
create
andupsert
for delegate models from generated hooks and trpc routers, as they cannot be directly created. - When generation
@relation
for delegate models, user-provided relation name should be used if it exists #1575 by @irvinzz - SWR is now added as a peer dependency of
@zenstackhq/swr
plugin. - The ZenStack monorepo has enabled corepack to enforce a consistent version of pnpm.
New Contributors
Thanks to @jasonmacdonald @benjamintd @irvinzz @mentorkadriu for contributing to this release! ❤️
Full Changelog: v2.2.4...v2.3.0
ZenStack Release v2.2.4
What's Changed
This release contains several fixes related to polymorphic models.
- When a concrete model is created with an explicit id field, make sure the field is pushed down to the base model's payload#1518
- Make sure concrete model's fields are included when its included from a deeply nested context #1522
- Convert polymorphic model's
createMany
payload into regularcreate
#1520
Full Changelog: v2.2.3...v2.2.4
ZenStack Release v2.2.3
What's Changed
- Fixed an incorrect validation error when checking for cross-model field comprisons.
Full Changelog: v2.2.2...v2.2.3
ZenStack Release v2.2.2
What's Changed
- Fixed incorrect identification of cross-model field comparison that hindered performance #1506 #1507.
- Improved validation of cross-model field comparison.
- Fixed the regression that when a field-level policy has no
@allow
rule, the access is always denied #1501
Full Changelog: v2.2.1...v2.2.2
ZenStack Release v2.2.1
What's Changed
- Fixed a typing issue with TanStack vue-query infinite queries.
Full Changelog: v2.2.0...v2.2.1
ZenStack Release v2.2.0
New Features
1. Comparing fields from different models in mutation policies #1463
Previous versions of ZenStack had an unintuitive limitation that you can't compare fields from different models in policy rules. E.g., the following snippet was not valid:
model Post {
...
org Organization @relation(...)
orgId Int
author User @relation(...)
authorId Int
@@allow('update', orgId == author.orgId) // orgId and author.orgId are from different models
}
This release partly resolved the limitation by supporting such comparisons in mutation rules ("create," "update," and "delete").
Cross-model field comparison is not natively supported by Prisma, so ZenStack has to read the data out of the database and check the rules in the JS runtime. When ZenStack identifies a policy rule that involves such a comparison, the entire rule will be evaluated "post-read". Although it's usually not a big deal for mutation operations, you should be aware of the performance impact. For best performance, put expressions involving cross-model comparison into separate policy rules (so that other rules are still evaluated during database queries).
Cross-model field comparison is still not supported in "read" rules for two reasons:
- It's very easy to result in reading an unbounded number of rows, filtering and discarding most of them.
- It should be noted that "read" rules cover not only find but also aggregations. If we can't do a filtered aggregation on the database side, we'll have to reimplement it in the ZenStack library.
Please provide feedback in our discord if it's important for you.
2. Added support for Prisma 5.14's new createManyAndReturn
API #1461
The returned results are properly filtered by access policies.
3. Relation filtering now respects field-level policies #1454
Background: ZenStack's "read" policy rules control not only what data you can retrieve but also how filters work. For example, in the following schema and query:
model Post {
...
deleted Boolean
@@allow('read', !deleted)
}
db.user.findMany({ where: { posts: { some: { published: true } } } });
Post
model's read rules will be injected into the where
clause, like:
db.user.findMany({
where: {
posts: {
some: {
published: true, // user-provided filter
deleted: false // ZenStack injected filter
}
}
});
In previous versions of ZenStack, such filter injection only respected model-level policies but not field-level ones. This release fixes this missing part. For fields involved in filters, if they have field-level "read" rules, those rules will also be combined into the final filter. The consequence is, for the above example, if the published
field is not readable, the findMany
will result in an empty array.
The injection also respects "override" field-level rules, meaning that even if the Post
model is not readable, but you have a field-level "read" rule for the published
field that overrides the model-level policy, the published
field can be used in the filter.
Fixes and Improvements
- Fixed Windows build issues and improved contribution documentation by @WimTibackx
- Fixed default value handling for BigInt type in Zod schemas by @aloisklink
- Upgraded Prisma peer dependency to <= 5.15.x
- Fixed typing issues in TanStack Query's infinite query hooks #1472
- Fixed typing issues in TanStack Query hooks generated for Svelte #1488
- Fixed overlong identifier names generated in Prisma schemas generated for polymorphic models #1466
- Fixed incorrect validation errors for polymorphic models inherited from an abstract base model #1474
- Fixed Decimal/Date object corruption when used with polymorphic models #1487
- Fixed runtime error when using polymorphic models with optional relation fields #1483
Docs Updates
-
Clerk integration guide now has sample code for Next.js app router
https://zenstack.dev/docs/guides/authentication/clerk#create-an-enhanced-prisma-client
New Contributors
Welcome @WimTibackx and @aloisklink as our new contributors!
Full Changelog: v2.1.2...v2.2.0
ZenStack Release v2.1.2
What's Changed
- Allow using type names (
Int
,String
,DateTime
, etc.) as enum field names in ZModel #1399 by @francistogram
New Contributors
Welcome @francistogram as our new contributor!
Full Changelog: v2.1.1...v2.1.2