react-semaphor 0.1.449 → 0.1.454

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