1import{an as q,y as N,b as w,i as b,aq as O,a0 as L}from"./DjRoh7cm.js";function S(e){const t=e[0].charAt(0),o=u=>({quant:u[0],displayName:u[1],currencyCode:u[2],exchangeQuant:u[3]||void 0,isin:u[4]||void 0,sectorCode:u[5]||void 0,ticker:u[6]||void 0});switch(t){case"S":return{_t:"stock",...o(e)};case"W":return{_t:"warrant",...o(e)};case"T":return{_t:"certificate",...o(e)};case"O":return{_t:"option",...o(e)};case"U":return{_t:"future",...o(e)};case"R":return{_t:"right",...o(e)};case"B":return{_t:"etn",...o(e)};case"A":return{_t:"etf",...o(e)};case"D":return{_t:"dr",...o(e)};case"N":return{_t:"bond",quant:e[0],displayName:e[1],currencyCode:e[2],exchangeQuant:e[3]||void 0,isin:e[4]||void 0,sectorCode:e[5]||void 0};case"X":return{_t:"index",quant:e[0],displayName:e[1],name:e[2]};case"Y":return{_t:"currency",quant:e[0],displayName:e[1],base:e[2],destination:e[3]};case"G":return{_t:"crypto",quant:e[0],displayName:e[1],base:e[2],destination:e[3]};case"E":return{_t:"exchange",quant:e[0],displayName:e[1],name:e[2]};case"C":return{_t:"commodity",quant:e[0],displayName:e[1]};case"I":return{_t:"interest",quant:e[0],displayName:e[1],name:e[2]};case"F":return{_t:"fund",quant:e[0],displayName:e[1],secId:e[2]};default:console.warn("Unable to resolve model",e);return}}function P(e){let t=e.displayName;return"ticker"in e&&e.ticker&&(t+=` ${e.ticker}`),"destination"in e&&(t+=` ${e.destination}`),"name"in e&&(t+=` ${e.name}`),"isin"in e&&(t+=` ${e.isin}`),t.toLowerCase()}function x(e){const t=e.map(o=>[P(o),o]);return(o,u,h)=>{o=o.toLowerCase();const l=[];let m=0;switch(o){case"håkon er kul":alert("njah");break;case"jørn er kul":case"fredrik er kul":case"thomas er kul":case"jonas er kul":case"therese er kul":case"marianne er kul":case"tc er kul":case"krzysztof er kul":alert("Stemmer!")}for(const[k,i]of t)if(h?.(i)!==!1){if("ticker"in i&&i.ticker&&i.ticker.toLowerCase()===o)l.some(f=>f.quant===i.quant)||(l.unshift(i),m++);else if(i.displayName.toLowerCase()===o){if(l.some(f=>f.quant===i.quant))continue;l.unshift(i)}else if("destination"in i&&i.destination.toLowerCase()===o){if(l.some(f=>f.quant===i.quant))continue;l.unshift(i)}else if("isin"in i&&i.isin?.toLowerCase()===o){if(l.some(f=>f.quant===i.quant))continue;l.unshift(i)}else if(k.includes(o)&&l.length<u+m){if(l.some(f=>f.quant===i.quant))continue;l.push(i)}if(l.length===u+m)break}return l}}const T=2500,v=3e3,E=Symbol("MODEL_ASYNC_TIMEOUT");function U(e){if(!Number.isFinite(e)||e<=0)return;if(typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function")return AbortSignal.timeout(e);if(typeof AbortController>"u")return;const t=new AbortController;return setTimeout(()=>t.abort(),e),t.signal}function $(e){let t;return{promise:new Promise(u=>{t=setTimeout(()=>{console.error(`getModelAsync timed out after ${v} ms`,{quant:e}),u(E)},v)}),cancel:()=>{t&&clearTimeout(t)}}}const R=q("pulse-models",()=>{const e=L(),t=N({}),o=new Map,u=n=>{const s={...t.value};Object.values(n).forEach(c=>{s[c.quant]||(s[c.quant]=c)}),t.value=s},h=()=>{t.value={}},l=async n=>{try{const s=await $fetch(n,{timeout:T});if(!s.success)throw new Error("Error fetching models");const c={...t.value};s.result.prefetched.forEach(a=>{const r=S(a);r&&!c[r.quant]&&(c[r.quant]=r)}),t.value=c}catch(s){console.error("Error fetching models",s)}},m=n=>w(()=>t.value[n]||void 0),k=(n,s=10,c)=>{const a=Object.values(t.value);return x(a)(n,s,c)};async function i(n,s){const c=`${s}/api/v1/models/lookup/${n}`,a=b(),r=b();try{const d=await fetch(c,{signal:U(T)});if(!d.ok)return r.value=new Error("Pulse models store: lookupModel failed"),console.error("Pulse models store: lookupModel failed",d.statusText),{data:a,error:r};const p=await d.json();p.success&&p.result?.model?a.value=S(p.result.model)||void 0:(console.error("Pulse models store: lookupModel failed",p),r.value=new Error("Pulse models store: lookupModel failed"))}catch(d){console.error("Pulse models store: lookupModel failed",d),r.value=new Error("Pulse models store: lookupModel failed")}return{data:a,error:r}}async function y(n){const s=t.value[n];if(s)return s;const c=e.public.marketVectorServer?.httpUrl;if(!c)return;const a=o.get(n);if(a)return a;const r=i(n,c).then(({data:d})=>(d.value&&u({[d.value.quant]:d.value}),d.value)).finally(()=>{o.delete(n)});return o.set(n,r),r}const f=async n=>{const s=m(n).value;if(s)return s;const c=$(n),a=await Promise.race([y(n),c.promise]).finally(()=>{c.cancel()});if(a!==E)return a||new Promise(r=>{const d=m(n);let p=!1;const _=M=>{p||(p=!0,clearTimeout(A),C?.(),r(M))},A=setTimeout(()=>{console.error(`getModelAsync timed out after ${v} ms`,{quant:n}),_(void 0)},v),C=O(d,M=>_(M))})},g=w(()=>Object.values(t.value));return{modelsRecord:t,modelsMapped:g,fetchModels:l,search:k,getModel:m,getModelAsync:f,getModelsByType:n=>g.value.filter(s=>n==="currency"?s._t===n&&!e.public.quants.cryptocurrencies?.includes(s.quant):n==="crypto"?s._t===n||e.public.quants.cryptocurrencies?.includes(s.quant):s._t===n),lookupModel:i,setModels:u,clearModels:h}});
1export{x as b,R as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.