Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-sparql-endpoint

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-sparql-endpoint - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

8

CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file.
<a name="v1.8.0"></a>
## [v1.8.0](https://github.com/rubensworks/fetch-sparql-endpoint.js/compare/v1.7.0...v1.8.0) - 2020-10-20
### Added
* [Add support for POSTing updates](https://github.com/rubensworks/fetch-sparql-endpoint.js/commit/bd44521158f2cdcc556697f402b62857ba94e997)
### Changed
<a name="v1.7.0"></a>

@@ -5,0 +13,0 @@ ## [v1.7.0](https://github.com/rubensworks/fetch-sparql-endpoint.js/compare/v1.6.2...v1.7.0) - 2020-09-16

18

lib/SparqlEndpointFetcher.d.ts

@@ -6,2 +6,3 @@ /// <reference types="node" />

import { SparqlXmlParser } from "sparqlxml-parse";
import { Readable } from "stream";
/**

@@ -53,4 +54,11 @@ * A SparqlEndpointFetcher can send queries to SPARQL endpoints,

*/
fetchTriples(endpoint: string, query: string): Promise<RDF.Stream>;
fetchTriples(endpoint: string, query: string): Promise<Readable & RDF.Stream>;
/**
* Send an update query to the given endpoint URL using POST.
*
* @param {string} endpoint A SPARQL endpoint URL. (without the `?query=` suffix).
* @param {string} query A SPARQL query string.
*/
fetchUpdate(endpoint: string, query: string): Promise<void>;
/**
* Send a query to the given endpoint URL and return the resulting stream.

@@ -66,2 +74,10 @@ *

fetchRawStream(endpoint: string, query: string, acceptHeader: string): Promise<[string, NodeJS.ReadableStream]>;
/**
* Helper function to generalize internal fetch calls.
*
* @param {string} url The URL to call.
* @param {RequestInit} init Options to pass along to the fetch call.
* @return {Promise<[string, NodeJS.ReadableStream]>} The content type and SPARQL endpoint response stream.
*/
private handleFetchCall;
}

@@ -68,0 +84,0 @@ export interface ISparqlEndpointFetcherArgs extends ISettings {

@@ -88,2 +88,18 @@ "use strict";

/**
* Send an update query to the given endpoint URL using POST.
*
* @param {string} endpoint A SPARQL endpoint URL. (without the `?query=` suffix).
* @param {string} query A SPARQL query string.
*/
async fetchUpdate(endpoint, query) {
const init = {
method: 'POST',
headers: {
'content-type': 'application/sparql-update',
},
body: query,
};
await this.handleFetchCall(endpoint, init);
}
/**
* Send a query to the given endpoint URL and return the resulting stream.

@@ -103,3 +119,13 @@ *

headers.append('Accept', acceptHeader);
const httpResponse = await (this.fetchCb || fetch)(url, { headers });
return this.handleFetchCall(url, { headers });
}
/**
* Helper function to generalize internal fetch calls.
*
* @param {string} url The URL to call.
* @param {RequestInit} init Options to pass along to the fetch call.
* @return {Promise<[string, NodeJS.ReadableStream]>} The content type and SPARQL endpoint response stream.
*/
async handleFetchCall(url, init) {
const httpResponse = await (this.fetchCb || fetch)(url, init);
// Wrap WhatWG readable stream into a Node.js readable stream

@@ -116,3 +142,4 @@ // If the body already is a Node.js stream (in the case of node-fetch), don't do explicit conversion.

if (!httpResponse.ok) {
throw new Error('Invalid SPARQL endpoint (' + endpoint + ') response: ' + httpResponse.statusText);
const simpleUrl = /^[^?]*/u.exec(url)[0];
throw new Error('Invalid SPARQL endpoint (' + simpleUrl + ') response: ' + httpResponse.statusText);
}

@@ -119,0 +146,0 @@ return [contentType, responseStream];

3

package.json
{
"name": "fetch-sparql-endpoint",
"version": "1.7.0",
"version": "1.8.0",
"description": "A simple, lightweight module to send queries to SPARQL endpoints and retrieve their results in a streaming fashion.",

@@ -53,2 +53,3 @@ "keywords": [

"@types/minimist": "^1.2.0",
"@types/n3": "^1.4.4",
"@types/sparqljs": "^3.0.1",

@@ -55,0 +56,0 @@ "arrayify-stream": "^1.0.0",

@@ -11,4 +11,3 @@ # Fetch SPARQL Endpoint

Currently, SPARQL queries such as `SELECT`, `ASK`, `CONSTRUCT` and `DESCRIBE` are supported.
[SPARQL UPDATE](https://www.w3.org/TR/sparql11-update/) to insert, delete and patch data is not supported yet.
All SPARQL queries are supported, such as `SELECT`, `ASK`, `CONSTRUCT` `DESCRIBE`, `INSERT`, `DELETE`, ...

@@ -106,2 +105,12 @@ Internally, this library supports SPARQL results in

### Fetch update
[SPARQL Update](https://www.w3.org/TR/sparql11-update/) queries answer with a void promise.
```js
await fetcher.fetchUpdate('https://dbpedia.org/sparql', 'INSERT DATA { <ex:s> <ex:p> <ex:o> }');
```
The `await` fill throw an error if the update has failed.
### Detect query type

@@ -108,0 +117,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc