-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
Separate lodestar-api package #2568
Conversation
Code Climate has analyzed commit f08afa1 and detected 34 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
return super.get((toHexString(key) as unknown) as ByteVector); | ||
type PubkeyHex = string; | ||
|
||
function toHexStringMaybe(hex: ByteVector | string): string { |
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.
Allow to pass string as hex string to prevent unnecessary parsing in the API
This pull request fixes 1 alert when merging 0b53679 into f677874 - view on LGTM.com fixed alerts:
|
headSlot: BigInt(headSlot), | ||
syncDistance: BigInt(0), | ||
headSlot: headSlot, | ||
syncDistance: 0, |
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.
No need to return a slot value as BigInt, return as Slot
This pull request fixes 1 alert when merging c685f91 into f677874 - view on LGTM.com fixed alerts:
|
This pull request fixes 1 alert when merging f08afa1 into f677874 - view on LGTM.com fixed alerts:
|
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.
LGTM, we discussed the details offline.
Long overdue update 🙏
Motivation
It was overdue to move the REST api code into its own package so it can be consumed by the validator, lightclient and dependees on NPM.
I've taken the opportunity to review how we declare and consume the REST routes to be more typesafe and succint. We can use Typescript to our advantage to ensure the client and server are compatible at build time and all the logic matches the spec definition.
I've tried to come up with a setup that derives this code (or part of it) from the openapi definition but I was unsuccessful. The code that you get is good but not good enough and requires significant tweaking defeating its purpose. We also have our own SSZ types objects which the openapi is not aware of complicating the logic in connecting both worlds.
See inline comments for rationale
lodestar/packages/api/src/routes/index.ts
Lines 10 to 47 in 0b53679
Description
Compact the client and server REST api logic into a separate package.
cross-fetch
. Consumers can provide their own http client if they want.registerRoutes
function which does that given the api implementationApi
and a fastify server.Other:
BREAKING CHANGES
Api
implementation type matchs the JSON return type of all routes. This means adding a{data: T}
wrapper to most routesbefore
after
before
after
before
after