react-semaphor 0.1.601 → 0.1.602

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 (75) hide show
  1. package/dist/analytics-protocol/index.js +9 -9
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +7 -7
  4. package/dist/briefings/index.js +4 -4
  5. package/dist/chunks/{assistant-chat-BE0XXzZP.js → assistant-chat-BWF3GYip.js} +12 -12
  6. package/dist/chunks/{bookmark-impact-DXDAN5AY.js → bookmark-impact-BF3iRx5a.js} +3 -3
  7. package/dist/chunks/{bookmark-state-BMyB3Tb6.js → bookmark-state-CBSTdW6q.js} +4 -4
  8. package/dist/chunks/{card-filter-builder-CE0-YVN5.js → card-filter-builder-B8XHwMY6.js} +394 -394
  9. package/dist/chunks/{comparison-window-caption-Dxj2CHOa.js → comparison-window-caption-W83qB4V5.js} +4 -4
  10. package/dist/chunks/{dashboard-mJKPFRbb.js → dashboard-DG5EIYYB.js} +1 -1
  11. package/dist/chunks/{dashboard-briefing-launcher-CntwKyiZ.js → dashboard-briefing-launcher-CBSrhyWZ.js} +727 -718
  12. package/dist/chunks/{dashboard-controls-XO089DMg.js → dashboard-controls-D6ECO4N1.js} +15 -15
  13. package/dist/chunks/{dashboard-json-CQRiydUv.js → dashboard-json-DrJftBSL.js} +4 -4
  14. package/dist/chunks/{dates-B-Urp5OD.js → dates-Bz-qM5px.js} +10 -10
  15. package/dist/chunks/{edit-dashboard-visual-f-Dm-BLR.js → edit-dashboard-visual-BDYAJIbb.js} +1565 -1544
  16. package/dist/chunks/{filter-line-CKNMyNTQ.js → filter-line-BXT6y303.js} +6 -6
  17. package/dist/chunks/{filter-reach-copy-B8GGyVuR.js → filter-reach-copy-BukhZmzm.js} +1661 -1950
  18. package/dist/chunks/{filter-value-text-CRtKecI5.js → filter-value-text-D3-bf3_b.js} +4 -4
  19. package/dist/chunks/{index-DoPApnxg.js → index-BW0yozjs.js} +5 -5
  20. package/dist/chunks/{layout-grid-CiSCZdIr.js → layout-grid-Ds0diMeY.js} +1 -1
  21. package/dist/chunks/{matrix-analytical-definition-myf3D3Qx.js → matrix-analytical-definition-CgQgVeeI.js} +4 -4
  22. package/dist/chunks/{matrix-member-presentation-g0c_NpDW.js → matrix-member-presentation-DSBIIudt.js} +1 -1
  23. package/dist/chunks/{matrix-operation-contract-C1SuOHLZ.js → matrix-operation-contract--DkNCOzd.js} +517 -514
  24. package/dist/chunks/{metric-comparison-Cm0G893W.js → metric-comparison-zMylnIkc.js} +1 -1
  25. package/dist/chunks/{paintbrush-DQIwqlck.js → paintbrush-CX8pao1j.js} +1 -1
  26. package/dist/chunks/{palette-Cun747Rg.js → palette-CuA0HlzF.js} +1 -1
  27. package/dist/chunks/{pivot-result-contract-expectations-C1Dyx8du.js → pivot-result-contract-expectations-C8KL7hPx.js} +8 -8
  28. package/dist/chunks/{pivot-result-identity-CBS-ssEp.js → pivot-result-identity-C1AOH1PS.js} +1 -1
  29. package/dist/chunks/{raw-temporal-value-DN_l-Tss.js → raw-temporal-value-E416F-0L.js} +1 -1
  30. package/dist/chunks/{report-preferences-dialog-SDZEcG2x.js → report-preferences-dialog-CbuVNDGi.js} +13 -13
  31. package/dist/chunks/{report-runtime-context-BbedQdtc.js → report-runtime-context-E7USjN7E.js} +1 -1
  32. package/dist/chunks/{resolve-dashboard-input-context-DRBS0eRa.js → resolve-dashboard-input-context-CULCE_hM.js} +8417 -7052
  33. package/dist/chunks/{save-Dj5bjm7P.js → save-BKHlDONy.js} +1 -1
  34. package/dist/chunks/{saved-dashboard-context-DWVlJcsa.js → saved-dashboard-context-C1WlOx5z.js} +32 -32
  35. package/dist/chunks/{selection-filter-compiler-DmAr7yqC.js → selection-filter-compiler-ifT8JCXS.js} +1 -1
  36. package/dist/chunks/{semaphor-ready-indicator-OFOoAY-A.js → semaphor-ready-indicator-CBIRcDWs.js} +33414 -31523
  37. package/dist/chunks/{shelf-drop-preview-context-2swWypXu.js → shelf-drop-preview-context-xR69SMA8.js} +53 -53
  38. package/dist/chunks/{stored-dashboard-NtOuEX6a.js → stored-dashboard-BuM8vnWf.js} +739 -717
  39. package/dist/chunks/{style-sheet-parts-Qv4UcLAo.js → style-sheet-parts-Bt9ZNre8.js} +2 -2
  40. package/dist/chunks/{table-export-sheet-Do7ZB0_F.js → table-export-sheet-DVljtHkG.js} +1 -1
  41. package/dist/chunks/{token-types-Dy_aXO-U.js → token-types-D_xKgyVS.js} +1 -1
  42. package/dist/chunks/{upload-Bq-puSVy.js → upload-Dll_M7XQ.js} +1 -1
  43. package/dist/chunks/{validators-C7DFk3QK.js → validators-ClWHpYql.js} +2 -2
  44. package/dist/chunks/{variable-draft-Cy03qnEi.js → variable-draft-CDGGl53R.js} +27 -28
  45. package/dist/dashboard/index.js +2 -2
  46. package/dist/dashboard-authoring/index.js +3086 -2578
  47. package/dist/format-utils/index.js +14 -14
  48. package/dist/index.js +71 -73
  49. package/dist/report-runtime-context/index.js +1 -1
  50. package/dist/style.css +1 -1
  51. package/dist/surfboard/index.js +2 -2
  52. package/dist/types/components/dashboard/dashboard-web-component.d.ts +7 -0
  53. package/dist/types/index.js +5 -5
  54. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +1 -1
  55. package/dist/types/lib/query-context/assemble-card-query.d.ts +6 -1
  56. package/dist/types/lib/stores/dashboard-store.d.ts +30 -0
  57. package/dist/types/shared/analytics-protocol/aggregate-expression.d.ts +15 -0
  58. package/dist/types/shared/dashboard-authoring/calculations/calculated-column.d.ts +52 -0
  59. package/dist/types/shared/dashboard-authoring/calculations/definition.d.ts +129 -0
  60. package/dist/types/shared/dashboard-authoring/calculations/resolve-dashboard-field-copies.d.ts +46 -0
  61. package/dist/types/shared/dashboard-authoring/calculations/tokens.d.ts +36 -0
  62. package/dist/types/shared/dashboard-authoring/changes/calculation-change.d.ts +399 -0
  63. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +144 -2
  64. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +21 -2
  65. package/dist/types/shared/dashboard-authoring/changes/domain-change.d.ts +143 -266
  66. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +2 -0
  67. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +46 -0
  68. package/dist/types/shared/dashboard-authoring/index.d.ts +7 -1
  69. package/dist/types/shared/dashboard-authoring/operations/calculated-field-operations.d.ts +133 -0
  70. package/dist/types/shared/dashboard-authoring/operations/card-operations.d.ts +71 -0
  71. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +18 -5
  72. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +21 -0
  73. package/dist/types/shared/usage-events/details.d.ts +2 -2
  74. package/dist/types/shared/usage-events/envelope.d.ts +2 -2
  75. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { a, R as s, D as o } from "../chunks/report-preferences-dialog-SDZEcG2x.js";
