-
Notifications
You must be signed in to change notification settings - Fork 4
/
linked-delta.ts
40 lines (33 loc) · 1.33 KB
/
linked-delta.ts
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
import { Quad, Quadruple } from "@ontologies/core";
import { NQuadsParser } from "n-quads-parser";
import { LinkedRenderStore } from "../LinkedRenderStore";
import {
ExtensionResponse,
RDFLibFetcherRequest,
ResponseAndFallbacks,
ResponseTransformer,
} from "../types";
/**
* Processes linked-delta responses.
*/
export function linkedDeltaProcessor(lrs: LinkedRenderStore<any>): ResponseTransformer {
return async function processLinkedDelta(response: ResponseAndFallbacks): Promise<Quad[]> {
let data: string;
if (response instanceof Response) {
data = response.bodyUsed ? "" : await response.text();
} else if (typeof XMLHttpRequest !== "undefined" && response instanceof XMLHttpRequest) {
data = response.responseText;
} else {
data = (response as RDFLibFetcherRequest | ExtensionResponse).body;
}
if (!data || data.length === 0) {
return [];
}
const parser = new NQuadsParser((lrs as any).store.getInternalStore());
const quads = parser.parseString(data) as Array<Quadruple | void>;
const expedite = response.hasOwnProperty("expedite") ? (response as any).expedite : false;
lrs.queueDelta(quads, expedite);
// TODO: Resolve the statements in this request
return [];
};
}