OpenFn / kit

The bits & pieces that make OpenFn work. (diagrammer, cli, compiler, runtime, runtime manager, logger, etc.)
8 stars 12 forks source link

Lazy State Expressions #649

Closed josephjclark closed 2 months ago

josephjclark commented 3 months ago

The new lazy state $ operator has an issue with expressions.

It works great for simple and nested state references:

post($.data.url, {
    data: $.data.nam`
}

But it doesn't work for any of these expressions:

// tempate litrals
post('www', {
    data: `hello ${$.data.name}`
})

// string concatenation
post('www', {
    name: $.data.first_name + " " + $.data.last_name
})

// dynamic property references
post('www', {
    city: mapCityForLocation[$.data.location]
})

Basically it works great if you use it as a property value, but it'll fail if you try to build it into any kind of more complex expression

josephjclark commented 2 months ago

The good news is: a fix is in progress! We just have to "hoist" the arrow declaration to the top of the operation argument (the top of the object, basically. then all expressions will just compile to state.data.first_name + state.data.last_name