react-semaphor 0.1.371 → 0.1.373

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.
Files changed (53) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +1 -1
  3. package/dist/chunks/{calendar-preferences-dialog-Dn6o2r2Y.js → calendar-preferences-dialog-BCO0I6Q2.js} +1 -1
  4. package/dist/chunks/{calendar-preferences-dialog-ClBAkMmF.js → calendar-preferences-dialog-CAcqW83Q.js} +1 -1
  5. package/dist/chunks/{dashboard-briefing-launcher-BO-kXtEd.js → dashboard-briefing-launcher-CxozwqgX.js} +1 -1
  6. package/dist/chunks/{dashboard-briefing-launcher-D3Xfc_26.js → dashboard-briefing-launcher-DTp4KNI1.js} +104 -104
  7. package/dist/chunks/{dashboard-controls-B3sdy_Zx.js → dashboard-controls-Bc4E4Cky.js} +167 -167
  8. package/dist/chunks/{dashboard-controls-DcXMFgGR.js → dashboard-controls-Dkct7mpD.js} +1 -1
  9. package/dist/chunks/{dashboard-json-CFURS_OR.js → dashboard-json-BFB5jFmm.js} +1 -1
  10. package/dist/chunks/{dashboard-json-BWfkEy48.js → dashboard-json-BmCwILfI.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-BD2AJLiT.js → edit-dashboard-visual-BBlY9tKB.js} +37 -37
  12. package/dist/chunks/{edit-dashboard-visual-DjdhKiP2.js → edit-dashboard-visual-BXLuXKFc.js} +6592 -6565
  13. package/dist/chunks/{index-C0Qnfr_7.js → index-Clqr43Sr.js} +36742 -34869
  14. package/dist/chunks/index-D5Pp-5LR.js +1361 -0
  15. package/dist/chunks/{resource-management-panel-DytUMSGA.js → resource-management-panel-BbkbAlPo.js} +1 -1
  16. package/dist/chunks/{resource-management-panel-YvIfaphX.js → resource-management-panel-DJUr47Bb.js} +51 -51
  17. package/dist/chunks/{use-create-flow-overlay-state-CwIG1Ekp.js → use-create-flow-overlay-state-B4EAcL2v.js} +1 -1
  18. package/dist/chunks/{use-create-flow-overlay-state-BETXykC9.js → use-create-flow-overlay-state-DZI7VYBs.js} +35 -35
  19. package/dist/chunks/{use-visual-utils-Bk135OgA.js → use-visual-utils-Bl3ltNL9.js} +12 -12
  20. package/dist/chunks/{use-visual-utils-BzFjIykb.js → use-visual-utils-djsPEgF1.js} +1 -1
  21. package/dist/chunks/{validation-D4Zz6WPD.js → validation-1V7bWmYw.js} +1 -1
  22. package/dist/chunks/{validation-CQFpcSSP.js → validation-DlrTIf1N.js} +1 -1
  23. package/dist/chunks/{validators-CuKnUZFO.js → validators-CtNmgsvG.js} +409 -314
  24. package/dist/chunks/validators-jpoYhpHh.js +1 -0
  25. package/dist/dashboard/index.cjs +1 -1
  26. package/dist/dashboard/index.js +1 -1
  27. package/dist/dashboard-authoring/index.cjs +1 -1
  28. package/dist/dashboard-authoring/index.js +1 -1
  29. package/dist/data-app-builder/index.cjs +1 -1
  30. package/dist/data-app-builder/index.js +1 -1
  31. package/dist/data-app-sdk/index.cjs +1 -1
  32. package/dist/data-app-sdk/index.js +32 -32
  33. package/dist/data-app-sdk-validation/index.cjs +1 -1
  34. package/dist/data-app-sdk-validation/index.js +2 -2
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.js +127 -126
  37. package/dist/style.css +1 -1
  38. package/dist/surfboard/index.cjs +1 -1
  39. package/dist/surfboard/index.js +2 -2
  40. package/dist/types/analytics-protocol.d.ts +102 -11
  41. package/dist/types/dashboard-assistant.d.ts +117 -103
  42. package/dist/types/dashboard-authoring.d.ts +63 -2
  43. package/dist/types/dashboard.d.ts +263 -2
  44. package/dist/types/data-app-builder.d.ts +40 -1
  45. package/dist/types/data-app-sdk-validation.d.ts +94 -102
  46. package/dist/types/data-app-sdk.d.ts +106 -11
  47. package/dist/types/main.d.ts +473 -2
  48. package/dist/types/shared.d.ts +263 -2
  49. package/dist/types/surfboard.d.ts +263 -2
  50. package/dist/types/types.d.ts +529 -2
  51. package/package.json +1 -1
  52. package/dist/chunks/index-DlLvzmJF.js +0 -1361
  53. package/dist/chunks/validators-DHee9kM2.js +0 -1
