-
Notifications
You must be signed in to change notification settings - Fork 22
refactor: remove applyWhen in favor of explicit props overlap check with alwaysApply exception #226
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
Conversation
| streamingProfile: true, | ||
| }, | ||
| apply: (asset, opts) => { | ||
| if (typeof opts.streamingProfile === "string") { |
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.
so my only concern here is that this is explicitly checking for a string, but it doesnt seem that the other side is checking the data type, so someone could pass in any truthy value and it would pass it along to the transformation?
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.
This kind of falls under the previous conversation we had about runtime validation. Since they are providing typed input (the streamingProfile prop already enforces that the value is a string), passing true or something should be a type error.
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.
would that be a type error if they're not using Typescript?
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 enable checkJs even if they're writing JS.
Based on our previous conversation, my impression was that we're assuming that people are using the API according to the types or the docs, i.e. not passing garbage. I think this is a good assumption when building a typed API, as otherwise you add tons of bloat for error handling that should never really occur based on the contract in general.
If there was a reason to expect untyped input/lots of mistakes, we'd kinda be back to square one wanting a runtime validator like Zod 😛
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.
is checkJs a user setting or library setting? guessing user setting? so idk if thats a good assumption
i think its more likely people will be using typescript in a Next.js app these days given its a default but i think there still need to be handling, but i guess my impression of the conversation wasn't whether or not to include the runtime validation i already had, moreso not using Zod for it, which i think was only being used in one or two places
seems like its just regressing things a hair for negligible value since it doesnt rely on zod? most of the checks that were there were simpler checks and most relied on specific code paths as opposed to simple validation
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.
It is a user setting, but what I'm describing is really a much broader principle in developing APIs that if someone is using your API in a way that isn't consistent with the contract, it's not your responsibility to check for every one of the infinite ways it could theoretically be misused.
Even if that's not enforced through TypeScript, your API docs still define a contract where the only allowed value type there would be a string, and the behavior would probably reasonable-ish if for some reason e.g. a number were provided- it would likely be interpolated into the URL string the same way it would have been if it were provided as a numeric string.
In fact, I'd say if I did pass a number, that behavior would be more intuitive to me than just ignoring it altogether which I think is what occurs as is?
Anyways, I'm happy to go back through the PR and reintegrate all the runtime checks, but I just want to flag that I don't think it's the right approach for a library like yours.
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 agree that its not my responsibility but i do believe if i can provide guide rails that will have negligible impact on the code/project but have a beneficial impact on their developer experience, i think its worth the effort, like this isn't really going to break the bank in terms of performance but it can help avoid broken experiences
what will happen is instead of getting a broken video because of an improper value (like a number), which can be very difficult to debug through Cloudinary (like not everyone knows about x-cld-error header), it will not add this parameter to the URL maintaining the video still in a working experience
an enhancement would be to warn of the usage in development mode like i do in the if (!getFormat(defaultImage)) { below but i opted not to specifically do that in every instance
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.
Okay I will add those checks back in!
| apply: (asset, opts) => { | ||
| const { defaultImage } = opts; | ||
|
|
||
| if (typeof defaultImage === "string") { |
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.
similar question
| apply: (cldAsset, options) => { | ||
| if (options.enhance) { | ||
| apply: (cldAsset, opts) => { | ||
| if (opts.enhance) { |
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.
why would this be left in then?
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.
Because the type here is a boolean, so the value false would be legal, so we have to check for that.
| apply: (cldAsset, opts, ctx) => { | ||
| const { seoSuffix } = opts; | ||
|
|
||
| if (typeof seoSuffix === "string") { |
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.
similar about string check
|
@colbyfayock My bad on the overlapping plugin props issue there, at least there was a clear type error that I definitely should have noticed :P |
…lwaysApply exception (#228) # Description <!-- Include a summary of the change made and also list the dependencies that are required if any --> Simplify applyWhen to just check for presence of props from the new props key as discussed with @colbyfayock, add an alwaysApply key that can be used for exceptions like SanitizePlugin that should always run regardless of the presence of associated keys. This is a rebased version of #226. ## Issue Ticket Number Fixes #<ISSUE_NUMBER> <!-- Specify above which issue this fixes by referencing the issue number (`#<ISSUE_NUMBER>`) or issue URL. --> <!-- Example: Fixes https://github.com/colbyfayock/cloudinary-util/issues/<ISSUE_NUMBER> --> ## Type of change <!-- Please select all options that are applicable. --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Fix or improve the documentation - [ ] This change requires a documentation update # Checklist <!-- These must all be followed and checked. --> - [ ] I have followed the contributing guidelines of this project as mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md) - [ ] I have created an [issue](https://github.com/colbyfayock/cloudinary-util/issues) ticket for this PR - [ ] I have checked to ensure there aren't other open [Pull Requests](https://github.com/colbyfayock/cloudinary-util/pulls) for the same update/change? - [ ] I have performed a self-review of my own code - [ ] I have run tests locally to ensure they all pass - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes needed to the documentation

Description
Simplify applyWhen to just check for presence of props from the new props key as discussed with @colbyfayock, add an alwaysApply key that can be used for exceptions like SanitizePlugin that should always run regardless of the presence of associated keys.
Issue Ticket Number
Fixes #<ISSUE_NUMBER>
Type of change
Checklist