Page MenuHomePhabricator

[token-server] Implement typescript
ClosedPublic

Authored by bytesofman on Mar 2 2024, 06:28.

Details

Reviewers
emack
Group Reviewers
Restricted Project
Commits
rABC939c333e4e53: [token-server] Implement typescript
Summary

chronik-client is in typescript and has a number of specifically defined types for its output. Since this server uses chronik-client types, we should also use typescript to get the benefit of this information.

Implement typescript in this repo. Install types for modules used. Deprecate un-necessary module without type definitions (register-ip). Update syntax.

Test Plan

npm test
ts-node index.ts and server starts

output from me doing this locally:

Express server started on port 3333
{
  type: 'Block',
  msgType: 'BLK_CONNECTED',
  blockHash: '00000000000000000f39c3307a459d311213708d390b9d0e230437b1c5c00d5f',
  blockHeight: 834086
}
{
  type: 'Block',
  msgType: 'BLK_FINALIZED',
  blockHash: '00000000000000000f39c3307a459d311213708d390b9d0e230437b1c5c00d5f',
  blockHeight: 834086
}

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Tail of the build log:

/work/apps/token-server /work/abc-ci-builds/token-server-tests

added 449 packages, and audited 450 packages in 3s

61 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

> token-server@0.0.0 test
> mocha --reporter mocha-junit-reporter --reporter-options mochaFile=test_results/token-server-junit.xml --reporter-options testsuitesTitle=Token Server Unit Tests --reporter-options rootSuiteTitle=Token Server


TypeError: Unknown file extension ".ts" for /work/apps/token-server/test/chronik/wsHandler.test.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at async link (node:internal/modules/esm/module_job:76:21)
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

##teamcity[blockOpened name='Code Coverage Summary']
##teamcity[buildStatisticValue key='CodeCoverageAbsBCovered' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsBTotal' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='0']
##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='0']
##teamcity[blockClosed name='Code Coverage Summary']
mv: cannot stat 'test_results/token-server-junit.xml': No such file or directory
Build token-server-tests failed with exit code 1
bytesofman edited the test plan for this revision. (Show Details)

typo fix in gitignore, remove unused type modules from package.json

bytesofman published this revision for review.Mar 2 2024, 14:51
bytesofman added inline comments.
apps/mock-chronik-client/index.d.ts
1 ↗(On Diff #45852)

Will need a separate diff to fully bring mocked-chronik-client into typescript

imo this is not worth rightnow because

  • mocked-chronik-client is only used for tests
  • the tests fail if mocked-chronik-client is used improperly
  • the types are quite complicated and expected to change
apps/token-server/index.ts
19 ↗(On Diff #45852)

ts won't let me access private methods. imo no need to force it, this console.log statement is not required.

bytesofman edited the test plan for this revision. (Show Details)
This revision is now accepted and ready to land.Mar 2 2024, 23:23
This revision was automatically updated to reflect the committed changes.