checker中要blockTrigger
This commit is contained in:
parent
aa4f89d778
commit
da735fa924
|
|
@ -29,23 +29,29 @@ function translateCheckerInAsyncContext(checker) {
|
|||
return (function (_a, context, option) {
|
||||
var operation = _a.operation;
|
||||
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var operationFilter, filter2, entity2, selection2, rows2, data_1, rows2, data_2;
|
||||
var operationFilter, action, filter2, entity2, selection2, rows2, data_1, rows2, data_2;
|
||||
var _b, _c;
|
||||
return tslib_1.__generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
operationFilter = operation.filter;
|
||||
operationFilter = operation.filter, action = operation.action;
|
||||
(0, assert_1.default)(operationFilter);
|
||||
filter2 = typeof filter_2 === 'function' ? filter_2(context, option) : filter_2;
|
||||
return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter)];
|
||||
case 1:
|
||||
if (!['select', 'count', 'stat'].includes(action)) return [3 /*break*/, 1];
|
||||
operation.filter = (0, filter_1.addFilterSegment)(operationFilter, filter2);
|
||||
return [2 /*return*/, 0];
|
||||
case 1: return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter)];
|
||||
case 2:
|
||||
if (_d.sent()) {
|
||||
return [2 /*return*/, 0];
|
||||
}
|
||||
if (!inconsistentRows_1) return [3 /*break*/, 3];
|
||||
if (!inconsistentRows_1) return [3 /*break*/, 4];
|
||||
entity2 = inconsistentRows_1.entity, selection2 = inconsistentRows_1.selection;
|
||||
return [4 /*yield*/, context.select(entity2, selection2(operationFilter), { dontCollect: true })];
|
||||
case 2:
|
||||
return [4 /*yield*/, context.select(entity2, selection2(operationFilter), {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
})];
|
||||
case 3:
|
||||
rows2 = _d.sent();
|
||||
data_1 = {};
|
||||
rows2.forEach(function (ele) {
|
||||
|
|
@ -60,13 +66,16 @@ function translateCheckerInAsyncContext(checker) {
|
|||
_b[entity2] = data_1,
|
||||
_b)
|
||||
}, errMsg_1);
|
||||
case 3: return [4 /*yield*/, context.select(entity, {
|
||||
case 4: return [4 /*yield*/, context.select(entity, {
|
||||
data: (0, actionDef_1.getFullProjection)(entity, context.getSchema()),
|
||||
filter: Object.assign({}, operationFilter, {
|
||||
$not: filter2,
|
||||
})
|
||||
}, { dontCollect: true })];
|
||||
case 4:
|
||||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
})];
|
||||
case 5:
|
||||
rows2 = _d.sent();
|
||||
data_2 = {};
|
||||
rows2.forEach(function (ele) {
|
||||
|
|
@ -118,13 +127,19 @@ function translateCheckerInSyncContext(checker) {
|
|||
case 'row': {
|
||||
var filter_3 = checker.filter, errMsg_2 = checker.errMsg;
|
||||
return function (operation, context, option) {
|
||||
var operationFilter = operation.filter;
|
||||
var operationFilter = operation.filter, action = operation.action;
|
||||
var filter2 = typeof filter_3 === 'function' ? filter_3(context, option) : filter_3;
|
||||
(0, assert_1.default)(operationFilter);
|
||||
if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter)) {
|
||||
return;
|
||||
if (['select', 'count', 'stat'].includes(action)) {
|
||||
operation.filter = (0, filter_1.addFilterSegment)(operationFilter, filter2);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter)) {
|
||||
return;
|
||||
}
|
||||
throw new Exception_1.OakRowInconsistencyException(undefined, errMsg_2);
|
||||
}
|
||||
throw new Exception_1.OakRowInconsistencyException(undefined, errMsg_2);
|
||||
};
|
||||
}
|
||||
case 'relation': {
|
||||
|
|
|
|||
|
|
@ -302,6 +302,7 @@ function checkFilterContains(entity, context, contained, filter) {
|
|||
filter: filter2,
|
||||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
if (count instanceof Promise) {
|
||||
return count.then(function (count2) { return count2 === 0; });
|
||||
|
|
|
|||
|
|
@ -24,49 +24,61 @@ export function translateCheckerInAsyncContext<
|
|||
case 'row': {
|
||||
const { filter, errMsg, inconsistentRows } = checker;
|
||||
return (async ({ operation }, context, option) => {
|
||||
const { filter: operationFilter } = operation;
|
||||
const { filter: operationFilter, action } = operation;
|
||||
assert(operationFilter);
|
||||
const filter2 = typeof filter === 'function' ? filter(context, option) : filter;
|
||||
if (await checkFilterContains(entity, context, filter2, operationFilter)) {
|
||||
if (['select', 'count', 'stat'].includes(action)) {
|
||||
operation.filter = addFilterSegment(operationFilter, filter2);
|
||||
return 0;
|
||||
}
|
||||
if (inconsistentRows) {
|
||||
const { entity: entity2, selection: selection2 } = inconsistentRows;
|
||||
const rows2 = await context.select(entity2, selection2(operationFilter), { dontCollect: true });
|
||||
const data = {};
|
||||
rows2.forEach(
|
||||
ele => Object.assign(data, {
|
||||
[ele.id as string]: ele,
|
||||
})
|
||||
);
|
||||
|
||||
throw new OakRowInconsistencyException({
|
||||
a: 's',
|
||||
d: {
|
||||
[entity2]: data,
|
||||
}
|
||||
}, errMsg);
|
||||
}
|
||||
else {
|
||||
const rows2 = await context.select(entity, {
|
||||
data: getFullProjection(entity, context.getSchema()),
|
||||
filter: Object.assign({}, operationFilter, {
|
||||
$not: filter2,
|
||||
})
|
||||
}, { dontCollect: true });
|
||||
const data = {};
|
||||
rows2.forEach(
|
||||
ele => Object.assign(data, {
|
||||
[ele.id as string]: ele,
|
||||
})
|
||||
);
|
||||
|
||||
throw new OakRowInconsistencyException({
|
||||
a: 's',
|
||||
d: {
|
||||
[entity]: data,
|
||||
}
|
||||
}, errMsg);
|
||||
if (await checkFilterContains(entity, context, filter2, operationFilter)) {
|
||||
return 0;
|
||||
}
|
||||
if (inconsistentRows) {
|
||||
const { entity: entity2, selection: selection2 } = inconsistentRows;
|
||||
const rows2 = await context.select(entity2, selection2(operationFilter), {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
const data = {};
|
||||
rows2.forEach(
|
||||
ele => Object.assign(data, {
|
||||
[ele.id as string]: ele,
|
||||
})
|
||||
);
|
||||
|
||||
throw new OakRowInconsistencyException({
|
||||
a: 's',
|
||||
d: {
|
||||
[entity2]: data,
|
||||
}
|
||||
}, errMsg);
|
||||
}
|
||||
else {
|
||||
const rows2 = await context.select(entity, {
|
||||
data: getFullProjection(entity, context.getSchema()),
|
||||
filter: Object.assign({}, operationFilter, {
|
||||
$not: filter2,
|
||||
})
|
||||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
const data = {};
|
||||
rows2.forEach(
|
||||
ele => Object.assign(data, {
|
||||
[ele.id as string]: ele,
|
||||
})
|
||||
);
|
||||
|
||||
throw new OakRowInconsistencyException({
|
||||
a: 's',
|
||||
d: {
|
||||
[entity]: data,
|
||||
}
|
||||
}, errMsg);
|
||||
}
|
||||
}
|
||||
}) as UpdateTriggerInTxn<ED, keyof ED, Cxt>['fn'];
|
||||
}
|
||||
|
|
@ -101,13 +113,19 @@ export function translateCheckerInSyncContext<
|
|||
case 'row': {
|
||||
const { filter, errMsg } = checker;
|
||||
return (operation, context, option) => {
|
||||
const { filter: operationFilter } = operation;
|
||||
const { filter: operationFilter, action } = operation;
|
||||
const filter2 = typeof filter === 'function' ? filter(context, option) : filter;
|
||||
assert(operationFilter);
|
||||
if (checkFilterContains<ED, T, Cxt>(entity, context, filter2, operationFilter)) {
|
||||
return;
|
||||
if (['select', 'count', 'stat'].includes(action)) {
|
||||
operation.filter = addFilterSegment(operationFilter, filter2);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (checkFilterContains<ED, T, Cxt>(entity, context, filter2, operationFilter)) {
|
||||
return;
|
||||
}
|
||||
throw new OakRowInconsistencyException(undefined, errMsg);
|
||||
}
|
||||
throw new OakRowInconsistencyException(undefined, errMsg);
|
||||
};
|
||||
}
|
||||
case 'relation': {
|
||||
|
|
|
|||
|
|
@ -321,6 +321,7 @@ export function checkFilterContains<ED extends EntityDict, T extends keyof ED, C
|
|||
filter: filter2,
|
||||
}, {
|
||||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
});
|
||||
if (count instanceof Promise) {
|
||||
return count.then(
|
||||
|
|
|
|||
Loading…
Reference in New Issue