@toclocoinc/lattice-grid 1.25.0 → 1.27.0

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.
package/lattice-grid.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Lattice Grid 1.25.0, type declarations
2
+ * Lattice Grid 1.27.0, type declarations
3
3
  * Copyright (c) 2026 TOCLOCO Inc. All rights reserved.
4
4
  * https://latticegrid.dev
5
5
  */
@@ -642,6 +642,12 @@ export interface Column {
642
642
  * `'filtered'` ranks within what the filters left.
643
643
  */
644
644
  scope?: 'all' | 'filtered';
645
+ /**
646
+ * For `kind: 'anomalyFlag'`, the modified-z score a row must clear to be
647
+ * flagged an anomaly. Default 3.5 (Iglewicz & Hoaglin). Ignored by
648
+ * `anomalyScore`, which reports the raw score, and by the other kinds.
649
+ */
650
+ threshold?: number;
645
651
  /**
646
652
  * For `kind: 'specStatus'`, the hard specification the row is judged
647
653
  * against. `lower`/`upper` are the pass limits (a value beyond either
@@ -1144,6 +1150,15 @@ export interface OpenWrite {
1144
1150
  age: number;
1145
1151
  }
1146
1152
 
1153
+ /** A structural op (append or delete) still awaiting an outcome (§5.3). */
1154
+ export interface OpenRowOp {
1155
+ id: string;
1156
+ kind: 'append' | 'delete';
1157
+ key: string;
1158
+ state: 'pending' | 'superseded';
1159
+ age: number;
1160
+ }
1161
+
1147
1162
  /**
1148
1163
  * What an adapter can persist back to its source — the write-back capability
1149
1164
  * (§4.1), declared on `AdapterCapabilities.mutate`. `false` (the default) is
@@ -1151,11 +1166,11 @@ export interface OpenWrite {
1151
1166
  * adapter opts in.
1152
1167
  */
1153
1168
  export interface MutateCapability {
1154
- /** The adapter can insert new rows. Wave 1: declared, not yet bridged. */
1169
+ /** The adapter can insert new rows, bridged by the structural engine (`edit.addRow`, §5.3). */
1155
1170
  append?: boolean;
1156
- /** The adapter can patch existing rows. Wave 1: the wired kind (§4.3 Option A). */
1171
+ /** The adapter can patch existing rows, bridged by the cell edit path (§4.3 Option A). */
1157
1172
  update?: boolean;
1158
- /** The adapter can remove rows. Wave 1: declared, not yet bridged. */
1173
+ /** The adapter can remove rows, bridged by the structural engine (`edit.deleteRow`, §5.3). */
1159
1174
  delete?: boolean;
1160
1175
  /**
1161
1176
  * The reconcile contract — what the server hands back after a successful
@@ -1319,6 +1334,19 @@ export interface GridConfig {
1319
1334
  */
1320
1335
  columnTagFilter?: boolean | { multiple?: boolean; label?: string };
1321
1336
 
1337
+ /**
1338
+ * Show a small chip in the grid chrome that reads how many rows an anomaly
1339
+ * shadow column has flagged, and filters the grid to exactly those when it is
1340
+ * clicked (BACKLOG-0000799).
1341
+ *
1342
+ * Off by default, and it draws nothing unless a column declares a
1343
+ * `shadow: { kind: 'anomalyFlag' }`. The count and the filter both read that
1344
+ * one shadow column, so the number on the chip is the number of rows the
1345
+ * click reveals. `column` names the base column to summarise when more than
1346
+ * one anomaly-flag shadow is present; `label` overrides the chip's wording.
1347
+ */
1348
+ anomalySummary?: boolean | { column?: string; label?: string };
1349
+
1322
1350
  /**
1323
1351
  * Open a row on a form when it is double-clicked.
1324
1352
  *
@@ -1917,6 +1945,18 @@ export interface GridConfig {
1917
1945
  /** Placeholder shown while nothing is grouped. */
1918
1946
  hint?: string;
1919
1947
  };
1948
+ /**
1949
+ * A built-in KPI/stat strip: a labelled band of {@link createStat} tiles the
1950
+ * grid places for you, above the column header. Each entry is a stat spec —
1951
+ * the same fields {@link StatConfig} takes, minus `grid` and `container`,
1952
+ * which the grid supplies — so a strip tile and a hand-placed one are the same
1953
+ * object. The tiles follow the grid's filters, recomputing on every change
1954
+ * exactly as a stand-alone stat does.
1955
+ *
1956
+ * Off by default and non-breaking, matching `groupPanel`: no `kpis` means no
1957
+ * band and no cost. It reuses `createStat` and reimplements no compute.
1958
+ */
1959
+ kpis?: Array<Omit<StatConfig, 'grid' | 'container'>>;
1920
1960
  /** The quick filter's initial text. */
1921
1961
  quickFilterText?: string;
1922
1962
  /**
@@ -2362,6 +2402,17 @@ export interface StatisticsApi {
2362
2402
  reduce(colId: string, fn: string): unknown;
2363
2403
  /** Everything worth knowing about one column, in one pass each. */
2364
2404
  profile(colId: string): ColumnProfile | null;
2405
+ /**
2406
+ * The rows that do not belong (BACKLOG-0000749): anomaly detection over the
2407
+ * filtered rows by the robust modified z-score (`modifiedZScore`, the
2408
+ * default), Tukey's IQR fences (`iqr`), or multivariate Mahalanobis distance
2409
+ * over the chosen columns (`mahalanobis`). Every flagged row carries the score
2410
+ * behind it and the reason for it, so a flag is explainable rather than a
2411
+ * verdict from nowhere. Non-numeric columns are returned under `skipped`.
2412
+ */
2413
+ anomalies(opts?: { columns?: string[];
2414
+ method?: 'modifiedZScore' | 'iqr' | 'mahalanobis';
2415
+ threshold?: number; k?: number; p?: number }): AnomalyReport;
2365
2416
  /**
2366
2417
  * Which columns differ most between the filtered subset and the whole
2367
2418
  * population it was drawn from, ranked by effect size — never by a p-value.
@@ -2381,6 +2432,20 @@ export interface StatisticsApi {
2381
2432
  * on one side alone is returned under `unmatched`.
2382
2433
  */
2383
2434
  datasetVsDataset(other: Grid, opts?: { columns?: string[] }): DatasetComparison;
2435
+ /**
2436
+ * Is the difference between two groups real? A two-sample test returned as
2437
+ * data to interpret — never a verdict (BACKLOG-0000750). The significance
2438
+ * boundary the comparison story (653, 735) stopped short of: those rank by how
2439
+ * *much* columns differ and return no p-value; this answers *how sure* for one
2440
+ * chosen pair of groups and hands the p-value back as data. There is no
2441
+ * `significant` flag, no badge, and no multiple-comparison correction. The
2442
+ * rows are split by `opts.by`, the test is chosen by the column's family and
2443
+ * named in the result (overridable with `opts.test`): Welch's t or
2444
+ * Mann-Whitney U for a numeric column, chi-square for a categorical one. Every
2445
+ * result pairs a confidence interval on the difference with the effect size,
2446
+ * so it is always "how big and how sure".
2447
+ */
2448
+ compareGroups(colId: string, opts: TwoSampleSpec): GroupComparison | null;
2384
2449
  /** Pearson's correlation between two columns. */
2385
2450
  correlation(a: string, b: string): number | null;
2386
2451
  /** Covariance, a correlation before the scales are divided out. */
@@ -2549,12 +2614,64 @@ export function openWindow(
2549
2614
  now?: () => number,
2550
2615
  ): Window;
2551
2616
 
2617
+ /**
2618
+ * The anomaly-detection methods (BACKLOG-0000749): the robust univariate
2619
+ * modified z-score, Tukey's IQR fences, and multivariate Mahalanobis distance.
2620
+ * Interpretable statistics with written-down cuts, never a black box.
2621
+ */
2622
+ export const ANOMALY_METHODS: readonly ('modifiedZScore' | 'iqr' | 'mahalanobis')[];
2623
+
2624
+ /**
2625
+ * Per-row modified z-scores and flags for one column of readings — the robust
2626
+ * outlier score on the median and MAD (`0.6745·(x − median)/MAD`), flagged past
2627
+ * `threshold` (default 3.5). Robust to the outliers themselves: one wild reading
2628
+ * cannot inflate the spread and hide. A non-finite reading and a zero-MAD column
2629
+ * yield a null score and no flag rather than an invented one.
2630
+ */
2631
+ export function modifiedZScores(
2632
+ values: ArrayLike<number>,
2633
+ opts?: { threshold?: number },
2634
+ ): { median: number | null; mad: number | null; threshold: number;
2635
+ scores: (number | null)[]; flags: boolean[]; flagged: number };
2636
+
2637
+ /**
2638
+ * Tukey's fences for one column: `[Q1 − k·IQR, Q3 + k·IQR]` (default `k = 1.5`),
2639
+ * the same fence the box plot draws, with R type 7 quartiles. Null when there
2640
+ * are no readings.
2641
+ */
2642
+ export function iqrFences(
2643
+ values: ArrayLike<number>,
2644
+ opts?: { k?: number },
2645
+ ): { q1: number; q3: number; iqr: number; lower: number; upper: number; k: number } | null;
2646
+
2647
+ /**
2648
+ * Mahalanobis distance of every row from the joint centre, in the metric of the
2649
+ * data's own sample covariance, cut at a χ² quantile (default the 0.975 point).
2650
+ * Catches a row impossible only in combination, which a per-column scan misses.
2651
+ * A row with any missing coordinate gets a null distance; a singular covariance
2652
+ * is ridge-regularised and reported as `singular` rather than throwing.
2653
+ */
2654
+ export function mahalanobis(
2655
+ matrix: number[][],
2656
+ opts?: { p?: number; ridge?: number },
2657
+ ): { center: number[]; df: number; cutoff: number; singular: boolean; used: number;
2658
+ distances: (number | null)[]; squared: (number | null)[]; flags: boolean[];
2659
+ flagged: number } | null;
2660
+
2552
2661
  export type ShadowKind =
2553
2662
  | 'updates' | 'updatedAt' | 'sinceUpdate' | 'delta' | 'deltaPercent'
2554
2663
  | 'rate' | 'history' | 'firstValue' | 'streak'
2555
2664
  /** Where the row sits among the others, over every tracked row. */
2556
2665
  | 'rank' | 'rankAsc' | 'rankChange' | 'percentile' | 'quartile'
2557
2666
  | 'zScore' | 'shareOfTotal'
2667
+ /**
2668
+ * A robust outlier score and flag per row (BACKLOG-0000749): the modified
2669
+ * z-score on the median and MAD, and the boolean of whether it clears
2670
+ * `threshold` (default 3.5, read off the shadow declaration). Sortable,
2671
+ * filterable, groupable and exportable like any cell. Null where there is no
2672
+ * robust spread to score against.
2673
+ */
2674
+ | 'anomalyScore' | 'anomalyFlag'
2558
2675
  /**
2559
2676
  * The row's pass/fail verdict against a hard-limit spec, as a value:
2560
2677
  * `'PASS'`, `'WARN'` or `'FAIL'`. Sortable, filterable, groupable and
@@ -2703,6 +2820,69 @@ export interface SubsetComparison {
2703
2820
  measures: { numeric: string; categorical: string; common: string };
2704
2821
  }
2705
2822
 
2823
+ export interface AnomalyReason {
2824
+ /** The column that put this row over the line. */
2825
+ column: string;
2826
+ /** The column's display name, or its id. */
2827
+ name: string;
2828
+ /** The row's value in that column. */
2829
+ value: number;
2830
+ /** The modified z-score, for the `modifiedZScore` method. */
2831
+ score?: number;
2832
+ /** The lower fence, for the `iqr` method. */
2833
+ lower?: number;
2834
+ /** The upper fence, for the `iqr` method. */
2835
+ upper?: number;
2836
+ /** Which rule flagged it. */
2837
+ method?: 'modifiedZScore' | 'iqr';
2838
+ }
2839
+
2840
+ export interface AnomalyRow {
2841
+ /** The row key — stable across a sort or a feed, where the index is not. */
2842
+ rowKey: string | null;
2843
+ /** The physical row index at the time of the call. */
2844
+ index: number;
2845
+ /**
2846
+ * The row's headline score: its most extreme modified z-score across the
2847
+ * flagging columns (univariate), the Mahalanobis distance (multivariate), or
2848
+ * null for the IQR method, which has no single score.
2849
+ */
2850
+ score: number | null;
2851
+ /** The squared Mahalanobis distance, for the `mahalanobis` method. */
2852
+ squared?: number | null;
2853
+ /** Why this row was flagged: the columns and how far, so it is explainable. */
2854
+ why: AnomalyReason[];
2855
+ }
2856
+
2857
+ export interface AnomalyReport {
2858
+ /** Which rule produced the report. */
2859
+ method: 'modifiedZScore' | 'iqr' | 'mahalanobis';
2860
+ /** The IQR fence multiplier, for the `iqr` method. */
2861
+ k?: number;
2862
+ /** How many rows the scan ran over. */
2863
+ n: number;
2864
+ /** The flagged rows, worst first. */
2865
+ rows: AnomalyRow[];
2866
+ /** How many rows were flagged. */
2867
+ flagged: number;
2868
+ /** The column ids that were not numeric and so could not be scored. */
2869
+ skipped: string[];
2870
+ /** How many numeric columns were scored (univariate). */
2871
+ scored?: number;
2872
+ /** Per-column summaries (univariate): the centre, spread and fence per column. */
2873
+ columns?: unknown;
2874
+ /** The degrees of freedom of the χ² cut (multivariate). */
2875
+ df?: number;
2876
+ /** The χ² cut the squared distance is compared against (multivariate). */
2877
+ cutoff?: number | null;
2878
+ /** The joint centre the distances are measured from (multivariate). */
2879
+ center?: number[];
2880
+ /** How many complete rows defined the metric (multivariate). */
2881
+ used?: number;
2882
+ /** Whether the covariance was singular and had to be regularised (multivariate). */
2883
+ singular?: boolean;
2884
+ }
2885
+
2706
2886
  export interface DatasetColumnDifference {
2707
2887
  /** The column id, present on both grids. */
2708
2888
  column: string;
@@ -2744,6 +2924,92 @@ export interface DatasetComparison {
2744
2924
  measures: { numeric: string; categorical: string; common: string };
2745
2925
  }
2746
2926
 
2927
+ /** How {@link StatisticsApi.compareGroups} splits the rows and picks a test. */
2928
+ export interface TwoSampleSpec {
2929
+ /** The column whose values split the rows into groups. Required. */
2930
+ by: string;
2931
+ /** The two group values to compare. The two most frequent when omitted. */
2932
+ groups?: [unknown, unknown];
2933
+ /**
2934
+ * Force a test rather than choosing by column family. `auto` (the default)
2935
+ * picks Welch or Mann-Whitney for a numeric column and chi-square for a
2936
+ * categorical one; the choice is always named in the result.
2937
+ */
2938
+ test?: 'auto' | 'welch' | 'mannWhitney' | 'chiSquare';
2939
+ /** The confidence level for the interval, 0 to 1. 0.95 by default. */
2940
+ confidence?: number;
2941
+ /**
2942
+ * The focal category for a chi-square difference interval, when the column has
2943
+ * more than two categories. Without it, a multi-category comparison reports no
2944
+ * scalar interval, only the effect size.
2945
+ */
2946
+ category?: unknown;
2947
+ }
2948
+
2949
+ /** The effect size paired with a two-sample test — the "how big" half. */
2950
+ export interface GroupEffectSize {
2951
+ /**
2952
+ * The named measure: `pooledStandardMeanDifference` (Cohen's d) for the
2953
+ * numeric tests, `categoricalTotalVariation` for chi-square.
2954
+ */
2955
+ name: string;
2956
+ /** The effect size in its own terms, or null when it has no scale here. */
2957
+ value: number | null;
2958
+ }
2959
+
2960
+ /** A confidence interval on the difference a two-sample test measured. */
2961
+ export interface GroupDifferenceInterval {
2962
+ /** The point estimate of the difference the interval is around. */
2963
+ estimate: number;
2964
+ lower: number;
2965
+ upper: number;
2966
+ /** The level the bounds were computed at, 0 to 1. */
2967
+ confidence: number;
2968
+ /** The method, named for honesty: `welch-t`, `hodges-lehmann`, `newcombe`. */
2969
+ method: string;
2970
+ /** For a chi-square interval, which category's share the difference is of. */
2971
+ category?: unknown;
2972
+ }
2973
+
2974
+ /**
2975
+ * The result of {@link StatisticsApi.compareGroups}: how big *and* how sure, as
2976
+ * data to interpret. Carries no significance verdict — the p-value is a number,
2977
+ * never a flag or a badge.
2978
+ */
2979
+ export interface GroupComparison {
2980
+ /** The test used, named so it is never hidden. */
2981
+ test: 'welch' | 'mannWhitney' | 'chiSquare';
2982
+ /** Whether the test was chosen automatically or forced by the caller. */
2983
+ chosenBy: 'auto' | 'override';
2984
+ /** Why this test — the column family, a normality screen, or the override. */
2985
+ reason: string;
2986
+ /** The test statistic. */
2987
+ statistic: number;
2988
+ /** What the statistic is: `t`, `U`, or `chiSquare`. */
2989
+ statisticName: string;
2990
+ /** The degrees of freedom, where the test has them; null for Mann-Whitney. */
2991
+ df: number | null;
2992
+ /**
2993
+ * The two-sided p-value, returned as data for the caller to interpret. Never
2994
+ * thresholded into a verdict here.
2995
+ */
2996
+ pValue: number;
2997
+ /** The confidence interval on the difference, or null when there is none. */
2998
+ interval: GroupDifferenceInterval | null;
2999
+ /** The paired effect size, so the p-value is never read on its own. */
3000
+ effectSize: GroupEffectSize;
3001
+ /** How many rows the first group stood on. */
3002
+ nA: number;
3003
+ /** How many rows the second group stood on. */
3004
+ nB: number;
3005
+ /** The two group values compared, as keys. */
3006
+ groups: [unknown, unknown];
3007
+ /** False when either group is under the reliability floor. */
3008
+ reliable: boolean;
3009
+ /** The test's method, named per the reference-suite honesty rule. */
3010
+ method: string;
3011
+ }
3012
+
2747
3013
  export interface FormattingApi {
2748
3014
  list(scope?: FormattingScope): FormattingRule[];
2749
3015
  all(): Record<FormattingScope, FormattingRule[]>;
@@ -2809,6 +3075,7 @@ export type EventName =
2809
3075
  | 'cell:clicked' | 'cell:dblclicked' | 'cell:contextmenu'
2810
3076
  | 'cell:edit:start' | 'cell:edit:end' | 'row:edit:start' | 'row:edit:end'
2811
3077
  | 'row:clicked' | 'row:dblclicked'
3078
+ | 'row:pending' | 'row:confirmed' | 'row:reverted' | 'row:conflict'
2812
3079
  | 'form:opened' | 'form:closed' | 'form:saved' | 'form:error'
2813
3080
  /* Query */
2814
3081
  | 'sort:changed' | 'filter:changed' | 'group:toggled'
@@ -3138,6 +3405,20 @@ export interface EditApi {
3138
3405
  undo(): void;
3139
3406
  redo(): void;
3140
3407
  setCells(writes: { key: string; colId: string; value: unknown }[], type?: 'cell' | 'fill' | 'paste'): number;
3408
+ /**
3409
+ * Set one value across a block of cells as a single undoable step (§12, card
3410
+ * 740). Defaults to the selected range; read-only and non-editable cells are
3411
+ * skipped and every write runs the normal parse/validate path.
3412
+ */
3413
+ bulkSet(value: unknown, opts?: { cells?: { key: string; colId: string }[] }): number;
3414
+ /**
3415
+ * Fill a selected range from its leading edge as one undoable step (§12, card
3416
+ * 740). The default copies the anchor across the range (Excel's Ctrl+D and its
3417
+ * natural siblings); `series: true` extrapolates a numeric or date series from
3418
+ * the first one or two cells of each line, falling back to a copy for types
3419
+ * with no series. `direction` defaults to `'down'`.
3420
+ */
3421
+ fill(opts?: { direction?: 'down' | 'up' | 'left' | 'right'; series?: boolean; range?: CellRange }): number;
3141
3422
  pasteInto(anchor: { key: string; colId: string }, text: string, extent?: { rows?: number; columns?: number }): number;
3142
3423
  /** Whether a bulk paste is previewed before it commits (`edit.pastePreview`, §12). */
3143
3424
  readonly pastePreview: boolean;
@@ -3167,6 +3448,52 @@ export interface EditApi {
3167
3448
  ): boolean;
3168
3449
  pending(): OpenWrite[];
3169
3450
  status(key: string, colId: string): 'pending' | null;
3451
+ /**
3452
+ * Append a row to a remote source optimistically and persist it (§5.3), the
3453
+ * structural analog of the cell edit path. The row shows immediately under a
3454
+ * client temp key, and `adapter.mutate({ kind: 'append', rows: [row] })` is
3455
+ * asked to persist it; when the server returns the real key the row is rekeyed
3456
+ * everywhere the grid tracks it and `row:confirmed` fires, while a refused
3457
+ * append is removed and fires `row:reverted`. Only wired when the source
3458
+ * declares `mutate.append`; otherwise it warns once and returns null.
3459
+ * @param row the new row (it need not carry a key yet)
3460
+ * @returns the client temp key the row is tracked under, or null when append
3461
+ * is not available on this source
3462
+ */
3463
+ addRow(row: object): string | null;
3464
+ /**
3465
+ * Delete a row from a remote source optimistically and persist it (§5.3). The
3466
+ * row is tombstoned immediately and `adapter.mutate({ kind: 'delete', keys: [key] })`
3467
+ * is asked to remove it; on confirmation the row is purged and `row:confirmed`
3468
+ * fires, on refusal it is restored and `row:reverted` fires. Only wired when
3469
+ * the source declares `mutate.delete`; otherwise it warns once and returns null.
3470
+ * @param key the row key to remove
3471
+ * @returns the id the op is tracked under, or null when delete is not available
3472
+ */
3473
+ deleteRow(key: string): string | null;
3474
+ /**
3475
+ * Report the outcome of an optimistic structural write (§5.3), the counterpart
3476
+ * to {@link settle} for `edit.confirm: 'manual'` over a backend that
3477
+ * acknowledges an append/delete on a separate channel. The id arrives on
3478
+ * `row:pending`.
3479
+ * @param id the op id from `row:pending`
3480
+ * @param ok true when the op reached the server
3481
+ * @param reason why it failed, carried on `row:reverted`
3482
+ * @param reconcile server key / row / conflict for a successful append settle
3483
+ * @returns true when the id named an op still awaiting an outcome
3484
+ */
3485
+ settleRow(id: string, ok: boolean, reason?: string, reconcile?: { key?: string; row?: unknown; conflict?: { serverRow?: unknown } }): boolean;
3486
+ /**
3487
+ * Whether a row has a structural op in flight (§5.3).
3488
+ * @param key the row key
3489
+ * @returns `'pending'`, or null when the row is settled
3490
+ */
3491
+ rowStatus(key: string): 'pending' | null;
3492
+ /**
3493
+ * Every structural op still awaiting an outcome (§5.3), oldest first; always
3494
+ * empty when the source cannot append or delete.
3495
+ */
3496
+ pendingRows(): OpenRowOp[];
3170
3497
  }
3171
3498
 
3172
3499
  export interface ScrollApi {
@@ -4366,6 +4693,21 @@ export function applyResidual(
4366
4693
  export function odataAdapter(options: {
4367
4694
  url: string; fetch?: typeof fetch; headers?: Record<string, string>;
4368
4695
  count?: boolean; search?: boolean;
4696
+ /**
4697
+ * The key property every write addresses a row by in its entity-key URL
4698
+ * segment (`/Orders(<key>)`), and that an add-row is rekeyed to from the
4699
+ * created entity. Write-back only (§7 OData).
4700
+ */
4701
+ key?: string;
4702
+ /**
4703
+ * Opt the adapter into write-back. `false` (the default) declares the source
4704
+ * read-only; `true` advertises `mutate: { update: true, delete: true, append:
4705
+ * true, returning: 'row' }` so a committed cell edit is persisted with
4706
+ * `PATCH`, a row delete with `DELETE /EntitySet(key)`, and an add-row with
4707
+ * `POST /EntitySet` reading the created entity back (§7 OData,
4708
+ * BACKLOG-0000766, BACKLOG-0000795).
4709
+ */
4710
+ edit?: boolean;
4369
4711
  }): PushdownAdapter & { urlFor(query: RemoteRequest): string };
4370
4712
 
4371
4713
  /**
@@ -4378,6 +4720,46 @@ export function restAdapter(options: {
4378
4720
  capabilities?: PushdownCapabilities; operators?: string[];
4379
4721
  encodeFilter?: (filters: object) => string;
4380
4722
  rows?: (body: unknown) => unknown[]; total?: (body: unknown, rows: unknown[]) => number;
4723
+ /**
4724
+ * Opt the adapter into write-back. `false` (the default) declares the source
4725
+ * read-only; `true` advertises `mutate: { update: true, delete: true, append:
4726
+ * true, returning }` so a committed cell edit is persisted with `PATCH`, a row
4727
+ * delete with `DELETE`, and an add-row with `POST` to the collection URL
4728
+ * (§7 REST, BACKLOG-0000769, BACKLOG-0000795).
4729
+ */
4730
+ edit?: boolean;
4731
+ /**
4732
+ * The reconcile contract for a successful write (§5.1). `'none'` (the default)
4733
+ * is last-write-wins — the optimistic value stands; `'row'` reads the server's
4734
+ * authoritative row (via {@link writeRow}) back before confirm; `'key'` reads
4735
+ * only the server-assigned key. An add-row needs `'row'` or `'key'` so the
4736
+ * temp row can be rekeyed to its server key.
4737
+ */
4738
+ returning?: 'row' | 'key' | 'none';
4739
+ /**
4740
+ * The property an add-row response carries the server-assigned key in, read
4741
+ * back (through {@link writeRow}) to rekey the optimistic row. Defaults to
4742
+ * `id`. Write-back only.
4743
+ */
4744
+ keyField?: string;
4745
+ /**
4746
+ * Full control of a mutation's HTTP shape, overriding the default verb map and
4747
+ * URL. Given the {@link MutationOp}, return the method, url and optional
4748
+ * headers/body actually sent. Overriding this supersedes {@link writeUrlFor}.
4749
+ */
4750
+ encodeMutation?: (op: MutationOp) => { method: string, url: string, headers?: Record<string, string>, body?: unknown };
4751
+ /**
4752
+ * The endpoint a single mutation targets, when the default `${url}/${key}` is
4753
+ * not what the service uses. Ignored when {@link encodeMutation} is supplied.
4754
+ * Addresses an existing row; an add-row POSTs to the collection `url` instead.
4755
+ */
4756
+ writeUrlFor?: (op: MutationOp) => string;
4757
+ /**
4758
+ * Pull the authoritative row out of a write response when `returning: 'row'`,
4759
+ * and the created row an add-row reads its key from. Tolerates the plain
4760
+ * entity, a `{ row }` or a `{ data }` envelope by default.
4761
+ */
4762
+ writeRow?: (body: unknown) => unknown;
4381
4763
  }): PushdownAdapter & { urlFor(query: RemoteRequest): string };
4382
4764
 
4383
4765
  /**
@@ -4400,6 +4782,28 @@ export function duckdbAdapter(options: {
4400
4782
  from: string;
4401
4783
  /** Columns to select. Everything by default. */
4402
4784
  fields?: string[];
4785
+ /**
4786
+ * The key column an update and a delete target in their `WHERE`, and that an
4787
+ * add-row is rekeyed by. Write-back is refused unless this names a real column,
4788
+ * because an `UPDATE`/`DELETE` without a unique key could touch more than one
4789
+ * row (§7 DuckDB). Defaults to `id`.
4790
+ */
4791
+ keyField?: string;
4792
+ /**
4793
+ * Allow write-back against a plain writable table. `false` (the default) keeps
4794
+ * the source read-only, so a `from` that is a view or an expression can never
4795
+ * be mutated by accident. Enables `update`, `delete` and `append`
4796
+ * (BACKLOG-0000765, BACKLOG-0000795).
4797
+ */
4798
+ writable?: boolean;
4799
+ /**
4800
+ * The reconcile contract for a successful write (§5.1). `'row'` (the default)
4801
+ * appends `RETURNING *` and reconciles server truth (computed columns,
4802
+ * triggers); `'none'` keeps the optimistic value (last-write-wins). An add-row
4803
+ * always `RETURNING`s at least the key column regardless, since it needs that
4804
+ * key to rekey the temp row.
4805
+ */
4806
+ returning?: 'row' | 'none';
4403
4807
  }): PushdownAdapter & { sqlFor(query: RemoteRequest): { sql: string; params: unknown[] } };
4404
4808
 
4405
4809
  /**
@@ -4428,8 +4832,72 @@ export function dfqlAdapter(options: {
4428
4832
  limit?: number;
4429
4833
  fetch?: typeof fetch;
4430
4834
  headers?: Record<string, string>;
4835
+ /**
4836
+ * Where record mutations are POSTed, when the default write endpoint is not
4837
+ * what the deployment uses. Write-back persists update, delete and add-row
4838
+ * (§7 DFQL, card 771).
4839
+ */
4840
+ writeUrl?: string;
4841
+ /**
4842
+ * Map a new grid row to the DemandFlow `fields` an append needs — its required
4843
+ * `entity`/`level`/`comboKey` — since the grid's structural append only knows
4844
+ * the row's own fields. Called once per appended row.
4845
+ */
4846
+ encodeCreate?: (row: unknown) => Record<string, unknown>;
4431
4847
  }): PushdownAdapter & { linesFor(query: RemoteRequest): object[] };
4432
4848
 
4849
+ /**
4850
+ * An adapter for a GraphQL endpoint (BACKLOG-0000741).
4851
+ *
4852
+ * GraphQL has no fixed query semantics — a filter, a sort and pagination are
4853
+ * whatever the schema defines — so this adapter is configured, not zero-config.
4854
+ * The caller supplies `buildQuery`, which turns the pushed plan into the
4855
+ * `{ query, variables }` body a GraphQL endpoint is POSTed, and `parseResponse`,
4856
+ * which reads the operation's `data` back into `{ rows, total }`. Sensible
4857
+ * defaults cover an offset/limit list with a `totalCount` and a Relay cursor
4858
+ * connection (`first`/`after` with `pageInfo`); either is replaced by passing
4859
+ * the hook.
4860
+ *
4861
+ * The default `buildQuery` pushes only the window and asks for the total, so the
4862
+ * default capabilities are `range` and `total` and nothing else: filter, sort
4863
+ * and quick are left absent and the grid finishes them over the window. Declare
4864
+ * `operators`/`capabilities` only alongside a `buildQuery` that genuinely emits
4865
+ * them, or the grid returns the wrong rows silently.
4866
+ *
4867
+ * A Relay cursor connection is forward-only: a deep window is reached by paging
4868
+ * forward to it, which costs round trips proportional to its offset. Offset
4869
+ * pagination jumps straight to the window. `buildMutation` opts the write path
4870
+ * in and is a declared follow-up (the write-back wave); `capabilities.mutate` is
4871
+ * `false` by declaration until it is wired.
4872
+ */
4873
+ export function graphqlAdapter(options: {
4874
+ /** The GraphQL endpoint, POSTed a `{ query, variables }` body. Required. */
4875
+ url: string;
4876
+ fetch?: typeof fetch; headers?: Record<string, string>;
4877
+ /** The root query field the default query selects from. `items` by default. */
4878
+ field?: string;
4879
+ /** Field names for the default query's selection set. */
4880
+ fields?: string[];
4881
+ /** A raw selection set (for nested fields), overriding `fields`. */
4882
+ selection?: string;
4883
+ /** `offset` (offset/limit list) or `cursor` (Relay connection). `offset` by default. */
4884
+ pagination?: 'offset' | 'cursor';
4885
+ /** The page size for the whole-result and forward-cursor walks. */
4886
+ pageSize?: number;
4887
+ /** Rename the pagination variables the adapter drives per page. */
4888
+ vars?: Partial<Record<'offset' | 'limit' | 'first' | 'after', string>>;
4889
+ capabilities?: PushdownCapabilities; operators?: string[];
4890
+ /** Turn the pushed plan into a GraphQL operation `{ query, variables }`, replacing the default. */
4891
+ buildQuery?: (request: RemoteRequest) => object;
4892
+ /** Read the operation's `data` into `{ rows, total, pageInfo? }`, replacing the default. */
4893
+ parseResponse?: (data: object) => object;
4894
+ /** Turn a mutation into a GraphQL operation (write-back follow-up). */
4895
+ buildMutation?: (op: object) => object;
4896
+ }): PushdownAdapter & {
4897
+ buildQuery(query: RemoteRequest): { query: string; variables: object };
4898
+ parseResponse(data: object): { rows: unknown[]; total: number };
4899
+ };
4900
+
4433
4901
  export function createGrid(element: HTMLElement, config?: GridConfig): Grid;
