Skip to content

Commit

Permalink
Migrate to rdf-data-factory and @types/rdf-js 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Sep 16, 2020
1 parent 20b09d1 commit 2acc5d2
Show file tree
Hide file tree
Showing 21 changed files with 1,659 additions and 1,626 deletions.
4 changes: 2 additions & 2 deletions lib/DocumentLoaderCached.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IDocumentLoader, IJsonLdContextNormalized} from "jsonld-context-parser";
import {IDocumentLoader, IJsonLdContext} from "jsonld-context-parser";
import {IFetchOptions, Util} from "./Util";

/**
Expand All @@ -12,7 +12,7 @@ export class DocumentLoaderCached implements IDocumentLoader {
this.options = options;
}

public async load(url: string): Promise<IJsonLdContextNormalized> {
public async load(url: string): Promise<IJsonLdContext> {
const { body } = await Util.fetchCached(url,
this.options, { headers: { accept: 'application/ld+json' } });
return JSON.parse(await require('stream-to-string')(body));
Expand Down
4 changes: 2 additions & 2 deletions lib/GeneralizedN3StreamParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {Parser} from "n3";
import {Transform} from "stream";

// Temporarily set format to text/n3 to allow blank node predicates (needed by JSON-LD tests)
const readPredicateOld = Parser.prototype._readPredicate;
const readPredicateOld = (<any> Parser.prototype)._readPredicate;
// tslint:disable-next-line:only-arrow-functions
Parser.prototype._readPredicate = function(token: any) {
(<any> Parser.prototype)._readPredicate = function(token: any) {
if (this.allowBlankNodePredicates) {
this._n3Mode = true;
this._quantified = {};
Expand Down
11 changes: 6 additions & 5 deletions lib/TestSuiteRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {literal, namedNode, triple} from "@rdfjs/data-model";
import {DataFactory} from "rdf-data-factory";
import * as LogSymbols from "log-symbols";
import * as RDF from "rdf-js";
import {IManifest} from "./IManifest";
Expand All @@ -10,6 +10,7 @@ import Timeout = NodeJS.Timeout;
// tslint:disable:no-var-requires
const quad = require('rdf-quad');
const streamifyArray = require('streamify-array');
const DF = new DataFactory();

export interface ITestSuiteConfig {
exitWithStatusCode0: boolean;
Expand Down Expand Up @@ -181,11 +182,11 @@ ${LogSymbols.error} ${result.test.name}

// Describe report
const report = properties.reportUri || '';
quads.push(triple(namedNode(report), namedNode(p.foaf + 'primaryTopic'), namedNode(properties.applicationUri)));
quads.push(triple(namedNode(report), namedNode(p.dc + 'issued'), literal(testDate.toISOString(),
namedNode(p.xsd + 'dateTime'))));
quads.push(DF.quad(DF.namedNode(report), DF.namedNode(p.foaf + 'primaryTopic'), DF.namedNode(properties.applicationUri)));
quads.push(DF.quad(DF.namedNode(report), DF.namedNode(p.dc + 'issued'), DF.literal(testDate.toISOString(),
DF.namedNode(p.xsd + 'dateTime'))));
for (const author of properties.authors) {
quads.push(triple(namedNode(report), namedNode(p.foaf + 'maker'), namedNode(author.uri)));
quads.push(DF.quad(DF.namedNode(report), DF.namedNode(p.foaf + 'maker'), DF.namedNode(author.uri)));
}

// Describe application
Expand Down
6 changes: 3 additions & 3 deletions lib/testcase/rdfsyntax/jsonld/TestCaseJsonLdToRdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {Resource} from "rdf-object";
import {resolve} from "relative-to-absolute-iri";
import {IFetchOptions, Util} from "../../../Util";
import {ITestCase, ITestCaseData} from "../../ITestCase";
import {IParser} from "../IParser";
import {TestCaseEval, TestCaseEvalHandler} from "../TestCaseEval";
import {namedNode} from "@rdfjs/data-model";
import {DataFactory} from "rdf-data-factory";
const DF = new DataFactory();

/**
* Test case handler for:
Expand All @@ -21,7 +21,7 @@ export class TestCaseJsonLdToRdfHandler extends TestCaseEvalHandler {
const testProperties: any = {};

// Only apply some properties for HTML tests
const isHtml = resource.isA(namedNode('https://w3c.github.io/json-ld-api/tests/vocab#HtmlTest'));
const isHtml = resource.isA(DF.namedNode('https://w3c.github.io/json-ld-api/tests/vocab#HtmlTest'));
if (isHtml) {
injectArguments.contentType = 'text/html';
}
Expand Down
7 changes: 4 additions & 3 deletions lib/testcase/sparql/TestCaseQueryEvaluation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {namedNode} from "@rdfjs/data-model";
import {DataFactory} from "rdf-data-factory";
import * as RDF from "rdf-js";
import {RdfObjectLoader, Resource} from "rdf-object";
import {stringToTerm} from "rdf-string";
Expand All @@ -17,6 +17,7 @@ import {QueryResultQuads} from "./QueryResultQuads";
// tslint:disable:no-var-requires
const arrayifyStream = require('arrayify-stream');
const stringifyStream = require('stream-to-string');
const DF = new DataFactory();

/**
* Test case handler for http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#QueryEvaluationTest.
Expand Down Expand Up @@ -208,12 +209,12 @@ export class TestCaseQueryEvaluationHandler implements ITestCaseHandler<TestCase
if (graphData.property.graph) {
queryDataLinks.push({
dataUri: graphData.property.graph.value,
dataGraph: namedNode(Util.normalizeBaseUrl(graphData.property.label.value)),
dataGraph: DF.namedNode(Util.normalizeBaseUrl(graphData.property.label.value)),
});
} else {
queryDataLinks.push({
dataUri: graphData.value,
dataGraph: namedNode(Util.normalizeBaseUrl(graphData.value)),
dataGraph: DF.namedNode(Util.normalizeBaseUrl(graphData.value)),
});
}
}
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/jest": "^26.0.0",
"coveralls": "^3.0.0",
"jest": "^26.0.1",
"jest-rdf": "^1.3.0",
"jest-rdf": "^1.6.0",
"manual-git-changelog": "^1.0.1",
"pre-commit": "^1.2.2",
"rimraf": "^3.0.0",
Expand Down Expand Up @@ -84,27 +84,27 @@
"@types/json-stable-stringify": "^1.0.32",
"@types/log-symbols": "^3.0.0",
"@types/minimist": "^1.2.0",
"@types/n3": "^1.1.6",
"@types/rdf-js": "^3.0.0",
"@types/n3": "^1.4.4",
"@types/rdf-js": "*",
"@types/sax": "^1.0.1",
"@rdfjs/data-model": "^1.1.2",
"arrayify-stream": "^1.0.0",
"isomorphic-fetch": "^2.2.1",
"cross-fetch": "^3.0.6",
"json-stable-stringify": "^1.0.1",
"jsonld-streaming-parser": "^2.0.0",
"jsonld-streaming-parser": "^2.1.0",
"log-symbols": "^4.0.0",
"minimist": "^1.2.0",
"n3": "^1.1.1",
"rdf-isomorphic": "^1.1.0",
"rdf-literal": "^1.0.0",
"rdf-object": "^1.1.0",
"rdf-quad": "^1.3.0",
"rdf-string": "^1.3.1",
"rdf-terms": "^1.4.0",
"rdfxml-streaming-parser": "^1.3.4",
"relative-to-absolute-iri": "^1.0.5",
"sparqljson-parse": "^1.5.0",
"sparqlxml-parse": "^1.2.1",
"rdf-data-factory": "^1.0.3",
"rdf-isomorphic": "^1.2.0",
"rdf-literal": "^1.2.0",
"rdf-object": "^1.3.0",
"rdf-quad": "^1.5.0",
"rdf-string": "^1.5.0",
"rdf-terms": "^1.6.2",
"rdfxml-streaming-parser": "^1.4.0",
"relative-to-absolute-iri": "^1.0.6",
"sparqljson-parse": "^1.6.0",
"sparqlxml-parse": "^1.4.0",
"stream-to-string": "^1.1.0",
"streamify-string": "^1.0.1"
}
Expand Down
Loading

0 comments on commit 2acc5d2

Please sign in to comment.