react-semaphor 0.1.601 → 0.1.603

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 (123) hide show
  1. package/dist/analytics-protocol/index.js +415 -375
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/assistant-protocol/index.js +5 -5
  4. package/dist/brand-studio/index.js +8 -8
  5. package/dist/briefings/index.js +5 -5
  6. package/dist/chunks/{add-to-dashboard-ClhEIFst.js → add-to-dashboard-CFF-wFU-.js} +1 -1
  7. package/dist/chunks/{analytics-base-schemas-DevrgqQb.js → analytics-base-schemas-DsUh5Q3C.js} +14 -12
  8. package/dist/chunks/{assistant-chat-BE0XXzZP.js → assistant-chat-B6hNQI1t.js} +146 -146
  9. package/dist/chunks/{bookmark-impact-DXDAN5AY.js → bookmark-impact-Ba2PLcGp.js} +3 -3
  10. package/dist/chunks/{bookmark-state-BMyB3Tb6.js → bookmark-state-n7AaNzR_.js} +517 -516
  11. package/dist/chunks/{card-filter-builder-CE0-YVN5.js → card-filter-builder-Y22HizVx.js} +474 -474
  12. package/dist/chunks/{comparison-window-caption-Dxj2CHOa.js → comparison-window-caption-Ck2TIbnR.js} +69 -69
  13. package/dist/chunks/{context-BJoEFgNl.js → context-UCQ7sere.js} +1 -1
  14. package/dist/chunks/{dashboard-mJKPFRbb.js → dashboard-BghI99oY.js} +1 -1
  15. package/dist/chunks/{dashboard-briefing-launcher-CntwKyiZ.js → dashboard-briefing-launcher-DtBAnGiH.js} +725 -716
  16. package/dist/chunks/{dashboard-controls-XO089DMg.js → dashboard-controls-CtFXlyjV.js} +53 -53
  17. package/dist/chunks/{dashboard-json-CQRiydUv.js → dashboard-json-DfGBUtCd.js} +5 -5
  18. package/dist/chunks/dates-BnrXF4bb.js +185 -0
  19. package/dist/chunks/{edit-dashboard-visual-f-Dm-BLR.js → edit-dashboard-visual-oxt3x1wb.js} +8081 -8268
  20. package/dist/chunks/{filter-line-CKNMyNTQ.js → filter-line-Cy5YYqRL.js} +27 -27
  21. package/dist/chunks/{filter-reach-copy-B8GGyVuR.js → filter-reach-copy-CE_ZX147.js} +1786 -2214
  22. package/dist/chunks/{filter-value-text-CRtKecI5.js → filter-value-text-fWvSDwkl.js} +11 -11
  23. package/dist/chunks/{index-DoPApnxg.js → index-D5rxbtS4.js} +24 -24
  24. package/dist/chunks/{layout-grid-CiSCZdIr.js → layout-grid-9LndRoLa.js} +1 -1
  25. package/dist/chunks/{matrix-analytical-definition-myf3D3Qx.js → matrix-analytical-definition-CCp48UCw.js} +496 -425
  26. package/dist/chunks/matrix-member-presentation-zNehruXR.js +391 -0
  27. package/dist/chunks/{matrix-operation-contract-C1SuOHLZ.js → matrix-operation-contract-DPBj69D8.js} +518 -514
  28. package/dist/chunks/{metric-comparison-Cm0G893W.js → metric-comparison-B0FR-Q8I.js} +184 -125
  29. package/dist/chunks/{paintbrush-DQIwqlck.js → paintbrush-58FQYY-y.js} +1 -1
  30. package/dist/chunks/{palette-Cun747Rg.js → palette-Be62Tkoa.js} +1 -1
  31. package/dist/chunks/{pivot-result-contract-expectations-C1Dyx8du.js → pivot-result-contract-expectations-BYqAmG9n.js} +1236 -1190
  32. package/dist/chunks/{pivot-result-identity-CBS-ssEp.js → pivot-result-identity-CAP4--iq.js} +1 -1
  33. package/dist/chunks/raw-temporal-value-Dg_MTFF7.js +3778 -0
  34. package/dist/chunks/{report-preferences-dialog-SDZEcG2x.js → report-preferences-dialog-uJp9GBTM.js} +219 -205
  35. package/dist/chunks/{report-runtime-context-BbedQdtc.js → report-runtime-context-c77_KF9v.js} +2 -2
  36. package/dist/chunks/{resolve-dashboard-input-context-DRBS0eRa.js → resolve-dashboard-input-context-Rtl1ffmE.js} +8808 -7291
  37. package/dist/chunks/{save-Dj5bjm7P.js → save-C5A0JnEV.js} +1 -1
  38. package/dist/chunks/{saved-dashboard-context-DWVlJcsa.js → saved-dashboard-context-tcyTU8jm.js} +199 -213
  39. package/dist/chunks/selection-filter-compiler-DNijjI5y.js +150 -0
  40. package/dist/chunks/{semaphor-ready-indicator-OFOoAY-A.js → semaphor-ready-indicator-FBvunj6S.js} +37894 -35726
  41. package/dist/chunks/{shelf-drop-preview-context-2swWypXu.js → shelf-drop-preview-context-QKStrcK9.js} +54 -54
  42. package/dist/chunks/{stored-dashboard-NtOuEX6a.js → stored-dashboard-CHozcAY9.js} +770 -743
  43. package/dist/chunks/{style-sheet-parts-Qv4UcLAo.js → style-sheet-parts-CDCG-8Ej.js} +258 -251
  44. package/dist/chunks/{table-export-sheet-Do7ZB0_F.js → table-export-sheet-ZFIvs6Sj.js} +1 -1
  45. package/dist/chunks/{token-types-Dy_aXO-U.js → token-types-XbM6QByy.js} +1 -1
  46. package/dist/chunks/{upload-Bq-puSVy.js → upload-H15d7uHK.js} +1 -1
  47. package/dist/chunks/{validators-C7DFk3QK.js → validators-Baf3VIf5.js} +5 -5
  48. package/dist/chunks/{variable-draft-Cy03qnEi.js → variable-draft-C2y8Jp6Z.js} +27 -28
  49. package/dist/dashboard/index.js +2 -2
  50. package/dist/dashboard-authoring/index.js +3392 -2761
  51. package/dist/format-utils/index.js +205 -204
  52. package/dist/index.js +73 -75
  53. package/dist/report-runtime-context/index.js +2 -2
  54. package/dist/style.css +1 -1
  55. package/dist/surfboard/index.js +2 -2
  56. package/dist/types/components/dashboard/dashboard-web-component.d.ts +7 -0
  57. package/dist/types/components/ui-custom/date-range-presets.d.ts +8 -0
  58. package/dist/types/index.js +5 -5
  59. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +1 -1
  60. package/dist/types/lib/document/document-edits.d.ts +0 -4
  61. package/dist/types/lib/query-context/assemble-card-query.d.ts +6 -1
  62. package/dist/types/lib/stores/dashboard-store.d.ts +30 -1
  63. package/dist/types/lib/types/common-types.d.ts +0 -2
  64. package/dist/types/lib/types/explorer-types.d.ts +1 -1
  65. package/dist/types/shared/analytics-protocol/aggregate-expression.d.ts +15 -0
  66. package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +18 -0
  67. package/dist/types/shared/analytics-protocol/analyze-result-types.d.ts +3 -0
  68. package/dist/types/shared/analytics-protocol/comparison-choices.d.ts +92 -0
  69. package/dist/types/shared/analytics-protocol/comparison-placement.d.ts +30 -0
  70. package/dist/types/shared/analytics-protocol/contracts.d.ts +11 -5
  71. package/dist/types/shared/analytics-protocol/date-window.d.ts +105 -0
  72. package/dist/types/shared/analytics-protocol/filter-field-ownership.d.ts +27 -0
  73. package/dist/types/shared/analytics-protocol/fixtures.d.ts +4 -2
  74. package/dist/types/shared/analytics-protocol/index.d.ts +3 -0
  75. package/dist/types/shared/analytics-protocol/metric-comparison.d.ts +93 -11
  76. package/dist/types/shared/assistant-protocol/context.d.ts +16 -16
  77. package/dist/types/shared/dashboard-authoring/calculations/calculated-column.d.ts +52 -0
  78. package/dist/types/shared/dashboard-authoring/calculations/definition.d.ts +129 -0
  79. package/dist/types/shared/dashboard-authoring/calculations/resolve-dashboard-field-copies.d.ts +46 -0
  80. package/dist/types/shared/dashboard-authoring/calculations/tokens.d.ts +36 -0
  81. package/dist/types/shared/dashboard-authoring/card-settings/card-display-write.d.ts +8 -0
  82. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +1 -1
  83. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +2 -1
  84. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +0 -3
  85. package/dist/types/shared/dashboard-authoring/changes/calculation-change.d.ts +399 -0
  86. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +165 -360
  87. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +23 -2
  88. package/dist/types/shared/dashboard-authoring/changes/domain-change.d.ts +143 -266
  89. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +2 -0
  90. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +46 -0
  91. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +10 -10
  92. package/dist/types/shared/dashboard-authoring/dashboard-variable-card.d.ts +2 -4
  93. package/dist/types/shared/dashboard-authoring/index.d.ts +7 -1
  94. package/dist/types/shared/dashboard-authoring/kpi-date-context.d.ts +2 -0
  95. package/dist/types/shared/dashboard-authoring/kpi-figure.d.ts +18 -0
  96. package/dist/types/shared/dashboard-authoring/measure-calculations/comparison.d.ts +8 -7
  97. package/dist/types/shared/dashboard-authoring/measure-calculations/dates.d.ts +11 -1
  98. package/dist/types/shared/dashboard-authoring/measure-calculations/index.d.ts +2 -2
  99. package/dist/types/shared/dashboard-authoring/measure-calculations/options.d.ts +4 -0
  100. package/dist/types/shared/dashboard-authoring/measure-calculations/read.d.ts +18 -1
  101. package/dist/types/shared/dashboard-authoring/measure-calculations/resolve.d.ts +2 -0
  102. package/dist/types/shared/dashboard-authoring/measure-calculations/schemas.d.ts +46 -88
  103. package/dist/types/shared/dashboard-authoring/operations/calculated-field-operations.d.ts +158 -0
  104. package/dist/types/shared/dashboard-authoring/operations/card-operations.d.ts +71 -0
  105. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +17 -6
  106. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +21 -0
  107. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +3 -0
  108. package/dist/types/shared/format-utils/comparison-detail.d.ts +34 -0
  109. package/dist/types/shared/format-utils/index.d.ts +1 -0
  110. package/dist/types/shared/format-utils/partial-period.d.ts +4 -2
  111. package/dist/types/shared/temporal/calendar-periods.d.ts +11 -0
  112. package/dist/types/shared/temporal/index.d.ts +2 -0
  113. package/dist/types/shared/temporal/temporal-text.d.ts +33 -0
  114. package/dist/types/shared/temporal/temporal.d.ts +27 -0
  115. package/dist/types/shared/temporal/zoned-wall-clock.d.ts +4 -3
  116. package/dist/types/shared/usage-events/details.d.ts +2 -2
  117. package/dist/types/shared/usage-events/envelope.d.ts +2 -2
  118. package/dist/usage-events/index.js +1 -1
  119. package/package.json +3 -2
  120. package/dist/chunks/dates-B-Urp5OD.js +0 -164
  121. package/dist/chunks/matrix-member-presentation-g0c_NpDW.js +0 -258
  122. package/dist/chunks/raw-temporal-value-DN_l-Tss.js +0 -454
  123. package/dist/chunks/selection-filter-compiler-DmAr7yqC.js +0 -131
