/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.
The composition is expensive. The composition promise is stored against the cached workspace object so repeat requests share one composition until the workspace cache is rebuilt.
- Source
Requires
Members
(inner, constant) compositionMap
Module scope map of composition promises keyed by the cached workspace object. A rebuilt workspace cache is a new object which does not have an entry in the map. Entries for discarded workspace objects are garbage collected.
- Source
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.
| Name | Type | Description |
|---|---|---|
templateScope | array | |
roles | array |
- Source
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.
| Name | Type | Description |
|---|---|---|
locale | Object | The composed locale. |
| Name | Type | Attributes | Description |
|---|---|---|---|
locale.locales | Array | <optional> | An array of nested locale keys. |
locale.keys | Array | <optional> | The locale key chain of a nested locale. |
- Source
(async, inner) composeWorkspaceScopes(workspace) → {Promise.<Set.<string>>}
All sources are cached before every locale, nested locale, and layer is composed with role checks bypassed.
| Name | Type | Description |
|---|---|---|
workspace | Object | The cached workspace. |
- Source
The workspace.scopes{} set.
- Type:
- Promise.<Set.<string>>
(async, inner) getScopes(forceopt) → {Promise.<Set.<string>>}
The cached workspace is retrieved from the workspace cache. The cache is only rebuilt with the force param flag or when the WORKSPACE_AGE is exceeded.
All sources are cached before every locale is composed. Composition is required to populate the workspace.scopes{} set.
The composition promise is stored in the compositionMap against the workspace object. Repeat requests for the same cached workspace await the stored promise and do not compose the workspace again. A failed composition is removed from the map so a subsequent request will retry the composition.
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
force | boolean | <optional> | The workspace cache will be rebuilt with the force param flag. |
- Source
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.
| Name | Type | Description |
|---|---|---|
scopes | Set.<string> | Set of scope strings. |
- Source
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.
| Name | Type | Description |
|---|---|---|
scopes | Set.<string> | Set of scope strings. |
- Source
The scopes tree.
- Type:
- Object