Skip to content

remove dependencies on node specific libraries#135

Merged
jakubkoci merged 2 commits intoopenwallet-foundation:masterfrom
TimoGlastra:rn-support
Nov 14, 2020
Merged

remove dependencies on node specific libraries#135
jakubkoci merged 2 commits intoopenwallet-foundation:masterfrom
TimoGlastra:rn-support

Conversation

@TimoGlastra
Copy link
Contributor

We were using three NodeJS specific libraries:

  • base64url -> Removed and now using Buffer to base64 encoding with a small base64ToBase64URL util function.
  • events -> added events dependency. In NodeJS the native events library will be used. In RN (or other platforms) the npm package will be used (Node will only use the npm package if you import events/ instead of events so we're good here)
  • buffer -> added buffer dependency and use an import from util/buffer.ts instead of global. Same as with events the native library will be used in NodeJS and the npm package in other environments

Signed-off-by: Timo Glastra <timo@animo.id>
when run in node environment the native events pacakge will be used.
in other environments the npm package will be used

Signed-off-by: Timo Glastra <timo@animo.id>
@TimoGlastra TimoGlastra requested a review from a team November 12, 2020 11:53
Copy link
Contributor

@jakubkoci jakubkoci left a comment

Choose a reason for hiding this comment

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

Good job Timo, I added just two notes, but I'm approving this.

*/
public static fromString(string: string) {
return JSON.parse(string);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried if this is not too much abstraction. I would suggest just calling JSON.parse directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. We're already using the JSON Encoder for all the other stuff so I thought it will be consistent in a way that everything that has to do with JSON encoding is done by the JsonEncoder.

I'm fine with removing it

*/
public static toString(json: unknown) {
return JSON.stringify(json);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried if this is not too much abstraction. I would suggest just calling JSON.stringify directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as with fromString, I'm fine with removing it

*/
public static fromBuffer(buffer: Buffer) {
return JsonEncoder.fromString(buffer.toString('utf-8'));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Tricky question: Should this be part of the JsonEncoder or BufferEncoder? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I wasn't sure either. But splitting toBuffer and fromBuffer between JsonEncoder and BufferEncoder also doesn't seem like the best approach to me. What do you think?

@jakubkoci jakubkoci merged commit 1b60fd6 into openwallet-foundation:master Nov 14, 2020
@TimoGlastra TimoGlastra deleted the rn-support branch May 15, 2021 10:02
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.

2 participants