@flumens/models 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=r(require("axios"));exports.fetchElasticOccurrences=function(r){return e.__awaiter(this,arguments,void 0,(function(r){var n,i,s,o,a,u,c,d,l,v,p=r.parentId,_=r.url,f=r.accessToken;return e.__generator(this,(function(r){switch(r.label){case 0:return n={terms:{"event.parent_event_id":Array.isArray(p)?p:[p]}},i={terms:{"event.event_id":Array.isArray(p)?p:[p]}},s=JSON.stringify({size:1e3,query:{bool:{must:[{bool:{should:[n,i]}}]}}}),o={Authorization:"Bearer ".concat(f)},a={method:"post",url:"".concat(_,"/index.php/services/rest/es-occurrences/_search"),headers:e.__assign({"Content-Type":"application/json"},o),data:s},[4,t.default.request(a)];case 1:return u=r.sent(),c=function(e){return e._source},[2,(null===(v=null===(l=null===(d=u.data)||void 0===d?void 0:d.hits)||void 0===l?void 0:l.hits)||void 0===v?void 0:v.map(c))||[]]}}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(require("axios"));exports.fetchElasticOccurrences=function(t){return e.__awaiter(this,arguments,void 0,(function(t){var n,a,i,o,s,c,u,d,_,l,v=t.parentId,p=t.url,f=t.accessToken;return e.__generator(this,(function(t){switch(t.label){case 0:return n={terms:{"event.parent_event_id":Array.isArray(v)?v:[v]}},a={terms:{"event.event_id":Array.isArray(v)?v:[v]}},i=JSON.stringify({size:5e3,query:{bool:{must:[{bool:{should:[n,a]}}]}},_source:["id","event.event_id","event.parent_event_id","metadata.created_on","metadata.updated_on","identification","occurrence.occurrence_remarks","occurrence.attributes","occurrence.media","taxon.species","taxon.taxon_name","taxon.taxa_taxon_list_id"]}),o={Authorization:"Bearer ".concat(f)},s={method:"post",url:"".concat(p,"/index.php/services/rest/es-occurrences/_search"),headers:e.__assign({"Content-Type":"application/json"},o),data:i},[4,r.default.request(s)];case 1:return c=t.sent(),u=function(e){return e._source},[2,(null===(l=null===(_=null===(d=c.data)||void 0===d?void 0:d.hits)||void 0===_?void 0:_.hits)||void 0===l?void 0:l.map(u))||[]]}}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(require("axios"));exports.fetchElasticSample=function(t){return e.__awaiter(this,arguments,void 0,(function(t){var i,s,n,o,a,u,c,l,d,h,p=t.id,v=t.cid,f=t.url,_=t.accessToken;return e.__generator(this,(function(t){switch(t.label){case 0:return i=JSON.stringify({size:1e3,query:{bool:{must:[{match:{id:p}}]}}}),p||(i=JSON.stringify({size:1e3,query:{bool:{must:[{match:{"event.source_system_key":v}}]}}})),s={Authorization:"Bearer ".concat(_)},n={method:"post",url:"".concat(f,"/index.php/services/rest/es-samples/_search"),headers:e.__assign({"Content-Type":"application/json"},s),data:i},[4,r.default.request(n)];case 1:if(o=t.sent(),a=function(e){return e._source},u=(null===(h=null===(d=null===(l=o.data)||void 0===l?void 0:l.hits)||void 0===d?void 0:d.hits)||void 0===h?void 0:h.map(a))||[],!(c=u[0]))throw new Error("Remote sample with id ".concat(p||v," was not found"));return[2,c]}}))}))},exports.fetchElasticSubSamples=function(t){return e.__awaiter(this,arguments,void 0,(function(t){var i,s,n,o,a,u,c,l,d=t.parentId,h=t.url,p=t.accessToken;return e.__generator(this,(function(t){switch(t.label){case 0:return i=JSON.stringify({size:1e3,query:{bool:{must:[{terms:{"event.parent_event_id":Array.isArray(d)?d:[d]}}]}}}),s={Authorization:"Bearer ".concat(p)},n={method:"post",url:"".concat(h,"/index.php/services/rest/es-samples/_search"),headers:e.__assign({"Content-Type":"application/json"},s),data:i},[4,r.default.request(n)];case 1:return o=t.sent(),a=function(e){return e._source},[2,(null===(l=null===(c=null===(u=o.data)||void 0===u?void 0:u.hits)||void 0===c?void 0:c.hits)||void 0===l?void 0:l.map(a))||[]]}}))}))};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=t(require("axios"));exports.fetchElasticSample=function(t){return e.__awaiter(this,arguments,void 0,(function(t){var r,n,i,o,s,u,c,d,l,v,_=t.id,p=t.cid,m=t.url,h=t.accessToken;return e.__generator(this,(function(t){switch(t.label){case 0:return r=JSON.stringify({size:1e3,query:{bool:{must:[{match:{id:_}}]}}}),_||(r=JSON.stringify({size:1e3,query:{bool:{must:[{match:{"event.source_system_key":p}}]}}})),n={Authorization:"Bearer ".concat(h)},i={method:"post",url:"".concat(m,"/index.php/services/rest/es-samples/_search"),headers:e.__assign({"Content-Type":"application/json"},n),data:r},[4,a.default.request(i)];case 1:if(o=t.sent(),s=function(e){return e._source},u=(null===(v=null===(l=null===(d=o.data)||void 0===d?void 0:d.hits)||void 0===l?void 0:l.hits)||void 0===v?void 0:v.map(s))||[],!(c=u[0]))throw new Error("Remote sample with id ".concat(_||p," was not found"));return[2,c]}}))}))},exports.fetchElasticSubSamples=function(t){return e.__awaiter(this,arguments,void 0,(function(t){var r,n,i,o,s,u,c,d,l=t.parentId,v=t.url,_=t.accessToken;return e.__generator(this,(function(t){switch(t.label){case 0:return r=JSON.stringify({size:2e3,query:{bool:{must:[{terms:{"event.parent_event_id":Array.isArray(l)?l:[l]}}]}},_source:["id","event.event_id","event.parent_event_id","event.source_system_key","event.attributes","event.media","event.event_remarks","event.date_start","metadata.created_on","metadata.updated_on","metadata.survey.id","metadata.group.id","metadata.trial","location.geom","location.output_sref_system","location.output_sref","location.point","location.code","location.name","location.verbatim_locality"]}),n={Authorization:"Bearer ".concat(_)},i={method:"post",url:"".concat(v,"/index.php/services/rest/es-samples/_search"),headers:e.__assign({"Content-Type":"application/json"},n),data:r},[4,a.default.request(i)];case 1:return o=t.sent(),s=function(e){return e._source},[2,(null===(d=null===(c=null===(u=o.data)||void 0===u?void 0:u.hits)||void 0===c?void 0:c.hits)||void 0===d?void 0:d.map(s))||[]]}}))}))};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("localforage"),t=require("localforage-cordovasqlitedriver"),i=require("@flumens/utils"),n=require("./utils.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(r),a=o(t),u=["indexeddb","websql","localstorage"];if(i.isPlatform("hybrid")){if(!window.sqlitePlugin)throw new Error("cordova-sql-storage plugin is missing. Please install it.");u=e.__spreadArray([a.default],u,!0)}var c={driverOrder:u},d=function(){function r(t){var i=this,n=e.__assign(e.__assign({},c),t);this.debugging=n.debugging,this.localForage=null,this.ready=new Promise((function(e,t){var o=new Promise((function(e){n.driverOrder&&"object"==typeof n.driverOrder[0]?s.default.defineDriver(n.driverOrder[0]).then(e):e(void 0)}));if(!n.storeName)throw new Error("storeName prop is missing");i.storeName=n.storeName,o.then((function(){var o={name:n.name||"indicia",storeName:n.storeName};n.version&&(o.version=n.version);var a=r._getDriverOrder(n.driverOrder),u=n.LocalForage||s.default;i.localForage=u.createInstance(o),i.localForage.setDriver(a).then(e).catch(t)}))}))}return r._getDriverOrder=function(e){return e.map((function(e){switch(e){case"indexeddb":return s.default.INDEXEDDB;case"websql":return s.default.WEBSQL;case"localstorage":return s.default.LOCALSTORAGE;default:return"object"==typeof e&&e._driver?e._driver:console.error("No such db driver!")}}))},r.prototype.save=function(r){return e.__awaiter(this,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r.cid)throw new Error("Invalid key passed to store");return this.debugging?[4,this.find(r.cid)]:[3,3];case 2:t=e.sent(),n.printDiff(t,r,r.cid,this.storeName),e.label=3;case 3:return[2,this.localForage.setItem(r.cid,r)]}}))}))},r.prototype.find=function(r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r)throw new Error("Invalid key passed to store");return[2,this.localForage.getItem(r)]}}))}))},r.prototype.findAll=function(){return e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),r=[],[4,this.localForage.iterate((function(e){r.push(e)}))];case 2:return e.sent(),[2,r]}}))}))},r.prototype.delete=function(r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r)throw new Error("Invalid key passed to store");return[2,this.localForage.removeItem(r)]}}))}))},r.prototype.deleteAll=function(){return e.__awaiter(this,void 0,void 0,(function(){var r,t=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.findAll()];case 2:return r=e.sent(),[4,Promise.all(r.map((function(e){return t.delete(e)})))];case 3:return e.sent(),[2]}}))}))},r.prototype.export=function(){return e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.ready];case 1:return t.sent(),r=function(r,t){var i;return e.__assign(e.__assign({},r),((i={})[t.cid]=t,i))},[4,this.findAll()];case 2:return[2,t.sent().reduce(r,{})]}}))}))},r.prototype.import=function(r){return e.__awaiter(this,void 0,void 0,(function(){var t,i=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.deleteAll()];case 2:if(e.sent(),"object"!=typeof r)throw new Error("Invalid obj passed to store");return t=Object.entries(r).map((function(e){var r=e[1];return i.save(r)})),[4,Promise.all(t)];case 3:return e.sent(),[2]}}))}))},r}();exports.default=d;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("localforage"),t=require("localforage-cordovasqlitedriver"),i=require("@flumens/utils"),n=require("./utils.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(r),a=o(t),u=["indexeddb","websql","localstorage"];i.isPlatform("hybrid")&&(u=e.__spreadArray([a.default],u,!0));var c={driverOrder:u},d=function(){function r(t){var n=this;if(i.isPlatform("hybrid")&&!window.sqlitePlugin)throw new Error("cordova-sql-storage plugin is missing. Please install it.");var o=e.__assign(e.__assign({},c),t);this.debugging=o.debugging,this.localForage=null,this.ready=new Promise((function(e,t){var i=new Promise((function(e){o.driverOrder&&"object"==typeof o.driverOrder[0]?s.default.defineDriver(o.driverOrder[0]).then(e):e(void 0)}));if(!o.storeName)throw new Error("storeName prop is missing");n.storeName=o.storeName,i.then((function(){var i={name:o.name||"indicia",storeName:o.storeName};o.version&&(i.version=o.version);var a=r._getDriverOrder(o.driverOrder),u=o.LocalForage||s.default;n.localForage=u.createInstance(i),n.localForage.setDriver(a).then(e).catch(t)}))}))}return r._getDriverOrder=function(e){return e.map((function(e){switch(e){case"indexeddb":return s.default.INDEXEDDB;case"websql":return s.default.WEBSQL;case"localstorage":return s.default.LOCALSTORAGE;default:return"object"==typeof e&&e._driver?e._driver:console.error("No such db driver!")}}))},r.prototype.save=function(r){return e.__awaiter(this,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r.cid)throw new Error("Invalid key passed to store");return this.debugging?[4,this.find(r.cid)]:[3,3];case 2:t=e.sent(),n.printDiff(t,r,r.cid,this.storeName),e.label=3;case 3:return[2,this.localForage.setItem(r.cid,r)]}}))}))},r.prototype.find=function(r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r)throw new Error("Invalid key passed to store");return[2,this.localForage.getItem(r)]}}))}))},r.prototype.findAll=function(){return e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),r=[],[4,this.localForage.iterate((function(e){r.push(e)}))];case 2:return e.sent(),[2,r]}}))}))},r.prototype.delete=function(r){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:if(e.sent(),!r)throw new Error("Invalid key passed to store");return[2,this.localForage.removeItem(r)]}}))}))},r.prototype.deleteAll=function(){return e.__awaiter(this,void 0,void 0,(function(){var r,t=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.findAll()];case 2:return r=e.sent(),[4,Promise.all(r.map((function(e){return t.delete(e)})))];case 3:return e.sent(),[2]}}))}))},r.prototype.export=function(){return e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.ready];case 1:return t.sent(),r=function(r,t){var i;return e.__assign(e.__assign({},r),((i={})[t.cid]=t,i))},[4,this.findAll()];case 2:return[2,t.sent().reduce(r,{})]}}))}))},r.prototype.import=function(r){return e.__awaiter(this,void 0,void 0,(function(){var t,i=this;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.ready];case 1:return e.sent(),[4,this.deleteAll()];case 2:if(e.sent(),"object"!=typeof r)throw new Error("Invalid obj passed to store");return t=Object.entries(r).map((function(e){var r=e[1];return i.save(r)})),[4,Promise.all(t)];case 3:return e.sent(),[2]}}))}))},r}();exports.default=d;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flumens/models",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {