react-semaphor 0.1.498 → 0.1.500

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 (120) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +22 -22
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +4 -4
  5. package/dist/briefings/index.cjs +1 -1
  6. package/dist/briefings/index.js +5 -5
  7. package/dist/chunks/{calculated-field-identity-BGIPbwBx.js → calculated-field-identity-BC2NViZZ.js} +73 -63
  8. package/dist/chunks/{calculated-field-identity-CEzmY7Bi.cjs → calculated-field-identity-CtYhhZoG.cjs} +1 -1
  9. package/dist/chunks/{constants-CKoIADZx.js → constants-CTRduy1g.js} +9 -9
  10. package/dist/chunks/{constants-CpBVuEea.cjs → constants-DNgpRMaX.cjs} +1 -1
  11. package/dist/chunks/{dashboard-briefing-launcher-BEmyxEd8.cjs → dashboard-briefing-launcher-BLJZ3Qgs.cjs} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-C8eAX-JN.js → dashboard-briefing-launcher-BXUyvRSV.js} +9 -9
  13. package/dist/chunks/{dashboard-controls-YvJe7cPL.cjs → dashboard-controls-Cd7otu4d.cjs} +1 -1
  14. package/dist/chunks/{dashboard-controls-C_v7sbq4.js → dashboard-controls-Cpwyyh9l.js} +11 -11
  15. package/dist/chunks/{dashboard-date-comparison-definition-aANgeL-E.js → dashboard-date-comparison-definition-C1vJshiP.js} +6 -6
  16. package/dist/chunks/{dashboard-date-comparison-definition-Er8D33iq.cjs → dashboard-date-comparison-definition-CWz_Yte8.cjs} +1 -1
  17. package/dist/chunks/{dashboard-json-BaT3Yy8x.js → dashboard-json-BInzxESW.js} +7 -7
  18. package/dist/chunks/{dashboard-json-CSp5bXIV.cjs → dashboard-json-DCC670oo.cjs} +1 -1
  19. package/dist/chunks/edit-dashboard-visual-CIQ2Ow3V.cjs +172 -0
  20. package/dist/chunks/{edit-dashboard-visual-GWiW0jjy.js → edit-dashboard-visual-Dfmk5Qmc.js} +6183 -6212
  21. package/dist/chunks/{editor-action-buttons-CfZITZwQ.js → editor-action-buttons-DjP4MzoJ.js} +6 -6
  22. package/dist/chunks/{editor-action-buttons-BSC0nwgV.cjs → editor-action-buttons-fiZSPjDC.cjs} +1 -1
  23. package/dist/chunks/{field-aggregations-DLWbqnBW.cjs → field-aggregations-mlkON_QA.cjs} +1 -1
  24. package/dist/chunks/{field-aggregations-CxJWY4Ny.js → field-aggregations-tLaXZ2VJ.js} +13 -13
  25. package/dist/chunks/{field-dependencies-BiyQuGxZ.cjs → field-dependencies-R7MrlW6D.cjs} +1 -1
  26. package/dist/chunks/{field-dependencies-CNOgt39w.js → field-dependencies-ZE2klbHO.js} +1 -1
  27. package/dist/chunks/{index-BJfUMDHc.js → index-BVIet238.js} +42 -42
  28. package/dist/chunks/{index-C3RHKD3d.cjs → index-Bh3SlWJS.cjs} +1 -1
  29. package/dist/chunks/{index-DhBGtRkR.cjs → index-C6KtprFE.cjs} +233 -233
  30. package/dist/chunks/{index-DjbQVfS6.js → index-CBUb9M4R.js} +26553 -26545
  31. package/dist/chunks/{matrix-analytical-definition-s10yOPft.js → matrix-analytical-definition-CIVFNNnF.js} +1 -1
  32. package/dist/chunks/{matrix-analytical-definition-DbaMwlWM.cjs → matrix-analytical-definition-wIEDXvV5.cjs} +1 -1
  33. package/dist/chunks/{matrix-card-DGpXdK_Y.js → matrix-card-BVvKHL7s.js} +2 -2
  34. package/dist/chunks/{matrix-card-BitrcBVw.cjs → matrix-card-Dh0J0_Of.cjs} +1 -1
  35. package/dist/chunks/matrix-control-sources-CjnsBREg.js +605 -0
  36. package/dist/chunks/matrix-control-sources-a67fwoOO.cjs +1 -0
  37. package/dist/chunks/{matrix-definition-AP5W3wGc.js → matrix-definition-BEXCfZAe.js} +3 -3
  38. package/dist/chunks/{matrix-definition-C33isJ3k.cjs → matrix-definition-CKVi4VVg.cjs} +1 -1
  39. package/dist/chunks/{matrix-formatter-CZYFhdZ0.js → matrix-formatter-BTPfthsa.js} +41 -41
  40. package/dist/chunks/{matrix-formatter-UCXQxvV3.cjs → matrix-formatter-CWtdnbfv.cjs} +1 -1
  41. package/dist/chunks/{matrix-member-presentation-5-M0obIa.js → matrix-member-presentation-DiDUvZts.js} +1 -1
  42. package/dist/chunks/{matrix-member-presentation-DgIq9UG9.cjs → matrix-member-presentation-e_KZoZOx.cjs} +1 -1
  43. package/dist/chunks/{matrix-operation-contract-BFumahBa.js → matrix-operation-contract-CPgckXxm.js} +144 -144
  44. package/dist/chunks/{matrix-operation-contract-C0-V685e.cjs → matrix-operation-contract-thtFuUYf.cjs} +1 -1
  45. package/dist/chunks/{metric-comparison-ClKUI7Tu.cjs → metric-comparison-CAqV6VnZ.cjs} +1 -1
  46. package/dist/chunks/{metric-comparison-Df3HmmUE.js → metric-comparison-Dgyq1I3d.js} +1 -1
  47. package/dist/chunks/{pivot-header-presentation-CGWDx1V_.cjs → pivot-header-presentation-DUXM-VOP.cjs} +1 -1
  48. package/dist/chunks/{pivot-header-presentation-CAmKYLgn.js → pivot-header-presentation-DcCO8-Ij.js} +3 -3
  49. package/dist/chunks/{pivot-result-identity-DBeK76wx.js → pivot-result-identity-Be1zm0AV.js} +1 -1
  50. package/dist/chunks/{pivot-result-identity-0grcK7bY.cjs → pivot-result-identity-DJyF4I2K.cjs} +1 -1
  51. package/dist/chunks/{pivot-result-lifecycle-DVPJg7Gg.js → pivot-result-lifecycle-DpSZOMOZ.js} +7 -7
  52. package/dist/chunks/{pivot-result-lifecycle-CC0jWMFT.cjs → pivot-result-lifecycle-E_huAPev.cjs} +1 -1
  53. package/dist/chunks/{raw-temporal-Kc3mdzH7.cjs → raw-temporal-DYoPBY6B.cjs} +1 -1
  54. package/dist/chunks/{raw-temporal-T3PEaGmJ.js → raw-temporal-DfnRBxQn.js} +2 -2
  55. package/dist/chunks/{raw-temporal-contract-Ck5vJoQ6.js → raw-temporal-contract-CNwYygW2.js} +1 -1
  56. package/dist/chunks/{raw-temporal-contract-SwtP1jSh.cjs → raw-temporal-contract-D1_n2pBj.cjs} +1 -1
  57. package/dist/chunks/{report-preferences-dialog-BcaEOgn2.cjs → report-preferences-dialog-BMs2Bt9t.cjs} +1 -1
  58. package/dist/chunks/{report-preferences-dialog-B8DdDM7q.js → report-preferences-dialog-CWK7wxW6.js} +6 -6
  59. package/dist/chunks/{report-runtime-context-D3t8vyl9.cjs → report-runtime-context-CqFbgZq9.cjs} +1 -1
  60. package/dist/chunks/{report-runtime-context-BziN1eg9.js → report-runtime-context-Dln1qvGS.js} +5 -5
  61. package/dist/chunks/{semantic-format-Ca-sdETk.cjs → semantic-format-C7Goni6h.cjs} +1 -1
  62. package/dist/chunks/{semantic-format-A3k--fpE.js → semantic-format-PKQt2EAz.js} +2 -2
  63. package/dist/chunks/{source-entity-resolution-CTUzMH2S.cjs → source-entity-resolution-BMKxwdKN.cjs} +1 -1
  64. package/dist/chunks/{source-entity-resolution-DX9C1ebK.js → source-entity-resolution-BSZ07Sl6.js} +19 -19
  65. package/dist/chunks/{switch-DV8zX7rV.js → switch-B4wVqV4L.js} +51 -50
  66. package/dist/chunks/{switch-CgycqpWv.cjs → switch-DVjKkt22.cjs} +12 -12
  67. package/dist/chunks/{temporal-bucket-contract-BBdvWsY0.cjs → temporal-bucket-contract-CSdspcYj.cjs} +1 -1
  68. package/dist/chunks/{temporal-bucket-contract-lq7Jrif0.js → temporal-bucket-contract-_WCvDnvn.js} +1 -1
  69. package/dist/chunks/{update-policy-DIw_H9RT.cjs → update-policy-BESKAspa.cjs} +1 -1
  70. package/dist/chunks/{update-policy-EgZ1nRbd.js → update-policy-BWbXhkk-.js} +2 -2
  71. package/dist/chunks/{validators-CvLOGzT3.js → validators-CHlnnHuS.js} +1102 -1043
  72. package/dist/chunks/validators-D2F_uxxP.cjs +1 -0
  73. package/dist/dashboard/index.cjs +1 -1
  74. package/dist/dashboard/index.js +1 -1
  75. package/dist/dashboard-authoring/index.cjs +3 -3
  76. package/dist/dashboard-authoring/index.js +112 -107
  77. package/dist/data-app-builder/index.cjs +1 -1
  78. package/dist/data-app-builder/index.js +2 -2
  79. package/dist/data-app-codegen/index.cjs +1 -1
  80. package/dist/data-app-codegen/index.js +2 -2
  81. package/dist/data-app-codegen-node/index.cjs +1 -1
  82. package/dist/data-app-codegen-node/index.js +3 -3
  83. package/dist/data-app-sdk/index.cjs +1 -1
  84. package/dist/data-app-sdk/index.js +4 -4
  85. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  86. package/dist/data-app-sdk-adapters/index.js +2 -2
  87. package/dist/data-app-sdk-validation/index.cjs +1 -1
  88. package/dist/data-app-sdk-validation/index.js +5 -5
  89. package/dist/format-utils/index.cjs +1 -1
  90. package/dist/format-utils/index.js +16 -16
  91. package/dist/index.cjs +1 -1
  92. package/dist/index.js +81 -78
  93. package/dist/report-runtime-context/index.cjs +1 -1
  94. package/dist/report-runtime-context/index.js +2 -2
  95. package/dist/style.css +1 -1
  96. package/dist/surfboard/index.cjs +1 -1
  97. package/dist/surfboard/index.js +2 -2
  98. package/dist/types/analytics-protocol.d.ts +15 -0
  99. package/dist/types/briefings.d.ts +16 -1
  100. package/dist/types/dashboard-assistant.d.ts +15 -0
  101. package/dist/types/dashboard-authoring.d.ts +49 -1
  102. package/dist/types/dashboard.d.ts +23 -1
  103. package/dist/types/data-app-builder.d.ts +15 -0
  104. package/dist/types/data-app-codegen-node.d.ts +15 -0
  105. package/dist/types/data-app-codegen.d.ts +15 -0
  106. package/dist/types/data-app-sdk-adapters.d.ts +15 -0
  107. package/dist/types/data-app-sdk-validation.d.ts +15 -0
  108. package/dist/types/data-app-sdk.d.ts +15 -0
  109. package/dist/types/format-utils.d.ts +15 -0
  110. package/dist/types/index.cjs +1 -1
  111. package/dist/types/index.js +30 -27
  112. package/dist/types/main.d.ts +67 -8
  113. package/dist/types/shared.d.ts +16 -1
  114. package/dist/types/surfboard.d.ts +23 -1
  115. package/dist/types/types.d.ts +67 -8
  116. package/package.json +1 -1
  117. package/dist/chunks/edit-dashboard-visual-_Wap0YGu.cjs +0 -172
  118. package/dist/chunks/matrix-control-sources-DdfST7Fo.cjs +0 -1
  119. package/dist/chunks/matrix-control-sources-Dxh6hOU9.js +0 -523
  120. package/dist/chunks/validators-mhiJSia7.cjs +0 -1
@@ -1,4 +1,4 @@
1
- import { k as f, l as b } from "./validators-CvLOGzT3.js";
1
+ import { o as f, q as b } from "./validators-CHlnnHuS.js";
2
2
  function m(t) {
3
3
  const { label: i, ...n } = t;
4
4
  return {
@@ -1 +1 @@
1
- "use strict";const u=require("./validators-mhiJSia7.cjs");function m(t){const{label:i,...n}=t;return{dataset:u.semaphorSourceIdentityKey(n),...t.kind==="physical"?{dialect:t.dialect,connectionType:t.connectionType}:{}}}function y(t){const{label:i,source:n,...e}=t;return{...e,source:n&&m(n)}}function s(t){const{label:i,format:n,description:e,tags:a,inputs:r,...l}=t;return{...l,inputs:Object.fromEntries(Object.entries(r).map(([c,f])=>[c,{...f,field:y(f.field)}]))}}function d(t){const{derivedField:i,...n}=t;return{...y(n),derivedField:i&&s(i)}}function o(t){const{label:i,format:n,description:e,semanticTemporalPresentation:a,derivedField:r,calculatedFormula:l,...c}=t;return{...c,semanticTemporalPresentation:a&&{granularity:a.granularity},derivedField:r&&s(r),calculatedFormula:l&&{...l,inputFields:l.inputFields.map(o)}}}function p(t){return{...t,conditions:t.conditions.map(({label:i,field:n,...e})=>({...e,field:o(n)})),groups:t.groups.map(p)}}function b(t){return{...t,source:m(t.source),rows:t.rows.map(i=>({...i,field:d(i.field)})),columns:t.columns.map(i=>({...i,field:d(i.field)})),measures:t.measures.map(i=>i.kind==="aggregate"?{...i,field:d(i.field)}:{...i,definition:s(i.definition)}),filters:t.filters&&p(t.filters),joinPlan:t.joinPlan&&{...t.joinPlan,joins:t.joinPlan.joins.map(i=>({...i,joinKeyGroups:i.joinKeyGroups.map(n=>({...n,keys:n.keys.map(e=>({...e,source:o(e.source),target:o(e.target)}))}))}))},sorts:[...t.sorts].sort((i,n)=>{const e=u.matrixSortKey(i),a=u.matrixSortKey(n);return e<a?-1:e>a?1:0})}}exports.getMatrixAnalyticalCalculation=s;exports.getMatrixAnalyticalDefinition=b;
1
+ "use strict";const u=require("./validators-D2F_uxxP.cjs");function m(t){const{label:i,...n}=t;return{dataset:u.semaphorSourceIdentityKey(n),...t.kind==="physical"?{dialect:t.dialect,connectionType:t.connectionType}:{}}}function y(t){const{label:i,source:n,...e}=t;return{...e,source:n&&m(n)}}function s(t){const{label:i,format:n,description:e,tags:a,inputs:r,...l}=t;return{...l,inputs:Object.fromEntries(Object.entries(r).map(([c,f])=>[c,{...f,field:y(f.field)}]))}}function d(t){const{derivedField:i,...n}=t;return{...y(n),derivedField:i&&s(i)}}function o(t){const{label:i,format:n,description:e,semanticTemporalPresentation:a,derivedField:r,calculatedFormula:l,...c}=t;return{...c,semanticTemporalPresentation:a&&{granularity:a.granularity},derivedField:r&&s(r),calculatedFormula:l&&{...l,inputFields:l.inputFields.map(o)}}}function p(t){return{...t,conditions:t.conditions.map(({label:i,field:n,...e})=>({...e,field:o(n)})),groups:t.groups.map(p)}}function b(t){return{...t,source:m(t.source),rows:t.rows.map(i=>({...i,field:d(i.field)})),columns:t.columns.map(i=>({...i,field:d(i.field)})),measures:t.measures.map(i=>i.kind==="aggregate"?{...i,field:d(i.field)}:{...i,definition:s(i.definition)}),filters:t.filters&&p(t.filters),joinPlan:t.joinPlan&&{...t.joinPlan,joins:t.joinPlan.joins.map(i=>({...i,joinKeyGroups:i.joinKeyGroups.map(n=>({...n,keys:n.keys.map(e=>({...e,source:o(e.source),target:o(e.target)}))}))}))},sorts:[...t.sorts].sort((i,n)=>{const e=u.matrixSortKey(i),a=u.matrixSortKey(n);return e<a?-1:e>a?1:0})}}exports.getMatrixAnalyticalCalculation=s;exports.getMatrixAnalyticalDefinition=b;
@@ -1,5 +1,5 @@
1
- import { n as a, o as s, q as f } from "./validators-CvLOGzT3.js";
2
- import "./matrix-operation-contract-BFumahBa.js";
1
+ import { r as a, t as s, u as f } from "./validators-CHlnnHuS.js";
2
+ import "./matrix-operation-contract-CPgckXxm.js";
3
3
  function u(i, r = {}) {
4
4
  var n, o;
5
5
  if (i.type !== "matrixTable" || !i.config || typeof i.config != "object" || !("matrix" in i.config)) return { status: "absent" };
@@ -1 +1 @@
1
- "use strict";const o=require("./validators-mhiJSia7.cjs");require("./matrix-operation-contract-C0-V685e.cjs");function s(i,r={}){var n,a;if(i.type!=="matrixTable"||!i.config||typeof i.config!="object"||!("matrix"in i.config))return{status:"absent"};if((n=i.sql)!=null&&n.trim()||(a=i.python)!=null&&a.trim())return{status:"invalid",error:new Error("A Matrix definition requires a config-only Matrix card.")};if("matrixIntent"in i.config&&i.config.matrixIntent!==void 0)return{status:"invalid",error:new Error("A Matrix card cannot contain two definitions.")};const t=(r.authoringDraft?o.matrixAuthoringConfigSchema:o.matrixConfigSchema).safeParse(i.config.matrix);return t.success?{status:"ready",config:t.data}:{status:"invalid",error:t.error}}function u(i){const r=s(i);if(r.status==="invalid")throw r.error;return r.status==="ready"?r.config:void 0}function f(i){const r=[],e=t=>{r.push(t),t.derivedField&&Object.values(t.derivedField.inputs).forEach(n=>e(n.field))};return[...i.rows,...i.columns].forEach(t=>e(t.field)),i.measures.forEach(t=>{t.kind==="aggregate"?e(t.field):Object.values(t.definition.inputs).forEach(n=>e(n.field))}),r}function c(i){return o.mergeSemaphorSourcesByIdentity([i.source,...f(i).map(r=>r.source??i.source)])}exports.inspectMatrixCardConfig=s;exports.matrixDefinitionFields=f;exports.matrixDefinitionSources=c;exports.readMatrixCardConfig=u;
1
+ "use strict";const o=require("./validators-D2F_uxxP.cjs");require("./matrix-operation-contract-thtFuUYf.cjs");function s(i,r={}){var n,a;if(i.type!=="matrixTable"||!i.config||typeof i.config!="object"||!("matrix"in i.config))return{status:"absent"};if((n=i.sql)!=null&&n.trim()||(a=i.python)!=null&&a.trim())return{status:"invalid",error:new Error("A Matrix definition requires a config-only Matrix card.")};if("matrixIntent"in i.config&&i.config.matrixIntent!==void 0)return{status:"invalid",error:new Error("A Matrix card cannot contain two definitions.")};const t=(r.authoringDraft?o.matrixAuthoringConfigSchema:o.matrixConfigSchema).safeParse(i.config.matrix);return t.success?{status:"ready",config:t.data}:{status:"invalid",error:t.error}}function u(i){const r=s(i);if(r.status==="invalid")throw r.error;return r.status==="ready"?r.config:void 0}function f(i){const r=[],e=t=>{r.push(t),t.derivedField&&Object.values(t.derivedField.inputs).forEach(n=>e(n.field))};return[...i.rows,...i.columns].forEach(t=>e(t.field)),i.measures.forEach(t=>{t.kind==="aggregate"?e(t.field):Object.values(t.definition.inputs).forEach(n=>e(n.field))}),r}function c(i){return o.mergeSemaphorSourcesByIdentity([i.source,...f(i).map(r=>r.source??i.source)])}exports.inspectMatrixCardConfig=s;exports.matrixDefinitionFields=f;exports.matrixDefinitionSources=c;exports.readMatrixCardConfig=u;
@@ -0,0 +1,605 @@
1
+ var te = Object.defineProperty;
2
+ var re = (e, t, o) => t in e ? te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var x = (e, t, o) => re(e, typeof t != "symbol" ? t + "" : t, o);
4
+ import { s as oe, d as ne, U as ie, F as ae, a_ as P, G as se, am as B, ak as ce, u as j, $ as le } from "./validators-CHlnnHuS.js";
5
+ import { C as A } from "./common-types-C6cAQgyh.js";
6
+ import "./matrix-operation-contract-CPgckXxm.js";
7
+ import { g as de, r as ge } from "./calculated-field-identity-BC2NViZZ.js";
8
+ import { g as ue } from "./field-aggregations-tLaXZ2VJ.js";
9
+ import { ZodError as fe } from "zod";
10
+ import { a as H } from "./matrix-card-BVvKHL7s.js";
11
+ import { m as Y, a as Z } from "./constants-DeLIHVAW.js";
12
+ function me(e, t) {
13
+ const r = Oe(e);
14
+ let i;
15
+ if (r.date) {
16
+ const d = Ne(r.date, 2);
17
+ i = Te(d.restDateString, d.year);
18
+ }
19
+ if (!i || isNaN(i.getTime()))
20
+ return /* @__PURE__ */ new Date(NaN);
21
+ const a = i.getTime();
22
+ let g = 0, u;
23
+ if (r.time && (g = De(r.time), isNaN(g)))
24
+ return /* @__PURE__ */ new Date(NaN);
25
+ if (r.timezone) {
26
+ if (u = he(r.timezone), isNaN(u))
27
+ return /* @__PURE__ */ new Date(NaN);
28
+ } else {
29
+ const d = new Date(a + g), N = /* @__PURE__ */ new Date(0);
30
+ return N.setFullYear(
31
+ d.getUTCFullYear(),
32
+ d.getUTCMonth(),
33
+ d.getUTCDate()
34
+ ), N.setHours(
35
+ d.getUTCHours(),
36
+ d.getUTCMinutes(),
37
+ d.getUTCSeconds(),
38
+ d.getUTCMilliseconds()
39
+ ), N;
40
+ }
41
+ return new Date(a + g + u);
42
+ }
43
+ const b = {
44
+ dateTimeDelimiter: /[T ]/,
45
+ timeZoneDelimiter: /[Z ]/i,
46
+ timezone: /([Z+-].*)$/
47
+ }, pe = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/, _e = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/, Ie = /^([+-])(\d{2})(?::?(\d{2}))?$/;
48
+ function Oe(e) {
49
+ const t = {}, o = e.split(b.dateTimeDelimiter);
50
+ let r;
51
+ if (o.length > 2)
52
+ return t;
53
+ if (/:/.test(o[0]) ? r = o[0] : (t.date = o[0], r = o[1], b.timeZoneDelimiter.test(t.date) && (t.date = e.split(b.timeZoneDelimiter)[0], r = e.substr(
54
+ t.date.length,
55
+ e.length
56
+ ))), r) {
57
+ const i = b.timezone.exec(r);
58
+ i ? (t.time = r.replace(i[1], ""), t.timezone = i[1]) : t.time = r;
59
+ }
60
+ return t;
61
+ }
62
+ function Ne(e, t) {
63
+ const o = new RegExp(
64
+ "^(?:(\\d{4}|[+-]\\d{" + (4 + t) + "})|(\\d{2}|[+-]\\d{" + (2 + t) + "})$)"
65
+ ), r = e.match(o);
66
+ if (!r) return { year: NaN, restDateString: "" };
67
+ const i = r[1] ? parseInt(r[1]) : null, a = r[2] ? parseInt(r[2]) : null;
68
+ return {
69
+ year: a === null ? i : a * 100,
70
+ restDateString: e.slice((r[1] || r[2]).length)
71
+ };
72
+ }
73
+ function Te(e, t) {
74
+ if (t === null) return /* @__PURE__ */ new Date(NaN);
75
+ const o = e.match(pe);
76
+ if (!o) return /* @__PURE__ */ new Date(NaN);
77
+ const r = !!o[4], i = y(o[1]), a = y(o[2]) - 1, g = y(o[3]), u = y(o[4]), d = y(o[5]) - 1;
78
+ if (r)
79
+ return ye(t, u, d) ? Ce(t, u, d) : /* @__PURE__ */ new Date(NaN);
80
+ {
81
+ const N = /* @__PURE__ */ new Date(0);
82
+ return !Ee(t, a, g) || !Re(t, i) ? /* @__PURE__ */ new Date(NaN) : (N.setUTCFullYear(t, a, Math.max(i, g)), N);
83
+ }
84
+ }
85
+ function y(e) {
86
+ return e ? parseInt(e) : 1;
87
+ }
88
+ function De(e) {
89
+ const t = e.match(_e);
90
+ if (!t) return NaN;
91
+ const o = L(t[1]), r = L(t[2]), i = L(t[3]);
92
+ return be(o, r, i) ? o * Y + r * Z + i * 1e3 : NaN;
93
+ }
94
+ function L(e) {
95
+ return e && parseFloat(e.replace(",", ".")) || 0;
96
+ }
97
+ function he(e) {
98
+ if (e === "Z") return 0;
99
+ const t = e.match(Ie);
100
+ if (!t) return 0;
101
+ const o = t[1] === "+" ? -1 : 1, r = parseInt(t[2]), i = t[3] && parseInt(t[3]) || 0;
102
+ return Ae(r, i) ? o * (r * Y + i * Z) : NaN;
103
+ }
104
+ function Ce(e, t, o) {
105
+ const r = /* @__PURE__ */ new Date(0);
106
+ r.setUTCFullYear(e, 0, 4);
107
+ const i = r.getUTCDay() || 7, a = (t - 1) * 7 + o + 1 - i;
108
+ return r.setUTCDate(r.getUTCDate() + a), r;
109
+ }
110
+ const we = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
111
+ function W(e) {
112
+ return e % 400 === 0 || e % 4 === 0 && e % 100 !== 0;
113
+ }
114
+ function Ee(e, t, o) {
115
+ return t >= 0 && t <= 11 && o >= 1 && o <= (we[t] || (W(e) ? 29 : 28));
116
+ }
117
+ function Re(e, t) {
118
+ return t >= 1 && t <= (W(e) ? 366 : 365);
119
+ }
120
+ function ye(e, t, o) {
121
+ return t >= 1 && t <= 53 && o >= 0 && o <= 6;
122
+ }
123
+ function be(e, t, o) {
124
+ return e === 24 ? t === 0 && o === 0 : o >= 0 && o < 60 && t >= 0 && t < 60 && e >= 0 && e < 25;
125
+ }
126
+ function Ae(e, t) {
127
+ return t >= 0 && t <= 59;
128
+ }
129
+ const et = [
130
+ "lg",
131
+ "md",
132
+ "sm",
133
+ "xs",
134
+ "xxs"
135
+ ], tt = 15;
136
+ function rt(e, t) {
137
+ return `${e}-${t}`;
138
+ }
139
+ const ot = "CONTROL_PLACEHOLDER_QUOTED", Se = "CONTROL_REFERENCE_MISSING", xe = "CONTROL_VALUE_MISSING", nt = "CONTROL_VALUE_INVALID", it = "CONTROL_CONTEXT_UNSUPPORTED", Le = "CONTROL_DEFINITION_DUPLICATE", Ve = "CONTROL_DEFINITION_INVALID", V = "CONTROL_BINDING_MAPPING_MISSING", Fe = "CONTROL_BINDING_TARGET_INVALID", k = "CONTROL_BINDING_VALUE_INVALID";
140
+ class _ extends Error {
141
+ constructor(o, r) {
142
+ super(o);
143
+ x(this, "status", 400);
144
+ x(this, "details");
145
+ Object.setPrototypeOf(this, _.prototype), this.name = "ControlResolutionError", this.details = r;
146
+ }
147
+ }
148
+ function X(e, t) {
149
+ const o = /* @__PURE__ */ new Map();
150
+ for (const r of [...e, ...t]) {
151
+ if (!r || typeof r != "object" || typeof r.id != "string" || r.id.trim().length === 0)
152
+ throw new _(
153
+ "Malformed control definition was provided for query execution.",
154
+ {
155
+ code: Ve
156
+ }
157
+ );
158
+ if (o.get(r.id))
159
+ throw new _(
160
+ `Duplicate control definition '${r.id}' was provided for query execution.`,
161
+ {
162
+ code: Le,
163
+ controlId: r.id
164
+ }
165
+ );
166
+ o.set(r.id, r);
167
+ }
168
+ return o;
169
+ }
170
+ const ve = /^-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
171
+ function Me(e) {
172
+ switch (e.source.kind) {
173
+ case "manual":
174
+ return e.source.options.map((t) => t.value);
175
+ case "field_allowlist":
176
+ return e.source.fieldIds;
177
+ case "metric_allowlist":
178
+ return e.source.metricIds;
179
+ case "dataset_values":
180
+ return null;
181
+ default:
182
+ return null;
183
+ }
184
+ }
185
+ function T(e) {
186
+ return `${e.label || e.id} (${e.id})`;
187
+ }
188
+ function Ue(e) {
189
+ return e.type === "field_selector" || e.type === "metric_selector" || e.type === "aggregation_selector" || e.type === "grain_selector";
190
+ }
191
+ function q(e, t) {
192
+ const o = Me(e);
193
+ if (!(!o || o.length === 0) && !o.includes(t))
194
+ throw new Error(
195
+ `Control ${T(e)} received unsupported value '${t}'.`
196
+ );
197
+ }
198
+ function $e(e, t) {
199
+ switch (e.type) {
200
+ case "enum":
201
+ case "field_selector":
202
+ case "metric_selector":
203
+ case "aggregation_selector":
204
+ case "grain_selector": {
205
+ if (typeof t != "string" || t.trim().length === 0)
206
+ throw new Error(
207
+ `Control ${T(e)} requires a non-empty string value.`
208
+ );
209
+ return Ue(e) && t === A || q(e, t), t;
210
+ }
211
+ case "multi_enum": {
212
+ if (!Array.isArray(t))
213
+ throw new Error(
214
+ `Control ${T(e)} requires a non-empty array value.`
215
+ );
216
+ if (t.length === 0) {
217
+ if (!e.requiredAtExecution)
218
+ return;
219
+ throw new Error(
220
+ `Control ${T(e)} requires a non-empty array value.`
221
+ );
222
+ }
223
+ for (const o of t) {
224
+ if (typeof o != "string" || o.trim().length === 0)
225
+ throw new Error(
226
+ `Control ${T(e)} requires string array values.`
227
+ );
228
+ q(e, o);
229
+ }
230
+ return t;
231
+ }
232
+ case "text": {
233
+ if (typeof t != "string")
234
+ throw new Error(
235
+ `Control ${T(e)} requires a string value.`
236
+ );
237
+ return t;
238
+ }
239
+ case "number": {
240
+ if (typeof t == "number" && Number.isFinite(t))
241
+ return t;
242
+ if (typeof t == "string" && ve.test(t.trim()))
243
+ return Number(t);
244
+ throw new Error(
245
+ `Control ${T(e)} requires a numeric value.`
246
+ );
247
+ }
248
+ case "boolean": {
249
+ if (typeof t != "boolean")
250
+ throw new Error(
251
+ `Control ${T(e)} requires a boolean value.`
252
+ );
253
+ return t;
254
+ }
255
+ case "date": {
256
+ if (t instanceof Date && !Number.isNaN(t.getTime()))
257
+ return t;
258
+ if (typeof t == "string" && t.trim().length > 0) {
259
+ const o = t.trim(), r = me(o);
260
+ if (!Number.isNaN(r.getTime()))
261
+ return o;
262
+ }
263
+ throw new Error(
264
+ `Control ${T(e)} requires a date-compatible value.`
265
+ );
266
+ }
267
+ default:
268
+ return t;
269
+ }
270
+ }
271
+ function Q(e) {
272
+ var i;
273
+ const t = e.definitions.get(e.binding.controlId);
274
+ if (!t)
275
+ throw new _(
276
+ `Binding references unknown control '${e.binding.controlId}'.`,
277
+ {
278
+ code: Se,
279
+ controlId: e.binding.controlId
280
+ }
281
+ );
282
+ if (!Object.prototype.hasOwnProperty.call(
283
+ e.controlValues || {},
284
+ e.binding.controlId
285
+ )) {
286
+ if (!t.requiredAtExecution)
287
+ return;
288
+ throw new _(
289
+ `Control '${e.binding.controlId}' must resolve to a concrete value before query execution.`,
290
+ {
291
+ code: xe,
292
+ controlId: e.binding.controlId
293
+ }
294
+ );
295
+ }
296
+ let r;
297
+ try {
298
+ r = $e(
299
+ t,
300
+ (i = e.controlValues) == null ? void 0 : i[e.binding.controlId]
301
+ );
302
+ } catch (a) {
303
+ const g = a instanceof Error ? a.message : String(a);
304
+ throw new _(g, {
305
+ code: k,
306
+ controlId: e.binding.controlId
307
+ });
308
+ }
309
+ if (typeof r == "string" && r.trim().length > 0)
310
+ return r;
311
+ if (typeof r == "number" || typeof r == "boolean")
312
+ return String(r);
313
+ if (r instanceof Date && !Number.isNaN(r.getTime()))
314
+ return r.toISOString();
315
+ throw new _(
316
+ `Binding control '${e.binding.controlId}' must resolve to a single scalar value.`,
317
+ {
318
+ code: k,
319
+ controlId: e.binding.controlId
320
+ }
321
+ );
322
+ }
323
+ function z(e) {
324
+ const t = e.binding.mapping[e.selectedValue];
325
+ if (typeof t == "string" && t.trim().length > 0)
326
+ return t;
327
+ throw new _(
328
+ `Binding for control '${e.binding.controlId}' does not map value '${e.selectedValue}'.`,
329
+ {
330
+ code: V,
331
+ controlId: e.binding.controlId
332
+ }
333
+ );
334
+ }
335
+ function Ge(e) {
336
+ const t = e.binding.mapping[e.selectedValue];
337
+ if (t && typeof t == "object" && "role" in t && t.role === "groupby")
338
+ return t;
339
+ throw new _(
340
+ `Binding for control '${e.binding.controlId}' does not map value '${e.selectedValue}' to a valid group-by field.`,
341
+ {
342
+ code: V,
343
+ controlId: e.binding.controlId
344
+ }
345
+ );
346
+ }
347
+ function Pe(e) {
348
+ const t = e.binding.mapping[e.selectedValue];
349
+ if (t && typeof t == "object" && "role" in t && t.role === "metric")
350
+ return t;
351
+ throw new _(
352
+ `Binding for control '${e.binding.controlId}' does not map value '${e.selectedValue}' to a valid metric field.`,
353
+ {
354
+ code: V,
355
+ controlId: e.binding.controlId
356
+ }
357
+ );
358
+ }
359
+ function Be(e, t, o) {
360
+ if (oe(
361
+ ne(t),
362
+ e.aggregateOrigin
363
+ ))
364
+ return { aggregate: void 0, aggregateOrigin: void 0 };
365
+ const r = o === "selection" && e.role === "metric" ? t.aggregate : void 0;
366
+ return {
367
+ aggregate: e.aggregate ?? r,
368
+ aggregateOrigin: e.aggregate ? e.aggregateOrigin : r ? t.aggregateOrigin : void 0
369
+ };
370
+ }
371
+ function ke(e, t, o) {
372
+ var r, i, a, g, u, d;
373
+ if (o === "domain")
374
+ return {
375
+ filters: (r = t.parameters) == null ? void 0 : r.filters,
376
+ windowTransform: (i = e.parameters) == null ? void 0 : i.windowTransform
377
+ };
378
+ if (!(!e.parameters && !t.parameters))
379
+ return {
380
+ filters: ((a = e.parameters) == null ? void 0 : a.filters) ?? ((g = t.parameters) == null ? void 0 : g.filters),
381
+ windowTransform: ((u = e.parameters) == null ? void 0 : u.windowTransform) ?? ((d = t.parameters) == null ? void 0 : d.windowTransform)
382
+ };
383
+ }
384
+ function at(e, t, o) {
385
+ const r = e;
386
+ return {
387
+ id: e.id,
388
+ role: e.role,
389
+ // Result-column names belong to the selection's consumer (for example,
390
+ // range bounds). They do not identify or redefine the catalog calculation.
391
+ ...o === "selection" && e.alias ? { alias: e.alias } : {},
392
+ granularity: e.granularity ?? t.granularity,
393
+ dateFormat: e.dateFormat,
394
+ customFormat: e.customFormat,
395
+ semanticTemporalPresentation: t.semanticTemporalPresentation || e.semanticTemporalPresentation,
396
+ ...Be(e, t, o),
397
+ ...e.role === "metric" ? {
398
+ aliasTemplate: r.aliasTemplate,
399
+ valueAliases: r.valueAliases,
400
+ comparison: r.comparison,
401
+ comparisonPolarity: r.comparisonPolarity,
402
+ parameters: ke(
403
+ r,
404
+ t,
405
+ "domain"
406
+ )
407
+ } : {},
408
+ ...qe(e)
409
+ };
410
+ }
411
+ function qe(e) {
412
+ const t = {
413
+ ...e.labelOrigin === "override" ? { label: e.label, labelOrigin: e.labelOrigin } : {},
414
+ ...e.formatOrigin === "override" ? { format: e.format, formatOrigin: e.formatOrigin } : {}
415
+ };
416
+ switch (e.role) {
417
+ case "pivotby":
418
+ return {
419
+ ...t,
420
+ memberOrder: e.memberOrder
421
+ };
422
+ case "sortby":
423
+ return {
424
+ ...t,
425
+ direction: e.direction
426
+ };
427
+ case "detail":
428
+ return {
429
+ ...t,
430
+ ...e.dateFormat !== void 0 ? { dateFormat: e.dateFormat } : {},
431
+ ...e.customFormat !== void 0 ? { customFormat: e.customFormat } : {}
432
+ };
433
+ default:
434
+ return t;
435
+ }
436
+ }
437
+ const ze = /* @__PURE__ */ new Set([
438
+ "day",
439
+ "week",
440
+ "month",
441
+ "quarter",
442
+ "year",
443
+ "hour",
444
+ "minute",
445
+ "second"
446
+ ]);
447
+ function st(e) {
448
+ let t = e.spec;
449
+ const o = X(
450
+ e.controlDefinitions || [],
451
+ e.cardControlDefinitions || []
452
+ ), r = (e.controlBindings || []).filter(
453
+ (n) => n.target !== "sql_param"
454
+ ), i = r.filter(
455
+ (n) => n.target === "config_metric_selector" || n.target === "config_field_selector"
456
+ ), a = r.filter(
457
+ (n) => n.target === "config_grain" || n.target === "config_aggregation"
458
+ ), g = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
459
+ let d;
460
+ const N = () => {
461
+ if (d) return d;
462
+ const n = e.catalog, c = /* @__PURE__ */ new Map();
463
+ for (const l of n) {
464
+ const f = c.get(l.id) ?? [];
465
+ c.set(l.id, [...f, l]);
466
+ }
467
+ return d = { refs: n, byId: c }, d;
468
+ }, w = (n, c) => {
469
+ throw new _(n, {
470
+ code: Fe,
471
+ ...c ? { controlId: c } : {}
472
+ });
473
+ }, S = (n, c) => {
474
+ var f;
475
+ if (n.derivedField) return n.derivedField.dataType;
476
+ const l = N().refs.filter((h) => h.field.name === n.name && P(h.field.source ?? e.spec.source, n.source ?? e.spec.source));
477
+ return l.length > 1 ? w("The selected field is ambiguous in the authorized Matrix field catalog.", c) : ce(((f = l[0]) == null ? void 0 : f.field.dataType) ?? n.dataType);
478
+ }, F = (n, c) => de(n, c.target, (l) => S(l, c.controlId)), D = ie.safeParse(t);
479
+ if (!D.success) return w(D.error.message);
480
+ t = D.data;
481
+ const K = [...i, ...a].map((n) => {
482
+ const c = Q({ binding: n, definitions: o, controlValues: e.controlValues }), l = !n.matrixTargetId && c !== void 0 && c !== A ? F(D.data, n) : [];
483
+ return {
484
+ binding: n,
485
+ selectedValue: c,
486
+ targetId: n.matrixTargetId ?? (l.length === 1 ? l[0].id : void 0)
487
+ };
488
+ });
489
+ for (const { binding: n, targetId: c, selectedValue: l } of K) {
490
+ if (l === void 0 || l === A)
491
+ continue;
492
+ const f = (s) => w(s, n.controlId), h = n.target === "config_metric_selector" || n.target === "config_aggregation", ee = F(t, n);
493
+ (!c || !ee.some((s) => s.id === c)) && f("Choose a valid Matrix level or measure target for this control.");
494
+ const v = `${n.target}:${c}`;
495
+ g.has(v) && f("Multiple controls cannot replace the same Matrix target."), g.add(v);
496
+ const M = (s) => {
497
+ const m = (N().byId.get(s.id) ?? []).filter((I) => !s.source || P(s.source, I.field.source ?? e.spec.source));
498
+ if (m.length !== 1) return f(m.length ? "The selected field is ambiguous in the authorized Matrix field catalog." : "The selected field is not in the authorized Matrix field catalog.");
499
+ const O = se.safeParse(m[0].field);
500
+ return O.success ? O.data : f(O.error.message);
501
+ }, E = n.target === "config_metric_selector" || n.target === "config_field_selector" ? n.mapping[l] : void 0, C = E && typeof E == "object" && "kind" in E && E.kind === "matrix_instance" ? E.id : void 0;
502
+ if (h) {
503
+ u.set(c, n.controlId);
504
+ const s = C === void 0 ? void 0 : D.data.measures.find(
505
+ (p) => p.id === C && p.kind === "aggregate"
506
+ );
507
+ C !== void 0 && !s && f("The selected Matrix aggregate measure is no longer available.");
508
+ const m = n.target === "config_metric_selector" && !s ? Pe({ binding: n, selectedValue: l }) : void 0, O = ((s == null ? void 0 : s.kind) === "aggregate" ? s.aggregate : m == null ? void 0 : m.aggregate) ?? (n.target === "config_aggregation" ? z({ binding: n, selectedValue: l }) : void 0), I = O === void 0 ? void 0 : ae.safeParse(O);
509
+ I && !I.success && f("This aggregation is not supported by Matrix."), t = {
510
+ ...t,
511
+ measures: t.measures.map(
512
+ (p) => p.id !== c || p.kind !== "aggregate" ? p : {
513
+ ...p,
514
+ ...m ? { field: M(m) } : {},
515
+ ...(s == null ? void 0 : s.kind) === "aggregate" ? { field: s.field } : {},
516
+ aggregate: I != null && I.success ? I.data : p.aggregate
517
+ }
518
+ )
519
+ };
520
+ } else {
521
+ const s = C === void 0 ? void 0 : [...D.data.rows, ...D.data.columns].find(
522
+ (p) => p.id === C
523
+ );
524
+ C !== void 0 && !s && f("The selected Matrix level is no longer available.");
525
+ const m = n.target === "config_field_selector" && !s ? Ge({ binding: n, selectedValue: l }) : void 0, O = n.target === "config_grain" ? z({ binding: n, selectedValue: l }) : s ? s.grain : m == null ? void 0 : m.granularity;
526
+ O !== void 0 && !ze.has(O) && f("This time grain is not supported by Matrix.");
527
+ const I = (p) => p.map((R) => {
528
+ if (R.id !== c) return R;
529
+ const U = (s == null ? void 0 : s.field) ?? (m ? M(m) : R.field), $ = S(U, n.controlId), G = O ?? (m && B($) ? R.grain : void 0);
530
+ return G && !B($) && f("A time grain requires a temporal Matrix level."), { ...R, field: U, grain: G };
531
+ });
532
+ t = {
533
+ ...t,
534
+ rows: I(t.rows),
535
+ columns: I(t.columns)
536
+ };
537
+ }
538
+ }
539
+ for (const [n, c] of Array.from(u)) {
540
+ const l = t.measures.find((h) => h.id === n);
541
+ if (!l || l.kind !== "aggregate") continue;
542
+ const f = S(l.field, c);
543
+ ue(f).some((h) => h.value === l.aggregate) || w(`Aggregation '${l.aggregate}' is not eligible for this Matrix field datatype.`, c);
544
+ }
545
+ try {
546
+ return ge(D.data, t);
547
+ } catch (n) {
548
+ if (n instanceof fe) return w(n.message);
549
+ throw n;
550
+ }
551
+ }
552
+ function J(e, t) {
553
+ const o = [], r = (i) => {
554
+ if (i.source) {
555
+ const a = le.safeParse(i.source);
556
+ if (a.success) o.push(a.data);
557
+ else if (t) throw a.error;
558
+ }
559
+ i.derivedField && Object.values(i.derivedField.inputs).forEach((a) => r(a.field));
560
+ };
561
+ for (const i of e) {
562
+ if (i.target !== "config_field_selector" && i.target !== "config_metric_selector") continue;
563
+ const a = t == null ? void 0 : t.get(i), g = t ? a && a !== A ? [i.mapping[a]] : [] : Object.values(i.mapping);
564
+ for (const u of g)
565
+ u && "role" in u && r(u);
566
+ }
567
+ return o;
568
+ }
569
+ function ct(e, t = [], o = []) {
570
+ return j([...H(e), ...J(t), ...o]);
571
+ }
572
+ function lt(e, t = {}) {
573
+ const o = t.controlBindings ?? [], r = X(t.controlDefinitions ?? [], t.cardControlDefinitions ?? []), i = new Map(o.filter((a) => a.target === "config_field_selector" || a.target === "config_metric_selector").map((a) => [a, Q({ binding: a, definitions: r, controlValues: t.controlValues })]));
574
+ return j([...H(e), ...J(o, i)]);
575
+ }
576
+ export {
577
+ ot as C,
578
+ tt as D,
579
+ et as a,
580
+ lt as b,
581
+ Se as c,
582
+ xe as d,
583
+ nt as e,
584
+ it as f,
585
+ rt as g,
586
+ Le as h,
587
+ Ve as i,
588
+ V as j,
589
+ Fe as k,
590
+ k as l,
591
+ ct as m,
592
+ _ as n,
593
+ X as o,
594
+ z as p,
595
+ Ge as q,
596
+ Q as r,
597
+ Pe as s,
598
+ Be as t,
599
+ ke as u,
600
+ $e as v,
601
+ at as w,
602
+ qe as x,
603
+ st as y,
604
+ me as z
605
+ };
@@ -0,0 +1 @@
1
+ "use strict";var ge=Object.defineProperty;var ue=(e,t,o)=>t in e?ge(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var F=(e,t,o)=>ue(e,typeof t!="symbol"?t+"":t,o);const _=require("./validators-D2F_uxxP.cjs"),S=require("./common-types-nBuCd3u2.cjs");require("./matrix-operation-contract-thtFuUYf.cjs");const Y=require("./calculated-field-identity-CtYhhZoG.cjs"),fe=require("./field-aggregations-mlkON_QA.cjs"),me=require("zod"),Z=require("./matrix-card-Dh0J0_Of.cjs"),b=require("./constants-B00YUv89.cjs");function X(e,t){const r=Ne(e);let i;if(r.date){const d=Re(r.date,2);i=De(d.restDateString,d.year)}if(!i||isNaN(i.getTime()))return new Date(NaN);const a=i.getTime();let g=0,u;if(r.time&&(g=Te(r.time),isNaN(g)))return new Date(NaN);if(r.timezone){if(u=pe(r.timezone),isNaN(u))return new Date(NaN)}else{const d=new Date(a+g),D=new Date(0);return D.setFullYear(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate()),D.setHours(d.getUTCHours(),d.getUTCMinutes(),d.getUTCSeconds(),d.getUTCMilliseconds()),D}return new Date(a+g+u)}const L={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},_e=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,Oe=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,Ie=/^([+-])(\d{2})(?::?(\d{2}))?$/;function Ne(e){const t={},o=e.split(L.dateTimeDelimiter);let r;if(o.length>2)return t;if(/:/.test(o[0])?r=o[0]:(t.date=o[0],r=o[1],L.timeZoneDelimiter.test(t.date)&&(t.date=e.split(L.timeZoneDelimiter)[0],r=e.substr(t.date.length,e.length))),r){const i=L.timezone.exec(r);i?(t.time=r.replace(i[1],""),t.timezone=i[1]):t.time=r}return t}function Re(e,t){const o=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+t)+"})|(\\d{2}|[+-]\\d{"+(2+t)+"})$)"),r=e.match(o);if(!r)return{year:NaN,restDateString:""};const i=r[1]?parseInt(r[1]):null,a=r[2]?parseInt(r[2]):null;return{year:a===null?i:a*100,restDateString:e.slice((r[1]||r[2]).length)}}function De(e,t){if(t===null)return new Date(NaN);const o=e.match(_e);if(!o)return new Date(NaN);const r=!!o[4],i=w(o[1]),a=w(o[2])-1,g=w(o[3]),u=w(o[4]),d=w(o[5])-1;if(r)return ye(t,u,d)?Ce(t,u,d):new Date(NaN);{const D=new Date(0);return!he(t,a,g)||!Ae(t,i)?new Date(NaN):(D.setUTCFullYear(t,a,Math.max(i,g)),D)}}function w(e){return e?parseInt(e):1}function Te(e){const t=e.match(Oe);if(!t)return NaN;const o=v(t[1]),r=v(t[2]),i=v(t[3]);return we(o,r,i)?o*b.millisecondsInHour+r*b.millisecondsInMinute+i*1e3:NaN}function v(e){return e&&parseFloat(e.replace(",","."))||0}function pe(e){if(e==="Z")return 0;const t=e.match(Ie);if(!t)return 0;const o=t[1]==="+"?-1:1,r=parseInt(t[2]),i=t[3]&&parseInt(t[3])||0;return Le(r,i)?o*(r*b.millisecondsInHour+i*b.millisecondsInMinute):NaN}function Ce(e,t,o){const r=new Date(0);r.setUTCFullYear(e,0,4);const i=r.getUTCDay()||7,a=(t-1)*7+o+1-i;return r.setUTCDate(r.getUTCDate()+a),r}const Ee=[31,null,31,30,31,30,31,31,30,31,30,31];function W(e){return e%400===0||e%4===0&&e%100!==0}function he(e,t,o){return t>=0&&t<=11&&o>=1&&o<=(Ee[t]||(W(e)?29:28))}function Ae(e,t){return t>=1&&t<=(W(e)?366:365)}function ye(e,t,o){return t>=1&&t<=53&&o>=0&&o<=6}function we(e,t,o){return e===24?t===0&&o===0:o>=0&&o<60&&t>=0&&t<60&&e>=0&&e<25}function Le(e,t){return t>=0&&t<=59}const Se=["lg","md","sm","xs","xxs"],be=15;function Ve(e,t){return`${e}-${t}`}const xe="CONTROL_PLACEHOLDER_QUOTED",Q="CONTROL_REFERENCE_MISSING",K="CONTROL_VALUE_MISSING",Fe="CONTROL_VALUE_INVALID",ve="CONTROL_CONTEXT_UNSUPPORTED",J="CONTROL_DEFINITION_DUPLICATE",ee="CONTROL_DEFINITION_INVALID",V="CONTROL_BINDING_MAPPING_MISSING",te="CONTROL_BINDING_TARGET_INVALID",M="CONTROL_BINDING_VALUE_INVALID";class O extends Error{constructor(o,r){super(o);F(this,"status",400);F(this,"details");Object.setPrototypeOf(this,O.prototype),this.name="ControlResolutionError",this.details=r}}function G(e,t){const o=new Map;for(const r of[...e,...t]){if(!r||typeof r!="object"||typeof r.id!="string"||r.id.trim().length===0)throw new O("Malformed control definition was provided for query execution.",{code:ee});if(o.get(r.id))throw new O(`Duplicate control definition '${r.id}' was provided for query execution.`,{code:J,controlId:r.id});o.set(r.id,r)}return o}const Me=/^-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;function Ue(e){switch(e.source.kind){case"manual":return e.source.options.map(t=>t.value);case"field_allowlist":return e.source.fieldIds;case"metric_allowlist":return e.source.metricIds;case"dataset_values":return null;default:return null}}function T(e){return`${e.label||e.id} (${e.id})`}function Ge(e){return e.type==="field_selector"||e.type==="metric_selector"||e.type==="aggregation_selector"||e.type==="grain_selector"}function j(e,t){const o=Ue(e);if(!(!o||o.length===0)&&!o.includes(t))throw new Error(`Control ${T(e)} received unsupported value '${t}'.`)}function re(e,t){switch(e.type){case"enum":case"field_selector":case"metric_selector":case"aggregation_selector":case"grain_selector":{if(typeof t!="string"||t.trim().length===0)throw new Error(`Control ${T(e)} requires a non-empty string value.`);return Ge(e)&&t===S.CONTROL_CARD_DEFAULT_VALUE||j(e,t),t}case"multi_enum":{if(!Array.isArray(t))throw new Error(`Control ${T(e)} requires a non-empty array value.`);if(t.length===0){if(!e.requiredAtExecution)return;throw new Error(`Control ${T(e)} requires a non-empty array value.`)}for(const o of t){if(typeof o!="string"||o.trim().length===0)throw new Error(`Control ${T(e)} requires string array values.`);j(e,o)}return t}case"text":{if(typeof t!="string")throw new Error(`Control ${T(e)} requires a string value.`);return t}case"number":{if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"&&Me.test(t.trim()))return Number(t);throw new Error(`Control ${T(e)} requires a numeric value.`)}case"boolean":{if(typeof t!="boolean")throw new Error(`Control ${T(e)} requires a boolean value.`);return t}case"date":{if(t instanceof Date&&!Number.isNaN(t.getTime()))return t;if(typeof t=="string"&&t.trim().length>0){const o=t.trim(),r=X(o);if(!Number.isNaN(r.getTime()))return o}throw new Error(`Control ${T(e)} requires a date-compatible value.`)}default:return t}}function P(e){var i;const t=e.definitions.get(e.binding.controlId);if(!t)throw new O(`Binding references unknown control '${e.binding.controlId}'.`,{code:Q,controlId:e.binding.controlId});if(!Object.prototype.hasOwnProperty.call(e.controlValues||{},e.binding.controlId)){if(!t.requiredAtExecution)return;throw new O(`Control '${e.binding.controlId}' must resolve to a concrete value before query execution.`,{code:K,controlId:e.binding.controlId})}let r;try{r=re(t,(i=e.controlValues)==null?void 0:i[e.binding.controlId])}catch(a){const g=a instanceof Error?a.message:String(a);throw new O(g,{code:M,controlId:e.binding.controlId})}if(typeof r=="string"&&r.trim().length>0)return r;if(typeof r=="number"||typeof r=="boolean")return String(r);if(r instanceof Date&&!Number.isNaN(r.getTime()))return r.toISOString();throw new O(`Binding control '${e.binding.controlId}' must resolve to a single scalar value.`,{code:M,controlId:e.binding.controlId})}function U(e){const t=e.binding.mapping[e.selectedValue];if(typeof t=="string"&&t.trim().length>0)return t;throw new O(`Binding for control '${e.binding.controlId}' does not map value '${e.selectedValue}'.`,{code:V,controlId:e.binding.controlId})}function oe(e){const t=e.binding.mapping[e.selectedValue];if(t&&typeof t=="object"&&"role"in t&&t.role==="groupby")return t;throw new O(`Binding for control '${e.binding.controlId}' does not map value '${e.selectedValue}' to a valid group-by field.`,{code:V,controlId:e.binding.controlId})}function ne(e){const t=e.binding.mapping[e.selectedValue];if(t&&typeof t=="object"&&"role"in t&&t.role==="metric")return t;throw new O(`Binding for control '${e.binding.controlId}' does not map value '${e.selectedValue}' to a valid metric field.`,{code:V,controlId:e.binding.controlId})}function ie(e,t,o){if(_.shouldDropInheritedCalculationAggregate(_.getCalculatedFieldComputeStage(t),e.aggregateOrigin))return{aggregate:void 0,aggregateOrigin:void 0};const r=o==="selection"&&e.role==="metric"?t.aggregate:void 0;return{aggregate:e.aggregate??r,aggregateOrigin:e.aggregate?e.aggregateOrigin:r?t.aggregateOrigin:void 0}}function ae(e,t,o){var r,i,a,g,u,d;if(o==="domain")return{filters:(r=t.parameters)==null?void 0:r.filters,windowTransform:(i=e.parameters)==null?void 0:i.windowTransform};if(!(!e.parameters&&!t.parameters))return{filters:((a=e.parameters)==null?void 0:a.filters)??((g=t.parameters)==null?void 0:g.filters),windowTransform:((u=e.parameters)==null?void 0:u.windowTransform)??((d=t.parameters)==null?void 0:d.windowTransform)}}function Pe(e,t,o){const r=e;return{id:e.id,role:e.role,...o==="selection"&&e.alias?{alias:e.alias}:{},granularity:e.granularity??t.granularity,dateFormat:e.dateFormat,customFormat:e.customFormat,semanticTemporalPresentation:t.semanticTemporalPresentation||e.semanticTemporalPresentation,...ie(e,t,o),...e.role==="metric"?{aliasTemplate:r.aliasTemplate,valueAliases:r.valueAliases,comparison:r.comparison,comparisonPolarity:r.comparisonPolarity,parameters:ae(r,t,"domain")}:{},...se(e)}}function se(e){const t={...e.labelOrigin==="override"?{label:e.label,labelOrigin:e.labelOrigin}:{},...e.formatOrigin==="override"?{format:e.format,formatOrigin:e.formatOrigin}:{}};switch(e.role){case"pivotby":return{...t,memberOrder:e.memberOrder};case"sortby":return{...t,direction:e.direction};case"detail":return{...t,...e.dateFormat!==void 0?{dateFormat:e.dateFormat}:{},...e.customFormat!==void 0?{customFormat:e.customFormat}:{}};default:return t}}const $e=new Set(["day","week","month","quarter","year","hour","minute","second"]);function Be(e){let t=e.spec;const o=G(e.controlDefinitions||[],e.cardControlDefinitions||[]),r=(e.controlBindings||[]).filter(n=>n.target!=="sql_param"),i=r.filter(n=>n.target==="config_metric_selector"||n.target==="config_field_selector"),a=r.filter(n=>n.target==="config_grain"||n.target==="config_aggregation"),g=new Set,u=new Map;let d;const D=()=>{if(d)return d;const n=e.catalog,c=new Map;for(const l of n){const f=c.get(l.id)??[];c.set(l.id,[...f,l])}return d={refs:n,byId:c},d},h=(n,c)=>{throw new O(n,{code:te,...c?{controlId:c}:{}})},x=(n,c)=>{var f;if(n.derivedField)return n.derivedField.dataType;const l=D().refs.filter(C=>C.field.name===n.name&&_.semaphorSourcesReferToSameDataset(C.field.source??e.spec.source,n.source??e.spec.source));return l.length>1?h("The selected field is ambiguous in the authorized Matrix field catalog.",c):_.normalizeAnalyticsCatalogDataType(((f=l[0])==null?void 0:f.field.dataType)??n.dataType)},$=(n,c)=>Y.getMatrixBindingTargets(n,c.target,l=>x(l,c.controlId)),p=_.matrixSpecSchema.safeParse(t);if(!p.success)return h(p.error.message);t=p.data;const le=[...i,...a].map(n=>{const c=P({binding:n,definitions:o,controlValues:e.controlValues}),l=!n.matrixTargetId&&c!==void 0&&c!==S.CONTROL_CARD_DEFAULT_VALUE?$(p.data,n):[];return{binding:n,selectedValue:c,targetId:n.matrixTargetId??(l.length===1?l[0].id:void 0)}});for(const{binding:n,targetId:c,selectedValue:l}of le){if(l===void 0||l===S.CONTROL_CARD_DEFAULT_VALUE)continue;const f=s=>h(s,n.controlId),C=n.target==="config_metric_selector"||n.target==="config_aggregation",de=$(t,n);(!c||!de.some(s=>s.id===c))&&f("Choose a valid Matrix level or measure target for this control.");const B=`${n.target}:${c}`;g.has(B)&&f("Multiple controls cannot replace the same Matrix target."),g.add(B);const q=s=>{const m=(D().byId.get(s.id)??[]).filter(N=>!s.source||_.semaphorSourcesReferToSameDataset(s.source,N.field.source??e.spec.source));if(m.length!==1)return f(m.length?"The selected field is ambiguous in the authorized Matrix field catalog.":"The selected field is not in the authorized Matrix field catalog.");const R=_.matrixFieldSchema.safeParse(m[0].field);return R.success?R.data:f(R.error.message)},A=n.target==="config_metric_selector"||n.target==="config_field_selector"?n.mapping[l]:void 0,E=A&&typeof A=="object"&&"kind"in A&&A.kind==="matrix_instance"?A.id:void 0;if(C){u.set(c,n.controlId);const s=E===void 0?void 0:p.data.measures.find(I=>I.id===E&&I.kind==="aggregate");E!==void 0&&!s&&f("The selected Matrix aggregate measure is no longer available.");const m=n.target==="config_metric_selector"&&!s?ne({binding:n,selectedValue:l}):void 0,R=((s==null?void 0:s.kind)==="aggregate"?s.aggregate:m==null?void 0:m.aggregate)??(n.target==="config_aggregation"?U({binding:n,selectedValue:l}):void 0),N=R===void 0?void 0:_.matrixAggregateSchema.safeParse(R);N&&!N.success&&f("This aggregation is not supported by Matrix."),t={...t,measures:t.measures.map(I=>I.id!==c||I.kind!=="aggregate"?I:{...I,...m?{field:q(m)}:{},...(s==null?void 0:s.kind)==="aggregate"?{field:s.field}:{},aggregate:N!=null&&N.success?N.data:I.aggregate})}}else{const s=E===void 0?void 0:[...p.data.rows,...p.data.columns].find(I=>I.id===E);E!==void 0&&!s&&f("The selected Matrix level is no longer available.");const m=n.target==="config_field_selector"&&!s?oe({binding:n,selectedValue:l}):void 0,R=n.target==="config_grain"?U({binding:n,selectedValue:l}):s?s.grain:m==null?void 0:m.granularity;R!==void 0&&!$e.has(R)&&f("This time grain is not supported by Matrix.");const N=I=>I.map(y=>{if(y.id!==c)return y;const k=(s==null?void 0:s.field)??(m?q(m):y.field),H=x(k,n.controlId),z=R??(m&&_.isAnalyticsDateLikeDataType(H)?y.grain:void 0);return z&&!_.isAnalyticsDateLikeDataType(H)&&f("A time grain requires a temporal Matrix level."),{...y,field:k,grain:z}});t={...t,rows:N(t.rows),columns:N(t.columns)}}}for(const[n,c]of Array.from(u)){const l=t.measures.find(C=>C.id===n);if(!l||l.kind!=="aggregate")continue;const f=x(l.field,c);fe.getFieldAggregationOptions(f).some(C=>C.value===l.aggregate)||h(`Aggregation '${l.aggregate}' is not eligible for this Matrix field datatype.`,c)}try{return Y.reconcileMatrixSpecStructure(p.data,t)}catch(n){if(n instanceof me.ZodError)return h(n.message);throw n}}function ce(e,t){const o=[],r=i=>{if(i.source){const a=_.configSourceRefSchema.safeParse(i.source);if(a.success)o.push(a.data);else if(t)throw a.error}i.derivedField&&Object.values(i.derivedField.inputs).forEach(a=>r(a.field))};for(const i of e){if(i.target!=="config_field_selector"&&i.target!=="config_metric_selector")continue;const a=t==null?void 0:t.get(i),g=t?a&&a!==S.CONTROL_CARD_DEFAULT_VALUE?[i.mapping[a]]:[]:Object.values(i.mapping);for(const u of g)u&&"role"in u&&r(u)}return o}function qe(e,t=[],o=[]){return _.mergeSemaphorSourcesByIdentity([...Z.matrixDefinitionSources(e),...ce(t),...o])}function ke(e,t={}){const o=t.controlBindings??[],r=G(t.controlDefinitions??[],t.cardControlDefinitions??[]),i=new Map(o.filter(a=>a.target==="config_field_selector"||a.target==="config_metric_selector").map(a=>[a,P({binding:a,definitions:r,controlValues:t.controlValues})]));return _.mergeSemaphorSourcesByIdentity([...Z.matrixDefinitionSources(e),...ce(o,i)])}exports.CONTROL_BINDING_MAPPING_MISSING_ERROR_CODE=V;exports.CONTROL_BINDING_TARGET_INVALID_ERROR_CODE=te;exports.CONTROL_BINDING_VALUE_INVALID_ERROR_CODE=M;exports.CONTROL_CONTEXT_UNSUPPORTED_ERROR_CODE=ve;exports.CONTROL_DEFINITION_DUPLICATE_ERROR_CODE=J;exports.CONTROL_DEFINITION_INVALID_ERROR_CODE=ee;exports.CONTROL_PLACEHOLDER_QUOTED_ERROR_CODE=xe;exports.CONTROL_REFERENCE_MISSING_ERROR_CODE=Q;exports.CONTROL_VALUE_INVALID_ERROR_CODE=Fe;exports.CONTROL_VALUE_MISSING_ERROR_CODE=K;exports.ControlResolutionError=O;exports.DASHBOARD_AUTHORING_BREAKPOINTS=Se;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=be;exports.buildControlDefinitionIndex=G;exports.getCalculatedFieldAggregateOverrides=ie;exports.getCalculatedFieldParameters=ae;exports.getCalculatedFieldShelfOverrides=se;exports.getColumnCatalogFieldId=Ve;exports.getDomainCalculatedSelectionOverrides=Pe;exports.matrixCatalogSources=qe;exports.matrixExecutionSources=ke;exports.parseISO=X;exports.resolveBindingControlValue=P;exports.resolveGroupByFieldTarget=oe;exports.resolveMatrixControlBindings=Be;exports.resolveMetricFieldTarget=ne;exports.resolveScalarMappedValue=U;exports.validateControlValue=re;