@@ -13,6 +13,9 @@ export * from './physical-source-resolution.js';
13
13
  export * from './source-entity-resolution.js';
14
14
  export * from './fixtures.js';
15
15
  export * from './metric-comparison.js';
16
+ export * from './comparison-choices.js';
17
+ export * from './date-window.js';
18
+ export * from './comparison-placement.js';
16
19
  export * from './applied-constraints.js';
17
20
  export * from './filter-field-ownership.js';
18
21
  export * from './click-reach-filter-id.js';
@@ -1,6 +1,30 @@
1
1
  import { SemaphorFieldRef, SemaphorTimeGrain, SemaphorValidationResult } from './contracts.js';
2
2
  import { TemporalShift } from '../temporal/calendar-periods.js';
3
- export type MetricComparisonSpec = {
3
+ import { ComparisonWindowShape } from './comparison-choices.js';
4
+ /**
5
+ * How far back a comparison steps (compare-with CW-D3): the window's own
6
+ * length (`period`, the previous period) or a fixed calendar unit.
7
+ */
8
+ export type ComparisonUnit = 'period' | 'day' | 'week' | 'month' | 'quarter' | 'year';
9
+ export declare const COMPARISON_UNITS: readonly ["period", "day", "week", "month", "quarter", "year"];
10
+ /** A step back: `offset` units (1 when absent); only a step by years may match weekdays (364 days a year, CW-D4). */
11
+ export type ComparisonShiftSpec = {
12
+ kind: 'shift';
13
+ unit: ComparisonUnit;
14
+ offset?: number;
15
+ matchWeekdays?: true;
16
+ };
17
+ /** What a measure is compared with: a step back, or a fixed number. */
18
+ export type MetricComparisonSpec = ComparisonShiftSpec | {
19
+ kind: 'target';
20
+ targetValue: number;
21
+ };
22
+ /**
23
+ * The period shapes saved before Compare with (CW-D5): still on stored cards,
24
+ * Date filter selections, bookmarks and variables, read through
25
+ * `readMetricComparisonSpec` and never written.
26
+ */
27
+ export type LegacyPeriodComparisonSpec = {
4
28
  kind: 'previous_period';
5
29
  offsetPeriods?: number;
6
30
  alignment?: 'calendar' | 'weekday';
@@ -10,16 +34,29 @@ export type MetricComparisonSpec = {
10
34
  offsetYears?: number;
11
35
  alignment?: 'calendar' | 'weekday';
12
36
  toDate?: boolean;
13
- } | {
14
- kind: 'target';
15
- targetValue: number;
16
37
  };
38
+ /** A comparison as stored: the spec, or a shape saved before Compare with. */
39
+ export type StoredMetricComparisonSpec = MetricComparisonSpec | LegacyPeriodComparisonSpec;
17
40
  export type MetricComparisonConfig = {
18
41
  mode: 'off';
19
42
  } | {
20
43
  mode: 'explicit';
21
- spec: MetricComparisonSpec;
44
+ spec: StoredMetricComparisonSpec;
22
45
  };
46
+ /**
47
+ * The one reader of a stored comparison (CW-D5, CW-INV-4): an old period
48
+ * shape becomes a step back (`previous_period` by the window's own length,
49
+ * `previous_year` by years, matching weekdays when it aligned by weekday); a
50
+ * stored `toDate` says nothing (CW-D2); a weekday alignment on a previous
51
+ * period is dropped (no saved card has one, ledger IN-03). An offset of 1 is
52
+ * left out.
53
+ */
54
+ export declare function readMetricComparisonSpec(spec: StoredMetricComparisonSpec): MetricComparisonSpec;
55
+ /** What a comparison is called in results and metadata (CW-D13): a step by years is the previous year. */
56
+ export type ComparisonFamily = 'previous_period' | 'previous_year' | 'target';
57
+ export declare function comparisonFamily(spec: StoredMetricComparisonSpec): ComparisonFamily;
58
+ /** How many steps back (1 when absent). */
59
+ export declare function comparisonOffset(spec: ComparisonShiftSpec): number;
23
60
  export type MetricComparisonPolarity = 'higher_is_better' | 'lower_is_better' | 'neutral';
24
61
  export declare const DEFAULT_METRIC_COMPARISON_POLARITY: "higher_is_better";
25
62
  export type ComparisonPresentationSpec = {
@@ -55,14 +92,15 @@ export declare const COMPARISON_PRESENTATION_DEFAULTS: {
55
92
  readonly showColor: true;
56
93
  readonly conditionalLabel: false;
57
94
  };
58
- export type ViewerPeriodComparisonSpec = Extract<MetricComparisonSpec, {
59
- kind: 'previous_period' | 'previous_year';
60
- }>;
95
+ /** A comparison a dashboard date can carry: a step back, never a target. */
96
+ export type ViewerPeriodComparisonSpec = ComparisonShiftSpec;
97
+ /** A dashboard date's comparison as stored: a step back, or a period shape saved before Compare with. */
98
+ export type StoredViewerPeriodComparisonSpec = ComparisonShiftSpec | LegacyPeriodComparisonSpec;
61
99
  export type GlobalDateComparisonSelection = {
62
100
  mode: 'off';
63
101
  } | {
64
102
  mode: 'period';
65
- spec: ViewerPeriodComparisonSpec;
103
+ spec: StoredViewerPeriodComparisonSpec;
66
104
  };
67
105
  export type DashboardDateComparisonOwner = {
68
106
  kind: 'global_date';
@@ -84,6 +122,39 @@ export type ResolvedMetricComparisonRequest = {
84
122
  spec: ViewerPeriodComparisonSpec;
85
123
  owner?: DashboardDateComparisonOwner;
86
124
  };
125
+ /**
126
+ * What a measure compares with, as one of three states (compare-with CW-D17):
127
+ * `pinned` to its own step or target (any stored comparison reads as pinned,
128
+ * CW-D20), `off`, or `follow` the Date filter's comparison. A measure with no
129
+ * comparison of its own on a card saved with "Inherit Global Date comparison"
130
+ * off reads as off, what it showed (CW-D21); the card switch is read here and
131
+ * nowhere else.
132
+ */
133
+ export type MeasureComparisonState = {
134
+ state: 'follow';
135
+ } | {
136
+ state: 'pinned';
137
+ spec: MetricComparisonSpec;
138
+ } | {
139
+ state: 'off';
140
+ };
141
+ export declare function readMeasureComparisonState(input: {
142
+ metricComparison?: MetricComparisonConfig;
143
+ inheritGlobalComparison?: false;
144
+ /**
145
+ * The card's comparisons are saved hidden ("Show comparison" off): every
146
+ * measure reads as off and none runs (compare-with CW-D28).
147
+ */
148
+ hidden?: boolean;
149
+ }): MeasureComparisonState;
150
+ /** Whether a card's comparisons are saved hidden ("Show comparison" off), the one reading of it (CW-D28). */
151
+ export declare function comparisonsHidden(presentation: Pick<ComparisonPresentationSpec, 'showComparison'> | undefined): boolean;
152
+ /**
153
+ * The comparison a measure runs with, from its state alone (CW-D17): pinned
154
+ * runs its own, follow runs the Date filter's comparison when there is one,
155
+ * off runs none. What asks decides what reaches it: a text variable gets no
156
+ * Date filter comparison (CW-D22), so it never follows.
157
+ */
87
158
  export declare function resolveMetricComparisonRequest(input: {
88
159
  metricComparison?: MetricComparisonConfig;
89
160
  inheritGlobalComparison?: false;
@@ -96,7 +167,9 @@ export type ResolvedDateWindow = {
96
167
  };
97
168
  export type ComparisonUnavailableReason = 'finite_current_window_required' | 'current_window_not_started'
98
169
  /** The date ranges the run applies to the field have no instant in common. */
99
- | 'current_window_empty' | 'temporal_binding_missing' | 'temporal_binding_ambiguous' | 'temporal_binding_invalid' | 'unsupported_output_shape' | 'unsupported_raw_sql' | 'insufficient_history' | 'invalid_comparison_spec' | 'comparison_execution_failed';
170
+ | 'current_window_empty' | 'temporal_binding_missing' | 'temporal_binding_ambiguous' | 'temporal_binding_invalid' | 'unsupported_output_shape' | 'unsupported_raw_sql' | 'insufficient_history'
171
+ /** A fixed step shorter than the window: the earlier window would overlap it (compare-with CW-D7). */
172
+ | 'overlaps_current_window' | 'invalid_comparison_spec' | 'comparison_execution_failed';
100
173
  export type ComparisonAvailability = {
101
174
  status: 'available';
102
175
  } | {
@@ -110,7 +183,15 @@ export type MetricComparisonOutputBase = {
110
183
  metricAlias: string;
111
184
  currentColumnKey: string;
112
185
  windowGrain?: MetricComparisonWindowGrain;
186
+ /** The current window as the run filtered it: cut at the run instant while it is still running (CW-D1). */
113
187
  currentWindow?: ResolvedDateWindow;
188
+ /**
189
+ * What the current window is, for naming its comparison (CW-D12, CW-D15):
190
+ * the window the user picked (This month), or a range whole and on the
191
+ * report calendar, worked out once where the run plans it. A running month
192
+ * then reads "Previous month", not its elapsed days (ledger P4-11).
193
+ */
194
+ windowShape?: ComparisonWindowShape;
114
195
  comparisonWindow?: ResolvedDateWindow;
115
196
  /**
116
197
  * How far back `comparisonWindow` sits from `currentWindow`: the one step a
@@ -158,7 +239,8 @@ export type MetricComparisonOutput = MetricComparisonOutputBase & ({
158
239
  comparisonSourceBucketColumnKey?: never;
159
240
  });
160
241
  export type MetricComparisonMetadataEntry = {
161
- type: MetricComparisonSpec['kind'];
242
+ /** The comparison's family (CW-D13), not the spec's kind. */
243
+ type: ComparisonFamily;
162
244
  displayName?: string;
163
245
  displayLabel?: string;
164
246
  output: MetricComparisonOutput;
@@ -625,15 +625,15 @@ export declare const assistantContextSchema: z.ZodEffects<z.ZodObject<{
625
625
  title: string;
626
626
  unsavedEdits: boolean;
627
627
  } | undefined;
628
- sheet?: {
629
- id: string;
630
- title: string;
631
- } | undefined;
632
628
  omitted?: {
633
629
  cards?: number | undefined;
634
630
  otherSheets?: number | undefined;
635
631
  activeInputs?: number | undefined;
636
632
  } | undefined;
633
+ sheet?: {
634
+ id: string;
635
+ title: string;
636
+ } | undefined;
637
637
  selectedCard?: {
638
638
  id: string;
639
639
  description: {
@@ -717,15 +717,15 @@ export declare const assistantContextSchema: z.ZodEffects<z.ZodObject<{
717
717
  title: string;
718
718
  unsavedEdits: boolean;
719
719
  } | undefined;
720
- sheet?: {
721
- id: string;
722
- title: string;
723
- } | undefined;
724
720
  omitted?: {
725
721
  cards?: number | undefined;
726
722
  otherSheets?: number | undefined;
727
723
  activeInputs?: number | undefined;
728
724
  } | undefined;
725
+ sheet?: {
726
+ id: string;
727
+ title: string;
728
+ } | undefined;
729
729
  selectedCard?: {
730
730
  id: string;
731
731
  description: {
@@ -809,15 +809,15 @@ export declare const assistantContextSchema: z.ZodEffects<z.ZodObject<{
809
809
  title: string;
810
810
  unsavedEdits: boolean;
811
811
  } | undefined;
812
- sheet?: {
813
- id: string;
814
- title: string;
815
- } | undefined;
816
812
  omitted?: {
817
813
  cards?: number | undefined;
818
814
  otherSheets?: number | undefined;
819
815
  activeInputs?: number | undefined;
820
816
  } | undefined;
817
+ sheet?: {
818
+ id: string;
819
+ title: string;
820
+ } | undefined;
821
821
  selectedCard?: {
822
822
  id: string;
823
823
  description: {
@@ -901,15 +901,15 @@ export declare const assistantContextSchema: z.ZodEffects<z.ZodObject<{
901
901
  title: string;
902
902
  unsavedEdits: boolean;
903
903
  } | undefined;
904
- sheet?: {
905
- id: string;
906
- title: string;
907
- } | undefined;
908
904
  omitted?: {
909
905
  cards?: number | undefined;
910
906
  otherSheets?: number | undefined;
911
907
  activeInputs?: number | undefined;
912
908
  } | undefined;
909
+ sheet?: {
910
+ id: string;
911
+ title: string;
912
+ } | undefined;
913
913
  selectedCard?: {
914
914
  id: string;
915
915
  description: {
@@ -0,0 +1,52 @@
1
+ import { Field } from '../../../lib/types/explorer-types.js';
2
+ /**
3
+ * A calculated column's identity and kind, the one owner (calculated fields
4
+ * one core, plan "Names and shapes"). A calculated column is a field object
5
+ * on a card or a dashboard filter that carries a formula: a non-empty
6
+ * `expression`, a `calculatedFieldOrigin` or a `derivedField`.
7
+ */
8
+ /** A field id with the field list's `card-source-` prefix removed: the id its definition has. */
9
+ export declare function normalizeCalculatedFieldId(id?: string): string | undefined;
10
+ /** The identity of a field with no id: role, namespace, name and formula. */
11
+ export declare function getCalculatedFieldComparableKey(field: Field): string;
12
+ /**
13
+ * How a column finds its definition, and a definition is known in its list:
14
+ * `domain:<stable id>` for a domain-scoped field, `id:<origin id or id, card-source- removed>`
15
+ * for any other with an id, `fallback:<comparable key>` for one with neither.
16
+ * A dashboard field and its copies share the key.
17
+ */
18
+ export declare function getCalculatedFieldIdentityKey(field: Field): string;
19
+ /** A field object that carries a formula (the plan's "calculated column"). */
20
+ export declare function isCalculatedColumn(field: Partial<Field> | null | undefined): boolean;
21
+ export type CalculatedColumnKind = 'domain_reference' | 'dashboard_copy' | 'no_definition';
22
+ /**
23
+ * What a calculated column is, in this order: a domain reference (the run
24
+ * path rebuilds it from the domain), a copy of one of the dashboard's fields
25
+ * (the run path rebuilds it from its field's definition, MC-D21), or a column without a definition (a
26
+ * frozen copy, a raw SQL copy, a card-field copy, a dashboard copy whose
27
+ * field is gone).
28
+ */
29
+ export declare function classifyCalculatedColumn(column: Field, dashboardFields: readonly Field[]): CalculatedColumnKind;
30
+ /**
31
+ * A column equals its field: the same name, formula, operation, input fields
32
+ * (dataset, name, aggregate, in order; a calculated input also by its own
33
+ * formula, at any depth) and data type. The column's own place (id, alias,
34
+ * its aggregate, sort, format, label) doesn't count (MC-D9, MC-INV-5).
35
+ */
36
+ export declare function calculatedColumnMatchesField(column: Field, field: Field): boolean;
37
+ /** The dashboard copies on a card's shelves, each as its own definition: how a sentence reads a card without its dashboard. */
38
+ export declare function dashboardCopiesOn(card: {
39
+ config?: unknown;
40
+ }): Field[];
41
+ /**
42
+ * The dashboard field a card query's name means, when it means one (MC-D9):
43
+ * a dashboard field of that name whose inputs read the card's source comes
44
+ * first; otherwise the name is the domain's, and undefined comes back. A
45
+ * source is its domain and dataset together (a dataset of one name can sit in
46
+ * two domains); an input that names no domain is matched by its dataset. The
47
+ * field list's display order doesn't change.
48
+ */
49
+ export declare function resolveCalculatedFieldName(name: string, source: {
50
+ domainId?: string;
51
+ datasetName: string;
52
+ }, dashboardFields: readonly Field[]): Field | undefined;
@@ -0,0 +1,129 @@
1
+ import { AggregateFunction, CalculatedFieldOperation, DataType, Field, GroupByField, MetricField } from '../../../lib/types/explorer-types.js';
2
+ /**
3
+ * A dashboard field's definition: the words that describe it to the stored
4
+ * shape and back, the one owner (calculated fields one core, MC-D5, MC-D16).
5
+ * The editor's dialog and the MCP both write through
6
+ * `buildCalculatedFieldDefinition`; the outline reads through
7
+ * `readCalculatedFieldDefinition`. The stored shape is the editor's: indexed
8
+ * `{field_N}` tokens over full `calculatedFormula.inputFields`.
9
+ */
10
+ export type CalculatedFieldDefinitionInput = {
11
+ kind: 'measure';
12
+ /** The name as typed; stored normalized, with the typed text as its label. */
13
+ name: string;
14
+ /** The formula with indexed tokens over `inputFields`. */
15
+ expression: string;
16
+ /** Each input as the field list offers it, in token order. */
17
+ inputFields: MetricField[];
18
+ /** The card the dialog was opened from: the entity of a formula over several datasets. */
19
+ cardId: string;
20
+ existingId?: string;
21
+ /**
22
+ * `row`: a formula over row fields the card aggregates as a whole
23
+ * (AVG(duration_ms / 1000)), its inputs as given; otherwise each input
24
+ * carries its aggregate (P0-02).
25
+ */
26
+ stage?: 'row';
27
+ /**
28
+ * Store the formula as written, inputs bare (`measureKeepsBareInputs`):
29
+ * an existing measure stored that way keeps it, because a card copy
30
+ * without an alias is named by its formula's first function, and
31
+ * writing the aggregates in would rename its result column.
32
+ */
33
+ asWritten?: true;
34
+ } | {
35
+ kind: 'dimension';
36
+ name: string;
37
+ expression: string;
38
+ inputFields: Array<Field | GroupByField | MetricField>;
39
+ dataType: DataType;
40
+ cardId: string;
41
+ existingId?: string;
42
+ };
43
+ /**
44
+ * The stage an edited measure keeps: a field the card aggregates as a whole
45
+ * (an agent's or the domain's row formula, `computeStage: 'row'`) stays one
46
+ * while its new formula has no aggregate (P0-02); otherwise undefined, and
47
+ * each input carries its aggregate.
48
+ */
49
+ export declare function measureStageOnEdit(existing: Field | undefined, expression: string): 'row' | undefined;
50
+ /**
51
+ * A measure's formula with each bare input written inside the aggregate the
52
+ * input carries (`{field_0} / {field_1}` over SUMs is `SUM({field_0}) /
53
+ * SUM({field_1})`): the formula shows what it computes, and the query builder
54
+ * runs the same SQL, because it wraps a bare metric input in that aggregate
55
+ * (calculated fields one core P0-02, as the editor's preset operations
56
+ * already write theirs). Left as written where the builder treats the input
57
+ * otherwise: a window or a FILTER, an input both inside and outside an
58
+ * aggregate, COUNT(*), a calculated input, an input with its own filters, or
59
+ * an aggregate the builder renders per database (MEDIAN).
60
+ */
61
+ export declare function writeInputAggregates(expression: string, inputFields: readonly Field[]): string;
62
+ /**
63
+ * Whether an edited measure keeps its formula as written: one stored with a
64
+ * bare input its aggregate would wrap (saved before P0-02) stays that way.
65
+ */
66
+ export declare function measureKeepsBareInputs(existing: Field | undefined): boolean;
67
+ /**
68
+ * The stored definition for a formula the editor or an agent states. A
69
+ * measure over aggregates is stored with its inputs' aggregates written in
70
+ * (`writeInputAggregates`), so the dialog and the MCP save one shape.
71
+ */
72
+ export declare function buildCalculatedFieldDefinition(input: CalculatedFieldDefinitionInput): MetricField | GroupByField;
73
+ /** A stored definition in the words a change states it in (`calculation.add`), for the outline (MC-INV-3). */
74
+ export type CalculatedFieldWords = {
75
+ name: string;
76
+ label?: string;
77
+ description?: string;
78
+ /** Named `{token}`s over `inputs`. */
79
+ expression: string;
80
+ inputs: Record<string, {
81
+ dataset: string;
82
+ field: string;
83
+ aggregate?: AggregateFunction;
84
+ }>;
85
+ use: 'aggregate' | 'group_or_filter';
86
+ dataType: string;
87
+ };
88
+ /**
89
+ * A stored definition read back in the change's words: each input named by
90
+ * its field (the field name, a suffix when two inputs share it), the formula
91
+ * in those names. Undefined for a definition whose formula names an input it
92
+ * doesn't have, or an input that is itself calculated.
93
+ */
94
+ export declare function readCalculatedFieldDefinition(field: Field): CalculatedFieldWords | undefined;
95
+ /**
96
+ * Creates a new calculated field from user inputs
97
+ * IMPORTANT: Both expression and calculatedFormula are generated atomically
98
+ * from the same inputs, preventing drift.
99
+ */
100
+ export declare function createCalculatedField(name: string, operation: CalculatedFieldOperation, metricA: MetricField | null, metricB: MetricField | null, _formatConfig: {
101
+ format: string;
102
+ decimalPlaces: number;
103
+ }, // Reserved for future use
104
+ cardId: string, existingId?: string, customExpression?: string, // For custom operations
105
+ constantFactor?: number, // For scale operation
106
+ customInputFields?: MetricField[]): MetricField;
107
+ export declare function createCalculatedDimension(name: string, expression: string, inputFields: Array<Field | GroupByField | MetricField>, dataType: DataType, cardId: string, existingId?: string): GroupByField;
108
+ /** The dialog's inputs for a measure's formula: each a measure, keeping an existing input's aggregate, else the model's default (calculated fields one core: one writer for the dialog and the MCP). */
109
+ export declare function buildMetricInputFieldsForExpression(inputFields: Array<Field | MetricField | GroupByField>, existingField?: MetricField): MetricField[];
110
+ /**
111
+ * A dashboard field from a formula the domain's compiler placed (MC-D5),
112
+ * written the way the editor's dialog writes one, so the MCP and the editor
113
+ * save the same JSON (MC-INV-1): each input is the field list's own catalog
114
+ * field (`catalog`, by name) with the dialog's keys; a dimension and a
115
+ * formula over aggregates go through `buildCalculatedFieldDefinition`. A row
116
+ * formula used as a measure keeps the compiler's meaning: the card aggregates
117
+ * the whole formula (`computeStage: 'row'`, inputs without aggregates), a
118
+ * shape the dialog builds only by placing a dimension as a measure (P0-02).
119
+ */
120
+ export declare function dashboardFieldFromCompiled(input: {
121
+ compiled: Field;
122
+ kind: 'measure' | 'dimension';
123
+ stage: 'row' | 'aggregate';
124
+ catalog: readonly Field[];
125
+ name: string;
126
+ label?: string;
127
+ description?: string;
128
+ id: string;
129
+ }): MetricField | GroupByField;
@@ -0,0 +1,46 @@
1
+ import { TCard, TDashboard } from '../../../lib/types/common-types.js';
2
+ import { Field } from '../../../lib/types/explorer-types.js';
3
+ /**
4
+ * A dashboard field's definition wins at run time (calculated fields one
5
+ * core MC-D21): every copy of a dashboard field, wherever it is stored (a
6
+ * card's shelves, sorts, card and inline filters, a dashboard filter's field,
7
+ * a filter value, a saved default, a bookmark, another field's inputs), is its
8
+ * placement plus a cached formula. Before a query is built, each copy is
9
+ * rebuilt from the dashboard's current definition; the copy keeps its own
10
+ * place (id, alias, aggregate, label, role, format, sort). A copy whose
11
+ * definition is gone runs as stored. Pure and in memory (MC-INV-4).
12
+ */
13
+ export type DashboardFieldDefinitions = readonly Field[];
14
+ /**
15
+ * The copy contract (MC-D21): what a copy of a dashboard field takes from the
16
+ * field, and what stays the placement's. The field owns its formula: the
17
+ * `expression`, the `calculatedFormula` (operation and inputs) and its data
18
+ * type. Everything else is the placement's and stays as the copy holds it:
19
+ * id, alias, role, aggregate, label, format, date grain, sort direction,
20
+ * comparison, parameters (their nested copies resolved where they are), the
21
+ * name a column is keyed by, and the stage a placement gave it (a dimension
22
+ * used as a measure). On an update (`previous`, the field before it), what
23
+ * the copy inherited unchanged from the old field (its name, label, format,
24
+ * description) follows the new one; what a placement wrote ("Count of Tier",
25
+ * an automatic date format, an author's rename) stays.
26
+ */
27
+ export declare function withDefinitionFormula<T extends Field>(copy: T, definition: Field, previous?: Field): T;
28
+ /** A field description another field embeds as an input: the input's name, formula and type follow its field; its own place stays. */
29
+ export declare const rewriteFieldMeta: (meta: Field, definition: Field) => Field;
30
+ /**
31
+ * A copy on a card's shelf keeps the result column its stored formula named
32
+ * (MC-D22): one without an alias is named by its formula, so a rebuilt
33
+ * formula would move it, and the table settings keyed by it.
34
+ */
35
+ export declare function withStoredResultKey(copy: Field, resolved: Field): Field;
36
+ /** A value's dashboard-field copies rebuilt from these definitions; the same value when it holds none or all are current. */
37
+ export declare function resolveDashboardFieldCopies<T>(value: T, definitions: DashboardFieldDefinitions | undefined): T;
38
+ /**
39
+ * A dashboard with every copy rebuilt from `definitions` (its own fields by
40
+ * default): its cards, its filters and its saved defaults (its definitions
41
+ * list stays as stored). Memoized per dashboard and definitions list, so the card query
42
+ * assembly pays for it once per dashboard.
43
+ */
44
+ export declare function resolveDashboardFieldCopiesIn(dashboard: TDashboard, definitions?: DashboardFieldDefinitions | undefined): TDashboard;
45
+ /** One card with its copies rebuilt (a card the editor holds outside the dashboard). */
46
+ export declare const resolveCardFieldCopies: (card: TCard, definitions: DashboardFieldDefinitions | undefined) => TCard;
@@ -0,0 +1,36 @@
1
+ /** Every token in the formula, in order of appearance, repeats included. */
2
+ export declare function readFormulaTokens(expression: string): string[];
3
+ /** A token with its offsets: `start` at its `{`, `end` at its `}`. */
4
+ export type FormulaTokenSpan = {
5
+ token: string;
6
+ raw: string;
7
+ start: number;
8
+ end: number;
9
+ };
10
+ /**
11
+ * Everything written in braces, whatever it holds, with its offsets: what a
12
+ * validator reads to refuse a token that isn't an input (`{orders.amount}`,
13
+ * `{ field_0 }`). `token` is the trimmed text, `raw` the braces as written.
14
+ * Quoted text is skipped, as everywhere else.
15
+ */
16
+ export declare function readBraceSpans(expression: string): FormulaTokenSpan[];
17
+ /** The input index an indexed token names (`field_3` → 3), else undefined. */
18
+ export declare function indexOfToken(token: string): number | undefined;
19
+ /** Each token replaced by what `replace` returns for it; quoted text untouched. */
20
+ export declare function mapFormulaTokens(expression: string, replace: (token: string) => string): string;
21
+ /**
22
+ * Named tokens to indexed: `{key}` becomes `{field_i}` where i is the key's
23
+ * position in `inputNames`. A token not in the list is kept as written.
24
+ */
25
+ export declare function toIndexedTokens(expression: string, inputNames: readonly string[]): string;
26
+ /**
27
+ * Indexed tokens to named: `{field_N}` becomes `{name}` for the name
28
+ * `nameAt(N)` gives. A token it gives no name for, or a named token, is kept.
29
+ */
30
+ export declare function toNamedTokens(expression: string, nameAt: (index: number) => string | undefined): string;
31
+ /**
32
+ * The editor's save step: tokens an author typed (a field's label or name in
33
+ * braces, any case, spaces allowed) become `{field_i}` by their position in
34
+ * `orderedTokens`, the typed tokens as the editor resolved them.
35
+ */
36
+ export declare function indexTypedTokens(expression: string, orderedTokens: readonly string[]): string;
@@ -89,6 +89,14 @@ export declare function writeAxisConfig(preferences: TCardPreferences | undefine
89
89
  * labels and position are kept as they are.
90
90
  */
91
91
  export declare function writeComparisonDisplay(preferences: TCardPreferences | undefined, display: ResolvedComparisonDisplay): TCardPreferences;
92
+ /**
93
+ * The card's comparisons no longer saved hidden (compare-with CW-D28): the
94
+ * stored `showComparison` goes, and the presentation with it when nothing
95
+ * else is left. Each measure's own state says what it shows.
96
+ */
97
+ /** Whether a two-metric KPI compares its first metric with the second (compare-with CW-D29): `true` stored, the key removed when off. */
98
+ export declare function writeMetricPairComparison(preferences: TCardPreferences | undefined, on: boolean): TCardPreferences;
99
+ export declare function writeComparisonsUnhidden(preferences: TCardPreferences | undefined): TCardPreferences;
92
100
  /**
93
101
  * An edit of the comparison panel's fields, as the comparison panel and the
94
102
  * table's settings make it: what a word states (show, mode, precision)
@@ -1,6 +1,6 @@
1
1
  import { TCard } from '../../../lib/types/common-types.js';
2
2
  import { CardType } from '../changes/card-types.js';
3
- export type SettingName = 'columns.label' | 'columns.format' | 'columns.hidden' | 'columns.width' | 'orientation' | 'stack' | 'donut' | 'totals' | 'dataLabels' | 'legend' | 'axes' | 'highlights' | 'columns.polarity' | 'comparisonDisplay' | 'inheritComparison' | 'trend' | 'trendGrain' | 'seeRecords' | 'columnOrder' | 'columnFilters' | 'tableSearch';
3
+ export type SettingName = 'columns.label' | 'columns.format' | 'columns.hidden' | 'columns.width' | 'orientation' | 'stack' | 'donut' | 'totals' | 'dataLabels' | 'legend' | 'axes' | 'highlights' | 'columns.polarity' | 'comparisonDisplay' | 'trend' | 'trendGrain' | 'seeRecords' | 'columnOrder' | 'columnFilters' | 'tableSearch';
4
4
  export declare const SETTINGS_BY_KIND: Readonly<Record<CardType, readonly SettingName[]>>;
5
5
  export type CardSettingsKind = {
6
6
  type: CardType;
@@ -36,6 +36,7 @@ export type AxisInput = {
36
36
  export type LegendPosition = 'top' | 'bottom' | 'left' | 'right';
37
37
  /** How a card shows its comparisons (RC-D4): a patch of the card's one comparison display. */
38
38
  export type ComparisonDisplayInput = {
39
+ /** Retired (compare-with CW-D28): refused; a measure set to off shows none. */
39
40
  show?: boolean;
40
41
  mode?: 'difference' | 'percent_change' | 'both' | 'ratio';
41
42
  /** Decimals of a percent change or ratio, an integer 0 to 6; null returns to the surface's default. */
@@ -79,7 +80,7 @@ export type CardSettingsInput = {
79
80
  y?: AxisInput;
80
81
  };
81
82
  comparisonDisplay?: ComparisonDisplayInput;
82
- /** false: measures without a comparison of their own ignore the dashboard's; true removes the stored opt-out (RC-D16). */
83
+ /** Retired (compare-with CW-D18): refused; each measure's comparison says whether it follows the Date filter. */
83
84
  inheritComparison?: boolean;
84
85
  /** A KPI's Trend switch (KPI trend window KT-D16): on draws its trend on the date it counts (KT-D1); off follows the summary and target. */
85
86
  trend?: boolean;
@@ -16,7 +16,6 @@ export type ResolvedColumnSettings = {
16
16
  };
17
17
  /** Only the comparison display fields that change; precision null removes the stored precision (RC-D4). */
18
18
  export type ResolvedComparisonDisplay = {
19
- show?: boolean;
20
19
  mode?: ComparisonDisplayInput['mode'];
21
20
  precision?: number | null;
22
21
  };
@@ -51,8 +50,6 @@ export type ResolvedCardSettings = {
51
50
  remove?: string[];
52
51
  };
53
52
  comparisonDisplay?: ResolvedComparisonDisplay;
54
- /** Whether measures without a comparison of their own follow the dashboard's (RC-D16). */
55
- inheritComparison?: boolean;
56
53
  /** A KPI's Trend switch (KT-D16). */
57
54
  trend?: boolean;
58
55
  /** A KPI trend's grain (KT-D12); null returns it to Automatic. */