Brayan Arrieta Alfaro's Blog

Brayan Arrieta Alfaro's Blog

How to fix the Harperive build issue with typescript?

How to fix the Harperive build issue with typescript?

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

For the case of typescript, there are a few options that we can use to connect. During the development related to my backend related to the HarperDB Hackathon, I'm using Harperive npm package that is a node.js driver for HarperDb.

Harperive.png

It is written in JavaScript, it natively supports promises, and functions can be executed with callbacks. Each HarperDb operation is exposed as a function on the client object. All functions take query options and an optional callback function.

As you can see Is an awesome library that provides easy integration, and features to connect and handle the data management related to your project.

Harperive support some features as:

  • Schema Operations (create, drop, describe)
  • Table Operations (create, drop, describe, create an attribute, drop attribute)
  • Query Operations
    • SQL Query
    • NoSQL Queries (insert, update, upsert, delete, search by value, search by hash)
  • User Operations (add, alter, drop, list)
  • Auth Operations (create authentication tokens, refresh operation token)

There are more feature supported by Haperive, In case that you wants to check some other features read the documentation

The Build Issue

There is an issue with Harperive that appears just when you try to create the build related to your typescript code when using Harperive as I mentioned in this GitHub issue created.

node_modules/harperive/types/index.d.ts:105:31 - error TS2304: Cannot find name 'tansactionLogsOptions'.

105   readTransactionLog(options: tansactionLogsOptions): Promise<any>;
                                  ~~~~~~~~~~~~~~~~~~~~~

node_modules/harperive/types/index.d.ts:106:31 - error TS2304: Cannot find name 'tansactionLogsOptions'.

106   readTransactionLog(options: tansactionLogsOptions, cb: (error: any, response: responseData) => any): void;
                                  ~~~~~~~~~~~~~~~~~~~~~

node_modules/harperive/types/index.d.ts:266:14 - error TS2304: Cannot find name 'millisecondTime'.

266   timestamp: millisecondTime;
                 ~~~~~~~~~~~~~~~

The issue happens because there are some typings not defined in the Harperive types, so that issue needs to fix to continue with the building project of our project. To fix that issue we can use the patch-package npm package that will allow us to patch the typing issue in Harperive.

First of all, we need to install patch-package as a dev dependency

npm install --save-dev patch-package

After that, we need to apply two changes to the library typings, to apply the change we need to find harperive in our node_modules folder, and after that open the types/index.d.ts file.

Note: The file path is <projectName>/node_modules/harperive/types/index.d.ts

library directory.png

The next step is to change all the tansactionLogsOptions references in the file to any type.

tansactionLogsOptions -> any

Also change millisecondTime references to any type.

millisecondTime -> any

After those changes will be applied we need to run the next command to create a patch related to that issue in our project.

npx patch-package harperive

The previous command will create a folder in our project root called patches with a new file harperive+2.0.1.patch.

patches.png

The final step that we need to do is add a new npm script to our package.json file

{
  ...,
  "scripts": {
    "postinstall": "patch-package"
  },
  ...
}

With this npm script, the main idea is that the harperive will be patched after the dependencies were installed for that reason the script name postinstall. After that just need to execute a simple npm install and the library will be patched, with that change the next time that we generate the build will be a successful message waiting for you.

Note: This is a temporal fix the main idea will be to try to fix the issue directly in the harperive repository and release a new version for the package.

Conclusion

Harperive is an awesome driver that we can integrate into our projects. Provide an awesome integration with HarperDB. So go ahead and try to integrate HarperDB in your project also participate in HarperDB Hackathon.

I will be updating this post based on your comments and recommendations so let me know in any case that you have some suggestions that can be added or something like that. Thanks for all! 👍

References

 
Share this