Skip to main content

Function: withRoleScaffold()

withRoleScaffold<S, Grantable, RoleType, Assignee, Prefix>(schema, opts): RoleScaffoldedSchema<S, Grantable, RoleType, Assignee, Prefix>

Defined in: packages/polizy/src/role-scaffold.ts:110

Merge the runtime-roles scaffold into a schema, preserving literal types.

Type Parameters​

S​

S extends AuthSchema<any, any, any, any, any>

Grantable​

Grantable extends readonly keyof S["actionToRelations"] & string[]

RoleType​

RoleType extends string = "role"

Assignee​

Assignee extends string = "assignee"

Prefix​

Prefix extends string = "cap_"

Parameters​

schema​

S

opts​

assigneeRelation?​

Assignee

Reserved group relation for user->role membership. Default "assignee".

capPrefix?​

Prefix

Prefix for the per-action capability relations. Default "cap_".

grantable​

Grantable

roleType?​

RoleType

Object type for role objects. Default "role".

Returns​

RoleScaffoldedSchema<S, Grantable, RoleType, Assignee, Prefix>

Example​

const schema = withRoleScaffold(baseSchema, {
grantable: ["view_bookings", "issue_refunds"],
});
// `role` object type, `assignee` group relation, and `cap_view_bookings` /
// `cap_issue_refunds` direct relations are now part of `schema`.