-
Notifications
You must be signed in to change notification settings - Fork 13
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
Issue #45: Add missing spec methods to DataFactory interface #46
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: bd385b4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
d29084b
to
a29a566
Compare
Hi @matthieubosquet :) Thanks for these changes! It may be worth using a mver bump to release these changes, as many RDF/JS implementations do not implement these methods (c.f. rdfjs/N3.js#447) - and so this will either cause (1) the package to declare methods that it does not implement or (2) have type errors if the package is, e.g., written in typescript and |
a29a566
to
ed5714e
Compare
ed5714e
to
b0ca1a9
Compare
Rebased and made this a major bump: b0ca1a9. I am not sure what is the release process and how to publish a v1.1.1 (maybe before merging this). I also wonder if maybe we could add a few items before potentially publishing a version 2.0.0:
|
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 see inline comment
If we want to simultaneously work on v2 then we'd probably need a dedicated branch... |
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 changeset @matthieubosquet 👌
I took a closer look and I agree with the other to make this a major release. A little unfortunate, because this may disrupt the ecosystem when some packages start to depend on @rdfjs/types@^2
while other stay on v1. But maybe I'm wrong we'll see
I also added some more suggestions (was on mobile earlier)
Co-authored-by: Tomasz Pluskiewicz <[email protected]>
Thanks for the suggestions @tpluscode and @rubensworks! I fixed up the tests after applying suggestions: f1879fb. The DataFactory initialised with |
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.
Great work. Thanks. I think we're good now
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.
Tested in rdf-data-factory, and everything seems to work as intended!
data-model.d.ts
Outdated
fromTerm<T extends Literal>(original: T): Literal; | ||
fromTerm<T extends Variable>(original: T): Variable; | ||
fromTerm<T extends DefaultGraph>(original: T): DefaultGraph; | ||
fromTerm<T extends Quad>(original: T): OutQuad; |
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.
BaseQuad
input should also presumably be supported since BaseQuad
s are valid Term
s
fromTerm<T extends Literal>(original: T): Literal; | ||
fromTerm<T extends Variable>(original: T): Variable; | ||
fromTerm<T extends DefaultGraph>(original: T): DefaultGraph; | ||
fromTerm<T extends Quad>(original: T): OutQuad; |
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 did you revert this?
After @jeswr's comment, I realised that there might be a bit of inconsistency in the DataFactory method declarations and its use of generic types. In a nutshell, with a typing such as: I tried to produce a commit that illustrates and offers a compromise to fix the issue. Remains an inconsistency with the quad factory part: If we allow that amount of specificity for Quads, is there a specific reason not to allow it for other Terms? |
I think I see where you're going, but this solution doesn't quite work. Consider using fromTerm from @rdfjs/data-model with an input of an N3.js NamedNode. The N3.js NamedNode has an extra #toJson method that will not be available in the NamedNode output by the @rdfjs/data-model method; however the type inference you have now would suggest that the output NamedNode does have this #toJson method. What you want to allow for is for the libraries to extend the DataFactory types such that any custom extensions they have to their terms can be included - that is fromTerm from N3.js will always output a NamedNode with the #toJson method regardless of whether the input NamedNode does or not. Your original implementation should permit this. |
To demonstrate the problem, here's see this playground link with the generic function. Here's what @jeswr described. The var |
I think it's worth mentioning the PR #24 which could allow implementors to define concrete term subtypes returned by a data factory @blake-regalia would you interested in picking up where we left that? |
@tpluscode and any interested others in this thread; could you please review DefinitelyTyped/DefinitelyTyped#70614 |
As per issue #45 the
fromTerm
andfromQuad
DataFactory methods defined by the RDF/JS DataModel specification are not reflected in the@rdfjs/types
package.This PR adds those methods.
That said, I am unsure in which context those methods would be used and didn't find an explanation of when it would be or whether the omission is intentional.