Skip to content

Commit

Permalink
Better typing of SPARQL Results JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
darashi committed Mar 5, 2024
1 parent cf9e476 commit 9cfd524
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,43 @@ import {
DescribeQuery,
} from "sparqljs";

type SPARQLResult = unknown; // TODO
type IRI = { type: "uri"; value: string };
type Literal = { type: "literal"; value: string };
type LiteralWithLanguageTag = Literal & { "xml:lang": string };
type LiteralWithDatatypeIRI = Literal & { datatype: string };
type BlankNode = { type: "bnode"; value: string };
type RDFTerm =
| IRI
| Literal
| LiteralWithLanguageTag
| LiteralWithDatatypeIRI
| BlankNode;

type Binding = Record<string, RDFTerm>;

export type SPARQLJSONResults = {
head: {
vars: string[];
link?: string[];
};
results: {
bindings: Binding[];
};
boolean: never;
};

export type SPARQLBooleanResults = {
head: {
link?: string[];
};
boolean: boolean;
results: never;
};

export type SPARQLResults = SPARQLJSONResults | SPARQLBooleanResults;

export type Response = {
body: SPARQLResult;
body: SPARQLResults;
headers: Record<string, string>;
contentType: string;
};
Expand Down

0 comments on commit 9cfd524

Please sign in to comment.