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

@globalfishingwatch/dataviews-client

Package Overview
Dependencies
Maintainers
2
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@globalfishingwatch/dataviews-client - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/dataviews-client.d.ts

220

dist/dataviews-client.js

@@ -1,204 +0,16 @@

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var uniq_1 = require("lodash/uniq");
var template_1 = require("lodash/template");
var DOWNLOADABLE_ENDPOINTS_TYPES = ['track', 'info', 'events'];
var DataviewsClient = /** @class */ (function () {
function DataviewsClient(_fetch, library) {
this._dataviews = new Map();
this._library = new Map();
this._endpointsLoaded = new Map();
this._fetch = _fetch;
// if dataview library is provided, convert it to a Map
if (library) {
this._library = new Map(library.map(function (dataview) { return [dataview.id, dataview]; }));
}
}
// Loads data for all current and visible dataviews
// Returns an array of promises, depending on
// - dv loading status (cant load data on a unresolved dv)
// - dv visibility
// - dv endpoints vs a whitelist of downloadable endpoints (ie tracks, info, but not tiles)
DataviewsClient.prototype.loadData = function () {
var _this = this;
// for each existing dataview
var promises = [];
this._dataviews.forEach(function (dataviewWorkspace) {
var _a;
var dataview = dataviewWorkspace.dataview;
// skip dataview if override sets it to false
if (dataviewWorkspace.overrides.visible === false) {
return;
}
(_a = dataview.datasets) === null || _a === void 0 ? void 0 : _a.forEach(function (dataset) {
var _a;
(_a = dataset.endpoints) === null || _a === void 0 ? void 0 : _a.filter(function (endpoint) { return DOWNLOADABLE_ENDPOINTS_TYPES.includes(endpoint.type); }).forEach(function (endpoint) {
var urlTemplateCompiled = template_1.default(endpoint.urlTemplate, {
interpolate: /{{([\s\S]+?)}}/g,
});
var resolvedUrl;
// template compilation will fail if template needs an override an and override has not been defined
try {
resolvedUrl = urlTemplateCompiled(dataviewWorkspace.datasetParams);
// skip loading endpoint if it has been previously done
if (_this._endpointsLoaded.get(resolvedUrl) === true)
return;
var promise = _this._fetch(resolvedUrl).then(function (response) {
_this._endpointsLoaded.set(resolvedUrl, true);
return { response: response, dataviewWorkspace: dataviewWorkspace, endpoint: endpoint, dataset: dataset };
});
promises.push(promise);
}
catch (e) {
console.error('Could not use urlTemplate, maybe a datasetParam is missing?');
console.error('dataview id:', dataviewWorkspace.id);
console.error('urlTemplate:', endpoint.urlTemplate);
console.error('overrides:', dataviewWorkspace.overrides);
}
});
});
});
return promises;
};
// Loads dataview/dataset info
// Returns null if nothing changed
// Else returns a promise that returns an array of resolved dataviews
DataviewsClient.prototype.load = function (inputDataviews_) {
var _this = this;
// transform string dvs if needed
//
// for each existing dataview
// if dataview not anymore in input dataviews
// remove from existing dataviews, mark dvs as changed
//
// for each input dataview
// if dv was already existing
// check delta with previous overrides, if delta is true:
// mark dvs as changed
// update dv overrides / aka merge dv config with overrides
// else
// if exist in defaultDataviewsLibrary, and use config
// else
// add to to-be-loaded endpoints
//
// check changed state of each DV
// if nothing has to be loaded AND nothing has changed, return null
// thunk will need to not dispatch an action
// if nothing has to be loaded, resolve promise instantly with resolved dvs
var inputDataviews = inputDataviews_;
if (!Array.isArray(inputDataviews_)) {
try {
inputDataviews = JSON.parse(inputDataviews_);
}
catch (e) {
console.error('Could not parse URL workspace');
}
}
var inputDataviewsDict = new Map(inputDataviews.map(function (inputDataview) { return [inputDataview.id, inputDataview]; }));
var hasUpdates = false;
var loadDataviewsForIds = [];
var loadDatasetsForIds = [];
this._dataviews.forEach(function (dataview, id) {
if (!inputDataviewsDict.has(id)) {
hasUpdates = true;
_this._dataviews.delete(id);
}
});
inputDataviewsDict.forEach(function (inputDataview, id) {
var _a, _b;
if (_this._dataviews.has(id)) {
// TODO update whn overrides update
// const overrides = getOverrideUpdates(this._dataviews.get(id)?.overrides, inputDataview.overrides)
// if (overrides) {
// this._dataviews.get(id)!.overrides = overrides
// hasUpdates = true
// }
}
else {
hasUpdates = true;
var libraryParams = { id: '' };
if (_this._library.has(id)) {
libraryParams = __assign({}, _this._library.get(id));
}
var ids = [id];
var datasetParamsId = (libraryParams.datasetParams || {}).id || (inputDataview.datasetParams || {}).id;
if (datasetParamsId) {
ids.push(datasetParamsId);
}
var uid = ids.join('_');
var newDataview = __assign(__assign(__assign({}, libraryParams), inputDataview), { id: uid, overrides: __assign(__assign({}, (libraryParams.overrides || {})), (inputDataview.overrides || {})), datasetParams: __assign(__assign({}, (libraryParams.datasetParams || {})), (inputDataview.datasetParams || {})) });
// no config -> load whole dataview
if (!((_a = newDataview.dataview) === null || _a === void 0 ? void 0 : _a.config)) {
loadDataviewsForIds.push(id);
// no dataset --> only load dataset
}
else if (!((_b = newDataview.dataview) === null || _b === void 0 ? void 0 : _b.datasets) && newDataview.dataview.datasetsIds) {
loadDatasetsForIds = loadDatasetsForIds.concat(newDataview.dataview.datasetsIds);
}
loadDatasetsForIds = uniq_1.default(loadDatasetsForIds);
_this._dataviews.set(id, newDataview);
}
});
if (!hasUpdates)
return null;
var promises = [];
if (loadDataviewsForIds.length) {
var dataviewsUrl = "/dataviews?ids=" + loadDataviewsForIds.join(',');
console.log(dataviewsUrl);
var fetchDataviews = this._fetch(dataviewsUrl)
.then(function (response) { return response.json(); })
.then(function (data) {
console.log('data from /dataviews');
// TODO hydrate this._dataviews + use overrides for dataviews (visual stuff)
console.log(data);
var resolvedDataviews = data;
_this._dataviews.forEach(function (dataviewWorkspace) {
var resolvedDataview = resolvedDataviews.find(function (dataview) { return dataview.id === dataviewWorkspace.id; });
dataviewWorkspace.dataview = __assign(__assign({}, dataviewWorkspace.dataview), resolvedDataview);
});
});
promises.push(fetchDataviews);
}
if (loadDatasetsForIds.length) {
var datasetsUrl = "/datasets?ids=" + loadDatasetsForIds.join(',');
var fetchdatasets = this._fetch(datasetsUrl)
.then(function (response) { return response.json(); })
.then(function (data) {
var datasets = data;
// populate each dataview with matching datasets
_this._dataviews.forEach(function (dataviewWorkspace) {
var dataview = dataviewWorkspace.dataview;
dataview.datasets = [];
datasets.forEach(function (dataset) {
var _a, _b;
if ((_a = dataview.datasetsIds) === null || _a === void 0 ? void 0 : _a.includes(dataset.id)) {
(_b = dataview.datasets) === null || _b === void 0 ? void 0 : _b.push(__assign({}, dataset));
}
});
});
});
promises.push(fetchdatasets);
}
return Promise.all(promises).then(function () {
var resolvedDataviews = Array.from(_this._dataviews).map(function (item) {
var dataviewWorkspace = item[1];
return dataviewWorkspace;
});
return resolvedDataviews;
});
};
return DataviewsClient;
}());
exports.default = DataviewsClient;
//# sourceMappingURL=dataviews-client.js.map
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var t=function(){return(t=Object.assign||function(t){for(var r,n=1,e=arguments.length;n<e;n++)for(var o in r=arguments[n])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(t,r){return t(r={exports:{}},r.exports),r.exports}var e="object"==typeof r&&r&&r.Object===Object&&r,o="object"==typeof self&&self&&self.Object===Object&&self,a=e||o||Function("return this")(),i=a.Symbol,u=Object.prototype,c=u.hasOwnProperty,s=u.toString,f=i?i.toStringTag:void 0;var l=function(t){var r=c.call(t,f),n=t[f];try{t[f]=void 0;var e=!0}catch(t){}var o=s.call(t);return e&&(r?t[f]=n:delete t[f]),o},v=Object.prototype.toString;var p=function(t){return v.call(t)},d=i?i.toStringTag:void 0;var h=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":d&&d in Object(t)?l(t):p(t)};var _=function(t){var r=typeof t;return null!=t&&("object"==r||"function"==r)};var y,b=function(t){if(!_(t))return!1;var r=h(t);return"[object Function]"==r||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r},g=a["__core-js_shared__"],j=(y=/[^.]+$/.exec(g&&g.keys&&g.keys.IE_PROTO||""))?"Symbol(src)_1."+y:"";var w=function(t){return!!j&&j in t},O=Function.prototype.toString;var m=function(t){if(null!=t){try{return O.call(t)}catch(t){}try{return t+""}catch(t){}}return""},A=/^\[object .+?Constructor\]$/,P=Function.prototype,S=Object.prototype,E=P.toString,x=S.hasOwnProperty,T=RegExp("^"+E.call(x).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var z=function(t){return!(!_(t)||w(t))&&(b(t)?T:A).test(m(t))};var $=function(t,r){return null==t?void 0:t[r]};var F=function(t,r){var n=$(t,r);return z(n)?n:void 0},M=F(Object,"create");var R=function(){this.__data__=M?M(null):{},this.size=0};var U=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r},I=Object.prototype.hasOwnProperty;var L=function(t){var r=this.__data__;if(M){var n=r[t];return"__lodash_hash_undefined__"===n?void 0:n}return I.call(r,t)?r[t]:void 0},k=Object.prototype.hasOwnProperty;var D=function(t){var r=this.__data__;return M?void 0!==r[t]:k.call(r,t)};var B=function(t,r){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=M&&void 0===r?"__lodash_hash_undefined__":r,this};function C(t){var r=-1,n=null==t?0:t.length;for(this.clear();++r<n;){var e=t[r];this.set(e[0],e[1])}}C.prototype.clear=R,C.prototype.delete=U,C.prototype.get=L,C.prototype.has=D,C.prototype.set=B;var q=C;var N=function(){this.__data__=[],this.size=0};var W=function(t,r){return t===r||t!=t&&r!=r};var G=function(t,r){for(var n=t.length;n--;)if(W(t[n][0],r))return n;return-1},J=Array.prototype.splice;var V=function(t){var r=this.__data__,n=G(r,t);return!(n<0)&&(n==r.length-1?r.pop():J.call(r,n,1),--this.size,!0)};var H=function(t){var r=this.__data__,n=G(r,t);return n<0?void 0:r[n][1]};var K=function(t){return G(this.__data__,t)>-1};var Q=function(t,r){var n=this.__data__,e=G(n,t);return e<0?(++this.size,n.push([t,r])):n[e][1]=r,this};function X(t){var r=-1,n=null==t?0:t.length;for(this.clear();++r<n;){var e=t[r];this.set(e[0],e[1])}}X.prototype.clear=N,X.prototype.delete=V,X.prototype.get=H,X.prototype.has=K,X.prototype.set=Q;var Y=X,Z=F(a,"Map");var tt=function(){this.size=0,this.__data__={hash:new q,map:new(Z||Y),string:new q}};var rt=function(t){var r=typeof t;return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t};var nt=function(t,r){var n=t.__data__;return rt(r)?n["string"==typeof r?"string":"hash"]:n.map};var et=function(t){var r=nt(this,t).delete(t);return this.size-=r?1:0,r};var ot=function(t){return nt(this,t).get(t)};var at=function(t){return nt(this,t).has(t)};var it=function(t,r){var n=nt(this,t),e=n.size;return n.set(t,r),this.size+=n.size==e?0:1,this};function ut(t){var r=-1,n=null==t?0:t.length;for(this.clear();++r<n;){var e=t[r];this.set(e[0],e[1])}}ut.prototype.clear=tt,ut.prototype.delete=et,ut.prototype.get=ot,ut.prototype.has=at,ut.prototype.set=it;var ct=ut;var st=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this};var ft=function(t){return this.__data__.has(t)};function lt(t){var r=-1,n=null==t?0:t.length;for(this.__data__=new ct;++r<n;)this.add(t[r])}lt.prototype.add=lt.prototype.push=st,lt.prototype.has=ft;var vt=lt;var pt=function(t,r,n,e){for(var o=t.length,a=n+(e?1:-1);e?a--:++a<o;)if(r(t[a],a,t))return a;return-1};var dt=function(t){return t!=t};var ht=function(t,r,n){for(var e=n-1,o=t.length;++e<o;)if(t[e]===r)return e;return-1};var _t=function(t,r,n){return r==r?ht(t,r,n):pt(t,dt,n)};var yt=function(t,r){return!!(null==t?0:t.length)&&_t(t,r,0)>-1};var bt=function(t,r,n){for(var e=-1,o=null==t?0:t.length;++e<o;)if(n(r,t[e]))return!0;return!1};var gt=function(t,r){return t.has(r)},jt=F(a,"Set");var wt=function(){};var Ot=function(t){var r=-1,n=Array(t.size);return t.forEach((function(t){n[++r]=t})),n},mt=jt&&1/Ot(new jt([,-0]))[1]==1/0?function(t){return new jt(t)}:wt;var At=function(t,r,n){var e=-1,o=yt,a=t.length,i=!0,u=[],c=u;if(n)i=!1,o=bt;else if(a>=200){var s=r?null:mt(t);if(s)return Ot(s);i=!1,o=gt,c=new vt}else c=r?[]:u;t:for(;++e<a;){var f=t[e],l=r?r(f):f;if(f=n||0!==f?f:0,i&&l==l){for(var v=c.length;v--;)if(c[v]===l)continue t;r&&c.push(l),u.push(f)}else o(c,l,n)||(c!==u&&c.push(l),u.push(f))}return u};var Pt=function(t){return t&&t.length?At(t):[]},St=function(){try{var t=F(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var Et=function(t,r,n){"__proto__"==r&&St?St(t,r,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[r]=n},xt=Object.prototype.hasOwnProperty;var Tt=function(t,r,n){var e=t[r];xt.call(t,r)&&W(e,n)&&(void 0!==n||r in t)||Et(t,r,n)};var zt=function(t,r,n,e){var o=!n;n||(n={});for(var a=-1,i=r.length;++a<i;){var u=r[a],c=e?e(n[u],t[u],u,n,t):void 0;void 0===c&&(c=t[u]),o?Et(n,u,c):Tt(n,u,c)}return n};var $t=function(t){return t};var Ft=function(t,r,n){switch(n.length){case 0:return t.call(r);case 1:return t.call(r,n[0]);case 2:return t.call(r,n[0],n[1]);case 3:return t.call(r,n[0],n[1],n[2])}return t.apply(r,n)},Mt=Math.max;var Rt=function(t,r,n){return r=Mt(void 0===r?t.length-1:r,0),function(){for(var e=arguments,o=-1,a=Mt(e.length-r,0),i=Array(a);++o<a;)i[o]=e[r+o];o=-1;for(var u=Array(r+1);++o<r;)u[o]=e[o];return u[r]=n(i),Ft(t,this,u)}};var Ut=function(t){return function(){return t}},It=St?function(t,r){return St(t,"toString",{configurable:!0,enumerable:!1,value:Ut(r),writable:!0})}:$t,Lt=Date.now;var kt=function(t){var r=0,n=0;return function(){var e=Lt(),o=16-(e-n);if(n=e,o>0){if(++r>=800)return arguments[0]}else r=0;return t.apply(void 0,arguments)}}(It);var Dt=function(t,r){return kt(Rt(t,r,$t),t+"")};var Bt=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991};var Ct=function(t){return null!=t&&Bt(t.length)&&!b(t)},qt=/^(?:0|[1-9]\d*)$/;var Nt=function(t,r){var n=typeof t;return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&qt.test(t))&&t>-1&&t%1==0&&t<r};var Wt=function(t,r,n){if(!_(n))return!1;var e=typeof r;return!!("number"==e?Ct(n)&&Nt(r,n.length):"string"==e&&r in n)&&W(n[r],t)};var Gt=function(t){return Dt((function(r,n){var e=-1,o=n.length,a=o>1?n[o-1]:void 0,i=o>2?n[2]:void 0;for(a=t.length>3&&"function"==typeof a?(o--,a):void 0,i&&Wt(n[0],n[1],i)&&(a=o<3?void 0:a,o=1),r=Object(r);++e<o;){var u=n[e];u&&t(r,u,e,a)}return r}))};var Jt=function(t,r){for(var n=-1,e=Array(t);++n<t;)e[n]=r(n);return e};var Vt=function(t){return null!=t&&"object"==typeof t};var Ht=function(t){return Vt(t)&&"[object Arguments]"==h(t)},Kt=Object.prototype,Qt=Kt.hasOwnProperty,Xt=Kt.propertyIsEnumerable,Yt=Ht(function(){return arguments}())?Ht:function(t){return Vt(t)&&Qt.call(t,"callee")&&!Xt.call(t,"callee")},Zt=Array.isArray;var tr=function(){return!1},rr=n((function(t,r){var n=r&&!r.nodeType&&r,e=n&&t&&!t.nodeType&&t,o=e&&e.exports===n?a.Buffer:void 0,i=(o?o.isBuffer:void 0)||tr;t.exports=i})),nr={};nr["[object Float32Array]"]=nr["[object Float64Array]"]=nr["[object Int8Array]"]=nr["[object Int16Array]"]=nr["[object Int32Array]"]=nr["[object Uint8Array]"]=nr["[object Uint8ClampedArray]"]=nr["[object Uint16Array]"]=nr["[object Uint32Array]"]=!0,nr["[object Arguments]"]=nr["[object Array]"]=nr["[object ArrayBuffer]"]=nr["[object Boolean]"]=nr["[object DataView]"]=nr["[object Date]"]=nr["[object Error]"]=nr["[object Function]"]=nr["[object Map]"]=nr["[object Number]"]=nr["[object Object]"]=nr["[object RegExp]"]=nr["[object Set]"]=nr["[object String]"]=nr["[object WeakMap]"]=!1;var er=function(t){return Vt(t)&&Bt(t.length)&&!!nr[h(t)]};var or=function(t){return function(r){return t(r)}},ar=n((function(t,r){var n=r&&!r.nodeType&&r,o=n&&t&&!t.nodeType&&t,a=o&&o.exports===n&&e.process,i=function(){try{var t=o&&o.require&&o.require("util").types;return t||a&&a.binding&&a.binding("util")}catch(t){}}();t.exports=i})),ir=ar&&ar.isTypedArray,ur=ir?or(ir):er,cr=Object.prototype.hasOwnProperty;var sr=function(t,r){var n=Zt(t),e=!n&&Yt(t),o=!n&&!e&&rr(t),a=!n&&!e&&!o&&ur(t),i=n||e||o||a,u=i?Jt(t.length,String):[],c=u.length;for(var s in t)!r&&!cr.call(t,s)||i&&("length"==s||o&&("offset"==s||"parent"==s)||a&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||Nt(s,c))||u.push(s);return u},fr=Object.prototype;var lr=function(t){var r=t&&t.constructor;return t===("function"==typeof r&&r.prototype||fr)};var vr=function(t){var r=[];if(null!=t)for(var n in Object(t))r.push(n);return r},pr=Object.prototype.hasOwnProperty;var dr=function(t){if(!_(t))return vr(t);var r=lr(t),n=[];for(var e in t)("constructor"!=e||!r&&pr.call(t,e))&&n.push(e);return n};var hr=function(t){return Ct(t)?sr(t,!0):dr(t)},_r=Gt((function(t,r,n,e){zt(r,hr(r),t,e)}));var yr=function(t,r){return function(n){return t(r(n))}},br=yr(Object.getPrototypeOf,Object),gr=Function.prototype,jr=Object.prototype,wr=gr.toString,Or=jr.hasOwnProperty,mr=wr.call(Object);var Ar=function(t){if(!Vt(t)||"[object Object]"!=h(t))return!1;var r=br(t);if(null===r)return!0;var n=Or.call(r,"constructor")&&r.constructor;return"function"==typeof n&&n instanceof n&&wr.call(n)==mr};var Pr=function(t){if(!Vt(t))return!1;var r=h(t);return"[object Error]"==r||"[object DOMException]"==r||"string"==typeof t.message&&"string"==typeof t.name&&!Ar(t)},Sr=Dt((function(t,r){try{return Ft(t,void 0,r)}catch(t){return Pr(t)?t:new Error(t)}}));var Er=function(t,r){for(var n=-1,e=null==t?0:t.length,o=Array(e);++n<e;)o[n]=r(t[n],n,t);return o};var xr=function(t,r){return Er(r,(function(r){return t[r]}))},Tr=Object.prototype,zr=Tr.hasOwnProperty;var $r=function(t,r,n,e){return void 0===t||W(t,Tr[n])&&!zr.call(e,n)?r:t},Fr={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"};var Mr=function(t){return"\\"+Fr[t]},Rr=yr(Object.keys,Object),Ur=Object.prototype.hasOwnProperty;var Ir=function(t){if(!lr(t))return Rr(t);var r=[];for(var n in Object(t))Ur.call(t,n)&&"constructor"!=n&&r.push(n);return r};var Lr=function(t){return Ct(t)?sr(t):Ir(t)},kr=/<%=([\s\S]+?)%>/g;var Dr=function(t){return function(r){return null==t?void 0:t[r]}}({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});var Br=function(t){return"symbol"==typeof t||Vt(t)&&"[object Symbol]"==h(t)},Cr=i?i.prototype:void 0,qr=Cr?Cr.toString:void 0;var Nr=function t(r){if("string"==typeof r)return r;if(Zt(r))return Er(r,t)+"";if(Br(r))return qr?qr.call(r):"";var n=r+"";return"0"==n&&1/r==-1/0?"-0":n};var Wr=function(t){return null==t?"":Nr(t)},Gr=/[&<>"']/g,Jr=RegExp(Gr.source);var Vr={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:kr,variable:"",imports:{_:{escape:function(t){return(t=Wr(t))&&Jr.test(t)?t.replace(Gr,Dr):t}}}},Hr=/\b__p \+= '';/g,Kr=/\b(__p \+=) '' \+/g,Qr=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Xr=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Yr=/($^)/,Zr=/['\n\r\u2028\u2029\\]/g,tn=Object.prototype.hasOwnProperty;var rn=function(t,r,n){var e=Vr.imports._.templateSettings||Vr;n&&Wt(t,r,n)&&(r=void 0),t=Wr(t),r=_r({},r,e,$r);var o,a,i=_r({},r.imports,e.imports,$r),u=Lr(i),c=xr(i,u),s=0,f=r.interpolate||Yr,l="__p += '",v=RegExp((r.escape||Yr).source+"|"+f.source+"|"+(f===kr?Xr:Yr).source+"|"+(r.evaluate||Yr).source+"|$","g"),p=tn.call(r,"sourceURL")?"//# sourceURL="+(r.sourceURL+"").replace(/[\r\n]/g," ")+"\n":"";t.replace(v,(function(r,n,e,i,u,c){return e||(e=i),l+=t.slice(s,c).replace(Zr,Mr),n&&(o=!0,l+="' +\n__e("+n+") +\n'"),u&&(a=!0,l+="';\n"+u+";\n__p += '"),e&&(l+="' +\n((__t = ("+e+")) == null ? '' : __t) +\n'"),s=c+r.length,r})),l+="';\n";var d=tn.call(r,"variable")&&r.variable;d||(l="with (obj) {\n"+l+"\n}\n"),l=(a?l.replace(Hr,""):l).replace(Kr,"$1").replace(Qr,"$1;"),l="function("+(d||"obj")+") {\n"+(d?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(o?", __e = _.escape":"")+(a?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+l+"return __p\n}";var h=Sr((function(){return Function(u,p+"return "+l).apply(void 0,c)}));if(h.source=l,Pr(h))throw h;return h},nn=["track","info","events"],en=function(){function r(t,r){this._dataviews=new Map,this._library=new Map,this._endpointsLoaded=new Map,this._fetch=t,r&&(this._library=new Map(r.map((function(t){return[t.id,t]}))))}return r.prototype.loadData=function(){var t=this,r=[];return this._dataviews.forEach((function(n){var e,o=n.dataview;!1!==n.overrides.visible&&(null===(e=o.datasets)||void 0===e||e.forEach((function(e){var o;null===(o=e.endpoints)||void 0===o||o.filter((function(t){return nn.includes(t.type)})).forEach((function(o){var a,i=rn(o.urlTemplate,{interpolate:/{{([\s\S]+?)}}/g});try{if(a=i(n.datasetParams),!0===t._endpointsLoaded.get(a))return;var u=t._fetch(a).then((function(r){return t._endpointsLoaded.set(a,!0),{response:r,dataviewWorkspace:n,endpoint:o,dataset:e}}));r.push(u)}catch(t){console.error("Could not use urlTemplate, maybe a datasetParam is missing?"),console.error("dataview id:",n.id),console.error("urlTemplate:",o.urlTemplate),console.error("overrides:",n.overrides)}}))})))})),r},r.prototype.load=function(r){var n=this,e=r;if(!Array.isArray(r))try{e=JSON.parse(r)}catch(t){console.error("Could not parse URL workspace")}var o=new Map(e.map((function(t){return[t.id,t]}))),a=!1,i=[],u=[];if(this._dataviews.forEach((function(t,r){o.has(r)||(a=!0,n._dataviews.delete(r))})),o.forEach((function(r,e){var o,c;if(n._dataviews.has(e));else{a=!0;var s={id:""};n._library.has(e)&&(s=t({},n._library.get(e)));var f=[e],l=(s.datasetParams||{}).id||(r.datasetParams||{}).id;l&&f.push(l);var v=f.join("_"),p=t(t(t({},s),r),{id:v,overrides:t(t({},s.overrides||{}),r.overrides||{}),datasetParams:t(t({},s.datasetParams||{}),r.datasetParams||{})});(null===(o=p.dataview)||void 0===o?void 0:o.config)?!(null===(c=p.dataview)||void 0===c?void 0:c.datasets)&&p.dataview.datasetsIds&&(u=u.concat(p.dataview.datasetsIds)):i.push(e),u=Pt(u),n._dataviews.set(e,p)}})),!a)return null;var c=[];if(i.length){var s="/dataviews?ids="+i.join(",");console.log(s);var f=this._fetch(s).then((function(t){return t.json()})).then((function(r){console.log("data from /dataviews"),console.log(r);var e=r;n._dataviews.forEach((function(r){var n=e.find((function(t){return t.id===r.id}));r.dataview=t(t({},r.dataview),n)}))}));c.push(f)}if(u.length){var l="/datasets?ids="+u.join(","),v=this._fetch(l).then((function(t){return t.json()})).then((function(r){var e=r;n._dataviews.forEach((function(r){var n=r.dataview;n.datasets=[],e.forEach((function(r){var e,o;(null===(e=n.datasetsIds)||void 0===e?void 0:e.includes(r.id))&&(null===(o=n.datasets)||void 0===o||o.push(t({},r)))}))}))}));c.push(v)}return Promise.all(c).then((function(){return Array.from(n._dataviews).map((function(t){return t[1]}))}))},r}();export default en;
//# sourceMappingURL=dataviews-client.js.map
{
"name": "@globalfishingwatch/dataviews-client",
"version": "1.0.0",
"version": "1.1.0",
"description": "",

@@ -9,3 +9,3 @@ "author": "satellitestudio <contact@satellitestud.io>",

"main": "dist/index.js",
"typings": "dist/types/index.d.ts",
"typings": "dist/index.d.ts",
"directories": {

@@ -24,4 +24,5 @@ "src": "src",

"start": "rollup -c ./rollup.config.js -w",
"build": "cross-env NODE_ENV=production tsc --module commonjs && rollup -c rollup.config.js",
"prepublishOnly": "yarn build",
"build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
"clean": "rimraf dist/*",
"prepublishOnly": "yarn clean && yarn build",
"test": "echo \"Error: run tests from root\" && exit 1"

@@ -32,5 +33,3 @@ },

},
"dependencies": {},
"devDependencies": {},
"gitHead": "10c3825a90f584a1c240e6f3c1a77dece200a650"
"gitHead": "ab695c0e6d464f329330520935e63d5022f93a9f"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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