oak-domain 6.1.1 → 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 +94 -9
- 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 +95 -9
- 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 +6 -3
- 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,141 @@
|
|
|
1
|
+
import { EntityDict } from "../../base-app-domain";
|
|
2
|
+
import { StorageSchema } from "../../types";
|
|
3
|
+
import { EntityDict as BaseEntityDict, AuthDeduceRelationMap } from "../../types/Entity";
|
|
4
|
+
import { AsyncContext } from "../AsyncRowStore";
|
|
5
|
+
import { SyncContext } from "../SyncRowStore";
|
|
6
|
+
/**
|
|
7
|
+
* RelationAuth —— 按 docs/permission-model.md(v0.5)重写的权限判定内核。
|
|
8
|
+
*
|
|
9
|
+
* 不变量映射:
|
|
10
|
+
* - I2 逐层必检:读路径以 `ReadTask` 链表达投影 OTM 骨架上的每个节点任务(D1/D2/D6),
|
|
11
|
+
* 根任务无条件执行;MTO 投影不构成任务(D5/I3)。
|
|
12
|
+
* - I3 MTO 零成本:`buildReadTasks` 不沿 MTO 边下降,不为其发起任何查询。
|
|
13
|
+
* - I4 双模式同结果:判定逻辑单源;sync/async 分叉只发生在 IO 叶子,由 `bind`/`allBind`
|
|
14
|
+
* 统一接续(同步输入 ⇒ 同步输出,不产生 Promise)。
|
|
15
|
+
* - I5 deduce 单点:`edgeRuleOf(...) === 'deduce'` 是唯一策略谓词;树形剪枝、投影不展开、
|
|
16
|
+
* 写侧放行、多态折算全部经它分派。
|
|
17
|
+
* - I6 豁免粒度:selectFree/updateFree 只把任务标记为 exempt(豁免节点自身行集要求),
|
|
18
|
+
* 不删除任务、不豁免链上其它节点(D4)。
|
|
19
|
+
* - I7 写语义保持:destructOperation/checkOperationTree 结构与现实现同构,仅把路径
|
|
20
|
+
* 拼接替换为 I8 原语。
|
|
21
|
+
* - I8 边传播单源:`deriveChildPath` 是唯一的授权路径派生原语——OTM 前缀边属性名、
|
|
22
|
+
* MTO 剥首段、deduce 零检查;读写共用。
|
|
23
|
+
* - E1 自顶向下短路:任务链按根→叶顺序求值,首个失败立即返回(异常在 checkActions
|
|
24
|
+
* 唯一汇点抛出,种类与时机读写一致)。
|
|
25
|
+
* - E2 扩展路径快路:父任务经见证 actionAuth 行通过后,其路径沿边派生为子任务候选见证,
|
|
26
|
+
* 仍以 actionAuth 数据存在为生效条件;E3 禁止无数据合成继承。
|
|
27
|
+
* - 保守拒绝:判别器伪造、目标歧义(反查 2 行封顶)、未知属性、$not/$xor 删减、环结构
|
|
28
|
+
* filter 一律不放大授权面。
|
|
29
|
+
*/
|
|
30
|
+
export declare class RelationAuth<ED extends EntityDict & BaseEntityDict> {
|
|
31
|
+
private authDeduceRelationMap;
|
|
32
|
+
private schema;
|
|
33
|
+
static SPECIAL_ENTITIES: string[];
|
|
34
|
+
private selectFreeEntities;
|
|
35
|
+
private updateFreeDict;
|
|
36
|
+
constructor(schema: StorageSchema<ED>, authDeduceRelationMap: AuthDeduceRelationMap<ED>, selectFreeEntities?: (keyof ED)[], updateFreeDict?: {
|
|
37
|
+
[A in keyof ED]?: string[];
|
|
38
|
+
});
|
|
39
|
+
checkRelationSync<T extends keyof ED, Cxt extends SyncContext<ED>>(entity: T, operation: Omit<ED[T]['Operation'] | ED[T]['Selection'], 'id'>, context: Cxt): void;
|
|
40
|
+
checkRelationAsync<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, operation: Omit<ED[T]['Operation'] | ED[T]['Selection'], 'id'>, context: Cxt): Promise<void>;
|
|
41
|
+
/** 节点自身是否不参与对象授权判定:selectFree 只豁免自身,特殊系统实体沿用旧行为整节点豁免。 */
|
|
42
|
+
private isSelfExemptEntity;
|
|
43
|
+
/** I5:deduce 策略唯一定义点 */
|
|
44
|
+
private edgeRuleOf;
|
|
45
|
+
/**
|
|
46
|
+
* 检查当前用户有无权限对filter约束的userRelation进行action操作(§6 特殊实体)
|
|
47
|
+
*/
|
|
48
|
+
private checkUserRelation;
|
|
49
|
+
private checkOperateSpecialEntities;
|
|
50
|
+
private isKnownEntity;
|
|
51
|
+
private collectStaticDeduceTargets;
|
|
52
|
+
/**
|
|
53
|
+
* deduce 折算(I5 消费方):实体权限可折算为其多态 entity/entityId 所指父对象的权限。
|
|
54
|
+
* 候选集合是并集 U(root) ∪ ⋃U(targetᵢ);任何不能静态确证目标的情形都只保留根候选
|
|
55
|
+
* (宁可保守拒绝,不能任选一行扩大授权)。
|
|
56
|
+
*/
|
|
57
|
+
private getDeducedEntityFilters;
|
|
58
|
+
/**
|
|
59
|
+
* 投影侧 filter 精修(§4.1 filter 三语义位置):
|
|
60
|
+
* 只保留能约束授权路径的属性,同时返回投影是否保持了原表达式。
|
|
61
|
+
* 若原查询为 Q=A∧B,删除 B 得到 A,则 Q⊆A,适合作为授权检查的安全上界;
|
|
62
|
+
* 若 Q=A∨B,只要每个分支都向上近似,A∨B⊆A'∨B' 仍成立。
|
|
63
|
+
* 但 NOT 和 XOR 不满足这种单调性:其内部发生删减时丢弃整个 NOT/XOR,
|
|
64
|
+
* 宁可少优化也不能误拒绝或扩大授权。
|
|
65
|
+
*/
|
|
66
|
+
private refineFilter;
|
|
67
|
+
/**
|
|
68
|
+
* 读路径任务链(D1/D2/D6,I2 逐层必检):
|
|
69
|
+
* 投影 OTM 骨架上每个节点生成一个独立任务;任务 filter = 精修后的根 filter 沿
|
|
70
|
+
* OTM 链逐层压平(left-join 语义下父链约束只由外键嵌入表达,不含子存在性约束,D6)。
|
|
71
|
+
* MTO 投影不生成任务(D5/I3);deduce 节点不展开(I5),其可见性由锚点节点任务担保。
|
|
72
|
+
* 根任务无条件生成——包括根下挂 OTM(旧"只检最深叶"的托付已废弃,D3)与根 selectFree
|
|
73
|
+
* (selectFree 只豁免自身,链上其它节点照常生成任务;根自身的豁免由 exempt 标记表达)。
|
|
74
|
+
*/
|
|
75
|
+
private buildReadTasks;
|
|
76
|
+
/**
|
|
77
|
+
* 单个读任务的包含性判定:filter ⊆ Auth(entity,'select')。
|
|
78
|
+
* 返回 [是否通过, 通过见证(可用于 E2 扩展的 actionAuth 行)]。
|
|
79
|
+
*/
|
|
80
|
+
private checkReadTask;
|
|
81
|
+
/**
|
|
82
|
+
* E2:把父任务通过见证沿边派生为子任务的扩展路径(I8 原语),
|
|
83
|
+
* 并在 actionAuth 中以数据见证确认扩展路径的授权行存在;不存在则回落正常判定。
|
|
84
|
+
*/
|
|
85
|
+
private probeWitnesses;
|
|
86
|
+
/**
|
|
87
|
+
* 任务的授权并集判定:对每个 deduce 候选(OR 语义,通过一个即可),
|
|
88
|
+
* 以该实体全部可用 actionAuth 的 scope 并集(§3.3)做包含性检查(静态优先,
|
|
89
|
+
* 数据比对兜底,不确定即拒绝)。返回所有使任务通过的见证行(供 E2)。
|
|
90
|
+
*/
|
|
91
|
+
private checkTaskAgainstAuths;
|
|
92
|
+
/** scope 合成:destEntity 匹配的授权行(并集成员,§3.3) */
|
|
93
|
+
private collectScopeAuths;
|
|
94
|
+
/** F ⊆ ⋃scope(minimize 后合成,数据比对兜底) */
|
|
95
|
+
private scopeContainsFilter;
|
|
96
|
+
private checkSelection;
|
|
97
|
+
/**
|
|
98
|
+
* 对于operation,解构出一个树形结构,以方便自顶向下的进行访问
|
|
99
|
+
* 但对于deduce的子对象,不必再向底层查看(I5:addChild 内经 edgeRuleOf 剪枝)
|
|
100
|
+
*/
|
|
101
|
+
private destructOperation;
|
|
102
|
+
/**
|
|
103
|
+
* 授权 scope filter 展开:把 path(destEntity 走向 user 的属性链)与末端谓词 filter
|
|
104
|
+
* 合成为 destEntity 上的 filter。
|
|
105
|
+
*/
|
|
106
|
+
private makePathFilter;
|
|
107
|
+
/**
|
|
108
|
+
* 对所有满足操作要求的actionAuth加以判断,找到可以满足当前用户身份的actionAuth
|
|
109
|
+
*/
|
|
110
|
+
private filterActionAuths;
|
|
111
|
+
/**
|
|
112
|
+
* 对于有些特殊的查询(带很多$or的查询,多发生在系统级别),单个actionAuth无法满足,需要共同加以判定
|
|
113
|
+
*/
|
|
114
|
+
private checkActionAuthInGroup;
|
|
115
|
+
/**
|
|
116
|
+
* 此函数判定一个结点是否能通过权限检测,同时寻找该结点本身对象上成立的actionAuth,用于本结点子孙结点的快速检测
|
|
117
|
+
* 如果结点因其deduce的对象通过了检测,其被推断对象的actionAuth无法用于更低对象的权限检测
|
|
118
|
+
*/
|
|
119
|
+
private findActionAuthsOnNode;
|
|
120
|
+
/**
|
|
121
|
+
* 级联树边解析(I8 前置)。destructOperation 的键形:
|
|
122
|
+
* - OTM 反指:键 = 父数据上的反指属性名 `子实体名$边名`('comment$post'),
|
|
123
|
+
* 前缀传播,边名 = 尾段;
|
|
124
|
+
* - MTO 正向/多态折算:键 = `父实体名$attr`('comment$user'、批式 'post$entity')或
|
|
125
|
+
* 裸 attr(历史手工树),剥首段,边名 = 子指向父的外键基名。
|
|
126
|
+
* 键形约定存在碰撞(如 'post$entity'),以 schema 双向外键探测定方向:
|
|
127
|
+
* 父侧存在名为尾段的 ref→子 外键 ⇒ MTO;否则子侧存在 ⇒ OTM;再否则多态折算 ⇒ MTO
|
|
128
|
+
* 以 'entity' 折算边;都不可解析 ⇒ 保守不传播。
|
|
129
|
+
*/
|
|
130
|
+
private resolveTreeEdge;
|
|
131
|
+
private checkOperationTree;
|
|
132
|
+
private checkOperation;
|
|
133
|
+
/**
|
|
134
|
+
* 检查一个operation是否能被通过权限测试。
|
|
135
|
+
* 判定汇点唯一(I4):读→任务链(E1 短路,失败 OakDataInvisible),
|
|
136
|
+
* 写→级联树自顶向下(失败 OakOperationUnpermitted);
|
|
137
|
+
* 异常种类与时机由本函数单点决定,读写内核不再各自抛异常。
|
|
138
|
+
*/
|
|
139
|
+
private checkActions;
|
|
140
|
+
}
|
|
141
|
+
export { getUserRelationsByActions } from './userLookup';
|