altair-static
Version:
Static package for altair graphql client
7 lines (6 loc) • 11 kB
JavaScript
(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))a(i);new MutationObserver(i=>{for(const d of i)if(d.type==="childList")for(const g of d.addedNodes)g.tagName==="LINK"&&g.rel==="modulepreload"&&a(g)}).observe(document,{childList:!0,subtree:!0});function n(i){const d={};return i.integrity&&(d.integrity=i.integrity),i.referrerPolicy&&(d.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?d.credentials="include":i.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function a(i){if(i.ep)return;i.ep=!0;const d=n(i);fetch(i.href,d)}})();let getRandomValues;const rnds8=new Uint8Array(16);function rng(){if(!getRandomValues&&(getRandomValues=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!getRandomValues))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}const byteToHex=[];for(let e=0;e<256;++e)byteToHex.push((e+256).toString(16).slice(1));function unsafeStringify(e,r=0){return byteToHex[e[r+0]]+byteToHex[e[r+1]]+byteToHex[e[r+2]]+byteToHex[e[r+3]]+"-"+byteToHex[e[r+4]]+byteToHex[e[r+5]]+"-"+byteToHex[e[r+6]]+byteToHex[e[r+7]]+"-"+byteToHex[e[r+8]]+byteToHex[e[r+9]]+"-"+byteToHex[e[r+10]]+byteToHex[e[r+11]]+byteToHex[e[r+12]]+byteToHex[e[r+13]]+byteToHex[e[r+14]]+byteToHex[e[r+15]]}const randomUUID=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),native={randomUUID};function v4(e,r,n){if(native.randomUUID&&!e)return native.randomUUID();e=e||{};const a=e.random||(e.rng||rng)();return a[6]=a[6]&15|64,a[8]=a[8]&63|128,unsafeStringify(a)}const SCRIPT_INIT_EXECUTE="init_execute",scriptRel="modulepreload",assetsURL=function(e){return"/"+e},seen={},__vitePreload=function(r,n,a){let i=Promise.resolve();if(n&&n.length>0){let h=function(y){return Promise.all(y.map(u=>Promise.resolve(u).then(c=>({status:"fulfilled",value:c}),c=>({status:"rejected",reason:c}))))};var g=h;document.getElementsByTagName("link");const v=document.querySelector("meta[property=csp-nonce]"),p=v?.nonce||v?.getAttribute("nonce");i=h(n.map(y=>{if(y=assetsURL(y),y in seen)return;seen[y]=!0;const u=y.endsWith(".css"),c=u?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${y}"]${c}`))return;const m=document.createElement("link");if(m.rel=u?"stylesheet":scriptRel,u||(m.as="script"),m.crossOrigin="",m.href=y,p&&m.setAttribute("nonce",p),document.head.appendChild(m),u)return new Promise((x,E)=>{m.addEventListener("load",x),m.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${y}`)))})}))}function d(v){const p=new Event("vite:preloadError",{cancelable:!0});if(p.payload=v,window.dispatchEvent(p),!p.defaultPrevented)throw v}return i.then(v=>{for(const p of v||[])p.status==="rejected"&&d(p.reason);return r().catch(d)})};var RequestType;(function(e){e.INTROSPECTION="introspection",e.QUERY="query",e.SUBSCRIPTION="subscription"})(RequestType||(RequestType={}));class ScriptEvaluatorWorker{}var objectPath$1={exports:{}},objectPath=objectPath$1.exports,hasRequiredObjectPath;function requireObjectPath(){return hasRequiredObjectPath||(hasRequiredObjectPath=1,(function(e){(function(r,n){e.exports=n()})(objectPath,function(){var r=Object.prototype.toString;function n(u,c){return u==null?!1:Object.prototype.hasOwnProperty.call(u,c)}function a(u){if(!u||g(u)&&u.length===0)return!0;if(typeof u!="string"){for(var c in u)if(n(u,c))return!1;return!0}return!1}function i(u){return r.call(u)}function d(u){return typeof u=="object"&&i(u)==="[object Object]"}var g=Array.isArray||function(u){return r.call(u)==="[object Array]"};function v(u){return typeof u=="boolean"||i(u)==="[object Boolean]"}function p(u){var c=parseInt(u);return c.toString()===u?c:u}function h(u){u=u||{};var c=function(s){return Object.keys(c).reduce(function(t,o){return o==="create"||typeof c[o]=="function"&&(t[o]=c[o].bind(c,s)),t},{})},m;u.includeInheritedProps?m=function(){return!0}:m=function(s,t){return typeof t=="number"&&Array.isArray(s)||n(s,t)};function x(s,t){if(m(s,t))return s[t]}function E(s,t,o,l){if(typeof t=="number"&&(t=[t]),!t||t.length===0)return s;if(typeof t=="string")return E(s,t.split(".").map(p),o,l);var f=t[0],w=x(s,f);if(u.includeInheritedProps&&(f==="__proto__"||f==="constructor"&&typeof w=="function"))throw new Error("For security reasons, object's magic properties cannot be set");return t.length===1?((w===void 0||!l)&&(s[f]=o),w):(w===void 0&&(typeof t[1]=="number"?s[f]=[]:s[f]={}),E(s[f],t.slice(1),o,l))}return c.has=function(s,t){if(typeof t=="number"?t=[t]:typeof t=="string"&&(t=t.split(".")),!t||t.length===0)return!!s;for(var o=0;o<t.length;o++){var l=p(t[o]);if(typeof l=="number"&&g(s)&&l<s.length||(u.includeInheritedProps?l in Object(s):n(s,l)))s=s[l];else return!1}return!0},c.ensureExists=function(s,t,o){return E(s,t,o,!0)},c.set=function(s,t,o,l){return E(s,t,o,l)},c.insert=function(s,t,o,l){var f=c.get(s,t);l=~~l,g(f)||(f=[],c.set(s,t,f)),f.splice(l,0,o)},c.empty=function(s,t){if(!a(t)&&s!=null){var o,l;if(o=c.get(s,t)){if(typeof o=="string")return c.set(s,t,"");if(v(o))return c.set(s,t,!1);if(typeof o=="number")return c.set(s,t,0);if(g(o))o.length=0;else if(d(o))for(l in o)m(o,l)&&delete o[l];else return c.set(s,t,null)}}},c.push=function(s,t){var o=c.get(s,t);g(o)||(o=[],c.set(s,t,o)),o.push.apply(o,Array.prototype.slice.call(arguments,2))},c.coalesce=function(s,t,o){for(var l,f=0,w=t.length;f<w;f++)if((l=c.get(s,t[f]))!==void 0)return l;return o},c.get=function(s,t,o){if(typeof t=="number"&&(t=[t]),!t||t.length===0)return s;if(s==null)return o;if(typeof t=="string")return c.get(s,t.split("."),o);var l=p(t[0]),f=x(s,l);return f===void 0?o:t.length===1?f:c.get(s[l],t.slice(1),o)},c.del=function(t,o){if(typeof o=="number"&&(o=[o]),t==null||a(o))return t;if(typeof o=="string")return c.del(t,o.split("."));var l=p(o[0]);if(!m(t,l))return t;if(o.length===1)g(t)?t.splice(l,1):delete t[l];else return c.del(t[l],o.slice(1));return t},c}var y=h();return y.create=h,y.withInheritedProps=h({includeInheritedProps:!0}),y})})(objectPath$1)),objectPath$1.exports}var objectPathExports=requireObjectPath();const ModuleImports={atob:{async exec(){return(await __vitePreload(async()=>{const{atob:e}=await import("./index-D_C6pEAs.js").then(r=>r.i);return{atob:e}},[])).atob}},btoa:{async exec(){return(await __vitePreload(async()=>{const{btoa:e}=await import("./index-D_C6pEAs.js").then(r=>r.i);return{btoa:e}},[])).btoa}},"crypto-js":{async exec(){return(await __vitePreload(async()=>{const{default:e}=await import("./index-CT51TZmB.js").then(r=>r.i);return{default:e}},[])).default}}},buildContextResponse=e=>{if(e.response)return{body:e.response.body,requestType:e.requestType??RequestType.QUERY,responseTime:e.response.responseTime,statusCode:e.response.status,headers:e.response.headers}},importModuleHelper=async e=>{const r=ModuleImports[e];if(!r)throw new Error(`No request script module found matching "${e}"`);return r.exec()},getGlobalContext=(e,r)=>({data:e,helpers:{getEnvironment:n=>objectPathExports.get(e.environment,n),setEnvironment:(n,a,i=!1)=>{objectPathExports.set(e.environment,n,a),i&&(e.__toSetActiveEnvironment=e.__toSetActiveEnvironment??{},objectPathExports.set(e.__toSetActiveEnvironment,n,a))},getCookie:n=>e.__cookieJar?.[n]??"",setCookie:(n,a,i)=>{r.setCookie(n,a,i)},request:async(n,a,i)=>r.request(n,a,i)},storage:{get:n=>r.getStorageItem(n),set:(n,a)=>r.setStorageItem(n,a)},importModule:n=>importModuleHelper(n),response:buildContextResponse(e),log:n=>{e.requestScriptLogs=e.requestScriptLogs??[],e.requestScriptLogs.push({id:crypto.randomUUID(),time:Date.now(),text:JSON.stringify(n,null,2),source:"Request script"})}}),workerHandlerNames=["setCookie","request","getStorageItem","setStorageItem"];class ScriptEvaluatorWorkerEngine{constructor(e){this.worker=e}start(){this.worker.onMessage(async e=>{switch(e.type){case SCRIPT_INIT_EXECUTE:try{await this.initExecute(e.payload)}catch(r){await this.makeCall("scriptError",r)}break}})}async initExecute(payload){const[script,data]=payload,res=await new Promise((resolve,reject)=>{this.worker.onError(e=>{reject(e)});const clonedMutableData=JSON.parse(JSON.stringify(data)),handlers=workerHandlerNames.reduce((e,r)=>(e[r]=((...n)=>this.makeCall(r,...n)),e),{}),context={altair:getGlobalContext(clonedMutableData,handlers),alert:e=>this.makeCall("alert",e)},contextEntries=Object.entries(context);try{const res=(function(){return eval(`
(async(${contextEntries.map(e=>e[0]).join(",")}) => {
${script};
return altair.data;
})(...this.__ctxE.map(e => e[1]));
`)}).call({__ctxE:contextEntries});return resolve(res)}catch(e){return reject(e)}});res.__toSetActiveEnvironment&&this.makeCall("updateActiveEnvironment",res.__toSetActiveEnvironment),this.makeCall("executeComplete",res)}makeCall(e,...r){return new Promise((n,a)=>{const i=v4();this.worker.onMessage(d=>{switch(d.type){case`${e}_response`:return d.payload.id!==i?void 0:n(d.payload.response);case`${e}_error`:return d.payload.id!==i?void 0:a(d.payload.error)}}),this.worker.send(e,{id:i,args:r})})}}class EvaluatorFrameWorker extends ScriptEvaluatorWorker{origin;constructor(){super();const n=new URLSearchParams(window.location.search).get("sc");if(!n)throw new Error("Invalid source provided!");this.origin=n}onMessage(r){window.addEventListener("message",n=>{n.origin===this.origin&&r(n.data)})}send(r,n){window.parent.postMessage({type:r,payload:n},this.origin)}onError(r){window.addEventListener("error",r),window.addEventListener("unhandledrejection",n=>{n.preventDefault(),r(n.reason)})}}const injectScript=e=>new Promise((r,n)=>{const a=document.getElementsByTagName("head")[0];if(!a)return n(new Error("No head found!"));const i=document.createElement("script");i.type="text/javascript",i.src=e,i.onload=()=>r(null),i.onerror=d=>n(d),a.appendChild(i)}),injectStylesheet=e=>new Promise((r,n)=>{const a=document.getElementsByTagName("head")[0];if(!a)return n(new Error("No head found!"));const i=document.createElement("link");i.type="text/css",i.rel="stylesheet",i.href=e,i.onload=()=>r(null),i.onerror=d=>n(d),a.appendChild(i)}),handlePluginSandbox=async()=>{const r=new URLSearchParams(window.location.search).get("plugin_sandbox_opts"),n=r?JSON.parse(r):void 0;if(!n)throw new Error("Invalid plugin options provided!");if(n.type!=="scripts")throw new Error("Invalid plugin option type provided!");if(document.querySelectorAll('style,link[rel="stylesheet"]').forEach(a=>a.remove()),n.styleUrls)for(const a of n.styleUrls)await injectStylesheet(a);if(n.scriptUrls)for(const a of n.scriptUrls)await injectScript(a)},searchParams=new URLSearchParams(window.location.search),sandboxType=searchParams.get("sandbox_type");sandboxType==="plugin"?handlePluginSandbox():new ScriptEvaluatorWorkerEngine(new EvaluatorFrameWorker).start();