-
Notifications
You must be signed in to change notification settings - Fork 75
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
Fix: Resolve Type Warnings for ConfigService.get() #3350
base: main
Are you sure you want to change the base?
Fix: Resolve Type Warnings for ConfigService.get() #3350
Conversation
- Ensured type consistency in all affected test cases. - Removed unnecessary type casting or added necessary casting. Signed-off-by: belloibrahv <belloibrahv@gmail.com>
- Ensured type consistency in all affected test cases. - Removed unnecessary type casting or added necessary casting. Signed-off-by: belloibrahv <belloibrahv@gmail.com>
@Nana-EC @ebadiere @quiet-node I've submitted a PR addressing issue #3142 to resolve type warnings for ConfigService.get(). It ensures type consistency across test cases by refining type usage and adding/removing the necessary casting. Let me know if further changes are needed. Thank you for reviewing! |
@@ -26,7 +28,7 @@ export interface ConfigProperty { | |||
} | |||
|
|||
export class GlobalConfig { | |||
public static readonly ENTRIES: Record<string, ConfigProperty> = { | |||
public static readonly ENTRIES: Record<ConfigName, ConfigProperty> = { |
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.
Instead of enumerating the keys manually, can we do something like
const _CONFIG = {
BATCH_REQUESTS_ENABLED: {
envName: 'BATCH_REQUESTS_ENABLED',
type: 'boolean',
required: false,
defaultValue: null,
},
//...
WS_SUBSCRIPTION_LIMIT: {
envName: 'WS_SUBSCRIPTION_LIMIT',
type: 'number',
required: false,
defaultValue: null,
},
} satisfies { [key: string]: ConfigProperty };
export type ConfigKey = keyof typeof _CONFIG;
export class GlobalConfig {
public static readonly ENTRIES: Record<ConfigKey, ConfigProperty> = _CONFIG;
}
?
So we retain type safety for the keys (even if they're strings).
Note that we can use satisfies
because we're using TypeScript 4.9.5
as defined in package-lock.json
.
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.
Thanks for the contribution.
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC |
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.
nit: revert
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC |
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.
revert this and any other license header changes where you're changing an old header date into this year.
Might be a bug in an automated script
|
||
describe('@server-config Server Configuration Options Coverage', function () { | ||
describe('Koa Server Timeout', () => { | ||
it('should timeout a request after the specified time', async () => { | ||
const requestTimeoutMs: number = parseInt(ConfigService.get('SERVER_REQUEST_TIMEOUT_MS') || '3000'); | ||
const requestTimeoutMs: number = parseInt(ConfigService.get(ConfigName.SERVER_REQUEST_TIMEOUT_MS) as string || '3000'); |
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 wonder if we should add a getString and do the casting in the ConfigService to make this easier on devs.
Thinking out loud and getting thoughts.
No need to change in this PR
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.
Thank you for the suggestion about ConfigService.getString
. I agree that it could streamline type handling. I suggest we open a separate issue to implement and test this change comprehensively.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3350 +/- ##
===========================================
- Coverage 85.04% 49.70% -35.35%
===========================================
Files 65 66 +1
Lines 4508 4601 +93
Branches 1023 1023
===========================================
- Hits 3834 2287 -1547
- Misses 330 1926 +1596
- Partials 344 388 +44
Flags with carried forward coverage won't be shown. Click here to find out more.
|
27253f5
to
7f440e4
Compare
@Nana-EC @acuarica @quiet-node, Could you please review my updates and let me know if further adjustments are needed? |
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.
Hi @belloibrahv, thanks for taking the time to send this, it's looking good. Left a couple of suggestions we can continue iterating on to improve the config.
@@ -49,13 +50,13 @@ describe('ConfigService tests', async function () { | |||
}); | |||
|
|||
it('should be able to get existing env var', async () => { | |||
const res = ConfigService.get('CHAIN_ID'); | |||
const res = ConfigService.get('CHAIN_ID' as ConfigKey); |
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.
Can we change the definition of ConfigService.get
to get(name: ConfigKey)
? So we can then avoid all these type assertions, i.e., as ConfigKey
.
Not related with your PR, but I tried this change locally and I saw there was a configuration entry missing, SERVER_HOST
. If we change the definition of get
as mentioned above, we might want add a SERVER_HOST
entry.
packages/config-service/tests/src/services/configService.spec.ts
Outdated
Show resolved
Hide resolved
Also @belloibrahv please take a look at #3350 (comment). |
Signed-off-by: belloibrahv <belloibrahv@gmail.com>
Signed-off-by: belloibrahv <belloibrahv@gmail.com>
Signed-off-by: belloibrahv <belloibrahv@gmail.com>
7f440e4
to
c7e6a08
Compare
Quality Gate passedIssues Measures |
@quiet-node @acuarica @Nana-EC @shemnon , thank you for the suggestion. I've implemented the following changes based on your feedback:
Let me know if there's anything else you'd like me to address! |
@acuarica, Thank you for the suggestion! I think adding a Would you suggest we implement these methods for this task or address it as a follow-up? Also, should these methods throw errors for mismatched types, or return defaults like |
Let's do it in a separate PR after this. Also appreciate the patience. |
Description:
This PR addresses type inconsistencies in the test specifications related to the
ConfigService.get(<envName>)
method. The changes ensure type safety and consistency across all affected test cases by aligning with the expected types defined in theConfigService.get()
method.Key Changes:
envName.ts
to define and manage environment variable types.envName
file, ensuring type consistency withConfigService.get()
.Related issue(s):
Fixes #3142
Notes for Reviewer:
ConfigService.get()
method's expected types.ConfigName
enum) were incorporated where feasible.Checklist: