Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @rdfjs/types

## 2.0.0

### Major Changes

- Add missing methods to DataFactory interface

## 1.1.1

### Patch Changes
Expand Down
14 changes: 14 additions & 0 deletions data-model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,18 @@ export interface DataFactory<OutQuad extends BaseQuad = Quad, InQuad extends Bas
* @see Quad
*/
quad(subject: InQuad['subject'], predicate: InQuad['predicate'], object: InQuad['object'], graph?: InQuad['graph']): OutQuad;

/**
* @param original The original term.
* @return A new instance of the term such that newTermInstance.equals(original) returns true.
* @see Term
*/
fromTerm(original: Term): Term;

/**
* @param original The original quad.
* @return A new instance of the quad such that newQuadInstance.equals(original) returns true.
* @see Quad
*/
fromQuad(original: InQuad): OutQuad;
}
21 changes: 21 additions & 0 deletions rdf-js-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

const namedNodeConstant: NamedNode<'http://example.org'> = <any> {};
const constantIri: 'http://example.org' = namedNodeConstant.value;
// @ts-expect-error

Check warning on line 22 in rdf-js-tests.ts

View workflow job for this annotation

GitHub Actions / build

Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer
const otherConstantIri: 'http://not-example.org' = namedNodeConstant.value;
// @ts-expect-error
const otherNamedNodeConstant: NamedNode<'http://not-example.org'> = namedNodeConstant;
Expand Down Expand Up @@ -84,6 +84,21 @@

const variable: Variable = dataFactory.variable ? dataFactory.variable('v1') : <any> {};

const defaultGraph: DefaultGraph = dataFactory.defaultGraph();

const term1: Term = dataFactory.fromTerm(dataFactory.namedNode(""));
const term2: Term = dataFactory.fromTerm(dataFactory.blankNode());
const term3: Term = dataFactory.fromTerm(dataFactory.literal(""));
const term4: Term = dataFactory.fromTerm(dataFactory.variable ? dataFactory.variable("v1") : <any> {});
const term5: Term = dataFactory.fromTerm(dataFactory.defaultGraph());

const quadFromQuad: Term = dataFactory.fromQuad(dataFactory.quad(
dataFactory.namedNode("x"),
dataFactory.namedNode("y"),
dataFactory.literal(""),
dataFactory.defaultGraph()
));

const term: NamedNode = <any> {};
interface QuadBnode extends BaseQuad {
subject: Term;
Expand Down Expand Up @@ -119,6 +134,8 @@
const equalToSelf: boolean = quadBobAge2.equals(quadBobAge);
const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else'));
}

const quadTerm: Term = dataFactory.fromTerm(quadBobAge);
}

function test_datafactory_star_basequad() {
Expand All @@ -143,6 +160,10 @@
const equalToSelf: boolean = quadBobAge2.equals(quadBobAge);
const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else'));
}

const baseQuadTerm: Term = dataFactory.fromTerm(quadBobAge);

const baseQuad: BaseQuad = dataFactory.fromQuad(quadBobAge);
}

function test_stream() {
Expand Down
Loading