dwn-sdk-js
dwn-sdk-js copied to clipboard
Made changed required by downstream nodejs projects
Made changes required to enable this SDK to be imported to spin up a nodejs DWN. Outlining journey that was taken in this PR:
- Downstream TS nodejs project is not able to import this SDK:
Fixed incorrect
types
value inpackage.json
, missingesm
in path; but: - Crash on start because JSON-schema file import need import assertion: Fixed by adding import assertions; but:
- Build failure upon adding import assertions:
Fixed by update
module
value intsconfig
to enable import assertion syntax in TS. but: - ts-mocha throws TypeError: Unknown file extension ".ts" error when attempting to run tests using
npm run test:ndoe
: After trying many things with no success, decided to use this opportunity to ditchts-mocha
andts-node
entirely by using building the tests and run tests usingmocha
directly, this will give us true code coverage also; but -
mocha
fails importing files because esm requires explicit.js
file imports but we don't do that: Added--es-module-specifier-resolution=node
flag to make node import files correctly. but: -
nyc
code coverage tool also mysteriously stopped reporting code coverage at all: After trying many things with no success again, decided to replacenyc
withc8
, which is now a far more active code coverage tool than the stallednyc
anyways; but - Spinning up DWN require explicit construction of DID resolver which is a pain: Made it an optional parameter with ION being the default resolvable method.
- Now the external DWN can finally officially run on nodejs for the first time, but immediately throws error for any request because the request parser does not JSON parse if input is an
object
, but raw input is actually ingested as an array of bytes, which is ofobject
type: Refactored the code to parse the raw bytes before passing to request parser.