/provider/getSrc
The getSrc module resolves src references through a provider determined from the src prefix, eg. file:, https:, cloudfront:, or a signer provider from a SIGN_* xyzEnv key.
All source responses are cached in a module scope source map regardless of their provider. Promises are stored in the map before provider requests are awaited so concurrent requests for the same src share one request. The source map must be cleared when the workspace cache is rebuilt.
- Source
Requires
- module:/sign/file
- module:/utils/envReplace
- module:/utils/logger
- module:/provider/cloudfront
- module:/provider/file
Members
(inner, constant) srcMap
Module scope source promise map. The map must be cleared when the workspace cache is rebuilt.
- Source
Methods
(async, inner) Cloudfront(ref) → {Promise.<(String|JSON|Error)>}
The method will extract a cloudfront URL from the ref param string.
The fetch request will be created from the cloudfront provider module with the cloudfront url.
| Name | Type | Description |
|---|---|---|
ref | string | Cloudfront resource reference. |
- Source
The fetch is resolved into either a string or JSON depending on the url ending.
- Type:
- Promise.<(String|JSON|Error)>
(async, inner) File(ref) → {Promise.<(String|JSON|Error)>}
The method will extract a file path from the ref param string.
The fetch request will be created from the file provider module with the file path.
| Name | Type | Description |
|---|---|---|
ref | string | File resource reference. |
- Source
The fetch is resolved into either a string or JSON depending on the url ending.
- Type:
- Promise.<(String|JSON|Error)>
(async, inner) Https(ref) → {Promise.<(String|JSON|Error)>}
The method will extract a https URL from the ref param string.
The fetch request will be created with the https url.
| Name | Type | Description |
|---|---|---|
ref | string | Https resource reference. |
- Source
The fetch is resolved into either a string or JSON depending on the url ending.
- Type:
- Promise.<(String|JSON|Error)>
(async, inner) XYZ(ref) → {Promise.<(String|JSON|Error)>}
The method splits the reference string into a params object for the XYZ file signer.
| Name | Type | Description |
|---|---|---|
ref | string | Reference for the XYZ signer. |
- Source
The fetch is resolved into either a string or JSON depending on the url ending.
- Type:
- Promise.<(String|JSON|Error)>
(async, inner) cacheSources(workspace) → {Promise.<Array.<String>>}
Recursively discovers src properties in a workspace and in fetched responses. Every source promise in a breadth is inserted into the source map before responses are inspected, so duplicate and concurrent references share one request.
All sources are fetched and inspected regardless of their provider. Sources nested in a source response, eg. a template src in a template, are discovered by inspecting the response.
Objects with the srcLoaded flag have their source response assembled in the cached workspace and their src is not read.
| Name | Type | Description |
|---|---|---|
workspace | Object |
- Source
Array of error messages for failed source requests.
- Type:
- Promise.<Array.<String>>
(inner) clearSrcMap()
Clears the module scope source map. The source map must be cleared when the workspace cache is rebuilt.
- Source
(inner) collectSrcs(value, sources, inspectedObjects) → {void}
Recursively collects src properties from the value object and adds them to the sources Set. Inspected objects are tracked in the inspectedObjects WeakSet to avoid infinite recursion.
The src of an object with the srcLoaded flag is not collected.
| Name | Type | Description |
|---|---|---|
value | Object | |
sources | Set | |
inspectedObjects | WeakSet |
- Source
- Type:
- void
(async, inner) getSrc(params) → {Promise.<(String|Object|Error)>}
The method will resolve a src reference through a provider determined from the src prefix, eg. file:, https:, cloudfront:, or a signer provider from a SIGN_* xyzEnv key.
An error is returned if the provider does not exist for the src prefix. The provider request is resolved into a string or JSON depending on the url ending.
| Name | Type | Description |
|---|---|---|
params | String | | A src reference string or params object. |
| Name | Type | Attributes | Description |
|---|---|---|---|
params.src | String | <optional> | Source reference. |
params.cache | Boolean | <optional> | The source map is bypassed for a fresh provider response with cache being false. |
params.workspace | Object | <optional> | Workspace to recursively discover and cache sources in. |
- Source
Cloned source response.
- Type:
- Promise.<(String|Object|Error)>
(inner) getSrcPromise(src) → {Promise.<(Object|Error)>}
Retrieves the source promise for the given src. If the source promise does not exist, it is created with the provider determined from the resolved src prefix.
Environment variables in the src are only substituted on a map miss. A src with environment variables is stored as an alias for the resolved src promise so envReplace runs once per unique src string.
| Name | Type | Description |
|---|---|---|
src | String | Source identifier. |
- Source
Source response promise.
- Type:
- Promise.<(Object|Error)>
(inner) providerPromise(resolvedSrc) → {Promise.<(String|Object|Error)>}
Creates a provider request promise for a resolved src. Provider errors are resolved rather than thrown.
| Name | Type | Description |
|---|---|---|
resolvedSrc | String | Resolved source reference. |
- Source
Provider response promise.
- Type:
- Promise.<(String|Object|Error)>