extends feature.
This lets you write rules that apply to a general type and automatically apply to all of its subtypes.
Actor and Resource Types
Every actor or resource declaration in Polar implicitly extends the abstract Actor or Resource types.
This means that any rule that references Actor can also accept types declared as actor.
Consider this policy snippet:
| Supertype | Subtype |
|---|---|
Actor | User |
Resource | Issue |
User is a subtype of Actor, and Issue is a subtype of Resource. Polar’s type system ensures that subtype values can be used wherever their supertypes appear.
Type Inheritance With extends
Actor Extends Resource
The built-in Actor type extends Resource. This means any parameter expecting a Resource value will also accept an Actor.
As a result, you can define roles, permissions, and relations over actors using actor resource blocks. While uncommon, this is useful when modeling authorization logic over user-like entities.
Extending Custom Types
Use theextends keyword to define custom inheritance relationships:
- Rule polymorphism: rules written for a supertype apply to all its subtypes.
- Inheritance: subtypes inherit permissions, roles, and relations defined on the supertype.
Rule Polymorphism
Subtype values satisfy rules defined over their supertypes. For example:Inherited Roles, Permissions, and Relations
Subtypes inherit all roles, permissions, and relations from their supertype. The supertype definition remains unchanged. Example:Details
Unification
Subtype values do not unify with their supertypes. For example, given the following definition:false:
Query Type Filtering
Query filters do not match subtypes. For example:Document values, even with a wildcard: