Merge branch 'auth' into sub
This commit is contained in:
commit
5fb4519346
|
|
@ -325,25 +325,16 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
};
|
||||
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, cascadeSelectFn, aggregateFn, option) {
|
||||
var _this = this;
|
||||
var projection = {};
|
||||
var cascadeSelectionFns = [];
|
||||
var supportMtoJoin = this.supportManyToOneJoin();
|
||||
var toModi = this.getSchema()[entity].toModi;
|
||||
(0, assert_1.default)(typeof projection2 === 'object');
|
||||
var _loop_1 = function (attr) {
|
||||
var _a, _b, _c, _d;
|
||||
var relation = (0, relation_1.judgeRelation)(this_1.storageSchema, entity, attr);
|
||||
if (relation === 1 || relation == 0) {
|
||||
Object.assign(projection, (_a = {},
|
||||
_a[attr] = projection2[attr],
|
||||
_a));
|
||||
}
|
||||
else if (relation === 2) {
|
||||
// 基于entity/entityId的多对一
|
||||
Object.assign(projection, {
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
});
|
||||
(0, assert_1.default)(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
cascadeSelectionFns.push(function (result) {
|
||||
|
|
@ -366,10 +357,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}
|
||||
});
|
||||
var _e = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _e.projection, subCascadeSelectionFns = _e.cascadeSelectionFns;
|
||||
Object.assign(projection, (_b = {},
|
||||
_b[attr] = subProjection,
|
||||
_b));
|
||||
var _a = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _a.projection, subCascadeSelectionFns = _a.cascadeSelectionFns;
|
||||
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
||||
return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
|
||||
}); });
|
||||
|
|
@ -435,9 +423,6 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
else if (typeof relation === 'string') {
|
||||
Object.assign(projection, (_c = {},
|
||||
_c["".concat(attr, "Id")] = 1,
|
||||
_c));
|
||||
(0, assert_1.default)(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
if (!toModi) {
|
||||
|
|
@ -460,10 +445,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
});
|
||||
}
|
||||
var _f = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _f.projection, subCascadeSelectionFns = _f.cascadeSelectionFns;
|
||||
Object.assign(projection, (_d = {},
|
||||
_d[attr] = subProjection,
|
||||
_d));
|
||||
var _b = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _b.projection, subCascadeSelectionFns = _b.cascadeSelectionFns;
|
||||
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
||||
return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
|
||||
}); });
|
||||
|
|
@ -529,8 +511,8 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
else {
|
||||
(0, assert_1.default)(relation instanceof Array);
|
||||
var _g = projection2[attr], subProjection_1 = _g.data, subFilter_1 = _g.filter, indexFrom_1 = _g.indexFrom, count_1 = _g.count, subSorter_1 = _g.sorter;
|
||||
var _h = tslib_1.__read(relation, 2), entity2_1 = _h[0], foreignKey_1 = _h[1];
|
||||
var _c = projection2[attr], subProjection_1 = _c.data, subFilter_1 = _c.filter, indexFrom_1 = _c.indexFrom, count_1 = _c.count, subSorter_1 = _c.sorter;
|
||||
var _d = tslib_1.__read(relation, 2), entity2_1 = _d[0], foreignKey_1 = _d[1];
|
||||
var isAggr = attr.endsWith('$$aggr');
|
||||
if (foreignKey_1) {
|
||||
// 基于属性的一对多
|
||||
|
|
@ -700,7 +682,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_loop_1(attr);
|
||||
}
|
||||
return {
|
||||
projection: projection,
|
||||
projection: projection2,
|
||||
cascadeSelectionFns: cascadeSelectionFns,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -547,6 +547,7 @@ function createCreateCheckers(schema) {
|
|||
var e_5, _a, e_6, _b;
|
||||
var illegalNullAttrs = (0, lodash_1.difference)(notNullAttrs, Object.keys(data2));
|
||||
if (illegalNullAttrs.length > 0) {
|
||||
var emtpyAttrs = [];
|
||||
try {
|
||||
// 要处理多对一的cascade create
|
||||
for (var illegalNullAttrs_1 = (e_5 = void 0, tslib_1.__values(illegalNullAttrs)), illegalNullAttrs_1_1 = illegalNullAttrs_1.next(); !illegalNullAttrs_1_1.done; illegalNullAttrs_1_1 = illegalNullAttrs_1.next()) {
|
||||
|
|
@ -586,7 +587,7 @@ function createCreateCheckers(schema) {
|
|||
}
|
||||
}
|
||||
// 到这里说明确实是有not null的属性没有赋值
|
||||
throw new Exception_1.OakAttrNotNullException(entity, illegalNullAttrs);
|
||||
emtpyAttrs.push(attr);
|
||||
}
|
||||
}
|
||||
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
||||
|
|
@ -596,6 +597,9 @@ function createCreateCheckers(schema) {
|
|||
}
|
||||
finally { if (e_5) throw e_5.error; }
|
||||
}
|
||||
if (emtpyAttrs.length > 0) {
|
||||
throw new Exception_1.OakAttrNotNullException(entity, emtpyAttrs);
|
||||
}
|
||||
}
|
||||
checkAttributeLegal(schema, entity, data2);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1600,9 +1600,13 @@ function checkDeduceFilters(dfc, context) {
|
|||
var andResult = $and.map(function (ele) {
|
||||
if (ele.hasOwnProperty('entity')) {
|
||||
var ele2_1 = ele;
|
||||
return context.count(ele2_1.entity, {
|
||||
filter: ele2_1.filter
|
||||
}, {});
|
||||
return context.count(
|
||||
ele2_1.entity,
|
||||
{
|
||||
filter: ele2_1.filter,
|
||||
},
|
||||
{ ignoreForeignKeyMiss: true }
|
||||
);
|
||||
}
|
||||
var ele2 = ele;
|
||||
return checkDeduceFilters(ele2, context);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "oak-domain",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"author": {
|
||||
"name": "XuChang"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -379,7 +379,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
cascadeSelectFn: <T2 extends keyof ED>(entity2: T2, selection: ED[T2]['Selection'], context: Cxt, op: OP) => Partial<ED[T2]['Schema']>[] | Promise<Partial<ED[T2]['Schema']>[]>,
|
||||
aggregateFn: <T2 extends keyof ED>(entity2: T2, aggregation: ED[T2]['Aggregation'], context: Cxt, op: OP) => AggregationResult<ED[T2]['Schema']> | Promise<AggregationResult<ED[T2]['Schema']>>,
|
||||
option: OP) {
|
||||
const projection: ED[T]['Selection']['data'] = {};
|
||||
const cascadeSelectionFns: Array<(result: Partial<ED[T]['Schema']>[]) => Promise<void> | void> = [];
|
||||
|
||||
const supportMtoJoin = this.supportManyToOneJoin();
|
||||
|
|
@ -389,17 +388,9 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
for (const attr in projection2) {
|
||||
const relation = judgeRelation(this.storageSchema, entity, attr);
|
||||
if (relation === 1 || relation == 0) {
|
||||
Object.assign(projection, {
|
||||
[attr]: projection2[attr],
|
||||
});
|
||||
}
|
||||
else if (relation === 2) {
|
||||
// 基于entity/entityId的多对一
|
||||
Object.assign(projection, {
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
});
|
||||
|
||||
assert(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
cascadeSelectionFns.push(
|
||||
|
|
@ -430,9 +421,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
projection: subProjection,
|
||||
cascadeSelectionFns: subCascadeSelectionFns,
|
||||
} = this.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option);
|
||||
Object.assign(projection, {
|
||||
[attr]: subProjection,
|
||||
});
|
||||
subCascadeSelectionFns.forEach(
|
||||
ele => cascadeSelectionFns.push(
|
||||
(result) => {
|
||||
|
|
@ -516,9 +504,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
}
|
||||
}
|
||||
else if (typeof relation === 'string') {
|
||||
Object.assign(projection, {
|
||||
[`${attr}Id`]: 1,
|
||||
});
|
||||
assert(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
if (!toModi) {
|
||||
|
|
@ -549,9 +534,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
projection: subProjection,
|
||||
cascadeSelectionFns: subCascadeSelectionFns,
|
||||
} = this.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option);
|
||||
Object.assign(projection, {
|
||||
[attr]: subProjection,
|
||||
});
|
||||
subCascadeSelectionFns.forEach(
|
||||
ele => cascadeSelectionFns.push(
|
||||
(result) => {
|
||||
|
|
@ -829,7 +811,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
}
|
||||
|
||||
return {
|
||||
projection,
|
||||
projection: projection2,
|
||||
cascadeSelectionFns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,6 +478,7 @@ export function createCreateCheckers<ED extends EntityDict & BaseEntityDict, Cxt
|
|||
const checkData = (data2: ED[keyof ED]['CreateSingle']['data']) => {
|
||||
const illegalNullAttrs = difference(notNullAttrs, Object.keys(data2));
|
||||
if (illegalNullAttrs.length > 0) {
|
||||
const emtpyAttrs: string[] = [];
|
||||
// 要处理多对一的cascade create
|
||||
for (const attr of illegalNullAttrs) {
|
||||
if (attr === 'entityId') {
|
||||
|
|
@ -505,7 +506,10 @@ export function createCreateCheckers<ED extends EntityDict & BaseEntityDict, Cxt
|
|||
}
|
||||
}
|
||||
// 到这里说明确实是有not null的属性没有赋值
|
||||
throw new OakAttrNotNullException(entity, illegalNullAttrs);
|
||||
emtpyAttrs.push(attr);
|
||||
}
|
||||
if (emtpyAttrs.length > 0) {
|
||||
throw new OakAttrNotNullException(entity, emtpyAttrs);
|
||||
}
|
||||
}
|
||||
checkAttributeLegal(schema, entity, data2);
|
||||
|
|
|
|||
|
|
@ -1653,7 +1653,7 @@ export function checkDeduceFilters<ED extends EntityDict & BaseEntityDict, Cxt e
|
|||
const ele2 = ele as DeducedFilter<ED, keyof ED>;
|
||||
return context.count(ele2.entity, {
|
||||
filter: ele2.filter
|
||||
}, {});
|
||||
}, { ignoreForeignKeyMiss: true });
|
||||
}
|
||||
const ele2 = ele as DeducedFilterCombination<ED>;
|
||||
return checkDeduceFilters(ele2, context);
|
||||
|
|
|
|||
Loading…
Reference in New Issue