OpenFn / adaptors

The new home for OpenFn adaptors; re-usable connectors for the most common DPGs and DPI building blocks.
GNU General Public License v3.0
6 stars 8 forks source link

Add `fnIf` in `common` #620

Closed mtuchi closed 3 months ago

mtuchi commented 3 months ago

Summary

Add fnIf operation in common, And prettier formatting made tiny change to cursor function

Ref #375

Review Checklist

Before merging, the reviewer should check the following items:

mtuchi commented 3 months ago

Sample test code for the fnIf function

fn(state => {
  state.name = 'ama';
  state.users = [
    {
      name: 'mtuchi',
      age: 'NaN',
    },
    {
      name: 'Africa',
      age: 'NaN',
    },
  ];
  return state;
});

fnIf(
  state => state?.name,
  state => {
    console.log(state.name);
    return state;
  }
);

fnIf(
  state => state.users.length > 1,
  each($.users, state => {
    console.log(state.data);
    return state;
  })
);

// Only if you export common/util 👇🏽 
fnIf($?.name, async state => {
  const { body } = await util.get('https://jsonplaceholder.typicode.com/users');
  state.results = body;

  return state;
});
josephjclark commented 3 months ago

Quick note: each adaptor needs to explicitly export this from common, and also needs a minor bump

mtuchi commented 3 months ago

I have updated each adaptor export fnIf from common and bump their version to a minor

josephjclark commented 3 months ago

Oh man @mtuchi I was not ready for this to be released!

I guess I shouldn't have approved it. That was a "thanks, I'll take it from here" sort of approval. I did say I was going to look at the docs.

Because we've got a lot of common changes coming together, I wanted to do one big release (maybe even a major) with them all at once

mtuchi commented 3 months ago

My bad @josephjclark 🙌🏽 , I thought this was ready for release. I will make sure to ask before merging next time