Merge branch 'release'
This commit is contained in:
commit
68e92fc1c3
|
|
@ -287,8 +287,19 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2) {
|
|||
var cascadePath = lch.cascadePath, relations = lch.relations;
|
||||
var paths = cascadePath.split('.');
|
||||
var translateRelationFilter = function (entity) {
|
||||
// 有两种情况,此entity和user有Relation定义,或是此entity上有userId
|
||||
if (schema[entity].relation) {
|
||||
// 有两种情况,此entity和user有Relation定义,或是此entity已经指向user
|
||||
if (entity === 'user') {
|
||||
return function (userId) { return ({
|
||||
id: userId,
|
||||
}); };
|
||||
}
|
||||
else if (schema[entity].relation) {
|
||||
if (relations) {
|
||||
var diff = (0, lodash_1.difference)(relations, schema[entity].relation);
|
||||
if (diff.length > 0) {
|
||||
throw new Error("".concat(entity2, "\u4E0A\u67D0auth\u5B9A\u4E49\u7684relations\u4E2D\u542B\u6709\u4E0D\u53EF\u8BC6\u522B\u7684\u5173\u7CFB\u5B9A\u4E49").concat(diff.join(','), "\uFF0C \u8BF7\u4ED4\u7EC6\u68C0\u67E5"));
|
||||
}
|
||||
}
|
||||
var relationEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
||||
return function (userId) {
|
||||
var _a;
|
||||
|
|
@ -313,11 +324,9 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2) {
|
|||
};
|
||||
};
|
||||
}
|
||||
var attributes = schema[entity].attributes;
|
||||
(0, assert_1.default)(attributes.hasOwnProperty('userId') && attributes.userId.type === 'ref' && attributes.userId.ref === 'user', "\u5728".concat(entity, "\u4E0A\u65E2\u627E\u4E0D\u5230userId\uFF0C\u4E5F\u6CA1\u6709relation\u5B9A\u4E49"));
|
||||
return function (userId) { return ({
|
||||
userId: userId,
|
||||
}); };
|
||||
else {
|
||||
(0, assert_1.default)(false, "".concat(entity2, "\u4E0A\u67D0auth\u5B9A\u4E49\u7684cascadePath").concat(cascadePath, "\u4E0D\u80FD\u5B9A\u4F4D\u5230User\u5BF9\u8C61\u6216\u8005\u548CUser\u5173\u8054\u7684\u5173\u7CFB\u5BF9\u8C61\uFF0C \u8BF7\u4ED4\u7EC6\u68C0\u67E5"));
|
||||
}
|
||||
};
|
||||
var translateFilterMakerIter = function (entity, iter) {
|
||||
var relation = (0, relation_1.judgeRelation)(schema, entity, paths[iter]);
|
||||
|
|
@ -325,32 +334,23 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2) {
|
|||
if (relation === 2) {
|
||||
var filterMaker_1 = translateRelationFilter(paths[iter]);
|
||||
return function (userId) {
|
||||
var _a;
|
||||
var filter = filterMaker_1(userId);
|
||||
if (filter.$in) {
|
||||
return {
|
||||
entity: paths[iter],
|
||||
entityId: filter,
|
||||
};
|
||||
}
|
||||
return _a = {},
|
||||
_a[paths[iter]] = filter,
|
||||
_a;
|
||||
(0, assert_1.default)(filter.id);
|
||||
return {
|
||||
entity: paths[iter],
|
||||
entityId: filter.id,
|
||||
};
|
||||
};
|
||||
}
|
||||
(0, assert_1.default)(typeof relation === 'string');
|
||||
var filterMaker_2 = translateRelationFilter(relation);
|
||||
return function (userId) {
|
||||
var _a, _b;
|
||||
var _a;
|
||||
var filter = filterMaker_2(userId);
|
||||
if (filter.$in) {
|
||||
return _a = {},
|
||||
_a["".concat(paths[iter], "Id")] = filter,
|
||||
_a;
|
||||
}
|
||||
return _b = {},
|
||||
_b[paths[iter]] = filter,
|
||||
_b;
|
||||
(0, assert_1.default)(filter.id);
|
||||
return _a = {},
|
||||
_a["".concat(paths[iter], "Id")] = filter.id,
|
||||
_a;
|
||||
};
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -230,6 +230,9 @@ function reinforceSelection(schema, entity, selection) {
|
|||
}
|
||||
]
|
||||
});
|
||||
Object.assign(data, {
|
||||
$$createAt$$: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.reinforceSelection = reinforceSelection;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-domain",
|
||||
"version": "2.4.2",
|
||||
"version": "2.4.3",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { AsyncContext } from "./AsyncRowStore";
|
|||
import { getFullProjection } from './actionDef';
|
||||
import { SyncContext } from './SyncRowStore';
|
||||
import { firstLetterUpperCase } from '../utils/string';
|
||||
import { uniq } from '../utils/lodash';
|
||||
import { uniq, difference } from '../utils/lodash';
|
||||
import { judgeRelation } from './relation';
|
||||
|
||||
export function translateCheckerInAsyncContext<
|
||||
|
|
@ -255,8 +255,19 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
|
|||
const paths = cascadePath.split('.');
|
||||
|
||||
const translateRelationFilter = <T extends keyof ED>(entity: T): (userId: string) => ED[T]['Selection']['filter'] => {
|
||||
// 有两种情况,此entity和user有Relation定义,或是此entity上有userId
|
||||
if (schema[entity].relation) {
|
||||
// 有两种情况,此entity和user有Relation定义,或是此entity已经指向user
|
||||
if (entity === 'user') {
|
||||
return (userId) => ({
|
||||
id: userId,
|
||||
});
|
||||
}
|
||||
else if (schema[entity].relation) {
|
||||
if (relations) {
|
||||
const diff = difference(relations, schema[entity].relation!);
|
||||
if (diff.length > 0) {
|
||||
throw new Error(`${entity2 as string}上某auth定义的relations中含有不可识别的关系定义${diff.join(',')}, 请仔细检查`);
|
||||
}
|
||||
}
|
||||
const relationEntityName = `user${firstLetterUpperCase(entity as string)}`;
|
||||
return (userId) => {
|
||||
const filter = relations ? {
|
||||
|
|
@ -280,12 +291,9 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
const { attributes } = schema[entity];
|
||||
assert(attributes.hasOwnProperty('userId') && attributes.userId.type === 'ref' && attributes.userId.ref === 'user', `在${entity as string}上既找不到userId,也没有relation定义`);
|
||||
return (userId) => ({
|
||||
userId,
|
||||
});
|
||||
else {
|
||||
assert(false, `${entity2 as string}上某auth定义的cascadePath${cascadePath}不能定位到User对象或者和User关联的关系对象, 请仔细检查`);
|
||||
}
|
||||
};
|
||||
|
||||
const translateFilterMakerIter = <T extends keyof ED>(entity: T, iter: number): (userId: string) => ED[T]['Selection']['filter'] => {
|
||||
|
|
@ -294,30 +302,22 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
|
|||
if (relation === 2) {
|
||||
const filterMaker = translateRelationFilter(paths[iter]);
|
||||
return (userId) => {
|
||||
const filter = filterMaker(userId);
|
||||
if (filter!.$in) {
|
||||
return {
|
||||
entity: paths[iter],
|
||||
entityId: filter,
|
||||
};
|
||||
}
|
||||
const filter = filterMaker(userId)!;
|
||||
assert(filter.id);
|
||||
return {
|
||||
[paths[iter]]: filter,
|
||||
entity: paths[iter],
|
||||
entityId: filter.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
assert(typeof relation === 'string');
|
||||
const filterMaker = translateRelationFilter(relation);
|
||||
return (userId) => {
|
||||
const filter = filterMaker(userId);
|
||||
const filter = filterMaker(userId)!;
|
||||
|
||||
if (filter!.$in) {
|
||||
return {
|
||||
[`${paths[iter]}Id`]: filter
|
||||
};
|
||||
}
|
||||
assert(filter.id);
|
||||
return {
|
||||
[paths[iter]]: filter,
|
||||
[`${paths[iter]}Id`]: filter.id,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,5 +228,8 @@ export function reinforceSelection<ED extends EntityDict>(schema: StorageSchema<
|
|||
}
|
||||
]
|
||||
});
|
||||
Object.assign(data, {
|
||||
$$createAt$$: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue