diff --git a/types/clownface/clownface-tests.ts b/types/clownface/clownface-tests.ts index fb54dd8def..82882d50ae 100644 --- a/types/clownface/clownface-tests.ts +++ b/types/clownface/clownface-tests.ts @@ -1,4 +1,4 @@ -import { Term, NamedNode, Dataset, Literal } from 'rdf-js'; +import { Term, NamedNode, Dataset, Literal, DatasetCore, BlankNode } from 'rdf-js'; import Clownface = require('clownface/lib/Clownface'); import clownface = require('clownface'); @@ -143,3 +143,18 @@ if (cf.value) { // .values const values: string[] = cf.values; + +const safeCf: clownface.SafeClownface = {}; + +const singleBlankAuto: clownface.SingleContextClownface = safeCf.blankNode(); +const SingleBlank: clownface.SingleContextClownface = safeCf.blankNode('blank'); +const singleNamed: clownface.SingleContextClownface = safeCf.namedNode('http://example.com/a'); +const singleLiteral: clownface.SingleContextClownface = safeCf.literal('a'); + +const fromSingleArrayBLank: clownface.SingleContextClownface = safeCf.blankNode([ 'b1' ]); +const fromSingleArrayNamed: clownface.SingleContextClownface = safeCf.namedNode([ 'http://example.com/a' ]); +const fromSingleArrayLiteral: clownface.SingleContextClownface = safeCf.literal([ 'a' ]); + +const multipleBlanks: clownface.SafeClownface = safeCf.blankNode([ 'b1', 'b2' ]); +const multipleNamed: clownface.SafeClownface = safeCf.namedNode([ 'http://example.com/a', 'http://example.com/b' ]); +const multipleLiterals: clownface.SafeClownface = safeCf.literal([ 'a', 'b' ]); diff --git a/types/clownface/index.d.ts b/types/clownface/index.d.ts index 53ec9d136f..f03fc076ff 100644 --- a/types/clownface/index.d.ts +++ b/types/clownface/index.d.ts @@ -12,6 +12,7 @@ declare namespace clownface { type AddCallback = (added: SingleContextClownface) => void; type SingleOrArray = T | T[]; + type SingleOrOneElementArray = T | [T]; type SingleOrArrayOfTerms = SingleOrArray; type SingleOrArrayOfTermsOrLiterals = SingleOrArray; @@ -73,6 +74,20 @@ declare namespace clownface { } interface SafeClownface extends Clownface { + // tslint:disable:no-unnecessary-generics + node(value: SingleOrOneElementArray, options?: NodeOptions): SingleContextClownface; + node(values: Array, options?: NodeOptions): SafeClownface; + // tslint:enable:no-unnecessary-generics + + blankNode(value?: SingleOrOneElementArray): SingleContextClownface; + blankNode(values: string[]): SafeClownface; + + literal(value: SingleOrOneElementArray, languageOrDatatype?: string | NamedNode): SingleContextClownface; + literal(values: Array, languageOrDatatype?: string | NamedNode): SafeClownface; + + namedNode(value: SingleOrOneElementArray): SingleContextClownface; + namedNode(values: Array): SafeClownface; + filter(cb: (quad: SingleContextClownface) => boolean): SafeClownface; forEach(cb: (quad: SingleContextClownface) => void): void; map(cb: (quad: SingleContextClownface, index: number) => X): X[];