Documentation ¶
Overview ¶
Package ctygoja is an adapter layer for converting between cty values and values used by the pure-Go JavaScript engine "goja". This can be used to create interfaces between a cty-based application and a JavaScript context.
The philosophy for this package is to behave as if values were converted via JSON using the mappings in the ctyjson package, relying on the fact that the cty type system (capsule types notwithstanding) is a superset of JSON.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromCtyValue ¶
FromCtyValue takes a cty.Value and returns the equivalent goja.Value belonging to the given goja Runtime.
Only known values can be converted to goja.Value. If you pass an unknown value then this function will panic. This function cannot convert capsule-typed values and will panic if you pass one.
The conversions from cty to JavaScript follow similar rules as the default representation of cty in JSON and so a round-trip through goja.Value and back to cty.Value is lossy: maps will generalize as objects and lists and sets will generalize as tuples.
This function must not be called concurrently with other use of the given runtime.
func ToCtyValue ¶
ToCtyValue attempts to find a cty.Value that is equivalent to the given goja.Value, returning an error if no conversion is possible.
Although cty is a superset of JSON and thus all cty values can be converted to JavaScript by way of a JSON-like mapping, JavaScript's type system includes many types that have no equivalent in cty, such as functions.
For predictability and consistency, the conversion from JavaScript to cty is defined as a conversion from JavaScript to JSON using the same rules as JavaScript's JSON.stringify function, followed by interpretation of that result in cty using the same rules as the cty/json package follows.
This function therefore fails in the cases where JSON.stringify would fail. Because neither cty nor JSON have an equivalent of "undefined", in cases where JSON.stringify would return undefined ToCtyValue returns a cty null value.
Types ¶
This section is empty.