zapier / zapier-platform

The SDK for you to build an integration on Zapier
https://platform.zapier.com
Other
344 stars 188 forks source link

PDE-4968 feat(schema-to-ts) - Introduce the Schema-to-TS compiler #818

Closed tkcranny closed 3 months ago

tkcranny commented 3 months ago

[!WARNING]
This is rather extensive and being contributed without much knowledge of the DevPlatform's architecture or process. Any feedback or suggestions, no matter how sweeping will be kindly appreciated.

This introduces the new schema-to-ts project in the packages/ directory that compiles typescript definitions from packages/schemas and outputs packages/core/types/zapier.generated.d.ts. This solution has been explored in the past but has abandoned until now, owing to the difficulties expressing function and promise syntax between JSON Schema and TypeScript. See #8 and #260 for further details.

This is a cleaned up and expanded version of a Hackweek Project from Team Integrations in Q2 2024 (coda).

How it works

Potential Issues

See Also

tkcranny commented 3 months ago

I've made some considerable changes today. Notably they include:

tkcranny commented 3 months ago

@rnegron:

In terms of the developer experience of generating the typing declarations file, I saw the precommit script in package.json but it doesn't seem to yarn (install the package requirements) beforehand. I suppose for most contributions to this repo, changes would not need to be made to this package and therefore it should be almost transparent that the typing is auto-generated before a commit happens in zapier-platform-core (and zapier-platform-schema!) What about adding a lifecycle step to the core (and schema?) package to ensure that schema-to-ts is ready to run on changes to that package? There are a lot of available lifecycle options for npm scripts šŸ˜µ.

I love this idea. I've tried a couple of things to this effect. What I've found by putting in lifecycle hooks into the Core/Schema packages to ensure schema-to-ts is installed though breaks both the node 16 tests, as well as the smoke-tests when the packages are built and used on their own with schema-to-ts missing from the expected location.

Fortunately yarn install from the root of the repo will prepare schema-to-ts's own node_modules in preparation for the transparent commit hooks that generate the output declarations.

Therefore the biggest issue I see is that people with this repo already checked out (i.e. you folks) will just need to run yarn from the root to get this tool to work. Fresh installs ought to be fine because of this too.

Is that acceptable for you?

xavdid commented 3 months ago

@tkcranny Congrats on getting this out the door! I was (apparently) still subscribed to the original issue so I got the email that it had been closed. This is an awesome approach; color me quite impressed! šŸŽ‰