Skip to content

Query

Defined in: src/core/Query.ts:12

Represents the inner Query class that helps build an access information for querying and checking permissions, from the underlying grants model. You can get a first instance of this class by calling AccessControl#can(<role>) method.

with(context): Query

Defined in: src/core/Query.ts:92

Supplies per-check context data, readable from grant conditions via $.. Merges over any ambient/earlier context (later wins). The fluent equivalent of passing context as the 2nd argument of AccessControl#can().

UnknownObject

The context data bag for this check.

Query

  • Self instance of Query.

role(role): Query

Defined in: src/core/Query.ts:106

A chainer method that sets the role(s) for this Query instance.

string | string[]

A single or array of roles.

Query

  • Self instance of Query.

resource(resource): Query

Defined in: src/core/Query.ts:116

A chainer method that sets the resource for this Query instance.

string

Target resource for this Query instance.

Query

  • Self instance of Query.

action(actionSpec, resource?): Permission

Defined in: src/core/Query.ts:132

Generic check entry for any action — CRUD or custom. The CRUD query methods are named sugar over this. actionSpec may carry possession via the :own/:any convention (omit ⇒ any).

string

Action name, optionally name:own/name:any.

string

Target resource.

Permission

  • The resolved Permission.
ac.can('author', { user, article }).action('publish:own', 'article').granted;

do(actionSpec, resource?): Permission

Defined in: src/core/Query.ts:145

The single sanctioned alias of Query#action. Generic: CRUD and custom. e.g. ac.can('admin').do('update') / .do('publish', 'article').

string

Action name, optionally name:own/name:any.

string

Target resource.

Permission

  • The resolved Permission.

createOwn(resource?): Permission

Defined in: src/core/Query.ts:163

Queries the underlying grant model and checks whether the current role(s) can “create” their “own” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

createAny(resource?): Permission

Defined in: src/core/Query.ts:181

Queries the underlying grant model and checks whether the current role(s) can “create” “any” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

readOwn(resource?): Permission

Defined in: src/core/Query.ts:206

Queries the underlying grant model and checks whether the current role(s) can “read” their “own” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

readAny(resource?): Permission

Defined in: src/core/Query.ts:224

Queries the underlying grant model and checks whether the current role(s) can “read” “any” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

updateOwn(resource?): Permission

Defined in: src/core/Query.ts:249

Queries the underlying grant model and checks whether the current role(s) can “update” their “own” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

updateAny(resource?): Permission

Defined in: src/core/Query.ts:267

Queries the underlying grant model and checks whether the current role(s) can “update” “any” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

deleteOwn(resource?): Permission

Defined in: src/core/Query.ts:292

Queries the underlying grant model and checks whether the current role(s) can “delete” their “own” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.

deleteAny(resource?): Permission

Defined in: src/core/Query.ts:310

Queries the underlying grant model and checks whether the current role(s) can “delete” “any” resource.

string

Defines the target resource to be checked. This is only optional if the target resource is previously defined. If not defined and omitted, this will throw.

Permission

  • An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
  • If the access query instance to be committed has any invalid data.