@dcupl/bundle 2.0.0-beta.19 → 2.0.0-beta.20
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.
package/dist/dcupl.bundle.min.js
CHANGED
|
@@ -12,5 +12,5 @@ These attributes will default to Step 1 processing which may be incorrect. This
|
|
|
12
12
|
`)if(y)p+=m;else{(p.length>0||!a)&&h.push(p),v&&d?h.forEach(N=>d.push(l?l(N):N)):d?c.push(this.buildObjectRow(d,h,n,u)):c.push([...h]),h=[],p="",v=!1,g+=m==="\r"&&M===`
|
|
13
13
|
`?1:0;continue}else if(m===k&&!y)h.push(p),p="";else if(m===t)y?M===s?(p+=t,g++):y=!1:p.length===0?y=!0:p+=m;else if((y||p.length===0)&&(m==="{"||m==="[")){const N=this.extractJson(r,g,k);p+=N.value,g+=N.length-1}else p+=m}return(p.length>0||!a)&&h.push(p),h.length&&(v&&d?h.forEach(m=>d.push(l?l(m):m)):d?c.push(this.buildObjectRow(d,h,n,u)):c.push([...h])),c}buildObjectRow(r,e,t,s){const o={};for(let n=0;n<r.length;n++){const i=r[n];let a=e[n];t&&(a=this.dynamicType(a)),o[i]=s?s(a,i):a}return o}detectDelimiter(r){const e=r.slice(0,r.indexOf(`
|
|
14
14
|
`)),t=[",",";"," ","|"],s=t.map(o=>{const n=new RegExp(`\\${o}`,"g");return(e.match(n)||[]).length});return t[s.indexOf(Math.max(...s))]||","}dynamicType(r){if(r==="true")return!0;if(r==="false")return!1;if(!isNaN(Number(r)))return Number(r);try{return JSON.parse(r)}catch{return r}}extractJson(r,e,t){const s=[];let o=e,n=!1,i="";for(;o<r.length;){const a=r[o];if(!n&&a===t)break;if(!n&&(a===`
|
|
15
|
-
`||a==="\r")){this.log.error("JSON block spans multiple lines",void 0,{startIndex:e,endIndex:o});break}if(a==='"'&&i!=="\\"&&(n=!n),n||(a==="{"||a==="["?s.push(a):(a==="}"&&s[s.length-1]==="{"||a==="]"&&s[s.length-1]==="[")&&s.pop()),o++,i=a,s.length===0&&!n)break}return{value:r.slice(e,o),length:o-e}}};function Bn(r,e=","){return r&&typeof r=="string"?r.split(e).map(t=>t.trim()):[]}class tv{loader;log=Nr.child({prefix:"CsvParser"});constructor(e){this.loader=e}getParserConfig(e,t,s,o){const n=this.loader.config.get()?.options,i=this.loader.options,a=this.log,l={};typeof t?.csvParserOptions?.quoteChar<"u"?l.quoteChar=t?.csvParserOptions?.quoteChar:typeof n?.csvParserOptions?.quoteChar<"u"?l.quoteChar=n?.csvParserOptions?.quoteChar:l.quoteChar=i.csvParserOptions?.quoteChar,typeof t?.csvParserOptions?.delimiter<"u"?l.delimiter=t?.csvParserOptions?.delimiter:typeof n?.csvParserOptions?.delimiter<"u"?l.delimiter=n?.csvParserOptions?.delimiter:l.delimiter=i.csvParserOptions?.delimiter,typeof t?.csvParserOptions?.escapeChar<"u"?l.escapeChar=t?.csvParserOptions?.escapeChar:typeof n?.csvParserOptions?.escapeChar<"u"?l.escapeChar=n?.csvParserOptions?.escapeChar:l.escapeChar=i.csvParserOptions?.escapeChar,typeof t?.csvParserOptions?.commentChar<"u"?l.commentChar=t?.csvParserOptions?.commentChar:typeof n?.csvParserOptions?.commentChar<"u"?l.commentChar=n?.csvParserOptions?.commentChar:l.commentChar=i.csvParserOptions?.commentChar;const u=new Map,c=new Map;if(e.references)for(const p of e.references)u.set(p.key,p),p.origin&&u.set(p.origin,p);if(e.properties)for(const p of e.properties)c.set(p.key,p),p.origin&&c.set(p.origin,p);const d=t?.keyProperty??e.keyProperty??"key",f=Array.isArray(d)?d:[d],h=new Set(f);return{delimiter:l?.delimiter,quoteChar:l?.quoteChar,escapeChar:l?.escapeChar,comments:l.commentChar,dynamicTyping:!1,header:!0,skipEmptyLines:!0,transformHeader:p=>{const y=p?.trim().replace(/"/g,"");return s&&y&&s.push(y),y},transform:function(p,y){if(typeof y>"u"||h.has(y))return p;if(p==="null")return null;if(p===""||typeof p>"u")return;const v=m=>{if(!o)return;const M=o[y];M?M.count+=1:o[y]={rawValue:p,expected:m,count:1}},g=u.get(y);if(g)if(p[0]==="{"||p[0]==="[")try{return JSON.parse(p)}catch(m){a.error("Failed to parse JSON in CSV reference field",m,{header:y,value:p});return}else return g.type==="singleValued"?p:p?.length>0&&g.type==="multiValued"?Bn(p,g?.separator):p;const k=c.get(y);if(!(!e.autoGenerateProperties&&!k))switch(k?.type){case"string":return p;case"int":{const m=parseInt(p,10);if(isNaN(m)){v("int");return}return m}case"float":{const m=parseFloat(p);if(isNaN(m)){v("float");return}return m}case"boolean":if(p==="true")return!0;if(p==="false")return!1;v("boolean");return;case"json":try{return p=p.replace(/[\x00-\x1F\x7F-\x9F]/g,""),JSON.parse(p)}catch(m){a.error("Failed to parse JSON in CSV property field",m,{header:y,value:p}),v("json");return}case"Array<string>":case"Array<int>":case"Array<float>":case"Array<date>":if(p&&typeof p=="string"&&p[0]==="[")try{return JSON.parse(p)}catch{v(k.type);return}if(p&&typeof p=="string")return Bn(p,k?.separator);v(k.type);return;default:return p}}}}getJsonFromCSVString(e,t,s){return this.getJsonFromCSVStringWithMetadata(e,t,s).data}getJsonFromCSVStringWithMetadata(e,t,s){const o=[],n={},i=this.getParserConfig(t,s.options,o,n);return{data:new ev().parse(e,i),sourceColumns:o,coercionFailureSamples:n}}}var Gn=typeof global=="object"&&global&&global.Object===Object&&global,rv=typeof self=="object"&&self&&self.Object===Object&&self,X=Gn||rv||Function("return this")(),fe=X.Symbol,Vn=Object.prototype,sv=Vn.hasOwnProperty,ov=Vn.toString,pt=fe?fe.toStringTag:void 0;function nv(r){var e=sv.call(r,pt),t=r[pt];try{r[pt]=void 0;var s=!0}catch{}var o=ov.call(r);return s&&(e?r[pt]=t:delete r[pt]),o}var iv=Object.prototype,av=iv.toString;function lv(r){return av.call(r)}var uv="[object Null]",cv="[object Undefined]",Un=fe?fe.toStringTag:void 0;function Ge(r){return r==null?r===void 0?cv:uv:Un&&Un in Object(r)?nv(r):lv(r)}function De(r){return r!=null&&typeof r=="object"}var dv="[object Symbol]";function Wr(r){return typeof r=="symbol"||De(r)&&Ge(r)==dv}function Nn(r,e){for(var t=-1,s=r==null?0:r.length,o=Array(s);++t<s;)o[t]=e(r[t],t,r);return o}var Ve=Array.isArray,zn=fe?fe.prototype:void 0,Ln=zn?zn.toString:void 0;function Wn(r){if(typeof r=="string")return r;if(Ve(r))return Nn(r,Wn)+"";if(Wr(r))return Ln?Ln.call(r):"";var e=r+"";return e=="0"&&1/r==-1/0?"-0":e}function Gt(r){var e=typeof r;return r!=null&&(e=="object"||e=="function")}function Hn(r){return r}var fv="[object AsyncFunction]",pv="[object Function]",hv="[object GeneratorFunction]",yv="[object Proxy]";function Jn(r){if(!Gt(r))return!1;var e=Ge(r);return e==pv||e==hv||e==fv||e==yv}var Hr=X["__core-js_shared__"],Zn=(function(){var r=/[^.]+$/.exec(Hr&&Hr.keys&&Hr.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""})();function gv(r){return!!Zn&&Zn in r}var mv=Function.prototype,vv=mv.toString;function Pe(r){if(r!=null){try{return vv.call(r)}catch{}try{return r+""}catch{}}return""}var bv=/[\\^$.*+?()[\]{}|]/g,kv=/^\[object .+?Constructor\]$/,wv=Function.prototype,Av=Object.prototype,$v=wv.toString,Cv=Av.hasOwnProperty,Dv=RegExp("^"+$v.call(Cv).replace(bv,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Pv(r){if(!Gt(r)||gv(r))return!1;var e=Jn(r)?Dv:kv;return e.test(Pe(r))}function _v(r,e){return r?.[e]}function _e(r,e){var t=_v(r,e);return Pv(t)?t:void 0}var Jr=_e(X,"WeakMap"),Yn=Object.create,xv=(function(){function r(){}return function(e){if(!Gt(e))return{};if(Yn)return Yn(e);r.prototype=e;var t=new r;return r.prototype=void 0,t}})();function Ev(r,e,t){switch(t.length){case 0:return r.call(e);case 1:return r.call(e,t[0]);case 2:return r.call(e,t[0],t[1]);case 3:return r.call(e,t[0],t[1],t[2])}return r.apply(e,t)}var Sv=800,jv=16,Mv=Date.now;function Rv(r){var e=0,t=0;return function(){var s=Mv(),o=jv-(s-t);if(t=s,o>0){if(++e>=Sv)return arguments[0]}else e=0;return r.apply(void 0,arguments)}}function Iv(r){return function(){return r}}var Vt=(function(){try{var r=_e(Object,"defineProperty");return r({},"",{}),r}catch{}})(),Tv=Vt?function(r,e){return Vt(r,"toString",{configurable:!0,enumerable:!1,value:Iv(e),writable:!0})}:Hn,Ov=Rv(Tv);function Kv(r,e){for(var t=-1,s=r==null?0:r.length;++t<s&&e(r[t],t,r)!==!1;);return r}function Fv(r,e,t,s){for(var o=r.length,n=t+-1;++n<o;)if(e(r[n],n,r))return n;return-1}function qv(r){return r!==r}function Qv(r,e,t){for(var s=t-1,o=r.length;++s<o;)if(r[s]===e)return s;return-1}function Bv(r,e,t){return e===e?Qv(r,e,t):Fv(r,qv,t)}function Gv(r,e){var t=r==null?0:r.length;return!!t&&Bv(r,e,0)>-1}var Vv=9007199254740991,Uv=/^(?:0|[1-9]\d*)$/;function Nv(r,e){var t=typeof r;return e=e??Vv,!!e&&(t=="number"||t!="symbol"&&Uv.test(r))&&r>-1&&r%1==0&&r<e}function zv(r,e,t){e=="__proto__"&&Vt?Vt(r,e,{configurable:!0,enumerable:!0,value:t,writable:!0}):r[e]=t}function Xn(r,e){return r===e||r!==r&&e!==e}var Lv=Object.prototype,Wv=Lv.hasOwnProperty;function Hv(r,e,t){var s=r[e];(!(Wv.call(r,e)&&Xn(s,t))||t===void 0&&!(e in r))&&zv(r,e,t)}var ei=Math.max;function Jv(r,e,t){return e=ei(e===void 0?r.length-1:e,0),function(){for(var s=arguments,o=-1,n=ei(s.length-e,0),i=Array(n);++o<n;)i[o]=s[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=s[o];return a[e]=t(i),Ev(r,this,a)}}function Zv(r,e){return Ov(Jv(r,e,Hn),r+"")}var Yv=9007199254740991;function ti(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=Yv}function ri(r){return r!=null&&ti(r.length)&&!Jn(r)}var Xv=Object.prototype;function si(r){var e=r&&r.constructor,t=typeof e=="function"&&e.prototype||Xv;return r===t}function eb(r,e){for(var t=-1,s=Array(r);++t<r;)s[t]=e(t);return s}var tb="[object Arguments]";function oi(r){return De(r)&&Ge(r)==tb}var ni=Object.prototype,rb=ni.hasOwnProperty,sb=ni.propertyIsEnumerable,ob=oi((function(){return arguments})())?oi:function(r){return De(r)&&rb.call(r,"callee")&&!sb.call(r,"callee")};function nb(){return!1}var ii=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ai=ii&&typeof module=="object"&&module&&!module.nodeType&&module,ib=ai&&ai.exports===ii,li=ib?X.Buffer:void 0,ab=li?li.isBuffer:void 0,ui=ab||nb,lb="[object Arguments]",ub="[object Array]",cb="[object Boolean]",db="[object Date]",fb="[object Error]",pb="[object Function]",hb="[object Map]",yb="[object Number]",gb="[object Object]",mb="[object RegExp]",vb="[object Set]",bb="[object String]",kb="[object WeakMap]",wb="[object ArrayBuffer]",Ab="[object DataView]",$b="[object Float32Array]",Cb="[object Float64Array]",Db="[object Int8Array]",Pb="[object Int16Array]",_b="[object Int32Array]",xb="[object Uint8Array]",Eb="[object Uint8ClampedArray]",Sb="[object Uint16Array]",jb="[object Uint32Array]",P={};P[$b]=P[Cb]=P[Db]=P[Pb]=P[_b]=P[xb]=P[Eb]=P[Sb]=P[jb]=!0,P[lb]=P[ub]=P[wb]=P[cb]=P[Ab]=P[db]=P[fb]=P[pb]=P[hb]=P[yb]=P[gb]=P[mb]=P[vb]=P[bb]=P[kb]=!1;function Mb(r){return De(r)&&ti(r.length)&&!!P[Ge(r)]}function Zr(r){return function(e){return r(e)}}var ci=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ht=ci&&typeof module=="object"&&module&&!module.nodeType&&module,Rb=ht&&ht.exports===ci,Yr=Rb&&Gn.process,Ue=(function(){try{var r=ht&&ht.require&&ht.require("util").types;return r||Yr&&Yr.binding&&Yr.binding("util")}catch{}})(),di=Ue&&Ue.isTypedArray,Ib=di?Zr(di):Mb,Tb=Object.prototype,Ob=Tb.hasOwnProperty;function Kb(r,e){var t=Ve(r),s=!t&&ob(r),o=!t&&!s&&ui(r),n=!t&&!s&&!o&&Ib(r),i=t||s||o||n,a=i?eb(r.length,String):[],l=a.length;for(var u in r)Ob.call(r,u)&&!(i&&(u=="length"||o&&(u=="offset"||u=="parent")||n&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||Nv(u,l)))&&a.push(u);return a}function fi(r,e){return function(t){return r(e(t))}}var Fb=fi(Object.keys,Object),qb=Object.prototype,Qb=qb.hasOwnProperty;function Bb(r){if(!si(r))return Fb(r);var e=[];for(var t in Object(r))Qb.call(r,t)&&t!="constructor"&&e.push(t);return e}function Gb(r){return ri(r)?Kb(r):Bb(r)}var Vb=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ub=/^\w*$/;function Nb(r,e){if(Ve(r))return!1;var t=typeof r;return t=="number"||t=="symbol"||t=="boolean"||r==null||Wr(r)?!0:Ub.test(r)||!Vb.test(r)||e!=null&&r in Object(e)}var yt=_e(Object,"create");function zb(){this.__data__=yt?yt(null):{},this.size=0}function Lb(r){var e=this.has(r)&&delete this.__data__[r];return this.size-=e?1:0,e}var Wb="__lodash_hash_undefined__",Hb=Object.prototype,Jb=Hb.hasOwnProperty;function Zb(r){var e=this.__data__;if(yt){var t=e[r];return t===Wb?void 0:t}return Jb.call(e,r)?e[r]:void 0}var Yb=Object.prototype,Xb=Yb.hasOwnProperty;function ek(r){var e=this.__data__;return yt?e[r]!==void 0:Xb.call(e,r)}var tk="__lodash_hash_undefined__";function rk(r,e){var t=this.__data__;return this.size+=this.has(r)?0:1,t[r]=yt&&e===void 0?tk:e,this}function xe(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var s=r[e];this.set(s[0],s[1])}}xe.prototype.clear=zb,xe.prototype.delete=Lb,xe.prototype.get=Zb,xe.prototype.has=ek,xe.prototype.set=rk;function sk(){this.__data__=[],this.size=0}function Ut(r,e){for(var t=r.length;t--;)if(Xn(r[t][0],e))return t;return-1}var ok=Array.prototype,nk=ok.splice;function ik(r){var e=this.__data__,t=Ut(e,r);if(t<0)return!1;var s=e.length-1;return t==s?e.pop():nk.call(e,t,1),--this.size,!0}function ak(r){var e=this.__data__,t=Ut(e,r);return t<0?void 0:e[t][1]}function lk(r){return Ut(this.__data__,r)>-1}function uk(r,e){var t=this.__data__,s=Ut(t,r);return s<0?(++this.size,t.push([r,e])):t[s][1]=e,this}function ae(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var s=r[e];this.set(s[0],s[1])}}ae.prototype.clear=sk,ae.prototype.delete=ik,ae.prototype.get=ak,ae.prototype.has=lk,ae.prototype.set=uk;var gt=_e(X,"Map");function ck(){this.size=0,this.__data__={hash:new xe,map:new(gt||ae),string:new xe}}function dk(r){var e=typeof r;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?r!=="__proto__":r===null}function Nt(r,e){var t=r.__data__;return dk(e)?t[typeof e=="string"?"string":"hash"]:t.map}function fk(r){var e=Nt(this,r).delete(r);return this.size-=e?1:0,e}function pk(r){return Nt(this,r).get(r)}function hk(r){return Nt(this,r).has(r)}function yk(r,e){var t=Nt(this,r),s=t.size;return t.set(r,e),this.size+=t.size==s?0:1,this}function le(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var s=r[e];this.set(s[0],s[1])}}le.prototype.clear=ck,le.prototype.delete=fk,le.prototype.get=pk,le.prototype.has=hk,le.prototype.set=yk;var gk="Expected a function";function Xr(r,e){if(typeof r!="function"||e!=null&&typeof e!="function")throw new TypeError(gk);var t=function(){var s=arguments,o=e?e.apply(this,s):s[0],n=t.cache;if(n.has(o))return n.get(o);var i=r.apply(this,s);return t.cache=n.set(o,i)||n,i};return t.cache=new(Xr.Cache||le),t}Xr.Cache=le;var mk=500;function vk(r){var e=Xr(r,function(s){return t.size===mk&&t.clear(),s}),t=e.cache;return e}var bk=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,kk=/\\(\\)?/g,wk=vk(function(r){var e=[];return r.charCodeAt(0)===46&&e.push(""),r.replace(bk,function(t,s,o,n){e.push(o?n.replace(kk,"$1"):s||t)}),e});function Ak(r){return r==null?"":Wn(r)}function $k(r,e){return Ve(r)?r:Nb(r,e)?[r]:wk(Ak(r))}function Ck(r){if(typeof r=="string"||Wr(r))return r;var e=r+"";return e=="0"&&1/r==-1/0?"-0":e}function Dk(r,e){e=$k(e,r);for(var t=0,s=e.length;r!=null&&t<s;)r=r[Ck(e[t++])];return t&&t==s?r:void 0}function Pk(r,e,t){var s=r==null?void 0:Dk(r,e);return s===void 0?t:s}function _k(r,e){for(var t=-1,s=e.length,o=r.length;++t<s;)r[o+t]=e[t];return r}var xk=fi(Object.getPrototypeOf,Object);function Ek(){this.__data__=new ae,this.size=0}function Sk(r){var e=this.__data__,t=e.delete(r);return this.size=e.size,t}function jk(r){return this.__data__.get(r)}function Mk(r){return this.__data__.has(r)}var Rk=200;function Ik(r,e){var t=this.__data__;if(t instanceof ae){var s=t.__data__;if(!gt||s.length<Rk-1)return s.push([r,e]),this.size=++t.size,this;t=this.__data__=new le(s)}return t.set(r,e),this.size=t.size,this}function Ne(r){var e=this.__data__=new ae(r);this.size=e.size}Ne.prototype.clear=Ek,Ne.prototype.delete=Sk,Ne.prototype.get=jk,Ne.prototype.has=Mk,Ne.prototype.set=Ik;var pi=typeof exports=="object"&&exports&&!exports.nodeType&&exports,hi=pi&&typeof module=="object"&&module&&!module.nodeType&&module,Tk=hi&&hi.exports===pi,yi=Tk?X.Buffer:void 0;yi&&yi.allocUnsafe;function Ok(r,e){return r.slice()}function Kk(r,e){for(var t=-1,s=r==null?0:r.length,o=0,n=[];++t<s;){var i=r[t];e(i,t,r)&&(n[o++]=i)}return n}function Fk(){return[]}var qk=Object.prototype,Qk=qk.propertyIsEnumerable,gi=Object.getOwnPropertySymbols,Bk=gi?function(r){return r==null?[]:(r=Object(r),Kk(gi(r),function(e){return Qk.call(r,e)}))}:Fk;function Gk(r,e,t){var s=e(r);return Ve(r)?s:_k(s,t(r))}function Vk(r){return Gk(r,Gb,Bk)}var es=_e(X,"DataView"),ts=_e(X,"Promise"),rs=_e(X,"Set"),mi="[object Map]",Uk="[object Object]",vi="[object Promise]",bi="[object Set]",ki="[object WeakMap]",wi="[object DataView]",Nk=Pe(es),zk=Pe(gt),Lk=Pe(ts),Wk=Pe(rs),Hk=Pe(Jr),ue=Ge;(es&&ue(new es(new ArrayBuffer(1)))!=wi||gt&&ue(new gt)!=mi||ts&&ue(ts.resolve())!=vi||rs&&ue(new rs)!=bi||Jr&&ue(new Jr)!=ki)&&(ue=function(r){var e=Ge(r),t=e==Uk?r.constructor:void 0,s=t?Pe(t):"";if(s)switch(s){case Nk:return wi;case zk:return mi;case Lk:return vi;case Wk:return bi;case Hk:return ki}return e});var Jk=Object.prototype,Zk=Jk.hasOwnProperty;function Yk(r){var e=r.length,t=new r.constructor(e);return e&&typeof r[0]=="string"&&Zk.call(r,"index")&&(t.index=r.index,t.input=r.input),t}var Ai=X.Uint8Array;function ss(r){var e=new r.constructor(r.byteLength);return new Ai(e).set(new Ai(r)),e}function Xk(r,e){var t=ss(r.buffer);return new r.constructor(t,r.byteOffset,r.byteLength)}var ew=/\w*$/;function tw(r){var e=new r.constructor(r.source,ew.exec(r));return e.lastIndex=r.lastIndex,e}var $i=fe?fe.prototype:void 0,Ci=$i?$i.valueOf:void 0;function rw(r){return Ci?Object(Ci.call(r)):{}}function sw(r,e){var t=ss(r.buffer);return new r.constructor(t,r.byteOffset,r.length)}var ow="[object Boolean]",nw="[object Date]",iw="[object Map]",aw="[object Number]",lw="[object RegExp]",uw="[object Set]",cw="[object String]",dw="[object Symbol]",fw="[object ArrayBuffer]",pw="[object DataView]",hw="[object Float32Array]",yw="[object Float64Array]",gw="[object Int8Array]",mw="[object Int16Array]",vw="[object Int32Array]",bw="[object Uint8Array]",kw="[object Uint8ClampedArray]",ww="[object Uint16Array]",Aw="[object Uint32Array]";function $w(r,e,t){var s=r.constructor;switch(e){case fw:return ss(r);case ow:case nw:return new s(+r);case pw:return Xk(r);case hw:case yw:case gw:case mw:case vw:case bw:case kw:case ww:case Aw:return sw(r);case iw:return new s;case aw:case cw:return new s(r);case lw:return tw(r);case uw:return new s;case dw:return rw(r)}}function Cw(r){return typeof r.constructor=="function"&&!si(r)?xv(xk(r)):{}}var Dw="[object Map]";function Pw(r){return De(r)&&ue(r)==Dw}var Di=Ue&&Ue.isMap,_w=Di?Zr(Di):Pw,xw="[object Set]";function Ew(r){return De(r)&&ue(r)==xw}var Pi=Ue&&Ue.isSet,Sw=Pi?Zr(Pi):Ew,_i="[object Arguments]",jw="[object Array]",Mw="[object Boolean]",Rw="[object Date]",Iw="[object Error]",xi="[object Function]",Tw="[object GeneratorFunction]",Ow="[object Map]",Kw="[object Number]",Ei="[object Object]",Fw="[object RegExp]",qw="[object Set]",Qw="[object String]",Bw="[object Symbol]",Gw="[object WeakMap]",Vw="[object ArrayBuffer]",Uw="[object DataView]",Nw="[object Float32Array]",zw="[object Float64Array]",Lw="[object Int8Array]",Ww="[object Int16Array]",Hw="[object Int32Array]",Jw="[object Uint8Array]",Zw="[object Uint8ClampedArray]",Yw="[object Uint16Array]",Xw="[object Uint32Array]",$={};$[_i]=$[jw]=$[Vw]=$[Uw]=$[Mw]=$[Rw]=$[Nw]=$[zw]=$[Lw]=$[Ww]=$[Hw]=$[Ow]=$[Kw]=$[Ei]=$[Fw]=$[qw]=$[Qw]=$[Bw]=$[Jw]=$[Zw]=$[Yw]=$[Xw]=!0,$[Iw]=$[xi]=$[Gw]=!1;function zt(r,e,t,s,o,n){var i;if(i!==void 0)return i;if(!Gt(r))return r;var a=Ve(r);if(a)i=Yk(r);else{var l=ue(r),u=l==xi||l==Tw;if(ui(r))return Ok(r);if(l==Ei||l==_i||u&&!o)i=u?{}:Cw(r);else{if(!$[l])return o?r:{};i=$w(r,l)}}n||(n=new Ne);var c=n.get(r);if(c)return c;n.set(r,i),Sw(r)?r.forEach(function(h){i.add(zt(h,e,t,h,r,n))}):_w(r)&&r.forEach(function(h,p){i.set(p,zt(h,e,t,p,r,n))});var d=Vk,f=a?void 0:d(r);return Kv(f||r,function(h,p){f&&(p=h,h=r[p]),Hv(i,p,zt(h,e,t,p,r,n))}),i}var eA=1,tA=4;function mt(r){return zt(r,eA|tA)}var rA="__lodash_hash_undefined__";function sA(r){return this.__data__.set(r,rA),this}function oA(r){return this.__data__.has(r)}function Lt(r){var e=-1,t=r==null?0:r.length;for(this.__data__=new le;++e<t;)this.add(r[e])}Lt.prototype.add=Lt.prototype.push=sA,Lt.prototype.has=oA;function Si(r,e){return r.has(e)}function nA(r){return De(r)&&ri(r)}var iA=Math.min;function aA(r,e,t){for(var s=Gv,o=r[0].length,n=r.length,i=n,a=Array(n),l=1/0,u=[];i--;){var c=r[i];l=iA(c.length,l),a[i]=o>=120&&c.length>=120?new Lt(i&&c):void 0}c=r[0];var d=-1,f=a[0];e:for(;++d<o&&u.length<l;){var h=c[d],p=h;if(h=h!==0?h:0,!(f?Si(f,p):s(u,p))){for(i=n;--i;){var y=a[i];if(!(y?Si(y,p):s(r[i],p)))continue e}f&&f.push(p),u.push(h)}}return u}function lA(r){return nA(r)?r:[]}var ji=Zv(function(r){var e=Nn(r,lA);return e.length&&e[0]===r[0]?aA(e):[]});class Mi{context="";total=0;totalItems=[];processedItems=new Set;downloadedItems=new Set;failedItems=new Set;remainingItems=new Set;skippedItems=[];run;processed=0;remaining=0;progress=0;currentItem;constructor(){}init(e,t){return this.total=e.length,this.totalItems=[...e],this.remaining=e.length,this.remainingItems=new Set(e),this.skippedItems=t?.skipped??[],this.run=t?.run,this.getProgress()}update(e,t,s,o){const n=mt(e);return n.success=t,o&&(n.status=o),t?this.downloadedItems.add(n):this.failedItems.add(n),this.currentItem=n,this.context=s,this.processed++,this.remaining--,this.progress=Math.round(this.processed*100/this.total),this.currentItem=n,this.processedItems.add(n),this.remainingItems.delete(e),this.getProgress()}getProgress(){return{total:this.total,processed:this.processed,remaining:this.remaining,downloadedItems:Array.from(this.downloadedItems.values()),failedItems:Array.from(this.failedItems.values()),progress:this.progress,context:this.context,currentItem:this.currentItem,totalItems:this.totalItems,processedItems:Array.from(this.processedItems.values()),remainingItems:Array.from(this.remainingItems.values()),skippedItems:this.skippedItems,run:this.run}}}function uA(r,e){for(const t of e)if(Array.isArray(t)){if(t.every(s=>r.includes(s)))return!0}else if(r.includes(t))return!0;return!1}function cA(r,e){return Xm(r).variables.map(t=>t.name).filter(t=>Pk(e,t)===void 0)}function Ri(r,e,t){const s={applicationKey:t?.applicationKey,resourceTags:t?.resourceTags,environmentKeys:t?.environmentKeys},o=r?.resources??[],n=Ym(o),i=[],a=[],l=Array.isArray(t?.resourceTags)&&t.resourceTags.length>0;return o.forEach((u,c)=>{if(l){if(!Array.isArray(u.tags)||!u.tags.length){a.push({resource:u,reason:"no-tags",id:n[c]});return}if(!uA(u.tags,t.resourceTags)){a.push({resource:u,reason:"tag-mismatch",id:n[c]});return}}const d=u.url??"",f=cA(d,e),h={...u,id:n[c],rawUrl:d,url:Bt(d,{...e})};f.length&&(h.unresolvedVariables=f),i.push(h)}),{scheduled:i,skipped:a,variables:e,run:s}}var dA=Object.defineProperty,fA=Object.getOwnPropertyDescriptor,Ii=(r,e,t,s)=>{for(var o=fA(e,t),n=r.length-1,i;n>=0;n--)(i=r[n])&&(o=i(e,t,o)||o);return o&&dA(e,t,o),o};const pA={missingModelHandling:{autoGenerateProperties:!0},defaultDataContainerUpdateType:"set",csvParserOptions:{delimiter:"",quoteChar:'"',escapeChar:'"',commentChar:void 0}};let os=class{key;core;cdRef=new Hm;log=Nr.child({prefix:"AppLoader"});registeredTransformers=[];options=pA;csvParser=new tv(this);currentConfig;globalVariables=new Map;defaultVariables=new Map;progressListeners=new Set;currentProcessOptions;currentContext="";progressHandler=new Mi;constructor(){this.initDefaultVariables()}destroy(){this.core=null,this.cdRef=null,this.csvParser=null,this.progressListeners=null,this.progressHandler=null}initDefaultVariables(){this.defaultVariables.set("projectId",{key:"projectId",value:void 0,description:"Your dcupl console project id"}),this.defaultVariables.set("apiKey",{key:"apiKey",value:void 0,description:"Your dcupl console project API key"}),this.defaultVariables.set("version",{key:"version",value:"draft",description:"The version of uploaded files to the dcupl CDN - draft/published/..."}),this.defaultVariables.set("cdnBaseUrl",{key:"cdnBaseUrl",value:"https://cdn.dcupl.com/files/projects",description:"The url to your dcupl folder - might be the dcupl CDN or any other "}),this.defaultVariables.set("baseUrl",{key:"baseUrl",value:"${cdnBaseUrl}/${projectId}/${version}",description:"The base url to your hosted models and data files"}),this.defaultVariables.set("modelUrl",{key:"modelUrl",value:"${baseUrl}/models",description:"The url to the your model files"}),this.defaultVariables.set("dataUrl",{key:"dataUrl",value:"${baseUrl}/data",description:"The url to the your data files"}),this.defaultVariables.set("transformerUrl",{key:"transformerUrl",value:"${baseUrl}/transformers",description:"The url to the your data files"}),this.defaultVariables.set("loaderFileName",{key:"loaderFileName",value:"dcupl.lc.json",description:"The file name of the loader json"}),this.defaultVariables.set("cdnVersion",{key:"cdnVersion",value:void 0,description:"The file-version of the CDN data"}),this.defaultVariables.set("consoleApiUrl",{key:"consoleApiUrl",value:"https://api.dcupl.com",description:"The dcupl console API Url"})}resources={get:r=>this.currentConfig?.resources.find(e=>e.key===r),getAll:()=>this.currentConfig?.resources||[],getWithTag:r=>this.currentConfig?.resources.filter(e=>e.tags?.includes(r))||[],set:r=>{this.currentConfig.resources=r},add:r=>{this.currentConfig.resources.push(r)},delete:r=>{const e=this.currentConfig.resources.findIndex(t=>t.key===r);e>-1&&this.currentConfig.resources.splice(e,1)},plan:r=>{const{config:e,options:t,variables:s}=this.resolveRunContext(r);return Ri(e,s,t)}};variables={get:(r,e)=>{const t=this.currentConfig?.environments?.filter(s=>s.key===e);return this.evaluateVariables(t,this.currentProcessOptions).find(s=>s.key===r)},getAll:r=>{const e=this.currentConfig?.environments?.filter(t=>t.key===r);return this.evaluateVariables(e,this.currentProcessOptions)},getAllAsObject:r=>{const e=this.currentConfig?.environments?.filter(t=>t.key===r);return this.getEvaluatedVariablesAsRecord(e,this.currentProcessOptions)},default:{get:r=>this.defaultVariables.get(r),getAll:()=>Array.from(this.defaultVariables.values())},environment:{get:(r,e)=>{if(!r)return;const t=this.currentConfig?.environments?.find(s=>s.key===r);if(t)return t.variables?.find(s=>s.key===e)},getAll:r=>this.currentConfig?.environments?.find(e=>e.key===r)?.variables||[]},process:{get:r=>this.currentProcessOptions?.variables?.find(e=>e.key===r),getAll:()=>this.currentProcessOptions?.variables||[]},global:{get:r=>this.globalVariables.get(r),getAll:()=>Array.from(this.globalVariables.values()),set:(r,e)=>{this.globalVariables.set(r,{key:r,value:e})},delete:r=>{this.globalVariables.delete(r)}}};transformers={get:r=>this.registeredTransformers.filter(e=>ji(e.applyTo,r.appyTo).length>0),getAll:()=>this.registeredTransformers,set:r=>{this.transformers.remove(r.key),this.registeredTransformers.push(r)},remove:r=>{const e=this.registeredTransformers.findIndex(t=>t.key===r);e>-1&&this.registeredTransformers.splice(e,1)}};config={get:()=>mt(this.currentConfig),set:r=>{this.currentConfig=mt(r)},fetch:async r=>this.fetchConfig(r)};async fetchConfig(r){if(!this.core)throw this.log.error("dcupl not connected. Did you add your loader to dcupl? -> dcupl.addRunner(loader)"),new Error;let e;r?.baseUrl&&this.defaultVariables.set("baseUrl",{key:"baseUrl",value:String(r.baseUrl)}),r?.loaderFileName&&this.defaultVariables.set("loaderFileName",{key:"loaderFileName",value:String(r.loaderFileName)});const t=this.variables.get("baseUrl")?.value;if(t&&this.isDcuplCdn(t))await this.setCdnVersion(),e=await this.loadConfigFromApi();else{const s=this.variables.get("loaderFileName")?.value,o=`${t}/${s}`;e=await this.loadConfigFromUrl(o,r?.headers)}if(this.isValidConfig(e))return r?.skipApply||this.config.set(e),e;throw new Error("Invalid Loader Configuration")}isValidConfig(r){return!!r}async loadConfigFromUrl(r,e){try{const t={};e&&(t.headers=e.reduce((o,n)=>(o[n.key]=n.value,o),{}));const s=await fetch(r,t);if(!s.ok)throw new Error(`Failed to fetch loader configuration from ${r}`);return s.json()}catch(t){this.log.error("Could not fetch loader configuration",t,{url:r});return}}async loadConfigFromApi(){const r=this.variables.get("baseUrl")?.value,e=this.variables.get("loaderFileName")?.value,t=this.variables.get("cdnVersion")?.value,s=this.variables.get("apiKey")?.value;try{let o=`${r}/${e}`;this.isDcuplCdn(o)&&(t&&(o=this.appendSearchParamToUrl(o,"v",String(t))),s&&(o=this.appendSearchParamToUrl(o,"api-key",s)));const n=await fetch(o);if(!n.ok)throw new Error(`Failed to fetch loader configuration from ${o}`);return n.json()}catch(o){this.log.error("Could not fetch loader configuration. Are you sure your projectId + apiKey are correct?",o,{baseUrl:r,loaderFileName:e});return}}appendSearchParamToUrl(r,e,t){const s=r.includes("?")?"&":"?";return`${r}${s}${e}=${t}`}async setCdnVersion(){let r;try{const e=this.variables.get("consoleApiUrl")?.value,t=this.variables.get("projectId")?.value,s=this.variables.get("version")?.value;r=`${e}/projects/${t}/files/versions/${s}/status`;const o=await(await fetch(r)).json();o&&o.changedAt&&this.defaultVariables.set("cdnVersion",{key:"cdnVersion",value:String(o.changedAt)})}catch(e){this.log.error("Could not fetch version status",e,{url:r})}}async process(r){if(!this.currentConfig)throw new Error("There is no config present. Make sure to call loader.setConfig(..) or loader.fetchConfig(...)");this.currentContext=zr();const{config:e,options:t,environments:s,variables:o}=this.resolveRunContext(r),n=this.getHeaderConfigs(s),i=this.getQueryParamConfigs(s),a=Ri(e,o,t),l=this.getLoaderOptions(e,t),u=await this.fetchResources(a,o,l,n,i);return this.currentProcessOptions=t,u}getHeaderConfigs(r){if(!r)return[];const e=[];return r.forEach(t=>{t.headers&&e.push(...t.headers)}),e}getQueryParamConfigs(r){if(!r)return[];const e=[];return r.forEach(t=>{t.queryParams&&e.push(...t.queryParams)}),e}getLoaderOptions(r,e){return e?.options?Object.assign({},this.options,e.options):r?.options?Object.assign({},this.options,r.options):Object.assign({},this.options)}resolveRunContext(r){if(!this.currentConfig)throw new Error("There is no config present. Make sure to call loader.setConfig(..) or loader.fetchConfig(...)");const e=mt(r),t=mt(this.currentConfig);if(e?.applicationKey){const n=this.getAppPreset(t,e);if(!n)throw new Error(`The applicationKey ${e.applicationKey} does not exist`);e.resourceTags=e.resourceTags||n?.resourceTags,e.variables=e.variables||n?.variables}const s=this.getEnvironments(t,e),o=this.getEvaluatedVariablesAsRecord(s,e);return{config:t,options:e,environments:s,variables:o}}evaluateVariables(r,e){const t=new Map;this.defaultVariables&&this.defaultVariables.forEach(n=>{t.set(n.key,n)}),r?.forEach(n=>{n?.variables&&n.variables.forEach(i=>{t.set(i.key,i)})}),e?.variables&&e.variables.forEach(n=>{t.set(n.key,n)}),this.globalVariables&&this.globalVariables.forEach(n=>{t.set(n.key,n)});const s=Array.from(t.values()).map(n=>({...n})),o={};for(const n of s)o[n.key]=n.value||"";for(const n of s)n.value=Bt(n.value,o);return s}getEvaluatedVariablesAsRecord(r,e){const t=this.evaluateVariables(r,e),s={};for(const o of t)s[o.key]=o.value||"";return s}getEnvironments(r,e){if(!(!r.environments||!r.environments[0])&&e&&e.environmentKeys&&e.environmentKeys.length>0)return r.environments.filter(t=>e.environmentKeys.indexOf(t.key)>-1)}getAppPreset(r,e){if(!(!r.applications||!r.applications[0])&&e?.applicationKey)return r.applications?.find(t=>t.key===e.applicationKey)}getHeaderForUrl(r,e,t){if(!t||!t.length||!r.tags?.length)return;const s=[];t?.forEach(n=>{if(!n.tags?.length){this.isValidCondition(n,e)&&s.push(n);return}n.tags.find(i=>r.tags?.includes(i))&&this.isValidCondition(n,e)&&s.push(n)});const o={};if(s.forEach(n=>{const i=Bt(n.value,{...e});o[n.key]=i}),Object.keys(o).length!==0)return o}getQueryParamsForUrl(r,e,t){const s=[];if(t?.forEach(o=>{if(!o.tags?.length){this.isValidCondition(o,e)&&s.push(o);return}o.tags.find(n=>r.tags?.includes(n))&&this.isValidCondition(o,e)&&s.push(o)}),this.isDcuplCdn(r.url)){const o=e.cdnVersion;o&&s.push({key:"v",value:o}),e.apiKey&&s?.push({key:"api-key",value:e.apiKey})}return s.map(o=>(o.value=Bt(o.value,{...e}),o))}isDcuplCdn(r){return r.includes("cdn.dcupl.com")}isValidCondition(r,e){return r.condition?.applyIfVariableHasValue?typeof e[r.condition?.applyIfVariableHasValue]<"u"&&e[r.condition?.applyIfVariableHasValue]!=="":!0}async handleScriptResources(r,e,t,s){return await Promise.all(r.map(async o=>{try{const n=o.scriptKey;if(this.core.scriptController.hasScript(n)){const l=this.progressHandler.update(o,!0,"script");return this.updateProgressListeners(l),null}const i=await this.fetchScript(o,e,t,s);this.core.scriptController.setScript(n,i);const a=this.progressHandler.update(o,!0,"script");this.updateProgressListeners(a);return}catch(n){this.log.error("Failed to load script resource",n,{url:o.url,scriptKey:o.scriptKey});const i={title:o.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:o,description:n?.message};this.setError(i);const a=this.progressHandler.update(o,!1,"script");this.updateProgressListeners(a);return}})),!0}async handleOperatorResources(r,e,t,s){return await Promise.all(r.map(async o=>{try{const n=o.operator;if(this.core.queryManager.registeredCustomOperator.has(n)){const l=this.progressHandler.update(o,!0,"operator");return this.updateProgressListeners(l),null}const i=await this.fetchJavascriptFile(o,e,t,s);this.core.query.registerCustomOperator(n,i);const a=this.progressHandler.update(o,!0,"operator");this.updateProgressListeners(a);return}catch(n){this.log.error("Failed to load operator resource",n,{url:o.url,operator:o.operator});const i={title:o.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:o,description:n?.message};this.setError(i);const a=this.progressHandler.update(o,!1,"operator");this.updateProgressListeners(a);return}})),!0}async handleTransformerResources(r,e,t,s){const o=[];return await Promise.all(r.map(async n=>{try{const i=this.registeredTransformers.find(c=>c.key===n.url);if(i){o.push(i);const c=this.progressHandler.update(n,!0,"transformer");this.updateProgressListeners(c);return}const a=await this.fetchJavascriptFile(n,e,t,s),l={key:n.url,applyTo:n.applyTo||[],type:n.transformerType||"parsedFileTransformer",transformer:a};this.registeredTransformers.push(l),o.push(l);const u=this.progressHandler.update(n,!0,"transformer");this.updateProgressListeners(u)}catch(i){this.log.error("Failed to load transformer resource",i,{url:n.url,transformerType:n.transformerType});const a={title:n.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:n,description:i?.message};this.setError(a);const l=this.progressHandler.update(n,!1,"transformer");this.updateProgressListeners(l)}})),o}getRequestOptions(r,e,t,s){const o=this.getHeaderForUrl(r,e,t),n=this.getQueryParamsForUrl(r,e,s);return{url:this.appendQueryParamsToUrl(r.url,n),headers:o}}async fetchScript(r,e,t,s){const{url:o,headers:n}=this.getRequestOptions(r,e,t,s),i=await fetch(o,{headers:n});if(!i.ok)throw new Error(`Failed to fetch data from ${o}`);return await i.text()}async fetchJavascriptFile(r,e,t,s){const{url:o,headers:n}=this.getRequestOptions(r,e,t,s),i=await fetch(o,{headers:n});if(!i.ok)throw new Error(`Failed to fetch data from ${o}`);const a=await i.text();return new Function(a)()}isValidModelDefinitionShape(r){if(typeof r!="object"||r===null||Array.isArray(r))return!1;const e=r;return!(typeof e.key!="string"||e.key.length===0||typeof e.properties<"u"&&!Array.isArray(e.properties))}emitInvalidModelDefinitionError(r,e,t){const s={title:r.url,type:"model",errorGroup:"ModelDefinitionError",errorType:"InvalidModelDefinition",model:t??"",meta:r,description:e};this.setError(s)}async handleModelResources(r,e,t,s){const o=r.map(async n=>{const i=new Date().getTime();let a;try{const{url:l,headers:u}=this.getRequestOptions(n,e,t,s),c=await fetch(l,{headers:u});if(a=c.status,!c.ok)throw new Error(`Failed to fetch data from ${l}`);const d=F.now(),f=await c.json(),h=F.now(),p=Array.isArray(f)?f:[f],y=[];for(const m of p)this.isValidModelDefinitionShape(m)?y.push(m):this.emitInvalidModelDefinitionError(n,"Resource body is not a valid ModelDefinition (missing or invalid `key`/`properties`)",typeof m?.key=="string"?m.key:void 0);if(y.length===0){const m=this.progressHandler.update(n,!1,"model",a);return this.updateProgressListeners(m),Promise.resolve(null)}const v=y.map(m=>m.key).join("__"),g=F.getEntriesByName(l.toString());if(Array.isArray(g)&&g[0]){const m=g[0],M={name:n.url,type:"resource",createdAt:new Date().getTime(),value:{model:v,type:"model",start:i,startTime:m.startTime,requestStart:m.requestStart,responseEnd:m.responseEnd,responseStart:m.responseStart,duration:m.duration,parseEnd:h,parseStart:d,decodedBodySize:m.decodedBodySize,encodedBodySize:m.encodedBodySize,end:h}};this.core.analyticsController.set({value:M,context:this.currentContext})}for(const m of y)this.addModelOrView(n,m);const k=this.progressHandler.update(n,!0,"model");return this.updateProgressListeners(k),Promise.resolve(f)}catch(l){this.log.error("Failed to load model resource",l,{url:n.url});const u={title:n.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:n,description:l?.message};this.setError(u);const c=this.progressHandler.update(n,!1,"model",a);return this.updateProgressListeners(c),Promise.resolve(null)}});return await Promise.all(o),!0}appendQueryParamsToUrl(r,e){const t=r.includes("?");let s=r;return e&&e.forEach((o,n)=>{s+=`${n===0&&!t?"?":"&"}${encodeURIComponent(o.key)}=${encodeURIComponent(o.value)}`}),s}async handleDataResources(r,e,t,s,o,n){const i=r.map(async a=>{const l=zr(),u={placeholderUid:l,data:[],model:a.model};this.core.registerContainer(u);const c=new Date().getTime();let d;try{const{url:f,headers:h}=this.getRequestOptions(a,e,s,o),p=await fetch(f,{headers:h});if(d=p.status,!p.ok)throw new Error(`Failed to fetch data from ${f}`);const y=p.headers.get("content-type"),v=F.now();let g;a.url.endsWith(".csv")||y?.includes("text/csv")?g=await p.text():g=await p.json();const k=F.now(),m=F.now(),M=this.handleTransformerLogic(g,a,"rawFileTransformer",n||[]),N=F.now();let bt=[],Wt=this.core.modelParser.unprocessedModelDescriptions.get(a.model);if(!Wt&&(t?.missingModelHandling?.autoGenerateProperties||a.options?.autoGenerateProperties)){const q=a.options?.autoGenerateProperties??t?.missingModelHandling?.autoGenerateProperties??!0;this.addModelOrView(a,{key:a.model,autoGenerateProperties:q,autoGenerateKey:a.options?.autoGenerateKey||!1,keyProperty:a?.options?.keyProperty||"key",keyPropertySeparator:a?.options?.keyPropertySeparator}),Wt=this.core.modelParser.unprocessedModelDescriptions.get(a.model)}const gA=F.now();let Ti={sourceColumns:[],coercionFailureSamples:{},origin:a.url};if(a.url.endsWith(".csv")||y?.includes("text/csv")){if(Wt){const q=this.csvParser.getJsonFromCSVStringWithMetadata(M,Wt,a);bt=q.data,Ti={sourceColumns:q.sourceColumns,coercionFailureSamples:q.coercionFailureSamples,origin:a.url}}}else bt=M;const mA=F.now(),vA=F.now();try{bt=this.handleTransformerLogic(bt,a,"parsedFileTransformer",n||[])}catch(q){this.log.error("Transformer error",q,{resource:a.url,model:a.model})}const bA=F.now(),Oi={placeholderUid:l,model:a.model,data:bt,type:a.options?.updateType||t.defaultDataContainerUpdateType,keyProperty:a?.options?.keyProperty,keyPropertySeparator:a?.options?.keyPropertySeparator,autoGenerateKey:a.options?.autoGenerateKey,autoGenerateProperties:a.options?.autoGenerateProperties},ns=F.getEntriesByName(f.toString());if(Array.isArray(ns)&&ns[0]){const q=ns[0],wA={name:a.url,type:"resource",createdAt:new Date().getTime(),value:{model:a.model,type:"data",start:c,startTime:q.startTime,requestStart:q.requestStart,responseEnd:q.responseEnd,responseStart:q.responseStart,duration:q.duration,parseEnd:k,rawTransformStart:m,rawTransformEnd:N,parseStart:v,csvToJsonStart:gA,csvToJsonEnd:mA,parsedTransformStart:vA,parsedTransformEnd:bA,decodedBodySize:q.decodedBodySize,encodedBodySize:q.encodedBodySize,end:k}};this.core.analyticsController.set({value:wA,context:this.currentContext})}this.core.updateRegisteredContainer(Oi,Ti);const kA=this.progressHandler.update(a,!0,"data",d);return this.updateProgressListeners(kA),Promise.resolve(Oi)}catch(f){this.log.error("Failed to load data resource",f,{url:a.url,model:a.model});const h={title:a.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:a,model:a.model,description:f?.message};this.setError(h),this.core.removeRegisteredContainer(u);const p=this.progressHandler.update(a,!1,"data",d);return this.updateProgressListeners(p),Promise.resolve()}});return await Promise.all(i),!0}async fetchResources(r,e,t,s,o){const n=r.scheduled;this.progressHandler=new Mi,this.progressHandler.init(n,{skipped:r.skipped,run:r.run}),this.updateProgressListeners(this.progressHandler.getProgress());try{if(!this.core)throw this.log.error("dcupl not connected. Did you add your loader to dcupl? -> dcupl.addRunner(loader)"),new Error;const i=n.filter(f=>f.type==="script");await this.handleScriptResources(i,e,s,o);const a=n.filter(f=>f.type==="operator");await this.handleOperatorResources(a,e,s,o);const l=n.filter(f=>f.type==="transformer"),u=await this.handleTransformerResources(l,e,s,o),c=n.filter(f=>f.type==="model");await this.handleModelResources(c,e,s,o);const d=n.filter(f=>f.type==="data");return await this.handleDataResources(d,e,t,s,o,u),!0}catch(i){return this.log.error("Failed to fetch resources",i),!1}}addModelOrView(r,e){try{"model"in e?this.core.views.set(e):this.core.models.set(e)}catch(t){const s={title:r.url,type:"model",errorGroup:"ModelDefinitionError",errorType:"InvalidModelDefinition",model:e.key,meta:r,description:t?.message};this.setError(s)}}handleTransformerLogic(r,e,t,s){for(const o of s)o.type===t&&o.transformer&&(!o.applyTo.length&&!e.tags?.length&&(r=o.transformer(e,r)),ji(o.applyTo,e.tags||[]).length&&(r=o.transformer(e,r)));return r}updateProgressListeners(r){this.progressListeners.forEach(e=>e(r))}on(r){return this.progressListeners.add(r),()=>{this.progressListeners.delete(r)}}setError(r){this.core.modelParser.qualityController.enabled&&this.core.modelParser.qualityController.setError(r)}};Ii([Qn({scope:"global",origin:"loader",type:"loader_config_fetched",connectMessage:!0,connectMessageResult:!0})],os.prototype,"fetchConfig"),Ii([Qn({scope:"global",origin:"loader",type:"loader_processed",connectMessage:!0})],os.prototype,"process");const hA=os;let vt,ze;async function yA(r){return vt=new oh(r.options),ze=new hA,vt.loaders.add(ze,"default"),r.appLoaderConfig?await ze.config.fetch(r.appLoaderConfig):await ze.config.fetch(),await ze.process(r.processOptions),await vt.init(),globalThis.dcupl=vt,{dcupl:vt,loader:ze}}globalThis.initDcupl=yA})();
|
|
15
|
+
`||a==="\r")){this.log.error("JSON block spans multiple lines",void 0,{startIndex:e,endIndex:o});break}if(a==='"'&&i!=="\\"&&(n=!n),n||(a==="{"||a==="["?s.push(a):(a==="}"&&s[s.length-1]==="{"||a==="]"&&s[s.length-1]==="[")&&s.pop()),o++,i=a,s.length===0&&!n)break}return{value:r.slice(e,o),length:o-e}}};function Bn(r,e=","){return r&&typeof r=="string"?r.split(e).map(t=>t.trim()):[]}class tv{loader;log=Nr.child({prefix:"CsvParser"});constructor(e){this.loader=e}getParserConfig(e,t,s,o){const n=this.loader.config.get()?.options,i=this.loader.options,a=this.log,l={};typeof t?.csvParserOptions?.quoteChar<"u"?l.quoteChar=t?.csvParserOptions?.quoteChar:typeof n?.csvParserOptions?.quoteChar<"u"?l.quoteChar=n?.csvParserOptions?.quoteChar:l.quoteChar=i.csvParserOptions?.quoteChar,typeof t?.csvParserOptions?.delimiter<"u"?l.delimiter=t?.csvParserOptions?.delimiter:typeof n?.csvParserOptions?.delimiter<"u"?l.delimiter=n?.csvParserOptions?.delimiter:l.delimiter=i.csvParserOptions?.delimiter,typeof t?.csvParserOptions?.escapeChar<"u"?l.escapeChar=t?.csvParserOptions?.escapeChar:typeof n?.csvParserOptions?.escapeChar<"u"?l.escapeChar=n?.csvParserOptions?.escapeChar:l.escapeChar=i.csvParserOptions?.escapeChar,typeof t?.csvParserOptions?.commentChar<"u"?l.commentChar=t?.csvParserOptions?.commentChar:typeof n?.csvParserOptions?.commentChar<"u"?l.commentChar=n?.csvParserOptions?.commentChar:l.commentChar=i.csvParserOptions?.commentChar;const u=new Map,c=new Map;if(e.references)for(const p of e.references)u.set(p.key,p),p.origin&&u.set(p.origin,p);if(e.properties)for(const p of e.properties)c.set(p.key,p),p.origin&&c.set(p.origin,p);const d=t?.keyProperty??e.keyProperty??"key",f=Array.isArray(d)?d:[d],h=new Set(f);return{delimiter:l?.delimiter,quoteChar:l?.quoteChar,escapeChar:l?.escapeChar,comments:l.commentChar,dynamicTyping:!1,header:!0,skipEmptyLines:!0,transformHeader:p=>{const y=p?.trim().replace(/"/g,"");return s&&y&&s.push(y),y},transform:function(p,y){if(typeof y>"u"||h.has(y))return p;if(p==="null")return null;if(p===""||typeof p>"u")return;const v=m=>{if(!o)return;const M=o[y];M?M.count+=1:o[y]={rawValue:p,expected:m,count:1}},g=u.get(y);if(g)if(p[0]==="{"||p[0]==="[")try{return JSON.parse(p)}catch(m){a.error("Failed to parse JSON in CSV reference field",m,{header:y,value:p});return}else return g.type==="singleValued"?p:p?.length>0&&g.type==="multiValued"?Bn(p,g?.separator):p;const k=c.get(y);if(!(!e.autoGenerateProperties&&!k))switch(k?.type){case"string":return p;case"int":{const m=parseInt(p,10);if(isNaN(m)){v("int");return}return m}case"float":{const m=parseFloat(p);if(isNaN(m)){v("float");return}return m}case"boolean":if(p==="true")return!0;if(p==="false")return!1;v("boolean");return;case"json":try{return p=p.replace(/[\x00-\x1F\x7F-\x9F]/g,""),JSON.parse(p)}catch(m){a.error("Failed to parse JSON in CSV property field",m,{header:y,value:p}),v("json");return}case"Array<string>":case"Array<int>":case"Array<float>":case"Array<date>":if(p&&typeof p=="string"&&p[0]==="[")try{return JSON.parse(p)}catch{v(k.type);return}if(p&&typeof p=="string")return Bn(p,k?.separator);v(k.type);return;default:return p}}}}getJsonFromCSVString(e,t,s){return this.getJsonFromCSVStringWithMetadata(e,t,s).data}getJsonFromCSVStringWithMetadata(e,t,s){const o=[],n={},i=this.getParserConfig(t,s.options,o,n);return{data:new ev().parse(e,i),sourceColumns:o,coercionFailureSamples:n}}}var Gn=typeof global=="object"&&global&&global.Object===Object&&global,rv=typeof self=="object"&&self&&self.Object===Object&&self,X=Gn||rv||Function("return this")(),fe=X.Symbol,Vn=Object.prototype,sv=Vn.hasOwnProperty,ov=Vn.toString,pt=fe?fe.toStringTag:void 0;function nv(r){var e=sv.call(r,pt),t=r[pt];try{r[pt]=void 0;var s=!0}catch{}var o=ov.call(r);return s&&(e?r[pt]=t:delete r[pt]),o}var iv=Object.prototype,av=iv.toString;function lv(r){return av.call(r)}var uv="[object Null]",cv="[object Undefined]",Un=fe?fe.toStringTag:void 0;function Ge(r){return r==null?r===void 0?cv:uv:Un&&Un in Object(r)?nv(r):lv(r)}function De(r){return r!=null&&typeof r=="object"}var dv="[object Symbol]";function Wr(r){return typeof r=="symbol"||De(r)&&Ge(r)==dv}function Nn(r,e){for(var t=-1,s=r==null?0:r.length,o=Array(s);++t<s;)o[t]=e(r[t],t,r);return o}var Ve=Array.isArray,zn=fe?fe.prototype:void 0,Ln=zn?zn.toString:void 0;function Wn(r){if(typeof r=="string")return r;if(Ve(r))return Nn(r,Wn)+"";if(Wr(r))return Ln?Ln.call(r):"";var e=r+"";return e=="0"&&1/r==-1/0?"-0":e}function Gt(r){var e=typeof r;return r!=null&&(e=="object"||e=="function")}function Hn(r){return r}var fv="[object AsyncFunction]",pv="[object Function]",hv="[object GeneratorFunction]",yv="[object Proxy]";function Jn(r){if(!Gt(r))return!1;var e=Ge(r);return e==pv||e==hv||e==fv||e==yv}var Hr=X["__core-js_shared__"],Zn=(function(){var r=/[^.]+$/.exec(Hr&&Hr.keys&&Hr.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""})();function gv(r){return!!Zn&&Zn in r}var mv=Function.prototype,vv=mv.toString;function Pe(r){if(r!=null){try{return vv.call(r)}catch{}try{return r+""}catch{}}return""}var bv=/[\\^$.*+?()[\]{}|]/g,kv=/^\[object .+?Constructor\]$/,wv=Function.prototype,Av=Object.prototype,$v=wv.toString,Cv=Av.hasOwnProperty,Dv=RegExp("^"+$v.call(Cv).replace(bv,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Pv(r){if(!Gt(r)||gv(r))return!1;var e=Jn(r)?Dv:kv;return e.test(Pe(r))}function _v(r,e){return r?.[e]}function _e(r,e){var t=_v(r,e);return Pv(t)?t:void 0}var Jr=_e(X,"WeakMap"),Yn=Object.create,xv=(function(){function r(){}return function(e){if(!Gt(e))return{};if(Yn)return Yn(e);r.prototype=e;var t=new r;return r.prototype=void 0,t}})();function Ev(r,e,t){switch(t.length){case 0:return r.call(e);case 1:return r.call(e,t[0]);case 2:return r.call(e,t[0],t[1]);case 3:return r.call(e,t[0],t[1],t[2])}return r.apply(e,t)}var Sv=800,jv=16,Mv=Date.now;function Rv(r){var e=0,t=0;return function(){var s=Mv(),o=jv-(s-t);if(t=s,o>0){if(++e>=Sv)return arguments[0]}else e=0;return r.apply(void 0,arguments)}}function Iv(r){return function(){return r}}var Vt=(function(){try{var r=_e(Object,"defineProperty");return r({},"",{}),r}catch{}})(),Tv=Vt?function(r,e){return Vt(r,"toString",{configurable:!0,enumerable:!1,value:Iv(e),writable:!0})}:Hn,Ov=Rv(Tv);function Kv(r,e){for(var t=-1,s=r==null?0:r.length;++t<s&&e(r[t],t,r)!==!1;);return r}function Fv(r,e,t,s){for(var o=r.length,n=t+-1;++n<o;)if(e(r[n],n,r))return n;return-1}function qv(r){return r!==r}function Qv(r,e,t){for(var s=t-1,o=r.length;++s<o;)if(r[s]===e)return s;return-1}function Bv(r,e,t){return e===e?Qv(r,e,t):Fv(r,qv,t)}function Gv(r,e){var t=r==null?0:r.length;return!!t&&Bv(r,e,0)>-1}var Vv=9007199254740991,Uv=/^(?:0|[1-9]\d*)$/;function Nv(r,e){var t=typeof r;return e=e??Vv,!!e&&(t=="number"||t!="symbol"&&Uv.test(r))&&r>-1&&r%1==0&&r<e}function zv(r,e,t){e=="__proto__"&&Vt?Vt(r,e,{configurable:!0,enumerable:!0,value:t,writable:!0}):r[e]=t}function Xn(r,e){return r===e||r!==r&&e!==e}var Lv=Object.prototype,Wv=Lv.hasOwnProperty;function Hv(r,e,t){var s=r[e];(!(Wv.call(r,e)&&Xn(s,t))||t===void 0&&!(e in r))&&zv(r,e,t)}var ei=Math.max;function Jv(r,e,t){return e=ei(e===void 0?r.length-1:e,0),function(){for(var s=arguments,o=-1,n=ei(s.length-e,0),i=Array(n);++o<n;)i[o]=s[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=s[o];return a[e]=t(i),Ev(r,this,a)}}function Zv(r,e){return Ov(Jv(r,e,Hn),r+"")}var Yv=9007199254740991;function ti(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=Yv}function ri(r){return r!=null&&ti(r.length)&&!Jn(r)}var Xv=Object.prototype;function si(r){var e=r&&r.constructor,t=typeof e=="function"&&e.prototype||Xv;return r===t}function eb(r,e){for(var t=-1,s=Array(r);++t<r;)s[t]=e(t);return s}var tb="[object Arguments]";function oi(r){return De(r)&&Ge(r)==tb}var ni=Object.prototype,rb=ni.hasOwnProperty,sb=ni.propertyIsEnumerable,ob=oi((function(){return arguments})())?oi:function(r){return De(r)&&rb.call(r,"callee")&&!sb.call(r,"callee")};function nb(){return!1}var ii=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ai=ii&&typeof module=="object"&&module&&!module.nodeType&&module,ib=ai&&ai.exports===ii,li=ib?X.Buffer:void 0,ab=li?li.isBuffer:void 0,ui=ab||nb,lb="[object Arguments]",ub="[object Array]",cb="[object Boolean]",db="[object Date]",fb="[object Error]",pb="[object Function]",hb="[object Map]",yb="[object Number]",gb="[object Object]",mb="[object RegExp]",vb="[object Set]",bb="[object String]",kb="[object WeakMap]",wb="[object ArrayBuffer]",Ab="[object DataView]",$b="[object Float32Array]",Cb="[object Float64Array]",Db="[object Int8Array]",Pb="[object Int16Array]",_b="[object Int32Array]",xb="[object Uint8Array]",Eb="[object Uint8ClampedArray]",Sb="[object Uint16Array]",jb="[object Uint32Array]",P={};P[$b]=P[Cb]=P[Db]=P[Pb]=P[_b]=P[xb]=P[Eb]=P[Sb]=P[jb]=!0,P[lb]=P[ub]=P[wb]=P[cb]=P[Ab]=P[db]=P[fb]=P[pb]=P[hb]=P[yb]=P[gb]=P[mb]=P[vb]=P[bb]=P[kb]=!1;function Mb(r){return De(r)&&ti(r.length)&&!!P[Ge(r)]}function Zr(r){return function(e){return r(e)}}var ci=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ht=ci&&typeof module=="object"&&module&&!module.nodeType&&module,Rb=ht&&ht.exports===ci,Yr=Rb&&Gn.process,Ue=(function(){try{var r=ht&&ht.require&&ht.require("util").types;return r||Yr&&Yr.binding&&Yr.binding("util")}catch{}})(),di=Ue&&Ue.isTypedArray,Ib=di?Zr(di):Mb,Tb=Object.prototype,Ob=Tb.hasOwnProperty;function Kb(r,e){var t=Ve(r),s=!t&&ob(r),o=!t&&!s&&ui(r),n=!t&&!s&&!o&&Ib(r),i=t||s||o||n,a=i?eb(r.length,String):[],l=a.length;for(var u in r)Ob.call(r,u)&&!(i&&(u=="length"||o&&(u=="offset"||u=="parent")||n&&(u=="buffer"||u=="byteLength"||u=="byteOffset")||Nv(u,l)))&&a.push(u);return a}function fi(r,e){return function(t){return r(e(t))}}var Fb=fi(Object.keys,Object),qb=Object.prototype,Qb=qb.hasOwnProperty;function Bb(r){if(!si(r))return Fb(r);var e=[];for(var t in Object(r))Qb.call(r,t)&&t!="constructor"&&e.push(t);return e}function Gb(r){return ri(r)?Kb(r):Bb(r)}var Vb=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ub=/^\w*$/;function Nb(r,e){if(Ve(r))return!1;var t=typeof r;return t=="number"||t=="symbol"||t=="boolean"||r==null||Wr(r)?!0:Ub.test(r)||!Vb.test(r)||e!=null&&r in Object(e)}var yt=_e(Object,"create");function zb(){this.__data__=yt?yt(null):{},this.size=0}function Lb(r){var e=this.has(r)&&delete this.__data__[r];return this.size-=e?1:0,e}var Wb="__lodash_hash_undefined__",Hb=Object.prototype,Jb=Hb.hasOwnProperty;function Zb(r){var e=this.__data__;if(yt){var t=e[r];return t===Wb?void 0:t}return Jb.call(e,r)?e[r]:void 0}var Yb=Object.prototype,Xb=Yb.hasOwnProperty;function ek(r){var e=this.__data__;return yt?e[r]!==void 0:Xb.call(e,r)}var tk="__lodash_hash_undefined__";function rk(r,e){var t=this.__data__;return this.size+=this.has(r)?0:1,t[r]=yt&&e===void 0?tk:e,this}function xe(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var s=r[e];this.set(s[0],s[1])}}xe.prototype.clear=zb,xe.prototype.delete=Lb,xe.prototype.get=Zb,xe.prototype.has=ek,xe.prototype.set=rk;function sk(){this.__data__=[],this.size=0}function Ut(r,e){for(var t=r.length;t--;)if(Xn(r[t][0],e))return t;return-1}var ok=Array.prototype,nk=ok.splice;function ik(r){var e=this.__data__,t=Ut(e,r);if(t<0)return!1;var s=e.length-1;return t==s?e.pop():nk.call(e,t,1),--this.size,!0}function ak(r){var e=this.__data__,t=Ut(e,r);return t<0?void 0:e[t][1]}function lk(r){return Ut(this.__data__,r)>-1}function uk(r,e){var t=this.__data__,s=Ut(t,r);return s<0?(++this.size,t.push([r,e])):t[s][1]=e,this}function ae(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var s=r[e];this.set(s[0],s[1])}}ae.prototype.clear=sk,ae.prototype.delete=ik,ae.prototype.get=ak,ae.prototype.has=lk,ae.prototype.set=uk;var gt=_e(X,"Map");function ck(){this.size=0,this.__data__={hash:new xe,map:new(gt||ae),string:new xe}}function dk(r){var e=typeof r;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?r!=="__proto__":r===null}function Nt(r,e){var t=r.__data__;return dk(e)?t[typeof e=="string"?"string":"hash"]:t.map}function fk(r){var e=Nt(this,r).delete(r);return this.size-=e?1:0,e}function pk(r){return Nt(this,r).get(r)}function hk(r){return Nt(this,r).has(r)}function yk(r,e){var t=Nt(this,r),s=t.size;return t.set(r,e),this.size+=t.size==s?0:1,this}function le(r){var e=-1,t=r==null?0:r.length;for(this.clear();++e<t;){var s=r[e];this.set(s[0],s[1])}}le.prototype.clear=ck,le.prototype.delete=fk,le.prototype.get=pk,le.prototype.has=hk,le.prototype.set=yk;var gk="Expected a function";function Xr(r,e){if(typeof r!="function"||e!=null&&typeof e!="function")throw new TypeError(gk);var t=function(){var s=arguments,o=e?e.apply(this,s):s[0],n=t.cache;if(n.has(o))return n.get(o);var i=r.apply(this,s);return t.cache=n.set(o,i)||n,i};return t.cache=new(Xr.Cache||le),t}Xr.Cache=le;var mk=500;function vk(r){var e=Xr(r,function(s){return t.size===mk&&t.clear(),s}),t=e.cache;return e}var bk=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,kk=/\\(\\)?/g,wk=vk(function(r){var e=[];return r.charCodeAt(0)===46&&e.push(""),r.replace(bk,function(t,s,o,n){e.push(o?n.replace(kk,"$1"):s||t)}),e});function Ak(r){return r==null?"":Wn(r)}function $k(r,e){return Ve(r)?r:Nb(r,e)?[r]:wk(Ak(r))}function Ck(r){if(typeof r=="string"||Wr(r))return r;var e=r+"";return e=="0"&&1/r==-1/0?"-0":e}function Dk(r,e){e=$k(e,r);for(var t=0,s=e.length;r!=null&&t<s;)r=r[Ck(e[t++])];return t&&t==s?r:void 0}function Pk(r,e,t){var s=r==null?void 0:Dk(r,e);return s===void 0?t:s}function _k(r,e){for(var t=-1,s=e.length,o=r.length;++t<s;)r[o+t]=e[t];return r}var xk=fi(Object.getPrototypeOf,Object);function Ek(){this.__data__=new ae,this.size=0}function Sk(r){var e=this.__data__,t=e.delete(r);return this.size=e.size,t}function jk(r){return this.__data__.get(r)}function Mk(r){return this.__data__.has(r)}var Rk=200;function Ik(r,e){var t=this.__data__;if(t instanceof ae){var s=t.__data__;if(!gt||s.length<Rk-1)return s.push([r,e]),this.size=++t.size,this;t=this.__data__=new le(s)}return t.set(r,e),this.size=t.size,this}function Ne(r){var e=this.__data__=new ae(r);this.size=e.size}Ne.prototype.clear=Ek,Ne.prototype.delete=Sk,Ne.prototype.get=jk,Ne.prototype.has=Mk,Ne.prototype.set=Ik;var pi=typeof exports=="object"&&exports&&!exports.nodeType&&exports,hi=pi&&typeof module=="object"&&module&&!module.nodeType&&module,Tk=hi&&hi.exports===pi,yi=Tk?X.Buffer:void 0;yi&&yi.allocUnsafe;function Ok(r,e){return r.slice()}function Kk(r,e){for(var t=-1,s=r==null?0:r.length,o=0,n=[];++t<s;){var i=r[t];e(i,t,r)&&(n[o++]=i)}return n}function Fk(){return[]}var qk=Object.prototype,Qk=qk.propertyIsEnumerable,gi=Object.getOwnPropertySymbols,Bk=gi?function(r){return r==null?[]:(r=Object(r),Kk(gi(r),function(e){return Qk.call(r,e)}))}:Fk;function Gk(r,e,t){var s=e(r);return Ve(r)?s:_k(s,t(r))}function Vk(r){return Gk(r,Gb,Bk)}var es=_e(X,"DataView"),ts=_e(X,"Promise"),rs=_e(X,"Set"),mi="[object Map]",Uk="[object Object]",vi="[object Promise]",bi="[object Set]",ki="[object WeakMap]",wi="[object DataView]",Nk=Pe(es),zk=Pe(gt),Lk=Pe(ts),Wk=Pe(rs),Hk=Pe(Jr),ue=Ge;(es&&ue(new es(new ArrayBuffer(1)))!=wi||gt&&ue(new gt)!=mi||ts&&ue(ts.resolve())!=vi||rs&&ue(new rs)!=bi||Jr&&ue(new Jr)!=ki)&&(ue=function(r){var e=Ge(r),t=e==Uk?r.constructor:void 0,s=t?Pe(t):"";if(s)switch(s){case Nk:return wi;case zk:return mi;case Lk:return vi;case Wk:return bi;case Hk:return ki}return e});var Jk=Object.prototype,Zk=Jk.hasOwnProperty;function Yk(r){var e=r.length,t=new r.constructor(e);return e&&typeof r[0]=="string"&&Zk.call(r,"index")&&(t.index=r.index,t.input=r.input),t}var Ai=X.Uint8Array;function ss(r){var e=new r.constructor(r.byteLength);return new Ai(e).set(new Ai(r)),e}function Xk(r,e){var t=ss(r.buffer);return new r.constructor(t,r.byteOffset,r.byteLength)}var ew=/\w*$/;function tw(r){var e=new r.constructor(r.source,ew.exec(r));return e.lastIndex=r.lastIndex,e}var $i=fe?fe.prototype:void 0,Ci=$i?$i.valueOf:void 0;function rw(r){return Ci?Object(Ci.call(r)):{}}function sw(r,e){var t=ss(r.buffer);return new r.constructor(t,r.byteOffset,r.length)}var ow="[object Boolean]",nw="[object Date]",iw="[object Map]",aw="[object Number]",lw="[object RegExp]",uw="[object Set]",cw="[object String]",dw="[object Symbol]",fw="[object ArrayBuffer]",pw="[object DataView]",hw="[object Float32Array]",yw="[object Float64Array]",gw="[object Int8Array]",mw="[object Int16Array]",vw="[object Int32Array]",bw="[object Uint8Array]",kw="[object Uint8ClampedArray]",ww="[object Uint16Array]",Aw="[object Uint32Array]";function $w(r,e,t){var s=r.constructor;switch(e){case fw:return ss(r);case ow:case nw:return new s(+r);case pw:return Xk(r);case hw:case yw:case gw:case mw:case vw:case bw:case kw:case ww:case Aw:return sw(r);case iw:return new s;case aw:case cw:return new s(r);case lw:return tw(r);case uw:return new s;case dw:return rw(r)}}function Cw(r){return typeof r.constructor=="function"&&!si(r)?xv(xk(r)):{}}var Dw="[object Map]";function Pw(r){return De(r)&&ue(r)==Dw}var Di=Ue&&Ue.isMap,_w=Di?Zr(Di):Pw,xw="[object Set]";function Ew(r){return De(r)&&ue(r)==xw}var Pi=Ue&&Ue.isSet,Sw=Pi?Zr(Pi):Ew,_i="[object Arguments]",jw="[object Array]",Mw="[object Boolean]",Rw="[object Date]",Iw="[object Error]",xi="[object Function]",Tw="[object GeneratorFunction]",Ow="[object Map]",Kw="[object Number]",Ei="[object Object]",Fw="[object RegExp]",qw="[object Set]",Qw="[object String]",Bw="[object Symbol]",Gw="[object WeakMap]",Vw="[object ArrayBuffer]",Uw="[object DataView]",Nw="[object Float32Array]",zw="[object Float64Array]",Lw="[object Int8Array]",Ww="[object Int16Array]",Hw="[object Int32Array]",Jw="[object Uint8Array]",Zw="[object Uint8ClampedArray]",Yw="[object Uint16Array]",Xw="[object Uint32Array]",$={};$[_i]=$[jw]=$[Vw]=$[Uw]=$[Mw]=$[Rw]=$[Nw]=$[zw]=$[Lw]=$[Ww]=$[Hw]=$[Ow]=$[Kw]=$[Ei]=$[Fw]=$[qw]=$[Qw]=$[Bw]=$[Jw]=$[Zw]=$[Yw]=$[Xw]=!0,$[Iw]=$[xi]=$[Gw]=!1;function zt(r,e,t,s,o,n){var i;if(i!==void 0)return i;if(!Gt(r))return r;var a=Ve(r);if(a)i=Yk(r);else{var l=ue(r),u=l==xi||l==Tw;if(ui(r))return Ok(r);if(l==Ei||l==_i||u&&!o)i=u?{}:Cw(r);else{if(!$[l])return o?r:{};i=$w(r,l)}}n||(n=new Ne);var c=n.get(r);if(c)return c;n.set(r,i),Sw(r)?r.forEach(function(h){i.add(zt(h,e,t,h,r,n))}):_w(r)&&r.forEach(function(h,p){i.set(p,zt(h,e,t,p,r,n))});var d=Vk,f=a?void 0:d(r);return Kv(f||r,function(h,p){f&&(p=h,h=r[p]),Hv(i,p,zt(h,e,t,p,r,n))}),i}var eA=1,tA=4;function mt(r){return zt(r,eA|tA)}var rA="__lodash_hash_undefined__";function sA(r){return this.__data__.set(r,rA),this}function oA(r){return this.__data__.has(r)}function Lt(r){var e=-1,t=r==null?0:r.length;for(this.__data__=new le;++e<t;)this.add(r[e])}Lt.prototype.add=Lt.prototype.push=sA,Lt.prototype.has=oA;function Si(r,e){return r.has(e)}function nA(r){return De(r)&&ri(r)}var iA=Math.min;function aA(r,e,t){for(var s=Gv,o=r[0].length,n=r.length,i=n,a=Array(n),l=1/0,u=[];i--;){var c=r[i];l=iA(c.length,l),a[i]=o>=120&&c.length>=120?new Lt(i&&c):void 0}c=r[0];var d=-1,f=a[0];e:for(;++d<o&&u.length<l;){var h=c[d],p=h;if(h=h!==0?h:0,!(f?Si(f,p):s(u,p))){for(i=n;--i;){var y=a[i];if(!(y?Si(y,p):s(r[i],p)))continue e}f&&f.push(p),u.push(h)}}return u}function lA(r){return nA(r)?r:[]}var ji=Zv(function(r){var e=Nn(r,lA);return e.length&&e[0]===r[0]?aA(e):[]});class Mi{context="";total=0;totalItems=[];processedItems=new Set;downloadedItems=new Set;failedItems=new Set;remainingItems=new Set;skippedItems=[];run;processed=0;remaining=0;progress=0;currentItem;constructor(){}init(e,t){return this.total=e.length,this.totalItems=[...e],this.remaining=e.length,this.remainingItems=new Set(e),this.skippedItems=t?.skipped??[],this.run=t?.run,this.getProgress()}update(e,t,s,o){const n=mt(e);return n.success=t,o&&(n.status=o),t?this.downloadedItems.add(n):this.failedItems.add(n),this.currentItem=n,this.context=s,this.processed++,this.remaining--,this.progress=Math.round(this.processed*100/this.total),this.currentItem=n,this.processedItems.add(n),this.remainingItems.delete(e),this.getProgress()}getProgress(){return{total:this.total,processed:this.processed,remaining:this.remaining,downloadedItems:Array.from(this.downloadedItems.values()),failedItems:Array.from(this.failedItems.values()),progress:this.progress,context:this.context,currentItem:this.currentItem,totalItems:this.totalItems,processedItems:Array.from(this.processedItems.values()),remainingItems:Array.from(this.remainingItems.values()),skippedItems:this.skippedItems,run:this.run}}}function uA(r,e){for(const t of e)if(Array.isArray(t)){if(t.every(s=>r.includes(s)))return!0}else if(r.includes(t))return!0;return!1}function cA(r,e){return Xm(r).variables.map(t=>t.name).filter(t=>Pk(e,t)===void 0)}function Ri(r,e,t){const s={applicationKey:t?.applicationKey,resourceTags:t?.resourceTags,environmentKeys:t?.environmentKeys},o=r?.resources??[],n=Ym(o),i=[],a=[],l=Array.isArray(t?.resourceTags)&&t.resourceTags.length>0;return o.forEach((u,c)=>{if(l){if(!Array.isArray(u.tags)||!u.tags.length){a.push({resource:u,reason:"no-tags",id:n[c]});return}if(!uA(u.tags,t.resourceTags)){a.push({resource:u,reason:"tag-mismatch",id:n[c]});return}}const d=u.url??"",f=cA(d,e),h={...u,id:n[c],rawUrl:d,url:Bt(d,{...e})};f.length&&(h.unresolvedVariables=f),i.push(h)}),{scheduled:i,skipped:a,variables:e,run:s}}var dA=Object.defineProperty,fA=Object.getOwnPropertyDescriptor,Ii=(r,e,t,s)=>{for(var o=fA(e,t),n=r.length-1,i;n>=0;n--)(i=r[n])&&(o=i(e,t,o)||o);return o&&dA(e,t,o),o};const pA={missingModelHandling:{autoGenerateProperties:!0},defaultDataContainerUpdateType:"set",csvParserOptions:{delimiter:"",quoteChar:'"',escapeChar:'"',commentChar:void 0}};let os=class{key;core;cdRef=new Hm;log=Nr.child({prefix:"AppLoader"});registeredTransformers=[];options=pA;csvParser=new tv(this);currentConfig;globalVariables=new Map;defaultVariables=new Map;progressListeners=new Set;currentProcessOptions;currentContext="";progressHandler=new Mi;constructor(){this.initDefaultVariables()}destroy(){this.core=null,this.cdRef=null,this.csvParser=null,this.progressListeners=null,this.progressHandler=null}initDefaultVariables(){this.defaultVariables.set("projectId",{key:"projectId",value:void 0,description:"Your dcupl console project id"}),this.defaultVariables.set("apiKey",{key:"apiKey",value:void 0,description:"Your dcupl console project API key"}),this.defaultVariables.set("version",{key:"version",value:"draft",description:"The version of uploaded files to the dcupl CDN - draft/published/..."}),this.defaultVariables.set("cdnBaseUrl",{key:"cdnBaseUrl",value:"https://cdn.dcupl.com/files/projects",description:"The url to your dcupl folder - might be the dcupl CDN or any other "}),this.defaultVariables.set("baseUrl",{key:"baseUrl",value:"${cdnBaseUrl}/${projectId}/${version}",description:"The base url to your hosted models and data files"}),this.defaultVariables.set("modelUrl",{key:"modelUrl",value:"${baseUrl}/models",description:"The url to the your model files"}),this.defaultVariables.set("dataUrl",{key:"dataUrl",value:"${baseUrl}/data",description:"The url to the your data files"}),this.defaultVariables.set("transformerUrl",{key:"transformerUrl",value:"${baseUrl}/transformers",description:"The url to the your data files"}),this.defaultVariables.set("loaderFileName",{key:"loaderFileName",value:"dcupl.lc.json",description:"The file name of the loader json"}),this.defaultVariables.set("cdnVersion",{key:"cdnVersion",value:void 0,description:"The file-version of the CDN data"}),this.defaultVariables.set("consoleApiUrl",{key:"consoleApiUrl",value:"https://api.dcupl.com",description:"The dcupl console API Url"})}resources={get:r=>this.currentConfig?.resources.find(e=>e.key===r),getAll:()=>this.currentConfig?.resources||[],getWithTag:r=>this.currentConfig?.resources.filter(e=>e.tags?.includes(r))||[],set:r=>{this.currentConfig.resources=r},add:r=>{this.currentConfig.resources.push(r)},delete:r=>{const e=this.currentConfig.resources.findIndex(t=>t.key===r);e>-1&&this.currentConfig.resources.splice(e,1)},plan:r=>{const{config:e,options:t,variables:s}=this.resolveRunContext(r);return Ri(e,s,t)}};variables={get:(r,e)=>{const t=this.currentConfig?.environments?.filter(s=>s.key===e);return this.evaluateVariables(t,this.currentProcessOptions).find(s=>s.key===r)},getAll:r=>{const e=this.currentConfig?.environments?.filter(t=>t.key===r);return this.evaluateVariables(e,this.currentProcessOptions)},getAllAsObject:r=>{const e=this.currentConfig?.environments?.filter(t=>t.key===r);return this.getEvaluatedVariablesAsRecord(e,this.currentProcessOptions)},default:{get:r=>this.defaultVariables.get(r),getAll:()=>Array.from(this.defaultVariables.values())},environment:{get:(r,e)=>{if(!r)return;const t=this.currentConfig?.environments?.find(s=>s.key===r);if(t)return t.variables?.find(s=>s.key===e)},getAll:r=>this.currentConfig?.environments?.find(e=>e.key===r)?.variables||[]},process:{get:r=>this.currentProcessOptions?.variables?.find(e=>e.key===r),getAll:()=>this.currentProcessOptions?.variables||[]},global:{get:r=>this.globalVariables.get(r),getAll:()=>Array.from(this.globalVariables.values()),set:(r,e)=>{this.globalVariables.set(r,{key:r,value:e})},delete:r=>{this.globalVariables.delete(r)}}};transformers={get:r=>this.registeredTransformers.filter(e=>ji(e.applyTo,r.appyTo).length>0),getAll:()=>this.registeredTransformers,set:r=>{this.transformers.remove(r.key),this.registeredTransformers.push(r)},remove:r=>{const e=this.registeredTransformers.findIndex(t=>t.key===r);e>-1&&this.registeredTransformers.splice(e,1)}};config={get:()=>mt(this.currentConfig),set:r=>{this.currentConfig=mt(r)},fetch:async r=>this.fetchConfig(r)};async fetchConfig(r){if(!this.core)throw this.log.error("dcupl not connected. Did you add your loader to dcupl? -> dcupl.addRunner(loader)"),new Error;let e;r?.baseUrl&&this.defaultVariables.set("baseUrl",{key:"baseUrl",value:String(r.baseUrl)}),r?.loaderFileName&&this.defaultVariables.set("loaderFileName",{key:"loaderFileName",value:String(r.loaderFileName)});const t=this.variables.get("baseUrl")?.value;if(t&&this.isDcuplCdn(t))await this.setCdnVersion(),e=await this.loadConfigFromApi();else{const s=this.variables.get("loaderFileName")?.value,o=`${t}/${s}`;e=await this.loadConfigFromUrl(o,r?.headers)}if(this.isValidConfig(e))return r?.skipApply||this.config.set(e),e;throw new Error("Invalid Loader Configuration")}isValidConfig(r){return!!r}async loadConfigFromUrl(r,e){try{const t={};e&&(t.headers=e.reduce((o,n)=>(o[n.key]=n.value,o),{}));const s=await fetch(r,t);if(!s.ok)throw new Error(`Failed to fetch loader configuration from ${r}`);return s.json()}catch(t){this.log.error("Could not fetch loader configuration",t,{url:r});return}}async loadConfigFromApi(){const r=this.variables.get("baseUrl")?.value,e=this.variables.get("loaderFileName")?.value,t=this.variables.get("cdnVersion")?.value,s=this.variables.get("apiKey")?.value;try{let o=`${r}/${e}`;this.isDcuplCdn(o)&&(t&&(o=this.appendSearchParamToUrl(o,"v",String(t))),s&&(o=this.appendSearchParamToUrl(o,"api-key",s)));const n=await fetch(o);if(!n.ok)throw new Error(`Failed to fetch loader configuration from ${o}`);return n.json()}catch(o){this.log.error("Could not fetch loader configuration. Are you sure your projectId + apiKey are correct?",o,{baseUrl:r,loaderFileName:e});return}}appendSearchParamToUrl(r,e,t){const s=r.includes("?")?"&":"?";return`${r}${s}${e}=${t}`}async setCdnVersion(){let r;try{const e=this.variables.get("consoleApiUrl")?.value,t=this.variables.get("projectId")?.value,s=this.variables.get("version")?.value;r=`${e}/projects/${t}/files/versions/${s}/status`;const o=await(await fetch(r)).json();o&&o.changedAt&&this.defaultVariables.set("cdnVersion",{key:"cdnVersion",value:String(o.changedAt)})}catch(e){this.log.error("Could not fetch version status",e,{url:r})}}async process(r){if(!this.currentConfig)throw new Error("There is no config present. Make sure to call loader.setConfig(..) or loader.fetchConfig(...)");this.currentContext=zr();const{config:e,options:t,environments:s,variables:o}=this.resolveRunContext(r),n=this.getHeaderConfigs(s),i=this.getQueryParamConfigs(s),a=Ri(e,o,t),l=this.getLoaderOptions(e,t),u=await this.fetchResources(a,o,l,n,i);return this.currentProcessOptions=t,u}getHeaderConfigs(r){if(!r)return[];const e=[];return r.forEach(t=>{t.headers&&e.push(...t.headers)}),e}getQueryParamConfigs(r){if(!r)return[];const e=[];return r.forEach(t=>{t.queryParams&&e.push(...t.queryParams)}),e}getLoaderOptions(r,e){return e?.options?Object.assign({},this.options,e.options):r?.options?Object.assign({},this.options,r.options):Object.assign({},this.options)}resolveRunContext(r){if(!this.currentConfig)throw new Error("There is no config present. Make sure to call loader.setConfig(..) or loader.fetchConfig(...)");const e=mt(r),t=mt(this.currentConfig);if(e?.applicationKey){const n=this.getAppPreset(t,e);if(!n)throw new Error(`The applicationKey ${e.applicationKey} does not exist`);e.resourceTags=e.resourceTags||n?.resourceTags,e.variables=e.variables||n?.variables}const s=this.getEnvironments(t,e),o=this.getEvaluatedVariablesAsRecord(s,e);return{config:t,options:e,environments:s,variables:o}}evaluateVariables(r,e){const t=new Map;this.defaultVariables&&this.defaultVariables.forEach(n=>{t.set(n.key,n)}),r?.forEach(n=>{n?.variables&&n.variables.forEach(i=>{t.set(i.key,i)})}),e?.variables&&e.variables.forEach(n=>{t.set(n.key,n)}),this.globalVariables&&this.globalVariables.forEach(n=>{t.set(n.key,n)});const s=Array.from(t.values()).map(n=>({...n})),o={};for(const n of s)o[n.key]=n.value||"";for(const n of s)n.value=Bt(n.value,o);return s}getEvaluatedVariablesAsRecord(r,e){const t=this.evaluateVariables(r,e),s={};for(const o of t)s[o.key]=o.value||"";return s}getEnvironments(r,e){if(!(!r.environments||!r.environments[0])&&e&&e.environmentKeys&&e.environmentKeys.length>0)return r.environments.filter(t=>e.environmentKeys.indexOf(t.key)>-1)}getAppPreset(r,e){if(!(!r.applications||!r.applications[0])&&e?.applicationKey)return r.applications?.find(t=>t.key===e.applicationKey)}getHeaderForUrl(r,e,t){if(!t||!t.length||!r.tags?.length)return;const s=[];t?.forEach(n=>{if(!n.tags?.length){this.isValidCondition(n,e)&&s.push(n);return}n.tags.find(i=>r.tags?.includes(i))&&this.isValidCondition(n,e)&&s.push(n)});const o={};if(s.forEach(n=>{const i=Bt(n.value,{...e});o[n.key]=i}),Object.keys(o).length!==0)return o}getQueryParamsForUrl(r,e,t){const s=[];if(t?.forEach(o=>{if(!o.tags?.length){this.isValidCondition(o,e)&&s.push(o);return}o.tags.find(n=>r.tags?.includes(n))&&this.isValidCondition(o,e)&&s.push(o)}),this.isDcuplCdn(r.url)){const o=e.cdnVersion;o&&s.push({key:"v",value:o}),e.apiKey&&s?.push({key:"api-key",value:e.apiKey})}return s.map(o=>(o.value=Bt(o.value,{...e}),o))}isDcuplCdn(r){let e;try{e=new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(r)?r:`https://${r}`).hostname.toLowerCase()}catch{return!1}return e.endsWith(".dcupl.com")&&e.split(".").some(t=>/^(dev-)?cdn\d*$/.test(t))}isValidCondition(r,e){return r.condition?.applyIfVariableHasValue?typeof e[r.condition?.applyIfVariableHasValue]<"u"&&e[r.condition?.applyIfVariableHasValue]!=="":!0}async handleScriptResources(r,e,t,s){return await Promise.all(r.map(async o=>{try{const n=o.scriptKey;if(this.core.scriptController.hasScript(n)){const l=this.progressHandler.update(o,!0,"script");return this.updateProgressListeners(l),null}const i=await this.fetchScript(o,e,t,s);this.core.scriptController.setScript(n,i);const a=this.progressHandler.update(o,!0,"script");this.updateProgressListeners(a);return}catch(n){this.log.error("Failed to load script resource",n,{url:o.url,scriptKey:o.scriptKey});const i={title:o.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:o,description:n?.message};this.setError(i);const a=this.progressHandler.update(o,!1,"script");this.updateProgressListeners(a);return}})),!0}async handleOperatorResources(r,e,t,s){return await Promise.all(r.map(async o=>{try{const n=o.operator;if(this.core.queryManager.registeredCustomOperator.has(n)){const l=this.progressHandler.update(o,!0,"operator");return this.updateProgressListeners(l),null}const i=await this.fetchJavascriptFile(o,e,t,s);this.core.query.registerCustomOperator(n,i);const a=this.progressHandler.update(o,!0,"operator");this.updateProgressListeners(a);return}catch(n){this.log.error("Failed to load operator resource",n,{url:o.url,operator:o.operator});const i={title:o.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:o,description:n?.message};this.setError(i);const a=this.progressHandler.update(o,!1,"operator");this.updateProgressListeners(a);return}})),!0}async handleTransformerResources(r,e,t,s){const o=[];return await Promise.all(r.map(async n=>{try{const i=this.registeredTransformers.find(c=>c.key===n.url);if(i){o.push(i);const c=this.progressHandler.update(n,!0,"transformer");this.updateProgressListeners(c);return}const a=await this.fetchJavascriptFile(n,e,t,s),l={key:n.url,applyTo:n.applyTo||[],type:n.transformerType||"parsedFileTransformer",transformer:a};this.registeredTransformers.push(l),o.push(l);const u=this.progressHandler.update(n,!0,"transformer");this.updateProgressListeners(u)}catch(i){this.log.error("Failed to load transformer resource",i,{url:n.url,transformerType:n.transformerType});const a={title:n.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:n,description:i?.message};this.setError(a);const l=this.progressHandler.update(n,!1,"transformer");this.updateProgressListeners(l)}})),o}getRequestOptions(r,e,t,s){const o=this.getHeaderForUrl(r,e,t),n=this.getQueryParamsForUrl(r,e,s);return{url:this.appendQueryParamsToUrl(r.url,n),headers:o}}async fetchScript(r,e,t,s){const{url:o,headers:n}=this.getRequestOptions(r,e,t,s),i=await fetch(o,{headers:n});if(!i.ok)throw new Error(`Failed to fetch data from ${o}`);return await i.text()}async fetchJavascriptFile(r,e,t,s){const{url:o,headers:n}=this.getRequestOptions(r,e,t,s),i=await fetch(o,{headers:n});if(!i.ok)throw new Error(`Failed to fetch data from ${o}`);const a=await i.text();return new Function(a)()}isValidModelDefinitionShape(r){if(typeof r!="object"||r===null||Array.isArray(r))return!1;const e=r;return!(typeof e.key!="string"||e.key.length===0||typeof e.properties<"u"&&!Array.isArray(e.properties))}emitInvalidModelDefinitionError(r,e,t){const s={title:r.url,type:"model",errorGroup:"ModelDefinitionError",errorType:"InvalidModelDefinition",model:t??"",meta:r,description:e};this.setError(s)}async handleModelResources(r,e,t,s){const o=r.map(async n=>{const i=new Date().getTime();let a;try{const{url:l,headers:u}=this.getRequestOptions(n,e,t,s),c=await fetch(l,{headers:u});if(a=c.status,!c.ok)throw new Error(`Failed to fetch data from ${l}`);const d=F.now(),f=await c.json(),h=F.now(),p=Array.isArray(f)?f:[f],y=[];for(const m of p)this.isValidModelDefinitionShape(m)?y.push(m):this.emitInvalidModelDefinitionError(n,"Resource body is not a valid ModelDefinition (missing or invalid `key`/`properties`)",typeof m?.key=="string"?m.key:void 0);if(y.length===0){const m=this.progressHandler.update(n,!1,"model",a);return this.updateProgressListeners(m),Promise.resolve(null)}const v=y.map(m=>m.key).join("__"),g=F.getEntriesByName(l.toString());if(Array.isArray(g)&&g[0]){const m=g[0],M={name:n.url,type:"resource",createdAt:new Date().getTime(),value:{model:v,type:"model",start:i,startTime:m.startTime,requestStart:m.requestStart,responseEnd:m.responseEnd,responseStart:m.responseStart,duration:m.duration,parseEnd:h,parseStart:d,decodedBodySize:m.decodedBodySize,encodedBodySize:m.encodedBodySize,end:h}};this.core.analyticsController.set({value:M,context:this.currentContext})}for(const m of y)this.addModelOrView(n,m);const k=this.progressHandler.update(n,!0,"model");return this.updateProgressListeners(k),Promise.resolve(f)}catch(l){this.log.error("Failed to load model resource",l,{url:n.url});const u={title:n.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:n,description:l?.message};this.setError(u);const c=this.progressHandler.update(n,!1,"model",a);return this.updateProgressListeners(c),Promise.resolve(null)}});return await Promise.all(o),!0}appendQueryParamsToUrl(r,e){const t=r.includes("?");let s=r;return e&&e.forEach((o,n)=>{s+=`${n===0&&!t?"?":"&"}${encodeURIComponent(o.key)}=${encodeURIComponent(o.value)}`}),s}async handleDataResources(r,e,t,s,o,n){const i=r.map(async a=>{const l=zr(),u={placeholderUid:l,data:[],model:a.model};this.core.registerContainer(u);const c=new Date().getTime();let d;try{const{url:f,headers:h}=this.getRequestOptions(a,e,s,o),p=await fetch(f,{headers:h});if(d=p.status,!p.ok)throw new Error(`Failed to fetch data from ${f}`);const y=p.headers.get("content-type"),v=F.now();let g;a.url.endsWith(".csv")||y?.includes("text/csv")?g=await p.text():g=await p.json();const k=F.now(),m=F.now(),M=this.handleTransformerLogic(g,a,"rawFileTransformer",n||[]),N=F.now();let bt=[],Wt=this.core.modelParser.unprocessedModelDescriptions.get(a.model);if(!Wt&&(t?.missingModelHandling?.autoGenerateProperties||a.options?.autoGenerateProperties)){const q=a.options?.autoGenerateProperties??t?.missingModelHandling?.autoGenerateProperties??!0;this.addModelOrView(a,{key:a.model,autoGenerateProperties:q,autoGenerateKey:a.options?.autoGenerateKey||!1,keyProperty:a?.options?.keyProperty||"key",keyPropertySeparator:a?.options?.keyPropertySeparator}),Wt=this.core.modelParser.unprocessedModelDescriptions.get(a.model)}const gA=F.now();let Ti={sourceColumns:[],coercionFailureSamples:{},origin:a.url};if(a.url.endsWith(".csv")||y?.includes("text/csv")){if(Wt){const q=this.csvParser.getJsonFromCSVStringWithMetadata(M,Wt,a);bt=q.data,Ti={sourceColumns:q.sourceColumns,coercionFailureSamples:q.coercionFailureSamples,origin:a.url}}}else bt=M;const mA=F.now(),vA=F.now();try{bt=this.handleTransformerLogic(bt,a,"parsedFileTransformer",n||[])}catch(q){this.log.error("Transformer error",q,{resource:a.url,model:a.model})}const bA=F.now(),Oi={placeholderUid:l,model:a.model,data:bt,type:a.options?.updateType||t.defaultDataContainerUpdateType,keyProperty:a?.options?.keyProperty,keyPropertySeparator:a?.options?.keyPropertySeparator,autoGenerateKey:a.options?.autoGenerateKey,autoGenerateProperties:a.options?.autoGenerateProperties},ns=F.getEntriesByName(f.toString());if(Array.isArray(ns)&&ns[0]){const q=ns[0],wA={name:a.url,type:"resource",createdAt:new Date().getTime(),value:{model:a.model,type:"data",start:c,startTime:q.startTime,requestStart:q.requestStart,responseEnd:q.responseEnd,responseStart:q.responseStart,duration:q.duration,parseEnd:k,rawTransformStart:m,rawTransformEnd:N,parseStart:v,csvToJsonStart:gA,csvToJsonEnd:mA,parsedTransformStart:vA,parsedTransformEnd:bA,decodedBodySize:q.decodedBodySize,encodedBodySize:q.encodedBodySize,end:k}};this.core.analyticsController.set({value:wA,context:this.currentContext})}this.core.updateRegisteredContainer(Oi,Ti);const kA=this.progressHandler.update(a,!0,"data",d);return this.updateProgressListeners(kA),Promise.resolve(Oi)}catch(f){this.log.error("Failed to load data resource",f,{url:a.url,model:a.model});const h={title:a.url,type:"loader",errorGroup:"ResourceError",errorType:"InvalidResource",meta:a,model:a.model,description:f?.message};this.setError(h),this.core.removeRegisteredContainer(u);const p=this.progressHandler.update(a,!1,"data",d);return this.updateProgressListeners(p),Promise.resolve()}});return await Promise.all(i),!0}async fetchResources(r,e,t,s,o){const n=r.scheduled;this.progressHandler=new Mi,this.progressHandler.init(n,{skipped:r.skipped,run:r.run}),this.updateProgressListeners(this.progressHandler.getProgress());try{if(!this.core)throw this.log.error("dcupl not connected. Did you add your loader to dcupl? -> dcupl.addRunner(loader)"),new Error;const i=n.filter(f=>f.type==="script");await this.handleScriptResources(i,e,s,o);const a=n.filter(f=>f.type==="operator");await this.handleOperatorResources(a,e,s,o);const l=n.filter(f=>f.type==="transformer"),u=await this.handleTransformerResources(l,e,s,o),c=n.filter(f=>f.type==="model");await this.handleModelResources(c,e,s,o);const d=n.filter(f=>f.type==="data");return await this.handleDataResources(d,e,t,s,o,u),!0}catch(i){return this.log.error("Failed to fetch resources",i),!1}}addModelOrView(r,e){try{"model"in e?this.core.views.set(e):this.core.models.set(e)}catch(t){const s={title:r.url,type:"model",errorGroup:"ModelDefinitionError",errorType:"InvalidModelDefinition",model:e.key,meta:r,description:t?.message};this.setError(s)}}handleTransformerLogic(r,e,t,s){for(const o of s)o.type===t&&o.transformer&&(!o.applyTo.length&&!e.tags?.length&&(r=o.transformer(e,r)),ji(o.applyTo,e.tags||[]).length&&(r=o.transformer(e,r)));return r}updateProgressListeners(r){this.progressListeners.forEach(e=>e(r))}on(r){return this.progressListeners.add(r),()=>{this.progressListeners.delete(r)}}setError(r){this.core.modelParser.qualityController.enabled&&this.core.modelParser.qualityController.setError(r)}};Ii([Qn({scope:"global",origin:"loader",type:"loader_config_fetched",connectMessage:!0,connectMessageResult:!0})],os.prototype,"fetchConfig"),Ii([Qn({scope:"global",origin:"loader",type:"loader_processed",connectMessage:!0})],os.prototype,"process");const hA=os;let vt,ze;async function yA(r){return vt=new oh(r.options),ze=new hA,vt.loaders.add(ze,"default"),r.appLoaderConfig?await ze.config.fetch(r.appLoaderConfig):await ze.config.fetch(),await ze.process(r.processOptions),await vt.init(),globalThis.dcupl=vt,{dcupl:vt,loader:ze}}globalThis.initDcupl=yA})();
|
|
16
16
|
//# sourceMappingURL=dcupl.bundle.min.js.map
|