@adaptabletools/adaptable 24.0.3 → 24.0.4

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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/AdaptableInterfaces/IAdaptable.d.ts +7 -0
  3. package/src/Api/AdaptableApi.d.ts +12 -0
  4. package/src/Api/GridApi.d.ts +13 -3
  5. package/src/Api/Implementation/AdaptableApiImpl.d.ts +1 -0
  6. package/src/Api/Implementation/AdaptableApiImpl.js +3 -0
  7. package/src/Api/Implementation/FlashingCellApiImpl.js +3 -8
  8. package/src/Api/Implementation/GridApiImpl.js +1 -1
  9. package/src/Api/Internal/AlertInternalApi.d.ts +7 -0
  10. package/src/Api/Internal/AlertInternalApi.js +42 -9
  11. package/src/Strategy/FlashingCellModule.js +2 -1
  12. package/src/Utilities/Helpers/CellValueHelper.d.ts +20 -0
  13. package/src/Utilities/Helpers/CellValueHelper.js +35 -0
  14. package/src/Utilities/Services/CalculatedColumnExpressionService.d.ts +25 -1
  15. package/src/Utilities/Services/CalculatedColumnExpressionService.js +160 -42
  16. package/src/Utilities/Services/DataService.js +10 -6
  17. package/src/Utilities/Services/FlashingCellService.d.ts +12 -0
  18. package/src/Utilities/Services/FlashingCellService.js +40 -3
  19. package/src/Utilities/Services/Interface/ICalculatedColumnExpressionService.d.ts +5 -0
  20. package/src/Utilities/Services/Interface/IQueryLanguageService.d.ts +5 -0
  21. package/src/Utilities/Services/QueryLanguageService.d.ts +6 -0
  22. package/src/Utilities/Services/QueryLanguageService.js +29 -1
  23. package/src/agGrid/AdaptableAgGrid.d.ts +80 -14
  24. package/src/agGrid/AdaptableAgGrid.js +468 -125
  25. package/src/agGrid/AgGridAdapter.d.ts +10 -1
  26. package/src/agGrid/AgGridAdapter.js +16 -0
  27. package/src/env.js +2 -2
  28. package/tsconfig.esm.tsbuildinfo +1 -1
@@ -3,15 +3,48 @@ import { CalculatedColumnModuleId } from '../Constants/ModuleConstants';
3
3
  import { expressionKindForCalculatedColumnType, getCalculatedColumnType, } from '../../AdaptableState/CalculatedColumnState';
4
4
  import { createHostExpressionContext, evaluate } from "../../../vendor/aql/index.js";
5
5
  import { createAdaptableAqlHost } from '../../aql/createAdaptableAqlHost';
6
- import Helper from '../Helpers/Helper';
6
+ import { areCellValuesEqual } from '../Helpers/CellValueHelper';
7
7
  import { CALCULATED_COLUMN_INVALID_CELL_VALUE } from '../Constants/GeneralConstants';
8
8
  export class CalculatedColumnExpressionService {
9
9
  adaptableApi;
10
10
  aggregatedColumnBindings = new Map();
11
+ dependencyCache;
11
12
  constructor(adaptableApi) {
12
13
  this.adaptableApi = adaptableApi;
13
14
  this.adaptableApi = adaptableApi;
14
15
  }
16
+ getDependencyCache() {
17
+ const calculatedColumns = this.adaptableApi.calculatedColumnApi.getCalculatedColumnState().CalculatedColumns;
18
+ const columns = this.adaptableApi.columnApi.getColumns();
19
+ const functionsGeneration = this.adaptableApi.internalApi
20
+ .getQueryLanguageService()
21
+ .getFunctionsGeneration();
22
+ const cache = this.dependencyCache;
23
+ if (cache &&
24
+ cache.calculatedColumns === calculatedColumns &&
25
+ cache.columns === columns &&
26
+ cache.functionsGeneration === functionsGeneration) {
27
+ return cache;
28
+ }
29
+ this.dependencyCache = {
30
+ calculatedColumns,
31
+ columns,
32
+ functionsGeneration,
33
+ observable: new Map(),
34
+ aggregated: new Map(),
35
+ dependentScalar: new Map(),
36
+ };
37
+ return this.dependencyCache;
38
+ }
39
+ getDependentScalarCalculatedColumns(columnId) {
40
+ const { dependentScalar } = this.getDependencyCache();
41
+ let calculatedColumns = dependentScalar.get(columnId);
42
+ if (!calculatedColumns) {
43
+ calculatedColumns = collectDependentScalarCalculatedColumns(this.adaptableApi, columnId);
44
+ dependentScalar.set(columnId, calculatedColumns);
45
+ }
46
+ return calculatedColumns;
47
+ }
15
48
  getComputedValueStore() {
16
49
  return this.adaptableApi.internalApi.getQueryLanguageService().getComputedValueStore();
17
50
  }
@@ -25,6 +58,7 @@ export class CalculatedColumnExpressionService {
25
58
  });
26
59
  this.aggregatedColumnBindings.clear();
27
60
  this.aggregatedColumnBindings = null;
61
+ this.dependencyCache = undefined;
28
62
  }
29
63
  resolveCalculatedColumnQuery(calculatedColumn) {
30
64
  return this.adaptableApi.internalApi
@@ -98,6 +132,15 @@ export class CalculatedColumnExpressionService {
98
132
  return { kind: 'columns', columnIds: [calculatedColumn.ColumnId] };
99
133
  }
100
134
  getObservableCalculatedColumnsAffectedByColumn(columnId) {
135
+ const { observable } = this.getDependencyCache();
136
+ let affected = observable.get(columnId);
137
+ if (!affected) {
138
+ affected = this.findObservableCalculatedColumnsAffectedByColumn(columnId);
139
+ observable.set(columnId, affected);
140
+ }
141
+ return affected;
142
+ }
143
+ findObservableCalculatedColumnsAffectedByColumn(columnId) {
101
144
  const queryLanguageService = this.adaptableApi.internalApi.getQueryLanguageService();
102
145
  const affected = [];
103
146
  for (const calculatedColumn of this.adaptableApi.calculatedColumnApi.getCalculatedColumns()) {
@@ -121,6 +164,15 @@ export class CalculatedColumnExpressionService {
121
164
  return affected;
122
165
  }
123
166
  getAggregatedCalculatedColumnsAffectedByColumn(columnId) {
167
+ const { aggregated } = this.getDependencyCache();
168
+ let affected = aggregated.get(columnId);
169
+ if (!affected) {
170
+ affected = this.findAggregatedCalculatedColumnsAffectedByColumn(columnId);
171
+ aggregated.set(columnId, affected);
172
+ }
173
+ return affected;
174
+ }
175
+ findAggregatedCalculatedColumnsAffectedByColumn(columnId) {
124
176
  const queryLanguageService = this.adaptableApi.internalApi.getQueryLanguageService();
125
177
  const affected = [];
126
178
  for (const calculatedColumn of this.adaptableApi.calculatedColumnApi.getCalculatedColumns()) {
@@ -268,25 +320,53 @@ function collectDependentScalarCalculatedColumns(adaptableApi, rootColumnId) {
268
320
  }
269
321
  return collected;
270
322
  }
271
- function buildShadowRowData(adaptableApi, info) {
272
- const shadowData = Helper.cloneObject(info.rowNode?.data ?? info.rowData ?? {});
273
- const fieldName = info.column.field ?? info.column.columnId;
274
- adaptableApi.internalApi.setValueUsingField(shadowData, fieldName, info.oldValue);
275
- return shadowData;
323
+ export function buildPreviousRowData(currentData, changes, suppressFieldDotNotation = false) {
324
+ const previousData = { ...currentData };
325
+ for (const { field, oldValue } of changes) {
326
+ if (suppressFieldDotNotation || !field.includes('.')) {
327
+ previousData[field] = oldValue;
328
+ continue;
329
+ }
330
+ const path = field.split('.');
331
+ let target = previousData;
332
+ for (let index = 0; index < path.length - 1 && target; index++) {
333
+ const next = target[path[index]];
334
+ if (next == null || typeof next !== 'object') {
335
+ target = undefined;
336
+ break;
337
+ }
338
+ target[path[index]] = Array.isArray(next) ? [...next] : { ...next };
339
+ target = target[path[index]];
340
+ }
341
+ if (target) {
342
+ target[path[path.length - 1]] = oldValue;
343
+ }
344
+ }
345
+ return previousData;
276
346
  }
277
- function evaluateScalarExpressionWithShadowData(adaptableApi, calculatedColumn, rowNode, shadowData) {
347
+ function createPreviousValuesEvaluator(adaptableApi, rowNode, previousData, suppressFieldDotNotation) {
278
348
  const internalApi = adaptableApi.internalApi;
279
- const moduleFns = internalApi
349
+ const baseFunctions = internalApi
280
350
  .getQueryLanguageService()
281
- .getModuleExpressionFunctionsMap(CalculatedColumnModuleId);
282
- const baseFunctions = { ...moduleFns.scalarFunctions };
351
+ .getModuleExpressionFunctionsMap(CalculatedColumnModuleId).scalarFunctions;
352
+ const previousValues = new Map();
353
+ const evaluateCalculatedColumn = (calculatedColumn) => {
354
+ if (previousValues.has(calculatedColumn.ColumnId)) {
355
+ return previousValues.get(calculatedColumn.ColumnId);
356
+ }
357
+ const value = evaluate(calculatedColumn.Expression, context);
358
+ previousValues.set(calculatedColumn.ColumnId, value);
359
+ return value;
360
+ };
283
361
  const resolveColumnValue = (columnId) => {
284
362
  const childCalculatedColumn = adaptableApi.calculatedColumnApi.getCalculatedColumnForColumnId(columnId);
285
363
  if (childCalculatedColumn && isScalarCalculatedColumn(adaptableApi, childCalculatedColumn)) {
286
- return evaluateScalarExpressionWithShadowData(adaptableApi, childCalculatedColumn, rowNode, shadowData);
364
+ return evaluateCalculatedColumn(childCalculatedColumn);
287
365
  }
288
- const adaptableColumn = adaptableApi.columnApi.getColumnWithColumnId(columnId);
289
- return internalApi.getValueUsingField(shadowData, adaptableColumn?.field ?? columnId);
366
+ const field = adaptableApi.columnApi.getColumnWithColumnId(columnId)?.field ?? columnId;
367
+ return suppressFieldDotNotation
368
+ ? previousData[field]
369
+ : internalApi.getValueUsingField(previousData, field);
290
370
  };
291
371
  const customFunctions = {
292
372
  ...baseFunctions,
@@ -296,65 +376,103 @@ function evaluateScalarExpressionWithShadowData(adaptableApi, calculatedColumn,
296
376
  },
297
377
  FIELD: {
298
378
  ...baseFunctions.FIELD,
299
- handler: (args) => internalApi.getValueUsingField(shadowData, args[0]),
379
+ handler: (args) => internalApi.getValueUsingField(previousData, args[0]),
300
380
  },
301
381
  };
302
- const shadowRowNode = { ...rowNode, data: shadowData };
303
382
  const context = createHostExpressionContext({
304
383
  host: createAdaptableAqlHost(adaptableApi),
305
384
  functions: customFunctions,
306
- rowRef: shadowRowNode,
385
+ rowRef: { ...rowNode, data: previousData },
307
386
  ext: internalApi.buildBaseContext(),
308
387
  });
309
- return evaluate(calculatedColumn.Expression, context);
388
+ return evaluateCalculatedColumn;
310
389
  }
311
- export function buildSyntheticCellDataChangedInfosForCalcColumns(adaptableApi, info) {
312
- if (!info.rowNode ||
313
- info.preventEdit ||
314
- info.trigger === 'undo' ||
315
- info.trigger === 'aggChange' ||
316
- info.trigger === 'calculatedColumnChange') {
317
- return [];
390
+ const isEligibleForCalculatedColumnChanges = (info) => !!info.rowNode &&
391
+ !info.preventEdit &&
392
+ info.trigger !== 'undo' &&
393
+ info.trigger !== 'aggChange' &&
394
+ info.trigger !== 'calculatedColumnChange';
395
+ function buildCalculatedColumnChangesForRow(adaptableApi, rowInfos, oldData) {
396
+ const expressionService = adaptableApi.internalApi.getCalculatedColumnExpressionService();
397
+ const calculatedColumns = [];
398
+ const seenColumnIds = new Set();
399
+ for (const info of rowInfos) {
400
+ for (const calculatedColumn of expressionService.getDependentScalarCalculatedColumns(info.column.columnId)) {
401
+ if (!seenColumnIds.has(calculatedColumn.ColumnId)) {
402
+ seenColumnIds.add(calculatedColumn.ColumnId);
403
+ calculatedColumns.push(calculatedColumn);
404
+ }
405
+ }
318
406
  }
319
- const calculatedColumns = collectDependentScalarCalculatedColumns(adaptableApi, info.column.columnId);
320
407
  if (!calculatedColumns.length) {
321
408
  return [];
322
409
  }
323
- const shadowData = buildShadowRowData(adaptableApi, info);
324
- const expressionService = adaptableApi.internalApi.getCalculatedColumnExpressionService();
325
- const syntheticEvents = [];
326
- calculatedColumns.forEach((calculatedColumn) => {
410
+ const { rowNode, primaryKeyValue } = rowInfos[0];
411
+ const suppressFieldDotNotation = !!adaptableApi.agGridApi.getGridOption('suppressFieldDotNotation');
412
+ const previousData = oldData ??
413
+ buildPreviousRowData(rowNode.data ?? rowInfos[0].rowData ?? {}, rowInfos.map((info) => ({
414
+ field: info.column.field ?? info.column.columnId,
415
+ oldValue: info.oldValue,
416
+ })), suppressFieldDotNotation);
417
+ const evaluatePreviousValue = createPreviousValuesEvaluator(adaptableApi, rowNode, previousData, suppressFieldDotNotation);
418
+ const calculatedColumnChanges = [];
419
+ for (const calculatedColumn of calculatedColumns) {
327
420
  let oldValue;
328
421
  try {
329
- oldValue = evaluateScalarExpressionWithShadowData(adaptableApi, calculatedColumn, info.rowNode, shadowData);
422
+ oldValue = evaluatePreviousValue(calculatedColumn);
330
423
  }
331
424
  catch {
332
- return;
425
+ continue;
333
426
  }
334
- const newValue = expressionService.evaluateCalculatedColumnQuery(calculatedColumn, info.rowNode);
335
- if (oldValue == newValue) {
336
- return;
427
+ const newValue = expressionService.evaluateCalculatedColumnQuery(calculatedColumn, rowNode);
428
+ if (areCellValuesEqual(oldValue, newValue)) {
429
+ continue;
337
430
  }
338
431
  const column = adaptableApi.columnApi.getColumnWithColumnId(calculatedColumn.ColumnId);
339
432
  if (!column) {
340
- return;
433
+ continue;
341
434
  }
342
- syntheticEvents.push(adaptableApi.internalApi.buildCellDataChangedInfo({
435
+ calculatedColumnChanges.push(adaptableApi.internalApi.buildCellDataChangedInfo({
343
436
  oldValue,
344
437
  newValue,
345
438
  column,
346
- primaryKeyValue: info.primaryKeyValue,
347
- rowNode: info.rowNode,
439
+ primaryKeyValue,
440
+ rowNode,
348
441
  trigger: 'calculatedColumnChange',
349
442
  }));
350
- });
351
- return syntheticEvents;
443
+ }
444
+ return calculatedColumnChanges;
445
+ }
446
+ export function buildSyntheticCellDataChangedInfosForCalcColumns(adaptableApi, info) {
447
+ if (!isEligibleForCalculatedColumnChanges(info)) {
448
+ return [];
449
+ }
450
+ return buildCalculatedColumnChangesForRow(adaptableApi, [info]);
352
451
  }
353
- export function expandCellDataChangedInfosWithCalculatedColumns(adaptableApi, cellDataChangedInfos) {
452
+ export function expandCellDataChangedInfosWithCalculatedColumns(adaptableApi, cellDataChangedInfos, oldData) {
354
453
  if (!cellDataChangedInfos.length) {
355
454
  return cellDataChangedInfos;
356
455
  }
357
- const syntheticEvents = cellDataChangedInfos.flatMap((info) => buildSyntheticCellDataChangedInfosForCalcColumns(adaptableApi, info));
456
+ const infosByRow = new Map();
457
+ for (const info of cellDataChangedInfos) {
458
+ if (!isEligibleForCalculatedColumnChanges(info)) {
459
+ continue;
460
+ }
461
+ const rowInfos = infosByRow.get(info.rowNode);
462
+ if (rowInfos) {
463
+ rowInfos.push(info);
464
+ }
465
+ else {
466
+ infosByRow.set(info.rowNode, [info]);
467
+ }
468
+ }
469
+ if (!infosByRow.size) {
470
+ return cellDataChangedInfos;
471
+ }
472
+ const syntheticEvents = [];
473
+ infosByRow.forEach((rowInfos) => {
474
+ syntheticEvents.push(...buildCalculatedColumnChangesForRow(adaptableApi, rowInfos, infosByRow.size === 1 ? oldData : undefined));
475
+ });
358
476
  if (!syntheticEvents.length) {
359
477
  return cellDataChangedInfos;
360
478
  }
@@ -1,4 +1,5 @@
1
1
  import Emitter from '../../Utilities/Emitter';
2
+ import { areCellValuesEqual } from '../Helpers/CellValueHelper';
2
3
  export class DataService {
3
4
  adaptable;
4
5
  emitter;
@@ -38,12 +39,15 @@ export class DataService {
38
39
  }
39
40
  }
40
41
  CreateCellDataChangedEvent(cellDataChangedInfo) {
41
- if (cellDataChangedInfo.newValue != cellDataChangedInfo.oldValue) {
42
- const validationRules = this.adaptable.api.internalApi
43
- .getValidationService()
44
- .getValidationRulesForDataChange(cellDataChangedInfo);
45
- if (validationRules.length) {
46
- cellDataChangedInfo.preventEdit = true;
42
+ if (!areCellValuesEqual(cellDataChangedInfo.oldValue, cellDataChangedInfo.newValue)) {
43
+ const isEdit = cellDataChangedInfo.trigger === 'edit' || cellDataChangedInfo.trigger === 'undo';
44
+ if (isEdit) {
45
+ const validationRules = this.adaptable.api.internalApi
46
+ .getValidationService()
47
+ .getValidationRulesForDataChange(cellDataChangedInfo);
48
+ if (validationRules.length) {
49
+ cellDataChangedInfo.preventEdit = true;
50
+ }
47
51
  }
48
52
  this.emitter.emitSync('BeforeCellDataChanged', cellDataChangedInfo);
49
53
  this.emitter.emitSync('CellDataChanged', cellDataChangedInfo);
@@ -9,11 +9,23 @@ export declare class FlashingCellService implements IAdaptableService {
9
9
  private api;
10
10
  gridCellsCurrentlyFlashing: Record<string, Record<string, TypeUuid>>;
11
11
  flashingCellsMapping: Record<TypeUuid, AdaptableFlashingCell>;
12
+ private flashesToClear;
13
+ private flashClearTimers;
12
14
  constructor(api: AdaptableApi);
13
15
  destroy(): void;
16
+ /**
17
+ * Clears the flash after `duration` ms. The flashes shown in one synchronous turn with the same
18
+ * duration share one timer, started when the turn ends, so none is shorter than its duration.
19
+ */
20
+ scheduleGridCellFlashClear(flashingCell: AdaptableFlashingCell, duration: number): void;
21
+ private startFlashClearTimers;
14
22
  addGridCellFlash(flashingCell: AdaptableFlashingCell): void;
15
23
  clearGridCellFlash(flashingCell: AdaptableFlashingCell): void;
16
24
  clearAllGridCellFlashes(): void;
17
25
  isAnyFlashingCellActive(): boolean;
26
+ /**
27
+ * Refreshes the flashing cells of the row and of its pinned copy, if they are rendered. A row
28
+ * rendered later reads the flash from this service when its cells are first rendered.
29
+ */
18
30
  private refreshGridCells;
19
31
  }
@@ -3,6 +3,8 @@ export class FlashingCellService {
3
3
  api;
4
4
  gridCellsCurrentlyFlashing;
5
5
  flashingCellsMapping;
6
+ flashesToClear;
7
+ flashClearTimers = new Set();
6
8
  constructor(api) {
7
9
  this.api = api;
8
10
  this.gridCellsCurrentlyFlashing = {};
@@ -11,6 +13,34 @@ export class FlashingCellService {
11
13
  destroy() {
12
14
  this.gridCellsCurrentlyFlashing = {};
13
15
  this.flashingCellsMapping = {};
16
+ this.flashesToClear = undefined;
17
+ this.flashClearTimers.forEach((timer) => clearTimeout(timer));
18
+ this.flashClearTimers.clear();
19
+ }
20
+ scheduleGridCellFlashClear(flashingCell, duration) {
21
+ if (!this.flashesToClear) {
22
+ this.flashesToClear = new Map();
23
+ queueMicrotask(() => this.startFlashClearTimers());
24
+ }
25
+ let flashingCells = this.flashesToClear.get(duration);
26
+ if (!flashingCells) {
27
+ flashingCells = [];
28
+ this.flashesToClear.set(duration, flashingCells);
29
+ }
30
+ flashingCells.push(flashingCell);
31
+ }
32
+ startFlashClearTimers() {
33
+ const flashesToClear = this.flashesToClear;
34
+ this.flashesToClear = undefined;
35
+ flashesToClear?.forEach((flashingCells, duration) => {
36
+ const timer = setTimeout(() => {
37
+ this.flashClearTimers.delete(timer);
38
+ this.api.internalApi
39
+ .getAdaptableInstance()
40
+ .runPostEditBatch(() => flashingCells.forEach((flashingCell) => this.clearGridCellFlash(flashingCell)));
41
+ }, duration);
42
+ this.flashClearTimers.add(timer);
43
+ });
14
44
  }
15
45
  addGridCellFlash(flashingCell) {
16
46
  const { rowPrimaryKey } = flashingCell;
@@ -54,10 +84,17 @@ export class FlashingCellService {
54
84
  return Object.keys(this.gridCellsCurrentlyFlashing).length > 0;
55
85
  }
56
86
  refreshGridCells(flashingCell) {
57
- const { cellDataChangedInfo } = flashingCell;
58
- if (!cellDataChangedInfo) {
87
+ const rowNode = flashingCell.cellDataChangedInfo?.rowNode;
88
+ if (!rowNode) {
59
89
  return;
60
90
  }
61
- this.api.gridApi.refreshCells(cellDataChangedInfo.rowNode, Object.keys(flashingCell.flashColumnIds), true);
91
+ const adaptable = this.api.internalApi.getAdaptableInstance();
92
+ const columnIds = Object.keys(flashingCell.flashColumnIds);
93
+ const pinnedSibling = rowNode.pinnedSibling;
94
+ for (const node of pinnedSibling ? [rowNode, pinnedSibling] : [rowNode]) {
95
+ if (adaptable.isRowNodeRendered(node)) {
96
+ this.api.gridApi.refreshCells(node, columnIds, true);
97
+ }
98
+ }
62
99
  }
63
100
  }
@@ -53,6 +53,11 @@ export interface ICalculatedColumnExpressionService extends IAdaptableService {
53
53
  * (window) result changing on the edited row would otherwise stay stale.
54
54
  */
55
55
  getAggregatedCalculatedColumnsAffectedByColumn(columnId: string): string[];
56
+ /**
57
+ * Scalar Calculated Columns whose value depends on `columnId`, directly or through other
58
+ * Calculated Columns; their changes are reported with the `calculatedColumnChange` trigger.
59
+ */
60
+ getDependentScalarCalculatedColumns(columnId: string): CalculatedColumn[];
56
61
  bindAggregatedCalculatedColumn(calculatedColumn: CalculatedColumn): void;
57
62
  unbindAggregatedCalculatedColumn(calculatedColumn: CalculatedColumn): void;
58
63
  buildSyntheticCellDataChangedInfosForCalcColumns(cellDataChangedInfo: CellDataChangedInfo): CellDataChangedInfo[];
@@ -142,6 +142,11 @@ export interface IQueryLanguageService extends IAdaptableService {
142
142
  * `(module, expression)` with the other per-expression caches.
143
143
  */
144
144
  getExpressionDependencies(expression: string, module: AdaptableModule): CompiledValueExpression['dependencies'] | undefined;
145
+ /**
146
+ * Changes whenever the expression function pools are refreshed; results derived from
147
+ * expression dependencies can be cached against it
148
+ */
149
+ getFunctionsGeneration(): number;
145
150
  /**
146
151
  * Static result type of an expression (`'number' | 'text' | 'date' |
147
152
  * 'boolean' | 'array' | 'duration'`), from the compiled plan — no
@@ -23,6 +23,9 @@ export declare class QueryLanguageService implements IQueryLanguageService {
23
23
  private _historyStore?;
24
24
  private _computedValueStore?;
25
25
  private dependenciesCache;
26
+ /** functions cache key -> expression text -> summary, for `summaryByExpressionTextGeneration` */
27
+ private summaryByExpressionText;
28
+ private summaryByExpressionTextGeneration;
26
29
  /** History-series releases per cached prepared evaluator (see `retainObservableSeries`). */
27
30
  private observableSeriesReleases;
28
31
  private hostEventsBound;
@@ -140,6 +143,8 @@ export declare class QueryLanguageService implements IQueryLanguageService {
140
143
  evaluateScalarExpression(expression: string, module: AdaptableModule, rowNode: unknown, evalContext?: QueryLanguageRowEvalContext): any;
141
144
  prepareBooleanRowEvaluator(expression: string, module: AdaptableModule): (rowNode: unknown) => any;
142
145
  executeValueExpression(expression: string, module: AdaptableModule, evalContext?: QueryLanguageRowEvalContext): ValueExecutionResult;
146
+ /** Changes whenever the expression function pools are refreshed */
147
+ getFunctionsGeneration(): number;
143
148
  getExpressionDependencies(expression: string, module: AdaptableModule): CompiledValueExpression['dependencies'] | undefined;
144
149
  getExpressionOutputType(expression: string, module: AdaptableModule): CompiledValueExpression['outputType'];
145
150
  isExpressionRowIndependent(expression: string, module: AdaptableModule): boolean;
@@ -148,6 +153,7 @@ export declare class QueryLanguageService implements IQueryLanguageService {
148
153
  * dependency and the static-type questions; the plan itself is not kept.
149
154
  */
150
155
  private getCompiledExpressionSummary;
156
+ private rememberSummaryForText;
151
157
  isAggregatedBooleanSatisfied(compiled: CompiledValueExpression, result: ValueExecutionResult, module: AdaptableModule, evalContext?: {
152
158
  host?: AqlHost;
153
159
  }): boolean;
@@ -65,6 +65,8 @@ export class QueryLanguageService {
65
65
  _historyStore;
66
66
  _computedValueStore;
67
67
  dependenciesCache = new Map();
68
+ summaryByExpressionText = new Map();
69
+ summaryByExpressionTextGeneration = 0;
68
70
  observableSeriesReleases = new Map();
69
71
  hostEventsBound = false;
70
72
  hostEventUnsubscribers = [];
@@ -87,6 +89,7 @@ export class QueryLanguageService {
87
89
  this._historyStore?.destroy();
88
90
  this._historyStore = undefined;
89
91
  this.dependenciesCache.clear();
92
+ this.summaryByExpressionText.clear();
90
93
  this.validationCache.clear();
91
94
  this.expressionKindCache.clear();
92
95
  this.rowEvaluatorCache.clear();
@@ -486,6 +489,9 @@ export class QueryLanguageService {
486
489
  getRowNodes: evalContext?.getRowNodes,
487
490
  }), { getValue: evalContext?.getColumnValue });
488
491
  }
492
+ getFunctionsGeneration() {
493
+ return this.functionsGeneration;
494
+ }
489
495
  getExpressionDependencies(expression, module) {
490
496
  return this.getCompiledExpressionSummary(expression, module)?.dependencies;
491
497
  }
@@ -499,9 +505,24 @@ export class QueryLanguageService {
499
505
  if (!expression?.trim()) {
500
506
  return undefined;
501
507
  }
502
- const cacheKey = `${this.functionsGeneration}::${this.getExpressionFunctionsCacheKey(module)}::${this.toCacheExpression(expression)}`;
508
+ if (this.summaryByExpressionTextGeneration !== this.functionsGeneration) {
509
+ this.summaryByExpressionText.clear();
510
+ this.summaryByExpressionTextGeneration = this.functionsGeneration;
511
+ }
512
+ const functionsCacheKey = this.getExpressionFunctionsCacheKey(module);
513
+ let summaryByText = this.summaryByExpressionText.get(functionsCacheKey);
514
+ if (!summaryByText) {
515
+ summaryByText = new Map();
516
+ this.summaryByExpressionText.set(functionsCacheKey, summaryByText);
517
+ }
518
+ const cachedForText = summaryByText.get(expression);
519
+ if (cachedForText !== undefined) {
520
+ return cachedForText ?? undefined;
521
+ }
522
+ const cacheKey = `${this.functionsGeneration}::${functionsCacheKey}::${this.toCacheExpression(expression)}`;
503
523
  const cached = this.dependenciesCache.get(cacheKey);
504
524
  if (cached !== undefined) {
525
+ this.rememberSummaryForText(summaryByText, expression, cached);
505
526
  return cached ?? undefined;
506
527
  }
507
528
  let summary;
@@ -517,8 +538,15 @@ export class QueryLanguageService {
517
538
  summary = null;
518
539
  }
519
540
  this.dependenciesCache.set(cacheKey, summary);
541
+ this.rememberSummaryForText(summaryByText, expression, summary);
520
542
  return summary ?? undefined;
521
543
  }
544
+ rememberSummaryForText(summaryByText, expression, summary) {
545
+ if (summaryByText.size >= CANONICAL_TEXT_CACHE_SIZE) {
546
+ summaryByText.clear();
547
+ }
548
+ summaryByText.set(expression, summary);
549
+ }
522
550
  isAggregatedBooleanSatisfied(compiled, result, module, evalContext) {
523
551
  return this.createEngine(module, evalContext?.host).isAggregatedBooleanSatisfied(compiled, result);
524
552
  }