IsRole

Copied!
( value )

Description

The IsRole function returns true only if value is a role, otherwise it returns false.

Parameters

Argument Type Definition and Requirements

value

Any

Any value, which is to be tested to determine whether it is a role or not.

Returns

Returns a boolean, indicating whether value was a role or not.

Examples

The following query uses Map to iterate over an array of all of the types of values that can be tested by a type-check function, passing each item into a Lambda function that returns an object, which contains the value and the result of calling IsRole with that value:

Copied!
client.query(
  q.(
    [
      ['array'],
      true,
      false,
      new Uint8Array([1, 2, 3, 4]),
      [0x1, 0x2, 0x3, 0x4],
      q.('Letters'),
      q.('credentials/self'),
      q.('child_db'),
      q.('2019-11-12'),
      q.(q.('Letters'), 123),
      10.1,
      q.('double'),
      q.('all_letters'),
      10,
      q.(q.(), '248967241620521472'),
      q.(q.('x', q.('x'))),
      null,
      { x: 10 },
      q.('employees'),
      q.(q.('all_letters')),
      'ten',
      '10',
      q.(),
      q.(q.(), '249062079147803136'),
    ],
    q.('x', {
      value: q.('x'),
      IsRole: q.(q.('x')),
    })
  )
)
.then((ret) => console.log(ret))
[ { value: [ 'array' ], IsRole: false },
  { value: true, IsRole: false },
  { value: false, IsRole: false },
  { value: Bytes("AQIDBA=="), IsRole: false },
  { value: [ 1, 2, 3, 4 ], IsRole: false },
  { value: ("Letters"), IsRole: false },
  { value: (Credentials(), "248967019900174848"),
    IsRole: false },
  { value: ("child_db"), IsRole: false },
  { value: ("2019-11-12"), IsRole: false },
  { value: (("Letters"), "123"), IsRole: false },
  { value: 10.1, IsRole: false },
  { value: ("double"), IsRole: false },
  { value: ("all_letters"), IsRole: false },
  { value: 10, IsRole: false },
  { value: ((), "248967241620521472"), IsRole: false },
  { value: (("x", ("x"))), IsRole: false },
  { value: null, IsRole: false },
  { value: { x: 10 }, IsRole: false },
  { value: ("employees"), IsRole: true },
  { value: (("all_letters")), IsRole: false },
  { value: 'ten', IsRole: false },
  { value: '10', IsRole: false },
  { value: ("2019-11-12T13:15:16.789Z"), IsRole: false },
  { value: ((), "249062079147803136"), IsRole: false } ]

This query operates on a pre-existing schema, which is not provided here.

Also, the query is executed via a client connection, that uses a secret acquired by calling Login (not shown here), so that Ref("credentials/self") returns a valid value.

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!