-
Notifications
You must be signed in to change notification settings - Fork 20
feat(lib): co2js: allow config and globalConfig parameters as input #50
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(lib): co2js: allow config and globalConfig parameters as input #50
Conversation
Hi if-team, would it be possible to get some feedback on this? I guess you are quiet busy currently, so anything you need to ease the process, let me know. Thank you! |
Hi @alexzurbonsen sorry for the delay, we were slammed last week finalizing the repos for the hackathon and missed this. We'll chat over this today and get you some feedback asap. |
Hi @jmcook1186, thanks, that sounds good. |
Hi @alexzurbonsen, thanks a lot - we looked at this and agree that having those params all in global config is not the best approach. However, the way we would prefer to resolve it is to have those values coming from |
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.
Please update the README file of the plugin to reflect that the options
come from the input
src/lib/co2js/index.ts
Outdated
|
||
const {InputValidationError} = ERRORS; | ||
|
||
export const Co2js = (globalConfig?: ConfigParams): PluginInterface => { |
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.
could you please remove the globalConfig
, we don't need it anymore
src/lib/co2js/index.ts
Outdated
/** | ||
* Validates Global config parameters. | ||
*/ | ||
const validateGlobalConfig = () => { |
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.
remove this function as well, as we don't need it anymore
src/lib/co2js/index.ts
Outdated
}) | ||
.partial() | ||
const inputSchema = bytesSchema | ||
.merge(greenWebHostSchema) |
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.
The green-web-host
parameter should be obtained only from the node config
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.
Are you sure? This would be sad, because it wouldn't support my use case. I wrote a plugin to get the green-web-host parameter separately and feed it into this one. This doesn't work if it is a config option.
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.
We assumed this parameter was constant at the level of a node in the manifest but if that's not the case I think we can probably flex on whether it is in config or inputs. @manushak can either confirm or push back.
Also, just because there are times we don't want to merge something into our version of a plugin, doesn't mean you can't host your preferred version elsewhere. The ideal outcome for us is to have many people all maintaining version so the plugins that work for their specific use cases in many repositories, and we just maintain a minimal "standard lib" of essentials. We want the plugin ecoystem to be as decentralized as possible so we are strongly in favour of people forking and modifying our plugins even if the changes don't get upstreamed.
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 @jmcook1186, thanks for your explanation. Makes sense to me.
My reasoning is that it is more convenient to have one standard version of a plugin that is allowing for a broad spectrum of use cases, than having several slightly modified versions of the same plugin throughout the ecosystem where people have to understand what the differences are etc. That might be confusing and a bit frustrating.
A plugin that is as general as possible makes the latter case less likely. So I think there is value in making a plugin as versatile as possible.
But if you don't want to include it, of course, I will just create a variant of it.
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.
we can be flexible and accept the green-web-host
either in node config or input
ea47532
to
5e09c70
Compare
I made most of the changes, except that I kept |
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.
please, update the readme file as well
src/lib/co2js/index.ts
Outdated
validateGlobalConfig() | ||
); | ||
const validatedConfig = validateConfig(config); | ||
const mergedValidatedConfig = Object.assign({}, validatedConfig); |
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.
mergedValidatedConfig
doesn't have any sense anymore
src/lib/co2js/index.ts
Outdated
}) | ||
.partial() | ||
const inputSchema = bytesSchema | ||
.merge(greenWebHostSchema) |
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.
we can be flexible and accept the green-web-host
either in node config or input
src/lib/co2js/index.ts
Outdated
const greenWebHostSchema = z.object({ | ||
'green-web-host': z.boolean().optional(), | ||
}); | ||
const optionsSchema = z.object({ |
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.
move optionsSchema
and bytesSchema
schemas to the validateInput
function
src/lib/co2js/index.ts
Outdated
* Validates input parameters. | ||
* Validates input and config parameters. | ||
*/ | ||
const validateInput = (input: PluginParams) => { |
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.
you can add the config as a second parameter and after merging write
.refine(() => !!config['green-web-host'] || !!input['green-web-host'], { message:
Green web host is provided neither in config nor in input.\nConfig: ${config}\nInput: ${input}, })
this will allow us to get rid of validateGreenWebHostExists
function
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.
Nice!
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 added a second check to make sure it is not provided twice. Let me know if that is not how you want it to be.
58d6fc7
to
b09f215
Compare
b09f215
to
5a88156
Compare
Hi @alexzurbonsen and @manushak - thanks for your work on this, I hope it's been useful for your hackathon project Alex. Two potential routes forwards: a) we can merge the changes if Cheers |
Hi @jmcook1186, sounds good to me. I like the design principle. Thanks for clarifying. Of course, I am okay with both routes forwards. Personally, I also have a preference for having one plugin instead of two. But I think both routes are totally fine. Let me know how you decide @manushak and @jmcook1186. Then I will either close this PR or make the necessary changes. |
Hi @alexzurbonsen please feel free to make the proposed changes and we'll be happy to merge. Let me know if you decide otherwise and I'll close this out. |
Hi @jmcook1186, finally had time to push the changes. |
4388a60
to
4c5c06d
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.
lgtm!
@manushak can you confirm you are happy too?
inputs: | ||
- timestamp: 2023-07-06T00:00 | ||
duration: 1 | ||
network/data/bytes: 1000000 |
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.
please, move green-web-host: true
into inputs (it is on line 69)
green-web-host: true | ||
inputs: | ||
- timestamp: 2023-07-06T00:00 | ||
duration: 1 |
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.
the same here, move green-web-host: true
into inputs (it's on line 113)
outputs: | ||
- timestamp: 2023-07-06T00:00 | ||
duration: 1 | ||
network/data/bytes: 1000000 |
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.
add green-web-host: true
into outputs
{ | ||
duration: 3600, // duration institute | ||
timestamp: '2021-01-01T00:00:00Z', // ISO8601 / RFC3339 timestamp | ||
'network/data/bytes': 1000000, // bytes transferred |
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.
move 'green-web-host': true, // true if the website is hosted on a green web host, false otherwise
into inputs (it's in line 172). The same in line 193
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, missed these changes.
src/lib/co2js/index.ts
Outdated
}) | ||
.refine(allDefined, { | ||
message: '`type` and `green-web-host` are not provided in node config', | ||
.refine(data => data['type'] !== undefined, { |
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.
you can remove the refine
method call, it is no longer necessary
Signed-off-by: alexzurbonsen <alexander.zur.bonsen@tngtech.com>
4c5c06d
to
cac94b2
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.
thanks, @alexzurbonsen, for your contribution. You have done amazing work!
@jmcook1186, it's ready to merge
Types of changes
A description of the changes proposed in the Pull Request
This is a suggestion on how to fix #49. There may be different approaches.
This one helps to enable old functionality within the new architecture.
If this PR finds acceptance, I would still need to adapt documentation.