oddsdk / ts-odd

An SDK for building apps with decentralized identity and storage.
https://odd.dev/
Apache License 2.0
179 stars 24 forks source link

NodeJS support #351

Open icidasset opened 2 years ago

icidasset commented 2 years ago

We have limited support for NodeJS right now. Some areas still expect the browser environment (eg. usage of fetch), such as the DNS module.

You can use file systems in node today by using the dependency injection system in webnative:

import "webnative/setup/node.js"

This will switch out the browser dependencies with the NodeJS equivalents. See tests for examples.

You can also do switch out individual pieces:

import * as webnativeStorage from "webnative/storage/implementation.js"

webnativeStorage.set({
  getItem: inMemoryStorage.getItem,
  setItem: inMemoryStorage.setItem,
  removeItem: inMemoryStorage.removeItem,
  clear: inMemoryStorage.clear,
})

Ideally the node implementations should be loaded automatically when webnative is used in NodeJS. Although, I don't know fully know the implications regarding bundlers. We'll most likely switch to Deno and that will have some impact as well: https://github.com/denoland/dnt#built-in-shims

icidasset commented 1 year ago

It's technically possible to have it work in NodeJS now. You will have to write a few components to get there, but it's possible.