-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: configuration service for LogLevel and chain ws address #312
Conversation
553688e
to
f60553f
Compare
I think from the API it would be best, if I could call |
f60553f
to
6244da6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer a config service that does not rely on a fixed set of fields to be able to extend easily in the future. What would you say, @tjwelde ?
I also remember we talked about config via environment variables, what's your opinion on this now?
94edfe2
to
65ece3d
Compare
Now works much more under the hood. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I had mentioned when we talked about it, I am not a fan of hard-coding specific configuration options into the config service. I predict this will be a nightmare for maintaining our codebase later. Also it doesn't work well with the project to split the SDK into smaller sub-packages. Are we sure we want to go down that road ?
To make for some more constructive feedback, I had imagined something like this:
let configuration: configOpts = {'logLevel': DEFAULT_DEBUG_LEVEL}
export function get<K extends keyof configOpts>(configOpt: K): configOpts[K] {
if (typeof configuration[configOpt] === 'undefined')
throw new Error(`GENERIC NOT CONFIGURED ERROR FOR ${configOpt}`)
return configuration[configOpt]
}
export function set(opts: Partial<configOpts>): void {
if(typeof opts['logLevel'] !== 'undefined') {
opts.logLevel = modifyLogLevel(opts.logLevel)
}
configuration = {...configuration, ...opts}
}
which could be exported as ConfigService
or Kilt.config
and would allow users to set options with (for example) Kilt.config.set({defaultNodeAddress: 'value'})
and get values with Kilt.config.get('defaultNodeAddress')
.
65ece3d
to
af1382d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two nitpicks, otherwise I think it looks pretty good.
What do you think @rflechtner
Looks good & works for me! |
packages/core/src/blockchainApiConnection/BlockchainApiConnection.ts
Outdated
Show resolved
Hide resolved
packages/core/src/blockchainApiConnection/BlockchainApiConnection.ts
Outdated
Show resolved
Hide resolved
Sure, but it saves you the scrolling. I think that could help quite a bit to make it obvious what’s happening.
--
From: LeonFLK <notifications@github.com>
Reply to: KILTprotocol/sdk-js <reply@reply.github.com>
Date: Wednesday, 27. January 2021 at 15:04
To: KILTprotocol/sdk-js <sdk-js@noreply.github.com>
Cc: Raphael Flechtner <mail@dasraph.de>, Mention <mention@noreply.github.com>
Subject: Re: [KILTprotocol/sdk-js] feat: configuration service for LogLevel and chain ws address (#312)
@LeonFLK commented on this pull request.
In packages/core/src/blockchainApiConnection/BlockchainApiConnection.ts:
@@ -31,7 +29,7 @@ export const CUSTOM_TYPES: RegistryTypes = {
}
export async function buildConnection(
- host: string = DEFAULT_WS_ADDRESS
+ host: string | undefined = get('address')
For me this wouldn't change comprehension, since we already import get from ConfigService, this is unnecessary IMO.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I mean one can always ctrl+click to get to the definition, and that specific file is quite small, so not much scrolling going on. Just think if we were to clarify each import like that and hold it to the same standard it's going to be messy. What do you think, make an exception for this file clarifying the import, or skip? Edit: import { get as ConfigService.get } does not work, would you want to import the whole ConfigService and then use the different functions like you said? |
Co-authored-by: Timo Welde <tjwelde@gmail.com>
99c34b8
to
f6a6bd5
Compare
yeah importing the ConfigService as a whole would we the solution. But it's not a must, leave it if you don't think it adds much |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes KILTProtocol/ticket#774
This merges and replaces ConfigLog.ts.
We do not want to connect implicitly to the default ws address, instead set it directly or via Kilt.config to set the address of our desired node. This address can be changed any time.
LogLevel can still be set by ENV.
This non-strongly typed approach uses generic set and get to manipulate and access configOpts configuration object.
No specific key suggestion anymore since configOpts is union type with generic keyed object.
Throws error on unset generic property key when accessing or on retrieval of unset address.
Checklist: