fix: preserve term generic type when constructing from another graph (#41606)

* fix: preserve term generic type when constructing from another graph

* style: revert unwanted whitespace change
This commit is contained in:
Tomasz Pluskiewicz
2020-01-15 02:52:54 -05:00
committed by Eli Barzilay
parent cb5127eecf
commit 5101bd7b8a
3 changed files with 35 additions and 11 deletions
+26 -6
View File
@@ -3,6 +3,7 @@ import Clownface = require('clownface/lib/Clownface');
import clownface = require('clownface');
const node: NamedNode = <any> {};
const blankNode: BlankNode = <any> {};
const predicate: NamedNode = <any> {};
const literal: Literal = <any> {};
let term: Term = <any> {};
@@ -13,8 +14,8 @@ const graph: NamedNode = <any> {};
let cf = new Clownface({ dataset });
cf = new Clownface({ dataset, graph });
cf = new Clownface({ dataset, term });
cf = new Clownface({ dataset, term: [term, term] });
const typedByTerm: Clownface<DatasetCore, NamedNode> = new Clownface({ dataset, term: node });
const typedByTerms: Clownface<DatasetCore, NamedNode | BlankNode> = new Clownface({ dataset, term: [node, blankNode] });
cf = new Clownface({ dataset, value: 'foo' });
cf = new Clownface({ dataset, value: ['foo', 'bar'] });
cf = new Clownface({ dataset, term: [term, term], value: ['foo', 'bar'] });
@@ -50,10 +51,10 @@ cf = cf.addOut(predicate, child => {
cf = cf.addOut(cf.node(predicate), cf.node(node));
// .blankNode
let blankNode: Clownface;
blankNode = cf.blankNode();
blankNode = cf.blankNode('label');
blankNode = cf.blankNode([ 'b1', 'b2' ]);
let blankContext: Clownface;
blankContext = cf.blankNode();
blankContext = cf.blankNode('label');
blankContext = cf.blankNode([ 'b1', 'b2' ]);
// .deleteIn
cf = cf.deleteIn();
@@ -74,6 +75,25 @@ cf = clownface({ dataset, term });
cf = clownface({ dataset, graph });
cf = clownface({ dataset, value: 'foo' });
const termContext: Clownface = clownface({
dataset,
term
});
const namedContext: Clownface<DatasetCore, NamedNode> = clownface({
dataset,
term: node,
});
const maybeNamed: BlankNode | NamedNode = <any> {};
const altContext: Clownface<DatasetCore, BlankNode | NamedNode> = clownface({
dataset,
term: maybeNamed,
});
const literalContext: clownface.SingleContextClownface<Dataset, Literal> = <any> {};
const deriveContextFromOtherGraph: Clownface<Dataset, Literal> = clownface(literalContext);
// .filter
cf = cf.filter(() => true);
cf = cf.filter((thus: Clownface) => true);
+8 -4
View File
@@ -30,8 +30,8 @@ declare namespace clownface {
value: string | string[];
}
interface WithTerm {
term: Term | Term[];
interface WithTerm<T extends Term = Term> {
term: T | T[];
}
interface Clownface<D extends DatasetCore = DatasetCore, T extends Term = Term> {
@@ -103,7 +103,11 @@ declare namespace clownface {
}
}
declare function clownface<D extends DatasetCore>(options: clownface.ClownfaceInit<D> & clownface.WithTerm | clownface.ClownfaceInit<D> & clownface.WithValue): clownface.SafeClownface<D>;
declare function clownface<D extends DatasetCore>(options: clownface.ClownfaceInit<D>): clownface.Clownface<D>;
type ClownfaceInitWithNode<D extends DatasetCore, T extends Term> =
clownface.ClownfaceInit<D> & clownface.WithTerm<T> |
clownface.ClownfaceInit<D> & clownface.WithValue;
declare function clownface<D extends DatasetCore, T extends Term = Term>(options: ClownfaceInitWithNode<D, T>): clownface.SafeClownface<D, T>;
declare function clownface<D extends DatasetCore, T extends Term = Term>(options: clownface.ClownfaceInit<D, T>): clownface.Clownface<D, T>;
export = clownface;
+1 -1
View File
@@ -15,7 +15,7 @@ import {
} from '..';
declare class Clownface<D extends DatasetCore = DatasetCore, T extends Term = Term> implements ClownfaceContract<D, T> {
constructor(options: ClownfaceInit & Partial<WithTerm> & Partial<WithValue>);
constructor(options: ClownfaceInit & Partial<WithTerm<T>> & Partial<WithValue>);
readonly term: T | undefined;
readonly terms: T[];
readonly value: string | undefined;