Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const next = async () => {
if (done)
return { done };
done = true;
// Find the document to update
const sources = await (source ? this.toComunicaSources(source) : this._sources);
if (!sources || sources.length !== 1)
throw new Error('Can only update a single source.');
const [{ value: document }] = sources;
if (!/^https?:\/\//.test(document))
throw new Error('Can only update an HTTP(s) document.');
// Send authenticated PATCH request to the document
const { ok, status, statusText } = await auth.fetch(document, {
method: 'PATCH',
headers: {
'Content-Type': 'application/sparql-update',
},
body: sparql,
});
// Error if the server response was not ok
if (!ok)
throw new Error(`Update query failed (${status}): ${statusText}`);
// Clear stale cached versions of the document
await this.clearCache(document);
return { value: createBindings({ ok }) };
};
fetch: async function(url,request){
var res = await solid.fetch(url,request).catch(err => {
this.err = err; return false
})
if(!res.ok) {
this.err = res.status + " ("+res.statusText+")"
return false
}
var txt = await res.text().catch(err => {
this.err = err; return false
})
return({value:txt})
},
/* SESSION MANAGEMENT
function getResourceOptions (url, options = {}) {
var _fetch = Config.User.OIDC? solidAuth.fetch : fetch;
url = url || currentLocation()
options.method = 'OPTIONS'
if (!options.noCredentials) {
options.credentials = 'include'
}
return _fetch(url, options)
.then(response => {
if (!response.ok) { // not a 2xx level response
let error = new Error('Error fetching resource OPTIONS: ' +
response.status + ' ' + response.statusText)
error.status = response.status
error.response = response
fetchAndParse: async function(url,contentType){
contentType = contentType || this.guessFileType(url)
var res = await solid.fetch(url).catch(err=>{
this.err=err; console.log(err); return false;
})
if(!res.ok) {
this.err = res.status + " ("+res.statusText+")"
return false
}
if( contentType==='application/json' ){
var obj = await res.json().catch(err=>{this.err=err; return false })
return (obj)
}
var txt = await res.text().catch(err=>{this.err=err; return false })
return this.text2graph(txt,url,contentType)
},
text2graph: function(text,url,contentType){
function putResource (url, data, contentType, links, options = {}) {
var _fetch = Config.User.OIDC? solidAuth.fetch : fetch;
if (!url) {
return Promise.reject(new Error('Cannot PUT resource - missing url'))
}
options.method = 'PUT'
options.body = data
if (!options.noCredentials) {
options.credentials = 'include'
}
options.headers = options.headers || {}
options.headers['Content-Type'] = contentType || DEFAULT_CONTENT_TYPE
add: async function(parentFolder,newThing,type,content) {
var link = '; rel="type"';
var filetype;
if(type==='folder'){
var link = '; rel="type"'
filetype = "text/turtle"
}
var request = {
method : 'POST',
headers : { 'Content-Type':filetype,slug:newThing,link:link }
}
if(content) request.body=content
var response = await solid.fetch( parentFolder, request )
.catch(err=>{this.err=err;return false})
if(response.ok) return true
else {
this.err = response.status + " ("+response.statusText+")"
return false
}
},
fetch: async function(url,request){