fix: stub out the Context class (#41961)

* fix: stub out the Context class

* fix: _context is actually an array

* fix: single term = single context
This commit is contained in:
Tomasz Pluskiewicz 2020-01-30 22:05:38 +01:00 committed by GitHub
parent 4e24fd4188
commit bcfad61323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -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<Dataset, Literal> = safeCf.literal
multipleLiterals = clownface({ dataset }).node([ 'a', 10, false ]);
const multipleMixedTerms: clownface.SafeClownface<Dataset> = 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;

View File

@ -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<Context<D, T>>;
list(): Iterable<SingleContextClownface<D>>;
toArray(): Array<Clownface<D, T>>;
filter(cb: (quad: Clownface<D, T>) => boolean): Clownface<D, T>;
@ -108,6 +109,7 @@ declare namespace clownface {
readonly terms: [T];
readonly value: string;
readonly values: [string];
readonly _context: [Context<D, T>];
}
}

View File

@ -15,6 +15,7 @@ import {
SingleContextClownface,
SingleOrOneElementArray
} from '..';
import { Context } from './Context';
declare class Clownface<D extends DatasetCore = DatasetCore, T extends Term = Term> implements ClownfaceContract<D, T> {
constructor(options: ClownfaceInit & Partial<WithSingleTerm<T> | WithTerms<T>> & Partial<WithSingleValue | WithValues>);
@ -24,7 +25,7 @@ declare class Clownface<D extends DatasetCore = DatasetCore, T extends Term = Te
readonly values: string[];
readonly dataset: D;
readonly datasets: D[];
readonly _context: any;
readonly _context: Array<Context<D, T>>;
list(): Iterable<SingleContextClownface<D>>;
toArray(): Array<Clownface<D, T>>;
filter(cb: (quad: Clownface<D, T>) => boolean): Clownface<D, T>;

18
types/clownface/lib/Context.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
import { DatasetCore, Quad_Graph, Term } from 'rdf-js';
declare namespace Context {
interface Context<D extends DatasetCore, T extends Term> {
dataset: D;
graph?: Quad_Graph;
term: T;
}
}
declare class Context<D extends DatasetCore, T extends Term> implements Context.Context<D, T> {
constructor(dataset: D, graph: Quad_Graph | undefined, value: any);
dataset: D;
graph?: Quad_Graph;
term: T;
}
export = Context;