Closed tkcranny closed 3 months ago
I've made some considerable changes today. Notably they include:
core/types/index.test-d.ts
.yarn type-tests
, and subsequently via yarn test
in the core package.BeforeRequestMiddleware
and AfterResponseMiddleware
types to zapier.custom.d.ts
module.
MiddlewaresSchema
for the respective types via a transformer for each.typescript
template to pass it's smoke test.
zapier init
function this is running. I think that output is itself for some spawned subprocesses it's running.@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?
@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! š
This introduces the new
schema-to-ts
project in thepackages/
directory that compiles typescript definitions frompackages/schemas
and outputspackages/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
yarn build
.yarn generate-types
, which will rundist/cli.js
(once built). This CLI has a number of flags and options if needed.../schema/exported-schema.json
for its input (by default).../core/types/zapier.generated.d.ts
(by default).index.d.ts
, nowzapier.custom.d.ts
), and are all intended to be bundled in the ZPC distribution on npm for downstream developers.precommit
andgit-add
scripts in itspackage.json
to build the generated types on commits via husky & lerna, similar to howcli
andschema
build their docs and output artefacts.json-schema-to-typescript
(npm) library. We choose to render our own TypeScript output with this intermediate result due to some unpleasant limitations and to correctly patch in real function definitions and links to public documentation.Potential Issues
packages/
or even this repo itself may not be the correct location.See Also
#260
was closed and#8
was reopened in 2021: https://github.com/zapier/zapier-platform/issues/8#issuecomment-827972091