Skip to content

Type inconsistency cause TypeError with policy/PolicyDef option #639

@genehynson

Description

@genehynson

I am overriding the default location of the access policy files with:

plugin accesspolicy {
  provider = '@core/access-policy'
  output = '../api/src/generated/zenstack'
}

And am importing it as such:

import policy from './generated/zenstack/policy';

And using the import like this:

const db = enhance(new PrismaClient(), getUser(), {modelMeta: metadata, policy});

And am getting this TypeError on policy:

 Type '{ create: (context: QueryContext) => any; update: boolean; postUpdate: boolean; read: (context: QueryContext) => any; delete: (context: QueryContext) => any; }' is not assignable to type 'Partial<Record<PolicyOperationKind, PolicyFunc>>'.
            Types of property 'update' are incompatible.
              Type 'boolean' is not assignable to type 'PolicyFunc'.

Here is the access policy definitions on my User model:

@@deny('all', auth() == null)
@@allow('all', auth() == this || auth().id == 1)

And here is the generated Policy for User:

declare const policy: {
    guard: {
        user: {
            create: typeof User_create;
            update: boolean;
            postUpdate: boolean;
            read: typeof User_read;
            delete: typeof User_delete;
        };
...

It seems to be complaining about the boolean type of update.

Discussed further here: https://discord.com/channels/1035538056146595961/1068743295863369858/1142972251554189392

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions