Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions types/clownface/clownface-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,17 @@ function testHas() {
const cf: AnyPointer<Term, Dataset> = <any> {};
let has: AnyPointer<Array<NamedNode | BlankNode>, Dataset> = cf.has(predicate, "Stuart");
has = cf.has([predicate, predicate], "Stuart");
has = cf.has(new Set([predicate, predicate]), "Stuart");
has = cf.has(predicate, [literal, literal]);
has = cf.has(predicate, new Set([literal, literal]));
}

function testIn() {
const cf: AnyPointer<Literal, Dataset> = <any> {};
let cfIn: MultiPointer<NamedNode | BlankNode, Dataset> = cf.in();
cfIn = cf.in(node);
cfIn = cf.in([node, node]);
cfIn = cf.in(new Set([node, node]));
cfIn = cf.in(cf.node(node));
cfIn = cf.in(cf.node([node, node]));

Expand Down Expand Up @@ -363,6 +366,7 @@ function testNode() {
let cfLit: AnyPointer<Literal, Dataset> = cf.node("foo");
cfLit = cf.node(123);
const cfLitMany: AnyPointer<Literal[], Dataset> = cf.node(["foo", "bar"]);
const cfLitManyFromSet: AnyPointer<Literal[], Dataset> = cf.node(new Set(["foo", "bar"]));
singleTerm = cf.node("http://example.org/", { type: "NamedNode" });
const cfBlank: AnyPointer<BlankNode, Dataset> = cf.node(null, { type: "BlankNode" });
cfLit = cf.node("example", { datatype: node.value });
Expand All @@ -385,6 +389,7 @@ function testOut() {
let cfTerm: AnyPointer<Term[], Dataset> = cf.out();
cfTerm = cf.out(node);
cfTerm = cf.out([node, node]);
cfTerm = cf.out(new Set([node, node]));
cfTerm = cf.out(cf.node([node, node]));

const singleContext: AnyPointer<NamedNode, Dataset> = <any> {};
Expand Down Expand Up @@ -458,7 +463,14 @@ function addInAddOutRetainsType() {

const addOutSingle: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(predicate, "foo");
const addOutSingleObjectArray: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(predicate, ["foo", "bar"]);
const addOutSingleObjectSet: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(
predicate,
new Set(["foo", "bar"]),
);
const addOutSinglePredicateArray: AnyPointer<NamedNode, Dataset> = singleNamed.addOut([predicate, predicate]);
const addOutSinglePredicateSet: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(
new Set([predicate, predicate]),
);
const addOutSingleNoObject: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(predicate);
const addOutSingleWithCallback: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(predicate, () => {});
const addOutSingleWithObjectAndCallback: AnyPointer<NamedNode, Dataset> = singleNamed.addOut(
Expand All @@ -469,7 +481,9 @@ function addInAddOutRetainsType() {

const addInSingle: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(predicate, "foo");
const addInSingleObjectArray: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(predicate, ["foo", "bar"]);
const addInSingleObjectSet: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(predicate, new Set(["foo", "bar"]));
const addInSinglePredicateArray: AnyPointer<NamedNode, Dataset> = singleNamed.addIn([predicate, predicate]);
const addInSinglePredicateSet: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(new Set([predicate, predicate]));
const addInSingleNoObject: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(predicate);
const addInSingleWithCallback: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(predicate, () => {});
const addInSingleWithObjectAndCallback: AnyPointer<NamedNode, Dataset> = singleNamed.addIn(
Expand Down
14 changes: 6 additions & 8 deletions types/clownface/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TermOrClownface<X extends Term = Term> = MultiPointer<X> | X;
type TermOrLiteral<X extends Term = Term> = TermOrClownface<X> | string | number | boolean;

type AddCallback<D extends DatasetCore, X extends Term> = (added: AnyPointer<X, D>) => void;
type SingleOrArray<T> = T | readonly T[];
type SingleOrArray<T> = T | readonly T[] | Iterable<T>;
type SingleOrOneElementArray<T> = T | readonly [T];

type SingleOrArrayOfTerms<X extends Term> = SingleOrArray<X> | MultiPointer<X>;
Expand Down Expand Up @@ -85,7 +85,7 @@ export interface AnyPointer<T extends AnyContext = AnyContext, D extends Dataset

node(value: SingleOrOneElementArray<boolean | string | number>, options?: NodeOptions): AnyPointer<Literal, D>;

node(values: Array<boolean | string | number>, options?: NodeOptions): AnyPointer<Literal[], D>;
node(values: Iterable<boolean | string | number>, options?: NodeOptions): AnyPointer<Literal[], D>;

node<X extends Term>(value: SingleOrOneElementArray<X> | AnyPointer<X, D>, options?: NodeOptions): AnyPointer<X, D>;

Expand All @@ -100,14 +100,14 @@ export interface AnyPointer<T extends AnyContext = AnyContext, D extends Dataset
node(values: null[] | Iterable<BlankNode>, options?: NodeOptions): AnyPointer<BlankNode[], D>;

node(
values: Array<boolean | string | number | Term | null> | Iterable<Term>,
values: Iterable<boolean | string | number | Term | null>,
options?: NodeOptions,
): AnyPointer<Term[], D>;

blankNode(value?: SingleOrOneElementArray<string> | AnyPointer<BlankNode, D>): AnyPointer<BlankNode, D>;

blankNode(
values: string[] | MultiPointer<BlankNode, D> | Iterable<BlankNode> | Iterable<GraphPointer<BlankNode, D>>,
values: MultiPointer<BlankNode, D> | Iterable<BlankNode | string> | Iterable<GraphPointer<BlankNode, D>>,
): AnyPointer<BlankNode[], D>;

literal(
Expand All @@ -117,9 +117,8 @@ export interface AnyPointer<T extends AnyContext = AnyContext, D extends Dataset

literal(
values:
| Array<boolean | string | number | null>
| Iterable<boolean | string | number | null | Literal>
| MultiPointer<Literal, D>
| Iterable<Literal>
| Iterable<GraphPointer<Literal, D>>,
languageOrDatatype?: string | NamedNode,
): AnyPointer<Literal[], D>;
Expand All @@ -130,9 +129,8 @@ export interface AnyPointer<T extends AnyContext = AnyContext, D extends Dataset

namedNode(
values:
| Array<string | NamedNode>
| Iterable<string | NamedNode>
| MultiPointer<NamedNode, D>
| Iterable<NamedNode>
| Iterable<GraphPointer<NamedNode, D>>,
): AnyPointer<NamedNode[], D>;

Expand Down