Skip to content
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

refactor: nodejs sdk design - dependencies - declaration to be more ts alike and up to date #365

Closed
wants to merge 6 commits into from

Conversation

Pulsar-momentum
Copy link

@Pulsar-momentum Pulsar-momentum commented Dec 11, 2023

What

Updated the project architecture, how the package is exported / constructed and his dependencies

Fixes bug(s)

  • ts-standard full validation
  • no ts error from wrong fetch declaration / overriding

@Pulsar-momentum Pulsar-momentum requested a review from a team as a code owner December 11, 2023 18:48
@Pulsar-momentum Pulsar-momentum changed the title Refactor of nodeJS sdk design / dependencies and declaration to be more ts alike and up to date refactor: nodejs sdk design - dependencies - declaration to be more ts alike and up to date Dec 11, 2023
src/main.ts Show resolved Hide resolved
Copy link
Member

@VaiTon VaiTon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, here it is a second round of reviews

README.md Outdated
import OFF from "openfoodfacts-nodejs";
const client = new OFF();
import { OpenFoodFacts } from "openfoodfacts-nodejs";
const client = new OFF({ country: 'string' || null });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an example, not the typing of the constructor.

@@ -1,31 +1,33 @@
{
"name": "openfoodfacts-nodejs",
"name": "openfoodfacts-nodejs-ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we change the name of the package?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the structure and the file working in and for ts, so in my point it make sense to rename it to "ts" to make people aware it's intended to also work for ts project

For what I know ts packages work for ts and js, but always make it explicit when they are made to work for ts

src/main.ts Outdated
const fill = "x".repeat(13 - beginning.length);
const barcode = beginning.concat(fill);
return this.getProduct(barcode);
this.baseUrl = 'https://world.openfoodfacts.org'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the {options.country} ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my test (using fr country) it didn't seems to work, maybe I did it wrong, in case I will put it back

export type Product = components['schemas']['Product']
export type SearchResult = external['responses/search_for_products.yaml']

export type Fetch = typeof fetch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this type could be removed. Is there any reason to keep it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, by exemple in my own project (that is also why I m making this refacto) I need the Product type from the off sdk to be accessible cause I need to type my return function

My own product type (coming from the exported mongo database) isn't compatible with the sdk return so I need this type to make some data convertion

Yet it can be inferered from the return but making it visible is a good thing for some case as mine

@@ -7,16 +7,18 @@
],
"module": "CommonJS",
"lib": [
"ES2022"
"ES2022",
"dom",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need DOM if we're working in pure NodeJS

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NodeJS fetch type was in conflit with the openapi-fetch packages, in this they are using the fetch type coming from dom and not from NodeJS

Before the refactoring the project was shouting a warning about fetch incompatible type, so using the fetch type coming from dom was the solution to be aligned with openapi-fetch packages

…n read me to be usable and provide more explanation
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@Pulsar-momentum
Copy link
Author

Hello @VaiTon, I made some new change about what you pointed out, aside for the point that need some more discussion

@teolemon
Copy link
Member

teolemon commented Mar 1, 2024

@VaiTon @Valetek arg, merge conflicts :-(

@Pulsar-momentum
Copy link
Author

@teolemon gave a look, I can't do the merge myself ... @VaiTon did too much change and added lot of content on his branch for me to handle it, I think it would be better if he can have a look on his side, my branch is essencially about refactoring, I didn't add any special behavior

So unless he take a look on it I think my change will be lost here :') I will probably remove some of his work if I try to do it on my side

@teolemon teolemon added refactor dependencies Pull requests that update a dependency file typescript labels May 7, 2024
@Pulsar-momentum Pulsar-momentum closed this by deleting the head repository Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file refactor typescript
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

3 participants