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.
Methods
Section titled “Methods”with()
Section titled “with()”with(
context):Query
Defined in: src/core/Query.ts:89
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().
Parameters
Section titled “Parameters”context
Section titled “context”The context data bag for this check.
Returns
Section titled “Returns”Query
- Self instance of
Query.
role()
Section titled “role()”role(
role):Query
Defined in: src/core/Query.ts:103
A chainer method that sets the role(s) for this Query instance.
Parameters
Section titled “Parameters”string | string[]
A single or array of roles.
Returns
Section titled “Returns”Query
- Self instance of
Query.
resource()
Section titled “resource()”resource(
resource):Query
Defined in: src/core/Query.ts:113
A chainer method that sets the resource for this Query instance.
Parameters
Section titled “Parameters”resource
Section titled “resource”string
Target resource for this Query instance.
Returns
Section titled “Returns”Query
- Self instance of
Query.
action()
Section titled “action()”action(
actionSpec,resource?):Permission
Defined in: src/core/Query.ts:129
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).
Parameters
Section titled “Parameters”actionSpec
Section titled “actionSpec”string
Action name, optionally name:own/name:any.
resource?
Section titled “resource?”string
Target resource.
Returns
Section titled “Returns”- The resolved
Permission.
Example
Section titled “Example”ac.can('author', { user, article }).action('publish:own', 'article').granted;do(
actionSpec,resource?):Permission
Defined in: src/core/Query.ts:142
The single sanctioned alias of Query#action. Generic: CRUD and
custom. e.g. ac.can('admin').do('update') / .do('publish', 'article').
Parameters
Section titled “Parameters”actionSpec
Section titled “actionSpec”string
Action name, optionally name:own/name:any.
resource?
Section titled “resource?”string
Target resource.
Returns
Section titled “Returns”- The resolved
Permission.
createOwn()
Section titled “createOwn()”createOwn(
resource?):Permission
Defined in: src/core/Query.ts:160
Queries the underlying grant model and checks whether the current role(s) can “create” their “own” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
createAny()
Section titled “createAny()”createAny(
resource?):Permission
Defined in: src/core/Query.ts:178
Queries the underlying grant model and checks whether the current role(s) can “create” “any” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
readOwn()
Section titled “readOwn()”readOwn(
resource?):Permission
Defined in: src/core/Query.ts:203
Queries the underlying grant model and checks whether the current role(s) can “read” their “own” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
readAny()
Section titled “readAny()”readAny(
resource?):Permission
Defined in: src/core/Query.ts:221
Queries the underlying grant model and checks whether the current role(s) can “read” “any” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
updateOwn()
Section titled “updateOwn()”updateOwn(
resource?):Permission
Defined in: src/core/Query.ts:246
Queries the underlying grant model and checks whether the current role(s) can “update” their “own” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
updateAny()
Section titled “updateAny()”updateAny(
resource?):Permission
Defined in: src/core/Query.ts:264
Queries the underlying grant model and checks whether the current role(s) can “update” “any” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
deleteOwn()
Section titled “deleteOwn()”deleteOwn(
resource?):Permission
Defined in: src/core/Query.ts:289
Queries the underlying grant model and checks whether the current role(s) can “delete” their “own” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.
deleteAny()
Section titled “deleteAny()”deleteAny(
resource?):Permission
Defined in: src/core/Query.ts:307
Queries the underlying grant model and checks whether the current role(s) can “delete” “any” resource.
Parameters
Section titled “Parameters”resource?
Section titled “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.
Returns
Section titled “Returns”- An object that defines whether the permission is granted; and the resource attributes that the permission is granted for.
Throws
Section titled “Throws”- If the access query instance to be committed has any invalid data.