oak-domain 6.1.0 → 6.1.2
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.
- package/es/base-app-domain/ActionDefDict.d.ts +1 -0
- package/es/base-app-domain/ActionDefDict.js +3 -1
- package/es/base-app-domain/EntityDict.d.ts +86 -1
- package/es/base-app-domain/Log/Storage.js +4 -0
- package/es/base-app-domain/Log/_baseSchema.d.ts +5 -0
- package/es/base-app-domain/Storage.js +3 -1
- package/es/base-app-domain/StyleDict.js +3 -1
- package/es/base-app-domain/Version/Action.d.ts +6 -0
- package/es/base-app-domain/Version/Action.js +2 -0
- package/es/base-app-domain/Version/Schema.d.ts +19 -0
- package/es/base-app-domain/Version/Schema.js +1 -0
- package/es/base-app-domain/Version/Storage.d.ts +3 -0
- package/es/base-app-domain/Version/Storage.js +54 -0
- package/es/base-app-domain/Version/Style.d.ts +3 -0
- package/es/base-app-domain/Version/Style.js +6 -0
- package/es/base-app-domain/Version/_baseSchema.d.ts +57 -0
- package/es/base-app-domain/Version/_baseSchema.js +1 -0
- package/es/compiler/dependencyBuilder.d.ts +1 -0
- package/es/compiler/dependencyBuilder.js +173 -55
- package/es/compiler/routerBuilder.d.ts +4 -1
- package/es/compiler/routerBuilder.js +22 -19
- package/es/compiler/schemaBuilder.d.ts +5 -1
- package/es/compiler/schemaBuilder.js +10 -0
- package/es/context/BackendRuntimeContext.d.ts +9 -1
- package/es/context/BackendRuntimeContext.js +13 -1
- package/es/entities/Log.d.ts +2 -0
- package/es/entities/Log.js +2 -0
- package/es/entities/Version.d.ts +14 -0
- package/es/entities/Version.js +42 -0
- package/es/store/AsyncRowStore.d.ts +4 -1
- package/es/store/AsyncRowStore.js +7 -0
- package/es/store/CascadeStore.js +22 -0
- package/es/store/RelationAuth/authorizationFilter.d.ts +11 -0
- package/es/store/RelationAuth/authorizationFilter.js +104 -0
- package/es/store/RelationAuth/continuation.d.ts +9 -0
- package/es/store/RelationAuth/continuation.js +33 -0
- package/es/store/RelationAuth/index.d.ts +141 -0
- package/es/store/RelationAuth/index.js +1440 -0
- package/es/store/RelationAuth/model.d.ts +38 -0
- package/es/store/RelationAuth/model.js +24 -0
- package/es/store/RelationAuth/userLookup.d.ts +21 -0
- package/es/store/RelationAuth/userLookup.js +102 -0
- package/es/store/SyncRowStore.d.ts +2 -1
- package/es/store/SyncRowStore.js +3 -0
- package/es/store/filter.fix.d.ts +128 -0
- package/es/store/filter.fix.js +2862 -0
- package/es/store/filter.js +14 -9
- package/es/store/triggers.js +239 -44
- package/es/types/Context.d.ts +2 -1
- package/es/types/Demand.d.ts +11 -1
- package/es/types/Environment.d.ts +13 -2
- package/es/types/Exception.d.ts +3 -3
- package/es/types/Exception.js +25 -22
- package/es/types/Expression.d.ts +4 -1
- package/es/types/Expression.js +1 -1
- package/es/types/Storage.d.ts +15 -2
- package/es/utils/SimpleConnector.js +5 -2
- package/es/utils/decimal.js +2 -1
- package/es/utils/fetch/index.ali.d.ts +3 -0
- package/es/utils/fetch/index.ali.js +31 -0
- package/es/utils/fetch/index.d.ts +3 -0
- package/es/utils/fetch/index.js +5 -0
- package/es/utils/fetch/index.mp.d.ts +5 -3
- package/es/utils/fetch/index.mp.js +5 -280
- package/es/utils/fetch/index.wechat.d.ts +5 -0
- package/es/utils/fetch/index.wechat.js +174 -0
- package/es/utils/fetch/mini-program.shared.d.ts +37 -0
- package/es/utils/fetch/mini-program.shared.js +85 -0
- package/es/utils/geo.d.ts +1 -1
- package/es/utils/geo.js +1 -1
- package/es/utils/random/random.ali.d.ts +6 -0
- package/es/utils/random/random.ali.js +21 -0
- package/es/utils/random/random.mp.d.ts +5 -1
- package/es/utils/random/random.mp.js +11 -5
- package/es/utils/random/random.native.d.ts +1 -1
- package/es/utils/random/random.native.js +7 -4
- package/es/utils/random/random.wechat.d.ts +1 -0
- package/es/utils/random/random.wechat.js +10 -0
- package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
- package/lib/base-app-domain/ActionDefDict.js +3 -1
- package/lib/base-app-domain/EntityDict.d.ts +86 -1
- package/lib/base-app-domain/Log/Storage.js +4 -0
- package/lib/base-app-domain/Log/_baseSchema.d.ts +5 -0
- package/lib/base-app-domain/Storage.js +3 -1
- package/lib/base-app-domain/StyleDict.js +3 -1
- package/lib/base-app-domain/Version/Action.d.ts +6 -0
- package/lib/base-app-domain/Version/Action.js +5 -0
- package/lib/base-app-domain/Version/Schema.d.ts +19 -0
- package/lib/base-app-domain/Version/Schema.js +4 -0
- package/lib/base-app-domain/Version/Storage.d.ts +3 -0
- package/lib/base-app-domain/Version/Storage.js +57 -0
- package/lib/base-app-domain/Version/Style.d.ts +3 -0
- package/lib/base-app-domain/Version/Style.js +9 -0
- package/lib/base-app-domain/Version/_baseSchema.d.ts +57 -0
- package/lib/base-app-domain/Version/_baseSchema.js +2 -0
- package/lib/compiler/dependencyBuilder.d.ts +1 -0
- package/lib/compiler/dependencyBuilder.js +173 -54
- package/lib/compiler/routerBuilder.d.ts +4 -1
- package/lib/compiler/routerBuilder.js +22 -19
- package/lib/compiler/schemaBuilder.d.ts +5 -1
- package/lib/compiler/schemaBuilder.js +10 -0
- package/lib/context/BackendRuntimeContext.d.ts +9 -1
- package/lib/context/BackendRuntimeContext.js +13 -1
- package/lib/entities/Log.d.ts +2 -0
- package/lib/entities/Log.js +2 -0
- package/lib/entities/Version.d.ts +14 -0
- package/lib/entities/Version.js +43 -0
- package/lib/store/AsyncRowStore.d.ts +4 -1
- package/lib/store/AsyncRowStore.js +7 -0
- package/lib/store/CascadeStore.js +22 -0
- package/lib/store/RelationAuth/authorizationFilter.d.ts +11 -0
- package/lib/store/RelationAuth/authorizationFilter.js +110 -0
- package/lib/store/RelationAuth/continuation.d.ts +9 -0
- package/lib/store/RelationAuth/continuation.js +37 -0
- package/lib/store/RelationAuth/index.d.ts +141 -0
- package/lib/store/RelationAuth/index.js +1445 -0
- package/lib/store/RelationAuth/model.d.ts +38 -0
- package/lib/store/RelationAuth/model.js +27 -0
- package/lib/store/RelationAuth/userLookup.d.ts +21 -0
- package/lib/store/RelationAuth/userLookup.js +105 -0
- package/lib/store/SyncRowStore.d.ts +2 -1
- package/lib/store/SyncRowStore.js +3 -0
- package/lib/store/filter.fix.d.ts +128 -0
- package/lib/store/filter.fix.js +2876 -0
- package/lib/store/filter.js +14 -9
- package/lib/store/triggers.js +239 -44
- package/lib/types/Context.d.ts +2 -1
- package/lib/types/Demand.d.ts +11 -1
- package/lib/types/Environment.d.ts +13 -2
- package/lib/types/Exception.d.ts +3 -3
- package/lib/types/Exception.js +25 -22
- package/lib/types/Expression.d.ts +4 -1
- package/lib/types/Expression.js +1 -1
- package/lib/types/Storage.d.ts +15 -2
- package/lib/utils/SimpleConnector.js +5 -2
- package/lib/utils/decimal.js +2 -1
- package/lib/utils/fetch/index.ali.d.ts +3 -0
- package/lib/utils/fetch/index.ali.js +36 -0
- package/lib/utils/fetch/index.d.ts +3 -0
- package/lib/utils/fetch/index.js +7 -0
- package/lib/utils/fetch/index.mp.d.ts +5 -3
- package/lib/utils/fetch/index.mp.js +5 -282
- package/lib/utils/fetch/index.wechat.d.ts +5 -0
- package/lib/utils/fetch/index.wechat.js +180 -0
- package/lib/utils/fetch/mini-program.shared.d.ts +37 -0
- package/lib/utils/fetch/mini-program.shared.js +96 -0
- package/lib/utils/geo.d.ts +1 -1
- package/lib/utils/geo.js +1 -1
- package/lib/utils/random/random.ali.d.ts +6 -0
- package/lib/utils/random/random.ali.js +24 -0
- package/lib/utils/random/random.mp.d.ts +5 -1
- package/lib/utils/random/random.mp.js +11 -5
- package/lib/utils/random/random.native.d.ts +1 -1
- package/lib/utils/random/random.native.js +7 -5
- package/lib/utils/random/random.wechat.d.ts +1 -0
- package/lib/utils/random/random.wechat.js +13 -0
- package/package.json +8 -5
- package/es/store/RelationAuth.d.ts +0 -115
- package/es/store/RelationAuth.js +0 -1340
- package/lib/store/RelationAuth.d.ts +0 -115
- package/lib/store/RelationAuth.js +0 -1345
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EntityDict } from '../../base-app-domain';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from '../../types/Entity';
|
|
3
|
+
export type OperationTree<ED extends EntityDict & BaseEntityDict> = {
|
|
4
|
+
entity: keyof ED;
|
|
5
|
+
action: ED[keyof ED]['Action'];
|
|
6
|
+
filter: ED[keyof ED]['Filter'];
|
|
7
|
+
children: Record<string, OperationTree<ED> | OperationTree<ED>[]>;
|
|
8
|
+
userRelations?: ED['userRelation']['OpSchema'][];
|
|
9
|
+
};
|
|
10
|
+
/** 读路径上一个节点的授权任务:行集(根filter ∧ 各层filter侧约束 ∧ 本节点filter) ⊆ Auth(entity,'select') */
|
|
11
|
+
export type ReadTask<ED extends EntityDict & BaseEntityDict> = {
|
|
12
|
+
entity: keyof ED;
|
|
13
|
+
filter: ED[keyof ED]['Filter'];
|
|
14
|
+
/** 本节点自身位于 selectFreeEntities(只豁免自身,D4) */
|
|
15
|
+
exempt: boolean;
|
|
16
|
+
/** 树父实体(根任务为 undefined),用于 E2 扩展路径派生 */
|
|
17
|
+
parentEntity?: keyof ED;
|
|
18
|
+
/** 父投影中连接本节点的边属性名,如 'comment$post' */
|
|
19
|
+
edgeAttr?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* I5 唯一策略谓词:当前实体上某属性所成边的授权语义。
|
|
23
|
+
* - deduce:多态 entity 外键折算边(实体在 authDeduceRelationMap 且属性为 'entity')——
|
|
24
|
+
* 该实体不作为独立节点检查,权限折算为其所指父对象的权限(§5.3)。
|
|
25
|
+
* - otm:一对多反向边——OTM 投影即行集查询,目标节点必须独立受权(D1/D2)。
|
|
26
|
+
* - mto:多对一正向外键——目标行由本行外键唯一确定,是"本行属性展开",不构成授权事实(D5)。
|
|
27
|
+
* - plain:原生属性;polymorphic:多态反指但目标不在折算表(保守,独立受权)。
|
|
28
|
+
*/
|
|
29
|
+
export type EdgeRule = 'deduce' | 'otm' | 'mto' | 'polymorphic' | 'plain';
|
|
30
|
+
/**
|
|
31
|
+
* I8 边传播唯一原语:已知树父实体上一条通过判定的授权路径(value 自父实体走向当前
|
|
32
|
+
* user),派生它对树子实体的扩展路径。返回 undefined 表示无扩展见证(回落子实体
|
|
33
|
+
* 自身的包含性判定,E2 数据见证 / E3 禁止合成)。
|
|
34
|
+
*
|
|
35
|
+
* @param rule 边方向(自子实体视角的 edgeRuleOf(childEntity, 子指向父的边属性名))
|
|
36
|
+
* @param edgeName 子指向父的边属性名(OTM `'comment$post'` 的 `$post`;MTO 即该外键属性名)
|
|
37
|
+
*/
|
|
38
|
+
export declare function deriveChildPath(rule: EdgeRule, edgeName: string, parentPathValue: string): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* I8 边传播唯一原语:已知树父实体上一条通过判定的授权路径(value 自父实体走向当前
|
|
3
|
+
* user),派生它对树子实体的扩展路径。返回 undefined 表示无扩展见证(回落子实体
|
|
4
|
+
* 自身的包含性判定,E2 数据见证 / E3 禁止合成)。
|
|
5
|
+
*
|
|
6
|
+
* @param rule 边方向(自子实体视角的 edgeRuleOf(childEntity, 子指向父的边属性名))
|
|
7
|
+
* @param edgeName 子指向父的边属性名(OTM `'comment$post'` 的 `$post`;MTO 即该外键属性名)
|
|
8
|
+
*/
|
|
9
|
+
export function deriveChildPath(rule, edgeName, parentPathValue) {
|
|
10
|
+
// deduce 零检查(§5.3);plain/polymorphic 不构成树边的授权传播。
|
|
11
|
+
if (rule === 'deduce' || rule === 'plain' || rule === 'polymorphic') {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (rule === 'otm') {
|
|
15
|
+
// 前缀"子指向父的边属性名":'post' + pv='' ⇒ 'post';'post' + 'user' ⇒ 'post.user'
|
|
16
|
+
return parentPathValue ? `${edgeName}.${parentPathValue}` : edgeName;
|
|
17
|
+
}
|
|
18
|
+
// MTO 剥首段:子路径 value 首段必须是这条边属性,否则不可派生。
|
|
19
|
+
const segments = parentPathValue.split('.');
|
|
20
|
+
if (segments[0] !== edgeName) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return segments.length > 1 ? segments.slice(1).join('.') : '';
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EntityDict } from '../../base-app-domain';
|
|
2
|
+
import { EntityDict as BaseEntityDict } from '../../types/Entity';
|
|
3
|
+
import { AsyncContext } from '../AsyncRowStore';
|
|
4
|
+
/**
|
|
5
|
+
* 获取有对entity进行actions操作权限的userRelation关系
|
|
6
|
+
* @param params
|
|
7
|
+
* @param context
|
|
8
|
+
*/
|
|
9
|
+
export declare function getUserRelationsByActions<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>>(params: {
|
|
10
|
+
entity: T;
|
|
11
|
+
filter: ED[T]['Filter'];
|
|
12
|
+
actions: ED[T]['Action'][];
|
|
13
|
+
overlap?: boolean;
|
|
14
|
+
}, context: Cxt): Promise<{
|
|
15
|
+
userRelations: ED["userRelation"]["Schema"][];
|
|
16
|
+
userEntities: {
|
|
17
|
+
entity: keyof ED;
|
|
18
|
+
entityId: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
}[];
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { destructDirectUserPath, destructRelationPath } from '../../utils/relationPath';
|
|
2
|
+
import { assert } from '../../utils/assert';
|
|
3
|
+
/**
|
|
4
|
+
* 获取有对entity进行actions操作权限的userRelation关系
|
|
5
|
+
* @param params
|
|
6
|
+
* @param context
|
|
7
|
+
*/
|
|
8
|
+
export async function getUserRelationsByActions(params, context) {
|
|
9
|
+
const { entity, filter, actions, overlap } = params;
|
|
10
|
+
const actionAuthfilter = {
|
|
11
|
+
path: {
|
|
12
|
+
destEntity: entity,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
if (overlap) {
|
|
16
|
+
Object.assign(actionAuthfilter, {
|
|
17
|
+
deActions: {
|
|
18
|
+
$overlaps: actions,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
Object.assign(actionAuthfilter, {
|
|
24
|
+
deActions: {
|
|
25
|
+
$contains: actions,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const actionAuths = await context.select('actionAuth', {
|
|
30
|
+
data: {
|
|
31
|
+
id: 1,
|
|
32
|
+
pathId: 1,
|
|
33
|
+
path: {
|
|
34
|
+
id: 1,
|
|
35
|
+
value: 1,
|
|
36
|
+
destEntity: 1,
|
|
37
|
+
recursive: 1,
|
|
38
|
+
},
|
|
39
|
+
relationId: 1,
|
|
40
|
+
relation: {
|
|
41
|
+
id: 1,
|
|
42
|
+
entity: 1,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
filter: actionAuthfilter,
|
|
46
|
+
}, { dontCollect: true });
|
|
47
|
+
const getUserRelations = async (urAuths) => {
|
|
48
|
+
// 相同的path可以groupBy掉
|
|
49
|
+
const urAuthDict2 = {};
|
|
50
|
+
urAuths.forEach((auth) => {
|
|
51
|
+
const { path, relationId } = auth;
|
|
52
|
+
const { value, recursive } = path;
|
|
53
|
+
if (!urAuthDict2[value]) {
|
|
54
|
+
urAuthDict2[value] = [[relationId], recursive];
|
|
55
|
+
}
|
|
56
|
+
else if (!urAuthDict2[value][0].includes(relationId)) {
|
|
57
|
+
assert(urAuthDict2[value][1] === recursive);
|
|
58
|
+
urAuthDict2[value][0].push(relationId);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const userRelations = await Promise.all(Object.keys(urAuthDict2).map(async (path) => {
|
|
62
|
+
const [relationIds, recursive] = urAuthDict2[path];
|
|
63
|
+
const { projection, getData } = destructRelationPath(context.getSchema(), entity, path, {
|
|
64
|
+
relationId: {
|
|
65
|
+
$in: relationIds,
|
|
66
|
+
},
|
|
67
|
+
}, recursive);
|
|
68
|
+
const rows = await context.select(entity, {
|
|
69
|
+
data: projection,
|
|
70
|
+
filter,
|
|
71
|
+
}, { dontCollect: true });
|
|
72
|
+
const urs = rows.map(ele => getData(ele)).flat().filter(ele => !!ele);
|
|
73
|
+
return urs;
|
|
74
|
+
}));
|
|
75
|
+
return userRelations.flat();
|
|
76
|
+
};
|
|
77
|
+
const getDirectUserEntities = async (directAuths) => {
|
|
78
|
+
const paths = [...new Set(directAuths.map(({ path }) => {
|
|
79
|
+
const { value, recursive } = path;
|
|
80
|
+
assert(!recursive);
|
|
81
|
+
return value;
|
|
82
|
+
}))];
|
|
83
|
+
const userEntities = await Promise.all(paths.map(async (path) => {
|
|
84
|
+
const { getData, projection } = destructDirectUserPath(context.getSchema(), entity, path);
|
|
85
|
+
const rows = await context.select(entity, {
|
|
86
|
+
data: projection,
|
|
87
|
+
filter,
|
|
88
|
+
}, { dontCollect: true });
|
|
89
|
+
return rows.map(row => getData(row)).flat().filter(row => !!row);
|
|
90
|
+
}));
|
|
91
|
+
return userEntities.flat();
|
|
92
|
+
};
|
|
93
|
+
const urAuths2 = actionAuths.filter(ele => ele.relationId !== undefined && ele.relationId !== null // 有relation说明通过userRelation关联
|
|
94
|
+
);
|
|
95
|
+
const directAuths2 = actionAuths.filter(ele => ele.relationId === undefined || ele.relationId === null // 没relation说明通过user关联
|
|
96
|
+
);
|
|
97
|
+
const [userRelations, userEntities] = await Promise.all([getUserRelations(urAuths2), getDirectUserEntities(directAuths2)]);
|
|
98
|
+
return {
|
|
99
|
+
userRelations,
|
|
100
|
+
userEntities,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -4,9 +4,10 @@ export declare abstract class SyncContext<ED extends EntityDict & BaseEntityDict
|
|
|
4
4
|
rowStore: SyncRowStore<ED, this>;
|
|
5
5
|
private uuid?;
|
|
6
6
|
constructor(rowStore: SyncRowStore<ED, SyncContext<ED>>);
|
|
7
|
-
abstract getCurrentUserId(allowUnloggedIn?:
|
|
7
|
+
abstract getCurrentUserId<T extends boolean = false>(allowUnloggedIn?: T): T extends true ? string | undefined : string;
|
|
8
8
|
abstract isRoot(): boolean;
|
|
9
9
|
abstract toString(): Promise<string>;
|
|
10
|
+
getAspectName(): string | undefined;
|
|
10
11
|
begin(option?: TxnOption): void;
|
|
11
12
|
commit(): void;
|
|
12
13
|
rollback(): void;
|
package/es/store/SyncRowStore.js
CHANGED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { EntityDict as BaseEntityDict, StorageSchema } from "../types";
|
|
2
|
+
import { EntityDict } from "../base-app-domain";
|
|
3
|
+
import { AsyncContext } from "./AsyncRowStore";
|
|
4
|
+
import { SyncContext } from "./SyncRowStore";
|
|
5
|
+
/**
|
|
6
|
+
* 把创建数据中可直接用于过滤的标量字段投影成 filter;关系对象和结构化字段不做机械复制。
|
|
7
|
+
* 对字段值为 null 的情况,创建语义转换为“字段缺失”:data[attr] = null => {$exists: false}。
|
|
8
|
+
*/
|
|
9
|
+
export declare function translateCreateDataToFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, data: ED[T]['CreateOperationData'], allowUnrecoganized: boolean): ED[T]["Filter"];
|
|
10
|
+
/**
|
|
11
|
+
* 按默认 AND 或 `union=true` 的 OR 组合 filters;内部合并器只在集合等价可证明时改写树形结构。
|
|
12
|
+
* 默认:`combineFilters(F_1,…,F_n) ≡ ⋂F_i`;union:`combineFilters(..., true) ≡ ⋃F_i`。
|
|
13
|
+
*/
|
|
14
|
+
export declare function combineFilters<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filters: Array<ED[T]['Filter']>, union?: true): ED[T]["Filter"] | {
|
|
15
|
+
$or: ED[T]["Filter"][];
|
|
16
|
+
$and?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
$and: ED[T]["Filter"][];
|
|
19
|
+
$or?: undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
type DeducedFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
|
|
22
|
+
entity: T;
|
|
23
|
+
filter: ED[T]['Filter'];
|
|
24
|
+
};
|
|
25
|
+
type DeducedFilterCombination<ED extends EntityDict & BaseEntityDict> = {
|
|
26
|
+
$or?: (DeducedFilterCombination<ED> | DeducedFilter<ED, keyof ED>)[];
|
|
27
|
+
$and?: (DeducedFilterCombination<ED> | DeducedFilter<ED, keyof ED>)[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 对单属性谓词求集合关系:`contained=true` 检查 `S(value1) ⊆ S(value2)`;否则检查 `S(value1) ∩ S(value2) = ∅`。
|
|
31
|
+
* 返回 `undefined` 表示当前算子组合不足以证明包含或相斥,不能当作 true/false 使用。
|
|
32
|
+
*/
|
|
33
|
+
export declare function judgeValueRelation(value1: any, value2: any, contained: boolean): boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* 根据filter对compared查询的各个条件进行逐项分析
|
|
36
|
+
* @param entity
|
|
37
|
+
* @param schema
|
|
38
|
+
* @param filter
|
|
39
|
+
* @param compared
|
|
40
|
+
* @param contained
|
|
41
|
+
* @returns
|
|
42
|
+
* sureAttributes中包含被判定肯定相容或肯定不相斥的属性(不用再继续判定了)
|
|
43
|
+
* uncertainAttributes中包含的是无法判定结果的属性
|
|
44
|
+
* totalAndDeducedFilters包含的是判定过程中推论的相容的充分条件(and关系)
|
|
45
|
+
* totalOrDeducedFilters包含的是判定过程中推论的相斥的充分条件(or关系)
|
|
46
|
+
*/
|
|
47
|
+
/** 按 compared 的顶层键做合取分解,分别记录可证明、未知和需到数据层求证的条件。 */
|
|
48
|
+
export declare function analyzeFilterRelation<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter: NonNullable<ED[T]['Filter']>, compared: NonNullable<ED[T]['Filter']>, contained: boolean): boolean | {
|
|
49
|
+
totalAndDeducedFilters: (DeducedFilterCombination<ED> | DeducedFilter<ED, T>)[];
|
|
50
|
+
totalOrDeducedFilters: (DeducedFilterCombination<ED> | DeducedFilter<ED, T>)[];
|
|
51
|
+
uncertainAttributes: string[];
|
|
52
|
+
sureAttributes: string[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* 判断filter是否包含contained中的查询条件,即filter查询的结果一定是contained查询结果的子集
|
|
57
|
+
* filter = {
|
|
58
|
+
* a: 1
|
|
59
|
+
* b: 2,
|
|
60
|
+
* c: 3,
|
|
61
|
+
* },
|
|
62
|
+
* conditionalFilter = {
|
|
63
|
+
* a: 1
|
|
64
|
+
* }
|
|
65
|
+
* 则包含
|
|
66
|
+
* @param entity
|
|
67
|
+
* @param schema
|
|
68
|
+
* @param filter
|
|
69
|
+
* @param contained
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
/** 判断 `S(filter) ⊆ S(contained)`;返回推导树表示需数据比较才能决定。 */
|
|
73
|
+
export declare function contains<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter: ED[T]['Filter'], contained: ED[T]['Filter']): boolean | DeducedFilterCombination<ED>;
|
|
74
|
+
export declare function getRelevantIds<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(filter?: ED[T]['Filter']): string[];
|
|
75
|
+
/**
|
|
76
|
+
* 判断两个过滤条件是否完全一致
|
|
77
|
+
* @param entity
|
|
78
|
+
* @param schema
|
|
79
|
+
* @param filter1
|
|
80
|
+
* @param filter2
|
|
81
|
+
*/
|
|
82
|
+
/** 判断两个纯 id filter 是否相同;带其他约束时保守返回 false,不冒充完整结构相等。 */
|
|
83
|
+
export declare function same<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter1: ED[T]['Filter'], filter2: ED[T]['Filter']): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* 寻找在树形结构中满足条件的数据行的上层数据
|
|
86
|
+
* 例如在area表中,如果“杭州市”满足这一条件,则希望查到更高层的“浙江省”和“中国”,即可构造出满足条件的filter
|
|
87
|
+
* @param entity
|
|
88
|
+
* @param parentKey parentId属性名
|
|
89
|
+
* @param filter 查询当前行的条件
|
|
90
|
+
* @param level
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* 通过重复反查 parentKey 生成祖先条件:`A_0=filter`,`A_{k+1}={id:{$in:{filter:A_k}}}`。
|
|
94
|
+
* `includeAll` 把第 0..level 层以 OR 合并,`includeSelf` 决定是否将 A_0 放入该并集。
|
|
95
|
+
*/
|
|
96
|
+
export declare function makeTreeAncestorFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Filter'], level?: number, includeAll?: boolean, includeSelf?: boolean): ED[T]['Filter'];
|
|
97
|
+
/**
|
|
98
|
+
* 寻找在树形结构中满足条件的数据行的下层数据
|
|
99
|
+
* 例如在area表中,如果“杭州市”满足这一条件,则希望查到更低层的“西湖区”,即可构造出满足条件的filter
|
|
100
|
+
* @param entity
|
|
101
|
+
* @param parentKey parentId属性名
|
|
102
|
+
* @param filter 查询当前行的条件
|
|
103
|
+
* @param level
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* 沿 parentKey 对应关系递归构造后代:`D_0=filter`,`D_{k+1}={parentRelation:D_k}`。
|
|
107
|
+
* `includeAll` 以 OR 合并第 0..level 层,`includeSelf` 决定是否将 D_0 纳入并集。
|
|
108
|
+
*/
|
|
109
|
+
export declare function makeTreeDescendantFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Filter'], level?: number, includeAll?: boolean, includeSelf?: boolean): ED[T]['Filter'];
|
|
110
|
+
/**
|
|
111
|
+
* 检查filter是否包含contained(filter查询的数据是contained查询数据的子集)
|
|
112
|
+
* @param entity
|
|
113
|
+
* @param context
|
|
114
|
+
* @param contained
|
|
115
|
+
* @param filter
|
|
116
|
+
* @param dataCompare
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
export declare function checkFilterContains<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends SyncContext<ED> | AsyncContext<ED>>(entity: T, context: Cxt, contained: ED[T]['Filter'], filter?: ED[T]['Filter'], dataCompare?: true, warningOnDataCompare?: true): boolean | Promise<boolean>;
|
|
120
|
+
export declare function checkFilterRepel<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends SyncContext<ED> | AsyncContext<ED>>(entity: T, context: Cxt, filter1: ED[T]['Filter'], filter2: ED[T]['Filter'], dataCompare?: true, warningOnDataCompare?: true): boolean | Promise<boolean>;
|
|
121
|
+
/**
|
|
122
|
+
* 有的场景下将filter当成非结构化属性存储,又想支持对其查询,此时必须将查询的filter进行转换,处理其中$开头的escape
|
|
123
|
+
* 只要filter是查询数据的标准子集,查询应当能返回true
|
|
124
|
+
* @param filter
|
|
125
|
+
*/
|
|
126
|
+
/** 递归遍历对象与数组,仅将键名前缀 `$` 改写为 `.$`,值与数组结构保持不变。 */
|
|
127
|
+
export declare function translateFilterToObjectPredicate(filter: Record<string, any>): any;
|
|
128
|
+
export {};
|