@@ -0,0 +1 @@
1
+ "use strict";const Z=require("./source-identity-C-xaeE_I.js");function J(e){const i=j(e);return C(i)?i:void 0}function j(e){if(typeof e!="string"||e.trim().length===0)return;const i=e.trim().toLowerCase().replace(/_/g," ");switch(i){case"eq":case"equals":case"=":return"=";case"neq":case"not equals":case"not equal":case"!=":return"!=";case"in":return"in";case"not in":return"not_in";case"contains":case"like":return"contains";case"not contains":case"not like":return"not_contains";case"between":return"between";case"not between":return"not_between";case">":case">=":case"<":case"<=":return i;case"is null":return"is_null";case"is not null":return"is_not_null";default:return W(e)?e:void 0}}function C(e){return e==="="||e==="!="||e==="in"||e==="not_in"||e==="contains"||e==="not_contains"||e==="between"||e==="not_between"||e===">"||e===">="||e==="<"||e==="<="}function W(e){return C(e)||e==="not_contains"||e==="is_null"||e==="is_not_null"}function a(e,i,t){return t?{code:e,message:i,path:t}:{code:e,message:i}}function ee(e){for(let i=0;i<e.length;i+=1){const t=e[i];if(e.some((n,s)=>s!==i&&U(n,t)))return!1}return!0}function L(e,i){return Z.semaphorFieldRefsMatch(e,i)}function U(e,i){return L(e,i)&&v(e)===v(i)}function ie(e){return`Metric intent has duplicate metric "${e.name}" with the same aggregate (${v(e)}). Use different aggregates to request both, or remove one entry.`}function T(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function te(e,i,t){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e)){t.push(a("invalid_sql_default_parameters","SQL defaultParameters must be an object keyed by parameter name.",i));return}Object.entries(e).forEach(([n,s])=>{if(!n.trim()){t.push(a("invalid_sql_default_parameter_name","SQL defaultParameters names must be non-empty strings.",`${i}.${n}`));return}(Array.isArray(s)?s.every(T):T(s))||t.push(a("invalid_sql_default_parameter_value","SQL defaultParameters values must be strings, numbers, booleans, nulls, or arrays of those scalar values.",`${i}.${n}`))})}}function ae(e,i){return k(e,i).length===1}function ne(e,i){return k(e,i).length===1}function k(e,i){return i.filter(n=>se(e,n))}function se(e,i){return re(e,i)?e.source?L(i,e):!0:!1}function re(e,i){return!(i.name!==e.name||e.role!==void 0&&i.role!==void 0&&i.role!==e.role||oe(e,i)&&v(i)!==v(e))}function oe(e,i){return e.role==="measure"||i.role==="measure"||e.aggregate!==void 0||i.aggregate!==void 0}function v(e){return(e.aggregate||"SUM").toUpperCase()}const de=/^(\d{4})-(\d{2})-(\d{2})$/,le=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/;function $(e){if(typeof e!="string")return null;const i=e.trim(),t=de.exec(i);if(t){const[,y,R,P]=t;return E(y,R,P)?new Date(Date.UTC(Number(y),Number(R)-1,Number(P))):null}const n=le.exec(i);if(!n)return null;const[,s,r,o,u,d,m="00",,p]=n;if(!E(s,r,o)||!g(u,0,23)||!g(d,0,59)||!g(m,0,59)||!ue(p))return null;const b=new Date(i);return Number.isFinite(b.getTime())?b:null}function E(e,i,t){const n=Number(e),s=Number(i),r=Number(t);if(!Number.isInteger(n)||!Number.isInteger(s)||!Number.isInteger(r)||s<1||s>12)return!1;const o=new Date(Date.UTC(n,s-1,r));return o.getUTCFullYear()===n&&o.getUTCMonth()===s-1&&o.getUTCDate()===r}function g(e,i,t){const n=Number(e);return Number.isInteger(n)&&n>=i&&n<=t}function ue(e){if(e==="Z")return!0;const i=/^([+-])(\d{2}):(\d{2})$/.exec(e);return!!(i&&g(i[2],0,23)&&g(i[3],0,59))}function l(e){return typeof e=="string"&&e.trim().length>0}function ce(e){const i=new Set;let t=0;for(;t<e.length;){const n=e[t];if(n==="'"||n==='"'){t=me(e,t);continue}if(n==="{"){const s=e.indexOf("}",t+1);if(s===-1){t+=1;continue}const r=e.slice(t+1,s);/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)&&i.add(r),t=s+1;continue}t+=1}return Array.from(i)}function me(e,i){const t=e[i];let n=i+1;for(;n<e.length;){if(e[n]===t){if(e[n+1]===t){n+=2;continue}return n+1}n+=1}return e.length}function c(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function O(e,i,t){if(e!==void 0){if(!c(e)){t.push(a("invalid_pagination","Pagination must be an object with positive integer page and pageSize.",i));return}(!Number.isInteger(e.page)||typeof e.page!="number"||e.page<1)&&t.push(a("invalid_pagination_page","Pagination page must be a positive integer.",`${i}.page`)),(!Number.isInteger(e.pageSize)||typeof e.pageSize!="number"||e.pageSize<1)&&t.push(a("invalid_pagination_page_size","Pagination pageSize must be a positive integer.",`${i}.pageSize`))}}function S(e){const i=new Set;for(const t of e){if(i.has(t))return t;i.add(t)}return null}function w(e,i,t,n){S(e.filter(r=>l(r)))&&n.push(a("duplicate_matrix_public_id",`Matrix ${t} ids must be unique so sort and expansion references are unambiguous.`,i))}const fe=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function V(e,i,t){if(!e||typeof e!="object"){t.push(a("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){l(e.domainId)||t.push(a("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),l(e.datasetName)||t.push(a("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){l(e.connectionId)||t.push(a("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),l(e.tableName)||t.push(a("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){l(e.connectionId)||t.push(a("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}t.push(a("invalid_source_kind","Source kind is not supported.",i))}function f(e,i,t,n={}){if(!e||!c(e)){n.required&&t.push(a("missing_field_ref","Field reference needs a name.",i));return}l(e.name)||t.push(a("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&V(e.source,`${i}.source`,t),_(e.aggregate,`${i}.aggregate`,t)}function _(e,i,t){e!==void 0&&(typeof e!="string"||!fe.has(e))&&t.push(a("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}const pe=new Set(["measure","group","date","id","filter"]),_e=new Set(["row","aggregate"]),H=new Set(["string","number","boolean","date","datetime","unknown"]),ge=new Set(["number","currency","percent","percentage","scientific","date","datetime","duration","string"]),ve=new Set(["millisecond","second","minute","hour","day"]),be=new Set(["compact","digital","long"]);function I(e,i,t){if(e===void 0)return;if(!c(e)){t.push(a("invalid_value_format","Value format must be a structured object.",i));return}const n=e;(typeof n.type!="string"||!ge.has(n.type))&&t.push(a("invalid_value_format_type","Value format type must be number, currency, percent, scientific, date, datetime, duration, or string.",`${i}.type`)),h(e.minimumFractionDigits,`${i}.minimumFractionDigits`,t),h(e.maximumFractionDigits,`${i}.maximumFractionDigits`,t),h(e.scale,`${i}.scale`,t),h(e.maxUnits,`${i}.maxUnits`,t),e.useGrouping!==void 0&&typeof e.useGrouping!="boolean"&&t.push(a("invalid_value_format_use_grouping","Value format useGrouping must be boolean.",`${i}.useGrouping`)),e.negativeStyle!==void 0&&e.negativeStyle!=="minus"&&e.negativeStyle!=="parentheses"&&t.push(a("invalid_value_format_negative_style","Value format negativeStyle must be minus or parentheses.",`${i}.negativeStyle`)),e.percentValueMode!==void 0&&e.percentValueMode!=="fraction"&&e.percentValueMode!=="whole"&&t.push(a("invalid_value_format_percent_mode","Value format percentValueMode must be fraction or whole.",`${i}.percentValueMode`));for(const s of["inputUnit","largestUnit","smallestUnit"]){const r=e[s];r!==void 0&&(typeof r!="string"||!ve.has(r))&&t.push(a("invalid_value_format_duration_unit","Duration format units must be millisecond, second, minute, hour, or day.",`${i}.${s}`))}e.outputStyle!==void 0&&(typeof e.outputStyle!="string"||!be.has(e.outputStyle))&&t.push(a("invalid_value_format_duration_style","Duration format outputStyle must be compact, digital, or long.",`${i}.outputStyle`))}function h(e,i,t){e!==void 0&&(typeof e!="number"||!Number.isFinite(e))&&t.push(a("invalid_value_format_number","Value format numeric options must be finite numbers.",i))}const ye=new Set(["additive","non_additive","ratio_of_sums","weighted","pre_aggregated","snapshot"]),he=new Set(["default","symmetric_aggregate","aggregate_then_join","weighted"]);function xe(e,i,t){if(!e||!c(e)){t.push(a("invalid_derived_field_input","Derived field inputs must be structured input references.",i));return}if(e.kind==="field"){f(e.field,`${i}.field`,t,{required:!0}),_(e.aggregate,`${i}.aggregate`,t);return}if(e.kind==="metric"){f(e.metric,`${i}.metric`,t,{required:!0});return}if(e.kind==="dimension"){f(e.dimension,`${i}.dimension`,t,{required:!0});return}t.push(a("invalid_derived_field_input","Derived field input kind must be field, metric, or dimension.",`${i}.kind`))}function N(e,i,t){if(!c(e)){t.push(a("invalid_result_column_ref","Result calculation references must use columnKey or field.",i));return}const n=l(e.columnKey),s=c(e.field);if(n===s){t.push(a("invalid_result_column_ref","Result calculation references must identify exactly one of columnKey or field.",i));return}s&&f(e.field,`${i}.field`,t,{required:!0})}function we(e,i,t){if(!c(e)){t.push(a("invalid_result_calculation_output","Result calculation output must be a structured object.",i));return}l(e.key)||t.push(a("invalid_result_calculation_output","Result calculation output needs a stable key.",`${i}.key`)),e.dataType!==void 0&&(typeof e.dataType!="string"||!H.has(e.dataType))&&t.push(a("invalid_result_calculation_output","Result calculation output dataType must be string, number, boolean, date, datetime, or unknown.",`${i}.dataType`)),I(e.format,`${i}.format`,t)}function $e(e,i,t){e!==void 0&&e!=="hour"&&e!=="day"&&e!=="week"&&e!=="month"&&e!=="quarter"&&e!=="year"&&t.push(a("invalid_time_grain","Time grain must be hour, day, week, month, quarter, or year.",i))}function G(e,i,t,n){e!=="asc"&&e!=="desc"&&t.push(a(n,"Sort direction must be asc or desc.",i))}function z(e,i,t,n){e!==void 0&&e!=="warehouseDefault"&&e!=="first"&&e!=="last"&&t.push(a(n,"Null ordering must be warehouseDefault, first, or last.",i))}function Q(e,i,t,n){e!==void 0&&e!=="global"&&e!=="withinParent"&&t.push(a(n,"Sort scope must be global or withinParent.",i))}function Se(e,i,t){e.enabled!==void 0&&typeof e.enabled!="boolean"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal enabled must be a boolean.",`${i}.enabled`)),e.position!==void 0&&e.position!=="before"&&e.position!=="after"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal position must be before or after.",`${i}.position`)),e.label!==void 0&&typeof e.label!="string"&&t.push(a("invalid_matrix_subtotal","Matrix subtotal label must be a string.",`${i}.label`))}function Me(e,i,t){if(G(e.direction,`${i}.direction`,t,"invalid_matrix_sort_direction"),z(e.nulls,`${i}.nulls`,t,"invalid_matrix_sort_nulls"),Q(e.scope,`${i}.scope`,t,"invalid_matrix_sort_scope"),!c(e.by)){t.push(a("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${i}.by`));return}if(e.by.kind!=="label"){if(e.by.kind==="field"){f(e.by.field,`${i}.by.field`,t,{required:!0}),_(e.by.aggregate,`${i}.by.aggregate`,t);return}t.push(a("invalid_matrix_sort_by","Matrix axis sort by must be label or field.",`${i}.by.kind`))}}function F(e,i,t,n){if(!Array.isArray(e))return n.required?t.push(a("missing_matrix_rows","Matrix intent needs at least one row axis level.",i)):e!==void 0&&t.push(a("invalid_matrix_columns","Matrix columns must be an array of axis levels.",i)),[];n.required&&e.length===0&&t.push(a("missing_matrix_rows","Matrix intent needs at least one row axis level.",i));const s=[];return e.forEach((r,o)=>{const u=`${i}.${o}`;if(!c(r)){t.push(a("invalid_matrix_axis_level","Matrix axis levels must be structured objects.",u));return}const d=r;s.push(d),d.id!==void 0&&!l(d.id)&&t.push(a("invalid_matrix_axis_level_id","Matrix axis level id must be a non-empty string.",`${u}.id`)),f(d.field,`${u}.field`,t,{required:!0}),$e(d.grain,`${u}.grain`,t),d.label!==void 0&&typeof d.label!="string"&&t.push(a("invalid_matrix_axis_label","Matrix axis level label must be a string.",`${u}.label`)),d.subtotal!==void 0&&typeof d.subtotal!="boolean"&&(c(d.subtotal)?Se(d.subtotal,`${u}.subtotal`,t):t.push(a("invalid_matrix_subtotal","Matrix subtotal must be a boolean or structured options object.",`${u}.subtotal`))),d.sortBy!==void 0&&(c(d.sortBy)?Me(d.sortBy,`${u}.sortBy`,t):t.push(a("invalid_matrix_sort_by","Matrix axis sortBy must be a structured object.",`${u}.sortBy`)))}),s}function Ae(e,i,t){if(!c(e)){t.push(a("invalid_matrix_total_behavior","Matrix total behavior must be a structured object.",i));return}if(e.kind!=="defaultAggregate"&&e.kind!=="blank"&&e.kind!=="labelOnly"&&e.kind!=="customAggregate"&&e.kind!=="percentOfParent"&&e.kind!=="percentOfGrandTotal"&&e.kind!=="customExpression"){t.push(a("invalid_matrix_total_behavior","Matrix total behavior kind is not supported.",`${i}.kind`));return}e.kind==="customAggregate"&&(Object.prototype.hasOwnProperty.call(e,"aggregate")?_(e.aggregate,`${i}.aggregate`,t):t.push(a("invalid_matrix_total_behavior","Custom matrix total behavior needs an aggregate.",`${i}.aggregate`))),e.kind==="customExpression"&&!l(e.expressionId)&&t.push(a("invalid_matrix_total_behavior","Custom matrix total behavior needs an expressionId.",`${i}.expressionId`)),e.kind==="labelOnly"&&e.label!==void 0&&typeof e.label!="string"&&t.push(a("invalid_matrix_total_behavior","Matrix label-only total behavior label must be a string.",`${i}.label`))}function ke(e,i,t){if(!Array.isArray(e)||e.length===0)return t.push(a("missing_matrix_values","Matrix intent needs at least one value field.",i)),[];const n=[];return e.forEach((s,r)=>{const o=`${i}.${r}`;if(!c(s)){t.push(a("invalid_matrix_value","Matrix values must be structured objects.",o));return}const u=s;n.push(u),u.id!==void 0&&!l(u.id)&&t.push(a("invalid_matrix_value_id","Matrix value id must be a non-empty string.",`${o}.id`)),f(u.field,`${o}.field`,t,{required:!0}),_(u.aggregate,`${o}.aggregate`,t),I(u.format,`${o}.format`,t),u.label!==void 0&&typeof u.label!="string"&&t.push(a("invalid_matrix_value_label","Matrix value label must be a string.",`${o}.label`)),u.totalBehavior!==void 0&&Ae(u.totalBehavior,`${o}.totalBehavior`,t)}),n}function Ie(e,i,t){if(!c(e)){t.push(a("invalid_matrix_totals","Matrix totals must be a structured object.",i));return}for(const n of["rows","columns"]){const s=e[n];s!==void 0&&s!==!0&&s!==!1&&s!=="perLevel"&&t.push(a("invalid_matrix_totals","Matrix total axis setting must be a boolean or perLevel.",`${i}.${n}`))}if(e.grandTotal!==void 0&&typeof e.grandTotal!="boolean")if(!c(e.grandTotal))t.push(a("invalid_matrix_totals","Matrix grandTotal must be a boolean or structured object.",`${i}.grandTotal`));else for(const n of["rows","columns"]){const s=e.grandTotal[n];s!==void 0&&typeof s!="boolean"&&t.push(a("invalid_matrix_totals","Matrix grandTotal rows/columns must be booleans.",`${i}.grandTotal.${n}`))}e.rowPosition!==void 0&&e.rowPosition!=="top"&&e.rowPosition!=="bottom"&&t.push(a("invalid_matrix_totals","Matrix row total position must be top or bottom.",`${i}.rowPosition`)),e.columnPosition!==void 0&&e.columnPosition!=="left"&&e.columnPosition!=="right"&&t.push(a("invalid_matrix_totals","Matrix column total position must be left or right.",`${i}.columnPosition`))}function M(e,i,t,n){if(!Array.isArray(e)){n.push(a("invalid_matrix_path","Matrix member path must be an array of path segments.",i));return}e.forEach((s,r)=>{const o=`${i}.${r}`;if(!c(s)){n.push(a("invalid_matrix_path","Matrix path segment must be a structured object.",o));return}const u=s;if(!l(u.levelId)){n.push(a("stable_id_required","Matrix path segments must reference an explicit public axis level id.",`${o}.levelId`));return}Object.prototype.hasOwnProperty.call(s,"value")||n.push(a("invalid_matrix_path","Matrix path segments must include a value property; use explicit null for null members.",`${o}.value`)),t.has(u.levelId)||n.push(a("stable_id_required","Matrix path segment levelId must match an explicit public axis level id.",`${o}.levelId`))})}function q(e,i,t,n){if(!c(e)){n.push(a("invalid_matrix_expansion","Matrix expansion axis options must be structured objects.",i));return}e.defaultDepth!==void 0&&(typeof e.defaultDepth!="number"||!Number.isInteger(e.defaultDepth)||e.defaultDepth<0)&&n.push(a("invalid_matrix_expansion","Matrix expansion defaultDepth must be a non-negative integer.",`${i}.defaultDepth`)),e.lazy!==void 0&&typeof e.lazy!="boolean"&&n.push(a("invalid_matrix_expansion","Matrix expansion lazy must be a boolean.",`${i}.lazy`)),e.expandedPaths!==void 0&&(Array.isArray(e.expandedPaths)?e.expandedPaths.forEach((s,r)=>{M(s,`${i}.expandedPaths.${r}`,t,n)}):n.push(a("invalid_matrix_expansion","Matrix expandedPaths must be an array of member paths.",`${i}.expandedPaths`)))}function De(e,i,t,n){if(e!==void 0){if(!c(e)){n.push(a("invalid_matrix_expansion","Matrix expansion must be a structured object.","expansion"));return}e.rows!==void 0&&q(e.rows,"expansion.rows",i,n),e.columns!==void 0&&q(e.columns,"expansion.columns",t,n)}}function Re(e,i,t,n,s){if(e!==void 0){if(!Array.isArray(e)){s.push(a("invalid_matrix_sort","Matrix sort must be an array of sort rules.","sort"));return}e.forEach((r,o)=>{const u=`sort.${o}`;if(!c(r)){s.push(a("invalid_matrix_sort","Matrix sort rule must be a structured object.",u));return}const d=r;d.axis!=="row"&&d.axis!=="column"&&s.push(a("invalid_matrix_sort","Matrix sort axis must be row or column.",`${u}.axis`));const m=d.axis==="column"?t:i;if(d.targetId!==void 0&&!m.has(d.targetId)&&s.push(a("stable_id_required","Matrix sort targetId must reference an explicit public axis level id.",`${u}.targetId`)),G(d.direction,`${u}.direction`,s,"invalid_matrix_sort_direction"),z(d.nulls,`${u}.nulls`,s,"invalid_matrix_sort_nulls"),Q(d.scope,`${u}.scope`,s,"invalid_matrix_sort_scope"),!c(d.by)){s.push(a("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${u}.by`));return}if(d.by.kind!=="label"){if(d.by.kind==="field"){f(d.by.field,`${u}.by.field`,s,{required:!0}),_(d.by.aggregate,`${u}.by.aggregate`,s);return}if(d.by.kind==="value"){(!l(d.by.valueId)||!n.has(d.by.valueId))&&s.push(a("stable_id_required","Matrix value sort must reference an explicit public value id.",`${u}.by.valueId`)),d.by.rowPath!==void 0&&M(d.by.rowPath,`${u}.by.rowPath`,i,s),d.by.columnPath!==void 0&&M(d.by.columnPath,`${u}.by.columnPath`,t,s);return}s.push(a("invalid_matrix_sort_by","Matrix sort by must be label, field, or value.",`${u}.by.kind`))}})}}function Pe(e,i){if(e!==void 0){if(!c(e)){i.push(a("invalid_matrix_layout","Matrix layout must be a structured object.","layout"));return}e.hierarchy!==void 0&&e.hierarchy!=="compact"&&e.hierarchy!=="tabular"&&e.hierarchy!=="outline"&&i.push(a("invalid_matrix_layout","Matrix hierarchy layout must be compact, tabular, or outline.","layout.hierarchy")),e.valuesPlacement!==void 0&&e.valuesPlacement!=="columns"&&e.valuesPlacement!=="rows"&&i.push(a("invalid_matrix_layout","Matrix valuesPlacement must be columns or rows.","layout.valuesPlacement")),e.stickyRowHeaders!==void 0&&typeof e.stickyRowHeaders!="boolean"&&i.push(a("invalid_matrix_layout","Matrix stickyRowHeaders must be a boolean.","layout.stickyRowHeaders")),e.stickyColumnHeaders!==void 0&&typeof e.stickyColumnHeaders!="boolean"&&i.push(a("invalid_matrix_layout","Matrix stickyColumnHeaders must be a boolean.","layout.stickyColumnHeaders"))}}function B(e,i,t){if(!c(e)){t.push(a("invalid_matrix_display_limits","Matrix display limit must be a structured object.",i));return}(typeof e.limit!="number"||!Number.isInteger(e.limit)||e.limit<1)&&t.push(a("invalid_matrix_display_limits","Matrix display limit must be a positive integer.",`${i}.limit`)),e.by!==void 0&&e.by!=="label"&&e.by!=="value"&&t.push(a("invalid_matrix_display_limits","Matrix display limit by must be label or value.",`${i}.by`)),e.direction!==void 0&&e.direction!=="top"&&e.direction!=="bottom"&&t.push(a("invalid_matrix_display_limits","Matrix display limit direction must be top or bottom.",`${i}.direction`)),e.others!==void 0&&typeof e.others!="boolean"&&(c(e.others)?e.others.label!==void 0&&typeof e.others.label!="string"&&t.push(a("invalid_matrix_display_limits","Matrix display limit others label must be a string.",`${i}.others.label`)):t.push(a("invalid_matrix_display_limits","Matrix display limit others must be a boolean or structured object.",`${i}.others`)))}function Te(e,i){if(e!==void 0){if(!c(e)){i.push(a("invalid_matrix_display_limits","Matrix displayLimits must be a structured object.","displayLimits"));return}e.rows!==void 0&&B(e.rows,"displayLimits.rows",i),e.columns!==void 0&&B(e.columns,"displayLimits.columns",i)}}function Ee(e,i){var d;((d=e.source)==null?void 0:d.kind)==="sql"&&i.push(a("unsupported_matrix_sql_source","Matrix analytics intent does not support raw SQL sources.","source.kind"));const t=F(e.rows,"rows",i,{required:!0}),n=F(e.columns,"columns",i,{required:!1}),s=ke(e.values,"values",i);x(e.filters,"filters",i),e.totals!==void 0&&Ie(e.totals,"totals",i),w(t.map(m=>m.id),"rows","row axis level",i),w(n.map(m=>m.id),"columns","column axis level",i),w(s.map(m=>m.id),"values","value",i);const r=new Set(t.map(m=>m.id).filter(m=>l(m))),o=new Set(n.map(m=>m.id).filter(m=>l(m))),u=new Set(s.map(m=>m.id).filter(m=>l(m)));Re(e.sort,r,o,u,i),De(e.expansion,r,o,i),Pe(e.layout,i),Te(e.displayLimits,i)}function Oe(e,i){if(e.analysis===void 0)return;if(!c(e.analysis)){i.push(a("invalid_metric_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(a("invalid_metric_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(a("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(a("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain")),e.analysis.orderBy!==void 0&&e.analysis.orderBy!=="absolute_change"&&e.analysis.orderBy!=="positive_change"&&e.analysis.orderBy!=="negative_change"&&e.analysis.orderBy!=="period"&&i.push(a("invalid_metric_analysis","Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.","analysis.orderBy"));const{timeWindow:t}=e.analysis;t!==void 0&&A(t,"analysis.timeWindow",i)}function A(e,i,t){if(!c(e)){t.push(a("invalid_time_window","Time window must be a structured object.",i));return}if(e.kind!==void 0&&e.kind!=="relative"&&e.kind!=="absolute"&&t.push(a("invalid_time_window","Time window kind must be relative or absolute.",`${i}.kind`)),e.kind==="absolute"){if(l(e.start)||t.push(a("invalid_time_window","Absolute time window start must be a non-empty ISO date or timestamp string.",`${i}.start`)),l(e.end)||t.push(a("invalid_time_window","Absolute time window end must be a non-empty ISO date or timestamp string.",`${i}.end`)),l(e.start)&&l(e.end)){const n=$(e.start),s=$(e.end);n||t.push(a("invalid_time_window","Absolute time window start must be a valid ISO date or timestamp.",`${i}.start`)),s||t.push(a("invalid_time_window","Absolute time window end must be a valid ISO date or timestamp.",`${i}.end`)),n&&s&&n.getTime()>s.getTime()&&t.push(a("invalid_time_window","Absolute time window start must be before or equal to end.",i))}return}e.unit!=="second"&&e.unit!=="minute"&&e.unit!=="hour"&&e.unit!=="day"&&e.unit!=="week"&&e.unit!=="month"&&e.unit!=="quarter"&&e.unit!=="year"&&t.push(a("invalid_time_window","Time window unit must be second, minute, hour, day, week, month, quarter, or year.",`${i}.unit`)),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<=0)&&t.push(a("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&t.push(a("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`)),e.completeness!==void 0&&e.completeness!=="include_partial"&&e.completeness!=="complete_periods"&&t.push(a("invalid_time_window","Time window completeness must be include_partial or complete_periods.",`${i}.completeness`))}function x(e,i,t){if(e!==void 0){if(!Array.isArray(e)){t.push(a("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((n,s)=>{var d;const r=`${i}.${s}`;if(!c(n)){t.push(a("invalid_analytics_filter","Analytics filter must be a structured object.",r));return}const o=n;f(o.field,`${r}.field`,t,{required:!0}),o.scope!==void 0&&o.scope!=="row"&&o.scope!=="aggregate"&&t.push(a("invalid_analytics_filter_scope","Analytics filter scope must be row or aggregate.",`${r}.scope`)),o.scope==="aggregate"&&((d=o.field)==null?void 0:d.role)!==void 0&&o.field.role!=="measure"&&t.push(a("invalid_analytics_filter_scope","Aggregate-scope analytics filters must target a measure field.",`${r}.scope`));const u=o.operator==="is_null"||o.operator==="is_not_null";if(o.operator!==void 0&&o.operator!=="="&&o.operator!=="!="&&o.operator!=="in"&&o.operator!=="not_in"&&o.operator!=="contains"&&o.operator!=="not_contains"&&o.operator!=="between"&&o.operator!=="not_between"&&o.operator!==">"&&o.operator!==">="&&o.operator!=="<"&&o.operator!=="<="&&o.operator!=="is_null"&&o.operator!=="is_not_null"&&t.push(a("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${r}.operator`)),o.values===void 0&&!u&&t.push(a("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",r)),u&&o.values!==void 0){t.push(a("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${r}.values`));return}if(o.values!==void 0&&!Array.isArray(o.values)){t.push(a("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${r}.values`));return}if(o.values!==void 0){const m=o.values.length;if(o.operator==="between"||o.operator==="not_between"){m!==2&&t.push(a("invalid_analytics_filter_values","Between analytics filters must include exactly two values.",`${r}.values`));return}(o.operator==="contains"||o.operator==="not_contains"||o.operator==="="||o.operator==="!="||o.operator===">"||o.operator===">="||o.operator==="<"||o.operator==="<="||o.operator===void 0)&&m!==1&&t.push(a("invalid_analytics_filter_values","Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",`${r}.values`))}})}}function Y(e){const i=[];if(!c(e))return i.push(a("invalid_derived_field","Derived field definition must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(e.kind!=="derived_field"&&i.push(a("invalid_derived_field_kind","Derived field kind must be derived_field.","kind")),l(e.name)||i.push(a("invalid_derived_field_name","Derived field needs a name.","name")),l(e.label)||i.push(a("invalid_derived_field_label","Derived field needs a label.","label")),pe.has(e.resultRole)||i.push(a("invalid_derived_field_role","Derived field resultRole must be measure, group, date, id, or filter.","resultRole")),H.has(e.dataType)||i.push(a("invalid_derived_field_data_type","Derived field dataType must be string, number, boolean, date, datetime, or unknown.","dataType")),_e.has(e.computeStage)||i.push(a("invalid_derived_field_compute_stage","Derived field computeStage must be row or aggregate.","computeStage")),e.computeStage==="aggregate"&&e.resultRole!=="measure"&&i.push(a("invalid_derived_field_compute_stage","Aggregate-stage derived fields must have resultRole measure.","computeStage")),e.resultRole!=="measure"&&e.defaultAggregate!==void 0&&i.push(a("invalid_derived_field_aggregate","Only measure derived fields may declare defaultAggregate.","defaultAggregate")),e.computeStage==="row"&&e.resultRole==="measure"&&e.defaultAggregate===void 0&&i.push(a("missing_derived_field_default_aggregate","Row-stage measure derived fields must declare defaultAggregate so row results have explicit rollup semantics.","defaultAggregate")),_(e.defaultAggregate,"defaultAggregate",i),e.aggregationBehavior!==void 0&&!ye.has(e.aggregationBehavior)&&i.push(a("invalid_derived_field_aggregation_behavior","Derived field aggregationBehavior is not supported.","aggregationBehavior")),e.aggregationStrategy!==void 0&&!he.has(e.aggregationStrategy)&&i.push(a("invalid_derived_field_aggregation_strategy","Derived field aggregationStrategy is not supported.","aggregationStrategy")),l(e.expression)||i.push(a("invalid_derived_field_expression","Derived field needs a named-token expression.","expression")),e.expressionLanguage!==void 0&&e.expressionLanguage!=="semaphor_sql_template"&&i.push(a("invalid_derived_field_expression_language","Derived field expressionLanguage must be semaphor_sql_template.","expressionLanguage")),!c(e.inputs)||Object.keys(e.inputs).length===0?i.push(a("invalid_derived_field_inputs","Derived field needs at least one typed input.","inputs")):Object.entries(e.inputs).forEach(([t,n])=>{if(!l(t)){i.push(a("invalid_derived_field_input_name","Derived field input names must be non-empty strings.","inputs"));return}xe(n,`inputs.${t}`,i)}),l(e.expression)&&c(e.inputs)){const t=ce(e.expression),n=new Set(t),s=Object.keys(e.inputs).filter(r=>l(r));t.forEach(r=>{Object.prototype.hasOwnProperty.call(e.inputs,r)||i.push(a("invalid_derived_field_expression_token",`Derived field expression token "{${r}}" needs a matching inputs.${r} entry.`,"expression"))}),s.forEach(r=>{n.has(r)||i.push(a("unused_derived_field_input",`Derived field input "${r}" is not referenced by expression.`,`inputs.${r}`))})}return I(e.format,"format",i),e.tags!==void 0&&(!Array.isArray(e.tags)||e.tags.some(t=>!l(t)))&&i.push(a("invalid_derived_field_tags","Derived field tags must be non-empty strings.","tags")),{ok:i.length===0,errors:i,warnings:[]}}function Ne(e){const i=[];if(!c(e))return i.push(a("invalid_result_calculation","Result calculation must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(l(e.id)||i.push(a("invalid_result_calculation_id","Result calculation needs an id.","id")),l(e.label)||i.push(a("invalid_result_calculation_label","Result calculation needs a label.","label")),e.kind!=="percent_of_total"&&e.kind!=="rank"&&e.kind!=="running_total"&&e.kind!=="previous_row_delta"&&i.push(a("invalid_result_calculation_kind","Result calculation kind must be percent_of_total, rank, running_total, or previous_row_delta.","kind")),N(e.input,"input",i),we(e.output,"output",i),e.kind==="percent_of_total"){const t=e.denominator;t!==void 0&&(c(t)?t.scope==="population"?(f(t.metric,"denominator.metric",i,{required:!0}),x(t.filters,"denominator.filters",i)):t.scope!=="returned_result"&&i.push(a("invalid_result_calculation_denominator","Percent-of-total denominator scope must be returned_result or population.","denominator.scope")):i.push(a("invalid_result_calculation_denominator","Percent-of-total denominator must be a structured object.","denominator")))}return e.kind==="rank"&&e.order!==void 0&&e.order!=="asc"&&e.order!=="desc"&&i.push(a("invalid_result_calculation_order","Rank result calculation order must be asc or desc.","order")),(e.kind==="running_total"||e.kind==="previous_row_delta")&&e.orderBy!==void 0&&N(e.orderBy,"orderBy",i),{ok:i.length===0,errors:i,warnings:[]}}function D(e){var n;const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:t,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]};if(e.version!==void 0&&e.version!==1&&i.push(a("invalid_version","Analytics intent version must be 1.","version")),V(e.source,"source",i),Fe(e,i),e.kind==="metric"){const s=Array.isArray(e.metrics)?e.metrics.filter(r=>c(r)&&l(r.name)):[];if(!Array.isArray(e.metrics)||e.metrics.length===0?i.push(a("missing_metric","Metric intent needs at least one metric.","metrics")):e.metrics.some(r=>!c(r)||!l(r.name))&&i.push(a("invalid_metric_list","Metric intent metrics must be an array of field references with names.","metrics")),s.forEach((r,o)=>{f(r,`metrics.${o}`,i,{required:!0})}),s.length>0&&!ee(s)){const r=s.find((o,u)=>s.some((d,m)=>m!==u&&U(d,o)));r&&i.push(a("duplicate_metric",ie(r),"metrics"))}if(c(e.primaryMetric)&&l(e.primaryMetric.name)&&k(e.primaryMetric,s).length>1&&i.push(a("ambiguous_primary_metric","Metric intent primaryMetric must identify exactly one selected metric.","primaryMetric")),e.primaryMetric!==void 0&&(f(e.primaryMetric,"primaryMetric",i,{required:!0}),c(e.primaryMetric)&&l(e.primaryMetric.name)&&s.length>0&&!ae(e.primaryMetric,s)&&i.push(a("invalid_primary_metric","Metric intent primaryMetric must match one metric field reference.","primaryMetric"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(a("invalid_metric_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(r=>!c(r)||!l(r.name))&&i.push(a("invalid_metric_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&f(e.dateField,"dateField",i),e.timeWindow!==void 0&&(A(e.timeWindow,"timeWindow",i),e.dateField||i.push(a("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((r,o)=>{f(r,`dimensions.${o}`,i)}),e.orderBy!==void 0){if(!c(e.orderBy))i.push(a("invalid_metric_order_by","Metric intent orderBy must be a structured object.","orderBy"));else if(f(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(a("invalid_metric_order_direction","Metric intent orderBy direction must be asc or desc.","orderBy.direction")),c(e.orderBy.field)&&l(e.orderBy.field.name)){const r=[...s,...e.timeGrain&&e.dateField&&c(e.dateField)?[e.dateField]:[],...Array.isArray(e.dimensions)?e.dimensions.filter(o=>c(o)&&l(o.name)):[]];r.length>0&&!ne(e.orderBy.field,r)&&i.push(a("invalid_metric_order_by","Metric intent orderBy.field must match one selected metric, grouped dateField, or dimension.","orderBy.field"))}}Oe(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(a("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(s=>!c(s)||!l(s.name))&&i.push(a("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((s,r)=>{f(s,`fields.${r}`,i)}),e.dateField!==void 0&&f(e.dateField,"dateField",i),O(e.pagination,"pagination",i),e.timeWindow!==void 0&&(A(e.timeWindow,"timeWindow",i),e.dateField||i.push(a("missing_time_window_date_field","Records timeWindow needs a dateField.","dateField"))),x(e.filters,"filters",i),Array.isArray(e.filters)&&e.filters.forEach((s,r)=>{c(s)&&s.scope==="aggregate"&&i.push(a("unsupported_record_filter_scope","Records intents support row-scope filters only. Use a metric intent for aggregate-scope filters.",`filters.${r}.scope`))}),e.orderBy!==void 0&&(c(e.orderBy)?(f(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(a("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(a("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy")))):e.kind==="inputOptions"?((!e.field||!l(e.field.name))&&i.push(a("missing_input_options_field","Input options intent needs a field.","field")),f(e.field,"field",i,{required:!0})):e.kind==="matrix"?Ee(e,i):e.kind==="sql"?(((n=e.source)==null?void 0:n.kind)!=="sql"&&i.push(a("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),l(e.sql)||i.push(a("missing_sql","SQL analytics intent needs SQL text.","sql")),te(e.defaultParameters,"defaultParameters",i),Array.isArray(e.fields)&&e.fields.forEach((s,r)=>{f(s,`fields.${r}`,i)}),O(e.pagination,"pagination",i)):i.push(a("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:Be(i)}}function Fe(e,i){if(!(!("derivedFields"in e)||e.derivedFields===void 0)){if(!Array.isArray(e.derivedFields)){i.push(a("invalid_derived_fields","Analytics intent derivedFields must be an array of derived field definitions.","derivedFields"));return}e.derivedFields.forEach((t,n)=>{Y(t).errors.forEach(r=>{i.push({...r,path:r.path?`derivedFields.${n}.${r.path}`:`derivedFields.${n}`})})})}}function K(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_operation_intent","Operation intent must be a structured object.")],warnings:t,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(a("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(a("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((n,s)=>{l(n.id)||i.push(a("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${s}.id`)),l(n.prompt)||i.push(a("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${s}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(l(e.instruction)||i.push(a("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const n=D(e.analyticsIntent);i.push(...n.errors),t.push(...n.warnings)}}else i.push(a("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:X(i)}}function qe(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:t,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(a("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(a("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const n=K(e.operationIntent);return i.push(...n.errors),t.push(...n.warnings),Array.isArray(e.plannedToolCalls)||i.push(a("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:t,repairHints:X(i)}}function X(e){return e.map(i=>({code:i.code,recommendedNextStep:i.code==="missing_obligations"?"Normalize the user request into one or more typed analytics obligations before recovery planning.":"Correct the operation/recovery contract shape before planning execution."}))}function Be(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_metric":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose one exact metric from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_matrix_rows":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Choose at least one row axis level for the matrix table."};case"missing_matrix_values":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose at least one value field for the matrix table."};case"unsupported_matrix_sql_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use a semantic or explorer-backed source for matrix tables; raw SQL matrix tables are not supported."};case"missing_input_options_field":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the exact field whose option values should be listed."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function je(e,i,t,n){if(!e||typeof e!="object"){t.push(a("invalid_view","Dashboard view must be an object.",i));return}if(l(e.title)||t.push(a("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){t.push(a("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){l(e.text)||n.push(a("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){t.push(a("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}e.presentation.kind==="matrixTable"&&e.analytics.kind!=="matrix"&&t.push(a("invalid_matrix_view_analytics","Matrix table views need matrix analytics intent.",`${i}.analytics.kind`));const s=D(e.analytics);for(const r of s.errors)t.push(a(r.code,r.message,`${i}.analytics${r.path?`.${r.path}`:""}`));for(const r of s.warnings)n.push(a(r.code,r.message,`${i}.analytics${r.path?`.${r.path}`:""}`))}function Ce(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[a("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:t};e.version!==1&&i.push(a("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(a("invalid_kind","Experience intent kind must be dashboard.")),l(e.title)||i.push(a("missing_title","Dashboard intent needs a title.","title"));const n=Array.isArray(e.inputs)?e.inputs:[],s=S(n.filter(c).map(d=>d.id).filter(d=>typeof d=="string"));s&&i.push(a("duplicate_input_id",`Duplicate input id: ${s}.`,"inputs"));for(const[d,m]of n.entries()){const p=`inputs.${d}`;if(!c(m)){i.push(a("invalid_input","Dashboard input must be an object.",p));continue}l(m.id)||i.push(a("missing_input_id","Input needs an id.",`${p}.id`)),l(m.label)||i.push(a("missing_input_label","Input needs a label.",`${p}.label`)),!m.field||!l(m.field.name)?i.push(a("missing_input_field","Input needs a field.",`${p}.field`)):f(m.field,`${p}.field`,i)}const r=Array.isArray(e.sections)?e.sections:[];r.length===0&&i.push(a("missing_sections","Dashboard intent needs at least one section.","sections"));const o=r.flatMap(d=>d&&typeof d=="object"&&Array.isArray(d.views)?d.views.filter(c).map(m=>m.id).filter(m=>!!m):[]),u=S(o);u&&i.push(a("duplicate_view_id",`Duplicate dashboard view id: ${u}.`,"sections"));for(const[d,m]of r.entries()){const p=`sections.${d}`;if(!m||typeof m!="object"){i.push(a("invalid_section","Dashboard section must be an object.",p));continue}if(l(m.title)||i.push(a("missing_section_title","Dashboard section needs a title.",p)),!Array.isArray(m.views)||m.views.length===0){i.push(a("missing_section_views","Dashboard section needs at least one view.",`${p}.views`));continue}for(const[b,y]of m.views.entries())je(y,`${p}.views.${b}`,i,t)}return{ok:i.length===0,errors:i,warnings:t}}exports.normalizeSemaphorAnalyticsFilterOperator=j;exports.normalizeSemaphorInputOperator=J;exports.parseSemaphorIsoTimeWindowBoundary=$;exports.validateSemaphorAnalyticsIntent=D;exports.validateSemaphorAnalyticsRecoveryPlan=qe;exports.validateSemaphorDashboardIntent=Ce;exports.validateSemaphorDerivedFieldDefinition=Y;exports.validateSemaphorOperationIntent=K;exports.validateSemaphorResultCalculation=Ne;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-DlLvzmJF.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-D5Pp-5LR.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as o } from "../chunks/index-C0Qnfr_7.js";
1
+ import { D as o } from "../chunks/index-Clqr43Sr.js";
2
2
  import { C as s, E as C } from "../chunks/common-types-4bjoIgvm.js";
3
3
  export {
4
4
  s as CONTROL_CARD_DEFAULT_VALUE,
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/contracts-CtB2VONT.js"),N=require("../chunks/source-identity-C-xaeE_I.js"),z=require("../chunks/validators-DHee9kM2.js"),De=require("../chunks/catalog-field-grounding-Du6mKDcF.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function oe(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function M(e){return oe(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function ve(e){return N.semaphorSourceIdentityKey(e)}function K(e,t){return N.semaphorSourcesReferToSameDataset(e,t)}function se(e,t){return N.preferSemaphorSourceMetadata(e,t)}function R(e){const t=[];for(const r of e){const n=t.findIndex(o=>K(o,r));n===-1?t.push(r):t[n]=se(t[n],r)}return t}function Ce(e){return R(e)[0]}function G(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!N.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return M(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&N.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function S(e,t){const r=W(e==null?void 0:e.source);return r?G(r,t):void 0}function de({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const o=[r,...n||[]],a=W(e),i=a?G(a,ae(a,o)):void 0;if(i)return i;if(e!==void 0)return;const d=S(t,r),s=d?G(d,ae(d,o)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(r)}function ke(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=S(e),n=S(t);return!r||!n?!0:K(r,n)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function ce(e){var t,r;return C(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function xe(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Te(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Fe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Re(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Ne(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Me(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function le(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ue({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(ce),n=new Set(r.filter(Boolean));return r.some(o=>!o)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function E(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=Te(e);return ce(e)===t.domainId?r&&t.datasetId?r===t.datasetId:xe(e)===t.datasetName:!1}return t.kind==="physical"?Fe(e)===t.connectionId&&Re(e)===t.tableName&&Ne(e)===(t.databaseName||"")&&Me(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(r=>E(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function B(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function fe({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=le(e);if(!n){if(t.length<=1)return;r.push(p("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(o=>E(o,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function H(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function ie(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Oe(e){var r;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...H(e.metrics),e.primaryMetric,e.dateField,...H(e.dimensions),...ie(e.filters).map(n=>n.field)])):e.kind==="records"?t.push(...P([...H(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field,...ie(e.filters).map(n=>n.field)])):e.kind==="inputOptions"?t.push(...P([e.field])):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function pe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Oe(e.analyticsIntent))if(n&&!t.some(o=>E(o,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function he({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=z.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function me({datasets:e,errors:t,requireAtLeastOne:r}){const n=ue({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function ge(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];me({datasets:o,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=a[0];i&&i.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(i==null?void 0:i.cards)||[];d.length>v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=B(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),fe({card:l,datasets:o,errors:t}),he({card:l,errors:t}),pe({card:l,datasets:o,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),A=B(I);A&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${A}.`));const w=h.map(l=>l.variableName).filter(Boolean)||[],y=B(w);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function be(e){var i;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(i=r.dashboardId)!=null&&i.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];me({datasets:o,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(fe({card:d.card,datasets:o,errors:t}),he({card:d.card,errors:t}),pe({card:d.card,datasets:o,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:n}}const Be={lg:48,md:36,sm:24,xs:12,xxs:6};function Pe(e,t){let r=0,n=0,o=0;return e.map(a=>{const i=Math.min(a.w,t);r>0&&r+i>t&&(r=0,n+=o,o=0);const d={i:a.frameId,x:r,y:n,w:i,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=i,o=Math.max(o,a.h),d})}function ze(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),o=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),i=a.slice(0,1),d=a.slice(i.length);return{kpis:r,introText:i,charts:n,tables:o,supportingText:d}}function Ee(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function qe(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function Ve(e){const{item:t,band:r,index:n,bandCount:o,breakpoint:a,columns:i}=e;return r==="kpi"?{...t,band:r,w:Ee(o,a,i),h:15,minW:Math.min(6,i),minH:12}:r==="table"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,i),minH:18}:r==="introText"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?i/2:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:{...t,band:r,w:qe(n,o,a,i),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,i),minH:16}}function T(e,t,r,n){return e.map((o,a)=>Ve({item:o,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function q(e){const t=ze(e);return Object.fromEntries(v.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Be[r],o=[...T(t.introText,"introText",r,n),...T(t.kpis,"kpi",r,n),...T(t.charts,"chart",r,n),...T(t.tables,"table",r,n),...T(t.supportingText,"supportingText",r,n)];return[r,Pe(o,n)]}))}function He(e){const t=De.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ge(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=He(e.dataType),n=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const o=Array.isArray(t)?t:[t],a=r==="date"?We(o):Ge(o);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ie(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ue(e,t,r){const n=(t||[]).filter(o=>o.scope==="card"&&o.targetCardId===r).map(o=>o.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function U(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Ke(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=U(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Xe(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:U(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:U(e.excludeCardIds,t)}:{}}}function Je(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,i)=>{const d=Ke(a.scope,t);if(d===null)return n.push(Ie("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:Xe(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Qe(e){var w,y;const t=ge(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/contracts-CtB2VONT.js"),N=require("../chunks/source-identity-C-xaeE_I.js"),z=require("../chunks/validators-jpoYhpHh.js"),De=require("../chunks/catalog-field-grounding-Du6mKDcF.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function oe(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function M(e){return oe(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function ve(e){return N.semaphorSourceIdentityKey(e)}function K(e,t){return N.semaphorSourcesReferToSameDataset(e,t)}function se(e,t){return N.preferSemaphorSourceMetadata(e,t)}function R(e){const t=[];for(const r of e){const n=t.findIndex(o=>K(o,r));n===-1?t.push(r):t[n]=se(t[n],r)}return t}function Ce(e){return R(e)[0]}function G(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!N.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return M(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&N.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function S(e,t){const r=W(e==null?void 0:e.source);return r?G(r,t):void 0}function de({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const o=[r,...n||[]],a=W(e),i=a?G(a,ae(a,o)):void 0;if(i)return i;if(e!==void 0)return;const d=S(t,r),s=d?G(d,ae(d,o)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(r)}function ke(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=S(e),n=S(t);return!r||!n?!0:K(r,n)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function ce(e){var t,r;return C(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function xe(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Te(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Fe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Re(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Ne(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Me(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function le(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ue({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(ce),n=new Set(r.filter(Boolean));return r.some(o=>!o)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function E(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=Te(e);return ce(e)===t.domainId?r&&t.datasetId?r===t.datasetId:xe(e)===t.datasetName:!1}return t.kind==="physical"?Fe(e)===t.connectionId&&Re(e)===t.tableName&&Ne(e)===(t.databaseName||"")&&Me(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(r=>E(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function B(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function fe({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=le(e);if(!n){if(t.length<=1)return;r.push(p("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(o=>E(o,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function H(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function ie(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Oe(e){var r;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...H(e.metrics),e.primaryMetric,e.dateField,...H(e.dimensions),...ie(e.filters).map(n=>n.field)])):e.kind==="records"?t.push(...P([...H(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field,...ie(e.filters).map(n=>n.field)])):e.kind==="inputOptions"?t.push(...P([e.field])):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function pe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Oe(e.analyticsIntent))if(n&&!t.some(o=>E(o,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function he({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=z.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function me({datasets:e,errors:t,requireAtLeastOne:r}){const n=ue({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function ge(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];me({datasets:o,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=a[0];i&&i.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(i==null?void 0:i.cards)||[];d.length>v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=B(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),fe({card:l,datasets:o,errors:t}),he({card:l,errors:t}),pe({card:l,datasets:o,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),A=B(I);A&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${A}.`));const w=h.map(l=>l.variableName).filter(Boolean)||[],y=B(w);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function be(e){var i;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(i=r.dashboardId)!=null&&i.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];me({datasets:o,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(fe({card:d.card,datasets:o,errors:t}),he({card:d.card,errors:t}),pe({card:d.card,datasets:o,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:n}}const Be={lg:48,md:36,sm:24,xs:12,xxs:6};function Pe(e,t){let r=0,n=0,o=0;return e.map(a=>{const i=Math.min(a.w,t);r>0&&r+i>t&&(r=0,n+=o,o=0);const d={i:a.frameId,x:r,y:n,w:i,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=i,o=Math.max(o,a.h),d})}function ze(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),o=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),i=a.slice(0,1),d=a.slice(i.length);return{kpis:r,introText:i,charts:n,tables:o,supportingText:d}}function Ee(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function qe(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function Ve(e){const{item:t,band:r,index:n,bandCount:o,breakpoint:a,columns:i}=e;return r==="kpi"?{...t,band:r,w:Ee(o,a,i),h:15,minW:Math.min(6,i),minH:12}:r==="table"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,i),minH:18}:r==="introText"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?i/2:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:{...t,band:r,w:qe(n,o,a,i),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,i),minH:16}}function T(e,t,r,n){return e.map((o,a)=>Ve({item:o,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function q(e){const t=ze(e);return Object.fromEntries(v.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Be[r],o=[...T(t.introText,"introText",r,n),...T(t.kpis,"kpi",r,n),...T(t.charts,"chart",r,n),...T(t.tables,"table",r,n),...T(t.supportingText,"supportingText",r,n)];return[r,Pe(o,n)]}))}function He(e){const t=De.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ge(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=He(e.dataType),n=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const o=Array.isArray(t)?t:[t],a=r==="date"?We(o):Ge(o);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ie(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ue(e,t,r){const n=(t||[]).filter(o=>o.scope==="card"&&o.targetCardId===r).map(o=>o.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function U(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Ke(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=U(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Xe(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:U(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:U(e.excludeCardIds,t)}:{}}}function Je(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,i)=>{const d=Ke(a.scope,t);if(d===null)return n.push(Ie("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:Xe(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Qe(e){var w,y;const t=ge(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
2
2
  `)||"Dashboard plan is invalid.");const r=e.plan.sheets[0],n=[...t.warnings],o=[],a=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),i=new Map(e.cardArtifacts.map(c=>[c.planCardId,c.card.id])),d=[];for(const c of r.cards){const f=a.get(c.id);if(!f){const l=Ie("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);o.push(l);continue}n.push(...f.warnings||[]);const g=Ue(f.card,e.plan.calculatedFields,c.id);d.push({id:c.frameId,cards:[g],activeCardId:g.id})}if(d.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:s,defaultInputValues:u,warnings:h}=Je(e.plan,i);n.push(...h);const I=q(r.cards.filter(c=>d.some(f=>f.id===c.frameId)).map(c=>({frameId:c.frameId,priority:c.priority,role:c.role})));return{dashboard:{id:e.dashboardId,title:e.plan.title,description:e.plan.description||"",sheets:[{id:r.id,kind:"dashboard",title:r.title,description:r.description,frames:d,layouts:I,calculatedFields:(w=e.plan.calculatedFields)==null?void 0:w.filter(c=>c.scope==="sheet"&&c.field).map(c=>c.field)}],calculatedFields:(y=e.plan.calculatedFields)==null?void 0:y.filter(c=>c.scope==="dashboard"&&c.field).map(c=>c.field),inputs:s,...u?{defaultInputValues:u}:{}},warnings:n,skippedOperations:o}}function k(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ye(e){return JSON.parse(JSON.stringify(e))}function Ze(e){var t;return(t=e.sheets)==null?void 0:t.find(r=>(r.kind||"dashboard")==="dashboard")}function L(e,t){var r;for(const n of e.sheets||[])for(const o of n.frames||[]){const a=(r=o.cards)==null?void 0:r.find(i=>i.id===t);if(a)return{sheet:n,frame:o,card:a}}return null}function ye(e){var r,n;const t=(n=(r=e.cards)==null?void 0:r[0])==null?void 0:n.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function et(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((r,n)=>[r.i,n]))}function _e(e,t=new Map){const r=et(e),n=Math.max(r.size,t.size),o=(e.frames||[]).map((a,i)=>({frameId:a.id,role:ye(a),priority:t.get(a.id)??r.get(a.id)??n+i}));e.layouts=q(o)}function tt(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function rt(e,t){if(!tt(e)){_e(e);return}const r=q([{frameId:t.id,role:ye(t),priority:0}]);e.layouts??(e.layouts={});for(const[n,o]of Object.entries(r)){const a=e.layouts[n]||[];if(a.some(s=>s.i===t.id))continue;const i=o[0];if(!i)continue;const d=a.reduce((s,u)=>Math.max(s,u.y+u.h),0);e.layouts[n]=[...a,{...i,y:d}]}}function nt(e,t){var n;const r=X(t.filter,t.defaultValue);r&&(e.defaultInputValues??(e.defaultInputValues={}),(n=e.defaultInputValues).shared??(n.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:r}})}function at(e){var d;const t=be(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
3
3
  `)||"Dashboard change plan is invalid.");const r=Ye(e.dashboard),n=[...t.warnings],o=[],a=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),i=Ze(r);if(!i)throw new Error("Dashboard has no editable dashboard sheet.");i.frames??(i.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((i.frames||[]).reduce((A,w)=>{var y;return A+(((y=w.cards)==null?void 0:y.length)||0)},0)>=v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS){o.push(k("generated_card_limit_reached",`AI refinement is capped at ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`,s.card.id));break}const h=a.get(s.card.id);if(!h){o.push(k("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const I={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};i.frames.push(I),rt(i,I);break}case"addFilterInput":{r.inputs??(r.inputs=[]);const u={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:r.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};r.inputs.push(u),nt(r,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)r.calculatedFields??(r.calculatedFields=[]),r.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)i.calculatedFields??(i.calculatedFields=[]),i.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const u=s.field.targetCardId?L(r,s.field.targetCardId):null;u?((d=u.card).calculatedFields??(d.calculatedFields=[]),u.card.calculatedFields.push(s.field.field)):o.push(k("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=L(r,s.cardId);if(!u){o.push(k("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}u.card.title=s.title,s.description!==void 0&&(u.card.description=s.description);break}case"reorderCards":{const u=new Map;for(let h=0;h<s.cardIds.length;h+=1){const I=s.cardIds[h],A=L(r,I);A&&u.set(A.frame.id,h)}_e(i,u);break}case"reuseCalculatedField":n.push(k("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":o.push(k("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:r,warnings:n,skippedOperations:o}}function b(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function F(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function Se(e,t){if(!t.has(e))return t.add(e),e;let r=2,n=`${e}-${r}`;for(;t.has(n);)r+=1,n=`${e}-${r}`;return t.add(n),n}function $(e){return!!(e&&typeof e=="object")}function Ae(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>$(t)&&typeof t.id=="string"):[]}function J(e){return Array.isArray(e.sections)?e.sections.filter(t=>$(t)):[]}function Q(e){return Array.isArray(e.views)?e.views.filter(t=>$(t)):[]}function x(e){if(!Array.isArray(e))return[];const t=[];for(const r of e){const n=S(r);n&&t.push(n)}return t}function it(e){var n,o;if(!e)return[];const t=[];if(M(e.source)&&t.push(e.source),e.kind==="metric"){t.push(...x(e.metrics));const a=S(e.dateField);a&&t.push(a),t.push(...x(e.dimensions)),t.push(...x((n=e.filters)==null?void 0:n.map(i=>i.field)))}else if(e.kind==="records"){const a=S(e.dateField);a&&t.push(a),t.push(...x(e.fields)),t.push(...x((o=e.filters)==null?void 0:o.map(i=>i.field)))}else if(e.kind==="inputOptions"){const a=S(e.field);a&&t.push(a)}else e.kind==="sql"&&t.push(...x(e.fields));const r="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const a of r){const i=S(a.field);i&&t.push(i)}return t}function ot(e){const t=[];for(const r of Ae(e)){const n=S(r.field);n&&t.push(n)}for(const r of J(e))for(const n of Q(r))t.push(...it(n.analytics));return t}function st(e){var r;const t=[];for(const n of J(e))for(const o of Q(n))M((r=o.analytics)==null?void 0:r.source)&&t.push(o.analytics.source);return t}function dt(e,t){const r=R(e).filter(M);if(r.length===0)return t.push(b("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const n=r.every(a=>a.kind==="semantic"),o=Array.from(new Set(r.filter(a=>a.kind==="semantic").map(a=>a.domainId)));return r.length>1&&(!n||o.length!==1)?(t.push(b("multiple_datasets_out_of_scope","The dashboard authoring compiler supports multiple datasets only within one semantic domain; using the first source and deferring the rest.")),[r[0]]):r}function ct(e,t){const r=J(e),n=Ae(e),o=R(ot(e)),a=R(st(e));return{sections:r,inputs:n,sources:o,primarySources:a,defaultSource:a.length===1?a[0]:void 0,datasets:dt(o,t)}}function lt(e){return e&&z.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function ut(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function ft(e){var t,r,n;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((r=e.presentation)==null?void 0:r.kind)==="table"?"table":((n=e.presentation)==null?void 0:n.kind)==="text"?"text":"chart"}function pt(e){const t=z.normalizeSemaphorInputOperator(e);switch(t){case"not_in":return"not in";case"not_between":return"not between";case"contains":return"like";case"not_contains":return"not like";default:return t||"in"}}function ht(e){return $(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function mt(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function gt(e,t,r,n,o,a){if(e.kind!=="filter")return a.push(b("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!$(e.field)||typeof e.field.name!="string")return a.push(b("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const i=de({explicitSource:void 0,field:e.field,defaultSource:t,fallbackSources:r}),d=(i==null?void 0:i.kind)==="semantic"||(i==null?void 0:i.kind)==="physical"?i.connectionId:void 0;if(!d)return a.push(b("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const h={id:`filter-${Se(F(e.id,e.field.name),o)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:ht(e),qualifiedTableName:mt(i),sql:"",operation:pt(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(i==null?void 0:i.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(i==null?void 0:i.kind)==="semantic"?{semanticDomainId:i.domainId,connectionId:i.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:n,filter:h,defaultValue:X(h,e.defaultValue)}}function j(e){const t=[],r=[];for(const n of e.viewIds){const o=e.viewIdToCardId.get(n);o?t.push(o):r.push(n)}return r.length>0&&e.warnings.push(b("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${r.join(", ")}.`)),Array.from(new Set(t))}function bt(e){var n,o;if(!e.protocolScope){const a=Array.from(new Set(e.boundCardIds));return a.length>0&&a.length<e.allCardIds.length?{kind:"cards",cardIds:a}:void 0}if(e.protocolScope.level==="dashboard"){if(!((n=e.protocolScope.excludeViewIds)!=null&&n.length))return;const a=new Set(j({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(i=>!a.has(i))}}if(e.protocolScope.level==="view"){const a=j({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return a.length===0?(e.warnings.push(b("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:a}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(b("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((o=e.protocolScope.excludeViewIds)!=null&&o.length))return{kind:"cards",cardIds:t};const r=new Set(j({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(a=>!r.has(a))}}function It(e){var w,y,c;const t=[],r=z.validateSemaphorDashboardIntent(e);for(const f of r.warnings)t.push(b(f.code,f.message));for(const f of r.errors)t.push(b(f.code,f.message));const n=ct(e,t),o=[],a=new Map,i=new Map,d=new Map,s=new Set,u=new Set;let h=0;for(const[f,g]of n.sections.entries()){const l=typeof g.title=="string"?g.title:`Section ${f+1}`,Y=g.id||F(l,`section-${f+1}`);i.set(Y,[]);for(const[Z,m]of Q(g).entries()){const ee=ut(m),V=F(m.id||`${l}-${m.title||`View ${Z+1}`}`,`card-${f+1}-${Z+1}`);if(!ee){t.push(b("unsupported_presentation",`Dashboard presentation "${((w=m.presentation)==null?void 0:w.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${V}`));continue}if(((y=m.analytics)==null?void 0:y.kind)==="sql"){t.push(b("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${V}`));continue}const te=Se(V,s),O=`card-${te}`;m.id&&a.set(m.id,O),(c=i.get(Y))==null||c.push(O);const we=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const re of we||[]){const ne=d.get(re.inputId)||[];ne.push(O),d.set(re.inputId,ne)}o.push({id:O,frameId:`frame-${te}`,title:m.title,description:m.description,type:ee,role:ft(m),priority:h,section:l,analyticsIntent:lt(m.analytics),text:m.text}),h+=1}}const I=n.inputs.map(f=>{const g=bt({protocolScope:f.scope,inputLabel:f.label,allCardIds:o.map(l=>l.id),boundCardIds:d.get(f.id)||[],viewIdToCardId:a,sectionIdToCardIds:i,warnings:t});return g===null?null:gt(f,n.defaultSource,n.sources,g,u,t)}).filter(f=>!!f);return{plan:{version:1,id:`plan-${F(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:n.datasets,sheets:[{id:`sheet-${F(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:o}],filterInputs:I.length?I:void 0,warnings:t.length?t:void 0,unresolvedRequests:r.ok?void 0:r.errors.map(f=>f.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=v.DASHBOARD_AUTHORING_BREAKPOINTS;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS;exports.applyDashboardChangePlan=at;exports.compileDashboardFromPlan=Qe;exports.compileResponsiveDashboardLayouts=q;exports.dashboardAuthoringDatasetMatchesSource=E;exports.dashboardAuthoringFieldsReferToSameTarget=ke;exports.dashboardAuthoringSourceFromField=S;exports.dashboardAuthoringSourceKey=ve;exports.dashboardAuthoringSourcesReferToSameDataset=K;exports.dashboardPlanFromSemaphorDashboardIntent=It;exports.findDashboardAuthoringDatasetForSource=$e;exports.getDashboardAuthoringCardSource=le;exports.isMaterializableDashboardAuthoringSource=M;exports.isSemaphorSourceRef=oe;exports.mergeDashboardAuthoringSources=R;exports.preferDashboardAuthoringSourceMetadata=se;exports.preferredDashboardAuthoringSource=Ce;exports.resolveDashboardAuthoringSource=de;exports.validateDashboardAuthoringDatasetScope=ue;exports.validateDashboardChangePlan=be;exports.validateDashboardPlan=ge;
@@ -1,6 +1,6 @@
1
1
  import { D as B, a as be } from "../chunks/contracts-CoCOpd_i.js";
2
2
  import { s as Ie, a as E, p as ye } from "../chunks/source-identity-Dj3dryN9.js";
3
- import { c as ae, f as _e, n as we } from "../chunks/validators-CuKnUZFO.js";
3
+ import { c as ae, f as _e, n as we } from "../chunks/validators-CtNmgsvG.js";
4
4
  import { b as ve } from "../chunks/catalog-field-grounding-DoEBOXQd.js";
5
5
  function _(e) {
6
6
  return e && typeof e == "object" ? e : null;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),kn=require("react-dom/client"),y=require("../chunks/index-DlLvzmJF.js"),x=require("../chunks/switch-fIkmwzUt.js"),Ye=require("../data-app-builder-browser-runtime/index.cjs"),Nn=require("../chunks/save-D3YYinDz.js");function Fr(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const d=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,d.get?d:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const An=Fr(p),Cn=Fr(kn);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),kn=require("react-dom/client"),y=require("../chunks/index-D5Pp-5LR.js"),x=require("../chunks/switch-fIkmwzUt.js"),Ye=require("../data-app-builder-browser-runtime/index.cjs"),Nn=require("../chunks/save-D3YYinDz.js");function Fr(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const d=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,d.get?d:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const An=Fr(p),Cn=Fr(kn);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -2,7 +2,7 @@ import { jsx as r, jsxs as c, Fragment as re } from "react/jsx-runtime";
2
2
  import * as Yn from "react";
3
3
  import { useContext as Zn, useState as x, useRef as oe, useMemo as je, useEffect as W, useCallback as Ot } from "react";
4
4
  import * as Xn from "react-dom/client";
5
- import { ak as ea, al as ta, am as Lr, an as jr, ao as zr, ap as ra, aq as Wr, ar as Hr, as as Jr, at as Vr, au as _r, av as Ur, aw as Gr, ax as na, ay as aa, az as oa, aA as sa, aB as Ht, aC as on, w as Kr, aD as ia, aE as Vt, aF as _t, aG as sn, aH as la, aI as da, aJ as ca } from "../chunks/index-C0Qnfr_7.js";
5
+ import { al as ea, am as ta, an as Lr, ao as jr, ap as zr, aq as ra, ar as Wr, as as Hr, at as Jr, au as Vr, av as _r, aw as Ur, ax as Gr, ay as na, az as aa, aA as oa, aB as sa, aC as Ht, aD as on, w as Kr, aE as ia, aF as Vt, aG as _t, aH as sn, aI as la, aJ as da, aK as ca } from "../chunks/index-Clqr43Sr.js";
6
6
  import { c as Ve, B as H, P as it, b as lt, d as dt, a2 as ua, a3 as pa, a4 as ha, a5 as ma, a6 as fa, X as He, f as me, R as ga, e as Ut } from "../chunks/switch-Dkx2qEOr.js";
7
7
  import { loadSemaphorBrowserRuntime as ot } from "../data-app-builder-browser-runtime/index.js";
8
8
  import { S as ba } from "../chunks/save-kkBEBeLg.js";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../chunks/validation-D4Zz6WPD.js"),z=require("../chunks/index-BxM99sFL.js"),p=require("react"),Q=require("react/jsx-runtime"),$=require("../chunks/validators-DHee9kM2.js"),L=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],N=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function O(e){if(!e)return{};const t=W(e.executionResult),n=U(e,t),r=J(n);return{...e,...Object.keys(n).length?{resultSets:n}:{},...r?{columns:r.columns,records:r.records,rowCount:r.rowCount}:{}}}function U(e,t){const n=B(e.resultSets);for(const i of L){if(n[i]){n[i]=P(n[i]);continue}const a=F(e[i]);if(!a.length)continue;const s=t.length?t:H(a);n[i]={records:R(a,s),columns:s,rowCount:a.length}}const r=Y(e.executionResult);return r&&r.records.length>0&&!n.records&&(n.records=r),n}function B(e){return Object.fromEntries(Object.entries(e||{}).map(([t,n])=>[t,P(n)]))}function P(e){var t;return{...e,records:R(e.records||[],e.columns||[]),rowCount:e.rowCount??((t=e.records)==null?void 0:t.length)??0}}function J(e){var t;for(const n of N)if((t=e[n])!=null&&t.records.length)return e[n];return Object.values(e).find(n=>n.records.length)||Object.values(e)[0]}function Y(e){const t=e==null?void 0:e.result;if(!(!t||t.kind!=="records"&&t.kind!=="sql"))return{records:R(t.records,t.columns),columns:t.columns,rowCount:t.rowCount??t.records.length}}function W(e){const t=e==null?void 0:e.result;return!t||t.kind!=="records"&&t.kind!=="sql"?[]:t.columns}function F(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object"&&!Array.isArray(t))):[]}function R(e,t){return t.length?e.map(n=>{const r={};return t.forEach((i,a)=>{const s=X(n,{name:i.key,label:i.label,fallbackNames:[i.name,Object.keys(n)[a]]});s!==void 0&&(r[i.key]=s)}),Object.keys(r).length?r:n}):e}function H(e){return Array.from(new Set(e.flatMap(n=>Object.keys(n)))).map(n=>({key:n,name:n,label:n}))}function X(e,t){const n=[t.name,t.label,...t.fallbackNames||[]].filter(r=>!!r);for(const r of n)if(Object.prototype.hasOwnProperty.call(e,r))return e[r]}function G(e){return e}function Z(e){return e}const ee={filter(e){return{...e,kind:"filter"}},control(e){return{...e,kind:"control"}},sqlParam(e){return{...e,kind:"control",role:"sqlParam"}},derivedField(e){return{...e,kind:"derived_field",expressionLanguage:e.expressionLanguage||"semaphor_sql_template"}},metric(e){return{...e,queryKind:"metric"}},analysis(e){return{...e,queryKind:"analysis"}},records(e){return{...e,queryKind:"records"}},inputOptions(e){return{...e,queryKind:"inputOptions"}},sql(e){return{...e,queryKind:"sql"}},matrix(e){return{...e,queryKind:"matrix"}}};function T(){return{executeAnalysis:(e,t,n)=>S(e,t,n??{}).then(O),executeMetric:(e,t)=>S(e,t),executeRecords:(e,t)=>S(e,t),executeInputOptions:(e,t)=>S(e,t),executeSql:(e,t)=>S(e,t),executeMatrix:(e,t)=>S(e,t)}}async function S(e,t,n){if(!t.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const r=await fetch(ne(t),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:JSON.stringify({intent:e,activeInputs:t.activeInputs,...n?{analysisOptions:n}:{},resultShape:e.kind})}),i=await te(r);if(!r.ok||i.error)throw new Error(i.error||`Semaphor Data App execution failed with status ${r.status}.`);return i}async function te(e){const t=await e.text().catch(()=>"");if(!t.trim())return e.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(t)}catch{return e.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:t}:{error:re(e,t),details:t}}}function re(e,t){const n=e.statusText?` ${e.statusText}`:"",r=t.replace(/\s+/g," ").trim();return r?`Semaphor Data App execution failed with status ${e.status}${n}: ${r.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${n}.`}function ne(e){const t=oe(e).replace(/\/+$/,"");return t?t.endsWith("/api")?`${t}/v1/data-app/execute`:`${t}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function oe(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return z.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const K=p.createContext({});function V(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function j(){return p.useContext(K)}function ie({token:e,apiBaseUrl:t,executor:n,children:r}){var o;const i=V(),a=((o=i==null?void 0:i.authToken)==null?void 0:o.accessToken)||e,s=(i==null?void 0:i.dataApiBaseUrl)||(i==null?void 0:i.apiBaseUrl)||t,h=p.useMemo(()=>T(),[]),c=n||h,l=p.useMemo(()=>({token:a,apiBaseUrl:s,executor:c}),[s,c,a]);return Q.jsx(K.Provider,{value:l,children:r})}const g={value:null},x={},ue={records:[]},D={options:[]},ae={records:[]},k={};function se(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs),n=u.toSemaphorAnalysisQueryOptions(e);try{const r=u.toSemaphorAnalysisIntent(e),i=y(r);return i?{error:i,activeInputs:t,analysisOptions:n,queryKey:m(void 0,t,i,n),idleData:x}:{intent:r,error:null,activeInputs:t,analysisOptions:n,queryKey:m(r,t,void 0,n),idleData:x}}catch(r){const i=f(r);return{error:i,activeInputs:t,analysisOptions:n,queryKey:m(void 0,t,i,n),idleData:x}}}function ce(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs);try{const n=u.toSemaphorMetricIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:g}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:g}}catch(n){const r=f(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:g}}}function le(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs),n=ue;try{const r=u.toSemaphorRecordsIntent(e),i=y(r);return i?{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}:{intent:r,error:null,activeInputs:t,queryKey:m(r,t),idleData:n}}catch(r){const i=f(r);return{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}}}function de(e){try{const t=u.toSemaphorInputOptionsIntent(e),n=y(t);return n?{error:n,queryKey:m(void 0,void 0,n),idleData:D}:{intent:t,error:null,queryKey:m(t),idleData:D}}catch(t){const n=f(t);return{error:n,queryKey:m(void 0,void 0,n),idleData:D}}}function pe(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs),n=ae;try{const r=u.toSemaphorSqlIntent(e),i=y(r);return i?{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}:{intent:r,error:null,activeInputs:t,queryKey:m(r,t),idleData:n}}catch(r){const i=f(r);return{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}}}function me(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs);try{const n=u.toSemaphorMatrixIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:k}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:k}}catch(n){const r=f(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:k}}}function f(e){return e instanceof Error?e:new Error(String(e))}function y(e){const t=$.validateSemaphorAnalyticsIntent(e);if(t.ok)return null;const n=t.errors.map(r=>r.path?`${r.code} at ${r.path}: ${r.message}`:`${r.code}: ${r.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function m(e,t,n,r){return JSON.stringify({intent:e,activeInputs:t,analysisOptions:r,error:n==null?void 0:n.message})}function he(e){const[t,n]=p.useState(e.defaultValue),r=Object.prototype.hasOwnProperty.call(e,"value"),i=r?e.value:t,a=p.useMemo(()=>u.normalizeSemaphorInputOptions(e.options),[e.options]),s=p.useCallback(c=>{var o;const l=c;(o=e.onValueChange)==null||o.call(e,l),r||n(l)},[r,e]),h=p.useCallback(()=>s(void 0),[s]);return p.useMemo(()=>{const c=u.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:c.field,operator:c.operator,controlRole:e.kind==="control"?e.role:void 0,value:i,options:a,isActive:u.hasSemaphorInputValue(i),setValue:s,clear:h,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:e.kind,label:e.label,value:i,isActive:u.hasSemaphorInputValue(i),operator:c.operator,controlRole:e.kind==="control"?e.role:void 0})}},[h,a,s,e,i])}function fe(e){const[t,n]=p.useState(()=>ve(e));return p.useEffect(()=>{n(r=>{let i=r;for(const a of e)!Object.prototype.hasOwnProperty.call(i,a.id)&&a.defaultValue!==void 0&&(i={...i,[a.id]:a.defaultValue});return i})},[e]),p.useMemo(()=>e.map(r=>{const i=Object.prototype.hasOwnProperty.call(r,"value"),a=i?r.value:t[r.id],s=u.normalizeSemaphorInputOptions(r.options),h=o=>{var d;(d=r.onValueChange)==null||d.call(r,o),i||n(v=>({...v,[r.id]:o}))},c=()=>h(void 0),l=u.toSemaphorInputSpec(r);return{id:r.id,kind:r.kind,label:r.label,field:l.field,operator:l.operator,controlRole:r.kind==="control"?r.role:void 0,value:a,options:s,isActive:u.hasSemaphorInputValue(a),setValue:h,clear:c,toAnalyticsInput:()=>({inputId:l.inputId,field:l.field,kind:r.kind,label:r.label,value:a,isActive:u.hasSemaphorInputValue(a),operator:l.operator,controlRole:r.kind==="control"?r.role:void 0})}}),[e,t])}function Se(e,t={}){const n=p.useMemo(()=>t.inputs?{...e,inputs:t.inputs}:e,[t.inputs,e]),r=p.useMemo(()=>{switch(n.queryKind){case"metric":return{queryKind:n.queryKind,request:ce(n)};case"analysis":return{queryKind:n.queryKind,request:se(n)};case"records":return{queryKind:n.queryKind,request:le(n)};case"inputOptions":return{queryKind:n.queryKind,request:de(n)};case"sql":return{queryKind:n.queryKind,request:pe(n)};case"matrix":return{queryKind:n.queryKind,request:me(n)};default:return E(n)}},[n]),i=p.useCallback(o=>{var v,q,b,w,C,I,_,A,M;const d=r.request;if(d.intent)switch(r.queryKind){case"metric":return(v=o.executor)==null?void 0:v.executeMetric(d.intent,o);case"analysis":return(b=(q=o.executor)==null?void 0:q.executeAnalysis)==null?void 0:b.call(q,d.intent,o,d.analysisOptions);case"records":return(w=o.executor)==null?void 0:w.executeRecords(d.intent,o);case"inputOptions":return(C=o.executor)==null?void 0:C.executeInputOptions(d.intent,o);case"sql":return(_=(I=o.executor)==null?void 0:I.executeSql)==null?void 0:_.call(I,d.intent,o);case"matrix":return(M=(A=o.executor)==null?void 0:A.executeMatrix)==null?void 0:M.call(A,d.intent,o);default:return E(r)}},[r]),a=ye(r.request.queryKey,i,r.request.idleData,r.request.activeInputs),s=r.request.error?r.request.idleData:a.data,h=r.request.error?"error":a.status,c=!r.request.error&&a.status==="loading",l=r.request.error||a.error;switch(r.queryKind){case"metric":{const o=s;return{id:n.id,intent:r.request.intent,value:(o==null?void 0:o.value)??null,metrics:o==null?void 0:o.metrics,comparisonValue:o==null?void 0:o.comparisonValue,delta:o==null?void 0:o.delta,deltaPercent:o==null?void 0:o.deltaPercent,records:o==null?void 0:o.records,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"analysis":{const o=O(s);return{id:n.id,intent:r.request.intent,...o||{},status:h,isLoading:c,error:l}}case"records":{const o=s;return{id:n.id,intent:r.request.intent,records:(o==null?void 0:o.records)||[],columns:o==null?void 0:o.columns,rowCount:o==null?void 0:o.rowCount,pagination:o==null?void 0:o.pagination,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"inputOptions":{const o=s;return{id:n.id,intent:r.request.intent,options:(o==null?void 0:o.options)||[],executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"sql":{const o=s;return{id:n.id,intent:r.request.intent,records:(o==null?void 0:o.records)||[],columns:o==null?void 0:o.columns,rowCount:o==null?void 0:o.rowCount,pagination:o==null?void 0:o.pagination,output:o==null?void 0:o.output,rowLimitExceeded:o==null?void 0:o.rowLimitExceeded,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"matrix":{const o=s;return{id:n.id,intent:r.request.intent,payload:o==null?void 0:o.payload,grid:o==null?void 0:o.grid,expansion:o==null?void 0:o.expansion,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}default:return E(r)}}function ye(e,t,n,r){const i=j(),a=p.useRef(t),s=p.useRef(r),[h,c]=p.useState({status:"idle",data:n,error:null});return a.current=t,s.current=r,p.useEffect(()=>{let l;try{l=a.current({...i,activeInputs:s.current})}catch(d){c({status:"error",data:n,error:f(d)});return}if(!l){c({status:"idle",data:n,error:null});return}let o=!1;return c(d=>({status:"loading",data:d.data,error:null})),l.then(d=>{o||c({status:"success",data:d,error:null})}).catch(d=>{o||c({status:"error",data:n,error:f(d)})}),()=>{o=!0}},[n,e,i]),h}function ve(e){return Object.fromEntries(e.filter(t=>t.defaultValue!==void 0).map(t=>[t.id,t.defaultValue]))}function E(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}exports.hasSemaphorInputValue=u.hasSemaphorInputValue;exports.normalizeSemaphorAnalysisQueryOptions=u.normalizeSemaphorAnalysisQueryOptions;exports.normalizeSemaphorInputOptions=u.normalizeSemaphorInputOptions;exports.toSemaphorActiveInputSnapshots=u.toSemaphorActiveInputSnapshots;exports.toSemaphorAnalysisIntent=u.toSemaphorAnalysisIntent;exports.toSemaphorAnalysisQueryOptions=u.toSemaphorAnalysisQueryOptions;exports.toSemaphorInputBinding=u.toSemaphorInputBinding;exports.toSemaphorInputBindings=u.toSemaphorInputBindings;exports.toSemaphorInputOptionsIntent=u.toSemaphorInputOptionsIntent;exports.toSemaphorInputSnapshots=u.toSemaphorInputSnapshots;exports.toSemaphorInputSpec=u.toSemaphorInputSpec;exports.toSemaphorMatrixIntent=u.toSemaphorMatrixIntent;exports.toSemaphorMetricIntent=u.toSemaphorMetricIntent;exports.toSemaphorRecordsIntent=u.toSemaphorRecordsIntent;exports.toSemaphorSqlIntent=u.toSemaphorSqlIntent;exports.validateSemaphorDataAppQuerySpecs=u.validateSemaphorDataAppQuerySpecs;exports.SemaphorDataAppContext=K;exports.SemaphorDataAppProvider=ie;exports.createSemaphorQueryExecutor=T;exports.defineSemaphorDataApp=G;exports.defineSemaphorInput=Z;exports.normalizeSemaphorAnalysisPayload=O;exports.readWindowRuntime=V;exports.semaphor=ee;exports.useSemaphorDataAppRuntime=j;exports.useSemaphorInput=he;exports.useSemaphorInputs=fe;exports.useSemaphorQuery=Se;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../chunks/validation-1V7bWmYw.js"),z=require("../chunks/index-BxM99sFL.js"),p=require("react"),Q=require("react/jsx-runtime"),$=require("../chunks/validators-jpoYhpHh.js"),L=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],N=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function E(e){if(!e)return{};const t=W(e.executionResult),n=U(e,t),r=J(n);return{...e,...Object.keys(n).length?{resultSets:n}:{},...r?{columns:r.columns,records:r.records,rowCount:r.rowCount}:{}}}function U(e,t){const n=B(e.resultSets);for(const i of L){if(n[i]){n[i]=P(n[i]);continue}const s=F(e[i]);if(!s.length)continue;const a=t.length?t:H(s);n[i]={records:O(s,a),columns:a,rowCount:s.length}}const r=Y(e.executionResult);return r&&r.records.length>0&&!n.records&&(n.records=r),n}function B(e){return Object.fromEntries(Object.entries(e||{}).map(([t,n])=>[t,P(n)]))}function P(e){var t;return{...e,records:O(e.records||[],e.columns||[]),rowCount:e.rowCount??((t=e.records)==null?void 0:t.length)??0}}function J(e){var t;for(const n of N)if((t=e[n])!=null&&t.records.length)return e[n];return Object.values(e).find(n=>n.records.length)||Object.values(e)[0]}function Y(e){const t=e==null?void 0:e.result;if(!(!t||t.kind!=="records"&&t.kind!=="sql"))return{records:O(t.records,t.columns),columns:t.columns,rowCount:t.rowCount??t.records.length}}function W(e){const t=e==null?void 0:e.result;return!t||t.kind!=="records"&&t.kind!=="sql"?[]:t.columns}function F(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object"&&!Array.isArray(t))):[]}function O(e,t){return t.length?e.map(n=>{const r={};return t.forEach((i,s)=>{const a=X(n,{name:i.key,label:i.label,fallbackNames:[i.name,Object.keys(n)[s]]});a!==void 0&&(r[i.key]=a)}),Object.keys(r).length?r:n}):e}function H(e){return Array.from(new Set(e.flatMap(n=>Object.keys(n)))).map(n=>({key:n,name:n,label:n}))}function X(e,t){const n=[t.name,t.label,...t.fallbackNames||[]].filter(r=>!!r);for(const r of n)if(Object.prototype.hasOwnProperty.call(e,r))return e[r]}function G(e){return e}function Z(e){return e}const ee={filter(e){return{...e,kind:"filter"}},control(e){return{...e,kind:"control"}},sqlParam(e){return{...e,kind:"control",role:"sqlParam"}},derivedField(e){return{...e,kind:"derived_field",expressionLanguage:e.expressionLanguage||"semaphor_sql_template"}},metric(e){return{...e,queryKind:"metric"}},analysis(e){return{...e,queryKind:"analysis"}},records(e){return{...e,queryKind:"records"}},inputOptions(e){return{...e,queryKind:"inputOptions"}},sql(e){return{...e,queryKind:"sql"}},matrix(e){return{...e,queryKind:"matrix"}}};function T(){return{executeAnalysis:(e,t,n)=>S(e,t,n??{}).then(E),executeMetric:(e,t)=>S(e,t),executeRecords:(e,t)=>S(e,t),executeInputOptions:(e,t)=>S(e,t),executeSql:(e,t)=>S(e,t),executeMatrix:(e,t)=>S(e,t)}}async function S(e,t,n){if(!t.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const r=await fetch(ne(t),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:JSON.stringify({intent:e,activeInputs:t.activeInputs,...n?{analysisOptions:n}:{},resultShape:e.kind})}),i=await te(r);if(!r.ok||i.error)throw new Error(i.error||`Semaphor Data App execution failed with status ${r.status}.`);return i}async function te(e){const t=await e.text().catch(()=>"");if(!t.trim())return e.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(t)}catch{return e.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:t}:{error:re(e,t),details:t}}}function re(e,t){const n=e.statusText?` ${e.statusText}`:"",r=t.replace(/\s+/g," ").trim();return r?`Semaphor Data App execution failed with status ${e.status}${n}: ${r.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${n}.`}function ne(e){const t=oe(e).replace(/\/+$/,"");return t?t.endsWith("/api")?`${t}/v1/data-app/execute`:`${t}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function oe(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return z.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const K=p.createContext({});function V(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function j(){return p.useContext(K)}function ie({token:e,apiBaseUrl:t,executor:n,children:r}){var o;const i=V(),s=((o=i==null?void 0:i.authToken)==null?void 0:o.accessToken)||e,a=(i==null?void 0:i.dataApiBaseUrl)||(i==null?void 0:i.apiBaseUrl)||t,h=p.useMemo(()=>T(),[]),c=n||h,l=p.useMemo(()=>({token:s,apiBaseUrl:a,executor:c}),[a,c,s]);return Q.jsx(K.Provider,{value:l,children:r})}const g={value:null},x={},ue={records:[]},D={options:[]},se={records:[]},k={};function ae(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs),n=u.toSemaphorAnalysisQueryOptions(e);try{const r=u.toSemaphorAnalysisIntent(e),i=y(r);return i?{error:i,activeInputs:t,analysisOptions:n,queryKey:m(void 0,t,i,n),idleData:x}:{intent:r,error:null,activeInputs:t,analysisOptions:n,queryKey:m(r,t,void 0,n),idleData:x}}catch(r){const i=f(r);return{error:i,activeInputs:t,analysisOptions:n,queryKey:m(void 0,t,i,n),idleData:x}}}function ce(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs);try{const n=u.toSemaphorMetricIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:g}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:g}}catch(n){const r=f(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:g}}}function le(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs),n=ue;try{const r=u.toSemaphorRecordsIntent(e),i=y(r);return i?{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}:{intent:r,error:null,activeInputs:t,queryKey:m(r,t),idleData:n}}catch(r){const i=f(r);return{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}}}function de(e){try{const t=u.toSemaphorInputOptionsIntent(e),n=y(t);return n?{error:n,queryKey:m(void 0,void 0,n),idleData:D}:{intent:t,error:null,queryKey:m(t),idleData:D}}catch(t){const n=f(t);return{error:n,queryKey:m(void 0,void 0,n),idleData:D}}}function pe(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs),n=se;try{const r=u.toSemaphorSqlIntent(e),i=y(r);return i?{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}:{intent:r,error:null,activeInputs:t,queryKey:m(r,t),idleData:n}}catch(r){const i=f(r);return{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}}}function me(e){const t=u.toSemaphorActiveInputSnapshots(e.inputs);try{const n=u.toSemaphorMatrixIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:k}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:k}}catch(n){const r=f(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:k}}}function f(e){return e instanceof Error?e:new Error(String(e))}function y(e){const t=$.validateSemaphorAnalyticsIntent(e);if(t.ok)return null;const n=t.errors.map(r=>r.path?`${r.code} at ${r.path}: ${r.message}`:`${r.code}: ${r.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function m(e,t,n,r){return JSON.stringify({intent:e,activeInputs:t,analysisOptions:r,error:n==null?void 0:n.message})}function he(e){const[t,n]=p.useState(e.defaultValue),r=Object.prototype.hasOwnProperty.call(e,"value"),i=r?e.value:t,s=p.useMemo(()=>u.normalizeSemaphorInputOptions(e.options),[e.options]),a=p.useCallback(c=>{var o;const l=c;(o=e.onValueChange)==null||o.call(e,l),r||n(l)},[r,e]),h=p.useCallback(()=>a(void 0),[a]);return p.useMemo(()=>{const c=u.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:c.field,operator:c.operator,controlRole:e.kind==="control"?e.role:void 0,value:i,options:s,isActive:u.hasSemaphorInputValue(i),setValue:a,clear:h,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:e.kind,label:e.label,value:i,isActive:u.hasSemaphorInputValue(i),operator:c.operator,controlRole:e.kind==="control"?e.role:void 0})}},[h,s,a,e,i])}function fe(e){const[t,n]=p.useState(()=>ve(e));return p.useEffect(()=>{n(r=>{let i=r;for(const s of e)!Object.prototype.hasOwnProperty.call(i,s.id)&&s.defaultValue!==void 0&&(i={...i,[s.id]:s.defaultValue});return i})},[e]),p.useMemo(()=>e.map(r=>{const i=Object.prototype.hasOwnProperty.call(r,"value"),s=i?r.value:t[r.id],a=u.normalizeSemaphorInputOptions(r.options),h=o=>{var d;(d=r.onValueChange)==null||d.call(r,o),i||n(v=>({...v,[r.id]:o}))},c=()=>h(void 0),l=u.toSemaphorInputSpec(r);return{id:r.id,kind:r.kind,label:r.label,field:l.field,operator:l.operator,controlRole:r.kind==="control"?r.role:void 0,value:s,options:a,isActive:u.hasSemaphorInputValue(s),setValue:h,clear:c,toAnalyticsInput:()=>({inputId:l.inputId,field:l.field,kind:r.kind,label:r.label,value:s,isActive:u.hasSemaphorInputValue(s),operator:l.operator,controlRole:r.kind==="control"?r.role:void 0})}}),[e,t])}function Se(e,t={}){const n=p.useMemo(()=>t.inputs?{...e,inputs:t.inputs}:e,[t.inputs,e]),r=p.useMemo(()=>{switch(n.queryKind){case"metric":return{queryKind:n.queryKind,request:ce(n)};case"analysis":return{queryKind:n.queryKind,request:ae(n)};case"records":return{queryKind:n.queryKind,request:le(n)};case"inputOptions":return{queryKind:n.queryKind,request:de(n)};case"sql":return{queryKind:n.queryKind,request:pe(n)};case"matrix":return{queryKind:n.queryKind,request:me(n)};default:return R(n)}},[n]),i=p.useCallback(o=>{var v,q,b,w,C,I,_,A,M;const d=r.request;if(d.intent)switch(r.queryKind){case"metric":return(v=o.executor)==null?void 0:v.executeMetric(d.intent,o);case"analysis":return(b=(q=o.executor)==null?void 0:q.executeAnalysis)==null?void 0:b.call(q,d.intent,o,d.analysisOptions);case"records":return(w=o.executor)==null?void 0:w.executeRecords(d.intent,o);case"inputOptions":return(C=o.executor)==null?void 0:C.executeInputOptions(d.intent,o);case"sql":return(_=(I=o.executor)==null?void 0:I.executeSql)==null?void 0:_.call(I,d.intent,o);case"matrix":return(M=(A=o.executor)==null?void 0:A.executeMatrix)==null?void 0:M.call(A,d.intent,o);default:return R(r)}},[r]),s=ye(r.request.queryKey,i,r.request.idleData,r.request.activeInputs),a=r.request.error?r.request.idleData:s.data,h=r.request.error?"error":s.status,c=!r.request.error&&s.status==="loading",l=r.request.error||s.error;switch(r.queryKind){case"metric":{const o=a;return{id:n.id,intent:r.request.intent,value:(o==null?void 0:o.value)??null,metrics:o==null?void 0:o.metrics,comparisonValue:o==null?void 0:o.comparisonValue,delta:o==null?void 0:o.delta,deltaPercent:o==null?void 0:o.deltaPercent,records:o==null?void 0:o.records,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"analysis":{const o=E(a);return{id:n.id,intent:r.request.intent,...o||{},status:h,isLoading:c,error:l}}case"records":{const o=a;return{id:n.id,intent:r.request.intent,records:(o==null?void 0:o.records)||[],columns:o==null?void 0:o.columns,rowCount:o==null?void 0:o.rowCount,pagination:o==null?void 0:o.pagination,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"inputOptions":{const o=a;return{id:n.id,intent:r.request.intent,options:(o==null?void 0:o.options)||[],executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"sql":{const o=a;return{id:n.id,intent:r.request.intent,records:(o==null?void 0:o.records)||[],columns:o==null?void 0:o.columns,rowCount:o==null?void 0:o.rowCount,pagination:o==null?void 0:o.pagination,output:o==null?void 0:o.output,rowLimitExceeded:o==null?void 0:o.rowLimitExceeded,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}case"matrix":{const o=a;return{id:n.id,intent:r.request.intent,matrixResult:o==null?void 0:o.matrixResult,grid:o==null?void 0:o.grid,expansion:o==null?void 0:o.expansion,executionResult:o==null?void 0:o.executionResult,status:h,isLoading:c,error:l}}default:return R(r)}}function ye(e,t,n,r){const i=j(),s=p.useRef(t),a=p.useRef(r),[h,c]=p.useState({status:"idle",data:n,error:null});return s.current=t,a.current=r,p.useEffect(()=>{let l;try{l=s.current({...i,activeInputs:a.current})}catch(d){c({status:"error",data:n,error:f(d)});return}if(!l){c({status:"idle",data:n,error:null});return}let o=!1;return c(d=>({status:"loading",data:d.data,error:null})),l.then(d=>{o||c({status:"success",data:d,error:null})}).catch(d=>{o||c({status:"error",data:n,error:f(d)})}),()=>{o=!0}},[n,e,i]),h}function ve(e){return Object.fromEntries(e.filter(t=>t.defaultValue!==void 0).map(t=>[t.id,t.defaultValue]))}function R(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}exports.hasSemaphorInputValue=u.hasSemaphorInputValue;exports.normalizeSemaphorAnalysisQueryOptions=u.normalizeSemaphorAnalysisQueryOptions;exports.normalizeSemaphorInputOptions=u.normalizeSemaphorInputOptions;exports.toSemaphorActiveInputSnapshots=u.toSemaphorActiveInputSnapshots;exports.toSemaphorAnalysisIntent=u.toSemaphorAnalysisIntent;exports.toSemaphorAnalysisQueryOptions=u.toSemaphorAnalysisQueryOptions;exports.toSemaphorInputBinding=u.toSemaphorInputBinding;exports.toSemaphorInputBindings=u.toSemaphorInputBindings;exports.toSemaphorInputOptionsIntent=u.toSemaphorInputOptionsIntent;exports.toSemaphorInputSnapshots=u.toSemaphorInputSnapshots;exports.toSemaphorInputSpec=u.toSemaphorInputSpec;exports.toSemaphorMatrixIntent=u.toSemaphorMatrixIntent;exports.toSemaphorMetricIntent=u.toSemaphorMetricIntent;exports.toSemaphorRecordsIntent=u.toSemaphorRecordsIntent;exports.toSemaphorSqlIntent=u.toSemaphorSqlIntent;exports.validateSemaphorDataAppQuerySpecs=u.validateSemaphorDataAppQuerySpecs;exports.SemaphorDataAppContext=K;exports.SemaphorDataAppProvider=ie;exports.createSemaphorQueryExecutor=T;exports.defineSemaphorDataApp=G;exports.defineSemaphorInput=Z;exports.normalizeSemaphorAnalysisPayload=E;exports.readWindowRuntime=V;exports.semaphor=ee;exports.useSemaphorDataAppRuntime=j;exports.useSemaphorInput=he;exports.useSemaphorInputs=fe;exports.useSemaphorQuery=Se;
@@ -1,9 +1,9 @@
1
- import { t as y, a as M, b as B, c as Q, d as J, e as Y, f as F, g as H, n as V, h as $, i as k } from "../chunks/validation-CQFpcSSP.js";
2
- import { m as ze, j as Me, k as Be, l as Qe, v as Je } from "../chunks/validation-CQFpcSSP.js";
1
+ import { t as y, a as M, b as B, c as Q, d as J, e as Y, f as F, g as H, n as V, h as $, i as x } from "../chunks/validation-DlrTIf1N.js";
2
+ import { m as ze, j as Me, k as Be, l as Qe, v as Je } from "../chunks/validation-DlrTIf1N.js";
3
3
  import { j as W } from "../chunks/index-CuHybtft.js";
4
- import { createContext as X, useContext as G, useMemo as m, useState as O, useCallback as R, useEffect as L, useRef as j } from "react";
4
+ import { createContext as X, useContext as G, useMemo as m, useState as O, useCallback as K, useEffect as L, useRef as j } from "react";
5
5
  import { jsx as Z } from "react/jsx-runtime";
6
- import { c as ee } from "../chunks/validators-CuKnUZFO.js";
6
+ import { c as ee } from "../chunks/validators-CtNmgsvG.js";
7
7
  const te = [
8
8
  "records",
9
9
  "changes",
@@ -301,7 +301,7 @@ function je({
301
301
  );
302
302
  return /* @__PURE__ */ Z(z.Provider, { value: c, children: r });
303
303
  }
304
- const I = { value: null }, x = {}, qe = { records: [] }, D = { options: [] }, Se = { records: [] }, E = {};
304
+ const k = { value: null }, I = {}, qe = { records: [] }, D = { options: [] }, Se = { records: [] }, E = {};
305
305
  function Ae(e) {
306
306
  const t = y(e.inputs), n = Y(e);
307
307
  try {
@@ -316,14 +316,14 @@ function Ae(e) {
316
316
  i,
317
317
  n
318
318
  ),
319
- idleData: x
319
+ idleData: I
320
320
  } : {
321
321
  intent: r,
322
322
  error: null,
323
323
  activeInputs: t,
324
324
  analysisOptions: n,
325
325
  queryKey: d(r, t, void 0, n),
326
- idleData: x
326
+ idleData: I
327
327
  };
328
328
  } catch (r) {
329
329
  const i = p(r);
@@ -337,7 +337,7 @@ function Ae(e) {
337
337
  i,
338
338
  n
339
339
  ),
340
- idleData: x
340
+ idleData: I
341
341
  };
342
342
  }
343
343
  }
@@ -349,13 +349,13 @@ function ge(e) {
349
349
  error: r,
350
350
  activeInputs: t,
351
351
  queryKey: d(void 0, t, r),
352
- idleData: I
352
+ idleData: k
353
353
  } : {
354
354
  intent: n,
355
355
  error: null,
356
356
  activeInputs: t,
357
357
  queryKey: d(n, t),
358
- idleData: I
358
+ idleData: k
359
359
  };
360
360
  } catch (n) {
361
361
  const r = p(n);
@@ -363,11 +363,11 @@ function ge(e) {
363
363
  error: r,
364
364
  activeInputs: t,
365
365
  queryKey: d(void 0, t, r),
366
- idleData: I
366
+ idleData: k
367
367
  };
368
368
  }
369
369
  }
370
- function ke(e) {
370
+ function xe(e) {
371
371
  const t = y(e.inputs), n = qe;
372
372
  try {
373
373
  const r = J(e), i = v(r);
@@ -393,7 +393,7 @@ function ke(e) {
393
393
  };
394
394
  }
395
395
  }
396
- function Ie(e) {
396
+ function ke(e) {
397
397
  try {
398
398
  const t = Q(e), n = v(t);
399
399
  return n ? {
@@ -415,7 +415,7 @@ function Ie(e) {
415
415
  };
416
416
  }
417
417
  }
418
- function xe(e) {
418
+ function Ie(e) {
419
419
  const t = y(e.inputs), n = Se;
420
420
  try {
421
421
  const r = B(e), i = v(r);
@@ -491,14 +491,14 @@ function Ve(e) {
491
491
  const [t, n] = O(e.defaultValue), r = Object.prototype.hasOwnProperty.call(e, "value"), i = r ? e.value : t, u = m(
492
492
  () => V(e.options),
493
493
  [e.options]
494
- ), s = R(
494
+ ), s = K(
495
495
  (a) => {
496
496
  var o;
497
497
  const c = a;
498
498
  (o = e.onValueChange) == null || o.call(e, c), r || n(c);
499
499
  },
500
500
  [r, e]
501
- ), f = R(() => s(void 0), [s]);
501
+ ), f = K(() => s(void 0), [s]);
502
502
  return m(() => {
503
503
  const a = $(e);
504
504
  return {
@@ -510,7 +510,7 @@ function Ve(e) {
510
510
  controlRole: e.kind === "control" ? e.role : void 0,
511
511
  value: i,
512
512
  options: u,
513
- isActive: k(i),
513
+ isActive: x(i),
514
514
  setValue: s,
515
515
  clear: f,
516
516
  toAnalyticsInput: () => ({
@@ -519,7 +519,7 @@ function Ve(e) {
519
519
  kind: e.kind,
520
520
  label: e.label,
521
521
  value: i,
522
- isActive: k(i),
522
+ isActive: x(i),
523
523
  operator: a.operator,
524
524
  controlRole: e.kind === "control" ? e.role : void 0
525
525
  })
@@ -527,7 +527,7 @@ function Ve(e) {
527
527
  }, [f, u, s, e, i]);
528
528
  }
529
529
  function $e(e) {
530
- const [t, n] = O(() => Ke(e));
530
+ const [t, n] = O(() => Re(e));
531
531
  return L(() => {
532
532
  n((r) => {
533
533
  let i = r;
@@ -556,7 +556,7 @@ function $e(e) {
556
556
  controlRole: r.kind === "control" ? r.role : void 0,
557
557
  value: u,
558
558
  options: s,
559
- isActive: k(u),
559
+ isActive: x(u),
560
560
  setValue: f,
561
561
  clear: a,
562
562
  toAnalyticsInput: () => ({
@@ -565,7 +565,7 @@ function $e(e) {
565
565
  kind: r.kind,
566
566
  label: r.label,
567
567
  value: u,
568
- isActive: k(u),
568
+ isActive: x(u),
569
569
  operator: c.operator,
570
570
  controlRole: r.kind === "control" ? r.role : void 0
571
571
  })
@@ -596,17 +596,17 @@ function Le(e, t = {}) {
596
596
  case "records":
597
597
  return {
598
598
  queryKind: n.queryKind,
599
- request: ke(n)
599
+ request: xe(n)
600
600
  };
601
601
  case "inputOptions":
602
602
  return {
603
603
  queryKind: n.queryKind,
604
- request: Ie(n)
604
+ request: ke(n)
605
605
  };
606
606
  case "sql":
607
607
  return {
608
608
  queryKind: n.queryKind,
609
- request: xe(n)
609
+ request: Ie(n)
610
610
  };
611
611
  case "matrix":
612
612
  return {
@@ -614,9 +614,9 @@ function Le(e, t = {}) {
614
614
  request: De(n)
615
615
  };
616
616
  default:
617
- return K(n);
617
+ return R(n);
618
618
  }
619
- }, [n]), i = R(
619
+ }, [n]), i = K(
620
620
  (o) => {
621
621
  var q, S, w, C, _, A, T, g, P;
622
622
  const l = r.request;
@@ -657,7 +657,7 @@ function Le(e, t = {}) {
657
657
  o
658
658
  );
659
659
  default:
660
- return K(r);
660
+ return R(r);
661
661
  }
662
662
  },
663
663
  [r]
@@ -745,7 +745,7 @@ function Le(e, t = {}) {
745
745
  return {
746
746
  id: n.id,
747
747
  intent: r.request.intent,
748
- payload: o == null ? void 0 : o.payload,
748
+ matrixResult: o == null ? void 0 : o.matrixResult,
749
749
  grid: o == null ? void 0 : o.grid,
750
750
  expansion: o == null ? void 0 : o.expansion,
751
751
  executionResult: o == null ? void 0 : o.executionResult,
@@ -755,7 +755,7 @@ function Le(e, t = {}) {
755
755
  };
756
756
  }
757
757
  default:
758
- return K(r);
758
+ return R(r);
759
759
  }
760
760
  }
761
761
  function Ee(e, t, n, r) {
@@ -801,12 +801,12 @@ function Ee(e, t, n, r) {
801
801
  };
802
802
  }, [n, e, i]), f;
803
803
  }
804
- function Ke(e) {
804
+ function Re(e) {
805
805
  return Object.fromEntries(
806
806
  e.filter((t) => t.defaultValue !== void 0).map((t) => [t.id, t.defaultValue])
807
807
  );
808
808
  }
809
- function K(e) {
809
+ function R(e) {
810
810
  throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`);
811
811
  }
812
812
  export {
@@ -815,7 +815,7 @@ export {
815
815
  de as createSemaphorQueryExecutor,
816
816
  _e as defineSemaphorDataApp,
817
817
  Te as defineSemaphorInput,
818
- k as hasSemaphorInputValue,
818
+ x as hasSemaphorInputValue,
819
819
  N as normalizeSemaphorAnalysisPayload,
820
820
  ze as normalizeSemaphorAnalysisQueryOptions,
821
821
  V as normalizeSemaphorInputOptions,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../chunks/validators-DHee9kM2.js");require("../chunks/catalog-field-grounding-Du6mKDcF.js");require("../chunks/source-identity-C-xaeE_I.js");const e=require("../chunks/validation-D4Zz6WPD.js");exports.normalizeSemaphorAnalysisQueryOptions=e.normalizeSemaphorAnalysisQueryOptions;exports.validateSemaphorDataAppQuerySpecs=e.validateSemaphorDataAppQuerySpecs;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../chunks/validators-jpoYhpHh.js");require("../chunks/catalog-field-grounding-Du6mKDcF.js");require("../chunks/source-identity-C-xaeE_I.js");const e=require("../chunks/validation-1V7bWmYw.js");exports.normalizeSemaphorAnalysisQueryOptions=e.normalizeSemaphorAnalysisQueryOptions;exports.validateSemaphorDataAppQuerySpecs=e.validateSemaphorDataAppQuerySpecs;
@@ -1,7 +1,7 @@
1
- import "../chunks/validators-CuKnUZFO.js";
1
+ import "../chunks/validators-CtNmgsvG.js";
2
2
  import "../chunks/catalog-field-grounding-DoEBOXQd.js";
3
3
  import "../chunks/source-identity-Dj3dryN9.js";
4
- import { m, v as i } from "../chunks/validation-CQFpcSSP.js";
4
+ import { m, v as i } from "../chunks/validation-DlrTIf1N.js";
5
5
  export {
6
6
  m as normalizeSemaphorAnalysisQueryOptions,
7
7
  i as validateSemaphorDataAppQuerySpecs