/workspace/getTemplate
The module exports the getTemplate method which is required by the query, languageTemplates, getLayer, and getLocale modules.
Requires
- module:/provider/getFrom
- module:/workspace/cache
- module:/utils/processEnv
Methods
(async, inner) getTemplate(template) → {Promise.<(Object|Error)>}
The workspace will be checked and cached by the Workspace API checkWorkspaceCache method.
The template parameter provided as a string from user input must be validated to only include whitelisted character.
A lookup for the template object in the cached workspace.templates{} will be performed.
The template will be returned without a src property.
Otherwise a lookup will be performed to check whether a template with a src property has been cached with the src as key in the workspace.templates{}.
An error will be returned if the getFrom method is unknown or unable to fetch from the template.src
A module template will be created from the response with the template.module flag.
In order to cache templates the fetched response object will be assigned to the template object in the workspace.templates.
The src property will be removed unless from a file origin where access is immediate.
A structured clone of the template will be returned to prevent the cached object being modified by role merges.
| Name | Type | Description |
|---|---|---|
template | string | | to be retrieved from workspace.templates if provided as string |
JSON Template
- Type:
- Promise.<(Object|Error)>
(async, inner) moduleTemplate(template, response) → {Promise.<(Object|Error)>}
The script string is converted to a JavaScript data URL which can be used in a dynamic ESM import.
The default export or the imported module itself will be assigned as the render method in the module template.
Module templates are not cached.
| Name | Type | Description |
|---|---|---|
template | object | |
response | string | Module script as string. |
JSON Template
- Type:
- Promise.<(Object|Error)>