react-semaphor 0.1.449 → 0.1.453

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 (134) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +115 -109
  3. package/dist/appearance/index.cjs +1 -1
  4. package/dist/appearance/index.js +1 -1
  5. package/dist/brand-studio/index.cjs +4 -4
  6. package/dist/brand-studio/index.js +15 -13
  7. package/dist/briefings/index.cjs +1 -1
  8. package/dist/briefings/index.js +39 -2131
  9. package/dist/chunks/{analyze-result-contract-BHb7sUUW.cjs → analyze-result-contract-Dxw66nUG.cjs} +1 -1
  10. package/dist/chunks/{analyze-result-contract-T-0Ntzys.js → analyze-result-contract-GHKFwThg.js} +1 -1
  11. package/dist/chunks/canonical-result-keys-Drc2x-lf.cjs +1 -0
  12. package/dist/chunks/canonical-result-keys-KLk__J_O.js +466 -0
  13. package/dist/chunks/color-CJvdlFM_.js +2162 -0
  14. package/dist/chunks/color-CyB5o13F.cjs +4 -0
  15. package/dist/chunks/{common-types-CQ6SHfLk.cjs → common-types-Ci66eflG.cjs} +1 -1
  16. package/dist/chunks/{common-types-B7Jk3Rtj.js → common-types-F6qk6PPS.js} +1 -1
  17. package/dist/chunks/contracts-CoCOpd_i.js +11 -0
  18. package/dist/chunks/contracts-CtB2VONT.cjs +1 -0
  19. package/dist/chunks/{dashboard-briefing-launcher-DCHiEkLE.js → dashboard-briefing-launcher-CFpX0WX3.js} +86 -84
  20. package/dist/chunks/dashboard-briefing-launcher-mUXWuiOZ.cjs +26 -0
  21. package/dist/chunks/{dashboard-controls-DwRFCcHV.js → dashboard-controls-BeYAmOJc.js} +15 -13
  22. package/dist/chunks/{dashboard-controls-CaFioayc.cjs → dashboard-controls-SoNubIu1.cjs} +1 -1
  23. package/dist/chunks/dashboard-json-BublPnQ4.cjs +1 -0
  24. package/dist/chunks/{dashboard-json-WoILbfTe.js → dashboard-json-DeLUagVV.js} +25 -23
  25. package/dist/chunks/edit-dashboard-visual-CrvPcO7A.cjs +172 -0
  26. package/dist/chunks/{edit-dashboard-visual-ciFhxqaI.js → edit-dashboard-visual-Go0h82DR.js} +6925 -6947
  27. package/dist/chunks/editor-action-buttons-1Lo0fIh7.cjs +16 -0
  28. package/dist/chunks/{editor-action-buttons-BPo_45pM.js → editor-action-buttons-BFNtjFzO.js} +41 -39
  29. package/dist/chunks/format-types-CFHQoIuk.js +1350 -0
  30. package/dist/chunks/format-types-PSZZ7hG8.cjs +1 -0
  31. package/dist/chunks/index-B3ZugihZ.js +3713 -0
  32. package/dist/chunks/{index-CPuawpXJ.js → index-BsH32bn1.js} +47472 -47845
  33. package/dist/chunks/index-ByFbacH7.cjs +1 -0
  34. package/dist/chunks/index-CACdoqu3.js +318 -0
  35. package/dist/chunks/index-DSKR3nKn.js +421 -0
  36. package/dist/chunks/index-DjiIh_9n.cjs +4 -0
  37. package/dist/chunks/index-F25jnH0p.cjs +1 -0
  38. package/dist/chunks/index-q12_nNUS.cjs +1392 -0
  39. package/dist/chunks/{metric-comparison-97zHGEx5.js → metric-comparison-D0T0MKRK.js} +1 -1
  40. package/dist/chunks/{metric-comparison-CUAJ8n4y.cjs → metric-comparison-DYR3RXam.cjs} +1 -1
  41. package/dist/chunks/pivot-header-presentation-DcfPaCiy.cjs +4 -0
  42. package/dist/chunks/pivot-header-presentation-nk604qc1.js +557 -0
  43. package/dist/chunks/{pivot-result-identity-CwJWpKI7.js → pivot-result-identity-C43Ai5Kr.js} +1 -1
  44. package/dist/chunks/{pivot-result-identity-CDLRT-YG.cjs → pivot-result-identity-CRUokNgm.cjs} +1 -1
  45. package/dist/chunks/pivot-result-lifecycle-4kSe0Hk1.js +1642 -0
  46. package/dist/chunks/pivot-result-lifecycle-BiJepH5S.cjs +1 -0
  47. package/dist/chunks/raw-temporal-contract-BF7PjBY9.js +64 -0
  48. package/dist/chunks/raw-temporal-contract-CxbRFwnd.cjs +1 -0
  49. package/dist/chunks/report-preferences-dialog-BEVZAE3m.cjs +1 -0
  50. package/dist/chunks/report-preferences-dialog-BNV7qXYH.js +723 -0
  51. package/dist/chunks/{report-runtime-context-bCy3CVzK.js → report-runtime-context-BJQDu2fV.js} +1 -1
  52. package/dist/chunks/{report-runtime-context-C8LZFsqV.cjs → report-runtime-context-DjYqLV-c.cjs} +1 -1
  53. package/dist/chunks/saved-temporal-bucket-format-DiZdQXOL.js +924 -0
  54. package/dist/chunks/saved-temporal-bucket-format-Gfbh4IiP.cjs +1 -0
  55. package/dist/chunks/switch-CjJ6FHYJ.cjs +138 -0
  56. package/dist/chunks/{switch-BXet-Sno.js → switch-DgLwr7O-.js} +4352 -5249
  57. package/dist/chunks/temporal-bucket-Dnj8qT9l.cjs +1 -0
  58. package/dist/chunks/temporal-bucket-FBZGrDCe.js +560 -0
  59. package/dist/chunks/temporal-bucket-authoring-7hv2laOG.cjs +1 -0
  60. package/dist/chunks/temporal-bucket-authoring-FIRnJz0e.js +221 -0
  61. package/dist/chunks/{temporal-bucket-contract-_F6vNhhH.js → temporal-bucket-contract-BQOj6Frl.js} +1 -1
  62. package/dist/chunks/{temporal-bucket-contract-ChDBWX8I.cjs → temporal-bucket-contract-anl4h-vg.cjs} +1 -1
  63. package/dist/chunks/{token-types-BHR58aTy.js → token-types-CRpQJ4kv.js} +1 -1
  64. package/dist/chunks/{token-types-BdQ8kHBm.cjs → token-types-D0i0IUX3.cjs} +1 -1
  65. package/dist/chunks/{update-policy-BxvYMYz0.cjs → update-policy-C1i9bgsy.cjs} +1 -1
  66. package/dist/chunks/{update-policy-g0rCQ9BM.js → update-policy-CaJz9aPG.js} +1 -1
  67. package/dist/chunks/{validators-Cs74WVie.js → validators-DeMXwRON.js} +253 -233
  68. package/dist/chunks/validators-Dm7Kpz6p.cjs +1 -0
  69. package/dist/dashboard/index.cjs +1 -1
  70. package/dist/dashboard/index.js +2 -2
  71. package/dist/dashboard-authoring/index.cjs +3 -3
  72. package/dist/dashboard-authoring/index.js +32 -29
  73. package/dist/data-app-builder/index.cjs +1 -1
  74. package/dist/data-app-builder/index.js +2 -2
  75. package/dist/data-app-codegen/index.cjs +1 -1
  76. package/dist/data-app-codegen/index.js +2 -2
  77. package/dist/data-app-codegen-node/index.cjs +1 -1
  78. package/dist/data-app-codegen-node/index.js +3 -3
  79. package/dist/data-app-sdk/index.cjs +1 -1
  80. package/dist/data-app-sdk/index.js +3 -3
  81. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  82. package/dist/data-app-sdk-adapters/index.js +2 -2
  83. package/dist/data-app-sdk-validation/index.cjs +1 -1
  84. package/dist/data-app-sdk-validation/index.js +3 -3
  85. package/dist/format-utils/index.cjs +3 -3
  86. package/dist/format-utils/index.js +162 -145
  87. package/dist/index.cjs +1 -1
  88. package/dist/index.js +157 -155
  89. package/dist/report-runtime-context/index.cjs +1 -1
  90. package/dist/report-runtime-context/index.js +2 -2
  91. package/dist/style.css +1 -1
  92. package/dist/surfboard/index.cjs +1 -1
  93. package/dist/surfboard/index.js +3 -3
  94. package/dist/types/analytics-protocol.d.ts +37 -0
  95. package/dist/types/briefings.d.ts +718 -7
  96. package/dist/types/dashboard-assistant.d.ts +18 -0
  97. package/dist/types/dashboard-authoring.d.ts +52 -2
  98. package/dist/types/dashboard.d.ts +128 -0
  99. package/dist/types/data-app-sdk-validation.d.ts +13 -0
  100. package/dist/types/data-app-sdk.d.ts +13 -0
  101. package/dist/types/format-utils.d.ts +190 -3
  102. package/dist/types/index.cjs +1 -1
  103. package/dist/types/index.js +4 -4
  104. package/dist/types/main.d.ts +103 -12
  105. package/dist/types/shared.d.ts +5 -0
  106. package/dist/types/surfboard.d.ts +129 -1
  107. package/dist/types/types.d.ts +98 -6
  108. package/dist/types/value-format-preferences.d.ts +3 -0
  109. package/package.json +2 -1
  110. package/dist/chunks/card-config-utils-15sRtebL.cjs +0 -1
  111. package/dist/chunks/card-config-utils-BYZ5MJOh.js +0 -16
  112. package/dist/chunks/dashboard-briefing-launcher-DDgDr2s3.cjs +0 -26
  113. package/dist/chunks/dashboard-json-CYtvwtvj.cjs +0 -1
  114. package/dist/chunks/edit-dashboard-visual-DwKcvlsF.cjs +0 -177
  115. package/dist/chunks/editor-action-buttons-BVmsk0Aj.cjs +0 -16
  116. package/dist/chunks/format-types-CSv0V7mm.cjs +0 -1
  117. package/dist/chunks/format-types-DZGgYj39.js +0 -1663
  118. package/dist/chunks/index-CJdxSyQq.js +0 -2578
  119. package/dist/chunks/index-DPv8_Ild.cjs +0 -1395
  120. package/dist/chunks/index-DRlMUglg.cjs +0 -4
  121. package/dist/chunks/pivot-result-lifecycle-BBabQ_da.js +0 -914
  122. package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +0 -4
  123. package/dist/chunks/presentation-execution-BLfPTGX_.js +0 -637
  124. package/dist/chunks/presentation-execution-BTV-Q43g.cjs +0 -1
  125. package/dist/chunks/report-preferences-dialog-D9ZCGh9l.js +0 -691
  126. package/dist/chunks/report-preferences-dialog-DaqTEcac.cjs +0 -1
  127. package/dist/chunks/switch-Cjk6G06r.cjs +0 -138
  128. package/dist/chunks/temporal-bucket-BnPxGrAi.js +0 -446
  129. package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +0 -1
  130. package/dist/chunks/temporal-bucket-authoring-CgOuakGW.js +0 -205
  131. package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +0 -1
  132. package/dist/chunks/temporal-result-owner-6peubmhU.js +0 -443
  133. package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +0 -1
  134. package/dist/chunks/validators-9D4KBqKD.cjs +0 -1
@@ -1 +1 @@
1
- "use strict";const t=require("./validators-9D4KBqKD.cjs"),a=new Set(Object.keys(t.SEMAPHOR_ANALYZE_RESULT_FIELD_CONTRACT));function o(){return Object.keys(t.SEMAPHOR_ANALYZE_RESULT_FIELD_CONTRACT)}function s(e){return a.has(e)}function l(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Semaphor analyze result must be an object.");const r=Object.keys(e).filter(n=>!s(n));if(r.length)throw new Error(`Semaphor analyze result contains unsupported top-level field(s): ${r.join(", ")}.`);return t.semaphorAnalyzeResultSchema.parse(e)}exports.getSemaphorAnalyzeResultFieldNames=o;exports.isSemaphorAnalyzeResultFieldName=s;exports.parseSemaphorAnalyzeResult=l;
1
+ "use strict";const t=require("./validators-Dm7Kpz6p.cjs"),a=new Set(Object.keys(t.SEMAPHOR_ANALYZE_RESULT_FIELD_CONTRACT));function o(){return Object.keys(t.SEMAPHOR_ANALYZE_RESULT_FIELD_CONTRACT)}function s(e){return a.has(e)}function l(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Semaphor analyze result must be an object.");const r=Object.keys(e).filter(n=>!s(n));if(r.length)throw new Error(`Semaphor analyze result contains unsupported top-level field(s): ${r.join(", ")}.`);return t.semaphorAnalyzeResultSchema.parse(e)}exports.getSemaphorAnalyzeResultFieldNames=o;exports.isSemaphorAnalyzeResultFieldName=s;exports.parseSemaphorAnalyzeResult=l;
@@ -1,4 +1,4 @@
1
- import { f as t, g as n } from "./validators-Cs74WVie.js";
1
+ import { f as t, g as n } from "./validators-DeMXwRON.js";
2
2
  const o = new Set(
3
3
  Object.keys(t)
4
4
  );
@@ -0,0 +1 @@
1
+ "use strict";require("./validators-Dm7Kpz6p.cjs");require("./analyze-result-contract-Dxw66nUG.cjs");const E=require("./metric-comparison-DYR3RXam.cjs"),_=new Set(["previous_period","same_period_last_year","start_vs_end","target"]),R=new Set([..._,"none",""]);function l(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function L(e){const o=l(e.preferences)?e.preferences:void 0,r=o&&l(o.kpiVisualOptions)?o.kpiVisualOptions:void 0,i=o&&l(o.tableVisualOptions)?o.tableVisualOptions:void 0;return{preferences:o,kpiOptions:r,kpiComparison:r&&l(r.metricComparison)?r.metricComparison:void 0,kpiComparisonPresent:!!r&&"metricComparison"in r,tableOptions:i,tableComparison:i&&l(i.metricComparison)?i.metricComparison:void 0,tableComparisonPresent:!!i&&"metricComparison"in i}}function O(e){const o=[],r=(i,a)=>{if(Array.isArray(i)){i.forEach((n,c)=>r(n,`${a}[${c}]`));return}if(!l(i))return;const m=i.config;if(l(m)){const n=L(i),c=!!(n.kpiComparisonPresent||n.tableComparisonPresent),g=m.metricColumns,p=Array.isArray(g)?g.flatMap((s,t)=>l(s)?[{index:t,metric:s}]:[]):[];if((p.some(({metric:s})=>"comparisonType"in s)||c)&&o.push({path:a,card:i,metrics:p,malformedMetricIndexes:Array.isArray(g)?g.flatMap((s,t)=>l(s)?[]:[t]):[],malformedMetricColumns:"metricColumns"in m&&!Array.isArray(g),hasLegacyPresentation:c}),"metricColumns"in m||c)return}Object.entries(i).forEach(([n,c])=>r(c,a?`${a}.${n}`:n))};return r(e,"$"),o}const I={difference:"difference",change:"percent_change",change_difference:"both",ratio:"ratio"};function w(e,o){if(!e)return;const r=Object.fromEntries(o.flatMap(i=>typeof e[i]=="string"?[[i,e[i]]]:[]));return Object.keys(r).length?r:void 0}function M(e,o,r){if(e!==void 0){if(!l(e)){r.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:o,message:"Legacy comparison formatOptions must be an object."});return}Object.entries(e).forEach(([i,a])=>{if(i==="decimalPlaces"){(typeof a!="number"||!Number.isInteger(a)||a<0||a>6)&&r.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${o}.decimalPlaces`,message:"Legacy comparison decimalPlaces must be an integer from 0 through 6."});return}i==="type"&&(a===void 0||a==="auto")||a!==void 0&&r.push({severity:"error",code:"unsupported_comparison_format",path:`${o}.${i}`,message:`Legacy comparison format option "${i}" has no canonical presentation mapping.`})})}}function v(e,o){const r=o==="kpi"?e.calculationType:e.calculatedAs,i=o==="table"&&r===void 0?"both":I[String(r)],a=l(e.formatOptions)?e.formatOptions:void 0,m=l(e.conditionalLabels)?e.conditionalLabels:void 0,n=l(o==="kpi"?e.colorConfig:e.colors)?o==="kpi"?e.colorConfig:e.colors:void 0,c={};if(i&&(c.displayMode=i),typeof(a==null?void 0:a.decimalPlaces)=="number"&&(c.precision=a.decimalPlaces),o==="kpi"){const s=e.showArrow!==!1,t=e.showColor!==!1;c.indicatorStyle=s?t?"arrow_badge":"arrow":t?"badge":"none",c.showColor=t,(e.position==="left"||e.position==="right"||e.position==="top")&&(c.position=e.position),typeof e.conditionalLabel=="boolean"&&(c.conditionalLabel=e.conditionalLabel),typeof e.labelName=="string"&&(c.labelName=e.labelName)}else(e.indicatorStyle==="arrow_badge"||e.indicatorStyle==="arrow"||e.indicatorStyle==="badge"||e.indicatorStyle==="none")&&(c.indicatorStyle=e.indicatorStyle);const g=m?{...w(m,["increase","decrease"]),...typeof m.noChange=="string"?{neutral:m.noChange}:typeof m.neutral=="string"?{neutral:m.neutral}:{}}:void 0;g&&Object.keys(g).length&&(c.conditionalLabels=g);const p=n?{...w(n,["increase","decrease"]),...typeof n.noChange=="string"?{neutral:n.noChange}:typeof n.neutral=="string"?{neutral:n.neutral}:{}}:void 0;return p&&Object.keys(p).length&&(c.colors=p),c}function $(e){return{...E.COMPARISON_PRESENTATION_DEFAULTS,...e}}function T(e){return e.some(({metric:o})=>o.comparisonType==="previous_period"||o.comparisonType==="same_period_last_year"||o.comparisonType==="target"?!0:l(o.comparison)&&o.comparison.mode==="explicit")}function C(e){const o=e.card.config;return e.metrics.length===2&&(o.groupByColumns===void 0||Array.isArray(o.groupByColumns)&&o.groupByColumns.length===0)}function P(e,o,r,i){const a=o==="kpi"?["enabled","calculationType","formatOptions","showArrow","showColor","conditionalLabel","labelName","position","conditionalLabels","colorConfig","lowerIsBetter"]:["calculatedAs","indicatorStyle","formatOptions","colors","lowerIsBetter"];Object.keys(e).forEach(s=>{a.includes(s)||i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.${s}`,message:`Unknown legacy comparison presentation field "${s}" cannot be dropped automatically.`})});const m=o==="kpi"?"calculationType":"calculatedAs";e[m]!==void 0&&!I[String(e[m])]&&i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.${m}`,message:`Legacy comparison ${m} is unsupported.`}),o==="kpi"&&e.position!==void 0&&!["left","right","top"].includes(String(e.position))&&i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.position`,message:"Legacy comparison position is unsupported."}),o==="kpi"&&e.labelName!==void 0&&typeof e.labelName!="string"&&i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.labelName`,message:"Legacy comparison labelName must be a string."}),(o==="kpi"?[["conditionalLabels",["increase","decrease","noChange"]],["colorConfig",["increase","decrease","noChange"]]]:[["colors",["increase","decrease","neutral"]]]).forEach(([s,t])=>{if(e[s]!==void 0){if(!l(e[s])){i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.${s}`,message:`Legacy comparison ${s} must be an object.`});return}Object.entries(e[s]).forEach(([f,u])=>{t.includes(f)?typeof u!="string"&&i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.${s}.${f}`,message:`Legacy comparison ${s}.${f} must be a string.`}):i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.${s}.${f}`,message:`Unknown legacy comparison ${s} field "${f}" cannot be dropped automatically.`})})}}),(o==="kpi"?["enabled","showArrow","showColor","conditionalLabel","lowerIsBetter"]:["lowerIsBetter"]).forEach(s=>{e[s]!==void 0&&typeof e[s]!="boolean"&&i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.${s}`,message:`Legacy comparison ${s} must be a boolean.`})}),o==="table"&&e.indicatorStyle!==void 0&&!["arrow_badge","arrow","badge","none"].includes(String(e.indicatorStyle))&&i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${r}.indicatorStyle`,message:"Legacy comparison indicatorStyle is unsupported."}),M(e.formatOptions,`${r}.formatOptions`,i);const g=v(e,o);E.validateComparisonPresentationSpec(g,r).errors.forEach(s=>{i.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:s.path||r,message:s.message})})}function S(e){const o=L(e.card),r=o.kpiComparison?v(o.kpiComparison,"kpi"):void 0,i=o.tableComparison?v(o.tableComparison,"table"):void 0;return{namespaces:o,kpi:r,table:i,presentation:r||i}}function B(e){const o=l(e.preferences)?e.preferences:{},r=l(o.kpiVisualOptions)?o.kpiVisualOptions:{},i=l(r.metricComparison)?r.metricComparison:{},a=l(o.tableVisualOptions)?o.tableVisualOptions:{},m=l(a.metricComparison)?a.metricComparison:{};return r.lowerIsBetter===!0||i.lowerIsBetter===!0||m.lowerIsBetter===!0?"lower_is_better":"higher_is_better"}function D(e){switch(e.comparisonType){case"previous_period":return{mode:"explicit",spec:{kind:"previous_period"}};case"same_period_last_year":return{mode:"explicit",spec:{kind:"previous_year"}};case"target":return{mode:"explicit",spec:{kind:"target",targetValue:e.targetValue}};default:return}}function j(e){const o=l(e.preferences)?e.preferences:void 0;if(!o)return;const r=l(o.kpiVisualOptions)?o.kpiVisualOptions:void 0;r&&delete r.lowerIsBetter;const i=l(o.tableVisualOptions)?o.tableVisualOptions:void 0,a=i&&l(i.metricComparison)?i.metricComparison:void 0;a&&delete a.lowerIsBetter}function x(e){const o=O(e);if(!o.length)return{document:e,changed:!1,changes:[],diagnostics:[]};const r=[];if(o.forEach(n=>{var c,g,p,s;if(n.malformedMetricColumns&&r.push({severity:"error",code:"malformed_metric_columns",path:`${n.path}.config.metricColumns`,message:"Metric columns must be an array before comparison migration."}),n.malformedMetricIndexes.forEach(t=>{r.push({severity:"error",code:"malformed_metric_columns",path:`${n.path}.config.metricColumns[${t}]`,message:"Metric columns must contain objects before comparison migration."})}),n.metrics.forEach(({metric:t,index:f})=>{if(!("comparisonType"in t))return;const u=`${n.path}.config.metricColumns[${f}]`,d=String(t.comparisonType||"");"comparison"in t&&r.push({severity:"error",code:"conflicting_comparison_contracts",path:u,message:"Metric contains both legacy and canonical comparison configuration; resolve the conflict before migration."});const h=l(t.parameters)?t.parameters:void 0,b=h&&l(h.windowTransform)?h.windowTransform:void 0;_.has(d)&&(b==null?void 0:b.function)==="previous_period_delta"&&r.push({severity:"error",code:"conflicting_comparison_window_transform",path:u,message:"A metric cannot combine baseline comparison with previous_period_delta; resolve the authoring intent before migration."}),R.has(d)||r.push({severity:"error",code:"unsupported_comparison_type",path:`${u}.comparisonType`,message:`Unsupported legacy metric comparison type "${d}".`}),t.comparisonType==="target"&&(typeof t.targetValue!="number"||!Number.isFinite(t.targetValue))&&r.push({severity:"error",code:"invalid_target_value",path:`${u}.targetValue`,message:"Legacy target comparison requires a finite metric targetValue."}),t.comparisonType==="start_vs_end"&&r.push({severity:"error",code:"unsupported_start_vs_end",path:`${u}.comparisonType`,message:"start_vs_end is retired and cannot be migrated automatically."}),t.targetValue!==void 0&&t.comparisonType!=="target"&&r.push({severity:"warning",code:"stray_target_value",path:`${u}.targetValue`,message:"Dead non-target targetValue will be removed without changing the baseline."})}),n.hasLegacyPresentation){const{namespaces:t,kpi:f,table:u}=S(n),d=[(c=t.kpiOptions)==null?void 0:c.lowerIsBetter,(g=t.kpiComparison)==null?void 0:g.lowerIsBetter,(p=t.tableComparison)==null?void 0:p.lowerIsBetter].filter(h=>typeof h=="boolean");new Set(d).size>1&&r.push({severity:"error",code:"conflicting_legacy_polarity",path:`${n.path}.preferences`,message:"Legacy comparison polarity values disagree; resolve the conflict before migration."}),((s=t.kpiOptions)==null?void 0:s.lowerIsBetter)!==void 0&&typeof t.kpiOptions.lowerIsBetter!="boolean"&&r.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${n.path}.preferences.kpiVisualOptions.lowerIsBetter`,message:"Legacy comparison lowerIsBetter must be a boolean."}),t.kpiComparisonPresent&&!t.kpiComparison&&r.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${n.path}.preferences.kpiVisualOptions.metricComparison`,message:"Legacy KPI comparison presentation must be an object."}),t.tableComparisonPresent&&!t.tableComparison&&r.push({severity:"error",code:"invalid_legacy_comparison_presentation",path:`${n.path}.preferences.tableVisualOptions.metricComparison`,message:"Legacy table comparison presentation must be an object."}),"comparisonPresentation"in(t.preferences||{})&&r.push({severity:"error",code:"conflicting_comparison_presentation_contracts",path:`${n.path}.preferences.comparisonPresentation`,message:"Card contains both legacy and canonical comparison presentation; resolve the conflict before migration."}),t.kpiComparison&&typeof t.kpiComparison.enabled=="boolean"&&"metricPairComparisonEnabled"in(t.preferences||{})&&C(n)&&r.push({severity:"error",code:"conflicting_comparison_presentation_contracts",path:`${n.path}.preferences.metricPairComparisonEnabled`,message:"Card contains both legacy and canonical metric-pair enablement; resolve the conflict before migration."}),t.kpiComparison&&P(t.kpiComparison,"kpi",`${n.path}.preferences.kpiVisualOptions.metricComparison`,r),t.tableComparison&&P(t.tableComparison,"table",`${n.path}.preferences.tableVisualOptions.metricComparison`,r),f&&u&&JSON.stringify($(f))!==JSON.stringify($(u))&&r.push({severity:"error",code:"conflicting_legacy_presentation_namespaces",path:`${n.path}.preferences`,message:"KPI and table comparison presentation values disagree; resolve the conflict before migration."})}}),r.some(n=>n.severity==="error"))return{document:e,changed:!1,changes:[],diagnostics:r};const i=JSON.parse(JSON.stringify(e)),a=O(i),m=[];return a.forEach(n=>{var g;const c=B(n.card);if(n.metrics.forEach(({metric:p,index:s})=>{if(!("comparisonType"in p))return;const t=String(p.comparisonType||""),f=`${n.path}.config.metricColumns[${s}]`,u=D(p),d=["comparisonType"];delete p.comparisonType,"targetValue"in p&&(delete p.targetValue,d.push("targetValue")),"comparisonDisplay"in p&&(delete p.comparisonDisplay,d.push("comparisonDisplay")),u?p.comparison=u:delete p.comparison,_.has(t)&&(p.comparisonPolarity=c),m.push({kind:"metric",path:f,metricId:typeof p.id=="string"?p.id:void 0,legacyType:t,comparison:u,comparisonPolarity:_.has(t)?c:void 0,removedFields:d})}),j(n.card),n.hasLegacyPresentation){const{namespaces:p,presentation:s}=S(n),t=(g=p.kpiComparison)==null?void 0:g.enabled,f={...s};typeof t=="boolean"&&T(n.metrics)&&(f.showComparison=t);const u=typeof t=="boolean"&&C(n)?t:void 0,d=typeof t=="boolean"&&!T(n.metrics)&&!C(n)?["kpiVisualOptions.metricComparison.enabled"]:void 0,h=p.preferences,b=[];n.metrics.forEach(({metric:y})=>{"comparisonPolarity"in y||(y.comparisonPolarity=c,typeof y.id=="string"&&b.push(y.id))}),Object.keys(f).length&&(h.comparisonPresentation=f),u!==void 0&&(h.metricPairComparisonEnabled=u),p.kpiOptions&&delete p.kpiOptions.metricComparison,p.tableOptions&&delete p.tableOptions.metricComparison,m.push({kind:"presentation",path:`${n.path}.preferences`,comparisonPresentation:Object.keys(f).length?f:void 0,metricPairComparisonEnabled:u,comparisonPolarityMetricIds:b,intentionallyDiscardedFields:d,removedFields:[...p.kpiComparison?["kpiVisualOptions.metricComparison"]:[],...p.tableComparison?["tableVisualOptions.metricComparison"]:[]]})}}),{document:i,changed:!0,changes:m,diagnostics:r}}const k=["bar","horizontalBar","line","area","stackedArea","combo","stackedBar","stackedLine"],K=new Set(k);function V(e){return typeof e=="string"&&K.has(e)}function Y(e){return e==="detailTable"||e==="table"||e==="aggregateTable"||e==="pivotTable"||e==="custom"||V(e)}function A(e){return!!(e!=null&&e.trim())}function F(e){return A(e.sql)||A(e.normalizedPython)?"freeform":e.hasExecutableConfig?"config":"none"}const U="SEMAPHOR_CALCULATED_FIELD";function N(e,o,r){if(r&&(o==="groupby"||o==="pivotby"))return r;if(o==="metric"&&e.name==="*"&&!e.expression)return e.alias||"count";if(e.alias)return e.alias;const i=e.entityName&&e.entityName!==U?e.entityName:void 0;if(e.role==="metric"){let a=e.aggregate||"metric";if(e.expression){const m=e.expression.match(/^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i);a=m?m[1].toLowerCase():"expr"}else a=a.toLowerCase();return i&&i!==e.name?`${i}_${e.name}_${a}`:`${e.name}_${a}`}return i&&i!==e.name?`${i}_${e.name}`:e.name}function H(e){return N(e,"detail")}function q(e){const o=e.label;return o&&e.labelCount===1&&(o===e.rawKey||!e.rawKeys.has(o))?o:e.rawKey}exports.SEMAPHOR_CARTESIAN_CHART_TYPES=k;exports.isSemaphorCartesianChartType=V;exports.resolveCanonicalDetailResultRawKey=H;exports.resolveCanonicalResultOutputKey=q;exports.resolveCanonicalResultRawKey=N;exports.resolveTemporalResultOwner=F;exports.supportsCanonicalDashboardTemporalResult=Y;exports.transformComparisonDocument=x;
@@ -0,0 +1,466 @@
1
+ import "./validators-DeMXwRON.js";
2
+ import "./analyze-result-contract-GHKFwThg.js";
3
+ import { f as I, C as k } from "./metric-comparison-D0T0MKRK.js";
4
+ const _ = /* @__PURE__ */ new Set([
5
+ "previous_period",
6
+ "same_period_last_year",
7
+ "start_vs_end",
8
+ "target"
9
+ ]), V = /* @__PURE__ */ new Set([..._, "none", ""]);
10
+ function l(e) {
11
+ return !!e && typeof e == "object" && !Array.isArray(e);
12
+ }
13
+ function E(e) {
14
+ const o = l(e.preferences) ? e.preferences : void 0, r = o && l(o.kpiVisualOptions) ? o.kpiVisualOptions : void 0, i = o && l(o.tableVisualOptions) ? o.tableVisualOptions : void 0;
15
+ return {
16
+ preferences: o,
17
+ kpiOptions: r,
18
+ kpiComparison: r && l(r.metricComparison) ? r.metricComparison : void 0,
19
+ kpiComparisonPresent: !!r && "metricComparison" in r,
20
+ tableOptions: i,
21
+ tableComparison: i && l(i.metricComparison) ? i.metricComparison : void 0,
22
+ tableComparisonPresent: !!i && "metricComparison" in i
23
+ };
24
+ }
25
+ function $(e) {
26
+ const o = [], r = (i, a) => {
27
+ if (Array.isArray(i)) {
28
+ i.forEach((n, c) => r(n, `${a}[${c}]`));
29
+ return;
30
+ }
31
+ if (!l(i)) return;
32
+ const m = i.config;
33
+ if (l(m)) {
34
+ const n = E(i), c = !!(n.kpiComparisonPresent || n.tableComparisonPresent), g = m.metricColumns, p = Array.isArray(g) ? g.flatMap(
35
+ (s, t) => l(s) ? [{ index: t, metric: s }] : []
36
+ ) : [];
37
+ if ((p.some(({ metric: s }) => "comparisonType" in s) || c) && o.push({
38
+ path: a,
39
+ card: i,
40
+ metrics: p,
41
+ malformedMetricIndexes: Array.isArray(g) ? g.flatMap(
42
+ (s, t) => l(s) ? [] : [t]
43
+ ) : [],
44
+ malformedMetricColumns: "metricColumns" in m && !Array.isArray(g),
45
+ hasLegacyPresentation: c
46
+ }), "metricColumns" in m || c) return;
47
+ }
48
+ Object.entries(i).forEach(
49
+ ([n, c]) => r(c, a ? `${a}.${n}` : n)
50
+ );
51
+ };
52
+ return r(e, "$"), o;
53
+ }
54
+ const A = {
55
+ difference: "difference",
56
+ change: "percent_change",
57
+ change_difference: "both",
58
+ ratio: "ratio"
59
+ };
60
+ function O(e, o) {
61
+ if (!e) return;
62
+ const r = Object.fromEntries(
63
+ o.flatMap(
64
+ (i) => typeof e[i] == "string" ? [[i, e[i]]] : []
65
+ )
66
+ );
67
+ return Object.keys(r).length ? r : void 0;
68
+ }
69
+ function N(e, o, r) {
70
+ if (e !== void 0) {
71
+ if (!l(e)) {
72
+ r.push({
73
+ severity: "error",
74
+ code: "invalid_legacy_comparison_presentation",
75
+ path: o,
76
+ message: "Legacy comparison formatOptions must be an object."
77
+ });
78
+ return;
79
+ }
80
+ Object.entries(e).forEach(([i, a]) => {
81
+ if (i === "decimalPlaces") {
82
+ (typeof a != "number" || !Number.isInteger(a) || a < 0 || a > 6) && r.push({
83
+ severity: "error",
84
+ code: "invalid_legacy_comparison_presentation",
85
+ path: `${o}.decimalPlaces`,
86
+ message: "Legacy comparison decimalPlaces must be an integer from 0 through 6."
87
+ });
88
+ return;
89
+ }
90
+ i === "type" && (a === void 0 || a === "auto") || a !== void 0 && r.push({
91
+ severity: "error",
92
+ code: "unsupported_comparison_format",
93
+ path: `${o}.${i}`,
94
+ message: `Legacy comparison format option "${i}" has no canonical presentation mapping.`
95
+ });
96
+ });
97
+ }
98
+ }
99
+ function v(e, o) {
100
+ const r = o === "kpi" ? e.calculationType : e.calculatedAs, i = o === "table" && r === void 0 ? "both" : A[String(r)], a = l(e.formatOptions) ? e.formatOptions : void 0, m = l(e.conditionalLabels) ? e.conditionalLabels : void 0, n = l(
101
+ o === "kpi" ? e.colorConfig : e.colors
102
+ ) ? o === "kpi" ? e.colorConfig : e.colors : void 0, c = {};
103
+ if (i && (c.displayMode = i), typeof (a == null ? void 0 : a.decimalPlaces) == "number" && (c.precision = a.decimalPlaces), o === "kpi") {
104
+ const s = e.showArrow !== !1, t = e.showColor !== !1;
105
+ c.indicatorStyle = s ? t ? "arrow_badge" : "arrow" : t ? "badge" : "none", c.showColor = t, (e.position === "left" || e.position === "right" || e.position === "top") && (c.position = e.position), typeof e.conditionalLabel == "boolean" && (c.conditionalLabel = e.conditionalLabel), typeof e.labelName == "string" && (c.labelName = e.labelName);
106
+ } else (e.indicatorStyle === "arrow_badge" || e.indicatorStyle === "arrow" || e.indicatorStyle === "badge" || e.indicatorStyle === "none") && (c.indicatorStyle = e.indicatorStyle);
107
+ const g = m ? {
108
+ ...O(m, ["increase", "decrease"]),
109
+ ...typeof m.noChange == "string" ? { neutral: m.noChange } : typeof m.neutral == "string" ? { neutral: m.neutral } : {}
110
+ } : void 0;
111
+ g && Object.keys(g).length && (c.conditionalLabels = g);
112
+ const p = n ? {
113
+ ...O(n, ["increase", "decrease"]),
114
+ ...typeof n.noChange == "string" ? { neutral: n.noChange } : typeof n.neutral == "string" ? { neutral: n.neutral } : {}
115
+ } : void 0;
116
+ return p && Object.keys(p).length && (c.colors = p), c;
117
+ }
118
+ function w(e) {
119
+ return { ...k, ...e };
120
+ }
121
+ function P(e) {
122
+ return e.some(({ metric: o }) => o.comparisonType === "previous_period" || o.comparisonType === "same_period_last_year" || o.comparisonType === "target" ? !0 : l(o.comparison) && o.comparison.mode === "explicit");
123
+ }
124
+ function C(e) {
125
+ const o = e.card.config;
126
+ return e.metrics.length === 2 && (o.groupByColumns === void 0 || Array.isArray(o.groupByColumns) && o.groupByColumns.length === 0);
127
+ }
128
+ function L(e, o, r, i) {
129
+ const a = o === "kpi" ? [
130
+ "enabled",
131
+ "calculationType",
132
+ "formatOptions",
133
+ "showArrow",
134
+ "showColor",
135
+ "conditionalLabel",
136
+ "labelName",
137
+ "position",
138
+ "conditionalLabels",
139
+ "colorConfig",
140
+ "lowerIsBetter"
141
+ ] : [
142
+ "calculatedAs",
143
+ "indicatorStyle",
144
+ "formatOptions",
145
+ "colors",
146
+ "lowerIsBetter"
147
+ ];
148
+ Object.keys(e).forEach((s) => {
149
+ a.includes(s) || i.push({
150
+ severity: "error",
151
+ code: "invalid_legacy_comparison_presentation",
152
+ path: `${r}.${s}`,
153
+ message: `Unknown legacy comparison presentation field "${s}" cannot be dropped automatically.`
154
+ });
155
+ });
156
+ const m = o === "kpi" ? "calculationType" : "calculatedAs";
157
+ e[m] !== void 0 && !A[String(e[m])] && i.push({
158
+ severity: "error",
159
+ code: "invalid_legacy_comparison_presentation",
160
+ path: `${r}.${m}`,
161
+ message: `Legacy comparison ${m} is unsupported.`
162
+ }), o === "kpi" && e.position !== void 0 && !["left", "right", "top"].includes(String(e.position)) && i.push({
163
+ severity: "error",
164
+ code: "invalid_legacy_comparison_presentation",
165
+ path: `${r}.position`,
166
+ message: "Legacy comparison position is unsupported."
167
+ }), o === "kpi" && e.labelName !== void 0 && typeof e.labelName != "string" && i.push({
168
+ severity: "error",
169
+ code: "invalid_legacy_comparison_presentation",
170
+ path: `${r}.labelName`,
171
+ message: "Legacy comparison labelName must be a string."
172
+ }), (o === "kpi" ? [
173
+ ["conditionalLabels", ["increase", "decrease", "noChange"]],
174
+ ["colorConfig", ["increase", "decrease", "noChange"]]
175
+ ] : [["colors", ["increase", "decrease", "neutral"]]]).forEach(([s, t]) => {
176
+ if (e[s] !== void 0) {
177
+ if (!l(e[s])) {
178
+ i.push({
179
+ severity: "error",
180
+ code: "invalid_legacy_comparison_presentation",
181
+ path: `${r}.${s}`,
182
+ message: `Legacy comparison ${s} must be an object.`
183
+ });
184
+ return;
185
+ }
186
+ Object.entries(e[s]).forEach(([u, f]) => {
187
+ t.includes(u) ? typeof f != "string" && i.push({
188
+ severity: "error",
189
+ code: "invalid_legacy_comparison_presentation",
190
+ path: `${r}.${s}.${u}`,
191
+ message: `Legacy comparison ${s}.${u} must be a string.`
192
+ }) : i.push({
193
+ severity: "error",
194
+ code: "invalid_legacy_comparison_presentation",
195
+ path: `${r}.${s}.${u}`,
196
+ message: `Unknown legacy comparison ${s} field "${u}" cannot be dropped automatically.`
197
+ });
198
+ });
199
+ }
200
+ }), (o === "kpi" ? ["enabled", "showArrow", "showColor", "conditionalLabel", "lowerIsBetter"] : ["lowerIsBetter"]).forEach((s) => {
201
+ e[s] !== void 0 && typeof e[s] != "boolean" && i.push({
202
+ severity: "error",
203
+ code: "invalid_legacy_comparison_presentation",
204
+ path: `${r}.${s}`,
205
+ message: `Legacy comparison ${s} must be a boolean.`
206
+ });
207
+ }), o === "table" && e.indicatorStyle !== void 0 && !["arrow_badge", "arrow", "badge", "none"].includes(
208
+ String(e.indicatorStyle)
209
+ ) && i.push({
210
+ severity: "error",
211
+ code: "invalid_legacy_comparison_presentation",
212
+ path: `${r}.indicatorStyle`,
213
+ message: "Legacy comparison indicatorStyle is unsupported."
214
+ }), N(e.formatOptions, `${r}.formatOptions`, i);
215
+ const g = v(e, o);
216
+ I(g, r).errors.forEach((s) => {
217
+ i.push({
218
+ severity: "error",
219
+ code: "invalid_legacy_comparison_presentation",
220
+ path: s.path || r,
221
+ message: s.message
222
+ });
223
+ });
224
+ }
225
+ function T(e) {
226
+ const o = E(e.card), r = o.kpiComparison ? v(o.kpiComparison, "kpi") : void 0, i = o.tableComparison ? v(o.tableComparison, "table") : void 0;
227
+ return { namespaces: o, kpi: r, table: i, presentation: r || i };
228
+ }
229
+ function M(e) {
230
+ const o = l(e.preferences) ? e.preferences : {}, r = l(o.kpiVisualOptions) ? o.kpiVisualOptions : {}, i = l(r.metricComparison) ? r.metricComparison : {}, a = l(o.tableVisualOptions) ? o.tableVisualOptions : {}, m = l(a.metricComparison) ? a.metricComparison : {};
231
+ return r.lowerIsBetter === !0 || i.lowerIsBetter === !0 || m.lowerIsBetter === !0 ? "lower_is_better" : "higher_is_better";
232
+ }
233
+ function B(e) {
234
+ switch (e.comparisonType) {
235
+ case "previous_period":
236
+ return { mode: "explicit", spec: { kind: "previous_period" } };
237
+ case "same_period_last_year":
238
+ return { mode: "explicit", spec: { kind: "previous_year" } };
239
+ case "target":
240
+ return {
241
+ mode: "explicit",
242
+ spec: { kind: "target", targetValue: e.targetValue }
243
+ };
244
+ default:
245
+ return;
246
+ }
247
+ }
248
+ function R(e) {
249
+ const o = l(e.preferences) ? e.preferences : void 0;
250
+ if (!o) return;
251
+ const r = l(o.kpiVisualOptions) ? o.kpiVisualOptions : void 0;
252
+ r && delete r.lowerIsBetter;
253
+ const i = l(o.tableVisualOptions) ? o.tableVisualOptions : void 0, a = i && l(i.metricComparison) ? i.metricComparison : void 0;
254
+ a && delete a.lowerIsBetter;
255
+ }
256
+ function z(e) {
257
+ const o = $(e);
258
+ if (!o.length)
259
+ return { document: e, changed: !1, changes: [], diagnostics: [] };
260
+ const r = [];
261
+ if (o.forEach((n) => {
262
+ var c, g, p, s;
263
+ if (n.malformedMetricColumns && r.push({
264
+ severity: "error",
265
+ code: "malformed_metric_columns",
266
+ path: `${n.path}.config.metricColumns`,
267
+ message: "Metric columns must be an array before comparison migration."
268
+ }), n.malformedMetricIndexes.forEach((t) => {
269
+ r.push({
270
+ severity: "error",
271
+ code: "malformed_metric_columns",
272
+ path: `${n.path}.config.metricColumns[${t}]`,
273
+ message: "Metric columns must contain objects before comparison migration."
274
+ });
275
+ }), n.metrics.forEach(({ metric: t, index: u }) => {
276
+ if (!("comparisonType" in t)) return;
277
+ const f = `${n.path}.config.metricColumns[${u}]`, d = String(t.comparisonType || "");
278
+ "comparison" in t && r.push({
279
+ severity: "error",
280
+ code: "conflicting_comparison_contracts",
281
+ path: f,
282
+ message: "Metric contains both legacy and canonical comparison configuration; resolve the conflict before migration."
283
+ });
284
+ const h = l(t.parameters) ? t.parameters : void 0, b = h && l(h.windowTransform) ? h.windowTransform : void 0;
285
+ _.has(d) && (b == null ? void 0 : b.function) === "previous_period_delta" && r.push({
286
+ severity: "error",
287
+ code: "conflicting_comparison_window_transform",
288
+ path: f,
289
+ message: "A metric cannot combine baseline comparison with previous_period_delta; resolve the authoring intent before migration."
290
+ }), V.has(d) || r.push({
291
+ severity: "error",
292
+ code: "unsupported_comparison_type",
293
+ path: `${f}.comparisonType`,
294
+ message: `Unsupported legacy metric comparison type "${d}".`
295
+ }), t.comparisonType === "target" && (typeof t.targetValue != "number" || !Number.isFinite(t.targetValue)) && r.push({
296
+ severity: "error",
297
+ code: "invalid_target_value",
298
+ path: `${f}.targetValue`,
299
+ message: "Legacy target comparison requires a finite metric targetValue."
300
+ }), t.comparisonType === "start_vs_end" && r.push({
301
+ severity: "error",
302
+ code: "unsupported_start_vs_end",
303
+ path: `${f}.comparisonType`,
304
+ message: "start_vs_end is retired and cannot be migrated automatically."
305
+ }), t.targetValue !== void 0 && t.comparisonType !== "target" && r.push({
306
+ severity: "warning",
307
+ code: "stray_target_value",
308
+ path: `${f}.targetValue`,
309
+ message: "Dead non-target targetValue will be removed without changing the baseline."
310
+ });
311
+ }), n.hasLegacyPresentation) {
312
+ const { namespaces: t, kpi: u, table: f } = T(n), d = [
313
+ (c = t.kpiOptions) == null ? void 0 : c.lowerIsBetter,
314
+ (g = t.kpiComparison) == null ? void 0 : g.lowerIsBetter,
315
+ (p = t.tableComparison) == null ? void 0 : p.lowerIsBetter
316
+ ].filter((h) => typeof h == "boolean");
317
+ new Set(d).size > 1 && r.push({
318
+ severity: "error",
319
+ code: "conflicting_legacy_polarity",
320
+ path: `${n.path}.preferences`,
321
+ message: "Legacy comparison polarity values disagree; resolve the conflict before migration."
322
+ }), ((s = t.kpiOptions) == null ? void 0 : s.lowerIsBetter) !== void 0 && typeof t.kpiOptions.lowerIsBetter != "boolean" && r.push({
323
+ severity: "error",
324
+ code: "invalid_legacy_comparison_presentation",
325
+ path: `${n.path}.preferences.kpiVisualOptions.lowerIsBetter`,
326
+ message: "Legacy comparison lowerIsBetter must be a boolean."
327
+ }), t.kpiComparisonPresent && !t.kpiComparison && r.push({
328
+ severity: "error",
329
+ code: "invalid_legacy_comparison_presentation",
330
+ path: `${n.path}.preferences.kpiVisualOptions.metricComparison`,
331
+ message: "Legacy KPI comparison presentation must be an object."
332
+ }), t.tableComparisonPresent && !t.tableComparison && r.push({
333
+ severity: "error",
334
+ code: "invalid_legacy_comparison_presentation",
335
+ path: `${n.path}.preferences.tableVisualOptions.metricComparison`,
336
+ message: "Legacy table comparison presentation must be an object."
337
+ }), "comparisonPresentation" in (t.preferences || {}) && r.push({
338
+ severity: "error",
339
+ code: "conflicting_comparison_presentation_contracts",
340
+ path: `${n.path}.preferences.comparisonPresentation`,
341
+ message: "Card contains both legacy and canonical comparison presentation; resolve the conflict before migration."
342
+ }), t.kpiComparison && typeof t.kpiComparison.enabled == "boolean" && "metricPairComparisonEnabled" in (t.preferences || {}) && C(n) && r.push({
343
+ severity: "error",
344
+ code: "conflicting_comparison_presentation_contracts",
345
+ path: `${n.path}.preferences.metricPairComparisonEnabled`,
346
+ message: "Card contains both legacy and canonical metric-pair enablement; resolve the conflict before migration."
347
+ }), t.kpiComparison && L(
348
+ t.kpiComparison,
349
+ "kpi",
350
+ `${n.path}.preferences.kpiVisualOptions.metricComparison`,
351
+ r
352
+ ), t.tableComparison && L(
353
+ t.tableComparison,
354
+ "table",
355
+ `${n.path}.preferences.tableVisualOptions.metricComparison`,
356
+ r
357
+ ), u && f && JSON.stringify(w(u)) !== JSON.stringify(w(f)) && r.push({
358
+ severity: "error",
359
+ code: "conflicting_legacy_presentation_namespaces",
360
+ path: `${n.path}.preferences`,
361
+ message: "KPI and table comparison presentation values disagree; resolve the conflict before migration."
362
+ });
363
+ }
364
+ }), r.some((n) => n.severity === "error"))
365
+ return { document: e, changed: !1, changes: [], diagnostics: r };
366
+ const i = JSON.parse(JSON.stringify(e)), a = $(i), m = [];
367
+ return a.forEach((n) => {
368
+ var g;
369
+ const c = M(n.card);
370
+ if (n.metrics.forEach(({ metric: p, index: s }) => {
371
+ if (!("comparisonType" in p)) return;
372
+ const t = String(p.comparisonType || ""), u = `${n.path}.config.metricColumns[${s}]`, f = B(p), d = ["comparisonType"];
373
+ delete p.comparisonType, "targetValue" in p && (delete p.targetValue, d.push("targetValue")), "comparisonDisplay" in p && (delete p.comparisonDisplay, d.push("comparisonDisplay")), f ? p.comparison = f : delete p.comparison, _.has(t) && (p.comparisonPolarity = c), m.push({
374
+ kind: "metric",
375
+ path: u,
376
+ metricId: typeof p.id == "string" ? p.id : void 0,
377
+ legacyType: t,
378
+ comparison: f,
379
+ comparisonPolarity: _.has(t) ? c : void 0,
380
+ removedFields: d
381
+ });
382
+ }), R(n.card), n.hasLegacyPresentation) {
383
+ const { namespaces: p, presentation: s } = T(n), t = (g = p.kpiComparison) == null ? void 0 : g.enabled, u = {
384
+ ...s
385
+ };
386
+ typeof t == "boolean" && P(n.metrics) && (u.showComparison = t);
387
+ const f = typeof t == "boolean" && C(n) ? t : void 0, d = typeof t == "boolean" && !P(n.metrics) && !C(n) ? ["kpiVisualOptions.metricComparison.enabled"] : void 0, h = p.preferences, b = [];
388
+ n.metrics.forEach(({ metric: y }) => {
389
+ "comparisonPolarity" in y || (y.comparisonPolarity = c, typeof y.id == "string" && b.push(y.id));
390
+ }), Object.keys(u).length && (h.comparisonPresentation = u), f !== void 0 && (h.metricPairComparisonEnabled = f), p.kpiOptions && delete p.kpiOptions.metricComparison, p.tableOptions && delete p.tableOptions.metricComparison, m.push({
391
+ kind: "presentation",
392
+ path: `${n.path}.preferences`,
393
+ comparisonPresentation: Object.keys(u).length ? u : void 0,
394
+ metricPairComparisonEnabled: f,
395
+ comparisonPolarityMetricIds: b,
396
+ intentionallyDiscardedFields: d,
397
+ removedFields: [
398
+ ...p.kpiComparison ? ["kpiVisualOptions.metricComparison"] : [],
399
+ ...p.tableComparison ? ["tableVisualOptions.metricComparison"] : []
400
+ ]
401
+ });
402
+ }
403
+ }), { document: i, changed: !0, changes: m, diagnostics: r };
404
+ }
405
+ const D = [
406
+ "bar",
407
+ "horizontalBar",
408
+ "line",
409
+ "area",
410
+ "stackedArea",
411
+ "combo",
412
+ "stackedBar",
413
+ "stackedLine"
414
+ ], x = new Set(
415
+ D
416
+ );
417
+ function j(e) {
418
+ return typeof e == "string" && x.has(e);
419
+ }
420
+ function G(e) {
421
+ return e === "detailTable" || e === "table" || e === "aggregateTable" || e === "pivotTable" || e === "custom" || j(e);
422
+ }
423
+ function S(e) {
424
+ return !!(e != null && e.trim());
425
+ }
426
+ function J(e) {
427
+ return S(e.sql) || S(e.normalizedPython) ? "freeform" : e.hasExecutableConfig ? "config" : "none";
428
+ }
429
+ const F = "SEMAPHOR_CALCULATED_FIELD";
430
+ function K(e, o, r) {
431
+ if (r && (o === "groupby" || o === "pivotby"))
432
+ return r;
433
+ if (o === "metric" && e.name === "*" && !e.expression)
434
+ return e.alias || "count";
435
+ if (e.alias) return e.alias;
436
+ const i = e.entityName && e.entityName !== F ? e.entityName : void 0;
437
+ if (e.role === "metric") {
438
+ let a = e.aggregate || "metric";
439
+ if (e.expression) {
440
+ const m = e.expression.match(
441
+ /^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i
442
+ );
443
+ a = m ? m[1].toLowerCase() : "expr";
444
+ } else
445
+ a = a.toLowerCase();
446
+ return i && i !== e.name ? `${i}_${e.name}_${a}` : `${e.name}_${a}`;
447
+ }
448
+ return i && i !== e.name ? `${i}_${e.name}` : e.name;
449
+ }
450
+ function q(e) {
451
+ return K(e, "detail");
452
+ }
453
+ function W(e) {
454
+ const o = e.label;
455
+ return o && e.labelCount === 1 && (o === e.rawKey || !e.rawKeys.has(o)) ? o : e.rawKey;
456
+ }
457
+ export {
458
+ D as S,
459
+ K as a,
460
+ q as b,
461
+ W as c,
462
+ j as i,
463
+ J as r,
464
+ G as s,
465
+ z as t
466
+ };