react-semaphor 0.1.443 → 0.1.445

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 (133) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/analytics-protocol/index.cjs +1 -1
  3. package/dist/analytics-protocol/index.js +123 -107
  4. package/dist/appearance/index.cjs +1 -1
  5. package/dist/brand-studio/index.cjs +2 -2
  6. package/dist/brand-studio/index.js +5 -4
  7. package/dist/briefings/index.cjs +1 -1
  8. package/dist/briefings/index.js +526 -457
  9. package/dist/chunks/analyze-result-contract-BHb7sUUW.cjs +1 -0
  10. package/dist/chunks/analyze-result-contract-DUv3QnMl.js +29 -0
  11. package/dist/chunks/{braces-CbO-aIwH.js → braces-BKimshER.cjs} +1 -1
  12. package/dist/chunks/{code-editor-BpADiIlq.js → code-editor-B4gTfvc5.js} +6800 -6560
  13. package/dist/chunks/code-editor-BYVorgOf.cjs +138 -0
  14. package/dist/chunks/common-types-CQ6SHfLk.cjs +1 -0
  15. package/dist/chunks/{common-types-ClkOI-3O.js → common-types-DFsDdpH7.js} +22 -21
  16. package/dist/chunks/dashboard-CAiwJW3L.cjs +1397 -0
  17. package/dist/chunks/{dashboard-briefing-launcher-C60n8LqW.js → dashboard-briefing-launcher-2SLNOaTg.js} +26 -24
  18. package/dist/chunks/{dashboard-briefing-launcher-BYMLjZxG.js → dashboard-briefing-launcher-CHwjpUYz.cjs} +2 -2
  19. package/dist/chunks/{dashboard-controls-ti9Rcel2.js → dashboard-controls-BfL14aqO.js} +11 -9
  20. package/dist/chunks/{dashboard-controls-BH_fZYDU.js → dashboard-controls-BgGTg4yw.cjs} +2 -2
  21. package/dist/chunks/dashboard-date-comparison-definition-DZq0htjG.cjs +1 -0
  22. package/dist/chunks/dashboard-json-BOv8tCa9.cjs +1 -0
  23. package/dist/chunks/{dashboard-json-Bturr634.js → dashboard-json-BZwq3EcS.js} +14 -12
  24. package/dist/chunks/{dashboard-Bd1Quco-.js → dashboard-u61yfU6u.js} +50081 -47351
  25. package/dist/chunks/edit-dashboard-visual-BdVCH0DJ.cjs +182 -0
  26. package/dist/chunks/{edit-dashboard-visual-DglMds57.js → edit-dashboard-visual-njLPYip3.js} +6825 -6656
  27. package/dist/chunks/{editor-action-buttons-CRi0fhVW.js → editor-action-buttons-BhLX5Q6m.js} +24 -23
  28. package/dist/chunks/{editor-action-buttons-Cxo7_tNG.js → editor-action-buttons-CBVMFipA.cjs} +1 -1
  29. package/dist/chunks/{index-D7KJindZ.js → format-types-CSv0V7mm.cjs} +1 -1
  30. package/dist/chunks/{index-CnujJ3fa.js → format-types-CZH5w1lo.js} +23 -17
  31. package/dist/chunks/{layout-grid-B08pP7v6.js → layout-grid-3-HWzEwU.cjs} +1 -1
  32. package/dist/chunks/{metric-comparison-CPoDx56y.js → metric-comparison-BJ_Qu1ZF.js} +1 -1
  33. package/dist/chunks/metric-comparison-CUAJ8n4y.cjs +1 -0
  34. package/dist/chunks/{palette-C0yjT5Tv.js → palette-DW_l7Jr0.cjs} +1 -1
  35. package/dist/chunks/pivot-result-identity-B6QCWOSi.js +94 -0
  36. package/dist/chunks/pivot-result-identity-CDLRT-YG.cjs +1 -0
  37. package/dist/chunks/pivot-result-lifecycle-BM3Pl-D1.js +914 -0
  38. package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +4 -0
  39. package/dist/chunks/presentation-execution-BTV-Q43g.cjs +1 -0
  40. package/dist/chunks/presentation-execution-CGlb7YZ6.js +637 -0
  41. package/dist/chunks/{report-preferences-dialog-TtwdAuNn.js → report-preferences-dialog-D_NJu2wU.js} +7 -6
  42. package/dist/chunks/report-preferences-dialog-r8QzOSFb.cjs +1 -0
  43. package/dist/chunks/report-runtime-context-C8LZFsqV.cjs +1 -0
  44. package/dist/chunks/report-runtime-context-Qzn11HQe.js +387 -0
  45. package/dist/chunks/{save-Xdc4pnys.js → save-4_uMnE6s.cjs} +1 -1
  46. package/dist/chunks/{search-Dcud9ajy.js → search-6ZmeMq55.cjs} +1 -1
  47. package/dist/chunks/temporal-bucket-BnPxGrAi.js +446 -0
  48. package/dist/chunks/temporal-bucket-authoring-BUZMuVca.js +205 -0
  49. package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +1 -0
  50. package/dist/chunks/temporal-bucket-contract-B2bJ1oe4.js +108 -0
  51. package/dist/chunks/temporal-bucket-contract-ChDBWX8I.cjs +1 -0
  52. package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +1 -0
  53. package/dist/chunks/{comparison-document-migration-Dj6xZMCb.js → temporal-result-owner-Cb27SSG9.js} +152 -123
  54. package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +1 -0
  55. package/dist/chunks/token-types-BdQ8kHBm.cjs +1 -0
  56. package/dist/chunks/token-types-DLo91nOf.js +8 -0
  57. package/dist/chunks/{update-policy-DnF_74zC.js → update-policy-BxvYMYz0.cjs} +1 -1
  58. package/dist/chunks/{update-policy-De2NswtM.js → update-policy-eg59mQqv.js} +1 -1
  59. package/dist/chunks/validators-9D4KBqKD.cjs +1 -0
  60. package/dist/chunks/validators-wZ2WlNHc.js +4640 -0
  61. package/dist/dashboard/index.cjs +1 -1
  62. package/dist/dashboard/index.js +2 -2
  63. package/dist/dashboard-authoring/index.cjs +3 -3
  64. package/dist/dashboard-authoring/index.js +136 -126
  65. package/dist/data-app-builder/index.cjs +1 -1
  66. package/dist/data-app-builder/index.js +2 -2
  67. package/dist/data-app-codegen/index.cjs +1 -1
  68. package/dist/data-app-codegen/index.js +2 -2
  69. package/dist/data-app-codegen-node/index.cjs +1 -1
  70. package/dist/data-app-codegen-node/index.js +3 -3
  71. package/dist/data-app-sdk/index.cjs +2 -2
  72. package/dist/data-app-sdk/index.js +34 -35
  73. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  74. package/dist/data-app-sdk-adapters/index.js +5 -5
  75. package/dist/data-app-sdk-validation/index.cjs +1 -1
  76. package/dist/data-app-sdk-validation/index.js +9 -10
  77. package/dist/format-utils/index.cjs +3 -3
  78. package/dist/format-utils/index.js +155 -176
  79. package/dist/index.cjs +1 -1
  80. package/dist/index.js +180 -174
  81. package/dist/report-runtime-context/index.cjs +1 -1
  82. package/dist/report-runtime-context/index.js +7 -392
  83. package/dist/shared/index.cjs +1 -1
  84. package/dist/style.css +1 -1
  85. package/dist/surfboard/index.cjs +1 -1
  86. package/dist/surfboard/index.js +3 -3
  87. package/dist/types/analytics-protocol.d.ts +257 -48
  88. package/dist/types/briefings.d.ts +138 -50
  89. package/dist/types/dashboard-assistant.d.ts +207 -52
  90. package/dist/types/dashboard-authoring.d.ts +182 -50
  91. package/dist/types/dashboard.d.ts +290 -48
  92. package/dist/types/data-app-builder.d.ts +48 -42
  93. package/dist/types/data-app-codegen-node.d.ts +50 -44
  94. package/dist/types/data-app-codegen.d.ts +50 -44
  95. package/dist/types/data-app-sdk-adapters.d.ts +48 -42
  96. package/dist/types/data-app-sdk-validation.d.ts +81 -43
  97. package/dist/types/data-app-sdk.d.ts +83 -45
  98. package/dist/types/format-utils.d.ts +645 -67
  99. package/dist/types/index.cjs +1 -1
  100. package/dist/types/index.js +19 -19
  101. package/dist/types/main.d.ts +298 -94
  102. package/dist/types/report-runtime-context.d.ts +3 -0
  103. package/dist/types/shared.d.ts +116 -41
  104. package/dist/types/surfboard.d.ts +290 -48
  105. package/dist/types/types.d.ts +455 -65
  106. package/package.json +3 -1
  107. package/dist/chunks/analyze-result-contract-BswhsmWT.js +0 -1
  108. package/dist/chunks/analyze-result-contract-CfOBEwaC.js +0 -1998
  109. package/dist/chunks/code-editor-M7HTUhdF.js +0 -138
  110. package/dist/chunks/common-types-C73-Ud1-.js +0 -1
  111. package/dist/chunks/comparison-document-migration-DbU_BTxR.js +0 -1
  112. package/dist/chunks/csv-utils-BZDvO2Fw.js +0 -376
  113. package/dist/chunks/csv-utils-Co0WxHke.js +0 -4
  114. package/dist/chunks/dashboard-cB3xmTNn.js +0 -1402
  115. package/dist/chunks/dashboard-date-comparison-definition-DGZr3m-b.js +0 -1
  116. package/dist/chunks/dashboard-json-Dw_55vSZ.js +0 -1
  117. package/dist/chunks/edit-dashboard-visual-BUc3NBQ4.js +0 -182
  118. package/dist/chunks/metric-comparison-DVy3fll_.js +0 -1
  119. package/dist/chunks/numeric-presentation-BJs5lSar.js +0 -517
  120. package/dist/chunks/numeric-presentation-Dlb-Dk4c.js +0 -1
  121. package/dist/chunks/report-preferences-dialog-CCvFqH4Q.js +0 -1
  122. package/dist/chunks/source-identity-5OPV4gvg.js +0 -92
  123. package/dist/chunks/source-identity-Cbo2LOHQ.js +0 -1
  124. package/dist/chunks/validators-B2vUAqTf.js +0 -1
  125. package/dist/chunks/validators-Bce_J7Vd.js +0 -2448
  126. /package/dist/chunks/{card-config-utils-15sRtebL.js → card-config-utils-15sRtebL.cjs} +0 -0
  127. /package/dist/chunks/{catalog-field-grounding-Bnx-3tE0.js → catalog-field-grounding-Bnx-3tE0.cjs} +0 -0
  128. /package/dist/chunks/{dashboard-input-contract-DV3cshjz.js → dashboard-input-contract-DV3cshjz.cjs} +0 -0
  129. /package/dist/chunks/{index-Dpm_VET4.js → index-Dpm_VET4.cjs} +0 -0
  130. /package/dist/chunks/{index-jSrCwPQz.js → index-jSrCwPQz.cjs} +0 -0
  131. /package/dist/chunks/{normalize-dashboard-for-dirty-check-BXRUMVb2.js → normalize-dashboard-for-dirty-check-BXRUMVb2.cjs} +0 -0
  132. /package/dist/chunks/{operators-DrTQsJXv.js → operators-DrTQsJXv.cjs} +0 -0
  133. /package/dist/chunks/{use-debounced-dirty-check-XHSwAefL.js → use-debounced-dirty-check-XHSwAefL.cjs} +0 -0
@@ -1,12 +1,11 @@
1
1
  import { toSemaphorInputSnapshots as jr, toSemaphorInputBinding as Hr, toSemaphorActiveInputSnapshots as X, toSemaphorMatrixIntent as Pr, toSemaphorSqlIntent as Vr, toSemaphorInputOptionsIntent as Qr, toSemaphorRecordsIntent as Ur, toSemaphorAnalysisQueryOptions as Gr, toSemaphorAnalysisIntent as Jr, toSemaphorMetricIntent as Yr, hasSemaphorInputValue as ue, normalizeSemaphorInputOptions as hr, toSemaphorInputSpec as br } from "../data-app-sdk-adapters/index.js";
2
2
  import { jsxs as p, Fragment as vr, jsx as a } from "react/jsx-runtime";
3
3
  import { createContext as Ie, useContext as Q, useState as z, useRef as E, useEffect as B, useMemo as I, Fragment as Xr, useReducer as Zr, useId as Sr, useCallback as D } from "react";
