Skip to main content

Schema Reference

This page provides a reference for the defineSchema options, relation types, and AuthSystem configuration parameters.

For a task-oriented guide on how to configure your schema, see Defining a Schema.


defineSchema Options

OptionTypeRequired?DefaultDescription
relationsRecord<string, RelationDefinition>YesMaps relation names to their definition type (direct, group, or hierarchy).
actionToRelationsRecord<string, string[]>YesMaps action names to an array of relations that grant the action.
subjectTypesstring[]No[]List of allowed subject types. Restricts subject types checked or granted at compile-time.
objectTypesstring[]No[]List of allowed object types. Restricts object types checked or granted at compile-time.
hierarchyPropagationRecord<string, string[]>NoundefinedDefines how actions flow down from parent objects to child objects.
fieldLevelObjectsstring[]No[]Object types that support field-level identifiers.
fieldSeparatorstringNo"#"Character that separates an object ID from a field name.

Relation Types

TypeSemanticsExample
directA direct link between a subject and an object.A user is the owner of a document.
groupLinks a subject to a grouping resource (allows nested check traversal).A user is a member of a team.
hierarchyLinks a child object to a parent object to propagate permissions.A document is inside a folder.

AuthSystem Constructor Options

OptionTypeRequired?DefaultDescription
storageStorageAdapterYesThe storage adapter to persist and retrieve relationship tuples.
schemaAuthSchemaYesThe schema returned by defineSchema.
defaultCheckDepthnumberNo20Maximum number of recursive hops allowed during group or hierarchy checks.
maxDepthBehavior"throw" | "deny"No"throw"Action when recursion exceeds maximum depth. "throw" raises a MaxDepthExceededError. "deny" returns false.
loggerLoggerNoNo-op loggerLogger instance (e.g. console) used to write debug or execution details.
fieldSeparatorstringNoSchema's separator or "#"Overrides the character used to separate object IDs from field names.

Additional Configuration Details

hierarchyPropagation Shape

The hierarchyPropagation object maps a child action to an array of parent actions that satisfy it:

hierarchyPropagation: {
[childActionName: string]: string[] // array of parent action names
}

When evaluating a permission check on a child object, if no direct grants are found, polizy traverses up the hierarchy using relations of type hierarchy. It then checks if the subject can perform any of the mapped parent actions on the parent object.

For details on implementing nesting, see the Folder Inheritance Guide.

fieldLevelObjects and fieldSeparator

When an object type is listed in fieldLevelObjects, you can check permissions on specific fields using the following separator syntax:

// subject: user:alice
// action: edit
// object: document:doc1#body

polizy automatically splits the object ID from the field identifier at the defined fieldSeparator (e.g. "#" or custom separator).

For details on implementing fine-grained field permissions, see the Field-Level Permissions Guide.