From b0ca1a94a9735e56711ffca92c3202b9e5f5af28 Mon Sep 17 00:00:00 2001 From: Matthieu Bosquet Date: Mon, 9 Sep 2024 17:01:51 +0100 Subject: [PATCH 1/5] Add missing spec methods to DataFactory interface --- CHANGELOG.md | 6 ++++++ data-model.d.ts | 14 ++++++++++++++ rdf-js-tests.ts | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca6925e..e7f2211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @rdfjs/types +## 2.0.0 + +### Major Changes + +- Add missing methods to DataFactory interface + ## 1.1.1 ### Patch Changes diff --git a/data-model.d.ts b/data-model.d.ts index 6fff406..8f7f80b 100644 --- a/data-model.d.ts +++ b/data-model.d.ts @@ -287,4 +287,18 @@ export interface DataFactory {}; + 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") : {}); + 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 = {}; interface QuadBnode extends BaseQuad { subject: Term; @@ -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() { @@ -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() { From 14906cfc5f820fa530cf2901860193ed350e0673 Mon Sep 17 00:00:00 2001 From: Matthieu Bosquet Date: Wed, 11 Sep 2024 16:34:08 +0100 Subject: [PATCH 2/5] Use changeset instead of changelog --- .changeset/afraid-donuts-retire.md | 5 +++++ CHANGELOG.md | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 .changeset/afraid-donuts-retire.md diff --git a/.changeset/afraid-donuts-retire.md b/.changeset/afraid-donuts-retire.md new file mode 100644 index 0000000..cae0f33 --- /dev/null +++ b/.changeset/afraid-donuts-retire.md @@ -0,0 +1,5 @@ +--- +"@rdfjs/types": major +--- + +Add missing methods to DataFactory interface diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f2211..ca6925e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,5 @@ # @rdfjs/types -## 2.0.0 - -### Major Changes - -- Add missing methods to DataFactory interface - ## 1.1.1 ### Patch Changes From 1bc86956f88182629f0c1bd5dccaa90d40463090 Mon Sep 17 00:00:00 2001 From: Matthieu Bosquet Date: Mon, 16 Sep 2024 17:57:54 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Tomasz Pluskiewicz --- .changeset/afraid-donuts-retire.md | 2 +- data-model.d.ts | 8 +++++++- rdf-js-tests.ts | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.changeset/afraid-donuts-retire.md b/.changeset/afraid-donuts-retire.md index cae0f33..23e13d9 100644 --- a/.changeset/afraid-donuts-retire.md +++ b/.changeset/afraid-donuts-retire.md @@ -2,4 +2,4 @@ "@rdfjs/types": major --- -Add missing methods to DataFactory interface +Add missing methods `fromTerm` and `fromQuad` to the `DataFactory` interface diff --git a/data-model.d.ts b/data-model.d.ts index 8f7f80b..7ed8c5e 100644 --- a/data-model.d.ts +++ b/data-model.d.ts @@ -293,7 +293,13 @@ export interface DataFactory(original: T): NamedNode; + fromTerm(original: T): BlankNode; + fromTerm(original: T): Literal; + fromTerm(original: T): Variable; + fromTerm(original: T): DefaultGraph; + fromTerm(original: T): OutQuad; + fromTerm(original: T): T; /** * @param original The original quad. diff --git a/rdf-js-tests.ts b/rdf-js-tests.ts index 121e902..39fba4d 100644 --- a/rdf-js-tests.ts +++ b/rdf-js-tests.ts @@ -86,11 +86,16 @@ function test_datafactory() { 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") : {}); - const term5: Term = dataFactory.fromTerm(dataFactory.defaultGraph()); + type NamedNodeExt = NamedNode & { someProp: string }; + const term1: NamedNode = dataFactory.fromTerm({}); + type BlankNodeExt = BlankNode & { someProp: string }; + const term2: BlankNode = dataFactory.fromTerm({}); + type LiteralExt = Literal & { someProp: string }; + const term3: Literal = dataFactory.fromTerm({}); + type VariableExt = Variable & { someProp: string }; + const term4: Variable = dataFactory.fromTerm( {}); + type DefaultGraphExt = DefaultGraph & { someProp: string }; + const term5: DefaultGraph = dataFactory.fromTerm({}); const quadFromQuad: Term = dataFactory.fromQuad(dataFactory.quad( dataFactory.namedNode("x"), @@ -135,7 +140,7 @@ function test_datafactory_star() { const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else')); } - const quadTerm: Term = dataFactory.fromTerm(quadBobAge); + const quadTerm: Quad = dataFactory.fromTerm(quadBobAge); } function test_datafactory_star_basequad() { @@ -161,7 +166,7 @@ function test_datafactory_star_basequad() { const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else')); } - const baseQuadTerm: Term = dataFactory.fromTerm(quadBobAge); + const baseQuadTerm: Quad = dataFactory.fromTerm(quadBobAge); const baseQuad: BaseQuad = dataFactory.fromQuad(quadBobAge); } From f1879fbe4b141efacd433ef16e34883b5d65119a Mon Sep 17 00:00:00 2001 From: Matthieu Bosquet Date: Mon, 16 Sep 2024 18:16:11 +0100 Subject: [PATCH 4/5] Fix fromTerm tests --- rdf-js-tests.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rdf-js-tests.ts b/rdf-js-tests.ts index 39fba4d..220016f 100644 --- a/rdf-js-tests.ts +++ b/rdf-js-tests.ts @@ -166,9 +166,20 @@ function test_datafactory_star_basequad() { const notEqualToOtherType: boolean = quadBobAge2.equals(dataFactory.namedNode('ex:something:else')); } - const baseQuadTerm: Quad = dataFactory.fromTerm(quadBobAge); + const baseQuadTerm: BaseQuad = dataFactory.fromTerm(quadBobAge); const baseQuad: BaseQuad = dataFactory.fromQuad(quadBobAge); + + // Test with regular Quad + const quadDataFactory: DataFactory = {}; + + const regularQuadBobAge: Quad = quadDataFactory.quad( + dataFactory.namedNode('ex:bob'), + dataFactory.namedNode('ex:age'), + dataFactory.literal('23'), + ); + + const quadTerm: Quad = quadDataFactory.fromTerm(regularQuadBobAge); } function test_stream() { From cfc4d28422d102ab0ed316e819fef5efa69f09ef Mon Sep 17 00:00:00 2001 From: Matthieu Bosquet Date: Thu, 5 Dec 2024 12:43:24 +0200 Subject: [PATCH 5/5] Apply jeswr suggestion --- data-model.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data-model.d.ts b/data-model.d.ts index 7ed8c5e..50ca6d5 100644 --- a/data-model.d.ts +++ b/data-model.d.ts @@ -298,7 +298,7 @@ export interface DataFactory(original: T): Literal; fromTerm(original: T): Variable; fromTerm(original: T): DefaultGraph; - fromTerm(original: T): OutQuad; + fromTerm(original: T): OutQuad; fromTerm(original: T): T; /**