Skip to content

Commit

Permalink
Add missing spec methods to DataFactory interface
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieubosquet committed Sep 10, 2024
1 parent ec006f7 commit a29a566
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @rdfjs/types

## 1.1.1

### Minor Changes

- Add missing methods to DataFactory interface

## 1.1.0

### Minor 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 @@ -84,6 +84,21 @@ function test_datafactory() {

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 @@ function test_datafactory_star() {
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 @@ function test_datafactory_star_basequad() {
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

0 comments on commit a29a566

Please sign in to comment.