-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add TypeScript and general refactor #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor comments. Overall I really like this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. thanks for the detailed README. Couple of my remarks to it.
- No tests
I don't see this like a huge deal. The idea behind this repo is to preserve the source of truth for chain informations. I'd be lenient with tests (I am not really sure what you would want to test) but instead validate as much as possible.
This script is run automatically before publishing to NPM and as part of (newly added) CI.
nit: pre-push hook would be nice as well.
write-env-variables
I'd also use this to populate env.example. Also the script is a bit dangerous in that it overrides the already existing .env
secrets. It might be good idea to make it smarter and only append/remove the new/unnecessary ones.
I've updated the README.md file with the API changes. Let me know what you think. It could still be improved further, but it at least describes the minimum. Also, the |
Say I add a particular version of I think |
Do you mean that you want chains at a certain point in time/package version? I didn't realise that this was a requirement. I assumed that the latest package version was always going to be preferable. I guess there are several options
I still feel that a script is better suited here and the workarounds above can be used if needed.
Sure I'm happy to change the name. The previous name was |
Ah okay, I hadn't noticed that
|
Instead of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1 (comment) can also be an issue
Co-authored-by: Burak Benligiray <[email protected]>
Co-authored-by: Burak Benligiray <[email protected]>
Yeah it's maybe not ideal, but dropping the I've updated the |
I think this is ready to be merged now. Let me know if you want me to hit the button. I assume we'll want to publish v2.0.0 for this too |
Motivation
If we want this package to be the "single source of truth" for API3 related projects, then I think it needs to be as robust as possible. However, the current setup has some issues. Specifically:
fs
chains/
directoryThis PR is an attempt to address points 1-3. Tests can be added in a followup PR if you're happy with this approach
API changes
The currently exported functions have been changed to the following:
Scripts
generate-chains
This script is intended to be run whenever one or more JSON files are changed in the
chains/
directory. It reads all of the files and creates a new TS file atsrc/generated/chains.ts
that has the staticCHAINS
export. This provides type safety to users and allows the package to be included in any environment.It is run as part of
yarn build
but can also be run withyarn dev
.yarn dev
will watch the directory for changes and re-write the file immediately.validate-chains
This script uses
zod
defined schemas to validate each of the JSON files inchains/
. For example, we can now validate that certain fields are present and conform to required formats (URLs, numbers etc.) If there are errors, the script exits with status 1. All errors are logged to stdout usingconsole.log
.This script is run automatically before publishing to NPM and as part of (newly added) CI.
write-env-variables
The old
writeEnvFile
has been extracted to a script to allow the package to be used in all environments. The newgetEnvVariables
function allows for the list of environment variables to be created, while the script actually writes the file.Usage:
yarn env:write --path .env
Considerations
tsconfig.json
files from https://github.com/api3dao/promise-utils. I also tried publishing under my own account and everything seemed to work. See: https://github.com/andreogle/chains