Closed blake-regalia closed 2 years ago
Latest commit: b54f46912073add09dd388b5447d43a168e27d11
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Would you revert the rdfjs-tests.d.ts.
rename? It did not get picked up by GitHub's diff
Yes, I'm happy to break these out into smaller, more manageable PRs. It's just that several of these changes are intra-dependent so it made it hard to split some of them up.
I understand the veto to 4. InQuad now defaults to StarQuad instead of OutQuad
.
Yes, I'm happy to break these out into smaller, more manageable PRs. It's just that several of these changes are intra-dependent so it made it hard to split some of them up.
I would totally separate "toArray
change".
We may work out the rest. If you look at my branch I linked to, it appears that some of those changes could be avoided?
Closing in favor of new and separate PRs per conversation.
This PR addresses several shortcomings of the current typings, introduces a set of narrower 'Plain' types for developers dealing with pre-RDF-star formats such as Turtle 1.1, and includes several fixes for generics, defaults, arguments, and return types. Closes #5
1. Introduction of 'Plain' and 'Star' namespaces
Not all libraries are ready to adopt the RDF-star specification draft and some will be interested in exclusively dealing with RDF 1.1 data. To accommodate the narrower scope of those 'Plain' Term types, this introduces the following namespaces:
1a.
PlainRole
andStarRole
Unions of Term types for the various roles they play in 'plain' RDF 1.1 Data, and RDF-star data, respectively. Each namespace exports the following named types:
Subject
,Predicate
,Object
,Graph
,Datatype
, andQuad
Note that
PlainRole
is an export-only type and not used by@rdfs/types
internally. It is meant to provide developers with a type for working with serialization formats and datasets that do not (yet) support RDF-star, such as Turtle 1.1 .1b.
PlainPattern
andStarPattern
For each type in
PlainRole
andStarRole
, these pattern interfaces add a union withVariable | null
for the various RDFJS methods that accept term patterns as input.2. Addition of
PlainQuad
andStarQuad
Without removing
BaseQuad
, these two new interfaces extendBaseQuad
by specifying a stricter term type for each quad component than the formerQuad_{Subject|Predicate|Object|Graph}
interfaces. Most notably,PlainQuad
andStarQuad
components do not have unions withVariable
(those cases are covered separately byPlainPattern
andStarPattern
).Note: Each of the
Quad_{Subject|Predicate|Object|Graph}
interfaces are still made available in the exports and carry the same exact types as before. A deprecation annotation has been added to notify the user to consider using one of the more fitting types.3.
OutQuad
now defaults toStarQuad
instead ofBaseQuad
The specification says that each component of the 'Quad' interface be a
Term
, hence whyBaseQuad
exists in the typings. In this PR,OutQuad
still extendsBaseQuad
, meaning that developers may still use quad implementations that have unorthodox term types such asLiteral
in the subject position. However, this PR makes it so that if the generics arguments are omitted, thenOutQuad
will default to a quad with the traditional term types (including the RDF-star subject and object types) for each component. This change provides developers with stronger type information by default without removing features nor deviating from the spec.4.
InQuad
now defaults toStarQuad
instead ofOutQuad
InQuad
should not default toOutQuad
if the 2nd generic argument is omitted. For example:Would imply now that the
quad
parameter is typed toMySpecialQuad
foradd(quad)
,delete(quad)
,has(quad)
, etc. -- but the library should accept all RDFJS terms as arguments in order to implement the spec, not justMySpecialQuad
.By defaulting to
InQuad
toStarQuad
, if this argument is omitted, then the types for quad arguments are assumed to be traditional, RDF-star compatible quads.See 3.1, 3.2, 3.3, 3.4, and 3.5 above for code references.
5.
subject
,predicate
,object
andgraph
arguments are now typed toInQuad['{subject|predicate|object|graph}']
Before this change, each argument in match methods (e.g.,
DatasetCore#match()
,Dataset#deleteMatches()
, and so on...) were typed toTerm
. Now these methods are typed by component types within the given genericInQuad
argument, and each one is union'ed with| Variable | null
.6. Distinguish between
OutQuad
vs.InQuad
generic arguments forSource
andStore
Prior to this PR, the argument types and return type of
Source#match()
(and, by inheritance,Store#match
) were the same; however the implementors should be allowed to accept RDFJS term types as arguments and return a stream of their own implementation ofQuad
. This change allows implementors to specify those two types (OutQuad
andInQuad
) much the same way it is done indataset.d.ts
.Additionally,
Store#removeMatches()
andStore#deleteGraph()
now specifyInQuad
rather than the ambiguousQ
.7. Remove
toArray()
Per https://github.com/rdfjs/dataset-spec/pull/64 .