Gathering detailed insights and metrics for @lune-climate/lune
Gathering detailed insights and metrics for @lune-climate/lune
Gathering detailed insights and metrics for @lune-climate/lune
Gathering detailed insights and metrics for @lune-climate/lune
lune-ui-lib
Lune UI Components Library
lune
Calculate the phases of the moon
@lune-climate/openapi-typescript-codegen
Fork of: https://github.com/ferdikoomen/openapi-typescript-codegen. Library that generates Typescript clients based on the OpenAPI specification.
@uwu/lune
The CLI build tool for shelter
npm install @lune-climate/lune
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
704 Commits
4 Watching
7 Branches
7 Contributors
Updated on 28 Nov 2024
TypeScript (98.75%)
Dockerfile (0.51%)
Makefile (0.44%)
JavaScript (0.31%)
Cumulative downloads
Total Downloads
Last day
-96.5%
5
Compared to previous day
Last week
-20%
463
Compared to previous week
Last month
-39.9%
4,354
Compared to previous month
Last year
465.9%
64,455
Compared to previous year
4
For the production of models, schemas and services we are using https://github.com/ferdikoomen/openapi-typescript-codegen. It is a tool we were already using on the dashboard and it overall produces the best results for our use case. There are some adaptations we do the generated services, but they are minimal. We do not export the core client and instead have our own implementations. Models and schemas are currently untouched, but as stated before, the services are touched and updated. The main advantage of this approach is not requiring manual intervention whenever a change in the schema is made.
The original services are generated as classes, where each method is a static method.
As an example, to place an order, one would call it as: OrdersService.createOrderByQuantity
A service in the case of openapi schema is a tagGroup
, while the method is the operationId
.
Both the client configuration (url, headers) and the request operation (how to perform the
API call) are hardcoded/static as well, meaning we perform a createOrderByQuantity
always
with the same client configuration and logic to perform the request. This is not ideal since
we might want to provide different implementations or even maybe have multiple clients with
different configurations (using multiple clients for multiple accounts/users for example).
Since we don't have duplicated operationIds
, we have agreed to provide all these methods at
the base level of the client, so we do not want to address them via tagGroups.
To accomodate for points above, these changes are made in all generated service files:
config
and client
as abstract protected consts.options
object parameter to every method. This object contains accountId
which
is used to override the Lune-Account
header.static
modifiers from methodsconfig
, client
and options
.CancelablePromise
, change OpenAPI
to ClientConfig
)requestBody
and queryParams
fields are
united under data
object. This allows for named parameters and overall better usage for our
users. This means our OpenAPI schema needs to make sure there are no duplicate names between
these two fields on an endpoint but it's a compromise we've agreed to do.This allows us to do a bit of a hackish behaviour, and have our client provide the config
and
client
implementations, and then add all methods of the services to it. It makes all
operationIds
present at the base level. We then create an interface on the client that inherits
from all the services, putting the operationIds
types in the client class. This is known as
mixin in Typescript.
See for more info: https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern
To make this automatic creation of the client a reality, we emply a strategy where a base_client.ts
is used to generate the final client.ts
. The main stages are:
base_client.ts
is copied as a base to client.ts
index.ts
is appended to client.ts
so as to have the models and schemas also at the base level.
This makes it possible to use lune.Mass
vs lune.models.Mass
. This can only be achieved since
we don't mix names between models, schemas and operations.We currently use Axios to perform the operations and define our config via an interface dedicated to hold it. The core implementation might be improved a bit, being still highly based on the original core library since it was quite good already.
Check example-usage
folder for a basic usage of the library in both TS and JS. But mostly, all you
need is to add it as a dependency, create a new client and use as normally :)
Also, you can check README_DIST.md
for the README present on the npm package, example usage should be
explicit there so not repeating it here.
If you want to rebuild everything locally from the remote OpenAPI schema (as performed on CI):
docker compose -f docker-compose-ci.yml run update_from_remote_schema
If you want to make sure the build is succeeding but don't want to rebuild the client from the
remote schema nor update with possible changes in the base client generator (as performed on CI):
docker compose -f docker-compose-ci.yml run build_from_source
For local builds, you can use a more lightweight version to rebuild the schema from the remote
that doesn't make sure dependencies are installed and skips linting:
docker compose -f docker-compose.yml run local_model_rebuild
If you want to get hands on inside the container, you can get in and use the make commands as much
as you want. To get a shell inside it, just do:
docker compose -f docker-compose.yml run client
Once inside, you have all Makefile commands at your disposal. Feel free to explore the Makefile
to
see all available. Here are some examples:
make build-from-schema
make build-from-source
An API change was released to Production. You want to start using it via the lune-client module.
Backend repo: Make sure the change is actually live in the API
Docs repo: Make sure the change is published in the docs. theoretically this should happen automatically. Due to some vague race condition, the Update API reference job might run without picking up the latest API version. Go check https://docs.lune.co/ and make sure you can see your change. If your change is NOT there - re-trigger the process by going to one of the runs of Update API reference job (like https://github.com/lune-climate/lune-docs/actions/runs/5963925137) and clicking the "Re-run all jobs" button.
ts-lune repo: 2. should trigger rebuild_schema_change workflow https://github.com/lune-climate/lune-ts/actions/workflows/rebuild-schema.yml which in turn opens a PR introducing the new API stuff to the ts-client. Go approve and merge that PR.
ts-lune repo: Kick off a version bump PR. Pick one:
and use the "Run workflow" button.
Wait for job to finish.
ts-lune repo: 4. should create a PR that bumps the ts-client to a new version. Approve and merge this.
npm registry: Go to and wait until you can see that the new version was published https://www.npmjs.com/package/@lune-climate/lune (this should have happened automatically after merging new version number to MASTER as seen in step 5. but seems slow - give it a min)
Bump the version of ts-client in your local repo to match the newly published npm version, run yarn/npm to install it and start using it
Diagram you don't actually need to look at:
No vulnerabilities found.
No security vulnerabilities found.