rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
676 stars 127 forks source link

GetQuads has a false Typescript definition #322

Open mauritsderoover opened 1 year ago

mauritsderoover commented 1 year ago

Every parameter in GetQuads should accept null or undefined but in the type definition file it is required to provide a OTerm.

I could change the type definitions and create a pull request if you would point me in the right direction.

Related to #139 #298

jeswr commented 1 year ago

Generally speaking I would recommend using #match() rather than #getQuads() as #match() is the method used by the RDF/JS dataset interface.

I'm also happy to review a PR to definitelyTyped updating the types.

jeswr commented 1 year ago

Also something that should probably be updated at the same time is ensuring that Quads are valid subject and object Terms

mauritsderoover commented 1 year ago

Are you referring to for example to the different implementations of RDF.NamedNode in rdf-data-factory and N3?

Rdf-data-factory => this seems to be the correct implementation of the rdf-js specification `export declare class NamedNode implements RDF.NamedNode {

readonly termType = "NamedNode";

readonly value: Iri;

constructor(value: Iri);

equals(other?: RDF.Term | null): boolean;

}`

N3

`export class NamedNode implements RDF.NamedNode {

readonly termType: "NamedNode";

readonly value: Iri;

constructor(iri: Iri);

readonly id: string;

toJSON(): {};

equals(other: RDF.Term): boolean;

static subclass(type: any): void;

}`

This basically means that I cannot use a quad from the factory with a N3.store without asserting types.

jeswr commented 1 year ago

I mean that

export type Quad_Subject = NamedNode | BlankNode | Variable;
export type Quad_Predicate = NamedNode | Variable;
export type Quad_Object = NamedNode | Literal | BlankNode | Variable;
export type Quad_Graph = DefaultGraph | NamedNode | BlankNode | Variable;

at the very least should be

export type Quad_Subject = NamedNode | BlankNode | Variable | BaseQuad;
export type Quad_Predicate = NamedNode | Variable;
export type Quad_Object = NamedNode | Literal | BlankNode | Variable | BaseQuad;
export type Quad_Graph = DefaultGraph | NamedNode | BlankNode | Variable;

to reflect the fact that the store supports rdf-star nested triples (in actual fact the implementation really supports BaseQuads in any position; but whether to expose that in the TS interface is another question)