Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDE-2564: core(feat): allow using await in inline function source (9.x backport) #390

Merged
merged 5 commits into from
Jul 2, 2021

Conversation

eliangcs
Copy link
Member

@eliangcs eliangcs commented Jun 22, 2021

This is a 9.x backport merging into the release-9.x branch. I created this new branch release-9.x from tag zapier-platform-cli@9.4.2 so we can release more 9.x versions from that branch. Once this PR is approved, I'll merge and cut a release 9.5.0.

This PR addresses two Jira tickets:

For PDE-2564, this patch allows developers to use the await operator in Visual Builder's Code Mode. For example, Visual Builder may generate this code for auth testing:

const options = {
  url: 'https://auth-json-server.zapier-staging.com/me',
  method: 'GET',
  headers: {
    'X-Api-Key': bundle.authData.api_key
  }
};
return z.request(options)
  .then((response) => {
    response.throwForStatus();
    return response.json;
  });

Now with the support for the await operator, developers can write this:

const options = {
  url: 'https://auth-json-server.zapier-staging.com/me',
  method: 'GET',
  headers: {
    'X-Api-Key': bundle.authData.api_key
  }
};
const response = await z.request(options);
response.throwForStatus();
return response.json;

@eliangcs eliangcs changed the title Async function 9.x core(feat): allow using await in inline function source Jun 22, 2021
@eliangcs eliangcs changed the title core(feat): allow using await in inline function source core(feat): allow using await in inline function source (9.x backport) Jun 22, 2021
@eliangcs eliangcs changed the title core(feat): allow using await in inline function source (9.x backport) PDE-2564: core(feat): allow using await in inline function source (9.x backport) Jun 28, 2021
@eliangcs eliangcs marked this pull request as ready for review June 28, 2021 09:13
@eliangcs eliangcs requested a review from xavdid as a code owner June 28, 2021 09:13
@eliangcs eliangcs changed the base branch from master to release-9.x June 28, 2021 09:18
Copy link
Contributor

@xavdid xavdid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! My only thought here is if it being async changes our error-handling story at all. I don't think it does (and I see you've got a test), but I could see a situation where wherever this created function is called (the execute command handler, I think?) we do a catch but don't expect a rejected promise. So, if you haven't, that bears looking into.

The only other consideration isn't related to the content of this PR exactly, but about the backporting. Apps that have been running continuously (most public apps, which probably don't have their lambda functions pruned) could still be running on Node 8. It's possible that they don't work on later node versions, but we don't know it yet. We could be poking the bear by refreshing apps that have been humming along nicely. It's probably fine, but that was an area of concern that popped up as I was thinking through this.

Also, my guess is that we'll take godzilla apps from 9.x right to 11.x, so we probably don't need a 10.x release, FWIW.

Great job!

@eliangcs
Copy link
Member Author

eliangcs commented Jul 2, 2021

@xavdid thanks for the great feedback! I didn't think that much so I took a second look.

I think we can safely assume the core always calls the created function asynchronously. The command handler named app is created here:

const app = createCommandHandler(frozenCompiledApp);
return applyMiddleware(befores, afters, app);

In applyMiddleware, there's a resolve wrapping around the app() call:

const promise = beforeMiddleware(input).then((newInput) => {
return resolve(app(newInput))
.then(ensureEnvelope)
.then((output) => {

This means even if app doesn't return a Promise, that resolve will make it a Promise. So I think we're safe replacing new Fucntion() with new AsyncFunction().

Good call on the Node 8 concern! I looked into the database. No Visual Builder apps are running on Node.js 8. I think they all got upgraded in the previously 9.x releases.

@xavdid
Copy link
Contributor

xavdid commented Jul 2, 2021

Sweet! Carry on 🚢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants