@trudb/tru-common-lib 0.2.553 → 0.2.555
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) => {
|
|
@@ -8515,12 +8602,17 @@ class TruDataChangeParser {
|
|
|
8515
8602
|
};
|
|
8516
8603
|
entityFoundByQuery = (change) => {
|
|
8517
8604
|
var entityAccessor = this.dataContext.entityAccess();
|
|
8518
|
-
var
|
|
8519
|
-
|
|
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
|
-
|
|
8609
|
+
globalEntities = entityAccessor.searchByRefArrayCacheOnly(this.entity, this.getLatestQuery(), [change.tableRef]);
|
|
8522
8610
|
}
|
|
8523
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
}
|
|
@@ -9030,7 +9127,7 @@ class TruDataGrid {
|
|
|
9030
9127
|
this.api.forEachNode((rowNode) => {
|
|
9031
9128
|
if (rowNode.data.$entity.Ref === change.tableRef) {
|
|
9032
9129
|
let results = this.dataContext.entityAccess().searchByRefArrayCacheOnly(this.config.resultConfig.entityType, this.latestSetupQuery, [rowNode.data.$entity.Ref]);
|
|
9033
|
-
if (
|
|
9130
|
+
if (results === null)
|
|
9034
9131
|
rowNodesToRemove.push({ $entity: { Ref: rowNode.id } });
|
|
9035
9132
|
}
|
|
9036
9133
|
});
|