Skip to content

[Feature Request] Separate files for model-level policies or validation #1077

@nwidynski

Description

@nwidynski

Is your feature request related to a problem? Please describe.
When developing complex access policies or validation a single zmodel can quickly get very chaotic.

Describe the solution you'd like
A way to put model-level access policies and validation in a separate file or abstract model.

Describe alternatives you've considered
We tried creating abstract models, which contain the model-level policies, but for Zenstack to recognize the fields
we would have to extend a common base model, which it then complains is extended from multiple times.

abstract model CounterSchema {
  name String
  value Int
}

//! If we don't extend CounterSchema here, Zenstack doesn't recognize "value"
abstract model CounterCreate extends CounterSchema {
  @@allow("create", value >= 0)
}

//! If we don't extend CounterSchema here, Zenstack doesn't recognize "name"
abstract model CounterRead extends CounterSchema {
  @@allow("read", name == "It should be readable")
}

//! This fails compilation because CounterSchema is extended twice
model Counter extends CounterCreate, CounterRead {
  id String @id
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions