@trudb/tru-common-lib 0.2.554 → 0.2.556

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.
@@ -1849,6 +1849,87 @@ class TruEntityAccessor {
1849
1849
  return queryData.results[0];
1850
1850
  })));
1851
1851
  };
1852
+ propertyPathValues = (entity, propertyPath) => {
1853
+ let values = [entity];
1854
+ propertyPath.split(/[./]/).filter(part => part.length > 0).forEach((part) => {
1855
+ const nextValues = [];
1856
+ values.forEach((value) => {
1857
+ if (value == null)
1858
+ return;
1859
+ const nextValue = value[part];
1860
+ if (Array.isArray(nextValue))
1861
+ nextValues.push(...nextValue);
1862
+ else if (nextValue != null)
1863
+ nextValues.push(nextValue);
1864
+ });
1865
+ values = nextValues;
1866
+ });
1867
+ return values;
1868
+ };
1869
+ propertyPathIsLoaded = (entity, propertyPath) => {
1870
+ let values = [entity];
1871
+ const parts = propertyPath.split(/[./]/).filter(part => part.length > 0);
1872
+ for (const part of parts) {
1873
+ const nextValues = [];
1874
+ for (const value of values) {
1875
+ if (value == null)
1876
+ continue;
1877
+ const entityAspect = value.entityAspect;
1878
+ const navigationProperty = entityAspect?.entityType?.getNavigationProperty?.(part);
1879
+ if (navigationProperty && !entityAspect.isNavigationPropertyLoaded(navigationProperty))
1880
+ return false;
1881
+ const nextValue = value[part];
1882
+ if (navigationProperty?.isScalar && nextValue == null &&
1883
+ navigationProperty.foreignKeyNames?.some((name) => value[name] != null))
1884
+ return false;
1885
+ if (Array.isArray(nextValue))
1886
+ nextValues.push(...nextValue);
1887
+ else if (nextValue != null && typeof nextValue === 'object')
1888
+ nextValues.push(nextValue);
1889
+ }
1890
+ values = nextValues;
1891
+ }
1892
+ return true;
1893
+ };
1894
+ predicateIsLocallyEvaluable = (predicate, entity, entityType) => {
1895
+ const accessor = this;
1896
+ const visitor = {
1897
+ passthruPredicate: function () { return false; },
1898
+ unaryPredicate: function (context) {
1899
+ return this.pred.visit(context);
1900
+ },
1901
+ binaryPredicate: function (context) {
1902
+ return this.expr1.visit(context) && this.expr2.visit(context);
1903
+ },
1904
+ andOrPredicate: function (context) {
1905
+ return this.preds.every((item) => item.visit(context));
1906
+ },
1907
+ anyAllPredicate: function (context) {
1908
+ if (!this.expr.visit(context))
1909
+ return false;
1910
+ return accessor.propertyPathValues(context.entity, this.exprSource)
1911
+ .every(item => this.pred.visit({ ...context, entity: item, entityType: this.expr.dataType }));
1912
+ },
1913
+ litExpr: function () { return true; },
1914
+ propExpr: function (context) {
1915
+ return accessor.propertyPathIsLoaded(context.entity, this.propertyPath);
1916
+ },
1917
+ fnExpr: function (context) {
1918
+ return this.exprs.every((item) => item.visit(context));
1919
+ }
1920
+ };
1921
+ try {
1922
+ return predicate.visit({ entity, entityType }, visitor);
1923
+ }
1924
+ catch {
1925
+ return false;
1926
+ }
1927
+ };
1928
+ queryIsLocallyEvaluable = (query, entities) => {
1929
+ if (!query.wherePredicate)
1930
+ return true;
1931
+ return entities.every(entity => this.predicateIsLocallyEvaluable(query.wherePredicate, entity, entity.entityAspect?.entityType));
1932
+ };
1852
1933
  searchByRefArrayCacheOnly = (entity, setupQuery = null, refs, includeDeleted = false) => {
1853
1934
  if (!includeDeleted)
1854
1935
  includeDeleted = false;
@@ -1872,6 +1953,12 @@ class TruEntityAccessor {
1872
1953
  var results = this._entityManager.executeQueryLocally(query);
1873
1954
  if (results && results.length)
1874
1955
  return results;
1956
+ var refQuery = this._breezeContext.createQuery(this.getQueryServiceName(entity)).using(queryOptions);
1957
+ if (refs.length > 0)
1958
+ refQuery = refQuery.where(this.getPrimaryKeyName(entity), 'in', refs);
1959
+ var refResults = this._entityManager.executeQueryLocally(refQuery);
1960
+ if (refResults.length && !this.queryIsLocallyEvaluable(query, refResults))
1961
+ return undefined;
1875
1962
  return null;
1876
1963
  };
1877
1964
  searchByRefWithQuery = (entity, setupQuery, ref) => {
@@ -6914,7 +7001,7 @@ class TruDataGridCellRenderer {
6914
7001
  init(params) {
6915
7002
  params.eGridCell.innerHTML = '';
6916
7003
  const value = params.value ?? '';
6917
- if (params.colDef.cellEditor && params.colDef.cellEditor.name === "StdRichTextList") {
7004
+ if (params.renderRichText === true) {
6918
7005
  var p = document.createElement('div');
6919
7006
  p.innerHTML = value;
6920
7007
  params.eGridCell.appendChild(p);
@@ -8515,12 +8602,17 @@ class TruDataChangeParser {
8515
8602
  };
8516
8603
  entityFoundByQuery = (change) => {
8517
8604
  var entityAccessor = this.dataContext.entityAccess();
8518
- var entities = entityAccessor.searchByRefArrayCacheOnly(this.entity, this.getLatestQuery(), [change.tableRef]);
8519
- if (!entities?.length) {
8605
+ var localEntities = entityAccessor.searchByRefArrayCacheOnly(this.entity, this.getLatestQuery(), [change.tableRef]);
8606
+ var globalEntities = null;
8607
+ if (!localEntities?.length) {
8520
8608
  var entityAccessor = this.globalDataContext.entityAccess();
8521
- entities = entityAccessor.searchByRefArrayCacheOnly(this.entity, this.getLatestQuery(), [change.tableRef]);
8609
+ globalEntities = entityAccessor.searchByRefArrayCacheOnly(this.entity, this.getLatestQuery(), [change.tableRef]);
8522
8610
  }
8523
- return entities === null ? 0 : entities.length;
8611
+ if (localEntities?.length || globalEntities?.length)
8612
+ return true;
8613
+ if (localEntities === undefined || globalEntities === undefined)
8614
+ return undefined;
8615
+ return false;
8524
8616
  };
8525
8617
  getEntityFromServer = (change) => {
8526
8618
  var entityAccessor = this.dataContext.entityAccess();
@@ -8557,20 +8649,24 @@ class TruDataChangeParser {
8557
8649
  if (change.changeOperation === 'U') {
8558
8650
  this.applyPropertyChanges(change, entity);
8559
8651
  var results = this.getLatestResults();
8560
- if (this.entityFoundByQuery(change)) {
8652
+ var entityMatchesQuery = this.entityFoundByQuery(change);
8653
+ if (entityMatchesQuery === true) {
8561
8654
  var entityAlreadyInResults = this.getEntityFromResults(results, change);
8562
8655
  if (!entityAlreadyInResults.length && this.isLoaded()) {
8563
8656
  this.addEntity(entity);
8564
8657
  }
8565
8658
  reloadResults = true;
8566
8659
  }
8567
- else {
8660
+ else if (entityMatchesQuery === false) {
8568
8661
  var entityToRemove = this.getEntityFromResults(results, change);
8569
8662
  if (entityToRemove.length) {
8570
8663
  results.splice(results.indexOf(entityToRemove[0]), 1);
8571
8664
  reloadResults = true;
8572
8665
  }
8573
8666
  }
8667
+ else {
8668
+ reloadResults = true;
8669
+ }
8574
8670
  }
8575
8671
  else if (change.changeOperation === 'D') {
8576
8672
  var results = this.getLatestResults();
@@ -8584,7 +8680,8 @@ class TruDataChangeParser {
8584
8680
  else if (change.changeOperation === 'I') {
8585
8681
  var results = this.getLatestResults();
8586
8682
  var entityAlreadyInResults = this.getEntityFromResults(results, change);
8587
- if (this.entityFoundByQuery(change) && !entityAlreadyInResults.length && this.isLoaded()) {
8683
+ var entityMatchesQuery = this.entityFoundByQuery(change);
8684
+ if (entityMatchesQuery === true && !entityAlreadyInResults.length && this.isLoaded()) {
8588
8685
  if (!localEntity) {
8589
8686
  var newEntity = this.dataContext.entityAccess().add(this.entity, this.contextFilters);
8590
8687
  const pkeyName = change.tableName + 'Ref';
@@ -8601,7 +8698,7 @@ class TruDataChangeParser {
8601
8698
  reloadResults = true;
8602
8699
  }
8603
8700
  }
8604
- else if (!this.entityFoundByQuery(change) && entityAlreadyInResults.length) {
8701
+ else if (entityMatchesQuery === false && entityAlreadyInResults.length) {
8605
8702
  var entityToDelete = this.getEntityFromResults(results, change);
8606
8703
  if (entityToDelete.length) {
8607
8704
  results.splice(results.indexOf(entityAlreadyInResults[0]), 1);
@@ -8629,7 +8726,7 @@ class TruDataChangeParser {
8629
8726
  await this.getEntityFromServer(change).subscribe((entity) => {
8630
8727
  if (entity) {
8631
8728
  this.applyPropertyChanges(change, entity);
8632
- if (this.entityFoundByQuery(change) && this.isLoaded()) {
8729
+ if (this.entityFoundByQuery(change) === true && this.isLoaded()) {
8633
8730
  this.addEntity(newEntity);
8634
8731
  reloadResults = true;
8635
8732
  }
@@ -8646,7 +8743,7 @@ class TruDataChangeParser {
8646
8743
  const pkeyName2 = change.tableName + 'Ref';
8647
8744
  newEntity[pkeyName2] = change.tableRef;
8648
8745
  this.applyPropertyChanges(change, newEntity);
8649
- if (this.entityFoundByQuery(change) && this.isLoaded()) {
8746
+ if (this.entityFoundByQuery(change) === true && this.isLoaded()) {
8650
8747
  this.addEntity(newEntity);
8651
8748
  reloadResults = true;
8652
8749
  }
@@ -8953,23 +9050,6 @@ class TruDataGrid {
8953
9050
  this.api.refreshCells({ force: true });
8954
9051
  }
8955
9052
  };
8956
- refsEqual = (left, right) => {
8957
- return left !== null && left !== undefined &&
8958
- right !== null && right !== undefined &&
8959
- left.toString() === right.toString();
8960
- };
8961
- confirmRowMembershipBeforeRemoval = (rowNode) => {
8962
- const ref = rowNode.data?.$entity?.Ref;
8963
- if (ref === null || ref === undefined)
8964
- return;
8965
- this.dataContext.entityAccess().searchByRefWithQuery(this.config.resultConfig.entityType, this.latestSetupQuery, ref).subscribe((results) => {
8966
- if (results?.length)
8967
- return;
8968
- const currentRowNode = rowNode.id === undefined ? null : this.api?.getRowNode(rowNode.id);
8969
- if (currentRowNode)
8970
- this.api.applyTransaction({ remove: [currentRowNode.data] });
8971
- });
8972
- };
8973
9053
  subscribeTo = () => {
8974
9054
  this.subs.push(this.appEnvironment.onSaveComplete$.pipe(skip(1)).subscribe(event => {
8975
9055
  if (event?.successful)
@@ -9038,16 +9118,17 @@ class TruDataGrid {
9038
9118
  dataChange.dataChanges.forEach((change) => {
9039
9119
  if (change.changeOperation === 'D') {
9040
9120
  this.api.forEachNode((rowNode) => {
9041
- if (this.refsEqual(rowNode.data.$entity.Ref, change.tableRef))
9042
- rowNodesToRemove.push(rowNode.data);
9121
+ if (rowNode.data.$entity.Ref === change.tableRef) {
9122
+ rowNodesToRemove.push({ $entity: { Ref: rowNode.id } });
9123
+ }
9043
9124
  });
9044
9125
  }
9045
9126
  if (change.changeOperation === 'U' || change.changeOperation === 'I') {
9046
9127
  this.api.forEachNode((rowNode) => {
9047
- if (this.refsEqual(rowNode.data.$entity.Ref, change.tableRef)) {
9128
+ if (rowNode.data.$entity.Ref === change.tableRef) {
9048
9129
  let results = this.dataContext.entityAccess().searchByRefArrayCacheOnly(this.config.resultConfig.entityType, this.latestSetupQuery, [rowNode.data.$entity.Ref]);
9049
- if (!results)
9050
- this.confirmRowMembershipBeforeRemoval(rowNode);
9130
+ if (results === null)
9131
+ rowNodesToRemove.push({ $entity: { Ref: rowNode.id } });
9051
9132
  }
9052
9133
  });
9053
9134
  }