-
Notifications
You must be signed in to change notification settings - Fork 23
feat: Filter invalid values in getIds #979
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
base: main
Are you sure you want to change the base?
Conversation
I would 100% prefer this. I know I'm always the one who says "is this really a breaking change" -- and I must say this is an interesting example! After all, this should fix existing uses, rather than break them... right? It's hard to imagine code depending on invalid input to this function throwing 🤷 |
I agree with making this a breaking change. Let's remove the options argument. |
Is it worth it to extract the validation functionality from |
Per feedback on plexinc#979
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 ship this as is, but let's mark the commit as a breaking change.
b98bfd6
to
d6bf05f
Compare
I removed the I also squashed this all down to a single commit because it was terrible fixing each of the conflicts that arose in the test file; easier to just fix everything all at once. |
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 think this PR should be fine as is. I don't think we need to mark it as breaking change. The only thing to change though is the commit prefix from feat:
to fix:
since I think this can be viewed as a bug fix.
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.
CLGTM! 🎉
f4fdb3a
to
11ae31b
Compare
🏋️
getIds
robustnessgetIds
is a useful utility function, but it accepts a limited subset of the valid ObjectId constructor argument types, and throws when presented with invalid input.It's not straight-forward to filter inputs to be valid constructor arguments; in some codebases we maintain bespoke utilities for performing these checks (eg;
isValidObjectId
).Unfortunately, the canonical validation for whether one of these arguments is a valid argument to the
ObjectId
constructor is cooked-in to the constructor itself.Therefore, rather than re-implementing this logic (or trying to get it extracted and exposed upstream), I updated the
getIds
implementation to rely on the constructor logic throughtry/catch
, and to discard invalid elements.🐤 Backwards-Compatibility
Per discussion, this is going to be a breaking change.
In order to keep the change backwards-compatible, I gated the filtering functionality behind afilterInvalid
option, passed togetIds
. If we were okay with making a breaking release, I think this would be much nicer as the default behavior.🔧 Changes
I updated
getAll
(🟦) and its specs (🟡) in a few ways.getAll
accept anIterable<ObjectIdConstructorParameter>
, widening acceptable input typesadd optionalGetIdsOptions
argument togetIds
, with optionalfilterInvalid
boolean membergetIds
innermap
toflatMap
, to allow single-pass filteringtry/catch
togetIds
innerflatMap
, to rely on ObjectId constructor validation behavioradd error re-throw togetIds
innerflatMap
, gated onfilterInvalid
optionadd test case for invalid input with nofilterInvalid
option