4434
4902
  export function createHeadlessGrid(config?: GridConfig): Grid;
4435
4903
 
@@ -4936,6 +5404,9 @@ declare module 'lattice-grid/modules/react' {
4936
5404
  * React nor the grid: you pass both in. That is what keeps the package's
4937
5405
  * promise of no runtime dependencies, and what stops an adapter disagreeing
4938
5406
  * with the grid version already loaded.
5407
+ *
5408
+ * The live grid is reached through a forwarded ref: `ref.current.grid` is the
5409
+ * same `Grid` the vanilla `createGrid` returns, or null before mount.
4939
5410
  */
4940
5411
  export function createLatticeGrid(deps: { React: unknown; createGrid: unknown }): unknown;
4941
5412
  /** Every grid event, as the prop name a React caller writes. */
@@ -4945,14 +5416,37 @@ declare module 'lattice-grid/modules/react' {
4945
5416
  }
4946
5417
 
4947
5418
  declare module 'lattice-grid/modules/vue' {
4948
- export function createLatticeGrid(deps: { Vue?: unknown; createGrid: unknown }): unknown;
5419
+ /**
5420
+ * Build the Vue 3 component.
5421
+ *
5422
+ * The Vue runtime and `createGrid` are passed in, for the same reason as the
5423
+ * React adapter: the package ships no dependencies and cannot import either.
5424
+ * The dependency key is lowercase `vue` — `createLatticeGrid({ vue, createGrid })`.
5425
+ *
5426
+ * The live grid is reached through the component's exposed `grid()` method:
5427
+ * with `ref="grid"` on the element, `this.$refs.grid.grid()` returns the same
5428
+ * `Grid` the vanilla `createGrid` returns, or null before mount.
5429
+ */
5430
+ export function createLatticeGrid(deps: { vue: unknown; createGrid: unknown }): unknown;
4949
5431
  export const EVENT_NAMES: readonly string[];
4950
5432
  export function dashedName(event: string): string;
4951
5433
  export default createLatticeGrid;
4952
5434
  }
4953
5435
 
4954
5436
  declare module 'lattice-grid/modules/svelte' {
4955
- /** A Svelte action: `use:lattice={config}`. */
5437
+ /**
5438
+ * A Svelte action: `use:lattice={config}`.
5439
+ *
5440
+ * The action owns nothing but the node the caller already has, so the grid is
5441
+ * reached one of two ways. Pass an `onGrid` callback in the action params
5442
+ * (BACKLOG-0000785): `use:lattice={{ ...config, onGrid: (g) => (grid = g) }}`
5443
+ * calls it once with the live `Grid` the moment it is built — synchronously,
5444
+ * before `ready` fires — and again if you hand the action a different
5445
+ * `onGrid`. Or read it off an event: every grid event carries the grid on its
5446
+ * `detail`, so `on:ready={(e) => e.detail.grid}` hands you the same `Grid` a
5447
+ * turn after construction. Use `onGrid` when you need the instance during the
5448
+ * first render.
5449
+ */
4956
5450
  export function createLatticeAction(deps: { createGrid: unknown }): unknown;
4957
5451
  export const EVENT_NAMES: readonly string[];
4958
5452
  export function dashedName(event: string): string;
@@ -4966,6 +5460,10 @@ declare module 'lattice-grid/modules/webcomponent' {
4966
5460
  * This module carries the grid inside it. Use it *or* `createGrid` in one
4967
5461
  * page, never both: two copies keep separate registries, and a renderer
4968
5462
  * registered through one will not appear in the other.
5463
+ *
5464
+ * The live grid is reached through the element's `grid` getter: `el.grid` is
5465
+ * the same `Grid` the vanilla `createGrid` returns, or null while the element
5466
+ * is disconnected.
4969
5467
  */
4970
5468
  export function defineLatticeGrid(tag?: string): void;
4971
5469
  export function createLatticeGridElement(deps?: object): unknown;
@@ -4975,6 +5473,11 @@ declare module 'lattice-grid/modules/webcomponent' {
4975
5473
  export function observedAttributeNames(): string[];
4976
5474
  export function domEventName(event: string): string;
4977
5475
  export class GridElementController {}
5476
+ // Core factories re-exported from this module so they bind to the one engine
5477
+ // the element already carries: a type built with these here shares the
5478
+ // element's registry rather than a second copy's (BACKLOG-0000787). Typed by
5479
+ // reference to the base package.
5480
+ export { createCurrencyType, createUnitType, registerUnitSystem, createStat } from 'lattice-grid';
4978
5481
  export default defineLatticeGrid;
4979
5482
  }
4980
5483
 
@@ -5006,6 +5509,27 @@ declare module 'lattice-grid/modules/htmx' {
5006
5509
  export const QUERY_CHANGED_EVENT: string;
5007
5510
  export const SCROLL_NEAR_END_EVENT: string;
5008
5511
  export const HTML_ROW_WARNING_THRESHOLD: number;
5512
+ // The core factory surface this module re-exports, so an htmx page builds its
5513
+ // configured columns (a currency type, a unit type, a stat) from the one
5514
+ // engine it already carries rather than a second copy (BACKLOG-0000786).
5515
+ // Typed by reference to the base package; names the base package leaves
5516
+ // untyped stay untyped here too.
5517
+ export {
5518
+ createHeadlessGrid, version, getVersion, Grid, Registry, registerModules,
5519
+ createRadixType, createUnitType, registerUnitSystem, defineUnit, UNIT_SYSTEMS, parseUnit, formatUnit,
5520
+ createCurrencyType, parseMoney, formatMoney, convertMoney, rateFunction, MISSING_RATE,
5521
+ Messages, createMessages, auditCatalogue,
5522
+ EN_GB, MESSAGE_KEYS, DEFAULT_LOCALE, formatList, resolveLocale, LOCALES, resolveCatalogue,
5523
+ EN_US, FR_FR, FR_CA, IT_IT, ES_ES, PT_BR, DE_DE, NL_NL, SV_SE, DA_DK, NB_NO, FI_FI,
5524
+ PL_PL, CS_CZ, HU_HU, RO_RO, UK_UA, EL_GR, JA_JP, AR, AR_SA,
5525
+ Window, openWindow, WINDOW_KINDS,
5526
+ evaluateFormula, referencesOf, looksLikeFormula, compileRules, ingest, ingestSync,
5527
+ createPushdownSource, planQuery, splitFilters, applyResidual, capabilitiesOf, resolveMutate, NO_CAPABILITIES,
5528
+ odataAdapter, restAdapter, dfqlAdapter, duckdbAdapter,
5529
+ createStat, deltaOf, toneOf,
5530
+ } from 'lattice-grid';
5531
+ // American licence aliases mirror the base package (dom/index.js).
5532
+ export { setLicence as setLicense, licenceInfo as licenseInfo, licenceState as licenseState } from 'lattice-grid';
5009
5533
  }
5010
5534
 
5011
5535
  declare module 'lattice-grid/modules/dhtmlx-compat' {