react-semaphor 0.1.367 → 0.1.368

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../chunks/validation-DGl8wnTt.js"),b=require("../chunks/index-BxM99sFL.js"),u=require("react"),q=require("react/jsx-runtime"),C=require("../chunks/validators-Dq5X4mp0.js"),w=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],M=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function D(t){if(!t)return{};const e=$(t.executionResult),n=P(t,e),o=_(n);return{...t,...Object.keys(n).length?{resultSets:n}:{},...o&&!t.columns?{columns:o.columns}:{},...o&&!t.records?{records:o.records}:{},...o&&t.rowCount===void 0?{rowCount:o.rowCount}:{}}}function P(t,e){const n={...t.resultSets||{}};for(const r of w){if(n[r]){n[r]=T(n[r]);continue}const s=z(t[r]);if(!s.length)continue;const a=e.length?e:j(s);n[r]={records:k(s,a),columns:a,rowCount:s.length}}const o=K(t.executionResult);return o&&o.records.length>0&&!n.records&&(n.records=o),n}function T(t){var e;return{...t,records:k(t.records||[],t.columns||[]),rowCount:t.rowCount??((e=t.records)==null?void 0:e.length)??0}}function _(t){var e;for(const n of M)if((e=t[n])!=null&&e.records.length)return t[n];return Object.values(t).find(n=>n.records.length)||Object.values(t)[0]}function K(t){const e=t==null?void 0:t.result;if(!(!e||e.kind!=="records"&&e.kind!=="sql"))return{records:k(e.records,e.columns),columns:e.columns,rowCount:e.rowCount??e.records.length}}function $(t){const e=t==null?void 0:t.result;return!e||e.kind!=="records"&&e.kind!=="sql"?[]:e.columns}function z(t){return Array.isArray(t)?t.filter(e=>!!(e&&typeof e=="object"&&!Array.isArray(e))):[]}function k(t,e){return e.length?t.map(n=>{const o={};return e.forEach((r,s)=>{const a=B(n,{name:r.key,label:r.label,fallbackNames:[r.name,Object.keys(n)[s]]});a!==void 0&&(o[r.key]=a)}),Object.keys(o).length?o:n}):t}function j(t){return Array.from(new Set(t.flatMap(n=>Object.keys(n)))).map(n=>({key:n,name:n,label:n}))}function B(t,e){const n=[e.name,e.label,...e.fallbackNames||[]].filter(o=>!!o);for(const o of n)if(Object.prototype.hasOwnProperty.call(t,o))return t[o]}function O(){return{executeAnalysis:(t,e,n)=>y(t,e,n??{}).then(D),executeMetric:(t,e)=>y(t,e),executeRecords:(t,e)=>y(t,e),executeInputOptions:(t,e)=>y(t,e)}}async function y(t,e,n){if(!e.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const o=await fetch(V(e),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({intent:t,activeInputs:e.activeInputs,...n?{analysisOptions:n}:{},resultShape:t.kind})}),r=await N(o);if(!o.ok||r.error)throw new Error(r.error||`Semaphor Data App execution failed with status ${o.status}.`);return r}async function N(t){const e=await t.text().catch(()=>"");if(!e.trim())return t.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(e)}catch{return t.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:e}:{error:U(t,e),details:e}}}function U(t,e){const n=t.statusText?` ${t.statusText}`:"",o=e.replace(/\s+/g," ").trim();return o?`Semaphor Data App execution failed with status ${t.status}${n}: ${o.slice(0,240)}`:`Semaphor Data App execution failed with status ${t.status}${n}.`}function V(t){const e=L(t).replace(/\/+$/,"");return e?e.endsWith("/api")?`${e}/v1/data-app/execute`:`${e}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function L(t){if(t.apiBaseUrl)return t.apiBaseUrl;if(!t.token)return"";try{return b.jwtDecode(t.token).apiServiceUrl||""}catch{return""}}const R=u.createContext({});function E(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function x(){return u.useContext(R)}function Q({token:t,apiBaseUrl:e,executor:n,children:o}){var d;const r=E(),s=((d=r==null?void 0:r.authToken)==null?void 0:d.accessToken)||t,a=(r==null?void 0:r.dataApiBaseUrl)||(r==null?void 0:r.apiBaseUrl)||e,p=u.useMemo(()=>O(),[]),c=n||p,m=u.useMemo(()=>({token:s,apiBaseUrl:a,executor:c}),[a,c,s]);return q.jsx(R.Provider,{value:m,children:o})}const A={value:null},I={},H={records:[]},g={options:[]};function J(t){const e=i.toSemaphorActiveInputSnapshots(t.inputs),n=i.toSemaphorAnalysisQueryOptions(t);try{const o=i.toSemaphorAnalysisIntent(t),r=f(o);return r?{error:r,activeInputs:e,analysisOptions:n,queryKey:l(void 0,e,r,n),idleData:I}:{intent:o,error:null,activeInputs:e,analysisOptions:n,queryKey:l(o,e,void 0,n),idleData:I}}catch(o){const r=S(o);return{error:r,activeInputs:e,analysisOptions:n,queryKey:l(void 0,e,r,n),idleData:I}}}function Y(t){const e=i.toSemaphorActiveInputSnapshots(t.inputs);try{const n=i.toSemaphorMetricIntent(t),o=f(n);return o?{error:o,activeInputs:e,queryKey:l(void 0,e,o),idleData:A}:{intent:n,error:null,activeInputs:e,queryKey:l(n,e),idleData:A}}catch(n){const o=S(n);return{error:o,activeInputs:e,queryKey:l(void 0,e,o),idleData:A}}}function W(t){const e=i.toSemaphorActiveInputSnapshots(t.inputs),n=H;try{const o=i.toSemaphorRecordsIntent(t),r=f(o);return r?{error:r,activeInputs:e,queryKey:l(void 0,e,r),idleData:n}:{intent:o,error:null,activeInputs:e,queryKey:l(o,e),idleData:n}}catch(o){const r=S(o);return{error:r,activeInputs:e,queryKey:l(void 0,e,r),idleData:n}}}function F(t){try{const e=i.toSemaphorInputOptionsIntent(t),n=f(e);return n?{error:n,queryKey:l(void 0,void 0,n),idleData:g}:{intent:e,error:null,queryKey:l(e),idleData:g}}catch(e){const n=S(e);return{error:n,queryKey:l(void 0,void 0,n),idleData:g}}}function S(t){return t instanceof Error?t:new Error(String(t))}function f(t){const e=C.validateSemaphorAnalyticsIntent(t);if(e.ok)return null;const n=e.errors.map(o=>o.path?`${o.code} at ${o.path}: ${o.message}`:`${o.code}: ${o.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function l(t,e,n,o){return JSON.stringify({intent:t,activeInputs:e,analysisOptions:o,error:n==null?void 0:n.message})}function G(t){const[e,n]=u.useState(t.defaultValue),o=Object.prototype.hasOwnProperty.call(t,"value"),r=o?t.value:e,s=u.useMemo(()=>i.normalizeSemaphorInputOptions(t.options),[t.options]),a=u.useCallback(c=>{var d;const m=c;(d=t.onValueChange)==null||d.call(t,m),o||n(m)},[o,t]),p=u.useCallback(()=>a(void 0),[a]);return u.useMemo(()=>{const c=i.toSemaphorInputSpec(t);return{id:t.id,kind:t.kind,label:t.label,field:c.field,operator:c.operator,controlRole:t.kind==="control"?t.role:void 0,value:r,options:s,isActive:i.hasSemaphorInputValue(r),setValue:a,clear:p,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:t.kind,label:t.label,value:r,isActive:i.hasSemaphorInputValue(r),operator:c.operator,controlRole:t.kind==="control"?t.role:void 0})}},[p,s,a,t,r])}function X(t){const e=u.useMemo(()=>J(t),[t]),n=u.useCallback(s=>{var a,p;return e.intent?(p=(a=s.executor)==null?void 0:a.executeAnalysis)==null?void 0:p.call(a,e.intent,s,e.analysisOptions):void 0},[e.analysisOptions,e.intent]),o=v(e.queryKey,n,e.idleData,e.activeInputs),r=u.useMemo(()=>D(e.error?e.idleData:o.data),[e.error,e.idleData,o.data]);return{id:t.id,intent:e.intent,...r||{},status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function Z(t){const e=u.useMemo(()=>Y(t),[t]),n=u.useCallback(s=>{var a;return e.intent?(a=s.executor)==null?void 0:a.executeMetric(e.intent,s):void 0},[e.intent]),o=v(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,value:(r==null?void 0:r.value)??null,metrics:r==null?void 0:r.metrics,comparisonValue:r==null?void 0:r.comparisonValue,delta:r==null?void 0:r.delta,deltaPercent:r==null?void 0:r.deltaPercent,records:r==null?void 0:r.records,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function ee(t){const e=u.useMemo(()=>W(t),[t]),n=u.useCallback(s=>{var a;return e.intent?(a=s.executor)==null?void 0:a.executeRecords(e.intent,s):void 0},[e.intent]),o=v(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,records:(r==null?void 0:r.records)||[],columns:r==null?void 0:r.columns,rowCount:r==null?void 0:r.rowCount,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function te(t){const e=u.useMemo(()=>F(t),[t]),n=u.useCallback(s=>{var a;return e.intent?(a=s.executor)==null?void 0:a.executeInputOptions(e.intent,s):void 0},[e.intent]),o=v(e.queryKey,n,e.idleData),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,options:(r==null?void 0:r.options)||[],executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function v(t,e,n,o){const r=x(),s=u.useRef(e),a=u.useRef(o),[p,c]=u.useState({status:"idle",data:n,error:null});return s.current=e,a.current=o,u.useEffect(()=>{let m;try{m=s.current({...r,activeInputs:a.current})}catch(h){c({status:"error",data:n,error:S(h)});return}if(!m){c({status:"idle",data:n,error:null});return}let d=!1;return c(h=>({status:"loading",data:h.data,error:null})),m.then(h=>{d||c({status:"success",data:h,error:null})}).catch(h=>{d||c({status:"error",data:n,error:S(h)})}),()=>{d=!0}},[n,t,r]),p}exports.hasSemaphorInputValue=i.hasSemaphorInputValue;exports.normalizeSemaphorAnalysisQueryOptions=i.normalizeSemaphorAnalysisQueryOptions;exports.normalizeSemaphorInputOptions=i.normalizeSemaphorInputOptions;exports.toSemaphorActiveInputSnapshots=i.toSemaphorActiveInputSnapshots;exports.toSemaphorAnalysisIntent=i.toSemaphorAnalysisIntent;exports.toSemaphorAnalysisQueryOptions=i.toSemaphorAnalysisQueryOptions;exports.toSemaphorInputBinding=i.toSemaphorInputBinding;exports.toSemaphorInputBindings=i.toSemaphorInputBindings;exports.toSemaphorInputOptionsIntent=i.toSemaphorInputOptionsIntent;exports.toSemaphorInputSnapshots=i.toSemaphorInputSnapshots;exports.toSemaphorInputSpec=i.toSemaphorInputSpec;exports.toSemaphorMetricIntent=i.toSemaphorMetricIntent;exports.toSemaphorRecordsIntent=i.toSemaphorRecordsIntent;exports.validateSemaphorDataAppHookSpecs=i.validateSemaphorDataAppHookSpecs;exports.SemaphorDataAppContext=R;exports.SemaphorDataAppProvider=Q;exports.createSemaphorQueryExecutor=O;exports.normalizeSemaphorAnalysisPayload=D;exports.readWindowRuntime=E;exports.useSemaphorAnalysis=X;exports.useSemaphorDataAppRuntime=x;exports.useSemaphorInput=G;exports.useSemaphorInputOptions=te;exports.useSemaphorMetric=Z;exports.useSemaphorRecords=ee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../chunks/validation-DGl8wnTt.js"),b=require("../chunks/index-BxM99sFL.js"),u=require("react"),q=require("react/jsx-runtime"),C=require("../chunks/validators-Dq5X4mp0.js"),w=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],M=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function D(t){var r,a;if(!t)return{};const e=$(t.executionResult),n=P(t,e),o=_(n);return{...t,...Object.keys(n).length?{resultSets:n}:{},...o&&!((r=t.columns)!=null&&r.length)?{columns:o.columns}:{},...o&&!((a=t.records)!=null&&a.length)?{records:o.records}:{},...o&&t.rowCount===void 0?{rowCount:o.rowCount}:{}}}function P(t,e){const n={...t.resultSets||{}};for(const r of w){if(n[r]){n[r]=T(n[r]);continue}const a=z(t[r]);if(!a.length)continue;const s=e.length?e:j(a);n[r]={records:k(a,s),columns:s,rowCount:a.length}}const o=K(t.executionResult);return o&&o.records.length>0&&!n.records&&(n.records=o),n}function T(t){var e;return{...t,records:k(t.records||[],t.columns||[]),rowCount:t.rowCount??((e=t.records)==null?void 0:e.length)??0}}function _(t){var e;for(const n of M)if((e=t[n])!=null&&e.records.length)return t[n];return Object.values(t).find(n=>n.records.length)||Object.values(t)[0]}function K(t){const e=t==null?void 0:t.result;if(!(!e||e.kind!=="records"&&e.kind!=="sql"))return{records:k(e.records,e.columns),columns:e.columns,rowCount:e.rowCount??e.records.length}}function $(t){const e=t==null?void 0:t.result;return!e||e.kind!=="records"&&e.kind!=="sql"?[]:e.columns}function z(t){return Array.isArray(t)?t.filter(e=>!!(e&&typeof e=="object"&&!Array.isArray(e))):[]}function k(t,e){return e.length?t.map(n=>{const o={};return e.forEach((r,a)=>{const s=B(n,{name:r.key,label:r.label,fallbackNames:[r.name,Object.keys(n)[a]]});s!==void 0&&(o[r.key]=s)}),Object.keys(o).length?o:n}):t}function j(t){return Array.from(new Set(t.flatMap(n=>Object.keys(n)))).map(n=>({key:n,name:n,label:n}))}function B(t,e){const n=[e.name,e.label,...e.fallbackNames||[]].filter(o=>!!o);for(const o of n)if(Object.prototype.hasOwnProperty.call(t,o))return t[o]}function O(){return{executeAnalysis:(t,e,n)=>y(t,e,n??{}).then(D),executeMetric:(t,e)=>y(t,e),executeRecords:(t,e)=>y(t,e),executeInputOptions:(t,e)=>y(t,e)}}async function y(t,e,n){if(!e.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const o=await fetch(V(e),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({intent:t,activeInputs:e.activeInputs,...n?{analysisOptions:n}:{},resultShape:t.kind})}),r=await N(o);if(!o.ok||r.error)throw new Error(r.error||`Semaphor Data App execution failed with status ${o.status}.`);return r}async function N(t){const e=await t.text().catch(()=>"");if(!e.trim())return t.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(e)}catch{return t.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:e}:{error:U(t,e),details:e}}}function U(t,e){const n=t.statusText?` ${t.statusText}`:"",o=e.replace(/\s+/g," ").trim();return o?`Semaphor Data App execution failed with status ${t.status}${n}: ${o.slice(0,240)}`:`Semaphor Data App execution failed with status ${t.status}${n}.`}function V(t){const e=L(t).replace(/\/+$/,"");return e?e.endsWith("/api")?`${e}/v1/data-app/execute`:`${e}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function L(t){if(t.apiBaseUrl)return t.apiBaseUrl;if(!t.token)return"";try{return b.jwtDecode(t.token).apiServiceUrl||""}catch{return""}}const R=u.createContext({});function E(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function x(){return u.useContext(R)}function Q({token:t,apiBaseUrl:e,executor:n,children:o}){var d;const r=E(),a=((d=r==null?void 0:r.authToken)==null?void 0:d.accessToken)||t,s=(r==null?void 0:r.dataApiBaseUrl)||(r==null?void 0:r.apiBaseUrl)||e,p=u.useMemo(()=>O(),[]),c=n||p,h=u.useMemo(()=>({token:a,apiBaseUrl:s,executor:c}),[s,c,a]);return q.jsx(R.Provider,{value:h,children:o})}const A={value:null},I={},H={records:[]},g={options:[]};function J(t){const e=i.toSemaphorActiveInputSnapshots(t.inputs),n=i.toSemaphorAnalysisQueryOptions(t);try{const o=i.toSemaphorAnalysisIntent(t),r=f(o);return r?{error:r,activeInputs:e,analysisOptions:n,queryKey:l(void 0,e,r,n),idleData:I}:{intent:o,error:null,activeInputs:e,analysisOptions:n,queryKey:l(o,e,void 0,n),idleData:I}}catch(o){const r=S(o);return{error:r,activeInputs:e,analysisOptions:n,queryKey:l(void 0,e,r,n),idleData:I}}}function Y(t){const e=i.toSemaphorActiveInputSnapshots(t.inputs);try{const n=i.toSemaphorMetricIntent(t),o=f(n);return o?{error:o,activeInputs:e,queryKey:l(void 0,e,o),idleData:A}:{intent:n,error:null,activeInputs:e,queryKey:l(n,e),idleData:A}}catch(n){const o=S(n);return{error:o,activeInputs:e,queryKey:l(void 0,e,o),idleData:A}}}function W(t){const e=i.toSemaphorActiveInputSnapshots(t.inputs),n=H;try{const o=i.toSemaphorRecordsIntent(t),r=f(o);return r?{error:r,activeInputs:e,queryKey:l(void 0,e,r),idleData:n}:{intent:o,error:null,activeInputs:e,queryKey:l(o,e),idleData:n}}catch(o){const r=S(o);return{error:r,activeInputs:e,queryKey:l(void 0,e,r),idleData:n}}}function F(t){try{const e=i.toSemaphorInputOptionsIntent(t),n=f(e);return n?{error:n,queryKey:l(void 0,void 0,n),idleData:g}:{intent:e,error:null,queryKey:l(e),idleData:g}}catch(e){const n=S(e);return{error:n,queryKey:l(void 0,void 0,n),idleData:g}}}function S(t){return t instanceof Error?t:new Error(String(t))}function f(t){const e=C.validateSemaphorAnalyticsIntent(t);if(e.ok)return null;const n=e.errors.map(o=>o.path?`${o.code} at ${o.path}: ${o.message}`:`${o.code}: ${o.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function l(t,e,n,o){return JSON.stringify({intent:t,activeInputs:e,analysisOptions:o,error:n==null?void 0:n.message})}function G(t){const[e,n]=u.useState(t.defaultValue),o=Object.prototype.hasOwnProperty.call(t,"value"),r=o?t.value:e,a=u.useMemo(()=>i.normalizeSemaphorInputOptions(t.options),[t.options]),s=u.useCallback(c=>{var d;const h=c;(d=t.onValueChange)==null||d.call(t,h),o||n(h)},[o,t]),p=u.useCallback(()=>s(void 0),[s]);return u.useMemo(()=>{const c=i.toSemaphorInputSpec(t);return{id:t.id,kind:t.kind,label:t.label,field:c.field,operator:c.operator,controlRole:t.kind==="control"?t.role:void 0,value:r,options:a,isActive:i.hasSemaphorInputValue(r),setValue:s,clear:p,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:t.kind,label:t.label,value:r,isActive:i.hasSemaphorInputValue(r),operator:c.operator,controlRole:t.kind==="control"?t.role:void 0})}},[p,a,s,t,r])}function X(t){const e=u.useMemo(()=>J(t),[t]),n=u.useCallback(a=>{var s,p;return e.intent?(p=(s=a.executor)==null?void 0:s.executeAnalysis)==null?void 0:p.call(s,e.intent,a,e.analysisOptions):void 0},[e.analysisOptions,e.intent]),o=v(e.queryKey,n,e.idleData,e.activeInputs),r=u.useMemo(()=>D(e.error?e.idleData:o.data),[e.error,e.idleData,o.data]);return{id:t.id,intent:e.intent,...r||{},status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function Z(t){const e=u.useMemo(()=>Y(t),[t]),n=u.useCallback(a=>{var s;return e.intent?(s=a.executor)==null?void 0:s.executeMetric(e.intent,a):void 0},[e.intent]),o=v(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,value:(r==null?void 0:r.value)??null,metrics:r==null?void 0:r.metrics,comparisonValue:r==null?void 0:r.comparisonValue,delta:r==null?void 0:r.delta,deltaPercent:r==null?void 0:r.deltaPercent,records:r==null?void 0:r.records,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function ee(t){const e=u.useMemo(()=>W(t),[t]),n=u.useCallback(a=>{var s;return e.intent?(s=a.executor)==null?void 0:s.executeRecords(e.intent,a):void 0},[e.intent]),o=v(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,records:(r==null?void 0:r.records)||[],columns:r==null?void 0:r.columns,rowCount:r==null?void 0:r.rowCount,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function te(t){const e=u.useMemo(()=>F(t),[t]),n=u.useCallback(a=>{var s;return e.intent?(s=a.executor)==null?void 0:s.executeInputOptions(e.intent,a):void 0},[e.intent]),o=v(e.queryKey,n,e.idleData),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,options:(r==null?void 0:r.options)||[],executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function v(t,e,n,o){const r=x(),a=u.useRef(e),s=u.useRef(o),[p,c]=u.useState({status:"idle",data:n,error:null});return a.current=e,s.current=o,u.useEffect(()=>{let h;try{h=a.current({...r,activeInputs:s.current})}catch(m){c({status:"error",data:n,error:S(m)});return}if(!h){c({status:"idle",data:n,error:null});return}let d=!1;return c(m=>({status:"loading",data:m.data,error:null})),h.then(m=>{d||c({status:"success",data:m,error:null})}).catch(m=>{d||c({status:"error",data:n,error:S(m)})}),()=>{d=!0}},[n,t,r]),p}exports.hasSemaphorInputValue=i.hasSemaphorInputValue;exports.normalizeSemaphorAnalysisQueryOptions=i.normalizeSemaphorAnalysisQueryOptions;exports.normalizeSemaphorInputOptions=i.normalizeSemaphorInputOptions;exports.toSemaphorActiveInputSnapshots=i.toSemaphorActiveInputSnapshots;exports.toSemaphorAnalysisIntent=i.toSemaphorAnalysisIntent;exports.toSemaphorAnalysisQueryOptions=i.toSemaphorAnalysisQueryOptions;exports.toSemaphorInputBinding=i.toSemaphorInputBinding;exports.toSemaphorInputBindings=i.toSemaphorInputBindings;exports.toSemaphorInputOptionsIntent=i.toSemaphorInputOptionsIntent;exports.toSemaphorInputSnapshots=i.toSemaphorInputSnapshots;exports.toSemaphorInputSpec=i.toSemaphorInputSpec;exports.toSemaphorMetricIntent=i.toSemaphorMetricIntent;exports.toSemaphorRecordsIntent=i.toSemaphorRecordsIntent;exports.validateSemaphorDataAppHookSpecs=i.validateSemaphorDataAppHookSpecs;exports.SemaphorDataAppContext=R;exports.SemaphorDataAppProvider=Q;exports.createSemaphorQueryExecutor=O;exports.normalizeSemaphorAnalysisPayload=D;exports.readWindowRuntime=E;exports.useSemaphorAnalysis=X;exports.useSemaphorDataAppRuntime=x;exports.useSemaphorInput=G;exports.useSemaphorInputOptions=te;exports.useSemaphorMetric=Z;exports.useSemaphorRecords=ee;
@@ -22,14 +22,15 @@ const z = [
22
22
  "largestPositiveDrivers"
23
23
  ];
24
24
  function O(t) {
25
+ var r, s;
25
26
  if (!t)
26
27
  return {};
27
28
  const e = H(t.executionResult), n = V(t, e), o = J(n);
28
29
  return {
29
30
  ...t,
30
31
  ...Object.keys(n).length ? { resultSets: n } : {},
31
- ...o && !t.columns ? { columns: o.columns } : {},
32
- ...o && !t.records ? { records: o.records } : {},
32
+ ...o && !((r = t.columns) != null && r.length) ? { columns: o.columns } : {},
33
+ ...o && !((s = t.records) != null && s.length) ? { records: o.records } : {},
33
34
  ...o && t.rowCount === void 0 ? { rowCount: o.rowCount } : {}
34
35
  };
35
36
  }
@@ -42,14 +43,14 @@ function V(t, e) {
42
43
  n[r] = Q(n[r]);
43
44
  continue;
44
45
  }
45
- const a = W(t[r]);
46
- if (!a.length)
46
+ const s = W(t[r]);
47
+ if (!s.length)
47
48
  continue;
48
- const s = e.length ? e : F(a);
49
+ const a = e.length ? e : F(s);
49
50
  n[r] = {
50
- records: I(a, s),
51
- columns: s,
52
- rowCount: a.length
51
+ records: I(s, a),
52
+ columns: a,
53
+ rowCount: s.length
53
54
  };
54
55
  }
55
56
  const o = Y(t.executionResult);
@@ -94,13 +95,13 @@ function W(t) {
94
95
  function I(t, e) {
95
96
  return e.length ? t.map((n) => {
96
97
  const o = {};
97
- return e.forEach((r, a) => {
98
- const s = G(n, {
98
+ return e.forEach((r, s) => {
99
+ const a = G(n, {
99
100
  name: r.key,
100
101
  label: r.label,
101
- fallbackNames: [r.name, Object.keys(n)[a]]
102
+ fallbackNames: [r.name, Object.keys(n)[s]]
102
103
  });
103
- s !== void 0 && (o[r.key] = s);
104
+ a !== void 0 && (o[r.key] = a);
104
105
  }), Object.keys(o).length ? o : n;
105
106
  }) : t;
106
107
  }
@@ -209,13 +210,13 @@ function me({
209
210
  children: o
210
211
  }) {
211
212
  var l;
212
- const r = ne(), a = ((l = r == null ? void 0 : r.authToken) == null ? void 0 : l.accessToken) || t, s = (r == null ? void 0 : r.dataApiBaseUrl) || (r == null ? void 0 : r.apiBaseUrl) || e, c = d(() => X(), []), i = n || c, p = d(
213
+ const r = ne(), s = ((l = r == null ? void 0 : r.authToken) == null ? void 0 : l.accessToken) || t, a = (r == null ? void 0 : r.dataApiBaseUrl) || (r == null ? void 0 : r.apiBaseUrl) || e, c = d(() => X(), []), i = n || c, p = d(
213
214
  () => ({
214
- token: a,
215
- apiBaseUrl: s,
215
+ token: s,
216
+ apiBaseUrl: a,
216
217
  executor: i
217
218
  }),
218
- [s, i, a]
219
+ [a, i, s]
219
220
  );
220
221
  return /* @__PURE__ */ B(b.Provider, { value: p, children: o });
221
222
  }
@@ -344,17 +345,17 @@ function u(t, e, n, o) {
344
345
  });
345
346
  }
346
347
  function he(t) {
347
- const [e, n] = R(t.defaultValue), o = Object.prototype.hasOwnProperty.call(t, "value"), r = o ? t.value : e, a = d(
348
+ const [e, n] = R(t.defaultValue), o = Object.prototype.hasOwnProperty.call(t, "value"), r = o ? t.value : e, s = d(
348
349
  () => K(t.options),
349
350
  [t.options]
350
- ), s = y(
351
+ ), a = y(
351
352
  (i) => {
352
353
  var l;
353
354
  const p = i;
354
355
  (l = t.onValueChange) == null || l.call(t, p), o || n(p);
355
356
  },
356
357
  [o, t]
357
- ), c = y(() => s(void 0), [s]);
358
+ ), c = y(() => a(void 0), [a]);
358
359
  return d(() => {
359
360
  const i = P(t);
360
361
  return {
@@ -365,9 +366,9 @@ function he(t) {
365
366
  operator: i.operator,
366
367
  controlRole: t.kind === "control" ? t.role : void 0,
367
368
  value: r,
368
- options: a,
369
+ options: s,
369
370
  isActive: E(r),
370
- setValue: s,
371
+ setValue: a,
371
372
  clear: c,
372
373
  toAnalyticsInput: () => ({
373
374
  inputId: i.inputId,
@@ -380,16 +381,16 @@ function he(t) {
380
381
  controlRole: t.kind === "control" ? t.role : void 0
381
382
  })
382
383
  };
383
- }, [c, a, s, t, r]);
384
+ }, [c, s, a, t, r]);
384
385
  }
385
386
  function ve(t) {
386
387
  const e = d(() => ae(t), [t]), n = y(
387
- (a) => {
388
- var s, c;
389
- return e.intent ? (c = (s = a.executor) == null ? void 0 : s.executeAnalysis) == null ? void 0 : c.call(
390
- s,
391
- e.intent,
388
+ (s) => {
389
+ var a, c;
390
+ return e.intent ? (c = (a = s.executor) == null ? void 0 : a.executeAnalysis) == null ? void 0 : c.call(
392
391
  a,
392
+ e.intent,
393
+ s,
393
394
  e.analysisOptions
394
395
  ) : void 0;
395
396
  },
@@ -416,9 +417,9 @@ function ve(t) {
416
417
  }
417
418
  function Se(t) {
418
419
  const e = d(() => ie(t), [t]), n = y(
419
- (a) => {
420
- var s;
421
- return e.intent ? (s = a.executor) == null ? void 0 : s.executeMetric(e.intent, a) : void 0;
420
+ (s) => {
421
+ var a;
422
+ return e.intent ? (a = s.executor) == null ? void 0 : a.executeMetric(e.intent, s) : void 0;
422
423
  },
423
424
  [e.intent]
424
425
  ), o = S(
@@ -444,9 +445,9 @@ function Se(t) {
444
445
  }
445
446
  function Ae(t) {
446
447
  const e = d(() => ue(t), [t]), n = y(
447
- (a) => {
448
- var s;
449
- return e.intent ? (s = a.executor) == null ? void 0 : s.executeRecords(e.intent, a) : void 0;
448
+ (s) => {
449
+ var a;
450
+ return e.intent ? (a = s.executor) == null ? void 0 : a.executeRecords(e.intent, s) : void 0;
450
451
  },
451
452
  [e.intent]
452
453
  ), o = S(
@@ -469,9 +470,9 @@ function Ae(t) {
469
470
  }
470
471
  function ge(t) {
471
472
  const e = d(() => ce(t), [t]), n = y(
472
- (a) => {
473
- var s;
474
- return e.intent ? (s = a.executor) == null ? void 0 : s.executeInputOptions(e.intent, a) : void 0;
473
+ (s) => {
474
+ var a;
475
+ return e.intent ? (a = s.executor) == null ? void 0 : a.executeInputOptions(e.intent, s) : void 0;
475
476
  },
476
477
  [e.intent]
477
478
  ), o = S(
@@ -490,17 +491,17 @@ function ge(t) {
490
491
  };
491
492
  }
492
493
  function S(t, e, n, o) {
493
- const r = oe(), a = x(e), s = x(o), [c, i] = R({
494
+ const r = oe(), s = x(e), a = x(o), [c, i] = R({
494
495
  status: "idle",
495
496
  data: n,
496
497
  error: null
497
498
  });
498
- return a.current = e, s.current = o, U(() => {
499
+ return s.current = e, a.current = o, U(() => {
499
500
  let p;
500
501
  try {
501
- p = a.current({
502
+ p = s.current({
502
503
  ...r,
503
- activeInputs: s.current
504
+ activeInputs: a.current
504
505
  });
505
506
  } catch (f) {
506
507
  i({
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.367",
8
+ "version": "0.1.368",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",