N3.js icon indicating copy to clipboard operation
N3.js copied to clipboard

GetQuads has a false Typescript definition

Open mauritsderoover opened this issue 2 years ago • 4 comments

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

mauritsderoover avatar Feb 09 '23 11:02 mauritsderoover

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 avatar Feb 09 '23 12:02 jeswr

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

jeswr avatar Feb 09 '23 12:02 jeswr

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<Iri extends string = string> implements RDF.NamedNode<Iri> {

readonly termType = "NamedNode";

readonly value: Iri;

constructor(value: Iri);

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

}`

N3

`export class NamedNode<Iri extends string = string> implements RDF.NamedNode<Iri> {

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.

mauritsderoover avatar Feb 09 '23 13:02 mauritsderoover

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)

jeswr avatar Feb 09 '23 22:02 jeswr