Compare commits
7 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
2fd9a46011 | |
|
|
afe81e3fbb | |
|
|
0fc00a02b4 | |
|
|
a547f1d890 | |
|
|
b51889c9a9 | |
|
|
c82bf99fdb | |
|
|
5b5621216f |
26
es/store.js
26
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') {
|
||||
|
|
|
|||
26
lib/store.js
26
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') {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-memory-tree-store",
|
||||
"version": "3.3.13",
|
||||
"version": "3.3.15",
|
||||
"description": "oak框架中内存级store的实现",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"es/**/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"oak-domain": "^5.1.26",
|
||||
"oak-domain": "file:../oak-domain",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
|||
25
src/store.ts
25
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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue