Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS migrations #221

Closed
wants to merge 17 commits into from
Closed

TS migrations #221

wants to merge 17 commits into from

Conversation

ebarakos
Copy link
Contributor

@ebarakos ebarakos commented Jan 12, 2021

Migrating the following adapters to Typescript:

google-finance
kaiko
marketstack
metalsapi
nikkei
nomics
openexchangerates
poa-gasprice
polygon

@github-actions
Copy link
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@ebarakos ebarakos force-pushed the feature/176014837-TS-migration branch 3 times, most recently from 70a3152 to b3fc300 Compare January 14, 2021 15:14
Copy link
Collaborator

@justinkaseman justinkaseman left a comment

Choose a reason for hiding this comment

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

Great!

Added a few small tweaks.

One thing I am unsure of is what the endpoint would be for some of these adapters. I know we want to keep similar endpoints conformed to the same name and params. Just thinking aloud that we need them documented somewhere.

import { makeExecute } from './adapter'
import { makeConfig } from './config'

const NAME = 'EXAMPLE'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const NAME = 'EXAMPLE'
const NAME = 'KAIKO'

@krebernisak Do we want this capitalized or lowercase? I've seen both ways, but let's pick a convention.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was first used as an ENV prefix to avoid naming collisions when using two or more adapters in the same env. So for now it was a simple hardcoded uppercase string

What we should do now to make this more robust is this:

  • Import the name from package.json, remove the -adapter suffix, and export that as NAME.
  • Create a toEnvName util function that will map it to a safe string to use as ENV name

Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit.

import { Requester } from '@chainlink/external-adapter'
import { Config } from '@chainlink/types'

export const DEFAULT_ENDPOINT = 'example'
Copy link
Collaborator

@justinkaseman justinkaseman Jan 14, 2021

Choose a reason for hiding this comment

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

This is currently an unused variable as there is only one endpoint

"test": "mocha --exit --timeout 0 -r ts-node/register 'test/**/*.test.ts'",
"test:unit": "mocha --exit --grep @integration --invert -r ts-node/register 'test/**/*.test.ts'",
"test:integration": "mocha --exit --timeout 0 --grep @integration -r ts-node/register 'test/**/*.test.ts'",
"server": "node -e 'require(\"./index.js\").server()'",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"server": "node -e 'require(\"./index.js\").server()'",

Take these out of every TS migrated EA as ./index.js is now gone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taking it out of the example as well.

case eod.Name: {
const data = await eod.execute(config, request)

return Requester.success(jobRunID, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will quickly grow to be hard to read if say 10 other endpoints were added.

I think the best style would be how Jonas modified the example adapter as seen here:
https://github.com/smartcontractkit/external-adapters-js/blob/develop/example/src/endpoint/example.ts#L32
Each endpoint handles its own return, which keeps adapter.ts a lot cleaner.


export const Name = 'eod'

const customError = (data: any) => data.Response === 'Error'
Copy link
Collaborator

Choose a reason for hiding this comment

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

@krebernisak Should we be adding typing for each API response shape? Seems like it might be hard to maintain, but could provide valuable debugging information.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not in this PR to keep it fast & simple.

But in the future, we should type anything that's useful, and I think that will become useful at one point. The further we go with composite adapters, the more we use the data provider adapters programmatically, the more useful we are going to find those types.

First, we should finish this migration, then focus on improvements to our internal framework data types, and then we can make another push like this where we add a bunch of underlying API data types in one push. At that point it could start being useful :)

marketstack/src/index.ts Outdated Show resolved Hide resolved
@@ -1,15 +1,46 @@
{
"name": "@chainlink/metalsapi-adapter",
"version": "0.0.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be bumping versions for all of these TS migrations?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think we should!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since all versions are now set to 0.0.1, let's wait until everything is finished/merged, and batch-update all TS migrated ones, or all TS ones in general.

metalsapi/src/index.ts Outdated Show resolved Hide resolved
nikkei/src/index.ts Outdated Show resolved Hide resolved
nomics/src/index.ts Outdated Show resolved Hide resolved
@ebarakos ebarakos force-pushed the feature/176014837-TS-migration branch from b3fc300 to 7236e27 Compare January 18, 2021 09:50
@ebarakos ebarakos linked an issue Jan 18, 2021 that may be closed by this pull request
@ebarakos ebarakos force-pushed the feature/176014837-TS-migration branch 5 times, most recently from 945a5f9 to 319ea92 Compare January 22, 2021 14:46
@ebarakos ebarakos force-pushed the feature/176014837-TS-migration branch from 319ea92 to 159c760 Compare January 25, 2021 15:10
@ebarakos ebarakos marked this pull request as draft January 27, 2021 15:25
@ebarakos
Copy link
Contributor Author

Converted this to draft as it had been split to 3 smaller batches. To be closed after merging the migrations.

@ebarakos ebarakos closed this Feb 3, 2021
@austinborn austinborn deleted the feature/176014837-TS-migration branch November 4, 2021 17:51
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.

Add API's response.data on the data field of adapter's response
3 participants