@gridsay/mui-x-data-grid 0.1.0 → 1.0.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/README.md CHANGED
@@ -8,8 +8,35 @@ current view with each question, and checks every answer before the grid applies
8
8
  npm install @gridsay/mui-x-data-grid
9
9
  ```
10
10
 
11
- Peer dependency: `@mui/x-data-grid-premium` 9.18 or a later 9.x release (`^9.18.0`); other major
12
- versions are not tested. Data Grid Premium is a commercial MUI package: you need your own MUI X licence, and the grid shows MUI's watermark without one.
11
+ MUI X Data Grid Premium is MUI's commercial product, not part of Gridsay's service. This helper is
12
+ compatible with it: peer dependency `@mui/x-data-grid-premium` 9.18 or a later 9.x release
13
+ (`^9.18.0`), tested with 9.18.0; other major versions are not tested. In a project on another
14
+ version, such as 9.17 or a future 10.x, npm 7 and later stop the install with an `ERESOLVE` error, and so does pnpm with strict peer dependencies on; otherwise pnpm and yarn warn. Earlier versions, 9.17 included, are not supported. You need your own MUI X Premium licence; without one, MUI shows its
15
+ watermark.
16
+
17
+ ## What leaves the browser
18
+
19
+ With every question, the resolver posts to your `url`:
20
+
21
+ - the question and the conversation id;
22
+ - the column context the grid builds: each column's field, description, type and filter
23
+ operators, and the columns the grid derives for pivoting. Pivoting on a column turns that column's values into column names (pivot on an id column, and the ids become column names), and the grid puts these names in its context even with data sampling off; the helper's own description leaves them out. Of any option list in this context, the helper sends only the first 500 options, and of each only its value and label, when its value is text, a number or a boolean; an option with any other value is left out and still counts toward the 500. Example values go only if you turn on
24
+ the grid's `allowAiAssistantDataSampling` (the grid then picks values from random rows) or write
25
+ `examples` on a column;
26
+ - with `apiRef`, the grid as it is now: the features you switched off (filtering, sorting,
27
+ grouping, aggregation, pivoting, selection, and charts when no chart is active); per column,
28
+ the limits you set (`filterable`, `sortable`, `groupable`, `pivotable` or `aggregable` set to `false`, and the names in `availableAggregationFunctions` as you wrote them); for `singleSelect` and `multiSelect` columns
29
+ only, the value and label of each of the first 500 options, the same whether data sampling is
30
+ on or off; and the filters (with the values typed or picked in them, when they are text, numbers, booleans or dates), sorting, grouping,
31
+ aggregation and pivot;
32
+ - `additionalContext`, `privateMode` and `referenceId`, when you set them;
33
+ - in the headers: always `content-type: application/json` (your own `headers` can replace it),
34
+ then your own `headers`, `x-api-key` when you set `publishableKey`, and
35
+ `Authorization: Bearer …` with the end user's token when you set `getToken`.
36
+ The helper calls `fetch` with its default credentials mode, so the browser adds your cookies
37
+ only when `url` is on the page's own origin.
38
+
39
+ The helper sends no rows, row ids or selection of its own.
13
40
 
14
41
  ## Usage
15
42
 
@@ -44,7 +71,7 @@ from the browser, pass that URL with a `publishableKey` and `getToken`; see
44
71
  | Option | Meaning |
45
72
  |---|---|
46
73
  | `url` | Required. Where the prompt is posted: your own route, or the Gridsay gateway. |
47
- | `apiRef` | The grid's `apiRef`. With it, the helper describes the grid to the server and adapts answers to it. Without it, you still get answer checking and readable errors. |
74
+ | `apiRef` | The grid's `apiRef`. With it, the helper describes the grid to the server and adapts answers to it. Without it, you still get answer checking and readable errors, but the helper cannot see the grid: an answer that leaves pivot mode can be overwritten (see [Versioning](#versioning)). With controlled state, such as `filterModel`, update it from the grid's change callbacks, or the panel reports answers the grid does not show. |
48
75
  | `headers` | An object, or a function returning one (it may be async), added to each request. |
49
76
  | `publishableKey` | A publishable key, sent as `x-api-key`. For calling the gateway from the browser. |
50
77
  | `getToken` | Returns your end user's token, called for every request and sent as `Authorization: Bearer …`. If it throws or returns nothing (`null`, `undefined` or `''`, at once or from a promise), the prompt fails with "Sign in to use the assistant." (`unauthenticated_user`) and nothing is sent. |
@@ -55,19 +82,21 @@ from the browser, pass that URL with a `publishableKey` and `getToken`; see
55
82
  The resolver rejects with a `GridsayError`; the grid shows its `message` to your user as it is.
56
83
  To log why, wrap the resolver and read the error's `code`, `status`, `retryAfter` and `detail`.
57
84
  `code` is the gateway's (such as `quota_exceeded` or `rate_limited`) or one of the helper's own,
58
- below. Compare codes, never messages: the messages may change.
85
+ below. Compare codes, never messages: the messages may be reworded in a minor release. A code
86
+ the helper does not know, such as one the gateway adds later, arrives as it is, with the
87
+ gateway's `status` and sentence.
59
88
 
60
89
  The helper's own failures, each code exported as `<NAME>_CODE` beside its sentence:
61
90
 
62
91
  | `code` | Sentence | When |
63
92
  |---|---|---|
64
93
  | `unauthenticated_user` | `UNAUTHENTICATED_USER`: "Sign in to use the assistant." (or your route's own sentence) | `getToken` threw or returned nothing (nothing was sent), or the response was a 401 whose body names no other code. The same code the gateway sends. |
65
- | `unexpected_error` | `INVALID_ANSWER`: "The assistant couldn't complete your request. Try again." | Your `headers` function threw. The user sees this sentence, never the text of what it threw; the original is in `cause`. |
94
+ | `unexpected_error` | `INVALID_ANSWER`: "The assistant couldn't complete your request. Try again." | Your `headers` function threw, or something failed unexpectedly while the helper prepared the request or the answer; the original is in `cause`. The user sees this sentence, never the text of what was thrown. |
66
95
  | `connection_failed` | `CONNECTION_FAILED`: "The connection was interrupted. Try again." | The request got no answer, or the answer was cut off. |
67
96
  | `not_json` | `NOT_JSON`: "The assistant couldn't respond. Try again." | The response was not JSON (a 401 is `unauthenticated_user` instead). `status` 404 usually means `url` is wrong. |
68
97
  | `invalid_answer` | `INVALID_ANSWER` | The response was not an answer the helper can read, or an error without a sentence of its own. |
69
98
 
70
- An error from the gateway keeps the gateway's own code, `status`, `retryAfter` and `detail`.
99
+ An error from the gateway keeps the gateway's own code, `status`, `retryAfter` and `detail`; a 401 that names no code keeps its sentence, `status` and `detail` but not `retryAfter`.
71
100
 
72
101
  ## What changes compared with the stock resolver
73
102
 
@@ -79,38 +108,176 @@ An error from the gateway keeps the gateway's own code, `status`, `retryAfter` a
79
108
  - **Answers are checked before the grid touches them.** A malformed answer leaves the grid as it
80
109
  was. End users see short messages instead of browser errors
81
110
  (see Errors). Messages from the server are shown as they are.
82
- - **Top N works.** Asking for more rows than exist, or for rows spread over several pages, selects
83
- the rows that exist. With a data source, selection waits for the new rows.
111
+ - **Top N selects rows that exist.** Asking for more rows than exist, or for rows spread over
112
+ several pages, selects the rows that exist. With a data source, selection waits for the grid to
113
+ announce the new rows, and selects nothing if it does not within 15 seconds.
84
114
  - **Sorting a grouped column reorders the groups.** The sort is moved to the grouping column the
85
115
  grid generates (single or multiple grouping-column mode); other sorts are kept.
86
116
  - **Leaving pivot mode** no longer brings back the grouping and aggregation from before the pivot.
87
117
  - **A chart follow-up** keeps the aggregation it asked for.
88
- - **One prompt at a time.** A prompt sent while another is running waits for it, so a follow-up
89
- always builds on the previous answer.
118
+ - **One prompt at a time.** A prompt sent while another is running on the same grid waits for it,
119
+ for a bounded time, then is sent anyway; with `apiRef`, every resolver created for the same grid shares that line. If that time passes, both prompts are in flight and each answer is applied when it is ready,
120
+ so the two can interleave. A failed prompt does not block the next one. The request itself has no
121
+ time limit, as with MUI's own resolver; the helper's wait for a data source's rows ends after 15
122
+ seconds. Each request carries exactly the conversation id the grid gave the prompt, as with MUI's
123
+ own resolver: a prompt typed before the first answer of a new conversation starts its own
124
+ conversation. When an app keeps `aiAssistantConversations` in its own state and a second resolver
125
+ asks while an answer is being read, the grid writes that state from stale props: with MUI's own
126
+ resolver and with this helper alike, the overlapping prompt is lost from the conversation; the
127
+ difference is that with this helper the first prompt ends as successful instead of staying at
128
+ "Processing…".
129
+
130
+ ## When something goes wrong after the answer arrives
90
131
 
91
- ## Limits
132
+ - **The grid refuses part of an answer.** The grid applies an answer itself, after the resolver
133
+ returns it, one part after another (in 9.18: filters, pivot, grouping, aggregation, sorting,
134
+ chart, selection). It has no rollback: if it throws partway, the parts before stay, and the
135
+ panel shows the grid's own error text, not one of this helper's sentences. The helper's own
136
+ steps come around that: it leaves pivot mode before returning an answer without a pivot, and
137
+ selects the top rows a moment after, so pivot mode can already be off, and the top rows can
138
+ still be selected, when the grid refuses the rest. Nothing undoes an answer; ask again or change
139
+ the grid by hand.
140
+ - **The delayed top-rows selection fails.** It runs after the panel has shown the answer as
141
+ applied, so its error cannot be shown there; the rows are simply not selected.
142
+ - **The grid is unmounted while a question is out.** If the grid unmounts or is replaced while a
143
+ question is in flight, the answer is handled by MUI exactly as with MUI's own resolver; the
144
+ helper's own steps are applied only to a grid that is still in the document. With React 19.3.1, a
145
+ reply that arrives while the grid is hidden under `<Activity>` gets the same handling as from
146
+ MUI's own resolver, and the helper's own steps (leaving pivot mode, rewriting a sort on a grouped
147
+ column, the safe top-rows selection, waiting for a data source's rows, repairing a chart's
148
+ aggregation) are skipped. The helper describes the grid after your `headers` and `getToken` have
149
+ resolved, checking that it is in the document before each read and once more after the last, with
150
+ nothing awaited between that check and the request; a grid that leaves the document after that
151
+ moment, while the request is out, is described as it was then.
152
+ - **Part of the grid fails: an untested grid version, or a callback of yours.** Every call into the
153
+ grid goes through one guarded path: reading its private API, its root props
154
+ (`disableColumnFilter`, `disableColumnSorting`, `disableRowGrouping`, `disableAggregation`,
155
+ `disablePivoting`, `rowSelection`, `rowGroupingColumnMode`, `dataSource`) and its state (filters,
156
+ sorting, row grouping, aggregation, pivot mode and model, the active chart, whether rows are
157
+ loading), your column definitions and functions (`valueOptions`, `getOptionValue`,
158
+ `getOptionLabel`, and what they return), and each of the helper's own steps on it (subscribing to
159
+ its events, leaving pivot mode, keeping a chart's aggregation, selecting the top rows). The one
160
+ thing the helper does on a grid that has left the document is remove its own listeners. A part
161
+ that is missing, in another shape, or throws is a failure. An error thrown by the grid or by your
162
+ own callbacks (such as `onPivotActiveChange`) during these steps is reported in the console and
163
+ the step is skipped: the question goes ahead with what could be read, and the steps that depend on
164
+ a failed one are skipped too. Without the root props, or when pivot mode cannot be read or left,
165
+ the helper skips moving a grouped column's sort to the grouping column, selecting the top rows
166
+ (the grid is not asked to either: its own selection throws when asked for more rows than its
167
+ filters leave) and keeping a chart's aggregation; it never selects rows of a page whose loading it
168
+ could not see end. Every wait on the grid has a bound and always ends. The grid's current view is
169
+ sent whole or not at all, so the server keeps the conversation's last answer rather than being
170
+ told a part is empty.
171
+ - **The console warning.** Each part of the grid that fails is reported once per resolver, when
172
+ the question that met it has settled, however it ended. The first question to meet a failure
173
+ prints the full warning, naming every part it could not read or change, followed by each error
174
+ it caught, so you see your own stack. A part that first fails on a later question prints one
175
+ short line (the package, the part, "skipped", and the error). A part already reported is never
176
+ reported again, so the output is bounded by the number of parts the helper touches, however many questions are asked. One exception: an `apiRef` whose `current` throws when read is reported at once, before the question settles, in a full warning of its own.
177
+ - **Reading your column definitions.** The helper reads your column definitions once, before the
178
+ request, as MUI reads them: `valueOptions` called with `{ field }`, then `getOptionValue` and
179
+ `getOptionLabel` once per option, each as a method of its column. If reading them throws, or the
180
+ grid has left the page by the end of that read, the question is sent without a description and
181
+ settles as MUI's resolver would; what was thrown is reported in the console. Nothing read from the
182
+ grid refuses a question. Column definitions whose getters or functions throw only sometimes,
183
+ return different values on each call, or change the grid while being read are outside what the
184
+ helper supports. A change that makes nothing fail, such as a prop that keeps its name but changes
185
+ its meaning, is not noticed.
186
+
187
+ ## Known limits
92
188
 
93
189
  - Grid-wide switches (`disable…`, `rowSelection`, `rowGroupingColumnMode`, `dataSource`) are not
94
190
  in the grid's public API. The helper reads them from the grid's internal props, tested with
95
- `@mui/x-data-grid-premium` 9.18. If a later version moves them, the helper treats every feature
96
- as switched on.
191
+ `@mui/x-data-grid-premium` 9.18.0. If a later version moves them, the helper warns once and
192
+ skips its own steps that depend on them rather than guess (see above). An optional prop such as
193
+ `dataSource` cannot be told apart from one that moved.
97
194
  - With a data source, top N selects at most the rows of the loaded page.
98
195
  - In single grouping-column mode, all group levels share one sort direction: the first grouped
99
196
  column in the sort decides it.
100
197
  - While leaving pivot mode, the grid shows its pre-pivot state for a moment before the answer
101
198
  lands.
102
- - The snapshot leaves out quick-filter text, filter values that are not text, numbers, booleans
103
- or dates, aggregation functions other than `avg`, `sum`, `min`, `max` and `size`, and
104
- singleSelect options computed from a row.
199
+ - The snapshot leaves out quick-filter text, filter values that are not text, numbers, booleans or
200
+ dates, aggregation functions other than `avg`, `sum`, `min`, `max` and `size`, options past the
201
+ 500th, and options that `valueOptions` gives only for a row (it is called with `{ field }` only,
202
+ as by MUI's own assistant).
105
203
  - The assistant cannot create, remove or change the type of a chart; it only fills the active one.
204
+ - **Selecting the top rows** differs from MUI's own resolver: the helper selects the first rows that
205
+ pass the filters and are not group rows, even inside a collapsed group, where MUI's selects the
206
+ first visible rows, a group row included. The answer it returns, and the grid stores in the
207
+ conversation, has `select: -1` in place of the number asked for.
208
+ - A chart's aggregation that you change by hand within half a second of an answer that set it is
209
+ put back to the answer's.
210
+ - The description can be incomplete in three cases: an active filter whose operator needs no value
211
+ and is past the column's 64th operator is left out; an option whose label is over 255 characters
212
+ is left out and still counts toward the 500; an aggregation function name over 64 characters is
213
+ left out and still counts toward the 32.
214
+ - The per-grid ordering holds when each grid has its own resolver and passes `apiRef`. Without
215
+ `apiRef`, one resolver shared by two grids makes each wait for the other, and two resolvers on
216
+ one grid do not wait for each other.
217
+ - A column whose field contains `>->` is treated as a pivot column and left out of the helper's
218
+ description: its limits, and its filters, sorting, grouping, aggregation and pivot entries.
219
+ - With no `additionalContext`, the request's `options` is `{}`, where MUI's own resolver sends
220
+ `additionalContext: ''`.
106
221
  - Requests use the browser's default credentials mode (cookies only for the same origin). Put a
107
222
  cross-origin route's credentials in `headers` or `getToken`.
108
223
 
109
- ## Status
224
+ ## Exports
225
+
226
+ Everything the package exports, and nothing else, is covered by the versioning rule below.
227
+
228
+ | Export | What it is |
229
+ |---|---|
230
+ | `createPromptResolver(options)` | Returns the grid's `onPrompt`. |
231
+ | `PromptResolver` (type) | The type of what `createPromptResolver` returns: `(prompt, context, conversationId?) => Promise<PromptData>`. |
232
+ | `PromptResolverOptions` (type) | The options in the table above. |
233
+ | `GridsayError` | The class every rejection is an instance of (see Errors). |
234
+ | `CONNECTION_FAILED`, `INVALID_ANSWER`, `NOT_JSON`, `UNAUTHENTICATED_USER` | The sentences (typed as `string`). |
235
+ | `CONNECTION_FAILED_CODE`, `INVALID_ANSWER_CODE`, `NOT_JSON_CODE`, `UNAUTHENTICATED_USER_CODE`, `UNEXPECTED_ERROR_CODE` | The codes. |
236
+
237
+ Entry points: `@gridsay/mui-x-data-grid` (ESM, with its type declarations) and
238
+ `@gridsay/mui-x-data-grid/package.json` (the package's manifest, for tools that read it).
239
+
240
+ ## Versioning
241
+
242
+ `@gridsay/mui-x-data-grid` follows semver from its first major release. It pins `@gridsay/core`
243
+ exactly.
244
+
245
+ - **Codes are the contract; sentences are not.** Match on `error.code`. The sentences
246
+ (`error.message`, and the exported `INVALID_ANSWER`, `CONNECTION_FAILED` and the others) are for
247
+ people and may be reworded in a minor.
248
+ - **A major** for anything that breaks what this package exports, whether the change is here or in
249
+ `@gridsay/core`: a removed or changed export, type, option or error code, or a new required
250
+ method or prop on what it accepts from the grid (`apiRef`).
251
+ - **A minor** for what only adds: a new optional field on `GridsayError` or on an answer, a new
252
+ option, a new error code.
253
+
254
+ **What this package promises.** It is tested with `@mui/x-data-grid-premium` 9.18.0. With that
255
+ version, `apiRef` passed, callbacks of yours that do not throw, and any controlled state (such as
256
+ `filterModel`) updated from the grid's change callbacks, an answer the panel shows as applied is what the grid shows, except a chart when no chart is active: the panel lists "Charts" among the applied changes, as with MUI's own resolver, while the grid has no chart to fill. Without `apiRef` the helper cannot see the grid: an answer that leaves pivot
257
+ mode can be overwritten when the grid restores what it showed before the pivot. With controlled
258
+ state your callbacks do not update, the grid keeps your state while the panel reports the answer
259
+ applied. An error thrown by the grid or by your own callbacks during the helper's own steps (reading
260
+ the grid, leaving pivot mode, selecting the top rows, keeping a chart's aggregation) is reported in the console and that step is skipped; when it is thrown while reading your column definitions, the question goes out without a description of the grid. While the grid
261
+ applies the answer itself, an error from your callbacks (such as `onSortModelChange`) is the grid's:
262
+ it stops the answer there, the panel shows its text, and the helper does not see it. On other grid
263
+ versions the behaviour is best effort and failures are reported the same way; a change that makes
264
+ nothing fail is not noticed.
265
+
266
+ Its own types (`PromptResolver`, what `apiRef` accepts) are declared in this package and do not
267
+ change with the grid; they accept what 9.18.0's types do, with `strict` and with
268
+ `exactOptionalPropertyTypes`.
269
+
270
+ To check this package's types against a release of the grid by hand, build it and run
271
+ `node packages/mui-x-data-grid/compat/check.mjs 9.18.0` (or `9` for the newest 9.x). It is not in
272
+ CI, because it installs MUI X Data Grid Premium, a commercial package.
273
+
274
+ `pnpm --filter @gridsay/mui-x-data-grid compare` runs each life-cycle scenario (unmount, a
275
+ replacement, a re-key, a ref swap, two resolvers, strict mode, `<Activity>`, a portal move) on a
276
+ real grid twice, with MUI's own resolver and with this helper, and checks that the grid, the
277
+ panel and your callbacks see the same; it is run by hand for the same reason.
110
278
 
111
- 0.1.0. Where this stands:
112
- [gridsay.com/features#status](https://gridsay.com/features#status). The API may change before 1.0.
113
- ESM only, no runtime dependencies besides `@gridsay/core`.
279
+ Where this stands: [gridsay.com/features#status](https://gridsay.com/features#status). ESM only,
280
+ no runtime dependencies besides `@gridsay/core`.
114
281
 
115
282
  Example: [`examples/mui-x-data-grid`](https://github.com/gridsay/gridsay/tree/main/examples/mui-x-data-grid).
116
283
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { CONNECTION_FAILED, CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER, INVALID_ANSWER_CODE, NOT_JSON, NOT_JSON_CODE, RequestHeaders, RequestOptions, UNAUTHENTICATED_USER, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE } from "@gridsay/core";
2
- import { DataGridPremiumProps, GridApiPremium, GridRowId, ValueOptions } from "@mui/x-data-grid-premium";
3
- type State = GridApiPremium['state'];
4
- /** The column properties the helper reads. Kept structural, so a second copy of the grid's types still fits. */
1
+ import { CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER_CODE, NOT_JSON_CODE, PromptData, RequestHeaders, RequestOptions, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE } from "@gridsay/core";
2
+ type RowId = string | number;
3
+ type ValueOption = string | number | object;
4
+ /** MUI's `GridFilterItem['operator']`: its operators, or any other string. */
5
+ type FilterOperator = 'contains' | 'doesNotContain' | 'equals' | 'doesNotEqual' | 'startsWith' | 'endsWith' | '=' | '!=' | '>' | '>=' | '<' | '<=' | 'is' | 'not' | 'after' | 'onOrAfter' | 'before' | 'onOrBefore' | 'isEmpty' | 'isNotEmpty' | 'isAnyOf' | (string & {});
6
+ /** The column properties the helper reads. */
5
7
  type Column = {
6
8
  field: string;
7
9
  type?: string;
@@ -15,52 +17,110 @@ type Column = {
15
17
  value: string;
16
18
  requiresFilterValue?: boolean;
17
19
  }[];
18
- valueOptions?: ValueOptions[] | ((params: {
20
+ valueOptions?: ValueOption[] | ((params: {
19
21
  field: string;
20
- }) => ValueOptions[]);
21
- getOptionValue?: (option: ValueOptions) => unknown;
22
- getOptionLabel?: (option: ValueOptions) => string;
22
+ }) => ValueOption[]);
23
+ getOptionValue?: (option: ValueOption) => unknown;
24
+ getOptionLabel?: (option: ValueOption) => string;
23
25
  };
24
- /** The part of the grid API the helper reads and drives. */
25
- type GridApi = Pick<GridApiPremium, 'getSortedRowIds' | 'setRowSelectionModel' | 'setAggregationModel' | 'setPivotActive'> & {
26
+ /** The part of the grid API the helper reads and drives: what `apiRef` must point to. */
27
+ type GridApi = {
26
28
  getAllColumns: () => Column[];
27
- getRowNode: (id: GridRowId) => {
29
+ getSortedRowIds: () => RowId[];
30
+ getRowNode: (id: RowId) => {
28
31
  type: string;
29
32
  } | null;
33
+ setRowSelectionModel: (model: {
34
+ type: 'include' | 'exclude';
35
+ ids: Set<RowId>;
36
+ }, reason?: 'singleRowSelection' | 'multipleRowsSelection') => void;
37
+ setAggregationModel: (model: Record<string, string>) => void;
38
+ setPivotActive: (active: boolean | ((prev: boolean) => boolean)) => void;
30
39
  subscribeEvent: (event: 'rowsSet' | 'aggregationModelChange', handler: () => void) => () => void;
40
+ rootElementRef: {
41
+ readonly current: {
42
+ readonly isConnected: boolean;
43
+ } | null;
44
+ };
31
45
  state: {
32
- filter: Pick<State['filter'], 'filteredRowsLookup'> & {
33
- filterModel: Pick<State['filter']['filterModel'], 'items'> & {
34
- logicOperator?: string;
46
+ filter: {
47
+ filteredRowsLookup: Record<RowId, false>;
48
+ filterModel: {
49
+ items: {
50
+ id?: number | string;
51
+ field: string;
52
+ operator: FilterOperator;
53
+ value?: unknown;
54
+ }[];
55
+ logicOperator?: 'and' | 'or';
35
56
  };
36
57
  };
37
- sorting: Pick<State['sorting'], 'sortModel'>;
38
- rowGrouping: Pick<State['rowGrouping'], 'model'>;
39
- aggregation: Pick<State['aggregation'], 'model'>;
40
- pivoting: Pick<State['pivoting'], 'active' | 'model'>;
41
- chartsIntegration: Pick<State['chartsIntegration'], 'activeChartId'>;
42
- rows: Pick<State['rows'], 'loading'>;
58
+ sorting: {
59
+ sortModel: readonly {
60
+ field: string;
61
+ sort: 'asc' | 'desc' | null | undefined;
62
+ }[];
63
+ };
64
+ rowGrouping: {
65
+ model: string[];
66
+ };
67
+ aggregation: {
68
+ model: Record<string, string>;
69
+ };
70
+ pivoting: {
71
+ active: boolean;
72
+ model: {
73
+ columns: {
74
+ field: string;
75
+ sort?: 'asc' | 'desc';
76
+ hidden?: boolean;
77
+ }[];
78
+ rows: {
79
+ field: string;
80
+ hidden?: boolean;
81
+ }[];
82
+ values: {
83
+ field: string;
84
+ aggFunc: string;
85
+ hidden?: boolean;
86
+ }[];
87
+ };
88
+ };
89
+ chartsIntegration: {
90
+ activeChartId: string;
91
+ };
92
+ rows: {
93
+ loading?: boolean;
94
+ };
43
95
  };
44
96
  };
45
- type PromptResolver = NonNullable<DataGridPremiumProps['onPrompt']>;
97
+ /**
98
+ * The grid's `onPrompt`, declared here so a grid release cannot change it. A test checks it still
99
+ * fits the grid's own prop at the tested version.
100
+ */
101
+ type PromptResolver = (prompt: string, context: string, conversationId?: string) => Promise<PromptData>;
102
+ export declare const CONNECTION_FAILED: string;
103
+ export declare const INVALID_ANSWER: string;
104
+ export declare const NOT_JSON: string;
105
+ export declare const UNAUTHENTICATED_USER: string;
46
106
  export type PromptResolverOptions = {
47
107
  /** Where the prompt is posted: your own proxy route, or the Gridsay gateway. */
48
108
  url: string;
49
109
  /** With it, the helper describes the grid to the server and adapts answers to the grid. */
50
110
  apiRef?: {
51
111
  readonly current: GridApi | null;
52
- };
112
+ } | undefined;
53
113
  /** Added to each request. */
54
- headers?: RequestHeaders | (() => RequestHeaders | Promise<RequestHeaders>);
114
+ headers?: RequestHeaders | (() => RequestHeaders | Promise<RequestHeaders>) | undefined;
55
115
  /** A publishable key, sent as `x-api-key`. */
56
- publishableKey?: string;
116
+ publishableKey?: string | undefined;
57
117
  /** The end user's token, fetched for every request and sent as a bearer token. */
58
- getToken?: RequestOptions['getToken'];
59
- additionalContext?: string;
60
- privateMode?: boolean;
118
+ getToken?: RequestOptions['getToken'] | undefined;
119
+ additionalContext?: string | undefined;
120
+ privateMode?: boolean | undefined;
61
121
  /** Your id for the end user. */
62
- referenceId?: string;
122
+ referenceId?: string | undefined;
63
123
  };
64
124
  /** Replaces `unstable_gridDefaultPromptResolver` as the grid's `onPrompt`. */
65
125
  export declare function createPromptResolver(options: PromptResolverOptions): PromptResolver;
66
- export { CONNECTION_FAILED, CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER, INVALID_ANSWER_CODE, NOT_JSON, NOT_JSON_CODE, type PromptResolver, UNAUTHENTICATED_USER, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE };
126
+ export { CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER_CODE, NOT_JSON_CODE, type PromptResolver, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE };