Merge branch 'dev' into release
This commit is contained in:
commit
0fa4d9c21d
15
es/store.js
15
es/store.js
|
|
@ -566,6 +566,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`);
|
||||
}
|
||||
|
|
|
|||
15
lib/store.js
15
lib/store.js
|
|
@ -568,6 +568,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`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-memory-tree-store",
|
||||
"version": "3.3.12",
|
||||
"version": "3.3.13",
|
||||
"description": "oak框架中内存级store的实现",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"es/**/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"oak-domain": "^5.1.24",
|
||||
"oak-domain": "^5.1.26",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
|||
17
src/store.ts
17
src/store.ts
|
|
@ -707,6 +707,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`);
|
||||
}
|
||||
|
|
@ -2281,7 +2296,7 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
}
|
||||
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)) {
|
||||
if ((row![UpdateAtAttribute] as number) <= (d[entity]![id]![UpdateAtAttribute] as number)) {
|
||||
this.updateAbjointRow(entity, {
|
||||
id: 'dummy',
|
||||
action: '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