-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
53 lines (42 loc) · 1.35 KB
/
types.ts
File metadata and controls
53 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type * as RDF from '@rdfjs/types';
import type { IShape } from 'query-shape-detection';
import type { Result } from './result/types';
export type SparqlSource = { type: "sparql"; endpoint: string };
export type RdfSource = { type: "rdf"; url: string; format: string };
export type Queryable = {
queryBindings: (sparql: string) => Promise<AsyncIterable<RDF.Bindings>>;
queryQuads: (sparql: string) => Promise<RDF.Quad[]>;
};
export type CatalogSource = {
source: SparqlSource | RdfSource | (() => Queryable | Promise<Queryable>);
graph?: string;
};
export type EntityType = "dcat:Dataset" | "dcat:Distribution" | "dcat:DataService";
export type NonEmptyArray<T> = [T, ...T[]];
export function isNonEmpty<T>(arr: T[]): arr is NonEmptyArray<T> {
return arr.length > 0;
}
export function filterNonNil<T>(arr: (T | null)[]): T[] {
const result: T[] = [];
for (const x of arr) { if (x !== null) result.push(x); }
return result;
}
export type CatalogEntity = {
entity: string;
entityType: EntityType;
shapes: NonEmptyArray<IShape>;
};
export type CatalogRecord = {
id: string;
source: CatalogSource;
entities: NonEmptyArray<CatalogEntity>;
};
export type SearchEntityResult = {
entity: string;
entityType: EntityType;
result: Result;
};
export type SearchCatalogResult = {
catalog: string;
entities: SearchEntityResult[];
};