Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

docs/reference/zmodel-language

ZModel language references

https://zenstack.dev/docs/reference/zmodel-language

You must be logged in to vote

Replies: 3 comments · 2 replies

Comment options

I would like to understand better how to create custom functions. I went to the linked github page regarding this. However, none of the functions seem to have code in them. It looks like TS but I'm not sure 🤷🏻‍♂️ Also, I can't find any references to these @@@ directives following the function in these docs. I suspect custom functions could help me construct complex conditional arguments more succinctly.

You must be logged in to vote
1 reply
@ymc9giscus
Comment options

ymc9 Apr 16, 2024 — with giscus
Maintainer

Hi, one thing I want to clarify first is the ZModel functions are not directly implemented in TS. They are compiled in different ways by the CLI based. For example, the startsWith(title, 'foo') function call is compiled into a partial Prisma query like:

{
  title: {
    startsWith: 'foo'
  } 
}

That part of compilation/transformation is open for extension yet. But I'd like to understand the specific goal you want to achieve here. Thanks!

Comment options

Hi, one thing I want to clarify first is the ZModel functions are not directly implemented in TS. They are compiled in different ways by the CLI based. For example, the startsWith(title, 'foo') function call is compiled into a partial Prisma query like:

{
  title: {
    startsWith: 'foo'
  } 
}

That part of compilation/transformation is open for extension yet. But I'd like to understand the specific goal you want to achieve here. Thanks!

Thanks for taking interest in my goals. My access control conditions are getting a bit wild and I was wondering if I could write a custom function for this. i.e. I have a nested permission structure so I end up doing something like this

@@allow('all',
        regions?[admins?[user == auth()]] ||
        parentCalendarGroup.regions?[admins?[user == auth()]] ||
        parentCalendarGroup.parentCalendarGroup.regions?[admins?[user == auth()]] ||
        parentCalendarGroup.parentCalendarGroup.parentCalendarGroup.regions?[admins?[user == auth()]]
    )

This is only going to get hairier if/when I introduce administrative priveledges to each level of the group hierarchy. I have already done some code generation for copy-pasting into my queries since that seems to be the only way that the types work properly in prisma 😑. Maybe I should just do that or it might not be worth it 🤷🏻‍♂️ ... the IDE support in Webstorm is pretty great! 👍 Partly just curious about all the functionality of the library.

You must be logged in to vote
1 reply
@ymc9giscus
Comment options

ymc9 Apr 17, 2024 — with giscus
Maintainer

Got it.

I see you've already found the feature request here: zenstackhq/zenstack#276

Do you think the solution being discussed over there (reducing duplication by delegating permission check to a relation field) will partly solve your problem?

Comment options

Any way to filter something out, based on the count of relations?

I.e. @@deny('all', members[count() < 2])

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.