Roles

envless.roles.iterate()

Stream roles one row at a time

ts
iterate(options?: RoleListOptions): AsyncGenerator<RoleResource, void, undefined>

Yields roles individually, fetching the next page only once the current one is drained. Role sets are small, so this exists mainly for symmetry with the other collections and for the ability to stop as soon as you find the row you wanted.

It returns an async generator, not a promise, so do not await the call itself: put it straight into a for await loop. No request is issued until the first iteration, and breaking out of the loop leaves any remaining pages unfetched.

Example

ts
for await (const role of envless.roles.iterate()) {
    if (role.isSystem) continue

    console.log(role.name, role.permissions.length)
}

Parameters

ParameterTypeRequiredDescription
options.limitnumberNoPage size fetched behind the scenes, clamped to 100.
options.offsetnumberNoRow to start streaming from.
options.searchstringNoCase insensitive substring match against role name and description.
options.sortByRoleSortNoOrder within each group: name (the default) is A to Z, updated and created are newest first. System roles always come first.
options.signalAbortSignalNoCancels the in flight page request and ends the stream.

Returns

An AsyncGenerator that yields RoleResource values until the pages run out.

Reads the roles collection. list returns one page as { items, pagination }, listAll collects every page into an array, and iterate streams one item at a time without buffering the whole set.

Worth knowing

  • The offset advances by the number of rows actually received, so a role created mid walk can shift the window.
  • System roles are yielded before custom roles, so a loop that breaks on the first row always sees a system role.

Required scopes

roles:read

Underlying endpoint

GET /roles

Request and response schema, every error code, and a live playground.

In Python

envless.roles.iterate()

The same method in envless-sdk, the Python SDK, with the same request, retries and errors.

In Ruby

Envless.roles.iterate

The same method in envless-sdk, the Ruby gem, with the same request, retries and errors.

In PHP

$envless->roles->iterate()

The same method in envless/sdk, the PHP SDK, with the same request, retries and errors.