Functions to process template descriptions.
A parsed description has a type specType
:
{ name: string, module: string | null, description=: string,
env: Object, components=: Array.<specType>}
Merging template B
into A
starts at the top and uses the following
rules:
-
If we are merging the top component and
A.name !== B.name
, throw an error ifoverrideName
is disabled, otherwise changeA.name
. -
To merge two components with the same name, if
B.module === null
then deleteA
. Otherwise, changeA.module
, merge theenv
properties, and finally, merge arrayB.components
intoA.components
. -
To merge array
B.components
intoA.components
iterate on each elementX
ofB.components
applying the following ordering rules:- If
X.name
matches anyY.name
then merge withY
in place, and rememberY
position in the array. - if
X.name
does not match any component, andX.module !== null
, insertX
after the last remembered position. If none was remembered,X
becomes the first element in the array. In both cases, remember the newX
position.
- If
Merge always clones first, leaving the original descriptions unmodified.
- Source:
Methods
merge(template, deltaopt, overrideName) → {specType}
- Source:
Patches a template description with a delta description.
Merge rules are described in a module-level comment in this file.
It does not modify the inputs, returning a cloned description with the merged results.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
template |
specType | A target parsed description. |
|
delta |
specDeltaType |
<optional> |
Description with changes to apply to
|
overrideName |
boolean | True if we allow changing the name of the
top level component, false if names in |
Throws:
-
if invalid inputs, or
overrideName
is false and we have different names for the top component. - Type
- Error
Returns:
A patched description.
- Type
- specType
(inner) mergeComponents(template, delta) → {Array.<specType>}
- Source:
Merge two component arrays of matching components.
Parameters:
Name | Type | Description |
---|---|---|
template |
Array.<specType> | |
delta |
Array.<specDeltaType> |
Returns:
result
- Type
- Array.<specType>
(inner) mergeEnv(template, delta) → {Object}
- Source:
Merge two environments of matching components.
Parameters:
Name | Type | Description |
---|---|---|
template |
Object | |
delta |
Object |
Returns:
result
- Type
- Object
(inner) mergeObj(template, delta, overrideName) → {specType}
- Source:
Merge two descriptions with the same name.
Parameters:
Name | Type | Description |
---|---|---|
template |
specType | |
delta |
specDeltaType | |
overrideName |
boolean |
Returns:
result
- Type
- specType
(inner) parseString(x) → {number|boolean|string|null|object}
- Source:
Parses an string into an object or number or boolean or null... If we fail we just leave it as it was.
Parameters:
Name | Type | Description |
---|---|---|
x |
string | String to parse |
Returns:
A parsed object.
- Type
- number | boolean | string | null | object
(inner) patchEnv(desc, f)
- Source:
Patches every environment in a description.
Parameters:
Name | Type | Description |
---|---|---|
desc |
specType | A description to patch. |
f |
function | A function to patch an environment. |
(inner) patchOneEnv(prefix, f)
- Source:
Returns a function that filters relevant values in an environment and applies a transform to them.
Parameters:
Name | Type | Description |
---|---|---|
prefix |
string | A matching prefix for selected values. |
f |
function | A function that transforms matching values. |
resolveEnv(desc)
- Source:
Patches in place env
values that link to environment properties.
We use the reserved process.env.
prefix for values that come from
the environment.
We can also provide default values using the string separator ||
, and any
characters after it will be parsed as JSON.
If parsing fails, we default to a simple string, avoiding the JSON requirement of quoting all strings. For example:
env: {"location" : "process.env.MY_LOCATION||Palo Alto"}
Parameters:
Name | Type | Description |
---|---|---|
desc |
specType | A description to be patched. |
resolveLinks(desc)
- Source:
Patches in place links to the top level environment.
We use the prefix $._.env.
. For example:
env: {"location" : "$._.env.location"}
Parameters:
Name | Type | Description |
---|---|---|
desc |
specType | A description to be patched. |