4
- import { c as et, m as rt } from "../chunks/source-identity-5OPV4gvg.js";
5
- import { a as lo, e as uo } from "../chunks/source-identity-5OPV4gvg.js";
6
- import "../chunks/analyze-result-contract-CfOBEwaC.js";
7
- import { M as tt, a as nt, S as it, E as ot, C as st } from "../chunks/search-DHZCro8B.js";
8
- import { X as at, C as lt, j as dt } from "../chunks/index-xHCrHprY.js";
9
- import { v as ut } from "../chunks/validators-Bce_J7Vd.js";
4
+ import { l as et, y as rt, j as tt } from "../chunks/validators-wZ2WlNHc.js";
5
+ import { c as ao, P as lo } from "../chunks/validators-wZ2WlNHc.js";
6
+ import "../chunks/analyze-result-contract-DUv3QnMl.js";
7
+ import { M as nt, a as it, S as ot, E as st, C as at } from "../chunks/search-DHZCro8B.js";
8
+ import { X as lt, C as dt, j as ut } from "../chunks/index-xHCrHprY.js";
10
9
  function me(e, r, t = {}) {
11
10
  return {
12
11
  ...t,
@@ -14,13 +13,13 @@ function me(e, r, t = {}) {
14
13
  role: r
15
14
  };
16
15
  }
17
- function Ji(e) {
16
+ function Gi(e) {
18
17
  return e;
19
18
  }
20
- function Yi(e) {
19
+ function Ji(e) {
21
20
  return e;
22
21
  }
23
- const Xi = {
22
+ const Yi = {
24
23
  source: {
25
24
  semantic(e) {
26
25
  return {
@@ -1634,7 +1633,7 @@ function Cr() {
1634
1633
  const e = V[V.length - 1];
1635
1634
  e ? window.__SEMAPHOR_DEVTOOLS__ = e.bridge : delete window.__SEMAPHOR_DEVTOOLS__;
1636
1635
  }
1637
- function Zi({
1636
+ function Xi({
1638
1637
  id: e,
1639
1638
  title: r,
1640
1639
  children: t
@@ -1760,7 +1759,7 @@ function _t({
1760
1759
  title: c ? "Exit fullscreen Semaphor Inspector" : "Enter fullscreen Semaphor Inspector",
1761
1760
  style: s.iconButton,
1762
1761
  onClick: () => g((S) => !S),
1763
- children: c ? /* @__PURE__ */ a(tt, { size: 15 }) : /* @__PURE__ */ a(nt, { size: 15 })
1762
+ children: c ? /* @__PURE__ */ a(nt, { size: 15 }) : /* @__PURE__ */ a(it, { size: 15 })
1764
1763
  }
1765
1764
  ),
1766
1765
  /* @__PURE__ */ a(
@@ -1770,13 +1769,13 @@ function _t({
1770
1769
  "aria-label": "Close Semaphor Inspector",
1771
1770
  style: s.iconButton,
1772
1771
  onClick: u.closeDevtools,
1773
- children: /* @__PURE__ */ a(at, { size: 15 })
1772
+ children: /* @__PURE__ */ a(lt, { size: 15 })
1774
1773
  }
1775
1774
  )
1776
1775
  ] })
1777
1776
  ] }),
1778
1777
  /* @__PURE__ */ p("label", { style: s.searchBox, children: [
1779
- /* @__PURE__ */ a(it, { size: 14 }),
1778
+ /* @__PURE__ */ a(ot, { size: 14 }),
1780
1779
  /* @__PURE__ */ a(
1781
1780
  "input",
1782
1781
  {
@@ -1882,7 +1881,7 @@ function _t({
1882
1881
  ) : null
1883
1882
  ] });
1884
1883
  }
1885
- function eo({
1884
+ function Zi({
1886
1885
  queryId: e,
1887
1886
  viewId: r,
1888
1887
  label: t,
@@ -1926,7 +1925,7 @@ function eo({
1926
1925
  viewId: c.viewId
1927
1926
  }),
1928
1927
  children: [
1929
- /* @__PURE__ */ a(ot, { size: 13 }),
1928
+ /* @__PURE__ */ a(st, { size: 13 }),
1930
1929
  /* @__PURE__ */ a("span", { style: s.inspectButtonText, children: ((v = c.latestAttempt) == null ? void 0 : v.status) || "idle" })
1931
1930
  ]
1932
1931
  }
@@ -2318,7 +2317,7 @@ function Ht({
2318
2317
  onClick: () => n((c) => !c),
2319
2318
  children: [
2320
2319
  /* @__PURE__ */ p("span", { style: s.issueSummaryHeaderLabel, children: [
2321
- t ? /* @__PURE__ */ a(lt, { size: 13 }) : /* @__PURE__ */ a(st, { size: 13 }),
2320
+ t ? /* @__PURE__ */ a(dt, { size: 13 }) : /* @__PURE__ */ a(at, { size: 13 }),
2322
2321
  /* @__PURE__ */ a("span", { children: "Issues" })
2323
2322
  ] }),
2324
2323
  /* @__PURE__ */ a("span", { style: s.issueSummaryCount, children: e.length })
@@ -3853,7 +3852,7 @@ function wi(e) {
3853
3852
  return e instanceof Error && e.kind === "data_app_query_error";
3854
3853
  }
3855
3854
  function ee(e, r = e.kind) {
3856
- const t = ut(e);
3855
+ const t = tt(e);
3857
3856
  if (t.ok)
3858
3857
  return null;
3859
3858
  const n = t.errors.map(
@@ -4050,7 +4049,7 @@ function Li(e) {
4050
4049
  if (!e.token)
4051
4050
  return "";
4052
4051
  try {
4053
- return dt(e.token).apiServiceUrl || "";
4052
+ return ut(e.token).apiServiceUrl || "";
4054
4053
  } catch {
4055
4054
  return "";
4056
4055
  }
@@ -4063,7 +4062,7 @@ function $i() {
4063
4062
  function Oi() {
4064
4063
  return Q(Mr);
4065
4064
  }
4066
- function ro(e) {
4065
+ function eo(e) {
4067
4066
  const [r, t] = z(e.defaultValue), n = Object.prototype.hasOwnProperty.call(e, "value"), i = n ? e.value : r, o = I(
4068
4067
  () => hr(e.options),
4069
4068
  [e.options]
@@ -4104,7 +4103,7 @@ function ro(e) {
4104
4103
  };
4105
4104
  }, [f, o, u, e, i]);
4106
4105
  }
4107
- function to(e) {
4106
+ function ro(e) {
4108
4107
  const [r, t] = z(() => Mi(e));
4109
4108
  return B(() => {
4110
4109
  t((n) => {
@@ -4154,7 +4153,7 @@ function to(e) {
4154
4153
  [e, r]
4155
4154
  );
4156
4155
  }
4157
- function no(e, r) {
4156
+ function to(e, r) {
4158
4157
  const t = (r == null ? void 0 : r.status) === "success" ? r.options : void 0, n = I(() => Bi(t), [t]);
4159
4158
  B(() => {
4160
4159
  Di(e.value, t) || e.clear();
@@ -4176,7 +4175,7 @@ function Bi(e) {
4176
4175
  function mr(e) {
4177
4176
  return `${typeof e}:${String(e)}`;
4178
4177
  }
4179
- function io(e, r = {}) {
4178
+ function no(e, r = {}) {
4180
4179
  const t = I(
4181
4180
  () => r.inputs ? {
4182
4181
  ...e,
@@ -4571,7 +4570,7 @@ function Se(e) {
4571
4570
  function Fi(e) {
4572
4571
  return !e || typeof e == "boolean" || e.enabled === !1 ? null : e.autoRenderDevtools === !0 ? {} : e.autoRenderDevtools ? e.autoRenderDevtools : null;
4573
4572
  }
4574
- function oo({
4573
+ function io({
4575
4574
  token: e,
4576
4575
  apiBaseUrl: r,
4577
4576
  executor: t,
@@ -4594,20 +4593,20 @@ function oo({
4594
4593
  ] }) });
4595
4594
  }
4596
4595
  export {
4597
- oo as SemaphorDataAppProvider,
4596
+ io as SemaphorDataAppProvider,
4598
4597
  _t as SemaphorDevtools,
4599
- eo as SemaphorDevtoolsInspectButton,
4600
- Zi as SemaphorViewBoundary,
4598
+ Zi as SemaphorDevtoolsInspectButton,
4599
+ Xi as SemaphorViewBoundary,
4601
4600
  Ii as createSemaphorQueryExecutor,
4602
- Ji as defineSemaphorDataApp,
4603
- Yi as defineSemaphorInput,
4601
+ Gi as defineSemaphorDataApp,
4602
+ Ji as defineSemaphorInput,
4604
4603
  Di as isSemaphorInputValueValidForOptions,
4605
- Xi as semaphor,
4606
- lo as semaphorMetricAggregate,
4607
- uo as semaphorMetricMeasureBindingKey,
4608
- no as useClearInvalidSemaphorInputValue,
4604
+ Yi as semaphor,
4605
+ ao as semaphorMetricAggregate,
4606
+ lo as semaphorMetricMeasureBindingKey,
4607
+ to as useClearInvalidSemaphorInputValue,
4609
4608
  Tr as useSemaphorDevtools,
4610
- ro as useSemaphorInput,
4611
- to as useSemaphorInputs,
4612
- io as useSemaphorQuery
4609
+ eo as useSemaphorInput,
4610
+ ro as useSemaphorInputs,
4611
+ no as useSemaphorQuery
4613
4612
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../chunks/operators-DrTQsJXv.js"),u=require("../chunks/source-identity-Cbo2LOHQ.js");require("../chunks/analyze-result-contract-BswhsmWT.js");function p(i){var n,e,a;const t=b(i);return{version:1,kind:"metric",id:i.id,label:i.label,source:s(i),measures:t,primaryMeasure:M(i,t),dateField:i.dateField?o(i.dateField,"date"):void 0,timeGrain:i.timeGrain,dimensions:(n=i.dimensions)==null?void 0:n.map(r=>o(r,"dimension")),comparison:G(i.comparison),orderBy:i.orderBy?{field:o(i.orderBy.field),direction:i.orderBy.direction}:void 0,inputs:l(i.inputs),...(e=i.filters)!=null&&e.length?{filters:i.filters}:{},...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},limit:i.limit,...(a=i.derivedFields)!=null&&a.length?{derivedFields:i.derivedFields}:{}}}function v(i){return{...p(i),...i.timeWindow?{timeWindow:i.timeWindow}:{},...i.analysis?{analysis:i.analysis}:{}}}function F(i){return{...i.chartTitle?{chartTitle:i.chartTitle}:{},...i.chartType?{chartType:i.chartType}:{},...i.driverMode?{driverMode:i.driverMode}:{},...i.includePopulation!==void 0?{includePopulation:i.includePopulation}:{},...i.calendarContext?{calendarContext:i.calendarContext}:{}}}function M(i,t){if(!i.primaryMeasure)return t[0]||{name:"",role:"measure"};const n=o(i.primaryMeasure,"measure"),e=A(n,t),a=e.length===1?e[0]:void 0;return a?I(n,a):n}function b(i){const t=[];for(const n of i.measures.map(e=>o(e,"measure"))){if(!n.name)continue;const e=t.findIndex(a=>R(a,n));if(e===-1){t.push(n);continue}t[e]=I(t[e],n)}return t}function R(i,t){return u.semaphorFieldRefsMatch(i,t)&&d(i)===d(t)}function H(i,t){return d(t)===d(i)}function w(i,t){return t.name!==i.name||i.source&&!u.semaphorFieldRefsMatch(t,i)?!1:H(i,t)}function A(i,t){const n=t.filter(e=>w(i,e));return i.aggregate!==void 0,n}function d(i){return u.semaphorMetricAggregate(i)}function I(i,t){if(i.aggregate&&t.aggregate&&i.aggregate!==t.aggregate)throw new Error(`Measure "${i.name}" was requested with conflicting aggregate semantics: ${i.aggregate} and ${t.aggregate}.`);return{...u.preferSemaphorFieldRefMetadata(i,t),aggregate:i.aggregate||t.aggregate}}function k(i){var n,e;if("sort"in i)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!V(i))throw new Error("semaphor.records needs at least one field.");const t=B(i.fields);return{version:1,kind:"records",id:i.id,label:i.label,source:s(i),fields:t,dateField:i.dateField?o(i.dateField,"date"):void 0,timeGrain:i.timeGrain,...i.timeWindow?{timeWindow:i.timeWindow}:{},...(n=i.filters)!=null&&n.length?{filters:i.filters}:{},orderBy:i.orderBy?{field:o(i.orderBy.field),direction:i.orderBy.direction}:void 0,inputs:l(i.inputs),...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},limit:i.limit,...i.pagination?{pagination:i.pagination}:{},...i.totals?{totals:{mode:"server",measures:i.totals.measures.map(a=>o(a,"measure"))}}:{},...(e=i.derivedFields)!=null&&e.length?{derivedFields:i.derivedFields}:{}}}function B(i){return i.map(t=>{const n=o(t);if(!n.role)throw new Error(`semaphor.records field "${n.name}" needs an explicit role.`);return n})}function x(i){var t,n,e;return{version:1,kind:"inputOptions",id:i.id,label:i.label,inputId:i.inputId,source:s(i),labelField:o(i.labelField,"dimension"),valueField:o(i.valueField,"dimension"),...i.searchField?{searchField:o(i.searchField,"dimension")}:{},...(t=i.disambiguationFields)!=null&&t.length?{disambiguationFields:i.disambiguationFields.map(a=>o(a,"dimension"))}:{},...i.population?{population:i.population}:{},...i.dependencies?{dependencies:i.dependencies}:{},search:i.search,limit:i.limit,...(n=i.inputs)!=null&&n.length?{inputs:i.inputs.map(a=>f(a))}:{},...(e=i.derivedFields)!=null&&e.length?{derivedFields:i.derivedFields}:{}}}function O(i){var t;return{version:1,kind:"sql",id:i.id,label:i.label,source:i.source,sql:i.sql,...i.defaultParameters?{defaultParameters:i.defaultParameters}:{},...i.pythonCode?{pythonCode:i.pythonCode}:{},...(t=i.fields)!=null&&t.length?{fields:i.fields.map(n=>o(n))}:{},inputs:l(i.inputs),limit:i.limit,...i.pagination?{pagination:i.pagination}:{},rationale:i.rationale}}function P(i){var t,n;return{version:1,kind:"matrix",id:i.id,label:i.label,source:s(i),rows:i.rows.map(e=>g(e,"dimension")),...i.columns?{columns:i.columns.map(e=>g(e,"dimension"))}:{},values:i.values.map(z),...(t=i.filters)!=null&&t.length?{filters:i.filters}:{},inputs:l(i.inputs),...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},...i.totals?{totals:i.totals}:{},...(n=i.sort)!=null&&n.length?{sort:i.sort}:{},...i.expansion?{expansion:i.expansion}:{},...i.layout?{layout:i.layout}:{},...i.displayLimits?{displayLimits:i.displayLimits}:{}}}function g(i,t){return C(i)?{...i,field:o(i.field,t)}:{field:o(i,t)}}function z(i){return T(i)?{...i,field:o(i.field,"measure")}:{field:o(i,"measure"),aggregate:i.aggregate}}function C(i){return"field"in i}function T(i){return"field"in i}function f(i){if("toAnalyticsInput"in i){const r=i.toAnalyticsInput();return{inputId:r.inputId,kind:r.kind,...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.relationshipHint}:{}}}if("id"in i){const r=h(i);return{inputId:r.inputId,kind:r.kind,...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.relationshipHint}:{}}}const t="kind"in i?i.kind:void 0,n="operator"in i?S(i.operator,i.inputId):void 0,e="controlRole"in i?i.controlRole:"role"in i?i.role:void 0,a=q(e)?e:void 0;return{inputId:i.inputId,...t?{kind:t}:{},...a?{controlRole:a}:{},...n?{operator:n}:{},...i.field?{field:i.field}:{},...i.relationshipHint?{relationshipHint:i.relationshipHint}:{}}}function q(i){return i==="grain"||i==="measure"||i==="dimension"||i==="aggregation"||i==="sqlParam"}function W(i){const t=l(i);return t.length>0?t:void 0}function y(i){return(i||[]).map(L)}function $(i){return y(i).filter(t=>t.isActive)}function h(i){if(i.kind==="filter"){const t=S(i.operator,i.id);return{inputId:i.id,kind:i.kind,label:i.label,field:o(i.field,"dimension"),operator:t||"in",...i.relationshipHint?{relationshipHint:i.relationshipHint}:{}}}return{inputId:i.id,kind:i.kind,label:i.label,controlRole:i.role}}function E(i=[]){return i.map(t=>typeof t=="object"?t:{label:String(t),value:t})}function m(i){return i==null?!1:Array.isArray(i)?i.length>0:typeof i=="string"?i.trim().length>0:!0}function L(i){if("toAnalyticsInput"in i)return i.toAnalyticsInput();if("kind"in i&&"isActive"in i)return i;if("id"in i){const t=h(i),n=Object.prototype.hasOwnProperty.call(i,"value")?i.value:i.defaultValue;return{inputId:t.inputId,kind:t.kind,label:t.label,...t.field?{field:t.field}:{},...t.operator?{operator:t.operator}:{},...t.controlRole?{controlRole:t.controlRole}:{},...t.relationshipHint?{relationshipHint:t.relationshipHint}:{},value:n,isActive:m(n)}}return{...i,kind:"filter",isActive:m(i.value),value:i.value}}function s(i){return i.source}function V(i){var t;return!!((t=i.fields)!=null&&t.length)}function o(i,t){return{...i,role:i.role||t}}function l(i){return(i||[]).map(f)}function G(i){if(i)return i}function S(i,t){if(i===void 0)return;const n=c.normalizeSemaphorInputOperator(i);if(!n)throw new Error(`useSemaphorInput "${t}" uses unsupported filter operator "${i}".`);return n}exports.hasSemaphorInputValue=m;exports.normalizeSemaphorInputOptions=E;exports.toSemaphorActiveInputSnapshots=$;exports.toSemaphorAnalysisIntent=v;exports.toSemaphorAnalysisQueryOptions=F;exports.toSemaphorInputBinding=f;exports.toSemaphorInputBindings=W;exports.toSemaphorInputOptionsIntent=x;exports.toSemaphorInputSnapshots=y;exports.toSemaphorInputSpec=h;exports.toSemaphorMatrixIntent=P;exports.toSemaphorMetricIntent=p;exports.toSemaphorRecordsIntent=k;exports.toSemaphorSqlIntent=O;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../chunks/validators-9D4KBqKD.cjs"),v=require("../chunks/operators-DrTQsJXv.cjs");require("../chunks/analyze-result-contract-BHb7sUUW.cjs");function p(i){var n,e,a;const t=b(i);return{version:1,kind:"metric",id:i.id,label:i.label,source:s(i),measures:t,primaryMeasure:M(i,t),dateField:i.dateField?o(i.dateField,"date"):void 0,timeGrain:i.timeGrain,dimensions:(n=i.dimensions)==null?void 0:n.map(r=>o(r,"dimension")),comparison:G(i.comparison),orderBy:i.orderBy?{field:o(i.orderBy.field),direction:i.orderBy.direction}:void 0,inputs:l(i.inputs),...(e=i.filters)!=null&&e.length?{filters:i.filters}:{},...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},limit:i.limit,...(a=i.derivedFields)!=null&&a.length?{derivedFields:i.derivedFields}:{}}}function c(i){return{...p(i),...i.timeWindow?{timeWindow:i.timeWindow}:{},...i.analysis?{analysis:i.analysis}:{}}}function F(i){return{...i.chartTitle?{chartTitle:i.chartTitle}:{},...i.chartType?{chartType:i.chartType}:{},...i.driverMode?{driverMode:i.driverMode}:{},...i.includePopulation!==void 0?{includePopulation:i.includePopulation}:{},...i.calendarContext?{calendarContext:i.calendarContext}:{}}}function M(i,t){if(!i.primaryMeasure)return t[0]||{name:"",role:"measure"};const n=o(i.primaryMeasure,"measure"),e=A(n,t),a=e.length===1?e[0]:void 0;return a?I(n,a):n}function b(i){const t=[];for(const n of i.measures.map(e=>o(e,"measure"))){if(!n.name)continue;const e=t.findIndex(a=>R(a,n));if(e===-1){t.push(n);continue}t[e]=I(t[e],n)}return t}function R(i,t){return u.semaphorFieldRefsMatch(i,t)&&d(i)===d(t)}function H(i,t){return d(t)===d(i)}function w(i,t){return t.name!==i.name||i.source&&!u.semaphorFieldRefsMatch(t,i)?!1:H(i,t)}function A(i,t){const n=t.filter(e=>w(i,e));return i.aggregate!==void 0,n}function d(i){return u.semaphorMetricAggregate(i)}function I(i,t){if(i.aggregate&&t.aggregate&&i.aggregate!==t.aggregate)throw new Error(`Measure "${i.name}" was requested with conflicting aggregate semantics: ${i.aggregate} and ${t.aggregate}.`);return{...u.preferSemaphorFieldRefMetadata(i,t),aggregate:i.aggregate||t.aggregate}}function k(i){var n,e;if("sort"in i)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!V(i))throw new Error("semaphor.records needs at least one field.");const t=B(i.fields);return{version:1,kind:"records",id:i.id,label:i.label,source:s(i),fields:t,dateField:i.dateField?o(i.dateField,"date"):void 0,timeGrain:i.timeGrain,...i.timeWindow?{timeWindow:i.timeWindow}:{},...(n=i.filters)!=null&&n.length?{filters:i.filters}:{},orderBy:i.orderBy?{field:o(i.orderBy.field),direction:i.orderBy.direction}:void 0,inputs:l(i.inputs),...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},limit:i.limit,...i.pagination?{pagination:i.pagination}:{},...i.totals?{totals:{mode:"server",measures:i.totals.measures.map(a=>o(a,"measure"))}}:{},...(e=i.derivedFields)!=null&&e.length?{derivedFields:i.derivedFields}:{}}}function B(i){return i.map(t=>{const n=o(t);if(!n.role)throw new Error(`semaphor.records field "${n.name}" needs an explicit role.`);return n})}function x(i){var t,n,e;return{version:1,kind:"inputOptions",id:i.id,label:i.label,inputId:i.inputId,source:s(i),labelField:o(i.labelField,"dimension"),valueField:o(i.valueField,"dimension"),...i.searchField?{searchField:o(i.searchField,"dimension")}:{},...(t=i.disambiguationFields)!=null&&t.length?{disambiguationFields:i.disambiguationFields.map(a=>o(a,"dimension"))}:{},...i.population?{population:i.population}:{},...i.dependencies?{dependencies:i.dependencies}:{},search:i.search,limit:i.limit,...(n=i.inputs)!=null&&n.length?{inputs:i.inputs.map(a=>f(a))}:{},...(e=i.derivedFields)!=null&&e.length?{derivedFields:i.derivedFields}:{}}}function O(i){var t;return{version:1,kind:"sql",id:i.id,label:i.label,source:i.source,sql:i.sql,...i.defaultParameters?{defaultParameters:i.defaultParameters}:{},...i.pythonCode?{pythonCode:i.pythonCode}:{},...(t=i.fields)!=null&&t.length?{fields:i.fields.map(n=>o(n))}:{},inputs:l(i.inputs),limit:i.limit,...i.pagination?{pagination:i.pagination}:{},rationale:i.rationale}}function P(i){var t,n;return{version:1,kind:"matrix",id:i.id,label:i.label,source:s(i),rows:i.rows.map(e=>g(e,"dimension")),...i.columns?{columns:i.columns.map(e=>g(e,"dimension"))}:{},values:i.values.map(z),...(t=i.filters)!=null&&t.length?{filters:i.filters}:{},inputs:l(i.inputs),...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},...i.totals?{totals:i.totals}:{},...(n=i.sort)!=null&&n.length?{sort:i.sort}:{},...i.expansion?{expansion:i.expansion}:{},...i.layout?{layout:i.layout}:{},...i.displayLimits?{displayLimits:i.displayLimits}:{}}}function g(i,t){return C(i)?{...i,field:o(i.field,t)}:{field:o(i,t)}}function z(i){return T(i)?{...i,field:o(i.field,"measure")}:{field:o(i,"measure"),aggregate:i.aggregate}}function C(i){return"field"in i}function T(i){return"field"in i}function f(i){if("toAnalyticsInput"in i){const r=i.toAnalyticsInput();return{inputId:r.inputId,kind:r.kind,...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.relationshipHint}:{}}}if("id"in i){const r=h(i);return{inputId:r.inputId,kind:r.kind,...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.relationshipHint}:{}}}const t="kind"in i?i.kind:void 0,n="operator"in i?S(i.operator,i.inputId):void 0,e="controlRole"in i?i.controlRole:"role"in i?i.role:void 0,a=q(e)?e:void 0;return{inputId:i.inputId,...t?{kind:t}:{},...a?{controlRole:a}:{},...n?{operator:n}:{},...i.field?{field:i.field}:{},...i.relationshipHint?{relationshipHint:i.relationshipHint}:{}}}function q(i){return i==="grain"||i==="measure"||i==="dimension"||i==="aggregation"||i==="sqlParam"}function W(i){const t=l(i);return t.length>0?t:void 0}function y(i){return(i||[]).map(L)}function $(i){return y(i).filter(t=>t.isActive)}function h(i){if(i.kind==="filter"){const t=S(i.operator,i.id);return{inputId:i.id,kind:i.kind,label:i.label,field:o(i.field,"dimension"),operator:t||"in",...i.relationshipHint?{relationshipHint:i.relationshipHint}:{}}}return{inputId:i.id,kind:i.kind,label:i.label,controlRole:i.role}}function E(i=[]){return i.map(t=>typeof t=="object"?t:{label:String(t),value:t})}function m(i){return i==null?!1:Array.isArray(i)?i.length>0:typeof i=="string"?i.trim().length>0:!0}function L(i){if("toAnalyticsInput"in i)return i.toAnalyticsInput();if("kind"in i&&"isActive"in i)return i;if("id"in i){const t=h(i),n=Object.prototype.hasOwnProperty.call(i,"value")?i.value:i.defaultValue;return{inputId:t.inputId,kind:t.kind,label:t.label,...t.field?{field:t.field}:{},...t.operator?{operator:t.operator}:{},...t.controlRole?{controlRole:t.controlRole}:{},...t.relationshipHint?{relationshipHint:t.relationshipHint}:{},value:n,isActive:m(n)}}return{...i,kind:"filter",isActive:m(i.value),value:i.value}}function s(i){return i.source}function V(i){var t;return!!((t=i.fields)!=null&&t.length)}function o(i,t){return{...i,role:i.role||t}}function l(i){return(i||[]).map(f)}function G(i){if(i)return i}function S(i,t){if(i===void 0)return;const n=v.normalizeSemaphorInputOperator(i);if(!n)throw new Error(`useSemaphorInput "${t}" uses unsupported filter operator "${i}".`);return n}exports.hasSemaphorInputValue=m;exports.normalizeSemaphorInputOptions=E;exports.toSemaphorActiveInputSnapshots=$;exports.toSemaphorAnalysisIntent=c;exports.toSemaphorAnalysisQueryOptions=F;exports.toSemaphorInputBinding=f;exports.toSemaphorInputBindings=W;exports.toSemaphorInputOptionsIntent=x;exports.toSemaphorInputSnapshots=y;exports.toSemaphorInputSpec=h;exports.toSemaphorMatrixIntent=P;exports.toSemaphorMetricIntent=p;exports.toSemaphorRecordsIntent=k;exports.toSemaphorSqlIntent=O;
@@ -1,6 +1,6 @@
1
- import { n as I } from "../chunks/operators-C8TxpM4C.js";
2
- import { s as m, p as F, a as c } from "../chunks/source-identity-5OPV4gvg.js";
3
- import "../chunks/analyze-result-contract-CfOBEwaC.js";
1
+ import { s as m, p as I, c } from "../chunks/validators-wZ2WlNHc.js";
2
+ import { n as F } from "../chunks/operators-C8TxpM4C.js";
3
+ import "../chunks/analyze-result-contract-DUv3QnMl.js";
4
4
  function p(i) {
5
5
  var n, r, a;
6
6
  const t = M(i);
@@ -94,7 +94,7 @@ function h(i, t) {
94
94
  `Measure "${i.name}" was requested with conflicting aggregate semantics: ${i.aggregate} and ${t.aggregate}.`
95
95
  );
96
96
  return {
97
- ...F(i, t),
97
+ ...I(i, t),
98
98
  aggregate: i.aggregate || t.aggregate
99
99
  };
100
100
  }
@@ -365,7 +365,7 @@ function T(i) {
365
365
  function v(i, t) {
366
366
  if (i === void 0)
367
367
  return;
368
- const n = I(i);
368
+ const n = F(i);
369
369
  if (!n)
370
370
  throw new Error(
371
371
  `useSemaphorInput "${t}" uses unsupported filter operator "${i}".`
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("../chunks/validators-B2vUAqTf.js");require("../chunks/analyze-result-contract-BswhsmWT.js");const v=require("../chunks/source-identity-Cbo2LOHQ.js"),W=require("../report-runtime-context/index.cjs"),y=require("../data-app-sdk-adapters/index.cjs"),R=require("../chunks/catalog-field-grounding-Bnx-3tE0.js");function J({intent:e,field:r,catalogField:o,relativePath:t}){const i=L({intent:e,field:r,relativePath:t});if(!i||i.allowedRelatedRoles.length===0)return!1;const a=f(r,i.selectedField),s=_(o),n=p(a);return M(s,i.allowedRelatedRoles)?n===s:!1}function U(e){return e.kind==="records"?Y(e):e.kind==="metric"?Z(e):ee(e)}function _(e){const r=R.normalizeAnalyticsCatalogName(e.role);if(r==="measure")return"measure";if(r==="id")return"id";const o=R.normalizeAnalyticsCatalogDataType(e.dataType);if(r==="date"||o==="date"||o==="datetime")return"date";if(r==="dimension")return"dimension"}function M(e,r){return!!(e&&r.includes(e))}function f(e,r){const o=p(e);if(o)return e.role===o?e:{...e,role:o};const t=r?p(r):void 0;return t?{...e,role:t}:e}function u(e,r){return e.find(o=>D(o,r))}function S(e){return[...e.rows.map(r=>r.field),...(e.columns||[]).map(r=>r.field)]}function L({intent:e,field:r,relativePath:o}){if(e.kind==="records")return V(e,r,o);if(e.kind==="metric")return G(e,r,o);if(e.kind==="matrix")return X(e,r,o)}function V(e,r,o){if(o.startsWith("spec.fields."))return{allowedRelatedRoles:["dimension","date","id"]};if(o==="spec.dateField"&&!e.timeWindow)return{allowedRelatedRoles:["date"]};if(o==="spec.orderBy.field"){const t=u(B(e),r);return{selectedField:t,allowedRelatedRoles:t?x(t):[]}}}function G(e,r,o){if(o.startsWith("spec.dimensions."))return{allowedRelatedRoles:["dimension"]};if(o==="spec.orderBy.field"){const t=u(e.dimensions||[],r);return{selectedField:t,allowedRelatedRoles:t?["dimension"]:[]}}}function X(e,r,o){if(te(o))return{allowedRelatedRoles:["dimension","date"]};if(ie(o)){const t=u(S(e),r);return{selectedField:t,allowedRelatedRoles:q(t)}}}function Y(e){var t,i;const r=B(e),o=(t=e.orderBy)!=null&&t.field?u(r,e.orderBy.field):void 0;return w([...r.map(a=>l(a,x(a))),...(i=e.orderBy)!=null&&i.field?[l(f(e.orderBy.field,o),o?x(o):[],{unsupportedRelatedRoleMessage:"Joined records projections support related sort fields only when the same related field is included in spec.fields.",recommendedNextStep:"Add the related sort field to spec.fields, or keep orderBy fields on the base source."})]:[]])}function Z(e){var o,t;const r=(o=e.orderBy)!=null&&o.field?u(e.dimensions||[],e.orderBy.field):void 0;return w([...e.measures.map(i=>l(i,[])),...e.primaryMeasure?[l(e.primaryMeasure,[])]:[],...(e.dimensions||[]).map(i=>l(i,["dimension"])),...e.dateField?[l({...e.dateField,role:"date"},[])]:[],...(t=e.orderBy)!=null&&t.field?[l(f(e.orderBy.field,r),r?["dimension"]:[],{unsupportedRelatedRoleMessage:"Joined metric projections support related orderBy fields only when the same related field is declared in spec.dimensions.",recommendedNextStep:"Add the related field as a metric dimension when it should participate in the grouped result, or keep orderBy fields on the base source."})]:[]])}function ee(e){const r=[...e.rows,...e.columns||[]];return w([...r.map(o=>l(o.field,q(o.field))),...r.flatMap(o=>{var a;if(((a=o.sortBy)==null?void 0:a.by.kind)!=="field")return[];const t=o.sortBy.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related axis sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep axis sort fields on the base source."})]}),...e.values.map(o=>l(o.field,[],{unsupportedRelatedRoleMessage:"Joined matrix projections support related row/column dimensions or dates only. Related value fields are not supported in this phase.",recommendedNextStep:"Keep matrix values on the base source, or use governed SQL for unsupported aggregate-safe joined values."})),...(e.sort||[]).flatMap(o=>{if(o.by.kind!=="field")return[];const t=o.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related top-level sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep matrix sort fields on the base source."})]})])}function x(e){const r=e?p(e):void 0;return r==="dimension"?["dimension"]:r==="date"?["date"]:r==="id"?["id"]:["dimension","date","id"]}function q(e){const r=e?p(e):void 0;return r==="date"?["date"]:r==="dimension"?["dimension"]:[]}function l(e,r,o={}){return{field:f(e),allowedRelatedRoles:r,...o}}function w(e){const r=[];return e.forEach(o=>{r.some(t=>re(t,o))||r.push(o)}),r}function B(e){const r=[...e.fields];return e.dateField&&!r.some(o=>T(o,e.dateField))&&r.push({...e.dateField,role:"date"}),r}function re(e,r){return D(e.field,r.field)&&e.allowedRelatedRoles.join("|")===r.allowedRelatedRoles.join("|")&&(e.unsupportedRelatedRoleMessage||"")===(r.unsupportedRelatedRoleMessage||"")&&(e.recommendedNextStep||"")===(r.recommendedNextStep||"")}function T(e,r){return v.semaphorFieldRefsMatch(e,r)}function D(e,r){return T(e,r)&&oe(p(e),p(r))}function oe(e,r){return!!(e&&(!r||e===r))}function p(e){return _(e)}function te(e){const r=e.split(".");return r.length===4&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&$(r[2])&&r[3]==="field"}function ie(e){const r=e.split(".");return r.length===6&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&$(r[2])&&r[3]==="sortBy"&&r[4]==="by"&&r[5]==="field"||r.length===5&&r[0]==="spec"&&r[1]==="sort"&&$(r[2])&&r[3]==="by"&&r[4]==="field"}function $(e){return e===void 0||e.trim()===""?!1:Number.isInteger(Number(e))&&Number(e)>=0}function ae({intent:e,field:r,relativePath:o,baseCatalog:t,fieldCatalogs:i}){const a=g(r,e.source),s=v.semaphorSourcesReferToSameDataset(a,e.source);if(!s&&!ne(e.source,a))return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a related Semaphor source outside the query's semantic domain.`,pathSuffix:".source",source:a};const n=s?t:I(i,a);if(!n)return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a Semaphor source that is not present in the visible field catalog.`,pathSuffix:".source",source:a};const d=F(n,r,e.source);return d?!s&&!se({intent:e,field:r,catalogField:d,relativePath:o})?{ok:!1,code:"unsupported_joined_projection",message:`Field "${r.name}" references a related Semaphor source, but this query kind does not support joined projections for that field yet.`,pathSuffix:".source",source:a}:{ok:!0,source:a,catalogField:d,usesBaseSource:s}:{ok:!1,code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,source:a}}function se({intent:e,field:r,catalogField:o,relativePath:t}){return J({intent:e,field:r,catalogField:o,relativePath:t})}function ne(e,r){return e.kind==="semantic"&&r.kind==="semantic"&&e.domainId===r.domainId}function I(e,r){return e.find(o=>b(o,r))}function F(e,r,o){const t=g(r,o);if(b(e,t))return e.fields.find(i=>de(i,r)&&b(e,g(i,e.source)))}function C(e){return R.normalizeAnalyticsCatalogName(e)}function g(e,r){return e.source||r}function b(e,r){return[e.source,...e.sourceAliases||[]].some(o=>v.semaphorSourcesReferToSameDataset(o,r))}function de(e,r){return!!(e.name&&r.name&&e.name===r.name)}function z(e,r={}){const o=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return c(o,"Data App analysis options must be an object.");const t=e,i={};if(t.chartTitle!==void 0){if(typeof t.chartTitle!="string")return c(`${o}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=t.chartTitle}if(t.chartType!==void 0){if(typeof t.chartType!="string")return c(`${o}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=t.chartType}if(t.driverMode!==void 0){if(!ue(t.driverMode))return c(`${o}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=t.driverMode}if(t.includePopulation!==void 0){if(typeof t.includePopulation!="boolean")return c(`${o}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=t.includePopulation}if(t.calendarContext!==void 0){const a=fe(t.calendarContext,{pathPrefix:`${o}.calendarContext`,validateTimezone:r.validateTimezone});if(!a.ok)return a;i.calendarContext=a.calendarContext}return{ok:!0,analysisOptions:i}}function le(e){const r=e.queries.map((i,a)=>ce(i,a,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),o=r.flatMap(i=>i.diagnostics),t=r.map(i=>i.executionResult);return{ok:o.every(i=>i.severity!=="error"),diagnostics:o,queries:r,intents:r.flatMap(i=>i.intent?[i.intent]:[]),executionResults:t}}function ce(e,r,o){const t=`queries.${r}`;try{const i=pe(e),a=be(e,i),s=E.validateSemaphorAnalyticsIntent(i),n=[...Ie({querySpec:e,queryId:a,intent:i,pathPrefix:t}),...s.errors.map(h=>P(h,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"error",intent:i})),...s.warnings.map(h=>P(h,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"warning",intent:i})),...ye({querySpec:e,queryId:a,intent:i,pathPrefix:t,fieldCatalogs:o.fieldCatalogs,requireFieldCatalog:o.requireFieldCatalog}),...Fe({querySpec:e,queryId:a,intent:i,pathPrefix:t,validateTimezone:o.validateTimezone})],d=$e(s,n);return{queryHook:e.queryHook,queryId:a,intent:i,diagnostics:n,executionResult:j({intent:i,validation:d,diagnostics:n})}}catch(i){const a={severity:"error",code:"invalid_query_spec",message:i instanceof Error?i.message:String(i),path:t,queryHook:e.queryHook,queryId:Q(e.spec)},s=K([a]);return{queryHook:e.queryHook,queryId:a.queryId,diagnostics:[a],executionResult:j({validation:s,diagnostics:[a]})}}}function c(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function N(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ue(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function fe(e,r){if(!e||typeof e!="object"||Array.isArray(e))return c(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const o=e,t=o.tz;let i=t;if(typeof t=="string"&&r.validateTimezone&&(i=r.validateTimezone(t)),i===null)return c(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.');const a=W.parseCalendarContext({...o,tz:i});if(!a.ok){const s=a.issues[0];return c(s!=null&&s.path?`${r.pathPrefix}.${s.path}`:r.pathPrefix,`Data App analysis option "calendarContext" is invalid: ${(s==null?void 0:s.message)??"invalid value"}.`)}return{ok:!0,calendarContext:a.value}}function pe(e){return me(e.spec)}function me(e){if(!N(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return y.toSemaphorMetricIntent(e);if(e.queryKind==="analysis")return y.toSemaphorAnalysisIntent(e);if(e.queryKind==="records")return y.toSemaphorRecordsIntent(e);if(e.queryKind==="sql")return y.toSemaphorSqlIntent(e);if(e.queryKind==="matrix")return y.toSemaphorMatrixIntent(e);if(e.queryKind==="inputOptions")return y.toSemaphorInputOptionsIntent(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix.")}function ye(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=I(e.fieldCatalogs,e.intent.source);if(!r)return[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}];const o=ge({...e,catalog:r}),t={...r,fields:[...r.fields,...Re(e.intent,r,e.intent.source)]};return[...o,...he({...e,fieldCatalogs:e.fieldCatalogs}),...ve({...e,catalog:t,fieldCatalogs:e.fieldCatalogs}),...qe({...e,catalog:t,fieldCatalogs:e.fieldCatalogs})]}function he(e){var o;if(e.intent.kind!=="inputOptions"||((o=e.intent.population)==null?void 0:o.kind)!=="related_population")return[];const r=e.intent.population.baseSource;return I(e.fieldCatalogs,r)?[]:[{severity:"error",code:"invalid_source_ref",message:"Input options related population baseSource does not match a visible Semaphor source.",path:`${e.pathPrefix}.spec.population.baseSource`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:r}]}function ge(e){const r=O(e.intent);if(r.length===0)return[];const o=[],t=new Set;return r.forEach((i,a)=>{const s=`${e.pathPrefix}.spec.derivedFields.${a}`,n=C(i.name);n&&(t.has(n)&&o.push({severity:"error",code:"duplicate_derived_field",message:`Derived field "${i.name}" is declared more than once.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}),t.add(n),e.catalog.fields.some(d=>C(d.name)===n)&&o.push({severity:"error",code:"derived_field_name_collision",message:`Derived field "${i.name}" conflicts with a field already visible on the selected Semaphor source.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source})),Object.entries(i.inputs||{}).forEach(([d,h])=>{const m=xe(h);if(!m)return;const k=g(m,e.intent.source);if(!v.semaphorSourcesReferToSameDataset(k,e.intent.source)){o.push({severity:"error",code:"unsupported_derived_field_source",message:`Derived field "${i.name}" input "${d}" references a different Semaphor source. App-local derived fields must use fields from the query source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:k,field:m});return}F(e.catalog,m,e.intent.source)||o.push({severity:"error",code:"missing_field",message:`Derived field "${i.name}" input "${d}" references field "${m.name}", which is not visible on the selected Semaphor source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:k,field:m})})}),o}function ve(e){return ke(e.intent).flatMap(({field:r,path:o})=>{const t=ae({intent:e.intent,field:r,relativePath:o,baseCatalog:e.catalog,fieldCatalogs:e.fieldCatalogs});return t.ok?[]:[{severity:"error",code:t.code,message:t.message,path:`${e.pathPrefix}.${o}${t.pathSuffix||""}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:t.source,field:r}]})}function qe(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((o,t)=>{if(!o.field)return[];const i=g(o.field,e.intent.source);if(!v.semaphorSourcesReferToSameDataset(i,e.intent.source)){if(Se(e.intent,i)){const a=I(e.fieldCatalogs,i);return a?F(a,o.field,i)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]:[{severity:"error",code:"invalid_source_ref",message:`Input "${o.inputId}" references a Semaphor source that is not present in the visible field catalog.`,path:`${e.pathPrefix}.spec.inputs.${t}.field.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${o.inputId}" filters a different Semaphor source than the query, and no relationship-aware semantic validation path is available for this query kind.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return F(e.catalog,o.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]})}function Se(e,r){return e.source.kind==="semantic"&&r.kind==="semantic"&&r.domainId===e.source.domainId}function Fe(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=z(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(o=>({severity:"error",code:o.code,message:o.message,path:o.path,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}))}function Ie(e){return e.querySpec.spec.queryKind!=="sql"?[]:N(e.querySpec.spec)?Object.prototype.hasOwnProperty.call(e.querySpec.spec,"parameters")?[{severity:"error",code:"deprecated_sql_parameters",message:"semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",path:`${e.pathPrefix}.spec.parameters`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id}]:[]:[]}function ke(e){return e.kind==="metric"?[...e.measures.map((r,o)=>({field:r,path:`spec.measures.${o}`})),...e.primaryMeasure?[{field:e.primaryMeasure,path:"spec.primaryMeasure"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,o)=>({field:r,path:`spec.dimensions.${o}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="records"?[...e.fields.map((r,o)=>({field:r,path:`spec.fields.${o}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="inputOptions"?[{field:e.labelField,path:"spec.labelField"},{field:e.valueField,path:"spec.valueField"},...e.searchField?[{field:e.searchField,path:"spec.searchField"}]:[],...(e.disambiguationFields||[]).map((r,o)=>({field:r,path:`spec.disambiguationFields.${o}`}))]:e.kind==="matrix"?[...e.rows.map((r,o)=>({field:r.field,path:`spec.rows.${o}.field`})),...e.rows.flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.rows.${o}.sortBy.by.field`}]:[]}),...(e.columns||[]).map((r,o)=>({field:r.field,path:`spec.columns.${o}.field`})),...(e.columns||[]).flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.columns.${o}.sortBy.by.field`}]:[]}),...e.values.map((r,o)=>({field:r.field,path:`spec.values.${o}.field`})),...(e.sort||[]).flatMap((r,o)=>r.by.kind==="field"?[{field:r.by.field,path:`spec.sort.${o}.by.field`}]:[]),...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:[]}function O(e){return!("derivedFields"in e)||!Array.isArray(e.derivedFields)?[]:e.derivedFields}function Re(e,r,o){return O(e).map(t=>({name:t.name,label:t.label,role:t.resultRole,dataType:t.dataType,source:r.source||o,...t.defaultAggregate?{aggregate:t.defaultAggregate}:{}}))}function xe(e){if(!(!e||typeof e!="object"))return e.field}function P(e,r){return{severity:r.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${r.pathPrefix}.spec.${e.path}`:r.pathPrefix,queryHook:r.queryHook,queryId:r.queryId,intentId:r.intent.id,source:r.intent.source}}function $e(e,r){const o=K(r);return{ok:o.ok&&e.ok,errors:H([...e.errors,...o.errors]),warnings:H([...e.warnings,...o.warnings]),repairHints:[...e.repairHints,...o.repairHints]}}function K(e){const r=e.filter(t=>t.severity==="error").map(A),o=e.filter(t=>t.severity==="warning").map(A);return{ok:r.length===0,errors:r,warnings:o,repairHints:r.map(t=>{var i,a;return{code:t.code,message:t.message,fieldRole:t.fieldRole,invalidField:(i=t.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((a=t.repairHint)==null?void 0:a.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function A(e){var r;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(r=e.field)==null?void 0:r.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,recommendedNextStep:e.code==="unsupported_input_filter_composition"?"Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries.":"Update the query spec to use a visible Semaphor source and field ref."}}}function H(e){const r=new Set;return e.filter(o=>{const t=`${o.code}:${o.path||""}:${o.message}`;return r.has(t)?!1:(r.add(t),!0)})}function j(e){var o,t;const r=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(o=e.intent)==null?void 0:o.id,status:r.length?"failed":"answered",resultShape:(t=e.intent)==null?void 0:t.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:r.length?[]:["query_spec_validation"],missingObligations:r.length?["query_spec_validation"]:[],warnings:e.validation.warnings},missingFields:r.filter(i=>i.code==="missing_field").flatMap(i=>{var a;return(a=i.field)!=null&&a.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function be(e,r){return r.id||Q(e.spec)}function Q(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.fieldWithSelectedProjectionRole=f;exports.findMatchingRelatedProjectionField=u;exports.isAllowedRelatedProjectionRole=M;exports.matrixAxisFieldsForPolicy=S;exports.normalizeSemaphorAnalysisQueryOptions=z;exports.normalizeSemaphorFieldRole=_;exports.relatedProjectionFieldCandidatesForIntent=U;exports.validateSemaphorDataAppQuerySpecs=le;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../chunks/validators-9D4KBqKD.cjs");require("../chunks/analyze-result-contract-BHb7sUUW.cjs");const E=require("../chunks/report-runtime-context-C8LZFsqV.cjs"),y=require("../data-app-sdk-adapters/index.cjs"),R=require("../chunks/catalog-field-grounding-Bnx-3tE0.cjs");function W({intent:e,field:r,catalogField:o,relativePath:t}){const i=U({intent:e,field:r,relativePath:t});if(!i||i.allowedRelatedRoles.length===0)return!1;const a=f(r,i.selectedField),s=_(o),n=p(a);return M(s,i.allowedRelatedRoles)?n===s:!1}function J(e){return e.kind==="records"?X(e):e.kind==="metric"?Y(e):Z(e)}function _(e){const r=R.normalizeAnalyticsCatalogName(e.role);if(r==="measure")return"measure";if(r==="id")return"id";const o=R.normalizeAnalyticsCatalogDataType(e.dataType);if(r==="date"||o==="date"||o==="datetime")return"date";if(r==="dimension")return"dimension"}function M(e,r){return!!(e&&r.includes(e))}function f(e,r){const o=p(e);if(o)return e.role===o?e:{...e,role:o};const t=r?p(r):void 0;return t?{...e,role:t}:e}function u(e,r){return e.find(o=>D(o,r))}function S(e){return[...e.rows.map(r=>r.field),...(e.columns||[]).map(r=>r.field)]}function U({intent:e,field:r,relativePath:o}){if(e.kind==="records")return L(e,r,o);if(e.kind==="metric")return V(e,r,o);if(e.kind==="matrix")return G(e,r,o)}function L(e,r,o){if(o.startsWith("spec.fields."))return{allowedRelatedRoles:["dimension","date","id"]};if(o==="spec.dateField"&&!e.timeWindow)return{allowedRelatedRoles:["date"]};if(o==="spec.orderBy.field"){const t=u(B(e),r);return{selectedField:t,allowedRelatedRoles:t?x(t):[]}}}function V(e,r,o){if(o.startsWith("spec.dimensions."))return{allowedRelatedRoles:["dimension"]};if(o==="spec.orderBy.field"){const t=u(e.dimensions||[],r);return{selectedField:t,allowedRelatedRoles:t?["dimension"]:[]}}}function G(e,r,o){if(oe(o))return{allowedRelatedRoles:["dimension","date"]};if(te(o)){const t=u(S(e),r);return{selectedField:t,allowedRelatedRoles:q(t)}}}function X(e){var t,i;const r=B(e),o=(t=e.orderBy)!=null&&t.field?u(r,e.orderBy.field):void 0;return w([...r.map(a=>l(a,x(a))),...(i=e.orderBy)!=null&&i.field?[l(f(e.orderBy.field,o),o?x(o):[],{unsupportedRelatedRoleMessage:"Joined records projections support related sort fields only when the same related field is included in spec.fields.",recommendedNextStep:"Add the related sort field to spec.fields, or keep orderBy fields on the base source."})]:[]])}function Y(e){var o,t;const r=(o=e.orderBy)!=null&&o.field?u(e.dimensions||[],e.orderBy.field):void 0;return w([...e.measures.map(i=>l(i,[])),...e.primaryMeasure?[l(e.primaryMeasure,[])]:[],...(e.dimensions||[]).map(i=>l(i,["dimension"])),...e.dateField?[l({...e.dateField,role:"date"},[])]:[],...(t=e.orderBy)!=null&&t.field?[l(f(e.orderBy.field,r),r?["dimension"]:[],{unsupportedRelatedRoleMessage:"Joined metric projections support related orderBy fields only when the same related field is declared in spec.dimensions.",recommendedNextStep:"Add the related field as a metric dimension when it should participate in the grouped result, or keep orderBy fields on the base source."})]:[]])}function Z(e){const r=[...e.rows,...e.columns||[]];return w([...r.map(o=>l(o.field,q(o.field))),...r.flatMap(o=>{var a;if(((a=o.sortBy)==null?void 0:a.by.kind)!=="field")return[];const t=o.sortBy.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related axis sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep axis sort fields on the base source."})]}),...e.values.map(o=>l(o.field,[],{unsupportedRelatedRoleMessage:"Joined matrix projections support related row/column dimensions or dates only. Related value fields are not supported in this phase.",recommendedNextStep:"Keep matrix values on the base source, or use governed SQL for unsupported aggregate-safe joined values."})),...(e.sort||[]).flatMap(o=>{if(o.by.kind!=="field")return[];const t=o.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related top-level sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep matrix sort fields on the base source."})]})])}function x(e){const r=e?p(e):void 0;return r==="dimension"?["dimension"]:r==="date"?["date"]:r==="id"?["id"]:["dimension","date","id"]}function q(e){const r=e?p(e):void 0;return r==="date"?["date"]:r==="dimension"?["dimension"]:[]}function l(e,r,o={}){return{field:f(e),allowedRelatedRoles:r,...o}}function w(e){const r=[];return e.forEach(o=>{r.some(t=>ee(t,o))||r.push(o)}),r}function B(e){const r=[...e.fields];return e.dateField&&!r.some(o=>T(o,e.dateField))&&r.push({...e.dateField,role:"date"}),r}function ee(e,r){return D(e.field,r.field)&&e.allowedRelatedRoles.join("|")===r.allowedRelatedRoles.join("|")&&(e.unsupportedRelatedRoleMessage||"")===(r.unsupportedRelatedRoleMessage||"")&&(e.recommendedNextStep||"")===(r.recommendedNextStep||"")}function T(e,r){return h.semaphorFieldRefsMatch(e,r)}function D(e,r){return T(e,r)&&re(p(e),p(r))}function re(e,r){return!!(e&&(!r||e===r))}function p(e){return _(e)}function oe(e){const r=e.split(".");return r.length===4&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&$(r[2])&&r[3]==="field"}function te(e){const r=e.split(".");return r.length===6&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&$(r[2])&&r[3]==="sortBy"&&r[4]==="by"&&r[5]==="field"||r.length===5&&r[0]==="spec"&&r[1]==="sort"&&$(r[2])&&r[3]==="by"&&r[4]==="field"}function $(e){return e===void 0||e.trim()===""?!1:Number.isInteger(Number(e))&&Number(e)>=0}function ie({intent:e,field:r,relativePath:o,baseCatalog:t,fieldCatalogs:i}){const a=v(r,e.source),s=h.semaphorSourcesReferToSameDataset(a,e.source);if(!s&&!se(e.source,a))return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a related Semaphor source outside the query's semantic domain.`,pathSuffix:".source",source:a};const n=s?t:I(i,a);if(!n)return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a Semaphor source that is not present in the visible field catalog.`,pathSuffix:".source",source:a};const d=F(n,r,e.source);return d?!s&&!ae({intent:e,field:r,catalogField:d,relativePath:o})?{ok:!1,code:"unsupported_joined_projection",message:`Field "${r.name}" references a related Semaphor source, but this query kind does not support joined projections for that field yet.`,pathSuffix:".source",source:a}:{ok:!0,source:a,catalogField:d,usesBaseSource:s}:{ok:!1,code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,source:a}}function ae({intent:e,field:r,catalogField:o,relativePath:t}){return W({intent:e,field:r,catalogField:o,relativePath:t})}function se(e,r){return e.kind==="semantic"&&r.kind==="semantic"&&e.domainId===r.domainId}function I(e,r){return e.find(o=>b(o,r))}function F(e,r,o){const t=v(r,o);if(b(e,t))return e.fields.find(i=>ne(i,r)&&b(e,v(i,e.source)))}function C(e){return R.normalizeAnalyticsCatalogName(e)}function v(e,r){return e.source||r}function b(e,r){return[e.source,...e.sourceAliases||[]].some(o=>h.semaphorSourcesReferToSameDataset(o,r))}function ne(e,r){return!!(e.name&&r.name&&e.name===r.name)}function z(e,r={}){const o=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return c(o,"Data App analysis options must be an object.");const t=e,i={};if(t.chartTitle!==void 0){if(typeof t.chartTitle!="string")return c(`${o}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=t.chartTitle}if(t.chartType!==void 0){if(typeof t.chartType!="string")return c(`${o}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=t.chartType}if(t.driverMode!==void 0){if(!ce(t.driverMode))return c(`${o}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=t.driverMode}if(t.includePopulation!==void 0){if(typeof t.includePopulation!="boolean")return c(`${o}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=t.includePopulation}if(t.calendarContext!==void 0){const a=ue(t.calendarContext,{pathPrefix:`${o}.calendarContext`,validateTimezone:r.validateTimezone});if(!a.ok)return a;i.calendarContext=a.calendarContext}return{ok:!0,analysisOptions:i}}function de(e){const r=e.queries.map((i,a)=>le(i,a,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),o=r.flatMap(i=>i.diagnostics),t=r.map(i=>i.executionResult);return{ok:o.every(i=>i.severity!=="error"),diagnostics:o,queries:r,intents:r.flatMap(i=>i.intent?[i.intent]:[]),executionResults:t}}function le(e,r,o){const t=`queries.${r}`;try{const i=fe(e),a=$e(e,i),s=h.validateSemaphorAnalyticsIntent(i),n=[...Fe({querySpec:e,queryId:a,intent:i,pathPrefix:t}),...s.errors.map(g=>P(g,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"error",intent:i})),...s.warnings.map(g=>P(g,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"warning",intent:i})),...me({querySpec:e,queryId:a,intent:i,pathPrefix:t,fieldCatalogs:o.fieldCatalogs,requireFieldCatalog:o.requireFieldCatalog}),...Se({querySpec:e,queryId:a,intent:i,pathPrefix:t,validateTimezone:o.validateTimezone})],d=xe(s,n);return{queryHook:e.queryHook,queryId:a,intent:i,diagnostics:n,executionResult:j({intent:i,validation:d,diagnostics:n})}}catch(i){const a={severity:"error",code:"invalid_query_spec",message:i instanceof Error?i.message:String(i),path:t,queryHook:e.queryHook,queryId:Q(e.spec)},s=K([a]);return{queryHook:e.queryHook,queryId:a.queryId,diagnostics:[a],executionResult:j({validation:s,diagnostics:[a]})}}}function c(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function N(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ce(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function ue(e,r){if(!e||typeof e!="object"||Array.isArray(e))return c(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const o=e,t=o.tz;let i=t;if(typeof t=="string"&&r.validateTimezone&&(i=r.validateTimezone(t)),i===null)return c(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.');const a=E.parseCalendarContext({...o,tz:i});if(!a.ok){const s=a.issues[0];return c(s!=null&&s.path?`${r.pathPrefix}.${s.path}`:r.pathPrefix,`Data App analysis option "calendarContext" is invalid: ${(s==null?void 0:s.message)??"invalid value"}.`)}return{ok:!0,calendarContext:a.value}}function fe(e){return pe(e.spec)}function pe(e){if(!N(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return y.toSemaphorMetricIntent(e);if(e.queryKind==="analysis")return y.toSemaphorAnalysisIntent(e);if(e.queryKind==="records")return y.toSemaphorRecordsIntent(e);if(e.queryKind==="sql")return y.toSemaphorSqlIntent(e);if(e.queryKind==="matrix")return y.toSemaphorMatrixIntent(e);if(e.queryKind==="inputOptions")return y.toSemaphorInputOptionsIntent(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix.")}function me(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=I(e.fieldCatalogs,e.intent.source);if(!r)return[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}];const o=he({...e,catalog:r}),t={...r,fields:[...r.fields,...ke(e.intent,r,e.intent.source)]};return[...o,...ye({...e,fieldCatalogs:e.fieldCatalogs}),...ge({...e,catalog:t,fieldCatalogs:e.fieldCatalogs}),...ve({...e,catalog:t,fieldCatalogs:e.fieldCatalogs})]}function ye(e){var o;if(e.intent.kind!=="inputOptions"||((o=e.intent.population)==null?void 0:o.kind)!=="related_population")return[];const r=e.intent.population.baseSource;return I(e.fieldCatalogs,r)?[]:[{severity:"error",code:"invalid_source_ref",message:"Input options related population baseSource does not match a visible Semaphor source.",path:`${e.pathPrefix}.spec.population.baseSource`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:r}]}function he(e){const r=O(e.intent);if(r.length===0)return[];const o=[],t=new Set;return r.forEach((i,a)=>{const s=`${e.pathPrefix}.spec.derivedFields.${a}`,n=C(i.name);n&&(t.has(n)&&o.push({severity:"error",code:"duplicate_derived_field",message:`Derived field "${i.name}" is declared more than once.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}),t.add(n),e.catalog.fields.some(d=>C(d.name)===n)&&o.push({severity:"error",code:"derived_field_name_collision",message:`Derived field "${i.name}" conflicts with a field already visible on the selected Semaphor source.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source})),Object.entries(i.inputs||{}).forEach(([d,g])=>{const m=Re(g);if(!m)return;const k=v(m,e.intent.source);if(!h.semaphorSourcesReferToSameDataset(k,e.intent.source)){o.push({severity:"error",code:"unsupported_derived_field_source",message:`Derived field "${i.name}" input "${d}" references a different Semaphor source. App-local derived fields must use fields from the query source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:k,field:m});return}F(e.catalog,m,e.intent.source)||o.push({severity:"error",code:"missing_field",message:`Derived field "${i.name}" input "${d}" references field "${m.name}", which is not visible on the selected Semaphor source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:k,field:m})})}),o}function ge(e){return Ie(e.intent).flatMap(({field:r,path:o})=>{const t=ie({intent:e.intent,field:r,relativePath:o,baseCatalog:e.catalog,fieldCatalogs:e.fieldCatalogs});return t.ok?[]:[{severity:"error",code:t.code,message:t.message,path:`${e.pathPrefix}.${o}${t.pathSuffix||""}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:t.source,field:r}]})}function ve(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((o,t)=>{if(!o.field)return[];const i=v(o.field,e.intent.source);if(!h.semaphorSourcesReferToSameDataset(i,e.intent.source)){if(qe(e.intent,i)){const a=I(e.fieldCatalogs,i);return a?F(a,o.field,i)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]:[{severity:"error",code:"invalid_source_ref",message:`Input "${o.inputId}" references a Semaphor source that is not present in the visible field catalog.`,path:`${e.pathPrefix}.spec.inputs.${t}.field.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${o.inputId}" filters a different Semaphor source than the query, and no relationship-aware semantic validation path is available for this query kind.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return F(e.catalog,o.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]})}function qe(e,r){return e.source.kind==="semantic"&&r.kind==="semantic"&&r.domainId===e.source.domainId}function Se(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=z(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(o=>({severity:"error",code:o.code,message:o.message,path:o.path,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}))}function Fe(e){return e.querySpec.spec.queryKind!=="sql"?[]:N(e.querySpec.spec)?Object.prototype.hasOwnProperty.call(e.querySpec.spec,"parameters")?[{severity:"error",code:"deprecated_sql_parameters",message:"semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",path:`${e.pathPrefix}.spec.parameters`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id}]:[]:[]}function Ie(e){return e.kind==="metric"?[...e.measures.map((r,o)=>({field:r,path:`spec.measures.${o}`})),...e.primaryMeasure?[{field:e.primaryMeasure,path:"spec.primaryMeasure"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,o)=>({field:r,path:`spec.dimensions.${o}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="records"?[...e.fields.map((r,o)=>({field:r,path:`spec.fields.${o}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="inputOptions"?[{field:e.labelField,path:"spec.labelField"},{field:e.valueField,path:"spec.valueField"},...e.searchField?[{field:e.searchField,path:"spec.searchField"}]:[],...(e.disambiguationFields||[]).map((r,o)=>({field:r,path:`spec.disambiguationFields.${o}`}))]:e.kind==="matrix"?[...e.rows.map((r,o)=>({field:r.field,path:`spec.rows.${o}.field`})),...e.rows.flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.rows.${o}.sortBy.by.field`}]:[]}),...(e.columns||[]).map((r,o)=>({field:r.field,path:`spec.columns.${o}.field`})),...(e.columns||[]).flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.columns.${o}.sortBy.by.field`}]:[]}),...e.values.map((r,o)=>({field:r.field,path:`spec.values.${o}.field`})),...(e.sort||[]).flatMap((r,o)=>r.by.kind==="field"?[{field:r.by.field,path:`spec.sort.${o}.by.field`}]:[]),...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:[]}function O(e){return!("derivedFields"in e)||!Array.isArray(e.derivedFields)?[]:e.derivedFields}function ke(e,r,o){return O(e).map(t=>({name:t.name,label:t.label,role:t.resultRole,dataType:t.dataType,source:r.source||o,...t.defaultAggregate?{aggregate:t.defaultAggregate}:{}}))}function Re(e){if(!(!e||typeof e!="object"))return e.field}function P(e,r){return{severity:r.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${r.pathPrefix}.spec.${e.path}`:r.pathPrefix,queryHook:r.queryHook,queryId:r.queryId,intentId:r.intent.id,source:r.intent.source}}function xe(e,r){const o=K(r);return{ok:o.ok&&e.ok,errors:H([...e.errors,...o.errors]),warnings:H([...e.warnings,...o.warnings]),repairHints:[...e.repairHints,...o.repairHints]}}function K(e){const r=e.filter(t=>t.severity==="error").map(A),o=e.filter(t=>t.severity==="warning").map(A);return{ok:r.length===0,errors:r,warnings:o,repairHints:r.map(t=>{var i,a;return{code:t.code,message:t.message,fieldRole:t.fieldRole,invalidField:(i=t.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((a=t.repairHint)==null?void 0:a.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function A(e){var r;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(r=e.field)==null?void 0:r.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,recommendedNextStep:e.code==="unsupported_input_filter_composition"?"Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries.":"Update the query spec to use a visible Semaphor source and field ref."}}}function H(e){const r=new Set;return e.filter(o=>{const t=`${o.code}:${o.path||""}:${o.message}`;return r.has(t)?!1:(r.add(t),!0)})}function j(e){var o,t;const r=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(o=e.intent)==null?void 0:o.id,status:r.length?"failed":"answered",resultShape:(t=e.intent)==null?void 0:t.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:r.length?[]:["query_spec_validation"],missingObligations:r.length?["query_spec_validation"]:[],warnings:e.validation.warnings},missingFields:r.filter(i=>i.code==="missing_field").flatMap(i=>{var a;return(a=i.field)!=null&&a.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function $e(e,r){return r.id||Q(e.spec)}function Q(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.fieldWithSelectedProjectionRole=f;exports.findMatchingRelatedProjectionField=u;exports.isAllowedRelatedProjectionRole=M;exports.matrixAxisFieldsForPolicy=S;exports.normalizeSemaphorAnalysisQueryOptions=z;exports.normalizeSemaphorFieldRole=_;exports.relatedProjectionFieldCandidatesForIntent=J;exports.validateSemaphorDataAppQuerySpecs=de;
@@ -1,7 +1,6 @@
1
- import { v as O } from "../chunks/validators-Bce_J7Vd.js";
2
- import "../chunks/analyze-result-contract-CfOBEwaC.js";
3
- import { s as K, b as q } from "../chunks/source-identity-5OPV4gvg.js";
4
- import { parseCalendarContext as Q } from "../report-runtime-context/index.js";
1
+ import { s as O, h as q, j as K } from "../chunks/validators-wZ2WlNHc.js";
2
+ import "../chunks/analyze-result-contract-DUv3QnMl.js";
3
+ import { p as Q } from "../chunks/report-runtime-context-Qzn11HQe.js";
5
4
  import { toSemaphorMetricIntent as E, toSemaphorAnalysisIntent as J, toSemaphorRecordsIntent as U, toSemaphorSqlIntent as W, toSemaphorMatrixIntent as L, toSemaphorInputOptionsIntent as V } from "../data-app-sdk-adapters/index.js";
6
5
  import { a as H, n as G } from "../chunks/catalog-field-grounding-AOGwWu0K.js";
7
6
  function X({
@@ -26,7 +25,7 @@ function X({
26
25
  i.allowedRelatedRoles
27
26
  ) ? n === s : !1;
28
27
  }
29
- function ze(e) {
28
+ function De(e) {
30
29
  return e.kind === "records" ? te(e) : e.kind === "metric" ? ie(e) : ae(e);
31
30
  }
32
31
  function A(e) {
@@ -264,7 +263,7 @@ function se(e, r) {
264
263
  return B(e.field, r.field) && e.allowedRelatedRoles.join("|") === r.allowedRelatedRoles.join("|") && (e.unsupportedRelatedRoleMessage || "") === (r.unsupportedRelatedRoleMessage || "") && (e.recommendedNextStep || "") === (r.recommendedNextStep || "");
265
264
  }
266
265
  function j(e, r) {
267
- return K(e, r);
266
+ return O(e, r);
268
267
  }
269
268
  function B(e, r) {
270
269
  return j(e, r) && ne(
@@ -440,7 +439,7 @@ function me(e, r = {}) {
440
439
  }
441
440
  return { ok: !0, analysisOptions: i };
442
441
  }
443
- function Ne(e) {
442
+ function ze(e) {
444
443
  const r = e.queries.map(
445
444
  (i, a) => ye(i, a, {
446
445
  fieldCatalogs: e.fieldCatalogs || [],
@@ -461,7 +460,7 @@ function Ne(e) {
461
460
  function ye(e, r, o) {
462
461
  const t = `queries.${r}`;
463
462
  try {
464
- const i = ve(e), a = He(e, i), s = O(i), n = [
463
+ const i = ve(e), a = He(e, i), s = K(i), n = [
465
464
  ...be({
466
465
  querySpec: e,
467
466
  queryId: a,
@@ -1068,6 +1067,6 @@ export {
1068
1067
  k as matrixAxisFieldsForPolicy,
1069
1068
  me as normalizeSemaphorAnalysisQueryOptions,
1070
1069
  A as normalizeSemaphorFieldRole,
1071
- ze as relatedProjectionFieldCandidatesForIntent,
1072
- Ne as validateSemaphorDataAppQuerySpecs
1070
+ De as relatedProjectionFieldCandidatesForIntent,
1071
+ ze as validateSemaphorDataAppQuerySpecs
1073
1072
  };
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/numeric-presentation-Dlb-Dk4c.js"),i=require("../chunks/csv-utils-Co0WxHke.js");function P(r,e,t,o){const n=r instanceof Date?r.toISOString():String(r),l=(o==null?void 0:o.browserTimezone)||t,s=(o==null?void 0:o.isSqlCard)??!1;if(e!=null&&e.useRelativeTime)return i.formatRelativeTime(n,(e==null?void 0:e.sourceTimezone)||"auto");const u=e!=null&&e.useCustomFormat&&(e!=null&&e.customFormat)?e.customFormat:(e==null?void 0:e.format)||"MM/dd/yyyy";return i.formatDate(n,u,e!=null&&e.timezone&&(e==null?void 0:e.timezone)!=="auto"?e.timezone:s?l:t,(e==null?void 0:e.sourceTimezone)||"auto")}function y(r,e,t){if(r==null)return"";if(!t.useFormattedValues||!e)return String(r);switch(e.type){case"number":return typeof r=="number"?a.formatNumberWithColumnSettings(r,e.numberFormat,t.locale):String(r);case"date":return P(r,e.dateFormat,t.timezone,{browserTimezone:t.browserTimezone,isSqlCard:t.isSqlCard});case"progress":return typeof r=="number"?`${r}%`:String(r);case"badge":case"link":case"text":case"none":default:return String(r)}}function T(r,e){return e.visibleColumns.map(t=>{const o=r[t],n=e.columnSettings[t];return y(o,n,{useFormattedValues:e.useFormattedValues,timezone:e.timezone,locale:e.locale})})}function w(r,e){const t=[];e.includeHeaders&&t.push(i.arrayToCSVRow(e.visibleColumns,e.delimiter));for(const o of r){const n=T(o,e);t.push(n.map(l=>i.escapeCSVValue(l,e.delimiter)).join(e.delimiter))}return t}function z(r,e,t=`
2
- `){return w(r,e).join(t)}function j(r,e,t){return r==null?"":t.useFormattedValues?typeof r=="number"&&(e==null?void 0:e.type)==="number"?a.formatNumberWithColumnSettings(r,e.numberFormat,t.locale):typeof r=="number"?r.toLocaleString(t.locale):String(r):String(r)}function C(r,e,t){var n,l;const o=[];if(r.isSubtotal&&!r.isGrandTotal){const s=e.groupByColumns.findIndex(u=>u.alias===r.subtotalLevel);e.groupByColumns.forEach((u,m)=>{var c,f,p,h;if(m===s){const v=(f=(c=e.rowAggregates)==null?void 0:c.find($=>$.groupLevel===r.subtotalLevel))==null?void 0:f.label,R=(h=(p=r.subtotalContext)==null?void 0:p.groupByValues)==null?void 0:h[u.alias];o.push(v??`Subtotal (${R??"Total"})`)}else m<s?o.push(String(r[u.alias]??"")):o.push("")})}else if(r.isGrandTotal){const s=(l=(n=e.rowAggregates)==null?void 0:n.find(u=>u.groupLevel==="ALL"))==null?void 0:l.label;o.push(s||"Grand Total"),e.groupByColumns.slice(1).forEach(()=>o.push(""))}else e.groupByColumns.forEach(s=>{o.push(String(r[s.alias]??""))});return e.pivotSchema.filter(s=>s.isMetricColumn).forEach(s=>{const u=r[s.alias],m=t.columnSettings[s.alias];o.push(j(u,m,t))}),o}function V(r){const e=r.groupByColumns.map(o=>o.label||o.name),t=r.pivotSchema.filter(o=>o.isMetricColumn).map(o=>o.displayLabel||o.metricLabel||o.metricName||o.alias);return[...e,...t]}function A(r,e,t){const o=[];if(t.includeHeaders){const n=V(e);o.push(i.arrayToCSVRow(n,t.delimiter))}for(const n of r){const l=C(n,e,t);o.push(l.map(s=>i.escapeCSVValue(s,t.delimiter)).join(t.delimiter))}return o}function E(r,e,t){for(const o of r){if(o.level<t){e[o.level].push(o.name);for(let n=1;n<o.colspan;n++)e[o.level].push("")}o.children?E(o.children,e,t):o.columnKey&&e[t].push(o.name)}}function d(r){const e=r.pivotByColumns.length,t=r.groupByColumns.length,o=Array.from({length:e+1},()=>[]);for(let n=0;n<e;n++)o[n].push(...Array(t).fill(""));if(o[e].push(...r.groupByColumns.map(n=>n.label||n.name)),E(r.columnHeadersTree,o,e),r.showRowTotals){for(let n=0;n<e;n++)o[n].push("");o[e].push("Total")}return o}function B(r,e,t){if(r==null)return"";if(!t.useFormattedValues)return String(r);const o=t.columnSettings[e];return typeof r=="number"&&(o==null?void 0:o.type)==="number"?a.formatNumberWithColumnSettings(r,o.numberFormat,t.locale):typeof r=="number"?r.toLocaleString(t.locale):String(r)}function N(r,e,t){const o=[];r.fieldValues.forEach((l,s)=>{r.isSubtotal&&s===0?o.push(`${l} Total`):r.isSubtotal?o.push(""):o.push(String(l??""))});let n=0;return e.columnHeaders.forEach(l=>{var m;const s=(m=r.cells[l])==null?void 0:m.value,u=B(s,l,t);o.push(u),e.showRowTotals&&typeof s=="number"&&(n+=s)}),e.showRowTotals&&o.push(n.toLocaleString(t.locale)),o}function I(r,e,t){const o=[];if(t.includeHeaders){const n=d(e);for(const l of n)o.push(i.arrayToCSVRow(l,t.delimiter))}for(const n of r){const l=N(n,e,t);o.push(l.map(s=>i.escapeCSVValue(s,t.delimiter)).join(t.delimiter))}return o}function b(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}function S(r,e,t){const o=new Set(e),n=Object.keys(r).find(l=>!o.has(l));if(n)throw new Error(`${t} contains unknown property "${n}"`)}function x(r,e="tableTotalsRequest"){if(!b(r))throw new Error(`${e} must be an object`);if(S(r,["source","columns"],e),r.source!=="documentFlatTable")throw new Error(`${e}.source must be documentFlatTable`);if(!Array.isArray(r.columns)||r.columns.length===0)throw new Error(`${e}.columns must be a non-empty array`);const t=new Set;let o=0;const n=r.columns.map((l,s)=>{const u=`${e}.columns.${s}`;if(!b(l))throw new Error(`${u} must be an object`);S(l,["fieldId","role","behavior","label"],u);const m=typeof l.fieldId=="string"?l.fieldId.trim():"";if(!m)throw new Error(`${u}.fieldId must be a non-empty string`);if(t.has(m))throw new Error(`${e}.columns duplicates fieldId "${m}"`);if(t.add(m),l.role!=="detail"&&l.role!=="groupby"&&l.role!=="metric")throw new Error(`${u}.role is invalid`);const c=l.role;if(l.behavior!=="sum"&&l.behavior!=="avg"&&l.behavior!=="count"&&l.behavior!=="label")throw new Error(`${u}.behavior is invalid`);const f=l.behavior;if(f==="label"){if(o+=1,c==="metric")throw new Error(`${u}.behavior label requires a non-metric role`)}else if(c!=="metric")throw new Error(`${u}.${f} requires metric role`);if(l.label!==void 0&&typeof l.label!="string")throw new Error(`${u}.label must be a string`);return{fieldId:m,role:c,behavior:f,...l.label!==void 0?{label:l.label}:{}}});if(o>1)throw new Error(`${e}.columns may contain at most one label`);return{source:"documentFlatTable",columns:n}}function L(r,e="tableTotalsByColumnId"){if(!b(r))throw new Error(`${e} must be an object`);const t={};for(const[o,n]of Object.entries(r)){if(!o.trim())throw new Error(`${e} contains an empty column id`);if(n!==null&&typeof n!="string"&&(typeof n!="number"||!Number.isFinite(n)))throw new Error(`${e}.${o} must be a string, finite number, or null`);t[o]=n}if(Object.keys(t).length===0)throw new Error(`${e} must not be empty`);return t}function D(r){if(typeof r=="number")return Number.isFinite(r)?r:null;if(!r.trim())return null;const e=Number(r);return Number.isFinite(e)?e:null}function q(r){const e=new Map(r.resolvedNumericFormats.flatMap(o=>o.target.kind==="column"?[[o.target.columnKey,o.format]]:[])),t=r.visibleColumns.map(o=>{const l=Object.prototype.hasOwnProperty.call(r.totalsByColumnId,o)?r.totalsByColumnId[o]:o===r.labelColumnKey?"Total":null;if(l===null)return"";if(!r.useFormattedValues)return String(l);const s=e.get(o),u=s?D(l):null;return s&&u!==null?a.formatNumericCanonical(u,s):String(l)});return`${i.arrayToCSVRow(t,r.delimiter)}
3
- `}exports.formatCurrency=a.formatCurrency;exports.formatNumber=a.formatNumber;exports.formatNumberCustom=a.formatNumberCustom;exports.formatNumberWithColumnSettings=a.formatNumberWithColumnSettings;exports.formatNumericCanonical=a.formatNumericCanonical;exports.formatPercent=a.formatPercent;exports.formatScientific=a.formatScientific;exports.parseNumericCanonicalFormat=a.parseNumericCanonicalFormat;exports.parseNumericPresentationExecutionSnapshot=a.parseNumericPresentationExecutionSnapshot;exports.parseNumericPresentationSnapshotEntries=a.parseNumericPresentationSnapshotEntries;exports.parseResolvedNumericCanonicalFormat=a.parseResolvedNumericCanonicalFormat;exports.resolveCurrencyFractionDigits=a.resolveCurrencyFractionDigits;exports.resolveNumericPresentation=a.resolveNumericPresentation;exports.validateCardExportNumericPresentationSnapshot=a.validateCardExportNumericPresentationSnapshot;exports.arrayToCSV=i.arrayToCSV;exports.arrayToCSVRow=i.arrayToCSVRow;exports.escapeCSVValue=i.escapeCSVValue;exports.formatDate=i.formatDate;exports.formatDuration=i.formatDuration;exports.formatMetricComparison=i.formatMetricComparison;exports.formatRelativeTime=i.formatRelativeTime;exports.getTimezoneAbbreviation=i.getTimezoneAbbreviation;exports.getTimezoneName=i.getTimezoneName;exports.objectsToCSV=i.objectsToCSV;exports.parseWithSourceTimezone=i.parseWithSourceTimezone;exports.resolveTimezone=i.resolveTimezone;exports.buildFlatTableExportTotalsFooter=q;exports.formatAggregateRow=C;exports.formatAggregateTableForCSV=A;exports.formatCellValue=y;exports.formatPivotDataRow=N;exports.formatPivotTableForCSV=I;exports.formatRowForExport=T;exports.formatTableForCSV=w;exports.generateAggregateHeaders=V;exports.generatePivotHeaders=d;exports.generateTableCSV=z;exports.parseFlatTableExportTotalsByColumnId=L;exports.parseFlatTableExportTotalsRequest=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../chunks/format-types-CSv0V7mm.cjs"),i=require("../chunks/presentation-execution-BTV-Q43g.cjs"),s=require("../chunks/pivot-result-lifecycle-DPc0ANwk.cjs"),m=require("../chunks/temporal-bucket-pMnV-4Nj.cjs"),P=require("../chunks/validators-9D4KBqKD.cjs"),g=require("../chunks/metric-comparison-CUAJ8n4y.cjs"),f=require("../chunks/pivot-result-identity-CDLRT-YG.cjs");function d(r,e,o,t){const n=r instanceof Date?r.toISOString():String(r),l=(t==null?void 0:t.browserTimezone)||o,a=(t==null?void 0:t.isSqlCard)??!1;if(e!=null&&e.useRelativeTime)return s.formatRelativeTime(n,(e==null?void 0:e.sourceTimezone)||"auto");const u=e!=null&&e.useCustomFormat&&(e!=null&&e.customFormat)?e.customFormat:(e==null?void 0:e.format)||"MM/dd/yyyy";return s.formatDate(n,u,e!=null&&e.timezone&&(e==null?void 0:e.timezone)!=="auto"?e.timezone:a?l:o,(e==null?void 0:e.sourceTimezone)||"auto")}function C(r,e,o){if(r==null)return"";if(!o.useFormattedValues||!e)return String(r);switch(e.type){case"number":return typeof r=="number"?i.formatNumberWithColumnSettings(r,e.numberFormat,o.locale):String(r);case"date":return d(r,e.dateFormat,o.timezone,{browserTimezone:o.browserTimezone,isSqlCard:o.isSqlCard});case"progress":return typeof r=="number"?`${r}%`:String(r);case"badge":case"link":case"text":case"none":default:return String(r)}}function E(r,e){return e.visibleColumns.map(o=>{const t=r[o],n=e.columnSettings[o];return C(t,n,{useFormattedValues:e.useFormattedValues,timezone:e.timezone,locale:e.locale})})}function v(r,e){const o=[];e.includeHeaders&&o.push(s.arrayToCSVRow(e.visibleColumns,e.delimiter));for(const t of r){const n=E(t,e);o.push(n.map(l=>s.escapeCSVValue(l,e.delimiter)).join(e.delimiter))}return o}function A(r,e,o=`
2
+ `){return v(r,e).join(o)}function w(r,e,o){for(const t of r){if(t.level<o){e[t.level].push(t.name);for(let n=1;n<t.colspan;n++)e[t.level].push("")}t.children?w(t.children,e,o):t.columnKey&&e[o].push(t.name)}}function R(r){const e=r.pivotByColumns.length,o=r.groupByColumns.length,t=Array.from({length:e+1},()=>[]);for(let n=0;n<e;n++)t[n].push(...Array(o).fill(""));if(t[e].push(...r.groupByColumns.map(n=>n.label||n.name)),w(r.columnHeadersTree,t,e),r.showRowTotals){for(let n=0;n<e;n++)t[n].push("");t[e].push("Total")}return t}function N(r,e,o){if(r==null)return"";if(!o.useFormattedValues)return String(r);const t=o.columnSettings[e];return typeof r=="number"&&(t==null?void 0:t.type)==="number"?i.formatNumberWithColumnSettings(r,t.numberFormat,o.locale):typeof r=="number"?r.toLocaleString(o.locale):String(r)}function S(r,e,o){const t=[];r.fieldValues.forEach((l,a)=>{r.isSubtotal&&a===0?t.push(`${l} Total`):r.isSubtotal?t.push(""):t.push(String(l??""))});let n=0;return e.columnHeaders.forEach(l=>{var c;const a=(c=r.cells[l])==null?void 0:c.value,u=N(a,l,o);t.push(u),e.showRowTotals&&typeof a=="number"&&(n+=a)}),e.showRowTotals&&t.push(n.toLocaleString(o.locale)),t}function V(r,e,o){const t=[];if(o.includeHeaders){const n=R(e);for(const l of n)t.push(s.arrayToCSVRow(l,o.delimiter))}for(const n of r){const l=S(n,e,o);t.push(l.map(a=>s.escapeCSVValue(a,o.delimiter)).join(o.delimiter))}return t}function T(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===null||e===Object.prototype}function y(r,e,o){const t=new Set(e),n=Object.keys(r).find(l=>!t.has(l));if(n)throw new Error(`${o} contains unknown property "${n}"`)}function B(r,e="tableTotalsRequest"){if(!T(r))throw new Error(`${e} must be an object`);if(y(r,["source","columns"],e),r.source!=="documentFlatTable")throw new Error(`${e}.source must be documentFlatTable`);if(!Array.isArray(r.columns)||r.columns.length===0)throw new Error(`${e}.columns must be a non-empty array`);const o=new Set;let t=0;const n=r.columns.map((l,a)=>{const u=`${e}.columns.${a}`;if(!T(l))throw new Error(`${u} must be an object`);y(l,["fieldId","role","behavior","label"],u);const c=typeof l.fieldId=="string"?l.fieldId.trim():"";if(!c)throw new Error(`${u}.fieldId must be a non-empty string`);if(o.has(c))throw new Error(`${e}.columns duplicates fieldId "${c}"`);if(o.add(c),l.role!=="detail"&&l.role!=="groupby"&&l.role!=="metric")throw new Error(`${u}.role is invalid`);const p=l.role;if(l.behavior!=="sum"&&l.behavior!=="avg"&&l.behavior!=="count"&&l.behavior!=="label")throw new Error(`${u}.behavior is invalid`);const b=l.behavior;if(b==="label"){if(t+=1,p==="metric")throw new Error(`${u}.behavior label requires a non-metric role`)}else if(p!=="metric")throw new Error(`${u}.${b} requires metric role`);if(l.label!==void 0&&typeof l.label!="string")throw new Error(`${u}.label must be a string`);return{fieldId:c,role:p,behavior:b,...l.label!==void 0?{label:l.label}:{}}});if(t>1)throw new Error(`${e}.columns may contain at most one label`);return{source:"documentFlatTable",columns:n}}function k(r,e="tableTotalsByColumnId"){if(!T(r))throw new Error(`${e} must be an object`);const o={};for(const[t,n]of Object.entries(r)){if(!t.trim())throw new Error(`${e} contains an empty column id`);if(n!==null&&typeof n!="string"&&(typeof n!="number"||!Number.isFinite(n)))throw new Error(`${e}.${t} must be a string, finite number, or null`);o[t]=n}if(Object.keys(o).length===0)throw new Error(`${e} must not be empty`);return o}function M(r){if(typeof r=="number")return Number.isFinite(r)?r:null;if(!r.trim())return null;const e=Number(r);return Number.isFinite(e)?e:null}function $(r){const e=r.visibleColumns.map(o=>{const n=Object.prototype.hasOwnProperty.call(r.totalsByColumnId,o)?r.totalsByColumnId[o]:o===r.labelColumnKey?"Total":null;if(n===null)return"";if(!r.useFormattedValues)return String(n);const l=i.findResolvedNumericFormat({snapshot:r.snapshot,scope:r.scope,target:{kind:"column",columnKey:o}}),a=l?M(n):null;return l&&a!==null?i.formatNumericCanonical(a,l):String(n)});return`${s.arrayToCSVRow(e,r.delimiter)}
3
+ `}exports.isNumericCanonicalFormat=h.isNumericCanonicalFormat;exports.findResolvedNumericFormat=i.findResolvedNumericFormat;exports.findResolvedTemporalBucketFormat=i.findResolvedTemporalBucketFormat;exports.formatCurrency=i.formatCurrency;exports.formatNumber=i.formatNumber;exports.formatNumberCustom=i.formatNumberCustom;exports.formatNumberWithColumnSettings=i.formatNumberWithColumnSettings;exports.formatNumericCanonical=i.formatNumericCanonical;exports.formatPercent=i.formatPercent;exports.formatScientific=i.formatScientific;exports.parseNumericCanonicalFormat=i.parseNumericCanonicalFormat;exports.parsePresentationExecutionSnapshot=i.parsePresentationExecutionSnapshot;exports.parsePresentationScope=i.parsePresentationScope;exports.parseResolvedNumericCanonicalFormat=i.parseResolvedNumericCanonicalFormat;exports.parseResolvedPresentationEntries=i.parseResolvedPresentationEntries;exports.resolveCurrencyFractionDigits=i.resolveCurrencyFractionDigits;exports.resolveNumericPresentation=i.resolveNumericPresentation;exports.validateCardExportNumericPresentationSnapshot=i.validateCardExportNumericPresentationSnapshot;exports.validateCardExportPresentationSnapshot=i.validateCardExportPresentationSnapshot;exports.AGGREGATE_TOTAL_MEMBER_MARKER=s.AGGREGATE_TOTAL_MEMBER_MARKER;exports.PivotHeaderPresentationError=s.PivotHeaderPresentationError;exports.PivotResultLifecycleError=s.PivotResultLifecycleError;exports.arrayToCSV=s.arrayToCSV;exports.arrayToCSVRow=s.arrayToCSVRow;exports.createCanonicalPivotResultTransport=s.createCanonicalPivotResultTransport;exports.derivePivotResultContractExpectations=s.derivePivotResultContractExpectations;exports.escapeCSVValue=s.escapeCSVValue;exports.formatAggregateGrandTotalLabel=s.formatAggregateGrandTotalLabel;exports.formatAggregateGroupCell=s.formatAggregateGroupCell;exports.formatAggregateGroupRow=s.formatAggregateGroupRow;exports.formatAggregateSubtotalLabel=s.formatAggregateSubtotalLabel;exports.formatDate=s.formatDate;exports.formatDuration=s.formatDuration;exports.formatMetricComparison=s.formatMetricComparison;exports.formatRelativeTime=s.formatRelativeTime;exports.getTimezoneAbbreviation=s.getTimezoneAbbreviation;exports.getTimezoneName=s.getTimezoneName;exports.isAggregateTotalMemberMarker=s.isAggregateTotalMemberMarker;exports.objectsToCSV=s.objectsToCSV;exports.parseCanonicalPivotResultTransport=s.parseCanonicalPivotResultTransport;exports.parseWithSourceTimezone=s.parseWithSourceTimezone;exports.presentAggregateGroupRow=s.presentAggregateGroupRow;exports.presentPivotHeader=s.presentPivotHeader;exports.resolveAggregateTablePresentationContext=s.resolveAggregateTablePresentationContext;exports.resolveTimezone=s.resolveTimezone;exports.TEMPORAL_BUCKET_PATTERN_TOKENS=m.TEMPORAL_BUCKET_PATTERN_TOKENS;exports.TemporalBucketContractError=m.TemporalBucketContractError;exports.formatTemporalBucket=m.formatTemporalBucket;exports.isTemporalBucketPreset=m.isTemporalBucketPreset;exports.parseResolvedTemporalBucketFormat=m.parseResolvedTemporalBucketFormat;exports.parseTemporalBucketValue=m.parseTemporalBucketValue;exports.resolveApplicableTemporalBucketFormat=m.resolveApplicableTemporalBucketFormat;exports.resolveTemporalBucketPresentation=m.resolveTemporalBucketPresentation;exports.tokenizeTemporalBucketPattern=m.tokenizeTemporalBucketPattern;exports.validateTemporalBucketFormatApplicability=m.validateTemporalBucketFormatApplicability;exports.SEMAPHOR_GENERATED_COUNT_METRIC_ID=P.SEMAPHOR_GENERATED_COUNT_METRIC_ID;exports.resolveMetricResultAlias=g.resolveMetricResultAlias;exports.PivotResultIdentityError=f.PivotResultIdentityError;exports.isPivotEmptyTupleAllowed=f.isPivotEmptyTupleAllowed;exports.isPivotSubtotalPrefix=f.isPivotSubtotalPrefix;exports.requirePivotHeaderMembers=f.requirePivotHeaderMembers;exports.requirePivotResultColumnIdentities=f.requirePivotResultColumnIdentities;exports.resolveQueryColumnKeyMapEntry=f.resolveQueryColumnKeyMapEntry;exports.resolveUniqueQueryColumnKeyMapEntry=f.resolveUniqueQueryColumnKeyMapEntry;exports.buildFlatTableExportTotalsFooter=$;exports.formatCellValue=C;exports.formatPivotDataRow=S;exports.formatPivotTableForCSV=V;exports.formatRowForExport=E;exports.formatTableForCSV=v;exports.generatePivotHeaders=R;exports.generateTableCSV=A;exports.parseFlatTableExportTotalsByColumnId=k;exports.parseFlatTableExportTotalsRequest=B;