Skip to content

Commit 4867bd6

Browse files
committed
Added more output logging
1 parent 8a4b971 commit 4867bd6

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

media/inspector.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extension.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,9 @@ import { parse } from 'yaml';
77
import axios from 'axios';
88
const jsonld = require('jsonld');
99
const ShaclValidator = require('schemarama/shaclValidator').Validator;
10-
const slugify = require('slugify');
11-
12-
import { rawListeners, report } from 'process';
13-
import { RDFArrayRemove, output } from 'rdflib/lib/utils-js';
1410
import { GraphType } from 'rdflib/lib/types';
1511
import { DefaultGraph } from 'rdflib/lib/tf-types';
16-
import { isSubject } from 'rdflib';
17-
18-
// New Oxigraph JS RDF library (built from rust)
19-
2012
import oxigraph from 'oxigraph/node.js';
21-
// const oxigraph = require('oxigraph');
2213

2314
const STRICT_NQUADS_REGEX = /(<\S+?>|_:\S+)?\s+(<\S+?>)\s+(<\S+?>|_:\S+?|(".*"(^^<.+>)?))\s+(<\S+?>|_:\S+?)\s*\.(\s*#.+)?/g;
2415

@@ -99,7 +90,7 @@ function loadRDFrdflib(data: string, rdfStore: $rdf.Store, mediaType: string) {
9990
try {
10091

10192
if (mediaType == "application/ld+json") {
102-
console.log("Converting to JSON-LD to NQuads to preserve named graphs");
93+
outputChannel.appendLine("Converting from JSON-LD to NQuads to preserve named graphs");
10394
JSONLDtoNQuads(data)
10495
.then(nquads => $rdf.parse(nquads, rdfStore, "https://example.com/test/", "application/n-quads", function () {
10596
outputChannel.appendLine("Successfully parsed: Statements in the graph: " + rdfStore.length);
@@ -155,11 +146,10 @@ function loadRDFOxigraph(data: string, rdfStore: oxigraph.Store, mediaType: stri
155146
try {
156147

157148
if (mediaType == "application/ld+json") {
158-
console.log("Converting to JSON-LD to NQuads to preserve named graphs");
149+
outputChannel.appendLine("Converting to JSON-LD to NQuads to preserve named graphs");
159150
JSONLDtoNQuads(data)
160151
.then(nquads => {
161152
rdfStore.load(nquads, mediaType, undefined, undefined);
162-
console.log(rdfStore);
163153
outputChannel.appendLine("Successfully parsed: Statements in the graph: " + rdfStore.size);
164154
resolve(rdfStore);
165155
}).catch((reason) => {
@@ -169,7 +159,6 @@ function loadRDFOxigraph(data: string, rdfStore: oxigraph.Store, mediaType: stri
169159
});
170160
} else {
171161
rdfStore.load(data, mediaType, undefined, undefined);
172-
console.log(rdfStore);
173162
outputChannel.appendLine("Successfully parsed: Statements in the graph: " + rdfStore.size);
174163
resolve(rdfStore);
175164
}
@@ -191,7 +180,7 @@ async function runQuery(query: string, documentText: string, mediaType: string):
191180
}).catch((reason) => {
192181
return [reason];
193182
}).finally(() => {
194-
console.log("Finally...");
183+
outputChannel.appendLine("Ran query");
195184
});
196185

197186
return result;
@@ -214,7 +203,7 @@ async function getView(documentText: string, mediaType: string, showTypes: boole
214203
}).catch((reason) => {
215204
result = {status: false, message: reason, mediaType: ""};
216205
}).finally(() => {
217-
console.log("Finally...");
206+
outputChannel.appendLine("D3 Graph built");
218207
});
219208
return result;
220209
}
@@ -553,7 +542,6 @@ async function getJSONwithEmbeddedContext(json_document: vscode.TextDocument) {
553542
if (context.constructor === Array) {
554543
let expandedContextArray:any[] = [];
555544
for (let c in context) {
556-
console.log(context[c]);
557545
// If the context is a string, and does not start with http, it is likely to be a file.
558546
// Let's try to load it.
559547
if (typeof context[c] == 'string' && loadLocalContexts && !context[c].toLowerCase().startsWith("http")) {
@@ -562,14 +550,13 @@ async function getJSONwithEmbeddedContext(json_document: vscode.TextDocument) {
562550
expandedContextArray.push(JSON.parse(json_context_doc.getText()));
563551
outputChannel.appendLine(`Including context from ${json_context_path}`);
564552
} else if (typeof context[c] == 'string' && prefetchRemoteContexts && context[c].toLowerCase().startsWith("http") ){
565-
console.log("Fetching context from URL " + context[c]);
553+
outputChannel.appendLine("Fetching context from URL: " + context[c]);
566554
try {
567555
const response = await axios({
568556
method: 'get',
569557
url: context[c],
570558
headers: { Accept: "application/ld+json;profile=http://www.w3.org/ns/json-ld#context"}
571559
})
572-
console.log(response);
573560

574561
if(response.headers['content-type'] != 'application/json' && response.headers['content-type'] != 'text/json' && response.headers['content-type'] != 'application/ld+json') {
575562
throw new Error("Service did not return JSON content type: " + response.headers['content-type']);
@@ -588,7 +575,6 @@ async function getJSONwithEmbeddedContext(json_document: vscode.TextDocument) {
588575
} catch (e: any){
589576
outputChannel.appendLine("Could not preload context from " + context[c]);
590577
outputChannel.appendLine(e.message);
591-
console.log(e);
592578
if (!gracefullyIgnoreFailedPrefetch) {
593579
expandedContextArray.push(context[c]);
594580
} else {
@@ -597,7 +583,7 @@ async function getJSONwithEmbeddedContext(json_document: vscode.TextDocument) {
597583

598584
}
599585
} else if (typeof context[c] == 'string' && context[c].toLowerCase().startsWith("http") ) {
600-
console.log("Adding proxy");
586+
// TODO: add ability to inject proxy URL here
601587
expandedContextArray.push(context[c]);
602588
} else {
603589
// Just passing through the value in the context array, as it may be an object or another array.
@@ -838,24 +824,22 @@ export function activate(context: vscode.ExtensionContext) {
838824
let shaclFileURIs = await vscode.window.showOpenDialog(options);
839825
if (!shaclFileURIs) {
840826
throw Error("No file selected!");
841-
}
827+
}
842828
shaclFileURI = shaclFileURIs[0];
843829
}
844830

845-
831+
outputChannel.appendLine(`Loading SHACL shapes from ${shaclFileURI}`);
846832
const shaclDocument = await vscode.workspace.openTextDocument(shaclFileURI);
847833
const result = await validate(document, shaclDocument);
848834

849-
console.log(result);
850835
// No failures? File is valid!
851836
if(result.failures.length==0) {
852-
console.log("File is valid");
853837
outputChannel.appendLine("Congratulations, your graph is valid!");
854838
return;
855839
}
856840
// If we do have failures, let's show them.
857-
console.log("File is not valid");
858-
vscode.window.showWarningMessage("Alas, your graph is not valid.");
841+
outputChannel.appendLine(`Alas, your graph does not conform to the SHACL shapes defined in ${shaclFileURI}`);
842+
vscode.window.showWarningMessage(`Alas, your graph does not conform to the SHACL shapes defined in ${shaclFileURI}`);
859843

860844
const variables = ["node", "message", "shape", "property", "severity"];
861845
const data = result.failures;
@@ -1155,22 +1139,26 @@ async function validate(document: vscode.TextDocument, shaclDocument: vscode.Tex
11551139
let store = new $rdf.Store();
11561140
let shapesStore = new $rdf.Store();
11571141

1142+
outputChannel.appendLine("Loading data into graph");
11581143
await loadRDFrdflib(doc.data, store, doc.fromMediaType);
11591144
let data = await serializeRDF(store, 'application/ld+json');
11601145

1146+
outputChannel.appendLine("Loading SHACL shape data into graph");
11611147
await loadRDFrdflib(shapes.data, shapesStore, shapes.fromMediaType);
11621148
let shapesData = await serializeRDF(shapesStore, 'text/turtle');
11631149

11641150
try {
1151+
outputChannel.appendLine("Validating data graph against shapes graph");
11651152
const validator = new ShaclValidator(shapesData, {annotations: {"node": "http://www.w3.org/ns/shacl#focusNode", "label": "http://www.w3.org/2000/01/rdf-schema#label"}});
11661153
let report = await validator.validate(data, {baseUrl: "http://example.org/test"});
1154+
outputChannel.appendLine("Validation completed");
11671155
return(report);
11681156
} catch (e:any) {
11691157
outputChannel.appendLine("SHACL Validator threw an error");
11701158
outputChannel.appendLine(e.message);
11711159
return {failures: [{message: "SHACL Validator threw an error: "+e.message, shape: "N/A", node: "N/A", severity: "error", property: "N/A"}]};
11721160
}
1173-
1161+
11741162
}
11751163

11761164

src/inspector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as d3 from "d3";
22
import { default as d3tip } from "d3-tip";
3-
import { on } from "events";
3+
// import { on } from "events";
44

55
document.addEventListener('DOMContentLoaded', function() {
66
const dataContents = window.document.getElementById('data').innerText;

0 commit comments

Comments
 (0)