From 0f4b15e1e9c670dcb98c1e7c40ba8e8b4eec696a Mon Sep 17 00:00:00 2001 From: jeff-zucker Date: Wed, 11 Nov 2020 15:25:58 -0800 Subject: [PATCH] fix conditional patch --- package.json | 2 +- src/rest-patch.js | 6 +++++- src/rest.js | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d0f47c8..0e60b2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solid-rest", - "version": "1.2.5", + "version": "1.2.6", "author": "Jeff Zucker", "license": "MIT", "description": "treat any storage as a mini Solid server", diff --git a/src/rest-patch.js b/src/rest-patch.js index 16252c0..ead210e 100644 --- a/src/rest-patch.js +++ b/src/rest-patch.js @@ -1,4 +1,4 @@ -const $rdf = global.$rdf; +let $rdf; //const crypto = require('crypto') TODO may be const PATCH_NS = 'http://www.w3.org/ns/solid/terms#' @@ -12,6 +12,10 @@ const PATCH_PARSERS = { class RestPatch { + constructor(passedRDF){ + $rdf = passedRDF; + } + async patchContent (content, contentType, options) { const url = options.url const resource = { diff --git a/src/rest.js b/src/rest.js index 45b9320..7dbba8a 100644 --- a/src/rest.js +++ b/src/rest.js @@ -17,8 +17,7 @@ constructor( handlers,auth,sessionId ) { const Global = (typeof window !="undefined") ? window : (typeof global !="undefined") ? global : {}; - const $rdf = Global.$rdf - patch = Global.$rdf ? new RestPatch() : null; + patch = Global.$rdf ? new RestPatch(Global.$rdf) : null; this.storageHandlers = {} if( typeof handlers ==="undefined" || handlers.length===0) { if( typeof window ==="undefined") { @@ -280,7 +279,7 @@ async fetch(uri, options = {}) { */ function _response(body, options, status = options.status) { options.status = status - if (body) options.statusText = body + // if (body) options.statusText = body options.headers = Object.assign(_getHeaders(pathname, options), options.headers) return new Response(body, options) } @@ -365,8 +364,9 @@ async fetch(uri, options = {}) { headers.location = headers.url = headers.location || options.url headers.date = headers.date || new Date(Date.now()).toISOString() - headers.allow = headers.allow || - [ 'OPTIONS','HEAD,GET,PATCH,POST,PUT,DELETE' ] + headers.allow = headers.allow || (typeof patch !="undefined") + ? 'OPTIONS,HEAD,GET,POST,PUT,PATCH,DELETE' + : 'OPTIONS,HEAD,GET,POST,PUT,DELETE' headers['wac-allow'] = headers['wac-allow'] || `user="read write append control",public="read"` headers['x-powered-by'] = headers['x-powered-by'] ||