Compare commits
19 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
2fd9a46011 | |
|
|
afe81e3fbb | |
|
|
0fc00a02b4 | |
|
|
a547f1d890 | |
|
|
b51889c9a9 | |
|
|
c82bf99fdb | |
|
|
5b5621216f | |
|
|
44d0df03cb | |
|
|
aa77a03f30 | |
|
|
ff0fcc8492 | |
|
|
e36cf430cf | |
|
|
a70f584e08 | |
|
|
b87d912388 | |
|
|
0f1b9168ac | |
|
|
17380fa8f9 | |
|
|
3b6ddbe317 | |
|
|
8cb729ad26 | |
|
|
7a5cfda18c | |
|
|
2dd4736907 |
80
es/store.js
80
es/store.js
|
|
@ -5,6 +5,7 @@ import { EXPRESSION_PREFIX, SUB_QUERY_PREDICATE_KEYWORD } from 'oak-domain/lib/t
|
|||
import { OakCongruentRowExists, OakException } from 'oak-domain/lib/types/Exception';
|
||||
import { isRefAttrNode } from 'oak-domain/lib/types/Demand';
|
||||
import { judgeRelation } from 'oak-domain/lib/store/relation';
|
||||
// Expression引入,下方声明改为any防止报错
|
||||
import { execOp, isExpression, opMultipleParams } from 'oak-domain/lib/types/Expression';
|
||||
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
||||
import { CascadeStore, polishSelection } from 'oak-domain/lib/store/CascadeStore';
|
||||
|
|
@ -146,13 +147,12 @@ export default class TreeStore extends CascadeStore {
|
|||
this.seq = {};
|
||||
}
|
||||
constructRow(node, context, option) {
|
||||
let data = cloneDeep(node.$current);
|
||||
if (context.getCurrentTxnId() && node.$txnId === context.getCurrentTxnId()) {
|
||||
if (!node.$next) {
|
||||
// 如果要求返回delete数据,返回带$$deleteAt$$的行
|
||||
// bug fixed,这里如果是自己create再删除,data也是null
|
||||
if (data && option?.includedDeleted) {
|
||||
return Object.assign({}, data, {
|
||||
if (node.$current && option?.includedDeleted) {
|
||||
return Object.assign({}, node.$current, {
|
||||
[DeleteAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
|
|
@ -160,19 +160,21 @@ export default class TreeStore extends CascadeStore {
|
|||
}
|
||||
else if (!node.$current) {
|
||||
// 本事务创建的,若在cache中$$createAt$$和$$updateAt$$置为1
|
||||
return Object.assign({}, data, node.$next, context instanceof SyncContext && {
|
||||
return Object.assign({}, node.$current, node.$next, context instanceof SyncContext && {
|
||||
[CreateAtAttribute]: 1,
|
||||
[UpdateAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 本事务更新的,若在cache中$$updateAt$$置为1
|
||||
return Object.assign({}, data, node.$next, context instanceof SyncContext && {
|
||||
return Object.assign({}, node.$current, node.$next, context instanceof SyncContext && {
|
||||
[UpdateAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
return data;
|
||||
return {
|
||||
...node.$current,
|
||||
};
|
||||
}
|
||||
testFilterFns(node, nodeDict, exprResolveFns, fns) {
|
||||
const { self, otm, mto } = fns;
|
||||
|
|
@ -290,12 +292,16 @@ export default class TreeStore extends CascadeStore {
|
|||
* @param context
|
||||
* @returns
|
||||
*/
|
||||
translateExpressionNode(entity, expression, context, option) {
|
||||
translateExpressionNode(entity,
|
||||
// expression: Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']> | ExpressionConstant,
|
||||
expression, context, option) {
|
||||
if (isExpression(expression)) {
|
||||
const op = Object.keys(expression)[0];
|
||||
const option2 = expression[op];
|
||||
if (opMultipleParams(op)) {
|
||||
const paramsTranslated = option2.map(ele => this.translateExpressionNode(entity, ele, context, option2));
|
||||
const paramsTranslated = option2.map(
|
||||
// const paramsTranslated = (option2 as (Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']>)[]).map(
|
||||
ele => this.translateExpressionNode(entity, ele, context, option2));
|
||||
return (row, nodeDict) => {
|
||||
let later = false;
|
||||
let results = paramsTranslated.map((ele) => {
|
||||
|
|
@ -385,7 +391,9 @@ export default class TreeStore extends CascadeStore {
|
|||
return expression;
|
||||
}
|
||||
}
|
||||
translateExpression(entity, expression, context, option) {
|
||||
translateExpression(entity,
|
||||
// expression: Expression<keyof ED[T]['Schema']>,
|
||||
expression, context, option) {
|
||||
const expr = this.translateExpressionNode(entity, expression, context, option);
|
||||
return (row, nodeDict) => {
|
||||
if (typeof expr !== 'function') {
|
||||
|
|
@ -566,6 +574,21 @@ export default class TreeStore extends CascadeStore {
|
|||
}).length > 0;
|
||||
};
|
||||
}
|
||||
case '$length': {
|
||||
// json中的数组长度查询
|
||||
const length = value;
|
||||
return (row) => {
|
||||
const data = path ? get(row, path) : row;
|
||||
assert(data instanceof Array, '$length operator can only used on array attribute');
|
||||
if (typeof length === 'number') {
|
||||
return data.length === length;
|
||||
}
|
||||
else {
|
||||
const op = Object.keys(length)[0];
|
||||
return this.translatePredicate(entity, 'length', op, length[op], option)(data);
|
||||
}
|
||||
};
|
||||
}
|
||||
default: {
|
||||
throw new Error(`predicate ${predicate} is not recoganized`);
|
||||
}
|
||||
|
|
@ -1460,7 +1483,7 @@ export default class TreeStore extends CascadeStore {
|
|||
else {
|
||||
assert([0, 1].includes(rel));
|
||||
result2[k] = row2[k];
|
||||
assert(['string', 'number', 'boolean'].includes(typeof row2[k]));
|
||||
assert(['string', 'number', 'boolean'].includes(typeof row2[k]) || row2[k] === null);
|
||||
key += `${row2[k]}`;
|
||||
values.push(row2[k]);
|
||||
}
|
||||
|
|
@ -1558,8 +1581,9 @@ export default class TreeStore extends CascadeStore {
|
|||
result[op] = 0;
|
||||
const data = distinct ? uniq(results[op]) : results[op];
|
||||
data.forEach((ele) => {
|
||||
assert(typeof ele === 'number', '只有number类型的属性才可以计算sum');
|
||||
result[op] += ele;
|
||||
if (typeof ele === 'number') {
|
||||
result[op] += ele;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (op.startsWith('#count')) {
|
||||
|
|
@ -1574,11 +1598,14 @@ export default class TreeStore extends CascadeStore {
|
|||
else if (op.startsWith('#avg')) {
|
||||
result[op] = 0;
|
||||
const data = (distinct ? uniq(results[op]) : results[op]).filter(ele => ![undefined, null].includes(ele));
|
||||
let count = 0;
|
||||
data.forEach((ele) => {
|
||||
assert(typeof ele === 'number', '只有number类型的属性才可以计算avg');
|
||||
result[op] += ele;
|
||||
if (typeof ele === 'number') {
|
||||
result[op] += ele;
|
||||
count += 1;
|
||||
}
|
||||
});
|
||||
result[op] = result[op] / data.length;
|
||||
result[op] = result[op] / count;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
@ -1898,16 +1925,19 @@ export default class TreeStore extends CascadeStore {
|
|||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'create');
|
||||
}
|
||||
else if (this.store[entity][id].$current?.[UpdateAtAttribute] <= d[entity][id][UpdateAtAttribute]) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: 'update',
|
||||
data: d[entity][id],
|
||||
filter: {
|
||||
id,
|
||||
},
|
||||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'update');
|
||||
else if (this.store[entity]?.[id]) {
|
||||
const row = this.constructRow(this.store[entity][id], context);
|
||||
if (row[UpdateAtAttribute] <= d[entity][id][UpdateAtAttribute]) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: 'update',
|
||||
data: d[entity][id],
|
||||
filter: {
|
||||
id,
|
||||
},
|
||||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'update');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
80
lib/store.js
80
lib/store.js
|
|
@ -7,6 +7,7 @@ const Demand_1 = require("oak-domain/lib/types/Demand");
|
|||
const Exception_1 = require("oak-domain/lib/types/Exception");
|
||||
const Demand_2 = require("oak-domain/lib/types/Demand");
|
||||
const relation_1 = require("oak-domain/lib/store/relation");
|
||||
// Expression引入,下方声明改为any防止报错
|
||||
const Expression_1 = require("oak-domain/lib/types/Expression");
|
||||
const SyncRowStore_1 = require("oak-domain/lib/store/SyncRowStore");
|
||||
const CascadeStore_1 = require("oak-domain/lib/store/CascadeStore");
|
||||
|
|
@ -148,13 +149,12 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
this.seq = {};
|
||||
}
|
||||
constructRow(node, context, option) {
|
||||
let data = (0, lodash_1.cloneDeep)(node.$current);
|
||||
if (context.getCurrentTxnId() && node.$txnId === context.getCurrentTxnId()) {
|
||||
if (!node.$next) {
|
||||
// 如果要求返回delete数据,返回带$$deleteAt$$的行
|
||||
// bug fixed,这里如果是自己create再删除,data也是null
|
||||
if (data && option?.includedDeleted) {
|
||||
return Object.assign({}, data, {
|
||||
if (node.$current && option?.includedDeleted) {
|
||||
return Object.assign({}, node.$current, {
|
||||
[Entity_1.DeleteAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
|
|
@ -162,19 +162,21 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
}
|
||||
else if (!node.$current) {
|
||||
// 本事务创建的,若在cache中$$createAt$$和$$updateAt$$置为1
|
||||
return Object.assign({}, data, node.$next, context instanceof SyncRowStore_1.SyncContext && {
|
||||
return Object.assign({}, node.$current, node.$next, context instanceof SyncRowStore_1.SyncContext && {
|
||||
[Entity_1.CreateAtAttribute]: 1,
|
||||
[Entity_1.UpdateAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 本事务更新的,若在cache中$$updateAt$$置为1
|
||||
return Object.assign({}, data, node.$next, context instanceof SyncRowStore_1.SyncContext && {
|
||||
return Object.assign({}, node.$current, node.$next, context instanceof SyncRowStore_1.SyncContext && {
|
||||
[Entity_1.UpdateAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
return data;
|
||||
return {
|
||||
...node.$current,
|
||||
};
|
||||
}
|
||||
testFilterFns(node, nodeDict, exprResolveFns, fns) {
|
||||
const { self, otm, mto } = fns;
|
||||
|
|
@ -292,12 +294,16 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
* @param context
|
||||
* @returns
|
||||
*/
|
||||
translateExpressionNode(entity, expression, context, option) {
|
||||
translateExpressionNode(entity,
|
||||
// expression: Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']> | ExpressionConstant,
|
||||
expression, context, option) {
|
||||
if ((0, Expression_1.isExpression)(expression)) {
|
||||
const op = Object.keys(expression)[0];
|
||||
const option2 = expression[op];
|
||||
if ((0, Expression_1.opMultipleParams)(op)) {
|
||||
const paramsTranslated = option2.map(ele => this.translateExpressionNode(entity, ele, context, option2));
|
||||
const paramsTranslated = option2.map(
|
||||
// const paramsTranslated = (option2 as (Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']>)[]).map(
|
||||
ele => this.translateExpressionNode(entity, ele, context, option2));
|
||||
return (row, nodeDict) => {
|
||||
let later = false;
|
||||
let results = paramsTranslated.map((ele) => {
|
||||
|
|
@ -387,7 +393,9 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
return expression;
|
||||
}
|
||||
}
|
||||
translateExpression(entity, expression, context, option) {
|
||||
translateExpression(entity,
|
||||
// expression: Expression<keyof ED[T]['Schema']>,
|
||||
expression, context, option) {
|
||||
const expr = this.translateExpressionNode(entity, expression, context, option);
|
||||
return (row, nodeDict) => {
|
||||
if (typeof expr !== 'function') {
|
||||
|
|
@ -568,6 +576,21 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
}).length > 0;
|
||||
};
|
||||
}
|
||||
case '$length': {
|
||||
// json中的数组长度查询
|
||||
const length = value;
|
||||
return (row) => {
|
||||
const data = path ? (0, lodash_1.get)(row, path) : row;
|
||||
(0, assert_1.assert)(data instanceof Array, '$length operator can only used on array attribute');
|
||||
if (typeof length === 'number') {
|
||||
return data.length === length;
|
||||
}
|
||||
else {
|
||||
const op = Object.keys(length)[0];
|
||||
return this.translatePredicate(entity, 'length', op, length[op], option)(data);
|
||||
}
|
||||
};
|
||||
}
|
||||
default: {
|
||||
throw new Error(`predicate ${predicate} is not recoganized`);
|
||||
}
|
||||
|
|
@ -1462,7 +1485,7 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
else {
|
||||
(0, assert_1.assert)([0, 1].includes(rel));
|
||||
result2[k] = row2[k];
|
||||
(0, assert_1.assert)(['string', 'number', 'boolean'].includes(typeof row2[k]));
|
||||
(0, assert_1.assert)(['string', 'number', 'boolean'].includes(typeof row2[k]) || row2[k] === null);
|
||||
key += `${row2[k]}`;
|
||||
values.push(row2[k]);
|
||||
}
|
||||
|
|
@ -1560,8 +1583,9 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
result[op] = 0;
|
||||
const data = distinct ? (0, lodash_1.uniq)(results[op]) : results[op];
|
||||
data.forEach((ele) => {
|
||||
(0, assert_1.assert)(typeof ele === 'number', '只有number类型的属性才可以计算sum');
|
||||
result[op] += ele;
|
||||
if (typeof ele === 'number') {
|
||||
result[op] += ele;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (op.startsWith('#count')) {
|
||||
|
|
@ -1576,11 +1600,14 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
else if (op.startsWith('#avg')) {
|
||||
result[op] = 0;
|
||||
const data = (distinct ? (0, lodash_1.uniq)(results[op]) : results[op]).filter(ele => ![undefined, null].includes(ele));
|
||||
let count = 0;
|
||||
data.forEach((ele) => {
|
||||
(0, assert_1.assert)(typeof ele === 'number', '只有number类型的属性才可以计算avg');
|
||||
result[op] += ele;
|
||||
if (typeof ele === 'number') {
|
||||
result[op] += ele;
|
||||
count += 1;
|
||||
}
|
||||
});
|
||||
result[op] = result[op] / data.length;
|
||||
result[op] = result[op] / count;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
@ -1900,16 +1927,19 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'create');
|
||||
}
|
||||
else if (this.store[entity][id].$current?.[Entity_1.UpdateAtAttribute] <= d[entity][id][Entity_1.UpdateAtAttribute]) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: 'update',
|
||||
data: d[entity][id],
|
||||
filter: {
|
||||
id,
|
||||
},
|
||||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'update');
|
||||
else if (this.store[entity]?.[id]) {
|
||||
const row = this.constructRow(this.store[entity][id], context);
|
||||
if (row[Entity_1.UpdateAtAttribute] <= d[entity][id][Entity_1.UpdateAtAttribute]) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: 'update',
|
||||
data: d[entity][id],
|
||||
filter: {
|
||||
id,
|
||||
},
|
||||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'update');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-memory-tree-store",
|
||||
"version": "3.3.10",
|
||||
"version": "3.3.15",
|
||||
"description": "oak框架中内存级store的实现",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"es/**/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"oak-domain": "^5.1.20",
|
||||
"oak-domain": "file:../oak-domain",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
|||
79
src/store.ts
79
src/store.ts
|
|
@ -15,6 +15,7 @@ import { StorageSchema } from 'oak-domain/lib/types/Storage';
|
|||
import { ExprResolveFn, NodeDict, RowNode } from "./types/type";
|
||||
import { isRefAttrNode, Q_BooleanValue, Q_FullTextValue, Q_NumberValue, Q_StringValue } from 'oak-domain/lib/types/Demand';
|
||||
import { judgeRelation } from 'oak-domain/lib/store/relation';
|
||||
// Expression引入,下方声明改为any防止报错
|
||||
import { execOp, Expression, ExpressionConstant, isExpression, opMultipleParams } from 'oak-domain/lib/types/Expression';
|
||||
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
||||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||||
|
|
@ -219,13 +220,12 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
}
|
||||
|
||||
private constructRow<Cxt extends Context, OP extends TreeStoreSelectOption>(node: RowNode, context: Cxt, option?: OP) {
|
||||
let data = cloneDeep(node.$current);
|
||||
if (context.getCurrentTxnId() && node.$txnId === context.getCurrentTxnId()) {
|
||||
if (!node.$next) {
|
||||
// 如果要求返回delete数据,返回带$$deleteAt$$的行
|
||||
// bug fixed,这里如果是自己create再删除,data也是null
|
||||
if (data && option?.includedDeleted) {
|
||||
return Object.assign({}, data, {
|
||||
if (node.$current && option?.includedDeleted) {
|
||||
return Object.assign({}, node.$current, {
|
||||
[DeleteAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
|
|
@ -233,19 +233,21 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
}
|
||||
else if (!node.$current) {
|
||||
// 本事务创建的,若在cache中$$createAt$$和$$updateAt$$置为1
|
||||
return Object.assign({}, data, node.$next, context instanceof SyncContext && {
|
||||
return Object.assign({}, node.$current, node.$next, context instanceof SyncContext && {
|
||||
[CreateAtAttribute]: 1,
|
||||
[UpdateAtAttribute]: 1,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// 本事务更新的,若在cache中$$updateAt$$置为1
|
||||
return Object.assign({}, data, node.$next, context instanceof SyncContext && {
|
||||
return Object.assign({}, node.$current, node.$next, context instanceof SyncContext && {
|
||||
[UpdateAtAttribute]: 1,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
return data;
|
||||
return {
|
||||
...node.$current,
|
||||
};
|
||||
}
|
||||
|
||||
private testFilterFns(
|
||||
|
|
@ -397,7 +399,8 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
*/
|
||||
private translateExpressionNode<T extends keyof ED, OP extends TreeStoreSelectOption, Cxt extends Context>(
|
||||
entity: T,
|
||||
expression: Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']> | ExpressionConstant,
|
||||
// expression: Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']> | ExpressionConstant,
|
||||
expression: any,
|
||||
context: Cxt,
|
||||
option?: OP): ExprNodeTranslator | ExpressionConstant {
|
||||
|
||||
|
|
@ -406,7 +409,8 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
const option2 = (expression as any)[op];
|
||||
|
||||
if (opMultipleParams(op)) {
|
||||
const paramsTranslated = (option2 as (Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']>)[]).map(
|
||||
const paramsTranslated = (option2 as any[]).map(
|
||||
// const paramsTranslated = (option2 as (Expression<keyof ED[T]['Schema']> | RefAttr<keyof ED[T]['Schema']>)[]).map(
|
||||
ele => this.translateExpressionNode(entity, ele, context, option2)
|
||||
);
|
||||
|
||||
|
|
@ -514,7 +518,8 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
|
||||
private translateExpression<T extends keyof ED, OP extends TreeStoreSelectOption, Cxt extends Context>(
|
||||
entity: T,
|
||||
expression: Expression<keyof ED[T]['Schema']>,
|
||||
// expression: Expression<keyof ED[T]['Schema']>,
|
||||
expression: any,
|
||||
context: Cxt, option?: OP): (row: Partial<ED[T]['OpSchema']>, nodeDict: NodeDict) => ExpressionConstant | ExprLaterCheckFn {
|
||||
const expr = this.translateExpressionNode(entity, expression, context, option);
|
||||
|
||||
|
|
@ -707,6 +712,21 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
}).length > 0;
|
||||
};
|
||||
}
|
||||
case '$length': {
|
||||
// json中的数组长度查询
|
||||
const length = value;
|
||||
return (row) => {
|
||||
const data = path ? get(row, path) : row;
|
||||
assert(data instanceof Array, '$length operator can only used on array attribute');
|
||||
if (typeof length === 'number') {
|
||||
return data.length === length;
|
||||
}
|
||||
else {
|
||||
const op = Object.keys(length)[0];
|
||||
return this.translatePredicate(entity, 'length', op, length[op], option)(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
default: {
|
||||
throw new Error(`predicate ${predicate} is not recoganized`);
|
||||
}
|
||||
|
|
@ -1749,7 +1769,7 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
else {
|
||||
assert([0, 1].includes(rel as number));
|
||||
(result2 as any)[k] = row2[k];
|
||||
assert(['string', 'number', 'boolean'].includes(typeof row2[k]));
|
||||
assert(['string', 'number', 'boolean'].includes(typeof row2[k]) || row2[k] === null);
|
||||
key += `${row2[k]}`;
|
||||
values.push(row2[k]);
|
||||
}
|
||||
|
|
@ -1860,8 +1880,9 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
const data = distinct ? uniq(results[op]) : results[op];
|
||||
data.forEach(
|
||||
(ele) => {
|
||||
assert(typeof ele === 'number', '只有number类型的属性才可以计算sum');
|
||||
result[op] += ele;
|
||||
if (typeof ele === 'number') {
|
||||
result[op] += ele;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -1881,13 +1902,16 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
const data = (distinct ? uniq(results[op]) : results[op]).filter(
|
||||
ele => ![undefined, null].includes(ele)
|
||||
);
|
||||
let count = 0;
|
||||
data.forEach(
|
||||
(ele) => {
|
||||
assert(typeof ele === 'number', '只有number类型的属性才可以计算avg');
|
||||
result[op] += ele;
|
||||
if (typeof ele === 'number') {
|
||||
result[op] += ele;
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
result[op] = result[op]/data.length;
|
||||
result[op] = result[op]/count;
|
||||
}
|
||||
}
|
||||
return result as AggregationResult<ED[T]['Schema']>[number];
|
||||
|
|
@ -2275,16 +2299,19 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
} as ED[keyof ED]['CreateSingle'], context, option2);
|
||||
this.addToOperationResult(result, entity, 'create');
|
||||
}
|
||||
else if (this.store[entity]![id].$current?.[UpdateAtAttribute]! <= d[entity]![id]![UpdateAtAttribute]!) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: 'update',
|
||||
data: d[entity]![id] as any,
|
||||
filter: {
|
||||
id,
|
||||
} as any,
|
||||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'update');
|
||||
else if (this.store[entity]?.[id]) {
|
||||
const row = this.constructRow(this.store[entity]![id]!, context);
|
||||
if ((row![UpdateAtAttribute] as number) <= (d[entity]![id]![UpdateAtAttribute] as number)) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: 'update',
|
||||
data: d[entity]![id] as any,
|
||||
filter: {
|
||||
id,
|
||||
} as any,
|
||||
}, context, option2);
|
||||
this.addToOperationResult(result, entity, 'update');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
test/test.ts
39
test/test.ts
|
|
@ -1317,6 +1317,43 @@ describe('基础测试', function () {
|
|||
}
|
||||
}, context, {});
|
||||
|
||||
const row12 = store.select('oper', {
|
||||
data: {
|
||||
id: 1,
|
||||
data: {
|
||||
name: 1,
|
||||
price: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
data: {
|
||||
price: {
|
||||
$length: 3,
|
||||
},
|
||||
}
|
||||
}
|
||||
}, context, {});
|
||||
|
||||
const row13 = store.select('oper', {
|
||||
data: {
|
||||
id: 1,
|
||||
data: {
|
||||
name: 1,
|
||||
price: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
data: {
|
||||
price: {
|
||||
$length: {
|
||||
$gt: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}, context, {});
|
||||
context.commit();
|
||||
assert(row.length === 1);
|
||||
assert(row2.length === 0);
|
||||
|
|
@ -1329,6 +1366,8 @@ describe('基础测试', function () {
|
|||
assert(row9.length === 1);
|
||||
assert(row10.length === 1);
|
||||
assert(row11.length === 0);
|
||||
assert(row12.length === 1);
|
||||
assert(row13.length === 0);
|
||||
// console.log(JSON.stringify(row7));
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue