Skip to content

Commit

Permalink
fix conditional patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-zucker committed Nov 11, 2020
1 parent 4830fba commit 0f4b15e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/rest-patch.js
Original file line number Diff line number Diff line change
@@ -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#'
Expand All @@ -12,6 +12,10 @@ const PATCH_PARSERS = {

class RestPatch {

constructor(passedRDF){
$rdf = passedRDF;
}

async patchContent (content, contentType, options) {
const url = options.url
const resource = {
Expand Down
10 changes: 5 additions & 5 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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'] ||
Expand Down

0 comments on commit 0f4b15e

Please sign in to comment.