-
Notifications
You must be signed in to change notification settings - Fork 71
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
Clean up some types and rename functions for clarity #128
Conversation
Per a comment from @forty, incoming types will be adjusted to |
@forty, how does this look to you? I still have to test it in |
That is what I had in mind yes 👍 With that said, I had a look to the full Node interface in nodejs type definition, and now I'm a bit torn, because the interface is huge so we cannot really validate it all, and the type guard could cause some mistake if someone use it with an object which is not a proper Node but is close enough that it can pass the type guard check. Practically, I think this is fine, unless someone is really misusing the library anyway, and personally, I'd find your current solution good enough to include in my own codebase (I'm just highlighting the caveats) |
One semi-elegant and somewhat safer way of checking your types without the helper is to use the class provided by you dom implementation, when available (not really the case for xmldom unfortunately)
Maybe this tells us those helpers belong to xmldom instead. Not really sure. |
This is a challenge that I ran into as well. I actually had a few more properties that I was checking, but found that they weren't included in these synthetic Node objects that are being generated. I figured that with these properties the confidence interval would be pretty high unless they were trying to cause a problem. If something was this close to a
Let's reach out to a maintainer at |
@cjbarth Are you talking about the type guards that you implemented in this PR? I think for xmldom it could make sense to provide type guards based on the prototypes that are currently only exported from the internal modules, not on certain property types or values. At least that would be my first thoughts when considering it. Regarding using xmldom as a ponyfill and only when the native API is not available (do I remember correctly that this is what xpath is doing?), the check based on the prototype would of course not work, so maybe it would make sense to do it the other way... The types provided by xmldom also refer to The other aspect for xmldom is that I'm trying really hard to limit the API of xmldom to things that are defined in one of the related specs. And from the perspective of a library that expects certain functions and properties to be present for something to be considered a This is my current perspective, based on the information I was able to extract from this thread and diff. |
This comment alone seems to eliminate the possibility of including such type guards in xmldom. Do you think it would be appropriate to have an @xmldom/xmldom-typeguards project or similar? Since we aren't dealing with a typical prototype chain, there really is a need to be able to have a reasonable degree of confidence that the object that is being interacted with is a certain type of object, and the only way to do so at this time, without getting crazy as @forty pointed out, would be to use code like identified in this PR to check I originally put these guards in |
I actually had that thought while writing my previous message, but I don't have any capacity beyond the xmldom project itself right now. I'm not aware whether it's possible to limit publishing rights to a single package in an npm org, but if that's possible I'm up for adding people to the org and making this possible, if it makes sense for enough people and there are enough volunteers to create and maintain it. And just to make it explicit: we are agreeing that these checks/guards should be working with the browser native implementation as well as with the xmldom implmentation, right? |
I would love to hear from @JLRishe : Would you like to see all this extra checking code be moved to a dependent project over at
That would be a simple addition to the code I've already written. In any case, I'd just write it in native TypeScript so that we didn't have to deal with definition files. If we all agree @karfau , I'd gladly use a bootstrapped blank project with all your typically tooling and integrate with that. Otherwise, I'd probably use the same type of pattern I've been using in |
Since xmldom is not a typescript project so far, I'm fine with providing an empty repo and access rights, and the people maintaining it should create the setup they need to work with it. The tooling in node-saml looks reasonable to me at first glance. Should I ever need to touch it I think I should be able to get started quickly. |
Since we haven't heard from @JLRishe , and he is admittedly very busy, I'm in favor of doing as @karfau and @forty have suggested and get a project up that is just for this kind of type checking. In any case, I'm blocked here and will probably move forward with using a fork of this project so that I can get Adding @markstos due to his involvement with |
@cjbarth Sadly I don't have admin rights on npm yet for that scope. I'm trying to get them, but didn't get a response yet since my last comment. What name would you want to have for the repo/package? I would prefer to not be involved in publishing, but if it is the only way it can currently be done I'm fine with configuring my secret for an automated release. |
I would imagine that |
There are some types that aren't correct. Adjust these types to be more accurate and rename some type-narrowing functions to have a more clear name.
This branch is in use by
xml-crypto
to validate that this methodology works.