@graffy/client
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -1,52 +0,2 @@ | ||
'use strict'; | ||
function getPath(query) { | ||
return Object.keys(query).sort().map(function (key) { | ||
return typeof query[key] === 'object' ? key + "(" + getPath(query[key]) + ")" : key; | ||
}).join(','); | ||
} | ||
function GraffyClient(baseUrl) { | ||
return function (store) { | ||
store.onGet(function (_ref) { | ||
var query = _ref.query, | ||
token = _ref.token; | ||
var url = baseUrl + "?include=" + getPath(query); | ||
if (!token) { | ||
if (!fetch) throw Error('client.fetch.unavailable'); | ||
return fetch(url).then(function (res) { | ||
return res.json(); | ||
}); | ||
} | ||
if (!EventSource) throw Error('client.sse.unavailable'); | ||
return new Promise(function (resolve, reject) { | ||
var source = new EventSource(url); | ||
var resolved = false; | ||
source.onmessage = function (_ref2) { | ||
var data = _ref2.data; | ||
data = JSON.parse(data); | ||
if (resolved) { | ||
store.pub(data); | ||
} else { | ||
resolve(data); | ||
resolved = true; | ||
} | ||
}; | ||
source.onerror = function (e) { | ||
if (!resolved) reject(e); | ||
}; | ||
token.onSignal(function () { | ||
source.close(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
module.exports = GraffyClient; | ||
'use strict';function getPath(a){return Object.keys(a).sort().map(function(b){return"object"==typeof a[b]?b+"("+getPath(a[b])+")":b}).join(",")}function GraffyClient(a){return function(b){b.onGet(function(c){var d=c.query,e=c.token,f=a+"?include="+getPath(d);if(!e){if(!fetch)throw Error("client.fetch.unavailable");return fetch(f).then(function(a){return a.json()})}if(!EventSource)throw Error("client.sse.unavailable");return new Promise(function(a,c){var d=new EventSource(f),g=!1;d.onmessage=function(c){var d=c.data;d=JSON.parse(d),g?b.pub(d):(a(d),g=!0)},d.onerror=function(a){g||c(a)},e.onSignal(function(){d.close()})})})}}module.exports=GraffyClient; | ||
//# sourceMappingURL=bundle.js.map |
{ | ||
"name": "@graffy/client", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"author": "aravind (github.com/aravindet)", | ||
@@ -5,0 +5,0 @@ "description": "HTTP client library for Graffy", |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
1853
8
5