sparqljson-parse
Advanced tools
Comparing version 1.7.0 to 2.0.0
export * from "./lib/SparqlJsonParser"; | ||
export * from "./lib/SparqlJsonBindingsTransformer"; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -14,3 +18,2 @@ if (k2 === undefined) k2 = k; | ||
__exportStar(require("./lib/SparqlJsonParser"), exports); | ||
__exportStar(require("./lib/SparqlJsonBindingsTransformer"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -44,3 +44,3 @@ /// <reference types="node" /> | ||
* @param {NodeJS.ReadableStream} sparqlResponseStream A SPARQL JSON response stream. | ||
* @return {NodeJS.ReadableStream} A stream of bindings. | ||
* @return {Promise<boolean>} The response boolean. | ||
*/ | ||
@@ -47,0 +47,0 @@ parseJsonBooleanStream(sparqlResponseStream: NodeJS.ReadableStream): Promise<boolean>; |
@@ -5,3 +5,5 @@ "use strict"; | ||
const rdf_data_factory_1 = require("rdf-data-factory"); | ||
const SparqlJsonBindingsTransformer_1 = require("./SparqlJsonBindingsTransformer"); | ||
const readable_stream_1 = require("readable-stream"); | ||
// tslint:disable-next-line:no-var-requires | ||
const JsonParser = require('jsonparse'); | ||
/** | ||
@@ -37,10 +39,20 @@ * Parser for the SPARQL 1.1 Query Results JSON format. | ||
sparqlResponseStream.on('error', errorListener); | ||
const variables = []; | ||
sparqlResponseStream | ||
.pipe(require('JSONStream').parse('head.vars.*').on('error', errorListener)) | ||
.on('data', (variable) => variables.push(this.dataFactory.variable(variable))) | ||
.on('end', () => resultStream.emit('variables', variables)); | ||
const jsonParser = new JsonParser(); | ||
jsonParser.onError = errorListener; | ||
jsonParser.onValue = (value) => { | ||
if (jsonParser.key === "vars" && jsonParser.stack.length === 2 && jsonParser.stack[1].key === 'head') { | ||
resultStream.emit('variables', value.map((v) => this.dataFactory.variable(v))); | ||
} | ||
else if (typeof jsonParser.key === 'number' && jsonParser.stack.length === 3 && jsonParser.stack[1].key === 'results' && jsonParser.stack[2].key === 'bindings') { | ||
resultStream.push(this.parseJsonBindings(value)); | ||
} | ||
}; | ||
const resultStream = sparqlResponseStream | ||
.pipe(require('JSONStream').parse('results.bindings.*').on('error', errorListener)) | ||
.pipe(new SparqlJsonBindingsTransformer_1.SparqlJsonBindingsTransformer(this)); | ||
.pipe(new readable_stream_1.Transform({ | ||
objectMode: true, | ||
transform(chunk, encoding, callback) { | ||
jsonParser.write(chunk); | ||
callback(); | ||
} | ||
})); | ||
return resultStream; | ||
@@ -101,9 +113,16 @@ } | ||
* @param {NodeJS.ReadableStream} sparqlResponseStream A SPARQL JSON response stream. | ||
* @return {NodeJS.ReadableStream} A stream of bindings. | ||
* @return {Promise<boolean>} The response boolean. | ||
*/ | ||
parseJsonBooleanStream(sparqlResponseStream) { | ||
return new Promise((resolve, reject) => { | ||
sparqlResponseStream.on('error', reject); | ||
sparqlResponseStream.pipe(require('JSONStream').parse('boolean')) | ||
.on('data', resolve) | ||
const parser = new JsonParser(); | ||
parser.onError = reject; | ||
parser.onValue = (value) => { | ||
if (parser.key === "boolean" && typeof value === 'boolean' && parser.stack.length === 1) { | ||
resolve(value); | ||
} | ||
}; | ||
sparqlResponseStream | ||
.on('error', reject) | ||
.on('data', d => parser.write(d)) | ||
.on('end', () => reject(new Error('No valid ASK response was found.'))); | ||
@@ -110,0 +129,0 @@ }); |
{ | ||
"name": "sparqljson-parse", | ||
"version": "1.7.0", | ||
"version": "2.0.0", | ||
"description": "Parses SPARQL JSON query results", | ||
@@ -33,7 +33,7 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/jest": "^26.0.0", | ||
"@types/jest": "^28.0.0", | ||
"@types/minimist": "^1.2.0", | ||
"arrayify-stream": "^1.0.0", | ||
"arrayify-stream": "^2.0.0", | ||
"coveralls": "^3.0.0", | ||
"jest": "^26.0.0", | ||
"jest": "^28.0.0", | ||
"jest-rdf": "^1.7.0", | ||
@@ -43,6 +43,9 @@ "manual-git-changelog": "^1.0.0", | ||
"streamify-string": "^1.0.1", | ||
"ts-jest": "^26.0.0", | ||
"ts-jest": "^28.0.0", | ||
"ts-loader": "^9.3.1", | ||
"tslint": "^6.0.0", | ||
"tslint-eslint-rules": "^5.3.1", | ||
"typescript": "^4.3.5" | ||
"typescript": "^4.3.5", | ||
"webpack": "^5.73.0", | ||
"webpack-cli": "^4.10.0" | ||
}, | ||
@@ -52,3 +55,3 @@ "jest": { | ||
"ts-jest": { | ||
"tsConfig": "test/tsconfig.json" | ||
"tsconfig": "test/tsconfig.json" | ||
} | ||
@@ -85,6 +88,9 @@ }, | ||
"@rdfjs/types": "*", | ||
"@types/node": "^13.1.0", | ||
"JSONStream": "^1.3.3", | ||
"rdf-data-factory": "^1.1.0" | ||
} | ||
"@types/readable-stream": "^2.3.13", | ||
"buffer": "^6.0.3", | ||
"jsonparse": "^1.3.1", | ||
"rdf-data-factory": "^1.1.0", | ||
"readable-stream": "^4.0.0" | ||
}, | ||
"sideEffects": false | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21467
10
241
6
16
+ Addedbuffer@^6.0.3
+ Addedjsonparse@^1.3.1
+ Addedreadable-stream@^4.0.0
+ Added@types/node@22.10.2(transitive)
+ Added@types/readable-stream@2.3.15(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedreadable-stream@4.6.0(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedundici-types@6.20.0(transitive)
- Removed@types/node@^13.1.0
- RemovedJSONStream@^1.3.3
- Removed@types/node@13.13.52(transitive)
- RemovedJSONStream@1.3.5(transitive)
- Removedthrough@2.3.8(transitive)