2
- import { C as f, E as D } from "../chunks/bookmark-state-BMyB3Tb6.js";
1
+ import { a, R as s, D as o } from "../chunks/report-preferences-dialog-CbuVNDGi.js";
2
+ import { C as f, E as D } from "../chunks/bookmark-state-CBSTdW6q.js";
3
3
  export {
4
4
  f as CONTROL_CARD_DEFAULT_VALUE,
5
5
  a as DisplayFormatPreferencesFields,
@@ -1 +1,8 @@
1
+ /**
2
+ * The dashboard as a custom element, for a host to register in the browser
3
+ * (`customElements.define('semaphor-dashboard', DashboardWC)`). Built only
4
+ * where `HTMLElement` exists: the class extends it, and a server that imports
5
+ * this package (a host's server render) has no DOM and registers no elements,
6
+ * so there it is undefined. The build's server import check guards this.
7
+ */
1
8
  export declare const DashboardWC: CustomElementConstructor;
@@ -1,8 +1,8 @@
1
- import { B as t, z as r, C as l, E as o, V as i, j as n, c as d, g as m, f as u, b as c, e as E, d as C, a as T, y as p, x as D, o as A, h as I, q as _, w as F, v as S, m as b, n as L, l as f, p as N, k as y, s as R, u as h, i as g, r as x, t as M } from "../chunks/bookmark-state-BMyB3Tb6.js";
2
- import { C as V, D as w, L as z, d as U, g as k, e as B, h as K, f as v, c as Y, a as q, i as G, b as P, n as Q, s as W } from "../chunks/validators-C7DFk3QK.js";
3
- import { D as J } from "../chunks/token-types-Dy_aXO-U.js";
4
- import { r as H, a as Z } from "../chunks/pivot-result-identity-CBS-ssEp.js";
5
- import { D as ee } from "../chunks/report-runtime-context-BbedQdtc.js";
1
+ import { B as t, z as r, C as l, E as o, V as i, j as n, c as d, g as m, f as u, b as c, e as E, d as C, a as T, y as p, x as D, o as A, h as I, q as _, w as F, v as S, m as b, n as L, l as f, p as N, k as y, s as R, u as h, i as g, r as x, t as M } from "../chunks/bookmark-state-CBSTdW6q.js";
2
+ import { C as V, D as w, L as z, d as U, g as k, e as B, h as K, f as v, c as Y, a as q, i as G, b as P, n as Q, s as W } from "../chunks/validators-ClWHpYql.js";
3
+ import { D as J } from "../chunks/token-types-D_xKgyVS.js";
4
+ import { r as H, a as Z } from "../chunks/pivot-result-identity-C1AOH1PS.js";
5
+ import { D as ee } from "../chunks/report-runtime-context-E7USjN7E.js";
6
6
  const e = [
7
7
  "concatenate",
8
8
  "conditional-category",
@@ -79,7 +79,7 @@ export type DashboardInputTargetContext = {
79
79
  knownFilterIds: ReadonlySet<string>;
80
80
  };
81
81
  export type BuildDashboardInputTargetContextInput = {
82
- dashboard: Pick<TDashboard, 'inputs' | 'filters' | 'controls' | 'sheets' | 'defaultInputValues'>;
82
+ dashboard: Pick<TDashboard, 'inputs' | 'filters' | 'controls' | 'sheets' | 'defaultInputValues' | 'calculatedFields'>;
83
83
  filter: TFilter;
84
84
  scope: DashboardInputTargetScope;
85
85
  /** The card a card-local target belongs to; lifts its inline inputs. */
@@ -1,7 +1,7 @@
1
1
  import { TFilterValue } from '../../components/surfboard/filter/types.js';
2
2
  import { CardViewStateMap } from '../dashboard-view-state/index.js';
3
3
  import { DashboardInputValues, ResolvedDashboardInputContext, TCard, TDashboard } from '../types/common-types.js';
4
- import { PaginationConfig } from '../types/explorer-types.js';
4
+ import { Field, PaginationConfig } from '../types/explorer-types.js';
5
5
  import { ResolvedPrimaryDateField, SemanticExecutionPayload } from '../types/semantic-runtime-types.js';
6
6
  import { TransientInputContext } from '../dashboard-inputs/transient-input-context.js';
7
7
  import { prepareMatrixCard, MatrixCardCatalog } from '../matrix-table/matrix-card-adapter.js';
@@ -63,6 +63,11 @@ export type CardQuerySource = {
63
63
  */
64
64
  editor?: {
65
65
  inlineFilterValuesMap: Record<string, TFilterValue[] | undefined>;
66
+ /**
67
+ * The dashboard fields as the editor holds them (its pending list while a
68
+ * card is open): the preview runs the definitions being edited (MC-D21).
69
+ */
70
+ calculatedFields?: readonly Field[];
66
71
  };
67
72
  };
68
73
  /** Where a card runs: a sheet of the dashboard, or a Document section with its own runtime. */
@@ -11,6 +11,7 @@ import { MissingPrintInputs } from '../print/print-inputs.js';
11
11
  import { default as ReactGridLayout } from 'react-grid-layout';
12
12
  import { CustomizableBreakpoint, EditableBreakpoint, FramePlacement, GridEditBreakpoint, LayoutItem } from '../../shared/layouts/index.js';
13
13
  import { DashboardOperation, OperationContext } from '../../shared/dashboard-authoring/operations/apply-dashboard-operations.js';
14
+ import { CalculatedFieldOperation } from '../../shared/dashboard-authoring/operations/calculated-field-operations.js';
14
15
  import { DashboardStyle } from '../../shared/dashboard-authoring/dashboard-style/types.js';
15
16
  import { FilterGroup, Field } from '../types/explorer-types.js';
16
17
  import { DashboardControlsModelOptions } from '../controls/control-authoring-types.js';
@@ -40,6 +41,12 @@ type AddFrameOptions = {
40
41
  /** By intent; absent: placed by kind (RL-D12). A duplicate passes `{ position: { beside: originalId } }`. */
41
42
  placement?: FramePlacement;
42
43
  semanticExecutionPayload?: SemanticExecutionPayload;
44
+ /**
45
+ * The frame is the visual editor's card saved as a copy (Save as): the
46
+ * editor's queued dashboard-field changes commit with it, all or nothing,
47
+ * and a refusal throws its reason with nothing changed (ledger P4-49).
48
+ */
49
+ withEditorFieldChanges?: boolean;
43
50
  };
44
51
  /**
45
52
  * A proposal the assistant applied in this edit session (analytics agent
@@ -162,6 +169,8 @@ export type DashboardStore = {
162
169
  * current frame.
163
170
  */
164
171
  visualEditPendingDashboardCalculatedFields?: Field[];
172
+ /** The dashboard-field operations the open card's edit made, applied with its commit (calculated fields one core MC-D11). */
173
+ visualEditPendingCalculatedFieldOps?: CalculatedFieldOperation[];
165
174
  /** Live edit-session check for host navigation; owned by dashboard controls. */
166
175
  checkUnsavedDashboardChanges: (() => boolean) | null;
167
176
  isDashboardEditing: boolean;
@@ -473,6 +482,27 @@ type Actions = {
473
482
  }) => void;
474
483
  updateSheetCalculatedFields: (sheetId: string, calculatedFields: Field[]) => void;
475
484
  updateDashboardCalculatedFields: (calculatedFields: Field[]) => void;
485
+ /** Whether the field changes a Document section card's edit made would apply with that card committed; asked before writing it. */
486
+ checkCalculatedFieldOps: (card: TCard, replacingCardId: string) => {
487
+ ok: true;
488
+ } | {
489
+ ok: false;
490
+ reason: string;
491
+ };
492
+ /** Whether `addFrame` with these options would apply, nothing changed: Save as asks before it creates a library visual (ledger P4-50). */
493
+ checkAddFrame: (sheetId: string, frame: TFrame, options?: AddFrameOptions) => {
494
+ ok: true;
495
+ } | {
496
+ ok: false;
497
+ reason: string;
498
+ };
499
+ /** Applies the field changes a Document section card's edit made, after its commit. */
500
+ commitCalculatedFieldOps: (editedCardId: string) => {
501
+ ok: true;
502
+ } | {
503
+ ok: false;
504
+ reason: string;
505
+ };
476
506
  setVisualEditPendingFrameRewrites: (sheetId: string, frames: TFrame[]) => void;
477
507
  clearVisualEditPendingFrameRewrites: (sheetId?: string) => void;
478
508
  updateCard: (sheetId: string, card: TCard) => void;
@@ -38,6 +38,12 @@ export type ScannedAggregateCall = {
38
38
  };
39
39
  argumentCount: number;
40
40
  filtered: boolean;
41
+ /** Each FILTER (...) or OVER (...) after the call: the offsets inside its parentheses. */
42
+ suffixes: Array<{
43
+ kind: 'filter' | 'over';
44
+ start: number;
45
+ end: number;
46
+ }>;
41
47
  };
42
48
  export type ScannedAggregateExpression = {
43
49
  calls: ScannedAggregateCall[];
@@ -46,6 +52,15 @@ export type ScannedAggregateExpression = {
46
52
  windowed: boolean;
47
53
  /** Input tokens that occur outside every aggregate call, in order. */
48
54
  tokensOutsideAggregates: string[];
55
+ /**
56
+ * Each OVER (...) after a call that is not an aggregate (LAG, RANK,
57
+ * ROW_NUMBER, ...): the offsets inside its parentheses. An aggregate's own
58
+ * OVER is in its call's `suffixes`.
59
+ */
60
+ windowClauses: Array<{
61
+ start: number;
62
+ end: number;
63
+ }>;
49
64
  /** All data reads belong to recognized aggregate calls; the rest consists
50
65
  * only of literals, operators and understood scalar composition. */
51
66
  aggregateInputsComplete: boolean;
@@ -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 runs it as stored), 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;