From bcfad613230a9140d4b4e08029578fd7bad9efa8 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Thu, 30 Jan 2020 22:05:38 +0100 Subject: [PATCH] fix: stub out the Context class (#41961) * fix: stub out the Context class * fix: _context is actually an array * fix: single term = single context --- types/clownface/clownface-tests.ts | 7 ++++++- types/clownface/index.d.ts | 4 +++- types/clownface/lib/Clownface.d.ts | 3 ++- types/clownface/lib/Context.d.ts | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 types/clownface/lib/Context.d.ts diff --git a/types/clownface/clownface-tests.ts b/types/clownface/clownface-tests.ts index dea754b887..cc053eabbd 100644 --- a/types/clownface/clownface-tests.ts +++ b/types/clownface/clownface-tests.ts @@ -1,4 +1,4 @@ -import { Term, NamedNode, Dataset, Literal, DatasetCore, BlankNode } from 'rdf-js'; +import { Term, NamedNode, Dataset, Literal, DatasetCore, BlankNode, Quad_Graph } from 'rdf-js'; import Clownface = require('clownface/lib/Clownface'); import clownface = require('clownface'); @@ -204,3 +204,8 @@ let multipleLiterals: clownface.SafeClownface = safeCf.literal multipleLiterals = clownface({ dataset }).node([ 'a', 10, false ]); const multipleMixedTerms: clownface.SafeClownface = clownface({ dataset }).node([ 'a', node, null ]); + +// .context +const ctxTerm: Literal = fromSingleArrayLiteral._context[0].term; +const ctxGraph: Quad_Graph | undefined = fromSingleArrayLiteral._context[0].graph; +const ctxDataset: Dataset = fromSingleArrayLiteral._context[0].dataset; diff --git a/types/clownface/index.d.ts b/types/clownface/index.d.ts index f4a2744e4b..66389ffd36 100644 --- a/types/clownface/index.d.ts +++ b/types/clownface/index.d.ts @@ -5,6 +5,7 @@ // TypeScript Version: 2.3 import { Term, DatasetCore, Quad_Graph, NamedNode, BlankNode, Literal } from 'rdf-js'; +import { Context } from './lib/Context'; declare namespace clownface { type TermOrClownface = Clownface | Term; @@ -49,7 +50,7 @@ declare namespace clownface { readonly values: string[]; readonly dataset: D; readonly datasets: D[]; - readonly _context: any; + readonly _context: Array>; list(): Iterable>; toArray(): Array>; filter(cb: (quad: Clownface) => boolean): Clownface; @@ -108,6 +109,7 @@ declare namespace clownface { readonly terms: [T]; readonly value: string; readonly values: [string]; + readonly _context: [Context]; } } diff --git a/types/clownface/lib/Clownface.d.ts b/types/clownface/lib/Clownface.d.ts index 81cbb4b6c0..657316487b 100644 --- a/types/clownface/lib/Clownface.d.ts +++ b/types/clownface/lib/Clownface.d.ts @@ -15,6 +15,7 @@ import { SingleContextClownface, SingleOrOneElementArray } from '..'; +import { Context } from './Context'; declare class Clownface implements ClownfaceContract { constructor(options: ClownfaceInit & Partial | WithTerms> & Partial); @@ -24,7 +25,7 @@ declare class Clownface>; list(): Iterable>; toArray(): Array>; filter(cb: (quad: Clownface) => boolean): Clownface; diff --git a/types/clownface/lib/Context.d.ts b/types/clownface/lib/Context.d.ts new file mode 100644 index 0000000000..9bbd1288fa --- /dev/null +++ b/types/clownface/lib/Context.d.ts @@ -0,0 +1,18 @@ +import { DatasetCore, Quad_Graph, Term } from 'rdf-js'; + +declare namespace Context { + interface Context { + dataset: D; + graph?: Quad_Graph; + term: T; + } +} + +declare class Context implements Context.Context { + constructor(dataset: D, graph: Quad_Graph | undefined, value: any); + dataset: D; + graph?: Quad_Graph; + term: T; +} + +export = Context;