/workspace/scopes

The scopes module exports the getScopes method which returns the complete set of templateScopes defined in the workspace.

A templateScope is only recorded in workspace.scopes{} when the object which defines it is composed. The getScopes method therefore composes every locale, nested locale, and layer with role checks bypassed before the scopes are read.

Requires

Methods

(inner) checkScope(templateScope, roles) → {boolean}

The checkScope method checks whether the user has access to the object based on the provided roles and templateScope.

The method is exported so that hosts which resolve roles outside the workspace API can evaluate scope strings with the same semantics applied during composition.

If the roles parameter is falsy, the method will return false.

If the roles parameter is true, the method will return true.

If the roles parameter is an array, the method will check whether the templateScope string is included in the roles array. If so, it will return true.

Parameters:
NameTypeDescription
templateScopearray
rolesarray
Returns:

Returns true if the user has access based on the roles and templateScope.

Type: 
boolean

(async, inner) composeNestedLocales(locale)

The method iterates the locale.locales array property and composes each nested locale so that the templateScopes of nested locales are recorded.

The method is called recursively to compose further nested locales.

Parameters:
NameTypeDescription
localeObject

The composed locale.

Properties
NameTypeAttributesDescription
locale.localesArray<optional>

An array of nested locale keys.

locale.keysArray<optional>

The locale key chain of a nested locale.

(async, inner) getScopes() → {Promise.<Set.<string>>}

The workspace cache is rebuilt and all sources are cached before every locale is composed. Composition is required to populate the workspace.scopes{} set.

Locales are composed with the roles parameter set to true so that every templateScope is recorded regardless of role access. The composed locales are discarded; only the scopes recorded during composition are returned.

Returns:

The set of templateScopes defined in the workspace.

Type: 
Promise.<Set.<string>>

(inner) scopesArray(scopes) → {Array.<string>}

The method returns a sorted array of scope strings with empty scopes removed.

Parameters:
NameTypeDescription
scopesSet.<string>

Set of scope strings.

Returns:

Sorted array of scope strings.

Type: 
Array.<string>

(inner) scopesTree(scopes) → {Object}

The method converts a set of dot delimited scope strings into a nested tree structure.

Parameters:
NameTypeDescription
scopesSet.<string>

Set of scope strings.

Returns:

The scopes tree.

Type: 
Object