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

Development registrar client #4

Open
wants to merge 10 commits into
base: development
Choose a base branch
from

Conversation

SalmaElsoly
Copy link

Description

implemented client for registrar :

  • farm(create/list/get/update)
  • account(create/get by public key / get by twin id / update)
  • node(register/list/get/update/ report uptime)
  • zos(get version)

Setup monorepo

used yarn with lerna + prettier + eslint

Related issues

#2 (comment)
#1 (comment)

@SalmaElsoly SalmaElsoly force-pushed the development_registrar_client branch from 0f24159 to a546fa6 Compare February 18, 2025 13:34
@SalmaElsoly SalmaElsoly requested a review from xmonader February 18, 2025 13:35
Copy link

@0oM4R 0oM4R left a comment

Choose a reason for hiding this comment

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

Great work ya Salma 👏

I have some suggestions :

  • I think we are going to use the module types in other places in the project rather than the module itself; IMO it's better to have an outer directory for types
  • we need some extra info about how to start the project what are the requirements how to build and how to run tests.

That was an overview of the code will test the functionality and comment back with the results.

"type": "git",
"url": "git+https://github.com/threefoldtech/tfgridv4-sdk-ts.git"
},
"scripts": {
Copy link

Choose a reason for hiding this comment

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

Is there a build script?

Copy link

Choose a reason for hiding this comment

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

It will be great if we have some example scripts, like we have in https://github.com/threefoldtech/tfgrid-sdk-ts/tree/development/packages/grid_client/scripts

Copy link

Choose a reason for hiding this comment

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

I think we need to wrap the requests with try-catch blocks

throw new Error("TwinID is not found");
}
const farmName = farm.farm_name;
if (!farmName || farmName.length < 1 || farmName.length > 40) {
Copy link

Choose a reason for hiding this comment

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

Create a const variable at the beginning

const MAX_FARM_NAME_LENGTH

this will enhance the readability and maintenance of the code;
if we need to increase that number later we do not need to search for where do we use it; and we may change it here but forget to change it in the error message or any other place that we may use it

let twinID = 1;
let farmID = 1;

test("create farm", async () => {
Copy link

Choose a reason for hiding this comment

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

I think we can add some more test cases:

  • create a farm with no existing twin ID
  • create a farm with an already existing farm name/id
  • create a farm with an invalid name

this.client = client;
}

async registerNode(node: NodeRegistrationRequest): Promise<NodeRegistrationResponse> {
Copy link

Choose a reason for hiding this comment

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

Should we add any validation to the node data? Not sure if it's correct to rely on the server validation

Copy link

Choose a reason for hiding this comment

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

here as well I think we need more test cases; invalid node data, invalid farm id etc

Copy link

Choose a reason for hiding this comment

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

can we add unit tests for those functions?

// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
Copy link

Choose a reason for hiding this comment

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

is there a reason behind using es2016 if not I suggest using the latest

Copy link

Choose a reason for hiding this comment

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

and removing the commented lines will be much better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants